Merge branch 'master' into blender2.8
authorLuca Rood <dev@lucarood.com>
Wed, 5 Jul 2017 13:50:01 +0000 (15:50 +0200)
committerLuca Rood <dev@lucarood.com>
Wed, 5 Jul 2017 13:50:01 +0000 (15:50 +0200)
intern/cycles/device/device_cpu.cpp
intern/cycles/device/device_cuda.cpp
intern/cycles/device/device_split_kernel.h
intern/cycles/device/opencl/opencl.h
intern/cycles/device/opencl/opencl_split.cpp
intern/cycles/device/opencl/opencl_util.cpp
intern/cycles/util/util_logging.h
source/blender/blenkernel/intern/particle.c
source/blender/blenkernel/intern/particle_distribute.c
source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.cpp
source/blender/makesrna/intern/rna_particle.c

index a0cdec0951b58183f9c2e12c9c9b315a218f6a2e..18112437b458f1deb6b5d742684531e47cb65f96 100644 (file)
@@ -149,7 +149,8 @@ public:
                                                    device_memory& use_queues_flag,
                                                    device_memory& work_pool_wgs);
 
-       virtual SplitKernelFunction* get_split_kernel_function(string kernel_name, const DeviceRequestedFeatures&);
+       virtual SplitKernelFunction* get_split_kernel_function(const string& kernel_name,
+                                                              const DeviceRequestedFeatures&);
        virtual int2 split_kernel_local_size();
        virtual int2 split_kernel_global_size(device_memory& kg, device_memory& data, DeviceTask *task);
        virtual uint64_t state_buffer_size(device_memory& kg, device_memory& data, size_t num_threads);
@@ -932,7 +933,8 @@ bool CPUSplitKernel::enqueue_split_kernel_data_init(const KernelDimensions& dim,
        return true;
 }
 
-SplitKernelFunction* CPUSplitKernel::get_split_kernel_function(string kernel_name, const DeviceRequestedFeatures&)
+SplitKernelFunction* CPUSplitKernel::get_split_kernel_function(const string& kernel_name,
+                                                               const DeviceRequestedFeatures&)
 {
        CPUSplitKernelFunction *kernel = new CPUSplitKernelFunction(device);
 
index 19e68007934483239e1f0657b47c90cd9df87dc3..e53aec0fbb97a61c1fd04a45bc0e1bce665b1906 100644 (file)
@@ -105,7 +105,8 @@ public:
                                                    device_memory& use_queues_flag,
                                                    device_memory& work_pool_wgs);
 
-       virtual SplitKernelFunction* get_split_kernel_function(string kernel_name, const DeviceRequestedFeatures&);
+       virtual SplitKernelFunction* get_split_kernel_function(const string& kernel_name,
+                                                              const DeviceRequestedFeatures&);
        virtual int2 split_kernel_local_size();
        virtual int2 split_kernel_global_size(device_memory& kg, device_memory& data, DeviceTask *task);
 };
@@ -2058,7 +2059,8 @@ bool CUDASplitKernel::enqueue_split_kernel_data_init(const KernelDimensions& dim
        return !device->have_error();
 }
 
-SplitKernelFunction* CUDASplitKernel::get_split_kernel_function(string kernel_name, const DeviceRequestedFeatures&)
+SplitKernelFunction* CUDASplitKernel::get_split_kernel_function(const string& kernel_name,
+                                                                const DeviceRequestedFeatures&)
 {
        CUfunction func;
 
index 2bac1998cb7ced6d4223df401a85256a52160f04..9c42cb5852025effc03059f029bd25531d475f53 100644 (file)
@@ -125,7 +125,8 @@ public:
                                                    device_memory& use_queues_flag,
                                                    device_memory& work_pool_wgs) = 0;
 
-       virtual SplitKernelFunction* get_split_kernel_function(string kernel_name, const DeviceRequestedFeatures&) = 0;
+       virtual SplitKernelFunction* get_split_kernel_function(const string& kernel_name,
+                                                              const DeviceRequestedFeatures&) = 0;
        virtual int2 split_kernel_local_size() = 0;
        virtual int2 split_kernel_global_size(device_memory& kg, device_memory& data, DeviceTask *task) = 0;
 };
index 399fae9b42e75ec5451c3b6ad254d530fcf9dc04..7da690904aa30a717967ba3aa3cf66308d0dd349 100644 (file)
@@ -84,7 +84,7 @@ public:
                                           string *error = NULL);
        static bool device_version_check(cl_device_id device,
                                         string *error = NULL);
-       static string get_hardware_id(string platform_name,
+       static string get_hardware_id(const string& platform_name,
                                      cl_device_id device_id);
        static void get_usable_devices(vector<OpenCLPlatformDevice> *usable_devices,
                                       bool force_all = false);
@@ -247,17 +247,17 @@ public:
        public:
                OpenCLProgram() : loaded(false), device(NULL) {}
                OpenCLProgram(OpenCLDeviceBase *device,
-                             string program_name,
-                             string kernel_name,
-                             string kernel_build_options,
+                             const string& program_name,
+                             const string& kernel_name,
+                             const string& kernel_build_options,
                              bool use_stdout = true);
                ~OpenCLProgram();
 
                void add_kernel(ustring name);
                void load();
 
-               bool is_loaded()    { return loaded; }
-               string get_log()    { return log; }
+               bool is_loaded() const { return loaded; }
+               const string& get_log() const { return log; }
                void report_error();
 
                cl_kernel operator()();
@@ -271,8 +271,8 @@ public:
                bool load_binary(const string& clbin, const string *debug_src = NULL);
                bool save_binary(const string& clbin);
 
-               void add_log(string msg, bool is_debug);
-               void add_error(string msg);
+               void add_log(const string& msg, bool is_debug);
+               void add_error(const string& msg);
 
                bool loaded;
                cl_program program;
index 08b632ee9d3670669801b818dabd22424f7a7e44..73b8769d3ccb70b7b01249b825051adcd3fd1d96 100644 (file)
@@ -263,7 +263,7 @@ public:
        explicit OpenCLSplitKernel(OpenCLDeviceSplitKernel *device) : DeviceSplitKernel(device), device(device) {
        }
 
-       virtual SplitKernelFunction* get_split_kernel_function(string kernel_name,
+       virtual SplitKernelFunction* get_split_kernel_function(const string& kernel_name,
                                                               const DeviceRequestedFeatures& requested_features)
        {
                OpenCLSplitKernelFunction* kernel = new OpenCLSplitKernelFunction(device, cached_memory);
index 8ba2a8e26da18873f3f8f5da508cee0b73e74a4b..0d34af3e04002f115414f2dc39bd239a0b77e123 100644 (file)
@@ -241,9 +241,9 @@ string OpenCLCache::get_kernel_md5()
 }
 
 OpenCLDeviceBase::OpenCLProgram::OpenCLProgram(OpenCLDeviceBase *device,
-                                               string program_name,
-                                               string kernel_file,
-                                               string kernel_build_options,
+                                               const string& program_name,
+                                               const string& kernel_file,
+                                               const string& kernel_build_options,
                                                bool use_stdout)
  : device(device),
    program_name(program_name),
@@ -274,7 +274,7 @@ void OpenCLDeviceBase::OpenCLProgram::release()
        }
 }
 
-void OpenCLDeviceBase::OpenCLProgram::add_log(string msg, bool debug)
+void OpenCLDeviceBase::OpenCLProgram::add_log(const string& msg, bool debug)
 {
        if(!use_stdout) {
                log += msg + "\n";
@@ -288,7 +288,7 @@ void OpenCLDeviceBase::OpenCLProgram::add_log(string msg, bool debug)
        }
 }
 
-void OpenCLDeviceBase::OpenCLProgram::add_error(string msg)
+void OpenCLDeviceBase::OpenCLProgram::add_error(const string& msg)
 {
        if(use_stdout) {
                fprintf(stderr, "%s\n", msg.c_str());
@@ -707,7 +707,7 @@ bool OpenCLInfo::device_version_check(cl_device_id device,
        return true;
 }
 
-string OpenCLInfo::get_hardware_id(string platform_name, cl_device_id device_id)
+string OpenCLInfo::get_hardware_id(const string& platform_name, cl_device_id device_id)
 {
        if(platform_name == "AMD Accelerated Parallel Processing" || platform_name == "Apple") {
                /* Use cl_amd_device_topology extension. */
index ecf9c9cfee09ef17fa1b614a03347190914c4a32..6380cb13a9ba66df8470d3ae2d175cf3541690cb 100644 (file)
 
 #if defined(WITH_CYCLES_LOGGING) && !defined(__KERNEL_GPU__)
 #  include <glog/logging.h>
-#else
-#  include <iostream>
 #endif
 
 CCL_NAMESPACE_BEGIN
 
 #if !defined(WITH_CYCLES_LOGGING) || defined(__KERNEL_GPU__)
-class StubStream : public std::ostream {
- public:
-       StubStream() : std::ostream(NULL) { }
+class StubStream {
+public:
+       template<class T>
+       StubStream& operator<<(const T&) {
+               return *this;
+       }
 };
 
 class LogMessageVoidify {
 public:
        LogMessageVoidify() { }
-       void operator&(::std::ostream&) { }
+       void operator&(StubStream&) { }
 };
 
 #  define LOG_SUPPRESS() (true) ? (void) 0 : LogMessageVoidify() & StubStream()
 #  define LOG(severity) LOG_SUPPRESS()
 #  define VLOG(severity) LOG_SUPPRESS()
-
 #endif
 
 #define VLOG_ONCE(level, flag) if(!flag) flag = true, VLOG(level)
index dabade5649082c7a72f0a25364486db93a2983e4..f34a680b52da559626fd31f43488d584dc194ec6 100644 (file)
@@ -3379,7 +3379,8 @@ void BKE_particlesettings_make_local(Main *bmain, ParticleSettings *part, const
 /*                     Textures                                                        */
 /************************************************/
 
-static int get_particle_uv(DerivedMesh *dm, ParticleData *pa, int face_index, const float fuv[4], char *name, float *texco)
+static int get_particle_uv(DerivedMesh *dm, ParticleData *pa, int index, const float fuv[4],
+                           char *name, float *texco, bool from_vert)
 {
        MFace *mf;
        MTFace *tf;
@@ -3395,11 +3396,15 @@ static int get_particle_uv(DerivedMesh *dm, ParticleData *pa, int face_index, co
 
        if (pa) {
                i = ELEM(pa->num_dmcache, DMCACHE_NOTFOUND, DMCACHE_ISCHILD) ? pa->num : pa->num_dmcache;
-               if (i >= dm->getNumTessFaces(dm))
+               if ((!from_vert && i >= dm->getNumTessFaces(dm)) ||
+                   (from_vert && i >= dm->getNumVerts(dm)))
+               {
                        i = -1;
+               }
+       }
+       else {
+               i = index;
        }
-       else
-               i = face_index;
 
        if (i == -1) {
                texco[0] = 0.0f;
@@ -3407,7 +3412,19 @@ static int get_particle_uv(DerivedMesh *dm, ParticleData *pa, int face_index, co
                texco[2] = 0.0f;
        }
        else {
-               mf = dm->getTessFaceData(dm, i, CD_MFACE);
+               if (from_vert) {
+                       mf = dm->getTessFaceDataArray(dm, CD_MFACE);
+
+                       for (int j = 0; j < dm->getNumTessFaces(dm); j++, mf++) {
+                               if (ELEM(i, mf->v1, mf->v2, mf->v3, mf->v4)) {
+                                       i = j;
+                                       break;
+                               }
+                       }
+               }
+               else {
+                       mf = dm->getTessFaceData(dm, i, CD_MFACE);
+               }
 
                psys_interpolate_uvs(&tf[i], mf->v4, fuv, texco);
 
@@ -3474,8 +3491,11 @@ static void get_cpa_texture(DerivedMesh *dm, ParticleSystem *psys, ParticleSetti
                                                mul_m4_v3(mtex->object->imat, texvec);
                                        break;
                                case TEXCO_UV:
-                                       if (fw && get_particle_uv(dm, NULL, face_index, fw, mtex->uvname, texvec))
+                                       if (fw && get_particle_uv(dm, NULL, face_index, fw, mtex->uvname,
+                                                                 texvec, (part->from == PART_FROM_VERT)))
+                                       {
                                                break;
+                                       }
                                        /* no break, failed to get uv's, so let's try orco's */
                                        ATTR_FALLTHROUGH;
                                case TEXCO_ORCO:
@@ -3547,8 +3567,11 @@ void psys_get_texture(ParticleSimulationData *sim, ParticleData *pa, ParticleTex
                                                mul_m4_v3(mtex->object->imat, texvec);
                                        break;
                                case TEXCO_UV:
-                                       if (get_particle_uv(sim->psmd->dm_final, pa, 0, pa->fuv, mtex->uvname, texvec))
+                                       if (get_particle_uv(sim->psmd->dm_final, pa, 0, pa->fuv, mtex->uvname,
+                                                           texvec, (part->from == PART_FROM_VERT)))
+                                       {
                                                break;
+                                       }
                                        /* no break, failed to get uv's, so let's try orco's */
                                        ATTR_FALLTHROUGH;
                                case TEXCO_ORCO:
index 6603521c42f87fccb8e7d09337f9385150e298e5..09da5fe72456bfb6e845e0137434062cdeb93e54 100644 (file)
@@ -427,12 +427,34 @@ static int distribute_binary_search(float *sum, int n, float value)
 static void distribute_from_verts_exec(ParticleTask *thread, ParticleData *pa, int p)
 {
        ParticleThreadContext *ctx= thread->ctx;
-       int rng_skip_tot= PSYS_RND_DIST_SKIP; /* count how many rng_* calls wont need skipping */
+       MFace *mface;
+
+       DM_ensure_tessface(ctx->dm);
+       mface = ctx->dm->getTessFaceDataArray(ctx->dm, CD_MFACE);
+
+       int rng_skip_tot = PSYS_RND_DIST_SKIP; /* count how many rng_* calls wont need skipping */
 
        /* TODO_PARTICLE - use original index */
-       pa->num= ctx->index[p];
-       pa->fuv[0] = 1.0f;
-       pa->fuv[1] = pa->fuv[2] = pa->fuv[3] = 0.0;
+       pa->num = ctx->index[p];
+
+       zero_v4(pa->fuv);
+
+       if (pa->num != DMCACHE_NOTFOUND && pa->num < ctx->dm->getNumVerts(ctx->dm)) {
+               for (int i = 0; i < ctx->dm->getNumTessFaces(ctx->dm); i++, mface++) {
+                       if (ELEM(pa->num, mface->v1, mface->v2, mface->v3, mface->v4)) {
+                               unsigned int *vert = &mface->v1;
+
+                               for (int j = 0; j < 4; j++, vert++) {
+                                       if (*vert == pa->num) {
+                                               pa->fuv[j] = 1.0f;
+                                               break;
+                                       }
+                               }
+
+                               break;
+                       }
+               }
+       }
        
 #if ONLY_WORKING_WITH_PA_VERTS
        if (ctx->tree) {
index 1ec52571be8f8eb755a9b1b01811051bbe262f94..9ff0bf9ce123b3a9f698d70af346d61f8414fa15 100644 (file)
@@ -286,9 +286,9 @@ void InverseSearchRadiusOperation::initExecution()
        this->m_inputRadius = this->getInputSocketReader(0);
 }
 
-voi *InverseSearchRadiusOperation::initializeTileData(rcti *rect)
+void *InverseSearchRadiusOperation::initializeTileData(rcti *rect)
 {
-       MemoryBuffer * data = new MemoryBuffer(NULL, rect);
+       MemoryBuffer * data = new MemoryBuffer(COM_DT_COLOR, rect);
        float *buffer = data->getBuffer();
        int x, y;
        int width = this->m_inputRadius->getWidth();
@@ -343,7 +343,7 @@ voi *InverseSearchRadiusOperation::initializeTileData(rcti *rect)
 void InverseSearchRadiusOperation::executePixelChunk(float output[4], int x, int y, void *data)
 {
        MemoryBuffer *buffer = (MemoryBuffer *)data;
-       buffer->readNoCheck(color, x, y);
+       buffer->readNoCheck(output, x, y);
 }
 
 void InverseSearchRadiusOperation::deinitializeTileData(rcti *rect, void *data) 
index 29f33907d395b59d6af832acb536441fabf4c502..b40519386cc9e1745784ba89132aca446671ea52 100644 (file)
@@ -448,10 +448,12 @@ static int rna_ParticleSystem_tessfaceidx_on_emitter(ParticleSystem *particlesys
        int totpart;
        int totchild = 0;
        int totface;
+       int totvert;
        int num = -1;
 
        DM_ensure_tessface(modifier->dm_final); /* BMESH - UNTIL MODIFIER IS UPDATED FOR MPoly */
        totface = modifier->dm_final->getNumTessFaces(modifier->dm_final);
+       totvert = modifier->dm_final->getNumVerts(modifier->dm_final);
 
        /* 1. check that everything is ok & updated */
        if (!particlesystem || !totface) {
@@ -486,13 +488,26 @@ static int rna_ParticleSystem_tessfaceidx_on_emitter(ParticleSystem *particlesys
                                return num;
                        }
                }
+               else if (part->from == PART_FROM_VERT) {
+                       if (num != DMCACHE_NOTFOUND && num < totvert) {
+                               MFace *mface = modifier->dm_final->getTessFaceDataArray(modifier->dm_final, CD_MFACE);
+
+                               *r_fuv = &particle->fuv;
+
+                               for (int i = 0; i < totface; i++, mface++) {
+                                       if (ELEM(num, mface->v1, mface->v2, mface->v3, mface->v4)) {
+                                               return i;
+                                       }
+                               }
+                       }
+               }
        }
        else {
                ChildParticle *cpa = particlesystem->child + particle_no - totpart;
                num = cpa->num;
 
                if (part->childtype == PART_CHILD_FACES) {
-                       if (ELEM(part->from, PART_FROM_FACE, PART_FROM_VOLUME)) {
+                       if (ELEM(part->from, PART_FROM_FACE, PART_FROM_VOLUME, PART_FROM_VERT)) {
                                if (num != DMCACHE_NOTFOUND && num < totface) {
                                        *r_fuv = &cpa->fuv;
                                        return num;
@@ -512,6 +527,19 @@ static int rna_ParticleSystem_tessfaceidx_on_emitter(ParticleSystem *particlesys
                                        return num;
                                }
                        }
+                       else if (part->from == PART_FROM_VERT) {
+                               if (num != DMCACHE_NOTFOUND && num < totvert) {
+                                       MFace *mface = modifier->dm_final->getTessFaceDataArray(modifier->dm_final, CD_MFACE);
+
+                                       *r_fuv = &parent->fuv;
+
+                                       for (int i = 0; i < totface; i++, mface++) {
+                                               if (ELEM(num, mface->v1, mface->v2, mface->v3, mface->v4)) {
+                                                       return i;
+                                               }
+                                       }
+                               }
+                       }
                }
        }