Remove half pixel globally instead of negating them with patches.

This commit is contained in:
Skyth 2024-10-24 17:43:05 +03:00
parent 9b70e1034a
commit c2d0128226
5 changed files with 31 additions and 41 deletions

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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<uint32_t>* device)
{
uint32_t width = uint32_t(g_swapChain->getWidth() * Config::ResolutionScale);

View file

@ -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

@ -1 +1 @@
Subproject commit 2489145820713afe12231e2c1d4526c14cf64085
Subproject commit 85d19486559ff3603456b20585f64a50e2dd9d95