Skip to content

Commit

Permalink
It's running.
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Oct 3, 2023
1 parent 6a2e5dd commit 9b411af
Show file tree
Hide file tree
Showing 11 changed files with 209 additions and 231 deletions.
327 changes: 136 additions & 191 deletions GPU/Common/DrawEngineCommon.cpp

Large diffs are not rendered by default.

34 changes: 24 additions & 10 deletions GPU/Common/DrawEngineCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class DrawEngineCommon {
return false;
}
int GetNumDrawCalls() const {
return numDrawCalls_;
return numDrawVerts_;
}

VertexDecoder *GetVertexDecoder(u32 vtype);
Expand All @@ -141,8 +141,8 @@ class DrawEngineCommon {
virtual bool UpdateUseHWTessellation(bool enabled) const { return enabled; }
void UpdatePlanes();

int ComputeNumVertsToDecode() const;
void DecodeVerts(u8 *dest);
void DecodeInds();

// Preprocessing for spline/bezier
u32 NormalizeVertices(u8 *outPtr, u8 *bufPtr, const u8 *inPtr, int lowerBound, int upperBound, u32 vertType, int *vertexSize = nullptr);
Expand All @@ -152,7 +152,10 @@ class DrawEngineCommon {
uint64_t ComputeHash();

// Vertex decoding
void DecodeVertsStep(u8 *dest, int &i, int &decodedVerts, const UVScale *uvScale);
void DecodeVertsStep(u8 *dest, int i, int &decodedVerts, const UVScale *uvScale);
void DecodeIndsStep(int i);

int ComputeNumVertsToDecode() const;

void ApplyFramebufferRead(FBOTexState *fboTexState);

Expand Down Expand Up @@ -210,25 +213,36 @@ class DrawEngineCommon {
TransformedVertex *transformedExpanded_ = nullptr;

// Defer all vertex decoding to a "Flush" (except when software skinning)
struct DeferredDrawCall {
struct DeferredVerts {
const void *verts;
u32 vertexCount;
u16 indexLowerBound;
u16 indexUpperBound;
UVScale uvScale;
};

struct DeferredInds {
const void *inds;
u32 vertexCount;
u8 indexType;
s8 prim;
u8 cullMode;
u16 indexLowerBound;
u16 indexUpperBound;
UVScale uvScale;
u16 indexOffset;
};

enum { MAX_DEFERRED_DRAW_CALLS = 128 };
DeferredDrawCall drawCalls_[MAX_DEFERRED_DRAW_CALLS];
int numDrawCalls_ = 0;
DeferredVerts drawVerts_[MAX_DEFERRED_DRAW_CALLS];
DeferredInds drawInds_[MAX_DEFERRED_DRAW_CALLS];

int numDrawVerts_ = 0;
int numDrawInds_ = 0;
int vertexCountInDrawCalls_ = 0;

int decimationCounter_ = 0;
int decodeCounter_ = 0;
int decodeVertsCounter_ = 0;
int decodeIndsCounter_ = 0;

int indexOffset_ = 0;

// Vertex collector state
IndexGenerator indexGen;
Expand Down
10 changes: 6 additions & 4 deletions GPU/D3D11/DrawEngineD3D11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ void DrawEngineD3D11::DoFlush() {

if (useCache) {
// getUVGenMode can have an effect on which UV decoder we need to use! And hence what the decoded data will look like. See #9263
u32 dcid = (u32)XXH3_64bits(&drawCalls_, sizeof(DeferredDrawCall) * numDrawCalls_) ^ gstate.getUVGenMode();
u32 dcid = ComputeDrawcallsHash() ^ gstate.getUVGenMode();

VertexArrayInfoD3D11 *vai;
if (!vai_.Get(dcid, &vai)) {
Expand Down Expand Up @@ -719,14 +719,16 @@ void DrawEngineD3D11::DoFlush() {
}

gpuStats.numFlushes++;
gpuStats.numDrawCalls += numDrawCalls_;
gpuStats.numDrawCalls += numDrawInds_;
gpuStats.numVertsSubmitted += vertexCountInDrawCalls_;

indexGen.Reset();
decodedVerts_ = 0;
numDrawCalls_ = 0;
numDrawVerts_ = 0;
numDrawInds_ = 0;
vertexCountInDrawCalls_ = 0;
decodeCounter_ = 0;
decodeVertsCounter_ = 0;
decodeIndsCounter_ = 0;
gstate_c.vertexFullAlpha = true;
framebufferManager_->SetColorUpdated(gstate_c.skipDrawReason);

Expand Down
6 changes: 3 additions & 3 deletions GPU/D3D11/DrawEngineD3D11.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,19 +138,19 @@ class DrawEngineD3D11 : public DrawEngineCommon {

// So that this can be inlined
void Flush() {
if (!numDrawCalls_)
if (!numDrawVerts_)
return;
DoFlush();
}

void FinishDeferred() {
if (!numDrawCalls_)
if (!numDrawVerts_)
return;
DecodeVerts(decoded_);
}

void DispatchFlush() override {
if (!numDrawCalls_)
if (!numDrawVerts_)
return;
Flush();
}
Expand Down
12 changes: 8 additions & 4 deletions GPU/Directx9/DrawEngineDX9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ void DrawEngineDX9::DoFlush() {

if (useCache) {
// getUVGenMode can have an effect on which UV decoder we need to use! And hence what the decoded data will look like. See #9263
u32 dcid = (u32)XXH3_64bits(&drawCalls_, sizeof(DeferredDrawCall) * numDrawCalls_) ^ gstate.getUVGenMode();
u32 dcid = ComputeDrawcallsHash() ^ gstate.getUVGenMode();
VertexArrayInfoDX9 *vai;
if (!vai_.Get(dcid, &vai)) {
vai = new VertexArrayInfoDX9();
Expand Down Expand Up @@ -658,14 +658,18 @@ void DrawEngineDX9::DoFlush() {
}

gpuStats.numFlushes++;
gpuStats.numDrawCalls += numDrawCalls_;
gpuStats.numDrawCalls += numDrawInds_;
gpuStats.numVertsSubmitted += vertexCountInDrawCalls_;

// TODO: The below should be shared.

indexGen.Reset();
decodedVerts_ = 0;
numDrawCalls_ = 0;
numDrawVerts_ = 0;
numDrawInds_ = 0;
vertexCountInDrawCalls_ = 0;
decodeCounter_ = 0;
decodeVertsCounter_ = 0;
decodeIndsCounter_ = 0;
gstate_c.vertexFullAlpha = true;
framebufferManager_->SetColorUpdated(gstate_c.skipDrawReason);

Expand Down
6 changes: 3 additions & 3 deletions GPU/Directx9/DrawEngineDX9.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,19 @@ class DrawEngineDX9 : public DrawEngineCommon {

// So that this can be inlined
void Flush() {
if (!numDrawCalls_)
if (!numDrawVerts_)
return;
DoFlush();
}

void FinishDeferred() {
if (!numDrawCalls_)
if (!numDrawVerts_)
return;
DecodeVerts(decoded_);
}

void DispatchFlush() override {
if (!numDrawCalls_)
if (!numDrawVerts_)
return;
Flush();
}
Expand Down
14 changes: 9 additions & 5 deletions GPU/GLES/DrawEngineGLES.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,11 @@ void DrawEngineGLES::DoFlush() {
// can't goto bail here, skips too many variable initializations. So let's wipe the most important stuff.
indexGen.Reset();
decodedVerts_ = 0;
numDrawCalls_ = 0;
numDrawVerts_ = 0;
numDrawInds_ = 0;
vertexCountInDrawCalls_ = 0;
decodeCounter_ = 0;
decodeVertsCounter_ = 0;
decodeIndsCounter_ = 0;
return;
}

Expand Down Expand Up @@ -471,17 +473,19 @@ void DrawEngineGLES::DoFlush() {

bail:
gpuStats.numFlushes++;
gpuStats.numDrawCalls += numDrawCalls_;
gpuStats.numDrawCalls += numDrawInds_;
gpuStats.numVertsSubmitted += vertexCountInDrawCalls_;

// TODO: When the next flush has the same vertex format, we can continue with the same offset in the vertex buffer,
// and start indexing from a higher value. This is very friendly to OpenGL (where we can't rely on baseindex if we
// wanted to avoid rebinding the vertex input every time).
indexGen.Reset();
decodedVerts_ = 0;
numDrawCalls_ = 0;
numDrawVerts_ = 0;
numDrawInds_ = 0;
vertexCountInDrawCalls_ = 0;
decodeCounter_ = 0;
decodeVertsCounter_ = 0;
decodeIndsCounter_ = 0;
gstate_c.vertexFullAlpha = true;
framebufferManager_->SetColorUpdated(gstate_c.skipDrawReason);

Expand Down
6 changes: 3 additions & 3 deletions GPU/GLES/DrawEngineGLES.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,19 @@ class DrawEngineGLES : public DrawEngineCommon {

// So that this can be inlined
void Flush() {
if (!numDrawCalls_)
if (!numDrawVerts_)
return;
DoFlush();
}

void FinishDeferred() {
if (!numDrawCalls_)
if (!numDrawVerts_)
return;
DoFlush();
}

void DispatchFlush() override {
if (!numDrawCalls_)
if (!numDrawVerts_)
return;
Flush();
}
Expand Down
17 changes: 12 additions & 5 deletions GPU/Vulkan/DrawEngineVulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,7 @@ void DrawEngineVulkan::DoFlush() {
// Decode directly into the pushbuffer
DecodeVertsToPushPool(pushVertex_, &vbOffset, &vbuf);
}
DecodeInds();
gpuStats.numUncachedVertsDrawn += indexGen.VertexCount();
}

Expand Down Expand Up @@ -845,6 +846,7 @@ void DrawEngineVulkan::DoFlush() {
dec_ = GetVertexDecoder(lastVType_);
}
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);
Expand All @@ -857,6 +859,7 @@ void DrawEngineVulkan::DoFlush() {
// Undo the strip optimization, not supported by the SW code yet.
if (prim == GE_PRIM_TRIANGLE_STRIP)
prim = GE_PRIM_TRIANGLES;
_dbg_assert_(prim != GE_PRIM_INVALID);

u16 *inds = decIndex_;
SoftwareTransformResult result{};
Expand Down Expand Up @@ -1007,14 +1010,16 @@ void DrawEngineVulkan::DoFlush() {
}

gpuStats.numFlushes++;
gpuStats.numDrawCalls += numDrawCalls_;
gpuStats.numDrawCalls += numDrawInds_;
gpuStats.numVertsSubmitted += vertexCountInDrawCalls_;

indexGen.Reset();
decodedVerts_ = 0;
numDrawCalls_ = 0;
numDrawVerts_ = 0;
numDrawInds_ = 0;
vertexCountInDrawCalls_ = 0;
decodeCounter_ = 0;
decodeIndsCounter_ = 0;
decodeVertsCounter_ = 0;
gstate_c.vertexFullAlpha = true;
framebufferManager_->SetColorUpdated(gstate_c.skipDrawReason);

Expand All @@ -1030,8 +1035,10 @@ void DrawEngineVulkan::DoFlush() {
void DrawEngineVulkan::ResetAfterDraw() {
indexGen.Reset();
decodedVerts_ = 0;
numDrawCalls_ = 0;
decodeCounter_ = 0;
numDrawVerts_ = 0;
numDrawInds_ = 0;
decodeIndsCounter_ = 0;
decodeVertsCounter_ = 0;
decOptions_.applySkinInDecode = g_Config.bSoftwareSkinning;
gstate_c.vertexFullAlpha = true;
}
Expand Down
6 changes: 3 additions & 3 deletions GPU/Vulkan/DrawEngineVulkan.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,13 @@ class DrawEngineVulkan : public DrawEngineCommon {

// So that this can be inlined
void Flush() {
if (!numDrawCalls_)
if (!numDrawVerts_)
return;
DoFlush();
}

void FinishDeferred() {
if (!numDrawCalls_)
if (!numDrawVerts_)
return;
// Decode any pending vertices. And also flush while we're at it, for simplicity.
// It might be possible to only decode like in the other backends, but meh, it can't matter.
Expand All @@ -185,7 +185,7 @@ class DrawEngineVulkan : public DrawEngineCommon {
}

void DispatchFlush() override {
if (!numDrawCalls_)
if (!numDrawVerts_)
return;
Flush();
}
Expand Down
2 changes: 2 additions & 0 deletions GPU/Vulkan/PipelineManagerVulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ static VulkanPipeline *CreateVulkanPipeline(VulkanRenderManager *renderManager,
desc->geometryShaderSource = gs->GetShaderString(SHADER_STRING_SOURCE_CODE);
}

_dbg_assert_(key.topology != VK_PRIMITIVE_TOPOLOGY_POINT_LIST);
_dbg_assert_(key.topology != VK_PRIMITIVE_TOPOLOGY_LINE_LIST);
desc->topology = (VkPrimitiveTopology)key.topology;

int vertexStride = 0;
Expand Down

0 comments on commit 9b411af

Please sign in to comment.