[Bf-blender-cvs] [bc15ec0896c] blender2.8: GPUFramebuffer: Refactor (Part 2)
Clément Foucault
noreply at git.blender.org
Sun Mar 25 21:33:24 CEST 2018
Commit: bc15ec0896c2deba2e2a45581fd0f408d4906df4
Author: Clément Foucault
Date: Sun Mar 25 17:46:48 2018 +0200
Branches: blender2.8
https://developer.blender.org/rBbc15ec0896c2deba2e2a45581fd0f408d4906df4
GPUFramebuffer: Refactor (Part 2)
This refactor modernise the use of framebuffers.
It also touches a lot of files so breaking down changes we have:
- GPUTexture: Allow textures to be attached to more than one GPUFrameBuffer.
This allows to create and configure more FBO without the need to attach
and detach texture at drawing time.
- GPUFrameBuffer: The wrapper starts to mimic opengl a bit closer. This
allows to configure the framebuffer inside a context other than the one
that will be rendering the framebuffer. We do the actual configuration
when binding the FBO. We also Keep track of config validity and save
drawbuffers state in the FBO. We remove the different bind/unbind
functions. These make little sense now that we have separate contexts.
- DRWFrameBuffer: We replace DRW_framebuffer functions by GPU_framebuffer
ones to avoid another layer of abstraction. We move the DRW convenience
functions to GPUFramebuffer instead and even add new ones. The MACRO
GPU_framebuffer_ensure_config is pretty much all you need to create and
config a GPUFramebuffer.
- DRWTexture: Due to the removal of DRWFrameBuffer, we needed to create
functions to create textures for thoses framebuffers. Pool textures are
now using default texture parameters for the texture type asked.
- DRWManager: Make sure no framebuffer object is bound when doing cache
filling.
- GPUViewport: Add new color_only_fb and depth_only_fb along with FB API
usage update. This let draw engines render to color/depth only target
and without the need to attach/detach textures.
- WM_window: Assert when a framebuffer is bound when changing context.
This balance the fact we are not track ogl context inside GPUFramebuffer.
- Eevee, Clay, Mode engines: Update to new API. This comes with a lot of
code simplification.
This also come with some cleanups in some engine codes.
===================================================================
M source/blender/draw/CMakeLists.txt
M source/blender/draw/DRW_engine.h
M source/blender/draw/engines/clay/clay_engine.c
M source/blender/draw/engines/clay/shaders/clay_frag.glsl
M source/blender/draw/engines/eevee/eevee_bloom.c
M source/blender/draw/engines/eevee/eevee_data.c
M source/blender/draw/engines/eevee/eevee_depth_of_field.c
M source/blender/draw/engines/eevee/eevee_effects.c
M source/blender/draw/engines/eevee/eevee_engine.c
M source/blender/draw/engines/eevee/eevee_lightprobes.c
M source/blender/draw/engines/eevee/eevee_lights.c
M source/blender/draw/engines/eevee/eevee_materials.c
M source/blender/draw/engines/eevee/eevee_mist.c
M source/blender/draw/engines/eevee/eevee_motion_blur.c
M source/blender/draw/engines/eevee/eevee_occlusion.c
M source/blender/draw/engines/eevee/eevee_private.h
M source/blender/draw/engines/eevee/eevee_render.c
M source/blender/draw/engines/eevee/eevee_screen_raytrace.c
M source/blender/draw/engines/eevee/eevee_subsurface.c
M source/blender/draw/engines/eevee/eevee_temporal_sampling.c
M source/blender/draw/engines/eevee/eevee_volumes.c
M source/blender/draw/engines/eevee/shaders/bsdf_common_lib.glsl
M source/blender/draw/intern/DRW_render.h
M source/blender/draw/intern/draw_manager.c
D source/blender/draw/intern/draw_manager_framebuffer.c
M source/blender/draw/intern/draw_manager_texture.c
M source/blender/draw/modes/edit_mesh_mode.c
M source/blender/draw/modes/object_mode.c
M source/blender/gpu/GPU_framebuffer.h
M source/blender/gpu/GPU_texture.h
M source/blender/gpu/intern/gpu_framebuffer.c
M source/blender/gpu/intern/gpu_lamp.c
M source/blender/gpu/intern/gpu_texture.c
M source/blender/gpu/intern/gpu_viewport.c
M source/blender/windowmanager/intern/wm_window.c
===================================================================
diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt
index f7d3a37246e..eb66e9c20ea 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -66,7 +66,6 @@ set(SRC
intern/draw_manager.c
intern/draw_manager_data.c
intern/draw_manager_exec.c
- intern/draw_manager_framebuffer.c
intern/draw_manager_shader.c
intern/draw_manager_text.c
intern/draw_manager_texture.c
diff --git a/source/blender/draw/DRW_engine.h b/source/blender/draw/DRW_engine.h
index cc4c0ed10e8..e42b5a49d64 100644
--- a/source/blender/draw/DRW_engine.h
+++ b/source/blender/draw/DRW_engine.h
@@ -58,6 +58,8 @@ struct WorkSpace;
/* Buffer and textures used by the viewport by default */
typedef struct DefaultFramebufferList {
struct GPUFrameBuffer *default_fb;
+ struct GPUFrameBuffer *color_only_fb;
+ struct GPUFrameBuffer *depth_only_fb;
struct GPUFrameBuffer *multisample_fb;
} DefaultFramebufferList;
diff --git a/source/blender/draw/engines/clay/clay_engine.c b/source/blender/draw/engines/clay/clay_engine.c
index 382551b16e4..86ff52045db 100644
--- a/source/blender/draw/engines/clay/clay_engine.c
+++ b/source/blender/draw/engines/clay/clay_engine.c
@@ -148,14 +148,11 @@ typedef struct CLAY_PassList {
struct DRWPass *hair_pass;
} CLAY_PassList;
-typedef struct CLAY_TextureList {
- struct GPUTexture *color_copy; /* only used if fxaa */
-} CLAY_TextureList;
typedef struct CLAY_Data {
void *engine_type;
CLAY_FramebufferList *fbl;
- CLAY_TextureList *txl;
+ DRWViewportEmptyList *txl;
CLAY_PassList *psl;
CLAY_StorageList *stl;
} CLAY_Data;
@@ -201,6 +198,7 @@ typedef struct CLAY_PrivateData {
struct GPUTexture *depth_tx; /* ref only, not alloced */
struct GPUTexture *normal_tx; /* ref only, not alloced */
struct GPUTexture *id_tx; /* ref only, not alloced */
+ struct GPUTexture *color_copy; /* ref only, not alloced */
bool enable_deferred_path;
/* Ssao */
float winmat[4][4];
@@ -351,9 +349,9 @@ static struct GPUTexture *create_jitter_texture(int num_samples)
static void clay_engine_init(void *vedata)
{
CLAY_StorageList *stl = ((CLAY_Data *)vedata)->stl;
- CLAY_TextureList *txl = ((CLAY_Data *)vedata)->txl;
CLAY_FramebufferList *fbl = ((CLAY_Data *)vedata)->fbl;
CLAY_ViewLayerData *sldata = CLAY_view_layer_data_get();
+ DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
/* Create Texture Array */
if (!e_data.matcap_array) {
@@ -463,19 +461,29 @@ static void clay_engine_init(void *vedata)
}
}
- if (DRW_state_is_fbo()) {
+ /* FBO setup */
+ {
const float *viewport_size = DRW_viewport_size_get();
- DRWFboTexture texs[2] = {{&g_data->normal_tx, DRW_TEX_RG_8, DRW_TEX_TEMP},
- {&g_data->id_tx, DRW_TEX_R_16I, DRW_TEX_TEMP}};
- DRW_framebuffer_init(&fbl->prepass_fb, &draw_engine_clay_type,
- (int)viewport_size[0], (int)viewport_size[1],
- texs, 2);
+ const int size[2] = {(int)viewport_size[0], (int)viewport_size[1]};
+
+ g_data->normal_tx = DRW_texture_pool_query_2D(size[0], size[1], DRW_TEX_RG_8, &draw_engine_clay_type);
+ g_data->id_tx = DRW_texture_pool_query_2D(size[0], size[1], DRW_TEX_R_16I, &draw_engine_clay_type);
+
+ GPU_framebuffer_ensure_config(&fbl->prepass_fb, {
+ GPU_ATTACHMENT_TEXTURE(dtxl->depth),
+ GPU_ATTACHMENT_TEXTURE(g_data->normal_tx),
+ GPU_ATTACHMENT_TEXTURE(g_data->id_tx)
+ });
/* For FXAA */
- DRWFboTexture tex = {&txl->color_copy, DRW_TEX_RGBA_8, DRW_TEX_FILTER};
- DRW_framebuffer_init(&fbl->antialias_fb, &draw_engine_clay_type,
- (int)viewport_size[0], (int)viewport_size[1],
- &tex, 1);
+ /* TODO(fclem): OPTI: we could merge normal_tx and id_tx into a DRW_TEX_RGBA_8
+ * and reuse it for the fxaa target. */
+ g_data->color_copy = DRW_texture_pool_query_2D(size[0], size[1], DRW_TEX_RGBA_8, &draw_engine_clay_type);
+
+ GPU_framebuffer_ensure_config(&fbl->antialias_fb, {
+ GPU_ATTACHMENT_NONE,
+ GPU_ATTACHMENT_TEXTURE(g_data->color_copy)
+ });
}
/* SSAO setup */
@@ -809,7 +817,6 @@ static void clay_cache_init(void *vedata)
DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
CLAY_PassList *psl = ((CLAY_Data *)vedata)->psl;
CLAY_StorageList *stl = ((CLAY_Data *)vedata)->stl;
- CLAY_TextureList *txl = ((CLAY_Data *)vedata)->txl;
/* Disable AO unless a material needs it. */
stl->g_data->enable_deferred_path = false;
@@ -854,7 +861,7 @@ static void clay_cache_init(void *vedata)
psl->copy_ps = DRW_pass_create("Copy", DRW_STATE_WRITE_COLOR);
grp = DRW_shgroup_create(e_data.copy_sh, psl->copy_ps);
- DRW_shgroup_uniform_buffer(grp, "colortex", &txl->color_copy);
+ DRW_shgroup_uniform_buffer(grp, "colortex", &stl->g_data->color_copy);
DRW_shgroup_call_add(grp, DRW_cache_fullscreen_quad_get(), NULL);
}
}
@@ -956,37 +963,25 @@ static void clay_draw_scene(void *vedata)
DRW_draw_pass(psl->hair_pass);
if (stl->g_data->enable_deferred_path) {
- if (DRW_state_is_fbo()) {
- DRW_framebuffer_texture_detach(dtxl->depth);
- DRW_framebuffer_texture_attach(fbl->prepass_fb, dtxl->depth, 0, 0);
- DRW_framebuffer_texture_attach(fbl->prepass_fb, stl->g_data->normal_tx, 0, 0);
- DRW_framebuffer_texture_attach(fbl->prepass_fb, stl->g_data->id_tx, 1, 0);
- DRW_framebuffer_bind(fbl->prepass_fb);
- /* We need to clear the id texture unfortunately. */
- DRW_framebuffer_clear(true, false, false, (float[4]){0.0f, 0.0f, 0.0f, 0.0f}, 0.0f);
- }
+ GPU_framebuffer_bind(fbl->prepass_fb);
+ /* We need to clear the id texture unfortunately. */
+ const float clear_col[4] = {0.0f, 0.0f, 0.0f, 0.0f};
+ GPU_framebuffer_clear_color(fbl->prepass_fb, clear_col);
DRW_draw_pass(psl->clay_pre_cull_ps);
DRW_draw_pass(psl->clay_flat_pre_cull_ps);
DRW_draw_pass(psl->clay_pre_ps);
DRW_draw_pass(psl->clay_flat_pre_ps);
- if (DRW_state_is_fbo()) {
- DRW_framebuffer_texture_detach(dtxl->depth);
- DRW_framebuffer_bind(dfbl->default_fb);
-
- DRW_draw_pass(psl->clay_deferred_ps);
-
- DRW_framebuffer_texture_attach(dfbl->default_fb, dtxl->depth, 0, 0);
- DRW_framebuffer_bind(dfbl->default_fb);
- }
+ GPU_framebuffer_bind(dfbl->color_only_fb);
+ DRW_draw_pass(psl->clay_deferred_ps);
}
if (true) { /* Always on for now. We might want a parameter for this. */
- DRW_framebuffer_bind(fbl->antialias_fb);
+ GPU_framebuffer_bind(fbl->antialias_fb);
DRW_draw_pass(psl->fxaa_ps);
- DRW_framebuffer_bind(dfbl->default_fb);
+ GPU_framebuffer_bind(dfbl->color_only_fb);
DRW_draw_pass(psl->copy_ps);
}
}
diff --git a/source/blender/draw/engines/clay/shaders/clay_frag.glsl b/source/blender/draw/engines/clay/shaders/clay_frag.glsl
index f2c6cd5f780..1939e4b735d 100644
--- a/source/blender/draw/engines/clay/shaders/clay_frag.glsl
+++ b/source/blender/draw/engines/clay/shaders/clay_frag.glsl
@@ -225,14 +225,15 @@ void main()
vec2 screenco = vec2(gl_FragCoord.xy) * invscreenres;
#ifdef DEFERRED_SHADING
- mat_id = texture(idtex, screenco).r;
+ ivec2 texel = ivec2(gl_FragCoord.xy);
+ mat_id = texelFetch(idtex, texel, 0).r;
/* early out (manual stencil test) */
if (mat_id == 0)
discard;
- float depth = texture(depthtex, screenco).r;
- vec3 N = normal_decode(texture(normaltex, screenco).rg);
+ float depth = texelFetch(depthtex, texel, 0).r;
+ vec3 N = normal_decode(texelFetch(normaltex, texel, 0).rg);
/* see the prepass for explanations. */
if (mat_id < 0) {
N = -N;
diff --git a/source/blender/draw/engines/eevee/eevee_bloom.c b/source/blender/draw/engines/eevee/eevee_bloom.c
index c62f35a70e7..29f6ca3988c 100644
--- a/source/blender/draw/engines/eevee/eevee_bloom.c
+++ b/source/blender/draw/engines/eevee/eevee_bloom.c
@@ -84,7 +84,6 @@ int EEVEE_bloom_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *vedata)
{
EEVEE_StorageList *stl = vedata->stl;
EEVEE_FramebufferList *fbl = vedata->fbl;
- EEVEE_TextureList *txl = vedata->txl;
EEVEE_EffectsInfo *effects = stl->effects;
const DRWContextState *draw_ctx = DRW_context_state_get();
@@ -112,10 +111,13 @@ int EEVEE_bloom_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *vedata)
effects->blit_texel_size[0] = 1.0f / (float)blitsize[0];
effects->blit_texel_size[1] = 1.0f / (float)blitsize[1];
- DRWFboTexture tex_blit = {&txl->bloom_blit, DRW_TEX_RGB_11_11_10, DRW_TEX_FILTER};
- DRW_framebuffer_init(&fbl->bloom_blit_fb, &draw_engine_eevee_type,
- (int)blitsize[0], (int)blitsize[1],
- &tex_blit, 1);
+ effects->bloom_blit = DRW_texture_pool_query_2D(blitsize[0], blitsize[1], DRW_TEX_RGB_11_11_10,
+ &draw_engine_eevee_type);
+
+ GPU_framebuffer_ensure_config(&fbl->bloom_blit_fb, {
+ GPU_ATTACHMENT_NONE,
+ GPU_ATTACHMENT_TEXTURE(effects->bloom_blit)
+ });
/* Parameters */
float threshold = BKE_collection_engine_property_value_get_float(props, "bloom_threshold");
@@ -151,10 +153,12 @@ int EEVEE_bloom_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *vedata)
effects->downsamp_texel_size[i][0] = 1.0f / (float)texsize[0];
effects->downsamp_texel_size[i][1] = 1.0f / (float)texsize[1];
- DRWFboTexture tex_bloom = {&txl->bloom_downsample[i], DRW_TEX_RGB_11_11_10, DRW_TEX_FILTER};
- DRW_framebuffer_init(&fbl->bloom_down_fb[i], &draw_engine_eevee_type,
- (int)texsize[0], (int)texsize[1],
- &tex_bloom, 1);
+ effects->bloom_downsample[i] = DRW_texture_pool_query_2D(texsize[0], texsize[1], DRW_TEX_RGB_11_11_10,
+ &draw_engine_eevee_type);
+ GPU_framebuffer_ensure_config(&fbl->bloom_down_fb[i], {
+ GPU_ATTACHMENT_NONE,
+ GPU_ATTACHMENT_TEXTURE(effects->bloom_downsample[i])
+ });
}
/* Upsample buffers */
@@ -165,30 +169,23 @@ int EEVEE_bloom_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *vedata)
texsize[0] = MAX2(texsize[0], 2);
texsize[1] = MAX2(texsize[1], 2);
- DRWFboTexture tex_bloom = {&txl->bloom_upsample[i], DRW_TEX_RGB_11_11_10, DRW_TEX_FILTER};
- DRW_framebuffer_init(&fbl->bloom_accum_fb[i], &draw_engine_eevee_ty
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list