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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
|
/*
* Copyright © 2023 Imagination Technologies Ltd.
*
* 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 (including the next
* paragraph) 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.
*/
#include <assert.h>
#include <stdint.h>
#include "pvr_uscgen.h"
#include "rogue/rogue.h"
#include "rogue/rogue_builder.h"
#include "util/u_dynarray.h"
void pvr_uscgen_tq_frag(const struct pvr_tq_shader_properties *shader_props,
struct pvr_tq_frag_sh_reg_layout *sh_reg_layout,
unsigned *temps_used,
struct util_dynarray *binary)
{
rogue_builder b;
rogue_shader *shader = rogue_shader_create(NULL, MESA_SHADER_NONE);
unsigned smp_coord_size = 2;
unsigned smp_coord_idx = 0;
rogue_regarray *smp_coords;
unsigned channels = 0;
unsigned output_idx = 1;
rogue_regarray *outputs = NULL;
unsigned image_state_size = 4;
unsigned image_state_idx;
rogue_regarray *image_state;
unsigned smp_state_size = 4;
unsigned smp_state_idx;
rogue_regarray *smp_state;
rogue_set_shader_name(shader, "TQ (fragment)");
rogue_builder_init(&b, shader);
rogue_push_block(&b);
smp_coords =
rogue_ssa_vec_regarray(b.shader, smp_coord_size, smp_coord_idx, 0);
/* TODO: Unrestrict. */
assert(shader_props->full_rate == false);
assert(shader_props->pick_component == false);
const struct pvr_tq_layer_properties *layer_props =
&shader_props->layer_props;
uint32_t loads;
/* TODO: Unrestrict. */
assert(layer_props->msaa == false);
assert(layer_props->sample_count == 1U);
assert(layer_props->resolve_op == PVR_RESOLVE_BLEND);
assert(layer_props->pbe_format == PVR_TRANSFER_PBE_PIXEL_SRC_RAW64 ||
layer_props->pbe_format == PVR_TRANSFER_PBE_PIXEL_SRC_RAW128);
assert(layer_props->sample == false);
assert(layer_props->layer_floats == PVR_INT_COORD_SET_FLOATS_0);
assert(layer_props->byte_unwind == 0);
assert(layer_props->linear == false);
loads = pvr_pbe_pixel_num_loads(layer_props->pbe_format);
for (uint32_t load = 0; load < loads; ++load) {
if (shader_props->iterated) {
/* TODO: feed{back,forward} the coeff index to/from shader_info. */
unsigned coeff_index = 0;
rogue_regarray *coeffs =
rogue_coeff_regarray(b.shader, smp_coord_size * 4, coeff_index);
rogue_instr *instr = &rogue_FITR_PIXEL(&b,
rogue_ref_regarray(smp_coords),
rogue_ref_drc(0),
rogue_ref_regarray(coeffs),
rogue_ref_val(smp_coord_size))
->instr;
rogue_add_instr_comment(instr, "load_iterated");
} else {
rogue_instr *instr;
rogue_regarray *smp_coord_x =
rogue_ssa_vec_regarray(b.shader, 1, smp_coord_idx, 0);
rogue_regarray *smp_coord_y =
rogue_ssa_vec_regarray(b.shader, 1, smp_coord_idx, 1);
/* (X,Y).P, pixel (X,Y) coordinates, pixel mode. */
rogue_reg *in_x = rogue_special_reg(b.shader, 97);
rogue_reg *in_y = rogue_special_reg(b.shader, 100);
instr =
&rogue_MOV(&b, rogue_ref_regarray(smp_coord_x), rogue_ref_reg(in_x))
->instr;
rogue_add_instr_comment(instr, "load_x");
instr =
&rogue_MOV(&b, rogue_ref_regarray(smp_coord_y), rogue_ref_reg(in_y))
->instr;
rogue_add_instr_comment(instr, "load_y");
}
if (!layer_props->msaa) {
} else {
unreachable("Unsupported layer property (MSAA).");
}
}
/* Source conversion. */
switch (layer_props->pbe_format) {
case PVR_TRANSFER_PBE_PIXEL_SRC_RAW64:
case PVR_TRANSFER_PBE_PIXEL_SRC_RAW128:
break;
default:
unreachable("Unsupported layer property (format).");
}
/* TODO: Select the texture_regs index appropriately. */
assert(sh_reg_layout->combined_image_samplers.count == 1);
image_state_idx = sh_reg_layout->combined_image_samplers.offsets[0].image;
image_state =
rogue_shared_regarray(b.shader, image_state_size, image_state_idx);
smp_state_idx = sh_reg_layout->combined_image_samplers.offsets[0].sampler;
smp_state = rogue_shared_regarray(b.shader, smp_state_size, smp_state_idx);
/* Pack/blend phase. */
rogue_backend_instr *smp2d;
switch (layer_props->pbe_format) {
case PVR_TRANSFER_PBE_PIXEL_SRC_RAW64:
case PVR_TRANSFER_PBE_PIXEL_SRC_RAW128: {
switch (layer_props->pbe_format) {
case PVR_TRANSFER_PBE_PIXEL_SRC_RAW64:
channels = 2;
break;
case PVR_TRANSFER_PBE_PIXEL_SRC_RAW128:
channels = 4;
break;
default:
unreachable("Unsupported layer property (format).");
}
outputs = rogue_ssa_vec_regarray(b.shader, channels, output_idx, 0);
smp2d = rogue_SMP2D(&b,
rogue_ref_regarray(outputs),
rogue_ref_drc(0),
rogue_ref_regarray(image_state),
rogue_ref_regarray(smp_coords),
rogue_ref_regarray(smp_state),
rogue_ref_io(ROGUE_IO_NONE),
rogue_ref_val(channels));
rogue_set_backend_op_mod(smp2d, ROGUE_BACKEND_OP_MOD_SLCWRITEBACK);
rogue_add_instr_comment(&smp2d->instr, "pack/blend");
if (!shader_props->iterated)
rogue_set_backend_op_mod(smp2d, ROGUE_BACKEND_OP_MOD_NNCOORDS);
break;
}
default:
unreachable("Unsupported layer property (format).");
}
assert(channels && outputs);
/* Copy outputs. */
for (unsigned u = 0; u < channels; ++u) {
rogue_regarray *output_elem =
rogue_ssa_vec_regarray(b.shader, 1, output_idx, u);
rogue_reg *pixout_elem = rogue_pixout_reg(b.shader, u);
rogue_MOV(&b,
rogue_ref_reg(pixout_elem),
rogue_ref_regarray(output_elem));
}
rogue_END(&b);
rogue_shader_passes(shader);
rogue_encode_shader(NULL, shader, binary);
*temps_used = rogue_count_used_regs(shader, ROGUE_REG_CLASS_TEMP);
sh_reg_layout->compiler_out.usc_constants.count = 0;
sh_reg_layout->compiler_out_total = 0;
ralloc_free(shader);
}
void pvr_uscgen_tq_eot(unsigned rt_count,
const uint64_t *pbe_regs,
struct util_dynarray *binary)
{
rogue_builder b;
rogue_shader *shader = rogue_shader_create(NULL, MESA_SHADER_NONE);
rogue_set_shader_name(shader, "TQ (EOT)");
rogue_builder_init(&b, shader);
rogue_push_block(&b);
rogue_backend_instr *emitpix = NULL;
for (unsigned u = 0; u < rt_count; ++u) {
if (u > 0)
rogue_WOP(&b);
rogue_reg *state_word_0 = rogue_shared_reg(shader, pbe_regs[u]);
rogue_reg *state_word_1 = rogue_shared_reg(shader, pbe_regs[u] + 1);
emitpix = rogue_EMITPIX(&b,
rogue_ref_reg(state_word_0),
rogue_ref_reg(state_word_1));
}
assert(emitpix);
rogue_set_backend_op_mod(emitpix, ROGUE_BACKEND_OP_MOD_FREEP);
rogue_END(&b);
rogue_shader_passes(shader);
rogue_encode_shader(NULL, shader, binary);
ralloc_free(shader);
}
|