Commit: 693dffb7b7c1039c2165b83b1b81fa39256d6ef8 Author: Miguel Pozo Date: Fri Jan 20 18:01:18 2023 +0100 Branches: tmp-worbench-rewrite2-optimizations https://developer.blender.org/rB693dffb7b7c1039c2165b83b1b81fa39256d6ef8
Use smaller ObjectBounds Only store center and size. Skip resource finalize computation. =================================================================== M source/blender/draw/engines/workbench/workbench_private.hh M source/blender/draw/engines/workbench/workbench_shadow.cc M source/blender/draw/intern/draw_manager.cc M source/blender/draw/intern/draw_resource.hh M source/blender/draw/intern/draw_shader_shared.h M source/blender/draw/intern/draw_view.cc M source/blender/draw/intern/draw_view.hh M source/blender/draw/intern/shaders/draw_resource_finalize_comp.glsl M source/blender/draw/intern/shaders/draw_view_info.hh M source/blender/draw/intern/shaders/draw_visibility_comp.glsl =================================================================== diff --git a/source/blender/draw/engines/workbench/workbench_private.hh b/source/blender/draw/engines/workbench/workbench_private.hh index 086553ca5c1..2022fb69945 100644 --- a/source/blender/draw/engines/workbench/workbench_private.hh +++ b/source/blender/draw/engines/workbench/workbench_private.hh @@ -269,7 +269,10 @@ class ShadowPass { ShadowView(); protected: - virtual void compute_visibility(ObjectBoundsBuf &bounds, uint resource_len, bool debug_freeze); + virtual void compute_visibility(ObjectMatricesBuf &matrices, + ObjectBoundsBuf &bounds, + uint resource_len, + bool debug_freeze); virtual VisibilityBuf &get_visibility_buffer(); } view_ = {}; diff --git a/source/blender/draw/engines/workbench/workbench_shadow.cc b/source/blender/draw/engines/workbench/workbench_shadow.cc index 22c7b663220..909edd63667 100644 --- a/source/blender/draw/engines/workbench/workbench_shadow.cc +++ b/source/blender/draw/engines/workbench/workbench_shadow.cc @@ -201,7 +201,8 @@ void ShadowPass::ShadowView::set_mode(ShadowPass::PassType type) current_pass_type_ = type; } -void ShadowPass::ShadowView::compute_visibility(ObjectBoundsBuf &bounds, +void ShadowPass::ShadowView::compute_visibility(ObjectMatricesBuf &matrices, + ObjectBoundsBuf &bounds, uint resource_len, bool debug_freeze) { @@ -231,6 +232,8 @@ void ShadowPass::ShadowView::compute_visibility(ObjectBoundsBuf &bounds, GPU_storagebuf_clear(visibility_buf_, GPU_R32UI, GPU_DATA_UINT, &data); } + /* TODO(Miguel Pozo): Disabled in the optimization branch */ + do_visibility_ = false; if (do_visibility_) { /* TODO(Miguel Pozo): Use regular culling for the caps pass */ @@ -249,6 +252,7 @@ void ShadowPass::ShadowView::compute_visibility(ObjectBoundsBuf &bounds, GPU_shader_uniform_3fv(shader, "shadow_direction", light_direction_); GPU_uniformbuf_bind(extruded_frustum_, GPU_shader_get_uniform_block(shader, "extruded_frustum")); + GPU_storagebuf_bind(matrices, GPU_shader_get_ssbo(shader, "matrix_buf")); GPU_storagebuf_bind(bounds, GPU_shader_get_ssbo(shader, "bounds_buf")); if (current_pass_type_ == ShadowPass::FORCED_FAIL) { GPU_storagebuf_bind(visibility_buf_, GPU_shader_get_ssbo(shader, "visibility_buf")); diff --git a/source/blender/draw/intern/draw_manager.cc b/source/blender/draw/intern/draw_manager.cc index d1a60c1af1f..540e1900424 100644 --- a/source/blender/draw/intern/draw_manager.cc +++ b/source/blender/draw/intern/draw_manager.cc @@ -166,7 +166,7 @@ void Manager::submit(PassMain &pass, View &view) bool freeze_culling = (U.experimental.use_viewport_debug && DST.draw_ctx.v3d && (DST.draw_ctx.v3d->debug_flag & V3D_DEBUG_FREEZE_CULLING) != 0); - view.compute_visibility(bounds_buf, resource_len_, freeze_culling); + view.compute_visibility(matrix_buf, bounds_buf, resource_len_, freeze_culling); command::RecordingState state; state.inverted_view = view.is_inverted(); diff --git a/source/blender/draw/intern/draw_resource.hh b/source/blender/draw/intern/draw_resource.hh index edc023c5703..09744d6403c 100644 --- a/source/blender/draw/intern/draw_resource.hh +++ b/source/blender/draw/intern/draw_resource.hh @@ -147,56 +147,54 @@ inline std::ostream &operator<<(std::ostream &stream, const ObjectInfos &infos) inline void ObjectBounds::sync() { - bounding_sphere.w = -1.0f; /* Disable test. */ + test_enabled = false; } inline void ObjectBounds::sync(Object &ob) { - BoundBox _bbox; - const BoundBox *bbox = &_bbox; + float3 min, max; + INIT_MINMAX(min, max); if (ob.type == OB_MESH) { /* Optimization: Retrieve the mesh cached min max directly. * Avoids allocating a BoundBox on every sample for each DupliObject instance. * TODO(Miguel Pozo): Remove once T92963 or T96968 are done */ - float3 min, max; BKE_mesh_wrapper_minmax(static_cast<Mesh *>(ob.data), min, max); - BKE_boundbox_init_from_minmax(&_bbox, min, max); } else { - bbox = BKE_object_boundbox_get(&ob); + const BoundBox *bbox = BKE_object_boundbox_get(&ob); if (bbox == nullptr) { - bounding_sphere.w = -1.0f; /* Disable test. */ + test_enabled = false; return; } + + for (const float3 &corner : bbox->vec) { + minmax_v3v3_v3(min, max, corner); + } } - *reinterpret_cast<float3 *>(&bounding_corners[0]) = bbox->vec[0]; - *reinterpret_cast<float3 *>(&bounding_corners[1]) = bbox->vec[4]; - *reinterpret_cast<float3 *>(&bounding_corners[2]) = bbox->vec[3]; - *reinterpret_cast<float3 *>(&bounding_corners[3]) = bbox->vec[1]; - bounding_sphere.w = 0.0f; /* Enable test. */ + size = (max - min) / 2.0f; + center = min + size; + test_enabled = true; +} + +inline void ObjectBounds::sync(const float3 ¢er, const float3 &size) +{ + this->center = center; + this->size = size; + test_enabled = true; } inline std::ostream &operator<<(std::ostream &stream, const ObjectBounds &bounds) { stream << "ObjectBounds("; - if (bounds.bounding_sphere.w == -1.0f) { + if (!bounds.test_enabled) { stream << "skipped)" << std::endl; return stream; } stream << std::endl; - stream << ".bounding_corners[0]" - << *reinterpret_cast<const float3 *>(&bounds.bounding_corners[0]) << std::endl; - stream << ".bounding_corners[1]" - << *reinterpret_cast<const float3 *>(&bounds.bounding_corners[1]) << std::endl; - stream << ".bounding_corners[2]" - << *reinterpret_cast<const float3 *>(&bounds.bounding_corners[2]) << std::endl; - stream << ".bounding_corners[3]" - << *reinterpret_cast<const float3 *>(&bounds.bounding_corners[3]) << std::endl; - stream << ".sphere=(pos=" << float3(bounds.bounding_sphere) - << ", rad=" << bounds.bounding_sphere.w << std::endl; - stream << ")" << std::endl; + stream << ".center" << bounds.center << std::endl; + stream << ".size" << bounds.size << std::endl; return stream; } diff --git a/source/blender/draw/intern/draw_shader_shared.h b/source/blender/draw/intern/draw_shader_shared.h index 23ded2ea5e9..d8ee2381054 100644 --- a/source/blender/draw/intern/draw_shader_shared.h +++ b/source/blender/draw/intern/draw_shader_shared.h @@ -175,15 +175,11 @@ struct ObjectInfos { BLI_STATIC_ASSERT_ALIGN(ObjectInfos, 16) struct ObjectBounds { - /** - * Uploaded as vertex (0, 4, 3, 1) of the bbox in local space, matching XYZ axis order. - * Then processed by GPU and stored as (0, 4-0, 3-0, 1-0) in world space for faster culling. - */ - float4 bounding_corners[4]; - /** Bounding sphere derived from the bounding corner. Computed on GPU. */ - float4 bounding_sphere; - /** Radius of the inscribed sphere derived from the bounding corner. Computed on GPU. */ -#define _inner_sphere_radius bounding_corners[3].w + float3 center; + bool test_enabled; + /* TODO(Miguel Pozo): This is actually half size */ + float3 size; + uint _pad; #if !defined(GPU_SHADER) && defined(__cplusplus) void sync(); diff --git a/source/blender/draw/intern/draw_view.cc b/source/blender/draw/intern/draw_view.cc index 85f31844311..2ff030bdd08 100644 --- a/source/blender/draw/intern/draw_view.cc +++ b/source/blender/draw/intern/draw_view.cc @@ -227,7 +227,10 @@ void View::bind() GPU_uniformbuf_bind(culling_, DRW_VIEW_CULLING_UBO_SLOT); } -void View::compute_visibility(ObjectBoundsBuf &bounds, uint resource_len, bool debug_freeze) +void View::compute_visibility(ObjectMatricesBuf &matrices, + ObjectBoundsBuf &bounds, + uint resource_len, + bool debug_freeze) { if (debug_freeze && frozen_ == false) { data_freeze_[0] = static_cast<ViewMatrices>(data_[0]); @@ -264,6 +267,7 @@ void View::compute_visibility(ObjectBoundsBuf &bounds, uint resource_len, bool d GPU_shader_uniform_1i(shader, "resource_len", resource_len); GPU_shader_uniform_1i(shader, "view_len", view_len_); GPU_shader_uniform_1i(shader, "visibility_word_per_draw", word_per_draw); + GPU_storagebuf_bind(matrices, GPU_shader_get_ssbo(shader, "matrix_buf")); GPU_storagebuf_bind(bounds, GPU_shader_get_ssbo(shader, "bounds_buf")); GPU_storagebuf_bind(visibility_buf_, GPU_shader_get_ssbo(shader, "visibility_buf")); GPU_uniformbuf_bind(frozen_ ? data_freeze_ : data_, DRW_VIEW_UBO_SLOT); diff --git a/source/blender/draw/intern/draw_view.hh b/source/blender/draw/intern/draw_view.hh index 5bf2bf1a568..e47a6980b20 100644 --- a/source/blender/draw/intern/draw_view.hh +++ b/source/blender/draw/intern/draw_view.hh @@ -26,6 +26,7 @@ namespace blender::draw { class Manager; /* TODO: de-duplicate. */ +using ObjectMatricesBuf = StorageArrayBuffer<ObjectMatrices, 128>; using ObjectBoundsBuf = StorageArrayBuffer<ObjectBounds, 128>; using VisibilityBuf = StorageArrayBuffer<uint, 4, true>; @@ -135,7 +136,10 @@ class View { protected: /** Called from draw manager. */ void bind(); - virtual void compute_visibility(ObjectBoundsBuf &bounds, uint resource_len, bool debug_freeze); + virtual void compute_visibility(ObjectMatricesBuf &matrices, + ObjectBoundsBuf &bounds, + uint resource_len, + bool debug_freeze); virtual VisibilityBuf &get_visibility_buffer(); void update_viewport_size(); diff --git a/source/blender/draw/intern/shaders/draw_resource_finalize_comp.glsl b/source/blender/draw/intern/shaders/draw_resource_finalize_comp.glsl index 511d4e49651..c410544826c 100644 --- a/source/blender/draw/intern/shaders/draw_resource_finalize_comp.glsl +++ b/source/blender/draw/intern/shaders/draw_resource_finalize_comp.glsl @@ -14,6 +14,8 @@ void main() mat4 model_mat = matrix_buf[resource_id].model; ObjectInfos infos = infos_buf[resource_id]; + +#if 0 ObjectBounds bounds = bounds_buf[resource_id]; if (bounds.bounding_sphere.w != -1. @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs