From a8588b0c5c86a10fec5d5160839042a4fb666557 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Thu, 20 Sep 2018 20:29:46 -0700 Subject: [PATCH 1/4] GPU: Correct handling of large viewport scaling. Need to multiply not divide, duh. Also lost the offset during refactor, and didn't test it well. --- GPU/Common/ShaderUniforms.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/GPU/Common/ShaderUniforms.cpp b/GPU/Common/ShaderUniforms.cpp index c6ffcf23c51e..e0f671950294 100644 --- a/GPU/Common/ShaderUniforms.cpp +++ b/GPU/Common/ShaderUniforms.cpp @@ -30,7 +30,7 @@ void CalcCullRange(float minValues[4], float maxValues[4], bool flipViewport, bo // Account for the projection viewport adjustment when viewport is too large. auto reverseViewportX = [](float x) { float pspViewport = (x - gstate.getViewportXCenter()) * (1.0f / gstate.getViewportXScale()); - return pspViewport * (1.0f / gstate_c.vpWidthScale); + return (pspViewport - gstate_c.vpXOffset) * gstate_c.vpWidthScale; }; auto reverseViewportY = [flipViewport](float y) { float heightScale = gstate_c.vpHeightScale; @@ -39,12 +39,12 @@ void CalcCullRange(float minValues[4], float maxValues[4], bool flipViewport, bo heightScale = -heightScale; } float pspViewport = (y - gstate.getViewportYCenter()) * (1.0f / gstate.getViewportYScale()); - return pspViewport * (1.0f / gstate_c.vpHeightScale); + return (pspViewport - gstate_c.vpYOffset) * heightScale; }; auto reverseViewportZ = [hasNegZ](float z) { float pspViewport = (z - gstate.getViewportZCenter()) * (1.0f / gstate.getViewportZScale()); // Differs from GLES: depth is 0 to 1, not -1 to 1. - float realViewport = (pspViewport - gstate_c.vpZOffset) * (1.0f / gstate_c.vpDepthScale); + float realViewport = (pspViewport - gstate_c.vpZOffset) * gstate_c.vpDepthScale; return hasNegZ ? realViewport : (realViewport * 0.5f + 0.5f); }; auto sortPair = [](float a, float b) { From e90ffdb8e14fedc4131a30675400275d5c77b5e2 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Thu, 20 Sep 2018 20:31:59 -0700 Subject: [PATCH 2/4] GE Debugger: Fix tex preview race condition. If we redraw the tex preview first, we need this for the VAO. Oops. --- Windows/GEDebugger/VertexPreview.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Windows/GEDebugger/VertexPreview.cpp b/Windows/GEDebugger/VertexPreview.cpp index 3dd9c8486b05..8fa7daa05081 100644 --- a/Windows/GEDebugger/VertexPreview.cpp +++ b/Windows/GEDebugger/VertexPreview.cpp @@ -392,8 +392,10 @@ void CGEDebugger::UpdatePrimPreview(u32 op, int which) { glBindVertexArray(previewVao); glEnableVertexAttribArray(previewProgram->a_position); - glGenBuffers(1, &ibuf); - glGenBuffers(1, &vbuf); + if (ibuf == 0) + glGenBuffers(1, &ibuf); + if (vbuf == 0) + glGenBuffers(1, &vbuf); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibuf); glBindBuffer(GL_ARRAY_BUFFER, vbuf); @@ -451,11 +453,15 @@ void CGEDebugger::UpdatePrimPreview(u32 op, int which) { glScissor((GLint)x, (GLint)-(y + fh - secondWindow->Height()), (GLsizei)fw, (GLsizei)fh); BindPreviewProgram(texPreviewProgram); - if (texPreviewVao == 0 && gl_extensions.ARB_vertex_array_object) { + if (texPreviewVao == 0 && vbuf != 0 && ibuf != 0 && gl_extensions.ARB_vertex_array_object) { glGenVertexArrays(1, &texPreviewVao); glBindVertexArray(texPreviewVao); glEnableVertexAttribArray(texPreviewProgram->a_position); + if (ibuf == 0) + glGenBuffers(1, &ibuf); + if (vbuf == 0) + glGenBuffers(1, &vbuf); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibuf); glBindBuffer(GL_ARRAY_BUFFER, vbuf); From cd0662c065456f267d585eaf6e8877ec907e1bf2 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Thu, 20 Sep 2018 20:36:41 -0700 Subject: [PATCH 3/4] GPU: Cleanup outdated flushbefore code. Backends didn't match. --- GPU/D3D11/GPU_D3D11.cpp | 2 +- GPU/Vulkan/GPU_Vulkan.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/GPU/D3D11/GPU_D3D11.cpp b/GPU/D3D11/GPU_D3D11.cpp index 2a2007f0bda1..dfd0c3d282b0 100644 --- a/GPU/D3D11/GPU_D3D11.cpp +++ b/GPU/D3D11/GPU_D3D11.cpp @@ -282,7 +282,7 @@ void GPU_D3D11::FinishDeferred() { inline void GPU_D3D11::CheckFlushOp(int cmd, u32 diff) { const u8 cmdFlags = cmdInfo_[cmd].flags; - if ((cmdFlags & FLAG_FLUSHBEFORE) || (diff && (cmdFlags & FLAG_FLUSHBEFOREONCHANGE))) { + if (diff && (cmdFlags & FLAG_FLUSHBEFOREONCHANGE)) { if (dumpThisFrame_) { NOTICE_LOG(G3D, "================ FLUSH ================"); } diff --git a/GPU/Vulkan/GPU_Vulkan.cpp b/GPU/Vulkan/GPU_Vulkan.cpp index 18aaa60b2efc..839cf1328470 100644 --- a/GPU/Vulkan/GPU_Vulkan.cpp +++ b/GPU/Vulkan/GPU_Vulkan.cpp @@ -425,7 +425,7 @@ void GPU_Vulkan::FinishDeferred() { inline void GPU_Vulkan::CheckFlushOp(int cmd, u32 diff) { const u8 cmdFlags = cmdInfo_[cmd].flags; - if ((cmdFlags & FLAG_FLUSHBEFORE) || (diff && (cmdFlags & FLAG_FLUSHBEFOREONCHANGE))) { + if (diff && (cmdFlags & FLAG_FLUSHBEFOREONCHANGE)) { if (dumpThisFrame_) { NOTICE_LOG(G3D, "================ FLUSH ================"); } From 4a5320ed7df5f082b95942544f4431124a1efbf2 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Thu, 20 Sep 2018 20:40:32 -0700 Subject: [PATCH 4/4] GLES: Refactor out duplicate code. --- GPU/GLES/ShaderManagerGLES.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/GPU/GLES/ShaderManagerGLES.cpp b/GPU/GLES/ShaderManagerGLES.cpp index c47b6a184350..bee0fad7086f 100644 --- a/GPU/GLES/ShaderManagerGLES.cpp +++ b/GPU/GLES/ShaderManagerGLES.cpp @@ -695,10 +695,7 @@ Shader *ShaderManagerGLES::ApplyVertexShader(int prim, u32 vertType, VShaderID * // Can still work with software transform. VShaderID vsidTemp; ComputeVertexShaderID(&vsidTemp, vertType, false); - uint32_t attrMask; - uint64_t uniformMask; - GenerateVertexShader(vsidTemp, codeBuffer_, &attrMask, &uniformMask); - vs = new Shader(render_, codeBuffer_, VertexShaderDesc(vsidTemp), GL_VERTEX_SHADER, false, attrMask, uniformMask); + vs = CompileVertexShader(vsidTemp); } vsCache_.Insert(*VSID, vs);