diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2018-11-21 13:41:34 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-11-21 13:41:34 -0500 |
| commit | e21d5ad650130631e17662ce8f22d15315ab597a (patch) | |
| tree | a1f5053efebc6184d21b0151e38ba1a52e74b07c | |
| parent | 9bb11b69a08c66e2857f439837e2253658aed9a4 (diff) | |
Feature/early depth stencil (#727)
* First pass support for early depth stencil.
* Add a simple test to check if output has attributes.
* Use cross compilation to test [earlydepthstencil] on glsl.
* If target is dxil, use dxc to test against.
Add hlsl to test earlydepthstencil against.
* * Added spSessionHasCompileTargetSupport
* Made slang-test use spSessionHasCompileTargetSupport to ignore tests that cannot run
| -rw-r--r-- | premake5.lua | 2 | ||||
| -rw-r--r-- | slang.h | 13 | ||||
| -rw-r--r-- | source/core/platform.cpp | 5 | ||||
| -rw-r--r-- | source/slang-glslang/slang-glslang.vcxproj | 2 | ||||
| -rw-r--r-- | source/slang-glslang/slang-glslang.vcxproj.filters | 6 | ||||
| -rw-r--r-- | source/slang/check.cpp | 10 | ||||
| -rw-r--r-- | source/slang/compiler.cpp | 58 | ||||
| -rw-r--r-- | source/slang/compiler.h | 5 | ||||
| -rw-r--r-- | source/slang/emit.cpp | 19 | ||||
| -rw-r--r-- | source/slang/ir-insts.h | 5 | ||||
| -rw-r--r-- | source/slang/ir-serialize.cpp | 7 | ||||
| -rw-r--r-- | source/slang/ir.cpp | 11 | ||||
| -rw-r--r-- | source/slang/ir.h | 2 | ||||
| -rw-r--r-- | source/slang/lower-to-ir.cpp | 5 | ||||
| -rw-r--r-- | source/slang/modifier-defs.h | 3 | ||||
| -rw-r--r-- | source/slang/slang.cpp | 10 | ||||
| -rw-r--r-- | tests/cross-compile/early-depth-stencil.hlsl | 9 | ||||
| -rw-r--r-- | tests/cross-compile/early-depth-stencil.hlsl.glsl | 16 | ||||
| -rw-r--r-- | tests/cross-compile/early-depth-stencil.hlsl.hlsl | 8 | ||||
| -rw-r--r-- | tools/slang-test/main.cpp | 64 | ||||
| -rw-r--r-- | tools/slang-test/slang-test.vcxproj | 3 | ||||
| -rw-r--r-- | tools/slang-test/test-context.cpp | 29 | ||||
| -rw-r--r-- | tools/slang-test/test-context.h | 12 |
23 files changed, 285 insertions, 19 deletions
diff --git a/premake5.lua b/premake5.lua index 8e02d433f..dcc86913a 100644 --- a/premake5.lua +++ b/premake5.lua @@ -435,7 +435,7 @@ tool "slang-generate" tool "slang-test" uuid "0C768A18-1D25-4000-9F37-DA5FE99E3B64" includedirs { "." } - links { "core" } + links { "core", "slang" } -- -- The reflection test harness `slang-reflection-test` is pretty @@ -1,4 +1,4 @@ -#ifndef SLANG_H +#ifndef SLANG_H #define SLANG_H /** \file slang.h @@ -354,7 +354,7 @@ extern "C" typedef uint32_t SlangUInt32; typedef intptr_t SlangInt; typedef uintptr_t SlangUInt; - + /*! @brief Severity of a diagnostic generated by the compiler. Values come from the enum below, with higher values representing more severe @@ -846,6 +846,15 @@ extern "C" SlangSession* session); /*! + @brief Returns SLANG_OK if a the compilation target is supported for this session + @param session Session + @param target The compilation target to test + @return SLANG_OK if the target is available */ + SLANG_API SlangResult spSessionHasCompileTargetSupport( + SlangSession* session, + SlangCompileTarget target); + + /*! @brief Add new builtin declarations to be used in subsequent compiles. */ SLANG_API void spAddBuiltins( diff --git a/source/core/platform.cpp b/source/core/platform.cpp index b96240def..d160fd37c 100644 --- a/source/core/platform.cpp +++ b/source/core/platform.cpp @@ -85,10 +85,13 @@ namespace Slang void* h = dlopen(platformFileName, RTLD_NOW | RTLD_LOCAL); if(!h) { +#if 0 + // We can't output the error message here, because it will cause output when testing what code gen is available if(auto msg = dlerror()) { fprintf(stderr, "error: %s\n", msg); } +#endif return SLANG_FAIL; } handleOut = (Handle)h; @@ -116,4 +119,4 @@ namespace Slang #endif // _WIN32 -}
\ No newline at end of file +} diff --git a/source/slang-glslang/slang-glslang.vcxproj b/source/slang-glslang/slang-glslang.vcxproj index 28e64e8de..eb53fc311 100644 --- a/source/slang-glslang/slang-glslang.vcxproj +++ b/source/slang-glslang/slang-glslang.vcxproj @@ -200,6 +200,7 @@ <ClInclude Include="..\..\external\glslang\glslang\MachineIndependent\iomapper.h" /> <ClInclude Include="..\..\external\glslang\glslang\MachineIndependent\localintermediate.h" /> <ClInclude Include="..\..\external\glslang\glslang\MachineIndependent\parseVersions.h" /> + <ClInclude Include="..\..\external\glslang\glslang\MachineIndependent\pch.h" /> <ClInclude Include="..\..\external\glslang\glslang\MachineIndependent\preprocessor\PpContext.h" /> <ClInclude Include="..\..\external\glslang\glslang\MachineIndependent\preprocessor\PpTokens.h" /> <ClInclude Include="..\..\external\glslang\glslang\MachineIndependent\propagateNoContraction.h" /> @@ -242,6 +243,7 @@ <ClCompile Include="..\..\external\glslang\glslang\MachineIndependent\limits.cpp" /> <ClCompile Include="..\..\external\glslang\glslang\MachineIndependent\linkValidate.cpp" /> <ClCompile Include="..\..\external\glslang\glslang\MachineIndependent\parseConst.cpp" /> + <ClCompile Include="..\..\external\glslang\glslang\MachineIndependent\pch.cpp" /> <ClCompile Include="..\..\external\glslang\glslang\MachineIndependent\preprocessor\Pp.cpp" /> <ClCompile Include="..\..\external\glslang\glslang\MachineIndependent\preprocessor\PpAtom.cpp" /> <ClCompile Include="..\..\external\glslang\glslang\MachineIndependent\preprocessor\PpContext.cpp" /> diff --git a/source/slang-glslang/slang-glslang.vcxproj.filters b/source/slang-glslang/slang-glslang.vcxproj.filters index 2e15ff5bd..482728c71 100644 --- a/source/slang-glslang/slang-glslang.vcxproj.filters +++ b/source/slang-glslang/slang-glslang.vcxproj.filters @@ -111,6 +111,9 @@ <ClInclude Include="..\..\external\glslang\glslang\MachineIndependent\parseVersions.h"> <Filter>Header Files</Filter> </ClInclude> + <ClInclude Include="..\..\external\glslang\glslang\MachineIndependent\pch.h"> + <Filter>Header Files</Filter> + </ClInclude> <ClInclude Include="..\..\external\glslang\glslang\MachineIndependent\preprocessor\PpContext.h"> <Filter>Header Files</Filter> </ClInclude> @@ -233,6 +236,9 @@ <ClCompile Include="..\..\external\glslang\glslang\MachineIndependent\parseConst.cpp"> <Filter>Source Files</Filter> </ClCompile> + <ClCompile Include="..\..\external\glslang\glslang\MachineIndependent\pch.cpp"> + <Filter>Source Files</Filter> + </ClCompile> <ClCompile Include="..\..\external\glslang\glslang\MachineIndependent\preprocessor\Pp.cpp"> <Filter>Source Files</Filter> </ClCompile> diff --git a/source/slang/check.cpp b/source/slang/check.cpp index 00c6f6dd0..e07bdf156 100644 --- a/source/slang/check.cpp +++ b/source/slang/check.cpp @@ -311,7 +311,10 @@ namespace Slang const char* libName = DefaultSharedLibraryLoader::getSharedLibraryNameFromType(type); if (SLANG_FAILED(sharedLibraryLoader->loadSharedLibrary(libName, sharedLibraries[int(type)].writeRef()))) { - sink->diagnose(SourceLoc(), Diagnostics::failedToLoadDynamicLibrary, libName); + if (sink) + { + sink->diagnose(SourceLoc(), Diagnostics::failedToLoadDynamicLibrary, libName); + } return nullptr; } } @@ -2072,6 +2075,11 @@ namespace Slang // Has no args SLANG_ASSERT(attr->args.Count() == 0); } + else if (attr.As<EarlyDepthStencilAttribute>()) + { + // Has no args + SLANG_ASSERT(attr->args.Count() == 0); + } else { if(attr->args.Count() == 0) diff --git a/source/slang/compiler.cpp b/source/slang/compiler.cpp index cab6355c1..1e514812a 100644 --- a/source/slang/compiler.cpp +++ b/source/slang/compiler.cpp @@ -181,6 +181,64 @@ namespace Slang } + bool hasCodeGenTarget(Session* session, CodeGenTarget target) + { + switch (target) + { + case CodeGenTarget::Unknown: return false; + case CodeGenTarget::None: return true; + case CodeGenTarget::GLSL: + case CodeGenTarget::GLSL_Vulkan: + case CodeGenTarget::GLSL_Vulkan_OneDesc: + { + // Can always output GLSL + return true; + } + case CodeGenTarget::HLSL: + { + // Can always output HLSL + return true; + } + case CodeGenTarget::SPIRVAssembly: + case CodeGenTarget::SPIRV: + { +#if SLANG_ENABLE_GLSLANG_SUPPORT + return session->getOrLoadSharedLibrary(Slang::SharedLibraryType::Glslang, nullptr) != nullptr; +#else + return false; +#endif + } + case CodeGenTarget::DXBytecode: + case CodeGenTarget::DXBytecodeAssembly: + { +#if SLANG_ENABLE_DXBC_SUPPORT + // Must have fxc + return session->getOrLoadSharedLibrary(SharedLibraryType::Fxc, nullptr) != nullptr; +#else + return false; +#endif + } + + case CodeGenTarget::DXIL: + case CodeGenTarget::DXILAssembly: + { +#if SLANG_ENABLE_DXIL_SUPPORT + // Must have dxc + return session->getOrLoadSharedLibrary(SharedLibraryType::Dxc, nullptr) && + session->getOrLoadSharedLibrary(SharedLibraryType::Dxil, nullptr); +#else + return false; +#endif + } + + default: + { + SLANG_ASSERT(!"Unhandled target"); + return false; + } + } + } + // String emitHLSLForEntryPoint( diff --git a/source/slang/compiler.h b/source/slang/compiler.h index c8c242568..0eaf6e8e9 100644 --- a/source/slang/compiler.h +++ b/source/slang/compiler.h @@ -1,4 +1,4 @@ -#ifndef SLANG_COMPILER_H_INCLUDED +#ifndef SLANG_COMPILER_H_INCLUDED #define SLANG_COMPILER_H_INCLUDED #include "../core/basic.h" @@ -499,6 +499,9 @@ namespace Slang char const* text, CodeGenTarget target); + /* Returns true if a codeGen target is available. */ + bool hasCodeGenTarget(Session* session, CodeGenTarget target); + struct TypeCheckingCache; // diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp index a3b99691d..bf98a1b24 100644 --- a/source/slang/emit.cpp +++ b/source/slang/emit.cpp @@ -4702,6 +4702,14 @@ struct EmitVisitor break; } + case Stage::Pixel: + { + if (irFunc->findDecoration<IREarlyDepthStencilDecoration>()) + { + emit("[earlydepthstencil]\n"); + } + break; + } // TODO: There are other stages that will need this kind of handling. default: break; @@ -4709,7 +4717,7 @@ struct EmitVisitor } void emitIREntryPointAttributes_GLSL( - IRFunc* /*irFunc*/, + IRFunc* irFunc, EmitContext* /*ctx*/, EntryPointLayout* entryPointLayout) { @@ -4805,6 +4813,15 @@ struct EmitVisitor } break; + case Stage::Pixel: + { + if (irFunc->findDecoration<IREarlyDepthStencilDecoration>()) + { + // https://www.khronos.org/opengl/wiki/Early_Fragment_Test + emit("layout(early_fragment_tests) in;\n"); + } + break; + } // TODO: There are other stages that will need this kind of handling. default: break; diff --git a/source/slang/ir-insts.h b/source/slang/ir-insts.h index 5cbdf326e..fc0c5f884 100644 --- a/source/slang/ir-insts.h +++ b/source/slang/ir-insts.h @@ -160,6 +160,11 @@ struct IRReadNoneDecoration : IRDecoration enum { kDecorationOp = kIRDecorationOp_ReadNone }; }; +struct IREarlyDepthStencilDecoration : IRDecoration +{ + enum { kDecorationOp = kIRDecorationOp_EarlyDepthStencil }; +}; + // An instruction that specializes another IR value // (representing a generic) to a particular set of generic arguments // (instructions representing types, witness tables, etc.) diff --git a/source/slang/ir-serialize.cpp b/source/slang/ir-serialize.cpp index 7e7c6c8a7..d8a01fb56 100644 --- a/source/slang/ir-serialize.cpp +++ b/source/slang/ir-serialize.cpp @@ -706,6 +706,7 @@ Result IRSerialWriter::write(IRModule* module, SourceManager* sourceManager, Opt case kIRDecorationOp_VulkanRayPayload: case kIRDecorationOp_VulkanCallablePayload: case kIRDecorationOp_VulkanHitAttributes: + case kIRDecorationOp_EarlyDepthStencil: case kIRDecorationOp_ReadNone: { dstInst.m_payloadType = PayloadType::Empty; @@ -1567,6 +1568,12 @@ IRDecoration* IRSerialReader::_createDecoration(const Ser::Inst& srcInst) SLANG_ASSERT(srcInst.m_payloadType == PayloadType::Empty); return decor; } + case kIRDecorationOp_EarlyDepthStencil: + { + auto decor = createEmptyDecoration<IREarlyDepthStencilDecoration>(m_module); + SLANG_ASSERT(srcInst.m_payloadType == PayloadType::Empty); + return decor; + } case kIRDecorationOp_VulkanHitAttributes: { auto decor = createEmptyDecoration<IRVulkanHitAttributesDecoration>(m_module); diff --git a/source/slang/ir.cpp b/source/slang/ir.cpp index 356648212..664927e8a 100644 --- a/source/slang/ir.cpp +++ b/source/slang/ir.cpp @@ -2949,6 +2949,11 @@ namespace Slang dump(context, "\n[__readNone]"); } break; + case kIRDecorationOp_EarlyDepthStencil: + { + dump(context, "\n[earlydepthstencil]"); + } + break; } } } @@ -5387,7 +5392,11 @@ namespace Slang context->builder->addDecoration<IRVulkanCallablePayloadDecoration>(clonedValue); } break; - + case kIRDecorationOp_EarlyDepthStencil: + { + context->builder->addDecoration<IREarlyDepthStencilDecoration>(clonedValue); + } + break; case kIRDecorationOp_VulkanHitAttributes: { context->builder->addDecoration<IRVulkanHitAttributesDecoration>(clonedValue); diff --git a/source/slang/ir.h b/source/slang/ir.h index b3c690c26..b8c8e85f2 100644 --- a/source/slang/ir.h +++ b/source/slang/ir.h @@ -160,6 +160,8 @@ enum IRDecorationOp : uint16_t kIRDecorationOp_ReadNone, kIRDecorationOp_VulkanCallablePayload, + kIRDecorationOp_EarlyDepthStencil, + kIRDecorationOp_CountOf }; diff --git a/source/slang/lower-to-ir.cpp b/source/slang/lower-to-ir.cpp index 4f40b4af6..1390cddaf 100644 --- a/source/slang/lower-to-ir.cpp +++ b/source/slang/lower-to-ir.cpp @@ -5146,6 +5146,11 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo> getBuilder()->addDecoration<IRReadNoneDecoration>(irFunc); } + if (decl->FindModifier<EarlyDepthStencilAttribute>()) + { + getBuilder()->addDecoration<IREarlyDepthStencilDecoration>(irFunc); + } + // For convenience, ensure that any additional global // values that were emitted while outputting the function // body appear before the function itself in the list diff --git a/source/slang/modifier-defs.h b/source/slang/modifier-defs.h index f6f55ecbd..5c86301ad 100644 --- a/source/slang/modifier-defs.h +++ b/source/slang/modifier-defs.h @@ -327,6 +327,7 @@ SIMPLE_SYNTAX_CLASS(FlattenAttribute, Attribute) // `[flatten]` SIMPLE_SYNTAX_CLASS(ForceCaseAttribute, Attribute) // `[forcecase]` SIMPLE_SYNTAX_CLASS(CallAttribute, Attribute) // `[call]` + // [[vk_push_constant]] [[push_constant]] SIMPLE_SYNTAX_CLASS(PushConstantAttribute, Attribute) @@ -348,7 +349,7 @@ SYNTAX_CLASS(PatchConstantFuncAttribute, Attribute) END_SYNTAX_CLASS() SIMPLE_SYNTAX_CLASS(DomainAttribute, Attribute) -SIMPLE_SYNTAX_CLASS(EarlyDepthStencilAttribute, Attribute) +SIMPLE_SYNTAX_CLASS(EarlyDepthStencilAttribute, Attribute) // `[earlydepthstencil]` // An HLSL `[numthreads(x,y,z)]` attribute SYNTAX_CLASS(NumThreadsAttribute, Attribute) diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index 28b504831..ef71430fc 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -1,4 +1,4 @@ -#include "../../slang.h" +#include "../../slang.h" #include "../core/slang-io.h" #include "../core/slang-string-util.h" @@ -1147,6 +1147,14 @@ SLANG_API ISlangSharedLibraryLoader* spSessionGetSharedLibraryLoader( return (s->sharedLibraryLoader == Slang::DefaultSharedLibraryLoader::getSingleton()) ? nullptr : s->sharedLibraryLoader.get(); } +SLANG_API SlangResult spSessionHasCompileTargetSupport( + SlangSession* session, + SlangCompileTarget target) +{ + auto s = SESSION(session); + return Slang::hasCodeGenTarget(s, Slang::CodeGenTarget(target)) ? SLANG_OK : SLANG_FAIL; +} + SLANG_API SlangCompileRequest* spCreateCompileRequest( SlangSession* session) { diff --git a/tests/cross-compile/early-depth-stencil.hlsl b/tests/cross-compile/early-depth-stencil.hlsl new file mode 100644 index 000000000..b40a29aba --- /dev/null +++ b/tests/cross-compile/early-depth-stencil.hlsl @@ -0,0 +1,9 @@ +//TEST:CROSS_COMPILE:-target spirv-assembly -entry main -stage fragment +//TEST:CROSS_COMPILE:-profile ps_6_0 -target dxil-assembly -entry main + +[earlydepthstencil] +float4 main(): SV_Target +{ + return float4(1, 0, 0, 1); +} + diff --git a/tests/cross-compile/early-depth-stencil.hlsl.glsl b/tests/cross-compile/early-depth-stencil.hlsl.glsl new file mode 100644 index 000000000..73e258a82 --- /dev/null +++ b/tests/cross-compile/early-depth-stencil.hlsl.glsl @@ -0,0 +1,16 @@ +//TEST_IGNORE_FILE: +#version 450 +layout(row_major) uniform; +layout(row_major) buffer; + +#line 5 0 +layout(location = 0) +out vec4 _S1; + +#line 5 +layout(early_fragment_tests) in; +void main() +{ + _S1 = vec4(float(1), float(0), float(0), float(1)); + return; +} diff --git a/tests/cross-compile/early-depth-stencil.hlsl.hlsl b/tests/cross-compile/early-depth-stencil.hlsl.hlsl new file mode 100644 index 000000000..378c5c0a1 --- /dev/null +++ b/tests/cross-compile/early-depth-stencil.hlsl.hlsl @@ -0,0 +1,8 @@ +//TEST_IGNORE_FILE: +#pragma pack_matrix(column_major) + +[earlydepthstencil] +vector<float,4> main() : SV_TARGET +{ + return vector<float,4>((float) 1, (float) 0, (float) 0, (float) 1); +} diff --git a/tools/slang-test/main.cpp b/tools/slang-test/main.cpp index 30fa709d7..9ce92f5bb 100644 --- a/tools/slang-test/main.cpp +++ b/tools/slang-test/main.cpp @@ -1,4 +1,4 @@ -// main.cpp +// main.cpp #include "../../source/core/slang-io.h" #include "../../source/core/token-reader.h" @@ -900,6 +900,25 @@ TestResult runEvalTest(TestContext* context, TestInput& input) return result; } +static SlangCompileTarget _getCompileTarget(const UnownedStringSlice& name) +{ +#define CASE(NAME, TARGET) if(name == NAME) return SLANG_##TARGET; + + CASE("hlsl", HLSL) + CASE("glsl", GLSL) + CASE("dxbc", DXBC) + CASE("dxbc-assembly", DXBC_ASM) + CASE("dxbc-asm", DXBC_ASM) + CASE("spirv", SPIRV) + CASE("spirv-assembly", SPIRV_ASM) + CASE("spirv-asm", SPIRV_ASM) + CASE("dxil", DXIL) + CASE("dxil-assembly", DXIL_ASM) + CASE("dxil-asm", DXIL_ASM) +#undef CASE + + return SLANG_TARGET_UNKNOWN; +} TestResult runCrossCompilerTest(TestContext* context, TestInput& input) { @@ -916,10 +935,39 @@ TestResult runCrossCompilerTest(TestContext* context, TestInput& input) expectedSpawner.pushExecutablePath(String(g_options.binDir) + "slangc" + osGetExecutableSuffix()); actualSpawner.pushArgument(filePath); - expectedSpawner.pushArgument(filePath + ".glsl"); - expectedSpawner.pushArgument("-pass-through"); - expectedSpawner.pushArgument("glslang"); + const auto& args = input.testOptions->args; + + const UInt targetIndex = args.IndexOf("-target"); + if (targetIndex != UInt(-1) && targetIndex + 1 < args.Count()) + { + SlangCompileTarget target = _getCompileTarget(args[targetIndex + 1].getUnownedSlice()); + + // Check the session supports it. If not we ignore it + if (SLANG_FAILED(spSessionHasCompileTargetSupport(context->getSession(), target))) + { + return TestResult::Ignored; + } + + switch (target) + { + case SLANG_DXIL_ASM: + { + expectedSpawner.pushArgument(filePath + ".hlsl"); + expectedSpawner.pushArgument("-pass-through"); + expectedSpawner.pushArgument("dxc"); + break; + } + default: + { + expectedSpawner.pushArgument(filePath + ".glsl"); + expectedSpawner.pushArgument("-pass-through"); + expectedSpawner.pushArgument("glslang"); + break; + } + } + } + for( auto arg : input.testOptions->args ) { actualSpawner.pushArgument(arg); @@ -1960,7 +2008,13 @@ int main( } // Setup the context - TestContext context(g_options.outputMode); + TestContext context; + if (SLANG_FAILED(context.init(g_options.outputMode))) + { + // Unable to initialize context + return 1; + } + context.m_dumpOutputOnFailure = g_options.dumpOutputOnFailure; context.m_isVerbose = g_options.shouldBeVerbose; diff --git a/tools/slang-test/slang-test.vcxproj b/tools/slang-test/slang-test.vcxproj index acaa07d3e..13bf42141 100644 --- a/tools/slang-test/slang-test.vcxproj +++ b/tools/slang-test/slang-test.vcxproj @@ -180,6 +180,9 @@ <ProjectReference Include="..\..\source\core\core.vcxproj"> <Project>{F9BE7957-8399-899E-0C49-E714FDDD4B65}</Project> </ProjectReference> + <ProjectReference Include="..\..\source\slang\slang.vcxproj"> + <Project>{DB00DA62-0533-4AFD-B59F-A67D5B3A0808}</Project> + </ProjectReference> </ItemGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> diff --git a/tools/slang-test/test-context.cpp b/tools/slang-test/test-context.cpp index 158258873..b94435a8e 100644 --- a/tools/slang-test/test-context.cpp +++ b/tools/slang-test/test-context.cpp @@ -69,8 +69,8 @@ static void appendXmlEncode(const String& in, StringBuilder& out) } } -TestContext::TestContext(TestOutputMode outputMode) : - m_outputMode(outputMode) +TestContext::TestContext() : + m_outputMode(TestOutputMode::Default) { m_totalTestCount = 0; m_passedTestCount = 0; @@ -82,6 +82,29 @@ TestContext::TestContext(TestOutputMode outputMode) : m_inTest = false; m_dumpOutputOnFailure = false; m_isVerbose = false; + + m_session = nullptr; +} + +Result TestContext::init(TestOutputMode outputMode) +{ + m_outputMode = outputMode; + + m_session = spCreateSession(nullptr); + if (!m_session) + { + return SLANG_FAIL; + } + + return SLANG_OK; +} + +TestContext::~TestContext() +{ + if (m_session) + { + spDestroySession(m_session); + } } bool TestContext::canWriteStdError() const @@ -601,4 +624,4 @@ void TestContext::endSuite() } m_suiteStack.RemoveLast(); -}
\ No newline at end of file +} diff --git a/tools/slang-test/test-context.h b/tools/slang-test/test-context.h index 94f8c689f..a81473efa 100644 --- a/tools/slang-test/test-context.h +++ b/tools/slang-test/test-context.h @@ -124,8 +124,16 @@ class TestContext /// Returns true if all run tests succeeded bool didAllSucceed() const; + /// Get the slang session + SlangSession* getSession() const { return m_session; } + + SlangResult init(TestOutputMode outputMode); + /// Ctor - TestContext(TestOutputMode outputMode); + TestContext(); + /// Dtor + ~TestContext(); + static TestResult combine(TestResult a, TestResult b) { return (a > b) ? a : b; } @@ -158,6 +166,8 @@ protected: int m_numFailResults; bool m_inTest; + + SlangSession* m_session; static TestContext* s_context; }; |
