Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
f1c8645
Allow SV_PrimitiveID in ray tracing hit stages
jkwak-work May 28, 2026
9a617f4
Support SV_PrimitiveID for DXIL ray tracing
jkwak-work May 28, 2026
70debcd
Fix HLSL legalization formatting
jkwak-work May 28, 2026
85865f8
Address HLSL legalization review feedback
jkwak-work May 29, 2026
9425abd
Support SV_PrimitiveID via GLSL SPIR-V
jkwak-work May 29, 2026
b85c65b
Address ray tracing primitive ID review
jkwak-work Jun 2, 2026
240a14a
Address upstream primitive ID review
jkwak-work Jun 2, 2026
9d2552d
Add primitive ID coverage tests
jkwak-work Jun 2, 2026
a61125a
Add primitive ID non-input diagnostics
jkwak-work Jun 2, 2026
d95badf
Preserve ray tracing GLSL parameter legalization
jkwak-work Jun 2, 2026
b5275bc
Support primitive ID hit params on CUDA
jkwak-work Jun 2, 2026
9da9ce2
Preserve primitive ID borrow replacements
jkwak-work Jun 2, 2026
7b64847
Address primitive ID test review
jkwak-work Jun 2, 2026
8d2b981
Add primitive ID coverage tests
jkwak-work Jun 2, 2026
213e0f7
Consolidate primitive ID lowering
jkwak-work Jun 4, 2026
cfeda0b
Canonicalize ray tracing primitive ID for GLSL
jkwak-work Jun 4, 2026
49e16ab
Address primitive ID legalization review
jkwak-work Jun 4, 2026
1225131
Guard primitive ID type conversion
jkwak-work Jun 4, 2026
9fa9f48
Handle pointer primitive ID params
jkwak-work Jun 4, 2026
ad3c6fa
Guard CUDA primitive ID conversion
jkwak-work Jun 4, 2026
cf1ac42
Export language server methods for wasm
jkwak-work Jun 4, 2026
7466afd
Build wasm compiler statically
jkwak-work Jun 4, 2026
33f4896
Test multi-entry primitive ID lowering
jkwak-work Jun 4, 2026
21f415a
Clarify HLSL parameter legalization name
jkwak-work Jun 6, 2026
e8ab0d6
Assert primitive ID legalization preconditions
jkwak-work Jun 6, 2026
de1f740
Reuse varying param traversal for primitive ID
jkwak-work Jun 6, 2026
701c4d4
Fix merge preset and formatting checks
jkwak-work Jun 6, 2026
bd32d06
Stabilize varying parameter entry traversal
jkwak-work Jun 6, 2026
2c5092b
Address ray tracing cleanup feedback
jkwak-work Jun 6, 2026
0035f14
Apply GLSL legalization formatting
jkwak-work Jun 6, 2026
ccc10a4
Legalize PrimitiveID before GLSL consolidation
jkwak-work Jun 6, 2026
742e7a9
Cover GLSL PrimitiveID legalization
jkwak-work Jun 6, 2026
e12ab61
Simplify GLSL entry parameter legalization
jkwak-work Jun 6, 2026
16a2d99
Apply GLSL parameter call formatting
jkwak-work Jun 6, 2026
92b53ac
Add PrimitiveID forwarding coverage
jkwak-work Jun 6, 2026
4f4b6c9
Cache GLSL SPIR-V emission mode
jkwak-work Jun 6, 2026
c18e089
Restore GLSL parameter return style
jkwak-work Jun 6, 2026
5190000
Keep GLSL entry point legalization signature
jkwak-work Jun 7, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions source/slang/core.meta.slang
Original file line number Diff line number Diff line change
Expand Up @@ -5050,6 +5050,9 @@ semantic sv_primitiveid
[require(geometry)]
[require(hull)]
[require(domain)]
[require(intersection)]
[require(anyhit)]
[require(closesthit)]
get : uint;

[require(geometry)]
Expand Down
7 changes: 4 additions & 3 deletions source/slang/slang-emit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1638,11 +1638,12 @@ Result linkAndOptimizeIR(
SLANG_PASS(legalizeEmptyRayPayloadsForHLSL);
}

// For DXIL only: unwrap ForceVarIntoRayPayloadStructTemporarily instructions
// (must run before legalizeExistentialTypeLayout removes empty struct parameters)
// For DXIL/HLSL: rewrite parameters that need backend intrinsics or
// temporary structs before existential layout removes empty struct
// parameters.
if (isD3DTarget(targetRequest))
{
SLANG_PASS(legalizeNonStructParameterToStructForHLSL);
SLANG_PASS(legalizeParametersForHLSL);
}

if (requiredLoweringPassSet.existentialTypeLayout)
Expand Down
24 changes: 24 additions & 0 deletions source/slang/slang-ir-glsl-legalize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "slang-ir-clone.h"
#include "slang-ir-inst-pass-base.h"
#include "slang-ir-insts.h"
#include "slang-ir-legalize-varying-params.h"
#include "slang-ir-single-return.h"
#include "slang-ir-specialize-function-call.h"
#include "slang-ir-util.h"
Expand Down Expand Up @@ -3093,6 +3094,7 @@ void consolidateRayTracingParameters(GLSLLegalizationContext* context, IRFunc* f
auto paramLayout = findVarLayout(param);
if (!isVaryingParameter(paramLayout))
continue;

builder->setInsertBefore(firstBlock->getFirstOrdinaryInst());
if (as<IROutParamType>(param->getDataType()) ||
as<IRBorrowInOutParamType>(param->getDataType()))
Expand Down Expand Up @@ -4820,6 +4822,8 @@ void legalizeEntryPointForGLSL(
SLANG_ASSERT(entryPointDecor);

auto stage = entryPointDecor->getProfile().getStage();
const bool shouldEmitSPIRVDirectly =
codeGenContext->getTargetProgram()->shouldEmitSPIRVDirectly();

auto layoutDecoration = func->findDecoration<IRLayoutDecoration>();
SLANG_ASSERT(layoutDecoration);
Expand Down Expand Up @@ -4909,6 +4913,26 @@ void legalizeEntryPointForGLSL(
invokePathConstantFuncInHullShader(&context, codeGenContext, scalarizedGlobalOutput);
}

if (isRayTracingHitStage(stage) && !shouldEmitSPIRVDirectly)
{
IRFunc* primitiveIndexFunc = nullptr;
if (auto firstBlock = func->getFirstBlock())
{
for (auto pp = firstBlock->getFirstParam(); pp;)
{
auto next = pp->getNextParam();
builder.setInsertBefore(firstBlock->getFirstOrdinaryInst());
tryLegalizeRayTracingPrimitiveIDParam(
Comment thread
jkwak-work marked this conversation as resolved.
module,
builder,
pp,
primitiveIndexFunc,
/* removeParam */ true);
pp = next;
}
}
}

// Special handling for ray tracing shaders
switch (stage)
{
Expand Down
20 changes: 15 additions & 5 deletions source/slang/slang-ir-hlsl-legalize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@

#include "slang-ir-inst-pass-base.h"
#include "slang-ir-insts.h"
#include "slang-ir-legalize-varying-params.h"
#include "slang-ir-specialize-function-call.h"
#include "slang-ir-util.h"
#include "slang-ir.h"

#include <functional>

namespace Slang
{

Expand Down Expand Up @@ -160,16 +159,27 @@ void searchChildrenForForceVarIntoStructTemporarily(IRModule* module, IRInst* in
}
}

void legalizeNonStructParameterToStructForHLSL(IRModule* module)
void legalizeParametersForHLSL(IRModule* module)
{
List<IRFunc*> funcs;

for (auto globalInst : module->getGlobalInsts())
{
// Only process functions - at this stage generics are already resolved,
// and the search only handles Block and Call children.
if (globalInst->getOp() != kIROp_Func)
auto func = as<IRFunc>(globalInst);
if (!func)
continue;
searchChildrenForForceVarIntoStructTemporarily(module, globalInst);

funcs.add(func);
}

for (auto func : funcs)
{
searchChildrenForForceVarIntoStructTemporarily(module, func);
}
Comment thread
jkwak-work marked this conversation as resolved.
Comment thread
jkwak-work marked this conversation as resolved.

legalizeRayTracingPrimitiveIDParamsForHLSL(module);
}

void legalizeEmptyRayPayloadsForHLSL(IRModule* module)
Expand Down
2 changes: 1 addition & 1 deletion source/slang/slang-ir-hlsl-legalize.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Session;
struct IRFunc;
struct IRModule;

void legalizeNonStructParameterToStructForHLSL(IRModule* module);
void legalizeParametersForHLSL(IRModule* module);

void legalizeEmptyRayPayloadsForHLSL(IRModule* module);

Expand Down
Loading
Loading