Debian Codegraph @

src/imagination/vulkan/pds/pvr_pipeline_pds.c

raw
1 /*
2 * Copyright © 2022 Imagination Technologies Ltd.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 */
23
24 #include <assert.h>
25 #include <stdbool.h>
26 #include <stdint.h>
27 #include <stdio.h>
28 #include <string.h>
29
30 #include "pvr_device_info.h"
31 #include "pvr_pds.h"
32 #include "pvr_rogue_pds_defs.h"
33 #include "pvr_rogue_pds_disasm.h"
34 #include "pvr_rogue_pds_encode.h"
35 #include "pvr_types.h"
36 #include "util/log.h"
37 #include "util/macros.h"
38
39 #define R32_C(x) ((x) + PVR_ROGUE_PDSINST_REGS32_CONST32_LOWER)
40 #define R32_T(x) ((x) + PVR_ROGUE_PDSINST_REGS32_TEMP32_LOWER)
41 #define R32_P(x) ((x) + PVR_ROGUE_PDSINST_REGS32_PTEMP32_LOWER)
42
43 #define R32TP_T(x) ((x) + PVR_ROGUE_PDSINST_REGS32TP_TEMP32_LOWER)
44 #define R32TP_P(x) ((x) + PVR_ROGUE_PDSINST_REGS32TP_PTEMP32_LOWER)
45
46 #define R64_C(x) ((x) + PVR_ROGUE_PDSINST_REGS64_CONST64_LOWER)
47 #define R64_T(x) ((x) + PVR_ROGUE_PDSINST_REGS64_TEMP64_LOWER)
48 #define R64_P(x) ((x) + PVR_ROGUE_PDSINST_REGS64_PTEMP64_LOWER)
49
50 #define R64TP_T(x) ((x) + PVR_ROGUE_PDSINST_REGS64TP_TEMP64_LOWER)
51 #define R64TP_P(x) ((x) + PVR_ROGUE_PDSINST_REGS64TP_PTEMP64_LOWER)
52
53 /* 32-bit PTemp index for draw indirect base instance. */
54 #define PVR_INDIRECT_BASE_INSTANCE_PTEMP 1U
55
56 /* Number of constants to reserve per DDMAD instruction in the PDS Vertex. */
57 #define PVR_PDS_DDMAD_NUM_CONSTS 8
58
59 #if defined(TRACE_PDS)
60 /* Some macros for a pretty printing. */
61
62 # define pvr_debug_pds_const(reg, size, annotation) \
63 mesa_logd("const[%d] @ (%dbits) %s", reg, size, annotation)
64 # define pvr_debug_pds_temp(reg, size, annotation) \
65 mesa_logd("temp[%d] @ (%dbits) %s", reg, size, annotation)
66 # define pvr_debug_pds_note(...) mesa_logd(" // " __VA_ARGS__)
67 # define pvr_debug_pds_flag(flags, flag) \
68 { \
69 if ((flags & flag) == flag) \
70 mesa_logd(" > " #flag); \
71 }
72 # define pvr_debug(annotation) mesa_logd(annotation)
73
74 #else
75 # define pvr_debug_pds_const(reg, size, annotation)
76 # define pvr_debug_pds_temp(reg, size, annotation)
77 # define pvr_debug_pds_note(...)
78 # define pvr_debug_pds_flag(flags, flag)
79 # define pvr_debug(annotation)
80 #endif
81
82 struct pvr_pds_const_map_entry_write_state {
83 const struct pvr_pds_info *PDS_info;
84 struct pvr_const_map_entry *entry;
85 size_t size_of_last_entry_in_bytes;
86 uint32_t entry_count;
87 size_t entries_size_in_bytes;
88 };
89
90 static void pvr_init_pds_const_map_entry_write_state(
91 struct pvr_pds_info *PDS_info,
92 struct pvr_pds_const_map_entry_write_state *entry_write_state)
93 {
94 entry_write_state->PDS_info = PDS_info;
95 entry_write_state->entry = PDS_info->entries;
96 entry_write_state->size_of_last_entry_in_bytes = 0;
97 entry_write_state->entry_count = 0;
98 entry_write_state->entries_size_in_bytes = 0;
99 }
100
101 /* Returns a pointer to the next struct pvr_const_map_entry. */
102 static void *pvr_prepare_next_pds_const_map_entry(
103 struct pvr_pds_const_map_entry_write_state *entry_write_state,
104 size_t size_of_next_entry_in_bytes)
105 {
106 /* Move on to the next entry. */
107 uint8_t *next_entry = ((uint8_t *)entry_write_state->entry +
108 entry_write_state->size_of_last_entry_in_bytes);
109 entry_write_state->entry = (struct pvr_const_map_entry *)next_entry;
110
111 entry_write_state->size_of_last_entry_in_bytes = size_of_next_entry_in_bytes;
112 entry_write_state->entry_count++;
113 entry_write_state->entries_size_in_bytes += size_of_next_entry_in_bytes;
114
115 /* Check if we can write into the next entry. */
116 assert(entry_write_state->entries_size_in_bytes <=
117 entry_write_state->PDS_info->entries_size_in_bytes);
118
119 return entry_write_state->entry;
120 }
121
122 static void pvr_write_pds_const_map_entry_vertex_attribute_address(
123 struct pvr_pds_const_map_entry_write_state *entry_write_state,
124 const struct pvr_pds_vertex_dma *DMA,
125 uint32_t const_val,
126 bool use_robust_vertex_fetch)
127 {
128 pvr_debug_pds_note("DMA %d dwords, stride %d, offset %d, bindingIdx %d",
129 DMA->size_in_dwords,
130 DMA->stride,
131 DMA->offset,
132 DMA->binding_index);
133
134 if (use_robust_vertex_fetch) {
135 struct pvr_const_map_entry_robust_vertex_attribute_address
136 *robust_attribute_entry;
137
138 robust_attribute_entry =
139 pvr_prepare_next_pds_const_map_entry(entry_write_state,
140 sizeof(*robust_attribute_entry));
141 robust_attribute_entry->type =
142 PVR_PDS_CONST_MAP_ENTRY_TYPE_ROBUST_VERTEX_ATTRIBUTE_ADDRESS;
143 robust_attribute_entry->const_offset = const_val;
144 robust_attribute_entry->binding_index = DMA->binding_index;
145 robust_attribute_entry->attrib_size_in_bytes = DMA->attrib_size_in_bytes;
146 robust_attribute_entry->offset = DMA->offset;
147 robust_attribute_entry->stride = DMA->stride;
148 robust_attribute_entry->size_in_dwords = DMA->size_in_dwords;
149 robust_attribute_entry->robustness_buffer_offset =
150 DMA->robustness_buffer_offset;
151 } else {
152 struct pvr_const_map_entry_vertex_attribute_address *attribute_entry;
153
154 attribute_entry =
155 pvr_prepare_next_pds_const_map_entry(entry_write_state,
156 sizeof(*attribute_entry));
157 attribute_entry->type =
158 PVR_PDS_CONST_MAP_ENTRY_TYPE_VERTEX_ATTRIBUTE_ADDRESS;
159 attribute_entry->const_offset = const_val;
160 attribute_entry->binding_index = DMA->binding_index;
161 attribute_entry->offset = DMA->offset;
162 attribute_entry->stride = DMA->stride;
163 attribute_entry->size_in_dwords = DMA->size_in_dwords;
164 }
165 }
166
167 static ALWAYS_INLINE uint32_t pvr_pds_encode_doutu(uint32_t cc,
168 uint32_t end,
169 uint32_t src0)
170 {
171 return pvr_pds_inst_encode_dout(cc,
172 end,
173 0,
174 src0,
175 PVR_ROGUE_PDSINST_DSTDOUT_DOUTU);
176 }
177
178 static uint32_t
179 pvr_encode_burst(struct pvr_pds_const_map_entry_write_state *entry_write_state,
180 bool last_dma,
181 bool halt,
182 unsigned int const32,
183 unsigned int const64,
184 unsigned int dma_size_in_dwords,
185 unsigned int destination,
186 unsigned int store)
187 {
188 uint32_t literal_value;
189
190 /* Encode literal value. */
191 literal_value = dma_size_in_dwords
192 << PVR_ROGUE_PDSINST_DOUT_FIELDS_DOUTD_SRC1_BSIZE_SHIFT;
193 literal_value |= destination
194 << PVR_ROGUE_PDSINST_DOUT_FIELDS_DOUTD_SRC1_AO_SHIFT;
195 literal_value |= PVR_ROGUE_PDSINST_DOUT_FIELDS_DOUTD_SRC1_CMODE_CACHED |
196 store;
197
198 if (last_dma)
199 literal_value |= PVR_ROGUE_PDSINST_DOUT_FIELDS_DOUTD_SRC1_LAST_EN;
200
201 /* Create const map entry. */
202 struct pvr_const_map_entry_literal32 *literal_entry;
203
204 literal_entry = pvr_prepare_next_pds_const_map_entry(entry_write_state,
205 sizeof(*literal_entry));
206 literal_entry->type = PVR_PDS_CONST_MAP_ENTRY_TYPE_LITERAL32;
207 literal_entry->const_offset = const32;
208 literal_entry->literal_value = literal_value;
209
210 /* Encode DOUTD */
211 return pvr_pds_inst_encode_dout(0,
212 halt,
213 R32_C(const32),
214 R64_C(const64),
215 PVR_ROGUE_PDSINST_DSTDOUT_DOUTD);
216 }
217
218 #define pvr_encode_burst_cs(psDataEntry, \
219 last_dma, \
220 halt, \
221 const32, \
222 const64, \
223 dma_size_in_dwords, \
224 destination) \
225 pvr_encode_burst( \
226 psDataEntry, \
227 last_dma, \
228 halt, \
229 const32, \
230 const64, \
231 dma_size_in_dwords, \
232 destination, \
233 PVR_ROGUE_PDSINST_DOUT_FIELDS_DOUTW_SRC1_DEST_COMMON_STORE)
234
235 static uint32_t pvr_encode_direct_write(
236 struct pvr_pds_const_map_entry_write_state *entry_write_state,
237 bool last_dma,
238 bool halt,
239 unsigned int const32,
240 unsigned int const64,
241 uint32_t data_mask,
242 unsigned int destination,
243 uint32_t destination_store,
244 const struct pvr_device_info *dev_info)
245 {
246 struct pvr_const_map_entry_literal32 *literal_entry;
247
248 uint32_t instruction =
249 pvr_pds_inst_encode_dout(0,
250 halt,
251 const32,
252 const64,
253 PVR_ROGUE_PDSINST_DSTDOUT_DOUTW);
254
255 literal_entry = pvr_prepare_next_pds_const_map_entry(entry_write_state,
256 sizeof(*literal_entry));
257 literal_entry->type = PVR_PDS_CONST_MAP_ENTRY_TYPE_LITERAL32;
258 literal_entry->const_offset = const32;
259 literal_entry->literal_value = destination_store;
260
261 if (PVR_HAS_FEATURE(dev_info, slc_mcu_cache_controls)) {
262 literal_entry->literal_value |=
263 PVR_ROGUE_PDSINST_DOUT_FIELDS_DOUTW_SRC1_CMODE_CACHED;
264 }
265
266 literal_entry->literal_value |=
267 destination << PVR_ROGUE_PDSINST_DOUT_FIELDS_DOUTW_SRC1_AO_SHIFT;
268
269 if (data_mask == 0x1) {
270 literal_entry->literal_value |=
271 PVR_ROGUE_PDSINST_DOUT_FIELDS_DOUTW_SRC1_BSIZE_LOWER;
272 } else if (data_mask == 0x2) {
273 literal_entry->literal_value |=
274 PVR_ROGUE_PDSINST_DOUT_FIELDS_DOUTW_SRC1_BSIZE_UPPER;
275 } else {
276 literal_entry->literal_value |=
277 PVR_ROGUE_PDSINST_DOUT_FIELDS_DOUTW_SRC1_BSIZE_ALL64;
278 }
279
280 if (last_dma) {
281 literal_entry->literal_value |=
282 PVR_ROGUE_PDSINST_DOUT_FIELDS_DOUTW_SRC1_LAST_EN;
283 }
284
285 return instruction;
286 }
287
288 /* Constant and Temporary register allocation
289 * - reserve space for a 32-bit register or a 64-bit register
290 * - returned indices are offsets to 32-bit register locations
291 * - 64-bit registers need to be aligned to even indices.
292 */
293 #define RESERVE_32BIT 1U
294 #define RESERVE_64BIT 2U
295
296 #if MESA_DEBUG
297 # define pvr_find_constant(usage, words, name) \
298 pvr_find_constant2(usage, words, name)
299 # define pvr_get_temps(usage, words, name) pvr_get_temps2(usage, words, name)
300 #else
301 # define pvr_find_constant(usage, words, name) \
302 pvr_find_constant2(usage, words, NULL);
303 # define pvr_get_temps(usage, words, name) pvr_get_temps2(usage, words, NULL)
304 #endif
305
306 static uint32_t
307 pvr_find_constant2(uint8_t *const_usage, uint8_t words, const char *const_name)
308 {
309 uint32_t const_index = ~0;
310 uint32_t step = words;
311 uint8_t mask = (1 << words) - 1;
312
313 assert(words == 1 || words == 2);
314
315 /* Find a register at 'step' alignment that satisfies the mask. */
316 for (uint32_t i = 0; i < PVR_MAX_VERTEX_ATTRIB_DMAS; i++) {
317 for (uint32_t b = 0; b < PVR_PDS_DDMAD_NUM_CONSTS; b += step) {
318 if ((const_usage[i] & (mask << b)) != 0)
319 continue;
320 const_usage[i] |= (mask << b);
321 const_index = i * 8 + b;
322 pvr_debug_pds_const(const_index, words * 32, const_name);
323 return const_index;
324 }
325 }
326
327 UNREACHABLE("Unexpected: Space cannot be found for constant");
328 return ~0;
329 }
330
331 #define PVR_MAX_PDS_TEMPS 32
332 struct pvr_temp_usage {
333 uint32_t temp_usage;
334 uint8_t temp_used;
335 uint8_t temps_needed;
336 };
337
338 #define PVR_INVALID_TEMP UINT8_C(~0)
339
340 static uint8_t pvr_get_temps2(struct pvr_temp_usage *temps,
341 uint8_t temps_needed,
342 const char *temp_name)
343 {
344 uint8_t step = temps_needed;
345 uint8_t mask = (1 << temps_needed) - 1;
346
347 assert(temps_needed == 1 || temps_needed == 2);
348 assert(temps->temp_used + temps_needed <= PVR_MAX_PDS_TEMPS);
349
350 for (uint8_t i = 0; i < PVR_MAX_PDS_TEMPS; i += step) {
351 if ((temps->temp_usage & (mask << i)) != 0)
352 continue;
353
354 const size_t clzBits = 8 * sizeof(unsigned int);
355
356 temps->temp_usage |= (mask << i);
357 temps->temp_used += temps_needed;
358 temps->temps_needed =
359 clzBits - __builtin_clz((unsigned int)temps->temp_usage);
360
361 pvr_debug_pds_temp(i, temps_needed * 32, temp_name);
362
363 return i;
364 }
365
366 UNREACHABLE("Unexpected: Space cannot be found for temps");
367 return PVR_INVALID_TEMP;
368 }
369
370 /**
371 * Wrapper macro to add a toggle for "data mode", allowing us to calculate the
372 * size of a PDS program without actually attempting to store it.
373 *
374 * \param dest The array/memory pointer where the PDS program should be stored.
375 * If the given code is NULL, automatically switch to count mode
376 * instead of attempting to fill in unallocated memory.
377 * \param counter The local counter that holds the total instruction count.
378 * \param statement What function call/value should be stored at dest[counter]
379 * when condition is false.
380 */
381
382 #define PVR_PDS_MODE_TOGGLE(dest, counter, statement) \
383 if (!dest) { \
384 counter++; \
385 } else { \
386 dest[counter++] = statement; \
387 PVR_PDS_PRINT_INST(statement); \
388 }
389
390 /**
391 * Generates the PDS vertex primary program for the dma's listed in the input
392 * structure. Produces the constant map for the Vulkan driver based upon the
393 * requirements of the instructions added to the program.
394 *
395 * PDS Data Layout
396 * ---------------
397 *
398 * The PDS data is optimized for the DDMAD layout, with the data for those
399 * instructions laid out first. The data required for other instructions is laid
400 * out in the entries unused by the DDMADs.
401 *
402 * DDMAD layout
403 * \verbatim
404 * bank | index | usage
405 * 0 | 0:1 | temps (current index)[-]
406 * 2 | 2:3 | stride[32]
407 * 1 | 4:5 | base address[64]
408 * 3 | 6:7 | ctrl[64]
409 * \endverbatim
410 *
411 * Each DMA whose stride > 0 requires one entry, laid out as above. We stride
412 * over the banks to ensure that each ddmad reads each of its operands from a
413 * different bank (i.e. remove bank clashes)
414 *
415 * Note: This is "wasting" const[0:1] and const[2], however these free
416 * registers will be used by other, non-ddmad instructions.
417 *
418 * The const register usage is maintained in the au8ConstUsage array, the
419 * DDMAD instructions, for example, will utilize the top 5 registers in each
420 * block of 8 hence a 'usage mask' of 0xF8 (0b11111000).
421 *
422 * Constant Map
423 * ------------
424 *
425 * The constant map is built up as we add PDS instructions and passed back
426 * for the driver to fill in the PDS data section with the correct parameters
427 * for each draw call.
428 *
429 * \param input_program PDS Program description.
430 * \param code Buffer to be filled in with the PDS program. If NULL is provided,
431 * automatically switch to count-mode, preventing writes to
432 * unallocated memory.
433 * \param info PDS info structure filled in for the driver, contains the
434 * constant map.
435 * \param use_robust_vertex_fetch Do vertex fetches apply range checking.
436 * \param dev_info pvr device information struct.
437 */
438 void pvr_pds_generate_vertex_primary_program(
439 struct pvr_pds_vertex_primary_program_input *input_program,
440 uint32_t *code,
441 struct pvr_pds_info *info,
442 bool use_robust_vertex_fetch,
443 const struct pvr_device_info *dev_info)
444 {
445 struct pvr_pds_const_map_entry_write_state entry_write_state;
446 struct pvr_const_map_entry_doutu_address *doutu_address_entry;
447
448 uint32_t instruction = 0; /* index into code */
449 uint32_t index; /* index used for current attribute, either vertex or
450 * instance.
451 */
452
453 uint32_t total_dma_count = 0;
454 uint32_t running_dma_count = 0;
455
456 uint32_t write_instance_control = ~0;
457 uint32_t write_vertex_control = ~0;
458 uint32_t write_base_instance_control = ~0;
459 uint32_t write_base_vertex_control = ~0;
460 uint32_t pvr_write_draw_index_control = ~0;
461 uint32_t write_view_index_control = ~0;
462
463 uint32_t ddmad_count = 0;
464 uint32_t doutw_count = 0;
465
466 uint32_t base_instance = 0;
467 uint32_t base_vertex = 0;
468 uint32_t draw_index = 0;
469
470 uint8_t const_usage[PVR_MAX_VERTEX_ATTRIB_DMAS] = { 0 };
471
472 struct pvr_temp_usage temp_usage = { 0 };
473
474 uint32_t zero_temp = PVR_INVALID_TEMP;
475
476 uint32_t max_index_temp = PVR_INVALID_TEMP;
477 uint32_t current_index_temp = PVR_INVALID_TEMP;
478
479 uint32_t index_id_temp = PVR_INVALID_TEMP;
480 uint32_t base_instance_ID_temp = PVR_INVALID_TEMP;
481 uint32_t instance_ID_temp = PVR_INVALID_TEMP;
482
483 /* Debug tracing of program flags. */
484 pvr_debug("pvr_pds_generate_vertex_primary_program");
485 pvr_debug("=================================================");
486 pvr_debug_pds_flag(input_program->flags,
487 PVR_PDS_VERTEX_FLAGS_VERTEX_ID_REQUIRED);
488 pvr_debug_pds_flag(input_program->flags,
489 PVR_PDS_VERTEX_FLAGS_INSTANCE_ID_REQUIRED);
490 pvr_debug_pds_flag(input_program->flags,
491 PVR_PDS_VERTEX_FLAGS_DRAW_INDIRECT_VARIANT);
492 pvr_debug_pds_flag(input_program->flags,
493 PVR_PDS_VERTEX_FLAGS_BASE_INSTANCE_VARIANT);
494 pvr_debug_pds_flag(input_program->flags,
495 PVR_PDS_VERTEX_FLAGS_BASE_INSTANCE_REQUIRED);
496 pvr_debug_pds_flag(input_program->flags,
497 PVR_PDS_VERTEX_FLAGS_BASE_VERTEX_REQUIRED);
498 pvr_debug_pds_flag(input_program->flags,
499 PVR_PDS_VERTEX_FLAGS_DRAW_INDEX_REQUIRED);
500 pvr_debug_pds_flag(input_program->flags,
501 PVR_PDS_VERTEX_FLAGS_VIEW_INDEX_REQUIRED);
502 pvr_debug(" ");
503
504 pvr_init_pds_const_map_entry_write_state(info, &entry_write_state);
505
506 /* At a minimum we need 2 dwords for the DOUTU, but since we allocate in
507 * blocks of 4 we can reserve dwords for the instance/vertex DOUTW.
508 */
509 info->data_size_in_dwords = 4;
510
511 /* Reserve 2 temps - these are automatically filled in by the VDM
512 *
513 * For instanced draw calls we manually increment the instance id by the
514 * base-instance offset which is either provided as a constant, or in a
515 * ptemp (for draw indirect)
516 *
517 * temp - contents
518 * ---------------
519 * 0 - index id (pre-filled)
520 * 1 - base instance + instance id
521 */
522 index_id_temp = pvr_get_temps(&temp_usage, RESERVE_32BIT, "VDM Index id");
523 instance_ID_temp =
524 pvr_get_temps(&temp_usage, RESERVE_32BIT, "VDM Instance id");
525
526 /* Reserve the lowest 2 dwords for DOUTU.
527 * [------XX]
528 */
529 const_usage[0] = 0x03;
530
531 /* Reserve consts for all the DDMAD's. */
532 for (uint32_t dma = 0; dma < input_program->dma_count; dma++) {
533 /* Mark the consts required by this ddmad "in-use".
534 * [XXXXX---]
535 */
536 const_usage[ddmad_count++] |= 0xf8;
537 }
538
539 /* Start off by assuming we can fit everything in the 8 dwords/ddmad
540 * footprint, if any DOUTD/DOUTW falls outside we will increase this
541 * counter.
542 */
543 if (ddmad_count)
544 info->data_size_in_dwords = PVR_PDS_DDMAD_NUM_CONSTS * ddmad_count;
545
546 if (input_program->flags & PVR_PDS_VERTEX_FLAGS_VERTEX_ID_REQUIRED) {
547 doutw_count++;
548 write_vertex_control =
549 pvr_find_constant(const_usage, RESERVE_32BIT, "Vertex id DOUTW Ctrl");
550 }
551
552 if (input_program->flags & PVR_PDS_VERTEX_FLAGS_INSTANCE_ID_REQUIRED) {
553 doutw_count++;
554 write_instance_control = pvr_find_constant(const_usage,
555 RESERVE_32BIT,
556 "Instance id DOUTW Ctrl");
557 }
558
559 if (input_program->flags & PVR_PDS_VERTEX_FLAGS_BASE_INSTANCE_REQUIRED) {
560 doutw_count++;
561 write_base_instance_control =
562 pvr_find_constant(const_usage,
563 RESERVE_32BIT,
564 "Base Instance DOUTW Ctrl");
565 }
566
567 if (input_program->flags & PVR_PDS_VERTEX_FLAGS_BASE_VERTEX_REQUIRED) {
568 doutw_count++;
569 write_base_vertex_control = pvr_find_constant(const_usage,
570 RESERVE_32BIT,
571 "Base Vertex DOUTW Ctrl");
572
573 /* Load base vertex from constant for non-indirect variants. */
574 if ((input_program->flags & PVR_PDS_VERTEX_FLAGS_DRAW_INDIRECT_VARIANT) ==
575 0) {
576 struct pvr_const_map_entry_base_vertex *psBaseVertexEntry =
577 (struct pvr_const_map_entry_base_vertex *)entry_write_state.entry;
578
579 base_vertex =
580 pvr_find_constant(const_usage, RESERVE_32BIT, "base_vertex");
581
582 psBaseVertexEntry =
583 pvr_prepare_next_pds_const_map_entry(&entry_write_state,
584 sizeof(*psBaseVertexEntry));
585 psBaseVertexEntry->type = PVR_PDS_CONST_MAP_ENTRY_TYPE_BASE_VERTEX;
586 psBaseVertexEntry->const_offset = base_vertex;
587 }
588 }
589
590 if (input_program->flags & PVR_PDS_VERTEX_FLAGS_DRAW_INDEX_REQUIRED) {
591 doutw_count++;
592 pvr_write_draw_index_control =
593 pvr_find_constant(const_usage, RESERVE_32BIT, "Draw Index DOUTW Ctrl");
594
595 /* Set draw index to 0 for non-indirect variants. */
596 if ((input_program->flags & PVR_PDS_VERTEX_FLAGS_DRAW_INDIRECT_VARIANT) ==
597 0) {
598 struct pvr_const_map_entry_literal32 *literal_entry;
599
600 draw_index =
601 pvr_find_constant(const_usage, RESERVE_32BIT, "draw_index");
602
603 literal_entry =
604 pvr_prepare_next_pds_const_map_entry(&entry_write_state,
605 sizeof(*literal_entry));
606 literal_entry->type = PVR_PDS_CONST_MAP_ENTRY_TYPE_LITERAL32;
607 literal_entry->const_offset = draw_index;
608 literal_entry->literal_value = 0;
609 }
610 }
611
612 if (input_program->flags & PVR_PDS_VERTEX_FLAGS_VIEW_INDEX_REQUIRED) {
613 doutw_count++;
614 write_view_index_control =
615 pvr_find_constant(const_usage, RESERVE_32BIT, "View index DOUTW Ctrl");
616 }
617
618 if (input_program->flags & PVR_PDS_VERTEX_FLAGS_DRAW_INDIRECT_VARIANT) {
619 /* Load absolute instance id into uiInstanceIdTemp. */
620 PVR_PDS_MODE_TOGGLE(
621 code,
622 instruction,
623 pvr_pds_inst_encode_add32(
624 /* cc */ 0,
625 /* alum */ 0,
626 /* sna */ 0,
627 /* src0 */ R32_P(PVR_INDIRECT_BASE_INSTANCE_PTEMP),
628 /* src1 */ R32_T(instance_ID_temp),
629 /* dst */ R32TP_T(instance_ID_temp)));
630 } else if (input_program->flags &
631 PVR_PDS_VERTEX_FLAGS_BASE_INSTANCE_VARIANT) {
632 struct pvr_const_map_entry_base_instance *base_instance_entry =
633 (struct pvr_const_map_entry_base_instance *)entry_write_state.entry;
634
635 base_instance =
636 pvr_find_constant(const_usage, RESERVE_32BIT, "base_instance");
637
638 PVR_PDS_MODE_TOGGLE(code,
639 instruction,
640 pvr_pds_inst_encode_add32(
641 /* cc */ 0,
642 /* alum */ 0,
643 /* sna */ 0,
644 /* src0 */ R32_C(base_instance),
645 /* src1 */ R32_T(instance_ID_temp),
646 /* dst */ R32TP_T(instance_ID_temp)));
647
648 base_instance_entry =
649 pvr_prepare_next_pds_const_map_entry(&entry_write_state,
650 sizeof(*base_instance_entry));
651 base_instance_entry->type = PVR_PDS_CONST_MAP_ENTRY_TYPE_BASE_INSTANCE;
652 base_instance_entry->const_offset = base_instance;
653 } else if (input_program->flags &
654 PVR_PDS_VERTEX_FLAGS_BASE_INSTANCE_REQUIRED) {
655 struct pvr_const_map_entry_base_instance *base_instance_entry =
656 (struct pvr_const_map_entry_base_instance *)entry_write_state.entry;
657
658 base_instance = pvr_find_constant(const_usage,
659 RESERVE_32BIT,
660 "base_instance (Driver Const)");
661
662 /* Base instance provided by the driver. */
663 base_instance_entry =
664 pvr_prepare_next_pds_const_map_entry(&entry_write_state,
665 sizeof(*base_instance_entry));
666 base_instance_entry->type = PVR_PDS_CONST_MAP_ENTRY_TYPE_BASE_INSTANCE;
667 base_instance_entry->const_offset = base_instance;
668 }
669
670 total_dma_count = ddmad_count;
671
672 total_dma_count += doutw_count;
673
674 if (use_robust_vertex_fetch) {
675 pvr_debug_pds_note("RobustBufferVertexFetch Initialization");
676
677 if (PVR_HAS_FEATURE(dev_info, pds_ddmadt)) {
678 zero_temp = pvr_get_temps(&temp_usage, RESERVE_32BIT, "zero_temp");
679
680 /* Load 0 into instance_ID_temp. */
681 PVR_PDS_MODE_TOGGLE(code,
682 instruction,
683 pvr_pds_inst_encode_limm(0, /* cc */
684 zero_temp, /* SRC1 */
685 0, /* SRC0 */
686 0 /* GR */
687 ));
688 } else {
689 zero_temp = pvr_get_temps(&temp_usage, RESERVE_64BIT, "zero_temp");
690
691 max_index_temp =
692 pvr_get_temps(&temp_usage, RESERVE_64BIT, "uMaxIndex");
693 current_index_temp =
694 pvr_get_temps(&temp_usage, RESERVE_64BIT, "uCurrentIndex");
695
696 PVR_PDS_MODE_TOGGLE(code,
697 instruction,
698 pvr_pds_inst_encode_sftlp64(
699 0, /* cc */
700 PVR_ROGUE_PDSINST_LOP_XOR, /* LOP */
701 1, /* IM */
702 R64TP_T(zero_temp >> 1), /* SRC0 (REGS64TP)
703 */
704 R64TP_T(zero_temp >> 1), /* SRC1 (REGS64TP)
705 */
706 0, /* SRC2 (REGS32) */
707 R64TP_T(zero_temp >> 1) /* DST (REG64TP) */
708 ));
709 PVR_PDS_MODE_TOGGLE(code,
710 instruction,
711 pvr_pds_inst_encode_sftlp64(
712 0, /* cc */
713 PVR_ROGUE_PDSINST_LOP_NONE, /* LOP */
714 1, /* IM */
715 R64TP_T(zero_temp >> 1), /* SRC0 (REGS64TP)
716 */
717 0, /* SRC1 (REGS64TP) */
718 0, /* SRC2 (REGS32) */
719 R64TP_T(current_index_temp >> 1) /* DST */
720 /* (REG64TP) */
721 ));
722 PVR_PDS_MODE_TOGGLE(code,
723 instruction,
724 pvr_pds_inst_encode_sftlp64(
725 0, /* cc */
726 PVR_ROGUE_PDSINST_LOP_NONE, /* LOP */
727 1, /* IM */
728 R64TP_T(zero_temp >> 1), /* SRC0 (REGS64TP)
729 */
730 0, /* SRC1 (REGS64TP) */
731 0, /* SRC2 (REGS32) */
732 R64TP_T(max_index_temp >> 1) /* DST */
733 /* (REG64TP) */
734 ));
735 }
736 }
737
738 if (input_program->dma_count && use_robust_vertex_fetch) {
739 PVR_PDS_MODE_TOGGLE(
740 code,
741 instruction,
742 pvr_pds_inst_encode_bra(PVR_ROGUE_PDSINST_PREDICATE_KEEP, /* SRCC */
743 0, /* Neg */
744 PVR_HAS_FEATURE(dev_info, pds_ddmadt)
745 ? PVR_ROGUE_PDSINST_PREDICATE_OOB
746 : PVR_ROGUE_PDSINST_PREDICATE_P0, /* SETC */
747 1 /* Addr */
748 ));
749 }
750
751 for (uint32_t dma = 0; dma < input_program->dma_count; dma++) {
752 struct pvr_const_map_entry_vertex_attribute_stride *stride_entry;
753 uint32_t const_base = dma * PVR_PDS_DDMAD_NUM_CONSTS;
754 uint32_t control_word;
755 struct pvr_const_map_entry_literal32 *literal_entry;
756
757 const struct pvr_pds_vertex_dma *vertex_dma =
758 &input_program->dma_list[dma];
759 bool last_dma = (++running_dma_count == total_dma_count);
760
761 pvr_debug_pds_note("Vertex Attribute DMA %d (last=%d)", dma, last_dma);
762
763 /* The id we use to index into this dma. */
764 if (vertex_dma->flags & PVR_PDS_VERTEX_DMA_FLAGS_INSTANCE_RATE) {
765 pvr_debug_pds_note("Instance Rate (divisor = %d)",
766 vertex_dma->divisor);
767
768 /* 4 - madd 0 - needs to be 64-bit aligned
769 * 5 - madd 1
770 */
771 if (vertex_dma->divisor > 1) {
772 const uint32_t adjusted_instance_ID_temp =
773 pvr_get_temps(&temp_usage,
774 RESERVE_64BIT,
775 "adjusted_instance_ID_temp");
776 const uint32_t MADD_temp =
777 pvr_get_temps(&temp_usage, RESERVE_64BIT, "MADD_temp");
778
779 /* 1. Remove base instance value from temp 1 to get instance id
780 * 2. Divide the instance id by the divisor - Iout = (Iin *
781 * Multiplier) >> (shift+31)
782 * 3. Add the base instance back on.
783 *
784 * Need two zero temps for the add part of the later MAD.
785 */
786
787 PVR_PDS_MODE_TOGGLE(code,
788 instruction,
789 pvr_pds_inst_encode_add64(
790 /* cc */ 0,
791 /* alum */ 0,
792 /* sna */ 1,
793 /* src0 */ R64_T(MADD_temp >> 1),
794 /* src1 */ R64_T(MADD_temp >> 1),
795 /* dst */ R64TP_T(MADD_temp >> 1)));
796
797 if (input_program->flags &
798 PVR_PDS_VERTEX_FLAGS_DRAW_INDIRECT_VARIANT) {
799 /* Subtract base instance from temp 1, put into
800 * adjusted_instance_ID_temp.
801 */
802 PVR_PDS_MODE_TOGGLE(
803 code,
804 instruction,
805 pvr_pds_inst_encode_add32(
806 /* cc */ 0,
807 /* alum */ 0,
808 /* sna */ 1,
809 /* src0 */ R32_T(instance_ID_temp),
810 /* src1 */ R32_P(PVR_INDIRECT_BASE_INSTANCE_PTEMP),
811 /* dst */ R32TP_T(adjusted_instance_ID_temp)));
812 } else if (input_program->flags &
813 PVR_PDS_VERTEX_FLAGS_BASE_INSTANCE_VARIANT) {
814 /* Subtract base instance from temp 1, put into
815 * adjusted_instance_ID_temp.
816 */
817 PVR_PDS_MODE_TOGGLE(
818 code,
819 instruction,
820 pvr_pds_inst_encode_add32(
821 /* cc */ 0,
822 /* alum */ 0,
823 /* sna */ 1,
824 /* src0 */ R32_T(instance_ID_temp),
825 /* src1 */ R32_C(base_instance),
826 /* dst */ R32TP_T(adjusted_instance_ID_temp)));
827 } else {
828 /* Copy instance from temp 1 to adjusted_instance_ID_temp.
829 */
830 PVR_PDS_MODE_TOGGLE(
831 code,
832 instruction,
833 pvr_pds_inst_encode_add32(
834 /* cc */ 0,
835 /* alum */ 0,
836 /* sna */ 0,
837 /* src0 */ R32_T(instance_ID_temp),
838 /* src1 */ R32_T(MADD_temp), /* MADD_temp is set
839 * to 0 at this point.
840 */
841 /* dst */ R32TP_T(adjusted_instance_ID_temp)));
842 }
843
844 /* shift = the bit of the next highest power of two. */
845 uint32_t shift_unsigned =
846 (31 - __builtin_clz(vertex_dma->divisor - 1)) + 1;
847 int32_t shift = (int32_t)shift_unsigned;
848 uint32_t shift_2s_comp;
849
850 pvr_debug_pds_note(
851 "Perform instance rate divide (as integer multiply and rshift)");
852
853 const uint32_t multipier_constant =
854 pvr_find_constant(const_usage,
855 RESERVE_32BIT,
856 "MultiplierConstant (for InstanceDivisor)");
857
858 /* multiplier = ( 2^(shift + 31) + (divisor - 1) ) / divisor,
859 note: the division above is integer division. */
860 uint64_t multipier64 =
861 (uint64_t)((((uint64_t)1 << ((uint64_t)shift_unsigned + 31)) +
862 ((uint64_t)vertex_dma->divisor - (uint64_t)1)) /
863 (uint64_t)vertex_dma->divisor);
864 uint32_t multiplier = (uint32_t)multipier64;
865
866 pvr_debug_pds_note(" - Value of MultiplierConstant = %u",
867 multiplier);
868 pvr_debug_pds_note(" - Value of Shift = %d", shift);
869
870 literal_entry =
871 pvr_prepare_next_pds_const_map_entry(&entry_write_state,
872 sizeof(*literal_entry));
873 literal_entry->type = PVR_PDS_CONST_MAP_ENTRY_TYPE_LITERAL32;
874 literal_entry->const_offset = multipier_constant;
875 literal_entry->literal_value = multiplier;
876
877 /* (Iin * Multiplier) */
878 PVR_PDS_MODE_TOGGLE(
879 code,
880 instruction,
881 pvr_rogue_inst_encode_mad(0, /* Sign of add is positive */
882 0, /* Unsigned ALU mode */
883 0, /* Unconditional */
884 R32_C(multipier_constant),
885 R32_T(adjusted_instance_ID_temp),
886 R64_T(MADD_temp / 2),
887 R64TP_T(MADD_temp / 2)));
888
889 /* >> (shift + 31) */
890 shift += 31;
891 shift *= -1;
892
893 if (shift < -31) {
894 /* >> (31) */
895 shift_2s_comp = 0xFFFE1;
896 PVR_PDS_MODE_TOGGLE(code,
897 instruction,
898 pvr_pds_inst_encode_sftlp64(
899 /* cc */ 0,
900 /* LOP */ PVR_ROGUE_PDSINST_LOP_NONE,
901 /* IM */ 1, /* enable immediate */
902 /* SRC0 */ R64_T(MADD_temp / 2),
903 /* SRC1 */ 0, /* This won't be used
904 in a shift
905 operation. */
906 /* SRC2 (Shift) */ shift_2s_comp,
907 /* DST */ R64TP_T(MADD_temp / 2)));
908 shift += 31;
909 }
910
911 /* >> (shift + 31) */
912 shift_2s_comp = *((uint32_t *)&shift);
913 PVR_PDS_MODE_TOGGLE(code,
914 instruction,
915 pvr_pds_inst_encode_sftlp64(
916 /* cc */ 0,
917 /* LOP */ PVR_ROGUE_PDSINST_LOP_NONE,
918 /* IM */ 1, /* enable immediate */
919 /* SRC0 */ R64_T(MADD_temp / 2),
920 /* SRC1 */ 0, /* This won't be used
921 * in a shift
922 * operation. */
923 /* SRC2 (Shift) */ shift_2s_comp,
924 /* DST */ R64TP_T(MADD_temp / 2)));
925
926 if (input_program->flags &
927 PVR_PDS_VERTEX_FLAGS_DRAW_INDIRECT_VARIANT) {
928 /* Add base instance. */
929 PVR_PDS_MODE_TOGGLE(
930 code,
931 instruction,
932 pvr_pds_inst_encode_add32(
933 /* cc */ 0,
934 /* alum */ 0,
935 /* sna */ 0,
936 /* src0 */ R32_T(MADD_temp),
937 /* src1 */ R32_P(PVR_INDIRECT_BASE_INSTANCE_PTEMP),
938 /* dst */ R32TP_T(MADD_temp)));
939 } else if (input_program->flags &
940 PVR_PDS_VERTEX_FLAGS_BASE_INSTANCE_VARIANT) {
941 /* Add base instance. */
942 PVR_PDS_MODE_TOGGLE(code,
943 instruction,
944 pvr_pds_inst_encode_add32(
945 /* cc */ 0,
946 /* alum */ 0,
947 /* sna */ 0,
948 /* src0 */ R32_T(MADD_temp),
949 /* src1 */ R32_C(base_instance),
950 /* dst */ R32TP_T(MADD_temp)));
951 }
952
953 pvr_debug_pds_note(
954 "DMA Vertex Index will be sourced from 'MADD_temp'");
955 index = MADD_temp;
956 } else if (vertex_dma->divisor == 0) {
957 if (base_instance_ID_temp == PVR_INVALID_TEMP) {
958 base_instance_ID_temp = pvr_get_temps(&temp_usage,
959 RESERVE_32BIT,
960 "uBaseInstanceIDTemp");
961 }
962
963 /* Load 0 into instance_ID_temp. */
964 PVR_PDS_MODE_TOGGLE(code,
965 instruction,
966 pvr_pds_inst_encode_limm(
967 /* cc */ 0,
968 /* src1 */ base_instance_ID_temp,
969 /* src0 */ 0,
970 /* gr */ 0));
971
972 if (input_program->flags &
973 PVR_PDS_VERTEX_FLAGS_DRAW_INDIRECT_VARIANT) {
974 /* Add base instance. */
975 PVR_PDS_MODE_TOGGLE(
976 code,
977 instruction,
978 pvr_pds_inst_encode_add32(
979 /* cc */ 0,
980 /* alum */ 0,
981 /* sna */ 0,
982 /* src0 */ R32_P(PVR_INDIRECT_BASE_INSTANCE_PTEMP),
983 /* src1 */ R32_T(base_instance_ID_temp),
984 /* dst */ R32TP_T(base_instance_ID_temp)));
985
986 } else if (input_program->flags &
987 PVR_PDS_VERTEX_FLAGS_BASE_INSTANCE_VARIANT) {
988 /* Add base instance. */
989 PVR_PDS_MODE_TOGGLE(
990 code,
991 instruction,
992 pvr_pds_inst_encode_add32(
993 /* cc */ 0,
994 /* alum */ 0,
995 /* sna */ 0,
996 /* src0 */ R32_C(base_instance),
997 /* src1 */ R32_T(base_instance_ID_temp),
998 /* dst */ R32TP_T(base_instance_ID_temp)));
999 }
1000
1001 pvr_debug_pds_note(
1002 "DMA Vertex Index will be sourced from 'uBaseInstanceIdTemp'");
1003 index = base_instance_ID_temp;
1004 } else {
1005 pvr_debug_pds_note(
1006 "DMA Vertex Index will be sourced from 'uInstanceIdTemp'");
1007 index = instance_ID_temp;
1008 }
1009 } else {
1010 pvr_debug_pds_note(
1011 "DMA Vertex Index will be sourced from 'uIndexIdTemp'");
1012 index = index_id_temp;
1013 }
1014
1015 /* DDMAD Const Usage [__XX_---] */
1016 pvr_write_pds_const_map_entry_vertex_attribute_address(
1017 &entry_write_state,
1018 vertex_dma,
1019 const_base + 4,
1020 use_robust_vertex_fetch);
1021
1022 /* DDMAD Const Usage [__XXX---] */
1023 stride_entry =
1024 pvr_prepare_next_pds_const_map_entry(&entry_write_state,
1025 sizeof(*stride_entry));
1026 stride_entry->type = PVR_PDS_CONST_MAP_ENTRY_TYPE_VERTEX_ATTRIBUTE_STRIDE;
1027 stride_entry->const_offset = const_base + 3;
1028 stride_entry->binding_index = vertex_dma->binding_index;
1029
1030 control_word = vertex_dma->size_in_dwords
1031 << PVR_ROGUE_PDSINST_DDMAD_FIELDS_SRC3_BSIZE_SHIFT;
1032 control_word |= vertex_dma->destination
1033 << PVR_ROGUE_PDSINST_DDMAD_FIELDS_SRC3_AO_SHIFT;
1034 control_word |= (PVR_ROGUE_PDSINST_DDMAD_FIELDS_SRC3_DEST_UNIFIED_STORE |
1035 PVR_ROGUE_PDSINST_DDMAD_FIELDS_SRC3_CMODE_CACHED);
1036
1037 /* DDMADT instructions will do a dummy doutd when OOB if
1038 * PVR_ROGUE_PDSINST_DDMAD_FIELDS_SRC3_LAST_EN is set but as the driver
1039 * would need to do another doutd after an OOB DDMADT to provide the 'in
1040 * bounds' data the DDMADT can't be set as LAST.
1041 *
1042 * This requires us to include a final dummy DDMAD.LAST instruction.
1043 *
1044 * Pseudocode taken from SeriesXE2017.PDS Instruction Controller
1045 * Specification.doc
1046 *
1047 * DDMAD src0,src1,src2,src3
1048 *
1049 * calculated_source_address := src0*src1+src2
1050 * base_address := src2
1051 * dma_parameters := src3[31:0]
1052 * buffer_size := src3[63:33]
1053 * test := src3[32]
1054 *
1055 * if (test == 1) {
1056 * // DDMAD(T)
1057 * if (calculated_source_address[39:0] + (burst_size<<2) <=
1058 * base_address[39:0] + buffer_size) {
1059 * OOB := 0
1060 * DOUTD calculated_source_address,dma_paramters
1061 * } else {
1062 * OOB := 1
1063 * if (last_instance == 1) {
1064 * dma_parameters[BURST_SIZE] := 0
1065 * DOUTD calculated_source_address,dma_paramters
1066 * }
1067 * }
1068 * } else {
1069 * // DDMAD
1070 * DOUTD calculated_source_address,dma_paramters
1071 * }
1072 */
1073
1074 if (last_dma && (!PVR_HAS_FEATURE(dev_info, pds_ddmadt) ||
1075 !use_robust_vertex_fetch)) {
1076 pvr_debug_pds_note("LAST DDMAD");
1077 control_word |= PVR_ROGUE_PDSINST_DDMAD_FIELDS_SRC3_LAST_EN;
1078 }
1079
1080 /* DDMAD Const Usage [_XXXX---] */
1081 literal_entry =
1082 pvr_prepare_next_pds_const_map_entry(&entry_write_state,
1083 sizeof(*literal_entry));
1084 literal_entry->type = PVR_PDS_CONST_MAP_ENTRY_TYPE_LITERAL32;
1085 literal_entry->const_offset = (const_base + 6);
1086 literal_entry->literal_value = control_word;
1087
1088 if (PVR_HAS_FEATURE(dev_info, pds_ddmadt)) {
1089 /* DDMAD Const Usage [XXXXX---]
1090 * With DDMADT an extra 32bits of SRC3 contains the information for
1091 * performing out-of-bounds tests on the DMA.
1092 */
1093
1094 if (use_robust_vertex_fetch) {
1095 struct pvr_pds_const_map_entry_vertex_attr_ddmadt_oob_buffer_size
1096 *oob_buffer_size;
1097 oob_buffer_size =
1098 pvr_prepare_next_pds_const_map_entry(&entry_write_state,
1099 sizeof(*oob_buffer_size));
1100
1101 oob_buffer_size->type =
1102 PVR_PDS_CONST_MAP_ENTRY_TYPE_VERTEX_ATTR_DDMADT_OOB_BUFFER_SIZE;
1103 oob_buffer_size->const_offset = const_base + 7;
1104 oob_buffer_size->offset = vertex_dma->offset;
1105 oob_buffer_size->binding_index = vertex_dma->binding_index;
1106 oob_buffer_size->size_in_dwords = vertex_dma->size_in_dwords;
1107 oob_buffer_size->attrib_size_in_bytes =
1108 vertex_dma->attrib_size_in_bytes;
1109 } else {
1110 literal_entry =
1111 pvr_prepare_next_pds_const_map_entry(&entry_write_state,
1112 sizeof(*literal_entry));
1113 literal_entry->type = PVR_PDS_CONST_MAP_ENTRY_TYPE_LITERAL32;
1114 literal_entry->const_offset = const_base + 7;
1115 literal_entry->literal_value = 0;
1116 }
1117
1118 PVR_PDS_MODE_TOGGLE(
1119 code,
1120 instruction,
1121 pvr_pds_inst_encode_ddmad(0, /* cc */
1122 0, /* END */
1123 R32_C(const_base + 3), /* SRC0 (REGS32) */
1124 index, /* SRC1 (REGS32T) */
1125 R64_C((const_base + 4) >> 1), /* SRC2
1126 * (REGS64)
1127 */
1128 R64_C((const_base + 6) >> 1) /* SRC3
1129 * (REGS64C)
1130 */
1131 ));
1132
1133 if (use_robust_vertex_fetch) {
1134 /* If not out of bounds, skip next DDMAD instructions. */
1135 PVR_PDS_MODE_TOGGLE(code,
1136 instruction,
1137 pvr_pds_inst_encode_ddmad(
1138 1, /* cc */
1139 0, /* END */
1140 R32_C(const_base + 3), /* SRC0 (REGS32) */
1141 R32_T(zero_temp), /* SRC1 (REGS32T) */
1142 R64_C((const_base + 4) >> 1), /* SRC2
1143 * (REGS64)
1144 */
1145 R64_C((const_base + 6) >> 1) /* SRC3
1146 * (REGS64C)
1147 */
1148 ));
1149
1150 /* Now the driver must have a dummy DDMAD marked as last. */
1151 if (last_dma) {
1152 uint32_t dummy_dma_const = pvr_find_constant(const_usage,
1153 RESERVE_64BIT,
1154 "uDummyDMAConst");
1155 uint32_t zero_const =
1156 pvr_find_constant(const_usage, RESERVE_64BIT, "uZeroConst");
1157
1158 literal_entry =
1159 pvr_prepare_next_pds_const_map_entry(&entry_write_state,
1160 sizeof(*literal_entry));
1161 literal_entry->type = PVR_PDS_CONST_MAP_ENTRY_TYPE_LITERAL32;
1162 literal_entry->const_offset = zero_const;
1163 literal_entry->literal_value = 0;
1164
1165 literal_entry =
1166 pvr_prepare_next_pds_const_map_entry(&entry_write_state,
1167 sizeof(*literal_entry));
1168 literal_entry->type = PVR_PDS_CONST_MAP_ENTRY_TYPE_LITERAL32;
1169 literal_entry->const_offset = zero_const + 1;
1170 literal_entry->literal_value = 0;
1171
1172 literal_entry =
1173 pvr_prepare_next_pds_const_map_entry(&entry_write_state,
1174 sizeof(*literal_entry));
1175 literal_entry->type = PVR_PDS_CONST_MAP_ENTRY_TYPE_LITERAL32;
1176 literal_entry->const_offset = dummy_dma_const;
1177 literal_entry->literal_value = 0;
1178
1179 literal_entry->literal_value |=
1180 0 << PVR_ROGUE_PDSINST_DDMAD_FIELDS_SRC3_BSIZE_SHIFT;
1181 literal_entry->literal_value |=
1182 (PVR_ROGUE_PDSINST_DDMAD_FIELDS_SRC3_DEST_UNIFIED_STORE |
1183 PVR_ROGUE_PDSINST_DDMAD_FIELDS_SRC3_CMODE_CACHED);
1184 literal_entry->literal_value |=
1185 PVR_ROGUE_PDSINST_DDMAD_FIELDS_SRC3_LAST_EN;
1186
1187 literal_entry =
1188 pvr_prepare_next_pds_const_map_entry(&entry_write_state,
1189 sizeof(*literal_entry));
1190 literal_entry->type = PVR_PDS_CONST_MAP_ENTRY_TYPE_LITERAL32;
1191 literal_entry->const_offset = dummy_dma_const + 1;
1192 literal_entry->literal_value = 0;
1193
1194 PVR_PDS_MODE_TOGGLE(code,
1195 instruction,
1196 pvr_pds_inst_encode_ddmad(
1197 0, /* cc */
1198 0, /* END */
1199 R32_C(zero_const), /* SRC0 (REGS32)
1200 */
1201 R32_T(zero_temp), /* SRC1 (REGS32T)
1202 */
1203 R64_C((dummy_dma_const) >> 1), /* SRC2
1204 (REGS64)
1205 */
1206 R64_C((dummy_dma_const) >> 1) /* SRC3
1207 (REGS64C)
1208 */
1209 ));
1210 }
1211 }
1212 } else {
1213 if (use_robust_vertex_fetch) {
1214 struct pvr_const_map_entry_vertex_attribute_max_index
1215 *max_index_entry;
1216
1217 pvr_debug("RobustVertexFetch DDMAD");
1218
1219 const uint32_t max_index_const =
1220 pvr_find_constant(const_usage, RESERVE_32BIT, "max_index_const");
1221
1222 max_index_entry =
1223 pvr_prepare_next_pds_const_map_entry(&entry_write_state,
1224 sizeof(*max_index_entry));
1225 max_index_entry->const_offset = max_index_const;
1226 max_index_entry->type =
1227 PVR_PDS_CONST_MAP_ENTRY_TYPE_VERTEX_ATTRIBUTE_MAX_INDEX;
1228 max_index_entry->binding_index = vertex_dma->binding_index;
1229 max_index_entry->offset = vertex_dma->offset;
1230 max_index_entry->stride = vertex_dma->stride;
1231 max_index_entry->size_in_dwords = vertex_dma->size_in_dwords;
1232 max_index_entry->attrib_size_in_bytes =
1233 vertex_dma->attrib_size_in_bytes;
1234
1235 PVR_PDS_MODE_TOGGLE(
1236 code,
1237 instruction,
1238 pvr_pds_inst_encode_add32(0, /* cc */
1239 0, /* ALUM */
1240 PVR_ROGUE_PDSINST_LOP_NONE, /* SNA */
1241 R32_C(max_index_const), /* SRC0
1242 * (REGS32)
1243 */
1244 R32_T(zero_temp), /* SRC1 (REGS32) */
1245 R32TP_T(max_index_temp) /* DST
1246 * (REG32TP)
1247 */
1248 ));
1249
1250 PVR_PDS_MODE_TOGGLE(code,
1251 instruction,
1252 pvr_pds_inst_encode_sftlp32(
1253 1, /* IM */
1254 0, /* cc */
1255 PVR_ROGUE_PDSINST_LOP_NONE, /* LOP */
1256 index, /* SRC0 (REGS32T) */
1257 0, /* SRC1 (REGS32) */
1258 0, /* SRC2 (REG32TP) */
1259 R32TP_T(current_index_temp) /* DST
1260 * (REG32TP)
1261 */
1262 ));
1263
1264 PVR_PDS_MODE_TOGGLE(
1265 code,
1266 instruction,
1267 pvr_pds_inst_encode_cmp(
1268 0, /* cc enable */
1269 PVR_ROGUE_PDSINST_COP_GT, /* Operation */
1270 R64TP_T(current_index_temp >> 1), /* SRC
1271 * (REGS64TP)
1272 */
1273 R64_T(max_index_temp >> 1) /* SRC1 (REGS64) */
1274 ));
1275
1276 PVR_PDS_MODE_TOGGLE(code,
1277 instruction,
1278 pvr_pds_inst_encode_sftlp32(
1279 1, /* IM */
1280 1, /* cc */
1281 PVR_ROGUE_PDSINST_LOP_NONE, /* LOP */
1282 zero_temp, /* SRC0 (REGS32T) */
1283 0, /* SRC1 (REGS32) */
1284 0, /* SRC2 (REG32TP) */
1285 R32TP_T(current_index_temp) /* DST
1286 * (REG32TP)
1287 */
1288 ));
1289
1290 PVR_PDS_MODE_TOGGLE(code,
1291 instruction,
1292 pvr_pds_inst_encode_ddmad(
1293 0, /* cc */
1294 0, /* END */
1295 R32_C(const_base + 3), /* SRC0 (REGS32) */
1296 current_index_temp, /* SRC1 (REGS32T) */
1297 R64_C((const_base + 4) >> 1), /* SRC2
1298 * (REGS64)
1299 */
1300 (const_base + 6) >> 1 /* SRC3 (REGS64C) */
1301 ));
1302 } else {
1303 PVR_PDS_MODE_TOGGLE(code,
1304 instruction,
1305 pvr_pds_inst_encode_ddmad(
1306 /* cc */ 0,
1307 /* end */ 0,
1308 /* src0 */ R32_C(const_base + 3),
1309 /* src1 */ (index),
1310 /* src2 */ R64_C((const_base + 4) >> 1),
1311 /* src3 */ (const_base + 6) >> 1));
1312 }
1313 }
1314 }
1315
1316 if (input_program->flags & PVR_PDS_VERTEX_FLAGS_VERTEX_ID_REQUIRED) {
1317 bool last_dma = (++running_dma_count == total_dma_count);
1318
1319 PVR_PDS_MODE_TOGGLE(
1320 code,
1321 instruction,
1322 pvr_encode_direct_write(
1323 &entry_write_state,
1324 last_dma,
1325 false,
1326 R64_C(write_vertex_control),
1327 R64_T(0),
1328 0x1,
1329 input_program->vertex_id_register,
1330 PVR_ROGUE_PDSINST_DOUT_FIELDS_DOUTW_SRC1_DEST_UNIFIED_STORE,
1331 dev_info));
1332 }
1333
1334 if (input_program->flags & PVR_PDS_VERTEX_FLAGS_INSTANCE_ID_REQUIRED) {
1335 bool last_dma = (++running_dma_count == total_dma_count);
1336
1337 PVR_PDS_MODE_TOGGLE(
1338 code,
1339 instruction,
1340 pvr_encode_direct_write(
1341 &entry_write_state,
1342 last_dma,
1343 false,
1344 R64_C(write_instance_control),
1345 R64_T(0),
1346 0x2,
1347 input_program->instance_id_register,
1348 PVR_ROGUE_PDSINST_DOUT_FIELDS_DOUTW_SRC1_DEST_UNIFIED_STORE,
1349 dev_info));
1350 }
1351
1352 if (input_program->flags & PVR_PDS_VERTEX_FLAGS_BASE_INSTANCE_REQUIRED) {
1353 bool last_dma = (++running_dma_count == total_dma_count);
1354
1355 if (input_program->flags & PVR_PDS_VERTEX_FLAGS_DRAW_INDIRECT_VARIANT) {
1356 /* Base instance comes from ptemp 1. */
1357 PVR_PDS_MODE_TOGGLE(
1358 code,
1359 instruction,
1360 pvr_encode_direct_write(
1361 &entry_write_state,
1362 last_dma,
1363 false,
1364 R64_C(write_base_instance_control),
1365 R64_P(PVR_INDIRECT_BASE_INSTANCE_PTEMP >> 1),
1366 0x2,
1367 input_program->base_instance_register,
1368 PVR_ROGUE_PDSINST_DOUT_FIELDS_DOUTW_SRC1_DEST_UNIFIED_STORE,
1369 dev_info));
1370 } else {
1371 uint32_t data_mask = (base_instance & 1) ? 0x2 : 0x1;
1372
1373 /* Base instance comes from driver constant. */
1374 PVR_PDS_MODE_TOGGLE(
1375 code,
1376 instruction,
1377 pvr_encode_direct_write(
1378 &entry_write_state,
1379 last_dma,
1380 false,
1381 R64_C(write_base_instance_control),
1382 R64_C(base_instance >> 1),
1383 data_mask,
1384 input_program->base_instance_register,
1385 PVR_ROGUE_PDSINST_DOUT_FIELDS_DOUTW_SRC1_DEST_UNIFIED_STORE,
1386 dev_info));
1387 }
1388 }
1389
1390 if (input_program->flags & PVR_PDS_VERTEX_FLAGS_BASE_VERTEX_REQUIRED) {
1391 bool last_dma = (++running_dma_count == total_dma_count);
1392
1393 if (input_program->flags & PVR_PDS_VERTEX_FLAGS_DRAW_INDIRECT_VARIANT) {
1394 /* Base vertex comes from ptemp 0 (initialized by PDS hardware). */
1395 PVR_PDS_MODE_TOGGLE(
1396 code,
1397 instruction,
1398 pvr_encode_direct_write(
1399 &entry_write_state,
1400 last_dma,
1401 false,
1402 R64_C(write_base_vertex_control),
1403 R64_P(0),
1404 0x1,
1405 input_program->base_vertex_register,
1406 PVR_ROGUE_PDSINST_DOUT_FIELDS_DOUTW_SRC1_DEST_UNIFIED_STORE,
1407 dev_info));
1408 } else {
1409 uint32_t data_mask = (base_vertex & 1) ? 0x2 : 0x1;
1410
1411 /* Base vertex comes from driver constant (literal 0). */
1412 PVR_PDS_MODE_TOGGLE(
1413 code,
1414 instruction,
1415 pvr_encode_direct_write(
1416 &entry_write_state,
1417 last_dma,
1418 false,
1419 R64_C(write_base_vertex_control),
1420 R64_C(base_vertex >> 1),
1421 data_mask,
1422 input_program->base_vertex_register,
1423 PVR_ROGUE_PDSINST_DOUT_FIELDS_DOUTW_SRC1_DEST_UNIFIED_STORE,
1424 dev_info));
1425 }
1426 }
1427
1428 if (input_program->flags & PVR_PDS_VERTEX_FLAGS_DRAW_INDEX_REQUIRED) {
1429 bool last_dma = (++running_dma_count == total_dma_count);
1430
1431 if (input_program->flags & PVR_PDS_VERTEX_FLAGS_DRAW_INDIRECT_VARIANT) {
1432 /* Draw index comes from ptemp 3. */
1433 PVR_PDS_MODE_TOGGLE(
1434 code,
1435 instruction,
1436 pvr_encode_direct_write(
1437 &entry_write_state,
1438 last_dma,
1439 false,
1440 R64_C(pvr_write_draw_index_control),
1441 R64_P(1),
1442 0x2,
1443 input_program->draw_index_register,
1444 PVR_ROGUE_PDSINST_DOUT_FIELDS_DOUTW_SRC1_DEST_UNIFIED_STORE,
1445 dev_info));
1446 } else {
1447 uint32_t data_mask = (draw_index & 1) ? 0x2 : 0x1;
1448
1449 /* Draw index comes from constant (literal 0). */
1450 PVR_PDS_MODE_TOGGLE(
1451 code,
1452 instruction,
1453 pvr_encode_direct_write(
1454 &entry_write_state,
1455 last_dma,
1456 false,
1457 R64_C(pvr_write_draw_index_control),
1458 R64_C(draw_index >> 1),
1459 data_mask,
1460 input_program->draw_index_register,
1461 PVR_ROGUE_PDSINST_DOUT_FIELDS_DOUTW_SRC1_DEST_UNIFIED_STORE,
1462 dev_info));
1463 }
1464 }
1465
1466 if (input_program->flags & PVR_PDS_VERTEX_FLAGS_VIEW_INDEX_REQUIRED) {
1467 bool last_dma = (++running_dma_count == total_dma_count);
1468 uint32_t data_mask = (PVR_PTEMP_VIEW_INDEX & 1) ? 0x2 : 0x1;
1469
1470 PVR_PDS_MODE_TOGGLE(
1471 code,
1472 instruction,
1473 pvr_encode_direct_write(
1474 &entry_write_state,
1475 last_dma,
1476 false,
1477 R64_C(write_view_index_control),
1478 R64_P(PVR_PTEMP_VIEW_INDEX >> 1),
1479 data_mask,
1480 input_program->view_index_register,
1481 PVR_ROGUE_PDSINST_DOUT_FIELDS_DOUTW_SRC1_DEST_UNIFIED_STORE,
1482 dev_info));
1483 }
1484
1485 doutu_address_entry =
1486 pvr_prepare_next_pds_const_map_entry(&entry_write_state,
1487 sizeof(*doutu_address_entry));
1488 doutu_address_entry->type = PVR_PDS_CONST_MAP_ENTRY_TYPE_DOUTU_ADDRESS;
1489 doutu_address_entry->const_offset = 0;
1490 doutu_address_entry->doutu_control = input_program->usc_task_control.src0;
1491
1492 if (use_robust_vertex_fetch) {
1493 /* Restore IF0 */
1494 PVR_PDS_MODE_TOGGLE(
1495 code,
1496 instruction,
1497 pvr_pds_inst_encode_bra(PVR_ROGUE_PDSINST_PREDICATE_KEEP, /* SRCCC */
1498 0, /* Neg */
1499 PVR_ROGUE_PDSINST_PREDICATE_IF0, /* SETCC */
1500 1 /* Addr */
1501 ));
1502 }
1503
1504 PVR_PDS_MODE_TOGGLE(code, instruction, pvr_pds_encode_doutu(1, 1, 0));
1505 PVR_PDS_MODE_TOGGLE(code, instruction, pvr_pds_inst_encode_halt(0));
1506
1507 assert(running_dma_count == total_dma_count);
1508
1509 for (uint32_t i = 0; i < ARRAY_SIZE(const_usage); i++) {
1510 if (const_usage[i] == 0)
1511 break;
1512
1513 info->data_size_in_dwords =
1514 8 * i + (32 - __builtin_clz((uint32_t)const_usage[i]));
1515 }
1516
1517 info->temps_required = temp_usage.temps_needed;
1518 info->entry_count = entry_write_state.entry_count;
1519 info->entries_written_size_in_bytes =
1520 entry_write_state.entries_size_in_bytes;
1521 info->code_size_in_dwords = instruction;
1522
1523 pvr_debug("=================================================\n");
1524 }
1525
1526 void pvr_pds_generate_descriptor_upload_program(
1527 struct pvr_pds_descriptor_program_input *input_program,
1528 uint32_t *code_section,
1529 struct pvr_pds_info *info)
1530 {
1531 unsigned int num_consts64 = 0;
1532 unsigned int num_consts32 = 0;
1533 unsigned int next_const64;
1534 unsigned int next_const32;
1535 unsigned int instruction = 0;
1536 uint32_t compile_time_buffer_index = 0;
1537
1538 unsigned int total_dma_count = 0;
1539 unsigned int running_dma_count = 0;
1540
1541 struct pvr_pds_const_map_entry_write_state entry_write_state;
1542
1543 /* Calculate the total register usage so we can stick 32-bit consts
1544 * after 64. Each DOUTD/DDMAD requires 1 32-bit constant and 1 64-bit
1545 * constant.
1546 */
1547 num_consts32 = input_program->descriptor_set_count;
1548 num_consts64 = input_program->descriptor_set_count;
1549 total_dma_count = input_program->descriptor_set_count;
1550
1551 pvr_init_pds_const_map_entry_write_state(info, &entry_write_state);
1552
1553 /* 1 DOUTD per compile time buffer: */
1554 for (unsigned int index = 0; index < input_program->buffer_count; index++) {
1555 num_consts32++;
1556 num_consts64++;
1557 total_dma_count++;
1558 }
1559
1560 /* DOUTU for the secondary update program requires a 64-bit constant. */
1561 if (input_program->secondary_program_present)
1562 num_consts64++;
1563
1564 info->data_size_in_dwords = (num_consts64 * 2) + (num_consts32);
1565
1566 /* Start counting constants. */
1567 next_const64 = 0;
1568 next_const32 = num_consts64 * 2;
1569
1570 /* For each descriptor set perform a DOUTD. */
1571 for (unsigned int descriptor_index = 0;
1572 descriptor_index < input_program->descriptor_set_count;
1573 descriptor_index++) {
1574 struct pvr_const_map_entry_descriptor_set *descriptor_set_entry;
1575 struct pvr_pds_descriptor_set *descriptor_set =
1576 &input_program->descriptor_sets[descriptor_index];
1577
1578 bool last_dma = (++running_dma_count == total_dma_count);
1579 bool halt = last_dma && !input_program->secondary_program_present;
1580
1581 descriptor_set_entry =
1582 pvr_prepare_next_pds_const_map_entry(&entry_write_state,
1583 sizeof(*descriptor_set_entry));
1584 descriptor_set_entry->type = PVR_PDS_CONST_MAP_ENTRY_TYPE_DESCRIPTOR_SET;
1585 descriptor_set_entry->const_offset = next_const64 * 2;
1586 descriptor_set_entry->descriptor_set = descriptor_set->descriptor_set;
1587
1588 PVR_PDS_MODE_TOGGLE(code_section,
1589 instruction,
1590 pvr_encode_burst_cs(&entry_write_state,
1591 last_dma,
1592 halt,
1593 next_const32,
1594 next_const64,
1595 descriptor_set->size_in_dwords,
1596 descriptor_set->destination));
1597
1598 next_const64++;
1599 next_const32++;
1600 }
1601
1602 for (unsigned int index = 0; index < input_program->buffer_count; index++) {
1603 struct pvr_pds_buffer *buffer = &input_program->buffers[index];
1604
1605 bool last_dma = (++running_dma_count == total_dma_count);
1606 bool halt = last_dma && !input_program->secondary_program_present;
1607
1608 switch (buffer->type) {
1609 case PVR_BUFFER_TYPE_DYNAMIC:
1610 case PVR_BUFFER_TYPE_PUSH_CONSTS:
1611 case PVR_BUFFER_TYPE_BLEND_CONSTS:
1612 case PVR_BUFFER_TYPE_POINT_SAMPLER:
1613 case PVR_BUFFER_TYPE_IA_SAMPLER:
1614 case PVR_BUFFER_TYPE_FRONT_FACE_OP:
1615 case PVR_BUFFER_TYPE_FS_META:
1616 case PVR_BUFFER_TYPE_TILE_BUFFERS:
1617 case PVR_BUFFER_TYPE_SPILL_INFO:
1618 case PVR_BUFFER_TYPE_SCRATCH_INFO:
1619 case PVR_BUFFER_TYPE_SAMPLE_LOCATIONS: {
1620 struct pvr_const_map_entry_special_buffer *special_buffer_entry;
1621
1622 special_buffer_entry =
1623 pvr_prepare_next_pds_const_map_entry(&entry_write_state,
1624 sizeof(*special_buffer_entry));
1625 special_buffer_entry->type =
1626 PVR_PDS_CONST_MAP_ENTRY_TYPE_SPECIAL_BUFFER;
1627 special_buffer_entry->buffer_type = buffer->type;
1628 special_buffer_entry->size_in_dwords = buffer->size_in_dwords;
1629
1630 switch (buffer->type) {
1631 case PVR_BUFFER_TYPE_DYNAMIC:
1632 special_buffer_entry->data = buffer->desc_set;
1633 break;
1634
1635 default:
1636 break;
1637 }
1638 break;
1639 }
1640 case PVR_BUFFER_TYPE_COMPILE_TIME: {
1641 struct pvr_const_map_entry_special_buffer *special_buffer_entry;
1642
1643 special_buffer_entry =
1644 pvr_prepare_next_pds_const_map_entry(&entry_write_state,
1645 sizeof(*special_buffer_entry));
1646 special_buffer_entry->type =
1647 PVR_PDS_CONST_MAP_ENTRY_TYPE_SPECIAL_BUFFER;
1648 special_buffer_entry->buffer_type = PVR_BUFFER_TYPE_COMPILE_TIME;
1649 special_buffer_entry->buffer_index = compile_time_buffer_index++;
1650 break;
1651 }
1652 }
1653
1654 entry_write_state.entry->const_offset = next_const64 * 2;
1655
1656 PVR_PDS_MODE_TOGGLE(code_section,
1657 instruction,
1658 pvr_encode_burst_cs(&entry_write_state,
1659 last_dma,
1660 halt,
1661 next_const32,
1662 next_const64,
1663 buffer->size_in_dwords,
1664 buffer->destination));
1665
1666 next_const64++;
1667 next_const32++;
1668 }
1669
1670 if (total_dma_count != running_dma_count)
1671 fprintf(stderr, "Mismatch in DMA count\n");
1672
1673 if (input_program->secondary_program_present) {
1674 struct pvr_const_map_entry_doutu_address *doutu_address;
1675
1676 PVR_PDS_MODE_TOGGLE(code_section,
1677 instruction,
1678 pvr_pds_encode_doutu(false, true, next_const64));
1679
1680 doutu_address =
1681 pvr_prepare_next_pds_const_map_entry(&entry_write_state,
1682 sizeof(*doutu_address));
1683 doutu_address->type = PVR_PDS_CONST_MAP_ENTRY_TYPE_DOUTU_ADDRESS;
1684 doutu_address->const_offset = next_const64 * 2;
1685 doutu_address->doutu_control = input_program->secondary_task_control.src0;
1686
1687 next_const64++;
1688 }
1689
1690 if (instruction == 0 && input_program->must_not_be_empty) {
1691 PVR_PDS_MODE_TOGGLE(code_section,
1692 instruction,
1693 pvr_pds_inst_encode_halt(
1694 /* cc */ false));
1695 }
1696
1697 info->entry_count = entry_write_state.entry_count;
1698 info->entries_written_size_in_bytes =
1699 entry_write_state.entries_size_in_bytes;
1700 info->code_size_in_dwords = instruction;
1701 }