From 0a880b09ad7dfcd1cded131fa5c0dde9ab19789a Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 2 Mar 2014 18:12:40 -0800 Subject: [PATCH 1/3] Allow fast bone mtx loads w/o software skinning. --- GPU/GLES/GLES_GPU.cpp | 12 ++++++++++++ GPU/GLES/GLES_GPU.h | 1 + GPU/GPUCommon.cpp | 8 ++++++-- GPU/GPUCommon.h | 1 + 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/GPU/GLES/GLES_GPU.cpp b/GPU/GLES/GLES_GPU.cpp index 9a9906c819..f1e2a6aaa0 100644 --- a/GPU/GLES/GLES_GPU.cpp +++ b/GPU/GLES/GLES_GPU.cpp @@ -1509,6 +1509,18 @@ void GLES_GPU::ExecuteOpInternal(u32 op, u32 diff) { } } +void GLES_GPU::FastLoadBoneMatrix(u32 target) { + if (!g_Config.bSoftwareSkinning) { + Flush(); + const int num = gstate.boneMatrixNumber & 0x7F; + shaderManager_->DirtyUniform(DIRTY_BONEMATRIX0 << (num / 12)); + if ((num % 12) != 0) { + shaderManager_->DirtyUniform((DIRTY_BONEMATRIX0 << (num / 12)) + 1); + } + } + gstate.FastLoadBoneMatrix(target); +} + void GLES_GPU::UpdateStats() { gpuStats.numVertexShaders = shaderManager_->NumVertexShaders(); gpuStats.numFragmentShaders = shaderManager_->NumFragmentShaders(); diff --git a/GPU/GLES/GLES_GPU.h b/GPU/GLES/GLES_GPU.h index 6746e77770..5742741f89 100644 --- a/GPU/GLES/GLES_GPU.h +++ b/GPU/GLES/GLES_GPU.h @@ -78,6 +78,7 @@ public: protected: virtual void FastRunLoop(DisplayList &list); virtual void ProcessEvent(GPUEvent ev); + virtual void FastLoadBoneMatrix(u32 target); private: void Flush() { diff --git a/GPU/GPUCommon.cpp b/GPU/GPUCommon.cpp index 83ad905dc8..9647de36bf 100644 --- a/GPU/GPUCommon.cpp +++ b/GPU/GPUCommon.cpp @@ -736,12 +736,12 @@ void GPUCommon::ExecuteOp(u32 op, u32 diff) { u32 target = gstate_c.getRelativeAddress(data); // Bone matrix optimization - many games will CALL a bone matrix (!). - if (g_Config.bSoftwareSkinning && (Memory::ReadUnchecked_U32(target) >> 24) == GE_CMD_BONEMATRIXDATA) { + if ((Memory::ReadUnchecked_U32(target) >> 24) == GE_CMD_BONEMATRIXDATA) { // Check for the end if ((Memory::ReadUnchecked_U32(target + 11 * 4) >> 24) == GE_CMD_BONEMATRIXDATA && (Memory::ReadUnchecked_U32(target + 12 * 4) >> 24) == GE_CMD_RET) { // Yep, pretty sure this is a bone matrix call. - gstate.FastLoadBoneMatrix(target); + FastLoadBoneMatrix(target); break; } } @@ -933,6 +933,10 @@ void GPUCommon::ExecuteOp(u32 op, u32 diff) { } } +void GPUCommon::FastLoadBoneMatrix(u32 target) { + gstate.FastLoadBoneMatrix(target); +} + struct DisplayListOld { int id; u32 startpc; diff --git a/GPU/GPUCommon.h b/GPU/GPUCommon.h index 769df0c94e..7ddbd39b53 100644 --- a/GPU/GPUCommon.h +++ b/GPU/GPUCommon.h @@ -88,6 +88,7 @@ protected: int GetNextListIndex(); void ProcessDLQueueInternal(); void ReapplyGfxStateInternal(); + virtual void FastLoadBoneMatrix(u32 target); virtual void ProcessEvent(GPUEvent ev); virtual bool ShouldExitEventLoop() { return coreState != CORE_RUNNING; From ecf9479d5a17b9ebae903ef56e19c53c086c75e8 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 2 Mar 2014 18:19:55 -0800 Subject: [PATCH 2/3] Always flush bone matrices when morph is enabled. Fixes graphical glitches in Shadow of Destiny and LittleBigPlanet with software skinning enabled. Maybe the other games in #5304. --- GPU/GLES/GLES_GPU.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/GPU/GLES/GLES_GPU.cpp b/GPU/GLES/GLES_GPU.cpp index f1e2a6aaa0..e78da59a17 100644 --- a/GPU/GLES/GLES_GPU.cpp +++ b/GPU/GLES/GLES_GPU.cpp @@ -1406,8 +1406,7 @@ void GLES_GPU::ExecuteOpInternal(u32 op, u32 diff) { u32 newVal = data << 8; if (num < 96 && newVal != ((const u32 *)gstate.boneMatrix)[num]) { // Bone matrices should NOT flush when software skinning is enabled! - // TODO: Also check for morph... - if (!g_Config.bSoftwareSkinning) { + if (!g_Config.bSoftwareSkinning || (gstate.vertType & GE_VTYPE_MORPHCOUNT_MASK) != 0) { Flush(); shaderManager_->DirtyUniform(DIRTY_BONEMATRIX0 << (num / 12)); } @@ -1510,7 +1509,7 @@ void GLES_GPU::ExecuteOpInternal(u32 op, u32 diff) { } void GLES_GPU::FastLoadBoneMatrix(u32 target) { - if (!g_Config.bSoftwareSkinning) { + if (!g_Config.bSoftwareSkinning || (gstate.vertType & GE_VTYPE_MORPHCOUNT_MASK) != 0) { Flush(); const int num = gstate.boneMatrixNumber & 0x7F; shaderManager_->DirtyUniform(DIRTY_BONEMATRIX0 << (num / 12)); From e08e9d8e89d1feb4172aa4244032a192e890faba Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 2 Mar 2014 20:09:18 -0800 Subject: [PATCH 3/3] Flush if morphing, even if only weight changed. Fixes more graphical glitches that happen when software skinning is enabled. --- GPU/GLES/GLES_GPU.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/GPU/GLES/GLES_GPU.cpp b/GPU/GLES/GLES_GPU.cpp index e78da59a17..e155c7ce4b 100644 --- a/GPU/GLES/GLES_GPU.cpp +++ b/GPU/GLES/GLES_GPU.cpp @@ -882,7 +882,8 @@ void GLES_GPU::ExecuteOpInternal(u32 op, u32 diff) { if (diff & (GE_VTYPE_TC_MASK | GE_VTYPE_THROUGH_MASK)) shaderManager_->DirtyUniform(DIRTY_UVSCALEOFFSET); } else { - if (diff & ~GE_VTYPE_WEIGHTCOUNT_MASK) { + // Don't flush when weight count changes, unless morph is enabled. + if ((diff & ~GE_VTYPE_WEIGHTCOUNT_MASK) || (data & GE_VTYPE_MORPHCOUNT_MASK) != 0) { // Restore and flush gstate.vertType ^= diff; Flush();