Skip to content

Commit

Permalink
Merge pull request #819 from billhollings/master
Browse files Browse the repository at this point in the history
Fix issue where preallocated descriptor count was not reset during vkResetDescriptorPool().
  • Loading branch information
billhollings authored Jan 21, 2020
2 parents 8463eb5 + 593f773 commit 0d94a8e
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 8 deletions.
16 changes: 10 additions & 6 deletions Docs/MoltenVK_Runtime_UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -352,17 +352,21 @@ There are three mechanisms for setting the values of the **MoltenVK** configurat
- Application runtime environment variables.
- Build settings at **MoltenVK** build time.

To change the **MoltenVK** configuration settings at runtime using a programmatic API, use the
`vkGetMoltenVKConfigurationMVK()` and `vkSetMoltenVKConfigurationMVK()` functions to retrieve,
modify, and set a copy of the `MVKConfiguration` structure.
To change some of the **MoltenVK** configuration settings at runtime using a programmatic API,
use the `vkGetMoltenVKConfigurationMVK()` and `vkSetMoltenVKConfigurationMVK()` functions to
retrieve, modify, and set a copy of the `MVKConfiguration` structure.

The initial value of each of the configuration settings can established at runtime
The initial value of each of the configuration settings can be established at runtime
by a corresponding environment variable, or if the environment variable is not set,
by a corresponding build setting at the time **MoltenVK** is compiled. The environment
variable and build setting for each configuration parameter share the same name.

See the description of the `MVKConfiguration` structure parameters in the `vk_mvk_moltenvk.h`
file for more info about configuring and optimizing **MoltenVK** at build time or runtime.
There are also a number of additional runtime environment variables that are not included in the
`MVKConfiguration` structure, but that also control **MoltenVK** behaviour.

See the description of the environment variables and the `MVKConfiguration` structure parameters
in the `vk_mvk_moltenvk.h` file for more info about configuring and optimizing **MoltenVK**
at runtime or build time.


<a name="shaders"></a>
Expand Down
8 changes: 6 additions & 2 deletions Docs/Whats_New.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,19 @@ For best results, use a Markdown reader.*
MoltenVK 1.0.40
---------------

Released TBD
Released 2020/01/21

- Refactor descriptor management to reduce memory footprint and fix caching leak.
- Add `MVK_CONFIG_PREALLOCATE_DESCRIPTORS` environment variable to support preallocated
descriptor pooling within a `VkDescriptorPool` via the `VkDescriptorPoolSize` values.
- Fix crash when app does not use queue family zero.
- Fix buffer offset in `vkCmdPushDescriptorSet()` for non-dedicated buffer memory.
- Fix Metal validation error on push constant sizing differences between C and MSL structs.
- Track performance of `CAMetalLayer nextDrawable` call.
- Document recommendation to use 3 swapchain images, particularly with full-screen rendering.
- Update `MoltenVK_Runtime_UserGuide.md` to better explain runtime environment variables.
- Update `VK_MVK_MOLTENVK_SPEC_VERSION` to `24`.
- Update copyright to 2020.
- Update copyright notices to year 2020.



Expand Down
9 changes: 9 additions & 0 deletions MoltenVK/MoltenVK/API/vk_mvk_moltenvk.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,15 @@ typedef unsigned long MTLLanguageVersion;
* on native 1D textures, including not being renderable, clearable, or permitting mipmaps.
* Using a Metal 2D texture allows Vulkan 1D textures to support this additional functionality.
* This setting is enabled by default, and MoltenVK will use a Metal 2D texture for each Vulkan 1D image.
*
* 7. The MVK_CONFIG_PREALLOCATE_DESCRIPTORS runtime environment variable or MoltenVK compile-time
* build setting 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 at a cost of preallocated application memory.
* If this environment variable is disabled, the descriptors required for a descriptor set will
* be dynamically allocated in application memory when the descriptor set itself is allocated.
* This setting is disabled by default, and MoltenVK will dynamically allocate descriptors
* when the containing descriptor set is allocated.
*/
typedef struct {

Expand Down
2 changes: 2 additions & 0 deletions MoltenVK/MoltenVK/GPUObjects/MVKDescriptorSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ class MVKDescriptorTypePreallocation : public MVKBaseObject {
VkResult allocateDescriptor(MVKDescriptor** pMVKDesc);
bool findDescriptor(uint32_t endIndex, MVKDescriptor** pMVKDesc);
void freeDescriptor(MVKDescriptor* mvkDesc);
void reset();

std::vector<DescriptorClass> _descriptors;
std::vector<bool> _availability;
Expand All @@ -188,6 +189,7 @@ class MVKPreallocatedDescriptors : public MVKBaseObject {

VkResult allocateDescriptor(VkDescriptorType descriptorType, MVKDescriptor** pMVKDesc);
void freeDescriptor(MVKDescriptor* mvkDesc);
void reset();

MVKDescriptorTypePreallocation<MVKUniformBufferDescriptor> _uniformBufferDescriptors;
MVKDescriptorTypePreallocation<MVKStorageBufferDescriptor> _storageBufferDescriptors;
Expand Down
21 changes: 21 additions & 0 deletions MoltenVK/MoltenVK/GPUObjects/MVKDescriptorSet.mm
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,11 @@ static inline bool getMVKPreallocateDescriptors() {
}
}

template<typename DescriptorClass>
void MVKDescriptorTypePreallocation<DescriptorClass>::reset() {
_nextAvailableIndex = 0;
}

template<typename DescriptorClass>
MVKDescriptorTypePreallocation<DescriptorClass>::MVKDescriptorTypePreallocation(const VkDescriptorPoolCreateInfo* pCreateInfo,
VkDescriptorType descriptorType) {
Expand Down Expand Up @@ -466,6 +471,21 @@ static inline bool getMVKPreallocateDescriptors() {
}
}

void MVKPreallocatedDescriptors::reset() {
_uniformBufferDescriptors.reset();
_storageBufferDescriptors.reset();
_uniformBufferDynamicDescriptors.reset();
_storageBufferDynamicDescriptors.reset();
_inlineUniformBlockDescriptors.reset();
_sampledImageDescriptors.reset();
_storageImageDescriptors.reset();
_inputAttachmentDescriptors.reset();
_samplerDescriptors.reset();
_combinedImageSamplerDescriptors.reset();
_uniformTexelBufferDescriptors.reset();
_storageTexelBufferDescriptors.reset();
}

MVKPreallocatedDescriptors::MVKPreallocatedDescriptors(const VkDescriptorPoolCreateInfo* pCreateInfo) :
_uniformBufferDescriptors(pCreateInfo, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER),
_storageBufferDescriptors(pCreateInfo, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER),
Expand Down Expand Up @@ -521,6 +541,7 @@ static inline bool getMVKPreallocateDescriptors() {
VkResult MVKDescriptorPool::reset(VkDescriptorPoolResetFlags flags) {
for (auto& mvkDS : _allocatedSets) { freeDescriptorSet(mvkDS); }
_allocatedSets.clear();
if (_preallocatedDescriptors) { _preallocatedDescriptors->reset(); }
return VK_SUCCESS;
}

Expand Down

0 comments on commit 0d94a8e

Please sign in to comment.