@@ -584,7 +584,17 @@ struct BufferResource {
584
584
ptr : BufferPtr ,
585
585
offset : wgt:: BufferAddress ,
586
586
dynamic_index : Option < u32 > ,
587
+
588
+ /// The buffer's size, if it is a [`Storage`] binding. Otherwise `None`.
589
+ ///
590
+ /// Buffers with the [`wgt::BufferBindingType::Storage`] binding type can
591
+ /// hold WGSL runtime-sized arrays. When one does, we must pass its size to
592
+ /// shader entry points to implement bounds checks and WGSL's `arrayLength`
593
+ /// function. See [`device::CompiledShader::sized_bindings`] for details.
594
+ ///
595
+ /// [`Storage`]: wgt::BufferBindingType::Storage
587
596
binding_size : Option < wgt:: BufferSize > ,
597
+
588
598
binding_location : u32 ,
589
599
}
590
600
@@ -607,7 +617,15 @@ pub struct ShaderModule {
607
617
#[ derive( Debug , Default ) ]
608
618
struct PipelineStageInfo {
609
619
push_constants : Option < PushConstantsInfo > ,
620
+
621
+ /// The buffer argument table index at which we pass runtime-sized arrays' buffer sizes.
622
+ ///
623
+ /// See [`device::CompiledShader::sized_bindings`] for more details.
610
624
sizes_slot : Option < naga:: back:: msl:: Slot > ,
625
+
626
+ /// Bindings of all WGSL `storage` globals that contain runtime-sized arrays.
627
+ ///
628
+ /// See [`device::CompiledShader::sized_bindings`] for more details.
611
629
sized_bindings : Vec < naga:: ResourceBinding > ,
612
630
}
613
631
@@ -714,7 +732,28 @@ struct CommandState {
714
732
index : Option < IndexState > ,
715
733
raw_wg_size : mtl:: MTLSize ,
716
734
stage_infos : MultiStageData < PipelineStageInfo > ,
735
+
736
+ /// Sizes of currently bound [`wgt::BufferBindingType::Storage`] buffers.
737
+ ///
738
+ /// Specifically:
739
+ ///
740
+ /// - The keys are ['ResourceBinding`] values (that is, the WGSL `@group`
741
+ /// and `@binding` attributes) for `var<storage>` global variables in the
742
+ /// current module that contain runtime-sized arrays.
743
+ ///
744
+ /// - The values are the actual sizes of the buffers currently bound to
745
+ /// provide those globals' contents, which are needed to implement bounds
746
+ /// checks and the WGSL `arrayLength` function.
747
+ ///
748
+ /// For each stage `S` in `stage_infos`, we consult this to find the sizes
749
+ /// of the buffers listed in [`stage_infos.S.sized_bindings`], which we must
750
+ /// pass to the entry point.
751
+ ///
752
+ /// See [`device::CompiledShader::sized_bindings`] for more details.
753
+ ///
754
+ /// [`ResourceBinding`]: naga::ResourceBinding
717
755
storage_buffer_length_map : fxhash:: FxHashMap < naga:: ResourceBinding , wgt:: BufferSize > ,
756
+
718
757
work_group_memory_sizes : Vec < u32 > ,
719
758
push_constants : Vec < u32 > ,
720
759
}
0 commit comments