Reduce memory usage by adjusting default memory allocs for many MVKVectorInline uses.

MVKRenderPass use emplace_back() instead of push_back()
when populating _subpasses  & _attachments vectors.
Add mvkLogSizeOf(T) development debugging function.
This commit is contained in:
Bill Hollings 2019-10-10 16:46:17 -04:00
parent 2ba65c50a3
commit 5c87700732
12 changed files with 31 additions and 27 deletions

View File

@ -189,6 +189,9 @@ do { \
# define MVK_DEBUGGER() { kill( getpid(), SIGINT ) ; } # define MVK_DEBUGGER() { kill( getpid(), SIGINT ) ; }
#endif #endif
// Log the size of a type, struct, or class
#define MVKLogSizeOf(T) printf("sizeof(%s): %lu.\n", #T, sizeof(T))
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -25,6 +25,7 @@ Released TBD
- Allow `MVK_CONFIG_SYNCHRONOUS_QUEUE_SUBMITS` build setting to be overridden. - Allow `MVK_CONFIG_SYNCHRONOUS_QUEUE_SUBMITS` build setting to be overridden.
- Fix memory leaks of system classes during `VkInstance` and `VkQueue` creation. - Fix memory leaks of system classes during `VkInstance` and `VkQueue` creation.
- Fix memory leaks when compiling shaders and pipelines without default OS autorelease pool. - Fix memory leaks when compiling shaders and pipelines without default OS autorelease pool.
- Reduce memory usage by adjusting default memory allocs for many MVKVectorInline uses.

View File

@ -117,7 +117,7 @@ protected:
MVKDescriptorSetLayout* _layout; MVKDescriptorSetLayout* _layout;
VkDescriptorSetLayoutBinding _info; VkDescriptorSetLayoutBinding _info;
MVKVectorInline<MVKSampler*, 16> _immutableSamplers; MVKVectorDefault<MVKSampler*> _immutableSamplers;
MVKShaderResourceBinding _mtlResourceIndexOffsets; MVKShaderResourceBinding _mtlResourceIndexOffsets;
bool _applyToStage[kMVKShaderStageMax]; bool _applyToStage[kMVKShaderStageMax];
}; };
@ -181,7 +181,7 @@ protected:
void addDescriptorPool(MVKDescriptorPool* mvkDescPool) { _descriptorPools.insert(mvkDescPool); } void addDescriptorPool(MVKDescriptorPool* mvkDescPool) { _descriptorPools.insert(mvkDescPool); }
void removeDescriptorPool(MVKDescriptorPool* mvkDescPool) { _descriptorPools.erase(mvkDescPool); } void removeDescriptorPool(MVKDescriptorPool* mvkDescPool) { _descriptorPools.erase(mvkDescPool); }
MVKVectorInline<MVKDescriptorSetLayoutBinding, 8> _bindings; MVKVectorInline<MVKDescriptorSetLayoutBinding, 1> _bindings;
std::unordered_map<uint32_t, uint32_t> _bindingToIndex; std::unordered_map<uint32_t, uint32_t> _bindingToIndex;
MVKShaderResourceBinding _mtlResourceCounts; MVKShaderResourceBinding _mtlResourceCounts;
std::unordered_set<MVKDescriptorPool*> _descriptorPools; std::unordered_set<MVKDescriptorPool*> _descriptorPools;
@ -271,13 +271,13 @@ protected:
MVKDescriptorSet* _pDescSet; MVKDescriptorSet* _pDescSet;
MVKDescriptorSetLayoutBinding* _pBindingLayout; MVKDescriptorSetLayoutBinding* _pBindingLayout;
MVKVectorInline<VkDescriptorImageInfo, 1> _imageBindings; MVKVectorDefault<VkDescriptorImageInfo> _imageBindings;
MVKVectorInline<VkDescriptorBufferInfo, 1> _bufferBindings; MVKVectorDefault<VkDescriptorBufferInfo> _bufferBindings;
MVKVectorInline<VkBufferView, 1> _texelBufferBindings; MVKVectorDefault<VkBufferView> _texelBufferBindings;
MVKVectorInline<id<MTLBuffer>, 1> _mtlBuffers; MVKVectorDefault<id<MTLBuffer>> _mtlBuffers;
MVKVectorInline<NSUInteger, 1> _mtlBufferOffsets; MVKVectorDefault<NSUInteger> _mtlBufferOffsets;
MVKVectorInline<id<MTLTexture>, 1> _mtlTextures; MVKVectorDefault<id<MTLTexture>> _mtlTextures;
MVKVectorInline<id<MTLSamplerState>, 1> _mtlSamplers; MVKVectorDefault<id<MTLSamplerState>> _mtlSamplers;
bool _hasDynamicSamplers; bool _hasDynamicSamplers;
}; };
@ -323,7 +323,7 @@ protected:
MVKDescriptorBinding* getBinding(uint32_t binding); MVKDescriptorBinding* getBinding(uint32_t binding);
MVKDescriptorSetLayout* _pLayout = nullptr; MVKDescriptorSetLayout* _pLayout = nullptr;
MVKVectorInline<MVKDescriptorBinding, 8> _bindings; MVKVectorInline<MVKDescriptorBinding, 1> _bindings;
}; };
@ -407,7 +407,7 @@ protected:
void propogateDebugName() override {} void propogateDebugName() override {}
VkDescriptorUpdateTemplateTypeKHR _type; VkDescriptorUpdateTemplateTypeKHR _type;
MVKVectorInline<VkDescriptorUpdateTemplateEntryKHR, 4> _entries; MVKVectorInline<VkDescriptorUpdateTemplateEntryKHR, 1> _entries;
}; };
#pragma mark - #pragma mark -

View File

@ -56,6 +56,6 @@ protected:
VkExtent2D _extent; VkExtent2D _extent;
uint32_t _layerCount; uint32_t _layerCount;
MVKVectorInline<MVKImageView*, 8> _attachments; MVKVectorInline<MVKImageView*, 4> _attachments;
}; };

View File

@ -257,7 +257,7 @@ protected:
VkPipelineStageFlags dstStageMask, VkPipelineStageFlags dstStageMask,
VkImageMemoryBarrier* pImageMemoryBarrier); VkImageMemoryBarrier* pImageMemoryBarrier);
MVKVectorInline<MVKImageSubresource, 4> _subresources; MVKVectorInline<MVKImageSubresource, 1> _subresources;
std::unordered_map<NSUInteger, id<MTLTexture>> _mtlTextureViews; std::unordered_map<NSUInteger, id<MTLTexture>> _mtlTextureViews;
VkExtent3D _extent; VkExtent3D _extent;
uint32_t _mipLevels; uint32_t _mipLevels;

View File

@ -187,9 +187,9 @@ protected:
MVKConfiguration _mvkConfig; MVKConfiguration _mvkConfig;
VkApplicationInfo _appInfo; VkApplicationInfo _appInfo;
MVKVectorInline<MVKPhysicalDevice*, 4> _physicalDevices; MVKVectorInline<MVKPhysicalDevice*, 1> _physicalDevices;
MVKVectorInline<MVKDebugReportCallback*, 4> _debugReportCallbacks; MVKVectorDefault<MVKDebugReportCallback*> _debugReportCallbacks;
MVKVectorInline<MVKDebugUtilsMessenger*, 4> _debugUtilMessengers; MVKVectorDefault<MVKDebugUtilsMessenger*> _debugUtilMessengers;
std::unordered_map<std::string, MVKEntryPoint> _entryPoints; std::unordered_map<std::string, MVKEntryPoint> _entryPoints;
std::mutex _dcbLock; std::mutex _dcbLock;
bool _hasDebugReportCallbacks; bool _hasDebugReportCallbacks;

View File

@ -107,9 +107,9 @@ public:
protected: protected:
void propogateDebugName() override {} void propogateDebugName() override {}
MVKVectorInline<MVKDescriptorSetLayout*, 8> _descriptorSetLayouts; MVKVectorInline<MVKDescriptorSetLayout*, 1> _descriptorSetLayouts;
MVKVectorInline<MVKShaderResourceBinding, 8> _dslMTLResourceIndexOffsets; MVKVectorInline<MVKShaderResourceBinding, 1> _dslMTLResourceIndexOffsets;
MVKVectorInline<VkPushConstantRange, 8> _pushConstants; MVKVectorDefault<VkPushConstantRange> _pushConstants;
MVKShaderResourceBinding _pushConstantsMTLResourceIndexes; MVKShaderResourceBinding _pushConstantsMTLResourceIndexes;
MVKShaderImplicitRezBinding _swizzleBufferIndex; MVKShaderImplicitRezBinding _swizzleBufferIndex;
MVKShaderImplicitRezBinding _bufferSizeBufferIndex; MVKShaderImplicitRezBinding _bufferSizeBufferIndex;

View File

@ -206,8 +206,8 @@ protected:
void commitActiveMTLCommandBuffer(bool signalCompletion = false); void commitActiveMTLCommandBuffer(bool signalCompletion = false);
void finish(); void finish();
MVKVectorInline<MVKCommandBuffer*, 16> _cmdBuffers; MVKVectorInline<MVKCommandBuffer*, 32> _cmdBuffers;
MVKVectorInline<MVKSemaphore*, 16> _signalSemaphores; MVKVectorInline<MVKSemaphore*, 8> _signalSemaphores;
MVKFence* _fence; MVKFence* _fence;
id<MTLCommandBuffer> _activeMTLCommandBuffer; id<MTLCommandBuffer> _activeMTLCommandBuffer;
}; };

View File

@ -174,8 +174,8 @@ protected:
void propogateDebugName() override {} void propogateDebugName() override {}
MVKVectorInline<MVKRenderPassAttachment, kMVKDefaultAttachmentCount> _attachments; MVKVectorInline<MVKRenderPassAttachment, kMVKDefaultAttachmentCount> _attachments;
MVKVectorInline<MVKRenderSubpass, 4> _subpasses; MVKVectorInline<MVKRenderSubpass, 1> _subpasses;
MVKVectorInline<VkSubpassDependency, 4 * 2> _subpassDependencies; MVKVectorDefault<VkSubpassDependency> _subpassDependencies;
}; };

View File

@ -348,7 +348,7 @@ MVKRenderPass::MVKRenderPass(MVKDevice* device,
// Add subpasses and dependencies first // Add subpasses and dependencies first
_subpasses.reserve(pCreateInfo->subpassCount); _subpasses.reserve(pCreateInfo->subpassCount);
for (uint32_t i = 0; i < pCreateInfo->subpassCount; i++) { for (uint32_t i = 0; i < pCreateInfo->subpassCount; i++) {
_subpasses.push_back(MVKRenderSubpass(this, &pCreateInfo->pSubpasses[i])); _subpasses.emplace_back(this, &pCreateInfo->pSubpasses[i]);
} }
_subpassDependencies.reserve(pCreateInfo->dependencyCount); _subpassDependencies.reserve(pCreateInfo->dependencyCount);
for (uint32_t i = 0; i < pCreateInfo->dependencyCount; i++) { for (uint32_t i = 0; i < pCreateInfo->dependencyCount; i++) {
@ -358,7 +358,7 @@ MVKRenderPass::MVKRenderPass(MVKDevice* device,
// Add attachments after subpasses, so each attachment can link to subpasses // Add attachments after subpasses, so each attachment can link to subpasses
_attachments.reserve(pCreateInfo->attachmentCount); _attachments.reserve(pCreateInfo->attachmentCount);
for (uint32_t i = 0; i < pCreateInfo->attachmentCount; i++) { for (uint32_t i = 0; i < pCreateInfo->attachmentCount; i++) {
_attachments.push_back(MVKRenderPassAttachment(this, &pCreateInfo->pAttachments[i])); _attachments.emplace_back(this, &pCreateInfo->pAttachments[i]);
} }
} }

View File

@ -151,7 +151,7 @@ protected:
void merge(MVKShaderLibraryCache* other); void merge(MVKShaderLibraryCache* other);
MVKVulkanAPIDeviceObject* _owner; MVKVulkanAPIDeviceObject* _owner;
MVKVectorInline<std::pair<SPIRVToMSLConversionConfiguration, MVKShaderLibrary*>, 4> _shaderLibraries; MVKVectorInline<std::pair<SPIRVToMSLConversionConfiguration, MVKShaderLibrary*>, 1> _shaderLibraries;
}; };

View File

@ -112,7 +112,7 @@ protected:
struct Availability { struct Availability {
MVKSwapchainImageAvailability status; MVKSwapchainImageAvailability status;
MVKVectorInline<MVKSwapchainSignaler, 4> signalers; MVKVectorInline<MVKSwapchainSignaler, 1> signalers;
MVKSwapchainSignaler preSignaled; MVKSwapchainSignaler preSignaled;
}; };