diff --git a/SPIRV/SpvBuilder.cpp b/SPIRV/SpvBuilder.cpp index f2af3b59e..708871eb1 100644 --- a/SPIRV/SpvBuilder.cpp +++ b/SPIRV/SpvBuilder.cpp @@ -1328,15 +1328,20 @@ Id Builder::createRvalueSwizzle(Decoration precision, Id typeId, Id source, std: // Comments in header Id Builder::createLvalueSwizzle(Id typeId, Id target, Id source, std::vector& channels) { - assert(getNumComponents(source) == (int)channels.size()); if (channels.size() == 1 && getNumComponents(source) == 1) return createCompositeInsert(source, target, typeId, channels.front()); Instruction* swizzle = new Instruction(getUniqueId(), typeId, OpVectorShuffle); - assert(isVector(source)); assert(isVector(target)); swizzle->addIdOperand(target); - swizzle->addIdOperand(source); + if (accessChain.component != NoResult) + // For dynamic component selection, source does not involve in l-value swizzle + swizzle->addIdOperand(target); + else { + assert(getNumComponents(source) == (int)channels.size()); + assert(isVector(source)); + swizzle->addIdOperand(source); + } // Set up an identity shuffle from the base value to the result value unsigned int components[4]; @@ -1345,8 +1350,12 @@ Id Builder::createLvalueSwizzle(Id typeId, Id target, Id source, std::vectormissingFunctionality("simultaneous l-value swizzle and dynamic component selection"); - // If swizzle still exists, it is out-of-order or not full, we must load the target vector, // extract and insert elements to perform writeMask and/or swizzle. Id source = NoResult; diff --git a/Test/baseResults/spv.accessChain.frag.out b/Test/baseResults/spv.accessChain.frag.out index e9a9d81bc..3d391c312 100755 --- a/Test/baseResults/spv.accessChain.frag.out +++ b/Test/baseResults/spv.accessChain.frag.out @@ -7,12 +7,12 @@ Linked fragment stage: // Module Version 10000 // Generated by (magic number): 80001 -// Id's are bound by 197 +// Id's are bound by 206 Capability Shader 1: ExtInstImport "GLSL.std.450" MemoryModel Logical GLSL450 - EntryPoint Fragment 4 "main" 65 149 + EntryPoint Fragment 4 "main" 65 158 ExecutionMode 4 OriginUpperLeft Source GLSL 420 Name 4 "main" @@ -57,22 +57,22 @@ Linked fragment stage: Name 60 "i" Name 61 "comp" Name 65 "OutColor" - Name 144 "s" - Name 149 "u" - Name 150 "param" - Name 154 "param" - Name 158 "param" - Name 162 "param" - Name 166 "param" - Name 170 "param" - Name 174 "param" - Name 178 "param" - Name 182 "param" - Name 186 "param" - Name 190 "param" - Name 194 "param" + Name 153 "s" + Name 158 "u" + Name 159 "param" + Name 163 "param" + Name 167 "param" + Name 171 "param" + Name 175 "param" + Name 179 "param" + Name 183 "param" + Name 187 "param" + Name 191 "param" + Name 195 "param" + Name 199 "param" + Name 203 "param" Decorate 65(OutColor) Location 0 - Decorate 149(u) Flat + Decorate 158(u) Flat 2: TypeVoid 3: TypeFunction 2 6: TypeFloat 32 @@ -90,77 +90,77 @@ Linked fragment stage: 95: TypeVector 6(float) 2 109: 67(int) Constant 2 136: TypePointer Output 6(float) - 141: 6(float) Constant 0 - 142: 7(fvec3) ConstantComposite 141 141 141 - 143: TypePointer Function 8(S) - 148: TypePointer Input 13(int) - 149(u): 148(ptr) Variable Input + 150: 6(float) Constant 0 + 151: 7(fvec3) ConstantComposite 150 150 150 + 152: TypePointer Function 8(S) + 157: TypePointer Input 13(int) + 158(u): 157(ptr) Variable Input 4(main): 2 Function None 3 5: Label - 144(s): 143(ptr) Variable Function - 150(param): 14(ptr) Variable Function - 154(param): 14(ptr) Variable Function - 158(param): 14(ptr) Variable Function - 162(param): 14(ptr) Variable Function - 166(param): 14(ptr) Variable Function - 170(param): 14(ptr) Variable Function - 174(param): 14(ptr) Variable Function - 178(param): 14(ptr) Variable Function - 182(param): 14(ptr) Variable Function - 186(param): 14(ptr) Variable Function - 190(param): 14(ptr) Variable Function - 194(param): 14(ptr) Variable Function - Store 65(OutColor) 142 - 145: 8(S) Load 144(s) - 146: 2 FunctionCall 11(GetColor1(struct-S-vf31;) 145 - 147: 8(S) Load 144(s) - 151: 13(int) Load 149(u) - Store 150(param) 151 - 152: 2 FunctionCall 18(GetColor2(struct-S-vf31;i1;) 147 150(param) - 153: 8(S) Load 144(s) - 155: 13(int) Load 149(u) - Store 154(param) 155 - 156: 2 FunctionCall 22(GetColor3(struct-S-vf31;i1;) 153 154(param) - 157: 8(S) Load 144(s) - 159: 13(int) Load 149(u) - Store 158(param) 159 - 160: 2 FunctionCall 26(GetColor4(struct-S-vf31;i1;) 157 158(param) - 161: 8(S) Load 144(s) - 163: 13(int) Load 149(u) - Store 162(param) 163 - 164: 2 FunctionCall 30(GetColor5(struct-S-vf31;i1;) 161 162(param) - 165: 8(S) Load 144(s) - 167: 13(int) Load 149(u) - Store 166(param) 167 - 168: 2 FunctionCall 34(GetColor6(struct-S-vf31;i1;) 165 166(param) - 169: 8(S) Load 144(s) - 171: 13(int) Load 149(u) - Store 170(param) 171 - 172: 2 FunctionCall 38(GetColor7(struct-S-vf31;i1;) 169 170(param) - 173: 8(S) Load 144(s) - 175: 13(int) Load 149(u) - Store 174(param) 175 - 176: 2 FunctionCall 42(GetColor8(struct-S-vf31;i1;) 173 174(param) - 177: 8(S) Load 144(s) - 179: 13(int) Load 149(u) - Store 178(param) 179 - 180: 2 FunctionCall 46(GetColor9(struct-S-vf31;i1;) 177 178(param) - 181: 8(S) Load 144(s) - 183: 13(int) Load 149(u) - Store 182(param) 183 - 184: 2 FunctionCall 50(GetColor10(struct-S-vf31;i1;) 181 182(param) - 185: 8(S) Load 144(s) - 187: 13(int) Load 149(u) - Store 186(param) 187 - 188: 2 FunctionCall 54(GetColor11(struct-S-vf31;i1;) 185 186(param) - 189: 8(S) Load 144(s) - 191: 13(int) Load 149(u) - Store 190(param) 191 - 192: 2 FunctionCall 58(GetColor12(struct-S-vf31;i1;) 189 190(param) - 193: 8(S) Load 144(s) - 195: 13(int) Load 149(u) - Store 194(param) 195 - 196: 2 FunctionCall 62(GetColor13(struct-S-vf31;i1;) 193 194(param) + 153(s): 152(ptr) Variable Function + 159(param): 14(ptr) Variable Function + 163(param): 14(ptr) Variable Function + 167(param): 14(ptr) Variable Function + 171(param): 14(ptr) Variable Function + 175(param): 14(ptr) Variable Function + 179(param): 14(ptr) Variable Function + 183(param): 14(ptr) Variable Function + 187(param): 14(ptr) Variable Function + 191(param): 14(ptr) Variable Function + 195(param): 14(ptr) Variable Function + 199(param): 14(ptr) Variable Function + 203(param): 14(ptr) Variable Function + Store 65(OutColor) 151 + 154: 8(S) Load 153(s) + 155: 2 FunctionCall 11(GetColor1(struct-S-vf31;) 154 + 156: 8(S) Load 153(s) + 160: 13(int) Load 158(u) + Store 159(param) 160 + 161: 2 FunctionCall 18(GetColor2(struct-S-vf31;i1;) 156 159(param) + 162: 8(S) Load 153(s) + 164: 13(int) Load 158(u) + Store 163(param) 164 + 165: 2 FunctionCall 22(GetColor3(struct-S-vf31;i1;) 162 163(param) + 166: 8(S) Load 153(s) + 168: 13(int) Load 158(u) + Store 167(param) 168 + 169: 2 FunctionCall 26(GetColor4(struct-S-vf31;i1;) 166 167(param) + 170: 8(S) Load 153(s) + 172: 13(int) Load 158(u) + Store 171(param) 172 + 173: 2 FunctionCall 30(GetColor5(struct-S-vf31;i1;) 170 171(param) + 174: 8(S) Load 153(s) + 176: 13(int) Load 158(u) + Store 175(param) 176 + 177: 2 FunctionCall 34(GetColor6(struct-S-vf31;i1;) 174 175(param) + 178: 8(S) Load 153(s) + 180: 13(int) Load 158(u) + Store 179(param) 180 + 181: 2 FunctionCall 38(GetColor7(struct-S-vf31;i1;) 178 179(param) + 182: 8(S) Load 153(s) + 184: 13(int) Load 158(u) + Store 183(param) 184 + 185: 2 FunctionCall 42(GetColor8(struct-S-vf31;i1;) 182 183(param) + 186: 8(S) Load 153(s) + 188: 13(int) Load 158(u) + Store 187(param) 188 + 189: 2 FunctionCall 46(GetColor9(struct-S-vf31;i1;) 186 187(param) + 190: 8(S) Load 153(s) + 192: 13(int) Load 158(u) + Store 191(param) 192 + 193: 2 FunctionCall 50(GetColor10(struct-S-vf31;i1;) 190 191(param) + 194: 8(S) Load 153(s) + 196: 13(int) Load 158(u) + Store 195(param) 196 + 197: 2 FunctionCall 54(GetColor11(struct-S-vf31;i1;) 194 195(param) + 198: 8(S) Load 153(s) + 200: 13(int) Load 158(u) + Store 199(param) 200 + 201: 2 FunctionCall 58(GetColor12(struct-S-vf31;i1;) 198 199(param) + 202: 8(S) Load 153(s) + 204: 13(int) Load 158(u) + Store 203(param) 204 + 205: 2 FunctionCall 62(GetColor13(struct-S-vf31;i1;) 202 203(param) Return FunctionEnd 11(GetColor1(struct-S-vf31;): 2 Function None 9 @@ -319,5 +319,15 @@ Linked fragment stage: 60(i): 8(S) FunctionParameter 61(comp): 14(ptr) FunctionParameter 63: Label + 141: 13(int) Load 61(comp) + 142: 6(float) CompositeExtract 60(i) 0 0 + 143: 7(fvec3) Load 65(OutColor) + 144: 95(fvec2) VectorShuffle 143 143 2 1 + 145: 6(float) VectorExtractDynamic 144 141 + 146: 6(float) FAdd 145 142 + 147: 7(fvec3) Load 65(OutColor) + 148: 7(fvec3) VectorShuffle 147 147 2 1 2 + 149: 7(fvec3) VectorInsertDynamic 148 146 141 + Store 65(OutColor) 149 Return FunctionEnd diff --git a/Test/spv.accessChain.frag b/Test/spv.accessChain.frag index 41ec0ca33..c7f805b57 100644 --- a/Test/spv.accessChain.frag +++ b/Test/spv.accessChain.frag @@ -71,7 +71,7 @@ void GetColor12(const S i, int comp) void GetColor13(const S i, int comp) { - // OutColor.zy[comp] += i.color.x; // not yet supported + OutColor.zy[comp] += i.color.x; } void main()