No longer using default Globals constructor in Metal shader code
Bug: skia:9736
Change-Id: If572ddae3c6aa42faa498b2fe3bf2fa25fd00bf1
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/261276
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
diff --git a/src/sksl/SkSLMetalCodeGenerator.cpp b/src/sksl/SkSLMetalCodeGenerator.cpp
index 641e4c0..66f73df 100644
--- a/src/sksl/SkSLMetalCodeGenerator.cpp
+++ b/src/sksl/SkSLMetalCodeGenerator.cpp
@@ -917,37 +917,31 @@
if ("main" == f.fDeclaration.fName) {
if (fNeedsGlobalStructInit) {
- this->writeLine(" Globals globalStruct;");
- this->writeLine(" thread Globals* _globals = &globalStruct;");
+ this->writeLine(" Globals globalStruct{");
+ const char* separator = "";
for (const auto& intf: fInterfaceBlockNameMap) {
const auto& intfName = intf.second;
- this->write(" _globals->");
+ this->write(separator);
+ separator = ", ";
+ this->write("&");
this->writeName(intfName);
- this->write(" = &");
- this->writeName(intfName);
- this->write(";\n");
}
for (const auto& var: fInitNonConstGlobalVars) {
- this->write(" _globals->");
- this->writeName(var->fVar->fName);
- this->write(" = ");
+ this->write(separator);
+ separator = ", ";
this->writeVarInitializer(*var->fVar, *var->fValue);
- this->writeLine(";");
}
for (const auto& texture: fTextures) {
- this->write(" _globals->");
+ this->write(separator);
+ separator = ", ";
this->writeName(texture->fName);
- this->write(" = ");
- this->writeName(texture->fName);
- this->write(";\n");
- this->write(" _globals->");
+ this->write(separator);
this->writeName(texture->fName);
this->write(SAMPLER_SUFFIX);
- this->write(" = ");
- this->writeName(texture->fName);
- this->write(SAMPLER_SUFFIX);
- this->write(";\n");
}
+ this->writeLine("};");
+ this->writeLine(" thread Globals* _globals = &globalStruct;");
+ this->writeLine(" (void)_globals;");
}
this->writeLine(" Outputs _outputStruct;");
this->writeLine(" thread Outputs* _out = &_outputStruct;");