Fix Cycles Metal build error and GCC warning after recent changes

Function overloading of make_float4() doesn't work since it's a macro, just
don't do this minor cleanup then.
This commit is contained in:
Brecht Van Lommel
2022-03-23 22:46:17 +01:00
parent d84b4becd3
commit 51380b9346
5 changed files with 30 additions and 38 deletions

View File

@@ -220,7 +220,7 @@ ccl_device_inline void hair_attenuation(KernelGlobals kg,
ccl_private float4 *Ap) ccl_private float4 *Ap)
{ {
/* Primary specular (R). */ /* Primary specular (R). */
Ap[0] = make_float4(f); Ap[0] = make_float4(f, f, f, f);
/* Transmission (TT). */ /* Transmission (TT). */
float3 col = sqr(1.0f - f) * T; float3 col = sqr(1.0f - f) * T;

View File

@@ -31,20 +31,18 @@ ccl_device_inline float frac(float x, int *ix)
return x - (float)i; return x - (float)i;
} }
template<typename ZeroT> ccl_always_inline ZeroT zero();
template<> ccl_always_inline float zero<float>()
{
return 0.0f;
}
template<> ccl_always_inline float4 zero<float4>()
{
return zero_float4();
}
template<typename TexT, typename OutT = float4> struct TextureInterpolator { template<typename TexT, typename OutT = float4> struct TextureInterpolator {
static ccl_always_inline OutT zero()
{
if constexpr (std::is_same<OutT, float4>::value) {
return zero_float4();
}
else {
return 0.0f;
}
}
static ccl_always_inline float4 read(float4 r) static ccl_always_inline float4 read(float4 r)
{ {
return r; return r;
@@ -99,7 +97,7 @@ template<typename TexT, typename OutT = float4> struct TextureInterpolator {
static ccl_always_inline OutT read_clip(const TexT *data, int x, int y, int width, int height) static ccl_always_inline OutT read_clip(const TexT *data, int x, int y, int width, int height)
{ {
if (x < 0 || x >= width || y < 0 || y >= height) { if (x < 0 || x >= width || y < 0 || y >= height) {
return zero<OutT>(); return zero();
} }
return read(data[y * width + x]); return read(data[y * width + x]);
} }
@@ -118,7 +116,7 @@ template<typename TexT, typename OutT = float4> struct TextureInterpolator {
read_clip(const TexT *data, int x, int y, int z, int width, int height, int depth) read_clip(const TexT *data, int x, int y, int z, int width, int height, int depth)
{ {
if (x < 0 || x >= width || y < 0 || y >= height || z < 0 || z >= depth) { if (x < 0 || x >= width || y < 0 || y >= height || z < 0 || z >= depth) {
return zero<OutT>(); return zero();
} }
return read(data[x + y * width + z * width * height]); return read(data[x + y * width + z * width * height]);
} }
@@ -221,7 +219,7 @@ template<typename TexT, typename OutT = float4> struct TextureInterpolator {
case EXTENSION_CLIP: case EXTENSION_CLIP:
/* No samples are inside the clip region. */ /* No samples are inside the clip region. */
if (ix < 0 || ix >= width || iy < 0 || iy >= height) { if (ix < 0 || ix >= width || iy < 0 || iy >= height) {
return zero<OutT>(); return zero();
} }
break; break;
case EXTENSION_EXTEND: case EXTENSION_EXTEND:
@@ -230,7 +228,7 @@ template<typename TexT, typename OutT = float4> struct TextureInterpolator {
break; break;
default: default:
kernel_assert(0); kernel_assert(0);
return zero<OutT>(); return zero();
} }
const TexT *data = (const TexT *)info.data; const TexT *data = (const TexT *)info.data;
@@ -259,7 +257,7 @@ template<typename TexT, typename OutT = float4> struct TextureInterpolator {
case EXTENSION_CLIP: case EXTENSION_CLIP:
/* No linear samples are inside the clip region. */ /* No linear samples are inside the clip region. */
if (ix < -1 || ix >= width || iy < -1 || iy >= height) { if (ix < -1 || ix >= width || iy < -1 || iy >= height) {
return zero<OutT>(); return zero();
} }
nix = ix + 1; nix = ix + 1;
niy = iy + 1; niy = iy + 1;
@@ -272,7 +270,7 @@ template<typename TexT, typename OutT = float4> struct TextureInterpolator {
break; break;
default: default:
kernel_assert(0); kernel_assert(0);
return zero<OutT>(); return zero();
} }
const TexT *data = (const TexT *)info.data; const TexT *data = (const TexT *)info.data;
@@ -311,7 +309,7 @@ template<typename TexT, typename OutT = float4> struct TextureInterpolator {
case EXTENSION_CLIP: case EXTENSION_CLIP:
/* No cubic samples are inside the clip region. */ /* No cubic samples are inside the clip region. */
if (ix < -2 || ix > width || iy < -2 || iy > height) { if (ix < -2 || ix > width || iy < -2 || iy > height) {
return zero<OutT>(); return zero();
} }
pix = ix - 1; pix = ix - 1;
@@ -335,7 +333,7 @@ template<typename TexT, typename OutT = float4> struct TextureInterpolator {
break; break;
default: default:
kernel_assert(0); kernel_assert(0);
return zero<OutT>(); return zero();
} }
const TexT *data = (const TexT *)info.data; const TexT *data = (const TexT *)info.data;
@@ -397,7 +395,7 @@ template<typename TexT, typename OutT = float4> struct TextureInterpolator {
case EXTENSION_CLIP: case EXTENSION_CLIP:
/* No samples are inside the clip region. */ /* No samples are inside the clip region. */
if (ix < 0 || ix >= width || iy < 0 || iy >= height || iz < 0 || iz >= depth) { if (ix < 0 || ix >= width || iy < 0 || iy >= height || iz < 0 || iz >= depth) {
return zero<OutT>(); return zero();
} }
break; break;
case EXTENSION_EXTEND: case EXTENSION_EXTEND:
@@ -407,7 +405,7 @@ template<typename TexT, typename OutT = float4> struct TextureInterpolator {
break; break;
default: default:
kernel_assert(0); kernel_assert(0);
return zero<OutT>(); return zero();
} }
const TexT *data = (const TexT *)info.data; const TexT *data = (const TexT *)info.data;
@@ -444,7 +442,7 @@ template<typename TexT, typename OutT = float4> struct TextureInterpolator {
case EXTENSION_CLIP: case EXTENSION_CLIP:
/* No linear samples are inside the clip region. */ /* No linear samples are inside the clip region. */
if (ix < -1 || ix >= width || iy < -1 || iy >= height || iz < -1 || iz >= depth) { if (ix < -1 || ix >= width || iy < -1 || iy >= height || iz < -1 || iz >= depth) {
return zero<OutT>(); return zero();
} }
nix = ix + 1; nix = ix + 1;
@@ -484,7 +482,7 @@ template<typename TexT, typename OutT = float4> struct TextureInterpolator {
break; break;
default: default:
kernel_assert(0); kernel_assert(0);
return zero<OutT>(); return zero();
} }
return trilinear_lookup((const TexT *)info.data, return trilinear_lookup((const TexT *)info.data,
@@ -553,7 +551,7 @@ template<typename TexT, typename OutT = float4> struct TextureInterpolator {
case EXTENSION_CLIP: { case EXTENSION_CLIP: {
/* No cubic samples are inside the clip region. */ /* No cubic samples are inside the clip region. */
if (ix < -2 || ix > width || iy < -2 || iy > height || iz < -2 || iz > depth) { if (ix < -2 || ix > width || iy < -2 || iy > height || iz < -2 || iz > depth) {
return zero<OutT>(); return zero();
} }
pix = ix - 1; pix = ix - 1;
@@ -599,7 +597,7 @@ template<typename TexT, typename OutT = float4> struct TextureInterpolator {
break; break;
default: default:
kernel_assert(0); kernel_assert(0);
return zero<OutT>(); return zero();
} }
const int xc[4] = {pix, ix, nix, nnix}; const int xc[4] = {pix, ix, nix, nnix};
const int yc[4] = {piy, iy, niy, nniy}; const int yc[4] = {piy, iy, niy, nniy};

View File

@@ -90,13 +90,13 @@ ccl_device_inline float4 zero_float4()
#ifdef __KERNEL_SSE__ #ifdef __KERNEL_SSE__
return float4(_mm_setzero_ps()); return float4(_mm_setzero_ps());
#else #else
return make_float4(0.0f); return make_float4(0.0f, 0.0f, 0.0f, 0.0f);
#endif #endif
} }
ccl_device_inline float4 one_float4() ccl_device_inline float4 one_float4()
{ {
return make_float4(1.0f); return make_float4(1.0f, 1.0f, 1.0f, 1.0f);
} }
#if !defined(__KERNEL_METAL__) #if !defined(__KERNEL_METAL__)
@@ -149,7 +149,7 @@ ccl_device_inline float4 operator/(const float4 &a, const float4 &b)
ccl_device_inline float4 operator+(const float4 &a, const float f) ccl_device_inline float4 operator+(const float4 &a, const float f)
{ {
return a + make_float4(f); return a + make_float4(f, f, f, f);
} }
ccl_device_inline float4 operator+(const float4 &a, const float4 &b) ccl_device_inline float4 operator+(const float4 &a, const float4 &b)
@@ -163,7 +163,7 @@ ccl_device_inline float4 operator+(const float4 &a, const float4 &b)
ccl_device_inline float4 operator-(const float4 &a, const float f) ccl_device_inline float4 operator-(const float4 &a, const float f)
{ {
return a - make_float4(f); return a - make_float4(f, f, f, f);
} }
ccl_device_inline float4 operator-(const float4 &a, const float4 &b) ccl_device_inline float4 operator-(const float4 &a, const float4 &b)
@@ -317,7 +317,7 @@ ccl_device_inline float4 reduce_add(const float4 &a)
# endif # endif
# else # else
float sum = (a.x + a.y) + (a.z + a.w); float sum = (a.x + a.y) + (a.z + a.w);
return make_float4(sum); return make_float4(sum, sum, sum, sum);
# endif # endif
} }

View File

@@ -45,7 +45,6 @@ ccl_device_inline float4 make_float4(const int4 &i);
ccl_device_inline void print_float4(const char *label, const float4 &a); ccl_device_inline void print_float4(const char *label, const float4 &a);
#endif /* __KERNEL_GPU__ */ #endif /* __KERNEL_GPU__ */
ccl_device_inline float4 make_float4(float f);
CCL_NAMESPACE_END CCL_NAMESPACE_END
#endif /* __UTIL_TYPES_FLOAT4_H__ */ #endif /* __UTIL_TYPES_FLOAT4_H__ */

View File

@@ -89,11 +89,6 @@ ccl_device_inline void print_float4(const char *label, const float4 &a)
{ {
printf("%s: %.8f %.8f %.8f %.8f\n", label, (double)a.x, (double)a.y, (double)a.z, (double)a.w); printf("%s: %.8f %.8f %.8f %.8f\n", label, (double)a.x, (double)a.y, (double)a.z, (double)a.w);
} }
#else
ccl_device_inline float4 make_float4(float f)
{
return make_float4(f, f, f, f);
}
#endif /* __KERNEL_GPU__ */ #endif /* __KERNEL_GPU__ */
CCL_NAMESPACE_END CCL_NAMESPACE_END