Skip to content
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

Rename instance_id & instance_custom_index to instance_index & instance_custom_data #6780

Open
wants to merge 25 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f862239
add test
Vecvec Dec 15, 2024
9c4b6cd
format
Vecvec Dec 15, 2024
d726398
move ray query get intersection to its own function
Vecvec Dec 15, 2024
c1db49b
regen snapshots
Vecvec Dec 16, 2024
a1f821b
remove old (and now unused) function
Vecvec Dec 16, 2024
7430bae
Merge branch 'trunk' into remove-rt-undefined-behavior
Vecvec Dec 16, 2024
ffb73fe
changelog
Vecvec Dec 16, 2024
e366e3c
Merge remote-tracking branch 'origin/remove-rt-undefined-behavior' in…
Vecvec Dec 16, 2024
b28b7fb
Merge remote-tracking branch 'refs/remotes/gfx-rs/trunk' into remove-…
Vecvec Dec 17, 2024
37260ca
format
Vecvec Dec 17, 2024
cc97ba7
Merge branch 'trunk' into remove-rt-undefined-behavior
Vecvec Dec 17, 2024
cb48e2c
Merge branch 'trunk' into remove-rt-undefined-behavior
Vecvec Dec 17, 2024
7251a36
Make what block ray t is in dependent on whether it is committed or c…
Vecvec Dec 18, 2024
c4fd478
regen snapshots
Vecvec Dec 18, 2024
7ff13b9
rename
Vecvec Dec 18, 2024
4f3e5a7
Merge remote-tracking branch 'refs/remotes/gfx-rs/trunk' into rename-…
Vecvec Dec 18, 2024
b3a555d
regen snapshots & fmt
Vecvec Dec 18, 2024
d75ff23
Merge branch 'trunk' into rename-rt-instance-id
Vecvec Dec 19, 2024
f399bb0
Merge branch 'trunk' into rename-rt-instance-id
Vecvec Dec 20, 2024
bbaf2ea
Merge remote-tracking branch 'trunk/trunk' into rename-rt-instance-id
Vecvec Jan 17, 2025
9fe03d6
Rename dx12 name.
Vecvec Jan 17, 2025
87542a6
Fix snapshots.
Vecvec Jan 17, 2025
ca1113a
Fix hlsl validation.
Vecvec Jan 17, 2025
2fee018
Changelog.
Vecvec Jan 17, 2025
5df2025
Merge remote-tracking branch 'trunk/trunk' into rename-rt-instance-id
Vecvec Jan 25, 2025
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ Use `hashbrown` in `wgpu-core`, `wgpu-hal` & `wgpu-info` to simplify no-std supp

By @brodycj in [#6925](https://github.com/gfx-rs/wgpu/pull/6925).

- Rename `instance_id` and `instance_custom_index` to `instance_index` and `instance_custom_data` by @Vecvec in
[#6780](https://github.com/gfx-rs/wgpu/pull/6780)

#### Vulkan

##### HAL queue callback support
Expand Down
6 changes: 3 additions & 3 deletions etc/specs/ray_tracing.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ struct RayIntersection {
kind: u32,
// Distance from starting point, measured in units of `RayDesc::dir`.
t: f32,
// Corresponds to `instance.custom_index` where `instance` is the `TlasInstance`
// Corresponds to `instance.custom_data` where `instance` is the `TlasInstance`
// that the intersected object was contained in.
instance_custom_index: u32,
instance_custom_data: u32,
// The index into the `TlasPackage` to get the `TlasInstance` that the hit object is in
instance_id: u32,
instance_index: u32,
// The offset into the shader binding table. Currently, this value is always 0.
sbt_record_offset: u32,
// The index into the `Blas`'s build descriptor (e.g. if `BlasBuildEntry::geometry` is
Expand Down
4 changes: 2 additions & 2 deletions examples/features/src/ray_cube_compute/shader.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ struct RayDesc {
struct RayIntersection {
kind: u32,
t: f32,
instance_custom_index: u32,
instance_id: u32,
instance_custom_data: u32,
instance_index: u32,
sbt_record_offset: u32,
geometry_index: u32,
primitive_index: u32,
Expand Down
8 changes: 4 additions & 4 deletions examples/features/src/ray_scene/shader.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ struct RayDesc {
struct RayIntersection {
kind: u32,
t: f32,
instance_custom_index: u32,
instance_id: u32,
instance_custom_data: u32,
instance_index: u32,
sbt_record_offset: u32,
geometry_index: u32,
primitive_index: u32,
Expand Down Expand Up @@ -131,7 +131,7 @@ fn fs_main(vertex: VertexOutput) -> @location(0) vec4<f32> {

let intersection = rayQueryGetCommittedIntersection(&rq);
if (intersection.kind != RAY_QUERY_INTERSECTION_NONE) {
let instance = instances[intersection.instance_custom_index];
let instance = instances[intersection.instance_custom_data];
let geometry = geometries[intersection.geometry_index + instance.first_geometry];

let index_offset = geometry.first_index;
Expand All @@ -155,7 +155,7 @@ fn fs_main(vertex: VertexOutput) -> @location(0) vec4<f32> {

color = vec4<f32>(material.albedo, 1.0);

if(intersection.instance_custom_index == 1u){
if(intersection.instance_custom_data == 1u){
color = vec4<f32>(normal, 1.0);
}
}
Expand Down
8 changes: 4 additions & 4 deletions naga/src/back/hlsl/ray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ impl<W: Write> super::Writer<'_, W> {
writeln!(self.out, " ret.t = rq.CommittedRayT();")?;
writeln!(
self.out,
" ret.instance_custom_index = rq.CommittedInstanceID();"
" ret.instance_custom_data = rq.CommittedInstanceID();"
)?;
writeln!(
self.out,
" ret.instance_id = rq.CommittedInstanceIndex();"
" ret.instance_index = rq.CommittedInstanceIndex();"
)?;
writeln!(
self.out,
Expand Down Expand Up @@ -129,11 +129,11 @@ impl<W: Write> super::Writer<'_, W> {

writeln!(
self.out,
" ret.instance_custom_index = rq.CandidateInstanceID();"
" ret.instance_custom_data = rq.CandidateInstanceID();"
)?;
writeln!(
self.out,
" ret.instance_id = rq.CandidateInstanceIndex();"
" ret.instance_index = rq.CandidateInstanceIndex();"
)?;
writeln!(
self.out,
Expand Down
4 changes: 2 additions & 2 deletions naga/src/front/type_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,13 @@ impl crate::Module {
offset: 4,
},
crate::StructMember {
name: Some("instance_custom_index".to_string()),
name: Some("instance_custom_data".to_string()),
ty: ty_flag,
binding: None,
offset: 8,
},
crate::StructMember {
name: Some("instance_id".to_string()),
name: Some("instance_index".to_string()),
ty: ty_flag,
binding: None,
offset: 12,
Expand Down
4 changes: 2 additions & 2 deletions naga/tests/in/ray-query.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ struct RayDesc {
struct RayIntersection {
kind: u32,
t: f32,
instance_custom_index: u32,
instance_id: u32,
instance_custom_data: u32,
instance_index: u32,
sbt_record_offset: u32,
geometry_index: u32,
primitive_index: u32,
Expand Down
12 changes: 6 additions & 6 deletions naga/tests/out/hlsl/ray-query.hlsl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
struct RayIntersection {
uint kind;
float t;
uint instance_custom_index;
uint instance_id;
uint instance_custom_data;
uint instance_index;
uint sbt_record_offset;
uint geometry_index;
uint primitive_index;
Expand Down Expand Up @@ -64,8 +64,8 @@ RayIntersection GetCommittedIntersection(RayQuery<RAY_FLAG_NONE> rq) {
ret.kind = rq.CommittedStatus();
if( rq.CommittedStatus() == COMMITTED_NOTHING) {} else {
ret.t = rq.CommittedRayT();
ret.instance_custom_index = rq.CommittedInstanceID();
ret.instance_id = rq.CommittedInstanceIndex();
ret.instance_custom_data = rq.CommittedInstanceID();
ret.instance_index = rq.CommittedInstanceIndex();
ret.sbt_record_offset = rq.CommittedInstanceContributionToHitGroupIndex();
ret.geometry_index = rq.CommittedGeometryIndex();
ret.primitive_index = rq.CommittedPrimitiveIndex();
Expand Down Expand Up @@ -128,8 +128,8 @@ RayIntersection GetCandidateIntersection(RayQuery<RAY_FLAG_NONE> rq) {
} else {
ret.kind = 3;
}
ret.instance_custom_index = rq.CandidateInstanceID();
ret.instance_id = rq.CandidateInstanceIndex();
ret.instance_custom_data = rq.CandidateInstanceID();
ret.instance_index = rq.CandidateInstanceIndex();
ret.sbt_record_offset = rq.CandidateInstanceContributionToHitGroupIndex();
ret.geometry_index = rq.CandidateGeometryIndex();
ret.primitive_index = rq.CandidatePrimitiveIndex();
Expand Down
4 changes: 2 additions & 2 deletions naga/tests/out/msl/ray-query.msl
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ constexpr metal::uint _map_intersection_type(const metal::raytracing::intersecti
struct RayIntersection {
uint kind;
float t;
uint instance_custom_index;
uint instance_id;
uint instance_custom_data;
uint instance_index;
uint sbt_record_offset;
uint geometry_index;
uint primitive_index;
Expand Down
2 changes: 1 addition & 1 deletion player/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ impl GlobalPlay for wgc::global::Global {
.map(|instance| wgc::ray_tracing::TlasInstance {
blas_id: instance.blas_id,
transform: &instance.transform,
custom_index: instance.custom_index,
custom_data: instance.custom_data,
mask: instance.mask,
})
});
Expand Down
8 changes: 4 additions & 4 deletions tests/tests/ray_tracing/shader.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ var acc_struct: acceleration_structure;
struct Intersection {
kind: u32,
t: f32,
instance_custom_index: u32,
instance_id: u32,
instance_custom_data: u32,
instance_index: u32,
sbt_record_offset: u32,
geometry_index: u32,
primitive_index: u32,
Expand Down Expand Up @@ -38,8 +38,8 @@ fn all_of_struct() {
out = Intersection(
intersection.kind,
intersection.t,
intersection.instance_custom_index,
intersection.instance_id,
intersection.instance_custom_data,
intersection.instance_index,
intersection.sbt_record_offset,
intersection.geometry_index,
intersection.primitive_index,
Expand Down
8 changes: 4 additions & 4 deletions wgpu-core/src/command/ray_tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ impl Global {
instance.map(|instance| TraceTlasInstance {
blas_id: instance.blas_id,
transform: *instance.transform,
custom_index: instance.custom_index,
custom_data: instance.custom_data,
mask: instance.mask,
})
})
Expand Down Expand Up @@ -444,7 +444,7 @@ impl Global {
instance.as_ref().map(|instance| TlasInstance {
blas_id: instance.blas_id,
transform: &instance.transform,
custom_index: instance.custom_index,
custom_data: instance.custom_data,
mask: instance.mask,
})
});
Expand Down Expand Up @@ -512,7 +512,7 @@ impl Global {

let mut instance_count = 0;
for instance in package.instances.flatten() {
if instance.custom_index >= (1u32 << 24u32) {
if instance.custom_data >= (1u32 << 24u32) {
return Err(BuildAccelerationStructureError::TlasInvalidCustomIndex(
tlas.error_ident(),
));
Expand All @@ -524,7 +524,7 @@ impl Global {
instance_buffer_staging_source.extend(device.raw().tlas_instance_to_bytes(
hal::TlasInstance {
transform: *instance.transform,
custom_index: instance.custom_index,
custom_data: instance.custom_data,
mask: instance.mask,
blas_address: blas.handle,
},
Expand Down
4 changes: 2 additions & 2 deletions wgpu-core/src/ray_tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ pub struct TlasBuildEntry {
pub struct TlasInstance<'a> {
pub blas_id: BlasId,
pub transform: &'a [f32; 12],
pub custom_index: u32,
pub custom_data: u32,
pub mask: u8,
}

Expand Down Expand Up @@ -243,7 +243,7 @@ pub struct TraceBlasBuildEntry {
pub struct TraceTlasInstance {
pub blas_id: BlasId,
pub transform: [f32; 12],
pub custom_index: u32,
pub custom_data: u32,
pub mask: u8,
}

Expand Down
2 changes: 1 addition & 1 deletion wgpu-hal/examples/ray-traced-triangle/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl std::fmt::Debug for AccelerationStructureInstance {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Instance")
.field("transform", &self.transform)
.field("custom_index()", &self.custom_index())
.field("custom_data()", &self.custom_index())
.field("mask()", &self.mask())
.field(
"shader_binding_table_record_offset()",
Expand Down
2 changes: 1 addition & 1 deletion wgpu-hal/src/dx12/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2312,7 +2312,7 @@ impl crate::Device for super::Device {
const MAX_U24: u32 = (1u32 << 24u32) - 1u32;
let temp = Direct3D12::D3D12_RAYTRACING_INSTANCE_DESC {
Transform: instance.transform,
_bitfield1: (instance.custom_index & MAX_U24) | (u32::from(instance.mask) << 24),
_bitfield1: (instance.custom_data & MAX_U24) | (u32::from(instance.mask) << 24),
_bitfield2: 0,
AccelerationStructure: instance.blas_address,
};
Expand Down
2 changes: 1 addition & 1 deletion wgpu-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2444,7 +2444,7 @@ pub struct AccelerationStructureBarrier {
#[derive(Debug, Copy, Clone)]
pub struct TlasInstance {
pub transform: [f32; 12],
pub custom_index: u32,
pub custom_data: u32,
pub mask: u8,
pub blas_address: u64,
}
2 changes: 1 addition & 1 deletion wgpu-hal/src/vulkan/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2569,7 +2569,7 @@ impl crate::Device for super::Device {
const MAX_U24: u32 = (1u32 << 24u32) - 1u32;
let temp = RawTlasInstance {
transform: instance.transform,
custom_index_and_mask: (instance.custom_index & MAX_U24)
custom_data_and_mask: (instance.custom_data & MAX_U24)
| (u32::from(instance.mask) << 24),
shader_binding_table_record_offset_and_flags: 0,
acceleration_structure_reference: instance.blas_address,
Expand Down
2 changes: 1 addition & 1 deletion wgpu-hal/src/vulkan/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1482,7 +1482,7 @@ fn get_lost_err() -> crate::DeviceError {
#[repr(C)]
struct RawTlasInstance {
transform: [f32; 12],
custom_index_and_mask: u32,
custom_data_and_mask: u32,
shader_binding_table_record_offset_and_flags: u32,
acceleration_structure_reference: u64,
}
8 changes: 4 additions & 4 deletions wgpu/src/api/blas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub struct TlasInstance {
///
/// This must only use the lower 24 bits, if any bits are outside that range (byte 4 does not equal 0) the TlasInstance becomes
/// invalid and generates a validation error when built
pub custom_index: u32,
pub custom_data: u32,
/// Mask for the instance used inside the shader to filter instances.
/// Reports hit only if `(shader_cull_mask & tlas_instance.mask) != 0u`.
pub mask: u8,
Expand All @@ -59,19 +59,19 @@ impl TlasInstance {
/// Construct TlasInstance.
/// - blas: Reference to the bottom level acceleration structure
/// - transform: Transform buffer offset in bytes (optional, required if transform buffer is present)
/// - custom_index: Custom index for the instance used inside the shader (max 24 bits)
/// - custom_data: Custom index for the instance used inside the shader (max 24 bits)
/// - mask: Mask for the instance used inside the shader to filter instances
///
/// Note: while one of these contains a reference to a BLAS that BLAS will not be dropped,
/// but it can still be destroyed. Destroying a BLAS that is referenced by one or more
/// TlasInstance(s) will immediately make them invalid. If one or more of those invalid
/// TlasInstances is inside a TlasPackage that is attempted to be built, the build will
/// generate a validation error.
pub fn new(blas: &Blas, transform: [f32; 12], custom_index: u32, mask: u8) -> Self {
pub fn new(blas: &Blas, transform: [f32; 12], custom_data: u32, mask: u8) -> Self {
Self {
blas: blas.inner.clone(),
transform,
custom_index,
custom_data,
mask,
}
}
Expand Down
2 changes: 1 addition & 1 deletion wgpu/src/backend/wgpu_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2522,7 +2522,7 @@ impl dispatch::CommandEncoderInterface for CoreCommandEncoder {
.map(|instance| wgc::ray_tracing::TlasInstance {
blas_id: instance.blas.as_core().id,
transform: &instance.transform,
custom_index: instance.custom_index,
custom_data: instance.custom_data,
mask: instance.mask,
})
});
Expand Down
Loading