diff options
| author | azhirnov <zh1dron@gmail.com> | 2020-08-11 19:48:23 +0000 |
|---|---|---|
| committer | azhirnov <zh1dron@gmail.com> | 2020-08-11 19:49:36 +0000 |
| commit | dc9a4e784c8bb97fbb16a01624c7b8f0544977a4 (patch) | |
| tree | b4a07f6e2029ca9d20999acfd940ea8e2556cb9d /Graphics/GraphicsEngineD3D11 | |
| parent | Bash function for format validation in submodules (#155) (diff) | |
| download | DiligentCore-dc9a4e784c8bb97fbb16a01624c7b8f0544977a4.tar.gz DiligentCore-dc9a4e784c8bb97fbb16a01624c7b8f0544977a4.zip | |
Added mesh shader
added mesh shader support to DX12 and Vulkan, added DXIL compiler for Shader Model 6.x
Diffstat (limited to 'Graphics/GraphicsEngineD3D11')
5 files changed, 475 insertions, 456 deletions
diff --git a/Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.hpp b/Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.hpp index f8db6f23..5230b833 100644 --- a/Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.hpp +++ b/Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.hpp @@ -130,6 +130,10 @@ public: virtual void DILIGENT_CALL_TYPE DrawIndirect(const DrawIndirectAttribs& Attribs, IBuffer* pAttribsBuffer) override final; /// Implementation of IDeviceContext::DrawIndexedIndirect() in Direct3D11 backend. virtual void DILIGENT_CALL_TYPE DrawIndexedIndirect(const DrawIndexedIndirectAttribs& Attribs, IBuffer* pAttribsBuffer) override final; + /// Implementation of IDeviceContext::DrawMesh() in Direct3D11 backend. + virtual void DILIGENT_CALL_TYPE DrawMesh(const DrawMeshAttribs& Attribs) override final; + /// Implementation of IDeviceContext::DrawMeshIndirect() in Direct3D11 backend. + virtual void DILIGENT_CALL_TYPE DrawMeshIndirect(const DrawMeshIndirectAttribs& Attribs, IBuffer* pAttribsBuffer) override final; /// Implementation of IDeviceContext::DispatchCompute() in Direct3D11 backend. virtual void DILIGENT_CALL_TYPE DispatchCompute(const DispatchComputeAttribs& Attribs) override final; diff --git a/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp index 0ff2227d..d936b247 100755 --- a/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp @@ -75,7 +75,7 @@ void DeviceContextD3D11Impl::SetPipelineState(IPipelineState* pPipelineState) TDeviceContextBase::SetPipelineState(pPipelineStateD3D11, 0 /*Dummy*/);
auto& Desc = pPipelineStateD3D11->GetDesc();
- if (Desc.IsComputePipeline)
+ if (Desc.IsComputePipeline()) {
auto* pd3d11CS = pPipelineStateD3D11->GetD3D11ComputeShader();
if (pd3d11CS == nullptr)
@@ -870,6 +870,16 @@ void DeviceContextD3D11Impl::DrawIndexedIndirect(const DrawIndexedIndirectAttrib m_pd3d11DeviceContext->DrawIndexedInstancedIndirect(pd3d11ArgsBuff, Attribs.IndirectDrawArgsOffset);
}
+void DeviceContextD3D11Impl::DrawMesh(const DrawMeshAttribs& Attribs) +{ + UNSUPPORTED("DrawMesh is not supported in DirectX 11"); +} + +void DeviceContextD3D11Impl::DrawMeshIndirect(const DrawMeshIndirectAttribs& Attribs, IBuffer* pAttribsBuffer) +{ + UNSUPPORTED("DrawMeshIndirect is not supported in DirectX 11"); +} + void DeviceContextD3D11Impl::DispatchCompute(const DispatchComputeAttribs& Attribs)
{
if (!DvpVerifyDispatchArguments(Attribs))
diff --git a/Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp index 3b787039..97d76fde 100644 --- a/Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp @@ -50,7 +50,7 @@ PipelineStateD3D11Impl::PipelineStateD3D11Impl(IReferenceCounters* pR m_StaticSamplers (STD_ALLOCATOR_RAW_MEM(StaticSamplerInfo, GetRawAllocator(), "Allocator for vector<StaticSamplerInfo>")) // clang-format on { - if (m_Desc.IsComputePipeline) + if (m_Desc.IsComputePipeline()) { auto* pCS = ValidatedCast<ShaderD3D11Impl>(m_Desc.ComputePipeline.pCS); m_pCS = pCS; diff --git a/Graphics/GraphicsEngineD3D11/src/ShaderD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/ShaderD3D11Impl.cpp index b5b0194f..8bf17567 100644 --- a/Graphics/GraphicsEngineD3D11/src/ShaderD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/ShaderD3D11Impl.cpp @@ -34,24 +34,24 @@ namespace Diligent { -static const std::string HLSLVersionToShaderModelString(const ShaderVersion& Version, Uint8 MaxMajorRevision, Uint8 MaxMinorRevision) +static const Uint8 HLSLVersionToShaderModelString(const ShaderVersion& Version, Uint8 MaxMajorRevision, Uint8 MaxMinorRevision) { - std::string ModelStr; + Uint8 ModelVer; if (Version.Major > MaxMajorRevision || Version.Major == MaxMajorRevision && Version.Minor > MaxMinorRevision) { - ModelStr = std::to_string(Uint32{MaxMajorRevision}) + '_' + std::to_string(Uint32{MaxMinorRevision}); + ModelVer = Uint8((MaxMajorRevision << 4) | MaxMinorRevision); LOG_ERROR_MESSAGE("Shader model ", Uint32{Version.Major}, "_", Uint32{Version.Minor}, " is not supported by this device. Maximum supported model: ", - ModelStr, ". Attempting to use ", ModelStr, '.'); + MaxMajorRevision, "_", MaxMinorRevision, ". Attempting to use ", MaxMajorRevision, "_", MaxMinorRevision, '.'); } else { - ModelStr = std::to_string(Uint32{Version.Major}) + '_' + std::to_string(Uint32{Version.Minor}); + ModelVer = Uint8((Version.Major << 4) | Version.Minor); } - return ModelStr; + return ModelVer; } -static const std::string GetD3D11ShaderModel(ID3D11Device* pd3d11Device, const ShaderVersion& HLSLVersion) +static const Uint8 GetD3D11ShaderModel(ID3D11Device* pd3d11Device, const ShaderVersion& HLSLVersion) { auto d3dDeviceFeatureLevel = pd3d11Device->GetFeatureLevel(); switch (d3dDeviceFeatureLevel) @@ -66,22 +66,22 @@ static const std::string GetD3D11ShaderModel(ID3D11Device* pd3d11Device, const S case D3D_FEATURE_LEVEL_11_1: case D3D_FEATURE_LEVEL_11_0: return (HLSLVersion.Major == 0 && HLSLVersion.Minor == 0) ? - std::string{"5_0"} : + Uint8(0x50) : HLSLVersionToShaderModelString(HLSLVersion, 5, 0); case D3D_FEATURE_LEVEL_10_1: return (HLSLVersion.Major == 0 && HLSLVersion.Minor == 0) ? - std::string{"4_1"} : + Uint8(0x41) : HLSLVersionToShaderModelString(HLSLVersion, 4, 1); case D3D_FEATURE_LEVEL_10_0: return (HLSLVersion.Major == 0 && HLSLVersion.Minor == 0) ? - std::string{"4_0"} : + Uint8(0x40) : HLSLVersionToShaderModelString(HLSLVersion, 4, 0); default: UNEXPECTED("Unexpected D3D feature level ", static_cast<Uint32>(d3dDeviceFeatureLevel)); - return "4_0"; + return Uint8(0x40); } } @@ -95,7 +95,7 @@ ShaderD3D11Impl::ShaderD3D11Impl(IReferenceCounters* pRefCounters, pRenderDeviceD3D11, ShaderCI.Desc }, - ShaderD3DBase{ShaderCI, GetD3D11ShaderModel(pRenderDeviceD3D11->GetD3D11Device(), ShaderCI.HLSLVersion).c_str()} + ShaderD3DBase{ShaderCI, GetD3D11ShaderModel(pRenderDeviceD3D11->GetD3D11Device(), ShaderCI.HLSLVersion)} // clang-format on { auto* pDeviceD3D11 = pRenderDeviceD3D11->GetD3D11Device(); diff --git a/Graphics/GraphicsEngineD3D11/src/ShaderResourcesD3D11.cpp b/Graphics/GraphicsEngineD3D11/src/ShaderResourcesD3D11.cpp index 769c91e2..779ce893 100755 --- a/Graphics/GraphicsEngineD3D11/src/ShaderResourcesD3D11.cpp +++ b/Graphics/GraphicsEngineD3D11/src/ShaderResourcesD3D11.cpp @@ -1,442 +1,447 @@ -/*
- * Copyright 2019-2020 Diligent Graphics LLC
- * Copyright 2015-2019 Egor Yusov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * In no event and under no legal theory, whether in tort (including negligence),
- * contract, or otherwise, unless required by applicable law (such as deliberate
- * and grossly negligent acts) or agreed to in writing, shall any Contributor be
- * liable for any damages, including any direct, indirect, special, incidental,
- * or consequential damages of any character arising as a result of this License or
- * out of the use or inability to use the software (including but not limited to damages
- * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
- * all other commercial damages or losses), even if such Contributor has been advised
- * of the possibility of such damages.
- */
-
-#include "pch.h"
-
-#include <d3dcompiler.h>
-#include "ShaderResourcesD3D11.hpp"
-#include "ShaderBase.hpp"
-#include "ShaderResourceCacheD3D11.hpp"
-#include "RenderDeviceD3D11Impl.hpp"
-
-namespace Diligent
-{
-
-
-ShaderResourcesD3D11::ShaderResourcesD3D11(RenderDeviceD3D11Impl* pDeviceD3D11Impl,
- ID3DBlob* pShaderBytecode,
- const ShaderDesc& ShdrDesc,
- const char* CombinedSamplerSuffix) :
- ShaderResources{ShdrDesc.ShaderType}
-{
- class NewResourceHandler
- {
- public:
- NewResourceHandler(RenderDeviceD3D11Impl* const _pDeviceD3D11Impl,
- const ShaderDesc& _ShdrDesc,
- const char* _CombinedSamplerSuffix,
- ShaderResourcesD3D11& _Resources) :
- // clang-format off
- pDeviceD3D11Impl {_pDeviceD3D11Impl },
- ShdrDesc {_ShdrDesc },
- CombinedSamplerSuffix{_CombinedSamplerSuffix},
- Resources {_Resources }
- // clang-format on
- {}
-
- void OnNewCB(const D3DShaderResourceAttribs& CBAttribs)
- {
- VERIFY(CBAttribs.BindPoint + CBAttribs.BindCount - 1 <= MaxAllowedBindPoint, "CB bind point exceeds supported range");
- Resources.m_MaxCBBindPoint = std::max(Resources.m_MaxCBBindPoint, static_cast<MaxBindPointType>(CBAttribs.BindPoint + CBAttribs.BindCount - 1));
- }
-
- void OnNewTexUAV(const D3DShaderResourceAttribs& TexUAV)
- {
- VERIFY(TexUAV.BindPoint + TexUAV.BindCount - 1 <= MaxAllowedBindPoint, "Tex UAV bind point exceeds supported range");
- Resources.m_MaxUAVBindPoint = std::max(Resources.m_MaxUAVBindPoint, static_cast<MaxBindPointType>(TexUAV.BindPoint + TexUAV.BindCount - 1));
- }
-
- void OnNewBuffUAV(const D3DShaderResourceAttribs& BuffUAV)
- {
- VERIFY(BuffUAV.BindPoint + BuffUAV.BindCount - 1 <= MaxAllowedBindPoint, "Buff UAV bind point exceeds supported range");
- Resources.m_MaxUAVBindPoint = std::max(Resources.m_MaxUAVBindPoint, static_cast<MaxBindPointType>(BuffUAV.BindPoint + BuffUAV.BindCount - 1));
- }
-
- void OnNewBuffSRV(const D3DShaderResourceAttribs& BuffSRV)
- {
- VERIFY(BuffSRV.BindPoint + BuffSRV.BindCount - 1 <= MaxAllowedBindPoint, "Buff SRV bind point exceeds supported range");
- Resources.m_MaxSRVBindPoint = std::max(Resources.m_MaxSRVBindPoint, static_cast<MaxBindPointType>(BuffSRV.BindPoint + BuffSRV.BindCount - 1));
- }
-
- void OnNewSampler(const D3DShaderResourceAttribs& SamplerAttribs)
- {
- VERIFY(SamplerAttribs.BindPoint + SamplerAttribs.BindCount - 1 <= MaxAllowedBindPoint, "Sampler bind point exceeds supported range");
- Resources.m_MaxSamplerBindPoint = std::max(Resources.m_MaxSamplerBindPoint, static_cast<MaxBindPointType>(SamplerAttribs.BindPoint + SamplerAttribs.BindCount - 1));
- }
-
- void OnNewTexSRV(const D3DShaderResourceAttribs& TexAttribs)
- {
- VERIFY(TexAttribs.BindPoint + TexAttribs.BindCount - 1 <= MaxAllowedBindPoint, "Tex SRV bind point exceeds supported range");
- Resources.m_MaxSRVBindPoint = std::max(Resources.m_MaxSRVBindPoint, static_cast<MaxBindPointType>(TexAttribs.BindPoint + TexAttribs.BindCount - 1));
- }
-
- ~NewResourceHandler()
- {
- }
-
- private:
- RenderDeviceD3D11Impl* const pDeviceD3D11Impl;
- const ShaderDesc& ShdrDesc;
- const char* CombinedSamplerSuffix;
- ShaderResourcesD3D11& Resources;
- };
-
- Initialize<D3D11_SHADER_DESC, D3D11_SHADER_INPUT_BIND_DESC, ID3D11ShaderReflection>(
- pShaderBytecode,
- NewResourceHandler{pDeviceD3D11Impl, ShdrDesc, CombinedSamplerSuffix, *this},
- ShdrDesc.Name,
- CombinedSamplerSuffix);
-}
-
-
-ShaderResourcesD3D11::~ShaderResourcesD3D11()
-{
-}
-
-
-#ifdef DILIGENT_DEVELOPMENT
-static String DbgMakeResourceName(const D3DShaderResourceAttribs& Attr, Uint32 BindPoint)
-{
- VERIFY(BindPoint >= Uint32{Attr.BindPoint} && BindPoint < Uint32{Attr.BindPoint} + Attr.BindCount, "Bind point is out of allowed range");
- if (Attr.BindCount == 1)
- return Attr.Name;
- else
- return String(Attr.Name) + '[' + std::to_string(BindPoint - Attr.BindPoint) + ']';
-}
-
-void ShaderResourcesD3D11::dvpVerifyCommittedResources(ID3D11Buffer* CommittedD3D11CBs[],
- ID3D11ShaderResourceView* CommittedD3D11SRVs[],
- ID3D11Resource* CommittedD3D11SRVResources[],
- ID3D11SamplerState* CommittedD3D11Samplers[],
- ID3D11UnorderedAccessView* CommittedD3D11UAVs[],
- ID3D11Resource* CommittedD3D11UAVResources[],
- ShaderResourceCacheD3D11& ResourceCache) const
-{
- ShaderResourceCacheD3D11::CachedCB* CachedCBs = nullptr;
- ID3D11Buffer** d3d11CBs = nullptr;
- ShaderResourceCacheD3D11::CachedResource* CachedSRVResources = nullptr;
- ID3D11ShaderResourceView** d3d11SRVs = nullptr;
- ShaderResourceCacheD3D11::CachedSampler* CachedSamplers = nullptr;
- ID3D11SamplerState** d3d11Samplers = nullptr;
- ShaderResourceCacheD3D11::CachedResource* CachedUAVResources = nullptr;
- ID3D11UnorderedAccessView** d3d11UAVs = nullptr;
- // clang-format off
- ResourceCache.GetCBArrays (CachedCBs, d3d11CBs);
- ResourceCache.GetSRVArrays (CachedSRVResources, d3d11SRVs);
- ResourceCache.GetSamplerArrays(CachedSamplers, d3d11Samplers);
- ResourceCache.GetUAVArrays (CachedUAVResources, d3d11UAVs);
- // clang-format on
-
- ProcessResources(
- [&](const D3DShaderResourceAttribs& cb, Uint32) //
- {
- for (auto BindPoint = cb.BindPoint; BindPoint < cb.BindPoint + cb.BindCount; ++BindPoint)
- {
- if (BindPoint >= ResourceCache.GetCBCount())
- {
- LOG_ERROR_MESSAGE("Unable to find constant buffer '", DbgMakeResourceName(cb, BindPoint), "' (slot ",
- BindPoint, ") in the resource cache: the cache reserves ", ResourceCache.GetCBCount(),
- " CB slots only. This should never happen and may be the result of using wrong resource cache.");
- continue;
- }
- auto& CB = CachedCBs[BindPoint];
- if (CB.pBuff == nullptr)
- {
- LOG_ERROR_MESSAGE("Constant buffer '", DbgMakeResourceName(cb, BindPoint), "' (slot ",
- BindPoint, ") is not initialized in the resource cache.");
- continue;
- }
-
- if (!(CB.pBuff->GetDesc().BindFlags & BIND_UNIFORM_BUFFER))
- {
- LOG_ERROR_MESSAGE("Buffer '", CB.pBuff->GetDesc().Name,
- "' committed in the device context as constant buffer to variable '",
- DbgMakeResourceName(cb, BindPoint), "' (slot ", BindPoint,
- ") in shader '", GetShaderName(), "' was not created with BIND_UNIFORM_BUFFER flag");
- continue;
- }
-
- VERIFY_EXPR(d3d11CBs[BindPoint] == CB.pBuff->GetD3D11Buffer());
-
- if (CommittedD3D11CBs[BindPoint] == nullptr)
- {
- LOG_ERROR_MESSAGE("No D3D11 resource committed to constant buffer '", DbgMakeResourceName(cb, BindPoint),
- "' (slot ", BindPoint, ") in shader '", GetShaderName(), "'");
- continue;
- }
-
- if (CommittedD3D11CBs[BindPoint] != d3d11CBs[BindPoint])
- {
- LOG_ERROR_MESSAGE("D3D11 resource committed to constant buffer '", DbgMakeResourceName(cb, BindPoint),
- "' (slot ", BindPoint, ") in shader '", GetShaderName(), "' does not match the resource in the resource cache");
- continue;
- }
- }
- },
-
- [&](const D3DShaderResourceAttribs& sam, Uint32) //
- {
- for (auto BindPoint = sam.BindPoint; BindPoint < sam.BindPoint + sam.BindCount; ++BindPoint)
- {
- if (BindPoint >= ResourceCache.GetSamplerCount())
- {
- LOG_ERROR_MESSAGE("Unable to find sampler '", DbgMakeResourceName(sam, BindPoint), "' (slot ", BindPoint,
- ") in the resource cache: the cache reserves ", ResourceCache.GetSamplerCount(),
- " Sampler slots only. This should never happen and may be the result of using wrong resource cache.");
- continue;
- }
- auto& Sam = CachedSamplers[BindPoint];
- if (Sam.pSampler == nullptr)
- {
- LOG_ERROR_MESSAGE("Sampler '", DbgMakeResourceName(sam, BindPoint), "' (slot ", BindPoint,
- ") is not initialized in the resource cache.");
- continue;
- }
- VERIFY_EXPR(d3d11Samplers[BindPoint] == Sam.pSampler->GetD3D11SamplerState());
-
- if (CommittedD3D11Samplers[BindPoint] == nullptr)
- {
- LOG_ERROR_MESSAGE("No D3D11 sampler committed to variable '", DbgMakeResourceName(sam, BindPoint),
- "' (slot ", BindPoint, ") in shader '", GetShaderName(), "'");
- continue;
- }
-
- if (CommittedD3D11Samplers[BindPoint] != d3d11Samplers[BindPoint])
- {
- LOG_ERROR_MESSAGE("D3D11 sampler committed to variable '", DbgMakeResourceName(sam, BindPoint),
- "' (slot ", BindPoint, ") in shader '", GetShaderName(), "' does not match the resource in the resource cache");
- continue;
- }
- }
- },
-
- [&](const D3DShaderResourceAttribs& tex, Uint32) //
- {
- for (auto BindPoint = tex.BindPoint; BindPoint < tex.BindPoint + tex.BindCount; ++BindPoint)
- {
- if (BindPoint >= ResourceCache.GetSRVCount())
- {
- LOG_ERROR_MESSAGE("Unable to find texture SRV '", DbgMakeResourceName(tex, BindPoint), "' (slot ",
- BindPoint, ") in the resource cache: the cache reserves ", ResourceCache.GetSRVCount(),
- " SRV slots only. This should never happen and may be the result of using wrong resource cache.");
- continue;
- }
- auto& SRVRes = CachedSRVResources[BindPoint];
- if (SRVRes.pBuffer != nullptr)
- {
- LOG_ERROR_MESSAGE("Unexpected buffer bound to variable '", DbgMakeResourceName(tex, BindPoint), "' (slot ",
- BindPoint, "). Texture is expected.");
- continue;
- }
- if (SRVRes.pTexture == nullptr)
- {
- LOG_ERROR_MESSAGE("Texture '", DbgMakeResourceName(tex, BindPoint), "' (slot ", BindPoint,
- ") is not initialized in the resource cache.");
- continue;
- }
-
- if (!(SRVRes.pTexture->GetDesc().BindFlags & BIND_SHADER_RESOURCE))
- {
- LOG_ERROR_MESSAGE("Texture '", SRVRes.pTexture->GetDesc().Name,
- "' committed in the device context as SRV to variable '", DbgMakeResourceName(tex, BindPoint),
- "' (slot ", BindPoint, ") in shader '", GetShaderName(), "' was not created with BIND_SHADER_RESOURCE flag");
- }
-
- if (CommittedD3D11SRVs[BindPoint] == nullptr)
- {
- LOG_ERROR_MESSAGE("No D3D11 resource committed to texture SRV '", DbgMakeResourceName(tex, BindPoint),
- "' (slot ", BindPoint, ") in shader '", GetShaderName(), "'");
- continue;
- }
-
- if (CommittedD3D11SRVs[BindPoint] != d3d11SRVs[BindPoint])
- {
- LOG_ERROR_MESSAGE("D3D11 resource committed to texture SRV '", DbgMakeResourceName(tex, BindPoint),
- "' (slot ", BindPoint, ") in shader '", GetShaderName(),
- "' does not match the resource in the resource cache");
- continue;
- }
- }
-
- if (tex.IsCombinedWithSampler())
- {
- const auto& SamAttribs = GetCombinedSampler(tex);
- VERIFY_EXPR(SamAttribs.IsValidBindPoint());
- VERIFY_EXPR(SamAttribs.BindCount == 1 || SamAttribs.BindCount == tex.BindCount);
- }
- },
-
- [&](const D3DShaderResourceAttribs& uav, Uint32) //
- {
- for (auto BindPoint = uav.BindPoint; BindPoint < uav.BindPoint + uav.BindCount; ++BindPoint)
- {
- if (BindPoint >= ResourceCache.GetUAVCount())
- {
- LOG_ERROR_MESSAGE("Unable to find texture UAV '", DbgMakeResourceName(uav, BindPoint), "' (slot ",
- BindPoint, ") in the resource cache: the cache reserves ", ResourceCache.GetUAVCount(),
- " UAV slots only. This should never happen and may be the result of using wrong resource cache.");
- continue;
- }
- auto& UAVRes = CachedUAVResources[BindPoint];
- if (UAVRes.pBuffer != nullptr)
- {
- LOG_ERROR_MESSAGE("Unexpected buffer bound to variable '", DbgMakeResourceName(uav, BindPoint),
- "' (slot ", BindPoint, "). Texture is expected.");
- continue;
- }
- if (UAVRes.pTexture == nullptr)
- {
- LOG_ERROR_MESSAGE("Texture '", DbgMakeResourceName(uav, BindPoint), "' (slot ", BindPoint,
- ") is not initialized in the resource cache.");
- continue;
- }
-
- if (!(UAVRes.pTexture->GetDesc().BindFlags & BIND_UNORDERED_ACCESS))
- {
- LOG_ERROR_MESSAGE("Texture '", UAVRes.pTexture->GetDesc().Name,
- "' committed in the device context as UAV to variable '", DbgMakeResourceName(uav, BindPoint), "' (slot ", BindPoint, ") in shader '", GetShaderName(), "' was not created with BIND_UNORDERED_ACCESS flag");
- }
-
- if (CommittedD3D11UAVs[BindPoint] == nullptr)
- {
- LOG_ERROR_MESSAGE("No D3D11 resource committed to texture UAV '", DbgMakeResourceName(uav, BindPoint),
- "' (slot ", BindPoint, ") in shader '", GetShaderName(), "'");
- continue;
- }
-
- if (CommittedD3D11UAVs[BindPoint] != d3d11UAVs[BindPoint])
- {
- LOG_ERROR_MESSAGE("D3D11 resource committed to texture UAV '", DbgMakeResourceName(uav, BindPoint),
- "' (slot ", BindPoint, ") in shader '", GetShaderName(), "' does not match the resource in the resource cache");
- continue;
- }
- }
- },
-
-
- [&](const D3DShaderResourceAttribs& buf, Uint32) //
- {
- for (auto BindPoint = buf.BindPoint; BindPoint < buf.BindPoint + buf.BindCount; ++BindPoint)
- {
- if (BindPoint >= ResourceCache.GetSRVCount())
- {
- LOG_ERROR_MESSAGE("Unable to find buffer SRV '", DbgMakeResourceName(buf, BindPoint), "' (slot ", BindPoint,
- ") in the resource cache: the cache reserves ", ResourceCache.GetSRVCount(),
- " SRV slots only. This should never happen and may be the result of using wrong resource cache.");
- continue;
- }
- auto& SRVRes = CachedSRVResources[BindPoint];
- if (SRVRes.pTexture != nullptr)
- {
- LOG_ERROR_MESSAGE("Unexpected texture bound to variable '", DbgMakeResourceName(buf, BindPoint),
- "' (slot ", BindPoint, "). Buffer is expected.");
- continue;
- }
- if (SRVRes.pBuffer == nullptr)
- {
- LOG_ERROR_MESSAGE("Buffer '", DbgMakeResourceName(buf, BindPoint), "' (slot ", BindPoint,
- ") is not initialized in the resource cache.");
- continue;
- }
-
- if (!(SRVRes.pBuffer->GetDesc().BindFlags & BIND_SHADER_RESOURCE))
- {
- LOG_ERROR_MESSAGE("Buffer '", SRVRes.pBuffer->GetDesc().Name,
- "' committed in the device context as SRV to variable '", DbgMakeResourceName(buf, BindPoint),
- "' (slot ", BindPoint, ") in shader '", GetShaderName(),
- "' was not created with BIND_SHADER_RESOURCE flag");
- }
-
- if (CommittedD3D11SRVs[BindPoint] == nullptr)
- {
- LOG_ERROR_MESSAGE("No D3D11 resource committed to buffer SRV '", DbgMakeResourceName(buf, BindPoint),
- "' (slot ", BindPoint, ") in shader '", GetShaderName(), "'");
- continue;
- }
-
- if (CommittedD3D11SRVs[BindPoint] != d3d11SRVs[BindPoint])
- {
- LOG_ERROR_MESSAGE("D3D11 resource committed to buffer SRV '", DbgMakeResourceName(buf, BindPoint),
- "' (slot ", BindPoint, ") in shader '", GetShaderName(),
- "' does not match the resource in the resource cache");
- continue;
- }
- }
- },
-
- [&](const D3DShaderResourceAttribs& uav, Uint32) //
- {
- for (auto BindPoint = uav.BindPoint; BindPoint < uav.BindPoint + uav.BindCount; ++BindPoint)
- {
- if (BindPoint >= ResourceCache.GetUAVCount())
- {
- LOG_ERROR_MESSAGE("Unable to find buffer UAV '", DbgMakeResourceName(uav, BindPoint), "' (slot ", BindPoint,
- ") in the resource cache: the cache reserves ", ResourceCache.GetUAVCount(),
- " UAV slots only. This should never happen and may be the result of using wrong resource cache.");
- continue;
- }
- auto& UAVRes = CachedUAVResources[BindPoint];
- if (UAVRes.pTexture != nullptr)
- {
- LOG_ERROR_MESSAGE("Unexpected texture bound to variable '", DbgMakeResourceName(uav, BindPoint),
- "' (slot ", BindPoint, "). Buffer is expected.");
- return;
- }
- if (UAVRes.pBuffer == nullptr)
- {
- LOG_ERROR_MESSAGE("Buffer UAV '", DbgMakeResourceName(uav, BindPoint), "' (slot ", BindPoint,
- ") is not initialized in the resource cache.");
- return;
- }
-
- if (!(UAVRes.pBuffer->GetDesc().BindFlags & BIND_UNORDERED_ACCESS))
- {
- LOG_ERROR_MESSAGE("Buffer '", UAVRes.pBuffer->GetDesc().Name,
- "' committed in the device context as UAV to variable '", DbgMakeResourceName(uav, BindPoint), "' (slot ", BindPoint, ") in shader '", GetShaderName(), "' was not created with BIND_UNORDERED_ACCESS flag");
- }
-
- if (CommittedD3D11UAVs[BindPoint] == nullptr)
- {
- LOG_ERROR_MESSAGE("No D3D11 resource committed to buffer UAV '", DbgMakeResourceName(uav, BindPoint),
- "' (slot ", BindPoint, ") in shader '", GetShaderName(), "'");
- return;
- }
-
- if (CommittedD3D11UAVs[BindPoint] != d3d11UAVs[BindPoint])
- {
- LOG_ERROR_MESSAGE("D3D11 resource committed to buffer UAV '", DbgMakeResourceName(uav, BindPoint),
- "' (slot ", BindPoint, ") in shader '", GetShaderName(),
- "' does not match the resource in the resource cache");
- return;
- }
- }
- } // clang-format off
- ); // clang-format on
-}
-#endif
-
-} // namespace Diligent
+/* + * Copyright 2019-2020 Diligent Graphics LLC + * Copyright 2015-2019 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#include "pch.h" + +#include <d3dcompiler.h> +#include "ShaderResourcesD3D11.hpp" +#include "ShaderBase.hpp" +#include "ShaderResourceCacheD3D11.hpp" +#include "RenderDeviceD3D11Impl.hpp" + +namespace Diligent +{ + + +ShaderResourcesD3D11::ShaderResourcesD3D11(RenderDeviceD3D11Impl* pDeviceD3D11Impl, + ID3DBlob* pShaderBytecode, + const ShaderDesc& ShdrDesc, + const char* CombinedSamplerSuffix) : + ShaderResources{ShdrDesc.ShaderType} +{ + class NewResourceHandler + { + public: + NewResourceHandler(RenderDeviceD3D11Impl* const _pDeviceD3D11Impl, + const ShaderDesc& _ShdrDesc, + const char* _CombinedSamplerSuffix, + ShaderResourcesD3D11& _Resources) : + // clang-format off + pDeviceD3D11Impl {_pDeviceD3D11Impl }, + ShdrDesc {_ShdrDesc }, + CombinedSamplerSuffix{_CombinedSamplerSuffix}, + Resources {_Resources } + // clang-format on + {} + + void OnNewCB(const D3DShaderResourceAttribs& CBAttribs) + { + VERIFY(CBAttribs.BindPoint + CBAttribs.BindCount - 1 <= MaxAllowedBindPoint, "CB bind point exceeds supported range"); + Resources.m_MaxCBBindPoint = std::max(Resources.m_MaxCBBindPoint, static_cast<MaxBindPointType>(CBAttribs.BindPoint + CBAttribs.BindCount - 1)); + } + + void OnNewTexUAV(const D3DShaderResourceAttribs& TexUAV) + { + VERIFY(TexUAV.BindPoint + TexUAV.BindCount - 1 <= MaxAllowedBindPoint, "Tex UAV bind point exceeds supported range"); + Resources.m_MaxUAVBindPoint = std::max(Resources.m_MaxUAVBindPoint, static_cast<MaxBindPointType>(TexUAV.BindPoint + TexUAV.BindCount - 1)); + } + + void OnNewBuffUAV(const D3DShaderResourceAttribs& BuffUAV) + { + VERIFY(BuffUAV.BindPoint + BuffUAV.BindCount - 1 <= MaxAllowedBindPoint, "Buff UAV bind point exceeds supported range"); + Resources.m_MaxUAVBindPoint = std::max(Resources.m_MaxUAVBindPoint, static_cast<MaxBindPointType>(BuffUAV.BindPoint + BuffUAV.BindCount - 1)); + } + + void OnNewBuffSRV(const D3DShaderResourceAttribs& BuffSRV) + { + VERIFY(BuffSRV.BindPoint + BuffSRV.BindCount - 1 <= MaxAllowedBindPoint, "Buff SRV bind point exceeds supported range"); + Resources.m_MaxSRVBindPoint = std::max(Resources.m_MaxSRVBindPoint, static_cast<MaxBindPointType>(BuffSRV.BindPoint + BuffSRV.BindCount - 1)); + } + + void OnNewSampler(const D3DShaderResourceAttribs& SamplerAttribs) + { + VERIFY(SamplerAttribs.BindPoint + SamplerAttribs.BindCount - 1 <= MaxAllowedBindPoint, "Sampler bind point exceeds supported range"); + Resources.m_MaxSamplerBindPoint = std::max(Resources.m_MaxSamplerBindPoint, static_cast<MaxBindPointType>(SamplerAttribs.BindPoint + SamplerAttribs.BindCount - 1)); + } + + void OnNewTexSRV(const D3DShaderResourceAttribs& TexAttribs) + { + VERIFY(TexAttribs.BindPoint + TexAttribs.BindCount - 1 <= MaxAllowedBindPoint, "Tex SRV bind point exceeds supported range"); + Resources.m_MaxSRVBindPoint = std::max(Resources.m_MaxSRVBindPoint, static_cast<MaxBindPointType>(TexAttribs.BindPoint + TexAttribs.BindCount - 1)); + } + + ~NewResourceHandler() + { + } + + private: + RenderDeviceD3D11Impl* const pDeviceD3D11Impl; + const ShaderDesc& ShdrDesc; + const char* CombinedSamplerSuffix; + ShaderResourcesD3D11& Resources; + }; + + CComPtr<ID3D11ShaderReflection> pShaderReflection; + HRESULT hr = D3DReflect(pShaderBytecode->GetBufferPointer(), pShaderBytecode->GetBufferSize(), __uuidof(pShaderReflection), reinterpret_cast<void**>(&pShaderReflection)); + CHECK_D3D_RESULT_THROW(hr, "Failed to get the shader reflection"); + + + Initialize<D3D11_SHADER_DESC, D3D11_SHADER_INPUT_BIND_DESC>( + static_cast<ID3D11ShaderReflection*>(pShaderReflection), + NewResourceHandler{pDeviceD3D11Impl, ShdrDesc, CombinedSamplerSuffix, *this}, + ShdrDesc.Name, + CombinedSamplerSuffix); +} + + +ShaderResourcesD3D11::~ShaderResourcesD3D11() +{ +} + + +#ifdef DILIGENT_DEVELOPMENT +static String DbgMakeResourceName(const D3DShaderResourceAttribs& Attr, Uint32 BindPoint) +{ + VERIFY(BindPoint >= Uint32{Attr.BindPoint} && BindPoint < Uint32{Attr.BindPoint} + Attr.BindCount, "Bind point is out of allowed range"); + if (Attr.BindCount == 1) + return Attr.Name; + else + return String(Attr.Name) + '[' + std::to_string(BindPoint - Attr.BindPoint) + ']'; +} + +void ShaderResourcesD3D11::dvpVerifyCommittedResources(ID3D11Buffer* CommittedD3D11CBs[], + ID3D11ShaderResourceView* CommittedD3D11SRVs[], + ID3D11Resource* CommittedD3D11SRVResources[], + ID3D11SamplerState* CommittedD3D11Samplers[], + ID3D11UnorderedAccessView* CommittedD3D11UAVs[], + ID3D11Resource* CommittedD3D11UAVResources[], + ShaderResourceCacheD3D11& ResourceCache) const +{ + ShaderResourceCacheD3D11::CachedCB* CachedCBs = nullptr; + ID3D11Buffer** d3d11CBs = nullptr; + ShaderResourceCacheD3D11::CachedResource* CachedSRVResources = nullptr; + ID3D11ShaderResourceView** d3d11SRVs = nullptr; + ShaderResourceCacheD3D11::CachedSampler* CachedSamplers = nullptr; + ID3D11SamplerState** d3d11Samplers = nullptr; + ShaderResourceCacheD3D11::CachedResource* CachedUAVResources = nullptr; + ID3D11UnorderedAccessView** d3d11UAVs = nullptr; + // clang-format off + ResourceCache.GetCBArrays (CachedCBs, d3d11CBs); + ResourceCache.GetSRVArrays (CachedSRVResources, d3d11SRVs); + ResourceCache.GetSamplerArrays(CachedSamplers, d3d11Samplers); + ResourceCache.GetUAVArrays (CachedUAVResources, d3d11UAVs); + // clang-format on + + ProcessResources( + [&](const D3DShaderResourceAttribs& cb, Uint32) // + { + for (auto BindPoint = cb.BindPoint; BindPoint < cb.BindPoint + cb.BindCount; ++BindPoint) + { + if (BindPoint >= ResourceCache.GetCBCount()) + { + LOG_ERROR_MESSAGE("Unable to find constant buffer '", DbgMakeResourceName(cb, BindPoint), "' (slot ", + BindPoint, ") in the resource cache: the cache reserves ", ResourceCache.GetCBCount(), + " CB slots only. This should never happen and may be the result of using wrong resource cache."); + continue; + } + auto& CB = CachedCBs[BindPoint]; + if (CB.pBuff == nullptr) + { + LOG_ERROR_MESSAGE("Constant buffer '", DbgMakeResourceName(cb, BindPoint), "' (slot ", + BindPoint, ") is not initialized in the resource cache."); + continue; + } + + if (!(CB.pBuff->GetDesc().BindFlags & BIND_UNIFORM_BUFFER)) + { + LOG_ERROR_MESSAGE("Buffer '", CB.pBuff->GetDesc().Name, + "' committed in the device context as constant buffer to variable '", + DbgMakeResourceName(cb, BindPoint), "' (slot ", BindPoint, + ") in shader '", GetShaderName(), "' was not created with BIND_UNIFORM_BUFFER flag"); + continue; + } + + VERIFY_EXPR(d3d11CBs[BindPoint] == CB.pBuff->GetD3D11Buffer()); + + if (CommittedD3D11CBs[BindPoint] == nullptr) + { + LOG_ERROR_MESSAGE("No D3D11 resource committed to constant buffer '", DbgMakeResourceName(cb, BindPoint), + "' (slot ", BindPoint, ") in shader '", GetShaderName(), "'"); + continue; + } + + if (CommittedD3D11CBs[BindPoint] != d3d11CBs[BindPoint]) + { + LOG_ERROR_MESSAGE("D3D11 resource committed to constant buffer '", DbgMakeResourceName(cb, BindPoint), + "' (slot ", BindPoint, ") in shader '", GetShaderName(), "' does not match the resource in the resource cache"); + continue; + } + } + }, + + [&](const D3DShaderResourceAttribs& sam, Uint32) // + { + for (auto BindPoint = sam.BindPoint; BindPoint < sam.BindPoint + sam.BindCount; ++BindPoint) + { + if (BindPoint >= ResourceCache.GetSamplerCount()) + { + LOG_ERROR_MESSAGE("Unable to find sampler '", DbgMakeResourceName(sam, BindPoint), "' (slot ", BindPoint, + ") in the resource cache: the cache reserves ", ResourceCache.GetSamplerCount(), + " Sampler slots only. This should never happen and may be the result of using wrong resource cache."); + continue; + } + auto& Sam = CachedSamplers[BindPoint]; + if (Sam.pSampler == nullptr) + { + LOG_ERROR_MESSAGE("Sampler '", DbgMakeResourceName(sam, BindPoint), "' (slot ", BindPoint, + ") is not initialized in the resource cache."); + continue; + } + VERIFY_EXPR(d3d11Samplers[BindPoint] == Sam.pSampler->GetD3D11SamplerState()); + + if (CommittedD3D11Samplers[BindPoint] == nullptr) + { + LOG_ERROR_MESSAGE("No D3D11 sampler committed to variable '", DbgMakeResourceName(sam, BindPoint), + "' (slot ", BindPoint, ") in shader '", GetShaderName(), "'"); + continue; + } + + if (CommittedD3D11Samplers[BindPoint] != d3d11Samplers[BindPoint]) + { + LOG_ERROR_MESSAGE("D3D11 sampler committed to variable '", DbgMakeResourceName(sam, BindPoint), + "' (slot ", BindPoint, ") in shader '", GetShaderName(), "' does not match the resource in the resource cache"); + continue; + } + } + }, + + [&](const D3DShaderResourceAttribs& tex, Uint32) // + { + for (auto BindPoint = tex.BindPoint; BindPoint < tex.BindPoint + tex.BindCount; ++BindPoint) + { + if (BindPoint >= ResourceCache.GetSRVCount()) + { + LOG_ERROR_MESSAGE("Unable to find texture SRV '", DbgMakeResourceName(tex, BindPoint), "' (slot ", + BindPoint, ") in the resource cache: the cache reserves ", ResourceCache.GetSRVCount(), + " SRV slots only. This should never happen and may be the result of using wrong resource cache."); + continue; + } + auto& SRVRes = CachedSRVResources[BindPoint]; + if (SRVRes.pBuffer != nullptr) + { + LOG_ERROR_MESSAGE("Unexpected buffer bound to variable '", DbgMakeResourceName(tex, BindPoint), "' (slot ", + BindPoint, "). Texture is expected."); + continue; + } + if (SRVRes.pTexture == nullptr) + { + LOG_ERROR_MESSAGE("Texture '", DbgMakeResourceName(tex, BindPoint), "' (slot ", BindPoint, + ") is not initialized in the resource cache."); + continue; + } + + if (!(SRVRes.pTexture->GetDesc().BindFlags & BIND_SHADER_RESOURCE)) + { + LOG_ERROR_MESSAGE("Texture '", SRVRes.pTexture->GetDesc().Name, + "' committed in the device context as SRV to variable '", DbgMakeResourceName(tex, BindPoint), + "' (slot ", BindPoint, ") in shader '", GetShaderName(), "' was not created with BIND_SHADER_RESOURCE flag"); + } + + if (CommittedD3D11SRVs[BindPoint] == nullptr) + { + LOG_ERROR_MESSAGE("No D3D11 resource committed to texture SRV '", DbgMakeResourceName(tex, BindPoint), + "' (slot ", BindPoint, ") in shader '", GetShaderName(), "'"); + continue; + } + + if (CommittedD3D11SRVs[BindPoint] != d3d11SRVs[BindPoint]) + { + LOG_ERROR_MESSAGE("D3D11 resource committed to texture SRV '", DbgMakeResourceName(tex, BindPoint), + "' (slot ", BindPoint, ") in shader '", GetShaderName(), + "' does not match the resource in the resource cache"); + continue; + } + } + + if (tex.IsCombinedWithSampler()) + { + const auto& SamAttribs = GetCombinedSampler(tex); + VERIFY_EXPR(SamAttribs.IsValidBindPoint()); + VERIFY_EXPR(SamAttribs.BindCount == 1 || SamAttribs.BindCount == tex.BindCount); + } + }, + + [&](const D3DShaderResourceAttribs& uav, Uint32) // + { + for (auto BindPoint = uav.BindPoint; BindPoint < uav.BindPoint + uav.BindCount; ++BindPoint) + { + if (BindPoint >= ResourceCache.GetUAVCount()) + { + LOG_ERROR_MESSAGE("Unable to find texture UAV '", DbgMakeResourceName(uav, BindPoint), "' (slot ", + BindPoint, ") in the resource cache: the cache reserves ", ResourceCache.GetUAVCount(), + " UAV slots only. This should never happen and may be the result of using wrong resource cache."); + continue; + } + auto& UAVRes = CachedUAVResources[BindPoint]; + if (UAVRes.pBuffer != nullptr) + { + LOG_ERROR_MESSAGE("Unexpected buffer bound to variable '", DbgMakeResourceName(uav, BindPoint), + "' (slot ", BindPoint, "). Texture is expected."); + continue; + } + if (UAVRes.pTexture == nullptr) + { + LOG_ERROR_MESSAGE("Texture '", DbgMakeResourceName(uav, BindPoint), "' (slot ", BindPoint, + ") is not initialized in the resource cache."); + continue; + } + + if (!(UAVRes.pTexture->GetDesc().BindFlags & BIND_UNORDERED_ACCESS)) + { + LOG_ERROR_MESSAGE("Texture '", UAVRes.pTexture->GetDesc().Name, + "' committed in the device context as UAV to variable '", DbgMakeResourceName(uav, BindPoint), "' (slot ", BindPoint, ") in shader '", GetShaderName(), "' was not created with BIND_UNORDERED_ACCESS flag"); + } + + if (CommittedD3D11UAVs[BindPoint] == nullptr) + { + LOG_ERROR_MESSAGE("No D3D11 resource committed to texture UAV '", DbgMakeResourceName(uav, BindPoint), + "' (slot ", BindPoint, ") in shader '", GetShaderName(), "'"); + continue; + } + + if (CommittedD3D11UAVs[BindPoint] != d3d11UAVs[BindPoint]) + { + LOG_ERROR_MESSAGE("D3D11 resource committed to texture UAV '", DbgMakeResourceName(uav, BindPoint), + "' (slot ", BindPoint, ") in shader '", GetShaderName(), "' does not match the resource in the resource cache"); + continue; + } + } + }, + + + [&](const D3DShaderResourceAttribs& buf, Uint32) // + { + for (auto BindPoint = buf.BindPoint; BindPoint < buf.BindPoint + buf.BindCount; ++BindPoint) + { + if (BindPoint >= ResourceCache.GetSRVCount()) + { + LOG_ERROR_MESSAGE("Unable to find buffer SRV '", DbgMakeResourceName(buf, BindPoint), "' (slot ", BindPoint, + ") in the resource cache: the cache reserves ", ResourceCache.GetSRVCount(), + " SRV slots only. This should never happen and may be the result of using wrong resource cache."); + continue; + } + auto& SRVRes = CachedSRVResources[BindPoint]; + if (SRVRes.pTexture != nullptr) + { + LOG_ERROR_MESSAGE("Unexpected texture bound to variable '", DbgMakeResourceName(buf, BindPoint), + "' (slot ", BindPoint, "). Buffer is expected."); + continue; + } + if (SRVRes.pBuffer == nullptr) + { + LOG_ERROR_MESSAGE("Buffer '", DbgMakeResourceName(buf, BindPoint), "' (slot ", BindPoint, + ") is not initialized in the resource cache."); + continue; + } + + if (!(SRVRes.pBuffer->GetDesc().BindFlags & BIND_SHADER_RESOURCE)) + { + LOG_ERROR_MESSAGE("Buffer '", SRVRes.pBuffer->GetDesc().Name, + "' committed in the device context as SRV to variable '", DbgMakeResourceName(buf, BindPoint), + "' (slot ", BindPoint, ") in shader '", GetShaderName(), + "' was not created with BIND_SHADER_RESOURCE flag"); + } + + if (CommittedD3D11SRVs[BindPoint] == nullptr) + { + LOG_ERROR_MESSAGE("No D3D11 resource committed to buffer SRV '", DbgMakeResourceName(buf, BindPoint), + "' (slot ", BindPoint, ") in shader '", GetShaderName(), "'"); + continue; + } + + if (CommittedD3D11SRVs[BindPoint] != d3d11SRVs[BindPoint]) + { + LOG_ERROR_MESSAGE("D3D11 resource committed to buffer SRV '", DbgMakeResourceName(buf, BindPoint), + "' (slot ", BindPoint, ") in shader '", GetShaderName(), + "' does not match the resource in the resource cache"); + continue; + } + } + }, + + [&](const D3DShaderResourceAttribs& uav, Uint32) // + { + for (auto BindPoint = uav.BindPoint; BindPoint < uav.BindPoint + uav.BindCount; ++BindPoint) + { + if (BindPoint >= ResourceCache.GetUAVCount()) + { + LOG_ERROR_MESSAGE("Unable to find buffer UAV '", DbgMakeResourceName(uav, BindPoint), "' (slot ", BindPoint, + ") in the resource cache: the cache reserves ", ResourceCache.GetUAVCount(), + " UAV slots only. This should never happen and may be the result of using wrong resource cache."); + continue; + } + auto& UAVRes = CachedUAVResources[BindPoint]; + if (UAVRes.pTexture != nullptr) + { + LOG_ERROR_MESSAGE("Unexpected texture bound to variable '", DbgMakeResourceName(uav, BindPoint), + "' (slot ", BindPoint, "). Buffer is expected."); + return; + } + if (UAVRes.pBuffer == nullptr) + { + LOG_ERROR_MESSAGE("Buffer UAV '", DbgMakeResourceName(uav, BindPoint), "' (slot ", BindPoint, + ") is not initialized in the resource cache."); + return; + } + + if (!(UAVRes.pBuffer->GetDesc().BindFlags & BIND_UNORDERED_ACCESS)) + { + LOG_ERROR_MESSAGE("Buffer '", UAVRes.pBuffer->GetDesc().Name, + "' committed in the device context as UAV to variable '", DbgMakeResourceName(uav, BindPoint), "' (slot ", BindPoint, ") in shader '", GetShaderName(), "' was not created with BIND_UNORDERED_ACCESS flag"); + } + + if (CommittedD3D11UAVs[BindPoint] == nullptr) + { + LOG_ERROR_MESSAGE("No D3D11 resource committed to buffer UAV '", DbgMakeResourceName(uav, BindPoint), + "' (slot ", BindPoint, ") in shader '", GetShaderName(), "'"); + return; + } + + if (CommittedD3D11UAVs[BindPoint] != d3d11UAVs[BindPoint]) + { + LOG_ERROR_MESSAGE("D3D11 resource committed to buffer UAV '", DbgMakeResourceName(uav, BindPoint), + "' (slot ", BindPoint, ") in shader '", GetShaderName(), + "' does not match the resource in the resource cache"); + return; + } + } + } // clang-format off + ); // clang-format on +} +#endif + +} // namespace Diligent |
