diff --git a/reference/opt/shaders-hlsl/vert/struct-composite-decl.vert b/reference/opt/shaders-hlsl/vert/struct-composite-decl.vert new file mode 100644 index 0000000..76bd349 --- /dev/null +++ b/reference/opt/shaders-hlsl/vert/struct-composite-decl.vert @@ -0,0 +1,44 @@ +struct VOut +{ + float4 a; + float4 b; + float4 c; + float4 d; +}; + +static VOut vout; +static float4 a; +static float4 b; +static float4 c; +static float4 d; + +struct SPIRV_Cross_Input +{ + float4 a : TEXCOORD0; + float4 b : TEXCOORD1; + float4 c : TEXCOORD2; + float4 d : TEXCOORD3; +}; + +struct SPIRV_Cross_Output +{ + VOut vout : TEXCOORD0; +}; + +void vert_main() +{ + VOut _26 = { a, b, c, d }; + vout = _26; +} + +SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) +{ + a = stage_input.a; + b = stage_input.b; + c = stage_input.c; + d = stage_input.d; + vert_main(); + SPIRV_Cross_Output stage_output; + stage_output.vout = vout; + return stage_output; +} diff --git a/reference/shaders-hlsl/vert/struct-composite-decl.vert b/reference/shaders-hlsl/vert/struct-composite-decl.vert new file mode 100644 index 0000000..5b2c582 --- /dev/null +++ b/reference/shaders-hlsl/vert/struct-composite-decl.vert @@ -0,0 +1,50 @@ +struct VOut +{ + float4 a; + float4 b; + float4 c; + float4 d; +}; + +static VOut vout; +static float4 a; +static float4 b; +static float4 c; +static float4 d; + +struct SPIRV_Cross_Input +{ + float4 a : TEXCOORD0; + float4 b : TEXCOORD1; + float4 c : TEXCOORD2; + float4 d : TEXCOORD3; +}; + +struct SPIRV_Cross_Output +{ + VOut vout : TEXCOORD0; +}; + +void emit_result(VOut v) +{ + vout = v; +} + +void vert_main() +{ + VOut _26 = { a, b, c, d }; + VOut param = _26; + emit_result(param); +} + +SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) +{ + a = stage_input.a; + b = stage_input.b; + c = stage_input.c; + d = stage_input.d; + vert_main(); + SPIRV_Cross_Output stage_output; + stage_output.vout = vout; + return stage_output; +} diff --git a/shaders-hlsl/vert/struct-composite-decl.vert b/shaders-hlsl/vert/struct-composite-decl.vert new file mode 100644 index 0000000..c527fdf --- /dev/null +++ b/shaders-hlsl/vert/struct-composite-decl.vert @@ -0,0 +1,26 @@ +#version 310 es + +layout(location = 0) in vec4 a; +layout(location = 1) in vec4 b; +layout(location = 2) in vec4 c; +layout(location = 3) in vec4 d; + +struct VOut +{ + vec4 a; + vec4 b; + vec4 c; + vec4 d; +}; + +layout(location = 0) out VOut vout; + +void emit_result(VOut v) +{ + vout = v; +} + +void main() +{ + emit_result(VOut(a, b, c, d)); +} diff --git a/spirv_glsl.cpp b/spirv_glsl.cpp index c7b3656..eac7b0d 100644 --- a/spirv_glsl.cpp +++ b/spirv_glsl.cpp @@ -5481,12 +5481,16 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction) } } + if (out_type.basetype == SPIRType::Struct && !backend.can_declare_struct_inline) + forward = false; + string constructor_op; if (backend.use_initializer_list && composite) { // Only use this path if we are building composites. // This path cannot be used for arithmetic. - constructor_op += type_to_glsl_constructor(get(result_type)); + if (backend.use_typed_initializer_list) + constructor_op += type_to_glsl_constructor(get(result_type)); constructor_op += "{ "; if (splat) constructor_op += to_expression(elems[0]); diff --git a/spirv_glsl.hpp b/spirv_glsl.hpp index 32bc40c..7869d74 100644 --- a/spirv_glsl.hpp +++ b/spirv_glsl.hpp @@ -313,6 +313,8 @@ protected: bool flexible_member_array_supported = true; bool explicit_struct_type = false; bool use_initializer_list = false; + bool use_typed_initializer_list = false; + bool can_declare_struct_inline = true; bool native_row_major_matrix = true; bool use_constructor_splatting = true; bool boolean_mix_support = true; diff --git a/spirv_hlsl.cpp b/spirv_hlsl.cpp index 1cebe99..09c6a50 100644 --- a/spirv_hlsl.cpp +++ b/spirv_hlsl.cpp @@ -3644,6 +3644,7 @@ string CompilerHLSL::compile() backend.use_constructor_splatting = false; backend.boolean_mix_support = false; backend.can_swizzle_scalar = true; + backend.can_declare_struct_inline = false; update_active_builtins(); analyze_sampler_comparison_states(); diff --git a/spirv_msl.cpp b/spirv_msl.cpp index 2ca6c06..78ffdd7 100644 --- a/spirv_msl.cpp +++ b/spirv_msl.cpp @@ -69,6 +69,7 @@ string CompilerMSL::compile() backend.swizzle_is_function = false; backend.shared_is_implied = false; backend.use_initializer_list = true; + backend.use_typed_initializer_list = true; backend.native_row_major_matrix = false; backend.flexible_member_array_supported = false; backend.force_temp_use_for_two_vector_shuffles = true;