diff options
Diffstat (limited to 'source/blender/draw/intern')
14 files changed, 66 insertions, 57 deletions
diff --git a/source/blender/draw/intern/DRW_gpu_wrapper.hh b/source/blender/draw/intern/DRW_gpu_wrapper.hh index af262272577..2809661c8c8 100644 --- a/source/blender/draw/intern/DRW_gpu_wrapper.hh +++ b/source/blender/draw/intern/DRW_gpu_wrapper.hh @@ -286,13 +286,13 @@ template< /** The number of values that can be stored in this uniform buffer. */ int64_t len /** True if the buffer only resides on GPU memory and cannot be accessed. */ - /* TODO(fclem): Currently unsupported. */ + /* TODO(@fclem): Currently unsupported. */ /* bool device_only = false */> class UniformArrayBuffer : public detail::UniformCommon<T, len, false> { public: UniformArrayBuffer() { - /* TODO(fclem) We should map memory instead. */ + /* TODO(@fclem): We should map memory instead. */ this->data_ = (T *)MEM_mallocN_aligned(len * sizeof(T), 16, this->name_); } }; @@ -301,13 +301,13 @@ template< /** Type of the values stored in this uniform buffer. */ typename T /** True if the buffer only resides on GPU memory and cannot be accessed. */ - /* TODO(fclem): Currently unsupported. */ + /* TODO(@fclem): Currently unsupported. */ /* bool device_only = false */> class UniformBuffer : public T, public detail::UniformCommon<T, 1, false> { public: UniformBuffer() { - /* TODO(fclem) How could we map this? */ + /* TODO(@fclem): How could we map this? */ this->data_ = static_cast<T *>(this); } @@ -641,7 +641,7 @@ class Texture : NonCopyable { bool cubemap = false) { - /* TODO(fclem) In the future, we need to check if mip_count did not change. + /* TODO(@fclem): In the future, we need to check if mip_count did not change. * For now it's ok as we always define all MIP level. */ if (tx_) { int3 size = this->size(); @@ -653,7 +653,7 @@ class Texture : NonCopyable { if (tx_ == nullptr) { tx_ = create(w, h, d, mips, format, data, layered, cubemap); if (mips > 1) { - /* TODO(fclem) Remove once we have immutable storage or when mips are + /* TODO(@fclem): Remove once we have immutable storage or when mips are * generated on creation. */ GPU_texture_generate_mipmap(tx_); } diff --git a/source/blender/draw/intern/draw_cache_impl_hair.cc b/source/blender/draw/intern/draw_cache_impl_hair.cc index d236f0c2f59..cdc06b121b0 100644 --- a/source/blender/draw/intern/draw_cache_impl_hair.cc +++ b/source/blender/draw/intern/draw_cache_impl_hair.cc @@ -29,7 +29,10 @@ #include "BLI_listbase.h" #include "BLI_math_base.h" +#include "BLI_math_vec_types.hh" #include "BLI_math_vector.h" +#include "BLI_math_vector.hh" +#include "BLI_span.hh" #include "BLI_utildefines.h" #include "DNA_hair_types.h" @@ -44,6 +47,10 @@ #include "draw_cache_impl.h" /* own include */ #include "draw_hair_private.h" /* own include */ +using blender::float3; +using blender::IndexRange; +using blender::Span; + static void hair_batch_cache_clear(Hair *hair); /* ---------------------------------------------------------------------- */ @@ -131,17 +138,9 @@ static void ensure_seg_pt_count(Hair *hair, ParticleHairCache *hair_cache) return; } - hair_cache->strands_len = 0; - hair_cache->elems_len = 0; - hair_cache->point_len = 0; - - HairCurve *curve = hair->curves; - int num_curves = hair->totcurve; - for (int i = 0; i < num_curves; i++, curve++) { - hair_cache->strands_len++; - hair_cache->elems_len += curve->numpoints + 1; - hair_cache->point_len += curve->numpoints; - } + hair_cache->strands_len = hair->geometry.curve_size; + hair_cache->elems_len = hair->geometry.point_size + hair->geometry.curve_size; + hair_cache->point_len = hair->geometry.point_size; } static void hair_batch_cache_fill_segments_proc_pos(Hair *hair, @@ -149,30 +148,36 @@ static void hair_batch_cache_fill_segments_proc_pos(Hair *hair, GPUVertBufRaw *length_step) { /* TODO: use hair radius layer if available. */ - HairCurve *curve = hair->curves; - int num_curves = hair->totcurve; - for (int i = 0; i < num_curves; i++, curve++) { - float(*curve_co)[3] = hair->co + curve->firstpoint; + const int curve_size = hair->geometry.curve_size; + Span<int> offsets{hair->geometry.offsets, hair->geometry.curve_size + 1}; + + Span<float3> positions{(float3 *)hair->geometry.position, hair->geometry.point_size}; + + for (const int i : IndexRange(curve_size)) { + const IndexRange curve_range(offsets[i], offsets[i + 1] - offsets[i]); + + Span<float3> spline_positions = positions.slice(curve_range); float total_len = 0.0f; - float *co_prev = nullptr, *seg_data_first; - for (int j = 0; j < curve->numpoints; j++) { + float *seg_data_first; + for (const int i_spline : spline_positions.index_range()) { float *seg_data = (float *)GPU_vertbuf_raw_step(attr_step); - copy_v3_v3(seg_data, curve_co[j]); - if (co_prev) { - total_len += len_v3v3(co_prev, curve_co[j]); + copy_v3_v3(seg_data, spline_positions[i_spline]); + if (i_spline == 0) { + seg_data_first = seg_data; } else { - seg_data_first = seg_data; + total_len += blender::math::distance(spline_positions[i_spline - 1], + spline_positions[i_spline]); } seg_data[3] = total_len; - co_prev = curve_co[j]; } /* Assign length value. */ *(float *)GPU_vertbuf_raw_step(length_step) = total_len; if (total_len > 0.0f) { /* Divide by total length to have a [0-1] number. */ - for (int j = 0; j < curve->numpoints; j++, seg_data_first += 4) { + for ([[maybe_unused]] const int i_spline : spline_positions.index_range()) { seg_data_first[3] /= total_len; + seg_data_first += 4; } } } @@ -226,11 +231,14 @@ static void hair_batch_cache_fill_strands_data(Hair *hair, GPUVertBufRaw *data_step, GPUVertBufRaw *seg_step) { - HairCurve *curve = hair->curves; - int num_curves = hair->totcurve; - for (int i = 0; i < num_curves; i++, curve++) { - *(uint *)GPU_vertbuf_raw_step(data_step) = curve->firstpoint; - *(ushort *)GPU_vertbuf_raw_step(seg_step) = curve->numpoints - 1; + const int curve_size = hair->geometry.curve_size; + Span<int> offsets{hair->geometry.offsets, hair->geometry.curve_size + 1}; + + for (const int i : IndexRange(curve_size)) { + const IndexRange curve_range(offsets[i], offsets[i + 1] - offsets[i]); + + *(uint *)GPU_vertbuf_raw_step(data_step) = curve_range.start(); + *(ushort *)GPU_vertbuf_raw_step(seg_step) = curve_range.size() - 1; } } @@ -289,10 +297,11 @@ static void hair_batch_cache_fill_segments_indices(Hair *hair, const int res, GPUIndexBufBuilder *elb) { - HairCurve *curve = hair->curves; - int num_curves = hair->totcurve; + const int curve_size = hair->geometry.curve_size; + uint curr_point = 0; - for (int i = 0; i < num_curves; i++, curve++) { + + for ([[maybe_unused]] const int i : IndexRange(curve_size)) { for (int k = 0; k < res; k++) { GPU_indexbuf_add_generic_vert(elb, curr_point++); } diff --git a/source/blender/draw/intern/draw_cache_impl_subdivision.cc b/source/blender/draw/intern/draw_cache_impl_subdivision.cc index a24a3a5a3a7..4a8670a9ee2 100644 --- a/source/blender/draw/intern/draw_cache_impl_subdivision.cc +++ b/source/blender/draw/intern/draw_cache_impl_subdivision.cc @@ -999,7 +999,7 @@ static bool draw_subdiv_build_cache(DRWSubdivCache *cache, cache->face_ptex_offset = BKE_subdiv_face_ptex_offset_get(subdiv); - // Build patch coordinates for all the face dots + /* Build patch coordinates for all the face dots. */ cache->fdots_patch_coords = gpu_vertbuf_create_from_format(get_blender_patch_coords_format(), mesh_eval->totpoly); CompressedPatchCoord *blender_fdots_patch_coords = (CompressedPatchCoord *)GPU_vertbuf_get_data( @@ -1760,7 +1760,7 @@ static void draw_subdiv_cache_ensure_mat_offsets(DRWSubdivCache *cache, int *mat_start = static_cast<int *>(MEM_callocN(sizeof(int) * mat_len, "subdiv mat_start")); int *subdiv_polygon_offset = cache->subdiv_polygon_offset; - // TODO: parallel_reduce? + /* TODO: parallel_reduce? */ for (int i = 0; i < mesh_eval->totpoly; i++) { const MPoly *mpoly = &mesh_eval->mpoly[i]; const int next_offset = (i == mesh_eval->totpoly - 1) ? number_of_quads : diff --git a/source/blender/draw/intern/draw_manager.h b/source/blender/draw/intern/draw_manager.h index d27eb8be9e0..38cd3ecb9b6 100644 --- a/source/blender/draw/intern/draw_manager.h +++ b/source/blender/draw/intern/draw_manager.h @@ -300,7 +300,7 @@ struct DRWCallBuffer { }; /** Used by #DRWUniform.type */ -/* TODO(jbakker): rename to DRW_RESOURCE/DRWResourceType. */ +/* TODO(@jbakker): rename to DRW_RESOURCE/DRWResourceType. */ typedef enum { DRW_UNIFORM_INT = 0, DRW_UNIFORM_INT_COPY, @@ -529,7 +529,7 @@ typedef struct DRWData { struct GHash *obattrs_ubo_pool; uint ubo_len; /** Texture pool to reuse temp texture across engines. */ - /* TODO(fclem) the pool could be shared even between viewports. */ + /* TODO(@fclem): The pool could be shared even between view-ports. */ struct DRWTexturePool *texture_pool; /** Per stereo view data. Contains engine data and default framebuffers. */ struct DRWViewData *view_data[2]; @@ -549,7 +549,7 @@ typedef struct DupliKey { typedef struct DRWManager { /* TODO: clean up this struct a bit. */ /* Cache generation */ - /* TODO(fclem) Rename to data. */ + /* TODO(@fclem): Rename to data. */ DRWData *vmempool; /** Active view data structure for one of the 2 stereo view. Not related to DRWView. */ struct DRWViewData *view_data_active; @@ -572,7 +572,7 @@ typedef struct DRWManager { struct ID *dupli_origin_data; /** Hash-map: #DupliKey -> void pointer for each enabled engine. */ struct GHash *dupli_ghash; - /** TODO(fclem): try to remove usage of this. */ + /** TODO(@fclem): try to remove usage of this. */ DRWInstanceData *object_instance_data[MAX_INSTANCE_DATA_SIZE]; /* Dupli data for the current dupli for each enabled engine. */ void **dupli_datas; @@ -615,7 +615,7 @@ typedef struct DRWManager { DRWView *view_active; DRWView *view_previous; uint primary_view_ct; - /** TODO(fclem): Remove this. Only here to support + /** TODO(@fclem): Remove this. Only here to support * shaders without common_view_lib.glsl */ DRWViewUboStorage view_storage_cpy; @@ -640,7 +640,7 @@ typedef struct DRWManager { GPUDrawList *draw_list; struct { - /* TODO(fclem): optimize: use chunks. */ + /* TODO(@fclem): optimize: use chunks. */ DRWDebugLine *lines; DRWDebugSphere *spheres; } debug; diff --git a/source/blender/draw/intern/draw_manager_data.c b/source/blender/draw/intern/draw_manager_data.c index a4d5d6f3c31..f07fc94f5d1 100644 --- a/source/blender/draw/intern/draw_manager_data.c +++ b/source/blender/draw/intern/draw_manager_data.c @@ -816,7 +816,7 @@ void DRW_shgroup_call_ex(DRWShadingGroup *shgroup, culling->user_data = user_data; } if (bypass_culling) { - /* NOTE this will disable culling for the whole object. */ + /* NOTE: this will disable culling for the whole object. */ culling->bsphere.radius = -1.0f; } } @@ -1248,7 +1248,7 @@ static void drw_shgroup_init(DRWShadingGroup *shgroup, GPUShader *shader) int chunkid_location = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_RESOURCE_CHUNK); int resourceid_location = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_RESOURCE_ID); - /* TODO(fclem) Will take the place of the above after the GPUShaderCreateInfo port. */ + /* TODO(@fclem): Will take the place of the above after the GPUShaderCreateInfo port. */ if (view_ubo_location == -1) { view_ubo_location = GPU_shader_get_builtin_block(shader, GPU_UNIFORM_BLOCK_DRW_VIEW); } diff --git a/source/blender/draw/intern/draw_shader_shared.h b/source/blender/draw/intern/draw_shader_shared.h index 35350417ca8..133ffdbd636 100644 --- a/source/blender/draw/intern/draw_shader_shared.h +++ b/source/blender/draw/intern/draw_shader_shared.h @@ -23,7 +23,7 @@ struct ViewInfos { }; BLI_STATIC_ASSERT_ALIGN(ViewInfos, 16) -/* TODO(fclem) Mass rename. */ +/* TODO(@fclem): Mass rename. */ #define ViewProjectionMatrix drw_view.persmat #define ViewProjectionMatrixInverse drw_view.persinv #define ViewMatrix drw_view.viewmat diff --git a/source/blender/draw/intern/draw_view_data.h b/source/blender/draw/intern/draw_view_data.h index b37e48c11e8..98ada5a59cb 100644 --- a/source/blender/draw/intern/draw_view_data.h +++ b/source/blender/draw/intern/draw_view_data.h @@ -35,7 +35,7 @@ struct DRWRegisteredDrawEngine; struct DrawEngineType; struct GPUViewport; -/* NOTE these structs are only here for reading the actual lists from the engine. +/* NOTE: these structs are only here for reading the actual lists from the engine. * The actual length of them is stored in a ViewportEngineData_Info. * The length of 1 is just here to avoid compiler warning. */ typedef struct FramebufferList { 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 b846da3f016..4dcd821e607 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 @@ -101,7 +101,7 @@ static uint gpu_component_size_for_attribute_type(CustomDataType type) case CD_PROP_BOOL: case CD_PROP_INT32: case CD_PROP_FLOAT: { - /* TODO(kevindietrich) : should be 1 when scalar attributes conversion is handled by us. See + /* TODO(@kevindietrich): should be 1 when scalar attributes conversion is handled by us. See * comment #extract_attr_init. */ return 3; } @@ -317,7 +317,7 @@ static void extract_attr_init(const MeshRenderData *mr, init_vbo_for_attribute(mr, vbo, request, false, static_cast<uint32_t>(mr->loop_len)); - /* TODO(kevindietrich) : float3 is used for scalar attributes as the implicit conversion done by + /* TODO(@kevindietrich): float3 is used for scalar attributes as the implicit conversion done by * OpenGL to vec4 for a scalar `s` will produce a `vec4(s, 0, 0, 1)`. However, following the * Blender convention, it should be `vec4(s, s, s, 1)`. This could be resolved using a similar * texture as for volume attribute, so we can control the conversion ourselves. */ diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edge_fac.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edge_fac.cc index 8470a71059f..4185f2f84a2 100644 --- a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edge_fac.cc +++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edge_fac.cc @@ -78,7 +78,7 @@ static void extract_edge_fac_init(const MeshRenderData *mr, data->edge_loop_count = static_cast<uchar *>( MEM_callocN(sizeof(uint32_t) * mr->edge_len, __func__)); - /* HACK(fclem) Detecting the need for edge render. + /* HACK(@fclem): Detecting the need for edge render. * We could have a flag in the mesh instead or check the modifier stack. */ const MEdge *med = mr->medge; for (int e_index = 0; e_index < mr->edge_len; e_index++, med++) { diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_pos_nor.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_pos_nor.cc index 5d2ea923658..11f1515275c 100644 --- a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_pos_nor.cc +++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_pos_nor.cc @@ -270,7 +270,7 @@ static void extract_pos_nor_loose_geom_subdiv(const DRWSubdivCache *subdiv_cache const MVert *coarse_verts = coarse_mesh->mvert; uint offset = subdiv_cache->num_subdiv_loops; - /* TODO(kevindietrich) : replace this when compressed normals are supported. */ + /* TODO(@kevindietrich): replace this when compressed normals are supported. */ struct SubdivPosNorLoop { float pos[3]; float nor[3]; diff --git a/source/blender/draw/intern/shaders/common_fxaa_lib.glsl b/source/blender/draw/intern/shaders/common_fxaa_lib.glsl index bf59972fbaa..599d875c500 100644 --- a/source/blender/draw/intern/shaders/common_fxaa_lib.glsl +++ b/source/blender/draw/intern/shaders/common_fxaa_lib.glsl @@ -51,7 +51,7 @@ /*============================================================================ FXAA QUALITY - TUNING KNOBS ------------------------------------------------------------------------------ -NOTE the other tuning knobs are now in the shader function inputs! +NOTE: the other tuning knobs are now in the shader function inputs! ============================================================================*/ #ifndef FXAA_QUALITY__PRESET /* diff --git a/source/blender/draw/intern/shaders/common_subdiv_lib.glsl b/source/blender/draw/intern/shaders/common_subdiv_lib.glsl index 9dd86c35ee4..e6538d80111 100644 --- a/source/blender/draw/intern/shaders/common_subdiv_lib.glsl +++ b/source/blender/draw/intern/shaders/common_subdiv_lib.glsl @@ -101,7 +101,7 @@ uint get_index(uint i) * the format. */ struct PosNorLoop { float x, y, z; - /* TODO(kevindietrich) : figure how to compress properly as GLSL does not have char/short types, + /* TODO(@kevindietrich): figure how to compress properly as GLSL does not have char/short types, * bit operations get tricky. */ float nx, ny, nz; float flag; diff --git a/source/blender/draw/intern/shaders/draw_hair_refine_info.hh b/source/blender/draw/intern/shaders/draw_hair_refine_info.hh index b41be7d8605..bdfc26b7dcd 100644 --- a/source/blender/draw/intern/shaders/draw_hair_refine_info.hh +++ b/source/blender/draw/intern/shaders/draw_hair_refine_info.hh @@ -25,7 +25,7 @@ GPU_SHADER_CREATE_INFO(draw_hair_refine_compute) .local_group_size(1, 1) - .storage_buf(0, Qualifier::WRITE_ONLY, "vec4", "posTime[]") + .storage_buf(0, Qualifier::WRITE, "vec4", "posTime[]") .sampler(0, ImageType::FLOAT_BUFFER, "hairPointBuffer") .sampler(1, ImageType::UINT_BUFFER, "hairStrandBuffer") .sampler(2, ImageType::UINT_BUFFER, "hairStrandSegBuffer") diff --git a/source/blender/draw/intern/shaders/draw_view_info.hh b/source/blender/draw/intern/shaders/draw_view_info.hh index 0a25059ffed..479527379cf 100644 --- a/source/blender/draw/intern/shaders/draw_view_info.hh +++ b/source/blender/draw/intern/shaders/draw_view_info.hh @@ -83,7 +83,7 @@ GPU_SHADER_CREATE_INFO(draw_hair) .sampler(15, ImageType::FLOAT_BUFFER, "hairPointBuffer") .sampler(14, ImageType::UINT_BUFFER, "hairStrandBuffer") .sampler(13, ImageType::UINT_BUFFER, "hairStrandSegBuffer") - /* TODO(fclem) Pack thoses into one UBO. */ + /* TODO(@fclem): Pack these into one UBO. */ .push_constant(Type::INT, "hairStrandsRes") .push_constant(Type::INT, "hairThicknessRes") .push_constant(Type::FLOAT, "hairRadRoot") |