Manages graphics on the system. More...
#include <stdint.h>#include <stdbool.h>#include "framebuffer.h"#include "video.h"#include "FreeRTOS.h"#include "task.h"#include "gx_xf.h"#include "gx_tev.h"#include "gx_immediate.h"Go to the source code of this file.
Classes | |
| struct | gx_fifo_t |
| Represents the a fifo for the Command Processor. More... | |
| struct | gx_texture_t |
| Cool little texture object. Really just a copy of the registers that will be set onto the GPU when the texture is loaded. More... | |
Macros | |
| #define | GX_WPAR_ADDRESS 0xCC008000 |
| #define | GX_WPAR_U8 (*(volatile uint8_t*)GX_WPAR_ADDRESS) |
| #define | GX_WPAR_U16 (*(volatile uint16_t*)GX_WPAR_ADDRESS) |
| #define | GX_WPAR_U32 (*(volatile uint32_t*)GX_WPAR_ADDRESS) |
| #define | GX_WPAR_S8 (*(volatile int8_t*)GX_WPAR_ADDRESS) |
| #define | GX_WPAR_S16 (*(volatile int16_t*)GX_WPAR_ADDRESS) |
| #define | GX_WPAR_S32 (*(volatile int32_t*)GX_WPAR_ADDRESS) |
| #define | GX_WPAR_F32 (*(volatile float*)GX_WPAR_ADDRESS) |
| #define | GX_FIFO_MINIMUM_SIZE (64 * 1024) |
| #define | GX_FIFO_WATERMARK (16 * 1024) |
| #define | GX_WPAR_OPCODE_LOAD_CP 0x08 |
| #define | GX_WPAR_OPCODE_LOAD_XF 0x10 |
| #define | GX_WPAR_OPCODE_LOAD_BP 0x61 |
| #define | GX_WPAR_OPCODE_PRIMITIVE(type, format) |
| #define | GX_XF_MEMORY_POSTEX_MTX_0 0x0000 |
| #define | GX_XF_MEMORY_NORMAL_MTX_0 0x0400 |
| #define | GX_XF_MEMORY_DUALTEX_MTX_0 0x0500 |
| #define | GX_XF_MEMORY_LIGHT0 0x0600 |
| #define | GX_XF_REGISTER_VERTEX_STATS 0x1008 |
| #define | GX_XF_REGISTER_COLOR_COUNT 0x1009 |
| #define | GX_XF_REGISTER_COLOR_CONTROL 0x100E |
| #define | GX_XF_REGISTER_DUALTEXTRANS 0x1012 |
| #define | GX_XF_REGISTER_MTXIDX_A 0x1018 |
| #define | GX_XF_REGISTER_MTXIDX_B 0x1019 |
| #define | GX_XF_REGISTER_VIEWPORT 0x101A |
| #define | GX_XF_REGISTER_PROJECTION 0x1020 |
| #define | GX_XF_REGISTER_TEXCOORD_COUNT 0x103F |
| #define | GX_XF_REGISTER_TEX0 0x1040 |
| #define | GX_XF_REGISTER_DUALTEX0 0x1050 |
| #define | GX_BP_REGISTERS_GENMODE (0x00 << 24) |
| #define | GX_BP_REGISTERS_COPY_FILTER_POS_A (0x01 << 24) |
| #define | GX_BP_REGISTERS_COPY_FILTER_POS_B (0x02 << 24) |
| #define | GX_BP_REGISTERS_COPY_FILTER_POS_C (0x03 << 24) |
| #define | GX_BP_REGISTERS_COPY_FILTER_POS_D (0x04 << 24) |
| #define | GX_BP_REGISTERS_SCISSOR_TL (0x20 << 24) |
| #define | GX_BP_REGISTERS_SCISSOR_BR (0x21 << 24) |
| #define | GX_BP_REGISTERS_SSIZE0 (0x30 << 24) |
| #define | GX_BP_REGISTERS_TSIZE0 (0x31 << 24) |
| #define | GX_BP_REGISTERS_Z_MODE (0x40 << 24) |
| #define | GX_BP_REGISTERS_CMODE_0 (0x41 << 24) |
| #define | GX_BP_REGISTERS_CMODE_1 (0x42 << 24) |
| #define | GX_BP_REGISTERS_PE_CONTROL (0X43 << 24) |
| #define | GX_BP_REGISTERS_PE_DONE (0x45 << 24) |
| #define | GX_BP_REGISTERS_EFB_SOURCE_TOP_LEFT (0x49 << 24) |
| #define | GX_BP_REGISTERS_EFB_SOURCE_WIDTH_HEIGHT (0x4A << 24) |
| #define | GX_BP_REGISTERS_XFB_TARGET_ADDRESS (0x4B << 24) |
| #define | GX_BP_REGISTERS_EFB_DESTINATION_WIDTH (0x4D << 24) |
| #define | GX_BP_REGISTERS_Y_SCALE (0x4E << 24) |
| #define | GX_BP_REGISTERS_PE_COPY_CLEAR_AR (0x4F << 24) |
| #define | GX_BP_REGISTERS_PE_COPY_CLEAR_GB (0x50 << 24) |
| #define | GX_BP_REGISTERS_PE_COPY_CLEAR_Z (0x51 << 24) |
| #define | GX_BP_REGISTERS_PE_COPY_EXECUTE (0x52 << 24) |
| #define | GX_BP_REGISTERS_COPY_FILTER_COEFF_A (0x53 << 24) |
| #define | GX_BP_REGISTERS_COPY_FILTER_COEFF_B (0x54 << 24) |
| #define | GX_BP_REGISTERS_SCISSOR_OFFSET (0x59 << 24) |
| #define | GX_BP_REGISTERS_TX_SETMODE0_I0 (0x80 << 24) |
| #define | GX_BP_REGISTERS_TX_SETMODE1_I0 (0x84 << 24) |
| #define | GX_BP_REGISTERS_TX_SETIMAGE0_I0 (0x88 << 24) |
| #define | GX_BP_REGISTERS_TX_SETIMAGE1_I0 (0x8C << 24) |
| #define | GX_BP_REGISTERS_TX_SETIMAGE2_I0 (0x90 << 24) |
| #define | GX_BP_REGISTERS_TX_SETIMAGE3_I0 (0x94 << 24) |
| #define | GX_BP_REGISTERS_TX_SETTLUT_0 (0x98 << 24) |
| #define | GX_BP_REGISTERS_TEV0_COLOR_ENV (0xC0 << 24) |
| #define | GX_BP_REGISTERS_TEV0_ALPHA_ENV (0xC1 << 24) |
| #define | GX_BP_REGISTERS_TEV_REGISTERL_0 (0xE0 << 24) |
| #define | GX_BP_REGISTERS_TEV_REGISTERH_0 (0xE1 << 24) |
| #define | GX_CP_REGISTERS_MTXIDX_A 0x30 |
| #define | GX_CP_REGISTERS_MTXIDX_B 0x40 |
| #define | GX_CP_REGISTER_VCD_LOW 0x50 |
| #define | GX_CP_REGISTER_VCD_HIGH 0x60 |
| #define | GX_CP_REGISTER_VAT_A 0x70 |
| #define | GX_CP_REGISTER_VAT_B 0x80 |
| #define | GX_CP_REGISTER_VAT_C 0x90 |
| #define | GX_WPAR_CP_LOAD(address, value) |
| #define | GX_WPAR_XF_LOAD(address, words) |
| #define | GX_WPAR_BP_LOAD(value) |
| #define | gx_end() |
| End drawing primatives. | |
Functions | |
| void | gx_initialize (const gx_fifo_t *fifo, const video_profile_t *video_profile) |
| Initializes the graphics. | |
| void | gx_initialize_state () |
| Initializes the graphics state. | |
| void | gx_initialize_video (const video_profile_t *video_profile) |
| Initializes all the video settings from a video profile. | |
| void | gx_fifo_initialize (gx_fifo_t *fifo, void *fifo_buffer, uint32_t fifo_buffer_size) |
| Creates the fifo data structure. | |
| void | gx_fifo_set (const gx_fifo_t *fifo) |
| Sets the current FIFO. | |
| void | gx_fifo_get (gx_fifo_t *fifo) |
| Gets the current FIFO. | |
| void | gx_flush () |
| Flushes all commands to the command processor. | |
| uint32_t | gx_efb_peak (uint32_t x, uint32_t y) |
| Grabs a pixel from the embedded frame buffer. | |
| void | gx_vtxdesc_clear () |
| Clears out all vertex descriptions. | |
| void | gx_vtxdesc_set (gx_vtxdesc_t desc, gx_vtxattr_data_t type) |
| Sets a vertex description. | |
| void | gx_vtxfmtattr_clear (uint8_t attribute_index) |
| Clears out a vertex attribute format. | |
| void | gx_vtxfmtattr_set (uint8_t attribute_index, gx_vtxdesc_t attribute, gx_vtxattr_component_t component, gx_vtxattr_component_format_t fmt, uint8_t fraction) |
| Sets the format of a vertex attribute. | |
| void | gx_begin (gx_primitive_t primitive, uint8_t attribute, uint16_t count) |
| Begin drawing primatives. | |
| void | gx_draw_done () |
| Call to send end current drawing session. Then wait. | |
| void | gx_set_render_thread (TaskHandle_t task) |
| Sets the current render thread for suspension. | |
| void | gx_set_clear_color (uint8_t r, uint8_t g, uint8_t b, uint8_t a) |
| Sets the background color when copying framebuffers. | |
| void | gx_set_clear_z (uint32_t z) |
| Sets the z value the frame buffer is cleared with. | |
| void | gx_set_copy_y_scale (float y_scale) |
| Sets the scale of the EFB to the XFB's Y. | |
| void | gx_set_scissor_rectangle (uint32_t x, uint32_t y, uint32_t width, uint32_t height) |
| Sets the scissor rectangle. | |
| void | gx_set_scissor_offset (int32_t x, int32_t y) |
| Offsets the scissor rectangle. | |
| void | gx_set_copy_window (uint32_t x, uint32_t y, uint32_t width, uint32_t height, uint32_t xfb_width) |
| Sets the window to of the EFB into the XFB. | |
| void | gx_set_clamp_mode (gx_clamp_mode_t mode) |
| Set the clamp mode when copying from EFB to XFB. | |
| void | gx_set_gamma (gx_gamma_t gamma) |
| Sets the gamma value when copying from EFB to XFB. | |
| void | gx_set_line_mode (gx_line_mode_t line_mode) |
| Sets the what lines are copied from EFB to XFB. | |
| void | gx_set_copy_filter (const uint8_t pattern[12][2], const uint8_t filter[7]) |
| Sets the interpolation filters used when copying the frame buffer into external frame buffers of differing resolutions. | |
| void | gx_set_z_mode (bool enable_compare, gx_compare_t compare, bool enable_update) |
| Determins how Z values will be treated. | |
| void | gx_set_color_update (bool update_color, bool update_alpha) |
| Enables updating the color when rendering into the EFB. | |
| void | gx_enable_z_precheck (bool enable) |
| Enables / Disables checking Z before or after texturing. | |
| void | gx_set_pixel_format (gx_pixel_format_t pixels_format, gx_z_format_t z_format) |
| Sets the format of pixels in the EFB. | |
| void | gx_copy_framebuffer (framebuffer_t *framebuffer, bool clear) |
| Copys the internal framebuffer to the external frame buffer. | |
| void | gx_initialize_texture (gx_texture_t *texture, const void *data, gx_texture_format_t format, int width, int height, gx_texture_wrap_t s_wrap, gx_texture_wrap_t t_wrap, bool mipmap) |
| Initializes a texture object for use. | |
| void | gx_flash_texture (gx_texture_map_t map, const gx_texture_t *texture) |
| Flashes a texture configuration onto the BP. | |
Manages graphics on the system.
Manages graphics on the system. Provides a interface to create and send commands to hardware, and configure the hardware for rendering.
| #define gx_end | ( | ) |
End drawing primatives.
This does nothing, its what you see in things like OpenGL so its included for similarity to such implementations. Also means it can be expanded if it turns out to be needed at some point.
| #define GX_WPAR_BP_LOAD | ( | value | ) |
| #define GX_WPAR_CP_LOAD | ( | address, | |
| value ) |
| #define GX_WPAR_OPCODE_PRIMITIVE | ( | type, | |
| format ) |
| #define GX_WPAR_XF_LOAD | ( | address, | |
| words ) |
|
extern |
Begin drawing primatives.
Signals to the GPU to expect primitive data in coming messages. Also flushes GPU state changes.
| primitive | Type of 3D primitive to draw. |
| attribute | Vertex attribute to use, values 0-7. |
| count | Vertex count. Up to 65535 |
|
extern |
Copys the internal framebuffer to the external frame buffer.
Copys the internal framebuffer to the external frame buffer. This is usually called during vblank to copy the frame buffer to display the next frame. vsync avoiding the need for double buffering.
| framebuffer | Pointer to frame buffer. Needs to be 32 byte aligned. |
| clear | Clear the internal frame buffer during the copy. |
|
extern |
Call to send end current drawing session. Then wait.
This will signal to the BP that drawing is done, flush it, then sleep the current thread until its done
|
extern |
Grabs a pixel from the embedded frame buffer.
Grabs a pixel from the embedded frame buffer. This is useful for debugging.
I don't recommend using it too much, the emulators do not like this. And it usually needs to be enabled for it to work in emulator.
|
extern |
Enables / Disables checking Z before or after texturing.
Used to turn off early checking of Z before texturing. Checking Z before texturing allows you to quickly discard the fragment and save bandwidth.
But if the TEV stages or whatever discard the fragment, the Z buffer, during the compare, will be falsy updated when the fragment is discard.
So if your scene contains these. You will need to disable this. Its on by default.
| enable | If true, Z values are checked before texturing. |
|
extern |
Gets the current FIFO.
Gets the current fifo from hardware. Useful to check up on the CP.
| fifo | Writes to fifo data into this. |
|
extern |
Creates the fifo data structure.
Creates an empty vertex descriptor.
Creates a simple fifo data structure to set in the CP.
| fifo | The fifo to setup |
| fifo_buffer | Buffer to put data into. 32 byte aligned |
| fifo_buffer_size | Size of the buffer. 32 byte aligned |
Creates the fifo data structure.
Creates a simple fifo data structure to set in the CP.
| fifo | The fifo to setup |
| fifo_buffer | Buffer to put data into. 32 byte aligned |
| fifo_buffer_size | Size of the buffer. 32 byte aligned |
|
extern |
Sets the current FIFO.
Sets the current FIFO the CP will read from. CP is hopefully disabled when you do this.
gx_initialize calls this
| fifo | The fifo to set |
|
extern |
Flashes a texture configuration onto the BP.
Sets up a texture for drawing by configuring the registers.
Its data wont be loaded into memory at this point, just that future draws with it will begin loading this new data.
| map | The texture channel to load into. 1-8 |
| texture | The texture register data. |
|
extern |
Flushes all commands to the command processor.
This inserts 32 NOP commands into the write gather pipeline to make sure that any commands at the end of the FIFO or display list get sent, since it only reads them in 32 byte burst.
This does not wait for command completion, it simply confirms commands before it will not be lost.
|
extern |
Initializes the graphics.
Puts the system graphics into a default state ready for rendering.
Takes a 32 byte aligned FIFO to hold commands. Hardware automatically fills it and cycles back through it, but write commands too fast and its possible to overflow it.
| fifo | Fifo to use. |
| video_profile | Video profile to use. |
|
extern |
Initializes the graphics state.
This function, called by gx_initialize, configures the hardware into GX's default state. That includes all the TEV stages and stuff like that.
It does not force the pipeline into a known state if somethings gone horribly wrong. Its just a bunch of calls to make the hardware into a pretty state.
This does not initialize some of the video settings. Use initialize video for that.
|
extern |
Initializes a texture object for use.
Initializes a texture object to be loaded whenever needed. This does not actually allocate or contain the image data. Make sure to keep that safe. No, it just holds the state of the registers needed in order to draw that texture.
| texture | The texture object to setup |
| data | Image data of the format |
| format | Texture Format |
| width | Width of the texture |
| height | Height of the texture |
| s_wrap | S Wrap (X values) |
| t_wrap | T Wrap (Y values) |
| mipmap | Enabling Mipmapping |
|
extern |
Initializes all the video settings from a video profile.
This function, usually following gx_initialize_state, can take a video profile and configure all the EFB and XFB copy registers to match your video profile.
|
extern |
Set the clamp mode when copying from EFB to XFB.
Defaults to clamping the top and bottom of the framebuffer.
| mode |
|
extern |
Sets the background color when copying framebuffers.
As the framebuffer is copied, it clears the EFB back with these colors and Z value.
| r | Red Channel |
| g | Green Channel |
| b | Blue Channel |
| a | Alpha Channel |
|
extern |
Sets the z value the frame buffer is cleared with.
As the frame buffer gets copied, it is cleared with this.
| z | Z value, usually the max of 0xFFFFFF (24 bits) |
|
extern |
Enables updating the color when rendering into the EFB.
| update_color | Update the color values |
| update_alpha | Update the alpha values |
|
extern |
Sets the interpolation filters used when copying the frame buffer into external frame buffers of differing resolutions.
This is a grid of values that determines how pixels are sampled when copying frame buffer.
For normal video modes you dont need to touch this.
For the X,Y pattern, Each one is between 0-12. The middle of the pixel is 6 (ish). These are for 3x MSAA generation.
filter is the array of ceoffenents between 0 and 63. Thats a Q0:6 fixed point format. And they should sum to 1 to keep normal brightness
The first 2 values are the top row. Then the next 3 are the middle row Last 2 are the bottom row.
Standard deflikering pattern is 0.25, 0.5, 0.25.
| pattern | Pixel position for the filter. |
| filter | Ceoffenents for the filter. |
|
extern |
Sets the window to of the EFB into the XFB.
Sets the window, or region, of the EFB to copy from.
| x | Begining / Left of the EFB Window |
| y | Begining / Top of the EFB Window |
| width | Width of the window EFB |
| height | Height of the Window EGB |
| xfb_width | Width of the XFB |
|
extern |
Sets the scale of the EFB to the XFB's Y.
Scales the image on the y axis to the size of the XFB
| scale | Usually xfb height / efb height |
|
extern |
Sets the gamma value when copying from EFB to XFB.
Defaults to 1.0
| gamma | The gamma value from the enum. |
|
extern |
Sets the what lines are copied from EFB to XFB.
Used to determine if all lines, or if even and odd lines are copied from EFB to XFB.
It defaults to progressive, aka, all lines.
|
extern |
Sets the format of pixels in the EFB.
Sets the format of the pixels in the EFB.
Also lets you control z compression and such.
I will need to comment more on the effects of antialiasing since some modes use it, some dont.
|
extern |
Sets the current render thread for suspension.
When the GX FIFO is too full, it will suspend the graphics thread and resume it once it clears out a bit.
gx_initialize sets this to the current thread. If you plan to call GX functions outside the thread to called gx_initialize. You may want to set it here.
You can also set it to null and bypass this functionality.
| task | Handle to the task. |
|
extern |
Offsets the scissor rectangle.
Allows the scissor rectangle to be moved around the screen.
Values range from -342 to 382 and are even.
| x | X offset of the window |
| y | Y offset of the window. |
|
extern |
Sets the scissor rectangle.
Defines the rectangle things will be culled in.
Should be set to the viewport size by default.
Values range from 0 to 2047 gx_set_scissor_offset can be used to further expand this.
| x | Begining / Left of the Window |
| y | Begining / Top of the Window |
| width | Width of thw window |
| height | Height of the Window |
|
extern |
Determins how Z values will be treated.
| enable_compare | Compare Z values? Or just pass all values |
| compare | Function to compare them with |
| enable_update | Update Z values of pixels? Or keep the previous. |
|
extern |
Clears out all vertex descriptions.
Turns off all vertex description parts in the VCD.
Enable them with gx_vtxdesc_set.
Guarantees it will be flushed to a valid state on the next draw call.
Called by gx_initialize()
|
extern |
Sets a vertex description.
Sets the source of vertex data the attributes will use.
Note, only positions, normals, colors, and texture coords support indexed types, the remaining will only be enabled or disabled.
There can only be 1 vertex description, but 8 vertex attributes.
Requires a vertex data cache flushed before use of new format.
| desc | Vertex description to enable. |
| type | Type of vertex data for it. |
|
extern |
Clears out a vertex attribute format.
Clears out a vertex attribute format.
Set with gx_vtxfmtattr_set.
Called by gx_initialize()
Guarantees it will be flushed to a valid state on the next draw call.
| attribute_index | The vertex attribute table to use, 0-7. |
|
extern |
Sets the format of a vertex attribute.
Sets the data format that vertex attributes are.
This will get updated in the VAT table of the GPU.
| attribute | The vertex attribute table to use, 0-7. Can switch between groups of vertex formats. |
| component | The component, like is it XY, or XYZ. RGB or RGBA |
| fmt | Format of the component, Is it RGBA8888, or like, U16 position data, or float |
| fraction | Number of fractional bits in fixed point values. That is, inititer formats like S16, will be divided by 2^fraction. 0-31 |