Skip to content

Commit a116861

Browse files
authored
Prevent resources for acceleration structures being created if they are not enabled (#8036)
* Prevent resources for acceleration structures being created if acceleration structures aren't supported.
1 parent 4938f86 commit a116861

File tree

4 files changed

+74
-2
lines changed

4 files changed

+74
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ By @Vecvec in [#7913](https://github.com/gfx-rs/wgpu/pull/7913).
5555

5656
### Changes
5757

58+
#### General
59+
60+
- Prevent resources for acceleration structures being created if acceleration structures are not enabled. By @Vecvec in [#8036](https://github.com/gfx-rs/wgpu/pull/8036).
61+
5862
#### Naga
5963

6064
Naga now requires that no type be larger than 1 GB. This limit may be lowered in the future; feedback on an appropriate value for the limit is welcome. By @andyleiserson in [#7950](https://github.com/gfx-rs/wgpu/pull/7950).

tests/tests/wgpu-gpu/ray_tracing/as_create.rs

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ use wgpu_macros::gpu_test;
99
use wgpu_test::{fail, GpuTestConfiguration, TestParameters, TestingContext};
1010

1111
pub fn all_tests(tests: &mut Vec<wgpu_test::GpuTestInitializer>) {
12-
tests.extend([BLAS_INVALID_VERTEX_FORMAT, BLAS_MISMATCHED_INDEX]);
12+
tests.extend([
13+
BLAS_INVALID_VERTEX_FORMAT,
14+
BLAS_MISMATCHED_INDEX,
15+
UNSUPPORTED_ACCELERATION_STRUCTURE_RESOURCES,
16+
]);
1317
}
1418

1519
#[gpu_test]
@@ -124,3 +128,42 @@ fn mismatched_index_blas_create(ctx: TestingContext) {
124128
None,
125129
);
126130
}
131+
132+
#[gpu_test]
133+
static UNSUPPORTED_ACCELERATION_STRUCTURE_RESOURCES: GpuTestConfiguration =
134+
GpuTestConfiguration::new()
135+
.parameters(TestParameters::default().test_features_limits())
136+
.run_sync(unsupported_acceleration_structure_resources);
137+
138+
fn unsupported_acceleration_structure_resources(ctx: TestingContext) {
139+
fail(
140+
&ctx.device,
141+
|| {
142+
ctx.device.create_buffer(&wgpu::BufferDescriptor {
143+
label: None,
144+
size: 4,
145+
usage: wgpu::BufferUsages::BLAS_INPUT,
146+
mapped_at_creation: false,
147+
})
148+
},
149+
None,
150+
);
151+
fail(
152+
&ctx.device,
153+
|| {
154+
ctx.device
155+
.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
156+
label: None,
157+
entries: &[wgpu::BindGroupLayoutEntry {
158+
binding: 0,
159+
visibility: wgpu::ShaderStages::COMPUTE,
160+
ty: wgpu::BindingType::AccelerationStructure {
161+
vertex_return: false,
162+
},
163+
count: None,
164+
}],
165+
})
166+
},
167+
None,
168+
);
169+
}

wgpu-core/src/device/resource.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,13 @@ impl Device {
795795
});
796796
}
797797

798+
if desc
799+
.usage
800+
.intersects(wgt::BufferUsages::BLAS_INPUT | wgt::BufferUsages::TLAS_INPUT)
801+
{
802+
self.require_features(wgt::Features::EXPERIMENTAL_RAY_QUERY)?;
803+
}
804+
798805
if desc.usage.contains(wgt::BufferUsages::INDEX)
799806
&& desc.usage.contains(
800807
wgt::BufferUsages::VERTEX
@@ -2303,7 +2310,22 @@ impl Device {
23032310
},
23042311
)
23052312
}
2306-
Bt::AccelerationStructure { .. } => (None, WritableStorage::No),
2313+
Bt::AccelerationStructure { vertex_return } => {
2314+
self.require_features(wgt::Features::EXPERIMENTAL_RAY_QUERY)
2315+
.map_err(|e| binding_model::CreateBindGroupLayoutError::Entry {
2316+
binding: entry.binding,
2317+
error: e.into(),
2318+
})?;
2319+
if vertex_return {
2320+
self.require_features(wgt::Features::EXPERIMENTAL_RAY_HIT_VERTEX_RETURN)
2321+
.map_err(|e| binding_model::CreateBindGroupLayoutError::Entry {
2322+
binding: entry.binding,
2323+
error: e.into(),
2324+
})?;
2325+
}
2326+
2327+
(None, WritableStorage::No)
2328+
}
23072329
Bt::ExternalTexture => {
23082330
self.require_features(wgt::Features::EXTERNAL_TEXTURE)
23092331
.map_err(|e| binding_model::CreateBindGroupLayoutError::Entry {

wgpu-core/src/resource.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,8 @@ pub enum CreateBufferError {
912912
MaxBufferSize { requested: u64, maximum: u64 },
913913
#[error(transparent)]
914914
MissingDownlevelFlags(#[from] MissingDownlevelFlags),
915+
#[error(transparent)]
916+
MissingFeatures(#[from] MissingFeatures),
915917
#[error("Failed to create bind group for indirect buffer validation: {0}")]
916918
IndirectValidationBindGroup(DeviceError),
917919
}
@@ -929,6 +931,7 @@ impl WebGpuError for CreateBufferError {
929931
Self::AccessError(e) => e,
930932
Self::MissingDownlevelFlags(e) => e,
931933
Self::IndirectValidationBindGroup(e) => e,
934+
Self::MissingFeatures(e) => e,
932935

933936
Self::UnalignedSize
934937
| Self::InvalidUsage(_)

0 commit comments

Comments
 (0)