added --rename-interface-variable <in|out> <location> <new_variable_name>
This commit is contained in:
parent
f5fd965fa0
commit
9f1eb5a20d
@ -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");
|
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 source to legacy GLSL/ESSL
|
||||||
|
|
||||||
HLSL tends to emit varying struct types to pass data between vertex and fragment.
|
HLSL tends to emit varying struct types to pass data between vertex and fragment.
|
||||||
|
25
main.cpp
25
main.cpp
@ -438,6 +438,7 @@ struct CLIArguments
|
|||||||
vector<Remap> remaps;
|
vector<Remap> remaps;
|
||||||
vector<string> extensions;
|
vector<string> extensions;
|
||||||
vector<VariableTypeRemap> variable_type_remaps;
|
vector<VariableTypeRemap> variable_type_remaps;
|
||||||
|
vector<InterfaceVariableRename> interface_variable_renames;
|
||||||
string entry;
|
string entry;
|
||||||
|
|
||||||
uint32_t iterations = 1;
|
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 "
|
"[--pls-in format input-name] [--pls-out format output-name] [--remap source_name target_name "
|
||||||
"components] [--extension ext] [--entry name] [--remove-unused-variables] "
|
"components] [--extension ext] [--entry name] [--remove-unused-variables] "
|
||||||
"[--flatten-multidimensional-arrays] "
|
"[--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)
|
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) });
|
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) {
|
cbs.add("--pls-in", [&args](CLIParser &parser) {
|
||||||
auto fmt = pls_format(parser.next_string());
|
auto fmt = pls_format(parser.next_string());
|
||||||
auto name = parser.next_string();
|
auto name = parser.next_string();
|
||||||
@ -758,6 +768,19 @@ int main(int argc, char *argv[])
|
|||||||
continue;
|
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)
|
if (args.dump_resources)
|
||||||
{
|
{
|
||||||
print_resources(*compiler, res);
|
print_resources(*compiler, res);
|
||||||
|
@ -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()
|
void CompilerGLSL::find_static_extensions()
|
||||||
{
|
{
|
||||||
for (auto &id : ids)
|
for (auto &id : ids)
|
||||||
|
@ -51,6 +51,13 @@ struct PlsRemap
|
|||||||
PlsFormat format;
|
PlsFormat format;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct InterfaceVariableRename
|
||||||
|
{
|
||||||
|
std::string in_or_out;
|
||||||
|
uint32_t location;
|
||||||
|
std::string variable_name;
|
||||||
|
};
|
||||||
|
|
||||||
class CompilerGLSL : public Compiler
|
class CompilerGLSL : public Compiler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -109,6 +116,8 @@ public:
|
|||||||
remap_pls_variables();
|
remap_pls_variables();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void rename_interface_variable(const std::vector<Resource> &resources, const InterfaceVariableRename &rename);
|
||||||
|
|
||||||
CompilerGLSL(std::vector<uint32_t> spirv_)
|
CompilerGLSL(std::vector<uint32_t> spirv_)
|
||||||
: Compiler(move(spirv_))
|
: Compiler(move(spirv_))
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user