Skip to content

Commit 4c59919

Browse files
committed
Revive the CTS job
Includes the following minor functional fixes to deno_webgpu: * Don't throw an error immediately when `create_buffer` is called with invalid usage flags. * Implement `on_submitted_work_done`. * Correct validation of GPUExtent3D element count. * Run without tracing (instead of panic) if the DENO_WEBGPU_TRACE env var is not set. Fixes gfx-rs#6838
1 parent 26bab56 commit 4c59919

File tree

10 files changed

+171
-41
lines changed

10 files changed

+171
-41
lines changed

.github/workflows/cts.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: CTS
2+
3+
on:
4+
pull_request:
5+
types: [labeled, opened, synchronize]
6+
workflow_dispatch:
7+
8+
env:
9+
CARGO_INCREMENTAL: false
10+
CARGO_TERM_COLOR: always
11+
RUST_BACKTRACE: full
12+
MSRV: "1.84"
13+
14+
jobs:
15+
cts:
16+
# For pull requests, run only run if we add the "PR: run CTS" label
17+
#
18+
if: "github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'PR: run CTS'))"
19+
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
include:
24+
# Windows
25+
- name: Windows x86_64
26+
os: windows-2022
27+
target: x86_64-pc-windows-msvc
28+
backends: dx12
29+
30+
# Linux
31+
#- name: Linux x86_64
32+
# os: ubuntu-20.04
33+
# target: x86_64-unknown-linux-gnu
34+
# backends: vulkan # gl
35+
36+
name: CTS ${{ matrix.name }}
37+
runs-on: ${{ matrix.os }}
38+
39+
steps:
40+
- name: checkout repo
41+
uses: actions/checkout@v4
42+
with:
43+
path: wgpu
44+
45+
- name: checkout cts
46+
run: |
47+
git clone https://github.com/gpuweb/cts.git
48+
cd cts
49+
git checkout $(cat ../wgpu/cts_runner/revision.txt)
50+
51+
- name: Install Repo MSRV toolchain
52+
run: |
53+
rustup toolchain install ${{ env.MSRV }} --no-self-update --profile=minimal --target ${{ matrix.target }}
54+
rustup override set ${{ env.MSRV }}
55+
cargo -V
56+
57+
- name: caching
58+
uses: Swatinem/rust-cache@v2
59+
with:
60+
key: cts-b # suffix for cache busting
61+
workspaces: wgpu
62+
63+
# We enable line numbers for panics, but that's it
64+
- name: disable debug
65+
shell: bash
66+
run: |
67+
mkdir -p wgpu/.cargo
68+
echo """[profile.dev]
69+
debug = 1" > wgpu/.cargo/config.toml
70+
71+
- name: build CTS runner
72+
run: |
73+
cargo build --manifest-path wgpu/cts_runner/Cargo.toml
74+
75+
- name: run CTS
76+
shell: bash
77+
run: |
78+
cd cts;
79+
for backend in ${{ matrix.backends }}; do
80+
echo "======= CTS TESTS $backend ======";
81+
grep -v '^//' ../wgpu/cts_runner/test.lst | while IFS=$' \t\r\n' read test; do
82+
echo "=== Running $test ===";
83+
DENO_WEBGPU_BACKEND=$backend cargo run --manifest-path ../wgpu/cts_runner/Cargo.toml --frozen -- ./tools/run_deno --verbose "$test";
84+
done
85+
done
86+
echo;
87+
echo "Note: Summary reflects only the last test suite, not the entire run."

Cargo.lock

Lines changed: 20 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,11 @@ web-sys = { version = "0.3.77", default-features = false }
231231
web-time = "1"
232232

233233
# deno dependencies
234-
deno_console = "0.190.0"
235-
deno_core = "0.336.0"
236-
deno_url = "0.190.0"
237-
deno_web = "0.221.0"
238-
deno_webidl = "0.190.0"
234+
deno_console = "0.192.0"
235+
deno_core = "0.338.0"
236+
deno_url = "0.192.0"
237+
deno_web = "0.224.0"
238+
deno_webidl = "0.192.0"
239239
deno_webgpu = { version = "0.157.0", path = "./deno_webgpu" }
240240
deno_unsync = "0.4.2"
241241
deno_error = "0.5.5"

cts_runner/revision.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7ea73ba6f44c9f6fedfffc06f14c73ea9f2eaa11
1+
049916a6191725aad5a5692e5a22df47d45c88fa

cts_runner/src/bootstrap.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import * as performance from "ext:deno_web/15_performance.js";
2929
import { loadWebGPU } from "ext:deno_webgpu/00_init.js";
3030
import * as imageData from "ext:deno_web/16_image_data.js";
3131
const webgpu = loadWebGPU();
32+
webgpu.initGPU();
3233

3334
// imports needed to pass module evaluation
3435
import "ext:deno_url/01_urlpattern.js";

cts_runner/test.lst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
unittests:*
22
webgpu:api,operation,command_buffer,basic:*
33
webgpu:api,operation,compute,basic:*
4+
webgpu:api,operation,device,lost:*
45
webgpu:api,operation,rendering,basic:clear:*
56
webgpu:api,operation,rendering,basic:fullscreen_quad:*
67
//FAIL: webgpu:api,operation,rendering,basic:large_draw:*
7-
webgpu:api,operation,rendering,blending:*
8-
webgpu:api,operation,rendering,blending:GPUBlendComponent:*
8+
webgpu:api,operation,rendering,color_target_state:blending,GPUBlendComponent:*
9+
webgpu:api,operation,rendering,color_target_state:blending,formats:*
10+
webgpu:api,operation,rendering,color_target_state:blend_constant,setting:*
911
webgpu:api,operation,rendering,depth:*
1012
webgpu:api,operation,rendering,draw:*
13+
// https://github.com/gfx-rs/wgpu/issues/7391
14+
//FAIL: webgpu:api,operation,uncapturederror:*

deno_webgpu/adapter.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,9 @@ impl GPUAdapter {
126126
let required_limits =
127127
serde_json::from_value(serde_json::to_value(descriptor.required_limits)?)?;
128128

129-
let webgpu_trace = std::env::var_os("DENO_WEBGPU_TRACE").unwrap();
129+
let trace = std::env::var_os("DENO_WEBGPU_TRACE")
130+
.map(|path| wgpu_types::Trace::Directory(std::path::PathBuf::from(path)))
131+
.unwrap_or_default();
130132

131133
let wgpu_descriptor = wgpu_types::DeviceDescriptor {
132134
label: crate::transform_label(descriptor.label.clone()),
@@ -135,7 +137,7 @@ impl GPUAdapter {
135137
),
136138
required_limits,
137139
memory_hints: Default::default(),
138-
trace: wgpu_types::Trace::Directory(std::path::PathBuf::from(webgpu_trace)),
140+
trace,
139141
};
140142

141143
let (device, queue) =

deno_webgpu/device.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ impl GPUDevice {
119119
fn queue(&self, scope: &mut v8::HandleScope) -> v8::Global<v8::Object> {
120120
self.queue_obj.get(scope, |_| GPUQueue {
121121
id: self.queue,
122+
device: self.id,
122123
error_handler: self.error_handler.clone(),
123124
instance: self.instance.clone(),
124125
label: self.label.clone(),
@@ -134,15 +135,12 @@ impl GPUDevice {
134135

135136
#[required(1)]
136137
#[cppgc]
137-
fn create_buffer(
138-
&self,
139-
#[webidl] descriptor: super::buffer::GPUBufferDescriptor,
140-
) -> Result<GPUBuffer, JsErrorBox> {
138+
fn create_buffer(&self, #[webidl] descriptor: super::buffer::GPUBufferDescriptor) -> GPUBuffer {
141139
let wgpu_descriptor = wgpu_core::resource::BufferDescriptor {
142140
label: crate::transform_label(descriptor.label.clone()),
143141
size: descriptor.size,
144142
usage: wgpu_types::BufferUsages::from_bits(descriptor.usage)
145-
.ok_or_else(|| JsErrorBox::type_error("usage is not valid"))?,
143+
.unwrap_or(wgpu_types::BufferUsages::empty()),
146144
mapped_at_creation: descriptor.mapped_at_creation,
147145
};
148146

@@ -152,7 +150,7 @@ impl GPUDevice {
152150

153151
self.error_handler.push_error(err);
154152

155-
Ok(GPUBuffer {
153+
GPUBuffer {
156154
instance: self.instance.clone(),
157155
error_handler: self.error_handler.clone(),
158156
id,
@@ -171,7 +169,7 @@ impl GPUDevice {
171169
None
172170
}),
173171
mapped_js_buffers: RefCell::new(vec![]),
174-
})
172+
}
175173
}
176174

177175
#[required(1)]

deno_webgpu/queue.rs

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
// Copyright 2018-2025 the Deno authors. MIT license.
22

3+
use std::cell::RefCell;
4+
use std::rc::Rc;
5+
use std::time::Duration;
6+
37
use deno_core::cppgc::Ptr;
8+
use deno_core::futures::channel::oneshot;
49
use deno_core::op2;
510
use deno_core::GarbageCollected;
611
use deno_core::WebIDL;
@@ -21,6 +26,7 @@ pub struct GPUQueue {
2126
pub label: String,
2227

2328
pub id: wgpu_core::id::QueueId,
29+
pub device: wgpu_core::id::DeviceId,
2430
}
2531

2632
impl Drop for GPUQueue {
@@ -74,9 +80,41 @@ impl GPUQueue {
7480

7581
#[async_method]
7682
async fn on_submitted_work_done(&self) -> Result<(), JsErrorBox> {
77-
Err(JsErrorBox::generic(
78-
"This operation is currently not supported",
79-
))
83+
let (sender, receiver) = oneshot::channel::<()>();
84+
85+
let callback = Box::new(move || {
86+
sender.send(()).unwrap();
87+
});
88+
89+
self.instance
90+
.queue_on_submitted_work_done(self.id, callback);
91+
92+
let done = Rc::new(RefCell::new(false));
93+
let done_ = done.clone();
94+
let device_poll_fut = async move {
95+
while !*done.borrow() {
96+
{
97+
self.instance
98+
.device_poll(self.device, wgpu_types::PollType::wait())
99+
.unwrap();
100+
}
101+
tokio::time::sleep(Duration::from_millis(10)).await;
102+
}
103+
Ok::<(), JsErrorBox>(())
104+
};
105+
106+
let receiver_fut = async move {
107+
receiver
108+
.await
109+
.map_err(|e| JsErrorBox::generic(e.to_string()))?;
110+
let mut done = done_.borrow_mut();
111+
*done = true;
112+
Ok::<(), JsErrorBox>(())
113+
};
114+
115+
tokio::try_join!(device_poll_fut, receiver_fut)?;
116+
117+
Ok(())
80118
}
81119

82120
#[required(3)]

deno_webgpu/webidl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl<'a> WebIdlConverter<'a> for GPUExtent3D {
6565
enforce_range: true,
6666
},
6767
)?;
68-
if !(conv.len() > 1 && conv.len() <= 3) {
68+
if conv.is_empty() || conv.len() > 3 {
6969
return Err(WebIdlError::other(prefix, context, JsErrorBox::type_error(format!("A sequence of number used as a GPUExtent3D must have between 1 and 3 elements, received {} elements", conv.len()))));
7070
}
7171

0 commit comments

Comments
 (0)