Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8253931: Lanai: MTLTexturePool refactoring
  • Loading branch information
Alexey Ushakov committed Oct 5, 2020
1 parent dd9a5fb commit 454fe1949d908f045da292a889350e6167c171e2
@@ -50,13 +50,15 @@
@implementation MTLCommandBufferWrapper {
id<MTLCommandBuffer> _commandBuffer;
NSMutableArray * _pooledTextures;
NSLock* _lock;
}

- (id) initWithCommandBuffer:(id<MTLCommandBuffer>)cmdBuf {
self = [super init];
if (self) {
_commandBuffer = [cmdBuf retain];
_pooledTextures = [[NSMutableArray alloc] init];
_lock = [[NSLock alloc] init];
}
return self;
}
@@ -66,20 +68,32 @@ - (id) initWithCommandBuffer:(id<MTLCommandBuffer>)cmdBuf {
}

- (void) onComplete { // invoked from completion handler in some pooled thread
for (int c = 0; c < [_pooledTextures count]; ++c)
[[_pooledTextures objectAtIndex:c] releaseTexture];
[_pooledTextures removeAllObjects];
[_lock lock];
@try {
for (int c = 0; c < [_pooledTextures count]; ++c)
[[_pooledTextures objectAtIndex:c] releaseTexture];
[_pooledTextures removeAllObjects];
} @finally {
[_lock unlock];
}

}

- (void) registerPooledTexture:(MTLPooledTextureHandle *)handle {
[_pooledTextures addObject:handle];
[_lock lock];
@try {
[_pooledTextures addObject:handle];
} @finally {
[_lock unlock];
}
}

- (void) dealloc {
[self onComplete];

[self->_pooledTextures release];
[self->_commandBuffer release];
[_pooledTextures release];
[_commandBuffer release];
[_lock release];
[super dealloc];
}

@@ -1,14 +1,21 @@
#ifndef MTLTexturePool_h_Included
#define MTLTexturePool_h_Included
#include <time.h>
#import "MTLUtils.h"

@class MTLPoolCell;

@interface MTLTexturePoolItem : NSObject
@property (readwrite, retain) id<MTLTexture> texture;
@property (readwrite) bool isBusy;
@property (readwrite, retain) NSDate * lastUsed;
@property (readwrite) NSTimeInterval lastUsed;
@property (readwrite) bool isMultiSample;
@property (readwrite, assign) MTLTexturePoolItem* prev;
@property (readwrite, retain) MTLTexturePoolItem* next;
@property (readwrite, assign) MTLPoolCell* cell;

- (id) initWithTexture:(id<MTLTexture>)tex;
- (id) initWithTexture:(id<MTLTexture>)tex cell:(MTLPoolCell*)cell;
- (void) releaseTexture;
@end

@interface MTLPooledTextureHandle : NSObject
@@ -27,4 +34,12 @@
isMultiSample:(bool)isMultiSample;
@end

@interface MTLPoolCell : NSObject
@property (readwrite, retain) MTLTexturePoolItem* available;
@property (readwrite, retain) MTLTexturePoolItem* occupied;
- (MTLTexturePoolItem*) createItem:(id<MTLTexture>) texture;
- (NSUInteger)cleanIfBefore:(time_t)lastUsedTimeToRemove;
- (void)releaseItem:(MTLTexturePoolItem *)item;
@end

#endif /* MTLTexturePool_h_Included */

0 comments on commit 454fe19

Please sign in to comment.