[Mesa-dev] [PATCH 41/70] i965: Convert performance monitor over to begin/end batch
Chris Wilson
chris at chris-wilson.co.uk
Fri Aug 7 13:13:45 PDT 2015
We need to wrap all batch buffer access inside begin/end. In order to
make that transformation for brw_performance_monitor.c requires a small
amount of code motion, but otherwise straightforward.
To simply the number of places where we try and access the batch, we
move the start/stop based on oa_users into the critical sections.
Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
---
src/mesa/drivers/dri/i965/brw_context.c | 3 ++
.../drivers/dri/i965/brw_performance_monitor.c | 38 ++++++++++------------
2 files changed, 20 insertions(+), 21 deletions(-)
diff --git a/src/mesa/drivers/dri/i965/brw_context.c b/src/mesa/drivers/dri/i965/brw_context.c
index e8d43db..26041e6 100644
--- a/src/mesa/drivers/dri/i965/brw_context.c
+++ b/src/mesa/drivers/dri/i965/brw_context.c
@@ -1575,6 +1575,9 @@ void brw_batch_finish_hook(brw_batch *batch)
*/
brw_emit_query_end(brw);
+ /* We may also need to snapshot and disable OA counters. */
+ brw_perf_monitor_finish_batch(brw);
+
brw->cache.bo_used_by_gpu = true;
}
diff --git a/src/mesa/drivers/dri/i965/brw_performance_monitor.c b/src/mesa/drivers/dri/i965/brw_performance_monitor.c
index dfc003f..5545ac7 100644
--- a/src/mesa/drivers/dri/i965/brw_performance_monitor.c
+++ b/src/mesa/drivers/dri/i965/brw_performance_monitor.c
@@ -703,12 +703,6 @@ emit_mi_report_perf_count(struct brw_context *brw,
{
assert(offset_in_bytes % 64 == 0);
- /* Make sure the commands to take a snapshot fits in a single batch. */
- intel_batchbuffer_require_space(&brw->batch,
- MI_REPORT_PERF_COUNT_BATCH_DWORDS * 4,
- RENDER_RING);
- int batch_used = USED_BATCH(&brw->batch);
-
/* Reports apparently don't always get written unless we flush first. */
brw_emit_mi_flush(brw);
@@ -749,9 +743,6 @@ emit_mi_report_perf_count(struct brw_context *brw,
/* Reports apparently don't always get written unless we flush after. */
brw_emit_mi_flush(brw);
-
- (void) batch_used;
- assert(USED_BATCH(&brw->batch) - batch_used <= MI_REPORT_PERF_COUNT_BATCH_DWORDS * 4);
}
/**
@@ -1101,6 +1092,13 @@ brw_begin_perf_monitor(struct gl_context *ctx,
DBG("Begin(%d)\n", m->Name);
reinitialize_perf_monitor(brw, monitor);
+
+ /* Ensure the OACONTROL enable and snapshot land in the same batch. */
+ if (brw_batch_begin(&brw->batch,
+ (MI_REPORT_PERF_COUNT_BATCH_DWORDS + 3) * 4,
+ RENDER_RING) < 0)
+ return false;
+
if (monitor_needs_oa(brw, m)) {
/* If the global OA bookend BO doesn't exist, allocate it. This should
* only happen once, but we delay until BeginPerfMonitor time to avoid
@@ -1126,12 +1124,8 @@ brw_begin_perf_monitor(struct gl_context *ctx,
calloc(brw->perfmon.entries_per_oa_snapshot, sizeof(uint32_t));
/* If the OA counters aren't already on, enable them. */
- if (brw->perfmon.oa_users == 0) {
- /* Ensure the OACONTROL enable and snapshot land in the same batch. */
- int space = (MI_REPORT_PERF_COUNT_BATCH_DWORDS + 3) * 4;
- intel_batchbuffer_require_space(&brw->batch, space, RENDER_RING);
+ if (brw->perfmon.oa_users++ == 0)
start_oa_counters(brw);
- }
/* Take a starting OA counter snapshot. */
emit_mi_report_perf_count(brw, monitor->oa_bo, 0, REPORT_ID);
@@ -1142,8 +1136,6 @@ brw_begin_perf_monitor(struct gl_context *ctx,
/* Add the monitor to the unresolved list. */
add_to_unresolved_monitor_list(brw, monitor);
-
- ++brw->perfmon.oa_users;
}
if (monitor_needs_statistics_registers(brw, m)) {
@@ -1155,7 +1147,7 @@ brw_begin_perf_monitor(struct gl_context *ctx,
snapshot_statistics_registers(brw, monitor, 0);
}
- return true;
+ return brw_batch_end(&brw->batch) == 0;
}
/**
@@ -1170,14 +1162,16 @@ brw_end_perf_monitor(struct gl_context *ctx,
DBG("End(%d)\n", m->Name);
+ if (brw_batch_begin(&brw->batch, 80, RENDER_RING) < 0)
+ return;
+
if (monitor_needs_oa(brw, m)) {
+ assert(brw->perfmon.oa_users > 0);
+
/* Take an ending OA counter snapshot. */
emit_mi_report_perf_count(brw, monitor->oa_bo,
SECOND_SNAPSHOT_OFFSET_IN_BYTES, REPORT_ID);
-
- --brw->perfmon.oa_users;
-
- if (brw->perfmon.oa_users == 0)
+ if (--brw->perfmon.oa_users == 0)
stop_oa_counters(brw);
if (monitor->oa_head_end == brw->perfmon.bookend_snapshots) {
@@ -1208,6 +1202,8 @@ brw_end_perf_monitor(struct gl_context *ctx,
snapshot_statistics_registers(brw, monitor,
SECOND_SNAPSHOT_OFFSET_IN_BYTES);
}
+
+ brw_batch_end(&brw->batch);
}
/**
--
2.5.0
More information about the mesa-dev
mailing list