From: Alyssa Rosenzweig Date: Tue, 25 Aug 2020 20:59:14 +0000 (-0400) Subject: panfrost: XMLify primitive information X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=b60d567edd6fe2149440a0365e3d9b7f899c7057;p=mesa.git panfrost: XMLify primitive information This is grouped as the latter part of the prefix. Some kludges around a magic field for compute jobs that we'll deal with later. (I hope.) Signed-off-by: Alyssa Rosenzweig Part-of: --- diff --git a/src/gallium/drivers/panfrost/pan_cmdstream.c b/src/gallium/drivers/panfrost/pan_cmdstream.c index fb27e213d31..bb5d018f7bd 100644 --- a/src/gallium/drivers/panfrost/pan_cmdstream.c +++ b/src/gallium/drivers/panfrost/pan_cmdstream.c @@ -76,13 +76,13 @@ panfrost_vt_emit_shared_memory(struct panfrost_batch *batch) void panfrost_vt_update_primitive_size(struct panfrost_context *ctx, - struct mali_vertex_tiler_prefix *prefix, + bool points, union midgard_primitive_size *primitive_size) { struct panfrost_rasterizer *rasterizer = ctx->rasterizer; if (!panfrost_writes_point_size(ctx)) { - float val = (prefix->draw_mode == MALI_DRAW_MODE_POINTS) ? + float val = points ? rasterizer->base.point_size : rasterizer->base.line_width; @@ -90,24 +90,6 @@ panfrost_vt_update_primitive_size(struct panfrost_context *ctx, } } -unsigned -panfrost_translate_index_size(unsigned size) -{ - switch (size) { - case 1: - return MALI_DRAW_INDEXED_UINT8; - - case 2: - return MALI_DRAW_INDEXED_UINT16; - - case 4: - return MALI_DRAW_INDEXED_UINT32; - - default: - unreachable("Invalid index size"); - } -} - /* Gets a GPU address for the associated index buffer. Only gauranteed to be * good for the duration of the draw (transient), could last longer. Also get * the bounds on the index buffer for the range accessed by the draw. We do diff --git a/src/gallium/drivers/panfrost/pan_cmdstream.h b/src/gallium/drivers/panfrost/pan_cmdstream.h index f722faf04dd..735b9a4786d 100644 --- a/src/gallium/drivers/panfrost/pan_cmdstream.h +++ b/src/gallium/drivers/panfrost/pan_cmdstream.h @@ -68,9 +68,6 @@ panfrost_emit_vertex_data(struct panfrost_batch *batch, mali_ptr panfrost_vt_emit_shared_memory(struct panfrost_batch *batch); -unsigned -panfrost_translate_index_size(unsigned size); - mali_ptr panfrost_get_index_buffer_bounded(struct panfrost_context *ctx, const struct pipe_draw_info *info, @@ -95,7 +92,7 @@ panfrost_emit_vertex_tiler_jobs(struct panfrost_batch *batch, void panfrost_vt_update_primitive_size(struct panfrost_context *ctx, - struct mali_vertex_tiler_prefix *prefix, + bool points, union midgard_primitive_size *primitive_size); mali_ptr diff --git a/src/gallium/drivers/panfrost/pan_compute.c b/src/gallium/drivers/panfrost/pan_compute.c index 6fdb5f0482a..53a23bcb6a0 100644 --- a/src/gallium/drivers/panfrost/pan_compute.c +++ b/src/gallium/drivers/panfrost/pan_compute.c @@ -128,6 +128,13 @@ panfrost_launch_grid(struct pipe_context *pipe, PIPE_SHADER_COMPUTE, &cfg.push_uniforms); } + unsigned magic = + util_logbase2_ceil(info->block[0] + 1) + + util_logbase2_ceil(info->block[1] + 1) + + util_logbase2_ceil(info->block[2] + 1); + + payload.prefix.primitive.opaque[0] = (magic) << 26; /* XXX */ + memcpy(&payload.postfix, &postfix, sizeof(postfix)); /* Invoke according to the grid info */ diff --git a/src/gallium/drivers/panfrost/pan_context.c b/src/gallium/drivers/panfrost/pan_context.c index e6ebfdb0191..4da307dcfcd 100644 --- a/src/gallium/drivers/panfrost/pan_context.c +++ b/src/gallium/drivers/panfrost/pan_context.c @@ -262,6 +262,17 @@ pan_emit_draw_descs(struct panfrost_batch *batch, d->samplers = panfrost_emit_sampler_descriptors(batch, st); } +static enum mali_index_type +panfrost_translate_index_size(unsigned size) +{ + switch (size) { + case 1: return MALI_INDEX_TYPE_UINT8; + case 2: return MALI_INDEX_TYPE_UINT16; + case 4: return MALI_INDEX_TYPE_UINT32; + default: unreachable("Invalid index size"); + } +} + static void panfrost_draw_vbo( struct pipe_context *pipe, @@ -315,48 +326,43 @@ panfrost_draw_vbo( struct mali_vertex_tiler_prefix vertex_prefix = { 0 }, tiler_prefix = { 0 }; struct mali_draw_packed vertex_postfix, tiler_postfix; + struct mali_primitive_packed primitive; union midgard_primitive_size primitive_size; - unsigned vertex_count; + unsigned vertex_count = ctx->vertex_count; mali_ptr shared_mem = (device->quirks & IS_BIFROST) ? panfrost_vt_emit_shared_memory(batch) : panfrost_batch_reserve_framebuffer(batch); struct pipe_rasterizer_state *rast = &ctx->rasterizer->base; - SET_BIT(tiler_prefix.unknown_draw, MALI_DRAW_FLATSHADE_FIRST, - rast->flatshade_first); - - tiler_prefix.draw_mode = pan_draw_mode(mode); - - unsigned draw_flags = 0x3000; - - if (panfrost_writes_point_size(ctx)) - draw_flags |= MALI_DRAW_VARYING_SIZE; - - if (info->primitive_restart) - draw_flags |= MALI_DRAW_PRIMITIVE_RESTART_FIXED_INDEX; - - if (info->index_size) { - unsigned min_index = 0, max_index = 0; - - tiler_prefix.indices = panfrost_get_index_buffer_bounded(ctx, - info, - &min_index, - &max_index); - - /* Use the corresponding values */ - vertex_count = max_index - min_index + 1; - ctx->offset_start = min_index + info->index_bias; - tiler_prefix.offset_bias_correction = -min_index; - tiler_prefix.index_count = MALI_POSITIVE(info->count); - draw_flags |= panfrost_translate_index_size(info->index_size); - } else { - vertex_count = ctx->vertex_count; - ctx->offset_start = info->start; - tiler_prefix.index_count = MALI_POSITIVE(ctx->vertex_count); + unsigned min_index = 0, max_index = 0; + + pan_pack(&primitive, PRIMITIVE, cfg) { + cfg.draw_mode = pan_draw_mode(mode); + cfg.point_size_array = panfrost_writes_point_size(ctx); + cfg.first_provoking_vertex = rast->flatshade_first; + cfg.primitive_restart = info->primitive_restart; + cfg.unknown_3 = 6; + + if (info->index_size) { + cfg.index_type = panfrost_translate_index_size(info->index_size); + cfg.indices = panfrost_get_index_buffer_bounded(ctx, info, + &min_index, &max_index); + + /* Use the corresponding values */ + vertex_count = max_index - min_index + 1; + ctx->offset_start = min_index + info->index_bias; + + cfg.base_vertex_offset = -min_index; + cfg.index_count = info->count; + } else { + ctx->offset_start = info->start; + cfg.index_count = ctx->vertex_count; + } } - tiler_prefix.unknown_draw = draw_flags; + vertex_prefix.primitive.opaque[0] = (5) << 26; /* XXX */ + memcpy(&tiler_prefix.primitive, &primitive, sizeof(primitive)); /* Encode the padded vertex count */ @@ -415,7 +421,7 @@ panfrost_draw_vbo( } primitive_size.pointer = psiz; - panfrost_vt_update_primitive_size(ctx, &tiler_prefix, &primitive_size); + panfrost_vt_update_primitive_size(ctx, info->mode == PIPE_PRIM_POINTS, &primitive_size); /* Fire off the draw itself */ panfrost_emit_vertex_tiler_jobs(batch, &vertex_prefix, &vertex_postfix, diff --git a/src/panfrost/bifrost/test/bi_submit.c b/src/panfrost/bifrost/test/bi_submit.c index 453d9dea51d..8b46569971f 100644 --- a/src/panfrost/bifrost/test/bi_submit.c +++ b/src/panfrost/bifrost/test/bi_submit.c @@ -182,6 +182,9 @@ bit_vertex(struct panfrost_device *dev, panfrost_program prog, struct bifrost_payload_vertex payload = { .prefix = { + .primitive = { + .opaque = { (5) << 26 } + } }, .postfix = { .gl_enables = 0x2, @@ -201,8 +204,6 @@ bit_vertex(struct panfrost_device *dev, panfrost_program prog, 1, 1, 1, true); - payload.prefix.workgroups_x_shift_3 = 5; - struct panfrost_bo *bos[] = { scratchpad, shmem, shader, shader_desc, ubo, var, attr }; diff --git a/src/panfrost/include/panfrost-job.h b/src/panfrost/include/panfrost-job.h index ce5aefd4d96..8cb30ed0cbf 100644 --- a/src/panfrost/include/panfrost-job.h +++ b/src/panfrost/include/panfrost-job.h @@ -420,23 +420,6 @@ struct mali_payload_write_value { * fused payloads. */ -/* Applies to unknown_draw */ - -#define MALI_DRAW_INDEXED_UINT8 (0x10) -#define MALI_DRAW_INDEXED_UINT16 (0x20) -#define MALI_DRAW_INDEXED_UINT32 (0x30) -#define MALI_DRAW_INDEXED_SIZE (0x30) -#define MALI_DRAW_INDEXED_SHIFT (4) - -#define MALI_DRAW_VARYING_SIZE (0x100) - -/* Set to use first vertex as the provoking vertex for flatshading. Clear to - * use the last vertex. This is the default in DX and VK, but not in GL. */ - -#define MALI_DRAW_FLATSHADE_FIRST (0x800) - -#define MALI_DRAW_PRIMITIVE_RESTART_FIXED_INDEX (0x10000) - struct mali_vertex_tiler_prefix { /* This is a dynamic bitfield containing the following things in this order: * @@ -474,52 +457,7 @@ struct mali_vertex_tiler_prefix { */ u32 invocation_shifts; - u32 draw_mode : 4; - u32 unknown_draw : 22; - - /* This is the the same as workgroups_x_shift_2 in compute shaders, but - * always 5 for vertex jobs and 6 for tiler jobs. I suspect this has - * something to do with how many quads get put in the same execution - * engine, which is a balance (you don't want to starve the engine, but - * you also want to distribute work evenly). - */ - u32 workgroups_x_shift_3 : 6; - - - /* Negative of min_index. This is used to compute - * the unbiased index in tiler/fragment shader runs. - * - * The hardware adds offset_bias_correction in each run, - * so that absent an index bias, the first vertex processed is - * genuinely the first vertex (0). But with an index bias, - * the first vertex process is numbered the same as the bias. - * - * To represent this more conviniently: - * unbiased_index = lower_bound_index + - * index_bias + - * offset_bias_correction - * - * This is done since the hardware doesn't accept a index_bias - * and this allows it to recover the unbiased index. - */ - int32_t offset_bias_correction; - u32 zero1; - - /* Like many other strictly nonzero quantities, index_count is - * subtracted by one. For an indexed cube, this is equal to 35 = 6 - * faces * 2 triangles/per face * 3 vertices/per triangle - 1. That is, - * for an indexed draw, index_count is the number of actual vertices - * rendered whereas invocation_count is the number of unique vertices - * rendered (the number of times the vertex shader must be invoked). - * For non-indexed draws, this is just equal to invocation_count. */ - - u32 index_count; - - /* No hidden structure; literally just a pointer to an array of uint - * indices (width depends on flags). Thanks, guys, for not making my - * life insane for once! NULL for non-indexed draws. */ - - u64 indices; + struct mali_primitive_packed primitive; } __attribute__((packed)); /* Point size / line width can either be specified as a 32-bit float (for diff --git a/src/panfrost/lib/decode.c b/src/panfrost/lib/decode.c index 3fa3da0acad..78b0a542ae5 100644 --- a/src/panfrost/lib/decode.c +++ b/src/panfrost/lib/decode.c @@ -1299,49 +1299,30 @@ pandecode_vertex_tiler_prefix(struct mali_vertex_tiler_prefix *p, int job_no, bo size_x, size_y, size_z, groups_x, groups_y, groups_z); - /* TODO: Decode */ - if (p->unknown_draw) - pandecode_prop("unknown_draw = 0x%" PRIx32, p->unknown_draw); - - pandecode_prop("workgroups_x_shift_3 = 0x%" PRIx32, p->workgroups_x_shift_3); - - if (p->draw_mode != MALI_DRAW_MODE_NONE) - pandecode_prop("draw_mode = %s", mali_draw_mode_as_str(p->draw_mode)); - - /* Index count only exists for tiler jobs anyway */ - - if (p->index_count) - pandecode_prop("index_count = MALI_POSITIVE(%" PRId32 ")", p->index_count + 1); - - - unsigned index_raw_size = (p->unknown_draw & MALI_DRAW_INDEXED_SIZE); - index_raw_size >>= MALI_DRAW_INDEXED_SHIFT; + fprintf(pandecode_dump_stream, "Primitive\n"); + struct MALI_PRIMITIVE primitive; + struct mali_primitive_packed prim_packed = p->primitive; + MALI_PRIMITIVE_unpack((const uint8_t *) &prim_packed, &primitive); + MALI_PRIMITIVE_print(pandecode_dump_stream, &primitive, 1 * 2); /* Validate an index buffer is present if we need one. TODO: verify * relationship between invocation_count and index_count */ - if (p->indices) { - unsigned count = p->index_count; - + if (primitive.indices) { /* Grab the size */ - unsigned size = (index_raw_size == 0x3) ? 4 : index_raw_size; + unsigned size = (primitive.index_type == MALI_INDEX_TYPE_UINT32) ? + sizeof(uint32_t) : primitive.index_type; /* Ensure we got a size, and if so, validate the index buffer * is large enough to hold a full set of indices of the given * size */ - if (!index_raw_size) + if (!size) pandecode_msg("XXX: index size missing\n"); else - pandecode_validate_buffer(p->indices, count * size); - } else if (index_raw_size) - pandecode_msg("XXX: unexpected index size %u\n", index_raw_size); - - if (p->offset_bias_correction) - pandecode_prop("offset_bias_correction = %d", p->offset_bias_correction); - - /* TODO: Figure out what this is. It's not zero */ - pandecode_prop("zero1 = 0x%" PRIx32, p->zero1); + pandecode_validate_buffer(primitive.indices, primitive.index_count * size); + } else if (primitive.index_type) + pandecode_msg("XXX: unexpected index size\n"); pandecode_indent--; pandecode_log("},\n"); @@ -2092,8 +2073,11 @@ pandecode_vertex_or_tiler_job_mdg(const struct mali_job_descriptor_header *h, pandecode_vertex_tiler_prefix(&v->prefix, job_no, is_graphics); pandecode_vertex_tiler_postfix(&v->postfix, job_no, false); - bool has_primitive_pointer = v->prefix.unknown_draw & MALI_DRAW_VARYING_SIZE; - pandecode_primitive_size(v->primitive_size, !has_primitive_pointer); + struct MALI_PRIMITIVE primitive; + struct mali_primitive_packed prim_packed = v->prefix.primitive; + MALI_PRIMITIVE_unpack((const uint8_t *) &prim_packed, &primitive); + + pandecode_primitive_size(v->primitive_size, primitive.point_size_array == 0); pandecode_indent--; pandecode_log("};\n"); diff --git a/src/panfrost/lib/midgard.xml b/src/panfrost/lib/midgard.xml index af209576a66..ee887e79440 100644 --- a/src/panfrost/lib/midgard.xml +++ b/src/panfrost/lib/midgard.xml @@ -201,6 +201,13 @@ + + + + + + + @@ -290,6 +297,23 @@ + + + + + + + + + + + + + + + + + diff --git a/src/panfrost/lib/pan_blit.c b/src/panfrost/lib/pan_blit.c index c1b704bff8f..f9ca87ea588 100644 --- a/src/panfrost/lib/pan_blit.c +++ b/src/panfrost/lib/pan_blit.c @@ -343,14 +343,8 @@ panfrost_load_midg( } } - struct midgard_payload_vertex_tiler payload = { - .prefix = { - .draw_mode = MALI_DRAW_MODE_TRIANGLES, - .unknown_draw = 0x3000, - .index_count = MALI_POSITIVE(vertex_count) - }, - }; - + struct midgard_payload_vertex_tiler payload = {}; + struct mali_primitive_packed primitive; struct mali_draw_packed draw; pan_pack(&draw, DRAW, cfg) { @@ -365,10 +359,16 @@ panfrost_load_midg( cfg.shared = fbd; } + pan_pack(&primitive, PRIMITIVE, cfg) { + cfg.draw_mode = MALI_DRAW_MODE_TRIANGLES; + cfg.index_count = vertex_count; + cfg.unknown_3 = 6; + } + + memcpy(&payload.prefix.primitive, &primitive, MALI_DRAW_LENGTH); memcpy(&payload.postfix, &draw, MALI_DRAW_LENGTH); panfrost_pack_work_groups_compute(&payload.prefix, 1, vertex_count, 1, 1, 1, 1, true); - payload.prefix.workgroups_x_shift_3 = 6; panfrost_new_job(pool, scoreboard, MALI_JOB_TYPE_TILER, false, 0, &payload, sizeof(payload), true); } diff --git a/src/panfrost/lib/pan_invocation.c b/src/panfrost/lib/pan_invocation.c index d86b16a2643..cfb5becbf61 100644 --- a/src/panfrost/lib/pan_invocation.c +++ b/src/panfrost/lib/pan_invocation.c @@ -106,9 +106,6 @@ panfrost_pack_work_groups_compute( /* Upload the packed bitfields */ out->invocation_count = packed; out->invocation_shifts = packed_shifts; - - /* TODO: Compute workgroups_x_shift_3 */ - out->workgroups_x_shift_3 = shift_2; } /* Packs vertex/tiler descriptors simultaneously */ @@ -128,9 +125,5 @@ panfrost_pack_work_groups_fused( /* Copy results over */ tiler->invocation_count = vertex->invocation_count; tiler->invocation_shifts = vertex->invocation_shifts; - - /* Set special fields for each */ - vertex->workgroups_x_shift_3 = 5; - tiler->workgroups_x_shift_3 = 6; }