24#include <pxr/base/tf/getenv.h>
25#include <pxr/imaging/hgi/tokens.h>
40const TfTokenVector kSupportedRPrimTypes = {
41 HdPrimTypeTokens->basisCurves,
42 HdPrimTypeTokens->mesh,
43 HdPrimTypeTokens->points,
45 HdPrimTypeTokens->volume,
49const TfTokenVector kSupportedSPrimTypes = {
50 HdPrimTypeTokens->camera,
51 HdPrimTypeTokens->material,
52 HdPrimTypeTokens->diskLight,
53 HdPrimTypeTokens->distantLight,
54 HdPrimTypeTokens->domeLight,
55 HdPrimTypeTokens->rectLight,
56 HdPrimTypeTokens->sphereLight,
59const TfTokenVector kSupportedBPrimTypes = {
60 HdPrimTypeTokens->renderBuffer,
62 _tokens->openvdbAsset,
66SessionParams GetSessionParams(
const HdRenderSettingsMap &settings)
73 HdRenderSettingsMap::const_iterator it;
76 it = settings.find(HdCyclesRenderSettingsTokens->threads);
77 if (it != settings.end()) {
78 params.
threads = VtValue::Cast<int>(it->second).GetWithDefault(params.
threads);
83 it = settings.find(HdCyclesRenderSettingsTokens->device);
84 if (it != settings.end()) {
85 deviceType = VtValue::Cast<std::string>(it->second).GetWithDefault(deviceType);
88 const std::string deviceTypeEnv = TfGetenv(
"CYCLES_DEVICE");
89 if (!deviceTypeEnv.empty()) {
90 deviceType = deviceTypeEnv;
95 std::transform(deviceType.begin(), deviceType.end(), deviceType.begin(), ::toupper);
101 if (info.meets_driver_requirement) {
102 devices.push_back(info);
105 if (devices.empty()) {
107 if (!devices.empty()) {
108 params.
device = devices.front();
125 const bool keep_nodes)
128 _renderParam = session_ ? std::make_unique<HdCyclesSession>(session_, keep_nodes) :
129 std::make_unique<HdCyclesSession>(GetSessionParams(settingsMap));
131 for (
const auto &setting : settingsMap) {
133 if (setting.first == HdCyclesRenderSettingsTokens->device ||
134 setting.first == HdCyclesRenderSettingsTokens->threads)
147 for (HdDriver *hdDriver : drivers) {
148 if (hdDriver->name == HgiTokens->renderDriver && hdDriver->driver.IsHolding<Hgi *>()) {
149 _hgi = hdDriver->driver.UncheckedGet<Hgi *>();
157#if defined(_WIN32) && defined(WITH_HYDRA_DISPLAY_DRIVER)
158 return _hgi && _hgi->GetAPIName() == HgiTokens->OpenGL;
166 return kSupportedRPrimTypes;
171 return kSupportedSPrimTypes;
176 return kSupportedBPrimTypes;
181 return _renderParam.get();
186 return HdResourceRegistrySharedPtr();
196 _renderParam->session->set_pause(
true);
202 _renderParam->session->set_pause(
false);
207 const HdRprimCollection &collection)
213 const SdfPath &instancerId)
225 if (typeId == HdPrimTypeTokens->mesh) {
228 if (typeId == HdPrimTypeTokens->basisCurves) {
231 if (typeId == HdPrimTypeTokens->points) {
235 if (typeId == HdPrimTypeTokens->volume) {
240 TF_CODING_ERROR(
"Unknown Rprim type %s", typeId.GetText());
251 if (typeId == HdPrimTypeTokens->camera) {
254 if (typeId == HdPrimTypeTokens->material) {
257 if (typeId == HdPrimTypeTokens->diskLight || typeId == HdPrimTypeTokens->distantLight ||
258 typeId == HdPrimTypeTokens->domeLight || typeId == HdPrimTypeTokens->rectLight ||
259 typeId == HdPrimTypeTokens->sphereLight)
264 TF_CODING_ERROR(
"Unknown Sprim type %s", typeId.GetText());
280 if (typeId == HdPrimTypeTokens->renderBuffer) {
284 if (typeId == _tokens->openvdbAsset) {
289 TF_CODING_ERROR(
"Unknown Bprim type %s", typeId.GetText());
309 _renderParam->UpdateScene();
314 return HdTokens->full;
319 return {_tokens->cycles};
324 const Stats &stats = _renderParam->session->stats;
325 const Progress &progress = _renderParam->session->progress;
329 progress.
get_time(totalTime, renderTime);
333 std::string substatus;
335 if (!substatus.empty()) {
336 status +=
" | " + substatus;
339 return {{
"rendererName", VtValue(
"Cycles")},
340 {
"rendererVersion", VtValue(GfVec3i(0, 0, 0))},
341 {
"percentDone", VtValue(
floor_to_int(fractionDone * 100))},
342 {
"fractionDone", VtValue(fractionDone)},
343 {
"loadClockTime", VtValue(totalTime - renderTime)},
344 {
"peakMemory", VtValue(stats.
mem_peak)},
345 {
"totalClockTime", VtValue(totalTime)},
346 {
"totalMemory", VtValue(stats.
mem_used)},
347 {
"renderProgressAnnotation", VtValue(status)}};
352 if (name == HdAovTokens->color) {
353 HdFormat colorFormat = HdFormatFloat32Vec4;
356 colorFormat = HdFormatFloat16Vec4;
359 return HdAovDescriptor(colorFormat,
false, VtValue(GfVec4f(0.0f)));
361 if (name == HdAovTokens->depth) {
362 return HdAovDescriptor(HdFormatFloat32,
false, VtValue(1.0f));
364 if (name == HdAovTokens->normal) {
365 return HdAovDescriptor(HdFormatFloat32Vec3,
false, VtValue(GfVec3f(0.0f)));
367 if (name == HdAovTokens->primId || name == HdAovTokens->instanceId ||
368 name == HdAovTokens->elementId)
370 return HdAovDescriptor(HdFormatInt32,
false, VtValue(-1));
373 return HdAovDescriptor();
378 Scene *
const scene = _renderParam->session->scene.get();
380 HdRenderSettingDescriptorList descriptors;
382 descriptors.push_back({
384 HdCyclesRenderSettingsTokens->timeLimit,
387 descriptors.push_back({
389 HdCyclesRenderSettingsTokens->samples,
392 descriptors.push_back({
394 HdCyclesRenderSettingsTokens->sampleOffset,
399 descriptors.push_back({socket.
ui_name.string(),
400 TfToken(
"cycles:integrator:" + socket.
name.string()),
409 Scene *
const scene = _renderParam->session->scene.get();
410 Session *
const session = _renderParam->session;
412 if (key == HdCyclesRenderSettingsTokens->stageMetersPerUnit) {
413 _renderParam->SetStageMetersPerUnit(
414 VtValue::Cast<double>(value).GetWithDefault(_renderParam->GetStageMetersPerUnit()));
416 else if (key == HdCyclesRenderSettingsTokens->timeLimit) {
420 else if (key == HdCyclesRenderSettingsTokens->samples) {
422 int samples = VtValue::Cast<int>(value).GetWithDefault(session->
params.
samples);
423 samples = std::min(std::max(1, samples), max_samples);
426 else if (key == HdCyclesRenderSettingsTokens->sampleOffset) {
434 const std::string &keyString = key.GetString();
435 if (keyString.rfind(
"cycles:integrator:", 0) == 0) {
436 const ustring socketName(keyString,
sizeof(
"cycles:integrator:") - 1);
447 Scene *
const scene = _renderParam->session->scene.get();
448 Session *
const session = _renderParam->session;
450 if (key == HdCyclesRenderSettingsTokens->stageMetersPerUnit) {
451 return VtValue(_renderParam->GetStageMetersPerUnit());
453 if (key == HdCyclesRenderSettingsTokens->device) {
456 if (key == HdCyclesRenderSettingsTokens->threads) {
459 if (key == HdCyclesRenderSettingsTokens->timeLimit) {
462 if (key == HdCyclesRenderSettingsTokens->samples) {
465 if (key == HdCyclesRenderSettingsTokens->sampleOffset) {
469 const std::string &keyString = key.GetString();
470 if (keyString.rfind(
"cycles:integrator:", 0) == 0) {
471 const ustring socketName(keyString,
sizeof(
"cycles:integrator:") - 1);
static DeviceInfo get_multi_device(const vector< DeviceInfo > &subdevices, const int threads, bool background)
static DeviceType type_from_string(const char *name)
static string string_from_type(DeviceType type)
static vector< DeviceInfo > available_devices(const uint device_type_mask=DEVICE_MASK_ALL)
HdCyclesCamera(const PXR_NS::SdfPath &sprimId)
HdCyclesCurves(const PXR_NS::SdfPath &rprimId)
bool IsPauseSupported() const override
PXR_NS::HdBprim * CreateFallbackBprim(const PXR_NS::TfToken &typeId) override
~HdCyclesDelegate() override
void SetRenderSetting(const PXR_NS::TfToken &key, const PXR_NS::VtValue &value) override
PXR_NS::HdInstancer * CreateInstancer(PXR_NS::HdSceneDelegate *delegate, const PXR_NS::SdfPath &id) override
void DestroyRprim(PXR_NS::HdRprim *rPrim) override
const PXR_NS::TfTokenVector & GetSupportedSprimTypes() const override
PXR_NS::HdRenderParam * GetRenderParam() const override
PXR_NS::HdRenderPassSharedPtr CreateRenderPass(PXR_NS::HdRenderIndex *index, const PXR_NS::HdRprimCollection &collection) override
PXR_NS::HdSprim * CreateFallbackSprim(const PXR_NS::TfToken &typeId) override
PXR_NS::HdResourceRegistrySharedPtr GetResourceRegistry() const override
void DestroySprim(PXR_NS::HdSprim *sPrim) override
void CommitResources(PXR_NS::HdChangeTracker *tracker) override
const PXR_NS::TfTokenVector & GetSupportedBprimTypes() const override
const PXR_NS::TfTokenVector & GetSupportedRprimTypes() const override
PXR_NS::HdRprim * CreateRprim(const PXR_NS::TfToken &typeId, const PXR_NS::SdfPath &rprimId) override
PXR_NS::TfTokenVector GetMaterialRenderContexts() const override
HdCyclesDelegate(const PXR_NS::HdRenderSettingsMap &settingsMap, CCL_NS::Session *session_=nullptr, const bool keep_nodes=false)
PXR_NS::HdAovDescriptor GetDefaultAovDescriptor(const PXR_NS::TfToken &name) const override
PXR_NS::HdSprim * CreateSprim(const PXR_NS::TfToken &typeId, const PXR_NS::SdfPath &sprimId) override
PXR_NS::VtValue GetRenderSetting(const PXR_NS::TfToken &key) const override
void SetDrivers(const PXR_NS::HdDriverVector &drivers) override
bool IsDisplaySupported() const
PXR_NS::HdRenderSettingDescriptorList GetRenderSettingDescriptors() const override
PXR_NS::TfToken GetMaterialBindingPurpose() const override
void DestroyBprim(PXR_NS::HdBprim *bPrim) override
PXR_NS::VtDictionary GetRenderStats() const override
void DestroyInstancer(PXR_NS::HdInstancer *instancer) override
PXR_NS::HdBprim * CreateBprim(const PXR_NS::TfToken &typeId, const PXR_NS::SdfPath &bprimId) override
HdCyclesField(const PXR_NS::SdfPath &bprimId, const PXR_NS::TfToken &typeId)
HdCyclesInstancer(PXR_NS::HdSceneDelegate *delegate, const PXR_NS::SdfPath &instancerId)
HdCyclesLight(const PXR_NS::SdfPath &sprimId, const PXR_NS::TfToken &lightType)
HdCyclesMaterial(const PXR_NS::SdfPath &sprimId)
HdCyclesMesh(const PXR_NS::SdfPath &rprimId)
HdCyclesPoints(const PXR_NS::SdfPath &rprimId)
HdCyclesRenderBuffer(const PXR_NS::SdfPath &bprimId)
HdCyclesRenderPass(PXR_NS::HdRenderIndex *index, const PXR_NS::HdRprimCollection &collection, HdCyclesSession *renderParam)
HdCyclesVolume(const PXR_NS::SdfPath &rprimId)
static const int MAX_SAMPLES
void get_status(string &status_, string &substatus_) const
void get_time(double &total_time_, double &render_time_) const
double get_progress() const
bool use_resolution_divider
DeviceInfo denoise_device
void set_time_limit(const double time_limit)
void set_samples(const int samples)
#define DEVICE_MASK(type)
#define HDCYCLES_NAMESPACE_CLOSE_SCOPE
TF_DEFINE_PRIVATE_TOKENS(_tokens,(visibleInPrimaryRay)(treatAsPoint)(falloff))
ccl_device_inline int floor_to_int(const float f)
void SetNodeValue(Node *node, const SocketType &socket, const VtValue &value)
VtValue GetNodeValue(const Node *node, const SocketType &socket)
HDCYCLES_NAMESPACE_OPEN_SCOPE TF_DEFINE_PUBLIC_TOKENS(HdCyclesRenderSettingsTokens, HD_CYCLES_RENDER_SETTINGS_TOKENS)
#define HD_CYCLES_RENDER_SETTINGS_TOKENS
vector< SocketType, std::allocator< SocketType > > inputs
const SocketType * find_input(ustring name) const