Rename any instance of scene layer or render layer in code with view layer
[blender.git] / source / blender / draw / engines / eevee / eevee_effects.c
1 /*
2  * Copyright 2016, Blender Foundation.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * Contributor(s): Blender Institute
19  *
20  */
21
22 /** \file eevee_effects.c
23  *  \ingroup draw_engine
24  *
25  * Gather all screen space effects technique such as Bloom, Motion Blur, DoF, SSAO, SSR, ...
26  */
27
28 #include "DRW_render.h"
29
30 #include "BKE_global.h" /* for G.debug_value */
31
32 #include "eevee_private.h"
33 #include "GPU_texture.h"
34
35 static struct {
36         /* Downsample Depth */
37         struct GPUShader *minz_downlevel_sh;
38         struct GPUShader *maxz_downlevel_sh;
39         struct GPUShader *minz_downdepth_sh;
40         struct GPUShader *maxz_downdepth_sh;
41         struct GPUShader *minz_downdepth_layer_sh;
42         struct GPUShader *maxz_downdepth_layer_sh;
43         struct GPUShader *minz_copydepth_sh;
44         struct GPUShader *maxz_copydepth_sh;
45
46         /* Simple Downsample */
47         struct GPUShader *downsample_sh;
48         struct GPUShader *downsample_cube_sh;
49
50         /* Theses are just references, not actually allocated */
51         struct GPUTexture *depth_src;
52         struct GPUTexture *color_src;
53
54         int depth_src_layer;
55         float cube_texel_size;
56 } e_data = {NULL}; /* Engine data */
57
58 extern char datatoc_effect_minmaxz_frag_glsl[];
59 extern char datatoc_effect_downsample_frag_glsl[];
60 extern char datatoc_effect_downsample_cube_frag_glsl[];
61 extern char datatoc_lightprobe_vert_glsl[];
62 extern char datatoc_lightprobe_geom_glsl[];
63
64 static void eevee_create_shader_downsample(void)
65 {
66         e_data.downsample_sh = DRW_shader_create_fullscreen(datatoc_effect_downsample_frag_glsl, NULL);
67         e_data.downsample_cube_sh = DRW_shader_create(
68                 datatoc_lightprobe_vert_glsl,
69                 datatoc_lightprobe_geom_glsl,
70                 datatoc_effect_downsample_cube_frag_glsl, NULL);
71
72         e_data.minz_downlevel_sh = DRW_shader_create_fullscreen(
73                 datatoc_effect_minmaxz_frag_glsl,
74                 "#define MIN_PASS\n");
75         e_data.maxz_downlevel_sh = DRW_shader_create_fullscreen(
76                 datatoc_effect_minmaxz_frag_glsl,
77                 "#define MAX_PASS\n");
78         e_data.minz_downdepth_sh = DRW_shader_create_fullscreen(
79                 datatoc_effect_minmaxz_frag_glsl,
80                 "#define MIN_PASS\n"
81                 "#define INPUT_DEPTH\n");
82         e_data.maxz_downdepth_sh = DRW_shader_create_fullscreen(
83                 datatoc_effect_minmaxz_frag_glsl,
84                 "#define MAX_PASS\n"
85                 "#define INPUT_DEPTH\n");
86         e_data.minz_downdepth_layer_sh = DRW_shader_create_fullscreen(
87                 datatoc_effect_minmaxz_frag_glsl,
88                 "#define MIN_PASS\n"
89                 "#define LAYERED\n"
90                 "#define INPUT_DEPTH\n");
91         e_data.maxz_downdepth_layer_sh = DRW_shader_create_fullscreen(
92                 datatoc_effect_minmaxz_frag_glsl,
93                 "#define MAX_PASS\n"
94                 "#define LAYERED\n"
95                 "#define INPUT_DEPTH\n");
96         e_data.minz_copydepth_sh = DRW_shader_create_fullscreen(
97                 datatoc_effect_minmaxz_frag_glsl,
98                 "#define MIN_PASS\n"
99                 "#define INPUT_DEPTH\n"
100                 "#define COPY_DEPTH\n");
101         e_data.maxz_copydepth_sh = DRW_shader_create_fullscreen(
102                 datatoc_effect_minmaxz_frag_glsl,
103                 "#define MAX_PASS\n"
104                 "#define INPUT_DEPTH\n"
105                 "#define COPY_DEPTH\n");
106 }
107
108 void EEVEE_effects_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)
109 {
110         EEVEE_StorageList *stl = vedata->stl;
111         EEVEE_FramebufferList *fbl = vedata->fbl;
112         EEVEE_TextureList *txl = vedata->txl;
113         EEVEE_EffectsInfo *effects;
114
115         const float *viewport_size = DRW_viewport_size_get();
116
117         /* Shaders */
118         if (!e_data.downsample_sh) {
119                 eevee_create_shader_downsample();
120         }
121
122         if (!stl->effects) {
123                 stl->effects = MEM_callocN(sizeof(EEVEE_EffectsInfo), "EEVEE_EffectsInfo");
124         }
125
126         effects = stl->effects;
127
128         effects->enabled_effects = 0;
129         effects->enabled_effects |= EEVEE_motion_blur_init(sldata, vedata);
130         effects->enabled_effects |= EEVEE_bloom_init(sldata, vedata);
131         effects->enabled_effects |= EEVEE_depth_of_field_init(sldata, vedata);
132         effects->enabled_effects |= EEVEE_temporal_sampling_init(sldata, vedata);
133         effects->enabled_effects |= EEVEE_occlusion_init(sldata, vedata);
134         effects->enabled_effects |= EEVEE_subsurface_init(sldata, vedata);
135         effects->enabled_effects |= EEVEE_screen_raytrace_init(sldata, vedata);
136         effects->enabled_effects |= EEVEE_volumes_init(sldata, vedata);
137
138         /**
139          * Ping Pong buffer
140          */
141         if ((effects->enabled_effects & EFFECT_POST_BUFFER) != 0) {
142                 DRWFboTexture tex = {&txl->color_post, DRW_TEX_RGBA_16, DRW_TEX_FILTER | DRW_TEX_MIPMAP};
143                 DRW_framebuffer_init(&fbl->effect_fb, &draw_engine_eevee_type,
144                                     (int)viewport_size[0], (int)viewport_size[1],
145                                     &tex, 1);
146         }
147         else {
148                 /* Cleanup to release memory */
149                 DRW_TEXTURE_FREE_SAFE(txl->color_post);
150                 DRW_FRAMEBUFFER_FREE_SAFE(fbl->effect_fb);
151         }
152
153         /**
154          * MinMax Pyramid
155          */
156         DRWFboTexture texmax = {&txl->maxzbuffer, DRW_TEX_DEPTH_24, DRW_TEX_MIPMAP};
157         DRW_framebuffer_init(&fbl->downsample_fb, &draw_engine_eevee_type,
158                             (int)viewport_size[0] / 2, (int)viewport_size[1] / 2,
159                             &texmax, 1);
160
161         /**
162          * Compute Mipmap texel alignement.
163          */
164         for (int i = 0; i < 10; ++i) {
165                 float mip_size[2] = {viewport_size[0], viewport_size[1]};
166                 for (int j = 0; j < i; ++j) {
167                         mip_size[0] = floorf(fmaxf(1.0f, mip_size[0] / 2.0f));
168                         mip_size[1] = floorf(fmaxf(1.0f, mip_size[1] / 2.0f));
169                 }
170                 stl->g_data->mip_ratio[i][0] = viewport_size[0] / (mip_size[0] * powf(2.0f, floorf(log2f(floorf(viewport_size[0] / mip_size[0])))));
171                 stl->g_data->mip_ratio[i][1] = viewport_size[1] / (mip_size[1] * powf(2.0f, floorf(log2f(floorf(viewport_size[1] / mip_size[1])))));
172         }
173
174
175         /**
176          * Normal buffer for deferred passes.
177          */
178         if ((effects->enabled_effects & EFFECT_NORMAL_BUFFER) != 0)     {
179                 if (txl->ssr_normal_input == NULL) {
180                         DRWTextureFormat nor_format = DRW_TEX_RG_16;
181                         txl->ssr_normal_input = DRW_texture_create_2D((int)viewport_size[0], (int)viewport_size[1], nor_format, 0, NULL);
182                 }
183
184                 /* Reattach textures to the right buffer (because we are alternating between buffers) */
185                 /* TODO multiple FBO per texture!!!! */
186                 DRW_framebuffer_texture_detach(txl->ssr_normal_input);
187                 DRW_framebuffer_texture_attach(fbl->main, txl->ssr_normal_input, 1, 0);
188         }
189         else {
190                 /* Cleanup to release memory */
191                 DRW_TEXTURE_FREE_SAFE(txl->ssr_normal_input);
192         }
193
194         /**
195          * Setup double buffer so we can access last frame as it was before post processes.
196          */
197         if ((effects->enabled_effects & EFFECT_DOUBLE_BUFFER) != 0) {
198                 DRWFboTexture tex_double_buffer = {&txl->color_double_buffer, DRW_TEX_RGBA_16, DRW_TEX_FILTER | DRW_TEX_MIPMAP};
199                 DRW_framebuffer_init(&fbl->double_buffer, &draw_engine_eevee_type,
200                                     (int)viewport_size[0], (int)viewport_size[1],
201                                     &tex_double_buffer, 1);
202         }
203         else {
204                 /* Cleanup to release memory */
205                 DRW_TEXTURE_FREE_SAFE(txl->color_double_buffer);
206                 DRW_FRAMEBUFFER_FREE_SAFE(fbl->double_buffer);
207         }
208 }
209
210 void EEVEE_effects_cache_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *vedata)
211 {
212         EEVEE_PassList *psl = vedata->psl;
213         EEVEE_StorageList *stl = vedata->stl;
214         EEVEE_TextureList *txl = vedata->txl;
215         EEVEE_EffectsInfo *effects = stl->effects;
216
217         struct Gwn_Batch *quad = DRW_cache_fullscreen_quad_get();
218
219         {
220                 psl->color_downsample_ps = DRW_pass_create("Downsample", DRW_STATE_WRITE_COLOR);
221                 DRWShadingGroup *grp = DRW_shgroup_create(e_data.downsample_sh, psl->color_downsample_ps);
222                 DRW_shgroup_uniform_buffer(grp, "source", &e_data.color_src);
223                 DRW_shgroup_uniform_float(grp, "fireflyFactor", &effects->ssr_firefly_fac, 1);
224                 DRW_shgroup_call_add(grp, quad, NULL);
225         }
226
227         {
228                 static int zero = 0;
229                 psl->color_downsample_cube_ps = DRW_pass_create("Downsample Cube", DRW_STATE_WRITE_COLOR);
230                 DRWShadingGroup *grp = DRW_shgroup_instance_create(e_data.downsample_cube_sh, psl->color_downsample_cube_ps, quad);
231                 DRW_shgroup_uniform_buffer(grp, "source", &e_data.color_src);
232                 DRW_shgroup_uniform_float(grp, "texelSize", &e_data.cube_texel_size, 1);
233                 DRW_shgroup_uniform_int(grp, "Layer", &zero, 1);
234                 DRW_shgroup_set_instance_count(grp, 6);
235         }
236
237         {
238                 /* Perform min/max downsample */
239                 DRWShadingGroup *grp;
240
241 #if 0 /* Not used for now */
242                 psl->minz_downlevel_ps = DRW_pass_create("HiZ Min Down Level", DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_ALWAYS);
243                 grp = DRW_shgroup_create(e_data.minz_downlevel_sh, psl->minz_downlevel_ps);
244                 DRW_shgroup_uniform_buffer(grp, "depthBuffer", &stl->g_data->minzbuffer);
245                 DRW_shgroup_call_add(grp, quad, NULL);
246 #endif
247
248                 psl->maxz_downlevel_ps = DRW_pass_create("HiZ Max Down Level", DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_ALWAYS);
249                 grp = DRW_shgroup_create(e_data.maxz_downlevel_sh, psl->maxz_downlevel_ps);
250                 DRW_shgroup_uniform_buffer(grp, "depthBuffer", &txl->maxzbuffer);
251                 DRW_shgroup_call_add(grp, quad, NULL);
252
253                 /* Copy depth buffer to halfres top level of HiZ */
254 #if 0 /* Not used for now */
255                 psl->minz_downdepth_ps = DRW_pass_create("HiZ Min Copy Depth Halfres", DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_ALWAYS);
256                 grp = DRW_shgroup_create(e_data.minz_downdepth_sh, psl->minz_downdepth_ps);
257                 DRW_shgroup_uniform_buffer(grp, "depthBuffer", &e_data.depth_src);
258                 DRW_shgroup_call_add(grp, quad, NULL);
259 #endif
260
261                 psl->maxz_downdepth_ps = DRW_pass_create("HiZ Max Copy Depth Halfres", DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_ALWAYS);
262                 grp = DRW_shgroup_create(e_data.maxz_downdepth_sh, psl->maxz_downdepth_ps);
263                 DRW_shgroup_uniform_buffer(grp, "depthBuffer", &e_data.depth_src);
264                 DRW_shgroup_call_add(grp, quad, NULL);
265
266 #if 0 /* Not used for now */
267                 psl->minz_downdepth_layer_ps = DRW_pass_create("HiZ Min Copy DepthLayer Halfres", DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_ALWAYS);
268                 grp = DRW_shgroup_create(e_data.minz_downdepth_layer_sh, psl->minz_downdepth_layer_ps);
269                 DRW_shgroup_uniform_buffer(grp, "depthBuffer", &e_data.depth_src);
270                 DRW_shgroup_uniform_int(grp, "depthLayer", &e_data.depth_src_layer, 1);
271                 DRW_shgroup_call_add(grp, quad, NULL);
272 #endif
273
274                 psl->maxz_downdepth_layer_ps = DRW_pass_create("HiZ Max Copy DepthLayer Halfres", DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_ALWAYS);
275                 grp = DRW_shgroup_create(e_data.maxz_downdepth_layer_sh, psl->maxz_downdepth_layer_ps);
276                 DRW_shgroup_uniform_buffer(grp, "depthBuffer", &e_data.depth_src);
277                 DRW_shgroup_uniform_int(grp, "depthLayer", &e_data.depth_src_layer, 1);
278                 DRW_shgroup_call_add(grp, quad, NULL);
279
280                 /* Copy depth buffer to halfres top level of HiZ */
281 #if 0 /* Not used for now */
282                 psl->minz_copydepth_ps = DRW_pass_create("HiZ Min Copy Depth Fullres", DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_ALWAYS);
283                 grp = DRW_shgroup_create(e_data.minz_copydepth_sh, psl->minz_copydepth_ps);
284                 DRW_shgroup_uniform_buffer(grp, "depthBuffer", &e_data.depth_src);
285                 DRW_shgroup_call_add(grp, quad, NULL);
286 #endif
287
288                 psl->maxz_copydepth_ps = DRW_pass_create("HiZ Max Copy Depth Fullres", DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_ALWAYS);
289                 grp = DRW_shgroup_create(e_data.maxz_copydepth_sh, psl->maxz_copydepth_ps);
290                 DRW_shgroup_uniform_buffer(grp, "depthBuffer", &e_data.depth_src);
291                 DRW_shgroup_call_add(grp, quad, NULL);
292         }
293 }
294
295 #if 0 /* Not required for now */
296 static void min_downsample_cb(void *vedata, int UNUSED(level))
297 {
298         EEVEE_PassList *psl = ((EEVEE_Data *)vedata)->psl;
299         DRW_draw_pass(psl->minz_downlevel_ps);
300 }
301 #endif
302
303 static void max_downsample_cb(void *vedata, int UNUSED(level))
304 {
305         EEVEE_PassList *psl = ((EEVEE_Data *)vedata)->psl;
306         DRW_draw_pass(psl->maxz_downlevel_ps);
307 }
308
309 static void simple_downsample_cb(void *vedata, int UNUSED(level))
310 {
311         EEVEE_PassList *psl = ((EEVEE_Data *)vedata)->psl;
312         DRW_draw_pass(psl->color_downsample_ps);
313 }
314
315 static void simple_downsample_cube_cb(void *vedata, int level)
316 {
317         EEVEE_PassList *psl = ((EEVEE_Data *)vedata)->psl;
318         e_data.cube_texel_size = (float)(1 << level) / (float)GPU_texture_width(e_data.color_src);
319         DRW_draw_pass(psl->color_downsample_cube_ps);
320 }
321
322 void EEVEE_create_minmax_buffer(EEVEE_Data *vedata, GPUTexture *depth_src, int layer)
323 {
324         EEVEE_PassList *psl = vedata->psl;
325         EEVEE_FramebufferList *fbl = vedata->fbl;
326         EEVEE_TextureList *txl = vedata->txl;
327
328         e_data.depth_src = depth_src;
329         e_data.depth_src_layer = layer;
330
331 #if 0 /* Not required for now */
332         DRW_stats_group_start("Min buffer");
333         /* Copy depth buffer to min texture top level */
334         DRW_framebuffer_texture_attach(fbl->downsample_fb, stl->g_data->minzbuffer, 0, 0);
335         DRW_framebuffer_bind(fbl->downsample_fb);
336         if (layer >= 0) {
337                 DRW_draw_pass(psl->minz_downdepth_layer_ps);
338         }
339         else {
340                 DRW_draw_pass(psl->minz_downdepth_ps);
341         }
342         DRW_framebuffer_texture_detach(stl->g_data->minzbuffer);
343
344         /* Create lower levels */
345         DRW_framebuffer_recursive_downsample(fbl->downsample_fb, stl->g_data->minzbuffer, 8, &min_downsample_cb, vedata);
346         DRW_stats_group_end();
347 #endif
348
349         DRW_stats_group_start("Max buffer");
350         /* Copy depth buffer to max texture top level */
351         DRW_framebuffer_texture_attach(fbl->downsample_fb, txl->maxzbuffer, 0, 0);
352         DRW_framebuffer_bind(fbl->downsample_fb);
353         if (layer >= 0) {
354                 DRW_draw_pass(psl->maxz_downdepth_layer_ps);
355         }
356         else {
357                 DRW_draw_pass(psl->maxz_downdepth_ps);
358         }
359         DRW_framebuffer_texture_detach(txl->maxzbuffer);
360
361         /* Create lower levels */
362         DRW_framebuffer_recursive_downsample(fbl->downsample_fb, txl->maxzbuffer, 8, &max_downsample_cb, vedata);
363         DRW_stats_group_end();
364
365         /* Restore */
366         DRW_framebuffer_bind(fbl->main);
367 }
368
369 /**
370  * Simple downsampling algorithm. Reconstruct mip chain up to mip level.
371  **/
372 void EEVEE_downsample_buffer(EEVEE_Data *vedata, struct GPUFrameBuffer *fb_src, GPUTexture *texture_src, int level)
373 {
374         e_data.color_src = texture_src;
375
376         DRW_stats_group_start("Downsample buffer");
377         /* Create lower levels */
378         DRW_framebuffer_recursive_downsample(fb_src, texture_src, level, &simple_downsample_cb, vedata);
379         DRW_stats_group_end();
380 }
381
382 /**
383  * Simple downsampling algorithm for cubemap. Reconstruct mip chain up to mip level.
384  **/
385 void EEVEE_downsample_cube_buffer(EEVEE_Data *vedata, struct GPUFrameBuffer *fb_src, GPUTexture *texture_src, int level)
386 {
387         e_data.color_src = texture_src;
388
389         DRW_stats_group_start("Downsample Cube buffer");
390         /* Create lower levels */
391         DRW_framebuffer_recursive_downsample(fb_src, texture_src, level, &simple_downsample_cube_cb, vedata);
392         DRW_stats_group_end();
393 }
394
395 void EEVEE_draw_effects(EEVEE_Data *vedata)
396 {
397         EEVEE_TextureList *txl = vedata->txl;
398         EEVEE_FramebufferList *fbl = vedata->fbl;
399         EEVEE_StorageList *stl = vedata->stl;
400         EEVEE_EffectsInfo *effects = stl->effects;
401         DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get();
402         DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
403
404         /* only once per frame after the first post process */
405         effects->swap_double_buffer = ((effects->enabled_effects & EFFECT_DOUBLE_BUFFER) != 0);
406
407         /* Init pointers */
408         effects->source_buffer = txl->color; /* latest updated texture */
409         effects->target_buffer = fbl->effect_fb; /* next target to render to */
410
411         /* Temporal Anti-Aliasing MUST come first */
412         EEVEE_temporal_sampling_draw(vedata);
413
414         /* Detach depth for effects to use it */
415         DRW_framebuffer_texture_detach(dtxl->depth);
416
417         /* Post process stack (order matters) */
418         EEVEE_motion_blur_draw(vedata);
419         EEVEE_depth_of_field_draw(vedata);
420         EEVEE_bloom_draw(vedata);
421
422         /* Restore default framebuffer */
423         DRW_framebuffer_texture_attach(dfbl->default_fb, dtxl->depth, 0, 0);
424         DRW_framebuffer_bind(dfbl->default_fb);
425
426         /* Tonemapping */
427         DRW_transform_to_display(effects->source_buffer);
428
429         /* Debug : Ouput buffer to view. */
430         switch (G.debug_value) {
431                 case 1:
432                         if (txl->maxzbuffer) DRW_transform_to_display(txl->maxzbuffer);
433                         break;
434                 case 2:
435                         if (stl->g_data->ssr_hit_output[0]) DRW_transform_to_display(stl->g_data->ssr_hit_output[0]);
436                         break;
437                 case 3:
438                         if (txl->ssr_normal_input) DRW_transform_to_display(txl->ssr_normal_input);
439                         break;
440                 case 4:
441                         if (txl->ssr_specrough_input) DRW_transform_to_display(txl->ssr_specrough_input);
442                         break;
443                 case 5:
444                         if (txl->color_double_buffer) DRW_transform_to_display(txl->color_double_buffer);
445                         break;
446                 case 6:
447                         if (stl->g_data->gtao_horizons_debug) DRW_transform_to_display(stl->g_data->gtao_horizons_debug);
448                         break;
449                 case 7:
450                         if (txl->sss_data) DRW_transform_to_display(txl->sss_data);
451                         break;
452                 default:
453                         break;
454         }
455
456         /* If no post processes is enabled, buffers are still not swapped, do it now. */
457         SWAP_DOUBLE_BUFFERS();
458
459         if (!stl->g_data->valid_double_buffer &&
460             ((effects->enabled_effects & EFFECT_DOUBLE_BUFFER) != 0) &&
461             (DRW_state_is_image_render() == false))
462         {
463                 /* If history buffer is not valid request another frame.
464                  * This fix black reflections on area resize. */
465                 DRW_viewport_request_redraw();
466         }
467
468         /* Record pers matrix for the next frame. */
469         DRW_viewport_matrix_get(stl->g_data->prev_persmat, DRW_MAT_PERS);
470
471         /* Update double buffer status if render mode. */
472         if (DRW_state_is_image_render()) {
473                 stl->g_data->valid_double_buffer = (txl->color_double_buffer != NULL);
474         }
475 }
476
477 void EEVEE_effects_free(void)
478 {
479         DRW_SHADER_FREE_SAFE(e_data.downsample_sh);
480         DRW_SHADER_FREE_SAFE(e_data.downsample_cube_sh);
481
482         DRW_SHADER_FREE_SAFE(e_data.minz_downlevel_sh);
483         DRW_SHADER_FREE_SAFE(e_data.maxz_downlevel_sh);
484         DRW_SHADER_FREE_SAFE(e_data.minz_downdepth_sh);
485         DRW_SHADER_FREE_SAFE(e_data.maxz_downdepth_sh);
486         DRW_SHADER_FREE_SAFE(e_data.minz_downdepth_layer_sh);
487         DRW_SHADER_FREE_SAFE(e_data.maxz_downdepth_layer_sh);
488         DRW_SHADER_FREE_SAFE(e_data.minz_copydepth_sh);
489         DRW_SHADER_FREE_SAFE(e_data.maxz_copydepth_sh);
490 }