Add an option to set the base uniform location
authorNeil Roberts <nroberts@igalia.com>
Tue, 20 Mar 2018 16:41:05 +0000 (17:41 +0100)
committerAlejandro Piñeiro <apinheiro@igalia.com>
Tue, 2 Oct 2018 10:15:22 +0000 (12:15 +0200)
This will be used to generate uniform locations with --aml

StandAlone/StandAlone.cpp
glslang/MachineIndependent/ShaderLang.cpp
glslang/MachineIndependent/iomapper.cpp
glslang/MachineIndependent/localintermediate.h
glslang/Public/ShaderLang.h

index e15994b..48fcb7f 100644 (file)
@@ -174,6 +174,7 @@ std::vector<std::string> Processes;                     // what should be record
 typedef std::map<unsigned int, unsigned int> TPerSetBaseBinding;
 
 std::vector<std::pair<std::string, int>> uniformLocationOverrides;
+int uniformBase = 0;
 
 std::array<std::array<unsigned int, EShLangCount>, glslang::EResCount> baseBinding;
 std::array<std::array<TPerSetBaseBinding, EShLangCount>, glslang::EResCount> baseBindingForSet;
@@ -465,6 +466,12 @@ void ProcessArguments(std::vector<std::unique_ptr<glslang::TWorkItem>>& workItem
                     } else if (lowerword == "auto-map-locations" || // synonyms
                                lowerword == "aml") {
                         Options |= EOptionAutoMapLocations;
+                    } else if (lowerword == "uniform-base") {
+                        if (argc <= 1)
+                            Error("no <base> provided for --uniform-base");
+                        uniformBase = ::strtol(argv[1], NULL, 10);
+                        bumpArg();
+                        break;
                     } else if (lowerword == "client") {
                         if (argc > 1) {
                             if (strcmp(argv[1], "vulkan100") == 0)
@@ -924,6 +931,8 @@ void CompileAndLinkShaderUnits(std::vector<ShaderCompUnit> compUnits)
                                                uniOverride.second);
         }
 
+        shader->setUniformLocationBase(uniformBase);
+
         // Set up the environment, some subsettings take precedence over earlier
         // ways of setting things.
         if (Options & EOptionSpv) {
@@ -1444,6 +1453,7 @@ void usage()
            "              suppress GLSL warnings, except as required by \"#extension : warn\"\n"
            "  -x          save binary output as text-based 32-bit hexadecimal numbers\n"
            "  -u<name>:<loc> specify a uniform location override for --aml\n"
+           "  --uniform-base <base> set a base to use for generated uniform locations\n"
            "  --auto-map-bindings | --amb       automatically bind uniform variables\n"
            "                                    without explicit bindings\n"
            "  --auto-map-locations | --aml      automatically locate input/output lacking\n"
index 1a30fd3..522ded1 100755 (executable)
@@ -1763,6 +1763,10 @@ void TShader::addUniformLocationOverride(const char* name, int loc)
 {
     intermediate->addUniformLocationOverride(name, loc);
 }
+void TShader::setUniformLocationBase(int base)
+{
+    intermediate->setUniformLocationBase(base);
+}
 // See comment above TDefaultHlslIoMapper in iomapper.cpp:
 void TShader::setHlslIoMapping(bool hlslIoMap)          { intermediate->setHlslIoMapping(hlslIoMap); }
 void TShader::setFlattenUniformArrays(bool flatten)     { intermediate->setFlattenUniformArrays(flatten); }
index 73ea801..e68e32f 100644 (file)
@@ -359,7 +359,7 @@ struct TDefaultIoResolverBase : public glslang::TIoMapResolver
 {
     TDefaultIoResolverBase(const TIntermediate &intermediate) :
         intermediate(intermediate),
-        nextUniformLocation(0),
+        nextUniformLocation(intermediate.getUniformLocationBase()),
         nextInputLocation(0),
         nextOutputLocation(0)
     { }
index a95e26f..59fbaa9 100644 (file)
@@ -252,7 +252,8 @@ public:
         hlslIoMapping(false),
         textureSamplerTransformMode(EShTexSampTransKeep),
         needToLegalize(false),
-        binaryDoubleOutput(false)
+        binaryDoubleOutput(false),
+        uniformLocationBase(0)
     {
         localSize[0] = 1;
         localSize[1] = 1;
@@ -685,6 +686,9 @@ public:
                     return pos->second;
     }
 
+    void setUniformLocationBase(int base) { uniformLocationBase = base; }
+    int getUniformLocationBase() const { return uniformLocationBase; }
+
     void setNeedsLegalization() { needToLegalize = true; }
     bool needsLegalization() const { return needToLegalize; }
 
@@ -811,6 +815,7 @@ protected:
     bool binaryDoubleOutput;
 
     std::unordered_map<TString, int> uniformLocationOverrides;
+    int uniformLocationBase;
 
 private:
     void operator=(TIntermediate&); // prevent assignments
index cd9f25e..74ab352 100644 (file)
@@ -414,6 +414,7 @@ public:
     void setAutoMapBindings(bool map);
     void setAutoMapLocations(bool map);
     void addUniformLocationOverride(const char* name, int loc);
+    void setUniformLocationBase(int base);
     void setInvertY(bool invert);
     void setHlslIoMapping(bool hlslIoMap);
     void setFlattenUniformArrays(bool flatten);