diff options
| author | Yong He <yonghe@outlook.com> | 2024-10-16 17:17:19 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-16 17:17:19 -0700 |
| commit | 2f7f48a00752b906d6a2d42cd1bb6fbf0cfeaad6 (patch) | |
| tree | 8704eae12930a7c87a8e9ef72e2a56acfeb393fc | |
| parent | 2ee898109006986250d5356a59003eb741a89ca4 (diff) | |
Fix entrypoint naming in glsl backend. (#5320)
| -rw-r--r-- | source/slang/slang-emit-c-like.cpp | 14 | ||||
| -rw-r--r-- | tools/slang-unit-test/unit-test-find-entrypoint-nested.cpp | 8 |
2 files changed, 21 insertions, 1 deletions
diff --git a/source/slang/slang-emit-c-like.cpp b/source/slang/slang-emit-c-like.cpp index 28eb7da04..b113f726e 100644 --- a/source/slang/slang-emit-c-like.cpp +++ b/source/slang/slang-emit-c-like.cpp @@ -1085,7 +1085,19 @@ String CLikeSourceEmitter::generateName(IRInst* inst) // use the appropriate options for glslang to // make it support a non-`main` name. // - return "main"; + // A function may have an entry-point deocration if it + // is declared by the user as an entry-point function. + // However it may not actually be compiled as an entry-point + // when generating code for targets that doesn't support + // multiple entry-points. + // We only want to emit "main" for user-marked entrypoint + // functions that are actually being selected as entrypoint + // for current compilation. We can do so by checking if + // a layout decoration existed on the function. + if (inst->findDecoration<IRLayoutDecoration>()) + { + return "main"; + } } return generateEntryPointNameImpl(entryPointDecor); diff --git a/tools/slang-unit-test/unit-test-find-entrypoint-nested.cpp b/tools/slang-unit-test/unit-test-find-entrypoint-nested.cpp index 4b6e01200..addada5b6 100644 --- a/tools/slang-unit-test/unit-test-find-entrypoint-nested.cpp +++ b/tools/slang-unit-test/unit-test-find-entrypoint-nested.cpp @@ -22,6 +22,7 @@ SLANG_UNIT_TEST(findEntryPointNested) [shader("raygeneration")] void inner() { + AllMemoryBarrier(); } [shader("raygeneration")] void outer() @@ -40,6 +41,13 @@ SLANG_UNIT_TEST(findEntryPointNested) slang::SessionDesc sessionDesc = {}; sessionDesc.targetCount = 1; sessionDesc.targets = &targetDesc; + sessionDesc.compilerOptionEntryCount = 1; + slang::CompilerOptionEntry compilerOptionEntry = {}; + compilerOptionEntry.name = slang::CompilerOptionName::EmitSpirvViaGLSL; + compilerOptionEntry.value.kind = slang::CompilerOptionValueKind::Int; + compilerOptionEntry.value.intValue0 = 1; + sessionDesc.compilerOptionEntries = &compilerOptionEntry; + ComPtr<slang::ISession> session; SLANG_CHECK(globalSession->createSession(sessionDesc, session.writeRef()) == SLANG_OK); |
