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 6cfd34e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ By @Valaphee in [#3402](https://github.com/gfx-rs/wgpu/pull/3402)
- Derive storage bindings via `naga::StorageAccess` instead of `naga::GlobalUse`. By @teoxoy in [#3985](https://github.com/gfx-rs/wgpu/pull/3985).
- `Queue::on_submitted_work_done` callbacks will now always be called after all previous `BufferSlice::map_async` callbacks, even when there are no active submissions. By @cwfitzgerald in [#4036](https://github.com/gfx-rs/wgpu/pull/4036).
- Fix `clear` texture views being leaked when `wgpu::SurfaceTexture` is dropped before it is presented. By @rajveermalviya in [#4057](https://github.com/gfx-rs/wgpu/pull/4057).
- Only produce `StageError::InputNotConsumed` on DX11/DX12. By @Aaron1011 in [#4116](https://github.com/gfx-rs/wgpu/pull/4116).

#### Vulkan
- Fix enabling `wgpu::Features::PARTIALLY_BOUND_BINDING_ARRAY` not being actually enabled in vulkan backend. By @39ali in[#3772](https://github.com/gfx-rs/wgpu/pull/3772).
Expand Down
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 6cfd34e

Please sign in to comment.