Skip to content

Commit

Permalink
Detect invalid layout(push_constant) modifier.
Browse files Browse the repository at this point in the history
Previously, the frontend would allow this flag combination through.
However, the SPIR-V backend asserts when layout(push_constant) is
applied to an in-variable or out-variable, or when a binding/set
is used.

Bug: oss-fuzz:58375
Change-Id: Ibad8879b50818a9ba6953918b85edaa64654e2cc
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/683200
Commit-Queue: Arman Uguray <[email protected]>
Auto-Submit: John Stiles <[email protected]>
Reviewed-by: Arman Uguray <[email protected]>
  • Loading branch information
johnstiles-google authored and SkCQ committed Apr 27, 2023
1 parent 1efb703 commit 487475e
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions gn/sksl_tests.gni
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ sksl_error_tests = [
"errors/Ossfuzz50922.sksl",
"errors/Ossfuzz56373.sksl",
"errors/Ossfuzz58037.sksl",
"errors/Ossfuzz58375.sksl",
"errors/OverflowFloatIntrinsic.sksl",
"errors/OverflowFloatLiteral.rts",
"errors/OverflowInlinedLiteral.sksl",
Expand Down
1 change: 1 addition & 0 deletions resources/sksl/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ skia_filegroup(
"errors/Ossfuzz50922.sksl",
"errors/Ossfuzz56373.sksl",
"errors/Ossfuzz58037.sksl",
"errors/Ossfuzz58375.sksl",
"errors/OverflowFloatIntrinsic.sksl",
"errors/OverflowFloatLiteral.rts",
"errors/OverflowInlinedLiteral.sksl",
Expand Down
1 change: 1 addition & 0 deletions resources/sksl/errors/LayoutRepeatedQualifiers.sksl
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@ layout qualifier 'gl' appears more than once
'layout(color)' is only permitted on 'uniform' variables
'layout(color)' is not permitted on variables of type 'float'
only one backend qualifier can be used
layout qualifier 'push_constant' is not permitted here
layout qualifier 'set' is not permitted here
*%%*/
5 changes: 5 additions & 0 deletions resources/sksl/errors/Ossfuzz58375.sksl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
layout (push_constant) in s { int x; };

half4 main(float2) {
return half4(0);
}
7 changes: 7 additions & 0 deletions src/sksl/ir/SkSLVarDeclarations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,13 @@ void VarDeclaration::ErrorCheck(const Context& context,
// Disallow all layout flags except 'color' in runtime effects
permittedLayoutFlags &= Layout::kColor_Flag;
}

// The `push_constant` flag isn't allowed on in-variables, out-variables, bindings or sets.
if ((modifiers.fLayout.fFlags & (Layout::kSet_Flag | Layout::kBinding_Flag)) ||
(modifiers.fFlags & (Modifiers::kIn_Flag | Modifiers::kOut_Flag))) {
permittedLayoutFlags &= ~Layout::kPushConstant_Flag;
}

modifiers.checkPermitted(context, modifiersPosition, permitted, permittedLayoutFlags);
}

Expand Down
5 changes: 4 additions & 1 deletion tests/sksl/errors/LayoutRepeatedQualifiers.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ layout (
error: 1: only one backend qualifier can be used
layout (
^^^^^^^^...
error: 1: layout qualifier 'push_constant' is not permitted here
layout (
^^^^^^^^...
error: 1: layout qualifier 'set' is not permitted here
layout (
^^^^^^^^...
19 errors
20 errors
6 changes: 6 additions & 0 deletions tests/sksl/errors/Ossfuzz58375.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
### Compilation failed:

error: 1: layout qualifier 'push_constant' is not permitted here
layout (push_constant) in s { int x; };
^^^^^^^^^^^^^^^^^^^^^^^^^
1 error

0 comments on commit 487475e

Please sign in to comment.