Only unroll matrices for vertex input.

Bandaid, might have to revisit this later.
This commit is contained in:
Hans-Kristian Arntzen 2017-10-05 16:31:52 +02:00
parent 03861274af
commit eb58f67727
5 changed files with 73 additions and 2 deletions

View File

@ -0,0 +1,26 @@
static float4 FragColor;
static float4x4 m;
struct SPIRV_Cross_Input
{
float4x4 m : TEXCOORD1;
};
struct SPIRV_Cross_Output
{
float4 FragColor : SV_Target0;
};
void frag_main()
{
FragColor = ((m[0] + m[1]) + m[2]) + m[3];
}
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
{
m = stage_input.m;
frag_main();
SPIRV_Cross_Output stage_output;
stage_output.FragColor = FragColor;
return stage_output;
}

View File

@ -0,0 +1,23 @@
static float4 gl_Position;
static float4x4 m;
struct SPIRV_Cross_Output
{
float4x4 m : TEXCOORD0;
float4 gl_Position : SV_Position;
};
void vert_main()
{
gl_Position = float4(1.0f, 1.0f, 1.0f, 1.0f);
m = float4x4(float4(1.0f, 0.0f, 0.0f, 0.0f), float4(0.0f, 1.0f, 0.0f, 0.0f), float4(0.0f, 0.0f, 1.0f, 0.0f), float4(0.0f, 0.0f, 0.0f, 1.0f));
}
SPIRV_Cross_Output main()
{
vert_main();
SPIRV_Cross_Output stage_output;
stage_output.gl_Position = gl_Position;
stage_output.m = m;
return stage_output;
}

View File

@ -0,0 +1,9 @@
#version 450
layout(location = 0) out vec4 FragColor;
layout(location = 1) in mat4 m;
void main()
{
FragColor = m[0] + m[1] + m[2] + m[3];
}

View File

@ -0,0 +1,9 @@
#version 450
layout(location = 0) out mat4 m;
void main()
{
gl_Position = vec4(1.0);
m = mat4(1.0);
}

View File

@ -518,6 +518,8 @@ void CompilerHLSL::emit_interface_block_in_struct(const SPIRVariable &var, unord
SPIRV_CROSS_THROW("All locations from 0 to 63 are exhausted.");
};
bool need_matrix_unroll = var.storage == StorageClassInput && execution.model == ExecutionModelVertex;
auto &m = meta[var.self].decoration;
auto name = to_name(var.self);
if (use_binding_number)
@ -531,7 +533,7 @@ void CompilerHLSL::emit_interface_block_in_struct(const SPIRVariable &var, unord
else
binding_number = get_vacant_location();
if (type.columns > 1)
if (need_matrix_unroll && type.columns > 1)
{
if (!type.array.empty())
SPIRV_CROSS_THROW("Arrays of matrices used as input/output. This is not supported.");
@ -1277,12 +1279,14 @@ void CompilerHLSL::emit_hlsl_entry_point()
if (var.storage != StorageClassInput)
continue;
bool need_matrix_unroll = var.storage == StorageClassInput && execution.model == ExecutionModelVertex;
if (!block && !var.remapped_variable && type.pointer && !is_builtin_variable(var) &&
interface_variable_exists_in_entry_point(var.self))
{
auto name = to_name(var.self);
auto &mtype = get<SPIRType>(var.basetype);
if (mtype.columns > 1)
if (need_matrix_unroll && mtype.columns > 1)
{
// Unroll matrices.
for (uint32_t col = 0; col < mtype.columns; col++)