[Bf-blender-cvs] [9c5dd7aad89] temp-pbvh-vbos: Merge branch 'master' into temp-pbvh-vbos

Joseph Eagar noreply at git.blender.org
Wed Sep 14 09:28:28 CEST 2022


Commit: 9c5dd7aad894d3224566c8dba39f8c9f50145517
Author: Joseph Eagar
Date:   Wed Sep 14 00:28:18 2022 -0700
Branches: temp-pbvh-vbos
https://developer.blender.org/rB9c5dd7aad894d3224566c8dba39f8c9f50145517

Merge branch 'master' into temp-pbvh-vbos

===================================================================



===================================================================

diff --cc source/blender/blenkernel/intern/pbvh.c
index c4d2279140c,2e273e076d5..cee2cbe6c8a
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@@ -536,67 -534,6 +536,79 @@@ static void pbvh_build(PBVH *pbvh, BB *
    build_sub(pbvh, 0, cb, prim_bbc, 0, totprim);
  }
  
 +static void pbvh_draw_args(PBVH *pbvh, PBVH_GPU_Args *args, PBVHNode *node)
 +{
 +  memset((void *)args, 0, sizeof(*args));
 +
++  if (!node->prim_indices) {
++    printf("error! %s\n", __func__);
++  }
++
 +  args->pbvh_type = pbvh->header.type;
 +  args->mesh_verts_num = pbvh->totvert;
 +  args->mesh_grids_num = pbvh->totgrid;
 +  args->node = node;
 +
 +  BKE_pbvh_node_num_verts(pbvh, node, NULL, &args->node_verts_num);
 +
 +  args->grid_hidden = pbvh->grid_hidden;
 +  args->face_sets_color_default = pbvh->face_sets_color_default;
 +  args->face_sets_color_seed = pbvh->face_sets_color_seed;
 +  args->mvert = pbvh->verts;
 +  args->mloop = pbvh->mloop;
 +  args->mpoly = pbvh->mpoly;
 +  args->mlooptri = pbvh->looptri;
 +
++  if (ELEM(pbvh->header.type, PBVH_FACES, PBVH_GRIDS)) {
++    args->hide_poly = pbvh->pdata ?
++                          CustomData_get_layer_named(pbvh->pdata, CD_PROP_BOOL, ".hide_poly") :
++                          NULL;
++  }
++
 +  switch (pbvh->header.type) {
 +    case PBVH_FACES:
 +      args->mesh_faces_num = pbvh->mesh->totpoly;
 +      args->vdata = pbvh->vdata;
 +      args->ldata = pbvh->ldata;
 +      args->pdata = pbvh->pdata;
 +      args->totprim = node->totprim;
 +      args->me = pbvh->mesh;
++      args->mpoly = pbvh->mpoly;
 +      args->vert_normals = pbvh->vert_normals;
 +
-       args->prim_indicies = node->prim_indices;
++      args->prim_indices = node->prim_indices;
 +      break;
 +    case PBVH_GRIDS:
 +      args->vdata = pbvh->vdata;
 +      args->ldata = pbvh->ldata;
 +      args->pdata = pbvh->pdata;
 +      args->ccg_key = pbvh->gridkey;
 +      args->me = pbvh->mesh;
 +      args->totprim = node->totprim;
 +      args->grid_indices = node->prim_indices;
 +      args->subdiv_ccg = pbvh->subdiv_ccg;
 +      args->face_sets = pbvh->face_sets;
++      args->mpoly = pbvh->mpoly;
 +
 +      args->mesh_grids_num = pbvh->totgrid;
 +      args->grids = pbvh->grids;
 +      args->gridfaces = pbvh->gridfaces;
 +      args->grid_flag_mats = pbvh->grid_flag_mats;
 +      args->vert_normals = pbvh->vert_normals;
 +      break;
 +    case PBVH_BMESH:
 +      args->bm = pbvh->header.bm;
 +      args->vdata = &args->bm->vdata;
 +      args->ldata = &args->bm->ldata;
 +      args->pdata = &args->bm->pdata;
 +      args->bm_faces = node->bm_faces;
 +      args->bm_other_verts = node->bm_other_verts;
 +      args->bm_unique_vert = node->bm_unique_verts;
 +      args->totprim = BLI_gset_len(node->bm_faces);
 +      break;
 +  }
 +}
 +
  void BKE_pbvh_build_mesh(PBVH *pbvh,
                           Mesh *mesh,
                           const MPoly *mpoly,
diff --cc source/blender/draw/CMakeLists.txt
index 3ddabeed4e6,e6b532ed25a..368e5f9ec3b
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@@ -92,9 -94,6 +94,7 @@@ set(SR
    intern/draw_manager_shader.c
    intern/draw_manager_text.c
    intern/draw_manager_texture.c
 +  intern/draw_pbvh.cc
-   intern/draw_manager.c
-   intern/draw_manager.cc
    intern/draw_select_buffer.c
    intern/draw_shader.cc
    intern/draw_texture_pool.cc
@@@ -225,9 -228,6 +229,7 @@@
    intern/draw_manager_profiling.h
    intern/draw_manager_testing.h
    intern/draw_manager_text.h
 +  intern/draw_pbvh.h
-   intern/draw_manager.h
-   intern/draw_manager.hh
    intern/draw_pass.hh
    intern/draw_resource.cc
    intern/draw_resource.hh
diff --cc source/blender/draw/DRW_engine.h
index 2dbf2112ed0,dec7a22aadb..9dc8ac372ae
--- a/source/blender/draw/DRW_engine.h
+++ b/source/blender/draw/DRW_engine.h
@@@ -239,63 -227,6 +239,65 @@@ void DRW_cdlayer_attr_aliases_add(struc
                                    const struct CustomDataLayer *cl,
                                    bool is_active_render,
                                    bool is_active_layer);
 +
 +/* PBVH */
 +
 +typedef struct PBVHBatches PBVHBatches;
 +
 +typedef struct PBVH_GPU_Args {
 +  int pbvh_type;
 +
 +  struct BMesh *bm;
 +  const struct Mesh *me;
 +  const struct MVert *mvert;
 +  const struct MLoop *mloop;
 +  const struct MPoly *mpoly;
 +  int mesh_verts_num, mesh_faces_num, mesh_grids_num;
 +  struct CustomData *vdata, *ldata, *pdata;
 +  const float (*vert_normals)[3];
 +
 +  int face_sets_color_seed, face_sets_color_default;
 +  int *face_sets; /* for PBVH_FACES and PBVH_GRIDS */
 +
 +  struct SubdivCCG *subdiv_ccg;
 +  const struct DMFlagMat *grid_flag_mats;
 +  const int *grid_indices;
 +  struct CCGKey ccg_key;
 +  CCGElem **grids;
 +  void **gridfaces;
 +  BLI_bitmap **grid_hidden;
 +
-   int *prim_indicies;
++  int *prim_indices;
 +  int totprim;
 +
++  bool *hide_poly;
++
 +  int node_verts_num;
 +
 +  const struct GSet *bm_unique_vert, *bm_other_verts, *bm_faces;
 +  const struct MLoopTri *mlooptri;
 +  struct PBVHNode *node;
 +} PBVH_GPU_Args;
 +
 +typedef struct PBVHGPUFormat PBVHGPUFormat;
 +
 +void DRW_pbvh_node_update(struct PBVHBatches *batches, struct PBVH_GPU_Args *args);
 +void DRW_pbvh_update_pre(struct PBVHBatches *batches, struct PBVH_GPU_Args *args);
 +
 +void DRW_pbvh_node_gpu_flush(struct PBVHBatches *batches);
 +struct PBVHBatches *DRW_pbvh_node_create(struct PBVH_GPU_Args *args);
 +void DRW_pbvh_node_free(struct PBVHBatches *batches);
 +struct GPUBatch *DRW_pbvh_tris_get(struct PBVHBatches *batches,
 +                                   struct PBVHAttrReq *attrs,
 +                                   int attrs_num,
 +                                   struct PBVH_GPU_Args *args,
 +                                   int *r_prim_count);
 +struct GPUBatch *DRW_pbvh_lines_get(struct PBVHBatches *batches,
 +                                    struct PBVHAttrReq *attrs,
 +                                    int attrs_num,
 +                                    struct PBVH_GPU_Args *args,
 +                                    int *r_prim_count);
 +
  #ifdef __cplusplus
  }
  #endif
diff --cc source/blender/draw/intern/draw_pbvh.cc
index 75518b188c0,00000000000..58083d0f44f
mode 100644,000000..100644
--- a/source/blender/draw/intern/draw_pbvh.cc
+++ b/source/blender/draw/intern/draw_pbvh.cc
@@@ -1,890 -1,0 +1,906 @@@
 +/* SPDX-License-Identifier: GPL-2.0-or-later
 + * Copyright 2005 Blender Foundation. All rights reserved. */
 +
 +/** \file
 + * \ingroup gpu
 + *
 + * Mesh drawing using OpenGL VBO (Vertex Buffer Objects)
 + */
 +
 +#include <limits.h>
 +#include <stddef.h>
 +#include <stdlib.h>
 +#include <string.h>
 +
 +#include "MEM_guardedalloc.h"
 +
 +#include "BLI_bitmap.h"
 +#include "BLI_ghash.h"
 +#include "BLI_math_color.h"
 +#include "BLI_utildefines.h"
 +
 +#include "DNA_mesh_types.h"
 +#include "DNA_meshdata_types.h"
 +
 +#include "BKE_DerivedMesh.h"
 +#include "BKE_attribute.h"
 +#include "BKE_ccg.h"
 +#include "BKE_customdata.h"
 +#include "BKE_mesh.h"
 +#include "BKE_paint.h"
 +#include "BKE_pbvh.h"
 +#include "BKE_subdiv_ccg.h"
 +
 +#include "GPU_batch.h"
 +#include "GPU_buffers.h"
 +
 +#include "DRW_engine.h"
 +#include "draw_pbvh.h"
 +
 +#include "gpu_private.h"
 +
 +#include "bmesh.h"
 +
 +#define MAX_PBVH_BATCH_KEY 512
 +#define MAX_PBVH_VBOS 16
 +
 +#include "BLI_index_range.hh"
 +#include "BLI_map.hh"
 +#include "BLI_math_vec_types.hh"
 +#include "BLI_vector.hh"
 +#include <vector>
 +
 +#include <algorithm>
 +#include <string>
 +
 +using blender::float2;
 +using blender::float3;
 +using blender::float4;
 +using blender::IndexRange;
 +using blender::Map;
 +using blender::Vector;
 +
 +using string = std::string;
 +using ushort3 = blender::vec_base<uint16_t, 3>;
 +using ushort4 = blender::vec_base<uint16_t, 4>;
 +using short3 = blender::vec_base<int16_t, 3>;
 +using uchar3 = blender::vec_base<uint8_t, 3>;
 +using char3 = blender::vec_base<int8_t, 3>;
 +using uchar4 = blender::vec_base<uint8_t, 4>;
 +
 +struct PBVHVbo {
 +  uint64_t type;
 +  eAttrDomain domain;
 +  string name;
 +  GPUVertBuf *vert_buf = nullptr;
 +  string key;
 +
 +  PBVHVbo(eAttrDomain _domain, uint64_t _type, string _name)
 +      : type(_type), domain(_domain), name(_name)
 +  {
 +  }
 +
 +  string build_key()
 +  {
 +    char buf[512];
 +
 +    sprintf(buf, "%d:%d:%s", (int)type, (int)domain, name.c_str());
 +
 +    key = string(buf);
 +    return key;
 +  }
 +};
 +
 +struct PBVHBatch {
 +  Vector<int> vbos;
 +  string key;
 +  GPUBatch *tris = nullptr, *lines = nullptr;
 +  int tris_count = 0, lines_count = 0;
 +
 +  void sort_vbos(Vector<PBVHVbo> &master_vbos)
 +  {
 +    struct cmp {
 +      Vector<PBVHVbo> &master_vbos;
 +
 +      cmp(Vector<PBVHVbo> &_master_vbos) : master_vbos(_master_vbos)
 +      {
 +      }
 +
 +      bool operator()(const int &a, const int &b)
 +      {
 +        return master_vbos[a].key < master_vbos[b].key;
 +      }
 +    };
 +
 +    std::sort(vbos.begin(), vbos.end(), cmp(master_vbos));
 +  }
 +
 +  ATTR_NO_OPT string build_key(Vector<PBVHVbo> &master_vbos)
 +  {
 +    key = "";
 +
 +    sort_vbos(master_vbos);
 +
 +    for (int vbo_i : vbos) {
 +      key += master_vbos[vbo_i].key + ":";
 +    }
 +
 +    return key;
 +  }
 +};
 +
 +static CustomData *get_cdata(eAttrDomain domain, PBVH_GPU_Args *args)
 +{
 +  switch (domain) {
 +    case ATTR_DOMAIN_POINT:
 +      return args->vdata;
 +    case ATTR_DOMAIN_CORNER:
 +      return args->ldata;
 +    case ATTR_DOMAIN_FACE:
 +      return args->pdata;
 +    default:
 +      return nullptr;
 +  }
 +}
 +
 +struct PBVHBatches {
 +  Vector<PBVHVbo> vbos;
 +  Map<string, PBVHBatch> batches;
 +  GPUIndexBuf *tri_index = nullptr;
 +  GPUIndexBuf *lines_index = nullptr;
 +  int tris_count = 0, lines_count = 0;
-   bool smooth = false;  // XXX
++  bool needs_tri_index = false;  // XXX
 +
 +  int material_index = 0;
 +
 +  ATTR_NO_OPT ~PBVHBatches()
 +  {
 +    for (PBVHBatch &batch : batches.values()) {
 +      GPU_BATCH_DISCARD_SAFE(batch.tris);
 +      GPU_BATCH_DISCARD_SAFE(batch.lines);
 +    }
 +
 +    for (PBVHVbo &vbo : vbos) {
 +      GPU_vertbuf_discard(vbo.vert_buf);
 +    }
 +
 + 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list