Code refactor: pass device to scene, check OSL with device info.
authorBrecht Van Lommel <brechtvanlommel@gmail.com>
Fri, 20 Oct 2017 03:08:26 +0000 (05:08 +0200)
committerBrecht Van Lommel <brechtvanlommel@gmail.com>
Mon, 23 Oct 2017 23:03:59 +0000 (01:03 +0200)
intern/cycles/app/cycles_standalone.cpp
intern/cycles/blender/blender_session.cpp
intern/cycles/device/device.cpp
intern/cycles/device/device.h
intern/cycles/device/device_cpu.cpp
intern/cycles/device/device_network.cpp
intern/cycles/render/scene.cpp
intern/cycles/render/scene.h

index 0cd249f0d84c2f1e1ab7310282de55c7e310b939..939c6cf7eb515b382959e600e120236e406cffec 100644 (file)
@@ -97,27 +97,9 @@ static BufferParams& session_buffer_params()
        return buffer_params;
 }
 
-static void session_init()
-{
-       options.session = new Session(options.session_params);
-       options.session->reset(session_buffer_params(), options.session_params.samples);
-       options.session->scene = options.scene;
-
-       if(options.session_params.background && !options.quiet)
-               options.session->progress.set_update_callback(function_bind(&session_print_status));
-#ifdef WITH_CYCLES_STANDALONE_GUI
-       else
-               options.session->progress.set_update_callback(function_bind(&view_redraw));
-#endif
-
-       options.session->start();
-
-       options.scene = NULL;
-}
-
 static void scene_init()
 {
-       options.scene = new Scene(options.scene_params, options.session_params.device);
+       options.scene = new Scene(options.scene_params, options.session->device);
 
        /* Read XML */
        xml_read_file(options.scene, options.filepath.c_str());
@@ -136,6 +118,25 @@ static void scene_init()
        options.scene->camera->compute_auto_viewplane();
 }
 
+static void session_init()
+{
+       options.session = new Session(options.session_params);
+       options.session->reset(session_buffer_params(), options.session_params.samples);
+
+       if(options.session_params.background && !options.quiet)
+               options.session->progress.set_update_callback(function_bind(&session_print_status));
+#ifdef WITH_CYCLES_STANDALONE_GUI
+       else
+               options.session->progress.set_update_callback(function_bind(&view_redraw));
+#endif
+
+       options.session->start();
+
+       /* load scene */
+       scene_init();
+       options.session->scene = options.scene;
+}
+
 static void session_exit()
 {
        if(options.session) {
@@ -430,7 +431,6 @@ static void options_parse(int argc, const char **argv)
        /* find matching device */
        DeviceType device_type = Device::type_from_string(devicename.c_str());
        vector<DeviceInfo>& devices = Device::available_devices();
-       DeviceInfo device_info;
        bool device_available = false;
 
        foreach(DeviceInfo& device, devices) {
@@ -467,9 +467,6 @@ static void options_parse(int argc, const char **argv)
 
        /* For smoother Viewport */
        options.session_params.start_resolution = 64;
-
-       /* load scene */
-       scene_init();
 }
 
 CCL_NAMESPACE_END
index f1226388a628f91be2261f8ebc7effda3c43396d..5b71e11d61d37a220c80141f6b34e3575a3e632c 100644 (file)
@@ -124,20 +124,22 @@ void BlenderSession::create_session()
        last_progress = -1.0f;
        start_resize_time = 0.0;
 
+       /* create session */
+       session = new Session(session_params);
+       session->scene = scene;
+       session->progress.set_update_callback(function_bind(&BlenderSession::tag_redraw, this));
+       session->progress.set_cancel_callback(function_bind(&BlenderSession::test_cancel, this));
+       session->set_pause(session_pause);
+
        /* create scene */
-       scene = new Scene(scene_params, session_params.device);
+       scene = new Scene(scene_params, session->device);
 
        /* setup callbacks for builtin image support */
        scene->image_manager->builtin_image_info_cb = function_bind(&BlenderSession::builtin_image_info, this, _1, _2, _3, _4, _5, _6, _7, _8);
        scene->image_manager->builtin_image_pixels_cb = function_bind(&BlenderSession::builtin_image_pixels, this, _1, _2, _3, _4, _5);
        scene->image_manager->builtin_image_float_pixels_cb = function_bind(&BlenderSession::builtin_image_float_pixels, this, _1, _2, _3, _4, _5);
 
-       /* create session */
-       session = new Session(session_params);
        session->scene = scene;
-       session->progress.set_update_callback(function_bind(&BlenderSession::tag_redraw, this));
-       session->progress.set_cancel_callback(function_bind(&BlenderSession::test_cancel, this));
-       session->set_pause(session_pause);
 
        /* create sync */
        sync = new BlenderSync(b_engine, b_data, b_scene, scene, !background, session->progress);
index f31cacd8ec1bd794e2f215526fb60b611272dd7f..16c027e2cb56ffe6f54e7d5407c9cfca67bbdaeb 100644 (file)
@@ -380,10 +380,13 @@ DeviceInfo Device::get_multi_device(const vector<DeviceInfo>& subdevices, int th
        info.has_bindless_textures = true;
        info.has_volume_decoupled = true;
        info.has_qbvh = true;
+       info.has_osl = true;
+
        foreach(const DeviceInfo &device, subdevices) {
                info.has_bindless_textures &= device.has_bindless_textures;
                info.has_volume_decoupled &= device.has_volume_decoupled;
                info.has_qbvh &= device.has_qbvh;
+               info.has_osl &= device.has_osl;
 
                if(device.type == DEVICE_CPU && subdevices.size() > 1) {
                        if(background) {
index f400eeb3e6b6ec2d5ca5d2b5fdb8899507a9304e..4bf88f75932e13122ccebbb205fe599faf9386da 100644 (file)
@@ -57,6 +57,7 @@ public:
        bool has_bindless_textures; /* flag for GPU and Multi device */
        bool has_volume_decoupled;
        bool has_qbvh;
+       bool has_osl;
        bool use_split_kernel; /* Denotes if the device is going to run cycles using split-kernel */
        int cpu_threads;
        vector<DeviceInfo> multi_devices;
@@ -72,6 +73,7 @@ public:
                has_bindless_textures = false;
                has_volume_decoupled = false;
                has_qbvh = false;
+               has_osl = false;
                use_split_kernel = false;
        }
 
index 0ba00da16a63f2982646c28c9da7650f3885f053..b05f24659ee615e647a0d7e50ad749bbdabb3c6a 100644 (file)
@@ -1028,6 +1028,7 @@ void device_cpu_info(vector<DeviceInfo>& devices)
        info.advanced_shading = true;
        info.has_qbvh = system_cpu_support_sse2();
        info.has_volume_decoupled = true;
+       info.has_osl = true;
 
        devices.insert(devices.begin(), info);
 }
index ced10c98dc959d083761d58a622aa012d030bd29..3fea89a243caf5ced40819724f98724fd3b1f7d6 100644 (file)
@@ -348,6 +348,7 @@ void device_network_info(vector<DeviceInfo>& devices)
        info.advanced_shading = true;
        info.has_volume_decoupled = false;
        info.has_qbvh = false;
+       info.has_osl = false;
 
        devices.push_back(info);
 }
index cf89385a33d2a7d28bf4fc44e77ceb8fd517826c..00c32312d9f8244652e1916982fd74a5807add3d 100644 (file)
 
 CCL_NAMESPACE_BEGIN
 
-Scene::Scene(const SceneParams& params_, const DeviceInfo& device_info_)
-: params(params_)
+Scene::Scene(const SceneParams& params_, Device *device)
+: device(device), params(params_)
 {
-       device = NULL;
        memset(&dscene.data, 0, sizeof(dscene.data));
 
        camera = new Camera();
@@ -54,13 +53,13 @@ Scene::Scene(const SceneParams& params_, const DeviceInfo& device_info_)
        mesh_manager = new MeshManager();
        object_manager = new ObjectManager();
        integrator = new Integrator();
-       image_manager = new ImageManager(device_info_);
+       image_manager = new ImageManager(device->info);
        particle_system_manager = new ParticleSystemManager();
        curve_system_manager = new CurveSystemManager();
        bake_manager = new BakeManager();
 
        /* OSL only works on the CPU */
-       if(device_info_.type == DEVICE_CPU)
+       if(device->info.has_osl)
                shader_manager = ShaderManager::create(this, params.shadingsystem);
        else
                shader_manager = ShaderManager::create(this, SHADINGSYSTEM_SVM);
index d4ec7d90ff503bdaa51031f59bce15dc915e1470..23b9eb06a7bd382e137607eb5154afb313e5ad92 100644 (file)
@@ -201,7 +201,7 @@ public:
        /* mutex must be locked manually by callers */
        thread_mutex mutex;
 
-       Scene(const SceneParams& params, const DeviceInfo& device_info);
+       Scene(const SceneParams& params, Device *device);
        ~Scene();
 
        void device_update(Device *device, Progress& progress);