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

Projects
None yet
8 participants
@lightningterror
Member

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

Show outdated Hide outdated plugins/GSdx/GSSetting.cpp Outdated
Show outdated Hide outdated plugins/GSdx/GSSetting.h Outdated
Show outdated Hide outdated plugins/GSdx/GSSettingsDlg.cpp Outdated
Show outdated Hide outdated plugins/GSdx/GSdx.rc Outdated

@lightningterror lightningterror changed the title from GSdx: Add 8bit CPU Framebuffer conversion hack to GSdx: Add 8bit CPU Framebuffer Conversion Hack Oct 5, 2017

@lightningterror lightningterror changed the title from GSdx: Add 8bit CPU Framebuffer Conversion Hack to GSdx: Add CPU 8Bit Framebuffer Conversion Hack Oct 5, 2017

Show outdated Hide outdated plugins/GSdx/GSTextureCache.cpp Outdated
@gregory38

This comment has been minimized.

Show comment
Hide comment
@gregory38

gregory38 Oct 5, 2017

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

Contributor

gregory38 commented Oct 5, 2017

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

Show outdated Hide outdated plugins/GSdx/GSSetting.cpp Outdated
Show outdated Hide outdated plugins/GSdx/GSSetting.cpp Outdated
Show outdated Hide outdated plugins/GSdx/GSdx.rc Outdated
Show outdated Hide outdated plugins/GSdx/GSTextureCache.cpp Outdated
Show outdated Hide outdated plugins/GSdx/GSTextureCache.cpp Outdated
Show outdated Hide outdated plugins/GSdx/GSTextureCache.h Outdated
@lightningterror

This comment has been minimized.

Show comment
Hide comment
@lightningterror

lightningterror Oct 11, 2017

Member

Updated.

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

Member

lightningterror commented Oct 11, 2017

Updated.

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

Show outdated Hide outdated plugins/GSdx/GSdx.rc Outdated
@lightningterror

This comment has been minimized.

Show comment
Hide comment
@lightningterror

lightningterror Oct 13, 2017

Member

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

Member

lightningterror commented Oct 13, 2017

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

Show outdated Hide outdated plugins/GSdx/GSSetting.cpp Outdated
@turtleli

This comment has been minimized.

Show comment
Hide comment
@turtleli

turtleli Oct 14, 2017

Member

You can merge it if the code is ok turtleli.

I think you should ask Gregory in this case ;)

Member

turtleli commented Oct 14, 2017

You can merge it if the code is ok turtleli.

I think you should ask Gregory in this case ;)

Show outdated Hide outdated plugins/GSdx/GSSetting.cpp Outdated
Show outdated Hide outdated plugins/GSdx/GSTextureCache.cpp Outdated

@lightningterror lightningterror changed the title from GSdx: Add CPU 8Bit Framebuffer Conversion Hack to GSdx: Add CPU Frame buffer Conversion Hack Oct 15, 2017

@lightningterror

This comment has been minimized.

Show comment
Hide comment
@lightningterror

lightningterror Oct 16, 2017

Member

I made some changes / renaming. How does it look now ?

Member

lightningterror commented Oct 16, 2017

I made some changes / renaming. How does it look now ?

Show outdated Hide outdated plugins/GSdx/GSSetting.cpp Outdated
GSdx: Add CPU Frame buffer Conversion Hack
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

This comment has been minimized.

Show comment
Hide comment
@lightningterror

lightningterror Oct 26, 2017

Member

Updated.

Member

lightningterror commented Oct 26, 2017

Updated.

@atomic83GitHub

This comment has been minimized.

Show comment
Hide comment
@atomic83GitHub

atomic83GitHub Oct 26, 2017

Contributor

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.

Contributor

atomic83GitHub 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

This comment has been minimized.

Show comment
Hide comment
@lightningterror

lightningterror Oct 27, 2017

Member

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

Member

lightningterror commented Oct 27, 2017

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

@willkuer

This comment has been minimized.

Show comment
Hide comment
@willkuer

willkuer Oct 27, 2017

Contributor

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

Contributor

willkuer commented Oct 27, 2017

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

@ssakash

This comment has been minimized.

Show comment
Hide comment
@ssakash

ssakash Oct 27, 2017

Member

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

Member

ssakash commented Oct 27, 2017

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

@gregory38

This comment has been minimized.

Show comment
Hide comment
@gregory38

gregory38 Oct 27, 2017

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.

Contributor

gregory38 commented Oct 27, 2017

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

@atomic83GitHub

This comment has been minimized.

Show comment
Hide comment
@atomic83GitHub

atomic83GitHub Oct 27, 2017

Contributor

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

Contributor

atomic83GitHub 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

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@gregory38

This comment has been minimized.

Show comment
Hide comment
@gregory38

gregory38 Nov 2, 2017

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.

Contributor

gregory38 commented Nov 2, 2017

@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 lightningterror:8bit-cpu-textureconvertion branch Nov 2, 2017

@lightningterror

This comment has been minimized.

Show comment
Hide comment
@lightningterror

lightningterror Nov 7, 2017

Member

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.

Member

lightningterror commented Nov 7, 2017

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

This comment has been minimized.

Show comment
Hide comment
@FlatOutPS2

FlatOutPS2 Jan 22, 2018

Member

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.

Member

FlatOutPS2 commented Jan 22, 2018

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

This comment has been minimized.

Show comment
Hide comment
@lightningterror

lightningterror Jan 22, 2018

Member

#ifdef ps_main17

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

Member

lightningterror commented Jan 22, 2018

#ifdef ps_main17

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

@FlatOutPS2

This comment has been minimized.

Show comment
Hide comment
@FlatOutPS2

FlatOutPS2 Jan 22, 2018

Member

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

Member

FlatOutPS2 commented Jan 22, 2018

@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

This comment has been minimized.

Show comment
Hide comment
@lightningterror

lightningterror Jan 22, 2018

Member

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

This might help 😛

Member

lightningterror commented Jan 22, 2018

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

This might help 😛

@FlatOutPS2

This comment has been minimized.

Show comment
Hide comment
@FlatOutPS2

FlatOutPS2 Jan 22, 2018

Member

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. :)

Member

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

This comment has been minimized.

Show comment
Hide comment
@lightningterror

lightningterror Jan 23, 2018

Member

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 ?

Member

lightningterror commented Jan 23, 2018

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

This comment has been minimized.

Show comment
Hide comment
@FlatOutPS2

FlatOutPS2 Jan 23, 2018

Member

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?

Member

FlatOutPS2 commented Jan 23, 2018

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

This comment has been minimized.

Show comment
Hide comment
@lightningterror

lightningterror Jan 23, 2018

Member

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

Member

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

This comment has been minimized.

Show comment
Hide comment
@gregory38

gregory38 Jan 23, 2018

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

Contributor

gregory38 commented Jan 23, 2018

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

This comment has been minimized.

Show comment
Hide comment
@FlatOutPS2

FlatOutPS2 Jan 23, 2018

Member

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.

Member

FlatOutPS2 commented Jan 23, 2018

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

This comment has been minimized.

Show comment
Hide comment
@lightningterror

lightningterror Jan 24, 2018

Member

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.

Member

lightningterror commented Jan 24, 2018

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

This comment has been minimized.

Show comment
Hide comment
@lightningterror

lightningterror Jan 31, 2018

Member

How is progress going ?

Member

lightningterror commented Jan 31, 2018

How is progress going ?

@FlatOutPS2

This comment has been minimized.

Show comment
Hide comment
@FlatOutPS2

FlatOutPS2 Jan 31, 2018

Member

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.

Member

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