Skip to content
Permalink
Browse files
8261549: Adjust memory size in MTLTexurePool.m
Reviewed-by: prr
  • Loading branch information
Alexey Ushakov committed Jun 7, 2021
1 parent e663ba9 commit 7e55569edee84dcae63fbdf1f89fefa554360736
Showing with 14 additions and 4 deletions.
  1. +14 −4 src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLTexurePool.m
@@ -26,8 +26,7 @@
#import "MTLTexturePool.h"
#import "Trace.h"

#define SCREEN_MEMORY_SIZE_4K (4096*2160*4) //~33,7 mb
#define MAX_POOL_MEMORY SCREEN_MEMORY_SIZE_4K/2
#define SCREEN_MEMORY_SIZE_5K (5120*4096*4) //~84 mb
#define MAX_POOL_ITEM_LIFETIME_SEC 30

#define CELL_WIDTH_BITS 5 // ~ 32 pixel
@@ -305,6 +304,7 @@ @implementation MTLTexturePool {
void ** _cells;
int _poolCellWidth;
int _poolCellHeight;
uint64_t _maxPoolMemory;
}

@synthesize device;
@@ -320,6 +320,16 @@ - (id) initWithDevice:(id<MTLDevice>)dev {
_cells = (void **)malloc(cellsCount * sizeof(void*));
memset(_cells, 0, cellsCount * sizeof(void*));
self.device = dev;

// recommendedMaxWorkingSetSize typically greatly exceeds SCREEN_MEMORY_SIZE_5K constant.
// It usually corresponds to the VRAM available to the graphics card
_maxPoolMemory = self.device.recommendedMaxWorkingSetSize/2;

// Set maximum to handle at least 5K screen size
if (_maxPoolMemory < SCREEN_MEMORY_SIZE_5K) {
_maxPoolMemory = SCREEN_MEMORY_SIZE_5K;
}

return self;
}

@@ -345,9 +355,9 @@ - (MTLPooledTextureHandle *) getTexture:(int)width height:(int)height format:(MT
// 1. clean pool if necessary
const int requestedPixels = width*height;
const int requestedBytes = requestedPixels*4;
if (_memoryTotalAllocated + requestedBytes > MAX_POOL_MEMORY) {
if (_memoryTotalAllocated + requestedBytes > _maxPoolMemory) {
[self cleanIfNecessary:0]; // release all free textures
} else if (_memoryTotalAllocated + requestedBytes > MAX_POOL_MEMORY/2) {
} else if (_memoryTotalAllocated + requestedBytes > _maxPoolMemory/2) {
[self cleanIfNecessary:MAX_POOL_ITEM_LIFETIME_SEC]; // release only old free textures
}

1 comment on commit 7e55569

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on 7e55569 Jun 7, 2021

Please sign in to comment.