Skip to content

Commit 660b21c

Browse files
[deno] Fix alignment check for mappedAtCreation buffers (gfx-rs#8700)
1 parent fc9912e commit 660b21c

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

cts_runner/test.lst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ webgpu:api,operation,render_pass,storeOp:*
3131
fails-if(vulkan) webgpu:api,operation,vertex_state,correctness:array_stride_zero:*
3232
// Presumably vertex pulling, revisit after https://github.com/gfx-rs/wgpu/issues/7981 is fixed.
3333
fails-if(metal) webgpu:api,operation,vertex_state,correctness:setVertexBuffer_offset_and_attribute_offset:*
34+
webgpu:api,validation,buffer,create:*
35+
webgpu:api,validation,buffer,destroy:*
3436
fails-if(dx12) webgpu:api,validation,capability_checks,limits,maxBindGroups:setBindGroup,*
3537
webgpu:api,validation,createBindGroup:buffer,effective_buffer_binding_size:*
3638
// Fails because we coerce a size of 0 in `GPUDevice.createBindGroup(…)` to `buffer.size - offset`.

deno_webgpu/device.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,21 @@ impl GPUDevice {
150150
fn create_buffer(
151151
&self,
152152
#[webidl] descriptor: super::buffer::GPUBufferDescriptor,
153-
) -> GPUBuffer {
153+
) -> Result<GPUBuffer, JsErrorBox> {
154+
// wgpu-core would also check this, but it needs to be reported via a JS
155+
// error, not a validation error. (WebGPU specifies this check on the
156+
// content timeline.)
157+
if descriptor.mapped_at_creation
158+
&& descriptor.size % wgpu_types::COPY_BUFFER_ALIGNMENT != 0
159+
{
160+
return Err(JsErrorBox::range_error(
161+
format!(
162+
"The size of a buffer that is mapped at creation must be a multiple of {}",
163+
wgpu_types::COPY_BUFFER_ALIGNMENT,
164+
)
165+
));
166+
}
167+
154168
// Validation of the usage needs to happen on the device timeline, so
155169
// don't raise an error immediately if it isn't valid. wgpu will
156170
// reject `BufferUsages::empty()`.
@@ -171,7 +185,7 @@ impl GPUDevice {
171185

172186
self.error_handler.push_error(err);
173187

174-
GPUBuffer {
188+
Ok(GPUBuffer {
175189
instance: self.instance.clone(),
176190
error_handler: self.error_handler.clone(),
177191
id,
@@ -190,7 +204,7 @@ impl GPUDevice {
190204
None
191205
}),
192206
mapped_js_buffers: RefCell::new(vec![]),
193-
}
207+
})
194208
}
195209

196210
#[required(1)]

0 commit comments

Comments
 (0)