@@ -292,16 +292,65 @@ struct EntryPointMeshInfo {
292292 primitive_topology : wgt:: PrimitiveTopology ,
293293}
294294
295+ /// The [shader interface][si] of an entry point in a [`naga::Module`].
296+ ///
297+ /// [si]: https://www.w3.org/TR/WGSL/#shader-interface
295298#[ derive( Debug , Default ) ]
296299struct EntryPoint {
300+ /// The builtin and user-defined values passed to the entry point.
301+ ///
302+ /// In WGSL, these can be either passed directly as arguments or
303+ /// gathered up in structs that are passed; here, they are all
304+ /// flattened out.
297305 inputs : Vec < Varying > ,
306+
307+ /// The builtin and user-defined values returned by the entry point.
308+ ///
309+ /// In WGSL, a function either returns a single varying directly,
310+ /// or returns a struct of varyings; here, they are all flattened
311+ /// out.
312+ ///
313+ /// For mesh shaders, this also includes the vertex and primitive outputs.
298314 outputs : Vec < Varying > ,
315+
316+ /// This entry point's [resource interface][ri].
317+ ///
318+ /// This lists all the bound resources (that is, global variables with
319+ /// `@group` and `@binding` attributes) that this entry point statically
320+ /// uses.
321+ ///
322+ /// Handles here refer to elements of [`Interface::resources`].
323+ ///
324+ /// [ri]: https://www.w3.org/TR/WGSL/#resource-interface
299325 resources : Vec < naga:: Handle < Resource > > ,
326+
327+ /// Pairs of (texture, sampler) handles that this entry point uses
328+ /// together.
329+ ///
330+ /// This is the same information that Naga provides in
331+ /// [`naga::valid::FunctionInfo::sampling_set`] (used for generating GLSL),
332+ /// but adjusted to use handles referring to [`Interface::resources`].
300333 sampling_pairs : FastHashSet < ( naga:: Handle < Resource > , naga:: Handle < Resource > ) > ,
334+
335+ /// This entry point's workgroup size, if it is a [compute-like] shader
336+ /// (`compute`, `task`, or `mesh`).
337+ ///
338+ /// For non-compute-like entry points, this is `[0, 0, 0]`.
339+ ///
340+ /// [compute-like]: naga::ShaderStage::compute_like
301341 workgroup_size : [ u32 ; 3 ] ,
342+
343+ /// Indicates that the entry point uses dual source blending.
302344 dual_source_blending : bool ,
345+
346+ /// For task shaders and mesh shaders, the size of the task payload global
347+ /// they use to communicate.
303348 task_payload_size : Option < u32 > ,
349+
350+ /// Additional information for mesh shader entry points.
304351 mesh_info : Option < EntryPointMeshInfo > ,
352+
353+ /// Size of the immediate data, and which slots this entry point uses.
305354 immediate_usage : naga:: valid:: ImmediateUsage ,
306355}
307356
@@ -317,10 +366,35 @@ impl hashbrown::Equivalent<EntryPointKey> for EntryPointKeyRef<'_> {
317366 }
318367}
319368
369+ /// A summary of the [shader interfaces][si] of the entry points in a [`naga::Module`].
370+ ///
371+ /// [si]: https://www.w3.org/TR/WGSL/#shader-interface
320372#[ derive( Debug ) ]
321373pub struct Interface {
374+ /// A clone of the limits of the [`Device`] this module was created from.
375+ ///
376+ /// [`Interface::check_stage`] consults this for workgroup size checks.
377+ ///
378+ /// [`Device`]: crate::device::Device
322379 limits : wgt:: Limits ,
380+
381+ /// All the resources the module cites as global variables.
382+ ///
383+ /// This lists all the module's bound resources: global variables with
384+ /// `@group` and `@binding` attributes.
385+ ///
386+ /// Fields of [`EntryPoint`] like [`resources`] and [`sampling_pairs`] refer to
387+ /// elements in this arena by [`naga::Handle`].
388+ ///
389+ /// [`resources`]: EntryPoint::resources
390+ /// [`sampling_pairs`]: EntryPoint::sampling_pairs
323391 resources : naga:: Arena < Resource > ,
392+
393+ /// The shader interface of each [`naga::EntryPoint`] in the module.
394+ ///
395+ /// This table is keyed by (stage, name) pairs: [`naga::Module`]s are
396+ /// allowed to contain multiple entry points with the same name, as long as
397+ /// they are for different shader stages.
324398 entry_points : FastHashMap < EntryPointKey , EntryPoint > ,
325399}
326400
@@ -1115,6 +1189,19 @@ pub struct StageIo {
11151189}
11161190
11171191impl Interface {
1192+ /// Build some entry point's list of inputs or outputs.
1193+ ///
1194+ /// Given `ty` and `binding` that describe an entry point's argument or
1195+ /// return value, figure out which builtins or locations are involved and
1196+ /// add them to `list`, which is either [`EntryPoint::inputs`] or
1197+ /// [`EntryPoint::outputs`].
1198+ ///
1199+ /// - If `ty` is a struct type, visit its members to find
1200+ /// individual bindings, and add them to `list`.
1201+ ///
1202+ /// - Otherwise, `binding` must be `Some(b)` where `b` describes a
1203+ /// binding's builtin or location, and `ty` gives its type. Add
1204+ /// this binding to `list`.
11181205 fn populate (
11191206 list : & mut Vec < Varying > ,
11201207 binding : Option < & naga:: Binding > ,
@@ -1252,6 +1339,11 @@ impl Interface {
12521339 list. push ( varying) ;
12531340 }
12541341
1342+ /// Construct an [`Interface`] value describing `module`.
1343+ ///
1344+ /// The `info` argument must be the results from validating `module`, and
1345+ /// `limits` must be the limits for the device that we will use to create
1346+ /// this shader module.
12551347 pub fn new ( module : & naga:: Module , info : & naga:: valid:: ModuleInfo , limits : wgt:: Limits ) -> Self {
12561348 let mut resources = naga:: Arena :: new ( ) ;
12571349 let mut resource_mapping = FastHashMap :: default ( ) ;
@@ -1404,6 +1496,11 @@ impl Interface {
14041496 . unwrap_or_default ( )
14051497 }
14061498
1499+ /// Select an entry point name, given an optional name and a shader stage.
1500+ ///
1501+ /// See [`ShaderModule::finalize_entry_point_name`] for details.
1502+ ///
1503+ /// [`ShaderModule::finalize_entry_point_name`]: crate::pipeline::ShaderModule::finalize_entry_point_name
14071504 pub fn finalize_entry_point_name (
14081505 & self ,
14091506 stage : naga:: ShaderStage ,
@@ -1427,8 +1524,27 @@ impl Interface {
14271524 } )
14281525 }
14291526
1430- /// Among other things, this implements some validation logic defined by the WebGPU spec. at
1431- /// <https://www.w3.org/TR/webgpu/#abstract-opdef-validating-inter-stage-interfaces>.
1527+ /// Analyze and validate an entry point for use as a given shader stage.
1528+ ///
1529+ /// Validate the entry point named `entry_point_name` for use in
1530+ /// `shader_stage`:
1531+ ///
1532+ /// - Apply the WebGPU specification's [validating inter-stage interfaces]
1533+ /// algorithm.
1534+ ///
1535+ /// - Enforce workgroup size limits.
1536+ ///
1537+ /// - Check bind group layouts, and fill in derived bind group layouts.
1538+ ///
1539+ /// - Compute the minimum binding sizes, given the shader's resource
1540+ /// interface.
1541+ ///
1542+ /// - Check the compatibility between textures and samplers.
1543+ ///
1544+ /// Given `inputs`, describing this stage's inputs, return a [`StageIo`]
1545+ /// describing its outputs.
1546+ ///
1547+ /// [validating inter-stage interfaces]: https://www.w3.org/TR/webgpu/#abstract-opdef-validating-inter-stage-interfaces
14321548 pub fn check_stage (
14331549 & self ,
14341550 layouts : & mut BindingLayoutSource ,
0 commit comments