diff options
author | Iago Toral Quiroga <[email protected]> | 2019-08-01 12:30:34 +0200 |
---|---|---|
committer | Iago Toral Quiroga <[email protected]> | 2019-08-08 08:36:52 +0200 |
commit | 0f2d1dfe65bfe1ee8f02ce45f100a5508debdfd4 (patch) | |
tree | 3bc9ea893083eb7b1dcad28381145206688b73f8 /src/gallium/drivers/v3d/v3d_context.c | |
parent | cf8986bce058e2724e01c68fcc64e34e59869a06 (diff) |
v3d: use the GPU to record primitives written to transform feedback
We can use the PRIMITIVE_COUNTS_FEEDBACK packet to write various primitive
counts to a buffer, including the number of primives written to transform
feedback buffers, which will handle buffer overflow correctly.
There are a couple of caveats with this:
Primitive counters are reset when we emit a 'Tile Binning Mode Configuration'
packet, which can happen in the middle of a primitives query, so we need to
read the buffer when we submit a job and accumulate the counts in the context
so we don't lose them.
We also need to do the same when we switch primitive type during transform
feedback so we can compute the correct number of recorded vertices from
the number of primitives. This is necessary so we can provide an accurate
vertex count for draw from transform feedback.
v2:
- When computing the number of vertices for a primitive, pass in the base
primitive, since that is what the hardware will count.
- No need to update primitive counts when switching primitive types if
the base primitives are the same.
- Log perf warning when mapping the primitive counts BO for readback (Eric).
- Only emit the primitive counts packet once at job end (Eric).
- Use u_upload mechanism for the primitive counts buffer (Eric).
- Use the XML to generate indices into the primitive counters buffer (Eric).
Fixes piglit tests:
spec/ext_transform_feedback/overflow-edge-cases
spec/ext_transform_feedback/query-primitives_written-bufferrange
spec/ext_transform_feedback/query-primitives_written-bufferrange-discard
spec/ext_transform_feedback/change-size base-shrink
spec/ext_transform_feedback/change-size base-grow
spec/ext_transform_feedback/change-size offset-shrink
spec/ext_transform_feedback/change-size offset-grow
spec/ext_transform_feedback/change-size range-shrink
spec/ext_transform_feedback/change-size range-grow
spec/ext_transform_feedback/intervening-read prims-written
Reviewed-by: Eric Anholt <[email protected]>
Diffstat (limited to 'src/gallium/drivers/v3d/v3d_context.c')
-rw-r--r-- | src/gallium/drivers/v3d/v3d_context.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/gallium/drivers/v3d/v3d_context.c b/src/gallium/drivers/v3d/v3d_context.c index fcd2d5ec69b..8dc8dd63581 100644 --- a/src/gallium/drivers/v3d/v3d_context.c +++ b/src/gallium/drivers/v3d/v3d_context.c @@ -31,6 +31,7 @@ #include "util/u_memory.h" #include "util/u_blitter.h" #include "util/u_upload_mgr.h" +#include "util/u_prim.h" #include "indices/u_primconvert.h" #include "pipe/p_screen.h" @@ -109,6 +110,39 @@ v3d_invalidate_resource(struct pipe_context *pctx, struct pipe_resource *prsc) job->store &= ~(PIPE_CLEAR_DEPTH | PIPE_CLEAR_STENCIL); } +/** + * Flushes the current job to get up-to-date primive counts written to the + * primitive counts BO, then accumulates the transform feedback primitive count + * in the context and the corresponding vertex counts in the bound stream + * output targets. + */ +void +v3d_tf_update_counters(struct v3d_context *v3d) +{ + struct v3d_job *job = v3d_get_job_for_fbo(v3d); + if (job->draw_calls_queued == 0) + return; + + /* In order to get up-to-date primitive counts we need to submit + * the job for execution so we get the counts written to memory. + * Notice that this will require a sync wait for the buffer write. + */ + uint32_t prims_before = v3d->tf_prims_generated; + v3d_job_submit(v3d, job); + uint32_t prims_after = v3d->tf_prims_generated; + if (prims_before == prims_after) + return; + + enum pipe_prim_type prim_type = u_base_prim_type(v3d->prim_mode); + uint32_t num_verts = u_vertices_for_prims(prim_type, + prims_after - prims_before); + for (int i = 0; i < v3d->streamout.num_targets; i++) { + struct v3d_stream_output_target *so = + v3d_stream_output_target(v3d->streamout.targets[i]); + so->recorded_vertex_count += num_verts; + } +} + static void v3d_context_destroy(struct pipe_context *pctx) { @@ -127,6 +161,9 @@ v3d_context_destroy(struct pipe_context *pctx) if (v3d->state_uploader) u_upload_destroy(v3d->state_uploader); + if (v3d->prim_counts) + pipe_resource_reference(&v3d->prim_counts, NULL); + slab_destroy_child(&v3d->transfer_pool); pipe_surface_reference(&v3d->framebuffer.cbufs[0], NULL); |