From a0711cf9b220c4d1b99614c4eccf31edc3f5cf6a Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Wed, 12 Aug 2020 14:33:42 -0400 Subject: [PATCH] Move the RenderCommand into the shared draw module --- wgpu-core/src/binding_model.rs | 2 - wgpu-core/src/command/draw.rs | 107 +++++++++++++++++++++++++++++++- wgpu-core/src/command/render.rs | 102 +++--------------------------- wgpu-types/src/lib.rs | 2 - 4 files changed, 113 insertions(+), 100 deletions(-) diff --git a/wgpu-core/src/binding_model.rs b/wgpu-core/src/binding_model.rs index 3c6841560..6aa014f74 100644 --- a/wgpu-core/src/binding_model.rs +++ b/wgpu-core/src/binding_model.rs @@ -37,8 +37,6 @@ pub enum CreateBindGroupLayoutError { MissingFeature(wgt::Features), #[error(transparent)] TooManyBindings(BindingTypeMaxCountError), - #[error("arrays of bindings can't be 0 elements long")] - ZeroCount, } #[derive(Clone, Debug, Error)] diff --git a/wgpu-core/src/command/draw.rs b/wgpu-core/src/command/draw.rs index 490ee57e4..1682a141b 100644 --- a/wgpu-core/src/command/draw.rs +++ b/wgpu-core/src/command/draw.rs @@ -12,10 +12,13 @@ use crate::{ track::UseExtendError, validation::{MissingBufferUsageError, MissingTextureUsageError}, }; -pub type BufferError = UseExtendError; +use wgt::{BufferAddress, BufferSize, Color}; +use std::num::NonZeroU32; use thiserror::Error; +pub type BufferError = UseExtendError; + /// Error validating a draw call. #[derive(Clone, Debug, Error, PartialEq)] pub enum DrawError { @@ -69,3 +72,105 @@ pub enum RenderCommandError { #[error(transparent)] PushConstants(#[from] PushConstantUploadError), } + +#[derive(Clone, Copy, Debug, Default)] +#[cfg_attr( + any(feature = "serial-pass", feature = "trace"), + derive(serde::Serialize) +)] +#[cfg_attr( + any(feature = "serial-pass", feature = "replay"), + derive(serde::Deserialize) +)] +pub struct Rect { + pub x: T, + pub y: T, + pub w: T, + pub h: T, +} + +#[doc(hidden)] +#[derive(Clone, Copy, Debug)] +#[cfg_attr( + any(feature = "serial-pass", feature = "trace"), + derive(serde::Serialize) +)] +#[cfg_attr( + any(feature = "serial-pass", feature = "replay"), + derive(serde::Deserialize) +)] +pub enum RenderCommand { + SetBindGroup { + index: u8, + num_dynamic_offsets: u8, + bind_group_id: id::BindGroupId, + }, + SetPipeline(id::RenderPipelineId), + SetIndexBuffer { + buffer_id: id::BufferId, + offset: BufferAddress, + size: Option, + }, + SetVertexBuffer { + slot: u32, + buffer_id: id::BufferId, + offset: BufferAddress, + size: Option, + }, + SetBlendColor(Color), + SetStencilReference(u32), + SetViewport { + rect: Rect, + //TODO: use half-float to reduce the size? + depth_min: f32, + depth_max: f32, + }, + SetScissor(Rect), + SetPushConstant { + stages: wgt::ShaderStage, + offset: u32, + size_bytes: u32, + /// None means there is no data and the data should be an array of zeros. + /// + /// Facilitates clears in renderbundles which explicitly do their clears. + values_offset: Option, + }, + Draw { + vertex_count: u32, + instance_count: u32, + first_vertex: u32, + first_instance: u32, + }, + DrawIndexed { + index_count: u32, + instance_count: u32, + first_index: u32, + base_vertex: i32, + first_instance: u32, + }, + MultiDrawIndirect { + buffer_id: id::BufferId, + offset: BufferAddress, + /// Count of `None` represents a non-multi call. + count: Option, + indexed: bool, + }, + MultiDrawIndirectCount { + buffer_id: id::BufferId, + offset: BufferAddress, + count_buffer_id: id::BufferId, + count_buffer_offset: BufferAddress, + max_count: u32, + indexed: bool, + }, + PushDebugGroup { + color: u32, + len: usize, + }, + PopDebugGroup, + InsertDebugMarker { + color: u32, + len: usize, + }, + ExecuteBundle(id::RenderBundleId), +} diff --git a/wgpu-core/src/command/render.rs b/wgpu-core/src/command/render.rs index 55726acf5..59f1c7928 100644 --- a/wgpu-core/src/command/render.rs +++ b/wgpu-core/src/command/render.rs @@ -6,7 +6,8 @@ use crate::{ binding_model::BindError, command::{ bind::{Binder, LayoutChange}, - BasePass, BasePassRef, CommandBuffer, CommandEncoderError, DrawError, RenderCommandError, + BasePass, BasePassRef, CommandBuffer, CommandEncoderError, DrawError, RenderCommand, + RenderCommandError, }, conv, device::{ @@ -28,9 +29,7 @@ use crate::{ use arrayvec::ArrayVec; use hal::command::CommandBuffer as _; use thiserror::Error; -use wgt::{ - BufferAddress, BufferSize, BufferUsage, Color, IndexFormat, InputStepMode, TextureUsage, -}; +use wgt::{BufferAddress, BufferUsage, Color, IndexFormat, InputStepMode, TextureUsage}; #[cfg(any(feature = "serial-pass", feature = "replay"))] use serde::Deserialize; @@ -143,96 +142,6 @@ pub struct RenderPassDescriptor<'a> { pub depth_stencil_attachment: Option<&'a DepthStencilAttachmentDescriptor>, } -#[derive(Clone, Copy, Debug, Default)] -#[cfg_attr(any(feature = "serial-pass", feature = "trace"), derive(Serialize))] -#[cfg_attr(any(feature = "serial-pass", feature = "replay"), derive(Deserialize))] -pub struct Rect { - pub x: T, - pub y: T, - pub w: T, - pub h: T, -} - -#[doc(hidden)] -#[derive(Clone, Copy, Debug)] -#[cfg_attr(any(feature = "serial-pass", feature = "trace"), derive(Serialize))] -#[cfg_attr(any(feature = "serial-pass", feature = "replay"), derive(Deserialize))] -pub enum RenderCommand { - SetBindGroup { - index: u8, - num_dynamic_offsets: u8, - bind_group_id: id::BindGroupId, - }, - SetPipeline(id::RenderPipelineId), - SetIndexBuffer { - buffer_id: id::BufferId, - offset: BufferAddress, - size: Option, - }, - SetVertexBuffer { - slot: u32, - buffer_id: id::BufferId, - offset: BufferAddress, - size: Option, - }, - SetBlendColor(Color), - SetStencilReference(u32), - SetViewport { - rect: Rect, - //TODO: use half-float to reduce the size? - depth_min: f32, - depth_max: f32, - }, - SetScissor(Rect), - SetPushConstant { - stages: wgt::ShaderStage, - offset: u32, - size_bytes: u32, - /// None means there is no data and the data should be an array of zeros. - /// - /// Facilitates clears in renderbundles which explicitly do their clears. - values_offset: Option, - }, - Draw { - vertex_count: u32, - instance_count: u32, - first_vertex: u32, - first_instance: u32, - }, - DrawIndexed { - index_count: u32, - instance_count: u32, - first_index: u32, - base_vertex: i32, - first_instance: u32, - }, - MultiDrawIndirect { - buffer_id: id::BufferId, - offset: BufferAddress, - /// Count of `None` represents a non-multi call. - count: Option, - indexed: bool, - }, - MultiDrawIndirectCount { - buffer_id: id::BufferId, - offset: BufferAddress, - count_buffer_id: id::BufferId, - count_buffer_offset: BufferAddress, - max_count: u32, - indexed: bool, - }, - PushDebugGroup { - color: u32, - len: usize, - }, - PopDebugGroup, - InsertDebugMarker { - color: u32, - len: usize, - }, - ExecuteBundle(id::RenderBundleId), -} - #[cfg_attr(feature = "serial-pass", derive(Deserialize, Serialize))] pub struct RenderPass { base: BasePass, @@ -1632,7 +1541,10 @@ impl Global { } pub mod render_ffi { - use super::{super::Rect, RenderCommand, RenderPass}; + use super::{ + super::{Rect, RenderCommand}, + RenderPass, + }; use crate::{id, span, RawString}; use std::{convert::TryInto, ffi, num::NonZeroU32, slice}; use wgt::{BufferAddress, BufferSize, Color, DynamicOffset}; diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 57511f362..953a6874c 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -16,8 +16,6 @@ use std::{num::NonZeroU32, ops::Range}; pub type BufferAddress = u64; /// Integral type used for buffer slice sizes. pub type BufferSize = std::num::NonZeroU64; -/// Index for binding a group. -pub type BindGroupIndex = u8; /// Integral type used for binding locations in shaders. pub type ShaderLocation = u32; /// Integral type used for dynamic bind group offsets.