Commit: d63829117c21c0d926cf0a9df645c3ed5cd8057a
Author: Clément Foucault
Date:   Thu Mar 1 19:27:38 2018 +0100
Branches: blender2.8
https://developer.blender.org/rBd63829117c21c0d926cf0a9df645c3ed5cd8057a

DRW: Refactor simple instancing.

Instead of creating a new instancing shading group without attrib, we now have 
instancing calls. The benefits is that they can be culled.
They can be used in conjuction with the standard and generate calls but shader 
must support it (which is generally not the case).
We store a pointer to the actual count so that the number can be tweaked 
between redraw.

This will makes multi layer rendering more efficient.

===================================================================

M       intern/gawain/gawain/gwn_batch.h
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_private.h
M       source/blender/draw/engines/eevee/eevee_render.c
M       source/blender/draw/engines/eevee/shaders/shadow_vert.glsl
M       source/blender/draw/intern/DRW_render.h
M       source/blender/draw/intern/draw_manager.h
M       source/blender/draw/intern/draw_manager_data.c
M       source/blender/draw/intern/draw_manager_exec.c
M       source/blender/draw/modes/object_mode.c

===================================================================

diff --git a/intern/gawain/gawain/gwn_batch.h b/intern/gawain/gawain/gwn_batch.h
index 788202ff3d5..3e90ef091f1 100644
--- a/intern/gawain/gawain/gwn_batch.h
+++ b/intern/gawain/gawain/gwn_batch.h
@@ -119,9 +119,6 @@ void GWN_batch_draw(Gwn_Batch*);
 // This does not bind/unbind shader and does not call gpuBindMatrices()
 void GWN_batch_draw_range_ex(Gwn_Batch*, int v_first, int v_count, bool 
force_instance);
 
-#define GWN_batch_draw_range(batch, first, count) \
-       GWN_batch_draw_range_ex(batch, first, count, false)
-
 // Does not even need batch
 void GWN_draw_primitive(Gwn_PrimType, int v_count);
 
diff --git a/source/blender/draw/engines/eevee/eevee_effects.c 
b/source/blender/draw/engines/eevee/eevee_effects.c
index 3427bb1d397..1030fe1ce3a 100644
--- a/source/blender/draw/engines/eevee/eevee_effects.c
+++ b/source/blender/draw/engines/eevee/eevee_effects.c
@@ -240,13 +240,13 @@ void EEVEE_effects_cache_init(EEVEE_ViewLayerData 
*sldata, EEVEE_Data *vedata)
 
        {
                static int zero = 0;
+               static unsigned int six = 6;
                psl->color_downsample_cube_ps = DRW_pass_create("Downsample 
Cube", DRW_STATE_WRITE_COLOR);
-               DRWShadingGroup *grp = 
DRW_shgroup_instance_create(e_data.downsample_cube_sh, 
psl->color_downsample_cube_ps,
-                                                                  quad, NULL);
+               DRWShadingGroup *grp = 
DRW_shgroup_create(e_data.downsample_cube_sh, psl->color_downsample_cube_ps);
                DRW_shgroup_uniform_buffer(grp, "source", &e_data.color_src);
                DRW_shgroup_uniform_float(grp, "texelSize", 
&e_data.cube_texel_size, 1);
                DRW_shgroup_uniform_int(grp, "Layer", &zero, 1);
-               DRW_shgroup_set_instance_count(grp, 6);
+               DRW_shgroup_call_instances_add(grp, quad, NULL, &six);
        }
 
        {
diff --git a/source/blender/draw/engines/eevee/eevee_engine.c 
b/source/blender/draw/engines/eevee/eevee_engine.c
index ded927d19f7..406d0ff7049 100644
--- a/source/blender/draw/engines/eevee/eevee_engine.c
+++ b/source/blender/draw/engines/eevee/eevee_engine.c
@@ -96,14 +96,13 @@ static void eevee_engine_init(void *ved)
 
 static void eevee_cache_init(void *vedata)
 {
-       EEVEE_PassList *psl = ((EEVEE_Data *)vedata)->psl;
        EEVEE_ViewLayerData *sldata = EEVEE_view_layer_data_ensure();
 
        EEVEE_bloom_cache_init(sldata, vedata);
        EEVEE_depth_of_field_cache_init(sldata, vedata);
        EEVEE_effects_cache_init(sldata, vedata);
        EEVEE_lightprobes_cache_init(sldata, vedata);
-       EEVEE_lights_cache_init(sldata, psl);
+       EEVEE_lights_cache_init(sldata, vedata);
        EEVEE_materials_cache_init(vedata);
        EEVEE_motion_blur_cache_init(sldata, vedata);
        EEVEE_occlusion_cache_init(sldata, vedata);
diff --git a/source/blender/draw/engines/eevee/eevee_lightprobes.c 
b/source/blender/draw/engines/eevee/eevee_lightprobes.c
index b4de6081457..cf6d1e153dc 100644
--- a/source/blender/draw/engines/eevee/eevee_lightprobes.c
+++ b/source/blender/draw/engines/eevee/eevee_lightprobes.c
@@ -538,14 +538,10 @@ void EEVEE_lightprobes_cache_init(EEVEE_ViewLayerData 
*sldata, EEVEE_Data *vedat
        {
                psl->probe_planar_downsample_ps = DRW_pass_create("LightProbe 
Planar Downsample", DRW_STATE_WRITE_COLOR);
 
-               struct Gwn_Batch *geom = DRW_cache_fullscreen_quad_get();
-               DRWShadingGroup *grp = DRW_shgroup_instance_create(
-                       e_data.probe_planar_downsample_sh,
-                       psl->probe_planar_downsample_ps,
-                       geom, NULL);
-               stl->g_data->planar_downsample = grp;
+               DRWShadingGroup *grp = 
DRW_shgroup_create(e_data.probe_planar_downsample_sh, 
psl->probe_planar_downsample_ps);
                DRW_shgroup_uniform_buffer(grp, "source", &txl->planar_pool);
                DRW_shgroup_uniform_float(grp, "fireflyFactor", 
&sldata->common_data.ssr_firefly_fac, 1);
+               DRW_shgroup_call_instances_add(grp, 
DRW_cache_fullscreen_quad_get(), NULL, (unsigned int *)&pinfo->num_planar);
        }
 }
 
@@ -846,12 +842,7 @@ static void EEVEE_lightprobes_updates(EEVEE_ViewLayerData 
*sldata, EEVEE_PassLis
                if (DRW_state_draw_support() &&
                    (probe->flag & LIGHTPROBE_FLAG_SHOW_DATA))
                {
-                       struct Gwn_Batch *geom = DRW_cache_sphere_get();
-                       DRWShadingGroup *grp = DRW_shgroup_instance_create(
-                               e_data.probe_grid_display_sh,
-                               psl->probe_display,
-                               geom, NULL);
-                       DRW_shgroup_set_instance_count(grp, ped->num_cell);
+                       DRWShadingGroup *grp = 
DRW_shgroup_create(e_data.probe_grid_display_sh, psl->probe_display);
                        DRW_shgroup_uniform_int(grp, "offset", &egrid->offset, 
1);
                        DRW_shgroup_uniform_ivec3(grp, "grid_resolution", 
egrid->resolution, 1);
                        DRW_shgroup_uniform_vec3(grp, "corner", egrid->corner, 
1);
@@ -860,6 +851,7 @@ static void EEVEE_lightprobes_updates(EEVEE_ViewLayerData 
*sldata, EEVEE_PassLis
                        DRW_shgroup_uniform_vec3(grp, "increment_z", 
egrid->increment_z, 1);
                        DRW_shgroup_uniform_buffer(grp, "irradianceGrid", 
&sldata->irradiance_pool);
                        DRW_shgroup_uniform_float(grp, "sphere_size", 
&probe->data_draw_size, 1);
+                       DRW_shgroup_call_instances_add(grp, 
DRW_cache_sphere_get(), NULL, (unsigned int *)&ped->num_cell);
                }
        }
 }
@@ -898,9 +890,6 @@ void EEVEE_lightprobes_cache_finish(EEVEE_ViewLayerData 
*sldata, EEVEE_Data *ved
        /* XXX this should be run each frame as it ensure planar_depth is set */
        planar_pool_ensure_alloc(vedata, pinfo->num_planar);
 
-       /* Setup planar filtering pass */
-       DRW_shgroup_set_instance_count(stl->g_data->planar_downsample, 
pinfo->num_planar);
-
        if (!sldata->probe_pool) {
                sldata->probe_pool = 
DRW_texture_create_2D_array(pinfo->cubemap_res, pinfo->cubemap_res, max_ff(1, 
pinfo->num_cube),
                                                                 
DRW_TEX_RGB_11_11_10, DRW_TEX_FILTER | DRW_TEX_MIPMAP, NULL);
diff --git a/source/blender/draw/engines/eevee/eevee_lights.c 
b/source/blender/draw/engines/eevee/eevee_lights.c
index 635f713c8ae..9eb6a761e1d 100644
--- a/source/blender/draw/engines/eevee/eevee_lights.c
+++ b/source/blender/draw/engines/eevee/eevee_lights.c
@@ -205,9 +205,11 @@ void EEVEE_lights_init(EEVEE_ViewLayerData *sldata)
        }
 }
 
-void EEVEE_lights_cache_init(EEVEE_ViewLayerData *sldata, EEVEE_PassList *psl)
+void EEVEE_lights_cache_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)
 {
        EEVEE_LampsInfo *linfo = sldata->lamps;
+       EEVEE_StorageList *stl = vedata->stl;
+       EEVEE_PassList *psl = vedata->psl;
 
        linfo->shcaster_frontbuffer->count = 0;
        linfo->num_light = 0;
@@ -271,15 +273,11 @@ void EEVEE_lights_cache_init(EEVEE_ViewLayerData *sldata, 
EEVEE_PassList *psl)
        }
 
        {
-               psl->shadow_cube_pass = DRW_pass_create(
-                       "Shadow Cube Pass",
-                       DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | 
DRW_STATE_DEPTH_LESS);
-       }
+               DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH 
| DRW_STATE_DEPTH_LESS;
+               psl->shadow_pass = DRW_pass_create("Shadow Pass", state);
 
-       {
-               psl->shadow_cascade_pass = DRW_pass_create(
-                       "Shadow Cascade Pass",
-                       DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | 
DRW_STATE_DEPTH_LESS);
+               DRWShadingGroup *grp = stl->g_data->shadow_shgrp = 
DRW_shgroup_create(e_data.shadow_sh, psl->shadow_pass);
+               DRW_shgroup_uniform_block(grp, "shadow_render_block", 
sldata->shadow_render_ubo);
        }
 }
 
@@ -378,24 +376,20 @@ void EEVEE_lights_cache_add(EEVEE_ViewLayerData *sldata, 
Object *ob)
 
 /* Add a shadow caster to the shadowpasses */
 void EEVEE_lights_cache_shcaster_add(
-        EEVEE_ViewLayerData *sldata, EEVEE_PassList *psl, struct Gwn_Batch 
*geom, float (*obmat)[4])
+        EEVEE_ViewLayerData *sldata, EEVEE_StorageList *stl, struct Gwn_Batch 
*geom, Object *ob)
 {
-       DRWShadingGroup *grp = DRW_shgroup_instance_create(e_data.shadow_sh, 
psl->shadow_cube_pass, geom, NULL);
-       DRW_shgroup_uniform_block(grp, "shadow_render_block", 
sldata->shadow_render_ubo);
-       DRW_shgroup_uniform_mat4(grp, "ShadowModelMatrix", (float *)obmat);
-       DRW_shgroup_set_instance_count(grp, 6);
-
-       grp = DRW_shgroup_instance_create(e_data.shadow_sh, 
psl->shadow_cascade_pass, geom, NULL);
-       DRW_shgroup_uniform_block(grp, "shadow_render_block", 
sldata->shadow_render_ubo);
-       DRW_shgroup_uniform_mat4(grp, "ShadowModelMatrix", (float *)obmat);
-       DRW_shgroup_set_instance_count(grp, MAX_CASCADE_NUM);
+       DRW_shgroup_call_object_instances_add(
+               stl->g_data->shadow_shgrp,
+               geom, ob,
+               &sldata->lamps->shadow_instance_count);
 }
 
 void EEVEE_lights_cache_shcaster_material_add(
        EEVEE_ViewLayerData *sldata, EEVEE_PassList *psl, struct GPUMaterial 
*gpumat,
        struct Gwn_Batch *geom, struct Object *ob, float (*obmat)[4], float 
*alpha_threshold)
 {
-       DRWShadingGroup *grp = DRW_shgroup_material_instance_create(gpumat, 
psl->shadow_cube_pass, geom, ob, NULL);
+       /* TODO / PERF : reuse the same shading group for objects with the same 
material */
+       DRWShadingGroup *grp = DRW_shgroup_material_create(gpumat, 
psl->shadow_pass);
 
        if (grp == NULL) return;
 
@@ -405,16 +399,7 @@ void EEVEE_lights_cache_shcaster_material_add(
        if (alpha_threshold != NULL)
                DRW_shgroup_uniform_float(grp, "alphaThreshold", 
alpha_threshold, 1);
 
-       DRW_shgroup_set_instance_count(grp, 6);
-
-       grp = DRW_shgroup_material_instance_create(gpumat, 
psl->shadow_cascade_pass, geom, ob, NULL);
-       DRW_shgroup_uniform_block(grp, "shadow_render_block", 
sldata->shadow_render_ubo);
-       DRW_shgroup_uniform_mat4(grp, "ShadowModelMatrix", (float *)obmat);
-
-       if (alpha_threshold != NULL)
-               DRW_shgroup_uniform_float(grp, "alphaThreshold", 
alpha_threshold, 1);
-
-       DRW_shgroup_set_instance_count(grp, MAX_CASCADE_NUM);
+       DRW_shgroup_call_object_instances_add(grp, geom, ob, 
&sldata->lamps->shadow_instance_count);
 }
 
 /* Make that object update shadow casting lamps inside its influence bounding 
box. */
@@ -1036,7 +1021,8 @@ void EEVEE_draw_shadows(EEVEE_ViewLayerData *sldata, 
EEVEE_PassList *psl)
                DRW_framebuffer_clear(true, true, false, clear_col, 1.0f);
 
                /* Render shadow cube */
-               DRW_draw_pass(psl->shadow_cube_pass);
+               linfo->shadow_instance_count = 6;
+               DRW_draw_pass(psl->shadow_pass);
 
                /* 0.001f is arbitrary, but it should be relatively small so 
that filter size is not too big. */
                float filter_texture_size = la->soft * 0.001f;
@@ -1110,7 +1096,8 @@ void EEVEE_draw_shadows(EEVEE_ViewLayerData *sldata, 
EEVEE_PassList *psl)
                DRW_framebuffer_clear(false, true, false, NULL, 1.0);
 
                /* Render shadow cascades */
-               DRW_draw_pass(psl->shado

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to