Preallocate a pool of descriptors by default.

Enable MVKConfiguration::preallocateDescriptors and
MVK_CONFIG_PREALLOCATE_DESCRIPTORS by default.
Rename MVKDescriptorTypePreallocation to MVKDescriptorTypePool.
This commit is contained in:
Bill Hollings 2021-03-15 16:27:39 -04:00
parent 6cba6a851b
commit 2ef21c65bf
5 changed files with 35 additions and 35 deletions

View File

@ -24,6 +24,8 @@ Released TBD
- 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`

View File

@ -660,22 +660,20 @@ typedef struct {
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;

View File

@ -146,17 +146,17 @@ protected:
#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 @@ public:
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 @@ protected:
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;
};

View File

@ -319,12 +319,12 @@ MVKDescriptorSet::MVKDescriptorSet(MVKDescriptorPool* pool) : MVKVulkanAPIDevice
#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 @@ VkResult MVKDescriptorTypePreallocation<DescriptorClass>::allocateDescriptor(MVK
// 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 @@ void MVKDescriptorTypePreallocation<DescriptorClass>::freeDescriptor(MVKDescript
// 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) {}

View File

@ -248,9 +248,9 @@ void mvkSetMVKConfiguration(MVKConfiguration* pMVKConfig);
# 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. */