i965: Flush pipeline on EndTransformFeedback.
[mesa.git] / src / mesa / drivers / dri / i965 / gen6_sol.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 /** \file gen6_sol.c
25 *
26 * Code to initialize the binding table entries used by transform feedback.
27 */
28
29 #include "brw_context.h"
30 #include "intel_batchbuffer.h"
31 #include "brw_defines.h"
32
33 static void
34 gen6_update_sol_surfaces(struct brw_context *brw)
35 {
36 struct gl_context *ctx = &brw->intel.ctx;
37 /* _NEW_TRANSFORM_FEEDBACK */
38 struct gl_transform_feedback_object *xfb_obj =
39 ctx->TransformFeedback.CurrentObject;
40 /* BRW_NEW_VERTEX_PROGRAM */
41 const struct gl_shader_program *shaderprog =
42 ctx->Shader.CurrentVertexProgram;
43 const struct gl_transform_feedback_info *linked_xfb_info =
44 &shaderprog->LinkedTransformFeedback;
45 int i;
46
47 for (i = 0; i < BRW_MAX_SOL_BINDINGS; ++i) {
48 const int surf_index = SURF_INDEX_SOL_BINDING(i);
49 if (xfb_obj->Active && i < linked_xfb_info->NumOutputs) {
50 unsigned buffer = linked_xfb_info->Outputs[i].OutputBuffer;
51 unsigned buffer_offset =
52 xfb_obj->Offset[buffer] / 4 +
53 linked_xfb_info->Outputs[i].DstOffset;
54 brw_update_sol_surface(
55 brw, xfb_obj->Buffers[buffer], &brw->bind.surf_offset[surf_index],
56 linked_xfb_info->Outputs[i].NumComponents,
57 linked_xfb_info->BufferStride[buffer], buffer_offset);
58 } else {
59 brw->bind.surf_offset[surf_index] = 0;
60 }
61 }
62 }
63
64 const struct brw_tracked_state gen6_sol_surface = {
65 .dirty = {
66 .mesa = _NEW_TRANSFORM_FEEDBACK,
67 .brw = (BRW_NEW_BATCH |
68 BRW_NEW_VERTEX_PROGRAM),
69 .cache = 0
70 },
71 .emit = gen6_update_sol_surfaces,
72 };
73
74 void
75 brw_end_transform_feedback(struct gl_context *ctx,
76 struct gl_transform_feedback_object *obj)
77 {
78 /* After EndTransformFeedback, it's likely that the client program will try
79 * to draw using the contents of the transform feedback buffer as vertex
80 * input. In order for this to work, we need to flush the data through at
81 * least the GS stage of the pipeline, and flush out the render cache. For
82 * simplicity, just do a full flush.
83 */
84 struct brw_context *brw = brw_context(ctx);
85 struct intel_context *intel = &brw->intel;
86 intel_batchbuffer_emit_mi_flush(intel);
87 }