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/bufferobj.h"
30 #include "main/macros.h"
31 #include "brw_context.h"
32 #include "intel_batchbuffer.h"
33 #include "brw_defines.h"
34 #include "brw_state.h"
35 #include "main/transformfeedback.h"
38 gen6_update_sol_surfaces(struct brw_context
*brw
)
40 struct gl_context
*ctx
= &brw
->ctx
;
41 /* BRW_NEW_TRANSFORM_FEEDBACK */
42 struct gl_transform_feedback_object
*xfb_obj
=
43 ctx
->TransformFeedback
.CurrentObject
;
44 /* BRW_NEW_VERTEX_PROGRAM */
45 const struct gl_shader_program
*shaderprog
=
46 ctx
->Shader
.CurrentVertexProgram
;
47 const struct gl_transform_feedback_info
*linked_xfb_info
=
48 &shaderprog
->LinkedTransformFeedback
;
51 for (i
= 0; i
< BRW_MAX_SOL_BINDINGS
; ++i
) {
52 const int surf_index
= SURF_INDEX_GEN6_SOL_BINDING(i
);
53 if (_mesa_is_xfb_active_and_unpaused(ctx
) &&
54 i
< linked_xfb_info
->NumOutputs
) {
55 unsigned buffer
= linked_xfb_info
->Outputs
[i
].OutputBuffer
;
56 unsigned buffer_offset
=
57 xfb_obj
->Offset
[buffer
] / 4 +
58 linked_xfb_info
->Outputs
[i
].DstOffset
;
59 brw_update_sol_surface(
60 brw
, xfb_obj
->Buffers
[buffer
], &brw
->ff_gs
.surf_offset
[surf_index
],
61 linked_xfb_info
->Outputs
[i
].NumComponents
,
62 linked_xfb_info
->BufferStride
[buffer
], buffer_offset
);
64 brw
->ff_gs
.surf_offset
[surf_index
] = 0;
68 brw
->state
.dirty
.brw
|= BRW_NEW_SURFACES
;
71 const struct brw_tracked_state gen6_sol_surface
= {
74 .brw
= (BRW_NEW_BATCH
|
75 BRW_NEW_VERTEX_PROGRAM
|
76 BRW_NEW_TRANSFORM_FEEDBACK
),
79 .emit
= gen6_update_sol_surfaces
,
83 * Constructs the binding table for the WM surface state, which maps unit
84 * numbers to surface state objects.
87 brw_gs_upload_binding_table(struct brw_context
*brw
)
89 struct gl_context
*ctx
= &brw
->ctx
;
90 /* BRW_NEW_VERTEX_PROGRAM */
91 const struct gl_shader_program
*shaderprog
=
92 ctx
->Shader
.CurrentVertexProgram
;
93 bool has_surfaces
= false;
97 const struct gl_transform_feedback_info
*linked_xfb_info
=
98 &shaderprog
->LinkedTransformFeedback
;
99 /* Currently we only ever upload surfaces for SOL. */
100 has_surfaces
= linked_xfb_info
->NumOutputs
!= 0;
103 /* Skip making a binding table if we don't have anything to put in it. */
105 if (brw
->ff_gs
.bind_bo_offset
!= 0) {
106 brw
->state
.dirty
.brw
|= BRW_NEW_GS_BINDING_TABLE
;
107 brw
->ff_gs
.bind_bo_offset
= 0;
112 /* Might want to calculate nr_surfaces first, to avoid taking up so much
113 * space for the binding table.
115 bind
= brw_state_batch(brw
, AUB_TRACE_BINDING_TABLE
,
116 sizeof(uint32_t) * BRW_MAX_GEN6_GS_SURFACES
,
117 32, &brw
->ff_gs
.bind_bo_offset
);
119 /* BRW_NEW_SURFACES */
120 memcpy(bind
, brw
->ff_gs
.surf_offset
, BRW_MAX_GEN6_GS_SURFACES
* sizeof(uint32_t));
122 brw
->state
.dirty
.brw
|= BRW_NEW_GS_BINDING_TABLE
;
125 const struct brw_tracked_state gen6_gs_binding_table
= {
128 .brw
= (BRW_NEW_BATCH
|
129 BRW_NEW_VERTEX_PROGRAM
|
133 .emit
= brw_gs_upload_binding_table
,
136 struct gl_transform_feedback_object
*
137 brw_new_transform_feedback(struct gl_context
*ctx
, GLuint name
)
139 struct brw_context
*brw
= brw_context(ctx
);
140 struct brw_transform_feedback_object
*brw_obj
=
141 CALLOC_STRUCT(brw_transform_feedback_object
);
145 _mesa_init_transform_feedback_object(&brw_obj
->base
, name
);
147 return &brw_obj
->base
;
151 brw_delete_transform_feedback(struct gl_context
*ctx
,
152 struct gl_transform_feedback_object
*obj
)
154 struct brw_transform_feedback_object
*brw_obj
=
155 (struct brw_transform_feedback_object
*) obj
;
157 for (unsigned i
= 0; i
< Elements(obj
->Buffers
); i
++) {
158 _mesa_reference_buffer_object(ctx
, &obj
->Buffers
[i
], NULL
);
165 brw_begin_transform_feedback(struct gl_context
*ctx
, GLenum mode
,
166 struct gl_transform_feedback_object
*obj
)
168 struct brw_context
*brw
= brw_context(ctx
);
169 const struct gl_shader_program
*vs_prog
=
170 ctx
->Shader
.CurrentVertexProgram
;
171 const struct gl_transform_feedback_info
*linked_xfb_info
=
172 &vs_prog
->LinkedTransformFeedback
;
173 struct gl_transform_feedback_object
*xfb_obj
=
174 ctx
->TransformFeedback
.CurrentObject
;
176 assert(brw
->gen
== 6);
178 /* Compute the maximum number of vertices that we can write without
179 * overflowing any of the buffers currently being used for feedback.
182 = _mesa_compute_max_transform_feedback_vertices(xfb_obj
,
185 /* 3DSTATE_GS_SVB_INDEX is non-pipelined. */
186 intel_emit_post_sync_nonzero_flush(brw
);
188 /* Initialize the SVBI 0 register to zero and set the maximum index. */
190 OUT_BATCH(_3DSTATE_GS_SVB_INDEX
<< 16 | (4 - 2));
191 OUT_BATCH(0); /* SVBI 0 */
192 OUT_BATCH(0); /* starting index */
193 OUT_BATCH(max_index
);
196 /* Initialize the rest of the unused streams to sane values. Otherwise,
197 * they may indicate that there is no room to write data and prevent
198 * anything from happening at all.
200 for (int i
= 1; i
< 4; i
++) {
202 OUT_BATCH(_3DSTATE_GS_SVB_INDEX
<< 16 | (4 - 2));
203 OUT_BATCH(i
<< SVB_INDEX_SHIFT
);
204 OUT_BATCH(0); /* starting index */
205 OUT_BATCH(0xffffffff);
211 brw_end_transform_feedback(struct gl_context
*ctx
,
212 struct gl_transform_feedback_object
*obj
)
214 /* After EndTransformFeedback, it's likely that the client program will try
215 * to draw using the contents of the transform feedback buffer as vertex
216 * input. In order for this to work, we need to flush the data through at
217 * least the GS stage of the pipeline, and flush out the render cache. For
218 * simplicity, just do a full flush.
220 struct brw_context
*brw
= brw_context(ctx
);
221 intel_batchbuffer_emit_mi_flush(brw
);