2 * Mesa 3-D graphics library
4 * Copyright (C) 2012-2013 LunarG, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
25 * Chia-I Wu <olv@lunarg.com>
31 #include "pipe/p_state.h"
32 #include "pipe/p_shader_tokens.h"
33 #include "toy_compiler.h"
36 struct tgsi_full_instruction
;
37 struct util_hash_table
;
39 typedef void (*toy_tgsi_translate
)(struct toy_compiler
*tc
,
40 const struct tgsi_full_instruction
*tgsi_inst
,
45 struct toy_compiler
*tc
;
47 const toy_tgsi_translate
*translate_table
;
49 struct util_hash_table
*reg_mapping
;
52 bool vs_prohibit_ucps
;
54 int fs_coord_pixel_center
;
55 bool fs_color0_writes_all_cbufs
;
59 int gs_max_output_vertices
;
70 unsigned usage_mask
:4; /* TGSI_WRITEMASK_x */
71 unsigned semantic_name
:8; /* TGSI_SEMANTIC_x */
72 unsigned semantic_index
:8;
73 unsigned interp
:4; /* TGSI_INTERPOLATE_x */
75 } inputs
[PIPE_MAX_SHADER_INPUTS
];
80 unsigned undefined_mask
:4;
81 unsigned usage_mask
:4; /* TGSI_WRITEMASK_x */
82 unsigned semantic_name
:8; /* TGSI_SEMANTIC_x */
83 unsigned semantic_index
:8;
84 } outputs
[PIPE_MAX_SHADER_OUTPUTS
];
89 unsigned semantic_name
:8; /* TGSI_SEMANTIC_x */
90 unsigned semantic_index
:8;
92 int num_system_values
;
98 * Find the slot of the TGSI input.
101 toy_tgsi_find_input(const struct toy_tgsi
*tgsi
, int index
)
105 for (slot
= 0; slot
< tgsi
->num_inputs
; slot
++) {
106 if (tgsi
->inputs
[slot
].index
== index
)
114 * Find the slot of the TGSI system value.
117 toy_tgsi_find_system_value(const struct toy_tgsi
*tgsi
, int index
)
121 for (slot
= 0; slot
< tgsi
->num_system_values
; slot
++) {
122 if (tgsi
->system_values
[slot
].index
== index
)
130 * Return the immediate data of the TGSI immediate.
132 static inline const uint32_t *
133 toy_tgsi_get_imm(const struct toy_tgsi
*tgsi
, unsigned index
,
138 if (index
>= tgsi
->imm_data
.cur
)
141 imm
= tgsi
->imm_data
.buf
[index
];
143 *type
= tgsi
->imm_data
.types
[index
];
149 * Return the dimension of the texture coordinates, as well as the location of
150 * the shadow reference value or the sample index.
153 toy_tgsi_get_texture_coord_dim(int tgsi_tex
, int *shadow_or_sample
)
158 * Depending on the texture target, (src0, src1.x) is interpreted
161 * (s, *, *, *, *), for 1D
162 * (s, t, *, *, *), for 2D, RECT
163 * (s, t, r, *, *), for 3D, CUBE
165 * (s, layer, *, *, *), for 1D_ARRAY
166 * (s, t, layer, *, *), for 2D_ARRAY
167 * (s, t, r, layer, *), for CUBE_ARRAY
169 * (s, *, shadow, *, *), for SHADOW1D
170 * (s, t, shadow, *, *), for SHADOW2D, SHADOWRECT
171 * (s, t, r, shadow, *), for SHADOWCUBE
173 * (s, layer, shadow, *, *), for SHADOW1D_ARRAY
174 * (s, t, layer, shadow, *), for SHADOW2D_ARRAY
175 * (s, t, r, layer, shadow), for SHADOWCUBE_ARRAY
177 * (s, t, sample, *, *), for 2D_MSAA
178 * (s, t, layer, sample, *), for 2D_ARRAY_MSAA
181 case TGSI_TEXTURE_1D
:
182 case TGSI_TEXTURE_SHADOW1D
:
185 case TGSI_TEXTURE_2D
:
186 case TGSI_TEXTURE_RECT
:
187 case TGSI_TEXTURE_1D_ARRAY
:
188 case TGSI_TEXTURE_SHADOW2D
:
189 case TGSI_TEXTURE_SHADOWRECT
:
190 case TGSI_TEXTURE_SHADOW1D_ARRAY
:
191 case TGSI_TEXTURE_2D_MSAA
:
194 case TGSI_TEXTURE_3D
:
195 case TGSI_TEXTURE_CUBE
:
196 case TGSI_TEXTURE_2D_ARRAY
:
197 case TGSI_TEXTURE_SHADOWCUBE
:
198 case TGSI_TEXTURE_SHADOW2D_ARRAY
:
199 case TGSI_TEXTURE_2D_ARRAY_MSAA
:
202 case TGSI_TEXTURE_CUBE_ARRAY
:
203 case TGSI_TEXTURE_SHADOWCUBE_ARRAY
:
207 assert(!"unknown texture target");
212 if (shadow_or_sample
) {
214 case TGSI_TEXTURE_SHADOW1D
:
216 *shadow_or_sample
= 2;
218 case TGSI_TEXTURE_SHADOW2D
:
219 case TGSI_TEXTURE_SHADOWRECT
:
220 case TGSI_TEXTURE_SHADOWCUBE
:
221 case TGSI_TEXTURE_SHADOW1D_ARRAY
:
222 case TGSI_TEXTURE_SHADOW2D_ARRAY
:
223 case TGSI_TEXTURE_SHADOWCUBE_ARRAY
:
224 case TGSI_TEXTURE_2D_MSAA
:
225 case TGSI_TEXTURE_2D_ARRAY_MSAA
:
226 *shadow_or_sample
= dim
;
229 /* no shadow nor sample */
230 *shadow_or_sample
= -1;
239 toy_compiler_translate_tgsi(struct toy_compiler
*tc
,
240 const struct tgsi_token
*tokens
, bool aos
,
241 struct toy_tgsi
*tgsi
);
244 toy_tgsi_cleanup(struct toy_tgsi
*tgsi
);
247 toy_tgsi_get_vrf(const struct toy_tgsi
*tgsi
,
248 enum tgsi_file_type file
, int dimension
, int index
);
251 toy_tgsi_dump(const struct toy_tgsi
*tgsi
);
253 #endif /* TOY_TGSI_H */