@@ -9,7 +9,7 @@ use super::{
9
9
use crate :: {
10
10
back:: { self , Baked } ,
11
11
proc:: { self , index, ExpressionKindTracker , NameKey } ,
12
- valid, Handle , Module , Scalar , ScalarKind , ShaderStage , TypeInner ,
12
+ valid, Handle , Module , RayQueryFunction , Scalar , ScalarKind , ShaderStage , TypeInner ,
13
13
} ;
14
14
use std:: { fmt, mem} ;
15
15
@@ -104,6 +104,8 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
104
104
entry_point_io : Vec :: new ( ) ,
105
105
named_expressions : crate :: NamedExpressions :: default ( ) ,
106
106
wrapped : super :: Wrapped :: default ( ) ,
107
+ written_committed_intersection : false ,
108
+ written_candidate_intersection : false ,
107
109
continue_ctx : back:: continue_forward:: ContinueCtx :: default ( ) ,
108
110
temp_access_chain : Vec :: new ( ) ,
109
111
need_bake_expressions : Default :: default ( ) ,
@@ -123,6 +125,8 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
123
125
self . entry_point_io . clear ( ) ;
124
126
self . named_expressions . clear ( ) ;
125
127
self . wrapped . clear ( ) ;
128
+ self . written_committed_intersection = false ;
129
+ self . written_candidate_intersection = false ;
126
130
self . continue_ctx . clear ( ) ;
127
131
self . need_bake_expressions . clear ( ) ;
128
132
}
@@ -1218,6 +1222,13 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
1218
1222
TypeInner :: Array { base, size, .. } | TypeInner :: BindingArray { base, size } => {
1219
1223
self . write_array_size ( module, base, size) ?;
1220
1224
}
1225
+ TypeInner :: AccelerationStructure => {
1226
+ write ! ( self . out, "RaytracingAccelerationStructure" ) ?;
1227
+ }
1228
+ TypeInner :: RayQuery => {
1229
+ // these are constant flags, there are dynamic flags also but constant flags are not supported by naga
1230
+ write ! ( self . out, "RayQuery<RAY_FLAG_NONE>" ) ?;
1231
+ }
1221
1232
_ => return Err ( Error :: Unimplemented ( format ! ( "write_value_type {inner:?}" ) ) ) ,
1222
1233
}
1223
1234
@@ -1375,15 +1386,20 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
1375
1386
self . write_array_size ( module, base, size) ?;
1376
1387
}
1377
1388
1378
- write ! ( self . out, " = " ) ?;
1379
- // Write the local initializer if needed
1380
- if let Some ( init) = local. init {
1381
- self . write_expr ( module, init, func_ctx) ?;
1382
- } else {
1383
- // Zero initialize local variables
1384
- self . write_default_init ( module, local. ty ) ?;
1389
+ match module. types [ local. ty ] . inner {
1390
+ // from https://microsoft.github.io/DirectX-Specs/d3d/Raytracing.html#tracerayinline-example-1 it seems that ray queries shouldn't be zeroed
1391
+ TypeInner :: RayQuery => { }
1392
+ _ => {
1393
+ write ! ( self . out, " = " ) ?;
1394
+ // Write the local initializer if needed
1395
+ if let Some ( init) = local. init {
1396
+ self . write_expr ( module, init, func_ctx) ?;
1397
+ } else {
1398
+ // Zero initialize local variables
1399
+ self . write_default_init ( module, local. ty ) ?;
1400
+ }
1401
+ }
1385
1402
}
1386
-
1387
1403
// Finish the local with `;` and add a newline (only for readability)
1388
1404
writeln ! ( self . out, ";" ) ?
1389
1405
}
@@ -2250,7 +2266,37 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
2250
2266
} => {
2251
2267
self . write_switch ( module, func_ctx, level, selector, cases) ?;
2252
2268
}
2253
- Statement :: RayQuery { .. } => unreachable ! ( ) ,
2269
+ Statement :: RayQuery { query, ref fun } => match * fun {
2270
+ RayQueryFunction :: Initialize {
2271
+ acceleration_structure,
2272
+ descriptor,
2273
+ } => {
2274
+ write ! ( self . out, "{level}" ) ?;
2275
+ self . write_expr ( module, query, func_ctx) ?;
2276
+ write ! ( self . out, ".TraceRayInline(" ) ?;
2277
+ self . write_expr ( module, acceleration_structure, func_ctx) ?;
2278
+ write ! ( self . out, ", " ) ?;
2279
+ self . write_expr ( module, descriptor, func_ctx) ?;
2280
+ write ! ( self . out, ".flags, " ) ?;
2281
+ self . write_expr ( module, descriptor, func_ctx) ?;
2282
+ write ! ( self . out, ".cull_mask, " ) ?;
2283
+ write ! ( self . out, "RayDescFromRayDesc_(" ) ?;
2284
+ self . write_expr ( module, descriptor, func_ctx) ?;
2285
+ writeln ! ( self . out, "));" ) ?;
2286
+ }
2287
+ RayQueryFunction :: Proceed { result } => {
2288
+ write ! ( self . out, "{level}" ) ?;
2289
+ let name = Baked ( result) . to_string ( ) ;
2290
+ write ! ( self . out, "const bool {name} = " ) ?;
2291
+ self . named_expressions . insert ( result, name) ;
2292
+ self . write_expr ( module, query, func_ctx) ?;
2293
+ writeln ! ( self . out, ".Proceed();" ) ?;
2294
+ }
2295
+ RayQueryFunction :: Terminate => {
2296
+ self . write_expr ( module, query, func_ctx) ?;
2297
+ writeln ! ( self . out, ".Abort();" ) ?;
2298
+ }
2299
+ } ,
2254
2300
Statement :: SubgroupBallot { result, predicate } => {
2255
2301
write ! ( self . out, "{level}" ) ?;
2256
2302
let name = Baked ( result) . to_string ( ) ;
@@ -3608,8 +3654,17 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
3608
3654
self . write_expr ( module, reject, func_ctx) ?;
3609
3655
write ! ( self . out, ")" ) ?
3610
3656
}
3611
- // Not supported yet
3612
- Expression :: RayQueryGetIntersection { .. } => unreachable ! ( ) ,
3657
+ Expression :: RayQueryGetIntersection { query, committed } => {
3658
+ if committed {
3659
+ write ! ( self . out, "GetCommittedIntersection(" ) ?;
3660
+ self . write_expr ( module, query, func_ctx) ?;
3661
+ write ! ( self . out, ")" ) ?;
3662
+ } else {
3663
+ write ! ( self . out, "GetCandidateIntersection(" ) ?;
3664
+ self . write_expr ( module, query, func_ctx) ?;
3665
+ write ! ( self . out, ")" ) ?;
3666
+ }
3667
+ }
3613
3668
// Nothing to do here, since call expression already cached
3614
3669
Expression :: CallResult ( _)
3615
3670
| Expression :: AtomicResult { .. }
0 commit comments