Fix review comments 2 #31

Merged
Bogdan Nagirniak merged 8 commits from BLEN-397 into hydra-render 2023-04-27 09:05:38 +02:00
7 changed files with 37 additions and 46 deletions
Showing only changes of commit 648e5e566c - Show all commits

View File

@ -18,12 +18,12 @@ namespace blender::render::hydra {
CLG_LOGREF_DECLARE_GLOBAL(LOG_RENDER_HYDRA, "render.hydra");
Engine::Engine(RenderEngine *bl_engine, const std::string &render_delegate_name)
: bl_engine_(bl_engine), render_delegate_name(render_delegate_name)
: bl_engine_(bl_engine), render_delegate_name_(render_delegate_name)
{
pxr::HdRendererPluginRegistry &registry = pxr::HdRendererPluginRegistry::GetInstance();
pxr::TF_PY_ALLOW_THREADS_IN_SCOPE();
render_delegate_ = registry.CreateRenderDelegate(pxr::TfToken(render_delegate_name));
render_delegate_ = registry.CreateRenderDelegate(pxr::TfToken(render_delegate_name_));
/* Current USD (23.02) has limited support for Vulkan. To make it works USD should be built
* with PXR_ENABLE_VULKAN_SUPPORT=TRUE which is not possible now */
@ -45,7 +45,7 @@ Engine::Engine(RenderEngine *bl_engine, const std::string &render_delegate_name)
render_index_.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("freeCamera"));
render_task_delegate_ = std::make_unique<RenderTaskDelegate>(
render_index_.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("renderTask"));
if (render_delegate_name == "HdStormRendererPlugin") {
if (render_delegate_name_ == "HdStormRendererPlugin") {
simple_light_task_delegate_ = std::make_unique<SimpleLightTaskDelegate>(
render_index_.get(),
pxr::SdfPath::AbsoluteRootPath().AppendElementString("simpleLightTask"));

View File

@ -33,12 +33,11 @@ class Engine {
pxr::HdRenderSettingsMap &render_settings) = 0;
virtual void render(Depsgraph *depsgraph) = 0;
std::string render_delegate_name;
protected:

move to protected

move to protected
float renderer_percent_done();
RenderEngine *bl_engine_;
std::string render_delegate_name_;
/* The order is important due to deletion order */
pxr::HgiUniquePtr hgi_;

View File

@ -21,7 +21,7 @@ void FinalEngine::sync(Depsgraph *depsgraph,
render_index_.get(),
pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"),
BlenderSceneDelegate::EngineType::FINAL,
render_delegate_name);
render_delegate_name_);
scene_delegate_->populate(depsgraph, context);
for (auto const &setting : render_settings) {
@ -33,6 +33,8 @@ void FinalEngine::render(Depsgraph *depsgraph)
{
prepare_for_render(depsgraph);
std::vector<float> &pixels = render_images_["Combined"];
{
/* Release the GIL before calling into hydra, in case any hydra plugins call into python. */
pxr::TF_PY_ALLOW_THREADS_IN_SCOPE();
@ -62,15 +64,15 @@ void FinalEngine::render(Depsgraph *depsgraph)
break;
}
render_task_delegate_->get_renderer_aov_data(pxr::HdAovTokens->color, pixels_->data());
update_render_result(render_images_, layer_name_, resolution_[0], resolution_[1]);
render_task_delegate_->get_renderer_aov_data(pxr::HdAovTokens->color, pixels.data());
update_render_result();
}
render_task_delegate_->get_renderer_aov_data(pxr::HdAovTokens->color, pixels_->data());
update_render_result(render_images_, layer_name_, resolution_[0], resolution_[1]);
render_task_delegate_->get_renderer_aov_data(pxr::HdAovTokens->color, pixels.data());
update_render_result();
}

rename to get_render_border

rename to `get_render_border`
pxr::GfVec4f FinalEngine::get_resolution(const Scene *scene)
pxr::GfVec4f FinalEngine::get_render_border(const Scene *scene)
{
const RenderData &r = scene->r;
float border_w = 1.0, border_h = 1.0;
@ -81,19 +83,16 @@ pxr::GfVec4f FinalEngine::get_resolution(const Scene *scene)
return pxr::GfVec4f(r.border.xmin, r.border.ymin, border_w, border_h);
}
void FinalEngine::update_render_result(std::map<std::string, std::vector<float>> &render_images,
const std::string &layer_name,
int width,
int height)
void FinalEngine::update_render_result()
{
RenderResult *result = RE_engine_begin_result(
bl_engine_, 0, 0, width, height, layer_name.c_str(), nullptr);
bl_engine_, 0, 0, resolution_[0], resolution_[1], layer_name_.c_str(), nullptr);
/* TODO: only for the first render layer */
RenderLayer *layer = (RenderLayer *)result->layers.first;
for (RenderPass *pass = (RenderPass *)layer->passes.first; pass != nullptr; pass = pass->next) {
auto it_image = render_images.find(pass->name);
if (it_image == render_images.end()) {
auto it_image = render_images_.find(pass->name);
if (it_image == render_images_.end()) {
continue;
}
memcpy(pass->rect,
@ -119,7 +118,7 @@ void FinalEngine::prepare_for_render(Depsgraph *depsgraph)
layer_name_ = view_layer->name;
const RenderData &r = scene->r;
pxr::GfVec4f border = get_resolution(scene);
pxr::GfVec4f border = get_render_border(scene);
pxr::GfVec2i image_res(r.xsch * r.size / 100, r.ysch * r.size / 100);
resolution_ = pxr::GfVec2i(int(image_res[0] * border[2]), int(image_res[1] * border[3]));
pxr::GfCamera camera =
@ -139,13 +138,14 @@ void FinalEngine::prepare_for_render(Depsgraph *depsgraph)
render_images_.emplace(
"Combined",
std::vector<float>(resolution_[0] * resolution_[1] * 4)); /* 4 - number of channels. */
pixels_ = &render_images_["Combined"];
}
void FinalEngineGL::render(Depsgraph *depsgraph)
{
prepare_for_render(depsgraph);
std::vector<float> &pixels = render_images_["Combined"];
GPUFrameBuffer *framebuffer = GPU_framebuffer_create("fb_hdyra_render_final");
GPUTexture *texture = GPU_texture_create_2d("tex_hydra_render_final",
resolution_[0],
@ -192,15 +192,15 @@ void FinalEngineGL::render(Depsgraph *depsgraph)
}
void *data = GPU_texture_read(texture, GPU_DATA_FLOAT, 0);
memcpy(pixels_->data(), data, pixels_->size() * sizeof(float));
memcpy(pixels.data(), data, pixels.size() * sizeof(float));
MEM_freeN(data);
update_render_result(render_images_, layer_name_, resolution_[0], resolution_[1]);
update_render_result();
}
void *data = GPU_texture_read(texture, GPU_DATA_FLOAT, 0);
memcpy(pixels_->data(), data, pixels_->size() * sizeof(float));
memcpy(pixels.data(), data, pixels.size() * sizeof(float));
MEM_freeN(data);
update_render_result(render_images_, layer_name_, resolution_[0], resolution_[1]);
update_render_result();

Simplify update_render_result - no need to provide parameters

Simplify `update_render_result` - no need to provide parameters
GPU_framebuffer_free(framebuffer);
GPU_texture_free(texture);

View File

@ -17,11 +17,8 @@ class FinalEngine : public Engine {
virtual void render(Depsgraph *b_depsgraph) override;
protected:
pxr::GfVec4f get_resolution(const Scene *scene);
void update_render_result(std::map<std::string, std::vector<float>> &render_images,
const std::string &layer_name,
int width,
int height);
pxr::GfVec4f get_render_border(const Scene *scene);
void update_render_result();
void notify_status(float progress, const std::string &title, const std::string &info);
void prepare_for_render(Depsgraph *depsgraph);
@ -31,7 +28,6 @@ class FinalEngine : public Engine {
std::string layer_name_;
std::map<std::string, std::vector<float>> render_images_;
pxr::GfVec2i resolution_;
std::vector<float> *pixels_ = nullptr;
};
class FinalEngineGL : public FinalEngine {

View File

@ -45,7 +45,7 @@ void PreviewEngine::sync(Depsgraph *depsgraph,
render_index_.get(),
pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"),
BlenderSceneDelegate::EngineType::PREVIEW,
render_delegate_name);
render_delegate_name_);
}
scene_delegate_->clear();
scene_delegate_->populate(depsgraph, context);
@ -59,6 +59,8 @@ void PreviewEngine::render(Depsgraph *depsgraph)
{
prepare_for_render(depsgraph);
std::vector<float> &pixels = render_images_["Combined"];
{
/* Release the GIL before calling into hydra, in case any hydra plugins call into python. */
pxr::TF_PY_ALLOW_THREADS_IN_SCOPE();
@ -74,12 +76,12 @@ void PreviewEngine::render(Depsgraph *depsgraph)
break;
}
render_task_delegate_->get_renderer_aov_data(pxr::HdAovTokens->color, pixels_->data());
update_render_result(layer_name_, resolution_[0], resolution_[1], pixels_);
render_task_delegate_->get_renderer_aov_data(pxr::HdAovTokens->color, pixels.data());
update_render_result(pixels);
}
render_task_delegate_->get_renderer_aov_data(pxr::HdAovTokens->color, pixels_->data());
update_render_result(layer_name_, resolution_[0], resolution_[1], pixels_);
render_task_delegate_->get_renderer_aov_data(pxr::HdAovTokens->color, pixels.data());
update_render_result(pixels);
}
double PreviewEngine::free_instance(uintptr_t uuid, void *user_data)
@ -100,17 +102,14 @@ void PreviewEngine::update(RenderEngine *bl_engine, const std::string &render_de
/* TODO: recreate render_delegate when render_delegate_id is changed */
}
void PreviewEngine::update_render_result(const std::string &layer_name,
int width,
int height,
std::vector<float> *pixels)
void PreviewEngine::update_render_result(std::vector<float> &pixels)
{
RenderResult *result = RE_engine_begin_result(
bl_engine_, 0, 0, width, height, layer_name.c_str(), nullptr);
bl_engine_, 0, 0, resolution_[0], resolution_[1], layer_name_.c_str(), nullptr);
RenderLayer *layer = (RenderLayer *)result->layers.first;
RenderPass *pass = (RenderPass *)layer->passes.first;
memcpy(pass->rect, pixels->data(), sizeof(float) * pass->rectx * pass->recty * pass->channels);
memcpy(pass->rect, pixels.data(), sizeof(float) * pass->rectx * pass->recty * pass->channels);
RE_engine_end_result(bl_engine_, result, false, false, false);
}

View File

@ -26,10 +26,7 @@ class PreviewEngine : public FinalEngine {
static std::unique_ptr<PreviewEngine> instance_;
void update(RenderEngine *bl_engine, const std::string &render_delegate_id);
void update_render_result(const std::string &layer_name,
int width,
int height,
std::vector<float> *pixels);
void update_render_result(std::vector<float> &pixels);
};
} // namespace blender::render::hydra

View File

@ -226,7 +226,7 @@ void ViewportEngine::sync(Depsgraph *depsgraph,
render_index_.get(),
pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"),
BlenderSceneDelegate::EngineType::VIEWPORT,
render_delegate_name);
render_delegate_name_);
}
scene_delegate_->populate(depsgraph, context);