From 4951356ebcc5b8491f2e4208eb9325105544b420 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Thu, 26 Dec 2024 17:53:58 +0100 Subject: [PATCH] Refactor: Cycles: Stop using entire OIIO namespace Pull Request: https://projects.blender.org/blender/blender/pulls/132361 --- intern/cycles/app/oiio_output_driver.cpp | 12 +-- intern/cycles/kernel/osl/services.cpp | 115 +++++++++++------------ intern/cycles/kernel/osl/services.h | 28 +++--- intern/cycles/scene/osl.cpp | 2 +- intern/cycles/util/args.h | 2 +- intern/cycles/util/image.h | 5 +- intern/cycles/util/image_impl.h | 3 +- intern/cycles/util/param.h | 17 +++- intern/cycles/util/path.cpp | 13 +-- intern/cycles/util/system.cpp | 7 -- 10 files changed, 104 insertions(+), 100 deletions(-) diff --git a/intern/cycles/app/oiio_output_driver.cpp b/intern/cycles/app/oiio_output_driver.cpp index a6254887f11..58c0fee343a 100644 --- a/intern/cycles/app/oiio_output_driver.cpp +++ b/intern/cycles/app/oiio_output_driver.cpp @@ -51,11 +51,11 @@ void OIIOOutputDriver::write_render_tile(const Tile &tile) } /* Manipulate offset and stride to convert from bottom-up to top-down convention. */ - ImageBuf image_buffer(spec, - pixels.data() + (height - 1) * width * 4, - AutoStride, - -width * 4 * sizeof(float), - AutoStride); + OIIO::ImageBuf image_buffer(spec, + pixels.data() + (height - 1) * width * 4, + AutoStride, + -width * 4 * sizeof(float), + AutoStride); /* Apply gamma correction for (some) non-linear file formats. * TODO: use OpenColorIO view transform if available. */ @@ -63,7 +63,7 @@ void OIIOOutputDriver::write_render_tile(const Tile &tile) u_colorspace_auto, "", image_output->format_name(), true) == u_colorspace_srgb) { const float g = 1.0f / 2.2f; - ImageBufAlgo::pow(image_buffer, image_buffer, {g, g, g, 1.0f}); + OIIO::ImageBufAlgo::pow(image_buffer, image_buffer, {g, g, g, 1.0f}); } /* Write to disk and close */ diff --git a/intern/cycles/kernel/osl/services.cpp b/intern/cycles/kernel/osl/services.cpp index 6bc95768137..6628ed3c7c9 100644 --- a/intern/cycles/kernel/osl/services.cpp +++ b/intern/cycles/kernel/osl/services.cpp @@ -1156,22 +1156,20 @@ bool OSLRenderServices::get_userdata( } #if OSL_LIBRARY_VERSION_CODE >= 11304 -TextureSystem::TextureHandle *OSLRenderServices::get_texture_handle(OSLUStringHash filename, - OSL::ShadingContext *context, - const TextureOpt *opt) +OSL::TextureSystem::TextureHandle *OSLRenderServices::get_texture_handle( + OSLUStringHash filename, OSL::ShadingContext *context, const OSL::TextureOpt *opt) { return get_texture_handle(to_ustring(filename), context, opt); } -TextureSystem::TextureHandle *OSLRenderServices::get_texture_handle(OSL::ustring filename, - OSL::ShadingContext *, - const TextureOpt *) +OSL::TextureSystem::TextureHandle *OSLRenderServices::get_texture_handle( + OSL::ustring filename, OSL::ShadingContext * /*context*/, const OSL::TextureOpt * /*options*/) #elif OSL_LIBRARY_VERSION_CODE >= 11100 -TextureSystem::TextureHandle *OSLRenderServices::get_texture_handle(OSLUStringHash filename, - OSL::ShadingContext *) +OSL::TextureSystem::TextureHandle *OSLRenderServices::get_texture_handle(OSLUStringHash filename, + OSL::ShadingContext *) #else -TextureSystem::TextureHandle *OSLRenderServices::get_texture_handle(OSLUStringHash filename) +OSL::TextureSystem::TextureHandle *OSLRenderServices::get_texture_handle(OSLUStringHash filename) #endif { OSLTextureHandleMap::iterator it = textures.find(filename); @@ -1180,13 +1178,13 @@ TextureSystem::TextureHandle *OSLRenderServices::get_texture_handle(OSLUStringHa /* For non-OIIO textures, just return a pointer to our own OSLTextureHandle. */ if (it != textures.end()) { if (it->second->type != OSLTextureHandle::OIIO) { - return reinterpret_cast(it->second.get()); + return reinterpret_cast(it->second.get()); } } /* Get handle from OpenImageIO. */ OSL::TextureSystem *ts = m_texturesys; - TextureSystem::TextureHandle *handle = ts->get_texture_handle(to_ustring(filename)); + OSL::TextureSystem::TextureHandle *handle = ts->get_texture_handle(to_ustring(filename)); if (handle == nullptr) { return nullptr; } @@ -1199,57 +1197,56 @@ TextureSystem::TextureHandle *OSLRenderServices::get_texture_handle(OSLUStringHa /* Assign OIIO texture handle and return. */ it->second->oiio_handle = handle; - return reinterpret_cast(it->second.get()); + return reinterpret_cast(it->second.get()); } - else { - /* Construct GPU texture handle for existing textures. */ - if (it != textures.end()) { - switch (it->second->type) { - case OSLTextureHandle::OIIO: - return nullptr; - case OSLTextureHandle::SVM: - if (!it->second->handle.empty() && it->second->handle.get_manager() != image_manager) { - it.clear(); - break; - } - return reinterpret_cast(OSL_TEXTURE_HANDLE_TYPE_SVM | - it->second->svm_slots[0].y); - case OSLTextureHandle::IES: - if (!it->second->handle.empty() && it->second->handle.get_manager() != image_manager) { - it.clear(); - break; - } - return reinterpret_cast(OSL_TEXTURE_HANDLE_TYPE_IES | - it->second->svm_slots[0].y); - case OSLTextureHandle::AO: - return reinterpret_cast( - OSL_TEXTURE_HANDLE_TYPE_AO_OR_BEVEL | 1); - case OSLTextureHandle::BEVEL: - return reinterpret_cast( - OSL_TEXTURE_HANDLE_TYPE_AO_OR_BEVEL | 2); - } - } - if (!image_manager) { - return nullptr; + /* Construct GPU texture handle for existing textures. */ + if (it != textures.end()) { + switch (it->second->type) { + case OSLTextureHandle::OIIO: + return nullptr; + case OSLTextureHandle::SVM: + if (!it->second->handle.empty() && it->second->handle.get_manager() != image_manager) { + it.clear(); + break; + } + return reinterpret_cast(OSL_TEXTURE_HANDLE_TYPE_SVM | + it->second->svm_slots[0].y); + case OSLTextureHandle::IES: + if (!it->second->handle.empty() && it->second->handle.get_manager() != image_manager) { + it.clear(); + break; + } + return reinterpret_cast(OSL_TEXTURE_HANDLE_TYPE_IES | + it->second->svm_slots[0].y); + case OSLTextureHandle::AO: + return reinterpret_cast( + OSL_TEXTURE_HANDLE_TYPE_AO_OR_BEVEL | 1); + case OSLTextureHandle::BEVEL: + return reinterpret_cast( + OSL_TEXTURE_HANDLE_TYPE_AO_OR_BEVEL | 2); } - - /* Load new textures using SVM image manager. */ - ImageHandle handle = image_manager->add_image(filename.string(), ImageParams()); - if (handle.empty()) { - return nullptr; - } - - if (!textures.insert(filename, new OSLTextureHandle(handle))) { - return nullptr; - } - - return reinterpret_cast(OSL_TEXTURE_HANDLE_TYPE_SVM | - handle.svm_slot()); } + + if (!image_manager) { + return nullptr; + } + + /* Load new textures using SVM image manager. */ + ImageHandle handle = image_manager->add_image(filename.string(), ImageParams()); + if (handle.empty()) { + return nullptr; + } + + if (!textures.insert(filename, new OSLTextureHandle(handle))) { + return nullptr; + } + + return reinterpret_cast(OSL_TEXTURE_HANDLE_TYPE_SVM | + handle.svm_slot()); } -bool OSLRenderServices::good(TextureSystem::TextureHandle *texture_handle) +bool OSLRenderServices::good(OSL::TextureSystem::TextureHandle *texture_handle) { OSLTextureHandle *handle = (OSLTextureHandle *)texture_handle; @@ -1265,7 +1262,7 @@ bool OSLRenderServices::good(TextureSystem::TextureHandle *texture_handle) bool OSLRenderServices::texture(OSLUStringHash filename, TextureHandle *texture_handle, TexturePerthread *texture_thread_info, - TextureOpt &options, + OSL::TextureOpt &options, OSL::ShaderGlobals *sg, float s, float t, @@ -1450,7 +1447,7 @@ bool OSLRenderServices::texture(OSLUStringHash filename, bool OSLRenderServices::texture3d(OSLUStringHash filename, TextureHandle *texture_handle, TexturePerthread *texture_thread_info, - TextureOpt &options, + OSL::TextureOpt &options, OSL::ShaderGlobals *sg, const OSL::Vec3 &P, const OSL::Vec3 &dPdx, @@ -1564,7 +1561,7 @@ bool OSLRenderServices::texture3d(OSLUStringHash filename, bool OSLRenderServices::environment(OSLUStringHash filename, TextureHandle *texture_handle, TexturePerthread *thread_info, - TextureOpt &options, + OSL::TextureOpt &options, OSL::ShaderGlobals *sg, const OSL::Vec3 &R, const OSL::Vec3 &dRdx, diff --git a/intern/cycles/kernel/osl/services.h b/intern/cycles/kernel/osl/services.h index 696ed035156..2b6ee1d705a 100644 --- a/intern/cycles/kernel/osl/services.h +++ b/intern/cycles/kernel/osl/services.h @@ -191,25 +191,25 @@ class OSLRenderServices : public OSL::RendererServices { bool derivatives) override; #if OSL_LIBRARY_VERSION_CODE >= 11304 - TextureSystem::TextureHandle *get_texture_handle(OSL::ustring filename, - OSL::ShadingContext *context, - const TextureOpt *options) override; - TextureSystem::TextureHandle *get_texture_handle(OSLUStringHash filename, - OSL::ShadingContext *context, - const TextureOpt *options) override; + OSL::TextureSystem::TextureHandle *get_texture_handle(OSL::ustring filename, + OSL::ShadingContext *context, + const OSL::TextureOpt *options) override; + OSL::TextureSystem::TextureHandle *get_texture_handle(OSLUStringHash filename, + OSL::ShadingContext *context, + const OSL::TextureOpt *options) override; #elif OSL_LIBRARY_VERSION_CODE >= 11100 - TextureSystem::TextureHandle *get_texture_handle(OSLUStringHash filename, - OSL::ShadingContext *context) override; + OSL::TextureSystem::TextureHandle *get_texture_handle(OSLUStringHash filename, + OSL::ShadingContext *context) override; #else - TextureSystem::TextureHandle *get_texture_handle(OSLUStringHash filename) override; + OSL::TextureSystem::TextureHandle *get_texture_handle(OSLUStringHash filename) override; #endif - bool good(TextureSystem::TextureHandle *texture_handle) override; + bool good(OSL::TextureSystem::TextureHandle *texture_handle) override; bool texture(OSLUStringHash filename, - TextureSystem::TextureHandle *texture_handle, + OSL::TextureSystem::TextureHandle *texture_handle, TexturePerthread *texture_thread_info, - TextureOpt &options, + OSL::TextureOpt &options, OSL::ShaderGlobals *sg, float s, float t, @@ -226,7 +226,7 @@ class OSLRenderServices : public OSL::RendererServices { bool texture3d(OSLUStringHash filename, TextureHandle *texture_handle, TexturePerthread *texture_thread_info, - TextureOpt &options, + OSL::TextureOpt &options, OSL::ShaderGlobals *sg, const OSL::Vec3 &P, const OSL::Vec3 &dPdx, @@ -242,7 +242,7 @@ class OSLRenderServices : public OSL::RendererServices { bool environment(OSLUStringHash filename, TextureHandle *texture_handle, TexturePerthread *texture_thread_info, - TextureOpt &options, + OSL::TextureOpt &options, OSL::ShaderGlobals *sg, const OSL::Vec3 &R, const OSL::Vec3 &dRdx, diff --git a/intern/cycles/scene/osl.cpp b/intern/cycles/scene/osl.cpp index 33cf76e73d5..6d788795754 100644 --- a/intern/cycles/scene/osl.cpp +++ b/intern/cycles/scene/osl.cpp @@ -262,7 +262,7 @@ void OSLShaderManager::texture_system_init() thread_scoped_lock lock(ts_shared_mutex); if (ts_shared_users++ == 0) { - ts_shared = TextureSystem::create(true); + ts_shared = OSL::TextureSystem::create(true); ts_shared->attribute("automip", 1); ts_shared->attribute("autotile", 64); diff --git a/intern/cycles/util/args.h b/intern/cycles/util/args.h index d0d904bc465..8d100291372 100644 --- a/intern/cycles/util/args.h +++ b/intern/cycles/util/args.h @@ -11,6 +11,6 @@ CCL_NAMESPACE_BEGIN -OIIO_NAMESPACE_USING +using OIIO::ArgParse; CCL_NAMESPACE_END diff --git a/intern/cycles/util/image.h b/intern/cycles/util/image.h index fb46b9221d0..c8fd4a2bb3c 100644 --- a/intern/cycles/util/image.h +++ b/intern/cycles/util/image.h @@ -13,7 +13,10 @@ CCL_NAMESPACE_BEGIN -OIIO_NAMESPACE_USING +using OIIO::AutoStride; +using OIIO::ImageInput; +using OIIO::ImageOutput; +using OIIO::ImageSpec; template void util_image_resize_pixels(const vector &input_pixels, diff --git a/intern/cycles/util/image_impl.h b/intern/cycles/util/image_impl.h index f9ff067a2cf..8c6a0ccb991 100644 --- a/intern/cycles/util/image_impl.h +++ b/intern/cycles/util/image_impl.h @@ -4,9 +4,8 @@ #pragma once -#include "util/algorithm.h" -#include "util/half.h" #include "util/image.h" +#include "util/math_base.h" CCL_NAMESPACE_BEGIN diff --git a/intern/cycles/util/param.h b/intern/cycles/util/param.h index e4cd337406f..3822d829fef 100644 --- a/intern/cycles/util/param.h +++ b/intern/cycles/util/param.h @@ -13,7 +13,19 @@ CCL_NAMESPACE_BEGIN -OIIO_NAMESPACE_USING +using OIIO::ParamValue; + +using OIIO::TypeColor; +using OIIO::TypeDesc; +using OIIO::TypeFloat; +using OIIO::TypeFloat4; +using OIIO::TypeInt; +using OIIO::TypeMatrix; +using OIIO::TypeNormal; +using OIIO::TypePoint; +using OIIO::TypeString; +using OIIO::TypeUnknown; +using OIIO::TypeVector; static constexpr TypeDesc TypeFloat2(TypeDesc::FLOAT, TypeDesc::VEC2); static constexpr TypeDesc TypeRGBA(TypeDesc::FLOAT, TypeDesc::VEC4, TypeDesc::COLOR); @@ -22,4 +34,7 @@ static constexpr TypeDesc TypeFloatArray4(TypeDesc::FLOAT, TypeDesc::NOSEMANTICS, 4); +using OIIO::ustring; +using OIIO::ustringhash; + CCL_NAMESPACE_END diff --git a/intern/cycles/util/path.cpp b/intern/cycles/util/path.cpp index a83e769d16b..c45f7098dc3 100644 --- a/intern/cycles/util/path.cpp +++ b/intern/cycles/util/path.cpp @@ -14,9 +14,7 @@ #include #include -OIIO_NAMESPACE_USING - -#include +#include #include @@ -38,7 +36,6 @@ OIIO_NAMESPACE_USING # include #endif -#include "util/map.h" #include "util/windows.h" CCL_NAMESPACE_BEGIN @@ -344,8 +341,8 @@ string path_get(const string &sub) return special; } - if (cached_path == "") { - cached_path = path_dirname(Sysutil::this_program_path()); + if (cached_path.empty()) { + cached_path = path_dirname(OIIO::Sysutil::this_program_path()); } return path_join(cached_path, sub); @@ -353,8 +350,8 @@ string path_get(const string &sub) string path_user_get(const string &sub) { - if (cached_user_path == "") { - cached_user_path = path_dirname(Sysutil::this_program_path()); + if (cached_user_path.empty()) { + cached_user_path = path_dirname(OIIO::Sysutil::this_program_path()); } return path_join(cached_user_path, sub); diff --git a/intern/cycles/util/system.cpp b/intern/cycles/util/system.cpp index 1eda393c4f4..3c98a10ae70 100644 --- a/intern/cycles/util/system.cpp +++ b/intern/cycles/util/system.cpp @@ -3,14 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ #include "util/system.h" - -#include "util/log.h" #include "util/string.h" -#include "util/types.h" - -#include - -OIIO_NAMESPACE_USING #ifdef _WIN32 # if (!defined(FREE_WINDOWS))