Merge pull request #590 from KhronosGroup/fix-581
Deal with packed expressions in more scenarios.
This commit is contained in:
commit
8bac5c09f3
@ -0,0 +1,23 @@
|
||||
#include <metal_stdlib>
|
||||
#include <simd/simd.h>
|
||||
|
||||
using namespace metal;
|
||||
|
||||
struct UBO
|
||||
{
|
||||
packed_float3 color;
|
||||
float v;
|
||||
};
|
||||
|
||||
struct main0_out
|
||||
{
|
||||
float4 FragColor [[color(0)]];
|
||||
};
|
||||
|
||||
fragment main0_out main0(constant UBO& _15 [[buffer(0)]])
|
||||
{
|
||||
main0_out out = {};
|
||||
out.FragColor = float4(_15.color[0], _15.color[1], _15.color[2], float4(1.0).w);
|
||||
return out;
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ vertex main0_out main0(constant UBO& _22 [[buffer(0)]])
|
||||
out.oA = _22.A;
|
||||
out.oB = float4(_22.B0, _22.B1);
|
||||
out.oC = float4(_22.C0, _22.C1) + float4(_22.C1.xy, _22.C1.z, _22.C0);
|
||||
out.oD = float4(_22.D0[0], _22.D0[1], _22.D0[2], _22.D1) + float4(float3(_22.D0).xy, _22.D0[2u], _22.D1);
|
||||
out.oD = float4(_22.D0[0], _22.D0[1], _22.D0[2], _22.D1) + float4(float2(_22.D0[0], _22.D0[1]), _22.D0[2u], _22.D1);
|
||||
out.oE = float4(_22.E0, _22.E1, _22.E2, _22.E3);
|
||||
out.oF = float4(_22.F0, _22.F1, _22.F2);
|
||||
return out;
|
||||
|
@ -0,0 +1,25 @@
|
||||
#include <metal_stdlib>
|
||||
#include <simd/simd.h>
|
||||
|
||||
using namespace metal;
|
||||
|
||||
struct UBO
|
||||
{
|
||||
packed_float3 color;
|
||||
float v;
|
||||
};
|
||||
|
||||
struct main0_out
|
||||
{
|
||||
float4 FragColor [[color(0)]];
|
||||
};
|
||||
|
||||
fragment main0_out main0(constant UBO& _15 [[buffer(0)]])
|
||||
{
|
||||
main0_out out = {};
|
||||
float4 f = float4(1.0);
|
||||
f = float4(_15.color[0], _15.color[1], _15.color[2], f.w);
|
||||
out.FragColor = f;
|
||||
return out;
|
||||
}
|
||||
|
15
shaders-msl/frag/packed-expression-vector-shuffle.frag
Normal file
15
shaders-msl/frag/packed-expression-vector-shuffle.frag
Normal file
@ -0,0 +1,15 @@
|
||||
#version 450
|
||||
layout(location = 0) out vec4 FragColor;
|
||||
|
||||
layout(binding = 0, std140) uniform UBO
|
||||
{
|
||||
vec3 color;
|
||||
float v;
|
||||
};
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 f = vec4(1.0);
|
||||
f.rgb = color;
|
||||
FragColor = f;
|
||||
}
|
@ -1855,6 +1855,7 @@ string CompilerGLSL::remap_swizzle(const SPIRType &out_type, uint32_t input_comp
|
||||
return join(type_to_glsl(out_type), "(", expr, ")");
|
||||
else
|
||||
{
|
||||
// FIXME: This will not work with packed expressions.
|
||||
auto e = enclose_expression(expr) + ".";
|
||||
// Just clamp the swizzle index if we have more outputs than inputs.
|
||||
for (uint32_t c = 0; c < out_type.vecsize; c++)
|
||||
@ -2372,6 +2373,15 @@ string CompilerGLSL::to_enclosed_expression(uint32_t id)
|
||||
return enclose_expression(to_expression(id));
|
||||
}
|
||||
|
||||
string CompilerGLSL::to_extract_component_expression(uint32_t id, uint32_t index)
|
||||
{
|
||||
auto expr = to_enclosed_expression(id);
|
||||
if (has_decoration(id, DecorationCPacked))
|
||||
return join(expr, "[", index, "]");
|
||||
else
|
||||
return join(expr, ".", index_to_swizzle(index));
|
||||
}
|
||||
|
||||
string CompilerGLSL::to_expression(uint32_t id)
|
||||
{
|
||||
auto itr = invalid_expressions.find(id);
|
||||
@ -3278,9 +3288,7 @@ void CompilerGLSL::emit_unrolled_unary_op(uint32_t result_type, uint32_t result_
|
||||
// Make sure to call to_expression multiple times to ensure
|
||||
// that these expressions are properly flushed to temporaries if needed.
|
||||
expr += op;
|
||||
expr += to_enclosed_expression(operand);
|
||||
expr += '.';
|
||||
expr += index_to_swizzle(i);
|
||||
expr += to_extract_component_expression(operand, i);
|
||||
|
||||
if (i + 1 < type.vecsize)
|
||||
expr += ", ";
|
||||
@ -3301,15 +3309,11 @@ void CompilerGLSL::emit_unrolled_binary_op(uint32_t result_type, uint32_t result
|
||||
{
|
||||
// Make sure to call to_expression multiple times to ensure
|
||||
// that these expressions are properly flushed to temporaries if needed.
|
||||
expr += to_enclosed_expression(op0);
|
||||
expr += '.';
|
||||
expr += index_to_swizzle(i);
|
||||
expr += to_extract_component_expression(op0, i);
|
||||
expr += ' ';
|
||||
expr += op;
|
||||
expr += ' ';
|
||||
expr += to_enclosed_expression(op1);
|
||||
expr += '.';
|
||||
expr += index_to_swizzle(i);
|
||||
expr += to_extract_component_expression(op1, i);
|
||||
|
||||
if (i + 1 < type.vecsize)
|
||||
expr += ", ";
|
||||
@ -3630,7 +3634,7 @@ void CompilerGLSL::emit_mix_op(uint32_t result_type, uint32_t id, uint32_t left,
|
||||
else
|
||||
{
|
||||
auto swiz = [this](uint32_t expression, uint32_t i) {
|
||||
return join(to_enclosed_expression(expression), ".", index_to_swizzle(i));
|
||||
return to_extract_component_expression(expression, i);
|
||||
};
|
||||
|
||||
expr = type_to_glsl_constructor(restype);
|
||||
@ -6538,6 +6542,10 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
|
||||
if (elems[i] >= type0.vecsize)
|
||||
shuffle = true;
|
||||
|
||||
// Cannot use swizzles with packed expressions, force shuffle path.
|
||||
if (!shuffle && has_decoration(vec0, DecorationCPacked))
|
||||
shuffle = true;
|
||||
|
||||
string expr;
|
||||
bool should_fwd, trivial_forward;
|
||||
|
||||
@ -6551,9 +6559,9 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
|
||||
for (uint32_t i = 0; i < length; i++)
|
||||
{
|
||||
if (elems[i] >= type0.vecsize)
|
||||
args.push_back(join(to_enclosed_expression(vec1), ".", index_to_swizzle(elems[i] - type0.vecsize)));
|
||||
args.push_back(to_extract_component_expression(vec1, elems[i] - type0.vecsize));
|
||||
else
|
||||
args.push_back(join(to_enclosed_expression(vec0), ".", index_to_swizzle(elems[i])));
|
||||
args.push_back(to_extract_component_expression(vec0, elems[i]));
|
||||
}
|
||||
expr += join(type_to_glsl_constructor(get<SPIRType>(result_type)), "(", merge(args), ")");
|
||||
}
|
||||
|
@ -436,6 +436,7 @@ protected:
|
||||
void append_global_func_args(const SPIRFunction &func, uint32_t index, std::vector<std::string> &arglist);
|
||||
std::string to_expression(uint32_t id);
|
||||
std::string to_enclosed_expression(uint32_t id);
|
||||
std::string to_extract_component_expression(uint32_t id, uint32_t index);
|
||||
std::string enclose_expression(const std::string &expr);
|
||||
void strip_enclosed_expression(std::string &expr);
|
||||
std::string to_member_name(const SPIRType &type, uint32_t index);
|
||||
|
Loading…
Reference in New Issue
Block a user