summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngine
diff options
context:
space:
mode:
authorassiduous <assiduous@diligentgraphics.com>2021-01-23 07:38:01 +0000
committerassiduous <assiduous@diligentgraphics.com>2021-01-23 07:38:01 +0000
commitb8caf2173c16d8ae4ac5fc5303a1e525ef56509c (patch)
treec902c3f249a968da521e005610b789bf323f73a8 /Graphics/GraphicsEngine
parentMerge branch 'azhirnov-res_layout' into resource_signature (diff)
downloadDiligentCore-b8caf2173c16d8ae4ac5fc5303a1e525ef56509c.tar.gz
DiligentCore-b8caf2173c16d8ae4ac5fc5303a1e525ef56509c.zip
Few updates to resource signature VK implementation
Diffstat (limited to 'Graphics/GraphicsEngine')
-rw-r--r--Graphics/GraphicsEngine/CMakeLists.txt1
-rw-r--r--Graphics/GraphicsEngine/include/PrivateConstants.h3
-rw-r--r--Graphics/GraphicsEngine/interface/Constants.h10
-rw-r--r--Graphics/GraphicsEngine/interface/PipelineResourceSignature.h70
-rw-r--r--Graphics/GraphicsEngine/src/PipelineResourceSignatureBase.cpp17
5 files changed, 72 insertions, 29 deletions
diff --git a/Graphics/GraphicsEngine/CMakeLists.txt b/Graphics/GraphicsEngine/CMakeLists.txt
index e3b99137..0cc1e740 100644
--- a/Graphics/GraphicsEngine/CMakeLists.txt
+++ b/Graphics/GraphicsEngine/CMakeLists.txt
@@ -15,6 +15,7 @@ set(INCLUDE
include/FenceBase.hpp
include/FramebufferBase.hpp
include/PipelineStateBase.hpp
+ include/PrivateConstants.h
include/QueryBase.hpp
include/RenderDeviceBase.hpp
include/RenderPassBase.hpp
diff --git a/Graphics/GraphicsEngine/include/PrivateConstants.h b/Graphics/GraphicsEngine/include/PrivateConstants.h
index 3c63a068..e84e7992 100644
--- a/Graphics/GraphicsEngine/include/PrivateConstants.h
+++ b/Graphics/GraphicsEngine/include/PrivateConstants.h
@@ -39,9 +39,6 @@ namespace Diligent
/// (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;
diff --git a/Graphics/GraphicsEngine/interface/Constants.h b/Graphics/GraphicsEngine/interface/Constants.h
index efb6ad0a..697ac8b5 100644
--- a/Graphics/GraphicsEngine/interface/Constants.h
+++ b/Graphics/GraphicsEngine/interface/Constants.h
@@ -44,8 +44,12 @@ DILIGENT_BEGIN_NAMESPACE(Diligent)
/// The maximum number of viewports.
#define DILIGENT_MAX_VIEWPORTS 16
-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 resource signatures that one pipeline can use
+#define DILIGENT_MAX_RESOURCE_SIGNATURES 8
+
+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;
+static const Uint32 MAX_RESOURCE_SIGNATURES = DILIGENT_MAX_RESOURCE_SIGNATURES;
DILIGENT_END_NAMESPACE // namespace Diligent
diff --git a/Graphics/GraphicsEngine/interface/PipelineResourceSignature.h b/Graphics/GraphicsEngine/interface/PipelineResourceSignature.h
index e7dfcb68..414add12 100644
--- a/Graphics/GraphicsEngine/interface/PipelineResourceSignature.h
+++ b/Graphics/GraphicsEngine/interface/PipelineResourceSignature.h
@@ -119,6 +119,9 @@ struct PipelineResourceDesc
/// Shader stages that this resource applies to. When multiple shader stages are specified,
/// all stages will share the same resource.
+ ///
+ /// \remarks There may be multiple resources with the same name in different shader stages,
+ /// but the stages specified for different resources with the same name must not overlap.
SHADER_TYPE ShaderStages DEFAULT_INITIALIZER(SHADER_TYPE_UNKNOWN);
/// Resource array size (must be 1 for non-array resources).
@@ -157,13 +160,13 @@ typedef struct PipelineResourceDesc PipelineResourceDesc;
/// Pipeline resource signature description.
struct PipelineResourceSignatureDesc DILIGENT_DERIVE(DeviceObjectAttribs)
- /// A pointer to array of resource descriptions. See Diligent::PipelineResourceDesc.
+ /// A pointer to an array of resource descriptions. See Diligent::PipelineResourceDesc.
const PipelineResourceDesc* Resources DEFAULT_INITIALIZER(nullptr);
/// The number of resources in Resources array.
Uint32 NumResources DEFAULT_INITIALIZER(0);
- /// A pointer to array of immutable samplers. See Diligent::ImmutableSamplerDesc.
+ /// A pointer to an array of immutable samplers. See Diligent::ImmutableSamplerDesc.
const ImmutableSamplerDesc* ImmutableSamplers DEFAULT_INITIALIZER(nullptr);
/// The number of immutable samplers in ImmutableSamplers array.
@@ -197,8 +200,8 @@ struct PipelineResourceSignatureDesc DILIGENT_DERIVE(DeviceObjectAttribs)
/// Shader resource binding allocation granularity
- /// This member defines allocation granularity for internal resources required by the shader resource
- /// binding object instances.
+ /// This member defines the allocation granularity for internal resources required by
+ /// the shader resource binding object instances.
Uint32 SRBAllocationGranularity DEFAULT_INITIALIZER(1);
};
typedef struct PipelineResourceSignatureDesc PipelineResourceSignatureDesc;
@@ -227,9 +230,9 @@ DILIGENT_BEGIN_INTERFACE(IPipelineResourceSignature, IDeviceObject)
/// Creates a shader resource binding object
- /// \param [out] ppShaderResourceBinding - memory location where pointer to the new shader resource
+ /// \param [out] ppShaderResourceBinding - Memory location where pointer to the new shader resource
/// binding object is written.
- /// \param [in] InitStaticResources - if set to true, the method will initialize static resources in
+ /// \param [in] InitStaticResources - If set to true, the method will initialize static resources in
/// the created object, which has the exact same effect as calling
/// IShaderResourceBinding::InitializeStaticResources().
VIRTUAL void METHOD(CreateShaderResourceBinding)(THIS_
@@ -237,12 +240,12 @@ DILIGENT_BEGIN_INTERFACE(IPipelineResourceSignature, IDeviceObject)
bool InitStaticResources DEFAULT_VALUE(false)) PURE;
- /// Binds static resources for all shaders in the pipeline resource signature
+ /// Binds static resources for the specified shader stages in the pipeline resource signature.
- /// \param [in] ShaderFlags - Flags that specify shader stages, for which resources will be bound.
- /// Any combination of Diligent::SHADER_TYPE may be used.
+ /// \param [in] ShaderFlags - Flags that specify shader stages, for which resources will be bound.
+ /// Any combination of Diligent::SHADER_TYPE may be used.
/// \param [in] pResourceMapping - Pointer to the resource mapping interface.
- /// \param [in] Flags - Additional flags. See Diligent::BIND_SHADER_RESOURCES_FLAGS.
+ /// \param [in] Flags - Additional flags. See Diligent::BIND_SHADER_RESOURCES_FLAGS.
VIRTUAL void METHOD(BindStaticResources)(THIS_
Uint32 ShaderFlags,
IResourceMapping* pResourceMapping,
@@ -254,9 +257,21 @@ DILIGENT_BEGIN_INTERFACE(IPipelineResourceSignature, IDeviceObject)
/// \param [in] ShaderType - Type of the shader to look up the variable.
/// Must be one of Diligent::SHADER_TYPE.
- /// \param [in] Name - Name of the variable.
- /// \remark The method does not increment the reference counter
- /// of the returned interface.
+ /// \param [in] Name - Name of the variable.
+ ///
+ /// \remarks If a variable is shared between multiple shader stages,
+ /// it can be accessed using any of those shader stages. Even
+ /// though IShaderResourceVariable instances returned by the method
+ /// may be different for different stages, internally they will
+ /// reference the same resource.
+ ///
+ /// Only static shader resource variables can be accessed using this method.
+ /// Mutable and dynamic variables are accessed through Shader Resource
+ /// Binding object.
+ ///
+ /// The method does not increment the reference counter of the
+ /// returned interface, and the application must *not* call Release()
+ /// unless it explicitly called AddRef().
VIRTUAL IShaderResourceVariable* METHOD(GetStaticVariableByName)(THIS_
SHADER_TYPE ShaderType,
const Char* Name) PURE;
@@ -266,12 +281,24 @@ DILIGENT_BEGIN_INTERFACE(IPipelineResourceSignature, IDeviceObject)
/// \param [in] ShaderType - Type of the shader to look up the variable.
/// Must be one of Diligent::SHADER_TYPE.
- /// \param [in] Index - Shader variable index. The index must be between
- /// 0 and the total number of variables returned by
- /// GetStaticVariableCount().
- /// \remark Only static shader resource variables can be accessed through this method.
- /// Mutable and dynamic variables are accessed through Shader Resource
- /// Binding object
+ /// \param [in] Index - Shader variable index. The index must be between
+ /// 0 and the total number of variables returned by
+ /// GetStaticVariableCount().
+ ///
+ ///
+ /// \remarks If a variable is shared between multiple shader stages,
+ /// it can be accessed using any of those shader stages. Even
+ /// though IShaderResourceVariable instances returned by the method
+ /// may be different for different stages, internally they will
+ /// reference the same resource.
+ ///
+ /// Only static shader resource variables can be accessed using this method.
+ /// Mutable and dynamic variables are accessed through Shader Resource
+ /// Binding object.
+ ///
+ /// The method does not increment the reference counter of the
+ /// returned interface, and the application must *not* call Release()
+ /// unless it explicitly called AddRef().
VIRTUAL IShaderResourceVariable* METHOD(GetStaticVariableByIndex)(THIS_
SHADER_TYPE ShaderType,
Uint32 Index) PURE;
@@ -280,8 +307,9 @@ DILIGENT_BEGIN_INTERFACE(IPipelineResourceSignature, IDeviceObject)
/// Returns the number of static shader resource variables.
/// \param [in] ShaderType - Type of the shader.
- /// \remark Only static variables (that can be accessed directly through the PSO) are counted.
- /// Mutable and dynamic variables are accessed through Shader Resource Binding object.
+ ///
+ /// \remarks Only static variables (that can be accessed directly through the PSO) are counted.
+ /// Mutable and dynamic variables are accessed through Shader Resource Binding object.
VIRTUAL Uint32 METHOD(GetStaticVariableCount)(THIS_
SHADER_TYPE ShaderType) CONST PURE;
diff --git a/Graphics/GraphicsEngine/src/PipelineResourceSignatureBase.cpp b/Graphics/GraphicsEngine/src/PipelineResourceSignatureBase.cpp
index f2f64443..9e51a93f 100644
--- a/Graphics/GraphicsEngine/src/PipelineResourceSignatureBase.cpp
+++ b/Graphics/GraphicsEngine/src/PipelineResourceSignatureBase.cpp
@@ -27,6 +27,10 @@
#include "PipelineResourceSignatureBase.hpp"
+#include <unordered_map>
+
+#include "HashUtils.hpp"
+
namespace Diligent
{
@@ -37,6 +41,8 @@ void ValidatePipelineResourceSignatureDesc(const PipelineResourceSignatureDesc&
if (Desc.BindingIndex >= MAX_RESOURCE_SIGNATURES)
LOG_PRS_ERROR_AND_THROW("Desc.BindingIndex (", Desc.BindingIndex, ") exceeds the maximum allowed value (", MAX_RESOURCE_SIGNATURES - 1, ").");
+ std::unordered_map<HashMapStringKey, SHADER_TYPE, HashMapStringKey::Hasher> ResourceShaderStages;
+
for (Uint32 i = 0; i < Desc.NumResources; ++i)
{
const auto& Res = Desc.Resources[i];
@@ -50,7 +56,15 @@ void ValidatePipelineResourceSignatureDesc(const PipelineResourceSignatureDesc&
if (Res.ArraySize == 0)
LOG_PRS_ERROR_AND_THROW("Desc.Resources[", i, "].ArraySize must not be 0");
-#ifdef DILIGENT_DEBUG
+ auto& UsedStages = ResourceShaderStages[Res.Name];
+ if ((UsedStages & Res.ShaderStages) != 0)
+ {
+ LOG_PRS_ERROR_AND_THROW("Multiple resources with name '", Res.Name,
+ "' specify overlapping shader stages. There may be multiple resources with the same name in different shader stages, "
+ "but the stages specified for different resources with the same name must not overlap.");
+ }
+ UsedStages |= Res.ShaderStages;
+
if ((Res.Flags & PIPELINE_RESOURCE_FLAG_NO_DYNAMIC_BUFFERS) &&
(Res.ResourceType != SHADER_RESOURCE_TYPE_CONSTANT_BUFFER &&
Res.ResourceType != SHADER_RESOURCE_TYPE_BUFFER_UAV &&
@@ -65,7 +79,6 @@ void ValidatePipelineResourceSignatureDesc(const PipelineResourceSignatureDesc&
(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)