2 * Copyright © 2011 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
25 * @file gen7_sol_state.c
27 * Controls the stream output logic (SOL) stage of the gen7 hardware, which is
28 * used to implement GL_EXT_transform_feedback.
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"
39 gen7_begin_transform_feedback(struct gl_context
*ctx
, GLenum mode
,
40 struct gl_transform_feedback_object
*obj
)
42 struct brw_context
*brw
= brw_context(ctx
);
43 struct brw_transform_feedback_object
*brw_obj
=
44 (struct brw_transform_feedback_object
*) obj
;
45 const struct gen_device_info
*devinfo
= &brw
->screen
->devinfo
;
47 assert(devinfo
->gen
== 7);
49 /* We're about to lose the information needed to compute the number of
50 * vertices written during the last Begin/EndTransformFeedback section,
51 * so we can't delay it any further.
53 brw_compute_xfb_vertices_written(brw
, brw_obj
);
55 /* No primitives have been generated yet. */
56 for (int i
= 0; i
< BRW_MAX_XFB_STREAMS
; i
++) {
57 brw_obj
->prims_generated
[i
] = 0;
60 /* Store the starting value of the SO_NUM_PRIMS_WRITTEN counters. */
61 brw_save_primitives_written_counters(brw
, brw_obj
);
63 /* Reset the SO buffer offsets to 0. */
64 if (!can_do_pipelined_register_writes(brw
->screen
)) {
65 intel_batchbuffer_flush(brw
);
66 brw
->batch
.needs_sol_reset
= true;
68 for (int i
= 0; i
< 4; i
++) {
70 OUT_BATCH(MI_LOAD_REGISTER_IMM
| (3 - 2));
71 OUT_BATCH(GEN7_SO_WRITE_OFFSET(i
));
77 brw_obj
->primitive_mode
= mode
;
81 gen7_end_transform_feedback(struct gl_context
*ctx
,
82 struct gl_transform_feedback_object
*obj
)
84 /* After EndTransformFeedback, it's likely that the client program will try
85 * to draw using the contents of the transform feedback buffer as vertex
86 * input. In order for this to work, we need to flush the data through at
87 * least the GS stage of the pipeline, and flush out the render cache. For
88 * simplicity, just do a full flush.
90 struct brw_context
*brw
= brw_context(ctx
);
91 struct brw_transform_feedback_object
*brw_obj
=
92 (struct brw_transform_feedback_object
*) obj
;
94 /* Store the ending value of the SO_NUM_PRIMS_WRITTEN counters. */
96 brw_save_primitives_written_counters(brw
, brw_obj
);
98 /* EndTransformFeedback() means that we need to update the number of
99 * vertices written. Since it's only necessary if DrawTransformFeedback()
100 * is called and it means mapping a buffer object, we delay computing it
101 * until it's absolutely necessary to try and avoid stalls.
103 brw_obj
->vertices_written_valid
= false;
107 gen7_pause_transform_feedback(struct gl_context
*ctx
,
108 struct gl_transform_feedback_object
*obj
)
110 struct brw_context
*brw
= brw_context(ctx
);
111 struct brw_transform_feedback_object
*brw_obj
=
112 (struct brw_transform_feedback_object
*) obj
;
113 const struct gen_device_info
*devinfo
= &brw
->screen
->devinfo
;
115 /* Flush any drawing so that the counters have the right values. */
116 brw_emit_mi_flush(brw
);
118 assert(devinfo
->gen
== 7);
120 /* Save the SOL buffer offset register values. */
121 for (int i
= 0; i
< 4; i
++) {
123 OUT_BATCH(MI_STORE_REGISTER_MEM
| (3 - 2));
124 OUT_BATCH(GEN7_SO_WRITE_OFFSET(i
));
125 OUT_RELOC(brw_obj
->offset_bo
, RELOC_WRITE
, i
* sizeof(uint32_t));
129 /* Store the temporary ending value of the SO_NUM_PRIMS_WRITTEN counters.
130 * While this operation is paused, other transform feedback actions may
131 * occur, which will contribute to the counters. We need to exclude that
134 brw_save_primitives_written_counters(brw
, brw_obj
);
138 gen7_resume_transform_feedback(struct gl_context
*ctx
,
139 struct gl_transform_feedback_object
*obj
)
141 struct brw_context
*brw
= brw_context(ctx
);
142 struct brw_transform_feedback_object
*brw_obj
=
143 (struct brw_transform_feedback_object
*) obj
;
144 const struct gen_device_info
*devinfo
= &brw
->screen
->devinfo
;
146 assert(devinfo
->gen
== 7);
148 /* Reload the SOL buffer offset registers. */
149 for (int i
= 0; i
< 4; i
++) {
151 OUT_BATCH(GEN7_MI_LOAD_REGISTER_MEM
| (3 - 2));
152 OUT_BATCH(GEN7_SO_WRITE_OFFSET(i
));
153 OUT_RELOC(brw_obj
->offset_bo
, RELOC_WRITE
, i
* sizeof(uint32_t));
157 /* Store the new starting value of the SO_NUM_PRIMS_WRITTEN counters. */
158 brw_save_primitives_written_counters(brw
, brw_obj
);