Skip to content

Commit

Permalink
Cleanups, make the various SubmitPrim implementations more similar
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Oct 12, 2023
1 parent 6dbe497 commit 12a98ba
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 33 deletions.
3 changes: 2 additions & 1 deletion GPU/D3D11/DrawEngineD3D11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,10 @@ void DrawEngineD3D11::DoFlush() {

DecodeVerts(decoded_);
DecodeInds();
gpuStats.numUncachedVertsDrawn += indexGen.VertexCount();

bool useElements = !indexGen.SeenOnlyPurePrims() || prim == GE_PRIM_TRIANGLE_FAN;
int vertexCount = indexGen.VertexCount();
gpuStats.numUncachedVertsDrawn += vertexCount;
int maxIndex = MaxIndex();
if (!useElements && indexGen.PureCount()) {
vertexCount = indexGen.PureCount();
Expand Down
30 changes: 13 additions & 17 deletions GPU/Directx9/DrawEngineDX9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,24 +255,20 @@ void DrawEngineDX9::DoFlush() {
bool useHWTransform = CanUseHardwareTransform(prim) && (tess || gstate.getShadeMode() != GE_SHADE_FLAT);

if (useHWTransform) {
LPDIRECT3DVERTEXBUFFER9 vb_ = NULL;
LPDIRECT3DINDEXBUFFER9 ib_ = NULL;

int vertexCount = 0;
int maxIndex = 0;
bool useElements = true;
{
DecodeVerts(decoded_);
DecodeInds();
gpuStats.numUncachedVertsDrawn += indexGen.VertexCount();
useElements = !indexGen.SeenOnlyPurePrims();
vertexCount = indexGen.VertexCount();
maxIndex = MaxIndex();
if (!useElements && indexGen.PureCount()) {
vertexCount = indexGen.PureCount();
}
prim = indexGen.Prim();
LPDIRECT3DVERTEXBUFFER9 vb_ = nullptr;
LPDIRECT3DINDEXBUFFER9 ib_ = nullptr;

DecodeVerts(decoded_);
DecodeInds();

bool useElements = !indexGen.SeenOnlyPurePrims();
int vertexCount = indexGen.VertexCount();
gpuStats.numUncachedVertsDrawn += vertexCount;
int maxIndex = MaxIndex();
if (!useElements && indexGen.PureCount()) {
vertexCount = indexGen.PureCount();
}
prim = indexGen.Prim();

_dbg_assert_((int)prim > 0);

Expand Down
22 changes: 8 additions & 14 deletions GPU/GLES/DrawEngineGLES.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,6 @@ void DrawEngineGLES::DoFlush() {
uint32_t indexBufferOffset = 0;

if (vshader->UseHWTransform()) {
int vertexCount = 0;
bool useElements = true;

if (decOptions_.applySkinInDecode && (lastVType_ & GE_VTYPE_WEIGHT_MASK)) {
// If software skinning, we're predecoding into "decoded". So make sure we're done, then push that content.
DecodeVerts(decoded_);
Expand All @@ -288,24 +285,16 @@ void DrawEngineGLES::DoFlush() {
}
DecodeInds();

gpuStats.numUncachedVertsDrawn += indexGen.VertexCount();

// 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).
useElements = !indexGen.SeenOnlyPurePrims();
vertexCount = indexGen.VertexCount();
bool useElements = !indexGen.SeenOnlyPurePrims();
int vertexCount = indexGen.VertexCount();
gpuStats.numUncachedVertsDrawn += vertexCount;
if (!useElements && indexGen.PureCount()) {
vertexCount = indexGen.PureCount();
}
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);
}
prim = indexGen.Prim();

bool hasColor = (lastVType_ & GE_VTYPE_COL_MASK) != GE_VTYPE_COL_NONE;
Expand All @@ -326,6 +315,11 @@ 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,
Expand Down
2 changes: 1 addition & 1 deletion GPU/Vulkan/DrawEngineVulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,10 @@ void DrawEngineVulkan::DoFlush() {
DecodeVertsToPushPool(pushVertex_, &vbOffset, &vbuf);
}
DecodeInds();
gpuStats.numUncachedVertsDrawn += indexGen.VertexCount();

bool useElements;
int vertexCount = indexGen.VertexCount();
gpuStats.numUncachedVertsDrawn += vertexCount;
if (forceIndexed) {
useElements = true;
prim = indexGen.GeneralPrim();
Expand Down

0 comments on commit 12a98ba

Please sign in to comment.