[Bf-blender-cvs] [171b36683a7] master: GPUExtensions: GL backend isolation
Clément Foucault
noreply at git.blender.org
Mon Sep 7 19:37:30 CEST 2020
Commit: 171b36683a774d70a8f25529858b9c002a2a317e
Author: Clément Foucault
Date: Mon Sep 7 18:52:30 2020 +0200
Branches: master
https://developer.blender.org/rB171b36683a774d70a8f25529858b9c002a2a317e
GPUExtensions: GL backend isolation
This is part of the Vulkan task T68990.
This commits changes a few things:
- Rename extensions to capabilities (but left the file name untouched).
- Cubemap mip render workaround detection is rewritten using gl
commands to avoid using the GPU API before initialization.
- Put all the capabilities that are only relevant for the GL backend
inside GLContext as static variables.
- Cleanup the names of the limit variables.
- Separate all GL related workaround search inside the GL module.
===================================================================
M source/blender/draw/intern/DRW_render.h
M source/blender/draw/intern/draw_manager.c
M source/blender/gpu/CMakeLists.txt
M source/blender/gpu/GPU_extensions.h
M source/blender/gpu/intern/gpu_extensions.cc
A source/blender/gpu/intern/gpu_extensions_private.hh
M source/blender/gpu/intern/gpu_init_exit.c
M source/blender/gpu/intern/gpu_private.h
M source/blender/gpu/intern/gpu_uniform_buffer.cc
M source/blender/gpu/opengl/gl_backend.cc
M source/blender/gpu/opengl/gl_backend.hh
M source/blender/gpu/opengl/gl_batch.cc
M source/blender/gpu/opengl/gl_context.hh
M source/blender/gpu/opengl/gl_drawlist.cc
M source/blender/gpu/opengl/gl_framebuffer.cc
M source/blender/gpu/opengl/gl_shader.cc
M source/blender/gpu/opengl/gl_texture.cc
M source/blender/gpu/opengl/gl_uniform_buffer.cc
===================================================================
diff --git a/source/blender/draw/intern/DRW_render.h b/source/blender/draw/intern/DRW_render.h
index 680636f9e87..e154a52b32f 100644
--- a/source/blender/draw/intern/DRW_render.h
+++ b/source/blender/draw/intern/DRW_render.h
@@ -721,7 +721,6 @@ void DRW_state_lock(DRWState state);
void DRW_select_load_id(uint id);
/* Draw State */
-void DRW_state_dfdy_factors_get(float dfdyfac[2]);
bool DRW_state_is_fbo(void);
bool DRW_state_is_select(void);
bool DRW_state_is_depth(void);
diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c
index 09ce16efcc2..49780f59db3 100644
--- a/source/blender/draw/intern/draw_manager.c
+++ b/source/blender/draw/intern/draw_manager.c
@@ -2496,11 +2496,6 @@ void DRW_draw_depth_object(
/** \name Draw Manager State (DRW_state)
* \{ */
-void DRW_state_dfdy_factors_get(float dfdyfac[2])
-{
- GPU_get_dfdy_factors(dfdyfac);
-}
-
/**
* When false, drawing doesn't output to a pixel buffer
* eg: Occlusion queries, or when we have setup a context to draw in already.
diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt
index 47ce113230b..358bd045c2f 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -137,6 +137,7 @@ set(SRC
intern/gpu_codegen.h
intern/gpu_context_private.hh
intern/gpu_drawlist_private.hh
+ intern/gpu_extensions_private.hh
intern/gpu_framebuffer_private.hh
intern/gpu_immediate_private.hh
intern/gpu_index_buffer_private.hh
diff --git a/source/blender/gpu/GPU_extensions.h b/source/blender/gpu/GPU_extensions.h
index 35967ac304f..dd0a2ec9f39 100644
--- a/source/blender/gpu/GPU_extensions.h
+++ b/source/blender/gpu/GPU_extensions.h
@@ -41,14 +41,10 @@ int GPU_max_color_texture_samples(void);
int GPU_max_cube_map_size(void);
int GPU_max_ubo_binds(void);
int GPU_max_ubo_size(void);
-void GPU_get_dfdy_factors(float fac[2]);
-bool GPU_arb_base_instance_is_supported(void);
bool GPU_arb_texture_cube_map_array_is_supported(void);
bool GPU_mip_render_workaround(void);
bool GPU_depth_blitting_workaround(void);
-bool GPU_unused_fb_slot_workaround(void);
bool GPU_use_main_context_workaround(void);
-bool GPU_texture_copy_workaround(void);
bool GPU_crappy_amd_driver(void);
int GPU_texture_size_with_limit(int res);
diff --git a/source/blender/gpu/intern/gpu_extensions.cc b/source/blender/gpu/intern/gpu_extensions.cc
index ac7748e6430..168d2fb3fbb 100644
--- a/source/blender/gpu/intern/gpu_extensions.cc
+++ b/source/blender/gpu/intern/gpu_extensions.cc
@@ -24,381 +24,95 @@
* with checks for drivers and GPU support.
*/
-#include "BLI_math_base.h"
-#include "BLI_math_vector.h"
-#include "BLI_utildefines.h"
-
-#include "BKE_global.h"
-#include "MEM_guardedalloc.h"
-
#include "DNA_userdef_types.h"
#include "GPU_extensions.h"
-#include "GPU_framebuffer.h"
-#include "GPU_glew.h"
-#include "GPU_platform.h"
-#include "GPU_texture.h"
-
-#include "intern/gpu_private.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#ifdef WIN32
-# include "BLI_winstuff.h"
-#endif
-
-/* Extensions support */
-
-/* -- extension: version of GL that absorbs it
- * EXT_gpu_shader4: 3.0
- * ARB_framebuffer object: 3.0
- * EXT_framebuffer_multisample_blit_scaled: ???
- * ARB_draw_instanced: 3.1
- * ARB_texture_multisample: 3.2
- * ARB_texture_query_lod: 4.0
- */
-
-static struct GPUGlobal {
- GLint maxtexsize;
- GLint maxtex3dsize;
- GLint maxtexlayers;
- GLint maxcubemapsize;
- GLint maxtextures;
- GLint maxtexturesfrag;
- GLint maxtexturesgeom;
- GLint maxtexturesvert;
- GLint maxubosize;
- GLint maxubobinds;
- int samples_color_texture_max;
- /* workaround for different calculation of dfdy factors on GPUs. Some GPUs/drivers
- * calculate dfdy in shader differently when drawing to an off-screen buffer. First
- * number is factor on screen and second is off-screen */
- float dfdyfactors[2];
- /* Some Intel drivers have limited support for `GLEW_ARB_base_instance` so in
- * these cases it is best to indicate that it is not supported. See T67951 */
- bool glew_arb_base_instance_is_supported;
- /* Cubemap Array support. */
- bool glew_arb_texture_cube_map_array_is_supported;
- /* Some Intel drivers have issues with using mips as framebuffer targets if
- * GL_TEXTURE_MAX_LEVEL is higher than the target mip.
- * We need a workaround in this cases. */
- bool mip_render_workaround;
- /* There is an issue with the #glBlitFramebuffer on MacOS with radeon pro graphics.
- * Blitting depth with#GL_DEPTH24_STENCIL8 is buggy so the workaround is to use
- * #GPU_DEPTH32F_STENCIL8. Then Blitting depth will work but blitting stencil will
- * still be broken. */
- bool depth_blitting_workaround;
- /* Crappy driver don't know how to map framebuffer slot to output vars...
- * We need to have no "holes" in the output buffer slots. */
- bool unused_fb_slot_workaround;
- bool broken_amd_driver;
- /* Some crappy Intel drivers don't work well with shaders created in different
- * rendering contexts. */
- bool use_main_context_workaround;
- /* Intel drivers exhibit artifacts when using #glCopyImageSubData & workbench anti-aliasing.
- * (see T76273) */
- bool texture_copy_workaround;
-} GG = {1, 0};
-
-static void gpu_detect_mip_render_workaround(void)
-{
- int cube_size = 2;
- float *source_pix = (float *)MEM_callocN(sizeof(float[4][6]) * cube_size * cube_size, __func__);
- float clear_color[4] = {1.0f, 0.5f, 0.0f, 0.0f};
- GPUTexture *tex = GPU_texture_create_cube(__func__, cube_size, 2, GPU_RGBA16F, source_pix);
- MEM_freeN(source_pix);
+#include "gpu_extensions_private.hh"
- GPU_texture_bind(tex, 0);
- GPU_texture_generate_mipmap(tex);
- glTexParameteri(GPU_texture_target(tex), GL_TEXTURE_BASE_LEVEL, 0);
- glTexParameteri(GPU_texture_target(tex), GL_TEXTURE_MAX_LEVEL, 0);
- GPU_texture_unbind(tex);
+#include "gl_backend.hh" /* TODO remove */
- GPUFrameBuffer *fb = GPU_framebuffer_create(__func__);
- GPU_framebuffer_texture_attach(fb, tex, 0, 1);
- GPU_framebuffer_bind(fb);
- GPU_framebuffer_clear_color(fb, clear_color);
- GPU_framebuffer_restore();
- GPU_framebuffer_free(fb);
+namespace blender::gpu {
- float *data = (float *)GPU_texture_read(tex, GPU_DATA_FLOAT, 1);
- GG.mip_render_workaround = !equals_v4v4(clear_color, data);
+GPUCapabilities GCaps;
- MEM_freeN(data);
- GPU_texture_free(tex);
}
-/* GPU Extensions */
+using namespace blender::gpu;
+
+/* -------------------------------------------------------------------- */
+/** \name Capabilities
+ * \{ */
int GPU_max_texture_size(void)
{
- return GG.maxtexsize;
+ return GCaps.max_texture_size;
}
-int GPU_max_texture_3d_size(void)
+int GPU_texture_size_with_limit(int res)
{
- return GG.maxtex3dsize;
+ int size = GPU_max_texture_size();
+ int reslimit = (U.glreslimit != 0) ? min_ii(U.glreslimit, size) : size;
+ return min_ii(reslimit, res);
}
int GPU_max_texture_layers(void)
{
- return GG.maxtexlayers;
-}
-
-int GPU_max_textures(void)
-{
- return GG.maxtextures;
-}
-
-int GPU_max_textures_frag(void)
-{
- return GG.maxtexturesfrag;
-}
-
-int GPU_max_textures_geom(void)
-{
- return GG.maxtexturesgeom;
+ return GCaps.max_texture_layers;
}
int GPU_max_textures_vert(void)
{
- return GG.maxtexturesvert;
-}
-
-int GPU_max_color_texture_samples(void)
-{
- return GG.samples_color_texture_max;
-}
-
-int GPU_max_cube_map_size(void)
-{
- return GG.maxcubemapsize;
-}
-
-int GPU_max_ubo_binds(void)
-{
- return GG.maxubobinds;
+ return GCaps.max_textures_vert;
}
-int GPU_max_ubo_size(void)
+int GPU_max_textures_geom(void)
{
- return GG.maxubosize;
+ return GCaps.max_textures_geom;
}
-void GPU_get_dfdy_factors(float fac[2])
+int GPU_max_textures_frag(void)
{
- copy_v2_v2(fac, GG.dfdyfactors);
+ return GCaps.max_textures_frag;
}
-bool GPU_arb_base_instance_is_supported(void)
+int GPU_max_textures(void)
{
- return GG.glew_arb_base_instance_is_supported;
+ return GCaps.max_textures;
}
bool GPU_arb_texture_cube_map_array_is_supported(void)
{
- return GG.glew_arb_texture_cube_map_array_is_supported;
+ /* FIXME bad level call. */
+ return GLContext::texture_cube_map_array_support;
}
bool GPU_mip_render_workaround(void)
{
- return GG.mip_render_workaround;
+ return GCaps.mip_render_workaround;
}
bool GPU_depth_blitting_workaround(void)
{
- return GG.depth_blitting_workaround;
-}
-
-bool GPU_unused_fb_slot_workaround(void)
-{
- return GG.unused_fb_slot_workaround;
+ return GCaps.depth_blitting_workaround;
}
bool GPU_use_main_context_workaround(void)
{
- return GG.use_main_context_workaround;
-}
-
-bool GPU_texture_copy_workaround(void)
-{
- return GG.texture_copy_workaround;
+ return GCaps.use_main_context_workaround;
}
bool GPU_crappy_amd_driver(void)
{
/* Currently are the same drivers with the `unused_fb_slot` problem. */
- return GG.broken_amd_driver;
-}
-
-int GPU_texture_size_with_limit(int res)
-{
- int size = GPU_max_texture_size();
- int reslimit = (U.glreslimit != 0) ? min_ii(U.glreslimit, size) : size;
- return min_ii(reslimit, res);
+ return GCaps.broken_amd_driver;
}
-void gpu_extensions_init(void)
-{
- /* during 2.8 development each platform has its own OpenGL minimum requirements
- * final 2.8 release will be unified on OpenGL 3.3 core profile, no required extensions
- * see developer.blender.org/T49012 for details
- */
- BLI_assert(GLEW_VERSION_3_3);
-
- glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &GG.maxtexturesfrag);
- glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &GG.maxtexturesvert);
- glGetIntegerv(GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS, &GG.maxtexturesgeom);
- glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &GG.maxtextures);
-
- glGetIntegerv(GL_MAX_TEXTURE_SIZE, &GG.maxtexsize);
- glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE, &GG.maxtex3dsize);
- glGetIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS, &GG.maxtexlayers);
- glGetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE, &GG.maxcubemapsize);
+/** \} */
- glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_BLOCKS, &GG.maxubobinds);
- glGetIntegerv(GL_MAX_UNIFORM_BLOCK_SIZE, &GG.maxubosize);
-
- glGetIntegerv(GL_MAX_COLOR_TEXTURE_SAMPLES, &GG.sa
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list