From 842290b6dd280d7110aa0190a3af00be4a7b3ef0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sat, 20 Oct 2018 13:22:14 +0200 Subject: [PATCH 1/3] Workaround for bad int behaviour on Adreno / GLES. (no problems in Vulkan). See #11480, should help #11479. --- GPU/GLES/DepalettizeShaderGLES.cpp | 4 ++++ GPU/GLES/GPU_GLES.cpp | 11 +++++++++-- GPU/GLES/TextureCacheGLES.cpp | 4 +++- GPU/GPUState.h | 2 +- UI/DevScreens.cpp | 7 +++++++ ext/native/gfx/gl_debug_log.h | 2 +- ext/native/gfx_es2/gpu_features.cpp | 7 +++++++ ext/native/thin3d/GLQueueRunner.cpp | 1 + ext/native/thin3d/GLRenderManager.h | 1 + 9 files changed, 34 insertions(+), 5 deletions(-) diff --git a/GPU/GLES/DepalettizeShaderGLES.cpp b/GPU/GLES/DepalettizeShaderGLES.cpp index 52b1458b13..b18ddd5876 100644 --- a/GPU/GLES/DepalettizeShaderGLES.cpp +++ b/GPU/GLES/DepalettizeShaderGLES.cpp @@ -53,6 +53,10 @@ DepalShaderCacheGLES::DepalShaderCacheGLES(Draw::DrawContext *draw) { render_ = (GLRenderManager *)draw->GetNativeObject(Draw::NativeObject::RENDER_MANAGER); // Pre-build the vertex program useGL3_ = gl_extensions.GLES3 || gl_extensions.VersionGEThan(3, 3); + if (!gstate_c.Supports(GPU_SUPPORTS_32BIT_INT_FSHADER)) { + // Use the floating point path, it just can't handle the math. + useGL3_ = false; + } vertexShaderFailed_ = false; vertexShader_ = 0; diff --git a/GPU/GLES/GPU_GLES.cpp b/GPU/GLES/GPU_GLES.cpp index 2a75ead250..f4e152e934 100644 --- a/GPU/GLES/GPU_GLES.cpp +++ b/GPU/GLES/GPU_GLES.cpp @@ -190,11 +190,18 @@ void GPU_GLES::CheckGPUFeatures() { } if (gl_extensions.IsGLES) { - if (gl_extensions.GLES3) + if (gl_extensions.GLES3) { features |= GPU_SUPPORTS_GLSL_ES_300; + // Mali reports 30 but works fine... + if (gl_extensions.range[1][5][1] >= 30) { + features |= GPU_SUPPORTS_32BIT_INT_FSHADER; + } + } } else { - if (gl_extensions.VersionGEThan(3, 3, 0)) + if (gl_extensions.VersionGEThan(3, 3, 0)) { features |= GPU_SUPPORTS_GLSL_330; + features |= GPU_SUPPORTS_32BIT_INT_FSHADER; + } } if (gl_extensions.EXT_shader_framebuffer_fetch || gl_extensions.NV_shader_framebuffer_fetch || gl_extensions.ARM_shader_framebuffer_fetch) { diff --git a/GPU/GLES/TextureCacheGLES.cpp b/GPU/GLES/TextureCacheGLES.cpp index 04b629e1b1..6536e8d916 100644 --- a/GPU/GLES/TextureCacheGLES.cpp +++ b/GPU/GLES/TextureCacheGLES.cpp @@ -444,7 +444,9 @@ void TextureCacheGLES::ApplyTextureFramebuffer(TexCacheEntry *entry, VirtualFram uint32_t clutMode = gstate.clutformat & 0xFFFFFF; bool useShaderDepal = framebufferManager_->GetCurrentRenderVFB() != framebuffer && gstate_c.Supports(GPU_SUPPORTS_GLSL_ES_300); - + if (!gstate_c.Supports(GPU_SUPPORTS_32BIT_INT_FSHADER)) { + useShaderDepal = false; + } if ((entry->status & TexCacheEntry::STATUS_DEPALETTIZE) && !g_Config.bDisableSlowFramebufEffects) { if (useShaderDepal) { const GEPaletteFormat clutFormat = gstate.getClutPaletteFormat(); diff --git a/GPU/GPUState.h b/GPU/GPUState.h index a73023927f..c2f61dcc5a 100644 --- a/GPU/GPUState.h +++ b/GPU/GPUState.h @@ -466,7 +466,6 @@ enum { GPU_SUPPORTS_DUALSOURCE_BLEND = FLAG_BIT(0), GPU_SUPPORTS_GLSL_ES_300 = FLAG_BIT(1), GPU_SUPPORTS_GLSL_330 = FLAG_BIT(2), - GPU_SUPPORTS_UNPACK_SUBIMAGE = FLAG_BIT(3), GPU_SUPPORTS_BLEND_MINMAX = FLAG_BIT(4), GPU_SUPPORTS_LOGIC_OP = FLAG_BIT(5), GPU_USE_DEPTH_RANGE_HACK = FLAG_BIT(6), @@ -478,6 +477,7 @@ enum { GPU_SUPPORTS_TEXTURE_FLOAT = FLAG_BIT(12), GPU_SUPPORTS_16BIT_FORMATS = FLAG_BIT(13), GPU_SUPPORTS_DEPTH_CLAMP = FLAG_BIT(14), + GPU_SUPPORTS_32BIT_INT_FSHADER = FLAG_BIT(15), GPU_SUPPORTS_LARGE_VIEWPORTS = FLAG_BIT(16), GPU_SUPPORTS_ACCURATE_DEPTH = FLAG_BIT(17), GPU_SUPPORTS_VAO = FLAG_BIT(18), diff --git a/UI/DevScreens.cpp b/UI/DevScreens.cpp index 12d1ee1e14..e6e3babc20 100644 --- a/UI/DevScreens.cpp +++ b/UI/DevScreens.cpp @@ -405,6 +405,13 @@ void SystemInfoScreen::CreateViews() { #endif if (GetGPUBackend() == GPUBackend::OPENGL) { deviceSpecs->Add(new InfoItem(si->T("Core Context"), gl_extensions.IsCoreContext ? di->T("Active") : di->T("Inactive"))); + int highp_int_min = gl_extensions.range[1][5][0]; + int highp_int_max = gl_extensions.range[1][5][1]; + if (highp_int_max != 0) { + char highp_int_range[512]; + snprintf(highp_int_range, sizeof(highp_int_range), "Highp int range: %d-%d", highp_int_min, highp_int_max); + deviceSpecs->Add(new InfoItem(si->T("High precision int range"), highp_int_range)); + } } deviceSpecs->Add(new ItemHeader(si->T("OS Information"))); deviceSpecs->Add(new InfoItem(si->T("Memory Page Size"), StringFromFormat(si->T("%d bytes"), GetMemoryProtectPageSize()))); diff --git a/ext/native/gfx/gl_debug_log.h b/ext/native/gfx/gl_debug_log.h index ae22ab1700..59f87e0842 100644 --- a/ext/native/gfx/gl_debug_log.h +++ b/ext/native/gfx/gl_debug_log.h @@ -6,7 +6,7 @@ // Utility to be able to liberally sprinkle GL error checks around your code // and easily disable them all in release builds - just undefine DEBUG_OPENGL. -// #define DEBUG_OPENGL +#define DEBUG_OPENGL #if defined(DEBUG_OPENGL) diff --git a/ext/native/gfx_es2/gpu_features.cpp b/ext/native/gfx_es2/gpu_features.cpp index 8bd8dc14aa..fab660781d 100644 --- a/ext/native/gfx_es2/gpu_features.cpp +++ b/ext/native/gfx_es2/gpu_features.cpp @@ -463,6 +463,13 @@ void CheckGLExtensions() { glGetShaderPrecisionFormat(shaderTypes[st], precisions[p], gl_extensions.range[st][p], &gl_extensions.precision[st][p]); } } + + // Now, Adreno lies. So let's override it. + if (gl_extensions.gpuVendor == GPU_VENDOR_QUALCOMM) { + WLOG("Detected Adreno - lowering int precision"); + gl_extensions.range[1][5][0] = 15; + gl_extensions.range[1][5][1] = 15; + } } #endif diff --git a/ext/native/thin3d/GLQueueRunner.cpp b/ext/native/thin3d/GLQueueRunner.cpp index 6d123518e3..bd6bc6bb6b 100644 --- a/ext/native/thin3d/GLQueueRunner.cpp +++ b/ext/native/thin3d/GLQueueRunner.cpp @@ -776,6 +776,7 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step) { } case GLRRenderCommand::UNIFORM4F: { + CHECK_GL_ERROR_IF_DEBUG(); int loc = c.uniform4.loc ? *c.uniform4.loc : -1; if (c.uniform4.name) { loc = curProgram->GetUniformLoc(c.uniform4.name); diff --git a/ext/native/thin3d/GLRenderManager.h b/ext/native/thin3d/GLRenderManager.h index 4c3c32b13d..932bb9db93 100644 --- a/ext/native/thin3d/GLRenderManager.h +++ b/ext/native/thin3d/GLRenderManager.h @@ -640,6 +640,7 @@ public: data.uniform4.loc = loc; data.uniform4.count = count; memcpy(data.uniform4.v, udata, sizeof(float) * count); + curRenderStep_->commands.push_back(data); } From 81b781fd4f85606da8f9597fd4878c11e78f88fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sat, 20 Oct 2018 13:25:53 +0200 Subject: [PATCH 2/3] Revert two accidental minor changes --- ext/native/thin3d/GLQueueRunner.cpp | 1 - ext/native/thin3d/GLRenderManager.h | 1 - 2 files changed, 2 deletions(-) diff --git a/ext/native/thin3d/GLQueueRunner.cpp b/ext/native/thin3d/GLQueueRunner.cpp index bd6bc6bb6b..6d123518e3 100644 --- a/ext/native/thin3d/GLQueueRunner.cpp +++ b/ext/native/thin3d/GLQueueRunner.cpp @@ -776,7 +776,6 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step) { } case GLRRenderCommand::UNIFORM4F: { - CHECK_GL_ERROR_IF_DEBUG(); int loc = c.uniform4.loc ? *c.uniform4.loc : -1; if (c.uniform4.name) { loc = curProgram->GetUniformLoc(c.uniform4.name); diff --git a/ext/native/thin3d/GLRenderManager.h b/ext/native/thin3d/GLRenderManager.h index 932bb9db93..4c3c32b13d 100644 --- a/ext/native/thin3d/GLRenderManager.h +++ b/ext/native/thin3d/GLRenderManager.h @@ -640,7 +640,6 @@ public: data.uniform4.loc = loc; data.uniform4.count = count; memcpy(data.uniform4.v, udata, sizeof(float) * count); - curRenderStep_->commands.push_back(data); } From ca58bb78dd77b136d09c3cba29673fb84f467088 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sat, 20 Oct 2018 16:48:17 +0200 Subject: [PATCH 3/3] Turn off gl debug logging again --- ext/native/gfx/gl_debug_log.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/native/gfx/gl_debug_log.h b/ext/native/gfx/gl_debug_log.h index 59f87e0842..ae22ab1700 100644 --- a/ext/native/gfx/gl_debug_log.h +++ b/ext/native/gfx/gl_debug_log.h @@ -6,7 +6,7 @@ // Utility to be able to liberally sprinkle GL error checks around your code // and easily disable them all in release builds - just undefine DEBUG_OPENGL. -#define DEBUG_OPENGL +// #define DEBUG_OPENGL #if defined(DEBUG_OPENGL)