Merge pull request #365 from KhronosGroup/fix-363

Validate HLSL output through FXC, fix various HLSL bugs.
This commit is contained in:
Hans-Kristian Arntzen 2017-12-12 16:06:25 +01:00 committed by GitHub
commit fa27b56e26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
35 changed files with 153 additions and 106 deletions

View File

@ -14,8 +14,7 @@ struct SPIRV_Cross_Output
void vert_main() void vert_main()
{ {
float _23 = float(gl_VertexID + gl_InstanceID); gl_Position = float(gl_VertexID + gl_InstanceID).xxxx;
gl_Position = float4(_23, _23, _23, _23);
} }
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)

View File

@ -5,7 +5,7 @@ RWByteAddressBuffer ReadWrite : register(u1);
void comp_main() void comp_main()
{ {
WriteOnly.Store4(0, asuint(asfloat(ReadOnly.Load4(0)))); WriteOnly.Store4(0, asuint(asfloat(ReadOnly.Load4(0))));
ReadWrite.Store4(0, asuint(asfloat(ReadWrite.Load4(0)) + float4(10.0f, 10.0f, 10.0f, 10.0f))); ReadWrite.Store4(0, asuint(asfloat(ReadWrite.Load4(0)) + 10.0f.xxxx));
} }
[numthreads(1, 1, 1)] [numthreads(1, 1, 1)]

View File

@ -13,8 +13,7 @@ void comp_main()
InterlockedAdd(uImage[int2(1, 5)], 1u, _19); InterlockedAdd(uImage[int2(1, 5)], 1u, _19);
uint _27; uint _27;
InterlockedAdd(uImage[int2(1, 5)], 1u, _27); InterlockedAdd(uImage[int2(1, 5)], 1u, _27);
int _28 = int(_27); iImage[int2(1, 6)] = int(_27).x;
iImage[int2(1, 6)] = int4(_28, _28, _28, _28).x;
uint _32; uint _32;
InterlockedOr(uImage[int2(1, 5)], 1u, _32); InterlockedOr(uImage[int2(1, 5)], 1u, _32);
uint _34; uint _34;

View File

@ -6,25 +6,25 @@ RWTexture2D<uint> uImageInU : register(u4);
RWTexture2D<uint> uImageOutU : register(u5); RWTexture2D<uint> uImageOutU : register(u5);
RWBuffer<float> uImageInBuffer : register(u6); RWBuffer<float> uImageInBuffer : register(u6);
RWBuffer<float> uImageOutBuffer : register(u7); RWBuffer<float> uImageOutBuffer : register(u7);
RWTexture2D<float2> uImageInF2 : register(u0); RWTexture2D<float2> uImageInF2 : register(u8);
RWTexture2D<float2> uImageOutF2 : register(u1); RWTexture2D<float2> uImageOutF2 : register(u9);
RWTexture2D<int2> uImageInI2 : register(u2); RWTexture2D<int2> uImageInI2 : register(u10);
RWTexture2D<int2> uImageOutI2 : register(u3); RWTexture2D<int2> uImageOutI2 : register(u11);
RWTexture2D<uint2> uImageInU2 : register(u4); RWTexture2D<uint2> uImageInU2 : register(u12);
RWTexture2D<uint2> uImageOutU2 : register(u5); RWTexture2D<uint2> uImageOutU2 : register(u13);
RWBuffer<float2> uImageInBuffer2 : register(u6); RWBuffer<float2> uImageInBuffer2 : register(u14);
RWBuffer<float2> uImageOutBuffer2 : register(u7); RWBuffer<float2> uImageOutBuffer2 : register(u15);
RWTexture2D<float4> uImageInF4 : register(u0); RWTexture2D<float4> uImageInF4 : register(u16);
RWTexture2D<float4> uImageOutF4 : register(u1); RWTexture2D<float4> uImageOutF4 : register(u17);
RWTexture2D<int4> uImageInI4 : register(u2); RWTexture2D<int4> uImageInI4 : register(u18);
RWTexture2D<int4> uImageOutI4 : register(u3); RWTexture2D<int4> uImageOutI4 : register(u19);
RWTexture2D<uint4> uImageInU4 : register(u4); RWTexture2D<uint4> uImageInU4 : register(u20);
RWTexture2D<uint4> uImageOutU4 : register(u5); RWTexture2D<uint4> uImageOutU4 : register(u21);
RWBuffer<float4> uImageInBuffer4 : register(u6); RWBuffer<float4> uImageInBuffer4 : register(u22);
RWBuffer<float4> uImageOutBuffer4 : register(u7); RWBuffer<float4> uImageOutBuffer4 : register(u23);
RWTexture2D<float4> uImageNoFmtF : register(u8); RWTexture2D<float4> uImageNoFmtF : register(u24);
RWTexture2D<uint4> uImageNoFmtU : register(u9); RWTexture2D<uint4> uImageNoFmtU : register(u25);
RWTexture2D<int4> uImageNoFmtI : register(u10); RWTexture2D<int4> uImageNoFmtI : register(u26);
static uint3 gl_GlobalInvocationID; static uint3 gl_GlobalInvocationID;
struct SPIRV_Cross_Input struct SPIRV_Cross_Input
@ -34,13 +34,13 @@ struct SPIRV_Cross_Input
void comp_main() void comp_main()
{ {
uImageOutF[int2(gl_GlobalInvocationID.xy)] = float4(uImageInF[int2(gl_GlobalInvocationID.xy)]).x; uImageOutF[int2(gl_GlobalInvocationID.xy)] = uImageInF[int2(gl_GlobalInvocationID.xy)].x;
uImageOutI[int2(gl_GlobalInvocationID.xy)] = int4(uImageInI[int2(gl_GlobalInvocationID.xy)]).x; uImageOutI[int2(gl_GlobalInvocationID.xy)] = uImageInI[int2(gl_GlobalInvocationID.xy)].x;
uImageOutU[int2(gl_GlobalInvocationID.xy)] = uint4(uImageInU[int2(gl_GlobalInvocationID.xy)]).x; uImageOutU[int2(gl_GlobalInvocationID.xy)] = uImageInU[int2(gl_GlobalInvocationID.xy)].x;
uImageOutBuffer[int(gl_GlobalInvocationID.x)] = float4(uImageInBuffer[int(gl_GlobalInvocationID.x)]).x; uImageOutBuffer[int(gl_GlobalInvocationID.x)] = uImageInBuffer[int(gl_GlobalInvocationID.x)].x;
uImageOutF2[int2(gl_GlobalInvocationID.xy)] = uImageInF2[int2(gl_GlobalInvocationID.xy)].xyyy.xy; uImageOutF2[int2(gl_GlobalInvocationID.xy)] = uImageInF2[int2(gl_GlobalInvocationID.xy)].xy;
uImageOutI2[int2(gl_GlobalInvocationID.xy)] = uImageInI2[int2(gl_GlobalInvocationID.xy)].xyyy.xy; uImageOutI2[int2(gl_GlobalInvocationID.xy)] = uImageInI2[int2(gl_GlobalInvocationID.xy)].xy;
uImageOutU2[int2(gl_GlobalInvocationID.xy)] = uImageInU2[int2(gl_GlobalInvocationID.xy)].xyyy.xy; uImageOutU2[int2(gl_GlobalInvocationID.xy)] = uImageInU2[int2(gl_GlobalInvocationID.xy)].xy;
float4 _135 = uImageInBuffer2[int(gl_GlobalInvocationID.x)].xyyy; float4 _135 = uImageInBuffer2[int(gl_GlobalInvocationID.x)].xyyy;
uImageOutBuffer2[int(gl_GlobalInvocationID.x)] = _135.xy; uImageOutBuffer2[int(gl_GlobalInvocationID.x)] = _135.xy;
uImageOutF4[int2(gl_GlobalInvocationID.xy)] = uImageInF4[int2(gl_GlobalInvocationID.xy)]; uImageOutF4[int2(gl_GlobalInvocationID.xy)] = uImageInF4[int2(gl_GlobalInvocationID.xy)];

View File

@ -13,8 +13,7 @@ struct SPIRV_Cross_Output
void frag_main() void frag_main()
{ {
bool _21 = x0.x > x0.y; bool2 _27 = (x0.x > x0.y).xx;
bool2 _27 = bool2(_21, _21);
FragColor = float2(_27.x ? float2(1.0f, 0.0f).x : float2(0.0f, 1.0f).x, _27.y ? float2(1.0f, 0.0f).y : float2(0.0f, 1.0f).y); FragColor = float2(_27.x ? float2(1.0f, 0.0f).x : float2(0.0f, 1.0f).x, _27.y ? float2(1.0f, 0.0f).y : float2(0.0f, 1.0f).y);
} }

View File

@ -1,5 +1,5 @@
Texture2D<float4> uSampler : register(t1); Texture2D<float4> uSampler : register(t0);
SamplerState _uSampler_sampler : register(s1); SamplerState _uSampler_sampler : register(s0);
Texture2D<float4> uSamplerShadow : register(t1); Texture2D<float4> uSamplerShadow : register(t1);
SamplerComparisonState _uSamplerShadow_sampler : register(s1); SamplerComparisonState _uSamplerShadow_sampler : register(s1);

View File

@ -47,8 +47,7 @@ float4 mod(float4 x, float4 y)
void frag_main() void frag_main()
{ {
float _41 = mod(a1, b1); FragColor = ((mod(a4, b4) + mod(a3, b3).xyzx) + mod(a2, b2).xyxy) + mod(a1, b1).xxxx;
FragColor = ((mod(a4, b4) + mod(a3, b3).xyzx) + mod(a2, b2).xyxy) + float4(_41, _41, _41, _41);
} }
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)

View File

@ -15,14 +15,13 @@ struct SPIRV_Cross_Output
float4 FragColor : SV_Target0; float4 FragColor : SV_Target0;
}; };
float _146[(c + 2)];
void frag_main() void frag_main()
{ {
float _113 = a + b;
float vec0[(c + 3)][8]; float vec0[(c + 3)][8];
vec0[0][0] = 10.0f;
Foo foo; Foo foo;
FragColor = ((float4(_113, _113, _113, _113) + float4(vec0[0][0], vec0[0][0], vec0[0][0], vec0[0][0])) + float4(_146[0], _146[0], _146[0], _146[0])) + float4(foo.elems[c], foo.elems[c], foo.elems[c], foo.elems[c]); foo.elems[c] = 10.0f;
FragColor = (((a + b).xxxx + vec0[0][0].xxxx) + 20.0f.xxxx) + foo.elems[c].xxxx;
} }
SPIRV_Cross_Output main() SPIRV_Cross_Output main()

View File

@ -14,8 +14,7 @@ struct SPIRV_Cross_Output
void vert_main() void vert_main()
{ {
float _19 = float(gl_VertexIndex + gl_InstanceIndex); gl_Position = float(gl_VertexIndex + gl_InstanceIndex).xxxx;
gl_Position = float4(_19, _19, _19, _19);
} }
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)

View File

@ -14,8 +14,7 @@ struct SPIRV_Cross_Output
void vert_main() void vert_main()
{ {
float _23 = float(gl_VertexID + gl_InstanceID); gl_Position = float(gl_VertexID + gl_InstanceID).xxxx;
gl_Position = float4(_23, _23, _23, _23);
} }
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)

View File

@ -5,7 +5,7 @@ RWByteAddressBuffer ReadWrite : register(u1);
void comp_main() void comp_main()
{ {
WriteOnly.Store4(0, asuint(asfloat(ReadOnly.Load4(0)))); WriteOnly.Store4(0, asuint(asfloat(ReadOnly.Load4(0))));
ReadWrite.Store4(0, asuint(asfloat(ReadWrite.Load4(0)) + float4(10.0f, 10.0f, 10.0f, 10.0f))); ReadWrite.Store4(0, asuint(asfloat(ReadWrite.Load4(0)) + 10.0f.xxxx));
} }
[numthreads(1, 1, 1)] [numthreads(1, 1, 1)]

View File

@ -13,8 +13,7 @@ void comp_main()
InterlockedAdd(uImage[int2(1, 5)], 1u, _19); InterlockedAdd(uImage[int2(1, 5)], 1u, _19);
uint _27; uint _27;
InterlockedAdd(uImage[int2(1, 5)], 1u, _27); InterlockedAdd(uImage[int2(1, 5)], 1u, _27);
int _28 = int(_27); iImage[int2(1, 6)] = int(_27).x;
iImage[int2(1, 6)] = int4(_28, _28, _28, _28).x;
uint _32; uint _32;
InterlockedOr(uImage[int2(1, 5)], 1u, _32); InterlockedOr(uImage[int2(1, 5)], 1u, _32);
uint _34; uint _34;

View File

@ -6,25 +6,25 @@ RWTexture2D<uint> uImageInU : register(u4);
RWTexture2D<uint> uImageOutU : register(u5); RWTexture2D<uint> uImageOutU : register(u5);
RWBuffer<float> uImageInBuffer : register(u6); RWBuffer<float> uImageInBuffer : register(u6);
RWBuffer<float> uImageOutBuffer : register(u7); RWBuffer<float> uImageOutBuffer : register(u7);
RWTexture2D<float2> uImageInF2 : register(u0); RWTexture2D<float2> uImageInF2 : register(u8);
RWTexture2D<float2> uImageOutF2 : register(u1); RWTexture2D<float2> uImageOutF2 : register(u9);
RWTexture2D<int2> uImageInI2 : register(u2); RWTexture2D<int2> uImageInI2 : register(u10);
RWTexture2D<int2> uImageOutI2 : register(u3); RWTexture2D<int2> uImageOutI2 : register(u11);
RWTexture2D<uint2> uImageInU2 : register(u4); RWTexture2D<uint2> uImageInU2 : register(u12);
RWTexture2D<uint2> uImageOutU2 : register(u5); RWTexture2D<uint2> uImageOutU2 : register(u13);
RWBuffer<float2> uImageInBuffer2 : register(u6); RWBuffer<float2> uImageInBuffer2 : register(u14);
RWBuffer<float2> uImageOutBuffer2 : register(u7); RWBuffer<float2> uImageOutBuffer2 : register(u15);
RWTexture2D<float4> uImageInF4 : register(u0); RWTexture2D<float4> uImageInF4 : register(u16);
RWTexture2D<float4> uImageOutF4 : register(u1); RWTexture2D<float4> uImageOutF4 : register(u17);
RWTexture2D<int4> uImageInI4 : register(u2); RWTexture2D<int4> uImageInI4 : register(u18);
RWTexture2D<int4> uImageOutI4 : register(u3); RWTexture2D<int4> uImageOutI4 : register(u19);
RWTexture2D<uint4> uImageInU4 : register(u4); RWTexture2D<uint4> uImageInU4 : register(u20);
RWTexture2D<uint4> uImageOutU4 : register(u5); RWTexture2D<uint4> uImageOutU4 : register(u21);
RWBuffer<float4> uImageInBuffer4 : register(u6); RWBuffer<float4> uImageInBuffer4 : register(u22);
RWBuffer<float4> uImageOutBuffer4 : register(u7); RWBuffer<float4> uImageOutBuffer4 : register(u23);
RWTexture2D<float4> uImageNoFmtF : register(u8); RWTexture2D<float4> uImageNoFmtF : register(u24);
RWTexture2D<uint4> uImageNoFmtU : register(u9); RWTexture2D<uint4> uImageNoFmtU : register(u25);
RWTexture2D<int4> uImageNoFmtI : register(u10); RWTexture2D<int4> uImageNoFmtI : register(u26);
static uint3 gl_GlobalInvocationID; static uint3 gl_GlobalInvocationID;
struct SPIRV_Cross_Input struct SPIRV_Cross_Input
@ -34,13 +34,13 @@ struct SPIRV_Cross_Input
void comp_main() void comp_main()
{ {
float4 f = float4(uImageInF[int2(gl_GlobalInvocationID.xy)]); float4 f = uImageInF[int2(gl_GlobalInvocationID.xy)].xxxx;
uImageOutF[int2(gl_GlobalInvocationID.xy)] = f.x; uImageOutF[int2(gl_GlobalInvocationID.xy)] = f.x;
int4 i = int4(uImageInI[int2(gl_GlobalInvocationID.xy)]); int4 i = uImageInI[int2(gl_GlobalInvocationID.xy)].xxxx;
uImageOutI[int2(gl_GlobalInvocationID.xy)] = i.x; uImageOutI[int2(gl_GlobalInvocationID.xy)] = i.x;
uint4 u = uint4(uImageInU[int2(gl_GlobalInvocationID.xy)]); uint4 u = uImageInU[int2(gl_GlobalInvocationID.xy)].xxxx;
uImageOutU[int2(gl_GlobalInvocationID.xy)] = u.x; uImageOutU[int2(gl_GlobalInvocationID.xy)] = u.x;
float4 b = float4(uImageInBuffer[int(gl_GlobalInvocationID.x)]); float4 b = uImageInBuffer[int(gl_GlobalInvocationID.x)].xxxx;
uImageOutBuffer[int(gl_GlobalInvocationID.x)] = b.x; uImageOutBuffer[int(gl_GlobalInvocationID.x)] = b.x;
float4 f2 = uImageInF2[int2(gl_GlobalInvocationID.xy)].xyyy; float4 f2 = uImageInF2[int2(gl_GlobalInvocationID.xy)].xyyy;
uImageOutF2[int2(gl_GlobalInvocationID.xy)] = f2.xy; uImageOutF2[int2(gl_GlobalInvocationID.xy)] = f2.xy;

View File

@ -13,8 +13,7 @@ struct SPIRV_Cross_Output
void frag_main() void frag_main()
{ {
bool _21 = x0.x > x0.y; bool2 _27 = (x0.x > x0.y).xx;
bool2 _27 = bool2(_21, _21);
FragColor = float2(_27.x ? float2(1.0f, 0.0f).x : float2(0.0f, 1.0f).x, _27.y ? float2(1.0f, 0.0f).y : float2(0.0f, 1.0f).y); FragColor = float2(_27.x ? float2(1.0f, 0.0f).x : float2(0.0f, 1.0f).x, _27.y ? float2(1.0f, 0.0f).y : float2(0.0f, 1.0f).y);
} }

View File

@ -1,5 +1,5 @@
Texture2D<float4> uSampler : register(t1); Texture2D<float4> uSampler : register(t0);
SamplerState _uSampler_sampler : register(s1); SamplerState _uSampler_sampler : register(s0);
Texture2D<float4> uSamplerShadow : register(t1); Texture2D<float4> uSamplerShadow : register(t1);
SamplerComparisonState _uSamplerShadow_sampler : register(s1); SamplerComparisonState _uSamplerShadow_sampler : register(s1);

View File

@ -66,6 +66,7 @@ uint SPIRV_Cross_textureSize(Buffer<float4> Tex, uint Level, out uint Param)
{ {
uint ret; uint ret;
Tex.GetDimensions(ret.x); Tex.GetDimensions(ret.x);
Param = 0u;
return ret; return ret;
} }

View File

@ -48,6 +48,7 @@ uint SPIRV_Cross_textureSize(Buffer<float4> Tex, uint Level, out uint Param)
{ {
uint ret; uint ret;
Tex.GetDimensions(ret.x); Tex.GetDimensions(ret.x);
Param = 0u;
return ret; return ret;
} }

View File

@ -51,7 +51,7 @@ void frag_main()
float3 m1 = mod(a3, b3); float3 m1 = mod(a3, b3);
float2 m2 = mod(a2, b2); float2 m2 = mod(a2, b2);
float m3 = mod(a1, b1); float m3 = mod(a1, b1);
FragColor = ((m0 + m1.xyzx) + m2.xyxy) + float4(m3, m3, m3, m3); FragColor = ((m0 + m1.xyzx) + m2.xyxy) + m3.xxxx;
} }
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)

View File

@ -61,11 +61,13 @@ void frag_main()
int c35 = int(g); int c35 = int(g);
uint c36 = uint(g); uint c36 = uint(g);
float c37 = float(g); float c37 = float(g);
float _113 = t0 + t1;
float vec0[(c + 3)][8]; float vec0[(c + 3)][8];
vec0[0][0] = 10.0f;
float vec1[(c + 2)]; float vec1[(c + 2)];
vec1[0] = 20.0f;
Foo foo; Foo foo;
FragColor = ((float4(_113, _113, _113, _113) + float4(vec0[0][0], vec0[0][0], vec0[0][0], vec0[0][0])) + float4(vec1[0], vec1[0], vec1[0], vec1[0])) + float4(foo.elems[c], foo.elems[c], foo.elems[c], foo.elems[c]); foo.elems[c] = 10.0f;
FragColor = (((t0 + t1).xxxx + vec0[0][0].xxxx) + vec1[0].xxxx) + foo.elems[c].xxxx;
} }
SPIRV_Cross_Output main() SPIRV_Cross_Output main()

View File

@ -14,8 +14,7 @@ struct SPIRV_Cross_Output
void vert_main() void vert_main()
{ {
float _19 = float(gl_VertexIndex + gl_InstanceIndex); gl_Position = float(gl_VertexIndex + gl_InstanceIndex).xxxx;
gl_Position = float4(_19, _19, _19, _19);
} }
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)

View File

@ -10,27 +10,27 @@ layout(r32ui, binding = 5) uniform writeonly uimage2D uImageOutU;
layout(r32f, binding = 6) uniform readonly imageBuffer uImageInBuffer; layout(r32f, binding = 6) uniform readonly imageBuffer uImageInBuffer;
layout(r32f, binding = 7) uniform writeonly imageBuffer uImageOutBuffer; layout(r32f, binding = 7) uniform writeonly imageBuffer uImageOutBuffer;
layout(rg32f, binding = 0) uniform readonly image2D uImageInF2; layout(rg32f, binding = 8) uniform readonly image2D uImageInF2;
layout(rg32f, binding = 1) uniform writeonly image2D uImageOutF2; layout(rg32f, binding = 9) uniform writeonly image2D uImageOutF2;
layout(rg32i, binding = 2) uniform readonly iimage2D uImageInI2; layout(rg32i, binding = 10) uniform readonly iimage2D uImageInI2;
layout(rg32i, binding = 3) uniform writeonly iimage2D uImageOutI2; layout(rg32i, binding = 11) uniform writeonly iimage2D uImageOutI2;
layout(rg32ui, binding = 4) uniform readonly uimage2D uImageInU2; layout(rg32ui, binding = 12) uniform readonly uimage2D uImageInU2;
layout(rg32ui, binding = 5) uniform writeonly uimage2D uImageOutU2; layout(rg32ui, binding = 13) uniform writeonly uimage2D uImageOutU2;
layout(rg32f, binding = 6) uniform readonly imageBuffer uImageInBuffer2; layout(rg32f, binding = 14) uniform readonly imageBuffer uImageInBuffer2;
layout(rg32f, binding = 7) uniform writeonly imageBuffer uImageOutBuffer2; layout(rg32f, binding = 15) uniform writeonly imageBuffer uImageOutBuffer2;
layout(rgba32f, binding = 0) uniform readonly image2D uImageInF4; layout(rgba32f, binding = 16) uniform readonly image2D uImageInF4;
layout(rgba32f, binding = 1) uniform writeonly image2D uImageOutF4; layout(rgba32f, binding = 17) uniform writeonly image2D uImageOutF4;
layout(rgba32i, binding = 2) uniform readonly iimage2D uImageInI4; layout(rgba32i, binding = 18) uniform readonly iimage2D uImageInI4;
layout(rgba32i, binding = 3) uniform writeonly iimage2D uImageOutI4; layout(rgba32i, binding = 19) uniform writeonly iimage2D uImageOutI4;
layout(rgba32ui, binding = 4) uniform readonly uimage2D uImageInU4; layout(rgba32ui, binding = 20) uniform readonly uimage2D uImageInU4;
layout(rgba32ui, binding = 5) uniform writeonly uimage2D uImageOutU4; layout(rgba32ui, binding = 21) uniform writeonly uimage2D uImageOutU4;
layout(rgba32f, binding = 6) uniform readonly imageBuffer uImageInBuffer4; layout(rgba32f, binding = 22) uniform readonly imageBuffer uImageInBuffer4;
layout(rgba32f, binding = 7) uniform writeonly imageBuffer uImageOutBuffer4; layout(rgba32f, binding = 23) uniform writeonly imageBuffer uImageOutBuffer4;
layout(binding = 8) uniform writeonly image2D uImageNoFmtF; layout(binding = 24) uniform writeonly image2D uImageNoFmtF;
layout(binding = 9) uniform writeonly uimage2D uImageNoFmtU; layout(binding = 25) uniform writeonly uimage2D uImageNoFmtU;
layout(binding = 10) uniform writeonly iimage2D uImageNoFmtI; layout(binding = 26) uniform writeonly iimage2D uImageNoFmtI;
void main() void main()
{ {

View File

@ -1,7 +1,7 @@
#version 310 es #version 310 es
precision mediump float; precision mediump float;
layout(set = 0, binding = 1) uniform mediump sampler2D uSampler; layout(set = 0, binding = 0) uniform mediump sampler2D uSampler;
layout(set = 0, binding = 1) uniform mediump sampler2DShadow uSamplerShadow; layout(set = 0, binding = 1) uniform mediump sampler2DShadow uSamplerShadow;
layout(location = 0) out float FragColor; layout(location = 0) out float FragColor;

View File

@ -71,7 +71,10 @@ void main()
// Flexible sized arrays with spec constants and spec constant ops. // Flexible sized arrays with spec constants and spec constant ops.
float vec0[c + 3][8]; float vec0[c + 3][8];
float vec1[c + 2]; float vec1[c + 2];
vec0[0][0] = 10.0;
vec1[0] = 20.0;
Foo foo; Foo foo;
foo.elems[c] = 10.0;
FragColor = vec4(t0 + t1) + vec0[0][0] + vec1[0] + foo.elems[c]; FragColor = vec4(t0 + t1) + vec0[0][0] + vec1[0] + foo.elems[c];
} }

View File

@ -1722,7 +1722,7 @@ string CompilerGLSL::remap_swizzle(const SPIRType &out_type, uint32_t input_comp
{ {
if (out_type.vecsize == input_components) if (out_type.vecsize == input_components)
return expr; return expr;
else if (input_components == 1) else if (input_components == 1 && !backend.can_swizzle_scalar)
return join(type_to_glsl(out_type), "(", expr, ")"); return join(type_to_glsl(out_type), "(", expr, ")");
else else
{ {
@ -1732,6 +1732,8 @@ string CompilerGLSL::remap_swizzle(const SPIRType &out_type, uint32_t input_comp
e += index_to_swizzle(min(c, input_components - 1)); e += index_to_swizzle(min(c, input_components - 1));
if (backend.swizzle_is_function && out_type.vecsize > 1) if (backend.swizzle_is_function && out_type.vecsize > 1)
e += "()"; e += "()";
remove_duplicate_swizzle(e);
return e; return e;
} }
} }
@ -5369,13 +5371,19 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
// Arrays and structs must be initialized properly in full. // Arrays and structs must be initialized properly in full.
bool composite = !out_type.array.empty() || out_type.basetype == SPIRType::Struct; bool composite = !out_type.array.empty() || out_type.basetype == SPIRType::Struct;
bool splat = in_type.vecsize == 1 && in_type.columns == 1 && !composite && backend.use_constructor_splatting; bool splat = in_type.vecsize == 1 && in_type.columns == 1 && !composite && backend.use_constructor_splatting;
bool swizzle_splat = in_type.vecsize == 1 && in_type.columns == 1 && backend.can_swizzle_scalar;
if (splat) if (splat || swizzle_splat)
{ {
uint32_t input = elems[0]; uint32_t input = elems[0];
for (uint32_t i = 0; i < length; i++) for (uint32_t i = 0; i < length; i++)
{
if (input != elems[i]) if (input != elems[i])
{
splat = false; splat = false;
swizzle_splat = false;
}
}
} }
string constructor_op; string constructor_op;
@ -5390,6 +5398,10 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
constructor_op += build_composite_combiner(elems, length); constructor_op += build_composite_combiner(elems, length);
constructor_op += " }"; constructor_op += " }";
} }
else if (swizzle_splat && !composite)
{
constructor_op = remap_swizzle(get<SPIRType>(result_type), 1, to_expression(elems[0]));
}
else else
{ {
constructor_op = type_to_glsl_constructor(get<SPIRType>(result_type)) + "("; constructor_op = type_to_glsl_constructor(get<SPIRType>(result_type)) + "(";

View File

@ -320,6 +320,7 @@ protected:
bool use_constructor_splatting = true; bool use_constructor_splatting = true;
bool boolean_mix_support = true; bool boolean_mix_support = true;
bool allow_precision_qualifiers = false; bool allow_precision_qualifiers = false;
bool can_swizzle_scalar = false;
} backend; } backend;
void emit_struct(SPIRType &type); void emit_struct(SPIRType &type);

View File

@ -1232,7 +1232,10 @@ void CompilerHLSL::emit_resources()
if (has_lod[index]) if (has_lod[index])
statement("Tex.GetDimensions(Level, ret.x, Param);"); statement("Tex.GetDimensions(Level, ret.x, Param);");
else else
{
statement("Tex.GetDimensions(ret.x);"); statement("Tex.GetDimensions(ret.x);");
statement("Param = 0u;");
}
break; break;
case 2: case 2:
if (has_lod[index]) if (has_lod[index])
@ -3596,6 +3599,7 @@ string CompilerHLSL::compile()
backend.use_initializer_list = true; backend.use_initializer_list = true;
backend.use_constructor_splatting = false; backend.use_constructor_splatting = false;
backend.boolean_mix_support = false; backend.boolean_mix_support = false;
backend.can_swizzle_scalar = true;
update_active_builtins(); update_active_builtins();
analyze_sampler_comparison_states(); analyze_sampler_comparison_states();

View File

@ -105,10 +105,43 @@ def cross_compile_msl(shader, spirv, opt):
subprocess.check_call(['spirv-val', spirv_path]) subprocess.check_call(['spirv-val', spirv_path])
return (spirv_path, msl_path) return (spirv_path, msl_path)
def shader_model_hlsl(shader):
if '.vert' in shader:
return '-Tvs_5_1'
elif '.frag' in shader:
return '-Tps_5_1'
elif '.comp' in shader:
return '-Tcs_5_1'
else:
return None
def shader_to_win_path(shader):
# It's (very) convenient to be able to run HLSL testing in wine on Unix-likes, so support that.
try:
with subprocess.Popen(['winepath', '-w', shader], stdout = subprocess.PIPE, stderr = subprocess.PIPE) as f:
stdout_data, stderr_data = f.communicate()
return stdout_data.decode('utf-8')
except OSError as oe:
if (oe.errno != os.errno.ENOENT): # Ignore not found errors
return shader
except subprocess.CalledProcessError:
raise
return shader
def validate_shader_hlsl(shader): def validate_shader_hlsl(shader):
subprocess.check_call(['glslangValidator', '-e', 'main', '-D', '-V', shader]) subprocess.check_call(['glslangValidator', '-e', 'main', '-D', '-V', shader])
if (not force_no_external_validation) and os.path.exists('fxc'): is_no_fxc = '.nofxc.' in shader
subprocess.check_call(['fxc', shader]) if (not force_no_external_validation) and (not is_no_fxc):
try:
win_path = shader_to_win_path(shader)
subprocess.check_call(['fxc', '-nologo', shader_model_hlsl(shader), win_path])
except OSError as oe:
if (oe.errno != os.errno.ENOENT): # Ignore not found errors
raise
except subprocess.CalledProcessError:
print('Failed compiling HLSL shader:', shader, 'with FXC.')
sys.exit(1)
def shader_to_sm(shader): def shader_to_sm(shader):
if '.sm51.' in shader: if '.sm51.' in shader:

View File

@ -3,7 +3,7 @@
echo "Building spirv-cross" echo "Building spirv-cross"
make -j$(nproc) make -j$(nproc)
export PATH="./external/glslang-build/StandAlone:./external/spirv-tools-build/tools:$PATH" export PATH="./external/glslang-build/StandAlone:./external/spirv-tools-build/tools:.:$PATH"
echo "Using glslangValidation in: $(which glslangValidator)." echo "Using glslangValidation in: $(which glslangValidator)."
echo "Using spirv-opt in: $(which spirv-opt)." echo "Using spirv-opt in: $(which spirv-opt)."

View File

@ -3,7 +3,7 @@
echo "Building spirv-cross" echo "Building spirv-cross"
make -j$(nproc) make -j$(nproc)
export PATH="./external/glslang-build/StandAlone:./external/spirv-tools-build/tools:$PATH" export PATH="./external/glslang-build/StandAlone:./external/spirv-tools-build/tools:.:$PATH"
echo "Using glslangValidation in: $(which glslangValidator)." echo "Using glslangValidation in: $(which glslangValidator)."
echo "Using spirv-opt in: $(which spirv-opt)." echo "Using spirv-opt in: $(which spirv-opt)."