diff options
author | Sergey Sharybin <sergey@blender.org> | 2022-02-10 12:37:00 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey@blender.org> | 2022-02-10 14:39:41 +0300 |
commit | 04d55038ee52fc1155cc0ece916d90fd535c2364 (patch) | |
tree | c216c00833a652d914a3a7012751bdd4c2fb90a9 /intern/cycles/scene | |
parent | 87d2de88fdeec75c7dcd77f93d51ee71542b45ce (diff) |
Fix size_t -> int -> size_t round trip in Cycles
There are two things achieved by this change:
- No possible downcast of size_t to int when calculating motion steps.
- Disambiguate call to `min()` which was for some reason considered
ambiguous on 32bit platforms `min(int, unsigned int)`.
- Do the same for the `max()` call to keep them symmetrical.
On an implementation side the `min()` is defined for a fixed width
integer type to disambiguate uint from size_t on 32bit platforms,
and yet be able to use it for 32bit operands on 64bit platforms without
upcast.
This ended up in a bit bigger change as the conditional compile-in of
functions is easiest if the functions is templated. Making the functions
templated required to remove the other source of ambiguity which is
`algorithm.h` which was pulling min/max from std.
Now it is the `math.h` which is the source of truth for min/max.
It was only one place which was relying on `algorithm.h` for these
functions, hence the choice of `math.h` as the safest and least
intrusive.
Fixes 32bit platforms (such as i386) in Debian package build system.
Differential Revision: https://developer.blender.org/D14062
Diffstat (limited to 'intern/cycles/scene')
-rw-r--r-- | intern/cycles/scene/hair.cpp | 12 | ||||
-rw-r--r-- | intern/cycles/scene/light.cpp | 4 | ||||
-rw-r--r-- | intern/cycles/scene/mesh.cpp | 2 | ||||
-rw-r--r-- | intern/cycles/scene/pointcloud.cpp | 2 |
4 files changed, 10 insertions, 10 deletions
diff --git a/intern/cycles/scene/hair.cpp b/intern/cycles/scene/hair.cpp index 2951a609ae9..9ac502e2727 100644 --- a/intern/cycles/scene/hair.cpp +++ b/intern/cycles/scene/hair.cpp @@ -119,7 +119,7 @@ void Hair::Curve::motion_keys(const float3 *curve_keys, { /* Figure out which steps we need to fetch and their interpolation factor. */ const size_t max_step = num_steps - 1; - const size_t step = min((int)(time * max_step), max_step - 1); + const size_t step = std::min((size_t)(time * max_step), max_step - 1); const float t = time * max_step - step; /* Fetch vertex coordinates. */ float4 curr_keys[2]; @@ -147,7 +147,7 @@ void Hair::Curve::cardinal_motion_keys(const float3 *curve_keys, { /* Figure out which steps we need to fetch and their interpolation factor. */ const size_t max_step = num_steps - 1; - const size_t step = min((int)(time * max_step), max_step - 1); + const size_t step = min((size_t)(time * max_step), max_step - 1); const float t = time * max_step - step; /* Fetch vertex coordinates. */ float4 curr_keys[4]; @@ -191,8 +191,8 @@ void Hair::Curve::keys_for_step(const float3 *curve_keys, size_t k1, float4 r_keys[2]) const { - k0 = max(k0, 0); - k1 = min(k1, num_keys - 1); + k0 = max(k0, (size_t)0); + k1 = min(k1, (size_t)(num_keys - 1)); const size_t center_step = ((num_steps - 1) / 2); if (step == center_step) { /* Center step: regular key location. */ @@ -237,8 +237,8 @@ void Hair::Curve::cardinal_keys_for_step(const float3 *curve_keys, size_t k3, float4 r_keys[4]) const { - k0 = max(k0, 0); - k3 = min(k3, num_keys - 1); + k0 = max(k0, (size_t)0); + k3 = min(k3, (size_t)(num_keys - 1)); const size_t center_step = ((num_steps - 1) / 2); if (step == center_step) { /* Center step: regular key location. */ diff --git a/intern/cycles/scene/light.cpp b/intern/cycles/scene/light.cpp index 83e531f42ef..415c4044aee 100644 --- a/intern/cycles/scene/light.cpp +++ b/intern/cycles/scene/light.cpp @@ -606,8 +606,8 @@ void LightManager::device_update_background(Device *device, ImageMetaData metadata; if (!env->handle.empty()) { ImageMetaData metadata = env->handle.metadata(); - environment_res.x = max(environment_res.x, metadata.width); - environment_res.y = max(environment_res.y, metadata.height); + environment_res.x = max(environment_res.x, (int)metadata.width); + environment_res.y = max(environment_res.y, (int)metadata.height); } } if (node->type == SkyTextureNode::get_node_type()) { diff --git a/intern/cycles/scene/mesh.cpp b/intern/cycles/scene/mesh.cpp index c381d7a54ff..f53dca88ee0 100644 --- a/intern/cycles/scene/mesh.cpp +++ b/intern/cycles/scene/mesh.cpp @@ -53,7 +53,7 @@ void Mesh::Triangle::motion_verts(const float3 *verts, { /* Figure out which steps we need to fetch and their interpolation factor. */ const size_t max_step = num_steps - 1; - const size_t step = min((int)(time * max_step), max_step - 1); + const size_t step = min((size_t)(time * max_step), max_step - 1); const float t = time * max_step - step; /* Fetch vertex coordinates. */ float3 curr_verts[3]; diff --git a/intern/cycles/scene/pointcloud.cpp b/intern/cycles/scene/pointcloud.cpp index 4f88fe9db3d..6356a5030f3 100644 --- a/intern/cycles/scene/pointcloud.cpp +++ b/intern/cycles/scene/pointcloud.cpp @@ -55,7 +55,7 @@ float4 PointCloud::Point::motion_key(const float3 *points, /* Figure out which steps we need to fetch and their * interpolation factor. */ const size_t max_step = num_steps - 1; - const size_t step = min((int)(time * max_step), max_step - 1); + const size_t step = min((size_t)(time * max_step), max_step - 1); const float t = time * max_step - step; /* Fetch vertex coordinates. */ const float4 curr_key = point_for_step( |