From 83f3b8d4ad7f72c38b714648d2df01dc287f3281 Mon Sep 17 00:00:00 2001 From: John Stiles Date: Mon, 7 Dec 2020 17:52:25 -0500 Subject: [PATCH] Add newline to end of Metal's Globals struct definition. Also fixes some additional style mishaps in class method names. Change-Id: I49e7ac1aa91d84fef5fbc636552f040a2cb58c78 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/341466 Commit-Queue: Brian Osman Auto-Submit: John Stiles Reviewed-by: Brian Osman --- src/sksl/SkSLMetalCodeGenerator.cpp | 30 +++++++++---------- tests/sksl/metal/golden/NumericGlobals.metal | 1 + tests/sksl/metal/golden/SamplerGlobals.metal | 1 + tests/sksl/shared/golden/ComplexDelete.metal | 1 + tests/sksl/shared/golden/GaussianBlur.metal | 1 + .../golden/InterfaceBlockAnonymous.metal | 3 +- .../shared/golden/InterfaceBlockArray.metal | 3 +- .../shared/golden/InterfaceBlockNamed.metal | 3 +- .../shared/golden/NumberConversions.metal | 1 + .../sksl/shared/golden/RectangleTexture.metal | 1 + tests/sksl/shared/golden/Structs.metal | 1 + tests/sksl/shared/golden/Texture2D.metal | 1 + .../shared/golden/VectorConstructors.metal | 1 + 13 files changed, 30 insertions(+), 18 deletions(-) diff --git a/src/sksl/SkSLMetalCodeGenerator.cpp b/src/sksl/SkSLMetalCodeGenerator.cpp index a45f638e7c..77f50c27f6 100644 --- a/src/sksl/SkSLMetalCodeGenerator.cpp +++ b/src/sksl/SkSLMetalCodeGenerator.cpp @@ -1715,7 +1715,7 @@ void MetalCodeGenerator::writeGlobalStruct() { class : public GlobalStructVisitor { public: void visitInterfaceBlock(const InterfaceBlock& block, const String& blockName) override { - this->AddElement(); + this->addElement(); fCodeGen->write(" constant "); fCodeGen->write(block.typeName()); fCodeGen->write("* "); @@ -1723,7 +1723,7 @@ void MetalCodeGenerator::writeGlobalStruct() { fCodeGen->write(";\n"); } void visitTexture(const Type& type, const String& name) override { - this->AddElement(); + this->addElement(); fCodeGen->write(" "); fCodeGen->writeBaseType(type); fCodeGen->write(" "); @@ -1732,13 +1732,13 @@ void MetalCodeGenerator::writeGlobalStruct() { fCodeGen->write(";\n"); } void visitSampler(const Type&, const String& name) override { - this->AddElement(); + this->addElement(); fCodeGen->write(" sampler "); fCodeGen->writeName(name); fCodeGen->write(";\n"); } void visitVariable(const Variable& var, const Expression* value) override { - this->AddElement(); + this->addElement(); fCodeGen->write(" "); fCodeGen->writeBaseType(var.type()); fCodeGen->write(" "); @@ -1746,15 +1746,15 @@ void MetalCodeGenerator::writeGlobalStruct() { fCodeGen->writeArrayDimensions(var.type()); fCodeGen->write(";\n"); } - void AddElement() { + void addElement() { if (fFirst) { fCodeGen->write("struct Globals {\n"); fFirst = false; } } - void Finish() { + void finish() { if (!fFirst) { - fCodeGen->write("};"); + fCodeGen->writeLine("};"); fFirst = true; } } @@ -1765,7 +1765,7 @@ void MetalCodeGenerator::writeGlobalStruct() { visitor.fCodeGen = this; this->visitGlobalStruct(&visitor); - visitor.Finish(); + visitor.finish(); } void MetalCodeGenerator::writeGlobalInit() { @@ -1773,27 +1773,27 @@ void MetalCodeGenerator::writeGlobalInit() { public: void visitInterfaceBlock(const InterfaceBlock& blockType, const String& blockName) override { - this->AddElement(); + this->addElement(); fCodeGen->write("&"); fCodeGen->writeName(blockName); } void visitTexture(const Type&, const String& name) override { - this->AddElement(); + this->addElement(); fCodeGen->writeName(name); } void visitSampler(const Type&, const String& name) override { - this->AddElement(); + this->addElement(); fCodeGen->writeName(name); } void visitVariable(const Variable& var, const Expression* value) override { - this->AddElement(); + this->addElement(); if (value) { fCodeGen->writeVarInitializer(var, *value); } else { fCodeGen->write("{}"); } } - void AddElement() { + void addElement() { if (fFirst) { fCodeGen->write(" Globals globalStruct{"); fFirst = false; @@ -1801,7 +1801,7 @@ void MetalCodeGenerator::writeGlobalInit() { fCodeGen->write(", "); } } - void Finish() { + void finish() { if (!fFirst) { fCodeGen->writeLine("};"); fCodeGen->writeLine(" thread Globals* _globals = &globalStruct;"); @@ -1814,7 +1814,7 @@ void MetalCodeGenerator::writeGlobalInit() { visitor.fCodeGen = this; this->visitGlobalStruct(&visitor); - visitor.Finish(); + visitor.finish(); } void MetalCodeGenerator::writeProgramElement(const ProgramElement& e) { diff --git a/tests/sksl/metal/golden/NumericGlobals.metal b/tests/sksl/metal/golden/NumericGlobals.metal index 792f25adb0..ad92aa42f1 100644 --- a/tests/sksl/metal/golden/NumericGlobals.metal +++ b/tests/sksl/metal/golden/NumericGlobals.metal @@ -15,6 +15,7 @@ struct Globals { + fragment Outputs fragmentMain(Inputs _in [[stage_in]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) { Globals globalStruct{{}, 123, {}, float4(4.0, 5.0, 6.0, 7.0)}; thread Globals* _globals = &globalStruct; diff --git a/tests/sksl/metal/golden/SamplerGlobals.metal b/tests/sksl/metal/golden/SamplerGlobals.metal index 6d405efa0f..ee6c7de68a 100644 --- a/tests/sksl/metal/golden/SamplerGlobals.metal +++ b/tests/sksl/metal/golden/SamplerGlobals.metal @@ -13,6 +13,7 @@ struct Globals { sampler texBSmplr; }; + fragment Outputs fragmentMain(Inputs _in [[stage_in]], texture2d texA[[texture(1)]], sampler texASmplr[[sampler(1)]], texture2d texB[[texture(0)]], sampler texBSmplr[[sampler(0)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) { Globals globalStruct{texA, texASmplr, texB, texBSmplr}; thread Globals* _globals = &globalStruct; diff --git a/tests/sksl/shared/golden/ComplexDelete.metal b/tests/sksl/shared/golden/ComplexDelete.metal index dd2c28328b..0701c4777d 100644 --- a/tests/sksl/shared/golden/ComplexDelete.metal +++ b/tests/sksl/shared/golden/ComplexDelete.metal @@ -14,6 +14,7 @@ struct Globals { sampler sSmplr; }; + fragment Outputs fragmentMain(Inputs _in [[stage_in]], constant Uniforms& _uniforms [[buffer(0)]], texture2d s[[texture(0)]], sampler sSmplr[[sampler(0)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) { Globals globalStruct{s, sSmplr}; thread Globals* _globals = &globalStruct; diff --git a/tests/sksl/shared/golden/GaussianBlur.metal b/tests/sksl/shared/golden/GaussianBlur.metal index 3ed8efc734..88554f5bd7 100644 --- a/tests/sksl/shared/golden/GaussianBlur.metal +++ b/tests/sksl/shared/golden/GaussianBlur.metal @@ -23,6 +23,7 @@ struct Globals { sampler uTextureSampler_0_Stage1Smplr; }; + float4 MatrixEffect_Stage1_c0_c0(thread Globals* _globals, float4 _input, float2 _coords) { float4 _0_TextureEffect_Stage1_c0_c0_c0; float2 _1_coords = (_globals->_anonInterface0->umatrix_Stage1_c0_c0 * float3(_coords, 1.0)).xy; diff --git a/tests/sksl/shared/golden/InterfaceBlockAnonymous.metal b/tests/sksl/shared/golden/InterfaceBlockAnonymous.metal index f70b4ee275..24bdc396e6 100644 --- a/tests/sksl/shared/golden/InterfaceBlockAnonymous.metal +++ b/tests/sksl/shared/golden/InterfaceBlockAnonymous.metal @@ -14,7 +14,8 @@ struct testBlock { }; struct Globals { constant testBlock* _anonInterface0; -};fragment Outputs fragmentMain(Inputs _in [[stage_in]], constant testBlock& _anonInterface0 [[buffer(789)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) { +}; +fragment Outputs fragmentMain(Inputs _in [[stage_in]], constant testBlock& _anonInterface0 [[buffer(789)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) { Globals globalStruct{&_anonInterface0}; thread Globals* _globals = &globalStruct; (void)_globals; diff --git a/tests/sksl/shared/golden/InterfaceBlockArray.metal b/tests/sksl/shared/golden/InterfaceBlockArray.metal index a4dbb31000..a28cc02cc8 100644 --- a/tests/sksl/shared/golden/InterfaceBlockArray.metal +++ b/tests/sksl/shared/golden/InterfaceBlockArray.metal @@ -11,7 +11,8 @@ struct testBlock { } test[2]; struct Globals { constant testBlock* test; -};fragment Outputs fragmentMain(Inputs _in [[stage_in]], constant testBlock& test [[buffer(123)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) { +}; +fragment Outputs fragmentMain(Inputs _in [[stage_in]], constant testBlock& test [[buffer(123)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) { Globals globalStruct{&test}; thread Globals* _globals = &globalStruct; (void)_globals; diff --git a/tests/sksl/shared/golden/InterfaceBlockNamed.metal b/tests/sksl/shared/golden/InterfaceBlockNamed.metal index eeb83064d4..fd7bb849ae 100644 --- a/tests/sksl/shared/golden/InterfaceBlockNamed.metal +++ b/tests/sksl/shared/golden/InterfaceBlockNamed.metal @@ -11,7 +11,8 @@ struct testBlock { } test; struct Globals { constant testBlock* test; -};fragment Outputs fragmentMain(Inputs _in [[stage_in]], constant testBlock& test [[buffer(456)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) { +}; +fragment Outputs fragmentMain(Inputs _in [[stage_in]], constant testBlock& test [[buffer(456)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) { Globals globalStruct{&test}; thread Globals* _globals = &globalStruct; (void)_globals; diff --git a/tests/sksl/shared/golden/NumberConversions.metal b/tests/sksl/shared/golden/NumberConversions.metal index 2bc41e0d20..1869dc624e 100644 --- a/tests/sksl/shared/golden/NumberConversions.metal +++ b/tests/sksl/shared/golden/NumberConversions.metal @@ -77,6 +77,7 @@ struct Globals { + fragment Outputs fragmentMain(Inputs _in [[stage_in]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) { diff --git a/tests/sksl/shared/golden/RectangleTexture.metal b/tests/sksl/shared/golden/RectangleTexture.metal index 029fd3c050..abd156a25e 100644 --- a/tests/sksl/shared/golden/RectangleTexture.metal +++ b/tests/sksl/shared/golden/RectangleTexture.metal @@ -13,6 +13,7 @@ struct Globals { sampler test2DRectSmplr; }; + fragment Outputs fragmentMain(Inputs _in [[stage_in]], texture2d test2D[[texture(0)]], sampler test2DSmplr[[sampler(0)]], texture2d test2DRect[[texture(1)]], sampler test2DRectSmplr[[sampler(1)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) { Globals globalStruct{test2D, test2DSmplr, test2DRect, test2DRectSmplr}; thread Globals* _globals = &globalStruct; diff --git a/tests/sksl/shared/golden/Structs.metal b/tests/sksl/shared/golden/Structs.metal index 687bd42b33..aceaa2a18e 100644 --- a/tests/sksl/shared/golden/Structs.metal +++ b/tests/sksl/shared/golden/Structs.metal @@ -20,6 +20,7 @@ struct Globals { B b1; }; + fragment Outputs fragmentMain(Inputs _in [[stage_in]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) { Globals globalStruct{{}, {}}; thread Globals* _globals = &globalStruct; diff --git a/tests/sksl/shared/golden/Texture2D.metal b/tests/sksl/shared/golden/Texture2D.metal index b570ed854e..91b00ec287 100644 --- a/tests/sksl/shared/golden/Texture2D.metal +++ b/tests/sksl/shared/golden/Texture2D.metal @@ -10,6 +10,7 @@ struct Globals { texture2d tex; sampler texSmplr; }; + fragment Outputs fragmentMain(Inputs _in [[stage_in]], texture2d tex[[texture(0)]], sampler texSmplr[[sampler(0)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) { Globals globalStruct{tex, texSmplr}; thread Globals* _globals = &globalStruct; diff --git a/tests/sksl/shared/golden/VectorConstructors.metal b/tests/sksl/shared/golden/VectorConstructors.metal index 66e76b6838..366fbf6d1f 100644 --- a/tests/sksl/shared/golden/VectorConstructors.metal +++ b/tests/sksl/shared/golden/VectorConstructors.metal @@ -21,6 +21,7 @@ struct Globals { + fragment Outputs fragmentMain(Inputs _in [[stage_in]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) { Globals globalStruct{float2(1.0), float2(1.0, 2.0), float2(1.0), float3(float2(1.0), 1.0), int2(1), int2(float2(1.0, 2.0)), float2(int2(1, 2))}; thread Globals* _globals = &globalStruct;