mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-24 05:10:42 -04:00
Xbox: Avoid uploading shader repeatedly, just change run address
This commit is contained in:
parent
f5541e7518
commit
04df26a574
@ -20,23 +20,16 @@
|
|||||||
// A lot of figuring out which GPU registers to use came from:
|
// A lot of figuring out which GPU registers to use came from:
|
||||||
// - comparing against pbgl and pbkit
|
// - comparing against pbgl and pbkit
|
||||||
|
|
||||||
static void LoadVertexShader(uint32_t* program, int programSize) {
|
// Room for 136 vertex shader instructions
|
||||||
uint32_t* p;
|
// Only need 3, so give 40 instructions to each
|
||||||
|
#define VS_COLOURED_OFFSET 0
|
||||||
|
#define VS_TEXTURED_OFFSET 40
|
||||||
|
|
||||||
// Set cursor for program upload
|
static void LoadVertexShader(int offset, uint32_t* program, int programSize) {
|
||||||
p = pb_begin();
|
uint32_t* p = pb_begin();
|
||||||
p = pb_push1(p, NV097_SET_TRANSFORM_PROGRAM_LOAD, 0);
|
p = NV2A_set_program_upload_offset(p, offset);
|
||||||
|
p = NV2A_upload_program(p, program, programSize);
|
||||||
pb_end(p);
|
pb_end(p);
|
||||||
|
|
||||||
// Copy program instructions (16 bytes each)
|
|
||||||
for (int i = 0; i < programSize / 16; i++)
|
|
||||||
{
|
|
||||||
p = pb_begin();
|
|
||||||
pb_push(p++, NV097_SET_TRANSFORM_PROGRAM, 4);
|
|
||||||
Mem_Copy(p, &program[i * 4], 4 * 4);
|
|
||||||
p += 4;
|
|
||||||
pb_end(p);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t vs_coloured_program[] = {
|
static uint32_t vs_coloured_program[] = {
|
||||||
@ -68,8 +61,7 @@ static void SetupShaders(void) {
|
|||||||
uint32_t *p;
|
uint32_t *p;
|
||||||
|
|
||||||
p = pb_begin();
|
p = pb_begin();
|
||||||
// Set run address of shader
|
p = NV2A_set_program_run_offset(p, 0);
|
||||||
p = pb_push1(p, NV097_SET_TRANSFORM_PROGRAM_START, 0);
|
|
||||||
|
|
||||||
// Set execution mode
|
// Set execution mode
|
||||||
p = pb_push1(p, NV097_SET_TRANSFORM_EXECUTION_MODE,
|
p = pb_push1(p, NV097_SET_TRANSFORM_EXECUTION_MODE,
|
||||||
@ -118,6 +110,9 @@ void Gfx_Create(void) {
|
|||||||
ResetState();
|
ResetState();
|
||||||
Gfx.NonPowTwoTexturesSupport = GFX_NONPOW2_UPLOAD;
|
Gfx.NonPowTwoTexturesSupport = GFX_NONPOW2_UPLOAD;
|
||||||
|
|
||||||
|
LoadVertexShader(VS_COLOURED_OFFSET, vs_textured_program, sizeof(vs_textured_program));
|
||||||
|
LoadVertexShader(VS_TEXTURED_OFFSET, vs_coloured_program, sizeof(vs_coloured_program));
|
||||||
|
|
||||||
// 1x1 dummy white texture
|
// 1x1 dummy white texture
|
||||||
struct Bitmap bmp;
|
struct Bitmap bmp;
|
||||||
BitmapCol pixels[1] = { BITMAPCOLOR_WHITE };
|
BitmapCol pixels[1] = { BITMAPCOLOR_WHITE };
|
||||||
@ -539,31 +534,15 @@ void Gfx_OnWindowResize(void) { }
|
|||||||
static struct Vec4 vp_scale = { 320, -240, 8388608, 1 };
|
static struct Vec4 vp_scale = { 320, -240, 8388608, 1 };
|
||||||
static struct Vec4 vp_offset = { 320, 240, 8388608, 1 };
|
static struct Vec4 vp_offset = { 320, 240, 8388608, 1 };
|
||||||
static struct Matrix _view, _proj, _mvp;
|
static struct Matrix _view, _proj, _mvp;
|
||||||
|
// TODO Upload constants too
|
||||||
static void UpdateVSConstants(void) {
|
// if necessary, look at vs.inl output for 'c[5]' etc..
|
||||||
uint32_t* p;
|
|
||||||
p = pb_begin();
|
|
||||||
|
|
||||||
p = NV2A_set_constant_upload_offset(p, 0);
|
|
||||||
|
|
||||||
// upload transformation matrix
|
|
||||||
p = NV2A_start_constants_upload(p, 16);
|
|
||||||
Mem_Copy(p, &_mvp, 16 * 4); p += 16;
|
|
||||||
|
|
||||||
// Upload constants too
|
|
||||||
//struct Vec4 v = { 1, 1, 1, 1 };
|
|
||||||
//Mem_Copy(p, &v, 4 * 4); p += 4;
|
|
||||||
// if necessary, look at vs.inl output for 'c[5]' etc..
|
|
||||||
|
|
||||||
pb_end(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Gfx_LoadMatrix(MatrixType type, const struct Matrix* matrix) {
|
void Gfx_LoadMatrix(MatrixType type, const struct Matrix* matrix) {
|
||||||
struct Matrix* dst = type == MATRIX_PROJ ? &_proj : &_view;
|
struct Matrix* dst = type == MATRIX_PROJ ? &_proj : &_view;
|
||||||
*dst = *matrix;
|
*dst = *matrix;
|
||||||
|
|
||||||
Matrix_Mul(&_mvp, &_view, &_proj);
|
Matrix_Mul(&_mvp, &_view, &_proj);
|
||||||
|
|
||||||
|
struct Matrix final;
|
||||||
struct Matrix vp = Matrix_Identity;
|
struct Matrix vp = Matrix_Identity;
|
||||||
vp.row1.x = vp_scale.x;
|
vp.row1.x = vp_scale.x;
|
||||||
vp.row2.y = vp_scale.y;
|
vp.row2.y = vp_scale.y;
|
||||||
@ -572,14 +551,19 @@ void Gfx_LoadMatrix(MatrixType type, const struct Matrix* matrix) {
|
|||||||
vp.row4.y = vp_offset.y;
|
vp.row4.y = vp_offset.y;
|
||||||
vp.row4.z = 8388608;
|
vp.row4.z = 8388608;
|
||||||
|
|
||||||
Matrix_Mul(&_mvp, &_mvp, &vp);
|
Matrix_Mul(&final, &_mvp, &vp);
|
||||||
UpdateVSConstants();
|
|
||||||
|
uint32_t* p;
|
||||||
|
p = pb_begin();
|
||||||
|
p = NV2A_set_constant_upload_offset(p, 0);
|
||||||
|
p = NV2A_upload_constants(p, &final, 16);
|
||||||
|
pb_end(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_LoadMVP(const struct Matrix* view, const struct Matrix* proj, struct Matrix* mvp) {
|
void Gfx_LoadMVP(const struct Matrix* view, const struct Matrix* proj, struct Matrix* mvp) {
|
||||||
Gfx_LoadMatrix(MATRIX_VIEW, view);
|
Gfx_LoadMatrix(MATRIX_VIEW, view);
|
||||||
Gfx_LoadMatrix(MATRIX_PROJ, proj);
|
Gfx_LoadMatrix(MATRIX_PROJ, proj);
|
||||||
Matrix_Mul(mvp, view, proj);
|
Mem_Copy(mvp, &_mvp, sizeof(struct Matrix));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gfx_EnableTextureOffset(float x, float y) {
|
void Gfx_EnableTextureOffset(float x, float y) {
|
||||||
@ -630,13 +614,17 @@ void Gfx_SetVertexFormat(VertexFormat fmt) {
|
|||||||
p = NV2A_set_vertex_attrib_format(p, COLOUR_ATTR_INDEX,
|
p = NV2A_set_vertex_attrib_format(p, COLOUR_ATTR_INDEX,
|
||||||
NV097_SET_VERTEX_DATA_ARRAY_FORMAT_TYPE_UB_D3D, 4, SIZEOF_VERTEX_COLOURED);
|
NV097_SET_VERTEX_DATA_ARRAY_FORMAT_TYPE_UB_D3D, 4, SIZEOF_VERTEX_COLOURED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fmt == VERTEX_FORMAT_TEXTURED) {
|
||||||
|
p = NV2A_set_program_run_offset(p, VS_COLOURED_OFFSET);
|
||||||
|
} else {
|
||||||
|
p = NV2A_set_program_run_offset(p, VS_TEXTURED_OFFSET);
|
||||||
|
}
|
||||||
pb_end(p);
|
pb_end(p);
|
||||||
|
|
||||||
if (fmt == VERTEX_FORMAT_TEXTURED) {
|
if (fmt == VERTEX_FORMAT_TEXTURED) {
|
||||||
LoadVertexShader(vs_textured_program, sizeof(vs_textured_program));
|
|
||||||
LoadFragmentShader_Textured();
|
LoadFragmentShader_Textured();
|
||||||
} else {
|
} else {
|
||||||
LoadVertexShader(vs_coloured_program, sizeof(vs_coloured_program));
|
|
||||||
LoadFragmentShader_Coloured();
|
LoadFragmentShader_Coloured();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,12 +49,35 @@ static CC_INLINE uint32_t* NV2A_set_constant_upload_offset(uint32_t* p, int offs
|
|||||||
return pb_push1(p, NV097_SET_TRANSFORM_CONSTANT_LOAD, 96 + offset);
|
return pb_push1(p, NV097_SET_TRANSFORM_CONSTANT_LOAD, 96 + offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
static CC_INLINE uint32_t* NV2A_start_constants_upload(uint32_t* p, int num_dwords) {
|
static CC_INLINE uint32_t* NV2A_upload_constants(uint32_t* p, void* src, int num_dwords) {
|
||||||
pb_push(p++, NV097_SET_TRANSFORM_CONSTANT, num_dwords);
|
pb_push(p++, NV097_SET_TRANSFORM_CONSTANT, num_dwords);
|
||||||
|
Mem_Copy(p, src, num_dwords * 4); p += num_dwords;
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*########################################################################################################################*
|
||||||
|
*---------------------------------------------------Vertex shader programs-------------------------------------------------*
|
||||||
|
*#########################################################################################################################*/
|
||||||
|
static CC_INLINE uint32_t* NV2A_set_program_upload_offset(uint32_t* p, int offset) {
|
||||||
|
return pb_push1(p, NV097_SET_TRANSFORM_PROGRAM_LOAD, offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
static CC_INLINE uint32_t* NV2A_upload_program(uint32_t* p, uint32_t* program, int size) {
|
||||||
|
// Copy program instructions (16 bytes each)
|
||||||
|
for (int i = 0; i < size / 16; i++, program += 4)
|
||||||
|
{
|
||||||
|
pb_push(p++, NV097_SET_TRANSFORM_PROGRAM, 4);
|
||||||
|
Mem_Copy(p, program, 16); p += 4;
|
||||||
|
}
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
static CC_INLINE uint32_t* NV2A_set_program_run_offset(uint32_t* p, int offset) {
|
||||||
|
return pb_push1(p, NV097_SET_TRANSFORM_PROGRAM_START, offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*-----------------------------------------------------Vertex attributes---------------------------------------------------*
|
*-----------------------------------------------------Vertex attributes---------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user