mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-04-05 08:51:28 +00:00
[vulkan] Fix more sync issues
Thanks to validation layers showing command buffer debug regions, it was pretty easy to find the offending buffers. Did need to modify QFV_PacketCopyBuffer to take a source barrier as well as the destination barrier, but this is probably for the best.
This commit is contained in:
parent
bc22cd3255
commit
e35bff066f
9 changed files with 59 additions and 29 deletions
|
@ -36,6 +36,7 @@ enum {
|
|||
// buffer barriers
|
||||
enum {
|
||||
qfv_BB_Unknown_to_TransferWrite,
|
||||
qfv_BB_UniformRead_to_TransferWrite,
|
||||
qfv_BB_TransferWrite_to_VertexAttrRead,
|
||||
qfv_BB_TransferWrite_to_IndexRead,
|
||||
qfv_BB_TransferWrite_to_UniformRead,
|
||||
|
|
|
@ -44,6 +44,7 @@ VkResult QFV_PacketWait (qfv_packet_t *packet);
|
|||
struct qfv_bufferbarrier_s;
|
||||
void QFV_PacketCopyBuffer (qfv_packet_t *packet,
|
||||
VkBuffer dstBuffer, VkDeviceSize offset,
|
||||
const struct qfv_bufferbarrier_s *srcBarrier,
|
||||
const struct qfv_bufferbarrier_s *dstBarrier);
|
||||
void QFV_PacketScatterBuffer (qfv_packet_t *packet, VkBuffer dstBuffer,
|
||||
uint32_t count, qfv_scatter_t *scatter,
|
||||
|
|
|
@ -183,9 +183,20 @@ const qfv_bufferbarrier_t bufferBarriers[] = {
|
|||
.srcStages = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
|
||||
.dstStages = VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
.barrier = {
|
||||
VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER, 0,
|
||||
0, VK_ACCESS_TRANSFER_WRITE_BIT,
|
||||
VK_QUEUE_FAMILY_IGNORED, VK_QUEUE_FAMILY_IGNORED,
|
||||
.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
|
||||
.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
|
||||
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||
},
|
||||
},
|
||||
[qfv_BB_UniformRead_to_TransferWrite] = {
|
||||
.srcStages = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT,
|
||||
.dstStages = VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
.barrier = {
|
||||
.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
|
||||
.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
|
||||
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
||||
},
|
||||
},
|
||||
[qfv_BB_TransferWrite_to_VertexAttrRead] = {
|
||||
|
|
|
@ -337,10 +337,11 @@ QFV_PacketWait (qfv_packet_t *packet)
|
|||
void
|
||||
QFV_PacketCopyBuffer (qfv_packet_t *packet,
|
||||
VkBuffer dstBuffer, VkDeviceSize offset,
|
||||
const qfv_bufferbarrier_t *srcBarrier,
|
||||
const qfv_bufferbarrier_t *dstBarrier)
|
||||
{
|
||||
qfv_devfuncs_t *dfunc = packet->stage->device->funcs;
|
||||
qfv_bufferbarrier_t bb = bufferBarriers[qfv_BB_Unknown_to_TransferWrite];
|
||||
qfv_bufferbarrier_t bb = *srcBarrier;
|
||||
bb.barrier.buffer = dstBuffer;
|
||||
bb.barrier.offset = offset;
|
||||
bb.barrier.size = packet->length;
|
||||
|
|
|
@ -289,8 +289,9 @@ generate_slice_indices (qfv_stagebuf_t *staging, qfv_resobj_t *ind_buffer)
|
|||
ind[i + 18] = i + 8;
|
||||
}
|
||||
ind[8] = ind[17] = ~0;
|
||||
QFV_PacketCopyBuffer (packet, ind_buffer->buffer.buffer, 0,
|
||||
&bufferBarriers[qfv_BB_TransferWrite_to_IndexRead]);
|
||||
auto sb = bufferBarriers[qfv_BB_Unknown_to_TransferWrite];
|
||||
auto db = bufferBarriers[qfv_BB_TransferWrite_to_IndexRead];
|
||||
QFV_PacketCopyBuffer (packet, ind_buffer->buffer.buffer, 0, &sb, &db);
|
||||
QFV_PacketSubmit (packet);
|
||||
}
|
||||
|
||||
|
@ -511,8 +512,14 @@ flush_vertqueue (vertqueue_t *queue, vulkan_ctx_t *ctx)
|
|||
qfv_packet_t *packet = QFV_PacketAcquire (ctx->staging);
|
||||
quadvert_t *verts = QFV_PacketExtend (packet, size);
|
||||
memcpy (verts, queue->verts, size);
|
||||
QFV_PacketCopyBuffer (packet, queue->buffer, queue->base,
|
||||
&bufferBarriers[qfv_BB_TransferWrite_to_UniformRead]);
|
||||
QFV_duCmdBeginLabel (ctx->device, packet->cmd, "flush_vertqueue",
|
||||
{0.2, 0.8, 0.3, 1});
|
||||
auto sb = bufferBarriers[qfv_BB_UniformRead_to_TransferWrite];
|
||||
auto db = bufferBarriers[qfv_BB_TransferWrite_to_UniformRead];
|
||||
sb.srcStages |= VK_PIPELINE_STAGE_VERTEX_SHADER_BIT;
|
||||
db.dstStages |= VK_PIPELINE_STAGE_VERTEX_SHADER_BIT;
|
||||
QFV_PacketCopyBuffer (packet, queue->buffer, queue->base, &sb, &db);
|
||||
QFV_duCmdEndLabel (ctx->device, packet->cmd);
|
||||
QFV_PacketSubmit (packet);
|
||||
queue->base += size;
|
||||
queue->count = 0;
|
||||
|
@ -1791,8 +1798,9 @@ Vulkan_Draw_AddFont (font_t *rfont, vulkan_ctx_t *ctx)
|
|||
.uv = {(u + w) * s, (v + h) * t },
|
||||
};
|
||||
}
|
||||
QFV_PacketCopyBuffer (packet, glyph_data->buffer.buffer, 0,
|
||||
&bufferBarriers[qfv_BB_TransferWrite_to_UniformRead]);
|
||||
auto sb = bufferBarriers[qfv_BB_Unknown_to_TransferWrite];
|
||||
auto db = bufferBarriers[qfv_BB_TransferWrite_to_UniformRead];
|
||||
QFV_PacketCopyBuffer (packet, glyph_data->buffer.buffer, 0, &sb, &db);
|
||||
QFV_PacketSubmit (packet);
|
||||
|
||||
packet = QFV_PacketAcquire (ctx->staging);
|
||||
|
|
|
@ -1917,13 +1917,14 @@ lighting_startup (exprctx_t *ectx)
|
|||
auto packet = QFV_PacketAcquire (ctx->staging);
|
||||
make_ico (packet);
|
||||
make_cone (packet);
|
||||
QFV_PacketCopyBuffer (packet, splat_verts[0].buffer.buffer, 0,
|
||||
&bufferBarriers[qfv_BB_TransferWrite_to_VertexAttrRead]);
|
||||
auto sb = bufferBarriers[qfv_BB_Unknown_to_TransferWrite];
|
||||
auto dbv = bufferBarriers[qfv_BB_TransferWrite_to_VertexAttrRead];
|
||||
auto dbi = bufferBarriers[qfv_BB_TransferWrite_to_IndexRead];
|
||||
QFV_PacketCopyBuffer (packet, splat_verts[0].buffer.buffer, 0, &sb, &dbv);
|
||||
QFV_PacketSubmit (packet);
|
||||
packet = QFV_PacketAcquire (ctx->staging);
|
||||
write_inds (packet);
|
||||
QFV_PacketCopyBuffer (packet, splat_inds[0].buffer.buffer, 0,
|
||||
&bufferBarriers[qfv_BB_TransferWrite_to_IndexRead]);
|
||||
QFV_PacketCopyBuffer (packet, splat_inds[0].buffer.buffer, 0, &sb, &dbi);
|
||||
QFV_PacketSubmit (packet);
|
||||
|
||||
qfvPopDebug (ctx);
|
||||
|
@ -2214,10 +2215,11 @@ upload_light_matrices (lightingctx_t *lctx, vulkan_ctx_t *ctx)
|
|||
size_t mat_size = sizeof (mat4f_t[lctx->light_mats.size]);
|
||||
void *mat_data = QFV_PacketExtend (packet, mat_size);
|
||||
memcpy (mat_data, lctx->light_mats.a, mat_size);
|
||||
auto bb = &bufferBarriers[qfv_BB_TransferWrite_to_UniformRead];
|
||||
auto sb = &bufferBarriers[qfv_BB_Unknown_to_TransferWrite];
|
||||
auto db = &bufferBarriers[qfv_BB_TransferWrite_to_UniformRead];
|
||||
for (size_t i = 0; i < lctx->frames.size; i++) {
|
||||
auto lframe = &lctx->frames.a[i];
|
||||
QFV_PacketCopyBuffer (packet, lframe->shadowmat_buffer, 0, bb);
|
||||
QFV_PacketCopyBuffer (packet, lframe->shadowmat_buffer, 0, sb, db);
|
||||
}
|
||||
QFV_PacketSubmit (packet);
|
||||
|
||||
|
@ -2227,7 +2229,7 @@ upload_light_matrices (lightingctx_t *lctx, vulkan_ctx_t *ctx)
|
|||
memset (id_data, -1, id_size);
|
||||
for (size_t i = 0; i < lctx->frames.size; i++) {
|
||||
auto lframe = &lctx->frames.a[i];
|
||||
QFV_PacketCopyBuffer (packet, lframe->shadowmat_id_buffer, 0, bb);
|
||||
QFV_PacketCopyBuffer (packet, lframe->shadowmat_id_buffer, 0, sb, db);
|
||||
}
|
||||
QFV_PacketSubmit (packet);
|
||||
}
|
||||
|
@ -2243,10 +2245,11 @@ upload_light_data (lightingctx_t *lctx, vulkan_ctx_t *ctx)
|
|||
auto packet = QFV_PacketAcquire (ctx->staging);
|
||||
auto light_data = QFV_PacketExtend (packet, sizeof (light_t[count]));
|
||||
memcpy (light_data, lights, sizeof (light_t[count]));
|
||||
auto bb = &bufferBarriers[qfv_BB_TransferWrite_to_UniformRead];
|
||||
auto sb = &bufferBarriers[qfv_BB_Unknown_to_TransferWrite];
|
||||
auto db = &bufferBarriers[qfv_BB_TransferWrite_to_UniformRead];
|
||||
for (size_t i = 0; i < lctx->frames.size; i++) {
|
||||
auto lframe = &lctx->frames.a[i];
|
||||
QFV_PacketCopyBuffer (packet, lframe->light_buffer, 0, bb);
|
||||
QFV_PacketCopyBuffer (packet, lframe->light_buffer, 0, sb, db);
|
||||
}
|
||||
QFV_PacketSubmit (packet);
|
||||
|
||||
|
@ -2268,7 +2271,7 @@ upload_light_data (lightingctx_t *lctx, vulkan_ctx_t *ctx)
|
|||
}
|
||||
for (size_t i = 0; i < lctx->frames.size; i++) {
|
||||
auto lframe = &lctx->frames.a[i];
|
||||
QFV_PacketCopyBuffer (packet, lframe->render_buffer, 0, bb);
|
||||
QFV_PacketCopyBuffer (packet, lframe->render_buffer, 0, sb, db);
|
||||
}
|
||||
QFV_PacketSubmit (packet);
|
||||
}
|
||||
|
|
|
@ -148,9 +148,11 @@ update_matrices (const exprval_t **params, exprval_t *result, exprctx_t *ectx)
|
|||
qfv_matrix_buffer_t *m = QFV_PacketExtend (packet, sizeof (*m));
|
||||
*m = mctx->matrices;
|
||||
|
||||
auto bb = bufferBarriers[qfv_BB_TransferWrite_to_UniformRead];
|
||||
bb.dstStages |= VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT;
|
||||
QFV_PacketCopyBuffer (packet, mframe->buffer, 0, &bb);
|
||||
auto sb = bufferBarriers[qfv_BB_Unknown_to_TransferWrite];
|
||||
auto db = bufferBarriers[qfv_BB_TransferWrite_to_UniformRead];
|
||||
db.dstStages |= VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT;
|
||||
db.dstStages |= VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT;
|
||||
QFV_PacketCopyBuffer (packet, mframe->buffer, 0, &sb, &db);
|
||||
QFV_PacketSubmit (packet);
|
||||
}
|
||||
|
||||
|
|
|
@ -115,9 +115,10 @@ debug_planes_draw (const exprval_t **params, exprval_t *result, exprctx_t *ectx)
|
|||
.planes[2] = make_plane (z, x, b, r),
|
||||
};
|
||||
auto buffer = &pctx->resources->objects[ctx->curFrame].buffer;
|
||||
auto bb = bufferBarriers[qfv_BB_TransferWrite_to_UniformRead];
|
||||
bb.dstStages |= VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT;
|
||||
QFV_PacketCopyBuffer (packet, buffer->buffer, 0, &bb);
|
||||
auto sb = bufferBarriers[qfv_BB_Unknown_to_TransferWrite];
|
||||
auto db = bufferBarriers[qfv_BB_TransferWrite_to_UniformRead];
|
||||
db.dstStages |= VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT;
|
||||
QFV_PacketCopyBuffer (packet, buffer->buffer, 0, &sb, &db);
|
||||
QFV_PacketSubmit (packet);
|
||||
|
||||
VkDescriptorSet sets[] = {
|
||||
|
@ -204,10 +205,11 @@ planes_startup (exprctx_t *ectx)
|
|||
{0, 1, 0, 0},
|
||||
}},
|
||||
};
|
||||
auto sb = bufferBarriers[qfv_BB_Unknown_to_TransferWrite];
|
||||
auto db = bufferBarriers[qfv_BB_TransferWrite_to_UniformRead];
|
||||
for (size_t i = 0; i < frames; i++) {
|
||||
auto buffer = &pctx->resources->objects[i].buffer;
|
||||
auto bb = &bufferBarriers[qfv_BB_TransferWrite_to_UniformRead];
|
||||
QFV_PacketCopyBuffer (packet, buffer->buffer, 0, bb);
|
||||
QFV_PacketCopyBuffer (packet, buffer->buffer, 0, &sb, &db);
|
||||
}
|
||||
QFV_PacketSubmit (packet);
|
||||
|
||||
|
|
|
@ -186,7 +186,8 @@ clear_translucent (const exprval_t **params, exprval_t *result, exprctx_t *ectx)
|
|||
qfv_packet_t *packet = QFV_PacketAcquire (ctx->staging);
|
||||
qfv_transtate_t *state = QFV_PacketExtend (packet, 2 * sizeof (*state));
|
||||
*state = (qfv_transtate_t) { 0, tctx->maxFragments };
|
||||
QFV_PacketCopyBuffer (packet, tframe->state->buffer.buffer, 0,
|
||||
auto sb = bufferBarriers[qfv_BB_Unknown_to_TransferWrite];
|
||||
QFV_PacketCopyBuffer (packet, tframe->state->buffer.buffer, 0, &sb,
|
||||
&(qfv_bufferbarrier_t) {
|
||||
.srcStages = VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
.dstStages = VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
|
||||
|
|
Loading…
Reference in a new issue