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 /source | |
| 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
Diffstat (limited to 'source')
| -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 |
14 files changed, 141 insertions, 7 deletions
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) { |
