Skip to content

Commit af3639f

Browse files
YaaZjbrbot
authored and
jbrbot
committed
JBR-7766 Fix VKTexturePool OOM.
1 parent 993236d commit af3639f

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/java.desktop/share/native/common/java2d/vulkan/VKAllocator.c

+8
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,14 @@ void VKAllocator_FindMemoryType(VKMemoryRequirements* requirements,
191191
static uint32_t VKAllocator_AllocatePage(VKAllocator* alloc, uint32_t memoryType, VkDeviceSize size,
192192
VkImage dedicatedImage, VkBuffer dedicatedBuffer) {
193193
assert(alloc != NULL);
194+
assert(memoryType < VK_MAX_MEMORY_TYPES);
195+
196+
uint32_t heapIndex = alloc->memoryProperties.memoryTypes[memoryType].heapIndex;
197+
VkDeviceSize heapSize = alloc->memoryProperties.memoryHeaps[heapIndex].size;
198+
if (size > heapSize) {
199+
J2dRlsTraceLn3(J2D_TRACE_ERROR, "VKAllocator_AllocatePage: not enough memory in heap, heapIndex=%d, heapSize=%d, size=%d", heapIndex, heapSize, size);
200+
return NO_PAGE_INDEX;
201+
}
194202

195203
// Allocate memory.
196204
VkBool32 dedicated = dedicatedImage != VK_NULL_HANDLE || dedicatedBuffer != VK_NULL_HANDLE;

src/java.desktop/share/native/common/java2d/vulkan/VKTexturePool.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ void VKTexturePoolLock_unlockImpl(ATexturePoolLockPrivPtr *lock) {
7373
}
7474

7575
static void VKTexturePool_FindImageMemoryType(VKMemoryRequirements* requirements) {
76-
// TODO both DEVICE_LOCAL and HOST_VISIBLE memory is very precious, we may need to use just DEVICE_LOCAL instead.
77-
VKAllocator_FindMemoryType(requirements, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, VK_ALL_MEMORY_PROPERTIES);
76+
VKAllocator_FindMemoryType(requirements, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, VK_ALL_MEMORY_PROPERTIES);
7877
}
7978

8079
/* Texture allocate/free API */

0 commit comments

Comments
 (0)