@@ -19,18 +19,21 @@ use std::{
1919 time:: Instant ,
2020} ;
2121use stela_driver_gpu:: metal:: {
22- abi:: { ArgumentBuffersTier , DispatchType , GpuFamily , ReadWriteTextureTier } ,
22+ abi:: { ArgumentBuffersTier , DispatchType , GpuFamily , IndexType , ReadWriteTextureTier } ,
2323 capabilities:: { Capabilities , Size } ,
2424 command_buffer:: { CommandBuffer , ComputePipelineState } ,
2525 device:: {
2626 BufferId , LibraryId , SamplerId ,
2727 pipelines:: { ComputePipelineRequest , LinkedFunctions , PipelineArchives } ,
2828 } ,
2929 error:: { Error , Result } ,
30+ vertex:: { Attribute , StageInLayout , StageInStep , StageInputDescriptor , VertexFormat } ,
3031} ;
3132
32- const BASIC_CASE : [ & str ; 15 ] = [
33+ const BASIC_CASE : [ & str ; 17 ] = [
3334 "buffers" ,
35+ "constants" ,
36+ "stage_input" ,
3437 "dispatch" ,
3538 "function" ,
3639 "grid" ,
@@ -94,6 +97,11 @@ fn basic(case: &Value) -> bool {
9497 } )
9598 && all ( "samplers" , & super :: suite_resources:: SAMPLER )
9699 && ( case[ "dispatch" ] . is_null ( ) || case[ "dispatch" ] == "threads" )
100+ && ( case[ "stage_input" ] . is_null ( )
101+ || only (
102+ & case[ "stage_input" ] ,
103+ & [ "attributes" , "index_buffer" , "index_type" , "layouts" ] ,
104+ ) )
97105}
98106
99107/// Runs the selected cases of the suite in `dir`; `only` keeps the cases
@@ -180,8 +188,9 @@ pub(crate) struct Runner<'a> {
180188 pub ( crate ) exporter : & ' a Exporter ,
181189 pub ( crate ) plan_dir : PathBuf ,
182190 libraries : BTreeMap < String , LibraryId > ,
183- /// By library, function and threadgroup width, height and depth.
184- pipelines : BTreeMap < ( String , String , [ u64 ; 3 ] ) , ComputePipelineState > ,
191+ /// By library, function, threadgroup size, and the constants and stage
192+ /// input the case gives, as JSON.
193+ pipelines : BTreeMap < ( String , String , [ u64 ; 3 ] , String ) , ComputePipelineState > ,
185194 /// The next fake guest range index each import takes.
186195 pub ( crate ) next_import : u64 ,
187196}
@@ -229,6 +238,59 @@ pub(crate) struct Held {
229238 pub ( crate ) samplers : Vec < SamplerId > ,
230239}
231240
241+ /// A kernel's stage input, as the runner's `stage_input_descriptor`.
242+ fn stage_input ( spec : & Value ) -> Result < StageInputDescriptor > {
243+ let number = |item : & Value , key : & str , default : u64 | item[ key] . as_u64 ( ) . unwrap_or ( default) ;
244+ let mut attributes = Vec :: new ( ) ;
245+ for item in spec[ "attributes" ] . as_array ( ) . into_iter ( ) . flatten ( ) {
246+ attributes. push ( Attribute {
247+ index : number ( item, "index" , 0 ) as u32 ,
248+ format : named (
249+ VertexFormat :: ALL ,
250+ item[ "format" ] . as_str ( ) . unwrap_or_default ( ) ,
251+ )
252+ . ok_or ( Error :: Unsupported ( "an attribute format" ) ) ?,
253+ offset : number ( item, "offset" , 0 ) ,
254+ buffer_index : number ( item, "buffer" , 0 ) as u32 ,
255+ } ) ;
256+ }
257+ let mut layouts = Vec :: new ( ) ;
258+ for item in spec[ "layouts" ] . as_array ( ) . into_iter ( ) . flatten ( ) {
259+ let step = item[ "step" ] . as_str ( ) . unwrap_or ( "grid_x" ) ;
260+ let step_function = match step {
261+ "grid_x" => StageInStep :: ThreadPositionInGridX ,
262+ "grid_y" => StageInStep :: ThreadPositionInGridY ,
263+ "grid_x_indexed" => StageInStep :: ThreadPositionInGridXIndexed ,
264+ "grid_y_indexed" => StageInStep :: ThreadPositionInGridYIndexed ,
265+ "constant" => StageInStep :: Constant ,
266+ _ => return Err ( Error :: Unsupported ( "a stage-in step function" ) ) ,
267+ } ;
268+ if item[ "stride" ] . is_string ( ) {
269+ return Err ( Error :: Unsupported ( "a dynamic stage-in stride" ) ) ;
270+ }
271+ layouts. push ( StageInLayout {
272+ buffer_index : number ( item, "buffer" , 0 ) as u32 ,
273+ stride : number ( item, "stride" , 16 ) ,
274+ step_function,
275+ step_rate : if step == "constant" {
276+ 0
277+ } else {
278+ number ( item, "rate" , 1 )
279+ } ,
280+ } ) ;
281+ }
282+ Ok ( StageInputDescriptor {
283+ attributes,
284+ layouts,
285+ index_type : if spec[ "index_type" ] == "uint16" {
286+ IndexType :: UInt16
287+ } else {
288+ IndexType :: UInt32
289+ } ,
290+ index_buffer_index : number ( spec, "index_buffer" , 0 ) as u32 ,
291+ } )
292+ }
293+
232294/// Whether the device has what `requires` names, as the runner's `unmet`:
233295/// the missing one, if any.
234296pub ( crate ) fn unmet ( capabilities : & Capabilities , requires : & Value ) -> Option < String > {
@@ -412,7 +474,7 @@ impl Runner<'_> {
412474 } ;
413475 let grid = triple ( "grid" , 1 ) ;
414476 let group = triple ( "threadgroup" , 64 ) ;
415- let state = self . pipeline ( library, function, group) ?;
477+ let state = self . pipeline ( library, function, group, case ) ?;
416478
417479 let mut commands = self . device . new_command_buffer ( ) ;
418480 self . make_buffers ( & case[ "buffers" ] , held) ?;
@@ -449,6 +511,9 @@ impl Runner<'_> {
449511 depth : group[ 2 ] ,
450512 } ;
451513 if case[ "dispatch" ] == "threads" {
514+ if case[ "stage_input" ] . is_object ( ) {
515+ commands. set_stage_in_region ( [ 0 ; 3 ] , grid) ?;
516+ }
452517 let grid = grid. map ( |size| size as u32 ) ;
453518 commands. dispatch_threads ( & mut self . device . resolver ( ) , grid, threads) ?;
454519 } else {
@@ -485,18 +550,28 @@ impl Runner<'_> {
485550 library : & str ,
486551 function : & str ,
487552 group : [ u64 ; 3 ] ,
553+ case : & Value ,
488554 ) -> Result < ComputePipelineState > {
489- let key = ( library. to_owned ( ) , function. to_owned ( ) , group) ;
555+ let shape = format ! ( "{} {}" , case[ "constants" ] , case[ "stage_input" ] ) ;
556+ let key = ( library. to_owned ( ) , function. to_owned ( ) , group, shape) ;
490557 if let Some ( state) = self . pipelines . get ( & key) {
491558 return Ok ( state. clone ( ) ) ;
492559 }
493560 let library = self . library ( library) ?;
494- let function = self . device . new_function ( library, function, Some ( & [ ] ) ) ?;
561+ let constants = super :: suite_constants:: values ( & case[ "constants" ] ) ?;
562+ let function = self
563+ . device
564+ . new_function ( library, function, Some ( & constants) ) ?;
565+ let stage_input = if case[ "stage_input" ] . is_object ( ) {
566+ Some ( stage_input ( & case[ "stage_input" ] ) ?)
567+ } else {
568+ None
569+ } ;
495570 let pipeline = self . device . new_compute_pipeline ( & ComputePipelineRequest {
496571 compute_function : function,
497572 threadgroup_size_is_multiple_of_thread_execution_width : false ,
498573 max_total_threads_per_threadgroup : 0 ,
499- stage_input : None ,
574+ stage_input,
500575 linked_functions : LinkedFunctions :: default ( ) ,
501576 support_indirect_command_buffers : false ,
502577 archives : PipelineArchives :: default ( ) ,
0 commit comments