gx2: Add gx2r buffer functions.

This commit is contained in:
James Benton 2016-10-09 15:57:23 +01:00
parent e254ea3ce2
commit 9871c06e67
4 changed files with 183 additions and 4 deletions

View File

@ -2,6 +2,7 @@
#include <wut.h>
#include "enum.h"
#include "sampler.h"
#include "gx2r/buffer.h"
/**
* \defgroup gx2_shader Shaders
@ -162,7 +163,7 @@ struct GX2VertexShader
BOOL hasStreamOut;
uint32_t streamOutStride[4];
UNKNOWN(4 * 4);
GX2RBuffer gx2rBuffer;
};
CHECK_OFFSET(GX2VertexShader, 0x00, regs.sq_pgm_resources_vs);
CHECK_OFFSET(GX2VertexShader, 0x04, regs.vgt_primitiveid_en);
@ -194,6 +195,7 @@ CHECK_OFFSET(GX2VertexShader, 0x108, attribVars);
CHECK_OFFSET(GX2VertexShader, 0x10c, ringItemsize);
CHECK_OFFSET(GX2VertexShader, 0x110, hasStreamOut);
CHECK_OFFSET(GX2VertexShader, 0x114, streamOutStride);
CHECK_OFFSET(GX2VertexShader, 0x124, gx2rBuffer);
CHECK_SIZE(GX2VertexShader, 0x134);
struct GX2PixelShader
@ -231,7 +233,7 @@ struct GX2PixelShader
uint32_t samplerVarCount;
GX2SamplerVar *samplerVars;
UNKNOWN(4 * 4);
GX2RBuffer gx2rBuffer;
};
CHECK_OFFSET(GX2PixelShader, 0x00, regs.sq_pgm_resources_ps);
CHECK_OFFSET(GX2PixelShader, 0x04, regs.sq_pgm_exports_ps);
@ -256,7 +258,8 @@ CHECK_OFFSET(GX2PixelShader, 0xC8, loopVarCount);
CHECK_OFFSET(GX2PixelShader, 0xCC, loopVars);
CHECK_OFFSET(GX2PixelShader, 0xD0, samplerVarCount);
CHECK_OFFSET(GX2PixelShader, 0xD4, samplerVars);
CHECK_SIZE(GX2PixelShader, 0xe8);
CHECK_OFFSET(GX2PixelShader, 0xD8, gx2rBuffer);
CHECK_SIZE(GX2PixelShader, 0xE8);
struct GX2GeometryShader
{
@ -298,7 +301,8 @@ struct GX2GeometryShader
uint32_t ringItemSize;
BOOL hasStreamOut;
uint32_t streamOutStride[4];
UNKNOWN(4 * 4);
GX2RBuffer gx2rBuffer;
};
CHECK_OFFSET(GX2GeometryShader, 0x00, regs.sq_pgm_resources_gs);
CHECK_OFFSET(GX2GeometryShader, 0x04, regs.vgt_gs_out_prim_type);
@ -328,6 +332,7 @@ CHECK_OFFSET(GX2GeometryShader, 0x84, samplerVars);
CHECK_OFFSET(GX2GeometryShader, 0x88, ringItemSize);
CHECK_OFFSET(GX2GeometryShader, 0x8C, hasStreamOut);
CHECK_OFFSET(GX2GeometryShader, 0x90, streamOutStride);
CHECK_OFFSET(GX2GeometryShader, 0xA0, gx2rBuffer);
CHECK_SIZE(GX2GeometryShader, 0xB0);
struct GX2AttribStream

67
include/gx2r/buffer.h Normal file
View File

@ -0,0 +1,67 @@
#pragma once
#include <wut.h>
#include "resource.h"
/**
* \defgroup gx2r_buffer Buffer
* \ingroup gx2r
* @{
*/
#ifdef __cplusplus
extern "C" {
#endif
typedef struct GX2RBuffer GX2RBuffer;
struct GX2RBuffer
{
GX2RResourceFlags flags;
uint32_t elemSize;
uint32_t elemCount;
void buffer;
};
CHECK_SIZE(GX2RBuffer, 0x10);
CHECK_OFFSET(GX2RBuffer, 0x00, flags);
CHECK_OFFSET(GX2RBuffer, 0x04, elemSize);
CHECK_OFFSET(GX2RBuffer, 0x08, elemCount);
CHECK_OFFSET(GX2RBuffer, 0x0C, buffer);
BOOL
GX2RBufferExists(GX2RBuffer *buffer);
BOOL
GX2RCreateBuffer(GX2RBuffer *buffer);
BOOL
GX2RCreateBufferUserMemory(GX2RBuffer *buffer,
void *memory,
uint32_t size);
void
GX2RDestroyBufferEx(GX2RBuffer *buffer,
GX2RResourceFlags flags);
uint32_t
GX2RGetBufferAlignment(GX2RResourceFlags flags);
uint32_t
GX2RGetBufferAllocationSize(GX2RBuffer *buffer);
void
GX2RInvalidateBuffer(GX2RBuffer *buffer,
GX2RResourceFlags flags);
void *
GX2RLockBufferEx(GX2RBuffer *buffer,
GX2RResourceFlags flags);
void
GX2RUnlockBufferEx(GX2RBuffer *buffer,
GX2RResourceFlags flags);
#ifdef __cplusplus
}
#endif
/** @} */

94
include/gx2r/resource.h Normal file
View File

@ -0,0 +1,94 @@
#pragma once
#include <wut.h>
/**
* \defgroup gx2r_resource Resource
* \ingroup gx2r
* @{
*/
#ifdef __cplusplus
extern "C" {
#endif
typedef enum GX2RResourceFlags
{
//! This resource is to be used as a texture
GX2R_RESOURCE_BIND_TEXTURE = 1 << 0,
//! This resource is to be used as a colour buffer
GX2R_RESOURCE_BIND_COLOR_BUFFER = 1 << 1,
//! This resource is to be used as a depth buffer
GX2R_RESOURCE_BIND_DEPTH_BUFFER = 1 << 2,
//! This resource is to be used as a scan buffer
GX2R_RESOURCE_BIND_SCAN_BUFFER = 1 << 3,
//! This resource is to be used as a vertex buffer
GX2R_RESOURCE_BIND_VERTEX_BUFFER = 1 << 4,
//! This resource is to be used as a index buffer
GX2R_RESOURCE_BIND_INDEX_BUFFER = 1 << 5,
//! This resource is to be used as a uniform block
GX2R_RESOURCE_BIND_UNIFORM_BLOCK = 1 << 6,
//! This resource is to be used as a shader program
GX2R_RESOURCE_BIND_SHADER_PROGRAM = 1 << 7,
//! This resource is to be used as a stream output
GX2R_RESOURCE_BIND_STREAM_OUTPUT = 1 << 8,
//! This resource is to be used as a display list
GX2R_RESOURCE_BIND_DISPLAY_LIST = 1 << 9,
//! This resource is to be used as a geometry shader ring buffer
GX2R_RESOURCE_BIND_GS_RING_BUFFER = 1 << 10,
//! Invalidate resource for a CPU read
GX2R_RESOURCE_USAGE_CPU_READ = 1 << 11,
//! Invalidate resource for a CPU write
GX2R_RESOURCE_USAGE_CPU_WRITE = 1 << 12,
//! Invalidate resource for a GPU read
GX2R_RESOURCE_USAGE_GPU_READ = 1 << 13,
//! Invalidate resource for a GPU write
GX2R_RESOURCE_USAGE_GPU_WRITE = 1 << 14,
//! Invalidate resource for a DMA read
GX2R_RESOURCE_USAGE_DMA_READ = 1 << 15,
//! Invalidate resource for a DMA write
GX2R_RESOURCE_USAGE_DMA_WRITE = 1 << 16,
//! Force resource allocation to be in MEM1
GX2R_RESOURCE_USAGE_FORCE_MEM1 = 1 << 17,
//! Force resource allocation to be in MEM2
GX2R_RESOURCE_USAGE_FORCE_MEM2 = 1 << 18,
//! Disable CPU invalidation
GX2R_RESOURCE_DISABLE_CPU_INVALIDATE = 1 << 20,
//! Disable GPU invalidation
GX2R_RESOURCE_DISABLE_GPU_INVALIDATE = 1 << 21,
//! Resource is locked for read-only access
GX2R_RESOURCE_LOCKED_READ_ONLY = 1 << 22,
//! Resource is to be allocated in user memory
GX2R_RESOURCE_USER_MEMORY = 1 << 29,
//! Resource is locked for all access
GX2R_RESOURCE_LOCKED = 1 << 30,
} GX2RResourceFlags;
#ifdef __cplusplus
}
#endif
/** @} */

View File

@ -191,3 +191,16 @@ EXPORT(GX2InitTextureRegs);
EXPORT(GX2SetPixelTexture);
EXPORT(GX2SetVertexTexture);
EXPORT(GX2SetGeometryTexture);
// gx2r/buffer.h
EXPORT(GX2RBufferExists);
EXPORT(GX2RCreateBuffer);
EXPORT(GX2RCreateBufferUserMemory);
EXPORT(GX2RDestroyBufferEx);
EXPORT(GX2RGetBufferAlignment);
EXPORT(GX2RGetBufferAllocationSize);
EXPORT(GX2RInvalidateBuffer);
EXPORT(GX2RLockBufferEx);
EXPORT(GX2RUnlockBufferEx);
// gx2r/resource.h