Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ By @wumpf in [#4147](https://github.com/gfx-rs/wgpu/pull/4147)
- 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).
- 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 @@ -1290,7 +1290,8 @@ 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(), self.features);
let hal_shader = hal::ShaderInput::Naga(hal::NagaShader { module, info });

let hal_desc = hal::ShaderModuleDescriptor {
Expand Down
16 changes: 14 additions & 2 deletions wgpu-core/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ struct EntryPoint {
#[derive(Debug)]
pub struct Interface {
limits: wgt::Limits,
features: wgt::Features,
resources: naga::Arena<Resource>,
entry_points: FastHashMap<(naga::ShaderStage, String), EntryPoint>,
}
Expand Down Expand Up @@ -831,7 +832,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,
features: wgt::Features,
) -> 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 @@ -912,6 +918,7 @@ impl Interface {

Self {
limits,
features,
resources,
entry_points,
}
Expand Down Expand Up @@ -1121,7 +1128,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 @@ -372,6 +372,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 @@ -871,6 +871,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 @@ -522,6 +522,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 @@ -737,6 +737,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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noticed, this line did not get updated.


// Shader:
Expand Down