Refactored IRGenerator::convertInterfaceBlock
Previously the magic surrounding sk_RTAdjust was inaccessible to the
DSL, meaning that the DSLParser would not work properly when the
sk_RTAdjust field was present in an interface block. This refactoring
means all interface blocks are processed via the same path.
Change-Id: I99a2fe6875dfcbccc53f7a44f0fb1912cb2722ce
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/442456
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
diff --git a/tests/SkSLDSLTest.cpp b/tests/SkSLDSLTest.cpp
index 4a5359a..2349249 100644
--- a/tests/SkSLDSLTest.cpp
+++ b/tests/SkSLDSLTest.cpp
@@ -2002,20 +2002,52 @@
}
DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLRTAdjust, r, ctxInfo) {
- AutoDSLContext context(ctxInfo.directContext()->priv().getGpu(), no_mark_vars_declared(),
- SkSL::ProgramKind::kVertex);
- DSLGlobalVar rtAdjust(kUniform_Modifier, kFloat4_Type, "sk_RTAdjust");
- Declare(rtAdjust);
- DSLFunction(kVoid_Type, "main").define(
- sk_Position() = Half4(0)
- );
- REPORTER_ASSERT(r, DSLWriter::ProgramElements().size() == 2);
- EXPECT_EQUAL(*DSLWriter::ProgramElements()[1],
- "void main() {"
- "(sk_PerVertex.sk_Position = float4(0.0));"
- "(sk_PerVertex.sk_Position = float4(((sk_PerVertex.sk_Position.xy * sk_RTAdjust.xz) + "
- "(sk_PerVertex.sk_Position.ww * sk_RTAdjust.yw)), 0.0, sk_PerVertex.sk_Position.w));"
- "}");
+ {
+ AutoDSLContext context(ctxInfo.directContext()->priv().getGpu(), no_mark_vars_declared(),
+ SkSL::ProgramKind::kVertex);
+ DSLGlobalVar rtAdjust(kUniform_Modifier, kFloat4_Type, "sk_RTAdjust");
+ Declare(rtAdjust);
+ DSLFunction(kVoid_Type, "main").define(
+ sk_Position() = Half4(0)
+ );
+ REPORTER_ASSERT(r, DSLWriter::ProgramElements().size() == 2);
+ EXPECT_EQUAL(*DSLWriter::ProgramElements()[1],
+ "void main() {"
+ "(sk_PerVertex.sk_Position = float4(0.0));"
+ "(sk_PerVertex.sk_Position = float4(((sk_PerVertex.sk_Position.xy * sk_RTAdjust.xz) + "
+ "(sk_PerVertex.sk_Position.ww * sk_RTAdjust.yw)), 0.0, sk_PerVertex.sk_Position.w));"
+ "}");
+ }
+
+ {
+ AutoDSLContext context(ctxInfo.directContext()->priv().getGpu(), no_mark_vars_declared(),
+ SkSL::ProgramKind::kVertex);
+ REPORTER_ASSERT(r, !DSLWriter::IRGenerator().haveRTAdjustInterfaceBlock());
+
+ DSLGlobalVar intf = InterfaceBlock(kUniform_Modifier, "uniforms",
+ { Field(kInt_Type, "unused"),
+ Field(kFloat4_Type, "sk_RTAdjust") });
+ REPORTER_ASSERT(r, DSLWriter::IRGenerator().haveRTAdjustInterfaceBlock());
+ REPORTER_ASSERT(r, DSLWriter::IRGenerator().getRTAdjustFieldIndex() == 1);
+ }
+
+ {
+ AutoDSLContext context(ctxInfo.directContext()->priv().getGpu(), no_mark_vars_declared(),
+ SkSL::ProgramKind::kVertex);
+ ExpectError error(r, "sk_RTAdjust must have type 'float4'");
+ InterfaceBlock(kUniform_Modifier, "uniforms",
+ { Field(kInt_Type, "unused"), Field(kHalf4_Type, "sk_RTAdjust") });
+ }
+
+ {
+ AutoDSLContext context(ctxInfo.directContext()->priv().getGpu(), no_mark_vars_declared(),
+ SkSL::ProgramKind::kVertex);
+ ExpectError error(r, "symbol 'sk_RTAdjust' was already defined");
+ InterfaceBlock(kUniform_Modifier, "uniforms1",
+ { Field(kInt_Type, "unused1"), Field(kFloat4_Type, "sk_RTAdjust") });
+ InterfaceBlock(kUniform_Modifier, "uniforms2",
+ { Field(kInt_Type, "unused2"), Field(kFloat4_Type, "sk_RTAdjust") });
+ }
}
DEF_GPUTEST_FOR_MOCK_CONTEXT(DSLInlining, r, ctxInfo) {