Skip to content

Commit

Permalink
wgpu-core: Only produce StageError::InputNotConsumed on DX11/DX12
Browse files Browse the repository at this point in the history
This error only exists due to an issue with naga's HLSL support:
gfx-rs/naga#1945
The WGPU spec itself allows vertex shader outputs that are
not consumed by the fragment shader.

Until the issue is fixed, we can allow unconsumed outputs on
all platforms other than DX11/DX12.
  • Loading branch information
Aaron1011 committed Sep 5, 2023
1 parent 54a7f0e commit 8b5f328
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion wgpu-core/src/device/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1286,7 +1286,7 @@ impl<A: HalApi> Device<A> {
inner: Box::new(inner),
})
})?;
let interface = validation::Interface::new(&module, &info, self.limits.clone());
let interface = validation::Interface::new(&module, &info, self.limits.clone(), A::VARIANT);
let hal_shader = hal::ShaderInput::Naga(hal::NagaShader { module, info });

let hal_desc = hal::ShaderModuleDescriptor {
Expand Down
15 changes: 13 additions & 2 deletions wgpu-core/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ struct EntryPoint {
#[derive(Debug)]
pub struct Interface {
limits: wgt::Limits,
backend: wgt::Backend,
resources: naga::Arena<Resource>,
entry_points: FastHashMap<(naga::ShaderStage, String), EntryPoint>,
}
Expand Down Expand Up @@ -829,7 +830,12 @@ impl Interface {
list.push(varying);
}

pub fn new(module: &naga::Module, info: &naga::valid::ModuleInfo, limits: wgt::Limits) -> Self {
pub fn new(
module: &naga::Module,
info: &naga::valid::ModuleInfo,
limits: wgt::Limits,
backend: wgt::Backend,
) -> Self {
let mut resources = naga::Arena::new();
let mut resource_mapping = FastHashMap::default();
for (var_handle, var) in module.global_variables.iter() {
Expand Down Expand Up @@ -910,6 +916,7 @@ impl Interface {

Self {
limits,
backend,
resources,
entry_points,
}
Expand Down Expand Up @@ -1119,7 +1126,11 @@ impl Interface {
}

// Check all vertex outputs and make sure the fragment shader consumes them.
if shader_stage == naga::ShaderStage::Fragment {
// This is only needed for HLSL shaders (DX11 and DX12) due to a naga HLSL issue:
// https://github.com/gfx-rs/naga/issues/1945
if shader_stage == naga::ShaderStage::Fragment
&& matches!(self.backend, wgt::Backend::Dx11 | wgt::Backend::Dx12)
{
for &index in inputs.keys() {
// This is a linear scan, but the count should be low enough
// that this should be fine.
Expand Down

0 comments on commit 8b5f328

Please sign in to comment.