Skip to content

Commit

Permalink
Fix issue with zero-vertex draw calls. Though, should maybe just filt…
Browse files Browse the repository at this point in the history
…er them out earlier.
  • Loading branch information
hrydgard committed Dec 10, 2023
1 parent aca3bbc commit 71aaad2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
17 changes: 8 additions & 9 deletions GPU/Common/DrawEngineCommon.cpp
Expand Up @@ -899,8 +899,11 @@ bool DrawEngineCommon::SubmitPrim(const void *verts, const void *inds, GEPrimiti
*bytesRead = vertexCount * dec_->VertexSize();

// Check that we have enough vertices to form the requested primitive.
if (vertexCount < 3 && ((vertexCount < 2 && prim > 0) || (prim > GE_PRIM_LINE_STRIP && prim != GE_PRIM_RECTANGLES)))
return false;
if (vertexCount < 3) {
if ((vertexCount < 2 && prim > 0) || (prim > GE_PRIM_LINE_STRIP && prim != GE_PRIM_RECTANGLES)) {
return false;
}
}

bool applySkin = (vertTypeID & GE_VTYPE_WEIGHT_MASK) && decOptions_.applySkinInDecode;

Expand All @@ -919,10 +922,10 @@ bool DrawEngineCommon::SubmitPrim(const void *verts, const void *inds, GEPrimiti
if (inds && numDrawVerts_ > decodeVertsCounter_ && drawVerts_[numDrawVerts_ - 1].verts == verts && !applySkin) {
// Same vertex pointer as a previous un-decoded draw call - let's just extend the decode!
di.vertDecodeIndex = numDrawVerts_ - 1;
DeferredVerts &dv = drawVerts_[numDrawVerts_ - 1];
u16 lb;
u16 ub;
GetIndexBounds(inds, vertexCount, vertTypeID, &lb, &ub);
DeferredVerts &dv = drawVerts_[numDrawVerts_ - 1];
if (lb < dv.indexLowerBound)
dv.indexLowerBound = lb;
if (ub > dv.indexUpperBound)
Expand All @@ -933,12 +936,8 @@ bool DrawEngineCommon::SubmitPrim(const void *verts, const void *inds, GEPrimiti
dv.verts = verts;
dv.vertexCount = vertexCount;
dv.uvScale = gstate_c.uv;
if (inds) {
GetIndexBounds(inds, vertexCount, vertTypeID, &dv.indexLowerBound, &dv.indexUpperBound);
} else {
dv.indexLowerBound = 0;
dv.indexUpperBound = vertexCount - 1;
}
// Does handle the unindexed case.
GetIndexBounds(inds, vertexCount, vertTypeID, &dv.indexLowerBound, &dv.indexUpperBound);
}

vertexCountInDrawCalls_ += vertexCount;
Expand Down
6 changes: 5 additions & 1 deletion GPU/Common/VertexDecoderCommon.cpp
Expand Up @@ -154,7 +154,11 @@ void GetIndexBounds(const void *inds, int count, u32 vertType, u16 *indexLowerBo
*indexUpperBound = (u16)upperBound;
} else {
*indexLowerBound = 0;
*indexUpperBound = count - 1;
if (count > 0) {
*indexUpperBound = count - 1;
} else {
*indexUpperBound = 0;
}
}
}

Expand Down
8 changes: 8 additions & 0 deletions GPU/Vulkan/DrawEngineVulkan.cpp
Expand Up @@ -376,15 +376,23 @@ void DrawEngineVulkan::DoFlush() {
lastVType_ |= (1 << 26);
dec_ = GetVertexDecoder(lastVType_);
}
int prevDecodedVerts = numDecodedVerts_;

DecodeVerts(decoded_);
DecodeInds();

bool hasColor = (lastVType_ & GE_VTYPE_COL_MASK) != GE_VTYPE_COL_NONE;
if (gstate.isModeThrough()) {
gstate_c.vertexFullAlpha = gstate_c.vertexFullAlpha && (hasColor || gstate.getMaterialAmbientA() == 255);
} else {
gstate_c.vertexFullAlpha = gstate_c.vertexFullAlpha && ((hasColor && (gstate.materialupdate & 1)) || gstate.getMaterialAmbientA() == 255) && (!gstate.isLightingEnabled() || gstate.getAmbientA() == 255);
}

int vcount = indexGen.VertexCount();
if (numDecodedVerts_ > 10 * vcount) {
decIndex_ = decIndex_;
}

gpuStats.numUncachedVertsDrawn += indexGen.VertexCount();
prim = indexGen.Prim();
// Undo the strip optimization, not supported by the SW code yet.
Expand Down

0 comments on commit 71aaad2

Please sign in to comment.