Merge pull request #1094 from UnknownShadow200/GfxRewrite2

Slightly optimise human model rendering
This commit is contained in:
UnknownShadow200 2023-11-10 18:20:44 +11:00 committed by GitHub
commit f9525efaf5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 38 additions and 91 deletions

View file

@ -21,9 +21,6 @@ extern const u32 offset_shbin_size;
(GX_TRANSFER_FLIP_VERT(0) | GX_TRANSFER_OUT_TILED(0) | GX_TRANSFER_RAW_COPY(0) | \
GX_TRANSFER_IN_FORMAT(GX_TRANSFER_FMT_RGBA8) | GX_TRANSFER_OUT_FORMAT(GX_TRANSFER_FMT_RGB8) | \
GX_TRANSFER_SCALING(GX_TRANSFER_SCALE_NO))
// Current format and size of vertices
static int gfx_stride, gfx_format = -1;
/*########################################################################################################################*
@ -442,11 +439,6 @@ void* Gfx_LockDynamicVb(GfxResourceID vb, VertexFormat fmt, int count) {
void Gfx_UnlockDynamicVb(GfxResourceID vb) { gfx_vertices = vb; }
void Gfx_SetDynamicVbData(GfxResourceID vb, void* vertices, int vCount) {
gfx_vertices = vb;
Mem_Copy(vb, vertices, vCount * gfx_stride);
}
void Gfx_DeleteDynamicVb(GfxResourceID* vb) { Gfx_DeleteVb(vb); }

View file

@ -23,8 +23,7 @@ static const GUID guid_IXDGIDevice = { 0x54ec77fa, 0x1377, 0x44e6, { 0x8c, 0
// Some generally useful background links
// https://gist.github.com/d7samurai/261c69490cce0620d0bfc93003cd1052
static int gfx_format = -1, depthBits; // TODO implement depthBits?? for ZNear calc
static UINT gfx_stride;
static int depthBits; // TODO implement depthBits?? for ZNear calc
static GfxResourceID white_square;
#ifdef _MSC_VER
@ -396,12 +395,6 @@ void Gfx_UnlockDynamicVb(GfxResourceID vb) {
Gfx_BindDynamicVb(vb);
}
void Gfx_SetDynamicVbData(GfxResourceID vb, void* vertices, int vCount) {
void* data = Gfx_LockDynamicVb(vb, gfx_format, vCount);
Mem_Copy(data, vertices, vCount * gfx_stride);
Gfx_UnlockDynamicVb(vb);
}
/*########################################################################################################################*
*-----------------------------------------------------Vertex rendering----------------------------------------------------*

View file

@ -19,8 +19,6 @@
/* https://docs.microsoft.com/en-us/windows/win32/direct3d9/d3dfvf-texcoordsizen */
static DWORD d3d9_formatMappings[] = { D3DFVF_XYZ | D3DFVF_DIFFUSE, D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1 };
/* Current format and size of vertices */
static int gfx_stride, gfx_format = -1;
static IDirect3D9* d3d;
static IDirect3DDevice9* device;

View file

@ -9,9 +9,6 @@
#include <kos.h>
#include <dc/matrix.h>
#include <dc/pvr.h>
/* Current format and size of vertices */
static int gfx_stride, gfx_format = -1;
static cc_bool renderingDisabled;
@ -166,12 +163,6 @@ void Gfx_UnlockDynamicVb(GfxResourceID vb) {
//dcache_flush_range(vb, vb_size);
}
void Gfx_SetDynamicVbData(GfxResourceID vb, void* vertices, int vCount) {
gfx_vertices = vb;
Mem_Copy(vb, vertices, vCount * gfx_stride);
//dcache_flush_range(vertices, vCount * gfx_stride);
}
void Gfx_DeleteDynamicVb(GfxResourceID* vb) { Gfx_DeleteVb(vb); }

View file

@ -332,14 +332,6 @@ void Gfx_UnlockDynamicVb(GfxResourceID vb) {
DCFlushRange(vb, vb_size);
}
// Current size of vertices
static int gfx_stride; // TODO move down to Drawing area ??
void Gfx_SetDynamicVbData(GfxResourceID vb, void* vertices, int vCount) {
gfx_vertices = vb;
Mem_Copy(vb, vertices, vCount * gfx_stride);
DCFlushRange(vertices, vCount * gfx_stride);
}
void Gfx_DeleteDynamicVb(GfxResourceID* vb) { Gfx_DeleteVb(vb); }
@ -476,9 +468,6 @@ void Gfx_DisableTextureOffset(void) {
/*########################################################################################################################*
*---------------------------------------------------------Drawing---------------------------------------------------------*
*#########################################################################################################################*/
// Current format and size of vertices
static int gfx_format = -1;
void Gfx_SetVertexFormat(VertexFormat fmt) {
if (fmt == gfx_format) return;
gfx_format = fmt;

View file

@ -159,8 +159,6 @@ typedef void (*GL_SetupVBFunc)(void);
typedef void (*GL_SetupVBRangeFunc)(int startVertex);
static GL_SetupVBFunc gfx_setupVBFunc;
static GL_SetupVBRangeFunc gfx_setupVBRangeFunc;
/* Current format and size of vertices */
static int gfx_stride, gfx_format = -1;
#if defined CC_BUILD_WIN && !defined CC_BUILD_GL11
/* Note the following about calling OpenGL functions on Windows */

View file

@ -86,8 +86,6 @@ static const struct DynamicLibSym core_funcs[] = {
#endif
#include "_GLShared.h"
/* Current format and size of vertices */
static int gfx_stride, gfx_format = -1;
static GfxResourceID white_square;

View file

@ -9,8 +9,6 @@
#include <GL/gl_integration.h>
#include <GL/gl.h>
/* Current format and size of vertices */
static int gfx_stride, gfx_format;
typedef void (*GL_SetupVBFunc)(void);
typedef void (*GL_SetupVBRangeFunc)(int startVertex);
static GL_SetupVBFunc gfx_setupVBFunc;
@ -319,11 +317,6 @@ void Gfx_UnlockDynamicVb(GfxResourceID vb) {
gfx_vertices = vb;
}
void Gfx_SetDynamicVbData(GfxResourceID vb, void* vertices, int vCount) {
gfx_vertices = vb;
Mem_Copy(vb, vertices, vCount * gfx_stride);
}
void Gfx_DeleteDynamicVb(GfxResourceID* vb) { Gfx_DeleteVb(vb); }

View file

@ -7,9 +7,6 @@
#include <malloc.h>
#include <rsx/rsx.h>
#include <sysutil/video.h>
/* Current format and size of vertices */
static int gfx_stride, gfx_format = -1;
static cc_bool renderingDisabled;
static gcmContextData* context;
@ -550,12 +547,6 @@ void Gfx_UnlockDynamicVb(GfxResourceID vb) {
rsxInvalidateVertexCache(context); // TODO needed?
}
void Gfx_SetDynamicVbData(GfxResourceID vb, void* vertices, int vCount) {
Mem_Copy(vb, vertices, vCount * gfx_stride);
Gfx_BindVb(vb);
rsxInvalidateVertexCache(context); // TODO needed?
}
void Gfx_DeleteDynamicVb(GfxResourceID* vb) { Gfx_DeleteVb(vb); }

View file

@ -266,8 +266,7 @@ void Gfx_OnWindowResize(void) { }
static cc_uint8* gfx_vertices;
/* Current format and size of vertices */
static int gfx_stride, gfx_format = -1, gfx_fields;
static int gfx_fields;
/*########################################################################################################################*
@ -323,12 +322,6 @@ void Gfx_UnlockDynamicVb(GfxResourceID vb) {
sceKernelDcacheWritebackInvalidateRange(vb, vb_size);
}
void Gfx_SetDynamicVbData(GfxResourceID vb, void* vertices, int vCount) {
gfx_vertices = vb;
Mem_Copy(vb, vertices, vCount * gfx_stride);
sceKernelDcacheWritebackInvalidateRange(vertices, vCount * gfx_stride);
}
void Gfx_DeleteDynamicVb(GfxResourceID* vb) { Gfx_DeleteVb(vb); }

View file

@ -7,8 +7,6 @@
#include <vitasdk.h>
// TODO track last frame used on
/* Current format and size of vertices */
static int gfx_stride, gfx_format = -1;
static cc_bool gfx_depthOnly;
static cc_bool gfx_alphaTesting, gfx_alphaBlending;
static int frontBufferIndex, backBufferIndex;

View file

@ -18,10 +18,6 @@
// A lot of figuring out which GPU registers to use came from:
// - comparing against pbgl and pbkit
// Current format and size of vertices
static int gfx_stride, gfx_format = -1;
static void LoadVertexShader(uint32_t* program, int programSize) {
uint32_t* p;
@ -461,11 +457,6 @@ void* Gfx_LockDynamicVb(GfxResourceID vb, VertexFormat fmt, int count) {
void Gfx_UnlockDynamicVb(GfxResourceID vb) { Gfx_BindVb(vb); }
void Gfx_SetDynamicVbData(GfxResourceID vb, void* vertices, int vCount) {
Mem_Copy(vb, vertices, vCount * gfx_stride);
Gfx_BindVb(vb);
}
void Gfx_DeleteDynamicVb(GfxResourceID* vb) { Gfx_DeleteVb(vb); }

View file

@ -882,17 +882,19 @@ struct ModelSet {
struct ModelPart head, torso, hat, torsoLayer;
struct ModelLimbs limbs[3];
};
#define HUMAN_BASE_VERTICES (6 * MODEL_BOX_VERTICES)
#define HUMAN_HAT32_VERTICES (1 * MODEL_BOX_VERTICES)
#define HUMAN_HAT64_VERTICES (6 * MODEL_BOX_VERTICES)
static void HumanModel_DrawCore(struct Entity* e, struct ModelSet* model, cc_bool opaque) {
static void HumanModel_DrawCore(struct Entity* e, struct ModelSet* model, cc_bool opaqueBody) {
struct ModelLimbs* set;
int type;
int type, num;
Model_ApplyTexture(e);
/* human model draws the body opaque so players can't have invisible skins */
if (opaque) Gfx_SetAlphaTest(false);
type = Models.skinType;
set = &model->limbs[type & 0x3];
num = HUMAN_BASE_VERTICES + (type == SKIN_64x32 ? HUMAN_HAT32_VERTICES : HUMAN_HAT64_VERTICES);
Model_LockVB(num);
Model_DrawRotate(-e->Pitch * MATH_DEG2RAD, 0, 0, &model->head, true);
Model_DrawPart(&model->torso);
@ -904,12 +906,6 @@ static void HumanModel_DrawCore(struct Entity* e, struct ModelSet* model, cc_boo
Model_DrawRotate(e->Anim.RightArmX, 0, e->Anim.RightArmZ, &set->rightArm, false);
Models.Rotation = ROTATE_ORDER_ZYX;
/* have to seperately draw these vertices without alpha testing */
if (opaque) {
Model_UpdateVB();
Gfx_SetAlphaTest(true);
}
if (type != SKIN_64x32) {
Model_DrawPart(&model->torsoLayer);
Model_DrawRotate(e->Anim.LeftLegX, 0, e->Anim.LeftLegZ, &set->leftLegLayer, false);
@ -921,19 +917,33 @@ static void HumanModel_DrawCore(struct Entity* e, struct ModelSet* model, cc_boo
Models.Rotation = ROTATE_ORDER_ZYX;
}
Model_DrawRotate(-e->Pitch * MATH_DEG2RAD, 0, 0, &model->hat, true);
Model_UpdateVB();
Model_UnlockVB();
if (opaqueBody) {
/* human model draws the body opaque so players can't have invisible skins */
Gfx_SetAlphaTest(false);
Gfx_DrawVb_IndexedTris_Range(HUMAN_BASE_VERTICES, 0);
Gfx_SetAlphaTest(true);
Gfx_DrawVb_IndexedTris_Range(num - HUMAN_BASE_VERTICES, HUMAN_BASE_VERTICES);
} else {
Gfx_DrawVb_IndexedTris(num);
}
}
static void HumanModel_DrawArmCore(struct ModelSet* model) {
struct ModelLimbs* set;
int type;
int type, num;
type = Models.skinType;
set = &model->limbs[type & 0x3];
num = type == SKIN_64x32 ? MODEL_BOX_VERTICES : (2 * MODEL_BOX_VERTICES);
Model_LockVB(num);
Model_DrawArmPart(&set->rightArm);
if (type != SKIN_64x32) Model_DrawArmPart(&set->rightArmLayer);
Model_UpdateVB();
Model_UnlockVB();
Gfx_DrawVb_IndexedTris(num);
}

View file

@ -19,6 +19,8 @@ const cc_string Gfx_LowPerfMessage = String_FromConst("&eRunning in reduced perf
static const int strideSizes[] = { SIZEOF_VERTEX_COLOURED, SIZEOF_VERTEX_TEXTURED };
/* Whether mipmaps must be created for all dimensions down to 1x1 or not */
static cc_bool customMipmapsLevels;
/* Current format and size of vertices */
static int gfx_stride, gfx_format = -1;
static cc_bool gfx_vsync, gfx_fogEnabled;
static float gfx_minFrameMs;
@ -389,6 +391,16 @@ GfxResourceID Gfx_CreateDynamicVb(VertexFormat fmt, int maxVertices) {
}
}
#if defined CC_BUILD_GL || defined CC_BUILD_D3D9
/* Slightly more efficient implementations are defined in the backends */
#else
void Gfx_SetDynamicVbData(GfxResourceID vb, void* vertices, int vCount) {
void* data = Gfx_LockDynamicVb(vb, gfx_format, vCount);
Mem_Copy(data, vertices, vCount * gfx_stride);
Gfx_UnlockDynamicVb(vb);
}
#endif
/*########################################################################################################################*
*----------------------------------------------------Graphics component---------------------------------------------------*