Fix various build issues and warnings on Linux #63

Merged
Brecht Van Lommel merged 2 commits from brecht/blender:hydra-build-linux into hydra-render 2023-07-13 20:26:51 +02:00
13 changed files with 64 additions and 37 deletions
Showing only changes of commit 4fe08ec8c6 - Show all commits

View File

@ -922,6 +922,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_ALEMBIC OFF)
set_and_warn_dependency(WITH_IMAGE_OPENEXR WITH_CYCLES_OSL 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 # auto enable openimageio for cycles
if(WITH_CYCLES) if(WITH_CYCLES)
# auto enable llvm for cycles_osl # auto enable llvm for cycles_osl

View File

@ -5,6 +5,18 @@ if(WIN32)
add_definitions(-DNOMINMAX -DWIN32_LEAN_AND_MEAN -DBOOST_DEBUG_PYTHON) add_definitions(-DNOMINMAX -DWIN32_LEAN_AND_MEAN -DBOOST_DEBUG_PYTHON)
endif() 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. # USD headers use deprecated TBB headers, silence warning.
add_definitions(-DTBB_SUPPRESS_DEPRECATED_MESSAGES=1) add_definitions(-DTBB_SUPPRESS_DEPRECATED_MESSAGES=1)
@ -43,9 +55,21 @@ set(INC_SYS
${BOOST_INCLUDE_DIR} ${BOOST_INCLUDE_DIR}
${TBB_INCLUDE_DIR} ${TBB_INCLUDE_DIR}
${GFLAGS_INCLUDE_DIRS} ${GFLAGS_INCLUDE_DIRS}
${LIBDIR}/MaterialX/include

This produces compile error
D:\amd\blender-git\lib\win64_vc15\usd\include\pxr/usd/usdMtlx/reader.h(31,10): fatal error C1083: Cannot open include file: 'MaterialXCore/Document.h': No such file or directory (compiling source file D:\amd\blender-git\blender\source\b lender\render\hydra\scene_delegate\mtlx_hydra_adapter.cc) [D:\amd\blender-git\buildnew\source\blender\render\hydra\bf_render_hydra.vcxproj]

This produces compile error `D:\amd\blender-git\lib\win64_vc15\usd\include\pxr/usd/usdMtlx/reader.h(31,10): fatal error C1083: Cannot open include file: 'MaterialXCore/Document.h': No such file or directory (compiling source file D:\amd\blender-git\blender\source\b lender\render\hydra\scene_delegate\mtlx_hydra_adapter.cc) [D:\amd\blender-git\buildnew\source\blender\render\hydra\bf_render_hydra.vcxproj]`

The thing is that we should not be using LIBDIR here, since that assumes precompiled libraries which is not always the case.

So instead I added MaterialXCore to LIB, which should automatically add the associated includes when used with find_package(MaterialX). This is the system that we are trying to move towards. However Windows doesn't seem to do this.

Can you get find_package(MaterialX) working in platform_win32.cmake?

If not, I guess you could do something manual there:

add_library(MaterialXCore SHARED IMPORTED)
set_target_properties(MaterialXCore PROPERTIES
  INTERFACE_INCLUDE_DIRECTORIES "${LIBDIR}/MaterialX/include"
)
The thing is that we should not be using `LIBDIR` here, since that assumes precompiled libraries which is not always the case. So instead I added `MaterialXCore` to `LIB`, which should automatically add the associated includes when used with `find_package(MaterialX)`. This is the system that we are trying to move towards. However Windows doesn't seem to do this. Can you get `find_package(MaterialX)` working in `platform_win32.cmake`? If not, I guess you could do something manual there: ``` add_library(MaterialXCore SHARED IMPORTED) set_target_properties(MaterialXCore PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${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 set(SRC
python.cc python.cc
@ -91,12 +115,6 @@ set(SRC
scene_delegate/volume.cc scene_delegate/volume.cc
) )
set(LIB
${Epoxy_LIBRARIES}
${PYTHON_LIBRARIES}
${BOOST_LIBRARIES}
)
blender_add_lib(bf_render_hydra "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") blender_add_lib(bf_render_hydra "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")
add_dependencies(bf_render_hydra bf_rna) add_dependencies(bf_render_hydra bf_rna)

View File

@ -33,7 +33,7 @@ static PyObject *register_plugins_func(PyObject * /*self*/, PyObject *args)
pyiter = PyObject_GetIter(pyplugin_dirs); pyiter = PyObject_GetIter(pyplugin_dirs);
if (pyiter) { if (pyiter) {
while (pyitem = PyIter_Next(pyiter)) { while ((pyitem = PyIter_Next(pyiter))) {
plugin_dirs.push_back(PyUnicode_AsUTF8(pyitem)); plugin_dirs.push_back(PyUnicode_AsUTF8(pyitem));
Py_DECREF(pyitem); Py_DECREF(pyitem);
} }
@ -87,7 +87,7 @@ static PyObject *engine_create_func(PyObject * /*self*/, PyObject *args)
} }
if (engine) { 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); return PyLong_FromVoidPtr(engine);
} }
@ -102,7 +102,7 @@ static PyObject *engine_free_func(PyObject * /*self*/, PyObject *args)
Engine *engine = (Engine *)PyLong_AsVoidPtr(pyengine); Engine *engine = (Engine *)PyLong_AsVoidPtr(pyengine);
delete engine; delete engine;
CLOG_INFO(LOG_RENDER_HYDRA, 1, "Engine %016llx", engine); CLOG_INFO(LOG_RENDER_HYDRA, 1, "Engine %p", engine);
Py_RETURN_NONE; Py_RETURN_NONE;
} }
@ -119,7 +119,7 @@ static PyObject *engine_sync_func(PyObject * /*self*/, PyObject *args)
engine->sync(depsgraph, context); engine->sync(depsgraph, context);
CLOG_INFO(LOG_RENDER_HYDRA, 2, "Engine %016llx", engine); CLOG_INFO(LOG_RENDER_HYDRA, 2, "Engine %p", engine);
Py_RETURN_NONE; Py_RETURN_NONE;
} }
@ -137,7 +137,7 @@ static PyObject *engine_sync_usd_func(PyObject * /*self*/, PyObject *args)
engine->sync_usd(stage); engine->sync_usd(stage);
CLOG_INFO(LOG_RENDER_HYDRA, 2, "Engine %016llx", engine); CLOG_INFO(LOG_RENDER_HYDRA, 2, "Engine %p", engine);
Py_RETURN_NONE; Py_RETURN_NONE;
} }
@ -157,7 +157,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_RENDER_HYDRA, 3, "Engine %016llx", engine); CLOG_INFO(LOG_RENDER_HYDRA, 3, "Engine %p", engine);
Py_RETURN_NONE; Py_RETURN_NONE;
} }
@ -177,7 +177,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_RENDER_HYDRA, 3, "Engine %016llx", engine); CLOG_INFO(LOG_RENDER_HYDRA, 3, "Engine %p", engine);
Py_RETURN_NONE; Py_RETURN_NONE;
} }
@ -210,7 +210,7 @@ static PyObject *engine_set_sync_setting_func(PyObject * /*self*/, PyObject *arg
Engine *engine = (Engine *)PyLong_AsVoidPtr(pyengine); Engine *engine = (Engine *)PyLong_AsVoidPtr(pyengine);
engine->set_sync_setting(key, get_setting_val(pyval)); engine->set_sync_setting(key, get_setting_val(pyval));
CLOG_INFO(LOG_RENDER_HYDRA, 3, "Engine %016llx: %s", engine, key); CLOG_INFO(LOG_RENDER_HYDRA, 3, "Engine %p: %s", engine, key);
Py_RETURN_NONE; Py_RETURN_NONE;
} }
@ -225,7 +225,7 @@ static PyObject *engine_set_render_setting_func(PyObject * /*self*/, PyObject *a
Engine *engine = (Engine *)PyLong_AsVoidPtr(pyengine); Engine *engine = (Engine *)PyLong_AsVoidPtr(pyengine);
engine->set_render_setting(key, get_setting_val(pyval)); engine->set_render_setting(key, get_setting_val(pyval));
CLOG_INFO(LOG_RENDER_HYDRA, 3, "Engine %016llx: %s", engine, key); CLOG_INFO(LOG_RENDER_HYDRA, 3, "Engine %p: %s", engine, key);
Py_RETURN_NONE; Py_RETURN_NONE;
} }

View File

@ -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) { if (key == pxr::HdTokens->params) {
return pxr::VtValue(task_params_); return pxr::VtValue(task_params_);
@ -127,7 +127,7 @@ pxr::HdRenderBufferDescriptor RenderTaskDelegate::GetRenderBufferDescriptor(pxr:
return buffer_descriptors_[id]; 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}; return {pxr::HdRenderTagTokens->geometry};
} }

View File

@ -273,7 +273,7 @@ pxr::SdfPath BlenderSceneDelegate::prim_id(ID *id, const char *prefix) const
{ {
/* Making id of object in form like <prefix>_<pointer in 16 hex digits format> */ /* Making id of object in form like <prefix>_<pointer in 16 hex digits format> */
char name[32]; 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); return GetDelegateID().AppendElementString(name);
} }

View File

@ -66,7 +66,7 @@ void CurvesData::update()
ID_LOG(1, ""); 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) { if (key == pxr::HdTokens->points) {
return pxr::VtValue(vertices_); return pxr::VtValue(vertices_);
@ -91,7 +91,7 @@ bool CurvesData::update_visibility()
return ret; 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, return pxr::HdBasisCurvesTopology(pxr::HdTokens->linear,
pxr::TfToken(), pxr::TfToken(),

View File

@ -7,7 +7,7 @@
#include <pxr/imaging/hd/sceneDelegate.h> #include <pxr/imaging/hd/sceneDelegate.h>
#include "BKE_duplilist.h" #include "BKE_duplilist.h"
#include "DNA_Curves_types.h" #include "DNA_curves_types.h"
#include "BLI_set.hh" #include "BLI_set.hh"
#include "material.h" #include "material.h"

View File

@ -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(); return pxr::VtValue();
} }

View File

@ -46,7 +46,7 @@ static std::string cache_image_file(Image *image,
opts.im_format = scene->r.im_format; 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); file_path = get_cache_file(file_name);
if (check_exist && BLI_exists(file_path.c_str())) { if (check_exist && BLI_exists(file_path.c_str())) {

View File

@ -163,7 +163,7 @@ void InstancerData::update_instance(Object *parent_ob, DupliObject *dupli)
inst->data = std::make_unique<LightData>(scene_delegate_, ob, p_id); inst->data = std::make_unique<LightData>(scene_delegate_, ob, p_id);
inst->data->init(); 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)); inst->transforms.push_back(gf_matrix_from_transform(dupli->mat));
} }
else { else {
@ -177,7 +177,7 @@ void InstancerData::update_instance(Object *parent_ob, DupliObject *dupli)
else { else {
inst->data->update(); 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()); inst->indices.push_back(mesh_transforms_.size());
mesh_transforms_.push_back(gf_matrix_from_transform(dupli->mat)); 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 <prefix>_<pointer in 16 hex digits format> */ /* Making id of object in form like <prefix>_<pointer in 16 hex digits format> */
char name[32]; char name[32];
snprintf(name, sizeof(name), "O_%016llx", (uint64_t)object); snprintf(name, sizeof(name), "O_%p", object);
return prim_id.AppendElementString(name); return prim_id.AppendElementString(name);
} }

View File

@ -1,14 +1,18 @@
/* SPDX-License-Identifier: Apache-2.0 /* SPDX-License-Identifier: Apache-2.0
* Copyright 2011-2022 Blender Foundation */ * Copyright 2011-2022 Blender Foundation */
#include "BLI_utildefines.h"
#include <pxr/base/arch/fileSystem.h> #include <pxr/base/arch/fileSystem.h>
#include <pxr/usd/ar/resolver.h> #include <pxr/usd/ar/resolver.h>
#include <pxr/usd/ar/resolverContextBinder.h> #include <pxr/usd/ar/resolverContextBinder.h>
#include <pxr/usd/ar/resolverScopedCache.h> #include <pxr/usd/ar/resolverScopedCache.h>
#include <pxr/usd/usdMtlx/reader.h> #ifdef WITH_MATERIALX
#include <pxr/usd/usdMtlx/utils.h> # include <pxr/usd/usdMtlx/reader.h>
# include <pxr/usd/usdMtlx/utils.h>
#endif
#include <pxr/usd/usdShade/material.h> #include <pxr/usd/usdShade/material.h>
#include <pxr/usd/usdShade/shader.h> #include <pxr/usd/usdShade/shader.h>
@ -20,8 +24,6 @@
#include "mtlx_hydra_adapter.h" #include "mtlx_hydra_adapter.h"
namespace mx = MaterialX;
namespace blender::render::hydra { namespace blender::render::hydra {
void hdmtlx_convert_to_materialnetworkmap(std::string const &mtlx_path, 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::TfTokenVector const &render_contexts,
pxr::HdMaterialNetworkMap *out) pxr::HdMaterialNetworkMap *out)
{ {
#ifdef WITH_MATERIALX
if (mtlx_path.empty()) { if (mtlx_path.empty()) {
return; return;
} }
@ -46,17 +49,17 @@ void hdmtlx_convert_to_materialnetworkmap(std::string const &mtlx_path,
pxr::UsdStageRefPtr stage = pxr::UsdStage::CreateInMemory(stage_id, context); pxr::UsdStageRefPtr stage = pxr::UsdStage::CreateInMemory(stage_id, context);
try { try {
mx::DocumentPtr doc = pxr::UsdMtlxReadDocument(mtlx_path); MaterialX::DocumentPtr doc = pxr::UsdMtlxReadDocument(mtlx_path);
pxr::UsdMtlxRead(doc, stage); pxr::UsdMtlxRead(doc, stage);
} }
catch (mx::ExceptionFoundCycle &x) { catch (MaterialX::ExceptionFoundCycle &x) {
Tf_PostErrorHelper(pxr::TF_CALL_CONTEXT, Tf_PostErrorHelper(pxr::TF_CALL_CONTEXT,
pxr::TF_DIAGNOSTIC_RUNTIME_ERROR_TYPE, pxr::TF_DIAGNOSTIC_RUNTIME_ERROR_TYPE,
"MaterialX cycle found: %s\n", "MaterialX cycle found: %s\n",
x.what()); x.what());
return; return;
} }
catch (mx::Exception &x) { catch (MaterialX::Exception &x) {
Tf_PostErrorHelper(pxr::TF_CALL_CONTEXT, Tf_PostErrorHelper(pxr::TF_CALL_CONTEXT,
pxr::TF_DIAGNOSTIC_RUNTIME_ERROR_TYPE, pxr::TF_DIAGNOSTIC_RUNTIME_ERROR_TYPE,
"MaterialX error: %s\n", "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 } // namespace blender::render::hydra

View File

@ -30,7 +30,7 @@ void SimpleLightTaskDelegate::set_camera_path(pxr::SdfPath const &camera_path)
task_params_.cameraPath = 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) { if (key == pxr::HdTokens->params) {
return pxr::VtValue(task_params_); return pxr::VtValue(task_params_);

View File

@ -217,12 +217,12 @@ void DrawTexture::free()
texture_ = nullptr; texture_ = nullptr;
} }
void ViewportEngine::render(Depsgraph *depsgraph) void ViewportEngine::render(Depsgraph * /* depsgraph */)
{ {
/* Empty function */ /* Empty function */
} }
void ViewportEngine::render(Depsgraph *depsgraph, bContext *context) void ViewportEngine::render(Depsgraph * /* depsgraph */, bContext *context)
{ {
ViewSettings view_settings(context); ViewSettings view_settings(context);
if (view_settings.width() * view_settings.height() == 0) { if (view_settings.width() * view_settings.height() == 0) {