From 15b6a9e2d947e46a192041dbe860e2e502eac619 Mon Sep 17 00:00:00 2001 From: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> Date: Tue, 3 Sep 2024 02:21:20 +0300 Subject: [PATCH] HW shaders: Fix attribute fetch --- src/core/PICA/draw_acceleration.cpp | 9 +++++---- src/core/renderer_gl/renderer_gl.cpp | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/core/PICA/draw_acceleration.cpp b/src/core/PICA/draw_acceleration.cpp index 538a714e..84096fb7 100644 --- a/src/core/PICA/draw_acceleration.cpp +++ b/src/core/PICA/draw_acceleration.cpp @@ -64,7 +64,6 @@ void GPU::getAcceleratedDrawInfo(PICA::DrawAcceleration& accel, bool indexed) { if (!fixedAttrib) { auto& attrData = attributeInfo[buffer]; // Get information for this attribute u64 attrCfg = attrData.getConfigFull(); // Get config1 | (config2 << 32) - u32 attributeOffset = attrData.offset; if (attrData.componentCount != 0) { // Size of the attribute in bytes multiplied by the total number of vertices @@ -73,6 +72,7 @@ void GPU::getAcceleratedDrawInfo(PICA::DrawAcceleration& accel, bool indexed) { accel.vertexDataSize += (bytes + 3) & ~3; } + u32 attributeOffset = 0; for (int i = 0; i < attrData.componentCount; i++) { uint index = (attrCfg >> (i * 4)) & 0xf; // Get index of attribute in vertexCfg auto& attr = accel.attributeInfo[attrCount]; @@ -101,6 +101,10 @@ void GPU::getAcceleratedDrawInfo(PICA::DrawAcceleration& accel, bool indexed) { // Mark the attribute as enabled accel.enabledAttributeMask |= 1 << inputReg; + // Get a pointer to the data where this attribute is stored + const u32 attrAddress = vertexBase + attributeOffset + attrData.offset + (accel.minimumIndex * attrData.size); + + attr.data = getPointerPhys(attrAddress); attr.inputReg = inputReg; attr.componentCount = size; attr.offset = attributeOffset; @@ -110,9 +114,6 @@ void GPU::getAcceleratedDrawInfo(PICA::DrawAcceleration& accel, bool indexed) { attr.isPadding = false; attributeOffset += attr.size; - // Get a pointer to the data where this attribute is stored - const u32 attrAddress = vertexBase + attr.offset + (accel.minimumIndex * attrData.size); - attr.data = getPointerPhys(attrAddress); attrCount += 1; } diff --git a/src/core/renderer_gl/renderer_gl.cpp b/src/core/renderer_gl/renderer_gl.cpp index 3d011955..6447f763 100644 --- a/src/core/renderer_gl/renderer_gl.cpp +++ b/src/core/renderer_gl/renderer_gl.cpp @@ -512,7 +512,7 @@ void RendererGL::drawVertices(PICA::PrimType primType, std::span v hwIndexBuffer->Bind(); glDrawRangeElementsBaseVertex( primitiveTopology, minimumIndex, maximumIndex, GLsizei(vertices.size()), usingShortIndices ? GL_UNSIGNED_SHORT : GL_UNSIGNED_BYTE, - hwIndexBufferOffset, -minimumIndex + hwIndexBufferOffset, -GLint(minimumIndex) ); } else { // When doing non-indexed rendering, just use glDrawArrays