diff options
author | Michael Kowalski <makowalski@nvidia.com> | 2022-09-23 23:56:14 +0300 |
---|---|---|
committer | Michael Kowalski <makowalski@nvidia.com> | 2022-09-23 23:56:14 +0300 |
commit | b2ad97ba97f3e55d1dd463e29ca0b2ec6fe761e1 (patch) | |
tree | f94394835c6b731e4e379f4ef48fb78b4af4b9ca /intern/cycles/util | |
parent | b31807c75f0c18c43ac6979e6da57dc9d420167a (diff) | |
parent | 7e980f2b8cb96aa6d04dc72899d08473367eeeb9 (diff) |
Merge branch 'master' into tmp-usd-alab-v2-T100452tmp-usd-alab-v2-T100452
Diffstat (limited to 'intern/cycles/util')
-rw-r--r-- | intern/cycles/util/CMakeLists.txt | 3 | ||||
-rw-r--r-- | intern/cycles/util/defines.h | 40 | ||||
-rw-r--r-- | intern/cycles/util/hash.h | 143 | ||||
-rw-r--r-- | intern/cycles/util/math.h | 6 | ||||
-rw-r--r-- | intern/cycles/util/opengl.h | 2 | ||||
-rw-r--r-- | intern/cycles/util/version.h | 4 |
6 files changed, 145 insertions, 53 deletions
diff --git a/intern/cycles/util/CMakeLists.txt b/intern/cycles/util/CMakeLists.txt index 81a7607baab..997d574a3b0 100644 --- a/intern/cycles/util/CMakeLists.txt +++ b/intern/cycles/util/CMakeLists.txt @@ -3,7 +3,6 @@ set(INC .. - ../../glew-mx ) set(INC_SYS @@ -149,6 +148,4 @@ endif() include_directories(${INC}) include_directories(SYSTEM ${INC_SYS}) -add_definitions(${GL_DEFINITIONS}) - cycles_add_library(cycles_util "${LIB}" ${SRC} ${SRC_HEADERS}) diff --git a/intern/cycles/util/defines.h b/intern/cycles/util/defines.h index c7118ca09c9..1969529eff0 100644 --- a/intern/cycles/util/defines.h +++ b/intern/cycles/util/defines.h @@ -89,46 +89,6 @@ # define UNLIKELY(x) (x) #endif -#if defined(__GNUC__) || defined(__clang__) -# if defined(__cplusplus) -/* Some magic to be sure we don't have reference in the type. */ -template<typename T> static inline T decltype_helper(T x) -{ - return x; -} -# define TYPEOF(x) decltype(decltype_helper(x)) -# else -# define TYPEOF(x) typeof(x) -# endif -#endif - -/* Causes warning: - * incompatible types when assigning to type 'Foo' from type 'Bar' - * ... the compiler optimizes away the temp var */ -#ifdef __GNUC__ -# define CHECK_TYPE(var, type) \ - { \ - TYPEOF(var) * __tmp; \ - __tmp = (type *)NULL; \ - (void)__tmp; \ - } \ - (void)0 - -# define CHECK_TYPE_PAIR(var_a, var_b) \ - { \ - TYPEOF(var_a) * __tmp; \ - __tmp = (typeof(var_b) *)NULL; \ - (void)__tmp; \ - } \ - (void)0 -#else -# define CHECK_TYPE(var, type) -# define CHECK_TYPE_PAIR(var_a, var_b) -#endif - -/* can be used in simple macros */ -#define CHECK_TYPE_INLINE(val, type) ((void)(((type)0) != (val))) - #ifndef __KERNEL_GPU__ # include <cassert> # define util_assert(statement) assert(statement) diff --git a/intern/cycles/util/hash.h b/intern/cycles/util/hash.h index 081b33025d8..4f83f331229 100644 --- a/intern/cycles/util/hash.h +++ b/intern/cycles/util/hash.h @@ -4,10 +4,28 @@ #ifndef __UTIL_HASH_H__ #define __UTIL_HASH_H__ +#include "util/math.h" #include "util/types.h" CCL_NAMESPACE_BEGIN +/* [0, uint_max] -> [0.0, 1.0) */ +ccl_device_forceinline float uint_to_float_excl(uint n) +{ + // Note: we divide by 4294967808 instead of 2^32 because the latter + // leads to a [0.0, 1.0] mapping instead of [0.0, 1.0) due to floating + // point rounding error. 4294967808 unfortunately leaves (precisely) + // one unused ulp between the max number this outputs and 1.0, but + // that's the best you can do with this construction. + return (float)n * (1.0f / 4294967808.0f); +} + +/* [0, uint_max] -> [0.0, 1.0] */ +ccl_device_forceinline float uint_to_float_incl(uint n) +{ + return (float)n * (1.0f / (float)0xFFFFFFFFu); +} + /* ***** Jenkins Lookup3 Hash Functions ***** */ /* Source: http://burtleburtle.net/bob/c/lookup3.c */ @@ -116,22 +134,22 @@ ccl_device_inline uint hash_uint4(uint kx, uint ky, uint kz, uint kw) ccl_device_inline float hash_uint_to_float(uint kx) { - return (float)hash_uint(kx) / (float)0xFFFFFFFFu; + return uint_to_float_incl(hash_uint(kx)); } ccl_device_inline float hash_uint2_to_float(uint kx, uint ky) { - return (float)hash_uint2(kx, ky) / (float)0xFFFFFFFFu; + return uint_to_float_incl(hash_uint2(kx, ky)); } ccl_device_inline float hash_uint3_to_float(uint kx, uint ky, uint kz) { - return (float)hash_uint3(kx, ky, kz) / (float)0xFFFFFFFFu; + return uint_to_float_incl(hash_uint3(kx, ky, kz)); } ccl_device_inline float hash_uint4_to_float(uint kx, uint ky, uint kz, uint kw) { - return (float)hash_uint4(kx, ky, kz, kw) / (float)0xFFFFFFFFu; + return uint_to_float_incl(hash_uint4(kx, ky, kz, kw)); } /* Hashing float or float[234] into a float in the range [0, 1]. */ @@ -359,6 +377,123 @@ ccl_device_inline avxi hash_avxi4(avxi kx, avxi ky, avxi kz, avxi kw) #endif +/* ***** Hash Prospector Hash Functions ***** + * + * These are based on the high-quality 32-bit hash/mixing functions from + * https://github.com/skeeto/hash-prospector + */ + +ccl_device_inline uint hash_hp_uint(uint i) +{ + // The actual mixing function from Hash Prospector. + i ^= i >> 16; + i *= 0x21f0aaad; + i ^= i >> 15; + i *= 0xd35a2d97; + i ^= i >> 15; + + // The xor is just to make input zero not map to output zero. + // The number is randomly selected and isn't special. + return i ^ 0xe6fe3beb; +} + +/* Seedable version of hash_hp_uint() above. */ +ccl_device_inline uint hash_hp_seeded_uint(uint i, uint seed) +{ + // Manipulate the seed so it doesn't interact poorly with n when they + // are both e.g. incrementing. This isn't fool-proof, but is good + // enough for practical use. + seed ^= seed << 19; + + return hash_hp_uint(i ^ seed); +} + +/* Outputs [0.0, 1.0). */ +ccl_device_inline float hash_hp_float(uint i) +{ + return uint_to_float_excl(hash_hp_uint(i)); +} + +/* Outputs [0.0, 1.0). */ +ccl_device_inline float hash_hp_seeded_float(uint i, uint seed) +{ + return uint_to_float_excl(hash_hp_seeded_uint(i, seed)); +} + +/* ***** Modified Wang Hash Functions ***** + * + * These are based on a bespoke modified version of the Wang hash, and + * can serve as a faster hash when quality isn't critical. + * + * The original Wang hash is documented here: + * https://www.burtleburtle.net/bob/hash/integer.html + */ + +ccl_device_inline uint hash_wang_seeded_uint(uint i, uint seed) +{ + i = (i ^ 61) ^ seed; + i += i << 3; + i ^= i >> 4; + i *= 0x27d4eb2d; + return i; +} + +/* Outputs [0.0, 1.0). */ +ccl_device_inline float hash_wang_seeded_float(uint i, uint seed) +{ + return uint_to_float_excl(hash_wang_seeded_uint(i, seed)); +} + +/* ***** Index Shuffling Hash Function ***** + * + * This function takes an index, the length of the thing the index points + * into, and returns a shuffled index. For example, if you pass indices + * 0 through 19 to this function with a length parameter of 20, it will + * return the indices in a shuffled order with no repeats. Indices + * larger than the length parameter will simply repeat the same shuffled + * pattern over and over. + * + * This is useful for iterating over an array in random shuffled order + * without having to shuffle the array itself. + * + * Passing different seeds results in different random shuffles. + * + * This function runs in average O(1) time. + * + * See https://andrew-helmer.github.io/permute/ for details on how this + * works. + */ +ccl_device_inline uint hash_shuffle_uint(uint i, uint length, uint seed) +{ + i = i % length; + uint mask = (1 << (32 - count_leading_zeros(length - 1))) - 1; + + do { + i ^= seed; + i *= 0xe170893d; + i ^= seed >> 16; + i ^= (i & mask) >> 4; + i ^= seed >> 8; + i *= 0x0929eb3f; + i ^= seed >> 23; + i ^= (i & mask) >> 1; + i *= 1 | seed >> 27; + i *= 0x6935fa69; + i ^= (i & mask) >> 11; + i *= 0x74dcb303; + i ^= (i & mask) >> 2; + i *= 0x9e501cc3; + i ^= (i & mask) >> 2; + i *= 0xc860a3df; + i &= mask; + i ^= i >> 5; + } while (i >= length); + + return i; +} + +/* ********** */ + #ifndef __KERNEL_GPU__ static inline uint hash_string(const char *str) { diff --git a/intern/cycles/util/math.h b/intern/cycles/util/math.h index 0585dcc8ad5..0905b3ec5c9 100644 --- a/intern/cycles/util/math.h +++ b/intern/cycles/util/math.h @@ -886,16 +886,16 @@ ccl_device_inline float2 map_to_tube(const float3 co) ccl_device_inline float2 map_to_sphere(const float3 co) { - float l = len(co); + float l = dot(co, co); float u, v; if (l > 0.0f) { if (UNLIKELY(co.x == 0.0f && co.y == 0.0f)) { u = 0.0f; /* Otherwise domain error. */ } else { - u = (1.0f - atan2f(co.x, co.y) / M_PI_F) / 2.0f; + u = (0.5f - atan2f(co.x, co.y) * M_1_2PI_F); } - v = 1.0f - safe_acosf(co.z / l) / M_PI_F; + v = 1.0f - safe_acosf(co.z / sqrtf(l)) * M_1_PI_F; } else { u = v = 0.0f; diff --git a/intern/cycles/util/opengl.h b/intern/cycles/util/opengl.h index 090deb861c4..fefee4ec022 100644 --- a/intern/cycles/util/opengl.h +++ b/intern/cycles/util/opengl.h @@ -7,6 +7,6 @@ /* OpenGL header includes, used everywhere we use OpenGL, to deal with * platform differences in one central place. */ -#include <GL/glew.h> +#include <epoxy/gl.h> #endif /* __UTIL_OPENGL_H__ */ diff --git a/intern/cycles/util/version.h b/intern/cycles/util/version.h index 8260dd4f55d..fb02c3eaeb7 100644 --- a/intern/cycles/util/version.h +++ b/intern/cycles/util/version.h @@ -9,7 +9,7 @@ CCL_NAMESPACE_BEGIN #define CYCLES_VERSION_MAJOR 3 -#define CYCLES_VERSION_MINOR 2 +#define CYCLES_VERSION_MINOR 4 #define CYCLES_VERSION_PATCH 0 #define CYCLES_MAKE_VERSION_STRING2(a, b, c) #a "." #b "." #c @@ -19,7 +19,7 @@ CCL_NAMESPACE_BEGIN /* Blender libraries version compatible with this version */ -#define CYCLES_BLENDER_LIBRARIES_VERSION 3.1 +#define CYCLES_BLENDER_LIBRARIES_VERSION 3.3 CCL_NAMESPACE_END |