Reduce memory requirements for MVKCmdPushConstants and MVKCmdPushDescriptorSet.

MVKCmdPushConstants convert to a template class based on push constant size.
MVKCmdPushDescriptorSet reduce count of pre-allocated VkWriteDescriptorSets,
in recognition that numerous dynamic allocations necessarily happen anyway.
Cleanup member variable order in commands to avoid internal memory gaps.
This commit is contained in:
Bill Hollings 2020-05-11 20:52:26 -04:00
parent 4ba93c16a5
commit 8f34c5af93
6 changed files with 33 additions and 18 deletions

View File

@ -190,7 +190,11 @@ typedef MVKCmdBindDescriptorSetsDynamic<8> MVKCmdBindDescriptorSetsDynamicMulti;
#pragma mark -
#pragma mark MVKCmdPushConstants
/** Vulkan command to bind push constants. */
/**
* Vulkan command to bind push constants.
* Template class to balance vector pre-allocations between very common low counts and fewer larger counts.
*/
template <size_t N>
class MVKCmdPushConstants : public MVKCommand {
public:
@ -206,12 +210,17 @@ public:
protected:
MVKCommandTypePool<MVKCommand>* getTypePool(MVKCommandPool* cmdPool) override;
MVKVectorInline<char, N> _pushConstants;
MVKPipelineLayout* _pipelineLayout;
VkShaderStageFlags _stageFlags;
uint32_t _offset;
MVKVectorInline<char, 128> _pushConstants;
};
// Concrete template class implementations.
typedef MVKCmdPushConstants<64> MVKCmdPushConstants64;
typedef MVKCmdPushConstants<128> MVKCmdPushConstants128;
typedef MVKCmdPushConstants<512> MVKCmdPushConstantsMulti;
#pragma mark -
#pragma mark MVKCmdPushDescriptorSet
@ -235,9 +244,9 @@ protected:
MVKCommandTypePool<MVKCommand>* getTypePool(MVKCommandPool* cmdPool) override;
void clearDescriptorWrites();
VkPipelineBindPoint _pipelineBindPoint;
MVKVectorInline<VkWriteDescriptorSet, 1> _descriptorWrites;
MVKPipelineLayout* _pipelineLayout;
MVKVectorInline<VkWriteDescriptorSet, 8> _descriptorWrites;
VkPipelineBindPoint _pipelineBindPoint;
uint32_t _set;
};
@ -264,8 +273,8 @@ protected:
MVKDescriptorUpdateTemplate* _descUpdateTemplate;
MVKPipelineLayout* _pipelineLayout;
uint32_t _set;
void* _pData = nullptr;
uint32_t _set;
};

View File

@ -253,12 +253,13 @@ template class MVKCmdBindDescriptorSetsDynamic<8>;
#pragma mark -
#pragma mark MVKCmdPushConstants
VkResult MVKCmdPushConstants::setContent(MVKCommandBuffer* cmdBuff,
VkPipelineLayout layout,
VkShaderStageFlags stageFlags,
uint32_t offset,
uint32_t size,
const void* pValues) {
template <size_t N>
VkResult MVKCmdPushConstants<N>::setContent(MVKCommandBuffer* cmdBuff,
VkPipelineLayout layout,
VkShaderStageFlags stageFlags,
uint32_t offset,
uint32_t size,
const void* pValues) {
_pipelineLayout = (MVKPipelineLayout*)layout;
_stageFlags = stageFlags;
_offset = offset;
@ -269,7 +270,8 @@ VkResult MVKCmdPushConstants::setContent(MVKCommandBuffer* cmdBuff,
return VK_SUCCESS;
}
void MVKCmdPushConstants::encode(MVKCommandEncoder* cmdEncoder) {
template <size_t N>
void MVKCmdPushConstants<N>::encode(MVKCommandEncoder* cmdEncoder) {
VkShaderStageFlagBits stages[] = {
VK_SHADER_STAGE_VERTEX_BIT,
VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
@ -284,6 +286,10 @@ void MVKCmdPushConstants::encode(MVKCommandEncoder* cmdEncoder) {
}
}
template class MVKCmdPushConstants<64>;
template class MVKCmdPushConstants<128>;
template class MVKCmdPushConstants<512>;
#pragma mark -
#pragma mark MVKCmdPushDescriptorSet

View File

@ -140,9 +140,9 @@ public:
protected:
MVKCommandTypePool<MVKCommand>* getTypePool(MVKCommandPool* cmdPool) override;
uint32_t _queryCount;
MVKBuffer* _destBuffer;
VkDeviceSize _destOffset;
VkDeviceSize _destStride;
VkQueryResultFlags _flags;
uint32_t _queryCount;
};

View File

@ -48,11 +48,11 @@ public:
protected:
MVKCommandTypePool<MVKCommand>* getTypePool(MVKCommandPool* cmdPool) override;
MVKVectorInline<VkClearValue, N> _clearValues;
MVKRenderPass* _renderPass;
MVKFramebuffer* _framebuffer;
VkRect2D _renderArea;
VkSubpassContents _contents;
MVKVectorInline<VkClearValue, N> _clearValues;
};
// Concrete template class implementations.
@ -146,8 +146,8 @@ public:
protected:
MVKCommandTypePool<MVKCommand>* getTypePool(MVKCommandPool* cmdPool) override;
uint32_t _firstViewport;
MVKVectorInline<VkViewport, N> _viewports;
uint32_t _firstViewport;
};
// Concrete template class implementations.
@ -176,8 +176,8 @@ public:
protected:
MVKCommandTypePool<MVKCommand>* getTypePool(MVKCommandPool* cmdPool) override;
uint32_t _firstScissor;
MVKVectorInline<VkRect2D, N> _scissors;
uint32_t _firstScissor;
};
// Concrete template class implementations.

View File

@ -89,7 +89,7 @@ MVK_CMD_TYPE_POOL(EndQuery)
MVK_CMD_TYPE_POOL(WriteTimestamp)
MVK_CMD_TYPE_POOL(ResetQueryPool)
MVK_CMD_TYPE_POOL(CopyQueryPoolResults)
MVK_CMD_TYPE_POOL(PushConstants)
MVK_CMD_TYPE_POOLS_FROM_TWO_THRESHOLDS(PushConstants, 64, 128)
MVK_CMD_TYPE_POOL(Dispatch)
MVK_CMD_TYPE_POOL(DispatchIndirect)
MVK_CMD_TYPE_POOL(PushDescriptorSet)

View File

@ -1832,7 +1832,7 @@ MVK_PUBLIC_SYMBOL void vkCmdPushConstants(
const void* pValues) {
MVKTraceVulkanCallStart();
MVKAddCmd(PushConstants, commandBuffer, layout, stageFlags, offset, size, pValues);
MVKAddCmdFromTwoThresholds(PushConstants, size, 64, 128, commandBuffer, layout, stageFlags, offset, size, pValues);
MVKTraceVulkanCallEnd();
}