From d4f31bc617ec1ffba9f5af505dfaeacd23223294 Mon Sep 17 00:00:00 2001 From: Steveice10 <1269164+Steveice10@users.noreply.github.com> Date: Fri, 10 Nov 2023 13:14:52 -0800 Subject: [PATCH] video_core: Fix fragment shader interlock usage on OpenGL. (#7144) --- externals/glad/Readme.md | 6 +++++ externals/glad/include/glad/glad.h | 27 ++++++++++++++++--- externals/glad/src/glad.c | 18 ++++++++++--- src/video_core/renderer_opengl/gl_driver.cpp | 3 +++ src/video_core/renderer_opengl/gl_driver.h | 15 +++++++++++ .../renderer_opengl/gl_shader_manager.cpp | 7 ++--- .../shader/generator/glsl_fs_shader_gen.cpp | 5 ++-- src/video_core/shader/generator/profile.h | 2 +- 8 files changed, 69 insertions(+), 14 deletions(-) diff --git a/externals/glad/Readme.md b/externals/glad/Readme.md index e503ac7a3..2afcc5b69 100644 --- a/externals/glad/Readme.md +++ b/externals/glad/Readme.md @@ -3,3 +3,9 @@ These files were generated by the [glad](https://github.com/Dav1dde/glad) OpenGL ``` python -m glad --profile core --out-path glad/ --api "gl=4.3,gles2=3.2" --generator=c ``` + +You can also generate the source using [this site](https://glad.dav1d.de/): +1. Select '4.3' for GL, '3.2' for GLES2, and 'Core' for Profile. +2. Input the currently supported extensions from [here](https://github.com/citra-emu/citra/blob/master/externals/glad/include/glad/glad.h#L9), plus any new required extensions. +3. Click Generate and download the generated source zip. +4. Unzip the new source over the current glad source files. \ No newline at end of file diff --git a/externals/glad/include/glad/glad.h b/externals/glad/include/glad/glad.h index 84561395b..d6333228d 100644 --- a/externals/glad/include/glad/glad.h +++ b/externals/glad/include/glad/glad.h @@ -1,6 +1,6 @@ /* - OpenGL, OpenGL ES loader generated by glad 0.1.34 on Sat Aug 26 18:38:43 2023. + OpenGL, OpenGL ES loader generated by glad 0.1.36 on Fri Nov 10 04:24:01 2023. Language/Generator: C/C++ Specification: gl @@ -10,6 +10,7 @@ GL_AMD_blend_minmax_factor, GL_ARB_buffer_storage, GL_ARB_clear_texture, + GL_ARB_fragment_shader_interlock, GL_ARB_get_texture_sub_image, GL_ARB_texture_compression_bptc, GL_ARM_shader_framebuffer_fetch, @@ -17,16 +18,18 @@ GL_EXT_clip_cull_distance, GL_EXT_shader_framebuffer_fetch, GL_EXT_texture_compression_s3tc, - GL_NV_blend_minmax_factor + GL_INTEL_fragment_shader_ordering, + GL_NV_blend_minmax_factor, + GL_NV_fragment_shader_interlock Loader: True Local files: False Omit khrplatform: False Reproducible: False Commandline: - --profile="core" --api="gl=4.3,gles2=3.2" --generator="c" --spec="gl" --extensions="GL_AMD_blend_minmax_factor,GL_ARB_buffer_storage,GL_ARB_clear_texture,GL_ARB_get_texture_sub_image,GL_ARB_texture_compression_bptc,GL_ARM_shader_framebuffer_fetch,GL_EXT_buffer_storage,GL_EXT_clip_cull_distance,GL_EXT_shader_framebuffer_fetch,GL_EXT_texture_compression_s3tc,GL_NV_blend_minmax_factor" + --profile="core" --api="gl=4.3,gles2=3.2" --generator="c" --spec="gl" --extensions="GL_AMD_blend_minmax_factor,GL_ARB_buffer_storage,GL_ARB_clear_texture,GL_ARB_fragment_shader_interlock,GL_ARB_get_texture_sub_image,GL_ARB_texture_compression_bptc,GL_ARM_shader_framebuffer_fetch,GL_EXT_buffer_storage,GL_EXT_clip_cull_distance,GL_EXT_shader_framebuffer_fetch,GL_EXT_texture_compression_s3tc,GL_INTEL_fragment_shader_ordering,GL_NV_blend_minmax_factor,GL_NV_fragment_shader_interlock" Online: - https://glad.dav1d.de/#profile=core&language=c&specification=gl&loader=on&api=gl%3D4.3&api=gles2%3D3.2&extensions=GL_AMD_blend_minmax_factor&extensions=GL_ARB_buffer_storage&extensions=GL_ARB_clear_texture&extensions=GL_ARB_get_texture_sub_image&extensions=GL_ARB_texture_compression_bptc&extensions=GL_ARM_shader_framebuffer_fetch&extensions=GL_EXT_buffer_storage&extensions=GL_EXT_clip_cull_distance&extensions=GL_EXT_shader_framebuffer_fetch&extensions=GL_EXT_texture_compression_s3tc&extensions=GL_NV_blend_minmax_factor + https://glad.dav1d.de/#profile=core&language=c&specification=gl&loader=on&api=gl%3D4.3&api=gles2%3D3.2&extensions=GL_AMD_blend_minmax_factor&extensions=GL_ARB_buffer_storage&extensions=GL_ARB_clear_texture&extensions=GL_ARB_fragment_shader_interlock&extensions=GL_ARB_get_texture_sub_image&extensions=GL_ARB_texture_compression_bptc&extensions=GL_ARM_shader_framebuffer_fetch&extensions=GL_EXT_buffer_storage&extensions=GL_EXT_clip_cull_distance&extensions=GL_EXT_shader_framebuffer_fetch&extensions=GL_EXT_texture_compression_s3tc&extensions=GL_INTEL_fragment_shader_ordering&extensions=GL_NV_blend_minmax_factor&extensions=GL_NV_fragment_shader_interlock */ @@ -3384,6 +3387,10 @@ typedef void (APIENTRYP PFNGLCLEARTEXSUBIMAGEPROC)(GLuint texture, GLint level, GLAPI PFNGLCLEARTEXSUBIMAGEPROC glad_glClearTexSubImage; #define glClearTexSubImage glad_glClearTexSubImage #endif +#ifndef GL_ARB_fragment_shader_interlock +#define GL_ARB_fragment_shader_interlock 1 +GLAPI int GLAD_GL_ARB_fragment_shader_interlock; +#endif #ifndef GL_ARB_get_texture_sub_image #define GL_ARB_get_texture_sub_image 1 GLAPI int GLAD_GL_ARB_get_texture_sub_image; @@ -3406,10 +3413,18 @@ GLAPI int GLAD_GL_EXT_shader_framebuffer_fetch; #define GL_EXT_texture_compression_s3tc 1 GLAPI int GLAD_GL_EXT_texture_compression_s3tc; #endif +#ifndef GL_INTEL_fragment_shader_ordering +#define GL_INTEL_fragment_shader_ordering 1 +GLAPI int GLAD_GL_INTEL_fragment_shader_ordering; +#endif #ifndef GL_NV_blend_minmax_factor #define GL_NV_blend_minmax_factor 1 GLAPI int GLAD_GL_NV_blend_minmax_factor; #endif +#ifndef GL_NV_fragment_shader_interlock +#define GL_NV_fragment_shader_interlock 1 +GLAPI int GLAD_GL_NV_fragment_shader_interlock; +#endif #ifndef GL_ARM_shader_framebuffer_fetch #define GL_ARM_shader_framebuffer_fetch 1 GLAPI int GLAD_GL_ARM_shader_framebuffer_fetch; @@ -3437,6 +3452,10 @@ GLAPI int GLAD_GL_EXT_texture_compression_s3tc; #define GL_NV_blend_minmax_factor 1 GLAPI int GLAD_GL_NV_blend_minmax_factor; #endif +#ifndef GL_NV_fragment_shader_interlock +#define GL_NV_fragment_shader_interlock 1 +GLAPI int GLAD_GL_NV_fragment_shader_interlock; +#endif #ifdef __cplusplus } diff --git a/externals/glad/src/glad.c b/externals/glad/src/glad.c index 925bcaf54..5627de55c 100644 --- a/externals/glad/src/glad.c +++ b/externals/glad/src/glad.c @@ -1,6 +1,6 @@ /* - OpenGL, OpenGL ES loader generated by glad 0.1.34 on Sat Aug 26 18:38:43 2023. + OpenGL, OpenGL ES loader generated by glad 0.1.36 on Fri Nov 10 04:24:01 2023. Language/Generator: C/C++ Specification: gl @@ -10,6 +10,7 @@ GL_AMD_blend_minmax_factor, GL_ARB_buffer_storage, GL_ARB_clear_texture, + GL_ARB_fragment_shader_interlock, GL_ARB_get_texture_sub_image, GL_ARB_texture_compression_bptc, GL_ARM_shader_framebuffer_fetch, @@ -17,16 +18,18 @@ GL_EXT_clip_cull_distance, GL_EXT_shader_framebuffer_fetch, GL_EXT_texture_compression_s3tc, - GL_NV_blend_minmax_factor + GL_INTEL_fragment_shader_ordering, + GL_NV_blend_minmax_factor, + GL_NV_fragment_shader_interlock Loader: True Local files: False Omit khrplatform: False Reproducible: False Commandline: - --profile="core" --api="gl=4.3,gles2=3.2" --generator="c" --spec="gl" --extensions="GL_AMD_blend_minmax_factor,GL_ARB_buffer_storage,GL_ARB_clear_texture,GL_ARB_get_texture_sub_image,GL_ARB_texture_compression_bptc,GL_ARM_shader_framebuffer_fetch,GL_EXT_buffer_storage,GL_EXT_clip_cull_distance,GL_EXT_shader_framebuffer_fetch,GL_EXT_texture_compression_s3tc,GL_NV_blend_minmax_factor" + --profile="core" --api="gl=4.3,gles2=3.2" --generator="c" --spec="gl" --extensions="GL_AMD_blend_minmax_factor,GL_ARB_buffer_storage,GL_ARB_clear_texture,GL_ARB_fragment_shader_interlock,GL_ARB_get_texture_sub_image,GL_ARB_texture_compression_bptc,GL_ARM_shader_framebuffer_fetch,GL_EXT_buffer_storage,GL_EXT_clip_cull_distance,GL_EXT_shader_framebuffer_fetch,GL_EXT_texture_compression_s3tc,GL_INTEL_fragment_shader_ordering,GL_NV_blend_minmax_factor,GL_NV_fragment_shader_interlock" Online: - https://glad.dav1d.de/#profile=core&language=c&specification=gl&loader=on&api=gl%3D4.3&api=gles2%3D3.2&extensions=GL_AMD_blend_minmax_factor&extensions=GL_ARB_buffer_storage&extensions=GL_ARB_clear_texture&extensions=GL_ARB_get_texture_sub_image&extensions=GL_ARB_texture_compression_bptc&extensions=GL_ARM_shader_framebuffer_fetch&extensions=GL_EXT_buffer_storage&extensions=GL_EXT_clip_cull_distance&extensions=GL_EXT_shader_framebuffer_fetch&extensions=GL_EXT_texture_compression_s3tc&extensions=GL_NV_blend_minmax_factor + https://glad.dav1d.de/#profile=core&language=c&specification=gl&loader=on&api=gl%3D4.3&api=gles2%3D3.2&extensions=GL_AMD_blend_minmax_factor&extensions=GL_ARB_buffer_storage&extensions=GL_ARB_clear_texture&extensions=GL_ARB_fragment_shader_interlock&extensions=GL_ARB_get_texture_sub_image&extensions=GL_ARB_texture_compression_bptc&extensions=GL_ARM_shader_framebuffer_fetch&extensions=GL_EXT_buffer_storage&extensions=GL_EXT_clip_cull_distance&extensions=GL_EXT_shader_framebuffer_fetch&extensions=GL_EXT_texture_compression_s3tc&extensions=GL_INTEL_fragment_shader_ordering&extensions=GL_NV_blend_minmax_factor&extensions=GL_NV_fragment_shader_interlock */ #include @@ -860,6 +863,7 @@ PFNGLWAITSYNCPROC glad_glWaitSync = NULL; int GLAD_GL_AMD_blend_minmax_factor = 0; int GLAD_GL_ARB_buffer_storage = 0; int GLAD_GL_ARB_clear_texture = 0; +int GLAD_GL_ARB_fragment_shader_interlock = 0; int GLAD_GL_ARB_get_texture_sub_image = 0; int GLAD_GL_ARB_texture_compression_bptc = 0; int GLAD_GL_ARM_shader_framebuffer_fetch = 0; @@ -867,7 +871,9 @@ int GLAD_GL_EXT_buffer_storage = 0; int GLAD_GL_EXT_clip_cull_distance = 0; int GLAD_GL_EXT_shader_framebuffer_fetch = 0; int GLAD_GL_EXT_texture_compression_s3tc = 0; +int GLAD_GL_INTEL_fragment_shader_ordering = 0; int GLAD_GL_NV_blend_minmax_factor = 0; +int GLAD_GL_NV_fragment_shader_interlock = 0; PFNGLBUFFERSTORAGEPROC glad_glBufferStorage = NULL; PFNGLCLEARTEXIMAGEPROC glad_glClearTexImage = NULL; PFNGLCLEARTEXSUBIMAGEPROC glad_glClearTexSubImage = NULL; @@ -1509,11 +1515,14 @@ static int find_extensionsGL(void) { GLAD_GL_AMD_blend_minmax_factor = has_ext("GL_AMD_blend_minmax_factor"); GLAD_GL_ARB_buffer_storage = has_ext("GL_ARB_buffer_storage"); GLAD_GL_ARB_clear_texture = has_ext("GL_ARB_clear_texture"); + GLAD_GL_ARB_fragment_shader_interlock = has_ext("GL_ARB_fragment_shader_interlock"); GLAD_GL_ARB_get_texture_sub_image = has_ext("GL_ARB_get_texture_sub_image"); GLAD_GL_ARB_texture_compression_bptc = has_ext("GL_ARB_texture_compression_bptc"); GLAD_GL_EXT_shader_framebuffer_fetch = has_ext("GL_EXT_shader_framebuffer_fetch"); GLAD_GL_EXT_texture_compression_s3tc = has_ext("GL_EXT_texture_compression_s3tc"); + GLAD_GL_INTEL_fragment_shader_ordering = has_ext("GL_INTEL_fragment_shader_ordering"); GLAD_GL_NV_blend_minmax_factor = has_ext("GL_NV_blend_minmax_factor"); + GLAD_GL_NV_fragment_shader_interlock = has_ext("GL_NV_fragment_shader_interlock"); free_exts(); return 1; } @@ -1988,6 +1997,7 @@ static int find_extensionsGLES2(void) { GLAD_GL_EXT_shader_framebuffer_fetch = has_ext("GL_EXT_shader_framebuffer_fetch"); GLAD_GL_EXT_texture_compression_s3tc = has_ext("GL_EXT_texture_compression_s3tc"); GLAD_GL_NV_blend_minmax_factor = has_ext("GL_NV_blend_minmax_factor"); + GLAD_GL_NV_fragment_shader_interlock = has_ext("GL_NV_fragment_shader_interlock"); free_exts(); return 1; } diff --git a/src/video_core/renderer_opengl/gl_driver.cpp b/src/video_core/renderer_opengl/gl_driver.cpp index 60ee92f4d..ceb018f32 100644 --- a/src/video_core/renderer_opengl/gl_driver.cpp +++ b/src/video_core/renderer_opengl/gl_driver.cpp @@ -181,6 +181,9 @@ void Driver::CheckExtensionSupport() { ext_texture_compression_s3tc = GLAD_GL_EXT_texture_compression_s3tc; ext_shader_framebuffer_fetch = GLAD_GL_EXT_shader_framebuffer_fetch; arm_shader_framebuffer_fetch = GLAD_GL_ARM_shader_framebuffer_fetch; + arb_fragment_shader_interlock = GLAD_GL_ARB_fragment_shader_interlock; + nv_fragment_shader_interlock = GLAD_GL_NV_fragment_shader_interlock; + intel_fragment_shader_ordering = GLAD_GL_INTEL_fragment_shader_ordering; blend_minmax_factor = GLAD_GL_AMD_blend_minmax_factor || GLAD_GL_NV_blend_minmax_factor; is_suitable = GLAD_GL_VERSION_4_3 || GLAD_GL_ES_VERSION_3_1; } diff --git a/src/video_core/renderer_opengl/gl_driver.h b/src/video_core/renderer_opengl/gl_driver.h index 81c6d734d..430469da7 100644 --- a/src/video_core/renderer_opengl/gl_driver.h +++ b/src/video_core/renderer_opengl/gl_driver.h @@ -118,6 +118,18 @@ public: return arm_shader_framebuffer_fetch; } + bool HasArbFragmentShaderInterlock() const { + return arb_fragment_shader_interlock; + } + + bool HasNvFragmentShaderInterlock() const { + return nv_fragment_shader_interlock; + } + + bool HasIntelFragmentShaderOrdering() const { + return intel_fragment_shader_ordering; + } + /// Returns true if the implementation supports (NV/AMD)_blend_minmax_factor bool HasBlendMinMaxFactor() const { return blend_minmax_factor; @@ -146,6 +158,9 @@ private: bool arb_texture_compression_bptc{}; bool arm_shader_framebuffer_fetch{}; bool ext_shader_framebuffer_fetch{}; + bool arb_fragment_shader_interlock{}; + bool nv_fragment_shader_interlock{}; + bool intel_fragment_shader_ordering{}; bool blend_minmax_factor{}; std::string_view gl_version{}; diff --git a/src/video_core/renderer_opengl/gl_shader_manager.cpp b/src/video_core/renderer_opengl/gl_shader_manager.cpp index 9f62a2f6f..b2361731e 100644 --- a/src/video_core/renderer_opengl/gl_shader_manager.cpp +++ b/src/video_core/renderer_opengl/gl_shader_manager.cpp @@ -269,15 +269,16 @@ public: .has_clip_planes = driver.HasClipCullDistance(), .has_geometry_shader = true, .has_custom_border_color = true, - .has_fragment_shader_interlock = false, + .has_fragment_shader_interlock = driver.HasArbFragmentShaderInterlock(), + // TODO: This extension requires GLSL 450 / OpenGL 4.5 context. .has_fragment_shader_barycentric = false, .has_blend_minmax_factor = driver.HasBlendMinMaxFactor(), .has_minus_one_to_one_range = true, .has_logic_op = !driver.IsOpenGLES(), .has_gl_ext_framebuffer_fetch = driver.HasExtFramebufferFetch(), .has_gl_arm_framebuffer_fetch = driver.HasArmShaderFramebufferFetch(), - .has_gl_nv_fragment_shader_interlock = driver.GetVendor() == Vendor::Nvidia, - .has_gl_intel_fragment_shader_interlock = driver.GetVendor() == Vendor::Intel, + .has_gl_nv_fragment_shader_interlock = driver.HasNvFragmentShaderInterlock(), + .has_gl_intel_fragment_shader_ordering = driver.HasIntelFragmentShaderOrdering(), // TODO: This extension requires GLSL 450 / OpenGL 4.5 context. .has_gl_nv_fragment_shader_barycentric = false, .is_vulkan = false, diff --git a/src/video_core/shader/generator/glsl_fs_shader_gen.cpp b/src/video_core/shader/generator/glsl_fs_shader_gen.cpp index 50f57ed11..e49eff4c0 100644 --- a/src/video_core/shader/generator/glsl_fs_shader_gen.cpp +++ b/src/video_core/shader/generator/glsl_fs_shader_gen.cpp @@ -1234,10 +1234,11 @@ void FragmentModule::DefineExtensions() { out += "#extension GL_NV_fragment_shader_interlock : enable\n"; out += "#define beginInvocationInterlock beginInvocationInterlockNV\n"; out += "#define endInvocationInterlock endInvocationInterlockNV\n"; - } else if (profile.has_gl_intel_fragment_shader_interlock) { + } else if (profile.has_gl_intel_fragment_shader_ordering) { + // NOTE: Intel does not have an end function for this. out += "#extension GL_INTEL_fragment_shader_ordering : enable\n"; out += "#define beginInvocationInterlock beginFragmentShaderOrderingINTEL\n"; - out += "#define endInvocationInterlock\n"; + out += "#define endInvocationInterlock()\n"; } else { use_fragment_shader_interlock = false; } diff --git a/src/video_core/shader/generator/profile.h b/src/video_core/shader/generator/profile.h index 1c16bb787..819baae33 100644 --- a/src/video_core/shader/generator/profile.h +++ b/src/video_core/shader/generator/profile.h @@ -19,7 +19,7 @@ struct Profile { bool has_gl_ext_framebuffer_fetch{}; bool has_gl_arm_framebuffer_fetch{}; bool has_gl_nv_fragment_shader_interlock{}; - bool has_gl_intel_fragment_shader_interlock{}; + bool has_gl_intel_fragment_shader_ordering{}; bool has_gl_nv_fragment_shader_barycentric{}; bool is_vulkan{}; };