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

Greg/gsdx sparse #2843

Merged
merged 17 commits into from Apr 26, 2019

Conversation

Projects
None yet
4 participants
@gregory38
Copy link
Contributor

commented Feb 7, 2019

Please find some code to create/manage sparse render target&depth buffer.

GL backend is mostly done. Likely need to fix function that rely on texture size.

Dx will gracefully fallback to standard mode.

Nothing is done on renderer neither the texture cache to really use those sparse texture.

@lightningterror lightningterror added this to the Release 1.6 milestone Feb 9, 2019

@lightningterror lightningterror force-pushed the greg/gsdx-sparse branch from c90af7d to a980e20 Feb 12, 2019

@tadanokojin tadanokojin force-pushed the greg/gsdx-sparse branch from 96c28c1 to c0e8d17 Feb 16, 2019

@gregory38 gregory38 force-pushed the greg/gsdx-sparse branch from 3066f2b to 95091b7 Feb 27, 2019

@gregory38

This comment has been minimized.

Copy link
Contributor Author

commented Feb 27, 2019

@tadanokojin @lightningterror I added some small improvements for sparse. In order to test it, you must force enable the sparse extension. Do you have any pending stuff on your side for sparse ?

@lightningterror

This comment has been minimized.

Copy link
Member

commented Feb 27, 2019

I got none, what about #2837 (comment) ?

@gregory38

This comment has been minimized.

Copy link
Contributor Author

commented Feb 27, 2019

I posted in the wrong PR. It was some tests for AMD if it doesn't help, no need to keep it.

@gregory38

This comment has been minimized.

Copy link
Contributor Author

commented Feb 27, 2019

So far code is disabled for everyone. But I'm afraid that it will be limited to Nvidia :(

@tadanokojin

This comment has been minimized.

Copy link
Member

commented Feb 27, 2019

I don't have anything that I can think of, I'll do some testing later today.

@tadanokojin

This comment has been minimized.

Copy link
Member

commented Feb 28, 2019

Major issues with Burnout 3

No Sparse:
002425

Sparse:
002426

@gregory38

This comment has been minimized.

Copy link
Contributor Author

commented Feb 28, 2019

Issue is perf ? Or the rendering ?

@tadanokojin

This comment has been minimized.

Copy link
Member

commented Feb 28, 2019

Perf, going from pin 60 to lower ends of 10.
Black sky is unrelated.

@gregory38

This comment has been minimized.

Copy link
Contributor Author

commented Feb 28, 2019

Hum need to find the culprit.

  • No Sparse depth ?
  • Always commit with no uncommit ?
@tadanokojin

This comment has been minimized.

Copy link
Member

commented Feb 28, 2019

I tested SoTC, DC2, GT4 and Jak 3 didn't notice any issues there.

Burnout Revenge has the same issue and I think it's safe to say Burnout Dominator probably has a similar issue (don't own it).

I tested with sparse depth enabled. No luck there.

note: not noticing any high/abnormal gpu usage or anything.

@tadanokojin

This comment has been minimized.

Copy link
Member

commented Feb 28, 2019

Burnout 3 is fine @ 2074597 as I remembered

Same commit revenge is spamming the log about sparse not being a multiple of the page size and still has severe perf issues.

@lightningterror lightningterror force-pushed the greg/gsdx-sparse branch from 9bed9a7 to 926ccb0 Mar 6, 2019

@gregory38

This comment has been minimized.

Copy link
Contributor Author

commented Mar 8, 2019

@tadanokojin
I won't have time to finish it. If you have time, could you like at the following idea/code. So far it is only a hack.
Currently, TC might rescale a previous target to use it as an input texture. Rescaling sucks as it reduces quality, speed impact is strange. I want to use the committed info, to only copy the useful data to the real sized GS texture.
Note: potentially it can be done without sparse texture.
Note2: it might require standard scaling (not custom resolution)

For example, GS will render into a frame buffer emulated by a (2x upscaled) 1536x768 target on GPU but only 1280x512 is committed. Then GS will read it back as a 1024x512 texture. We want to create a sparse target of 2048x1024 (scaling factor * size of GS). Then copy only the 1280x512 data from old target to new source.

Game that need to be tested

  • tri-ace game (radiata story/star ocean 3/forgot the 3rd one) with blending off, they use it to compute shadow. They will hit this code path 100th a time by frame ! Don't forget to disable CRC hack that will skip those shadows
  • snowblend engine game (baldur gate/...), because of the half-screen (half_right) special case

Here the current hacking patch

--- a/plugins/GSdx/Renderers/HW/GSTextureCache.cpp
+++ b/plugins/GSdx/Renderers/HW/GSTextureCache.cpp
@@ -1190,6 +1190,7 @@ GSTextureCache::Source* GSTextureCache::CreateSource(const GIFRegTEX0& TEX0, con
            GL_INS("ERROR: Reading RT as a packed-indexed 4 bits format is not supported");
        }
 #endif
+       bool is_copy = shader == ShaderConvert_COPY;
 
        if (GSLocalMemory::m_psm[TEX0.PSM].bpp > 8) {
            src->m_32_bits_fmt = dst->m_32_bits_fmt;
@@ -1300,7 +1301,11 @@ GSTextureCache::Source* GSTextureCache::CreateSource(const GIFRegTEX0& TEX0, con
        // 2/ It doesn't support rescaling of the RT (tw = 1024)
        // Maybe it will be more easy to just round the UV value in the Vertex Shader
 
-       if (!is_8bits) {
+       if (is_copy && m_renderer->m_dev->HasColorSparse()) {
+           GSVector2i committed_size = dst->m_texture->GetCommittedSize();
+           dRect.z = std::min(committed_size.x, w);
+           dRect.w = std::min(committed_size.y, h);
+       } else if (!is_8bits) {
            // 8 bits handling is special due to unscaling. It is better to not execute this code
            if (w > dstsize.x)
            {
@@ -1318,6 +1323,9 @@ GSTextureCache::Source* GSTextureCache::CreateSource(const GIFRegTEX0& TEX0, con
        }
 
        GSVector4 sRect(0, 0, w, h);
+       if (is_copy && m_renderer->m_dev->HasColorSparse()) {
+           sRect = dRect;
+       }
 
        // Don't be fooled by the name. 'dst' is the old target (hence the input)
        // 'src' is the new texture cache entry (hence the output)
@@ -1357,7 +1365,7 @@ GSTextureCache::Source* GSTextureCache::CreateSource(const GIFRegTEX0& TEX0, con
        // copy. Likely a speed boost and memory usage reduction.
        bool linear = (TEX0.PSM == PSM_PSMCT32 || TEX0.PSM == PSM_PSMCT24);
 
-       if ((sRect == dRect).alltrue() && !shader)
+       if ((sRect == dRect).alltrue() && is_copy)
        {
            if (half_right) {
                // You typically hit this code in snow engine game. Dstsize is the size of of Dx/GL RT
@@ -1366,7 +1374,7 @@ GSTextureCache::Source* GSTextureCache::CreateSource(const GIFRegTEX0& TEX0, con
                float real_width = dst->m_TEX0.TBW * 64u * dst->m_texture->GetScale().x;
                m_renderer->m_dev->CopyRect(sTex, dTex, GSVector4i((int)(real_width/2.0f), 0, (int)real_width, h));
            } else {
-               m_renderer->m_dev->CopyRect(sTex, dTex, GSVector4i(0, 0, w, h)); // <= likely wrong dstsize.x could be bigger than w
+               m_renderer->m_dev->CopyRect(sTex, dTex, GSVector4i(0, 0, sRect.z, sRect.w)); // <= likely wrong dstsize.x could be bigger than w
            }
        }
        else
@lightningterror

This comment has been minimized.

Copy link
Member

commented Mar 11, 2019

Just so we don't forget #2813 needs to be looked over. Seems sparse makes things worse for now.

@gregory38

This comment has been minimized.

Copy link
Contributor Author

commented Mar 11, 2019

Strange. Long dump of spike would be nice.

@gregory38

This comment has been minimized.

Copy link
Contributor Author

commented Mar 19, 2019

Thing to do

  • add commit in the 2 copy function (device)
  • only uncommit in recycle in debug/dev build. Too much uncommit is bad for performance.

gregory38 added some commits Feb 7, 2019

gsdx hw: allow to create sparse texture at device level
Obviously texture allocation should be updated too
gsdx hw: add API to manage sparse texture allocation
DX/GL should implement "CommitPages" to really commit memory

Note: CommitPages should also update the m_committed_size member

gregory38 and others added some commits Feb 7, 2019

gsdx ogl: enable sparse feature on GSdevice interface
Note: remain
* To really use sparse texture
* To debug it ^^
gsdx hw: commit texture before a clear in OI hack
Note I didn't bother to compute the draw region for single game hack.
Gain would be 0 if game doesn't suffer of memory issue in the first place
gsdx ogl: always commit a sparse texture when force_texture_clear is …
…enabled

The goal is to ensure the behavior of the option. VRAM usage isn't important
as option is mainly intented for debug purpose.

@lightningterror lightningterror force-pushed the greg/gsdx-sparse branch from 2689db9 to 95edf67 Mar 26, 2019

@lightningterror

This comment has been minimized.

Copy link
Member

commented Mar 26, 2019

I pushed the sparse extension detection, amd sparse depth and tc dead code commits on to master with some minor tweaks followed by a rebase on current branch.

@Freestate2nd

This comment has been minimized.

Copy link

commented Apr 3, 2019

@tadanokojin

Game that need to be tested

* tri-ace game (radiata story/star ocean 3/forgot the 3rd one) with blending off, they use it to compute shadow. They will hit this code path 100th a time by frame ! Don't forget to disable CRC hack that will skip those shadows

The third TRI-ACE GAME for ps2 is Valkyrie Profile Silmeria (AKA Valkyrie Profile 2)

@Freestate2nd

This comment has been minimized.

Copy link

commented Apr 3, 2019

Third Tri-ace game for testing is Valkyrie Profile Silmeria

@lightningterror

This comment has been minimized.

Copy link
Member

commented Apr 10, 2019

@gregory38 with the new test code for Star Ocean 3 I'm noticing around 7 fps increase on my dump compared to current sparse branch.

@gregory38

This comment has been minimized.

Copy link
Contributor Author

commented Apr 10, 2019

@lightningterror what test code ?

Edit you mean the above hack ?

gregory38 added some commits Apr 10, 2019

gsdx ogl: only always uncommit texture in debug build
It is good for memory but bad for the speed. There is likely a better trade-off
but it should be enough for now
gsdx ogl: commit texture in copy function
So far not yet used but safer this way
@lightningterror

This comment has been minimized.

Copy link
Member

commented Apr 10, 2019

Ye that one that you asked kojin to test.
#2843 (comment)

@gregory38

This comment has been minimized.

Copy link
Contributor Author

commented Apr 10, 2019

Oh. What upscaled resolution. Accurate blending ?

Then test the new PR.

@lightningterror

This comment has been minimized.

Copy link
Member

commented Apr 10, 2019

Blending off and native res.

Edit: I will test the pr soonish.

@lightningterror

This comment has been minimized.

Copy link
Member

commented Apr 26, 2019

I will merge this now but we shouldn't forget to address the mentioned issues in the future.

@lightningterror lightningterror merged commit ead3d21 into master Apr 26, 2019

4 checks passed

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

@lightningterror lightningterror deleted the greg/gsdx-sparse branch Apr 26, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.