<div dir="ltr">On 17 May 2013 10:17, Kenneth Graunke <span dir="ltr"><<a href="mailto:kenneth@whitecape.org" target="_blank">kenneth@whitecape.org</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hardware contexts greatly simplify the query object code. The pipeline<br>
statistics counters get saved and restored with the context, which means<br>
that we don't need to worry about other workloads polluting them.<br>
<br>
This means that we can simply write a single pair of values (one at<br>
BeginQuery and one at EndQuery) rather than a series of pairs. This<br>
also means we don't need to worry about the BO getting full. We also<br>
don't need to delay BO allocation and starting snapshot until the first<br>
draw.<br>
<br>
The generation split here is a little off: technically, Ironlake can also<br>
support hardware contexts. However, the kernel currently doesn't, and<br>
even if it were to do so someday, we'd need to wait a while before<br>
bumping the kernel requirement to take advantage of it.<br>
<br>
Cc: Eric Anholt <<a href="mailto:eric@anholt.net">eric@anholt.net</a>><br>
Cc: Paul Berry <<a href="mailto:stereotype441@gmail.com">stereotype441@gmail.com</a>><br>
Signed-off-by: Kenneth Graunke <<a href="mailto:kenneth@whitecape.org">kenneth@whitecape.org</a>><br>
---<br>
src/mesa/drivers/dri/i965/Makefile.sources | 1 +<br>
src/mesa/drivers/dri/i965/brw_context.c | 2 +<br>
src/mesa/drivers/dri/i965/brw_context.h | 3 +<br>
src/mesa/drivers/dri/i965/brw_queryobj.c | 83 ++-----<br>
src/mesa/drivers/dri/i965/gen6_queryobj.c | 354 +++++++++++++++++++++++++++++<br>
5 files changed, 383 insertions(+), 60 deletions(-)<br>
create mode 100644 src/mesa/drivers/dri/i965/gen6_queryobj.c<br>
<br>
diff --git a/src/mesa/drivers/dri/i965/Makefile.sources b/src/mesa/drivers/dri/i965/Makefile.sources<br>
index a0ffd3a..d67a5a4 100644<br>
--- a/src/mesa/drivers/dri/i965/Makefile.sources<br>
+++ b/src/mesa/drivers/dri/i965/Makefile.sources<br>
@@ -104,6 +104,7 @@ i965_FILES = \<br>
gen6_depthstencil.c \<br>
gen6_gs_state.c \<br>
gen6_multisample_state.c \<br>
+ gen6_queryobj.c \<br>
gen6_sampler_state.c \<br>
gen6_scissor_state.c \<br>
gen6_sf_state.c \<br>
diff --git a/src/mesa/drivers/dri/i965/brw_context.c b/src/mesa/drivers/dri/i965/brw_context.c<br>
index 2f5fedb..beade5c 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_context.c<br>
+++ b/src/mesa/drivers/dri/i965/brw_context.c<br>
@@ -88,6 +88,8 @@ static void brwInitDriverFunctions(struct intel_screen *screen,<br>
<br>
brwInitFragProgFuncs( functions );<br>
brw_init_queryobj_functions(functions);<br>
+ if (screen->gen >= 6)<br>
+ gen6_reinit_queryobj_functions(functions);<br></blockquote><div><br></div><div>I find it confusing that we initialize the queryobj function pointers to the pre-gen6 functions and then immediately override some of them to gen6+ versions.<br>
<br>How about splitting brw_init_queryobj_functions() into brw_init_common_queryobj_functions() and brw_init_pre_gen6_queryobj_functions(), and renaming gen6_reinit_queryobj_functions() to just gen6_init_queryobj_functions()?<br>
<br></div><div>Then this code would change to:<br><br></div><div>brw_init_common_queryobj_functions()<br>if (screen->gen < 6)<br></div><div> brw_init_pre_gen6_queryobj_functions()<br></div><div>else<br></div><div>
gen6_init_queryobj_functions()<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
functions->QuerySamplesForFormat = brw_query_samples_for_format;<br>
functions->BeginTransformFeedback = brw_begin_transform_feedback;<br>
diff --git a/src/mesa/drivers/dri/i965/brw_context.h b/src/mesa/drivers/dri/i965/brw_context.h<br>
index 9baf57b..9ef6aca 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_context.h<br>
+++ b/src/mesa/drivers/dri/i965/brw_context.h<br>
@@ -1164,6 +1164,9 @@ void brw_init_queryobj_functions(struct dd_function_table *functions);<br>
void brw_emit_query_begin(struct brw_context *brw);<br>
void brw_emit_query_end(struct brw_context *brw);<br>
<br>
+/** gen6_queryobj.c */<br>
+void gen6_reinit_queryobj_functions(struct dd_function_table *functions);<br>
+<br>
/*======================================================================<br>
* brw_state_dump.c<br>
*/<br>
diff --git a/src/mesa/drivers/dri/i965/brw_queryobj.c b/src/mesa/drivers/dri/i965/brw_queryobj.c<br>
index 40f926b..1c1e0b4 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_queryobj.c<br>
+++ b/src/mesa/drivers/dri/i965/brw_queryobj.c<br></blockquote><div><br></div><div>So is brw_queryobj.c now for pre-Gen6 only? If so, can we please add a comment to that effect at the top of the file, and remove the remaining intel->gen checks (e.g. in write_timestamp())? If not, can we somehow document which functions are Pre-gen6 and which aren't (e.g. with "assert(intel->gen < 6);" at the top of the pre-gen6 functions)? As it stands this patch leaves the file in a condition where it's hard to tell without a deep understanding of the driver which functions are for which chip generations.<br>
</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
@@ -94,40 +94,21 @@ write_timestamp(struct intel_context *intel, drm_intel_bo *query_bo, int idx)<br>
static void<br>
write_depth_count(struct intel_context *intel, drm_intel_bo *query_bo, int idx)<br>
{ <br></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
- if (intel->gen >= 6) {<br>
- /* Emit Sandybridge workaround flush: */<br>
- if (intel->gen == 6)<br>
- intel_emit_post_sync_nonzero_flush(intel);<br>
-<br>
- BEGIN_BATCH(5);<br>
- OUT_BATCH(_3DSTATE_PIPE_CONTROL | (5 - 2));<br>
- OUT_BATCH(PIPE_CONTROL_DEPTH_STALL |<br>
- PIPE_CONTROL_WRITE_DEPTH_COUNT);<br>
- OUT_RELOC(query_bo,<br>
- I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,<br>
- PIPE_CONTROL_GLOBAL_GTT_WRITE |<br>
- (idx * sizeof(uint64_t)));<br>
- OUT_BATCH(0);<br>
- OUT_BATCH(0);<br>
- ADVANCE_BATCH();<br>
- } else {<br>
- BEGIN_BATCH(4);<br>
- OUT_BATCH(_3DSTATE_PIPE_CONTROL | (4 - 2) |<br>
- PIPE_CONTROL_DEPTH_STALL |<br>
- PIPE_CONTROL_WRITE_DEPTH_COUNT);<br>
- /* This object could be mapped cacheable, but we don't have an exposed<br>
- * mechanism to support that. Since it's going uncached, tell GEM that<br>
- * we're writing to it. The usual clflush should be all that's required<br>
- * to pick up the results.<br>
- */<br>
- OUT_RELOC(query_bo,<br>
- I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,<br>
- PIPE_CONTROL_GLOBAL_GTT_WRITE |<br>
- (idx * sizeof(uint64_t)));<br>
- OUT_BATCH(0);<br>
- OUT_BATCH(0);<br>
- ADVANCE_BATCH();<br>
- }<br>
+ BEGIN_BATCH(4);<br>
+ OUT_BATCH(_3DSTATE_PIPE_CONTROL | (4 - 2) |<br>
+ PIPE_CONTROL_DEPTH_STALL | PIPE_CONTROL_WRITE_DEPTH_COUNT);<br>
+ /* This object could be mapped cacheable, but we don't have an exposed<br>
+ * mechanism to support that. Since it's going uncached, tell GEM that<br>
+ * we're writing to it. The usual clflush should be all that's required<br>
+ * to pick up the results.<br>
+ */<br>
+ OUT_RELOC(query_bo,<br>
+ I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,<br>
+ PIPE_CONTROL_GLOBAL_GTT_WRITE |<br>
+ (idx * sizeof(uint64_t)));<br>
+ OUT_BATCH(0);<br>
+ OUT_BATCH(0);<br>
+ ADVANCE_BATCH();<br>
}<br>
<br>
/**<br>
@@ -165,36 +146,12 @@ brw_queryobj_get_results(struct gl_context *ctx,<br>
/* The query BO contains the starting and ending timestamps.<br>
* Subtract the two and convert to nanoseconds.<br>
*/<br>
- if (intel->gen >= 6)<br>
- query->Base.Result += 80 * (results[1] - results[0]);<br>
- else<br>
- query->Base.Result += 1000 * ((results[1] >> 32) - (results[0] >> 32));<br>
+ query->Base.Result += 1000 * ((results[1] >> 32) - (results[0] >> 32));<br>
break;<br>
<br>
case GL_TIMESTAMP:<br>
/* The query BO contains a single timestamp value in results[0]. */<br>
- if (intel->gen >= 6) {<br>
- /* Our timer is a clock that increments every 80ns (regardless of<br>
- * other clock scaling in the system). The timestamp register we can<br>
- * read for glGetTimestamp() masks out the top 32 bits, so we do that<br>
- * here too to let the two counters be compared against each other.<br>
- *<br>
- * If we just multiplied that 32 bits of data by 80, it would roll<br>
- * over at a non-power-of-two, so an application couldn't use<br>
- * GL_QUERY_COUNTER_BITS to handle rollover correctly. Instead, we<br>
- * report 36 bits and truncate at that (rolling over 5 times as often<br>
- * as the HW counter), and when the 32-bit counter rolls over, it<br>
- * happens to also be at a rollover in the reported value from near<br>
- * (1<<36) to 0.<br>
- *<br>
- * The low 32 bits rolls over in ~343 seconds. Our 36-bit result<br>
- * rolls over every ~69 seconds.<br>
- */<br>
- query->Base.Result = 80 * (results[0] & 0xffffffff);<br>
- query->Base.Result &= (1ull << 36) - 1;<br>
- } else {<br>
- query->Base.Result = 1000 * (results[0] >> 32);<br>
- }<br>
+ query->Base.Result = 1000 * (results[0] >> 32);<br>
break;<br>
<br>
case GL_SAMPLES_PASSED_ARB:<br></blockquote><div><br></div><div>Below this code, in the GL_PRIMITIVES_GENERATED and GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN cases, can we change the comment so that instead of saying "We don't actually query the hardware for this value, so query->bo should always be NULL and execution should never reach here." it says something like "Transform feedback isn't supported pre-gen6"?<br>
<br><div>Similarly, there's code in brw_begin_query() and brw_end_query() for handling GL_PRIMITIVES_GENERATED and GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN that is now unreachable because we don't support transform feedback prior to Gen6. I think we should replace it with a comment to that affect and an assertion.<br>
</div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
@@ -545,6 +502,9 @@ brw_emit_query_begin(struct brw_context *brw)<br>
struct gl_context *ctx = &intel->ctx;<br>
struct brw_query_object *query = brw->query.obj;<br>
<br>
+ if (intel->hw_ctx)<br>
+ return;<br>
+<br></blockquote><div><br></div><div>The comment above brw_emit_query_begin() says that we record PS_DEPTH_COUNT at the beginning and end of each batch, regardless of whether hardware contexts are in use. Can we please change the comment to reflect the new behaviour?<br>
<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
/* Skip if we're not doing any queries, or we've already recorded the<br>
* initial query value for this batchbuffer.<br>
*/<br>
@@ -569,6 +529,9 @@ brw_emit_query_end(struct brw_context *brw)<br>
struct intel_context *intel = &brw->intel;<br>
struct brw_query_object *query = brw->query.obj;<br>
<br>
+ if (intel->hw_ctx)<br>
+ return;<br>
+<br>
if (!brw->query.begin_emitted)<br>
return;<br>
<br>
diff --git a/src/mesa/drivers/dri/i965/gen6_queryobj.c b/src/mesa/drivers/dri/i965/gen6_queryobj.c<br>
new file mode 100644<br>
index 0000000..28af8d7<br>
--- /dev/null<br>
+++ b/src/mesa/drivers/dri/i965/gen6_queryobj.c<br>
@@ -0,0 +1,354 @@<br>
+/*<br>
+ * Copyright © 2008 Intel Corporation<br>
+ *<br>
+ * Permission is hereby granted, free of charge, to any person obtaining a<br>
+ * copy of this software and associated documentation files (the "Software"),<br>
+ * to deal in the Software without restriction, including without limitation<br>
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
+ * and/or sell copies of the Software, and to permit persons to whom the<br>
+ * Software is furnished to do so, subject to the following conditions:<br>
+ *<br>
+ * The above copyright notice and this permission notice (including the next<br>
+ * paragraph) shall be included in all copies or substantial portions of the<br>
+ * Software.<br>
+ *<br>
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL<br>
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br>
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS<br>
+ * IN THE SOFTWARE.<br>
+ *<br>
+ * Authors:<br>
+ * Eric Anholt <<a href="mailto:eric@anholt.net">eric@anholt.net</a>><br>
+ * Kenneth Graunke <<a href="mailto:kenneth@whitecape.org">kenneth@whitecape.org</a>><br>
+ */<br>
+<br>
+/** @file gen6_queryobj.c<br>
+ *<br>
+ * Support for query objects (GL_ARB_occlusion_query, GL_ARB_timer_query,<br>
+ * GL_EXT_transform_feedback, and friends) on platforms that support<br>
+ * hardware contexts (Gen6+).<br>
+ */<br>
+#include "main/imports.h"<br>
+<br>
+#include "brw_context.h"<br>
+#include "brw_defines.h"<br>
+#include "brw_state.h"<br>
+#include "intel_batchbuffer.h"<br>
+#include "intel_reg.h"<br>
+<br>
+/**<br>
+ * Emit PIPE_CONTROLs to write the current GPU timestamp into a buffer.<br>
+ */<br>
+static void<br>
+write_timestamp(struct intel_context *intel, drm_intel_bo *query_bo, int idx)<br>
+{<br>
+ /* Emit workaround flushes: */<br>
+ if (intel->gen == 6) {<br>
+ /* The timestamp write below is a non-zero post-sync op, which on<br>
+ * Gen6 necessitates a CS stall. CS stalls need stall at scoreboard<br>
+ * set. See the comments for intel_emit_post_sync_nonzero_flush().<br>
+ */<br>
+ BEGIN_BATCH(4);<br>
+ OUT_BATCH(_3DSTATE_PIPE_CONTROL | (4 - 2));<br>
+ OUT_BATCH(PIPE_CONTROL_CS_STALL | PIPE_CONTROL_STALL_AT_SCOREBOARD);<br>
+ OUT_BATCH(0);<br>
+ OUT_BATCH(0);<br>
+ ADVANCE_BATCH();<br>
+ }<br>
+<br>
+ BEGIN_BATCH(5);<br>
+ OUT_BATCH(_3DSTATE_PIPE_CONTROL | (5 - 2));<br>
+ OUT_BATCH(PIPE_CONTROL_WRITE_TIMESTAMP);<br>
+ OUT_RELOC(query_bo,<br>
+ I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,<br>
+ PIPE_CONTROL_GLOBAL_GTT_WRITE |<br>
+ idx * sizeof(uint64_t));<br>
+ OUT_BATCH(0);<br>
+ OUT_BATCH(0);<br>
+ ADVANCE_BATCH();<br>
+}<br>
+<br>
+/**<br>
+ * Emit PIPE_CONTROLs to write the PS_DEPTH_COUNT register into a buffer.<br>
+ */<br>
+static void<br>
+write_depth_count(struct intel_context *intel, drm_intel_bo *query_bo, int idx)<br>
+{<br>
+ /* Emit Sandybridge workaround flush: */<br>
+ if (intel->gen == 6)<br>
+ intel_emit_post_sync_nonzero_flush(intel);<br>
+<br>
+ BEGIN_BATCH(5);<br>
+ OUT_BATCH(_3DSTATE_PIPE_CONTROL | (5 - 2));<br>
+ OUT_BATCH(PIPE_CONTROL_DEPTH_STALL |<br>
+ PIPE_CONTROL_WRITE_DEPTH_COUNT);<br>
+ OUT_RELOC(query_bo,<br>
+ I915_GEM_DOMAIN_INSTRUCTION, I915_GEM_DOMAIN_INSTRUCTION,<br>
+ PIPE_CONTROL_GLOBAL_GTT_WRITE |<br>
+ (idx * sizeof(uint64_t)));<br>
+ OUT_BATCH(0);<br>
+ OUT_BATCH(0);<br>
+ ADVANCE_BATCH();<br>
+}<br>
+<br>
+/**<br>
+ * Wait on the query object's BO and calculate the final result.<br>
+ */<br>
+static void<br>
+gen6_queryobj_get_results(struct gl_context *ctx,<br>
+ struct brw_query_object *query)<br>
+{<br>
+ struct intel_context *intel = intel_context(ctx);<br>
+<br>
+ if (query->bo == NULL)<br>
+ return;<br>
+<br>
+ /* If the application has requested the query result, but this batch is<br>
+ * still contributing to it, flush it now so the results will be present<br>
+ * when mapped.<br>
+ */<br>
+ if (drm_intel_bo_references(intel-><a href="http://batch.bo" target="_blank">batch.bo</a>, query->bo))<br>
+ intel_batchbuffer_flush(intel);<br>
+<br>
+ if (unlikely(intel->perf_debug)) {<br>
+ if (drm_intel_bo_busy(query->bo)) {<br>
+ perf_debug("Stalling on the GPU waiting for a query object.\n");<br>
+ }<br>
+ }<br>
+<br>
+ drm_intel_bo_map(query->bo, false);<br>
+ uint64_t *results = query->bo->virtual;<br>
+ switch (query->Base.Target) {<br>
+ case GL_TIME_ELAPSED:<br>
+ /* The query BO contains the starting and ending timestamps.<br>
+ * Subtract the two and convert to nanoseconds.<br>
+ */<br>
+ query->Base.Result += 80 * (results[1] - results[0]);<br>
+ break;<br>
+<br>
+ case GL_TIMESTAMP:<br>
+ /* Our timer is a clock that increments every 80ns (regardless of<br>
+ * other clock scaling in the system). The timestamp register we can<br>
+ * read for glGetTimestamp() masks out the top 32 bits, so we do that<br>
+ * here too to let the two counters be compared against each other.<br>
+ *<br>
+ * If we just multiplied that 32 bits of data by 80, it would roll<br>
+ * over at a non-power-of-two, so an application couldn't use<br>
+ * GL_QUERY_COUNTER_BITS to handle rollover correctly. Instead, we<br>
+ * report 36 bits and truncate at that (rolling over 5 times as often<br>
+ * as the HW counter), and when the 32-bit counter rolls over, it<br>
+ * happens to also be at a rollover in the reported value from near<br>
+ * (1<<36) to 0.<br>
+ *<br>
+ * The low 32 bits rolls over in ~343 seconds. Our 36-bit result<br>
+ * rolls over every ~69 seconds.<br>
+ *<br>
+ * The query BO contains a single timestamp value in results[0].<br>
+ */<br>
+ query->Base.Result = 80 * (results[0] & 0xffffffff);<br>
+ query->Base.Result &= (1ull << 36) - 1;<br>
+ break;<br>
+<br>
+ case GL_SAMPLES_PASSED_ARB:<br>
+ query->Base.Result += results[1] - results[0];<br>
+ break;<br>
+<br>
+ case GL_ANY_SAMPLES_PASSED:<br>
+ case GL_ANY_SAMPLES_PASSED_CONSERVATIVE:<br>
+ query->Base.Result = results[0] != results[1];<br>
+ break;<br>
+<br>
+ case GL_PRIMITIVES_GENERATED:<br>
+ case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN:<br>
+ /* We don't actually query the hardware for this value, so query->bo<br>
+ * should always be NULL and execution should never reach here.<br>
+ */<br>
+ assert(!"Unreachable");<br>
+ break;<br>
+<br>
+ default:<br>
+ assert(!"Unrecognized query target in brw_queryobj_get_results()");<br>
+ break;<br>
+ }<br>
+ drm_intel_bo_unmap(query->bo);<br>
+<br>
+ /* Now that we've processed the data stored in the query's buffer object,<br>
+ * we can release it.<br>
+ */<br>
+ drm_intel_bo_unreference(query->bo);<br>
+ query->bo = NULL;<br>
+}<br>
+<br>
+/**<br>
+ * Driver hook for glBeginQuery().<br>
+ *<br>
+ * Initializes driver structures and emits any GPU commands required to begin<br>
+ * recording data for the query.<br>
+ */<br>
+static void<br>
+gen6_begin_query(struct gl_context *ctx, struct gl_query_object *q)<br>
+{<br>
+ struct brw_context *brw = brw_context(ctx);<br>
+ struct intel_context *intel = intel_context(ctx);<br>
+ struct brw_query_object *query = (struct brw_query_object *)q;<br>
+<br>
+ switch (query->Base.Target) {<br>
+ case GL_TIME_ELAPSED:<br>
+ /* For timestamp queries, we record the starting time right away so that<br>
+ * we measure the full time between BeginQuery and EndQuery. There's<br>
+ * some debate about whether this is the right thing to do. Our decision<br>
+ * is based on the following text from the ARB_timer_query extension:<br>
+ *<br>
+ * "(5) Should the extension measure total time elapsed between the full<br>
+ * completion of the BeginQuery and EndQuery commands, or just time<br>
+ * spent in the graphics library?<br>
+ *<br>
+ * RESOLVED: This extension will measure the total time elapsed<br>
+ * between the full completion of these commands. Future extensions<br>
+ * may implement a query to determine time elapsed at different stages<br>
+ * of the graphics pipeline."<br>
+ *<br>
+ * We write a starting timestamp now (at index 0). At EndQuery() time,<br>
+ * we'll write a second timestamp (at index 1), and subtract the two to<br>
+ * obtain the time elapsed. Notably, this includes time elapsed while<br>
+ * the system was doing other work, such as running other applications.<br>
+ */<br>
+ drm_intel_bo_unreference(query->bo);<br>
+ query->bo = drm_intel_bo_alloc(intel->bufmgr, "timer query", 4096, 4096);<br>
+ write_timestamp(intel, query->bo, 0);<br>
+ break;<br>
+<br>
+ case GL_ANY_SAMPLES_PASSED:<br>
+ case GL_ANY_SAMPLES_PASSED_CONSERVATIVE:<br>
+ case GL_SAMPLES_PASSED_ARB:<br>
+ /* Since we're starting a new query, we need to be sure to throw away<br>
+ * any previous occlusion query results.<br>
+ */<br>
+ drm_intel_bo_unreference(query->bo);<br>
+ query->bo = drm_intel_bo_alloc(intel->bufmgr, "occl. query", 4096, 4096);<br>
+ write_depth_count(intel, query->bo, 0);<br>
+ break;<br>
+<br>
+ case GL_PRIMITIVES_GENERATED:<br>
+ /* We don't actually query the hardware for this value; we keep track of<br>
+ * it a software counter. So just reset the counter.<br>
+ */<br>
+ brw->sol.primitives_generated = 0;<br>
+ brw->sol.counting_primitives_generated = true;<br>
+ break;<br>
+<br>
+ case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN:<br>
+ /* We don't actually query the hardware for this value; we keep track of<br>
+ * it a software counter. So just reset the counter.<br>
+ */<br>
+ brw->sol.primitives_written = 0;<br>
+ brw->sol.counting_primitives_written = true;<br>
+ break;<br>
+<br>
+ default:<br>
+ assert(!"Unrecognized query target in brw_begin_query()");<br>
+ break;<br>
+ }<br>
+}<br>
+<br>
+/**<br>
+ * Driver hook for glEndQuery().<br>
+ *<br>
+ * Emits GPU commands to record a final query value, ending any data capturing.<br>
+ * However, the final result isn't necessarily available until the GPU processes<br>
+ * those commands. brw_queryobj_get_results() processes the captured data to<br>
+ * produce the final result.<br>
+ */<br>
+static void<br>
+gen6_end_query(struct gl_context *ctx, struct gl_query_object *q)<br>
+{<br>
+ struct brw_context *brw = brw_context(ctx);<br>
+ struct intel_context *intel = intel_context(ctx);<br>
+ struct brw_query_object *query = (struct brw_query_object *)q;<br>
+<br>
+ switch (query->Base.Target) {<br>
+ case GL_TIME_ELAPSED:<br>
+ write_timestamp(intel, query->bo, 1);<br>
+ break;<br>
+<br>
+ case GL_ANY_SAMPLES_PASSED:<br>
+ case GL_ANY_SAMPLES_PASSED_CONSERVATIVE:<br>
+ case GL_SAMPLES_PASSED_ARB:<br>
+ write_depth_count(intel, query->bo, 1);<br>
+ break;<br>
+<br>
+ case GL_PRIMITIVES_GENERATED:<br>
+ /* We don't actually query the hardware for this value; we keep track of<br>
+ * it in a software counter. So just read the counter and store it in<br>
+ * the query object.<br>
+ */<br>
+ query->Base.Result = brw->sol.primitives_generated;<br>
+ brw->sol.counting_primitives_generated = false;<br>
+ break;<br>
+<br>
+ case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN:<br>
+ /* We don't actually query the hardware for this value; we keep track of<br>
+ * it in a software counter. So just read the counter and store it in<br>
+ * the query object.<br>
+ */<br>
+ query->Base.Result = brw->sol.primitives_written;<br>
+ brw->sol.counting_primitives_written = false;<br>
+ break;<br>
+<br>
+ default:<br>
+ assert(!"Unrecognized query target in brw_end_query()");<br>
+ break;<br>
+ }<br>
+}<br>
+<br>
+/**<br>
+ * The WaitQuery() driver hook.<br>
+ *<br>
+ * Wait for a query result to become available and return it. This is the<br>
+ * backing for glGetQueryObjectiv() with the GL_QUERY_RESULT pname.<br>
+ */<br>
+static void gen6_wait_query(struct gl_context *ctx, struct gl_query_object *q)<br>
+{<br>
+ struct brw_query_object *query = (struct brw_query_object *)q;<br>
+<br>
+ gen6_queryobj_get_results(ctx, query);<br>
+ query->Base.Ready = true;<br>
+}<br>
+<br>
+/**<br>
+ * The CheckQuery() driver hook.<br>
+ *<br>
+ * Checks whether a query result is ready yet. If not, flushes.<br>
+ * This is the backing for glGetQueryObjectiv()'s QUERY_RESULT_AVAILABLE pname.<br>
+ */<br>
+static void gen6_check_query(struct gl_context *ctx, struct gl_query_object *q)<br>
+{<br>
+ struct intel_context *intel = intel_context(ctx);<br>
+ struct brw_query_object *query = (struct brw_query_object *)q;<br>
+<br>
+ /* From the GL_ARB_occlusion_query spec:<br>
+ *<br>
+ * "Instead of allowing for an infinite loop, performing a<br>
+ * QUERY_RESULT_AVAILABLE_ARB will perform a flush if the result is<br>
+ * not ready yet on the first time it is queried. This ensures that<br>
+ * the async query will return true in finite time.<br>
+ */<br>
+ if (query->bo && drm_intel_bo_references(intel-><a href="http://batch.bo" target="_blank">batch.bo</a>, query->bo))<br>
+ intel_batchbuffer_flush(intel);<br>
+<br>
+ if (query->bo == NULL || !drm_intel_bo_busy(query->bo)) {<br>
+ gen6_queryobj_get_results(ctx, query);<br>
+ query->Base.Ready = true;<br>
+ }<br>
+}<br>
+<br>
+void gen6_reinit_queryobj_functions(struct dd_function_table *functions)<br>
+{<br>
+ functions->BeginQuery = gen6_begin_query;<br>
+ functions->EndQuery = gen6_end_query;<br>
+ functions->CheckQuery = gen6_check_query;<br>
+ functions->WaitQuery = gen6_wait_query;<br>
+}<br>
<span class=""><font color="#888888">--<br>
1.8.2.3<br>
<br>
</font></span></blockquote></div><br></div></div>