OSDN Git Service

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