Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upstream deno changes #2895

Merged
merged 3 commits into from
Jul 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 34 additions & 45 deletions deno_webgpu/src/01_webgpu.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -233,9 +258,6 @@
}
const GPUPrototype = GPU.prototype;

const _adapter = Symbol("[[adapter]]");
const _cleanup = Symbol("[[cleanup]]");

/**
* @typedef InnerGPUAdapter
* @property {number} rid
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -419,8 +438,6 @@
}
const GPUAdapterInfoPrototype = GPUAdapterInfo.prototype;

const _limits = Symbol("[[limits]]");

function createGPUSupportedLimits(features) {
/** @type {GPUSupportedLimits} */
const adapterFeatures = webidl.createBranded(GPUSupportedLimits);
Expand Down Expand Up @@ -576,8 +593,6 @@
}
const GPUSupportedLimitsPrototype = GPUSupportedLimits.prototype;

const _features = Symbol("[[features]]");

function createGPUSupportedFeatures(features) {
/** @type {GPUSupportedFeatures} */
const adapterFeatures = webidl.createBranded(GPUSupportedFeatures);
Expand Down Expand Up @@ -643,9 +658,6 @@

const GPUSupportedFeaturesPrototype = GPUSupportedFeatures.prototype;

const _reason = Symbol("[[reason]]");
const _message = Symbol("[[message]]");

/**
* @param {string | undefined} reason
* @param {string} message
Expand Down Expand Up @@ -687,8 +699,6 @@

const GPUDeviceLostInfoPrototype = GPUDeviceLostInfo.prototype;

const _label = Symbol("[[label]]");

/**
* @param {string} name
* @param {any} type
Expand Down Expand Up @@ -717,9 +727,6 @@
});
}

const _device = Symbol("[[device]]");
const _queue = Symbol("[[queue]]");

/**
* @typedef ErrorScope
* @property {string} filter
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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, {
Expand Down Expand Up @@ -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, {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -2091,8 +2090,6 @@
}
}

const _views = Symbol("[[views]]");

/**
* @param {string | null} label
* @param {InnerGPUDevice} device
Expand Down Expand Up @@ -2202,8 +2199,6 @@
}
}

const _texture = Symbol("[[texture]]");

/**
* @param {string | null} label
* @param {GPUTexture} texture
Expand Down Expand Up @@ -2661,8 +2656,6 @@
}
}

const _encoders = Symbol("[[encoders]]");

/**
* @param {string | null} label
* @param {InnerGPUDevice} device
Expand Down Expand Up @@ -3395,8 +3388,6 @@
GPUObjectBaseMixin("GPUCommandEncoder", GPUCommandEncoder);
const GPUCommandEncoderPrototype = GPUCommandEncoder.prototype;

const _encoder = Symbol("[[encoder]]");

/**
* @param {string | null} label
* @param {GPUCommandEncoder} encoder
Expand Down Expand Up @@ -5190,8 +5181,6 @@
}
GPUObjectBaseMixin("GPURenderBundle", GPURenderBundle);

const _descriptor = Symbol("[[descriptor]]");

/**
* @param {string | null} label
* @param {InnerGPUDevice} device
Expand Down
28 changes: 23 additions & 5 deletions deno_webgpu/src/02_idl_types.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1440,7 +1454,9 @@
{
key: "targets",
converter: webidl.createSequenceConverter(
webidl.converters["GPUColorTargetState"],
webidl.createNullableConverter(
webidl.converters["GPUColorTargetState"],
),
),
required: true,
},
Expand Down Expand Up @@ -1819,7 +1835,9 @@
{
key: "colorAttachments",
converter: webidl.createSequenceConverter(
webidl.converters["GPURenderPassColorAttachment"],
webidl.createNullableConverter(
webidl.converters["GPURenderPassColorAttachment"],
),
),
required: true,
},
Expand Down Expand Up @@ -1864,7 +1882,7 @@
{
key: "colorFormats",
converter: webidl.createSequenceConverter(
webidl.converters["GPUTextureFormat"],
webidl.createNullableConverter(webidl.converters["GPUTextureFormat"]),
),
required: true,
},
Expand Down
3 changes: 2 additions & 1 deletion deno_webgpu/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion deno_webgpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
);
Expand Down
63 changes: 41 additions & 22 deletions deno_webgpu/src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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>();
Expand All @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -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>,
Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand Down
Loading