Dreamcast: Fix last commit oops

This commit is contained in:
UnknownShadow200 2024-04-25 22:19:53 +10:00
parent 6f5500d4e8
commit 2d307e6fc1
6 changed files with 22 additions and 54 deletions

View File

@ -4,7 +4,7 @@
#include "Errors.h" #include "Errors.h"
#include "Logger.h" #include "Logger.h"
#include "Window.h" #include "Window.h"
#include "../third_party/gldc/include/gldc.h" #include "../third_party/gldc/gldc.h"
#include <malloc.h> #include <malloc.h>
#include <kos.h> #include <kos.h>
#include <dc/matrix.h> #include <dc/matrix.h>

View File

@ -8,34 +8,12 @@ static const void* VERTEX_PTR;
GLuint i = count; \ GLuint i = count; \
while(i--) while(i--)
static void generateColouredQuads(Vertex* dst, const GLsizei first, const GLuint count) {
/* Generating PVR vertices from the user-submitted data gets complicated, particularly
* when a realloc could invalidate pointers. This structure holds all the information
* we need on the target vertex array to allow passing around to the various stages (e.g. generate/clip etc.)
*/
typedef struct __attribute__((aligned(32))) {
PolyList* output;
uint32_t header_offset; // The offset of the header in the output list
uint32_t start_offset; // The offset into the output list
} SubmissionTarget;
static SubmissionTarget SUBMISSION_TARGET;
GL_FORCE_INLINE PolyHeader* _glSubmissionTargetHeader(SubmissionTarget* target) {
return aligned_vector_at(&target->output->vector, target->header_offset);
}
GL_FORCE_INLINE Vertex* _glSubmissionTargetStart(SubmissionTarget* target) {
return aligned_vector_at(&target->output->vector, target->start_offset);
}
static void generateColouredQuads(SubmissionTarget* target, const GLsizei first, const GLuint count) {
/* Read from the client buffers and generate an array of ClipVertices */ /* Read from the client buffers and generate an array of ClipVertices */
GLuint numQuads = count / 4; GLuint numQuads = count / 4;
Vertex* start = _glSubmissionTargetStart(target);
/* Copy the pos, uv and color directly in one go */ /* Copy the pos, uv and color directly in one go */
const GLubyte* src = VERTEX_PTR + (first * 16); const GLubyte* src = VERTEX_PTR + (first * 16);
Vertex* dst = start;
const float w = 1.0f; const float w = 1.0f;
PREFETCH(src); PREFETCH(src);
@ -62,14 +40,12 @@ static void generateColouredQuads(SubmissionTarget* target, const GLsizei first,
} }
} }
static void generateTexturedQuads(SubmissionTarget* target, const GLsizei first, const GLuint count) { static void generateTexturedQuads(Vertex* dst, const GLsizei first, const GLuint count) {
/* Read from the client buffers and generate an array of ClipVertices */ /* Read from the client buffers and generate an array of ClipVertices */
GLuint numQuads = count / 4; GLuint numQuads = count / 4;
Vertex* start = _glSubmissionTargetStart(target);
/* Copy the pos, uv and color directly in one go */ /* Copy the pos, uv and color directly in one go */
const GLubyte* src = VERTEX_PTR + (first * 24); const GLubyte* src = VERTEX_PTR + (first * 24);
Vertex* dst = start;
const float w = 1.0f; const float w = 1.0f;
PREFETCH(src); PREFETCH(src);
@ -96,47 +72,40 @@ static void generateTexturedQuads(SubmissionTarget* target, const GLsizei first,
} }
} }
void _glInitSubmissionTarget() {
SubmissionTarget* target = &SUBMISSION_TARGET;
target->output = NULL;
target->header_offset = target->start_offset = 0;
}
extern void apply_poly_header(PolyHeader* header, PolyList* activePolyList); extern void apply_poly_header(PolyHeader* header, PolyList* activePolyList);
GL_FORCE_INLINE void submitVertices(GLuint vertexCount) { GL_FORCE_INLINE Vertex* submitVertices(GLuint vertexCount) {
SubmissionTarget* const target = &SUBMISSION_TARGET;
TRACE(); TRACE();
target->output = _glActivePolyList(); PolyList* output = _glActivePolyList();
uint32_t header_offset;
uint32_t start_offset;
uint32_t vector_size = aligned_vector_size(&target->output->vector); uint32_t vector_size = aligned_vector_size(&output->vector);
GLboolean header_required = (vector_size == 0) || STATE_DIRTY; GLboolean header_required = (vector_size == 0) || STATE_DIRTY;
target->header_offset = vector_size; header_offset = vector_size;
target->start_offset = target->header_offset + (header_required ? 1 : 0); start_offset = header_offset + (header_required ? 1 : 0);
gl_assert(target->header_offset >= 0);
/* Make room for the vertices and header */ /* Make room for the vertices and header */
aligned_vector_extend(&target->output->vector, (header_required) + vertexCount); aligned_vector_extend(&output->vector, (header_required) + vertexCount);
gl_assert(target->header_offset < aligned_vector_size(&target->output->vector)); gl_assert(header_offset < aligned_vector_size(&output->vector));
if (header_required) { if (header_required) {
apply_poly_header(_glSubmissionTargetHeader(target), target->output); apply_poly_header(aligned_vector_at(&output->vector, header_offset), output);
STATE_DIRTY = GL_FALSE; STATE_DIRTY = GL_FALSE;
} }
return aligned_vector_at(&output->vector, start_offset);
} }
void APIENTRY glDrawArrays(GLenum mode, GLint first, GLsizei count) { void APIENTRY glDrawArrays(GLenum mode, GLint first, GLsizei count) {
TRACE(); TRACE();
if (!count) return; if (!count) return;
Vertex* start = submitVertices(count);
submitVertices(count);
if (TEXTURES_ENABLED) { if (TEXTURES_ENABLED) {
generateTexturedQuads(&SUBMISSION_TARGET, first, count); generateTexturedQuads(start, first, count);
} else { } else {
generateColouredQuads(&SUBMISSION_TARGET, first, count); generateColouredQuads(start, first, count);
} }
} }

View File

@ -26,7 +26,6 @@ void APIENTRY glKosInit() {
InitGPU(config.autosort_enabled, config.fsaa_enabled); InitGPU(config.autosort_enabled, config.fsaa_enabled);
AUTOSORT_ENABLED = config.autosort_enabled; AUTOSORT_ENABLED = config.autosort_enabled;
_glInitSubmissionTarget();
_glInitContext(); _glInitContext();
_glInitTextures(); _glInitTextures();

View File

@ -8,7 +8,7 @@
#include "platform.h" #include "platform.h"
#include "types.h" #include "types.h"
#include "../include/gldc.h" #include "../gldc.h"
#include "aligned_vector.h" #include "aligned_vector.h"

View File

@ -257,10 +257,10 @@ Viewport VIEWPORT;
/* Set the GL viewport */ /* Set the GL viewport */
void APIENTRY glViewport(GLint x, GLint y, GLsizei width, GLsizei height) { void APIENTRY glViewport(GLint x, GLint y, GLsizei width, GLsizei height) {
VIEWPORT.hwidth = ((GLfloat)width) * 0.5f; VIEWPORT.hwidth = width * 0.5f;
VIEWPORT.hheight = ((GLfloat)height) * -0.5f; VIEWPORT.hheight = height * -0.5f;
VIEWPORT.x_plus_hwidth = x + VIEWPORT.hwidth; VIEWPORT.x_plus_hwidth = x + width * 0.5f;
VIEWPORT.y_plus_hheight = y + VIEWPORT.hheight; VIEWPORT.y_plus_hheight = y + height * 0.5f;
} }