Skip to content

Commit 5d6578b

Browse files
authored
Don't crash when precompiling twice (shader-slang#6576)
Abort precompileForTarget if it's already done. Fixes shader-slang#6516
1 parent f59e0ef commit 5d6578b

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

source/slang/slang-compiler-tu.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,18 @@ Module::precompileForTarget(SlangCompileTarget target, slang::IBlob** outDiagnos
9595
{
9696
CodeGenTarget targetEnum = CodeGenTarget(target);
9797

98+
// Don't precompile twice for the same target
99+
for (auto globalInst : getIRModule()->getModuleInst()->getChildren())
100+
{
101+
if (auto inst = as<IREmbeddedDownstreamIR>(globalInst))
102+
{
103+
if (inst->getTarget() == targetEnum)
104+
{
105+
return SLANG_OK;
106+
}
107+
}
108+
}
109+
98110
auto module = getIRModule();
99111
auto linkage = getLinkage();
100112
auto builder = IRBuilder(module);

tools/gfx-unit-test/precompiled-module-2.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,15 @@ static Slang::Result precompileProgram(
5959
(void**)precompileService.writeRef()) == SLANG_OK)
6060
{
6161
Slang::ComPtr<slang::IBlob> diagnosticsBlob;
62-
precompileService->precompileForTarget(target, diagnosticsBlob.writeRef());
62+
auto res = precompileService->precompileForTarget(target, diagnosticsBlob.writeRef());
6363
diagnoseIfNeeded(diagnosticsBlob);
64+
SLANG_RETURN_ON_FAIL(res);
65+
66+
// compile a second time to check for driver bugs.
67+
diagnosticsBlob = nullptr;
68+
res = precompileService->precompileForTarget(target, diagnosticsBlob.writeRef());
69+
diagnoseIfNeeded(diagnosticsBlob);
70+
SLANG_RETURN_ON_FAIL(res);
6471
}
6572
}
6673

0 commit comments

Comments
 (0)