Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/gallium/drivers/i915/i915_fpc.h
4570 views
1
/**************************************************************************
2
*
3
* Copyright 2003 VMware, Inc.
4
* All Rights Reserved.
5
*
6
* Permission is hereby granted, free of charge, to any person obtaining a
7
* copy of this software and associated documentation files (the
8
* "Software"), to deal in the Software without restriction, including
9
* without limitation the rights to use, copy, modify, merge, publish,
10
* distribute, sub license, and/or sell copies of the Software, and to
11
* permit persons to whom the Software is furnished to do so, subject to
12
* the following conditions:
13
*
14
* The above copyright notice and this permission notice (including the
15
* next paragraph) shall be included in all copies or substantial portions
16
* of the Software.
17
*
18
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21
* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
*
26
**************************************************************************/
27
28
#ifndef I915_FPC_H
29
#define I915_FPC_H
30
31
#include "i915_context.h"
32
#include "i915_reg.h"
33
34
#include "pipe/p_shader_tokens.h"
35
36
#include "tgsi/tgsi_parse.h"
37
38
#define I915_PROGRAM_SIZE 192
39
40
/* Use those indices for pos/face routing, must be >= num of inputs */
41
#define I915_SEMANTIC_POS 100
42
#define I915_SEMANTIC_FACE 101
43
44
/**
45
* Program translation state
46
*/
47
struct i915_fp_compile {
48
struct i915_fragment_shader *shader; /* the shader we're compiling */
49
50
bool used_constants[I915_MAX_CONSTANT];
51
52
/** maps TGSI immediate index to constant slot */
53
uint32_t num_immediates;
54
uint32_t immediates_map[I915_MAX_CONSTANT];
55
float immediates[I915_MAX_CONSTANT][4];
56
57
bool first_instruction;
58
59
uint32_t declarations[I915_PROGRAM_SIZE];
60
uint32_t program[I915_PROGRAM_SIZE];
61
62
uint32_t *csr; /**< Cursor, points into program. */
63
64
uint32_t *decl; /**< Cursor, points into declarations. */
65
66
uint32_t decl_s; /**< flags for which s regs need to be decl'd */
67
uint32_t decl_t; /**< flags for which t regs need to be decl'd */
68
69
uint32_t temp_flag; /**< Tracks temporary regs which are in use */
70
uint32_t utemp_flag; /**< Tracks TYPE_U temporary regs which are in use */
71
72
uint32_t register_phases[I915_MAX_TEMPORARY];
73
uint32_t nr_tex_indirect;
74
uint32_t nr_tex_insn;
75
uint32_t nr_alu_insn;
76
uint32_t nr_decl_insn;
77
78
bool log_program_errors;
79
bool error; /**< Set if i915_program_error() is called */
80
uint32_t NumNativeInstructions;
81
uint32_t NumNativeAluInstructions;
82
uint32_t NumNativeTexInstructions;
83
uint32_t NumNativeTexIndirections;
84
};
85
86
/* Having zero and one in here makes the definition of swizzle a lot
87
* easier.
88
*/
89
#define UREG_TYPE_SHIFT 29
90
#define UREG_NR_SHIFT 24
91
#define UREG_CHANNEL_X_NEGATE_SHIFT 23
92
#define UREG_CHANNEL_X_SHIFT 20
93
#define UREG_CHANNEL_Y_NEGATE_SHIFT 19
94
#define UREG_CHANNEL_Y_SHIFT 16
95
#define UREG_CHANNEL_Z_NEGATE_SHIFT 15
96
#define UREG_CHANNEL_Z_SHIFT 12
97
#define UREG_CHANNEL_W_NEGATE_SHIFT 11
98
#define UREG_CHANNEL_W_SHIFT 8
99
#define UREG_CHANNEL_ZERO_NEGATE_MBZ 5
100
#define UREG_CHANNEL_ZERO_SHIFT 4
101
#define UREG_CHANNEL_ONE_NEGATE_MBZ 1
102
#define UREG_CHANNEL_ONE_SHIFT 0
103
104
#define UREG_BAD 0xffffffff /* not a valid ureg */
105
106
#define X SRC_X
107
#define Y SRC_Y
108
#define Z SRC_Z
109
#define W SRC_W
110
#define ZERO SRC_ZERO
111
#define ONE SRC_ONE
112
113
/* Construct a ureg:
114
*/
115
#define UREG(type, nr) \
116
(((type) << UREG_TYPE_SHIFT) | ((nr) << UREG_NR_SHIFT) | \
117
(X << UREG_CHANNEL_X_SHIFT) | (Y << UREG_CHANNEL_Y_SHIFT) | \
118
(Z << UREG_CHANNEL_Z_SHIFT) | (W << UREG_CHANNEL_W_SHIFT) | \
119
(ZERO << UREG_CHANNEL_ZERO_SHIFT) | (ONE << UREG_CHANNEL_ONE_SHIFT))
120
121
#define GET_CHANNEL_SRC(reg, channel) ((reg << (channel * 4)) & (0xf << 20))
122
#define CHANNEL_SRC(src, channel) (src >> (channel * 4))
123
124
#define GET_UREG_TYPE(reg) (((reg) >> UREG_TYPE_SHIFT) & REG_TYPE_MASK)
125
#define GET_UREG_NR(reg) (((reg) >> UREG_NR_SHIFT) & REG_NR_MASK)
126
127
#define UREG_XYZW_CHANNEL_MASK 0x00ffff00
128
129
/* One neat thing about the UREG representation:
130
*/
131
static inline int
132
swizzle(int reg, uint32_t x, uint32_t y, uint32_t z, uint32_t w)
133
{
134
assert(x <= SRC_ONE);
135
assert(y <= SRC_ONE);
136
assert(z <= SRC_ONE);
137
assert(w <= SRC_ONE);
138
return ((reg & ~UREG_XYZW_CHANNEL_MASK) |
139
CHANNEL_SRC(GET_CHANNEL_SRC(reg, x), 0) |
140
CHANNEL_SRC(GET_CHANNEL_SRC(reg, y), 1) |
141
CHANNEL_SRC(GET_CHANNEL_SRC(reg, z), 2) |
142
CHANNEL_SRC(GET_CHANNEL_SRC(reg, w), 3));
143
}
144
145
#define A0_DEST(reg) (((reg)&UREG_TYPE_NR_MASK) >> UREG_A0_DEST_SHIFT_LEFT)
146
#define D0_DEST(reg) (((reg)&UREG_TYPE_NR_MASK) >> UREG_A0_DEST_SHIFT_LEFT)
147
#define T0_DEST(reg) (((reg)&UREG_TYPE_NR_MASK) >> UREG_A0_DEST_SHIFT_LEFT)
148
#define A0_SRC0(reg) (((reg)&UREG_MASK) >> UREG_A0_SRC0_SHIFT_LEFT)
149
#define A1_SRC0(reg) (((reg)&UREG_MASK) << UREG_A1_SRC0_SHIFT_RIGHT)
150
#define A1_SRC1(reg) (((reg)&UREG_MASK) >> UREG_A1_SRC1_SHIFT_LEFT)
151
#define A2_SRC1(reg) (((reg)&UREG_MASK) << UREG_A2_SRC1_SHIFT_RIGHT)
152
#define A2_SRC2(reg) (((reg)&UREG_MASK) >> UREG_A2_SRC2_SHIFT_LEFT)
153
154
/* These are special, and don't have swizzle/negate bits.
155
*/
156
#define T0_SAMPLER(reg) (GET_UREG_NR(reg) << T0_SAMPLER_NR_SHIFT)
157
#define T1_ADDRESS_REG(reg) \
158
((GET_UREG_NR(reg) << T1_ADDRESS_REG_NR_SHIFT) | \
159
(GET_UREG_TYPE(reg) << T1_ADDRESS_REG_TYPE_SHIFT))
160
161
/* Macros for translating UREG's into the various register fields used
162
* by the I915 programmable unit.
163
*/
164
#define UREG_A0_DEST_SHIFT_LEFT (UREG_TYPE_SHIFT - A0_DEST_TYPE_SHIFT)
165
#define UREG_A0_SRC0_SHIFT_LEFT (UREG_TYPE_SHIFT - A0_SRC0_TYPE_SHIFT)
166
#define UREG_A1_SRC0_SHIFT_RIGHT \
167
(A1_SRC0_CHANNEL_W_SHIFT - UREG_CHANNEL_W_SHIFT)
168
#define UREG_A1_SRC1_SHIFT_LEFT (UREG_TYPE_SHIFT - A1_SRC1_TYPE_SHIFT)
169
#define UREG_A2_SRC1_SHIFT_RIGHT \
170
(A2_SRC1_CHANNEL_W_SHIFT - UREG_CHANNEL_W_SHIFT)
171
#define UREG_A2_SRC2_SHIFT_LEFT (UREG_TYPE_SHIFT - A2_SRC2_TYPE_SHIFT)
172
173
#define UREG_MASK 0xffffff00
174
#define UREG_TYPE_NR_MASK \
175
((REG_TYPE_MASK << UREG_TYPE_SHIFT) | (REG_NR_MASK << UREG_NR_SHIFT))
176
177
/***********************************************************************
178
* Public interface for the compiler
179
*/
180
extern void i915_translate_fragment_program(struct i915_context *i915,
181
struct i915_fragment_shader *fs);
182
183
extern uint32_t i915_get_temp(struct i915_fp_compile *p);
184
extern uint32_t i915_get_utemp(struct i915_fp_compile *p);
185
extern void i915_release_utemps(struct i915_fp_compile *p);
186
187
extern uint32_t i915_emit_texld(struct i915_fp_compile *p, uint32_t dest,
188
uint32_t destmask, uint32_t sampler,
189
uint32_t coord, uint32_t op,
190
uint32_t num_coord);
191
192
extern uint32_t i915_emit_arith(struct i915_fp_compile *p, uint32_t op,
193
uint32_t dest, uint32_t mask, uint32_t saturate,
194
uint32_t src0, uint32_t src1, uint32_t src2);
195
196
extern uint32_t i915_emit_decl(struct i915_fp_compile *p, uint32_t type,
197
uint32_t nr, uint32_t d0_flags);
198
199
extern uint32_t i915_emit_const1f(struct i915_fp_compile *p, float c0);
200
201
extern uint32_t i915_emit_const2f(struct i915_fp_compile *p, float c0,
202
float c1);
203
204
extern uint32_t i915_emit_const4fv(struct i915_fp_compile *p, const float *c);
205
206
extern uint32_t i915_emit_const4f(struct i915_fp_compile *p, float c0, float c1,
207
float c2, float c3);
208
209
/*======================================================================
210
* i915_fpc_translate.c
211
*/
212
213
extern void i915_program_error(struct i915_fp_compile *p, const char *msg, ...);
214
215
/*======================================================================
216
* i915_fpc_optimize.c
217
*/
218
219
struct i915_src_register {
220
unsigned File : 4; /* TGSI_FILE_ */
221
unsigned Indirect : 1; /* BOOL */
222
unsigned Dimension : 1; /* BOOL */
223
int Index : 16; /* SINT */
224
unsigned SwizzleX : 3; /* TGSI_SWIZZLE_ */
225
unsigned SwizzleY : 3; /* TGSI_SWIZZLE_ */
226
unsigned SwizzleZ : 3; /* TGSI_SWIZZLE_ */
227
unsigned SwizzleW : 3; /* TGSI_SWIZZLE_ */
228
unsigned Absolute : 1; /* BOOL */
229
unsigned Negate : 1; /* BOOL */
230
};
231
232
/* Additional swizzle supported in i915 */
233
#define TGSI_SWIZZLE_ZERO 4
234
#define TGSI_SWIZZLE_ONE 5
235
236
struct i915_dst_register {
237
unsigned File : 4; /* TGSI_FILE_ */
238
unsigned WriteMask : 4; /* TGSI_WRITEMASK_ */
239
unsigned Indirect : 1; /* BOOL */
240
unsigned Dimension : 1; /* BOOL */
241
int Index : 16; /* SINT */
242
unsigned Padding : 6;
243
};
244
245
struct i915_full_dst_register {
246
struct i915_dst_register Register;
247
/*
248
struct tgsi_ind_register Indirect;
249
struct tgsi_dimension Dimension;
250
struct tgsi_ind_register DimIndirect;
251
*/
252
};
253
254
struct i915_full_src_register {
255
struct i915_src_register Register;
256
/*
257
struct tgsi_ind_register Indirect;
258
struct tgsi_dimension Dimension;
259
struct tgsi_ind_register DimIndirect;
260
*/
261
};
262
263
struct i915_full_instruction {
264
struct tgsi_instruction Instruction;
265
/*
266
struct tgsi_instruction_label Label;
267
*/
268
struct tgsi_instruction_texture Texture;
269
struct i915_full_dst_register Dst[1];
270
struct i915_full_src_register Src[3];
271
};
272
273
union i915_full_token {
274
struct tgsi_token Token;
275
struct tgsi_full_declaration FullDeclaration;
276
struct tgsi_full_immediate FullImmediate;
277
struct i915_full_instruction FullInstruction;
278
struct tgsi_full_property FullProperty;
279
};
280
281
struct i915_token_list {
282
union i915_full_token *Tokens;
283
unsigned NumTokens;
284
};
285
286
extern struct i915_token_list *i915_optimize(const struct tgsi_token *tokens);
287
288
extern void i915_optimize_free(struct i915_token_list *tokens);
289
290
extern uint32_t i915_num_coords(uint32_t tex);
291
292
#endif
293
294