transfer FP and vertices to VRAM only once; fix vertex array format parameters
[ps3freebsd_ps3gpu_test.git] / util.h
blob416a00ecc58431afacc61ab6c8e02510a5ee3713
1 /*-
2 * Copyright (C) 2011, 2012 glevand <geoffrey.levand@mail.ru>
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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.
26 * $FreeBSD$
29 #ifndef _UTIL_H
30 #define _UTIL_H
32 #define ARRAY_SIZE(_a) (sizeof(_a) / sizeof((_a)[0]))
33 #define ROUNDUP(_x, _y) ((((_x) + ((_y) - 1)) / (_y)) * (_y))
35 struct surface_desc {
36 uint32_t sd_color_loc[4];
37 uint32_t sd_color_off[4];
38 uint32_t sd_color_pitch[4];
39 uint8_t sd_color_fmt;
40 uint8_t sd_color_target;
41 uint32_t sd_depth_loc;
42 uint32_t sd_depth_off;
43 uint32_t sd_depth_pitch;
44 uint8_t sd_depth_fmt;
45 uint16_t sd_x;
46 uint16_t sd_y;
47 uint16_t sd_w;
48 uint16_t sd_h;
51 static inline void
52 memset32(void *buf, uint32_t val, int word_count)
54 uint32_t *ptr = buf;
56 while (word_count--)
57 *ptr++ = val;
60 static inline uint32_t
61 get_channel_id(const volatile void *driver_info)
63 return (*(uint32_t *) ((uint8_t *) driver_info + 0xc));
66 static inline int
67 get_flip_status(const volatile void *driver_info, uint8_t head)
69 uint32_t val;
71 val = *(uint32_t *) ((uint8_t *) driver_info + 0x10c0 + head * 0x40);
73 return !(val >> 31);
76 static inline int
77 wait_fifo_idle(volatile uint32_t *control)
79 int count = 10000;
81 while (count--) {
82 if (control[0x10] == control[0x11])
83 break;
85 usleep(100);
88 if (control[0x10] != control[0x11])
89 return (-1);
91 return (0);
95 * How to convert image to JPG format:
97 * convert -depth 8 -size 1920x1080 rgba:image.argb \
98 * -channel All -separate -clone 0 -delete 0 -combine -channel BA \
99 * -negate +channel -background white -flatten image.jpg
101 * convert image.jpg -resize 640x480 image_small.jpg
103 int save_image(const char *filename, const char *buf, int len);
105 void dump_fifo(FILE *fp, const uint32_t *fifo, unsigned int word_count);
107 int transfer_data(uint32_t *fifo, uint32_t src, uint32_t dst,
108 uint32_t dst_offset, int32_t dst_pitch,
109 uint32_t src_offset, int32_t src_pitch,
110 uint32_t row_length, uint32_t row_count);
112 int transfer_inline(uint32_t *fifo, uint32_t dst, uint32_t dst_offset,
113 const uint32_t *data, uint32_t word_count);
115 int flip_display_buffer(uint32_t *fifo, uint8_t channel_id, uint8_t buffer_id,
116 uint8_t head);
118 int set_depth_mask(uint32_t *fifo, uint32_t mask);
120 int set_color_mask(uint32_t *fifo, uint32_t mask);
122 int set_color_mask_mrt(uint32_t *fifo, uint32_t mask);
124 int set_clear_color(uint32_t *fifo, uint32_t color);
126 int set_scissor(uint32_t *fifo, uint16_t x, uint16_t y, uint16_t w, uint16_t h);
128 int set_front_poly_mode(uint32_t *fifo, uint32_t mode);
130 int set_shade_mode(uint32_t *fifo, uint32_t mode);
132 int clear_surface(uint32_t *fifo, uint32_t mask);
134 int set_surface(uint32_t *fifo, const struct surface_desc *sd);
136 int wait_label(uint32_t *fifo, uint32_t index, uint32_t val);
138 int set_label(uint32_t *fifo, uint32_t index, uint32_t val);
140 int set_viewport(uint32_t *fifo, uint16_t x, uint16_t y, uint16_t w, uint16_t h,
141 float zmin, float zmax, const float offset[4], const float scale[4]);
143 int load_vertex_prg(uint32_t *fifo, uint16_t slot, const uint32_t *prg, int instr_count);
145 int set_vertex_prg_reg_count(uint32_t *fifo, unsigned int count);
147 int set_vertex_prg_start_slot(uint32_t *fifo, uint16_t slot);
149 int set_vertex_attr_inmask(uint32_t *fifo, uint32_t mask);
151 int set_vertex_attr_outmask(uint32_t *fifo, uint32_t mask);
153 int set_frag_prg(uint32_t *fifo, uint8_t location, uint32_t offset);
155 int frag_prg_ctrl(uint32_t *fifo, uint8_t reg_count, uint8_t replace_txp_with_tex,
156 uint8_t pixel_kill, uint8_t output_from_h0, uint8_t depth_replace);
158 int draw_begin(uint32_t *fifo, uint32_t mode);
160 int draw_end(uint32_t *fifo);
162 int set_vertex_data_arrfmt(uint32_t *fifo, uint8_t reg, uint16_t freq,
163 uint8_t stride, uint8_t size, uint8_t type);
165 int set_vertex_data_4f(uint32_t *fifo, uint8_t reg, const float val[4]);
167 int set_vertex_data_arr(uint32_t *fifo, uint8_t reg,
168 uint16_t freq, uint8_t stride, uint8_t size, uint8_t type,
169 uint8_t location, uint32_t offset);
171 int draw_arrays(uint32_t *fifo, uint32_t mode, uint32_t first, uint32_t count);
173 #endif