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
->ctx
;
40 /* BRW_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
->ff_gs
.surf_offset
[surf_index
],
60 linked_xfb_info
->Outputs
[i
].NumComponents
,
61 linked_xfb_info
->BufferStride
[buffer
], buffer_offset
);
63 brw
->ff_gs
.surf_offset
[surf_index
] = 0;
67 brw
->state
.dirty
.brw
|= BRW_NEW_SURFACES
;
70 const struct brw_tracked_state gen6_sol_surface
= {
73 .brw
= (BRW_NEW_BATCH
|
74 BRW_NEW_VERTEX_PROGRAM
|
75 BRW_NEW_TRANSFORM_FEEDBACK
),
78 .emit
= gen6_update_sol_surfaces
,
82 * Constructs the binding table for the WM surface state, which maps unit
83 * numbers to surface state objects.
86 brw_gs_upload_binding_table(struct brw_context
*brw
)
88 struct gl_context
*ctx
= &brw
->ctx
;
89 /* BRW_NEW_VERTEX_PROGRAM */
90 const struct gl_shader_program
*shaderprog
=
91 ctx
->Shader
.CurrentVertexProgram
;
92 bool has_surfaces
= false;
96 const struct gl_transform_feedback_info
*linked_xfb_info
=
97 &shaderprog
->LinkedTransformFeedback
;
98 /* Currently we only ever upload surfaces for SOL. */
99 has_surfaces
= linked_xfb_info
->NumOutputs
!= 0;
102 /* Skip making a binding table if we don't have anything to put in it. */
104 if (brw
->ff_gs
.bind_bo_offset
!= 0) {
105 brw
->state
.dirty
.brw
|= BRW_NEW_GS_BINDING_TABLE
;
106 brw
->ff_gs
.bind_bo_offset
= 0;
111 /* Might want to calculate nr_surfaces first, to avoid taking up so much
112 * space for the binding table.
114 bind
= brw_state_batch(brw
, AUB_TRACE_BINDING_TABLE
,
115 sizeof(uint32_t) * BRW_MAX_GS_SURFACES
,
116 32, &brw
->ff_gs
.bind_bo_offset
);
118 /* BRW_NEW_SURFACES */
119 memcpy(bind
, brw
->ff_gs
.surf_offset
, BRW_MAX_GS_SURFACES
* sizeof(uint32_t));
121 brw
->state
.dirty
.brw
|= BRW_NEW_GS_BINDING_TABLE
;
124 const struct brw_tracked_state gen6_gs_binding_table
= {
127 .brw
= (BRW_NEW_BATCH
|
128 BRW_NEW_VERTEX_PROGRAM
|
132 .emit
= brw_gs_upload_binding_table
,
136 brw_begin_transform_feedback(struct gl_context
*ctx
, GLenum mode
,
137 struct gl_transform_feedback_object
*obj
)
139 struct brw_context
*brw
= brw_context(ctx
);
140 const struct gl_shader_program
*vs_prog
=
141 ctx
->Shader
.CurrentVertexProgram
;
142 const struct gl_transform_feedback_info
*linked_xfb_info
=
143 &vs_prog
->LinkedTransformFeedback
;
144 struct gl_transform_feedback_object
*xfb_obj
=
145 ctx
->TransformFeedback
.CurrentObject
;
147 assert(brw
->gen
== 6);
149 /* Compute the maximum number of vertices that we can write without
150 * overflowing any of the buffers currently being used for feedback.
153 = _mesa_compute_max_transform_feedback_vertices(xfb_obj
,
156 /* Initialize the SVBI 0 register to zero and set the maximum index. */
158 OUT_BATCH(_3DSTATE_GS_SVB_INDEX
<< 16 | (4 - 2));
159 OUT_BATCH(0); /* SVBI 0 */
160 OUT_BATCH(0); /* starting index */
161 OUT_BATCH(max_index
);
164 /* Initialize the rest of the unused streams to sane values. Otherwise,
165 * they may indicate that there is no room to write data and prevent
166 * anything from happening at all.
168 for (int i
= 1; i
< 4; i
++) {
170 OUT_BATCH(_3DSTATE_GS_SVB_INDEX
<< 16 | (4 - 2));
171 OUT_BATCH(i
<< SVB_INDEX_SHIFT
);
172 OUT_BATCH(0); /* starting index */
173 OUT_BATCH(0xffffffff);
179 brw_end_transform_feedback(struct gl_context
*ctx
,
180 struct gl_transform_feedback_object
*obj
)
182 /* After EndTransformFeedback, it's likely that the client program will try
183 * to draw using the contents of the transform feedback buffer as vertex
184 * input. In order for this to work, we need to flush the data through at
185 * least the GS stage of the pipeline, and flush out the render cache. For
186 * simplicity, just do a full flush.
188 struct brw_context
*brw
= brw_context(ctx
);
189 intel_batchbuffer_emit_mi_flush(brw
);