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
26 * Code to initialize the binding table entries used by transform feedback.
29 #include "main/macros.h"
30 #include "brw_context.h"
31 #include "intel_batchbuffer.h"
32 #include "brw_defines.h"
33 #include "brw_state.h"
34 #include "main/transformfeedback.h"
37 gen6_update_sol_surfaces(struct brw_context
*brw
)
39 struct gl_context
*ctx
= &brw
->intel
.ctx
;
40 /* _NEW_TRANSFORM_FEEDBACK */
41 struct gl_transform_feedback_object
*xfb_obj
=
42 ctx
->TransformFeedback
.CurrentObject
;
43 /* BRW_NEW_VERTEX_PROGRAM */
44 const struct gl_shader_program
*shaderprog
=
45 ctx
->Shader
.CurrentVertexProgram
;
46 const struct gl_transform_feedback_info
*linked_xfb_info
=
47 &shaderprog
->LinkedTransformFeedback
;
50 for (i
= 0; i
< BRW_MAX_SOL_BINDINGS
; ++i
) {
51 const int surf_index
= SURF_INDEX_SOL_BINDING(i
);
52 if (_mesa_is_xfb_active_and_unpaused(ctx
) &&
53 i
< linked_xfb_info
->NumOutputs
) {
54 unsigned buffer
= linked_xfb_info
->Outputs
[i
].OutputBuffer
;
55 unsigned buffer_offset
=
56 xfb_obj
->Offset
[buffer
] / 4 +
57 linked_xfb_info
->Outputs
[i
].DstOffset
;
58 brw_update_sol_surface(
59 brw
, xfb_obj
->Buffers
[buffer
], &brw
->gs
.surf_offset
[surf_index
],
60 linked_xfb_info
->Outputs
[i
].NumComponents
,
61 linked_xfb_info
->BufferStride
[buffer
], buffer_offset
);
63 brw
->gs
.surf_offset
[surf_index
] = 0;
67 brw
->state
.dirty
.brw
|= BRW_NEW_SURFACES
;
70 const struct brw_tracked_state gen6_sol_surface
= {
72 .mesa
= _NEW_TRANSFORM_FEEDBACK
,
73 .brw
= (BRW_NEW_BATCH
|
74 BRW_NEW_VERTEX_PROGRAM
),
77 .emit
= gen6_update_sol_surfaces
,
81 * Constructs the binding table for the WM surface state, which maps unit
82 * numbers to surface state objects.
85 brw_gs_upload_binding_table(struct brw_context
*brw
)
87 struct gl_context
*ctx
= &brw
->intel
.ctx
;
88 /* BRW_NEW_VERTEX_PROGRAM */
89 const struct gl_shader_program
*shaderprog
=
90 ctx
->Shader
.CurrentVertexProgram
;
91 bool has_surfaces
= false;
95 const struct gl_transform_feedback_info
*linked_xfb_info
=
96 &shaderprog
->LinkedTransformFeedback
;
97 /* Currently we only ever upload surfaces for SOL. */
98 has_surfaces
= linked_xfb_info
->NumOutputs
!= 0;
101 /* Skip making a binding table if we don't have anything to put in it. */
103 if (brw
->gs
.bind_bo_offset
!= 0) {
104 brw
->state
.dirty
.brw
|= BRW_NEW_GS_BINDING_TABLE
;
105 brw
->gs
.bind_bo_offset
= 0;
110 /* Might want to calculate nr_surfaces first, to avoid taking up so much
111 * space for the binding table.
113 bind
= brw_state_batch(brw
, AUB_TRACE_BINDING_TABLE
,
114 sizeof(uint32_t) * BRW_MAX_GS_SURFACES
,
115 32, &brw
->gs
.bind_bo_offset
);
117 /* BRW_NEW_SURFACES */
118 memcpy(bind
, brw
->gs
.surf_offset
, BRW_MAX_GS_SURFACES
* sizeof(uint32_t));
120 brw
->state
.dirty
.brw
|= BRW_NEW_GS_BINDING_TABLE
;
123 const struct brw_tracked_state gen6_gs_binding_table
= {
126 .brw
= (BRW_NEW_BATCH
|
127 BRW_NEW_VERTEX_PROGRAM
|
131 .emit
= brw_gs_upload_binding_table
,
135 gen6_update_sol_indices(struct brw_context
*brw
)
137 struct intel_context
*intel
= &brw
->intel
;
140 OUT_BATCH(_3DSTATE_GS_SVB_INDEX
<< 16 | (4 - 2));
142 OUT_BATCH(brw
->sol
.svbi_0_starting_index
); /* BRW_NEW_SOL_INDICES */
143 OUT_BATCH(brw
->sol
.svbi_0_max_index
); /* BRW_NEW_SOL_INDICES */
147 const struct brw_tracked_state gen6_sol_indices
= {
150 .brw
= (BRW_NEW_BATCH
|
151 BRW_NEW_SOL_INDICES
),
154 .emit
= gen6_update_sol_indices
,
158 brw_begin_transform_feedback(struct gl_context
*ctx
, GLenum mode
,
159 struct gl_transform_feedback_object
*obj
)
161 struct brw_context
*brw
= brw_context(ctx
);
162 struct intel_context
*intel
= &brw
->intel
;
163 const struct gl_shader_program
*vs_prog
=
164 ctx
->Shader
.CurrentVertexProgram
;
165 const struct gl_transform_feedback_info
*linked_xfb_info
=
166 &vs_prog
->LinkedTransformFeedback
;
167 struct gl_transform_feedback_object
*xfb_obj
=
168 ctx
->TransformFeedback
.CurrentObject
;
170 /* Compute the maximum number of vertices that we can write without
171 * overflowing any of the buffers currently being used for feedback.
174 = _mesa_compute_max_transform_feedback_vertices(xfb_obj
,
177 /* Initialize the SVBI 0 register to zero and set the maximum index.
178 * These values will be sent to the hardware on the next draw.
180 brw
->state
.dirty
.brw
|= BRW_NEW_SOL_INDICES
;
181 brw
->sol
.svbi_0_starting_index
= 0;
182 brw
->sol
.svbi_0_max_index
= max_index
;
183 brw
->sol
.offset_0_batch_start
= 0;
185 if (intel
->gen
>= 7) {
186 /* Ask the kernel to reset the SO offsets for any previous transform
187 * feedback, so we start at the start of the user's buffer. (note: these
188 * are not the query counters)
190 intel
->batch
.needs_sol_reset
= true;
195 brw_end_transform_feedback(struct gl_context
*ctx
,
196 struct gl_transform_feedback_object
*obj
)
198 /* After EndTransformFeedback, it's likely that the client program will try
199 * to draw using the contents of the transform feedback buffer as vertex
200 * input. In order for this to work, we need to flush the data through at
201 * least the GS stage of the pipeline, and flush out the render cache. For
202 * simplicity, just do a full flush.
204 struct brw_context
*brw
= brw_context(ctx
);
205 struct intel_context
*intel
= &brw
->intel
;
206 intel_batchbuffer_emit_mi_flush(intel
);