From 3525a4d800e96e665fe91ce25eb3217d92007750 Mon Sep 17 00:00:00 2001 From: Paul Molodowitch Date: Wed, 22 May 2024 12:22:37 -0700 Subject: [PATCH] [hdEmbree] ies.h / ies.cpp: patch, and add pxr-IES.patch and README.md --- pxr/imaging/plugin/hdEmbree/pxrIES/README.md | 32 +++++ pxr/imaging/plugin/hdEmbree/pxrIES/ies.cpp | 44 +++++-- pxr/imaging/plugin/hdEmbree/pxrIES/ies.h | 25 +++- .../plugin/hdEmbree/pxrIES/pxr-IES.patch | 123 ++++++++++++++++++ 4 files changed, 203 insertions(+), 21 deletions(-) create mode 100644 pxr/imaging/plugin/hdEmbree/pxrIES/README.md create mode 100644 pxr/imaging/plugin/hdEmbree/pxrIES/pxr-IES.patch diff --git a/pxr/imaging/plugin/hdEmbree/pxrIES/README.md b/pxr/imaging/plugin/hdEmbree/pxrIES/README.md new file mode 100644 index 0000000000..307db52715 --- /dev/null +++ b/pxr/imaging/plugin/hdEmbree/pxrIES/README.md @@ -0,0 +1,32 @@ +# 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://www.cycles-renderer.org/), a path-traced renderer that is a +spinoff of the larger [Blender](https://projects.blender.org/blender/blender/) +project, though available with in own repository, and via the Apache 2.0 +license: + +- https://projects.blender.org/blender/cycles +- https://projects.blender.org/blender/cycles/src/branch/main/LICENSE + +## Version + +v4.1.1 ( 234fa733d30a0e49cd10b2c92091500103a1150a ) + +## Setup + +When updating IES, the following steps should be followed: + +1. Copy `src/util/ies.h` and `src/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..243680d918 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,23 @@ int IESFile::packed_size() return 0; } + +static float sizet_to_float(const size_t source_size_t) noexcept +{ + int intermediate_int = static_cast(source_size_t); + float dest_float; + + static_assert(sizeof(intermediate_int) == sizeof(dest_float), + "Size of source and destination for memcpy must be identical"); + std::memcpy(&dest_float, &intermediate_int, sizeof(float)); + return dest_float; +} + 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++) = sizet_to_float(h_angles.size()); + *(data++) = sizet_to_float(v_angles.size()); memcpy(data, &h_angles[0], h_angles.size() * sizeof(float)); data += h_angles.size(); @@ -407,4 +420,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..0bbae712ff 100644 --- a/pxr/imaging/plugin/hdEmbree/pxrIES/ies.h +++ b/pxr/imaging/plugin/hdEmbree/pxrIES/ies.h @@ -2,13 +2,21 @@ * * SPDX-License-Identifier: Apache-2.0 */ -#ifndef __UTIL_IES_H__ -#define __UTIL_IES_H__ +#ifndef PXR_IMAGING_PLUGIN_HD_EMBREE_PXRIES_IES_H +#define PXR_IMAGING_PLUGIN_HD_EMBREE_PXRIES_IES_H -#include "util/string.h" -#include "util/vector.h" -CCL_NAMESPACE_BEGIN +#include +#include + +#include "pxr/pxr.h" + +PXR_NAMESPACE_OPEN_SCOPE + +namespace pxr_ccl { + +using std::string; +using std::vector; class IESFile { public: @@ -24,6 +32,7 @@ class IESFile { protected: bool parse(const string &ies); bool process(); + void process_type_a(); void process_type_b(); void process_type_c(); @@ -41,6 +50,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__ */ +#endif /* PXR_IMAGING_PLUGIN_HD_EMBREE_PXRIES_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..50f8ead381 --- /dev/null +++ b/pxr/imaging/plugin/hdEmbree/pxrIES/pxr-IES.patch @@ -0,0 +1,123 @@ +diff --git a/pxr/imaging/plugin/hdEmbree/pxrIES/ies.cpp b/pxr/imaging/plugin/hdEmbree/pxrIES/ies.cpp +index a6725cc04..243680d91 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,23 @@ int IESFile::packed_size() + return 0; + } + ++ ++static float sizet_to_float(const size_t source_size_t) noexcept ++{ ++ int intermediate_int = static_cast(source_size_t); ++ float dest_float; ++ ++ static_assert(sizeof(intermediate_int) == sizeof(dest_float), ++ "Size of source and destination for memcpy must be identical"); ++ std::memcpy(&dest_float, &intermediate_int, sizeof(float)); ++ return dest_float; ++} ++ + 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++) = sizet_to_float(h_angles.size()); ++ *(data++) = sizet_to_float(v_angles.size()); + + memcpy(data, &h_angles[0], h_angles.size() * sizeof(float)); + data += h_angles.size(); +@@ -407,4 +420,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..0bbae712f 100644 +--- a/pxr/imaging/plugin/hdEmbree/pxrIES/ies.h ++++ b/pxr/imaging/plugin/hdEmbree/pxrIES/ies.h +@@ -2,13 +2,21 @@ + * + * SPDX-License-Identifier: Apache-2.0 */ + +-#ifndef __UTIL_IES_H__ +-#define __UTIL_IES_H__ ++#ifndef PXR_IMAGING_PLUGIN_HD_EMBREE_PXRIES_IES_H ++#define PXR_IMAGING_PLUGIN_HD_EMBREE_PXRIES_IES_H + +-#include "util/string.h" +-#include "util/vector.h" + +-CCL_NAMESPACE_BEGIN ++#include ++#include ++ ++#include "pxr/pxr.h" ++ ++PXR_NAMESPACE_OPEN_SCOPE ++ ++namespace pxr_ccl { ++ ++using std::string; ++using std::vector; + + class IESFile { + public: +@@ -24,6 +32,7 @@ class IESFile { + protected: + bool parse(const string &ies); + bool process(); ++ + void process_type_a(); + void process_type_b(); + void process_type_c(); +@@ -41,6 +50,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__ */ ++#endif /* PXR_IMAGING_PLUGIN_HD_EMBREE_PXRIES_IES_H */