summaryrefslogtreecommitdiffstats
path: root/Graphics/ShaderTools
diff options
context:
space:
mode:
authorazhirnov <zh1dron@gmail.com>2020-11-16 17:30:23 +0000
committerazhirnov <zh1dron@gmail.com>2020-11-16 17:53:02 +0000
commit43c3821993cb3d6ec3025fa7156da8544d2a1dac (patch)
treefa5b7cc5774c7f72a307f2b0cd250e64a7abecf0 /Graphics/ShaderTools
parentbug fix for ray tracing, fixed KHR via NV emulation. (diff)
downloadDiligentCore-43c3821993cb3d6ec3025fa7156da8544d2a1dac.tar.gz
DiligentCore-43c3821993cb3d6ec3025fa7156da8544d2a1dac.zip
D3D12 resource binding refactoring, rename LinearAllocator to FixedLinearAllocator.
Diffstat (limited to 'Graphics/ShaderTools')
-rw-r--r--Graphics/ShaderTools/include/DXCompiler.hpp9
-rw-r--r--Graphics/ShaderTools/src/DXCompiler.cpp82
2 files changed, 13 insertions, 78 deletions
diff --git a/Graphics/ShaderTools/include/DXCompiler.hpp b/Graphics/ShaderTools/include/DXCompiler.hpp
index b996bdff..b80dc636 100644
--- a/Graphics/ShaderTools/include/DXCompiler.hpp
+++ b/Graphics/ShaderTools/include/DXCompiler.hpp
@@ -85,13 +85,10 @@ public:
IDataBlob** ppCompilerOutput) noexcept(false) = 0;
using TResourceBindingMap = std::unordered_map<HashMapStringKey, Uint32, HashMapStringKey::Hasher>;
- using TBindingMapPerStage = std::array<TResourceBindingMap, MAX_SHADERS_IN_PIPELINE>;
- virtual bool RemapResourceBinding(const TBindingMapPerStage& BindingMapPerStage,
- const char* EntryPoint,
- const void* pBytecode,
- size_t BytecodeSize,
- IDxcBlob** ppByteCodeBlob) = 0;
+ virtual bool RemapResourceBinding(const TResourceBindingMap& ResourceMap,
+ IDxcBlob* pSrcBytecode,
+ IDxcBlob** ppDstByteCode) = 0;
// Attempts to extract shader reflection from the bytecode using DXC.
virtual void GetD3D12ShaderReflection(IDxcBlob* pShaderBytecode,
diff --git a/Graphics/ShaderTools/src/DXCompiler.cpp b/Graphics/ShaderTools/src/DXCompiler.cpp
index cdad9b55..8388ba89 100644
--- a/Graphics/ShaderTools/src/DXCompiler.cpp
+++ b/Graphics/ShaderTools/src/DXCompiler.cpp
@@ -42,8 +42,6 @@
#include "DataBlobImpl.hpp"
#include "RefCntAutoPtr.hpp"
#include "ShaderToolsCommon.hpp"
-#include "PlatformMisc.hpp"
-#include "GraphicsAccessories.hpp"
#if D3D12_SUPPORTED
# include <d3d12shader.h>
@@ -94,11 +92,9 @@ public:
virtual void GetD3D12ShaderReflection(IDxcBlob* pShaderBytecode,
ID3D12ShaderReflection** ppShaderReflection) override final;
- virtual bool RemapResourceBinding(const TBindingMapPerStage& BindingMapPerStage,
- const char* EntryPoint,
- const void* pBytecode,
- size_t BytecodeSize,
- IDxcBlob** ppByteCodeBlob) override final;
+ virtual bool RemapResourceBinding(const TResourceBindingMap& ResourceMap,
+ IDxcBlob* pSrcBytecode,
+ IDxcBlob** ppDstByteCode) override final;
private:
DxcCreateInstanceProc Load()
@@ -141,9 +137,8 @@ private:
return m_pCreateInstance;
}
- bool ValidateAndSign(DxcCreateInstanceProc CreateInstance, IDxcLibrary* library, CComPtr<IDxcBlob>& compiled, IDxcBlob** ppBlobOut) const;
- bool PatchDXIL(const TResourceBindingMap& ResourceMap, String& DXIL) const;
- SHADER_TYPE GetEntryShaderType(const String& EntryPoint, const String& DXIL) const;
+ bool ValidateAndSign(DxcCreateInstanceProc CreateInstance, IDxcLibrary* library, CComPtr<IDxcBlob>& compiled, IDxcBlob** ppBlobOut) const;
+ bool PatchDXIL(const TResourceBindingMap& ResourceMap, String& DXIL) const;
private:
DxcCreateInstanceProc m_pCreateInstance = nullptr;
@@ -765,11 +760,9 @@ void DXCompilerImpl::Compile(const ShaderCreateInfo& ShaderCI,
}
}
-bool DXCompilerImpl::RemapResourceBinding(const TBindingMapPerStage& BindingMapPerStage,
- const char* EntryPoint,
- const void* pBytecode,
- size_t BytecodeSize,
- IDxcBlob** ppByteCodeBlob)
+bool DXCompilerImpl::RemapResourceBinding(const TResourceBindingMap& ResourceMap,
+ IDxcBlob* pSrcBytecode,
+ IDxcBlob** ppDstByteCode)
{
#if D3D12_SUPPORTED
auto CreateInstance = GetCreateInstaceProc();
@@ -805,16 +798,8 @@ bool DXCompilerImpl::RemapResourceBinding(const TBindingMapPerStage& BindingMapP
return false;
}
- CComPtr<IDxcBlobEncoding> srcBytecode;
- hr = library->CreateBlobWithEncodingFromPinned(pBytecode, static_cast<Uint32>(BytecodeSize), 0, &srcBytecode);
- if (FAILED(hr))
- {
- LOG_ERROR("Failed to create bytecode blob");
- return false;
- }
-
CComPtr<IDxcBlobEncoding> disasm;
- hr = compiler->Disassemble(srcBytecode, &disasm);
+ hr = compiler->Disassemble(pSrcBytecode, &disasm);
if (FAILED(hr))
{
LOG_ERROR("Failed to disassemble bytecode");
@@ -824,10 +809,6 @@ bool DXCompilerImpl::RemapResourceBinding(const TBindingMapPerStage& BindingMapP
String dxilAsm;
dxilAsm.assign(static_cast<const char*>(disasm->GetBufferPointer()), disasm->GetBufferSize());
- SHADER_TYPE shaderType = GetEntryShaderType(EntryPoint, dxilAsm);
- const Uint32 shaderIndex = GetShaderTypePipelineIndex(shaderType, PIPELINE_TYPE_RAY_TRACING);
- const auto& ResourceMap = BindingMapPerStage[shaderIndex];
-
if (!PatchDXIL(ResourceMap, dxilAsm))
{
LOG_ERROR("Failed to patch resource bindings");
@@ -874,7 +855,7 @@ bool DXCompilerImpl::RemapResourceBinding(const TBindingMapPerStage& BindingMapP
if (FAILED(hr))
return false;
- return ValidateAndSign(CreateInstance, library, compiled, ppByteCodeBlob);
+ return ValidateAndSign(CreateInstance, library, compiled, ppDstByteCode);
#else
return false;
@@ -946,47 +927,4 @@ bool DXCompilerImpl::PatchDXIL(const TResourceBindingMap& ResourceMap, String& D
return true;
}
-namespace
-{
-template <Uint32 S>
-inline bool ReverseCmp(const char* lhsRev, const char (&rhs)[S])
-{
- const Uint32 count = S - 1;
- const char* lhs = lhsRev - count;
- return std::memcmp(lhs, rhs, count) == 0;
-}
-} // namespace
-
-SHADER_TYPE DXCompilerImpl::GetEntryShaderType(const String& EntryPoint, const String& DXIL) const
-{
- const String Pattern = "void " + EntryPoint + "(";
- const char ShaderTypeStart[] = "[shader(\\22";
- const char ShaderTypeEnd[] = "\\22)]";
- const char RayGenShader[] = "raygeneration";
- const char MissShader[] = "miss";
- const char AnyHitShader[] = "anyhit";
- const char ClosestHitShader[] = "closesthit";
- const char IntersectionShader[] = "intersection";
- const char CallableShader[] = "callable";
-
- size_t pos = DXIL.find(Pattern);
- if (pos == String::npos)
- return SHADER_TYPE_UNKNOWN;
-
- size_t endPos = DXIL.rfind(ShaderTypeEnd, pos);
- if (endPos == String::npos)
- return SHADER_TYPE_UNKNOWN;
-
- const char* str = &DXIL[endPos];
- // clang-format off
- if (ReverseCmp(str, RayGenShader )) return SHADER_TYPE_RAY_GEN;
- if (ReverseCmp(str, MissShader )) return SHADER_TYPE_RAY_MISS;
- if (ReverseCmp(str, AnyHitShader )) return SHADER_TYPE_RAY_ANY_HIT;
- if (ReverseCmp(str, ClosestHitShader )) return SHADER_TYPE_RAY_CLOSEST_HIT;
- if (ReverseCmp(str, IntersectionShader)) return SHADER_TYPE_RAY_INTERSECTION;
- if (ReverseCmp(str, CallableShader )) return SHADER_TYPE_CALLABLE;
- // clang-format on
- return SHADER_TYPE_UNKNOWN;
-}
-
} // namespace Diligent