2 * Copyright © 2014 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 * Neil Roberts <neil@linux.intel.com>
27 /** @file brw_conditional_render.c
29 * Support for conditional rendering based on query objects
30 * (GL_NV_conditional_render, GL_ARB_conditional_render_inverted) on Gen7+.
33 #include "main/imports.h"
34 #include "main/condrender.h"
36 #include "brw_context.h"
37 #include "brw_defines.h"
38 #include "intel_batchbuffer.h"
41 set_predicate_enable(struct brw_context
*brw
,
45 brw
->predicate
.state
= BRW_PREDICATE_STATE_RENDER
;
47 brw
->predicate
.state
= BRW_PREDICATE_STATE_DONT_RENDER
;
51 set_predicate_for_overflow_query(struct brw_context
*brw
,
52 struct brw_query_object
*query
,
53 int stream_start
, int count
)
55 hsw_overflow_result_to_gpr0(brw
, query
, count
);
56 brw_load_register_reg64(brw
, HSW_CS_GPR(0), MI_PREDICATE_SRC0
);
57 brw_load_register_imm64(brw
, MI_PREDICATE_SRC1
, 0ull);
61 set_predicate_for_occlusion_query(struct brw_context
*brw
,
62 struct brw_query_object
*query
)
64 brw_load_register_mem64(brw
,
67 I915_GEM_DOMAIN_INSTRUCTION
,
70 brw_load_register_mem64(brw
,
73 I915_GEM_DOMAIN_INSTRUCTION
,
79 set_predicate_for_result(struct brw_context
*brw
,
80 struct brw_query_object
*query
,
86 assert(query
->bo
!= NULL
);
88 /* Needed to ensure the memory is coherent for the MI_LOAD_REGISTER_MEM
89 * command when loading the values into the predicate source registers for
90 * conditional rendering.
92 brw_emit_pipe_control_flush(brw
, PIPE_CONTROL_FLUSH_ENABLE
);
94 switch (query
->Base
.Target
) {
95 case GL_TRANSFORM_FEEDBACK_STREAM_OVERFLOW_ARB
:
96 set_predicate_for_overflow_query(brw
, query
, 0, 1);
98 case GL_TRANSFORM_FEEDBACK_OVERFLOW_ARB
:
99 set_predicate_for_overflow_query(brw
, query
, 0, MAX_VERTEX_STREAMS
);
102 set_predicate_for_occlusion_query(brw
, query
);
106 load_op
= MI_PREDICATE_LOADOP_LOAD
;
108 load_op
= MI_PREDICATE_LOADOP_LOADINV
;
111 OUT_BATCH(GEN7_MI_PREDICATE
|
113 MI_PREDICATE_COMBINEOP_SET
|
114 MI_PREDICATE_COMPAREOP_SRCS_EQUAL
);
117 brw
->predicate
.state
= BRW_PREDICATE_STATE_USE_BIT
;
121 brw_begin_conditional_render(struct gl_context
*ctx
,
122 struct gl_query_object
*q
,
125 struct brw_context
*brw
= brw_context(ctx
);
126 struct brw_query_object
*query
= (struct brw_query_object
*) q
;
129 if (!brw
->predicate
.supported
)
132 if ((query
->Base
.Target
== GL_TRANSFORM_FEEDBACK_OVERFLOW_ARB
||
133 query
->Base
.Target
== GL_TRANSFORM_FEEDBACK_STREAM_OVERFLOW_ARB
) &&
134 !can_do_mi_math_and_lrr(brw
->screen
))
139 case GL_QUERY_NO_WAIT
:
140 case GL_QUERY_BY_REGION_WAIT
:
141 case GL_QUERY_BY_REGION_NO_WAIT
:
144 case GL_QUERY_WAIT_INVERTED
:
145 case GL_QUERY_NO_WAIT_INVERTED
:
146 case GL_QUERY_BY_REGION_WAIT_INVERTED
:
147 case GL_QUERY_BY_REGION_NO_WAIT_INVERTED
:
151 unreachable("Unexpected conditional render mode");
154 /* If there are already samples from a BLT operation or if the query object
155 * is ready then we can avoid looking at the values in the buffer and just
156 * decide whether to draw using the CPU without stalling.
158 if (query
->Base
.Result
|| query
->Base
.Ready
)
159 set_predicate_enable(brw
, (query
->Base
.Result
!= 0) ^ inverted
);
161 set_predicate_for_result(brw
, query
, inverted
);
165 brw_end_conditional_render(struct gl_context
*ctx
,
166 struct gl_query_object
*q
)
168 struct brw_context
*brw
= brw_context(ctx
);
170 /* When there is no longer a conditional render in progress it should
173 brw
->predicate
.state
= BRW_PREDICATE_STATE_RENDER
;
177 brw_init_conditional_render_functions(struct dd_function_table
*functions
)
179 functions
->BeginConditionalRender
= brw_begin_conditional_render
;
180 functions
->EndConditionalRender
= brw_end_conditional_render
;
184 brw_check_conditional_render(struct brw_context
*brw
)
186 const struct gl_query_object
*query
= brw
->ctx
.Query
.CondRenderQuery
;
188 const bool query_is_xfb
= query
&&
189 (query
->Target
== GL_TRANSFORM_FEEDBACK_OVERFLOW_ARB
||
190 query
->Target
== GL_TRANSFORM_FEEDBACK_STREAM_OVERFLOW_ARB
);
192 if (brw
->predicate
.supported
&&
193 (can_do_mi_math_and_lrr(brw
->screen
) || !query_is_xfb
)) {
194 /* In some cases it is possible to determine that the primitives should
195 * be skipped without needing the predicate enable bit and still without
198 return brw
->predicate
.state
!= BRW_PREDICATE_STATE_DONT_RENDER
;
200 perf_debug("Conditional rendering is implemented in software and may "
202 return _mesa_check_conditional_render(&brw
->ctx
);