add debug names to various objects
This commit is contained in:
parent
ddd7403bd0
commit
6614a6935b
|
@ -1,9 +1,11 @@
|
|||
## 2021-05-..-17, E93, E94
|
||||
- [x] rtx: improve AS lifetime/management; i.e. pre-cache them, etc
|
||||
- [x] add debug names to all of the buffers
|
||||
|
||||
## 2021-05-10, E93
|
||||
- [x] rtx: don't recreate tlas each frame
|
||||
|
||||
# Next
|
||||
- [ ] rtx: improve AS lifetime/management; i.e. pre-cache them, etc
|
||||
- [ ] add debug names to all of the buffers
|
||||
- [ ] nvnsight into buffer memory and stuff
|
||||
- [ ] rtx: build acceleration structures in a single queue/cmdbuf
|
||||
- [ ] studio models: pre-compute buffer sizes and allocate them at once
|
||||
|
|
|
@ -261,7 +261,7 @@ qboolean initVk2d( void )
|
|||
if (!createPipelines())
|
||||
return false;
|
||||
|
||||
if (!createBuffer(&g2d.pics_buffer, sizeof(vertex_2d_t) * (MAX_PICS * 6),
|
||||
if (!createBuffer("2d pics_buffer", &g2d.pics_buffer, sizeof(vertex_2d_t) * (MAX_PICS * 6),
|
||||
VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT ))
|
||||
// FIXME cleanup
|
||||
return false;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
#include <memory.h>
|
||||
|
||||
qboolean createBuffer(vk_buffer_t *buf, uint32_t size, VkBufferUsageFlags usage, VkMemoryPropertyFlags flags)
|
||||
qboolean createBuffer(const char *debug_name, vk_buffer_t *buf, uint32_t size, VkBufferUsageFlags usage, VkMemoryPropertyFlags flags)
|
||||
{
|
||||
VkBufferCreateInfo bci = {
|
||||
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
|
||||
|
@ -12,6 +12,7 @@ qboolean createBuffer(vk_buffer_t *buf, uint32_t size, VkBufferUsageFlags usage,
|
|||
};
|
||||
VkMemoryRequirements memreq;
|
||||
XVK_CHECK(vkCreateBuffer(vk_core.device, &bci, NULL, &buf->buffer));
|
||||
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);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
#include "vk_core.h"
|
||||
|
||||
qboolean createBuffer(vk_buffer_t *buf, uint32_t size, VkBufferUsageFlags usage, VkMemoryPropertyFlags flags);
|
||||
qboolean createBuffer(const char *debug_name, vk_buffer_t *buf, uint32_t size, VkBufferUsageFlags usage, VkMemoryPropertyFlags flags);
|
||||
void destroyBuffer(vk_buffer_t *buf);
|
||||
|
||||
|
||||
|
|
|
@ -558,7 +558,7 @@ qboolean R_VkInit( void )
|
|||
if (!createCommandPool())
|
||||
return false;
|
||||
|
||||
if (!createBuffer(&vk_core.staging, 16 * 1024 * 1024 /* TODO why 16Mb? */, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))
|
||||
if (!createBuffer("staging", &vk_core.staging, 16 * 1024 * 1024 /* TODO why 16Mb? */, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))
|
||||
return false;
|
||||
|
||||
{
|
||||
|
|
|
@ -79,6 +79,19 @@ extern vulkan_core_t vk_core;
|
|||
|
||||
const char *resultName(VkResult result);
|
||||
|
||||
#define SET_DEBUG_NAME(object, type, name) \
|
||||
do { \
|
||||
if (vk_core.debug) { \
|
||||
VkDebugUtilsObjectNameInfoEXT duoni = { \
|
||||
.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT, \
|
||||
.objectHandle = (uint64_t)object, \
|
||||
.objectType = type, \
|
||||
.pObjectName = name, \
|
||||
}; \
|
||||
XVK_CHECK(vkSetDebugUtilsObjectNameEXT(vk_core.device, &duoni)); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
// TODO make this not fatal: devise proper error handling strategies
|
||||
// FIXME Host_Error does not cause process to exit, we need to handle this manually
|
||||
#define XVK_CHECK(f) do { \
|
||||
|
|
|
@ -257,12 +257,12 @@ qboolean VK_RenderInit( void )
|
|||
|
||||
// TODO device memory and friends (e.g. handle mobile memory ...)
|
||||
|
||||
if (!createBuffer(&g_render.buffer, vertex_buffer_size + index_buffer_size,
|
||||
if (!createBuffer("render buffer", &g_render.buffer, vertex_buffer_size + index_buffer_size,
|
||||
VK_BUFFER_USAGE_INDEX_BUFFER_BIT | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | (vk_core.rtx ? VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT : 0),
|
||||
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | (vk_core.rtx ? VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT : 0))) // TODO staging buffer?
|
||||
return false;
|
||||
|
||||
if (!createBuffer(&g_render.uniform_buffer, uniform_unit_size * MAX_UNIFORM_SLOTS,
|
||||
if (!createBuffer("render uniform_buffer", &g_render.uniform_buffer, uniform_unit_size * MAX_UNIFORM_SLOTS,
|
||||
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
|
||||
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | (vk_core.rtx ? VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT : 0))) // TODO staging buffer?
|
||||
return false;
|
||||
|
@ -940,7 +940,8 @@ void VK_RenderModelDynamicBegin( const char *debug_name, int render_mode ) {
|
|||
g_dynamic_model.model.geometries = g_dynamic_model.geometries;
|
||||
g_dynamic_model.model.num_geometries = 0;
|
||||
g_dynamic_model.model.render_mode = render_mode;
|
||||
memset(&g_dynamic_model.model.rtx, 0, sizeof(g_dynamic_model.model.rtx));
|
||||
g_dynamic_model.model.rtx.blas = VK_NULL_HANDLE;
|
||||
g_dynamic_model.model.rtx.kusochki_offset = 0;
|
||||
}
|
||||
void VK_RenderModelDynamicAddGeometry( const vk_render_geometry_t *geom ) {
|
||||
ASSERT(g_dynamic_model.model.geometries);
|
||||
|
|
|
@ -197,6 +197,7 @@ static VkDeviceAddress getASAddress(VkAccelerationStructureKHR as) {
|
|||
}
|
||||
|
||||
typedef struct {
|
||||
const char *debug_name;
|
||||
VkAccelerationStructureKHR *p_accel;
|
||||
const VkAccelerationStructureGeometryKHR *geoms;
|
||||
const uint32_t *max_prim_counts;
|
||||
|
@ -326,6 +327,7 @@ static qboolean createOrUpdateAccelerationStructure(VkCommandBuffer cmdbuf, cons
|
|||
}
|
||||
|
||||
XVK_CHECK(vkCreateAccelerationStructureKHR(vk_core.device, &asci, NULL, args->p_accel));
|
||||
SET_DEBUG_NAME(*args->p_accel, VK_OBJECT_TYPE_ACCELERATION_STRUCTURE_KHR, args->debug_name);
|
||||
|
||||
// gEngine.Con_Reportf("AS=%p, n_geoms=%u, build: %#x %d %#x\n", *args->p_accel, args->n_geoms, buffer_offset, build_size.accelerationStructureSize, buffer_offset + build_size.accelerationStructureSize);
|
||||
}
|
||||
|
@ -360,6 +362,16 @@ void VK_RayNewMap( void ) {
|
|||
g_rtx.tlas = VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
// Clear BLAS cache
|
||||
for (int i = 0; i < ARRAYSIZE(g_rtx.blas_cache.accels); ++i) {
|
||||
vk_accel_t *a = g_rtx.blas_cache.accels + i;
|
||||
if (a->as == VK_NULL_HANDLE)
|
||||
break;
|
||||
|
||||
vkDestroyAccelerationStructureKHR(vk_core.device, a->as, NULL);
|
||||
memset(a, 0, sizeof(*a));
|
||||
}
|
||||
|
||||
const VkAccelerationStructureGeometryKHR tl_geom[] = {
|
||||
{
|
||||
.sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_KHR,
|
||||
|
@ -383,6 +395,7 @@ void VK_RayNewMap( void ) {
|
|||
// we can't really rebuild TLAS because instance count changes are not allowed .dynamic = true,
|
||||
.dynamic = false,
|
||||
.p_accel = &g_rtx.tlas,
|
||||
.debug_name = "TLAS",
|
||||
};
|
||||
if (!createOrUpdateAccelerationStructure(VK_NULL_HANDLE, &asrgs)) {
|
||||
gEngine.Host_Error("Could not create TLAS\n");
|
||||
|
@ -551,6 +564,7 @@ void VK_RayFrameEnd(const vk_ray_frame_render_args_t* args)
|
|||
// we can't really rebuild TLAS because instance count changes are not allowed .dynamic = true,
|
||||
.dynamic = false,
|
||||
.p_accel = &g_rtx.tlas,
|
||||
.debug_name = "TLAS...",
|
||||
};
|
||||
if (!createOrUpdateAccelerationStructure(cmdbuf, &asrgs)) {
|
||||
gEngine.Host_Error("Could not update TLAS\n");
|
||||
|
@ -848,7 +862,7 @@ qboolean VK_RayInit( void )
|
|||
{
|
||||
ASSERT(vk_core.rtx);
|
||||
// TODO complain and cleanup on failure
|
||||
if (!createBuffer(&g_rtx.accels_buffer, MAX_ACCELS_BUFFER,
|
||||
if (!createBuffer("ray accels_buffer", &g_rtx.accels_buffer, MAX_ACCELS_BUFFER,
|
||||
VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_STORAGE_BIT_KHR | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT,
|
||||
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
||||
))
|
||||
|
@ -858,7 +872,7 @@ qboolean VK_RayInit( void )
|
|||
g_rtx.accels_buffer_addr = getBufferDeviceAddress(g_rtx.accels_buffer.buffer);
|
||||
g_rtx.accels_buffer_alloc.size = g_rtx.accels_buffer.size;
|
||||
|
||||
if (!createBuffer(&g_rtx.scratch_buffer, MAX_SCRATCH_BUFFER,
|
||||
if (!createBuffer("ray scratch_buffer", &g_rtx.scratch_buffer, MAX_SCRATCH_BUFFER,
|
||||
VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_STORAGE_BIT_KHR | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT,
|
||||
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
||||
)) {
|
||||
|
@ -866,7 +880,7 @@ qboolean VK_RayInit( void )
|
|||
}
|
||||
g_rtx.scratch_buffer_addr = getBufferDeviceAddress(g_rtx.scratch_buffer.buffer);
|
||||
|
||||
if (!createBuffer(&g_rtx.tlas_geom_buffer, sizeof(VkAccelerationStructureInstanceKHR) * MAX_ACCELS,
|
||||
if (!createBuffer("ray tlas_geom_buffer", &g_rtx.tlas_geom_buffer, sizeof(VkAccelerationStructureInstanceKHR) * MAX_ACCELS,
|
||||
VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
|
||||
VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR,
|
||||
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) {
|
||||
|
@ -874,7 +888,7 @@ qboolean VK_RayInit( void )
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!createBuffer(&g_rtx.kusochki_buffer, sizeof(vk_kusok_data_t) * MAX_KUSOCHKI,
|
||||
if (!createBuffer("ray kusochki_buffer", &g_rtx.kusochki_buffer, sizeof(vk_kusok_data_t) * MAX_KUSOCHKI,
|
||||
VK_BUFFER_USAGE_STORAGE_BUFFER_BIT /* | VK_BUFFER_USAGE_TRANSFER_DST_BIT */,
|
||||
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) {
|
||||
// FIXME complain, handle
|
||||
|
@ -882,14 +896,14 @@ qboolean VK_RayInit( void )
|
|||
}
|
||||
g_rtx.kusochki_alloc.size = MAX_KUSOCHKI;
|
||||
|
||||
if (!createBuffer(&g_rtx.emissive_kusochki_buffer, sizeof(vk_emissive_kusochki_t),
|
||||
if (!createBuffer("ray emissive_kusochki_buffer", &g_rtx.emissive_kusochki_buffer, sizeof(vk_emissive_kusochki_t),
|
||||
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT /* | VK_BUFFER_USAGE_TRANSFER_DST_BIT */,
|
||||
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) {
|
||||
// FIXME complain, handle
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!createBuffer(&g_rtx.light_grid_buffer, sizeof(vk_ray_shader_light_grid),
|
||||
if (!createBuffer("ray light_grid_buffer", &g_rtx.light_grid_buffer, sizeof(vk_ray_shader_light_grid),
|
||||
VK_BUFFER_USAGE_STORAGE_BUFFER_BIT /* | VK_BUFFER_USAGE_TRANSFER_DST_BIT */,
|
||||
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) {
|
||||
// FIXME complain, handle
|
||||
|
@ -1081,6 +1095,7 @@ qboolean VK_RayModelInit( vk_ray_model_init_t args ) {
|
|||
.type = VK_ACCELERATION_STRUCTURE_TYPE_BOTTOM_LEVEL_KHR,
|
||||
.dynamic = args.model->dynamic,
|
||||
.p_accel = &as,
|
||||
.debug_name = args.model->debug_name,
|
||||
};
|
||||
|
||||
// TODO batch building multiple blases together
|
||||
|
|
Loading…
Reference in New Issue