summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineVulkan
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/GraphicsEngineVulkan
parentFew updates to readme (diff)
downloadDiligentCore-48749b2a7ab458a5f0a80b6c471faea8c314c494.tar.gz
DiligentCore-48749b2a7ab458a5f0a80b6c471faea8c314c494.zip
Some code clean-up
Diffstat (limited to 'Graphics/GraphicsEngineVulkan')
-rw-r--r--Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp16
-rw-r--r--Graphics/GraphicsEngineVulkan/include/PipelineLayoutVk.hpp4
-rw-r--r--Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp30
-rw-r--r--Graphics/GraphicsEngineVulkan/src/PipelineResourceSignatureVkImpl.cpp10
-rw-r--r--Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp4
5 files changed, 39 insertions, 25 deletions
diff --git a/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp
index 4e6d2b30..b5797361 100644
--- a/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp
+++ b/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp
@@ -476,10 +476,10 @@ private:
Uint32 NumCommands = 0;
} m_State;
- // graphics, compute, ray tracing
- static constexpr Uint32 PIPELINE_BIND_POINTS = 3;
+ // Graphics/mesh, compute, ray tracing
+ static constexpr Uint32 NUM_PIPELINE_BIND_POINTS = 3;
- // static and dynamic descriptor sets
+ // Static/mutable and dynamic descriptor sets
static constexpr Uint32 MAX_DESCR_SET_PER_SIGNATURE = 2;
struct DescriptorSetBindInfo
@@ -490,9 +490,9 @@ private:
ShaderResourceArray Resources;
VkDescSetArray vkSets = {};
- BoolArray PendingVkSet = {0}; // 'true' if new descriptor set must be bound
- BoolArray PendingDynamicDescriptors = {0}; // 'true' if dynamic descriptor set must be bound
- BoolArray DynamicBuffersPresent = {0};
+ BoolArray PendingVkSet = {}; // 'true' if new descriptor set must be bound
+ BoolArray PendingDynamicDescriptors = {}; // 'true' if dynamic descriptor set must be bound
+ BoolArray DynamicBuffersPresent = {};
DescriptorSetBindInfo()
{}
@@ -519,8 +519,8 @@ private:
void BindDescriptorSetsWithDynamicOffsets(DescriptorSetBindInfo& DescrSetBindInfo);
void ValidateShaderResources();
- /// AZ TODO: comment
- std::array<DescriptorSetBindInfo, PIPELINE_BIND_POINTS> m_DescrSetBindInfo;
+ /// Descriptor set binding information for each pipeline type (graphics/mesh, compute, ray tracing)
+ std::array<DescriptorSetBindInfo, NUM_PIPELINE_BIND_POINTS> m_DescrSetBindInfo;
/// AZ TODO: comment
std::vector<Uint32> m_DynamicBufferOffsets;
diff --git a/Graphics/GraphicsEngineVulkan/include/PipelineLayoutVk.hpp b/Graphics/GraphicsEngineVulkan/include/PipelineLayoutVk.hpp
index cbc654b7..d6b4c922 100644
--- a/Graphics/GraphicsEngineVulkan/include/PipelineLayoutVk.hpp
+++ b/Graphics/GraphicsEngineVulkan/include/PipelineLayoutVk.hpp
@@ -90,10 +90,10 @@ private:
Uint32 m_DynamicOffsetCount : 25;
Uint32 m_SignatureCount : 3;
- static_assert(MAX_RESOURCE_SIGNATURES == (1 << 3), "update m_SignatureCount bits count");
+ static_assert(MAX_RESOURCE_SIGNATURES == (1 << 3), "Update m_SignatureCount bits count");
Uint32 m_DescrSetCount : 4;
- static_assert(MAX_RESOURCE_SIGNATURES * 2 == (1 << 4), "update m_DescrSetCount bits count");
+ static_assert(MAX_RESOURCE_SIGNATURES * 2 == (1 << 4), "Update m_DescrSetCount bits count");
using SignatureArray = std::array<RefCntAutoPtr<PipelineResourceSignatureVkImpl>, MAX_RESOURCE_SIGNATURES>;
using DescSetOffsetArray = std::array<Uint8, MAX_RESOURCE_SIGNATURES>;
diff --git a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp
index 958a5e80..19bbd91a 100644
--- a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp
@@ -314,26 +314,38 @@ void DeviceContextVkImpl::SetPipelineState(IPipelineState* pPipelineState)
static Uint32 PipelineTypeToBindPointIndex(PIPELINE_TYPE Type)
{
- const Uint8 Indices[] = {
+ // clang-format off
+ static_assert(PIPELINE_TYPE_GRAPHICS == 0, "PIPELINE_TYPE_GRAPHICS == 0 is expected");
+ static_assert(PIPELINE_TYPE_COMPUTE == 1, "PIPELINE_TYPE_COMPUTE == 1 is expected");
+ static_assert(PIPELINE_TYPE_MESH == 2, "PIPELINE_TYPE_MESH == 2 is expected");
+ static_assert(PIPELINE_TYPE_RAY_TRACING == 3, "PIPELINE_TYPE_RAY_TRACING == 3 is expected");
+ // clang-format on
+ constexpr Uint8 Indices[] = {
0, // PIPELINE_TYPE_GRAPHICS
1, // PIPELINE_TYPE_COMPUTE
0, // PIPELINE_TYPE_MESH
2 // PIPELINE_TYPE_RAY_TRACING
};
- static_assert(_countof(Indices) == Uint32{PIPELINE_TYPE_LAST} + 1, "AZ TODO");
+ static_assert(_countof(Indices) == Uint32{PIPELINE_TYPE_LAST} + 1, "Please add the new pipeline type to the list above");
return Indices[Uint32{Type}];
}
-static VkPipelineBindPoint PipelineTypeToBindPoint(PIPELINE_TYPE Type)
+static VkPipelineBindPoint PipelineTypeToVkBindPoint(PIPELINE_TYPE Type)
{
- const VkPipelineBindPoint BindPoints[] = {
+ // clang-format off
+ static_assert(PIPELINE_TYPE_GRAPHICS == 0, "PIPELINE_TYPE_GRAPHICS == 0 is expected");
+ static_assert(PIPELINE_TYPE_COMPUTE == 1, "PIPELINE_TYPE_COMPUTE == 1 is expected");
+ static_assert(PIPELINE_TYPE_MESH == 2, "PIPELINE_TYPE_MESH == 2 is expected");
+ static_assert(PIPELINE_TYPE_RAY_TRACING == 3, "PIPELINE_TYPE_RAY_TRACING == 3 is expected");
+ // clang-format on
+ const VkPipelineBindPoint vkBindPoints[] = {
VK_PIPELINE_BIND_POINT_GRAPHICS, // PIPELINE_TYPE_GRAPHICS
VK_PIPELINE_BIND_POINT_COMPUTE, // PIPELINE_TYPE_COMPUTE
VK_PIPELINE_BIND_POINT_GRAPHICS, // PIPELINE_TYPE_MESH
VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR // PIPELINE_TYPE_RAY_TRACING
};
- static_assert(_countof(BindPoints) == Uint32{PIPELINE_TYPE_LAST} + 1, "AZ TODO");
- return BindPoints[Uint32{Type}];
+ static_assert(_countof(vkBindPoints) == Uint32{PIPELINE_TYPE_LAST} + 1, "Please add the new pipeline type to the list above");
+ return vkBindPoints[Uint32{Type}];
}
void DeviceContextVkImpl::BindShaderResources(PipelineStateVkImpl* pPipelineStateVk)
@@ -344,7 +356,6 @@ void DeviceContextVkImpl::BindShaderResources(PipelineStateVkImpl* pPipelineStat
const auto BindIndex = PipelineTypeToBindPointIndex(pPipelineStateVk->GetDesc().PipelineType);
auto& BindInfo = m_DescrSetBindInfo[BindIndex];
auto& Resources = BindInfo.Resources;
- const auto BindPoint = PipelineTypeToBindPoint(pPipelineStateVk->GetDesc().PipelineType);
const auto SignCount = Layout.GetSignatureCount();
Uint32 CompatSignCount = SignCount;
@@ -355,6 +366,9 @@ void DeviceContextVkImpl::BindShaderResources(PipelineStateVkImpl* pPipelineStat
// (14.2.2. Pipeline Layouts, clause 'Pipeline Layout Compatibility')
// https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#descriptorsets-compatibility
+ // AZ TODO: do we need to unbind incompatible descriptor sets here or
+ // should the user handle this?
+
// unbind incompatible descriptor sets
for (Uint32 i = 0; i < SignCount; ++i)
{
@@ -390,7 +404,7 @@ void DeviceContextVkImpl::BindDescriptorSetsWithDynamicOffsets(DescriptorSetBind
const auto& Layout = pPipelineStateVk->GetPipelineLayout();
const auto BindIndex = PipelineTypeToBindPointIndex(pPipelineStateVk->GetDesc().PipelineType);
auto& Resources = BindInfo.Resources;
- const auto BindPoint = PipelineTypeToBindPoint(pPipelineStateVk->GetDesc().PipelineType);
+ const auto BindPoint = PipelineTypeToVkBindPoint(pPipelineStateVk->GetDesc().PipelineType);
const auto SignCount = Layout.GetSignatureCount();
auto& Offsets = m_DynamicBufferOffsets;
const auto VkLayout = Layout.GetVkPipelineLayout();
diff --git a/Graphics/GraphicsEngineVulkan/src/PipelineResourceSignatureVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/PipelineResourceSignatureVkImpl.cpp
index 8513a161..2bcafcf1 100644
--- a/Graphics/GraphicsEngineVulkan/src/PipelineResourceSignatureVkImpl.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/PipelineResourceSignatureVkImpl.cpp
@@ -71,19 +71,19 @@ VkDescriptorType GetVkDescriptorType(DescriptorType Type)
DescriptorType GetDescriptorType(const PipelineResourceDesc& Res)
{
- const bool WithDynamicOffset = !(Res.Flags & PIPELINE_RESOURCE_FLAG_NO_DYNAMIC_OFFSETS);
+ const bool WithDynamicOffset = !(Res.Flags & PIPELINE_RESOURCE_FLAG_NO_DYNAMIC_BUFFERS);
const bool CombinedSampler = (Res.Flags & PIPELINE_RESOURCE_FLAG_COMBINED_IMAGE);
- const bool UseTexelBuffer = (Res.Flags & PIPELINE_RESOURCE_FLAG_TEXEL_BUFFER);
+ const bool UseTexelBuffer = (Res.Flags & PIPELINE_RESOURCE_FLAG_FORMATTED_BUFFER);
static_assert(SHADER_RESOURCE_TYPE_LAST == SHADER_RESOURCE_TYPE_ACCEL_STRUCT, "Please update the switch below to handle the new shader resource type");
switch (Res.ResourceType)
{
case SHADER_RESOURCE_TYPE_CONSTANT_BUFFER:
- VERIFY_EXPR(!(Res.Flags & ~PIPELINE_RESOURCE_FLAG_NO_DYNAMIC_OFFSETS));
+ VERIFY_EXPR(!(Res.Flags & ~PIPELINE_RESOURCE_FLAG_NO_DYNAMIC_BUFFERS));
return WithDynamicOffset ? DescriptorType::UniformBufferDynamic : DescriptorType::UniformBuffer;
case SHADER_RESOURCE_TYPE_BUFFER_UAV:
- VERIFY_EXPR(!(Res.Flags & ~(PIPELINE_RESOURCE_FLAG_NO_DYNAMIC_OFFSETS | PIPELINE_RESOURCE_FLAG_TEXEL_BUFFER)));
+ VERIFY_EXPR(!(Res.Flags & ~(PIPELINE_RESOURCE_FLAG_NO_DYNAMIC_BUFFERS | PIPELINE_RESOURCE_FLAG_FORMATTED_BUFFER)));
return UseTexelBuffer ? DescriptorType::StorageTexelBuffer :
(WithDynamicOffset ? DescriptorType::StorageBufferDynamic : DescriptorType::StorageBuffer);
@@ -92,7 +92,7 @@ DescriptorType GetDescriptorType(const PipelineResourceDesc& Res)
return CombinedSampler ? DescriptorType::CombinedImageSampler : DescriptorType::SeparateImage;
case SHADER_RESOURCE_TYPE_BUFFER_SRV:
- VERIFY_EXPR(!(Res.Flags & ~(PIPELINE_RESOURCE_FLAG_NO_DYNAMIC_OFFSETS | PIPELINE_RESOURCE_FLAG_TEXEL_BUFFER)));
+ VERIFY_EXPR(!(Res.Flags & ~(PIPELINE_RESOURCE_FLAG_NO_DYNAMIC_BUFFERS | PIPELINE_RESOURCE_FLAG_FORMATTED_BUFFER)));
return UseTexelBuffer ? DescriptorType::UniformTexelBuffer :
(WithDynamicOffset ? DescriptorType::StorageBufferDynamic_ReadOnly : DescriptorType::StorageBuffer_ReadOnly);
diff --git a/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp
index 736154a5..b92c94f4 100644
--- a/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp
@@ -526,12 +526,12 @@ void GetShaderResourceTypeAndFlags(SPIRVShaderResourceAttribs::ResourceType Type
case SPIRVShaderResourceAttribs::ResourceType::UniformTexelBuffer:
OutType = SHADER_RESOURCE_TYPE_BUFFER_SRV;
- OutFlags = PIPELINE_RESOURCE_FLAG_TEXEL_BUFFER;
+ OutFlags = PIPELINE_RESOURCE_FLAG_FORMATTED_BUFFER;
break;
case SPIRVShaderResourceAttribs::ResourceType::StorageTexelBuffer:
OutType = SHADER_RESOURCE_TYPE_BUFFER_UAV;
- OutFlags = PIPELINE_RESOURCE_FLAG_TEXEL_BUFFER;
+ OutFlags = PIPELINE_RESOURCE_FLAG_FORMATTED_BUFFER;
break;
case SPIRVShaderResourceAttribs::ResourceType::StorageImage: