Skip to content

Commit 8355603

Browse files
test(cts): Enable some external texture tests (gfx-rs#8901)
1 parent 96e3af8 commit 8355603

14 files changed

Lines changed: 128 additions & 46 deletions

File tree

Cargo.lock

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

cts_runner/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ deno_url.workspace = true
2020
deno_web.workspace = true
2121
deno_webidl.workspace = true
2222
deno_webgpu.workspace = true
23+
pico-args.workspace = true
2324
tokio = { workspace = true, features = ["full"] }
2425
termcolor.workspace = true
2526

cts_runner/fail.lst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ webgpu:shader,validation,parse,shadow_builtins:* // 83%, function param shadowin
189189
webgpu:shader,validation,shader_io,align:* // 98%, https://github.com/gfx-rs/wgpu/issues/8892
190190
webgpu:shader,validation,shader_io,binding:* // 95%, https://github.com/gfx-rs/wgpu/issues/8892
191191
webgpu:shader,validation,shader_io,builtins:* // 50%, trailing comma not accepted
192-
webgpu:shader,validation,shader_io,group_and_binding:* // 87%, texture_external
193192
webgpu:shader,validation,shader_io,group:* // 95%, https://github.com/gfx-rs/wgpu/issues/8892
194193
webgpu:shader,validation,shader_io,id:* // 94%, https://github.com/gfx-rs/wgpu/issues/8892, @id on const
195194
webgpu:shader,validation,shader_io,interpolate:* // 91%, https://github.com/gfx-rs/wgpu/issues/8892

cts_runner/src/bootstrap.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,22 @@ windowOrWorkerGlobalScope.console.enumerable = false;
234234
// for the application.
235235
//
236236
// Note that catching an error here _does not_ result in a non-zero exit status.
237+
let enableExternalTexture_ = false;
237238
const requestDevice = webgpu.GPUAdapter.prototype.requestDevice;
238239
webgpu.GPUAdapter.prototype.requestDevice = function(desc) {
240+
if (enableExternalTexture_) {
241+
// Deno doesn't meaningfully support external textures, but we provide
242+
// an option to enable it anyways to allow running some CTS tests that
243+
// do pass.
244+
if (!desc) {
245+
desc = { requiredFeatures: ['external-texture'] };
246+
} else if (!desc.requiredFeatures) {
247+
desc.requiredFeatures = ['external-texture'];
248+
} else {
249+
desc.requiredFeatures.push('external-texture');
250+
}
251+
}
252+
239253
return requestDevice.call(this, desc).then((device) => {
240254
device.onuncapturederror = (event) => {
241255
core.print("cts_runner caught WebGPU error: " + event.error.message + "\n", true);
@@ -301,12 +315,13 @@ core.registerErrorBuilder(
301315

302316
let hasBootstrapped = false;
303317

304-
function bootstrapRuntime({ args, cwd }) {
318+
function bootstrapRuntime({ args, cwd, enableExternalTexture = false }) {
305319
if (hasBootstrapped) {
306320
throw new Error("Runtime has already been bootstrapped.");
307321
}
308322
performance.setTimeOrigin(DateNow());
309323
globalThis_ = globalThis;
324+
enableExternalTexture_ = enableExternalTexture;
310325

311326
// Remove bootstrapping data from the global scope
312327
delete globalThis.__bootstrap;

cts_runner/src/main.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ use termcolor::ColorSpec;
2323
use termcolor::WriteColor;
2424

2525
pub async fn run() -> Result<(), AnyError> {
26-
let mut args_iter = env::args();
27-
let _ = args_iter.next();
28-
let url = args_iter
29-
.next()
26+
let mut args = pico_args::Arguments::from_env();
27+
let enable_external_texture = args.contains("--enable-external-texture");
28+
let url = args
29+
.subcommand()
30+
.ok()
31+
.flatten()
3032
.ok_or_else(|| anyhow!("missing specifier in first command line argument"))?;
3133
let specifier = resolve_url_or_path(&url, &env::current_dir()?)?;
3234

@@ -43,8 +45,17 @@ pub async fn run() -> Result<(), AnyError> {
4345
..Default::default()
4446
};
4547
let mut js_runtime = JsRuntime::new(options);
46-
let args = args_iter.collect::<Vec<String>>();
47-
let cfg = json!({"args": args, "cwd": env::current_dir().unwrap().to_string_lossy() });
48+
let args = args
49+
.finish()
50+
.into_iter()
51+
.map(|os| os.into_string().ok())
52+
.collect::<Option<Vec<String>>>()
53+
.ok_or_else(|| anyhow!("Invalid UTF-8 in arguments"))?;
54+
let cfg = json!({
55+
"args": args,
56+
"cwd": env::current_dir().unwrap().to_string_lossy(),
57+
"enableExternalTexture": enable_external_texture,
58+
});
4859

4960
{
5061
let context = js_runtime.main_context();

cts_runner/test.lst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ webgpu:api,validation,render_pipeline,inter_stage:location,*
247247
webgpu:api,validation,render_pipeline,inter_stage:max_shader_variable_location:*
248248
webgpu:api,validation,render_pipeline,inter_stage:max_variables_count,*
249249
webgpu:api,validation,render_pipeline,misc:basic:*
250+
fails-if(vulkan) webgpu:api,validation,render_pipeline,misc:external_texture:*
250251
webgpu:api,validation,render_pipeline,misc:no_attachment:*
251252
webgpu:api,validation,render_pipeline,misc:pipeline_layout,device_mismatch:*
252253
webgpu:api,validation,render_pipeline,misc:vertex_state_only:*
@@ -358,9 +359,13 @@ webgpu:shader,validation,expression,call,builtin,sin:*
358359
webgpu:shader,validation,expression,call,builtin,step:*
359360
webgpu:shader,validation,expression,call,builtin,tan:*
360361
webgpu:shader,validation,expression,call,builtin,tanh:*
362+
// Uses external textures
363+
fails-if(vulkan) webgpu:shader,validation,expression,call,builtin,textureLoad:*
361364
webgpu:shader,validation,expression,call,builtin,textureNumLayers:*
362365
webgpu:shader,validation,expression,call,builtin,textureNumLevels:*
363366
webgpu:shader,validation,expression,call,builtin,textureNumSamples:*
367+
// Uses external textures
368+
fails-if(vulkan) webgpu:shader,validation,expression,call,builtin,textureSampleBaseClampToEdge:*
364369
webgpu:shader,validation,expression,call,builtin,textureStore:*
365370
webgpu:shader,validation,expression,call,builtin,trunc:*
366371
// FAIL: others in `value_constructor` due to https://github.com/gfx-rs/wgpu/issues/4720, possibly more
@@ -393,6 +398,8 @@ webgpu:shader,validation,parse,semicolon:*
393398
webgpu:shader,validation,parse,shadow_builtins:function_param:*
394399
webgpu:shader,validation,parse,source:*
395400
webgpu:shader,validation,shader_io,entry_point:*
401+
// Uses external texture bindings
402+
fails-if(vulkan) webgpu:shader,validation,shader_io,group_and_binding:*
396403
webgpu:shader,validation,shader_io,invariant:*
397404
webgpu:shader,validation,statement,break_if:*
398405
webgpu:shader,validation,statement,break:*

deno_webgpu/adapter.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,18 @@ impl GPUAdapter {
125125
.cloned()
126126
.collect::<HashSet<_>>();
127127

128-
if !required_features.is_subset(&supported_features) {
128+
// External textures are a required part of WebGPU, and `external-texture`
129+
// is not a WebGPU-defined feature. `wgpu` has it behind a feature for now,
130+
// because support is not complete. Allow applications to request that
131+
// feature even though it is not reported as an adapter-supported feature.
132+
//
133+
// There is probably not anything useful that Deno applications can do with
134+
// external textures, but it is useful to be able to enable it in
135+
// `cts_runner`.
136+
if required_features
137+
.difference(&supported_features)
138+
.any(|feat| *feat != GPUFeatureName::ExternalTexture)
139+
{
129140
return Err(CreateDeviceError::RequiredFeaturesNotASubset);
130141
}
131142

deno_webgpu/bind_group.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use deno_core::WebIDL;
1717
use crate::buffer::GPUBuffer;
1818
use crate::error::GPUGenericError;
1919
use crate::sampler::GPUSampler;
20+
use crate::texture::GPUExternalTexture;
2021
use crate::texture::GPUTexture;
2122
use crate::texture::GPUTextureView;
2223
use crate::Instance;
@@ -98,6 +99,7 @@ pub(crate) enum GPUBindingResource {
9899
TextureView(Ptr<GPUTextureView>),
99100
Buffer(Ptr<GPUBuffer>),
100101
BufferBinding(GPUBufferBinding),
102+
ExternalTexture(Ptr<GPUExternalTexture>),
101103
}
102104

103105
impl<'a> WebIdlConverter<'a> for GPUBindingResource {
@@ -148,6 +150,16 @@ impl<'a> WebIdlConverter<'a> for GPUBindingResource {
148150
)
149151
.map(Self::Buffer)
150152
})
153+
.or_else(|_| {
154+
<Ptr<GPUExternalTexture>>::convert(
155+
scope,
156+
value,
157+
prefix.clone(),
158+
context.borrowed(),
159+
options,
160+
)
161+
.map(Self::ExternalTexture)
162+
})
151163
.or_else(|_| {
152164
GPUBufferBinding::convert(scope, value, prefix, context, options)
153165
.map(Self::BufferBinding)

deno_webgpu/bind_group_layout.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ pub(crate) struct GPUBindGroupLayoutEntry {
6969
pub sampler: Option<GPUSamplerBindingLayout>,
7070
pub texture: Option<GPUTextureBindingLayout>,
7171
pub storage_texture: Option<GPUStorageTextureBindingLayout>,
72+
pub external_texture: Option<GPUExternalTextureBindingLayout>,
7273
}
7374

7475
#[derive(WebIDL)]
@@ -189,3 +190,7 @@ impl From<GPUStorageTextureAccess> for wgpu_types::StorageTextureAccess {
189190
}
190191
}
191192
}
193+
194+
#[derive(WebIDL)]
195+
#[webidl(dictionary)]
196+
pub(crate) struct GPUExternalTextureBindingLayout {}

deno_webgpu/device.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ impl GPUDevice {
304304
entry.sampler.is_some(),
305305
entry.texture.is_some(),
306306
entry.storage_texture.is_some(),
307+
entry.external_texture.is_some(),
307308
]
308309
.into_iter()
309310
.filter(|t| *t)
@@ -335,6 +336,8 @@ impl GPUDevice {
335336
format: storage_texture.format.into(),
336337
view_dimension: storage_texture.view_dimension.into(),
337338
}
339+
} else if entry.external_texture.is_some() {
340+
BindingType::ExternalTexture
338341
} else {
339342
unreachable!()
340343
};
@@ -435,6 +438,9 @@ impl GPUDevice {
435438
size: buffer_binding.size,
436439
})
437440
}
441+
GPUBindingResource::ExternalTexture(external_texture) => {
442+
BindingResource::ExternalTexture(external_texture.id)
443+
}
438444
},
439445
})
440446
.collect::<Vec<_>>();

0 commit comments

Comments
 (0)