Skip to content

Commit

Permalink
Add Features::SHADER_UNUSED_VERTEX_OUTPUT to allow disabling check
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron1011 committed Sep 13, 2023
1 parent 6cfd34e commit da0c51d
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +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).
- 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 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
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 @@ -625,6 +628,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
3 changes: 2 additions & 1 deletion wgpu-core/src/device/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1286,7 +1286,8 @@ impl<A: HalApi> Device<A> {
inner: Box::new(inner),
})
})?;
let interface = validation::Interface::new(&module, &info, self.limits.clone(), A::VARIANT);
let interface =
validation::Interface::new(&module, &info, self.limits.clone(), self.features);
let hal_shader = hal::ShaderInput::Naga(hal::NagaShader { module, info });

let hal_desc = hal::ShaderModuleDescriptor {
Expand Down
13 changes: 7 additions & 6 deletions wgpu-core/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ struct EntryPoint {
#[derive(Debug)]
pub struct Interface {
limits: wgt::Limits,
backend: wgt::Backend,
features: wgt::Features,
resources: naga::Arena<Resource>,
entry_points: FastHashMap<(naga::ShaderStage, String), EntryPoint>,
}
Expand Down Expand Up @@ -834,7 +834,7 @@ impl Interface {
module: &naga::Module,
info: &naga::valid::ModuleInfo,
limits: wgt::Limits,
backend: wgt::Backend,
features: wgt::Features,
) -> Self {
let mut resources = naga::Arena::new();
let mut resource_mapping = FastHashMap::default();
Expand Down Expand Up @@ -916,7 +916,7 @@ impl Interface {

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

// Check all vertex outputs and make sure the fragment shader consumes them.
// This is only needed for HLSL shaders (DX11 and DX12) due to a naga HLSL issue:
// https://github.com/gfx-rs/naga/issues/1945
// This requirement is removed if the `SHADER_UNUSED_VERTEX_OUTPUT` feature is enabled.
if shader_stage == naga::ShaderStage::Fragment
&& matches!(self.backend, wgt::Backend::Dx11 | wgt::Backend::Dx12)
&& !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
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_EARLY_DEPTH_TEST, 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 @@ -847,6 +847,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 @@ -520,6 +520,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 @@ -782,6 +782,15 @@ bitflags::bitflags! {
/// This is a native only feature.
const SHADER_EARLY_DEPTH_TEST = 1 << 62;

/// 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 << 63;

// 62..64 available
}
}
Expand Down

0 comments on commit da0c51d

Please sign in to comment.