Add ray query statements to the IR

This commit is contained in:
Dzmitry Malyshau 2023-02-13 21:12:06 -08:00
parent 432b4990a7
commit e46c53d212
13 changed files with 99 additions and 2 deletions

View File

@ -252,6 +252,22 @@ impl StatementGraph {
}
"Atomic"
}
S::RayQuery { query, ref fun } => {
self.dependencies.push((id, query, "query"));
if let crate::RayQueryFunction::Initialize {
acceleration_structure,
descriptor,
} = *fun
{
self.dependencies.push((
id,
acceleration_structure,
"acceleration_structure",
));
self.dependencies.push((id, descriptor, "descriptor"));
}
"RayQuery"
}
};
// Set the last node to the merge node
last_node = merge_id;

View File

@ -2197,6 +2197,7 @@ impl<'a, W: Write> Writer<'a, W> {
self.write_expr(value, ctx)?;
writeln!(self.out, ");")?;
}
Statement::RayQuery { .. } => unreachable!(),
}
Ok(())

View File

@ -1980,6 +1980,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
writeln!(self.out, "{level}}}")?
}
Statement::RayQuery { .. } => unreachable!(),
}
Ok(())

View File

@ -2759,6 +2759,7 @@ impl<W: Write> Writer<W> {
// done
writeln!(self.out, ";")?;
}
crate::Statement::RayQuery { .. } => unreachable!(),
}
}

View File

@ -2196,6 +2196,17 @@ impl<'w> BlockContext<'w> {
block.body.push(instruction);
}
crate::Statement::RayQuery { query, ref fun } => {
let query_id = self.cached[query];
match *fun {
crate::RayQueryFunction::Initialize {
acceleration_structure,
descriptor,
} => {}
crate::RayQueryFunction::Proceed => {}
crate::RayQueryFunction::Terminate => {}
}
}
}
}

View File

@ -937,6 +937,7 @@ impl<W: Write> Writer<W> {
writeln!(self.out, "{level}workgroupBarrier();")?;
}
}
Statement::RayQuery { .. } => unreachable!(),
}
Ok(())

View File

@ -3672,7 +3672,8 @@ impl<I: Iterator<Item = u32>> Frontend<I> {
| S::Barrier(_)
| S::Store { .. }
| S::ImageStore { .. }
| S::Atomic { .. } => {}
| S::Atomic { .. }
| S::RayQuery { .. } => {}
S::Call {
function: ref mut callee,
ref arguments,

View File

@ -1473,6 +1473,19 @@ pub struct SwitchCase {
pub fall_through: bool,
}
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serialize", derive(Serialize))]
#[cfg_attr(feature = "deserialize", derive(Deserialize))]
#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
pub enum RayQueryFunction {
Initialize {
acceleration_structure: Handle<Expression>,
descriptor: Handle<Expression>,
},
Proceed,
Terminate,
}
//TODO: consider removing `Clone`. It's not valid to clone `Statement::Emit` anyway.
/// Instructions which make up an executable block.
// Clone is used only for error reporting and is not intended for end users
@ -1646,6 +1659,10 @@ pub enum Statement {
arguments: Vec<Handle<Expression>>,
result: Option<Handle<Expression>>,
},
RayQuery {
query: Handle<Expression>,
fun: RayQueryFunction,
},
}
/// A function argument.

View File

@ -34,6 +34,7 @@ pub fn ensure_block_returns(block: &mut crate::Block) {
| S::Store { .. }
| S::ImageStore { .. }
| S::Call { .. }
| S::RayQuery { .. }
| S::Atomic { .. }
| S::Barrier(_)),
)

View File

@ -893,6 +893,18 @@ impl FunctionInfo {
}
FunctionUniformity::new()
}
S::RayQuery { query, ref fun } => {
let _ = self.add_ref(query);
if let crate::RayQueryFunction::Initialize {
acceleration_structure,
descriptor,
} = *fun
{
let _ = self.add_ref(acceleration_structure);
let _ = self.add_ref(descriptor);
}
FunctionUniformity::new()
}
};
disruptor = disruptor.or(uniformity.exit_disruptor());

View File

@ -807,6 +807,9 @@ impl super::Validator {
} => {
self.validate_atomic(pointer, fun, value, result, context)?;
}
S::RayQuery { query: _, fun: _ } => {
//TODO
}
}
}
Ok(BlockInfo { stages, finished })

View File

@ -496,6 +496,20 @@ impl super::Validator {
validate_expr_opt(result)?;
Ok(())
}
crate::Statement::RayQuery { query, ref fun } => {
validate_expr(query)?;
match *fun {
crate::RayQueryFunction::Initialize {
acceleration_structure,
descriptor,
} => {
validate_expr(acceleration_structure)?;
validate_expr(descriptor)?;
}
crate::RayQueryFunction::Proceed | crate::RayQueryFunction::Terminate => {}
}
Ok(())
}
crate::Statement::Break
| crate::Statement::Continue
| crate::Statement::Kill

View File

@ -1,5 +1,23 @@
var acc_struct: acceleration_structure;
/*
let RAY_FLAG_NONE = 0u;
let RAY_FLAG_TERMINATE_ON_FIRST_HIT = 4u;
let RAY_QUERY_INTERSECTION_NONE = 0u;
let RAY_QUERY_INTERSECTION_TRIANGLE = 1u;
let RAY_QUERY_INTERSECTION_GENERATED = 2u;
let RAY_QUERY_INTERSECTION_AABB = 4u;
struct RayDesc {
flags: u32,
cull_mask: u32,
origin: vec3<f32>,
t_min: f32,
dir: vec3<f32>,
t_max: f32,
}*/
struct Output {
visible: u32,
}
@ -9,7 +27,7 @@ var<storage, read_write> output: Output;
fn main() {
var rq: ray_query;
rayQueryInitialize(rq, acceleration_structure, RAY_FLAGS_TERMINATE_ON_FIRST_HIT, 0xFF, vec3<f32>(0.0), 0.1, vec3<f32>(0.0, 1.0, 0.0), 100.0);
rayQueryInitialize(rq, acceleration_structure, RayDesc(RAY_FLAG_TERMINATE_ON_FIRST_HIT, 0xFF, vec3<f32>(0.0), 0.1, vec3<f32>(0.0, 1.0, 0.0), 100.0));
rayQueryProceed(rq);