diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-04-05 19:42:31 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-04-05 19:42:31 +0400 |
commit | 89926a0598a794043ed9b702f32d119fed888c04 (patch) | |
tree | 9d6dae64adcd31e738e32141fa9c15219c6cb981 /intern | |
parent | 83fff218cca47147183c1177de9db1381cfa48e6 (diff) | |
parent | 12981b004891aa6dbd2334a4c732ba38c1b0c349 (diff) |
svn merge ^/trunk/blender -r55776:55813
Diffstat (limited to 'intern')
-rw-r--r-- | intern/cycles/kernel/kernel_camera.h | 6 | ||||
-rw-r--r-- | intern/cycles/render/osl.cpp | 40 | ||||
-rw-r--r-- | intern/cycles/render/osl.h | 5 | ||||
-rw-r--r-- | intern/opencolorio/ocio_impl_glsl.cc | 25 |
4 files changed, 61 insertions, 15 deletions
diff --git a/intern/cycles/kernel/kernel_camera.h b/intern/cycles/kernel/kernel_camera.h index 694ef8bd01d..800daf40887 100644 --- a/intern/cycles/kernel/kernel_camera.h +++ b/intern/cycles/kernel/kernel_camera.h @@ -115,10 +115,10 @@ __device void camera_sample_orthographic(KernelGlobals *kg, float raster_x, floa float3 Pfocus = ray->D*ft; /* update ray for effect of lens */ - ray->P = make_float3(lensuv.x, lensuv.y, 0.0f); - ray->D = normalize(Pfocus - ray->P); + float3 lensuvw = make_float3(lensuv.x, lensuv.y, 0.0f); - ray->P += Pcamera; + ray->P += lensuvw; + ray->D = normalize(Pfocus - lensuvw); } /* transform ray from camera to world */ diff --git a/intern/cycles/render/osl.cpp b/intern/cycles/render/osl.cpp index cefb6315725..3294f1ebe4c 100644 --- a/intern/cycles/render/osl.cpp +++ b/intern/cycles/render/osl.cpp @@ -41,6 +41,12 @@ CCL_NAMESPACE_BEGIN #ifdef WITH_OSL +/* Shared Texture System */ + +OSL::TextureSystem *OSLShaderManager::ts_shared = NULL; +int OSLShaderManager::ts_shared_users = 0; +thread_mutex OSLShaderManager::ts_shared_mutex; + /* Shader Manager */ OSLShaderManager::OSLShaderManager() @@ -54,7 +60,17 @@ OSLShaderManager::OSLShaderManager() OSLShaderManager::~OSLShaderManager() { OSL::ShadingSystem::destroy(ss); - OSL::TextureSystem::destroy(ts); + + /* shared texture system decrease users and destroy if no longer used */ + { + thread_scoped_lock lock(ts_shared_mutex); + ts_shared_users--; + + if(ts_shared_users == 0) { + OSL::TextureSystem::destroy(ts_shared); + ts_shared = NULL; + } + } delete services; } @@ -133,14 +149,22 @@ void OSLShaderManager::device_free(Device *device, DeviceScene *dscene, Scene *s void OSLShaderManager::texture_system_init() { - /* if we let OSL create it, it leaks */ - ts = TextureSystem::create(true); - ts->attribute("automip", 1); - ts->attribute("autotile", 64); - ts->attribute("gray_to_rgb", 1); + /* create texture system, shared between different renders to reduce memory usage */ + thread_scoped_lock lock(ts_shared_mutex); + + if(ts_shared_users == 0) { + ts_shared = TextureSystem::create(true); + + ts_shared->attribute("automip", 1); + ts_shared->attribute("autotile", 64); + ts_shared->attribute("gray_to_rgb", 1); + + /* effectively unlimited for now, until we support proper mipmap lookups */ + ts_shared->attribute("max_memory_MB", 16384); + } - /* effectively unlimited for now, until we support proper mipmap lookups */ - ts->attribute("max_memory_MB", 16384); + ts = ts_shared; + ts_shared_users++; } void OSLShaderManager::shading_system_init() diff --git a/intern/cycles/render/osl.h b/intern/cycles/render/osl.h index 2d3996df0eb..c459f6bfa08 100644 --- a/intern/cycles/render/osl.h +++ b/intern/cycles/render/osl.h @@ -21,6 +21,7 @@ #include "util_set.h" #include "util_string.h" +#include "util_thread.h" #include "shader.h" @@ -92,6 +93,10 @@ protected: OSLRenderServices *services; OSL::ErrorHandler errhandler; map<string, OSLShaderInfo> loaded_shaders; + + static OSL::TextureSystem *ts_shared; + static thread_mutex ts_shared_mutex; + static int ts_shared_users; }; #endif diff --git a/intern/opencolorio/ocio_impl_glsl.cc b/intern/opencolorio/ocio_impl_glsl.cc index 9343a13e888..cfa758e9a84 100644 --- a/intern/opencolorio/ocio_impl_glsl.cc +++ b/intern/opencolorio/ocio_impl_glsl.cc @@ -60,6 +60,7 @@ typedef struct OCIO_GLSLDrawState { bool lut3d_texture_allocated; /* boolean flag indicating whether * lut texture is allocated */ + bool lut3d_texture_valid; GLuint lut3d_texture; /* OGL texture ID for 3D LUT */ @@ -170,12 +171,12 @@ static OCIO_GLSLDrawState *allocateOpenGLState(void) } /* Ensure LUT texture and array are allocated */ -static void ensureLUT3DAllocated(OCIO_GLSLDrawState *state) +static bool ensureLUT3DAllocated(OCIO_GLSLDrawState *state) { int num_3d_entries = 3 * LUT3D_EDGE_SIZE * LUT3D_EDGE_SIZE * LUT3D_EDGE_SIZE; if (state->lut3d_texture_allocated) - return; + return state->lut3d_texture_valid; glGenTextures(1, &state->lut3d_texture); @@ -188,11 +189,22 @@ static void ensureLUT3DAllocated(OCIO_GLSLDrawState *state) glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); + + /* clean glError buffer */ + while (glGetError() != GL_NO_ERROR) {} + glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB16F_ARB, LUT3D_EDGE_SIZE, LUT3D_EDGE_SIZE, LUT3D_EDGE_SIZE, - 0, GL_RGB,GL_FLOAT, &state->lut3d); + 0, GL_RGB, GL_FLOAT, state->lut3d); state->lut3d_texture_allocated = true; + + /* GL_RGB16F_ARB could be not supported at some drivers + * in this case we could not use GLSL display + */ + state->lut3d_texture_valid = glGetError() == GL_NO_ERROR; + + return state->lut3d_texture_valid; } /** @@ -218,7 +230,12 @@ bool OCIOImpl::setupGLSLDraw(OCIO_GLSLDrawState **state_r, OCIO_ConstProcessorRc glGetIntegerv(GL_TEXTURE_2D, &state->last_texture); glGetIntegerv(GL_ACTIVE_TEXTURE, &state->last_texture_unit); - ensureLUT3DAllocated(state); + if (!ensureLUT3DAllocated(state)) { + glActiveTexture(state->last_texture_unit); + glBindTexture(GL_TEXTURE_2D, state->last_texture); + + return false; + } /* Step 1: Create a GPU Shader Description */ GpuShaderDesc shaderDesc; |