Merge branch 'mesa_7_6_branch' into mesa_7_7_branch
[mesa.git] / src / gallium / drivers / svga / svga_tgsi.h
1 /**********************************************************
2 * Copyright 2008-2009 VMware, Inc. All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 *
24 **********************************************************/
25
26 #ifndef SVGA_TGSI_H
27 #define SVGA_TGSI_H
28
29 #include "pipe/p_state.h"
30
31 #include "svga_hw_reg.h"
32
33 struct svga_fragment_shader;
34 struct svga_vertex_shader;
35 struct svga_shader;
36 struct tgsi_shader_info;
37 struct tgsi_token;
38
39
40 struct svga_vs_compile_key
41 {
42 ubyte need_prescale:1;
43 ubyte allow_psiz:1;
44 unsigned zero_stride_vertex_elements;
45 ubyte num_zero_stride_vertex_elements:6;
46 };
47
48 struct svga_fs_compile_key
49 {
50 boolean light_twoside:1;
51 boolean front_cw:1;
52 ubyte num_textures;
53 ubyte num_unnormalized_coords;
54 struct {
55 ubyte compare_mode : 1;
56 ubyte compare_func : 3;
57 ubyte unnormalized : 1;
58
59 ubyte width_height_idx : 7;
60
61 ubyte texture_target;
62 } tex[PIPE_MAX_SAMPLERS];
63 };
64
65 union svga_compile_key {
66 struct svga_vs_compile_key vkey;
67 struct svga_fs_compile_key fkey;
68 };
69
70 struct svga_shader_result
71 {
72 const struct svga_shader *shader;
73
74 /* Parameters used to generate this compilation result:
75 */
76 union svga_compile_key key;
77
78 /* Compiled shader tokens:
79 */
80 const unsigned *tokens;
81 unsigned nr_tokens;
82
83 /* SVGA Shader ID:
84 */
85 unsigned id;
86
87 /* Next compilation result:
88 */
89 struct svga_shader_result *next;
90 };
91
92
93 /* TGSI doesn't provide use with VS input semantics (they're actually
94 * pretty meaningless), so we just generate some plausible ones here.
95 * This is called both from within the TGSI translator and when
96 * building vdecls to ensure they match up.
97 *
98 * The real use of this information is matching vertex elements to
99 * fragment shader inputs in the case where vertex shader is disabled.
100 */
101 static INLINE void svga_generate_vdecl_semantics( unsigned idx,
102 unsigned *usage,
103 unsigned *usage_index )
104 {
105 if (idx == 0) {
106 *usage = SVGA3D_DECLUSAGE_POSITION;
107 *usage_index = 0;
108 }
109 else {
110 *usage = SVGA3D_DECLUSAGE_TEXCOORD;
111 *usage_index = idx - 1;
112 }
113 }
114
115
116
117 static INLINE unsigned svga_vs_key_size( const struct svga_vs_compile_key *key )
118 {
119 return sizeof *key;
120 }
121
122 static INLINE unsigned svga_fs_key_size( const struct svga_fs_compile_key *key )
123 {
124 return (const char *)&key->tex[key->num_textures].texture_target -
125 (const char *)key;
126 }
127
128 struct svga_shader_result *
129 svga_translate_fragment_program( const struct svga_fragment_shader *fs,
130 const struct svga_fs_compile_key *fkey );
131
132 struct svga_shader_result *
133 svga_translate_vertex_program( const struct svga_vertex_shader *fs,
134 const struct svga_vs_compile_key *vkey );
135
136
137 void svga_destroy_shader_result( struct svga_shader_result *result );
138
139 #endif