vk: improve memory allocation logging
print region names, requirements, etc. also decrease default vulkan device memory allocation size to 64Mb decrease max vertices to 512k
This commit is contained in:
parent
a5f22ca11d
commit
951d382eb6
|
@ -30,9 +30,7 @@ qboolean VK_BufferCreate(const char *debug_name, vk_buffer_t *buf, uint32_t size
|
|||
SET_DEBUG_NAME(buf->buffer, VK_OBJECT_TYPE_BUFFER, debug_name);
|
||||
|
||||
vkGetBufferMemoryRequirements(vk_core.device, buf->buffer, &memreq);
|
||||
gEngine.Con_Reportf("memreq: memoryTypeBits=0x%x alignment=%zu size=%zu\n", memreq.memoryTypeBits, memreq.alignment, memreq.size);
|
||||
|
||||
buf->devmem = VK_DevMemAllocate(memreq, flags, usage & VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT ? VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT : 0);
|
||||
buf->devmem = VK_DevMemAllocate(debug_name, memreq, flags, usage & VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT ? VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT : 0);
|
||||
XVK_CHECK(vkBindBufferMemory(vk_core.device, buf->buffer, buf->devmem.device_memory, buf->devmem.offset));
|
||||
|
||||
buf->mapped = buf->devmem.mapped;
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#define MAX_TEXTURES 4096
|
||||
|
||||
// TODO count these properly
|
||||
#define MAX_BUFFER_VERTICES (1 * 1024 * 1024)
|
||||
#define MAX_BUFFER_VERTICES (512 * 1024)
|
||||
#define MAX_BUFFER_INDICES (MAX_BUFFER_VERTICES * 3)
|
||||
|
||||
// indexed by uint8_t
|
||||
|
|
|
@ -457,7 +457,9 @@ static void devicePrintMemoryInfo(const VkPhysicalDeviceMemoryProperties *props,
|
|||
gEngine.Con_Printf("Memory types: %d\n", props->memoryTypeCount);
|
||||
for (int i = 0; i < (int)props->memoryTypeCount; ++i) {
|
||||
const VkMemoryType* const type = props->memoryTypes + i;
|
||||
gEngine.Con_Printf(" %d: heap=%d flags=%c%c%c%c%c\n", i, type->heapIndex,
|
||||
gEngine.Con_Printf(" %d: bit=0x%x heap=%d flags=%c%c%c%c%c\n", i,
|
||||
(1 << i),
|
||||
type->heapIndex,
|
||||
type->propertyFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT ? 'D' : '.',
|
||||
type->propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT ? 'V' : '.',
|
||||
type->propertyFlags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT ? 'C' : '.',
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
#include "vk_devmem.h"
|
||||
#include "alolcator.h"
|
||||
|
||||
#define MAX_DEVMEM_ALLOCS 8
|
||||
#define MAX_DEVMEM_ALLOCS 16
|
||||
#define DEFAULT_ALLOCATION_SIZE (64 * 1024 * 1024)
|
||||
|
||||
typedef struct {
|
||||
uint32_t type_bit;
|
||||
|
@ -33,8 +34,6 @@ static int findMemoryWithType(uint32_t type_index_bits, VkMemoryPropertyFlags fl
|
|||
return UINT32_MAX;
|
||||
}
|
||||
|
||||
#define DEFAULT_ALLOCATION_SIZE (128 * 1024 * 1024)
|
||||
|
||||
static VkDeviceSize optimalSize(VkDeviceSize size) {
|
||||
if (size < DEFAULT_ALLOCATION_SIZE)
|
||||
return DEFAULT_ALLOCATION_SIZE;
|
||||
|
@ -47,7 +46,6 @@ static VkDeviceSize optimalSize(VkDeviceSize size) {
|
|||
}
|
||||
|
||||
static int allocateDeviceMemory(VkMemoryRequirements req, VkMemoryPropertyFlags prop_flags, VkMemoryAllocateFlags allocate_flags) {
|
||||
//static int allocateDeviceMemory(VkDeviceSize size, uint32_t type_bits, VkMemoryAllocateFlags flags, VkMemoryPropertyFlags prop_flags) {
|
||||
if (g_vk_devmem.num_allocs == MAX_DEVMEM_ALLOCS)
|
||||
return -1;
|
||||
|
||||
|
@ -64,7 +62,7 @@ static int allocateDeviceMemory(VkMemoryRequirements req, VkMemoryPropertyFlags
|
|||
.memoryTypeIndex = findMemoryWithType(req.memoryTypeBits, prop_flags),
|
||||
};
|
||||
|
||||
gEngine.Con_Reportf("allocateDeviceMemory size=%zu memoryTypeBits=0x%x memoryProperties=%c%c%c%c%c allocate_flags=0x%x prop_flags=0x%x => typeIndex=%d\n",
|
||||
gEngine.Con_Reportf("allocateDeviceMemory size=%zu memoryTypeBits=0x%x prop_flags=%c%c%c%c%c allocate_flags=0x%x => typeIndex=%d\n",
|
||||
mai.allocationSize, req.memoryTypeBits,
|
||||
prop_flags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT ? 'D' : '.',
|
||||
prop_flags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT ? 'V' : '.',
|
||||
|
@ -72,7 +70,6 @@ static int allocateDeviceMemory(VkMemoryRequirements req, VkMemoryPropertyFlags
|
|||
prop_flags & VK_MEMORY_PROPERTY_HOST_CACHED_BIT ? '$' : '.',
|
||||
prop_flags & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT ? 'L' : '.',
|
||||
allocate_flags,
|
||||
prop_flags,
|
||||
mai.memoryTypeIndex);
|
||||
ASSERT(mai.memoryTypeIndex != UINT32_MAX);
|
||||
|
||||
|
@ -96,11 +93,20 @@ static int allocateDeviceMemory(VkMemoryRequirements req, VkMemoryPropertyFlags
|
|||
return g_vk_devmem.num_allocs++;
|
||||
}
|
||||
|
||||
vk_devmem_t VK_DevMemAllocate(VkMemoryRequirements req, VkMemoryPropertyFlags prop_flags, VkMemoryAllocateFlags allocate_flags) {
|
||||
vk_devmem_t VK_DevMemAllocate(const char *name, VkMemoryRequirements req, VkMemoryPropertyFlags prop_flags, VkMemoryAllocateFlags allocate_flags) {
|
||||
vk_devmem_t ret = {0};
|
||||
int device_memory_index = -1;
|
||||
alo_block_t block;
|
||||
|
||||
gEngine.Con_Reportf("VK_DevMemAllocate name=\"%s\" size=%zu alignment=%zu memoryTypeBits=0x%x prop_flags=%c%c%c%c%c allocate_flags=0x%x\n",
|
||||
name, req.size, req.alignment, req.memoryTypeBits,
|
||||
prop_flags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT ? 'D' : '.',
|
||||
prop_flags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT ? 'V' : '.',
|
||||
prop_flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT ? 'C' : '.',
|
||||
prop_flags & VK_MEMORY_PROPERTY_HOST_CACHED_BIT ? '$' : '.',
|
||||
prop_flags & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT ? 'L' : '.',
|
||||
allocate_flags);
|
||||
|
||||
if (vk_core.rtx) {
|
||||
// TODO this is needed only for the ray tracer and only while there's no proper staging
|
||||
// Once staging is established, we can avoid forcing this on every devmem allocation
|
||||
|
@ -140,7 +146,7 @@ vk_devmem_t VK_DevMemAllocate(VkMemoryRequirements req, VkMemoryPropertyFlags pr
|
|||
vk_device_memory_t *const device_memory = g_vk_devmem.allocs + device_memory_index;
|
||||
ret.device_memory = device_memory->device_memory;
|
||||
ret.offset = block.offset;
|
||||
ret.mapped = device_memory->map ? device_memory->map + block.offset : NULL;
|
||||
ret.mapped = device_memory->map ? (char*)device_memory->map + block.offset : NULL;
|
||||
|
||||
gEngine.Con_Reportf("Allocated devmem=%d block=%d offset=%d size=%d\n", device_memory_index, block.index, (int)block.offset, (int)block.size);
|
||||
|
||||
|
|
|
@ -12,5 +12,5 @@ typedef struct vk_devmem_s {
|
|||
struct { int devmem, block; } priv_;
|
||||
} vk_devmem_t;
|
||||
|
||||
vk_devmem_t VK_DevMemAllocate(VkMemoryRequirements req, VkMemoryPropertyFlags props, VkMemoryAllocateFlags flags);
|
||||
vk_devmem_t VK_DevMemAllocate(const char *name, VkMemoryRequirements req, VkMemoryPropertyFlags props, VkMemoryAllocateFlags flags);
|
||||
void VK_DevMemFree(const vk_devmem_t *mem);
|
||||
|
|
|
@ -112,7 +112,7 @@ static void createDepthImage(int w, int h) {
|
|||
SET_DEBUG_NAME(g_frame.depth.image, VK_OBJECT_TYPE_IMAGE, "depth buffer");
|
||||
|
||||
vkGetImageMemoryRequirements(vk_core.device, g_frame.depth.image, &memreq);
|
||||
g_frame.depth.device_memory = VK_DevMemAllocate(memreq, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, 0);
|
||||
g_frame.depth.device_memory = VK_DevMemAllocate("depth buffer", memreq, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, 0);
|
||||
XVK_CHECK(vkBindImageMemory(vk_core.device, g_frame.depth.image, g_frame.depth.device_memory.device_memory, g_frame.depth.device_memory.offset));
|
||||
|
||||
{
|
||||
|
@ -611,7 +611,7 @@ static rgbdata_t *XVK_ReadPixels( void ) {
|
|||
{
|
||||
VkMemoryRequirements memreq;
|
||||
vkGetImageMemoryRequirements(vk_core.device, dest_image, &memreq);
|
||||
dest_devmem = VK_DevMemAllocate(memreq, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT, 0);
|
||||
dest_devmem = VK_DevMemAllocate("screenshot", memreq, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT, 0);
|
||||
XVK_CHECK(vkBindImageMemory(vk_core.device, dest_image, dest_devmem.device_memory, dest_devmem.offset));
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ xvk_image_t XVK_ImageCreate(const xvk_image_create_t *create) {
|
|||
SET_DEBUG_NAME(image.image, VK_OBJECT_TYPE_IMAGE, create->debug_name);
|
||||
|
||||
vkGetImageMemoryRequirements(vk_core.device, image.image, &memreq);
|
||||
image.devmem = VK_DevMemAllocate(memreq, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, 0);
|
||||
image.devmem = VK_DevMemAllocate(create->debug_name, memreq, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, 0);
|
||||
XVK_CHECK(vkBindImageMemory(vk_core.device, image.image, image.devmem.device_memory, image.devmem.offset));
|
||||
|
||||
ivci.viewType = create->is_cubemap ? VK_IMAGE_VIEW_TYPE_CUBE : VK_IMAGE_VIEW_TYPE_2D;
|
||||
|
|
Loading…
Reference in New Issue