From 3a8cab2b0f7ccb8181692df7ec16f9afd43b3ff9 Mon Sep 17 00:00:00 2001 From: Luke Usher Date: Tue, 30 Jan 2018 16:48:31 +0000 Subject: [PATCH] Update VshHandleIsVertexShader to use a different detection method This is incorrect when compared to real hardware, but both our previous approach and using the same method as real hardware are insufficient right now, so this approach can be a suitable interim fix. Our previous method breaks in some titles such as Kingdom Under Fire that uses a higher than 0xFFFF value for an FVF The real hardware method (checking D3DFVD_RESERVED0) fixes Kingdom Under Fire but breaks rendering in many titles: This cannot be made to work properly until we unpatch CreateVertexShader, which is outside the scope of this current experimental branch --- src/CxbxKrnl/EmuD3D8/VertexShader.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/CxbxKrnl/EmuD3D8/VertexShader.h b/src/CxbxKrnl/EmuD3D8/VertexShader.h index 7d61fbacc..7eb4b0e67 100644 --- a/src/CxbxKrnl/EmuD3D8/VertexShader.h +++ b/src/CxbxKrnl/EmuD3D8/VertexShader.h @@ -75,10 +75,13 @@ extern void FreeVertexDynamicPatch(VERTEX_SHADER *pVertexShader); extern boolean IsValidCurrentShader(void); extern boolean VshHandleIsValidShader(DWORD Handle); -// Dxbx note : On Xbox, a FVF is recognizable when the handle <= 0x0000FFFF -// (as all values above are allocated VertexShader addresses). -inline boolean VshHandleIsFVF(DWORD Handle) { return (Handle > NULL) && (Handle <= 0x0000FFFF); } -inline boolean VshHandleIsVertexShader(DWORD Handle) { return (Handle > 0x0000FFFF) ? TRUE : FALSE; } +// NOTE: Comparing with 0xFFFF breaks some titles (like Kingdom Under Fire) +// The real Xbox checks the D3DFVF_RESERVED0 flag but we can't do that without +// breaking rendering in many titles: CreateVertexShader needs to be unpatched first. +// Instead, we assume any vertex shaders will be allocated by our memory manager and +// exist above the XBE reserved region, not great, but it'l do for now. +inline boolean VshHandleIsFVF(DWORD Handle) { return (Handle > NULL) && (Handle <= XBE_MAX_VA); } +inline boolean VshHandleIsVertexShader(DWORD Handle) { return (Handle > XBE_MAX_VA) ? TRUE : FALSE; } inline X_D3DVertexShader *VshHandleGetVertexShader(DWORD Handle) { return VshHandleIsVertexShader(Handle) ? (X_D3DVertexShader *)Handle : nullptr; } VERTEX_DYNAMIC_PATCH *VshGetVertexDynamicPatch(DWORD Handle);