Avoid decoding indices when we don't need them.

This commit is contained in:
Henrik Rydgård committed 2023-12-20 14:25:19 +01:00
1 parent d9c6d0931b
commit 61acce195c
9 files changed
+150 -206

No files matched your search

+16 -23
View File
@@ -284,19 +284,20 @@ void DrawEngineGLES::DoFlush() {
u8 *dest = (u8 *)frameData.pushVertex->Allocate(vertsToDecode * dec_->GetDecVtxFmt().stride, 4, &vertexBuffer, &vertexBufferOffset);
DecodeVerts(dest);
}
DecodeInds();
// If there's only been one primitive type, and it's either TRIANGLES, LINES or POINTS,
// there is no need for the index buffer we built. We can then use glDrawArrays instead
// for a very minor speed boost. TODO: We can probably detect this case earlier, like before
// actually doing any vertex decoding (unless we're doing soft skinning and pre-decode on submit).
bool useElements = !indexGen.SeenOnlyPurePrims();
int vertexCount = indexGen.VertexCount();
gpuStats.numUncachedVertsDrawn += vertexCount;
if (!useElements && indexGen.PureCount()) {
vertexCount = indexGen.PureCount();
int vertexCount;
int maxIndex;
bool useElements;
DecodeVerts(decoded_);
DecodeIndsAndGetData(&prim, &vertexCount, &maxIndex, &useElements, false);
if (useElements) {
uint32_t esz = sizeof(uint16_t) * vertexCount;
void *dest = frameData.pushIndex->Allocate(esz, 2, &indexBuffer, &indexBufferOffset);
// TODO: When we need to apply an index offset, we can apply it directly when copying the indices here.
// Of course, minding the maximum value of 65535...
memcpy(dest, decIndex_, esz);
}
prim = indexGen.Prim();
bool hasColor = (lastVType_ & GE_VTYPE_COL_MASK) != GE_VTYPE_COL_NONE;
if (gstate.isModeThrough()) {
@@ -316,11 +317,6 @@ void DrawEngineGLES::DoFlush() {
LinkedShader *program = shaderManager_->ApplyFragmentShader(vsid, vshader, pipelineState_, framebufferManager_->UseBufferedRendering());
GLRInputLayout *inputLayout = SetupDecFmtForDraw(dec_->GetDecVtxFmt());
if (useElements) {
uint32_t esz = sizeof(uint16_t) * indexGen.VertexCount();
void *dest = frameData.pushIndex->Allocate(esz, 2, &indexBuffer, &indexBufferOffset);
// TODO: When we need to apply an index offset, we can apply it directly when copying the indices here.
// Of course, minding the maximum value of 65535...
memcpy(dest, decIndex_, esz);
render_->DrawIndexed(inputLayout,
vertexBuffer, vertexBufferOffset,
indexBuffer, indexBufferOffset,
@@ -338,7 +334,7 @@ void DrawEngineGLES::DoFlush() {
dec_ = GetVertexDecoder(lastVType_);
}
DecodeVerts(decoded_);
DecodeInds();
int vertexCount = DecodeInds();
bool hasColor = (lastVType_ & GE_VTYPE_COL_MASK) != GE_VTYPE_COL_NONE;
if (gstate.isModeThrough()) {
@@ -347,11 +343,8 @@ void DrawEngineGLES::DoFlush() {
gstate_c.vertexFullAlpha = gstate_c.vertexFullAlpha && ((hasColor && (gstate.materialupdate & 1)) || gstate.getMaterialAmbientA() == 255) && (!gstate.isLightingEnabled() || gstate.getAmbientA() == 255);
}
gpuStats.numUncachedVertsDrawn += indexGen.VertexCount();
prim = indexGen.Prim();
// Undo the strip optimization, not supported by the SW code yet.
if (prim == GE_PRIM_TRIANGLE_STRIP)
prim = GE_PRIM_TRIANGLES;
gpuStats.numUncachedVertsDrawn += vertexCount;
prim = IndexGenerator::GeneralPrim((GEPrimitiveType)drawInds_[0].prim);
u16 *inds = decIndex_;
SoftwareTransformResult result{};
@@ -377,7 +370,7 @@ void DrawEngineGLES::DoFlush() {
UpdateCachedViewportState(vpAndScissor_);
}
int vertexCount = indexGen.VertexCount();
int maxIndex = numDecodedVerts_;
// TODO: Split up into multiple draw calls for GLES 2.0 where you can't guarantee support for more than 0x10000 verts.
if (gl_extensions.IsGLES && !gl_extensions.GLES3) {