Code refactor: pass device to scene, check OSL with device info.

This commit is contained in:
Brecht Van Lommel 2017-10-20 05:08:26 +02:00
parent cc96cdd9d4
commit ae41f38f78
8 changed files with 42 additions and 37 deletions

@ -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

@ -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());

@ -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) {

@ -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;
}

@ -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);
}

@ -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);
}

@ -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);

@ -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);