This patch adds a Hydra render delegate to Cycles, allowing Cycles to be used for rendering in applications that provide a Hydra viewport. The implementation was written from scratch against Cycles X, for integration into the Blender repository to make it possible to continue developing it in step with the rest of Cycles. For this purpose it follows the style of the rest of the Cycles code and can be built with a CMake option (`WITH_CYCLES_HYDRA_RENDER_DELEGATE=1`) similar to the existing standalone version of Cycles. Since Hydra render delegates need to be built against the exact USD version and other dependencies as the target application is using, this is intended to be built separate from Blender (`WITH_BLENDER=0` CMake option) and with support for library versions different from what Blender is using. As such the CMake build scripts for Windows had to be modified slightly, so that the Cycles Hydra render delegate can e.g. be built with MSVC 2017 again even though Blender requires MSVC 2019 now, and it's possible to specify custom paths to the USD SDK etc. The codebase supports building against the latest USD release 22.03 and all the way back to USD 20.08 (with some limitations). Reviewed By: brecht, LazyDodo Differential Revision: https://developer.blender.org/D14398
72 lines
2.0 KiB
C++
72 lines
2.0 KiB
C++
/* SPDX-License-Identifier: Apache-2.0
|
|
* Copyright 2022 NVIDIA Corporation
|
|
* Copyright 2022 Blender Foundation */
|
|
|
|
#include "hydra/plugin.h"
|
|
#include "hydra/render_delegate.h"
|
|
#include "util/log.h"
|
|
#include "util/path.h"
|
|
|
|
#include <pxr/base/arch/filesystem.h>
|
|
#include <pxr/base/plug/plugin.h>
|
|
#include <pxr/base/plug/thisPlugin.h>
|
|
#include <pxr/base/tf/envSetting.h>
|
|
#include <pxr/imaging/hd/rendererPluginRegistry.h>
|
|
|
|
PXR_NAMESPACE_OPEN_SCOPE
|
|
|
|
#ifdef WITH_CYCLES_LOGGING
|
|
TF_DEFINE_ENV_SETTING(CYCLES_LOGGING, false, "Enable Cycles logging")
|
|
TF_DEFINE_ENV_SETTING(CYCLES_LOGGING_SEVERITY, 1, "Cycles logging verbosity")
|
|
#endif
|
|
|
|
HdCyclesPlugin::HdCyclesPlugin()
|
|
{
|
|
const PlugPluginPtr plugin = PLUG_THIS_PLUGIN;
|
|
// Initialize Cycles paths relative to the plugin resource path
|
|
std::string rootPath = PXR_NS::ArchAbsPath(plugin->GetResourcePath());
|
|
CCL_NS::path_init(std::move(rootPath));
|
|
|
|
#ifdef WITH_CYCLES_LOGGING
|
|
if (TfGetEnvSetting(CYCLES_LOGGING)) {
|
|
CCL_NS::util_logging_start();
|
|
CCL_NS::util_logging_verbosity_set(TfGetEnvSetting(CYCLES_LOGGING_SEVERITY));
|
|
}
|
|
#endif
|
|
}
|
|
|
|
HdCyclesPlugin::~HdCyclesPlugin()
|
|
{
|
|
}
|
|
|
|
bool HdCyclesPlugin::IsSupported() const
|
|
{
|
|
return true;
|
|
}
|
|
|
|
HdRenderDelegate *HdCyclesPlugin::CreateRenderDelegate()
|
|
{
|
|
return CreateRenderDelegate({});
|
|
}
|
|
|
|
HdRenderDelegate *HdCyclesPlugin::CreateRenderDelegate(const HdRenderSettingsMap &settingsMap)
|
|
{
|
|
return new HD_CYCLES_NS::HdCyclesDelegate(settingsMap);
|
|
}
|
|
|
|
void HdCyclesPlugin::DeleteRenderDelegate(HdRenderDelegate *renderDelegate)
|
|
{
|
|
delete renderDelegate;
|
|
}
|
|
|
|
// USD's type system accounts for namespace, so we'd have to register our name as
|
|
// HdCycles::HdCyclesPlugin in plugInfo.json, which isn't all that bad for JSON,
|
|
// but those colons may cause issues for any USD specific tooling. So just put our
|
|
// plugin class in the pxr namespace (which USD's type system will elide).
|
|
TF_REGISTRY_FUNCTION(TfType)
|
|
{
|
|
HdRendererPluginRegistry::Define<PXR_NS::HdCyclesPlugin>();
|
|
}
|
|
|
|
PXR_NAMESPACE_CLOSE_SCOPE
|