From f27426714306e07f33b9ff588e2e63062fdae222 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Mon, 5 Sep 2022 23:13:16 -0700 Subject: [PATCH] GPU: Allow usage of texturing in immediate verts. And respect the other flags that I can reproduce working in a test. I can't seem to get the fog to work at all, or the shading mode, or the secondary color. Maybe depends on other flags or bits in other regs... --- GPU/GPUCommon.cpp | 34 +++++++++++++++++++++++++++++++++- GPU/GPUCommon.h | 1 + GPU/Software/TransformUnit.cpp | 4 +++- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/GPU/GPUCommon.cpp b/GPU/GPUCommon.cpp index a4e765ea03..a47e9edea8 100644 --- a/GPU/GPUCommon.cpp +++ b/GPU/GPUCommon.cpp @@ -2410,6 +2410,8 @@ void GPUCommon::Execute_ImmVertexAlphaPrim(u32 op, u32 diff) { v.color1_32 = gstate.imm_scv & 0xFFFFFF; if (prim != GE_PRIM_KEEP_PREVIOUS) { immPrim_ = (GEPrimitiveType)prim; + // Flags seem to only be respected from the first prim. + immFlags_ = op & 0x00FFF800; } else if (prim == GE_PRIM_KEEP_PREVIOUS && immPrim_ != GE_PRIM_INVALID) { static constexpr int flushPrimCount[] = { 1, 2, 0, 3, 0, 0, 2, 0 }; // Instead of finding a proper point to flush, we just emit a full rectangle every time one @@ -2456,12 +2458,42 @@ void GPUCommon::FlushImm() { } int vtype = GE_VTYPE_TC_FLOAT | GE_VTYPE_POS_FLOAT | GE_VTYPE_COL_8888 | GE_VTYPE_THROUGH; + static constexpr int GE_IMM_CULLENABLE = 0x00080000; + static constexpr int GE_IMM_CULLFACE = 0x00100000; + static constexpr int GE_IMM_TEXTURE = 0x00200000; + static constexpr int GE_IMM_DITHER = 0x00800000; + + bool texturing = (immFlags_ & GE_IMM_TEXTURE) != 0; + bool prevTexturing = gstate.isTextureMapEnabled(); + bool cullEnable = (immFlags_ & GE_IMM_CULLENABLE) != 0; + bool prevCullEnable = gstate.isCullEnabled(); + int cullMode = (immFlags_ & GE_IMM_CULLFACE) != 0 ? 1 : 0; + bool prevDither = gstate.isDitherEnabled(); + bool dither = (immFlags_ & GE_IMM_DITHER) != 0; + // Some notes say there's a flag to control this, but it seems to be flat regardless. + GEShadeMode prevShadeMode = gstate.getShadeMode(); + + if (texturing != prevTexturing || cullEnable != prevCullEnable || dither != prevDither || prevShadeMode != GE_SHADE_FLAT) { + DispatchFlush(); + gstate.textureMapEnable = (GE_CMD_TEXTUREMAPENABLE << 24) | (int)texturing; + gstate.cullfaceEnable = (GE_CMD_CULLFACEENABLE << 24) | (int)cullEnable; + gstate.shademodel = (GE_CMD_SHADEMODE << 24) | GE_SHADE_FLAT; + gstate.ditherEnable = (GE_CMD_DITHERENABLE << 24) | (int)dither; + gstate_c.Dirty(DIRTY_VERTEXSHADER_STATE | DIRTY_FRAGMENTSHADER_STATE | DIRTY_RASTER_STATE); + } + int bytesRead; uint32_t vertTypeID = GetVertTypeID(vtype, 0); - drawEngineCommon_->DispatchSubmitImm(temp, nullptr, immPrim_, immCount_, vertTypeID, gstate.getCullMode(), &bytesRead); + drawEngineCommon_->DispatchSubmitImm(temp, nullptr, immPrim_, immCount_, vertTypeID, cullMode, &bytesRead); // TOOD: In the future, make a special path for these. // drawEngineCommon_->DispatchSubmitImm(immBuffer_, immCount_); immCount_ = 0; + + gstate.textureMapEnable = (GE_CMD_TEXTUREMAPENABLE << 24) | (int)prevTexturing; + gstate.cullfaceEnable = (GE_CMD_CULLFACEENABLE << 24) | (int)prevCullEnable; + gstate.shademodel = (GE_CMD_SHADEMODE << 24) | prevShadeMode; + gstate.ditherEnable = (GE_CMD_DITHERENABLE << 24) | (int)prevDither; + gstate_c.Dirty(DIRTY_VERTEXSHADER_STATE | DIRTY_FRAGMENTSHADER_STATE | DIRTY_RASTER_STATE); } void GPUCommon::ExecuteOp(u32 op, u32 diff) { diff --git a/GPU/GPUCommon.h b/GPU/GPUCommon.h index f2c64d95b8..3a5674127f 100644 --- a/GPU/GPUCommon.h +++ b/GPU/GPUCommon.h @@ -354,6 +354,7 @@ protected: TransformedVertex immBuffer_[MAX_IMMBUFFER_SIZE]; int immCount_ = 0; GEPrimitiveType immPrim_ = GE_PRIM_INVALID; + uint32_t immFlags_ = 0; std::string reportingPrimaryInfo_; std::string reportingFullInfo_; diff --git a/GPU/Software/TransformUnit.cpp b/GPU/Software/TransformUnit.cpp index db50f48bb6..cbfb754b77 100644 --- a/GPU/Software/TransformUnit.cpp +++ b/GPU/Software/TransformUnit.cpp @@ -71,10 +71,12 @@ void SoftwareDrawEngine::DispatchSubmitPrim(const void *verts, const void *inds, } void SoftwareDrawEngine::DispatchSubmitImm(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."); + int flipCull = cullMode != gstate.getCullMode() ? 1 : 0; // TODO: For now, just setting all dirty. transformUnit.SetDirty(SoftDirty(-1)); + gstate.cullmode ^= flipCull; transformUnit.SubmitPrimitive(verts, inds, prim, vertexCount, vertTypeID, bytesRead, this); + gstate.cullmode ^= flipCull; // TODO: Should really clear, but the vertex type is faked so things might need resetting... transformUnit.SetDirty(SoftDirty(-1)); }