From 9604118401f185c0e1a213b8e99dad060c6263bc Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Wed, 13 Nov 2019 13:35:56 -0500 Subject: * Added getCStr(Name*) (#1121) * Added the name to the EntryPointLayout so is always available * Made spReflectionEntryPoint_getName use name * Improved checking for entry point name in render-test * Improved COMPILE test type to allow failure and output of failure. --- source/slang/slang-name.cpp | 5 +++++ source/slang/slang-name.h | 3 +++ source/slang/slang-parameter-binding.cpp | 1 + source/slang/slang-reflection.cpp | 4 +--- source/slang/slang-type-layout.h | 3 +++ tools/render-test/slang-support.cpp | 27 +++++++++++++++++++++++---- tools/slang-test/slang-test-main.cpp | 12 ++++++++++++ 7 files changed, 48 insertions(+), 7 deletions(-) diff --git a/source/slang/slang-name.cpp b/source/slang/slang-name.cpp index 8934b17bd..b6035982b 100644 --- a/source/slang/slang-name.cpp +++ b/source/slang/slang-name.cpp @@ -14,6 +14,11 @@ UnownedStringSlice getUnownedStringSliceText(Name* name) return name ? name->text.getUnownedSlice() : UnownedStringSlice(); } +const char* getCstr(Name* name) +{ + return name ? name->text.getBuffer() : nullptr; +} + Name* NamePool::getName(String const& text) { RefPtr name; diff --git a/source/slang/slang-name.h b/source/slang/slang-name.h index de04d5fdf..cf702686b 100644 --- a/source/slang/slang-name.h +++ b/source/slang/slang-name.h @@ -39,6 +39,9 @@ String getText(Name* name); /// Get the text as unowned string slice UnownedStringSlice getUnownedStringSliceText(Name* name); +// Get a name as a C style string, or nullptr if name is nullptr +const char* getCstr(Name* name); + // A `RootNamePool` is used to store and look up names. // If two systems need to work together with names, and be sure that they // get equivalent names for a string like `"Foo"`, then they need to use diff --git a/source/slang/slang-parameter-binding.cpp b/source/slang/slang-parameter-binding.cpp index 33ad32918..5ea81c809 100644 --- a/source/slang/slang-parameter-binding.cpp +++ b/source/slang/slang-parameter-binding.cpp @@ -2166,6 +2166,7 @@ static RefPtr collectEntryPointParameters( // RefPtr entryPointLayout = new EntryPointLayout(); entryPointLayout->profile = entryPoint->getProfile(); + entryPointLayout->name = entryPoint->getName(); // The entry point layout must be added to the output // program layout so that it can be accessed by reflection. diff --git a/source/slang/slang-reflection.cpp b/source/slang/slang-reflection.cpp index f2c4973ed..59130b0fc 100644 --- a/source/slang/slang-reflection.cpp +++ b/source/slang/slang-reflection.cpp @@ -1210,9 +1210,7 @@ SLANG_API char const* spReflectionEntryPoint_getName( SlangReflectionEntryPoint* inEntryPoint) { auto entryPointLayout = convert(inEntryPoint); - if(!entryPointLayout) return 0; - - return getText(entryPointLayout->entryPoint.GetName()).begin(); + return entryPointLayout ? getCstr(entryPointLayout->name) : nullptr; } SLANG_API unsigned spReflectionEntryPoint_getParameterCount( diff --git a/source/slang/slang-type-layout.h b/source/slang/slang-type-layout.h index ac0ef3bd7..fc638c3dd 100644 --- a/source/slang/slang-type-layout.h +++ b/source/slang/slang-type-layout.h @@ -658,6 +658,9 @@ public: // The shader profile that was used to compile the entry point Profile profile; + // The name of the entry point. Always available even if entryPoint is nullptr (for example when it came from a library) + Name* name = nullptr; + // Layout for any results of the entry point RefPtr resultLayout; diff --git a/tools/render-test/slang-support.cpp b/tools/render-test/slang-support.cpp index 06284e1e3..5b038d208 100644 --- a/tools/render-test/slang-support.cpp +++ b/tools/render-test/slang-support.cpp @@ -149,20 +149,22 @@ static const char computeEntryPointName[] = "computeMain"; if (request.computeShader.name) { - int computeEntryPoint = 0; + int computeEntryPointIndex = 0; if(!gOptions.dontAddDefaultEntryPoints) { - computeEntryPoint = spAddEntryPointEx(slangRequest, computeTranslationUnit, + computeEntryPointIndex = spAddEntryPointEx(slangRequest, computeTranslationUnit, computeEntryPointName, SLANG_STAGE_COMPUTE, (int)rawEntryPointTypeNames.getCount(), rawEntryPointTypeNames.getBuffer()); - setEntryPointExistentialTypeArgs(computeEntryPoint); + setEntryPointExistentialTypeArgs(computeEntryPointIndex); } spSetLineDirectiveMode(slangRequest, SLANG_LINE_DIRECTIVE_MODE_NONE); + const SlangResult res = spCompile(slangRequest); + if (auto diagnostics = spGetDiagnosticOutput(slangRequest)) { fprintf(stderr, "%s", diagnostics); @@ -170,9 +172,26 @@ static const char computeEntryPointName[] = "computeMain"; SLANG_RETURN_ON_FAIL(res); + // We are going to get the entry point count... lets check what we have + { + auto reflection = spGetReflection(slangRequest); + // Get the amount of entry points in reflection + const int entryPointCount = int(spReflection_getEntryPointCount(reflection)); + + // Above code assumes there is an entry point + SLANG_ASSERT(entryPointCount && computeEntryPointIndex < entryPointCount); + + auto entryPoint = spReflection_getEntryPointByIndex(reflection, computeEntryPointIndex); + + // Get the entry point name + const char* entryPointName = spReflectionEntryPoint_getName(entryPoint); + + SLANG_ASSERT(entryPointName); + } + { size_t codeSize = 0; - char const* code = (char const*) spGetEntryPointCode(slangRequest, computeEntryPoint, &codeSize); + char const* code = (char const*) spGetEntryPointCode(slangRequest, computeEntryPointIndex, &codeSize); ShaderProgram::KernelDesc kernelDesc; kernelDesc.stage = StageType::Compute; diff --git a/tools/slang-test/slang-test-main.cpp b/tools/slang-test/slang-test-main.cpp index 2000bf617..e0474ebe6 100644 --- a/tools/slang-test/slang-test-main.cpp +++ b/tools/slang-test/slang-test-main.cpp @@ -1106,6 +1106,18 @@ TestResult runCompile(TestContext* context, TestInput& input) return TestResult::Pass; } + if (exeRes.resultCode != 0) + { + auto reporter = context->reporter; + if (reporter) + { + auto output = getOutput(exeRes); + reporter->message(TestMessageType::TestFailure, output); + } + + return TestResult::Fail; + } + return TestResult::Pass; } -- cgit v1.2.3