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_PUSH_BEFORE
<< 3))) ||
511 LIST_IS_EMPTY(&bc
->cf_last
->alu
)) {
512 R600_ERR("last CF is not ALU (%p)\n", bc
->cf_last
);
515 alu
= LIST_ENTRY(struct r600_bc_alu
, bc
->cf_last
->alu
.prev
, list
);
516 if (!alu
->last
|| !alu
->nliteral
|| alu
->literal_added
) {
519 memcpy(alu
->value
, value
, 4 * 4);
520 bc
->cf_last
->ndw
+= alu
->nliteral
;
521 bc
->ndw
+= alu
->nliteral
;
522 alu
->literal_added
= 1;
526 int r600_bc_add_vtx(struct r600_bc
*bc
, const struct r600_bc_vtx
*vtx
)
528 struct r600_bc_vtx
*nvtx
= r600_bc_vtx();
533 memcpy(nvtx
, vtx
, sizeof(struct r600_bc_vtx
));
535 /* cf can contains only alu or only vtx or only tex */
536 if (bc
->cf_last
== NULL
||
537 (bc
->cf_last
->inst
!= V_SQ_CF_WORD1_SQ_CF_INST_VTX
&&
538 bc
->cf_last
->inst
!= V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC
) ||
540 r
= r600_bc_add_cf(bc
);
545 bc
->cf_last
->inst
= V_SQ_CF_WORD1_SQ_CF_INST_VTX
;
547 LIST_ADDTAIL(&nvtx
->list
, &bc
->cf_last
->vtx
);
548 /* each fetch use 4 dwords */
549 bc
->cf_last
->ndw
+= 4;
551 if ((bc
->ndw
/ 4) > 7)
552 bc
->force_add_cf
= 1;
556 int r600_bc_add_tex(struct r600_bc
*bc
, const struct r600_bc_tex
*tex
)
558 struct r600_bc_tex
*ntex
= r600_bc_tex();
563 memcpy(ntex
, tex
, sizeof(struct r600_bc_tex
));
565 /* cf can contains only alu or only vtx or only tex */
566 if (bc
->cf_last
== NULL
||
567 bc
->cf_last
->inst
!= V_SQ_CF_WORD1_SQ_CF_INST_TEX
||
569 r
= r600_bc_add_cf(bc
);
574 bc
->cf_last
->inst
= V_SQ_CF_WORD1_SQ_CF_INST_TEX
;
576 LIST_ADDTAIL(&ntex
->list
, &bc
->cf_last
->tex
);
577 /* each texture fetch use 4 dwords */
578 bc
->cf_last
->ndw
+= 4;
580 if ((bc
->ndw
/ 4) > 7)
581 bc
->force_add_cf
= 1;
585 int r600_bc_add_cfinst(struct r600_bc
*bc
, int inst
)
588 r
= r600_bc_add_cf(bc
);
592 bc
->cf_last
->cond
= V_SQ_CF_COND_ACTIVE
;
593 bc
->cf_last
->inst
= inst
;
597 /* common to all 3 families */
598 static int r600_bc_vtx_build(struct r600_bc
*bc
, struct r600_bc_vtx
*vtx
, unsigned id
)
600 unsigned fetch_resource_start
= 0;
602 /* check if we are fetch shader */
603 /* fetch shader can also access vertex resource,
604 * first fetch shader resource is at 160
606 if (bc
->type
== -1) {
607 switch (bc
->chiprev
) {
612 fetch_resource_start
= 160;
615 case CHIPREV_EVERGREEN
:
616 fetch_resource_start
= 0;
619 fprintf(stderr
, "%s:%s:%d unknown chiprev %d\n",
620 __FILE__
, __func__
, __LINE__
, bc
->chiprev
);
624 bc
->bytecode
[id
++] = S_SQ_VTX_WORD0_BUFFER_ID(vtx
->buffer_id
+ fetch_resource_start
) |
625 S_SQ_VTX_WORD0_SRC_GPR(vtx
->src_gpr
) |
626 S_SQ_VTX_WORD0_SRC_SEL_X(vtx
->src_sel_x
) |
627 S_SQ_VTX_WORD0_MEGA_FETCH_COUNT(vtx
->mega_fetch_count
);
628 bc
->bytecode
[id
++] = S_SQ_VTX_WORD1_DST_SEL_X(vtx
->dst_sel_x
) |
629 S_SQ_VTX_WORD1_DST_SEL_Y(vtx
->dst_sel_y
) |
630 S_SQ_VTX_WORD1_DST_SEL_Z(vtx
->dst_sel_z
) |
631 S_SQ_VTX_WORD1_DST_SEL_W(vtx
->dst_sel_w
) |
632 S_SQ_VTX_WORD1_USE_CONST_FIELDS(vtx
->use_const_fields
) |
633 S_SQ_VTX_WORD1_DATA_FORMAT(vtx
->data_format
) |
634 S_SQ_VTX_WORD1_NUM_FORMAT_ALL(vtx
->num_format_all
) |
635 S_SQ_VTX_WORD1_FORMAT_COMP_ALL(vtx
->format_comp_all
) |
636 S_SQ_VTX_WORD1_SRF_MODE_ALL(vtx
->srf_mode_all
) |
637 S_SQ_VTX_WORD1_GPR_DST_GPR(vtx
->dst_gpr
);
638 bc
->bytecode
[id
++] = S_SQ_VTX_WORD2_MEGA_FETCH(1);
639 bc
->bytecode
[id
++] = 0;
643 /* common to all 3 families */
644 static int r600_bc_tex_build(struct r600_bc
*bc
, struct r600_bc_tex
*tex
, unsigned id
)
646 bc
->bytecode
[id
++] = S_SQ_TEX_WORD0_TEX_INST(tex
->inst
) |
647 S_SQ_TEX_WORD0_RESOURCE_ID(tex
->resource_id
) |
648 S_SQ_TEX_WORD0_SRC_GPR(tex
->src_gpr
) |
649 S_SQ_TEX_WORD0_SRC_REL(tex
->src_rel
);
650 bc
->bytecode
[id
++] = S_SQ_TEX_WORD1_DST_GPR(tex
->dst_gpr
) |
651 S_SQ_TEX_WORD1_DST_REL(tex
->dst_rel
) |
652 S_SQ_TEX_WORD1_DST_SEL_X(tex
->dst_sel_x
) |
653 S_SQ_TEX_WORD1_DST_SEL_Y(tex
->dst_sel_y
) |
654 S_SQ_TEX_WORD1_DST_SEL_Z(tex
->dst_sel_z
) |
655 S_SQ_TEX_WORD1_DST_SEL_W(tex
->dst_sel_w
) |
656 S_SQ_TEX_WORD1_LOD_BIAS(tex
->lod_bias
) |
657 S_SQ_TEX_WORD1_COORD_TYPE_X(tex
->coord_type_x
) |
658 S_SQ_TEX_WORD1_COORD_TYPE_Y(tex
->coord_type_y
) |
659 S_SQ_TEX_WORD1_COORD_TYPE_Z(tex
->coord_type_z
) |
660 S_SQ_TEX_WORD1_COORD_TYPE_W(tex
->coord_type_w
);
661 bc
->bytecode
[id
++] = S_SQ_TEX_WORD2_OFFSET_X(tex
->offset_x
) |
662 S_SQ_TEX_WORD2_OFFSET_Y(tex
->offset_y
) |
663 S_SQ_TEX_WORD2_OFFSET_Z(tex
->offset_z
) |
664 S_SQ_TEX_WORD2_SAMPLER_ID(tex
->sampler_id
) |
665 S_SQ_TEX_WORD2_SRC_SEL_X(tex
->src_sel_x
) |
666 S_SQ_TEX_WORD2_SRC_SEL_Y(tex
->src_sel_y
) |
667 S_SQ_TEX_WORD2_SRC_SEL_Z(tex
->src_sel_z
) |
668 S_SQ_TEX_WORD2_SRC_SEL_W(tex
->src_sel_w
);
669 bc
->bytecode
[id
++] = 0;
673 /* r600 only, r700/eg bits in r700_asm.c */
674 static int r600_bc_alu_build(struct r600_bc
*bc
, struct r600_bc_alu
*alu
, unsigned id
)
678 /* don't replace gpr by pv or ps for destination register */
679 bc
->bytecode
[id
++] = S_SQ_ALU_WORD0_SRC0_SEL(alu
->src
[0].sel
) |
680 S_SQ_ALU_WORD0_SRC0_REL(alu
->src
[0].rel
) |
681 S_SQ_ALU_WORD0_SRC0_CHAN(alu
->src
[0].chan
) |
682 S_SQ_ALU_WORD0_SRC0_NEG(alu
->src
[0].neg
) |
683 S_SQ_ALU_WORD0_SRC1_SEL(alu
->src
[1].sel
) |
684 S_SQ_ALU_WORD0_SRC1_REL(alu
->src
[1].rel
) |
685 S_SQ_ALU_WORD0_SRC1_CHAN(alu
->src
[1].chan
) |
686 S_SQ_ALU_WORD0_SRC1_NEG(alu
->src
[1].neg
) |
687 S_SQ_ALU_WORD0_LAST(alu
->last
);
690 bc
->bytecode
[id
++] = S_SQ_ALU_WORD1_DST_GPR(alu
->dst
.sel
) |
691 S_SQ_ALU_WORD1_DST_CHAN(alu
->dst
.chan
) |
692 S_SQ_ALU_WORD1_DST_REL(alu
->dst
.rel
) |
693 S_SQ_ALU_WORD1_CLAMP(alu
->dst
.clamp
) |
694 S_SQ_ALU_WORD1_OP3_SRC2_SEL(alu
->src
[2].sel
) |
695 S_SQ_ALU_WORD1_OP3_SRC2_REL(alu
->src
[2].rel
) |
696 S_SQ_ALU_WORD1_OP3_SRC2_CHAN(alu
->src
[2].chan
) |
697 S_SQ_ALU_WORD1_OP3_SRC2_NEG(alu
->src
[2].neg
) |
698 S_SQ_ALU_WORD1_OP3_ALU_INST(alu
->inst
) |
699 S_SQ_ALU_WORD1_BANK_SWIZZLE(alu
->bank_swizzle
);
701 bc
->bytecode
[id
++] = S_SQ_ALU_WORD1_DST_GPR(alu
->dst
.sel
) |
702 S_SQ_ALU_WORD1_DST_CHAN(alu
->dst
.chan
) |
703 S_SQ_ALU_WORD1_DST_REL(alu
->dst
.rel
) |
704 S_SQ_ALU_WORD1_CLAMP(alu
->dst
.clamp
) |
705 S_SQ_ALU_WORD1_OP2_SRC0_ABS(alu
->src
[0].abs
) |
706 S_SQ_ALU_WORD1_OP2_SRC1_ABS(alu
->src
[1].abs
) |
707 S_SQ_ALU_WORD1_OP2_WRITE_MASK(alu
->dst
.write
) |
708 S_SQ_ALU_WORD1_OP2_ALU_INST(alu
->inst
) |
709 S_SQ_ALU_WORD1_BANK_SWIZZLE(alu
->bank_swizzle
) |
710 S_SQ_ALU_WORD1_OP2_UPDATE_EXECUTE_MASK(alu
->predicate
) |
711 S_SQ_ALU_WORD1_OP2_UPDATE_PRED(alu
->predicate
);
714 if (alu
->nliteral
&& !alu
->literal_added
) {
715 R600_ERR("Bug in ALU processing for instruction 0x%08x, literal not added correctly\n", alu
->inst
);
717 for (i
= 0; i
< alu
->nliteral
; i
++) {
718 bc
->bytecode
[id
++] = alu
->value
[i
];
724 /* common for r600/r700 - eg in eg_asm.c */
725 static int r600_bc_cf_build(struct r600_bc
*bc
, struct r600_bc_cf
*cf
)
727 unsigned id
= cf
->id
;
730 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU
<< 3):
731 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE
<< 3):
732 bc
->bytecode
[id
++] = S_SQ_CF_ALU_WORD0_ADDR(cf
->addr
>> 1) |
733 S_SQ_CF_ALU_WORD0_KCACHE_MODE0(cf
->kcache0_mode
) |
734 S_SQ_CF_ALU_WORD0_KCACHE_BANK0(cf
->kcache0_bank
) |
735 S_SQ_CF_ALU_WORD0_KCACHE_BANK1(cf
->kcache1_bank
);
737 bc
->bytecode
[id
++] = S_SQ_CF_ALU_WORD1_CF_INST(cf
->inst
>> 3) |
738 S_SQ_CF_ALU_WORD1_KCACHE_MODE1(cf
->kcache1_mode
) |
739 S_SQ_CF_ALU_WORD1_KCACHE_ADDR0(cf
->kcache0_addr
) |
740 S_SQ_CF_ALU_WORD1_KCACHE_ADDR1(cf
->kcache1_addr
) |
741 S_SQ_CF_ALU_WORD1_BARRIER(1) |
742 S_SQ_CF_ALU_WORD1_USES_WATERFALL(bc
->chiprev
== CHIPREV_R600
? cf
->r6xx_uses_waterfall
: 0) |
743 S_SQ_CF_ALU_WORD1_COUNT((cf
->ndw
/ 2) - 1);
745 case V_SQ_CF_WORD1_SQ_CF_INST_TEX
:
746 case V_SQ_CF_WORD1_SQ_CF_INST_VTX
:
747 case V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC
:
748 bc
->bytecode
[id
++] = S_SQ_CF_WORD0_ADDR(cf
->addr
>> 1);
749 bc
->bytecode
[id
++] = S_SQ_CF_WORD1_CF_INST(cf
->inst
) |
750 S_SQ_CF_WORD1_BARRIER(1) |
751 S_SQ_CF_WORD1_COUNT((cf
->ndw
/ 4) - 1);
753 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
:
754 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE
:
755 bc
->bytecode
[id
++] = S_SQ_CF_ALLOC_EXPORT_WORD0_RW_GPR(cf
->output
.gpr
) |
756 S_SQ_CF_ALLOC_EXPORT_WORD0_ELEM_SIZE(cf
->output
.elem_size
) |
757 S_SQ_CF_ALLOC_EXPORT_WORD0_ARRAY_BASE(cf
->output
.array_base
) |
758 S_SQ_CF_ALLOC_EXPORT_WORD0_TYPE(cf
->output
.type
);
759 bc
->bytecode
[id
++] = S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_X(cf
->output
.swizzle_x
) |
760 S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Y(cf
->output
.swizzle_y
) |
761 S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_Z(cf
->output
.swizzle_z
) |
762 S_SQ_CF_ALLOC_EXPORT_WORD1_SWIZ_SEL_W(cf
->output
.swizzle_w
) |
763 S_SQ_CF_ALLOC_EXPORT_WORD1_BARRIER(cf
->output
.barrier
) |
764 S_SQ_CF_ALLOC_EXPORT_WORD1_CF_INST(cf
->output
.inst
) |
765 S_SQ_CF_ALLOC_EXPORT_WORD1_END_OF_PROGRAM(cf
->output
.end_of_program
);
767 case V_SQ_CF_WORD1_SQ_CF_INST_JUMP
:
768 case V_SQ_CF_WORD1_SQ_CF_INST_ELSE
:
769 case V_SQ_CF_WORD1_SQ_CF_INST_POP
:
770 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL
:
771 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END
:
772 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE
:
773 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK
:
774 case V_SQ_CF_WORD1_SQ_CF_INST_CALL_FS
:
775 case V_SQ_CF_WORD1_SQ_CF_INST_RETURN
:
776 bc
->bytecode
[id
++] = S_SQ_CF_WORD0_ADDR(cf
->cf_addr
>> 1);
777 bc
->bytecode
[id
++] = S_SQ_CF_WORD1_CF_INST(cf
->inst
) |
778 S_SQ_CF_WORD1_BARRIER(1) |
779 S_SQ_CF_WORD1_COND(cf
->cond
) |
780 S_SQ_CF_WORD1_POP_COUNT(cf
->pop_count
);
784 R600_ERR("unsupported CF instruction (0x%X)\n", cf
->inst
);
790 int r600_bc_build(struct r600_bc
*bc
)
792 struct r600_bc_cf
*cf
;
793 struct r600_bc_alu
*alu
;
794 struct r600_bc_vtx
*vtx
;
795 struct r600_bc_tex
*tex
;
799 if (bc
->callstack
[0].max
> 0)
800 bc
->nstack
= ((bc
->callstack
[0].max
+ 3) >> 2) + 2;
801 if (bc
->type
== TGSI_PROCESSOR_VERTEX
&& !bc
->nstack
) {
805 /* first path compute addr of each CF block */
806 /* addr start after all the CF instructions */
807 addr
= bc
->cf_last
->id
+ 2;
808 LIST_FOR_EACH_ENTRY(cf
, &bc
->cf
, list
) {
810 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU
<< 3):
811 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE
<< 3):
813 case V_SQ_CF_WORD1_SQ_CF_INST_TEX
:
814 case V_SQ_CF_WORD1_SQ_CF_INST_VTX
:
815 case V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC
:
816 /* fetch node need to be 16 bytes aligned*/
818 addr
&= 0xFFFFFFFCUL
;
820 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
:
821 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE
:
822 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
:
823 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE
:
825 case V_SQ_CF_WORD1_SQ_CF_INST_JUMP
:
826 case V_SQ_CF_WORD1_SQ_CF_INST_ELSE
:
827 case V_SQ_CF_WORD1_SQ_CF_INST_POP
:
828 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL
:
829 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END
:
830 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE
:
831 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK
:
832 case V_SQ_CF_WORD1_SQ_CF_INST_CALL_FS
:
833 case V_SQ_CF_WORD1_SQ_CF_INST_RETURN
:
836 R600_ERR("unsupported CF instruction (0x%X)\n", cf
->inst
);
841 bc
->ndw
= cf
->addr
+ cf
->ndw
;
844 bc
->bytecode
= calloc(1, bc
->ndw
* 4);
845 if (bc
->bytecode
== NULL
)
847 LIST_FOR_EACH_ENTRY(cf
, &bc
->cf
, list
) {
849 if (bc
->chiprev
== CHIPREV_EVERGREEN
)
850 r
= eg_bc_cf_build(bc
, cf
);
852 r
= r600_bc_cf_build(bc
, cf
);
856 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU
<< 3):
857 case (V_SQ_CF_ALU_WORD1_SQ_CF_INST_ALU_PUSH_BEFORE
<< 3):
858 LIST_FOR_EACH_ENTRY(alu
, &cf
->alu
, list
) {
859 switch(bc
->chiprev
) {
861 r
= r600_bc_alu_build(bc
, alu
, addr
);
864 case CHIPREV_EVERGREEN
: /* eg alu is same encoding as r700 */
865 r
= r700_bc_alu_build(bc
, alu
, addr
);
868 R600_ERR("unknown family %d\n", bc
->family
);
875 addr
+= alu
->nliteral
;
879 case V_SQ_CF_WORD1_SQ_CF_INST_VTX
:
880 case V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC
:
881 LIST_FOR_EACH_ENTRY(vtx
, &cf
->vtx
, list
) {
882 r
= r600_bc_vtx_build(bc
, vtx
, addr
);
888 case V_SQ_CF_WORD1_SQ_CF_INST_TEX
:
889 LIST_FOR_EACH_ENTRY(tex
, &cf
->tex
, list
) {
890 r
= r600_bc_tex_build(bc
, tex
, addr
);
896 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
:
897 case V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE
:
898 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT
:
899 case EG_V_SQ_CF_ALLOC_EXPORT_WORD1_SQ_CF_INST_EXPORT_DONE
:
900 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_START_NO_AL
:
901 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_END
:
902 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_CONTINUE
:
903 case V_SQ_CF_WORD1_SQ_CF_INST_LOOP_BREAK
:
904 case V_SQ_CF_WORD1_SQ_CF_INST_JUMP
:
905 case V_SQ_CF_WORD1_SQ_CF_INST_ELSE
:
906 case V_SQ_CF_WORD1_SQ_CF_INST_POP
:
907 case V_SQ_CF_WORD1_SQ_CF_INST_CALL_FS
:
908 case V_SQ_CF_WORD1_SQ_CF_INST_RETURN
:
911 R600_ERR("unsupported CF instruction (0x%X)\n", cf
->inst
);
918 void r600_bc_clear(struct r600_bc
*bc
)
920 struct r600_bc_cf
*cf
= NULL
, *next_cf
;
925 LIST_FOR_EACH_ENTRY_SAFE(cf
, next_cf
, &bc
->cf
, list
) {
926 struct r600_bc_alu
*alu
= NULL
, *next_alu
;
927 struct r600_bc_tex
*tex
= NULL
, *next_tex
;
928 struct r600_bc_tex
*vtx
= NULL
, *next_vtx
;
930 LIST_FOR_EACH_ENTRY_SAFE(alu
, next_alu
, &cf
->alu
, list
) {
934 LIST_INITHEAD(&cf
->alu
);
936 LIST_FOR_EACH_ENTRY_SAFE(tex
, next_tex
, &cf
->tex
, list
) {
940 LIST_INITHEAD(&cf
->tex
);
942 LIST_FOR_EACH_ENTRY_SAFE(vtx
, next_vtx
, &cf
->vtx
, list
) {
946 LIST_INITHEAD(&cf
->vtx
);
951 LIST_INITHEAD(&cf
->list
);
954 void r600_bc_dump(struct r600_bc
*bc
)
959 switch (bc
->chiprev
) {
971 fprintf(stderr
, "bytecode %d dw -----------------------\n", bc
->ndw
);
972 fprintf(stderr
, " %c\n", chip
);
973 for (i
= 0; i
< bc
->ndw
; i
++) {
974 fprintf(stderr
, "0x%08X\n", bc
->bytecode
[i
]);
976 fprintf(stderr
, "--------------------------------------\n");
979 void r600_cf_vtx(struct r600_vertex_element
*ve
, u32
*bytecode
, unsigned count
)
981 struct r600_pipe_state
*rstate
;
985 bytecode
[i
++] = S_SQ_CF_WORD0_ADDR(8 >> 1);
986 bytecode
[i
++] = S_SQ_CF_WORD1_CF_INST(V_SQ_CF_WORD1_SQ_CF_INST_VTX
) |
987 S_SQ_CF_WORD1_BARRIER(1) |
988 S_SQ_CF_WORD1_COUNT(8 - 1);
989 bytecode
[i
++] = S_SQ_CF_WORD0_ADDR(40 >> 1);
990 bytecode
[i
++] = S_SQ_CF_WORD1_CF_INST(V_SQ_CF_WORD1_SQ_CF_INST_VTX
) |
991 S_SQ_CF_WORD1_BARRIER(1) |
992 S_SQ_CF_WORD1_COUNT(count
- 8 - 1);
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(count
- 1);
999 bytecode
[i
++] = S_SQ_CF_WORD0_ADDR(0);
1000 bytecode
[i
++] = S_SQ_CF_WORD1_CF_INST(V_SQ_CF_WORD1_SQ_CF_INST_RETURN
) |
1001 S_SQ_CF_WORD1_BARRIER(1);
1003 rstate
= &ve
->rstate
;
1004 rstate
->id
= R600_PIPE_STATE_FETCH_SHADER
;
1006 r600_pipe_state_add_reg(rstate
, R_0288A4_SQ_PGM_RESOURCES_FS
,
1007 0x00000000, 0xFFFFFFFF, NULL
);
1008 r600_pipe_state_add_reg(rstate
, R_0288DC_SQ_PGM_CF_OFFSET_FS
,
1009 0x00000000, 0xFFFFFFFF, NULL
);
1010 r600_pipe_state_add_reg(rstate
, R_028894_SQ_PGM_START_FS
,
1011 r600_bo_offset(ve
->fetch_shader
) >> 8,
1012 0xFFFFFFFF, ve
->fetch_shader
);
1015 void r600_cf_vtx_tc(struct r600_vertex_element
*ve
, u32
*bytecode
, unsigned count
)
1017 struct r600_pipe_state
*rstate
;
1021 bytecode
[i
++] = S_SQ_CF_WORD0_ADDR(8 >> 1);
1022 bytecode
[i
++] = S_SQ_CF_WORD1_CF_INST(V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC
) |
1023 S_SQ_CF_WORD1_BARRIER(1) |
1024 S_SQ_CF_WORD1_COUNT(8 - 1);
1025 bytecode
[i
++] = S_SQ_CF_WORD0_ADDR(40 >> 1);
1026 bytecode
[i
++] = S_SQ_CF_WORD1_CF_INST(V_SQ_CF_WORD1_SQ_CF_INST_VTX_TC
) |
1027 S_SQ_CF_WORD1_BARRIER(1) |
1028 S_SQ_CF_WORD1_COUNT((count
- 8) - 1);
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(count
- 1);
1035 bytecode
[i
++] = S_SQ_CF_WORD0_ADDR(0);
1036 bytecode
[i
++] = S_SQ_CF_WORD1_CF_INST(V_SQ_CF_WORD1_SQ_CF_INST_RETURN
) |
1037 S_SQ_CF_WORD1_BARRIER(1);
1039 rstate
= &ve
->rstate
;
1040 rstate
->id
= R600_PIPE_STATE_FETCH_SHADER
;
1042 r600_pipe_state_add_reg(rstate
, R_0288A4_SQ_PGM_RESOURCES_FS
,
1043 0x00000000, 0xFFFFFFFF, NULL
);
1044 r600_pipe_state_add_reg(rstate
, R_0288DC_SQ_PGM_CF_OFFSET_FS
,
1045 0x00000000, 0xFFFFFFFF, NULL
);
1046 r600_pipe_state_add_reg(rstate
, R_028894_SQ_PGM_START_FS
,
1047 r600_bo_offset(ve
->fetch_shader
) >> 8,
1048 0xFFFFFFFF, ve
->fetch_shader
);
1051 static void r600_vertex_data_type(enum pipe_format pformat
, unsigned *format
,
1052 unsigned *num_format
, unsigned *format_comp
)
1054 const struct util_format_description
*desc
;
1061 desc
= util_format_description(pformat
);
1062 if (desc
->layout
!= UTIL_FORMAT_LAYOUT_PLAIN
) {
1066 /* Find the first non-VOID channel. */
1067 for (i
= 0; i
< 4; i
++) {
1068 if (desc
->channel
[i
].type
!= UTIL_FORMAT_TYPE_VOID
) {
1073 switch (desc
->channel
[i
].type
) {
1074 /* Half-floats, floats, doubles */
1075 case UTIL_FORMAT_TYPE_FLOAT
:
1076 switch (desc
->channel
[i
].size
) {
1078 switch (desc
->nr_channels
) {
1080 *format
= FMT_16_FLOAT
;
1083 *format
= FMT_16_16_FLOAT
;
1086 *format
= FMT_16_16_16_FLOAT
;
1089 *format
= FMT_16_16_16_16_FLOAT
;
1094 switch (desc
->nr_channels
) {
1096 *format
= FMT_32_FLOAT
;
1099 *format
= FMT_32_32_FLOAT
;
1102 *format
= FMT_32_32_32_FLOAT
;
1105 *format
= FMT_32_32_32_32_FLOAT
;
1114 case UTIL_FORMAT_TYPE_UNSIGNED
:
1116 case UTIL_FORMAT_TYPE_SIGNED
:
1117 switch (desc
->channel
[i
].size
) {
1119 switch (desc
->nr_channels
) {
1127 // *format = FMT_8_8_8; /* fails piglit draw-vertices test */
1130 *format
= FMT_8_8_8_8
;
1135 switch (desc
->nr_channels
) {
1140 *format
= FMT_16_16
;
1143 // *format = FMT_16_16_16; /* fails piglit draw-vertices test */
1146 *format
= FMT_16_16_16_16
;
1151 switch (desc
->nr_channels
) {
1156 *format
= FMT_32_32
;
1159 *format
= FMT_32_32_32
;
1162 *format
= FMT_32_32_32_32
;
1174 if (desc
->channel
[i
].type
== UTIL_FORMAT_TYPE_SIGNED
) {
1177 if (desc
->channel
[i
].normalized
) {
1184 R600_ERR("unsupported vertex format %s\n", util_format_name(pformat
));
1187 void r600_bc(unsigned ndw
, unsigned chiprev
, u32
*bytecode
)
1204 fprintf(stderr
, "bytecode %d dw -----------------------\n", ndw
);
1205 fprintf(stderr
, " %c\n", chip
);
1206 for (i
= 0; i
< ndw
; i
++) {
1207 fprintf(stderr
, "0x%08X\n", bytecode
[i
]);
1209 fprintf(stderr
, "--------------------------------------\n");
1212 int r600_vertex_elements_build_fetch_shader(struct r600_pipe_context
*rctx
, struct r600_vertex_element
*ve
)
1216 unsigned fetch_resource_start
= 0, format
, num_format
, format_comp
;
1217 struct pipe_vertex_element
*elements
= ve
->elements
;
1218 const struct util_format_description
*desc
;
1220 /* 2 dwords for cf aligned to 4 + 4 dwords per input */
1221 ndw
= 8 + ve
->count
* 4;
1222 ve
->fs_size
= ndw
* 4;
1224 /* use PIPE_BIND_VERTEX_BUFFER so we use the cache buffer manager */
1225 ve
->fetch_shader
= r600_bo(rctx
->radeon
, ndw
*4, 256, PIPE_BIND_VERTEX_BUFFER
, 0);
1226 if (ve
->fetch_shader
== NULL
) {
1230 bytecode
= r600_bo_map(rctx
->radeon
, ve
->fetch_shader
, 0, NULL
);
1231 if (bytecode
== NULL
) {
1232 r600_bo_reference(rctx
->radeon
, &ve
->fetch_shader
, NULL
);
1236 if (rctx
->family
>= CHIP_CEDAR
) {
1237 eg_cf_vtx(ve
, &bytecode
[0], (ndw
- 8) / 4);
1239 r600_cf_vtx(ve
, &bytecode
[0], (ndw
- 8) / 4);
1240 fetch_resource_start
= 160;
1243 /* vertex elements offset need special handling, if offset is bigger
1244 * than what we can put in fetch instruction then we need to alterate
1245 * the vertex resource offset. In such case in order to simplify code
1246 * we will bound one resource per elements. It's a worst case scenario.
1248 for (i
= 0; i
< ve
->count
; i
++) {
1249 ve
->vbuffer_offset
[i
] = C_SQ_VTX_WORD2_OFFSET
& elements
[i
].src_offset
;
1250 if (ve
->vbuffer_offset
[i
]) {
1251 ve
->vbuffer_need_offset
= 1;
1255 for (i
= 0; i
< ve
->count
; i
++) {
1256 unsigned vbuffer_index
;
1257 r600_vertex_data_type(ve
->hw_format
[i
], &format
, &num_format
, &format_comp
);
1258 desc
= util_format_description(ve
->hw_format
[i
]);
1260 R600_ERR("unknown format %d\n", ve
->hw_format
[i
]);
1261 r600_bo_reference(rctx
->radeon
, &ve
->fetch_shader
, NULL
);
1265 /* see above for vbuffer_need_offset explanation */
1266 vbuffer_index
= elements
[i
].vertex_buffer_index
;
1267 if (ve
->vbuffer_need_offset
) {
1268 bytecode
[8 + i
* 4 + 0] = S_SQ_VTX_WORD0_BUFFER_ID(i
+ fetch_resource_start
);
1270 bytecode
[8 + i
* 4 + 0] = S_SQ_VTX_WORD0_BUFFER_ID(vbuffer_index
+ fetch_resource_start
);
1272 bytecode
[8 + i
* 4 + 0] |= S_SQ_VTX_WORD0_SRC_GPR(0) |
1273 S_SQ_VTX_WORD0_SRC_SEL_X(0) |
1274 S_SQ_VTX_WORD0_MEGA_FETCH_COUNT(0x1F);
1275 bytecode
[8 + i
* 4 + 1] = S_SQ_VTX_WORD1_DST_SEL_X(desc
->swizzle
[0]) |
1276 S_SQ_VTX_WORD1_DST_SEL_Y(desc
->swizzle
[1]) |
1277 S_SQ_VTX_WORD1_DST_SEL_Z(desc
->swizzle
[2]) |
1278 S_SQ_VTX_WORD1_DST_SEL_W(desc
->swizzle
[3]) |
1279 S_SQ_VTX_WORD1_USE_CONST_FIELDS(0) |
1280 S_SQ_VTX_WORD1_DATA_FORMAT(format
) |
1281 S_SQ_VTX_WORD1_NUM_FORMAT_ALL(num_format
) |
1282 S_SQ_VTX_WORD1_FORMAT_COMP_ALL(format_comp
) |
1283 S_SQ_VTX_WORD1_SRF_MODE_ALL(1) |
1284 S_SQ_VTX_WORD1_GPR_DST_GPR(i
+ 1);
1285 bytecode
[8 + i
* 4 + 2] = S_SQ_VTX_WORD2_OFFSET(elements
[i
].src_offset
) |
1286 S_SQ_VTX_WORD2_MEGA_FETCH(1);
1287 bytecode
[8 + i
* 4 + 3] = 0;
1289 r600_bo_unmap(rctx
->radeon
, ve
->fetch_shader
);