[Bf-blender-cvs] [6a0a92c587f] temp-pbvh-split: Merge branch 'master' into temp-pbvh-split
Joseph Eagar
noreply at git.blender.org
Fri Oct 7 11:33:17 CEST 2022
Commit: 6a0a92c587f0b8496dd3494f2b551d88f29564bf
Author: Joseph Eagar
Date: Thu Oct 6 14:14:55 2022 -0700
Branches: temp-pbvh-split
https://developer.blender.org/rB6a0a92c587f0b8496dd3494f2b551d88f29564bf
Merge branch 'master' into temp-pbvh-split
===================================================================
===================================================================
diff --cc source/blender/blenkernel/intern/pbvh_intern.h
index 36ef5e85149,bdfd3ad3d09..c78bfc25cb2
--- a/source/blender/blenkernel/intern/pbvh_intern.h
+++ b/source/blender/blenkernel/intern/pbvh_intern.h
@@@ -142,11 -147,9 +147,11 @@@ struct PBVH
int totvert;
int leaf_limit;
+ int pixel_leaf_limit;
+ int depth_limit;
/* Mesh data */
- const struct Mesh *mesh;
+ struct Mesh *mesh;
/* NOTE: Normals are not `const` because they can be updated for drawing by sculpt code. */
float (*vert_normals)[3];
diff --cc source/blender/draw/intern/DRW_render.h
index b3dfa681e2c,1752198c349..d134e97e925
--- a/source/blender/draw/intern/DRW_render.h
+++ b/source/blender/draw/intern/DRW_render.h
@@@ -17,8 -17,7 +17,8 @@@
#include "BKE_context.h"
#include "BKE_layer.h"
#include "BKE_material.h"
- #include "BKE_scene.h"
+#include "BKE_pbvh.h"
+ #include "BKE_scene.h"
#include "BLT_translation.h"
diff --cc source/blender/draw/intern/draw_manager_data.cc
index 00000000000,6741d25bcdf..2931766c5d6
mode 000000,100644..100644
--- a/source/blender/draw/intern/draw_manager_data.cc
+++ b/source/blender/draw/intern/draw_manager_data.cc
@@@ -1,0 -1,2589 +1,2590 @@@
+ /* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright 2016 Blender Foundation. */
+
+ /** \file
+ * \ingroup draw
+ */
+
+ #include "DRW_pbvh.h"
+
+ #include "draw_attributes.h"
+ #include "draw_manager.h"
+ #include "draw_pbvh.h"
+
+ #include "BKE_curve.h"
+ #include "BKE_duplilist.h"
+ #include "BKE_global.h"
+ #include "BKE_image.h"
+ #include "BKE_mesh.h"
+ #include "BKE_object.h"
+ #include "BKE_paint.h"
+ #include "BKE_pbvh.h"
+ #include "BKE_volume.h"
+
+ /* For debug cursor position. */
+ #include "WM_api.h"
+ #include "wm_window.h"
+
+ #include "DNA_curve_types.h"
+ #include "DNA_mesh_types.h"
+ #include "DNA_meta_types.h"
+ #include "DNA_screen_types.h"
+
+ #include "BLI_array.hh"
+ #include "BLI_hash.h"
+ #include "BLI_link_utils.h"
+ #include "BLI_listbase.h"
+ #include "BLI_math_bits.h"
+ #include "BLI_memblock.h"
+ #include "BLI_mempool.h"
+
+ #ifdef DRW_DEBUG_CULLING
+ # include "BLI_math_bits.h"
+ #endif
+
+ #include "GPU_capabilities.h"
+ #include "GPU_material.h"
+ #include "GPU_uniform_buffer.h"
+
+ #include "intern/gpu_codegen.h"
+
+ /**
+ * IMPORTANT:
+ * In order to be able to write to the same print buffer sequentially, we add a barrier to allow
+ * multiple shader calls writing to the same buffer.
+ * However, this adds explicit synchronization events which might change the rest of the
+ * application behavior and hide some bugs. If you know you are using shader debug print in only
+ * one shader pass, you can comment this out to remove the aforementioned barrier.
+ */
+ #define DISABLE_DEBUG_SHADER_PRINT_BARRIER
+
+ /* -------------------------------------------------------------------- */
+ /** \name Uniform Buffer Object (DRW_uniformbuffer)
+ * \{ */
+
+ static void draw_call_sort(DRWCommand *array, DRWCommand *array_tmp, int array_len)
+ {
+ /* Count unique batches. It's not really important if
+ * there is collisions. If there is a lot of different batches,
+ * the sorting benefit will be negligible.
+ * So at least sort fast! */
+ uchar idx[128] = {0};
+ /* Shift by 6 positions knowing each GPUBatch is > 64 bytes */
+ #define KEY(a) ((size_t((a).draw.batch) >> 6) % ARRAY_SIZE(idx))
+ BLI_assert(array_len <= ARRAY_SIZE(idx));
+
+ for (int i = 0; i < array_len; i++) {
+ /* Early out if nothing to sort. */
+ if (++idx[KEY(array[i])] == array_len) {
+ return;
+ }
+ }
+ /* Accumulate batch indices */
+ for (int i = 1; i < ARRAY_SIZE(idx); i++) {
+ idx[i] += idx[i - 1];
+ }
+ /* Traverse in reverse to not change the order of the resource ID's. */
+ for (int src = array_len - 1; src >= 0; src--) {
+ array_tmp[--idx[KEY(array[src])]] = array[src];
+ }
+ #undef KEY
+
+ memcpy(array, array_tmp, sizeof(*array) * array_len);
+ }
+
+ void drw_resource_buffer_finish(DRWData *vmempool)
+ {
+ int chunk_id = DRW_handle_chunk_get(&DST.resource_handle);
+ int elem_id = DRW_handle_id_get(&DST.resource_handle);
+ int ubo_len = 1 + chunk_id - ((elem_id == 0) ? 1 : 0);
+ size_t list_size = sizeof(GPUUniformBuf *) * ubo_len;
+
+ /* TODO: find a better system. currently a lot of obinfos UBO are going to be unused
+ * if not rendering with Eevee. */
+
+ if (vmempool->matrices_ubo == nullptr) {
+ vmempool->matrices_ubo = static_cast<GPUUniformBuf **>(MEM_callocN(list_size, __func__));
+ vmempool->obinfos_ubo = static_cast<GPUUniformBuf **>(MEM_callocN(list_size, __func__));
+ vmempool->ubo_len = ubo_len;
+ }
+
+ /* Remove unnecessary buffers */
+ for (int i = ubo_len; i < vmempool->ubo_len; i++) {
+ GPU_uniformbuf_free(vmempool->matrices_ubo[i]);
+ GPU_uniformbuf_free(vmempool->obinfos_ubo[i]);
+ }
+
+ if (ubo_len != vmempool->ubo_len) {
+ vmempool->matrices_ubo = static_cast<GPUUniformBuf **>(
+ MEM_recallocN(vmempool->matrices_ubo, list_size));
+ vmempool->obinfos_ubo = static_cast<GPUUniformBuf **>(
+ MEM_recallocN(vmempool->obinfos_ubo, list_size));
+ vmempool->ubo_len = ubo_len;
+ }
+
+ /* Create/Update buffers. */
+ for (int i = 0; i < ubo_len; i++) {
+ void *data_obmat = BLI_memblock_elem_get(vmempool->obmats, i, 0);
+ void *data_infos = BLI_memblock_elem_get(vmempool->obinfos, i, 0);
+ if (vmempool->matrices_ubo[i] == nullptr) {
+ vmempool->matrices_ubo[i] = GPU_uniformbuf_create(sizeof(DRWObjectMatrix) *
+ DRW_RESOURCE_CHUNK_LEN);
+ vmempool->obinfos_ubo[i] = GPU_uniformbuf_create(sizeof(DRWObjectInfos) *
+ DRW_RESOURCE_CHUNK_LEN);
+ }
+ GPU_uniformbuf_update(vmempool->matrices_ubo[i], data_obmat);
+ GPU_uniformbuf_update(vmempool->obinfos_ubo[i], data_infos);
+ }
+
+ DRW_uniform_attrs_pool_flush_all(vmempool->obattrs_ubo_pool);
+
+ /* Aligned alloc to avoid unaligned memcpy. */
+ DRWCommandChunk *chunk_tmp = static_cast<DRWCommandChunk *>(
+ MEM_mallocN_aligned(sizeof(DRWCommandChunk), 16, __func__));
+ DRWCommandChunk *chunk;
+ BLI_memblock_iter iter;
+ BLI_memblock_iternew(vmempool->commands, &iter);
+ while ((chunk = static_cast<DRWCommandChunk *>(BLI_memblock_iterstep(&iter)))) {
+ bool sortable = true;
+ /* We can only sort chunks that contain #DRWCommandDraw only. */
+ for (int i = 0; i < ARRAY_SIZE(chunk->command_type) && sortable; i++) {
+ if (chunk->command_type[i] != 0) {
+ sortable = false;
+ }
+ }
+ if (sortable) {
+ draw_call_sort(chunk->commands, chunk_tmp->commands, chunk->command_used);
+ }
+ }
+ MEM_freeN(chunk_tmp);
+ }
+
+ /** \} */
+
+ /* -------------------------------------------------------------------- */
+ /** \name Uniforms (DRW_shgroup_uniform)
+ * \{ */
+
+ static void drw_shgroup_uniform_create_ex(DRWShadingGroup *shgroup,
+ int loc,
+ DRWUniformType type,
+ const void *value,
+ eGPUSamplerState sampler_state,
+ int length,
+ int arraysize)
+ {
+ if (loc == -1) {
+ /* Nice to enable eventually, for now EEVEE uses uniforms that might not exist. */
+ // BLI_assert(0);
+ return;
+ }
+
+ DRWUniformChunk *unichunk = shgroup->uniforms;
+ /* Happens on first uniform or if chunk is full. */
+ if (!unichunk || unichunk->uniform_used == unichunk->uniform_len) {
+ unichunk = static_cast<DRWUniformChunk *>(BLI_memblock_alloc(DST.vmempool->uniforms));
+ unichunk->uniform_len = ARRAY_SIZE(shgroup->uniforms->uniforms);
+ unichunk->uniform_used = 0;
+ BLI_LINKS_PREPEND(shgroup->uniforms, unichunk);
+ }
+
+ DRWUniform *uni = unichunk->uniforms + unichunk->uniform_used++;
+
+ uni->location = loc;
+ uni->type = type;
+ uni->length = length;
+ uni->arraysize = arraysize;
+
+ switch (type) {
+ case DRW_UNIFORM_INT_COPY:
+ BLI_assert(length <= 4);
+ memcpy(uni->ivalue, value, sizeof(int) * length);
+ break;
+ case DRW_UNIFORM_FLOAT_COPY:
+ BLI_assert(length <= 4);
+ memcpy(uni->fvalue, value, sizeof(float) * length);
+ break;
+ case DRW_UNIFORM_BLOCK:
+ uni->block = (GPUUniformBuf *)value;
+ break;
+ case DRW_UNIFORM_BLOCK_REF:
+ uni->block_ref = (GPUUniformBuf **)value;
+ break;
+ case DRW_UNIFORM_IMAGE:
+ case DRW_UNIFORM_TEXTURE:
+ uni->texture = (GPUTexture *)value;
+ uni->sampler_state = sampler_state;
+ break;
+ case DRW_UNIFORM_IMAGE_REF:
+ case DRW_UNIFORM_TEXTURE_REF:
+ uni->texture_ref = (GPUTexture **)value;
+ uni->sampler_state = sampler_state;
+ break;
+ case DRW_UNIFORM_BLOCK_OBATTRS:
+ uni->uniform_attrs = (GPUUniformAttrList *)value;
+ break;
+ default:
+ uni->pvalue = (const float *)value;
+ break;
+ }
+ }
+
+ static void drw_shgroup_uniform(DRWShadingGroup *shgroup,
+ const char *name,
+ DRWUniformType type,
+ const void *value,
+ int length,
+ int arraysize)
+ {
+ BLI_assert(arraysize > 0 && arraysize <= 16);
+ BLI_assert(length >= 0 && length <= 16);
+ BLI_assert(!ELEM(type,
+ DRW_UNIFORM_STORAGE_BLOCK,
+ DRW_UNIFORM_STORAGE_BLOCK_REF,
+ DRW_UNIFORM_BLOCK,
+ DRW_UNIFORM_BLOCK_REF,
+ DRW_UNIFORM_TEXTURE,
+ DRW_UNIFORM_TEXTURE_REF));
+ int location = GPU_shader_get_uniform(shgroup->shader, name);
+ drw_shgroup_uniform_create_ex(
+ shgroup, location, type, value, GPU_SAMPLER_DEFAULT, length, arraysize);
+ }
+
+ void DRW_shgroup_uniform_texture_ex(DRWShadingGroup *shgroup,
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list