diff --git a/scripts/modules/bpy_hydra.py b/scripts/modules/bpy_hydra.py index 07eaa455912e..3923a78d6bcc 100644 --- a/scripts/modules/bpy_hydra.py +++ b/scripts/modules/bpy_hydra.py @@ -109,7 +109,7 @@ def export_mtlx(material): if not doc: 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}") mx_utils.export_to_file(doc, mtlx_file, export_deps=True, copy_deps=False) return str(mtlx_file) diff --git a/source/blender/render/hydra/engine.cc b/source/blender/render/hydra/engine.cc index 26026dad49ea..fdcbf0903785 100644 --- a/source/blender/render/hydra/engine.cc +++ b/source/blender/render/hydra/engine.cc @@ -8,11 +8,14 @@ #include #include +#include "BLI_path_util.h" +#include "GPU_context.h" + #include "engine.h" 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) { @@ -21,6 +24,12 @@ Engine::Engine(RenderEngine *bl_engine, const std::string &delegate_id) : bl_eng pxr::TF_PY_ALLOW_THREADS_IN_SCOPE(); 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; if (bl_engine->type->flag & RE_USE_GPU_CONTEXT) { hgi_ = pxr::Hgi::CreatePlatformDefaultHgi(); diff --git a/source/blender/render/hydra/engine.h b/source/blender/render/hydra/engine.h index 2f129a6fb4e8..2bd760c1537d 100644 --- a/source/blender/render/hydra/engine.h +++ b/source/blender/render/hydra/engine.h @@ -21,7 +21,7 @@ namespace blender::render::hydra { -extern struct CLG_LogRef *LOG_EN; /* EN - Engine */ +extern struct CLG_LogRef *LOG_RENDER_HYDRA; /* EN - Engine */ class Engine { public: diff --git a/source/blender/render/hydra/final_engine.cc b/source/blender/render/hydra/final_engine.cc index f2b8286fc04c..768934b9ffca 100644 --- a/source/blender/render/hydra/final_engine.cc +++ b/source/blender/render/hydra/final_engine.cc @@ -2,13 +2,14 @@ * Copyright 2011-2022 Blender Foundation */ #include "BKE_lib_id.h" +#include "BLI_timecode.h" #include "DEG_depsgraph_query.h" #include "GPU_framebuffer.h" #include "GPU_texture.h" +#include "PIL_time.h" #include "camera.h" #include "final_engine.h" -#include "utils.h" namespace blender::render::hydra { @@ -63,12 +64,6 @@ void FinalEngine::render(Depsgraph *depsgraph) } tasks.push_back(render_task_delegate_->get_task()); - std::chrono::time_point time_begin = std::chrono::steady_clock::now(), - time_current; - std::chrono::milliseconds elapsed_time; - - float percent_done = 0.0; - std::map> render_images{ {"Combined", std::vector(res[0] * res[1] * 4)}}; /* 4 - number of channels. */ std::vector &pixels = render_images["Combined"]; @@ -79,19 +74,23 @@ void FinalEngine::render(Depsgraph *depsgraph) engine_->Execute(render_index_.get(), &tasks); } + char elapsed_time[32]; + double time_begin = PIL_check_seconds_timer(); + float percent_done = 0.0; + while (true) { if (RE_engine_test_break(bl_engine_)) { break; } percent_done = renderer_percent_done(); - time_current = std::chrono::steady_clock::now(); - elapsed_time = std::chrono::duration_cast(time_current - - time_begin); + + BLI_timecode_string_from_time_simple( + elapsed_time, sizeof(elapsed_time), PIL_check_seconds_timer() - time_begin); notify_status(percent_done / 100.0, scene_name + ": " + layer_name, - "Render Time: " + format_duration(elapsed_time) + + std::string("Render Time: ") + elapsed_time + " | Done: " + std::to_string(int(percent_done)) + "%"); if (render_task_delegate_->is_converged()) { @@ -185,12 +184,6 @@ void FinalEngineGL::render(Depsgraph *depsgraph) } tasks.push_back(render_task_delegate_->get_task()); - std::chrono::time_point time_begin = std::chrono::steady_clock::now(), - time_current; - std::chrono::milliseconds elapsed_time; - - float percent_done = 0.0; - std::map> render_images{ {"Combined", std::vector(res[0] * res[1] * 4)}}; /* 4 - number of channels. */ std::vector &pixels = render_images["Combined"]; @@ -217,19 +210,23 @@ void FinalEngineGL::render(Depsgraph *depsgraph) engine_->Execute(render_index_.get(), &tasks); } + char elapsed_time[32]; + double time_begin = PIL_check_seconds_timer(); + float percent_done = 0.0; + while (true) { if (RE_engine_test_break(bl_engine_)) { break; } percent_done = renderer_percent_done(); - time_current = std::chrono::steady_clock::now(); - elapsed_time = std::chrono::duration_cast(time_current - - time_begin); + + BLI_timecode_string_from_time_simple( + elapsed_time, sizeof(elapsed_time), PIL_check_seconds_timer() - time_begin); notify_status(percent_done / 100.0, scene_name + ": " + layer_name, - "Render Time: " + format_duration(elapsed_time) + + std::string("Render Time: ") + elapsed_time + " | Done: " + std::to_string(int(percent_done)) + "%"); if (render_task_delegate_->is_converged()) { diff --git a/source/blender/render/hydra/final_engine.h b/source/blender/render/hydra/final_engine.h index 17473ad5ec74..388500a38710 100644 --- a/source/blender/render/hydra/final_engine.h +++ b/source/blender/render/hydra/final_engine.h @@ -3,8 +3,6 @@ #pragma once -#include - #include "engine.h" namespace blender::render::hydra { diff --git a/source/blender/render/hydra/preview_engine.cc b/source/blender/render/hydra/preview_engine.cc index 08b1f5b90c7d..4992c67f9636 100644 --- a/source/blender/render/hydra/preview_engine.cc +++ b/source/blender/render/hydra/preview_engine.cc @@ -109,7 +109,7 @@ double PreviewEngine::free_instance(uintptr_t uuid, void *user_data) return LIFETIME; } - CLOG_INFO(LOG_EN, 2, ""); + CLOG_INFO(LOG_RENDER_HYDRA, 2, ""); instance_ = nullptr; return -1; } diff --git a/source/blender/render/hydra/python.cc b/source/blender/render/hydra/python.cc index e445ead763a2..c4d10e8b24c3 100644 --- a/source/blender/render/hydra/python.cc +++ b/source/blender/render/hydra/python.cc @@ -22,7 +22,7 @@ namespace blender::render::hydra { 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()) + "/blender.shared/usd"); @@ -59,7 +59,7 @@ static PyObject *register_plugins_func(PyObject * /*self*/, PyObject *args) ss << s << ", "; } 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; } @@ -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); } @@ -146,7 +146,7 @@ static PyObject *engine_free_func(PyObject * /*self*/, PyObject *args) delete engine; } - CLOG_INFO(LOG_EN, 2, "Engine %016llx", engine); + CLOG_INFO(LOG_RENDER_HYDRA, 2, "Engine %016llx", engine); Py_RETURN_NONE; } @@ -185,7 +185,7 @@ static PyObject *engine_sync_func(PyObject * /*self*/, PyObject *args) 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; } @@ -205,7 +205,7 @@ static PyObject *engine_render_func(PyObject * /*self*/, PyObject *args) engine->render(depsgraph); Py_END_ALLOW_THREADS; - CLOG_INFO(LOG_EN, 2, "Engine %016llx", engine); + CLOG_INFO(LOG_RENDER_HYDRA, 2, "Engine %016llx", engine); Py_RETURN_NONE; } @@ -225,7 +225,7 @@ static PyObject *engine_view_draw_func(PyObject * /*self*/, PyObject *args) engine->render(depsgraph, context); Py_END_ALLOW_THREADS; - CLOG_INFO(LOG_EN, 3, "Engine %016llx", engine); + CLOG_INFO(LOG_RENDER_HYDRA, 3, "Engine %016llx", engine); Py_RETURN_NONE; } diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc index 2cc06c447c33..bb6614f2be8a 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc @@ -11,7 +11,7 @@ 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, pxr::SdfPath const &delegate_id, @@ -22,14 +22,14 @@ BlenderSceneDelegate::BlenderSceneDelegate(pxr::HdRenderIndex *parent_index, 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); return m_data->mesh_topology(); } 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); if (obj_data) { 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) { - 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); if (obj_data) { @@ -80,7 +80,7 @@ pxr::VtValue BlenderSceneDelegate::GetLightParamValue(pxr::SdfPath const &id, pxr::HdPrimvarDescriptorVector BlenderSceneDelegate::GetPrimvarDescriptors( 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); if (m_data) { @@ -120,7 +120,7 @@ bool BlenderSceneDelegate::GetVisible(pxr::SdfPath const &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()); if (i_data) { 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) { - 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); 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::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); return i_data->indices(prototype_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); return i_data->transform; } @@ -336,8 +336,11 @@ void BlenderSceneDelegate::check_updates() ITER_BEGIN ( DEG_iterator_ids_begin, DEG_iterator_ids_next, DEG_iterator_ids_end, &data, ID *, id) { - CLOG_INFO( - LOG_BSD, 2, "Update: %s [%s]", id->name, std::bitset<32>(id->recalc).to_string().c_str()); + CLOG_INFO(LOG_RENDER_HYDRA_SCENE, + 2, + "Update: %s [%s]", + id->name, + std::bitset<32>(id->recalc).to_string().c_str()); switch (GS(id->name)) { case ID_OB: { diff --git a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h index 7db71c2de335..de0e67d6c904 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.h @@ -18,7 +18,7 @@ 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 { friend MeshData; /* has access to materials_*/ diff --git a/source/blender/render/hydra/scene_delegate/id.h b/source/blender/render/hydra/scene_delegate/id.h index 8fbd202e947e..425933c2258b 100644 --- a/source/blender/render/hydra/scene_delegate/id.h +++ b/source/blender/render/hydra/scene_delegate/id.h @@ -39,6 +39,7 @@ template const T IdData::get_data(pxr::TfToken const &key) const } #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 diff --git a/source/blender/render/hydra/scene_delegate/instancer.cc b/source/blender/render/hydra/scene_delegate/instancer.cc index 948da2ca03fa..554eac79d12d 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.cc +++ b/source/blender/render/hydra/scene_delegate/instancer.cc @@ -59,7 +59,7 @@ void InstancerData::insert() 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_) { it.second.obj_data->remove(); } diff --git a/source/blender/render/hydra/scene_delegate/light.cc b/source/blender/render/hydra/scene_delegate/light.cc index b14c07667893..ab4642f86389 100644 --- a/source/blender/render/hydra/scene_delegate/light.cc +++ b/source/blender/render/hydra/scene_delegate/light.cc @@ -85,7 +85,7 @@ void LightData::init() /* TODO: temporary value, it should be delivered through Python UI */ data_[pxr::HdLightTokens->exposure] = 1.0f; - set_transform_to_object(); + write_transform(); } void LightData::insert() @@ -96,7 +96,7 @@ void LightData::insert() 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); } @@ -118,7 +118,7 @@ void LightData::update() bits = pxr::HdLight::AllDirty; } else if (id->recalc & ID_RECALC_TRANSFORM) { - set_transform_to_object(); + write_transform(); bits = pxr::HdLight::DirtyTransform; } scene_delegate_->GetRenderIndex().GetChangeTracker().MarkSprimDirty(prim_id, bits); diff --git a/source/blender/render/hydra/scene_delegate/material.cc b/source/blender/render/hydra/scene_delegate/material.cc index 2d5071d938f7..e6793deacad4 100644 --- a/source/blender/render/hydra/scene_delegate/material.cc +++ b/source/blender/render/hydra/scene_delegate/material.cc @@ -68,7 +68,7 @@ void MaterialData::init() Py_DECREF(result); } 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(); } Py_DECREF(module); @@ -103,7 +103,7 @@ void MaterialData::insert() 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); } diff --git a/source/blender/render/hydra/scene_delegate/mesh.cc b/source/blender/render/hydra/scene_delegate/mesh.cc index a2a06b39d77a..50f65f26a269 100644 --- a/source/blender/render/hydra/scene_delegate/mesh.cc +++ b/source/blender/render/hydra/scene_delegate/mesh.cc @@ -40,7 +40,7 @@ void MeshData::init() } write_material(); - set_transform_to_object(); + write_transform(); } void MeshData::insert() @@ -60,7 +60,7 @@ void MeshData::remove() 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); } @@ -78,7 +78,7 @@ void MeshData::update() bits |= pxr::HdChangeTracker::DirtyMaterialId; } if (id->recalc & ID_RECALC_TRANSFORM) { - set_transform_to_object(); + write_transform(); bits |= pxr::HdChangeTracker::DirtyTransform; } } diff --git a/source/blender/render/hydra/scene_delegate/object.cc b/source/blender/render/hydra/scene_delegate/object.cc index 7e5396cf8d8c..ea7de70e4b91 100644 --- a/source/blender/render/hydra/scene_delegate/object.cc +++ b/source/blender/render/hydra/scene_delegate/object.cc @@ -79,7 +79,7 @@ bool ObjectData::update_visibility() return ret; } -void ObjectData::set_transform_to_object() +void ObjectData::write_transform() { transform = gf_matrix_from_transform(((Object *)id)->object_to_world); } diff --git a/source/blender/render/hydra/scene_delegate/object.h b/source/blender/render/hydra/scene_delegate/object.h index 5297c576e28b..f7fd44c76168 100644 --- a/source/blender/render/hydra/scene_delegate/object.h +++ b/source/blender/render/hydra/scene_delegate/object.h @@ -29,7 +29,7 @@ class ObjectData : public IdData { bool visible; protected: - void set_transform_to_object(); + void write_transform(); }; using ObjectDataMap = diff --git a/source/blender/render/hydra/scene_delegate/world.cc b/source/blender/render/hydra/scene_delegate/world.cc index 41697a9cf5a3..08f7a326db10 100644 --- a/source/blender/render/hydra/scene_delegate/world.cc +++ b/source/blender/render/hydra/scene_delegate/world.cc @@ -49,7 +49,7 @@ void WorldData::init() { ID_LOG(2, ""); - set_transform(); + write_transform(); World *world = (World *)id; data_.clear(); @@ -129,7 +129,7 @@ void WorldData::insert() 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); } @@ -157,7 +157,7 @@ pxr::VtValue WorldData::get_data(pxr::TfToken const &key) const 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()); diff --git a/source/blender/render/hydra/scene_delegate/world.h b/source/blender/render/hydra/scene_delegate/world.h index d29806ec1298..083e0daff78a 100644 --- a/source/blender/render/hydra/scene_delegate/world.h +++ b/source/blender/render/hydra/scene_delegate/world.h @@ -37,7 +37,7 @@ class WorldData : public IdData { pxr::GfMatrix4d transform; private: - void set_transform(); + void write_transform(); std::map data_; }; diff --git a/source/blender/render/hydra/utils.cc b/source/blender/render/hydra/utils.cc index 8d37a14ef7ac..9a0462fc4ae3 100644 --- a/source/blender/render/hydra/utils.cc +++ b/source/blender/render/hydra/utils.cc @@ -1,9 +1,7 @@ /* SPDX-License-Identifier: Apache-2.0 * Copyright 2011-2022 Blender Foundation */ -#include #include -#include #include @@ -29,35 +27,6 @@ pxr::GfMatrix4d gf_matrix_from_transform(float m[4][4]) 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(millisecs); - millisecs -= m; - auto s = std::chrono::duration_cast(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, Scene *scene, Image *image, @@ -65,8 +34,7 @@ std::string cache_image(Main *bmain, ImageSaveOptions *opts, ReportList *reports) { - const std::string default_format = ".png"; - + const char *default_format = ".png"; char tempfile[FILE_MAX]; if (!BKE_image_save_options_init(opts, bmain, scene, image, iuser, true, false)) { @@ -74,20 +42,13 @@ std::string cache_image(Main *bmain, return ""; } - std::string image_name; + char image_name[32]; + snprintf(image_name, 32, "img_%016llx", (uint64_t)image); - if (image->source == IMA_SRC_GENERATED) { - 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); - } + strcat(image_name, default_format); - image_name.append(default_format); - - BLI_path_join(tempfile, sizeof(tempfile), BKE_tempdir_session(), image_name.c_str()); + BLI_path_join( + tempfile, sizeof(tempfile), BKE_tempdir_session(), "hydra_image_cache", image_name); STRNCPY(opts->filepath, tempfile); if (!BKE_image_save(reports, bmain, image, iuser, opts)) { diff --git a/source/blender/render/hydra/utils.h b/source/blender/render/hydra/utils.h index 05d7c85fc610..e71c64e9b5d8 100644 --- a/source/blender/render/hydra/utils.h +++ b/source/blender/render/hydra/utils.h @@ -3,7 +3,6 @@ #pragma once -#include #include #include @@ -14,7 +13,6 @@ namespace blender::render::hydra { pxr::GfMatrix4d gf_matrix_from_transform(float m[4][4]); -std::string format_duration(std::chrono::milliseconds secs); std::string cache_image(Main *bmain, Scene *scene, Image *image, diff --git a/source/blender/render/hydra/viewport_engine.cc b/source/blender/render/hydra/viewport_engine.cc index f3db317a9a8b..802f2d9f3c1a 100644 --- a/source/blender/render/hydra/viewport_engine.cc +++ b/source/blender/render/hydra/viewport_engine.cc @@ -12,13 +12,15 @@ #include "BKE_camera.h" #include "BLI_math_matrix.h" +#include "BLI_timecode.h" #include "DEG_depsgraph_query.h" #include "GPU_matrix.h" +#include "PIL_time.h" + #include "camera.h" -#include "utils.h" #include "viewport_engine.h" namespace blender::render::hydra { @@ -259,10 +261,6 @@ void ViewportEngine::render(Depsgraph *depsgraph, bContext *context) 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); GPU_shader_bind(shader); @@ -285,21 +283,23 @@ void ViewportEngine::render(Depsgraph *depsgraph, bContext *context) GPU_shader_unbind(); - std::chrono::time_point time_current = - std::chrono::steady_clock::now(); - std::chrono::milliseconds elapsed_time = std::chrono::duration_cast( - time_current - time_begin_); + if (renderer_percent_done() == 0.0f) { + time_begin_ = PIL_check_seconds_timer(); + } - 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()) { - notify_status("Time: " + formatted_time + + notify_status(std::string("Time: ") + elapsed_time + " | Done: " + std::to_string(int(renderer_percent_done())) + "%", "Render"); bl_engine_->flag |= RE_ENGINE_DO_DRAW; } else { - notify_status(("Time: " + formatted_time).c_str(), "Rendering Done"); + notify_status((std::string("Time: ") + elapsed_time).c_str(), "Rendering Done"); } } diff --git a/source/blender/render/hydra/viewport_engine.h b/source/blender/render/hydra/viewport_engine.h index a362cf21bfba..2f893d71a9d1 100644 --- a/source/blender/render/hydra/viewport_engine.h +++ b/source/blender/render/hydra/viewport_engine.h @@ -3,8 +3,6 @@ #pragma once -#include - #include #include "GPU_batch.h" @@ -46,7 +44,7 @@ class ViewportEngine : public Engine { void notify_status(const std::string &title, const std::string &info); private: - std::chrono::time_point time_begin_; + double time_begin_; DrawTexture draw_texture_; };