upstream deno changes (#2895)

* upstream GPUAutoLayoutMode

* clean up symbols and fix miscalled op

* fix gfx-rs/wgpu#2778
This commit is contained in:
Leo Kettmeir 2022-07-20 18:47:10 +02:00 committed by GitHub
parent e49ef97311
commit 534ad76d5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 106 additions and 75 deletions

View File

@ -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

View File

@ -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,
},

View File

@ -119,7 +119,8 @@ pub async fn op_webgpu_buffer_get_map_async(
{
let state = state.borrow();
let instance = state.borrow::<super::Instance>();
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;
}

View File

@ -288,7 +288,7 @@ impl From<GpuRequiredFeatures> 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"),
);

View File

@ -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<String>,
layout: Option<ResourceId>,
layout: GPUPipelineLayoutOrGPUAutoLayoutMode,
compute: GpuProgrammableStage,
) -> Result<WebGpuResult, AnyError> {
let instance = state.borrow::<super::Instance>();
@ -57,11 +70,12 @@ pub fn op_webgpu_create_compute_pipeline(
.get::<super::WebGpuDevice>(device_rid)?;
let device = device_resource.0;
let pipeline_layout = if let Some(rid) = layout {
let id = state.resource_table.get::<WebGpuPipelineLayout>(rid)?;
Some(id.0)
} else {
None
let pipeline_layout = match layout {
GPUPipelineLayoutOrGPUAutoLayoutMode::Layout(rid) => {
let id = state.resource_table.get::<WebGpuPipelineLayout>(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<String>,
layout: Option<ResourceId>,
layout: GPUPipelineLayoutOrGPUAutoLayoutMode,
vertex: GpuVertexState,
primitive: GpuPrimitiveState,
depth_stencil: Option<GpuDepthStencilState>,
@ -290,11 +306,12 @@ pub fn op_webgpu_create_render_pipeline(
.get::<super::WebGpuDevice>(args.device_rid)?;
let device = device_resource.0;
let layout = if let Some(rid) = args.layout {
let pipeline_layout_resource = state.resource_table.get::<WebGpuPipelineLayout>(rid)?;
Some(pipeline_layout_resource.0)
} else {
None
let layout = match args.layout {
GPUPipelineLayoutOrGPUAutoLayoutMode::Layout(rid) => {
let pipeline_layout_resource = state.resource_table.get::<WebGpuPipelineLayout>(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(

View File

@ -537,8 +537,12 @@ interface GPUCompilationInfo {
readonly attribute FrozenArray<GPUCompilationMessage> messages;
};
enum GPUAutoLayoutMode {
"auto"
};
dictionary GPUPipelineDescriptorBase : GPUObjectDescriptorBase {
required GPUPipelineLayout layout;
required (GPUPipelineLayout or GPUAutoLayoutMode) layout;
};
interface mixin GPUPipelineBase {