wgpu icon indicating copy to clipboard operation
wgpu copied to clipboard

Update inter-stage interface validation to follow spec

Open Imberflur opened this issue 1 year ago • 0 comments

https://gpuweb.github.io/gpuweb/#abstract-opdef-validating-inter-stage-interfaces

I noticed a few inconsistencies with the spec when reading through the interface validation code in wgpu-core.

  • [ ] User-defined variables all count as 4 components towards the limit (not what ty.dim.num_components() returns).

    Each user-defined output of descriptor.vertex consumes 4 scalar components.

    For each user-defined input of descriptor.fragment there must be a user-defined output of descriptor.vertex that location, type, and interpolation of the input.

  • [ ] If the topology is "point-list" the component limit for vertex outputs needs to be reduced by 1.

    If descriptor.primitive.topology is "point-list":

    Decrement maxVertexShaderOutputComponents by 1.

  • [ ] For fragment inputs, the front_facing, sample_index, and sample_mask builtins all count as 1 component towards the limit.

  • [ ] There is now a maxInterStageShaderVariables (also mentioned in https://github.com/gfx-rs/wgpu/issues/2170):

    The location of each user-defined output of descriptor.vertex must be < device.limits.maxInterStageShaderVariables.


I also had a couple questions on things aren't necessarily issues but weren't obvious to me when reading the code:

  • At the point where validation is done: https://github.com/gfx-rs/wgpu/blob/53dd49f839bfa87331f2f2ed91b8810d86a6a6d7/wgpu-core/src/validation.rs#L1255 are all Varying::Local variables "user-defined"? (in terms of how the spec uses "user-defined")
  • Matching types between stages is checked via frag_input_ty.is_subtype_of(vert_output_ty) (here). E.g. for a particular location this would allow vec4<f32> on the vertex side and f32 on the fragment side. Whether this is allowed isn't clear to me when looking at the line in the spec:

    For each user-defined input of descriptor.fragment there must be a user-defined output of descriptor.vertex that location, type, and interpolation of the input.

Imberflur avatar Apr 22 '24 00:04 Imberflur