#include "vc5_context.h"
#include "vc5_resource.h"
#include "vc5_cl.h"
-#include "broadcom/cle/v3d_packet_v33_pack.h"
#include "broadcom/compiler/v3d_compiler.h"
+#include "broadcom/common/v3d_macros.h"
+#include "broadcom/cle/v3dx_pack.h"
/**
* Does the initial bining command list setup for drawing to a given FBO.
vc5_job_add_bo(job, job->bcl.bo);
job->tile_alloc = vc5_bo_alloc(vc5->screen, 1024 * 1024, "tile alloc");
- struct vc5_bo *tsda = vc5_bo_alloc(vc5->screen,
- job->draw_tiles_y *
- job->draw_tiles_x *
- 64,
- "TSDA");
-
+ uint32_t tsda_per_tile_size = vc5->screen->devinfo.ver >= 40 ? 256 : 64;
+ job->tile_state = vc5_bo_alloc(vc5->screen,
+ job->draw_tiles_y *
+ job->draw_tiles_x *
+ tsda_per_tile_size,
+ "TSDA");
+
+#if V3D_VERSION < 40
/* "Binning mode lists start with a Tile Binning Mode Configuration
* item (120)"
*
cl_address(job->tile_alloc, 0);
config.tile_allocation_memory_size = job->tile_alloc->size;
}
+#endif
cl_emit(&job->bcl, TILE_BINNING_MODE_CONFIGURATION_PART1, config) {
+#if V3D_VERSION >= 40
+ config.width_in_pixels_minus_1 = vc5->framebuffer.width - 1;
+ config.height_in_pixels_minus_1 = vc5->framebuffer.height - 1;
+ config.number_of_render_targets_minus_1 =
+ MAX2(vc5->framebuffer.nr_cbufs, 1) - 1;
+#else /* V3D_VERSION < 40 */
config.tile_state_data_array_base_address =
- cl_address(tsda, 0);
+ cl_address(job->tile_state, 0);
config.width_in_tiles = job->draw_tiles_x;
config.height_in_tiles = job->draw_tiles_y;
-
/* Must be >= 1 */
- config.number_of_render_targets = 1;
+ config.number_of_render_targets =
+ MAX2(vc5->framebuffer.nr_cbufs, 1);
+#endif /* V3D_VERSION < 40 */
config.multisample_mode_4x = job->msaa;
config.maximum_bpp_of_all_render_targets = job->internal_bpp;
}
- vc5_bo_unreference(&tsda);
-
/* There's definitely nothing in the VCD cache we want. */
cl_emit(&job->bcl, FLUSH_VCD_CACHE, bin);
+ /* Disable any leftover OQ state from another job. */
+ cl_emit(&job->bcl, OCCLUSION_QUERY_COUNTER, counter);
+
/* "Binning mode lists must have a Start Tile Binning item (6) after
* any prefix state data before the binning list proper starts."
*/
cl_emit(&job->bcl, START_TILE_BINNING, bin);
- cl_emit(&job->bcl, PRIMITIVE_LIST_FORMAT, fmt) {
- fmt.data_type = LIST_INDEXED;
- fmt.primitive_type = LIST_TRIANGLES;
- }
-
job->needs_flush = true;
job->draw_width = vc5->framebuffer.width;
job->draw_height = vc5->framebuffer.height;
}
}
-static struct vc5_cl_reloc
-vc5_get_default_values(struct vc5_context *vc5)
-{
- struct vc5_job *job = vc5->job;
-
- /* VC5_DIRTY_VTXSTATE */
- struct vc5_vertex_stateobj *vtx = vc5->vtx;
-
- /* Set up the default values for attributes. */
- vc5_cl_ensure_space(&job->indirect, 4 * 4 * vtx->num_elements, 4);
- struct vc5_cl_reloc default_values =
- cl_address(job->indirect.bo, cl_offset(&job->indirect));
- vc5_bo_reference(default_values.bo);
-
- struct vc5_cl_out *defaults = cl_start(&job->indirect);
- for (int i = 0; i < vtx->num_elements; i++) {
- cl_aligned_f(&defaults, 0.0);
- cl_aligned_f(&defaults, 0.0);
- cl_aligned_f(&defaults, 0.0);
- cl_aligned_f(&defaults, 1.0);
- }
- cl_end(&job->indirect, defaults);
-
- return default_values;
-}
-
static void
vc5_emit_gl_shader_state(struct vc5_context *vc5,
const struct pipe_draw_info *info)
vc5_write_uniforms(vc5, vc5->prog.cs,
&vc5->constbuf[PIPE_SHADER_VERTEX],
&vc5->verttex);
- struct vc5_cl_reloc default_values = vc5_get_default_values(vc5);
+ /* See GFXH-930 workaround below */
+ uint32_t num_elements_to_emit = MAX2(vtx->num_elements, 1);
uint32_t shader_rec_offset =
vc5_cl_ensure_space(&job->indirect,
cl_packet_length(GL_SHADER_STATE_RECORD) +
- vtx->num_elements *
+ num_elements_to_emit *
cl_packet_length(GL_SHADER_STATE_ATTRIBUTE_RECORD),
32);
shader.coordinate_shader_has_separate_input_and_output_vpm_blocks = true;
shader.vertex_shader_has_separate_input_and_output_vpm_blocks = true;
shader.coordinate_shader_input_vpm_segment_size =
- vc5->prog.cs->prog_data.vs->vpm_input_size;
+ MAX2(vc5->prog.cs->prog_data.vs->vpm_input_size, 1);
shader.vertex_shader_input_vpm_segment_size =
- vc5->prog.vs->prog_data.vs->vpm_input_size;
+ MAX2(vc5->prog.vs->prog_data.vs->vpm_input_size, 1);
shader.coordinate_shader_output_vpm_segment_size =
vc5->prog.cs->prog_data.vs->vpm_output_size;
shader.vertex_shader_uniforms_address = vs_uniforms;
shader.fragment_shader_uniforms_address = fs_uniforms;
+#if V3D_VERSION >= 41
+ shader.coordinate_shader_4_way_threadable =
+ vc5->prog.cs->prog_data.vs->base.threads == 4;
+ shader.vertex_shader_4_way_threadable =
+ vc5->prog.vs->prog_data.vs->base.threads == 4;
+ shader.fragment_shader_4_way_threadable =
+ vc5->prog.fs->prog_data.fs->base.threads == 4;
+
+ shader.coordinate_shader_start_in_final_thread_section =
+ vc5->prog.cs->prog_data.vs->base.single_seg;
+ shader.vertex_shader_start_in_final_thread_section =
+ vc5->prog.vs->prog_data.vs->base.single_seg;
+ shader.fragment_shader_start_in_final_thread_section =
+ vc5->prog.fs->prog_data.fs->base.single_seg;
+#else
+ shader.coordinate_shader_4_way_threadable =
+ vc5->prog.cs->prog_data.vs->base.threads == 4;
+ shader.coordinate_shader_2_way_threadable =
+ vc5->prog.cs->prog_data.vs->base.threads == 2;
+ shader.vertex_shader_4_way_threadable =
+ vc5->prog.vs->prog_data.vs->base.threads == 4;
+ shader.vertex_shader_2_way_threadable =
+ vc5->prog.vs->prog_data.vs->base.threads == 2;
+ shader.fragment_shader_4_way_threadable =
+ vc5->prog.fs->prog_data.fs->base.threads == 4;
+ shader.fragment_shader_2_way_threadable =
+ vc5->prog.fs->prog_data.fs->base.threads == 2;
+#endif
+
shader.vertex_id_read_by_coordinate_shader =
vc5->prog.cs->prog_data.vs->uses_vid;
shader.instance_id_read_by_coordinate_shader =
shader.instance_id_read_by_vertex_shader =
vc5->prog.vs->prog_data.vs->uses_iid;
- shader.address_of_default_attribute_values = default_values;
+ shader.address_of_default_attribute_values =
+ cl_address(vtx->default_attribute_values, 0);
}
for (int i = 0; i < vtx->num_elements; i++) {
struct pipe_vertex_buffer *vb =
&vertexbuf->vb[elem->vertex_buffer_index];
struct vc5_resource *rsc = vc5_resource(vb->buffer.resource);
- const struct util_format_description *desc =
- util_format_description(elem->src_format);
-
- uint32_t offset = vb->buffer_offset + elem->src_offset;
- cl_emit(&job->indirect, GL_SHADER_STATE_ATTRIBUTE_RECORD, attr) {
- uint32_t r_size = desc->channel[0].size;
-
- /* vec_size == 0 means 4 */
- attr.vec_size = desc->nr_channels & 3;
-
- switch (desc->channel[0].type) {
- case UTIL_FORMAT_TYPE_FLOAT:
- if (r_size == 32) {
- attr.type = ATTRIBUTE_FLOAT;
- } else {
- assert(r_size == 16);
- attr.type = ATTRIBUTE_HALF_FLOAT;
- }
- break;
-
- case UTIL_FORMAT_TYPE_SIGNED:
- case UTIL_FORMAT_TYPE_UNSIGNED:
- switch (r_size) {
- case 32:
- attr.type = ATTRIBUTE_INT;
- break;
- case 16:
- attr.type = ATTRIBUTE_SHORT;
- break;
- case 10:
- attr.type = ATTRIBUTE_INT2_10_10_10;
- break;
- case 8:
- attr.type = ATTRIBUTE_BYTE;
- break;
- default:
- fprintf(stderr,
- "format %s unsupported\n",
- desc->name);
- attr.type = ATTRIBUTE_BYTE;
- abort();
- }
- break;
-
- default:
- fprintf(stderr,
- "format %s unsupported\n",
- desc->name);
- abort();
- }
-
- attr.signed_int_type =
- desc->channel[0].type == UTIL_FORMAT_TYPE_SIGNED;
-
- attr.normalized_int_type = desc->channel[0].normalized;
- attr.read_as_int_uint = desc->channel[0].pure_integer;
- attr.address = cl_address(rsc->bo, offset);
+ const uint32_t size =
+ cl_packet_length(GL_SHADER_STATE_ATTRIBUTE_RECORD);
+ cl_emit_with_prepacked(&job->indirect,
+ GL_SHADER_STATE_ATTRIBUTE_RECORD,
+ &vtx->attrs[i * size], attr) {
attr.stride = vb->stride;
- attr.instance_divisor = elem->instance_divisor;
+ attr.address = cl_address(rsc->bo,
+ vb->buffer_offset +
+ elem->src_offset);
attr.number_of_values_read_by_coordinate_shader =
vc5->prog.cs->prog_data.vs->vattr_sizes[i];
attr.number_of_values_read_by_vertex_shader =
vc5->prog.vs->prog_data.vs->vattr_sizes[i];
+#if V3D_VERSION >= 41
+ attr.maximum_index = 0xffffff;
+#endif
+ }
+ }
+
+ if (vtx->num_elements == 0) {
+ /* GFXH-930: At least one attribute must be enabled and read
+ * by CS and VS. If we have no attributes being consumed by
+ * the shader, set up a dummy to be loaded into the VPM.
+ */
+ cl_emit(&job->indirect, GL_SHADER_STATE_ATTRIBUTE_RECORD, attr) {
+ /* Valid address of data whose value will be unused. */
+ attr.address = cl_address(job->indirect.bo, 0);
+
+ attr.type = ATTRIBUTE_FLOAT;
+ attr.stride = 0;
+ attr.vec_size = 1;
+
+ attr.number_of_values_read_by_coordinate_shader = 1;
+ attr.number_of_values_read_by_vertex_shader = 1;
}
}
cl_emit(&job->bcl, GL_SHADER_STATE, state) {
state.address = cl_address(job->indirect.bo, shader_rec_offset);
- state.number_of_attribute_arrays = vtx->num_elements;
+ state.number_of_attribute_arrays = num_elements_to_emit;
}
vc5_bo_unreference(&cs_uniforms.bo);
vc5_bo_unreference(&vs_uniforms.bo);
vc5_bo_unreference(&fs_uniforms.bo);
- vc5_bo_unreference(&default_values.bo);
job->shader_rec_count++;
}
+/**
+ * Computes the various transform feedback statistics, since they can't be
+ * recorded by CL packets.
+ */
+static void
+vc5_tf_statistics_record(struct vc5_context *vc5,
+ const struct pipe_draw_info *info,
+ bool prim_tf)
+{
+ if (!vc5->active_queries)
+ return;
+
+ uint32_t prims = u_prims_for_vertices(info->mode, info->count);
+ vc5->prims_generated += prims;
+
+ if (prim_tf) {
+ /* XXX: Only count if we didn't overflow. */
+ vc5->tf_prims_generated += prims;
+ }
+}
+
+static void
+vc5_update_job_ez(struct vc5_context *vc5, struct vc5_job *job)
+{
+ switch (vc5->zsa->ez_state) {
+ case VC5_EZ_UNDECIDED:
+ /* If the Z/S state didn't pick a direction but didn't
+ * disable, then go along with the current EZ state. This
+ * allows EZ optimization for Z func == EQUAL or NEVER.
+ */
+ break;
+
+ case VC5_EZ_LT_LE:
+ case VC5_EZ_GT_GE:
+ /* If the Z/S state picked a direction, then it needs to match
+ * the current direction if we've decided on one.
+ */
+ if (job->ez_state == VC5_EZ_UNDECIDED)
+ job->ez_state = vc5->zsa->ez_state;
+ else if (job->ez_state != vc5->zsa->ez_state)
+ job->ez_state = VC5_EZ_DISABLED;
+ break;
+
+ case VC5_EZ_DISABLED:
+ /* If the current Z/S state disables EZ because of a bad Z
+ * func or stencil operation, then we can't do any more EZ in
+ * this frame.
+ */
+ job->ez_state = VC5_EZ_DISABLED;
+ break;
+ }
+
+ /* If the FS affects the Z of the pixels, then it may update against
+ * the chosen EZ direction (though we could use
+ * ARB_conservative_depth's hints to avoid this)
+ */
+ if (vc5->prog.fs->prog_data.fs->writes_z) {
+ job->ez_state = VC5_EZ_DISABLED;
+ }
+
+ if (job->first_ez_state == VC5_EZ_UNDECIDED)
+ job->first_ez_state = job->ez_state;
+}
+
static void
vc5_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info)
{
vc5_start_draw(vc5);
vc5_update_compiled_shaders(vc5, info->mode);
+ vc5_update_job_ez(vc5, job);
- vc5_emit_state(pctx);
+#if V3D_VERSION >= 41
+ v3d41_emit_state(pctx);
+#else
+ v3d33_emit_state(pctx);
+#endif
if (vc5->dirty & (VC5_DIRTY_VTXBUF |
VC5_DIRTY_VTXSTATE |
}
}
- /* The HW only processes transform feedback on primitives with the
- * flag set.
- */
uint32_t prim_tf_enable = 0;
- if (vc5->prog.bind_vs->num_tf_outputs)
+#if V3D_VERSION < 40
+ /* V3D 3.x: The HW only processes transform feedback on primitives
+ * with the flag set.
+ */
+ if (vc5->streamout.num_targets)
prim_tf_enable = (V3D_PRIM_POINTS_TF - V3D_PRIM_POINTS);
+#endif
+
+ vc5_tf_statistics_record(vc5, info, vc5->streamout.num_targets);
/* Note that the primitive type fields match with OpenGL/gallium
* definitions, up to but not including QUADS.
}
struct vc5_resource *rsc = vc5_resource(prsc);
+#if V3D_VERSION >= 40
+ cl_emit(&job->bcl, INDEX_BUFFER_SETUP, ib) {
+ ib.address = cl_address(rsc->bo, 0);
+ ib.size = rsc->bo->size;
+ }
+#endif
+
if (info->instance_count > 1) {
cl_emit(&job->bcl, INDEXED_INSTANCED_PRIMITIVE_LIST, prim) {
prim.index_type = ffs(info->index_size) - 1;
+#if V3D_VERSION >= 40
+ prim.index_offset = offset;
+#else /* V3D_VERSION < 40 */
prim.maximum_index = (1u << 31) - 1; /* XXX */
prim.address_of_indices_list =
cl_address(rsc->bo, offset);
+#endif /* V3D_VERSION < 40 */
prim.mode = info->mode | prim_tf_enable;
prim.enable_primitive_restarts = info->primitive_restart;
cl_emit(&job->bcl, INDEXED_PRIMITIVE_LIST, prim) {
prim.index_type = ffs(info->index_size) - 1;
prim.length = info->count;
+#if V3D_VERSION >= 40
+ prim.index_offset = offset;
+#else /* V3D_VERSION < 40 */
prim.maximum_index = (1u << 31) - 1; /* XXX */
prim.address_of_indices_list =
cl_address(rsc->bo, offset);
+#endif /* V3D_VERSION < 40 */
prim.mode = info->mode | prim_tf_enable;
prim.enable_primitive_restarts = info->primitive_restart;
}
if (vc5->zsa->base.depth.enabled) {
job->resolve |= PIPE_CLEAR_DEPTH;
rsc->initialized_buffers = PIPE_CLEAR_DEPTH;
-
- if (vc5->zsa->early_z_enable)
- job->uses_early_z = true;
}
if (vc5->zsa->base.stencil[0].enabled) {
vc5_job_add_bo(job, rsc->bo);
}
- if (V3D_DEBUG & V3D_DEBUG_ALWAYS_FLUSH)
+ if (job->referenced_size > 768 * 1024 * 1024) {
+ perf_debug("Flushing job with %dkb to try to free up memory\n",
+ job->referenced_size / 1024);
vc5_flush(pctx);
-}
+ }
-static uint32_t
-pack_rgba(enum pipe_format format, const float *rgba)
-{
- union util_color uc;
- util_pack_color(rgba, format, &uc);
- if (util_format_get_blocksize(format) == 2)
- return uc.us;
- else
- return uc.ui[0];
+ if (V3D_DEBUG & V3D_DEBUG_ALWAYS_FLUSH)
+ vc5_flush(pctx);
}
static void
job = vc5_get_job_for_fbo(vc5);
}
- if (buffers & PIPE_CLEAR_COLOR0) {
- struct vc5_resource *rsc =
- vc5_resource(vc5->framebuffer.cbufs[0]->texture);
- uint32_t clear_color;
-
-#if 0
- if (vc5_rt_format_is_565(vc5->framebuffer.cbufs[0]->format)) {
- /* In 565 mode, the hardware will be packing our color
- * for us.
- */
- clear_color = pack_rgba(PIPE_FORMAT_R8G8B8A8_UNORM,
- color->f);
- } else {
- /* Otherwise, we need to do this packing because we
- * support multiple swizzlings of RGBA8888.
- */
- clear_color =
- pack_rgba(vc5->framebuffer.cbufs[0]->format,
- color->f);
+ for (int i = 0; i < VC5_MAX_DRAW_BUFFERS; i++) {
+ uint32_t bit = PIPE_CLEAR_COLOR0 << i;
+ if (!(buffers & bit))
+ continue;
+
+ struct pipe_surface *psurf = vc5->framebuffer.cbufs[i];
+ struct vc5_surface *surf = vc5_surface(psurf);
+ struct vc5_resource *rsc = vc5_resource(psurf->texture);
+
+ union util_color uc;
+ uint32_t internal_size = 4 << surf->internal_bpp;
+
+ static union pipe_color_union swapped_color;
+ if (vc5->swap_color_rb & (1 << i)) {
+ swapped_color.f[0] = color->f[2];
+ swapped_color.f[1] = color->f[1];
+ swapped_color.f[2] = color->f[0];
+ swapped_color.f[3] = color->f[3];
+ color = &swapped_color;
+ }
+
+ switch (surf->internal_type) {
+ case V3D_INTERNAL_TYPE_8:
+ util_pack_color(color->f, PIPE_FORMAT_R8G8B8A8_UNORM,
+ &uc);
+ memcpy(job->clear_color[i], uc.ui, internal_size);
+ break;
+ case V3D_INTERNAL_TYPE_8I:
+ case V3D_INTERNAL_TYPE_8UI:
+ job->clear_color[i][0] = ((color->ui[0] & 0xff) |
+ (color->ui[1] & 0xff) << 8 |
+ (color->ui[2] & 0xff) << 16 |
+ (color->ui[3] & 0xff) << 24);
+ break;
+ case V3D_INTERNAL_TYPE_16F:
+ util_pack_color(color->f, PIPE_FORMAT_R16G16B16A16_FLOAT,
+ &uc);
+ memcpy(job->clear_color[i], uc.ui, internal_size);
+ break;
+ case V3D_INTERNAL_TYPE_16I:
+ case V3D_INTERNAL_TYPE_16UI:
+ job->clear_color[i][0] = ((color->ui[0] & 0xffff) |
+ color->ui[1] << 16);
+ job->clear_color[i][1] = ((color->ui[2] & 0xffff) |
+ color->ui[3] << 16);
+ break;
+ case V3D_INTERNAL_TYPE_32F:
+ case V3D_INTERNAL_TYPE_32I:
+ case V3D_INTERNAL_TYPE_32UI:
+ memcpy(job->clear_color[i], color->ui, internal_size);
+ break;
}
-#endif
- clear_color = pack_rgba(vc5->framebuffer.cbufs[0]->format,
- color->f);
- job->clear_color[0] = job->clear_color[1] = clear_color;
- rsc->initialized_buffers |= (buffers & PIPE_CLEAR_COLOR0);
+ rsc->initialized_buffers |= bit;
}
unsigned zsclear = buffers & PIPE_CLEAR_DEPTHSTENCIL;
}
void
-vc5_draw_init(struct pipe_context *pctx)
+v3dX(draw_init)(struct pipe_context *pctx)
{
pctx->draw_vbo = vc5_draw_vbo;
pctx->clear = vc5_clear;