Skip to content

Commit 19d24b5

Browse files
committedMar 11, 2025
Fix review comments from cheneym2
1 parent 64f3075 commit 19d24b5

File tree

4 files changed

+115
-91
lines changed

4 files changed

+115
-91
lines changed
 

‎source/slang/slang-ir.cpp

+69-63
Original file line numberDiff line numberDiff line change
@@ -7117,6 +7117,74 @@ void dumpIRGeneric(IRDumpContext* context, IRGeneric* witnessTable)
71177117
dump(context, "}\n");
71187118
}
71197119

7120+
static void dumpEmbeddedDownstream(IRDumpContext* context, IRInst* inst)
7121+
{
7122+
auto targetInst = inst->getOperand(0);
7123+
auto blobInst = inst->getOperand(1);
7124+
7125+
// Get the target value
7126+
auto targetLit = as<IRIntLit>(targetInst);
7127+
if (!targetLit)
7128+
{
7129+
dump(context, "EmbeddedDownstreamIR(invalid target)");
7130+
return;
7131+
}
7132+
7133+
// Get the blob
7134+
auto blobLitInst = as<IRBlobLit>(blobInst);
7135+
if (!blobLitInst)
7136+
{
7137+
dump(context, "EmbeddedDownstreamIR(invalid blob)");
7138+
return;
7139+
}
7140+
7141+
dump(context, "EmbeddedDownstreamIR(");
7142+
dump(context, targetLit->getValue());
7143+
dump(context, " : Int, ");
7144+
7145+
// If target is SPIR-V (6), disassemble the blob
7146+
if (targetLit->getValue() == (IRIntegerValue)CodeGenTarget::SPIRV)
7147+
{
7148+
auto blob = blobLitInst->getStringSlice();
7149+
const uint32_t* spirvCode = (const uint32_t*)blob.begin();
7150+
const size_t spirvWordCount = blob.getLength() / sizeof(uint32_t);
7151+
7152+
// Get the compiler from the session through the module
7153+
auto module = inst->getModule();
7154+
auto session = module->getSession();
7155+
IDownstreamCompiler* compiler = session->getOrLoadDownstreamCompiler(
7156+
PassThroughMode::SpirvDis,
7157+
nullptr);
7158+
7159+
if (compiler)
7160+
{
7161+
// Use glslang interface to disassemble with string output
7162+
String disassemblyOutput;
7163+
if (SLANG_SUCCEEDED(compiler->disassembleWithResult(spirvCode, int(spirvWordCount), disassemblyOutput)))
7164+
{
7165+
// Dump the captured disassembly
7166+
dump(context, "\n");
7167+
dumpIndent(context);
7168+
dump(context, disassemblyOutput);
7169+
}
7170+
else
7171+
{
7172+
dump(context, "<disassembly failed>");
7173+
}
7174+
}
7175+
else
7176+
{
7177+
dump(context, "<unavailable disassembler>");
7178+
}
7179+
}
7180+
else
7181+
{
7182+
// TODO: Add DXIL disassembly call here.
7183+
dump(context, "<binary blob>");
7184+
}
7185+
dump(context, ")");
7186+
}
7187+
71207188
static void dumpInstExpr(IRDumpContext* context, IRInst* inst)
71217189
{
71227190
if (!inst)
@@ -7169,69 +7237,7 @@ static void dumpInstExpr(IRDumpContext* context, IRInst* inst)
71697237
// Special case EmbeddedDownstreamIR to show SPIR-V disassembly
71707238
if (op == kIROp_EmbeddedDownstreamIR)
71717239
{
7172-
auto targetInst = inst->getOperand(0);
7173-
auto blobInst = inst->getOperand(1);
7174-
7175-
// Get the target value
7176-
auto targetLit = as<IRIntLit>(targetInst);
7177-
if (!targetLit)
7178-
{
7179-
dump(context, "EmbeddedDownstreamIR(invalid target)");
7180-
return;
7181-
}
7182-
7183-
// Get the blob
7184-
auto blobLitInst = as<IRBlobLit>(blobInst);
7185-
if (!blobLitInst)
7186-
{
7187-
dump(context, "EmbeddedDownstreamIR(invalid blob)");
7188-
return;
7189-
}
7190-
7191-
dump(context, "EmbeddedDownstreamIR(");
7192-
dump(context, targetLit->getValue());
7193-
dump(context, " : Int, ");
7194-
7195-
// If target is SPIR-V (6), disassemble the blob
7196-
if (targetLit->getValue() == (IRIntegerValue)CodeGenTarget::SPIRV)
7197-
{
7198-
auto blob = blobLitInst->getStringSlice();
7199-
const uint32_t* spirvCode = (const uint32_t*)blob.begin();
7200-
const size_t spirvWordCount = blob.getLength() / sizeof(uint32_t);
7201-
7202-
// Get the compiler from the session through the module
7203-
auto module = inst->getModule();
7204-
auto session = module->getSession();
7205-
IDownstreamCompiler* compiler = session->getOrLoadDownstreamCompiler(
7206-
PassThroughMode::SpirvDis,
7207-
nullptr);
7208-
7209-
if (compiler)
7210-
{
7211-
// Use glslang interface to disassemble with string output
7212-
String disassemblyOutput;
7213-
if (SLANG_SUCCEEDED(compiler->disassembleWithResult(spirvCode, int(spirvWordCount), disassemblyOutput)))
7214-
{
7215-
// Dump the captured disassembly
7216-
dump(context, "\n");
7217-
dumpIndent(context);
7218-
dump(context, disassemblyOutput);
7219-
}
7220-
else
7221-
{
7222-
dump(context, "<disassembly failed>");
7223-
}
7224-
}
7225-
else
7226-
{
7227-
dump(context, "<invalid SPIR-V>");
7228-
}
7229-
}
7230-
else
7231-
{
7232-
dump(context, "<binary blob>");
7233-
}
7234-
dump(context, ")");
7240+
dumpEmbeddedDownstream(context, inst);
72357241
return;
72367242
}
72377243

‎source/slang/slang.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -5533,6 +5533,7 @@ RefPtr<ComponentType> CompositeComponentType::create(
55335533
// Y = compose(C,D);
55345534
// Z = compose(X,Y);
55355535
//
5536+
// W = compose(A, B, C, D);
55365537
//
55375538
// Then there is no observable difference between
55385539
// Z and W, so we might prefer to have them be identical.

‎tests/modules/module-dual-target-verify.slang

-28
This file was deleted.
+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// multi-target-module.slang
2+
// Test that a slang-module can store both SPIR-V and DXIL blobs separately
3+
4+
//TEST:SIMPLE(filecheck=CHECK): -o tests/modules/multi-target-module.slang-module -target dxil -embed-downstream-ir -target spirv -embed-downstream-ir -profile lib_6_6 -incomplete-library -dump-ir -verbose-paths
5+
6+
module multi_target_module;
7+
8+
// Simple function that will work on both SPIR-V and DXIL targets
9+
public float4 addVectors(float4 a, float4 b)
10+
{
11+
return a + b;
12+
}
13+
14+
// Another function that should be compatible with both targets
15+
public float3 normalizeVector(float3 v)
16+
{
17+
return normalize(v);
18+
}
19+
20+
[shader("compute")]
21+
[numthreads(8, 8, 1)]
22+
void main(uint3 dispatchThreadID : SV_DispatchThreadID)
23+
{
24+
float4 a = float4(1.0, 2.0, 3.0, 4.0);
25+
float4 b = float4(5.0, 6.0, 7.0, 8.0);
26+
27+
float4 result = addVectors(a, b);
28+
29+
float3 v = float3(1.0, 1.0, 1.0);
30+
float3 n = normalizeVector(v);
31+
}
32+
33+
// Check for the first occurrence of availableInDownstreamIR for addVectors in this section
34+
// Check that there are two entries, one for dxil and one for spirv.
35+
// CHECK: [availableInDownstreamIR(6 : Int)]
36+
// CHECK: [availableInDownstreamIR(10 : Int)]
37+
// CHECK: [public]
38+
// CHECK: [export("_S19multi_target_module10addVectorsp2pi_v4fi_v4fv4f")]
39+
40+
// Check for the second occurrence of availableInDownstreamIR for normalizeVector in this section
41+
// Check that there are two entries, one for dxil and one for spirv.
42+
// CHECK: [availableInDownstreamIR(6 : Int)]
43+
// CHECK: [availableInDownstreamIR(10 : Int)]
44+
// CHECK: [public]
45+
// CHECK: [export("_S19multi_target_module15normalizeVectorp1pi_v3fv3f")]

0 commit comments

Comments
 (0)
Please sign in to comment.