Fix review comments #27

Merged
Bogdan Nagirniak merged 14 commits from BLEN-392 into hydra-render 2023-04-21 15:02:44 +02:00
22 changed files with 89 additions and 124 deletions

View File

@ -109,7 +109,7 @@ def export_mtlx(material):
if not doc: if not doc:
return "" return ""
mtlx_file = mx_utils.get_temp_file(".mtlx", material.name) mtlx_file = mx_utils.get_temp_file(".mtlx", f"mat_{material.as_pointer():016x}")

Use hex format for mtlx name like:
f"mat_{material.as_pointer():016x}"

Use hex format for mtlx name like: `f"mat_{material.as_pointer():016x}"`
mx_utils.export_to_file(doc, mtlx_file, export_deps=True, copy_deps=False) mx_utils.export_to_file(doc, mtlx_file, export_deps=True, copy_deps=False)
return str(mtlx_file) return str(mtlx_file)

View File

@ -8,11 +8,14 @@
#include <pxr/imaging/hgi/tokens.h> #include <pxr/imaging/hgi/tokens.h>
#include <pxr/usd/usdGeom/tokens.h> #include <pxr/usd/usdGeom/tokens.h>
#include "BLI_path_util.h"
#include "GPU_context.h"
#include "engine.h" #include "engine.h"
namespace blender::render::hydra { namespace blender::render::hydra {
CLG_LOGREF_DECLARE_GLOBAL(LOG_EN, "rhd.en"); CLG_LOGREF_DECLARE_GLOBAL(LOG_RENDER_HYDRA, "render.hydra");
Engine::Engine(RenderEngine *bl_engine, const std::string &delegate_id) : bl_engine_(bl_engine) Engine::Engine(RenderEngine *bl_engine, const std::string &delegate_id) : bl_engine_(bl_engine)
{ {
@ -21,6 +24,12 @@ Engine::Engine(RenderEngine *bl_engine, const std::string &delegate_id) : bl_eng
pxr::TF_PY_ALLOW_THREADS_IN_SCOPE(); pxr::TF_PY_ALLOW_THREADS_IN_SCOPE();
render_delegate_ = registry.CreateRenderDelegate(pxr::TfToken(delegate_id)); render_delegate_ = registry.CreateRenderDelegate(pxr::TfToken(delegate_id));
/* 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 */
if (GPU_backend_get_type() == GPU_BACKEND_VULKAN) {
BLI_setenv("HGI_ENABLE_VULKAN", "1");
}
pxr::HdDriverVector hd_drivers; pxr::HdDriverVector hd_drivers;
if (bl_engine->type->flag & RE_USE_GPU_CONTEXT) { if (bl_engine->type->flag & RE_USE_GPU_CONTEXT) {
hgi_ = pxr::Hgi::CreatePlatformDefaultHgi(); hgi_ = pxr::Hgi::CreatePlatformDefaultHgi();

View File

@ -21,7 +21,7 @@
namespace blender::render::hydra { namespace blender::render::hydra {
extern struct CLG_LogRef *LOG_EN; /* EN - Engine */ extern struct CLG_LogRef *LOG_RENDER_HYDRA; /* EN - Engine */
class Engine { class Engine {
public: public:

View File

@ -2,13 +2,14 @@
* Copyright 2011-2022 Blender Foundation */ * Copyright 2011-2022 Blender Foundation */
#include "BKE_lib_id.h" #include "BKE_lib_id.h"
#include "BLI_timecode.h"
#include "DEG_depsgraph_query.h" #include "DEG_depsgraph_query.h"
#include "GPU_framebuffer.h" #include "GPU_framebuffer.h"
#include "GPU_texture.h" #include "GPU_texture.h"
#include "PIL_time.h"
#include "camera.h" #include "camera.h"
#include "final_engine.h" #include "final_engine.h"
#include "utils.h"
namespace blender::render::hydra { namespace blender::render::hydra {
@ -63,12 +64,6 @@ void FinalEngine::render(Depsgraph *depsgraph)
} }
tasks.push_back(render_task_delegate_->get_task()); tasks.push_back(render_task_delegate_->get_task());
std::chrono::time_point<std::chrono::steady_clock> time_begin = std::chrono::steady_clock::now(),
time_current;
std::chrono::milliseconds elapsed_time;
float percent_done = 0.0;
std::map<std::string, std::vector<float>> render_images{ std::map<std::string, std::vector<float>> render_images{
{"Combined", std::vector<float>(res[0] * res[1] * 4)}}; /* 4 - number of channels. */ {"Combined", std::vector<float>(res[0] * res[1] * 4)}}; /* 4 - number of channels. */
std::vector<float> &pixels = render_images["Combined"]; std::vector<float> &pixels = render_images["Combined"];
@ -79,19 +74,23 @@ void FinalEngine::render(Depsgraph *depsgraph)
engine_->Execute(render_index_.get(), &tasks); engine_->Execute(render_index_.get(), &tasks);
} }
char elapsed_time[32];
double time_begin = PIL_check_seconds_timer();
float percent_done = 0.0;
while (true) { while (true) {
if (RE_engine_test_break(bl_engine_)) { if (RE_engine_test_break(bl_engine_)) {
break; break;
} }
percent_done = renderer_percent_done(); percent_done = renderer_percent_done();
time_current = std::chrono::steady_clock::now();
elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(time_current - BLI_timecode_string_from_time_simple(
time_begin); elapsed_time, sizeof(elapsed_time), PIL_check_seconds_timer() - time_begin);
notify_status(percent_done / 100.0, notify_status(percent_done / 100.0,
scene_name + ": " + layer_name, scene_name + ": " + layer_name,
"Render Time: " + format_duration(elapsed_time) + std::string("Render Time: ") + elapsed_time +
" | Done: " + std::to_string(int(percent_done)) + "%"); " | Done: " + std::to_string(int(percent_done)) + "%");
if (render_task_delegate_->is_converged()) { if (render_task_delegate_->is_converged()) {
@ -185,12 +184,6 @@ void FinalEngineGL::render(Depsgraph *depsgraph)
} }
tasks.push_back(render_task_delegate_->get_task()); tasks.push_back(render_task_delegate_->get_task());
std::chrono::time_point<std::chrono::steady_clock> time_begin = std::chrono::steady_clock::now(),
time_current;
std::chrono::milliseconds elapsed_time;
float percent_done = 0.0;
std::map<std::string, std::vector<float>> render_images{ std::map<std::string, std::vector<float>> render_images{
{"Combined", std::vector<float>(res[0] * res[1] * 4)}}; /* 4 - number of channels. */ {"Combined", std::vector<float>(res[0] * res[1] * 4)}}; /* 4 - number of channels. */
std::vector<float> &pixels = render_images["Combined"]; std::vector<float> &pixels = render_images["Combined"];
@ -217,19 +210,23 @@ void FinalEngineGL::render(Depsgraph *depsgraph)
engine_->Execute(render_index_.get(), &tasks); engine_->Execute(render_index_.get(), &tasks);
} }
char elapsed_time[32];
double time_begin = PIL_check_seconds_timer();
float percent_done = 0.0;
while (true) { while (true) {
if (RE_engine_test_break(bl_engine_)) { if (RE_engine_test_break(bl_engine_)) {
break; break;
} }
percent_done = renderer_percent_done(); percent_done = renderer_percent_done();
time_current = std::chrono::steady_clock::now();
elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(time_current - BLI_timecode_string_from_time_simple(
time_begin); elapsed_time, sizeof(elapsed_time), PIL_check_seconds_timer() - time_begin);
notify_status(percent_done / 100.0, notify_status(percent_done / 100.0,
scene_name + ": " + layer_name, scene_name + ": " + layer_name,
"Render Time: " + format_duration(elapsed_time) + std::string("Render Time: ") + elapsed_time +
" | Done: " + std::to_string(int(percent_done)) + "%"); " | Done: " + std::to_string(int(percent_done)) + "%");
if (render_task_delegate_->is_converged()) { if (render_task_delegate_->is_converged()) {

View File

@ -3,8 +3,6 @@
#pragma once #pragma once
#include <chrono>
#include "engine.h" #include "engine.h"
namespace blender::render::hydra { namespace blender::render::hydra {

View File

@ -109,7 +109,7 @@ double PreviewEngine::free_instance(uintptr_t uuid, void *user_data)
return LIFETIME; return LIFETIME;
} }
CLOG_INFO(LOG_EN, 2, ""); CLOG_INFO(LOG_RENDER_HYDRA, 2, "");
instance_ = nullptr; instance_ = nullptr;
return -1; return -1;
} }

View File

@ -22,7 +22,7 @@ namespace blender::render::hydra {
static PyObject *init_func(PyObject * /*self*/, PyObject *args) static PyObject *init_func(PyObject * /*self*/, PyObject *args)
{ {
CLOG_INFO(LOG_EN, 1, "Init"); CLOG_INFO(LOG_RENDER_HYDRA, 1, "Init");
pxr::PlugRegistry::GetInstance().RegisterPlugins(std::string(BKE_appdir_program_dir()) + pxr::PlugRegistry::GetInstance().RegisterPlugins(std::string(BKE_appdir_program_dir()) +
"/blender.shared/usd"); "/blender.shared/usd");
@ -59,7 +59,7 @@ static PyObject *register_plugins_func(PyObject * /*self*/, PyObject *args)
ss << s << ", "; ss << s << ", ";
} }
ss << "]"; ss << "]";
CLOG_INFO(LOG_EN, 1, "Register %s", ss.str().c_str()); CLOG_INFO(LOG_RENDER_HYDRA, 1, "Register %s", ss.str().c_str());
Py_RETURN_NONE; Py_RETURN_NONE;
} }
@ -125,7 +125,7 @@ static PyObject *engine_create_func(PyObject * /*self*/, PyObject *args)
} }
} }
CLOG_INFO(LOG_EN, 2, "Engine %016llx %s", engine, engine_type); CLOG_INFO(LOG_RENDER_HYDRA, 2, "Engine %016llx %s", engine, engine_type);
return PyLong_FromVoidPtr(engine); return PyLong_FromVoidPtr(engine);
} }
@ -146,7 +146,7 @@ static PyObject *engine_free_func(PyObject * /*self*/, PyObject *args)
delete engine; delete engine;
} }
CLOG_INFO(LOG_EN, 2, "Engine %016llx", engine); CLOG_INFO(LOG_RENDER_HYDRA, 2, "Engine %016llx", engine);
Py_RETURN_NONE; Py_RETURN_NONE;
} }
@ -185,7 +185,7 @@ static PyObject *engine_sync_func(PyObject * /*self*/, PyObject *args)
engine->sync(depsgraph, context, settings); engine->sync(depsgraph, context, settings);
CLOG_INFO(LOG_EN, 2, "Engine %016llx", engine); CLOG_INFO(LOG_RENDER_HYDRA, 2, "Engine %016llx", engine);
Py_RETURN_NONE; Py_RETURN_NONE;
} }
@ -205,7 +205,7 @@ static PyObject *engine_render_func(PyObject * /*self*/, PyObject *args)
engine->render(depsgraph); engine->render(depsgraph);
Py_END_ALLOW_THREADS; Py_END_ALLOW_THREADS;
CLOG_INFO(LOG_EN, 2, "Engine %016llx", engine); CLOG_INFO(LOG_RENDER_HYDRA, 2, "Engine %016llx", engine);
Py_RETURN_NONE; Py_RETURN_NONE;
} }
@ -225,7 +225,7 @@ static PyObject *engine_view_draw_func(PyObject * /*self*/, PyObject *args)
engine->render(depsgraph, context); engine->render(depsgraph, context);
Py_END_ALLOW_THREADS; Py_END_ALLOW_THREADS;
CLOG_INFO(LOG_EN, 3, "Engine %016llx", engine); CLOG_INFO(LOG_RENDER_HYDRA, 3, "Engine %016llx", engine);
Py_RETURN_NONE; Py_RETURN_NONE;
} }

View File

@ -11,7 +11,7 @@
namespace blender::render::hydra { namespace blender::render::hydra {
CLG_LOGREF_DECLARE_GLOBAL(LOG_BSD, "rhd.bsd"); CLG_LOGREF_DECLARE_GLOBAL(LOG_RENDER_HYDRA_SCENE, "render.hydra.scene");
BlenderSceneDelegate::BlenderSceneDelegate(pxr::HdRenderIndex *parent_index, BlenderSceneDelegate::BlenderSceneDelegate(pxr::HdRenderIndex *parent_index,
pxr::SdfPath const &delegate_id, pxr::SdfPath const &delegate_id,
@ -22,14 +22,14 @@ BlenderSceneDelegate::BlenderSceneDelegate(pxr::HdRenderIndex *parent_index,
pxr::HdMeshTopology BlenderSceneDelegate::GetMeshTopology(pxr::SdfPath const &id) pxr::HdMeshTopology BlenderSceneDelegate::GetMeshTopology(pxr::SdfPath const &id)
{ {
CLOG_INFO(LOG_BSD, 3, "%s", id.GetText()); CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s", id.GetText());
MeshData *m_data = mesh_data(id); MeshData *m_data = mesh_data(id);
return m_data->mesh_topology(); return m_data->mesh_topology();
} }
pxr::GfMatrix4d BlenderSceneDelegate::GetTransform(pxr::SdfPath const &id) pxr::GfMatrix4d BlenderSceneDelegate::GetTransform(pxr::SdfPath const &id)
{ {
CLOG_INFO(LOG_BSD, 3, "%s", id.GetText()); CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s", id.GetText());
ObjectData *obj_data = object_data(id); ObjectData *obj_data = object_data(id);
if (obj_data) { if (obj_data) {
return obj_data->transform; return obj_data->transform;
@ -44,7 +44,7 @@ pxr::GfMatrix4d BlenderSceneDelegate::GetTransform(pxr::SdfPath const &id)
pxr::VtValue BlenderSceneDelegate::Get(pxr::SdfPath const &id, pxr::TfToken const &key) pxr::VtValue BlenderSceneDelegate::Get(pxr::SdfPath const &id, pxr::TfToken const &key)
{ {
CLOG_INFO(LOG_BSD, 3, "%s, %s", id.GetText(), key.GetText()); CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s, %s", id.GetText(), key.GetText());
ObjectData *obj_data = object_data(id); ObjectData *obj_data = object_data(id);
if (obj_data) { if (obj_data) {
@ -80,7 +80,7 @@ pxr::VtValue BlenderSceneDelegate::GetLightParamValue(pxr::SdfPath const &id,
pxr::HdPrimvarDescriptorVector BlenderSceneDelegate::GetPrimvarDescriptors( pxr::HdPrimvarDescriptorVector BlenderSceneDelegate::GetPrimvarDescriptors(
pxr::SdfPath const &id, pxr::HdInterpolation interpolation) pxr::SdfPath const &id, pxr::HdInterpolation interpolation)
{ {
CLOG_INFO(LOG_BSD, 3, "%s, %d", id.GetText(), interpolation); CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s, %d", id.GetText(), interpolation);
MeshData *m_data = mesh_data(id); MeshData *m_data = mesh_data(id);
if (m_data) { if (m_data) {
@ -120,7 +120,7 @@ bool BlenderSceneDelegate::GetVisible(pxr::SdfPath const &id)
pxr::SdfPath BlenderSceneDelegate::GetInstancerId(pxr::SdfPath const &prim_id) pxr::SdfPath BlenderSceneDelegate::GetInstancerId(pxr::SdfPath const &prim_id)
{ {
CLOG_INFO(LOG_BSD, 3, "%s", prim_id.GetText()); CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s", prim_id.GetText());
InstancerData *i_data = instancer_data(prim_id.GetParentPath()); InstancerData *i_data = instancer_data(prim_id.GetParentPath());
if (i_data) { if (i_data) {
return i_data->prim_id; return i_data->prim_id;
@ -130,7 +130,7 @@ pxr::SdfPath BlenderSceneDelegate::GetInstancerId(pxr::SdfPath const &prim_id)
pxr::SdfPathVector BlenderSceneDelegate::GetInstancerPrototypes(pxr::SdfPath const &instancer_id) pxr::SdfPathVector BlenderSceneDelegate::GetInstancerPrototypes(pxr::SdfPath const &instancer_id)
{ {
CLOG_INFO(LOG_BSD, 3, "%s", instancer_id.GetText()); CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s", instancer_id.GetText());
InstancerData *i_data = instancer_data(instancer_id); InstancerData *i_data = instancer_data(instancer_id);
return i_data->prototypes(); return i_data->prototypes();
} }
@ -138,14 +138,14 @@ pxr::SdfPathVector BlenderSceneDelegate::GetInstancerPrototypes(pxr::SdfPath con
pxr::VtIntArray BlenderSceneDelegate::GetInstanceIndices(pxr::SdfPath const &instancer_id, pxr::VtIntArray BlenderSceneDelegate::GetInstanceIndices(pxr::SdfPath const &instancer_id,
pxr::SdfPath const &prototype_id) pxr::SdfPath const &prototype_id)
{ {
CLOG_INFO(LOG_BSD, 3, "%s, %s", instancer_id.GetText(), prototype_id.GetText()); CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s, %s", instancer_id.GetText(), prototype_id.GetText());
InstancerData *i_data = instancer_data(instancer_id); InstancerData *i_data = instancer_data(instancer_id);
return i_data->indices(prototype_id); return i_data->indices(prototype_id);
} }
pxr::GfMatrix4d BlenderSceneDelegate::GetInstancerTransform(pxr::SdfPath const &instancer_id) pxr::GfMatrix4d BlenderSceneDelegate::GetInstancerTransform(pxr::SdfPath const &instancer_id)
{ {
CLOG_INFO(LOG_BSD, 3, "%s", instancer_id.GetText()); CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s", instancer_id.GetText());
InstancerData *i_data = instancer_data(instancer_id); InstancerData *i_data = instancer_data(instancer_id);
return i_data->transform; return i_data->transform;
} }
@ -336,8 +336,11 @@ void BlenderSceneDelegate::check_updates()
ITER_BEGIN ( ITER_BEGIN (
DEG_iterator_ids_begin, DEG_iterator_ids_next, DEG_iterator_ids_end, &data, ID *, id) { DEG_iterator_ids_begin, DEG_iterator_ids_next, DEG_iterator_ids_end, &data, ID *, id) {
CLOG_INFO( CLOG_INFO(LOG_RENDER_HYDRA_SCENE,
LOG_BSD, 2, "Update: %s [%s]", id->name, std::bitset<32>(id->recalc).to_string().c_str()); 2,
"Update: %s [%s]",
id->name,
std::bitset<32>(id->recalc).to_string().c_str());
switch (GS(id->name)) { switch (GS(id->name)) {
case ID_OB: { case ID_OB: {

View File

@ -18,7 +18,7 @@
namespace blender::render::hydra { namespace blender::render::hydra {
extern struct CLG_LogRef *LOG_BSD; /* BSD - Blender Scene Delegate */ extern struct CLG_LogRef *LOG_RENDER_HYDRA_SCENE; /* BSD - Blender Scene Delegate */
class BlenderSceneDelegate : public pxr::HdSceneDelegate { class BlenderSceneDelegate : public pxr::HdSceneDelegate {
friend MeshData; /* has access to materials_*/ friend MeshData; /* has access to materials_*/

View File

@ -39,6 +39,7 @@ template<class T> const T IdData::get_data(pxr::TfToken const &key) const
} }
#define ID_LOG(level, msg, ...) \ #define ID_LOG(level, msg, ...) \
CLOG_INFO(LOG_BSD, level, "%s (%s): " msg, prim_id.GetText(), id->name, __VA_ARGS__); CLOG_INFO( \
LOG_RENDER_HYDRA_SCENE, level, "%s (%s): " msg, prim_id.GetText(), id->name, __VA_ARGS__);
} // namespace blender::render::hydra } // namespace blender::render::hydra

View File

@ -59,7 +59,7 @@ void InstancerData::insert()
void InstancerData::remove() void InstancerData::remove()
{ {
CLOG_INFO(LOG_BSD, 2, "%s", prim_id.GetText()); CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 2, "%s", prim_id.GetText());
for (auto &it : instances_) { for (auto &it : instances_) {
it.second.obj_data->remove(); it.second.obj_data->remove();
} }

View File

@ -85,7 +85,7 @@ void LightData::init()
/* TODO: temporary value, it should be delivered through Python UI */ /* TODO: temporary value, it should be delivered through Python UI */
data_[pxr::HdLightTokens->exposure] = 1.0f; data_[pxr::HdLightTokens->exposure] = 1.0f;
set_transform_to_object(); write_transform();
} }
void LightData::insert() void LightData::insert()
@ -96,7 +96,7 @@ void LightData::insert()
void LightData::remove() void LightData::remove()
{ {
CLOG_INFO(LOG_BSD, 2, "%s", prim_id.GetText()); CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 2, "%s", prim_id.GetText());
scene_delegate_->GetRenderIndex().RemoveSprim(prim_type_, prim_id); scene_delegate_->GetRenderIndex().RemoveSprim(prim_type_, prim_id);
} }
@ -118,7 +118,7 @@ void LightData::update()
bits = pxr::HdLight::AllDirty; bits = pxr::HdLight::AllDirty;
} }
else if (id->recalc & ID_RECALC_TRANSFORM) { else if (id->recalc & ID_RECALC_TRANSFORM) {
set_transform_to_object(); write_transform();
bits = pxr::HdLight::DirtyTransform; bits = pxr::HdLight::DirtyTransform;
} }
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkSprimDirty(prim_id, bits); scene_delegate_->GetRenderIndex().GetChangeTracker().MarkSprimDirty(prim_id, bits);

View File

@ -68,7 +68,7 @@ void MaterialData::init()
Py_DECREF(result); Py_DECREF(result);
} }
else { else {
CLOG_ERROR(LOG_BSD, "Export error for %s", id->name); CLOG_ERROR(LOG_RENDER_HYDRA_SCENE, "Export error for %s", id->name);
PyErr_Print(); PyErr_Print();
} }
Py_DECREF(module); Py_DECREF(module);
@ -103,7 +103,7 @@ void MaterialData::insert()
void MaterialData::remove() void MaterialData::remove()
{ {
CLOG_INFO(LOG_BSD, 2, "%s", prim_id.GetText()); CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 2, "%s", prim_id.GetText());
scene_delegate_->GetRenderIndex().RemoveSprim(pxr::HdPrimTypeTokens->material, prim_id); scene_delegate_->GetRenderIndex().RemoveSprim(pxr::HdPrimTypeTokens->material, prim_id);
} }

View File

@ -40,7 +40,7 @@ void MeshData::init()
} }
write_material(); write_material();
set_transform_to_object(); write_transform();
} }
void MeshData::insert() void MeshData::insert()
@ -60,7 +60,7 @@ void MeshData::remove()
return; return;
} }
CLOG_INFO(LOG_BSD, 2, "%s", prim_id.GetText()); CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 2, "%s", prim_id.GetText());
scene_delegate_->GetRenderIndex().RemoveRprim(prim_id); scene_delegate_->GetRenderIndex().RemoveRprim(prim_id);
} }
@ -78,7 +78,7 @@ void MeshData::update()
bits |= pxr::HdChangeTracker::DirtyMaterialId; bits |= pxr::HdChangeTracker::DirtyMaterialId;
} }
if (id->recalc & ID_RECALC_TRANSFORM) { if (id->recalc & ID_RECALC_TRANSFORM) {
set_transform_to_object(); write_transform();
bits |= pxr::HdChangeTracker::DirtyTransform; bits |= pxr::HdChangeTracker::DirtyTransform;
} }
} }

View File

@ -79,7 +79,7 @@ bool ObjectData::update_visibility()
return ret; return ret;
} }
void ObjectData::set_transform_to_object() void ObjectData::write_transform()
{ {
transform = gf_matrix_from_transform(((Object *)id)->object_to_world); transform = gf_matrix_from_transform(((Object *)id)->object_to_world);
} }

View File

@ -29,7 +29,7 @@ class ObjectData : public IdData {
bool visible; bool visible;
protected: protected:
void set_transform_to_object(); void write_transform();
}; };
using ObjectDataMap = using ObjectDataMap =

View File

@ -49,7 +49,7 @@ void WorldData::init()
{ {
ID_LOG(2, ""); ID_LOG(2, "");
set_transform(); write_transform();
World *world = (World *)id; World *world = (World *)id;
data_.clear(); data_.clear();
@ -129,7 +129,7 @@ void WorldData::insert()
void WorldData::remove() void WorldData::remove()
{ {
CLOG_INFO(LOG_BSD, 2, "%s", prim_id.GetText()); CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 2, "%s", prim_id.GetText());
scene_delegate_->GetRenderIndex().RemoveSprim(pxr::HdPrimTypeTokens->domeLight, prim_id); scene_delegate_->GetRenderIndex().RemoveSprim(pxr::HdPrimTypeTokens->domeLight, prim_id);
} }
@ -157,7 +157,7 @@ pxr::VtValue WorldData::get_data(pxr::TfToken const &key) const
return ret; return ret;
} }
void WorldData::set_transform() void WorldData::write_transform()
{ {
transform = pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(1.0, 0.0, 0.0), -90), pxr::GfVec3d()); transform = pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(1.0, 0.0, 0.0), -90), pxr::GfVec3d());

View File

@ -37,7 +37,7 @@ class WorldData : public IdData {
pxr::GfMatrix4d transform; pxr::GfMatrix4d transform;
private: private:
void set_transform(); void write_transform();
std::map<pxr::TfToken, pxr::VtValue> data_; std::map<pxr::TfToken, pxr::VtValue> data_;
}; };

View File

@ -1,9 +1,7 @@
/* SPDX-License-Identifier: Apache-2.0 /* SPDX-License-Identifier: Apache-2.0
* Copyright 2011-2022 Blender Foundation */ * Copyright 2011-2022 Blender Foundation */
#include <chrono>
#include <filesystem> #include <filesystem>
#include <sstream>
#include <pxr/base/tf/stringUtils.h> #include <pxr/base/tf/stringUtils.h>
@ -29,35 +27,6 @@ pxr::GfMatrix4d gf_matrix_from_transform(float m[4][4])
return ret; return ret;
} }
std::string format_duration(std::chrono::milliseconds millisecs)
{
std::stringstream ss;
bool neg = millisecs < std::chrono::milliseconds(0);
if (neg) {
millisecs = -millisecs;
}
auto m = std::chrono::duration_cast<std::chrono::minutes>(millisecs);
millisecs -= m;
auto s = std::chrono::duration_cast<std::chrono::seconds>(millisecs);
millisecs -= s;
if (neg) {
ss << "-";
}
if (m < std::chrono::minutes(10)) {
ss << "0";
}
ss << std::to_string(m / std::chrono::minutes(1)) << ":";
if (s < std::chrono::seconds(10)) {
ss << "0";
}
ss << std::to_string(s / std::chrono::seconds(1)) << ":";
if (millisecs < std::chrono::milliseconds(10)) {
ss << "0";
}
ss << std::to_string(millisecs / std::chrono::milliseconds(1) / 10);
return ss.str();
}
std::string cache_image(Main *bmain, std::string cache_image(Main *bmain,
Scene *scene, Scene *scene,
Image *image, Image *image,
@ -65,8 +34,7 @@ std::string cache_image(Main *bmain,
ImageSaveOptions *opts, ImageSaveOptions *opts,
ReportList *reports) ReportList *reports)
{ {
const std::string default_format = ".png"; const char *default_format = ".png";
char tempfile[FILE_MAX]; char tempfile[FILE_MAX];
if (!BKE_image_save_options_init(opts, bmain, scene, image, iuser, true, false)) { if (!BKE_image_save_options_init(opts, bmain, scene, image, iuser, true, false)) {
@ -74,20 +42,13 @@ std::string cache_image(Main *bmain,
return ""; return "";
} }
std::string image_name; char image_name[32];
snprintf(image_name, 32, "img_%016llx", (uint64_t)image);

Use hex format for image name like:

char str[32];
snprintf(str, 32, "img_%016llx", (uint64_t)image);
Use hex format for image name like: ``` char str[32]; snprintf(str, 32, "img_%016llx", (uint64_t)image); ```
if (image->source == IMA_SRC_GENERATED) { strcat(image_name, default_format);
image_name = pxr::TfMakeValidIdentifier(image_name.append(image->id.name + 2));
}
else {
image_name = image->filepath == NULL ? image->filepath : image->id.name + 2;
image_name = std::filesystem::path(image_name).filename().replace_extension().string();
image_name = pxr::TfMakeValidIdentifier(image_name);
}
image_name.append(default_format); BLI_path_join(
tempfile, sizeof(tempfile), BKE_tempdir_session(), "hydra_image_cache", image_name);
BLI_path_join(tempfile, sizeof(tempfile), BKE_tempdir_session(), image_name.c_str());
STRNCPY(opts->filepath, tempfile); STRNCPY(opts->filepath, tempfile);
if (!BKE_image_save(reports, bmain, image, iuser, opts)) { if (!BKE_image_save(reports, bmain, image, iuser, opts)) {

View File

@ -3,7 +3,6 @@
#pragma once #pragma once
#include <chrono>
#include <string> #include <string>
#include <pxr/base/gf/matrix4d.h> #include <pxr/base/gf/matrix4d.h>
@ -14,7 +13,6 @@
namespace blender::render::hydra { namespace blender::render::hydra {
pxr::GfMatrix4d gf_matrix_from_transform(float m[4][4]); pxr::GfMatrix4d gf_matrix_from_transform(float m[4][4]);
std::string format_duration(std::chrono::milliseconds secs);
std::string cache_image(Main *bmain, std::string cache_image(Main *bmain,
Scene *scene, Scene *scene,
Image *image, Image *image,

View File

@ -12,13 +12,15 @@
#include "BKE_camera.h" #include "BKE_camera.h"
#include "BLI_math_matrix.h" #include "BLI_math_matrix.h"
#include "BLI_timecode.h"
#include "DEG_depsgraph_query.h" #include "DEG_depsgraph_query.h"
#include "GPU_matrix.h" #include "GPU_matrix.h"
#include "PIL_time.h"
#include "camera.h" #include "camera.h"
#include "utils.h"
#include "viewport_engine.h" #include "viewport_engine.h"
namespace blender::render::hydra { namespace blender::render::hydra {
@ -259,10 +261,6 @@ void ViewportEngine::render(Depsgraph *depsgraph, bContext *context)
render_task_delegate_->set_renderer_aov(pxr::HdAovTokens->color); render_task_delegate_->set_renderer_aov(pxr::HdAovTokens->color);
} }
if (renderer_percent_done() == 0.0f) {
time_begin_ = std::chrono::steady_clock::now();
}
GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_IMAGE); GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_IMAGE);
GPU_shader_bind(shader); GPU_shader_bind(shader);
@ -285,21 +283,23 @@ void ViewportEngine::render(Depsgraph *depsgraph, bContext *context)
GPU_shader_unbind(); GPU_shader_unbind();
std::chrono::time_point<std::chrono::steady_clock> time_current = if (renderer_percent_done() == 0.0f) {
std::chrono::steady_clock::now(); time_begin_ = PIL_check_seconds_timer();
std::chrono::milliseconds elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>( }
time_current - time_begin_);
std::string formatted_time = format_duration(elapsed_time); char elapsed_time[32];
BLI_timecode_string_from_time_simple(
elapsed_time, sizeof(elapsed_time), PIL_check_seconds_timer() - time_begin_);
if (!render_task_delegate_->is_converged()) { if (!render_task_delegate_->is_converged()) {
notify_status("Time: " + formatted_time + notify_status(std::string("Time: ") + elapsed_time +
" | Done: " + std::to_string(int(renderer_percent_done())) + "%", " | Done: " + std::to_string(int(renderer_percent_done())) + "%",
"Render"); "Render");
bl_engine_->flag |= RE_ENGINE_DO_DRAW; bl_engine_->flag |= RE_ENGINE_DO_DRAW;
} }
else { else {
notify_status(("Time: " + formatted_time).c_str(), "Rendering Done"); notify_status((std::string("Time: ") + elapsed_time).c_str(), "Rendering Done");
} }
} }

View File

@ -3,8 +3,6 @@
#pragma once #pragma once
#include <chrono>
#include <pxr/imaging/hd/renderBuffer.h> #include <pxr/imaging/hd/renderBuffer.h>
#include "GPU_batch.h" #include "GPU_batch.h"
@ -46,7 +44,7 @@ class ViewportEngine : public Engine {
void notify_status(const std::string &title, const std::string &info); void notify_status(const std::string &title, const std::string &info);
private: private:
std::chrono::time_point<std::chrono::steady_clock> time_begin_; double time_begin_;
DrawTexture draw_texture_; DrawTexture draw_texture_;
}; };