diff --git a/CMakeLists.txt b/CMakeLists.txt index 67111207a30e..98b967cad629 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -931,6 +931,9 @@ set_and_warn_dependency(WITH_IMAGE_OPENEXR WITH_OPENVDB OFF) set_and_warn_dependency(WITH_IMAGE_OPENEXR WITH_ALEMBIC OFF) set_and_warn_dependency(WITH_IMAGE_OPENEXR WITH_CYCLES_OSL OFF) +# Hydra requires USD. +set_and_warn_dependency(WITH_USD WITH_HYDRA OFF) + # auto enable openimageio for cycles if(WITH_CYCLES) # auto enable llvm for cycles_osl diff --git a/source/blender/render/hydra/CMakeLists.txt b/source/blender/render/hydra/CMakeLists.txt index 52b6b175c983..6dc9daadc19c 100644 --- a/source/blender/render/hydra/CMakeLists.txt +++ b/source/blender/render/hydra/CMakeLists.txt @@ -5,6 +5,18 @@ if(WIN32) add_definitions(-DNOMINMAX -DWIN32_LEAN_AND_MEAN -DBOOST_DEBUG_PYTHON) endif() +# Precompiled Linux libs are made with GCC, and USD uses some extensions +# which lead to an incompatible ABI for Clang. Using those extensions with +# Clang as well works around the issue. +if(UNIX AND NOT APPLE) + if(CMAKE_C_COMPILER_ID MATCHES "Clang") + if(EXISTS ${LIBDIR}) + add_definitions(-DARCH_HAS_GNU_STL_EXTENSIONS) + add_cxx_flag("-Wno-deprecated") + endif() + endif() +endif() + # USD headers use deprecated TBB headers, silence warning. add_definitions(-DTBB_SUPPRESS_DEPRECATED_MESSAGES=1) @@ -44,9 +56,21 @@ set(INC_SYS ${BOOST_INCLUDE_DIR} ${TBB_INCLUDE_DIR} ${GFLAGS_INCLUDE_DIRS} - ${LIBDIR}/MaterialX/include ) +set(LIB + ${Epoxy_LIBRARIES} + ${PYTHON_LIBRARIES} + ${BOOST_LIBRARIES} + ${USD_LIBRARIES} + ${TBB_LIBRARIES} +) + +if(WITH_MATERIALX) + add_definitions(-DWITH_MATERIALX) + list(APPEND LIB MaterialXCore) +endif() + set(SRC python.cc @@ -92,12 +116,6 @@ set(SRC scene_delegate/volume.cc ) -set(LIB - ${Epoxy_LIBRARIES} - ${PYTHON_LIBRARIES} - ${BOOST_LIBRARIES} -) - blender_add_lib(bf_render_hydra "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") add_dependencies(bf_render_hydra bf_rna) diff --git a/source/blender/render/hydra/python.cc b/source/blender/render/hydra/python.cc index 0cc0d11c21b7..7b8e0152555f 100644 --- a/source/blender/render/hydra/python.cc +++ b/source/blender/render/hydra/python.cc @@ -33,7 +33,7 @@ static PyObject *register_plugins_func(PyObject * /*self*/, PyObject *args) pyiter = PyObject_GetIter(pyplugin_dirs); if (pyiter) { - while (pyitem = PyIter_Next(pyiter)) { + while ((pyitem = PyIter_Next(pyiter))) { plugin_dirs.push_back(PyUnicode_AsUTF8(pyitem)); Py_DECREF(pyitem); } @@ -87,7 +87,7 @@ static PyObject *engine_create_func(PyObject * /*self*/, PyObject *args) } if (engine) { - CLOG_INFO(LOG_RENDER_HYDRA, 1, "Engine %016llx %s", engine, engine_type); + CLOG_INFO(LOG_RENDER_HYDRA, 1, "Engine %p %s", engine, engine_type); } return PyLong_FromVoidPtr(engine); } @@ -102,7 +102,7 @@ static PyObject *engine_free_func(PyObject * /*self*/, PyObject *args) Engine *engine = (Engine *)PyLong_AsVoidPtr(pyengine); delete engine; - CLOG_INFO(LOG_RENDER_HYDRA, 1, "Engine %016llx", engine); + CLOG_INFO(LOG_RENDER_HYDRA, 1, "Engine %p", engine); Py_RETURN_NONE; } @@ -117,7 +117,7 @@ static PyObject *engine_sync_func(PyObject * /*self*/, PyObject *args) Depsgraph *depsgraph = (Depsgraph *)PyLong_AsVoidPtr(pydepsgraph); bContext *context = (bContext *)PyLong_AsVoidPtr(pycontext); - CLOG_INFO(LOG_RENDER_HYDRA, 2, "Engine %016llx", engine); + CLOG_INFO(LOG_RENDER_HYDRA, 2, "Engine %p", engine); engine->sync(depsgraph, context); Py_RETURN_NONE; @@ -135,7 +135,7 @@ static PyObject *engine_sync_usd_func(PyObject * /*self*/, PyObject *args) boost::python::extract extract(pystage); pxr::UsdStagePtr stage = extract(); - CLOG_INFO(LOG_RENDER_HYDRA, 2, "Engine %016llx", engine); + CLOG_INFO(LOG_RENDER_HYDRA, 2, "Engine %p", engine); engine->sync_usd(stage); Py_RETURN_NONE; @@ -152,7 +152,7 @@ static PyObject *engine_render_func(PyObject * /*self*/, PyObject *args) Engine *engine = (Engine *)PyLong_AsVoidPtr(pyengine); Depsgraph *depsgraph = (Depsgraph *)PyLong_AsVoidPtr(pydepsgraph); - CLOG_INFO(LOG_RENDER_HYDRA, 2, "Engine %016llx", engine); + CLOG_INFO(LOG_RENDER_HYDRA, 2, "Engine %p", engine); /* Allow Blender to execute other Python scripts. */ Py_BEGIN_ALLOW_THREADS; @@ -173,7 +173,7 @@ static PyObject *engine_view_draw_func(PyObject * /*self*/, PyObject *args) Depsgraph *depsgraph = (Depsgraph *)PyLong_AsVoidPtr(pydepsgraph); bContext *context = (bContext *)PyLong_AsVoidPtr(pycontext); - CLOG_INFO(LOG_RENDER_HYDRA, 3, "Engine %016llx", engine); + CLOG_INFO(LOG_RENDER_HYDRA, 3, "Engine %p", engine); /* Allow Blender to execute other Python scripts. */ Py_BEGIN_ALLOW_THREADS; @@ -211,7 +211,7 @@ static PyObject *engine_set_sync_setting_func(PyObject * /*self*/, PyObject *arg Engine *engine = (Engine *)PyLong_AsVoidPtr(pyengine); - CLOG_INFO(LOG_RENDER_HYDRA, 3, "Engine %016llx: %s", engine, key); + CLOG_INFO(LOG_RENDER_HYDRA, 3, "Engine %p: %s", engine, key); engine->set_sync_setting(key, get_setting_val(pyval)); Py_RETURN_NONE; @@ -227,7 +227,7 @@ static PyObject *engine_set_render_setting_func(PyObject * /*self*/, PyObject *a Engine *engine = (Engine *)PyLong_AsVoidPtr(pyengine); - CLOG_INFO(LOG_RENDER_HYDRA, 3, "Engine %016llx: %s", engine, key); + CLOG_INFO(LOG_RENDER_HYDRA, 3, "Engine %p: %s", engine, key); engine->set_render_setting(key, get_setting_val(pyval)); Py_RETURN_NONE; diff --git a/source/blender/render/hydra/render_task_delegate.cc b/source/blender/render/hydra/render_task_delegate.cc index d5348aef4d7b..5351be086ca2 100644 --- a/source/blender/render/hydra/render_task_delegate.cc +++ b/source/blender/render/hydra/render_task_delegate.cc @@ -106,7 +106,7 @@ void RenderTaskDelegate::set_camera_and_viewport(pxr::SdfPath const &camera_id, } } -pxr::VtValue RenderTaskDelegate::Get(pxr::SdfPath const &id, pxr::TfToken const &key) +pxr::VtValue RenderTaskDelegate::Get(pxr::SdfPath const & /*id*/, pxr::TfToken const &key) { if (key == pxr::HdTokens->params) { return pxr::VtValue(task_params_); @@ -127,7 +127,7 @@ pxr::HdRenderBufferDescriptor RenderTaskDelegate::GetRenderBufferDescriptor(pxr: return buffer_descriptors_[id]; } -pxr::TfTokenVector RenderTaskDelegate::GetTaskRenderTags(pxr::SdfPath const &task_id) +pxr::TfTokenVector RenderTaskDelegate::GetTaskRenderTags(pxr::SdfPath const & /*task_id*/) { return {pxr::HdRenderTagTokens->geometry}; } 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 fa45f5714cbf..10742f657ac3 100644 --- a/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc +++ b/source/blender/render/hydra/scene_delegate/blender_scene_delegate.cc @@ -273,7 +273,7 @@ pxr::SdfPath BlenderSceneDelegate::prim_id(ID *id, const char *prefix) const { /* Making id of object in form like _ */ char name[32]; - snprintf(name, sizeof(name), "%s_%016llx", prefix, (uintptr_t)id); + snprintf(name, sizeof(name), "%s_%p", prefix, id); return GetDelegateID().AppendElementString(name); } diff --git a/source/blender/render/hydra/scene_delegate/curves.cc b/source/blender/render/hydra/scene_delegate/curves.cc index 0364afb1475f..53e3ca6ed872 100644 --- a/source/blender/render/hydra/scene_delegate/curves.cc +++ b/source/blender/render/hydra/scene_delegate/curves.cc @@ -66,7 +66,7 @@ void CurvesData::update() ID_LOG(1, ""); } -pxr::VtValue CurvesData::get_data(pxr::SdfPath const &id, pxr::TfToken const &key) const +pxr::VtValue CurvesData::get_data(pxr::SdfPath const & /* id */, pxr::TfToken const &key) const { if (key == pxr::HdTokens->points) { return pxr::VtValue(vertices_); @@ -91,7 +91,7 @@ bool CurvesData::update_visibility() return ret; } -pxr::HdBasisCurvesTopology CurvesData::curves_topology(pxr::SdfPath const &id) const +pxr::HdBasisCurvesTopology CurvesData::curves_topology(pxr::SdfPath const & /* id */) const { return pxr::HdBasisCurvesTopology(pxr::HdTokens->linear, pxr::TfToken(), diff --git a/source/blender/render/hydra/scene_delegate/id.cc b/source/blender/render/hydra/scene_delegate/id.cc index 90ce224dfa0d..1cf8d6b9dd34 100644 --- a/source/blender/render/hydra/scene_delegate/id.cc +++ b/source/blender/render/hydra/scene_delegate/id.cc @@ -12,7 +12,7 @@ IdData::IdData(BlenderSceneDelegate *scene_delegate, ID *id, pxr::SdfPath const { } -pxr::VtValue IdData::get_data(pxr::TfToken const &key) const +pxr::VtValue IdData::get_data(pxr::TfToken const & /*key*/) const { return pxr::VtValue(); } diff --git a/source/blender/render/hydra/scene_delegate/image.cc b/source/blender/render/hydra/scene_delegate/image.cc index 7f8f4a28c3d3..b04c82678f55 100644 --- a/source/blender/render/hydra/scene_delegate/image.cc +++ b/source/blender/render/hydra/scene_delegate/image.cc @@ -46,7 +46,7 @@ static std::string cache_image_file(Image *image, opts.im_format = scene->r.im_format; } - snprintf(file_name, sizeof(file_name), "img_%016llx%s", (uintptr_t)image, r_ext); + snprintf(file_name, sizeof(file_name), "img_%p%s", image, r_ext); file_path = get_cache_file(file_name); if (check_exist && BLI_exists(file_path.c_str())) { diff --git a/source/blender/render/hydra/scene_delegate/instancer.cc b/source/blender/render/hydra/scene_delegate/instancer.cc index 7dd8e9401dbc..c0c6b5a5c794 100644 --- a/source/blender/render/hydra/scene_delegate/instancer.cc +++ b/source/blender/render/hydra/scene_delegate/instancer.cc @@ -163,7 +163,7 @@ void InstancerData::update_instance(Object *parent_ob, DupliObject *dupli) inst->data = std::make_unique(scene_delegate_, ob, p_id); inst->data->init(); } - ID_LOG(2, "Light %s %d", inst->data->id->name, inst->transforms.size()); + ID_LOG(2, "Light %s %d", inst->data->id->name, (int)inst->transforms.size()); inst->transforms.push_back(gf_matrix_from_transform(dupli->mat)); } else { @@ -177,7 +177,7 @@ void InstancerData::update_instance(Object *parent_ob, DupliObject *dupli) else { inst->data->update(); } - ID_LOG(2, "Mesh %s %d", inst->data->id->name, mesh_transforms_.size()); + ID_LOG(2, "Mesh %s %d", inst->data->id->name, (int)mesh_transforms_.size()); inst->indices.push_back(mesh_transforms_.size()); mesh_transforms_.push_back(gf_matrix_from_transform(dupli->mat)); } @@ -225,7 +225,7 @@ pxr::SdfPath InstancerData::object_prim_id(Object *object) const { /* Making id of object in form like _ */ char name[32]; - snprintf(name, sizeof(name), "O_%016llx", (uint64_t)object); + snprintf(name, sizeof(name), "O_%p", object); return prim_id.AppendElementString(name); } diff --git a/source/blender/render/hydra/scene_delegate/mtlx_hydra_adapter.cc b/source/blender/render/hydra/scene_delegate/mtlx_hydra_adapter.cc index 072d222bab4c..b673cceece69 100644 --- a/source/blender/render/hydra/scene_delegate/mtlx_hydra_adapter.cc +++ b/source/blender/render/hydra/scene_delegate/mtlx_hydra_adapter.cc @@ -1,14 +1,18 @@ /* SPDX-License-Identifier: Apache-2.0 * Copyright 2011-2022 Blender Foundation */ +#include "BLI_utildefines.h" + #include #include #include #include -#include -#include +#ifdef WITH_MATERIALX +# include +# include +#endif #include #include @@ -20,8 +24,6 @@ #include "mtlx_hydra_adapter.h" -namespace mx = MaterialX; - namespace blender::render::hydra { void hdmtlx_convert_to_materialnetworkmap(std::string const &mtlx_path, @@ -29,6 +31,7 @@ void hdmtlx_convert_to_materialnetworkmap(std::string const &mtlx_path, pxr::TfTokenVector const &render_contexts, pxr::HdMaterialNetworkMap *out) { +#ifdef WITH_MATERIALX if (mtlx_path.empty()) { return; } @@ -46,17 +49,17 @@ void hdmtlx_convert_to_materialnetworkmap(std::string const &mtlx_path, pxr::UsdStageRefPtr stage = pxr::UsdStage::CreateInMemory(stage_id, context); try { - mx::DocumentPtr doc = pxr::UsdMtlxReadDocument(mtlx_path); + MaterialX::DocumentPtr doc = pxr::UsdMtlxReadDocument(mtlx_path); pxr::UsdMtlxRead(doc, stage); } - catch (mx::ExceptionFoundCycle &x) { + catch (MaterialX::ExceptionFoundCycle &x) { Tf_PostErrorHelper(pxr::TF_CALL_CONTEXT, pxr::TF_DIAGNOSTIC_RUNTIME_ERROR_TYPE, "MaterialX cycle found: %s\n", x.what()); return; } - catch (mx::Exception &x) { + catch (MaterialX::Exception &x) { Tf_PostErrorHelper(pxr::TF_CALL_CONTEXT, pxr::TF_DIAGNOSTIC_RUNTIME_ERROR_TYPE, "MaterialX error: %s\n", @@ -78,6 +81,9 @@ void hdmtlx_convert_to_materialnetworkmap(std::string const &mtlx_path, } } } +#else + UNUSED_VARS(mtlx_path, shader_source_types, render_contexts, out); +#endif } } // namespace blender::render::hydra diff --git a/source/blender/render/hydra/simple_light_task_delegate.cc b/source/blender/render/hydra/simple_light_task_delegate.cc index 6bd7fc0cecfc..574bce126d28 100644 --- a/source/blender/render/hydra/simple_light_task_delegate.cc +++ b/source/blender/render/hydra/simple_light_task_delegate.cc @@ -30,7 +30,7 @@ void SimpleLightTaskDelegate::set_camera_path(pxr::SdfPath const &camera_path) task_params_.cameraPath = camera_path; } -pxr::VtValue SimpleLightTaskDelegate::Get(pxr::SdfPath const &id, pxr::TfToken const &key) +pxr::VtValue SimpleLightTaskDelegate::Get(pxr::SdfPath const & /*id*/, pxr::TfToken const &key) { if (key == pxr::HdTokens->params) { return pxr::VtValue(task_params_); diff --git a/source/blender/render/hydra/viewport_engine.cc b/source/blender/render/hydra/viewport_engine.cc index 35fa618080c0..75306e459e6a 100644 --- a/source/blender/render/hydra/viewport_engine.cc +++ b/source/blender/render/hydra/viewport_engine.cc @@ -217,12 +217,12 @@ void DrawTexture::free() texture_ = nullptr; } -void ViewportEngine::render(Depsgraph *depsgraph) +void ViewportEngine::render(Depsgraph * /* depsgraph */) { /* Empty function */ } -void ViewportEngine::render(Depsgraph *depsgraph, bContext *context) +void ViewportEngine::render(Depsgraph * /* depsgraph */, bContext *context) { ViewSettings view_settings(context); if (view_settings.width() * view_settings.height() == 0) {