[vulkan] Add entity labels to command queues

Brush models looked a little too tricky due to the very different style
of command queue, so that's left for now, but alias, iqm and sprite
entities are now labeled. The labels are made up of the lower 5 hex
digits of the entity address, the position, and colored by the
normalized position vector. Not sure that's the best choice as it does
mean the color changes as the entity moves, and can be quite subtle
between nearby entities, but it still helps identify the entities in the
command buffer.

And, as I suspected, I've got multiple draw calls for the one ogre. Now
to find out why.
This commit is contained in:
Bill Currie 2022-05-07 14:12:02 +09:00
parent 18af340160
commit 08c8b8d51b
5 changed files with 42 additions and 9 deletions

View file

@ -81,4 +81,8 @@ VkSampler Vulkan_CreateSampler (struct vulkan_ctx_s *ctx, const char *name);
VkDescriptorSetLayout Vulkan_CreateDescriptorSetLayout(struct vulkan_ctx_s*ctx,
const char *name);
struct entity_s;
void Vulkan_BeginEntityLabel (struct vulkan_ctx_s *ctx, VkCommandBuffer cmd,
struct entity_s *ent);
#endif // __QF_Vulkan_vid_h

View file

@ -76,7 +76,7 @@ static void
emit_commands (VkCommandBuffer cmd, int pose1, int pose2,
qfv_alias_skin_t *skin,
uint32_t numPC, qfv_push_constants_t *constants,
aliashdr_t *hdr, qfv_renderframe_t *rFrame)
aliashdr_t *hdr, qfv_renderframe_t *rFrame, entity_t *ent)
{
vulkan_ctx_t *ctx = rFrame->vulkan_ctx;
qfv_device_t *device = ctx->device;
@ -97,6 +97,8 @@ emit_commands (VkCommandBuffer cmd, int pose1, int pose2,
};
int bindingCount = skin ? 3 : 2;
Vulkan_BeginEntityLabel (ctx, cmd, ent);
dfunc->vkCmdBindVertexBuffers (cmd, 0, bindingCount, buffers, offsets);
dfunc->vkCmdBindIndexBuffer (cmd, mesh->index_buffer, 0,
VK_INDEX_TYPE_UINT32);
@ -109,6 +111,8 @@ emit_commands (VkCommandBuffer cmd, int pose1, int pose2,
actx->layout, 1, 1, sets, 0, 0);
}
dfunc->vkCmdDrawIndexed (cmd, 3 * hdr->mdl.numtris, 1, 0, 0, 0);
QFV_CmdEndLabel (device, cmd);
}
void
@ -164,10 +168,10 @@ Vulkan_DrawAlias (entity_t *ent, qfv_renderframe_t *rFrame)
emit_commands (aframe->cmdSet.a[QFV_aliasDepth],
ent->animation.pose1, ent->animation.pose2,
0, 2, push_constants, hdr, rFrame);
0, 2, push_constants, hdr, rFrame, ent);
emit_commands (aframe->cmdSet.a[QFV_aliasGBuffer],
ent->animation.pose1, ent->animation.pose2,
skin, 6, push_constants, hdr, rFrame);
skin, 6, push_constants, hdr, rFrame, ent);
}
static void

View file

@ -76,7 +76,7 @@ static void
emit_commands (VkCommandBuffer cmd, int pose1, int pose2,
qfv_iqm_skin_t *skins,
uint32_t numPC, qfv_push_constants_t *constants,
iqm_t *iqm, qfv_renderframe_t *rFrame)
iqm_t *iqm, qfv_renderframe_t *rFrame, entity_t *ent)
{
vulkan_ctx_t *ctx = rFrame->vulkan_ctx;
qfv_device_t *device = ctx->device;
@ -92,6 +92,8 @@ emit_commands (VkCommandBuffer cmd, int pose1, int pose2,
};
int bindingCount = 2;//skins ? 2 : 1;
Vulkan_BeginEntityLabel (ctx, cmd, ent);
dfunc->vkCmdBindVertexBuffers (cmd, 0, bindingCount, buffers, offsets);
dfunc->vkCmdBindIndexBuffer (cmd, mesh->index_buffer, 0,
VK_INDEX_TYPE_UINT16);
@ -116,6 +118,8 @@ emit_commands (VkCommandBuffer cmd, int pose1, int pose2,
dfunc->vkCmdDrawIndexed (cmd, 3 * iqm->meshes[i].num_triangles, 1,
3 * iqm->meshes[i].first_triangle, 0, 0);
}
QFV_CmdEndLabel (device, cmd);
}
void
@ -160,10 +164,10 @@ Vulkan_DrawIQM (entity_t *ent, qfv_renderframe_t *rFrame)
emit_commands (aframe->cmdSet.a[QFV_iqmDepth],
ent->animation.pose1, ent->animation.pose2,
0, 2, push_constants, iqm, rFrame);
0, 2, push_constants, iqm, rFrame, ent);
emit_commands (aframe->cmdSet.a[QFV_iqmGBuffer],
ent->animation.pose1, ent->animation.pose2,
skins, 6, push_constants, iqm, rFrame);
skins, 6, push_constants, iqm, rFrame, ent);
}
static void

View file

@ -82,13 +82,15 @@ static QFV_Subpass subpass_map[] = {
static void
emit_commands (VkCommandBuffer cmd, qfv_sprite_t *sprite,
int numPC, qfv_push_constants_t *constants,
qfv_renderframe_t *rFrame)
qfv_renderframe_t *rFrame, entity_t *ent)
{
vulkan_ctx_t *ctx = rFrame->vulkan_ctx;
qfv_device_t *device = ctx->device;
qfv_devfuncs_t *dfunc = device->funcs;
spritectx_t *sctx = ctx->sprite_context;
Vulkan_BeginEntityLabel (ctx, cmd, ent);
QFV_PushConstants (device, cmd, sctx->layout, numPC, constants);
VkDescriptorSet sets[] = {
sprite->descriptors,
@ -96,6 +98,8 @@ emit_commands (VkCommandBuffer cmd, qfv_sprite_t *sprite,
dfunc->vkCmdBindDescriptorSets (cmd, VK_PIPELINE_BIND_POINT_GRAPHICS,
sctx->layout, 1, 1, sets, 0, 0);
dfunc->vkCmdDraw (cmd, 4, 1, 0, 0);
QFV_CmdEndLabel (device, cmd);
}
void
@ -126,10 +130,10 @@ Vulkan_DrawSprite (entity_t *ent, qfv_renderframe_t *rFrame)
emit_commands (sframe->cmdSet.a[QFV_spriteDepth],
(qfv_sprite_t *) ((byte *) sprite + sprite->data),
2, push_constants, rFrame);
2, push_constants, rFrame, ent);
emit_commands (sframe->cmdSet.a[QFV_spriteGBuffer],
(qfv_sprite_t *) ((byte *) sprite + sprite->data),
2, push_constants, rFrame);
2, push_constants, rFrame, ent);
}
static void

View file

@ -49,6 +49,8 @@
#include "QF/quakefs.h"
#include "QF/sys.h"
#include "QF/va.h"
#include "QF/simd/vec4f.h"
#include "QF/scene/entity.h"
#include "QF/Vulkan/qf_matrices.h"
#include "QF/Vulkan/qf_vid.h"
#include "QF/Vulkan/barrier.h"
@ -799,3 +801,18 @@ Vulkan_DestroyFrames (vulkan_ctx_t *ctx)
DARRAY_CLEAR (&ctx->frames);
}
void
Vulkan_BeginEntityLabel (vulkan_ctx_t *ctx, VkCommandBuffer cmd,
entity_t *ent)
{
qfv_device_t *device = ctx->device;
int entaddr = (intptr_t) ent & 0xfffff;
vec4f_t pos = Transform_GetWorldPosition (ent->transform);
vec4f_t dir = normalf (pos - (vec4f_t) { 0, 0, 0, 1 });
vec4f_t color = 0.5 * dir + (vec4f_t) {0.5, 0.5, 0.5, 1 };
QFV_CmdBeginLabel (device, cmd,
va (ctx->va_ctx, "ent %05x [%g, %g, %g]", entaddr,
VectorExpand (pos)), color);
}