@@ -2306,7 +2306,7 @@ IRInst* materializeValue(IRBuilder* builder, ScalarizedVal const& val)
2306
2306
}
2307
2307
}
2308
2308
2309
- static void handleSingleParam (
2309
+ void handleSingleParam (
2310
2310
GLSLLegalizationContext* context,
2311
2311
IRFunc* func,
2312
2312
IRParam* pp,
@@ -2381,7 +2381,8 @@ static void consolidateParameters(
2381
2381
valueType = inOutType->getValueType ();
2382
2382
2383
2383
auto key = builder->createStructKey ();
2384
- builder->addNameHintDecoration (key, UnownedStringSlice (" field" ));
2384
+ if (auto nameDecor = _param->findDecoration <IRNameHintDecoration>())
2385
+ builder->addNameHintDecoration (key, nameDecor->getName ());
2385
2386
auto field = builder->createStructField (structType, key, valueType);
2386
2387
field->removeFromParent ();
2387
2388
field->insertAtEnd (structType);
@@ -2441,64 +2442,54 @@ static void consolidateParameters(
2441
2442
}
2442
2443
}
2443
2444
2444
- static void handleMultipleParams (GLSLLegalizationContext* context, IRFunc* func, IRParam* pp)
2445
+ // Consolidate ray tracing parameters for an entry point function
2446
+ void consolidateRayTracingParameters (
2447
+ GLSLLegalizationContext* context,
2448
+ IRFunc* func)
2445
2449
{
2450
+ auto builder = context->getBuilder ();
2446
2451
auto firstBlock = func->getFirstBlock ();
2452
+ if (!firstBlock)
2453
+ return ;
2447
2454
2448
- // Now we run the consolidation step, but if we've already
2449
- // processed this parameter, skip it.
2450
- List<IRParam*>* processedParams = nullptr ;
2451
- if (auto foundList = context->rayTracingProcessedParams .tryGetValue (func))
2452
- {
2453
- processedParams = foundList;
2454
- if (processedParams->contains (pp))
2455
- return ;
2456
- }
2457
- else
2458
- {
2459
- context->rayTracingProcessedParams [func] = List<IRParam*>();
2460
- processedParams = &context->rayTracingProcessedParams [func];
2461
- }
2462
-
2463
- // Collect all parameters that need to be consolidated
2464
- List<IRParam*> params;
2465
- List<IRVarLayout*> paramLayouts;
2455
+ // Collect all out/inout parameters that need to be consolidated
2456
+ List<IRParam*> outParams;
2457
+ List<IRParam*> otherParams;
2466
2458
2467
- for (auto _param = firstBlock->getFirstParam (); _param; _param = _param ->getNextParam ())
2459
+ for (auto param = firstBlock->getFirstParam (); param; param = param ->getNextParam ())
2468
2460
{
2469
- auto pLayoutDecoration = _param->findDecoration <IRLayoutDecoration>();
2470
- SLANG_ASSERT (pLayoutDecoration);
2471
- auto pLayout = as<IRVarLayout>(pLayoutDecoration->getLayout ());
2472
- SLANG_ASSERT (pLayout);
2473
-
2474
- // Only include parameters that haven't been processed yet
2475
- auto _paramType = _param->getDataType ();
2476
- bool needsConsolidation = (as<IROutType>(_paramType) || as<IRInOutType>(_paramType));
2477
- if (!processedParams->contains (_param) && needsConsolidation)
2461
+ builder->setInsertBefore (firstBlock->getFirstOrdinaryInst ());
2462
+ if (as<IROutTypeBase>(param->getDataType ()))
2463
+ {
2464
+ outParams.add (param);
2465
+ }
2466
+ else
2478
2467
{
2479
- params.add (_param);
2480
- paramLayouts.add (pLayout);
2481
- processedParams->add (_param);
2468
+ otherParams.add (param);
2482
2469
}
2483
2470
}
2484
2471
2485
- consolidateParameters (context, func, params);
2486
- }
2487
-
2488
- void legalizeRayTracingEntryPointParameterForGLSL (
2489
- GLSLLegalizationContext* context,
2490
- IRFunc* func,
2491
- IRParam* pp,
2492
- IRVarLayout* paramLayout,
2493
- bool hasSingleOutOrInOutParam)
2494
- {
2495
- if (hasSingleOutOrInOutParam)
2472
+ // We don't need consolidation here.
2473
+ if (outParams.getCount () <= 1 )
2496
2474
{
2497
- handleSingleParam (context, func, pp, paramLayout);
2475
+ // We have one out/inout param, so add it as part of otherParams so we can
2476
+ // just do one pass of handleSingleParam().
2477
+ if (outParams.getCount () == 1 )
2478
+ {
2479
+ otherParams.add (outParams[0 ]);
2480
+ }
2481
+ for (auto param : otherParams)
2482
+ {
2483
+ auto paramLayoutDecoration = param->findDecoration <IRLayoutDecoration>();
2484
+ SLANG_ASSERT (paramLayoutDecoration);
2485
+ auto paramLayout = as<IRVarLayout>(paramLayoutDecoration->getLayout ());
2486
+ handleSingleParam (context, func, param, paramLayout);
2487
+ }
2498
2488
return ;
2499
2489
}
2500
2490
2501
- handleMultipleParams (context, func, pp);
2491
+ // Consolidate the parameters
2492
+ consolidateParameters (context, func, outParams);
2502
2493
}
2503
2494
2504
2495
static void legalizeMeshPayloadInputParam (
@@ -3344,28 +3335,6 @@ void legalizeEntryPointParameterForGLSL(
3344
3335
case Stage::Intersection:
3345
3336
case Stage::Miss:
3346
3337
case Stage::RayGeneration:
3347
- {
3348
- // Count the number of inout or out parameters
3349
- int inoutOrOutParamCount = 0 ;
3350
- auto firstBlock = func->getFirstBlock ();
3351
- for (auto _param = firstBlock->getFirstParam (); _param; _param = _param->getNextParam ())
3352
- {
3353
- auto _paramType = _param->getDataType ();
3354
- if (as<IROutType>(_paramType) || as<IRInOutType>(_paramType))
3355
- {
3356
- inoutOrOutParamCount++;
3357
- }
3358
- }
3359
-
3360
- // If we have just one inout or out param, we don't need consolidation.
3361
- bool hasSingleOutOrInOutParam = inoutOrOutParamCount <= 1 ;
3362
- legalizeRayTracingEntryPointParameterForGLSL (
3363
- context,
3364
- func,
3365
- pp,
3366
- paramLayout,
3367
- hasSingleOutOrInOutParam);
3368
- }
3369
3338
return ;
3370
3339
}
3371
3340
@@ -3941,12 +3910,33 @@ void legalizeEntryPointForGLSL(
3941
3910
invokePathConstantFuncInHullShader (&context, codeGenContext, scalarizedGlobalOutput);
3942
3911
}
3943
3912
3913
+ // Special handling for ray tracing shaders
3914
+ bool isRayTracingShader = false ;
3915
+ switch (stage)
3916
+ {
3917
+ case Stage::AnyHit:
3918
+ case Stage::Callable:
3919
+ case Stage::ClosestHit:
3920
+ case Stage::Intersection:
3921
+ case Stage::Miss:
3922
+ case Stage::RayGeneration:
3923
+ isRayTracingShader = true ;
3924
+ consolidateRayTracingParameters (&context, func);
3925
+ break ;
3926
+ default :
3927
+ break ;
3928
+ }
3929
+
3944
3930
// Next we will walk through any parameters of the entry-point function,
3945
3931
// and turn them into global variables.
3946
3932
if (auto firstBlock = func->getFirstBlock ())
3947
3933
{
3948
3934
for (auto pp = firstBlock->getFirstParam (); pp; pp = pp->getNextParam ())
3949
3935
{
3936
+ if (isRayTracingShader)
3937
+ {
3938
+ continue ;
3939
+ }
3950
3940
// Any initialization code we insert for parameters needs
3951
3941
// to be at the start of the "ordinary" instructions in the block:
3952
3942
builder.setInsertBefore (firstBlock->getFirstOrdinaryInst ());
@@ -3962,7 +3952,7 @@ void legalizeEntryPointForGLSL(
3962
3952
3963
3953
legalizeEntryPointParameterForGLSL (&context, codeGenContext, func, pp, paramLayout);
3964
3954
}
3965
-
3955
+
3966
3956
// At this point we should have eliminated all uses of the
3967
3957
// parameters of the entry block. Also, our control-flow
3968
3958
// rules mean that the entry block cannot be the target
0 commit comments