Move perspective divide to the submission loop

This commit is contained in:
Luke Benstead 2020-10-20 20:15:16 +01:00
parent 952c915ee8
commit 40aedc2530
2 changed files with 19 additions and 20 deletions

View File

@ -925,25 +925,6 @@ static void light(SubmissionTarget* target) {
_glPerformLighting(vertex, ES, target->count);
}
#define PVR_MIN_Z 0.2f
#define PVR_MAX_Z 1.0 + PVR_MIN_Z
GL_FORCE_INLINE void divide(SubmissionTarget* target) {
TRACE();
/* Perform perspective divide on each vertex */
Vertex* vertex = _glSubmissionTargetStart(target);
ITERATE(target->count) {
float f = MATH_Fast_Invert(vertex->w);
vertex->xyz[0] *= f;
vertex->xyz[1] *= f;
vertex->xyz[2] *= f;
vertex->xyz[2] = MAX(1.0f - (vertex->xyz[2] * 0.5f + 0.5f), 0.0001f);
++vertex;
}
}
GL_FORCE_INLINE void push(PVRHeader* header, GLboolean multiTextureHeader, PolyList* activePolyList, GLshort textureUnit) {
TRACE();
@ -1088,7 +1069,6 @@ GL_FORCE_INLINE void submitVertices(GLenum mode, GLsizei first, GLuint count, GL
}
divide(target);
push(_glSubmissionTargetHeader(target), GL_FALSE, target->output, 0);
/*

View File

@ -45,6 +45,21 @@ static inline ListIterator* begin(void* src, int n) {
return (n) ? it : NULL;
}
GL_FORCE_INLINE isVertex(const Vertex* vertex) {
return (
vertex->flags == PVR_CMD_VERTEX ||
vertex->flags == PVR_CMD_VERTEX_EOL
);
}
static inline void perspective_divide(Vertex* vertex) {
float f = MATH_Fast_Invert(vertex->w);
vertex->xyz[0] *= f;
vertex->xyz[1] *= f;
vertex->xyz[2] *= f;
vertex->xyz[2] = MAX(1.0f - (vertex->xyz[2] * 0.5f + 0.5f), 0.0001f);
}
static void pvr_list_submit(void *src, int n) {
GLuint *d = TA_SQ_ADDR;
@ -53,6 +68,10 @@ static void pvr_list_submit(void *src, int n) {
while(it) {
__asm__("pref @%0" : : "r"(it->current + 1)); /* prefetch 64 bytes for next loop */
if(it->current->flags != DEAD) {
if(isVertex(it->current)) {
perspective_divide(it->current);
}
GLuint* s = (GLuint*) it->current;
d[0] = *(s++);