KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
pvr.h File Reference

Low-level PVR (3D hardware) interface. More...

#include <sys/cdefs.h>
#include <stdalign.h>
#include <stdbool.h>
#include <arch/memory.h>
#include <arch/types.h>
#include <arch/cache.h>
#include <dc/sq.h>
#include <kos/img.h>
#include <kos/regfield.h>
#include "pvr/pvr_mem.h"
#include "pvr/pvr_regs.h"
#include "pvr/pvr_misc.h"
#include "pvr/pvr_dma.h"
#include "pvr/pvr_fog.h"
#include "pvr/pvr_pal.h"
#include "pvr/pvr_txr.h"

Go to the source code of this file.

Data Structures

struct  pvr_poly_cxt_t
 PVR polygon context. More...
 
struct  pvr_sprite_cxt_t
 PVR sprite context. More...
 
struct  pvr_poly_hdr_t
 PVR polygon header. More...
 
struct  pvr_poly_ic_hdr_t
 PVR polygon header with intensity color. More...
 
struct  pvr_poly_mod_hdr_t
 PVR polygon header to be used with modifier volumes. More...
 
struct  pvr_sprite_hdr_t
 PVR polygon header specifically for sprites. More...
 
struct  pvr_mod_hdr_t
 Modifier volume header. More...
 
struct  pvr_vertex_t
 Generic PVR vertex type. More...
 
struct  pvr_vertex_pcm_t
 PVR vertex type: Non-textured, packed color, affected by modifier volume. More...
 
struct  pvr_vertex_tpcm_t
 PVR vertex type: Textured, packed color, affected by modifier volume. More...
 
struct  pvr_sprite_txr_t
 PVR vertex type: Textured sprite. More...
 
struct  pvr_sprite_col_t
 PVR vertex type: Untextured sprite. More...
 
struct  pvr_modifier_vol_t
 PVR vertex type: Modifier volume. More...
 
struct  pvr_init_params_t
 PVR initialization structure. More...
 

Macros

#define PVR_LIST_OP_POLY   0
 Opaque polygon list.
 
#define PVR_LIST_OP_MOD   1
 Opaque modifier list.
 
#define PVR_LIST_TR_POLY   2
 Translucent polygon list.
 
#define PVR_LIST_TR_MOD   3
 Translucent modifier list.
 
#define PVR_LIST_PT_POLY   4
 Punch-thru polygon list.
 
#define PVR_SHADE_FLAT   0
 Use flat shading.
 
#define PVR_SHADE_GOURAUD   1
 Use Gouraud shading.
 
#define PVR_DEPTHCMP_NEVER   0
 Never pass.
 
#define PVR_DEPTHCMP_LESS   1
 Less than.
 
#define PVR_DEPTHCMP_EQUAL   2
 Equal to.
 
#define PVR_DEPTHCMP_LEQUAL   3
 Less than or equal to.
 
#define PVR_DEPTHCMP_GREATER   4
 Greater than.
 
#define PVR_DEPTHCMP_NOTEQUAL   5
 Not equal to.
 
#define PVR_DEPTHCMP_GEQUAL   6
 Greater than or equal to.
 
#define PVR_DEPTHCMP_ALWAYS   7
 Always pass.
 
#define PVR_CULLING_NONE   0
 Disable culling.
 
#define PVR_CULLING_SMALL   1
 Cull if small.
 
#define PVR_CULLING_CCW   2
 Cull if counterclockwise.
 
#define PVR_CULLING_CW   3
 Cull if clockwise.
 
#define PVR_DEPTHWRITE_ENABLE   0
 Update the Z value.
 
#define PVR_DEPTHWRITE_DISABLE   1
 Do not update the Z value.
 
#define PVR_TEXTURE_DISABLE   0
 Disable texturing.
 
#define PVR_TEXTURE_ENABLE   1
 Enable texturing.
 
#define PVR_BLEND_ZERO   0
 None of this color.
 
#define PVR_BLEND_ONE   1
 All of this color.
 
#define PVR_BLEND_DESTCOLOR   2
 Destination color.
 
#define PVR_BLEND_INVDESTCOLOR   3
 Inverse of destination color.
 
#define PVR_BLEND_SRCALPHA   4
 Blend with source alpha.
 
#define PVR_BLEND_INVSRCALPHA   5
 Blend with inverse source alpha.
 
#define PVR_BLEND_DESTALPHA   6
 Blend with destination alpha.
 
#define PVR_BLEND_INVDESTALPHA   7
 Blend with inverse destination alpha.
 
#define PVR_BLEND_DISABLE   0
 Disable blending.
 
#define PVR_BLEND_ENABLE   1
 Enable blending.
 
#define PVR_FOG_TABLE   0
 Table fog.
 
#define PVR_FOG_VERTEX   1
 Vertex fog.
 
#define PVR_FOG_DISABLE   2
 Disable fog.
 
#define PVR_FOG_TABLE2   3
 Table fog mode 2.
 
#define PVR_USERCLIP_DISABLE   0
 Disable clipping.
 
#define PVR_USERCLIP_INSIDE   2
 Enable clipping inside area.
 
#define PVR_USERCLIP_OUTSIDE   3
 Enable clipping outside area.
 
#define PVR_CLRCLAMP_DISABLE   0
 Disable color clamping.
 
#define PVR_CLRCLAMP_ENABLE   1
 Enable color clamping.
 
#define PVR_SPECULAR_DISABLE   0
 Disable offset colors.
 
#define PVR_SPECULAR_ENABLE   1
 Enable offset colors.
 
#define PVR_ALPHA_DISABLE   0
 Disable alpha blending.
 
#define PVR_ALPHA_ENABLE   1
 Enable alpha blending.
 
#define PVR_TXRALPHA_ENABLE   0
 Enable alpha blending.
 
#define PVR_TXRALPHA_DISABLE   1
 Disable alpha blending.
 
#define PVR_UVFLIP_NONE   0
 No flipped coordinates.
 
#define PVR_UVFLIP_V   1
 Flip V only.
 
#define PVR_UVFLIP_U   2
 Flip U only.
 
#define PVR_UVFLIP_UV   3
 Flip U and V.
 
#define PVR_UVCLAMP_NONE   0
 Disable clamping.
 
#define PVR_UVCLAMP_V   1
 Clamp V only.
 
#define PVR_UVCLAMP_U   2
 Clamp U only.
 
#define PVR_UVCLAMP_UV   3
 Clamp U and V.
 
#define PVR_FILTER_NONE   0
 No filtering (point sample)
 
#define PVR_FILTER_NEAREST   0
 No filtering (point sample)
 
#define PVR_FILTER_BILINEAR   2
 Bilinear interpolation.
 
#define PVR_FILTER_TRILINEAR1   4
 Trilinear interpolation pass 1.
 
#define PVR_FILTER_TRILINEAR2   6
 Trilinear interpolation pass 2.
 
#define PVR_MIPBIAS_NORMAL   PVR_MIPBIAS_1_00 /* txr_mipmap_bias */
 
#define PVR_MIPBIAS_0_25   1
 
#define PVR_MIPBIAS_0_50   2
 
#define PVR_MIPBIAS_0_75   3
 
#define PVR_MIPBIAS_1_00   4
 
#define PVR_MIPBIAS_1_25   5
 
#define PVR_MIPBIAS_1_50   6
 
#define PVR_MIPBIAS_1_75   7
 
#define PVR_MIPBIAS_2_00   8
 
#define PVR_MIPBIAS_2_25   9
 
#define PVR_MIPBIAS_2_50   10
 
#define PVR_MIPBIAS_2_75   11
 
#define PVR_MIPBIAS_3_00   12
 
#define PVR_MIPBIAS_3_25   13
 
#define PVR_MIPBIAS_3_50   14
 
#define PVR_MIPBIAS_3_75   15
 
#define PVR_TXRENV_REPLACE   0
 C = Ct, A = At.
 
#define PVR_TXRENV_MODULATE   1
 C = Cs * Ct, A = At.
 
#define PVR_TXRENV_DECAL   2
 C = (Cs * At) + (Cs * (1-At)), A = As.
 
#define PVR_TXRENV_MODULATEALPHA   3
 C = Cs * Ct, A = As * At.
 
#define PVR_MIPMAP_DISABLE   0
 Disable mipmap processing.
 
#define PVR_MIPMAP_ENABLE   1
 Enable mipmap processing.
 
#define PVR_TXRFMT_NONE   0
 No texture.
 
#define PVR_TXRFMT_VQ_DISABLE   (0 << 30)
 Not VQ encoded.
 
#define PVR_TXRFMT_VQ_ENABLE   (1 << 30)
 VQ encoded.
 
#define PVR_TXRFMT_ARGB1555   (0 << 27)
 16-bit ARGB1555
 
#define PVR_TXRFMT_RGB565   (1 << 27)
 16-bit RGB565
 
#define PVR_TXRFMT_ARGB4444   (2 << 27)
 16-bit ARGB4444
 
#define PVR_TXRFMT_YUV422   (3 << 27)
 YUV422 format.
 
#define PVR_TXRFMT_BUMP   (4 << 27)
 Bumpmap format.
 
#define PVR_TXRFMT_PAL4BPP   (5 << 27)
 4BPP paletted format
 
#define PVR_TXRFMT_PAL8BPP   (6 << 27)
 8BPP paletted format
 
#define PVR_TXRFMT_TWIDDLED   (0 << 26)
 Texture is twiddled.
 
#define PVR_TXRFMT_NONTWIDDLED   (1 << 26)
 Texture is not twiddled.
 
#define PVR_TXRFMT_NOSTRIDE   (0 << 21)
 Texture is not strided.
 
#define PVR_TXRFMT_STRIDE   (1 << 21)
 Texture is strided.
 
#define PVR_TXRFMT_8BPP_PAL(x)
 8BPP palette selector
 
#define PVR_TXRFMT_4BPP_PAL(x)
 4BPP palette selector
 
#define PVR_CLRFMT_ARGBPACKED   0
 32-bit integer ARGB
 
#define PVR_CLRFMT_4FLOATS   1
 4 floating point values
 
#define PVR_CLRFMT_INTENSITY   2
 Intensity color.
 
#define PVR_CLRFMT_INTENSITY_PREV   3
 Use last intensity.
 
#define PVR_UVFMT_32BIT   0
 32-bit floating point U/V
 
#define PVR_UVFMT_16BIT   1
 16-bit floating point U/V
 
#define PVR_MODIFIER_DISABLE   0
 Disable modifier effects.
 
#define PVR_MODIFIER_ENABLE   1
 Enable modifier effects.
 
#define PVR_MODIFIER_CHEAP_SHADOW   0
 
#define PVR_MODIFIER_NORMAL   1
 
#define PVR_MODIFIER_OTHER_POLY   0
 Not the last polygon in the volume.
 
#define PVR_MODIFIER_INCLUDE_LAST_POLY   1
 Last polygon, inclusion volume.
 
#define PVR_MODIFIER_EXCLUDE_LAST_POLY   2
 Last polygon, exclusion volume.
 
#define PVR_CMD_POLYHDR   0x80840000
 PVR polygon header.
 
#define PVR_CMD_VERTEX   0xe0000000
 PVR vertex data.
 
#define PVR_CMD_VERTEX_EOL   0xf0000000
 PVR vertex, end of strip.
 
#define PVR_CMD_USERCLIP   0x20000000
 PVR user clipping area.
 
#define PVR_CMD_MODIFIER   0x80000000
 PVR modifier volume.
 
#define PVR_CMD_SPRITE   0xA0000000
 PVR sprite header.
 
#define PVR_TA_CMD_TYPE   GENMASK(26, 24)
 
#define PVR_TA_CMD_USERCLIP   GENMASK(17, 16)
 
#define PVR_TA_CMD_MODIFIER   BIT(7)
 
#define PVR_TA_CMD_MODIFIERMODE   BIT(6)
 
#define PVR_TA_CMD_CLRFMT   GENMASK(5, 4)
 
#define PVR_TA_CMD_TXRENABLE   BIT(3)
 
#define PVR_TA_CMD_SPECULAR   BIT(2)
 
#define PVR_TA_CMD_SHADE   BIT(1)
 
#define PVR_TA_CMD_UVFMT   BIT(0)
 
#define PVR_TA_PM1_DEPTHCMP   GENMASK(31, 29)
 
#define PVR_TA_PM1_CULLING   GENMASK(28, 27)
 
#define PVR_TA_PM1_DEPTHWRITE   BIT(26)
 
#define PVR_TA_PM1_TXRENABLE   BIT(25)
 
#define PVR_TA_PM1_MODIFIERINST   GENMASK(30, 29)
 
#define PVR_TA_PM2_SRCBLEND   GENMASK(31, 29)
 
#define PVR_TA_PM2_DSTBLEND   GENMASK(28, 26)
 
#define PVR_TA_PM2_SRCENABLE   BIT(25)
 
#define PVR_TA_PM2_DSTENABLE   BIT(24)
 
#define PVR_TA_PM2_FOG   GENMASK(23, 22)
 
#define PVR_TA_PM2_CLAMP   BIT(21)
 
#define PVR_TA_PM2_ALPHA   BIT(20)
 
#define PVR_TA_PM2_TXRALPHA   BIT(19)
 
#define PVR_TA_PM2_UVFLIP   GENMASK(18, 17)
 
#define PVR_TA_PM2_UVCLAMP   GENMASK(16, 15)
 
#define PVR_TA_PM2_FILTER   GENMASK(14, 12)
 
#define PVR_TA_PM2_MIPBIAS   GENMASK(11, 8)
 
#define PVR_TA_PM2_TXRENV   GENMASK(7, 6)
 
#define PVR_TA_PM2_USIZE   GENMASK(5, 3)
 
#define PVR_TA_PM2_VSIZE   GENMASK(2, 0)
 
#define PVR_TA_PM3_MIPMAP   BIT(31)
 
#define PVR_TA_PM3_TXRFMT   GENMASK(30, 21)
 
#define PVR_BINSIZE_0   0
 0-length (disables the list)
 
#define PVR_BINSIZE_8   8
 8-word (32-byte) length
 
#define PVR_BINSIZE_16   16
 16-word (64-byte) length
 
#define PVR_BINSIZE_32   32
 32-word (128-byte) length
 
#define pvr_dr_target(vtx_buf_ptr)
 Obtain the target address for Direct Rendering.
 
#define pvr_dr_commit(addr)
 Commit a primitive written into the Direct Rendering target address.
 

Typedefs

typedef uint32_t pvr_list_t
 PVR list specification.
 
typedef uint32_t pvr_dr_state_t
 Direct Rendering state variable type.
 

Functions

int pvr_init (const pvr_init_params_t *params)
 Initialize the PVR chip to ready status.
 
int pvr_init_defaults (void)
 Simple PVR initialization.
 
int pvr_shutdown (void)
 Shut down the PVR chip from ready status.
 
int pvr_vertex_dma_enabled (void)
 Is vertex DMA enabled?
 
void * pvr_set_vertbuf (pvr_list_t list, void *buffer, size_t len)
 Setup a vertex buffer for one of the list types.
 
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_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.
 
void pvr_scene_begin (void)
 Begin collecting data for a frame of 3D output to the off-screen frame buffer.
 
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.
 
int pvr_list_begin (pvr_list_t list)
 Begin collecting data for the given list type.
 
int pvr_list_finish (void)
 End collecting data for the current list type.
 
int pvr_prim (const void *data, size_t size)
 Submit a primitive of the current list type.
 
void pvr_dr_init (pvr_dr_state_t *vtx_buf_ptr)
 Initialize a state variable for Direct Rendering.
 
void pvr_dr_finish (void)
 Finish work with Direct Rendering.
 
void pvr_send_to_ta (void *data)
 Upload a 32-byte payload to the Tile Accelerator.
 
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_flush (pvr_list_t list)
 Flush the buffered data of the given list type to the TA.
 
int pvr_scene_finish (void)
 Call this after you have finished submitting all data for a frame.
 
int pvr_wait_ready (void)
 Block the caller until the PVR system is ready for another frame to be submitted.
 
int pvr_check_ready (void)
 Check if the PVR system is ready for another frame to be submitted.
 
int pvr_wait_render_done (void)
 Block the caller until the PVR has finished rendering the previous frame.
 
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_cxt_col (pvr_poly_cxt_t *dst, pvr_list_t list)
 Fill in a polygon context for non-textured polygons.
 
void pvr_poly_cxt_txr (pvr_poly_cxt_t *dst, pvr_list_t list, int textureformat, int tw, int th, pvr_ptr_t textureaddr, int filtering)
 Fill in a polygon context for a textured polygon.
 
void pvr_sprite_compile (pvr_sprite_hdr_t *dst, const pvr_sprite_cxt_t *src)
 Compile a sprite context into a sprite header.
 
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_sprite_cxt_txr (pvr_sprite_cxt_t *dst, pvr_list_t list, int textureformat, int tw, int th, pvr_ptr_t textureaddr, int filtering)
 Fill in a sprite context for a textured sprite.
 
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_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_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_poly_cxt_txr_mod (pvr_poly_cxt_t *dst, pvr_list_t list, int textureformat, int tw, int th, pvr_ptr_t textureaddr, int filtering, int textureformat2, int tw2, int th2, pvr_ptr_t textureaddr2, int filtering2)
 Fill in a polygon context for a textured polygon affected by modifier volumes.
 
pvr_ptr_t pvr_get_front_buffer (void)
 Get a pointer to the front buffer.
 

Detailed Description

Low-level PVR (3D hardware) interface.

This file provides support for using the PVR 3D hardware in the Dreamcast. Note that this does not handle any sort of perspective transformations or anything of the like. This is just a very thin wrapper around the actual hardware support.

This file is used for pretty much everything related to the PVR, from memory management to actual primitive rendering.

Note
This API does not handle any sort of transformations (including perspective!) so for that, you should look to KGL.
Author
Megan Potter
Roger Cattermole
Paul Boese
Brian Paul
Lawrence Sebald
Benoit Miller
Ruslan Rostovtsev