From f8be662d357be9dcbb4b298d93b43d29ae93ce04 Mon Sep 17 00:00:00 2001 From: assiduous Date: Tue, 27 Oct 2020 19:08:28 -0700 Subject: A number of updates/fixes to PSO refactor merge --- Graphics/GraphicsEngineD3DBase/CMakeLists.txt | 2 + .../include/D3DCommonTypeConversions.hpp | 40 ++++++++++++++++ .../include/ShaderResources.hpp | 24 ++++++---- .../include/ShaderVariableD3DBase.hpp | 4 +- .../src/D3DCommonTypeConversions.cpp | 55 ++++++++++++++++++++++ .../GraphicsEngineD3DBase/src/ShaderResources.cpp | 24 ++-------- 6 files changed, 117 insertions(+), 32 deletions(-) create mode 100644 Graphics/GraphicsEngineD3DBase/include/D3DCommonTypeConversions.hpp create mode 100644 Graphics/GraphicsEngineD3DBase/src/D3DCommonTypeConversions.cpp (limited to 'Graphics/GraphicsEngineD3DBase') 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/ShaderResources.hpp b/Graphics/GraphicsEngineD3DBase/include/ShaderResources.hpp index cc24414e..926ce209 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::max(); static constexpr const Uint16 MaxBindPoint = InvalidBindPoint - 1; static constexpr const Uint16 MaxBindCount = std::numeric_limits::max(); @@ -157,7 +159,8 @@ public: } // 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(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"); diff --git a/Graphics/GraphicsEngineD3DBase/include/ShaderVariableD3DBase.hpp b/Graphics/GraphicsEngineD3DBase/include/ShaderVariableD3DBase.hpp index 78525f30..2497b17d 100644 --- a/Graphics/GraphicsEngineD3DBase/include/ShaderVariableD3DBase.hpp +++ b/Graphics/GraphicsEngineD3DBase/include/ShaderVariableD3DBase.hpp @@ -87,8 +87,8 @@ protected: }; -template -bool VerifyBufferViewModeD3D(BufferViewImplType* pViewD3D11, const AttribsType& Attribs, const char* ShaderName) +template +bool VerifyBufferViewModeD3D(BufferViewImplType* pViewD3D11, const D3DShaderResourceAttribs& Attribs, const char* ShaderName) { if (pViewD3D11 == nullptr) return true; 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 +#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 79d2cb22..7e6c1f50 100644 --- a/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp +++ b/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp @@ -55,6 +55,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, @@ -467,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()) -- cgit v1.2.3