[Bf-blender-cvs] [db34c9eceb4] cycles_texture_cache: Cycles: first additions for OIIO texture caching
Stefan Werner
noreply at git.blender.org
Mon Nov 27 20:40:05 CET 2017
Commit: db34c9eceb4b1de5df2188176464488c0b18a77f
Author: Stefan Werner
Date: Thu May 4 13:09:17 2017 +0200
Branches: cycles_texture_cache
https://developer.blender.org/rBdb34c9eceb4b1de5df2188176464488c0b18a77f
Cycles: first additions for OIIO texture caching
* TextureSystem options are exposed in the UI
* Automatic generation of .tx files is optional
* Texture lookups do not use differentials or mip maps yet, so performance is pretty bad
===================================================================
M intern/cycles/blender/addon/properties.py
M intern/cycles/blender/addon/ui.py
M intern/cycles/blender/blender_sync.cpp
M intern/cycles/device/device.h
M intern/cycles/device/device_cpu.cpp
M intern/cycles/kernel/kernel_globals.h
A intern/cycles/kernel/kernel_oiio_globals.h
M intern/cycles/kernel/kernel_types.h
M intern/cycles/kernel/svm/svm_image.h
M intern/cycles/render/image.cpp
M intern/cycles/render/image.h
M intern/cycles/render/osl.cpp
M intern/cycles/render/osl.h
M intern/cycles/render/scene.h
M intern/cycles/render/shader.cpp
M intern/cycles/render/shader.h
M intern/cycles/render/svm.cpp
===================================================================
diff --git a/intern/cycles/blender/addon/properties.py b/intern/cycles/blender/addon/properties.py
index e5084138a9c..f8363390829 100644
--- a/intern/cycles/blender/addon/properties.py
+++ b/intern/cycles/blender/addon/properties.py
@@ -616,6 +616,49 @@ class CyclesRenderSettings(bpy.types.PropertyGroup):
items=enum_texture_limit
)
+ cls.texture_cache_size = IntProperty(
+ name="Texture Cache Size (MB)",
+ default=0,
+ description="The size of the OpenImageIO texture cache in MB. A value of 0 turns off texture caching. Typical values are in the range of 100s of MB.",
+ min=0
+ )
+
+ cls.texture_auto_convert = BoolProperty(
+ name="Auto Convert Textures",
+ default=True,
+ description="Automatically convert textures to .tx files for optimal texture cache performance."
+ )
+
+ cls.texture_accept_unmipped = BoolProperty(
+ name="Accept Unmipped",
+ default=True,
+ description="Texture cached rendering without mip mapping is very expensive. Uncheck to prevent Cycles from using textures that are not mip mapped."
+ )
+
+ cls.texture_accept_untiled = BoolProperty(
+ name="Accept Untiled",
+ default=True,
+ description="Texture cached rendering without tiled textures is very expensive. Uncheck to prevent Cycles from using textures that are not tiled."
+ )
+
+ cls.texture_auto_tile = BoolProperty(
+ name="Auto Tile",
+ default=True,
+ description="On the fly creation of tiled versions of textures that are not tiled. This can increase render time but helps reduce memory usage."
+ )
+
+ cls.texture_auto_mip = BoolProperty(
+ name="Auto Mip",
+ default=True,
+ description="On the fly creation of mip maps of textures that are not mip mapped. This can increase render time but helps reduce memory usage."
+ )
+
+ cls.texture_tile_size = IntProperty(
+ name="Tile Size",
+ default=64,
+ description="The size of tiles that Cycles uses for auto tiling."
+ )
+
cls.ao_bounces = IntProperty(
name="AO Bounces",
default=0,
diff --git a/intern/cycles/blender/addon/ui.py b/intern/cycles/blender/addon/ui.py
index 03ca1ab6c7f..95f5cda970c 100644
--- a/intern/cycles/blender/addon/ui.py
+++ b/intern/cycles/blender/addon/ui.py
@@ -412,6 +412,16 @@ class CYCLES_RENDER_PT_performance(CyclesButtonsPanel, Panel):
subsub.active = False
subsub.prop(cscene, "use_progressive_refine")
+ sub.separator()
+ sub.label(text="Texture Cache:")
+ sub.prop(cscene, "texture_cache_size")
+ sub.prop(cscene, "texture_auto_convert")
+ sub.prop(cscene, "texture_accept_unmipped")
+ sub.prop(cscene, "texture_accept_untiled")
+ sub.prop(cscene, "texture_auto_mip")
+ sub.prop(cscene, "texture_auto_tile")
+ sub.prop(cscene, "texture_tile_size")
+
col = split.column()
col.label(text="Final Render:")
diff --git a/intern/cycles/blender/blender_sync.cpp b/intern/cycles/blender/blender_sync.cpp
index e24ed31b926..bdc40b5c0e8 100644
--- a/intern/cycles/blender/blender_sync.cpp
+++ b/intern/cycles/blender/blender_sync.cpp
@@ -668,6 +668,14 @@ SceneParams BlenderSync::get_scene_params(BL::Scene& b_scene,
params.use_qbvh = DebugFlags().cpu.qbvh;
+ params.texture_cache_size = RNA_int_get(&cscene, "texture_cache_size");
+ params.texture_auto_convert = RNA_int_get(&cscene, "texture_auto_convert");
+ params.texture_accept_unmipped = RNA_int_get(&cscene, "texture_accept_unmipped");
+ params.texture_accept_untiled = RNA_int_get(&cscene, "texture_accept_untiled");
+ params.texture_tile_size = RNA_int_get(&cscene, "texture_tile_size");
+ params.texture_auto_mip = RNA_int_get(&cscene, "texture_auto_mip");
+ params.texture_auto_tile = RNA_int_get(&cscene, "texture_auto_tile");
+
return params;
}
diff --git a/intern/cycles/device/device.h b/intern/cycles/device/device.h
index 35b545388f2..5293b72456a 100644
--- a/intern/cycles/device/device.h
+++ b/intern/cycles/device/device.h
@@ -293,6 +293,9 @@ public:
/* open shading language, only for CPU device */
virtual void *osl_memory() { return NULL; }
+
+ /* open image io, only for CPU device */
+ virtual void *oiio_memory() { return NULL; }
/* load/compile kernels, must be called before adding tasks */
virtual bool load_kernels(
diff --git a/intern/cycles/device/device_cpu.cpp b/intern/cycles/device/device_cpu.cpp
index 999b9230d29..a7708ba2a62 100644
--- a/intern/cycles/device/device_cpu.cpp
+++ b/intern/cycles/device/device_cpu.cpp
@@ -34,6 +34,7 @@
#include "kernel/kernel_types.h"
#include "kernel/split/kernel_split_data.h"
#include "kernel/kernel_globals.h"
+#include "kernel/kernel_oiio_globals.h"
#include "kernel/filter/filter.h"
@@ -169,6 +170,7 @@ public:
#ifdef WITH_OSL
OSLGlobals osl_globals;
#endif
+ OIIOGlobals oiio_globals;
bool use_split_kernel;
@@ -237,6 +239,13 @@ public:
#ifdef WITH_OSL
kernel_globals.osl = &osl_globals;
#endif
+ oiio_globals.tex_sys = TextureSystem::create();
+ oiio_globals.tex_sys->attribute("max_memory_MB", 1024.0f);
+ oiio_globals.tex_sys->attribute("autotile", 64);
+ oiio_globals.tex_sys->attribute("automip", 64);
+ oiio_globals.tex_sys->attribute("gray_to_rgb", 1);
+ kernel_globals.oiio = &oiio_globals;
+
use_split_kernel = DebugFlags().cpu.split_kernel;
if(use_split_kernel) {
VLOG(1) << "Will be using split kernel.";
@@ -269,7 +278,11 @@ public:
~CPUDevice()
{
task_pool.stop();
- texture_info.free();
+ texture_info.free();
+ VLOG(1) << oiio_globals.tex_sys->getstats();
+ oiio_globals.tex_sys->reset_stats();
+ TextureSystem::destroy(oiio_globals.tex_sys);
+ kernel_globals.oiio = NULL;
}
virtual bool show_samples() const
@@ -439,6 +452,11 @@ public:
#endif
}
+ void *oiio_memory()
+ {
+ return &oiio_globals;
+ }
+
void thread_run(DeviceTask *task)
{
if(task->type == DeviceTask::RENDER) {
diff --git a/intern/cycles/kernel/kernel_globals.h b/intern/cycles/kernel/kernel_globals.h
index 97d4726407b..220f665330f 100644
--- a/intern/cycles/kernel/kernel_globals.h
+++ b/intern/cycles/kernel/kernel_globals.h
@@ -41,6 +41,9 @@ struct OSLGlobals;
struct OSLThreadData;
struct OSLShadingSystem;
# endif
+# ifdef __OIIO__
+struct OIIOGlobals;
+# endif
struct Intersection;
struct VolumeStep;
@@ -60,6 +63,10 @@ typedef struct KernelGlobals {
OSLThreadData *osl_tdata;
# endif
+# ifdef __OIIO__
+ OIIOGlobals *oiio;
+# endif
+
/* **** Run-time data **** */
/* Heap-allocated storage for transparent shadows intersections. */
diff --git a/intern/cycles/kernel/kernel_oiio_globals.h b/intern/cycles/kernel/kernel_oiio_globals.h
new file mode 100644
index 00000000000..713752d3a3d
--- /dev/null
+++ b/intern/cycles/kernel/kernel_oiio_globals.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2011-2017 Blender Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __KERNEL_OIIO_GLOBALS_H__
+#define __KERNEL_OIIO_GLOBALS_H__
+
+#include <OpenImageIO/texture.h>
+#include "util/util_vector.h"
+
+CCL_NAMESPACE_BEGIN
+
+struct OIIOGlobals
+{
+public:
+ OIIO::TextureSystem *tex_sys;
+ vector<OIIO::TextureSystem::TextureHandle*> tex_paths;
+};
+
+CCL_NAMESPACE_END
+
+#endif
diff --git a/intern/cycles/kernel/kernel_types.h b/intern/cycles/kernel/kernel_types.h
index c4a9b3f4aa3..5c77e921366 100644
--- a/intern/cycles/kernel/kernel_types.h
+++ b/intern/cycles/kernel/kernel_types.h
@@ -89,6 +89,7 @@ CCL_NAMESPACE_BEGIN
# ifdef WITH_OSL
# define __OSL__
# endif
+# define __OIIO__
# define __PRINCIPLED__
# define __SUBSURFACE__
# define __CMJ__
diff --git a/intern/cycles/kernel/svm/svm_image.h b/intern/cycles/kernel/svm/svm_image.h
index 4226e7adfe0..934347c5964 100644
--- a/intern/cycles/kernel/svm/svm_image.h
+++ b/intern/cycles/kernel/svm/svm_image.h
@@ -14,11 +14,30 @@
* limitations under the License.
*/
+#ifdef __OIIO__
+# include "kernel/kernel_oiio_globals.h"
+#endif
+
CCL_NAMESPACE_BEGIN
ccl_device float4 svm_image_texture(KernelGlobals *kg, int id, float x, float y, uint srgb, uint use_alpha)
{
- float4 r = kernel_tex_image_interp(kg, id, x, y);
+ float4 r;
+# ifdef __OIIO__
+ if(kg->oiio && kg->oiio->tex_paths.size() > id) {
+ OIIO::TextureOpt options;
+ options.swrap = options.twrap = OIIO::TextureOpt::WrapPeriodic;
+ options.interpmode = OIIO::TextureOpt::InterpBilinear;
+ options.mipmode = OIIO::TextureOpt::MipModeNoMIP;
+ if(kg->oiio->tex_paths[id]) {
+ bool success = kg->oiio->tex_sys->texture(kg->oiio->tex_paths[id], kg->oiio->tex_sys->get_perthread_info(), options, x, 1.0f - y, 0.0f, 0.0f, 0.0f, 0.0f, 3, (float*)&r);
+ if(!success) {
+ (void) kg->oiio->tex_sys->geterror();
+ }
+ }
+ } else
+# endif
+ r = kernel_tex_image_interp(kg, id, x, y);
const float alpha = r.w;
if(use_alpha && alpha != 1.0f && alpha != 0.0f) {
diff --git a/intern/cycles/render/image.cpp b/intern/cycles/render/image.cpp
index 482442cce29..3faeaaf1be0 100644
--- a/intern/cycles/render/image.cpp
+++ b/intern/cycles/render/image.cpp
@@ -28,6 +28,9 @@
#include <OSL/oslexec.h>
#endif
+#include "kernel/kernel_oiio_globals.h"
+#include <OpenImageIO/ImageBufAlgo.h>
+
CCL_NAMESPACE_BEGIN
/* Some helpers to silence warning in templated function. */
@@ -43,7 +46,8 @@ static bool isfinite(half /*value*/)
ImageManager::ImageManager(const DeviceInfo& info)
{
need_update = true;
- osl_texture_system = NU
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list