Skip to content

Validation fails to reject out-of-range fragment shader output locations #5341

@jimblandy

Description

@jimblandy

There is no language in the WebGPU API or WGSL specs that would reject a fragment shader that has an output whose location exceeds maxColorAttachments.

For example, suppose that maxColorAttachments is 8 and we have the following fragment shader:

struct FragmentOut {
    @location(0) color: vec4<f32>,
    @location(8) slurve: vec4<f32>,
}

@fragment
fn blue() -> FragmentOut {
   return FragmentOut(vec4<f32>(0.0, 0.0, 1.0, 1.0), vec4<f32>());
}

Chrome refuses to construct a render pipeline:

Uncaptured WebGPU error: [EntryPoint "blue"] infringes limits:
 - Fragment output variable "<retval>.slurve" has a location (8) that exceeds the maximum (8).

 - While validating fragment stage ([ShaderModule (unlabeled)], entryPoint: "blue").
 - While validating fragment state.
 - While calling [Device].CreateRenderPipeline([RenderPipelineDescriptor]).

But as far as I can see, there is no language in the WebGPU spec that supports Chrome in producing this error. Although every non-null member in the GPUFragmentState::targets array is checked against the fragment shader's outputs, there is no requirement to inspect fragment shader outputs that do not have targets.

I'm also a little surprised that WebGPU allows fragment shaders to write to targets that aren't specified; is this to allow reuse of fragment shaders with different subsets of the possible targets?

Metadata

Metadata

Assignees

No one assigned

    Labels

    apiWebGPU APIapi resolvedResolved - waiting for a change to the API specification

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions