Blender V4.3
render_pass.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2022 NVIDIA Corporation
2 * SPDX-FileCopyrightText: 2022 Blender Foundation
3 *
4 * SPDX-License-Identifier: Apache-2.0 */
5
6#include "hydra/render_pass.h"
7#include "hydra/camera.h"
11#include "hydra/session.h"
12
13#ifdef WITH_HYDRA_DISPLAY_DRIVER
14# include "hydra/display_driver.h"
15#endif
16
17#include "scene/camera.h"
18#include "scene/integrator.h"
19#include "scene/scene.h"
20
21#include "session/session.h"
22
23#include <pxr/imaging/hd/renderPassState.h>
24
26
28 HdRprimCollection const &collection,
29 HdCyclesSession *renderParam)
30 : HdRenderPass(index, collection), _renderParam(renderParam)
31{
32 Session *const session = _renderParam->session;
33 // Reset cancel state so session thread can continue rendering
34 session->progress.reset();
35
36 session->set_output_driver(make_unique<HdCyclesOutputDriver>(renderParam));
37
38 const auto renderDelegate = static_cast<const HdCyclesDelegate *>(
39 GetRenderIndex()->GetRenderDelegate());
40 if (renderDelegate->IsDisplaySupported()) {
41#ifdef WITH_HYDRA_DISPLAY_DRIVER
42 session->set_display_driver(
43 make_unique<HdCyclesDisplayDriver>(renderParam, renderDelegate->GetHgi()));
44#endif
45 }
46}
47
49{
50 Session *const session = _renderParam->session;
51 session->cancel(true);
52}
53
55{
56 for (const HdRenderPassAovBinding &aovBinding : _renderParam->GetAovBindings()) {
57 if (aovBinding.renderBuffer && !aovBinding.renderBuffer->IsConverged()) {
58 return false;
59 }
60 }
61
62 return true;
63}
64
65void HdCyclesRenderPass::ResetConverged()
66{
67 for (const HdRenderPassAovBinding &aovBinding : _renderParam->GetAovBindings()) {
68 if (const auto renderBuffer = static_cast<HdCyclesRenderBuffer *>(aovBinding.renderBuffer)) {
69 renderBuffer->SetConverged(false);
70 }
71 }
72}
73
74void HdCyclesRenderPass::_Execute(const HdRenderPassStateSharedPtr &renderPassState,
75 const TfTokenVector &renderTags)
76{
77 Scene *const scene = _renderParam->session->scene;
78 Session *const session = _renderParam->session;
79
80 if (session->progress.get_cancel()) {
81 return; // Something went wrong and cannot continue without recreating the session
82 }
83
84 if (scene->mutex.try_lock()) {
85 const auto renderDelegate = static_cast<HdCyclesDelegate *>(
86 GetRenderIndex()->GetRenderDelegate());
87
88 const unsigned int settingsVersion = renderDelegate->GetRenderSettingsVersion();
89
90 // Update requested AOV bindings
91 const HdRenderPassAovBindingVector &aovBindings = renderPassState->GetAovBindings();
92 if (_renderParam->GetAovBindings() != aovBindings ||
93 // Need to resync passes when denoising is enabled or disabled to update the pass mode
94 (settingsVersion != _lastSettingsVersion && scene->integrator->use_denoise_is_modified()))
95 {
96 _renderParam->SyncAovBindings(aovBindings);
97
98 if (renderDelegate->IsDisplaySupported()) {
99 // Update display pass to the first requested color AOV
100 HdRenderPassAovBinding displayAovBinding = !aovBindings.empty() ? aovBindings.front() :
101 HdRenderPassAovBinding();
102 if (displayAovBinding.aovName == HdAovTokens->color && displayAovBinding.renderBuffer) {
103 _renderParam->SetDisplayAovBinding(displayAovBinding);
104 }
105 else {
106 _renderParam->SetDisplayAovBinding(HdRenderPassAovBinding());
107 }
108 }
109 }
110
111 // Update camera dimensions to the viewport size
112#if PXR_VERSION >= 2102
113 CameraUtilFraming framing = renderPassState->GetFraming();
114 if (!framing.IsValid()) {
115 const GfVec4f vp = renderPassState->GetViewport();
116 framing = CameraUtilFraming(GfRect2i(GfVec2i(0), int(vp[2]), int(vp[3])));
117 }
118
119 scene->camera->set_full_width(framing.dataWindow.GetWidth());
120 scene->camera->set_full_height(framing.dataWindow.GetHeight());
121#else
122 const GfVec4f vp = renderPassState->GetViewport();
123 scene->camera->set_full_width(int(vp[2]));
124 scene->camera->set_full_height(int(vp[3]));
125#endif
126
127 if (const auto camera = static_cast<const HdCyclesCamera *>(renderPassState->GetCamera())) {
128 camera->ApplyCameraSettings(_renderParam, scene->camera);
129 }
130 else {
132 renderPassState->GetWorldToViewMatrix(),
133 renderPassState->GetProjectionMatrix(),
134 renderPassState->GetClipPlanes(),
135 scene->camera);
136 }
137
138 // Reset session if the session, scene, camera or AOV bindings changed
139 if (scene->need_reset() || settingsVersion != _lastSettingsVersion) {
140 _lastSettingsVersion = settingsVersion;
141
142 // Reset convergence state of all render buffers
143 ResetConverged();
144
145 BufferParams buffer_params;
146#if PXR_VERSION >= 2102
147 buffer_params.full_x = static_cast<int>(framing.displayWindow.GetMin()[0]);
148 buffer_params.full_y = static_cast<int>(framing.displayWindow.GetMin()[1]);
149 buffer_params.full_width = static_cast<int>(framing.displayWindow.GetSize()[0]);
150 buffer_params.full_height = static_cast<int>(framing.displayWindow.GetSize()[1]);
151
152 buffer_params.window_x = framing.dataWindow.GetMinX() - buffer_params.full_x;
153 buffer_params.window_y = framing.dataWindow.GetMinY() - buffer_params.full_y;
154 buffer_params.window_width = framing.dataWindow.GetWidth();
155 buffer_params.window_height = framing.dataWindow.GetHeight();
156
157 buffer_params.width = buffer_params.window_width;
158 buffer_params.height = buffer_params.window_height;
159#else
160 buffer_params.width = static_cast<int>(vp[2]);
161 buffer_params.height = static_cast<int>(vp[3]);
162 buffer_params.full_width = buffer_params.width;
163 buffer_params.full_height = buffer_params.height;
164 buffer_params.window_width = buffer_params.width;
165 buffer_params.window_height = buffer_params.height;
166#endif
167
168 session->reset(session->params, buffer_params);
169 }
170
171 scene->mutex.unlock();
172
173 // Start Cycles render thread if not already running
174 session->start();
175 }
176
177 session->draw();
178}
179
180void HdCyclesRenderPass::_MarkCollectionDirty() {}
181
struct Scene Scene
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Gabor Generate Gabor noise Gradient Generate interpolated color and intensity values based on the input vector Magic Generate a psychedelic color texture Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a or normal between camera
int full_width
Definition buffers.h:87
int window_y
Definition buffers.h:80
int full_height
Definition buffers.h:88
int window_height
Definition buffers.h:82
int window_width
Definition buffers.h:81
NODE_DECLARE int width
Definition buffers.h:72
int window_x
Definition buffers.h:79
void ApplyCameraSettings(PXR_NS::HdRenderParam *renderParam, CCL_NS::Camera *targetCamera) const
~HdCyclesRenderPass() override
HdCyclesRenderPass(PXR_NS::HdRenderIndex *index, const PXR_NS::HdRprimCollection &collection, HdCyclesSession *renderParam)
bool IsConverged() const override
const PXR_NS::HdRenderPassAovBindingVector & GetAovBindings() const
bool get_cancel() const
Definition progress.h:93
void reset()
Definition progress.h:64
void cancel(bool quick=false)
Progress progress
SessionParams params
void reset(const SessionParams &session_params, const BufferParams &buffer_params)
void set_output_driver(unique_ptr< OutputDriver > driver)
#define HDCYCLES_NAMESPACE_CLOSE_SCOPE
Integrator * integrator
Definition scene.h:128
thread_mutex mutex
Definition scene.h:164
bool need_reset(const bool check_camera=true)
Definition scene.cpp:429
struct Object * camera