Cycles: Prepare for more image extension types support
authorSergey Sharybin <sergey.vfx@gmail.com>
Tue, 28 Jul 2015 11:51:10 +0000 (13:51 +0200)
committerSergey Sharybin <sergey.vfx@gmail.com>
Tue, 28 Jul 2015 12:14:24 +0000 (14:14 +0200)
Basically just replace boolean periodic flag with extension type enum in the
device API.

intern/cycles/device/device.h
intern/cycles/device/device_cpu.cpp
intern/cycles/device/device_cuda.cpp
intern/cycles/device/device_multi.cpp
intern/cycles/device/device_network.cpp
intern/cycles/device/device_opencl.cpp
intern/cycles/kernel/kernel.h
intern/cycles/kernel/kernel_compat_cpu.h
intern/cycles/kernel/kernels/cpu/kernel.cpp
intern/cycles/render/image.cpp

index ea1e20d1500be329f39a391823ea7aafe1c5f67e..3c0fb8809481bc2eef0c9851f3c4b67f0871d898 100644 (file)
@@ -173,10 +173,10 @@ public:
        virtual void tex_alloc(const char * /*name*/,
                               device_memory& /*mem*/,
                               InterpolationType interpolation = INTERPOLATION_NONE,
-                              bool periodic = false)
+                              ExtensionType extension = EXTENSION_REPEAT)
        {
                (void)interpolation;  /* Ignored. */
-               (void)periodic;  /* Ignored. */
+               (void)extension;  /* Ignored. */
        };
        virtual void tex_free(device_memory& /*mem*/) {};
 
index ec82b3805c4e75fca0b8a00469ec0f4ea7b1b3ea..f06963c146ea401eec38102bd60fe7f6bfbecc46 100644 (file)
@@ -126,7 +126,7 @@ public:
        void tex_alloc(const char *name,
                       device_memory& mem,
                       InterpolationType interpolation,
-                      bool periodic)
+                      ExtensionType extension)
        {
                VLOG(1) << "Texture allocate: " << name << ", " << mem.memory_size() << " bytes.";
                kernel_tex_copy(&kernel_globals,
@@ -136,7 +136,7 @@ public:
                                mem.data_height,
                                mem.data_depth,
                                interpolation,
-                               periodic);
+                               extension);
                mem.device_pointer = mem.data_pointer;
                mem.device_size = mem.memory_size();
                stats.mem_alloc(mem.device_size);
index 4a9c27f54299b5e89fa446634e30b835ce7b87c6..9703b786289f8c5b1da55475c551089f85f5b618 100644 (file)
@@ -416,7 +416,10 @@ public:
                cuda_pop_context();
        }
 
-       void tex_alloc(const char *name, device_memory& mem, InterpolationType interpolation, bool periodic)
+       void tex_alloc(const char *name,
+                      device_memory& mem,
+                      InterpolationType interpolation,
+                      ExtensionType extension)
        {
                /* todo: support 3D textures, only CPU for now */
                VLOG(1) << "Texture allocate: " << name << ", " << mem.memory_size() << " bytes.";
@@ -510,7 +513,7 @@ public:
                                cuda_assert(cuTexRefSetFlags(texref, CU_TRSF_READ_AS_INTEGER));
                        }
 
-                       if(periodic) {
+                       if(extension == EXTENSION_REPEAT) {
                                cuda_assert(cuTexRefSetAddressMode(texref, 0, CU_TR_ADDRESS_MODE_WRAP));
                                cuda_assert(cuTexRefSetAddressMode(texref, 1, CU_TR_ADDRESS_MODE_WRAP));
                        }
index c61e550151f75f9838cc17b1fb293a92c7eadae1..8fb841b2b0d43ffdeb816b09e324b8ccf50176c2 100644 (file)
@@ -169,13 +169,17 @@ public:
                        sub.device->const_copy_to(name, host, size);
        }
 
-       void tex_alloc(const char *name, device_memory& mem, InterpolationType interpolation, bool periodic)
+       void tex_alloc(const char *name,
+                      device_memory& mem,
+                      InterpolationType
+                      interpolation,
+                      ExtensionType extension)
        {
                VLOG(1) << "Texture allocate: " << name << ", " << mem.memory_size() << " bytes.";
 
                foreach(SubDevice& sub, devices) {
                        mem.device_pointer = 0;
-                       sub.device->tex_alloc(name, mem, interpolation, periodic);
+                       sub.device->tex_alloc(name, mem, interpolation, extension);
                        sub.ptr_map[unique_ptr] = mem.device_pointer;
                }
 
index 1d6066c94dc091169483f5a3682a6dc93c02f992..d1f941ad9f26e5a28a8b1488183deb7f136a9a8d 100644 (file)
@@ -163,7 +163,10 @@ public:
                snd.write_buffer(host, size);
        }
 
-       void tex_alloc(const char *name, device_memory& mem, InterpolationType interpolation, bool periodic)
+       void tex_alloc(const char *name,
+                      device_memory& mem,
+                      InterpolationType interpolation,
+                      ExtensionType extension)
        {
                VLOG(1) << "Texture allocate: " << name << ", " << mem.memory_size() << " bytes.";
 
@@ -178,7 +181,7 @@ public:
                snd.add(name_string);
                snd.add(mem);
                snd.add(interpolation);
-               snd.add(periodic);
+               snd.add(extension);
                snd.write();
                snd.write_buffer((void*)mem.data_pointer, mem.memory_size());
        }
@@ -571,13 +574,13 @@ protected:
                        network_device_memory mem;
                        string name;
                        InterpolationType interpolation;
-                       bool periodic;
+                       ExtensionType extension_typr;
                        device_ptr client_pointer;
 
                        rcv.read(name);
                        rcv.read(mem);
                        rcv.read(interpolation);
-                       rcv.read(periodic);
+                       rcv.read(extension);
                        lock.unlock();
 
                        client_pointer = mem.device_pointer;
@@ -593,7 +596,7 @@ protected:
 
                        rcv.read_buffer((uint8_t*)mem.data_pointer, data_size);
 
-                       device->tex_alloc(name.c_str(), mem, interpolation, periodic);
+                       device->tex_alloc(name.c_str(), mem, interpolation, extension);
 
                        pointer_mapping_insert(client_pointer, mem.device_pointer);
                }
index 0cc49e846cc7b5f7b589b3b3b6bae5cc804ddd56..fee9a8a803d2ed8cf5e8f37d6c83290454c6b0b6 100644 (file)
@@ -1179,7 +1179,7 @@ public:
        void tex_alloc(const char *name,
                       device_memory& mem,
                       InterpolationType /*interpolation*/,
-                      bool /*periodic*/)
+                      ExtensionType /*extension*/)
        {
                VLOG(1) << "Texture allocate: " << name << ", " << mem.memory_size() << " bytes.";
                mem_alloc(mem, MEM_READ_ONLY);
index 5c34ddcfbcbe0cc5ca149fe02cc2300e6045838e..b2596d10ee75fb3bca0de3391e8d47e0e96fe190 100644 (file)
@@ -39,7 +39,7 @@ void kernel_tex_copy(KernelGlobals *kg,
                      size_t height,
                      size_t depth,
                      InterpolationType interpolation=INTERPOLATION_LINEAR,
-                     bool periodic = true);
+                     ExtensionType extension = EXTENSION_REPEAT);
 
 void kernel_cpu_path_trace(KernelGlobals *kg, float *buffer, unsigned int *rng_state,
        int sample, int x, int y, int offset, int stride);
index a780c356a187cd03b0d84fb3992ed4b3d9d08d99..be8e54b3d3de9ec17459e597e56ce34d183134b4 100644 (file)
@@ -138,7 +138,7 @@ template<typename T> struct texture_image  {
                if(interpolation == INTERPOLATION_CLOSEST) {
                        frac(x*(float)width, &ix);
                        frac(y*(float)height, &iy);
-                       if(periodic) {
+                       if(extension == EXTENSION_REPEAT) {
                                ix = wrap_periodic(ix, width);
                                iy = wrap_periodic(iy, height);
 
@@ -153,7 +153,7 @@ template<typename T> struct texture_image  {
                        float tx = frac(x*(float)width - 0.5f, &ix);
                        float ty = frac(y*(float)height - 0.5f, &iy);
 
-                       if(periodic) {
+                       if(extension == EXTENSION_REPEAT) {
                                ix = wrap_periodic(ix, width);
                                iy = wrap_periodic(iy, height);
 
@@ -180,7 +180,7 @@ template<typename T> struct texture_image  {
                        const float tx = frac(x*(float)width - 0.5f, &ix);
                        const float ty = frac(y*(float)height - 0.5f, &iy);
                        int pix, piy, nnix, nniy;
-                       if(periodic) {
+                       if(extension == EXTENSION_REPEAT) {
                                ix = wrap_periodic(ix, width);
                                iy = wrap_periodic(iy, height);
 
@@ -251,7 +251,7 @@ template<typename T> struct texture_image  {
                        frac(y*(float)height, &iy);
                        frac(z*(float)depth, &iz);
 
-                       if(periodic) {
+                       if(extension == EXTENSION_REPEAT) {
                                ix = wrap_periodic(ix, width);
                                iy = wrap_periodic(iy, height);
                                iz = wrap_periodic(iz, depth);
@@ -269,7 +269,7 @@ template<typename T> struct texture_image  {
                        float ty = frac(y*(float)height - 0.5f, &iy);
                        float tz = frac(z*(float)depth - 0.5f, &iz);
 
-                       if(periodic) {
+                       if(extension == EXTENSION_REPEAT) {
                                ix = wrap_periodic(ix, width);
                                iy = wrap_periodic(iy, height);
                                iz = wrap_periodic(iz, depth);
@@ -309,7 +309,7 @@ template<typename T> struct texture_image  {
                        const float tz = frac(z*(float)depth - 0.5f, &iz);
                        int pix, piy, piz, nnix, nniy, nniz;
 
-                       if(periodic) {
+                       if(extension == EXTENSION_REPEAT) {
                                ix = wrap_periodic(ix, width);
                                iy = wrap_periodic(iy, height);
                                iz = wrap_periodic(iz, depth);
@@ -392,7 +392,7 @@ template<typename T> struct texture_image  {
 
        T *data;
        int interpolation;
-       bool periodic;
+       ExtensionType extension;
        int width, height, depth;
 #undef SET_CUBIC_SPLINE_WEIGHTS
 };
index 2dbd9e62ee7bf6cf5f80d46f847f2d998e21c03f..2c8d3503c1a8bb68eb31ec2607082ff431ce6848 100644 (file)
@@ -45,7 +45,7 @@ void kernel_tex_copy(KernelGlobals *kg,
                      size_t height,
                      size_t depth,
                      InterpolationType interpolation,
-                     bool periodic)
+                     ExtensionType extension)
 {
        if(0) {
        }
@@ -71,7 +71,7 @@ void kernel_tex_copy(KernelGlobals *kg,
                        tex->data = (float4*)mem;
                        tex->dimensions_set(width, height, depth);
                        tex->interpolation = interpolation;
-                       tex->periodic = periodic;
+                       tex->extension = extension;
                }
        }
        else if(strstr(name, "__tex_image")) {
@@ -87,7 +87,7 @@ void kernel_tex_copy(KernelGlobals *kg,
                        tex->data = (uchar4*)mem;
                        tex->dimensions_set(width, height, depth);
                        tex->interpolation = interpolation;
-                       tex->periodic = periodic;
+                       tex->extension = extension;
                }
        }
        else
index dc9aeeefc6d891e58f857fff0f9028c20f6e34ef..7bceb8a8bfa0eec2a593049b552f8843de3ccd51 100644 (file)
@@ -714,7 +714,7 @@ void ImageManager::device_load_image(Device *device, DeviceScene *dscene, int sl
                        device->tex_alloc(name.c_str(),
                                          tex_img,
                                          img->interpolation,
-                                         img->extension == EXTENSION_REPEAT);
+                                         img->extension);
                }
        }
        else {
@@ -749,7 +749,7 @@ void ImageManager::device_load_image(Device *device, DeviceScene *dscene, int sl
                        device->tex_alloc(name.c_str(),
                                          tex_img,
                                          img->interpolation,
-                                         img->extension == EXTENSION_REPEAT);
+                                         img->extension);
                }
        }