@@ -220,12 +220,17 @@ struct RequiredLoweringPassSet
220
220
bool combinedTextureSamplers;
221
221
bool reinterpret;
222
222
bool generics;
223
+ bool bindExistential;
223
224
bool autodiff;
224
225
bool derivativePyBindWrapper;
225
226
bool bitcast;
226
227
bool existentialTypeLayout;
227
228
bool bindingQuery;
228
229
bool meshOutput;
230
+ bool higherOrderFunc;
231
+ bool glslGlobalVar;
232
+ bool glslSSBO;
233
+ bool byteAddressBuffer;
229
234
};
230
235
231
236
void calcRequiredLoweringPassSet (RequiredLoweringPassSet& result, CodeGenContext* codeGenContext, IRInst* inst)
@@ -303,6 +308,27 @@ void calcRequiredLoweringPassSet(RequiredLoweringPassSet& result, CodeGenContext
303
308
case kIROp_AutoPyBindCudaDecoration :
304
309
result.derivativePyBindWrapper = true ;
305
310
break ;
311
+ case kIROp_Param :
312
+ if (as<IRFuncType>(inst->getDataType ()))
313
+ result.higherOrderFunc = true ;
314
+ break ;
315
+ case kIROp_GlobalInputDecoration :
316
+ case kIROp_GlobalOutputDecoration :
317
+ case kIROp_GetWorkGroupSize :
318
+ result.glslGlobalVar = true ;
319
+ break ;
320
+ case kIROp_BindExistentialSlotsDecoration :
321
+ result.bindExistential = true ;
322
+ result.generics = true ;
323
+ result.existentialTypeLayout = true ;
324
+ break ;
325
+ case kIROp_GLSLShaderStorageBufferType :
326
+ result.glslSSBO = true ;
327
+ break ;
328
+ case kIROp_ByteAddressBufferLoad :
329
+ case kIROp_ByteAddressBufferStore :
330
+ result.byteAddressBuffer = true ;
331
+ break ;
306
332
}
307
333
for (auto child : inst->getDecorationsAndChildren ())
308
334
{
@@ -348,10 +374,14 @@ Result linkAndOptimizeIR(
348
374
// un-specialized IR.
349
375
dumpIRIfEnabled (codeGenContext, irModule, " POST IR VALIDATION" );
350
376
351
- if (!isKhronosTarget (targetRequest))
377
+ // Scan the IR module and determine which lowering/legalization passes are needed.
378
+ RequiredLoweringPassSet requiredLoweringPassSet = {};
379
+ calcRequiredLoweringPassSet (requiredLoweringPassSet, codeGenContext, irModule->getModuleInst ());
380
+
381
+ if (!isKhronosTarget (targetRequest) && requiredLoweringPassSet.glslSSBO )
352
382
lowerGLSLShaderStorageBufferObjectsToStructuredBuffers (irModule, sink);
353
383
354
- if (!targetProgram-> getOptionSet (). shouldPerformMinimumOptimizations () )
384
+ if (requiredLoweringPassSet. glslGlobalVar )
355
385
translateGLSLGlobalVar (codeGenContext, irModule);
356
386
357
387
// Replace any global constants with their values.
@@ -370,7 +400,8 @@ Result linkAndOptimizeIR(
370
400
// shader parameters for those slots, to be wired up to
371
401
// use sites.
372
402
//
373
- bindExistentialSlots (irModule, sink);
403
+ if (requiredLoweringPassSet.bindExistential )
404
+ bindExistentialSlots (irModule, sink);
374
405
#if 0
375
406
dumpIRIfEnabled(codeGenContext, irModule, "EXISTENTIALS BOUND");
376
407
#endif
@@ -450,9 +481,6 @@ Result linkAndOptimizeIR(
450
481
break ;
451
482
}
452
483
453
- RequiredLoweringPassSet requiredLoweringPassSet = {};
454
- calcRequiredLoweringPassSet (requiredLoweringPassSet, codeGenContext, irModule->getModuleInst ());
455
-
456
484
if (requiredLoweringPassSet.optionalType )
457
485
lowerOptionalType (irModule, sink);
458
486
@@ -540,7 +568,10 @@ Result linkAndOptimizeIR(
540
568
return SLANG_FAIL;
541
569
dumpIRIfEnabled (codeGenContext, irModule, " AFTER-SPECIALIZE" );
542
570
543
- applySparseConditionalConstantPropagation (irModule, codeGenContext->getSink ());
571
+ if (changed)
572
+ {
573
+ applySparseConditionalConstantPropagation (irModule, codeGenContext->getSink ());
574
+ }
544
575
eliminateDeadCode (irModule, deadCodeEliminationOptions);
545
576
546
577
validateIRModuleIfEnabled (codeGenContext, irModule);
@@ -564,7 +595,7 @@ Result linkAndOptimizeIR(
564
595
// which do.
565
596
// Specialize away these parameters
566
597
// TODO: We should implement a proper defunctionalization pass
567
- if (!targetProgram-> getOptionSet (). shouldPerformMinimumOptimizations () )
598
+ if (requiredLoweringPassSet. higherOrderFunc )
568
599
changed |= specializeHigherOrderParameters (codeGenContext, irModule);
569
600
570
601
dumpIRIfEnabled (codeGenContext, irModule, " BEFORE-AUTODIFF" );
@@ -673,7 +704,11 @@ Result linkAndOptimizeIR(
673
704
// up downstream passes like type legalization, so we
674
705
// will run a DCE pass to clean up after the specialization.
675
706
//
676
- if (!fastIRSimplificationOptions.minimalOptimization )
707
+ if (fastIRSimplificationOptions.minimalOptimization )
708
+ {
709
+ eliminateDeadCode (irModule, deadCodeEliminationOptions);
710
+ }
711
+ else
677
712
{
678
713
simplifyIR (targetProgram, irModule, defaultIRSimplificationOptions, sink);
679
714
}
@@ -788,7 +823,9 @@ Result linkAndOptimizeIR(
788
823
// to see if we can clean up any temporaries created by legalization.
789
824
// (e.g., things that used to be aggregated might now be split up,
790
825
// so that we can work with the individual fields).
791
- if (!fastIRSimplificationOptions.minimalOptimization )
826
+ if (fastIRSimplificationOptions.minimalOptimization )
827
+ eliminateDeadCode (irModule, deadCodeEliminationOptions);
828
+ else
792
829
simplifyIR (targetProgram, irModule, fastIRSimplificationOptions, sink);
793
830
794
831
#if 0
@@ -849,6 +886,7 @@ Result linkAndOptimizeIR(
849
886
// of aggregate types from/to byte-address buffers into
850
887
// stores of individual scalar or vector values.
851
888
//
889
+ if (requiredLoweringPassSet.byteAddressBuffer )
852
890
{
853
891
ByteAddressBufferLegalizationOptions byteAddressBufferOptions;
854
892
0 commit comments