Skip to content

Commit 18710fe

Browse files
jimblandykvark
authored andcommitted
Expand on the documentation for ray-tracing features.
1 parent 532d1ad commit 18710fe

File tree

4 files changed

+92
-8
lines changed

4 files changed

+92
-8
lines changed

src/back/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,14 @@ impl crate::Statement {
220220
}
221221

222222
bitflags::bitflags! {
223-
/// Ray flags.
223+
/// Ray flags, for a [`RayDesc`]'s `flags` field.
224+
///
225+
/// Note that these exactly correspond to the SPIR-V "Ray Flags" mask, and
226+
/// the SPIR-V backend passes them directly through to the
227+
/// `OpRayQueryInitializeKHR` instruction. (We have to choose something, so
228+
/// we might as well make one back end's life easier.)
229+
///
230+
/// [`RayDesc`]: crate::Module::generate_ray_desc_type
224231
#[derive(Default)]
225232
pub struct RayFlag: u32 {
226233
const OPAQUE = 0x01;

src/front/type_gen.rs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,21 @@ Type generators.
55
use crate::{arena::Handle, span::Span};
66

77
impl crate::Module {
8-
//Note: has to match `struct RayDesc`
8+
/// Populate this module's [`SpecialTypes::ray_desc`] type.
9+
///
10+
/// [`SpecialTypes::ray_desc`] is the type of the [`descriptor`] operand of
11+
/// an [`Initialize`] [`RayQuery`] statement. In WGSL, it is a struct type
12+
/// referred to as `RayDesc`.
13+
///
14+
/// Backends consume values of this type to drive platform APIs, so if you
15+
/// change any its fields, you must update the backends to match. Look for
16+
/// backend code dealing with [`RayQueryFunction::Initialize`].
17+
///
18+
/// [`SpecialTypes::ray_desc`]: crate::SpecialTypes::ray_desc
19+
/// [`descriptor`]: crate::RayQueryFunction::Initialize::descriptor
20+
/// [`Initialize`]: crate::RayQueryFunction::Initialize
21+
/// [`RayQuery`]: crate::Statement::RayQuery
22+
/// [`RayQueryFunction::Initialize`]: crate::RayQueryFunction::Initialize
923
pub(super) fn generate_ray_desc_type(&mut self) -> Handle<crate::Type> {
1024
if let Some(handle) = self.special_types.ray_desc {
1125
return handle;
@@ -96,7 +110,18 @@ impl crate::Module {
96110
handle
97111
}
98112

99-
//Note: has to match `struct RayIntersection`
113+
/// Populate this module's [`SpecialTypes::ray_intersection`] type.
114+
///
115+
/// [`SpecialTypes::ray_intersection`] is the type of a
116+
/// `RayQueryGetIntersection` expression. In WGSL, it is a struct type
117+
/// referred to as `RayIntersection`.
118+
///
119+
/// Backends construct values of this type based on platform APIs, so if you
120+
/// change any its fields, you must update the backends to match. Look for
121+
/// the backend's handling for [`Expression::RayQueryGetIntersection`].
122+
///
123+
/// [`SpecialTypes::ray_intersection`]: crate::SpecialTypes::ray_intersection
124+
/// [`Expression::RayQueryGetIntersection`]: crate::Expression::RayQueryGetIntersection
100125
pub(super) fn generate_ray_intersection_type(&mut self) -> Handle<crate::Type> {
101126
if let Some(handle) = self.special_types.ray_intersection {
102127
return handle;

src/lib.rs

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,10 @@ Naga's rules for when `Expression`s are evaluated are as follows:
107107
[`Atomic`] statement, representing the result of the atomic operation, is
108108
evaluated when the `Atomic` statement is executed.
109109
110-
- Similarly, an [`RayQueryProceedResult`] expression, which is a boolean
111-
indicating if the ray query is finished.
110+
- A [`RayQueryProceedResult`] expression, which is a boolean
111+
indicating if the ray query is finished, is evaluated when the
112+
[`RayQuery`] statement whose [`Proceed::result`] points to it is
113+
executed.
112114
113115
- All other expressions are evaluated when the (unique) [`Statement::Emit`]
114116
statement that covers them is executed.
@@ -184,6 +186,9 @@ tree.
184186
[`Call`]: Statement::Call
185187
[`Emit`]: Statement::Emit
186188
[`Store`]: Statement::Store
189+
[`RayQuery`]: Statement::RayQuery
190+
191+
[`Proceed::result`]: RayQueryFunction::Proceed::result
187192
188193
[`Validator::validate`]: valid::Validator::validate
189194
[`ModuleInfo`]: valid::ModuleInfo
@@ -727,6 +732,7 @@ pub enum TypeInner {
727732

728733
/// Opaque object representing an acceleration structure of geometry.
729734
AccelerationStructure,
735+
730736
/// Locally used handle for ray queries.
731737
RayQuery,
732738

@@ -1445,9 +1451,16 @@ pub enum Expression {
14451451
/// This doesn't match the semantics of spirv's `OpArrayLength`, which must be passed
14461452
/// a pointer to a structure containing a runtime array in its' last field.
14471453
ArrayLength(Handle<Expression>),
1448-
/// Result of `rayQueryProceed`.
1454+
1455+
/// Result of a [`Proceed`] [`RayQuery`] statement.
1456+
///
1457+
/// [`Proceed`]: RayQueryFunction::Proceed
1458+
/// [`RayQuery`]: Statement::RayQuery
14491459
RayQueryProceedResult,
1450-
/// Result of `rayQueryGet*Intersection`.
1460+
1461+
/// Return an intersection found by `query`.
1462+
///
1463+
/// If `committed` is true, return the committed result available when
14511464
RayQueryGetIntersection {
14521465
query: Handle<Expression>,
14531466
committed: bool,
@@ -1484,18 +1497,45 @@ pub struct SwitchCase {
14841497
pub fall_through: bool,
14851498
}
14861499

1500+
/// An operation that a [`RayQuery` statement] applies to its [`query`] operand.
1501+
///
1502+
/// [`RayQuery` statement]: Statement::RayQuery
1503+
/// [`query`]: Statement::RayQuery::query
14871504
#[derive(Clone, Debug)]
14881505
#[cfg_attr(feature = "serialize", derive(Serialize))]
14891506
#[cfg_attr(feature = "deserialize", derive(Deserialize))]
14901507
#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
14911508
pub enum RayQueryFunction {
1509+
/// Initialize the `RayQuery` object.
14921510
Initialize {
1511+
/// The acceleration structure within which this query should search for hits.
1512+
///
1513+
/// The expression must be an [`AccelerationStructure`].
1514+
///
1515+
/// [`AccelerationStructure`]: TypeInner::AccelerationStructure
14931516
acceleration_structure: Handle<Expression>,
1517+
1518+
#[allow(rustdoc::private_intra_doc_links)]
1519+
/// A struct of detailed parameters for the ray query.
1520+
///
1521+
/// This expression should have the struct type given in
1522+
/// [`SpecialTypes::ray_desc`]. This is available in the WGSL
1523+
/// front end as the `RayDesc` type.
14941524
descriptor: Handle<Expression>,
14951525
},
1526+
1527+
/// Start or continue the query given by the statement's [`query`] operand.
1528+
///
1529+
/// After executing this statement, the `result` expression is a
1530+
/// [`Bool`] scalar indicating whether there are more intersection
1531+
/// candidates to consider.
1532+
///
1533+
/// [`query`]: Statement::RayQuery::query
1534+
/// [`Bool`]: ScalarKind::Bool
14961535
Proceed {
14971536
result: Handle<Expression>,
14981537
},
1538+
14991539
Terminate,
15001540
}
15011541

@@ -1673,7 +1713,12 @@ pub enum Statement {
16731713
result: Option<Handle<Expression>>,
16741714
},
16751715
RayQuery {
1716+
/// The [`RayQuery`] object this statement operates on.
1717+
///
1718+
/// [`RayQuery`]: TypeInner::RayQuery
16761719
query: Handle<Expression>,
1720+
1721+
/// The specific operation we're performing on `query`.
16771722
fun: RayQueryFunction,
16781723
},
16791724
}
@@ -1800,8 +1845,15 @@ pub struct EntryPoint {
18001845
#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
18011846
pub struct SpecialTypes {
18021847
/// Type for `RayDesc`.
1848+
///
1849+
/// Call [`Module::generate_ray_desc_type`] to populate this if
1850+
/// needed and return the handle.
18031851
ray_desc: Option<Handle<Type>>,
1852+
18041853
/// Type for `RayIntersection`.
1854+
///
1855+
/// Call [`Module::generate_ray_intersection_type`] to populate
1856+
/// this if needed and return the handle.
18051857
ray_intersection: Option<Handle<Type>>,
18061858
}
18071859

src/valid/handles.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Implementation of [`super::Validator::validate_module_handles`].
1+
//! Implementation of `Validator::validate_module_handles`.
22
33
use crate::{
44
arena::{BadHandle, BadRangeError},

0 commit comments

Comments
 (0)