Skip to content
Merged
2 changes: 2 additions & 0 deletions src/imagination/common/pvr_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ static const struct debug_named_value debug_control[] = {
{ "compute_log", PVR_DEBUG_COMPUTE_LOG, "Log compute pipelines and dispatches." },
{ "bo_log", PVR_DEBUG_BO_LOG,
"Log device-memory and driver BO allocations with size, heap and purpose; live-set summary on any failed allocation and at device destroy." },
{ "pass_log", PVR_DEBUG_PASS_LOG,
"Log every render (targets, load/store, draws, programs), job submit and graphics pipeline to $PVR_PASS_LOG.<pid> (else stderr)." },
DEBUG_NAMED_VALUE_END
};
/* clang-format on */
Expand Down
2 changes: 2 additions & 0 deletions src/imagination/common/pvr_debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ extern uint32_t PVR_DEBUG;
#define PVR_DEBUG_ERRORS BITFIELD_BIT(8)

#define PVR_DEBUG_COMPUTE_LOG BITFIELD_BIT(9)
/* per-render, per-submit and per-pipeline records (pvr_pass_log.h) */
#define PVR_DEBUG_PASS_LOG BITFIELD_BIT(10)

void pvr_process_debug_variable(void);

Expand Down
2 changes: 2 additions & 0 deletions src/imagination/vulkan/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pvr_files = files(
'winsys/pvr_winsys_helper.c',
'pvr_bo.c',
'pvr_bo_log.c',
'pvr_pass_log.c',
'pvr_csb.c',
'pvr_descriptor_set.c',
'pvr_device.c',
Expand Down Expand Up @@ -173,6 +174,7 @@ common_per_arch_files += files(
pvr_files += files(
'pvr_g5p_formats.c',
'pvr_g5p_image.c',
'pvr_g5p_reuse.c',
'pvr_g5p_nir.c',
'pvr_g5p_shader_dump.c',
'pvr_errlog.c',
Expand Down
282 changes: 276 additions & 6 deletions src/imagination/vulkan/pvr_arch_cmd_buffer.c

Large diffs are not rendered by default.

17 changes: 11 additions & 6 deletions src/imagination/vulkan/pvr_arch_csb.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "util/list.h"
#include "util/u_dynarray.h"
#include "vk_log.h"
#include "pvr_g5p_reuse.h"

/**
* \brief Adds VDMCTRL_STREAM_LINK/CDMCTRL_STREAM_LINK dwords into the control
Expand Down Expand Up @@ -121,12 +122,16 @@ static bool pvr_csb_buffer_extend(struct pvr_csb *csb)
STATIC_ASSERT(ROGUE_VDMCTRL_GUARD_SIZE_DEFAULT ==
ROGUE_CDMCTRL_GUARD_SIZE_DEFAULT);

result = pvr_bo_alloc(csb->device,
csb->device->heaps.general_heap,
PVR_CMD_BUFFER_CSB_BO_SIZE,
cache_line_size,
PVR_BO_ALLOC_FLAG_CPU_MAPPED,
&pvr_bo);
/* G5P: a block retired by an earlier command buffer whose jobs have
* completed, zeroed (pvr_g5p_reuse.h); else a new one */
pvr_g5p_csb_block_alloc(csb->device, &pvr_bo);
result = pvr_bo ? VK_SUCCESS
: pvr_bo_alloc(csb->device,
csb->device->heaps.general_heap,
PVR_CMD_BUFFER_CSB_BO_SIZE,
cache_line_size,
PVR_BO_ALLOC_FLAG_CPU_MAPPED,
&pvr_bo);
if (result != VK_SUCCESS) {
vk_error(csb->device, result);
csb->status = result;
Expand Down
117 changes: 117 additions & 0 deletions src/imagination/vulkan/pvr_arch_descriptor_set.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
*/

#include <c99_alloca.h>
#include <inttypes.h>
#include "pvr_descriptor_set.h"

#include "util/u_math.h"
#include "vk_descriptor_update_template.h"
#include "vk_format.h"
#include "vk_log.h"
#include "vk_util.h"

Expand All @@ -16,6 +19,7 @@
#include "pvr_device.h"
#include "pvr_entrypoints.h"
#include "pvr_image.h"
#include "pvr_pass_log.h"
#include "pvr_physical_device.h"
#include "pvr_sampler.h"
#include "pvr_g5p_compute_state.h"
Expand Down Expand Up @@ -107,6 +111,86 @@ write_sampler(const struct pvr_descriptor_set *set,
memcpy(desc_mapping, &sampler_desc, sizeof(sampler_desc));
}

/* PVR_DEBUG=pass_log: which bindings hold sampled images and their layout/ext census (pvr_pass_log.h) */
static void
pvr_pass_log_note_image(const struct pvr_descriptor_set *cset,
const struct pvr_descriptor_set_layout_binding *binding,
const VkDescriptorImageInfo *image_info)
{
struct pvr_descriptor_set *set = (struct pvr_descriptor_set *)cset;
const ptrdiff_t b = binding - set->layout->bindings;
bool ext = false, tex = false, lin = false, lin_pot = false, lin_big = false;

if (b < 0 || b >= 64)
return;
if (image_info && image_info->imageView != VK_NULL_HANDLE) {
VK_FROM_HANDLE(pvr_image_view, iv, image_info->imageView);
const struct pvr_image *img = pvr_image_view_get_image(iv);
const uint32_t w = img->vk.extent.width;
const uint32_t h = img->vk.extent.height;
ext = img->vk.external_handle_types || vk_format_get_plane_count(img->vk.format) > 1;
tex = true;
lin = img->memlayout == PVR_MEMLAYOUT_LINEAR;
const bool pot = util_is_power_of_two_nonzero(w) && util_is_power_of_two_nonzero(h);
lin_pot = lin && pot && img->vk.mip_levels == 1 && !img->vk.external_handle_types;
lin_big = lin && (uint64_t)w * h >= 256 * 256;
if (pvr_pass_log_enabled() && pvr_pass_log_image_first(img)) {
pvr_pass_log_printf("T img=@%" PRIx64 " fmt=%s %ux%u levels=%u layers=%u layout=%s usage=%" PRIx64 " ext=%u",
img->dev_addr.addr, pvr_pass_log_format(img->vk.format), w, h,
img->vk.mip_levels, img->vk.array_layers, lin ? "lin" : "twd",
(uint64_t)img->vk.usage, (unsigned)ext);
}
}
const uint64_t bit = BITFIELD64_BIT(b);
if (ext)
set->pass_log_ext |= bit;
else
set->pass_log_ext &= ~bit;
if (tex)
set->pass_log_tex |= bit;
else
set->pass_log_tex &= ~bit;
if (lin)
set->pass_log_lin |= bit;
else
set->pass_log_lin &= ~bit;
if (lin_pot)
set->pass_log_lin_pot |= bit;
else
set->pass_log_lin_pot &= ~bit;
if (lin_big)
set->pass_log_lin_big |= bit;
else
set->pass_log_lin_big &= ~bit;
}

/* Barrier precision (pvr_geom_hazard.h): the image of a descriptor a
* pre-raster stage may read, by (binding, element). Push descriptor sets are
* written into a stack copy and stay untracked; the draw-side capture treats
* them as unknown.
*/
#define PVR_GEOM_PRE_RASTER_STAGES \
(VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT | \
VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT | VK_SHADER_STAGE_GEOMETRY_BIT)

static void
pvr_geom_note_image(const struct pvr_descriptor_set *cset,
const struct pvr_descriptor_set_layout_binding *binding,
uint32_t elem,
const VkDescriptorImageInfo *image_info)
{
struct pvr_descriptor_set *set = (struct pvr_descriptor_set *)cset;
struct pvr_geom_range range = { 0, 0 };

if (!(binding->stage_flags & PVR_GEOM_PRE_RASTER_STAGES))
return;
if (image_info && image_info->imageView != VK_NULL_HANDLE) {
VK_FROM_HANDLE(pvr_image_view, iv, image_info->imageView);
range = pvr_geom_image_range(pvr_image_view_get_image(iv));
}
pvr_geom_set_store(&set->geom_images, (uint32_t)(binding - set->layout->bindings), elem, range);
}

static void
write_image_sampler(const struct pvr_descriptor_set *set,
const VkDescriptorImageInfo *image_info,
Expand Down Expand Up @@ -151,6 +235,9 @@ write_image_sampler(const struct pvr_descriptor_set *set,
}
PVR_G5P_HOOK(image_sampler, set, image_info, &image_sampler_desc)
memcpy(desc_mapping, &image_sampler_desc, sizeof(image_sampler_desc));
pvr_geom_note_image(set, binding, elem, image_info);
if (pvr_pass_log_enabled())
pvr_pass_log_note_image(set, binding, image_info);
}

static void
Expand Down Expand Up @@ -189,6 +276,9 @@ write_sampled_image(const struct pvr_descriptor_set *set,
assert(!image_view->sampler_words[0] && !image_view->sampler_words[1]);

memcpy(desc_mapping, &sampled_image_desc, sizeof(sampled_image_desc));
pvr_geom_note_image(set, binding, elem, image_info);
if (pvr_pass_log_enabled())
pvr_pass_log_note_image(set, binding, image_info);
}

static void
Expand All @@ -201,6 +291,8 @@ write_storage_image(const struct pvr_descriptor_set *set,
const unsigned desc_offset = binding->offset + (elem * binding->stride);
void *desc_mapping = (uint8_t *)set->mapping + desc_offset;

pvr_geom_note_image(set, binding, elem, image_info);

if (image_info->imageView == VK_NULL_HANDLE) {
memset(desc_mapping, 0, sizeof(struct pvr_image_descriptor));
return;
Expand Down Expand Up @@ -479,6 +571,31 @@ void PVR_PER_ARCH(UpdateDescriptorSets)(
memcpy(dst_desc_mapping, src_desc_mapping, src_binding->stride);
}
}
/* barrier precision: the copied elements' images (pvr_geom_note_image()) */
if (dst_binding->stage_flags & PVR_GEOM_PRE_RASTER_STAGES) {
if (src_set->geom_images.overflow)
dst_set->geom_images.overflow = true;
for (uint32_t j = 0; j < copy->descriptorCount; j++) {
const struct pvr_geom_set_image *e =
pvr_geom_set_find(&src_set->geom_images, copy->srcBinding, copy->srcArrayElement + j);
const struct pvr_geom_range none = { 0, 0 };

pvr_geom_set_store(&dst_set->geom_images, copy->dstBinding, copy->dstArrayElement + j,
e ? e->range : none);
}
}
if (pvr_pass_log_enabled() && copy->descriptorCount > 0 &&
copy->srcBinding < 64 && copy->dstBinding < 64) {
const uint64_t sbit = BITFIELD64_BIT(copy->srcBinding);
const uint64_t dbit = BITFIELD64_BIT(copy->dstBinding);
dst_set->pass_log_ext = (dst_set->pass_log_ext & ~dbit) | ((src_set->pass_log_ext & sbit) ? dbit : 0);
dst_set->pass_log_tex = (dst_set->pass_log_tex & ~dbit) | ((src_set->pass_log_tex & sbit) ? dbit : 0);
dst_set->pass_log_lin = (dst_set->pass_log_lin & ~dbit) | ((src_set->pass_log_lin & sbit) ? dbit : 0);
dst_set->pass_log_lin_pot =
(dst_set->pass_log_lin_pot & ~dbit) | ((src_set->pass_log_lin_pot & sbit) ? dbit : 0);
dst_set->pass_log_lin_big =
(dst_set->pass_log_lin_big & ~dbit) | ((src_set->pass_log_lin_big & sbit) ? dbit : 0);
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/imagination/vulkan/pvr_arch_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* SPDX-License-Identifier: MIT
*/

#include "pvr_g5p_reuse.h"
#include "pvr_bo_log.h"
#include "pvr_device.h"

Expand Down Expand Up @@ -901,6 +902,8 @@ VkResult PVR_PER_ARCH(create_device)(struct pvr_physical_device *pdevice,
device,
device->suballoc_usc.default_size);

pvr_g5p_reuse_init(device);

if (p_atomic_inc_return(&instance->active_device_count) >
PVR_SECONDARY_DEVICE_THRESHOLD) {
initial_free_list_size = PVR_SECONDARY_DEVICE_FREE_LIST_INITAL_SIZE;
Expand Down Expand Up @@ -1079,6 +1082,7 @@ VkResult PVR_PER_ARCH(create_device)(struct pvr_physical_device *pdevice,
pvr_bo_log_summary(device, "destroy");
pvr_bo_log_device_finish(device);
}
pvr_g5p_reuse_finish(device);
pvr_bo_suballocator_fini(&device->suballoc_cmd_usc);
pvr_bo_suballocator_fini(&device->suballoc_cmd_pds);
pvr_bo_suballocator_fini(&device->suballoc_cmd_general);
Expand Down Expand Up @@ -1158,6 +1162,7 @@ void PVR_PER_ARCH(destroy_device)(struct pvr_device *device,
pvr_bo_log_summary(device, "destroy");
pvr_bo_log_device_finish(device);
}
pvr_g5p_reuse_finish(device);
pvr_bo_suballocator_fini(&device->suballoc_cmd_usc);
pvr_bo_suballocator_fini(&device->suballoc_cmd_pds);
pvr_bo_suballocator_fini(&device->suballoc_cmd_general);
Expand Down
2 changes: 2 additions & 0 deletions src/imagination/vulkan/pvr_arch_g5p.c
Original file line number Diff line number Diff line change
Expand Up @@ -1606,6 +1606,8 @@ PVR_PER_ARCH(g5p_job_init)(struct pvr_cmd_buffer *cmd_buffer, struct pvr_sub_cmd
hw_render->stencil_resolve_mode != VK_RESOLVE_MODE_NONE;
}
g->skip_empty_tiles = !keep;
g->load_background = load;
g->partial_area = partial;

memcpy(g->background, bgnd, sizeof(g->background));
g->eot[0] = eot_data.data_offset;
Expand Down
2 changes: 1 addition & 1 deletion src/imagination/vulkan/pvr_arch_g5p_compute.c
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,7 @@ PVR_PER_ARCH(g5p_compute_job_submit)(struct pvr_compute_ctx *ctx,
* run on the device. */
if (cs->pvr_bo != list_first_entry(&cs->pvr_bo_list, struct pvr_bo, link))
return vk_errorf(d, VK_ERROR_OUT_OF_HOST_MEMORY, "G5P: chained CDM stream not implemented yet");
struct pvr_winsys_compute_submit_info info = { .wait = wait,
struct pvr_winsys_compute_submit_info info = { .stamp = sub->g5p_stamp, .wait = wait,
.g5p_log = sub->g5p_log_first, .g5p_log_count = sub->g5p_log_count,
.frame_num = d->global_queue_present_count, .job_num = d->global_cmd_buffer_submit_count };
info.fw_stream_len =
Expand Down
91 changes: 91 additions & 0 deletions src/imagination/vulkan/pvr_arch_g5p_gfx.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "util/u_math.h"

#include "pco_g5p_general.h"
#include "pvr_g5p_vtex_plan.h"
#include "pdsc.h"
#include "pdsc_internal.h"
#include "pdsc_isa_pack.h"
Expand Down Expand Up @@ -2396,6 +2397,94 @@ g5p_realign_binding(struct pvr_cmd_buffer *cmd_buffer, const struct pvr_vertex_b
return VK_SUCCESS;
}

/* Barrier precision (pvr_geom_hazard.h): the image a vertex upload reads, into the render's read set; an image
* the driver cannot name makes the geometry stage opaque */
static enum pvr_geom_opaque
g5p_geom_read_image(struct pvr_geom_hazard *hz, const struct pvr_descriptor_state *desc, unsigned set_idx,
unsigned binding, unsigned element)
{
const struct pvr_descriptor_set *set = set_idx < PVR_MAX_DESCRIPTOR_SETS ? desc->sets[set_idx] : NULL;
const struct pvr_geom_set_image *e;

/* push descriptors are written to a stack copy (untracked); an unbound or overflowing set is unknown */
if (!set || !set->layout || (desc->push_set && set == &desc->push_set->instantiate_set) ||
set->geom_images.overflow || binding >= set->layout->binding_count)
return PVR_GEOM_OPAQUE_DESC;
/* its contents may change after this draw is recorded */
if (set->layout->bindings[binding].flags & VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT)
return PVR_GEOM_OPAQUE_DESC;
e = pvr_geom_set_find((struct pvr_geom_set_images *)&set->geom_images, binding, element);
if (e)
pvr_geom_hazard_add_read(hz, e->range);
return PVR_GEOM_OPAQUE_NONE;
}

/* Barrier precision: what this draw's geometry stage reads that a fragment job can write (the images its vertex
* program uploads: a G5P vertex program reads no other image), whether it writes memory (vertex stores, transform
* feedback), and whether its fragment program writes memory. Called once the draw's render is final (after the VDM
* split), so the record lands on the render the draw is in. Buffers are not listed: a fragment job writes one only
* through stores (opaque) or a linear attachment (opaque, pvr_geom_image_buffer_visible()). */
static void
g5p_geom_hazard_note_draw(struct pvr_cmd_buffer *cmd_buffer, const struct pvr_g5p_pipeline *g, bool xfb)
{
struct pvr_sub_cmd *sub = cmd_buffer->state.current_sub_cmd;
const struct pvr_descriptor_state *desc = &cmd_buffer->state.gfx_desc_state;
struct pvr_geom_hazard *hz;
const struct pvr_g5p_stage_uploads *up;
bool same;

STATIC_ASSERT(PVR_MAX_DESCRIPTOR_SETS <= PVR_GEOM_HAZARD_MAX_SETS);
if (!sub || sub->type != PVR_SUB_CMD_TYPE_GRAPHICS ||
pvr_geom_precise_level(&cmd_buffer->device->pdevice->dev_info) < 2)
return;
hz = &sub->gfx.geom_hz;
hz->draws++;
if (g->fs_side_effects)
hz->writes_opaque = true;
if (xfb || g->vs_side_effects) {
hz->reads_opaque = PVR_GEOM_OPAQUE_VS_WRITES;
return;
}
up = g->vs_uploads;
if (hz->reads_opaque || !up)
return;

/* the same program and sets as the previous draw of this render: nothing new (a bound set's contents are fixed
* while the command buffer is recorded; update-after-bind bindings are opaque) */
same = hz->last_pipeline == (const void *)g;
for (unsigned s = 0; s < PVR_MAX_DESCRIPTOR_SETS; s++) {
if (hz->sets[s] != (const void *)desc->sets[s]) {
same = false;
hz->sets[s] = desc->sets[s];
}
}
hz->set_count = PVR_MAX_DESCRIPTOR_SETS;
hz->last_pipeline = g;
if (same)
return;

const unsigned n = up->vtex ? up->vtex->count : up->count;
for (unsigned i = 0; i < n && !hz->reads_opaque; i++) {
enum pvr_geom_opaque why;

if (up->vtex) {
const struct pco_g5p_upload *u = &up->vtex->u[i];

if (u->kind != PCO_G5P_UPLOAD_IMAGE)
continue;
why = g5p_geom_read_image(hz, desc, u->set, u->binding, u->element);
} else {
const struct pvr_g5p_stage_upload *u = &up->u[i];

if (u->kind != PCO_G5P_UPLOAD_IMAGE)
continue;
why = g5p_geom_read_image(hz, desc, u->set, u->binding, u->element);
}
if (why)
hz->reads_opaque = why;
}
}

VkResult
PVR_PER_ARCH(g5p_cmd_draw)(struct pvr_cmd_buffer *cmd_buffer, const struct pvr_g5p_draw *draw)
{
Expand Down Expand Up @@ -2513,6 +2602,8 @@ PVR_PER_ARCH(g5p_cmd_draw)(struct pvr_cmd_buffer *cmd_buffer, const struct pvr_g
return result;
if (g->fs_depth_feedback)
cs->current_sub_cmd->gfx.has_depth_feedback = true;
/* barrier precision: after the last change of program variant (xfb, one-layer, LOD-bias, punch) */
g5p_geom_hazard_note_draw(cmd_buffer, g, xfb);

/* the clip: the render area within the attachment, cut to the scissor
* and to the viewport. A clip smaller than the attachment is the A9 ICD's
Expand Down
Loading
Loading