2022-02-11 09:07:11 +11:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
* Copyright 2005 Blender Foundation. All rights reserved. */
|
2009-10-03 15:35:01 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
* \ingroup gpu
|
2011-02-21 06:58:46 +00:00
|
|
|
*/
|
|
|
|
|
2009-10-03 15:35:01 +00:00
|
|
|
#pragma once
|
|
|
|
|
2015-07-17 12:25:05 +02:00
|
|
|
#include <stddef.h>
|
|
|
|
|
2022-04-05 11:42:55 -07:00
|
|
|
#include "BKE_attribute.h"
|
|
|
|
|
2020-03-02 15:28:47 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2012-12-30 18:24:54 +00:00
|
|
|
struct BMesh;
|
2012-05-10 20:33:09 +00:00
|
|
|
struct CCGElem;
|
|
|
|
struct CCGKey;
|
|
|
|
struct DMFlagMat;
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
struct GSet;
|
|
|
|
struct MLoop;
|
2019-05-14 20:20:01 +10:00
|
|
|
struct MLoopCol;
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
struct MLoopTri;
|
|
|
|
struct MPoly;
|
2020-09-30 11:51:13 +10:00
|
|
|
struct MPropCol;
|
2015-07-16 16:22:28 +02:00
|
|
|
struct MVert;
|
2019-12-17 10:08:47 +11:00
|
|
|
struct Mesh;
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
struct PBVH;
|
2020-04-03 08:29:09 -06:00
|
|
|
struct SubdivCCG;
|
2015-07-14 16:48:23 +02:00
|
|
|
|
2021-12-09 20:01:47 +11:00
|
|
|
/**
|
|
|
|
* Buffers for drawing from PBVH grids.
|
|
|
|
*/
|
2014-01-02 22:22:36 +02:00
|
|
|
typedef struct GPU_PBVH_Buffers GPU_PBVH_Buffers;
|
2012-02-22 22:48:34 +00:00
|
|
|
|
2021-12-09 20:01:47 +11:00
|
|
|
/**
|
|
|
|
* Build must be called once before using the other functions,
|
|
|
|
* used every time mesh topology changes.
|
|
|
|
*
|
|
|
|
* Threaded: do not call any functions that use OpenGL calls!
|
|
|
|
*/
|
2020-05-14 15:27:11 +02:00
|
|
|
GPU_PBVH_Buffers *GPU_pbvh_mesh_buffers_build(const struct MPoly *mpoly,
|
2015-07-17 03:36:03 +10:00
|
|
|
const struct MLoop *mloop,
|
|
|
|
const struct MLoopTri *looptri,
|
2020-09-04 20:59:13 +02:00
|
|
|
const struct MVert *mvert,
|
2015-07-17 03:36:03 +10:00
|
|
|
const int *face_indices,
|
2020-09-04 20:59:13 +02:00
|
|
|
const int *sculpt_face_sets,
|
2022-01-07 11:38:08 +11:00
|
|
|
int face_indices_len,
|
2019-10-09 19:03:57 +02:00
|
|
|
const struct Mesh *mesh);
|
2012-02-22 22:48:34 +00:00
|
|
|
|
2021-12-09 20:01:47 +11:00
|
|
|
/**
|
|
|
|
* Threaded: do not call any functions that use OpenGL calls!
|
|
|
|
*/
|
2017-05-11 22:03:50 +10:00
|
|
|
GPU_PBVH_Buffers *GPU_pbvh_grid_buffers_build(int totgrid, unsigned int **grid_hidden);
|
2012-02-22 22:48:34 +00:00
|
|
|
|
2021-12-09 20:01:47 +11:00
|
|
|
/**
|
|
|
|
* Threaded: do not call any functions that use OpenGL calls!
|
|
|
|
*/
|
2017-05-11 22:03:50 +10:00
|
|
|
GPU_PBVH_Buffers *GPU_pbvh_bmesh_buffers_build(bool smooth_shading);
|
2012-12-30 18:24:54 +00:00
|
|
|
|
2021-12-09 20:01:47 +11:00
|
|
|
/**
|
|
|
|
* Free part of data for update. Not thread safe, must run in OpenGL main thread.
|
|
|
|
*/
|
2019-09-27 22:42:57 +02:00
|
|
|
void GPU_pbvh_bmesh_buffers_update_free(GPU_PBVH_Buffers *buffers);
|
|
|
|
void GPU_pbvh_grid_buffers_update_free(GPU_PBVH_Buffers *buffers,
|
|
|
|
const struct DMFlagMat *grid_flag_mats,
|
2020-07-13 11:27:09 +02:00
|
|
|
const int *grid_indices);
|
2014-05-05 21:13:27 +03:00
|
|
|
|
2021-12-09 20:01:47 +11:00
|
|
|
/**
|
|
|
|
* Update mesh buffers without topology changes. Threaded.
|
|
|
|
*/
|
2018-01-12 17:35:26 +01:00
|
|
|
enum {
|
2018-01-15 11:38:56 +01:00
|
|
|
GPU_PBVH_BUFFERS_SHOW_MASK = (1 << 1),
|
2020-03-05 14:53:23 +01:00
|
|
|
GPU_PBVH_BUFFERS_SHOW_VCOL = (1 << 2),
|
|
|
|
GPU_PBVH_BUFFERS_SHOW_SCULPT_FACE_SETS = (1 << 3),
|
2018-01-12 17:35:26 +01:00
|
|
|
};
|
|
|
|
|
2021-12-09 20:01:47 +11:00
|
|
|
/**
|
|
|
|
* Threaded: do not call any functions that use OpenGL calls!
|
|
|
|
*/
|
2017-05-11 22:03:50 +10:00
|
|
|
void GPU_pbvh_mesh_buffers_update(GPU_PBVH_Buffers *buffers,
|
2015-07-16 16:22:28 +02:00
|
|
|
const struct MVert *mvert,
|
Refactor: Move normals out of MVert, lazy calculation
As described in T91186, this commit moves mesh vertex normals into a
contiguous array of float vectors in a custom data layer, how face
normals are currently stored.
The main interface is documented in `BKE_mesh.h`. Vertex and face
normals are now calculated on-demand and cached, retrieved with an
"ensure" function. Since the logical state of a mesh is now "has
normals when necessary", they can be retrieved from a `const` mesh.
The goal is to use on-demand calculation for all derived data, but
leave room for eager calculation for performance purposes (modifier
evaluation is threaded, but viewport data generation is not).
**Benefits**
This moves us closer to a SoA approach rather than the current AoS
paradigm. Accessing a contiguous `float3` is much more efficient than
retrieving data from a larger struct. The memory requirements for
accessing only normals or vertex locations are smaller, and at the
cost of more memory usage for just normals, they now don't have to
be converted between float and short, which also simplifies code
In the future, the remaining items can be removed from `MVert`,
leaving only `float3`, which has similar benefits (see T93602).
Removing the combination of derived and original data makes it
conceptually simpler to only calculate normals when necessary.
This is especially important now that we have more opportunities
for temporary meshes in geometry nodes.
**Performance**
In addition to the theoretical future performance improvements by
making `MVert == float3`, I've done some basic performance testing
on this patch directly. The data is fairly rough, but it gives an idea
about where things stand generally.
- Mesh line primitive 4m Verts: 1.16x faster (36 -> 31 ms),
showing that accessing just `MVert` is now more efficient.
- Spring Splash Screen: 1.03-1.06 -> 1.06-1.11 FPS, a very slight
change that at least shows there is no regression.
- Sprite Fright Snail Smoosh: 3.30-3.40 -> 3.42-3.50 FPS, a small
but observable speedup.
- Set Position Node with Scaled Normal: 1.36x faster (53 -> 39 ms),
shows that using normals in geometry nodes is faster.
- Normal Calculation 1.6m Vert Cube: 1.19x faster (25 -> 21 ms),
shows that calculating normals is slightly faster now.
- File Size of 1.6m Vert Cube: 1.03x smaller (214.7 -> 208.4 MB),
Normals are not saved in files, which can help with large meshes.
As for memory usage, it may be slightly more in some cases, but
I didn't observe any difference in the production files I tested.
**Tests**
Some modifiers and cycles test results need to be updated with this
commit, for two reasons:
- The subdivision surface modifier is not responsible for calculating
normals anymore. In master, the modifier creates different normals
than the result of the `Mesh` normal calculation, so this is a bug
fix.
- There are small differences in the results of some modifiers that
use normals because they are not converted to and from `short`
anymore.
**Future improvements**
- Remove `ModifierTypeInfo::dependsOnNormals`. Code in each modifier
already retrieves normals if they are needed anyway.
- Copy normals as part of a better CoW system for attributes.
- Make more areas use lazy instead of eager normal calculation.
- Remove `BKE_mesh_normals_tag_dirty` in more places since that is
now the default state of a new mesh.
- Possibly apply a similar change to derived face corner normals.
Differential Revision: https://developer.blender.org/D12770
2022-01-13 14:37:58 -06:00
|
|
|
const float (*vert_normals)[3],
|
2015-07-11 03:25:28 +10:00
|
|
|
const float *vmask,
|
2022-04-05 11:42:55 -07:00
|
|
|
const void *vcol_data,
|
|
|
|
int vcol_type,
|
|
|
|
AttributeDomain vcol_domain,
|
2020-03-05 14:53:23 +01:00
|
|
|
const int *sculpt_face_sets,
|
2022-01-07 11:38:08 +11:00
|
|
|
int face_sets_color_seed,
|
|
|
|
int face_sets_color_default,
|
|
|
|
int update_flags);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-12-09 20:01:47 +11:00
|
|
|
/**
|
|
|
|
* Creates a vertex buffer (coordinate, normal, color) and,
|
|
|
|
* if smooth shading, an element index buffer.
|
|
|
|
* Threaded: do not call any functions that use OpenGL calls!
|
|
|
|
*/
|
2017-05-11 22:03:50 +10:00
|
|
|
void GPU_pbvh_bmesh_buffers_update(GPU_PBVH_Buffers *buffers,
|
|
|
|
struct BMesh *bm,
|
|
|
|
struct GSet *bm_faces,
|
|
|
|
struct GSet *bm_unique_verts,
|
|
|
|
struct GSet *bm_other_verts,
|
2022-01-07 11:38:08 +11:00
|
|
|
int update_flags);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-12-09 20:01:47 +11:00
|
|
|
/**
|
|
|
|
* Threaded: do not call any functions that use OpenGL calls!
|
|
|
|
*/
|
2017-05-11 22:03:50 +10:00
|
|
|
void GPU_pbvh_grid_buffers_update(GPU_PBVH_Buffers *buffers,
|
2020-04-01 01:03:20 +02:00
|
|
|
struct SubdivCCG *subdiv_ccg,
|
2017-05-11 22:03:50 +10:00
|
|
|
struct CCGElem **grids,
|
|
|
|
const struct DMFlagMat *grid_flag_mats,
|
|
|
|
int *grid_indices,
|
|
|
|
int totgrid,
|
2020-04-01 01:03:20 +02:00
|
|
|
const int *sculpt_face_sets,
|
2022-01-07 11:38:08 +11:00
|
|
|
int face_sets_color_seed,
|
|
|
|
int face_sets_color_default,
|
2017-05-11 22:03:50 +10:00
|
|
|
const struct CCGKey *key,
|
2022-01-07 11:38:08 +11:00
|
|
|
int update_flags);
|
2012-02-22 22:48:34 +00:00
|
|
|
|
2021-12-09 20:01:47 +11:00
|
|
|
/**
|
|
|
|
* Finish update. Not thread safe, must run in OpenGL main thread.
|
|
|
|
*/
|
2019-09-27 22:42:57 +02:00
|
|
|
void GPU_pbvh_buffers_update_flush(GPU_PBVH_Buffers *buffers);
|
|
|
|
|
2021-12-09 20:01:47 +11:00
|
|
|
/**
|
|
|
|
* Free buffers. Not thread safe, must run in OpenGL main thread.
|
|
|
|
*/
|
2019-09-27 22:42:57 +02:00
|
|
|
void GPU_pbvh_buffers_free(GPU_PBVH_Buffers *buffers);
|
|
|
|
|
2021-12-09 20:01:47 +11:00
|
|
|
/** Draw. */
|
2019-02-14 20:24:13 +01:00
|
|
|
struct GPUBatch *GPU_pbvh_buffers_batch_get(GPU_PBVH_Buffers *buffers, bool fast, bool wires);
|
2012-02-22 22:48:34 +00:00
|
|
|
|
2019-05-04 00:46:26 +02:00
|
|
|
short GPU_pbvh_buffers_material_index_get(GPU_PBVH_Buffers *buffers);
|
|
|
|
|
2020-03-21 18:09:43 +01:00
|
|
|
bool GPU_pbvh_buffers_has_overlays(GPU_PBVH_Buffers *buffers);
|
2018-08-24 16:46:42 +02:00
|
|
|
|
2020-03-02 15:28:47 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|