diff --git a/pxr/imaging/plugin/hdEmbree/pxrIES/README.md b/pxr/imaging/plugin/hdEmbree/pxrIES/README.md new file mode 100644 index 0000000000..ae97b47b0c --- /dev/null +++ b/pxr/imaging/plugin/hdEmbree/pxrIES/README.md @@ -0,0 +1,31 @@ +# IES utilities + +Utilities for reading and using .ies files (IESNA LM-63 Format), which are used +to describe lights. + +The files `ies.h` and `ies.cpp` are originally from +[Cycles](https://docs.blender.org/manual/en/latest/render/cycles/index.html), +which is part of the larger +[Blender](https://projects.blender.org/blender/blender/) project, though with +a the less restrictive Apache 2.0 license - see: + +- https://www.blender.org/about/license/ + +## Version + +v4.1.1 ( 53c49589f311bd3c9e3ea8f62b3fa8fe8e5d2c8c ) + +## Setup + +When updating IES, the following steps should be followed: + +1. Copy `intern/cycles/util/ies.h` and `intern/cycles/util/ies.cpp` over the + copies in `pxr/imaging/plugin/hdEmbree/pxrIES`. +2. Apply `pxr-IES.patch` to update the source files with modifications for USD, + ie, from the USD repo root folder: + + ```sh + patch -p1 -i pxr/imaging/plugin/hdEmbree/pxrIES/pxr-IES.patch + ``` +3. Commit your changes, noting the exact version of blender that the new ies + files were copied from. \ No newline at end of file diff --git a/pxr/imaging/plugin/hdEmbree/pxrIES/ies.cpp b/pxr/imaging/plugin/hdEmbree/pxrIES/ies.cpp index a6725cc049..7a6917303c 100644 --- a/pxr/imaging/plugin/hdEmbree/pxrIES/ies.cpp +++ b/pxr/imaging/plugin/hdEmbree/pxrIES/ies.cpp @@ -2,21 +2,22 @@ * * SPDX-License-Identifier: Apache-2.0 */ +#include "ies.h" #include +#include -#include "util/foreach.h" -#include "util/ies.h" -#include "util/math.h" -#include "util/string.h" +#define _USE_MATH_DEFINES +#include -CCL_NAMESPACE_BEGIN +#if !defined(M_PI) +#define M_PI 3.14159265358979323846 +#endif -// NOTE: For some reason gcc-7.2 does not instantiate this version of the -// allocator here (used in IESTextParser). Works fine for gcc-6, gcc-7.3 and gcc-8. -// -// TODO(sergey): Get to the root of this issue, or confirm this is a compiler -// issue. -template class GuardedAllocator; +#define M_PI_F M_PI + +PXR_NAMESPACE_OPEN_SCOPE + +namespace pxr_ccl { bool IESFile::load(const string &ies) { @@ -43,11 +44,28 @@ int IESFile::packed_size() return 0; } +template +std::enable_if_t && + std::is_trivially_copyable_v, + To> +// constexpr support needs compiler magic +bit_cast(const From &src) noexcept +{ + static_assert(std::is_trivially_constructible_v, + "This implementation additionally requires " + "destination type to be trivially constructible"); + + To dst; + std::memcpy(&dst, &src, sizeof(To)); + return dst; +} + void IESFile::pack(float *data) { if (v_angles.size() && h_angles.size()) { - *(data++) = __int_as_float(h_angles.size()); - *(data++) = __int_as_float(v_angles.size()); + *(data++) = bit_cast(static_cast(h_angles.size())); + *(data++) = bit_cast(static_cast(v_angles.size())); memcpy(data, &h_angles[0], h_angles.size() * sizeof(float)); data += h_angles.size(); @@ -407,4 +425,7 @@ IESFile::~IESFile() clear(); } -CCL_NAMESPACE_END +} // namespace pxr_ccl + +PXR_NAMESPACE_CLOSE_SCOPE + diff --git a/pxr/imaging/plugin/hdEmbree/pxrIES/ies.h b/pxr/imaging/plugin/hdEmbree/pxrIES/ies.h index 8c506befdd..051c23f6c4 100644 --- a/pxr/imaging/plugin/hdEmbree/pxrIES/ies.h +++ b/pxr/imaging/plugin/hdEmbree/pxrIES/ies.h @@ -5,10 +5,18 @@ #ifndef __UTIL_IES_H__ #define __UTIL_IES_H__ -#include "util/string.h" -#include "util/vector.h" +#include +#include + +using std::string; +using std::vector; + +#include "pxr/pxr.h" + +PXR_NAMESPACE_OPEN_SCOPE + +namespace pxr_ccl { -CCL_NAMESPACE_BEGIN class IESFile { public: @@ -19,11 +27,16 @@ class IESFile { void pack(float *data); bool load(const string &ies); + + virtual void clear(); protected: bool parse(const string &ies); + + virtual bool process(); + void process_type_a(); void process_type_b(); void process_type_c(); @@ -41,6 +54,8 @@ class IESFile { enum IESType { TYPE_A = 3, TYPE_B = 2, TYPE_C = 1 } type; }; -CCL_NAMESPACE_END +} // namespace pxr_ccl + +PXR_NAMESPACE_CLOSE_SCOPE #endif /* __UTIL_IES_H__ */ diff --git a/pxr/imaging/plugin/hdEmbree/pxrIES/pxr-IES.patch b/pxr/imaging/plugin/hdEmbree/pxrIES/pxr-IES.patch new file mode 100644 index 0000000000..acef74a69b --- /dev/null +++ b/pxr/imaging/plugin/hdEmbree/pxrIES/pxr-IES.patch @@ -0,0 +1,131 @@ +diff --git a/pxr/imaging/plugin/hdEmbree/pxrIES/ies.cpp b/pxr/imaging/plugin/hdEmbree/pxrIES/ies.cpp +index a6725cc04..7a6917303 100644 +--- a/pxr/imaging/plugin/hdEmbree/pxrIES/ies.cpp ++++ b/pxr/imaging/plugin/hdEmbree/pxrIES/ies.cpp +@@ -2,21 +2,22 @@ + * + * SPDX-License-Identifier: Apache-2.0 */ + ++#include "ies.h" + #include ++#include + +-#include "util/foreach.h" +-#include "util/ies.h" +-#include "util/math.h" +-#include "util/string.h" ++#define _USE_MATH_DEFINES ++#include + +-CCL_NAMESPACE_BEGIN ++#if !defined(M_PI) ++#define M_PI 3.14159265358979323846 ++#endif + +-// NOTE: For some reason gcc-7.2 does not instantiate this version of the +-// allocator here (used in IESTextParser). Works fine for gcc-6, gcc-7.3 and gcc-8. +-// +-// TODO(sergey): Get to the root of this issue, or confirm this is a compiler +-// issue. +-template class GuardedAllocator; ++#define M_PI_F M_PI ++ ++PXR_NAMESPACE_OPEN_SCOPE ++ ++namespace pxr_ccl { + + bool IESFile::load(const string &ies) + { +@@ -43,11 +44,28 @@ int IESFile::packed_size() + return 0; + } + ++template ++std::enable_if_t && ++ std::is_trivially_copyable_v, ++ To> ++// constexpr support needs compiler magic ++bit_cast(const From &src) noexcept ++{ ++ static_assert(std::is_trivially_constructible_v, ++ "This implementation additionally requires " ++ "destination type to be trivially constructible"); ++ ++ To dst; ++ std::memcpy(&dst, &src, sizeof(To)); ++ return dst; ++} ++ + void IESFile::pack(float *data) + { + if (v_angles.size() && h_angles.size()) { +- *(data++) = __int_as_float(h_angles.size()); +- *(data++) = __int_as_float(v_angles.size()); ++ *(data++) = bit_cast(static_cast(h_angles.size())); ++ *(data++) = bit_cast(static_cast(v_angles.size())); + + memcpy(data, &h_angles[0], h_angles.size() * sizeof(float)); + data += h_angles.size(); +@@ -407,4 +425,7 @@ IESFile::~IESFile() + clear(); + } + +-CCL_NAMESPACE_END ++} // namespace pxr_ccl ++ ++PXR_NAMESPACE_CLOSE_SCOPE ++ +diff --git a/pxr/imaging/plugin/hdEmbree/pxrIES/ies.h b/pxr/imaging/plugin/hdEmbree/pxrIES/ies.h +index 8c506befd..051c23f6c 100644 +--- a/pxr/imaging/plugin/hdEmbree/pxrIES/ies.h ++++ b/pxr/imaging/plugin/hdEmbree/pxrIES/ies.h +@@ -5,10 +5,18 @@ + #ifndef __UTIL_IES_H__ + #define __UTIL_IES_H__ + +-#include "util/string.h" +-#include "util/vector.h" ++#include ++#include ++ ++using std::string; ++using std::vector; ++ ++#include "pxr/pxr.h" ++ ++PXR_NAMESPACE_OPEN_SCOPE ++ ++namespace pxr_ccl { + +-CCL_NAMESPACE_BEGIN + + class IESFile { + public: +@@ -19,11 +27,16 @@ class IESFile { + void pack(float *data); + + bool load(const string &ies); ++ ++ virtual + void clear(); + + protected: + bool parse(const string &ies); ++ ++ virtual + bool process(); ++ + void process_type_a(); + void process_type_b(); + void process_type_c(); +@@ -41,6 +54,8 @@ class IESFile { + enum IESType { TYPE_A = 3, TYPE_B = 2, TYPE_C = 1 } type; + }; + +-CCL_NAMESPACE_END ++} // namespace pxr_ccl ++ ++PXR_NAMESPACE_CLOSE_SCOPE + + #endif /* __UTIL_IES_H__ */