1 /**********************************************************
2 * Copyright 2008-2009 VMware, Inc. All rights reserved.
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:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
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
24 **********************************************************/
29 #include "pipe/p_state.h"
31 #include "svga_hw_reg.h"
33 struct svga_fragment_shader
;
34 struct svga_vertex_shader
;
36 struct tgsi_shader_info
;
40 struct svga_vs_compile_key
42 unsigned zero_stride_vertex_elements
;
43 unsigned need_prescale
:1;
44 unsigned allow_psiz
:1;
45 unsigned num_zero_stride_vertex_elements
:6;
48 struct svga_fs_compile_key
50 unsigned light_twoside
:1;
52 unsigned white_fragments
:1;
53 unsigned num_textures
:8;
54 unsigned num_unnormalized_coords
:8;
56 unsigned compare_mode
:1;
57 unsigned compare_func
:3;
58 unsigned unnormalized
:1;
59 unsigned width_height_idx
:7;
60 unsigned texture_target
:8;
61 } tex
[PIPE_MAX_SAMPLERS
];
64 union svga_compile_key
{
65 struct svga_vs_compile_key vkey
;
66 struct svga_fs_compile_key fkey
;
69 struct svga_shader_result
71 const struct svga_shader
*shader
;
73 /* Parameters used to generate this compilation result:
75 union svga_compile_key key
;
77 /* Compiled shader tokens:
79 const unsigned *tokens
;
86 /* Next compilation result:
88 struct svga_shader_result
*next
;
92 /* TGSI doesn't provide use with VS input semantics (they're actually
93 * pretty meaningless), so we just generate some plausible ones here.
94 * This is called both from within the TGSI translator and when
95 * building vdecls to ensure they match up.
97 * The real use of this information is matching vertex elements to
98 * fragment shader inputs in the case where vertex shader is disabled.
100 static INLINE
void svga_generate_vdecl_semantics( unsigned idx
,
102 unsigned *usage_index
)
105 *usage
= SVGA3D_DECLUSAGE_POSITION
;
109 *usage
= SVGA3D_DECLUSAGE_TEXCOORD
;
110 *usage_index
= idx
- 1;
116 static INLINE
unsigned svga_vs_key_size( const struct svga_vs_compile_key
*key
)
121 static INLINE
unsigned svga_fs_key_size( const struct svga_fs_compile_key
*key
)
123 return (const char *)&key
->tex
[key
->num_textures
] - (const char *)key
;
126 struct svga_shader_result
*
127 svga_translate_fragment_program( const struct svga_fragment_shader
*fs
,
128 const struct svga_fs_compile_key
*fkey
);
130 struct svga_shader_result
*
131 svga_translate_vertex_program( const struct svga_vertex_shader
*fs
,
132 const struct svga_vs_compile_key
*vkey
);
135 void svga_destroy_shader_result( struct svga_shader_result
*result
);