This repository has been archived on 2023-10-09. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
blender-archive/source/blender/gpu/intern/gpu_shader_builder_stubs.cc
Hans Goudey 1af62cb3bf Mesh: Move positions to a generic attribute
**Changes**
As described in T93602, this patch removes all use of the `MVert`
struct, replacing it with a generic named attribute with the name
`"position"`, consistent with other geometry types.

Variable names have been changed from `verts` to `positions`, to align
with the attribute name and the more generic design (positions are not
vertices, they are just an attribute stored on the point domain).

This change is made possible by previous commits that moved all other
data out of `MVert` to runtime data or other generic attributes. What
remains is mostly a simple type change. Though, the type still shows up
859 times, so the patch is quite large.

One compromise is that now `CD_MASK_BAREMESH` now contains
`CD_PROP_FLOAT3`. With the general move towards generic attributes
over custom data types, we are removing use of these type masks anyway.

**Benefits**
The most obvious benefit is reduced memory usage and the benefits
that brings in memory-bound situations. `float3` is only 3 bytes, in
comparison to `MVert` which was 4. When there are millions of vertices
this starts to matter more.

The other benefits come from using a more generic type. Instead of
writing algorithms specifically for `MVert`, code can just use arrays
of vectors. This will allow eliminating many temporary arrays or
wrappers used to extract positions.

Many possible improvements aren't implemented in this patch, though
I did switch simplify or remove the process of creating temporary
position arrays in a few places.

The design clarity that "positions are just another attribute" brings
allows removing explicit copying of vertices in some procedural
operations-- they are just processed like most other attributes.

**Performance**
This touches so many areas that it's hard to benchmark exhaustively,
but I observed some areas as examples.
* The mesh line node with 4 million count was 1.5x (8ms to 12ms) faster.
* The Spring splash screen went from ~4.3 to ~4.5 fps.
* The subdivision surface modifier/node was slightly faster
RNA access through Python may be slightly slower, since now we need
a name lookup instead of just a custom data type lookup for each index.

**Future Improvements**
* Remove uses of "vert_coords" functions:
  * `BKE_mesh_vert_coords_alloc`
  * `BKE_mesh_vert_coords_get`
  * `BKE_mesh_vert_coords_apply{_with_mat4}`
* Remove more hidden copying of positions
* General simplification now possible in many areas
* Convert more code to C++ to use `float3` instead of `float[3]`
  * Currently `reinterpret_cast` is used for those C-API functions

Differential Revision: https://developer.blender.org/D15982
2023-01-10 00:10:43 -05:00

301 lines
7.2 KiB
C++

/* SPDX-License-Identifier: GPL-2.0-or-later
* Copyright 2021 Blender Foundation. All rights reserved. */
/** \file
* \ingroup gpu
*
* Stubs to reduce linking time for shader_builder.
*/
#include "BLI_utildefines.h"
#include "IMB_imbuf.h"
#include "IMB_imbuf_types.h"
#include "BKE_attribute.h"
#include "BKE_customdata.h"
#include "BKE_global.h"
#include "BKE_material.h"
#include "BKE_mesh.h"
#include "BKE_node.h"
#include "BKE_paint.h"
#include "BKE_pbvh.h"
#include "BKE_subdiv_ccg.h"
#include "DNA_userdef_types.h"
#include "NOD_shader.h"
#include "DRW_engine.h"
#include "bmesh.h"
#include "UI_resources.h"
extern "C" {
Global G;
UserDef U;
/* -------------------------------------------------------------------- */
/** \name Stubs of BLI_imbuf_types.h
* \{ */
void IMB_freeImBuf(ImBuf * /*ibuf*/)
{
BLI_assert_unreachable();
}
struct ImBuf *IMB_allocImBuf(unsigned int /*x*/,
unsigned int /*y*/,
unsigned char /*planes*/,
unsigned int /*flags*/)
{
BLI_assert_unreachable();
return nullptr;
}
/** \} */
/* -------------------------------------------------------------------- */
/** \name Stubs of UI_resources.h
* \{ */
void UI_GetThemeColor4fv(int /*colorid*/, float[4] /*col*/)
{
BLI_assert_unreachable();
}
void UI_GetThemeColor3fv(int /*colorid*/, float[3] /*col*/)
{
BLI_assert_unreachable();
}
void UI_GetThemeColorShade4fv(int /*colorid*/, int /*offset*/, float[4] /*col*/)
{
BLI_assert_unreachable();
}
void UI_GetThemeColorShadeAlpha4fv(int /*colorid*/,
int /*coloffset*/,
int /*alphaoffset*/,
float[4] /*col*/)
{
BLI_assert_unreachable();
}
void UI_GetThemeColorBlendShade4fv(
int /*colorid1*/, int /*colorid2*/, float /*fac*/, int /*offset*/, float[4] /*col*/)
{
BLI_assert_unreachable();
}
void UI_GetThemeColorBlend3ubv(int /*colorid1*/, int /*colorid2*/, float /*fac*/, uchar[3] /*col*/)
{
BLI_assert_unreachable();
}
void UI_GetThemeColorShadeAlpha4ubv(int /*colorid*/,
int /*coloffset*/,
int /*alphaoffset*/,
uchar[4] /*col*/)
{
BLI_assert_unreachable();
}
/** \} */
/* -------------------------------------------------------------------- */
/** \name Stubs of BKE_attribute.h
* \{ */
eAttrDomain BKE_id_attribute_domain(const struct ID * /*id*/,
const struct CustomDataLayer * /*layer*/)
{
return ATTR_DOMAIN_AUTO;
}
/** \} */
/* -------------------------------------------------------------------- */
/** \name Stubs of BKE_paint.h
* \{ */
bool paint_is_face_hidden(const struct MLoopTri * /*lt*/, const bool * /*hide_poly*/)
{
BLI_assert_unreachable();
return false;
}
void BKE_paint_face_set_overlay_color_get(const int /*face_set*/,
const int /*seed*/,
uchar[4] /*col*/)
{
BLI_assert_unreachable();
}
bool paint_is_grid_face_hidden(const uint * /*grid_hidden*/,
int /*gridsize*/,
int /*x*/,
int /*y*/)
{
BLI_assert_unreachable();
return false;
}
/** \} */
/* -------------------------------------------------------------------- */
/** \name Stubs of BKE_mesh.h
* \{ */
void BKE_mesh_calc_poly_normal(const struct MPoly * /*mpoly*/,
const struct MLoop * /*loopstart*/,
const float (*vert_positions)[3],
float[3] /*col*/)
{
UNUSED_VARS(vert_positions);
BLI_assert_unreachable();
}
void BKE_mesh_looptri_get_real_edges(const struct MEdge * /*edges*/,
const struct MLoop * /*loops*/,
const struct MLoopTri * /*looptri*/,
int[3] /*col*/)
{
BLI_assert_unreachable();
}
/** \} */
/* -------------------------------------------------------------------- */
/** \name Stubs of BKE_material.h
* \{ */
void BKE_material_defaults_free_gpu()
{
/* This function is reachable via GPU_exit. */
}
/** \} */
/* -------------------------------------------------------------------- */
/** \name Stubs of BKE_customdata.h
* \{ */
int CustomData_get_offset(const struct CustomData * /*data*/, int /*type*/)
{
BLI_assert_unreachable();
return 0;
}
int CustomData_get_named_layer_index(const struct CustomData * /*data*/,
int /*type*/,
const char * /*name*/)
{
return -1;
}
int CustomData_get_active_layer_index(const struct CustomData * /*data*/, int /*type*/)
{
return -1;
}
int CustomData_get_render_layer_index(const struct CustomData * /*data*/, int /*type*/)
{
return -1;
}
bool CustomData_has_layer(const struct CustomData * /*data*/, int /*type*/)
{
return false;
}
void *CustomData_get_layer_named(const struct CustomData * /*data*/,
int /*type*/,
const char * /*name*/)
{
return nullptr;
}
void *CustomData_get_layer(const struct CustomData * /*data*/, int /*type*/)
{
return nullptr;
}
/** \} */
/* -------------------------------------------------------------------- */
/** \name Stubs of BKE_pbvh.h
* \{ */
int BKE_pbvh_count_grid_quads(BLI_bitmap ** /*grid_hidden*/,
const int * /*grid_indices*/,
int /*totgrid*/,
int /*gridsize*/,
int /*display_gridsize*/)
{
BLI_assert_unreachable();
return 0;
}
/** \} */
/* -------------------------------------------------------------------- */
/** \name Stubs of BKE_subdiv_ccg.h
* \{ */
int BKE_subdiv_ccg_grid_to_face_index(const SubdivCCG * /*subdiv_ccg*/, const int /*grid_index*/)
{
BLI_assert_unreachable();
return 0;
}
/** \} */
/* -------------------------------------------------------------------- */
/** \name Stubs of BKE_node.h
* \{ */
void ntreeGPUMaterialNodes(struct bNodeTree * /*localtree*/, struct GPUMaterial * /*mat*/)
{
BLI_assert_unreachable();
}
struct bNodeTree *ntreeLocalize(struct bNodeTree * /*ntree*/)
{
BLI_assert_unreachable();
return nullptr;
}
void ntreeFreeLocalTree(struct bNodeTree * /*ntree*/)
{
BLI_assert_unreachable();
}
/** \} */
/* -------------------------------------------------------------------- */
/** \name Stubs of bmesh.h
* \{ */
void BM_face_as_array_vert_tri(BMFace * /*f*/, BMVert *[3] /*r_verts*/)
{
BLI_assert_unreachable();
}
/** \} */
/* -------------------------------------------------------------------- */
/** \name Stubs of DRW_engine.h
* \{ */
void DRW_deferred_shader_remove(struct GPUMaterial * /*mat*/)
{
BLI_assert_unreachable();
}
void DRW_cdlayer_attr_aliases_add(struct GPUVertFormat * /*format*/,
const char * /*base_name*/,
const struct CustomData * /*data*/,
const struct CustomDataLayer * /*cl*/,
bool /*is_active_render*/,
bool /*is_active_layer*/)
{
}
/** \} */
}