2011-04-27 11:58:34 +00:00
|
|
|
/*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Copyright 2011-2013 Blender Foundation
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
2014-12-25 02:50:24 +01:00
|
|
|
* limitations under the License.
|
2011-04-27 11:58:34 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <Python.h>
|
|
|
|
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 20:39:14 +02:00
|
|
|
#include "blender/CCL_api.h"
|
2012-01-09 16:58:01 +00:00
|
|
|
|
2019-02-06 12:57:10 +01:00
|
|
|
#include "blender/blender_device.h"
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 20:39:14 +02:00
|
|
|
#include "blender/blender_session.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "blender/blender_sync.h"
|
2020-02-02 13:09:18 +01:00
|
|
|
#include "blender/blender_util.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2019-02-06 12:57:10 +01:00
|
|
|
#include "render/denoising.h"
|
2019-03-19 14:38:57 +01:00
|
|
|
#include "render/merge.h"
|
2019-02-06 12:57:10 +01:00
|
|
|
|
2018-01-19 14:55:53 +01:00
|
|
|
#include "util/util_debug.h"
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 20:39:14 +02:00
|
|
|
#include "util/util_foreach.h"
|
|
|
|
#include "util/util_logging.h"
|
|
|
|
#include "util/util_md5.h"
|
|
|
|
#include "util/util_opengl.h"
|
2020-06-01 00:11:17 +02:00
|
|
|
#include "util/util_openimagedenoise.h"
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 20:39:14 +02:00
|
|
|
#include "util/util_path.h"
|
|
|
|
#include "util/util_string.h"
|
2020-06-05 11:39:11 +02:00
|
|
|
#include "util/util_task.h"
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 20:39:14 +02:00
|
|
|
#include "util/util_types.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-11-03 14:32:35 +00:00
|
|
|
#ifdef WITH_OSL
|
2019-04-17 06:17:24 +02:00
|
|
|
# include "render/osl.h"
|
2012-11-03 14:32:35 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
# include <OSL/oslconfig.h>
|
2020-03-19 09:33:03 +01:00
|
|
|
# include <OSL/oslquery.h>
|
2012-11-03 14:32:35 +00:00
|
|
|
#endif
|
|
|
|
|
Cycles: Support multithreaded compilation of kernels
This patch implements a workaround to get the multithreaded compilation from D2231 working.
So far, it only works for Blender, not for Cycles Standalone. Also, I have only tested the Linux codepath in the helper function.
Depends on D2231.
Reviewers: brecht, dingto, sergey, juicyfruit, lukasstockner97
Reviewed By: brecht
Subscribers: Loner, jbakker, candreacchio, 3dLuver, LazyDodo, bliblubli
Differential Revision: https://developer.blender.org/D2264
2019-02-15 08:18:38 +01:00
|
|
|
#ifdef WITH_OPENCL
|
2019-04-17 06:17:24 +02:00
|
|
|
# include "device/device_intern.h"
|
Cycles: Support multithreaded compilation of kernels
This patch implements a workaround to get the multithreaded compilation from D2231 working.
So far, it only works for Blender, not for Cycles Standalone. Also, I have only tested the Linux codepath in the helper function.
Depends on D2231.
Reviewers: brecht, dingto, sergey, juicyfruit, lukasstockner97
Reviewed By: brecht
Subscribers: Loner, jbakker, candreacchio, 3dLuver, LazyDodo, bliblubli
Differential Revision: https://developer.blender.org/D2264
2019-02-15 08:18:38 +01:00
|
|
|
#endif
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
2016-01-12 16:00:48 +05:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
/* Flag describing whether debug flags were synchronized from scene. */
|
|
|
|
bool debug_flags_set = false;
|
|
|
|
|
|
|
|
void *pylong_as_voidptr_typesafe(PyObject *object)
|
2014-07-01 15:43:37 +06:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (object == Py_None)
|
|
|
|
return NULL;
|
|
|
|
return PyLong_AsVoidPtr(object);
|
2014-07-01 15:43:37 +06:00
|
|
|
}
|
|
|
|
|
2020-05-04 20:02:08 +02:00
|
|
|
PyObject *pyunicode_from_string(const char *str)
|
|
|
|
{
|
|
|
|
/* Ignore errors if device API returns invalid UTF-8 strings. */
|
|
|
|
return PyUnicode_DecodeUTF8(str, strlen(str), "ignore");
|
|
|
|
}
|
|
|
|
|
2016-01-12 16:00:48 +05:00
|
|
|
/* Synchronize debug flags from a given Blender scene.
|
|
|
|
* Return truth when device list needs invalidation.
|
|
|
|
*/
|
|
|
|
bool debug_flags_sync_from_scene(BL::Scene b_scene)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
DebugFlagsRef flags = DebugFlags();
|
|
|
|
PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles");
|
|
|
|
/* Backup some settings for comparison. */
|
|
|
|
DebugFlags::OpenCL::DeviceType opencl_device_type = flags.opencl.device_type;
|
|
|
|
/* Synchronize shared flags. */
|
|
|
|
flags.viewport_static_bvh = get_enum(cscene, "debug_bvh_type");
|
|
|
|
/* Synchronize CPU flags. */
|
|
|
|
flags.cpu.avx2 = get_boolean(cscene, "debug_use_cpu_avx2");
|
|
|
|
flags.cpu.avx = get_boolean(cscene, "debug_use_cpu_avx");
|
|
|
|
flags.cpu.sse41 = get_boolean(cscene, "debug_use_cpu_sse41");
|
|
|
|
flags.cpu.sse3 = get_boolean(cscene, "debug_use_cpu_sse3");
|
|
|
|
flags.cpu.sse2 = get_boolean(cscene, "debug_use_cpu_sse2");
|
|
|
|
flags.cpu.bvh_layout = (BVHLayout)get_enum(cscene, "debug_bvh_layout");
|
|
|
|
flags.cpu.split_kernel = get_boolean(cscene, "debug_use_cpu_split_kernel");
|
|
|
|
/* Synchronize CUDA flags. */
|
|
|
|
flags.cuda.adaptive_compile = get_boolean(cscene, "debug_use_cuda_adaptive_compile");
|
|
|
|
flags.cuda.split_kernel = get_boolean(cscene, "debug_use_cuda_split_kernel");
|
2019-09-12 14:50:06 +02:00
|
|
|
/* Synchronize OptiX flags. */
|
|
|
|
flags.optix.cuda_streams = get_int(cscene, "debug_optix_cuda_streams");
|
2020-07-06 12:25:54 +02:00
|
|
|
flags.optix.curves_api = get_boolean(cscene, "debug_optix_curves_api");
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Synchronize OpenCL device type. */
|
|
|
|
switch (get_enum(cscene, "debug_opencl_device_type")) {
|
|
|
|
case 0:
|
|
|
|
flags.opencl.device_type = DebugFlags::OpenCL::DEVICE_NONE;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
flags.opencl.device_type = DebugFlags::OpenCL::DEVICE_ALL;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
flags.opencl.device_type = DebugFlags::OpenCL::DEVICE_DEFAULT;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
flags.opencl.device_type = DebugFlags::OpenCL::DEVICE_CPU;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
flags.opencl.device_type = DebugFlags::OpenCL::DEVICE_GPU;
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
flags.opencl.device_type = DebugFlags::OpenCL::DEVICE_ACCELERATOR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* Synchronize other OpenCL flags. */
|
|
|
|
flags.opencl.debug = get_boolean(cscene, "debug_use_opencl_debug");
|
|
|
|
flags.opencl.mem_limit = ((size_t)get_int(cscene, "debug_opencl_mem_limit")) * 1024 * 1024;
|
|
|
|
return flags.opencl.device_type != opencl_device_type;
|
2016-01-12 16:00:48 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Reset debug flags to default values.
|
|
|
|
* Return truth when device list needs invalidation.
|
|
|
|
*/
|
|
|
|
bool debug_flags_reset()
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
DebugFlagsRef flags = DebugFlags();
|
|
|
|
/* Backup some settings for comparison. */
|
|
|
|
DebugFlags::OpenCL::DeviceType opencl_device_type = flags.opencl.device_type;
|
|
|
|
flags.reset();
|
|
|
|
return flags.opencl.device_type != opencl_device_type;
|
2016-01-12 16:00:48 +05:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
} /* namespace */
|
2016-01-12 16:00:48 +05:00
|
|
|
|
2014-02-12 23:13:45 +01:00
|
|
|
void python_thread_state_save(void **python_thread_state)
|
2014-02-12 21:49:34 +01:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
*python_thread_state = (void *)PyEval_SaveThread();
|
2014-02-12 21:49:34 +01:00
|
|
|
}
|
|
|
|
|
2014-02-12 23:13:45 +01:00
|
|
|
void python_thread_state_restore(void **python_thread_state)
|
2014-02-12 21:49:34 +01:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
PyEval_RestoreThread((PyThreadState *)*python_thread_state);
|
|
|
|
*python_thread_state = NULL;
|
2014-02-12 21:49:34 +01:00
|
|
|
}
|
|
|
|
|
2014-10-14 14:53:49 +02:00
|
|
|
static const char *PyC_UnicodeAsByte(PyObject *py_str, PyObject **coerce)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
const char *result = _PyUnicode_AsString(py_str);
|
|
|
|
if (result) {
|
|
|
|
/* 99% of the time this is enough but we better support non unicode
|
2019-06-12 09:04:10 +10:00
|
|
|
* chars since blender doesn't limit this.
|
2019-04-17 06:17:24 +02:00
|
|
|
*/
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
PyErr_Clear();
|
|
|
|
if (PyBytes_Check(py_str)) {
|
|
|
|
return PyBytes_AS_STRING(py_str);
|
|
|
|
}
|
|
|
|
else if ((*coerce = PyUnicode_EncodeFSDefault(py_str))) {
|
|
|
|
return PyBytes_AS_STRING(*coerce);
|
|
|
|
}
|
|
|
|
else {
|
2019-06-12 09:04:10 +10:00
|
|
|
/* Clear the error, so Cycles can be at least used without
|
2019-04-17 06:17:24 +02:00
|
|
|
* GPU and OSL support,
|
|
|
|
*/
|
|
|
|
PyErr_Clear();
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
2014-10-14 14:53:49 +02:00
|
|
|
}
|
|
|
|
|
2015-03-27 15:47:55 +05:00
|
|
|
static PyObject *init_func(PyObject * /*self*/, PyObject *args)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
PyObject *path, *user_path;
|
|
|
|
int headless;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (!PyArg_ParseTuple(args, "OOi", &path, &user_path, &headless)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-10-14 14:53:49 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
PyObject *path_coerce = NULL, *user_path_coerce = NULL;
|
|
|
|
path_init(PyC_UnicodeAsByte(path, &path_coerce),
|
|
|
|
PyC_UnicodeAsByte(user_path, &user_path_coerce));
|
|
|
|
Py_XDECREF(path_coerce);
|
|
|
|
Py_XDECREF(user_path_coerce);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BlenderSession::headless = headless;
|
2015-02-18 21:16:52 +05:00
|
|
|
|
2019-08-29 12:32:27 +02:00
|
|
|
DebugFlags().running_inside_blender = true;
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
VLOG(2) << "Debug flags initialized to:\n" << DebugFlags();
|
2016-01-12 16:00:48 +05:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
Py_RETURN_NONE;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2016-02-07 03:40:41 +05:00
|
|
|
static PyObject *exit_func(PyObject * /*self*/, PyObject * /*args*/)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
ShaderManager::free_memory();
|
|
|
|
TaskScheduler::free_memory();
|
|
|
|
Device::free_memory();
|
|
|
|
Py_RETURN_NONE;
|
2016-02-07 03:40:41 +05:00
|
|
|
}
|
|
|
|
|
2015-03-27 15:47:55 +05:00
|
|
|
static PyObject *create_func(PyObject * /*self*/, PyObject *args)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2019-09-11 08:22:53 +02:00
|
|
|
PyObject *pyengine, *pypreferences, *pydata, *pyscreen, *pyregion, *pyv3d, *pyrv3d;
|
2019-04-17 06:17:24 +02:00
|
|
|
int preview_osl;
|
|
|
|
|
|
|
|
if (!PyArg_ParseTuple(args,
|
2019-09-11 08:22:53 +02:00
|
|
|
"OOOOOOOi",
|
2019-04-17 06:17:24 +02:00
|
|
|
&pyengine,
|
|
|
|
&pypreferences,
|
|
|
|
&pydata,
|
2019-09-11 08:22:53 +02:00
|
|
|
&pyscreen,
|
2019-04-17 06:17:24 +02:00
|
|
|
&pyregion,
|
|
|
|
&pyv3d,
|
|
|
|
&pyrv3d,
|
|
|
|
&preview_osl)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* RNA */
|
2019-09-11 08:22:53 +02:00
|
|
|
ID *bScreen = (ID *)PyLong_AsVoidPtr(pyscreen);
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
PointerRNA engineptr;
|
|
|
|
RNA_pointer_create(NULL, &RNA_RenderEngine, (void *)PyLong_AsVoidPtr(pyengine), &engineptr);
|
|
|
|
BL::RenderEngine engine(engineptr);
|
|
|
|
|
|
|
|
PointerRNA preferencesptr;
|
|
|
|
RNA_pointer_create(
|
|
|
|
NULL, &RNA_Preferences, (void *)PyLong_AsVoidPtr(pypreferences), &preferencesptr);
|
|
|
|
BL::Preferences preferences(preferencesptr);
|
|
|
|
|
|
|
|
PointerRNA dataptr;
|
|
|
|
RNA_main_pointer_create((Main *)PyLong_AsVoidPtr(pydata), &dataptr);
|
|
|
|
BL::BlendData data(dataptr);
|
|
|
|
|
|
|
|
PointerRNA regionptr;
|
2019-09-11 08:22:53 +02:00
|
|
|
RNA_pointer_create(bScreen, &RNA_Region, pylong_as_voidptr_typesafe(pyregion), ®ionptr);
|
2019-04-17 06:17:24 +02:00
|
|
|
BL::Region region(regionptr);
|
|
|
|
|
|
|
|
PointerRNA v3dptr;
|
2019-09-11 08:22:53 +02:00
|
|
|
RNA_pointer_create(bScreen, &RNA_SpaceView3D, pylong_as_voidptr_typesafe(pyv3d), &v3dptr);
|
2019-04-17 06:17:24 +02:00
|
|
|
BL::SpaceView3D v3d(v3dptr);
|
|
|
|
|
|
|
|
PointerRNA rv3dptr;
|
2019-09-11 08:22:53 +02:00
|
|
|
RNA_pointer_create(bScreen, &RNA_RegionView3D, pylong_as_voidptr_typesafe(pyrv3d), &rv3dptr);
|
2019-04-17 06:17:24 +02:00
|
|
|
BL::RegionView3D rv3d(rv3dptr);
|
|
|
|
|
|
|
|
/* create session */
|
|
|
|
BlenderSession *session;
|
|
|
|
|
|
|
|
if (rv3d) {
|
|
|
|
/* interactive viewport session */
|
|
|
|
int width = region.width();
|
|
|
|
int height = region.height();
|
|
|
|
|
|
|
|
session = new BlenderSession(engine, preferences, data, v3d, rv3d, width, height);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* offline session or preview render */
|
|
|
|
session = new BlenderSession(engine, preferences, data, preview_osl);
|
|
|
|
}
|
|
|
|
|
|
|
|
return PyLong_FromVoidPtr(session);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2015-03-27 15:47:55 +05:00
|
|
|
static PyObject *free_func(PyObject * /*self*/, PyObject *value)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
delete (BlenderSession *)PyLong_AsVoidPtr(value);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
Py_RETURN_NONE;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2018-02-26 16:46:48 +01:00
|
|
|
static PyObject *render_func(PyObject * /*self*/, PyObject *args)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
PyObject *pysession, *pydepsgraph;
|
2018-02-26 16:46:48 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (!PyArg_ParseTuple(args, "OO", &pysession, &pydepsgraph))
|
|
|
|
return NULL;
|
2018-02-26 16:46:48 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BlenderSession *session = (BlenderSession *)PyLong_AsVoidPtr(pysession);
|
2018-02-26 16:46:48 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
PointerRNA depsgraphptr;
|
|
|
|
RNA_pointer_create(NULL, &RNA_Depsgraph, (ID *)PyLong_AsVoidPtr(pydepsgraph), &depsgraphptr);
|
|
|
|
BL::Depsgraph b_depsgraph(depsgraphptr);
|
2014-02-12 23:13:45 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
python_thread_state_save(&session->python_thread_state);
|
2014-02-12 23:13:45 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
session->render(b_depsgraph);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
python_thread_state_restore(&session->python_thread_state);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
Py_RETURN_NONE;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2014-01-02 19:05:07 -02:00
|
|
|
/* pixel_array and result passed as pointers */
|
2015-03-27 15:47:55 +05:00
|
|
|
static PyObject *bake_func(PyObject * /*self*/, PyObject *args)
|
2014-01-02 19:05:07 -02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
PyObject *pysession, *pydepsgraph, *pyobject;
|
|
|
|
const char *pass_type;
|
Cycles: code refactor to bake using regular render session and tiles
There should be no user visible change from this, except that tile size
now affects performance. The goal here is to simplify bake denoising in
D3099, letting it reuse more denoising tiles and pass code.
A lot of code is now shared with regular rendering, with the two main
differences being that we read some render result passes from the bake API
when starting to render a tile, and call the bake kernel instead of the
path trace kernel.
With this kind of design where Cycles asks for tiles from the bake API,
it should eventually be easier to reduce memory usage, show tiles as
they are baked, or bake multiple passes at once, though there's still
quite some work needed for that.
Reviewers: #cycles
Subscribers: monio, wmatyjewicz, lukasstockner97, michaelknubben
Differential Revision: https://developer.blender.org/D3108
2019-05-10 21:39:58 +02:00
|
|
|
int pass_filter, width, height;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
if (!PyArg_ParseTuple(args,
|
Cycles: code refactor to bake using regular render session and tiles
There should be no user visible change from this, except that tile size
now affects performance. The goal here is to simplify bake denoising in
D3099, letting it reuse more denoising tiles and pass code.
A lot of code is now shared with regular rendering, with the two main
differences being that we read some render result passes from the bake API
when starting to render a tile, and call the bake kernel instead of the
path trace kernel.
With this kind of design where Cycles asks for tiles from the bake API,
it should eventually be easier to reduce memory usage, show tiles as
they are baked, or bake multiple passes at once, though there's still
quite some work needed for that.
Reviewers: #cycles
Subscribers: monio, wmatyjewicz, lukasstockner97, michaelknubben
Differential Revision: https://developer.blender.org/D3108
2019-05-10 21:39:58 +02:00
|
|
|
"OOOsiii",
|
2019-04-17 06:17:24 +02:00
|
|
|
&pysession,
|
|
|
|
&pydepsgraph,
|
|
|
|
&pyobject,
|
|
|
|
&pass_type,
|
|
|
|
&pass_filter,
|
Cycles: code refactor to bake using regular render session and tiles
There should be no user visible change from this, except that tile size
now affects performance. The goal here is to simplify bake denoising in
D3099, letting it reuse more denoising tiles and pass code.
A lot of code is now shared with regular rendering, with the two main
differences being that we read some render result passes from the bake API
when starting to render a tile, and call the bake kernel instead of the
path trace kernel.
With this kind of design where Cycles asks for tiles from the bake API,
it should eventually be easier to reduce memory usage, show tiles as
they are baked, or bake multiple passes at once, though there's still
quite some work needed for that.
Reviewers: #cycles
Subscribers: monio, wmatyjewicz, lukasstockner97, michaelknubben
Differential Revision: https://developer.blender.org/D3108
2019-05-10 21:39:58 +02:00
|
|
|
&width,
|
|
|
|
&height))
|
2019-04-17 06:17:24 +02:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
BlenderSession *session = (BlenderSession *)PyLong_AsVoidPtr(pysession);
|
|
|
|
|
|
|
|
PointerRNA depsgraphptr;
|
|
|
|
RNA_pointer_create(NULL, &RNA_Depsgraph, PyLong_AsVoidPtr(pydepsgraph), &depsgraphptr);
|
|
|
|
BL::Depsgraph b_depsgraph(depsgraphptr);
|
|
|
|
|
|
|
|
PointerRNA objectptr;
|
|
|
|
RNA_id_pointer_create((ID *)PyLong_AsVoidPtr(pyobject), &objectptr);
|
|
|
|
BL::Object b_object(objectptr);
|
|
|
|
|
|
|
|
python_thread_state_save(&session->python_thread_state);
|
|
|
|
|
Cycles: code refactor to bake using regular render session and tiles
There should be no user visible change from this, except that tile size
now affects performance. The goal here is to simplify bake denoising in
D3099, letting it reuse more denoising tiles and pass code.
A lot of code is now shared with regular rendering, with the two main
differences being that we read some render result passes from the bake API
when starting to render a tile, and call the bake kernel instead of the
path trace kernel.
With this kind of design where Cycles asks for tiles from the bake API,
it should eventually be easier to reduce memory usage, show tiles as
they are baked, or bake multiple passes at once, though there's still
quite some work needed for that.
Reviewers: #cycles
Subscribers: monio, wmatyjewicz, lukasstockner97, michaelknubben
Differential Revision: https://developer.blender.org/D3108
2019-05-10 21:39:58 +02:00
|
|
|
session->bake(b_depsgraph, b_object, pass_type, pass_filter, width, height);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
python_thread_state_restore(&session->python_thread_state);
|
|
|
|
|
|
|
|
Py_RETURN_NONE;
|
2014-01-02 19:05:07 -02:00
|
|
|
}
|
|
|
|
|
2015-03-27 15:47:55 +05:00
|
|
|
static PyObject *draw_func(PyObject * /*self*/, PyObject *args)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
PyObject *pysession, *pygraph, *pyv3d, *pyrv3d;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (!PyArg_ParseTuple(args, "OOOO", &pysession, &pygraph, &pyv3d, &pyrv3d))
|
|
|
|
return NULL;
|
2018-07-06 10:17:58 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BlenderSession *session = (BlenderSession *)PyLong_AsVoidPtr(pysession);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (PyLong_AsVoidPtr(pyrv3d)) {
|
|
|
|
/* 3d view drawing */
|
|
|
|
int viewport[4];
|
|
|
|
glGetIntegerv(GL_VIEWPORT, viewport);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
session->draw(viewport[2], viewport[3]);
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
Py_RETURN_NONE;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2015-03-27 15:47:55 +05:00
|
|
|
static PyObject *reset_func(PyObject * /*self*/, PyObject *args)
|
2012-11-09 08:46:53 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
PyObject *pysession, *pydata, *pydepsgraph;
|
2012-11-09 08:46:53 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (!PyArg_ParseTuple(args, "OOO", &pysession, &pydata, &pydepsgraph))
|
|
|
|
return NULL;
|
2012-11-09 08:46:53 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BlenderSession *session = (BlenderSession *)PyLong_AsVoidPtr(pysession);
|
2012-11-09 08:46:53 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
PointerRNA dataptr;
|
|
|
|
RNA_main_pointer_create((Main *)PyLong_AsVoidPtr(pydata), &dataptr);
|
|
|
|
BL::BlendData b_data(dataptr);
|
2012-11-09 08:46:53 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
PointerRNA depsgraphptr;
|
|
|
|
RNA_pointer_create(NULL, &RNA_Depsgraph, PyLong_AsVoidPtr(pydepsgraph), &depsgraphptr);
|
|
|
|
BL::Depsgraph b_depsgraph(depsgraphptr);
|
2012-11-09 08:46:53 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
python_thread_state_save(&session->python_thread_state);
|
2012-11-09 08:46:53 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
session->reset_session(b_data, b_depsgraph);
|
2012-11-09 08:46:53 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
python_thread_state_restore(&session->python_thread_state);
|
2012-11-09 08:46:53 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
Py_RETURN_NONE;
|
2012-11-09 08:46:53 +00:00
|
|
|
}
|
|
|
|
|
2018-02-26 16:46:48 +01:00
|
|
|
static PyObject *sync_func(PyObject * /*self*/, PyObject *args)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
PyObject *pysession, *pydepsgraph;
|
2018-02-26 16:46:48 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (!PyArg_ParseTuple(args, "OO", &pysession, &pydepsgraph))
|
|
|
|
return NULL;
|
2018-02-26 16:46:48 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BlenderSession *session = (BlenderSession *)PyLong_AsVoidPtr(pysession);
|
2018-02-26 16:46:48 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
PointerRNA depsgraphptr;
|
|
|
|
RNA_pointer_create(NULL, &RNA_Depsgraph, PyLong_AsVoidPtr(pydepsgraph), &depsgraphptr);
|
|
|
|
BL::Depsgraph b_depsgraph(depsgraphptr);
|
2014-02-12 23:13:45 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
python_thread_state_save(&session->python_thread_state);
|
2014-02-12 23:13:45 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
session->synchronize(b_depsgraph);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
python_thread_state_restore(&session->python_thread_state);
|
2012-09-04 13:29:07 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
Py_RETURN_NONE;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
static PyObject *available_devices_func(PyObject * /*self*/, PyObject *args)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
const char *type_name;
|
|
|
|
if (!PyArg_ParseTuple(args, "s", &type_name)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
DeviceType type = Device::type_from_string(type_name);
|
|
|
|
uint mask = (type == DEVICE_NONE) ? DEVICE_MASK_ALL : DEVICE_MASK(type);
|
|
|
|
mask |= DEVICE_MASK_CPU;
|
|
|
|
|
|
|
|
vector<DeviceInfo> devices = Device::available_devices(mask);
|
|
|
|
PyObject *ret = PyTuple_New(devices.size());
|
|
|
|
|
|
|
|
for (size_t i = 0; i < devices.size(); i++) {
|
|
|
|
DeviceInfo &device = devices[i];
|
|
|
|
string type_name = Device::string_from_type(device.type);
|
2020-06-08 17:16:10 +02:00
|
|
|
PyObject *device_tuple = PyTuple_New(4);
|
2020-05-04 20:02:08 +02:00
|
|
|
PyTuple_SET_ITEM(device_tuple, 0, pyunicode_from_string(device.description.c_str()));
|
|
|
|
PyTuple_SET_ITEM(device_tuple, 1, pyunicode_from_string(type_name.c_str()));
|
|
|
|
PyTuple_SET_ITEM(device_tuple, 2, pyunicode_from_string(device.id.c_str()));
|
2020-06-08 17:16:10 +02:00
|
|
|
PyTuple_SET_ITEM(device_tuple, 3, PyBool_FromLong(device.has_peer_memory));
|
2019-04-17 06:17:24 +02:00
|
|
|
PyTuple_SET_ITEM(ret, i, device_tuple);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2012-11-03 14:32:35 +00:00
|
|
|
#ifdef WITH_OSL
|
2013-03-18 16:34:57 +00:00
|
|
|
|
2015-03-27 15:47:55 +05:00
|
|
|
static PyObject *osl_update_node_func(PyObject * /*self*/, PyObject *args)
|
2012-11-03 14:32:35 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
PyObject *pydata, *pynodegroup, *pynode;
|
|
|
|
const char *filepath = NULL;
|
|
|
|
|
|
|
|
if (!PyArg_ParseTuple(args, "OOOs", &pydata, &pynodegroup, &pynode, &filepath))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* RNA */
|
|
|
|
PointerRNA dataptr;
|
|
|
|
RNA_main_pointer_create((Main *)PyLong_AsVoidPtr(pydata), &dataptr);
|
|
|
|
BL::BlendData b_data(dataptr);
|
|
|
|
|
|
|
|
PointerRNA nodeptr;
|
|
|
|
RNA_pointer_create((ID *)PyLong_AsVoidPtr(pynodegroup),
|
|
|
|
&RNA_ShaderNodeScript,
|
|
|
|
(void *)PyLong_AsVoidPtr(pynode),
|
|
|
|
&nodeptr);
|
|
|
|
BL::ShaderNodeScript b_node(nodeptr);
|
|
|
|
|
|
|
|
/* update bytecode hash */
|
|
|
|
string bytecode = b_node.bytecode();
|
|
|
|
|
|
|
|
if (!bytecode.empty()) {
|
|
|
|
MD5Hash md5;
|
|
|
|
md5.append((const uint8_t *)bytecode.c_str(), bytecode.size());
|
|
|
|
b_node.bytecode_hash(md5.get_hex().c_str());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
b_node.bytecode_hash("");
|
|
|
|
|
|
|
|
/* query from file path */
|
|
|
|
OSL::OSLQuery query;
|
|
|
|
|
|
|
|
if (!OSLShaderManager::osl_query(query, filepath))
|
|
|
|
Py_RETURN_FALSE;
|
|
|
|
|
|
|
|
/* add new sockets from parameters */
|
|
|
|
set<void *> used_sockets;
|
|
|
|
|
|
|
|
for (int i = 0; i < query.nparams(); i++) {
|
|
|
|
const OSL::OSLQuery::Parameter *param = query.getparam(i);
|
|
|
|
|
|
|
|
/* skip unsupported types */
|
|
|
|
if (param->varlenarray || param->isstruct || param->type.arraylen > 1)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* determine socket type */
|
|
|
|
string socket_type;
|
|
|
|
BL::NodeSocket::type_enum data_type = BL::NodeSocket::type_VALUE;
|
|
|
|
float4 default_float4 = make_float4(0.0f, 0.0f, 0.0f, 1.0f);
|
|
|
|
float default_float = 0.0f;
|
|
|
|
int default_int = 0;
|
|
|
|
string default_string = "";
|
|
|
|
|
|
|
|
if (param->isclosure) {
|
|
|
|
socket_type = "NodeSocketShader";
|
|
|
|
data_type = BL::NodeSocket::type_SHADER;
|
|
|
|
}
|
|
|
|
else if (param->type.vecsemantics == TypeDesc::COLOR) {
|
|
|
|
socket_type = "NodeSocketColor";
|
|
|
|
data_type = BL::NodeSocket::type_RGBA;
|
|
|
|
|
|
|
|
if (param->validdefault) {
|
|
|
|
default_float4[0] = param->fdefault[0];
|
|
|
|
default_float4[1] = param->fdefault[1];
|
|
|
|
default_float4[2] = param->fdefault[2];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (param->type.vecsemantics == TypeDesc::POINT ||
|
|
|
|
param->type.vecsemantics == TypeDesc::VECTOR ||
|
|
|
|
param->type.vecsemantics == TypeDesc::NORMAL) {
|
|
|
|
socket_type = "NodeSocketVector";
|
|
|
|
data_type = BL::NodeSocket::type_VECTOR;
|
|
|
|
|
|
|
|
if (param->validdefault) {
|
|
|
|
default_float4[0] = param->fdefault[0];
|
|
|
|
default_float4[1] = param->fdefault[1];
|
|
|
|
default_float4[2] = param->fdefault[2];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (param->type.aggregate == TypeDesc::SCALAR) {
|
|
|
|
if (param->type.basetype == TypeDesc::INT) {
|
|
|
|
socket_type = "NodeSocketInt";
|
|
|
|
data_type = BL::NodeSocket::type_INT;
|
|
|
|
if (param->validdefault)
|
|
|
|
default_int = param->idefault[0];
|
|
|
|
}
|
|
|
|
else if (param->type.basetype == TypeDesc::FLOAT) {
|
|
|
|
socket_type = "NodeSocketFloat";
|
|
|
|
data_type = BL::NodeSocket::type_VALUE;
|
|
|
|
if (param->validdefault)
|
|
|
|
default_float = param->fdefault[0];
|
|
|
|
}
|
|
|
|
else if (param->type.basetype == TypeDesc::STRING) {
|
|
|
|
socket_type = "NodeSocketString";
|
|
|
|
data_type = BL::NodeSocket::type_STRING;
|
|
|
|
if (param->validdefault)
|
|
|
|
default_string = param->sdefault[0].string();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* find socket socket */
|
|
|
|
BL::NodeSocket b_sock(PointerRNA_NULL);
|
|
|
|
if (param->isoutput) {
|
|
|
|
b_sock = b_node.outputs[param->name.string()];
|
|
|
|
/* remove if type no longer matches */
|
|
|
|
if (b_sock && b_sock.bl_idname() != socket_type) {
|
|
|
|
b_node.outputs.remove(b_data, b_sock);
|
|
|
|
b_sock = BL::NodeSocket(PointerRNA_NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
b_sock = b_node.inputs[param->name.string()];
|
|
|
|
/* remove if type no longer matches */
|
|
|
|
if (b_sock && b_sock.bl_idname() != socket_type) {
|
|
|
|
b_node.inputs.remove(b_data, b_sock);
|
|
|
|
b_sock = BL::NodeSocket(PointerRNA_NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!b_sock) {
|
|
|
|
/* create new socket */
|
|
|
|
if (param->isoutput)
|
|
|
|
b_sock = b_node.outputs.create(
|
|
|
|
b_data, socket_type.c_str(), param->name.c_str(), param->name.c_str());
|
|
|
|
else
|
|
|
|
b_sock = b_node.inputs.create(
|
|
|
|
b_data, socket_type.c_str(), param->name.c_str(), param->name.c_str());
|
|
|
|
|
|
|
|
/* set default value */
|
|
|
|
if (data_type == BL::NodeSocket::type_VALUE) {
|
|
|
|
set_float(b_sock.ptr, "default_value", default_float);
|
|
|
|
}
|
|
|
|
else if (data_type == BL::NodeSocket::type_INT) {
|
|
|
|
set_int(b_sock.ptr, "default_value", default_int);
|
|
|
|
}
|
|
|
|
else if (data_type == BL::NodeSocket::type_RGBA) {
|
|
|
|
set_float4(b_sock.ptr, "default_value", default_float4);
|
|
|
|
}
|
|
|
|
else if (data_type == BL::NodeSocket::type_VECTOR) {
|
|
|
|
set_float3(b_sock.ptr, "default_value", float4_to_float3(default_float4));
|
|
|
|
}
|
|
|
|
else if (data_type == BL::NodeSocket::type_STRING) {
|
|
|
|
set_string(b_sock.ptr, "default_value", default_string);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
used_sockets.insert(b_sock.ptr.data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* remove unused parameters */
|
|
|
|
bool removed;
|
|
|
|
|
|
|
|
do {
|
|
|
|
BL::Node::inputs_iterator b_input;
|
|
|
|
BL::Node::outputs_iterator b_output;
|
|
|
|
|
|
|
|
removed = false;
|
|
|
|
|
|
|
|
for (b_node.inputs.begin(b_input); b_input != b_node.inputs.end(); ++b_input) {
|
|
|
|
if (used_sockets.find(b_input->ptr.data) == used_sockets.end()) {
|
|
|
|
b_node.inputs.remove(b_data, *b_input);
|
|
|
|
removed = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (b_node.outputs.begin(b_output); b_output != b_node.outputs.end(); ++b_output) {
|
|
|
|
if (used_sockets.find(b_output->ptr.data) == used_sockets.end()) {
|
|
|
|
b_node.outputs.remove(b_data, *b_output);
|
|
|
|
removed = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (removed);
|
|
|
|
|
|
|
|
Py_RETURN_TRUE;
|
2012-11-03 14:32:35 +00:00
|
|
|
}
|
|
|
|
|
2015-03-27 15:47:55 +05:00
|
|
|
static PyObject *osl_compile_func(PyObject * /*self*/, PyObject *args)
|
2012-11-03 14:32:35 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
const char *inputfile = NULL, *outputfile = NULL;
|
2012-11-03 14:32:35 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (!PyArg_ParseTuple(args, "ss", &inputfile, &outputfile))
|
|
|
|
return NULL;
|
2018-07-06 10:17:58 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* return */
|
|
|
|
if (!OSLShaderManager::osl_compile(inputfile, outputfile))
|
|
|
|
Py_RETURN_FALSE;
|
2012-11-03 14:32:35 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
Py_RETURN_TRUE;
|
2012-11-03 14:32:35 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-03-27 15:47:55 +05:00
|
|
|
static PyObject *system_info_func(PyObject * /*self*/, PyObject * /*value*/)
|
2015-01-06 14:13:21 +05:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
string system_info = Device::device_capabilities();
|
2020-05-04 20:02:08 +02:00
|
|
|
return pyunicode_from_string(system_info.c_str());
|
2015-01-06 14:13:21 +05:00
|
|
|
}
|
|
|
|
|
2015-07-23 12:08:19 +02:00
|
|
|
#ifdef WITH_OPENCL
|
|
|
|
static PyObject *opencl_disable_func(PyObject * /*self*/, PyObject * /*value*/)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
VLOG(2) << "Disabling OpenCL platform.";
|
|
|
|
DebugFlags().opencl.device_type = DebugFlags::OpenCL::DEVICE_NONE;
|
|
|
|
Py_RETURN_NONE;
|
2015-07-23 12:08:19 +02:00
|
|
|
}
|
Cycles: Support multithreaded compilation of kernels
This patch implements a workaround to get the multithreaded compilation from D2231 working.
So far, it only works for Blender, not for Cycles Standalone. Also, I have only tested the Linux codepath in the helper function.
Depends on D2231.
Reviewers: brecht, dingto, sergey, juicyfruit, lukasstockner97
Reviewed By: brecht
Subscribers: Loner, jbakker, candreacchio, 3dLuver, LazyDodo, bliblubli
Differential Revision: https://developer.blender.org/D2264
2019-02-15 08:18:38 +01:00
|
|
|
|
|
|
|
static PyObject *opencl_compile_func(PyObject * /*self*/, PyObject *args)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
PyObject *sequence = PySequence_Fast(args, "Arguments must be a sequence");
|
|
|
|
if (sequence == NULL) {
|
|
|
|
Py_RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
vector<string> parameters;
|
|
|
|
for (Py_ssize_t i = 0; i < PySequence_Fast_GET_SIZE(sequence); i++) {
|
|
|
|
PyObject *item = PySequence_Fast_GET_ITEM(sequence, i);
|
|
|
|
PyObject *item_as_string = PyObject_Str(item);
|
|
|
|
const char *parameter_string = PyUnicode_AsUTF8(item_as_string);
|
|
|
|
parameters.push_back(parameter_string);
|
|
|
|
Py_DECREF(item_as_string);
|
|
|
|
}
|
|
|
|
Py_DECREF(sequence);
|
|
|
|
|
|
|
|
if (device_opencl_compile_kernel(parameters)) {
|
|
|
|
Py_RETURN_TRUE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Py_RETURN_FALSE;
|
|
|
|
}
|
Cycles: Support multithreaded compilation of kernels
This patch implements a workaround to get the multithreaded compilation from D2231 working.
So far, it only works for Blender, not for Cycles Standalone. Also, I have only tested the Linux codepath in the helper function.
Depends on D2231.
Reviewers: brecht, dingto, sergey, juicyfruit, lukasstockner97
Reviewed By: brecht
Subscribers: Loner, jbakker, candreacchio, 3dLuver, LazyDodo, bliblubli
Differential Revision: https://developer.blender.org/D2264
2019-02-15 08:18:38 +01:00
|
|
|
}
|
2015-07-23 12:08:19 +02:00
|
|
|
#endif
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
static bool image_parse_filepaths(PyObject *pyfilepaths, vector<string> &filepaths)
|
2019-02-06 12:57:10 +01:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (PyUnicode_Check(pyfilepaths)) {
|
|
|
|
const char *filepath = PyUnicode_AsUTF8(pyfilepaths);
|
|
|
|
filepaths.push_back(filepath);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
PyObject *sequence = PySequence_Fast(pyfilepaths,
|
|
|
|
"File paths must be a string or sequence of strings");
|
|
|
|
if (sequence == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Py_ssize_t i = 0; i < PySequence_Fast_GET_SIZE(sequence); i++) {
|
|
|
|
PyObject *item = PySequence_Fast_GET_ITEM(sequence, i);
|
|
|
|
const char *filepath = PyUnicode_AsUTF8(item);
|
|
|
|
if (filepath == NULL) {
|
|
|
|
PyErr_SetString(PyExc_ValueError, "File paths must be a string or sequence of strings.");
|
|
|
|
Py_DECREF(sequence);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
filepaths.push_back(filepath);
|
|
|
|
}
|
|
|
|
Py_DECREF(sequence);
|
|
|
|
|
|
|
|
return true;
|
2019-02-06 12:57:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *denoise_func(PyObject * /*self*/, PyObject *args, PyObject *keywords)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
static const char *keyword_list[] = {
|
|
|
|
"preferences", "scene", "view_layer", "input", "output", "tile_size", "samples", NULL};
|
|
|
|
PyObject *pypreferences, *pyscene, *pyviewlayer;
|
|
|
|
PyObject *pyinput, *pyoutput = NULL;
|
|
|
|
int tile_size = 0, samples = 0;
|
|
|
|
|
|
|
|
if (!PyArg_ParseTupleAndKeywords(args,
|
|
|
|
keywords,
|
|
|
|
"OOOO|Oii",
|
|
|
|
(char **)keyword_list,
|
|
|
|
&pypreferences,
|
|
|
|
&pyscene,
|
|
|
|
&pyviewlayer,
|
|
|
|
&pyinput,
|
|
|
|
&pyoutput,
|
|
|
|
&tile_size,
|
|
|
|
&samples)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get device specification from preferences and scene. */
|
|
|
|
PointerRNA preferencesptr;
|
|
|
|
RNA_pointer_create(
|
|
|
|
NULL, &RNA_Preferences, (void *)PyLong_AsVoidPtr(pypreferences), &preferencesptr);
|
|
|
|
BL::Preferences b_preferences(preferencesptr);
|
|
|
|
|
|
|
|
PointerRNA sceneptr;
|
|
|
|
RNA_id_pointer_create((ID *)PyLong_AsVoidPtr(pyscene), &sceneptr);
|
|
|
|
BL::Scene b_scene(sceneptr);
|
|
|
|
|
|
|
|
DeviceInfo device = blender_device_info(b_preferences, b_scene, true);
|
|
|
|
|
|
|
|
/* Get denoising parameters from view layer. */
|
|
|
|
PointerRNA viewlayerptr;
|
|
|
|
RNA_pointer_create((ID *)PyLong_AsVoidPtr(pyscene),
|
|
|
|
&RNA_ViewLayer,
|
|
|
|
PyLong_AsVoidPtr(pyviewlayer),
|
|
|
|
&viewlayerptr);
|
|
|
|
PointerRNA cviewlayer = RNA_pointer_get(&viewlayerptr, "cycles");
|
|
|
|
|
|
|
|
DenoiseParams params;
|
|
|
|
params.radius = get_int(cviewlayer, "denoising_radius");
|
|
|
|
params.strength = get_float(cviewlayer, "denoising_strength");
|
|
|
|
params.feature_strength = get_float(cviewlayer, "denoising_feature_strength");
|
|
|
|
params.relative_pca = get_boolean(cviewlayer, "denoising_relative_pca");
|
|
|
|
params.neighbor_frames = get_int(cviewlayer, "denoising_neighbor_frames");
|
|
|
|
|
|
|
|
/* Parse file paths list. */
|
|
|
|
vector<string> input, output;
|
|
|
|
|
|
|
|
if (!image_parse_filepaths(pyinput, input)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pyoutput) {
|
|
|
|
if (!image_parse_filepaths(pyoutput, output)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
output = input;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (input.empty()) {
|
|
|
|
PyErr_SetString(PyExc_ValueError, "No input file paths specified.");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (input.size() != output.size()) {
|
|
|
|
PyErr_SetString(PyExc_ValueError, "Number of input and output file paths does not match.");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create denoiser. */
|
|
|
|
Denoiser denoiser(device);
|
|
|
|
denoiser.params = params;
|
|
|
|
denoiser.input = input;
|
|
|
|
denoiser.output = output;
|
|
|
|
|
|
|
|
if (tile_size > 0) {
|
|
|
|
denoiser.tile_size = make_int2(tile_size, tile_size);
|
|
|
|
}
|
|
|
|
if (samples > 0) {
|
|
|
|
denoiser.samples_override = samples;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Run denoiser. */
|
|
|
|
if (!denoiser.run()) {
|
|
|
|
PyErr_SetString(PyExc_ValueError, denoiser.error.c_str());
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Py_RETURN_NONE;
|
2019-02-06 12:57:10 +01:00
|
|
|
}
|
|
|
|
|
2019-03-19 14:38:57 +01:00
|
|
|
static PyObject *merge_func(PyObject * /*self*/, PyObject *args, PyObject *keywords)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
static const char *keyword_list[] = {"input", "output", NULL};
|
|
|
|
PyObject *pyinput, *pyoutput = NULL;
|
|
|
|
|
|
|
|
if (!PyArg_ParseTupleAndKeywords(
|
|
|
|
args, keywords, "OO", (char **)keyword_list, &pyinput, &pyoutput)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Parse input list. */
|
|
|
|
vector<string> input;
|
|
|
|
if (!image_parse_filepaths(pyinput, input)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Parse output string. */
|
|
|
|
if (!PyUnicode_Check(pyoutput)) {
|
|
|
|
PyErr_SetString(PyExc_ValueError, "Output must be a string.");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
string output = PyUnicode_AsUTF8(pyoutput);
|
|
|
|
|
|
|
|
/* Merge. */
|
|
|
|
ImageMerger merger;
|
|
|
|
merger.input = input;
|
|
|
|
merger.output = output;
|
|
|
|
|
|
|
|
if (!merger.run()) {
|
|
|
|
PyErr_SetString(PyExc_ValueError, merger.error.c_str());
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Py_RETURN_NONE;
|
2019-03-19 14:38:57 +01:00
|
|
|
}
|
|
|
|
|
2016-01-12 16:00:48 +05:00
|
|
|
static PyObject *debug_flags_update_func(PyObject * /*self*/, PyObject *args)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
PyObject *pyscene;
|
|
|
|
if (!PyArg_ParseTuple(args, "O", &pyscene)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2016-01-12 16:00:48 +05:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
PointerRNA sceneptr;
|
|
|
|
RNA_id_pointer_create((ID *)PyLong_AsVoidPtr(pyscene), &sceneptr);
|
|
|
|
BL::Scene b_scene(sceneptr);
|
2016-01-12 16:00:48 +05:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (debug_flags_sync_from_scene(b_scene)) {
|
|
|
|
VLOG(2) << "Tagging device list for update.";
|
|
|
|
Device::tag_update();
|
|
|
|
}
|
2016-01-12 16:00:48 +05:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
VLOG(2) << "Debug flags set to:\n" << DebugFlags();
|
2016-01-12 16:00:48 +05:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
debug_flags_set = true;
|
2016-01-12 16:00:48 +05:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
Py_RETURN_NONE;
|
2016-01-12 16:00:48 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *debug_flags_reset_func(PyObject * /*self*/, PyObject * /*args*/)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (debug_flags_reset()) {
|
|
|
|
VLOG(2) << "Tagging device list for update.";
|
|
|
|
Device::tag_update();
|
|
|
|
}
|
|
|
|
if (debug_flags_set) {
|
|
|
|
VLOG(2) << "Debug flags reset to:\n" << DebugFlags();
|
|
|
|
debug_flags_set = false;
|
|
|
|
}
|
|
|
|
Py_RETURN_NONE;
|
2016-01-12 16:00:48 +05:00
|
|
|
}
|
|
|
|
|
2017-03-15 15:52:27 +01:00
|
|
|
static PyObject *set_resumable_chunk_func(PyObject * /*self*/, PyObject *args)
|
2016-03-30 15:55:12 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
int num_resumable_chunks, current_resumable_chunk;
|
|
|
|
if (!PyArg_ParseTuple(args, "ii", &num_resumable_chunks, ¤t_resumable_chunk)) {
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (num_resumable_chunks <= 0) {
|
|
|
|
fprintf(stderr, "Cycles: Bad value for number of resumable chunks.\n");
|
|
|
|
abort();
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
}
|
|
|
|
if (current_resumable_chunk < 1 || current_resumable_chunk > num_resumable_chunks) {
|
|
|
|
fprintf(stderr, "Cycles: Bad value for current resumable chunk number.\n");
|
|
|
|
abort();
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
VLOG(1) << "Initialized resumable render: "
|
|
|
|
<< "num_resumable_chunks=" << num_resumable_chunks << ", "
|
|
|
|
<< "current_resumable_chunk=" << current_resumable_chunk;
|
|
|
|
BlenderSession::num_resumable_chunks = num_resumable_chunks;
|
|
|
|
BlenderSession::current_resumable_chunk = current_resumable_chunk;
|
|
|
|
|
|
|
|
printf("Cycles: Will render chunk %d of %d\n", current_resumable_chunk, num_resumable_chunks);
|
|
|
|
|
|
|
|
Py_RETURN_NONE;
|
2016-03-30 15:55:12 +02:00
|
|
|
}
|
|
|
|
|
2017-03-15 15:52:27 +01:00
|
|
|
static PyObject *set_resumable_chunk_range_func(PyObject * /*self*/, PyObject *args)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
int num_chunks, start_chunk, end_chunk;
|
|
|
|
if (!PyArg_ParseTuple(args, "iii", &num_chunks, &start_chunk, &end_chunk)) {
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (num_chunks <= 0) {
|
|
|
|
fprintf(stderr, "Cycles: Bad value for number of resumable chunks.\n");
|
|
|
|
abort();
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
}
|
|
|
|
if (start_chunk < 1 || start_chunk > num_chunks) {
|
|
|
|
fprintf(stderr, "Cycles: Bad value for start chunk number.\n");
|
|
|
|
abort();
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
}
|
|
|
|
if (end_chunk < 1 || end_chunk > num_chunks) {
|
|
|
|
fprintf(stderr, "Cycles: Bad value for start chunk number.\n");
|
|
|
|
abort();
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
}
|
|
|
|
if (start_chunk > end_chunk) {
|
|
|
|
fprintf(stderr, "Cycles: End chunk should be higher than start one.\n");
|
|
|
|
abort();
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
VLOG(1) << "Initialized resumable render: "
|
|
|
|
<< "num_resumable_chunks=" << num_chunks << ", "
|
|
|
|
<< "start_resumable_chunk=" << start_chunk << "end_resumable_chunk=" << end_chunk;
|
|
|
|
BlenderSession::num_resumable_chunks = num_chunks;
|
|
|
|
BlenderSession::start_resumable_chunk = start_chunk;
|
|
|
|
BlenderSession::end_resumable_chunk = end_chunk;
|
|
|
|
|
|
|
|
printf("Cycles: Will render chunks %d to %d of %d\n", start_chunk, end_chunk, num_chunks);
|
|
|
|
|
|
|
|
Py_RETURN_NONE;
|
2017-03-15 15:52:27 +01:00
|
|
|
}
|
|
|
|
|
2019-05-10 23:32:58 +02:00
|
|
|
static PyObject *clear_resumable_chunk_func(PyObject * /*self*/, PyObject * /*value*/)
|
|
|
|
{
|
|
|
|
VLOG(1) << "Clear resumable render";
|
|
|
|
BlenderSession::num_resumable_chunks = 0;
|
|
|
|
BlenderSession::current_resumable_chunk = 0;
|
|
|
|
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
}
|
|
|
|
|
2018-07-27 15:46:13 +02:00
|
|
|
static PyObject *enable_print_stats_func(PyObject * /*self*/, PyObject * /*args*/)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BlenderSession::print_render_stats = true;
|
|
|
|
Py_RETURN_NONE;
|
2018-07-27 15:46:13 +02:00
|
|
|
}
|
|
|
|
|
Cycles: Refactor Device selection to allow individual GPU compute device selection
Previously, it was only possible to choose a single GPU or all of that type (CUDA or OpenCL).
Now, a toggle button is displayed for every device.
These settings are tied to the PCI Bus ID of the devices, so they're consistent across hardware addition and removal (but not when swapping/moving cards).
From the code perspective, the more important change is that now, the compute device properties are stored in the Addon preferences of the Cycles addon, instead of directly in the User Preferences.
This allows for a cleaner implementation, removing the Cycles C API functions that were called by the RNA code to specify the enum items.
Note that this change is neither backwards- nor forwards-compatible, but since it's only a User Preference no existing files are broken.
Reviewers: #cycles, brecht
Reviewed By: #cycles, brecht
Subscribers: brecht, juicyfruit, mib2berlin, Blendify
Differential Revision: https://developer.blender.org/D2338
2016-11-07 02:33:53 +01:00
|
|
|
static PyObject *get_device_types_func(PyObject * /*self*/, PyObject * /*args*/)
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
vector<DeviceType> device_types = Device::available_types();
|
2019-09-12 14:50:06 +02:00
|
|
|
bool has_cuda = false, has_optix = false, has_opencl = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
foreach (DeviceType device_type, device_types) {
|
|
|
|
has_cuda |= (device_type == DEVICE_CUDA);
|
2019-09-12 14:50:06 +02:00
|
|
|
has_optix |= (device_type == DEVICE_OPTIX);
|
2019-04-17 06:17:24 +02:00
|
|
|
has_opencl |= (device_type == DEVICE_OPENCL);
|
|
|
|
}
|
2019-09-12 14:50:06 +02:00
|
|
|
PyObject *list = PyTuple_New(3);
|
2019-04-17 06:17:24 +02:00
|
|
|
PyTuple_SET_ITEM(list, 0, PyBool_FromLong(has_cuda));
|
2019-09-12 14:50:06 +02:00
|
|
|
PyTuple_SET_ITEM(list, 1, PyBool_FromLong(has_optix));
|
|
|
|
PyTuple_SET_ITEM(list, 2, PyBool_FromLong(has_opencl));
|
2019-04-17 06:17:24 +02:00
|
|
|
return list;
|
Cycles: Refactor Device selection to allow individual GPU compute device selection
Previously, it was only possible to choose a single GPU or all of that type (CUDA or OpenCL).
Now, a toggle button is displayed for every device.
These settings are tied to the PCI Bus ID of the devices, so they're consistent across hardware addition and removal (but not when swapping/moving cards).
From the code perspective, the more important change is that now, the compute device properties are stored in the Addon preferences of the Cycles addon, instead of directly in the User Preferences.
This allows for a cleaner implementation, removing the Cycles C API functions that were called by the RNA code to specify the enum items.
Note that this change is neither backwards- nor forwards-compatible, but since it's only a User Preference no existing files are broken.
Reviewers: #cycles, brecht
Reviewed By: #cycles, brecht
Subscribers: brecht, juicyfruit, mib2berlin, Blendify
Differential Revision: https://developer.blender.org/D2338
2016-11-07 02:33:53 +01:00
|
|
|
}
|
|
|
|
|
2020-10-02 00:48:01 +02:00
|
|
|
static PyObject *set_device_override_func(PyObject * /*self*/, PyObject *arg)
|
|
|
|
{
|
|
|
|
PyObject *override_string = PyObject_Str(arg);
|
|
|
|
string override = PyUnicode_AsUTF8(override_string);
|
|
|
|
Py_DECREF(override_string);
|
|
|
|
|
|
|
|
bool include_cpu = false;
|
|
|
|
const string cpu_suffix = "+CPU";
|
|
|
|
if (string_endswith(override, cpu_suffix)) {
|
|
|
|
include_cpu = true;
|
|
|
|
override = override.substr(0, override.length() - cpu_suffix.length());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (override == "CPU") {
|
|
|
|
BlenderSession::device_override = DEVICE_MASK_CPU;
|
|
|
|
}
|
|
|
|
else if (override == "OPENCL") {
|
|
|
|
BlenderSession::device_override = DEVICE_MASK_OPENCL;
|
|
|
|
}
|
|
|
|
else if (override == "CUDA") {
|
|
|
|
BlenderSession::device_override = DEVICE_MASK_CUDA;
|
|
|
|
}
|
|
|
|
else if (override == "OPTIX") {
|
|
|
|
BlenderSession::device_override = DEVICE_MASK_OPTIX;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf("\nError: %s is not a valid Cycles device.\n", override.c_str());
|
|
|
|
Py_RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (include_cpu) {
|
|
|
|
BlenderSession::device_override = (DeviceTypeMask)(BlenderSession::device_override |
|
|
|
|
DEVICE_MASK_CPU);
|
|
|
|
}
|
|
|
|
|
|
|
|
Py_RETURN_TRUE;
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
static PyMethodDef methods[] = {
|
2019-04-17 06:17:24 +02:00
|
|
|
{"init", init_func, METH_VARARGS, ""},
|
|
|
|
{"exit", exit_func, METH_VARARGS, ""},
|
|
|
|
{"create", create_func, METH_VARARGS, ""},
|
|
|
|
{"free", free_func, METH_O, ""},
|
|
|
|
{"render", render_func, METH_VARARGS, ""},
|
|
|
|
{"bake", bake_func, METH_VARARGS, ""},
|
|
|
|
{"draw", draw_func, METH_VARARGS, ""},
|
|
|
|
{"sync", sync_func, METH_VARARGS, ""},
|
|
|
|
{"reset", reset_func, METH_VARARGS, ""},
|
2012-11-03 14:32:35 +00:00
|
|
|
#ifdef WITH_OSL
|
2019-04-17 06:17:24 +02:00
|
|
|
{"osl_update_node", osl_update_node_func, METH_VARARGS, ""},
|
|
|
|
{"osl_compile", osl_compile_func, METH_VARARGS, ""},
|
2012-11-03 14:32:35 +00:00
|
|
|
#endif
|
2019-04-17 06:17:24 +02:00
|
|
|
{"available_devices", available_devices_func, METH_VARARGS, ""},
|
|
|
|
{"system_info", system_info_func, METH_NOARGS, ""},
|
2015-07-23 12:08:19 +02:00
|
|
|
#ifdef WITH_OPENCL
|
2019-04-17 06:17:24 +02:00
|
|
|
{"opencl_disable", opencl_disable_func, METH_NOARGS, ""},
|
|
|
|
{"opencl_compile", opencl_compile_func, METH_VARARGS, ""},
|
2015-07-23 12:08:19 +02:00
|
|
|
#endif
|
2016-03-30 15:55:12 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Standalone denoising */
|
|
|
|
{"denoise", (PyCFunction)denoise_func, METH_VARARGS | METH_KEYWORDS, ""},
|
|
|
|
{"merge", (PyCFunction)merge_func, METH_VARARGS | METH_KEYWORDS, ""},
|
2019-02-06 12:57:10 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Debugging routines */
|
|
|
|
{"debug_flags_update", debug_flags_update_func, METH_VARARGS, ""},
|
|
|
|
{"debug_flags_reset", debug_flags_reset_func, METH_NOARGS, ""},
|
2016-03-30 15:55:12 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Statistics. */
|
|
|
|
{"enable_print_stats", enable_print_stats_func, METH_NOARGS, ""},
|
2018-07-27 15:46:13 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Resumable render */
|
|
|
|
{"set_resumable_chunk", set_resumable_chunk_func, METH_VARARGS, ""},
|
|
|
|
{"set_resumable_chunk_range", set_resumable_chunk_range_func, METH_VARARGS, ""},
|
2019-05-10 23:32:58 +02:00
|
|
|
{"clear_resumable_chunk", clear_resumable_chunk_func, METH_NOARGS, ""},
|
2016-03-30 15:55:12 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Compute Device selection */
|
|
|
|
{"get_device_types", get_device_types_func, METH_VARARGS, ""},
|
2020-10-02 00:48:01 +02:00
|
|
|
{"set_device_override", set_device_override_func, METH_O, ""},
|
Cycles: Refactor Device selection to allow individual GPU compute device selection
Previously, it was only possible to choose a single GPU or all of that type (CUDA or OpenCL).
Now, a toggle button is displayed for every device.
These settings are tied to the PCI Bus ID of the devices, so they're consistent across hardware addition and removal (but not when swapping/moving cards).
From the code perspective, the more important change is that now, the compute device properties are stored in the Addon preferences of the Cycles addon, instead of directly in the User Preferences.
This allows for a cleaner implementation, removing the Cycles C API functions that were called by the RNA code to specify the enum items.
Note that this change is neither backwards- nor forwards-compatible, but since it's only a User Preference no existing files are broken.
Reviewers: #cycles, brecht
Reviewed By: #cycles, brecht
Subscribers: brecht, juicyfruit, mib2berlin, Blendify
Differential Revision: https://developer.blender.org/D2338
2016-11-07 02:33:53 +01:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
{NULL, NULL, 0, NULL},
|
2011-04-27 11:58:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct PyModuleDef module = {
|
2019-04-17 06:17:24 +02:00
|
|
|
PyModuleDef_HEAD_INIT,
|
|
|
|
"_cycles",
|
|
|
|
"Blender cycles render integration",
|
|
|
|
-1,
|
|
|
|
methods,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2011-04-27 11:58:34 +00:00
|
|
|
};
|
|
|
|
|
2012-01-09 16:58:01 +00:00
|
|
|
CCL_NAMESPACE_END
|
|
|
|
|
|
|
|
void *CCL_python_module_init()
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
PyObject *mod = PyModule_Create(&ccl::module);
|
2011-12-24 02:47:13 +00:00
|
|
|
|
|
|
|
#ifdef WITH_OSL
|
2019-04-17 06:17:24 +02:00
|
|
|
/* TODO(sergey): This gives us library we've been linking against.
|
|
|
|
* In theory with dynamic OSL library it might not be
|
|
|
|
* accurate, but there's nothing in OSL API which we
|
|
|
|
* might use to get version in runtime.
|
|
|
|
*/
|
|
|
|
int curversion = OSL_LIBRARY_VERSION_CODE;
|
|
|
|
PyModule_AddObject(mod, "with_osl", Py_True);
|
|
|
|
Py_INCREF(Py_True);
|
|
|
|
PyModule_AddObject(
|
|
|
|
mod,
|
|
|
|
"osl_version",
|
|
|
|
Py_BuildValue("(iii)", curversion / 10000, (curversion / 100) % 100, curversion % 100));
|
|
|
|
PyModule_AddObject(
|
|
|
|
mod,
|
|
|
|
"osl_version_string",
|
|
|
|
PyUnicode_FromFormat(
|
|
|
|
"%2d, %2d, %2d", curversion / 10000, (curversion / 100) % 100, curversion % 100));
|
2011-12-24 02:47:13 +00:00
|
|
|
#else
|
2019-04-17 06:17:24 +02:00
|
|
|
PyModule_AddObject(mod, "with_osl", Py_False);
|
|
|
|
Py_INCREF(Py_False);
|
|
|
|
PyModule_AddStringConstant(mod, "osl_version", "unknown");
|
|
|
|
PyModule_AddStringConstant(mod, "osl_version_string", "unknown");
|
2011-12-24 02:47:13 +00:00
|
|
|
#endif
|
|
|
|
|
Render API/Cycles: Identify Render Passes by their name instead of a type flag
Previously, every RenderPass would have a bitfield that specified its type. That limits the number of passes to 32, which was reached a while ago.
However, most of the code already supported arbitrary RenderPasses since they were also used to store Multilayer EXR images.
Therefore, this commit completely removes the passflag from RenderPass and changes all code to use the unique pass name for identification.
Since Blender Internal relies on hardcoded passes and to preserve compatibility, 32 pass names are reserved for the old hardcoded passes.
To support these arbitrary passes, the Render Result compositor node now adds dynamic sockets. For compatibility, the old hardcoded sockets are always stored and just hidden when the corresponding pass isn't available.
To use these changes, the Render Engine API now includes a function that allows render engines to add arbitrary passes to the render result. To be able to add options for these passes, addons can now add their own properties to SceneRenderLayers.
To keep the compositor input node updated, render engine plugins have to implement a callback that registers all the passes that will be generated.
From a user perspective, nothing should change with this commit.
Differential Revision: https://developer.blender.org/D2443
Differential Revision: https://developer.blender.org/D2444
2017-05-03 00:21:18 +02:00
|
|
|
#ifdef WITH_CYCLES_DEBUG
|
2019-04-17 06:17:24 +02:00
|
|
|
PyModule_AddObject(mod, "with_cycles_debug", Py_True);
|
|
|
|
Py_INCREF(Py_True);
|
Render API/Cycles: Identify Render Passes by their name instead of a type flag
Previously, every RenderPass would have a bitfield that specified its type. That limits the number of passes to 32, which was reached a while ago.
However, most of the code already supported arbitrary RenderPasses since they were also used to store Multilayer EXR images.
Therefore, this commit completely removes the passflag from RenderPass and changes all code to use the unique pass name for identification.
Since Blender Internal relies on hardcoded passes and to preserve compatibility, 32 pass names are reserved for the old hardcoded passes.
To support these arbitrary passes, the Render Result compositor node now adds dynamic sockets. For compatibility, the old hardcoded sockets are always stored and just hidden when the corresponding pass isn't available.
To use these changes, the Render Engine API now includes a function that allows render engines to add arbitrary passes to the render result. To be able to add options for these passes, addons can now add their own properties to SceneRenderLayers.
To keep the compositor input node updated, render engine plugins have to implement a callback that registers all the passes that will be generated.
From a user perspective, nothing should change with this commit.
Differential Revision: https://developer.blender.org/D2443
Differential Revision: https://developer.blender.org/D2444
2017-05-03 00:21:18 +02:00
|
|
|
#else
|
2019-04-17 06:17:24 +02:00
|
|
|
PyModule_AddObject(mod, "with_cycles_debug", Py_False);
|
|
|
|
Py_INCREF(Py_False);
|
Render API/Cycles: Identify Render Passes by their name instead of a type flag
Previously, every RenderPass would have a bitfield that specified its type. That limits the number of passes to 32, which was reached a while ago.
However, most of the code already supported arbitrary RenderPasses since they were also used to store Multilayer EXR images.
Therefore, this commit completely removes the passflag from RenderPass and changes all code to use the unique pass name for identification.
Since Blender Internal relies on hardcoded passes and to preserve compatibility, 32 pass names are reserved for the old hardcoded passes.
To support these arbitrary passes, the Render Result compositor node now adds dynamic sockets. For compatibility, the old hardcoded sockets are always stored and just hidden when the corresponding pass isn't available.
To use these changes, the Render Engine API now includes a function that allows render engines to add arbitrary passes to the render result. To be able to add options for these passes, addons can now add their own properties to SceneRenderLayers.
To keep the compositor input node updated, render engine plugins have to implement a callback that registers all the passes that will be generated.
From a user perspective, nothing should change with this commit.
Differential Revision: https://developer.blender.org/D2443
Differential Revision: https://developer.blender.org/D2444
2017-05-03 00:21:18 +02:00
|
|
|
#endif
|
|
|
|
|
2013-12-07 02:29:53 +01:00
|
|
|
#ifdef WITH_NETWORK
|
2019-04-17 06:17:24 +02:00
|
|
|
PyModule_AddObject(mod, "with_network", Py_True);
|
|
|
|
Py_INCREF(Py_True);
|
2018-11-09 11:34:54 +01:00
|
|
|
#else /* WITH_NETWORK */
|
2019-04-17 06:17:24 +02:00
|
|
|
PyModule_AddObject(mod, "with_network", Py_False);
|
|
|
|
Py_INCREF(Py_False);
|
|
|
|
#endif /* WITH_NETWORK */
|
2013-12-07 02:29:53 +01:00
|
|
|
|
2018-11-07 12:58:12 +01:00
|
|
|
#ifdef WITH_EMBREE
|
2019-04-17 06:17:24 +02:00
|
|
|
PyModule_AddObject(mod, "with_embree", Py_True);
|
|
|
|
Py_INCREF(Py_True);
|
2018-11-09 11:34:54 +01:00
|
|
|
#else /* WITH_EMBREE */
|
2019-04-17 06:17:24 +02:00
|
|
|
PyModule_AddObject(mod, "with_embree", Py_False);
|
|
|
|
Py_INCREF(Py_False);
|
|
|
|
#endif /* WITH_EMBREE */
|
2018-11-07 12:58:12 +01:00
|
|
|
|
2020-06-01 00:11:17 +02:00
|
|
|
if (ccl::openimagedenoise_supported()) {
|
|
|
|
PyModule_AddObject(mod, "with_openimagedenoise", Py_True);
|
|
|
|
Py_INCREF(Py_True);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
PyModule_AddObject(mod, "with_openimagedenoise", Py_False);
|
|
|
|
Py_INCREF(Py_False);
|
|
|
|
}
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return (void *)mod;
|
2012-01-09 16:58:01 +00:00
|
|
|
}
|