Skip to content

Commit 046a1b4

Browse files
feat(deno): implement WGSLLanguageFeatures (gfx-rs#8884)
1 parent 5346881 commit 046a1b4

4 files changed

Lines changed: 78 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Top level categories:
2222
- Performance
2323
- Documentation
2424
- Dependency Updates
25-
- deno-webgpu
25+
- deno_webgpu
2626
- Examples
2727
- Testing/Internal
2828
@@ -93,6 +93,10 @@ Bottom level categories:
9393

9494
- Prevent UB from incorrectly using ray queries on HLSL. By @Vecvec in [#8763](https://github.com/gfx-rs/wgpu/pull/8763).
9595

96+
### deno\_webgpu
97+
98+
- Expose the `GPU.wgslLanguageFeatures` property. By @andyleiserson in [#8884](https://github.com/gfx-rs/wgpu/pull/8884).
99+
96100
## v28.0.0 (2025-12-17)
97101

98102
### Major Changes

cts_runner/test.lst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,8 @@ webgpu:shader,validation,expression,call,builtin,workgroupUniformLoad:no_atomics
240240
webgpu:shader,validation,expression,call,builtin,workgroupUniformLoad:only_in_compute:*
241241
webgpu:shader,validation,expression,call,builtin,workgroupUniformLoad:param_constructible_only:*
242242
webgpu:shader,validation,extension,dual_source_blending:blend_src_syntax_validation:*
243+
webgpu:shader,validation,extension,pointer_composite_access:*
244+
webgpu:shader,validation,parse,requires:*
243245
webgpu:shader,validation,statement,statement_behavior:invalid_statements:body="break_if"
244246
webgpu:shader,validation,statement,statement_behavior:invalid_statements:body="break"
245247
webgpu:shader,validation,statement,statement_behavior:invalid_statements:body="continue"

deno_webgpu/01_webgpu.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
GPUTexture,
3737
GPUTextureView,
3838
GPUExternalTexture,
39+
WGSLLanguageFeatures,
3940
op_create_gpu,
4041
op_webgpu_device_start_capture,
4142
op_webgpu_device_stop_capture,
@@ -238,6 +239,21 @@ ObjectDefineProperty(GPUSupportedFeaturesPrototype, privateCustomInspect, {
238239
},
239240
});
240241

242+
const WGSLLanguageFeaturesPrototype = WGSLLanguageFeatures.prototype;
243+
webidl.setlikeObjectWrap(WGSLLanguageFeaturesPrototype, true);
244+
ObjectDefineProperty(WGSLLanguageFeaturesPrototype, privateCustomInspect, {
245+
__proto__: null,
246+
value(inspect, inspectOptions) {
247+
if (ObjectPrototypeIsPrototypeOf(WGSLLanguageFeaturesPrototype, this)) {
248+
return `${this.constructor.name} ${
249+
// deno-lint-ignore prefer-primordials
250+
inspect([...this], inspectOptions)}`;
251+
} else {
252+
return `${this.constructor.name} ${inspect({}, inspectOptions)}`;
253+
}
254+
},
255+
});
256+
241257
const GPUSupportedLimitsPrototype = GPUSupportedLimits.prototype;
242258
ObjectDefineProperty(GPUSupportedLimitsPrototype, privateCustomInspect, {
243259
__proto__: null,
@@ -938,5 +954,6 @@ export {
938954
GPUExternalTexture,
939955
GPUUncapturedErrorEvent,
940956
GPUValidationError,
957+
WGSLLanguageFeatures,
941958
initGPU,
942959
};

deno_webgpu/lib.rs

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ deno_core::extension!(
7373
],
7474
objects = [
7575
GPU,
76+
WGSLLanguageFeatures,
7677
adapter::GPUAdapter,
7778
adapter::GPUAdapterInfo,
7879
bind_group::GPUBindGroup,
@@ -129,7 +130,9 @@ pub fn op_create_gpu(
129130
scope,
130131
pipeline_error_class,
131132
)));
132-
GPU
133+
GPU {
134+
wgsl_language_features: SameObject::new(),
135+
}
133136
}
134137

135138
struct EventTargetSetup {
@@ -139,7 +142,9 @@ struct EventTargetSetup {
139142
struct ErrorEventClass(v8::Global<v8::Value>);
140143
struct PipelineErrorClass(v8::Global<v8::Value>);
141144

142-
pub struct GPU;
145+
pub struct GPU {
146+
pub wgsl_language_features: SameObject<WGSLLanguageFeatures>,
147+
}
143148

144149
impl GarbageCollected for GPU {
145150
fn get_name(&self) -> &'static std::ffi::CStr {
@@ -228,6 +233,53 @@ impl GPU {
228233
texture::GPUTextureFormat::Bgra8unorm.as_str()
229234
}
230235
}
236+
237+
#[getter]
238+
#[global]
239+
fn wgslLanguageFeatures(
240+
&self,
241+
scope: &mut v8::HandleScope,
242+
) -> v8::Global<v8::Object> {
243+
self
244+
.wgsl_language_features
245+
.get(scope, WGSLLanguageFeatures::new)
246+
}
247+
}
248+
249+
pub struct WGSLLanguageFeatures(v8::Global<v8::Value>);
250+
251+
impl GarbageCollected for WGSLLanguageFeatures {
252+
fn get_name(&self) -> &'static std::ffi::CStr {
253+
c"WGSLLanguageFeatures"
254+
}
255+
}
256+
257+
impl WGSLLanguageFeatures {
258+
pub fn new(scope: &mut v8::HandleScope) -> Self {
259+
use wgpu_core::naga::front::wgsl::ImplementedLanguageExtension;
260+
261+
let set = v8::Set::new(scope);
262+
for ext in ImplementedLanguageExtension::all() {
263+
let key = v8::String::new(scope, ext.to_ident()).unwrap();
264+
set.add(scope, key.into());
265+
}
266+
Self(v8::Global::new(scope, <v8::Local<v8::Value>>::from(set)))
267+
}
268+
}
269+
270+
#[op2]
271+
impl WGSLLanguageFeatures {
272+
#[constructor]
273+
#[cppgc]
274+
fn constructor(_: bool) -> Result<WGSLLanguageFeatures, GPUGenericError> {
275+
Err(GPUGenericError::InvalidConstructor)
276+
}
277+
278+
#[global]
279+
#[symbol("setlike_set")]
280+
fn set(&self) -> v8::Global<v8::Value> {
281+
self.0.clone()
282+
}
231283
}
232284

233285
fn transform_label<'a>(label: String) -> Option<std::borrow::Cow<'a, str>> {

0 commit comments

Comments
 (0)