Add overload compile method for hlsl with vertex attribute remap.
This adds remap to semantic and semantic_index as HLSL instead of always binding to TEXCOORD + binding_number.
This commit is contained in:
Родитель
997be5cb23
Коммит
7216d13620
|
@ -666,6 +666,23 @@ void CompilerHLSL::emit_interface_block_in_struct(const SPIRVariable &var, unord
|
|||
else
|
||||
binding_number = get_vacant_location();
|
||||
|
||||
// Allow semantic remap if specified.
|
||||
string semantic = "TEXCOORD";
|
||||
uint32_t semantic_index = binding_number;
|
||||
|
||||
if (vertex_attributes.size())
|
||||
{
|
||||
for (auto &attribute : vertex_attributes)
|
||||
{
|
||||
if (attribute.name == name)
|
||||
{
|
||||
semantic = attribute.semantic;
|
||||
semantic_index = attribute.semantic_index;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (need_matrix_unroll && type.columns > 1)
|
||||
{
|
||||
if (!type.array.empty())
|
||||
|
@ -677,14 +694,14 @@ void CompilerHLSL::emit_interface_block_in_struct(const SPIRVariable &var, unord
|
|||
SPIRType newtype = type;
|
||||
newtype.columns = 1;
|
||||
statement(to_interpolation_qualifiers(get_decoration_mask(var.self)),
|
||||
variable_decl(newtype, join(name, "_", i)), " : TEXCOORD", binding_number, ";");
|
||||
variable_decl(newtype, join(name, "_", i)), " : ", semantic, semantic_index, binding_number, ";");
|
||||
active_locations.insert(binding_number++);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
statement(to_interpolation_qualifiers(get_decoration_mask(var.self)), variable_decl(type, name),
|
||||
" : TEXCOORD", binding_number, ";");
|
||||
" : ", semantic, semantic_index, binding_number, ";");
|
||||
|
||||
// Structs and arrays should consume more locations.
|
||||
uint32_t consumed_locations = type_to_consumed_locations(type);
|
||||
|
@ -3144,6 +3161,18 @@ void CompilerHLSL::require_texture_query_variant(const SPIRType &type)
|
|||
}
|
||||
}
|
||||
|
||||
string CompilerHLSL::compile(std::vector<HLSLVertexAttr> *p_vertex_attributes)
|
||||
{
|
||||
if (p_vertex_attributes)
|
||||
{
|
||||
vertex_attributes.clear();
|
||||
for (auto &va : *p_vertex_attributes)
|
||||
vertex_attributes.emplace_back(va);
|
||||
}
|
||||
|
||||
return compile();
|
||||
}
|
||||
|
||||
string CompilerHLSL::compile()
|
||||
{
|
||||
// Do not deal with ES-isms like precision, older extensions and such.
|
||||
|
|
|
@ -23,6 +23,13 @@
|
|||
|
||||
namespace spirv_cross
|
||||
{
|
||||
struct HLSLVertexAttr
|
||||
{
|
||||
std::string name;
|
||||
std::string semantic;
|
||||
uint32_t semantic_index;
|
||||
};
|
||||
|
||||
class CompilerHLSL : public CompilerGLSL
|
||||
{
|
||||
public:
|
||||
|
@ -54,6 +61,7 @@ public:
|
|||
options = opts;
|
||||
}
|
||||
|
||||
std::string compile(std::vector<HLSLVertexAttr> *p_vertex_attributes);
|
||||
std::string compile() override;
|
||||
|
||||
private:
|
||||
|
@ -133,6 +141,7 @@ private:
|
|||
void emit_builtin_variables();
|
||||
bool require_output = false;
|
||||
bool require_input = false;
|
||||
std::vector<HLSLVertexAttr> vertex_attributes;
|
||||
|
||||
uint32_t type_to_consumed_locations(const SPIRType &type) const;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче