add VP register bitmasks
[ps3freebsd_ps3gpu_test.git] / util.h
blob7005686191d31da775dbce55d02f5e320bfb01dc
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);
94 int setup_control(int fd, int context_id, unsigned long put, unsigned long get,
95 unsigned int ref);
97 int memory_allocate(int fd, int context_id, int type, int size, int align,
98 unsigned long *handle, unsigned int *gpu_addr, void **map);
100 int display_buffer_set(int fd, int context_id, int buffer_id, int width, int height,
101 int pitch, unsigned long offset);
103 int set_flip_mode(int fd, int context_id, int head, int mode);
105 int reset_flip_status(int fd, int context_id, int head);
107 int flip(int fd, int context_id, int head, unsigned long offset);
110 * How to convert image to JPG format:
112 * convert -depth 8 -size 1920x1080 rgba:image.argb \
113 * -channel All -separate -clone 0 -delete 0 -combine -channel BA \
114 * -negate +channel -background white -flatten image.jpg
116 * convert image.jpg -resize 640x480 image_small.jpg
118 int save_image(const char *filename, const char *buf, int len);
120 void dump_fifo(FILE *fp, const uint32_t *fifo, unsigned int word_count);
122 int set_reference(uint32_t *fifo, uint32_t val);
124 int transfer_data(uint32_t *fifo, uint32_t src, uint32_t dst,
125 uint32_t dst_offset, int32_t dst_pitch,
126 uint32_t src_offset, int32_t src_pitch,
127 uint32_t row_length, uint32_t row_count);
129 int transfer_inline(uint32_t *fifo, uint32_t dst, uint32_t dst_offset,
130 const uint32_t *data, uint32_t word_count);
132 int flip_display_buffer(uint32_t *fifo, uint8_t channel_id, uint8_t buffer_id,
133 uint8_t head);
135 int set_depth_mask(uint32_t *fifo, uint32_t mask);
137 int set_color_mask(uint32_t *fifo, uint32_t mask);
139 int set_color_mask_mrt(uint32_t *fifo, uint32_t mask);
141 int set_clear_color(uint32_t *fifo, uint32_t color);
143 int set_scissor(uint32_t *fifo, uint16_t x, uint16_t y, uint16_t w, uint16_t h);
145 int set_front_poly_mode(uint32_t *fifo, uint32_t mode);
147 int set_shade_mode(uint32_t *fifo, uint32_t mode);
149 int clear_surface(uint32_t *fifo, uint32_t mask);
151 int set_surface(uint32_t *fifo, const struct surface_desc *sd);
153 int wait_label(uint32_t *fifo, uint32_t index, uint32_t val);
155 int write_label(uint32_t *fifo, uint32_t index, uint32_t val);
157 int write_backend_label(uint32_t *fifo, uint32_t index, uint32_t val);
159 int set_viewport(uint32_t *fifo, uint16_t x, uint16_t y, uint16_t w, uint16_t h,
160 float zmin, float zmax, const float offset[4], const float scale[4]);
162 int load_vertex_prg(uint32_t *fifo, uint16_t slot, const uint32_t *prg, int instr_count);
164 int set_vertex_prg_reg_count(uint32_t *fifo, unsigned int count);
166 int set_vertex_prg_start_slot(uint32_t *fifo, uint16_t slot);
168 int set_vertex_prg_const(uint32_t *fifo, uint32_t start, uint32_t count,
169 const float *val);
172 * 0 ATTR0, POSITION Vertex (float4)
173 * 1 ATTR1, BLENDWEIGHT Vertex weight (float)
174 * 2 ATTR2, NORMAL Normal (float3)
175 * 3 ATTR3, COLOR, COLOR0, DIFFUSE Color (float4)
176 * 4 ATTR4, COLOR1, SPECULAR Secondary color (float4)
177 * 5 ATTR5, FOGCOORD, TESSFACTOR Fog coordinate (float)
178 * 6 ATTR6, PSIZE Point size (float)
179 * 7 ATTR7, BLENDINDICES Palette index for skinning (float4)
180 * 8 ATTR8, TEXCOORD0 Texture coordinate 0 (float4)
181 * 9 ATTR9, TEXCOORD1 Texture coordinate 1 (float4)
182 * 10 ATTR10, TEXCOORD2 Texture coordinate 2 (float4)
183 * 11 ATTR11, TEXCOORD3 Texture coordinate 3 (float4)
184 * 12 ATTR12, TEXCOORD4 Texture coordinate 4 (float4)
185 * 13 ATTR13, TEXCOORD5 Texture coordinate 5 (float4)
186 * 14 ATTR14, TEXCOORD6, TANGENT Texture coordinate 6 (float4) Tangent vector (float4)
187 * 15 ATTR15, TEXCOORD7, BINORMAL Texture coordinate 7 (float4) Binormal vector (float4)
189 int set_vertex_attr_inmask(uint32_t *fifo, uint32_t mask);
192 * 0 COLOR, COLOR0, COL0 Front diffuse color
193 * 1 COLOR1, COL1 Front specular color
194 * 2 BCOL0 Back diffuse color
195 * 3 BCOL1 Back specular color
196 * 4 FOG, FOGC Fog
197 * 5 PSIZE, PSIZ Point size
198 * 6 CLP0 User clip plane 0
199 * 7 CLP1 User clip plane 1
200 * 8 CLP2 User clip plane 2
201 * 9 CLP3 User clip plane 3
202 * 10 CLP4 User clip plane 4
203 * 11 CLP5 User clip plane 5
204 * 12 TEXCOORD8, TEX8 Texture coordinate 8
205 * 13 TEXCOORD9, TEX9 Texture coordinate 9
206 * 14 TEXCOORD0, TEX0 Texture coordinate 0
207 * 15 TEXCOORD1, TEX1 Texture coordinate 1
208 * 16 TEXCOORD2, TEX2 Texture coordinate 2
209 * 17 TEXCOORD3, TEX3 Texture coordinate 3
210 * 18 TEXCOORD4, TEX4 Texture coordinate 4
211 * 19 TEXCOORD5, TEX5 Texture coordinate 5
212 * 20 TEXCOORD6, TEX6 Texture coordinate 6
213 * 21 TEXCOORD7, TEX7 Texture coordinate 7
215 int set_vertex_attr_outmask(uint32_t *fifo, uint32_t mask);
217 int set_frag_prg(uint32_t *fifo, uint8_t location, uint32_t offset);
219 int frag_prg_ctrl(uint32_t *fifo, uint8_t reg_count, uint8_t replace_txp_with_tex,
220 uint8_t pixel_kill, uint8_t output_from_h0, uint8_t depth_replace);
222 int draw_begin(uint32_t *fifo, uint32_t mode);
224 int draw_end(uint32_t *fifo);
226 int set_vertex_data_arrfmt(uint32_t *fifo, uint8_t reg, uint16_t freq,
227 uint8_t stride, uint8_t size, uint8_t type);
229 int set_vertex_data_2f(uint32_t *fifo, uint8_t reg, const float val[2]);
231 int set_vertex_data_4f(uint32_t *fifo, uint8_t reg, const float val[4]);
233 int set_vertex_data_arr(uint32_t *fifo, uint8_t reg,
234 uint16_t freq, uint8_t stride, uint8_t size, uint8_t type,
235 uint8_t location, uint32_t offset);
237 int draw_arrays(uint32_t *fifo, uint32_t mode, uint32_t first, uint32_t count);
239 int invalidate_vertex_cache(uint32_t *fifo);
241 #endif