Merge branch '7.8'
[mesa.git] / src / gallium / drivers / i965 / brw_vs_surface_state.c
1 /*
2 Copyright (C) Intel Corp. 2006. All Rights Reserved.
3 Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
4 develop this 3D driver.
5
6 Permission is hereby granted, free of charge, to any person obtaining
7 a copy of this software and associated documentation files (the
8 "Software"), to deal in the Software without restriction, including
9 without limitation the rights to use, copy, modify, merge, publish,
10 distribute, sublicense, and/or sell copies of the Software, and to
11 permit persons to whom the Software is furnished to do so, subject to
12 the following conditions:
13
14 The above copyright notice and this permission notice (including the
15 next paragraph) shall be included in all copies or substantial
16 portions of the Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
22 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
26 **********************************************************************/
27 /*
28 * Authors:
29 * Keith Whitwell <keith@tungstengraphics.com>
30 */
31
32 #include "brw_context.h"
33 #include "brw_state.h"
34 #include "brw_winsys.h"
35
36 /* XXX: disabled true constant buffer functionality
37 */
38
39
40 /* Creates a new VS constant buffer reflecting the current VS program's
41 * constants, if needed by the VS program.
42 *
43 * Otherwise, constants go through the CURBEs using the brw_constant_buffer
44 * state atom.
45 */
46 #if 0
47 static struct brw_winsys_buffer *
48 brw_vs_update_constant_buffer(struct brw_context *brw)
49 {
50 /* XXX: true constant buffers
51 */
52 struct brw_vertex_program *vp =
53 (struct brw_vertex_program *) brw->vertex_program;
54 const struct gl_program_parameter_list *params = vp->program.Base.Parameters;
55 const int size = params->NumParameters * 4 * sizeof(GLfloat);
56 drm_intel_bo *const_buffer;
57
58 /* BRW_NEW_VERTEX_PROGRAM */
59 if (!vp->use_const_buffer)
60 return NULL;
61
62 const_buffer = brw->sws->bo_alloc(brw->sws,
63 BRW_BUFFER_TYPE_SHADER_CONSTANTS,
64 size, 64);
65
66 /* _NEW_PROGRAM_CONSTANTS */
67 brw->sws->bo_subdata(const_buffer, 0, size, params->ParameterValues,
68 NULL, 0);
69
70 return const_buffer;
71 }
72 #endif
73
74 /**
75 * Update the surface state for a VS constant buffer.
76 *
77 * Sets brw->vs.surf_bo[surf] and brw->vp->const_buffer.
78 */
79 #if 0
80 static void
81 brw_update_vs_constant_surface( struct brw_context *brw,
82 GLuint surf)
83 {
84 struct brw_surface_key key;
85 struct pipe_resource *cb = brw->curr.vs_constants;
86 enum pipe_error ret;
87
88 assert(surf == 0);
89
90 /* If we're in this state update atom, we need to update VS constants, so
91 * free the old buffer and create a new one for the new contents.
92 */
93 ret = brw_vs_update_constant_buffer(brw, &vp->const_buffer);
94 if (ret)
95 return ret;
96
97 /* If there's no constant buffer, then no surface BO is needed to point at
98 * it.
99 */
100 if (vp->const_buffer == NULL) {
101 bo_reference(brw->vs.surf_bo[surf], NULL);
102 return PIPE_OK;
103 }
104
105 memset(&key, 0, sizeof(key));
106
107 key.format = PIPE_FORMAT_R32G32B32A32_FLOAT;
108 key.bo = vp->const_buffer;
109 key.depthmode = GL_NONE;
110 key.pitch = params->NumParameters;
111 key.width = params->NumParameters;
112 key.height = 1;
113 key.depth = 1;
114 key.cpp = 16;
115
116 /*
117 printf("%s:\n", __FUNCTION__);
118 printf(" width %d height %d depth %d cpp %d pitch %d\n",
119 key.width, key.height, key.depth, key.cpp, key.pitch);
120 */
121
122 if (brw_search_cache(&brw->surface_cache,
123 BRW_SS_SURFACE,
124 &key, sizeof(key),
125 &key.bo, key.bo ? 1 : 0,
126 NULL,
127 &brw->vs.surf_bo[surf]))
128 return PIPE_OK;
129
130 ret = brw_create_constant_surface(brw, &key
131 &brw->vs.surf_bo[surf]);
132 if (ret)
133 return ret;
134
135 return PIPE_OK;
136 }
137 #endif
138
139
140 /**
141 * Constructs the binding table for the VS surface state.
142 */
143 static enum pipe_error
144 brw_vs_get_binding_table(struct brw_context *brw,
145 struct brw_winsys_buffer **bo_out)
146 {
147 #if 0
148 static GLuint data[BRW_VS_MAX_SURF]; /* always zero */
149 struct brw_winsys_reloc reloc[BRW_VS_MAX_SURF];
150 int i;
151
152 /* Emit binding table relocations to surface state */
153 for (i = 0; i < BRW_VS_MAX_SURF; i++) {
154 make_reloc(&reloc[i],
155 BRW_USAGE_STATE,
156 0,
157 i * 4,
158 brw->vs.surf_bo[i]);
159 }
160
161 ret = brw_cache_data( &brw->surface_cache,
162 BRW_SS_SURF_BIND,
163 NULL, 0,
164 reloc, nr_reloc,
165 data, sizeof data,
166 NULL, NULL,
167 bo_out);
168 if (ret)
169 return ret;
170
171 FREE(data);
172 return PIPE_OK;
173 #else
174 return PIPE_OK;
175 #endif
176 }
177
178 /**
179 * Vertex shader surfaces (constant buffer).
180 *
181 * This consumes the state updates for the constant buffer needing
182 * to be updated, and produces BRW_NEW_NR_VS_SURFACES for the VS unit and
183 * CACHE_NEW_SURF_BIND for the binding table upload.
184 */
185 static enum pipe_error prepare_vs_surfaces(struct brw_context *brw )
186 {
187 enum pipe_error ret;
188
189 #if 0
190 int i;
191 int nr_surfaces = 0;
192
193 brw_update_vs_constant_surface(ctx, SURF_INDEX_VERT_CONST_BUFFER);
194
195 for (i = 0; i < BRW_VS_MAX_SURF; i++) {
196 if (brw->vs.surf_bo[i] != NULL) {
197 nr_surfaces = i + 1;
198 }
199 }
200
201 if (brw->vs.nr_surfaces != nr_surfaces) {
202 brw->state.dirty.brw |= BRW_NEW_NR_VS_SURFACES;
203 brw->vs.nr_surfaces = nr_surfaces;
204 }
205 #endif
206
207 /* Note that we don't end up updating the bind_bo if we don't have a
208 * surface to be pointing at. This should be relatively harmless, as it
209 * just slightly increases our working set size.
210 */
211 if (brw->vs.nr_surfaces != 0) {
212 ret = brw_vs_get_binding_table(brw, &brw->vs.bind_bo);
213 if (ret)
214 return ret;
215 }
216
217 return PIPE_OK;
218 }
219
220 const struct brw_tracked_state brw_vs_surfaces = {
221 .dirty = {
222 .mesa = (PIPE_NEW_VERTEX_CONSTANTS |
223 PIPE_NEW_VERTEX_SHADER),
224 .brw = 0,
225 .cache = 0
226 },
227 .prepare = prepare_vs_surfaces,
228 };
229
230
231