From 534ad76d5a2d7fc9f894b1f14bd0cba77b28eb16 Mon Sep 17 00:00:00 2001 From: Leo Kettmeir Date: Wed, 20 Jul 2022 18:47:10 +0200 Subject: [PATCH] upstream deno changes (#2895) * upstream GPUAutoLayoutMode * clean up symbols and fix miscalled op * fix gfx-rs/wgpu#2778 --- deno_webgpu/src/01_webgpu.js | 79 ++++++++++++++------------------- deno_webgpu/src/02_idl_types.js | 28 +++++++++--- deno_webgpu/src/buffer.rs | 3 +- deno_webgpu/src/lib.rs | 2 +- deno_webgpu/src/pipeline.rs | 63 +++++++++++++++++--------- deno_webgpu/webgpu.idl | 6 ++- 6 files changed, 106 insertions(+), 75 deletions(-) diff --git a/deno_webgpu/src/01_webgpu.js b/deno_webgpu/src/01_webgpu.js index 6bcc5f50c9..21599a117e 100644 --- a/deno_webgpu/src/01_webgpu.js +++ b/deno_webgpu/src/01_webgpu.js @@ -48,6 +48,31 @@ Uint8Array, } = window.__bootstrap.primordials; + const _rid = Symbol("[[rid]]"); + const _size = Symbol("[[size]]"); + const _usage = Symbol("[[usage]]"); + const _state = Symbol("[[state]]"); + const _mappingRange = Symbol("[[mapping_range]]"); + const _mappedRanges = Symbol("[[mapped_ranges]]"); + const _mapMode = Symbol("[[map_mode]]"); + const _adapter = Symbol("[[adapter]]"); + const _cleanup = Symbol("[[cleanup]]"); + const _vendor = Symbol("[[vendor]]"); + const _architecture = Symbol("[[architecture]]"); + const _description = Symbol("[[description]]"); + const _limits = Symbol("[[limits]]"); + const _features = Symbol("[[features]]"); + const _reason = Symbol("[[reason]]"); + const _message = Symbol("[[message]]"); + const _label = Symbol("[[label]]"); + const _device = Symbol("[[device]]"); + const _queue = Symbol("[[queue]]"); + const _views = Symbol("[[views]]"); + const _texture = Symbol("[[texture]]"); + const _encoders = Symbol("[[encoders]]"); + const _encoder = Symbol("[[encoder]]"); + const _descriptor = Symbol("[[descriptor]]"); + /** * @param {any} self * @param {{prefix: string, context: string}} opts @@ -233,9 +258,6 @@ } const GPUPrototype = GPU.prototype; - const _adapter = Symbol("[[adapter]]"); - const _cleanup = Symbol("[[cleanup]]"); - /** * @typedef InnerGPUAdapter * @property {number} rid @@ -370,9 +392,6 @@ } const GPUAdapterPrototype = GPUAdapter.prototype; - const _vendor = Symbol("[[vendor]]"); - const _architecture = Symbol("[[architecture]]"); - const _description = Symbol("[[description]]"); class GPUAdapterInfo { /** @type {string} */ [_vendor]; @@ -419,8 +438,6 @@ } const GPUAdapterInfoPrototype = GPUAdapterInfo.prototype; - const _limits = Symbol("[[limits]]"); - function createGPUSupportedLimits(features) { /** @type {GPUSupportedLimits} */ const adapterFeatures = webidl.createBranded(GPUSupportedLimits); @@ -576,8 +593,6 @@ } const GPUSupportedLimitsPrototype = GPUSupportedLimits.prototype; - const _features = Symbol("[[features]]"); - function createGPUSupportedFeatures(features) { /** @type {GPUSupportedFeatures} */ const adapterFeatures = webidl.createBranded(GPUSupportedFeatures); @@ -643,9 +658,6 @@ const GPUSupportedFeaturesPrototype = GPUSupportedFeatures.prototype; - const _reason = Symbol("[[reason]]"); - const _message = Symbol("[[message]]"); - /** * @param {string | undefined} reason * @param {string} message @@ -687,8 +699,6 @@ const GPUDeviceLostInfoPrototype = GPUDeviceLostInfo.prototype; - const _label = Symbol("[[label]]"); - /** * @param {string} name * @param {any} type @@ -717,9 +727,6 @@ }); } - const _device = Symbol("[[device]]"); - const _queue = Symbol("[[queue]]"); - /** * @typedef ErrorScope * @property {string} filter @@ -1184,12 +1191,13 @@ } }); - const { rid, err } = core.opSync("op_webgpu_create_bind_group", { - deviceRid: device.rid, - label: descriptor.label, + const { rid, err } = core.opSync( + "op_webgpu_create_bind_group", + device.rid, + descriptor.label, layout, entries, - }); + ); device.pushError(err); const bindGroup = createGPUBindGroup( @@ -1244,8 +1252,8 @@ context: "Argument 1", }); const device = assertDevice(this, { prefix, context: "this" }); - let layout = undefined; - if (descriptor.layout) { + let layout = descriptor.layout; + if (typeof descriptor.layout !== "string") { const context = "layout"; layout = assertResource(descriptor.layout, { prefix, context }); assertDeviceMatch(device, descriptor.layout, { @@ -1299,8 +1307,8 @@ context: "Argument 1", }); const device = assertDevice(this, { prefix, context: "this" }); - let layout = undefined; - if (descriptor.layout) { + let layout = descriptor.layout; + if (typeof descriptor.layout !== "string") { const context = "layout"; layout = assertResource(descriptor.layout, { prefix, context }); assertDeviceMatch(device, descriptor.layout, { @@ -1720,15 +1728,6 @@ } GPUObjectBaseMixin("GPUQueue", GPUQueue); - const _rid = Symbol("[[rid]]"); - - const _size = Symbol("[[size]]"); - const _usage = Symbol("[[usage]]"); - const _state = Symbol("[[state]]"); - const _mappingRange = Symbol("[[mapping_range]]"); - const _mappedRanges = Symbol("[[mapped_ranges]]"); - const _mapMode = Symbol("[[map_mode]]"); - /** * @typedef CreateGPUBufferOptions * @property {ArrayBuffer | null} mapping @@ -2091,8 +2090,6 @@ } } - const _views = Symbol("[[views]]"); - /** * @param {string | null} label * @param {InnerGPUDevice} device @@ -2202,8 +2199,6 @@ } } - const _texture = Symbol("[[texture]]"); - /** * @param {string | null} label * @param {GPUTexture} texture @@ -2661,8 +2656,6 @@ } } - const _encoders = Symbol("[[encoders]]"); - /** * @param {string | null} label * @param {InnerGPUDevice} device @@ -3395,8 +3388,6 @@ GPUObjectBaseMixin("GPUCommandEncoder", GPUCommandEncoder); const GPUCommandEncoderPrototype = GPUCommandEncoder.prototype; - const _encoder = Symbol("[[encoder]]"); - /** * @param {string | null} label * @param {GPUCommandEncoder} encoder @@ -5190,8 +5181,6 @@ } GPUObjectBaseMixin("GPURenderBundle", GPURenderBundle); - const _descriptor = Symbol("[[descriptor]]"); - /** * @param {string | null} label * @param {InnerGPUDevice} device diff --git a/deno_webgpu/src/02_idl_types.js b/deno_webgpu/src/02_idl_types.js index cabd30a5f2..c1532c7ec9 100644 --- a/deno_webgpu/src/02_idl_types.js +++ b/deno_webgpu/src/02_idl_types.js @@ -41,7 +41,7 @@ } = window.__bootstrap.webgpu; const { SymbolIterator, TypeError } = window.__bootstrap.primordials; - // This needs to be initalized after all of the base classes are implmented, + // This needs to be initialized after all of the base classes are implemented, // otherwise their converters might not be available yet. // DICTIONARY: GPUObjectDescriptorBase const dictMembersGPUObjectDescriptorBase = [ @@ -945,11 +945,25 @@ // GPUCompilationInfo.prototype, // ); + webidl.converters["GPUAutoLayoutMode"] = webidl.createEnumConverter( + "GPUAutoLayoutMode", + [ + "auto", + ], + ); + + webidl.converters["GPUPipelineLayout or GPUAutoLayoutMode"] = (V, opts) => { + if (typeof V === "object") { + return webidl.converters["GPUPipelineLayout"](V, opts); + } + return webidl.converters["GPUAutoLayoutMode"](V, opts); + }; + // DICTIONARY: GPUPipelineDescriptorBase const dictMembersGPUPipelineDescriptorBase = [ { key: "layout", - converter: webidl.converters["GPUPipelineLayout"], + converter: webidl.converters["GPUPipelineLayout or GPUAutoLayoutMode"], }, ]; webidl.converters["GPUPipelineDescriptorBase"] = webidl @@ -1440,7 +1454,9 @@ { key: "targets", converter: webidl.createSequenceConverter( - webidl.converters["GPUColorTargetState"], + webidl.createNullableConverter( + webidl.converters["GPUColorTargetState"], + ), ), required: true, }, @@ -1819,7 +1835,9 @@ { key: "colorAttachments", converter: webidl.createSequenceConverter( - webidl.converters["GPURenderPassColorAttachment"], + webidl.createNullableConverter( + webidl.converters["GPURenderPassColorAttachment"], + ), ), required: true, }, @@ -1864,7 +1882,7 @@ { key: "colorFormats", converter: webidl.createSequenceConverter( - webidl.converters["GPUTextureFormat"], + webidl.createNullableConverter(webidl.converters["GPUTextureFormat"]), ), required: true, }, diff --git a/deno_webgpu/src/buffer.rs b/deno_webgpu/src/buffer.rs index 97934c0159..bea1a3bf2d 100644 --- a/deno_webgpu/src/buffer.rs +++ b/deno_webgpu/src/buffer.rs @@ -119,7 +119,8 @@ pub async fn op_webgpu_buffer_get_map_async( { let state = state.borrow(); let instance = state.borrow::(); - gfx_select!(device => instance.device_poll(device, wgpu_types::Maintain::Wait)).unwrap(); + gfx_select!(device => instance.device_poll(device, wgpu_types::Maintain::Wait)) + .unwrap(); } tokio::time::sleep(Duration::from_millis(10)).await; } diff --git a/deno_webgpu/src/lib.rs b/deno_webgpu/src/lib.rs index 25de7f177c..5c2559dbbf 100644 --- a/deno_webgpu/src/lib.rs +++ b/deno_webgpu/src/lib.rs @@ -288,7 +288,7 @@ impl From for wgpu_types::Features { wgpu_types::Features::DEPTH_CLIP_CONTROL, required_features.0.contains("depth-clip-control"), ); - features.set( + features.set( wgpu_types::Features::DEPTH24UNORM_STENCIL8, required_features.0.contains("depth24unorm-stencil8"), ); diff --git a/deno_webgpu/src/pipeline.rs b/deno_webgpu/src/pipeline.rs index 9b135f5d44..aee67f80c2 100644 --- a/deno_webgpu/src/pipeline.rs +++ b/deno_webgpu/src/pipeline.rs @@ -35,6 +35,19 @@ impl Resource for WebGpuRenderPipeline { } } +#[derive(Deserialize)] +#[serde(rename_all = "camelCase")] +pub enum GPUAutoLayoutMode { + Auto, +} + +#[derive(Deserialize)] +#[serde(untagged)] +pub enum GPUPipelineLayoutOrGPUAutoLayoutMode { + Layout(ResourceId), + Auto(GPUAutoLayoutMode), +} + #[derive(Deserialize)] #[serde(rename_all = "camelCase")] pub struct GpuProgrammableStage { @@ -48,7 +61,7 @@ pub fn op_webgpu_create_compute_pipeline( state: &mut OpState, device_rid: ResourceId, label: Option, - layout: Option, + layout: GPUPipelineLayoutOrGPUAutoLayoutMode, compute: GpuProgrammableStage, ) -> Result { let instance = state.borrow::(); @@ -57,11 +70,12 @@ pub fn op_webgpu_create_compute_pipeline( .get::(device_rid)?; let device = device_resource.0; - let pipeline_layout = if let Some(rid) = layout { - let id = state.resource_table.get::(rid)?; - Some(id.0) - } else { - None + let pipeline_layout = match layout { + GPUPipelineLayoutOrGPUAutoLayoutMode::Layout(rid) => { + let id = state.resource_table.get::(rid)?; + Some(id.0) + } + GPUPipelineLayoutOrGPUAutoLayoutMode::Auto(GPUAutoLayoutMode::Auto) => None, }; let compute_shader_module_resource = state @@ -78,11 +92,13 @@ pub fn op_webgpu_create_compute_pipeline( }, }; let implicit_pipelines = match layout { - Some(_) => None, - None => Some(wgpu_core::device::ImplicitPipelineIds { - root_id: std::marker::PhantomData, - group_ids: &[std::marker::PhantomData; MAX_BIND_GROUPS], - }), + GPUPipelineLayoutOrGPUAutoLayoutMode::Layout(_) => None, + GPUPipelineLayoutOrGPUAutoLayoutMode::Auto(GPUAutoLayoutMode::Auto) => { + Some(wgpu_core::device::ImplicitPipelineIds { + root_id: std::marker::PhantomData, + group_ids: &[std::marker::PhantomData; MAX_BIND_GROUPS], + }) + } }; let (compute_pipeline, maybe_err) = gfx_select!(device => instance.device_create_compute_pipeline( @@ -271,7 +287,7 @@ struct GpuFragmentState { pub struct CreateRenderPipelineArgs { device_rid: ResourceId, label: Option, - layout: Option, + layout: GPUPipelineLayoutOrGPUAutoLayoutMode, vertex: GpuVertexState, primitive: GpuPrimitiveState, depth_stencil: Option, @@ -290,11 +306,12 @@ pub fn op_webgpu_create_render_pipeline( .get::(args.device_rid)?; let device = device_resource.0; - let layout = if let Some(rid) = args.layout { - let pipeline_layout_resource = state.resource_table.get::(rid)?; - Some(pipeline_layout_resource.0) - } else { - None + let layout = match args.layout { + GPUPipelineLayoutOrGPUAutoLayoutMode::Layout(rid) => { + let pipeline_layout_resource = state.resource_table.get::(rid)?; + Some(pipeline_layout_resource.0) + } + GPUPipelineLayoutOrGPUAutoLayoutMode::Auto(GPUAutoLayoutMode::Auto) => None, }; let vertex_shader_module_resource = state @@ -344,11 +361,13 @@ pub fn op_webgpu_create_render_pipeline( }; let implicit_pipelines = match args.layout { - Some(_) => None, - None => Some(wgpu_core::device::ImplicitPipelineIds { - root_id: std::marker::PhantomData, - group_ids: &[std::marker::PhantomData; MAX_BIND_GROUPS], - }), + GPUPipelineLayoutOrGPUAutoLayoutMode::Layout(_) => None, + GPUPipelineLayoutOrGPUAutoLayoutMode::Auto(GPUAutoLayoutMode::Auto) => { + Some(wgpu_core::device::ImplicitPipelineIds { + root_id: std::marker::PhantomData, + group_ids: &[std::marker::PhantomData; MAX_BIND_GROUPS], + }) + } }; let (render_pipeline, maybe_err) = gfx_select!(device => instance.device_create_render_pipeline( diff --git a/deno_webgpu/webgpu.idl b/deno_webgpu/webgpu.idl index e088fa2778..cda505715f 100644 --- a/deno_webgpu/webgpu.idl +++ b/deno_webgpu/webgpu.idl @@ -537,8 +537,12 @@ interface GPUCompilationInfo { readonly attribute FrozenArray messages; }; +enum GPUAutoLayoutMode { + "auto" +}; + dictionary GPUPipelineDescriptorBase : GPUObjectDescriptorBase { - required GPUPipelineLayout layout; + required (GPUPipelineLayout or GPUAutoLayoutMode) layout; }; interface mixin GPUPipelineBase {