Skip to content

Commit

Permalink
[WebGPU] Support writing @Builtin(frag_depth) from the fragment shader
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=252452
rdar://105578867

Reviewed by Mike Wyrzykowski.

During code generation we were skipping serialization of builtins for fragment
output struct members.

* Source/WebGPU/WGSL/Metal/MetalFunctionWriter.cpp:
(WGSL::Metal::FunctionDefinitionWriter::visit):
* Source/WebGPU/WGSL/tests/valid/fragment-output.wgsl:

Canonical link: https://commits.webkit.org/269929@main
  • Loading branch information
tadeuzagallo committed Oct 30, 2023
1 parent df5c532 commit 76a4fde
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 1 addition & 2 deletions Source/WebGPU/WGSL/Metal/MetalFunctionWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,10 +505,9 @@ void FunctionDefinitionWriter::visit(AST::BuiltinAttribute& builtin)
// Built-in attributes are only valid for parameters. If a struct member originally
// had a built-in attribute it must have already been hoisted into a parameter, but
// we keep the original struct so we can reconstruct it.
if (m_structRole.has_value() && *m_structRole != AST::StructureRole::VertexOutput)
if (m_structRole.has_value() && *m_structRole != AST::StructureRole::VertexOutput && *m_structRole != AST::StructureRole::FragmentOutput)
return;

// FIXME: we should replace this with something more efficient, like a trie
switch (builtin.builtin()) {
case Builtin::FragDepth:
m_stringBuilder.append("[[depth(any)]]");
Expand Down
2 changes: 2 additions & 0 deletions Source/WebGPU/WGSL/tests/valid/fragment-output.wgsl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// RUN: %metal-compile main
struct S {
@builtin(frag_depth) depth: f32,
@location(0) x : vec3<f32>,
@location(1) y : vec4<f32>,
}
Expand All @@ -11,5 +12,6 @@ fn main() -> S {
var output : S;
output.x = vec3f(0);
output.y = vec4f(1);
output.depth = 1;
return output;
}

0 comments on commit 76a4fde

Please sign in to comment.