KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
pvr.h
Go to the documentation of this file.
1/* KallistiOS ##version##
2
3 dc/pvr.h
4 Copyright (C) 2002 Megan Potter
5 Copyright (C) 2014 Lawrence Sebald
6 Copyright (C) 2023 Ruslan Rostovtsev
7
8 Low-level PVR 3D interface for the DC
9*/
10
11/** \file dc/pvr.h
12 \brief Low-level PVR (3D hardware) interface.
13 \ingroup pvr
14
15 This file provides support for using the PVR 3D hardware in the Dreamcast.
16 Note that this does not handle any sort of perspective transformations or
17 anything of the like. This is just a very thin wrapper around the actual
18 hardware support.
19
20 This file is used for pretty much everything related to the PVR, from memory
21 management to actual primitive rendering.
22
23 \note
24 This API does \a not handle any sort of transformations
25 (including perspective!) so for that, you should look to KGL.
26
27 \author Megan Potter
28 \author Roger Cattermole
29 \author Paul Boese
30 \author Brian Paul
31 \author Lawrence Sebald
32 \author Benoit Miller
33 \author Ruslan Rostovtsev
34*/
35
36#ifndef __DC_PVR_H
37#define __DC_PVR_H
38
39#include <kos/cdefs.h>
40__BEGIN_DECLS
41
42#include <stdalign.h>
43#include <stdbool.h>
44#include <stdint.h>
45
46#include <dc/memory.h>
47#include <arch/types.h>
48#include <dc/sq.h>
49#include <kos/img.h>
50#include <kos/regfield.h>
51
52/* Note: This file also #includes headers from dc/pvr/. They are mostly
53 at the bottom of the file to be able to use types defined throughout. */
54
55#include "pvr/pvr_mem.h"
56#include "pvr/pvr_header.h"
57
58/** \defgroup pvr PowerVR API
59 \brief Low-level PowerVR GPU Driver.
60 \ingroup video
61*/
62
63/* Data types ********************************************************/
64
65/** \defgroup pvr_lists Polygon Lists
66 \brief Types pertaining to PVR list types: opaque, pt, tr, etc
67 \ingroup pvr
68*/
69
70/** \defgroup pvr_geometry Geometry
71 \brief PVR API for managing scene geometry
72 \ingroup pvr
73*/
74
75/** \defgroup pvr_primitives Primitives
76 \brief Polygon and sprite management
77 \ingroup pvr_geometry
78*/
79
80/** \defgroup pvr_ctx Contexts
81 \brief User-friendly intermittent primitive representation
82 \ingroup pvr_primitives
83*/
84
85/** \defgroup pvr_mip_bias Mipmap Bias Modes
86 \brief Mipmap bias modes for PowerVR primitive contexts
87 \ingroup pvr_ctx_texture
88
89 @{
90*/
109/** @} */
110
111/** \defgroup pvr_uv_flip U/V Flip Mode
112 \brief Enable or disable U/V flipping on the PVR
113 \ingroup pvr_ctx_texture
114
115 These flags determine what happens when U/V coordinate values exceed 1.0.
116 In any of the flipped cases, the specified coordinate value will flip around
117 after 1.0, essentially mirroring the image. So, if you displayed an image
118 with a U coordinate of 0.0 on the left hand side and 2.0 on the right hand
119 side with U flipping turned on, you'd have an image that was displayed twice
120 as if mirrored across the middle. This mirroring behavior happens at every
121 unit boundary (so at 2.0 it returns to normal, at 3.0 it flips, etc).
122
123 The default case is to disable mirroring. In addition, clamping of the U/V
124 coordinates by PVR_UVCLAMP_U, PVR_UVCLAMP_V, or PVR_UVCLAMP_UV will disable
125 the mirroring behavior.
126 @{
127*/
128typedef enum pvr_uv_flip {
129 PVR_UVFLIP_NONE, /**< No flipped coordinates */
130 PVR_UVFLIP_V, /**< Flip V only */
131 PVR_UVFLIP_U, /**< Flip U only */
132 PVR_UVFLIP_UV /**< Flip U and V */
134/** @} */
135
136/** \defgroup pvr_uv_clamp U/V Clamp Mode
137 \brief Enable or disable clamping of U/V on the PVR
138 \ingroup pvr_ctx_texture
139
140 These flags determine whether clamping will be applied to U/V coordinate
141 values that exceed 1.0. If enabled, these modes will explicitly override the
142 flip/mirroring modes (PVR_UVFLIP_U, PVR_UVFLIP_V, and PVR_UVFLIP_UV), and
143 will instead ensure that the coordinate(s) in question never exceed 1.0.
144 @{
145*/
146typedef enum pvr_uv_clamp {
147 PVR_UVCLAMP_NONE, /**< Disable clamping */
148 PVR_UVCLAMP_V, /**< Clamp V only */
149 PVR_UVCLAMP_U, /**< Clamp U only */
150 PVR_UVCLAMP_UV /**< Clamp U and V */
152/** @} */
153
154/** \brief PVR polygon context.
155 \ingroup pvr_ctx
156
157 You should use this more human readable format for specifying your polygon
158 contexts, and then compile them into polygon headers when you are ready to
159 start using them.
160
161 This has embedded structures in it for two reasons; the first reason is to
162 make it easier for me to add new stuff later without breaking existing code.
163 The second reason is to make it more readable and usable.
164
165 Unfortunately, it seems that Doxygen chokes up a little bit on this
166 structure, and others like it. The documentation should still be mostly
167 understandable though...
168
169 \headerfile dc/pvr.h
170*/
171typedef struct {
172 pvr_list_t list_type; /**< \brief Primitive list */
173 struct {
174 bool alpha; /**< \brief Enable alpha outside modifier */
175 bool shading; /**< \brief Enable gourad shading */
176 pvr_fog_type_t fog_type; /**< \brief Fog type outside modifier */
177 pvr_cull_mode_t culling; /**< \brief Culling mode */
178 bool color_clamp; /**< \brief Enable color clamping outside modifer */
179 pvr_clip_mode_t clip_mode; /**< \brief Clipping mode */
180 bool modifier_mode; /**< \brief True normal; false: cheap shadow */
181 bool specular; /**< \brief Enable offset color outside modifier */
182 bool alpha2; /**< \brief Enable alpha inside modifier */
183 pvr_fog_type_t fog_type2; /**< \brief Fog type inside modifier */
184 bool color_clamp2; /**< \brief Enable color clamping inside modifer */
185 } gen; /**< \brief General parameters */
186 struct {
187 pvr_blend_mode_t src; /**< \brief Source blending mode outside modifier */
188 pvr_blend_mode_t dst; /**< \brief Dest blending mode outside modifier */
189 bool src_enable; /**< \brief Source blending enable outside modifier */
190 bool dst_enable; /**< \brief Dest blending enable outside modifier */
191 pvr_blend_mode_t src2; /**< \brief Source blending mode inside modifier */
192 pvr_blend_mode_t dst2; /**< \brief Dest blending mode inside modifier */
193 bool src_enable2; /**< \brief Source blending mode inside modifier */
194 bool dst_enable2; /**< \brief Dest blending mode inside modifier */
195 } blend; /**< \brief Blending parameters */
196 struct {
197 pvr_color_fmts_t color; /**< \brief Color format in vertex */
198 bool uv; /**< \brief True: 16-bit floating-point U/Vs; False: 32-bit */
199 bool modifier; /**< \brief Enable modifier effects */
200 } fmt; /**< \brief Format control */
201 struct {
202 pvr_depthcmp_mode_t comparison; /**< \brief Depth comparison mode */
203 bool write; /**< \brief Enable depth writes */
204 } depth; /**< \brief Depth comparison/write modes */
205 struct {
206 bool enable; /**< \brief Enable/disable texturing */
207 pvr_filter_mode_t filter; /**< \brief Filtering mode */
208 bool mipmap; /**< \brief Enable/disable mipmaps */
209 pvr_mip_bias_t mipmap_bias; /**< \brief Mipmap bias */
210 pvr_uv_flip_t uv_flip; /**< \brief Enable/disable U/V flipping */
211 pvr_uv_clamp_t uv_clamp; /**< \brief Enable/disable U/V clamping */
212 bool alpha; /**< \brief True to _disable_ texture alpha */
213 pvr_txr_shading_mode_t env; /**< \brief Texture color contribution */
214 int width; /**< \brief Texture width (requires a power of 2) */
215 int height; /**< \brief Texture height (requires a power of 2) */
216 int format; /**< \brief Texture format
217 \see pvr_txr_fmts */
218 pvr_ptr_t base; /**< \brief Texture pointer */
219 } txr, /**< \brief Texturing params outside modifier */
220 txr2; /**< \brief Texturing params inside modifier */
222
223/** \brief PVR sprite context.
224 \ingroup pvr_ctx
225
226 You should use this more human readable format for specifying your sprite
227 contexts, and then compile them into sprite headers when you are ready to
228 start using them.
229
230 Unfortunately, it seems that Doxygen chokes up a little bit on this
231 structure, and others like it. The documentation should still be mostly
232 understandable though...
233
234 \headerfile dc/pvr.h
235*/
236typedef struct {
237 pvr_list_t list_type; /**< \brief Primitive list */
238 struct {
239 bool alpha; /**< \brief Enable alpha */
240 pvr_fog_type_t fog_type; /**< \brief Fog type */
241 pvr_cull_mode_t culling; /**< \brief Culling mode */
242 bool color_clamp; /**< \brief Enable color clamp */
243 pvr_clip_mode_t clip_mode; /**< \brief Clipping mode */
244 bool specular; /**< \brief Enable offset color */
245 } gen; /**< \brief General parameters */
246 struct {
247 pvr_blend_mode_t src; /**< \brief Source blending mode */
248 pvr_blend_mode_t dst; /**< \brief Dest blending mode */
249 bool src_enable; /**< \brief Source blending enable */
250 bool dst_enable; /**< \brief Dest blending enable */
251 } blend;
252 struct {
253 pvr_depthcmp_mode_t comparison; /**< \brief Depth comparison mode */
254 bool write; /**< \brief Enable depth writes */
255 } depth; /**< \brief Depth comparison/write modes */
256 struct {
257 bool enable; /**< \brief Enable/disable texturing */
258 pvr_filter_mode_t filter; /**< \brief Filtering mode */
259 bool mipmap; /**< \brief Enable/disable mipmaps */
260 pvr_mip_bias_t mipmap_bias; /**< \brief Mipmap bias */
261 pvr_uv_flip_t uv_flip; /**< \brief Enable/disable U/V flipping */
262 pvr_uv_clamp_t uv_clamp; /**< \brief Enable/disable U/V clamping */
263 bool alpha; /**< \brief True to _disable_ texture alpha */
264 pvr_txr_shading_mode_t env; /**< \brief Texture color contribution */
265 int width; /**< \brief Texture width (requires a power of 2) */
266 int height; /**< \brief Texture height (requires a power of 2) */
267 int format; /**< \brief Texture format
268 \see pvr_txr_fmts */
269 pvr_ptr_t base; /**< \brief Texture pointer */
270 } txr; /**< \brief Texturing params */
272
273/* Constants for the above structure; thanks to Benoit Miller for these */
274
275/** \defgroup pvr_ctx_attrib Attributes
276 \brief PVR primitive context attributes
277 \ingroup pvr_ctx
278*/
279
280/** \defgroup pvr_ctx_depth Depth
281 \brief Depth attributes for PVR polygon contexts
282 \ingroup pvr_ctx_attrib
283*/
284
285/** \defgroup pvr_ctx_texture Texture
286 \brief Texture attributes for PVR polygon contexts
287 \ingroup pvr_ctx_attrib
288*/
289
290/** \defgroup pvr_ctx_color Color
291 \brief Color attributes for PowerVR primitive contexts
292 \ingroup pvr_ctx_attrib
293*/
294
295/** \defgroup pvr_txr_fmts Formats
296 \brief PowerVR texture formats
297 \ingroup pvr_txr_mgmt
298
299 These are the texture formats that the PVR supports. Note that some of
300 these, you can OR together with other values.
301
302 @{
303*/
304#define PVR_TXRFMT_NONE 0 /**< \brief No texture */
305#define PVR_TXRFMT_VQ_DISABLE (0 << 30) /**< \brief Not VQ encoded */
306#define PVR_TXRFMT_VQ_ENABLE (1 << 30) /**< \brief VQ encoded */
307#define PVR_TXRFMT_ARGB1555 (0 << 27) /**< \brief 16-bit ARGB1555 */
308#define PVR_TXRFMT_RGB565 (1 << 27) /**< \brief 16-bit RGB565 */
309#define PVR_TXRFMT_ARGB4444 (2 << 27) /**< \brief 16-bit ARGB4444 */
310#define PVR_TXRFMT_YUV422 (3 << 27) /**< \brief YUV422 format */
311#define PVR_TXRFMT_BUMP (4 << 27) /**< \brief Bumpmap format */
312#define PVR_TXRFMT_PAL4BPP (5 << 27) /**< \brief 4BPP paletted format */
313#define PVR_TXRFMT_PAL8BPP (6 << 27) /**< \brief 8BPP paletted format */
314#define PVR_TXRFMT_TWIDDLED (0 << 26) /**< \brief Texture is twiddled */
315#define PVR_TXRFMT_NONTWIDDLED (1 << 26) /**< \brief Texture is not twiddled */
316#define PVR_TXRFMT_POW2_STRIDE (0 << 25) /**< \brief Stride is a power-of-two */
317#define PVR_TXRFMT_X32_STRIDE (1 << 25) /**< \brief Stride is multiple of 32 */
318
319/* Compat. */
320static const uint32_t PVR_TXRFMT_NOSTRIDE __depr("Please use PVR_TXRFMT_POW2_STRIDE.") = PVR_TXRFMT_POW2_STRIDE;
321static const uint32_t PVR_TXRFMT_STRIDE __depr("Please use PVR_TXRFMT_X32_STRIDE. Note this may cause breakage as PVR_TXRFMT_STRIDE was never working correctly." ) = PVR_TXRFMT_X32_STRIDE;
322
323/* OR one of these into your texture format if you need it. Note that
324 these coincide with the twiddled/stride bits, so you can't have a
325 non-twiddled/strided texture that's paletted! */
326
327/** \brief 8BPP palette selector
328
329 \param x The palette index */
330#define PVR_TXRFMT_8BPP_PAL(x) ((x) << 25)
331
332/** \brief 4BPP palette selector
333
334 \param x The palette index */
335#define PVR_TXRFMT_4BPP_PAL(x) ((x) << 21)
336/** @} */
337
338/** \defgroup pvr_ctx_modvol Modifier Volumes
339 \brief PowerVR modifier volume polygon context attributes
340 \ingroup pvr_ctx_attrib
341*/
342
343/** \defgroup pvr_mod_modes Modes
344 \brief Modifier volume modes for PowerVR primitive contexts
345 \ingroup pvr_ctx_modvol
346
347 All triangles in a single modifier volume should be of the other poly type,
348 except for the last one. That should be either of the other two types,
349 depending on whether you want an inclusion or exclusion volume.
350
351 @{
352*/
353#define PVR_MODIFIER_OTHER_POLY 0 /**< \brief Not the last polygon in the volume */
354#define PVR_MODIFIER_INCLUDE_LAST_POLY 1 /**< \brief Last polygon, inclusion volume */
355#define PVR_MODIFIER_EXCLUDE_LAST_POLY 2 /**< \brief Last polygon, exclusion volume */
356/** @} */
357
358/** \defgroup pvr_primitives_headers Headers
359 \brief Compiled headers for polygons and sprites
360 \ingroup pvr_primitives
361
362 @{
363*/
364
365/** \brief PVR polygon header with intensity color.
366
367 This is the equivalent of pvr_poly_hdr_t, but for use with intensity color.
368
369 \headerfile dc/pvr.h
370*/
371#define pvr_poly_ic_hdr pvr_poly_hdr
373
374/** \brief PVR polygon header to be used with modifier volumes.
375
376 This is the equivalent of a pvr_poly_hdr_t for use when a polygon is to be
377 used with modifier volumes.
378
379 \headerfile dc/pvr.h
380*/
381#define pvr_poly_mod_hdr pvr_poly_hdr
383
384/** \brief PVR polygon header specifically for sprites.
385
386 This is the equivalent of a pvr_poly_hdr_t for use when a quad/sprite is to
387 be rendered. Note that the color data is here, not in the vertices.
388
389 \headerfile dc/pvr.h
390*/
391#define pvr_sprite_hdr pvr_poly_hdr
393
394/** \brief Modifier volume header.
395
396 This is the header that should be submitted when dealing with setting a
397 modifier volume.
398
399 \headerfile dc/pvr.h
400*/
401#define pvr_mod_hdr pvr_poly_hdr
403/** @} */
404
405/** \defgroup pvr_vertex_types Vertices
406 \brief PowerVR vertex types
407 \ingroup pvr_geometry
408
409 @{
410*/
411
412/** \brief Generic PVR vertex type.
413
414 The PVR chip itself supports many more vertex types, but this is the main
415 one that can be used with both textured and non-textured polygons, and is
416 fairly fast.
417
418 \headerfile dc/pvr.h
419*/
420typedef struct pvr_vertex {
421 alignas(32)
422 uint32_t flags; /**< \brief TA command (vertex flags) */
423 float x; /**< \brief X coordinate */
424 float y; /**< \brief Y coordinate */
425 float z; /**< \brief Z coordinate */
426 union {
427 struct {
428 float u; /**< \brief Texture U coordinate */
429 float v; /**< \brief Texture V coordinate */
430 };
431 struct {
432 uint32_t argb0; /**< \brief Vertex color when modified, outside area */
433 uint32_t argb1; /**< \brief Vertex color when modified, inside area */
434 };
435 };
436 uint32_t argb; /**< \brief Vertex color */
437 uint32_t oargb; /**< \brief Vertex offset color */
439
440/** \brief PVR vertex type: Non-textured, packed color, affected by modifier
441 volume.
442
443 This vertex type has two copies of colors. The second color is used when
444 enclosed within a modifier volume.
445
446 \headerfile dc/pvr.h
447*/
448typedef struct pvr_vertex_pcm {
449 alignas(32)
450 uint32_t flags; /**< \brief TA command (vertex flags) */
451 float x; /**< \brief X coordinate */
452 float y; /**< \brief Y coordinate */
453 float z; /**< \brief Z coordinate */
454 uint32_t argb0; /**< \brief Vertex color (outside volume) */
455 uint32_t argb1; /**< \brief Vertex color (inside volume) */
456 uint32_t d1; /**< \brief Dummy value */
457 uint32_t d2; /**< \brief Dummy value */
459
460/** \brief PVR vertex type: Textured, packed color, affected by modifier volume.
461
462 Note that this vertex type has two copies of colors, offset colors, and
463 texture coords. The second set of texture coords, colors, and offset colors
464 are used when enclosed within a modifier volume.
465
466 \headerfile dc/pvr.h
467*/
468typedef struct pvr_vertex_tpcm {
469 alignas(32)
470 uint32_t flags; /**< \brief TA command (vertex flags) */
471 float x; /**< \brief X coordinate */
472 float y; /**< \brief Y coordinate */
473 float z; /**< \brief Z coordinate */
474 float u0; /**< \brief Texture U coordinate (outside) */
475 float v0; /**< \brief Texture V coordinate (outside) */
476 uint32_t argb0; /**< \brief Vertex color (outside) */
477 uint32_t oargb0; /**< \brief Vertex offset color (outside) */
478 float u1; /**< \brief Texture U coordinate (inside) */
479 float v1; /**< \brief Texture V coordinate (inside) */
480 uint32_t argb1; /**< \brief Vertex color (inside) */
481 uint32_t oargb1; /**< \brief Vertex offset color (inside) */
482 uint32_t d1; /**< \brief Dummy value */
483 uint32_t d2; /**< \brief Dummy value */
484 uint32_t d3; /**< \brief Dummy value */
485 uint32_t d4; /**< \brief Dummy value */
487
488/** \brief PVR vertex type: Textured sprite.
489
490 This vertex type is to be used with the sprite polygon header and the sprite
491 related commands to draw textured sprites. Note that there is no fourth Z
492 coordinate. I suppose it just gets interpolated?
493
494 The U/V coordinates in here are in the 16-bit per coordinate form. Also,
495 like the fourth Z value, there is no fourth U or V, so it must get
496 interpolated from the others.
497
498 \headerfile dc/pvr.h
499*/
500typedef struct pvr_sprite_txr {
501 alignas(32)
502 uint32_t flags; /**< \brief TA command (vertex flags) */
503 float ax; /**< \brief First X coordinate */
504 float ay; /**< \brief First Y coordinate */
505 float az; /**< \brief First Z coordinate */
506 float bx; /**< \brief Second X coordinate */
507 float by; /**< \brief Second Y coordinate */
508 float bz; /**< \brief Second Z coordinate */
509 float cx; /**< \brief Third X coordinate */
510 float cy; /**< \brief Third Y coordinate */
511 float cz; /**< \brief Third Z coordinate */
512 float dx; /**< \brief Fourth X coordinate */
513 float dy; /**< \brief Fourth Y coordinate */
514 uint32_t dummy; /**< \brief Dummy value */
515 uint32_t auv; /**< \brief First U/V texture coordinates */
516 uint32_t buv; /**< \brief Second U/V texture coordinates */
517 uint32_t cuv; /**< \brief Third U/V texture coordinates */
519
520/** \brief PVR vertex type: Untextured sprite.
521
522 This vertex type is to be used with the sprite polygon header and the sprite
523 related commands to draw untextured sprites (aka, quads).
524*/
525typedef struct pvr_sprite_col {
526 alignas(32)
527 uint32_t flags; /**< \brief TA command (vertex flags) */
528 float ax; /**< \brief First X coordinate */
529 float ay; /**< \brief First Y coordinate */
530 float az; /**< \brief First Z coordinate */
531 float bx; /**< \brief Second X coordinate */
532 float by; /**< \brief Second Y coordinate */
533 float bz; /**< \brief Second Z coordinate */
534 float cx; /**< \brief Third X coordinate */
535 float cy; /**< \brief Third Y coordinate */
536 float cz; /**< \brief Third Z coordinate */
537 float dx; /**< \brief Fourth X coordinate */
538 float dy; /**< \brief Fourth Y coordinate */
539 uint32_t d1; /**< \brief Dummy value */
540 uint32_t d2; /**< \brief Dummy value */
541 uint32_t d3; /**< \brief Dummy value */
542 uint32_t d4; /**< \brief Dummy value */
544
545/** \brief PVR vertex type: Modifier volume.
546
547 This vertex type is to be used with the modifier volume header to specify
548 triangular modifier areas.
549*/
550typedef struct pvr_modifier_vol {
551 alignas(32)
552 uint32_t flags; /**< \brief TA command (vertex flags) */
553 float ax; /**< \brief First X coordinate */
554 float ay; /**< \brief First Y coordinate */
555 float az; /**< \brief First Z coordinate */
556 float bx; /**< \brief Second X coordinate */
557 float by; /**< \brief Second Y coordinate */
558 float bz; /**< \brief Second Z coordinate */
559 float cx; /**< \brief Third X coordinate */
560 float cy; /**< \brief Third Y coordinate */
561 float cz; /**< \brief Third Z coordinate */
562 uint32_t d1; /**< \brief Dummy value */
563 uint32_t d2; /**< \brief Dummy value */
564 uint32_t d3; /**< \brief Dummy value */
565 uint32_t d4; /**< \brief Dummy value */
566 uint32_t d5; /**< \brief Dummy value */
567 uint32_t d6; /**< \brief Dummy value */
569
570/** @} */
571
572/** \defgroup pvr_commands TA Command Values
573 \brief Command values for submitting data to the TA
574 \ingroup pvr_primitives_headers
575
576 These are are appropriate values for TA commands. Use whatever goes with the
577 primitive type you're using.
578
579 @{
580*/
581#define PVR_CMD_POLYHDR 0x80840000 /**< \brief PVR polygon header.
582Striplength set to 2 */
583#define PVR_CMD_VERTEX 0xe0000000 /**< \brief PVR vertex data */
584#define PVR_CMD_VERTEX_EOL 0xf0000000 /**< \brief PVR vertex, end of strip */
585#define PVR_CMD_USERCLIP 0x20000000 /**< \brief PVR user clipping area */
586#define PVR_CMD_MODIFIER 0x80000000 /**< \brief PVR modifier volume */
587#define PVR_CMD_SPRITE 0xA0000000 /**< \brief PVR sprite header */
588/** @} */
589
590/** \defgroup pvr_bitmasks Constants and Masks
591 \brief Polygon header constants and masks
592 \ingroup pvr_primitives_headers
593
594 Note that thanks to the arrangement of constants, this is mainly a matter of
595 bit shifting to compile headers...
596
597 @{
598*/
599#define PVR_TA_CMD_TYPE GENMASK(26, 24)
600#define PVR_TA_CMD_USERCLIP GENMASK(17, 16)
601#define PVR_TA_CMD_MODIFIER BIT(7)
602#define PVR_TA_CMD_MODIFIERMODE BIT(6)
603#define PVR_TA_CMD_CLRFMT GENMASK(5, 4)
604#define PVR_TA_CMD_TXRENABLE BIT(3)
605#define PVR_TA_CMD_SPECULAR BIT(2)
606#define PVR_TA_CMD_SHADE BIT(1)
607#define PVR_TA_CMD_UVFMT BIT(0)
608#define PVR_TA_PM1_DEPTHCMP GENMASK(31, 29)
609#define PVR_TA_PM1_CULLING GENMASK(28, 27)
610#define PVR_TA_PM1_DEPTHWRITE BIT(26)
611#define PVR_TA_PM1_TXRENABLE BIT(25)
612#define PVR_TA_PM1_MODIFIERINST GENMASK(30, 29)
613#define PVR_TA_PM2_SRCBLEND GENMASK(31, 29)
614#define PVR_TA_PM2_DSTBLEND GENMASK(28, 26)
615#define PVR_TA_PM2_SRCENABLE BIT(25)
616#define PVR_TA_PM2_DSTENABLE BIT(24)
617#define PVR_TA_PM2_FOG GENMASK(23, 22)
618#define PVR_TA_PM2_CLAMP BIT(21)
619#define PVR_TA_PM2_ALPHA BIT(20)
620#define PVR_TA_PM2_TXRALPHA BIT(19)
621#define PVR_TA_PM2_UVFLIP GENMASK(18, 17)
622#define PVR_TA_PM2_UVCLAMP GENMASK(16, 15)
623#define PVR_TA_PM2_FILTER GENMASK(14, 13)
624#define PVR_TA_PM2_MIPBIAS GENMASK(11, 8)
625#define PVR_TA_PM2_TXRENV GENMASK(7, 6)
626#define PVR_TA_PM2_USIZE GENMASK(5, 3)
627#define PVR_TA_PM2_VSIZE GENMASK(2, 0)
628#define PVR_TA_PM3_MIPMAP BIT(31)
629#define PVR_TA_PM3_TXRFMT GENMASK(30, 21)
630/** @} */
631
632/* Initialization ****************************************************/
633/** \defgroup pvr_init Initialization
634 \brief Driver initialization and shutdown
635 \ingroup pvr
636
637 Initialization and shutdown: stuff you should only ever have to do
638 once in your program.
639*/
640
641/** \defgroup pvr_binsizes Primitive Bin Sizes
642 \brief Available sizes for primitive bins
643 \ingroup pvr_init
644 @{
645*/
646#define PVR_BINSIZE_0 0 /**< \brief 0-length (disables the list) */
647#define PVR_BINSIZE_8 8 /**< \brief 8-word (32-byte) length */
648#define PVR_BINSIZE_16 16 /**< \brief 16-word (64-byte) length */
649#define PVR_BINSIZE_32 32 /**< \brief 32-word (128-byte) length */
650/** @} */
651
652/** \brief PVR initialization structure
653 \ingroup pvr_init
654
655 This structure defines how the PVR initializes various parts of the system,
656 including the primitive bin sizes, the vertex buffer size, and whether
657 vertex DMA will be enabled.
658
659 You essentially fill one of these in, and pass it to pvr_init().
660
661 \headerfile dc/pvr.h
662 \sa pvr_default_params
663*/
664typedef struct {
665 /** \brief Bin sizes.
666
667 The bins go in the following order: opaque polygons, opaque modifiers,
668 translucent polygons, translucent modifiers, punch-thrus
669 */
670 int opb_sizes[5];
671
672 /** \brief Vertex buffer size (should be a nice round number) */
674
675 /** \brief Enable vertex DMA?
676
677 Set to non-zero if we want to enable vertex DMA mode. Note that if this
678 is set, then _all_ enabled lists need to have a vertex buffer assigned,
679 even if you never use that list for anything.
680 */
682
683 /** \brief Enable horizontal scaling?
684
685 Set to non-zero if horizontal scaling is to be enabled. By enabling this
686 setting and stretching your image to double the native screen width, you
687 can get horizontal full-screen anti-aliasing. */
689
690 /** \brief Disable translucent polygon autosort?
691
692 Set to non-zero to disable translucent polygon autosorting. By enabling
693 this setting, the PVR acts more like a traditional Z-buffered system
694 when rendering translucent polygons, meaning you must pre-sort them
695 yourself if you want them to appear in the right order. */
697
698
699 /** \brief OPB Overflow Count.
700
701 Preallocates this many extra OPBs (sets of tile bins), allowing the PVR
702 to use the extra space when there's too much geometry in the first OPB.
703
704 Increasing this value can eliminate artifacts where pieces of geometry
705 flicker in and out of existence along the tile boundaries. */
706
708
709 /** \brief Disable vertex buffer double-buffering.
710
711 Use only one single vertex buffer. This means that the PVR must finish
712 rendering before the Tile Accelerator is used to prepare a new frame;
713 but it allows using much smaller vertex buffers. */
715
717
718/** \brief PVR initialization structure defaults
719 \ingroup pvr_init
720
721 These are the default values for pvr_init_params_t used by pvr_init_defaults().
722
723 \sa pvr_init_defaults()
724*/
727 .vertex_buf_size = 512 * 1024,
728 .opb_overflow_count = 3
729};
730
731/** \brief Initialize the PVR chip to ready status.
732 \ingroup pvr_init
733
734 This function enables the specified lists and uses the specified parameters.
735 Note that bins and vertex buffers come from the texture memory pool, so only
736 allocate what you actually need. Expects that a 2D mode was initialized
737 already using the vid_* API.
738
739 \param params The set of parameters to initialize with
740 \retval 0 On success
741 \retval -1 If the PVR has already been initialized or the video
742 mode active is not suitable for 3D
743*/
745
746/** \brief Simple PVR initialization.
747 \ingroup pvr_init
748
749 This simpler function initializes the PVR using the default parameters defined in
750 pvr_default_params.
751
752 \retval 0 On success
753 \retval -1 If the PVR has already been initialized or the video
754 mode active is not suitable for 3D
755
756 \sa pvr_default_params
757*/
759
760/** \brief Shut down the PVR chip from ready status.
761 \ingroup pvr_init
762
763 This essentially leaves the video system in 2D mode as it was before the
764 init.
765
766 \retval 0 On success
767 \retval -1 If the PVR has not been initialized
768*/
769int pvr_shutdown(void);
770
771
772/* Scene rendering ***************************************************/
773/** \defgroup pvr_scene_mgmt Scene Submission
774 \brief PowerVR API for submitting scene geometry
775 \ingroup pvr
776
777 This API is used to submit triangle strips to the PVR via the TA
778 interface in the chip.
779
780 An important side note about the PVR is that all primitive types
781 must be submitted grouped together. If you have 10 polygons for each
782 list type, then the PVR must receive them via the TA by list type,
783 with a list delimiter in between.
784
785 So there are two modes you can use here. The first mode allows you to
786 submit data directly to the TA. Your data will be forwarded to the
787 chip for processing as it is fed to the PVR module. If your data
788 is easily sorted into the primitive types, then this is the fastest
789 mode for submitting data.
790
791 The second mode allows you to submit data via main-RAM vertex buffers,
792 which will be queued until the proper primitive type is active. In this
793 case, each piece of data is copied into the vertex buffer while the
794 wrong list is activated, and when the proper list becomes activated,
795 the data is all sent at once. Ideally this would be via DMA, right
796 now it is by store queues. This has the advantage of allowing you to
797 send data in any order and have the PVR functions resolve how it should
798 get sent to the hardware, but it is slower.
799
800 The nice thing is that any combination of these modes can be used. You
801 can assign a vertex buffer for any list, and it will be used to hold the
802 incoming vertex data until the proper list has come up. Or if the proper
803 list is already up, the data will be submitted directly. So if most of
804 your polygons are opaque, and you only have a couple of translucents,
805 you can set a small buffer to gather translucent data and then it will
806 get sent when you do a pvr_end_scene().
807
808 Thanks to Mikael Kalms for the idea for this API.
809
810 \note
811 Another somewhat subtle point that bears mentioning is that in the normal
812 case (interrupts enabled) an interrupt handler will automatically take
813 care of starting a frame rendering (after scene_finish()) and also
814 flipping pages when appropriate.
815*/
816
817/** \defgroup pvr_vertex_dma Vertex DMA
818 \brief Use the DMA to transfer inactive lists to the PVR
819 \ingroup pvr_scene_mgmt
820*/
821
822/** \brief Is vertex DMA enabled?
823 \ingroup pvr_vertex_dma
824
825 \return Non-zero if vertex DMA was enabled at init time
826*/
828
829/** \brief Setup a vertex buffer for one of the list types.
830 \ingroup pvr_list_mgmt
831
832 If the specified list type already has a vertex buffer, it will be replaced
833 by the new one.
834
835 \note
836 Each buffer should actually be twice as long as what you will need to hold
837 two frames worth of data).
838
839 \warning
840 You should generally not try to do this at any time besides before a frame
841 is begun, or Bad Things May Happen.
842
843 \param list The primitive list to set the buffer for.
844 \param buffer The location of the buffer in main RAM. This must be
845 aligned to a 32-byte boundary.
846 \param len The length of the buffer. This must be a multiple of
847 64, and must be at least 128 (even if you're not
848 using the list).
849
850 \return The old buffer location (if any)
851*/
852void *pvr_set_vertbuf(pvr_list_t list, void *buffer, size_t len);
853
854/** \brief Retrieve a pointer to the current output location in the DMA buffer
855 for the requested list.
856 \ingroup pvr_vertex_dma
857
858 Vertex DMA must globally be enabled for this to work. Data may be added to
859 this buffer by the user program directly; however, make sure to call
860 pvr_vertbuf_written() to notify the system of any such changes.
861
862 \param list The primitive list to get the buffer for.
863
864 \return The tail of that list's buffer.
865*/
867
868/** \brief Notify the PVR system that data have been written into the output
869 buffer for the given list.
870 \ingroup pvr_vertex_dma
871
872 This should always be done after writing data directly to these buffers or
873 it will get overwritten by other data.
874
875 \param list The primitive list that was modified.
876 \param amt Number of bytes written. Must be a multiple of 32.
877*/
879
880/** \brief Begin collecting data for a frame of 3D output to the off-screen
881 frame buffer.
882 \ingroup pvr_scene_mgmt
883
884 You must call this function (or pvr_scene_begin_rtt()) for ever frame of
885 output.
886*/
888
889/** \brief Begin collecting data for a frame of 3D output to the specified
890 texture.
891 \ingroup pvr_scene_mgmt
892 \deprecated Use pvr_scene_begin_rtt() instead.
893
894 This function currently only supports outputting at the same size as the
895 actual screen. Thus, make sure rx and ry are at least large enough for that.
896 For a 640x480 output, rx will generally be 1024 on input and ry 512, as
897 these are the smallest values that are powers of two and will hold the full
898 screen sized output.
899
900 \param txr The texture to render to.
901 \param rx Width of the texture buffer (in pixels).
902 \param ry Height of the texture buffer (in pixels).
903*/
904void pvr_scene_begin_txr(pvr_ptr_t txr, uint32_t *rx, uint32_t *ry)
905 __depr("pvr_scene_begin_txr() is deprecated. Use pvr_scene_begin_rtt().");
906
907/** \brief Begin collecting scene data for rendering into a texture target
908 with an explicit render size.
909 \ingroup pvr_scene_mgmt
910
911 This is the preferred render-to-texture API and does not require a
912 screen-sized backing texture. The PVR will render into a region of render_w
913 by render_h pixels, using stride_px pixels as the backing memory pitch.
914
915 render_w and render_h describe the area to draw. stride_px describes the
916 number of pixels between rows in memory and must be greater than or equal
917 to render_w. For the initial 16-bit render target implementation,
918 stride_px must also be a multiple of 4 pixels.
919
920 \note Initial support is intended for 16-bit render targets, matching the
921 deprecated pvr_scene_begin_txr() compatibility wrapper behavior.
922
923 \param txr The texture to render to.
924 \param render_w Width of the render area (in pixels).
925 \param render_h Height of the render area (in pixels).
926 \param stride_px Backing texture pitch (in pixels).
927
928 \retval 0 On success.
929 \retval -1 If the specified arguments are invalid.
930*/
931int pvr_scene_begin_rtt(pvr_ptr_t txr, uint32_t render_w,
932 uint32_t render_h, uint32_t stride_px);
933
934
935/** \defgroup pvr_list_mgmt Polygon Lists
936 \brief PVR API for managing list submission
937 \ingroup pvr_scene_mgmt
938*/
939
940/** \brief Begin collecting data for the given list type.
941 \ingroup pvr_list_mgmt
942
943 Lists do not have to be submitted in any particular order, but all types of
944 a list must be submitted at once (unless vertex DMA mode is enabled).
945
946 Note that there is no need to call this function in DMA mode unless you want
947 to make use of pvr_prim() for compatibility. This function will
948 automatically call pvr_list_finish() if a list is already opened before
949 opening the new list.
950
951 \param list The list to open.
952 \retval 0 On success.
953 \retval -1 If the specified list has already been closed.
954*/
956
957/** \brief End collecting data for the current list type.
958 \ingroup pvr_list_mgmt
959
960 Lists can never be opened again within a single frame once they have been
961 closed. Thus submitting a primitive that belongs in a closed list is
962 considered an error. Closing a list that is already closed is also an error.
963
964 Note that if you open a list but do not submit any primitives, a blank one
965 will be submitted to satisfy the hardware. If vertex DMA mode is enabled,
966 then this simply sets the current list pointer to no list, and none of the
967 above restrictions apply.
968
969 \retval 0 On success.
970 \retval -1 On error.
971*/
973
974/** \brief Submit a primitive of the current list type.
975 \ingroup pvr_list_mgmt
976
977 Note that any values submitted in this fashion will go directly to the
978 hardware without any sort of buffering, and submitting a primitive of the
979 wrong type will quite likely ruin your scene. Note that this also will not
980 work if you haven't begun any list types (i.e., all data is queued). If DMA
981 is enabled, the primitive will be appended to the end of the currently
982 selected list's buffer.
983
984 \warning
985 \p data must be 32-byte aligned!
986
987 \param data The primitive to submit.
988 \param size The length of the primitive, in bytes. Must be a
989 multiple of 32.
990
991 \retval 0 On success.
992 \retval -1 On error.
993*/
994int pvr_prim(const void *data, size_t size);
995
996/** \defgroup pvr_direct Direct Rendering
997 \brief API for using direct rendering with the PVR
998 \ingroup pvr_scene_mgmt
999
1000 @{
1001*/
1002
1003/** \cond */
1004extern uint32_t pvr_dr_addr;
1005/** \endcond */
1006
1007/** \brief Obtain the target address for Direct Rendering.
1008
1009 Note that you're not expected to pass any argument. The macro can take
1010 arguments for compatibility reasons and will ignore them.
1011
1012 \return A write-only destination address where a primitive
1013 should be written to get ready to submit it to the
1014 TA in DR mode.
1015*/
1016#define pvr_dr_target(...) __builtin_assume_aligned((void *)((pvr_dr_addr ^= 32)), 32)
1017
1018/** \brief Commit a primitive written into the Direct Rendering target address.
1019
1020 \param addr The address returned by pvr_dr_target(), after you
1021 have written the primitive to it.
1022*/
1023#define pvr_dr_commit(addr) sq_flush(addr)
1024
1025/** \brief Upload a 32-byte payload to the Tile Accelerator
1026
1027 Upload the given payload to the Tile Accelerator. The difference with the
1028 Direct Rendering approach above is that the Store Queues are not used, and
1029 therefore can be used for anything else.
1030
1031 \param data A pointer to the 32-byte payload.
1032 The pointer must be aligned to 8 bytes.
1033*/
1035
1036/** @} */
1037
1038/** \brief Submit a primitive of the given list type.
1039 \ingroup pvr_list_mgmt
1040
1041 Data will be queued in a vertex buffer, thus one must be available for the
1042 list specified (will be asserted by the code).
1043
1044 \param list The list to submit to.
1045 \param data The primitive to submit.
1046 \param size The size of the primitive in bytes. This must be a
1047 multiple of 32.
1048
1049 \retval 0 On success.
1050 \retval -1 On error.
1051*/
1052int pvr_list_prim(pvr_list_t list, const void *data, size_t size);
1053
1054/** \brief Flush the buffered data of the given list type to the TA.
1055 \ingroup pvr_list_mgmt
1056
1057 This function is currently not implemented, and calling it will result in an
1058 assertion failure. It is intended to be used later in a "hybrid" mode where
1059 both direct and DMA TA submission is possible.
1060
1061 \param list The list to flush.
1062
1063 \retval -1 On error (it is not possible to succeed).
1064*/
1066
1067/** \brief Call this after you have finished submitting all data for a frame.
1068 \ingroup pvr_scene_mgmt
1069
1070 Once this has been called, you can not submit any more data until one of the
1071 pvr_scene_begin() or pvr_scene_begin_rtt() functions is called again.
1072
1073 \retval 0 On success.
1074 \retval -1 On error (no scene started).
1075*/
1077
1078/** \brief Block the caller until the PVR system is ready for another frame to
1079 be submitted.
1080 \ingroup pvr_scene_mgmt
1081
1082 The PVR system allocates enough space for two frames: one in data collection
1083 mode, and another in rendering mode. If a frame is currently rendering, and
1084 another frame has already been closed, then the caller cannot do anything
1085 else until the rendering frame completes. Note also that the new frame
1086 cannot be activated except during a vertical blanking period, so this
1087 essentially waits until a rendered frame is complete and a vertical blank
1088 happens.
1089
1090 \retval 0 On success. A new scene can be started now.
1091 \retval -1 On error. Something is probably very wrong...
1092*/
1094
1095/** \brief Check if the PVR system is ready for another frame to be submitted.
1096 \ingroup pvr_scene_mgmt
1097
1098 \retval 0 If the PVR is ready for a new scene. You must call
1099 pvr_wait_ready() afterwards, before starting a new
1100 scene.
1101 \retval -1 If the PVR is not ready for a new scene yet.
1102*/
1104
1105/** \brief Block the caller until the PVR has finished rendering the previous
1106 frame.
1107 \ingroup pvr_scene_mgmt
1108
1109 This function can be used to wait until the PVR is done rendering a previous
1110 scene. This can be useful for instance to make sure that the PVR is done
1111 using textures that have to be updated, before updating those.
1112
1113 \retval 0 On success.
1114 \retval -1 On error. Something is probably very wrong...
1115*/
1117
1118
1119/* Primitive handling ************************************************/
1120
1121/** \defgroup pvr_primitives_compilation Compilation
1122 \brief API for compiling primitive contexts
1123 into headers
1124 \ingroup pvr_ctx
1125*/
1126
1127/** \brief Compile a polygon context into a polygon header.
1128 \ingroup pvr_primitives_compilation
1129
1130 This function compiles a pvr_poly_cxt_t into the form needed by the hardware
1131 for rendering. This is for use with normal polygon headers.
1132
1133 \param dst Where to store the compiled header.
1134 \param src The context to compile.
1135*/
1137
1138/** \defgroup pvr_ctx_init Initialization
1139 \brief Functions for initializing PVR polygon contexts
1140 \ingroup pvr_ctx
1141*/
1142
1143/** \brief Fill in a polygon context for non-textured polygons.
1144 \ingroup pvr_ctx_init
1145
1146 This function fills in a pvr_poly_cxt_t with default parameters appropriate
1147 for rendering a non-textured polygon in the given list.
1148
1149 \param dst Where to store the polygon context.
1150 \param list The primitive list to be used.
1151*/
1153
1154/** \brief Fill in a polygon context for a textured polygon.
1155 \ingroup pvr_ctx_init
1156
1157 This function fills in a pvr_poly_cxt_t with default parameters appropriate
1158 for rendering a textured polygon in the given list.
1159
1160 \param dst Where to store the polygon context.
1161 \param list The primitive list to be used.
1162 \param textureformat The format of the texture used.
1163 \param tw The width of the texture, in pixels.
1164 \param th The height of the texture, in pixels.
1165 \param textureaddr A pointer to the texture.
1166 \param filtering The type of filtering to use.
1167
1168 \see pvr_txr_fmts
1169*/
1171 int textureformat, int tw, int th, pvr_ptr_t textureaddr,
1172 pvr_filter_mode_t filtering);
1173
1174/** \brief Compile a sprite context into a sprite header.
1175 \ingroup pvr_primitives_compilation
1176
1177 This function compiles a pvr_sprite_cxt_t into the form needed by the
1178 hardware for rendering. This is for use with sprite headers.
1179
1180 \param dst Where to store the compiled header.
1181 \param src The context to compile.
1182*/
1184 const pvr_sprite_cxt_t *src);
1185
1186/** \brief Fill in a sprite context for non-textured sprites.
1187 \ingroup pvr_ctx_init
1188
1189 This function fills in a pvr_sprite_cxt_t with default parameters
1190 appropriate for rendering a non-textured sprite in the given list.
1191
1192 \param dst Where to store the sprite context.
1193 \param list The primitive list to be used.
1194*/
1196
1197/** \brief Fill in a sprite context for a textured sprite.
1198 \ingroup pvr_ctx_init
1199
1200 This function fills in a pvr_sprite_cxt_t with default parameters
1201 appropriate for rendering a textured sprite in the given list.
1202
1203 \param dst Where to store the sprite context.
1204 \param list The primitive list to be used.
1205 \param textureformat The format of the texture used.
1206 \param tw The width of the texture, in pixels.
1207 \param th The height of the texture, in pixels.
1208 \param textureaddr A pointer to the texture.
1209 \param filtering The type of filtering to use.
1210
1211 \see pvr_txr_fmts
1212*/
1214 int textureformat, int tw, int th, pvr_ptr_t textureaddr,
1215 pvr_filter_mode_t filtering);
1216
1217/** \brief Create a modifier volume header.
1218 \ingroup pvr_primitives_compilation
1219
1220 This function fills in a modifier volume header with the parameters
1221 specified. Note that unlike for polygons and sprites, there is no context
1222 step for modifiers.
1223
1224 \param dst Where to store the modifier header.
1225 \param list The primitive list to be used.
1226 \param mode The mode for this modifier.
1227 \param cull The culling mode to use.
1228
1229 \see pvr_mod_modes
1230 \see pvr_cull_modes
1231*/
1233 uint32_t cull);
1234
1235/** \brief Compile a polygon context into a polygon header that is affected by
1236 modifier volumes.
1237 \ingroup pvr_primitives_compilation
1238
1239 This function works pretty similarly to pvr_poly_compile(), but compiles
1240 into the header type that is affected by a modifier volume. The context
1241 should have been created with either pvr_poly_cxt_col_mod() or
1242 pvr_poly_cxt_txr_mod().
1243
1244 \param dst Where to store the compiled header.
1245 \param src The context to compile.
1246*/
1248
1249/** \brief Fill in a polygon context for non-textured polygons affected by a
1250 modifier volume.
1251 \ingroup pvr_ctx_init
1252
1253 This function fills in a pvr_poly_cxt_t with default parameters appropriate
1254 for rendering a non-textured polygon in the given list that will be affected
1255 by modifier volumes.
1256
1257 \param dst Where to store the polygon context.
1258 \param list The primitive list to be used.
1259*/
1261
1262/** \brief Fill in a polygon context for a textured polygon affected by
1263 modifier volumes.
1264 \ingroup pvr_ctx_init
1265
1266 This function fills in a pvr_poly_cxt_t with default parameters appropriate
1267 for rendering a textured polygon in the given list and being affected by
1268 modifier volumes.
1269
1270 \param dst Where to store the polygon context.
1271 \param list The primitive list to be used.
1272 \param textureformat The format of the texture used (outside).
1273 \param tw The width of the texture, in pixels (outside).
1274 \param th The height of the texture, in pixels (outside).
1275 \param textureaddr A pointer to the texture (outside).
1276 \param filtering The type of filtering to use (outside).
1277 \param textureformat2 The format of the texture used (inside).
1278 \param tw2 The width of the texture, in pixels (inside).
1279 \param th2 The height of the texture, in pixels (inside).
1280 \param textureaddr2 A pointer to the texture (inside).
1281 \param filtering2 The type of filtering to use (inside).
1282
1283 \see pvr_txr_fmts
1284*/
1286 int textureformat, int tw, int th,
1287 pvr_ptr_t textureaddr, pvr_filter_mode_t filtering,
1288 int textureformat2, int tw2, int th2,
1289 pvr_ptr_t textureaddr2, pvr_filter_mode_t filtering2);
1290
1291/** \brief Get a pointer to the front buffer.
1292 \ingroup pvr_txr_mgmt
1293
1294 This function can be used to retrieve a pointer to the front buffer, aka.
1295 the last fully rendered buffer that is either being displayed right now,
1296 or is queued to be displayed.
1297
1298 Note that the frame buffers lie in 32-bit memory, while textures lie in
1299 64-bit memory. The address returned will point to 64-bit memory, but the
1300 front buffer cannot be used directly as a regular texture.
1301
1302 \return A pointer to the front buffer.
1303*/
1305
1306/** \brief Get a pointer to the back buffer.
1307 \ingroup pvr_txr_mgmt
1308
1309 This function can be used to retrieve a pointer to the back buffer, aka.
1310 the frame buffer that will be rendered to.
1311
1312 Note that the frame buffers lie in 32-bit memory, while textures lie in
1313 64-bit memory. The address returned will point to 64-bit memory, but the
1314 back buffer cannot be used directly as a regular texture.
1315
1316 \return A pointer to the back buffer.
1317*/
1319
1320/*********************************************************************/
1321
1322#include "pvr/pvr_regs.h"
1323#include "pvr/pvr_misc.h"
1324#include "pvr/pvr_dma.h"
1325#include "pvr/pvr_fog.h"
1326#include "pvr/pvr_pal.h"
1327#include "pvr/pvr_txr.h"
1328#include "pvr/pvr_legacy.h"
1329
1330__END_DECLS
1331
1332#endif /* __DC_PVR_H */
int mode
Definition 2ndmix.c:539
pvr_init_params_t params
Definition 2ndmix.c:820
static struct @89 data[BARRIER_COUNT]
static pvr_ptr_t txr
Definition bump.c:28
Various common macros used throughout the codebase.
Constants for areas of the system memory map.
#define PVR_BINSIZE_16
16-word (64-byte) length
Definition pvr.h:648
#define PVR_BINSIZE_0
0-length (disables the list)
Definition pvr.h:646
void pvr_poly_cxt_txr(pvr_poly_cxt_t *dst, pvr_list_t list, int textureformat, int tw, int th, pvr_ptr_t textureaddr, pvr_filter_mode_t filtering)
Fill in a polygon context for a textured polygon.
void pvr_poly_cxt_col_mod(pvr_poly_cxt_t *dst, pvr_list_t list)
Fill in a polygon context for non-textured polygons affected by a modifier volume.
void pvr_sprite_cxt_txr(pvr_sprite_cxt_t *dst, pvr_list_t list, int textureformat, int tw, int th, pvr_ptr_t textureaddr, pvr_filter_mode_t filtering)
Fill in a sprite context for a textured sprite.
void pvr_poly_cxt_txr_mod(pvr_poly_cxt_t *dst, pvr_list_t list, int textureformat, int tw, int th, pvr_ptr_t textureaddr, pvr_filter_mode_t filtering, int textureformat2, int tw2, int th2, pvr_ptr_t textureaddr2, pvr_filter_mode_t filtering2)
Fill in a polygon context for a textured polygon affected by modifier volumes.
void pvr_poly_cxt_col(pvr_poly_cxt_t *dst, pvr_list_t list)
Fill in a polygon context for non-textured polygons.
void pvr_sprite_cxt_col(pvr_sprite_cxt_t *dst, pvr_list_t list)
Fill in a sprite context for non-textured sprites.
void pvr_send_to_ta(void *data)
Upload a 32-byte payload to the Tile Accelerator.
int pvr_shutdown(void)
Shut down the PVR chip from ready status.
int pvr_init_defaults(void)
Simple PVR initialization.
int pvr_init(const pvr_init_params_t *params)
Initialize the PVR chip to ready status.
static const pvr_init_params_t pvr_default_params
PVR initialization structure defaults.
Definition pvr.h:725
void * pvr_set_vertbuf(pvr_list_t list, void *buffer, size_t len)
Setup a vertex buffer for one of the list types.
int pvr_list_flush(pvr_list_t list)
Flush the buffered data of the given list type to the TA.
int pvr_prim(const void *data, size_t size)
Submit a primitive of the current list type.
int pvr_list_finish(void)
End collecting data for the current list type.
int pvr_list_prim(pvr_list_t list, const void *data, size_t size)
Submit a primitive of the given list type.
int pvr_list_begin(pvr_list_t list)
Begin collecting data for the given list type.
pvr_mip_bias_t
Definition pvr.h:91
@ PVR_MIPBIAS_1_50
Definition pvr.h:97
@ PVR_MIPBIAS_3_25
Definition pvr.h:104
@ PVR_MIPBIAS_3_50
Definition pvr.h:105
@ PVR_MIPBIAS_2_00
Definition pvr.h:99
@ PVR_MIPBIAS_0_75
Definition pvr.h:94
@ PVR_MIPBIAS_1_00
Definition pvr.h:95
@ PVR_MIPBIAS_0_50
Definition pvr.h:93
@ PVR_MIPBIAS_2_50
Definition pvr.h:101
@ PVR_MIPBIAS_0_25
Definition pvr.h:92
@ PVR_MIPBIAS_3_75
Definition pvr.h:106
@ PVR_MIPBIAS_2_25
Definition pvr.h:100
@ PVR_MIPBIAS_1_25
Definition pvr.h:96
@ PVR_MIPBIAS_NORMAL
Definition pvr.h:107
@ PVR_MIPBIAS_2_75
Definition pvr.h:102
@ PVR_MIPBIAS_1_75
Definition pvr.h:98
@ PVR_MIPBIAS_3_00
Definition pvr.h:103
void pvr_mod_compile(pvr_mod_hdr_t *dst, pvr_list_t list, uint32_t mode, uint32_t cull)
Create a modifier volume header.
void pvr_poly_compile(pvr_poly_hdr_t *dst, const pvr_poly_cxt_t *src)
Compile a polygon context into a polygon header.
void pvr_poly_mod_compile(pvr_poly_mod_hdr_t *dst, const pvr_poly_cxt_t *src)
Compile a polygon context into a polygon header that is affected by modifier volumes.
void pvr_sprite_compile(pvr_sprite_hdr_t *dst, const pvr_sprite_cxt_t *src)
Compile a sprite context into a sprite header.
pvr_txr_shading_mode_t
Texture color calculation modes.
Definition pvr_header.h:124
pvr_poly_hdr_t pvr_poly_mod_hdr_t
Definition pvr.h:382
pvr_poly_hdr_t pvr_poly_ic_hdr_t
Definition pvr.h:372
pvr_poly_hdr_t pvr_sprite_hdr_t
Definition pvr.h:392
pvr_filter_mode_t
Texture sampling modes.
Definition pvr_header.h:132
pvr_cull_mode_t
Primitive culling modes.
Definition pvr_header.h:77
pvr_fog_type_t
Fog modes.
Definition pvr_header.h:145
pvr_depthcmp_mode_t
Depth comparison modes.
Definition pvr_header.h:88
pvr_color_fmts_t
Vertex color formats.
Definition pvr_header.h:38
pvr_poly_hdr_t pvr_mod_hdr_t
Definition pvr.h:402
pvr_blend_mode_t
Blending modes.
Definition pvr_header.h:157
pvr_clip_mode_t
Primitive clipping modes.
Definition pvr_header.h:49
pvr_list_t
PVR rendering lists.
Definition pvr_header.h:60
int pvr_scene_finish(void)
Call this after you have finished submitting all data for a frame.
void pvr_scene_begin_txr(pvr_ptr_t txr, uint32_t *rx, uint32_t *ry)
Begin collecting data for a frame of 3D output to the specified texture.
void pvr_scene_begin(void)
Begin collecting data for a frame of 3D output to the off-screen frame buffer.
int pvr_check_ready(void)
Check if the PVR system is ready for another frame to be submitted.
int pvr_wait_ready(void)
Block the caller until the PVR system is ready for another frame to be submitted.
int pvr_scene_begin_rtt(pvr_ptr_t txr, uint32_t render_w, uint32_t render_h, uint32_t stride_px)
Begin collecting scene data for rendering into a texture target with an explicit render size.
int pvr_wait_render_done(void)
Block the caller until the PVR has finished rendering the previous frame.
#define PVR_TXRFMT_POW2_STRIDE
Stride is a power-of-two.
Definition pvr.h:316
static const uint32_t PVR_TXRFMT_NOSTRIDE
Definition pvr.h:320
static const uint32_t PVR_TXRFMT_STRIDE
Definition pvr.h:321
#define PVR_TXRFMT_X32_STRIDE
Stride is multiple of 32.
Definition pvr.h:317
pvr_ptr_t pvr_get_back_buffer(void)
Get a pointer to the back buffer.
pvr_ptr_t pvr_get_front_buffer(void)
Get a pointer to the front buffer.
pvr_uv_clamp_t
Definition pvr.h:146
@ PVR_UVCLAMP_UV
Clamp U and V.
Definition pvr.h:150
@ PVR_UVCLAMP_NONE
Disable clamping.
Definition pvr.h:147
@ PVR_UVCLAMP_U
Clamp U only.
Definition pvr.h:149
@ PVR_UVCLAMP_V
Clamp V only.
Definition pvr.h:148
pvr_uv_flip_t
Definition pvr.h:128
@ PVR_UVFLIP_NONE
No flipped coordinates.
Definition pvr.h:129
@ PVR_UVFLIP_UV
Flip U and V.
Definition pvr.h:132
@ PVR_UVFLIP_V
Flip V only.
Definition pvr.h:130
@ PVR_UVFLIP_U
Flip U only.
Definition pvr.h:131
void pvr_vertbuf_written(pvr_list_t list, size_t amt)
Notify the PVR system that data have been written into the output buffer for the given list.
int pvr_vertex_dma_enabled(void)
Is vertex DMA enabled?
void * pvr_vertbuf_tail(pvr_list_t list)
Retrieve a pointer to the current output location in the DMA buffer for the requested list.
void * pvr_ptr_t
PVR texture memory pointer.
Definition pvr_mem.h:45
Platform-independent image type.
static char buffer[256]
Definition porthelper.c:11
API for utilizing the DMA with the PVR for rendering.
Public API for the PVR's hardware fog.
Polygon/Sprite header definitions.
All deprecated PVR API Constants.
VRAM Management and Access.
Miscellaneous utilities for the PVR API.
Palette API for the PowerVR.
PVR Driver Registers.
Texture management with the PVR 3D API.
Macros to help dealing with register fields.
static pvr_list_t list
Definition shadow.c:25
Functions to access the SH4 Store Queues.
PVR initialization structure.
Definition pvr.h:664
int fsaa_enabled
Enable horizontal scaling?
Definition pvr.h:688
int vbuf_doublebuf_disabled
Disable vertex buffer double-buffering.
Definition pvr.h:714
int dma_enabled
Enable vertex DMA?
Definition pvr.h:681
int vertex_buf_size
Vertex buffer size (should be a nice round number)
Definition pvr.h:673
int autosort_disabled
Disable translucent polygon autosort?
Definition pvr.h:696
int opb_overflow_count
OPB Overflow Count.
Definition pvr.h:707
PVR vertex type: Modifier volume.
Definition pvr.h:550
uint32_t d1
Dummy value.
Definition pvr.h:562
uint32_t d4
Dummy value.
Definition pvr.h:565
float by
Second Y coordinate.
Definition pvr.h:557
float ay
First Y coordinate.
Definition pvr.h:554
float ax
First X coordinate.
Definition pvr.h:553
uint32_t d3
Dummy value.
Definition pvr.h:564
float cz
Third Z coordinate.
Definition pvr.h:561
float bz
Second Z coordinate.
Definition pvr.h:558
float cy
Third Y coordinate.
Definition pvr.h:560
uint32_t d6
Dummy value.
Definition pvr.h:567
uint32_t d2
Dummy value.
Definition pvr.h:563
uint32_t d5
Dummy value.
Definition pvr.h:566
float bx
Second X coordinate.
Definition pvr.h:556
float az
First Z coordinate.
Definition pvr.h:555
float cx
Third X coordinate.
Definition pvr.h:559
PVR polygon context.
Definition pvr.h:171
pvr_list_t list_type
Primitive list.
Definition pvr.h:172
bool specular
Enable offset color outside modifier.
Definition pvr.h:181
pvr_blend_mode_t src
Source blending mode outside modifier.
Definition pvr.h:187
pvr_uv_clamp_t uv_clamp
Enable/disable U/V clamping.
Definition pvr.h:211
pvr_cull_mode_t culling
Culling mode.
Definition pvr.h:177
bool mipmap
Enable/disable mipmaps.
Definition pvr.h:208
pvr_fog_type_t fog_type2
Fog type inside modifier.
Definition pvr.h:183
bool modifier_mode
True normal; false: cheap shadow.
Definition pvr.h:180
bool alpha2
Enable alpha inside modifier.
Definition pvr.h:182
pvr_uv_flip_t uv_flip
Enable/disable U/V flipping.
Definition pvr.h:210
bool color_clamp
Enable color clamping outside modifer.
Definition pvr.h:178
pvr_filter_mode_t filter
Filtering mode.
Definition pvr.h:207
bool write
Enable depth writes.
Definition pvr.h:203
pvr_ptr_t base
Texture pointer.
Definition pvr.h:218
pvr_blend_mode_t src2
Source blending mode inside modifier.
Definition pvr.h:191
struct pvr_poly_cxt_t::@51 txr2
Texturing params inside modifier.
bool enable
Enable/disable texturing.
Definition pvr.h:206
bool shading
Enable gourad shading.
Definition pvr.h:175
pvr_mip_bias_t mipmap_bias
Mipmap bias.
Definition pvr.h:209
int width
Texture width (requires a power of 2)
Definition pvr.h:214
pvr_blend_mode_t dst
Dest blending mode outside modifier.
Definition pvr.h:188
bool color_clamp2
Enable color clamping inside modifer.
Definition pvr.h:184
int height
Texture height (requires a power of 2)
Definition pvr.h:215
bool uv
True: 16-bit floating-point U/Vs; False: 32-bit.
Definition pvr.h:198
pvr_depthcmp_mode_t comparison
Depth comparison mode.
Definition pvr.h:202
bool src_enable2
Source blending mode inside modifier.
Definition pvr.h:193
pvr_blend_mode_t dst2
Dest blending mode inside modifier.
Definition pvr.h:192
bool modifier
Enable modifier effects.
Definition pvr.h:199
bool src_enable
Source blending enable outside modifier.
Definition pvr.h:189
pvr_color_fmts_t color
Color format in vertex.
Definition pvr.h:197
pvr_txr_shading_mode_t env
Texture color contribution.
Definition pvr.h:213
pvr_fog_type_t fog_type
Fog type outside modifier.
Definition pvr.h:176
bool alpha
Enable alpha outside modifier.
Definition pvr.h:174
pvr_clip_mode_t clip_mode
Clipping mode.
Definition pvr.h:179
bool dst_enable2
Dest blending mode inside modifier.
Definition pvr.h:194
bool dst_enable
Dest blending enable outside modifier.
Definition pvr.h:190
int format
Texture format.
Definition pvr.h:216
PVR polygon header.
Definition pvr_header.h:312
PVR vertex type: Untextured sprite.
Definition pvr.h:525
float bz
Second Z coordinate.
Definition pvr.h:533
float ay
First Y coordinate.
Definition pvr.h:529
uint32_t d3
Dummy value.
Definition pvr.h:541
float cz
Third Z coordinate.
Definition pvr.h:536
float bx
Second X coordinate.
Definition pvr.h:531
uint32_t d1
Dummy value.
Definition pvr.h:539
float cy
Third Y coordinate.
Definition pvr.h:535
float ax
First X coordinate.
Definition pvr.h:528
float by
Second Y coordinate.
Definition pvr.h:532
uint32_t d4
Dummy value.
Definition pvr.h:542
float dy
Fourth Y coordinate.
Definition pvr.h:538
uint32_t d2
Dummy value.
Definition pvr.h:540
float cx
Third X coordinate.
Definition pvr.h:534
float az
First Z coordinate.
Definition pvr.h:530
float dx
Fourth X coordinate.
Definition pvr.h:537
PVR sprite context.
Definition pvr.h:236
bool alpha
Enable alpha.
Definition pvr.h:239
bool mipmap
Enable/disable mipmaps.
Definition pvr.h:259
bool enable
Enable/disable texturing.
Definition pvr.h:257
pvr_mip_bias_t mipmap_bias
Mipmap bias.
Definition pvr.h:260
bool src_enable
Source blending enable.
Definition pvr.h:249
pvr_uv_clamp_t uv_clamp
Enable/disable U/V clamping.
Definition pvr.h:262
pvr_blend_mode_t dst
Dest blending mode.
Definition pvr.h:248
pvr_fog_type_t fog_type
Fog type.
Definition pvr.h:240
bool write
Enable depth writes.
Definition pvr.h:254
pvr_uv_flip_t uv_flip
Enable/disable U/V flipping.
Definition pvr.h:261
bool specular
Enable offset color.
Definition pvr.h:244
bool color_clamp
Enable color clamp.
Definition pvr.h:242
pvr_list_t list_type
Primitive list.
Definition pvr.h:237
pvr_clip_mode_t clip_mode
Clipping mode.
Definition pvr.h:243
int width
Texture width (requires a power of 2)
Definition pvr.h:265
pvr_txr_shading_mode_t env
Texture color contribution.
Definition pvr.h:264
pvr_ptr_t base
Texture pointer.
Definition pvr.h:269
pvr_blend_mode_t src
Source blending mode.
Definition pvr.h:247
pvr_filter_mode_t filter
Filtering mode.
Definition pvr.h:258
pvr_cull_mode_t culling
Culling mode.
Definition pvr.h:241
pvr_depthcmp_mode_t comparison
Depth comparison mode.
Definition pvr.h:253
int height
Texture height (requires a power of 2)
Definition pvr.h:266
bool dst_enable
Dest blending enable.
Definition pvr.h:250
int format
Texture format.
Definition pvr.h:267
PVR vertex type: Textured sprite.
Definition pvr.h:500
float bz
Second Z coordinate.
Definition pvr.h:508
float dx
Fourth X coordinate.
Definition pvr.h:512
float az
First Z coordinate.
Definition pvr.h:505
float ax
First X coordinate.
Definition pvr.h:503
uint32_t buv
Second U/V texture coordinates.
Definition pvr.h:516
float cz
Third Z coordinate.
Definition pvr.h:511
uint32_t dummy
Dummy value.
Definition pvr.h:514
float by
Second Y coordinate.
Definition pvr.h:507
uint32_t auv
First U/V texture coordinates.
Definition pvr.h:515
float dy
Fourth Y coordinate.
Definition pvr.h:513
float cx
Third X coordinate.
Definition pvr.h:509
uint32_t cuv
Third U/V texture coordinates.
Definition pvr.h:517
float bx
Second X coordinate.
Definition pvr.h:506
float cy
Third Y coordinate.
Definition pvr.h:510
float ay
First Y coordinate.
Definition pvr.h:504
PVR vertex type: Non-textured, packed color, affected by modifier volume.
Definition pvr.h:448
float z
Z coordinate.
Definition pvr.h:453
uint32_t d1
Dummy value.
Definition pvr.h:456
uint32_t argb0
Vertex color (outside volume)
Definition pvr.h:454
float x
X coordinate.
Definition pvr.h:451
float y
Y coordinate.
Definition pvr.h:452
uint32_t d2
Dummy value.
Definition pvr.h:457
uint32_t argb1
Vertex color (inside volume)
Definition pvr.h:455
Generic PVR vertex type.
Definition pvr.h:420
float z
Z coordinate.
Definition pvr.h:425
float y
Y coordinate.
Definition pvr.h:424
float u
Texture U coordinate.
Definition pvr.h:428
uint32_t oargb
Vertex offset color.
Definition pvr.h:437
uint32_t argb1
Vertex color when modified, inside area.
Definition pvr.h:433
float x
X coordinate.
Definition pvr.h:423
float v
Texture V coordinate.
Definition pvr.h:429
uint32_t argb
Vertex color.
Definition pvr.h:436
uint32_t argb0
Vertex color when modified, outside area.
Definition pvr.h:432
PVR vertex type: Textured, packed color, affected by modifier volume.
Definition pvr.h:468
float z
Z coordinate.
Definition pvr.h:473
uint32_t oargb1
Vertex offset color (inside)
Definition pvr.h:481
uint32_t oargb0
Vertex offset color (outside)
Definition pvr.h:477
float x
X coordinate.
Definition pvr.h:471
float u0
Texture U coordinate (outside)
Definition pvr.h:474
uint32_t d2
Dummy value.
Definition pvr.h:483
float v0
Texture V coordinate (outside)
Definition pvr.h:475
uint32_t d4
Dummy value.
Definition pvr.h:485
float u1
Texture U coordinate (inside)
Definition pvr.h:478
float y
Y coordinate.
Definition pvr.h:472
float v1
Texture V coordinate (inside)
Definition pvr.h:479
uint32_t argb0
Vertex color (outside)
Definition pvr.h:476
uint32_t argb1
Vertex color (inside)
Definition pvr.h:480
uint32_t d1
Dummy value.
Definition pvr.h:482
uint32_t d3
Dummy value.
Definition pvr.h:484
Common integer types.