Skip to content

Commit 2eb35cd

Browse files
PipelineLayoutVk: only store push constant info when needed
1 parent b44e771 commit 2eb35cd

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

Graphics/GraphicsEngineVulkan/include/PipelineLayoutVk.hpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
/// Declaration of Diligent::PipelineLayoutVk class
3232

3333
#include <array>
34+
#include <memory>
3435

3536
#include "VulkanUtilities/ObjectWrappers.hpp"
3637

@@ -63,17 +64,21 @@ class PipelineLayoutVk
6364

6465
struct PushConstantInfo
6566
{
66-
Uint32 Size = 0;
67-
VkShaderStageFlags StageFlags = 0;
68-
Uint32 SignatureIndex = ~0u;
69-
Uint32 ResourceIndex = ~0u;
67+
VkPushConstantRange vkRange = {};
7068

71-
constexpr explicit operator bool() const { return Size != 0; }
69+
Uint32 SignatureIndex = ~0u;
70+
Uint32 ResourceIndex = ~0u;
71+
72+
constexpr explicit operator bool() const { return vkRange.size != 0; }
7273
};
7374
static PushConstantInfo GetPushConstantInfo(const RefCntAutoPtr<PipelineResourceSignatureVkImpl>* ppSignatures,
7475
Uint32 SignatureCount);
7576

76-
const PushConstantInfo& GetPushConstantInfo() const { return m_PushConstantInfo; }
77+
const PushConstantInfo& GetPushConstantInfo() const
78+
{
79+
static const PushConstantInfo NullPCInfo;
80+
return m_PushConstantInfo ? *m_PushConstantInfo : NullPCInfo;
81+
}
7782

7883
private:
7984
VulkanUtilities::PipelineLayoutWrapper m_VkPipelineLayout;
@@ -86,7 +91,7 @@ class PipelineLayoutVk
8691
// (Maximum is MAX_RESOURCE_SIGNATURES * 2)
8792
Uint8 m_DescrSetCount = 0;
8893

89-
PushConstantInfo m_PushConstantInfo;
94+
std::unique_ptr<PushConstantInfo> m_PushConstantInfo;
9095

9196
#ifdef DILIGENT_DEBUG
9297
Uint32 m_DbgMaxBindIndex = 0;

Graphics/GraphicsEngineVulkan/src/PipelineLayoutVk.cpp

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,13 @@ PipelineLayoutVk::PushConstantInfo PipelineLayoutVk::GetPushConstantInfo(
8383
{
8484
VERIFY_EXPR(ResDesc.ArraySize > 0);
8585
// For inline constants, ArraySize contains the number of 32-bit constants.
86-
PCInfo.Size = ResDesc.ArraySize * sizeof(Uint32);
87-
PCInfo.StageFlags = ShaderTypesToVkShaderStageFlags(ResDesc.ShaderStages);
86+
PCInfo.vkRange.size = ResDesc.ArraySize * sizeof(Uint32);
87+
PCInfo.vkRange.offset = 0;
88+
PCInfo.vkRange.stageFlags = ShaderTypesToVkShaderStageFlags(ResDesc.ShaderStages);
89+
8890
PCInfo.SignatureIndex = BindInd;
8991
PCInfo.ResourceIndex = r;
92+
9093
break;
9194
}
9295
}
@@ -156,22 +159,15 @@ void PipelineLayoutVk::Create(RenderDeviceVkImpl* pD
156159
") used by the pipeline layout exceeds device limit (", Limits.maxDescriptorSetStorageBuffersDynamic, ")");
157160
}
158161

159-
m_PushConstantInfo = GetPushConstantInfo(ppSignatures, SignatureCount);
160-
161-
// Set up push constant range if present
162-
VkPushConstantRange PushConstantRange{};
163-
if (m_PushConstantInfo)
162+
if (PushConstantInfo PCInfo = GetPushConstantInfo(ppSignatures, SignatureCount))
164163
{
165164
// Validate push constant size against device limits
166-
if (m_PushConstantInfo.Size > Limits.maxPushConstantsSize)
165+
if (PCInfo.vkRange.size > Limits.maxPushConstantsSize)
167166
{
168-
LOG_ERROR_AND_THROW("Push constant size (", m_PushConstantInfo.Size,
167+
LOG_ERROR_AND_THROW("Push constant size (", PCInfo.vkRange.size,
169168
" bytes) exceeds device limit (", Limits.maxPushConstantsSize, " bytes)");
170169
}
171-
172-
PushConstantRange.stageFlags = m_PushConstantInfo.StageFlags;
173-
PushConstantRange.offset = 0;
174-
PushConstantRange.size = m_PushConstantInfo.Size;
170+
m_PushConstantInfo = std::make_unique<PushConstantInfo>(std::move(PCInfo));
175171
}
176172

177173
VkPipelineLayoutCreateInfo PipelineLayoutCI{};
@@ -181,7 +177,7 @@ void PipelineLayoutVk::Create(RenderDeviceVkImpl* pD
181177
PipelineLayoutCI.setLayoutCount = DescSetLayoutCount;
182178
PipelineLayoutCI.pSetLayouts = DescSetLayoutCount ? DescSetLayouts.data() : nullptr;
183179
PipelineLayoutCI.pushConstantRangeCount = m_PushConstantInfo ? 1 : 0;
184-
PipelineLayoutCI.pPushConstantRanges = m_PushConstantInfo ? &PushConstantRange : nullptr;
180+
PipelineLayoutCI.pPushConstantRanges = m_PushConstantInfo ? &m_PushConstantInfo->vkRange : nullptr;
185181

186182
m_VkPipelineLayout = pDeviceVk->GetLogicalDevice().CreatePipelineLayout(PipelineLayoutCI);
187183

0 commit comments

Comments
 (0)