24#include <pxr/base/tf/getenv.h>
25#include <pxr/imaging/hd/extComputation.h>
26#include <pxr/imaging/hgi/tokens.h>
41const TfTokenVector kSupportedRPrimTypes = {
42 HdPrimTypeTokens->basisCurves,
43 HdPrimTypeTokens->mesh,
44 HdPrimTypeTokens->points,
46 HdPrimTypeTokens->volume,
50const TfTokenVector kSupportedSPrimTypes = {
51 HdPrimTypeTokens->camera,
52 HdPrimTypeTokens->material,
53 HdPrimTypeTokens->diskLight,
54 HdPrimTypeTokens->distantLight,
55 HdPrimTypeTokens->domeLight,
56 HdPrimTypeTokens->rectLight,
57 HdPrimTypeTokens->sphereLight,
58 HdPrimTypeTokens->extComputation,
61const TfTokenVector kSupportedBPrimTypes = {
62 HdPrimTypeTokens->renderBuffer,
64 _tokens->openvdbAsset,
68SessionParams GetSessionParams(
const HdRenderSettingsMap &settings)
73 params.use_resolution_divider =
false;
75 HdRenderSettingsMap::const_iterator it;
78 it = settings.find(HdCyclesRenderSettingsTokens->threads);
79 if (it != settings.end()) {
80 params.threads = VtValue::Cast<int>(it->second).GetWithDefault(
params.threads);
85 it = settings.find(HdCyclesRenderSettingsTokens->device);
86 if (it != settings.end()) {
87 deviceType = VtValue::Cast<std::string>(it->second).GetWithDefault(deviceType);
90 const std::string deviceTypeEnv = TfGetenv(
"CYCLES_DEVICE");
91 if (!deviceTypeEnv.empty()) {
92 deviceType = deviceTypeEnv;
97 std::transform(deviceType.begin(), deviceType.end(), deviceType.begin(), ::toupper);
118 const bool keep_nodes)
121 _renderParam = session_ ? std::make_unique<HdCyclesSession>(session_, keep_nodes) :
122 std::make_unique<HdCyclesSession>(GetSessionParams(settingsMap));
124 for (
const auto &setting : settingsMap) {
126 if (setting.first == HdCyclesRenderSettingsTokens->device ||
127 setting.first == HdCyclesRenderSettingsTokens->threads)
140 for (HdDriver *hdDriver : drivers) {
141 if (hdDriver->name == HgiTokens->renderDriver && hdDriver->driver.IsHolding<Hgi *>()) {
142 _hgi = hdDriver->driver.UncheckedGet<Hgi *>();
150#if defined(_WIN32) && defined(WITH_HYDRA_DISPLAY_DRIVER)
151 return _hgi && _hgi->GetAPIName() == HgiTokens->OpenGL;
159 return kSupportedRPrimTypes;
164 return kSupportedSPrimTypes;
169 return kSupportedBPrimTypes;
174 return _renderParam.get();
179 return HdResourceRegistrySharedPtr();
189 _renderParam->session->set_pause(
true);
195 _renderParam->session->set_pause(
false);
200 const HdRprimCollection &collection)
202 return HdRenderPassSharedPtr(
new HdCyclesRenderPass(index, collection, _renderParam.get()));
206 const SdfPath &instancerId
207#
if PXR_VERSION < 2102
209 const SdfPath &parentId
215#
if PXR_VERSION < 2102
228 const SdfPath &rprimId
229#
if PXR_VERSION < 2102
231 const SdfPath &instancerId
235 if (typeId == HdPrimTypeTokens->mesh) {
237#
if PXR_VERSION < 2102
243 if (typeId == HdPrimTypeTokens->basisCurves) {
245#
if PXR_VERSION < 2102
251 if (typeId == HdPrimTypeTokens->points) {
253#
if PXR_VERSION < 2102
260 if (typeId == HdPrimTypeTokens->volume) {
262#
if PXR_VERSION < 2102
270 TF_CODING_ERROR(
"Unknown Rprim type %s", typeId.GetText());
281 if (typeId == HdPrimTypeTokens->camera) {
284 if (typeId == HdPrimTypeTokens->material) {
287 if (typeId == HdPrimTypeTokens->diskLight || typeId == HdPrimTypeTokens->distantLight ||
288 typeId == HdPrimTypeTokens->domeLight || typeId == HdPrimTypeTokens->rectLight ||
289 typeId == HdPrimTypeTokens->sphereLight)
293 if (typeId == HdPrimTypeTokens->extComputation) {
294 return new HdExtComputation(sprimId);
297 TF_CODING_ERROR(
"Unknown Sprim type %s", typeId.GetText());
313 if (typeId == HdPrimTypeTokens->renderBuffer) {
317 if (typeId == _tokens->openvdbAsset) {
322 TF_CODING_ERROR(
"Unknown Bprim type %s", typeId.GetText());
342 _renderParam->UpdateScene();
347 return HdTokens->full;
350#if HD_API_VERSION < 41
353 return _tokens->cycles;
356TfTokenVector HdCyclesDelegate::GetMaterialRenderContexts()
const
358 return {_tokens->cycles};
364 const Stats &stats = _renderParam->session->stats;
365 const Progress &progress = _renderParam->session->progress;
367 double totalTime, renderTime;
368 progress.
get_time(totalTime, renderTime);
371 std::string status, substatus;
373 if (!substatus.empty()) {
374 status +=
" | " + substatus;
377 return {{
"rendererName", VtValue(
"Cycles")},
378 {
"rendererVersion", VtValue(GfVec3i(0, 0, 0))},
379 {
"percentDone", VtValue(
floor_to_int(fractionDone * 100))},
380 {
"fractionDone", VtValue(fractionDone)},
381 {
"loadClockTime", VtValue(totalTime - renderTime)},
382 {
"peakMemory", VtValue(stats.
mem_peak)},
383 {
"totalClockTime", VtValue(totalTime)},
384 {
"totalMemory", VtValue(stats.
mem_used)},
385 {
"renderProgressAnnotation", VtValue(status)}};
390 if (name == HdAovTokens->color) {
391 HdFormat colorFormat = HdFormatFloat32Vec4;
394 colorFormat = HdFormatFloat16Vec4;
397 return HdAovDescriptor(colorFormat,
false, VtValue(GfVec4f(0.0f)));
399 if (name == HdAovTokens->depth) {
400 return HdAovDescriptor(HdFormatFloat32,
false, VtValue(1.0f));
402 if (name == HdAovTokens->normal) {
403 return HdAovDescriptor(HdFormatFloat32Vec3,
false, VtValue(GfVec3f(0.0f)));
405 if (name == HdAovTokens->primId || name == HdAovTokens->instanceId ||
406 name == HdAovTokens->elementId)
408 return HdAovDescriptor(HdFormatInt32,
false, VtValue(-1));
411 return HdAovDescriptor();
416 Scene *
const scene = _renderParam->session->scene;
418 HdRenderSettingDescriptorList descriptors;
420 descriptors.push_back({
422 HdCyclesRenderSettingsTokens->timeLimit,
425 descriptors.push_back({
427 HdCyclesRenderSettingsTokens->samples,
430 descriptors.push_back({
432 HdCyclesRenderSettingsTokens->sampleOffset,
436 for (
const SocketType &socket : scene->integrator->type->inputs) {
437 descriptors.push_back({socket.ui_name.string(),
438 TfToken(
"cycles:integrator:" + socket.name.string()),
447 Scene *
const scene = _renderParam->session->scene;
448 Session *
const session = _renderParam->session;
450 if (key == HdCyclesRenderSettingsTokens->stageMetersPerUnit) {
451 _renderParam->SetStageMetersPerUnit(
452 VtValue::Cast<double>(value).GetWithDefault(_renderParam->GetStageMetersPerUnit()));
454 else if (key == HdCyclesRenderSettingsTokens->timeLimit) {
458 else if (key == HdCyclesRenderSettingsTokens->samples) {
460 int samples = VtValue::Cast<int>(value).GetWithDefault(session->
params.
samples);
461 samples = std::min(std::max(1, samples), max_samples);
464 else if (key == HdCyclesRenderSettingsTokens->sampleOffset) {
470 const std::string &keyString = key.GetString();
471 if (keyString.rfind(
"cycles:integrator:", 0) == 0) {
472 ustring socketName(keyString,
sizeof(
"cycles:integrator:") - 1);
473 if (
const SocketType *socket = scene->integrator->
type->find_input(socketName)) {
483 Scene *
const scene = _renderParam->session->scene;
484 Session *
const session = _renderParam->session;
486 if (key == HdCyclesRenderSettingsTokens->stageMetersPerUnit) {
487 return VtValue(_renderParam->GetStageMetersPerUnit());
489 else if (key == HdCyclesRenderSettingsTokens->device) {
492 else if (key == HdCyclesRenderSettingsTokens->threads) {
495 else if (key == HdCyclesRenderSettingsTokens->timeLimit) {
498 else if (key == HdCyclesRenderSettingsTokens->samples) {
501 else if (key == HdCyclesRenderSettingsTokens->sampleOffset) {
505 const std::string &keyString = key.GetString();
506 if (keyString.rfind(
"cycles:integrator:", 0) == 0) {
507 ustring socketName(keyString,
sizeof(
"cycles:integrator:") - 1);
508 if (
const SocketType *socket = scene->integrator->
type->find_input(socketName)) {
static vector< DeviceInfo > available_devices(uint device_type_mask=DEVICE_MASK_ALL)
static DeviceType type_from_string(const char *name)
static string string_from_type(DeviceType type)
static DeviceInfo get_multi_device(const vector< DeviceInfo > &subdevices, int threads, bool background)
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
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::TfToken GetMaterialNetworkSelector() const override
PXR_NS::HdResourceRegistrySharedPtr GetResourceRegistry() const override
PXR_NS::HdInstancer * CreateInstancer(PXR_NS::HdSceneDelegate *delegate, const PXR_NS::SdfPath &id, const PXR_NS::SdfPath &instancerId) 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
HdCyclesDelegate(const PXR_NS::HdRenderSettingsMap &settingsMap, CCL_NS::Session *session_=nullptr, const bool keep_nodes=false)
PXR_NS::HdRprim * CreateRprim(const PXR_NS::TfToken &typeId, const PXR_NS::SdfPath &rprimId, const PXR_NS::SdfPath &instancerId) override
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
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
void set_time_limit(double time_limit)
void set_samples(int samples)
#define DEVICE_MASK(type)
#define HDCYCLES_NAMESPACE_CLOSE_SCOPE
Vector< CPUDevice > devices
list of all CPUDevices. for every hardware thread an instance of CPUDevice is created
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)
TF_DEFINE_PRIVATE_TOKENS(_tokens,(cycles)(openvdbAsset))
#define HD_CYCLES_RENDER_SETTINGS_TOKENS
ccl_device_inline int floor_to_int(float f)