Fix: Cycles: Ubsan warnings with new voronoi texture hashing

Signed integer overflow is undefined, but works reliably enough for us
anyway, so just silence it like the Blender implementation already does.

This also caused some tests like cycles_displacement_cpu to run much slower
(3s -> 42s) due to the overhead of detecting and ignoring repeated warnings.

Pull Request: https://projects.blender.org/blender/blender/pulls/146783
This commit is contained in:
Brecht Van Lommel
2025-09-25 17:48:22 +02:00
committed by Brecht Van Lommel
parent b74e696acc
commit 57342a51f8
2 changed files with 19 additions and 4 deletions

View File

@@ -82,6 +82,18 @@
# endif
#endif /* __KERNEL_GPU__ */
/* Address sanitizer suppression. */
#ifdef __KERNEL_GPU__
# define ccl_ignore_integer_overflow
#else
# if defined(__SANITIZE_ADDRESS__) && (defined(__GNUC__) || defined(__clang__))
# define ccl_ignore_integer_overflow [[gnu::no_sanitize("signed-integer-overflow")]]
# else
# define ccl_ignore_integer_overflow
# endif
#endif
/* macros */
/* hints for branch prediction, only use in code that runs a _lot_ */

View File

@@ -4,6 +4,7 @@
#pragma once
#include "util/defines.h"
#include "util/math.h"
#include "util/types.h"
@@ -31,9 +32,11 @@ ccl_device_forceinline float uint_to_float_incl(const uint n)
* https://jcgt.org/published/0009/03/02/
*
* Slightly modified to only use signed integers,
* so that they can also be implemented in OSL. */
* so that they can also be implemented in OSL.
*
* Silence UBsan warnings about signed integer overflow. */
ccl_device_inline int2 hash_pcg2d_i(int2 v)
ccl_ignore_integer_overflow ccl_device_inline int2 hash_pcg2d_i(int2 v)
{
v = v * make_int2(1664525) + make_int2(1013904223);
v.x += v.y * 1664525;
@@ -44,7 +47,7 @@ ccl_device_inline int2 hash_pcg2d_i(int2 v)
return v & make_int2(0x7FFFFFFF);
}
ccl_device_inline int3 hash_pcg3d_i(int3 v)
ccl_ignore_integer_overflow ccl_device_inline int3 hash_pcg3d_i(int3 v)
{
v = v * make_int3(1664525) + make_int3(1013904223);
v.x += v.y * v.z;
@@ -57,7 +60,7 @@ ccl_device_inline int3 hash_pcg3d_i(int3 v)
return v & make_int3(0x7FFFFFFF);
}
ccl_device_inline int4 hash_pcg4d_i(int4 v)
ccl_ignore_integer_overflow ccl_device_inline int4 hash_pcg4d_i(int4 v)
{
v = v * make_int4(1664525) + make_int4(1013904223);
v.x += v.y * v.w;