Preallocate a pool of descriptors by default.
Enable MVKConfiguration::preallocateDescriptors and
MVK_CONFIG_PREALLOCATE_DESCRIPTORS by default.
Rename MVKDescriptorTypePreallocation to MVKDescriptorTypePool.
diff --git a/Docs/Whats_New.md b/Docs/Whats_New.md
index c69f0f9..2b2bb2c 100644
--- a/Docs/Whats_New.md
+++ b/Docs/Whats_New.md
@@ -24,6 +24,8 @@
- Avoid use of _Metal_ renderpass load and store actions on memoryless attachments.
- Remove project qualifiers from references to `SPIRV-Cross` header files.
- `MVKDescriptorPool` pools its descriptor sets.
+- Enable `MVKConfiguration::preallocateDescriptors` and `MVK_CONFIG_PREALLOCATE_DESCRIPTORS`
+ environment variable by default to preallocate descriptors when a `VkDescriptorPool` is created.
- Add `MVKConfiguration::apiVersionToAdvertise` and `MVK_CONFIG_API_VERSION_TO_ADVERTISE`
env var to configure **MoltenVK** to advertise a particular _Vulkan_ version.
- Add `MVKConfiguration::advertiseExtensions` and `MVK_CONFIG_ADVERTISE_EXTENSIONS`
diff --git a/MoltenVK/MoltenVK/API/vk_mvk_moltenvk.h b/MoltenVK/MoltenVK/API/vk_mvk_moltenvk.h
index 7cdcf59..7a90a4d 100644
--- a/MoltenVK/MoltenVK/API/vk_mvk_moltenvk.h
+++ b/MoltenVK/MoltenVK/API/vk_mvk_moltenvk.h
@@ -660,22 +660,20 @@
VkBool32 texture1DAs2D;
/**
- * Controls whether MoltenVK should preallocate memory in each VkDescriptorPool
- * ccording to the values of the VkDescriptorPoolSize parameters. Doing so may improve
- * descriptor set allocation performance at a cost of preallocated application memory,
- * and possible descreased performance when creating and reseting the VkDescriptorPool.
- * If this setting is disabled, the descriptors required for a descriptor set will
- * be dynamically allocated in application memory when the descriptor set itself is allocated.
+ * Controls whether MoltenVK should preallocate memory in each VkDescriptorPool according
+ * to the values of the VkDescriptorPoolSize parameters. Doing so may improve descriptor set
+ * allocation performance and memory stability at a cost of preallocated application memory.
+ * If this setting is disabled, the descriptors required for a descriptor set will be individually
+ * dynamically allocated in application memory when the descriptor set itself is allocated.
*
- * The value of this parameter may be changed at any time during application runtime,
- * and the changed value will immediately effect behavior of VkDescriptorPools created
- * after the setting is changed.
+ * The value of this parameter may be changed at any time during application runtime, and the
+ * changed value will affect the behavior of VkDescriptorPools created after the value is changed.
*
* The initial value or this parameter is set by the
* MVK_CONFIG_PREALLOCATE_DESCRIPTORS
* runtime environment variable or MoltenVK compile-time build setting.
- * If neither is set, this setting is disabled by default, and MoltenVK will
- * dynamically allocate descriptors when the containing descriptor set is allocated.
+ * If neither is set, this setting is enabled by default, and MoltenVK will
+ * allocate a pool of descriptors when a VkDescriptorPool is created.
*/
VkBool32 preallocateDescriptors;
diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKDescriptorSet.h b/MoltenVK/MoltenVK/GPUObjects/MVKDescriptorSet.h
index 4dfe90a..8d1e931 100644
--- a/MoltenVK/MoltenVK/GPUObjects/MVKDescriptorSet.h
+++ b/MoltenVK/MoltenVK/GPUObjects/MVKDescriptorSet.h
@@ -146,17 +146,17 @@
#pragma mark -
-#pragma mark MVKDescriptorTypePreallocation
+#pragma mark MVKDescriptorTypePool
-/** Support class for MVKDescriptorPool that holds preallocated instances of a single concrete descriptor class. */
+/** Support class for MVKDescriptorPool that holds a pool of instances of a single concrete descriptor class. */
template<class DescriptorClass>
-class MVKDescriptorTypePreallocation : public MVKBaseObject {
+class MVKDescriptorTypePool : public MVKBaseObject {
public:
MVKVulkanAPIObject* getVulkanAPIObject() override { return nullptr; };
- MVKDescriptorTypePreallocation(size_t poolSize);
+ MVKDescriptorTypePool(size_t poolSize);
protected:
friend class MVKDescriptorPool;
@@ -200,7 +200,7 @@
protected:
friend class MVKDescriptorSet;
- template<class> friend class MVKDescriptorTypePreallocation;
+ template<class> friend class MVKDescriptorTypePool;
void propagateDebugName() override {}
const uint32_t* getVariableDecriptorCounts(const VkDescriptorSetAllocateInfo* pAllocateInfo);
@@ -212,18 +212,18 @@
MVKSmallVector<MVKDescriptorSet> _descriptorSets;
MVKBitArray _descriptorSetAvailablility;
- MVKDescriptorTypePreallocation<MVKUniformBufferDescriptor> _uniformBufferDescriptors;
- MVKDescriptorTypePreallocation<MVKStorageBufferDescriptor> _storageBufferDescriptors;
- MVKDescriptorTypePreallocation<MVKUniformBufferDynamicDescriptor> _uniformBufferDynamicDescriptors;
- MVKDescriptorTypePreallocation<MVKStorageBufferDynamicDescriptor> _storageBufferDynamicDescriptors;
- MVKDescriptorTypePreallocation<MVKInlineUniformBlockDescriptor> _inlineUniformBlockDescriptors;
- MVKDescriptorTypePreallocation<MVKSampledImageDescriptor> _sampledImageDescriptors;
- MVKDescriptorTypePreallocation<MVKStorageImageDescriptor> _storageImageDescriptors;
- MVKDescriptorTypePreallocation<MVKInputAttachmentDescriptor> _inputAttachmentDescriptors;
- MVKDescriptorTypePreallocation<MVKSamplerDescriptor> _samplerDescriptors;
- MVKDescriptorTypePreallocation<MVKCombinedImageSamplerDescriptor> _combinedImageSamplerDescriptors;
- MVKDescriptorTypePreallocation<MVKUniformTexelBufferDescriptor> _uniformTexelBufferDescriptors;
- MVKDescriptorTypePreallocation<MVKStorageTexelBufferDescriptor> _storageTexelBufferDescriptors;
+ MVKDescriptorTypePool<MVKUniformBufferDescriptor> _uniformBufferDescriptors;
+ MVKDescriptorTypePool<MVKStorageBufferDescriptor> _storageBufferDescriptors;
+ MVKDescriptorTypePool<MVKUniformBufferDynamicDescriptor> _uniformBufferDynamicDescriptors;
+ MVKDescriptorTypePool<MVKStorageBufferDynamicDescriptor> _storageBufferDynamicDescriptors;
+ MVKDescriptorTypePool<MVKInlineUniformBlockDescriptor> _inlineUniformBlockDescriptors;
+ MVKDescriptorTypePool<MVKSampledImageDescriptor> _sampledImageDescriptors;
+ MVKDescriptorTypePool<MVKStorageImageDescriptor> _storageImageDescriptors;
+ MVKDescriptorTypePool<MVKInputAttachmentDescriptor> _inputAttachmentDescriptors;
+ MVKDescriptorTypePool<MVKSamplerDescriptor> _samplerDescriptors;
+ MVKDescriptorTypePool<MVKCombinedImageSamplerDescriptor> _combinedImageSamplerDescriptors;
+ MVKDescriptorTypePool<MVKUniformTexelBufferDescriptor> _uniformTexelBufferDescriptors;
+ MVKDescriptorTypePool<MVKStorageTexelBufferDescriptor> _storageTexelBufferDescriptors;
bool _hasPooledDescriptors;
};
diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKDescriptorSet.mm b/MoltenVK/MoltenVK/GPUObjects/MVKDescriptorSet.mm
index 9d6e853..aeeb58f 100644
--- a/MoltenVK/MoltenVK/GPUObjects/MVKDescriptorSet.mm
+++ b/MoltenVK/MoltenVK/GPUObjects/MVKDescriptorSet.mm
@@ -319,12 +319,12 @@
#pragma mark -
-#pragma mark MVKDescriptorTypePreallocation
+#pragma mark MVKDescriptorTypePool
// If preallocated, find the next availalble descriptor.
// If not preallocated, create one on the fly.
template<class DescriptorClass>
-VkResult MVKDescriptorTypePreallocation<DescriptorClass>::allocateDescriptor(MVKDescriptor** pMVKDesc,
+VkResult MVKDescriptorTypePool<DescriptorClass>::allocateDescriptor(MVKDescriptor** pMVKDesc,
MVKDescriptorPool* pool) {
DescriptorClass* mvkDesc;
if (pool->_hasPooledDescriptors) {
@@ -344,7 +344,7 @@
// The descriptor will be reset when it is re-allocated. This streamlines the reset() of this pool.
// If not preallocated, simply destroy returning descriptor.
template<typename DescriptorClass>
-void MVKDescriptorTypePreallocation<DescriptorClass>::freeDescriptor(MVKDescriptor* mvkDesc,
+void MVKDescriptorTypePool<DescriptorClass>::freeDescriptor(MVKDescriptor* mvkDesc,
MVKDescriptorPool* pool) {
if (pool->_hasPooledDescriptors) {
size_t descIdx = (DescriptorClass*)mvkDesc - _descriptors.data();
@@ -356,12 +356,12 @@
// Preallocated descriptors will be reset when they are reused
template<typename DescriptorClass>
-void MVKDescriptorTypePreallocation<DescriptorClass>::reset() {
+void MVKDescriptorTypePool<DescriptorClass>::reset() {
_availability.setAllBits();
}
template<typename DescriptorClass>
-MVKDescriptorTypePreallocation<DescriptorClass>::MVKDescriptorTypePreallocation(size_t poolSize) :
+MVKDescriptorTypePool<DescriptorClass>::MVKDescriptorTypePool(size_t poolSize) :
_descriptors(poolSize),
_availability(poolSize, true) {}
diff --git a/MoltenVK/MoltenVK/Utility/MVKEnvironment.h b/MoltenVK/MoltenVK/Utility/MVKEnvironment.h
index d6a6602..5a7e67a 100644
--- a/MoltenVK/MoltenVK/Utility/MVKEnvironment.h
+++ b/MoltenVK/MoltenVK/Utility/MVKEnvironment.h
@@ -248,9 +248,9 @@
# define MVK_CONFIG_TEXTURE_1D_AS_2D 1
#endif
-/** Preallocate descriptors when creating VkDescriptorPool. Disabled by default. */
+/** Preallocate descriptors when creating VkDescriptorPool. Enabled by default. */
#ifndef MVK_CONFIG_PREALLOCATE_DESCRIPTORS
-# define MVK_CONFIG_PREALLOCATE_DESCRIPTORS 0
+# define MVK_CONFIG_PREALLOCATE_DESCRIPTORS 1
#endif
/** Use pooling for command resources in a VkCommandPool. Enabled by default. */