Skip to content

Commit

Permalink
Move the clockwise calculation out of DrawEngineCommon
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Oct 10, 2023
1 parent 82606b6 commit 078018a
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 24 deletions.
18 changes: 5 additions & 13 deletions GPU/Common/DrawEngineCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ void DrawEngineCommon::DispatchSubmitImm(GEPrimitiveType prim, TransformedVertex

int bytesRead;
uint32_t vertTypeID = GetVertTypeID(vtype, 0, decOptions_.applySkinInDecode);
SubmitPrim(&temp[0], nullptr, prim, vertexCount, vertTypeID, cullMode, &bytesRead);

bool clockwise = !gstate.isCullEnabled() || gstate.getCullMode() == cullMode;
SubmitPrim(&temp[0], nullptr, prim, vertexCount, vertTypeID, clockwise, &bytesRead);
DispatchFlush();

if (!prevThrough) {
Expand Down Expand Up @@ -681,7 +683,7 @@ uint64_t DrawEngineCommon::ComputeHash() {
return fullhash;
}

int DrawEngineCommon::ExtendNonIndexedPrim(const uint32_t *cmd, const uint32_t *stall, u32 vertTypeID, int cullMode, int *bytesRead, bool isTriangle) {
int DrawEngineCommon::ExtendNonIndexedPrim(const uint32_t *cmd, const uint32_t *stall, u32 vertTypeID, bool clockwise, int *bytesRead, bool isTriangle) {
const uint32_t *start = cmd;
int prevDrawVerts = numDrawVerts_ - 1;
DeferredVerts &dv = drawVerts_[prevDrawVerts];
Expand All @@ -690,11 +692,6 @@ int DrawEngineCommon::ExtendNonIndexedPrim(const uint32_t *cmd, const uint32_t *
_dbg_assert_(numDrawInds_ <= MAX_DEFERRED_DRAW_INDS); // if it's equal, the check below will take care of it before any action is taken.
_dbg_assert_(numDrawVerts_ > 0);

bool clockwise = true;
if (gstate.isCullEnabled() && gstate.getCullMode() != cullMode) {
clockwise = false;
}

while (cmd != stall) {
uint32_t data = *cmd;
if ((data & 0xFFF80000) != 0x04000000) {
Expand Down Expand Up @@ -727,7 +724,7 @@ int DrawEngineCommon::ExtendNonIndexedPrim(const uint32_t *cmd, const uint32_t *
}

// vertTypeID is the vertex type but with the UVGen mode smashed into the top bits.
bool DrawEngineCommon::SubmitPrim(const void *verts, const void *inds, GEPrimitiveType prim, int vertexCount, u32 vertTypeID, int cullMode, int *bytesRead) {
bool DrawEngineCommon::SubmitPrim(const void *verts, const void *inds, GEPrimitiveType prim, int vertexCount, u32 vertTypeID, bool clockwise, int *bytesRead) {
if (!indexGen.PrimCompatible(prevPrim_, prim) || numDrawVerts_ >= MAX_DEFERRED_DRAW_VERTS || numDrawInds_ >= MAX_DEFERRED_DRAW_INDS || vertexCountInDrawCalls_ + vertexCount > VERTEX_BUFFER_MAX) {
DispatchFlush();
}
Expand Down Expand Up @@ -759,11 +756,6 @@ bool DrawEngineCommon::SubmitPrim(const void *verts, const void *inds, GEPrimiti

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

bool clockwise = true;
if (gstate.isCullEnabled() && gstate.getCullMode() != cullMode) {
clockwise = false;
}

DeferredInds &di = drawInds_[numDrawInds_++];
di.inds = inds;
di.indexType = (vertTypeID & GE_VTYPE_IDX_MASK) >> GE_VTYPE_IDX_SHIFT;
Expand Down
8 changes: 4 additions & 4 deletions GPU/Common/DrawEngineCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ class DrawEngineCommon {
// This would seem to be unnecessary now, but is still required for splines/beziers to work in the software backend since SubmitPrim
// is different. Should probably refactor that.
// Note that vertTypeID should be computed using GetVertTypeID().
virtual void DispatchSubmitPrim(const void *verts, const void *inds, GEPrimitiveType prim, int vertexCount, u32 vertTypeID, int cullMode, int *bytesRead) {
SubmitPrim(verts, inds, prim, vertexCount, vertTypeID, cullMode, bytesRead);
virtual void DispatchSubmitPrim(const void *verts, const void *inds, GEPrimitiveType prim, int vertexCount, u32 vertTypeID, bool clockwise, int *bytesRead) {
SubmitPrim(verts, inds, prim, vertexCount, vertTypeID, clockwise, bytesRead);
}

virtual void DispatchSubmitImm(GEPrimitiveType prim, TransformedVertex *buffer, int vertexCount, int cullMode, bool continuation);
Expand All @@ -111,8 +111,8 @@ class DrawEngineCommon {
}
}

int ExtendNonIndexedPrim(const uint32_t *cmd, const uint32_t *stall, u32 vertTypeID, int cullMode, int *bytesRead, bool isTriangle);
bool SubmitPrim(const void *verts, const void *inds, GEPrimitiveType prim, int vertexCount, u32 vertTypeID, int cullMode, int *bytesRead);
int ExtendNonIndexedPrim(const uint32_t *cmd, const uint32_t *stall, u32 vertTypeID, bool clockwise, int *bytesRead, bool isTriangle);
bool SubmitPrim(const void *verts, const void *inds, GEPrimitiveType prim, int vertexCount, u32 vertTypeID, bool clockwise, int *bytesRead);
template<class Surface>
void SubmitCurve(const void *control_points, const void *indices, Surface &surface, u32 vertType, int *bytesRead, const char *scope);
void ClearSplineBezierWeights();
Expand Down
2 changes: 1 addition & 1 deletion GPU/Common/SplineCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ void DrawEngineCommon::SubmitCurve(const void *control_points, const void *indic
uint32_t vertTypeID = GetVertTypeID(vertTypeWithIndex16, gstate.getUVGenMode(), decOptions_.applySkinInDecode);
int generatedBytesRead;
if (output.count)
DispatchSubmitPrim(output.vertices, output.indices, PatchPrimToPrim(surface.primType), output.count, vertTypeID, gstate.getCullMode(), &generatedBytesRead);
DispatchSubmitPrim(output.vertices, output.indices, PatchPrimToPrim(surface.primType), output.count, vertTypeID, true, &generatedBytesRead);

if (flushOnParams_)
DispatchFlush();
Expand Down
7 changes: 4 additions & 3 deletions GPU/GPUCommonHW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ void GPUCommonHW::Execute_Prim(u32 op, u32 diff) {
int cullMode = gstate.getCullMode();

uint32_t vertTypeID = GetVertTypeID(vertexType, gstate.getUVGenMode(), g_Config.bSoftwareSkinning);
if (!drawEngineCommon_->SubmitPrim(verts, inds, prim, count, vertTypeID, cullMode, &bytesRead)) {
if (!drawEngineCommon_->SubmitPrim(verts, inds, prim, count, vertTypeID, true, &bytesRead)) {
canExtend = false;
}
// After drawing, we advance the vertexAddr (when non indexed) or indexAddr (when indexed).
Expand Down Expand Up @@ -1024,11 +1024,12 @@ void GPUCommonHW::Execute_Prim(u32 op, u32 diff) {
// TODO: more efficient updating of verts/inds

u32 count = data & 0xFFFF;
bool clockwise = !gstate.isCullEnabled() || gstate.getCullMode() == cullMode;
if (canExtend) {
// Non-indexed draws can be cheaply merged if vertexAddr hasn't changed, that means the vertices
// are consecutive in memory.
_dbg_assert_((vertexType & GE_VTYPE_IDX_MASK) == GE_VTYPE_IDX_NONE);
int commandsExecuted = drawEngineCommon_->ExtendNonIndexedPrim(src, stall, vertTypeID, cullMode, &bytesRead, isTriangle);
int commandsExecuted = drawEngineCommon_->ExtendNonIndexedPrim(src, stall, vertTypeID, clockwise, &bytesRead, isTriangle);
if (!commandsExecuted) {
goto bail;
}
Expand All @@ -1046,7 +1047,7 @@ void GPUCommonHW::Execute_Prim(u32 op, u32 diff) {
// We can extend again after submitting a normal draw.
canExtend = isTriangle;
}
if (!drawEngineCommon_->SubmitPrim(verts, inds, newPrim, count, vertTypeID, cullMode, &bytesRead)) {
if (!drawEngineCommon_->SubmitPrim(verts, inds, newPrim, count, vertTypeID, clockwise, &bytesRead)) {
canExtend = false;
}
AdvanceVerts(vertexType, count, bytesRead);
Expand Down
4 changes: 2 additions & 2 deletions GPU/Software/TransformUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ void SoftwareDrawEngine::DispatchFlush() {
transformUnit.Flush("debug");
}

void SoftwareDrawEngine::DispatchSubmitPrim(const void *verts, const void *inds, GEPrimitiveType prim, int vertexCount, u32 vertTypeID, int cullMode, int *bytesRead) {
_assert_msg_(cullMode == gstate.getCullMode(), "Mixed cull mode not supported.");
void SoftwareDrawEngine::DispatchSubmitPrim(const void *verts, const void *inds, GEPrimitiveType prim, int vertexCount, u32 vertTypeID, bool clockwise, int *bytesRead) {
_assert_msg_(clockwise, "Mixed cull mode not supported.");
transformUnit.SubmitPrimitive(verts, inds, prim, vertexCount, vertTypeID, bytesRead, this);
}

Expand Down
2 changes: 1 addition & 1 deletion GPU/Software/TransformUnit.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class SoftwareDrawEngine : public DrawEngineCommon {

void NotifyConfigChanged() override;
void DispatchFlush() override;
void DispatchSubmitPrim(const void *verts, const void *inds, GEPrimitiveType prim, int vertexCount, u32 vertType, int cullMode, int *bytesRead) override;
void DispatchSubmitPrim(const void *verts, const void *inds, GEPrimitiveType prim, int vertexCount, u32 vertType, bool clockwise, int *bytesRead) override;
void DispatchSubmitImm(GEPrimitiveType prim, TransformedVertex *buffer, int vertexCount, int cullMode, bool continuation) override;

VertexDecoder *FindVertexDecoder(u32 vtype);
Expand Down

0 comments on commit 078018a

Please sign in to comment.