[wgpu-core] validate BGL entry visibility for non-core features (#10042)

(cherry picked from commit 422b1c3a2c)
This commit is contained in:
Teodor Tanasoaia authored and Andy Leiserson committed 2026-08-14 14:34:21 -07:00
1 parent 265becdf84
commit 85d3266078
5 files changed
+102

No files matched your search

+2
View File
@@ -95,6 +95,8 @@ Bottom level categories:
- Validate that the arguments are within the indirect buffer when encoding an indirect draw to a render bundle. Moves some indirect draw errors from `RenderPassErrorInner` to `RenderCommandError`. By @andyleiserson in [#9871](https://github.com/gfx-rs/wgpu/pull/9871).
- When creating render pipelines, validate that a corresponding shader output is present for each color attachment with non-zero write mask, and that shader output includes alpha when the blend operation uses source alpha. By @andyleiserson in [#9939](https://github.com/gfx-rs/wgpu/pull/9939).
- Reject bind group layout entries with `TASK` or `MESH` visibility unless `Features::EXPERIMENTAL_MESH_SHADER` is enabled. By @teoxoy in [#10042](https://github.com/gfx-rs/wgpu/issues/10042).
- Reject bind group layout entries with `RAY_GENERATION`, `ANY_HIT`, `CLOSEST_HIT`, or `MISS` visibility unless `Features::EXPERIMENTAL_RAY_TRACING_PIPELINES` is enabled. By @teoxoy in [#10042](https://github.com/gfx-rs/wgpu/issues/10042).
#### Naga
@@ -0,0 +1,36 @@
use wgpu::*;
use wgpu_test::fail;
fn check_visibility_requires_mesh_shader_feature(visibility: ShaderStages) {
let (device, _queue) = wgpu::Device::noop(&DeviceDescriptor::default());
fail(
&device,
|| {
device.create_bind_group_layout(&BindGroupLayoutDescriptor {
label: Some("mesh shader visibility"),
entries: &[BindGroupLayoutEntry {
binding: 0,
visibility,
ty: BindingType::Buffer {
ty: BufferBindingType::Storage { read_only: true },
has_dynamic_offset: false,
min_binding_size: None,
},
count: None,
}],
})
},
Some("EXPERIMENTAL_MESH_SHADER"),
);
}
#[test]
fn task_visibility_requires_mesh_shader_feature() {
check_visibility_requires_mesh_shader_feature(ShaderStages::TASK);
}
#[test]
fn mesh_visibility_requires_mesh_shader_feature() {
check_visibility_requires_mesh_shader_feature(ShaderStages::MESH);
}
+2
View File
@@ -10,5 +10,7 @@ mod experimental;
mod external_texture;
mod immediates;
mod instance;
mod mesh_shader;
mod ray_tracing_pipeline;
mod render_pipeline;
mod texture;
@@ -0,0 +1,46 @@
use wgpu::*;
use wgpu_test::fail;
fn check_visibility_requires_ray_tracing_pipelines_feature(visibility: ShaderStages) {
let (device, _queue) = wgpu::Device::noop(&DeviceDescriptor::default());
fail(
&device,
|| {
device.create_bind_group_layout(&BindGroupLayoutDescriptor {
label: Some("ray tracing pipeline visibility"),
entries: &[BindGroupLayoutEntry {
binding: 0,
visibility,
ty: BindingType::Buffer {
ty: BufferBindingType::Storage { read_only: true },
has_dynamic_offset: false,
min_binding_size: None,
},
count: None,
}],
})
},
Some("EXPERIMENTAL_RAY_TRACING_PIPELINES"),
);
}
#[test]
fn ray_generation_visibility_requires_ray_tracing_pipelines_feature() {
check_visibility_requires_ray_tracing_pipelines_feature(ShaderStages::RAY_GENERATION);
}
#[test]
fn any_hit_visibility_requires_ray_tracing_pipelines_feature() {
check_visibility_requires_ray_tracing_pipelines_feature(ShaderStages::ANY_HIT);
}
#[test]
fn closest_hit_visibility_requires_ray_tracing_pipelines_feature() {
check_visibility_requires_ray_tracing_pipelines_feature(ShaderStages::CLOSEST_HIT);
}
#[test]
fn miss_visibility_requires_ray_tracing_pipelines_feature() {
check_visibility_requires_ray_tracing_pipelines_feature(ShaderStages::MISS);
}
+16
View File
@@ -3095,6 +3095,22 @@ impl Device {
));
}
if entry
.visibility
.intersects(wgt::ShaderStages::TASK | wgt::ShaderStages::MESH)
{
required_features |= wgt::Features::EXPERIMENTAL_MESH_SHADER;
}
if entry.visibility.intersects(
wgt::ShaderStages::RAY_GENERATION
| wgt::ShaderStages::ANY_HIT
| wgt::ShaderStages::CLOSEST_HIT
| wgt::ShaderStages::MISS,
) {
required_features |= wgt::Features::EXPERIMENTAL_RAY_TRACING_PIPELINES;
}
if entry.visibility.contains(wgt::ShaderStages::VERTEX) {
if writable_storage == WritableStorage::Yes {
required_features |= wgt::Features::VERTEX_WRITABLE_STORAGE;