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

zfreeze #1812

Merged
merged 11 commits into from
Jan 24, 2015
Merged

zfreeze #1812

merged 11 commits into from
Jan 24, 2015

Conversation

phire
Copy link
Member

@phire phire commented Jan 2, 2015

This has been a long journey but zfreeze is finished.
This PR contains code from neobrain, NanoByte011 and phire.

Changes since #1767

  • Don't cull CULLALL primitives so early because they are often used as reference planes.
  • Convert CalculateZSlope to screenspace coordinates.
  • Convert Pixelshader to screenspace coordinates (instead of worldspace xy coordinates, which is totally wrong)
  • Divide depth by 2^24 instead of clamping to 0.0-1.0 as was done before.
  • Adjust from DirectX/OpenGL screenspace coordinates to gamecube screenspace coordinates, by compensating for EFB scale. (and flipping the vertical axis in the case of OpenGL) Zfreeze now works in most games.
  • Make sure early depth isn't forced on when zfreeze is enabled, fixing fast depth and gimmick courts in Mario Power Tennis (NanoByte)
  • Improved shader constant uniform buffer savestate code.
  • Move Common code into VideoCommon
  • OpenGL: don't send CULLALL vertexes to GPU Memory.

Known Issues:

  • The Delfino Plaza court in Mario Power Tennis has zfighting issues. These may be unfixable.
  • It should still be possible to generate test cases with visible reference triangles which aren't rendered correctly with this approach. Fortunately, all known retail games use invisible reference planes.

Todo:

  • Don't update the constants uniform buffer before every drawcall.
  • Cleanup CULLALL mode code path.
  • Make sure this isn't broken on anyone's video card.
  • Savestate Issues
  • Handle per-vertex matrix indexes for the reference plane, or leave a comment justifying that we don't need to.

@JMC47
Copy link
Contributor

JMC47 commented Jan 2, 2015

This needed some actual testing. The following results are real and not fake.

Mario Power Tennis works on D3D except for a giant white triangle that covers part of the court screen. Shadows draw correctly. Only works at 1x IR, and apparently this isn't right as well. Gimmick Courts suffer from severe zfighting and white boxes flickering off the court.

On OGL the court covers up most of the screen, akin to the software renderer implementation.

Need for speed Hot Pursuit 2 shadow works and draws correctly, except it's drawing over the car itself.

NBA Street v3 has the same behavior as Need For Speed Hot Pursuit 2 with shadows drawing over the players in this case.

Super Mario Strikers has the static shadows work, but the object shadows (blue shells and whatnot) exhibit the EA problem of drawing on top of everything.

Working Titles

Star Wars Rogue Squadron 2 - Perfect
Star Wars Rogue Squadron 3 - Perfect
Mario Golf: Toadstool Tour - Perfect
NHL 2003 - Perfect
Blood Omen 2 - Perfect (dunno wtf @phire is talking about)
NBA Live 2005 - Perfect
NBA Live 2006 - Perfect (only used in menus)

@Linktothepast
Copy link
Contributor

I am getting this pixel shader error in Rogue Squadron 3: http://prntscr.com/5nk2rm

@@ -690,6 +690,24 @@ void VertexShaderManager::ResetView()
bProjectionChanged = true;
}

void VertexShaderManager::TransformToClipSpace(const float* data, float *out)
{
const float *world_matrix = (const float *)xfmem.posMatrices + g_main_cp_state.matrix_index_a.PosNormalMtxIdx * 4;

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

@phire
Copy link
Member Author

phire commented Jan 2, 2015

@Linktothepast Could you pastebin a copy of bad_ps_0003.txt?

@neobrain neobrain changed the title Fix various issues with NanoByte's port of Neobrains zfreeze branch. Fix various issues with NanoByte's port of neobrain's zfreeze branch. Jan 2, 2015
@Linktothepast
Copy link
Contributor

I deleted that because they piled up, but i made a new one. It happened with d3d btw...
http://pastebin.com/LnbZG0vg

@Linktothepast
Copy link
Contributor

With open gl i got this instead: http://prntscr.com/5nn5j1
Followed by this: http://prntscr.com/5nn65e

@phire
Copy link
Member Author

phire commented Jan 2, 2015

I need the bad*.txt dumps, otherwise I can't possibly diagnose the problem.

@Linktothepast
Copy link
Contributor

A paste of the above opengl vertexshader error:
http://pastebin.com/Um0hBf0p

@phire
Copy link
Member Author

phire commented Jan 2, 2015

Well, that is completely broken. Missing a huge chunk of the vertex shader. I don't think the errors are related to this branch.

@JMC47
Copy link
Contributor

JMC47 commented Jan 2, 2015

So, we're down to Mario Power Tennis and Super Mario Strikers having issues in D3D at this point.

@JMC47
Copy link
Contributor

JMC47 commented Jan 2, 2015

OpenGL is now working as well as D3D. The one non-working case in both backends is Mario Power Tennis's Delfino Plaza Court. Every other case is working properly.

if (s_bEFBScaleChanged) {
dirty = true;
constants.efbscale[0] = 1.0f / float(Renderer::EFBToScaledXf(1));
constants.efbscale[1] = 1.0f / float(Renderer::EFBToScaledYf(1));

This comment was marked as off-topic.

}

// if cull mode is CULL_ALL, ignore triangles and quads
if (bpmem.genMode.cullmode == GenMode::CULL_ALL && current_primitive_type == PRIMITIVE_TRIANGLES)

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

@JMC47
Copy link
Contributor

JMC47 commented Jan 2, 2015

Been testing; the only problems left are in Mario Power Tennis, it seems. The Blooper Court seems to have minor issues (possibly not related to zfreeze) and Delfino Plaza Court (severe zfighting issues) and all the other games are acting correctly it seems. There may be super minor stuff that I'm missing due to having to test 12 games, but, it seems fine to me.

@kingcons
Copy link

kingcons commented Jan 2, 2015

This is awesome work. Congrats ya'll! :) 👍

@NanoByte011
Copy link
Contributor

Good progress phire... I did try this build out though and it doesn't seem to be working completely

  • Blood Omen 2, skybox is not in background but gui does show
  • Shadows have z-fighting/clipping in most games
  • Mario Tennis doesn't look right with lots of z-fighting

Am I missing something in my setup? Tested OGL and D3D, OGL works better

@phire
Copy link
Member Author

phire commented Jan 2, 2015

Could you provide details of your exact GPU and drivers?

It's entirely possible (and potentially very annoying) that this solution only works on certain models of GPU.

@NanoByte011
Copy link
Contributor

hmmm I'm sure it's something on my end because I pulled the built exe from the RS2 thread and it's fine, so maybe I didn't grab the correct code when I built it! :)

Sorry about the panic attack!

@Tinob
Copy link
Contributor

Tinob commented Jan 3, 2015

Have you cheked the interaction of zfreeze with early z?

@Linktothepast
Copy link
Contributor

Found the cause of those pixel shader errors, it was per pixel lighting, with it disabled it works fine here.

@CrossVR
Copy link
Contributor

CrossVR commented Jan 4, 2015

@Linktothepast What is the error? Sounds like something is wrong with the pixel shader generation.

@Linktothepast
Copy link
Contributor

See comments from me above, they have all the info. It seems that per pixel lighting was the cause.

@CrossVR
Copy link
Contributor

CrossVR commented Jan 4, 2015

That shader is so broken I'm not sure how that could even happen. Looks like either Dolphin crashed very badly while outputting the shader or the dump has become corrupted for other reasons. I mean it literally cut off const strings.

@NanoByte011
Copy link
Contributor

Reporting in here...

I was trying to see what was up with the Delfino Gimmick Court in Mario Tennis, but can't find the exact cause... obviously the decals on the court and the mud are being rendered at the same depth causing z-fighting, so it looks like we are somehow missing some zfreeze reference polies, it's very odd this is the only problem, though if you look close enough at the shadows on the first court you can see the chairs and the shadows for the toads have z-fighting going on.

I also encountered a huge slow down in Rebel Strike in the "Deception at Destrillion" mission once you get into the sphere trap area after the corridor. The spacebox doesn't render properly and the game goes form 60fps down to 8-11 fps with heavy graphical glitches in the background.

I'll let you know if I find anything else out!

float a = DF31 * -dy12 - DF21 * dy31;
float b = dx31 * DF21 + dx12 * DF31;
float c = -dx12 * dy31 - dx31 * -dy12;

This comment was marked as off-topic.

This comment was marked as off-topic.

@mac1202
Copy link

mac1202 commented Jan 21, 2015

Ok thanks for your feedback i will post a bug report about the crash when mmu is enabled.

NanoByte011 and others added 9 commits January 23, 2015 03:31
Initial port of original zfreeze branch (3.5-1729) by neobrain into
most recent build of Dolphin.

Makes Rogue Squadron 2 very playable at full speed thanks to recent core
speedups made to Dolphin. Works on DirectX Video plugin only for now.

Enjoy!  and Merry Xmas!!
Based on the feedback from pull request dolphin-emu#1767 I have put in most of
degasus's suggestions in here now.

I think we have a real winner here as moving the code to
VertexManagerBase for a function has allowed OGL to utilize zfreeze now
:)

Correct use of the vertex pointer has also corrected most of the issue
found in pull request dolphin-emu#1767 that JMC47 stated.  Which also for me now
has Mario Tennis working with no polygon spikes on the characters
anymore!  Shadows are still an issue and probably in the other games
with shadow problems.  Rebel Strike also seems better but random skybox
glitches can show up.
Results are still not correct, but things are getting closer.

 * Don't cull CULLALL primitives so early so they can be used as reference
        planes.
 * Convert CalculateZSlope to screenspace coordinates.
 * Convert Pixelshader to screenspace coordinates (instead of worldspace
        xy coordinates, which is totally wrong)
 * Divide depth by 2^24 instead of clamping to 0.0-1.0 as was done
        before.

Progress:
 * Rouge Squadron 2/3 appear correct in game (videos in rs2 save file
         selection are missing)
 * Shadows draw 100% correctly in NHL 2003.
 * Mario golf menu renders correctly.
 * NFS: HP2, shadows sometimes render on top of car or below the road.
 * Mario Tennis, courts and shadows render correctly, but at wrong depth
 * Blood Omen 2, doesn't work.
OpenGL requires the y coordinates to be flipped.

Also refactored PixelGen code to remove duplicate code.
- Calculate ZSlope every flush but only set PixelShader Constant on Reset Buffer when zfreeze
- Fixed another Pixel Shader bug in D3D that was giving me grief
This is closer to what the hardware does anyway.
Had to re-do *ShaderManager so they saved their constant arrays
instead of completly rebuilding them on restore state.
@@ -89,6 +89,8 @@ void VertexManager::ResetBuffer(u32 stride)
buffer = s_indexBuffer->Map(MAXIBUFFERSIZE * sizeof(u16));
IndexGenerator::Start((u16*)buffer.first);
s_index_offset = buffer.second;


This comment was marked as off-topic.


// Global matrix ID.
u32 mtxIdx = g_main_cp_state.matrix_index_a.PosNormalMtxIdx;
PortableVertexDeclaration vert_decl = format->GetVertexDeclaration();

This comment was marked as off-topic.

Also:
 * Implement support for per-vertex PosMatrixIndex
 * Only update zslope constant once when zfreeze is activated.
 * Added a bunch of comments.
@phire
Copy link
Member Author

phire commented Jan 23, 2015

@dolphin-emu-bot rebuild

@phire
Copy link
Member Author

phire commented Jan 23, 2015

Ok, we are 99.8% finished. I'm just worried about those failures with llvmpipe on fifoci.

I don't have a clean code-path for cull-all triangles and bufferstorage, I suspect they are interacting badly.

Do Not Merge

Instead we keep the loaded vertices in CPU memory.
@phire
Copy link
Member Author

phire commented Jan 24, 2015

And Finished.

@phire
Copy link
Member Author

phire commented Jan 24, 2015

As soon as @degasus gives the last commit a look over this can be merged.

@dolphin-emu-bot
Copy link
Contributor

FifoCI detected that this change impacts graphical rendering. Here are the behavior differences detected by the system:

  • fifa-street on ogl-lin-mesa: diff
  • mtennis-zfreeze on ogl-lin-mesa: diff
  • rs2-zfreeze on ogl-lin-mesa: diff
  • mtennis-zfreeze on ogl-lin-nv: diff
  • rs2-zfreeze on ogl-lin-nv: diff

automated-fifoci-reporter

@neobrain
Copy link
Member

#yolo #hype

neobrain added a commit that referenced this pull request Jan 24, 2015
Add proper zfreeze support.
@neobrain neobrain merged commit 43036af into dolphin-emu:master Jan 24, 2015
// is enabled in the following flush.
for (unsigned int i = 0; i < 3; ++i)
{
u8* vtx_ptr = s_pCurBufferPointer - vert_decl.stride * (3 - i);

This comment was marked as off-topic.

@phire phire deleted the real_zfreeze branch July 4, 2015 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet