gallium/radeon: atomize render condition (SET_PREDICATION)
authorMarek Olšák <marek.olsak@amd.com>
Sat, 7 Nov 2015 14:39:39 +0000 (15:39 +0100)
committerMarek Olšák <marek.olsak@amd.com>
Fri, 13 Nov 2015 18:54:42 +0000 (19:54 +0100)
Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
src/gallium/drivers/r600/evergreen_state.c
src/gallium/drivers/r600/r600_hw_context.c
src/gallium/drivers/r600/r600_pipe.h
src/gallium/drivers/r600/r600_state.c
src/gallium/drivers/radeon/r600_pipe_common.c
src/gallium/drivers/radeon/r600_pipe_common.h
src/gallium/drivers/radeon/r600_query.c
src/gallium/drivers/radeonsi/si_hw_context.c
src/gallium/drivers/radeonsi/si_state.c
src/gallium/drivers/radeonsi/si_state.h

index 2fcc49bf7e2a3d34f952c7703e1fcbfa7d4e1e44..684eee7a355979021a32c0d2d3e1ccfd4ec09daa 100644 (file)
@@ -3543,6 +3543,7 @@ void evergreen_init_state_functions(struct r600_context *rctx)
        r600_init_atom(rctx, &rctx->viewport.atom, id++, r600_emit_viewport_state, 0);
        r600_init_atom(rctx, &rctx->stencil_ref.atom, id++, r600_emit_stencil_ref, 4);
        r600_init_atom(rctx, &rctx->vertex_fetch_shader.atom, id++, evergreen_emit_vertex_fetch_shader, 5);
+       r600_add_atom(rctx, &rctx->b.render_cond_atom, id++);
        r600_add_atom(rctx, &rctx->b.streamout.begin_atom, id++);
        r600_add_atom(rctx, &rctx->b.streamout.enable_atom, id++);
        r600_init_atom(rctx, &rctx->vertex_shader.atom, id++, r600_emit_shader, 23);
index f810b7150ea2dcea4545dd58a52c4992de500a87..6409f0bd9f778cf221b70d658325dfbd29d84649 100644 (file)
@@ -323,6 +323,7 @@ void r600_begin_new_cs(struct r600_context *ctx)
        }
        r600_mark_atom_dirty(ctx, &ctx->vertex_shader.atom);
        r600_mark_atom_dirty(ctx, &ctx->b.streamout.enable_atom);
+       r600_mark_atom_dirty(ctx, &ctx->b.render_cond_atom);
 
        if (ctx->blend_state.cso)
                r600_mark_atom_dirty(ctx, &ctx->blend_state.atom);
index 950bb6be76ceae9c83642b05ec8064553b326e7e..bbb55adef827ca46bccc92901e3c12ab128bcba5 100644 (file)
@@ -38,7 +38,7 @@
 
 #include "tgsi/tgsi_scan.h"
 
-#define R600_NUM_ATOMS 42
+#define R600_NUM_ATOMS 43
 
 #define R600_MAX_VIEWPORTS 16
 
index ebb15ee9789ad495c5ac5bed0e616b5fafbf8f99..c2d4abc5ea1a56fd2a07ce686554bdb9ab57586b 100644 (file)
@@ -3106,6 +3106,7 @@ void r600_init_state_functions(struct r600_context *rctx)
        r600_init_atom(rctx, &rctx->config_state.atom, id++, r600_emit_config_state, 3);
        r600_init_atom(rctx, &rctx->stencil_ref.atom, id++, r600_emit_stencil_ref, 4);
        r600_init_atom(rctx, &rctx->vertex_fetch_shader.atom, id++, r600_emit_vertex_fetch_shader, 5);
+       r600_add_atom(rctx, &rctx->b.render_cond_atom, id++);
        r600_add_atom(rctx, &rctx->b.streamout.begin_atom, id++);
        r600_add_atom(rctx, &rctx->b.streamout.enable_atom, id++);
        r600_init_atom(rctx, &rctx->vertex_shader.atom, id++, r600_emit_shader, 23);
index b6f6c92c5cff546641d3ecdfd4e75ae5d5903b94..3599692a857fccda561436fbd0b80f3debe33fdb 100644 (file)
@@ -161,12 +161,6 @@ void r600_postflush_resume_features(struct r600_common_context *ctx)
                r600_resume_nontimer_queries(ctx);
                r600_resume_timer_queries(ctx);
        }
-
-       /* Re-emit PKT3_SET_PREDICATION. */
-       if (ctx->current_render_cond)
-               ctx->b.render_condition(&ctx->b, ctx->current_render_cond,
-                                       ctx->current_render_cond_cond,
-                                       ctx->current_render_cond_mode);
 }
 
 static void r600_flush_from_st(struct pipe_context *ctx,
index 2a3a3a707e311a12a2b1b6fbaeb898e3c3295948..09465ae0596d8628249d531ae2ae1b68ec180af6 100644 (file)
@@ -417,6 +417,7 @@ struct r600_common_context {
        unsigned                        num_draw_calls;
 
        /* Render condition. */
+       struct r600_atom                render_cond_atom;
        struct pipe_query               *current_render_cond;
        unsigned                        current_render_cond_mode;
        boolean                         current_render_cond_cond;
index 18383148a3f04ba143cf721597f8092e5bd8fd26..145b629deb1ddff487631fd1460ad790079f0bf0 100644 (file)
@@ -303,13 +303,36 @@ static void r600_emit_query_end(struct r600_common_context *ctx, struct r600_que
        r600_update_prims_generated_query_state(ctx, query->type, -1);
 }
 
-static void r600_emit_query_predication(struct r600_common_context *ctx, struct r600_query *query,
-                                       int operation, bool flag_wait)
+static void r600_emit_query_predication(struct r600_common_context *ctx,
+                                       struct r600_atom *atom)
 {
        struct radeon_winsys_cs *cs = ctx->gfx.cs;
+       struct r600_query *query = (struct r600_query*)ctx->current_render_cond;
        struct r600_query_buffer *qbuf;
-       unsigned count;
-       uint32_t op = PRED_OP(operation);
+       uint32_t op;
+       bool flag_wait;
+
+       if (!query)
+               return;
+
+       flag_wait = ctx->current_render_cond_mode == PIPE_RENDER_COND_WAIT ||
+                   ctx->current_render_cond_mode == PIPE_RENDER_COND_BY_REGION_WAIT;
+
+       switch (query->type) {
+       case PIPE_QUERY_OCCLUSION_COUNTER:
+       case PIPE_QUERY_OCCLUSION_PREDICATE:
+               op = PRED_OP(PREDICATION_OP_ZPASS);
+               break;
+       case PIPE_QUERY_PRIMITIVES_EMITTED:
+       case PIPE_QUERY_PRIMITIVES_GENERATED:
+       case PIPE_QUERY_SO_STATISTICS:
+       case PIPE_QUERY_SO_OVERFLOW_PREDICATE:
+               op = PRED_OP(PREDICATION_OP_PRIMCOUNT);
+               break;
+       default:
+               assert(0);
+               return;
+       }
 
        /* if true then invert, see GL_ARB_conditional_render_inverted */
        if (ctx->current_render_cond_cond)
@@ -317,13 +340,6 @@ static void r600_emit_query_predication(struct r600_common_context *ctx, struct
        else
                op |= PREDICATION_DRAW_VISIBLE; /* Draw if visable/overflow */
 
-       /* Find how many results there are. */
-       count = 0;
-       for (qbuf = &query->buffer; qbuf; qbuf = qbuf->previous)
-               count += qbuf->results_end / query->result_size;
-       
-       ctx->need_gfx_cs_space(&ctx->b, 5 * count, TRUE);
-       
        op |= flag_wait ? PREDICATION_HINT_WAIT : PREDICATION_HINT_NOWAIT_DRAW;
        
        /* emit predicate packets for all data blocks */
@@ -811,39 +827,21 @@ static void r600_render_condition(struct pipe_context *ctx,
                                  uint mode)
 {
        struct r600_common_context *rctx = (struct r600_common_context *)ctx;
-       struct r600_query *rquery = (struct r600_query *)query;
-       bool wait_flag = false;
+       struct r600_query *rquery = (struct r600_query*)query;
+       struct r600_query_buffer *qbuf;
+       struct r600_atom *atom = &rctx->render_cond_atom;
 
        rctx->current_render_cond = query;
        rctx->current_render_cond_cond = condition;
        rctx->current_render_cond_mode = mode;
+       rctx->predicate_drawing = query != NULL;
 
-       if (query == NULL) {
-               rctx->predicate_drawing = false;
-               return;
-       }
-
-       if (mode == PIPE_RENDER_COND_WAIT ||
-           mode == PIPE_RENDER_COND_BY_REGION_WAIT) {
-               wait_flag = true;
-       }
-
-       rctx->predicate_drawing = true;
+       /* Compute the size of SET_PREDICATION packets. */
+       atom->num_dw = 0;
+       for (qbuf = &rquery->buffer; qbuf; qbuf = qbuf->previous)
+               atom->num_dw += (qbuf->results_end / rquery->result_size) * 5;
 
-       switch (rquery->type) {
-       case PIPE_QUERY_OCCLUSION_COUNTER:
-       case PIPE_QUERY_OCCLUSION_PREDICATE:
-               r600_emit_query_predication(rctx, rquery, PREDICATION_OP_ZPASS, wait_flag);
-               break;
-       case PIPE_QUERY_PRIMITIVES_EMITTED:
-       case PIPE_QUERY_PRIMITIVES_GENERATED:
-       case PIPE_QUERY_SO_STATISTICS:
-       case PIPE_QUERY_SO_OVERFLOW_PREDICATE:
-               r600_emit_query_predication(rctx, rquery, PREDICATION_OP_PRIMCOUNT, wait_flag);
-               break;
-       default:
-               assert(0);
-       }
+       rctx->set_atom_dirty(rctx, atom, query != NULL);
 }
 
 static void r600_suspend_queries(struct r600_common_context *ctx,
@@ -1012,6 +1010,7 @@ void r600_query_init(struct r600_common_context *rctx)
        rctx->b.begin_query = r600_begin_query;
        rctx->b.end_query = r600_end_query;
        rctx->b.get_query_result = r600_get_query_result;
+       rctx->render_cond_atom.emit = r600_emit_query_predication;
 
        if (((struct r600_common_screen*)rctx->b.screen)->info.r600_num_backends > 0)
            rctx->b.render_condition = r600_render_condition;
index 2f4f1eec04b1224cbb72ce2dd967192f0fceee59..f28c11cb1d2daae9d289d1738b5c9692caf110bc 100644 (file)
@@ -182,6 +182,7 @@ void si_begin_new_cs(struct si_context *ctx)
        si_mark_atom_dirty(ctx, &ctx->spi_map);
        si_mark_atom_dirty(ctx, &ctx->spi_ps_input);
        si_mark_atom_dirty(ctx, &ctx->b.streamout.enable_atom);
+       si_mark_atom_dirty(ctx, &ctx->b.render_cond_atom);
        si_all_descriptors_begin_new_cs(ctx);
 
        ctx->scissors.dirty_mask = (1 << SI_MAX_VIEWPORTS) - 1;
index 6c411c11a77e0247c030475d6db6ed7dff9b1a87..93847d5ec2f76314a46a4f90af7ea86776cf076e 100644 (file)
@@ -3069,6 +3069,7 @@ static void si_init_config(struct si_context *sctx);
 
 void si_init_state_functions(struct si_context *sctx)
 {
+       si_init_external_atom(sctx, &sctx->b.render_cond_atom, &sctx->atoms.s.render_cond);
        si_init_external_atom(sctx, &sctx->b.streamout.begin_atom, &sctx->atoms.s.streamout_begin);
        si_init_external_atom(sctx, &sctx->b.streamout.enable_atom, &sctx->atoms.s.streamout_enable);
 
index 8b9a311cd3f09f741684a01bef512fb8424e87fa..f5ca661f8d71943a2e3636bcd32f37f4b09ed2d4 100644 (file)
@@ -110,6 +110,7 @@ union si_state_atoms {
        struct {
                /* The order matters. */
                struct r600_atom *cache_flush;
+               struct r600_atom *render_cond;
                struct r600_atom *streamout_begin;
                struct r600_atom *streamout_enable; /* must be after streamout_begin */
                struct r600_atom *framebuffer;