@@ -46,8 +46,8 @@ impl super::CommandEncoder {
4646 }
4747
4848 unsafe fn prepare_draw ( & mut self , base_vertex : i32 , base_instance : u32 ) {
49- let list = self . list . unwrap ( ) ;
5049 while self . pass . dirty_vertex_buffers != 0 {
50+ let list = self . list . unwrap ( ) ;
5151 let index = self . pass . dirty_vertex_buffers . trailing_zeros ( ) ;
5252 self . pass . dirty_vertex_buffers ^= 1 << index;
5353 list. IASetVertexBuffers (
@@ -61,6 +61,7 @@ impl super::CommandEncoder {
6161 super :: RootElement :: SpecialConstantBuffer {
6262 base_vertex : other_vertex,
6363 base_instance : other_instance,
64+ other : _,
6465 } => base_vertex != other_vertex || base_instance != other_instance,
6566 _ => true ,
6667 } ;
@@ -70,13 +71,33 @@ impl super::CommandEncoder {
7071 super :: RootElement :: SpecialConstantBuffer {
7172 base_vertex,
7273 base_instance,
74+ other : 0 ,
7375 } ;
7476 }
7577 }
7678 self . update_root_elements ( ) ;
7779 }
7880
79- fn prepare_dispatch ( & mut self ) {
81+ fn prepare_dispatch ( & mut self , count : [ u32 ; 3 ] ) {
82+ if let Some ( root_index) = self . pass . layout . special_constants_root_index {
83+ let needs_update = match self . pass . root_elements [ root_index as usize ] {
84+ super :: RootElement :: SpecialConstantBuffer {
85+ base_vertex,
86+ base_instance,
87+ other,
88+ } => [ base_vertex as u32 , base_instance, other] != count,
89+ _ => true ,
90+ } ;
91+ if needs_update {
92+ self . pass . dirty_root_elements |= 1 << root_index;
93+ self . pass . root_elements [ root_index as usize ] =
94+ super :: RootElement :: SpecialConstantBuffer {
95+ base_vertex : count[ 0 ] as i32 ,
96+ base_instance : count[ 1 ] ,
97+ other : count[ 2 ] ,
98+ } ;
99+ }
100+ }
80101 self . update_root_elements ( ) ;
81102 }
82103
@@ -95,12 +116,17 @@ impl super::CommandEncoder {
95116 super :: RootElement :: SpecialConstantBuffer {
96117 base_vertex,
97118 base_instance,
119+ other,
98120 } => match self . pass . kind {
99121 Pk :: Render => {
100122 list. set_graphics_root_constant ( index, base_vertex as u32 , 0 ) ;
101123 list. set_graphics_root_constant ( index, base_instance, 1 ) ;
102124 }
103- Pk :: Compute => ( ) ,
125+ Pk :: Compute => {
126+ list. set_compute_root_constant ( index, base_vertex as u32 , 0 ) ;
127+ list. set_compute_root_constant ( index, base_instance, 1 ) ;
128+ list. set_compute_root_constant ( index, other, 2 ) ;
129+ }
104130 Pk :: Transfer => ( ) ,
105131 } ,
106132 super :: RootElement :: Table ( descriptor) => match self . pass . kind {
@@ -141,6 +167,7 @@ impl super::CommandEncoder {
141167 super :: RootElement :: SpecialConstantBuffer {
142168 base_vertex : 0 ,
143169 base_instance : 0 ,
170+ other : 0 ,
144171 } ;
145172 }
146173 self . pass . layout = layout. clone ( ) ;
@@ -934,10 +961,12 @@ impl crate::CommandEncoder<super::Api> for super::CommandEncoder {
934961 }
935962
936963 unsafe fn dispatch ( & mut self , count : [ u32 ; 3 ] ) {
937- self . prepare_dispatch ( ) ;
964+ self . prepare_dispatch ( count ) ;
938965 self . list . unwrap ( ) . dispatch ( count) ;
939966 }
940967 unsafe fn dispatch_indirect ( & mut self , buffer : & super :: Buffer , offset : wgt:: BufferAddress ) {
968+ self . prepare_dispatch ( [ 0 ; 3 ] ) ;
969+ //TODO: update special constants indirectly
941970 self . list . unwrap ( ) . ExecuteIndirect (
942971 self . shared . cmd_signatures . dispatch . as_mut_ptr ( ) ,
943972 1 ,
0 commit comments