From ae41f38f78f8c54f92cf34dd88e35948e19aed55 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Fri, 20 Oct 2017 05:08:26 +0200 Subject: [PATCH] Code refactor: pass device to scene, check OSL with device info. --- intern/cycles/app/cycles_standalone.cpp | 43 +++++++++++------------ intern/cycles/blender/blender_session.cpp | 18 +++++----- intern/cycles/device/device.cpp | 3 ++ intern/cycles/device/device.h | 2 ++ intern/cycles/device/device_cpu.cpp | 1 + intern/cycles/device/device_network.cpp | 1 + intern/cycles/render/scene.cpp | 9 +++-- intern/cycles/render/scene.h | 2 +- 8 files changed, 42 insertions(+), 37 deletions(-) diff --git a/intern/cycles/app/cycles_standalone.cpp b/intern/cycles/app/cycles_standalone.cpp index 0cd249f0d84..939c6cf7eb5 100644 --- a/intern/cycles/app/cycles_standalone.cpp +++ b/intern/cycles/app/cycles_standalone.cpp @@ -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& 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 diff --git a/intern/cycles/blender/blender_session.cpp b/intern/cycles/blender/blender_session.cpp index f1226388a62..5b71e11d61d 100644 --- a/intern/cycles/blender/blender_session.cpp +++ b/intern/cycles/blender/blender_session.cpp @@ -124,14 +124,6 @@ void BlenderSession::create_session() last_progress = -1.0f; start_resize_time = 0.0; - /* create scene */ - scene = new Scene(scene_params, session_params.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; @@ -139,6 +131,16 @@ void BlenderSession::create_session() session->progress.set_cancel_callback(function_bind(&BlenderSession::test_cancel, this)); session->set_pause(session_pause); + /* create scene */ + 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); + + session->scene = scene; + /* create sync */ sync = new BlenderSync(b_engine, b_data, b_scene, scene, !background, session->progress); BL::Object b_camera_override(b_engine.camera_override()); diff --git a/intern/cycles/device/device.cpp b/intern/cycles/device/device.cpp index f31cacd8ec1..16c027e2cb5 100644 --- a/intern/cycles/device/device.cpp +++ b/intern/cycles/device/device.cpp @@ -380,10 +380,13 @@ DeviceInfo Device::get_multi_device(const vector& 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) { diff --git a/intern/cycles/device/device.h b/intern/cycles/device/device.h index f400eeb3e6b..4bf88f75932 100644 --- a/intern/cycles/device/device.h +++ b/intern/cycles/device/device.h @@ -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 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; } diff --git a/intern/cycles/device/device_cpu.cpp b/intern/cycles/device/device_cpu.cpp index 0ba00da16a6..b05f24659ee 100644 --- a/intern/cycles/device/device_cpu.cpp +++ b/intern/cycles/device/device_cpu.cpp @@ -1028,6 +1028,7 @@ void device_cpu_info(vector& 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); } diff --git a/intern/cycles/device/device_network.cpp b/intern/cycles/device/device_network.cpp index ced10c98dc9..3fea89a243c 100644 --- a/intern/cycles/device/device_network.cpp +++ b/intern/cycles/device/device_network.cpp @@ -348,6 +348,7 @@ void device_network_info(vector& devices) info.advanced_shading = true; info.has_volume_decoupled = false; info.has_qbvh = false; + info.has_osl = false; devices.push_back(info); } diff --git a/intern/cycles/render/scene.cpp b/intern/cycles/render/scene.cpp index cf89385a33d..00c32312d9f 100644 --- a/intern/cycles/render/scene.cpp +++ b/intern/cycles/render/scene.cpp @@ -40,10 +40,9 @@ 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); diff --git a/intern/cycles/render/scene.h b/intern/cycles/render/scene.h index d4ec7d90ff5..23b9eb06a7b 100644 --- a/intern/cycles/render/scene.h +++ b/intern/cycles/render/scene.h @@ -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);