mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
webgpu: Align writeBuffer
with spec (#33147)
* Sync `WriteBuffer` Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> * Set good expectations Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> * Change assert to debug_assert Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> --------- Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This commit is contained in:
parent
3b8c638a84
commit
65bd5a3b99
4 changed files with 24 additions and 37 deletions
6
Cargo.lock
generated
6
Cargo.lock
generated
|
@ -4328,7 +4328,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mozjs"
|
name = "mozjs"
|
||||||
version = "0.14.1"
|
version = "0.14.1"
|
||||||
source = "git+https://github.com/servo/mozjs#4f0724dd3b9b58120903ff6a1043e71e7c7b9eb1"
|
source = "git+https://github.com/servo/mozjs#d90edd169aae1e16c1ef8b7bd4b2e0d93dda8ba2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bindgen",
|
"bindgen",
|
||||||
"cc",
|
"cc",
|
||||||
|
@ -4340,8 +4340,8 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mozjs_sys"
|
name = "mozjs_sys"
|
||||||
version = "0.128.0-8"
|
version = "0.128.0-9"
|
||||||
source = "git+https://github.com/servo/mozjs#4f0724dd3b9b58120903ff6a1043e71e7c7b9eb1"
|
source = "git+https://github.com/servo/mozjs#d90edd169aae1e16c1ef8b7bd4b2e0d93dda8ba2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bindgen",
|
"bindgen",
|
||||||
"cc",
|
"cc",
|
||||||
|
|
|
@ -116,33 +116,45 @@ impl GPUQueueMethods for GPUQueue {
|
||||||
data_offset: GPUSize64,
|
data_offset: GPUSize64,
|
||||||
size: Option<GPUSize64>,
|
size: Option<GPUSize64>,
|
||||||
) -> Fallible<()> {
|
) -> Fallible<()> {
|
||||||
let bytes = match data {
|
// Step 1
|
||||||
|
let sizeof_element: usize = match data {
|
||||||
|
BufferSource::ArrayBufferView(ref d) => d.get_array_type().byte_size().unwrap_or(1),
|
||||||
|
BufferSource::ArrayBuffer(_) => 1,
|
||||||
|
};
|
||||||
|
let data = match data {
|
||||||
BufferSource::ArrayBufferView(d) => d.to_vec(),
|
BufferSource::ArrayBufferView(d) => d.to_vec(),
|
||||||
BufferSource::ArrayBuffer(d) => d.to_vec(),
|
BufferSource::ArrayBuffer(d) => d.to_vec(),
|
||||||
};
|
};
|
||||||
|
// Step 2
|
||||||
|
let data_size: usize = data.len() / sizeof_element;
|
||||||
|
debug_assert_eq!(data.len() % sizeof_element, 0);
|
||||||
|
// Step 3
|
||||||
let content_size = if let Some(s) = size {
|
let content_size = if let Some(s) = size {
|
||||||
s
|
s
|
||||||
} else {
|
} else {
|
||||||
bytes.len() as GPUSize64 - data_offset
|
(data_size as GPUSize64)
|
||||||
|
.checked_sub(data_offset)
|
||||||
|
.ok_or(Error::Operation)?
|
||||||
};
|
};
|
||||||
let valid = data_offset + content_size <= bytes.len() as u64 &&
|
|
||||||
buffer.state() == GPUBufferState::Unmapped &&
|
|
||||||
content_size % wgt::COPY_BUFFER_ALIGNMENT == 0 &&
|
|
||||||
buffer_offset % wgt::COPY_BUFFER_ALIGNMENT == 0;
|
|
||||||
|
|
||||||
|
// Step 4
|
||||||
|
let valid = data_offset + content_size <= data_size as u64 &&
|
||||||
|
content_size * sizeof_element as u64 % wgt::COPY_BUFFER_ALIGNMENT == 0;
|
||||||
if !valid {
|
if !valid {
|
||||||
return Err(Error::Operation);
|
return Err(Error::Operation);
|
||||||
}
|
}
|
||||||
|
|
||||||
let final_data = IpcSharedMemory::from_bytes(
|
// Step 5&6
|
||||||
&bytes[data_offset as usize..(data_offset + content_size) as usize],
|
let contents = IpcSharedMemory::from_bytes(
|
||||||
|
&data[(data_offset as usize) * sizeof_element..
|
||||||
|
((data_offset + content_size) as usize) * sizeof_element],
|
||||||
);
|
);
|
||||||
if let Err(e) = self.channel.0.send(WebGPURequest::WriteBuffer {
|
if let Err(e) = self.channel.0.send(WebGPURequest::WriteBuffer {
|
||||||
device_id: self.device.borrow().as_ref().unwrap().id().0,
|
device_id: self.device.borrow().as_ref().unwrap().id().0,
|
||||||
queue_id: self.queue.0,
|
queue_id: self.queue.0,
|
||||||
buffer_id: buffer.id().0,
|
buffer_id: buffer.id().0,
|
||||||
buffer_offset,
|
buffer_offset,
|
||||||
data: final_data,
|
data: contents,
|
||||||
}) {
|
}) {
|
||||||
warn!("Failed to send WriteBuffer({:?}) ({})", buffer.id(), e);
|
warn!("Failed to send WriteBuffer({:?}) ({})", buffer.id(), e);
|
||||||
return Err(Error::Operation);
|
return Err(Error::Operation);
|
||||||
|
|
|
@ -1242,7 +1242,6 @@ impl WGPU {
|
||||||
data,
|
data,
|
||||||
} => {
|
} => {
|
||||||
let global = &self.global;
|
let global = &self.global;
|
||||||
//TODO: Report result to content process
|
|
||||||
let result = gfx_select!(queue_id => global.queue_write_buffer(
|
let result = gfx_select!(queue_id => global.queue_write_buffer(
|
||||||
queue_id,
|
queue_id,
|
||||||
buffer_id,
|
buffer_id,
|
||||||
|
|
24
tests/wpt/webgpu/meta/webgpu/cts.https.html.ini
vendored
24
tests/wpt/webgpu/meta/webgpu/cts.https.html.ini
vendored
|
@ -4397,26 +4397,18 @@
|
||||||
|
|
||||||
[cts.https.html?q=webgpu:api,operation,queue,writeBuffer:array_types:*]
|
[cts.https.html?q=webgpu:api,operation,queue,writeBuffer:array_types:*]
|
||||||
[:arrayType="Float32Array";useArrayBuffer=false]
|
[:arrayType="Float32Array";useArrayBuffer=false]
|
||||||
expected:
|
|
||||||
if os == "linux" and not debug: FAIL
|
|
||||||
|
|
||||||
[:arrayType="Float32Array";useArrayBuffer=true]
|
[:arrayType="Float32Array";useArrayBuffer=true]
|
||||||
|
|
||||||
[:arrayType="Float64Array";useArrayBuffer=false]
|
[:arrayType="Float64Array";useArrayBuffer=false]
|
||||||
expected:
|
|
||||||
if os == "linux" and not debug: FAIL
|
|
||||||
|
|
||||||
[:arrayType="Float64Array";useArrayBuffer=true]
|
[:arrayType="Float64Array";useArrayBuffer=true]
|
||||||
|
|
||||||
[:arrayType="Int16Array";useArrayBuffer=false]
|
[:arrayType="Int16Array";useArrayBuffer=false]
|
||||||
expected:
|
|
||||||
if os == "linux" and not debug: FAIL
|
|
||||||
|
|
||||||
[:arrayType="Int16Array";useArrayBuffer=true]
|
[:arrayType="Int16Array";useArrayBuffer=true]
|
||||||
|
|
||||||
[:arrayType="Int32Array";useArrayBuffer=false]
|
[:arrayType="Int32Array";useArrayBuffer=false]
|
||||||
expected:
|
|
||||||
if os == "linux" and not debug: FAIL
|
|
||||||
|
|
||||||
[:arrayType="Int32Array";useArrayBuffer=true]
|
[:arrayType="Int32Array";useArrayBuffer=true]
|
||||||
|
|
||||||
|
@ -4425,14 +4417,10 @@
|
||||||
[:arrayType="Int8Array";useArrayBuffer=true]
|
[:arrayType="Int8Array";useArrayBuffer=true]
|
||||||
|
|
||||||
[:arrayType="Uint16Array";useArrayBuffer=false]
|
[:arrayType="Uint16Array";useArrayBuffer=false]
|
||||||
expected:
|
|
||||||
if os == "linux" and not debug: FAIL
|
|
||||||
|
|
||||||
[:arrayType="Uint16Array";useArrayBuffer=true]
|
[:arrayType="Uint16Array";useArrayBuffer=true]
|
||||||
|
|
||||||
[:arrayType="Uint32Array";useArrayBuffer=false]
|
[:arrayType="Uint32Array";useArrayBuffer=false]
|
||||||
expected:
|
|
||||||
if os == "linux" and not debug: FAIL
|
|
||||||
|
|
||||||
[:arrayType="Uint32Array";useArrayBuffer=true]
|
[:arrayType="Uint32Array";useArrayBuffer=true]
|
||||||
|
|
||||||
|
@ -5381,20 +5369,12 @@
|
||||||
|
|
||||||
[cts.https.html?q=webgpu:api,operation,rendering,basic:large_draw:*]
|
[cts.https.html?q=webgpu:api,operation,rendering,basic:large_draw:*]
|
||||||
[:indexed=false;indirect=false]
|
[:indexed=false;indirect=false]
|
||||||
expected:
|
|
||||||
if os == "linux" and not debug: FAIL
|
|
||||||
|
|
||||||
[:indexed=false;indirect=true]
|
[:indexed=false;indirect=true]
|
||||||
expected:
|
|
||||||
if os == "linux" and not debug: FAIL
|
|
||||||
|
|
||||||
[:indexed=true;indirect=false]
|
[:indexed=true;indirect=false]
|
||||||
expected:
|
|
||||||
if os == "linux" and not debug: FAIL
|
|
||||||
|
|
||||||
[:indexed=true;indirect=true]
|
[:indexed=true;indirect=true]
|
||||||
expected:
|
|
||||||
if os == "linux" and not debug: FAIL
|
|
||||||
|
|
||||||
|
|
||||||
[cts.https.html?q=webgpu:api,operation,rendering,color_target_state:blend_constant,initial:*]
|
[cts.https.html?q=webgpu:api,operation,rendering,color_target_state:blend_constant,initial:*]
|
||||||
|
@ -47615,8 +47595,6 @@
|
||||||
|
|
||||||
[cts.https.html?q=webgpu:api,validation,queue,destroyed,buffer:writeBuffer:*]
|
[cts.https.html?q=webgpu:api,validation,queue,destroyed,buffer:writeBuffer:*]
|
||||||
[:]
|
[:]
|
||||||
expected:
|
|
||||||
if os == "linux" and not debug: FAIL
|
|
||||||
|
|
||||||
|
|
||||||
[cts.https.html?q=webgpu:api,validation,queue,destroyed,query_set:beginOcclusionQuery:*]
|
[cts.https.html?q=webgpu:api,validation,queue,destroyed,query_set:beginOcclusionQuery:*]
|
||||||
|
@ -47691,8 +47669,6 @@
|
||||||
|
|
||||||
[cts.https.html?q=webgpu:api,validation,queue,writeBuffer:buffer_state:*]
|
[cts.https.html?q=webgpu:api,validation,queue,writeBuffer:buffer_state:*]
|
||||||
[:bufferState="destroyed"]
|
[:bufferState="destroyed"]
|
||||||
expected:
|
|
||||||
if os == "linux" and not debug: FAIL
|
|
||||||
|
|
||||||
[:bufferState="invalid"]
|
[:bufferState="invalid"]
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue