summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2024-10-14 10:06:16 -0700
committerGitHub <noreply@github.com>2024-10-14 10:06:16 -0700
commit2e08f33386b65502e16eea33613bddf98ab8b440 (patch)
treefc2b0f8808b5c8bb8659d054387e77c617220f16
parente57736bdec06246e32f9deea0ad3cc05a433acb1 (diff)
Fix assert when compiling an entrypoint that calls another entrypoint. (#5268)
* Fix assert when compiling an entrypoint that calls another entrypoint. * Fix test.
-rw-r--r--CMakeLists.txt23
-rw-r--r--source/slang/slang-ir-entry-point-uniforms.cpp11
-rw-r--r--tools/slang-test/slang-test-main.cpp3
-rw-r--r--tools/slang-unit-test/unit-test-find-entrypoint-nested.cpp68
4 files changed, 91 insertions, 14 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4e27a724e..0d710c137 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -382,17 +382,18 @@ endif()
#
# This is an executable target because emcmake produces .a files without bindings if you just create a static library
# https://stackoverflow.com/questions/63622009/static-library-built-with-cmake-as-a-with-emscripten-instead-of-wasm-js
-slang_add_target(
- source/slang-wasm
- EXECUTABLE
- EXCLUDE_FROM_ALL
- USE_FEWER_WARNINGS
- LINK_WITH_PRIVATE miniz lz4_static slang core compiler-core
- INCLUDE_DIRECTORIES_PUBLIC include source/slang-wasm
-)
-# To generate binding code
-target_link_options(slang-wasm PUBLIC "--bind")
-
+if(EMSCRIPTEN)
+ slang_add_target(
+ source/slang-wasm
+ EXECUTABLE
+ EXCLUDE_FROM_ALL
+ USE_FEWER_WARNINGS
+ LINK_WITH_PRIVATE miniz lz4_static slang core compiler-core
+ INCLUDE_DIRECTORIES_PUBLIC include source/slang-wasm
+ )
+ # To generate binding code
+ target_link_options(slang-wasm PUBLIC "--bind")
+endif()
#
# Our wrappers for glslang and llvm
#
diff --git a/source/slang/slang-ir-entry-point-uniforms.cpp b/source/slang/slang-ir-entry-point-uniforms.cpp
index a269ec171..aa327caf6 100644
--- a/source/slang/slang-ir-entry-point-uniforms.cpp
+++ b/source/slang/slang-ir-entry-point-uniforms.cpp
@@ -200,8 +200,15 @@ struct CollectEntryPointUniformParams : PerEntryPointPass
// defensive and bail out in the failure case in release builds.
//
auto funcLayoutDecoration = entryPointFunc->findDecoration<IRLayoutDecoration>();
- SLANG_ASSERT(funcLayoutDecoration);
- if(!funcLayoutDecoration)
+
+ // If the module contains two functions with entrypoint decorations,
+ // and one entrypoint calls the other entrypoint, and the user
+ // tells us to compile the caller entrypoint but not the callee
+ // entrypoint, we will not have the layout decoration created for
+ // the callee entrypoint. In this case, we should simply treat the
+ // callee entrypoint as if it is an ordinary function and skip the
+ // rest of the logic here.
+ if (!funcLayoutDecoration)
return;
auto entryPointLayout = as<IREntryPointLayout>(funcLayoutDecoration->getLayout());
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);
+}
+