Files
wgpu/naga/tests/out/spv/const-exprs.spvasm
Jamie Nicol 7b54f9dfd2 [naga wgsl-in] Concretize base type prior to non-constant indexed access (#7260)
Parsing currently fails for shaders that attempt to dynamically index
an abstract-typed array (or vector, etc), like so:

    var x = array(1, 2, 3)[i];

This is caused by attempting to concretize the Expression::Access
expression, which the ConstantEvaluator fails to do so due to the
presence of a non-constant expression.

To solve this, this patch concretizes the base type *prior* to
indexing it (for non-constant indices), meaning the constant evaluator
never sees any non-constant expressions. This matches the WGSL
specification:

    When an abstract array value e is indexed by an expression that is
    not a const-expression, then the array is concretized before the
    index is applied.

(Similar applies for both vectors and matrices, too.)

This may be somewhat non-optimal in that if there are multiple
accesses of the same abstract expression, we will produce duplicated
concretized versions of that expression. This seems unlikely to be a
major issue in practice, and we can always improve this if and when we
encounter a real issue caused by it.
2025-03-03 09:33:08 -05:00

226 lines
5.5 KiB
Plaintext

; SPIR-V
; Version: 1.1
; Generator: rspirv
; Bound: 166
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %156 "main"
OpExecutionMode %156 LocalSize 2 3 1
OpDecorate %9 ArrayStride 4
OpDecorate %14 ArrayStride 4
%2 = OpTypeVoid
%3 = OpTypeInt 32 0
%4 = OpTypeInt 32 1
%5 = OpTypeBool
%6 = OpTypeVector %4 4
%7 = OpTypeFloat 32
%8 = OpTypeVector %7 4
%10 = OpConstant %3 2
%9 = OpTypeArray %7 %10
%11 = OpTypeVector %7 2
%12 = OpTypeVector %5 2
%13 = OpTypeVector %4 3
%15 = OpConstant %3 9
%14 = OpTypeArray %4 %15
%16 = OpConstant %4 3
%17 = OpConstantTrue %5
%18 = OpConstantFalse %5
%19 = OpConstant %4 4
%20 = OpConstant %4 8
%21 = OpConstant %7 3.141
%22 = OpConstant %7 6.282
%23 = OpConstant %7 0.44444445
%24 = OpConstant %7 0.0
%25 = OpConstantComposite %8 %23 %24 %24 %24
%26 = OpConstant %4 0
%27 = OpConstant %4 1
%28 = OpConstant %4 2
%29 = OpConstant %7 4.0
%30 = OpConstant %7 5.0
%31 = OpConstantComposite %11 %29 %30
%32 = OpConstantComposite %12 %17 %18
%35 = OpTypeFunction %2
%36 = OpConstantComposite %6 %19 %16 %28 %27
%38 = OpTypePointer Function %6
%43 = OpTypePointer Function %4
%47 = OpConstant %4 6
%52 = OpConstant %4 30
%53 = OpConstant %4 70
%56 = OpConstantNull %4
%58 = OpConstantNull %4
%61 = OpConstantNull %6
%72 = OpConstant %4 -4
%73 = OpConstantComposite %6 %72 %72 %72 %72
%82 = OpConstant %7 1.0
%83 = OpConstant %7 2.0
%84 = OpConstantComposite %8 %83 %82 %82 %82
%86 = OpTypePointer Function %8
%91 = OpTypePointer Function %9
%92 = OpConstantNull %9
%97 = OpTypeFunction %3 %4
%98 = OpConstant %3 10
%99 = OpConstant %3 20
%100 = OpConstant %3 30
%101 = OpConstant %3 0
%108 = OpConstantNull %3
%111 = OpConstantComposite %13 %27 %27 %27
%112 = OpConstantComposite %13 %26 %27 %28
%113 = OpConstantComposite %13 %27 %26 %28
%115 = OpTypePointer Function %13
%122 = OpTypePointer Function %5
%134 = OpTypeFunction %2 %3
%135 = OpConstant %3 1
%136 = OpConstant %4 5
%137 = OpConstant %4 7
%138 = OpConstant %4 9
%139 = OpConstantComposite %14 %27 %28 %16 %19 %136 %47 %137 %20 %138
%140 = OpConstantComposite %6 %27 %28 %16 %19
%142 = OpTypePointer Function %7
%144 = OpTypePointer Function %3
%146 = OpConstantNull %4
%148 = OpConstantNull %4
%150 = OpTypePointer Function %14
%34 = OpFunction %2 None %35
%33 = OpLabel
%37 = OpVariable %38 Function %36
OpBranch %39
%39 = OpLabel
OpReturn
OpFunctionEnd
%41 = OpFunction %2 None %35
%40 = OpLabel
%42 = OpVariable %43 Function %28
OpBranch %44
%44 = OpLabel
OpReturn
OpFunctionEnd
%46 = OpFunction %2 None %35
%45 = OpLabel
%48 = OpVariable %43 Function %47
OpBranch %49
%49 = OpLabel
OpReturn
OpFunctionEnd
%51 = OpFunction %2 None %35
%50 = OpLabel
%60 = OpVariable %38 Function %61
%55 = OpVariable %43 Function %56
%59 = OpVariable %43 Function %53
%54 = OpVariable %43 Function %52
%57 = OpVariable %43 Function %58
OpBranch %62
%62 = OpLabel
%63 = OpLoad %4 %54
OpStore %55 %63
%64 = OpLoad %4 %55
OpStore %57 %64
%65 = OpLoad %4 %54
%66 = OpLoad %4 %55
%67 = OpLoad %4 %57
%68 = OpLoad %4 %59
%69 = OpCompositeConstruct %6 %65 %66 %67 %68
OpStore %60 %69
OpReturn
OpFunctionEnd
%71 = OpFunction %2 None %35
%70 = OpLabel
%74 = OpVariable %38 Function %73
OpBranch %75
%75 = OpLabel
OpReturn
OpFunctionEnd
%77 = OpFunction %2 None %35
%76 = OpLabel
%78 = OpVariable %38 Function %73
OpBranch %79
%79 = OpLabel
OpReturn
OpFunctionEnd
%81 = OpFunction %2 None %35
%80 = OpLabel
%85 = OpVariable %86 Function %84
OpBranch %87
%87 = OpLabel
OpReturn
OpFunctionEnd
%89 = OpFunction %2 None %35
%88 = OpLabel
%90 = OpVariable %91 Function %92
OpBranch %93
%93 = OpLabel
OpReturn
OpFunctionEnd
%96 = OpFunction %3 None %97
%95 = OpFunctionParameter %4
%94 = OpLabel
OpBranch %102
%102 = OpLabel
OpSelectionMerge %103 None
OpSwitch %95 %107 0 %104 1 %105 2 %106
%104 = OpLabel
OpReturnValue %98
%105 = OpLabel
OpReturnValue %99
%106 = OpLabel
OpReturnValue %100
%107 = OpLabel
OpReturnValue %101
%103 = OpLabel
OpReturnValue %108
OpFunctionEnd
%110 = OpFunction %2 None %35
%109 = OpLabel
%114 = OpVariable %115 Function %111
%116 = OpVariable %115 Function %112
%117 = OpVariable %115 Function %113
OpBranch %118
%118 = OpLabel
OpReturn
OpFunctionEnd
%120 = OpFunction %2 None %35
%119 = OpLabel
%128 = OpVariable %122 Function %18
%125 = OpVariable %122 Function %17
%121 = OpVariable %122 Function %18
%129 = OpVariable %122 Function %17
%126 = OpVariable %122 Function %18
%123 = OpVariable %122 Function %17
%127 = OpVariable %122 Function %17
%124 = OpVariable %122 Function %18
OpBranch %130
%130 = OpLabel
OpReturn
OpFunctionEnd
%133 = OpFunction %2 None %134
%132 = OpFunctionParameter %3
%131 = OpLabel
%143 = OpVariable %144 Function %135
%147 = OpVariable %43 Function %148
%141 = OpVariable %142 Function %82
%145 = OpVariable %43 Function %146
%151 = OpVariable %150 Function
OpBranch %149
%149 = OpLabel
OpStore %151 %139
%152 = OpAccessChain %43 %151 %132
%153 = OpLoad %4 %152
OpStore %145 %153
%154 = OpVectorExtractDynamic %4 %140 %132
OpStore %147 %154
OpReturn
OpFunctionEnd
%156 = OpFunction %2 None %35
%155 = OpLabel
OpBranch %157
%157 = OpLabel
%158 = OpFunctionCall %2 %34
%159 = OpFunctionCall %2 %41
%160 = OpFunctionCall %2 %46
%161 = OpFunctionCall %2 %51
%162 = OpFunctionCall %2 %71
%163 = OpFunctionCall %2 %77
%164 = OpFunctionCall %2 %81
%165 = OpFunctionCall %2 %89
OpReturn
OpFunctionEnd