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"
35 * We use a 32-bit mask to keep track of the generic indexes.
37 #define MAX_GENERIC_VARYING 32
40 struct svga_fragment_shader
;
41 struct svga_vertex_shader
;
43 struct tgsi_shader_info
;
47 struct svga_vs_compile_key
49 unsigned fs_generic_inputs
;
50 unsigned need_prescale
:1;
51 unsigned allow_psiz
:1;
52 unsigned adjust_attrib_range
:16;
55 struct svga_fs_compile_key
57 unsigned light_twoside
:1;
59 unsigned white_fragments
:1;
60 unsigned write_color0_to_n_cbufs
:3;
61 unsigned num_textures
:8;
62 unsigned num_unnormalized_coords
:8;
63 unsigned sprite_origin_lower_left
:1;
65 unsigned compare_mode
:1;
66 unsigned compare_func
:3;
67 unsigned unnormalized
:1;
68 unsigned width_height_idx
:7;
69 unsigned texture_target
:8;
70 unsigned sprite_texgen
:1;
75 } tex
[PIPE_MAX_SAMPLERS
];
79 * Key/index for identifying shader variants.
81 struct svga_compile_key
{
82 struct svga_vs_compile_key vkey
;
83 struct svga_fs_compile_key fkey
;
84 int8_t generic_remap_table
[MAX_GENERIC_VARYING
];
89 * A single TGSI shader may be compiled into different variants of
90 * SVGA3D shaders depending on the compile key. Each user shader
91 * will have a linked list of these variants.
93 struct svga_shader_variant
95 const struct svga_shader
*shader
;
97 /** Parameters used to generate this variant */
98 struct svga_compile_key key
;
100 /* Compiled shader tokens:
102 const unsigned *tokens
;
105 /** Per-context shader identifier used with SVGA_3D_CMD_SHADER_DEFINE,
106 * SVGA_3D_CMD_SET_SHADER and SVGA_3D_CMD_SHADER_DESTROY.
110 /* GB object buffer containing the bytecode */
111 struct svga_winsys_gb_shader
*gb_shader
;
114 struct svga_shader_variant
*next
;
118 /* TGSI doesn't provide use with VS input semantics (they're actually
119 * pretty meaningless), so we just generate some plausible ones here.
120 * This is called both from within the TGSI translator and when
121 * building vdecls to ensure they match up.
123 * The real use of this information is matching vertex elements to
124 * fragment shader inputs in the case where vertex shader is disabled.
126 static INLINE
void svga_generate_vdecl_semantics( unsigned idx
,
128 unsigned *usage_index
)
131 *usage
= SVGA3D_DECLUSAGE_POSITION
;
135 *usage
= SVGA3D_DECLUSAGE_TEXCOORD
;
136 *usage_index
= idx
- 1;
142 static INLINE
unsigned svga_vs_key_size( const struct svga_vs_compile_key
*key
)
147 static INLINE
unsigned svga_fs_key_size( const struct svga_fs_compile_key
*key
)
149 return (const char *)&key
->tex
[key
->num_textures
] - (const char *)key
;
152 struct svga_shader_variant
*
153 svga_translate_fragment_program( const struct svga_fragment_shader
*fs
,
154 const struct svga_fs_compile_key
*fkey
);
156 struct svga_shader_variant
*
157 svga_translate_vertex_program( const struct svga_vertex_shader
*fs
,
158 const struct svga_vs_compile_key
*vkey
);
162 svga_get_generic_inputs_mask(const struct tgsi_shader_info
*info
);
165 svga_get_generic_outputs_mask(const struct tgsi_shader_info
*info
);
168 svga_remap_generics(unsigned generics_mask
,
169 int8_t remap_table
[MAX_GENERIC_VARYING
]);
172 svga_remap_generic_index(int8_t remap_table
[MAX_GENERIC_VARYING
],