mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-21 23:11:01 +01:00
Safe error handling for commands API
This commit is contained in:
1 parent
f67771fb87
commit
1b03fbe9be
6 files changed
+351
-302
No files matched your search
+8
-4
@@ -123,7 +123,8 @@ impl GlobalExt for wgc::hub::Global<IdentityPassThroughFactory> {
|
||||
.command_encoder_copy_texture_to_texture::<B>(encoder, &src, &dst, &size)
|
||||
.unwrap(),
|
||||
trace::Command::RunComputePass { base } => {
|
||||
self.command_encoder_run_compute_pass_impl::<B>(encoder, base.as_ref());
|
||||
self.command_encoder_run_compute_pass_impl::<B>(encoder, base.as_ref())
|
||||
.unwrap();
|
||||
}
|
||||
trace::Command::RunRenderPass {
|
||||
base,
|
||||
@@ -135,7 +136,8 @@ impl GlobalExt for wgc::hub::Global<IdentityPassThroughFactory> {
|
||||
base.as_ref(),
|
||||
&target_colors,
|
||||
target_depth_stencil.as_ref(),
|
||||
);
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -364,14 +366,16 @@ impl GlobalExt for wgc::hub::Global<IdentityPassThroughFactory> {
|
||||
},
|
||||
device,
|
||||
Some(base),
|
||||
);
|
||||
)
|
||||
.unwrap();
|
||||
self.render_bundle_encoder_finish::<B>(
|
||||
bundle,
|
||||
&wgt::RenderBundleDescriptor {
|
||||
label: label.as_ptr(),
|
||||
},
|
||||
id,
|
||||
);
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
A::DestroyRenderBundle(id) => {
|
||||
self.render_bundle_destroy::<B>(id);
|
||||
|
||||
@@ -378,7 +378,7 @@ pub type BindGroupEntry<'a> = wgt::BindGroupEntry<BindingResource<'a>>;
|
||||
pub type BindGroupDescriptor<'a> =
|
||||
wgt::BindGroupDescriptor<'a, BindGroupLayoutId, BindGroupEntry<'a>>;
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum BindError {
|
||||
/// Number of dynamic offsets doesn't match the number of dynamic bindings
|
||||
/// in the bind group layout.
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
!*/
|
||||
|
||||
use crate::{
|
||||
binding_model::PushConstantUploadError,
|
||||
command::{BasePass, RenderCommand},
|
||||
conv,
|
||||
device::{AttachmentData, Label, RenderPassContext, MAX_VERTEX_BUFFERS, SHADER_STAGE_COUNT},
|
||||
@@ -62,9 +63,9 @@ impl RenderBundleEncoder {
|
||||
desc: &wgt::RenderBundleEncoderDescriptor,
|
||||
parent_id: id::DeviceId,
|
||||
base: Option<BasePass<RenderCommand>>,
|
||||
) -> Self {
|
||||
) -> Result<Self, InvalidSampleCountError> {
|
||||
span!(_guard, INFO, "RenderBundleEncoder::new");
|
||||
RenderBundleEncoder {
|
||||
Ok(RenderBundleEncoder {
|
||||
base: base.unwrap_or_else(BasePass::new),
|
||||
parent_id,
|
||||
context: RenderPassContext {
|
||||
@@ -75,11 +76,13 @@ impl RenderBundleEncoder {
|
||||
},
|
||||
sample_count: {
|
||||
let sc = desc.sample_count;
|
||||
assert!(sc != 0 && sc <= 32 && conv::is_power_of_two(sc));
|
||||
if sc == 0 || sc > 32 || !conv::is_power_of_two(sc) {
|
||||
return Err(InvalidSampleCountError);
|
||||
}
|
||||
sc as u8
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn parent(&self) -> id::DeviceId {
|
||||
@@ -87,6 +90,10 @@ impl RenderBundleEncoder {
|
||||
}
|
||||
}
|
||||
|
||||
/// Error type returned from `RenderBundleEncoder::new` if the sample count is invalid.
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct InvalidSampleCountError;
|
||||
|
||||
//Note: here, `RenderBundle` is just wrapping a raw stream of render commands.
|
||||
// The plan is to back it by an actual Vulkan secondary buffer, D3D12 Bundle,
|
||||
// or Metal indirect command buffer.
|
||||
@@ -120,7 +127,7 @@ impl RenderBundle {
|
||||
bind_group_guard: &Storage<crate::binding_model::BindGroup<B>, id::BindGroupId>,
|
||||
pipeline_guard: &Storage<crate::pipeline::RenderPipeline<B>, id::RenderPipelineId>,
|
||||
buffer_guard: &Storage<crate::resource::Buffer<B>, id::BufferId>,
|
||||
) {
|
||||
) -> Result<(), RenderCommandError> {
|
||||
use hal::command::CommandBuffer as _;
|
||||
|
||||
let mut offsets = self.base.dynamic_offsets.as_slice();
|
||||
@@ -185,8 +192,9 @@ impl RenderBundle {
|
||||
size_bytes,
|
||||
values_offset,
|
||||
} => {
|
||||
let pipeline_layout = &pipeline_layout_guard[pipeline_layout_id
|
||||
.expect("Must have a pipeline bound to use push constants")];
|
||||
let pipeline_layout_id =
|
||||
pipeline_layout_id.ok_or(RenderCommandError::UnboundPipeline)?;
|
||||
let pipeline_layout = &pipeline_layout_guard[pipeline_layout_id];
|
||||
|
||||
if let Some(values_offset) = values_offset {
|
||||
let values_end_offset = (values_offset + size_bytes / 4) as usize;
|
||||
@@ -268,6 +276,7 @@ impl RenderBundle {
|
||||
| RenderCommand::SetScissor(_) => unreachable!(),
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -579,13 +588,50 @@ impl State {
|
||||
}
|
||||
}
|
||||
|
||||
/// Error encountered when encoding a render command.
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum RenderCommandError {
|
||||
/// A bind group index is greater than the device's requested `max_bind_group` limit.
|
||||
BindGroupIndexOutOfRange,
|
||||
/// A dynamic buffer offset is not a multiple of the required buffer alignment.
|
||||
UnalignedBufferOffset,
|
||||
/// The number of buffer offsets does not match the number of dynamic bindings.
|
||||
WrongBufferOffsetCount,
|
||||
/// The pipeline is incompatible with the render pass.
|
||||
///
|
||||
/// Either:
|
||||
/// - The render pipeline output formats and sample counts do not match render pass attachment formats.
|
||||
/// - The pipeline is not compatible with the depth-stencil read-only render pass.
|
||||
IncompatiblePipeline,
|
||||
/// The provided buffer does not have the required usage.
|
||||
InvalidBufferUsage,
|
||||
/// The provided texture does not have the required usage.
|
||||
InvalidTextureUsage,
|
||||
/// A pipeline must be bound.
|
||||
UnboundPipeline,
|
||||
/// There was an error with the push constants.
|
||||
PushConstantUploadError(PushConstantUploadError),
|
||||
/// Vertex extends beyond limit.
|
||||
VertexBeyondLimit,
|
||||
/// Instance extends beyond limit.
|
||||
InstanceBeyondLimit,
|
||||
/// Index extends beyond limit.
|
||||
IndexBeyondLimit,
|
||||
}
|
||||
|
||||
impl From<PushConstantUploadError> for RenderCommandError {
|
||||
fn from(error: PushConstantUploadError) -> Self {
|
||||
Self::PushConstantUploadError(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
pub fn render_bundle_encoder_finish<B: GfxBackend>(
|
||||
&self,
|
||||
bundle_encoder: RenderBundleEncoder,
|
||||
desc: &wgt::RenderBundleDescriptor<Label>,
|
||||
id_in: Input<G, id::RenderBundleId>,
|
||||
) -> id::RenderBundleId {
|
||||
) -> Result<id::RenderBundleId, RenderCommandError> {
|
||||
span!(_guard, INFO, "RenderBundleEncoder::finish");
|
||||
let hub = B::hub(self);
|
||||
let mut token = Token::root();
|
||||
@@ -621,24 +667,20 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
num_dynamic_offsets,
|
||||
bind_group_id,
|
||||
} => {
|
||||
assert!(
|
||||
(index as u32) < device.limits.max_bind_groups,
|
||||
"Bind group index {0} is out of range 0..{1} provided by requested max_bind_group limit {1}",
|
||||
index,
|
||||
device.limits.max_bind_groups
|
||||
);
|
||||
if (index as u32) >= device.limits.max_bind_groups {
|
||||
return Err(RenderCommandError::BindGroupIndexOutOfRange);
|
||||
}
|
||||
|
||||
let offsets = &base.dynamic_offsets[..num_dynamic_offsets as usize];
|
||||
base.dynamic_offsets =
|
||||
&base.dynamic_offsets[num_dynamic_offsets as usize..];
|
||||
for off in offsets {
|
||||
assert_eq!(
|
||||
*off as wgt::BufferAddress % wgt::BIND_BUFFER_ALIGNMENT,
|
||||
0,
|
||||
"Misaligned dynamic buffer offset: {} does not align with {}",
|
||||
off,
|
||||
wgt::BIND_BUFFER_ALIGNMENT
|
||||
);
|
||||
// Check for misaligned offsets.
|
||||
if offsets
|
||||
.iter()
|
||||
.map(|offset| *offset as wgt::BufferAddress)
|
||||
.any(|offset| offset % wgt::BIND_BUFFER_ALIGNMENT != 0)
|
||||
{
|
||||
return Err(RenderCommandError::UnalignedBufferOffset);
|
||||
}
|
||||
|
||||
let bind_group = state
|
||||
@@ -646,7 +688,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
.bind_groups
|
||||
.use_extend(&*bind_group_guard, bind_group_id, (), ())
|
||||
.unwrap();
|
||||
assert_eq!(bind_group.dynamic_binding_info.len(), offsets.len());
|
||||
if bind_group.dynamic_binding_info.len() != offsets.len() {
|
||||
return Err(RenderCommandError::WrongBufferOffsetCount);
|
||||
}
|
||||
|
||||
state.set_bind_group(index, bind_group_id, bind_group.layout_id, offsets);
|
||||
state.trackers.merge_extend(&bind_group.used);
|
||||
@@ -658,10 +702,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
.use_extend(&*pipeline_guard, pipeline_id, (), ())
|
||||
.unwrap();
|
||||
|
||||
assert!(
|
||||
bundle_encoder.context.compatible(&pipeline.pass_context),
|
||||
"The render pipeline output formats and sample counts do not match render pass attachment formats!"
|
||||
);
|
||||
if !bundle_encoder.context.compatible(&pipeline.pass_context) {
|
||||
return Err(RenderCommandError::IncompatiblePipeline);
|
||||
}
|
||||
//TODO: check read-only depth
|
||||
|
||||
let layout = &pipeline_layout_guard[pipeline.layout_id.value];
|
||||
@@ -688,7 +731,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
.buffers
|
||||
.use_extend(&*buffer_guard, buffer_id, (), BufferUse::INDEX)
|
||||
.unwrap();
|
||||
assert!(buffer.usage.contains(wgt::BufferUsage::INDEX), "An invalid setIndexBuffer call has been made. The buffer usage is {:?} which does not contain required usage INDEX", buffer.usage);
|
||||
if !buffer.usage.contains(wgt::BufferUsage::INDEX) {
|
||||
return Err(RenderCommandError::InvalidBufferUsage);
|
||||
}
|
||||
|
||||
let end = match size {
|
||||
Some(s) => offset + s.get(),
|
||||
@@ -707,11 +752,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
.buffers
|
||||
.use_extend(&*buffer_guard, buffer_id, (), BufferUse::VERTEX)
|
||||
.unwrap();
|
||||
assert!(
|
||||
buffer.usage.contains(wgt::BufferUsage::VERTEX),
|
||||
"An invalid setVertexBuffer call has been made. The buffer usage is {:?} which does not contain required usage VERTEX",
|
||||
buffer.usage
|
||||
);
|
||||
if !buffer.usage.contains(wgt::BufferUsage::VERTEX) {
|
||||
return Err(RenderCommandError::InvalidBufferUsage);
|
||||
}
|
||||
|
||||
let end = match size {
|
||||
Some(s) => offset + s.get(),
|
||||
@@ -727,12 +770,12 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
} => {
|
||||
let end_offset = offset + size_bytes;
|
||||
|
||||
let pipeline_layout = &pipeline_layout_guard[pipeline_layout_id
|
||||
.expect("Must have a pipeline bound to use push constants")];
|
||||
let pipeline_layout_id =
|
||||
pipeline_layout_id.ok_or(RenderCommandError::UnboundPipeline)?;
|
||||
let pipeline_layout = &pipeline_layout_guard[pipeline_layout_id];
|
||||
|
||||
pipeline_layout
|
||||
.validate_push_constant_ranges(stages, offset, end_offset)
|
||||
.unwrap();
|
||||
.validate_push_constant_ranges(stages, offset, end_offset)?;
|
||||
|
||||
commands.push(command);
|
||||
}
|
||||
@@ -743,18 +786,12 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
first_instance,
|
||||
} => {
|
||||
let (vertex_limit, instance_limit) = state.vertex_limits();
|
||||
assert!(
|
||||
first_vertex + vertex_count <= vertex_limit,
|
||||
"Vertex {} extends beyond limit {}",
|
||||
first_vertex + vertex_count,
|
||||
vertex_limit
|
||||
);
|
||||
assert!(
|
||||
first_instance + instance_count <= instance_limit,
|
||||
"Instance {} extends beyond limit {}",
|
||||
first_instance + instance_count,
|
||||
instance_limit
|
||||
);
|
||||
if first_vertex + vertex_count > vertex_limit {
|
||||
return Err(RenderCommandError::VertexBeyondLimit);
|
||||
}
|
||||
if first_instance + instance_count > instance_limit {
|
||||
return Err(RenderCommandError::InstanceBeyondLimit);
|
||||
}
|
||||
commands.extend(state.flush_vertices());
|
||||
commands.extend(state.flush_binds());
|
||||
commands.push(command);
|
||||
@@ -769,18 +806,12 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
//TODO: validate that base_vertex + max_index() is within the provided range
|
||||
let (_, instance_limit) = state.vertex_limits();
|
||||
let index_limit = state.index.limit();
|
||||
assert!(
|
||||
first_index + index_count <= index_limit,
|
||||
"Index {} extends beyond limit {}",
|
||||
first_index + index_count,
|
||||
index_limit
|
||||
);
|
||||
assert!(
|
||||
first_instance + instance_count <= instance_limit,
|
||||
"Instance {} extends beyond limit {}",
|
||||
first_instance + instance_count,
|
||||
instance_limit
|
||||
);
|
||||
if first_index + index_count > index_limit {
|
||||
return Err(RenderCommandError::IndexBeyondLimit);
|
||||
}
|
||||
if first_instance + instance_count > instance_limit {
|
||||
return Err(RenderCommandError::InstanceBeyondLimit);
|
||||
}
|
||||
commands.extend(state.index.flush());
|
||||
commands.extend(state.flush_vertices());
|
||||
commands.extend(state.flush_binds());
|
||||
@@ -797,11 +828,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
.buffers
|
||||
.use_extend(&*buffer_guard, buffer_id, (), BufferUse::INDIRECT)
|
||||
.unwrap();
|
||||
assert!(
|
||||
buffer.usage.contains(wgt::BufferUsage::INDIRECT),
|
||||
"An invalid drawIndirect call has been made. The buffer usage is {:?} which does not contain required usage INDIRECT",
|
||||
buffer.usage
|
||||
);
|
||||
if !buffer.usage.contains(wgt::BufferUsage::INDIRECT) {
|
||||
return Err(RenderCommandError::InvalidBufferUsage);
|
||||
}
|
||||
|
||||
commands.extend(state.flush_vertices());
|
||||
commands.extend(state.flush_binds());
|
||||
@@ -818,11 +847,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
.buffers
|
||||
.use_extend(&*buffer_guard, buffer_id, (), BufferUse::INDIRECT)
|
||||
.unwrap();
|
||||
assert!(
|
||||
buffer.usage.contains(wgt::BufferUsage::INDIRECT),
|
||||
"An invalid drawIndexedIndirect call has been made. The buffer usage is {:?} which does not contain required usage INDIRECT",
|
||||
buffer.usage
|
||||
);
|
||||
if !buffer.usage.contains(wgt::BufferUsage::INDIRECT) {
|
||||
return Err(RenderCommandError::InvalidBufferUsage);
|
||||
}
|
||||
|
||||
commands.extend(state.index.flush());
|
||||
commands.extend(state.flush_vertices());
|
||||
@@ -890,7 +917,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
.bundles
|
||||
.init(id, ref_count, PhantomData)
|
||||
.unwrap();
|
||||
id
|
||||
Ok(id)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use crate::{
|
||||
binding_model::{BindError, PushConstantUploadError},
|
||||
command::{
|
||||
bind::{Binder, LayoutChange},
|
||||
BasePass, BasePassRef, CommandBuffer,
|
||||
@@ -107,6 +108,34 @@ struct State {
|
||||
debug_scope_depth: u32,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum ComputePassError {
|
||||
/// A bind group index is greater than the device's requested `max_bind_group` limit.
|
||||
BindGroupIndexOutOfRange,
|
||||
/// A pipeline must be bound.
|
||||
UnboundPipeline,
|
||||
/// The provided buffer does not have the required usage.
|
||||
InvalidBufferUsage,
|
||||
/// Can't pop debug group, because number of pushed debug groups is zero.
|
||||
InvalidPopDebugGroup,
|
||||
/// An error encountered while validating dynamic bindings.
|
||||
BindError(BindError),
|
||||
/// There was an error with the push constants.
|
||||
PushConstantUploadError(PushConstantUploadError),
|
||||
}
|
||||
|
||||
impl From<PushConstantUploadError> for ComputePassError {
|
||||
fn from(error: PushConstantUploadError) -> Self {
|
||||
Self::PushConstantUploadError(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<BindError> for ComputePassError {
|
||||
fn from(error: BindError) -> Self {
|
||||
Self::BindError(error)
|
||||
}
|
||||
}
|
||||
|
||||
// Common routines between render/compute
|
||||
|
||||
impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
@@ -114,7 +143,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
&self,
|
||||
encoder_id: id::CommandEncoderId,
|
||||
pass: &ComputePass,
|
||||
) {
|
||||
) -> Result<(), ComputePassError> {
|
||||
self.command_encoder_run_compute_pass_impl::<B>(encoder_id, pass.base.as_ref())
|
||||
}
|
||||
|
||||
@@ -123,7 +152,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
&self,
|
||||
encoder_id: id::CommandEncoderId,
|
||||
mut base: BasePassRef<ComputeCommand>,
|
||||
) {
|
||||
) -> Result<(), ComputePassError> {
|
||||
span!(_guard, INFO, "CommandEncoder::run_compute_pass");
|
||||
let hub = B::hub(self);
|
||||
let mut token = Token::root();
|
||||
@@ -162,12 +191,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
num_dynamic_offsets,
|
||||
bind_group_id,
|
||||
} => {
|
||||
assert!(
|
||||
(index as u32) < cmb.limits.max_bind_groups,
|
||||
"Bind group index {0} is out of range 0..{1} provided by requested max_bind_group limit {1}",
|
||||
index,
|
||||
cmb.limits.max_bind_groups
|
||||
);
|
||||
if (index as u32) >= cmb.limits.max_bind_groups {
|
||||
return Err(ComputePassError::BindGroupIndexOutOfRange);
|
||||
}
|
||||
|
||||
let offsets = &base.dynamic_offsets[..num_dynamic_offsets as usize];
|
||||
base.dynamic_offsets = &base.dynamic_offsets[num_dynamic_offsets as usize..];
|
||||
@@ -177,7 +203,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
.bind_groups
|
||||
.use_extend(&*bind_group_guard, bind_group_id, (), ())
|
||||
.unwrap();
|
||||
bind_group.validate_dynamic_bindings(offsets).unwrap();
|
||||
bind_group.validate_dynamic_bindings(offsets)?;
|
||||
|
||||
log::trace!(
|
||||
"Encoding barriers on binding of {:?} to {:?}",
|
||||
@@ -294,10 +320,11 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
let data_slice =
|
||||
&base.push_constant_data[(values_offset as usize)..values_end_offset];
|
||||
|
||||
let pipeline_layout = &pipeline_layout_guard[state
|
||||
let pipeline_layout_id = state
|
||||
.binder
|
||||
.pipeline_layout_id
|
||||
.expect("Must have a pipeline bound to use push constants")];
|
||||
.ok_or(ComputePassError::UnboundPipeline)?;
|
||||
let pipeline_layout = &pipeline_layout_guard[pipeline_layout_id];
|
||||
|
||||
pipeline_layout
|
||||
.validate_push_constant_ranges(
|
||||
@@ -305,26 +332,22 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
offset,
|
||||
end_offset_bytes,
|
||||
)
|
||||
.unwrap();
|
||||
.map_err(ComputePassError::from)?;
|
||||
|
||||
unsafe { raw.push_compute_constants(&pipeline_layout.raw, offset, data_slice) }
|
||||
}
|
||||
ComputeCommand::Dispatch(groups) => {
|
||||
assert_eq!(
|
||||
state.pipeline,
|
||||
PipelineState::Set,
|
||||
"Dispatch DEBUG: Pipeline is missing"
|
||||
);
|
||||
if state.pipeline != PipelineState::Set {
|
||||
return Err(ComputePassError::UnboundPipeline);
|
||||
}
|
||||
unsafe {
|
||||
raw.dispatch(groups);
|
||||
}
|
||||
}
|
||||
ComputeCommand::DispatchIndirect { buffer_id, offset } => {
|
||||
assert_eq!(
|
||||
state.pipeline,
|
||||
PipelineState::Set,
|
||||
"Dispatch DEBUG: Pipeline is missing"
|
||||
);
|
||||
if state.pipeline != PipelineState::Set {
|
||||
return Err(ComputePassError::UnboundPipeline);
|
||||
}
|
||||
let (src_buffer, src_pending) = cmb.trackers.buffers.use_replace(
|
||||
&*buffer_guard,
|
||||
buffer_id,
|
||||
@@ -354,10 +377,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
base.string_data = &base.string_data[len..];
|
||||
}
|
||||
ComputeCommand::PopDebugGroup => {
|
||||
assert_ne!(
|
||||
state.debug_scope_depth, 0,
|
||||
"Can't pop debug group, because number of pushed debug groups is zero!"
|
||||
);
|
||||
if state.debug_scope_depth == 0 {
|
||||
return Err(ComputePassError::InvalidPopDebugGroup);
|
||||
}
|
||||
state.debug_scope_depth -= 1;
|
||||
unsafe {
|
||||
raw.end_debug_marker();
|
||||
@@ -370,6 +392,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+191
-197
@@ -3,9 +3,10 @@
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use crate::{
|
||||
binding_model::BindError,
|
||||
command::{
|
||||
bind::{Binder, LayoutChange},
|
||||
BasePass, BasePassRef,
|
||||
BasePass, BasePassRef, RenderCommandError,
|
||||
},
|
||||
conv,
|
||||
device::{
|
||||
@@ -38,24 +39,20 @@ pub type DepthStencilAttachmentDescriptor =
|
||||
fn is_depth_stencil_read_only(
|
||||
desc: &DepthStencilAttachmentDescriptor,
|
||||
aspects: hal::format::Aspects,
|
||||
) -> bool {
|
||||
) -> Result<bool, RenderPassError> {
|
||||
if aspects.contains(hal::format::Aspects::DEPTH) && !desc.depth.read_only {
|
||||
return false;
|
||||
return Ok(false);
|
||||
}
|
||||
if (desc.depth.load_op, desc.depth.store_op) != (LoadOp::Load, StoreOp::Store) {
|
||||
return Err(RenderPassError::InvalidDepthStencilOps);
|
||||
}
|
||||
assert_eq!(
|
||||
(desc.depth.load_op, desc.depth.store_op),
|
||||
(LoadOp::Load, StoreOp::Store),
|
||||
"Unable to clear non-present/read-only depth"
|
||||
);
|
||||
if aspects.contains(hal::format::Aspects::STENCIL) && !desc.stencil.read_only {
|
||||
return false;
|
||||
return Ok(false);
|
||||
}
|
||||
assert_eq!(
|
||||
(desc.stencil.load_op, desc.stencil.store_op),
|
||||
(LoadOp::Load, StoreOp::Store),
|
||||
"Unable to clear non-present/read-only stencil"
|
||||
);
|
||||
true
|
||||
if (desc.stencil.load_op, desc.stencil.store_op) != (LoadOp::Load, StoreOp::Store) {
|
||||
return Err(RenderPassError::InvalidDepthStencilOps);
|
||||
}
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
pub type RenderPassDescriptor<'a> =
|
||||
@@ -209,8 +206,8 @@ impl OptionalState {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq)]
|
||||
enum DrawError {
|
||||
#[derive(Clone, PartialEq)]
|
||||
pub enum DrawError {
|
||||
MissingBlendColor,
|
||||
MissingStencilReference,
|
||||
MissingPipeline,
|
||||
@@ -346,6 +343,59 @@ impl State {
|
||||
}
|
||||
}
|
||||
|
||||
/// Error encountered when performing a render pass.
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum RenderPassError {
|
||||
/// Attachment's sample count is not valid.
|
||||
InvalidSampleCount,
|
||||
/// All resolve targets must have a sample count of 1.
|
||||
InvalidResolveTargetSampleCount,
|
||||
/// Extent state must match extent from view.
|
||||
ExtentStateMismatch,
|
||||
/// Attempted to use a swap chain image as a depth/stencil attachment.
|
||||
SwapChainImageAsDepthStencil,
|
||||
/// Unable to clear non-present/read-only depth/stencil.
|
||||
InvalidDepthStencilOps,
|
||||
/// All attachments must have the same sample count.
|
||||
SampleCountMismatch,
|
||||
/// Texture view's swap chain must match swap chain in use.
|
||||
SwapChainMismatch,
|
||||
/// Setting `values_offset` to be `None` is only for internal use in render bundles.
|
||||
InvalidValuesOffset,
|
||||
/// The specified device feature is required for the given command, but is not enabled.
|
||||
MissingDeviceFeature(&'static str),
|
||||
/// Indirect draw command would overrun the bounds of the buffer.
|
||||
IndirectBufferOverrun,
|
||||
/// Can't pop debug group, because number of pushed debug groups is zero.
|
||||
InvalidPopDebugGroup,
|
||||
/// The render bundle output formats do not match render pass attachment formats.
|
||||
IncompatibleRenderBundle,
|
||||
/// An error encountered while encoding a command.
|
||||
RenderCommandError(RenderCommandError),
|
||||
/// An error encountered while handling a draw command.
|
||||
DrawError(DrawError),
|
||||
/// An error encountered while validating dynamic bindings.
|
||||
BindError(BindError),
|
||||
}
|
||||
|
||||
impl From<RenderCommandError> for RenderPassError {
|
||||
fn from(error: RenderCommandError) -> Self {
|
||||
Self::RenderCommandError(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<DrawError> for RenderPassError {
|
||||
fn from(error: DrawError) -> Self {
|
||||
Self::DrawError(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<BindError> for RenderPassError {
|
||||
fn from(error: BindError) -> Self {
|
||||
Self::BindError(error)
|
||||
}
|
||||
}
|
||||
|
||||
// Common routines between render/compute
|
||||
|
||||
impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
@@ -353,7 +403,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
&self,
|
||||
encoder_id: id::CommandEncoderId,
|
||||
pass: &RenderPass,
|
||||
) {
|
||||
) -> Result<(), RenderPassError> {
|
||||
self.command_encoder_run_render_pass_impl::<B>(
|
||||
encoder_id,
|
||||
pass.base.as_ref(),
|
||||
@@ -369,7 +419,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
mut base: BasePassRef<RenderCommand>,
|
||||
color_attachments: &[ColorAttachmentDescriptor],
|
||||
depth_stencil_attachment: Option<&DepthStencilAttachmentDescriptor>,
|
||||
) {
|
||||
) -> Result<(), RenderPassError> {
|
||||
span!(_guard, INFO, "CommandEncoder::run_render_pass");
|
||||
|
||||
let hub = B::hub(self);
|
||||
@@ -434,10 +484,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
.get(0)
|
||||
.map(|at| view_guard[at.attachment].samples)
|
||||
.unwrap_or(1);
|
||||
assert!(
|
||||
sample_count & samples_count_limit != 0,
|
||||
"Attachment sample_count must be supported by physical device limits"
|
||||
);
|
||||
if sample_count & samples_count_limit == 0 {
|
||||
return Err(RenderPassError::InvalidSampleCount);
|
||||
}
|
||||
|
||||
log::trace!(
|
||||
"Encoding render pass begin in command buffer {:?}",
|
||||
@@ -451,14 +500,16 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
.use_extend(&*view_guard, at.attachment, (), ())
|
||||
.unwrap();
|
||||
if let Some(ex) = extent {
|
||||
assert_eq!(ex, view.extent, "Extent state must match extent from view");
|
||||
if ex != view.extent {
|
||||
return Err(RenderPassError::ExtentStateMismatch);
|
||||
}
|
||||
} else {
|
||||
extent = Some(view.extent);
|
||||
}
|
||||
let source_id = match view.inner {
|
||||
TextureViewInner::Native { ref source_id, .. } => source_id,
|
||||
TextureViewInner::SwapChain { .. } => {
|
||||
panic!("Unexpected depth/stencil use of swapchain image!")
|
||||
return Err(RenderPassError::SwapChainImageAsDepthStencil)
|
||||
}
|
||||
};
|
||||
|
||||
@@ -466,7 +517,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
let previous_use = base_trackers
|
||||
.textures
|
||||
.query(source_id.value, view.range.clone());
|
||||
let new_use = if is_depth_stencil_read_only(at, view.range.aspects) {
|
||||
let new_use = if is_depth_stencil_read_only(at, view.range.aspects)? {
|
||||
is_ds_read_only = true;
|
||||
TextureUse::ATTACHMENT_READ
|
||||
} else {
|
||||
@@ -509,14 +560,15 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
.use_extend(&*view_guard, at.attachment, (), ())
|
||||
.unwrap();
|
||||
if let Some(ex) = extent {
|
||||
assert_eq!(ex, view.extent, "Extent state must match extent from view");
|
||||
if ex != view.extent {
|
||||
return Err(RenderPassError::ExtentStateMismatch);
|
||||
}
|
||||
} else {
|
||||
extent = Some(view.extent);
|
||||
}
|
||||
assert_eq!(
|
||||
view.samples, sample_count,
|
||||
"All attachments must have the same sample_count"
|
||||
);
|
||||
if view.samples != sample_count {
|
||||
return Err(RenderPassError::SampleCountMismatch);
|
||||
}
|
||||
|
||||
let layouts = match view.inner {
|
||||
TextureViewInner::Native { ref source_id, .. } => {
|
||||
@@ -543,10 +595,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
}
|
||||
TextureViewInner::SwapChain { ref source_id, .. } => {
|
||||
if let Some((ref sc_id, _)) = cmb.used_swap_chain {
|
||||
assert_eq!(
|
||||
source_id.value, sc_id.value,
|
||||
"Texture view's swap chain must match swap chain in use"
|
||||
);
|
||||
if source_id.value != sc_id.value {
|
||||
return Err(RenderPassError::SwapChainMismatch);
|
||||
}
|
||||
} else {
|
||||
assert!(used_swap_chain.is_none());
|
||||
used_swap_chain = Some(source_id.clone());
|
||||
@@ -579,15 +630,12 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
.views
|
||||
.use_extend(&*view_guard, resolve_target, (), ())
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
extent,
|
||||
Some(view.extent),
|
||||
"Extent state must match extent from view"
|
||||
);
|
||||
assert_eq!(
|
||||
view.samples, 1,
|
||||
"All resolve_targets must have a sample_count of 1"
|
||||
);
|
||||
if extent != Some(view.extent) {
|
||||
return Err(RenderPassError::ExtentStateMismatch);
|
||||
}
|
||||
if view.samples != 1 {
|
||||
return Err(RenderPassError::InvalidResolveTargetSampleCount);
|
||||
}
|
||||
|
||||
let layouts = match view.inner {
|
||||
TextureViewInner::Native { ref source_id, .. } => {
|
||||
@@ -614,10 +662,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
}
|
||||
TextureViewInner::SwapChain { ref source_id, .. } => {
|
||||
if let Some((ref sc_id, _)) = cmb.used_swap_chain {
|
||||
assert_eq!(
|
||||
source_id.value, sc_id.value,
|
||||
"Texture view's swap chain must match swap chain in use"
|
||||
);
|
||||
if source_id.value != sc_id.value {
|
||||
return Err(RenderPassError::SwapChainMismatch);
|
||||
}
|
||||
} else {
|
||||
assert!(used_swap_chain.is_none());
|
||||
used_swap_chain = Some(source_id.clone());
|
||||
@@ -673,16 +720,14 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
{
|
||||
let real_attachment_index = match at.resolve_target {
|
||||
Some(resolve_attachment) => {
|
||||
assert_ne!(
|
||||
view_guard[at.attachment].samples,
|
||||
1,
|
||||
"RenderPassColorAttachmentDescriptor's attachment with a resolve_target must be multi-sampled",
|
||||
);
|
||||
assert_eq!(
|
||||
view_guard[resolve_attachment].samples,
|
||||
1,
|
||||
"RenderPassColorAttachmentDescriptor's resolve_target must not be multi-sampled",
|
||||
);
|
||||
if view_guard[at.attachment].samples == 1 {
|
||||
return Err(RenderPassError::InvalidSampleCount);
|
||||
}
|
||||
if view_guard[resolve_attachment].samples != 1 {
|
||||
return Err(
|
||||
RenderPassError::InvalidResolveTargetSampleCount,
|
||||
);
|
||||
}
|
||||
attachment_index + i
|
||||
}
|
||||
None => hal::pass::ATTACHMENT_UNUSED,
|
||||
@@ -882,12 +927,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
num_dynamic_offsets,
|
||||
bind_group_id,
|
||||
} => {
|
||||
assert!(
|
||||
(index as u32) < device.limits.max_bind_groups,
|
||||
"Bind group index {0} is out of range 0..{1} provided by requested max_bind_group limit {1}",
|
||||
index,
|
||||
device.limits.max_bind_groups
|
||||
);
|
||||
if (index as u32) >= device.limits.max_bind_groups {
|
||||
return Err(RenderCommandError::BindGroupIndexOutOfRange.into());
|
||||
}
|
||||
|
||||
let offsets = &base.dynamic_offsets[..num_dynamic_offsets as usize];
|
||||
base.dynamic_offsets = &base.dynamic_offsets[num_dynamic_offsets as usize..];
|
||||
@@ -896,7 +938,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
.bind_groups
|
||||
.use_extend(&*bind_group_guard, bind_group_id, (), ())
|
||||
.unwrap();
|
||||
bind_group.validate_dynamic_bindings(offsets).unwrap();
|
||||
bind_group
|
||||
.validate_dynamic_bindings(offsets)
|
||||
.map_err(RenderPassError::from)?;
|
||||
|
||||
trackers.merge_extend(&bind_group.used);
|
||||
|
||||
@@ -931,15 +975,16 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
.use_extend(&*pipeline_guard, pipeline_id, (), ())
|
||||
.unwrap();
|
||||
|
||||
assert!(
|
||||
context.compatible(&pipeline.pass_context),
|
||||
"The render pipeline output formats and sample count do not match render pass attachment formats!"
|
||||
);
|
||||
assert!(
|
||||
!is_ds_read_only || pipeline.flags.contains(PipelineFlags::DEPTH_STENCIL_READ_ONLY),
|
||||
"Pipeline {:?} is not compatible with the depth-stencil read-only render pass",
|
||||
pipeline_id
|
||||
);
|
||||
if !context.compatible(&pipeline.pass_context) {
|
||||
return Err(RenderCommandError::IncompatiblePipeline.into());
|
||||
}
|
||||
if is_ds_read_only
|
||||
&& pipeline
|
||||
.flags
|
||||
.contains(PipelineFlags::DEPTH_STENCIL_READ_ONLY)
|
||||
{
|
||||
return Err(RenderCommandError::IncompatiblePipeline.into());
|
||||
}
|
||||
|
||||
state
|
||||
.blend_color
|
||||
@@ -1057,7 +1102,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
.buffers
|
||||
.use_extend(&*buffer_guard, buffer_id, (), BufferUse::INDEX)
|
||||
.unwrap();
|
||||
assert!(buffer.usage.contains(BufferUsage::INDEX), "An invalid setIndexBuffer call has been made. The buffer usage is {:?} which does not contain required usage INDEX", buffer.usage);
|
||||
if !buffer.usage.contains(wgt::BufferUsage::INDEX) {
|
||||
return Err(RenderCommandError::InvalidBufferUsage.into());
|
||||
}
|
||||
|
||||
let end = match size {
|
||||
Some(s) => offset + s.get(),
|
||||
@@ -1089,7 +1136,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
.buffers
|
||||
.use_extend(&*buffer_guard, buffer_id, (), BufferUse::VERTEX)
|
||||
.unwrap();
|
||||
assert!(buffer.usage.contains(BufferUsage::VERTEX), "An invalid setVertexBuffer call has been made. The buffer usage is {:?} which does not contain required usage VERTEX", buffer.usage);
|
||||
if !buffer.usage.contains(wgt::BufferUsage::VERTEX) {
|
||||
return Err(RenderCommandError::InvalidBufferUsage.into());
|
||||
}
|
||||
let empty_slots = (1 + slot as usize).saturating_sub(state.vertex.inputs.len());
|
||||
state
|
||||
.vertex
|
||||
@@ -1149,22 +1198,23 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
size_bytes,
|
||||
values_offset,
|
||||
} => {
|
||||
let values_offset = values_offset
|
||||
.expect("values_offset of None is only for internal use in renderbundles");
|
||||
let values_offset =
|
||||
values_offset.ok_or(RenderPassError::InvalidValuesOffset)?;
|
||||
|
||||
let end_offset_bytes = offset + size_bytes;
|
||||
let values_end_offset = (values_offset + size_bytes / 4) as usize;
|
||||
let data_slice =
|
||||
&base.push_constant_data[(values_offset as usize)..values_end_offset];
|
||||
|
||||
let pipeline_layout = &pipeline_layout_guard[state
|
||||
let pipeline_layout_id = state
|
||||
.binder
|
||||
.pipeline_layout_id
|
||||
.expect("Must have a pipeline bound to use push constants")];
|
||||
.ok_or(RenderCommandError::UnboundPipeline)?;
|
||||
let pipeline_layout = &pipeline_layout_guard[pipeline_layout_id];
|
||||
|
||||
pipeline_layout
|
||||
.validate_push_constant_ranges(stages, offset, end_offset_bytes)
|
||||
.unwrap();
|
||||
.map_err(RenderCommandError::from)?;
|
||||
|
||||
unsafe {
|
||||
raw.push_graphics_constants(
|
||||
@@ -1193,19 +1243,13 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
first_vertex,
|
||||
first_instance,
|
||||
} => {
|
||||
state.is_ready().unwrap();
|
||||
assert!(
|
||||
first_vertex + vertex_count <= state.vertex.vertex_limit,
|
||||
"Vertex {} extends beyond limit {}",
|
||||
first_vertex + vertex_count,
|
||||
state.vertex.vertex_limit
|
||||
);
|
||||
assert!(
|
||||
first_instance + instance_count <= state.vertex.instance_limit,
|
||||
"Instance {} extends beyond limit {}",
|
||||
first_instance + instance_count,
|
||||
state.vertex.instance_limit
|
||||
);
|
||||
state.is_ready()?;
|
||||
if first_vertex + vertex_count > state.vertex.vertex_limit {
|
||||
return Err(RenderCommandError::VertexBeyondLimit.into());
|
||||
}
|
||||
if first_instance + instance_count > state.vertex.instance_limit {
|
||||
return Err(RenderCommandError::InstanceBeyondLimit.into());
|
||||
}
|
||||
|
||||
unsafe {
|
||||
raw.draw(
|
||||
@@ -1221,21 +1265,15 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
base_vertex,
|
||||
first_instance,
|
||||
} => {
|
||||
state.is_ready().unwrap();
|
||||
state.is_ready()?;
|
||||
|
||||
//TODO: validate that base_vertex + max_index() is within the provided range
|
||||
assert!(
|
||||
first_index + index_count <= state.index.limit,
|
||||
"Index {} extends beyond limit {}",
|
||||
first_index + index_count,
|
||||
state.index.limit
|
||||
);
|
||||
assert!(
|
||||
first_instance + instance_count <= state.vertex.instance_limit,
|
||||
"Instance {} extends beyond limit {}",
|
||||
first_instance + instance_count,
|
||||
state.vertex.instance_limit
|
||||
);
|
||||
if first_index + index_count > state.index.limit {
|
||||
return Err(RenderCommandError::IndexBeyondLimit.into());
|
||||
}
|
||||
if first_instance + instance_count > state.vertex.instance_limit {
|
||||
return Err(RenderCommandError::InstanceBeyondLimit.into());
|
||||
}
|
||||
|
||||
unsafe {
|
||||
raw.draw_indexed(
|
||||
@@ -1251,14 +1289,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
count,
|
||||
indexed,
|
||||
} => {
|
||||
state.is_ready().unwrap();
|
||||
|
||||
let name = match (count, indexed) {
|
||||
(None, false) => "drawIndirect",
|
||||
(None, true) => "drawIndexedIndirect",
|
||||
(Some(..), false) => "multiDrawIndirect",
|
||||
(Some(..), true) => "multiDrawIndexedIndirect",
|
||||
};
|
||||
state.is_ready()?;
|
||||
|
||||
let stride = match indexed {
|
||||
false => 16,
|
||||
@@ -1266,38 +1297,27 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
};
|
||||
|
||||
if count.is_some() {
|
||||
assert!(
|
||||
device.features.contains(wgt::Features::MULTI_DRAW_INDIRECT),
|
||||
"The feature MULTI_DRAW_INDIRECT must be enabled to use {}",
|
||||
name
|
||||
);
|
||||
if !device.features.contains(wgt::Features::MULTI_DRAW_INDIRECT) {
|
||||
return Err(RenderPassError::MissingDeviceFeature(
|
||||
"MULTI_DRAW_INDIRECT",
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
let buffer = trackers
|
||||
.buffers
|
||||
.use_extend(&*buffer_guard, buffer_id, (), BufferUse::INDIRECT)
|
||||
.unwrap();
|
||||
assert!(
|
||||
buffer.usage.contains(BufferUsage::INDIRECT),
|
||||
"An invalid {} call has been made. The indirect buffer usage is {:?} which does not contain required usage INDIRECT",
|
||||
name,
|
||||
buffer.usage,
|
||||
);
|
||||
if !buffer.usage.contains(BufferUsage::INDIRECT) {
|
||||
return Err(RenderCommandError::InvalidBufferUsage.into());
|
||||
}
|
||||
|
||||
let actual_count = count.unwrap_or(1);
|
||||
|
||||
let begin_offset = offset;
|
||||
let end_offset = offset + stride * actual_count as u64;
|
||||
assert!(
|
||||
end_offset <= buffer.size,
|
||||
"{} with offset {}{} uses bytes {}..{} which overruns indirect buffer of size {}",
|
||||
name,
|
||||
offset,
|
||||
count.map_or_else(String::new, |v| format!(" and count {}", v)),
|
||||
begin_offset,
|
||||
end_offset,
|
||||
buffer.size
|
||||
);
|
||||
if end_offset > buffer.size {
|
||||
return Err(RenderPassError::IndirectBufferOverrun);
|
||||
}
|
||||
|
||||
match indexed {
|
||||
false => unsafe {
|
||||
@@ -1321,70 +1341,46 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
max_count,
|
||||
indexed,
|
||||
} => {
|
||||
state.is_ready().unwrap();
|
||||
|
||||
let name = match indexed {
|
||||
false => "multiDrawIndirectCount",
|
||||
true => "multiDrawIndexedIndirectCount",
|
||||
};
|
||||
state.is_ready()?;
|
||||
|
||||
let stride = match indexed {
|
||||
false => 16,
|
||||
true => 20,
|
||||
};
|
||||
|
||||
assert!(
|
||||
device
|
||||
.features
|
||||
.contains(wgt::Features::MULTI_DRAW_INDIRECT_COUNT),
|
||||
"The feature MULTI_DRAW_INDIRECT_COUNT must be enabled to use {}",
|
||||
name
|
||||
);
|
||||
if !device
|
||||
.features
|
||||
.contains(wgt::Features::MULTI_DRAW_INDIRECT_COUNT)
|
||||
{
|
||||
return Err(RenderPassError::MissingDeviceFeature(
|
||||
"MULTI_DRAW_INDIRECT_COUNT",
|
||||
));
|
||||
}
|
||||
|
||||
let buffer = trackers
|
||||
.buffers
|
||||
.use_extend(&*buffer_guard, buffer_id, (), BufferUse::INDIRECT)
|
||||
.unwrap();
|
||||
assert!(
|
||||
buffer.usage.contains(BufferUsage::INDIRECT),
|
||||
"An invalid {} call has been made. The indirect buffer usage is {:?} which does not contain required usage INDIRECT",
|
||||
name,
|
||||
buffer.usage
|
||||
);
|
||||
if !buffer.usage.contains(BufferUsage::INDIRECT) {
|
||||
return Err(RenderCommandError::InvalidBufferUsage.into());
|
||||
}
|
||||
let count_buffer = trackers
|
||||
.buffers
|
||||
.use_extend(&*buffer_guard, count_buffer_id, (), BufferUse::INDIRECT)
|
||||
.unwrap();
|
||||
assert!(
|
||||
count_buffer.usage.contains(BufferUsage::INDIRECT),
|
||||
"An invalid {} call has been made. The count buffer usage is {:?} which does not contain required usage INDIRECT",
|
||||
name,
|
||||
count_buffer.usage
|
||||
);
|
||||
if !count_buffer.usage.contains(BufferUsage::INDIRECT) {
|
||||
return Err(RenderCommandError::InvalidBufferUsage.into());
|
||||
}
|
||||
|
||||
let begin_offset = offset;
|
||||
let end_offset = offset + stride * max_count as u64;
|
||||
assert!(
|
||||
end_offset <= buffer.size,
|
||||
"{} with offset {} and max_count {} uses bytes {}..{} which overruns indirect buffer of size {}",
|
||||
name,
|
||||
offset,
|
||||
max_count,
|
||||
begin_offset,
|
||||
end_offset,
|
||||
buffer.size
|
||||
);
|
||||
if end_offset > buffer.size {
|
||||
return Err(RenderPassError::IndirectBufferOverrun);
|
||||
}
|
||||
|
||||
let begin_count_offset = count_buffer_offset;
|
||||
let end_count_offset = count_buffer_offset + 4;
|
||||
assert!(
|
||||
end_count_offset <= count_buffer.size,
|
||||
"{} uses bytes {}..{} which overruns count buffer of size {}",
|
||||
name,
|
||||
begin_count_offset,
|
||||
end_count_offset,
|
||||
count_buffer.size
|
||||
);
|
||||
if end_count_offset > count_buffer.size {
|
||||
return Err(RenderPassError::IndirectBufferOverrun);
|
||||
}
|
||||
|
||||
match indexed {
|
||||
false => unsafe {
|
||||
@@ -1418,10 +1414,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
base.string_data = &base.string_data[len..];
|
||||
}
|
||||
RenderCommand::PopDebugGroup => {
|
||||
assert_ne!(
|
||||
state.debug_scope_depth, 0,
|
||||
"Can't pop debug group, because number of pushed debug groups is zero!"
|
||||
);
|
||||
if state.debug_scope_depth == 0 {
|
||||
return Err(RenderPassError::InvalidPopDebugGroup);
|
||||
}
|
||||
state.debug_scope_depth -= 1;
|
||||
unsafe {
|
||||
raw.end_debug_marker();
|
||||
@@ -1439,10 +1434,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
.use_extend(&*bundle_guard, bundle_id, (), ())
|
||||
.unwrap();
|
||||
|
||||
assert!(
|
||||
context.compatible(&bundle.context),
|
||||
"The render bundle output formats do not match render pass attachment formats!"
|
||||
);
|
||||
if !context.compatible(&bundle.context) {
|
||||
return Err(RenderPassError::IncompatibleRenderBundle);
|
||||
}
|
||||
|
||||
unsafe {
|
||||
bundle.execute(
|
||||
@@ -1451,8 +1445,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
&*bind_group_guard,
|
||||
&*pipeline_guard,
|
||||
&*buffer_guard,
|
||||
)
|
||||
};
|
||||
)?;
|
||||
}
|
||||
|
||||
trackers.merge_extend(&bundle.used);
|
||||
state.reset_bundle();
|
||||
@@ -1467,11 +1461,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
|
||||
for ot in output_attachments {
|
||||
let texture = &texture_guard[ot.texture_id.value];
|
||||
assert!(
|
||||
texture.usage.contains(TextureUsage::OUTPUT_ATTACHMENT),
|
||||
"Texture usage {:?} must contain the usage flag OUTPUT_ATTACHMENT",
|
||||
texture.usage
|
||||
);
|
||||
if !texture.usage.contains(TextureUsage::OUTPUT_ATTACHMENT) {
|
||||
return Err(RenderCommandError::InvalidTextureUsage.into());
|
||||
}
|
||||
|
||||
// the tracker set of the pass is always in "extend" mode
|
||||
trackers
|
||||
@@ -1511,6 +1503,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
cmb.raw.last_mut().unwrap().finish();
|
||||
}
|
||||
cmb.raw.push(raw);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2120,10 +2120,10 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
&self,
|
||||
device_id: id::DeviceId,
|
||||
desc: &wgt::RenderBundleEncoderDescriptor,
|
||||
) -> id::RenderBundleEncoderId {
|
||||
) -> Result<id::RenderBundleEncoderId, command::InvalidSampleCountError> {
|
||||
span!(_guard, INFO, "Device::create_render_bundle_encoder");
|
||||
let encoder = command::RenderBundleEncoder::new(desc, device_id, None);
|
||||
Box::into_raw(Box::new(encoder))
|
||||
encoder.map(|encoder| Box::into_raw(Box::new(encoder)))
|
||||
}
|
||||
|
||||
pub fn render_bundle_destroy<B: GfxBackend>(&self, render_bundle_id: id::RenderBundleId) {
|
||||
|
||||
Reference in new issue
Block a user