diff options
| author | assiduous <assiduous@diligentgraphics.com> | 2020-12-15 19:32:55 +0000 |
|---|---|---|
| committer | assiduous <assiduous@diligentgraphics.com> | 2020-12-15 19:32:55 +0000 |
| commit | 2cbe12c8541f63719ae3662cda827ed53004c0b2 (patch) | |
| tree | 6ff68d7ee7d386d1c0e30c00fcd551fcbf819c6c /Graphics/GraphicsEngineD3DBase | |
| parent | Math Lib: added Matrix4x4 constructor from float4 rows (diff) | |
| parent | BasicMath: minor code formatting (diff) | |
| download | DiligentCore-2cbe12c8541f63719ae3662cda827ed53004c0b2.tar.gz DiligentCore-2cbe12c8541f63719ae3662cda827ed53004c0b2.zip | |
Merge branch 'azhirnov-ray_tracing_2'
Diffstat (limited to 'Graphics/GraphicsEngineD3DBase')
7 files changed, 234 insertions, 102 deletions
diff --git a/Graphics/GraphicsEngineD3DBase/CMakeLists.txt b/Graphics/GraphicsEngineD3DBase/CMakeLists.txt index 0e116368..36e0c01a 100644 --- a/Graphics/GraphicsEngineD3DBase/CMakeLists.txt +++ b/Graphics/GraphicsEngineD3DBase/CMakeLists.txt @@ -3,6 +3,7 @@ cmake_minimum_required (VERSION 3.10) project(Diligent-GraphicsEngineD3DBase CXX) set(INCLUDE + include/D3DCommonTypeConversions.hpp include/D3DErrors.hpp include/D3DShaderResourceLoader.hpp include/D3DTypeConversionImpl.hpp @@ -22,6 +23,7 @@ set(INTERFACE ) set(SOURCE + src/D3DCommonTypeConversions.cpp src/DXGITypeConversions.cpp src/ShaderD3DBase.cpp src/ShaderResources.cpp diff --git a/Graphics/GraphicsEngineD3DBase/include/D3DCommonTypeConversions.hpp b/Graphics/GraphicsEngineD3DBase/include/D3DCommonTypeConversions.hpp new file mode 100644 index 00000000..7b3f1e00 --- /dev/null +++ b/Graphics/GraphicsEngineD3DBase/include/D3DCommonTypeConversions.hpp @@ -0,0 +1,40 @@ +/* + * 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. + */ + +#pragma once + +/// \file +/// Common D3D type conversions + +#include "GraphicsTypes.h" + +namespace Diligent +{ + +RESOURCE_DIMENSION D3DSrvDimensionToResourceDimension(D3D_SRV_DIMENSION SrvDim); + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3DBase/include/D3DShaderResourceLoader.hpp b/Graphics/GraphicsEngineD3DBase/include/D3DShaderResourceLoader.hpp index f63aa8ad..5d5f847e 100644 --- a/Graphics/GraphicsEngineD3DBase/include/D3DShaderResourceLoader.hpp +++ b/Graphics/GraphicsEngineD3DBase/include/D3DShaderResourceLoader.hpp @@ -42,12 +42,13 @@ namespace Diligent struct D3DShaderResourceCounters { - Uint32 NumCBs = 0; - Uint32 NumTexSRVs = 0; - Uint32 NumTexUAVs = 0; - Uint32 NumBufSRVs = 0; - Uint32 NumBufUAVs = 0; - Uint32 NumSamplers = 0; + Uint32 NumCBs = 0; + Uint32 NumTexSRVs = 0; + Uint32 NumTexUAVs = 0; + Uint32 NumBufSRVs = 0; + Uint32 NumBufUAVs = 0; + Uint32 NumSamplers = 0; + Uint32 NumAccelStructs = 0; }; template <typename D3D_SHADER_DESC, @@ -61,7 +62,8 @@ template <typename D3D_SHADER_DESC, typename TOnNewBuffUAV, typename TOnNewBuffSRV, typename TOnNewSampler, - typename TOnNewTexSRV> + typename TOnNewTexSRV, + typename TOnNewAccelStruct> void LoadD3DShaderResources(TShaderReflection* pShaderReflection, THandleShaderDesc HandleShaderDesc, TOnResourcesCounted OnResourcesCounted, @@ -70,7 +72,8 @@ void LoadD3DShaderResources(TShaderReflection* pShaderReflection, TOnNewBuffUAV OnNewBuffUAV, TOnNewBuffSRV OnNewBuffSRV, TOnNewSampler OnNewSampler, - TOnNewTexSRV OnNewTexSRV) + TOnNewTexSRV OnNewTexSRV, + TOnNewAccelStruct OnNewAccelStruct) { D3D_SHADER_DESC shaderDesc = {}; pShaderReflection->GetDesc(&shaderDesc); @@ -91,6 +94,9 @@ void LoadD3DShaderResources(TShaderReflection* pShaderReflection, D3D_SHADER_INPUT_BIND_DESC BindingDesc = {}; pShaderReflection->GetResourceBindingDesc(Res, &BindingDesc); + if (BindingDesc.BindPoint == UINT32_MAX) + BindingDesc.BindPoint = D3DShaderResourceAttribs::InvalidBindPoint; + std::string Name(BindingDesc.Name); SkipCount = 1; @@ -173,6 +179,7 @@ void LoadD3DShaderResources(TShaderReflection* pShaderReflection, case D3D_SIT_UAV_APPEND_STRUCTURED: UNSUPPORTED( "Append structured buffers are not supported" ); break; case D3D_SIT_UAV_CONSUME_STRUCTURED: UNSUPPORTED( "Consume structured buffers are not supported" ); break; case D3D_SIT_UAV_RWSTRUCTURED_WITH_COUNTER: UNSUPPORTED( "RW structured buffers with counter are not supported" ); break; + case D3D_SIT_RTACCELERATIONSTRUCTURE: ++RC.NumAccelStructs; break; // clang-format on default: UNEXPECTED("Unexpected resource type"); } @@ -284,6 +291,12 @@ void LoadD3DShaderResources(TShaderReflection* pShaderReflection, break; } + case D3D_SIT_RTACCELERATIONSTRUCTURE: + { + OnNewAccelStruct(Res); + break; + } + default: { UNEXPECTED("Unexpected resource input type"); diff --git a/Graphics/GraphicsEngineD3DBase/include/ShaderResources.hpp b/Graphics/GraphicsEngineD3DBase/include/ShaderResources.hpp index efbff703..c5607ce3 100644 --- a/Graphics/GraphicsEngineD3DBase/include/ShaderResources.hpp +++ b/Graphics/GraphicsEngineD3DBase/include/ShaderResources.hpp @@ -67,6 +67,7 @@ #include "StringPool.hpp" #include "D3DShaderResourceLoader.hpp" #include "PipelineState.h" +#include "D3DCommonTypeConversions.hpp" namespace Diligent { @@ -81,7 +82,6 @@ struct D3DShaderResourceAttribs /* 8 */ const Uint16 BindPoint; /*10 */ const Uint16 BindCount; -private: // 4 4 24 // bit | 0 1 2 3 | 4 5 6 7 | 8 9 10 ... 31 | // | | | | @@ -94,6 +94,7 @@ private: static_assert(D3D_SIT_UAV_RWSTRUCTURED_WITH_COUNTER < (1 << ShaderInputTypeBits), "Not enough bits to represent D3D_SHADER_INPUT_TYPE"); static_assert(D3D_SRV_DIMENSION_BUFFEREX < (1 << SRVDimBits), "Not enough bits to represent D3D_SRV_DIMENSION"); +private: // We need to use Uint32 instead of the actual type for reliability and correctness. // There originally was a problem when the type of InputType was D3D_SHADER_INPUT_TYPE: // the value of D3D_SIT_UAV_RWBYTEADDRESS (8) was interpreted as -8 (as the underlying enum type @@ -106,8 +107,9 @@ private: // clang-format on public: - static constexpr const Uint32 InvalidSamplerId = (1 << SamplerOrTexSRVIdBits) - 1; - static constexpr const Uint32 InvalidTexSRVId = (1 << SamplerOrTexSRVIdBits) - 1; + static constexpr const Uint32 InvalidSamplerId = (1U << SamplerOrTexSRVIdBits) - 1U; + static constexpr const Uint32 MaxSamplerId = InvalidSamplerId - 1; + static constexpr const Uint32 InvalidTexSRVId = (1U << SamplerOrTexSRVIdBits) - 1U; static constexpr const Uint16 InvalidBindPoint = std::numeric_limits<Uint16>::max(); static constexpr const Uint16 MaxBindPoint = InvalidBindPoint - 1; static constexpr const Uint16 MaxBindCount = std::numeric_limits<Uint16>::max(); @@ -144,20 +146,21 @@ public: #endif } - D3DShaderResourceAttribs(StringPool& NamesPool, const D3DShaderResourceAttribs& rhs, Uint32 SamplerId) noexcept : + D3DShaderResourceAttribs(StringPool& NamesPool, const D3DShaderResourceAttribs& rhs, Uint32 _SamplerId, Uint32 _BindPoint) noexcept : // clang-format off D3DShaderResourceAttribs { NamesPool.CopyString(rhs.Name), - rhs.BindPoint, + _BindPoint, rhs.BindCount, rhs.GetInputType(), rhs.GetSRVDimension(), - SamplerId + _SamplerId } // clang-format on { - VERIFY(GetInputType() == D3D_SIT_TEXTURE && GetSRVDimension() != D3D_SRV_DIMENSION_BUFFER, "Only texture SRV can be assigned a texture sampler"); + VERIFY(_SamplerId == InvalidSamplerId || (GetInputType() == D3D_SIT_TEXTURE && GetSRVDimension() != D3D_SRV_DIMENSION_BUFFER), + "Only texture SRV can be assigned a valid texture sampler"); } D3DShaderResourceAttribs(StringPool& NamesPool, const D3DShaderResourceAttribs& rhs) noexcept : @@ -192,13 +195,16 @@ public: return static_cast<D3D_SRV_DIMENSION>(SRVDimension); } - RESOURCE_DIMENSION GetResourceDimension() const; + RESOURCE_DIMENSION GetResourceDimension() const + { + return D3DSrvDimensionToResourceDimension(GetSRVDimension()); + } bool IsMultisample() const; bool IsCombinedWithSampler() const { - return GetCombinedSamplerId() != InvalidSamplerId; + return GetInputType() == D3D_SIT_TEXTURE && SamplerOrTexSRVId != InvalidSamplerId; } bool IsCombinedWithTexSRV() const @@ -236,15 +242,15 @@ public: HLSLShaderResourceDesc GetHLSLResourceDesc() const; -private: - friend class ShaderResources; - Uint32 GetCombinedSamplerId() const { VERIFY(GetInputType() == D3D_SIT_TEXTURE && GetSRVDimension() != D3D_SRV_DIMENSION_BUFFER, "Invalid input type: D3D_SIT_TEXTURE is expected"); return SamplerOrTexSRVId; } +private: + friend class ShaderResources; + void SetTexSRVId(Uint32 TexSRVId) { VERIFY(GetInputType() == D3D_SIT_SAMPLER, "Invalid input type: D3D_SIT_SAMPLER is expected"); @@ -280,20 +286,22 @@ public: ~ShaderResources(); // clang-format off - Uint32 GetNumCBs() const noexcept { return (m_TexSRVOffset - 0); } - Uint32 GetNumTexSRV() const noexcept { return (m_TexUAVOffset - m_TexSRVOffset); } - Uint32 GetNumTexUAV() const noexcept { return (m_BufSRVOffset - m_TexUAVOffset); } - Uint32 GetNumBufSRV() const noexcept { return (m_BufUAVOffset - m_BufSRVOffset); } - Uint32 GetNumBufUAV() const noexcept { return (m_SamplersOffset - m_BufUAVOffset); } - Uint32 GetNumSamplers() const noexcept { return (m_TotalResources - m_SamplersOffset); } - Uint32 GetTotalResources()const noexcept { return m_TotalResources; } - - const D3DShaderResourceAttribs& GetCB (Uint32 n)const noexcept { return GetResAttribs(n, GetNumCBs(), 0); } - const D3DShaderResourceAttribs& GetTexSRV (Uint32 n)const noexcept { return GetResAttribs(n, GetNumTexSRV(), m_TexSRVOffset); } - const D3DShaderResourceAttribs& GetTexUAV (Uint32 n)const noexcept { return GetResAttribs(n, GetNumTexUAV(), m_TexUAVOffset); } - const D3DShaderResourceAttribs& GetBufSRV (Uint32 n)const noexcept { return GetResAttribs(n, GetNumBufSRV(), m_BufSRVOffset); } - const D3DShaderResourceAttribs& GetBufUAV (Uint32 n)const noexcept { return GetResAttribs(n, GetNumBufUAV(), m_BufUAVOffset); } - const D3DShaderResourceAttribs& GetSampler(Uint32 n)const noexcept { return GetResAttribs(n, GetNumSamplers(), m_SamplersOffset); } + Uint32 GetNumCBs() const noexcept { return (m_TexSRVOffset - 0); } + Uint32 GetNumTexSRV() const noexcept { return (m_TexUAVOffset - m_TexSRVOffset); } + Uint32 GetNumTexUAV() const noexcept { return (m_BufSRVOffset - m_TexUAVOffset); } + Uint32 GetNumBufSRV() const noexcept { return (m_BufUAVOffset - m_BufSRVOffset); } + Uint32 GetNumBufUAV() const noexcept { return (m_SamplersOffset - m_BufUAVOffset); } + Uint32 GetNumSamplers() const noexcept { return (m_AccelStructsOffset - m_SamplersOffset); } + Uint32 GetNumAccelStructs()const noexcept { return (m_TotalResources - m_AccelStructsOffset); } + Uint32 GetTotalResources() const noexcept { return m_TotalResources; } + + const D3DShaderResourceAttribs& GetCB (Uint32 n)const noexcept { return GetResAttribs(n, GetNumCBs(), 0); } + const D3DShaderResourceAttribs& GetTexSRV (Uint32 n)const noexcept { return GetResAttribs(n, GetNumTexSRV(), m_TexSRVOffset); } + const D3DShaderResourceAttribs& GetTexUAV (Uint32 n)const noexcept { return GetResAttribs(n, GetNumTexUAV(), m_TexUAVOffset); } + const D3DShaderResourceAttribs& GetBufSRV (Uint32 n)const noexcept { return GetResAttribs(n, GetNumBufSRV(), m_BufSRVOffset); } + const D3DShaderResourceAttribs& GetBufUAV (Uint32 n)const noexcept { return GetResAttribs(n, GetNumBufUAV(), m_BufUAVOffset); } + const D3DShaderResourceAttribs& GetSampler (Uint32 n)const noexcept { return GetResAttribs(n, GetNumSamplers(), m_SamplersOffset); } + const D3DShaderResourceAttribs& GetAccelStruct(Uint32 n)const noexcept { return GetResAttribs(n, GetNumAccelStructs(), m_AccelStructsOffset); } // clang-format on const D3DShaderResourceAttribs& GetCombinedSampler(const D3DShaderResourceAttribs& TexSRV) const noexcept @@ -317,13 +325,15 @@ public: typename THandleTexSRV, typename THandleTexUAV, typename THandleBufSRV, - typename THandleBufUAV> - void ProcessResources(THandleCB HandleCB, - THandleSampler HandleSampler, - THandleTexSRV HandleTexSRV, - THandleTexUAV HandleTexUAV, - THandleBufSRV HandleBufSRV, - THandleBufUAV HandleBufUAV) const + typename THandleBufUAV, + typename THandleAccelStruct> + void ProcessResources(THandleCB HandleCB, + THandleSampler HandleSampler, + THandleTexSRV HandleTexSRV, + THandleTexUAV HandleTexUAV, + THandleBufSRV HandleBufSRV, + THandleBufUAV HandleBufUAV, + THandleAccelStruct HandleAccelStruct) const { for (Uint32 n = 0; n < GetNumCBs(); ++n) { @@ -360,6 +370,12 @@ public: const auto& BufUAV = GetBufUAV(n); HandleBufUAV(BufUAV, n); } + + for (Uint32 n = 0; n < GetNumAccelStructs(); ++n) + { + const auto& AS = GetAccelStruct(n); + HandleAccelStruct(AS, n); + } } bool IsCompatibleWith(const ShaderResources& Resources) const; @@ -420,12 +436,13 @@ protected: } // clang-format off - D3DShaderResourceAttribs& GetCB(Uint32 n) noexcept { return GetResAttribs(n, GetNumCBs(), 0); } - D3DShaderResourceAttribs& GetTexSRV(Uint32 n) noexcept { return GetResAttribs(n, GetNumTexSRV(), m_TexSRVOffset); } - D3DShaderResourceAttribs& GetTexUAV(Uint32 n) noexcept { return GetResAttribs(n, GetNumTexUAV(), m_TexUAVOffset); } - D3DShaderResourceAttribs& GetBufSRV(Uint32 n) noexcept { return GetResAttribs(n, GetNumBufSRV(), m_BufSRVOffset); } - D3DShaderResourceAttribs& GetBufUAV(Uint32 n) noexcept { return GetResAttribs(n, GetNumBufUAV(), m_BufUAVOffset); } - D3DShaderResourceAttribs& GetSampler(Uint32 n) noexcept { return GetResAttribs(n, GetNumSamplers(), m_SamplersOffset); } + D3DShaderResourceAttribs& GetCB(Uint32 n) noexcept { return GetResAttribs(n, GetNumCBs(), 0); } + D3DShaderResourceAttribs& GetTexSRV(Uint32 n) noexcept { return GetResAttribs(n, GetNumTexSRV(), m_TexSRVOffset); } + D3DShaderResourceAttribs& GetTexUAV(Uint32 n) noexcept { return GetResAttribs(n, GetNumTexUAV(), m_TexUAVOffset); } + D3DShaderResourceAttribs& GetBufSRV(Uint32 n) noexcept { return GetResAttribs(n, GetNumBufSRV(), m_BufSRVOffset); } + D3DShaderResourceAttribs& GetBufUAV(Uint32 n) noexcept { return GetResAttribs(n, GetNumBufUAV(), m_BufUAVOffset); } + D3DShaderResourceAttribs& GetSampler(Uint32 n) noexcept { return GetResAttribs(n, GetNumSamplers(), m_SamplersOffset); } + D3DShaderResourceAttribs& GetAccelStruct(Uint32 n)noexcept { return GetResAttribs(n, GetNumAccelStructs(), m_AccelStructsOffset); } // clang-format on private: @@ -447,12 +464,13 @@ private: // Offsets in elements of D3DShaderResourceAttribs typedef Uint16 OffsetType; - OffsetType m_TexSRVOffset = 0; - OffsetType m_TexUAVOffset = 0; - OffsetType m_BufSRVOffset = 0; - OffsetType m_BufUAVOffset = 0; - OffsetType m_SamplersOffset = 0; - OffsetType m_TotalResources = 0; + OffsetType m_TexSRVOffset = 0; + OffsetType m_TexUAVOffset = 0; + OffsetType m_BufSRVOffset = 0; + OffsetType m_BufUAVOffset = 0; + OffsetType m_SamplersOffset = 0; + OffsetType m_AccelStructsOffset = 0; + OffsetType m_TotalResources = 0; const SHADER_TYPE m_ShaderType; @@ -469,7 +487,7 @@ void ShaderResources::Initialize(TShaderReflection* pShaderReflection, const Char* ShaderName, const Char* CombinedSamplerSuffix) { - Uint32 CurrCB = 0, CurrTexSRV = 0, CurrTexUAV = 0, CurrBufSRV = 0, CurrBufUAV = 0, CurrSampler = 0; + Uint32 CurrCB = 0, CurrTexSRV = 0, CurrTexUAV = 0, CurrBufSRV = 0, CurrBufUAV = 0, CurrSampler = 0, CurrAS = 0; // Resource names pool is only needed to facilitate string allocation. StringPool ResourceNamesPool; @@ -534,13 +552,20 @@ void ShaderResources::Initialize(TShaderReflection* pShaderReflection, VERIFY(CurrSampler == GetNumSamplers(), "All samplers must be initialized before texture SRVs"); auto SamplerId = CombinedSamplerSuffix != nullptr ? FindAssignedSamplerId(TexAttribs, CombinedSamplerSuffix) : D3DShaderResourceAttribs::InvalidSamplerId; - auto* pNewTexSRV = new (&GetTexSRV(CurrTexSRV)) D3DShaderResourceAttribs{ResourceNamesPool, TexAttribs, SamplerId}; + auto* pNewTexSRV = new (&GetTexSRV(CurrTexSRV)) D3DShaderResourceAttribs{ResourceNamesPool, TexAttribs, SamplerId, TexAttribs.BindPoint}; if (SamplerId != D3DShaderResourceAttribs::InvalidSamplerId) { GetSampler(SamplerId).SetTexSRVId(CurrTexSRV); } ++CurrTexSRV; NewResHandler.OnNewTexSRV(*pNewTexSRV); + }, + + [&](const D3DShaderResourceAttribs& AccelStructAttribs) // + { + VERIFY_EXPR(AccelStructAttribs.GetInputType() == D3D_SIT_RTACCELERATIONSTRUCTURE); + auto* pNewAccelStruct = new (&GetAccelStruct(CurrAS++)) D3DShaderResourceAttribs{ResourceNamesPool, AccelStructAttribs}; + NewResHandler.OnNewAccelStruct(*pNewAccelStruct); } // ); @@ -562,12 +587,13 @@ void ShaderResources::Initialize(TShaderReflection* pShaderReflection, VERIFY_EXPR(ResourceNamesPool.GetRemainingSize() == 0); // clang-format off - VERIFY(CurrCB == GetNumCBs(), "Not all CBs are initialized which will cause a crash when ~D3DShaderResourceAttribs() is called"); - VERIFY(CurrTexSRV == GetNumTexSRV(), "Not all Tex SRVs are initialized which will cause a crash when ~D3DShaderResourceAttribs() is called" ); - VERIFY(CurrTexUAV == GetNumTexUAV(), "Not all Tex UAVs are initialized which will cause a crash when ~D3DShaderResourceAttribs() is called" ); - VERIFY(CurrBufSRV == GetNumBufSRV(), "Not all Buf SRVs are initialized which will cause a crash when ~D3DShaderResourceAttribs() is called" ); - VERIFY(CurrBufUAV == GetNumBufUAV(), "Not all Buf UAVs are initialized which will cause a crash when ~D3DShaderResourceAttribs() is called" ); - VERIFY(CurrSampler == GetNumSamplers(), "Not all Samplers are initialized which will cause a crash when ~D3DShaderResourceAttribs() is called" ); + VERIFY(CurrCB == GetNumCBs(), "Not all CBs are initialized which will cause a crash when ~D3DShaderResourceAttribs() is called"); + VERIFY(CurrTexSRV == GetNumTexSRV(), "Not all Tex SRVs are initialized which will cause a crash when ~D3DShaderResourceAttribs() is called" ); + VERIFY(CurrTexUAV == GetNumTexUAV(), "Not all Tex UAVs are initialized which will cause a crash when ~D3DShaderResourceAttribs() is called" ); + VERIFY(CurrBufSRV == GetNumBufSRV(), "Not all Buf SRVs are initialized which will cause a crash when ~D3DShaderResourceAttribs() is called" ); + VERIFY(CurrBufUAV == GetNumBufUAV(), "Not all Buf UAVs are initialized which will cause a crash when ~D3DShaderResourceAttribs() is called" ); + VERIFY(CurrSampler == GetNumSamplers(), "Not all Samplers are initialized which will cause a crash when ~D3DShaderResourceAttribs() is called" ); + VERIFY(CurrAS == GetNumAccelStructs(), "Not all Accel Structs are initialized which will cause a crash when ~D3DShaderResourceAttribs() is called" ); // clang-format on } diff --git a/Graphics/GraphicsEngineD3DBase/include/SwapChainD3DBase.hpp b/Graphics/GraphicsEngineD3DBase/include/SwapChainD3DBase.hpp index 701361d1..f26bcc5e 100644 --- a/Graphics/GraphicsEngineD3DBase/include/SwapChainD3DBase.hpp +++ b/Graphics/GraphicsEngineD3DBase/include/SwapChainD3DBase.hpp @@ -157,6 +157,7 @@ protected: swapChainDesc.SampleDesc.Quality = 0; DEV_CHECK_ERR(m_SwapChainDesc.Usage != 0, "No swap chain usage flags defined"); + static_assert(SWAP_CHAIN_USAGE_LAST == SWAP_CHAIN_USAGE_COPY_SOURCE, "Please update this function to handle the new swapchain usage"); swapChainDesc.BufferUsage = 0; if (m_SwapChainDesc.Usage & SWAP_CHAIN_USAGE_RENDER_TARGET) swapChainDesc.BufferUsage |= DXGI_USAGE_RENDER_TARGET_OUTPUT; diff --git a/Graphics/GraphicsEngineD3DBase/src/D3DCommonTypeConversions.cpp b/Graphics/GraphicsEngineD3DBase/src/D3DCommonTypeConversions.cpp new file mode 100644 index 00000000..15f9cc76 --- /dev/null +++ b/Graphics/GraphicsEngineD3DBase/src/D3DCommonTypeConversions.cpp @@ -0,0 +1,55 @@ +/* + * 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 <d3dcommon.h> +#include "D3DCommonTypeConversions.hpp" + +namespace Diligent +{ + +RESOURCE_DIMENSION D3DSrvDimensionToResourceDimension(D3D_SRV_DIMENSION SrvDim) +{ + switch (SrvDim) + { + // clang-format off + case D3D_SRV_DIMENSION_BUFFER: return RESOURCE_DIM_BUFFER; + case D3D_SRV_DIMENSION_TEXTURE1D: return RESOURCE_DIM_TEX_1D; + case D3D_SRV_DIMENSION_TEXTURE1DARRAY: return RESOURCE_DIM_TEX_1D_ARRAY; + case D3D_SRV_DIMENSION_TEXTURE2D: return RESOURCE_DIM_TEX_2D; + case D3D_SRV_DIMENSION_TEXTURE2DARRAY: return RESOURCE_DIM_TEX_2D_ARRAY; + case D3D_SRV_DIMENSION_TEXTURE2DMS: return RESOURCE_DIM_TEX_2D; + case D3D_SRV_DIMENSION_TEXTURE2DMSARRAY: return RESOURCE_DIM_TEX_2D_ARRAY; + case D3D_SRV_DIMENSION_TEXTURE3D: return RESOURCE_DIM_TEX_3D; + case D3D_SRV_DIMENSION_TEXTURECUBE: return RESOURCE_DIM_TEX_CUBE; + case D3D_SRV_DIMENSION_TEXTURECUBEARRAY: return RESOURCE_DIM_TEX_CUBE_ARRAY; + // clang-format on + default: + return RESOURCE_DIM_BUFFER; + } +} + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp b/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp index b975b506..09d27372 100644 --- a/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp +++ b/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp @@ -25,7 +25,6 @@ * of the possibility of such damages. */ -#include "pch.h" #include "EngineMemory.h" #include "StringTools.hpp" #include "ShaderResources.hpp" @@ -55,6 +54,9 @@ ShaderResources::~ShaderResources() for (Uint32 n = 0; n < GetNumSamplers(); ++n) GetSampler(n).~D3DShaderResourceAttribs(); + + for (Uint32 n = 0; n < GetNumAccelStructs(); ++n) + GetAccelStruct(n).~D3DShaderResourceAttribs(); } void ShaderResources::AllocateMemory(IMemoryAllocator& Allocator, @@ -74,23 +76,25 @@ void ShaderResources::AllocateMemory(IMemoryAllocator& Allocator, }; // clang-format off - auto CBOffset = AdvanceOffset(ResCounters.NumCBs); (void)CBOffset; // To suppress warning - m_TexSRVOffset = AdvanceOffset(ResCounters.NumTexSRVs); - m_TexUAVOffset = AdvanceOffset(ResCounters.NumTexUAVs); - m_BufSRVOffset = AdvanceOffset(ResCounters.NumBufSRVs); - m_BufUAVOffset = AdvanceOffset(ResCounters.NumBufUAVs); - m_SamplersOffset = AdvanceOffset(ResCounters.NumSamplers); - m_TotalResources = AdvanceOffset(0); + auto CBOffset = AdvanceOffset(ResCounters.NumCBs); (void)CBOffset; // To suppress warning + m_TexSRVOffset = AdvanceOffset(ResCounters.NumTexSRVs); + m_TexUAVOffset = AdvanceOffset(ResCounters.NumTexUAVs); + m_BufSRVOffset = AdvanceOffset(ResCounters.NumBufSRVs); + m_BufUAVOffset = AdvanceOffset(ResCounters.NumBufUAVs); + m_SamplersOffset = AdvanceOffset(ResCounters.NumSamplers); + m_AccelStructsOffset = AdvanceOffset(ResCounters.NumAccelStructs); + m_TotalResources = AdvanceOffset(0); auto AlignedResourceNamesPoolSize = Align(ResourceNamesPoolSize, sizeof(void*)); auto MemorySize = m_TotalResources * sizeof(D3DShaderResourceAttribs) + AlignedResourceNamesPoolSize * sizeof(char); - VERIFY_EXPR(GetNumCBs() == ResCounters.NumCBs); - VERIFY_EXPR(GetNumTexSRV() == ResCounters.NumTexSRVs); - VERIFY_EXPR(GetNumTexUAV() == ResCounters.NumTexUAVs); - VERIFY_EXPR(GetNumBufSRV() == ResCounters.NumBufSRVs); - VERIFY_EXPR(GetNumBufUAV() == ResCounters.NumBufUAVs); - VERIFY_EXPR(GetNumSamplers()== ResCounters.NumSamplers); + VERIFY_EXPR(GetNumCBs() == ResCounters.NumCBs); + VERIFY_EXPR(GetNumTexSRV() == ResCounters.NumTexSRVs); + VERIFY_EXPR(GetNumTexUAV() == ResCounters.NumTexUAVs); + VERIFY_EXPR(GetNumBufSRV() == ResCounters.NumBufSRVs); + VERIFY_EXPR(GetNumBufUAV() == ResCounters.NumBufUAVs); + VERIFY_EXPR(GetNumSamplers() == ResCounters.NumSamplers); + VERIFY_EXPR(GetNumAccelStructs()== ResCounters.NumAccelStructs); // clang-format on if (MemorySize) @@ -208,6 +212,12 @@ D3DShaderResourceCounters ShaderResources::CountResources(const PipelineResource auto VarType = FindVariableType(BufUAV, ResourceLayout); if (IsAllowedType(VarType, AllowedTypeBits)) ++Counters.NumBufUAVs; + }, + [&](const D3DShaderResourceAttribs& AccelStruct, Uint32) // + { + auto VarType = FindVariableType(AccelStruct, ResourceLayout); + if (IsAllowedType(VarType, AllowedTypeBits)) + ++Counters.NumAccelStructs; } // ); @@ -226,15 +236,16 @@ void ShaderResources::DvpVerifyResourceLayout(const PipelineResourceLayoutDesc& std::string ShadersStr; while (ShaderStages != SHADER_TYPE_UNKNOWN) { - const auto ShaderType = ShaderStages & static_cast<SHADER_TYPE>(~(static_cast<Uint32>(ShaderStages) - 1)); - const char* ShaderName = nullptr; + const auto ShaderType = ShaderStages & static_cast<SHADER_TYPE>(~(static_cast<Uint32>(ShaderStages) - 1)); + String ShaderName; for (Uint32 s = 0; s < NumShaders; ++s) { const auto& Resources = *pShaderResources[s]; if ((ShaderStages & Resources.GetShaderType()) != 0) { - ShaderName = Resources.GetShaderName(); - break; + if (ShaderName.size()) + ShaderName += ", "; + ShaderName += Resources.GetShaderName(); } } @@ -242,10 +253,10 @@ void ShaderResources::DvpVerifyResourceLayout(const PipelineResourceLayoutDesc& ShadersStr.append(", "); ShadersStr.append(GetShaderTypeLiteralName(ShaderType)); ShadersStr.append(" ("); - if (ShaderName) + if (ShaderName.size()) { ShadersStr.push_back('\''); - ShadersStr.append(ShaderName ? ShaderName : "<Not enabled in PSO>"); + ShadersStr.append(ShaderName); ShadersStr.push_back('\''); } else @@ -400,6 +411,11 @@ bool ShaderResources::IsCompatibleWith(const ShaderResources& Res) const { if (!BufUAV.IsCompatibleWith(Res.GetBufUAV(n))) IsCompatible = false; + }, + [&](const D3DShaderResourceAttribs& AccelStruct, Uint32 n) // + { + if (!AccelStruct.IsCompatibleWith(Res.GetAccelStruct(n))) + IsCompatible = false; } // ); return IsCompatible; @@ -454,27 +470,6 @@ HLSLShaderResourceDesc D3DShaderResourceAttribs::GetHLSLResourceDesc() const return ResourceDesc; } -RESOURCE_DIMENSION D3DShaderResourceAttribs::GetResourceDimension() const -{ - switch (GetSRVDimension()) - { - // clang-format off - case D3D_SRV_DIMENSION_BUFFER: return RESOURCE_DIM_BUFFER; - case D3D_SRV_DIMENSION_TEXTURE1D: return RESOURCE_DIM_TEX_1D; - case D3D_SRV_DIMENSION_TEXTURE1DARRAY: return RESOURCE_DIM_TEX_1D_ARRAY; - case D3D_SRV_DIMENSION_TEXTURE2D: return RESOURCE_DIM_TEX_2D; - case D3D_SRV_DIMENSION_TEXTURE2DARRAY: return RESOURCE_DIM_TEX_2D_ARRAY; - case D3D_SRV_DIMENSION_TEXTURE2DMS: return RESOURCE_DIM_TEX_2D; - case D3D_SRV_DIMENSION_TEXTURE2DMSARRAY: return RESOURCE_DIM_TEX_2D_ARRAY; - case D3D_SRV_DIMENSION_TEXTURE3D: return RESOURCE_DIM_TEX_3D; - case D3D_SRV_DIMENSION_TEXTURECUBE: return RESOURCE_DIM_TEX_CUBE; - case D3D_SRV_DIMENSION_TEXTURECUBEARRAY: return RESOURCE_DIM_TEX_CUBE_ARRAY; - // clang-format on - default: - return RESOURCE_DIM_BUFFER; - } -} - bool D3DShaderResourceAttribs::IsMultisample() const { switch (GetSRVDimension()) |
