diff options
| author | Yong He <yonghe@outlook.com> | 2024-10-14 10:06:16 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-14 10:06:16 -0700 |
| commit | 2e08f33386b65502e16eea33613bddf98ab8b440 (patch) | |
| tree | fc2b0f8808b5c8bb8659d054387e77c617220f16 /tools/slang-unit-test/unit-test-find-entrypoint-nested.cpp | |
| parent | e57736bdec06246e32f9deea0ad3cc05a433acb1 (diff) | |
Fix assert when compiling an entrypoint that calls another entrypoint. (#5268)
* Fix assert when compiling an entrypoint that calls another entrypoint.
* Fix test.
Diffstat (limited to 'tools/slang-unit-test/unit-test-find-entrypoint-nested.cpp')
| -rw-r--r-- | tools/slang-unit-test/unit-test-find-entrypoint-nested.cpp | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/tools/slang-unit-test/unit-test-find-entrypoint-nested.cpp b/tools/slang-unit-test/unit-test-find-entrypoint-nested.cpp new file mode 100644 index 000000000..4b6e01200 --- /dev/null +++ b/tools/slang-unit-test/unit-test-find-entrypoint-nested.cpp @@ -0,0 +1,68 @@ +// unit-test-find-entrypoint-nested.cpp + +#include "slang.h" + +#include <stdio.h> +#include <stdlib.h> + +#include "tools/unit-test/slang-unit-test.h" +#include "slang-com-ptr.h" +#include "../../source/core/slang-io.h" +#include "../../source/core/slang-process.h" + +using namespace Slang; + +// Test that the IModule::findAndCheckEntryPoint API works with modules that +// defines two entrypoints, where one entrypoint calls the other. + +SLANG_UNIT_TEST(findEntryPointNested) +{ + // Source for a module that contains an undecorated entrypoint. + const char* userSourceBody = R"( + [shader("raygeneration")] + void inner() + { + } + [shader("raygeneration")] + void outer() + { + inner(); + } + )"; + + auto moduleName = "moduleG" + String(Process::getId()); + String userSource = "import " + moduleName + ";\n" + userSourceBody; + ComPtr<slang::IGlobalSession> globalSession; + SLANG_CHECK(slang_createGlobalSession(SLANG_API_VERSION, globalSession.writeRef()) == SLANG_OK); + slang::TargetDesc targetDesc = {}; + targetDesc.format = SLANG_SPIRV; + targetDesc.profile = globalSession->findProfile("spirv_1_5"); + slang::SessionDesc sessionDesc = {}; + sessionDesc.targetCount = 1; + sessionDesc.targets = &targetDesc; + ComPtr<slang::ISession> session; + SLANG_CHECK(globalSession->createSession(sessionDesc, session.writeRef()) == SLANG_OK); + + ComPtr<slang::IBlob> diagnosticBlob; + auto module = session->loadModuleFromSourceString("m", "m.slang", userSourceBody, diagnosticBlob.writeRef()); + SLANG_CHECK(module != nullptr); + + ComPtr<slang::IEntryPoint> entryPoint; + module->findAndCheckEntryPoint("outer", SLANG_STAGE_RAY_GENERATION, entryPoint.writeRef(), diagnosticBlob.writeRef()); + SLANG_CHECK(entryPoint != nullptr); + + ComPtr<slang::IComponentType> compositeProgram; + slang::IComponentType* components[] = { module, entryPoint.get() }; + session->createCompositeComponentType(components, 2, compositeProgram.writeRef(), diagnosticBlob.writeRef()); + SLANG_CHECK(compositeProgram != nullptr); + + ComPtr<slang::IComponentType> linkedProgram; + compositeProgram->link(linkedProgram.writeRef(), diagnosticBlob.writeRef()); + SLANG_CHECK(linkedProgram != nullptr); + + ComPtr<slang::IBlob> code; + linkedProgram->getEntryPointCode(0, 0, code.writeRef(), diagnosticBlob.writeRef()); + SLANG_CHECK(code != nullptr); + SLANG_CHECK(code->getBufferSize() != 0); +} + |
