23 #include <pxr/base/tf/getenv.h>
24 #include <pxr/imaging/hd/extComputation.h>
25 #include <pxr/imaging/hgi/tokens.h>
40 const TfTokenVector kSupportedRPrimTypes = {
41 HdPrimTypeTokens->basisCurves,
42 HdPrimTypeTokens->mesh,
43 HdPrimTypeTokens->points,
45 HdPrimTypeTokens->volume,
49 const TfTokenVector kSupportedSPrimTypes = {
50 HdPrimTypeTokens->camera,
51 HdPrimTypeTokens->material,
52 HdPrimTypeTokens->diskLight,
53 HdPrimTypeTokens->distantLight,
54 HdPrimTypeTokens->domeLight,
55 HdPrimTypeTokens->rectLight,
56 HdPrimTypeTokens->sphereLight,
57 HdPrimTypeTokens->extComputation,
60 const TfTokenVector kSupportedBPrimTypes = {
61 HdPrimTypeTokens->renderBuffer,
63 _tokens->openvdbAsset,
67 SessionParams GetSessionParams(
const HdRenderSettingsMap &settings)
72 params.use_resolution_divider =
false;
74 HdRenderSettingsMap::const_iterator it;
77 it = settings.find(HdCyclesRenderSettingsTokens->threads);
78 if (it != settings.end()) {
79 params.threads = VtValue::Cast<int>(it->second).GetWithDefault(
params.threads);
84 it = settings.find(HdCyclesRenderSettingsTokens->device);
85 if (it != settings.end()) {
86 deviceType = VtValue::Cast<std::string>(it->second).GetWithDefault(deviceType);
89 const std::string deviceTypeEnv = TfGetenv(
"CYCLES_DEVICE");
90 if (!deviceTypeEnv.empty()) {
91 deviceType = deviceTypeEnv;
96 std::transform(deviceType.begin(), deviceType.end(), deviceType.begin(), ::toupper);
117 const bool keep_nodes)
120 _renderParam = session_ ? std::make_unique<HdCyclesSession>(session_, keep_nodes) :
121 std::make_unique<HdCyclesSession>(GetSessionParams(settingsMap));
123 for (
const auto &setting : settingsMap) {
125 if (setting.first == HdCyclesRenderSettingsTokens->device ||
126 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) {
292 if (typeId == HdPrimTypeTokens->extComputation) {
293 return new HdExtComputation(sprimId);
296 TF_CODING_ERROR(
"Unknown Sprim type %s", typeId.GetText());
312 if (typeId == HdPrimTypeTokens->renderBuffer) {
316 if (typeId == _tokens->openvdbAsset) {
321 TF_CODING_ERROR(
"Unknown Bprim type %s", typeId.GetText());
341 _renderParam->UpdateScene();
346 return HdTokens->full;
349 #if HD_API_VERSION < 41
352 return _tokens->cycles;
355 TfTokenVector HdCyclesDelegate::GetMaterialRenderContexts()
const
357 return {_tokens->cycles};
363 const Stats &stats = _renderParam->session->stats;
364 const Progress &progress = _renderParam->session->progress;
366 double totalTime, renderTime;
367 progress.
get_time(totalTime, renderTime);
370 std::string status, substatus;
372 if (!substatus.empty()) {
373 status +=
" | " + substatus;
376 return {{
"rendererName", VtValue(
"Cycles")},
377 {
"rendererVersion", VtValue(GfVec3i(0, 0, 0))},
378 {
"percentDone", VtValue(
floor_to_int(fractionDone * 100))},
379 {
"fractionDone", VtValue(fractionDone)},
380 {
"loadClockTime", VtValue(totalTime - renderTime)},
381 {
"peakMemory", VtValue(stats.
mem_peak)},
382 {
"totalClockTime", VtValue(totalTime)},
383 {
"totalMemory", VtValue(stats.
mem_used)},
384 {
"renderProgressAnnotation", VtValue(status)}};
389 if (name == HdAovTokens->color) {
390 HdFormat colorFormat = HdFormatFloat32Vec4;
393 colorFormat = HdFormatFloat16Vec4;
396 return HdAovDescriptor(colorFormat,
false, VtValue(GfVec4f(0.0f)));
398 if (name == HdAovTokens->depth) {
399 return HdAovDescriptor(HdFormatFloat32,
false, VtValue(1.0f));
401 if (name == HdAovTokens->normal) {
402 return HdAovDescriptor(HdFormatFloat32Vec3,
false, VtValue(GfVec3f(0.0f)));
404 if (name == HdAovTokens->primId || name == HdAovTokens->instanceId ||
405 name == HdAovTokens->elementId) {
406 return HdAovDescriptor(HdFormatInt32,
false, VtValue(-1));
409 return HdAovDescriptor();
414 Scene *
const scene = _renderParam->session->scene;
416 HdRenderSettingDescriptorList descriptors;
418 descriptors.push_back({
420 HdCyclesRenderSettingsTokens->timeLimit,
423 descriptors.push_back({
425 HdCyclesRenderSettingsTokens->samples,
428 descriptors.push_back({
430 HdCyclesRenderSettingsTokens->sampleOffset,
435 descriptors.push_back({socket.
ui_name.string(),
436 TfToken(
"cycles:integrator:" + socket.
name.string()),
445 Scene *
const scene = _renderParam->session->scene;
446 Session *
const session = _renderParam->session;
448 if (key == HdCyclesRenderSettingsTokens->stageMetersPerUnit) {
449 _renderParam->SetStageMetersPerUnit(
450 VtValue::Cast<double>(value).GetWithDefault(_renderParam->GetStageMetersPerUnit()));
452 else if (key == HdCyclesRenderSettingsTokens->timeLimit) {
456 else if (key == HdCyclesRenderSettingsTokens->samples) {
458 int samples = VtValue::Cast<int>(value).GetWithDefault(session->
params.
samples);
462 else if (key == HdCyclesRenderSettingsTokens->sampleOffset) {
468 const std::string &keyString = key.GetString();
469 if (keyString.rfind(
"cycles:integrator:", 0) == 0) {
470 ustring socketName(keyString,
sizeof(
"cycles:integrator:") - 1);
481 Scene *
const scene = _renderParam->session->scene;
482 Session *
const session = _renderParam->session;
484 if (key == HdCyclesRenderSettingsTokens->stageMetersPerUnit) {
485 return VtValue(_renderParam->GetStageMetersPerUnit());
487 else if (key == HdCyclesRenderSettingsTokens->device) {
490 else if (key == HdCyclesRenderSettingsTokens->threads) {
493 else if (key == HdCyclesRenderSettingsTokens->timeLimit) {
496 else if (key == HdCyclesRenderSettingsTokens->samples) {
499 else if (key == HdCyclesRenderSettingsTokens->sampleOffset) {
503 const std::string &keyString = key.GetString();
504 if (keyString.rfind(
"cycles:integrator:", 0) == 0) {
505 ustring socketName(keyString,
sizeof(
"cycles:integrator:") - 1);
SIMD_FORCE_INLINE btVector3 transform(const btVector3 &point) const
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
vector< SocketType, std::allocator< SocketType > > inputs
const SocketType * find_input(ustring name) const
ccl_device_inline int floor_to_int(float f)