Skip to content

Commit 534ad76

Browse files
authored
upstream deno changes (#2895)
* upstream GPUAutoLayoutMode * clean up symbols and fix miscalled op * fix #2778
1 parent e49ef97 commit 534ad76

File tree

6 files changed

+106
-75
lines changed

6 files changed

+106
-75
lines changed

deno_webgpu/src/01_webgpu.js

Lines changed: 34 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,31 @@
4848
Uint8Array,
4949
} = window.__bootstrap.primordials;
5050

51+
const _rid = Symbol("[[rid]]");
52+
const _size = Symbol("[[size]]");
53+
const _usage = Symbol("[[usage]]");
54+
const _state = Symbol("[[state]]");
55+
const _mappingRange = Symbol("[[mapping_range]]");
56+
const _mappedRanges = Symbol("[[mapped_ranges]]");
57+
const _mapMode = Symbol("[[map_mode]]");
58+
const _adapter = Symbol("[[adapter]]");
59+
const _cleanup = Symbol("[[cleanup]]");
60+
const _vendor = Symbol("[[vendor]]");
61+
const _architecture = Symbol("[[architecture]]");
62+
const _description = Symbol("[[description]]");
63+
const _limits = Symbol("[[limits]]");
64+
const _features = Symbol("[[features]]");
65+
const _reason = Symbol("[[reason]]");
66+
const _message = Symbol("[[message]]");
67+
const _label = Symbol("[[label]]");
68+
const _device = Symbol("[[device]]");
69+
const _queue = Symbol("[[queue]]");
70+
const _views = Symbol("[[views]]");
71+
const _texture = Symbol("[[texture]]");
72+
const _encoders = Symbol("[[encoders]]");
73+
const _encoder = Symbol("[[encoder]]");
74+
const _descriptor = Symbol("[[descriptor]]");
75+
5176
/**
5277
* @param {any} self
5378
* @param {{prefix: string, context: string}} opts
@@ -233,9 +258,6 @@
233258
}
234259
const GPUPrototype = GPU.prototype;
235260

236-
const _adapter = Symbol("[[adapter]]");
237-
const _cleanup = Symbol("[[cleanup]]");
238-
239261
/**
240262
* @typedef InnerGPUAdapter
241263
* @property {number} rid
@@ -370,9 +392,6 @@
370392
}
371393
const GPUAdapterPrototype = GPUAdapter.prototype;
372394

373-
const _vendor = Symbol("[[vendor]]");
374-
const _architecture = Symbol("[[architecture]]");
375-
const _description = Symbol("[[description]]");
376395
class GPUAdapterInfo {
377396
/** @type {string} */
378397
[_vendor];
@@ -419,8 +438,6 @@
419438
}
420439
const GPUAdapterInfoPrototype = GPUAdapterInfo.prototype;
421440

422-
const _limits = Symbol("[[limits]]");
423-
424441
function createGPUSupportedLimits(features) {
425442
/** @type {GPUSupportedLimits} */
426443
const adapterFeatures = webidl.createBranded(GPUSupportedLimits);
@@ -576,8 +593,6 @@
576593
}
577594
const GPUSupportedLimitsPrototype = GPUSupportedLimits.prototype;
578595

579-
const _features = Symbol("[[features]]");
580-
581596
function createGPUSupportedFeatures(features) {
582597
/** @type {GPUSupportedFeatures} */
583598
const adapterFeatures = webidl.createBranded(GPUSupportedFeatures);
@@ -643,9 +658,6 @@
643658

644659
const GPUSupportedFeaturesPrototype = GPUSupportedFeatures.prototype;
645660

646-
const _reason = Symbol("[[reason]]");
647-
const _message = Symbol("[[message]]");
648-
649661
/**
650662
* @param {string | undefined} reason
651663
* @param {string} message
@@ -687,8 +699,6 @@
687699

688700
const GPUDeviceLostInfoPrototype = GPUDeviceLostInfo.prototype;
689701

690-
const _label = Symbol("[[label]]");
691-
692702
/**
693703
* @param {string} name
694704
* @param {any} type
@@ -717,9 +727,6 @@
717727
});
718728
}
719729

720-
const _device = Symbol("[[device]]");
721-
const _queue = Symbol("[[queue]]");
722-
723730
/**
724731
* @typedef ErrorScope
725732
* @property {string} filter
@@ -1184,12 +1191,13 @@
11841191
}
11851192
});
11861193

1187-
const { rid, err } = core.opSync("op_webgpu_create_bind_group", {
1188-
deviceRid: device.rid,
1189-
label: descriptor.label,
1194+
const { rid, err } = core.opSync(
1195+
"op_webgpu_create_bind_group",
1196+
device.rid,
1197+
descriptor.label,
11901198
layout,
11911199
entries,
1192-
});
1200+
);
11931201
device.pushError(err);
11941202

11951203
const bindGroup = createGPUBindGroup(
@@ -1244,8 +1252,8 @@
12441252
context: "Argument 1",
12451253
});
12461254
const device = assertDevice(this, { prefix, context: "this" });
1247-
let layout = undefined;
1248-
if (descriptor.layout) {
1255+
let layout = descriptor.layout;
1256+
if (typeof descriptor.layout !== "string") {
12491257
const context = "layout";
12501258
layout = assertResource(descriptor.layout, { prefix, context });
12511259
assertDeviceMatch(device, descriptor.layout, {
@@ -1299,8 +1307,8 @@
12991307
context: "Argument 1",
13001308
});
13011309
const device = assertDevice(this, { prefix, context: "this" });
1302-
let layout = undefined;
1303-
if (descriptor.layout) {
1310+
let layout = descriptor.layout;
1311+
if (typeof descriptor.layout !== "string") {
13041312
const context = "layout";
13051313
layout = assertResource(descriptor.layout, { prefix, context });
13061314
assertDeviceMatch(device, descriptor.layout, {
@@ -1720,15 +1728,6 @@
17201728
}
17211729
GPUObjectBaseMixin("GPUQueue", GPUQueue);
17221730

1723-
const _rid = Symbol("[[rid]]");
1724-
1725-
const _size = Symbol("[[size]]");
1726-
const _usage = Symbol("[[usage]]");
1727-
const _state = Symbol("[[state]]");
1728-
const _mappingRange = Symbol("[[mapping_range]]");
1729-
const _mappedRanges = Symbol("[[mapped_ranges]]");
1730-
const _mapMode = Symbol("[[map_mode]]");
1731-
17321731
/**
17331732
* @typedef CreateGPUBufferOptions
17341733
* @property {ArrayBuffer | null} mapping
@@ -2091,8 +2090,6 @@
20912090
}
20922091
}
20932092

2094-
const _views = Symbol("[[views]]");
2095-
20962093
/**
20972094
* @param {string | null} label
20982095
* @param {InnerGPUDevice} device
@@ -2202,8 +2199,6 @@
22022199
}
22032200
}
22042201

2205-
const _texture = Symbol("[[texture]]");
2206-
22072202
/**
22082203
* @param {string | null} label
22092204
* @param {GPUTexture} texture
@@ -2661,8 +2656,6 @@
26612656
}
26622657
}
26632658

2664-
const _encoders = Symbol("[[encoders]]");
2665-
26662659
/**
26672660
* @param {string | null} label
26682661
* @param {InnerGPUDevice} device
@@ -3395,8 +3388,6 @@
33953388
GPUObjectBaseMixin("GPUCommandEncoder", GPUCommandEncoder);
33963389
const GPUCommandEncoderPrototype = GPUCommandEncoder.prototype;
33973390

3398-
const _encoder = Symbol("[[encoder]]");
3399-
34003391
/**
34013392
* @param {string | null} label
34023393
* @param {GPUCommandEncoder} encoder
@@ -5190,8 +5181,6 @@
51905181
}
51915182
GPUObjectBaseMixin("GPURenderBundle", GPURenderBundle);
51925183

5193-
const _descriptor = Symbol("[[descriptor]]");
5194-
51955184
/**
51965185
* @param {string | null} label
51975186
* @param {InnerGPUDevice} device

deno_webgpu/src/02_idl_types.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
} = window.__bootstrap.webgpu;
4242
const { SymbolIterator, TypeError } = window.__bootstrap.primordials;
4343

44-
// This needs to be initalized after all of the base classes are implmented,
44+
// This needs to be initialized after all of the base classes are implemented,
4545
// otherwise their converters might not be available yet.
4646
// DICTIONARY: GPUObjectDescriptorBase
4747
const dictMembersGPUObjectDescriptorBase = [
@@ -945,11 +945,25 @@
945945
// GPUCompilationInfo.prototype,
946946
// );
947947

948+
webidl.converters["GPUAutoLayoutMode"] = webidl.createEnumConverter(
949+
"GPUAutoLayoutMode",
950+
[
951+
"auto",
952+
],
953+
);
954+
955+
webidl.converters["GPUPipelineLayout or GPUAutoLayoutMode"] = (V, opts) => {
956+
if (typeof V === "object") {
957+
return webidl.converters["GPUPipelineLayout"](V, opts);
958+
}
959+
return webidl.converters["GPUAutoLayoutMode"](V, opts);
960+
};
961+
948962
// DICTIONARY: GPUPipelineDescriptorBase
949963
const dictMembersGPUPipelineDescriptorBase = [
950964
{
951965
key: "layout",
952-
converter: webidl.converters["GPUPipelineLayout"],
966+
converter: webidl.converters["GPUPipelineLayout or GPUAutoLayoutMode"],
953967
},
954968
];
955969
webidl.converters["GPUPipelineDescriptorBase"] = webidl
@@ -1440,7 +1454,9 @@
14401454
{
14411455
key: "targets",
14421456
converter: webidl.createSequenceConverter(
1443-
webidl.converters["GPUColorTargetState"],
1457+
webidl.createNullableConverter(
1458+
webidl.converters["GPUColorTargetState"],
1459+
),
14441460
),
14451461
required: true,
14461462
},
@@ -1819,7 +1835,9 @@
18191835
{
18201836
key: "colorAttachments",
18211837
converter: webidl.createSequenceConverter(
1822-
webidl.converters["GPURenderPassColorAttachment"],
1838+
webidl.createNullableConverter(
1839+
webidl.converters["GPURenderPassColorAttachment"],
1840+
),
18231841
),
18241842
required: true,
18251843
},
@@ -1864,7 +1882,7 @@
18641882
{
18651883
key: "colorFormats",
18661884
converter: webidl.createSequenceConverter(
1867-
webidl.converters["GPUTextureFormat"],
1885+
webidl.createNullableConverter(webidl.converters["GPUTextureFormat"]),
18681886
),
18691887
required: true,
18701888
},

deno_webgpu/src/buffer.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ pub async fn op_webgpu_buffer_get_map_async(
119119
{
120120
let state = state.borrow();
121121
let instance = state.borrow::<super::Instance>();
122-
gfx_select!(device => instance.device_poll(device, wgpu_types::Maintain::Wait)).unwrap();
122+
gfx_select!(device => instance.device_poll(device, wgpu_types::Maintain::Wait))
123+
.unwrap();
123124
}
124125
tokio::time::sleep(Duration::from_millis(10)).await;
125126
}

deno_webgpu/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ impl From<GpuRequiredFeatures> for wgpu_types::Features {
288288
wgpu_types::Features::DEPTH_CLIP_CONTROL,
289289
required_features.0.contains("depth-clip-control"),
290290
);
291-
features.set(
291+
features.set(
292292
wgpu_types::Features::DEPTH24UNORM_STENCIL8,
293293
required_features.0.contains("depth24unorm-stencil8"),
294294
);

deno_webgpu/src/pipeline.rs

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,19 @@ impl Resource for WebGpuRenderPipeline {
3535
}
3636
}
3737

38+
#[derive(Deserialize)]
39+
#[serde(rename_all = "camelCase")]
40+
pub enum GPUAutoLayoutMode {
41+
Auto,
42+
}
43+
44+
#[derive(Deserialize)]
45+
#[serde(untagged)]
46+
pub enum GPUPipelineLayoutOrGPUAutoLayoutMode {
47+
Layout(ResourceId),
48+
Auto(GPUAutoLayoutMode),
49+
}
50+
3851
#[derive(Deserialize)]
3952
#[serde(rename_all = "camelCase")]
4053
pub struct GpuProgrammableStage {
@@ -48,7 +61,7 @@ pub fn op_webgpu_create_compute_pipeline(
4861
state: &mut OpState,
4962
device_rid: ResourceId,
5063
label: Option<String>,
51-
layout: Option<ResourceId>,
64+
layout: GPUPipelineLayoutOrGPUAutoLayoutMode,
5265
compute: GpuProgrammableStage,
5366
) -> Result<WebGpuResult, AnyError> {
5467
let instance = state.borrow::<super::Instance>();
@@ -57,11 +70,12 @@ pub fn op_webgpu_create_compute_pipeline(
5770
.get::<super::WebGpuDevice>(device_rid)?;
5871
let device = device_resource.0;
5972

60-
let pipeline_layout = if let Some(rid) = layout {
61-
let id = state.resource_table.get::<WebGpuPipelineLayout>(rid)?;
62-
Some(id.0)
63-
} else {
64-
None
73+
let pipeline_layout = match layout {
74+
GPUPipelineLayoutOrGPUAutoLayoutMode::Layout(rid) => {
75+
let id = state.resource_table.get::<WebGpuPipelineLayout>(rid)?;
76+
Some(id.0)
77+
}
78+
GPUPipelineLayoutOrGPUAutoLayoutMode::Auto(GPUAutoLayoutMode::Auto) => None,
6579
};
6680

6781
let compute_shader_module_resource = state
@@ -78,11 +92,13 @@ pub fn op_webgpu_create_compute_pipeline(
7892
},
7993
};
8094
let implicit_pipelines = match layout {
81-
Some(_) => None,
82-
None => Some(wgpu_core::device::ImplicitPipelineIds {
83-
root_id: std::marker::PhantomData,
84-
group_ids: &[std::marker::PhantomData; MAX_BIND_GROUPS],
85-
}),
95+
GPUPipelineLayoutOrGPUAutoLayoutMode::Layout(_) => None,
96+
GPUPipelineLayoutOrGPUAutoLayoutMode::Auto(GPUAutoLayoutMode::Auto) => {
97+
Some(wgpu_core::device::ImplicitPipelineIds {
98+
root_id: std::marker::PhantomData,
99+
group_ids: &[std::marker::PhantomData; MAX_BIND_GROUPS],
100+
})
101+
}
86102
};
87103

88104
let (compute_pipeline, maybe_err) = gfx_select!(device => instance.device_create_compute_pipeline(
@@ -271,7 +287,7 @@ struct GpuFragmentState {
271287
pub struct CreateRenderPipelineArgs {
272288
device_rid: ResourceId,
273289
label: Option<String>,
274-
layout: Option<ResourceId>,
290+
layout: GPUPipelineLayoutOrGPUAutoLayoutMode,
275291
vertex: GpuVertexState,
276292
primitive: GpuPrimitiveState,
277293
depth_stencil: Option<GpuDepthStencilState>,
@@ -290,11 +306,12 @@ pub fn op_webgpu_create_render_pipeline(
290306
.get::<super::WebGpuDevice>(args.device_rid)?;
291307
let device = device_resource.0;
292308

293-
let layout = if let Some(rid) = args.layout {
294-
let pipeline_layout_resource = state.resource_table.get::<WebGpuPipelineLayout>(rid)?;
295-
Some(pipeline_layout_resource.0)
296-
} else {
297-
None
309+
let layout = match args.layout {
310+
GPUPipelineLayoutOrGPUAutoLayoutMode::Layout(rid) => {
311+
let pipeline_layout_resource = state.resource_table.get::<WebGpuPipelineLayout>(rid)?;
312+
Some(pipeline_layout_resource.0)
313+
}
314+
GPUPipelineLayoutOrGPUAutoLayoutMode::Auto(GPUAutoLayoutMode::Auto) => None,
298315
};
299316

300317
let vertex_shader_module_resource = state
@@ -344,11 +361,13 @@ pub fn op_webgpu_create_render_pipeline(
344361
};
345362

346363
let implicit_pipelines = match args.layout {
347-
Some(_) => None,
348-
None => Some(wgpu_core::device::ImplicitPipelineIds {
349-
root_id: std::marker::PhantomData,
350-
group_ids: &[std::marker::PhantomData; MAX_BIND_GROUPS],
351-
}),
364+
GPUPipelineLayoutOrGPUAutoLayoutMode::Layout(_) => None,
365+
GPUPipelineLayoutOrGPUAutoLayoutMode::Auto(GPUAutoLayoutMode::Auto) => {
366+
Some(wgpu_core::device::ImplicitPipelineIds {
367+
root_id: std::marker::PhantomData,
368+
group_ids: &[std::marker::PhantomData; MAX_BIND_GROUPS],
369+
})
370+
}
352371
};
353372

354373
let (render_pipeline, maybe_err) = gfx_select!(device => instance.device_create_render_pipeline(

0 commit comments

Comments
 (0)