diff --git a/src/imagination/vulkan/pvr_arch_g5p_gfx.c b/src/imagination/vulkan/pvr_arch_g5p_gfx.c index 6fe858b5cc7..6f04da86f7b 100644 --- a/src/imagination/vulkan/pvr_arch_g5p_gfx.c +++ b/src/imagination/vulkan/pvr_arch_g5p_gfx.c @@ -2312,9 +2312,11 @@ g5p_record_ds_usage(struct pvr_sub_cmd_gfx *sub, const struct vk_dynamic_graphic * of 4 draws from a copy whose elements start on dwords: new stride = align(max(stride, 16), 4), room for the * widest attribute past a small stride (GL's byte vec4 of stride 2). The bytes inside an element keep their * offsets; an attribute at an unaligned offset is shifted out in the vertex program (pvr_g5p_vertex_nir.c). - * The copy runs when the job is submitted (pvr_arch_queue.c drains sub_cmd->gfx.g9p_realigns): a transfer - * recorded before the draw (they run on the CPU at submission) may be what fills the source; a source the GPU - * can write waits for the jobs before it. */ + * The copy runs when the job is submitted (pvr_arch_queue.c drains sub_cmd->gfx.g9p_realigns): a source the GPU + * wrote (storage, texel or transform-feedback binding, a query copy, an A7 compute transfer: g9p_gpu_written) + * waits for the jobs before it (the flag is read again at submission, g9p_realign_needs_wait()); CPU-written + * sources and A8/A9 transfer destinations (transfers run on the CPU at submission, in order) are copied without + * a wait. */ static uint32_t g5p_realigned_stride(uint32_t stride) { @@ -2344,7 +2346,7 @@ g5p_cpu_addr(struct pvr_device *device, uint64_t addr, uint64_t *available) static VkResult g5p_realign_binding(struct pvr_cmd_buffer *cmd_buffer, const struct pvr_vertex_binding *vb, uint32_t stride, - uint32_t extra, uint64_t *addr) + uint32_t extra, bool unaligned, uint64_t *addr) { uint64_t available; const uint8_t *src = g5p_cpu_addr(cmd_buffer->device, vb->buffer->dev_addr.addr + vb->offset, &available); @@ -2379,10 +2381,7 @@ g5p_realign_binding(struct pvr_cmd_buffer *cmd_buffer, const struct pvr_vertex_b const struct g9p_realign r = { .src = src, .dst = pvr_bo_suballoc_get_map_addr(bo), .size = size, .count = count, .stride = stride, .new_stride = new_stride, .dst_addr = bo->dev_addr.addr, .extra = extra, - .gpu_written = vb->buffer->g9p_gpu_written || - (vb->buffer->vk.usage & (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | - VK_BUFFER_USAGE_TRANSFORM_FEEDBACK_BUFFER_BIT_EXT | - VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT)), + .gpu_written = vb->buffer->g9p_gpu_written, .buffer = vb->buffer, }; /* a secondary's render joins its primary's job: copied now */ if (cmd_buffer->vk.level == VK_COMMAND_BUFFER_LEVEL_SECONDARY) { @@ -2391,6 +2390,10 @@ g5p_realign_binding(struct pvr_cmd_buffer *cmd_buffer, const struct pvr_vertex_b memcpy(r.dst + i * r.new_stride, r.src + i * r.stride, MIN2(MAX2(r.new_stride, 16), r.size - i * r.stride)); } else { + if (getenv("G9P_WAITLOG")) + fprintf(stderr, "g5p: realign %s addr 0x%" PRIx64 " stride %u size %" PRIu64 " gpu_written %d\n", + unaligned ? "unaligned" : "overread", vb->buffer->dev_addr.addr + vb->offset, stride, size, + r.gpu_written); util_dynarray_append_typed(&cmd_buffer->state.current_sub_cmd->gfx.g9p_realigns, struct g9p_realign, r); } return VK_SUCCESS; @@ -2667,7 +2670,8 @@ PVR_PER_ARCH(g5p_cmd_draw)(struct pvr_cmd_buffer *cmd_buffer, const struct pvr_g uint64_t binding_base = vb->buffer->dev_addr.addr + vb->offset; if (copy[fe->binding]) { if (!realigned[fe->binding]) { - result = g5p_realign_binding(cmd_buffer, vb, stride, extent[fe->binding], &realigned[fe->binding]); + result = g5p_realign_binding(cmd_buffer, vb, stride, extent[fe->binding], + ((binding_base | stride) & 3) != 0, &realigned[fe->binding]); if (result != VK_SUCCESS) return result; } diff --git a/src/imagination/vulkan/pvr_arch_g5p_query.c b/src/imagination/vulkan/pvr_arch_g5p_query.c index b08ebf26c2c..32c88b3658f 100644 --- a/src/imagination/vulkan/pvr_arch_g5p_query.c +++ b/src/imagination/vulkan/pvr_arch_g5p_query.c @@ -552,6 +552,9 @@ PVR_PER_ARCH(g5p_add_query_program)(struct pvr_cmd_buffer *cmd_buffer, params.count = query_info->copy_query_results.query_count; params.dest_stride = query_info->copy_query_results.stride; params.flags = query_info->copy_query_results.flags; + /* the copy is a GPU kernel: a later realigned vertex binding of + * this buffer must wait for it (g5p_realign_binding()) */ + dst->g9p_gpu_written = true; buffers[0] = dst->dev_addr.addr + query_info->copy_query_results.dst_offset; buffers[1] = diff --git a/src/imagination/vulkan/pvr_arch_g5p_xfb.c b/src/imagination/vulkan/pvr_arch_g5p_xfb.c index 0a4efa7579b..f5979e65191 100644 --- a/src/imagination/vulkan/pvr_arch_g5p_xfb.c +++ b/src/imagination/vulkan/pvr_arch_g5p_xfb.c @@ -116,6 +116,8 @@ PVR_PER_ARCH(g5p_xfb_bind)(struct pvr_cmd_buffer *cmd_buffer, uint32_t first, ui const VkDeviceSize off = offsets[i]; const VkDeviceSize size = !sizes || sizes[i] == VK_WHOLE_SIZE ? buffer->vk.size - off : sizes[i]; st->bind[first + i] = (struct g5p_xfb_range){ buffer, off, size }; + if (buffer) + buffer->g9p_gpu_written = true; } } @@ -128,6 +130,7 @@ g5p_xfb_counters(struct g5p_xfb_range *out, uint32_t first, uint32_t count, cons continue; VK_FROM_HANDLE(pvr_buffer, buffer, counters[i]); out[first + i] = (struct g5p_xfb_range){ buffer, offsets ? offsets[i] : 0, 4 }; + buffer->g9p_gpu_written = true; } } diff --git a/src/imagination/vulkan/pvr_arch_g9p_gfx.c b/src/imagination/vulkan/pvr_arch_g9p_gfx.c index e9856ff4cc6..9ba4f7d41f2 100644 --- a/src/imagination/vulkan/pvr_arch_g9p_gfx.c +++ b/src/imagination/vulkan/pvr_arch_g9p_gfx.c @@ -1715,13 +1715,16 @@ PVR_PER_ARCH(g9p_realign_vertex_bindings)(struct pvr_sub_cmd_gfx *sub_cmd) /* * Whether the copies must wait for the jobs before: host writes are visible at * submission and buffer transfers run on the CPU in order before this job, so - * only a source the GPU itself can write needs it. + * only a source the GPU itself can write needs it. The buffer's flag is read + * here, at submission, not only when the draw was recorded: a storage or + * transform feedback binding recorded after the draw, in a command buffer + * submitted before this one, sets it in between. */ bool PVR_PER_ARCH(g9p_realign_needs_wait)(const struct pvr_sub_cmd_gfx *sub_cmd) { util_dynarray_foreach (&sub_cmd->g9p_realigns, struct g9p_realign, r) { - if (r->gpu_written) + if (r->gpu_written || (r->buffer && r->buffer->g9p_gpu_written)) return true; } return false; @@ -1764,6 +1767,7 @@ realign_vertex_binding(struct pvr_cmd_buffer *cmd_buffer, const struct pvr_verte .stride = stride, .new_stride = new_stride, .gpu_written = vb->buffer->g9p_gpu_written || getenv("G9P_REALIGN_WAIT"), + .buffer = vb->buffer, }; /* a secondary's render joins its primary's job: no list of its own there */ diff --git a/src/imagination/vulkan/pvr_buffer.h b/src/imagination/vulkan/pvr_buffer.h index da4d8958fb6..01916d4b52c 100644 --- a/src/imagination/vulkan/pvr_buffer.h +++ b/src/imagination/vulkan/pvr_buffer.h @@ -33,7 +33,8 @@ struct pvr_buffer { struct pvr_winsys_vma *vma; /* Device address the buffer is mapped to in device virtual address space */ pvr_dev_addr_t dev_addr; - /* G9P: bound where the GPU can write it (storage descriptor, transform feedback) */ + /* G9P, G5P: bound where the GPU can write it (storage descriptor, transform + * feedback; on G5P also a query copy and the A7's compute transfers) */ bool g9p_gpu_written; }; diff --git a/src/imagination/vulkan/pvr_g9p.h b/src/imagination/vulkan/pvr_g9p.h index 7bfebf3e624..8423d0a9375 100644 --- a/src/imagination/vulkan/pvr_g9p.h +++ b/src/imagination/vulkan/pvr_g9p.h @@ -17,6 +17,7 @@ #include "util/log.h" #include "vk_log.h" +struct pvr_buffer; struct pvr_cmd_buffer; struct pvr_compute_pipeline; struct pvr_device; @@ -31,7 +32,11 @@ struct g9p_realign { uint8_t *dst; uint64_t size, count; uint32_t stride, new_stride; - bool gpu_written; /* the source may be written by an earlier GPU job */ + bool gpu_written; /* the source may be written by an earlier GPU job, known when the draw was recorded */ + /* the source's buffer: its g9p_gpu_written is read again at submission (g9p_realign_needs_wait()), as a + * GPU writer recorded after the draw may be submitted before it. A command buffer is only submitted while + * every buffer it uses is alive (destroying one makes it invalid), so the pointer is valid there. */ + const struct pvr_buffer *buffer; uint64_t dst_addr; /* the copy's device address (G5P reuses a copy across the sub-command's draws) */ uint32_t extra; /* G5P: zero bytes after the copy's last element, for its fetches' overread */ }; diff --git a/src/imagination/vulkan/rogue/pvr_blit.c b/src/imagination/vulkan/rogue/pvr_blit.c index 23564c50ff2..776f59daa17 100644 --- a/src/imagination/vulkan/rogue/pvr_blit.c +++ b/src/imagination/vulkan/rogue/pvr_blit.c @@ -1407,6 +1407,7 @@ void pvr_rogue_CmdCopyImageToBuffer2( /* the A7: the compute copy kernel (pvr_arch_g3_compute.c) */ if (PVR_HAS_FEATURE(&cmd_buffer->device->pdevice->dev_info, apple_g3)) { + dst->g9p_gpu_written = true; PVR_PER_ARCH(g3_copy_buffer_image)(cmd_buffer, dst, src, false, pCopyImageToBufferInfo->regionCount, pCopyImageToBufferInfo->pRegions); return; @@ -1713,6 +1714,7 @@ void pvr_rogue_CmdUpdateBuffer(VkCommandBuffer commandBuffer, if (result != VK_SUCCESS) return; if (PVR_HAS_FEATURE(&cmd_buffer->device->pdevice->dev_info, apple_g3)) { + dst->g9p_gpu_written = true; PVR_PER_ARCH(g3_copy_buffer)(cmd_buffer, pvr_bo->dev_addr.addr, dst->dev_addr.addr + dstOffset, dataSize); return; } @@ -1738,6 +1740,7 @@ void pvr_rogue_CmdCopyBuffer2(VkCommandBuffer commandBuffer, /* the A7: the compute copy kernel (pvr_arch_g3_compute.c) */ if (PVR_HAS_FEATURE(&cmd_buffer->device->pdevice->dev_info, apple_g3)) { + dst->g9p_gpu_written = true; for (uint32_t i = 0; i < pCopyBufferInfo->regionCount; i++) PVR_PER_ARCH(g3_copy_buffer)(cmd_buffer, src->dev_addr.addr + pCopyBufferInfo->pRegions[i].srcOffset, dst->dev_addr.addr + pCopyBufferInfo->pRegions[i].dstOffset, @@ -1790,6 +1793,7 @@ void pvr_rogue_CmdFillBuffer(VkCommandBuffer commandBuffer, */ fillSize &= ~3ULL; if (PVR_HAS_FEATURE(&cmd_buffer->device->pdevice->dev_info, apple_g3)) { + dst->g9p_gpu_written = true; PVR_PER_ARCH(g3_fill_buffer)(cmd_buffer, dst->dev_addr.addr + dstOffset, fillSize, data); return; }