i965: Remove dead entrypoints to state cache, rename the one that's left.
[mesa.git] / src / mesa / drivers / dri / i965 / brw_vs.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
33 #include "brw_context.h"
34 #include "brw_vs.h"
35 #include "brw_util.h"
36 #include "brw_state.h"
37 #include "program/prog_print.h"
38 #include "program/prog_parameter.h"
39
40
41
42 static void do_vs_prog( struct brw_context *brw,
43 struct brw_vertex_program *vp,
44 struct brw_vs_prog_key *key )
45 {
46 struct gl_context *ctx = &brw->intel.ctx;
47 GLuint program_size;
48 const GLuint *program;
49 struct brw_vs_compile c;
50 int aux_size;
51 int i;
52
53 memset(&c, 0, sizeof(c));
54 memcpy(&c.key, key, sizeof(*key));
55
56 brw_init_compile(brw, &c.func);
57 c.vp = vp;
58
59 c.prog_data.outputs_written = vp->program.Base.OutputsWritten;
60 c.prog_data.inputs_read = vp->program.Base.InputsRead;
61
62 if (c.key.copy_edgeflag) {
63 c.prog_data.outputs_written |= BITFIELD64_BIT(VERT_RESULT_EDGE);
64 c.prog_data.inputs_read |= 1<<VERT_ATTRIB_EDGEFLAG;
65 }
66
67 /* Put dummy slots into the VUE for the SF to put the replaced
68 * point sprite coords in. We shouldn't need these dummy slots,
69 * which take up precious URB space, but it would mean that the SF
70 * doesn't get nice aligned pairs of input coords into output
71 * coords, which would be a pain to handle.
72 */
73 for (i = 0; i < 8; i++) {
74 if (c.key.point_coord_replace & (1 << i))
75 c.prog_data.outputs_written |= BITFIELD64_BIT(VERT_RESULT_TEX0 + i);
76 }
77
78 if (0) {
79 _mesa_fprint_program_opt(stdout, &c.vp->program.Base, PROG_PRINT_DEBUG,
80 GL_TRUE);
81 }
82
83 /* Emit GEN4 code.
84 */
85 brw_vs_emit(&c);
86
87 /* get the program
88 */
89 program = brw_get_program(&c.func, &program_size);
90
91 /* We upload from &c.prog_data including the constant_map assuming
92 * they're packed together. It would be nice to have a
93 * compile-time assert macro here.
94 */
95 assert(c.constant_map == (int8_t *)&c.prog_data +
96 sizeof(c.prog_data));
97 assert(ctx->Const.VertexProgram.MaxNativeParameters ==
98 ARRAY_SIZE(c.constant_map));
99 (void) ctx;
100
101 aux_size = sizeof(c.prog_data);
102 /* constant_map */
103 aux_size += c.vp->program.Base.Parameters->NumParameters;
104
105 drm_intel_bo_unreference(brw->vs.prog_bo);
106 brw->vs.prog_bo = brw_upload_cache(&brw->cache, BRW_VS_PROG,
107 &c.key, sizeof(c.key),
108 program, program_size,
109 &c.prog_data, aux_size,
110 &brw->vs.prog_data);
111 }
112
113
114 static void brw_upload_vs_prog(struct brw_context *brw)
115 {
116 struct gl_context *ctx = &brw->intel.ctx;
117 struct brw_vs_prog_key key;
118 struct brw_vertex_program *vp =
119 (struct brw_vertex_program *)brw->vertex_program;
120 int i;
121
122 memset(&key, 0, sizeof(key));
123
124 /* Just upload the program verbatim for now. Always send it all
125 * the inputs it asks for, whether they are varying or not.
126 */
127 key.program_string_id = vp->id;
128 key.nr_userclip = brw_count_bits(ctx->Transform.ClipPlanesEnabled);
129 key.copy_edgeflag = (ctx->Polygon.FrontMode != GL_FILL ||
130 ctx->Polygon.BackMode != GL_FILL);
131 key.two_side_color = (ctx->Light.Enabled && ctx->Light.Model.TwoSide);
132
133 /* _NEW_LIGHT | _NEW_BUFFERS */
134 key.clamp_vertex_color = ctx->Light._ClampVertexColor;
135
136 /* _NEW_POINT */
137 if (ctx->Point.PointSprite) {
138 for (i = 0; i < 8; i++) {
139 if (ctx->Point.CoordReplace[i])
140 key.point_coord_replace |= (1 << i);
141 }
142 }
143
144 /* Make an early check for the key.
145 */
146 drm_intel_bo_unreference(brw->vs.prog_bo);
147 brw->vs.prog_bo = brw_search_cache(&brw->cache, BRW_VS_PROG,
148 &key, sizeof(key),
149 &brw->vs.prog_data);
150 if (brw->vs.prog_bo == NULL)
151 do_vs_prog(brw, vp, &key);
152 brw->vs.constant_map = ((int8_t *)brw->vs.prog_data +
153 sizeof(*brw->vs.prog_data));
154 }
155
156
157 /* See brw_vs.c:
158 */
159 const struct brw_tracked_state brw_vs_prog = {
160 .dirty = {
161 .mesa = (_NEW_TRANSFORM | _NEW_POLYGON | _NEW_POINT | _NEW_LIGHT |
162 _NEW_BUFFERS),
163 .brw = BRW_NEW_VERTEX_PROGRAM,
164 .cache = 0
165 },
166 .prepare = brw_upload_vs_prog
167 };