2 * Copyright (C) 2011, 2012 glevand <geoffrey.levand@mail.ru>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer,
10 * without modification, immediately at the beginning of the file.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 #include <sys/ioctl.h>
40 #include "ps3gpu_ctl.h"
41 #include "ps3gpu_mth.h"
45 setup_control(int fd
, int context_id
, unsigned long put
, unsigned long get
,
48 struct ps3gpu_ctl_setup_control setup_control
;
50 setup_control
.context_id
= context_id
;
51 setup_control
.put
= put
;
52 setup_control
.get
= get
;
53 setup_control
.ref
= ref
;
55 return (ioctl(fd
, PS3GPU_CTL_SETUP_CONTROL
, &setup_control
));
59 memory_allocate(int fd
, int context_id
, int type
, int size
, int align
,
60 unsigned long *handle
, unsigned int *gpu_addr
, void **map
)
62 struct ps3gpu_ctl_memory_allocate memory_allocate
;
63 struct ps3gpu_ctl_memory_free memory_free
;
66 memory_allocate
.context_id
= context_id
;
67 memory_allocate
.type
= type
;
68 memory_allocate
.size
= size
;
69 memory_allocate
.align
= align
;
71 err
= ioctl(fd
, PS3GPU_CTL_MEMORY_ALLOCATE
, &memory_allocate
);
76 *handle
= memory_allocate
.handle
;
79 *gpu_addr
= memory_allocate
.gpu_addr
;
82 *map
= mmap(NULL
, memory_allocate
.size
,
83 PROT_READ
| PROT_WRITE
, MAP_SHARED
, fd
, memory_allocate
.handle
);
84 if (*map
== (void *) MAP_FAILED
) {
85 memory_free
.context_id
= context_id
;
86 memory_free
.handle
= memory_allocate
.handle
;
88 ioctl(fd
, PS3GPU_CTL_MEMORY_FREE
, &memory_free
);
98 display_buffer_set(int fd
, int context_id
, int buffer_id
, int width
, int height
,
99 int pitch
, unsigned long offset
)
101 struct ps3gpu_ctl_display_buffer_set display_buffer_set
;
103 display_buffer_set
.context_id
= context_id
;
104 display_buffer_set
.buffer_id
= buffer_id
;
105 display_buffer_set
.width
= width
;
106 display_buffer_set
.height
= height
;
107 display_buffer_set
.pitch
= pitch
;
108 display_buffer_set
.offset
= offset
;
110 return (ioctl(fd
, PS3GPU_CTL_DISPLAY_BUFFER_SET
, &display_buffer_set
));
114 set_flip_mode(int fd
, int context_id
, int head
, int mode
)
116 struct ps3gpu_ctl_set_flip_mode set_flip_mode
;
118 set_flip_mode
.context_id
= context_id
;
119 set_flip_mode
.head
= head
;
120 set_flip_mode
.mode
= mode
;
122 return (ioctl(fd
, PS3GPU_CTL_SET_FLIP_MODE
, &set_flip_mode
));
126 reset_flip_status(int fd
, int context_id
, int head
)
128 struct ps3gpu_ctl_reset_flip_status reset_flip_status
;
130 reset_flip_status
.context_id
= context_id
;
131 reset_flip_status
.head
= head
;
133 return (ioctl(fd
, PS3GPU_CTL_RESET_FLIP_STATUS
, &reset_flip_status
));
137 flip(int fd
, int context_id
, int head
, unsigned long offset
)
139 struct ps3gpu_ctl_flip flip
;
141 flip
.context_id
= context_id
;
143 flip
.offset
= offset
;
145 return (ioctl(fd
, PS3GPU_CTL_FLIP
, &flip
));
149 get_tiled_pitch_size(uint32_t pitch
)
151 static const uint32_t tile_pitches
[] = {
152 0x00000000, 0x00000200, 0x00000300, 0x00000400,
153 0x00000500, 0x00000600, 0x00000700, 0x00000800,
154 0x00000a00, 0x00000c00, 0x00000d00, 0x00000e00,
155 0x00001000, 0x00001400, 0x00001800, 0x00001a00,
156 0x00001c00, 0x00002000, 0x00002800, 0x00003000,
157 0x00003400, 0x00003800, 0x00004000, 0x00005000,
158 0x00006000, 0x00006800, 0x00007000, 0x00008000,
159 0x0000a000, 0x0000c000, 0x0000d000, 0x0000e000,
165 for (i
= 0; i
< ARRAY_SIZE(tile_pitches
) - 1; i
++) {
166 if ((tile_pitches
[i
] < pitch
) && (pitch
<= tile_pitches
[i
+ 1]))
167 return (tile_pitches
[i
+ 1]);
174 save_image(const char *filename
, const char *buf
, int len
)
180 fp
= fopen(filename
, "w");
184 nwritten
= fwrite(buf
, 1, len
, fp
);
194 dump_fifo(FILE *fp
, const uint32_t *fifo
, unsigned int word_count
)
198 while (word_count
--) {
199 fprintf(fp
, "%08x: %08x\n", i
* 4, fifo
[i
]);
205 set_reference(uint32_t *fifo
, uint32_t val
)
209 fifo
[i
++] = PS3GPU_MTH_HDR(1, 0, PS3GPU_MTH_ADDR_REF
);
216 transfer_data(uint32_t *fifo
, uint32_t src
, uint32_t dst
,
217 uint32_t dst_offset
, int32_t dst_pitch
, uint32_t src_offset
, int32_t src_pitch
,
218 uint32_t row_length
, uint32_t row_count
)
223 fifo
[i
++] = PS3GPU_MTH_HDR(2, 1, 0x184);
232 fifo
[i
++] = PS3GPU_MTH_HDR(8, 1, 0x30c);
233 fifo
[i
++] = src_offset
;
234 fifo
[i
++] = dst_offset
;
235 fifo
[i
++] = src_pitch
;
236 fifo
[i
++] = dst_pitch
;
237 fifo
[i
++] = row_length
;
239 fifo
[i
++] = 0x00000101;
240 fifo
[i
++] = 0x00000000;
242 src_offset
+= h
* src_pitch
;
243 dst_offset
+= h
* dst_pitch
;
247 fifo
[i
++] = PS3GPU_MTH_HDR(1, 1, 0x310);
248 fifo
[i
++] = 0x00000000;
254 transfer_inline(uint32_t *fifo
, uint32_t dst
, uint32_t dst_offset
,
255 const uint32_t *data
, uint32_t word_count
)
257 int odd
= word_count
& 1;
260 fifo
[i
++] = PS3GPU_MTH_HDR(1, 3, 0x188);
263 fifo
[i
++] = PS3GPU_MTH_HDR(1, 3, 0x30c);
264 fifo
[i
++] = dst_offset
& ~0x3f;
266 fifo
[i
++] = PS3GPU_MTH_HDR(2, 3, 0x300);
267 fifo
[i
++] = 0x0000000b;
268 fifo
[i
++] = 0x10001000;
270 fifo
[i
++] = PS3GPU_MTH_HDR(3, 5, 0x304);
271 fifo
[i
++] = (dst_offset
>> 2) & 0xf;
272 fifo
[i
++] = 0x00010000 | word_count
;
273 fifo
[i
++] = 0x00010000 | word_count
;
275 fifo
[i
++] = PS3GPU_MTH_HDR((word_count
+ 1) & ~1, 5, 0x400);
281 fifo
[i
++] = 0x00000000;
287 flip_display_buffer(uint32_t *fifo
, uint8_t channel_id
, uint8_t buffer_id
,
292 /* reset flip label */
294 fifo
[i
++] = PS3GPU_MTH_HDR(1, 0, 0x64);
295 fifo
[i
++]= (head
<< 4);
297 fifo
[i
++] = PS3GPU_MTH_HDR(1, 0, 0x6c);
298 fifo
[i
++] = 0x00000001;
300 /* 0xcafebabe flip method */
302 fifo
[i
++] = PS3GPU_MTH_HDR(1, 7, 0x920 + (head
<< 2));
303 fifo
[i
++] = 0x80000000 | (channel_id
<< 8) | buffer_id
;
309 set_depth_mask(uint32_t *fifo
, uint32_t mask
)
313 fifo
[i
++] = PS3GPU_MTH_HDR(1, 0, PS3GPU_MTH_ADDR_DEPTH_MASK
);
320 set_color_mask(uint32_t *fifo
, uint32_t mask
)
324 fifo
[i
++] = PS3GPU_MTH_HDR(1, 0, PS3GPU_MTH_ADDR_COLOR_MASK
);
331 set_color_mask_mrt(uint32_t *fifo
, uint32_t mask
)
335 fifo
[i
++] = PS3GPU_MTH_HDR(1, 0, PS3GPU_MTH_ADDR_COLOR_MASK_MRT
);
342 set_clear_color(uint32_t *fifo
, uint32_t color
)
346 fifo
[i
++] = PS3GPU_MTH_HDR(1, 0, PS3GPU_MTH_ADDR_CLEAR_COLOR
);
353 set_scissor(uint32_t *fifo
, uint16_t x
, uint16_t y
, uint16_t w
, uint16_t h
)
357 fifo
[i
++] = PS3GPU_MTH_HDR(2, 0, PS3GPU_MTH_ADDR_SCISSOR
);
358 fifo
[i
++] = (w
<< 16) | x
;
359 fifo
[i
++] = (h
<< 16) | y
;
365 set_front_poly_mode(uint32_t *fifo
, uint32_t mode
)
369 fifo
[i
++] = PS3GPU_MTH_HDR(1, 0, 0x1828);
376 set_shade_mode(uint32_t *fifo
, uint32_t mode
)
380 fifo
[i
++] = PS3GPU_MTH_HDR(1, 0, 0x368);
387 blend_enable(uint32_t *fifo
, uint32_t enable
)
391 fifo
[i
++] = PS3GPU_MTH_HDR(1, 0, 0x310);
398 clear_surface(uint32_t *fifo
, uint32_t mask
)
402 fifo
[i
++] = PS3GPU_MTH_HDR(1, 0, 0x1d94);
405 fifo
[i
++] = PS3GPU_MTH_HDR(1, 0, 0x100);
406 fifo
[i
++] = 0x00000000;
412 set_surface(uint32_t *fifo
, const struct surface_desc
*sd
)
416 fifo
[i
++] = PS3GPU_MTH_HDR(1, 0, 0x194);
417 fifo
[i
++] = sd
->sd_color_loc
[0];
419 fifo
[i
++] = PS3GPU_MTH_HDR(1, 0, 0x18c);
420 fifo
[i
++] = sd
->sd_color_loc
[1];
422 fifo
[i
++] = PS3GPU_MTH_HDR(2, 0, 0x1b4);
423 fifo
[i
++] = sd
->sd_color_loc
[2];
424 fifo
[i
++] = sd
->sd_color_loc
[3];
426 fifo
[i
++] = PS3GPU_MTH_HDR(1, 0, 0x198);
427 fifo
[i
++] = sd
->sd_depth_loc
;
429 fifo
[i
++] = PS3GPU_MTH_HDR(6, 0, 0x208);
430 fifo
[i
++] = ((uint8_t) log2(sd
->sd_h
) << 24) | ((uint8_t) log2(sd
->sd_w
) << 16) |
431 (0x0 << 12) | (0x1 << 8) |
432 (sd
->sd_depth_fmt
<< 5) | sd
->sd_color_fmt
;
433 fifo
[i
++] = sd
->sd_color_pitch
[0];
434 fifo
[i
++] = sd
->sd_color_off
[0];
435 fifo
[i
++] = sd
->sd_depth_off
;
436 fifo
[i
++] = sd
->sd_color_off
[1];
437 fifo
[i
++] = sd
->sd_color_pitch
[1];
439 fifo
[i
++] = PS3GPU_MTH_HDR(1, 0, 0x22c);
440 fifo
[i
++] = sd
->sd_depth_pitch
;
442 fifo
[i
++] = PS3GPU_MTH_HDR(4, 0, 0x280);
443 fifo
[i
++] = sd
->sd_color_pitch
[2];
444 fifo
[i
++] = sd
->sd_color_pitch
[3];
445 fifo
[i
++] = sd
->sd_color_off
[2];
446 fifo
[i
++] = sd
->sd_color_off
[3];
448 fifo
[i
++] = PS3GPU_MTH_HDR(1, 0, 0x220);
449 fifo
[i
++] = sd
->sd_color_target
;
451 fifo
[i
++] = PS3GPU_MTH_HDR(1, 0, 0x2b8);
452 fifo
[i
++] = (sd
->sd_y
<< 16) | sd
->sd_x
;
454 fifo
[i
++] = PS3GPU_MTH_HDR(2, 0, 0x200);
455 fifo
[i
++] = (sd
->sd_w
<< 16) | sd
->sd_x
;
456 fifo
[i
++] = (sd
->sd_h
<< 16) | sd
->sd_y
;
458 fifo
[i
++] = PS3GPU_MTH_HDR(1, 0, 0x1d88);
459 fifo
[i
++] = (0x0 << 16) | (0x1 << 12) |
460 (sd
->sd_h
- ((sd
->sd_h
>> 12) & 0x1));
466 wait_label(uint32_t *fifo
, uint32_t index
, uint32_t val
)
470 fifo
[i
++] = PS3GPU_MTH_HDR(1, 0, 0x64);
471 fifo
[i
++] = index
<< 4;
473 fifo
[i
++] = PS3GPU_MTH_HDR(1, 0, 0x68);
480 write_label(uint32_t *fifo
, uint32_t index
, uint32_t val
)
484 fifo
[i
++] = PS3GPU_MTH_HDR(1, 0, 0x64);
485 fifo
[i
++] = index
<< 4;
487 fifo
[i
++] = PS3GPU_MTH_HDR(1, 0, 0x6c);
494 write_backend_label(uint32_t *fifo
, uint32_t index
, uint32_t val
)
498 fifo
[i
++] = PS3GPU_MTH_HDR(1, 0, 0x1d6c);
499 fifo
[i
++] = index
<< 4;
501 fifo
[i
++] = PS3GPU_MTH_HDR(1, 0, 0x1d70);
502 fifo
[i
++] = (val
& 0xff00ff00) | ((val
& 0xff) << 16) | ((val
>> 16) & 0xff);
508 write_texture_label(uint32_t *fifo
, uint32_t index
, uint32_t val
)
512 fifo
[i
++] = PS3GPU_MTH_HDR(1, 0, 0x1d6c);
513 fifo
[i
++] = index
<< 4;
515 fifo
[i
++] = PS3GPU_MTH_HDR(1, 0, 0x1d74);
522 set_viewport(uint32_t *fifo
, uint16_t x
, uint16_t y
, uint16_t w
, uint16_t h
,
523 float zmin
, float zmax
, const float offset
[4], const float scale
[4])
527 fifo
[i
++] = PS3GPU_MTH_HDR(2, 0, 0xa00);
528 fifo
[i
++] = (w
<< 16) | x
;
529 fifo
[i
++] = (h
<< 16) | y
;
531 fifo
[i
++] = PS3GPU_MTH_HDR(2, 0, 0x394);
532 fifo
[i
++] = *(uint32_t *) &zmin
;
533 fifo
[i
++] = *(uint32_t *) &zmax
;
535 fifo
[i
++] = PS3GPU_MTH_HDR(8, 0, 0xa20);
536 fifo
[i
++] = *(uint32_t *) &offset
[0];
537 fifo
[i
++] = *(uint32_t *) &offset
[1];
538 fifo
[i
++] = *(uint32_t *) &offset
[2];
539 fifo
[i
++] = *(uint32_t *) &offset
[3];
540 fifo
[i
++] = *(uint32_t *) &scale
[0];
541 fifo
[i
++] = *(uint32_t *) &scale
[1];
542 fifo
[i
++] = *(uint32_t *) &scale
[2];
543 fifo
[i
++] = *(uint32_t *) &scale
[3];
545 fifo
[i
++] = PS3GPU_MTH_HDR(8, 0, 0xa20);
546 fifo
[i
++] = *(uint32_t *) &offset
[0];
547 fifo
[i
++] = *(uint32_t *) &offset
[1];
548 fifo
[i
++] = *(uint32_t *) &offset
[2];
549 fifo
[i
++] = *(uint32_t *) &offset
[3];
550 fifo
[i
++] = *(uint32_t *) &scale
[0];
551 fifo
[i
++] = *(uint32_t *) &scale
[1];
552 fifo
[i
++] = *(uint32_t *) &scale
[2];
553 fifo
[i
++] = *(uint32_t *) &scale
[3];
559 load_vertex_prg(uint32_t *fifo
, uint16_t slot
, const uint32_t *prg
, int instr_count
)
564 fifo
[i
++] = PS3GPU_MTH_HDR(1, 0, 0x1e9c);
567 while (instr_count
>= 32) {
568 fifo
[i
++] = PS3GPU_MTH_HDR(32, 0, 0xb80);
570 for (j
= 0; j
< 32; j
++) {
580 if (instr_count
> 0) {
581 fifo
[i
++] = PS3GPU_MTH_HDR(instr_count
<< 2, 0, 0xb80);
583 for (j
= 0; j
< instr_count
; j
++) {
595 set_vertex_prg_reg_count(uint32_t *fifo
, unsigned int count
)
600 val
= (count
<= 32) ? 0x0020ffff : 0x0030ffff;
602 fifo
[i
++] = PS3GPU_MTH_HDR(1, 0, 0x1ef8);
609 set_vertex_prg_start_slot(uint32_t *fifo
, uint16_t slot
)
613 fifo
[i
++] = PS3GPU_MTH_HDR(1, 0, 0x1ea0);
620 set_vertex_prg_const(uint32_t *fifo
, uint32_t start
, uint32_t count
,
626 while (count
>= 32) {
627 fifo
[i
++] = PS3GPU_MTH_HDR(33, 0, 0x1efc);
630 for (j
= 0; j
< 32; j
++)
631 fifo
[i
++] = *(uint32_t *) val
++;
638 fifo
[i
++] = PS3GPU_MTH_HDR(count
+ 1, 0, 0x1efc);
641 for (j
= 0; j
< count
; j
++)
642 fifo
[i
++] = *(uint32_t *) val
++;
649 set_vertex_attr_inmask(uint32_t *fifo
, uint32_t mask
)
653 fifo
[i
++] = PS3GPU_MTH_HDR(1, 0, 0x1ff0);
660 set_vertex_attr_outmask(uint32_t *fifo
, uint32_t mask
)
664 fifo
[i
++] = PS3GPU_MTH_HDR(1, 0, 0x1ff4);
671 set_frag_prg(uint32_t *fifo
, uint8_t location
, uint32_t offset
)
675 fifo
[i
++] = PS3GPU_MTH_HDR(1, 0, 0x8e4);
676 fifo
[i
++] = offset
| location
;
682 frag_prg_ctrl(uint32_t *fifo
, uint8_t reg_count
, uint8_t replace_txp_with_tex
,
683 uint8_t pixel_kill
, uint8_t output_from_h0
, uint8_t depth_replace
)
693 fifo
[i
++] = PS3GPU_MTH_HDR(1, 0, 0x1d60);
694 fifo
[i
++] = (reg_count
<< 24) | (replace_txp_with_tex
<< 15) | 0x00000400 |
695 (pixel_kill
<< 7) | (!output_from_h0
<< 6) | (depth_replace
<< 1);
701 draw_begin(uint32_t *fifo
, uint32_t mode
)
705 fifo
[i
++] = 0x40000000 | PS3GPU_MTH_HDR(3, 0, 0x1714);
706 fifo
[i
++] = 0x00000000;
707 fifo
[i
++] = 0x00000000;
708 fifo
[i
++] = 0x00000000;
710 fifo
[i
++] = PS3GPU_MTH_HDR(1, 0, 0x1808);
717 draw_end(uint32_t *fifo
)
721 fifo
[i
++] = PS3GPU_MTH_HDR(1, 0, 0x1808);
722 fifo
[i
++] = 0x00000000;
728 set_vertex_data_arrfmt(uint32_t *fifo
, uint8_t reg
, uint16_t freq
,
729 uint8_t stride
, uint8_t size
, uint8_t type
)
733 fifo
[i
++] = PS3GPU_MTH_HDR(1, 0, 0x1740 + (reg
<< 4));
734 fifo
[i
++] = (freq
<< 16) | (stride
<< 8) | (size
<< 4) | type
;
740 set_vertex_data_2f(uint32_t *fifo
, uint8_t reg
, const float val
[2])
744 fifo
[i
++] = PS3GPU_MTH_HDR(2, 0, 0x1880 + (reg
<< 3));
745 fifo
[i
++] = *(uint32_t *) &val
[0];
746 fifo
[i
++] = *(uint32_t *) &val
[1];
752 set_vertex_data_4f(uint32_t *fifo
, uint8_t reg
, const float val
[4])
756 fifo
[i
++] = PS3GPU_MTH_HDR(4, 0, 0x1c00 + (reg
<< 4));
757 fifo
[i
++] = *(uint32_t *) &val
[0];
758 fifo
[i
++] = *(uint32_t *) &val
[1];
759 fifo
[i
++] = *(uint32_t *) &val
[2];
760 fifo
[i
++] = *(uint32_t *) &val
[3];
766 set_vertex_data_arr(uint32_t *fifo
, uint8_t reg
,
767 uint16_t freq
, uint8_t stride
, uint8_t size
, uint8_t type
,
768 uint8_t location
, uint32_t offset
)
772 fifo
[i
++] = PS3GPU_MTH_HDR(1, 0, 0x1740 + (reg
<< 2));
773 fifo
[i
++] = (freq
<< 16) | (stride
<< 8) | (size
<< 4) | type
;
775 fifo
[i
++] = PS3GPU_MTH_HDR(1, 0, 0x1680 + (reg
<< 2));
776 fifo
[i
++] = (location
<< 31) | offset
;
782 draw_arrays(uint32_t *fifo
, uint32_t mode
, uint32_t first
, uint32_t count
)
789 fifo
[i
++] = 0x40000000 | PS3GPU_MTH_HDR(3, 0, 0x1714);
790 fifo
[i
++] = 0x00000000;
791 fifo
[i
++] = 0x00000000;
792 fifo
[i
++] = 0x00000000;
794 fifo
[i
++] = PS3GPU_MTH_HDR(1, 0, 0x1808);
797 fifo
[i
++] = PS3GPU_MTH_HDR(1, 0, 0x1814);
798 fifo
[i
++] = (((count
- 1) & 0xff) << 24) | first
;
800 first
+= ((count
- 1) & 0xff) + 1;
801 count
-= ((count
- 1) & 0xff) + 1;
803 while (count
>= (0x7ff * 0x100)) {
804 fifo
[i
++] = 0x40000000 | PS3GPU_MTH_HDR(0x7ff, 0, 0x1814);
806 for (j
= 0; j
< 0x7ff; j
++) {
807 fifo
[i
++] = ((0x100 - 1) << 24) | first
;
811 count
-= 0x7ff * 0x100;
815 fifo
[i
++] = 0x40000000 | PS3GPU_MTH_HDR(count
, 0, 0x1814);
817 for (j
= 0; j
< count
; j
++) {
818 fifo
[i
++] = ((0x100 - 1) << 24) | first
;
825 fifo
[i
++] = PS3GPU_MTH_HDR(1, 0, 0x1808);
826 fifo
[i
++] = 0x00000000;
832 invalidate_vertex_cache(uint32_t *fifo
)
836 fifo
[i
++] = PS3GPU_MTH_HDR(1, 0, 0x1710);
837 fifo
[i
++] = 0x00000000;
839 fifo
[i
++] = PS3GPU_MTH_HDR(1, 0, 0x1714);
840 fifo
[i
++] = 0x00000000;
842 fifo
[i
++] = PS3GPU_MTH_HDR(1, 0, 0x1714);
843 fifo
[i
++] = 0x00000000;
845 fifo
[i
++] = PS3GPU_MTH_HDR(1, 0, 0x1714);
846 fifo
[i
++] = 0x00000000;
852 set_texture(uint32_t *fifo
, uint8_t index
, const struct texture_desc
*td
)
856 fifo
[i
++] = PS3GPU_MTH_HDR(2, 0, 0x1a00 + (index
<< 5));
857 fifo
[i
++] = td
->td_off
;
858 fifo
[i
++] = (td
->td_mipmap
<< 16) | (td
->td_fmt
<< 8) |
859 (td
->td_dimension
<< 4) | (td
->td_border
<< 3) |
860 (td
->td_cubemap
<< 2) | td
->td_loc
;
862 fifo
[i
++] = PS3GPU_MTH_HDR(1, 0, 0x1a18 + (index
<< 5));
863 fifo
[i
++] = (td
->td_w
<< 16) | td
->td_h
;
865 fifo
[i
++] = PS3GPU_MTH_HDR(1, 0, 0x1840 + (index
<< 2));
866 fifo
[i
++] = (td
->td_depth
<< 20) | td
->td_pitch
;
868 fifo
[i
++] = PS3GPU_MTH_HDR(1, 0, 0x1a10 + (index
<< 5));
869 fifo
[i
++] = td
->td_remap
;
875 texture_ctrl(uint32_t *fifo
, uint8_t index
, uint8_t enable
,
876 uint16_t min_lod
, uint16_t max_lod
, uint8_t max_aniso
)
880 fifo
[i
++] = PS3GPU_MTH_HDR(1, 0, 0x1a0c + (index
<< 5));
881 fifo
[i
++] = (enable
<< 31) | ((min_lod
& 0xfff) << 19) |
882 ((max_lod
& 0xfff) << 7) | (max_aniso
<< 4);
888 set_texture_addr(uint32_t *fifo
, uint8_t index
,
889 uint8_t wrap_s
, uint8_t wrap_t
, uint8_t wrap_r
, uint8_t unsigned_remap
,
890 uint8_t zfunc
, uint8_t gamma
)
894 fifo
[i
++] = PS3GPU_MTH_HDR(1, 0, 0x1a08 + (index
<< 5));
895 fifo
[i
++] = (zfunc
<< 28) | (gamma
<< 20) | (wrap_r
<< 16) |
896 (unsigned_remap
<< 12) | (wrap_t
<< 8) | wrap_s
;
902 set_texture_filter(uint32_t *fifo
, uint8_t index
,
903 uint16_t bias
, uint8_t min
, uint8_t mag
, uint8_t conv
)
907 fifo
[i
++] = PS3GPU_MTH_HDR(1, 0, 0x1a14 + (index
<< 5));
908 fifo
[i
++] = (mag
<< 24) | (min
<< 16) | (conv
<< 13) | (bias
& 0x1fff);
914 invalidate_texture_cache(uint32_t *fifo
, uint32_t val
)
918 fifo
[i
++] = PS3GPU_MTH_HDR(1, 0, 0x1fd8);
925 set_timestamp(uint32_t *fifo
, uint32_t index
)
929 fifo
[i
++] = PS3GPU_MTH_HDR(1, 0, 0x1800);
930 fifo
[i
++] = 0x01000000 | index
<< 4;