aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamson <16504129+sagudev@users.noreply.github.com>2024-08-21 13:46:23 +0200
committerGitHub <noreply@github.com>2024-08-21 11:46:23 +0000
commit65bd5a3b9982c9af453fe97134e4f91e55b1df19 (patch)
treea44f48ce3471367533eb0490b24673b948b41a2c
parent3b8c638a845ac21cb42a87434130dbd8e7b5107e (diff)
downloadservo-65bd5a3b9982c9af453fe97134e4f91e55b1df19.tar.gz
servo-65bd5a3b9982c9af453fe97134e4f91e55b1df19.zip
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>
-rw-r--r--Cargo.lock6
-rw-r--r--components/script/dom/gpuqueue.rs30
-rw-r--r--components/webgpu/wgpu_thread.rs1
-rw-r--r--tests/wpt/webgpu/meta/webgpu/cts.https.html.ini24
4 files changed, 24 insertions, 37 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 893fc04ddae..7165ce16023 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -4328,7 +4328,7 @@ dependencies = [
[[package]]
name = "mozjs"
version = "0.14.1"
-source = "git+https://github.com/servo/mozjs#4f0724dd3b9b58120903ff6a1043e71e7c7b9eb1"
+source = "git+https://github.com/servo/mozjs#d90edd169aae1e16c1ef8b7bd4b2e0d93dda8ba2"
dependencies = [
"bindgen",
"cc",
@@ -4340,8 +4340,8 @@ dependencies = [
[[package]]
name = "mozjs_sys"
-version = "0.128.0-8"
-source = "git+https://github.com/servo/mozjs#4f0724dd3b9b58120903ff6a1043e71e7c7b9eb1"
+version = "0.128.0-9"
+source = "git+https://github.com/servo/mozjs#d90edd169aae1e16c1ef8b7bd4b2e0d93dda8ba2"
dependencies = [
"bindgen",
"cc",
diff --git a/components/script/dom/gpuqueue.rs b/components/script/dom/gpuqueue.rs
index f69cc278094..aa0daa5ae0f 100644
--- a/components/script/dom/gpuqueue.rs
+++ b/components/script/dom/gpuqueue.rs
@@ -116,33 +116,45 @@ impl GPUQueueMethods for GPUQueue {
data_offset: GPUSize64,
size: Option<GPUSize64>,
) -> 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::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 {
s
} 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 {
return Err(Error::Operation);
}
- let final_data = IpcSharedMemory::from_bytes(
- &bytes[data_offset as usize..(data_offset + content_size) as usize],
+ // Step 5&6
+ 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 {
device_id: self.device.borrow().as_ref().unwrap().id().0,
queue_id: self.queue.0,
buffer_id: buffer.id().0,
buffer_offset,
- data: final_data,
+ data: contents,
}) {
warn!("Failed to send WriteBuffer({:?}) ({})", buffer.id(), e);
return Err(Error::Operation);
diff --git a/components/webgpu/wgpu_thread.rs b/components/webgpu/wgpu_thread.rs
index cf65b2bd580..a577906bd4e 100644
--- a/components/webgpu/wgpu_thread.rs
+++ b/components/webgpu/wgpu_thread.rs
@@ -1242,7 +1242,6 @@ impl WGPU {
data,
} => {
let global = &self.global;
- //TODO: Report result to content process
let result = gfx_select!(queue_id => global.queue_write_buffer(
queue_id,
buffer_id,
diff --git a/tests/wpt/webgpu/meta/webgpu/cts.https.html.ini b/tests/wpt/webgpu/meta/webgpu/cts.https.html.ini
index 303af4bc340..718a26320e0 100644
--- a/tests/wpt/webgpu/meta/webgpu/cts.https.html.ini
+++ b/tests/wpt/webgpu/meta/webgpu/cts.https.html.ini
@@ -4397,26 +4397,18 @@
[cts.https.html?q=webgpu:api,operation,queue,writeBuffer:array_types:*]
[:arrayType="Float32Array";useArrayBuffer=false]
- expected:
- if os == "linux" and not debug: FAIL
[:arrayType="Float32Array";useArrayBuffer=true]
[:arrayType="Float64Array";useArrayBuffer=false]
- expected:
- if os == "linux" and not debug: FAIL
[:arrayType="Float64Array";useArrayBuffer=true]
[:arrayType="Int16Array";useArrayBuffer=false]
- expected:
- if os == "linux" and not debug: FAIL
[:arrayType="Int16Array";useArrayBuffer=true]
[:arrayType="Int32Array";useArrayBuffer=false]
- expected:
- if os == "linux" and not debug: FAIL
[:arrayType="Int32Array";useArrayBuffer=true]
@@ -4425,14 +4417,10 @@
[:arrayType="Int8Array";useArrayBuffer=true]
[:arrayType="Uint16Array";useArrayBuffer=false]
- expected:
- if os == "linux" and not debug: FAIL
[:arrayType="Uint16Array";useArrayBuffer=true]
[:arrayType="Uint32Array";useArrayBuffer=false]
- expected:
- if os == "linux" and not debug: FAIL
[:arrayType="Uint32Array";useArrayBuffer=true]
@@ -5381,20 +5369,12 @@
[cts.https.html?q=webgpu:api,operation,rendering,basic:large_draw:*]
[:indexed=false;indirect=false]
- expected:
- if os == "linux" and not debug: FAIL
[:indexed=false;indirect=true]
- expected:
- if os == "linux" and not debug: FAIL
[:indexed=true;indirect=false]
- expected:
- if os == "linux" and not debug: FAIL
[: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:*]
@@ -47615,8 +47595,6 @@
[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:*]
@@ -47691,8 +47669,6 @@
[cts.https.html?q=webgpu:api,validation,queue,writeBuffer:buffer_state:*]
[:bufferState="destroyed"]
- expected:
- if os == "linux" and not debug: FAIL
[:bufferState="invalid"]