Scalarize vector readFirstInvocationARB (#2766)
authorGreg Fischer <greg@lunarg.com>
Thu, 23 Sep 2021 16:40:43 +0000 (10:40 -0600)
committerGitHub <noreply@github.com>
Thu, 23 Sep 2021 16:40:43 +0000 (10:40 -0600)
Fixes #2761

SPIRV/GlslangToSpv.cpp
Test/baseResults/spv.shaderBallot.comp.out

index 71b00d7..1117470 100644 (file)
@@ -7506,6 +7506,8 @@ spv::Id TGlslangToSpvTraverser::createInvocationsOperation(glslang::TOperator op
         break;
     case glslang::EOpReadFirstInvocation:
         opCode = spv::OpSubgroupFirstInvocationKHR;
+        if (builder.isVectorType(typeId))
+            return CreateInvocationsVectorOperation(opCode, groupOperation, typeId, operands);
         break;
     case glslang::EOpBallot:
     {
@@ -7630,7 +7632,7 @@ spv::Id TGlslangToSpvTraverser::CreateInvocationsVectorOperation(spv::Op op, spv
     assert(op == spv::OpGroupFMin || op == spv::OpGroupUMin || op == spv::OpGroupSMin ||
            op == spv::OpGroupFMax || op == spv::OpGroupUMax || op == spv::OpGroupSMax ||
            op == spv::OpGroupFAdd || op == spv::OpGroupIAdd || op == spv::OpGroupBroadcast ||
-           op == spv::OpSubgroupReadInvocationKHR ||
+           op == spv::OpSubgroupReadInvocationKHR || op == spv::OpSubgroupFirstInvocationKHR ||
            op == spv::OpGroupFMinNonUniformAMD || op == spv::OpGroupUMinNonUniformAMD ||
            op == spv::OpGroupSMinNonUniformAMD ||
            op == spv::OpGroupFMaxNonUniformAMD || op == spv::OpGroupUMaxNonUniformAMD ||
@@ -7659,6 +7661,8 @@ spv::Id TGlslangToSpvTraverser::CreateInvocationsVectorOperation(spv::Op op, spv
             spvGroupOperands.push_back(scalar);
             spv::IdImmediate operand = { true, operands[1] };
             spvGroupOperands.push_back(operand);
+        } else if (op == spv::OpSubgroupFirstInvocationKHR) {
+            spvGroupOperands.push_back(scalar);
         } else if (op == spv::OpGroupBroadcast) {
             spv::IdImmediate scope = { true, builder.makeUintConstant(spv::ScopeSubgroup) };
             spvGroupOperands.push_back(scope);
index 9338529..2a0106e 100644 (file)
@@ -1,7 +1,7 @@
 spv.shaderBallot.comp
 // Module Version 10000
 // Generated by (magic number): 8000a
-// Id's are bound by 343
+// Id's are bound by 397
 
                               Capability Shader
                               Capability Int64
@@ -42,7 +42,7 @@ spv.shaderBallot.comp
                               Decorate 72(Buffers) BufferBlock
                               Decorate 75(data) DescriptorSet 0
                               Decorate 75(data) Binding 0
-                              Decorate 342 BuiltIn WorkgroupSize
+                              Decorate 396 BuiltIn WorkgroupSize
                2:             TypeVoid
                3:             TypeFunction 2
                6:             TypeInt 32 0
@@ -89,8 +89,8 @@ spv.shaderBallot.comp
              196:             TypePointer Uniform 6(int)
              203:             TypePointer Uniform 20(ivec4)
              218:             TypeVector 6(int) 3
-             341:      6(int) Constant 8
-             342:  218(ivec3) ConstantComposite 341 341 100
+             395:      6(int) Constant 8
+             396:  218(ivec3) ConstantComposite 395 395 100
          4(main):           2 Function None 3
                5:             Label
    8(invocation):      7(ptr) Variable Function
@@ -329,107 +329,161 @@ spv.shaderBallot.comp
              257:     88(ptr)   AccessChain 75(data) 86 77
              258:   69(fvec4)   Load 257
              259:   87(fvec2)   VectorShuffle 258 258 0 1
-             260:   87(fvec2)   SubgroupFirstInvocationKHR 259
-             261:     79(ptr)   AccessChain 75(data) 256 77 78
-             262:   68(float)   CompositeExtract 260 0
-                                Store 261 262
-             263:     79(ptr)   AccessChain 75(data) 256 77 100
-             264:   68(float)   CompositeExtract 260 1
-                                Store 263 264
-             265:      6(int)   Load 8(invocation)
-             266:     88(ptr)   AccessChain 75(data) 104 77
-             267:   69(fvec4)   Load 266
-             268:  105(fvec3)   VectorShuffle 267 267 0 1 2
-             269:  105(fvec3)   SubgroupFirstInvocationKHR 268
-             270:     79(ptr)   AccessChain 75(data) 265 77 78
-             271:   68(float)   CompositeExtract 269 0
-                                Store 270 271
-             272:     79(ptr)   AccessChain 75(data) 265 77 100
-             273:   68(float)   CompositeExtract 269 1
-                                Store 272 273
-             274:     79(ptr)   AccessChain 75(data) 265 77 121
-             275:   68(float)   CompositeExtract 269 2
-                                Store 274 275
-             276:      6(int)   Load 8(invocation)
-             277:     88(ptr)   AccessChain 75(data) 125 77
-             278:   69(fvec4)   Load 277
-             279:   69(fvec4)   SubgroupFirstInvocationKHR 278
-             280:     88(ptr)   AccessChain 75(data) 276 77
-                                Store 280 279
-             281:      6(int)   Load 8(invocation)
-             282:    140(ptr)   AccessChain 75(data) 77 86 78
-             283:     70(int)   Load 282
-             284:     70(int)   SubgroupFirstInvocationKHR 283
-             285:    140(ptr)   AccessChain 75(data) 281 86 78
-                                Store 285 284
+             260:   68(float)   CompositeExtract 259 0
+             261:   68(float)   SubgroupFirstInvocationKHR 260
+             262:   68(float)   CompositeExtract 259 1
+             263:   68(float)   SubgroupFirstInvocationKHR 262
+             264:   87(fvec2)   CompositeConstruct 261 263
+             265:     79(ptr)   AccessChain 75(data) 256 77 78
+             266:   68(float)   CompositeExtract 264 0
+                                Store 265 266
+             267:     79(ptr)   AccessChain 75(data) 256 77 100
+             268:   68(float)   CompositeExtract 264 1
+                                Store 267 268
+             269:      6(int)   Load 8(invocation)
+             270:     88(ptr)   AccessChain 75(data) 104 77
+             271:   69(fvec4)   Load 270
+             272:  105(fvec3)   VectorShuffle 271 271 0 1 2
+             273:   68(float)   CompositeExtract 272 0
+             274:   68(float)   SubgroupFirstInvocationKHR 273
+             275:   68(float)   CompositeExtract 272 1
+             276:   68(float)   SubgroupFirstInvocationKHR 275
+             277:   68(float)   CompositeExtract 272 2
+             278:   68(float)   SubgroupFirstInvocationKHR 277
+             279:  105(fvec3)   CompositeConstruct 274 276 278
+             280:     79(ptr)   AccessChain 75(data) 269 77 78
+             281:   68(float)   CompositeExtract 279 0
+                                Store 280 281
+             282:     79(ptr)   AccessChain 75(data) 269 77 100
+             283:   68(float)   CompositeExtract 279 1
+                                Store 282 283
+             284:     79(ptr)   AccessChain 75(data) 269 77 121
+             285:   68(float)   CompositeExtract 279 2
+                                Store 284 285
              286:      6(int)   Load 8(invocation)
-             287:    148(ptr)   AccessChain 75(data) 86 86
-             288:   71(ivec4)   Load 287
-             289:  147(ivec2)   VectorShuffle 288 288 0 1
-             290:  147(ivec2)   SubgroupFirstInvocationKHR 289
-             291:    140(ptr)   AccessChain 75(data) 286 86 78
-             292:     70(int)   CompositeExtract 290 0
-                                Store 291 292
-             293:    140(ptr)   AccessChain 75(data) 286 86 100
-             294:     70(int)   CompositeExtract 290 1
-                                Store 293 294
-             295:      6(int)   Load 8(invocation)
-             296:    148(ptr)   AccessChain 75(data) 104 86
-             297:   71(ivec4)   Load 296
-             298:  163(ivec3)   VectorShuffle 297 297 0 1 2
-             299:  163(ivec3)   SubgroupFirstInvocationKHR 298
-             300:    140(ptr)   AccessChain 75(data) 295 86 78
-             301:     70(int)   CompositeExtract 299 0
-                                Store 300 301
-             302:    140(ptr)   AccessChain 75(data) 295 86 100
-             303:     70(int)   CompositeExtract 299 1
-                                Store 302 303
-             304:    140(ptr)   AccessChain 75(data) 295 86 121
-             305:     70(int)   CompositeExtract 299 2
-                                Store 304 305
-             306:      6(int)   Load 8(invocation)
-             307:    148(ptr)   AccessChain 75(data) 125 86
-             308:   71(ivec4)   Load 307
-             309:   71(ivec4)   SubgroupFirstInvocationKHR 308
-             310:    148(ptr)   AccessChain 75(data) 306 86
-                                Store 310 309
-             311:      6(int)   Load 8(invocation)
-             312:    196(ptr)   AccessChain 75(data) 77 104 78
-             313:      6(int)   Load 312
-             314:      6(int)   SubgroupFirstInvocationKHR 313
-             315:    196(ptr)   AccessChain 75(data) 311 104 78
-                                Store 315 314
-             316:      6(int)   Load 8(invocation)
-             317:    203(ptr)   AccessChain 75(data) 86 104
-             318:   20(ivec4)   Load 317
-             319:   26(ivec2)   VectorShuffle 318 318 0 1
-             320:   26(ivec2)   SubgroupFirstInvocationKHR 319
-             321:    196(ptr)   AccessChain 75(data) 316 104 78
-             322:      6(int)   CompositeExtract 320 0
-                                Store 321 322
-             323:    196(ptr)   AccessChain 75(data) 316 104 100
-             324:      6(int)   CompositeExtract 320 1
-                                Store 323 324
-             325:      6(int)   Load 8(invocation)
-             326:    203(ptr)   AccessChain 75(data) 104 104
-             327:   20(ivec4)   Load 326
-             328:  218(ivec3)   VectorShuffle 327 327 0 1 2
-             329:  218(ivec3)   SubgroupFirstInvocationKHR 328
-             330:    196(ptr)   AccessChain 75(data) 325 104 78
-             331:      6(int)   CompositeExtract 329 0
+             287:     88(ptr)   AccessChain 75(data) 125 77
+             288:   69(fvec4)   Load 287
+             289:   68(float)   CompositeExtract 288 0
+             290:   68(float)   SubgroupFirstInvocationKHR 289
+             291:   68(float)   CompositeExtract 288 1
+             292:   68(float)   SubgroupFirstInvocationKHR 291
+             293:   68(float)   CompositeExtract 288 2
+             294:   68(float)   SubgroupFirstInvocationKHR 293
+             295:   68(float)   CompositeExtract 288 3
+             296:   68(float)   SubgroupFirstInvocationKHR 295
+             297:   69(fvec4)   CompositeConstruct 290 292 294 296
+             298:     88(ptr)   AccessChain 75(data) 286 77
+                                Store 298 297
+             299:      6(int)   Load 8(invocation)
+             300:    140(ptr)   AccessChain 75(data) 77 86 78
+             301:     70(int)   Load 300
+             302:     70(int)   SubgroupFirstInvocationKHR 301
+             303:    140(ptr)   AccessChain 75(data) 299 86 78
+                                Store 303 302
+             304:      6(int)   Load 8(invocation)
+             305:    148(ptr)   AccessChain 75(data) 86 86
+             306:   71(ivec4)   Load 305
+             307:  147(ivec2)   VectorShuffle 306 306 0 1
+             308:     70(int)   CompositeExtract 307 0
+             309:     70(int)   SubgroupFirstInvocationKHR 308
+             310:     70(int)   CompositeExtract 307 1
+             311:     70(int)   SubgroupFirstInvocationKHR 310
+             312:  147(ivec2)   CompositeConstruct 309 311
+             313:    140(ptr)   AccessChain 75(data) 304 86 78
+             314:     70(int)   CompositeExtract 312 0
+                                Store 313 314
+             315:    140(ptr)   AccessChain 75(data) 304 86 100
+             316:     70(int)   CompositeExtract 312 1
+                                Store 315 316
+             317:      6(int)   Load 8(invocation)
+             318:    148(ptr)   AccessChain 75(data) 104 86
+             319:   71(ivec4)   Load 318
+             320:  163(ivec3)   VectorShuffle 319 319 0 1 2
+             321:     70(int)   CompositeExtract 320 0
+             322:     70(int)   SubgroupFirstInvocationKHR 321
+             323:     70(int)   CompositeExtract 320 1
+             324:     70(int)   SubgroupFirstInvocationKHR 323
+             325:     70(int)   CompositeExtract 320 2
+             326:     70(int)   SubgroupFirstInvocationKHR 325
+             327:  163(ivec3)   CompositeConstruct 322 324 326
+             328:    140(ptr)   AccessChain 75(data) 317 86 78
+             329:     70(int)   CompositeExtract 327 0
+                                Store 328 329
+             330:    140(ptr)   AccessChain 75(data) 317 86 100
+             331:     70(int)   CompositeExtract 327 1
                                 Store 330 331
-             332:    196(ptr)   AccessChain 75(data) 325 104 100
-             333:      6(int)   CompositeExtract 329 1
+             332:    140(ptr)   AccessChain 75(data) 317 86 121
+             333:     70(int)   CompositeExtract 327 2
                                 Store 332 333
-             334:    196(ptr)   AccessChain 75(data) 325 104 121
-             335:      6(int)   CompositeExtract 329 2
-                                Store 334 335
-             336:      6(int)   Load 8(invocation)
-             337:    203(ptr)   AccessChain 75(data) 125 104
-             338:   20(ivec4)   Load 337
-             339:   20(ivec4)   SubgroupFirstInvocationKHR 338
-             340:    203(ptr)   AccessChain 75(data) 336 104
-                                Store 340 339
+             334:      6(int)   Load 8(invocation)
+             335:    148(ptr)   AccessChain 75(data) 125 86
+             336:   71(ivec4)   Load 335
+             337:     70(int)   CompositeExtract 336 0
+             338:     70(int)   SubgroupFirstInvocationKHR 337
+             339:     70(int)   CompositeExtract 336 1
+             340:     70(int)   SubgroupFirstInvocationKHR 339
+             341:     70(int)   CompositeExtract 336 2
+             342:     70(int)   SubgroupFirstInvocationKHR 341
+             343:     70(int)   CompositeExtract 336 3
+             344:     70(int)   SubgroupFirstInvocationKHR 343
+             345:   71(ivec4)   CompositeConstruct 338 340 342 344
+             346:    148(ptr)   AccessChain 75(data) 334 86
+                                Store 346 345
+             347:      6(int)   Load 8(invocation)
+             348:    196(ptr)   AccessChain 75(data) 77 104 78
+             349:      6(int)   Load 348
+             350:      6(int)   SubgroupFirstInvocationKHR 349
+             351:    196(ptr)   AccessChain 75(data) 347 104 78
+                                Store 351 350
+             352:      6(int)   Load 8(invocation)
+             353:    203(ptr)   AccessChain 75(data) 86 104
+             354:   20(ivec4)   Load 353
+             355:   26(ivec2)   VectorShuffle 354 354 0 1
+             356:      6(int)   CompositeExtract 355 0
+             357:      6(int)   SubgroupFirstInvocationKHR 356
+             358:      6(int)   CompositeExtract 355 1
+             359:      6(int)   SubgroupFirstInvocationKHR 358
+             360:   26(ivec2)   CompositeConstruct 357 359
+             361:    196(ptr)   AccessChain 75(data) 352 104 78
+             362:      6(int)   CompositeExtract 360 0
+                                Store 361 362
+             363:    196(ptr)   AccessChain 75(data) 352 104 100
+             364:      6(int)   CompositeExtract 360 1
+                                Store 363 364
+             365:      6(int)   Load 8(invocation)
+             366:    203(ptr)   AccessChain 75(data) 104 104
+             367:   20(ivec4)   Load 366
+             368:  218(ivec3)   VectorShuffle 367 367 0 1 2
+             369:      6(int)   CompositeExtract 368 0
+             370:      6(int)   SubgroupFirstInvocationKHR 369
+             371:      6(int)   CompositeExtract 368 1
+             372:      6(int)   SubgroupFirstInvocationKHR 371
+             373:      6(int)   CompositeExtract 368 2
+             374:      6(int)   SubgroupFirstInvocationKHR 373
+             375:  218(ivec3)   CompositeConstruct 370 372 374
+             376:    196(ptr)   AccessChain 75(data) 365 104 78
+             377:      6(int)   CompositeExtract 375 0
+                                Store 376 377
+             378:    196(ptr)   AccessChain 75(data) 365 104 100
+             379:      6(int)   CompositeExtract 375 1
+                                Store 378 379
+             380:    196(ptr)   AccessChain 75(data) 365 104 121
+             381:      6(int)   CompositeExtract 375 2
+                                Store 380 381
+             382:      6(int)   Load 8(invocation)
+             383:    203(ptr)   AccessChain 75(data) 125 104
+             384:   20(ivec4)   Load 383
+             385:      6(int)   CompositeExtract 384 0
+             386:      6(int)   SubgroupFirstInvocationKHR 385
+             387:      6(int)   CompositeExtract 384 1
+             388:      6(int)   SubgroupFirstInvocationKHR 387
+             389:      6(int)   CompositeExtract 384 2
+             390:      6(int)   SubgroupFirstInvocationKHR 389
+             391:      6(int)   CompositeExtract 384 3
+             392:      6(int)   SubgroupFirstInvocationKHR 391
+             393:   20(ivec4)   CompositeConstruct 386 388 390 392
+             394:    203(ptr)   AccessChain 75(data) 382 104
+                                Store 394 393
                                 Branch 67
               67:             Label
                               Return