i965: Reduce passing 2x32b of reloc_domains to 2 bits
[mesa.git] / src / mesa / drivers / dri / i965 / gen7_sol_state.c
1 /*
2 * Copyright © 2011 Intel Corporation
3 *
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:
10 *
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
13 * Software.
14 *
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
21 * IN THE SOFTWARE.
22 */
23
24 /**
25 * @file gen7_sol_state.c
26 *
27 * Controls the stream output logic (SOL) stage of the gen7 hardware, which is
28 * used to implement GL_EXT_transform_feedback.
29 */
30
31 #include "brw_context.h"
32 #include "brw_state.h"
33 #include "brw_defines.h"
34 #include "intel_batchbuffer.h"
35 #include "intel_buffer_objects.h"
36 #include "main/transformfeedback.h"
37
38 void
39 gen7_begin_transform_feedback(struct gl_context *ctx, GLenum mode,
40 struct gl_transform_feedback_object *obj)
41 {
42 struct brw_context *brw = brw_context(ctx);
43 struct brw_transform_feedback_object *brw_obj =
44 (struct brw_transform_feedback_object *) obj;
45
46 assert(brw->gen == 7);
47
48 /* We're about to lose the information needed to compute the number of
49 * vertices written during the last Begin/EndTransformFeedback section,
50 * so we can't delay it any further.
51 */
52 brw_compute_xfb_vertices_written(brw, brw_obj);
53
54 /* No primitives have been generated yet. */
55 for (int i = 0; i < BRW_MAX_XFB_STREAMS; i++) {
56 brw_obj->prims_generated[i] = 0;
57 }
58
59 /* Store the starting value of the SO_NUM_PRIMS_WRITTEN counters. */
60 brw_save_primitives_written_counters(brw, brw_obj);
61
62 /* Reset the SO buffer offsets to 0. */
63 if (!can_do_pipelined_register_writes(brw->screen)) {
64 intel_batchbuffer_flush(brw);
65 brw->batch.needs_sol_reset = true;
66 } else {
67 for (int i = 0; i < 4; i++) {
68 BEGIN_BATCH(3);
69 OUT_BATCH(MI_LOAD_REGISTER_IMM | (3 - 2));
70 OUT_BATCH(GEN7_SO_WRITE_OFFSET(i));
71 OUT_BATCH(0);
72 ADVANCE_BATCH();
73 }
74 }
75
76 brw_obj->primitive_mode = mode;
77 }
78
79 void
80 gen7_end_transform_feedback(struct gl_context *ctx,
81 struct gl_transform_feedback_object *obj)
82 {
83 /* After EndTransformFeedback, it's likely that the client program will try
84 * to draw using the contents of the transform feedback buffer as vertex
85 * input. In order for this to work, we need to flush the data through at
86 * least the GS stage of the pipeline, and flush out the render cache. For
87 * simplicity, just do a full flush.
88 */
89 struct brw_context *brw = brw_context(ctx);
90 struct brw_transform_feedback_object *brw_obj =
91 (struct brw_transform_feedback_object *) obj;
92
93 /* Store the ending value of the SO_NUM_PRIMS_WRITTEN counters. */
94 if (!obj->Paused)
95 brw_save_primitives_written_counters(brw, brw_obj);
96
97 /* EndTransformFeedback() means that we need to update the number of
98 * vertices written. Since it's only necessary if DrawTransformFeedback()
99 * is called and it means mapping a buffer object, we delay computing it
100 * until it's absolutely necessary to try and avoid stalls.
101 */
102 brw_obj->vertices_written_valid = false;
103 }
104
105 void
106 gen7_pause_transform_feedback(struct gl_context *ctx,
107 struct gl_transform_feedback_object *obj)
108 {
109 struct brw_context *brw = brw_context(ctx);
110 struct brw_transform_feedback_object *brw_obj =
111 (struct brw_transform_feedback_object *) obj;
112
113 /* Flush any drawing so that the counters have the right values. */
114 brw_emit_mi_flush(brw);
115
116 assert(brw->gen == 7);
117
118 /* Save the SOL buffer offset register values. */
119 for (int i = 0; i < 4; i++) {
120 BEGIN_BATCH(3);
121 OUT_BATCH(MI_STORE_REGISTER_MEM | (3 - 2));
122 OUT_BATCH(GEN7_SO_WRITE_OFFSET(i));
123 OUT_RELOC(brw_obj->offset_bo, RELOC_WRITE, i * sizeof(uint32_t));
124 ADVANCE_BATCH();
125 }
126
127 /* Store the temporary ending value of the SO_NUM_PRIMS_WRITTEN counters.
128 * While this operation is paused, other transform feedback actions may
129 * occur, which will contribute to the counters. We need to exclude that
130 * from our counts.
131 */
132 brw_save_primitives_written_counters(brw, brw_obj);
133 }
134
135 void
136 gen7_resume_transform_feedback(struct gl_context *ctx,
137 struct gl_transform_feedback_object *obj)
138 {
139 struct brw_context *brw = brw_context(ctx);
140 struct brw_transform_feedback_object *brw_obj =
141 (struct brw_transform_feedback_object *) obj;
142
143 assert(brw->gen == 7);
144
145 /* Reload the SOL buffer offset registers. */
146 for (int i = 0; i < 4; i++) {
147 BEGIN_BATCH(3);
148 OUT_BATCH(GEN7_MI_LOAD_REGISTER_MEM | (3 - 2));
149 OUT_BATCH(GEN7_SO_WRITE_OFFSET(i));
150 OUT_RELOC(brw_obj->offset_bo, RELOC_WRITE, i * sizeof(uint32_t));
151 ADVANCE_BATCH();
152 }
153
154 /* Store the new starting value of the SO_NUM_PRIMS_WRITTEN counters. */
155 brw_save_primitives_written_counters(brw, brw_obj);
156 }