@@ -22,7 +22,6 @@ const MAX_BUNNIES: usize = 1 << 20;
22
22
const BUNNY_SIZE : f32 = 0.15 * 256.0 ;
23
23
const GRAVITY : f32 = -9.8 * 100.0 ;
24
24
const MAX_VELOCITY : f32 = 750.0 ;
25
- const COMMAND_BUFFER_PER_CONTEXT : usize = 100 ;
26
25
const DESIRED_MAX_LATENCY : u32 = 2 ;
27
26
28
27
#[ repr( C ) ]
@@ -498,7 +497,7 @@ impl<A: hal::Api> Example<A> {
498
497
let mut fence = device. create_fence ( ) . unwrap ( ) ;
499
498
let init_cmd = cmd_encoder. end_encoding ( ) . unwrap ( ) ;
500
499
queue
501
- . submit ( & [ & init_cmd] , & [ ] , Some ( ( & mut fence, init_fence_value) ) )
500
+ . submit ( & [ & init_cmd] , & [ ] , ( & mut fence, init_fence_value) )
502
501
. unwrap ( ) ;
503
502
device. wait ( & fence, init_fence_value, !0 ) . unwrap ( ) ;
504
503
device. destroy_buffer ( staging_buffer) ;
@@ -550,7 +549,7 @@ impl<A: hal::Api> Example<A> {
550
549
{
551
550
let ctx = & mut self . contexts [ self . context_index ] ;
552
551
self . queue
553
- . submit ( & [ ] , & [ ] , Some ( ( & mut ctx. fence , ctx. fence_value ) ) )
552
+ . submit ( & [ ] , & [ ] , ( & mut ctx. fence , ctx. fence_value ) )
554
553
. unwrap ( ) ;
555
554
}
556
555
@@ -650,7 +649,13 @@ impl<A: hal::Api> Example<A> {
650
649
651
650
let ctx = & mut self . contexts [ self . context_index ] ;
652
651
653
- let surface_tex = unsafe { self . surface . acquire_texture ( None ) . unwrap ( ) . unwrap ( ) . texture } ;
652
+ let surface_tex = unsafe {
653
+ self . surface
654
+ . acquire_texture ( None , & ctx. fence )
655
+ . unwrap ( )
656
+ . unwrap ( )
657
+ . texture
658
+ } ;
654
659
655
660
let target_barrier0 = hal:: TextureBarrier {
656
661
texture : surface_tex. borrow ( ) ,
@@ -718,7 +723,6 @@ impl<A: hal::Api> Example<A> {
718
723
}
719
724
720
725
ctx. frames_recorded += 1 ;
721
- let do_fence = ctx. frames_recorded > COMMAND_BUFFER_PER_CONTEXT ;
722
726
723
727
let target_barrier1 = hal:: TextureBarrier {
724
728
texture : surface_tex. borrow ( ) ,
@@ -732,45 +736,42 @@ impl<A: hal::Api> Example<A> {
732
736
733
737
unsafe {
734
738
let cmd_buf = ctx. encoder . end_encoding ( ) . unwrap ( ) ;
735
- let fence_param = if do_fence {
736
- Some ( ( & mut ctx. fence , ctx. fence_value ) )
737
- } else {
738
- None
739
- } ;
740
739
self . queue
741
- . submit ( & [ & cmd_buf] , & [ & surface_tex] , fence_param)
740
+ . submit (
741
+ & [ & cmd_buf] ,
742
+ & [ & surface_tex] ,
743
+ ( & mut ctx. fence , ctx. fence_value ) ,
744
+ )
742
745
. unwrap ( ) ;
743
746
self . queue . present ( & self . surface , surface_tex) . unwrap ( ) ;
744
747
ctx. used_cmd_bufs . push ( cmd_buf) ;
745
748
ctx. used_views . push ( surface_tex_view) ;
746
749
} ;
747
750
748
- if do_fence {
749
- log:: debug!( "Context switch from {}" , self . context_index) ;
750
- let old_fence_value = ctx. fence_value ;
751
- if self . contexts . len ( ) == 1 {
752
- let hal_desc = hal:: CommandEncoderDescriptor {
753
- label : None ,
754
- queue : & self . queue ,
755
- } ;
756
- self . contexts . push ( unsafe {
757
- ExecutionContext {
758
- encoder : self . device . create_command_encoder ( & hal_desc) . unwrap ( ) ,
759
- fence : self . device . create_fence ( ) . unwrap ( ) ,
760
- fence_value : 0 ,
761
- used_views : Vec :: new ( ) ,
762
- used_cmd_bufs : Vec :: new ( ) ,
763
- frames_recorded : 0 ,
764
- }
765
- } ) ;
766
- }
767
- self . context_index = ( self . context_index + 1 ) % self . contexts . len ( ) ;
768
- let next = & mut self . contexts [ self . context_index ] ;
769
- unsafe {
770
- next. wait_and_clear ( & self . device ) ;
771
- }
772
- next. fence_value = old_fence_value + 1 ;
751
+ log:: debug!( "Context switch from {}" , self . context_index) ;
752
+ let old_fence_value = ctx. fence_value ;
753
+ if self . contexts . len ( ) == 1 {
754
+ let hal_desc = hal:: CommandEncoderDescriptor {
755
+ label : None ,
756
+ queue : & self . queue ,
757
+ } ;
758
+ self . contexts . push ( unsafe {
759
+ ExecutionContext {
760
+ encoder : self . device . create_command_encoder ( & hal_desc) . unwrap ( ) ,
761
+ fence : self . device . create_fence ( ) . unwrap ( ) ,
762
+ fence_value : 0 ,
763
+ used_views : Vec :: new ( ) ,
764
+ used_cmd_bufs : Vec :: new ( ) ,
765
+ frames_recorded : 0 ,
766
+ }
767
+ } ) ;
768
+ }
769
+ self . context_index = ( self . context_index + 1 ) % self . contexts . len ( ) ;
770
+ let next = & mut self . contexts [ self . context_index ] ;
771
+ unsafe {
772
+ next. wait_and_clear ( & self . device ) ;
773
773
}
774
+ next. fence_value = old_fence_value + 1 ;
774
775
}
775
776
}
776
777
0 commit comments