diff options
author | Hans-Kristian Arntzen <post@arntzen-software.no> | 2022-10-26 18:42:48 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-26 18:42:48 +0300 |
commit | 3ea057a303969da7d76d6f35bf3f2811e8f29da2 (patch) | |
tree | 822497c8e46e6254204d25236239757e44069ae2 | |
parent | 0851baf9ee12f95d74d3bdd051f108b8a4b1a366 (diff) | |
parent | 47c7fc16eb4f9294eb89e1bb8595565046fe9559 (diff) |
Merge pull request #2045 from KhronosGroup/fix-2037
HLSL: Add option to bind vertex input smemantics by name.
-rw-r--r-- | main.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
@@ -613,6 +613,12 @@ struct InterfaceVariableRename string variable_name; }; +struct HLSLVertexAttributeRemapNamed +{ + std::string name; + std::string semantic; +}; + struct CLIArguments { const char *input = nullptr; @@ -692,6 +698,7 @@ struct CLIArguments SmallVector<VariableTypeRemap> variable_type_remaps; SmallVector<InterfaceVariableRename> interface_variable_renames; SmallVector<HLSLVertexAttributeRemap> hlsl_attr_remap; + SmallVector<HLSLVertexAttributeRemapNamed> hlsl_attr_remap_named; SmallVector<std::pair<uint32_t, uint32_t>> masked_stage_outputs; SmallVector<BuiltIn> masked_stage_builtins; string entry; @@ -824,6 +831,8 @@ static void print_help_hlsl() "\t\tShader must ensure that read/write state is consistent at all call sites.\n" "\t[--set-hlsl-vertex-input-semantic <location> <semantic>]:\n\t\tEmits a specific vertex input semantic for a given location.\n" "\t\tOtherwise, TEXCOORD# is used as semantics, where # is location.\n" + "\t[--set-hlsl-named-vertex-input-semantic <name> <semantic>]:\n\t\tEmits a specific vertex input semantic for a given name.\n" + "\t\tOpName reflection information must be intact.\n" "\t[--hlsl-enable-16bit-types]:\n\t\tEnables native use of half/int16_t/uint16_t and ByteAddressBuffer interaction with these types. Requires SM 6.2.\n" "\t[--hlsl-flatten-matrix-vertex-input-semantics]:\n\t\tEmits matrix vertex inputs with input semantics as if they were independent vectors, e.g. TEXCOORD{2,3,4} rather than matrix form TEXCOORD2_{0,1,2}.\n" ); @@ -1485,6 +1494,22 @@ static string compile_iteration(const CLIArguments &args, std::vector<uint32_t> { for (auto &remap : args.hlsl_attr_remap) static_cast<CompilerHLSL *>(compiler.get())->add_vertex_attribute_remap(remap); + + for (auto &named_remap : args.hlsl_attr_remap_named) + { + auto itr = std::find_if(res.stage_inputs.begin(), res.stage_inputs.end(), [&](const Resource &input_res) { + return input_res.name == named_remap.name; + }); + + if (itr != res.stage_inputs.end()) + { + HLSLVertexAttributeRemap remap = { + compiler->get_decoration(itr->id, DecorationLocation), + named_remap.semantic, + }; + static_cast<CompilerHLSL *>(compiler.get())->add_vertex_attribute_remap(remap); + } + } } auto ret = compiler->compile(); @@ -1745,6 +1770,12 @@ static int main_inner(int argc, char *argv[]) remap.semantic = parser.next_string(); args.hlsl_attr_remap.push_back(std::move(remap)); }); + cbs.add("--set-hlsl-named-vertex-input-semantic", [&args](CLIParser &parser) { + HLSLVertexAttributeRemapNamed remap; + remap.name = parser.next_string(); + remap.semantic = parser.next_string(); + args.hlsl_attr_remap_named.push_back(std::move(remap)); + }); cbs.add("--remap", [&args](CLIParser &parser) { string src = parser.next_string(); |