mirror of
https://github.com/servo/servo.git
synced 2025-08-04 21:20:23 +01:00
webgpu: Support pipeline-overridable constants (#33291)
* Impl pipeline constants Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> * More relaxed lifetimes Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> * Update expectations Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> * Replace convert function with `From` implementation Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> --------- Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This commit is contained in:
parent
a976db3ec0
commit
3c6ca33832
4 changed files with 32 additions and 395 deletions
|
@ -6,8 +6,10 @@ use std::borrow::Cow;
|
||||||
use std::num::NonZeroU64;
|
use std::num::NonZeroU64;
|
||||||
|
|
||||||
use webgpu::wgc::command as wgpu_com;
|
use webgpu::wgc::command as wgpu_com;
|
||||||
|
use webgpu::wgc::pipeline::ProgrammableStageDescriptor;
|
||||||
use webgpu::wgt::{self, AstcBlock, AstcChannel};
|
use webgpu::wgt::{self, AstcBlock, AstcChannel};
|
||||||
|
|
||||||
|
use super::bindings::codegen::Bindings::WebGPUBinding::GPUProgrammableStage;
|
||||||
use super::bindings::error::Error;
|
use super::bindings::error::Error;
|
||||||
use crate::dom::bindings::codegen::Bindings::WebGPUBinding::{
|
use crate::dom::bindings::codegen::Bindings::WebGPUBinding::{
|
||||||
GPUAddressMode, GPUBindGroupLayoutEntry, GPUBlendComponent, GPUBlendFactor, GPUBlendOperation,
|
GPUAddressMode, GPUBindGroupLayoutEntry, GPUBlendComponent, GPUBlendFactor, GPUBlendOperation,
|
||||||
|
@ -473,7 +475,7 @@ pub fn convert_ic_texture(
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn convert_label(parent: &GPUObjectDescriptorBase) -> Option<Cow<'static, str>> {
|
pub fn convert_label<'a>(parent: &GPUObjectDescriptorBase) -> Option<Cow<'a, str>> {
|
||||||
if parent.label.is_empty() {
|
if parent.label.is_empty() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
|
@ -579,3 +581,23 @@ pub fn convert_color(color: &GPUColor) -> Fallible<wgt::Color> {
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a> From<&GPUProgrammableStage> for ProgrammableStageDescriptor<'a> {
|
||||||
|
fn from(stage: &GPUProgrammableStage) -> Self {
|
||||||
|
Self {
|
||||||
|
module: stage.module.id().0,
|
||||||
|
entry_point: stage
|
||||||
|
.entryPoint
|
||||||
|
.as_ref()
|
||||||
|
.map(|ep| Cow::Owned(ep.to_string())),
|
||||||
|
constants: Cow::Owned(
|
||||||
|
stage
|
||||||
|
.constants
|
||||||
|
.as_ref()
|
||||||
|
.map(|records| records.iter().map(|(k, v)| (k.0.clone(), **v)).collect())
|
||||||
|
.unwrap_or_default(),
|
||||||
|
),
|
||||||
|
zero_initialize_workgroup_memory: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
|
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use std::collections::HashMap;
|
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
|
@ -246,12 +245,12 @@ impl GPUDevice {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_render_pipeline(
|
fn parse_render_pipeline<'a>(
|
||||||
&self,
|
&self,
|
||||||
descriptor: &GPURenderPipelineDescriptor,
|
descriptor: &GPURenderPipelineDescriptor,
|
||||||
) -> Fallible<(
|
) -> Fallible<(
|
||||||
Option<(PipelineLayoutId, Vec<BindGroupLayoutId>)>,
|
Option<(PipelineLayoutId, Vec<BindGroupLayoutId>)>,
|
||||||
RenderPipelineDescriptor<'static>,
|
RenderPipelineDescriptor<'a>,
|
||||||
)> {
|
)> {
|
||||||
let (layout, implicit_ids, _) = self.get_pipeline_layout_data(&descriptor.parent.layout);
|
let (layout, implicit_ids, _) = self.get_pipeline_layout_data(&descriptor.parent.layout);
|
||||||
|
|
||||||
|
@ -260,17 +259,7 @@ impl GPUDevice {
|
||||||
layout,
|
layout,
|
||||||
cache: None,
|
cache: None,
|
||||||
vertex: wgpu_pipe::VertexState {
|
vertex: wgpu_pipe::VertexState {
|
||||||
stage: wgpu_pipe::ProgrammableStageDescriptor {
|
stage: (&descriptor.vertex.parent).into(),
|
||||||
module: descriptor.vertex.parent.module.id().0,
|
|
||||||
entry_point: descriptor
|
|
||||||
.vertex
|
|
||||||
.parent
|
|
||||||
.entryPoint
|
|
||||||
.as_ref()
|
|
||||||
.map(|ep| Cow::Owned(ep.to_string())),
|
|
||||||
constants: Cow::Owned(HashMap::new()),
|
|
||||||
zero_initialize_workgroup_memory: true,
|
|
||||||
},
|
|
||||||
buffers: Cow::Owned(
|
buffers: Cow::Owned(
|
||||||
descriptor
|
descriptor
|
||||||
.vertex
|
.vertex
|
||||||
|
@ -302,16 +291,7 @@ impl GPUDevice {
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|stage| -> Fallible<wgpu_pipe::FragmentState> {
|
.map(|stage| -> Fallible<wgpu_pipe::FragmentState> {
|
||||||
Ok(wgpu_pipe::FragmentState {
|
Ok(wgpu_pipe::FragmentState {
|
||||||
stage: wgpu_pipe::ProgrammableStageDescriptor {
|
stage: (&stage.parent).into(),
|
||||||
module: stage.parent.module.id().0,
|
|
||||||
entry_point: stage
|
|
||||||
.parent
|
|
||||||
.entryPoint
|
|
||||||
.as_ref()
|
|
||||||
.map(|ep| Cow::Owned(ep.to_string())),
|
|
||||||
constants: Cow::Owned(HashMap::new()),
|
|
||||||
zero_initialize_workgroup_memory: true,
|
|
||||||
},
|
|
||||||
targets: Cow::Owned(
|
targets: Cow::Owned(
|
||||||
stage
|
stage
|
||||||
.targets
|
.targets
|
||||||
|
@ -670,16 +650,7 @@ impl GPUDeviceMethods for GPUDevice {
|
||||||
let desc = wgpu_pipe::ComputePipelineDescriptor {
|
let desc = wgpu_pipe::ComputePipelineDescriptor {
|
||||||
label: convert_label(&descriptor.parent.parent),
|
label: convert_label(&descriptor.parent.parent),
|
||||||
layout,
|
layout,
|
||||||
stage: wgpu_pipe::ProgrammableStageDescriptor {
|
stage: (&descriptor.compute).into(),
|
||||||
module: descriptor.compute.module.id().0,
|
|
||||||
entry_point: descriptor
|
|
||||||
.compute
|
|
||||||
.entryPoint
|
|
||||||
.as_ref()
|
|
||||||
.map(|ep| Cow::Owned(ep.to_string())),
|
|
||||||
constants: Cow::Owned(HashMap::new()),
|
|
||||||
zero_initialize_workgroup_memory: true,
|
|
||||||
},
|
|
||||||
cache: None,
|
cache: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -721,16 +692,7 @@ impl GPUDeviceMethods for GPUDevice {
|
||||||
let desc = wgpu_pipe::ComputePipelineDescriptor {
|
let desc = wgpu_pipe::ComputePipelineDescriptor {
|
||||||
label: convert_label(&descriptor.parent.parent),
|
label: convert_label(&descriptor.parent.parent),
|
||||||
layout,
|
layout,
|
||||||
stage: wgpu_pipe::ProgrammableStageDescriptor {
|
stage: (&descriptor.compute).into(),
|
||||||
module: descriptor.compute.module.id().0,
|
|
||||||
entry_point: descriptor
|
|
||||||
.compute
|
|
||||||
.entryPoint
|
|
||||||
.as_ref()
|
|
||||||
.map(|ep| Cow::Owned(ep.to_string())),
|
|
||||||
constants: Cow::Owned(HashMap::new()),
|
|
||||||
zero_initialize_workgroup_memory: true,
|
|
||||||
},
|
|
||||||
cache: None,
|
cache: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -625,8 +625,11 @@ interface mixin GPUPipelineBase {
|
||||||
dictionary GPUProgrammableStage {
|
dictionary GPUProgrammableStage {
|
||||||
required GPUShaderModule module;
|
required GPUShaderModule module;
|
||||||
USVString entryPoint;
|
USVString entryPoint;
|
||||||
|
record<USVString, GPUPipelineConstantValue> constants;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef double GPUPipelineConstantValue; // May represent WGSL's bool, f32, i32, u32, and f16 if enabled.
|
||||||
|
|
||||||
[Exposed=(Window, DedicatedWorker), Serializable, Pref="dom.webgpu.enabled"]
|
[Exposed=(Window, DedicatedWorker), Serializable, Pref="dom.webgpu.enabled"]
|
||||||
interface GPUComputePipeline {
|
interface GPUComputePipeline {
|
||||||
};
|
};
|
||||||
|
|
350
tests/wpt/webgpu/meta/webgpu/cts.https.html.ini
vendored
350
tests/wpt/webgpu/meta/webgpu/cts.https.html.ini
vendored
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue