Add scene setting to export through either Hydra or USD, for debugging #65

Merged
Brecht Van Lommel merged 7 commits from brecht/blender:hydra-usd-export into hydra-render 2023-07-14 19:41:17 +02:00
14 changed files with 190 additions and 35 deletions
Showing only changes of commit 16e7896c9f - Show all commits

View File

@ -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_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)
@ -45,9 +57,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
) )
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
@ -96,12 +120,6 @@ set(SRC
scene_delegate/world.h scene_delegate/world.h
) )
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;
} }
@ -117,7 +117,7 @@ static PyObject *engine_sync_func(PyObject * /*self*/, PyObject *args)
Depsgraph *depsgraph = (Depsgraph *)PyLong_AsVoidPtr(pydepsgraph); Depsgraph *depsgraph = (Depsgraph *)PyLong_AsVoidPtr(pydepsgraph);
bContext *context = (bContext *)PyLong_AsVoidPtr(pycontext); 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); engine->sync(depsgraph, context);
Py_RETURN_NONE; Py_RETURN_NONE;
@ -134,7 +134,7 @@ static PyObject *engine_render_func(PyObject * /*self*/, PyObject *args)
Engine *engine = (Engine *)PyLong_AsVoidPtr(pyengine); Engine *engine = (Engine *)PyLong_AsVoidPtr(pyengine);
Depsgraph *depsgraph = (Depsgraph *)PyLong_AsVoidPtr(pydepsgraph); 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. */ /* Allow Blender to execute other Python scripts. */
Py_BEGIN_ALLOW_THREADS; Py_BEGIN_ALLOW_THREADS;
@ -155,7 +155,7 @@ static PyObject *engine_view_draw_func(PyObject * /*self*/, PyObject *args)
Depsgraph *depsgraph = (Depsgraph *)PyLong_AsVoidPtr(pydepsgraph); Depsgraph *depsgraph = (Depsgraph *)PyLong_AsVoidPtr(pydepsgraph);
bContext *context = (bContext *)PyLong_AsVoidPtr(pycontext); 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. */ /* Allow Blender to execute other Python scripts. */
Py_BEGIN_ALLOW_THREADS; Py_BEGIN_ALLOW_THREADS;
@ -193,7 +193,7 @@ static PyObject *engine_set_sync_setting_func(PyObject * /*self*/, PyObject *arg
Engine *engine = (Engine *)PyLong_AsVoidPtr(pyengine); 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)); engine->set_sync_setting(key, get_setting_val(pyval));
Py_RETURN_NONE; Py_RETURN_NONE;
@ -209,7 +209,7 @@ static PyObject *engine_set_render_setting_func(PyObject * /*self*/, PyObject *a
Engine *engine = (Engine *)PyLong_AsVoidPtr(pyengine); 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)); engine->set_render_setting(key, get_setting_val(pyval));
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

@ -263,7 +263,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

@ -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) {

View File

@ -665,6 +665,33 @@ if(WITH_CYCLES OR WITH_OPENGL_RENDER_TESTS)
-outdir "${TEST_OUT_DIR}/workbench" -outdir "${TEST_OUT_DIR}/workbench"
) )
endforeach() endforeach()
if(WITH_HYDRA)
# Hydra Storm
foreach(render_test ${render_tests})
add_python_test(
hydra_storm_${render_test}_test
${CMAKE_CURRENT_LIST_DIR}/storm_render_tests.py
-blender "${TEST_BLENDER_EXE}"
-testdir "${TEST_SRC_DIR}/render/${render_test}"
-idiff "${OPENIMAGEIO_IDIFF}"
-outdir "${TEST_OUT_DIR}/hydra_storm"
-export_method "HYDRA"
)
endforeach()
foreach(render_test ${render_tests})
add_python_test(
usd_storm_${render_test}_test
${CMAKE_CURRENT_LIST_DIR}/storm_render_tests.py
-blender "${TEST_BLENDER_EXE}"
-testdir "${TEST_SRC_DIR}/render/${render_test}"
-idiff "${OPENIMAGEIO_IDIFF}"
-outdir "${TEST_OUT_DIR}/usd_storm"
-export_method "USD"
)
endforeach()
endif()
endif() endif()
endif() endif()
endif() endif()

View File

@ -0,0 +1,101 @@
#!/usr/bin/env python3
# SPDX-FileCopyrightText: 2015-2023 Blender Foundation
#
# SPDX-License-Identifier: Apache-2.0
import argparse
import os
import platform
import shlex
import shutil
import subprocess
import sys
from pathlib import Path
def setup():
import bpy
import addon_utils
addon_utils.enable("hydra_storm")
for scene in bpy.data.scenes:
scene.render.engine = 'HYDRA_STORM'
scene.hydra.export_method = os.environ['BLENDER_HYDRA_EXPORT_METHOD']
# When run from inside Blender, render and exit.
try:
import bpy
inside_blender = True
except ImportError:
inside_blender = False
if inside_blender:
try:
setup()
except Exception as e:
print(e)
sys.exit(1)
def get_arguments(filepath, output_filepath):
return [
"--background",
"-noaudio",
"--factory-startup",
"--enable-autoexec",
"--debug-memory",
"--debug-exit-on-error",
filepath,
"-P",
os.path.realpath(__file__),
"-o", output_filepath,
"-F", "PNG",
"-f", "1"]
def create_argparse():
parser = argparse.ArgumentParser()
parser.add_argument("-blender", nargs="+")
parser.add_argument("-testdir", nargs=1)
parser.add_argument("-outdir", nargs=1)
parser.add_argument("-idiff", nargs=1)
parser.add_argument("-export_method", nargs=1)
return parser
def main():
parser = create_argparse()
args = parser.parse_args()
blender = args.blender[0]
test_dir = args.testdir[0]
idiff = args.idiff[0]
output_dir = args.outdir[0]
export_method = args.export_method[0]
from modules import render_report
name = "Storm Hydra" if export_method == 'HYDRA' else 'Storm USD'
report = render_report.Report(name, output_dir, idiff)
report.set_pixelated(True)
report.set_reference_dir("storm_renders")
if export_method == 'HYDRA':
report.set_compare_engine('cycles', 'CPU')
else:
report.set_compare_engine('hydra_storm')
test_dir_name = Path(test_dir).name
os.environ['BLENDER_HYDRA_EXPORT_METHOD'] = export_method
ok = report.run(test_dir, blender, get_arguments, batch=True)
sys.exit(not ok)
if not inside_blender and __name__ == "__main__":
main()