@@ -329,10 +329,6 @@ struct GLSLLegalizationContext
329
329
330
330
IRBuilder* builder;
331
331
IRBuilder* getBuilder () { return builder; }
332
-
333
- // For ray tracing shaders, we need to consolidate all parameters into a single structure
334
- Dictionary<IRFunc*, IRInst*> rayTracingConsolidatedVars;
335
- Dictionary<IRFunc*, List<IRParam*>> rayTracingProcessedParams;
336
332
};
337
333
338
334
// This examines the passed type and determines the GLSL mesh shader indices
@@ -2306,7 +2302,7 @@ IRInst* materializeValue(IRBuilder* builder, ScalarizedVal const& val)
2306
2302
}
2307
2303
}
2308
2304
2309
- static void handleSingleParam (
2305
+ void handleSingleParam (
2310
2306
GLSLLegalizationContext* context,
2311
2307
IRFunc* func,
2312
2308
IRParam* pp,
@@ -2360,7 +2356,6 @@ static void handleSingleParam(
2360
2356
2361
2357
static void consolidateParameters (
2362
2358
GLSLLegalizationContext* context,
2363
- IRFunc* func,
2364
2359
List<IRParam*>& params)
2365
2360
{
2366
2361
auto builder = context->getBuilder ();
@@ -2381,7 +2376,8 @@ static void consolidateParameters(
2381
2376
valueType = inOutType->getValueType ();
2382
2377
2383
2378
auto key = builder->createStructKey ();
2384
- builder->addNameHintDecoration (key, UnownedStringSlice (" field" ));
2379
+ if (auto nameDecor = _param->findDecoration <IRNameHintDecoration>())
2380
+ builder->addNameHintDecoration (key, nameDecor->getName ());
2385
2381
auto field = builder->createStructField (structType, key, valueType);
2386
2382
field->removeFromParent ();
2387
2383
field->insertAtEnd (structType);
@@ -2396,9 +2392,6 @@ static void consolidateParameters(
2396
2392
// Add the ray payload decoration and assign location 0.
2397
2393
builder->addVulkanRayPayloadDecoration (consolidatedVar, 0 );
2398
2394
2399
- // Store the consolidated variable for this function
2400
- context->rayTracingConsolidatedVars [func] = consolidatedVar;
2401
-
2402
2395
// Replace each parameter with a field in the consolidated struct
2403
2396
for (Index i = 0 ; i < params.getCount (); ++i)
2404
2397
{
@@ -2441,64 +2434,54 @@ static void consolidateParameters(
2441
2434
}
2442
2435
}
2443
2436
2444
- static void handleMultipleParams (GLSLLegalizationContext* context, IRFunc* func, IRParam* pp)
2437
+ // Consolidate ray tracing parameters for an entry point function
2438
+ void consolidateRayTracingParameters (
2439
+ GLSLLegalizationContext* context,
2440
+ IRFunc* func)
2445
2441
{
2442
+ auto builder = context->getBuilder ();
2446
2443
auto firstBlock = func->getFirstBlock ();
2444
+ if (!firstBlock)
2445
+ return ;
2447
2446
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;
2447
+ // Collect all out/inout parameters that need to be consolidated
2448
+ List<IRParam*> outParams;
2449
+ List<IRParam*> otherParams;
2466
2450
2467
- for (auto _param = firstBlock->getFirstParam (); _param; _param = _param ->getNextParam ())
2451
+ for (auto param = firstBlock->getFirstParam (); param; param = param ->getNextParam ())
2468
2452
{
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)
2453
+ builder->setInsertBefore (firstBlock->getFirstOrdinaryInst ());
2454
+ if (as<IROutTypeBase>(param->getDataType ()))
2455
+ {
2456
+ outParams.add (param);
2457
+ }
2458
+ else
2478
2459
{
2479
- params.add (_param);
2480
- paramLayouts.add (pLayout);
2481
- processedParams->add (_param);
2460
+ otherParams.add (param);
2482
2461
}
2483
2462
}
2484
2463
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)
2464
+ // We don't need consolidation here.
2465
+ if (outParams.getCount () <= 1 )
2496
2466
{
2497
- handleSingleParam (context, func, pp, paramLayout);
2467
+ // We have one out/inout param, so add it as part of otherParams so we can
2468
+ // just do one pass of handleSingleParam().
2469
+ if (outParams.getCount () == 1 )
2470
+ {
2471
+ otherParams.add (outParams[0 ]);
2472
+ }
2473
+ for (auto param : otherParams)
2474
+ {
2475
+ auto paramLayoutDecoration = param->findDecoration <IRLayoutDecoration>();
2476
+ SLANG_ASSERT (paramLayoutDecoration);
2477
+ auto paramLayout = as<IRVarLayout>(paramLayoutDecoration->getLayout ());
2478
+ handleSingleParam (context, func, param, paramLayout);
2479
+ }
2498
2480
return ;
2499
2481
}
2500
2482
2501
- handleMultipleParams (context, func, pp);
2483
+ // Consolidate the parameters
2484
+ consolidateParameters (context, outParams);
2502
2485
}
2503
2486
2504
2487
static void legalizeMeshPayloadInputParam (
@@ -3344,28 +3327,6 @@ void legalizeEntryPointParameterForGLSL(
3344
3327
case Stage::Intersection:
3345
3328
case Stage::Miss:
3346
3329
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
3330
return ;
3370
3331
}
3371
3332
@@ -3941,12 +3902,33 @@ void legalizeEntryPointForGLSL(
3941
3902
invokePathConstantFuncInHullShader (&context, codeGenContext, scalarizedGlobalOutput);
3942
3903
}
3943
3904
3905
+ // Special handling for ray tracing shaders
3906
+ bool isRayTracingShader = false ;
3907
+ switch (stage)
3908
+ {
3909
+ case Stage::AnyHit:
3910
+ case Stage::Callable:
3911
+ case Stage::ClosestHit:
3912
+ case Stage::Intersection:
3913
+ case Stage::Miss:
3914
+ case Stage::RayGeneration:
3915
+ isRayTracingShader = true ;
3916
+ consolidateRayTracingParameters (&context, func);
3917
+ break ;
3918
+ default :
3919
+ break ;
3920
+ }
3921
+
3944
3922
// Next we will walk through any parameters of the entry-point function,
3945
3923
// and turn them into global variables.
3946
3924
if (auto firstBlock = func->getFirstBlock ())
3947
3925
{
3948
3926
for (auto pp = firstBlock->getFirstParam (); pp; pp = pp->getNextParam ())
3949
3927
{
3928
+ if (isRayTracingShader)
3929
+ {
3930
+ continue ;
3931
+ }
3950
3932
// Any initialization code we insert for parameters needs
3951
3933
// to be at the start of the "ordinary" instructions in the block:
3952
3934
builder.setInsertBefore (firstBlock->getFirstOrdinaryInst ());
@@ -3962,7 +3944,7 @@ void legalizeEntryPointForGLSL(
3962
3944
3963
3945
legalizeEntryPointParameterForGLSL (&context, codeGenContext, func, pp, paramLayout);
3964
3946
}
3965
-
3947
+
3966
3948
// At this point we should have eliminated all uses of the
3967
3949
// parameters of the entry block. Also, our control-flow
3968
3950
// rules mean that the entry block cannot be the target
0 commit comments