[Bf-blender-cvs] [c766d9b9dc5] master: GPUTexture: GL Backend Isolation
Clément Foucault
noreply at git.blender.org
Sat Sep 5 17:50:08 CEST 2020
Commit: c766d9b9dc5661693a58e01a3637f15197c2fe59
Author: Clément Foucault
Date: Sat Sep 5 17:29:51 2020 +0200
Branches: master
https://developer.blender.org/rBc766d9b9dc5661693a58e01a3637f15197c2fe59
GPUTexture: GL Backend Isolation
This is a massive cleanup needed for vulkan support T68990. It provides:
- More meaningful enums with conversion functions.
- Less hacky supports of arrays and cubemaps (all considered layered).
- More inline with the stateless design of vulkan and modern GL.
- Methods Fallbacks are using framebuffer functions that are wrapped
instead of implementing inside the texture module.
What is not in there:
- API change.
- Samplers support (breaks a few effects).
# Conflicts:
# source/blender/gpu/GPU_texture.h
===================================================================
M source/blender/gpu/GPU_texture.h
M source/blender/gpu/intern/gpu_state_private.hh
M source/blender/gpu/intern/gpu_texture.cc
M source/blender/gpu/intern/gpu_texture_private.hh
M source/blender/gpu/opengl/gl_context.hh
M source/blender/gpu/opengl/gl_debug.cc
M source/blender/gpu/opengl/gl_debug.hh
M source/blender/gpu/opengl/gl_state.cc
M source/blender/gpu/opengl/gl_state.hh
M source/blender/gpu/opengl/gl_texture.cc
M source/blender/gpu/opengl/gl_texture.hh
===================================================================
diff --git a/source/blender/gpu/GPU_texture.h b/source/blender/gpu/GPU_texture.h
index 8cc5936fac9..e56866c5259 100644
--- a/source/blender/gpu/GPU_texture.h
+++ b/source/blender/gpu/GPU_texture.h
@@ -44,6 +44,7 @@ typedef struct GPUTexture GPUTexture;
* - All states are created at startup to avoid runtime costs.
*/
typedef enum eGPUSamplerState {
+ GPU_SAMPLER_DEFAULT = 0,
GPU_SAMPLER_FILTER = (1 << 0),
GPU_SAMPLER_MIPMAP = (1 << 1),
GPU_SAMPLER_REPEAT_S = (1 << 2),
@@ -52,8 +53,11 @@ typedef enum eGPUSamplerState {
GPU_SAMPLER_CLAMP_BORDER = (1 << 5), /* Clamp to border color instead of border texel. */
GPU_SAMPLER_COMPARE = (1 << 6),
GPU_SAMPLER_ANISO = (1 << 7),
+ GPU_SAMPLER_ICON = (1 << 8),
+
+ GPU_SAMPLER_REPEAT = (GPU_SAMPLER_REPEAT_S | GPU_SAMPLER_REPEAT_T | GPU_SAMPLER_REPEAT_R),
/* Don't use that. */
- GPU_SAMPLER_MAX = (1 << 8),
+ GPU_SAMPLER_MAX = (GPU_SAMPLER_ICON + 1),
} eGPUSamplerState;
ENUM_OPERATORS(eGPUSamplerState)
@@ -209,12 +213,6 @@ GPUTexture *GPU_texture_create_1d_array(
int w, int h, eGPUTextureFormat tex_format, const float *pixels, char err_out[256]);
GPUTexture *GPU_texture_create_2d(
int w, int h, eGPUTextureFormat tex_format, const float *pixels, char err_out[256]);
-GPUTexture *GPU_texture_create_2d_multisample(int w,
- int h,
- eGPUTextureFormat tex_format,
- const float *pixels,
- int samples,
- char err_out[256]);
GPUTexture *GPU_texture_create_2d_array(
int w, int h, int d, eGPUTextureFormat tex_format, const float *pixels, char err_out[256]);
GPUTexture *GPU_texture_create_3d(
@@ -227,7 +225,6 @@ GPUTexture *GPU_texture_create_cube_array(
int w, int d, eGPUTextureFormat tex_format, const float *pixels, char err_out[256]);
GPUTexture *GPU_texture_create_from_vertbuf(struct GPUVertBuf *vert);
-GPUTexture *GPU_texture_create_buffer(eGPUTextureFormat tex_format, const uint buffer);
GPUTexture *GPU_texture_create_compressed(
int w, int h, int miplen, eGPUTextureFormat format, const void *data);
@@ -286,7 +283,6 @@ int GPU_texture_height(const GPUTexture *tex);
int GPU_texture_orig_width(const GPUTexture *tex);
int GPU_texture_orig_height(const GPUTexture *tex);
void GPU_texture_orig_size_set(GPUTexture *tex, int w, int h);
-int GPU_texture_layers(const GPUTexture *tex);
eGPUTextureFormat GPU_texture_format(const GPUTexture *tex);
int GPU_texture_samples(const GPUTexture *tex);
bool GPU_texture_array(const GPUTexture *tex);
diff --git a/source/blender/gpu/intern/gpu_state_private.hh b/source/blender/gpu/intern/gpu_state_private.hh
index 61234c4612c..6ce240df108 100644
--- a/source/blender/gpu/intern/gpu_state_private.hh
+++ b/source/blender/gpu/intern/gpu_state_private.hh
@@ -26,6 +26,8 @@
#include "GPU_state.h"
+#include "gpu_texture_private.hh"
+
#include <cstring>
namespace blender {
@@ -160,6 +162,10 @@ class GPUStateManager {
virtual ~GPUStateManager(){};
virtual void apply_state(void) = 0;
+
+ virtual void texture_bind(Texture *tex, eGPUSamplerState sampler, int unit) = 0;
+ virtual void texture_unbind(Texture *tex) = 0;
+ virtual void texture_unbind_all(void) = 0;
};
} // namespace gpu
diff --git a/source/blender/gpu/intern/gpu_texture.cc b/source/blender/gpu/intern/gpu_texture.cc
index ced9ea5a498..9d431ef4648 100644
--- a/source/blender/gpu/intern/gpu_texture.cc
+++ b/source/blender/gpu/intern/gpu_texture.cc
@@ -21,28 +21,12 @@
* \ingroup gpu
*/
-#include <string.h>
+#include "BLI_string.h"
-#include "MEM_guardedalloc.h"
-
-#include "DNA_image_types.h"
-#include "DNA_userdef_types.h"
-
-#include "BLI_blenlib.h"
-#include "BLI_math_base.h"
-#include "BLI_utildefines.h"
-
-#include "BKE_global.h"
-
-#include "GPU_batch.h"
-#include "GPU_context.h"
-#include "GPU_debug.h"
-#include "GPU_extensions.h"
#include "GPU_framebuffer.h"
-#include "GPU_glew.h"
-#include "GPU_platform.h"
#include "GPU_texture.h"
+#include "gpu_backend.hh"
#include "gpu_context_private.hh"
#include "gpu_framebuffer_private.hh"
@@ -62,1478 +46,380 @@ Texture::Texture(const char *name)
else {
name_[0] = '\0';
}
-}
-
-Texture::~Texture()
-{
-}
-
-/** \} */
-
-/* -------------------------------------------------------------------- */
-/** \name Operation
- * \{ */
-
-void Texture::attach_to(FrameBuffer *)
-{
-}
-
-/** \} */
-
-} // namespace blender::gpu
-
-/* -------------------------------------------------------------------- */
-/** \name C-API
- * \{ */
-
-using namespace blender::gpu;
-
-static struct GPUTextureGlobal {
- /** Texture used in place of invalid textures (not loaded correctly, missing). */
- GPUTexture *invalid_tex_1D;
- GPUTexture *invalid_tex_2D;
- GPUTexture *invalid_tex_3D;
- /** Sampler objects used to replace internal texture parameters. */
- GLuint samplers[GPU_SAMPLER_MAX];
- GLuint icon_sampler;
-} GG = {NULL};
-
-/* Maximum number of FBOs a texture can be attached to. */
-#define GPU_TEX_MAX_FBO_ATTACHED 12
-
-typedef enum eGPUTextureFormatFlag {
- GPU_FORMAT_DEPTH = (1 << 0),
- GPU_FORMAT_STENCIL = (1 << 1),
- GPU_FORMAT_INTEGER = (1 << 2),
- GPU_FORMAT_FLOAT = (1 << 3),
-
- GPU_FORMAT_1D = (1 << 10),
- GPU_FORMAT_2D = (1 << 11),
- GPU_FORMAT_3D = (1 << 12),
- GPU_FORMAT_CUBE = (1 << 13),
- GPU_FORMAT_ARRAY = (1 << 14),
-} eGPUTextureFormatFlag;
-
-ENUM_OPERATORS(eGPUTextureFormatFlag)
-
-/* GPUTexture */
-struct GPUTexture {
- int w, h, d; /* width/height/depth */
- int orig_w, orig_h; /* width/height (of source data), optional. */
- int number; /* Texture unit to which this texture is bound. */
- int refcount; /* reference count */
- GLenum target; /* GL_TEXTURE_* */
- GLenum target_base; /* same as target, (but no multisample)
- * use it for unbinding */
- GLuint bindcode; /* opengl identifier for texture */
-
- eGPUTextureFormat format;
- eGPUTextureFormatFlag format_flag;
- eGPUSamplerState sampler_state; /* Internal Sampler state. */
-
- int mipmaps; /* number of mipmaps */
- int components; /* number of color/alpha channels */
- int samples; /* number of samples for multisamples textures. 0 if not multisample target */
-
- int fb_attachment[GPU_TEX_MAX_FBO_ATTACHED];
- GPUFrameBuffer *fb[GPU_TEX_MAX_FBO_ATTACHED];
- /* Legacy workaround for texture copy. */
- GLuint copy_fb;
- GPUContext *copy_fb_ctx;
-};
-using namespace blender;
-using namespace blender::gpu;
-
-static uint gpu_get_bytesize(eGPUTextureFormat data_type);
-static void gpu_texture_framebuffer_ensure(GPUTexture *tex);
-
-/* ------ Memory Management ------- */
-/* Records every texture allocation / free
- * to estimate the Texture Pool Memory consumption */
-static uint memory_usage = 0;
-
-static uint gpu_texture_memory_footprint_compute(GPUTexture *tex)
-{
- uint memsize;
- const uint bytesize = gpu_get_bytesize(tex->format);
- const int samp = max_ii(tex->samples, 1);
- switch (tex->target_base) {
- case GL_TEXTURE_1D:
- case GL_TEXTURE_BUFFER:
- memsize = bytesize * tex->w * samp;
- break;
- case GL_TEXTURE_1D_ARRAY:
- case GL_TEXTURE_2D:
- memsize = bytesize * tex->w * tex->h * samp;
- break;
- case GL_TEXTURE_2D_ARRAY:
- case GL_TEXTURE_3D:
- memsize = bytesize * tex->w * tex->h * tex->d * samp;
- break;
- case GL_TEXTURE_CUBE_MAP:
- memsize = bytesize * 6 * tex->w * tex->h * samp;
- break;
- case GL_TEXTURE_CUBE_MAP_ARRAY_ARB:
- memsize = bytesize * 6 * tex->w * tex->h * tex->d * samp;
- break;
- default:
- BLI_assert(0);
- return 0;
- }
- if (tex->mipmaps != 0) {
- /* Just to get an idea of the memory used here is computed
- * as if the maximum number of mipmaps was generated. */
- memsize += memsize / 3;
+ for (int i = 0; i < GPU_TEX_MAX_FBO_ATTACHED; i++) {
+ fb[i] = NULL;
}
-
- return memsize;
}
-static void gpu_texture_memory_footprint_add(GPUTexture *tex)
-{
- memory_usage += gpu_texture_memory_footprint_compute(tex);
-}
-
-static void gpu_texture_memory_footprint_remove(GPUTexture *tex)
-{
- memory_usage -= gpu_texture_memory_footprint_compute(tex);
-}
-
-uint GPU_texture_memory_usage_get(void)
-{
- return memory_usage;
-}
-
-/* -------------------------------- */
-
-static const char *gl_enum_to_str(GLenum e)
+Texture::~Texture()
{
-#define ENUM_TO_STRING(e) \
- case GL_##e: { \
- return STRINGIFY_ARG(e); \
+ for (int i = 0; i < GPU_TEX_MAX_FBO_ATTACHED; i++) {
+ if (fb[i] != NULL) {
+ FrameBuffer *framebuffer = reinterpret_cast<FrameBuffer *>(fb[i]);
+ framebuffer->attachment_set((GPUAttachmentType)fb_attachment[i], GPU_ATTACHMENT_NONE);
+ }
}
-
- switch (e) {
- ENUM_TO_STRING(TEXTURE_CUBE_MAP);
- ENUM_TO_STRING(TEXTURE_CUBE_MAP_ARRAY);
- ENUM_TO_STRING(TEXTURE_2D);
- ENUM_TO_STRING(TEXTURE_2D_ARRAY);
- ENUM_TO_STRING(TEXTURE_1D);
- ENUM_TO_STRING(TEXTURE_1D_ARRAY);
- ENUM_TO_STRING(TEXTURE_3D);
- ENUM_TO_STRING(TEXTURE_2D_MULTISAMPLE);
- ENUM_TO_STRING(RGBA32F);
- ENUM_TO_STRING(RGBA16F);
- ENUM_TO_STRING(RGBA16UI);
- ENUM_TO_STRING(RGBA16I);
- ENUM_TO_STRING(RGBA16);
- ENUM_TO_STRING(RGBA8UI);
- ENUM_TO_STRING(RGBA8I);
- ENUM_TO_STRING(RGBA8);
- ENUM_TO_STRING(RGB16F);
- ENUM_TO_STRING(RG32F);
- ENUM_TO_STRING(RG16F);
- ENUM_TO_STRING(RG16UI);
- ENUM_TO_STRING(RG16I);
- ENUM_TO_STRING(RG16);
- ENUM_TO_STRING(RG8UI);
- ENUM_TO_STRING(RG8I);
- ENUM_TO_STRING(RG8);
- ENUM_TO_STRING(R8UI);
- ENUM_TO_STRING(R8I);
- ENUM_TO_STRING(R8);
- ENUM_TO_STRING(R32F);
- ENUM_TO_STRING(R32UI);
- ENUM_TO_STRING(R32I);
- ENUM_TO_STRING(R16F);
- ENUM_TO_STRING(R16UI);
- ENUM_TO_STRING(R16I);
- ENUM_TO_STRING(R16);
- ENUM_TO_STRING(R11F_G11F_B10F);
- ENUM_TO_STRING(SRGB8_ALPHA8);
- ENUM_TO_STRING(DEPTH24_STENCIL8);
- ENUM_TO_STRING(DEPTH32F_STENCIL8);
- ENUM_TO_STRING(DEPTH_COMPONENT32F);
- ENUM_TO_STRING(DEPTH_COMPONENT24);
- ENUM_TO_STRIN
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list