Skip to content

Commit

Permalink
when creating and building acceleration structures require Features::…
Browse files Browse the repository at this point in the history
…RAY_TRACING_ACCELERATION_STRUCTURE is enabled
  • Loading branch information
Vecvec committed Sep 20, 2024
1 parent cb167a4 commit e2168e6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
16 changes: 15 additions & 1 deletion wgpu-core/src/command/ray_tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
FastHashSet,
};

use wgt::{math::align_to, BufferAddress, BufferUsages};
use wgt::{math::align_to, BufferAddress, BufferUsages, Features};

use super::{BakedCommands, CommandBufferMutable};
use crate::ray_tracing::BlasTriangleGeometry;
Expand Down Expand Up @@ -67,6 +67,13 @@ impl Global {

let device = &cmd_buf.device;

if !device
.features
.contains(Features::RAY_TRACING_ACCELERATION_STRUCTURE)
{
return Err(BuildAccelerationStructureError::MissingFeature);
}

let build_command_index = NonZeroU64::new(
device
.last_acceleration_structure_build_command_index
Expand Down Expand Up @@ -343,6 +350,13 @@ impl Global {

let device = &cmd_buf.device;

if !device
.features
.contains(Features::RAY_TRACING_ACCELERATION_STRUCTURE)
{
return Err(BuildAccelerationStructureError::MissingFeature);
}

let build_command_index = NonZeroU64::new(
device
.last_acceleration_structure_build_command_index
Expand Down
19 changes: 17 additions & 2 deletions wgpu-core/src/device/ray_tracing.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use std::mem::ManuallyDrop;
use std::sync::Arc;

use hal::AccelerationStructureTriangleIndices;

#[cfg(feature = "trace")]
use crate::device::trace;
use crate::lock::rank;
Expand All @@ -15,6 +13,8 @@ use crate::{
ray_tracing::{get_raw_tlas_instance_size, CreateBlasError, CreateTlasError},
resource, LabelHelpers,
};
use hal::AccelerationStructureTriangleIndices;
use wgt::Features;

impl Device {
fn create_blas(
Expand Down Expand Up @@ -182,6 +182,13 @@ impl Global {
Err(err) => break 'error CreateBlasError::Device(err),
};

if !device
.features
.contains(Features::RAY_TRACING_ACCELERATION_STRUCTURE)
{
break 'error CreateBlasError::MissingFeature;
}

#[cfg(feature = "trace")]
if let Some(trace) = device.trace.lock().as_mut() {
trace.add(trace::Action::CreateBlas {
Expand Down Expand Up @@ -225,6 +232,14 @@ impl Global {
Ok(_) => {}
Err(e) => break 'error CreateTlasError::Device(e),
}

if !device
.features
.contains(Features::RAY_TRACING_ACCELERATION_STRUCTURE)
{
break 'error CreateTlasError::MissingFeature;
}

#[cfg(feature = "trace")]
if let Some(trace) = device.trace.lock().as_mut() {
trace.add(trace::Action::CreateTlas {
Expand Down
7 changes: 7 additions & 0 deletions wgpu-core/src/ray_tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ pub enum CreateBlasError {
MissingIndexData,
#[error("Provided format was not within allowed formats. Provided format: {0:?}. Allowed formats: {1:?}")]
InvalidVertexFormat(VertexFormat, Vec<VertexFormat>),
#[error("Features::RAY_TRACING_ACCELERATION_STRUCTURE is not enabled")]
MissingFeature,
}

#[derive(Clone, Debug, Error)]
Expand All @@ -39,6 +41,8 @@ pub enum CreateTlasError {
Device(#[from] DeviceError),
#[error(transparent)]
CreateBufferError(#[from] CreateBufferError),
#[error("Features::RAY_TRACING_ACCELERATION_STRUCTURE is not enabled")]
MissingFeature,
#[error("Unimplemented Tlas error: this error is not yet implemented")]
Unimplemented,
}
Expand Down Expand Up @@ -136,6 +140,9 @@ pub enum BuildAccelerationStructureError {
#[error("Tlas {0:?} is invalid or destroyed")]
InvalidTlas(ResourceErrorIdent),

#[error("Features::RAY_TRACING_ACCELERATION_STRUCTURE is not enabled")]
MissingFeature,

#[error("Buffer {0:?} is missing `TLAS_INPUT` usage flag")]
MissingTlasInputUsageFlag(ResourceErrorIdent),
}
Expand Down

0 comments on commit e2168e6

Please sign in to comment.