From a71be3f75f5d74f2c9ecf6f6da771568a828c5aa Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Sat, 5 Sep 2015 19:58:47 +0200 Subject: [PATCH 01/12] Start moving GPU feature compatibility decisions to startup (and a single, cache-friendly flag field) --- GPU/GLES/FragmentShaderGenerator.cpp | 54 ++++++++++++++-------------- GPU/GLES/Framebuffer.cpp | 28 +++------------ GPU/GLES/Framebuffer.h | 2 -- GPU/GLES/GLES_GPU.cpp | 52 +++++++++++++++++++++++++++ GPU/GLES/GLES_GPU.h | 3 ++ GPU/GLES/ShaderManager.cpp | 2 +- GPU/GLES/StateMapping.cpp | 2 +- GPU/GPUState.h | 17 +++++++++ 8 files changed, 107 insertions(+), 53 deletions(-) diff --git a/GPU/GLES/FragmentShaderGenerator.cpp b/GPU/GLES/FragmentShaderGenerator.cpp index f44a282513..c105d90c20 100644 --- a/GPU/GLES/FragmentShaderGenerator.cpp +++ b/GPU/GLES/FragmentShaderGenerator.cpp @@ -156,7 +156,7 @@ ReplaceAlphaType ReplaceAlphaWithStencil(ReplaceBlendType replaceBlend) { if (nonAlphaSrcFactors[gstate.getBlendFuncA()] && nonAlphaDestFactors[gstate.getBlendFuncB()]) { return REPLACE_ALPHA_YES; } else { - if (gl_extensions.ARB_blend_func_extended) { + if (gstate_c.featureFlags & GPU_SUPPORTS_DUALSOURCE_BLEND) { return REPLACE_ALPHA_DUALSOURCE; } else { return REPLACE_ALPHA_NO; @@ -285,7 +285,7 @@ ReplaceBlendType ReplaceBlendWithShader(bool allowShaderBlend) { case GE_DSTBLEND_DOUBLEINVSRCALPHA: // We can't technically do this correctly (due to clamping) without reading the dst color. // Using a copy isn't accurate either, though, when there's overlap. - if (gl_extensions.ANY_shader_framebuffer_fetch) + if (gstate_c.featureFlags & GPU_SUPPORTS_ANY_FRAMEBUFFER_FETCH) return !allowShaderBlend ? REPLACE_BLEND_PRE_SRC_2X_ALPHA : REPLACE_BLEND_COPY_FBO; return REPLACE_BLEND_PRE_SRC_2X_ALPHA; @@ -344,14 +344,14 @@ ReplaceBlendType ReplaceBlendWithShader(bool allowShaderBlend) { case GE_DSTBLEND_DOUBLEINVSRCALPHA: if (funcA == GE_SRCBLEND_SRCALPHA || funcA == GE_SRCBLEND_INVSRCALPHA) { // Can't safely double alpha, will clamp. However, a copy may easily be worse due to overlap. - if (gl_extensions.ANY_shader_framebuffer_fetch) + if (gstate_c.featureFlags & GPU_SUPPORTS_ANY_FRAMEBUFFER_FETCH) return !allowShaderBlend ? REPLACE_BLEND_PRE_SRC_2X_ALPHA : REPLACE_BLEND_COPY_FBO; return REPLACE_BLEND_PRE_SRC_2X_ALPHA; } else { // This means dst alpha/color is used in the src factor. // Unfortunately, copying here causes overlap problems in Silent Hill games (it seems?) // We will just hope that doubling alpha for the dst factor will not clamp too badly. - if (gl_extensions.ANY_shader_framebuffer_fetch) + if (gstate_c.featureFlags & GPU_SUPPORTS_ANY_FRAMEBUFFER_FETCH) return !allowShaderBlend ? REPLACE_BLEND_2X_ALPHA : REPLACE_BLEND_COPY_FBO; return REPLACE_BLEND_2X_ALPHA; } @@ -426,14 +426,14 @@ void ComputeFragmentShaderID(ShaderID *id) { id0 |= (doTextureAlpha & 1) << 5; // rgb or rgba id0 |= (gstate_c.flipTexture & 1) << 6; - if (gstate_c.needShaderTexClamp) { - bool textureAtOffset = gstate_c.curTextureXOffset != 0 || gstate_c.curTextureYOffset != 0; - // 3 bits total. - id0 |= 1 << 7; - id0 |= gstate.isTexCoordClampedS() << 8; - id0 |= gstate.isTexCoordClampedT() << 9; - id0 |= (textureAtOffset & 1) << 10; - } +if (gstate_c.needShaderTexClamp) { + bool textureAtOffset = gstate_c.curTextureXOffset != 0 || gstate_c.curTextureYOffset != 0; + // 3 bits total. + id0 |= 1 << 7; + id0 |= gstate.isTexCoordClampedS() << 8; + id0 |= gstate.isTexCoordClampedT() << 9; + id0 |= (textureAtOffset & 1) << 10; +} } id0 |= (lmode & 1) << 11; @@ -456,7 +456,7 @@ void ComputeFragmentShaderID(ShaderID *id) { id0 |= (enableColorDoubling & 1) << 23; // 2 bits id0 |= (stencilToAlpha) << 24; - + if (stencilToAlpha != REPLACE_ALPHA_NO) { // 4 bits id0 |= ReplaceAlphaWithStencilType() << 26; @@ -504,7 +504,7 @@ void GenerateFragmentShader(char *buffer) { #if defined(USING_GLES2) // Let's wait until we have a real use for this. // ES doesn't support dual source alpha :( - if (gl_extensions.GLES3) { + if (gstate_c.featureFlags & GPU_SUPPORTS_GLSL_ES_300) { WRITE(p, "#version 300 es\n"); // GLSL ES 3.0 fragColor0 = "fragColor0"; texture = "texture"; @@ -525,16 +525,18 @@ void GenerateFragmentShader(char *buffer) { highpFog = (gl_extensions.bugs & BUG_PVR_SHADER_PRECISION_BAD) ? true : false; highpTexcoord = highpFog; - if (gl_extensions.EXT_shader_framebuffer_fetch) { - WRITE(p, "#extension GL_EXT_shader_framebuffer_fetch : require\n"); - lastFragData = "gl_LastFragData[0]"; - } else if (gl_extensions.NV_shader_framebuffer_fetch) { - // GL_NV_shader_framebuffer_fetch is available on mobile platform and ES 2.0 only but not on desktop. - WRITE(p, "#extension GL_NV_shader_framebuffer_fetch : require\n"); - lastFragData = "gl_LastFragData[0]"; - } else if (gl_extensions.ARM_shader_framebuffer_fetch) { - WRITE(p, "#extension GL_ARM_shader_framebuffer_fetch : require\n"); - lastFragData = "gl_LastFragColorARM"; + if (gstate_c.featureFlags & GPU_SUPPORTS_ANY_FRAMEBUFFER_FETCH) { + if (gl_extensions.EXT_shader_framebuffer_fetch) { + WRITE(p, "#extension GL_EXT_shader_framebuffer_fetch : require\n"); + lastFragData = "gl_LastFragData[0]"; + } else if (gl_extensions.NV_shader_framebuffer_fetch) { + // GL_NV_shader_framebuffer_fetch is available on mobile platform and ES 2.0 only but not on desktop. + WRITE(p, "#extension GL_NV_shader_framebuffer_fetch : require\n"); + lastFragData = "gl_LastFragData[0]"; + } else if (gl_extensions.ARM_shader_framebuffer_fetch) { + WRITE(p, "#extension GL_ARM_shader_framebuffer_fetch : require\n"); + lastFragData = "gl_LastFragColorARM"; + } } WRITE(p, "precision lowp float;\n"); @@ -611,7 +613,7 @@ void GenerateFragmentShader(char *buffer) { if (doTexture) WRITE(p, "uniform sampler2D tex;\n"); if (!gstate.isModeClear() && replaceBlend > REPLACE_BLEND_STANDARD) { - if (!gl_extensions.ANY_shader_framebuffer_fetch && replaceBlend == REPLACE_BLEND_COPY_FBO) { + if (!(gstate_c.featureFlags & GPU_SUPPORTS_ANY_FRAMEBUFFER_FETCH) && replaceBlend == REPLACE_BLEND_COPY_FBO) { if (!texelFetch) { WRITE(p, "uniform vec2 u_fbotexSize;\n"); } @@ -962,7 +964,7 @@ void GenerateFragmentShader(char *buffer) { if (replaceBlend == REPLACE_BLEND_COPY_FBO) { // If we have NV_shader_framebuffer_fetch / EXT_shader_framebuffer_fetch, we skip the blit. // We can just read the prev value more directly. - if (gl_extensions.ANY_shader_framebuffer_fetch) { + if (gstate_c.featureFlags & GPU_SUPPORTS_ANY_FRAMEBUFFER_FETCH) { WRITE(p, " lowp vec4 destColor = %s;\n", lastFragData); } else if (!texelFetch) { WRITE(p, " lowp vec4 destColor = %s(fbotex, gl_FragCoord.xy * u_fbotexSize.xy);\n", texture); diff --git a/GPU/GLES/Framebuffer.cpp b/GPU/GLES/Framebuffer.cpp index 1908a25682..d02e0a1145 100644 --- a/GPU/GLES/Framebuffer.cpp +++ b/GPU/GLES/Framebuffer.cpp @@ -1128,24 +1128,6 @@ void FramebufferManager::CopyDisplayToOutput() { } } -inline bool FramebufferManager::ShouldDownloadUsingCPU(const VirtualFramebuffer *vfb) const { -#ifndef USING_GLES2 - bool useCPU = g_Config.iRenderingMode == FB_READFBOMEMORY_CPU; - // We might get here if hackForce04154000Download_ is hit. - // Some cards or drivers seem to always dither when downloading a framebuffer to 16-bit. - // This causes glitches in games that expect the exact values. - // It has not been experienced on NVIDIA cards, so those are left using the GPU (which is faster.) - if (g_Config.iRenderingMode == FB_BUFFERED_MODE) { - if (gl_extensions.gpuVendor != GPU_VENDOR_NVIDIA || gl_extensions.ver[0] < 3) { - useCPU = true; - } - } - return useCPU; -#else - return true; -#endif -} - void FramebufferManager::ReadFramebufferToMemory(VirtualFramebuffer *vfb, bool sync, int x, int y, int w, int h) { PROFILE_THIS_SCOPE("gpu-readback"); #ifndef USING_GLES2 @@ -1212,7 +1194,7 @@ void FramebufferManager::ReadFramebufferToMemory(VirtualFramebuffer *vfb, bool s nvfb->colorDepth = FBO_8888; break; } - if (ShouldDownloadUsingCPU(vfb)) { + if (gstate_c.Supports(GPU_PREFER_CPU_DOWNLOAD)) { nvfb->colorDepth = vfb->colorDepth; } @@ -1309,12 +1291,12 @@ void FramebufferManager::BlitFramebuffer(VirtualFramebuffer *dst, int dstX, int bool useNV = false; #ifndef USING_GLES2 - if (gl_extensions.FBO_ARB) { + if (gstate_c.Supports(GPU_SUPPORTS_FBO_ARB)) { useNV = false; useBlit = true; } #else - if (gl_extensions.GLES3 || gl_extensions.NV_framebuffer_blit) { + if (gl_extensions.GLES3 || (gstate_c..Supports(GPU_SUPPORTS_NV_FRAMEBUFFER_BLIT)) { useNV = !gl_extensions.GLES3; useBlit = true; } @@ -1497,7 +1479,7 @@ void FramebufferManager::PackFramebufferAsync_(VirtualFramebuffer *vfb) { GLubyte *packed = 0; bool unbind = false; const u8 nextPBO = (currentPBO_ + 1) % MAX_PBO; - const bool useCPU = ShouldDownloadUsingCPU(vfb); + const bool useCPU = gstate_c.Supports(GPU_PREFER_CPU_DOWNLOAD); // We'll prepare two PBOs to switch between readying and reading if (!pixelBufObj_) { @@ -1541,7 +1523,7 @@ void FramebufferManager::PackFramebufferAsync_(VirtualFramebuffer *vfb) { if (vfb) { int pixelType, pixelSize, pixelFormat, align; - bool reverseOrder = (gl_extensions.gpuVendor == GPU_VENDOR_NVIDIA) || (gl_extensions.gpuVendor == GPU_VENDOR_AMD); + bool reverseOrder = gstate_c.Supports(GPU_PREFER_REVERSE_COLOR_ORDER); switch (vfb->format) { // GL_UNSIGNED_INT_8_8_8_8 returns A B G R (little-endian, tested in Nvidia card/x86 PC) // GL_UNSIGNED_BYTE returns R G B A in consecutive bytes ("big-endian"/not treated as 32-bit value) diff --git a/GPU/GLES/Framebuffer.h b/GPU/GLES/Framebuffer.h index 27b784807f..ee371cbcdc 100644 --- a/GPU/GLES/Framebuffer.h +++ b/GPU/GLES/Framebuffer.h @@ -145,8 +145,6 @@ private: void SetNumExtraFBOs(int num); - inline bool ShouldDownloadUsingCPU(const VirtualFramebuffer *vfb) const; - #ifndef USING_GLES2 void PackFramebufferAsync_(VirtualFramebuffer *vfb); #endif diff --git a/GPU/GLES/GLES_GPU.cpp b/GPU/GLES/GLES_GPU.cpp index 41a2616281..cf33f6e4dd 100644 --- a/GPU/GLES/GLES_GPU.cpp +++ b/GPU/GLES/GLES_GPU.cpp @@ -396,6 +396,7 @@ GLES_GPU::CommandInfo GLES_GPU::cmdInfo_[256]; GLES_GPU::GLES_GPU() : resized_(false) { UpdateVsyncInterval(true); + CheckGPUFeatures(); shaderManager_ = new ShaderManager(); transformDraw_.SetShaderManager(shaderManager_); @@ -463,6 +464,57 @@ GLES_GPU::~GLES_GPU() { glstate.SetVSyncInterval(0); } +// Take the raw GL extension and versioning data and turn into feature flags. +void GLES_GPU::CheckGPUFeatures() { + u32 features = 0; + if (gl_extensions.ARB_blend_func_extended /*|| gl_extensions.EXT_blend_func_extended*/) + features |= GPU_SUPPORTS_DUALSOURCE_BLEND; + +#ifdef USING_GLES2 + if (gl_extensions.GLES3) + features |= GPU_SUPPORTS_GLSL_ES_300; +#else + if (gl_extensions.VersionGEThan(3, 3, 0)) + features |= GPU_SUPPORTS_GLSL_330; +#endif + // Framebuffer fetch appears to be buggy at least on Tegra 3 devices. So we blacklist it. + // Tales of Destiny 2 has been reported to display green. + if (gl_extensions.EXT_shader_framebuffer_fetch || gl_extensions.NV_shader_framebuffer_fetch || gl_extensions.ARM_shader_framebuffer_fetch) { + features |= GPU_SUPPORTS_ANY_FRAMEBUFFER_FETCH; + // Blacklist Tegra 3, doesn't work very well. + if (strstr(gl_extensions.model, "NVIDIA Tegra 3") != 0) { + features &= ~GPU_SUPPORTS_ANY_FRAMEBUFFER_FETCH; + } + } + + if (gl_extensions.FBO_ARB || gl_extensions.IsGLES) { + features |= GPU_SUPPORTS_FBO_ARB; + } + +#ifndef USING_GLES2 + bool useCPU = g_Config.iRenderingMode == FB_READFBOMEMORY_CPU; + // We might get here if hackForce04154000Download_ is hit. + // Some cards or drivers seem to always dither when downloading a framebuffer to 16-bit. + // This causes glitches in games that expect the exact values. + // It has not been experienced on NVIDIA cards, so those are left using the GPU (which is faster.) + if (g_Config.iRenderingMode == FB_BUFFERED_MODE) { + if (gl_extensions.gpuVendor != GPU_VENDOR_NVIDIA || gl_extensions.ver[0] < 3) { + useCPU = true; + } + } +#else + useCPU = true; +#endif + if (useCPU) { + features |= GPU_PREFER_CPU_DOWNLOAD; + } + + if ((gl_extensions.gpuVendor == GPU_VENDOR_NVIDIA) || (gl_extensions.gpuVendor == GPU_VENDOR_AMD)) + features |= GPU_PREFER_REVERSE_COLOR_ORDER; + + gstate_c.featureFlags = features; +} + // Let's avoid passing nulls into snprintf(). static const char *GetGLStringAlways(GLenum name) { const GLubyte *value = glGetString(name); diff --git a/GPU/GLES/GLES_GPU.h b/GPU/GLES/GLES_GPU.h index 052b409e96..178770837d 100644 --- a/GPU/GLES/GLES_GPU.h +++ b/GPU/GLES/GLES_GPU.h @@ -36,6 +36,9 @@ class GLES_GPU : public GPUCommon { public: GLES_GPU(); ~GLES_GPU(); + + void CheckGPUFeatures(); + void InitClear() override; void Reinitialize() override; void PreExecuteOp(u32 op, u32 diff) override; diff --git a/GPU/GLES/ShaderManager.cpp b/GPU/GLES/ShaderManager.cpp index 3216572d45..dc86026fec 100644 --- a/GPU/GLES/ShaderManager.cpp +++ b/GPU/GLES/ShaderManager.cpp @@ -103,7 +103,7 @@ LinkedShader::LinkedShader(Shader *vs, Shader *fs, u32 vertType, bool useHWTrans glBindAttribLocation(program, ATTR_COLOR1, "color1"); #ifndef USING_GLES2 - if (gl_extensions.ARB_blend_func_extended) { + if (gstate_c.featureFlags & GPU_SUPPORTS_DUALSOURCE_BLEND) { // Dual source alpha glBindFragDataLocationIndexed(program, 0, 0, "fragColor0"); glBindFragDataLocationIndexed(program, 0, 1, "fragColor1"); diff --git a/GPU/GLES/StateMapping.cpp b/GPU/GLES/StateMapping.cpp index 30aa49ebe4..bf46f1a4bc 100644 --- a/GPU/GLES/StateMapping.cpp +++ b/GPU/GLES/StateMapping.cpp @@ -168,7 +168,7 @@ static inline bool blendColorSimilar(const Vec3f &a, const Vec3f &b, float margi } bool TransformDrawEngine::ApplyShaderBlending() { - if (gl_extensions.ANY_shader_framebuffer_fetch) { + if (gstate_c.featureFlags & GPU_SUPPORTS_ANY_FRAMEBUFFER_FETCH) { return true; } diff --git a/GPU/GPUState.h b/GPU/GPUState.h index 8a65db7804..1e639e4f26 100644 --- a/GPU/GPUState.h +++ b/GPU/GPUState.h @@ -442,7 +442,24 @@ enum TextureChangeReason { TEXCHANGE_PARAMSONLY = 0x02, }; +#define FLAG_BIT(x) (1 << x) + +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_NV_FRAMEBUFFER_BLIT = FLAG_BIT(10), + GPU_SUPPORTS_ANY_FRAMEBUFFER_FETCH = FLAG_BIT(20), + GPU_SUPPORTS_FBO_ARB = FLAG_BIT(25), + GPU_PREFER_CPU_DOWNLOAD = FLAG_BIT(30), + GPU_PREFER_REVERSE_COLOR_ORDER = FLAG_BIT(31), +}; + struct GPUStateCache { + bool Supports(int flag) { return (featureFlags & flag) != 0; } + + u32 featureFlags; + u32 vertexAddr; u32 indexAddr; u32 offsetAddr; From f52404927773311a1643b938cb223717539eca4c Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Sat, 5 Sep 2015 21:23:58 +0200 Subject: [PATCH 02/12] Move more GPU feature checks upfront. Re-check when exiting settings menu. --- GPU/GLES/FragmentShaderGenerator.cpp | 2 +- GPU/GLES/Framebuffer.cpp | 2 +- GPU/GLES/Framebuffer.h | 2 + GPU/GLES/GLES_GPU.cpp | 63 ++++++++++++++++++---------- GPU/GLES/GLES_GPU.h | 1 + GPU/GLES/StateMapping.cpp | 2 +- GPU/GLES/TextureCache.cpp | 23 +++++----- GPU/GPUCommon.h | 2 + GPU/GPUInterface.h | 2 + GPU/GPUState.h | 4 ++ UI/EmuScreen.cpp | 1 + 11 files changed, 70 insertions(+), 34 deletions(-) diff --git a/GPU/GLES/FragmentShaderGenerator.cpp b/GPU/GLES/FragmentShaderGenerator.cpp index c105d90c20..3bab172e2f 100644 --- a/GPU/GLES/FragmentShaderGenerator.cpp +++ b/GPU/GLES/FragmentShaderGenerator.cpp @@ -253,7 +253,7 @@ ReplaceBlendType ReplaceBlendWithShader(bool allowShaderBlend) { case GE_BLENDMODE_MIN: case GE_BLENDMODE_MAX: - if (gl_extensions.EXT_blend_minmax || gl_extensions.GLES3) { + if (gstate_c.Supports(GPU_SUPPORTS_BLEND_MINMAX)) { return REPLACE_BLEND_STANDARD; } else { return !allowShaderBlend ? REPLACE_BLEND_STANDARD : REPLACE_BLEND_COPY_FBO; diff --git a/GPU/GLES/Framebuffer.cpp b/GPU/GLES/Framebuffer.cpp index d02e0a1145..533649965b 100644 --- a/GPU/GLES/Framebuffer.cpp +++ b/GPU/GLES/Framebuffer.cpp @@ -1296,7 +1296,7 @@ void FramebufferManager::BlitFramebuffer(VirtualFramebuffer *dst, int dstX, int useBlit = true; } #else - if (gl_extensions.GLES3 || (gstate_c..Supports(GPU_SUPPORTS_NV_FRAMEBUFFER_BLIT)) { + if (gl_extensions.GLES3 || gstate_c.Supports(GPU_SUPPORTS_NV_FRAMEBUFFER_BLIT)) { useNV = !gl_extensions.GLES3; useBlit = true; } diff --git a/GPU/GLES/Framebuffer.h b/GPU/GLES/Framebuffer.h index ee371cbcdc..27b784807f 100644 --- a/GPU/GLES/Framebuffer.h +++ b/GPU/GLES/Framebuffer.h @@ -145,6 +145,8 @@ private: void SetNumExtraFBOs(int num); + inline bool ShouldDownloadUsingCPU(const VirtualFramebuffer *vfb) const; + #ifndef USING_GLES2 void PackFramebufferAsync_(VirtualFramebuffer *vfb); #endif diff --git a/GPU/GLES/GLES_GPU.cpp b/GPU/GLES/GLES_GPU.cpp index cf33f6e4dd..c69fea9df6 100644 --- a/GPU/GLES/GLES_GPU.cpp +++ b/GPU/GLES/GLES_GPU.cpp @@ -21,6 +21,7 @@ #include "Common/ChunkFile.h" +#include "Core/Config.h" #include "Core/Debugger/Breakpoints.h" #include "Core/MemMapHelpers.h" #include "Core/Host.h" @@ -31,6 +32,7 @@ #include "GPU/GPUState.h" #include "GPU/ge_constants.h" #include "GPU/GeDisasm.h" +#include "GPU/Common/FramebufferCommon.h" #include "GPU/GLES/ShaderManager.h" #include "GPU/GLES/GLES_GPU.h" @@ -470,13 +472,14 @@ void GLES_GPU::CheckGPUFeatures() { if (gl_extensions.ARB_blend_func_extended /*|| gl_extensions.EXT_blend_func_extended*/) features |= GPU_SUPPORTS_DUALSOURCE_BLEND; -#ifdef USING_GLES2 - if (gl_extensions.GLES3) - features |= GPU_SUPPORTS_GLSL_ES_300; -#else - if (gl_extensions.VersionGEThan(3, 3, 0)) - features |= GPU_SUPPORTS_GLSL_330; -#endif + if (gl_extensions.IsGLES) { + if (gl_extensions.GLES3) + features |= GPU_SUPPORTS_GLSL_ES_300; + } else { + if (gl_extensions.VersionGEThan(3, 3, 0)) + features |= GPU_SUPPORTS_GLSL_330; + } + // Framebuffer fetch appears to be buggy at least on Tegra 3 devices. So we blacklist it. // Tales of Destiny 2 has been reported to display green. if (gl_extensions.EXT_shader_framebuffer_fetch || gl_extensions.NV_shader_framebuffer_fetch || gl_extensions.ARM_shader_framebuffer_fetch) { @@ -491,27 +494,45 @@ void GLES_GPU::CheckGPUFeatures() { features |= GPU_SUPPORTS_FBO_ARB; } + bool useCPU = false; + if (!gl_extensions.IsGLES) { + // Urrgh, we don't even define FB_READFBOMEMORY_CPU on mobile #ifndef USING_GLES2 - bool useCPU = g_Config.iRenderingMode == FB_READFBOMEMORY_CPU; - // We might get here if hackForce04154000Download_ is hit. - // Some cards or drivers seem to always dither when downloading a framebuffer to 16-bit. - // This causes glitches in games that expect the exact values. - // It has not been experienced on NVIDIA cards, so those are left using the GPU (which is faster.) - if (g_Config.iRenderingMode == FB_BUFFERED_MODE) { - if (gl_extensions.gpuVendor != GPU_VENDOR_NVIDIA || gl_extensions.ver[0] < 3) { - useCPU = true; - } - } -#else - useCPU = true; + useCPU = g_Config.iRenderingMode == FB_READFBOMEMORY_CPU; #endif - if (useCPU) { - features |= GPU_PREFER_CPU_DOWNLOAD; + // We might get here if hackForce04154000Download_ is hit. + // Some cards or drivers seem to always dither when downloading a framebuffer to 16-bit. + // This causes glitches in games that expect the exact values. + // It has not been experienced on NVIDIA cards, so those are left using the GPU (which is faster.) + if (g_Config.iRenderingMode == FB_BUFFERED_MODE) { + if (gl_extensions.gpuVendor != GPU_VENDOR_NVIDIA || gl_extensions.ver[0] < 3) { + useCPU = true; + } + } + } else { + useCPU = true; } + if (useCPU) + features |= GPU_PREFER_CPU_DOWNLOAD; + if ((gl_extensions.gpuVendor == GPU_VENDOR_NVIDIA) || (gl_extensions.gpuVendor == GPU_VENDOR_AMD)) features |= GPU_PREFER_REVERSE_COLOR_ORDER; + if (gl_extensions.OES_texture_npot) + features |= GPU_SUPPORTS_OES_TEXTURE_NPOT; + + if (gl_extensions.EXT_unpack_subimage || !gl_extensions.IsGLES) + features |= GPU_SUPPORTS_UNPACK_SUBIMAGE; + + if (gl_extensions.EXT_blend_minmax || gl_extensions.GLES3) + features |= GPU_SUPPORTS_BLEND_MINMAX; + +#ifdef MOBILE_DEVICE + // Arguably, we should turn off GPU_IS_MOBILE on like modern Tegras, etc. + features |= GPU_IS_MOBILE; +#endif + gstate_c.featureFlags = features; } diff --git a/GPU/GLES/GLES_GPU.h b/GPU/GLES/GLES_GPU.h index 178770837d..b2a97684e1 100644 --- a/GPU/GLES/GLES_GPU.h +++ b/GPU/GLES/GLES_GPU.h @@ -37,6 +37,7 @@ public: GLES_GPU(); ~GLES_GPU(); + // This gets called on startup and when we get back from settings. void CheckGPUFeatures(); void InitClear() override; diff --git a/GPU/GLES/StateMapping.cpp b/GPU/GLES/StateMapping.cpp index bf46f1a4bc..7c08adc418 100644 --- a/GPU/GLES/StateMapping.cpp +++ b/GPU/GLES/StateMapping.cpp @@ -567,7 +567,7 @@ void TransformDrawEngine::ApplyBlendState() { glstate.blendFuncSeparate.set(glBlendFuncA, glBlendFuncB, GL_ZERO, GL_ONE); } - if (gl_extensions.EXT_blend_minmax || gl_extensions.GLES3) { + if (gstate_c.Supports(GPU_SUPPORTS_BLEND_MINMAX)) { glstate.blendEquationSeparate.set(eqLookup[blendFuncEq], alphaEq); } else { glstate.blendEquationSeparate.set(eqLookupNoMinMax[blendFuncEq], alphaEq); diff --git a/GPU/GLES/TextureCache.cpp b/GPU/GLES/TextureCache.cpp index d953087a89..ff352ca552 100644 --- a/GPU/GLES/TextureCache.cpp +++ b/GPU/GLES/TextureCache.cpp @@ -66,6 +66,7 @@ #define GL_UNPACK_ROW_LENGTH 0x0CF2 #endif +// Hack! extern int g_iNumVideos; TextureCache::TextureCache() : cacheSizeEstimate_(0), secondCacheSizeEstimate_(0), clearCacheNextFrame_(false), lowMemoryMode_(false), clutBuf_(NULL), clutMaxBytes_(0), texelsScaledThisFrame_(0) { @@ -1446,14 +1447,15 @@ void TextureCache::SetTexture(bool force) { scaleFactor = (PSP_CoreParameter().renderWidth + 479) / 480; } -#ifndef MOBILE_DEVICE - scaleFactor = std::min(gl_extensions.OES_texture_npot ? 5 : 4, scaleFactor); - if (!gl_extensions.OES_texture_npot && scaleFactor == 3) { - scaleFactor = 2; + // Mobile devices don't get the higher scale factors, too expensive. Very rough way to decide though... + if (!gstate_c.Supports(GPU_IS_MOBILE)) { + scaleFactor = std::min(gstate_c.Supports(GPU_SUPPORTS_OES_TEXTURE_NPOT) ? 5 : 4, scaleFactor); + if (!gl_extensions.OES_texture_npot && scaleFactor == 3) { + scaleFactor = 2; + } + } else { + scaleFactor = std::min(gstate_c.Supports(GPU_SUPPORTS_OES_TEXTURE_NPOT) ? 3 : 2, scaleFactor); } -#else - scaleFactor = std::min(gl_extensions.OES_texture_npot ? 3 : 2, scaleFactor); -#endif } else { scaleFactor = g_Config.iTexScalingLevel; } @@ -1698,7 +1700,7 @@ void *TextureCache::DecodeTextureLevel(GETextureFormat format, GEPaletteFormat c case GE_TFMT_8888: if (!swizzled) { // Special case: if we don't need to deal with packing, we don't need to copy. - if ((g_Config.iTexScalingLevel == 1 && gl_extensions.EXT_unpack_subimage) || w == bufw) { + if ((g_Config.iTexScalingLevel == 1 && gstate_c.Supports(GPU_SUPPORTS_UNPACK_SUBIMAGE)) || w == bufw) { if (UseBGRA8888()) { tmpTexBuf32.resize(std::max(bufw, w) * h); finalBuf = tmpTexBuf32.data(); @@ -1791,7 +1793,7 @@ void *TextureCache::DecodeTextureLevel(GETextureFormat format, GEPaletteFormat c ERROR_LOG_REPORT(G3D, "NO finalbuf! Will crash!"); } - if (!(g_Config.iTexScalingLevel == 1 && gl_extensions.EXT_unpack_subimage) && w != bufw) { + if (!(g_Config.iTexScalingLevel == 1 && gstate_c.Supports(GPU_SUPPORTS_UNPACK_SUBIMAGE)) && w != bufw) { int pixelSize; switch (dstFmt) { case GL_UNSIGNED_SHORT_4_4_4_4: @@ -1803,6 +1805,7 @@ void *TextureCache::DecodeTextureLevel(GETextureFormat format, GEPaletteFormat c pixelSize = 4; break; } + // Need to rearrange the buffer to simulate GL_UNPACK_ROW_LENGTH etc. int inRowBytes = bufw * pixelSize; int outRowBytes = w * pixelSize; @@ -1868,7 +1871,7 @@ void TextureCache::LoadTextureLevel(TexCacheEntry &entry, int level, bool replac gpuStats.numTexturesDecoded++; // Can restore these and remove the fixup at the end of DecodeTextureLevel on desktop GL and GLES 3. - if ((g_Config.iTexScalingLevel == 1 && gl_extensions.EXT_unpack_subimage) && w != bufw) { + if ((g_Config.iTexScalingLevel == 1 && gstate_c.Supports(GPU_SUPPORTS_UNPACK_SUBIMAGE)) && w != bufw) { glPixelStorei(GL_UNPACK_ROW_LENGTH, bufw); useUnpack = true; } diff --git a/GPU/GPUCommon.h b/GPU/GPUCommon.h index cc60d15080..6ead754b81 100644 --- a/GPU/GPUCommon.h +++ b/GPU/GPUCommon.h @@ -18,6 +18,8 @@ class GPUCommon : public GPUThreadEventQueue, public GPUDebugInterface { public: GPUCommon(); virtual ~GPUCommon(); + + virtual void CheckGPUFeatures() override {} virtual void Reinitialize(); virtual void InterruptStart(int listid); diff --git a/GPU/GPUInterface.h b/GPU/GPUInterface.h index 15a57fed3c..9af5d02ba0 100644 --- a/GPU/GPUInterface.h +++ b/GPU/GPUInterface.h @@ -207,6 +207,8 @@ public: static const int DisplayListMaxCount = 64; + virtual void CheckGPUFeatures() = 0; + // Initialization virtual void InitClear() = 0; virtual void Reinitialize() = 0; diff --git a/GPU/GPUState.h b/GPU/GPUState.h index 1e639e4f26..e70fbb48c1 100644 --- a/GPU/GPUState.h +++ b/GPU/GPUState.h @@ -448,9 +448,13 @@ 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_NV_FRAMEBUFFER_BLIT = FLAG_BIT(10), GPU_SUPPORTS_ANY_FRAMEBUFFER_FETCH = FLAG_BIT(20), GPU_SUPPORTS_FBO_ARB = FLAG_BIT(25), + GPU_SUPPORTS_OES_TEXTURE_NPOT = FLAG_BIT(26), + GPU_IS_MOBILE = FLAG_BIT(29), GPU_PREFER_CPU_DOWNLOAD = FLAG_BIT(30), GPU_PREFER_REVERSE_COLOR_ORDER = FLAG_BIT(31), }; diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index 8b2db8bdc0..2bbc151f21 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -180,6 +180,7 @@ void EmuScreen::dialogFinished(const Screen *dialog, DialogResult result) { quit_ = false; } RecreateViews(); + gpu->CheckGPUFeatures(); } static void AfterStateLoad(bool success, void *ignored) { From 5b2ffd14349fcc42690090e51f05ea6913cf4542 Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Sat, 5 Sep 2015 22:11:28 +0200 Subject: [PATCH 03/12] Fix some naming, remove NV_draw_texture, move decisions out --- GPU/GLES/Framebuffer.cpp | 21 ++---- GPU/GLES/GLES_GPU.cpp | 16 ++++- GPU/GLES/StateMapping.cpp | 129 +++++++++++++++++++------------------ GPU/GLES/StencilBuffer.cpp | 2 +- GPU/GPUState.h | 3 + native | 2 +- 6 files changed, 90 insertions(+), 83 deletions(-) diff --git a/GPU/GLES/Framebuffer.cpp b/GPU/GLES/Framebuffer.cpp index 533649965b..288592306a 100644 --- a/GPU/GLES/Framebuffer.cpp +++ b/GPU/GLES/Framebuffer.cpp @@ -520,20 +520,7 @@ void FramebufferManager::DrawActiveTexture(GLuint texture, float x, float y, flo } if (texture) { - // We know the texture, we can do a DrawTexture shortcut on nvidia. -#if defined(ANDROID) - // Don't remember why I disabled this - no win? - if (false && gl_extensions.NV_draw_texture && !program) { - // Fast path for Tegra. TODO: Make this path work on desktop nvidia, seems GLEW doesn't have a clue. - // Actually, on Desktop we should just use glBlitFramebuffer - although we take a texture here - // so that's a little gnarly, will have to modify all callers. - glDrawTextureNV(texture, 0, - x, y, w, h, 0.0f, - u0, v1, u1, v0); - return; - } -#endif - + // Previously had NVDrawTexture fallback here but wasn't worth it. glBindTexture(GL_TEXTURE_2D, texture); } @@ -832,7 +819,7 @@ void FramebufferManager::BlitFramebufferDepth(VirtualFramebuffer *src, VirtualFr src->renderHeight == dst->renderHeight) { #ifndef USING_GLES2 - if (gl_extensions.FBO_ARB) { + if (gl_extensions.ARB_framebuffer_object) { bool useNV = false; #else if (gl_extensions.GLES3 || gl_extensions.NV_framebuffer_blit) { @@ -1263,7 +1250,7 @@ void FramebufferManager::ReadFramebufferToMemory(VirtualFramebuffer *vfb, bool s #ifdef USING_GLES2 PackFramebufferSync_(nvfb, x, y, w, h); #else - if (gl_extensions.PBO_ARB && gl_extensions.OES_texture_npot) { + if (gl_extensions.ARB_pixel_buffer_object && gl_extensions.OES_texture_npot) { if (!sync) { PackFramebufferAsync_(nvfb); } else { @@ -1569,7 +1556,7 @@ void FramebufferManager::PackFramebufferAsync_(VirtualFramebuffer *vfb) { GLenum fbStatus; #ifndef USING_GLES2 - if (!gl_extensions.FBO_ARB) { + if (!gl_extensions.ARB_framebuffer_object) { fbStatus = glCheckFramebufferStatusEXT(GL_READ_FRAMEBUFFER); } else { fbStatus = glCheckFramebufferStatus(GL_READ_FRAMEBUFFER); diff --git a/GPU/GLES/GLES_GPU.cpp b/GPU/GLES/GLES_GPU.cpp index c69fea9df6..04d9837690 100644 --- a/GPU/GLES/GLES_GPU.cpp +++ b/GPU/GLES/GLES_GPU.cpp @@ -469,8 +469,14 @@ GLES_GPU::~GLES_GPU() { // Take the raw GL extension and versioning data and turn into feature flags. void GLES_GPU::CheckGPUFeatures() { u32 features = 0; - if (gl_extensions.ARB_blend_func_extended /*|| gl_extensions.EXT_blend_func_extended*/) - features |= GPU_SUPPORTS_DUALSOURCE_BLEND; + if (gl_extensions.ARB_blend_func_extended /*|| gl_extensions.EXT_blend_func_extended*/) { + if (gl_extensions.gpuVendor == GPU_VENDOR_INTEL || !gl_extensions.VersionGEThan(3, 0, 0)) { + // Don't use this extension to off on sub 3.0 OpenGL versions as it does not seem reliable + // Also on Intel, see https://github.com/hrydgard/ppsspp/issues/4867 + } else { + features |= GPU_SUPPORTS_DUALSOURCE_BLEND; + } + } if (gl_extensions.IsGLES) { if (gl_extensions.GLES3) @@ -490,7 +496,8 @@ void GLES_GPU::CheckGPUFeatures() { } } - if (gl_extensions.FBO_ARB || gl_extensions.IsGLES) { + // Note: there's a lie going on in the codebase about what ARB_FBO really is. It's not equal to the FBO in ES 2.0. + if (gl_extensions.ARB_framebuffer_object) { features |= GPU_SUPPORTS_FBO_ARB; } @@ -528,6 +535,9 @@ void GLES_GPU::CheckGPUFeatures() { if (gl_extensions.EXT_blend_minmax || gl_extensions.GLES3) features |= GPU_SUPPORTS_BLEND_MINMAX; + if (!gl_extensions.IsGLES) + features |= GPU_SUPPORTS_LOGIC_OP; + #ifdef MOBILE_DEVICE // Arguably, we should turn off GPU_IS_MOBILE on like modern Tegras, etc. features |= GPU_IS_MOBILE; diff --git a/GPU/GLES/StateMapping.cpp b/GPU/GLES/StateMapping.cpp index 7c08adc418..533da787f0 100644 --- a/GPU/GLES/StateMapping.cpp +++ b/GPU/GLES/StateMapping.cpp @@ -212,6 +212,7 @@ inline void TransformDrawEngine::ResetShaderBlending() { } } +// Try to simulate some common logic ops. void TransformDrawEngine::ApplyStencilReplaceAndLogicOp(ReplaceAlphaType replaceAlphaWithStencil) { StencilValueType stencilType = STENCIL_VALUE_KEEP; if (replaceAlphaWithStencil == REPLACE_ALPHA_YES) { @@ -222,59 +223,60 @@ void TransformDrawEngine::ApplyStencilReplaceAndLogicOp(ReplaceAlphaType replace GLenum srcBlend = GL_ONE; GLenum dstBlend = GL_ZERO; GLenum blendOp = GL_FUNC_ADD; -#if defined(USING_GLES2) - if (gstate.isLogicOpEnabled()) { - switch (gstate.getLogicOp()) - { - case GE_LOGIC_CLEAR: - srcBlend = GL_ZERO; - break; - case GE_LOGIC_AND: - case GE_LOGIC_AND_REVERSE: - WARN_LOG_REPORT_ONCE(d3dLogicOpAnd, G3D, "Unsupported AND logic op: %x", gstate.getLogicOp()); - break; - case GE_LOGIC_COPY: - // This is the same as off. - break; - case GE_LOGIC_COPY_INVERTED: - // Handled in the shader. - break; - case GE_LOGIC_AND_INVERTED: - case GE_LOGIC_NOR: - case GE_LOGIC_NAND: - case GE_LOGIC_EQUIV: - // Handled in the shader. - WARN_LOG_REPORT_ONCE(d3dLogicOpAndInverted, G3D, "Attempted invert for logic op: %x", gstate.getLogicOp()); - break; - case GE_LOGIC_INVERTED: - srcBlend = GL_ONE; - dstBlend = GL_ONE; - blendOp = GL_FUNC_SUBTRACT; - WARN_LOG_REPORT_ONCE(d3dLogicOpInverted, G3D, "Attempted inverse for logic op: %x", gstate.getLogicOp()); - break; - case GE_LOGIC_NOOP: - srcBlend = GL_ZERO; - dstBlend = GL_ONE; - break; - case GE_LOGIC_XOR: - WARN_LOG_REPORT_ONCE(d3dLogicOpOrXor, G3D, "Unsupported XOR logic op: %x", gstate.getLogicOp()); - break; - case GE_LOGIC_OR: - case GE_LOGIC_OR_INVERTED: - // Inverted in shader. - dstBlend = GL_ONE; - WARN_LOG_REPORT_ONCE(d3dLogicOpOr, G3D, "Attempted or for logic op: %x", gstate.getLogicOp()); - break; - case GE_LOGIC_OR_REVERSE: - WARN_LOG_REPORT_ONCE(d3dLogicOpOrReverse, G3D, "Unsupported OR REVERSE logic op: %x", gstate.getLogicOp()); - break; - case GE_LOGIC_SET: - dstBlend = GL_ONE; - WARN_LOG_REPORT_ONCE(d3dLogicOpSet, G3D, "Attempted set for logic op: %x", gstate.getLogicOp()); - break; + + if (!gstate_c.Supports(GPU_SUPPORTS_LOGIC_OP)) { + if (gstate.isLogicOpEnabled()) { + switch (gstate.getLogicOp()) + { + case GE_LOGIC_CLEAR: + srcBlend = GL_ZERO; + break; + case GE_LOGIC_AND: + case GE_LOGIC_AND_REVERSE: + WARN_LOG_REPORT_ONCE(d3dLogicOpAnd, G3D, "Unsupported AND logic op: %x", gstate.getLogicOp()); + break; + case GE_LOGIC_COPY: + // This is the same as off. + break; + case GE_LOGIC_COPY_INVERTED: + // Handled in the shader. + break; + case GE_LOGIC_AND_INVERTED: + case GE_LOGIC_NOR: + case GE_LOGIC_NAND: + case GE_LOGIC_EQUIV: + // Handled in the shader. + WARN_LOG_REPORT_ONCE(d3dLogicOpAndInverted, G3D, "Attempted invert for logic op: %x", gstate.getLogicOp()); + break; + case GE_LOGIC_INVERTED: + srcBlend = GL_ONE; + dstBlend = GL_ONE; + blendOp = GL_FUNC_SUBTRACT; + WARN_LOG_REPORT_ONCE(d3dLogicOpInverted, G3D, "Attempted inverse for logic op: %x", gstate.getLogicOp()); + break; + case GE_LOGIC_NOOP: + srcBlend = GL_ZERO; + dstBlend = GL_ONE; + break; + case GE_LOGIC_XOR: + WARN_LOG_REPORT_ONCE(d3dLogicOpOrXor, G3D, "Unsupported XOR logic op: %x", gstate.getLogicOp()); + break; + case GE_LOGIC_OR: + case GE_LOGIC_OR_INVERTED: + // Inverted in shader. + dstBlend = GL_ONE; + WARN_LOG_REPORT_ONCE(d3dLogicOpOr, G3D, "Attempted or for logic op: %x", gstate.getLogicOp()); + break; + case GE_LOGIC_OR_REVERSE: + WARN_LOG_REPORT_ONCE(d3dLogicOpOrReverse, G3D, "Unsupported OR REVERSE logic op: %x", gstate.getLogicOp()); + break; + case GE_LOGIC_SET: + dstBlend = GL_ONE; + WARN_LOG_REPORT_ONCE(d3dLogicOpSet, G3D, "Attempted set for logic op: %x", gstate.getLogicOp()); + break; + } } } -#endif // We're not blending, but we may still want to blend for stencil. // This is only useful for INCR/DECR/INVERT. Others can write directly. @@ -605,9 +607,11 @@ void TransformDrawEngine::ApplyDrawState(int prim) { glstate.dither.disable(); if (gstate.isModeClear()) { -#if !defined(USING_GLES2) - // Logic Ops - glstate.colorLogicOp.disable(); +#ifndef USING_GLES2 + if (gstate_c.Supports(GPU_SUPPORTS_LOGIC_OP)) { + // Logic Ops + glstate.colorLogicOp.disable(); + } #endif // Culling glstate.cullFace.disable(); @@ -639,13 +643,16 @@ void TransformDrawEngine::ApplyDrawState(int prim) { glstate.stencilTest.disable(); } } else { -#if !defined(USING_GLES2) - // Logic Ops - if (gstate.isLogicOpEnabled() && gstate.getLogicOp() != GE_LOGIC_COPY) { - glstate.colorLogicOp.enable(); - glstate.logicOp.set(logicOps[gstate.getLogicOp()]); - } else { - glstate.colorLogicOp.disable(); +#ifndef USING_GLES2 + if (gstate_c.Supports(GPU_SUPPORTS_LOGIC_OP)) { + // TODO: Make this dynamic + // Logic Ops + if (gstate.isLogicOpEnabled() && gstate.getLogicOp() != GE_LOGIC_COPY) { + glstate.colorLogicOp.enable(); + glstate.logicOp.set(logicOps[gstate.getLogicOp()]); + } else { + glstate.colorLogicOp.disable(); + } } #endif // Set cull diff --git a/GPU/GLES/StencilBuffer.cpp b/GPU/GLES/StencilBuffer.cpp index cc1195805a..b8a2a64497 100644 --- a/GPU/GLES/StencilBuffer.cpp +++ b/GPU/GLES/StencilBuffer.cpp @@ -170,7 +170,7 @@ bool FramebufferManager::NotifyStencilUpload(u32 addr, int size, bool skipZero) bool useNV = false; #ifndef USING_GLES2 - if (gl_extensions.FBO_ARB) { + if (gl_extensions.ARB_framebuffer_object) { useNV = false; useBlit = true; } diff --git a/GPU/GPUState.h b/GPU/GPUState.h index e70fbb48c1..2878343c0b 100644 --- a/GPU/GPUState.h +++ b/GPU/GPUState.h @@ -444,12 +444,15 @@ enum TextureChangeReason { #define FLAG_BIT(x) (1 << x) +// Some of these are OpenGL-specific even though this file is neutral, unfortunately. +// Might want to move this mechanism into the backend later. 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_SUPPORTS_NV_FRAMEBUFFER_BLIT = FLAG_BIT(10), GPU_SUPPORTS_ANY_FRAMEBUFFER_FETCH = FLAG_BIT(20), GPU_SUPPORTS_FBO_ARB = FLAG_BIT(25), diff --git a/native b/native index da38466d29..2b24f76d34 160000 --- a/native +++ b/native @@ -1 +1 @@ -Subproject commit da38466d29a8db045ad56d1fe00601bf43b88d57 +Subproject commit 2b24f76d34437941d3d6444c39e190d3c3fe979f From 186d624ef3de632c35ed20390f7afb8417ec5363 Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Sat, 5 Sep 2015 22:40:45 +0200 Subject: [PATCH 04/12] Cleanup of FBO+blit flags. Requires the change in native to stop lying. --- GPU/Directx9/helper/dx_state.h | 1 - GPU/GLES/Framebuffer.cpp | 27 ++++++++------------------- GPU/GLES/GLES_GPU.cpp | 11 ++++++++--- GPU/GLES/StencilBuffer.cpp | 10 +++------- GPU/GPUState.h | 7 ++++--- native | 2 +- 6 files changed, 24 insertions(+), 34 deletions(-) diff --git a/GPU/Directx9/helper/dx_state.h b/GPU/Directx9/helper/dx_state.h index 9217c7a9c6..e1f6845e18 100644 --- a/GPU/Directx9/helper/dx_state.h +++ b/GPU/Directx9/helper/dx_state.h @@ -408,7 +408,6 @@ struct GLExtensions { bool OES_depth_texture; bool EXT_discard_framebuffer; bool FBO_ARB; - bool FBO_EXT; }; extern GLExtensions gl_extensions; diff --git a/GPU/GLES/Framebuffer.cpp b/GPU/GLES/Framebuffer.cpp index 288592306a..76c6a71461 100644 --- a/GPU/GLES/Framebuffer.cpp +++ b/GPU/GLES/Framebuffer.cpp @@ -818,24 +818,21 @@ void FramebufferManager::BlitFramebufferDepth(VirtualFramebuffer *src, VirtualFr src->renderWidth == dst->renderWidth && src->renderHeight == dst->renderHeight) { -#ifndef USING_GLES2 - if (gl_extensions.ARB_framebuffer_object) { - bool useNV = false; -#else - if (gl_extensions.GLES3 || gl_extensions.NV_framebuffer_blit) { - bool useNV = !gl_extensions.GLES3; -#endif + if (gstate_c.Supports(GPU_SUPPORTS_ARB_FRAMEBUFFER_BLIT | GPU_SUPPORTS_NV_FRAMEBUFFER_BLIT)) { + // Only use NV if ARB isn't supported. + bool useNV = !gstate_c.Supports(GPU_SUPPORTS_ARB_FRAMEBUFFER_BLIT); // Let's only do this if not clearing depth. fbo_bind_for_read(src->fbo); glDisable(GL_SCISSOR_TEST); -#if defined(USING_GLES2) && defined(ANDROID) // We only support this extension on Android, it's not even available on PC. if (useNV) { +#if defined(USING_GLES2) && defined(ANDROID) // We only support this extension on Android, it's not even available on PC. glBlitFramebufferNV(0, 0, src->renderWidth, src->renderHeight, 0, 0, dst->renderWidth, dst->renderHeight, GL_DEPTH_BUFFER_BIT, GL_NEAREST); - } else #endif // defined(USING_GLES2) && defined(ANDROID) + } else { glBlitFramebuffer(0, 0, src->renderWidth, src->renderHeight, 0, 0, dst->renderWidth, dst->renderHeight, GL_DEPTH_BUFFER_BIT, GL_NEAREST); + } // If we set dst->depthUpdated here, our optimization above would be pointless. glstate.scissorTest.restore(); @@ -1278,7 +1275,7 @@ void FramebufferManager::BlitFramebuffer(VirtualFramebuffer *dst, int dstX, int bool useNV = false; #ifndef USING_GLES2 - if (gstate_c.Supports(GPU_SUPPORTS_FBO_ARB)) { + if (gstate_c.Supports(GPU_SUPPORTS_FBO)) { useNV = false; useBlit = true; } @@ -1555,15 +1552,7 @@ void FramebufferManager::PackFramebufferAsync_(VirtualFramebuffer *vfb) { } GLenum fbStatus; -#ifndef USING_GLES2 - if (!gl_extensions.ARB_framebuffer_object) { - fbStatus = glCheckFramebufferStatusEXT(GL_READ_FRAMEBUFFER); - } else { - fbStatus = glCheckFramebufferStatus(GL_READ_FRAMEBUFFER); - } -#else - fbStatus = glCheckFramebufferStatus(GL_READ_FRAMEBUFFER); -#endif + fbStatus = (GLenum)fbo_check_framebuffer_status(vfb->fbo); if (fbStatus != GL_FRAMEBUFFER_COMPLETE) { ERROR_LOG(SCEGE, "Incomplete source framebuffer, aborting read"); diff --git a/GPU/GLES/GLES_GPU.cpp b/GPU/GLES/GLES_GPU.cpp index 04d9837690..3e23885127 100644 --- a/GPU/GLES/GLES_GPU.cpp +++ b/GPU/GLES/GLES_GPU.cpp @@ -496,9 +496,14 @@ void GLES_GPU::CheckGPUFeatures() { } } - // Note: there's a lie going on in the codebase about what ARB_FBO really is. It's not equal to the FBO in ES 2.0. - if (gl_extensions.ARB_framebuffer_object) { - features |= GPU_SUPPORTS_FBO_ARB; + if (gl_extensions.ARB_framebuffer_object || gl_extensions.EXT_framebuffer_object || gl_extensions.IsGLES) { + features |= GPU_SUPPORTS_FBO; + } + if (gl_extensions.ARB_framebuffer_object || gl_extensions.GLES3) { + features |= GPU_SUPPORTS_ARB_FRAMEBUFFER_BLIT; + } + if (gl_extensions.NV_framebuffer_blit) { + features |= GPU_SUPPORTS_NV_FRAMEBUFFER_BLIT; } bool useCPU = false; diff --git a/GPU/GLES/StencilBuffer.cpp b/GPU/GLES/StencilBuffer.cpp index b8a2a64497..ab562bb090 100644 --- a/GPU/GLES/StencilBuffer.cpp +++ b/GPU/GLES/StencilBuffer.cpp @@ -169,17 +169,13 @@ bool FramebufferManager::NotifyStencilUpload(u32 addr, int size, bool skipZero) bool useBlit = false; bool useNV = false; -#ifndef USING_GLES2 - if (gl_extensions.ARB_framebuffer_object) { + if (gstate_c.Supports(GPU_SUPPORTS_ARB_FRAMEBUFFER_BLIT)) { useNV = false; useBlit = true; - } -#else - if (gl_extensions.GLES3 || gl_extensions.NV_framebuffer_blit) { - useNV = !gl_extensions.GLES3; + } else if (gstate_c.Supports(GPU_SUPPORTS_NV_FRAMEBUFFER_BLIT)) { + useNV = true; useBlit = true; } -#endif // Our fragment shader (and discard) is slow. Since the source is 1x, we can stencil to 1x. // Then after we're done, we'll just blit it across and stretch it there. diff --git a/GPU/GPUState.h b/GPU/GPUState.h index 2878343c0b..d319a8205c 100644 --- a/GPU/GPUState.h +++ b/GPU/GPUState.h @@ -453,10 +453,11 @@ enum { GPU_SUPPORTS_UNPACK_SUBIMAGE = FLAG_BIT(3), GPU_SUPPORTS_BLEND_MINMAX = FLAG_BIT(4), GPU_SUPPORTS_LOGIC_OP = FLAG_BIT(5), - GPU_SUPPORTS_NV_FRAMEBUFFER_BLIT = FLAG_BIT(10), GPU_SUPPORTS_ANY_FRAMEBUFFER_FETCH = FLAG_BIT(20), - GPU_SUPPORTS_FBO_ARB = FLAG_BIT(25), - GPU_SUPPORTS_OES_TEXTURE_NPOT = FLAG_BIT(26), + GPU_SUPPORTS_FBO = FLAG_BIT(25), + GPU_SUPPORTS_ARB_FRAMEBUFFER_BLIT = FLAG_BIT(26), + GPU_SUPPORTS_NV_FRAMEBUFFER_BLIT = FLAG_BIT(27), + GPU_SUPPORTS_OES_TEXTURE_NPOT = FLAG_BIT(28), GPU_IS_MOBILE = FLAG_BIT(29), GPU_PREFER_CPU_DOWNLOAD = FLAG_BIT(30), GPU_PREFER_REVERSE_COLOR_ORDER = FLAG_BIT(31), diff --git a/native b/native index 2b24f76d34..6934d31090 160000 --- a/native +++ b/native @@ -1 +1 @@ -Subproject commit 2b24f76d34437941d3d6444c39e190d3c3fe979f +Subproject commit 6934d31090a25d44b23a05b6eaa7576cc4a4f4b9 From 0237b84efd8d5d81959daadf6e5977fd02f8c3b8 Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Sat, 5 Sep 2015 23:09:06 +0200 Subject: [PATCH 05/12] Reduce use of #ifdef USING_GLES2 some more --- Core/Config.cpp | 4 +- GPU/GLES/FragmentShaderGenerator.cpp | 25 +++++----- GPU/GLES/GLES_GPU.cpp | 4 ++ GPU/GLES/StencilBuffer.cpp | 22 +++++---- GPU/GLES/TextureCache.cpp | 73 +++++++++++++--------------- GPU/GPUState.h | 1 + UI/EmuScreen.cpp | 4 +- native | 2 +- 8 files changed, 70 insertions(+), 65 deletions(-) diff --git a/Core/Config.cpp b/Core/Config.cpp index df77f7ba2f..5ec26364f4 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -432,7 +432,9 @@ static ConfigSetting graphicsSettings[] = { ConfigSetting("FrameSkipUnthrottle", &g_Config.bFrameSkipUnthrottle, true), #endif ReportedConfigSetting("ForceMaxEmulatedFPS", &g_Config.iForceMaxEmulatedFPS, 60, true, true), -#ifdef USING_GLES2 + + // TODO: Hm, on fast mobile GPUs we should definitely default to at least 4... +#ifdef MOBILE_DEVICE ConfigSetting("AnisotropyLevel", &g_Config.iAnisotropyLevel, 0, true, true), #else ConfigSetting("AnisotropyLevel", &g_Config.iAnisotropyLevel, 8, true, true), diff --git a/GPU/GLES/FragmentShaderGenerator.cpp b/GPU/GLES/FragmentShaderGenerator.cpp index 3bab172e2f..b518576262 100644 --- a/GPU/GLES/FragmentShaderGenerator.cpp +++ b/GPU/GLES/FragmentShaderGenerator.cpp @@ -16,8 +16,9 @@ // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. #if !defined(USING_GLES2) -// SDL 1.2 on Apple does not have support for OpenGL 3 and hence needs -// special treatment in the shader generator. +// We do not yet enable OpenGL 3 on Apple, so we need +// special treatment in the shader generator. However, the GL version check +// should be enough? TODO #if defined(__APPLE__) #define FORCE_OPENGL_2_0 #endif @@ -373,8 +374,7 @@ enum LogicOpReplaceType { }; static inline LogicOpReplaceType ReplaceLogicOpType() { -#if defined(USING_GLES2) - if (gstate.isLogicOpEnabled()) { + if (!gstate_c.Supports(GPU_SUPPORTS_LOGIC_OP) && gstate.isLogicOpEnabled()) { switch (gstate.getLogicOp()) { case GE_LOGIC_COPY_INVERTED: case GE_LOGIC_AND_INVERTED: @@ -391,7 +391,6 @@ static inline LogicOpReplaceType ReplaceLogicOpType() { return LOGICOPTYPE_NORMAL; } } -#endif return LOGICOPTYPE_NORMAL; } @@ -426,14 +425,14 @@ void ComputeFragmentShaderID(ShaderID *id) { id0 |= (doTextureAlpha & 1) << 5; // rgb or rgba id0 |= (gstate_c.flipTexture & 1) << 6; -if (gstate_c.needShaderTexClamp) { - bool textureAtOffset = gstate_c.curTextureXOffset != 0 || gstate_c.curTextureYOffset != 0; - // 3 bits total. - id0 |= 1 << 7; - id0 |= gstate.isTexCoordClampedS() << 8; - id0 |= gstate.isTexCoordClampedT() << 9; - id0 |= (textureAtOffset & 1) << 10; -} + if (gstate_c.needShaderTexClamp) { + bool textureAtOffset = gstate_c.curTextureXOffset != 0 || gstate_c.curTextureYOffset != 0; + // 3 bits total. + id0 |= 1 << 7; + id0 |= gstate.isTexCoordClampedS() << 8; + id0 |= gstate.isTexCoordClampedT() << 9; + id0 |= (textureAtOffset & 1) << 10; + } } id0 |= (lmode & 1) << 11; diff --git a/GPU/GLES/GLES_GPU.cpp b/GPU/GLES/GLES_GPU.cpp index 3e23885127..0099087acd 100644 --- a/GPU/GLES/GLES_GPU.cpp +++ b/GPU/GLES/GLES_GPU.cpp @@ -543,6 +543,10 @@ void GLES_GPU::CheckGPUFeatures() { if (!gl_extensions.IsGLES) features |= GPU_SUPPORTS_LOGIC_OP; + if (gl_extensions.GLES3 || !gl_extensions.IsGLES) { + features |= GPU_SUPPORTS_TEXTURE_LOD_CONTROL; + } + #ifdef MOBILE_DEVICE // Arguably, we should turn off GPU_IS_MOBILE on like modern Tegras, etc. features |= GPU_IS_MOBILE; diff --git a/GPU/GLES/StencilBuffer.cpp b/GPU/GLES/StencilBuffer.cpp index ab562bb090..8bc849267e 100644 --- a/GPU/GLES/StencilBuffer.cpp +++ b/GPU/GLES/StencilBuffer.cpp @@ -22,11 +22,11 @@ #include "GPU/GLES/ShaderManager.h" #include "GPU/GLES/TextureCache.h" -static const char *stencil_fs = -#ifdef USING_GLES2 +static const char *gles_prefix = "#version 100\n" -"precision highp float;\n" -#endif +"precision highp float;\n"; + +static const char *stencil_fs = "varying vec2 v_texcoord0;\n" "uniform float u_stencilValue;\n" "uniform sampler2D tex;\n" @@ -39,10 +39,6 @@ static const char *stencil_fs = "}\n"; static const char *stencil_vs = -#ifdef USING_GLES2 -"#version 100\n" -"precision highp float;\n" -#endif "attribute vec4 a_position;\n" "attribute vec2 a_texcoord0;\n" "varying vec2 v_texcoord0;\n" @@ -51,6 +47,14 @@ static const char *stencil_vs = " gl_Position = a_position;\n" "}\n"; +std::string GLSLES100PrefixProgram(std::string code) { + if (gl_extensions.IsGLES) { + return std::string(gles_prefix) + code; + } else { + return code; + } +} + static u8 StencilBits5551(const u8 *ptr8, u32 numPixels) { const u32 *ptr = (const u32 *)ptr8; @@ -146,7 +150,7 @@ bool FramebufferManager::NotifyStencilUpload(u32 addr, int size, bool skipZero) if (!stencilUploadProgram_) { std::string errorString; - stencilUploadProgram_ = glsl_create_source(stencil_vs, stencil_fs, &errorString); + stencilUploadProgram_ = glsl_create_source(GLSLES100PrefixProgram(stencil_vs).c_str(), GLSLES100PrefixProgram(stencil_fs).c_str(), &errorString); if (!stencilUploadProgram_) { ERROR_LOG_REPORT(G3D, "Failed to compile stencilUploadProgram! This shouldn't happen.\n%s", errorString.c_str()); } else { diff --git a/GPU/GLES/TextureCache.cpp b/GPU/GLES/TextureCache.cpp index ff352ca552..aba39f7ad1 100644 --- a/GPU/GLES/TextureCache.cpp +++ b/GPU/GLES/TextureCache.cpp @@ -719,20 +719,23 @@ void TextureCache::UpdateSamplingParams(TexCacheEntry &entry, bool force) { if (entry.maxLevel != 0) { if (force || entry.lodBias != lodBias) { + if (gstate_c.Supports(GPU_SUPPORTS_TEXTURE_LOD_CONTROL)) { + GETexLevelMode mode = gstate.getTexLevelMode(); + switch (mode) { + case GE_TEXLEVEL_MODE_AUTO: + // TODO + break; + case GE_TEXLEVEL_MODE_CONST: + // Sigh, LOD_BIAS is not even in ES 3.0.. #ifndef USING_GLES2 - GETexLevelMode mode = gstate.getTexLevelMode(); - switch (mode) { - case GE_TEXLEVEL_MODE_AUTO: - // TODO - break; - case GE_TEXLEVEL_MODE_CONST: - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_LOD_BIAS, lodBias); - break; - case GE_TEXLEVEL_MODE_SLOPE: - // TODO - break; - } + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_LOD_BIAS, lodBias); #endif + break; + case GE_TEXLEVEL_MODE_SLOPE: + // TODO + break; + } + } entry.lodBias = lodBias; } } @@ -1419,8 +1422,7 @@ void TextureCache::SetTexture(bool force) { break; } -#ifndef USING_GLES2 - if (i > 0) { + if (i > 0 && gstate_c.Supports(GPU_SUPPORTS_TEXTURE_LOD_CONTROL)) { int tw = gstate.getTextureWidth(i); int th = gstate.getTextureHeight(i); if (tw != 1 && tw != (gstate.getTextureWidth(i - 1) >> 1)) @@ -1428,7 +1430,6 @@ void TextureCache::SetTexture(bool force) { else if (th != 1 && th != (gstate.getTextureHeight(i - 1) >> 1)) badMipSizes = true; } -#endif } // In addition, simply don't load more than level 0 if g_Config.bMipMap is false. @@ -1506,34 +1507,28 @@ void TextureCache::SetTexture(bool force) { // Mipmapping only enable when texture scaling disable if (maxLevel > 0 && g_Config.iTexScalingLevel == 1) { -#ifndef USING_GLES2 - if (badMipSizes) { - // WARN_LOG(G3D, "Bad mipmap for texture sized %dx%dx%d - autogenerating", w, h, (int)format); - glGenerateMipmap(GL_TEXTURE_2D); - } else { - for (int i = 1; i <= maxLevel; i++) { - LoadTextureLevel(*entry, i, replaceImages, scaleFactor, dstFmt); + if (gstate_c.Supports(GPU_SUPPORTS_TEXTURE_LOD_CONTROL)) { + if (badMipSizes) { + // WARN_LOG(G3D, "Bad mipmap for texture sized %dx%dx%d - autogenerating", w, h, (int)format); + glGenerateMipmap(GL_TEXTURE_2D); + } else { + for (int i = 1; i <= maxLevel; i++) { + LoadTextureLevel(*entry, i, replaceImages, scaleFactor, dstFmt); + } + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, maxLevel); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, (float)maxLevel); } - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, maxLevel); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, (float)maxLevel); - } -#else - // Avoid PowerVR driver bug - if (w > 1 && h > 1 && !(gl_extensions.gpuVendor == GPU_VENDOR_POWERVR && h > w)) { // Really! only seems to fail if height > width - // NOTICE_LOG(G3D, "Generating mipmap for texture sized %dx%d%d", w, h, (int)format); - glGenerateMipmap(GL_TEXTURE_2D); } else { - entry->maxLevel = 0; + // Avoid PowerVR driver bug + if (w > 1 && h > 1 && !(h > w && (gl_extensions.bugs & BUG_PVR_GENMIPMAP_HEIGHT_GREATER))) { // Really! only seems to fail if height > width + // NOTICE_LOG(G3D, "Generating mipmap for texture sized %dx%d%d", w, h, (int)format); + glGenerateMipmap(GL_TEXTURE_2D); + } else { + entry->maxLevel = 0; + } } -#endif - } else { -#ifndef USING_GLES2 + } else if (gstate_c.Supports(GPU_SUPPORTS_TEXTURE_LOD_CONTROL)) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0); -#else - if (gl_extensions.GLES3) { - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0); - } -#endif } int aniso = 1 << g_Config.iAnisotropyLevel; diff --git a/GPU/GPUState.h b/GPU/GPUState.h index d319a8205c..9099d846b7 100644 --- a/GPU/GPUState.h +++ b/GPU/GPUState.h @@ -454,6 +454,7 @@ enum { GPU_SUPPORTS_BLEND_MINMAX = FLAG_BIT(4), GPU_SUPPORTS_LOGIC_OP = FLAG_BIT(5), GPU_SUPPORTS_ANY_FRAMEBUFFER_FETCH = FLAG_BIT(20), + GPU_SUPPORTS_TEXTURE_LOD_CONTROL = FLAG_BIT(24), GPU_SUPPORTS_FBO = FLAG_BIT(25), GPU_SUPPORTS_ARB_FRAMEBUFFER_BLIT = FLAG_BIT(26), GPU_SUPPORTS_NV_FRAMEBUFFER_BLIT = FLAG_BIT(27), diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index 2bbc151f21..2aa4854582 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -924,20 +924,20 @@ void EmuScreen::render() { screenManager()->getUIContext()->End(); } -#ifdef USING_GLES2 // We have no use for backbuffer depth or stencil, so let tiled renderers discard them after tiling. if (gl_extensions.GLES3 && glInvalidateFramebuffer != nullptr) { GLenum attachments[2] = { GL_DEPTH, GL_STENCIL }; glInvalidateFramebuffer(GL_FRAMEBUFFER, 2, attachments); } else if (!gl_extensions.GLES3) { +#ifdef USING_GLES2 // Tiled renderers like PowerVR should benefit greatly from this. However - seems I can't call it? bool hasDiscard = gl_extensions.EXT_discard_framebuffer; // TODO if (hasDiscard) { //const GLenum targets[3] = { GL_COLOR_EXT, GL_DEPTH_EXT, GL_STENCIL_EXT }; //glDiscardFramebufferEXT(GL_FRAMEBUFFER, 3, targets); } - } #endif + } } void EmuScreen::deviceLost() { diff --git a/native b/native index 6934d31090..67e22c29c2 160000 --- a/native +++ b/native @@ -1 +1 @@ -Subproject commit 6934d31090a25d44b23a05b6eaa7576cc4a4f4b9 +Subproject commit 67e22c29c2823c4f182e99920adff32ba88c1069 From 1c0158bfe682b96cbfac0950ea051497838e8f3b Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Sat, 5 Sep 2015 23:39:10 +0200 Subject: [PATCH 06/12] Further reduce the use of ifdef USING_GLES2 and friends. --- GPU/Common/PostShader.cpp | 16 +++++++----- GPU/GLES/Framebuffer.cpp | 47 +++++++--------------------------- GPU/GLES/Framebuffer.h | 10 ++------ GPU/GLES/GLES_GPU.cpp | 1 - GPU/GLES/StateMapping.cpp | 4 +-- GPU/GLES/TransformPipeline.cpp | 9 ------- native | 2 +- 7 files changed, 23 insertions(+), 66 deletions(-) diff --git a/GPU/Common/PostShader.cpp b/GPU/Common/PostShader.cpp index f17d825f3f..1c95298716 100644 --- a/GPU/Common/PostShader.cpp +++ b/GPU/Common/PostShader.cpp @@ -25,6 +25,7 @@ #include "file/ini_file.h" #include "file/file_util.h" #include "file/vfs.h" +#include "gfx_es2/gpu_features.h" #include "Core/Config.h" #include "GPU/Common/PostShader.h" @@ -84,13 +85,14 @@ void LoadPostShaderInfo(std::vector directories) { info.vertexShaderFile = path + "/" + temp; section.Get("OutputResolution", &info.outputResolution, false); -#ifdef USING_GLES2 - // Let's ignore shaders we can't support. TODO: Check for GLES 3.0 - bool requiresIntegerSupport; - section.Get("RequiresIntSupport", &requiresIntegerSupport, false); - if (requiresIntegerSupport) - continue; -#endif + // Let's ignore shaders we can't support. TODO: Not a very good check + if (gl_extensions.IsGLES && !gl_extensions.GLES3) { + bool requiresIntegerSupport; + section.Get("RequiresIntSupport", &requiresIntegerSupport, false); + if (requiresIntegerSupport) + continue; + } + auto beginErase = std::find(shaderInfo.begin(), shaderInfo.end(), info.name); if (beginErase != shaderInfo.end()) { shaderInfo.erase(beginErase, shaderInfo.end()); diff --git a/GPU/GLES/Framebuffer.cpp b/GPU/GLES/Framebuffer.cpp index 76c6a71461..c0ca056660 100644 --- a/GPU/GLES/Framebuffer.cpp +++ b/GPU/GLES/Framebuffer.cpp @@ -48,22 +48,6 @@ #include "UI/OnScreenDisplay.h" -#if defined(USING_GLES2) -#ifndef GL_READ_FRAMEBUFFER -#define GL_READ_FRAMEBUFFER GL_FRAMEBUFFER -#define GL_DRAW_FRAMEBUFFER GL_FRAMEBUFFER -#endif -#ifndef GL_RGBA8 -#define GL_RGBA8 GL_RGBA -#endif -#ifndef GL_DEPTH_COMPONENT24 -#define GL_DEPTH_COMPONENT24 GL_DEPTH_COMPONENT24_OES -#endif -#ifndef GL_DEPTH24_STENCIL8_OES -#define GL_DEPTH24_STENCIL8_OES 0x88F0 -#endif -#endif - extern int g_iNumVideos; static const char tex_fs[] = @@ -284,12 +268,9 @@ FramebufferManager::FramebufferManager() : usePostShader_(false), postShaderAtOutputResolution_(false), resized_(false), - gameUsesSequentialCopies_(false) -#ifndef USING_GLES2 - , + gameUsesSequentialCopies_(false), pixelBufObj_(nullptr), currentPBO_(0) -#endif { } @@ -312,9 +293,7 @@ FramebufferManager::~FramebufferManager() { fbo_destroy(it->second.fbo); } -#ifndef USING_GLES2 delete [] pixelBufObj_; -#endif delete [] convBuf_; } @@ -1274,17 +1253,13 @@ void FramebufferManager::BlitFramebuffer(VirtualFramebuffer *dst, int dstX, int bool useBlit = false; bool useNV = false; -#ifndef USING_GLES2 - if (gstate_c.Supports(GPU_SUPPORTS_FBO)) { + if (gstate_c.Supports(GPU_SUPPORTS_ARB_FRAMEBUFFER_BLIT)) { useNV = false; useBlit = true; - } -#else - if (gl_extensions.GLES3 || gstate_c.Supports(GPU_SUPPORTS_NV_FRAMEBUFFER_BLIT)) { - useNV = !gl_extensions.GLES3; + } else if (gstate_c.Supports(GPU_SUPPORTS_NV_FRAMEBUFFER_BLIT)) { + useNV = true; useBlit = true; } -#endif float srcXFactor = useBlit ? (float)src->renderWidth / (float)src->bufferWidth : 1.0f; float srcYFactor = useBlit ? (float)src->renderHeight / (float)src->bufferHeight : 1.0f; @@ -1835,12 +1810,11 @@ bool FramebufferManager::GetFramebuffer(u32 fb_address, int fb_stride, GEBufferF buffer.Allocate(vfb->renderWidth, vfb->renderHeight, GE_FORMAT_8888, true, true); if (vfb->fbo) fbo_bind_for_read(vfb->fbo); -#ifndef USING_GLES2 - glReadBuffer(GL_COLOR_ATTACHMENT0); -#endif + if (gl_extensions.GLES3 || !gl_extensions.IsGLES) + glReadBuffer(GL_COLOR_ATTACHMENT0); + glPixelStorei(GL_PACK_ALIGNMENT, 4); glReadPixels(0, 0, vfb->renderWidth, vfb->renderHeight, GL_RGBA, GL_UNSIGNED_BYTE, buffer.GetData()); - return true; } @@ -1864,18 +1838,15 @@ bool FramebufferManager::GetDepthbuffer(u32 fb_address, int fb_stride, u32 z_add return true; } -#ifndef USING_GLES2 buffer.Allocate(vfb->renderWidth, vfb->renderHeight, GPU_DBG_FORMAT_FLOAT, true); if (vfb->fbo) fbo_bind_for_read(vfb->fbo); - glReadBuffer(GL_DEPTH_ATTACHMENT); + if (gl_extensions.GLES3 || !gl_extensions.IsGLES) + glReadBuffer(GL_DEPTH_ATTACHMENT); glPixelStorei(GL_PACK_ALIGNMENT, 4); glReadPixels(0, 0, vfb->renderWidth, vfb->renderHeight, GL_DEPTH_COMPONENT, GL_FLOAT, buffer.GetData()); return true; -#else - return false; -#endif } bool FramebufferManager::GetStencilbuffer(u32 fb_address, int fb_stride, GPUDebugBuffer &buffer) { diff --git a/GPU/GLES/Framebuffer.h b/GPU/GLES/Framebuffer.h index 27b784807f..341f4b19bc 100644 --- a/GPU/GLES/Framebuffer.h +++ b/GPU/GLES/Framebuffer.h @@ -38,7 +38,6 @@ class TextureCache; class TransformDrawEngine; class ShaderManager; -#ifndef USING_GLES2 // Simple struct for asynchronous PBO readbacks struct AsyncPBO { GLuint handle; @@ -52,8 +51,6 @@ struct AsyncPBO { bool reading; }; -#endif - struct CardboardSettings { bool enabled; float leftEyeXPosition; @@ -147,9 +144,7 @@ private: inline bool ShouldDownloadUsingCPU(const VirtualFramebuffer *vfb) const; -#ifndef USING_GLES2 - void PackFramebufferAsync_(VirtualFramebuffer *vfb); -#endif + void PackFramebufferAsync_(VirtualFramebuffer *vfb); // Not used under ES currently void PackFramebufferSync_(VirtualFramebuffer *vfb, int x, int y, int w, int h); // Used by DrawPixels @@ -187,8 +182,7 @@ private: std::vector bvfbs_; // blitting framebuffers (for download) std::map tempFBOs_; -#ifndef USING_GLES2 + // Not used under ES currently. AsyncPBO *pixelBufObj_; //this isn't that large u8 currentPBO_; -#endif }; diff --git a/GPU/GLES/GLES_GPU.cpp b/GPU/GLES/GLES_GPU.cpp index 0099087acd..a52f6d4fa7 100644 --- a/GPU/GLES/GLES_GPU.cpp +++ b/GPU/GLES/GLES_GPU.cpp @@ -512,7 +512,6 @@ void GLES_GPU::CheckGPUFeatures() { #ifndef USING_GLES2 useCPU = g_Config.iRenderingMode == FB_READFBOMEMORY_CPU; #endif - // We might get here if hackForce04154000Download_ is hit. // Some cards or drivers seem to always dither when downloading a framebuffer to 16-bit. // This causes glitches in games that expect the exact values. // It has not been experienced on NVIDIA cards, so those are left using the GPU (which is faster.) diff --git a/GPU/GLES/StateMapping.cpp b/GPU/GLES/StateMapping.cpp index 533da787f0..e1cba640be 100644 --- a/GPU/GLES/StateMapping.cpp +++ b/GPU/GLES/StateMapping.cpp @@ -132,7 +132,7 @@ static const GLushort logicOps[] = { static GLenum toDualSource(GLenum blendfunc) { switch (blendfunc) { -#ifndef USING_GLES2 +#if !defined(USING_GLES2) // TODO: Remove when we have better headers case GL_SRC_ALPHA: return GL_SRC1_ALPHA; case GL_ONE_MINUS_SRC_ALPHA: @@ -420,7 +420,7 @@ void TransformDrawEngine::ApplyBlendState() { } } - if (replaceAlphaWithStencil == REPLACE_ALPHA_DUALSOURCE) { + if (replaceAlphaWithStencil == REPLACE_ALPHA_DUALSOURCE && gstate_c.Supports(GPU_SUPPORTS_DUALSOURCE_BLEND)) { glBlendFuncA = toDualSource(glBlendFuncA); glBlendFuncB = toDualSource(glBlendFuncB); } diff --git a/GPU/GLES/TransformPipeline.cpp b/GPU/GLES/TransformPipeline.cpp index 2994fe26bd..a3a8b8b7f6 100644 --- a/GPU/GLES/TransformPipeline.cpp +++ b/GPU/GLES/TransformPipeline.cpp @@ -777,11 +777,7 @@ rotateVBO: SetupDecFmtForDraw(program, dec_->GetDecVtxFmt(), vbo ? 0 : decoded); if (useElements) { -#if 1 // USING_GLES2 glDrawElements(glprim[prim], vertexCount, GL_UNSIGNED_SHORT, ebo ? 0 : (GLvoid*)decIndex); -#else - glDrawRangeElements(glprim[prim], 0, maxIndex, vertexCount, GL_UNSIGNED_SHORT, ebo ? 0 : (GLvoid*)decIndex); -#endif } else { glDrawArrays(glprim[prim], 0, vertexCount); } @@ -830,12 +826,7 @@ rotateVBO: if (attrMask & (1 << ATTR_COLOR0)) glVertexAttribPointer(ATTR_COLOR0, 4, GL_UNSIGNED_BYTE, GL_TRUE, vertexSize, ((uint8_t*)drawBuffer) + offsetof(TransformedVertex, color0)); if (attrMask & (1 << ATTR_COLOR1)) glVertexAttribPointer(ATTR_COLOR1, 3, GL_UNSIGNED_BYTE, GL_TRUE, vertexSize, ((uint8_t*)drawBuffer) + offsetof(TransformedVertex, color1)); if (drawIndexed) { -#if 1 // USING_GLES2 glDrawElements(glprim[prim], numTrans, GL_UNSIGNED_SHORT, inds); -#else - // This doesn't seem to provide much of a win. - glDrawRangeElements(glprim[prim], 0, maxIndex, numTrans, GL_UNSIGNED_SHORT, inds); -#endif } else { glDrawArrays(glprim[prim], 0, numTrans); } diff --git a/native b/native index 67e22c29c2..6566949ab5 160000 --- a/native +++ b/native @@ -1 +1 @@ -Subproject commit 67e22c29c2823c4f182e99920adff32ba88c1069 +Subproject commit 6566949ab5e52df54e4027201c07a826160a7f23 From b22850720dd04e5662f98d75513e5bab7b8db9bf Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Sun, 6 Sep 2015 00:13:46 +0200 Subject: [PATCH 07/12] Move the CheckGPUFeatures call to the Resize check --- GPU/GLES/GLES_GPU.cpp | 1 + GPU/GPUCommon.h | 1 - GPU/GPUInterface.h | 2 -- UI/EmuScreen.cpp | 1 - 4 files changed, 1 insertion(+), 4 deletions(-) diff --git a/GPU/GLES/GLES_GPU.cpp b/GPU/GLES/GLES_GPU.cpp index a52f6d4fa7..52686ef8e1 100644 --- a/GPU/GLES/GLES_GPU.cpp +++ b/GPU/GLES/GLES_GPU.cpp @@ -680,6 +680,7 @@ void GLES_GPU::UpdateCmdInfo() { void GLES_GPU::BeginFrameInternal() { if (resized_) { + CheckGPUFeatures(); UpdateCmdInfo(); transformDraw_.Resized(); } diff --git a/GPU/GPUCommon.h b/GPU/GPUCommon.h index 6ead754b81..fa1288fd41 100644 --- a/GPU/GPUCommon.h +++ b/GPU/GPUCommon.h @@ -19,7 +19,6 @@ public: GPUCommon(); virtual ~GPUCommon(); - virtual void CheckGPUFeatures() override {} virtual void Reinitialize(); virtual void InterruptStart(int listid); diff --git a/GPU/GPUInterface.h b/GPU/GPUInterface.h index 9af5d02ba0..15a57fed3c 100644 --- a/GPU/GPUInterface.h +++ b/GPU/GPUInterface.h @@ -207,8 +207,6 @@ public: static const int DisplayListMaxCount = 64; - virtual void CheckGPUFeatures() = 0; - // Initialization virtual void InitClear() = 0; virtual void Reinitialize() = 0; diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index 2aa4854582..f218ae5d43 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -180,7 +180,6 @@ void EmuScreen::dialogFinished(const Screen *dialog, DialogResult result) { quit_ = false; } RecreateViews(); - gpu->CheckGPUFeatures(); } static void AfterStateLoad(bool success, void *ignored) { From 2d0635c3e66d0ee33da46f1c4bbf3264797dedb1 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 5 Sep 2015 16:28:46 -0700 Subject: [PATCH 08/12] Cut out a bit more USING_GLES2. --- GPU/Common/DepalettizeShaderCommon.cpp | 13 +++++++------ GPU/GLES/Framebuffer.cpp | 16 ++++++++-------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/GPU/Common/DepalettizeShaderCommon.cpp b/GPU/Common/DepalettizeShaderCommon.cpp index 36bd191a97..d52225c8f1 100644 --- a/GPU/Common/DepalettizeShaderCommon.cpp +++ b/GPU/Common/DepalettizeShaderCommon.cpp @@ -17,6 +17,7 @@ #include +#include "gfx_es2/gl_state.h" #include "Common/Log.h" #include "Core/Reporting.h" #include "GPU/GPUState.h" @@ -28,12 +29,12 @@ // Uses integer instructions available since OpenGL 3.0. Suitable for ES 3.0 as well. void GenerateDepalShader300(char *buffer, GEBufferFormat pixelFormat) { char *p = buffer; -#ifdef USING_GLES2 - WRITE(p, "#version 300 es\n"); - WRITE(p, "precision mediump float;\n"); -#else - WRITE(p, "#version 330\n"); -#endif + if (gl_extensions.IsGLES) { + WRITE(p, "#version 300 es\n"); + WRITE(p, "precision mediump float;\n"); + } else { + WRITE(p, "#version 330\n"); + } WRITE(p, "in vec2 v_texcoord0;\n"); WRITE(p, "out vec4 fragColor0;\n"); WRITE(p, "uniform sampler2D tex;\n"); diff --git a/GPU/GLES/Framebuffer.cpp b/GPU/GLES/Framebuffer.cpp index c0ca056660..c5f76a6eb5 100644 --- a/GPU/GLES/Framebuffer.cpp +++ b/GPU/GLES/Framebuffer.cpp @@ -705,15 +705,15 @@ void FramebufferManager::NotifyRenderFramebufferSwitched(VirtualFramebuffer *pre } textureCache_->NotifyFramebuffer(vfb->fb_address, vfb, NOTIFY_FB_UPDATED); -#ifdef USING_GLES2 - // Some tiled mobile GPUs benefit IMMENSELY from clearing an FBO before rendering - // to it. This broke stuff before, so now it only clears on the first use of an - // FBO in a frame. This means that some games won't be able to avoid the on-some-GPUs - // performance-crushing framebuffer reloads from RAM, but we'll have to live with that. - if (vfb->last_frame_render != gpuStats.numFlips) { - ClearBuffer(); + if (gl_extensions.IsGLES) { + // Some tiled mobile GPUs benefit IMMENSELY from clearing an FBO before rendering + // to it. This broke stuff before, so now it only clears on the first use of an + // FBO in a frame. This means that some games won't be able to avoid the on-some-GPUs + // performance-crushing framebuffer reloads from RAM, but we'll have to live with that. + if (vfb->last_frame_render != gpuStats.numFlips) { + ClearBuffer(); + } } -#endif // Copy depth pixel value from the read framebuffer to the draw framebuffer if (prevVfb && !g_Config.bDisableSlowFramebufEffects) { From fb7c71e41dbe0cf748ef2e7ed7c67d784478cd83 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 5 Sep 2015 16:28:59 -0700 Subject: [PATCH 09/12] Simplify NV blit logic. --- GPU/GLES/Framebuffer.cpp | 12 ++---------- GPU/GLES/StencilBuffer.cpp | 12 ++---------- 2 files changed, 4 insertions(+), 20 deletions(-) diff --git a/GPU/GLES/Framebuffer.cpp b/GPU/GLES/Framebuffer.cpp index c5f76a6eb5..8164547c5c 100644 --- a/GPU/GLES/Framebuffer.cpp +++ b/GPU/GLES/Framebuffer.cpp @@ -1250,16 +1250,8 @@ void FramebufferManager::BlitFramebuffer(VirtualFramebuffer *dst, int dstX, int fbo_bind_as_render_target(dst->fbo); glDisable(GL_SCISSOR_TEST); - bool useBlit = false; - bool useNV = false; - - if (gstate_c.Supports(GPU_SUPPORTS_ARB_FRAMEBUFFER_BLIT)) { - useNV = false; - useBlit = true; - } else if (gstate_c.Supports(GPU_SUPPORTS_NV_FRAMEBUFFER_BLIT)) { - useNV = true; - useBlit = true; - } + bool useBlit = gstate_c.Supports(GPU_SUPPORTS_ARB_FRAMEBUFFER_BLIT | GPU_SUPPORTS_NV_FRAMEBUFFER_BLIT); + bool useNV = useBlit && !gstate_c.Supports(GPU_SUPPORTS_ARB_FRAMEBUFFER_BLIT); float srcXFactor = useBlit ? (float)src->renderWidth / (float)src->bufferWidth : 1.0f; float srcYFactor = useBlit ? (float)src->renderHeight / (float)src->bufferHeight : 1.0f; diff --git a/GPU/GLES/StencilBuffer.cpp b/GPU/GLES/StencilBuffer.cpp index 8bc849267e..6cfd6ad52e 100644 --- a/GPU/GLES/StencilBuffer.cpp +++ b/GPU/GLES/StencilBuffer.cpp @@ -170,16 +170,8 @@ bool FramebufferManager::NotifyStencilUpload(u32 addr, int size, bool skipZero) glstate.stencilTest.enable(); glstate.stencilOp.set(GL_REPLACE, GL_REPLACE, GL_REPLACE); - bool useBlit = false; - bool useNV = false; - - if (gstate_c.Supports(GPU_SUPPORTS_ARB_FRAMEBUFFER_BLIT)) { - useNV = false; - useBlit = true; - } else if (gstate_c.Supports(GPU_SUPPORTS_NV_FRAMEBUFFER_BLIT)) { - useNV = true; - useBlit = true; - } + bool useBlit = gstate_c.Supports(GPU_SUPPORTS_ARB_FRAMEBUFFER_BLIT | GPU_SUPPORTS_NV_FRAMEBUFFER_BLIT); + bool useNV = useBlit && !gstate_c.Supports(GPU_SUPPORTS_ARB_FRAMEBUFFER_BLIT); // Our fragment shader (and discard) is slow. Since the source is 1x, we can stencil to 1x. // Then after we're done, we'll just blit it across and stretch it there. From 764539f814a125fb7d883e4e1a654af82c3d27c9 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 5 Sep 2015 16:44:17 -0700 Subject: [PATCH 10/12] Clean up GLES logic used in shader gen. --- GPU/Common/DepalettizeShaderCommon.cpp | 12 +-- GPU/GLES/FragmentShaderGenerator.cpp | 132 ++++++++++++------------- GPU/GLES/VertexShaderGenerator.cpp | 50 ++++------ 3 files changed, 87 insertions(+), 107 deletions(-) diff --git a/GPU/Common/DepalettizeShaderCommon.cpp b/GPU/Common/DepalettizeShaderCommon.cpp index d52225c8f1..a6e52bdb4a 100644 --- a/GPU/Common/DepalettizeShaderCommon.cpp +++ b/GPU/Common/DepalettizeShaderCommon.cpp @@ -219,12 +219,12 @@ void GenerateDepalShaderFloat(char *buffer, GEBufferFormat pixelFormat, ShaderLa sprintf(offset, " + %f", texel_offset); if (lang == GLSL_140) { -#ifdef USING_GLES2 - WRITE(p, "#version 100\n"); - WRITE(p, "precision mediump float;\n"); -#else - WRITE(p, "#version 110\n"); -#endif + if (gl_extensions.IsGLES) { + WRITE(p, "#version 100\n"); + WRITE(p, "precision mediump float;\n"); + } else { + WRITE(p, "#version 110\n"); + } WRITE(p, "varying vec2 v_texcoord0;\n"); WRITE(p, "uniform sampler2D tex;\n"); WRITE(p, "uniform sampler2D pal;\n"); diff --git a/GPU/GLES/FragmentShaderGenerator.cpp b/GPU/GLES/FragmentShaderGenerator.cpp index b518576262..858a200ca6 100644 --- a/GPU/GLES/FragmentShaderGenerator.cpp +++ b/GPU/GLES/FragmentShaderGenerator.cpp @@ -500,88 +500,78 @@ void GenerateFragmentShader(char *buffer) { bool bitwiseOps = false; const char *lastFragData = nullptr; -#if defined(USING_GLES2) - // Let's wait until we have a real use for this. - // ES doesn't support dual source alpha :( - if (gstate_c.featureFlags & GPU_SUPPORTS_GLSL_ES_300) { - WRITE(p, "#version 300 es\n"); // GLSL ES 3.0 - fragColor0 = "fragColor0"; - texture = "texture"; - glslES30 = true; - bitwiseOps = true; - texelFetch = "texelFetch"; - } else { - WRITE(p, "#version 100\n"); // GLSL ES 1.0 - if (gl_extensions.EXT_gpu_shader4) { - WRITE(p, "#extension GL_EXT_gpu_shader4 : enable\n"); + if (gl_extensions.IsGLES) { + // ES doesn't support dual source alpha :( + if (gstate_c.featureFlags & GPU_SUPPORTS_GLSL_ES_300) { + WRITE(p, "#version 300 es\n"); // GLSL ES 3.0 + fragColor0 = "fragColor0"; + texture = "texture"; + glslES30 = true; bitwiseOps = true; - texelFetch = "texelFetch2D"; + texelFetch = "texelFetch"; + } else { + WRITE(p, "#version 100\n"); // GLSL ES 1.0 + if (gl_extensions.EXT_gpu_shader4) { + WRITE(p, "#extension GL_EXT_gpu_shader4 : enable\n"); + bitwiseOps = true; + texelFetch = "texelFetch2D"; + } } - } - // PowerVR needs highp to do the fog in MHU correctly. - // Others don't, and some can't handle highp in the fragment shader. - highpFog = (gl_extensions.bugs & BUG_PVR_SHADER_PRECISION_BAD) ? true : false; - highpTexcoord = highpFog; + // PowerVR needs highp to do the fog in MHU correctly. + // Others don't, and some can't handle highp in the fragment shader. + highpFog = (gl_extensions.bugs & BUG_PVR_SHADER_PRECISION_BAD) ? true : false; + highpTexcoord = highpFog; - if (gstate_c.featureFlags & GPU_SUPPORTS_ANY_FRAMEBUFFER_FETCH) { - if (gl_extensions.EXT_shader_framebuffer_fetch) { - WRITE(p, "#extension GL_EXT_shader_framebuffer_fetch : require\n"); - lastFragData = "gl_LastFragData[0]"; - } else if (gl_extensions.NV_shader_framebuffer_fetch) { - // GL_NV_shader_framebuffer_fetch is available on mobile platform and ES 2.0 only but not on desktop. - WRITE(p, "#extension GL_NV_shader_framebuffer_fetch : require\n"); - lastFragData = "gl_LastFragData[0]"; - } else if (gl_extensions.ARM_shader_framebuffer_fetch) { - WRITE(p, "#extension GL_ARM_shader_framebuffer_fetch : require\n"); - lastFragData = "gl_LastFragColorARM"; + if (gstate_c.featureFlags & GPU_SUPPORTS_ANY_FRAMEBUFFER_FETCH) { + if (gl_extensions.EXT_shader_framebuffer_fetch) { + WRITE(p, "#extension GL_EXT_shader_framebuffer_fetch : require\n"); + lastFragData = "gl_LastFragData[0]"; + } else if (gl_extensions.NV_shader_framebuffer_fetch) { + // GL_NV_shader_framebuffer_fetch is available on mobile platform and ES 2.0 only but not on desktop. + WRITE(p, "#extension GL_NV_shader_framebuffer_fetch : require\n"); + lastFragData = "gl_LastFragData[0]"; + } else if (gl_extensions.ARM_shader_framebuffer_fetch) { + WRITE(p, "#extension GL_ARM_shader_framebuffer_fetch : require\n"); + lastFragData = "gl_LastFragColorARM"; + } } - } - WRITE(p, "precision lowp float;\n"); - -#elif !defined(FORCE_OPENGL_2_0) - if (gl_extensions.VersionGEThan(3, 3, 0)) { - fragColor0 = "fragColor0"; - texture = "texture"; - glslES30 = true; - bitwiseOps = true; - texelFetch = "texelFetch"; - WRITE(p, "#version 330\n"); - WRITE(p, "#define lowp\n"); - WRITE(p, "#define mediump\n"); - WRITE(p, "#define highp\n"); - } else if (gl_extensions.VersionGEThan(3, 0, 0)) { - fragColor0 = "fragColor0"; - bitwiseOps = true; - texelFetch = "texelFetch"; - WRITE(p, "#version 130\n"); - if (gl_extensions.EXT_gpu_shader4) { - WRITE(p, "#extension GL_EXT_gpu_shader4 : enable\n"); - } - // Remove lowp/mediump in non-mobile non-glsl 3 implementations - WRITE(p, "#define lowp\n"); - WRITE(p, "#define mediump\n"); - WRITE(p, "#define highp\n"); + WRITE(p, "precision lowp float;\n"); } else { - WRITE(p, "#version 110\n"); - if (gl_extensions.EXT_gpu_shader4) { - WRITE(p, "#extension GL_EXT_gpu_shader4 : enable\n"); + // TODO: Handle this in VersionGEThan? +#if !defined(FORCE_OPENGL_2_0) + if (gl_extensions.VersionGEThan(3, 3, 0)) { + fragColor0 = "fragColor0"; + texture = "texture"; + glslES30 = true; bitwiseOps = true; - texelFetch = "texelFetch2D"; + texelFetch = "texelFetch"; + WRITE(p, "#version 330\n"); + } else if (gl_extensions.VersionGEThan(3, 0, 0)) { + fragColor0 = "fragColor0"; + bitwiseOps = true; + texelFetch = "texelFetch"; + WRITE(p, "#version 130\n"); + if (gl_extensions.EXT_gpu_shader4) { + WRITE(p, "#extension GL_EXT_gpu_shader4 : enable\n"); + } + } else { + WRITE(p, "#version 110\n"); + if (gl_extensions.EXT_gpu_shader4) { + WRITE(p, "#extension GL_EXT_gpu_shader4 : enable\n"); + bitwiseOps = true; + texelFetch = "texelFetch2D"; + } } - // Remove lowp/mediump in non-mobile non-glsl 3 implementations - WRITE(p, "#define lowp\n"); - WRITE(p, "#define mediump\n"); - WRITE(p, "#define highp\n"); - } -#else - // Need to remove lowp/mediump for Mac - WRITE(p, "#define lowp\n"); - WRITE(p, "#define mediump\n"); - WRITE(p, "#define highp\n"); #endif + // We remove these everywhere - GL4, GL3, Mac-forced-GL2, etc. + WRITE(p, "#define lowp\n"); + WRITE(p, "#define mediump\n"); + WRITE(p, "#define highp\n"); + } + if (glslES30) { varying = "in"; } diff --git a/GPU/GLES/VertexShaderGenerator.cpp b/GPU/GLES/VertexShaderGenerator.cpp index 379043ca0b..9c25ddb1f9 100644 --- a/GPU/GLES/VertexShaderGenerator.cpp +++ b/GPU/GLES/VertexShaderGenerator.cpp @@ -192,48 +192,38 @@ void GenerateVertexShader(int prim, u32 vertType, char *buffer, bool useHWTransf bool highpFog = false; bool highpTexcoord = false; -#if defined(USING_GLES2) - // Let's wait until we have a real use for this. - // ES doesn't support dual source alpha :( - if (gl_extensions.GLES3) { - WRITE(p, "#version 300 es\n"); - glslES30 = true; + if (gl_extensions.IsGLES) { + // ES doesn't support dual source alpha :( + if (gl_extensions.GLES3) { + WRITE(p, "#version 300 es\n"); + glslES30 = true; + } else { + WRITE(p, "#version 100\n"); // GLSL ES 1.0 + } + WRITE(p, "precision highp float;\n"); + + // PowerVR needs highp to do the fog in MHU correctly. + // Others don't, and some can't handle highp in the fragment shader. + highpFog = (gl_extensions.bugs & BUG_PVR_SHADER_PRECISION_BAD) ? true : false; + highpTexcoord = highpFog; } else { - WRITE(p, "#version 100\n"); // GLSL ES 1.0 - } - WRITE(p, "precision highp float;\n"); - - // PowerVR needs highp to do the fog in MHU correctly. - // Others don't, and some can't handle highp in the fragment shader. - highpFog = (gl_extensions.bugs & BUG_PVR_SHADER_PRECISION_BAD) ? true : false; - highpTexcoord = highpFog; - -#elif !defined(FORCE_OPENGL_2_0) + // TODO: Handle this in VersionGEThan? +#if !defined(FORCE_OPENGL_2_0) if (gl_extensions.VersionGEThan(3, 3, 0)) { glslES30 = true; WRITE(p, "#version 330\n"); - WRITE(p, "#define lowp\n"); - WRITE(p, "#define mediump\n"); - WRITE(p, "#define highp\n"); } else if (gl_extensions.VersionGEThan(3, 0, 0)) { WRITE(p, "#version 130\n"); - // Remove lowp/mediump in non-mobile non-glsl 3 implementations - WRITE(p, "#define lowp\n"); - WRITE(p, "#define mediump\n"); - WRITE(p, "#define highp\n"); } else { WRITE(p, "#version 110\n"); - // Remove lowp/mediump in non-mobile non-glsl 3 implementations + } +#endif + + // We remove these everywhere - GL4, GL3, Mac-forced-GL2, etc. WRITE(p, "#define lowp\n"); WRITE(p, "#define mediump\n"); WRITE(p, "#define highp\n"); } -#else - // Need to remove lowp/mediump for Mac - WRITE(p, "#define lowp\n"); - WRITE(p, "#define mediump\n"); - WRITE(p, "#define highp\n"); -#endif if (glslES30) { attribute = "in"; From 63da81513b3ae4fcf1b7cdbd1523b8eabbce9f92 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 5 Sep 2015 16:45:17 -0700 Subject: [PATCH 11/12] A few more misc GLES runtime cleanups. --- UI/DevScreens.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/UI/DevScreens.cpp b/UI/DevScreens.cpp index 61bfce2618..514e729751 100644 --- a/UI/DevScreens.cpp +++ b/UI/DevScreens.cpp @@ -365,11 +365,11 @@ void SystemInfoScreen::CreateViews() { deviceSpecs->Add(new ItemHeader("Version Information")); std::string apiVersion; if (g_Config.iGPUBackend == GPU_BACKEND_OPENGL) { -#ifdef USING_GLES2 - apiVersion = StringFromFormat("v%d.%d.%d ES", gl_extensions.ver[0], gl_extensions.ver[1], gl_extensions.ver[2]); -#else - apiVersion = StringFromFormat("v%d.%d.%d", gl_extensions.ver[0], gl_extensions.ver[1], gl_extensions.ver[2]); -#endif + if (gl_extensions.IsGLES) { + apiVersion = StringFromFormat("v%d.%d.%d ES", gl_extensions.ver[0], gl_extensions.ver[1], gl_extensions.ver[2]); + } else { + apiVersion = StringFromFormat("v%d.%d.%d", gl_extensions.ver[0], gl_extensions.ver[1], gl_extensions.ver[2]); + } } else { apiVersion = thin3d->GetInfoString(T3DInfo::APIVERSION); if (apiVersion.size() > 30) @@ -413,14 +413,13 @@ void SystemInfoScreen::CreateViews() { tabHolder->AddTab("OGL Extensions", oglExtensionsScroll); -#ifndef USING_GLES2 - oglExtensions->Add(new ItemHeader("OpenGL Extensions")); -#else - if (gl_extensions.GLES3) + if (!gl_extensions.IsGLES) { + oglExtensions->Add(new ItemHeader("OpenGL Extensions")); + } else if (gl_extensions.GLES3) { oglExtensions->Add(new ItemHeader("OpenGL ES 3.0 Extensions")); - else + } else { oglExtensions->Add(new ItemHeader("OpenGL ES 2.0 Extensions")); -#endif + } exts.clear(); SplitString(g_all_gl_extensions, ' ', exts); From 43f0ec47db21283fccfdca7c5e3094153effcab0 Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Sun, 6 Sep 2015 10:04:40 +0200 Subject: [PATCH 12/12] Update native --- native | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native b/native index 6566949ab5..f4f2a95067 160000 --- a/native +++ b/native @@ -1 +1 @@ -Subproject commit 6566949ab5e52df54e4027201c07a826160a7f23 +Subproject commit f4f2a950678b9d46e3f1babe54cf9df75f72f91c