@@ -1315,7 +1315,7 @@ impl ShaderBindingData {
13151315 device : Arc < Device > ,
13161316 pipeline : & dyn hal:: DynRayTracingPipeline ,
13171317 num_intersection_groups : usize ,
1318- ) -> Result < Self , CreateRayTracingPipelineError > {
1318+ ) -> Result < Arc < Self > , CreateRayTracingPipelineError > {
13191319 let mut base_data = Vec :: new ( ) ;
13201320
13211321 let ray_generation_data = unsafe {
@@ -1371,6 +1371,14 @@ impl ShaderBindingData {
13711371 }
13721372 . map_err ( |e| CreateRayTracingPipelineError :: Device ( device. handle_hal_error ( e) ) ) ?;
13731373
1374+ let sbd = Arc :: new ( Self {
1375+ raw : ManuallyDrop :: new ( buffer) ,
1376+ device : device. clone ( ) ,
1377+ num_intersection_groups : u32:: try_from ( num_intersection_groups) . unwrap ( ) ,
1378+ miss_offset : padded_miss_offset,
1379+ intersection_offset : padded_intersection_offset,
1380+ } ) ;
1381+
13741382 // If there is no queue anymore, the ray tracing pipeline can't be accessed, so we don't have to worry about UB from uninitialized values
13751383 if let Some ( queue) = device. get_queue ( ) {
13761384 let mut staging = crate :: resource:: StagingBuffer :: new (
@@ -1390,7 +1398,7 @@ impl ShaderBindingData {
13901398 unsafe {
13911399 encoder. copy_buffer_to_buffer (
13921400 staging_buf. raw ( ) ,
1393- buffer . as_ref ( ) ,
1401+ sbd . raw . as_ref ( ) ,
13941402 & [ hal:: BufferCopy {
13951403 src_offset : 0 ,
13961404 dst_offset : 0 ,
@@ -1401,15 +1409,10 @@ impl ShaderBindingData {
14011409 } ;
14021410
14031411 writes. consume ( staging_buf) ;
1412+ writes. use_shader_binding_data ( & sbd) ;
14041413 }
14051414
1406- Ok ( Self {
1407- raw : ManuallyDrop :: new ( buffer) ,
1408- device,
1409- num_intersection_groups : u32:: try_from ( num_intersection_groups) . unwrap ( ) ,
1410- miss_offset : padded_miss_offset,
1411- intersection_offset : padded_intersection_offset,
1412- } )
1415+ Ok ( sbd)
14131416 }
14141417}
14151418
@@ -1427,7 +1430,7 @@ impl Drop for ShaderBindingData {
14271430pub ( crate ) struct RayTracingPipelineState {
14281431 pub ( crate ) raw : ManuallyDrop < Box < dyn hal:: DynRayTracingPipeline > > ,
14291432 pub ( crate ) layout : Arc < PipelineLayout > ,
1430- pub ( crate ) shader_binding_data : ShaderBindingData ,
1433+ pub ( crate ) shader_binding_data : Arc < ShaderBindingData > ,
14311434 pub ( crate ) _shader_modules : Vec < Arc < ShaderModule > > ,
14321435}
14331436
0 commit comments