2 * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
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
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 NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
25 #include "util/u_format.h"
26 #include "util/u_memory.h"
27 #include "pipe/p_shader_tokens.h"
28 #include "r600_pipe.h"
30 #include "r600_opcodes.h"
32 #include "r600_formats.h"
35 static inline unsigned int r600_bc_get_num_operands(struct r600_bc_alu
*alu
)
41 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP
:
43 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_ADD
:
44 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLE
:
45 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGT
:
46 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLGE
:
47 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_KILLNE
:
48 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MUL
:
49 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX
:
50 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MIN
:
51 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETE
:
52 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETNE
:
53 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGT
:
54 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SETGE
:
55 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE
:
56 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGT
:
57 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETGE
:
58 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE
:
59 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4
:
60 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_DOT4_IEEE
:
61 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_CUBE
:
64 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV
:
65 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOVA_FLOOR
:
66 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FRACT
:
67 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLOOR
:
68 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_TRUNC
:
69 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_EXP_IEEE
:
70 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_CLAMPED
:
71 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_IEEE
:
72 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIP_IEEE
:
73 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_RECIPSQRT_IEEE
:
74 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_INT
:
75 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_SIN
:
76 case V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_COS
:
79 "Need instruction operand number for 0x%x.\n", alu
->inst
);
85 int r700_bc_alu_build(struct r600_bc
*bc
, struct r600_bc_alu
*alu
, unsigned id
);
87 static struct r600_bc_cf
*r600_bc_cf(void)
89 struct r600_bc_cf
*cf
= CALLOC_STRUCT(r600_bc_cf
);
93 LIST_INITHEAD(&cf
->list
);
94 LIST_INITHEAD(&cf
->alu
);
95 LIST_INITHEAD(&cf
->vtx
);
96 LIST_INITHEAD(&cf
->tex
);
100 static struct r600_bc_alu
*r600_bc_alu(void)
102 struct r600_bc_alu
*alu
= CALLOC_STRUCT(r600_bc_alu
);
106 LIST_INITHEAD(&alu
->list
);
107 LIST_INITHEAD(&alu
->bs_list
);
111 static struct r600_bc_vtx
*r600_bc_vtx(void)
113 struct r600_bc_vtx
*vtx
= CALLOC_STRUCT(r600_bc_vtx
);
117 LIST_INITHEAD(&vtx
->list
);
121 static struct r600_bc_tex
*r600_bc_tex(void)
123 struct r600_bc_tex
*tex
= CALLOC_STRUCT(r600_bc_tex
);
127 LIST_INITHEAD(&tex
->list
);
131 int r600_bc_init(struct r600_bc
*bc
, enum radeon_family family
)
133 LIST_INITHEAD(&bc
->cf
);
135 switch (bc
->family
) {
144 bc
->chiprev
= CHIPREV_R600
;
150 bc
->chiprev
= CHIPREV_R700
;
158 bc
->chiprev
= CHIPREV_EVERGREEN
;
161 R600_ERR("unknown family %d\n", bc
->family
);
167 static int r600_bc_add_cf(struct r600_bc
*bc
)
169 struct r600_bc_cf
*cf
= r600_bc_cf();
173 LIST_ADDTAIL(&cf
->list
, &bc
->cf
);
175 cf
->id
= bc
->cf_last
->id
+ 2;
179 bc
->force_add_cf
= 0;
183 int r600_bc_add_output(struct r600_bc
*bc
, const struct r600_bc_output
*output
)
187 r
= r600_bc_add_cf(bc
);
190 bc
->cf_last
->inst
= output
->inst
;
191 memcpy(&bc
->cf_last
->output
, output
, sizeof(struct r600_bc_output
));
195 const unsigned bank_swizzle_vec
[8] = {SQ_ALU_VEC_210
, //000
196 SQ_ALU_VEC_120
, //001
197 SQ_ALU_VEC_102
, //010
199 SQ_ALU_VEC_201
, //011
200 SQ_ALU_VEC_012
, //100
201 SQ_ALU_VEC_021
, //101
203 SQ_ALU_VEC_012
, //110
204 SQ_ALU_VEC_012
}; //111
206 const unsigned bank_swizzle_scl
[8] = {SQ_ALU_SCL_210
, //000
207 SQ_ALU_SCL_122
, //001
208 SQ_ALU_SCL_122
, //010
210 SQ_ALU_SCL_221
, //011
211 SQ_ALU_SCL_212
, //100
212 SQ_ALU_SCL_122
, //101
214 SQ_ALU_SCL_122
, //110
215 SQ_ALU_SCL_122
}; //111
217 static int init_gpr(struct r600_bc_alu
*alu
)
219 int cycle
, component
;
221 for (cycle
= 0; cycle
< NUM_OF_CYCLES
; cycle
++)
222 for (component
= 0; component
< NUM_OF_COMPONENTS
; component
++)
223 alu
->hw_gpr
[cycle
][component
] = -1;
228 static int reserve_gpr(struct r600_bc_alu
*alu
, unsigned sel
, unsigned chan
, unsigned cycle
)
230 if (alu
->hw_gpr
[cycle
][chan
] < 0)
231 alu
->hw_gpr
[cycle
][chan
] = sel
;
232 else if (alu
->hw_gpr
[cycle
][chan
] != (int)sel
) {
233 R600_ERR("Another scalar operation has already used GPR read port for channel\n");
239 static int cycle_for_scalar_bank_swizzle(const int swiz
, const int sel
, unsigned *p_cycle
)
245 table
[0] = 2; table
[1] = 1; table
[2] = 0;
246 *p_cycle
= table
[sel
];
249 table
[0] = 1; table
[1] = 2; table
[2] = 2;
250 *p_cycle
= table
[sel
];
253 table
[0] = 2; table
[1] = 1; table
[2] = 2;
254 *p_cycle
= table
[sel
];
257 table
[0] = 2; table
[1] = 2; table
[2] = 1;
258 *p_cycle
= table
[sel
];
262 R600_ERR("bad scalar bank swizzle value\n");
269 static int cycle_for_vector_bank_swizzle(const int swiz
, const int sel
, unsigned *p_cycle
)
276 table
[0] = 0; table
[1] = 1; table
[2] = 2;
277 *p_cycle
= table
[sel
];
280 table
[0] = 0; table
[1] = 2; table
[2] = 1;
281 *p_cycle
= table
[sel
];
284 table
[0] = 1; table
[1] = 2; table
[2] = 0;
285 *p_cycle
= table
[sel
];
288 table
[0] = 1; table
[1] = 0; table
[2] = 2;
289 *p_cycle
= table
[sel
];
292 table
[0] = 2; table
[1] = 0; table
[2] = 1;
293 *p_cycle
= table
[sel
];
296 table
[0] = 2; table
[1] = 1; table
[2] = 0;
297 *p_cycle
= table
[sel
];
300 R600_ERR("bad vector bank swizzle value\n");
309 static void update_chan_counter(struct r600_bc_alu
*alu
, int *chan_counter
)
315 num_src
= r600_bc_get_num_operands(alu
);
317 for (i
= 0; i
< num_src
; i
++) {
318 channel_swizzle
= alu
->src
[i
].chan
;
319 if ((alu
->src
[i
].sel
> 0 && alu
->src
[i
].sel
< 128) && channel_swizzle
<= 3)
320 chan_counter
[channel_swizzle
]++;
324 /* we need something like this I think - but this is bogus */
325 int check_read_slots(struct r600_bc
*bc
, struct r600_bc_alu
*alu_first
)
327 struct r600_bc_alu
*alu
;
328 int chan_counter
[4] = { 0 };
330 update_chan_counter(alu_first
, chan_counter
);
332 LIST_FOR_EACH_ENTRY(alu
, &alu_first
->bs_list
, bs_list
) {
333 update_chan_counter(alu
, chan_counter
);
336 if (chan_counter
[0] > 3 ||
337 chan_counter
[1] > 3 ||
338 chan_counter
[2] > 3 ||
339 chan_counter
[3] > 3) {
340 R600_ERR("needed to split instruction for input ran out of banks %x %d %d %d %d\n",
341 alu_first
->inst
, chan_counter
[0], chan_counter
[1], chan_counter
[2], chan_counter
[3]);
348 static int is_const(int sel
)
350 if (sel
> 255 && sel
< 512)
352 if (sel
>= V_SQ_ALU_SRC_0
&& sel
<= V_SQ_ALU_SRC_LITERAL
)
357 static int check_scalar(struct r600_bc
*bc
, struct r600_bc_alu
*alu
)
359 unsigned swizzle_key
;
361 if (alu
->bank_swizzle_force
) {
362 alu
->bank_swizzle
= alu
->bank_swizzle_force
;
365 swizzle_key
= (is_const(alu
->src
[0].sel
) ? 4 : 0 ) +
366 (is_const(alu
->src
[1].sel
) ? 2 : 0 ) +
367 (is_const(alu
->src
[2].sel
) ? 1 : 0 );
369 alu
->bank_swizzle
= bank_swizzle_scl
[swizzle_key
];
373 static int check_vector(struct r600_bc
*bc
, struct r600_bc_alu
*alu
)
375 unsigned swizzle_key
;
377 if (alu
->bank_swizzle_force
) {
378 alu
->bank_swizzle
= alu
->bank_swizzle_force
;
381 swizzle_key
= (is_const(alu
->src
[0].sel
) ? 4 : 0 ) +
382 (is_const(alu
->src
[1].sel
) ? 2 : 0 ) +
383 (is_const(alu
->src
[2].sel
) ? 1 : 0 );
385 alu
->bank_swizzle
= bank_swizzle_vec
[swizzle_key
];
389 static int check_and_set_bank_swizzle(struct r600_bc
*bc
, struct r600_bc_alu
*alu_first
)
391 struct r600_bc_alu
*alu
= NULL
;
396 LIST_FOR_EACH_ENTRY(alu
, &alu_first
->bs_list
, bs_list
) {
400 if (num_instr
== 1) {
401 check_scalar(bc
, alu_first
);
404 /* check_read_slots(bc, bc->cf_last->curr_bs_head);*/
405 check_vector(bc
, alu_first
);
406 LIST_FOR_EACH_ENTRY(alu
, &alu_first
->bs_list
, bs_list
) {
407 check_vector(bc
, alu
);
413 int r600_bc_add_alu_type(struct r600_bc
*bc
, const struct r600_bc_alu
*alu
, int type
)
415 struct r600_bc_alu
*nalu
= r600_bc_alu();
416 struct r600_bc_alu
*lalu
;
421 memcpy(nalu
, alu
, sizeof(struct r600_bc_alu
));
424 /* cf can contains only alu or only vtx or only tex */
425 if (bc
->cf_last
== NULL
|| bc
->cf_last
->inst
!= (type
<< 3) ||
427 r
= r600_bc_add_cf(bc
);
432 bc
->cf_last
->inst
= (type
<< 3);
434 if (!bc
->cf_last
->curr_bs_head
) {
435 bc
->cf_last
->curr_bs_head
= nalu
;
436 LIST_INITHEAD(&nalu
->bs_list
);
438 LIST_ADDTAIL(&nalu
->bs_list
, &bc
->cf_last
->curr_bs_head
->bs_list
);
440 /* at most 128 slots, one add alu can add 4 slots + 4 constants(2 slots)
442 if (alu
->last
&& (bc
->cf_last
->ndw
>> 1) >= 120) {
443 bc
->force_add_cf
= 1;
445 /* number of gpr == the last gpr used in any alu */
446 for (i
= 0; i
< 3; i
++) {
447 if (alu
->src
[i
].sel
>= bc
->ngpr
&& alu
->src
[i
].sel
< 128) {
448 bc
->ngpr
= alu
->src
[i
].sel
+ 1;
450 /* compute how many literal are needed
451 * either 2 or 4 literals
453 if (alu
->src
[i
].sel
== 253) {
454 if (((alu
->src
[i
].chan
+ 2) & 0x6) > nalu
->nliteral
) {
455 nalu
->nliteral
= (alu
->src
[i
].chan
+ 2) & 0x6;
459 if (!LIST_IS_EMPTY(&bc
->cf_last
->alu
)) {
460 lalu
= LIST_ENTRY(struct r600_bc_alu
, bc
->cf_last
->alu
.prev
, list
);
461 if (!lalu
->last
&& lalu
->nliteral
> nalu
->nliteral
) {
462 nalu
->nliteral
= lalu
->nliteral
;
465 if (alu
->dst
.sel
>= bc
->ngpr
) {
466 bc
->ngpr
= alu
->dst
.sel
+ 1;
468 LIST_ADDTAIL(&nalu
->list
, &bc
->cf_last
->alu
);
469 /* each alu use 2 dwords */
470 bc
->cf_last
->ndw
+= 2;
473 bc
->cf_last
->kcache0_mode
= 2;
475 /* process cur ALU instructions for bank swizzle */
477 check_and_set_bank_swizzle(bc
, bc
->cf_last
->curr_bs_head
);
478 bc
->cf_last
->curr_bs_head
= NULL
;
483 int r600_bc_add_alu(struct r600_bc
*bc
, const struct r600_bc_alu
*alu
)
485 return r600_bc_add_alu_type(bc
, alu
, BC_INST(bc
, V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU
));
488 int r600_bc_add_literal(struct r600_bc
*bc
, const u32
*value
)
490 struct r600_bc_alu
*alu
;
492 if (bc
->cf_last
== NULL
) {
495 if (bc
->cf_last
->inst
== V_SQ_CF_WORD1_SQ_CF_INST_TEX
) {
499 if (bc
->cf_last
->inst
== V_SQ_CF_WORD1_SQ_CF_INST_JUMP
||
500 bc
->cf_last
->inst
== V_SQ_CF_WORD1_SQ_CF_INST_ELSE
||
501 bc
->cf_last
->inst
== V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL
||
502 bc
->cf_last
->inst
== V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK
||
503 bc
->cf_last
->inst
== V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE
||
504 bc
->cf_last
->inst
== V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END
||
505 bc
->cf_last
->inst
== V_SQ_CF_WORD1_SQ_CF_INST_POP
) {
509 if (((bc
->cf_last
->inst
!= (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU
<< 3)) &&
510 (bc
->cf_last
->inst
!= (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER
<< 3)) &&
511 (bc
->cf_last
->inst
!= (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER
<< 3)) &&
512 (bc
->cf_last
->inst
!= (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE
<< 3))) ||
513 LIST_IS_EMPTY(&bc
->cf_last
->alu
)) {
514 R600_ERR("last CF is not ALU (%p)\n", bc
->cf_last
);
517 alu
= LIST_ENTRY(struct r600_bc_alu
, bc
->cf_last
->alu
.prev
, list
);
518 if (!alu
->last
|| !alu
->nliteral
|| alu
->literal_added
) {
521 memcpy(alu
->value
, value
, 4 * 4);
522 bc
->cf_last
->ndw
+= alu
->nliteral
;
523 bc
->ndw
+= alu
->nliteral
;
524 alu
->literal_added
= 1;
528 int r600_bc_add_vtx(struct r600_bc
*bc
, const struct r600_bc_vtx
*vtx
)
530 struct r600_bc_vtx
*nvtx
= r600_bc_vtx();
535 memcpy(nvtx
, vtx
, sizeof(struct r600_bc_vtx
));
537 /* cf can contains only alu or only vtx or only tex */
538 if (bc
->cf_last
== NULL
||
539 (bc
->cf_last
->inst
!= V_SQ_CF_WORD1_SQ_CF_INST_VTX
&&
540 bc
->cf_last
->inst
!= V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC
) ||
542 r
= r600_bc_add_cf(bc
);
547 bc
->cf_last
->inst
= V_SQ_CF_WORD1_SQ_CF_INST_VTX
;
549 LIST_ADDTAIL(&nvtx
->list
, &bc
->cf_last
->vtx
);
550 /* each fetch use 4 dwords */
551 bc
->cf_last
->ndw
+= 4;
553 if ((bc
->ndw
/ 4) > 7)
554 bc
->force_add_cf
= 1;
558 int r600_bc_add_tex(struct r600_bc
*bc
, const struct r600_bc_tex
*tex
)
560 struct r600_bc_tex
*ntex
= r600_bc_tex();
565 memcpy(ntex
, tex
, sizeof(struct r600_bc_tex
));
567 /* cf can contains only alu or only vtx or only tex */
568 if (bc
->cf_last
== NULL
||
569 bc
->cf_last
->inst
!= V_SQ_CF_WORD1_SQ_CF_INST_TEX
||
571 r
= r600_bc_add_cf(bc
);
576 bc
->cf_last
->inst
= V_SQ_CF_WORD1_SQ_CF_INST_TEX
;
578 LIST_ADDTAIL(&ntex
->list
, &bc
->cf_last
->tex
);
579 /* each texture fetch use 4 dwords */
580 bc
->cf_last
->ndw
+= 4;
582 if ((bc
->ndw
/ 4) > 7)
583 bc
->force_add_cf
= 1;
587 int r600_bc_add_cfinst(struct r600_bc
*bc
, int inst
)
590 r
= r600_bc_add_cf(bc
);
594 bc
->cf_last
->cond
= V_SQ_CF_COND_ACTIVE
;
595 bc
->cf_last
->inst
= inst
;
599 /* common to all 3 families */
600 static int r600_bc_vtx_build(struct r600_bc
*bc
, struct r600_bc_vtx
*vtx
, unsigned id
)
602 unsigned fetch_resource_start
= 0;
604 /* check if we are fetch shader */
605 /* fetch shader can also access vertex resource,
606 * first fetch shader resource is at 160
608 if (bc
->type
== -1) {
609 switch (bc
->chiprev
) {
614 fetch_resource_start
= 160;
617 case CHIPREV_EVERGREEN
:
618 fetch_resource_start
= 0;
621 fprintf(stderr
, "%s:%s:%d unknown chiprev %d\n",
622 __FILE__
, __func__
, __LINE__
, bc
->chiprev
);
626 bc
->bytecode
[id
++] = S_SQ_VTX_WORD0_BUFFER_ID(vtx
->buffer_id
+ fetch_resource_start
) |
627 S_SQ_VTX_WORD0_SRC_GPR(vtx
->src_gpr
) |
628 S_SQ_VTX_WORD0_SRC_SEL_X(vtx
->src_sel_x
) |
629 S_SQ_VTX_WORD0_MEGA_FETCH_COUNT(vtx
->mega_fetch_count
);
630 bc
->bytecode
[id
++] = S_SQ_VTX_WORD1_DST_SEL_X(vtx
->dst_sel_x
) |
631 S_SQ_VTX_WORD1_DST_SEL_Y(vtx
->dst_sel_y
) |
632 S_SQ_VTX_WORD1_DST_SEL_Z(vtx
->dst_sel_z
) |
633 S_SQ_VTX_WORD1_DST_SEL_W(vtx
->dst_sel_w
) |
634 S_SQ_VTX_WORD1_USE_CONST_FIELDS(vtx
->use_const_fields
) |
635 S_SQ_VTX_WORD1_DATA_FORMAT(vtx
->data_format
) |
636 S_SQ_VTX_WORD1_NUM_FORMAT_ALL(vtx
->num_format_all
) |
637 S_SQ_VTX_WORD1_FORMAT_COMP_ALL(vtx
->format_comp_all
) |
638 S_SQ_VTX_WORD1_SRF_MODE_ALL(vtx
->srf_mode_all
) |
639 S_SQ_VTX_WORD1_GPR_DST_GPR(vtx
->dst_gpr
);
640 bc
->bytecode
[id
++] = S_SQ_VTX_WORD2_MEGA_FETCH(1);
641 bc
->bytecode
[id
++] = 0;
645 /* common to all 3 families */
646 static int r600_bc_tex_build(struct r600_bc
*bc
, struct r600_bc_tex
*tex
, unsigned id
)
648 bc
->bytecode
[id
++] = S_SQ_TEX_WORD0_TEX_INST(tex
->inst
) |
649 S_SQ_TEX_WORD0_RESOURCE_ID(tex
->resource_id
) |
650 S_SQ_TEX_WORD0_SRC_GPR(tex
->src_gpr
) |
651 S_SQ_TEX_WORD0_SRC_REL(tex
->src_rel
);
652 bc
->bytecode
[id
++] = S_SQ_TEX_WORD1_DST_GPR(tex
->dst_gpr
) |
653 S_SQ_TEX_WORD1_DST_REL(tex
->dst_rel
) |
654 S_SQ_TEX_WORD1_DST_SEL_X(tex
->dst_sel_x
) |
655 S_SQ_TEX_WORD1_DST_SEL_Y(tex
->dst_sel_y
) |
656 S_SQ_TEX_WORD1_DST_SEL_Z(tex
->dst_sel_z
) |
657 S_SQ_TEX_WORD1_DST_SEL_W(tex
->dst_sel_w
) |
658 S_SQ_TEX_WORD1_LOD_BIAS(tex
->lod_bias
) |
659 S_SQ_TEX_WORD1_COORD_TYPE_X(tex
->coord_type_x
) |
660 S_SQ_TEX_WORD1_COORD_TYPE_Y(tex
->coord_type_y
) |
661 S_SQ_TEX_WORD1_COORD_TYPE_Z(tex
->coord_type_z
) |
662 S_SQ_TEX_WORD1_COORD_TYPE_W(tex
->coord_type_w
);
663 bc
->bytecode
[id
++] = S_SQ_TEX_WORD2_OFFSET_X(tex
->offset_x
) |
664 S_SQ_TEX_WORD2_OFFSET_Y(tex
->offset_y
) |
665 S_SQ_TEX_WORD2_OFFSET_Z(tex
->offset_z
) |
666 S_SQ_TEX_WORD2_SAMPLER_ID(tex
->sampler_id
) |
667 S_SQ_TEX_WORD2_SRC_SEL_X(tex
->src_sel_x
) |
668 S_SQ_TEX_WORD2_SRC_SEL_Y(tex
->src_sel_y
) |
669 S_SQ_TEX_WORD2_SRC_SEL_Z(tex
->src_sel_z
) |
670 S_SQ_TEX_WORD2_SRC_SEL_W(tex
->src_sel_w
);
671 bc
->bytecode
[id
++] = 0;
675 /* r600 only, r700/eg bits in r700_asm.c */
676 static int r600_bc_alu_build(struct r600_bc
*bc
, struct r600_bc_alu
*alu
, unsigned id
)
680 /* don't replace gpr by pv or ps for destination register */
681 bc
->bytecode
[id
++] = S_SQ_ALU_WORD0_SRC0_SEL(alu
->src
[0].sel
) |
682 S_SQ_ALU_WORD0_SRC0_REL(alu
->src
[0].rel
) |
683 S_SQ_ALU_WORD0_SRC0_CHAN(alu
->src
[0].chan
) |
684 S_SQ_ALU_WORD0_SRC0_NEG(alu
->src
[0].neg
) |
685 S_SQ_ALU_WORD0_SRC1_SEL(alu
->src
[1].sel
) |
686 S_SQ_ALU_WORD0_SRC1_REL(alu
->src
[1].rel
) |
687 S_SQ_ALU_WORD0_SRC1_CHAN(alu
->src
[1].chan
) |
688 S_SQ_ALU_WORD0_SRC1_NEG(alu
->src
[1].neg
) |
689 S_SQ_ALU_WORD0_LAST(alu
->last
);
692 bc
->bytecode
[id
++] = S_SQ_ALU_WORD1_DST_GPR(alu
->dst
.sel
) |
693 S_SQ_ALU_WORD1_DST_CHAN(alu
->dst
.chan
) |
694 S_SQ_ALU_WORD1_DST_REL(alu
->dst
.rel
) |
695 S_SQ_ALU_WORD1_CLAMP(alu
->dst
.clamp
) |
696 S_SQ_ALU_WORD1_OP3_SRC2_SEL(alu
->src
[2].sel
) |
697 S_SQ_ALU_WORD1_OP3_SRC2_REL(alu
->src
[2].rel
) |
698 S_SQ_ALU_WORD1_OP3_SRC2_CHAN(alu
->src
[2].chan
) |
699 S_SQ_ALU_WORD1_OP3_SRC2_NEG(alu
->src
[2].neg
) |
700 S_SQ_ALU_WORD1_OP3_ALU_INST(alu
->inst
) |
701 S_SQ_ALU_WORD1_BANK_SWIZZLE(alu
->bank_swizzle
);
703 bc
->bytecode
[id
++] = S_SQ_ALU_WORD1_DST_GPR(alu
->dst
.sel
) |
704 S_SQ_ALU_WORD1_DST_CHAN(alu
->dst
.chan
) |
705 S_SQ_ALU_WORD1_DST_REL(alu
->dst
.rel
) |
706 S_SQ_ALU_WORD1_CLAMP(alu
->dst
.clamp
) |
707 S_SQ_ALU_WORD1_OP2_SRC0_ABS(alu
->src
[0].abs
) |
708 S_SQ_ALU_WORD1_OP2_SRC1_ABS(alu
->src
[1].abs
) |
709 S_SQ_ALU_WORD1_OP2_WRITE_MASK(alu
->dst
.write
) |
710 S_SQ_ALU_WORD1_OP2_OMOD(alu
->omod
) |
711 S_SQ_ALU_WORD1_OP2_ALU_INST(alu
->inst
) |
712 S_SQ_ALU_WORD1_BANK_SWIZZLE(alu
->bank_swizzle
) |
713 S_SQ_ALU_WORD1_OP2_UPDATE_EXECUTE_MASK(alu
->predicate
) |
714 S_SQ_ALU_WORD1_OP2_UPDATE_PRED(alu
->predicate
);
717 if (alu
->nliteral
&& !alu
->literal_added
) {
718 R600_ERR("Bug in ALU processing for instruction 0x%08x, literal not added correctly\n", alu
->inst
);
720 for (i
= 0; i
< alu
->nliteral
; i
++) {
721 bc
->bytecode
[id
++] = alu
->value
[i
];
727 /* common for r600/r700 - eg in eg_asm.c */
728 static int r600_bc_cf_build(struct r600_bc
*bc
, struct r600_bc_cf
*cf
)
730 unsigned id
= cf
->id
;
733 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU
<< 3):
734 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER
<< 3):
735 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER
<< 3):
736 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE
<< 3):
737 bc
->bytecode
[id
++] = S_SQ_CF_ALU_WORD0_ADDR(cf
->addr
>> 1) |
738 S_SQ_CF_ALU_WORD0_KCACHE_MODE0(cf
->kcache0_mode
) |
739 S_SQ_CF_ALU_WORD0_KCACHE_BANK0(cf
->kcache0_bank
) |
740 S_SQ_CF_ALU_WORD0_KCACHE_BANK1(cf
->kcache1_bank
);
742 bc
->bytecode
[id
++] = S_SQ_CF_ALU_WORD1_CF_INST(cf
->inst
>> 3) |
743 S_SQ_CF_ALU_WORD1_KCACHE_MODE1(cf
->kcache1_mode
) |
744 S_SQ_CF_ALU_WORD1_KCACHE_ADDR0(cf
->kcache0_addr
) |
745 S_SQ_CF_ALU_WORD1_KCACHE_ADDR1(cf
->kcache1_addr
) |
746 S_SQ_CF_ALU_WORD1_BARRIER(1) |
747 S_SQ_CF_ALU_WORD1_USES_WATERFALL(bc
->chiprev
== CHIPREV_R600
? cf
->r6xx_uses_waterfall
: 0) |
748 S_SQ_CF_ALU_WORD1_COUNT((cf
->ndw
/ 2) - 1);
750 case V_SQ_CF_WORD1_SQ_CF_INST_TEX
:
751 case V_SQ_CF_WORD1_SQ_CF_INST_VTX
:
752 case V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC
:
753 bc
->bytecode
[id
++] = S_SQ_CF_WORD0_ADDR(cf
->addr
>> 1);
754 bc
->bytecode
[id
++] = S_SQ_CF_WORD1_CF_INST(cf
->inst
) |
755 S_SQ_CF_WORD1_BARRIER(1) |
756 S_SQ_CF_WORD1_COUNT((cf
->ndw
/ 4) - 1);
758 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
:
759 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE
:
760 bc
->bytecode
[id
++] = S_SQ_CF_ALLOC_EXPORT_WORD0_RW_GPR(cf
->output
.gpr
) |
761 S_SQ_CF_ALLOC_EXPORT_WORD0_ELEM_SIZE(cf
->output
.elem_size
) |
762 S_SQ_CF_ALLOC_EXPORT_WORD0_ARRAY_BASE(cf
->output
.array_base
) |
763 S_SQ_CF_ALLOC_EXPORT_WORD0_TYPE(cf
->output
.type
);
764 bc
->bytecode
[id
++] = S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_X(cf
->output
.swizzle_x
) |
765 S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Y(cf
->output
.swizzle_y
) |
766 S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Z(cf
->output
.swizzle_z
) |
767 S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_W(cf
->output
.swizzle_w
) |
768 S_SQ_CF_ALLOC_EXPORT_WORD1_BARRIER(cf
->output
.barrier
) |
769 S_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(cf
->output
.inst
) |
770 S_SQ_CF_ALLOC_EXPORT_WORD1_END_OF_PROGRAM(cf
->output
.end_of_program
);
772 case V_SQ_CF_WORD1_SQ_CF_INST_JUMP
:
773 case V_SQ_CF_WORD1_SQ_CF_INST_ELSE
:
774 case V_SQ_CF_WORD1_SQ_CF_INST_POP
:
775 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL
:
776 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END
:
777 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE
:
778 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK
:
779 case V_SQ_CF_WORD1_SQ_CF_INST_CALL_FS
:
780 case V_SQ_CF_WORD1_SQ_CF_INST_RETURN
:
781 bc
->bytecode
[id
++] = S_SQ_CF_WORD0_ADDR(cf
->cf_addr
>> 1);
782 bc
->bytecode
[id
++] = S_SQ_CF_WORD1_CF_INST(cf
->inst
) |
783 S_SQ_CF_WORD1_BARRIER(1) |
784 S_SQ_CF_WORD1_COND(cf
->cond
) |
785 S_SQ_CF_WORD1_POP_COUNT(cf
->pop_count
);
789 R600_ERR("unsupported CF instruction (0x%X)\n", cf
->inst
);
795 int r600_bc_build(struct r600_bc
*bc
)
797 struct r600_bc_cf
*cf
;
798 struct r600_bc_alu
*alu
;
799 struct r600_bc_vtx
*vtx
;
800 struct r600_bc_tex
*tex
;
804 if (bc
->callstack
[0].max
> 0)
805 bc
->nstack
= ((bc
->callstack
[0].max
+ 3) >> 2) + 2;
806 if (bc
->type
== TGSI_PROCESSOR_VERTEX
&& !bc
->nstack
) {
810 /* first path compute addr of each CF block */
811 /* addr start after all the CF instructions */
812 addr
= bc
->cf_last
->id
+ 2;
813 LIST_FOR_EACH_ENTRY(cf
, &bc
->cf
, list
) {
815 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU
<< 3):
816 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER
<< 3):
817 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER
<< 3):
818 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE
<< 3):
820 case V_SQ_CF_WORD1_SQ_CF_INST_TEX
:
821 case V_SQ_CF_WORD1_SQ_CF_INST_VTX
:
822 case V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC
:
823 /* fetch node need to be 16 bytes aligned*/
825 addr
&= 0xFFFFFFFCUL
;
827 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
:
828 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE
:
829 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
:
830 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE
:
832 case V_SQ_CF_WORD1_SQ_CF_INST_JUMP
:
833 case V_SQ_CF_WORD1_SQ_CF_INST_ELSE
:
834 case V_SQ_CF_WORD1_SQ_CF_INST_POP
:
835 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL
:
836 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END
:
837 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE
:
838 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK
:
839 case V_SQ_CF_WORD1_SQ_CF_INST_CALL_FS
:
840 case V_SQ_CF_WORD1_SQ_CF_INST_RETURN
:
843 R600_ERR("unsupported CF instruction (0x%X)\n", cf
->inst
);
848 bc
->ndw
= cf
->addr
+ cf
->ndw
;
851 bc
->bytecode
= calloc(1, bc
->ndw
* 4);
852 if (bc
->bytecode
== NULL
)
854 LIST_FOR_EACH_ENTRY(cf
, &bc
->cf
, list
) {
856 if (bc
->chiprev
== CHIPREV_EVERGREEN
)
857 r
= eg_bc_cf_build(bc
, cf
);
859 r
= r600_bc_cf_build(bc
, cf
);
863 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU
<< 3):
864 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP_AFTER
<< 3):
865 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_POP2_AFTER
<< 3):
866 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE
<< 3):
867 LIST_FOR_EACH_ENTRY(alu
, &cf
->alu
, list
) {
868 switch(bc
->chiprev
) {
870 r
= r600_bc_alu_build(bc
, alu
, addr
);
873 case CHIPREV_EVERGREEN
: /* eg alu is same encoding as r700 */
874 r
= r700_bc_alu_build(bc
, alu
, addr
);
877 R600_ERR("unknown family %d\n", bc
->family
);
884 addr
+= alu
->nliteral
;
888 case V_SQ_CF_WORD1_SQ_CF_INST_VTX
:
889 case V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC
:
890 LIST_FOR_EACH_ENTRY(vtx
, &cf
->vtx
, list
) {
891 r
= r600_bc_vtx_build(bc
, vtx
, addr
);
897 case V_SQ_CF_WORD1_SQ_CF_INST_TEX
:
898 LIST_FOR_EACH_ENTRY(tex
, &cf
->tex
, list
) {
899 r
= r600_bc_tex_build(bc
, tex
, addr
);
905 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
:
906 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE
:
907 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
:
908 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE
:
909 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL
:
910 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END
:
911 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE
:
912 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK
:
913 case V_SQ_CF_WORD1_SQ_CF_INST_JUMP
:
914 case V_SQ_CF_WORD1_SQ_CF_INST_ELSE
:
915 case V_SQ_CF_WORD1_SQ_CF_INST_POP
:
916 case V_SQ_CF_WORD1_SQ_CF_INST_CALL_FS
:
917 case V_SQ_CF_WORD1_SQ_CF_INST_RETURN
:
920 R600_ERR("unsupported CF instruction (0x%X)\n", cf
->inst
);
927 void r600_bc_clear(struct r600_bc
*bc
)
929 struct r600_bc_cf
*cf
= NULL
, *next_cf
;
934 LIST_FOR_EACH_ENTRY_SAFE(cf
, next_cf
, &bc
->cf
, list
) {
935 struct r600_bc_alu
*alu
= NULL
, *next_alu
;
936 struct r600_bc_tex
*tex
= NULL
, *next_tex
;
937 struct r600_bc_tex
*vtx
= NULL
, *next_vtx
;
939 LIST_FOR_EACH_ENTRY_SAFE(alu
, next_alu
, &cf
->alu
, list
) {
943 LIST_INITHEAD(&cf
->alu
);
945 LIST_FOR_EACH_ENTRY_SAFE(tex
, next_tex
, &cf
->tex
, list
) {
949 LIST_INITHEAD(&cf
->tex
);
951 LIST_FOR_EACH_ENTRY_SAFE(vtx
, next_vtx
, &cf
->vtx
, list
) {
955 LIST_INITHEAD(&cf
->vtx
);
960 LIST_INITHEAD(&cf
->list
);
963 void r600_bc_dump(struct r600_bc
*bc
)
968 switch (bc
->chiprev
) {
980 fprintf(stderr
, "bytecode %d dw -----------------------\n", bc
->ndw
);
981 fprintf(stderr
, " %c\n", chip
);
982 for (i
= 0; i
< bc
->ndw
; i
++) {
983 fprintf(stderr
, "0x%08X\n", bc
->bytecode
[i
]);
985 fprintf(stderr
, "--------------------------------------\n");
988 void r600_cf_vtx(struct r600_vertex_element
*ve
, u32
*bytecode
, unsigned count
)
990 struct r600_pipe_state
*rstate
;
994 bytecode
[i
++] = S_SQ_CF_WORD0_ADDR(8 >> 1);
995 bytecode
[i
++] = S_SQ_CF_WORD1_CF_INST(V_SQ_CF_WORD1_SQ_CF_INST_VTX
) |
996 S_SQ_CF_WORD1_BARRIER(1) |
997 S_SQ_CF_WORD1_COUNT(8 - 1);
998 bytecode
[i
++] = S_SQ_CF_WORD0_ADDR(40 >> 1);
999 bytecode
[i
++] = S_SQ_CF_WORD1_CF_INST(V_SQ_CF_WORD1_SQ_CF_INST_VTX
) |
1000 S_SQ_CF_WORD1_BARRIER(1) |
1001 S_SQ_CF_WORD1_COUNT(count
- 8 - 1);
1003 bytecode
[i
++] = S_SQ_CF_WORD0_ADDR(8 >> 1);
1004 bytecode
[i
++] = S_SQ_CF_WORD1_CF_INST(V_SQ_CF_WORD1_SQ_CF_INST_VTX
) |
1005 S_SQ_CF_WORD1_BARRIER(1) |
1006 S_SQ_CF_WORD1_COUNT(count
- 1);
1008 bytecode
[i
++] = S_SQ_CF_WORD0_ADDR(0);
1009 bytecode
[i
++] = S_SQ_CF_WORD1_CF_INST(V_SQ_CF_WORD1_SQ_CF_INST_RETURN
) |
1010 S_SQ_CF_WORD1_BARRIER(1);
1012 rstate
= &ve
->rstate
;
1013 rstate
->id
= R600_PIPE_STATE_FETCH_SHADER
;
1015 r600_pipe_state_add_reg(rstate
, R_0288A4_SQ_PGM_RESOURCES_FS
,
1016 0x00000000, 0xFFFFFFFF, NULL
);
1017 r600_pipe_state_add_reg(rstate
, R_0288DC_SQ_PGM_CF_OFFSET_FS
,
1018 0x00000000, 0xFFFFFFFF, NULL
);
1019 r600_pipe_state_add_reg(rstate
, R_028894_SQ_PGM_START_FS
,
1020 r600_bo_offset(ve
->fetch_shader
) >> 8,
1021 0xFFFFFFFF, ve
->fetch_shader
);
1024 void r600_cf_vtx_tc(struct r600_vertex_element
*ve
, u32
*bytecode
, unsigned count
)
1026 struct r600_pipe_state
*rstate
;
1030 bytecode
[i
++] = S_SQ_CF_WORD0_ADDR(8 >> 1);
1031 bytecode
[i
++] = S_SQ_CF_WORD1_CF_INST(V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC
) |
1032 S_SQ_CF_WORD1_BARRIER(1) |
1033 S_SQ_CF_WORD1_COUNT(8 - 1);
1034 bytecode
[i
++] = S_SQ_CF_WORD0_ADDR(40 >> 1);
1035 bytecode
[i
++] = S_SQ_CF_WORD1_CF_INST(V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC
) |
1036 S_SQ_CF_WORD1_BARRIER(1) |
1037 S_SQ_CF_WORD1_COUNT((count
- 8) - 1);
1039 bytecode
[i
++] = S_SQ_CF_WORD0_ADDR(8 >> 1);
1040 bytecode
[i
++] = S_SQ_CF_WORD1_CF_INST(V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC
) |
1041 S_SQ_CF_WORD1_BARRIER(1) |
1042 S_SQ_CF_WORD1_COUNT(count
- 1);
1044 bytecode
[i
++] = S_SQ_CF_WORD0_ADDR(0);
1045 bytecode
[i
++] = S_SQ_CF_WORD1_CF_INST(V_SQ_CF_WORD1_SQ_CF_INST_RETURN
) |
1046 S_SQ_CF_WORD1_BARRIER(1);
1048 rstate
= &ve
->rstate
;
1049 rstate
->id
= R600_PIPE_STATE_FETCH_SHADER
;
1051 r600_pipe_state_add_reg(rstate
, R_0288A4_SQ_PGM_RESOURCES_FS
,
1052 0x00000000, 0xFFFFFFFF, NULL
);
1053 r600_pipe_state_add_reg(rstate
, R_0288DC_SQ_PGM_CF_OFFSET_FS
,
1054 0x00000000, 0xFFFFFFFF, NULL
);
1055 r600_pipe_state_add_reg(rstate
, R_028894_SQ_PGM_START_FS
,
1056 r600_bo_offset(ve
->fetch_shader
) >> 8,
1057 0xFFFFFFFF, ve
->fetch_shader
);
1060 static void r600_vertex_data_type(enum pipe_format pformat
, unsigned *format
,
1061 unsigned *num_format
, unsigned *format_comp
)
1063 const struct util_format_description
*desc
;
1070 desc
= util_format_description(pformat
);
1071 if (desc
->layout
!= UTIL_FORMAT_LAYOUT_PLAIN
) {
1075 /* Find the first non-VOID channel. */
1076 for (i
= 0; i
< 4; i
++) {
1077 if (desc
->channel
[i
].type
!= UTIL_FORMAT_TYPE_VOID
) {
1082 switch (desc
->channel
[i
].type
) {
1083 /* Half-floats, floats, doubles */
1084 case UTIL_FORMAT_TYPE_FLOAT
:
1085 switch (desc
->channel
[i
].size
) {
1087 switch (desc
->nr_channels
) {
1089 *format
= FMT_16_FLOAT
;
1092 *format
= FMT_16_16_FLOAT
;
1095 *format
= FMT_16_16_16_FLOAT
;
1098 *format
= FMT_16_16_16_16_FLOAT
;
1103 switch (desc
->nr_channels
) {
1105 *format
= FMT_32_FLOAT
;
1108 *format
= FMT_32_32_FLOAT
;
1111 *format
= FMT_32_32_32_FLOAT
;
1114 *format
= FMT_32_32_32_32_FLOAT
;
1123 case UTIL_FORMAT_TYPE_UNSIGNED
:
1125 case UTIL_FORMAT_TYPE_SIGNED
:
1126 switch (desc
->channel
[i
].size
) {
1128 switch (desc
->nr_channels
) {
1136 // *format = FMT_8_8_8; /* fails piglit draw-vertices test */
1139 *format
= FMT_8_8_8_8
;
1144 switch (desc
->nr_channels
) {
1149 *format
= FMT_16_16
;
1152 // *format = FMT_16_16_16; /* fails piglit draw-vertices test */
1155 *format
= FMT_16_16_16_16
;
1160 switch (desc
->nr_channels
) {
1165 *format
= FMT_32_32
;
1168 *format
= FMT_32_32_32
;
1171 *format
= FMT_32_32_32_32
;
1183 if (desc
->channel
[i
].type
== UTIL_FORMAT_TYPE_SIGNED
) {
1186 if (desc
->channel
[i
].normalized
) {
1193 R600_ERR("unsupported vertex format %s\n", util_format_name(pformat
));
1196 static void r600_bc(unsigned ndw
, unsigned chiprev
, u32
*bytecode
)
1213 fprintf(stderr
, "bytecode %d dw -----------------------\n", ndw
);
1214 fprintf(stderr
, " %c\n", chip
);
1215 for (i
= 0; i
< ndw
; i
++) {
1216 fprintf(stderr
, "0x%08X\n", bytecode
[i
]);
1218 fprintf(stderr
, "--------------------------------------\n");
1221 int r600_vertex_elements_build_fetch_shader(struct r600_pipe_context
*rctx
, struct r600_vertex_element
*ve
)
1225 unsigned fetch_resource_start
= 0, format
, num_format
, format_comp
;
1226 struct pipe_vertex_element
*elements
= ve
->elements
;
1227 const struct util_format_description
*desc
;
1229 /* 2 dwords for cf aligned to 4 + 4 dwords per input */
1230 ndw
= 8 + ve
->count
* 4;
1231 ve
->fs_size
= ndw
* 4;
1233 /* use PIPE_BIND_VERTEX_BUFFER so we use the cache buffer manager */
1234 ve
->fetch_shader
= r600_bo(rctx
->radeon
, ndw
*4, 256, PIPE_BIND_VERTEX_BUFFER
, 0);
1235 if (ve
->fetch_shader
== NULL
) {
1239 bytecode
= r600_bo_map(rctx
->radeon
, ve
->fetch_shader
, 0, NULL
);
1240 if (bytecode
== NULL
) {
1241 r600_bo_reference(rctx
->radeon
, &ve
->fetch_shader
, NULL
);
1245 if (rctx
->family
>= CHIP_CEDAR
) {
1246 eg_cf_vtx(ve
, &bytecode
[0], (ndw
- 8) / 4);
1248 r600_cf_vtx(ve
, &bytecode
[0], (ndw
- 8) / 4);
1249 fetch_resource_start
= 160;
1252 /* vertex elements offset need special handling, if offset is bigger
1253 * than what we can put in fetch instruction then we need to alterate
1254 * the vertex resource offset. In such case in order to simplify code
1255 * we will bound one resource per elements. It's a worst case scenario.
1257 for (i
= 0; i
< ve
->count
; i
++) {
1258 ve
->vbuffer_offset
[i
] = C_SQ_VTX_WORD2_OFFSET
& elements
[i
].src_offset
;
1259 if (ve
->vbuffer_offset
[i
]) {
1260 ve
->vbuffer_need_offset
= 1;
1264 for (i
= 0; i
< ve
->count
; i
++) {
1265 unsigned vbuffer_index
;
1266 r600_vertex_data_type(ve
->hw_format
[i
], &format
, &num_format
, &format_comp
);
1267 desc
= util_format_description(ve
->hw_format
[i
]);
1269 R600_ERR("unknown format %d\n", ve
->hw_format
[i
]);
1270 r600_bo_reference(rctx
->radeon
, &ve
->fetch_shader
, NULL
);
1274 /* see above for vbuffer_need_offset explanation */
1275 vbuffer_index
= elements
[i
].vertex_buffer_index
;
1276 if (ve
->vbuffer_need_offset
) {
1277 bytecode
[8 + i
* 4 + 0] = S_SQ_VTX_WORD0_BUFFER_ID(i
+ fetch_resource_start
);
1279 bytecode
[8 + i
* 4 + 0] = S_SQ_VTX_WORD0_BUFFER_ID(vbuffer_index
+ fetch_resource_start
);
1281 bytecode
[8 + i
* 4 + 0] |= S_SQ_VTX_WORD0_SRC_GPR(0) |
1282 S_SQ_VTX_WORD0_SRC_SEL_X(0) |
1283 S_SQ_VTX_WORD0_MEGA_FETCH_COUNT(0x1F);
1284 bytecode
[8 + i
* 4 + 1] = S_SQ_VTX_WORD1_DST_SEL_X(desc
->swizzle
[0]) |
1285 S_SQ_VTX_WORD1_DST_SEL_Y(desc
->swizzle
[1]) |
1286 S_SQ_VTX_WORD1_DST_SEL_Z(desc
->swizzle
[2]) |
1287 S_SQ_VTX_WORD1_DST_SEL_W(desc
->swizzle
[3]) |
1288 S_SQ_VTX_WORD1_USE_CONST_FIELDS(0) |
1289 S_SQ_VTX_WORD1_DATA_FORMAT(format
) |
1290 S_SQ_VTX_WORD1_NUM_FORMAT_ALL(num_format
) |
1291 S_SQ_VTX_WORD1_FORMAT_COMP_ALL(format_comp
) |
1292 S_SQ_VTX_WORD1_SRF_MODE_ALL(1) |
1293 S_SQ_VTX_WORD1_GPR_DST_GPR(i
+ 1);
1294 bytecode
[8 + i
* 4 + 2] = S_SQ_VTX_WORD2_OFFSET(elements
[i
].src_offset
) |
1295 S_SQ_VTX_WORD2_MEGA_FETCH(1);
1296 bytecode
[8 + i
* 4 + 3] = 0;
1298 r600_bo_unmap(rctx
->radeon
, ve
->fetch_shader
);