mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-19 22:11:01 +01:00
Integer division or modulo is undefined behaviour in SPIR-V when the divisor is zero, or when the dividend is the most negative number representable by the result type and the divisor is negative one. This patch makes us avoid this undefined behaviour and instead ensures we adhere to the WGSL spec in these cases: for divisions the expression evaluates to the value of the dividend, and for modulos the expression evaluates to zero. Similarily to how we handle these cases for the MSL and HLSL backends, prior to emitting each function we emit code for any helper functions required by that function's expressions. In this case that is helper functions for integer division and modulo. Then, when emitting the actual function's body, if we encounter an expression which needs wrapped we instead emit a function call to the helper.
157 lines
4.3 KiB
Plaintext
157 lines
4.3 KiB
Plaintext
; SPIR-V
|
|
; Version: 1.0
|
|
; Generator: rspirv
|
|
; Bound: 114
|
|
OpCapability Shader
|
|
%1 = OpExtInstImport "GLSL.std.450"
|
|
OpMemoryModel Logical GLSL450
|
|
OpEntryPoint Vertex %46 "vs_main" %39 %42 %44
|
|
OpEntryPoint Fragment %106 "fs_main" %99 %102 %105
|
|
OpExecutionMode %106 OriginUpperLeft
|
|
OpMemberDecorate %6 0 Offset 0
|
|
OpMemberDecorate %6 1 Offset 16
|
|
OpMemberDecorate %8 0 Offset 0
|
|
OpMemberDecorate %8 0 ColMajor
|
|
OpMemberDecorate %8 0 MatrixStride 16
|
|
OpMemberDecorate %8 1 Offset 64
|
|
OpMemberDecorate %8 1 ColMajor
|
|
OpMemberDecorate %8 1 MatrixStride 16
|
|
OpDecorate %14 DescriptorSet 0
|
|
OpDecorate %14 Binding 0
|
|
OpDecorate %15 Block
|
|
OpMemberDecorate %15 0 Offset 0
|
|
OpDecorate %17 DescriptorSet 0
|
|
OpDecorate %17 Binding 1
|
|
OpDecorate %19 DescriptorSet 0
|
|
OpDecorate %19 Binding 2
|
|
OpDecorate %39 BuiltIn VertexIndex
|
|
OpDecorate %42 BuiltIn Position
|
|
OpDecorate %44 Location 0
|
|
OpDecorate %99 BuiltIn FragCoord
|
|
OpDecorate %102 Location 0
|
|
OpDecorate %105 Location 0
|
|
%2 = OpTypeVoid
|
|
%4 = OpTypeFloat 32
|
|
%3 = OpTypeVector %4 4
|
|
%5 = OpTypeVector %4 3
|
|
%6 = OpTypeStruct %3 %5
|
|
%7 = OpTypeMatrix %3 4
|
|
%8 = OpTypeStruct %7 %7
|
|
%9 = OpTypeInt 32 0
|
|
%10 = OpTypeInt 32 1
|
|
%11 = OpTypeMatrix %5 3
|
|
%12 = OpTypeImage %4 Cube 0 0 0 1 Unknown
|
|
%13 = OpTypeSampler
|
|
%15 = OpTypeStruct %8
|
|
%16 = OpTypePointer Uniform %15
|
|
%14 = OpVariable %16 Uniform
|
|
%18 = OpTypePointer UniformConstant %12
|
|
%17 = OpVariable %18 UniformConstant
|
|
%20 = OpTypePointer UniformConstant %13
|
|
%19 = OpVariable %20 UniformConstant
|
|
%22 = OpTypeFunction %10 %10 %10
|
|
%26 = OpTypeBool
|
|
%27 = OpConstant %10 0
|
|
%29 = OpConstant %10 -2147483648
|
|
%30 = OpConstant %10 -1
|
|
%35 = OpConstant %10 1
|
|
%40 = OpTypePointer Input %9
|
|
%39 = OpVariable %40 Input
|
|
%43 = OpTypePointer Output %3
|
|
%42 = OpVariable %43 Output
|
|
%45 = OpTypePointer Output %5
|
|
%44 = OpVariable %45 Output
|
|
%47 = OpTypeFunction %2
|
|
%48 = OpTypePointer Uniform %8
|
|
%49 = OpConstant %9 0
|
|
%51 = OpConstant %10 2
|
|
%52 = OpConstant %4 4.0
|
|
%53 = OpConstant %4 1.0
|
|
%54 = OpConstant %4 0.0
|
|
%56 = OpTypePointer Function %10
|
|
%57 = OpConstantNull %10
|
|
%59 = OpConstantNull %10
|
|
%74 = OpTypePointer Uniform %7
|
|
%75 = OpTypePointer Uniform %3
|
|
%76 = OpConstant %9 1
|
|
%83 = OpConstant %9 2
|
|
%100 = OpTypePointer Input %3
|
|
%99 = OpVariable %100 Input
|
|
%103 = OpTypePointer Input %5
|
|
%102 = OpVariable %103 Input
|
|
%105 = OpVariable %43 Output
|
|
%111 = OpTypeSampledImage %12
|
|
%21 = OpFunction %10 None %22
|
|
%23 = OpFunctionParameter %10
|
|
%24 = OpFunctionParameter %10
|
|
%25 = OpLabel
|
|
%28 = OpIEqual %26 %24 %27
|
|
%31 = OpIEqual %26 %23 %29
|
|
%32 = OpIEqual %26 %24 %30
|
|
%33 = OpLogicalAnd %26 %31 %32
|
|
%34 = OpLogicalOr %26 %28 %33
|
|
%36 = OpSelect %10 %34 %35 %24
|
|
%37 = OpSDiv %10 %23 %36
|
|
OpReturnValue %37
|
|
OpFunctionEnd
|
|
%46 = OpFunction %2 None %47
|
|
%38 = OpLabel
|
|
%55 = OpVariable %56 Function %57
|
|
%58 = OpVariable %56 Function %59
|
|
%41 = OpLoad %9 %39
|
|
%50 = OpAccessChain %48 %14 %49
|
|
OpBranch %60
|
|
%60 = OpLabel
|
|
%61 = OpBitcast %10 %41
|
|
%62 = OpFunctionCall %10 %21 %61 %51
|
|
OpStore %55 %62
|
|
%63 = OpBitcast %10 %41
|
|
%64 = OpBitwiseAnd %10 %63 %35
|
|
OpStore %58 %64
|
|
%65 = OpLoad %10 %55
|
|
%66 = OpConvertSToF %4 %65
|
|
%67 = OpFMul %4 %66 %52
|
|
%68 = OpFSub %4 %67 %53
|
|
%69 = OpLoad %10 %58
|
|
%70 = OpConvertSToF %4 %69
|
|
%71 = OpFMul %4 %70 %52
|
|
%72 = OpFSub %4 %71 %53
|
|
%73 = OpCompositeConstruct %3 %68 %72 %54 %53
|
|
%77 = OpAccessChain %75 %50 %76 %49
|
|
%78 = OpLoad %3 %77
|
|
%79 = OpVectorShuffle %5 %78 %78 0 1 2
|
|
%80 = OpAccessChain %75 %50 %76 %76
|
|
%81 = OpLoad %3 %80
|
|
%82 = OpVectorShuffle %5 %81 %81 0 1 2
|
|
%84 = OpAccessChain %75 %50 %76 %83
|
|
%85 = OpLoad %3 %84
|
|
%86 = OpVectorShuffle %5 %85 %85 0 1 2
|
|
%87 = OpCompositeConstruct %11 %79 %82 %86
|
|
%88 = OpTranspose %11 %87
|
|
%89 = OpAccessChain %74 %50 %49
|
|
%90 = OpLoad %7 %89
|
|
%91 = OpMatrixTimesVector %3 %90 %73
|
|
%92 = OpVectorShuffle %5 %91 %91 0 1 2
|
|
%93 = OpMatrixTimesVector %5 %88 %92
|
|
%94 = OpCompositeConstruct %6 %73 %93
|
|
%95 = OpCompositeExtract %3 %94 0
|
|
OpStore %42 %95
|
|
%96 = OpCompositeExtract %5 %94 1
|
|
OpStore %44 %96
|
|
OpReturn
|
|
OpFunctionEnd
|
|
%106 = OpFunction %2 None %47
|
|
%97 = OpLabel
|
|
%101 = OpLoad %3 %99
|
|
%104 = OpLoad %5 %102
|
|
%98 = OpCompositeConstruct %6 %101 %104
|
|
%107 = OpLoad %12 %17
|
|
%108 = OpLoad %13 %19
|
|
OpBranch %109
|
|
%109 = OpLabel
|
|
%110 = OpCompositeExtract %5 %98 1
|
|
%112 = OpSampledImage %111 %107 %108
|
|
%113 = OpImageSampleImplicitLod %3 %112 %110
|
|
OpStore %105 %113
|
|
OpReturn
|
|
OpFunctionEnd |