diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2022-08-27 18:26:48 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2022-08-27 18:26:48 +0300 |
commit | 8b5ffd9af05515ecb09295e3fc252ab46afa499d (patch) | |
tree | 7102de059302e7754936f294c7d8cb0093217839 | |
parent | c813d270a19ca1e15a504d46983f4d8ac6805ce9 (diff) |
EEVEE next Use new Draw for light culling
5 files changed, 65 insertions, 57 deletions
diff --git a/source/blender/draw/engines/eevee_next/eevee_light.cc b/source/blender/draw/engines/eevee_next/eevee_light.cc index 558a9846ced..cf9949c6c23 100644 --- a/source/blender/draw/engines/eevee_next/eevee_light.cc +++ b/source/blender/draw/engines/eevee_next/eevee_light.cc @@ -399,49 +399,47 @@ void LightModule::culling_pass_sync() uint culling_tile_dispatch_size = divide_ceil_u(total_word_count_, CULLING_TILE_GROUP_SIZE); /* NOTE: We reference the buffers that may be resized or updated later. */ + + culling_ps_.init(); { - DRW_PASS_CREATE(culling_select_ps_, DRW_STATE_NO_DRAW); - GPUShader *sh = inst_.shaders.static_shader_get(LIGHT_CULLING_SELECT); - DRWShadingGroup *grp = DRW_shgroup_create(sh, culling_select_ps_); - DRW_shgroup_storage_block_ref(grp, "light_cull_buf", &culling_data_buf_); - DRW_shgroup_storage_block(grp, "in_light_buf", light_buf_); - DRW_shgroup_storage_block(grp, "out_light_buf", culling_light_buf_); - DRW_shgroup_storage_block(grp, "out_zdist_buf", culling_zdist_buf_); - DRW_shgroup_storage_block(grp, "out_key_buf", culling_key_buf_); - DRW_shgroup_call_compute(grp, culling_select_dispatch_size, 1, 1); - DRW_shgroup_barrier(grp, GPU_BARRIER_SHADER_STORAGE); + auto &sub = culling_ps_.sub("Select"); + sub.shader_set(inst_.shaders.static_shader_get(LIGHT_CULLING_SELECT)); + sub.bind("light_cull_buf", &culling_data_buf_); + sub.bind("in_light_buf", light_buf_); + sub.bind("out_light_buf", culling_light_buf_); + sub.bind("out_zdist_buf", culling_zdist_buf_); + sub.bind("out_key_buf", culling_key_buf_); + sub.dispatch(int3(culling_select_dispatch_size, 1, 1)); + sub.barrier(GPU_BARRIER_SHADER_STORAGE); } { - DRW_PASS_CREATE(culling_sort_ps_, DRW_STATE_NO_DRAW); - GPUShader *sh = inst_.shaders.static_shader_get(LIGHT_CULLING_SORT); - DRWShadingGroup *grp = DRW_shgroup_create(sh, culling_sort_ps_); - DRW_shgroup_storage_block_ref(grp, "light_cull_buf", &culling_data_buf_); - DRW_shgroup_storage_block(grp, "in_light_buf", light_buf_); - DRW_shgroup_storage_block(grp, "out_light_buf", culling_light_buf_); - DRW_shgroup_storage_block(grp, "in_zdist_buf", culling_zdist_buf_); - DRW_shgroup_storage_block(grp, "in_key_buf", culling_key_buf_); - DRW_shgroup_call_compute(grp, culling_sort_dispatch_size, 1, 1); - DRW_shgroup_barrier(grp, GPU_BARRIER_SHADER_STORAGE); + auto &sub = culling_ps_.sub("Sort"); + sub.shader_set(inst_.shaders.static_shader_get(LIGHT_CULLING_SORT)); + sub.bind("light_cull_buf", &culling_data_buf_); + sub.bind("in_light_buf", light_buf_); + sub.bind("out_light_buf", culling_light_buf_); + sub.bind("in_zdist_buf", culling_zdist_buf_); + sub.bind("in_key_buf", culling_key_buf_); + sub.dispatch(int3(culling_sort_dispatch_size, 1, 1)); + sub.barrier(GPU_BARRIER_SHADER_STORAGE); } { - DRW_PASS_CREATE(culling_zbin_ps_, DRW_STATE_NO_DRAW); - GPUShader *sh = inst_.shaders.static_shader_get(LIGHT_CULLING_ZBIN); - DRWShadingGroup *grp = DRW_shgroup_create(sh, culling_zbin_ps_); - DRW_shgroup_storage_block_ref(grp, "light_cull_buf", &culling_data_buf_); - DRW_shgroup_storage_block(grp, "light_buf", culling_light_buf_); - DRW_shgroup_storage_block(grp, "out_zbin_buf", culling_zbin_buf_); - DRW_shgroup_call_compute(grp, 1, 1, 1); - DRW_shgroup_barrier(grp, GPU_BARRIER_SHADER_STORAGE); + auto &sub = culling_ps_.sub("Zbin"); + sub.shader_set(inst_.shaders.static_shader_get(LIGHT_CULLING_ZBIN)); + sub.bind("light_cull_buf", &culling_data_buf_); + sub.bind("light_buf", culling_light_buf_); + sub.bind("out_zbin_buf", culling_zbin_buf_); + sub.dispatch(int3(1, 1, 1)); + sub.barrier(GPU_BARRIER_SHADER_STORAGE); } { - DRW_PASS_CREATE(culling_tile_ps_, DRW_STATE_NO_DRAW); - GPUShader *sh = inst_.shaders.static_shader_get(LIGHT_CULLING_TILE); - DRWShadingGroup *grp = DRW_shgroup_create(sh, culling_tile_ps_); - DRW_shgroup_storage_block_ref(grp, "light_cull_buf", &culling_data_buf_); - DRW_shgroup_storage_block(grp, "light_buf", culling_light_buf_); - DRW_shgroup_storage_block(grp, "out_light_tile_buf", culling_tile_buf_); - DRW_shgroup_call_compute(grp, culling_tile_dispatch_size, 1, 1); - DRW_shgroup_barrier(grp, GPU_BARRIER_SHADER_STORAGE); + auto &sub = culling_ps_.sub("Tiles"); + sub.shader_set(inst_.shaders.static_shader_get(LIGHT_CULLING_TILE)); + sub.bind("light_cull_buf", &culling_data_buf_); + sub.bind("light_buf", culling_light_buf_); + sub.bind("out_light_tile_buf", culling_tile_buf_); + sub.dispatch(int3(culling_tile_dispatch_size, 1, 1)); + sub.barrier(GPU_BARRIER_SHADER_STORAGE); } } @@ -453,7 +451,7 @@ void LightModule::debug_pass_sync() } DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_CUSTOM; - debug_draw_ps_ = DRW_pass_create("LightCulling.Debug", state); + debug_draw_ps_ = DRW_pass_create("Debug.LightCulling", state); GPUShader *sh = inst_.shaders.static_shader_get(LIGHT_CULLING_DEBUG); DRWShadingGroup *grp = DRW_shgroup_create(sh, debug_draw_ps_); inst_.hiz_buffer.bind_resources(grp); @@ -465,10 +463,10 @@ void LightModule::debug_pass_sync() DRW_shgroup_call_procedural_triangles(grp, nullptr, 1); } -void LightModule::set_view(const DRWView *view, const int2 extent) +void LightModule::set_view(View &view, const int2 extent) { - float far_z = DRW_view_far_distance_get(view); - float near_z = DRW_view_near_distance_get(view); + float far_z = view.far_clip(); + float near_z = view.near_clip(); culling_data_buf_.zbin_scale = -CULLING_ZBIN_COUNT / fabsf(far_z - near_z); culling_data_buf_.zbin_bias = -near_z * culling_data_buf_.zbin_scale; @@ -476,15 +474,7 @@ void LightModule::set_view(const DRWView *view, const int2 extent) culling_data_buf_.visible_count = 0; culling_data_buf_.push_update(); - DRW_stats_group_start("Light Culling"); - - DRW_view_set_active(view); - DRW_draw_pass(culling_select_ps_); - DRW_draw_pass(culling_sort_ps_); - DRW_draw_pass(culling_zbin_ps_); - DRW_draw_pass(culling_tile_ps_); - - DRW_stats_group_end(); + inst_.manager->submit(culling_ps_, view); } void LightModule::debug_draw(GPUFrameBuffer *view_fb) diff --git a/source/blender/draw/engines/eevee_next/eevee_light.hh b/source/blender/draw/engines/eevee_next/eevee_light.hh index afa207805a5..72d6d71dd8a 100644 --- a/source/blender/draw/engines/eevee_next/eevee_light.hh +++ b/source/blender/draw/engines/eevee_next/eevee_light.hh @@ -116,10 +116,7 @@ class LightModule { /** Bitmap of lights touching each tiles. */ LightCullingTileBuf culling_tile_buf_ = {"LightCull_tile"}; /** Culling compute passes. */ - DRWPass *culling_select_ps_ = nullptr; - DRWPass *culling_sort_ps_ = nullptr; - DRWPass *culling_zbin_ps_ = nullptr; - DRWPass *culling_tile_ps_ = nullptr; + PassSimple culling_ps_ = {"LightCulling"}; /** Total number of words the tile buffer needs to contain for the render resolution. */ uint total_word_count_ = 0; @@ -138,7 +135,7 @@ class LightModule { /** * Update acceleration structure for the given view. */ - void set_view(const DRWView *view, const int2 extent); + void set_view(View &view, const int2 extent); void debug_draw(GPUFrameBuffer *view_fb); diff --git a/source/blender/draw/engines/eevee_next/eevee_pipeline.cc b/source/blender/draw/engines/eevee_next/eevee_pipeline.cc index aae63bfaa99..16a7fd0e56b 100644 --- a/source/blender/draw/engines/eevee_next/eevee_pipeline.cc +++ b/source/blender/draw/engines/eevee_next/eevee_pipeline.cc @@ -117,11 +117,11 @@ void ForwardPipeline::sync() inst_.sampling.bind_resources(&opaque_ps_); } - opaque_single_sided_ps_ = &opaque_ps_.sub("DoubleSided"); + opaque_single_sided_ps_ = &opaque_ps_.sub("SingleSided"); opaque_single_sided_ps_->state_set(DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL | DRW_STATE_CULL_BACK); - opaque_double_sided_ps_ = &opaque_ps_.sub("SingleSided"); + opaque_double_sided_ps_ = &opaque_ps_.sub("DoubleSided"); opaque_double_sided_ps_->state_set(DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL); } { diff --git a/source/blender/draw/engines/eevee_next/eevee_view.cc b/source/blender/draw/engines/eevee_next/eevee_view.cc index 785d0c43ab0..152f1c55919 100644 --- a/source/blender/draw/engines/eevee_next/eevee_view.cc +++ b/source/blender/draw/engines/eevee_next/eevee_view.cc @@ -123,7 +123,7 @@ void ShadingView::render() inst_.pipelines.world.render(render_view_new); /* TODO(fclem): Move it after the first prepass (and hiz update) once pipeline is stabilized. */ - inst_.lights.set_view(render_view_, extent_); + inst_.lights.set_view(render_view_new, extent_); // inst_.pipelines.deferred.render( // render_view_, rt_buffer_opaque_, rt_buffer_refract_, depth_tx_, combined_tx_); diff --git a/source/blender/draw/intern/draw_view.hh b/source/blender/draw/intern/draw_view.hh index 594fbe79ca4..19a3a3feab3 100644 --- a/source/blender/draw/intern/draw_view.hh +++ b/source/blender/draw/intern/draw_view.hh @@ -49,6 +49,27 @@ class View { void sync(const float4x4 &view_mat, const float4x4 &win_mat); + bool is_persp() const + { + return data_.winmat[3][3] == 0.0f; + } + + float far_clip() const + { + if (is_persp()) { + return -data_.winmat[3][2] / (data_.winmat[2][2] + 1.0f); + } + return -(data_.winmat[3][2] - 1.0f) / data_.winmat[2][2]; + } + + float near_clip() const + { + if (is_persp()) { + return -data_.winmat[3][2] / (data_.winmat[2][2] - 1.0f); + } + return -(data_.winmat[3][2] + 1.0f) / data_.winmat[2][2]; + } + private: /** Called from draw manager. */ void bind(); |