1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
/*
* Mesa 3-D graphics library
*
* Copyright (C) 2012-2013 LunarG, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
* Authors:
* Chia-I Wu <olv@lunarg.com>
*/
#ifndef TOY_TGSI_H
#define TOY_TGSI_H
#include "pipe/p_state.h"
#include "pipe/p_shader_tokens.h"
#include "toy_compiler.h"
struct tgsi_token;
struct tgsi_full_instruction;
struct util_hash_table;
typedef void (*toy_tgsi_translate)(struct toy_compiler *tc,
const struct tgsi_full_instruction *tgsi_inst,
struct toy_dst *dst,
struct toy_src *src);
struct toy_tgsi {
struct toy_compiler *tc;
bool aos;
const toy_tgsi_translate *translate_table;
struct util_hash_table *reg_mapping;
struct {
bool vs_prohibit_ucps;
int fs_coord_origin;
int fs_coord_pixel_center;
bool fs_color0_writes_all_cbufs;
int fs_depth_layout;
int gs_input_prim;
int gs_output_prim;
int gs_max_output_vertices;
} props;
struct {
enum toy_type *types;
uint32_t (*buf)[4];
int cur, size;
} imm_data;
struct {
int index:16;
unsigned usage_mask:4; /* TGSI_WRITEMASK_x */
unsigned semantic_name:8; /* TGSI_SEMANTIC_x */
unsigned semantic_index:8;
unsigned interp:4; /* TGSI_INTERPOLATE_x */
unsigned centroid:1;
} inputs[PIPE_MAX_SHADER_INPUTS];
int num_inputs;
struct {
int index:16;
unsigned undefined_mask:4;
unsigned usage_mask:4; /* TGSI_WRITEMASK_x */
unsigned semantic_name:8; /* TGSI_SEMANTIC_x */
unsigned semantic_index:8;
} outputs[PIPE_MAX_SHADER_OUTPUTS];
int num_outputs;
struct {
int index:16;
unsigned semantic_name:8; /* TGSI_SEMANTIC_x */
unsigned semantic_index:8;
} system_values[8];
int num_system_values;
int const_count;
bool const_indirect;
bool uses_kill;
};
/**
* Find the slot of the TGSI input.
*/
static inline int
toy_tgsi_find_input(const struct toy_tgsi *tgsi, int index)
{
int slot;
for (slot = 0; slot < tgsi->num_inputs; slot++) {
if (tgsi->inputs[slot].index == index)
return slot;
}
return -1;
}
/**
* Find the slot of the TGSI system value.
*/
static inline int
toy_tgsi_find_system_value(const struct toy_tgsi *tgsi, int index)
{
int slot;
for (slot = 0; slot < tgsi->num_system_values; slot++) {
if (tgsi->system_values[slot].index == index)
return slot;
}
return -1;
}
/**
* Return the immediate data of the TGSI immediate.
*/
static inline const uint32_t *
toy_tgsi_get_imm(const struct toy_tgsi *tgsi, unsigned index,
enum toy_type *type)
{
const uint32_t *imm;
if (index >= tgsi->imm_data.cur)
return NULL;
imm = tgsi->imm_data.buf[index];
if (type)
*type = tgsi->imm_data.types[index];
return imm;
}
void
toy_compiler_translate_tgsi(struct toy_compiler *tc,
const struct tgsi_token *tokens, bool aos,
struct toy_tgsi *tgsi);
void
toy_tgsi_cleanup(struct toy_tgsi *tgsi);
int
toy_tgsi_get_vrf(const struct toy_tgsi *tgsi,
enum tgsi_file_type file, int dimension, int index);
void
toy_tgsi_dump(const struct toy_tgsi *tgsi);
#endif /* TOY_TGSI_H */
|