[deno] Fix alignment check for mappedAtCreation buffers (#8700)

This commit is contained in:
Andy Leiserson authored and GitHub committed 2025-12-10 15:15:37 -05:00
1 parent fc9912ed30
commit 660b21c571
2 files changed
+19 -3

No files matched your search

+2
View File
@@ -31,6 +31,8 @@ webgpu:api,operation,render_pass,storeOp:*
fails-if(vulkan) webgpu:api,operation,vertex_state,correctness:array_stride_zero:*
// Presumably vertex pulling, revisit after https://github.com/gfx-rs/wgpu/issues/7981 is fixed.
fails-if(metal) webgpu:api,operation,vertex_state,correctness:setVertexBuffer_offset_and_attribute_offset:*
webgpu:api,validation,buffer,create:*
webgpu:api,validation,buffer,destroy:*
fails-if(dx12) webgpu:api,validation,capability_checks,limits,maxBindGroups:setBindGroup,*
webgpu:api,validation,createBindGroup:buffer,effective_buffer_binding_size:*
// Fails because we coerce a size of 0 in `GPUDevice.createBindGroup(…)` to `buffer.size - offset`.
+17 -3
View File
@@ -150,7 +150,21 @@ impl GPUDevice {
fn create_buffer(
&self,
#[webidl] descriptor: super::buffer::GPUBufferDescriptor,
) -> GPUBuffer {
) -> Result<GPUBuffer, JsErrorBox> {
// wgpu-core would also check this, but it needs to be reported via a JS
// error, not a validation error. (WebGPU specifies this check on the
// content timeline.)
if descriptor.mapped_at_creation
&& descriptor.size % wgpu_types::COPY_BUFFER_ALIGNMENT != 0
{
return Err(JsErrorBox::range_error(
format!(
"The size of a buffer that is mapped at creation must be a multiple of {}",
wgpu_types::COPY_BUFFER_ALIGNMENT,
)
));
}
// Validation of the usage needs to happen on the device timeline, so
// don't raise an error immediately if it isn't valid. wgpu will
// reject `BufferUsages::empty()`.
@@ -171,7 +185,7 @@ impl GPUDevice {
self.error_handler.push_error(err);
GPUBuffer {
Ok(GPUBuffer {
instance: self.instance.clone(),
error_handler: self.error_handler.clone(),
id,
@@ -190,7 +204,7 @@ impl GPUDevice {
None
}),
mapped_js_buffers: RefCell::new(vec![]),
}
})
}
#[required(1)]