Skip to content

Commit

Permalink
wgpu-core: Only produce StageError::InputNotConsumed on DX11/DX12 (#4116
Browse files Browse the repository at this point in the history
)

* wgpu-core: Only produce StageError::InputNotConsumed on DX11/DX12

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.

* Add Features::SHADER_UNUSED_VERTEX_OUTPUT to allow disabling check

* Pick an unused feature id
  • Loading branch information
Aaron1011 authored and torokati44 committed Oct 9, 2023
1 parent 75b41fe commit 3c7c941
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ Bottom level categories:

### Bug Fixes

#### General

- Add `Feature::SHADER_UNUSED_VERTEX_OUTPUT` to allow unused vertex shader outputs. By @Aaron1011 in [#4116](https://github.com/gfx-rs/wgpu/pull/4116).

#### Vulkan

- Fix x11 hang while resizing on vulkan. @Azorlogh in [#4184](https://github.com/gfx-rs/wgpu/pull/4184).
Expand Down
7 changes: 7 additions & 0 deletions deno_webgpu/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,9 @@ fn deserialize_features(features: &wgpu_types::Features) -> Vec<&'static str> {
if features.contains(wgpu_types::Features::SHADER_EARLY_DEPTH_TEST) {
return_features.push("shader-early-depth-test");
}
if features.contains(wgpu_types::Features::SHADER_UNUSED_VERTEX_OUTPUT) {
return_features.push("shader-unused-vertex-output");
}

return_features
}
Expand Down Expand Up @@ -624,6 +627,10 @@ impl From<GpuRequiredFeatures> for wgpu_types::Features {
wgpu_types::Features::SHADER_EARLY_DEPTH_TEST,
required_features.0.contains("shader-early-depth-test"),
);
features.set(
wgpu_types::Features::SHADER_UNUSED_VERTEX_OUTPUT,
required_features.0.contains("shader-unused-vertex-output"),
);

features
}
Expand Down
7 changes: 6 additions & 1 deletion wgpu-core/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,12 @@ impl Interface {
}

// Check all vertex outputs and make sure the fragment shader consumes them.
if shader_stage == naga::ShaderStage::Fragment {
// This requirement is removed if the `SHADER_UNUSED_VERTEX_OUTPUT` feature is enabled.
if shader_stage == naga::ShaderStage::Fragment
&& !self
.features
.contains(wgt::Features::SHADER_UNUSED_VERTEX_OUTPUT)
{
for &index in inputs.keys() {
// This is a linear scan, but the count should be low enough
// that this should be fine.
Expand Down
1 change: 1 addition & 0 deletions wgpu-hal/src/gles/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ impl super::Adapter {
ver >= (3, 2) || extensions.contains("OES_geometry_shader"),
);
features.set(wgt::Features::SHADER_EARLY_DEPTH_TEST, ver >= (3, 1));
features.set(wgt::Features::SHADER_UNUSED_VERTEX_OUTPUT, true);
let gles_bcn_exts = [
"GL_EXT_texture_compression_s3tc_srgb",
"GL_EXT_texture_compression_rgtc",
Expand Down
1 change: 1 addition & 0 deletions wgpu-hal/src/metal/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,7 @@ impl super::PrivateCapabilities {
features.set(F::ADDRESS_MODE_CLAMP_TO_ZERO, true);

features.set(F::RG11B10UFLOAT_RENDERABLE, self.format_rg11b10_all);
features.set(F::SHADER_UNUSED_VERTEX_OUTPUT, true);

features
}
Expand Down
1 change: 1 addition & 0 deletions wgpu-hal/src/vulkan/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ impl PhysicalDeviceFeatures {
| vk::FormatFeatureFlags::COLOR_ATTACHMENT_BLEND,
);
features.set(F::RG11B10UFLOAT_RENDERABLE, rg11b10ufloat_renderable);
features.set(F::SHADER_UNUSED_VERTEX_OUTPUT, true);

(features, dl_flags)
}
Expand Down
9 changes: 9 additions & 0 deletions wgpu-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,15 @@ bitflags::bitflags! {
/// This is a native only feature.
const VERTEX_ATTRIBUTE_64BIT = 1 << 53;

/// Allows vertex shaders to have outputs which are not consumed
/// by the fragment shader.
///
/// Supported platforms:
/// - Vulkan
/// - Metal
/// - OpenGL
const SHADER_UNUSED_VERTEX_OUTPUT = 1 << 54;

// 54..59 available

// Shader:
Expand Down

0 comments on commit 3c7c941

Please sign in to comment.