From 5650142df071f0700c6bce638f87cf711c006319 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Mon, 13 Feb 2023 13:54:01 -0500 Subject: [PATCH] Cleanup: Move draw_attributes.hh to C++ In order to experiment with different storage types for `DRW_Attributes` and for general cleanup (see #103343). Also move a curves header to C++. --- source/blender/draw/CMakeLists.txt | 4 +- source/blender/draw/intern/draw_attributes.cc | 2 +- .../{draw_attributes.h => draw_attributes.hh} | 26 +++------- .../blender/draw/intern/draw_cache_extract.hh | 2 +- .../draw/intern/draw_cache_impl_curves.cc | 4 +- .../draw/intern/draw_cache_impl_pointcloud.cc | 2 +- source/blender/draw/intern/draw_curves.cc | 2 +- ...urves_private.h => draw_curves_private.hh} | 29 ++++------- .../blender/draw/intern/draw_manager_data.cc | 2 +- source/blender/draw/intern/draw_pointcloud.cc | 2 +- source/blender/draw/intern/draw_shader.h | 52 ++++++++++--------- .../extract_mesh_vbo_attributes.cc | 2 +- 12 files changed, 56 insertions(+), 73 deletions(-) rename source/blender/draw/intern/{draw_attributes.h => draw_attributes.hh} (86%) rename source/blender/draw/intern/{draw_curves_private.h => draw_curves_private.hh} (84%) diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt index ce3d09e46d9..063050660c6 100644 --- a/source/blender/draw/CMakeLists.txt +++ b/source/blender/draw/CMakeLists.txt @@ -225,7 +225,7 @@ set(SRC DRW_select_buffer.h intern/DRW_gpu_wrapper.hh intern/DRW_render.h - intern/draw_attributes.h + intern/draw_attributes.hh intern/draw_cache.h intern/draw_cache_extract.hh intern/draw_cache_impl.h @@ -234,7 +234,7 @@ set(SRC intern/draw_command.hh intern/draw_common.h intern/draw_common_shader_shared.h - intern/draw_curves_private.h + intern/draw_curves_private.hh intern/draw_debug.h intern/draw_debug.hh intern/draw_hair_private.h diff --git a/source/blender/draw/intern/draw_attributes.cc b/source/blender/draw/intern/draw_attributes.cc index cc7c9959850..553832b0bf6 100644 --- a/source/blender/draw/intern/draw_attributes.cc +++ b/source/blender/draw/intern/draw_attributes.cc @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0-or-later * Copyright 2022 Blender Foundation. All rights reserved. */ -#include "draw_attributes.h" +#include "draw_attributes.hh" /* Return true if the given DRW_AttributeRequest is already in the requests. */ static bool drw_attributes_has_request(const DRW_Attributes *requests, DRW_AttributeRequest req) diff --git a/source/blender/draw/intern/draw_attributes.h b/source/blender/draw/intern/draw_attributes.hh similarity index 86% rename from source/blender/draw/intern/draw_attributes.h rename to source/blender/draw/intern/draw_attributes.hh index 66320f1b500..1449f7b3b8a 100644 --- a/source/blender/draw/intern/draw_attributes.h +++ b/source/blender/draw/intern/draw_attributes.hh @@ -9,9 +9,7 @@ #pragma once -#ifdef __cplusplus -# include -#endif +#include #include "DNA_customdata_types.h" @@ -24,23 +22,19 @@ #include "GPU_shader.h" #include "GPU_vertex_format.h" -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct DRW_AttributeRequest { +struct DRW_AttributeRequest { eCustomDataType cd_type; int layer_index; eAttrDomain domain; char attribute_name[64]; -} DRW_AttributeRequest; +}; -typedef struct DRW_Attributes { +struct DRW_Attributes { DRW_AttributeRequest requests[GPU_MAX_ATTR]; int num_requests; -} DRW_Attributes; +}; -typedef struct DRW_MeshCDMask { +struct DRW_MeshCDMask { uint32_t uv : 8; uint32_t tan : 8; uint32_t orco : 1; @@ -50,7 +44,7 @@ typedef struct DRW_MeshCDMask { * Edit uv layer is from the base edit mesh as modifiers could remove it. (see #68857) */ uint32_t edit_uv : 1; -} DRW_MeshCDMask; +}; /* Keep `DRW_MeshCDMask` struct within a `uint32_t`. * bit-wise and atomic operations are used to compare and update the struct. @@ -59,11 +53,9 @@ BLI_STATIC_ASSERT(sizeof(DRW_MeshCDMask) <= sizeof(uint32_t), "DRW_MeshCDMask ex void drw_attributes_clear(DRW_Attributes *attributes); -#ifdef __cplusplus void drw_attributes_merge(DRW_Attributes *dst, const DRW_Attributes *src, std::mutex &render_mutex); -#endif /* Return true if all requests in b are in a. */ bool drw_attributes_overlap(const DRW_Attributes *a, const DRW_Attributes *b); @@ -78,7 +70,3 @@ bool drw_custom_data_match_attribute(const CustomData *custom_data, const char *name, int *r_layer_index, eCustomDataType *r_type); - -#ifdef __cplusplus -} -#endif diff --git a/source/blender/draw/intern/draw_cache_extract.hh b/source/blender/draw/intern/draw_cache_extract.hh index 4fe360eecd7..bc64be7656c 100644 --- a/source/blender/draw/intern/draw_cache_extract.hh +++ b/source/blender/draw/intern/draw_cache_extract.hh @@ -22,7 +22,7 @@ #include "GPU_index_buffer.h" #include "GPU_vertex_buffer.h" -#include "draw_attributes.h" +#include "draw_attributes.hh" struct DRWSubdivCache; struct MeshRenderData; diff --git a/source/blender/draw/intern/draw_cache_impl_curves.cc b/source/blender/draw/intern/draw_cache_impl_curves.cc index 22e1eb3ece5..beea2f20eb9 100644 --- a/source/blender/draw/intern/draw_cache_impl_curves.cc +++ b/source/blender/draw/intern/draw_cache_impl_curves.cc @@ -34,10 +34,10 @@ #include "DRW_render.h" -#include "draw_attributes.h" +#include "draw_attributes.hh" #include "draw_cache_impl.h" /* own include */ #include "draw_cache_inline.h" -#include "draw_curves_private.h" /* own include */ +#include "draw_curves_private.hh" /* own include */ #include "draw_shader.h" using blender::ColorGeometry4f; diff --git a/source/blender/draw/intern/draw_cache_impl_pointcloud.cc b/source/blender/draw/intern/draw_cache_impl_pointcloud.cc index 4997aef6089..3b9202bcb04 100644 --- a/source/blender/draw/intern/draw_cache_impl_pointcloud.cc +++ b/source/blender/draw/intern/draw_cache_impl_pointcloud.cc @@ -25,7 +25,7 @@ #include "GPU_batch.h" #include "GPU_material.h" -#include "draw_attributes.h" +#include "draw_attributes.hh" #include "draw_cache_impl.h" #include "draw_cache_inline.h" #include "draw_pointcloud_private.hh" /* own include */ diff --git a/source/blender/draw/intern/draw_curves.cc b/source/blender/draw/intern/draw_curves.cc index 2be32cc704c..48e9cca98e0 100644 --- a/source/blender/draw/intern/draw_curves.cc +++ b/source/blender/draw/intern/draw_curves.cc @@ -26,7 +26,7 @@ #include "DRW_render.h" #include "draw_cache_impl.h" -#include "draw_curves_private.h" +#include "draw_curves_private.hh" #include "draw_hair_private.h" #include "draw_manager.h" #include "draw_shader.h" diff --git a/source/blender/draw/intern/draw_curves_private.h b/source/blender/draw/intern/draw_curves_private.hh similarity index 84% rename from source/blender/draw/intern/draw_curves_private.h rename to source/blender/draw/intern/draw_curves_private.hh index 9d02eedbbc3..be24872b1be 100644 --- a/source/blender/draw/intern/draw_curves_private.h +++ b/source/blender/draw/intern/draw_curves_private.hh @@ -10,26 +10,23 @@ #include "BKE_attribute.h" #include "GPU_shader.h" -#include "draw_attributes.h" - -#ifdef __cplusplus -extern "C" { -#endif +#include "draw_attributes.hh" struct Curves; struct GPUVertBuf; struct GPUBatch; +struct GPUMaterial; #define MAX_THICKRES 2 /* see eHairType */ #define MAX_HAIR_SUBDIV 4 /* see hair_subdiv rna */ -typedef enum CurvesEvalShader { +enum CurvesEvalShader { CURVES_EVAL_CATMULL_ROM = 0, CURVES_EVAL_BEZIER = 1, -} CurvesEvalShader; +}; #define CURVES_EVAL_SHADER_NUM 3 -typedef struct CurvesEvalFinalCache { +struct CurvesEvalFinalCache { /* Output of the subdivision stage: vertex buffer sized to subdiv level. */ GPUVertBuf *proc_buf; @@ -58,10 +55,10 @@ typedef struct CurvesEvalFinalCache { /* Output of the subdivision stage: vertex buffers sized to subdiv level. This is only attributes * on point domain. */ GPUVertBuf *attributes_buf[GPU_MAX_ATTR]; -} CurvesEvalFinalCache; +}; /* Curves procedural display: Evaluation is done on the GPU. */ -typedef struct CurvesEvalCache { +struct CurvesEvalCache { /* Control point positions on evaluated data-block combined with parameter data. */ GPUVertBuf *proc_point_buf; @@ -82,19 +79,15 @@ typedef struct CurvesEvalCache { int strands_len; int elems_len; int point_len; -} CurvesEvalCache; +}; /** * Ensure all necessary textures and buffers exist for GPU accelerated drawing. */ -bool curves_ensure_procedural_data(struct Curves *curves, - struct CurvesEvalCache **r_hair_cache, - struct GPUMaterial *gpu_material, +bool curves_ensure_procedural_data(Curves *curves, + CurvesEvalCache **r_hair_cache, + GPUMaterial *gpu_material, int subdiv, int thickness_res); void drw_curves_get_attribute_sampler_name(const char *layer_name, char r_sampler_name[32]); - -#ifdef __cplusplus -} -#endif diff --git a/source/blender/draw/intern/draw_manager_data.cc b/source/blender/draw/intern/draw_manager_data.cc index 546ccbf7ef8..5887f3c79b7 100644 --- a/source/blender/draw/intern/draw_manager_data.cc +++ b/source/blender/draw/intern/draw_manager_data.cc @@ -7,7 +7,7 @@ #include "DRW_pbvh.hh" -#include "draw_attributes.h" +#include "draw_attributes.hh" #include "draw_manager.h" #include "draw_pbvh.h" diff --git a/source/blender/draw/intern/draw_pointcloud.cc b/source/blender/draw/intern/draw_pointcloud.cc index 4f228addffb..0522c850068 100644 --- a/source/blender/draw/intern/draw_pointcloud.cc +++ b/source/blender/draw/intern/draw_pointcloud.cc @@ -21,7 +21,7 @@ #include "DRW_gpu_wrapper.hh" #include "DRW_render.h" -#include "draw_attributes.h" +#include "draw_attributes.hh" #include "draw_cache_impl.h" #include "draw_common.h" #include "draw_manager.h" diff --git a/source/blender/draw/intern/draw_shader.h b/source/blender/draw/intern/draw_shader.h index e4c71812471..d519775ceef 100644 --- a/source/blender/draw/intern/draw_shader.h +++ b/source/blender/draw/intern/draw_shader.h @@ -7,36 +7,38 @@ #pragma once -#include "draw_curves_private.h" -#include "draw_hair_private.h" +#ifdef __cplusplus +# include "draw_curves_private.hh" +# include "draw_hair_private.h" + +struct GPUShader; + +enum eParticleRefineShaderType { + PART_REFINE_SHADER_TRANSFORM_FEEDBACK, + PART_REFINE_SHADER_TRANSFORM_FEEDBACK_WORKAROUND, + PART_REFINE_SHADER_COMPUTE, +}; + +/* draw_shader.cc */ + +GPUShader *DRW_shader_hair_refine_get(ParticleRefineShader refinement, + eParticleRefineShaderType sh_type); + +GPUShader *DRW_shader_curves_refine_get(CurvesEvalShader type, eParticleRefineShaderType sh_type); + +GPUShader *DRW_shader_debug_print_display_get(); +GPUShader *DRW_shader_debug_draw_display_get(); +GPUShader *DRW_shader_draw_visibility_compute_get(); +GPUShader *DRW_shader_draw_view_finalize_get(); +GPUShader *DRW_shader_draw_resource_finalize_get(); +GPUShader *DRW_shader_draw_command_generate_get(); + +#endif #ifdef __cplusplus extern "C" { #endif -struct GPUShader; - -typedef enum eParticleRefineShaderType { - PART_REFINE_SHADER_TRANSFORM_FEEDBACK, - PART_REFINE_SHADER_TRANSFORM_FEEDBACK_WORKAROUND, - PART_REFINE_SHADER_COMPUTE, -} eParticleRefineShaderType; - -/* draw_shader.cc */ - -struct GPUShader *DRW_shader_hair_refine_get(ParticleRefineShader refinement, - eParticleRefineShaderType sh_type); - -struct GPUShader *DRW_shader_curves_refine_get(CurvesEvalShader type, - eParticleRefineShaderType sh_type); - -struct GPUShader *DRW_shader_debug_print_display_get(void); -struct GPUShader *DRW_shader_debug_draw_display_get(void); -struct GPUShader *DRW_shader_draw_visibility_compute_get(void); -struct GPUShader *DRW_shader_draw_view_finalize_get(void); -struct GPUShader *DRW_shader_draw_resource_finalize_get(void); -struct GPUShader *DRW_shader_draw_command_generate_get(void); - void DRW_shaders_free(void); #ifdef __cplusplus diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_attributes.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_attributes.cc index 21201593d0c..df52444a25b 100644 --- a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_attributes.cc +++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_attributes.cc @@ -17,7 +17,7 @@ #include "BKE_attribute.hh" #include "BKE_mesh.h" -#include "draw_attributes.h" +#include "draw_attributes.hh" #include "draw_subdivision.h" #include "extract_mesh.hh" -- 2.30.2