mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-21 15:00:57 +01:00
fix(naga): reject @location(…)s for input in compute shaders
This commit is contained in:
1 parent
468e9da9a5
commit
f28f1bf49f
3 files changed
+78
No files matched your search
@@ -131,6 +131,7 @@ By @sagudev in [#10109](https://github.com/gfx-rs/wgpu/pull/10109).
|
||||
- Replace embedded NUL characters with `?` when writing debug strings to SPIR-V. By @andyleiserson in [#9904](https://github.com/gfx-rs/wgpu/pull/9904).
|
||||
- Fix invalid HLSL generated for `textureSampleLevel` with non-2D textures. By @mvanhorn in [#9717](https://github.com/gfx-rs/wgpu/issues/9717).
|
||||
- Reject return types on compute shader entrypoints. By @ErichDonGubler in [#10026](https://github.com/gfx-rs/wgpu/pull/10026).
|
||||
- Reject `@location(…)`s in compute shaders. By @ErichDonGubler in [#10026](https://github.com/gfx-rs/wgpu/pull/10026).
|
||||
|
||||
#### DX12
|
||||
|
||||
|
||||
@@ -1387,6 +1387,36 @@ impl super::Validator {
|
||||
};
|
||||
ctx.validate(ep, fa.ty, fa.binding.as_ref())
|
||||
.map_err_inner(|e| EntryPointError::Argument(index as u32, e).with_span())?;
|
||||
match ep.stage {
|
||||
nt::ShaderStage::Compute | nt::ShaderStage::Mesh | nt::ShaderStage::Task => {
|
||||
let reject_location_binding = |binding| {
|
||||
if let Some(&crate::ir::Binding::Location { .. }) = binding {
|
||||
return Err(EntryPointError::Argument(
|
||||
index as u32,
|
||||
VaryingError::InvalidAttributeInStage("location", ep.stage),
|
||||
)
|
||||
.with_span());
|
||||
}
|
||||
Ok(())
|
||||
};
|
||||
reject_location_binding(fa.binding.as_ref())?;
|
||||
|
||||
if let &crate::TypeInner::Struct { ref members, .. } =
|
||||
&module.types[fa.ty].inner
|
||||
{
|
||||
members
|
||||
.iter()
|
||||
.map(|m| m.binding.as_ref())
|
||||
.try_for_each(reject_location_binding)?;
|
||||
}
|
||||
}
|
||||
nt::ShaderStage::Vertex
|
||||
| nt::ShaderStage::Fragment
|
||||
| nt::ShaderStage::RayGeneration
|
||||
| nt::ShaderStage::Miss
|
||||
| nt::ShaderStage::AnyHit
|
||||
| nt::ShaderStage::ClosestHit => {}
|
||||
}
|
||||
}
|
||||
|
||||
self.location_mask.make_empty();
|
||||
|
||||
@@ -5701,3 +5701,50 @@ fn compute_shaders_dont_accept_result_types() {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn user_locations_not_accepted_in_compute_entry_point_arguments() {
|
||||
check_validation! {
|
||||
"
|
||||
@compute @workgroup_size(1)
|
||||
fn main(@location(0) _input: u32) { return; }
|
||||
":
|
||||
Err(
|
||||
naga::valid::ValidationError::EntryPoint {
|
||||
stage: naga::ShaderStage::Compute,
|
||||
source: naga::valid::EntryPointError::Argument(
|
||||
0,
|
||||
naga::valid::VaryingError::InvalidAttributeInStage(
|
||||
"location",
|
||||
naga::ShaderStage::Compute,
|
||||
),
|
||||
),
|
||||
..
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
check_validation! {
|
||||
"
|
||||
struct ComputeInput {
|
||||
@location(0) input0: vec4<f32>,
|
||||
@location(1) input1: u32,
|
||||
}
|
||||
@compute @workgroup_size(1)
|
||||
fn main(_input: ComputeInput) { return; }
|
||||
":
|
||||
Err(
|
||||
naga::valid::ValidationError::EntryPoint {
|
||||
stage: naga::ShaderStage::Compute,
|
||||
source: naga::valid::EntryPointError::Argument(
|
||||
0,
|
||||
naga::valid::VaryingError::InvalidAttributeInStage(
|
||||
"location",
|
||||
naga::ShaderStage::Compute
|
||||
),
|
||||
),
|
||||
..
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user