From c2d0128226aa5509ae046325f22e61bc3468d30a Mon Sep 17 00:00:00 2001 From: Skyth <19259897+blueskythlikesclouds@users.noreply.github.com> Date: Thu, 24 Oct 2024 17:43:05 +0300 Subject: [PATCH] Remove half pixel globally instead of negating them with patches. --- UnleashedRecomp/gpu/shader/movie_vs.hlsl | 1 - .../gpu/shader/resolve_msaa_depth.hlsli | 2 +- UnleashedRecomp/gpu/video.cpp | 52 +++++++++++-------- UnleashedRecompLib/config/SWA.toml | 15 ------ thirdparty/ShaderRecomp | 2 +- 5 files changed, 31 insertions(+), 41 deletions(-) diff --git a/UnleashedRecomp/gpu/shader/movie_vs.hlsl b/UnleashedRecomp/gpu/shader/movie_vs.hlsl index e4fc8f8..af4196c 100644 --- a/UnleashedRecomp/gpu/shader/movie_vs.hlsl +++ b/UnleashedRecomp/gpu/shader/movie_vs.hlsl @@ -8,7 +8,6 @@ Interpolators main(in VertexShaderInput In) Interpolators Out; Out.ProjPos = In.ObjPos; - Out.ProjPos.xy += float2(GET_CONSTANT(g_ViewportSize).z, -GET_CONSTANT(g_ViewportSize).w); Out.UV = In.UV; return Out; } diff --git a/UnleashedRecomp/gpu/shader/resolve_msaa_depth.hlsli b/UnleashedRecomp/gpu/shader/resolve_msaa_depth.hlsli index d06c83d..fe95dd2 100644 --- a/UnleashedRecomp/gpu/shader/resolve_msaa_depth.hlsli +++ b/UnleashedRecomp/gpu/shader/resolve_msaa_depth.hlsli @@ -12,7 +12,7 @@ float main(in float4 position : SV_Position) : SV_Depth float result = g_Texture2DMSDescriptorHeap[g_PushConstants.ResourceDescriptorIndex].Load(int2(position.xy), 0); [unroll] for (int i = 1; i < SAMPLE_COUNT; i++) - result = max(result, g_Texture2DMSDescriptorHeap[g_PushConstants.ResourceDescriptorIndex].Load(int2(position.xy), i)); + result = min(result, g_Texture2DMSDescriptorHeap[g_PushConstants.ResourceDescriptorIndex].Load(int2(position.xy), i)); return result; } diff --git a/UnleashedRecomp/gpu/video.cpp b/UnleashedRecomp/gpu/video.cpp index 4d6fe49..b5228c8 100644 --- a/UnleashedRecomp/gpu/video.cpp +++ b/UnleashedRecomp/gpu/video.cpp @@ -87,6 +87,7 @@ struct SharedConstants static GuestSurface* g_renderTarget; static GuestSurface* g_depthStencil; static RenderViewport g_viewport(0.0f, 0.0f, 1280.0f, 720.0f); +static bool g_halfPixel = true; static PipelineState g_pipelineState; static SharedConstants g_sharedConstants; static RenderSamplerDesc g_samplerDescs[16]; @@ -1246,23 +1247,27 @@ static void FlushViewport() if (g_dirtyStates.viewport) { + auto viewport = g_viewport; + if (g_halfPixel) + { + viewport.x += 0.5f; + viewport.y += 0.5f; + } + if (renderingToBackBuffer) { uint32_t width = g_swapChain->getWidth(); uint32_t height = g_swapChain->getHeight(); - commandList->setViewports(RenderViewport( - g_viewport.x * width / 1280.0f, - g_viewport.y * height / 720.0f, - g_viewport.width * width / 1280.0f, - g_viewport.height * height / 720.0f, - g_viewport.minDepth, - g_viewport.maxDepth)); - } - else - { - commandList->setViewports(g_viewport); + viewport.x *= width / 1280.0f; + viewport.y *= height / 720.0f; + viewport.width *= width / 1280.0f; + viewport.height *= height / 720.0f; } + + commandList->setViewports(viewport); + + g_dirtyStates.viewport = false; } if (g_dirtyStates.scissorRect) @@ -1285,9 +1290,18 @@ static void FlushViewport() } commandList->setScissors(scissorRect); + + g_dirtyStates.scissorRect = false; } } +static bool SetHalfPixel(bool enable) +{ + bool oldValue = g_halfPixel; + SetDirtyValue(g_dirtyStates.viewport, g_halfPixel, enable); + return oldValue; +} + static void StretchRect(GuestDevice* device, uint32_t flags, uint32_t, GuestTexture* texture) { const bool isDepthStencil = (flags & 0x4) != 0; @@ -1349,7 +1363,8 @@ static void StretchRect(GuestDevice* device, uint32_t flags, uint32_t, GuestText desc.depthAttachment = texture->texture; texture->framebuffer = g_device->createFramebuffer(desc); } - + + bool oldHalfPixel = SetHalfPixel(false); FlushViewport(); commandList->setFramebuffer(texture->framebuffer.get()); @@ -1362,6 +1377,8 @@ static void StretchRect(GuestDevice* device, uint32_t flags, uint32_t, GuestText if (g_vulkan) g_dirtyStates.vertexShaderConstants = true; + + SetHalfPixel(oldHalfPixel); } else { @@ -2638,12 +2655,6 @@ static void MakePictureData(GuestPictureData* pictureData, uint8_t* data, uint32 } } -void HalfPixelOffsetMidAsmHook(PPCRegister& f9, PPCRegister& f0) -{ - f9.f64 = 0.0; - f0.f64 = 0.0; -} - void IndexBufferLengthMidAsmHook(PPCRegister& r3) { r3.u64 *= 2; @@ -2657,11 +2668,6 @@ void SetShadowResolutionMidAsmHook(PPCRegister& r11) r11.u64 = res; } -void Primitive2DHalfPixelOffsetMidAsmHook(PPCRegister& f13) -{ - f13.f64 = 0.0; -} - static void SetResolution(be* device) { uint32_t width = uint32_t(g_swapChain->getWidth() * Config::ResolutionScale); diff --git a/UnleashedRecompLib/config/SWA.toml b/UnleashedRecompLib/config/SWA.toml index d567d2c..7271ad8 100644 --- a/UnleashedRecompLib/config/SWA.toml +++ b/UnleashedRecompLib/config/SWA.toml @@ -79,11 +79,6 @@ invalid_instructions = [ { data = 0x00485645, size = 44 } # End of .text ] -[[midasm_hook]] -name = "HalfPixelOffsetMidAsmHook" -address = 0x82E9FD64 -registers = ["f9", "f0"] - [[midasm_hook]] name = "IndexBufferLengthMidAsmHook" address = 0x82E26244 @@ -94,16 +89,6 @@ name = "SetShadowResolutionMidAsmHook" address = 0x82BAD87C registers = ["r11"] -[[midasm_hook]] -name = "Primitive2DHalfPixelOffsetMidAsmHook" -address = 0x830D1F40 -registers = ["f13"] - -[[midasm_hook]] -name = "Primitive2DHalfPixelOffsetMidAsmHook" -address = 0x830D213C -registers = ["f13"] - [[midasm_hook]] name = "CameraAspectRatioMidAsmHook" address = 0x82468E84 diff --git a/thirdparty/ShaderRecomp b/thirdparty/ShaderRecomp index 2489145..85d1948 160000 --- a/thirdparty/ShaderRecomp +++ b/thirdparty/ShaderRecomp @@ -1 +1 @@ -Subproject commit 2489145820713afe12231e2c1d4526c14cf64085 +Subproject commit 85d19486559ff3603456b20585f64a50e2dd9d95