added --rename-interface-variable <in|out> <location> <new_variable_name>

This commit is contained in:
Jason Chan 2017-06-23 22:20:42 +02:00
parent f5fd965fa0
commit 9f1eb5a20d
4 changed files with 55 additions and 1 deletions

View File

@ -173,6 +173,12 @@ You can make use of the reflection interface to force the name of the struct typ
compiler.set_name(varying_resource.base_type_id, "VertexFragmentLinkage");
```
Some platform may require identical variable name for both vertex outputs and fragment inputs. (for example MacOSX)
to rename varaible base on location, please add
```
--rename-interface-variable <in|out> <location> <new_variable_name>
```
#### HLSL source to legacy GLSL/ESSL
HLSL tends to emit varying struct types to pass data between vertex and fragment.

View File

@ -438,6 +438,7 @@ struct CLIArguments
vector<Remap> remaps;
vector<string> extensions;
vector<VariableTypeRemap> variable_type_remaps;
vector<InterfaceVariableRename> interface_variable_renames;
string entry;
uint32_t iterations = 1;
@ -463,7 +464,9 @@ static void print_help()
"[--pls-in format input-name] [--pls-out format output-name] [--remap source_name target_name "
"components] [--extension ext] [--entry name] [--remove-unused-variables] "
"[--flatten-multidimensional-arrays] "
"[--remap-variable-type <variable_name> <new_variable_type>]\n");
"[--remap-variable-type <variable_name> <new_variable_type>]"
"[--rename-interface-variable <in|out> <location> <new_variable_name>]"
"\n");
}
static bool remap_generic(Compiler &compiler, const vector<Resource> &resources, const Remap &remap)
@ -602,6 +605,13 @@ int main(int argc, char *argv[])
args.variable_type_remaps.push_back({ move(var_name), move(new_type) });
});
cbs.add("--rename-interface-variable", [&args](CLIParser &parser) {
string in_or_out = parser.next_string();
uint32_t loc = parser.next_uint();
string var_name = parser.next_string();
args.interface_variable_renames.push_back({ move(in_or_out), loc, move(var_name) });
});
cbs.add("--pls-in", [&args](CLIParser &parser) {
auto fmt = pls_format(parser.next_string());
auto name = parser.next_string();
@ -758,6 +768,19 @@ int main(int argc, char *argv[])
continue;
}
for (auto &rename : args.interface_variable_renames)
{
if (rename.in_or_out == "in")
compiler->rename_interface_variable(res.stage_inputs, rename);
else if (rename.in_or_out == "out")
compiler->rename_interface_variable(res.stage_outputs, rename);
else
{
fprintf(stderr, "error at --rename-interface-variable %s, acceptable options are [in,out]\n", rename.in_or_out.c_str());
return EXIT_FAILURE;
}
}
if (args.dump_resources)
{
print_resources(*compiler, res);

View File

@ -237,6 +237,22 @@ void CompilerGLSL::remap_pls_variables()
}
}
void CompilerGLSL::rename_interface_variable(const vector<Resource> &resources, const InterfaceVariableRename &rename)
{
for (auto &v : resources)
{
if (!has_decoration(v.id, spv::DecorationLocation))
continue;
auto loc = meta[v.id].decoration.location;
if (loc != rename.location)
continue;
printf("rename %s %d %s", rename.in_or_out.c_str(), rename.location, rename.variable_name.c_str());
set_name(v.id, rename.variable_name);
}
}
void CompilerGLSL::find_static_extensions()
{
for (auto &id : ids)

View File

@ -51,6 +51,13 @@ struct PlsRemap
PlsFormat format;
};
struct InterfaceVariableRename
{
std::string in_or_out;
uint32_t location;
std::string variable_name;
};
class CompilerGLSL : public Compiler
{
public:
@ -109,6 +116,8 @@ public:
remap_pls_variables();
}
void rename_interface_variable(const std::vector<Resource> &resources, const InterfaceVariableRename &rename);
CompilerGLSL(std::vector<uint32_t> spirv_)
: Compiler(move(spirv_))
{