Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: Battlefield 2 - Modern combat 2 - 1e Flickering bug (v1.7.3859) #8869

Open
IamLupo opened this issue May 17, 2023 · 18 comments
Open

[BUG]: Battlefield 2 - Modern combat 2 - 1e Flickering bug (v1.7.3859) #8869

IamLupo opened this issue May 17, 2023 · 18 comments

Comments

@IamLupo
Copy link

IamLupo commented May 17, 2023

Describe the Bug

The bug consist of heavy flickering graphics issues that happends for Battlefield 2 Modern Combat in multiplayer mode. This starts to happen for any hardware as renderer. Software renderer does work correctly without flickering! Our discord community all confirms they experience the same issue thats why i jumped in for investigation and a solution.

The flickering issues I manage to track down by testing version 1.7.3858 that has not the flickering issue. The version 1.7.3859 has the flickering issue.
By checking the pull 7797 for version v1.7.3859. You see that Battlefield 2 got a specific patch GSHwHack::OI_Battlefield2.

By disable "beforeDraw" for "GSHwHack::OI_Battlefield2" in the "GameIndex.yaml", I manage to stop the 1e flickering issue. Because we disabled the Hardware fix in "beforeDraw" we triggered a old bug called "black main menu". This basically didn't draw the full main menu on the screen that caused for a large black screen. With the "GSHwHack::OI_Battlefield2" it patched the width and height of that image.

After debugging this "GSHwHack::OI_Battlefield2" patch i manage to understand better how it worked. Thats why i changed the code to not let it trigger anymore in multiplayer.

bool GSHwHack::OI_Battlefield2MP(GSRendererHW& r, GSTexture* rt, GSTexture* ds, GSTextureCache::Source* t)
{
	if (rt && t && RCONTEXT->FRAME.Block() == 0 && RCONTEXT->TEX0.TBP0 == 0x1000)
	{
		const GSVector4i rc(0, 0, std::min(rt->GetWidth(), t->m_texture->GetWidth()), std::min(rt->GetHeight(), t->m_texture->GetHeight()));
		g_gs_device->CopyRect(t->m_texture, rt, rc, 0, 0);

		r.m_tc->InvalidateTemporarySource();
		return false;
	}

	return true;
}

Basically i patch the code that it only can trigger false when he detect the main menu. If he is not in the main menu he return true and no patch is applied on the GS.

In the orginal "GSHwHack::OI_Battlefield2" line 959 you see it has a extra if statement to return true. I didnt fully get the reason behind this desision. Because of this it returns to much false returns. This was the main cause of this flicker issue in multiplayer.

My idea is to split this into 2 patches: "GSHwHack::OI_Battlefield2SP"(default) and "GSHwHack::OI_Battlefield2MP". This way our BF2:MC online community can switch what patch to choose in "GameIndex.yaml" file. I notice right now that the BF2:MC community keeps on a lower PCSX2 version because of this issue.

Reproduction Steps

  • Change settings:
    Graphic:
    Renderer: Direct3D 12
    Adapter: RTX 3080
    Network & HDD
    Enable network
    Ethernet device Type: Sockets
    Ethernet device: Ethernet

  • Start the game, click in the main menu: Play online

  • Create a new adapter with DNS IP(45.7.228.197).

  • Login with your account or your create one.

  • Join a random server

Once you joined the game the flickering starts happening.

Expected Behavior

No response

PCSX2 Revision

v1.7.3859

Operating System

Windows 10 (64bit)

If Linux - Specify Distro

No response

CPU

AMD Ryzen 9 5900X

GPU

RTX 3080

GS Settings

SLUS-21026:
name: "Battlefield 2 - Modern Combat"
region: "NTSC-U"
compat: 5
gsHWFixes:
autoFlush: 1 # Post-processing.
halfPixelOffset: 2 # Offset post-processing.
texturePreloading: 1 # Spikes all over the place otherwise.
getSkipCount: "GSC_Battlefield2" # Depth clear.
beforeDraw: "OI_Battlefield2" # Framebuffer copy, fixes rendering for bottom part of screen.

Emulation Settings

settings

GS Window Screenshots

Ingame
The screenshot doesn't show it correctly, but the screen keeps flickering,..

BlackMainMenu
This is how the "Black main menu" looks like. It is filled for 90% unrendered screen.

Logs & Dumps

Battlefield 2 - Modern Combat_SLUS-21026_20230517121505

GS Dump: https://mega.nz/file/Acpx2KbZ#ipJWX53b0KDEPQ1C-sE0ZHVlvIE9p1uDGzrl3ESt0HE

@IamLupo IamLupo added the Bug label May 17, 2023
@IamLupo IamLupo changed the title [BUG]: Battlefield 2 - Modern combat 2 - Flicker A issues (1.7.3859) [BUG]: Battlefield 2 - Modern combat 2 - 1e Flickering bug (1.7.3859) May 17, 2023
@IamLupo IamLupo changed the title [BUG]: Battlefield 2 - Modern combat 2 - 1e Flickering bug (1.7.3859) [BUG]: Battlefield 2 - Modern combat 2 - 1e Flickering bug (v1.7.3859) May 17, 2023
@stenzek
Copy link
Contributor

stenzek commented May 19, 2023

Won't fix. Use software mode.

(the hw fix/GSC/OI has no effect on sw mode)

Some of my rambling:

Stenzek — 04/24/2023 1:14 AM
so it's clearing 8 pages at a time, row by row
I wonder if I can cheat and just peek at the next draw
WHY ARE YOU CHANGE TEX1 YOU STUPID GAME
later on it copies rows
but only the MSB
it's clearing and copying shit so many times per frame
I could hardcode all the BPs I guess
but idk if they're the same between PAL and US
it can stay broken

@stenzek stenzek closed this as not planned Won't fix, can't repro, duplicate, stale May 19, 2023
@IamLupo
Copy link
Author

IamLupo commented May 19, 2023

I put a lot of effort to provide this information and a concrete solution,... and you dont even look at it or comment on the arguments i provide...
I understand this is a hard issue, but the best thing is to split it appart and work on that... I see only rambling and no real pinpoint arguments why you went stuck with battlefield 2. Why not provide the information you discovered and document it. Like other people can continue on it?

I compiled the latest version with my patches and both of the issues i posted got resolved....

@ElTioRata
Copy link
Contributor

@IamLupo can you provide your patches?

@IamLupo
Copy link
Author

IamLupo commented Dec 1, 2024

@ElTioRata You can ask the community for fixes for the emultor in our discord: https://discord.com/invite/bf2mc
We also provide steps to setup the emulator on our website: https://bf2mc.com/guides

Because the PCSX2 developers keep closing tickets and totally ignore out fixes without feedback we desided to keep it in our community to discusse these issue and provide solutions to our community.

@JordanTheToaster
Copy link
Member

Reopening as it is a valid issue despite the difficulty of fixing it. If you want to post the patch here I can add it to PCSX2 so it can be used by everyone.

@IamLupo
Copy link
Author

IamLupo commented Dec 1, 2024

@JordanTheToaster I didn’t expect someone to care. Sorry for my grumpy comment earlier.

The patch itself might be useless at the moment. The newest PCSX2 versions have changed a lot, and we’ve noticed many positive improvements! Let me give you a more in-depth explanation.

Here are the issues we encountered related to this topic:

1: "Black main menu" issue:
This didn’t require a patch, as we realized it could be fixed by enabling "Game Fixes" > "Use Software Renderer For FMVs" in version 1.7.3858. In the latest PCSX2 versions, this issue has been resolved without needing any game fixes. It’s completely fixed now!

2: Flickering when playing online:
Back in the day (version 1.7.3858), this issue required my patch. However, in later versions, this problem disappeared on its own.

Basically, these issues have been resolved in the latest PCSX2 versions.

Regarding the second issue/solution I previously posted [1], there were additional visual glitches, like skybox flickering. These issues have also started to disappear in the newer PCSX2 versions. Great work!

However, three new issues have emerged in the latest PCSX2 versions:

1: The sun doesn’t render anymore:
This is a minor issue that no one in the community seems to mind.

2: Visual glitch with duplicated screen rendering:
The screen is rendered a second time with transparency and incorrect offsets.
We managed to fix this by applying the following settings:
"Graphics" > "Hardware Fixes" > "Skip draw range:" set to 0-3.
This removes the graphical glitch entirely.

3: Explosion texture glitch during online gameplay:
When vehicles explode online, the explosion texture renders incorrectly, causing a weird glitch visible to everyone. This issue has existed since we got BF2MC online again. Despite my research to pinpoint the source of the problem, I couldn’t find any related code or implement a fix.
See here video: [2]

All in all, PCSX2 has improved significantly and is now in a very playable state for the community.

[1] #8870
[2] https://www.youtube.com/watch?v=gzGGAcyHR5U

@OmegaGG
Copy link

OmegaGG commented Dec 1, 2024

Lupo has covered the gist of the remaining bugs;

In V1.7.3858 the explosion bug is fixed with this modified vulkan shader tfx.glsl

Just to highlight that these bugs pertain to the Multiplayer section of the game only which we restored full functionality to last year. This can be accessed with network enabled and a PCSX2 network config with Manual DNS: 128.140.0.23. The Game is multi ELF where the Multiplayer game boots from: cdrom0:\MP.BIN with entry point at 0x00100008.

As far as I can see the Singleplayer portion of the game is fixed by Stenzek previously.

I can provide gs dumps from both the current stable release and V1.7.3858 if needed.

@IamLupo
Copy link
Author

IamLupo commented Dec 1, 2024

@OmegaGG Thanks for jumping in on that one. I forgot the explosion vehicle can be solved with the shader patch in V1.7.3858.

For latest PCSX2 version this shader fix doesnt work anymore. It prevents you to reach the online menu's anymore and the menu's stay black.

I see the following has been changed compaired to yours and V1.7.3858.

Before:

gl_Position.z *= exp2(-32.0f);		// integer->float depth
o_col0 = (C.a > 127.5f) ? vec4(gl_PrimitiveID) : vec4(0x7FFFFFFF);
o_col0 = (C.a < 127.5f) ? vec4(gl_PrimitiveID) : vec4(0x7FFFFFFF);

After:

line 54: 	  gl_Position.z *= exp2(-64.0f);		// integer->float depth
line 1218:  o_col0 = (C.a > 127.5f) ? vec4(gl_PrimitiveID) : vec4(0xFFFFFFFF);
line 1224:  o_col0 = (C.a < 127.5f) ? vec4(gl_PrimitiveID) : vec4(0xFFFFFFFF);

@IamLupo
Copy link
Author

IamLupo commented Dec 1, 2024

Oke i can confirm now with latest PCSX2 version the explosion vehicle is fixed by edit the tfx.glsl.

Before:

o_col0 = (C.a > 127.5f) ? vec4(gl_PrimitiveID) : vec4(0x7FFFFFFF);
o_col0 = (C.a < 127.5f) ? vec4(gl_PrimitiveID) : vec4(0x7FFFFFFF);

After:

o_col0 = (C.a > 127.5f) ? vec4(gl_PrimitiveID) : vec4(0xFFFFFFFF);
o_col0 = (C.a < 127.5f) ? vec4(gl_PrimitiveID) : vec4(0xFFFFFFFF);

@lightningterror
Copy link
Contributor

@IamLupo Can you post a gs dump of the explosion vehicle issue?

@IamLupo
Copy link
Author

IamLupo commented Dec 1, 2024

@IamLupo
Copy link
Author

IamLupo commented Dec 1, 2024

@OmegaGG we also forgot to mention one other bug:

The flashbangs for the flash grenade doesn't work in any PCSX2 version. Basically the flash bang itself doesn't show up. Normally the screen should be white for a second or 2 and then fades away.
Right now players on emulator doesn't have this effect and have a advantage agains ps2 console players.

@lightningterror
Copy link
Contributor

@lightningterror Battlefield 2 - Modern Combat_SLUS-21026_20241202002840.gs.zst.zip

I don't see any difference between hw and sw?

@IamLupo
Copy link
Author

IamLupo commented Dec 1, 2024

Image
This is how the explosion effect looks like. Its totally glitchy at 2 frames.

With the earlier presented shader file "tfx.glsl" its been fixed.

@lightningterror
Copy link
Contributor

Might need a longer multiframe dump, this is the one you sent
Image

@IamLupo
Copy link
Author

IamLupo commented Dec 1, 2024

oke i pressed ctrl + shift + f8 for multiple frames. Let me reupload a new one

@IamLupo
Copy link
Author

IamLupo commented Dec 1, 2024

The file becomes pretty big :( 90 mb. Let me check to upload on our web server.

Explosion Artifacting

@OmegaGG
Copy link

OmegaGG commented Dec 2, 2024

Here are my GS Dumps

Missing Flashbang

Explosion Artifacting

@lightningterror lightningterror pinned this issue Jan 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants