diff --git a/CHANGELOG.md b/CHANGELOG.md index 4360ce160..0de389796 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -65,6 +65,10 @@ Naga now requires that no type be larger than 1 GB. This limit may be lowered in ### Bug Fixes +#### General + +- Validate that effective buffer binding size is aligned to 4 when creating bind groups with buffer entries.. By @ErichDonGubler in [8041](https://github.com/gfx-rs/wgpu/pull/8041). + #### Vulkan Fix `STATUS_HEAP_CORRUPTION` crash when concurrently calling `create_sampler`. By @atlv24 in [#8043](https://github.com/gfx-rs/wgpu/pull/8043). diff --git a/cts_runner/test.lst b/cts_runner/test.lst index 26c1db582..7282bef2c 100644 --- a/cts_runner/test.lst +++ b/cts_runner/test.lst @@ -19,6 +19,7 @@ webgpu:api,operation,render_pass,storeOp:render_pass_store_op,color_attachment_w webgpu:api,operation,render_pass,storeOp:render_pass_store_op,color_attachment_only:* webgpu:api,operation,render_pass,storeOp:render_pass_store_op,multiple_color_attachments:* webgpu:api,operation,render_pass,storeOp:render_pass_store_op,depth_stencil_attachment_only:* +webgpu:api,validation,createBindGroup:buffer,effective_buffer_binding_size:* webgpu:api,validation,encoding,beginComputePass:* webgpu:api,validation,encoding,beginRenderPass:* webgpu:api,validation,encoding,cmds,clearBuffer:* diff --git a/wgpu-core/src/binding_model.rs b/wgpu-core/src/binding_model.rs index 30d8a99a9..2cbac7bfa 100644 --- a/wgpu-core/src/binding_model.rs +++ b/wgpu-core/src/binding_model.rs @@ -167,6 +167,8 @@ pub enum CreateBindGroupError { MissingTextureUsage(#[from] MissingTextureUsageError), #[error("Binding declared as a single item, but bind group is using it as an array")] SingleBindingExpected, + #[error("Effective buffer binding size {size} for storage buffers is expected to align to {alignment}, but size is {size}")] + UnalignedEffectiveBufferBindingSizeForStorage { alignment: u8, size: u64 }, #[error("Buffer offset {0} does not respect device's requested `{1}` limit {2}")] UnalignedBufferOffset(wgt::BufferAddress, &'static str, u32), #[error( @@ -275,6 +277,7 @@ impl WebGpuError for CreateBindGroupError { | Self::DuplicateBinding(_) | Self::MissingBindingDeclaration(_) | Self::SingleBindingExpected + | Self::UnalignedEffectiveBufferBindingSizeForStorage { .. } | Self::UnalignedBufferOffset(_, _, _) | Self::BufferRangeTooLarge { .. } | Self::WrongBindingType { .. } diff --git a/wgpu-core/src/device/resource.rs b/wgpu-core/src/device/resource.rs index b55676ea5..eed295bdf 100644 --- a/wgpu-core/src/device/resource.rs +++ b/wgpu-core/src/device/resource.rs @@ -2542,6 +2542,19 @@ impl Device { buffer.check_usage(pub_usage)?; let (bb, bind_size) = buffer.binding(bb.offset, bb.size, snatch_guard)?; + + if matches!(binding_ty, wgt::BufferBindingType::Storage { .. }) { + let storage_buf_size_alignment = 4; + + let aligned = bind_size % u64::from(storage_buf_size_alignment) == 0; + if !aligned { + return Err(Error::UnalignedEffectiveBufferBindingSizeForStorage { + alignment: storage_buf_size_alignment, + size: bind_size, + }); + } + } + let bind_end = bb.offset + bind_size; if bind_size > range_limit as u64 {