fix(naga): disallow result types in compute shaders

This commit is contained in:
Erich Gubler committed 2026-08-19 20:04:16 +02:00
1 parent 0b5a96dbd8
commit 468e9da9a5
3 files changed
+41 -1

No files matched your search

+1
View File
@@ -130,6 +130,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).
#### DX12
+5 -1
View File
@@ -191,6 +191,8 @@ pub enum EntryPointError {
RayPayloadInInvalidStage(crate::ShaderStage),
#[error("Only the `closest_hit`, `any_hit`, and `miss` shader stages can access a global variable in the `incoming_ray_payload` address space")]
IncomingRayPayloadInInvalidStage(crate::ShaderStage),
#[error("Compute shader entry point cannot have a return type")]
UnexpectedComputeShaderEntryResult,
}
fn storage_usage(access: crate::StorageAccess) -> GlobalUse {
@@ -1424,8 +1426,10 @@ impl super::Validator {
return Err(EntryPointError::WrongTaskShaderEntryResult.with_span());
}
}
nt::ShaderStage::Compute => {
return Err(EntryPointError::UnexpectedComputeShaderEntryResult.with_span())
}
nt::ShaderStage::Fragment
| nt::ShaderStage::Compute
| nt::ShaderStage::RayGeneration
| nt::ShaderStage::Miss
| nt::ShaderStage::AnyHit
+35
View File
@@ -5666,3 +5666,38 @@ fn unterminated_block_comment_errors() {
"unterminated block comment",
)
}
#[test]
fn compute_shaders_dont_accept_result_types() {
check_validation! {
"
@compute @workgroup_size(1)
fn main() -> @location(0) u32 { return 0; }
":
Err(
naga::valid::ValidationError::EntryPoint {
stage: naga::ShaderStage::Compute,
source: naga::valid::EntryPointError::UnexpectedComputeShaderEntryResult,
..
},
)
}
check_validation! {
"
struct ComputeOutput {
@location(0) output0: vec4<f32>,
@location(1) output1: u32,
}
@compute @workgroup_size(1)
fn main() -> ComputeOutput { return ComputeOutput(vec4(0.0), 1); }
":
Err(
naga::valid::ValidationError::EntryPoint {
stage: naga::ShaderStage::Compute,
source: naga::valid::EntryPointError::UnexpectedComputeShaderEntryResult,
..
},
)
}
}