summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngine
diff options
context:
space:
mode:
authorassiduous <assiduous@diligentgraphics.com>2021-01-21 06:53:31 +0000
committerassiduous <assiduous@diligentgraphics.com>2021-01-21 06:53:31 +0000
commit48749b2a7ab458a5f0a80b6c471faea8c314c494 (patch)
tree0d32ab5706642927efccb68fdebdc6e546f04dfe /Graphics/GraphicsEngine
parentFew updates to readme (diff)
downloadDiligentCore-48749b2a7ab458a5f0a80b6c471faea8c314c494.tar.gz
DiligentCore-48749b2a7ab458a5f0a80b6c471faea8c314c494.zip
Some code clean-up
Diffstat (limited to 'Graphics/GraphicsEngine')
-rw-r--r--Graphics/GraphicsEngine/CMakeLists.txt1
-rw-r--r--Graphics/GraphicsEngine/include/PipelineResourceSignatureBase.hpp39
-rw-r--r--Graphics/GraphicsEngine/interface/Constants.h13
-rw-r--r--Graphics/GraphicsEngine/interface/PipelineResourceSignature.h69
-rw-r--r--Graphics/GraphicsEngine/src/PipelineResourceSignatureBase.cpp61
5 files changed, 137 insertions, 46 deletions
diff --git a/Graphics/GraphicsEngine/CMakeLists.txt b/Graphics/GraphicsEngine/CMakeLists.txt
index 0e47e286..e3b99137 100644
--- a/Graphics/GraphicsEngine/CMakeLists.txt
+++ b/Graphics/GraphicsEngine/CMakeLists.txt
@@ -75,6 +75,7 @@ set(SOURCE
src/DeviceContextBase.cpp
src/EngineMemory.cpp
src/FramebufferBase.cpp
+ src/PipelineResourceSignatureBase.cpp
src/PipelineStateBase.cpp
src/ResourceMappingBase.cpp
src/ShaderBindingTableBase.cpp
diff --git a/Graphics/GraphicsEngine/include/PipelineResourceSignatureBase.hpp b/Graphics/GraphicsEngine/include/PipelineResourceSignatureBase.hpp
index 20b2b563..a5cbf71b 100644
--- a/Graphics/GraphicsEngine/include/PipelineResourceSignatureBase.hpp
+++ b/Graphics/GraphicsEngine/include/PipelineResourceSignatureBase.hpp
@@ -40,6 +40,8 @@
namespace Diligent
{
+void ValidatePipelineResourceSignatureDesc(const PipelineResourceSignatureDesc& Desc) noexcept(false);
+
/// Template class implementing base functionality of the pipeline resource signature object.
/// \tparam BaseInterface - Base interface that this class will inheret
@@ -52,10 +54,10 @@ class PipelineResourceSignatureBase : public DeviceObjectBase<BaseInterface, Ren
public:
using TDeviceObjectBase = DeviceObjectBase<BaseInterface, RenderDeviceImplType, PipelineResourceSignatureDesc>;
- /// \param pRefCounters - Reference counters object that controls the lifetime of this BLAS.
+ /// \param pRefCounters - Reference counters object that controls the lifetime of this resource signature.
/// \param pDevice - Pointer to the device.
- /// \param Desc - TLAS description.
- /// \param bIsDeviceInternal - Flag indicating if the BLAS is an internal device object and
+ /// \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.
PipelineResourceSignatureBase(IReferenceCounters* pRefCounters,
RenderDeviceImplType* pDevice,
@@ -66,6 +68,16 @@ public:
this->m_Desc.Resources = nullptr;
this->m_Desc.ImmutableSamplers = nullptr;
this->m_Desc.CombinedSamplerSuffix = nullptr;
+
+ try
+ {
+ ValidatePipelineResourceSignatureDesc(Desc);
+ }
+ catch (...)
+ {
+ Destruct();
+ throw;
+ }
}
~PipelineResourceSignatureBase()
@@ -85,8 +97,6 @@ public:
bool IsUsingSeparateSamplers() const { return !IsUsingCombinedSamplers(); }
protected:
-#define LOG_PRS_ERROR_AND_THROW(...) LOG_ERROR_AND_THROW("Description of a pipeline resource signature '", (Desc.Name ? Desc.Name : ""), "' is invalid: ", ##__VA_ARGS__)
-
void ReserveSpaceForDescription(FixedLinearAllocator& Allocator, const PipelineResourceSignatureDesc& Desc) const noexcept(false)
{
Allocator.AddSpace<PipelineResourceDesc>(Desc.NumResources);
@@ -96,22 +106,17 @@ protected:
{
const auto& Res = Desc.Resources[i];
- if (Res.Name == nullptr)
- LOG_PRS_ERROR_AND_THROW("AZ TODO");
-
- if (Res.ShaderStages == SHADER_TYPE_UNKNOWN)
- LOG_PRS_ERROR_AND_THROW("AZ TODO");
-
- if (Res.ArraySize == 0)
- LOG_PRS_ERROR_AND_THROW("AZ TODO");
+ VERIFY(Res.Name != nullptr, "Name can't be null. This error should've been caught by ValidatePipelineResourceSignatureDesc.");
+ VERIFY(Res.ShaderStages != SHADER_TYPE_UNKNOWN, "ShaderStages can't be SHADER_TYPE_UNKNOWN. This error should've been caught by ValidatePipelineResourceSignatureDesc.");
+ VERIFY(Res.ArraySize != 0, "ArraySize can't be 0. This error should've been caught by ValidatePipelineResourceSignatureDesc.");
Allocator.AddSpaceForString(Res.Name);
}
for (Uint32 i = 0; i < Desc.NumImmutableSamplers; ++i)
{
- if (Desc.ImmutableSamplers[i].SamplerOrTextureName == nullptr)
- LOG_PRS_ERROR_AND_THROW("AZ TODO");
+ VERIFY(Desc.ImmutableSamplers[i].SamplerOrTextureName != nullptr,
+ "SamplerOrTextureName can't be null. This error should've been caught by ValidatePipelineResourceSignatureDesc.");
Allocator.AddSpaceForString(Desc.ImmutableSamplers[i].SamplerOrTextureName);
}
@@ -162,8 +167,6 @@ protected:
#endif
}
-#undef LOG_PRS_ERROR_AND_THROW
-
Int8 GetStaticVariableCountHelper(SHADER_TYPE ShaderType, const std::array<Int8, MAX_SHADERS_IN_PIPELINE>& StaticVarIndex) const
{
if (!IsConsistentShaderType(ShaderType, m_PipelineType))
@@ -227,7 +230,7 @@ protected:
protected:
size_t m_Hash = 0;
- PIPELINE_TYPE m_PipelineType = PIPELINE_TYPE(0xFF);
+ PIPELINE_TYPE m_PipelineType = static_cast<PIPELINE_TYPE>(0xFF);
#ifdef DILIGENT_DEBUG
bool m_IsDestructed = false;
diff --git a/Graphics/GraphicsEngine/interface/Constants.h b/Graphics/GraphicsEngine/interface/Constants.h
index e91cbdad..3f290303 100644
--- a/Graphics/GraphicsEngine/interface/Constants.h
+++ b/Graphics/GraphicsEngine/interface/Constants.h
@@ -34,28 +34,25 @@
DILIGENT_BEGIN_NAMESPACE(Diligent)
-// clang-format off
-
-/// Maximum number of input buffer slots.
+/// The maximum number of input buffer slots.
/// D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT == 32
#define DILIGENT_MAX_BUFFER_SLOTS 32
-/// Maximum number of simultaneous render targets.
+/// The maximum number of simultaneous render targets.
#define DILIGENT_MAX_RENDER_TARGETS 8
-/// Maximum number of viewports.
+/// 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;
-/// Maximum number of shader stages in a pipeline.
+/// 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;
-// clang-format on
-
DILIGENT_END_NAMESPACE // namespace Diligent
diff --git a/Graphics/GraphicsEngine/interface/PipelineResourceSignature.h b/Graphics/GraphicsEngine/interface/PipelineResourceSignature.h
index 4406e004..1eab00d2 100644
--- a/Graphics/GraphicsEngine/interface/PipelineResourceSignature.h
+++ b/Graphics/GraphicsEngine/interface/PipelineResourceSignature.h
@@ -30,7 +30,7 @@
// clang-format off
/// \file
-/// Definition of the Diligent::IRenderDevice interface and related data structures
+/// Definition of the Diligent::IPipelineResourceSignature interface and related data structures
#include "../../../Primitives/interface/Object.h"
#include "../../../Platforms/interface/PlatformDefinitions.h"
@@ -75,36 +75,62 @@ struct ImmutableSamplerDesc
typedef struct ImmutableSamplerDesc ImmutableSamplerDesc;
-/// AZ TODO: comment
+/// Flags that define pipeline resource properties
DILIGENT_TYPED_ENUM(PIPELINE_RESOURCE_FLAGS, Uint8)
{
+ /// Resource has no special properties
PIPELINE_RESOURCE_FLAG_UNKNOWN = 0x00,
- PIPELINE_RESOURCE_FLAG_NO_DYNAMIC_OFFSETS = 0x01, ///< Vulkan only, for SHADER_RESOURCE_TYPE_CONSTANT_BUFFER, SHADER_RESOURCE_TYPE_BUFFER_UAV, SHADER_RESOURCE_TYPE_BUFFER_SRV
- PIPELINE_RESOURCE_FLAG_COMBINED_IMAGE = 0x02, ///< For SHADER_RESOURCE_TYPE_TEXTURE_SRV
- PIPELINE_RESOURCE_FLAG_TEXEL_BUFFER = 0x04, ///< For SHADER_RESOURCE_TYPE_BUFFER_UAV, SHADER_RESOURCE_TYPE_BUFFER_SRV
+
+ /// Indicates that dynamic buffers will never be bound to the resource
+ /// variable. Applies to SHADER_RESOURCE_TYPE_CONSTANT_BUFFER,
+ /// SHADER_RESOURCE_TYPE_BUFFER_UAV, SHADER_RESOURCE_TYPE_BUFFER_SRV resources.
+ ///
+ /// \remarks In Vulkan and Direct3D12 backends, dynamic buffers require extra work
+ /// at run time. If an application knows it will never bind a dynamic buffer to
+ /// the variable, it should use PIPELINE_RESOURCE_FLAG_NO_DYNAMIC_BUFFERS flag
+ /// to improve performance. This flag is not required and non-dynamic buffers
+ /// will still work even if the flag is not used. It is an error to bind a
+ /// dynamic buffer to resource that uses
+ /// PIPELINE_RESOURCE_FLAG_NO_DYNAMIC_BUFFERS flag.
+ PIPELINE_RESOURCE_FLAG_NO_DYNAMIC_BUFFERS = 0x01,
+
+ /// Indicates that a texture SRV will be combined with a sampler.
+ /// Applies to SHADER_RESOURCE_TYPE_TEXTURE_SRV resources.
+ PIPELINE_RESOURCE_FLAG_COMBINED_IMAGE = 0x02,
+
+ /// Indicates that this variable will be used to bind formatted buffers.
+ /// Applies to SHADER_RESOURCE_TYPE_BUFFER_UAV and SHADER_RESOURCE_TYPE_BUFFER_SRV
+ /// resources.
+ ///
+ /// \remarks In Vulkan backend formatted buffers require another descriptor type
+ /// as opposed to structured buffers. If an application will be using
+ /// formatted buffers with buffer UAVs and SRVs, it must specify the
+ /// PIPELINE_RESOURCE_FLAG_FORMATTED_BUFFER flag.
+ PIPELINE_RESOURCE_FLAG_FORMATTED_BUFFER = 0x04
};
DEFINE_FLAG_ENUM_OPERATORS(PIPELINE_RESOURCE_FLAGS);
-/// AZ TODO: comment
+/// Pipeline resource description.
struct PipelineResourceDesc
{
- /// AZ TODO: comment
+ /// Resource name in the shader
const char* Name DEFAULT_INITIALIZER(nullptr);
- /// AZ TODO: comment
+ /// Shader stages that this resource applies to. When multiple shader stages are specified,
+ /// all stages will share the same resource.
SHADER_TYPE ShaderStages DEFAULT_INITIALIZER(SHADER_TYPE_UNKNOWN);
- /// AZ TODO: comment
+ /// Resource array size (must be 1 for non-array resources).
Uint32 ArraySize DEFAULT_INITIALIZER(1);
- /// AZ TODO: comment
+ /// Resource type, see Diligent::SHADER_RESOURCE_TYPE.
SHADER_RESOURCE_TYPE ResourceType DEFAULT_INITIALIZER(SHADER_RESOURCE_TYPE_UNKNOWN);
- /// AZ TODO: comment
+ /// Resource variable type, see Diligent::SHADER_RESOURCE_VARIABLE_TYPE.
SHADER_RESOURCE_VARIABLE_TYPE VarType DEFAULT_INITIALIZER(SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE);
- /// AZ TODO: comment
+ /// Special resource flags, see Diligent::PIPELINE_RESOURCE_FLAGS.
PIPELINE_RESOURCE_FLAGS Flags DEFAULT_INITIALIZER(PIPELINE_RESOURCE_FLAG_UNKNOWN);
#if DILIGENT_CPP_INTERFACE
@@ -128,19 +154,19 @@ struct PipelineResourceDesc
typedef struct PipelineResourceDesc PipelineResourceDesc;
-/// AZ TODO: comment
+/// Pipeline resource signature description.
struct PipelineResourceSignatureDesc DILIGENT_DERIVE(DeviceObjectAttribs)
- /// AZ TODO: comment
+ /// A pointer to array of resource descriptions. See Diligent::PipelineResourceDesc.
const PipelineResourceDesc* Resources DEFAULT_INITIALIZER(nullptr);
- /// AZ TODO: comment
+ /// The number of resources in Resources array.
Uint32 NumResources DEFAULT_INITIALIZER(0);
- /// AZ TODO: comment
+ /// A pointer to array of immutable samplers. See Diligent::ImmutableSamplerDesc.
const ImmutableSamplerDesc* ImmutableSamplers DEFAULT_INITIALIZER(nullptr);
- /// AZ TODO: comment
+ /// The number of immutable samplers in ImmutableSamplers array.
Uint32 NumImmutableSamplers DEFAULT_INITIALIZER(0);
/// AZ TODO: comment
@@ -149,6 +175,9 @@ struct PipelineResourceSignatureDesc DILIGENT_DERIVE(DeviceObjectAttribs)
/// AZ TODO: comment
Uint16 BindingOffsets [SHADER_RESOURCE_TYPE_LAST + 1] DEFAULT_INITIALIZER({});
+
+ // AZ TODO: add UseCombinedTextureSamplers back?
+
/// If UseCombinedTextureSamplers is true, defines the suffix added to the
/// texture variable name to get corresponding sampler name. For example,
/// for default value "_sampler", a texture named "tex" will be combined
@@ -178,11 +207,11 @@ static const INTERFACE_ID IID_PipelineResourceSignature =
// clang-format off
-/// Pipeline state interface
+/// Pipeline resource signature interface
DILIGENT_BEGIN_INTERFACE(IPipelineResourceSignature, IDeviceObject)
{
#if DILIGENT_CPP_INTERFACE
- /// AZ TODO: comment
+ /// Returns the pipeline resource signature description, see Diligent::PipelineResourceSignatureDesc.
virtual const PipelineResourceSignatureDesc& METHOD(GetDesc)() const override = 0;
#endif
@@ -198,7 +227,7 @@ DILIGENT_BEGIN_INTERFACE(IPipelineResourceSignature, IDeviceObject)
bool InitStaticResources DEFAULT_VALUE(false)) PURE;
- /// Binds resources for all shaders in the pipeline resource signature
+ /// Binds static resources for all shaders 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.
diff --git a/Graphics/GraphicsEngine/src/PipelineResourceSignatureBase.cpp b/Graphics/GraphicsEngine/src/PipelineResourceSignatureBase.cpp
new file mode 100644
index 00000000..4a880300
--- /dev/null
+++ b/Graphics/GraphicsEngine/src/PipelineResourceSignatureBase.cpp
@@ -0,0 +1,61 @@
+/*
+ * 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.
+ */
+
+#include "PipelineResourceSignatureBase.hpp"
+
+namespace Diligent
+{
+
+#define LOG_PRS_ERROR_AND_THROW(...) LOG_ERROR_AND_THROW("Description of a pipeline resource signature '", (Desc.Name ? Desc.Name : ""), "' is invalid: ", ##__VA_ARGS__)
+
+void ValidatePipelineResourceSignatureDesc(const PipelineResourceSignatureDesc& Desc) noexcept(false)
+{
+ for (Uint32 i = 0; i < Desc.NumResources; ++i)
+ {
+ const auto& Res = Desc.Resources[i];
+
+ if (Res.Name == nullptr)
+ LOG_PRS_ERROR_AND_THROW("Desc.Resources[", i, "].Name must not be null");
+
+ if (Res.ShaderStages == SHADER_TYPE_UNKNOWN)
+ LOG_PRS_ERROR_AND_THROW("Desc.Resources[", i, "].ShaderStages must not be SHADER_TYPE_UNKNOWN");
+
+ if (Res.ArraySize == 0)
+ LOG_PRS_ERROR_AND_THROW("Desc.Resources[", i, "].ArraySize must not be 0");
+ }
+
+ for (Uint32 i = 0; i < Desc.NumImmutableSamplers; ++i)
+ {
+ if (Desc.ImmutableSamplers[i].SamplerOrTextureName == nullptr)
+ LOG_PRS_ERROR_AND_THROW("Desc.ImmutableSamplers[", i, "].SamplerOrTextureName must not be null");
+ }
+}
+
+#undef LOG_PRS_ERROR_AND_THROW
+
+
+} // namespace Diligent