Skip to content

Commit

Permalink
HW shaders: Fix attribute fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
wheremyfoodat committed Sep 2, 2024
1 parent e332ab2 commit 15b6a9e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/core/PICA/draw_acceleration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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];
Expand Down Expand Up @@ -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<u8>(attrAddress);
attr.inputReg = inputReg;
attr.componentCount = size;
attr.offset = attributeOffset;
Expand All @@ -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<u8>(attrAddress);
attrCount += 1;
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/renderer_gl/renderer_gl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ void RendererGL::drawVertices(PICA::PrimType primType, std::span<const Vertex> 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
Expand Down

0 comments on commit 15b6a9e

Please sign in to comment.