Skip to content

Implement SAMPLED_TEXTURE_ARRAY_NON_UNIFORM_INDEXING #715

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

Merged
merged 1 commit into from
Jun 12, 2020
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
20 changes: 10 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions wgpu-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ bitflags = "1.0"
copyless = "0.1"
fxhash = "0.2"
log = "0.4"
hal = { package = "gfx-hal", version = "0.5.1" }
hal = { package = "gfx-hal", version = "0.5.2" }
gfx-backend-empty = "0.5"
gfx-descriptor = "0.1"
gfx-memory = "0.1"
Expand All @@ -51,16 +51,16 @@ version = "0.5"
features = ["peek-poke"]

[target.'cfg(any(target_os = "ios", target_os = "macos"))'.dependencies]
gfx-backend-metal = { version = "0.5.3" }
gfx-backend-vulkan = { version = "0.5.7", optional = true }
gfx-backend-metal = { version = "0.5.4" }
gfx-backend-vulkan = { version = "0.5.6", optional = true }

[target.'cfg(all(unix, not(target_os = "ios"), not(target_os = "macos")))'.dependencies]
gfx-backend-vulkan = { version = "0.5.7" }
gfx-backend-vulkan = { version = "0.5.6" }

[target.'cfg(windows)'.dependencies]
gfx-backend-dx12 = { version = "0.5.5" }
gfx-backend-dx12 = { version = "0.5.6" }
gfx-backend-dx11 = { version = "0.5" }
gfx-backend-vulkan = { version = "0.5.7" }
gfx-backend-vulkan = { version = "0.5.8" }

[target.'cfg(any(target_os = "linux", target_os = "macos", target_os = "windows", target_os = "dragonfly", target_os = "freebsd"))'.dependencies]
battery = { version = "0.7", optional = true }
Expand Down
6 changes: 3 additions & 3 deletions wgpu-core/src/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1129,10 +1129,10 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
wgt::BindingType::SampledTexture { .. } => {
if !device
.extensions
.contains(wgt::Extensions::TEXTURE_BINDING_ARRAY)
.contains(wgt::Extensions::SAMPLED_TEXTURE_BINDING_ARRAY)
{
return Err(binding_model::BindGroupLayoutError::MissingExtension(
wgt::Extensions::TEXTURE_BINDING_ARRAY,
wgt::Extensions::SAMPLED_TEXTURE_BINDING_ARRAY,
));
}
}
Expand Down Expand Up @@ -1497,7 +1497,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}
}
binding_model::BindingResource::TextureViewArray(ref bindings_array) => {
assert!(device.extensions.contains(wgt::Extensions::TEXTURE_BINDING_ARRAY), "Extension TEXTURE_BINDING_ARRAY must be enabled to use TextureViewArrays in a bind group");
assert!(device.extensions.contains(wgt::Extensions::SAMPLED_TEXTURE_BINDING_ARRAY), "Extension SAMPLED_TEXTURE_BINDING_ARRAY must be enabled to use TextureViewArrays in a bind group");

if let Some(count) = decl.count {
assert_eq!(
Expand Down
59 changes: 38 additions & 21 deletions wgpu-core/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,21 @@ impl<B: hal::Backend> Adapter<B> {
adapter_features.contains(hal::Features::SAMPLER_ANISOTROPY),
);
extensions.set(
wgt::Extensions::TEXTURE_BINDING_ARRAY,
wgt::Extensions::SAMPLED_TEXTURE_BINDING_ARRAY,
adapter_features.contains(hal::Features::TEXTURE_DESCRIPTOR_ARRAY),
);
extensions.set(
wgt::Extensions::SAMPLED_TEXTURE_ARRAY_DYNAMIC_INDEXING,
adapter_features.contains(hal::Features::SHADER_SAMPLED_IMAGE_ARRAY_DYNAMIC_INDEXING),
);
extensions.set(
wgt::Extensions::SAMPLED_TEXTURE_ARRAY_NON_UNIFORM_INDEXING,
adapter_features.contains(hal::Features::SAMPLED_TEXTURE_DESCRIPTOR_INDEXING),
);
extensions.set(
wgt::Extensions::UNSIZED_BINDING_ARRAY,
adapter_features.contains(hal::Features::UNSIZED_DESCRIPTOR_ARRAY),
);
if unsafe_extensions.allowed() {
// Unsafe extensions go here
}
Expand Down Expand Up @@ -641,33 +653,38 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
);

// Check features needed by extensions
if desc
.extensions
.contains(wgt::Extensions::ANISOTROPIC_FILTERING)
{
assert!(
available_features.contains(hal::Features::SAMPLER_ANISOTROPY),
"Missing feature SAMPLER_ANISOTROPY for anisotropic filtering extension"
);
enabled_features |= hal::Features::SAMPLER_ANISOTROPY;
}
enabled_features.set(
hal::Features::SAMPLER_ANISOTROPY,
desc.extensions
.contains(wgt::Extensions::ANISOTROPIC_FILTERING),
);
if desc
.extensions
.contains(wgt::Extensions::MAPPABLE_PRIMARY_BUFFERS)
&& adapter.raw.info.device_type == hal::adapter::DeviceType::DiscreteGpu
{
log::warn!("Extension MAPPABLE_PRIMARY_BUFFERS enabled on a discrete gpu. This is a massive performance footgun and likely not what you wanted");
}
if desc
.extensions
.contains(wgt::Extensions::TEXTURE_BINDING_ARRAY)
{
assert!(
available_features.contains(hal::Features::TEXTURE_DESCRIPTOR_ARRAY),
"Missing feature TEXTURE_DESCRIPTOR_ARRAY for texture binding array extension"
);
enabled_features |= hal::Features::TEXTURE_DESCRIPTOR_ARRAY;
}
enabled_features.set(
hal::Features::TEXTURE_DESCRIPTOR_ARRAY,
desc.extensions
.contains(wgt::Extensions::SAMPLED_TEXTURE_BINDING_ARRAY),
);
enabled_features.set(
hal::Features::SHADER_SAMPLED_IMAGE_ARRAY_DYNAMIC_INDEXING,
desc.extensions
.contains(wgt::Extensions::SAMPLED_TEXTURE_ARRAY_DYNAMIC_INDEXING),
);
enabled_features.set(
hal::Features::SAMPLED_TEXTURE_DESCRIPTOR_INDEXING,
desc.extensions
.contains(wgt::Extensions::SAMPLED_TEXTURE_ARRAY_NON_UNIFORM_INDEXING),
);
enabled_features.set(
hal::Features::UNSIZED_DESCRIPTOR_ARRAY,
desc.extensions
.contains(wgt::Extensions::UNSIZED_BINDING_ARRAY),
);

let family = adapter
.raw
Expand Down
54 changes: 51 additions & 3 deletions wgpu-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ bitflags::bitflags! {
///
/// This is a native only extension.
const MAPPABLE_PRIMARY_BUFFERS = 0x0000_0000_0002_0000;
/// Allows the user to create uniform arrays of textures in shaders:
/// Allows the user to create uniform arrays of sampled textures in shaders:
///
/// eg. `uniform texture2D textures[10]`.
///
Expand All @@ -170,7 +170,55 @@ bitflags::bitflags! {
/// - Vulkan
///
/// This is a native only extension.
const TEXTURE_BINDING_ARRAY = 0x0000_0000_0004_0000;
const SAMPLED_TEXTURE_BINDING_ARRAY = 0x0000_0000_0004_0000;
/// Allows shaders to index sampled texture arrays with dynamically uniform values:
///
/// eg. `texture_array[uniform_value]`
///
/// This extension means the hardware will also support SAMPLED_TEXTURE_BINDING_ARRAY,
/// but it still must be requested to use it.
///
/// Supported platforms:
/// - DX12
/// - Metal (with MSL 2.0+ on macOS 10.13+)
/// - Vulkan (via feature shaderSampledImageArrayDynamicIndexing)
///
/// This is a native only extension.
const SAMPLED_TEXTURE_ARRAY_DYNAMIC_INDEXING = 0x0000_0000_0008_0000;
/// Allows shaders to index sampled texture arrays with dynamically non-uniform values:
///
/// eg. `texture_array[vertex_data]`
///
/// In order to use this extension, the corresponding GLSL extension must be enabled like so:
///
/// `#extension GL_EXT_nonuniform_qualifier : require`
///
/// HLSL does not need any extension.
///
/// This extension means the hardware will also support SAMPLED_TEXTURE_ARRAY_DYNAMIC_INDEXING
/// and SAMPLED_TEXTURE_BINDING_ARRAY, but they still must be requested to use them.
///
/// Supported platforms:
/// - DX12
/// - Metal (with MSL 2.0+ on macOS 10.13+)
/// - Vulkan 1.2+ (or via VK_EXT_descriptor_indexing)
///
/// This is a native only extension.
const SAMPLED_TEXTURE_ARRAY_NON_UNIFORM_INDEXING = 0x0000_0000_0010_0000;
/// Allows the user to create unsized uniform arrays of bindings:
///
/// eg. `uniform texture2D textures[]`.
///
/// This extension only allows them to exist and to be indexed by compile time constant
/// values. However if this extension exists, SAMPLED_TEXTURE_ARRAY_NON_UNIFORM_INDEXING is
/// _very_ likely to exist.
///
/// Supported platforms:
/// - DX12
/// - Vulkan 1.2+ (or via VK_EXT_descriptor_indexing)
///
/// This is a native only extension.
const UNSIZED_BINDING_ARRAY = 0x0000_0000_0020_0000;
/// Extensions which are part of the upstream webgpu standard
const ALL_WEBGPU = 0x0000_0000_0000_FFFF;
/// Extensions that require activating the unsafe extension flag
Expand Down Expand Up @@ -1258,7 +1306,7 @@ pub struct BindGroupLayoutEntry {
pub ty: BindingType,
/// If this value is Some, indicates this entry is an array. Array size must be 1 or greater.
///
/// If this value is Some and `ty` is `BindingType::SampledTexture`, the TEXTURE_BINDING_ARRAY extension must be enabled.
/// If this value is Some and `ty` is `BindingType::SampledTexture`, the SAMPLED_TEXTURE_BINDING_ARRAY extension must be enabled.
///
/// If this value is Some and `ty` is any other variant, bind group creation will fail.
pub count: Option<u32>,
Expand Down