From 0db00e9657fecbb98ad2d167ff5cde0624c092ba Mon Sep 17 00:00:00 2001 From: initial-algebra <67286231+initial-algebra@users.noreply.github.com> Date: Sat, 17 Jul 2021 15:31:35 -0200 Subject: [PATCH] Implement `Feature::SHADER_PRIMITIVE_INDEX` on Vulkan --- Cargo.lock | 2 +- wgpu-core/Cargo.toml | 2 +- wgpu-core/src/device/mod.rs | 5 +++++ wgpu-hal/Cargo.toml | 4 ++-- wgpu-hal/src/vulkan/adapter.rs | 2 ++ wgpu-types/src/lib.rs | 11 +++++++++++ wgpu/Cargo.toml | 4 ++-- 7 files changed, 24 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c1a33fb97..460f49db0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1051,7 +1051,7 @@ dependencies = [ [[package]] name = "naga" version = "0.5.0" -source = "git+https://github.com/gfx-rs/naga?rev=458db0b#458db0b5228854dc417283f4b9742e03f25bc492" +source = "git+https://github.com/gfx-rs/naga?rev=8f71a36#8f71a368eff3a18fd348ab6193cb183df0f49f95" dependencies = [ "bit-set", "bitflags", diff --git a/wgpu-core/Cargo.toml b/wgpu-core/Cargo.toml index 2aa0e43f0..c9f408588 100644 --- a/wgpu-core/Cargo.toml +++ b/wgpu-core/Cargo.toml @@ -36,7 +36,7 @@ thiserror = "1" [dependencies.naga] git = "https://github.com/gfx-rs/naga" -rev = "458db0b" +rev = "8f71a36" features = ["wgsl-in"] [dependencies.wgt] diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index 1fd38bb34..8ea2c934f 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -898,6 +898,11 @@ impl Device { Caps::FLOAT64, self.features.contains(wgt::Features::SHADER_FLOAT64), ); + caps.set( + Caps::PRIMITIVE_INDEX, + self.features + .contains(wgt::Features::SHADER_PRIMITIVE_INDEX), + ); let info = naga::valid::Validator::new(naga::valid::ValidationFlags::all(), caps) .validate(&module)?; let interface = validation::Interface::new(&module, &info, self.features); diff --git a/wgpu-hal/Cargo.toml b/wgpu-hal/Cargo.toml index 63e81dc2b..d30363600 100644 --- a/wgpu-hal/Cargo.toml +++ b/wgpu-hal/Cargo.toml @@ -65,11 +65,11 @@ core-graphics-types = "0.1" [dependencies.naga] git = "https://github.com/gfx-rs/naga" -rev = "458db0b" +rev = "8f71a36" [dev-dependencies.naga] git = "https://github.com/gfx-rs/naga" -rev = "458db0b" +rev = "8f71a36" features = ["wgsl-in"] [dev-dependencies] diff --git a/wgpu-hal/src/vulkan/adapter.rs b/wgpu-hal/src/vulkan/adapter.rs index 0f8a95daa..0ceef3a43 100644 --- a/wgpu-hal/src/vulkan/adapter.rs +++ b/wgpu-hal/src/vulkan/adapter.rs @@ -125,6 +125,7 @@ impl PhysicalDeviceFeatures { //.shader_int64(requested_features.contains(wgt::Features::SHADER_INT64)) //.shader_int16(requested_features.contains(wgt::Features::SHADER_INT16)) //.shader_resource_residency(requested_features.contains(wgt::Features::SHADER_RESOURCE_RESIDENCY)) + .geometry_shader(requested_features.contains(wgt::Features::SHADER_PRIMITIVE_INDEX)) .build(), vulkan_1_2: if api_version >= vk::API_VERSION_1_2 { Some( @@ -290,6 +291,7 @@ impl PhysicalDeviceFeatures { F::TEXTURE_BINDING_ARRAY, self.core.shader_sampled_image_array_dynamic_indexing != 0, ); + features.set(F::SHADER_PRIMITIVE_INDEX, self.core.geometry_shader != 0); if Self::all_features_supported( &features, &[ diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 1b96cfdca..7c581d6c5 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -479,6 +479,17 @@ bitflags::bitflags! { /// /// This is a native only feature. const SPIRV_SHADER_PASSTHROUGH = 0x0000_0800_0000_0000; + /// Enables `builtin(primitive_index)` in fragment shaders. + /// + /// Note: enables geometry processing for pipelines using the builtin. + /// This may come with a significant performance impact on some hardware. + /// Other pipelines are not affected. + /// + /// Supported platforms: + /// - Vulkan + /// + /// This is a native only feature. + const SHADER_PRIMITIVE_INDEX = 0x0000_1000_0000_0000; } } diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index ca5f015b3..56d751d91 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -73,13 +73,13 @@ env_logger = "0.8" [dependencies.naga] git = "https://github.com/gfx-rs/naga" -rev = "458db0b" +rev = "8f71a36" optional = true # used to test all the example shaders [dev-dependencies.naga] git = "https://github.com/gfx-rs/naga" -rev = "458db0b" +rev = "8f71a36" features = ["wgsl-in"] [[example]]