Remove private flag from MVKCommandEncoder::copyToTempMTLBufferAllocation().

MVKMTLBufferAllocationPool subclass from MVKDeviceTrackingMixin.
MVKDeviceObjectPool subclass from MVKDeviceTrackingMixin.
This commit is contained in:
Bill Hollings 2021-03-22 07:51:07 -04:00
parent ef1990306d
commit 55a2fe6467
5 changed files with 13 additions and 11 deletions

View File

@ -373,7 +373,7 @@ public:
const MVKMTLBufferAllocation* getTempMTLBuffer(NSUInteger length, bool isPrivate = false, bool isDedicated = false);
/** Copy the bytes to a temporary MTLBuffer that will be returned to a pool after the command buffer is finished. */
const MVKMTLBufferAllocation* copyToTempMTLBufferAllocation(const void* bytes, NSUInteger length, bool isPrivate = false, bool isDedicated = false);
const MVKMTLBufferAllocation* copyToTempMTLBufferAllocation(const void* bytes, NSUInteger length, bool isDedicated = false);
/** Returns the command encoding pool. */
MVKCommandEncodingPool* getCommandEncodingPool();

View File

@ -659,8 +659,8 @@ MVKCommandEncodingPool* MVKCommandEncoder::getCommandEncodingPool() {
}
// Copies the specified bytes into a temporary allocation within a pooled MTLBuffer, and returns the MTLBuffer allocation.
const MVKMTLBufferAllocation* MVKCommandEncoder::copyToTempMTLBufferAllocation(const void* bytes, NSUInteger length, bool isPrivate, bool isDedicated) {
const MVKMTLBufferAllocation* mtlBuffAlloc = getTempMTLBuffer(length, isPrivate, isDedicated);
const MVKMTLBufferAllocation* MVKCommandEncoder::copyToTempMTLBufferAllocation(const void* bytes, NSUInteger length, bool isDedicated) {
const MVKMTLBufferAllocation* mtlBuffAlloc = getTempMTLBuffer(length, false, isDedicated);
void* pBuffData = mtlBuffAlloc->getContents();
mlock(pBuffData, length);
memcpy(pBuffData, bytes, length);

View File

@ -75,7 +75,7 @@ protected:
* To return a MVKMTLBufferAllocation retrieved from this pool, back to this pool,
* call the returnToPool() function on the MVKMTLBufferAllocation instance.
*/
class MVKMTLBufferAllocationPool : public MVKObjectPool<MVKMTLBufferAllocation> {
class MVKMTLBufferAllocationPool : public MVKObjectPool<MVKMTLBufferAllocation>, public MVKDeviceTrackingMixin {
public:
@ -91,6 +91,7 @@ public:
protected:
friend class MVKMTLBufferAllocation;
MVKBaseObject* getBaseObject() override { return this; };
MVKMTLBufferAllocation* newObject() override;
void returnAllocation(MVKMTLBufferAllocation* ba) { _isThreadSafe ? returnObjectSafely(ba) : returnObject(ba); }
uint32_t calcMTLBufferAllocationCount();
@ -101,7 +102,6 @@ protected:
NSUInteger _mtlBufferLength;
MTLStorageMode _mtlStorageMode;
MVKSmallVector<id<MTLBuffer>, 64> _mtlBuffers;
MVKDevice* _device;
bool _isThreadSafe;
};

View File

@ -51,8 +51,10 @@ void MVKMTLBufferAllocationPool::addMTLBuffer() {
MVKMTLBufferAllocationPool::MVKMTLBufferAllocationPool(MVKDevice* device, NSUInteger allocationLength, bool makeThreadSafe,
bool isDedicated, MTLStorageMode mtlStorageMode) : MVKObjectPool<MVKMTLBufferAllocation>(true) {
_device = device;
bool isDedicated, MTLStorageMode mtlStorageMode) :
MVKObjectPool<MVKMTLBufferAllocation>(true),
MVKDeviceTrackingMixin(device) {
_allocationLength = allocationLength;
_isThreadSafe = makeThreadSafe;
_mtlBufferLength = _allocationLength * (isDedicated ? 1 : calcMTLBufferAllocationCount());

View File

@ -892,6 +892,7 @@ public:
protected:
MVKBaseObject* getBaseObject() override { return this; };
};
@ -929,11 +930,10 @@ protected:
/** Manages a pool of instances of a particular object type that requires an MVKDevice during construction. */
template <class T>
class MVKDeviceObjectPool : public MVKObjectPool<T> {
class MVKDeviceObjectPool : public MVKObjectPool<T>, public MVKDeviceTrackingMixin {
public:
/** Returns the Vulkan API opaque object controlling this object. */
MVKVulkanAPIObject* getVulkanAPIObject() override { return _device; };
@ -941,12 +941,12 @@ public:
* Configures this instance for the device, and either use pooling, or not, depending
* on the value of isPooling, which defaults to true if not indicated explicitly.
*/
MVKDeviceObjectPool(MVKDevice* device, bool isPooling = true) : MVKObjectPool<T>(isPooling), _device(device) {}
MVKDeviceObjectPool(MVKDevice* device, bool isPooling = true) : MVKObjectPool<T>(isPooling), MVKDeviceTrackingMixin(device) {}
protected:
T* newObject() override { return new T(_device); }
MVKBaseObject* getBaseObject() override { return this; };
MVKDevice* _device;
};