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

GSdx: Add CPU Frame buffer Conversion Hack #2086

Merged
merged 1 commit into from
Nov 2, 2017

Conversation

lightningterror
Copy link
Contributor

@lightningterror lightningterror commented Oct 5, 2017

Add HwW Hack that enables 4-bit and 8-bit Frame buffer Conversion on the CPU.
Can fix broken textures on games but at the cost of slower performance.
List of games: Harry Potter games, Fifa Street games, MGS3 games.
Games like Call of Duty, Kung fu Panda might also be affected as well as others especially on Direct3D.
Add HW Hack GUI option on Windows/Linux for Framebuffer Convertion hack named "CPU FB Conversion."

Should fix
https://forums.pcsx2.net/Thread-Harry-Potter-and-The-Chamber-of-Secrets-SLES-51192-E-artifacting

Should Improve
#569

@@ -122,6 +122,13 @@ const char* dialog_message(int ID, bool* updateText) {
case IDC_TC_DEPTH:
return "Disable the support of Depth buffer in the texture cache.\n"
"It can help to increase speed but it will likely create various glitches.";
case IDC_8BITCPUFBHACK:

This comment was marked as spam.

@@ -63,6 +63,7 @@ enum {
IDC_ACCURATE_BLEND_UNIT,
IDC_ACCURATE_DATE,
IDC_TC_DEPTH,
IDC_8BITCPUFBHACK,

This comment was marked as spam.

@@ -698,6 +698,7 @@ void GSHacksDlg::OnInit()
CheckDlgButton(m_hWnd, IDC_PRELOAD_GS, theApp.GetConfigB("preload_frame_with_gs_data"));
CheckDlgButton(m_hWnd, IDC_ALIGN_SPRITE, theApp.GetConfigB("UserHacks_align_sprite_X"));
CheckDlgButton(m_hWnd, IDC_TC_DEPTH, theApp.GetConfigB("UserHacks_DisableDepthSupport"));
CheckDlgButton(m_hWnd, IDC_8BITCPUFBHACK, theApp.GetConfigB("UserHack_cpu_8bis_fb_conversion"));

This comment was marked as spam.

@@ -142,6 +142,7 @@ BEGIN
CONTROL "Alpha",IDC_ALPHAHACK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,71,34,8
CONTROL "Alpha Stencil",IDC_ALPHASTENCIL,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,108,71,57,8
CONTROL "Disable Depth Emulation",IDC_TC_DEPTH,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,108,84,92,8
CONTROL "CPU FB Conversion", IDC_8BITCPUFBHACK, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 14, 84, 91, 8

This comment was marked as spam.

@lightningterror lightningterror force-pushed the 8bit-cpu-textureconvertion branch 2 times, most recently from e1deb2f to 66faf74 Compare October 5, 2017 00:39
@lightningterror lightningterror changed the title GSdx: Add 8bit CPU Framebuffer conversion hack GSdx: Add 8bit CPU Framebuffer Conversion Hack Oct 5, 2017
@lightningterror lightningterror force-pushed the 8bit-cpu-textureconvertion branch 2 times, most recently from b6444b1 to a02a091 Compare October 5, 2017 00:55
@lightningterror lightningterror changed the title GSdx: Add 8bit CPU Framebuffer Conversion Hack GSdx: Add CPU 8Bit Framebuffer Conversion Hack Oct 5, 2017
@lightningterror lightningterror force-pushed the 8bit-cpu-textureconvertion branch 3 times, most recently from b970e55 to 7d13e95 Compare October 5, 2017 02:00
// 2/ even with upscaling
// 3/ for both DX and OpenGL
if (m_cpu_8bit_fb_coversion && psm == PSM_PSMT8)
// Hack can fix broken textures on games such as: Harry Potter games (Direct3D and OpenGL), Fifa Street games (Direct3D only), MGS3 (Direct3D only).

This comment was marked as spam.

@gregory38
Copy link
Contributor

HLSL <=> GLSL

vec2 => float2
uvec2 (vector of 2 unsigned int) => uint2 
ivec2 (vector 2 signed int) => int2
gl_FragCoord => SV_Position (I hope you won't have issue with the Y axis order)
texelFetch => Load

Copy/past GLSL code, replace the above. Update header/return based on other HLSL equivalent (ps_main0).

Oh I just saw that you need also the ScalingFactor constant buffer parameter. My code is awful without comment...

@lightningterror lightningterror force-pushed the 8bit-cpu-textureconvertion branch 5 times, most recently from 8f69412 to 9b25560 Compare October 7, 2017 18:14
@@ -122,6 +122,13 @@ const char* dialog_message(int ID, bool* updateText) {
case IDC_TC_DEPTH:
return "Disable the support of Depth buffer in the texture cache.\n"
"It can help to increase speed but it will likely create various glitches.";
case IDC_8BIT_CPU_FBHACK:
return "Forces 8-bit shader conversion to be done on the CPU instead of the GPU but performance will be slower.\n"
"Direct3D doesn't support shader conversion , OpenGL does support shader conversion but it doesn't render some corners properly.\n"

This comment was marked as spam.

"Direct3D doesn't support shader conversion , OpenGL does support shader conversion but it doesn't render some corners properly.\n"
"The hack can fix glitches or broken graphics in some games.\n"
"Harry Potter games (Direct3D and OpenGL).\n"
"Fifa Street games (Direct3D).\n"

This comment was marked as spam.

@@ -142,6 +142,7 @@ BEGIN
CONTROL "Alpha",IDC_ALPHAHACK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,71,34,8
CONTROL "Alpha Stencil",IDC_ALPHASTENCIL,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,108,71,57,8
CONTROL "Disable Depth Emulation",IDC_TC_DEPTH,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,108,84,92,8
CONTROL "CPU 8-bit FB Conversion", IDC_8BIT_CPU_FBHACK, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 14, 84, 92, 8

This comment was marked as spam.

// 3/ for both DX and OpenGL
if (m_cpu_8bit_fb_coversion && psm == PSM_PSMT8)
// Direct3D doesn't have a shader conversion so it needs to be done on the CPU side which causes slowdowns (Fifa Street).
// OpenGL has a shader but it doesn't handle some corners properly (Harry Potter, COD ?, Kung fu Panda ?).

This comment was marked as spam.

This comment was marked as spam.

// 1/ it just works :)
// 2/ even with upscaling
// 3/ for both DX and OpenGL
if (m_cpu_8bit_fb_coversion && psm == PSM_PSMT8)

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@@ -130,6 +130,7 @@ class GSTextureCache
bool m_preload_frame;
uint8* m_temp;
bool m_can_convert_depth;
bool m_cpu_8bit_fb_coversion;

This comment was marked as spam.

@lightningterror
Copy link
Contributor Author

Updated.

p.s. the shader port will be in a separate pr. Don't wanna delay this a month (maybe) or so.

@lightningterror lightningterror force-pushed the 8bit-cpu-textureconvertion branch 2 times, most recently from 6caec8d to 7e83c54 Compare October 11, 2017 01:05
@@ -142,6 +142,7 @@ BEGIN
CONTROL "Alpha",IDC_ALPHAHACK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,71,34,8
CONTROL "Alpha Stencil",IDC_ALPHASTENCIL,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,108,71,57,8
CONTROL "Disable Depth Emulation",IDC_TC_DEPTH,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,108,84,92,8
CONTROL "CPU 8-bit FB Conversion",IDC_8BIT_CPU_FBHACK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP, 14, 84, 92, 8

This comment was marked as spam.

This comment was marked as spam.

@lightningterror
Copy link
Contributor Author

You can merge it if the code is ok @turtleli.

@@ -122,6 +122,13 @@ const char* dialog_message(int ID, bool* updateText) {
case IDC_TC_DEPTH:
return "Disable the support of Depth buffer in the texture cache.\n"
"It can help to increase speed but it will likely create various glitches.";
case IDC_8BIT_CPU_FBHACK:
return "Forces 8-bit shader conversion to be done on the CPU instead of the GPU but performance will be slower.\n"
"Direct3D doesn't support shader conversion, OpenGL does support shader conversion but it doesn't render some corner cases properly.\n"

This comment was marked as spam.

This comment was marked as spam.

@lightningterror lightningterror force-pushed the 8bit-cpu-textureconvertion branch 2 times, most recently from effa6b2 to fa9fe49 Compare October 17, 2017 22:11
@@ -122,6 +122,13 @@ const char* dialog_message(int ID, bool* updateText) {
case IDC_TC_DEPTH:
return "Disable the support of Depth buffer in the texture cache.\n"
"It can help to increase speed but it will likely create various glitches.";
case IDC_CPU_FB_CONVERSION:
return "Enables 4-bit and 8-bit frame buffer conversion to be done on the CPU instead of the GPU.\n\n"

This comment was marked as spam.

Add HW Hack that enables Framebuffer Conversion on the CPU instead of the GPU.
Can fix broken textures on games but at the cost of slower performance.
List of games: Harry Potter games, FIFA Street games.
Games like Call of Duty, Kung fu Panda might also be affected as well as others
especially on Direct3D.
Add HW Hack GUI option on Windows/Linux for 4-bit and 8-bit Framebuffer conversion hack
named "Frame Buffer Conversion".
@lightningterror
Copy link
Contributor Author

Updated.

@ghost
Copy link

ghost commented Oct 26, 2017

This hack cause massive slowdown and a driver crash (nvidia) in Mercenaries 2.It also cause graphics glitch and slowdown in MGS3 under OpenGL (DX is better with it).
This hack don't solve Kung fu panda and cause a GSDX out of memory issue.

@lightningterror
Copy link
Contributor Author

lightningterror commented Oct 27, 2017

It's a hack. It should be enabled only if a game needs it. Otherwise no.

@willkuer
Copy link
Contributor

I guess it shouldn't produce crashes, or? Slowdowns and glitches are obviously a different story.

@ssakash
Copy link
Member

ssakash commented Oct 27, 2017

Why is this actually described as a hack? It's more accurate than the shader alternative, right?

@gregory38
Copy link
Contributor

@atomic83GitHub
OpenGL is capable to convert the frame buffer directly on the GPU in a fast and mostly accurate way. Except some rare games, you shouldn't enable it.

Did you get the crash on OpenGL or Dx ? Maybe it consume too much memory.

Speed wise, this hack will range from slow to very slow. Because you need
1/ stop to send command to GPU
2/ Finish current work
3/ read data from GPU

@ssakash
It is just too slow. And it seems it isn't that stable.

@ghost
Copy link

ghost commented Oct 27, 2017

#gregory38 I use DX mode and I can confirm that the driver crash is a out of memory issue.

@gregory38 gregory38 merged commit 1cbd4c5 into PCSX2:master Nov 2, 2017
@gregory38
Copy link
Contributor

@atomic83GitHub thanks for the info.Potentially we could reduce the memory usage.

So far we do

  • create an offscreen texture which contains a data buffer
  • read the data
  • put the texture in GSdx garbage collector

All calls are synchronous (hence the slowness). So even if we have multiple offscreen texture, only one data buffer will be used. So instead to duplicate all data buffers, we could use a big common one. Anyway, my feeling is that this hack isn't a good solution most of the time. I.e. better port the glsl shader that can handle 90% of conversion at fast speed.

@lightningterror lightningterror deleted the 8bit-cpu-textureconvertion branch November 2, 2017 14:55
@lightningterror
Copy link
Contributor Author

Anyway, my feeling is that this hack isn't a good solution most of the time. I.e. better port the glsl shader that can handle 90% of conversion at fast speed.

Agreed. So far it seems only Harry Potter and TCoS will need it even with the ported shader. And I guess games that use 4-bit as well.

@FlatOutPS2
Copy link
Contributor

All calls are synchronous (hence the slowness). So even if we have multiple offscreen texture, only one data buffer will be used. So instead to duplicate all data buffers, we could use a big common one. Anyway, my feeling is that this hack isn't a good solution most of the time. I.e. better port the glsl shader that can handle 90% of conversion at fast speed.

@gregory38 Which shader is it? I don't get different results on OGL compared to DX with this hack.

@lightningterror
Copy link
Contributor Author

#ifdef ps_main17

FIFA-Street-8bits and Blending.zip
You can use this as a testcase.

@FlatOutPS2
Copy link
Contributor

@lightningterror Thanks for the info.

I tried a quick port to DX for easier testing, but speed was terrible. I hope I did something wrong. :p Will look more into it later to hopefully improve/expand the shader.

@lightningterror
Copy link
Contributor Author

From Gregory: Note you might need to add some dummy/stub shader for 11-16

This might help 😛

@FlatOutPS2
Copy link
Contributor

FlatOutPS2 commented Jan 22, 2018

This might help 😛

You don't need to add those. If anything, that would make things slower.

EDIT: Turns out I did make a mistake unrelated to the shader that made things slower. :)

@lightningterror
Copy link
Contributor Author

EDIT: Turns out I did make a mistake unrelated to the shader that made things slower. :)

I sense a PR Soon™.

Btw the shader on ogl isn't perfect either.
Harry Potter COS.zip
Harry Potter COS doesn't like the shader so it could be tweaked a bit more, do you wanna try to debug/solve the issue ?

@FlatOutPS2
Copy link
Contributor

do you wanna try to debug/solve the issue ?

That was the point of my interest. I noticed your hack helps Stuntman, but I suspect the current shader doesn't work on that game because the game uses 4-bits.

Have you found any more games that need the hack/improved shader?

@lightningterror
Copy link
Contributor Author

lightningterror commented Jan 23, 2018

doesn't work on that game because the game uses 4-bits

The shader is only for 8-bits. A new shader probably needs to be written for 4-bit.

MGS3 maybe ? I'm not sure.
On OGL enabling FBC causes a whole bunch of other graphical issues. Plus high GS usage.
No result from disabling the shader inside the code, I don't see any difference or maybe it's used in a different part of the game.

I get no results on D3D with the FBC hack. The only result I get is enabling texture shuffle on D3D so it could be related to why I don't get any result in the first place. On top of that MGS3 also uses channel shuffle I think. Not sure tho.
MGS3-Demo.zip

@gregory38
Copy link
Contributor

The shader have 2 limitations

  • 4 bits format isn't handled.
  • page offset isn't supported either. This offset changes the pixel position.

In my opinion we should build a lookup table (texture) with the pixel position based on the various format offset.

8 bits texture is often uses with depth effect / channel shuffling / texture shuffling. It doesn't help to reduce the complexity...

For the story I create the version of this shader for the blue fog of MGS3. However I don't remember if it was related to depth. I vaguely remember a (box?) fighting game (with night in the name) that also use 8 bits format (but it could be blending issue too).

I really should upload all my gsdump somewhere...

@FlatOutPS2
Copy link
Contributor

vaguely remember a (box?) fighting game (with night in the name) that also use 8 bits format (but it could be blending issue too).

Yeah, I found it. It's Fight Night Round 2. Another EA title(like FIFA Street). And like FIFA Street it also needs blending to properly fix the issue.
And my suspicion about Stuntman was proven correct. It does need a 4 bits handler.

@lightningterror
Copy link
Contributor Author

I'll just add this info here, it may be important. The FBC hack breaks channel shuffle effect on MGS3, dunno about other games.
All the more reason to replace the hack with a shader.

@lightningterror
Copy link
Contributor Author

How is progress going ?

@FlatOutPS2
Copy link
Contributor

FlatOutPS2 commented Jan 31, 2018

How is progress going ?

There's hardly been any progress. I've been busy with other PCSX2 projects. I'll have to add some basic blending too for this work properly in Direct3D, so it'll take longer than just a simple shader port plus improvements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants