Revision: 37053
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37053
Author:   blendix
Date:     2011-05-31 16:21:30 +0000 (Tue, 31 May 2011)
Log Message:
-----------
Cycles: OSL build & image manager fixes.

Modified Paths:
--------------
    branches/cycles/intern/cycles/CMakeLists.txt
    branches/cycles/intern/cycles/kernel/kernel_compat_opencl.h
    branches/cycles/intern/cycles/kernel/kernel_globals.h
    branches/cycles/intern/cycles/kernel/osl/osl_services.cpp
    branches/cycles/intern/cycles/render/image.cpp
    branches/cycles/intern/cycles/render/image.h
    branches/cycles/intern/cycles/render/nodes.cpp
    branches/cycles/intern/cycles/render/osl.cpp
    branches/cycles/intern/cycles/util/util_types.h

Modified: branches/cycles/intern/cycles/CMakeLists.txt
===================================================================
--- branches/cycles/intern/cycles/CMakeLists.txt        2011-05-31 16:19:02 UTC 
(rev 37052)
+++ branches/cycles/intern/cycles/CMakeLists.txt        2011-05-31 16:21:30 UTC 
(rev 37053)
@@ -28,7 +28,7 @@
 SET(CYCLES_CUDA "/usr/local/cuda" CACHE PATH "Path to CUDA installation")
 SET(CYCLES_OPENCL "" CACHE PATH "Path to OpenCL installation")
 SET(CYCLES_PARTIO "" CACHE PATH "Path to Partio installation")
-SET(CYCLES_GLEW "" CACHE PATH "Path to GLUT installation")
+SET(CYCLES_GLEW "" CACHE PATH "Path to GLEW installation")
 
 # Install, todo: deduplicate install path code
 

Modified: branches/cycles/intern/cycles/kernel/kernel_compat_opencl.h
===================================================================
--- branches/cycles/intern/cycles/kernel/kernel_compat_opencl.h 2011-05-31 
16:19:02 UTC (rev 37052)
+++ branches/cycles/intern/cycles/kernel/kernel_compat_opencl.h 2011-05-31 
16:21:30 UTC (rev 37053)
@@ -42,6 +42,25 @@
        return (1.0f - t)*data[index] + t*data[nindex];
 }
 
+#ifdef make_float2
+#undef make_float2
+#endif
+#ifdef make_float3
+#undef make_float3
+#endif
+#ifdef make_float4
+#undef make_float4
+#endif
+#ifdef make_int2
+#undef make_int2
+#endif
+#ifdef make_int3
+#undef make_int3
+#endif
+#ifdef make_int4
+#undef make_int4
+#endif
+
 #define make_float2(x, y) ((float2)(x, y))
 #define make_float3(x, y, z) ((float3)(x, y, z, 0.0f))
 #define make_float4(x, y, z, w) ((float4)(x, y, z, w))
@@ -49,6 +68,13 @@
 #define make_int3(x, y, z) ((int3)(x, y, z, 0))
 #define make_int4(x, y, z, w) ((int4)(x, y, z, w))
 
+#ifdef float3
+#undef float3
+#endif
+#ifdef int3
+#undef int3
+#endif
+
 typedef float4 float3;
 typedef int4 int3;
 

Modified: branches/cycles/intern/cycles/kernel/kernel_globals.h
===================================================================
--- branches/cycles/intern/cycles/kernel/kernel_globals.h       2011-05-31 
16:19:02 UTC (rev 37052)
+++ branches/cycles/intern/cycles/kernel/kernel_globals.h       2011-05-31 
16:21:30 UTC (rev 37053)
@@ -18,6 +18,14 @@
 
 /* Constant Globals */
 
+#ifdef __KERNEL_CPU__
+
+#ifdef WITH_OSL
+#include "osl_globals.h"
+#endif
+
+#endif
+
 CCL_NAMESPACE_BEGIN
 
 /* On the CPU, we pass along the struct KernelGlobals to nearly everywhere in
@@ -27,10 +35,6 @@
 
 #ifdef __KERNEL_CPU__
 
-#ifdef WITH_OSL
-//#include "osl_globals.h"
-#endif
-
 typedef struct KernelGlobals {
 
 #define KERNEL_TEX(type, ttype, name) ttype name;
@@ -42,7 +46,7 @@
 #ifdef WITH_OSL
        /* On the CPU, we also have the OSL globals here. Most data structures 
are shared
           with SVM, the difference is in the shaders and object/mesh 
attributes. */
-       //OSLGlobals osl;
+       OSLGlobals osl;
 #endif
 
 } KernelGLobals;

Modified: branches/cycles/intern/cycles/kernel/osl/osl_services.cpp
===================================================================
--- branches/cycles/intern/cycles/kernel/osl/osl_services.cpp   2011-05-31 
16:19:02 UTC (rev 37052)
+++ branches/cycles/intern/cycles/kernel/osl/osl_services.cpp   2011-05-31 
16:21:30 UTC (rev 37053)
@@ -176,6 +176,7 @@
                        (derivatives)? &fval[1]: NULL, (derivatives)? &fval[2]: 
NULL);
        }
        else {
+               /* todo: this won't work when float3 has w component */
                float3 *fval = (float3*)val;
                fval[0] = triangle_attribute_float3(kg, sd, attr.elem, 
attr.offset,
                        (derivatives)? &fval[1]: NULL, (derivatives)? &fval[2]: 
NULL);

Modified: branches/cycles/intern/cycles/render/image.cpp
===================================================================
--- branches/cycles/intern/cycles/render/image.cpp      2011-05-31 16:19:02 UTC 
(rev 37052)
+++ branches/cycles/intern/cycles/render/image.cpp      2011-05-31 16:21:30 UTC 
(rev 37053)
@@ -25,11 +25,16 @@
 #include "util_path.h"
 #include "util_progress.h"
 
+#ifdef WITH_OSL
+#include <OSL/oslexec.h>
+#endif
+
 CCL_NAMESPACE_BEGIN
 
 ImageManager::ImageManager()
 {
        need_update = true;
+       osl_texture_system = NULL;
 }
 
 ImageManager::~ImageManager()
@@ -39,6 +44,11 @@
        }
 }
 
+void ImageManager::set_osl_texture_system(void *texture_system)
+{
+       osl_texture_system = texture_system;
+}
+
 int ImageManager::add_image(const string& filename)
 {
        Image *img;
@@ -77,8 +87,17 @@
        return slot;
 }
 
-void ImageManager::remove_image(int slot)
+void ImageManager::remove_image(const string& filename)
 {
+       size_t slot;
+
+       for(slot = 0; slot < images.size(); slot++)
+               if(images[slot] && images[slot]->filename == filename)
+                       break;
+       
+       if(slot == images.size())
+               return;
+
        assert(images[slot]);
 
        /* decrement user count */
@@ -90,8 +109,6 @@
           that use them, but we do not want to reload the image all the time. 
*/
        if(images[slot]->users == 0)
                need_update = true;
-       
-       /* todo: remove OSL image from cache */
 }
 
 bool ImageManager::file_load_image(Image *img, device_vector<uchar4>& tex_img)
@@ -156,10 +173,12 @@
 
 void ImageManager::device_load_image(Device *device, DeviceScene *dscene, int 
slot)
 {
+       if(osl_texture_system)
+               return;
+
        Image *img = images[slot];
        device_vector<uchar4>& tex_img = dscene->tex_image[slot];
 
-       img->need_load = false;
        if(tex_img.device_pointer)
                device->tex_free(tex_img);
 
@@ -184,8 +203,16 @@
 void ImageManager::device_free_image(Device *device, DeviceScene *dscene, int 
slot)
 {
        if(images[slot]) {
-               device->tex_free(dscene->tex_image[slot]);
-               dscene->tex_image[slot].clear();
+               if(osl_texture_system) {
+#ifdef WITH_OSL
+                       ustring filename(images[slot]->filename);
+                       
((OSL::TextureSystem*)osl_texture_system)->invalidate(filename);
+#endif
+               }
+               else {
+                       device->tex_free(dscene->tex_image[slot]);
+                       dscene->tex_image[slot].clear();
+               }
 
                delete images[slot];
                images[slot] = NULL;
@@ -206,6 +233,7 @@
                                string name = 
path_filename(images[slot]->filename);
                                progress.set_status("Updating Images", "Loading 
" + name);
                                device_load_image(device, dscene, slot);
+                               images[slot]->need_load = false;
                        }
 
                        if(progress.get_cancel()) return;

Modified: branches/cycles/intern/cycles/render/image.h
===================================================================
--- branches/cycles/intern/cycles/render/image.h        2011-05-31 16:19:02 UTC 
(rev 37052)
+++ branches/cycles/intern/cycles/render/image.h        2011-05-31 16:21:30 UTC 
(rev 37053)
@@ -38,11 +38,13 @@
        ~ImageManager();
 
        int add_image(const string& filename);
-       void remove_image(int slot);
+       void remove_image(const string& filename);
 
        void device_update(Device *device, DeviceScene *dscene, Progress& 
progress);
        void device_free(Device *device, DeviceScene *dscene);
 
+       void set_osl_texture_system(void *texture_system);
+
        bool need_update;
 
 private:
@@ -54,6 +56,7 @@
        };
 
        vector<Image*> images;
+       void *osl_texture_system;
 
        bool file_load_image(Image *img, device_vector<uchar4>& tex_img);
 

Modified: branches/cycles/intern/cycles/render/nodes.cpp
===================================================================
--- branches/cycles/intern/cycles/render/nodes.cpp      2011-05-31 16:19:02 UTC 
(rev 37052)
+++ branches/cycles/intern/cycles/render/nodes.cpp      2011-05-31 16:21:30 UTC 
(rev 37053)
@@ -53,8 +53,8 @@
 
 ImageTextureNode::~ImageTextureNode()
 {
-       if(image_manager && slot != -1)
-               image_manager->remove_image(slot);
+       if(image_manager)
+               image_manager->remove_image(filename);
 }
 
 ShaderNode *ImageTextureNode::clone() const
@@ -117,8 +117,8 @@
 
 EnvironmentTextureNode::~EnvironmentTextureNode()
 {
-       if(image_manager && slot != -1)
-               image_manager->remove_image(slot);
+       if(image_manager)
+               image_manager->remove_image(filename);
 }
 
 ShaderNode *EnvironmentTextureNode::clone() const

Modified: branches/cycles/intern/cycles/render/osl.cpp
===================================================================
--- branches/cycles/intern/cycles/render/osl.cpp        2011-05-31 16:19:02 UTC 
(rev 37052)
+++ branches/cycles/intern/cycles/render/osl.cpp        2011-05-31 16:21:30 UTC 
(rev 37053)
@@ -44,9 +44,6 @@
 
 OSLShaderManager::OSLShaderManager()
 {
-       /* todo: verify if we are leaking shaders
-        * todo: verify if we are leaking image cache memory */
-
        services = new OSLRenderServices();
 
        /* if we let OSL create it, it leaks */
@@ -112,6 +109,9 @@
 
        foreach(Shader *shader, scene->shaders)
                shader->need_update = false;
+       
+       /* set texture system */
+       scene->image_manager->set_osl_texture_system((void*)ts);
 }
 
 void OSLShaderManager::device_free(Device *device, DeviceScene *dscene)

Modified: branches/cycles/intern/cycles/util/util_types.h
===================================================================
--- branches/cycles/intern/cycles/util/util_types.h     2011-05-31 16:19:02 UTC 
(rev 37052)
+++ branches/cycles/intern/cycles/util/util_types.h     2011-05-31 16:21:30 UTC 
(rev 37053)
@@ -172,6 +172,10 @@
 struct float3 {
        float x, y, z;
 
+#ifdef WITH_OPENCL
+       float w;
+#endif
+
        float operator[](int i) const { return *(&x + i); }
        float& operator[](int i) { return *(&x + i); }
 };
@@ -253,7 +257,11 @@
 
 __device float3 make_float3(float x, float y, float z)
 {
+#ifdef WITH_OPENCL
+       float3 a = {x, y, z, 0.0f};
+#else
        float3 a = {x, y, z};
+#endif
        return a;
 }
 

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to