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 | |
| 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')
| -rw-r--r-- | tools/slang-test/slang-test-main.cpp | 3 | ||||
| -rw-r--r-- | tools/slang-unit-test/unit-test-find-entrypoint-nested.cpp | 68 |
2 files changed, 70 insertions, 1 deletions
diff --git a/tools/slang-test/slang-test-main.cpp b/tools/slang-test/slang-test-main.cpp index b493b40b0..150e21d5d 100644 --- a/tools/slang-test/slang-test-main.cpp +++ b/tools/slang-test/slang-test-main.cpp @@ -4644,7 +4644,8 @@ SlangResult innerMain(int argc, char** argv) static constexpr int kFailedTestLimitForRetry = 16; if (context.failedFileTests.getCount() <= kFailedTestLimitForRetry) { - printf("Retrying %d failed tests...\n", (int)context.failedFileTests.getCount()); + if (context.failedFileTests.getCount() > 0) + printf("Retrying %d failed tests...\n", (int)context.failedFileTests.getCount()); for (auto& test : context.failedFileTests) { FileTestInfoImpl* fileTestInfo = static_cast<FileTestInfoImpl*>(test.Ptr()); 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); +} + |
