Merge pull request #29 from w23/debug-labels

restore debug labels for traditional renderer
This commit is contained in:
Ivan Avdeev 2021-08-15 11:25:49 -07:00 committed by GitHub
commit 584ca32d36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 98 additions and 53 deletions

View File

@ -1,7 +1,9 @@
## 2021-08-15, E126
- [x] restore render debug labels
# Next
- [ ] restore render debug labels
- [ ] rtx: simple convolution denoise (bilateral?)
- [ ] rtx: split ray tracing into modules: pipeline mgmt, buffer mgmt
- [ ] rtx: simple convolution denoise (bilateral?)
- [ ] rtx: better light culling: normal, bsp visibility, light volumes and intensity, sort by intensity, etc
- [ ] rtx: cluster dlights
- [ ] rtx: dynamically sized light clusters
@ -98,7 +100,7 @@
- [ ] better 2d renderer: fill DRAWQUAD(texture, color, ...) command into storage buffer instead of 4 vertices
- [ ] auto-atlas lots of smol textures: most of model texture are tiny (64x64 or less), can we not rebind them all the time? alt: bindless texture array
- [ ] can we also try to coalesce sprite draw calls?
- [ ] brush geometry is not watertight
- [ ] brush geometry is not watertight
- [ ] collect render_draw_t w/o submitting them to cmdbuf, then sort by render_mode, trans depth, and other parameters, trying to batch as much stuff as possible; only then submit
# Previously
@ -318,4 +320,4 @@
- [x] disable lightmaps, or use white texture for it instead
## 2021-08-11, E125
- [x] simplify buffer api: do alloc+lock as a single op
- [x] simplify buffer api: do alloc+lock as a single op

View File

@ -147,6 +147,15 @@ void vk2dEnd( VkCommandBuffer cmdbuf )
vkCmdBindVertexBuffers(cmdbuf, 0, 1, &g2d.pics_buffer.buffer, &offset);
if (vk_core.debug)
{
VkDebugUtilsLabelEXT label = {
.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT,
.pLabelName = "2d overlay",
};
vkCmdBeginDebugUtilsLabelEXT(cmdbuf, &label);
}
for (int i = 0; i <= g2d.current_batch; ++i)
{
vk_texture_t *texture = findTexture(g2d.batch[i].texture);
@ -158,6 +167,9 @@ void vk2dEnd( VkCommandBuffer cmdbuf )
vkCmdDraw(cmdbuf, g2d.batch[i].vertex_count, 1, g2d.batch[i].vertex_offset, 0);
} // FIXME else what?
}
if (vk_core.debug)
vkCmdEndDebugUtilsLabelEXT(cmdbuf);
}
static qboolean createPipelines( void )

View File

@ -357,11 +357,22 @@ typedef struct render_draw_s {
/* TODO this should be a separate thing? */ struct { float r, g, b; } emissive;
} render_draw_t;
enum draw_command_type_e {
DrawLabelBegin,
DrawLabelEnd,
DrawDraw
};
typedef struct {
render_draw_t draw;
uint32_t ubo_offset;
//char debug_name[MAX_DEBUG_NAME_LENGTH];
matrix3x4 transform;
enum draw_command_type_e type;
union {
char debug_label[MAX_DEBUG_NAME_LENGTH];
struct {
render_draw_t draw;
uint32_t ubo_offset;
matrix3x4 transform;
} draw;
};
} draw_command_t;
static struct {
@ -465,7 +476,27 @@ static uint32_t allocUniform( uint32_t size, uint32_t alignment ) {
return offset;
}
static void VK_RenderScheduleDraw( const render_draw_t *draw )
static draw_command_t *drawCmdAlloc( void ) {
ASSERT(g_render_state.num_draw_commands < ARRAYSIZE(g_render_state.draw_commands));
return g_render_state.draw_commands + (g_render_state.num_draw_commands++);
}
static void drawCmdPushDebugLabelBegin( const char *debug_label ) {
if (vk_core.debug) {
draw_command_t *draw_command = drawCmdAlloc();
draw_command->type = DrawLabelBegin;
Q_strncpy(draw_command->debug_label, debug_label, sizeof draw_command->debug_label);
}
}
static void drawCmdPushDebugLabelEnd( void ) {
if (vk_core.debug) {
draw_command_t *draw_command = drawCmdAlloc();
draw_command->type = DrawLabelEnd;
}
}
static void drawCmdPushDraw( const render_draw_t *draw )
{
draw_command_t *draw_command;
@ -500,10 +531,11 @@ static void VK_RenderScheduleDraw( const render_draw_t *draw )
g_render_state.uniform_data_set_mask |= UNIFORM_UPLOADED;
}
draw_command = g_render_state.draw_commands + (g_render_state.num_draw_commands++);
draw_command->draw = *draw;
draw_command->ubo_offset = g_render_state.current_ubo_offset;
Matrix3x4_Copy(draw_command->transform, g_render_state.model);
draw_command = drawCmdAlloc();
draw_command->draw.draw = *draw;
draw_command->draw.ubo_offset = g_render_state.current_ubo_offset;
draw_command->type = DrawDraw;
Matrix3x4_Copy(draw_command->draw.transform, g_render_state.model);
}
void VK_RenderAddStaticLight(vec3_t origin, vec3_t color)
@ -600,51 +632,58 @@ void VK_RenderEnd( VkCommandBuffer cmdbuf )
for (int i = 0; i < g_render_state.num_draw_commands; ++i) {
const draw_command_t *const draw = g_render_state.draw_commands + i;
if (ubo_offset != draw->ubo_offset)
switch (draw->type) {
case DrawLabelBegin:
{
VkDebugUtilsLabelEXT label = {
.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT,
.pLabelName = draw->debug_label,
};
vkCmdBeginDebugUtilsLabelEXT(cmdbuf, &label);
}
continue;
case DrawLabelEnd:
vkCmdEndDebugUtilsLabelEXT(cmdbuf);
continue;
}
if (ubo_offset != draw->draw.ubo_offset)
{
ubo_offset = draw->ubo_offset;
ubo_offset = draw->draw.ubo_offset;
vkCmdBindDescriptorSets(vk_core.cb, VK_PIPELINE_BIND_POINT_GRAPHICS, g_render.pipeline_layout, 0, 1, vk_desc.ubo_sets, 1, &ubo_offset);
}
if (pipeline != draw->draw.render_mode) {
pipeline = draw->draw.render_mode;
if (pipeline != draw->draw.draw.render_mode) {
pipeline = draw->draw.draw.render_mode;
vkCmdBindPipeline(vk_core.cb, VK_PIPELINE_BIND_POINT_GRAPHICS, g_render.pipelines[pipeline]);
}
if (lightmap != draw->draw.lightmap) {
lightmap = draw->draw.lightmap;
if (lightmap != draw->draw.draw.lightmap) {
lightmap = draw->draw.draw.lightmap;
vkCmdBindDescriptorSets(vk_core.cb, VK_PIPELINE_BIND_POINT_GRAPHICS, g_render.pipeline_layout, 2, 1, &findTexture(lightmap)->vk.descriptor, 0, NULL);
}
if (texture != draw->draw.texture)
if (texture != draw->draw.draw.texture)
{
texture = draw->draw.texture;
texture = draw->draw.draw.texture;
// TODO names/enums for binding points
vkCmdBindDescriptorSets(vk_core.cb, VK_PIPELINE_BIND_POINT_GRAPHICS, g_render.pipeline_layout, 1, 1, &findTexture(texture)->vk.descriptor, 0, NULL);
}
// Only indexed mode is supported
ASSERT(draw->draw.index_offset >= 0);
vkCmdDrawIndexed(vk_core.cb, draw->draw.element_count, 1, draw->draw.index_offset, draw->draw.vertex_offset, 0);
ASSERT(draw->draw.draw.index_offset >= 0);
vkCmdDrawIndexed(vk_core.cb, draw->draw.draw.element_count, 1, draw->draw.draw.index_offset, draw->draw.draw.vertex_offset, 0);
}
}
void VK_RenderDebugLabelBegin( const char *name )
{
// TODO fix this
/* if (vk_core.debug) { */
/* VkDebugUtilsLabelEXT label = { */
/* .sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT, */
/* .pLabelName = name, */
/* }; */
/* vkCmdBeginDebugUtilsLabelEXT(vk_core.cb, &label); */
/* } */
drawCmdPushDebugLabelBegin(name);
}
void VK_RenderDebugLabelEnd( void )
{
/* if (vk_core.debug) */
/* vkCmdEndDebugUtilsLabelEXT(vk_core.cb); */
drawCmdPushDebugLabelEnd();
}
void VK_RenderEndRTX( VkCommandBuffer cmdbuf, VkImageView img_dst_view, VkImage img_dst, uint32_t w, uint32_t h )
@ -738,10 +777,11 @@ void VK_RenderModelDraw( vk_render_model_t* model ) {
return;
}
drawCmdPushDebugLabelBegin( model->debug_name );
for (int i = 0; i < model->num_geometries; ++i) {
const vk_render_geometry_t *geom = model->geometries + i;
const qboolean split = current_texture != geom->texture
const qboolean split = current_texture != geom->texture
|| vertex_offset != geom->vertex_offset
|| (index_offset + element_count) != geom->index_offset;
@ -753,7 +793,7 @@ void VK_RenderModelDraw( vk_render_model_t* model ) {
if (split) {
if (element_count) {
const render_draw_t draw = {
render_draw_t draw = {
.lightmap = tglob.lightmapTextures[0], // FIXME there can be more than one lightmap textures
.texture = current_texture,
.render_mode = model->render_mode,
@ -762,7 +802,7 @@ void VK_RenderModelDraw( vk_render_model_t* model ) {
.index_offset = index_offset,
};
VK_RenderScheduleDraw( &draw );
drawCmdPushDraw( &draw );
}
current_texture = geom->texture;
@ -786,8 +826,10 @@ void VK_RenderModelDraw( vk_render_model_t* model ) {
.index_offset = index_offset,
};
VK_RenderScheduleDraw( &draw );
drawCmdPushDraw( &draw );
}
drawCmdPushDebugLabelEnd();
}
#define MAX_DYNAMIC_GEOMETRY 256

View File

@ -646,7 +646,7 @@ qboolean R_SpriteOccluded( cl_entity_t *e, vec3_t origin, float *pscale )
return false;
}
static void R_DrawSpriteQuad( mspriteframe_t *frame, vec3_t org, vec3_t v_right, vec3_t v_up, float scale, int texture, int render_mode )
static void R_DrawSpriteQuad( const char *debug_name, mspriteframe_t *frame, vec3_t org, vec3_t v_right, vec3_t v_up, float scale, int texture, int render_mode )
{
vec3_t point;
xvk_render_buffer_allocation_t vertex_buffer, index_buffer;
@ -714,7 +714,7 @@ static void R_DrawSpriteQuad( mspriteframe_t *frame, vec3_t org, vec3_t v_right,
.index_offset = index_buffer.buffer.unit.offset,
};
VK_RenderModelDynamicBegin( "sprite" /* TODO its name */, render_mode );
VK_RenderModelDynamicBegin( debug_name, render_mode );
VK_RenderModelDynamicAddGeometry( &geometry );
VK_RenderModelDynamicCommit();
}
@ -928,14 +928,6 @@ void VK_SpriteDrawModel( cl_entity_t *e )
GL_Cull( GL_NONE );
*/
if (vk_core.debug) {
VkDebugUtilsLabelEXT label = {
.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT,
.pLabelName = model->name,
};
vkCmdBeginDebugUtilsLabelEXT(vk_core.cb, &label);
}
if( oldframe == frame )
{
// draw the single non-lerped frame
@ -947,7 +939,7 @@ void VK_SpriteDrawModel( cl_entity_t *e )
ubo->color[3] = tr.blend;
*/
VK_RenderStateSetColor( color[0], color[1], color[2], .5f ); // FIXME VK: tr.blend
R_DrawSpriteQuad( frame, origin, v_right, v_up, scale, frame->gl_texturenum, e->curstate.rendermode );
R_DrawSpriteQuad( model->name, frame, origin, v_right, v_up, scale, frame->gl_texturenum, e->curstate.rendermode );
}
else
{
@ -959,14 +951,14 @@ void VK_SpriteDrawModel( cl_entity_t *e )
{
// FIXME VK make sure we end up with the same values as gl
VK_RenderStateSetColor( color[0], color[1], color[2], 1.f * ilerp );
R_DrawSpriteQuad( oldframe, origin, v_right, v_up, scale, oldframe->gl_texturenum, e->curstate.rendermode );
R_DrawSpriteQuad( model->name, oldframe, origin, v_right, v_up, scale, oldframe->gl_texturenum, e->curstate.rendermode );
}
if( lerp != 0.0f )
{
// FIXME VK make sure we end up with the same values as gl
VK_RenderStateSetColor( color[0], color[1], color[2], 1.f * lerp );
R_DrawSpriteQuad( frame, origin, v_right, v_up, scale, frame->gl_texturenum, e->curstate.rendermode );
R_DrawSpriteQuad( model->name, frame, origin, v_right, v_up, scale, frame->gl_texturenum, e->curstate.rendermode );
}
}
@ -989,7 +981,4 @@ void VK_SpriteDrawModel( cl_entity_t *e )
pglDepthFunc( GL_LEQUAL );
}
*/
if (vk_core.debug)
vkCmdEndDebugUtilsLabelEXT(vk_core.cb);
}