diff --git a/.travis.yml b/.travis.yml index ddaf6719..f7d48b0f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,7 @@ dist: trusty # We check out glslang at a specific revision to avoid test output mismatches env: - - GLSLANG_REV=b56f4ac72c57f5c50f14ddb0bf1f78eaaef21c2b + - GLSLANG_REV=e4e8f7b7a31a751be285b64741465b769f5f146f before_script: - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install python3; fi diff --git a/reference/shaders-msl/frag/mix.frag b/reference/shaders-msl/frag/mix.frag index fe1229ce..33157811 100644 --- a/reference/shaders-msl/frag/mix.frag +++ b/reference/shaders-msl/frag/mix.frag @@ -23,26 +23,8 @@ fragment main0_out main0(main0_in in [[stage_in]]) out.FragColor = float4(l.x ? in.vIn1.x : in.vIn0.x, l.y ? in.vIn1.y : in.vIn0.y, l.z ? in.vIn1.z : in.vIn0.z, l.w ? in.vIn1.w : in.vIn0.w); bool f = true; out.FragColor = float4(f ? in.vIn3 : in.vIn2); - float4 _35; - if (f) - { - _35 = in.vIn0; - } - else - { - _35 = in.vIn1; - } - out.FragColor = _35; - float _44; - if (f) - { - _44 = in.vIn2; - } - else - { - _44 = in.vIn3; - } - out.FragColor = float4(_44); + out.FragColor = f ? in.vIn0 : in.vIn1; + out.FragColor = float4(f ? in.vIn2 : in.vIn3); return out; } diff --git a/reference/shaders/comp/generate_height.comp b/reference/shaders/comp/generate_height.comp index 1367e951..30ec624c 100644 --- a/reference/shaders/comp/generate_height.comp +++ b/reference/shaders/comp/generate_height.comp @@ -4,40 +4,40 @@ layout(local_size_x = 64, local_size_y = 1, local_size_z = 1) in; layout(binding = 0, std430) readonly buffer Distribution { vec2 distribution[]; -} _190; +} _136; layout(binding = 2, std140) uniform UBO { vec4 uModTime; -} _218; +} _165; layout(binding = 1, std430) writeonly buffer HeightmapFFT { uint heights[]; -} _276; +} _224; uvec2 workaround_mix(uvec2 a, uvec2 b, bvec2 sel) { - uint _137; + uint _83; if (sel.x) { - _137 = b.x; + _83 = b.x; } else { - _137 = a.x; + _83 = a.x; } - uint _147 = _137; - uint _148; + uint _93 = _83; + uint _94; if (sel.y) { - _148 = b.y; + _94 = b.y; } else { - _148 = a.y; + _94 = a.y; } - return uvec2(_147, _148); + return uvec2(_93, _94); } vec2 alias(vec2 i, vec2 N) @@ -68,13 +68,13 @@ void generate_heightmap() uvec2 param_1 = uvec2(0u); bvec2 param_2 = equal(i, uvec2(0u)); uvec2 wi = workaround_mix(param, param_1, param_2); - vec2 a = _190.distribution[(i.y * N.x) + i.x]; - vec2 b = _190.distribution[(wi.y * N.x) + wi.x]; + vec2 a = _136.distribution[(i.y * N.x) + i.x]; + vec2 b = _136.distribution[(wi.y * N.x) + wi.x]; vec2 param_3 = vec2(i); vec2 param_4 = vec2(N); - vec2 k = _218.uModTime.xy * alias(param_3, param_4); + vec2 k = _165.uModTime.xy * alias(param_3, param_4); float k_len = length(k); - float w = sqrt(9.81000041961669921875 * k_len) * _218.uModTime.z; + float w = sqrt(9.81000041961669921875 * k_len) * _165.uModTime.z; float cw = cos(w); float sw = sin(w); vec2 param_5 = a; @@ -86,7 +86,7 @@ void generate_heightmap() b = vec2(b.x, -b.y); vec2 res = a + b; vec2 param_9 = res; - _276.heights[(i.y * N.x) + i.x] = pack2(param_9); + _224.heights[(i.y * N.x) + i.x] = pack2(param_9); } void main() diff --git a/reference/shaders/frag/ground.frag b/reference/shaders/frag/ground.frag index 4b0ea829..4d998d56 100644 --- a/reference/shaders/frag/ground.frag +++ b/reference/shaders/frag/ground.frag @@ -10,7 +10,7 @@ layout(binding = 4, std140) uniform GlobalPSData vec4 g_ResolutionParams; vec4 g_TimeParams; vec4 g_FogColor_Distance; -} _56; +} _101; layout(binding = 2) uniform mediump sampler2D TexNormalmap; @@ -47,7 +47,7 @@ void main() vec3 grass = vec3(0.100000001490116119384765625, 0.300000011920928955078125, 0.100000001490116119384765625); vec3 dirt = vec3(0.100000001490116119384765625); vec3 snow = vec3(0.800000011920928955078125); - float grass_snow = smoothstep(0.0, 0.1500000059604644775390625, (_56.g_CamPos.y + EyeVec.y) / 200.0); + float grass_snow = smoothstep(0.0, 0.1500000059604644775390625, (_101.g_CamPos.y + EyeVec.y) / 200.0); vec3 base = mix(grass, snow, vec3(grass_snow)); float edge = smoothstep(0.699999988079071044921875, 0.75, Normal.y); Color = mix(dirt, base, vec3(edge)); diff --git a/reference/shaders/frag/mix.frag b/reference/shaders/frag/mix.frag index 68e82273..6e7884ff 100644 --- a/reference/shaders/frag/mix.frag +++ b/reference/shaders/frag/mix.frag @@ -13,26 +13,8 @@ void main() bvec4 l = bvec4(false, true, false, false); FragColor = mix(vIn0, vIn1, l); bool f = true; - FragColor = vec4(mix(vIn2, vIn3, f)); - highp vec4 _35; - if (f) - { - _35 = vIn0; - } - else - { - _35 = vIn1; - } - FragColor = _35; - highp float _44; - if (f) - { - _44 = vIn2; - } - else - { - _44 = vIn3; - } - FragColor = vec4(_44); + FragColor = vec4(f ? vIn3 : vIn2); + FragColor = f ? vIn0 : vIn1; + FragColor = vec4(f ? vIn2 : vIn3); } diff --git a/reference/shaders/vert/ground.vert b/reference/shaders/vert/ground.vert index 44b19a99..e787f603 100644 --- a/reference/shaders/vert/ground.vert +++ b/reference/shaders/vert/ground.vert @@ -6,6 +6,18 @@ struct PatchData vec4 LODs; }; +layout(binding = 0, std140) uniform PerPatch +{ + PatchData Patches[256]; +} _53; + +layout(binding = 2, std140) uniform GlobalGround +{ + vec4 GroundScale; + vec4 GroundPosition; + vec4 InvGroundSize_PatchScale; +} _156; + layout(binding = 0, std140) uniform GlobalVSData { vec4 g_ViewProj_Row0; @@ -26,19 +38,7 @@ layout(binding = 0, std140) uniform GlobalVSData vec4 g_ShadowVP_Row1; vec4 g_ShadowVP_Row2; vec4 g_ShadowVP_Row3; -} _58; - -layout(binding = 0, std140) uniform PerPatch -{ - PatchData Patches[256]; -} _284; - -layout(binding = 2, std140) uniform GlobalGround -{ - vec4 GroundScale; - vec4 GroundPosition; - vec4 InvGroundSize_PatchScale; -} _381; +} _236; layout(binding = 1) uniform mediump sampler2D TexLOD; layout(binding = 0) uniform mediump sampler2D TexHeightmap; @@ -51,33 +51,33 @@ layout(location = 0) out vec2 TexCoord; vec2 warp_position() { - float vlod = dot(LODWeights, _284.Patches[(gl_InstanceID + SPIRV_Cross_BaseInstance)].LODs); - vlod = mix(vlod, _284.Patches[(gl_InstanceID + SPIRV_Cross_BaseInstance)].Position.w, all(equal(LODWeights, vec4(0.0)))); + float vlod = dot(LODWeights, _53.Patches[(gl_InstanceID + SPIRV_Cross_BaseInstance)].LODs); + vlod = all(equal(LODWeights, vec4(0.0))) ? _53.Patches[(gl_InstanceID + SPIRV_Cross_BaseInstance)].Position.w : vlod; float floor_lod = floor(vlod); float fract_lod = vlod - floor_lod; uint ufloor_lod = uint(floor_lod); uvec2 uPosition = uvec2(Position); uvec2 mask = (uvec2(1u) << uvec2(ufloor_lod, ufloor_lod + 1u)) - uvec2(1u); - uint _332; + uint _106; if (uPosition.x < 32u) { - _332 = mask.x; + _106 = mask.x; } else { - _332 = 0u; + _106 = 0u; } - uint _342 = _332; - uint _343; + uint _116 = _106; + uint _117; if (uPosition.y < 32u) { - _343 = mask.y; + _117 = mask.y; } else { - _343 = 0u; + _117 = 0u; } - uvec2 rounding = uvec2(_342, _343); + uvec2 rounding = uvec2(_116, _117); vec4 lower_upper_snapped = vec4((uPosition + rounding).xyxy & ~mask.xxyy); return mix(lower_upper_snapped.xy, lower_upper_snapped.zw, vec2(fract_lod)); } @@ -92,19 +92,19 @@ vec2 lod_factor(vec2 uv) void main() { - vec2 PatchPos = _284.Patches[(gl_InstanceID + SPIRV_Cross_BaseInstance)].Position.xz * _381.InvGroundSize_PatchScale.zw; + vec2 PatchPos = _53.Patches[(gl_InstanceID + SPIRV_Cross_BaseInstance)].Position.xz * _156.InvGroundSize_PatchScale.zw; vec2 WarpedPos = warp_position(); vec2 VertexPos = PatchPos + WarpedPos; - vec2 NormalizedPos = VertexPos * _381.InvGroundSize_PatchScale.xy; + vec2 NormalizedPos = VertexPos * _156.InvGroundSize_PatchScale.xy; vec2 param = NormalizedPos; vec2 lod = lod_factor(param); - vec2 Offset = _381.InvGroundSize_PatchScale.xy * exp2(lod.x); + vec2 Offset = _156.InvGroundSize_PatchScale.xy * exp2(lod.x); float Elevation = mix(textureLod(TexHeightmap, NormalizedPos + (Offset * 0.5), lod.x).x, textureLod(TexHeightmap, NormalizedPos + (Offset * 1.0), lod.x + 1.0).x, lod.y); vec3 WorldPos = vec3(NormalizedPos.x, Elevation, NormalizedPos.y); - WorldPos *= _381.GroundScale.xyz; - WorldPos += _381.GroundPosition.xyz; - EyeVec = WorldPos - _58.g_CamPos.xyz; - TexCoord = NormalizedPos + (_381.InvGroundSize_PatchScale.xy * 0.5); - gl_Position = (((_58.g_ViewProj_Row0 * WorldPos.x) + (_58.g_ViewProj_Row1 * WorldPos.y)) + (_58.g_ViewProj_Row2 * WorldPos.z)) + _58.g_ViewProj_Row3; + WorldPos *= _156.GroundScale.xyz; + WorldPos += _156.GroundPosition.xyz; + EyeVec = WorldPos - _236.g_CamPos.xyz; + TexCoord = NormalizedPos + (_156.InvGroundSize_PatchScale.xy * 0.5); + gl_Position = (((_236.g_ViewProj_Row0 * WorldPos.x) + (_236.g_ViewProj_Row1 * WorldPos.y)) + (_236.g_ViewProj_Row2 * WorldPos.z)) + _236.g_ViewProj_Row3; } diff --git a/reference/shaders/vert/ocean.vert b/reference/shaders/vert/ocean.vert index c542fe25..e9965de3 100644 --- a/reference/shaders/vert/ocean.vert +++ b/reference/shaders/vert/ocean.vert @@ -6,6 +6,19 @@ struct PatchData vec4 LODs; }; +layout(binding = 0, std140) uniform Offsets +{ + PatchData Patches[256]; +} _53; + +layout(binding = 4, std140) uniform GlobalOcean +{ + vec4 OceanScale; + vec4 OceanPosition; + vec4 InvOceanSize_PatchScale; + vec4 NormalTexCoordScale; +} _180; + layout(binding = 0, std140) uniform GlobalVSData { vec4 g_ViewProj_Row0; @@ -26,20 +39,7 @@ layout(binding = 0, std140) uniform GlobalVSData vec4 g_ShadowVP_Row1; vec4 g_ShadowVP_Row2; vec4 g_ShadowVP_Row3; -} _58; - -layout(binding = 0, std140) uniform Offsets -{ - PatchData Patches[256]; -} _284; - -layout(binding = 4, std140) uniform GlobalOcean -{ - vec4 OceanScale; - vec4 OceanPosition; - vec4 InvOceanSize_PatchScale; - vec4 NormalTexCoordScale; -} _405; +} _273; layout(binding = 1) uniform mediump sampler2D TexLOD; layout(binding = 0) uniform mediump sampler2D TexDisplacement; @@ -52,54 +52,54 @@ layout(location = 1) out vec4 TexCoord; vec2 warp_position() { - float vlod = dot(LODWeights, _284.Patches[(gl_InstanceID + SPIRV_Cross_BaseInstance)].LODs); - vlod = mix(vlod, _284.Patches[(gl_InstanceID + SPIRV_Cross_BaseInstance)].Position.w, all(equal(LODWeights, vec4(0.0)))); + float vlod = dot(LODWeights, _53.Patches[(gl_InstanceID + SPIRV_Cross_BaseInstance)].LODs); + vlod = all(equal(LODWeights, vec4(0.0))) ? _53.Patches[(gl_InstanceID + SPIRV_Cross_BaseInstance)].Position.w : vlod; float floor_lod = floor(vlod); float fract_lod = vlod - floor_lod; uint ufloor_lod = uint(floor_lod); uvec4 uPosition = uvec4(Position); uvec2 mask = (uvec2(1u) << uvec2(ufloor_lod, ufloor_lod + 1u)) - uvec2(1u); - uint _333; + uint _107; if (uPosition.x < 32u) { - _333 = mask.x; + _107 = mask.x; } else { - _333 = 0u; + _107 = 0u; } uvec4 rounding; - rounding.x = _333; - uint _345; + rounding.x = _107; + uint _119; if (uPosition.y < 32u) { - _345 = mask.x; + _119 = mask.x; } else { - _345 = 0u; + _119 = 0u; } - rounding.y = _345; - uint _356; + rounding.y = _119; + uint _130; if (uPosition.x < 32u) { - _356 = mask.y; + _130 = mask.y; } else { - _356 = 0u; + _130 = 0u; } - rounding.z = _356; - uint _368; + rounding.z = _130; + uint _142; if (uPosition.y < 32u) { - _368 = mask.y; + _142 = mask.y; } else { - _368 = 0u; + _142 = 0u; } - rounding.w = _368; + rounding.w = _142; vec4 lower_upper_snapped = vec4((uPosition.xyxy + rounding) & ~mask.xxyy); return mix(lower_upper_snapped.xy, lower_upper_snapped.zw, vec2(fract_lod)); } @@ -114,20 +114,20 @@ vec2 lod_factor(vec2 uv) void main() { - vec2 PatchPos = _284.Patches[(gl_InstanceID + SPIRV_Cross_BaseInstance)].Position.xz * _405.InvOceanSize_PatchScale.zw; + vec2 PatchPos = _53.Patches[(gl_InstanceID + SPIRV_Cross_BaseInstance)].Position.xz * _180.InvOceanSize_PatchScale.zw; vec2 WarpedPos = warp_position(); vec2 VertexPos = PatchPos + WarpedPos; - vec2 NormalizedPos = VertexPos * _405.InvOceanSize_PatchScale.xy; - vec2 NormalizedTex = NormalizedPos * _405.NormalTexCoordScale.zw; + vec2 NormalizedPos = VertexPos * _180.InvOceanSize_PatchScale.xy; + vec2 NormalizedTex = NormalizedPos * _180.NormalTexCoordScale.zw; vec2 param = NormalizedPos; vec2 lod = lod_factor(param); - vec2 Offset = (_405.InvOceanSize_PatchScale.xy * exp2(lod.x)) * _405.NormalTexCoordScale.zw; + vec2 Offset = (_180.InvOceanSize_PatchScale.xy * exp2(lod.x)) * _180.NormalTexCoordScale.zw; vec3 Displacement = mix(textureLod(TexDisplacement, NormalizedTex + (Offset * 0.5), lod.x).yxz, textureLod(TexDisplacement, NormalizedTex + (Offset * 1.0), lod.x + 1.0).yxz, vec3(lod.y)); vec3 WorldPos = vec3(NormalizedPos.x, 0.0, NormalizedPos.y) + Displacement; - WorldPos *= _405.OceanScale.xyz; - WorldPos += _405.OceanPosition.xyz; - EyeVec = WorldPos - _58.g_CamPos.xyz; - TexCoord = vec4(NormalizedTex, NormalizedTex * _405.NormalTexCoordScale.xy) + ((_405.InvOceanSize_PatchScale.xyxy * 0.5) * _405.NormalTexCoordScale.zwzw); - gl_Position = (((_58.g_ViewProj_Row0 * WorldPos.x) + (_58.g_ViewProj_Row1 * WorldPos.y)) + (_58.g_ViewProj_Row2 * WorldPos.z)) + _58.g_ViewProj_Row3; + WorldPos *= _180.OceanScale.xyz; + WorldPos += _180.OceanPosition.xyz; + EyeVec = WorldPos - _273.g_CamPos.xyz; + TexCoord = vec4(NormalizedTex, NormalizedTex * _180.NormalTexCoordScale.xy) + ((_180.InvOceanSize_PatchScale.xyxy * 0.5) * _180.NormalTexCoordScale.zwzw); + gl_Position = (((_273.g_ViewProj_Row0 * WorldPos.x) + (_273.g_ViewProj_Row1 * WorldPos.y)) + (_273.g_ViewProj_Row2 * WorldPos.z)) + _273.g_ViewProj_Row3; } diff --git a/reference/shaders/vulkan/frag/spec-constant.vk.frag.vk b/reference/shaders/vulkan/frag/spec-constant.vk.frag.vk index 14747d10..3481be4c 100644 --- a/reference/shaders/vulkan/frag/spec-constant.vk.frag.vk +++ b/reference/shaders/vulkan/frag/spec-constant.vk.frag.vk @@ -2,67 +2,67 @@ precision mediump float; precision highp int; -layout(constant_id = 1) const float _9 = 1.0; -layout(constant_id = 2) const float _11 = 2.0; -layout(constant_id = 3) const int _16 = 3; -layout(constant_id = 4) const int _25 = 4; -layout(constant_id = 5) const uint _34 = 5u; -layout(constant_id = 6) const uint _35 = 6u; -layout(constant_id = 7) const bool _56 = false; -layout(constant_id = 8) const bool _57 = true; +layout(constant_id = 1) const float a = 1.0; +layout(constant_id = 2) const float b = 2.0; +layout(constant_id = 3) const int c = 3; +layout(constant_id = 4) const int d = 4; +layout(constant_id = 5) const uint e = 5u; +layout(constant_id = 6) const uint f = 6u; +layout(constant_id = 7) const bool g = false; +layout(constant_id = 8) const bool h = true; struct Foo { - float elems[(_25 + 2)]; + float elems[(d + 2)]; }; layout(location = 0) out vec4 FragColor; void main() { - float t0 = _9; - float t1 = _11; - mediump uint c0 = (uint(_16) + 0u); - mediump int c1 = (-_16); - mediump int c2 = (~_16); - mediump int c3 = (_16 + _25); - mediump int c4 = (_16 - _25); - mediump int c5 = (_16 * _25); - mediump int c6 = (_16 / _25); - mediump uint c7 = (_34 / _35); - mediump int c8 = (_16 % _25); - mediump uint c9 = (_34 % _35); - mediump int c10 = (_16 >> _25); - mediump uint c11 = (_34 >> _35); - mediump int c12 = (_16 << _25); - mediump int c13 = (_16 | _25); - mediump int c14 = (_16 ^ _25); - mediump int c15 = (_16 & _25); - bool c16 = (_56 || _57); - bool c17 = (_56 && _57); - bool c18 = (!_56); - bool c19 = (_56 == _57); - bool c20 = (_56 != _57); - bool c21 = (_16 == _25); - bool c22 = (_16 != _25); - bool c23 = (_16 < _25); - bool c24 = (_34 < _35); - bool c25 = (_16 > _25); - bool c26 = (_34 > _35); - bool c27 = (_16 <= _25); - bool c28 = (_34 <= _35); - bool c29 = (_16 >= _25); - bool c30 = (_34 >= _35); + float t0 = a; + float t1 = b; + mediump uint c0 = (uint(c) + 0u); + mediump int c1 = (-c); + mediump int c2 = (~c); + mediump int c3 = (c + d); + mediump int c4 = (c - d); + mediump int c5 = (c * d); + mediump int c6 = (c / d); + mediump uint c7 = (e / f); + mediump int c8 = (c % d); + mediump uint c9 = (e % f); + mediump int c10 = (c >> d); + mediump uint c11 = (e >> f); + mediump int c12 = (c << d); + mediump int c13 = (c | d); + mediump int c14 = (c ^ d); + mediump int c15 = (c & d); + bool c16 = (g || h); + bool c17 = (g && h); + bool c18 = (!g); + bool c19 = (g == h); + bool c20 = (g != h); + bool c21 = (c == d); + bool c22 = (c != d); + bool c23 = (c < d); + bool c24 = (e < f); + bool c25 = (c > d); + bool c26 = (e > f); + bool c27 = (c <= d); + bool c28 = (e <= f); + bool c29 = (c >= d); + bool c30 = (e >= f); mediump int c31 = c8 + c3; - mediump int c32 = int(_34 + 0u); - bool c33 = (_16 != int(0u)); - bool c34 = (_34 != 0u); - mediump int c35 = int(_56); - mediump uint c36 = uint(_56); - float c37 = float(_56); - float vec0[_25][(_16 + 3)]; - float vec1[(_16 + 2)][(_25 + 5)]; + mediump int c32 = int(e + 0u); + bool c33 = (c != int(0u)); + bool c34 = (e != 0u); + mediump int c35 = int(g); + mediump uint c36 = uint(g); + float c37 = float(g); + float vec0[d][(c + 3)]; + float vec1[(c + 2)][(d + 5)]; Foo foo; - FragColor = ((vec4(t0 + t1) + vec4(vec0[0][0])) + vec4(vec1[0][0])) + vec4(foo.elems[_16]); + FragColor = ((vec4(t0 + t1) + vec4(vec0[0][0])) + vec4(vec1[0][0])) + vec4(foo.elems[c]); } diff --git a/spirv_glsl.cpp b/spirv_glsl.cpp index 65fccee5..2811bcb4 100644 --- a/spirv_glsl.cpp +++ b/spirv_glsl.cpp @@ -2378,6 +2378,11 @@ void CompilerGLSL::emit_mix_op(uint32_t result_type, uint32_t id, uint32_t left, bool has_boolean_mix = (options.es && options.version >= 310) || (!options.es && options.version >= 450); bool trivial_mix = to_trivial_mix_op(restype, mix_op, left, right, lerp); + // Cannot use boolean mix when the lerp argument is just one boolean, + // fall back to regular trinary statements. + if (lerptype.vecsize == 1) + has_boolean_mix = false; + // If we can reduce the mix to a simple cast, do so. // This helps for cases like int(bool), uint(bool) which is implemented with // OpSelect bool 1 0.