Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report error when generated spirv is empty. #5899

Merged
merged 4 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions source/slang/slang-diagnostic-defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -2452,6 +2452,12 @@ DIAGNOSTIC(
DIAGNOSTIC(57001, Warning, spirvOptFailed, "spirv-opt failed. $0")
DIAGNOSTIC(57002, Error, unknownPatchConstantParameter, "unknown patch constant parameter '$0'.")
DIAGNOSTIC(57003, Error, unknownTessPartitioning, "unknown tessellation partitioning '$0'.")
DIAGNOSTIC(
57004,
Error,
outputSpvIsEmpty,
"output SPIR-V contains no exported symbols. Please make sure to specify at least one "
"entrypoint.")

// GLSL Compatibility
DIAGNOSTIC(
Expand Down
10 changes: 10 additions & 0 deletions source/slang/slang-emit-spirv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7964,6 +7964,8 @@ SlangResult emitSPIRVFromIR(
{
spirvOut.clear();

bool symbolsEmitted = false;

auto sink = codeGenContext->getSink();

#if 0
Expand Down Expand Up @@ -8008,6 +8010,7 @@ SlangResult emitSPIRVFromIR(
if (shouldPreserveParams && as<IRGlobalParam>(inst))
{
context.ensureInst(inst);
symbolsEmitted = true;
}
if (generateWholeProgram)
{
Expand All @@ -8016,6 +8019,7 @@ SlangResult emitSPIRVFromIR(
if (func->findDecoration<IRDownstreamModuleExportDecoration>())
{
context.ensureInst(inst);
symbolsEmitted = true;
}
}
}
Expand Down Expand Up @@ -8046,8 +8050,14 @@ SlangResult emitSPIRVFromIR(
for (auto irEntryPoint : irEntryPoints)
{
context.ensureInst(irEntryPoint);
symbolsEmitted = true;
}

if (!symbolsEmitted)
{
sink->diagnose(irModule->getModuleInst(), Diagnostics::outputSpvIsEmpty);
return SLANG_FAIL;
}

// Move forward delcared pointers to the end.
do
Expand Down
7 changes: 7 additions & 0 deletions tests/spirv/empty-module.slang
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK): -target spirv

// missing entrypoint attribute
void vertMain()
{}

// CHECK: error 57004
Loading