Skip to content

Instantly share code, notes, and snippets.

@SausCode
Created November 28, 2019 21:01
Show Gist options
  • Save SausCode/a3572e7b700bcd29b53fb7c3070cbe0e to your computer and use it in GitHub Desktop.
Save SausCode/a3572e7b700bcd29b53fb7c3070cbe0e to your computer and use it in GitHub Desktop.
SPV Diss gl_ClipDistance Issues
#pragma clang diagnostic ignored "-Wmissing-prototypes"
#pragma clang diagnostic ignored "-Wmissing-braces"
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
template<typename T, size_t Num>
struct spvUnsafeArray
{
T elements[Num ? Num : 1];
thread T& operator [] (size_t pos) thread
{
return elements[pos];
}
constexpr const thread T& operator [] (size_t pos) const thread
{
return elements[pos];
}
device T& operator [] (size_t pos) device
{
return elements[pos];
}
constexpr const device T& operator [] (size_t pos) const device
{
return elements[pos];
}
constexpr const constant T& operator [] (size_t pos) const constant
{
return elements[pos];
}
threadgroup T& operator [] (size_t pos) threadgroup
{
return elements[pos];
}
constexpr const threadgroup T& operator [] (size_t pos) const threadgroup
{
return elements[pos];
}
};
constant bool _26_tmp [[function_constant(32)]];
constant bool _26 = is_function_constant_defined(_26_tmp) ? _26_tmp : true;
constant uint _139_tmp [[function_constant(1216)]];
constant uint _139 = is_function_constant_defined(_139_tmp) ? _139_tmp : 0u;
constant uint _141_tmp [[function_constant(1217)]];
constant uint _141 = is_function_constant_defined(_141_tmp) ? _141_tmp : 1u;
constant uint _143_tmp [[function_constant(1218)]];
constant uint _143 = is_function_constant_defined(_143_tmp) ? _143_tmp : 2u;
constant uint _145_tmp [[function_constant(1219)]];
constant uint _145 = is_function_constant_defined(_145_tmp) ? _145_tmp : 3u;
constant uint _149_tmp [[function_constant(1220)]];
constant uint _149 = is_function_constant_defined(_149_tmp) ? _149_tmp : 0u;
constant uint _151_tmp [[function_constant(1221)]];
constant uint _151 = is_function_constant_defined(_151_tmp) ? _151_tmp : 1u;
constant uint _153_tmp [[function_constant(1222)]];
constant uint _153 = is_function_constant_defined(_153_tmp) ? _153_tmp : 2u;
constant uint _155_tmp [[function_constant(1223)]];
constant uint _155 = is_function_constant_defined(_155_tmp) ? _155_tmp : 3u;
struct main0_out
{
float4 m_34 [[color(0), index(0)]];
float4 m_35 [[color(1), index(0)]];
};
struct main0_in
{
float4 m_29 [[user(locn2)]];
float3 m_32 [[user(locn3)]];
};
static inline __attribute__((always_inline))
void ps_main(thread spvUnsafeArray<float4, 5> (&shader_in), thread sampler v_21, thread texture2d<float> v_24, thread float4& v_34, thread float4& v_35, thread float4& v_46)
{
float4 _48 = v_46;
_48.x = dot(shader_in[3].xyz, shader_in[3].xyz);
v_46 = _48;
float4 _53 = v_46;
_53.x = rsqrt(v_46.x);
v_46 = _53;
float4 _63 = v_46;
_63.y = fma(shader_in[3].z, v_46.x, as_type<float>(1065353216u));
v_46 = _63;
float2 _70 = v_46.xx * shader_in[3].xy;
v_46 = float4(_70.x, v_46.y, _70.y, v_46.w);
float4 _77 = v_46;
_77.y = rsqrt(v_46.y);
v_46 = _77;
float2 _82 = v_46.yy * v_46.xz;
v_46 = float4(_82.x, _82.y, v_46.z, v_46.w);
float2 _94 = fma(v_46.xy, as_type<float2>(uint2(1052050676u)), as_type<float2>(uint2(1056964608u)));
v_34 = float4(_94.x, _94.y, v_34.z, v_34.w);
float2 _99 = as_type<float2>(uint2(0u, 1056964608u));
v_34 = float4(v_34.x, v_34.y, _99.x, _99.y);
float3 _112 = v_24.sample(v_21, shader_in[2].zwzz.xy).xyz;
v_46 = float4(_112.x, _112.y, _112.z, v_46.w);
v_35 = float4(v_46.xyz.x, v_46.xyz.y, v_46.xyz.z, v_35.w);
float4 _121 = v_35;
_121.w = as_type<float>(0u);
v_35 = _121;
}
fragment main0_out main0(main0_in in [[stage_in]], texture2d<float> v_24 [[texture(0)]], sampler v_21 [[sampler(0)]])
{
main0_out out = {};
spvUnsafeArray<float4, 5> shader_in;
shader_in[2] = in.m_29;
shader_in[3] = float4(in.m_32.x, in.m_32.y, in.m_32.z, shader_in[3].w);
float4 _136 = shader_in[1];
_136.x = gl_ClipDistance[0];
shader_in[1] = _136;
float4 v_46;
ps_main(shader_in, v_21, v_24, out.m_34, out.m_35, v_46);
out.m_34 = float4(out.m_34[_139], out.m_34[_141], out.m_34[_143], out.m_34[_145]);
out.m_35 = float4(out.m_35[_149], out.m_35[_151], out.m_35[_153], out.m_35[_155]);
return out;
}
; SPIR-V
; Version: 1.3
; Generator: Khronos; 0
; Bound: 158
; Schema: 0
OpCapability Shader
OpCapability ImageQuery
OpCapability DerivativeControl
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main "main" %clip_distances %__2 %__3 %__4 %__5
OpExecutionMode %main OriginUpperLeft
OpSource Unknown 0 %3
OpName %shader_in "shader_in"
OpName %clip_distances "clip_distances"
OpName %ps_main "ps_main"
OpName %_ ""
OpName %__0 ""
OpName %__1 ""
OpName %__2 ""
OpName %__3 ""
OpName %__4 ""
OpName %__5 ""
OpName %__6 ""
OpName %__7 ""
OpName %__8 ""
OpName %__9 ""
OpName %__10 ""
OpName %__11 ""
OpName %__12 ""
OpName %__13 ""
OpName %__14 ""
OpName %main "main"
OpDecorate %clip_distances BuiltIn ClipDistance
OpDecorate %_ DescriptorSet 0
OpDecorate %_ Binding 16
OpDecorate %__0 DescriptorSet 0
OpDecorate %__0 Binding 32
OpDecorate %__1 SpecId 32
OpDecorate %__2 Location 2
OpDecorate %__3 Location 3
OpDecorate %__4 Location 0
OpDecorate %__4 Index 0
OpDecorate %__5 Location 1
OpDecorate %__5 Index 0
OpDecorate %__7 SpecId 1216
OpDecorate %__8 SpecId 1217
OpDecorate %__9 SpecId 1218
OpDecorate %__10 SpecId 1219
OpDecorate %__11 SpecId 1220
OpDecorate %__12 SpecId 1221
OpDecorate %__13 SpecId 1222
OpDecorate %__14 SpecId 1223
%uint = OpTypeInt 32 0
%uint_5 = OpConstant %uint 5
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%_arr_v4float_uint_5 = OpTypeArray %v4float %uint_5
%_ptr_Private__arr_v4float_uint_5 = OpTypePointer Private %_arr_v4float_uint_5
%uint_1 = OpConstant %uint 1
%_arr_float_uint_1 = OpTypeArray %float %uint_1
%_ptr_Input__arr_float_uint_1 = OpTypePointer Input %_arr_float_uint_1
%void = OpTypeVoid
%17 = OpTypeFunction %void
%19 = OpTypeSampler
%_ptr_UniformConstant_19 = OpTypePointer UniformConstant %19
%22 = OpTypeImage %float 2D 0 0 0 1 Unknown
%_ptr_UniformConstant_22 = OpTypePointer UniformConstant %22
%bool = OpTypeBool
%__1 = OpSpecConstantTrue %bool
%27 = OpTypeImage %float 2D 1 0 0 1 Unknown
%_ptr_Input_v4float = OpTypePointer Input %v4float
%v3float = OpTypeVector %float 3
%_ptr_Input_v3float = OpTypePointer Input %v3float
%_ptr_Output_v4float = OpTypePointer Output %v4float
%int = OpTypeInt 32 1
%int_3 = OpConstant %int 3
%_ptr_Private_v4float = OpTypePointer Private %v4float
%uint_1065353216 = OpConstant %uint 1065353216
%v2float = OpTypeVector %float 2
%uint_1052050676 = OpConstant %uint 1052050676
%v2uint = OpTypeVector %uint 2
%89 = OpConstantComposite %v2uint %uint_1052050676 %uint_1052050676
%uint_1056964608 = OpConstant %uint 1056964608
%92 = OpConstantComposite %v2uint %uint_1056964608 %uint_1056964608
%uint_0 = OpConstant %uint 0
%98 = OpConstantComposite %v2uint %uint_0 %uint_1056964608
%int_2 = OpConstant %int 2
%107 = OpTypeSampledImage %22
%int_0 = OpConstant %int 0
%_ptr_Input_float = OpTypePointer Input %float
%int_1 = OpConstant %int 1
%__7 = OpSpecConstant %uint 0
%__8 = OpSpecConstant %uint 1
%__9 = OpSpecConstant %uint 2
%__10 = OpSpecConstant %uint 3
%__11 = OpSpecConstant %uint 0
%__12 = OpSpecConstant %uint 1
%__13 = OpSpecConstant %uint 2
%__14 = OpSpecConstant %uint 3
%shader_in = OpVariable %_ptr_Private__arr_v4float_uint_5 Private
%clip_distances = OpVariable %_ptr_Input__arr_float_uint_1 Input
%_ = OpVariable %_ptr_UniformConstant_19 UniformConstant
%__0 = OpVariable %_ptr_UniformConstant_22 UniformConstant
%__2 = OpVariable %_ptr_Input_v4float Input
%__3 = OpVariable %_ptr_Input_v3float Input
%__4 = OpVariable %_ptr_Output_v4float Output
%__5 = OpVariable %_ptr_Output_v4float Output
%__6 = OpVariable %_ptr_Private_v4float Private
%ps_main = OpFunction %void None %17
%18 = OpLabel
%39 = OpAccessChain %_ptr_Private_v4float %shader_in %int_3
%40 = OpLoad %v4float %39
%41 = OpVectorShuffle %v3float %40 %40 0 1 2
%42 = OpAccessChain %_ptr_Private_v4float %shader_in %int_3
%43 = OpLoad %v4float %42
%44 = OpVectorShuffle %v3float %43 %43 0 1 2
%45 = OpDot %float %41 %44
%47 = OpLoad %v4float %__6
%48 = OpCompositeInsert %v4float %45 %47 0
OpStore %__6 %48
%49 = OpLoad %v4float %__6
%50 = OpCompositeExtract %float %49 0
%51 = OpExtInst %float %1 InverseSqrt %50
%52 = OpLoad %v4float %__6
%53 = OpCompositeInsert %v4float %51 %52 0
OpStore %__6 %53
%54 = OpAccessChain %_ptr_Private_v4float %shader_in %int_3
%55 = OpLoad %v4float %54
%56 = OpCompositeExtract %float %55 2
%57 = OpLoad %v4float %__6
%58 = OpCompositeExtract %float %57 0
%60 = OpBitcast %float %uint_1065353216
%61 = OpExtInst %float %1 Fma %56 %58 %60
%62 = OpLoad %v4float %__6
%63 = OpCompositeInsert %v4float %61 %62 1
OpStore %__6 %63
%64 = OpLoad %v4float %__6
%66 = OpVectorShuffle %v2float %64 %64 0 0
%67 = OpAccessChain %_ptr_Private_v4float %shader_in %int_3
%68 = OpLoad %v4float %67
%69 = OpVectorShuffle %v2float %68 %68 0 1
%70 = OpFMul %v2float %66 %69
%71 = OpLoad %v4float %__6
%72 = OpVectorShuffle %v4float %71 %70 4 1 5 3
OpStore %__6 %72
%73 = OpLoad %v4float %__6
%74 = OpCompositeExtract %float %73 1
%75 = OpExtInst %float %1 InverseSqrt %74
%76 = OpLoad %v4float %__6
%77 = OpCompositeInsert %v4float %75 %76 1
OpStore %__6 %77
%78 = OpLoad %v4float %__6
%79 = OpVectorShuffle %v2float %78 %78 1 1
%80 = OpLoad %v4float %__6
%81 = OpVectorShuffle %v2float %80 %80 0 2
%82 = OpFMul %v2float %79 %81
%83 = OpLoad %v4float %__6
%84 = OpVectorShuffle %v4float %83 %82 4 5 2 3
OpStore %__6 %84
%85 = OpLoad %v4float %__6
%86 = OpVectorShuffle %v2float %85 %85 0 1
%90 = OpBitcast %v2float %89
%93 = OpBitcast %v2float %92
%94 = OpExtInst %v2float %1 Fma %86 %90 %93
%95 = OpLoad %v4float %__4
%96 = OpVectorShuffle %v4float %95 %94 4 5 2 3
OpStore %__4 %96
%99 = OpBitcast %v2float %98
%100 = OpLoad %v4float %__4
%101 = OpVectorShuffle %v4float %100 %99 0 1 4 5
OpStore %__4 %101
%103 = OpAccessChain %_ptr_Private_v4float %shader_in %int_2
%104 = OpLoad %v4float %103
%105 = OpVectorShuffle %v4float %104 %104 2 3 2 2
%106 = OpVectorShuffle %v2float %105 %105 0 1
%108 = OpLoad %22 %__0
%109 = OpLoad %19 %_
%110 = OpSampledImage %107 %108 %109
%111 = OpImageSampleImplicitLod %v4float %110 %106
%112 = OpVectorShuffle %v3float %111 %111 0 1 2
%113 = OpLoad %v4float %__6
%114 = OpVectorShuffle %v4float %113 %112 4 5 6 3
OpStore %__6 %114
%115 = OpLoad %v4float %__6
%116 = OpVectorShuffle %v3float %115 %115 0 1 2
%117 = OpLoad %v4float %__5
%118 = OpVectorShuffle %v4float %117 %116 4 5 6 3
OpStore %__5 %118
%119 = OpBitcast %float %uint_0
%120 = OpLoad %v4float %__5
%121 = OpCompositeInsert %v4float %119 %120 3
OpStore %__5 %121
OpReturn
OpFunctionEnd
%main = OpFunction %void None %17
%122 = OpLabel
%123 = OpLoad %v4float %__2
%124 = OpAccessChain %_ptr_Private_v4float %shader_in %int_2
OpStore %124 %123
%125 = OpLoad %v3float %__3
%126 = OpAccessChain %_ptr_Private_v4float %shader_in %int_3
%127 = OpLoad %v4float %126
%128 = OpVectorShuffle %v4float %127 %125 4 5 6 3
OpStore %126 %128
%131 = OpAccessChain %_ptr_Input_float %clip_distances %int_0
%132 = OpLoad %float %131
%134 = OpAccessChain %_ptr_Private_v4float %shader_in %int_1
%135 = OpLoad %v4float %134
%136 = OpCompositeInsert %v4float %132 %135 0
OpStore %134 %136
%137 = OpFunctionCall %void %ps_main
%138 = OpLoad %v4float %__4
%140 = OpVectorExtractDynamic %float %138 %__7
%142 = OpVectorExtractDynamic %float %138 %__8
%144 = OpVectorExtractDynamic %float %138 %__9
%146 = OpVectorExtractDynamic %float %138 %__10
%147 = OpCompositeConstruct %v4float %140 %142 %144 %146
OpStore %__4 %147
%148 = OpLoad %v4float %__5
%150 = OpVectorExtractDynamic %float %148 %__11
%152 = OpVectorExtractDynamic %float %148 %__12
%154 = OpVectorExtractDynamic %float %148 %__13
%156 = OpVectorExtractDynamic %float %148 %__14
%157 = OpCompositeConstruct %v4float %150 %152 %154 %156
OpStore %__5 %157
OpReturn
OpFunctionEnd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment