Fix review comments #27

Merged
Bogdan Nagirniak merged 14 commits from BLEN-392 into hydra-render 2023-04-21 15:02:44 +02:00
11 changed files with 60 additions and 53 deletions
Showing only changes of commit c367279df3 - Show all commits

View File

@ -8,11 +8,14 @@
#include <pxr/imaging/hgi/tokens.h>
#include <pxr/usd/usdGeom/tokens.h>
#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,10 @@ 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));
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();

View File

@ -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:

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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,
@ -44,7 +44,7 @@ void BlenderSceneDelegate::populate(Depsgraph *deps, bContext *cont)
unsigned int scene_recalc = ((ID *)scene_)->recalc;
if (scene_recalc) {
/* Checking scene updates */
CLOG_INFO(LOG_BSD,
CLOG_INFO(LOG_RENDER_HYDRA_SCENE,
2,
"Update: %s [%s]",
((ID *)scene_)->name,
@ -74,7 +74,7 @@ void BlenderSceneDelegate::populate(Depsgraph *deps, bContext *cont)
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());
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: {
@ -125,14 +125,14 @@ void BlenderSceneDelegate::clear()
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();
@ -152,7 +152,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) {
@ -188,7 +188,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) {
@ -228,7 +228,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, true);
if (i_data) {
return i_data->instancer_id;
@ -238,7 +238,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());
pxr::SdfPathVector paths;
paths.push_back(instancer_id.GetParentPath());
return paths;
@ -247,14 +247,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->instance_indices();
}
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();
}
@ -391,7 +391,7 @@ void BlenderSceneDelegate::update_collection(bool remove, bool visibility)
Object *,
object) {
CLOG_INFO(LOG_BSD, 2, "Add %s", ((ID *)object)->name);
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 2, "Add %s", ((ID *)object)->name);
if (!ObjectData::is_supported(object)) {
continue;
}

View File

@ -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;

View File

@ -15,7 +15,7 @@ InstancerData::InstancerData(BlenderSceneDelegate *scene_delegate, Object *objec
id_ = nullptr;
p_id_ = prim_id(scene_delegate, object);
instancer_id = p_id_.AppendElementString("Instancer");
CLOG_INFO(LOG_BSD, 2, "%s, instancer_id=%s", ((ID *)parent_obj_)->name, instancer_id.GetText());
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 2, "%s, instancer_id=%s", ((ID *)parent_obj_)->name, instancer_id.GetText());
}
bool InstancerData::is_supported(Object *object)
@ -54,7 +54,7 @@ pxr::SdfPath InstancerData::prim_id(BlenderSceneDelegate *scene_delegate, Object
void InstancerData::init()
{
CLOG_INFO(LOG_BSD, 2, "%s", ((ID *)parent_obj_)->name);
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 2, "%s", ((ID *)parent_obj_)->name);
set_instances();
MeshData::init();
@ -62,7 +62,7 @@ void InstancerData::init()
void InstancerData::insert()
{
CLOG_INFO(LOG_BSD, 2, "%s", ((ID *)parent_obj_)->name);
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 2, "%s", ((ID *)parent_obj_)->name);
MeshData::insert();
if (face_vertex_counts_.empty()) {
@ -73,7 +73,7 @@ void InstancerData::insert()
void InstancerData::remove()
{
CLOG_INFO(LOG_BSD, 2, "%s", ((ID *)parent_obj_)->name);
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 2, "%s", ((ID *)parent_obj_)->name);
if (!scene_delegate_->GetRenderIndex().HasInstancer(instancer_id)) {
return;
@ -85,7 +85,7 @@ void InstancerData::remove()
void InstancerData::update()
{
CLOG_INFO(LOG_BSD, 2, "%s", ((ID *)parent_obj_)->name);
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 2, "%s", ((ID *)parent_obj_)->name);
pxr::HdDirtyBits bits = pxr::HdChangeTracker::Clean;
unsigned int recalc = ((ID *)parent_obj_)->recalc;
@ -113,7 +113,7 @@ void InstancerData::update()
pxr::VtValue InstancerData::get_data(pxr::TfToken const &key) const
{
CLOG_INFO(LOG_BSD, 3, "%s [%s]", id_->name, key.GetText());
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s [%s]", id_->name, key.GetText());
if (key == pxr::HdInstancerTokens->instanceTransform) {
return pxr::VtValue(transforms_);
@ -185,7 +185,7 @@ bool InstancerData::set_instances()
}
transforms_.push_back(gf_matrix_from_transform(dupli->mat));
CLOG_INFO(
LOG_BSD, 2, "Instance %s (%s) %d", id_->name, ((ID *)dupli->ob)->name, dupli->random_id);
LOG_RENDER_HYDRA_SCENE, 2, "Instance %s (%s) %d", id_->name, ((ID *)dupli->ob)->name, dupli->random_id);
}
free_object_duplilist(lb);

View File

@ -17,12 +17,12 @@ namespace blender::render::hydra {
LightData::LightData(BlenderSceneDelegate *scene_delegate, Object *object)
: ObjectData(scene_delegate, object)
{
CLOG_INFO(LOG_BSD, 2, "%s id=%s", id_->name, p_id_.GetText());
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 2, "%s id=%s", id_->name, p_id_.GetText());
}
void LightData::init()
{
CLOG_INFO(LOG_BSD, 2, "%s", id_->name);
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 2, "%s", id_->name);
Light *light = (Light *)((Object *)id_)->data;
data_.clear();
@ -87,19 +87,19 @@ void LightData::init()
void LightData::insert()
{
CLOG_INFO(LOG_BSD, 2, "%s", id_->name);
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 2, "%s", id_->name);
scene_delegate_->GetRenderIndex().InsertSprim(p_type_, scene_delegate_, p_id_);
}
void LightData::remove()
{
CLOG_INFO(LOG_BSD, 2, "%s", id_->name);
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 2, "%s", id_->name);
scene_delegate_->GetRenderIndex().RemoveSprim(p_type_, p_id_);
}
void LightData::update()
{
CLOG_INFO(LOG_BSD, 2, "%s", id_->name);
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 2, "%s", id_->name);
Light *light = (Light *)((Object *)id_)->data;
if (prim_type(light) != p_type_) {

View File

@ -24,7 +24,7 @@ MaterialData::MaterialData(BlenderSceneDelegate *scene_delegate, Material *mater
: IdData(scene_delegate, (ID *)material)
{
p_id_ = prim_id(scene_delegate, material);
CLOG_INFO(LOG_BSD, 2, "%s, id=%s", id_->name, p_id_.GetText());
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 2, "%s, id=%s", id_->name, p_id_.GetText());
}
std::unique_ptr<MaterialData> MaterialData::create(BlenderSceneDelegate *scene_delegate,
@ -47,7 +47,7 @@ pxr::SdfPath MaterialData::prim_id(BlenderSceneDelegate *scene_delegate, Materia
void MaterialData::init()
{
CLOG_INFO(LOG_BSD, 2, "%s", id_->name);
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 2, "%s", id_->name);
material_network_map_ = pxr::VtValue();
@ -76,7 +76,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);
@ -84,25 +84,25 @@ void MaterialData::init()
PyGILState_Release(gstate);
mtlx_path_ = pxr::SdfAssetPath(path, path);
CLOG_INFO(LOG_BSD, 2, "Export: %s, mtlx=%s", id_->name, mtlx_path_.GetResolvedPath().c_str());
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 2, "Export: %s, mtlx=%s", id_->name, mtlx_path_.GetResolvedPath().c_str());
}
void MaterialData::insert()
{
CLOG_INFO(LOG_BSD, 2, "%s", id_->name);
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 2, "%s", id_->name);
scene_delegate_->GetRenderIndex().InsertSprim(
pxr::HdPrimTypeTokens->material, scene_delegate_, p_id_);
}
void MaterialData::remove()
{
CLOG_INFO(LOG_BSD, 2, "%s", id_->name);
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 2, "%s", id_->name);
scene_delegate_->GetRenderIndex().RemoveSprim(pxr::HdPrimTypeTokens->material, p_id_);
}
void MaterialData::update()
{
CLOG_INFO(LOG_BSD, 2, "%s", id_->name);
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 2, "%s", id_->name);
init();
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkSprimDirty(p_id_,
pxr::HdMaterial::AllDirty);
@ -115,7 +115,7 @@ pxr::VtValue MaterialData::get_data(pxr::TfToken const &key) const
if (!mtlx_path_.GetResolvedPath().empty()) {
ret = mtlx_path_;
}
CLOG_INFO(LOG_BSD, 3, "%s", key.GetText());
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 3, "%s", key.GetText());
}
return ret;
}

View File

@ -18,12 +18,12 @@ namespace blender::render::hydra {
MeshData::MeshData(BlenderSceneDelegate *scene_delegate, Object *object)
: ObjectData(scene_delegate, object), mat_data_(nullptr)
{
CLOG_INFO(LOG_BSD, 2, "%s, id=%s", id_->name, p_id_.GetText());
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 2, "%s, id=%s", id_->name, p_id_.GetText());
}
void MeshData::init()
{
CLOG_INFO(LOG_BSD, 2, "%s", id_->name);
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 2, "%s", id_->name);
Object *object = (Object *)id_;
if (object->type == OB_MESH && object->mode == OB_MODE_OBJECT &&
@ -47,7 +47,7 @@ void MeshData::insert()
return;
}
CLOG_INFO(LOG_BSD, 2, "%s", id_->name);
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 2, "%s", id_->name);
scene_delegate_->GetRenderIndex().InsertRprim(
pxr::HdPrimTypeTokens->mesh, scene_delegate_, p_id_);
}
@ -58,7 +58,7 @@ void MeshData::remove()
return;
}
CLOG_INFO(LOG_BSD, 2, "%s", id_->name);
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 2, "%s", id_->name);
scene_delegate_->GetRenderIndex().RemoveRprim(p_id_);
}
@ -94,7 +94,7 @@ void MeshData::update()
remove();
return;
}
CLOG_INFO(LOG_BSD, 2, "%s", id_->name);
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 2, "%s", id_->name);
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkRprimDirty(p_id_, bits);
}

View File

@ -32,7 +32,7 @@ WorldData::WorldData(BlenderSceneDelegate *scene_delegate, World *world, bContex
: IdData(scene_delegate, (ID *)world), context_(context)
{
p_id_ = prim_id(scene_delegate);
CLOG_INFO(LOG_BSD, 2, "%s, id=%s", id_->name, p_id_.GetText());
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 2, "%s, id=%s", id_->name, p_id_.GetText());
}
std::unique_ptr<WorldData> WorldData::create(BlenderSceneDelegate *scene_delegate,
@ -52,7 +52,7 @@ pxr::SdfPath WorldData::prim_id(BlenderSceneDelegate *scene_delegate)
void WorldData::init()
{
CLOG_INFO(LOG_BSD, 2, "%s", id_->name);
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 2, "%s", id_->name);
World *world = (World *)id_;
data_.clear();
@ -125,20 +125,20 @@ void WorldData::init()
void WorldData::insert()
{
CLOG_INFO(LOG_BSD, 2, "%s", id_->name);
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 2, "%s", id_->name);
scene_delegate_->GetRenderIndex().InsertSprim(
pxr::HdPrimTypeTokens->domeLight, scene_delegate_, p_id_);
}
void WorldData::remove()
{
CLOG_INFO(LOG_BSD, 2, "%s", id_->name);
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 2, "%s", id_->name);
scene_delegate_->GetRenderIndex().RemoveSprim(pxr::HdPrimTypeTokens->domeLight, p_id_);
}
void WorldData::update()
{
CLOG_INFO(LOG_BSD, 2, "%s", id_->name);
CLOG_INFO(LOG_RENDER_HYDRA_SCENE, 2, "%s", id_->name);
init();
scene_delegate_->GetRenderIndex().GetChangeTracker().MarkSprimDirty(p_id_,
pxr::HdLight::AllDirty);