Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAYA-109927: Remove dependency on boost::hash_combine. #1183

Merged
merged 2 commits into from
Feb 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion doc/codingGuidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,15 @@ Respect the minimum supported version for Maya and USD stated in [build.md](http
Recent extensions to the C++ standard introduce many features previously only found in [boost](http://boost.org). To avoid introducing additional dependencies, developers should strive to use functionality in the C++ std over boost. If you encounter usage of boost in the code, consider converting this to the equivalent std mechanism.
Our library currently has the following boost dependencies:
* `boost::python`
* `boost::hash_combine` (see [this proposal](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0814r0.pdf) )
* `boost::make_shared` (preferable to replace with `std::shared_ptr`)

***Update:***

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the last PR, it would be good to clean-up this Update section, since we people can use GitHub to check the history of changes. We don't need to keep them in the document.

* `boost::filesystem` and `boost::system` are removed. Until the transition to C++17 std::filesystem, [ghc::filesystem](https://github.com/gulrak/filesystem) must be used as an alternative across the project.

* Dependency on `boost::thread` is removed from Animal Logic plugin.

* `boost::hash_combine` is replaced with `MayaUsd::hash_combine` and should be used instead across the project.

## Modern C++
Our goal is to develop [maya-usd](https://github.com/autodesk/maya-usd) following modern C++ practices. We’ll follow the [C++ Core Guidelines](http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines) and pay attention to:
* `using` (vs `typedef`) keyword
Expand Down
11 changes: 5 additions & 6 deletions lib/mayaUsd/render/mayaToHydra/renderOverride.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <hdMaya/delegates/sceneDelegate.h>
#include <hdMaya/utils.h>
#include <mayaUsd/render/px_vp20/utils.h>
#include <mayaUsd/utils/hash.h>

#include <pxr/base/gf/matrix4d.h>
#include <pxr/base/tf/instantiateSingleton.h>
Expand All @@ -47,8 +48,6 @@
#include <maya/MTimerMessage.h>
#include <maya/MUiMessage.h>

#include <boost/functional/hash.hpp>

#include <atomic>
#include <chrono>
#include <exception>
Expand Down Expand Up @@ -169,10 +168,10 @@ void ResolveUniqueHits_Workaround(const HdxPickHitVector& inHits, HdxPickHitVect
const HdxPickHit& hit = inHits[i];

size_t hash = 0;
boost::hash_combine(hash, hit.delegateId.GetHash());
boost::hash_combine(hash, hit.objectId.GetHash());
boost::hash_combine(hash, hit.instancerId.GetHash());
boost::hash_combine(hash, hit.instanceIndex);
MayaUsd::hash_combine(hash, hit.delegateId.GetHash());
MayaUsd::hash_combine(hash, hit.objectId.GetHash());
MayaUsd::hash_combine(hash, hit.instancerId.GetHash());
MayaUsd::hash_combine(hash, hit.instanceIndex);

// As an optimization, keep track of the previous hash value and
// reject indices that match it without performing a map lookup.
Expand Down
11 changes: 7 additions & 4 deletions lib/mayaUsd/render/pxrUsdMayaGL/renderParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@

/// \file pxrUsdMayaGL/renderParams.h

#include <mayaUsd/utils/hash.h>

#include <pxr/base/gf/vec4f.h>
#include <pxr/pxr.h>

#include <boost/functional/hash.hpp>

PXR_NAMESPACE_OPEN_SCOPE

struct PxrMayaHdRenderParams
Expand All @@ -40,8 +40,11 @@ struct PxrMayaHdRenderParams
size_t Hash() const
{
size_t hash = size_t(enableLighting);
boost::hash_combine(hash, useWireframe);
boost::hash_combine(hash, wireframeColor);
MayaUsd::hash_combine(hash, useWireframe);
MayaUsd::hash_combine(hash, wireframeColor[0]);
MayaUsd::hash_combine(hash, wireframeColor[1]);
MayaUsd::hash_combine(hash, wireframeColor[2]);
MayaUsd::hash_combine(hash, wireframeColor[3]);

return hash;
}
Expand Down
40 changes: 20 additions & 20 deletions lib/mayaUsd/render/vp2RenderDelegate/render_delegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "render_pass.h"

#include <mayaUsd/render/vp2ShaderFragments/shaderFragments.h>
#include <mayaUsd/utils/hash.h>

#include <pxr/imaging/hd/bprim.h>
#include <pxr/imaging/hd/camera.h>
Expand All @@ -33,7 +34,6 @@

#include <maya/MProfiler.h>

#include <boost/functional/hash.hpp>
#include <tbb/reader_writer_lock.h>
#include <tbb/spin_rw_mutex.h>

Expand Down Expand Up @@ -134,10 +134,10 @@ struct MColorHash
std::size_t operator()(const MColor& color) const
{
std::size_t seed = 0;
boost::hash_combine(seed, color.r);
boost::hash_combine(seed, color.g);
boost::hash_combine(seed, color.b);
boost::hash_combine(seed, color.a);
MayaUsd::hash_combine(seed, color.r);
MayaUsd::hash_combine(seed, color.g);
MayaUsd::hash_combine(seed, color.b);
MayaUsd::hash_combine(seed, color.a);
return seed;
}
};
Expand Down Expand Up @@ -358,21 +358,21 @@ struct MSamplerStateDescHash
std::size_t operator()(const MHWRender::MSamplerStateDesc& desc) const
{
std::size_t seed = 0;
boost::hash_combine(seed, desc.filter);
boost::hash_combine(seed, desc.comparisonFn);
boost::hash_combine(seed, desc.addressU);
boost::hash_combine(seed, desc.addressV);
boost::hash_combine(seed, desc.addressW);
boost::hash_combine(seed, desc.borderColor[0]);
boost::hash_combine(seed, desc.borderColor[1]);
boost::hash_combine(seed, desc.borderColor[2]);
boost::hash_combine(seed, desc.borderColor[3]);
boost::hash_combine(seed, desc.mipLODBias);
boost::hash_combine(seed, desc.minLOD);
boost::hash_combine(seed, desc.maxLOD);
boost::hash_combine(seed, desc.maxAnisotropy);
boost::hash_combine(seed, desc.coordCount);
boost::hash_combine(seed, desc.elementIndex);
MayaUsd::hash_combine(seed, desc.filter);
MayaUsd::hash_combine(seed, desc.comparisonFn);
MayaUsd::hash_combine(seed, desc.addressU);
MayaUsd::hash_combine(seed, desc.addressV);
MayaUsd::hash_combine(seed, desc.addressW);
MayaUsd::hash_combine(seed, desc.borderColor[0]);
MayaUsd::hash_combine(seed, desc.borderColor[1]);
MayaUsd::hash_combine(seed, desc.borderColor[2]);
MayaUsd::hash_combine(seed, desc.borderColor[3]);
MayaUsd::hash_combine(seed, desc.mipLODBias);
MayaUsd::hash_combine(seed, desc.minLOD);
MayaUsd::hash_combine(seed, desc.maxLOD);
MayaUsd::hash_combine(seed, desc.maxAnisotropy);
MayaUsd::hash_combine(seed, desc.coordCount);
MayaUsd::hash_combine(seed, desc.elementIndex);
return seed;
}
};
Expand Down
1 change: 1 addition & 0 deletions lib/mayaUsd/utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ set(HEADERS
util.h
utilFileSystem.h
utilSerialization.h
hash.h
)

# -----------------------------------------------------------------------------
Expand Down
38 changes: 38 additions & 0 deletions lib/mayaUsd/utils/hash.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// Copyright 2021 Autodesk
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef MAYAUSD_UTILS_HASH_H
#define MAYAUSD_UTILS_HASH_H

#include <mayaUsd/base/api.h>

#include <functional>

namespace MAYAUSD_NS_DEF {

// hash combiner taken from:
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0814r0.pdf

// boost::hash implementation also relies on the same algorithm:
// https://www.boost.org/doc/libs/1_64_0/boost/functional/hash/hash.hpp

template <typename T> inline void hash_combine(size_t& seed, const T& value)
{
::std::hash<T> hasher;
seed ^= hasher(value) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
} // namespace MAYAUSD_NS_DEF

#endif // MAYAUSD_UTILS_HASH_H
7 changes: 4 additions & 3 deletions lib/usd/hdMaya/adapters/materialAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <hdMaya/adapters/mayaAttrs.h>
#include <hdMaya/adapters/tokens.h>
#include <hdMaya/utils.h>
#include <mayaUsd/utils/hash.h>

#include <pxr/base/tf/stl.h>
#include <pxr/base/tf/token.h>
Expand Down Expand Up @@ -258,9 +259,9 @@ class HdMayaShadingEngineAdapter : public HdMayaMaterialAdapter
{
auto hash = filePath.Hash();
const auto wrapping = GetFileTextureWrappingParams(fileObj);
boost::hash_combine(hash, GetDelegate()->GetParams().textureMemoryPerTexture);
boost::hash_combine(hash, std::get<0>(wrapping));
boost::hash_combine(hash, std::get<1>(wrapping));
MayaUsd::hash_combine(hash, GetDelegate()->GetParams().textureMemoryPerTexture);
MayaUsd::hash_combine(hash, std::get<0>(wrapping));
MayaUsd::hash_combine(hash, std::get<1>(wrapping));
return HdTextureResource::ID(hash);
}

Expand Down