Merge branch 'mesa_7_7_branch'
[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_defines.h"
35 #include "brw_winsys.h"
36
37 /* XXX: disabled true constant buffer functionality
38 */
39
40
41 /* Creates a new VS constant buffer reflecting the current VS program's
42 * constants, if needed by the VS program.
43 *
44 * Otherwise, constants go through the CURBEs using the brw_constant_buffer
45 * state atom.
46 */
47 #if 0
48 static struct brw_winsys_buffer *
49 brw_vs_update_constant_buffer(struct brw_context *brw)
50 {
51 /* XXX: true constant buffers
52 */
53 struct brw_vertex_program *vp =
54 (struct brw_vertex_program *) brw->vertex_program;
55 const struct gl_program_parameter_list *params = vp->program.Base.Parameters;
56 const int size = params->NumParameters * 4 * sizeof(GLfloat);
57 drm_intel_bo *const_buffer;
58
59 /* BRW_NEW_VERTEX_PROGRAM */
60 if (!vp->use_const_buffer)
61 return NULL;
62
63 const_buffer = brw->sws->bo_alloc(brw->sws,
64 BRW_BUFFER_TYPE_SHADER_CONSTANTS,
65 size, 64);
66
67 /* _NEW_PROGRAM_CONSTANTS */
68 brw->sws->bo_subdata(const_buffer, 0, size, params->ParameterValues,
69 NULL, 0);
70
71 return const_buffer;
72 }
73 #endif
74
75 /**
76 * Update the surface state for a VS constant buffer.
77 *
78 * Sets brw->vs.surf_bo[surf] and brw->vp->const_buffer.
79 */
80 #if 0
81 static void
82 brw_update_vs_constant_surface( struct brw_context *brw,
83 GLuint surf)
84 {
85 struct brw_surface_key key;
86 struct pipe_buffer *cb = brw->curr.vs_constants;
87 enum pipe_error ret;
88
89 assert(surf == 0);
90
91 /* If we're in this state update atom, we need to update VS constants, so
92 * free the old buffer and create a new one for the new contents.
93 */
94 ret = brw_vs_update_constant_buffer(brw, &vp->const_buffer);
95 if (ret)
96 return ret;
97
98 /* If there's no constant buffer, then no surface BO is needed to point at
99 * it.
100 */
101 if (vp->const_buffer == NULL) {
102 bo_reference(brw->vs.surf_bo[surf], NULL);
103 return PIPE_OK;
104 }
105
106 memset(&key, 0, sizeof(key));
107
108 key.format = PIPE_FORMAT_R32G32B32A32_FLOAT;
109 key.bo = vp->const_buffer;
110 key.depthmode = GL_NONE;
111 key.pitch = params->NumParameters;
112 key.width = params->NumParameters;
113 key.height = 1;
114 key.depth = 1;
115 key.cpp = 16;
116
117 /*
118 printf("%s:\n", __FUNCTION__);
119 printf(" width %d height %d depth %d cpp %d pitch %d\n",
120 key.width, key.height, key.depth, key.cpp, key.pitch);
121 */
122
123 if (brw_search_cache(&brw->surface_cache,
124 BRW_SS_SURFACE,
125 &key, sizeof(key),
126 &key.bo, key.bo ? 1 : 0,
127 NULL,
128 &brw->vs.surf_bo[surf]))
129 return PIPE_OK;
130
131 ret = brw_create_constant_surface(brw, &key
132 &brw->vs.surf_bo[surf]);
133 if (ret)
134 return ret;
135
136 return PIPE_OK;
137 }
138 #endif
139
140
141 /**
142 * Constructs the binding table for the VS surface state.
143 */
144 static enum pipe_error
145 brw_vs_get_binding_table(struct brw_context *brw,
146 struct brw_winsys_buffer **bo_out)
147 {
148 #if 0
149 static GLuint data[BRW_VS_MAX_SURF]; /* always zero */
150 struct brw_winsys_reloc reloc[BRW_VS_MAX_SURF];
151 int i;
152
153 /* Emit binding table relocations to surface state */
154 for (i = 0; i < BRW_VS_MAX_SURF; i++) {
155 make_reloc(&reloc[i],
156 BRW_USAGE_STATE,
157 0,
158 i * 4,
159 brw->vs.surf_bo[i]);
160 }
161
162 ret = brw_cache_data( &brw->surface_cache,
163 BRW_SS_SURF_BIND,
164 NULL, 0,
165 reloc, nr_reloc,
166 data, sizeof data,
167 NULL, NULL,
168 bo_out);
169 if (ret)
170 return ret;
171
172 FREE(data);
173 return PIPE_OK;
174 #else
175 return PIPE_OK;
176 #endif
177 }
178
179 /**
180 * Vertex shader surfaces (constant buffer).
181 *
182 * This consumes the state updates for the constant buffer needing
183 * to be updated, and produces BRW_NEW_NR_VS_SURFACES for the VS unit and
184 * CACHE_NEW_SURF_BIND for the binding table upload.
185 */
186 static enum pipe_error prepare_vs_surfaces(struct brw_context *brw )
187 {
188 enum pipe_error ret;
189
190 #if 0
191 int i;
192 int nr_surfaces = 0;
193
194 brw_update_vs_constant_surface(ctx, SURF_INDEX_VERT_CONST_BUFFER);
195
196 for (i = 0; i < BRW_VS_MAX_SURF; i++) {
197 if (brw->vs.surf_bo[i] != NULL) {
198 nr_surfaces = i + 1;
199 }
200 }
201
202 if (brw->vs.nr_surfaces != nr_surfaces) {
203 brw->state.dirty.brw |= BRW_NEW_NR_VS_SURFACES;
204 brw->vs.nr_surfaces = nr_surfaces;
205 }
206 #endif
207
208 /* Note that we don't end up updating the bind_bo if we don't have a
209 * surface to be pointing at. This should be relatively harmless, as it
210 * just slightly increases our working set size.
211 */
212 if (brw->vs.nr_surfaces != 0) {
213 ret = brw_vs_get_binding_table(brw, &brw->vs.bind_bo);
214 if (ret)
215 return ret;
216 }
217
218 return PIPE_OK;
219 }
220
221 const struct brw_tracked_state brw_vs_surfaces = {
222 .dirty = {
223 .mesa = (PIPE_NEW_VERTEX_CONSTANTS |
224 PIPE_NEW_VERTEX_SHADER),
225 .brw = 0,
226 .cache = 0
227 },
228 .prepare = prepare_vs_surfaces,
229 };
230
231
232