Skip to content

Commit 76451af

Browse files
authored
fmath.h: re-inline convert_type() half varieties (#5130)
A few years ago, in PR #3301, we made a big effort to remove Imath types as much as possible from the public APIs. Somehow, as part of that refactor, we ended up with just the half-varieties of fmath.h's convert_types() templates actually being implemented in fmath.cpp and only declared (by default) in fmath.h. I'm honestly not sure why I did that now, and the PR doesn't explain that particular point. But that sets up a potential link incompatibility if OIIO used a different release of Imath than the use is using when calling that utility function. So this PR makes it fully inline again, so the Imath version the downstream package uses just doesn't need to match what was found/used at the time that OIIO was built. Signed-off-by: Larry Gritz <lg@larrygritz.com>
1 parent 235e364 commit 76451af

3 files changed

Lines changed: 6 additions & 30 deletions

File tree

src/include/OpenImageIO/fmath.h

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -911,20 +911,11 @@ convert_type<float,uint8_t> (const float *src, uint8_t *dst, size_t n,
911911

912912

913913
#if defined(_HALF_H_) || defined(IMATH_HALF_H_)
914+
// Specialize for half only if half.h is included prior to fmath.h
914915
template<>
915-
OIIO_UTIL_API
916-
void convert_type<half,float> (const half *src, float *dst, size_t n,
917-
float /*_min*/, float /*_max*/);
918-
template<>
919-
OIIO_UTIL_API
920-
void convert_type<float,half> (const float *src, half *dst, size_t n,
921-
half /*_min*/, half /*_max*/);
922-
923-
#if OIIO_FMATH_HEADER_ONLY
924-
// Not just the declarations, give the definitions here.
925-
template<>
926-
void convert_type<half,float> (const half *src, float *dst, size_t n,
927-
float /*_min*/, float /*_max*/)
916+
inline void
917+
convert_type<half,float> (const half *src, float *dst, size_t n,
918+
float /*_min*/, float /*_max*/)
928919
{
929920
#if OIIO_SIMD >= 8 && OIIO_F16C_ENABLED
930921
// If f16c ops are enabled, it's worth doing this by 8's
@@ -944,7 +935,7 @@ void convert_type<half,float> (const half *src, float *dst, size_t n,
944935
}
945936

946937
template<>
947-
void
938+
inline void
948939
convert_type<float,half> (const float *src, half *dst, size_t n,
949940
half /*_min*/, half /*_max*/)
950941
{
@@ -964,7 +955,6 @@ convert_type<float,half> (const float *src, half *dst, size_t n,
964955
while (n--)
965956
*dst++ = *src++;
966957
}
967-
#endif /* if OIIO_FMATH_HEADER_ONLY */
968958
#endif /* if defined(IMATH_HALF_H_) */
969959

970960
#endif /* ifndef __CUDA_ARCH__ */

src/libutil/CMakeLists.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
set (libOpenImageIO_Util_srcs argparse.cpp benchmark.cpp
66
errorhandler.cpp farmhash.cpp filesystem.cpp
7-
fmath.cpp filter.cpp hashes.cpp paramlist.cpp
7+
filter.cpp hashes.cpp paramlist.cpp
88
plugin.cpp SHA1.cpp
99
strutil.cpp sysutil.cpp thread.cpp timer.cpp
1010
typedesc.cpp ustring.cpp xxhash.cpp)
@@ -15,9 +15,6 @@ if (CMAKE_COMPILER_IS_GNUCC)
1515
endif ()
1616

1717
if (CMAKE_UNITY_BUILD)
18-
# If unity builds are occurring, fmath.cpp MUST be compiled alone. But the
19-
# rest can be built together if in group mode.
20-
set_property (SOURCE fmath.cpp APPEND PROPERTY SKIP_UNITY_BUILD_INCLUSION TRUE)
2118
set_source_files_properties (${libOpenImageIO_Util_srcs}
2219
PROPERTIES UNITY_GROUP utilsrc)
2320
endif ()

src/libutil/fmath.cpp

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)