Reduce heap allocations during rendering

This commit is contained in:
aerofly 2018-12-18 15:59:49 +01:00
parent d4506cc41e
commit d87b71887e
10 changed files with 22 additions and 17 deletions

View File

@ -129,7 +129,7 @@ private:
MVKPipelineLayout* _pipelineLayout; MVKPipelineLayout* _pipelineLayout;
VkShaderStageFlags _stageFlags; VkShaderStageFlags _stageFlags;
uint32_t _offset; uint32_t _offset;
MVKVector<char> _pushConstants; MVKVector128<char> _pushConstants;
}; };
@ -157,7 +157,7 @@ private:
VkPipelineBindPoint _pipelineBindPoint; VkPipelineBindPoint _pipelineBindPoint;
MVKPipelineLayout* _pipelineLayout; MVKPipelineLayout* _pipelineLayout;
std::vector<VkWriteDescriptorSet> _descriptorWrites; MVKVector<VkWriteDescriptorSet> _descriptorWrites;
uint32_t _set; uint32_t _set;
}; };

View File

@ -189,7 +189,7 @@ class MVKPushConstantsCommandEncoderState : public MVKCommandEncoderState {
public: public:
/** Sets the specified push constants. */ /** Sets the specified push constants. */
void setPushConstants(uint32_t offset, MVKVector<char>& pushConstants); void setPushConstants(uint32_t offset, MVKVector128<char>& pushConstants);
/** Sets the index of the Metal buffer used to hold the push constants. */ /** Sets the index of the Metal buffer used to hold the push constants. */
void setMTLBufferIndex(uint32_t mtlBufferIndex); void setMTLBufferIndex(uint32_t mtlBufferIndex);
@ -203,7 +203,7 @@ protected:
void encodeImpl() override; void encodeImpl() override;
void resetImpl() override; void resetImpl() override;
MVKVector<char> _pushConstants; MVKVector128<char> _pushConstants;
VkShaderStageFlagBits _shaderStage; VkShaderStageFlagBits _shaderStage;
uint32_t _mtlBufferIndex = 0; uint32_t _mtlBufferIndex = 0;
}; };

View File

@ -136,7 +136,7 @@ void MVKScissorCommandEncoderState::resetImpl() {
#pragma mark - #pragma mark -
#pragma mark MVKPushConstantsCommandEncoderState #pragma mark MVKPushConstantsCommandEncoderState
void MVKPushConstantsCommandEncoderState:: setPushConstants(uint32_t offset, MVKVector<char>& pushConstants) { void MVKPushConstantsCommandEncoderState:: setPushConstants(uint32_t offset, MVKVector128<char>& pushConstants) {
uint32_t pcCnt = (uint32_t)pushConstants.size(); uint32_t pcCnt = (uint32_t)pushConstants.size();
mvkEnsureSize(_pushConstants, offset + pcCnt); mvkEnsureSize(_pushConstants, offset + pcCnt);
copy(pushConstants.begin(), pushConstants.end(), _pushConstants.begin() + offset); copy(pushConstants.begin(), pushConstants.end(), _pushConstants.begin() + offset);

View File

@ -138,7 +138,7 @@ public:
/** Encodes this descriptor set layout and the specified descriptor updates on the specified command encoder immediately. */ /** Encodes this descriptor set layout and the specified descriptor updates on the specified command encoder immediately. */
void pushDescriptorSet(MVKCommandEncoder* cmdEncoder, void pushDescriptorSet(MVKCommandEncoder* cmdEncoder,
std::vector<VkWriteDescriptorSet>& descriptorWrites, MVKVector<VkWriteDescriptorSet>& descriptorWrites,
MVKShaderResourceBinding& dslMTLRezIdxOffsets); MVKShaderResourceBinding& dslMTLRezIdxOffsets);

View File

@ -542,7 +542,7 @@ static const void* getWriteParameters(VkDescriptorType type, const VkDescriptorI
} }
void MVKDescriptorSetLayout::pushDescriptorSet(MVKCommandEncoder* cmdEncoder, void MVKDescriptorSetLayout::pushDescriptorSet(MVKCommandEncoder* cmdEncoder,
vector<VkWriteDescriptorSet>& descriptorWrites, MVKVector<VkWriteDescriptorSet>& descriptorWrites,
MVKShaderResourceBinding& dslMTLRezIdxOffsets) { MVKShaderResourceBinding& dslMTLRezIdxOffsets) {
if (!_isPushDescriptorLayout) return; if (!_isPushDescriptorLayout) return;

View File

@ -20,8 +20,8 @@
#include "MVKResource.h" #include "MVKResource.h"
#include "MVKSync.h" #include "MVKSync.h"
#include "MVKVector.h"
#include <mutex> #include <mutex>
#include <list>
#import <IOSurface/IOSurfaceRef.h> #import <IOSurface/IOSurfaceRef.h>
@ -397,7 +397,7 @@ protected:
uint32_t _swapchainIndex; uint32_t _swapchainIndex;
id<CAMetalDrawable> _mtlDrawable; id<CAMetalDrawable> _mtlDrawable;
std::mutex _availabilityLock; std::mutex _availabilityLock;
std::list<MVKSwapchainSignaler> _availabilitySignalers; MVKVector<MVKSwapchainSignaler> _availabilitySignalers;
MVKSwapchainSignaler _preSignaled; MVKSwapchainSignaler _preSignaled;
MVKSwapchainImageAvailability _availability; MVKSwapchainImageAvailability _availability;
}; };

View File

@ -1000,7 +1000,8 @@ void MVKSwapchainImage::makeAvailable() {
// If this image is not yet available, extract and signal the first semaphore and fence. // If this image is not yet available, extract and signal the first semaphore and fence.
signaler = _availabilitySignalers.front(); signaler = _availabilitySignalers.front();
_availabilitySignalers.pop_front(); _availabilitySignalers.erase( _availabilitySignalers.begin() );
//_availabilitySignalers.pop_front();
} }
// Signal the semaphore and fence, and let them know they are no longer being tracked. // Signal the semaphore and fence, and let them know they are no longer being tracked.

View File

@ -25,7 +25,6 @@
#include "MVKVector.h" #include "MVKVector.h"
#include <MoltenVKSPIRVToMSLConverter/SPIRVToMSLConverter.h> #include <MoltenVKSPIRVToMSLConverter/SPIRVToMSLConverter.h>
#include <unordered_set> #include <unordered_set>
#include <vector>
#include <ostream> #include <ostream>
#import <Metal/Metal.h> #import <Metal/Metal.h>
@ -63,7 +62,7 @@ public:
/** Updates a descriptor set in a command encoder. */ /** Updates a descriptor set in a command encoder. */
void pushDescriptorSet(MVKCommandEncoder* cmdEncoder, void pushDescriptorSet(MVKCommandEncoder* cmdEncoder,
std::vector<VkWriteDescriptorSet>& descriptorWrites, MVKVector<VkWriteDescriptorSet>& descriptorWrites,
uint32_t set); uint32_t set);
/** Updates a descriptor set from a template in a command encoder. */ /** Updates a descriptor set from a template in a command encoder. */
@ -82,9 +81,9 @@ public:
MVKPipelineLayout(MVKDevice* device, const VkPipelineLayoutCreateInfo* pCreateInfo); MVKPipelineLayout(MVKDevice* device, const VkPipelineLayoutCreateInfo* pCreateInfo);
protected: protected:
std::vector<MVKDescriptorSetLayout> _descriptorSetLayouts; MVKVector<MVKDescriptorSetLayout> _descriptorSetLayouts;
std::vector<MVKShaderResourceBinding> _dslMTLResourceIndexOffsets; MVKVector<MVKShaderResourceBinding> _dslMTLResourceIndexOffsets;
std::vector<VkPushConstantRange> _pushConstants; MVKVector<VkPushConstantRange> _pushConstants;
MVKShaderResourceBinding _pushConstantsMTLResourceIndexes; MVKShaderResourceBinding _pushConstantsMTLResourceIndexes;
MVKShaderAuxBufferBinding _auxBufferIndex; MVKShaderAuxBufferBinding _auxBufferIndex;
}; };

View File

@ -55,7 +55,7 @@ void MVKPipelineLayout::bindDescriptorSets(MVKCommandEncoder* cmdEncoder,
} }
void MVKPipelineLayout::pushDescriptorSet(MVKCommandEncoder* cmdEncoder, void MVKPipelineLayout::pushDescriptorSet(MVKCommandEncoder* cmdEncoder,
vector<VkWriteDescriptorSet>& descriptorWrites, MVKVector<VkWriteDescriptorSet>& descriptorWrites,
uint32_t set) { uint32_t set) {
_descriptorSetLayouts[set].pushDescriptorSet(cmdEncoder, descriptorWrites, _descriptorSetLayouts[set].pushDescriptorSet(cmdEncoder, descriptorWrites,

View File

@ -456,7 +456,7 @@ public:
{ {
--alc.num_elements_used; --alc.num_elements_used;
for( size_t i = it.GetIndex(); i < alc.num_elements_used; ++i ) for( size_t i = it.get_position(); i < alc.num_elements_used; ++i )
{ {
alc.ptr[i] = std::move( alc.ptr[i + 1] ); alc.ptr[i] = std::move( alc.ptr[i + 1] );
} }
@ -524,5 +524,10 @@ public:
} }
}; };
template<typename Type>
using MVKVector128 = MVKVector<Type, mvk_vector_allocator_with_stack<Type, 128>>;
#endif #endif