i965/gs: Implement support for geometry shader surfaces.
[mesa.git] / src / mesa / drivers / dri / i965 / brw_gs_surface_state.c
1 /*
2 * Copyright © 2013 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 #include "main/mtypes.h"
25 #include "program/prog_parameter.h"
26
27 #include "brw_context.h"
28 #include "brw_state.h"
29
30
31 /* Creates a new GS constant buffer reflecting the current GS program's
32 * constants, if needed by the GS program.
33 *
34 * Otherwise, constants go through the CURBEs using the brw_constant_buffer
35 * state atom.
36 */
37 static void
38 brw_upload_gs_pull_constants(struct brw_context *brw)
39 {
40 struct brw_stage_state *stage_state = &brw->gs.base;
41
42 /* BRW_NEW_GEOMETRY_PROGRAM */
43 struct brw_geometry_program *gp =
44 (struct brw_geometry_program *) brw->geometry_program;
45
46 if (!gp)
47 return;
48
49 /* CACHE_NEW_GS_PROG */
50 const struct brw_vec4_prog_data *prog_data = &brw->gs.prog_data->base;
51
52 /* _NEW_PROGRAM_CONSTANTS */
53 brw_upload_vec4_pull_constants(brw, BRW_NEW_GS_CONSTBUF, &gp->program.Base,
54 stage_state, prog_data);
55 }
56
57 const struct brw_tracked_state brw_gs_pull_constants = {
58 .dirty = {
59 .mesa = (_NEW_PROGRAM_CONSTANTS),
60 .brw = (BRW_NEW_BATCH | BRW_NEW_GEOMETRY_PROGRAM),
61 .cache = CACHE_NEW_GS_PROG,
62 },
63 .emit = brw_upload_gs_pull_constants,
64 };
65
66 static void
67 brw_upload_gs_ubo_surfaces(struct brw_context *brw)
68 {
69 struct gl_context *ctx = &brw->ctx;
70 struct brw_stage_state *stage_state = &brw->gs.base;
71
72 /* _NEW_PROGRAM */
73 struct gl_shader_program *prog = ctx->Shader.CurrentGeometryProgram;
74
75 if (!prog)
76 return;
77
78 brw_upload_ubo_surfaces(brw, prog->_LinkedShaders[MESA_SHADER_GEOMETRY],
79 &stage_state->surf_offset[SURF_INDEX_VEC4_UBO(0)]);
80 }
81
82 const struct brw_tracked_state brw_gs_ubo_surfaces = {
83 .dirty = {
84 .mesa = _NEW_PROGRAM,
85 .brw = BRW_NEW_BATCH | BRW_NEW_UNIFORM_BUFFER,
86 .cache = 0,
87 },
88 .emit = brw_upload_gs_ubo_surfaces,
89 };
90
91
92 /**
93 * Constructs the binding table for the WM surface state, which maps unit
94 * numbers to surface state objects.
95 */
96 static void
97 brw_gs_upload_binding_table(struct brw_context *brw)
98 {
99 struct brw_stage_state *stage_state = &brw->gs.base;
100
101 /* If there's no GS, skip changing anything. */
102 if (!brw->gs.prog_data)
103 return;
104
105 /* CACHE_NEW_GS_PROG */
106 const struct brw_vec4_prog_data *prog_data = &brw->gs.prog_data->base;
107
108 /* BRW_NEW_SURFACES and BRW_NEW_GS_CONSTBUF */
109 brw_vec4_upload_binding_table(brw, BRW_NEW_GS_BINDING_TABLE, stage_state,
110 prog_data);
111 }
112
113 const struct brw_tracked_state brw_gs_binding_table = {
114 .dirty = {
115 .mesa = 0,
116 .brw = (BRW_NEW_BATCH |
117 BRW_NEW_GS_CONSTBUF |
118 BRW_NEW_SURFACES),
119 .cache = CACHE_NEW_GS_PROG
120 },
121 .emit = brw_gs_upload_binding_table,
122 };