brw_vs.c revision f2eb6434ab1cf72e938956c82d2f530368a6be4a
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.h"
38#include "shader/arbprogparse.h"
39
40
41
42static void do_vs_prog( struct brw_context *brw,
43			struct brw_vertex_program *vp,
44			struct brw_vs_prog_key *key )
45{
46   GLuint program_size;
47   const GLuint *program;
48   struct brw_vs_compile c;
49
50   memset(&c, 0, sizeof(c));
51   memcpy(&c.key, key, sizeof(*key));
52
53   brw_init_compile(&c.func);
54   c.vp = vp;
55
56   c.prog_data.outputs_written = vp->program.Base.OutputsWritten;
57   c.prog_data.inputs_read = vp->program.Base.InputsRead;
58
59   if (c.key.copy_edgeflag) {
60      c.prog_data.outputs_written |= 1<<VERT_RESULT_EDGE;
61      c.prog_data.inputs_read |= 1<<VERT_ATTRIB_EDGEFLAG;
62   }
63
64   if (0)
65      _mesa_print_program(&c.vp->program.Base);
66
67
68
69   /* Emit GEN4 code.
70    */
71   brw_vs_emit(&c);
72
73   /* get the program
74    */
75   program = brw_get_program(&c.func, &program_size);
76
77   /*
78    */
79   brw->vs.prog_gs_offset = brw_upload_cache( &brw->cache[BRW_VS_PROG],
80					      &c.key,
81					      sizeof(c.key),
82					      program,
83					      program_size,
84					      &c.prog_data,
85					      &brw->vs.prog_data);
86}
87
88
89static void brw_upload_vs_prog( struct brw_context *brw )
90{
91   struct brw_vs_prog_key key;
92   struct brw_vertex_program *vp =
93      (struct brw_vertex_program *)brw->vertex_program;
94
95   assert (vp && !vp->program.IsNVProgram);
96
97   memset(&key, 0, sizeof(key));
98
99   /* Just upload the program verbatim for now.  Always send it all
100    * the inputs it asks for, whether they are varying or not.
101    */
102   key.program_string_id = vp->id;
103   key.nr_userclip = brw_count_bits(brw->attribs.Transform->ClipPlanesEnabled);
104   key.copy_edgeflag = (brw->attribs.Polygon->FrontMode != GL_FILL ||
105			brw->attribs.Polygon->BackMode != GL_FILL);
106
107   /* BRW_NEW_METAOPS
108    */
109   if (brw->metaops.active)
110      key.know_w_is_one = 1;
111
112   /* Make an early check for the key.
113    */
114   if (brw_search_cache(&brw->cache[BRW_VS_PROG],
115			&key, sizeof(key),
116			&brw->vs.prog_data,
117			&brw->vs.prog_gs_offset))
118       return;
119
120   do_vs_prog(brw, vp, &key);
121}
122
123
124/* See brw_vs.c:
125 */
126const struct brw_tracked_state brw_vs_prog = {
127   .dirty = {
128      .mesa  = _NEW_TRANSFORM | _NEW_POLYGON,
129      .brw   = BRW_NEW_VERTEX_PROGRAM | BRW_NEW_METAOPS,
130      .cache = 0
131   },
132   .update = brw_upload_vs_prog
133};
134