1
1

Experiment with 1M instances fast generation

This commit is contained in:
2022-10-12 09:49:59 +02:00
parent 5a10182a70
commit 81c4833a0d
4 changed files with 24 additions and 10 deletions

View File

@@ -5,6 +5,8 @@
#include "ED_view3d.h" #include "ED_view3d.h"
#include "GPU_capabilities.h" #include "GPU_capabilities.h"
#include "BLI_rand.hh"
#include "workbench_private.hh" #include "workbench_private.hh"
namespace blender::workbench { namespace blender::workbench {
@@ -231,10 +233,11 @@ class Instance {
} }
} }
else { else {
ResourceHandle handle = manager.resource_handle(ob_ref); float4x4 model_matrix(ob_ref.object->obmat);
Material &mat = resources.material_buf.get_or_resize(handle.resource_index()); // ResourceHandle handle = manager.resource_handle(ob_ref);
Material mat;
if (material_subtype == eMaterialSubType::OBJECT) { if (material_subtype == eMaterialSubType::OBJECT) {
mat = Material(*ob_ref.object); mat = Material(*ob_ref.object);
} }
@@ -250,7 +253,18 @@ class Instance {
GPUBatch *batch = geometry_get(ob_ref); GPUBatch *batch = geometry_get(ob_ref);
if (batch) { if (batch) {
pipeline_get(ob_ref).draw(batch, handle); blender::RandomNumberGenerator rng(23423);
for (size_t y = 0; y < 1000; y++) {
for (size_t x = 0; x < 1000; x++) {
model_matrix[3][0] = x * 0.001f;
model_matrix[3][1] = y * 0.001f;
ResourceHandle handle = manager.resource_handle(model_matrix);
resources.material_buf.get_or_resize(handle.resource_index()) = mat;
pipeline_get(ob_ref).draw(batch, handle);
}
}
} }
} }
} }

View File

@@ -180,7 +180,7 @@ inline ResourceHandle Manager::resource_handle(const ObjectRef ref)
return ResourceHandle(resource_len_++, (ref.object->transflag & OB_NEG_SCALE) != 0); return ResourceHandle(resource_len_++, (ref.object->transflag & OB_NEG_SCALE) != 0);
} }
inline ResourceHandle Manager::resource_handle(const float4x4 &model_matrix) BLI_NOINLINE inline ResourceHandle Manager::resource_handle(const float4x4 &model_matrix)
{ {
matrix_buf.get_or_resize(resource_len_).sync(model_matrix); matrix_buf.get_or_resize(resource_len_).sync(model_matrix);
bounds_buf.get_or_resize(resource_len_).sync(); bounds_buf.get_or_resize(resource_len_).sync();

View File

@@ -480,8 +480,8 @@ static void draw_compute_culling(DRWView *view)
cull->mask = 0; cull->mask = 0;
} }
else { else {
bool culled = !draw_culling_sphere_test( bool culled = false; //! draw_culling_sphere_test(
&view->frustum_bsphere, view->frustum_planes, &cull->bsphere); //&view->frustum_bsphere, view->frustum_planes, &cull->bsphere);
#ifdef DRW_DEBUG_CULLING #ifdef DRW_DEBUG_CULLING
if (G.debug_value != 0) { if (G.debug_value != 0) {
@@ -496,9 +496,9 @@ static void draw_compute_culling(DRWView *view)
} }
#endif #endif
if (view->visibility_fn) { // if (view->visibility_fn) {
culled = !view->visibility_fn(!culled, cull->user_data); // culled = !view->visibility_fn(!culled, cull->user_data);
} // }
SET_FLAG_FROM_TEST(cull->mask, culled, view->culling_mask); SET_FLAG_FROM_TEST(cull->mask, culled, view->culling_mask);
} }

View File

@@ -38,7 +38,7 @@ inline void ObjectMatrices::sync(const Object &object)
inline void ObjectMatrices::sync(const float4x4 &model_matrix) inline void ObjectMatrices::sync(const float4x4 &model_matrix)
{ {
model = model_matrix; model = model_matrix;
model_inverse = model_matrix.inverted(); // model_inverse = model_matrix.inverted();
} }
inline std::ostream &operator<<(std::ostream &stream, const ObjectMatrices &matrices) inline std::ostream &operator<<(std::ostream &stream, const ObjectMatrices &matrices)