mirror of
https://github.com/RPCS3/glslang.git
synced 2025-02-25 13:23:12 +00:00
Merge pull request #1515 from Igalia/more-location-command-line-options
Enhancement: add extra command line options that modifies aml
This commit is contained in:
commit
2f78b9c742
@ -173,6 +173,9 @@ std::vector<std::string> Processes; // what should be record
|
||||
// Per descriptor-set binding base data
|
||||
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;
|
||||
std::array<std::vector<std::string>, EShLangCount> baseResourceSetBinding;
|
||||
@ -431,6 +434,22 @@ void ProcessArguments(std::vector<std::unique_ptr<glslang::TWorkItem>>& workItem
|
||||
Options &= ~EOptionVulkanRules;
|
||||
};
|
||||
|
||||
const auto getUniformOverride = [getStringOperand]() {
|
||||
const char *arg = getStringOperand("-u<name>:<location>");
|
||||
const char *split = strchr(arg, ':');
|
||||
if (split == NULL) {
|
||||
printf("%s: missing location\n", arg);
|
||||
exit(EFailUsage);
|
||||
}
|
||||
errno = 0;
|
||||
int location = ::strtol(split + 1, NULL, 10);
|
||||
if (errno) {
|
||||
printf("%s: invalid location\n", arg);
|
||||
exit(EFailUsage);
|
||||
}
|
||||
return std::make_pair(std::string(arg, split - arg), location);
|
||||
};
|
||||
|
||||
for (bumpArg(); argc >= 1; bumpArg()) {
|
||||
if (argv[0][0] == '-') {
|
||||
switch (argv[0][1]) {
|
||||
@ -447,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)
|
||||
@ -572,6 +597,9 @@ void ProcessArguments(std::vector<std::unique_ptr<glslang::TWorkItem>>& workItem
|
||||
else
|
||||
UserPreamble.addDef(getStringOperand("-D<macro> macro name"));
|
||||
break;
|
||||
case 'u':
|
||||
uniformLocationOverrides.push_back(getUniformOverride());
|
||||
break;
|
||||
case 'E':
|
||||
Options |= EOptionOutputPreprocessed;
|
||||
break;
|
||||
@ -898,6 +926,13 @@ void CompileAndLinkShaderUnits(std::vector<ShaderCompUnit> compUnits)
|
||||
if (Options & EOptionInvertY)
|
||||
shader->setInvertY(true);
|
||||
|
||||
for (auto& uniOverride : uniformLocationOverrides) {
|
||||
shader->addUniformLocationOverride(uniOverride.first.c_str(),
|
||||
uniOverride.second);
|
||||
}
|
||||
|
||||
shader->setUniformLocationBase(uniformBase);
|
||||
|
||||
// Set up the environment, some subsettings take precedence over earlier
|
||||
// ways of setting things.
|
||||
if (Options & EOptionSpv) {
|
||||
@ -1417,6 +1452,8 @@ void usage()
|
||||
" -w | --suppress-warnings\n"
|
||||
" 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"
|
||||
|
@ -1759,6 +1759,14 @@ void TShader::setAutoMapBindings(bool map) { intermediate->setAutoM
|
||||
void TShader::setInvertY(bool invert) { intermediate->setInvertY(invert); }
|
||||
// Fragile: currently within one stage: simple auto-assignment of location
|
||||
void TShader::setAutoMapLocations(bool map) { intermediate->setAutoMapLocations(map); }
|
||||
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); }
|
||||
|
@ -359,7 +359,7 @@ struct TDefaultIoResolverBase : public glslang::TIoMapResolver
|
||||
{
|
||||
TDefaultIoResolverBase(const TIntermediate &intermediate) :
|
||||
intermediate(intermediate),
|
||||
nextUniformLocation(0),
|
||||
nextUniformLocation(intermediate.getUniformLocationBase()),
|
||||
nextInputLocation(0),
|
||||
nextOutputLocation(0)
|
||||
{ }
|
||||
@ -434,7 +434,7 @@ struct TDefaultIoResolverBase : public glslang::TIoMapResolver
|
||||
|
||||
return 0;
|
||||
}
|
||||
int resolveUniformLocation(EShLanguage /*stage*/, const char* /*name*/, const glslang::TType& type, bool /*is_live*/) override
|
||||
int resolveUniformLocation(EShLanguage /*stage*/, const char* name, const glslang::TType& type, bool /*is_live*/) override
|
||||
{
|
||||
// kick out of not doing this
|
||||
if (!doAutoLocationMapping())
|
||||
@ -455,7 +455,11 @@ struct TDefaultIoResolverBase : public glslang::TIoMapResolver
|
||||
return -1;
|
||||
}
|
||||
|
||||
int location = nextUniformLocation;
|
||||
int location = intermediate.getUniformLocationOverride(name);
|
||||
if (location != -1)
|
||||
return location;
|
||||
|
||||
location = nextUniformLocation;
|
||||
|
||||
nextUniformLocation += TIntermediate::computeTypeUniformLocationSize(type);
|
||||
|
||||
|
@ -252,7 +252,8 @@ public:
|
||||
hlslIoMapping(false),
|
||||
textureSamplerTransformMode(EShTexSampTransKeep),
|
||||
needToLegalize(false),
|
||||
binaryDoubleOutput(false)
|
||||
binaryDoubleOutput(false),
|
||||
uniformLocationBase(0)
|
||||
{
|
||||
localSize[0] = 1;
|
||||
localSize[1] = 1;
|
||||
@ -671,6 +672,23 @@ public:
|
||||
void addProcessArgument(const std::string& arg) { processes.addArgument(arg); }
|
||||
const std::vector<std::string>& getProcesses() const { return processes.getProcesses(); }
|
||||
|
||||
void addUniformLocationOverride(const TString& name, int location)
|
||||
{
|
||||
uniformLocationOverrides[name] = location;
|
||||
}
|
||||
|
||||
int getUniformLocationOverride(const TString& name) const
|
||||
{
|
||||
auto pos = uniformLocationOverrides.find(name);
|
||||
if (pos == uniformLocationOverrides.end())
|
||||
return -1;
|
||||
else
|
||||
return pos->second;
|
||||
}
|
||||
|
||||
void setUniformLocationBase(int base) { uniformLocationBase = base; }
|
||||
int getUniformLocationBase() const { return uniformLocationBase; }
|
||||
|
||||
void setNeedsLegalization() { needToLegalize = true; }
|
||||
bool needsLegalization() const { return needToLegalize; }
|
||||
|
||||
@ -796,6 +814,9 @@ protected:
|
||||
bool needToLegalize;
|
||||
bool binaryDoubleOutput;
|
||||
|
||||
std::unordered_map<TString, int> uniformLocationOverrides;
|
||||
int uniformLocationBase;
|
||||
|
||||
private:
|
||||
void operator=(TIntermediate&); // prevent assignments
|
||||
};
|
||||
|
@ -413,6 +413,8 @@ public:
|
||||
void setResourceSetBinding(const std::vector<std::string>& base);
|
||||
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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user