1
1
// currently windows only because here we need a concrete gfx and os implementation
2
2
#![ cfg( target_os = "windows" ) ]
3
3
4
+ use hotline_rs:: gfx:: RaytracingTLAS ;
5
+
4
6
///
5
7
/// Raytraced Shadows
6
8
///
@@ -43,9 +45,9 @@ pub fn blas_from_mesh(device: &mut ResMut<DeviceRes>, mesh: &pmfx::Mesh<gfx_plat
43
45
index_buffer : & mesh. ib ,
44
46
vertex_buffer : & mesh. vb ,
45
47
transform3x4 : None ,
46
- index_count : 3 ,
48
+ index_count : mesh . num_indices as usize ,
47
49
index_format : gfx:: Format :: R16u ,
48
- vertex_count : 3 ,
50
+ vertex_count : mesh . num_indices as usize ,
49
51
vertex_format : gfx:: Format :: RGB32f ,
50
52
vertex_stride : 56
51
53
} ) ,
@@ -186,11 +188,11 @@ pub fn setup_raytraced_shadows_scene(
186
188
blas_from_mesh ( & mut device, & cube_mesh) ?
187
189
) ) ;
188
190
189
- commands. spawn ( (
191
+ commands. spawn (
190
192
TLAS {
191
193
tlas : None
192
194
}
193
- ) ) ;
195
+ ) ;
194
196
195
197
//
196
198
@@ -250,8 +252,16 @@ pub fn animate_lights (
250
252
Ok ( ( ) )
251
253
}
252
254
255
+ // TODO_RT
256
+ // create tlas with heap?
257
+ // update tlas
258
+ // mesh vertex count
259
+ // fix: Ignoring InitialState D3D12_RESOURCE_STATE_COPY_DEST. Buffers are effectively created in state D3D12_RESOURCE_STATE_COMMON.
260
+ // colors from rust compile output?
261
+
253
262
#[ export_compute_fn]
254
- pub fn render_meshes_raytraced (
263
+ pub fn render_meshes_raytraced (
264
+ device : ResMut < DeviceRes > ,
255
265
pmfx : & Res < PmfxRes > ,
256
266
pass : & pmfx:: ComputePass < gfx_platform:: Device > ,
257
267
tlas_query : Query < & TLAS >
@@ -262,35 +272,39 @@ pub fn render_meshes_raytraced(
262
272
let output_size = pmfx. get_texture_2d_size ( "staging_output" ) . expect ( "expected staging_output" ) ;
263
273
let output_tex = pmfx. get_texture ( "staging_output" ) . expect ( "expected staging_output" ) ;
264
274
265
- let cam = pmfx. get_camera_constants ( "main_camera" ) ;
266
- if let Ok ( cam ) = cam {
275
+ let camera = pmfx. get_camera_constants ( "main_camera" ) ;
276
+ if let Ok ( camera ) = camera {
267
277
for t in & tlas_query {
268
278
if let Some ( tlas) = & t. tlas {
269
279
270
280
// set pipeline
271
- let rt_pipeline = pmfx. get_raytracing_pipeline ( & pass. pass_pipline ) ?;
272
- pass. cmd_buf . set_raytracing_pipeline ( & rt_pipeline. pipeline ) ;
273
-
274
- // camera constants TODO:
275
-
276
- // resource use constants
277
- let using_slot = rt_pipeline. pipeline . get_pipeline_slot ( 0 , 1 , gfx:: DescriptorType :: PushConstants ) ;
278
- if let Some ( slot) = using_slot {
279
- for i in 0 ..pass. use_indices . len ( ) {
280
- let num_constants = gfx:: num_32bit_constants ( & pass. use_indices [ i] ) ;
281
- pass. cmd_buf . push_compute_constants (
282
- slot. index ,
283
- num_constants,
284
- i as u32 * num_constants,
285
- gfx:: as_u8_slice ( & pass. use_indices [ i] )
286
- ) ;
287
- }
281
+ let raytracing_pipeline = pmfx. get_raytracing_pipeline ( & pass. pass_pipline ) ?;
282
+ pass. cmd_buf . set_raytracing_pipeline ( & raytracing_pipeline. pipeline ) ;
283
+
284
+
285
+ let slot = raytracing_pipeline. pipeline . get_pipeline_slot ( 0 , 0 , gfx:: DescriptorType :: PushConstants ) ;
286
+ if let Some ( slot) = slot {
287
+ // camera constants
288
+ let inv = camera. view_projection_matrix . inverse ( ) ;
289
+ pass. cmd_buf . push_compute_constants ( slot. index , 16 , 0 , & inv) ;
290
+
291
+ // output uav
292
+ pass. cmd_buf . push_compute_constants ( slot. index , 4 , 16 , gfx:: as_u8_slice ( & pass. use_indices [ 0 ] . index ) ) ;
288
293
}
289
294
290
- pass. cmd_buf . set_heap ( & rt_pipeline. pipeline , & pmfx. shader_heap ) ;
295
+ // bind shader heap
296
+ if let Some ( u0) = raytracing_pipeline. pipeline . get_pipeline_slot ( 0 , 0 , gfx:: DescriptorType :: UnorderedAccess ) {
297
+ pass. cmd_buf . set_binding ( & raytracing_pipeline. pipeline , & pmfx. shader_heap , u0. index , 0 ) ;
298
+ }
299
+
300
+ // bind tlas on t1 (device heap)
301
+ let srv0 = tlas. get_srv_index ( ) . expect ( "expect tlas to have an srv" ) ;
302
+ if let Some ( t0) = raytracing_pipeline. pipeline . get_pipeline_slot ( 69 , 0 , gfx:: DescriptorType :: ShaderResource ) {
303
+ pass. cmd_buf . set_binding ( & raytracing_pipeline. pipeline , device. get_shader_heap ( ) , t0. index , srv0) ;
304
+ }
291
305
292
306
// dispatch
293
- pass. cmd_buf . dispatch_rays ( & rt_pipeline . sbt , gfx:: Size3 {
307
+ pass. cmd_buf . dispatch_rays ( & raytracing_pipeline . sbt , gfx:: Size3 {
294
308
x : output_size. 0 as u32 ,
295
309
y : output_size. 1 as u32 ,
296
310
z : 1
0 commit comments