i965g: still working on compilation
[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 dri_bo_subdata(const_buffer, 0, size, params->ParameterValues);
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_buffer *cb = brw->curr.vs_constants;
86
87 assert(surf == 0);
88
89 /* If we're in this state update atom, we need to update VS constants, so
90 * free the old buffer and create a new one for the new contents.
91 */
92 brw->sws->bo_unreference(vp->const_buffer);
93 vp->const_buffer = brw_vs_update_constant_buffer(brw);
94
95 /* If there's no constant buffer, then no surface BO is needed to point at
96 * it.
97 */
98 if (vp->const_buffer == 0) {
99 drm_intel_bo_unreference(brw->vs.surf_bo[surf]);
100 brw->vs.surf_bo[surf] = NULL;
101 return;
102 }
103
104 memset(&key, 0, sizeof(key));
105
106 key.format = PIPE_FORMAT_R32G32B32A32_FLOAT;
107 key.bo = vp->const_buffer;
108 key.depthmode = GL_NONE;
109 key.pitch = params->NumParameters;
110 key.width = params->NumParameters;
111 key.height = 1;
112 key.depth = 1;
113 key.cpp = 16;
114
115 /*
116 printf("%s:\n", __FUNCTION__);
117 printf(" width %d height %d depth %d cpp %d pitch %d\n",
118 key.width, key.height, key.depth, key.cpp, key.pitch);
119 */
120
121 drm_intel_bo_unreference(brw->vs.surf_bo[surf]);
122 brw->vs.surf_bo[surf] = brw_search_cache(&brw->surface_cache,
123 BRW_SS_SURFACE,
124 &key, sizeof(key),
125 &key.bo, key.bo ? 1 : 0,
126 NULL);
127 if (brw->vs.surf_bo[surf] == NULL) {
128 brw->vs.surf_bo[surf] = brw_create_constant_surface(brw, &key);
129 }
130 }
131 #endif
132
133
134 /**
135 * Constructs the binding table for the VS surface state.
136 */
137 static struct brw_winsys_buffer *
138 brw_vs_get_binding_table(struct brw_context *brw)
139 {
140 #if 0
141 struct brw_winsys_buffer *bind_bo;
142
143 bind_bo = brw_search_cache(&brw->surface_cache, BRW_SS_SURF_BIND,
144 NULL, 0,
145 brw->vs.surf_bo, BRW_VS_MAX_SURF,
146 NULL);
147
148 if (bind_bo == NULL) {
149 GLuint data_size = BRW_VS_MAX_SURF * sizeof(GLuint);
150 uint32_t *data = malloc(data_size);
151 int i;
152
153 for (i = 0; i < BRW_VS_MAX_SURF; i++)
154 if (brw->vs.surf_bo[i])
155 data[i] = brw->vs.surf_bo[i]->offset;
156 else
157 data[i] = 0;
158
159 bind_bo = brw_upload_cache( &brw->surface_cache, BRW_SS_SURF_BIND,
160 NULL, 0,
161 brw->vs.surf_bo, BRW_VS_MAX_SURF,
162 data, data_size,
163 NULL, NULL);
164
165 /* Emit binding table relocations to surface state */
166 for (i = 0; i < BRW_VS_MAX_SURF; i++) {
167 if (brw->vs.surf_bo[i] != NULL) {
168 /* The presumed offsets were set in the data values for
169 * brw_upload_cache.
170 */
171 drm_intel_bo_emit_reloc(bind_bo, i * 4,
172 brw->vs.surf_bo[i], 0,
173 I915_GEM_DOMAIN_INSTRUCTION, 0);
174 }
175 }
176
177 free(data);
178 }
179
180 return bind_bo;
181 #else
182 return NULL;
183 #endif
184 }
185
186 /**
187 * Vertex shader surfaces (constant buffer).
188 *
189 * This consumes the state updates for the constant buffer needing
190 * to be updated, and produces BRW_NEW_NR_VS_SURFACES for the VS unit and
191 * CACHE_NEW_SURF_BIND for the binding table upload.
192 */
193 static int prepare_vs_surfaces(struct brw_context *brw )
194 {
195 #if 0
196 int i;
197 int nr_surfaces = 0;
198
199 brw_update_vs_constant_surface(ctx, SURF_INDEX_VERT_CONST_BUFFER);
200
201 for (i = 0; i < BRW_VS_MAX_SURF; i++) {
202 if (brw->vs.surf_bo[i] != NULL) {
203 nr_surfaces = i + 1;
204 }
205 }
206
207 if (brw->vs.nr_surfaces != nr_surfaces) {
208 brw->state.dirty.brw |= BRW_NEW_NR_VS_SURFACES;
209 brw->vs.nr_surfaces = nr_surfaces;
210 }
211 #endif
212
213 /* Note that we don't end up updating the bind_bo if we don't have a
214 * surface to be pointing at. This should be relatively harmless, as it
215 * just slightly increases our working set size.
216 */
217 if (brw->vs.nr_surfaces != 0) {
218 brw->sws->bo_unreference(brw->vs.bind_bo);
219 brw->vs.bind_bo = brw_vs_get_binding_table(brw);
220 }
221
222 return 0;
223 }
224
225 const struct brw_tracked_state brw_vs_surfaces = {
226 .dirty = {
227 .mesa = (PIPE_NEW_VERTEX_CONSTANTS |
228 PIPE_NEW_VERTEX_SHADER),
229 .brw = 0,
230 .cache = 0
231 },
232 .prepare = prepare_vs_surfaces,
233 };
234
235
236