summaryrefslogtreecommitdiffstats
path: root/Graphics
diff options
context:
space:
mode:
authorassiduous <assiduous@diligentgraphics.com>2020-09-10 20:57:41 +0000
committerassiduous <assiduous@diligentgraphics.com>2020-09-10 20:57:41 +0000
commit69c3d59c355ad52c350cf9792fe4d2aa06fdc849 (patch)
tree740c574a0253f3c083cbebcca72fc861ea3552b6 /Graphics
parentFew updates to ShaderD3DBase (diff)
downloadDiligentCore-69c3d59c355ad52c350cf9792fe4d2aa06fdc849.tar.gz
DiligentCore-69c3d59c355ad52c350cf9792fe4d2aa06fdc849.zip
D3D12 backend: few updates to mesh shader implementation
Diffstat (limited to 'Graphics')
-rw-r--r--Graphics/GraphicsEngineD3D12/CMakeLists.txt4
-rw-r--r--Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.hpp2
-rw-r--r--Graphics/GraphicsEngineD3D12/include/ShaderResourcesD3D12.hpp8
-rw-r--r--Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp2
-rw-r--r--Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp35
-rw-r--r--Graphics/GraphicsEngineD3D12/src/RootSignature.cpp2
-rw-r--r--Graphics/GraphicsEngineD3D12/src/ShaderD3D12Impl.cpp61
-rw-r--r--Graphics/GraphicsEngineD3D12/src/ShaderResourcesD3D12.cpp22
-rw-r--r--Graphics/HLSLTools/include/DXILUtils.hpp4
-rw-r--r--Graphics/HLSLTools/src/DXILUtils.cpp94
10 files changed, 143 insertions, 91 deletions
diff --git a/Graphics/GraphicsEngineD3D12/CMakeLists.txt b/Graphics/GraphicsEngineD3D12/CMakeLists.txt
index e8a48236..28e7abad 100644
--- a/Graphics/GraphicsEngineD3D12/CMakeLists.txt
+++ b/Graphics/GraphicsEngineD3D12/CMakeLists.txt
@@ -181,10 +181,10 @@ target_compile_definitions(Diligent-GraphicsEngineD3D12-shared PUBLIC ENGINE_DLL
if(${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION} STRGREATER_EQUAL "10.0.19041.0")
set(D3D12_H_HAS_MESH_SHADER ON CACHE INTERNAL "" FORCE)
- target_compile_definitions(Diligent-GraphicsEngineD3D12-static PRIVATE D3D12_H_HAS_MESH_SHADER)
+ target_compile_definitions(Diligent-GraphicsEngineD3D12-static PRIVATE D3D12_H_HAS_MESH_SHADER=1)
endif()
if(${DILIGENT_HAS_D3D12_DXIL_COMPILER})
- target_compile_definitions(Diligent-GraphicsEngineD3D12-static PRIVATE DILIGENT_HAS_D3D12_DXIL_COMPILER)
+ target_compile_definitions(Diligent-GraphicsEngineD3D12-static PRIVATE DILIGENT_HAS_D3D12_DXIL_COMPILE=1)
endif()
# Set output name to GraphicsEngineD3D12_{32|64}{r|d}
diff --git a/Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.hpp b/Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.hpp
index bac52b9e..710db2ef 100644
--- a/Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.hpp
+++ b/Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.hpp
@@ -192,7 +192,7 @@ private:
QueryManagerD3D12 m_QueryMgr;
- D3D_SHADER_MODEL m_ShaderModel = D3D_SHADER_MODEL_5_1;
+ D3D_SHADER_MODEL m_MaxShaderModel = D3D_SHADER_MODEL_5_1;
std::unique_ptr<IDxCompilerLibrary> m_pDxCompiler;
};
diff --git a/Graphics/GraphicsEngineD3D12/include/ShaderResourcesD3D12.hpp b/Graphics/GraphicsEngineD3D12/include/ShaderResourcesD3D12.hpp
index b1c12f90..228db950 100644
--- a/Graphics/GraphicsEngineD3D12/include/ShaderResourcesD3D12.hpp
+++ b/Graphics/GraphicsEngineD3D12/include/ShaderResourcesD3D12.hpp
@@ -92,10 +92,10 @@ class ShaderResourcesD3D12 final : public ShaderResources
{
public:
// Loads shader resources from the compiled shader bytecode
- ShaderResourcesD3D12(ID3DBlob* pShaderBytecode,
- const ShaderDesc& ShdrDesc,
- const char* CombinedSamplerSuffix,
- class RenderDeviceD3D12Impl* pRenderDeviceD3D12);
+ ShaderResourcesD3D12(ID3DBlob* pShaderBytecode,
+ const ShaderDesc& ShdrDesc,
+ const char* CombinedSamplerSuffix,
+ class IDxCompilerLibrary* pCompilerLibrary);
// clang-format off
ShaderResourcesD3D12 (const ShaderResourcesD3D12&) = delete;
diff --git a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp
index 70289385..546c9de8 100644
--- a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp
@@ -227,6 +227,8 @@ void DeviceContextD3D12Impl::SetPipelineState(IPipelineState* pPipelineState)
}
else
{
+ VERIFY_EXPR(PSODesc.IsAnyGraphicsPipeline());
+
auto& GraphicsCtx = CmdCtx.AsGraphicsContext();
GraphicsCtx.SetPipelineState(pd3d12PSO);
diff --git a/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp
index bdf596a4..76e8aa07 100644
--- a/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp
@@ -67,7 +67,7 @@ static CComPtr<IDXGIAdapter1> DXGIAdapterFromD3D12Device(ID3D12Device* pd3d12Dev
ShaderVersion RenderDeviceD3D12Impl::GetMaxShaderModel() const
{
- return ShaderVersion{Uint8((m_ShaderModel >> 4) & 0xF), Uint8(m_ShaderModel & 0xF)};
+ return ShaderVersion{static_cast<Uint8>((m_MaxShaderModel >> 4) & 0xF), static_cast<Uint8>(m_MaxShaderModel & 0xF)};
}
D3D_FEATURE_LEVEL RenderDeviceD3D12Impl::GetD3DFeatureLevel() const
@@ -206,24 +206,25 @@ RenderDeviceD3D12Impl::RenderDeviceD3D12Impl(IReferenceCounters* pRefCo
{
// Direct3D12 supports shader model 5.1 on all feature levels.
// https://docs.microsoft.com/en-us/windows/win32/direct3d12/hardware-feature-levels#feature-level-support
- m_ShaderModel = D3D_SHADER_MODEL_5_1;
+ m_MaxShaderModel = D3D_SHADER_MODEL_5_1;
// Header may not have constants for D3D_SHADER_MODEL_6_1 and above.
- const D3D_SHADER_MODEL Models[] = {
- D3D_SHADER_MODEL(0x65), // for mesh shader
- D3D_SHADER_MODEL(0x64),
- D3D_SHADER_MODEL(0x63),
- D3D_SHADER_MODEL(0x62),
- D3D_SHADER_MODEL(0x61),
- D3D_SHADER_MODEL_6_0};
-
- D3D12_FEATURE_DATA_SHADER_MODEL ShaderModel = {};
+ const D3D_SHADER_MODEL Models[] = //
+ {
+ static_cast<D3D_SHADER_MODEL>(0x65), // minimum required for mesh shader
+ static_cast<D3D_SHADER_MODEL>(0x64),
+ static_cast<D3D_SHADER_MODEL>(0x63),
+ static_cast<D3D_SHADER_MODEL>(0x62),
+ static_cast<D3D_SHADER_MODEL>(0x61),
+ D3D_SHADER_MODEL_6_0 //
+ };
+
for (auto Model : Models)
{
- ShaderModel.HighestShaderModel = Model;
+ D3D12_FEATURE_DATA_SHADER_MODEL ShaderModel = {Model};
if (SUCCEEDED(m_pd3d12Device->CheckFeatureSupport(D3D12_FEATURE_SHADER_MODEL, &ShaderModel, sizeof(ShaderModel))))
{
- m_ShaderModel = ShaderModel.HighestShaderModel;
+ m_MaxShaderModel = ShaderModel.HighestShaderModel;
break;
}
}
@@ -232,11 +233,13 @@ RenderDeviceD3D12Impl::RenderDeviceD3D12Impl(IReferenceCounters* pRefCo
// Check if mesh shader is supported.
#ifdef D3D12_H_HAS_MESH_SHADER
{
- D3D12_FEATURE_DATA_D3D12_OPTIONS7 FeatureData = {};
- bool SupportsMeshShader = SUCCEEDED(m_pd3d12Device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS7, &FeatureData, sizeof(FeatureData))) &&
+ D3D12_FEATURE_DATA_D3D12_OPTIONS7 FeatureData = {};
+
+ bool SupportsMeshShader =
+ SUCCEEDED(m_pd3d12Device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS7, &FeatureData, sizeof(FeatureData))) &&
FeatureData.MeshShaderTier != D3D12_MESH_SHADER_TIER_NOT_SUPPORTED;
- m_DeviceCaps.Features.MeshShaders = (m_ShaderModel >= D3D_SHADER_MODEL_6_5 && SupportsMeshShader);
+ m_DeviceCaps.Features.MeshShaders = (m_MaxShaderModel >= D3D_SHADER_MODEL_6_5 && SupportsMeshShader);
}
#endif
diff --git a/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp b/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp
index 0acaa810..6ec0497f 100644
--- a/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp
@@ -175,7 +175,7 @@ RootSignature::RootSignature() :
}
// clang-format off
-static D3D12_SHADER_VISIBILITY ShaderTypeInd2ShaderVisibilityMap[]
+static constexpr D3D12_SHADER_VISIBILITY ShaderTypeInd2ShaderVisibilityMap[]
{
D3D12_SHADER_VISIBILITY_VERTEX, // 0
D3D12_SHADER_VISIBILITY_PIXEL, // 1
diff --git a/Graphics/GraphicsEngineD3D12/src/ShaderD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/ShaderD3D12Impl.cpp
index 80025b36..36a14167 100644
--- a/Graphics/GraphicsEngineD3D12/src/ShaderD3D12Impl.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/ShaderD3D12Impl.cpp
@@ -38,23 +38,50 @@ namespace Diligent
static ShaderVersion GetD3D12ShaderModel(RenderDeviceD3D12Impl* pDevice, const ShaderVersion& HLSLVersion, SHADER_COMPILER ShaderCompiler)
{
- if (ShaderCompiler != SHADER_COMPILER_DXC)
- return HLSLVersion.Major == 0 ? ShaderVersion{5, 1} : HLSLVersion;
+ ShaderVersion CompilerSM;
+ if (ShaderCompiler == SHADER_COMPILER_DXC)
+ {
+ if (pDevice->GetDxCompiler() && pDevice->GetDxCompiler()->IsLoaded())
+ {
+ CompilerSM = pDevice->GetDxCompiler()->GetMaxShaderModel();
+ }
+ else
+ {
+ LOG_ERROR_MESSAGE("DXC compiler is not loaded");
+ CompilerSM = ShaderVersion{5, 1};
+ }
+ }
+ else
+ {
+ VERIFY(ShaderCompiler == SHADER_COMPILER_FXC || ShaderCompiler == SHADER_COMPILER_DEFAULT, "Unexpected compiler");
+ // Direct3D12 supports shader model 5.1 on all feature levels.
+ // https://docs.microsoft.com/en-us/windows/win32/direct3d12/hardware-feature-levels#feature-level-support
+ CompilerSM = ShaderVersion{5, 1};
+ }
- ShaderVersion DeviceSM = pDevice->GetMaxShaderModel();
- ShaderVersion CompilerSM = pDevice->GetDxCompiler() && pDevice->GetDxCompiler()->IsLoaded() ? pDevice->GetDxCompiler()->GetMaxShaderModel() : ShaderVersion{5, 1};
- ShaderVersion MaxSM;
+ ShaderVersion DeviceSM = pDevice->GetMaxShaderModel();
- MaxSM = DeviceSM.Major == CompilerSM.Major ?
- (DeviceSM.Minor > CompilerSM.Minor ? CompilerSM : DeviceSM) :
- (DeviceSM.Major > CompilerSM.Major ? CompilerSM : DeviceSM);
+ ShaderVersion MaxSupportedSM = DeviceSM.Major == CompilerSM.Major ?
+ (DeviceSM.Minor < CompilerSM.Minor ? DeviceSM : CompilerSM) :
+ (DeviceSM.Major < CompilerSM.Major ? DeviceSM : CompilerSM);
if (HLSLVersion.Major == 0 && HLSLVersion.Minor == 0)
- return MaxSM;
-
- return HLSLVersion.Major == MaxSM.Major ?
- (HLSLVersion.Minor > MaxSM.Minor ? MaxSM : HLSLVersion) :
- (HLSLVersion.Major > MaxSM.Major ? MaxSM : HLSLVersion);
+ {
+ return MaxSupportedSM;
+ }
+ else
+ {
+ if (HLSLVersion.Major > MaxSupportedSM.Major ||
+ HLSLVersion.Major == MaxSupportedSM.Major && HLSLVersion.Minor > MaxSupportedSM.Minor)
+ {
+ LOG_WARNING_MESSAGE("Requested shader model ", Uint32{HLSLVersion.Major}, '_', Uint32{HLSLVersion.Minor},
+ " is not supported by the device/compiler. Downgrading to maximum supported version ",
+ Uint32{MaxSupportedSM.Major}, '_', Uint32{MaxSupportedSM.Minor});
+ return MaxSupportedSM;
+ }
+ else
+ return HLSLVersion;
+ }
}
ShaderD3D12Impl::ShaderD3D12Impl(IReferenceCounters* pRefCounters,
@@ -73,7 +100,13 @@ ShaderD3D12Impl::ShaderD3D12Impl(IReferenceCounters* pRefCounters,
// Load shader resources
auto& Allocator = GetRawAllocator();
auto* pRawMem = ALLOCATE(Allocator, "Allocator for ShaderResources", ShaderResourcesD3D12, 1);
- auto* pResources = new (pRawMem) ShaderResourcesD3D12(m_pShaderByteCode, m_Desc, ShaderCI.UseCombinedTextureSamplers ? ShaderCI.CombinedSamplerSuffix : nullptr, pRenderDeviceD3D12);
+ auto* pResources = new (pRawMem) ShaderResourcesD3D12 //
+ {
+ m_pShaderByteCode,
+ m_Desc,
+ ShaderCI.UseCombinedTextureSamplers ? ShaderCI.CombinedSamplerSuffix : nullptr,
+ pRenderDeviceD3D12->GetDxCompiler() //
+ };
m_pShaderResources.reset(pResources, STDDeleterRawMem<ShaderResourcesD3D12>(Allocator));
}
diff --git a/Graphics/GraphicsEngineD3D12/src/ShaderResourcesD3D12.cpp b/Graphics/GraphicsEngineD3D12/src/ShaderResourcesD3D12.cpp
index 01726d00..6cd31660 100644
--- a/Graphics/GraphicsEngineD3D12/src/ShaderResourcesD3D12.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/ShaderResourcesD3D12.cpp
@@ -32,16 +32,15 @@
#include "ShaderD3DBase.hpp"
#include "ShaderBase.hpp"
#include "DXILUtils.hpp"
-#include "RenderDeviceD3D12Impl.hpp"
namespace Diligent
{
-ShaderResourcesD3D12::ShaderResourcesD3D12(ID3DBlob* pShaderBytecode,
- const ShaderDesc& ShdrDesc,
- const char* CombinedSamplerSuffix,
- RenderDeviceD3D12Impl* pRenderDeviceD3D12) :
+ShaderResourcesD3D12::ShaderResourcesD3D12(ID3DBlob* pShaderBytecode,
+ const ShaderDesc& ShdrDesc,
+ const char* CombinedSamplerSuffix,
+ class IDxCompilerLibrary* pCompilerLibrary) :
ShaderResources{ShdrDesc.ShaderType}
{
class NewResourceHandler
@@ -58,18 +57,21 @@ ShaderResourcesD3D12::ShaderResourcesD3D12(ID3DBlob* pShaderBytecod
};
CComPtr<ID3D12ShaderReflection> pShaderReflection;
- auto* DxCompiler = pRenderDeviceD3D12->GetDxCompiler();
+ if (pCompilerLibrary != nullptr)
+ {
+ // Try to get shader reflection with DXC.
+ DxcGetShaderReflection(pCompilerLibrary, reinterpret_cast<IDxcBlob*>(pShaderBytecode), &pShaderReflection);
+ }
- // At first try to get shader reflection with a DXC.
- if (!DxcGetShaderReflection(DxCompiler, reinterpret_cast<IDxcBlob*>(pShaderBytecode), &pShaderReflection))
+ if (!pShaderReflection)
{
// Use FXC to get reflection.
- HRESULT hr = D3DReflect(pShaderBytecode->GetBufferPointer(), pShaderBytecode->GetBufferSize(), __uuidof(pShaderReflection), reinterpret_cast<void**>(&pShaderReflection));
+ auto hr = D3DReflect(pShaderBytecode->GetBufferPointer(), pShaderBytecode->GetBufferSize(), __uuidof(pShaderReflection), reinterpret_cast<void**>(&pShaderReflection));
CHECK_D3D_RESULT_THROW(hr, "Failed to get the shader reflection");
}
Initialize<D3D12_SHADER_DESC, D3D12_SHADER_INPUT_BIND_DESC, ID3D12ShaderReflection>(
- static_cast<ID3D12ShaderReflection*>(pShaderReflection),
+ pShaderReflection,
NewResourceHandler{},
ShdrDesc.Name,
CombinedSamplerSuffix);
diff --git a/Graphics/HLSLTools/include/DXILUtils.hpp b/Graphics/HLSLTools/include/DXILUtils.hpp
index 32e53b43..7af71a19 100644
--- a/Graphics/HLSLTools/include/DXILUtils.hpp
+++ b/Graphics/HLSLTools/include/DXILUtils.hpp
@@ -83,9 +83,9 @@ std::vector<uint32_t> DXILtoSPIRV(IDxCompilerLibrary* pLibrary,
#endif
#if D3D12_SUPPORTED
-// Returns false if pShaderBytecode hasn't DXIL bytecode.
+// Attempts to extract shader reflection from the bytecode using DXC.
// Throws exception on error.
-bool DxcGetShaderReflection(IDxCompilerLibrary* pLibrary,
+void DxcGetShaderReflection(IDxCompilerLibrary* pLibrary,
IDxcBlob* pShaderBytecode,
ID3D12ShaderReflection** ppShaderReflection) noexcept(false);
#endif
diff --git a/Graphics/HLSLTools/src/DXILUtils.cpp b/Graphics/HLSLTools/src/DXILUtils.cpp
index b183a65c..bfd417e5 100644
--- a/Graphics/HLSLTools/src/DXILUtils.cpp
+++ b/Graphics/HLSLTools/src/DXILUtils.cpp
@@ -25,8 +25,6 @@
* of the possibility of such damages.
*/
-#include <unordered_set>
-#include <unordered_map>
#include <memory>
#include <array>
#include <mutex>
@@ -56,7 +54,7 @@ class DXCompilerImpl final : public DXCompilerBase
public:
DXCompilerImpl(DXCompilerTarget Target, const char* pLibName) :
m_Target{Target},
- m_LibName{pLibName ? pLibName : "dxcompiler.dll"}
+ m_LibName{pLibName ? pLibName : "dxcompiler"}
{}
ShaderVersion GetMaxShaderModel() override
@@ -73,9 +71,7 @@ public:
DxcCreateInstanceProc GetCreateInstaceProc()
{
- Load();
- // mutex is not needed here
- return m_pCreateInstance;
+ return Load();
}
bool Compile(const char* Source,
@@ -91,12 +87,12 @@ public:
IDxcBlob** ppCompilerOutput) override;
private:
- void Load()
+ DxcCreateInstanceProc Load()
{
std::unique_lock<std::mutex> lock{m_Guard};
if (m_IsInitialized)
- return;
+ return m_pCreateInstance;
m_IsInitialized = true;
m_pCreateInstance = DXCompilerBase::Load(m_Target, m_LibName);
@@ -106,8 +102,7 @@ private:
CComPtr<IDxcValidator> validator;
if (SUCCEEDED(m_pCreateInstance(CLSID_DxcValidator, IID_PPV_ARGS(&validator))))
{
- CComPtr<IDxcVersionInfo> info;
- if (SUCCEEDED(validator->QueryInterface(IID_PPV_ARGS(&info))))
+ if (CComQIPtr<IDxcVersionInfo> info{validator})
{
UINT32 ver = 0, minor = 0;
info->GetVersion(&ver, &minor);
@@ -128,6 +123,8 @@ private:
}
}
}
+
+ return m_pCreateInstance;
}
private:
@@ -262,17 +259,26 @@ bool DXCompilerImpl::Compile(const char* Source,
CComPtr<IDxcLibrary> library;
hr = CreateInstance(CLSID_DxcLibrary, IID_PPV_ARGS(&library));
if (FAILED(hr))
+ {
+ LOG_ERROR("Failed to create DXC Library");
return false;
+ }
CComPtr<IDxcCompiler> compiler;
hr = CreateInstance(CLSID_DxcCompiler, IID_PPV_ARGS(&compiler));
if (FAILED(hr))
+ {
+ LOG_ERROR("Failed to create DXC Compiler");
return false;
+ }
CComPtr<IDxcBlobEncoding> sourceBlob;
hr = library->CreateBlobWithEncodingFromPinned(Source, UINT32(SourceLength), CP_UTF8, &sourceBlob);
if (FAILED(hr))
+ {
+ LOG_ERROR("Failed to create DXC Blob encoding");
return false;
+ }
DxcIncludeHandlerImpl IncludeHandler{pShaderSourceStreamFactory, library};
@@ -305,26 +311,35 @@ bool DXCompilerImpl::Compile(const char* Source,
}
if (FAILED(hr))
- return false; // compilation failed
+ {
+ LOG_ERROR("Failed to compile shader");
+ return false;
+ }
CComPtr<IDxcBlob> compiled;
hr = result->GetResult(&compiled);
if (FAILED(hr))
return false;
- // validate and sign in
+ // validate and sign
if (m_Target == DXCompilerTarget::Direct3D12)
{
CComPtr<IDxcValidator> validator;
hr = CreateInstance(CLSID_DxcValidator, IID_PPV_ARGS(&validator));
if (FAILED(hr))
+ {
+ LOG_ERROR("Failed to create DXC Validator");
return false;
+ }
CComPtr<IDxcOperationResult> validationResult;
hr = validator->Validate(compiled, DxcValidatorFlags_InPlaceEdit, &validationResult);
if (validationResult == nullptr || FAILED(hr))
- return false; // validation failed
+ {
+ LOG_ERROR("Failed to validate shader bytecode");
+ return false;
+ }
HRESULT status = E_FAIL;
validationResult->GetStatus(&status);
@@ -361,38 +376,36 @@ bool DXCompilerImpl::Compile(const char* Source,
#if D3D12_SUPPORTED
# define FOURCC(a, b, c, d) (uint32_t{((d) << 24) | ((c) << 16) | ((b) << 8) | (a)})
-bool DxcGetShaderReflection(IDxCompilerLibrary* pLibrary,
+void DxcGetShaderReflection(IDxCompilerLibrary* pLibrary,
IDxcBlob* pShaderBytecode,
ID3D12ShaderReflection** ppShaderReflection) noexcept(false)
{
- HRESULT hr;
- bool IsDXIL = false;
- auto CreateInstance = pLibrary ? static_cast<DXCompilerImpl*>(pLibrary)->GetCreateInstaceProc() : nullptr;
+ VERIFY_EXPR(pLibrary != nullptr);
- if (CreateInstance != nullptr)
- {
- const uint32_t DFCC_DXIL = FOURCC('D', 'X', 'I', 'L');
- CComPtr<IDxcContainerReflection> pReflection;
- UINT32 shaderIdx;
+ auto CreateInstance = static_cast<DXCompilerImpl*>(pLibrary)->GetCreateInstaceProc();
+ if (CreateInstance == nullptr)
+ return;
- hr = CreateInstance(CLSID_DxcContainerReflection, IID_PPV_ARGS(&pReflection));
- if (FAILED(hr))
- LOG_ERROR_AND_THROW("Failed to create shader reflection instance");
+ const uint32_t DFCC_DXIL = FOURCC('D', 'X', 'I', 'L');
- hr = pReflection->Load(pShaderBytecode);
- if (FAILED(hr))
- LOG_ERROR_AND_THROW("Failed to load shader reflection from bytecode");
+ CComPtr<IDxcContainerReflection> pReflection;
+ UINT32 shaderIdx;
- hr = pReflection->FindFirstPartKind(DFCC_DXIL, &shaderIdx);
- IsDXIL = SUCCEEDED(hr);
- if (IsDXIL)
- {
- hr = pReflection->GetPartReflection(shaderIdx, __uuidof(*ppShaderReflection), reinterpret_cast<void**>(ppShaderReflection));
- if (FAILED(hr))
- LOG_ERROR_AND_THROW("Failed to get the shader reflection");
- }
+ auto hr = CreateInstance(CLSID_DxcContainerReflection, IID_PPV_ARGS(&pReflection));
+ if (FAILED(hr))
+ LOG_ERROR_AND_THROW("Failed to create shader reflection instance");
+
+ hr = pReflection->Load(pShaderBytecode);
+ if (FAILED(hr))
+ LOG_ERROR_AND_THROW("Failed to load shader reflection from bytecode");
+
+ hr = pReflection->FindFirstPartKind(DFCC_DXIL, &shaderIdx);
+ if (SUCCEEDED(hr))
+ {
+ hr = pReflection->GetPartReflection(shaderIdx, __uuidof(*ppShaderReflection), reinterpret_cast<void**>(ppShaderReflection));
+ if (FAILED(hr))
+ LOG_ERROR_AND_THROW("Failed to get the shader reflection");
}
- return IsDXIL;
}
#endif
@@ -418,7 +431,7 @@ std::vector<uint32_t> DXILtoSPIRV(IDxCompilerLibrary* pLibrary,
const char* ExtraDefinitions,
IDataBlob** ppCompilerOutput) noexcept(false)
{
- RefCntAutoPtr<IDataBlob> pFileData(MakeNewRCObj<DataBlobImpl>()(0));
+ RefCntAutoPtr<IDataBlob> pFileData{MakeNewRCObj<DataBlobImpl>()(0)};
const char* SourceCode = 0;
int SourceCodeLen = 0;
@@ -530,8 +543,6 @@ std::vector<uint32_t> DXILtoSPIRV(IDxCompilerLibrary* pLibrary,
pOutputDataBlob->QueryInterface(IID_DataBlob, reinterpret_cast<IObject**>(ppCompilerOutput));
}
- std::vector<uint32_t> SPIRV;
-
if (!result)
{
if (ppCompilerOutput != nullptr)
@@ -540,10 +551,11 @@ std::vector<uint32_t> DXILtoSPIRV(IDxCompilerLibrary* pLibrary,
}
else
{
- LOG_ERROR_AND_THROW("Failed to compile Vukan shader \"", (Attribs.Desc.Name != nullptr ? Attribs.Desc.Name : ""), "\":\n", (CompilerMsg != nullptr ? CompilerMsg : "<no compiler log available>"));
+ LOG_ERROR_AND_THROW("Failed to compile Vukan shader \"", (Attribs.Desc.Name != nullptr ? Attribs.Desc.Name : ""), "\":\n", (CompilerMsg != nullptr ? std::string(CompilerMsg, CompilerMsgLen) : "<no compiler log available>"));
}
}
+ std::vector<uint32_t> SPIRV;
if (result && compiled && compiled->GetBufferSize() > 0)
{
SPIRV.assign(static_cast<uint32_t*>(compiled->GetBufferPointer()),