i965g: add new state flag tracking fs signature changes
[mesa.git] / src / gallium / drivers / 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 #include "tgsi/tgsi_dump.h"
33
34 #include "brw_context.h"
35 #include "brw_vs.h"
36 #include "brw_util.h"
37 #include "brw_state.h"
38 #include "brw_pipe_rast.h"
39
40
41
42 static enum pipe_error do_vs_prog( struct brw_context *brw,
43 struct brw_vertex_shader *vp,
44 struct brw_vs_prog_key *key,
45 struct brw_winsys_buffer **bo_out)
46 {
47 enum pipe_error ret;
48 GLuint program_size;
49 const GLuint *program;
50 struct brw_vs_compile c;
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.nr_outputs = vp->info.num_outputs;
59 c.prog_data.nr_inputs = vp->info.num_inputs;
60
61 /* XXX: we want edgeflag handling to be integrated to the vertex
62 * shader, but are currently faking the edgeflag output:
63 */
64 if (c.key.copy_edgeflag) {
65 c.prog_data.output_edgeflag = c.prog_data.nr_outputs;
66 c.prog_data.nr_outputs++;
67 }
68 else {
69 c.prog_data.output_edgeflag = ~0;
70 }
71
72
73 if (1)
74 tgsi_dump(c.vp->tokens, 0);
75
76 /* Emit GEN4 code.
77 */
78 brw_vs_emit(&c);
79
80 /* get the program
81 */
82 ret = brw_get_program(&c.func, &program, &program_size);
83 if (ret)
84 return ret;
85
86 ret = brw_upload_cache( &brw->cache, BRW_VS_PROG,
87 &c.key, sizeof(c.key),
88 NULL, 0,
89 program, program_size,
90 &c.prog_data,
91 &brw->vs.prog_data,
92 bo_out);
93 if (ret)
94 return ret;
95
96 return PIPE_OK;
97 }
98
99
100 static enum pipe_error brw_upload_vs_prog(struct brw_context *brw)
101 {
102 struct brw_vs_prog_key key;
103 struct brw_vertex_shader *vp = brw->curr.vertex_shader;
104 struct brw_fs_signature *sig = &brw->curr.fragment_shader->signature;
105 enum pipe_error ret;
106
107 memset(&key, 0, sizeof(key));
108
109 key.program_string_id = vp->id;
110 key.nr_userclip = brw->curr.ucp.nr;
111 key.copy_edgeflag = (brw->curr.rast->templ.fill_ccw != PIPE_POLYGON_MODE_FILL ||
112 brw->curr.rast->templ.fill_cw != PIPE_POLYGON_MODE_FILL);
113
114 memcpy(&key.fs_signature, sig, brw_fs_signature_size(sig));
115
116
117 /* Make an early check for the key.
118 */
119 if (brw_search_cache(&brw->cache, BRW_VS_PROG,
120 &key, brw_vs_prog_key_size(&key),
121 NULL, 0,
122 &brw->vs.prog_data,
123 &brw->vs.prog_bo))
124 return PIPE_OK;
125
126 ret = do_vs_prog(brw, vp, &key, &brw->vs.prog_bo);
127 if (ret)
128 return ret;
129
130 return PIPE_OK;
131 }
132
133
134 /* See brw_vs.c:
135 */
136 const struct brw_tracked_state brw_vs_prog = {
137 .dirty = {
138 .mesa = (PIPE_NEW_CLIP |
139 PIPE_NEW_RAST |
140 PIPE_NEW_FRAGMENT_SIGNATURE),
141 .brw = BRW_NEW_VERTEX_PROGRAM,
142 .cache = 0
143 },
144 .prepare = brw_upload_vs_prog
145 };