diff --git a/Cargo.lock b/Cargo.lock index e1575da1c..8882ccdaf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -893,6 +893,7 @@ dependencies = [ "deno_webgpu", "deno_webidl", "env_logger", + "pico-args", "tempfile", "termcolor", "tokio", diff --git a/cts_runner/Cargo.toml b/cts_runner/Cargo.toml index 218a61c80..ad3eec28a 100644 --- a/cts_runner/Cargo.toml +++ b/cts_runner/Cargo.toml @@ -20,6 +20,7 @@ deno_url.workspace = true deno_web.workspace = true deno_webidl.workspace = true deno_webgpu.workspace = true +pico-args.workspace = true tokio = { workspace = true, features = ["full"] } termcolor.workspace = true diff --git a/cts_runner/fail.lst b/cts_runner/fail.lst index f67153ce5..daff5f259 100644 --- a/cts_runner/fail.lst +++ b/cts_runner/fail.lst @@ -189,7 +189,6 @@ webgpu:shader,validation,parse,shadow_builtins:* // 83%, function param shadowin webgpu:shader,validation,shader_io,align:* // 98%, https://github.com/gfx-rs/wgpu/issues/8892 webgpu:shader,validation,shader_io,binding:* // 95%, https://github.com/gfx-rs/wgpu/issues/8892 webgpu:shader,validation,shader_io,builtins:* // 50%, trailing comma not accepted -webgpu:shader,validation,shader_io,group_and_binding:* // 87%, texture_external webgpu:shader,validation,shader_io,group:* // 95%, https://github.com/gfx-rs/wgpu/issues/8892 webgpu:shader,validation,shader_io,id:* // 94%, https://github.com/gfx-rs/wgpu/issues/8892, @id on const webgpu:shader,validation,shader_io,interpolate:* // 91%, https://github.com/gfx-rs/wgpu/issues/8892 diff --git a/cts_runner/src/bootstrap.js b/cts_runner/src/bootstrap.js index 42fcc41c2..7c7a9b340 100644 --- a/cts_runner/src/bootstrap.js +++ b/cts_runner/src/bootstrap.js @@ -234,8 +234,22 @@ windowOrWorkerGlobalScope.console.enumerable = false; // for the application. // // Note that catching an error here _does not_ result in a non-zero exit status. +let enableExternalTexture_ = false; const requestDevice = webgpu.GPUAdapter.prototype.requestDevice; webgpu.GPUAdapter.prototype.requestDevice = function(desc) { + if (enableExternalTexture_) { + // Deno doesn't meaningfully support external textures, but we provide + // an option to enable it anyways to allow running some CTS tests that + // do pass. + if (!desc) { + desc = { requiredFeatures: ['external-texture'] }; + } else if (!desc.requiredFeatures) { + desc.requiredFeatures = ['external-texture']; + } else { + desc.requiredFeatures.push('external-texture'); + } + } + return requestDevice.call(this, desc).then((device) => { device.onuncapturederror = (event) => { core.print("cts_runner caught WebGPU error: " + event.error.message + "\n", true); @@ -301,12 +315,13 @@ core.registerErrorBuilder( let hasBootstrapped = false; -function bootstrapRuntime({ args, cwd }) { +function bootstrapRuntime({ args, cwd, enableExternalTexture = false }) { if (hasBootstrapped) { throw new Error("Runtime has already been bootstrapped."); } performance.setTimeOrigin(DateNow()); globalThis_ = globalThis; + enableExternalTexture_ = enableExternalTexture; // Remove bootstrapping data from the global scope delete globalThis.__bootstrap; diff --git a/cts_runner/src/main.rs b/cts_runner/src/main.rs index cbb88b866..f61a159c2 100644 --- a/cts_runner/src/main.rs +++ b/cts_runner/src/main.rs @@ -23,10 +23,12 @@ use termcolor::ColorSpec; use termcolor::WriteColor; pub async fn run() -> Result<(), AnyError> { - let mut args_iter = env::args(); - let _ = args_iter.next(); - let url = args_iter - .next() + let mut args = pico_args::Arguments::from_env(); + let enable_external_texture = args.contains("--enable-external-texture"); + let url = args + .subcommand() + .ok() + .flatten() .ok_or_else(|| anyhow!("missing specifier in first command line argument"))?; let specifier = resolve_url_or_path(&url, &env::current_dir()?)?; @@ -43,8 +45,17 @@ pub async fn run() -> Result<(), AnyError> { ..Default::default() }; let mut js_runtime = JsRuntime::new(options); - let args = args_iter.collect::>(); - let cfg = json!({"args": args, "cwd": env::current_dir().unwrap().to_string_lossy() }); + let args = args + .finish() + .into_iter() + .map(|os| os.into_string().ok()) + .collect::>>() + .ok_or_else(|| anyhow!("Invalid UTF-8 in arguments"))?; + let cfg = json!({ + "args": args, + "cwd": env::current_dir().unwrap().to_string_lossy(), + "enableExternalTexture": enable_external_texture, + }); { let context = js_runtime.main_context(); diff --git a/cts_runner/test.lst b/cts_runner/test.lst index 61002e716..cf48a393a 100644 --- a/cts_runner/test.lst +++ b/cts_runner/test.lst @@ -247,6 +247,7 @@ webgpu:api,validation,render_pipeline,inter_stage:location,* webgpu:api,validation,render_pipeline,inter_stage:max_shader_variable_location:* webgpu:api,validation,render_pipeline,inter_stage:max_variables_count,* webgpu:api,validation,render_pipeline,misc:basic:* +fails-if(vulkan) webgpu:api,validation,render_pipeline,misc:external_texture:* webgpu:api,validation,render_pipeline,misc:no_attachment:* webgpu:api,validation,render_pipeline,misc:pipeline_layout,device_mismatch:* webgpu:api,validation,render_pipeline,misc:vertex_state_only:* @@ -358,9 +359,13 @@ webgpu:shader,validation,expression,call,builtin,sin:* webgpu:shader,validation,expression,call,builtin,step:* webgpu:shader,validation,expression,call,builtin,tan:* webgpu:shader,validation,expression,call,builtin,tanh:* +// Uses external textures +fails-if(vulkan) webgpu:shader,validation,expression,call,builtin,textureLoad:* webgpu:shader,validation,expression,call,builtin,textureNumLayers:* webgpu:shader,validation,expression,call,builtin,textureNumLevels:* webgpu:shader,validation,expression,call,builtin,textureNumSamples:* +// Uses external textures +fails-if(vulkan) webgpu:shader,validation,expression,call,builtin,textureSampleBaseClampToEdge:* webgpu:shader,validation,expression,call,builtin,textureStore:* webgpu:shader,validation,expression,call,builtin,trunc:* // 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:* webgpu:shader,validation,parse,shadow_builtins:function_param:* webgpu:shader,validation,parse,source:* webgpu:shader,validation,shader_io,entry_point:* +// Uses external texture bindings +fails-if(vulkan) webgpu:shader,validation,shader_io,group_and_binding:* webgpu:shader,validation,shader_io,invariant:* webgpu:shader,validation,statement,break_if:* webgpu:shader,validation,statement,break:* diff --git a/deno_webgpu/adapter.rs b/deno_webgpu/adapter.rs index 7a98f2c6b..2101791b7 100644 --- a/deno_webgpu/adapter.rs +++ b/deno_webgpu/adapter.rs @@ -125,7 +125,18 @@ impl GPUAdapter { .cloned() .collect::>(); - if !required_features.is_subset(&supported_features) { + // External textures are a required part of WebGPU, and `external-texture` + // is not a WebGPU-defined feature. `wgpu` has it behind a feature for now, + // because support is not complete. Allow applications to request that + // feature even though it is not reported as an adapter-supported feature. + // + // There is probably not anything useful that Deno applications can do with + // external textures, but it is useful to be able to enable it in + // `cts_runner`. + if required_features + .difference(&supported_features) + .any(|feat| *feat != GPUFeatureName::ExternalTexture) + { return Err(CreateDeviceError::RequiredFeaturesNotASubset); } diff --git a/deno_webgpu/bind_group.rs b/deno_webgpu/bind_group.rs index de329ecf4..6d930fea7 100644 --- a/deno_webgpu/bind_group.rs +++ b/deno_webgpu/bind_group.rs @@ -17,6 +17,7 @@ use deno_core::WebIDL; use crate::buffer::GPUBuffer; use crate::error::GPUGenericError; use crate::sampler::GPUSampler; +use crate::texture::GPUExternalTexture; use crate::texture::GPUTexture; use crate::texture::GPUTextureView; use crate::Instance; @@ -98,6 +99,7 @@ pub(crate) enum GPUBindingResource { TextureView(Ptr), Buffer(Ptr), BufferBinding(GPUBufferBinding), + ExternalTexture(Ptr), } impl<'a> WebIdlConverter<'a> for GPUBindingResource { @@ -148,6 +150,16 @@ impl<'a> WebIdlConverter<'a> for GPUBindingResource { ) .map(Self::Buffer) }) + .or_else(|_| { + >::convert( + scope, + value, + prefix.clone(), + context.borrowed(), + options, + ) + .map(Self::ExternalTexture) + }) .or_else(|_| { GPUBufferBinding::convert(scope, value, prefix, context, options) .map(Self::BufferBinding) diff --git a/deno_webgpu/bind_group_layout.rs b/deno_webgpu/bind_group_layout.rs index fe3fe8a0f..58d1d5a97 100644 --- a/deno_webgpu/bind_group_layout.rs +++ b/deno_webgpu/bind_group_layout.rs @@ -69,6 +69,7 @@ pub(crate) struct GPUBindGroupLayoutEntry { pub sampler: Option, pub texture: Option, pub storage_texture: Option, + pub external_texture: Option, } #[derive(WebIDL)] @@ -189,3 +190,7 @@ impl From for wgpu_types::StorageTextureAccess { } } } + +#[derive(WebIDL)] +#[webidl(dictionary)] +pub(crate) struct GPUExternalTextureBindingLayout {} diff --git a/deno_webgpu/device.rs b/deno_webgpu/device.rs index d3f7811db..4e0a3ed65 100644 --- a/deno_webgpu/device.rs +++ b/deno_webgpu/device.rs @@ -304,6 +304,7 @@ impl GPUDevice { entry.sampler.is_some(), entry.texture.is_some(), entry.storage_texture.is_some(), + entry.external_texture.is_some(), ] .into_iter() .filter(|t| *t) @@ -335,6 +336,8 @@ impl GPUDevice { format: storage_texture.format.into(), view_dimension: storage_texture.view_dimension.into(), } + } else if entry.external_texture.is_some() { + BindingType::ExternalTexture } else { unreachable!() }; @@ -435,6 +438,9 @@ impl GPUDevice { size: buffer_binding.size, }) } + GPUBindingResource::ExternalTexture(external_texture) => { + BindingResource::ExternalTexture(external_texture.id) + } }, }) .collect::>(); diff --git a/deno_webgpu/texture.rs b/deno_webgpu/texture.rs index 6f421ee54..cd07444aa 100644 --- a/deno_webgpu/texture.rs +++ b/deno_webgpu/texture.rs @@ -710,7 +710,9 @@ impl From for TextureFormat { } } -pub struct GPUExternalTexture {} +pub struct GPUExternalTexture { + pub id: wgpu_core::id::ExternalTextureId, +} impl WebIdlInterfaceConverter for GPUExternalTexture { const NAME: &'static str = "GPUExternalTexture"; diff --git a/deno_webgpu/webidl.rs b/deno_webgpu/webidl.rs index 81da9b91e..5ac0b2daf 100644 --- a/deno_webgpu/webidl.rs +++ b/deno_webgpu/webidl.rs @@ -399,6 +399,11 @@ pub enum GPUFeatureName { #[webidl(rename = "subgroups")] Subgroups, + // standard feature, but not default yet in wgpu due to incomplete support + // (and even if enabled in wgpu, doing so may not be appropriate in Deno) + #[webidl(rename = "external-texture")] + ExternalTexture, + // extended from spec #[webidl(rename = "texture-format-16-bit-norm")] TextureFormat16BitNorm, @@ -486,6 +491,7 @@ pub fn feature_names_to_features( GPUFeatureName::Float32Filterable => Features::FLOAT32_FILTERABLE, GPUFeatureName::DualSourceBlending => Features::DUAL_SOURCE_BLENDING, GPUFeatureName::Subgroups => Features::SUBGROUP, + GPUFeatureName::ExternalTexture => Features::EXTERNAL_TEXTURE, GPUFeatureName::TextureFormat16BitNorm => Features::TEXTURE_FORMAT_16BIT_NORM, GPUFeatureName::TextureCompressionAstcHdr => Features::TEXTURE_COMPRESSION_ASTC_HDR, GPUFeatureName::TextureAdapterSpecificFormatFeatures => Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES, diff --git a/xtask/src/cts.rs b/xtask/src/cts.rs index 945c06990..eb7c04de7 100644 --- a/xtask/src/cts.rs +++ b/xtask/src/cts.rs @@ -97,6 +97,12 @@ pub fn run_cts( .transpose()?; let running_on_backend = args.opt_value_from_str::<_, String>("--backend")?; + let enable_external_texture = args.contains("--enable-external-texture") + || (!args.contains("--disable-external-texture") + && running_on_backend + .as_ref() + .is_some_and(|b| ["metal", "dx12"].contains(&b.as_str()))); + let mut filter_pattern = args.opt_value_from_str::<_, String>("--filter")?; let mut filter_invert = false; @@ -117,12 +123,6 @@ pub fn run_cts( None }; - if running_on_backend.is_none() { - log::warn!( - "fails-if conditions are only evaluated if a backend is specified with --backend" - ); - } - let mut list_files = Vec::::new(); while let Some(file) = args.opt_value_from_str("-f")? { list_files.push(file); @@ -137,6 +137,11 @@ pub fn run_cts( }) .collect::>(); + if running_on_backend.is_none() && (!list_files.is_empty() || tests.is_empty()) { + log::warn!("The `--backend` option was not provided. `fails-if` conditions and external"); + log::warn!("texture support are handled correctly only when a backend is specified."); + } + let mut default_output_filter = PrintOutputWhen::Always; if tests.is_empty() && list_files.is_empty() { @@ -313,18 +318,16 @@ pub fn run_cts( }; if let Some(passthrough_args) = passthrough_args { - let mut cmd = shell + shell .cmd("cargo") .args(run_flags) .args(["--manifest-path".as_ref(), wgpu_cargo_toml.as_os_str()]) .args(["-p", "cts_runner"]) - .args(["--bin", "cts_runner"]); - - if release { - cmd = cmd.arg("--release") - } - - cmd.args(["--", "./tools/run_deno", "--verbose"]) + .args(["--bin", "cts_runner"]) + .args(release.then_some("--release")) + .arg("--") + .args(enable_external_texture.then_some("--enable-external-texture")) + .args(["./tools/run_deno", "--verbose"]) .args(&passthrough_args) .run()?; @@ -348,19 +351,16 @@ pub fn run_cts( log::info!("Running {}", test.selector.to_string_lossy()); } - let mut cmd = shell + let cmd = shell .cmd("cargo") .args(run_flags) .args(["--manifest-path".as_ref(), wgpu_cargo_toml.as_os_str()]) .args(["-p", "cts_runner"]) - .args(["--bin", "cts_runner"]); - - if release { - cmd = cmd.arg("--release") - } - - cmd = cmd - .args(["--", "./tools/run_deno", "--verbose"]) + .args(["--bin", "cts_runner"]) + .args(release.then_some("--release")) + .arg("--") + .args(enable_external_texture.then_some("--enable-external-texture")) + .args(["./tools/run_deno", "--verbose"]) .args([&test.selector]); match output_filter { diff --git a/xtask/src/main.rs b/xtask/src/main.rs index e9d796fdc..6786db75d 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -26,19 +26,25 @@ Commands: -f cts_runner/test.lst --print-output-when=test-fails` were specified. - --skip-checkout Don't check out the pinned CTS version, use whatever - is already checked out. - --release Build and run in release mode - --llvm-cov Run with LLVM code coverage - --backend Specify the backend (metal, dx12, or vulkan). Used - to evaluate `fails-if` conditions in the test list. - --filter Filter tests by selector using a regex pattern. - Prefix with '!' to invert (exclude matching tests). - Applied after all tests are collected. - --print-output-when One of `test-fails` or `always`. When no `test - selector`, `test list file`, or `args` are - specified, this defaults to `test-fails`. Otherwise, - this defaults to `always`. + --skip-checkout Don't check out the pinned CTS version, use whatever + is already checked out. + --release Build and run in release mode + --llvm-cov Run with LLVM code coverage + --backend Specify the backend (metal, dx12, or vulkan). Used + to evaluate `fails-if` conditions in the test list. + --filter Filter tests by selector using a regex pattern. + Prefix with '!' to invert (exclude matching tests). + Applied after all tests are collected. + --print-output-when One of `test-fails` or `always`. When no `test + selector`, `test list file`, or `args` are + specified, this defaults to `test-fails`. Otherwise, + this defaults to `always`. + --enable-external-texture Enable the external-texture feature. By default it is + enabled if `--backend` specifies Metal or DX12, + otherwise disabled. External textures do not really + work in Deno, but some CTS tests for shaders and + pipeline layouts are able to pass. + --disable-external-texture Disable the external-texture feature. run-wasm Build and run web examples