summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngine
diff options
context:
space:
mode:
authorassiduous <assiduous@diligentgraphics.com>2021-01-23 04:46:14 +0000
committerassiduous <assiduous@diligentgraphics.com>2021-01-23 04:46:14 +0000
commit9eca06a41fa72a8158784ad5116c717076634e40 (patch)
tree243933cedcf15607bf2d2a976cd7eb2e8e548da7 /Graphics/GraphicsEngine
parentPipelineState.h: updated comments (diff)
parentimprovements and optimizations for resource signature (diff)
downloadDiligentCore-9eca06a41fa72a8158784ad5116c717076634e40.tar.gz
DiligentCore-9eca06a41fa72a8158784ad5116c717076634e40.zip
Merge branch 'azhirnov-res_layout' into resource_signature
Diffstat (limited to 'Graphics/GraphicsEngine')
-rw-r--r--Graphics/GraphicsEngine/include/DeviceContextBase.hpp2
-rw-r--r--Graphics/GraphicsEngine/include/PipelineResourceSignatureBase.hpp47
-rw-r--r--Graphics/GraphicsEngine/include/PipelineStateBase.hpp21
-rw-r--r--Graphics/GraphicsEngine/include/PrivateConstants.h51
-rw-r--r--Graphics/GraphicsEngine/include/RenderDeviceBase.hpp2
-rw-r--r--Graphics/GraphicsEngine/include/ShaderResourceBindingBase.hpp1
-rw-r--r--Graphics/GraphicsEngine/include/TopLevelASBase.hpp4
-rw-r--r--Graphics/GraphicsEngine/interface/Constants.h7
-rw-r--r--Graphics/GraphicsEngine/interface/PipelineResourceSignature.h9
-rw-r--r--Graphics/GraphicsEngine/interface/ShaderResourceBinding.h2
-rw-r--r--Graphics/GraphicsEngine/src/PipelineResourceSignatureBase.cpp17
11 files changed, 126 insertions, 37 deletions
diff --git a/Graphics/GraphicsEngine/include/DeviceContextBase.hpp b/Graphics/GraphicsEngine/include/DeviceContextBase.hpp
index 8626c57b..f6d12e11 100644
--- a/Graphics/GraphicsEngine/include/DeviceContextBase.hpp
+++ b/Graphics/GraphicsEngine/include/DeviceContextBase.hpp
@@ -497,7 +497,7 @@ inline bool DeviceContextBase<BaseInterface, ImplementationTraits>::CommitShader
if (pShaderResourceBinding == nullptr)
{
- LOG_ERROR_MESSAGE("TODO");
+ LOG_ERROR_MESSAGE("pShaderResourceBinding must not be null");
return false;
}
#endif
diff --git a/Graphics/GraphicsEngine/include/PipelineResourceSignatureBase.hpp b/Graphics/GraphicsEngine/include/PipelineResourceSignatureBase.hpp
index 63034655..0e14162a 100644
--- a/Graphics/GraphicsEngine/include/PipelineResourceSignatureBase.hpp
+++ b/Graphics/GraphicsEngine/include/PipelineResourceSignatureBase.hpp
@@ -29,9 +29,11 @@
/// \file
/// Implementation of the Diligent::PipelineResourceSignatureBase template class
-#include <unordered_map>
+#include <array>
+#include <limits>
#include <algorithm>
+#include "PrivateConstants.h"
#include "PipelineResourceSignature.h"
#include "DeviceObjectBase.hpp"
#include "RenderDeviceBase.hpp"
@@ -58,13 +60,14 @@ public:
/// \param pDevice - Pointer to the device.
/// \param Desc - Resource signature description.
/// \param bIsDeviceInternal - Flag indicating if this resource signature is an internal device object and
- /// must not keep a strong reference to the device.
+ /// must not keep a strong reference to the device.
PipelineResourceSignatureBase(IReferenceCounters* pRefCounters,
RenderDeviceImplType* pDevice,
const PipelineResourceSignatureDesc& Desc,
bool bIsDeviceInternal = false) :
TDeviceObjectBase{pRefCounters, pDevice, Desc, bIsDeviceInternal}
{
+ // Don't read from m_Desc until it was allocated and copied in CopyDescription()
this->m_Desc.Resources = nullptr;
this->m_Desc.ImmutableSamplers = nullptr;
this->m_Desc.CombinedSamplerSuffix = nullptr;
@@ -88,6 +91,13 @@ public:
bool IsUsingCombinedSamplers() const { return this->m_Desc.CombinedSamplerSuffix != nullptr; }
bool IsUsingSeparateSamplers() const { return !IsUsingCombinedSamplers(); }
+ Uint32 GetTotalResourceCount() const { return this->m_Desc.NumResources; }
+
+ std::pair<Uint32, Uint32> GetResourceIndexRange(SHADER_RESOURCE_VARIABLE_TYPE VarType) const
+ {
+ return std::pair<Uint32, Uint32>{m_ResourceOffsets[VarType], m_ResourceOffsets[VarType + 1]};
+ }
+
protected:
void ReserveSpaceForDescription(FixedLinearAllocator& Allocator, const PipelineResourceSignatureDesc& Desc) const noexcept(false)
{
@@ -113,15 +123,14 @@ protected:
Allocator.AddSpaceForString(Desc.ImmutableSamplers[i].SamplerOrTextureName);
}
- Allocator.AddSpaceForString(Desc.CombinedSamplerSuffix);
+ if (Desc.UseCombinedTextureSamplers)
+ Allocator.AddSpaceForString(Desc.CombinedSamplerSuffix);
}
void CopyDescription(FixedLinearAllocator& Allocator, const PipelineResourceSignatureDesc& Desc) noexcept(false)
{
- PipelineResourceDesc* pResources = Allocator.Allocate<PipelineResourceDesc>(this->m_Desc.NumResources);
- ImmutableSamplerDesc* pSamplers = Allocator.Allocate<ImmutableSamplerDesc>(this->m_Desc.NumImmutableSamplers);
-
- m_Hash = ComputeHash(Desc.NumResources, Desc.NumImmutableSamplers, Desc.BindingIndex);
+ PipelineResourceDesc* pResources = Allocator.Allocate<PipelineResourceDesc>(Desc.NumResources);
+ ImmutableSamplerDesc* pSamplers = Allocator.Allocate<ImmutableSamplerDesc>(Desc.NumImmutableSamplers);
for (Uint32 i = 0; i < Desc.NumResources; ++i)
{
@@ -129,21 +138,31 @@ protected:
Dst = Desc.Resources[i];
Dst.Name = Allocator.CopyString(Desc.Resources[i].Name);
- HashCombine(m_Hash, Dst.ArraySize, Dst.ResourceType, Dst.ShaderStages, Dst.VarType, Dst.Flags);
+ ++m_ResourceOffsets[Dst.VarType + 1];
}
+ std::sort(pResources, pResources + Desc.NumResources,
+ [](const PipelineResourceDesc& lhs, const PipelineResourceDesc& rhs) {
+ return lhs.VarType < rhs.VarType;
+ });
+
+ for (size_t i = 1; i < m_ResourceOffsets.size(); ++i)
+ m_ResourceOffsets[i] += m_ResourceOffsets[i - 1];
+
+ VERIFY_EXPR(m_ResourceOffsets[SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES] == Desc.NumResources);
+
for (Uint32 i = 0; i < Desc.NumImmutableSamplers; ++i)
{
auto& Dst = pSamplers[i];
Dst = Desc.ImmutableSamplers[i];
Dst.SamplerOrTextureName = Allocator.CopyString(Desc.ImmutableSamplers[i].SamplerOrTextureName);
-
- HashCombine(m_Hash, Dst.ShaderStages, Dst.Desc);
}
- this->m_Desc.Resources = pResources;
- this->m_Desc.ImmutableSamplers = pSamplers;
- this->m_Desc.CombinedSamplerSuffix = Allocator.CopyString(Desc.CombinedSamplerSuffix);
+ this->m_Desc.Resources = pResources;
+ this->m_Desc.ImmutableSamplers = pSamplers;
+
+ if (Desc.UseCombinedTextureSamplers)
+ this->m_Desc.CombinedSamplerSuffix = Allocator.CopyString(Desc.CombinedSamplerSuffix);
}
void Destruct()
@@ -222,6 +241,8 @@ protected:
protected:
size_t m_Hash = 0;
+ std::array<Uint16, SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES + 1> m_ResourceOffsets = {};
+
PIPELINE_TYPE m_PipelineType = static_cast<PIPELINE_TYPE>(0xFF);
#ifdef DILIGENT_DEBUG
diff --git a/Graphics/GraphicsEngine/include/PipelineStateBase.hpp b/Graphics/GraphicsEngine/include/PipelineStateBase.hpp
index 4b8b3b8a..4f95bae8 100644
--- a/Graphics/GraphicsEngine/include/PipelineStateBase.hpp
+++ b/Graphics/GraphicsEngine/include/PipelineStateBase.hpp
@@ -35,6 +35,7 @@
#include <unordered_set>
#include <cstring>
+#include "PrivateConstants.h"
#include "PipelineState.h"
#include "DeviceObjectBase.hpp"
#include "STDAllocator.hpp"
@@ -238,44 +239,44 @@ public:
{
*ppShaderResourceBinding = nullptr;
- if (GetResourceSignatureCount() != 1)
+ if (this->GetResourceSignatureCount() != 1)
return;
- return GetResourceSignature(0)->CreateShaderResourceBinding(ppShaderResourceBinding, InitStaticResources);
+ return this->GetResourceSignature(0)->CreateShaderResourceBinding(ppShaderResourceBinding, InitStaticResources);
}
virtual IShaderResourceVariable* DILIGENT_CALL_TYPE GetStaticVariableByName(SHADER_TYPE ShaderType,
const Char* Name) override final
{
- if (GetResourceSignatureCount() != 1)
+ if (this->GetResourceSignatureCount() != 1)
return nullptr;
- return GetResourceSignature(0)->GetStaticVariableByName(ShaderType, Name);
+ return this->GetResourceSignature(0)->GetStaticVariableByName(ShaderType, Name);
}
virtual IShaderResourceVariable* DILIGENT_CALL_TYPE GetStaticVariableByIndex(SHADER_TYPE ShaderType,
Uint32 Index) override final
{
- if (GetResourceSignatureCount() != 1)
+ if (this->GetResourceSignatureCount() != 1)
return nullptr;
- return GetResourceSignature(0)->GetStaticVariableByIndex(ShaderType, Index);
+ return this->GetResourceSignature(0)->GetStaticVariableByIndex(ShaderType, Index);
}
virtual Uint32 DILIGENT_CALL_TYPE GetStaticVariableCount(SHADER_TYPE ShaderType) const override final
{
- if (GetResourceSignatureCount() != 1)
+ if (this->GetResourceSignatureCount() != 1)
return 0;
- return GetResourceSignature(0)->GetStaticVariableCount(ShaderType);
+ return this->GetResourceSignature(0)->GetStaticVariableCount(ShaderType);
}
virtual void DILIGENT_CALL_TYPE BindStaticResources(Uint32 ShaderFlags, IResourceMapping* pResourceMapping, Uint32 Flags) override final
{
- if (GetResourceSignatureCount() != 1)
+ if (this->GetResourceSignatureCount() != 1)
return;
- return GetResourceSignature(0)->BindStaticResources(ShaderFlags, pResourceMapping, Flags);
+ return this->GetResourceSignature(0)->BindStaticResources(ShaderFlags, pResourceMapping, Flags);
}
inline void CopyShaderHandle(const char* Name, void* pData, size_t DataSize) const
diff --git a/Graphics/GraphicsEngine/include/PrivateConstants.h b/Graphics/GraphicsEngine/include/PrivateConstants.h
new file mode 100644
index 00000000..3c63a068
--- /dev/null
+++ b/Graphics/GraphicsEngine/include/PrivateConstants.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2019-2021 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
+/// Definition of the engine private constants
+
+#include "Constants.h"
+
+namespace Diligent
+{
+
+/// The maximum number of shader stages in a pipeline.
+/// (Vertex, Hull, Domain, Geometry, Pixel) or (Amplification, Mesh, Pixel), or (Compute) or (RayGen, Miss, ClosestHit, AnyHit, Intersection, Callable)
+static constexpr Uint32 MAX_SHADERS_IN_PIPELINE = 6;
+
+/// The maximum number of resource signatures that one pipeline can use
+static constexpr Uint32 MAX_RESOURCE_SIGNATURES = 8;
+
+// Static/mutable and dynamic descriptor sets (Vulkan only)
+static constexpr Uint32 MAX_DESCR_SET_PER_SIGNATURE = 2;
+
+// The maximum number of resources in pipeline resources signature.
+static constexpr Uint32 MAX_RESOURCES_IN_SIGNATURE = 1u << 16;
+
+} // namespace Diligent
diff --git a/Graphics/GraphicsEngine/include/RenderDeviceBase.hpp b/Graphics/GraphicsEngine/include/RenderDeviceBase.hpp
index b67d15a9..928dd792 100644
--- a/Graphics/GraphicsEngine/include/RenderDeviceBase.hpp
+++ b/Graphics/GraphicsEngine/include/RenderDeviceBase.hpp
@@ -236,7 +236,7 @@ public:
/// Size of the SBT object (ShaderBindingTableD3D12Impl, ShaderBindingtableVkImpl, etc.), in bytes
const size_t SBTObjSize;
- /// AZ TODO: comment
+ /// Size of the pipeline resource signature object (PipelineResourceSignatureD3D12Impl, PipelineResourceSignatureVkImpl, etc.), in bytes
const size_t PipeResSignObjSize;
};
diff --git a/Graphics/GraphicsEngine/include/ShaderResourceBindingBase.hpp b/Graphics/GraphicsEngine/include/ShaderResourceBindingBase.hpp
index 897ba560..058e3c86 100644
--- a/Graphics/GraphicsEngine/include/ShaderResourceBindingBase.hpp
+++ b/Graphics/GraphicsEngine/include/ShaderResourceBindingBase.hpp
@@ -32,6 +32,7 @@
#include <array>
+#include "PrivateConstants.h"
#include "ShaderResourceBinding.h"
#include "ObjectBase.hpp"
#include "GraphicsTypes.h"
diff --git a/Graphics/GraphicsEngine/include/TopLevelASBase.hpp b/Graphics/GraphicsEngine/include/TopLevelASBase.hpp
index 41a0785b..2994ad83 100644
--- a/Graphics/GraphicsEngine/include/TopLevelASBase.hpp
+++ b/Graphics/GraphicsEngine/include/TopLevelASBase.hpp
@@ -69,10 +69,10 @@ private:
public:
using TDeviceObjectBase = DeviceObjectBase<BaseInterface, RenderDeviceImplType, TopLevelASDesc>;
- /// \param pRefCounters - Reference counters object that controls the lifetime of this BLAS.
+ /// \param pRefCounters - Reference counters object that controls the lifetime of this TLAS.
/// \param pDevice - Pointer to the device.
/// \param Desc - TLAS description.
- /// \param bIsDeviceInternal - Flag indicating if the BLAS is an internal device object and
+ /// \param bIsDeviceInternal - Flag indicating if the TLAS is an internal device object and
/// must not keep a strong reference to the device.
TopLevelASBase(IReferenceCounters* pRefCounters,
RenderDeviceImplType* pDevice,
diff --git a/Graphics/GraphicsEngine/interface/Constants.h b/Graphics/GraphicsEngine/interface/Constants.h
index 3f290303..efb6ad0a 100644
--- a/Graphics/GraphicsEngine/interface/Constants.h
+++ b/Graphics/GraphicsEngine/interface/Constants.h
@@ -48,11 +48,4 @@ static const Uint32 MAX_BUFFER_SLOTS = DILIGENT_MAX_BUFFER_SLOTS;
static const Uint32 MAX_RENDER_TARGETS = DILIGENT_MAX_RENDER_TARGETS;
static const Uint32 MAX_VIEWPORTS = DILIGENT_MAX_VIEWPORTS;
-/// The maximum number of shader stages in a pipeline.
-/// (Vertex, Hull, Domain, Geometry, Pixel) or (Amplification, Mesh, Pixel), or (Compute) or (RayGen, Miss, ClosestHit, AnyHit, Intersection, Callable)
-static const Uint32 MAX_SHADERS_IN_PIPELINE = 6;
-
-/// The maximum number of resource signatures that one pipeline can use
-static const Uint32 MAX_RESOURCE_SIGNATURES = 8;
-
DILIGENT_END_NAMESPACE // namespace Diligent
diff --git a/Graphics/GraphicsEngine/interface/PipelineResourceSignature.h b/Graphics/GraphicsEngine/interface/PipelineResourceSignature.h
index 8959ced0..e7dfcb68 100644
--- a/Graphics/GraphicsEngine/interface/PipelineResourceSignature.h
+++ b/Graphics/GraphicsEngine/interface/PipelineResourceSignature.h
@@ -180,8 +180,13 @@ struct PipelineResourceSignatureDesc DILIGENT_DERIVE(DeviceObjectAttribs)
/// AZ TODO: comment
Uint16 BindingOffsets [SHADER_RESOURCE_TYPE_LAST + 1] DEFAULT_INITIALIZER({});
-
- // AZ TODO: add UseCombinedTextureSamplers back?
+ /// If set to true, textures will be combined with texture samplers.
+ /// The CombinedSamplerSuffix member defines the suffix added to the texture variable
+ /// name to get corresponding sampler name. When using combined samplers,
+ /// the sampler assigned to the shader resource view is automatically set when
+ /// the view is bound. Otherwise samplers need to be explicitly set similar to other
+ /// shader variables.
+ bool UseCombinedTextureSamplers DEFAULT_INITIALIZER(false);
/// If UseCombinedTextureSamplers is true, defines the suffix added to the
/// texture variable name to get corresponding sampler name. For example,
diff --git a/Graphics/GraphicsEngine/interface/ShaderResourceBinding.h b/Graphics/GraphicsEngine/interface/ShaderResourceBinding.h
index 8c7f006f..39815ade 100644
--- a/Graphics/GraphicsEngine/interface/ShaderResourceBinding.h
+++ b/Graphics/GraphicsEngine/interface/ShaderResourceBinding.h
@@ -122,7 +122,7 @@ DILIGENT_BEGIN_INTERFACE(IShaderResourceBinding, IObject)
/// Initializes static resources
- // Deprecated: use
+ // Deprecated: use InitializeStaticResourcesWithSignature()
/// If the parent pipeline state object contain static resources
/// (see Diligent::SHADER_RESOURCE_VARIABLE_TYPE_STATIC), this method must be called
diff --git a/Graphics/GraphicsEngine/src/PipelineResourceSignatureBase.cpp b/Graphics/GraphicsEngine/src/PipelineResourceSignatureBase.cpp
index ee597307..f2f64443 100644
--- a/Graphics/GraphicsEngine/src/PipelineResourceSignatureBase.cpp
+++ b/Graphics/GraphicsEngine/src/PipelineResourceSignatureBase.cpp
@@ -49,6 +49,23 @@ void ValidatePipelineResourceSignatureDesc(const PipelineResourceSignatureDesc&
if (Res.ArraySize == 0)
LOG_PRS_ERROR_AND_THROW("Desc.Resources[", i, "].ArraySize must not be 0");
+
+#ifdef DILIGENT_DEBUG
+ if ((Res.Flags & PIPELINE_RESOURCE_FLAG_NO_DYNAMIC_BUFFERS) &&
+ (Res.ResourceType != SHADER_RESOURCE_TYPE_CONSTANT_BUFFER &&
+ Res.ResourceType != SHADER_RESOURCE_TYPE_BUFFER_UAV &&
+ Res.ResourceType != SHADER_RESOURCE_TYPE_TEXTURE_SRV))
+ LOG_PRS_ERROR_AND_THROW("Desc.Resources[", i, "].Flags must not contains PIPELINE_RESOURCE_FLAG_NO_DYNAMIC_BUFFERS if ResourceType is not buffer");
+
+ if ((Res.Flags & PIPELINE_RESOURCE_FLAG_COMBINED_IMAGE) &&
+ Res.ResourceType != SHADER_RESOURCE_TYPE_TEXTURE_SRV)
+ LOG_PRS_ERROR_AND_THROW("Desc.Resources[", i, "].Flags must not contains PIPELINE_RESOURCE_FLAG_COMBINED_IMAGE if ResourceType is not SHADER_RESOURCE_TYPE_TEXTURE_SRV");
+
+ if ((Res.Flags & PIPELINE_RESOURCE_FLAG_FORMATTED_BUFFER) &&
+ (Res.ResourceType != SHADER_RESOURCE_TYPE_BUFFER_UAV &&
+ Res.ResourceType != SHADER_RESOURCE_TYPE_BUFFER_SRV))
+ LOG_PRS_ERROR_AND_THROW("Desc.Resources[", i, "].Flags must not contains PIPELINE_RESOURCE_FLAG_FORMATTED_BUFFER if ResourceType is not buffer");
+#endif
}
for (Uint32 i = 0; i < Desc.NumImmutableSamplers; ++i)