Merge remote branch 'origin/master' into lp-binning
[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 "shader/prog_print.h"
38 #include "shader/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 GLcontext *ctx = &brw->intel.ctx;
47 GLuint program_size;
48 const GLuint *program;
49 struct brw_vs_compile c;
50 int aux_size;
51
52 memset(&c, 0, sizeof(c));
53 memcpy(&c.key, key, sizeof(*key));
54
55 brw_init_compile(brw, &c.func);
56 c.vp = vp;
57
58 c.prog_data.outputs_written = vp->program.Base.OutputsWritten;
59 c.prog_data.inputs_read = vp->program.Base.InputsRead;
60
61 if (c.key.copy_edgeflag) {
62 c.prog_data.outputs_written |= BITFIELD64_BIT(VERT_RESULT_EDGE);
63 c.prog_data.inputs_read |= 1<<VERT_ATTRIB_EDGEFLAG;
64 }
65
66 if (0)
67 _mesa_print_program(&c.vp->program.Base);
68
69
70
71 /* Emit GEN4 code.
72 */
73 brw_vs_emit(&c);
74
75 /* get the program
76 */
77 program = brw_get_program(&c.func, &program_size);
78
79 /* We upload from &c.prog_data including the constant_map assuming
80 * they're packed together. It would be nice to have a
81 * compile-time assert macro here.
82 */
83 assert(c.constant_map == (int8_t *)&c.prog_data +
84 sizeof(c.prog_data));
85 assert(ctx->Const.VertexProgram.MaxNativeParameters ==
86 ARRAY_SIZE(c.constant_map));
87
88 aux_size = sizeof(c.prog_data);
89 if (c.vp->use_const_buffer)
90 aux_size += c.vp->program.Base.Parameters->NumParameters;
91
92 dri_bo_unreference(brw->vs.prog_bo);
93 brw->vs.prog_bo = brw_upload_cache_with_auxdata(&brw->cache, BRW_VS_PROG,
94 &c.key, sizeof(c.key),
95 NULL, 0,
96 program, program_size,
97 &c.prog_data,
98 aux_size,
99 &brw->vs.prog_data);
100 }
101
102
103 static void brw_upload_vs_prog(struct brw_context *brw)
104 {
105 GLcontext *ctx = &brw->intel.ctx;
106 struct brw_vs_prog_key key;
107 struct brw_vertex_program *vp =
108 (struct brw_vertex_program *)brw->vertex_program;
109
110 memset(&key, 0, sizeof(key));
111
112 /* Just upload the program verbatim for now. Always send it all
113 * the inputs it asks for, whether they are varying or not.
114 */
115 key.program_string_id = vp->id;
116 key.nr_userclip = brw_count_bits(ctx->Transform.ClipPlanesEnabled);
117 key.copy_edgeflag = (ctx->Polygon.FrontMode != GL_FILL ||
118 ctx->Polygon.BackMode != GL_FILL);
119
120 /* Make an early check for the key.
121 */
122 dri_bo_unreference(brw->vs.prog_bo);
123 brw->vs.prog_bo = brw_search_cache(&brw->cache, BRW_VS_PROG,
124 &key, sizeof(key),
125 NULL, 0,
126 &brw->vs.prog_data);
127 if (brw->vs.prog_bo == NULL)
128 do_vs_prog(brw, vp, &key);
129 brw->vs.constant_map = ((int8_t *)brw->vs.prog_data +
130 sizeof(*brw->vs.prog_data));
131 }
132
133
134 /* See brw_vs.c:
135 */
136 const struct brw_tracked_state brw_vs_prog = {
137 .dirty = {
138 .mesa = _NEW_TRANSFORM | _NEW_POLYGON,
139 .brw = BRW_NEW_VERTEX_PROGRAM,
140 .cache = 0
141 },
142 .prepare = brw_upload_vs_prog
143 };