Repository navigation
Loosen pipeline fragment output validation - #1918
Conversation
This loosens validation so that fragment shaders do not need to include an output location for color targets that cannot be written to (have a writeMask of 0). This allows better shader reuse so that the shader fragment outputs do not need to match the pipeline color targets exactly if the pipeline does not intend to write to those targets.
kvark
left a comment
There was a problem hiding this comment.
I think this is generally good. It involves a bit more work on the implementation side to plumb the outputs to the shader. To help justifying this work, could you post a practical example that would benefit from this change?
|
Not actually more work. The spec prior to this PR required plumbing the outputs from the shader in order to validate they were present, with the correct type. |
|
The current spec requires that an implementation reflects the shader's use of outputs. |
|
Stated in the linked issue, "all of the target APIs Metal/D3D12/Vulkan allow you to have a fragment shader that does not write to all (or any) of the color attachments" so no shader patches are needed. I didn't find docs that say it is disallowed, and experimentally, the backend validation layers do not say that this is invalid. The Vulkan explicitly calls out that this is allowed, but does say that an undefined value may be written to the output - which is why the PR is validating that the writeMask is 0. |
kvark
left a comment
There was a problem hiding this comment.
Ah, ok, yes, thanks for correction! So the implementation will, instead of patching the shader, cut out the output from the pipeline description entirely. That makes it much easier to implement.
|
IIRC this was what we agreed upon in the meeting? So we can merge it? |
|
Just re-reading the Vulkan part, so they consider this to be "undefined value" and not cover with any valid usage rules. Seems good to go. |
Tests that use fragment shaders that don't write to the output must declare the color target with writeMask 0. Spec PR: gpuweb/gpuweb#1918 Bug: crbug.com/dawn/962
Tests that use fragment shaders that don't write to the output must declare the color target with writeMask 0. Spec PR: gpuweb/gpuweb#1918 Bug: crbug.com/dawn/962
Tests that use fragment shaders that don't write to the output must declare the color target with writeMask 0. Spec PR: gpuweb/gpuweb#1918 Bug: crbug.com/dawn/962
|
Recently when I'm working on the implementation for this, it seems on Metal it doesn't allow pipeline shader output type != color attachment type with writeMask == 0 WGSL: Color target format: WriteMask of 1,2,3 are 0. And I got this on Metal: I set writeMask to 0 and blendingEnabled to false for MTLRenderPipelineColorAttachmentDescriptor. (Let me know if setting some other state could turn it to valid) Since we don't a shader patch, maybe we'd like to adjust the validation rule to exclude the case where shader output type != color attachment/target type? I think for real use case, devs can just set the unused one to undefined (sparse attachment). It doesn't make much sense to write some int32 to a RGBA8Unorm with writeMask set to 0 though? |
|
This makes sense to me. I think the original intent of the PR was to make it valid for the fragment stage have extra outputs, not outputs that are a different format from the pipeline color targets. Could you make a PR for this validation? |
|
@shrekshao I don't understand the problem Here the loop will go through indices 0 2 and 3. (assuming undefined is that the color state 1 is not present in the descriptor. In Dawn's API that's translated with an Undefined format, but it's an implementation detail of Dawn/Chromium). For index 0: the entryPoint has a pipeline output. The type is f32 which is compatible with "rgba8unrom" What am I missing? |
It is not compatible. But the writeMask of index 2 is set 0
so it satisfies the "Otherwise" branch so it should be valid. We want to rule out these cases (shader output type don't match with attachment format) that don't seem to have realistic meaning, by only allow one incompatible case: "|colorState|.{{GPUColorTargetState/format}} can be |
|
They way I read the spec is: Basically if entries match, they must be compatible. If there is no output in the shader, but an entry in the descriptor, then the writeMask must be 0. This matches the commit message of this PR:
|
|
You are right. The current spec looks good. |
This loosens validation so that fragment shaders do not need
to include an output location for color targets that cannot be written
to (have a writeMask of 0). This allows better shader reuse so that
the shader fragment outputs do not need to match the pipeline
color targets exactly if the pipeline does not intend to write
to those targets.
Resolves #1900
Preview | Diff