diff options
author | Campbell Barton <campbell@blender.org> | 2022-09-26 10:38:25 +0300 |
---|---|---|
committer | Campbell Barton <campbell@blender.org> | 2022-09-26 10:58:36 +0300 |
commit | 333e41eac6daf60c6aa9df0496a39c57d74b9c87 (patch) | |
tree | 5986e980fd64bc4ef1c3dda125a0f9dca4bab2c8 /source/blender/gpu | |
parent | 0210c4df1793799a09a35e44be286dfca88769dc (diff) |
Cleanup: replace C-style casts with functional casts for numeric types
Use function style casts in C++ headers & source.
Diffstat (limited to 'source/blender/gpu')
-rw-r--r-- | source/blender/gpu/intern/gpu_framebuffer_private.hh | 4 | ||||
-rw-r--r-- | source/blender/gpu/metal/mtl_context.hh | 2 | ||||
-rw-r--r-- | source/blender/gpu/metal/mtl_pso_descriptor_state.hh | 38 | ||||
-rw-r--r-- | source/blender/gpu/metal/mtl_texture.hh | 16 | ||||
-rw-r--r-- | source/blender/gpu/opengl/gl_index_buffer.hh | 6 | ||||
-rw-r--r-- | source/blender/gpu/opengl/gl_vertex_buffer.cc | 2 |
6 files changed, 32 insertions, 36 deletions
diff --git a/source/blender/gpu/intern/gpu_framebuffer_private.hh b/source/blender/gpu/intern/gpu_framebuffer_private.hh index 6e5d9518bfc..76e816e7f65 100644 --- a/source/blender/gpu/intern/gpu_framebuffer_private.hh +++ b/source/blender/gpu/intern/gpu_framebuffer_private.hh @@ -40,12 +40,12 @@ typedef enum GPUAttachmentType : int { inline constexpr GPUAttachmentType operator-(GPUAttachmentType a, int b) { - return static_cast<GPUAttachmentType>(static_cast<int>(a) - b); + return static_cast<GPUAttachmentType>(int(a) - b); } inline constexpr GPUAttachmentType operator+(GPUAttachmentType a, int b) { - return static_cast<GPUAttachmentType>(static_cast<int>(a) + b); + return static_cast<GPUAttachmentType>(int(a) + b); } inline GPUAttachmentType &operator++(GPUAttachmentType &a) diff --git a/source/blender/gpu/metal/mtl_context.hh b/source/blender/gpu/metal/mtl_context.hh index 3ba33ebfa46..6229afcef79 100644 --- a/source/blender/gpu/metal/mtl_context.hh +++ b/source/blender/gpu/metal/mtl_context.hh @@ -352,7 +352,7 @@ struct MTLSamplerArray { { uint32_t hash = this->num_samplers; for (int i = 0; i < this->num_samplers; i++) { - hash ^= (uint32_t)this->mtl_sampler_flags[i] << (i % 3); + hash ^= uint32_t(this->mtl_sampler_flags[i]) << (i % 3); } return hash; } diff --git a/source/blender/gpu/metal/mtl_pso_descriptor_state.hh b/source/blender/gpu/metal/mtl_pso_descriptor_state.hh index 1906350679a..198d309874b 100644 --- a/source/blender/gpu/metal/mtl_pso_descriptor_state.hh +++ b/source/blender/gpu/metal/mtl_pso_descriptor_state.hh @@ -28,8 +28,8 @@ struct MTLVertexAttributeDescriptorPSO { uint64_t hash() const { - return (uint64_t)((uint64_t)this->format ^ (this->offset << 4) ^ (this->buffer_index << 8) ^ - (this->format_conversion_mode << 12)); + return uint64_t((uint64_t(this->format) ^ (this->offset << 4) ^ (this->buffer_index << 8) ^ + (this->format_conversion_mode << 12))); } }; @@ -46,8 +46,7 @@ struct MTLVertexBufferLayoutDescriptorPSO { uint64_t hash() const { - return (uint64_t)((uint64_t)this->step_function ^ (this->step_rate << 4) ^ - (this->stride << 8)); + return uint64_t(uint64_t(this->step_function) ^ (this->step_rate << 4) ^ (this->stride << 8)); } }; @@ -217,31 +216,30 @@ struct MTLRenderPipelineStateDescriptor { * has collisions. */ uint64_t hash = this->vertex_descriptor.hash(); - hash ^= (uint64_t)this->num_color_attachments << 16; /* up to 6 (3 bits). */ - hash ^= (uint64_t)this->depth_attachment_format << 18; /* up to 555 (9 bits). */ - hash ^= (uint64_t)this->stencil_attachment_format << 20; /* up to 555 (9 bits). */ - hash ^= (uint64_t)(*( - (uint64_t *)&this->vertex_descriptor.prim_topology_class)); /* Up to 3 (2 bits). */ + hash ^= uint64_t(this->num_color_attachments) << 16; /* up to 6 (3 bits). */ + hash ^= uint64_t(this->depth_attachment_format) << 18; /* up to 555 (9 bits). */ + hash ^= uint64_t(this->stencil_attachment_format) << 20; /* up to 555 (9 bits). */ + hash ^= uint64_t( + *((uint64_t *)&this->vertex_descriptor.prim_topology_class)); /* Up to 3 (2 bits). */ /* Only include elements in Hash if they are needed - avoids variable null assignments * influencing hash. */ if (this->num_color_attachments > 0) { - hash ^= (uint64_t)this->color_write_mask << 22; /* 4 bit bit-mask. */ - hash ^= (uint64_t)this->alpha_blend_op << 26; /* Up to 4 (3 bits). */ - hash ^= (uint64_t)this->rgb_blend_op << 29; /* Up to 4 (3 bits). */ - hash ^= (uint64_t)this->dest_alpha_blend_factor << 32; /* Up to 18 (5 bits). */ - hash ^= (uint64_t)this->dest_rgb_blend_factor << 37; /* Up to 18 (5 bits). */ - hash ^= (uint64_t)this->src_alpha_blend_factor << 42; /* Up to 18 (5 bits). */ - hash ^= (uint64_t)this->src_rgb_blend_factor << 47; /* Up to 18 (5 bits). */ + hash ^= uint64_t(this->color_write_mask) << 22; /* 4 bit bit-mask. */ + hash ^= uint64_t(this->alpha_blend_op) << 26; /* Up to 4 (3 bits). */ + hash ^= uint64_t(this->rgb_blend_op) << 29; /* Up to 4 (3 bits). */ + hash ^= uint64_t(this->dest_alpha_blend_factor) << 32; /* Up to 18 (5 bits). */ + hash ^= uint64_t(this->dest_rgb_blend_factor) << 37; /* Up to 18 (5 bits). */ + hash ^= uint64_t(this->src_alpha_blend_factor) << 42; /* Up to 18 (5 bits). */ + hash ^= uint64_t(this->src_rgb_blend_factor) << 47; /* Up to 18 (5 bits). */ } for (const uint c : IndexRange(GPU_FB_MAX_COLOR_ATTACHMENT)) { - hash ^= (uint64_t)this->color_attachment_format[c] << (c + 52); // up to 555 (9 bits) + hash ^= uint64_t(this->color_attachment_format[c]) << (c + 52); /* Up to 555 (9 bits). */ } - hash |= (uint64_t)((this->blending_enabled && (this->num_color_attachments > 0)) ? 1 : 0) - << 62; - hash ^= (uint64_t)this->point_size; + hash |= uint64_t((this->blending_enabled && (this->num_color_attachments > 0)) ? 1 : 0) << 62; + hash ^= uint64_t(this->point_size); return hash; } diff --git a/source/blender/gpu/metal/mtl_texture.hh b/source/blender/gpu/metal/mtl_texture.hh index 88d09e4e133..ebc9eb2e00e 100644 --- a/source/blender/gpu/metal/mtl_texture.hh +++ b/source/blender/gpu/metal/mtl_texture.hh @@ -51,9 +51,9 @@ struct TextureUpdateRoutineSpecialisation { uint64_t hash() const { blender::DefaultHash<std::string> string_hasher; - return (uint64_t)string_hasher( + return uint64_t(string_hasher( this->input_data_type + this->output_data_type + - std::to_string((this->component_count_input << 8) + this->component_count_output)); + std::to_string((this->component_count_input << 8) + this->component_count_output))); } }; @@ -108,10 +108,10 @@ struct TextureReadRoutineSpecialisation { uint64_t hash() const { blender::DefaultHash<std::string> string_hasher; - return (uint64_t)string_hasher(this->input_data_type + this->output_data_type + - std::to_string((this->component_count_input << 8) + - this->component_count_output + - (this->depth_format_mode << 28))); + return uint64_t(string_hasher(this->input_data_type + this->output_data_type + + std::to_string((this->component_count_input << 8) + + this->component_count_output + + (this->depth_format_mode << 28)))); } }; @@ -138,12 +138,12 @@ struct MTLSamplerState { operator uint() const { - return (uint)state; + return uint(state); } operator uint64_t() const { - return (uint64_t)state; + return uint64_t(state); } }; diff --git a/source/blender/gpu/opengl/gl_index_buffer.hh b/source/blender/gpu/opengl/gl_index_buffer.hh index 974c01d2b65..78159db764c 100644 --- a/source/blender/gpu/opengl/gl_index_buffer.hh +++ b/source/blender/gpu/opengl/gl_index_buffer.hh @@ -35,11 +35,9 @@ class GLIndexBuf : public IndexBuf { { additional_vertex_offset += index_start_; if (index_type_ == GPU_INDEX_U32) { - return reinterpret_cast<void *>(static_cast<intptr_t>(additional_vertex_offset) * - sizeof(GLuint)); + return reinterpret_cast<void *>(intptr_t(additional_vertex_offset) * sizeof(GLuint)); } - return reinterpret_cast<void *>(static_cast<intptr_t>(additional_vertex_offset) * - sizeof(GLushort)); + return reinterpret_cast<void *>(intptr_t(additional_vertex_offset) * sizeof(GLushort)); } GLuint restart_index() const diff --git a/source/blender/gpu/opengl/gl_vertex_buffer.cc b/source/blender/gpu/opengl/gl_vertex_buffer.cc index 2515b7e8f19..d186c2025b3 100644 --- a/source/blender/gpu/opengl/gl_vertex_buffer.cc +++ b/source/blender/gpu/opengl/gl_vertex_buffer.cc @@ -142,7 +142,7 @@ void *GLVertBuf::unmap(const void *mapped_data) const void GLVertBuf::wrap_handle(uint64_t handle) { BLI_assert(vbo_id_ == 0); - BLI_assert(glIsBuffer(static_cast<uint>(handle))); + BLI_assert(glIsBuffer(uint(handle))); is_wrapper_ = true; vbo_id_ = uint(handle); /* We assume the data is already on the device, so no need to allocate or send it. */ |