diff options
author | Rob Clark <[email protected]> | 2017-04-21 17:48:42 -0400 |
---|---|---|
committer | Rob Clark <[email protected]> | 2017-04-22 10:03:02 -0400 |
commit | e769349fc619b7141ed9ba6189d3ed5933527190 (patch) | |
tree | a7b047979f2223d2e0ad1c19334648d70460c12e /src/gallium/drivers/freedreno | |
parent | 52d2fa37f5337f637d04d012331b40d923ea5354 (diff) |
freedreno/a5xx: occlusion query
Signed-off-by: Rob Clark <[email protected]>
Diffstat (limited to 'src/gallium/drivers/freedreno')
-rw-r--r-- | src/gallium/drivers/freedreno/a5xx/fd5_context.c | 1 | ||||
-rw-r--r-- | src/gallium/drivers/freedreno/a5xx/fd5_context.h | 3 | ||||
-rw-r--r-- | src/gallium/drivers/freedreno/a5xx/fd5_emit.h | 7 | ||||
-rw-r--r-- | src/gallium/drivers/freedreno/a5xx/fd5_query.c | 132 |
4 files changed, 140 insertions, 3 deletions
diff --git a/src/gallium/drivers/freedreno/a5xx/fd5_context.c b/src/gallium/drivers/freedreno/a5xx/fd5_context.c index 1e4e83c16fa..bca2ab78aeb 100644 --- a/src/gallium/drivers/freedreno/a5xx/fd5_context.c +++ b/src/gallium/drivers/freedreno/a5xx/fd5_context.c @@ -24,6 +24,7 @@ * Rob Clark <[email protected]> */ +#include "freedreno_query_acc.h" #include "fd5_context.h" #include "fd5_blend.h" diff --git a/src/gallium/drivers/freedreno/a5xx/fd5_context.h b/src/gallium/drivers/freedreno/a5xx/fd5_context.h index 846c4b92242..c8db470f71a 100644 --- a/src/gallium/drivers/freedreno/a5xx/fd5_context.h +++ b/src/gallium/drivers/freedreno/a5xx/fd5_context.h @@ -80,6 +80,9 @@ struct fd5_context { * due to variant change. See fixup_shader_state() */ struct ir3_shader_key last_key; + + /* number of active samples-passed queries: */ + int samples_passed_queries; }; static inline struct fd5_context * diff --git a/src/gallium/drivers/freedreno/a5xx/fd5_emit.h b/src/gallium/drivers/freedreno/a5xx/fd5_emit.h index b18c0a8cb66..83556c298f7 100644 --- a/src/gallium/drivers/freedreno/a5xx/fd5_emit.h +++ b/src/gallium/drivers/freedreno/a5xx/fd5_emit.h @@ -147,9 +147,16 @@ fd5_emit_render_cntl(struct fd_context *ctx, bool blit) * Other bits seem to depend on query state, like if samples-passed * query is active. */ + bool samples_passed = (fd5_context(ctx)->samples_passed_queries > 0); OUT_PKT4(ring, REG_A5XX_RB_RENDER_CNTL, 1); OUT_RING(ring, 0x00000000 | /* RB_RENDER_CNTL */ + COND(samples_passed, A5XX_RB_RENDER_CNTL_SAMPLES_PASSED) | COND(!blit, 0x8)); + + OUT_PKT4(ring, REG_A5XX_GRAS_SC_CNTL, 1); + OUT_RING(ring, 0x00000008 | /* GRAS_SC_CNTL */ + COND(samples_passed, A5XX_GRAS_SC_CNTL_SAMPLES_PASSED)); + } void fd5_emit_vertex_bufs(struct fd_ringbuffer *ring, struct fd5_emit *emit); diff --git a/src/gallium/drivers/freedreno/a5xx/fd5_query.c b/src/gallium/drivers/freedreno/a5xx/fd5_query.c index 894c6825203..2dc4b50897a 100644 --- a/src/gallium/drivers/freedreno/a5xx/fd5_query.c +++ b/src/gallium/drivers/freedreno/a5xx/fd5_query.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Rob Clark <[email protected]> + * Copyright (C) 2017 Rob Clark <[email protected]> * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -24,9 +24,135 @@ * Rob Clark <[email protected]> */ +/* NOTE: see https://github.com/freedreno/freedreno/wiki/A5xx-Queries */ + +#include "freedreno_query_acc.h" +#include "freedreno_resource.h" + +#include "fd5_context.h" +#include "fd5_format.h" #include "fd5_query.h" -void fd5_query_context_init(struct pipe_context *pctx) +/* + * Occlusion Query: + * + * OCCLUSION_COUNTER and OCCLUSION_PREDICATE differ only in how they + * interpret results + */ + +struct PACKED fd5_samples_passed { + uint64_t start; + uint64_t result; + uint64_t stop; +}; + +#define samples_passed(aq, field) \ + fd_resource((aq)->prsc)->bo, \ + offsetof(struct fd5_samples_passed, field), \ + 0, 0 + +static void +occlusion_resume(struct fd_acc_query *aq, struct fd_batch *batch) { - /* TODO */ + struct fd_ringbuffer *ring = batch->draw; + + OUT_PKT4(ring, REG_A5XX_RB_SAMPLE_COUNT_CONTROL, 1); + OUT_RING(ring, A5XX_RB_SAMPLE_COUNT_CONTROL_COPY); + + OUT_PKT4(ring, REG_A5XX_RB_SAMPLE_COUNT_ADDR_LO, 2); + OUT_RELOCW(ring, samples_passed(aq, start)); + + OUT_PKT7(ring, CP_EVENT_WRITE, 1); + OUT_RING(ring, ZPASS_DONE); + fd_reset_wfi(batch); + + fd5_context(batch->ctx)->samples_passed_queries++; +} + +static void +occlusion_pause(struct fd_acc_query *aq, struct fd_batch *batch) +{ + struct fd_ringbuffer *ring = batch->draw; + + OUT_PKT7(ring, CP_MEM_WRITE, 4); + OUT_RELOCW(ring, samples_passed(aq, stop)); + OUT_RING(ring, 0xffffffff); + OUT_RING(ring, 0xffffffff); + + OUT_PKT7(ring, CP_WAIT_MEM_WRITES, 0); + + OUT_PKT4(ring, REG_A5XX_RB_SAMPLE_COUNT_CONTROL, 1); + OUT_RING(ring, A5XX_RB_SAMPLE_COUNT_CONTROL_COPY); + + OUT_PKT4(ring, REG_A5XX_RB_SAMPLE_COUNT_ADDR_LO, 2); + OUT_RELOCW(ring, samples_passed(aq, stop)); + + OUT_PKT7(ring, CP_EVENT_WRITE, 1); + OUT_RING(ring, ZPASS_DONE); + fd_reset_wfi(batch); + + OUT_PKT7(ring, CP_WAIT_REG_MEM, 6); + OUT_RING(ring, 0x00000014); // XXX + OUT_RELOC(ring, samples_passed(aq, stop)); + OUT_RING(ring, 0xffffffff); + OUT_RING(ring, 0xffffffff); + OUT_RING(ring, 0x00000010); // XXX + + /* result += stop - start: */ + OUT_PKT7(ring, CP_MEM_TO_MEM, 9); + OUT_RING(ring, CP_MEM_TO_MEM_0_DOUBLE | + CP_MEM_TO_MEM_0_NEG_C); + OUT_RELOCW(ring, samples_passed(aq, result)); /* dst */ + OUT_RELOC(ring, samples_passed(aq, result)); /* srcA */ + OUT_RELOC(ring, samples_passed(aq, stop)); /* srcB */ + OUT_RELOC(ring, samples_passed(aq, start)); /* srcC */ + + fd5_context(batch->ctx)->samples_passed_queries--; + +} + +static void +occlusion_counter_result(struct fd_context *ctx, void *buf, + union pipe_query_result *result) +{ + struct fd5_samples_passed *sp = buf; + result->u64 = sp->result; +} + +static void +occlusion_predicate_result(struct fd_context *ctx, void *buf, + union pipe_query_result *result) +{ + struct fd5_samples_passed *sp = buf; + result->b = !!sp->result; +} + +static const struct fd_acc_sample_provider occlusion_counter = { + .query_type = PIPE_QUERY_OCCLUSION_COUNTER, + .active = FD_STAGE_DRAW, + .size = sizeof(struct fd5_samples_passed), + .resume = occlusion_resume, + .pause = occlusion_pause, + .result = occlusion_counter_result, +}; + +static const struct fd_acc_sample_provider occlusion_predicate = { + .query_type = PIPE_QUERY_OCCLUSION_PREDICATE, + .active = FD_STAGE_DRAW, + .size = sizeof(struct fd5_samples_passed), + .resume = occlusion_resume, + .pause = occlusion_pause, + .result = occlusion_predicate_result, +}; + +void +fd5_query_context_init(struct pipe_context *pctx) +{ + struct fd_context *ctx = fd_context(pctx); + + ctx->create_query = fd_acc_create_query; + ctx->query_set_stage = fd_acc_query_set_stage; + + fd_acc_query_register_provider(pctx, &occlusion_counter); + fd_acc_query_register_provider(pctx, &occlusion_predicate); } |