@@ -282,18 +282,57 @@ struct EntryPointMeshInfo {
282282 primitive_topology : wgt:: PrimitiveTopology ,
283283}
284284
285+ /// The [resource interface][ri] of an entry point in a [`naga::Module`].
286+ ///
287+ /// [ri]: https://www.w3.org/TR/WGSL/#resource-interface
285288#[ derive( Debug , Default ) ]
286289struct EntryPoint {
290+ /// The builtin and local values passed to the entry point.
291+ ///
292+ /// In WGSL, these can be either passed directly as arguments or
293+ /// gathered up in structs that are passed; here, they are all
294+ /// flattened out.
287295 inputs : Vec < Varying > ,
296+
297+ /// The builtin and local values returned by the entry point.
298+ ///
299+ /// In WGSL, a function either returns a single varying directly,
300+ /// or returns a struct of varyings; here, they are all flattened
301+ /// out.
288302 outputs : Vec < Varying > ,
303+
304+ /// All the globals this entry point uses.
305+ ///
306+ /// Handles here refer to elements of [`Interface::resources`].
289307 resources : Vec < naga:: Handle < Resource > > ,
308+
290309 #[ allow( unused) ]
291310 spec_constants : Vec < SpecializationConstant > ,
311+
312+ /// Pairs of (sampler, texture) handles that this entry point uses
313+ /// together.
314+ ///
315+ /// This is the same information that Naga provides in
316+ /// [`naga::valid::FunctionInfo::sampling_set`] (used for generating GLSL),
317+ /// but adjusted to use handles referring to [`Interface::resources`].
292318 sampling_pairs : FastHashSet < ( naga:: Handle < Resource > , naga:: Handle < Resource > ) > ,
319+
320+ /// This entry point's workgroup size, if it is a compute-like shader.
321+ ///
322+ /// For non-compute-like entry points, this is `[0, 0, 0]`.
293323 workgroup_size : [ u32 ; 3 ] ,
324+
325+ /// Indicates that the entry point uses dual source blending.
294326 dual_source_blending : bool ,
327+
328+ /// For task shaders and mesh shaders, the size of the task payload global
329+ /// they use to communicate.
295330 task_payload_size : Option < u32 > ,
331+
332+ /// Additional information for mesh shader entry points.
296333 mesh_info : Option < EntryPointMeshInfo > ,
334+
335+ /// Which slots of immediate data this entry point uses.
297336 immediate_usage : naga:: valid:: ImmediateUsage ,
298337}
299338
@@ -309,10 +348,24 @@ impl hashbrown::Equivalent<EntryPointKey> for EntryPointKeyRef<'_> {
309348 }
310349}
311350
351+ /// A summary of the [resource interfaces][ri] of the entry points in a [`naga::Module`].
352+ ///
353+ /// [ri]: https://www.w3.org/TR/WGSL/#resource-interface
312354#[ derive( Debug ) ]
313355pub struct Interface {
356+ /// A clone of the resource limits of the [`Device`] this module
357+ /// was created from.
358+ ///
359+ /// [`Device`]: crate::device::Device
314360 limits : wgt:: Limits ,
361+
362+ /// All the resources the module cites as global variables.
363+ ///
364+ /// Specific elements of `entry_points` refer to elements in this
365+ /// arena by [`naga::Handle`]`.
315366 resources : naga:: Arena < Resource > ,
367+
368+ /// The resource interface of each [`naga::EntryPoint`] in the module.
316369 entry_points : FastHashMap < EntryPointKey , EntryPoint > ,
317370}
318371
@@ -1103,6 +1156,19 @@ pub struct StageIo {
11031156}
11041157
11051158impl Interface {
1159+ /// Build some entry point's list of inputs or outputs.
1160+ ///
1161+ /// Given `ty` and `binding` that describe an entry point's
1162+ /// argument or return value, figure out which builtins or
1163+ /// locations are involved and add them to `ty`, which is either
1164+ /// [`EntryPoint::inputs`] or [`EntryPoint::outputs`].
1165+ ///
1166+ /// - If `ty` is a struct type, visit its members to find
1167+ /// individual bindings, and add them to `list`.
1168+ ///
1169+ /// - Otherwise, `binding` must be `Some(b)` where `b` describes a
1170+ /// binding's builtin or location, and `ty` gives its type. Add
1171+ /// this binding to `list`.
11061172 fn populate (
11071173 list : & mut Vec < Varying > ,
11081174 binding : Option < & naga:: Binding > ,
@@ -1245,6 +1311,11 @@ impl Interface {
12451311 list. push ( varying) ;
12461312 }
12471313
1314+ /// Construct an [`Interface`] value describing `module`.
1315+ ///
1316+ /// The `info` argument must be the results from validating `module`, and
1317+ /// `limits` must be the limits for the device that we will use to create
1318+ /// this shader module.
12481319 pub fn new ( module : & naga:: Module , info : & naga:: valid:: ModuleInfo , limits : wgt:: Limits ) -> Self {
12491320 let mut resources = naga:: Arena :: new ( ) ;
12501321 let mut resource_mapping = FastHashMap :: default ( ) ;
@@ -1419,6 +1490,8 @@ impl Interface {
14191490 } )
14201491 }
14211492
1493+ /// Validate the entry point described by `self` for use with `shader_stage`.
1494+ ///
14221495 /// Among other things, this implements some validation logic defined by the WebGPU spec. at
14231496 /// <https://www.w3.org/TR/webgpu/#abstract-opdef-validating-inter-stage-interfaces>.
14241497 pub fn check_stage (
0 commit comments