Support row-major matrices in access chain when not natively supported by backend (MSL).

This commit is contained in:
Bill Hollings 2016-12-11 11:01:08 -05:00
Родитель 875c32fd39
Коммит 343677e639
3 изменённых файлов: 39 добавлений и 0 удалений

Просмотреть файл

@ -3040,6 +3040,7 @@ string CompilerGLSL::access_chain(uint32_t base, const uint32_t *indices, uint32
SPIRType temp;
bool access_chain_is_arrayed = false;
bool mtx_needs_transp = matrix_needs_transposition(base);
for (uint32_t i = 0; i < count; i++)
{
@ -3092,11 +3093,18 @@ string CompilerGLSL::access_chain(uint32_t base, const uint32_t *indices, uint32
expr += ".";
expr += to_member_name(*type, index);
}
mtx_needs_transp = member_matrix_needs_transposition(*type, index);
type = &get<SPIRType>(type->member_types[index]);
}
// Matrix -> Vector
else if (type->columns > 1)
{
if (mtx_needs_transp)
{
expr = transpose(expr);
mtx_needs_transp = false;
}
expr += "[";
if (index_is_literal)
expr += convert_to_string(index);
@ -3141,6 +3149,9 @@ string CompilerGLSL::access_chain(uint32_t base, const uint32_t *indices, uint32
throw CompilerError("Cannot subdivide a scalar value!");
}
if (mtx_needs_transp)
expr = transpose(expr);
return expr;
}
@ -4736,6 +4747,27 @@ void CompilerGLSL::add_member_name(SPIRType &type, uint32_t index)
}
}
// Checks whether the member is a row_major matrix that requires transposition before use
bool CompilerGLSL::matrix_needs_transposition(uint32_t id)
{
return (backend.transpose_row_major_matrices &&
(meta[id].decoration.decoration_flags & (1ull << DecorationRowMajor)));
}
// Checks whether the member is a row_major matrix that requires transposition before use
bool CompilerGLSL::member_matrix_needs_transposition(const SPIRType &type, uint32_t index)
{
return (backend.transpose_row_major_matrices &&
(combined_decoration_for_member(type, index) & (1ull << DecorationRowMajor)));
}
// Wraps the expression in a transpose() function call
string CompilerGLSL::transpose(string exp_str)
{
strip_enclosed_expression(exp_str);
return join("transpose(", exp_str, ")");
}
string CompilerGLSL::variable_decl(const SPIRType &type, const string &name)
{
string type_name = type_to_glsl(type);

Просмотреть файл

@ -223,6 +223,11 @@ protected:
void add_local_variable_name(uint32_t id);
void add_resource_name(uint32_t id);
void add_member_name(SPIRType &type, uint32_t name);
bool matrix_needs_transposition(uint32_t id);
bool member_matrix_needs_transposition(const SPIRType &type, uint32_t index);
virtual std::string transpose(std::string exp_str);
std::unordered_set<std::string> local_variable_names;
std::unordered_set<std::string> resource_names;
@ -244,6 +249,7 @@ protected:
bool flexible_member_array_supported = true;
bool explicit_struct_type = false;
bool use_initializer_list = false;
bool transpose_row_major_matrices = false;
} backend;
void emit_struct(SPIRType &type);

Просмотреть файл

@ -64,6 +64,7 @@ string CompilerMSL::compile(MSLConfiguration &msl_cfg, vector<MSLVertexAttr> *p_
backend.discard_literal = "discard_fragment()";
backend.swizzle_is_function = false;
backend.shared_is_implied = false;
backend.transpose_row_major_matrices = true;
uint32_t pass_count = 0;
do