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