Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make GetIndexBounds friendlier to autovectorization. Works on x86 at least. #18219

Merged
merged 1 commit into from
Sep 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions GPU/Common/VertexDecoderCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,28 +108,36 @@ void DecVtxFormat::InitializeFromID(uint32_t id) {
void GetIndexBounds(const void *inds, int count, u32 vertType, u16 *indexLowerBound, u16 *indexUpperBound) {
// Find index bounds. Could cache this in display lists.
// Also, this could be greatly sped up with SSE2/NEON, although rarely a bottleneck.
int lowerBound = 0x7FFFFFFF;
int upperBound = 0;
u32 idx = vertType & GE_VTYPE_IDX_MASK;
if (idx == GE_VTYPE_IDX_8BIT) {
const u8 *ind8 = (const u8 *)inds;
if (idx == GE_VTYPE_IDX_16BIT) {
uint16_t upperBound = 0;
uint16_t lowerBound = 0xFFFF;
const u16_le *ind16 = (const u16_le *)inds;
for (int i = 0; i < count; i++) {
u8 value = ind8[i];
u16 value = ind16[i];
if (value > upperBound)
upperBound = value;
if (value < lowerBound)
lowerBound = value;
}
} else if (idx == GE_VTYPE_IDX_16BIT) {
const u16_le *ind16 = (const u16_le *)inds;
*indexLowerBound = lowerBound;
*indexUpperBound = upperBound;
} else if (idx == GE_VTYPE_IDX_8BIT) {
uint8_t upperBound = 0;
uint8_t lowerBound = 0xFF;
const u8 *ind8 = (const u8 *)inds;
for (int i = 0; i < count; i++) {
u16 value = ind16[i];
u8 value = ind8[i];
if (value > upperBound)
upperBound = value;
if (value < lowerBound)
lowerBound = value;
}
*indexLowerBound = lowerBound;
*indexUpperBound = upperBound;
} else if (idx == GE_VTYPE_IDX_32BIT) {
int lowerBound = 0x7FFFFFFF;
int upperBound = 0;
WARN_LOG_REPORT_ONCE(indexBounds32, G3D, "GetIndexBounds: Decoding 32-bit indexes");
const u32_le *ind32 = (const u32_le *)inds;
for (int i = 0; i < count; i++) {
Expand All @@ -143,12 +151,12 @@ void GetIndexBounds(const void *inds, int count, u32 vertType, u16 *indexLowerBo
if (value < lowerBound)
lowerBound = value;
}
*indexLowerBound = (u16)lowerBound;
*indexUpperBound = (u16)upperBound;
} else {
lowerBound = 0;
upperBound = count - 1;
*indexLowerBound = 0;
*indexUpperBound = count - 1;
}
*indexLowerBound = (u16)lowerBound;
*indexUpperBound = (u16)upperBound;
}

void PrintDecodedVertex(const VertexReader &vtx) {
Expand Down