diff options
| author | Yong He <yonghe@outlook.com> | 2024-12-19 07:07:31 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-19 23:07:31 +0800 |
| commit | 16f617f944655edf3631dc78bb13c504b53d2771 (patch) | |
| tree | 1b342b185bd93d8d5c30b22060457b017f609386 | |
| parent | a427c5807a3c5d541686d2d382265ecc09bdb95d (diff) | |
Report error when generated spirv is empty. (#5899)
* Report error when generated spirv is empty.
* format code
---------
Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
Co-authored-by: Ellie Hermaszewska <ellieh@nvidia.com>
| -rw-r--r-- | source/slang/slang-diagnostic-defs.h | 6 | ||||
| -rw-r--r-- | source/slang/slang-emit-spirv.cpp | 10 | ||||
| -rw-r--r-- | tests/spirv/empty-module.slang | 7 |
3 files changed, 23 insertions, 0 deletions
diff --git a/source/slang/slang-diagnostic-defs.h b/source/slang/slang-diagnostic-defs.h index 305013f43..a2975e88f 100644 --- a/source/slang/slang-diagnostic-defs.h +++ b/source/slang/slang-diagnostic-defs.h @@ -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( diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp index 92fa507e0..63ebfcf6e 100644 --- a/source/slang/slang-emit-spirv.cpp +++ b/source/slang/slang-emit-spirv.cpp @@ -7964,6 +7964,8 @@ SlangResult emitSPIRVFromIR( { spirvOut.clear(); + bool symbolsEmitted = false; + auto sink = codeGenContext->getSink(); #if 0 @@ -8008,6 +8010,7 @@ SlangResult emitSPIRVFromIR( if (shouldPreserveParams && as<IRGlobalParam>(inst)) { context.ensureInst(inst); + symbolsEmitted = true; } if (generateWholeProgram) { @@ -8016,6 +8019,7 @@ SlangResult emitSPIRVFromIR( if (func->findDecoration<IRDownstreamModuleExportDecoration>()) { context.ensureInst(inst); + symbolsEmitted = true; } } } @@ -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 diff --git a/tests/spirv/empty-module.slang b/tests/spirv/empty-module.slang new file mode 100644 index 000000000..76c98bdb9 --- /dev/null +++ b/tests/spirv/empty-module.slang @@ -0,0 +1,7 @@ +//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK): -target spirv + +// missing entrypoint attribute +void vertMain() +{} + +// CHECK: error 57004
\ No newline at end of file |
