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.
diff --git a/Common/MVKLogging.h b/Common/MVKLogging.h
index ddf2933..51e4ade 100644
--- a/Common/MVKLogging.h
+++ b/Common/MVKLogging.h
@@ -189,6 +189,9 @@
# define MVK_DEBUGGER() { kill( getpid(), SIGINT ) ; }
#endif
+// Log the size of a type, struct, or class
+#define MVKLogSizeOf(T) printf("sizeof(%s): %lu.\n", #T, sizeof(T))
+
#ifdef __cplusplus
}
diff --git a/Docs/Whats_New.md b/Docs/Whats_New.md
index 3ff9cc8..01303ad 100644
--- a/Docs/Whats_New.md
+++ b/Docs/Whats_New.md
@@ -25,6 +25,7 @@
- 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 when compiling shaders and pipelines without default OS autorelease pool.
+- Reduce memory usage by adjusting default memory allocs for many MVKVectorInline uses.
diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKDescriptorSet.h b/MoltenVK/MoltenVK/GPUObjects/MVKDescriptorSet.h
index 9b80795..41ef3cb 100644
--- a/MoltenVK/MoltenVK/GPUObjects/MVKDescriptorSet.h
+++ b/MoltenVK/MoltenVK/GPUObjects/MVKDescriptorSet.h
@@ -117,7 +117,7 @@
MVKDescriptorSetLayout* _layout;
VkDescriptorSetLayoutBinding _info;
- MVKVectorInline<MVKSampler*, 16> _immutableSamplers;
+ MVKVectorDefault<MVKSampler*> _immutableSamplers;
MVKShaderResourceBinding _mtlResourceIndexOffsets;
bool _applyToStage[kMVKShaderStageMax];
};
@@ -181,7 +181,7 @@
void addDescriptorPool(MVKDescriptorPool* mvkDescPool) { _descriptorPools.insert(mvkDescPool); }
void removeDescriptorPool(MVKDescriptorPool* mvkDescPool) { _descriptorPools.erase(mvkDescPool); }
- MVKVectorInline<MVKDescriptorSetLayoutBinding, 8> _bindings;
+ MVKVectorInline<MVKDescriptorSetLayoutBinding, 1> _bindings;
std::unordered_map<uint32_t, uint32_t> _bindingToIndex;
MVKShaderResourceBinding _mtlResourceCounts;
std::unordered_set<MVKDescriptorPool*> _descriptorPools;
@@ -271,13 +271,13 @@
MVKDescriptorSet* _pDescSet;
MVKDescriptorSetLayoutBinding* _pBindingLayout;
- MVKVectorInline<VkDescriptorImageInfo, 1> _imageBindings;
- MVKVectorInline<VkDescriptorBufferInfo, 1> _bufferBindings;
- MVKVectorInline<VkBufferView, 1> _texelBufferBindings;
- MVKVectorInline<id<MTLBuffer>, 1> _mtlBuffers;
- MVKVectorInline<NSUInteger, 1> _mtlBufferOffsets;
- MVKVectorInline<id<MTLTexture>, 1> _mtlTextures;
- MVKVectorInline<id<MTLSamplerState>, 1> _mtlSamplers;
+ MVKVectorDefault<VkDescriptorImageInfo> _imageBindings;
+ MVKVectorDefault<VkDescriptorBufferInfo> _bufferBindings;
+ MVKVectorDefault<VkBufferView> _texelBufferBindings;
+ MVKVectorDefault<id<MTLBuffer>> _mtlBuffers;
+ MVKVectorDefault<NSUInteger> _mtlBufferOffsets;
+ MVKVectorDefault<id<MTLTexture>> _mtlTextures;
+ MVKVectorDefault<id<MTLSamplerState>> _mtlSamplers;
bool _hasDynamicSamplers;
};
@@ -323,7 +323,7 @@
MVKDescriptorBinding* getBinding(uint32_t binding);
MVKDescriptorSetLayout* _pLayout = nullptr;
- MVKVectorInline<MVKDescriptorBinding, 8> _bindings;
+ MVKVectorInline<MVKDescriptorBinding, 1> _bindings;
};
@@ -407,7 +407,7 @@
void propogateDebugName() override {}
VkDescriptorUpdateTemplateTypeKHR _type;
- MVKVectorInline<VkDescriptorUpdateTemplateEntryKHR, 4> _entries;
+ MVKVectorInline<VkDescriptorUpdateTemplateEntryKHR, 1> _entries;
};
#pragma mark -
diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKFramebuffer.h b/MoltenVK/MoltenVK/GPUObjects/MVKFramebuffer.h
index e7a0852..095c5d5 100644
--- a/MoltenVK/MoltenVK/GPUObjects/MVKFramebuffer.h
+++ b/MoltenVK/MoltenVK/GPUObjects/MVKFramebuffer.h
@@ -56,6 +56,6 @@
VkExtent2D _extent;
uint32_t _layerCount;
- MVKVectorInline<MVKImageView*, 8> _attachments;
+ MVKVectorInline<MVKImageView*, 4> _attachments;
};
diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKImage.h b/MoltenVK/MoltenVK/GPUObjects/MVKImage.h
index 5a1ebce..616b124 100644
--- a/MoltenVK/MoltenVK/GPUObjects/MVKImage.h
+++ b/MoltenVK/MoltenVK/GPUObjects/MVKImage.h
@@ -257,7 +257,7 @@
VkPipelineStageFlags dstStageMask,
VkImageMemoryBarrier* pImageMemoryBarrier);
- MVKVectorInline<MVKImageSubresource, 4> _subresources;
+ MVKVectorInline<MVKImageSubresource, 1> _subresources;
std::unordered_map<NSUInteger, id<MTLTexture>> _mtlTextureViews;
VkExtent3D _extent;
uint32_t _mipLevels;
diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKInstance.h b/MoltenVK/MoltenVK/GPUObjects/MVKInstance.h
index 301a4f0..645ed49 100644
--- a/MoltenVK/MoltenVK/GPUObjects/MVKInstance.h
+++ b/MoltenVK/MoltenVK/GPUObjects/MVKInstance.h
@@ -187,9 +187,9 @@
MVKConfiguration _mvkConfig;
VkApplicationInfo _appInfo;
- MVKVectorInline<MVKPhysicalDevice*, 4> _physicalDevices;
- MVKVectorInline<MVKDebugReportCallback*, 4> _debugReportCallbacks;
- MVKVectorInline<MVKDebugUtilsMessenger*, 4> _debugUtilMessengers;
+ MVKVectorInline<MVKPhysicalDevice*, 1> _physicalDevices;
+ MVKVectorDefault<MVKDebugReportCallback*> _debugReportCallbacks;
+ MVKVectorDefault<MVKDebugUtilsMessenger*> _debugUtilMessengers;
std::unordered_map<std::string, MVKEntryPoint> _entryPoints;
std::mutex _dcbLock;
bool _hasDebugReportCallbacks;
diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKPipeline.h b/MoltenVK/MoltenVK/GPUObjects/MVKPipeline.h
index 020af29..2157f67 100644
--- a/MoltenVK/MoltenVK/GPUObjects/MVKPipeline.h
+++ b/MoltenVK/MoltenVK/GPUObjects/MVKPipeline.h
@@ -107,9 +107,9 @@
protected:
void propogateDebugName() override {}
- MVKVectorInline<MVKDescriptorSetLayout*, 8> _descriptorSetLayouts;
- MVKVectorInline<MVKShaderResourceBinding, 8> _dslMTLResourceIndexOffsets;
- MVKVectorInline<VkPushConstantRange, 8> _pushConstants;
+ MVKVectorInline<MVKDescriptorSetLayout*, 1> _descriptorSetLayouts;
+ MVKVectorInline<MVKShaderResourceBinding, 1> _dslMTLResourceIndexOffsets;
+ MVKVectorDefault<VkPushConstantRange> _pushConstants;
MVKShaderResourceBinding _pushConstantsMTLResourceIndexes;
MVKShaderImplicitRezBinding _swizzleBufferIndex;
MVKShaderImplicitRezBinding _bufferSizeBufferIndex;
diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKQueue.h b/MoltenVK/MoltenVK/GPUObjects/MVKQueue.h
index 2976527..01d75b8 100644
--- a/MoltenVK/MoltenVK/GPUObjects/MVKQueue.h
+++ b/MoltenVK/MoltenVK/GPUObjects/MVKQueue.h
@@ -206,8 +206,8 @@
void commitActiveMTLCommandBuffer(bool signalCompletion = false);
void finish();
- MVKVectorInline<MVKCommandBuffer*, 16> _cmdBuffers;
- MVKVectorInline<MVKSemaphore*, 16> _signalSemaphores;
+ MVKVectorInline<MVKCommandBuffer*, 32> _cmdBuffers;
+ MVKVectorInline<MVKSemaphore*, 8> _signalSemaphores;
MVKFence* _fence;
id<MTLCommandBuffer> _activeMTLCommandBuffer;
};
diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKRenderPass.h b/MoltenVK/MoltenVK/GPUObjects/MVKRenderPass.h
index 253f367..0c48ba2 100644
--- a/MoltenVK/MoltenVK/GPUObjects/MVKRenderPass.h
+++ b/MoltenVK/MoltenVK/GPUObjects/MVKRenderPass.h
@@ -174,8 +174,8 @@
void propogateDebugName() override {}
MVKVectorInline<MVKRenderPassAttachment, kMVKDefaultAttachmentCount> _attachments;
- MVKVectorInline<MVKRenderSubpass, 4> _subpasses;
- MVKVectorInline<VkSubpassDependency, 4 * 2> _subpassDependencies;
+ MVKVectorInline<MVKRenderSubpass, 1> _subpasses;
+ MVKVectorDefault<VkSubpassDependency> _subpassDependencies;
};
diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKRenderPass.mm b/MoltenVK/MoltenVK/GPUObjects/MVKRenderPass.mm
index 42b499b..ddcbe4b 100644
--- a/MoltenVK/MoltenVK/GPUObjects/MVKRenderPass.mm
+++ b/MoltenVK/MoltenVK/GPUObjects/MVKRenderPass.mm
@@ -348,7 +348,7 @@
// Add subpasses and dependencies first
_subpasses.reserve(pCreateInfo->subpassCount);
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);
for (uint32_t i = 0; i < pCreateInfo->dependencyCount; i++) {
@@ -358,7 +358,7 @@
// Add attachments after subpasses, so each attachment can link to subpasses
_attachments.reserve(pCreateInfo->attachmentCount);
for (uint32_t i = 0; i < pCreateInfo->attachmentCount; i++) {
- _attachments.push_back(MVKRenderPassAttachment(this, &pCreateInfo->pAttachments[i]));
+ _attachments.emplace_back(this, &pCreateInfo->pAttachments[i]);
}
}
diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKShaderModule.h b/MoltenVK/MoltenVK/GPUObjects/MVKShaderModule.h
index 4ef1dfb..6274ee6 100644
--- a/MoltenVK/MoltenVK/GPUObjects/MVKShaderModule.h
+++ b/MoltenVK/MoltenVK/GPUObjects/MVKShaderModule.h
@@ -151,7 +151,7 @@
void merge(MVKShaderLibraryCache* other);
MVKVulkanAPIDeviceObject* _owner;
- MVKVectorInline<std::pair<SPIRVToMSLConversionConfiguration, MVKShaderLibrary*>, 4> _shaderLibraries;
+ MVKVectorInline<std::pair<SPIRVToMSLConversionConfiguration, MVKShaderLibrary*>, 1> _shaderLibraries;
};
diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKSwapchain.h b/MoltenVK/MoltenVK/GPUObjects/MVKSwapchain.h
index bb7ed85..6211f0d 100644
--- a/MoltenVK/MoltenVK/GPUObjects/MVKSwapchain.h
+++ b/MoltenVK/MoltenVK/GPUObjects/MVKSwapchain.h
@@ -112,7 +112,7 @@
struct Availability {
MVKSwapchainImageAvailability status;
- MVKVectorInline<MVKSwapchainSignaler, 4> signalers;
+ MVKVectorInline<MVKSwapchainSignaler, 1> signalers;
MVKSwapchainSignaler preSignaled;
};