Skip to content

Commit

Permalink
Add ptrw() to LocalVector, to bring it in-line with Vector and `S…
Browse files Browse the repository at this point in the history
…tring`.
  • Loading branch information
Ivorforce committed Dec 22, 2024
1 parent 216b330 commit 9350531
Show file tree
Hide file tree
Showing 47 changed files with 123 additions and 125 deletions.
2 changes: 1 addition & 1 deletion core/io/dir_access.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ Error DirAccess::copy(const String &p_from, const String &p_to, int p_chmod_flag
break;
}

int bytes_read = fsrc->get_buffer(buffer.ptr(), buffer_size);
int bytes_read = fsrc->get_buffer(buffer.ptrw(), buffer_size);
if (bytes_read <= 0) {
err = FAILED;
break;
Expand Down
2 changes: 1 addition & 1 deletion core/io/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2009,7 +2009,7 @@ Error Image::generate_mipmap_roughness(RoughnessChannel p_roughness_channel, con
normal_h = nm->get_height();

normal_sat_vec.resize(normal_w * normal_h * 3);
double *normal_sat = normal_sat_vec.ptr();
double *normal_sat = normal_sat_vec.ptrw();

// Create summed area table.
for (int y = 0; y < normal_h; y++) {
Expand Down
2 changes: 1 addition & 1 deletion core/io/remote_filesystem_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ Error RemoteFilesystemClient::_synchronize_with_server(const String &p_host, int
uint64_t file_size = tcp_client->get_u64();
file_buffer.resize(file_size);

err = tcp_client->get_data(file_buffer.ptr(), file_size);
err = tcp_client->get_data(file_buffer.ptrw(), file_size);
if (err != OK) {
ERR_PRINT(vformat("Error retrieving file from remote filesystem: '%s'.", file));
server_disconnected = true;
Expand Down
2 changes: 1 addition & 1 deletion core/io/zip_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ int godot_unzip_get_current_file_info(unzFile p_zip_file, unz_file_info64 &r_fil
LocalVector<char> long_file_path_buffer;
long_file_path_buffer.resize(r_file_info.size_filename);

err = unzGetCurrentFileInfo64(p_zip_file, &r_file_info, long_file_path_buffer.ptr(), long_file_path_buffer.size(), nullptr, 0, nullptr, 0);
err = unzGetCurrentFileInfo64(p_zip_file, &r_file_info, long_file_path_buffer.ptrw(), long_file_path_buffer.size(), nullptr, 0, nullptr, 0);
if (err != UNZ_OK) {
return err;
}
Expand Down
12 changes: 6 additions & 6 deletions core/math/a_star.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ bool AStar3D::_solve(Point *begin_point, Point *end_point, bool p_allow_partial_
break;
}

sorter.pop_heap(0, open_list.size(), open_list.ptr()); // Remove the current point from the open list.
sorter.pop_heap(0, open_list.size(), open_list.ptrw()); // Remove the current point from the open list.
open_list.remove_at(open_list.size() - 1);
p->closed_pass = pass; // Mark the point as closed.

Expand Down Expand Up @@ -380,9 +380,9 @@ bool AStar3D::_solve(Point *begin_point, Point *end_point, bool p_allow_partial_
e->abs_f_score = e->f_score - e->g_score;

if (new_point) { // The position of the new points is already known.
sorter.push_heap(0, open_list.size() - 1, 0, e, open_list.ptr());
sorter.push_heap(0, open_list.size() - 1, 0, e, open_list.ptrw());
} else {
sorter.push_heap(0, open_list.find(e), 0, e, open_list.ptr());
sorter.push_heap(0, open_list.find(e), 0, e, open_list.ptrw());
}
}
}
Expand Down Expand Up @@ -847,7 +847,7 @@ bool AStar2D::_solve(AStar3D::Point *begin_point, AStar3D::Point *end_point, boo
break;
}

sorter.pop_heap(0, open_list.size(), open_list.ptr()); // Remove the current point from the open list.
sorter.pop_heap(0, open_list.size(), open_list.ptrw()); // Remove the current point from the open list.
open_list.remove_at(open_list.size() - 1);
p->closed_pass = astar.pass; // Mark the point as closed.

Expand Down Expand Up @@ -877,9 +877,9 @@ bool AStar2D::_solve(AStar3D::Point *begin_point, AStar3D::Point *end_point, boo
e->abs_f_score = e->f_score - e->g_score;

if (new_point) { // The position of the new points is already known.
sorter.push_heap(0, open_list.size() - 1, 0, e, open_list.ptr());
sorter.push_heap(0, open_list.size() - 1, 0, e, open_list.ptrw());
} else {
sorter.push_heap(0, open_list.find(e), 0, e, open_list.ptr());
sorter.push_heap(0, open_list.find(e), 0, e, open_list.ptrw());
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions core/math/a_star_grid_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ bool AStarGrid2D::_solve(Point *p_begin_point, Point *p_end_point, bool p_allow_
break;
}

sorter.pop_heap(0, open_list.size(), open_list.ptr()); // Remove the current point from the open list.
sorter.pop_heap(0, open_list.size(), open_list.ptrw()); // Remove the current point from the open list.
open_list.remove_at(open_list.size() - 1);
p->closed_pass = pass; // Mark the point as closed.

Expand Down Expand Up @@ -566,9 +566,9 @@ bool AStarGrid2D::_solve(Point *p_begin_point, Point *p_end_point, bool p_allow_
e->abs_f_score = e->f_score - e->g_score;

if (new_point) { // The position of the new points is already known.
sorter.push_heap(0, open_list.size() - 1, 0, e, open_list.ptr());
sorter.push_heap(0, open_list.size() - 1, 0, e, open_list.ptrw());
} else {
sorter.push_heap(0, open_list.find(e), 0, e, open_list.ptr());
sorter.push_heap(0, open_list.find(e), 0, e, open_list.ptrw());
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions core/math/bvh_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,11 @@ class BVH_IterativeInfo {
if (depth > threshold) {
if (aux_stack.is_empty()) {
aux_stack.resize(ALLOCA_STACK_SIZE * 2);
memcpy(aux_stack.ptr(), stack, get_alloca_stacksize());
memcpy(aux_stack.ptrw(), stack, get_alloca_stacksize());
} else {
aux_stack.resize(aux_stack.size() * 2);
}
stack = aux_stack.ptr();
stack = aux_stack.ptrw();
threshold = aux_stack.size() - 2;
}
return &stack[depth++];
Expand Down
2 changes: 1 addition & 1 deletion core/math/convex_hull.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2320,7 +2320,7 @@ Error ConvexHullComputer::convex_hull(const Vector<Vector3> &p_points, Geometry3
// reverse indices: Godot wants clockwise, but this is counter-clockwise
if (face.indices.size() > 2) {
// reverse all but the first index.
int *indices = face.indices.ptr();
int *indices = face.indices.ptrw();
for (uint32_t c = 0; c < (face.indices.size() - 1) / 2; c++) {
SWAP(indices[c + 1], indices[face.indices.size() - 1 - c]);
}
Expand Down
12 changes: 6 additions & 6 deletions core/math/dynamic_bvh.h
Original file line number Diff line number Diff line change
Expand Up @@ -344,12 +344,12 @@ void DynamicBVH::aabb_query(const AABB &p_box, QueryResult &r_result) {
if (depth > threshold) {
if (aux_stack.is_empty()) {
aux_stack.resize(ALLOCA_STACK_SIZE * 2);
memcpy(aux_stack.ptr(), alloca_stack, ALLOCA_STACK_SIZE * sizeof(const Node *));
memcpy(aux_stack.ptrw(), alloca_stack, ALLOCA_STACK_SIZE * sizeof(const Node *));
alloca_stack = nullptr;
} else {
aux_stack.resize(aux_stack.size() * 2);
}
stack = aux_stack.ptr();
stack = aux_stack.ptrw();
threshold = aux_stack.size() - 2;
}
stack[depth++] = n->children[0];
Expand Down Expand Up @@ -397,12 +397,12 @@ void DynamicBVH::convex_query(const Plane *p_planes, int p_plane_count, const Ve
if (depth > threshold) {
if (aux_stack.is_empty()) {
aux_stack.resize(ALLOCA_STACK_SIZE * 2);
memcpy(aux_stack.ptr(), alloca_stack, ALLOCA_STACK_SIZE * sizeof(const Node *));
memcpy(aux_stack.ptrw(), alloca_stack, ALLOCA_STACK_SIZE * sizeof(const Node *));
alloca_stack = nullptr;
} else {
aux_stack.resize(aux_stack.size() * 2);
}
stack = aux_stack.ptr();
stack = aux_stack.ptrw();
threshold = aux_stack.size() - 2;
}
stack[depth++] = n->children[0];
Expand Down Expand Up @@ -456,12 +456,12 @@ void DynamicBVH::ray_query(const Vector3 &p_from, const Vector3 &p_to, QueryResu
if (depth > threshold) {
if (aux_stack.is_empty()) {
aux_stack.resize(ALLOCA_STACK_SIZE * 2);
memcpy(aux_stack.ptr(), alloca_stack, ALLOCA_STACK_SIZE * sizeof(const Node *));
memcpy(aux_stack.ptrw(), alloca_stack, ALLOCA_STACK_SIZE * sizeof(const Node *));
alloca_stack = nullptr;
} else {
aux_stack.resize(aux_stack.size() * 2);
}
stack = aux_stack.ptr();
stack = aux_stack.ptrw();
threshold = aux_stack.size() - 2;
}
stack[depth++] = node->children[0];
Expand Down
2 changes: 1 addition & 1 deletion core/object/undo_redo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ void UndoRedo::_process_operation_list(List<Operation>::Element *E, bool p_execu
args.push_back(&binds[i]);
}

method_callback(method_callback_ud, obj, op.name, args.ptr(), binds.size());
method_callback(method_callback_ud, obj, op.name, args.ptrw(), binds.size());
}
}
} break;
Expand Down
12 changes: 5 additions & 7 deletions core/templates/local_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,11 @@ class LocalVector {
T *data = nullptr;

public:
T *ptr() {
return data;
}

const T *ptr() const {
return data;
}
// This function is the same as ptr(), in that it returns a pointer to the underlying buffer.
// It is called ptrw() to convey write intention. This decision was made to have API uniformity
// to other collection types, e.g. Vector.
T *ptrw() { return data; }
const T *ptr() const { return data; }

_FORCE_INLINE_ void push_back(T p_elem) {
if (unlikely(count == capacity)) {
Expand Down
4 changes: 2 additions & 2 deletions core/variant/variant_call.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ static _FORCE_INLINE_ void vc_ptrcall(void (*method)(T *, P...), void *p_base, c
Variant base = PtrToArg<m_class>::convert(p_base); \
Variant ret; \
Callable::CallError ce; \
m_method_ptr(&base, vars_ptrs.ptr(), p_argcount, ret, ce); \
m_method_ptr(&base, vars_ptrs.ptrw(), p_argcount, ret, ce); \
if (m_has_return) { \
m_return_type r = ret; \
PtrToArg<m_return_type>::encode(ret, r_ret); \
Expand Down Expand Up @@ -626,7 +626,7 @@ static _FORCE_INLINE_ void vc_ptrcall(void (*method)(T *, P...), void *p_base, c
Variant base = PtrToArg<m_class>::convert(p_base); \
Variant ret; \
Callable::CallError ce; \
m_method_ptr(&base, vars_ptrs.ptr(), p_argcount, ret, ce); \
m_method_ptr(&base, vars_ptrs.ptrw(), p_argcount, ret, ce); \
} \
static int get_argument_count() { \
return 1; \
Expand Down
12 changes: 6 additions & 6 deletions drivers/gles3/rasterizer_scene_gles3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2206,7 +2206,7 @@ void RasterizerSceneGLES3::_render_shadow_pass(RID p_light, RID p_shadow_atlas,
spec_constant_base_flags |= SceneShaderGLES3::RENDER_SHADOWS_LINEAR;
}

RenderListParameters render_list_params(render_list[RENDER_LIST_SECONDARY].elements.ptr(), render_list[RENDER_LIST_SECONDARY].elements.size(), reverse_cull, spec_constant_base_flags, false);
RenderListParameters render_list_params(render_list[RENDER_LIST_SECONDARY].elements.ptrw(), render_list[RENDER_LIST_SECONDARY].elements.size(), reverse_cull, spec_constant_base_flags, false);

_render_list_template<PASS_MODE_SHADOW>(&render_list_params, &render_data, 0, render_list[RENDER_LIST_SECONDARY].elements.size());

Expand Down Expand Up @@ -2508,7 +2508,7 @@ void RasterizerSceneGLES3::render_scene(const Ref<RenderSceneBuffers> &p_render_
SceneShaderGLES3::DISABLE_LIGHTMAP | SceneShaderGLES3::DISABLE_LIGHT_OMNI |
SceneShaderGLES3::DISABLE_LIGHT_SPOT;

RenderListParameters render_list_params(render_list[RENDER_LIST_OPAQUE].elements.ptr(), render_list[RENDER_LIST_OPAQUE].elements.size(), reverse_cull, spec_constant, use_wireframe);
RenderListParameters render_list_params(render_list[RENDER_LIST_OPAQUE].elements.ptrw(), render_list[RENDER_LIST_OPAQUE].elements.size(), reverse_cull, spec_constant, use_wireframe);
_render_list_template<PASS_MODE_DEPTH>(&render_list_params, &render_data, 0, render_list[RENDER_LIST_OPAQUE].elements.size());

glColorMask(1, 1, 1, 1);
Expand Down Expand Up @@ -2608,7 +2608,7 @@ void RasterizerSceneGLES3::render_scene(const Ref<RenderSceneBuffers> &p_render_
}

// Render Opaque Objects.
RenderListParameters render_list_params(render_list[RENDER_LIST_OPAQUE].elements.ptr(), render_list[RENDER_LIST_OPAQUE].elements.size(), reverse_cull, spec_constant_base_flags, use_wireframe);
RenderListParameters render_list_params(render_list[RENDER_LIST_OPAQUE].elements.ptrw(), render_list[RENDER_LIST_OPAQUE].elements.size(), reverse_cull, spec_constant_base_flags, use_wireframe);

_render_list_template<PASS_MODE_COLOR>(&render_list_params, &render_data, 0, render_list[RENDER_LIST_OPAQUE].elements.size());

Expand Down Expand Up @@ -2684,7 +2684,7 @@ void RasterizerSceneGLES3::render_scene(const Ref<RenderSceneBuffers> &p_render_
scene_state.enable_gl_blend(true);

//Render transparent pass
RenderListParameters render_list_params_alpha(render_list[RENDER_LIST_ALPHA].elements.ptr(), render_list[RENDER_LIST_ALPHA].elements.size(), reverse_cull, spec_constant_base_flags, use_wireframe);
RenderListParameters render_list_params_alpha(render_list[RENDER_LIST_ALPHA].elements.ptrw(), render_list[RENDER_LIST_ALPHA].elements.size(), reverse_cull, spec_constant_base_flags, use_wireframe);

_render_list_template<PASS_MODE_COLOR_TRANSPARENT>(&render_list_params_alpha, &render_data, 0, render_list[RENDER_LIST_ALPHA].elements.size(), true);

Expand Down Expand Up @@ -3705,7 +3705,7 @@ void RasterizerSceneGLES3::render_particle_collider_heightfield(RID p_collider,

glClear(GL_DEPTH_BUFFER_BIT);

RenderListParameters render_list_params(render_list[RENDER_LIST_SECONDARY].elements.ptr(), render_list[RENDER_LIST_SECONDARY].elements.size(), false, 31, false);
RenderListParameters render_list_params(render_list[RENDER_LIST_SECONDARY].elements.ptrw(), render_list[RENDER_LIST_SECONDARY].elements.size(), false, 31, false);

_render_list_template<PASS_MODE_SHADOW>(&render_list_params, &render_data, 0, render_list[RENDER_LIST_SECONDARY].elements.size());

Expand Down Expand Up @@ -3763,7 +3763,7 @@ void RasterizerSceneGLES3::_render_uv2(const PagedArray<RenderGeometryInstance *
base_spec_constant |= SceneShaderGLES3::DISABLE_LIGHT_SPOT;
base_spec_constant |= SceneShaderGLES3::DISABLE_LIGHTMAP;

RenderListParameters render_list_params(render_list[RENDER_LIST_SECONDARY].elements.ptr(), render_list[RENDER_LIST_SECONDARY].elements.size(), false, base_spec_constant, true, Vector2(0, 0));
RenderListParameters render_list_params(render_list[RENDER_LIST_SECONDARY].elements.ptrw(), render_list[RENDER_LIST_SECONDARY].elements.size(), false, base_spec_constant, true, Vector2(0, 0));

const int uv_offset_count = 9;
static const Vector2 uv_offsets[uv_offset_count] = {
Expand Down
8 changes: 4 additions & 4 deletions drivers/gles3/rasterizer_scene_gles3.h
Original file line number Diff line number Diff line change
Expand Up @@ -600,12 +600,12 @@ class RasterizerSceneGLES3 : public RendererSceneRender {

void sort_by_key() {
SortArray<GeometryInstanceSurface *, SortByKey> sorter;
sorter.sort(elements.ptr(), elements.size());
sorter.sort(elements.ptrw(), elements.size());
}

void sort_by_key_range(uint32_t p_from, uint32_t p_size) {
SortArray<GeometryInstanceSurface *, SortByKey> sorter;
sorter.sort(elements.ptr() + p_from, p_size);
sorter.sort(elements.ptrw() + p_from, p_size);
}

struct SortByDepth {
Expand All @@ -617,7 +617,7 @@ class RasterizerSceneGLES3 : public RendererSceneRender {
void sort_by_depth() { //used for shadows

SortArray<GeometryInstanceSurface *, SortByDepth> sorter;
sorter.sort(elements.ptr(), elements.size());
sorter.sort(elements.ptrw(), elements.size());
}

struct SortByReverseDepthAndPriority {
Expand All @@ -629,7 +629,7 @@ class RasterizerSceneGLES3 : public RendererSceneRender {
void sort_by_reverse_depth_and_priority() { //used for alpha

SortArray<GeometryInstanceSurface *, SortByReverseDepthAndPriority> sorter;
sorter.sort(elements.ptr(), elements.size());
sorter.sort(elements.ptrw(), elements.size());
}

_FORCE_INLINE_ void add_element(GeometryInstanceSurface *p_element) {
Expand Down
2 changes: 1 addition & 1 deletion drivers/gles3/storage/material_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ void ShaderData::get_shader_uniform_list(List<PropertyInfo> *p_param_list) const
filtered_uniforms.push_back(Pair<StringName, int>(E.key, E.value.prop_order));
}
int uniform_count = filtered_uniforms.size();
sorter.sort(filtered_uniforms.ptr(), uniform_count);
sorter.sort(filtered_uniforms.ptrw(), uniform_count);

String last_group;
for (int i = 0; i < uniform_count; i++) {
Expand Down
6 changes: 3 additions & 3 deletions drivers/gles3/storage/mesh_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2273,7 +2273,7 @@ void MeshStorage::skeleton_allocate_data(RID p_skeleton, int p_bones, bool p_2d_
glBindTexture(GL_TEXTURE_2D, 0);
GLES3::Utilities::get_singleton()->texture_allocated_data(skeleton->transforms_texture, skeleton->data.size() * sizeof(float), "Skeleton transforms texture");

memset(skeleton->data.ptr(), 0, skeleton->data.size() * sizeof(float));
memset(skeleton->data.ptrw(), 0, skeleton->data.size() * sizeof(float));

_skeleton_make_dirty(skeleton);
}
Expand Down Expand Up @@ -2304,7 +2304,7 @@ void MeshStorage::skeleton_bone_set_transform(RID p_skeleton, int p_bone, const
ERR_FAIL_INDEX(p_bone, skeleton->size);
ERR_FAIL_COND(skeleton->use_2d);

float *dataptr = skeleton->data.ptr() + p_bone * 12;
float *dataptr = skeleton->data.ptrw() + p_bone * 12;

dataptr[0] = p_transform.basis.rows[0][0];
dataptr[1] = p_transform.basis.rows[0][1];
Expand Down Expand Up @@ -2356,7 +2356,7 @@ void MeshStorage::skeleton_bone_set_transform_2d(RID p_skeleton, int p_bone, con
ERR_FAIL_INDEX(p_bone, skeleton->size);
ERR_FAIL_COND(!skeleton->use_2d);

float *dataptr = skeleton->data.ptr() + p_bone * 8;
float *dataptr = skeleton->data.ptrw() + p_bone * 8;

dataptr[0] = p_transform.columns[0][0];
dataptr[1] = p_transform.columns[1][0];
Expand Down
2 changes: 1 addition & 1 deletion drivers/metal/metal_objects.mm
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@
resources->reserve(resources->size() + keyval.value.size());

uint32_t i = 0, j = 0;
__unsafe_unretained id<MTLResource> *resources_ptr = resources->ptr();
__unsafe_unretained id<MTLResource> *resources_ptr = resources->ptrw();
const __unsafe_unretained id<MTLResource> *keyval_ptr = keyval.value.ptr();
// 2-way merge.
while (i < resources->size() && j < keyval.value.size()) {
Expand Down
2 changes: 1 addition & 1 deletion drivers/metal/rendering_device_driver_metal.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1303,7 +1303,7 @@ void read(LocalVector<uint8_t> &p_val) {
read(len);
CHECK(len);
p_val.resize(len);
memcpy(p_val.ptr(), data + pos, len);
memcpy(p_val.ptrw(), data + pos, len);
pos += len;
}

Expand Down
Loading

0 comments on commit 9350531

Please sign in to comment.