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 "GPU_capabilities.h"
#include "BLI_rand.hh"
#include "workbench_private.hh"
namespace blender::workbench {
@@ -231,10 +233,11 @@ class Instance {
}
}
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) {
mat = Material(*ob_ref.object);
}
@@ -250,7 +253,18 @@ class Instance {
GPUBatch *batch = geometry_get(ob_ref);
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);
}
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);
bounds_buf.get_or_resize(resource_len_).sync();

View File

@@ -480,8 +480,8 @@ static void draw_compute_culling(DRWView *view)
cull->mask = 0;
}
else {
bool culled = !draw_culling_sphere_test(
&view->frustum_bsphere, view->frustum_planes, &cull->bsphere);
bool culled = false; //! draw_culling_sphere_test(
//&view->frustum_bsphere, view->frustum_planes, &cull->bsphere);
#ifdef DRW_DEBUG_CULLING
if (G.debug_value != 0) {
@@ -496,9 +496,9 @@ static void draw_compute_culling(DRWView *view)
}
#endif
if (view->visibility_fn) {
culled = !view->visibility_fn(!culled, cull->user_data);
}
// if (view->visibility_fn) {
// culled = !view->visibility_fn(!culled, cull->user_data);
// }
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)
{
model = model_matrix;
model_inverse = model_matrix.inverted();
// model_inverse = model_matrix.inverted();
}
inline std::ostream &operator<<(std::ostream &stream, const ObjectMatrices &matrices)