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:
Samson 2024-09-04 13:31:07 +02:00 committed by GitHub
parent a976db3ec0
commit 3c6ca33832
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 32 additions and 395 deletions

View file

@ -6,8 +6,10 @@ use std::borrow::Cow;
use std::num::NonZeroU64;
use webgpu::wgc::command as wgpu_com;
use webgpu::wgc::pipeline::ProgrammableStageDescriptor;
use webgpu::wgt::{self, AstcBlock, AstcChannel};
use super::bindings::codegen::Bindings::WebGPUBinding::GPUProgrammableStage;
use super::bindings::error::Error;
use crate::dom::bindings::codegen::Bindings::WebGPUBinding::{
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() {
None
} 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,
}
}
}