change back to gcc
[ps3freebsd_ps3gpu_test.git] / util.h
blob3dfca4a447d80f62a06346cc4ebf3a073382f057
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 struct texture_desc {
52 uint8_t td_loc;
53 uint32_t td_off;
54 uint32_t td_pitch;
55 uint16_t td_w;
56 uint16_t td_h;
57 uint8_t td_fmt;
58 uint8_t td_border;
59 uint16_t td_depth;
60 uint8_t td_dimension;
61 uint8_t td_mipmap;
62 uint8_t td_cubemap;
63 uint32_t td_remap;
66 static inline void
67 memset32(void *buf, uint32_t val, int word_count)
69 uint32_t *ptr = buf;
71 while (word_count--)
72 *ptr++ = val;
75 static inline uint32_t
76 get_channel_id(const volatile void *driver_info)
78 return (*(uint32_t *) ((uint8_t *) driver_info + 0xc));
81 static inline uint32_t
82 get_label_area_offset(const volatile void *driver_info)
84 return (*(uint32_t *) ((uint8_t *) driver_info + 0x30));
87 static inline uint32_t
88 get_report_data_area_offset(const volatile void *driver_info)
90 return (*(uint32_t *) ((uint8_t *) driver_info + 0x34));
93 static inline int
94 get_flip_status(const volatile void *driver_info, uint8_t head)
96 uint32_t val;
98 val = *(uint32_t *) ((uint8_t *) driver_info + 0x10c0 + head * 0x40);
100 return !(val >> 31);
103 static inline int
104 wait_fifo_idle(volatile uint32_t *control)
106 int count = 10000;
108 while (count--) {
109 if (control[0x10] == control[0x11])
110 break;
112 usleep(100);
115 if (control[0x10] != control[0x11])
116 return (-1);
118 return (0);
121 static inline uint32_t *
122 get_label_addr(const volatile void *driver_info, const volatile void *reports,
123 uint32_t index)
125 return ((uint32_t *) ((uint8_t *) reports +
126 get_label_area_offset(driver_info) + (index << 4)));
129 static inline uint32_t
130 get_label_value(const volatile void *driver_info, const volatile void *reports,
131 uint32_t index)
133 uint32_t val;
135 val = *get_label_addr(driver_info, reports, index);
137 return (val);
140 static inline uint64_t *
141 get_timestamp_addr(const volatile void *driver_info, const volatile void *reports,
142 uint32_t index)
144 return ((uint64_t *) ((uint8_t *) reports +
145 get_report_data_area_offset(driver_info) + (index << 4)));
148 static inline uint64_t
149 get_timestamp_value(const volatile void *driver_info, const volatile void *reports,
150 uint32_t index)
152 uint64_t val;
154 val = *get_timestamp_addr(driver_info, reports, index);
156 return (val);
159 int setup_control(int fd, int context_id, unsigned long put, unsigned long get,
160 unsigned int ref);
162 int memory_allocate(int fd, int context_id, int type, int size, int align,
163 unsigned long *handle, unsigned int *gpu_addr, void **map);
165 int display_buffer_set(int fd, int context_id, int buffer_id, int width, int height,
166 int pitch, unsigned long offset);
168 int set_flip_mode(int fd, int context_id, int head, int mode);
170 int reset_flip_status(int fd, int context_id, int head);
172 int flip(int fd, int context_id, int head, unsigned long offset);
174 int get_tiled_pitch_size(int pitch);
176 int tile_set(int fd, int context_id, int tile_id, int size, int pitch,
177 int cmp_mode, int bank, int base, unsigned long offset);
179 int tile_unset(int fd, int context_id, int tile_id, int bank,
180 unsigned long offset);
183 * How to convert image to JPG format:
185 * convert -depth 8 -size 1920x1080 rgba:image.argb \
186 * -channel All -separate -clone 0 -delete 0 -combine -channel BA \
187 * -negate +channel -background white -flatten image.jpg
189 * convert image.jpg -resize 640x480 image_small.jpg
191 int save_image(const char *filename, const char *buf, int len);
193 void dump_fifo(FILE *fp, const uint32_t *fifo, unsigned int word_count);
195 int set_reference(uint32_t *fifo, uint32_t val);
197 int transfer_data(uint32_t *fifo, uint32_t src, uint32_t dst,
198 uint32_t dst_offset, int32_t dst_pitch,
199 uint32_t src_offset, int32_t src_pitch,
200 uint32_t row_length, uint32_t row_count);
202 int transfer_inline(uint32_t *fifo, uint32_t dst, uint32_t dst_offset,
203 const uint32_t *data, uint32_t word_count);
205 int flip_display_buffer(uint32_t *fifo, uint8_t channel_id, uint8_t buffer_id,
206 uint8_t head);
208 int set_depth_mask(uint32_t *fifo, uint32_t mask);
210 int set_color_mask(uint32_t *fifo, uint32_t mask);
212 int set_color_mask_mrt(uint32_t *fifo, uint32_t mask);
214 int set_clear_color(uint32_t *fifo, uint32_t color);
216 int set_scissor(uint32_t *fifo, uint16_t x, uint16_t y, uint16_t w, uint16_t h);
218 int set_front_poly_mode(uint32_t *fifo, uint32_t mode);
220 int set_shade_mode(uint32_t *fifo, uint32_t mode);
222 int blend_enable(uint32_t *fifo, uint32_t enable);
224 int clear_surface(uint32_t *fifo, uint32_t mask);
226 int set_surface(uint32_t *fifo, const struct surface_desc *sd);
228 int wait_label(uint32_t *fifo, uint32_t index, uint32_t val);
230 int write_label(uint32_t *fifo, uint32_t index, uint32_t val);
232 int write_backend_label(uint32_t *fifo, uint32_t index, uint32_t val);
234 int write_texture_label(uint32_t *fifo, uint32_t index, uint32_t val);
236 int set_viewport(uint32_t *fifo, uint16_t x, uint16_t y, uint16_t w, uint16_t h,
237 float zmin, float zmax, const float offset[4], const float scale[4]);
239 int load_vertex_prg(uint32_t *fifo, uint16_t slot, const uint32_t *prg, int instr_count);
241 int set_vertex_prg_reg_count(uint32_t *fifo, unsigned int count);
243 int set_vertex_prg_start_slot(uint32_t *fifo, uint16_t slot);
245 int set_vertex_prg_const(uint32_t *fifo, uint32_t start, uint32_t count,
246 const float *val);
249 * 0 ATTR0, POSITION Vertex (float4)
250 * 1 ATTR1, BLENDWEIGHT Vertex weight (float)
251 * 2 ATTR2, NORMAL Normal (float3)
252 * 3 ATTR3, COLOR, COLOR0, DIFFUSE Color (float4)
253 * 4 ATTR4, COLOR1, SPECULAR Secondary color (float4)
254 * 5 ATTR5, FOGCOORD, TESSFACTOR Fog coordinate (float)
255 * 6 ATTR6, PSIZE Point size (float)
256 * 7 ATTR7, BLENDINDICES Palette index for skinning (float4)
257 * 8 ATTR8, TEXCOORD0 Texture coordinate 0 (float4)
258 * 9 ATTR9, TEXCOORD1 Texture coordinate 1 (float4)
259 * 10 ATTR10, TEXCOORD2 Texture coordinate 2 (float4)
260 * 11 ATTR11, TEXCOORD3 Texture coordinate 3 (float4)
261 * 12 ATTR12, TEXCOORD4 Texture coordinate 4 (float4)
262 * 13 ATTR13, TEXCOORD5 Texture coordinate 5 (float4)
263 * 14 ATTR14, TEXCOORD6, TANGENT Texture coordinate 6 (float4) Tangent vector (float4)
264 * 15 ATTR15, TEXCOORD7, BINORMAL Texture coordinate 7 (float4) Binormal vector (float4)
266 int set_vertex_attr_inmask(uint32_t *fifo, uint32_t mask);
269 * 0 COLOR, COLOR0, COL0 Front diffuse color
270 * 1 COLOR1, COL1 Front specular color
271 * 2 BCOL0 Back diffuse color
272 * 3 BCOL1 Back specular color
273 * 4 FOG, FOGC Fog
274 * 5 PSIZE, PSIZ Point size
275 * 6 CLP0 User clip plane 0
276 * 7 CLP1 User clip plane 1
277 * 8 CLP2 User clip plane 2
278 * 9 CLP3 User clip plane 3
279 * 10 CLP4 User clip plane 4
280 * 11 CLP5 User clip plane 5
281 * 12 TEXCOORD8, TEX8 Texture coordinate 8
282 * 13 TEXCOORD9, TEX9 Texture coordinate 9
283 * 14 TEXCOORD0, TEX0 Texture coordinate 0
284 * 15 TEXCOORD1, TEX1 Texture coordinate 1
285 * 16 TEXCOORD2, TEX2 Texture coordinate 2
286 * 17 TEXCOORD3, TEX3 Texture coordinate 3
287 * 18 TEXCOORD4, TEX4 Texture coordinate 4
288 * 19 TEXCOORD5, TEX5 Texture coordinate 5
289 * 20 TEXCOORD6, TEX6 Texture coordinate 6
290 * 21 TEXCOORD7, TEX7 Texture coordinate 7
292 int set_vertex_attr_outmask(uint32_t *fifo, uint32_t mask);
294 int set_frag_prg(uint32_t *fifo, uint8_t location, uint32_t offset);
296 int frag_prg_ctrl(uint32_t *fifo, uint8_t reg_count, uint8_t replace_txp_with_tex,
297 uint8_t pixel_kill, uint8_t output_from_h0, uint8_t depth_replace);
299 int draw_begin(uint32_t *fifo, uint32_t mode);
301 int draw_end(uint32_t *fifo);
303 int set_vertex_data_arrfmt(uint32_t *fifo, uint8_t reg, uint16_t freq,
304 uint8_t stride, uint8_t size, uint8_t type);
306 int set_vertex_data_2f(uint32_t *fifo, uint8_t reg, const float val[2]);
308 int set_vertex_data_4f(uint32_t *fifo, uint8_t reg, const float val[4]);
310 int set_vertex_data_arr(uint32_t *fifo, uint8_t reg,
311 uint16_t freq, uint8_t stride, uint8_t size, uint8_t type,
312 uint8_t location, uint32_t offset);
314 int draw_arrays(uint32_t *fifo, uint32_t mode, uint32_t first, uint32_t count);
316 int invalidate_vertex_cache(uint32_t *fifo);
318 int set_texture(uint32_t *fifo, uint8_t index, const struct texture_desc *td);
320 int texture_ctrl(uint32_t *fifo, uint8_t index, uint8_t enable,
321 uint16_t min_lod, uint16_t max_lod, uint8_t max_aniso);
323 int set_texture_addr(uint32_t *fifo, uint8_t index,
324 uint8_t wrap_s, uint8_t wrap_t, uint8_t wrap_r, uint8_t unsigned_remap,
325 uint8_t zfunc, uint8_t gamma);
327 int set_texture_filter(uint32_t *fifo, uint8_t index,
328 uint16_t bias, uint8_t min, uint8_t mag, uint8_t conv);
330 int invalidate_texture_cache(uint32_t *fifo, uint32_t val);
332 int set_timestamp(uint32_t *fifo, uint32_t index);
334 #endif