2022-02-11 13:53:21 +01:00
|
|
|
/* SPDX-License-Identifier: Apache-2.0
|
|
|
|
* Copyright 2011-2022 Blender Foundation */
|
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
|
|
|
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "blender/device.h"
|
|
|
|
#include "blender/session.h"
|
|
|
|
#include "blender/sync.h"
|
|
|
|
#include "blender/util.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "session/denoising.h"
|
|
|
|
#include "session/merge.h"
|
2019-02-06 12:57:10 +01:00
|
|
|
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "util/debug.h"
|
|
|
|
#include "util/foreach.h"
|
2022-09-21 17:58:34 +02:00
|
|
|
#include "util/guiding.h"
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "util/log.h"
|
|
|
|
#include "util/md5.h"
|
|
|
|
#include "util/openimagedenoise.h"
|
|
|
|
#include "util/path.h"
|
|
|
|
#include "util/string.h"
|
|
|
|
#include "util/task.h"
|
|
|
|
#include "util/tbb.h"
|
|
|
|
#include "util/types.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2022-12-02 15:56:12 +01:00
|
|
|
#include "GPU_state.h"
|
|
|
|
|
2012-11-03 14:32:35 +00:00
|
|
|
#ifdef WITH_OSL
|
2021-10-24 14:19:19 +02:00
|
|
|
# include "scene/osl.h"
|
2012-11-03 14:32:35 +00: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
|
|
|
|
|
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
|
|
|
{
|
|
|
|
if (object == Py_None)
|
|
|
|
return NULL;
|
|
|
|
return PyLong_AsVoidPtr(object);
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
*/
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
static void debug_flags_sync_from_scene(BL::Scene b_scene)
|
2016-01-12 16:00:48 +05:00
|
|
|
{
|
|
|
|
DebugFlagsRef flags = DebugFlags();
|
|
|
|
PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles");
|
|
|
|
/* Synchronize CPU flags. */
|
|
|
|
flags.cpu.avx2 = get_boolean(cscene, "debug_use_cpu_avx2");
|
|
|
|
flags.cpu.sse41 = get_boolean(cscene, "debug_use_cpu_sse41");
|
|
|
|
flags.cpu.sse2 = get_boolean(cscene, "debug_use_cpu_sse2");
|
2018-01-19 10:59:58 +01:00
|
|
|
flags.cpu.bvh_layout = (BVHLayout)get_enum(cscene, "debug_bvh_layout");
|
2016-05-06 22:34:15 +02:00
|
|
|
/* Synchronize CUDA flags. */
|
|
|
|
flags.cuda.adaptive_compile = get_boolean(cscene, "debug_use_cuda_adaptive_compile");
|
2019-09-12 14:50:06 +02:00
|
|
|
/* Synchronize OptiX flags. */
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
flags.optix.use_debug = get_boolean(cscene, "debug_use_optix_debug");
|
2016-01-12 16:00:48 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Reset debug flags to default values.
|
|
|
|
* Return truth when device list needs invalidation.
|
|
|
|
*/
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
static void debug_flags_reset()
|
2016-01-12 16:00:48 +05:00
|
|
|
{
|
|
|
|
DebugFlagsRef flags = DebugFlags();
|
|
|
|
flags.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
} /* namespace */
|
|
|
|
|
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
|
|
|
{
|
2014-02-12 23:13:45 +01: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
|
|
|
{
|
2014-02-12 23:13:45 +01:00
|
|
|
PyEval_RestoreThread((PyThreadState *)*python_thread_state);
|
|
|
|
*python_thread_state = NULL;
|
2014-02-12 21:49:34 +01:00
|
|
|
}
|
|
|
|
|
2023-02-15 16:15:59 +11:00
|
|
|
static const char *PyC_UnicodeAsBytes(PyObject *py_str, PyObject **coerce)
|
2014-10-14 14:53:49 +02:00
|
|
|
{
|
2021-02-13 22:57:01 +11:00
|
|
|
const char *result = PyUnicode_AsUTF8(py_str);
|
2016-03-23 13:58:31 +01:00
|
|
|
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.
|
2016-03-23 13:58:31 +01:00
|
|
|
*/
|
|
|
|
return result;
|
2014-10-14 14:53:49 +02:00
|
|
|
}
|
2016-03-23 13:58:31 +01:00
|
|
|
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
|
2016-03-23 13:58:31 +01: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
|
|
|
{
|
2022-01-10 16:05:17 +01:00
|
|
|
PyObject *path, *user_path;
|
2015-02-18 21:16:52 +05:00
|
|
|
int headless;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2022-01-10 16:05:17 +01:00
|
|
|
if (!PyArg_ParseTuple(args, "OOi", &path, &user_path, &headless)) {
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
return nullptr;
|
2014-10-14 14:53:49 +02:00
|
|
|
}
|
|
|
|
|
2022-01-10 16:05:17 +01:00
|
|
|
PyObject *path_coerce = nullptr, *user_path_coerce = nullptr;
|
2023-02-15 16:15:59 +11:00
|
|
|
path_init(PyC_UnicodeAsBytes(path, &path_coerce),
|
|
|
|
PyC_UnicodeAsBytes(user_path, &user_path_coerce));
|
2014-10-14 14:53:49 +02:00
|
|
|
Py_XDECREF(path_coerce);
|
|
|
|
Py_XDECREF(user_path_coerce);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2015-02-18 21:16:52 +05:00
|
|
|
BlenderSession::headless = headless;
|
|
|
|
|
2011-12-24 02:47:13 +00: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*/)
|
|
|
|
{
|
|
|
|
ShaderManager::free_memory();
|
|
|
|
TaskScheduler::free_memory();
|
|
|
|
Device::free_memory();
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
}
|
|
|
|
|
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;
|
2015-02-18 21:16:52 +05:00
|
|
|
int preview_osl;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-02-11 13:37:45 +01:00
|
|
|
if (!PyArg_ParseTuple(args,
|
2019-09-11 08:22:53 +02:00
|
|
|
"OOOOOOOi",
|
2019-02-11 13:37:45 +01:00
|
|
|
&pyengine,
|
|
|
|
&pypreferences,
|
|
|
|
&pydata,
|
2019-09-11 08:22:53 +02:00
|
|
|
&pyscreen,
|
2015-02-18 21:16:52 +05:00
|
|
|
&pyregion,
|
|
|
|
&pyv3d,
|
|
|
|
&pyrv3d,
|
|
|
|
&preview_osl)) {
|
2011-04-27 11:58:34 +00:00
|
|
|
return NULL;
|
2015-02-11 01:02:36 +05:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* RNA */
|
2019-09-11 08:22:53 +02:00
|
|
|
ID *bScreen = (ID *)PyLong_AsVoidPtr(pyscreen);
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
PointerRNA engineptr;
|
2011-05-05 13:51:33 +00:00
|
|
|
RNA_pointer_create(NULL, &RNA_RenderEngine, (void *)PyLong_AsVoidPtr(pyengine), &engineptr);
|
2011-04-27 11:58:34 +00:00
|
|
|
BL::RenderEngine engine(engineptr);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-02-11 13:37:45 +01:00
|
|
|
PointerRNA preferencesptr;
|
|
|
|
RNA_pointer_create(
|
|
|
|
NULL, &RNA_Preferences, (void *)PyLong_AsVoidPtr(pypreferences), &preferencesptr);
|
|
|
|
BL::Preferences preferences(preferencesptr);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
PointerRNA dataptr;
|
2014-12-11 16:55:10 +05:00
|
|
|
RNA_main_pointer_create((Main *)PyLong_AsVoidPtr(pydata), &dataptr);
|
2011-04-27 11:58:34 +00:00
|
|
|
BL::BlendData data(dataptr);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
PointerRNA regionptr;
|
2019-09-11 08:22:53 +02:00
|
|
|
RNA_pointer_create(bScreen, &RNA_Region, pylong_as_voidptr_typesafe(pyregion), ®ionptr);
|
2011-04-27 11:58:34 +00:00
|
|
|
BL::Region region(regionptr);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
PointerRNA v3dptr;
|
2019-09-11 08:22:53 +02:00
|
|
|
RNA_pointer_create(bScreen, &RNA_SpaceView3D, pylong_as_voidptr_typesafe(pyv3d), &v3dptr);
|
2011-04-27 11:58:34 +00:00
|
|
|
BL::SpaceView3D v3d(v3dptr);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
PointerRNA rv3dptr;
|
2019-09-11 08:22:53 +02:00
|
|
|
RNA_pointer_create(bScreen, &RNA_RegionView3D, pylong_as_voidptr_typesafe(pyrv3d), &rv3dptr);
|
2011-04-27 11:58:34 +00:00
|
|
|
BL::RegionView3D rv3d(rv3dptr);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* create session */
|
|
|
|
BlenderSession *session;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
if (rv3d) {
|
2013-01-28 17:37:51 +00:00
|
|
|
/* interactive viewport session */
|
2011-04-27 11:58:34 +00:00
|
|
|
int width = region.width();
|
|
|
|
int height = region.height();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-02-11 13:37:45 +01:00
|
|
|
session = new BlenderSession(engine, preferences, data, v3d, rv3d, width, height);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
else {
|
2013-01-28 17:37:51 +00:00
|
|
|
/* offline session or preview render */
|
2019-02-11 13:37:45 +01:00
|
|
|
session = new BlenderSession(engine, preferences, data, preview_osl);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
return PyLong_FromVoidPtr(session);
|
|
|
|
}
|
|
|
|
|
2015-03-27 15:47:55 +05:00
|
|
|
static PyObject *free_func(PyObject * /*self*/, PyObject *value)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2011-12-24 02:47:13 +00:00
|
|
|
delete (BlenderSession *)PyLong_AsVoidPtr(value);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2011-12-24 02:47:13 +00: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
|
|
|
{
|
2018-02-26 16:46:48 +01:00
|
|
|
PyObject *pysession, *pydepsgraph;
|
|
|
|
|
|
|
|
if (!PyArg_ParseTuple(args, "OO", &pysession, &pydepsgraph))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
BlenderSession *session = (BlenderSession *)PyLong_AsVoidPtr(pysession);
|
|
|
|
|
|
|
|
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
|
|
|
|
2021-06-14 23:50:24 +10:00
|
|
|
/* Allow Blender to execute other Python scripts. */
|
2014-02-12 23:13:45 +01:00
|
|
|
python_thread_state_save(&session->python_thread_state);
|
|
|
|
|
2021-06-14 23:50:24 +10:00
|
|
|
session->render(b_depsgraph);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2014-02-12 23:13:45 +01:00
|
|
|
python_thread_state_restore(&session->python_thread_state);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2011-12-24 02:47:13 +00:00
|
|
|
Py_RETURN_NONE;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
static PyObject *render_frame_finish_func(PyObject * /*self*/, PyObject *args)
|
|
|
|
{
|
|
|
|
PyObject *pysession;
|
|
|
|
|
|
|
|
if (!PyArg_ParseTuple(args, "O", &pysession)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
BlenderSession *session = (BlenderSession *)PyLong_AsVoidPtr(pysession);
|
|
|
|
|
|
|
|
/* Allow Blender to execute other Python scripts. */
|
|
|
|
python_thread_state_save(&session->python_thread_state);
|
|
|
|
|
|
|
|
session->render_frame_finish();
|
|
|
|
|
|
|
|
python_thread_state_restore(&session->python_thread_state);
|
|
|
|
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *draw_func(PyObject * /*self*/, PyObject *args)
|
|
|
|
{
|
|
|
|
PyObject *py_session, *py_graph, *py_screen, *py_space_image;
|
|
|
|
|
|
|
|
if (!PyArg_ParseTuple(args, "OOOO", &py_session, &py_graph, &py_screen, &py_space_image)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
BlenderSession *session = (BlenderSession *)PyLong_AsVoidPtr(py_session);
|
|
|
|
|
|
|
|
ID *b_screen = (ID *)PyLong_AsVoidPtr(py_screen);
|
|
|
|
|
|
|
|
PointerRNA b_space_image_ptr;
|
|
|
|
RNA_pointer_create(b_screen,
|
|
|
|
&RNA_SpaceImageEditor,
|
|
|
|
pylong_as_voidptr_typesafe(py_space_image),
|
|
|
|
&b_space_image_ptr);
|
|
|
|
BL::SpaceImageEditor b_space_image(b_space_image_ptr);
|
|
|
|
|
|
|
|
session->draw(b_space_image);
|
|
|
|
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2018-02-26 16:46:48 +01:00
|
|
|
PyObject *pysession, *pydepsgraph, *pyobject;
|
2014-01-02 19:05:07 -02:00
|
|
|
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
|
|
|
|
2018-02-26 16:46:48 +01: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",
|
2018-02-26 16:46:48 +01: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))
|
2014-01-02 19:05:07 -02:00
|
|
|
return NULL;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-01-02 19:05:07 -02:00
|
|
|
BlenderSession *session = (BlenderSession *)PyLong_AsVoidPtr(pysession);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-02-26 16:46:48 +01:00
|
|
|
PointerRNA depsgraphptr;
|
2018-05-23 12:13:21 +02:00
|
|
|
RNA_pointer_create(NULL, &RNA_Depsgraph, PyLong_AsVoidPtr(pydepsgraph), &depsgraphptr);
|
2018-02-26 16:46:48 +01:00
|
|
|
BL::Depsgraph b_depsgraph(depsgraphptr);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-01-02 19:05:07 -02:00
|
|
|
PointerRNA objectptr;
|
|
|
|
RNA_id_pointer_create((ID *)PyLong_AsVoidPtr(pyobject), &objectptr);
|
|
|
|
BL::Object b_object(objectptr);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-05-22 20:18:45 -03:00
|
|
|
python_thread_state_save(&session->python_thread_state);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-06-14 23:50:24 +10:00
|
|
|
session->bake(b_depsgraph, b_object, pass_type, pass_filter, width, height);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-05-22 20:18:45 -03:00
|
|
|
python_thread_state_restore(&session->python_thread_state);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-01-02 19:05:07 -02:00
|
|
|
Py_RETURN_NONE;
|
|
|
|
}
|
|
|
|
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
static PyObject *view_draw_func(PyObject * /*self*/, PyObject *args)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2017-04-25 16:18:24 +02:00
|
|
|
PyObject *pysession, *pygraph, *pyv3d, *pyrv3d;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2017-04-25 16:18:24 +02:00
|
|
|
if (!PyArg_ParseTuple(args, "OOOO", &pysession, &pygraph, &pyv3d, &pyrv3d))
|
2011-04-27 11:58:34 +00:00
|
|
|
return NULL;
|
2018-07-06 10:17:58 +02:00
|
|
|
|
2011-05-05 13:51:33 +00:00
|
|
|
BlenderSession *session = (BlenderSession *)PyLong_AsVoidPtr(pysession);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2011-05-05 13:51:33 +00:00
|
|
|
if (PyLong_AsVoidPtr(pyrv3d)) {
|
2011-04-27 11:58:34 +00:00
|
|
|
/* 3d view drawing */
|
|
|
|
int viewport[4];
|
2022-12-02 15:56:12 +01:00
|
|
|
GPU_viewport_size_get_i(viewport);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
session->view_draw(viewport[2], viewport[3]);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2011-12-24 02:47:13 +00: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
|
|
|
{
|
2018-05-23 12:13:21 +02:00
|
|
|
PyObject *pysession, *pydata, *pydepsgraph;
|
2012-11-09 08:46:53 +00:00
|
|
|
|
2018-05-23 12:13:21 +02:00
|
|
|
if (!PyArg_ParseTuple(args, "OOO", &pysession, &pydata, &pydepsgraph))
|
2012-11-09 08:46:53 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
BlenderSession *session = (BlenderSession *)PyLong_AsVoidPtr(pysession);
|
|
|
|
|
|
|
|
PointerRNA dataptr;
|
2014-12-11 17:11:23 +05:00
|
|
|
RNA_main_pointer_create((Main *)PyLong_AsVoidPtr(pydata), &dataptr);
|
2012-11-09 08:46:53 +00:00
|
|
|
BL::BlendData b_data(dataptr);
|
|
|
|
|
2018-05-23 12:13:21 +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
|
|
|
|
2014-02-12 23:13:45 +01:00
|
|
|
python_thread_state_save(&session->python_thread_state);
|
2012-11-09 08:46:53 +00:00
|
|
|
|
2021-06-14 23:50:24 +10:00
|
|
|
session->reset_session(b_data, b_depsgraph);
|
2012-11-09 08:46:53 +00:00
|
|
|
|
2014-02-12 23:13:45 +01:00
|
|
|
python_thread_state_restore(&session->python_thread_state);
|
2012-11-09 08:46:53 +00:00
|
|
|
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
}
|
|
|
|
|
2018-02-26 16:46:48 +01:00
|
|
|
static PyObject *sync_func(PyObject * /*self*/, PyObject *args)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2018-02-26 16:46:48 +01:00
|
|
|
PyObject *pysession, *pydepsgraph;
|
|
|
|
|
|
|
|
if (!PyArg_ParseTuple(args, "OO", &pysession, &pydepsgraph))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
BlenderSession *session = (BlenderSession *)PyLong_AsVoidPtr(pysession);
|
|
|
|
|
|
|
|
PointerRNA depsgraphptr;
|
2018-05-23 12:13:21 +02:00
|
|
|
RNA_pointer_create(NULL, &RNA_Depsgraph, PyLong_AsVoidPtr(pydepsgraph), &depsgraphptr);
|
2018-02-26 16:46:48 +01:00
|
|
|
BL::Depsgraph b_depsgraph(depsgraphptr);
|
2014-02-12 23:13:45 +01:00
|
|
|
|
|
|
|
python_thread_state_save(&session->python_thread_state);
|
|
|
|
|
2021-06-14 23:50:24 +10:00
|
|
|
session->synchronize(b_depsgraph);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2014-02-12 23:13:45 +01:00
|
|
|
python_thread_state_restore(&session->python_thread_state);
|
2012-09-04 13:29:07 +00:00
|
|
|
|
2011-12-24 02:47:13 +00:00
|
|
|
Py_RETURN_NONE;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2019-01-29 16:39:30 +01:00
|
|
|
static PyObject *available_devices_func(PyObject * /*self*/, PyObject *args)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2019-01-29 16:39:30 +01:00
|
|
|
const char *type_name;
|
|
|
|
if (!PyArg_ParseTuple(args, "s", &type_name)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-01-29 16:39:30 +01:00
|
|
|
DeviceType type = Device::type_from_string(type_name);
|
2020-10-19 23:58:28 +11:00
|
|
|
/* "NONE" is defined by the add-on, see: `CyclesPreferences.get_device_types`. */
|
|
|
|
if ((type == DEVICE_NONE) && (strcmp(type_name, "NONE") != 0)) {
|
2020-10-15 16:35:41 +11:00
|
|
|
PyErr_Format(PyExc_ValueError, "Device \"%s\" not known.", type_name);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-01-29 16:39:30 +01:00
|
|
|
uint mask = (type == DEVICE_NONE) ? DEVICE_MASK_ALL : DEVICE_MASK(type);
|
|
|
|
mask |= DEVICE_MASK_CPU;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-01-29 16:39:30 +01:00
|
|
|
vector<DeviceInfo> devices = Device::available_devices(mask);
|
2012-01-09 16:58:01 +00:00
|
|
|
PyObject *ret = PyTuple_New(devices.size());
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-01-09 16:58:01 +00:00
|
|
|
for (size_t i = 0; i < devices.size(); i++) {
|
|
|
|
DeviceInfo &device = devices[i];
|
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
|
|
|
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));
|
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
|
|
|
PyTuple_SET_ITEM(ret, i, device_tuple);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2018-05-27 23:46:02 +02:00
|
|
|
PyObject *pydata, *pynodegroup, *pynode;
|
2012-11-03 14:32:35 +00:00
|
|
|
const char *filepath = NULL;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-27 23:46:02 +02:00
|
|
|
if (!PyArg_ParseTuple(args, "OOOs", &pydata, &pynodegroup, &pynode, &filepath))
|
2012-11-03 14:32:35 +00:00
|
|
|
return NULL;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-11-03 14:32:35 +00:00
|
|
|
/* RNA */
|
2018-05-27 23:46:02 +02:00
|
|
|
PointerRNA dataptr;
|
|
|
|
RNA_main_pointer_create((Main *)PyLong_AsVoidPtr(pydata), &dataptr);
|
|
|
|
BL::BlendData b_data(dataptr);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-11-03 14:32:35 +00:00
|
|
|
PointerRNA nodeptr;
|
|
|
|
RNA_pointer_create((ID *)PyLong_AsVoidPtr(pynodegroup),
|
|
|
|
&RNA_ShaderNodeScript,
|
|
|
|
(void *)PyLong_AsVoidPtr(pynode),
|
|
|
|
&nodeptr);
|
|
|
|
BL::ShaderNodeScript b_node(nodeptr);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-11-03 14:32:35 +00:00
|
|
|
/* update bytecode hash */
|
|
|
|
string bytecode = b_node.bytecode();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-11-03 14:32:35 +00:00
|
|
|
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("");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-11-03 14:32:35 +00:00
|
|
|
/* query from file path */
|
|
|
|
OSL::OSLQuery query;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-11-03 14:32:35 +00:00
|
|
|
if (!OSLShaderManager::osl_query(query, filepath))
|
|
|
|
Py_RETURN_FALSE;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-11-03 14:32:35 +00:00
|
|
|
/* add new sockets from parameters */
|
|
|
|
set<void *> used_sockets;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-11-03 14:32:35 +00:00
|
|
|
for (int i = 0; i < query.nparams(); i++) {
|
|
|
|
const OSL::OSLQuery::Parameter *param = query.getparam(i);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-11-03 14:32:35 +00:00
|
|
|
/* skip unsupported types */
|
|
|
|
if (param->varlenarray || param->isstruct || param->type.arraylen > 1)
|
|
|
|
continue;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-08-11 14:49:48 +02:00
|
|
|
/* Read metadata. */
|
|
|
|
bool is_bool_param = false;
|
2022-11-23 18:02:45 +01:00
|
|
|
bool hide_value = !param->validdefault;
|
2021-08-11 14:49:48 +02:00
|
|
|
ustring param_label = param->name;
|
|
|
|
|
|
|
|
for (const OSL::OSLQuery::Parameter &metadata : param->metadata) {
|
|
|
|
if (metadata.type == TypeDesc::STRING) {
|
|
|
|
if (metadata.name == "widget") {
|
|
|
|
/* Boolean socket. */
|
|
|
|
if (metadata.sdefault[0] == "boolean" || metadata.sdefault[0] == "checkBox") {
|
|
|
|
is_bool_param = true;
|
|
|
|
}
|
2022-11-23 18:02:45 +01:00
|
|
|
else if (metadata.sdefault[0] == "null") {
|
|
|
|
hide_value = true;
|
|
|
|
}
|
2021-08-11 14:49:48 +02:00
|
|
|
}
|
|
|
|
else if (metadata.name == "label") {
|
|
|
|
/* Socket label. */
|
|
|
|
param_label = metadata.sdefault[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-03 14:32:35 +00:00
|
|
|
/* determine socket type */
|
2016-10-24 12:31:11 +02:00
|
|
|
string socket_type;
|
2013-03-18 16:34:57 +00:00
|
|
|
BL::NodeSocket::type_enum data_type = BL::NodeSocket::type_VALUE;
|
|
|
|
float4 default_float4 = make_float4(0.0f, 0.0f, 0.0f, 1.0f);
|
2012-11-03 14:32:35 +00:00
|
|
|
float default_float = 0.0f;
|
|
|
|
int default_int = 0;
|
2016-10-24 12:31:11 +02:00
|
|
|
string default_string = "";
|
2021-08-11 14:49:48 +02:00
|
|
|
bool default_boolean = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-11-03 14:32:35 +00:00
|
|
|
if (param->isclosure) {
|
2013-03-18 16:34:57 +00:00
|
|
|
socket_type = "NodeSocketShader";
|
2013-05-01 13:28:44 +00:00
|
|
|
data_type = BL::NodeSocket::type_SHADER;
|
2012-11-03 14:32:35 +00:00
|
|
|
}
|
|
|
|
else if (param->type.vecsemantics == TypeDesc::COLOR) {
|
2013-03-18 16:34:57 +00:00
|
|
|
socket_type = "NodeSocketColor";
|
|
|
|
data_type = BL::NodeSocket::type_RGBA;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-11-03 14:32:35 +00:00
|
|
|
if (param->validdefault) {
|
|
|
|
default_float4[0] = param->fdefault[0];
|
|
|
|
default_float4[1] = param->fdefault[1];
|
|
|
|
default_float4[2] = param->fdefault[2];
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2012-11-03 14:32:35 +00:00
|
|
|
else if (param->type.vecsemantics == TypeDesc::POINT ||
|
|
|
|
param->type.vecsemantics == TypeDesc::VECTOR ||
|
2014-05-05 02:19:08 +10:00
|
|
|
param->type.vecsemantics == TypeDesc::NORMAL) {
|
2013-03-18 16:34:57 +00:00
|
|
|
socket_type = "NodeSocketVector";
|
|
|
|
data_type = BL::NodeSocket::type_VECTOR;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-11-03 14:32:35 +00:00
|
|
|
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) {
|
2021-08-11 14:49:48 +02:00
|
|
|
if (is_bool_param) {
|
|
|
|
socket_type = "NodeSocketBool";
|
|
|
|
data_type = BL::NodeSocket::type_BOOLEAN;
|
|
|
|
if (param->validdefault) {
|
2022-09-26 09:53:49 +10:00
|
|
|
default_boolean = bool(param->idefault[0]);
|
2021-08-11 14:49:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
socket_type = "NodeSocketInt";
|
|
|
|
data_type = BL::NodeSocket::type_INT;
|
|
|
|
if (param->validdefault)
|
|
|
|
default_int = param->idefault[0];
|
|
|
|
}
|
2012-11-03 14:32:35 +00:00
|
|
|
}
|
|
|
|
else if (param->type.basetype == TypeDesc::FLOAT) {
|
2013-03-18 16:34:57 +00:00
|
|
|
socket_type = "NodeSocketFloat";
|
|
|
|
data_type = BL::NodeSocket::type_VALUE;
|
2012-11-03 14:32:35 +00:00
|
|
|
if (param->validdefault)
|
|
|
|
default_float = param->fdefault[0];
|
|
|
|
}
|
2012-11-06 21:36:44 +00:00
|
|
|
else if (param->type.basetype == TypeDesc::STRING) {
|
2013-03-18 16:34:57 +00:00
|
|
|
socket_type = "NodeSocketString";
|
|
|
|
data_type = BL::NodeSocket::type_STRING;
|
2012-11-06 21:36:44 +00:00
|
|
|
if (param->validdefault)
|
2018-12-11 12:17:26 +01:00
|
|
|
default_string = param->sdefault[0].string();
|
2012-11-06 21:36:44 +00:00
|
|
|
}
|
2012-11-09 21:27:05 +00:00
|
|
|
else
|
|
|
|
continue;
|
2012-11-03 14:32:35 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
continue;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-08-11 14:49:48 +02:00
|
|
|
/* Update existing socket. */
|
|
|
|
bool found_existing = false;
|
2015-03-28 00:15:15 +05:00
|
|
|
if (param->isoutput) {
|
2021-08-11 14:49:48 +02:00
|
|
|
for (BL::NodeSocket &b_sock : b_node.outputs) {
|
|
|
|
if (b_sock.identifier() == param->name) {
|
|
|
|
if (b_sock.bl_idname() != socket_type) {
|
|
|
|
/* Remove if type no longer matches. */
|
|
|
|
b_node.outputs.remove(b_data, b_sock);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Reuse and update label. */
|
|
|
|
if (b_sock.name() != param_label) {
|
|
|
|
b_sock.name(param_label.string());
|
|
|
|
}
|
|
|
|
used_sockets.insert(b_sock.ptr.data);
|
|
|
|
found_existing = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2021-08-11 14:49:48 +02:00
|
|
|
for (BL::NodeSocket &b_sock : b_node.inputs) {
|
|
|
|
if (b_sock.identifier() == param->name) {
|
|
|
|
if (b_sock.bl_idname() != socket_type) {
|
|
|
|
/* Remove if type no longer matches. */
|
|
|
|
b_node.inputs.remove(b_data, b_sock);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Reuse and update label. */
|
|
|
|
if (b_sock.name() != param_label) {
|
|
|
|
b_sock.name(param_label.string());
|
|
|
|
}
|
2022-11-23 18:02:45 +01:00
|
|
|
if (b_sock.hide_value() != hide_value) {
|
|
|
|
b_sock.hide_value(hide_value);
|
|
|
|
}
|
2021-08-11 14:49:48 +02:00
|
|
|
used_sockets.insert(b_sock.ptr.data);
|
|
|
|
found_existing = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-08-11 14:49:48 +02:00
|
|
|
if (!found_existing) {
|
|
|
|
/* Create new socket. */
|
|
|
|
BL::NodeSocket b_sock = (param->isoutput) ? b_node.outputs.create(b_data,
|
|
|
|
socket_type.c_str(),
|
|
|
|
param_label.c_str(),
|
|
|
|
param->name.c_str()) :
|
|
|
|
b_node.inputs.create(b_data,
|
|
|
|
socket_type.c_str(),
|
|
|
|
param_label.c_str(),
|
|
|
|
param->name.c_str());
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-06-10 20:47:58 +00:00
|
|
|
/* set default value */
|
2013-03-18 16:34:57 +00:00
|
|
|
if (data_type == BL::NodeSocket::type_VALUE) {
|
|
|
|
set_float(b_sock.ptr, "default_value", default_float);
|
2012-11-03 14:32:35 +00:00
|
|
|
}
|
2013-03-18 16:34:57 +00:00
|
|
|
else if (data_type == BL::NodeSocket::type_INT) {
|
|
|
|
set_int(b_sock.ptr, "default_value", default_int);
|
2012-11-03 14:32:35 +00:00
|
|
|
}
|
2013-03-18 16:34:57 +00:00
|
|
|
else if (data_type == BL::NodeSocket::type_RGBA) {
|
|
|
|
set_float4(b_sock.ptr, "default_value", default_float4);
|
2012-11-03 14:32:35 +00:00
|
|
|
}
|
2013-03-18 16:34:57 +00:00
|
|
|
else if (data_type == BL::NodeSocket::type_VECTOR) {
|
|
|
|
set_float3(b_sock.ptr, "default_value", float4_to_float3(default_float4));
|
2012-11-03 14:32:35 +00:00
|
|
|
}
|
2013-03-18 16:34:57 +00:00
|
|
|
else if (data_type == BL::NodeSocket::type_STRING) {
|
|
|
|
set_string(b_sock.ptr, "default_value", default_string);
|
2012-11-03 14:32:35 +00:00
|
|
|
}
|
2021-08-11 14:49:48 +02:00
|
|
|
else if (data_type == BL::NodeSocket::type_BOOLEAN) {
|
|
|
|
set_boolean(b_sock.ptr, "default_value", default_boolean);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-11-23 18:02:45 +01:00
|
|
|
b_sock.hide_value(hide_value);
|
|
|
|
|
2021-08-11 14:49:48 +02:00
|
|
|
used_sockets.insert(b_sock.ptr.data);
|
|
|
|
}
|
2012-11-03 14:32:35 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-11-03 14:32:35 +00:00
|
|
|
/* remove unused parameters */
|
|
|
|
bool removed;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-11-03 14:32:35 +00:00
|
|
|
do {
|
|
|
|
removed = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-01-25 16:20:10 +01:00
|
|
|
for (BL::NodeSocket &b_input : b_node.inputs) {
|
|
|
|
if (used_sockets.find(b_input.ptr.data) == used_sockets.end()) {
|
|
|
|
b_node.inputs.remove(b_data, b_input);
|
2012-11-03 14:32:35 +00:00
|
|
|
removed = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-01-25 16:20:10 +01:00
|
|
|
for (BL::NodeSocket &b_output : b_node.outputs) {
|
|
|
|
if (used_sockets.find(b_output.ptr.data) == used_sockets.end()) {
|
|
|
|
b_node.outputs.remove(b_data, b_output);
|
2012-11-03 14:32:35 +00:00
|
|
|
removed = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (removed);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-11-03 14:32:35 +00:00
|
|
|
Py_RETURN_TRUE;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
const char *inputfile = NULL, *outputfile = NULL;
|
|
|
|
|
|
|
|
if (!PyArg_ParseTuple(args, "ss", &inputfile, &outputfile))
|
|
|
|
return NULL;
|
2018-07-06 10:17:58 +02:00
|
|
|
|
2012-11-03 14:32:35 +00:00
|
|
|
/* return */
|
|
|
|
if (!OSLShaderManager::osl_compile(inputfile, outputfile))
|
|
|
|
Py_RETURN_FALSE;
|
|
|
|
|
|
|
|
Py_RETURN_TRUE;
|
|
|
|
}
|
|
|
|
#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
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-03-19 14:38:57 +01:00
|
|
|
static bool image_parse_filepaths(PyObject *pyfilepaths, vector<string> &filepaths)
|
2019-02-06 12:57:10 +01:00
|
|
|
{
|
|
|
|
if (PyUnicode_Check(pyfilepaths)) {
|
|
|
|
const char *filepath = PyUnicode_AsUTF8(pyfilepaths);
|
|
|
|
filepaths.push_back(filepath);
|
|
|
|
return true;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-02-06 12:57:10 +01:00
|
|
|
PyObject *sequence = PySequence_Fast(pyfilepaths,
|
|
|
|
"File paths must be a string or sequence of strings");
|
|
|
|
if (sequence == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-02-06 12:57:10 +01:00
|
|
|
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);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-02-06 12:57:10 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *denoise_func(PyObject * /*self*/, PyObject *args, PyObject *keywords)
|
|
|
|
{
|
|
|
|
static const char *keyword_list[] = {
|
2022-01-04 21:39:54 +01:00
|
|
|
"preferences", "scene", "view_layer", "input", "output", NULL};
|
2019-02-11 13:37:45 +01:00
|
|
|
PyObject *pypreferences, *pyscene, *pyviewlayer;
|
2019-02-06 12:57:10 +01:00
|
|
|
PyObject *pyinput, *pyoutput = NULL;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-02-06 12:57:10 +01:00
|
|
|
if (!PyArg_ParseTupleAndKeywords(args,
|
|
|
|
keywords,
|
2022-01-04 21:39:54 +01:00
|
|
|
"OOOO|O",
|
2019-02-06 12:57:10 +01:00
|
|
|
(char **)keyword_list,
|
2019-02-11 13:37:45 +01:00
|
|
|
&pypreferences,
|
|
|
|
&pyscene,
|
|
|
|
&pyviewlayer,
|
2019-02-06 12:57:10 +01:00
|
|
|
&pyinput,
|
2022-01-04 21:39:54 +01:00
|
|
|
&pyoutput)) {
|
2019-02-06 12:57:10 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-02-06 12:57:10 +01:00
|
|
|
/* Get device specification from preferences and scene. */
|
|
|
|
PointerRNA preferencesptr;
|
2019-02-11 13:37:45 +01:00
|
|
|
RNA_pointer_create(
|
|
|
|
NULL, &RNA_Preferences, (void *)PyLong_AsVoidPtr(pypreferences), &preferencesptr);
|
|
|
|
BL::Preferences b_preferences(preferencesptr);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-02-06 12:57:10 +01:00
|
|
|
PointerRNA sceneptr;
|
|
|
|
RNA_id_pointer_create((ID *)PyLong_AsVoidPtr(pyscene), &sceneptr);
|
|
|
|
BL::Scene b_scene(sceneptr);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-01-04 16:01:24 +00:00
|
|
|
DeviceInfo device = blender_device_info(b_preferences, b_scene, true, true);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-02-06 12:57:10 +01:00
|
|
|
/* Get denoising parameters from view layer. */
|
2019-02-11 13:37:45 +01:00
|
|
|
PointerRNA viewlayerptr;
|
|
|
|
RNA_pointer_create((ID *)PyLong_AsVoidPtr(pyscene),
|
|
|
|
&RNA_ViewLayer,
|
|
|
|
PyLong_AsVoidPtr(pyviewlayer),
|
|
|
|
&viewlayerptr);
|
2022-01-04 21:39:54 +01:00
|
|
|
BL::ViewLayer b_view_layer(viewlayerptr);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-01-04 21:39:54 +01:00
|
|
|
DenoiseParams params = BlenderSync::get_denoise_params(b_scene, b_view_layer, true);
|
|
|
|
params.use = true;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-02-06 12:57:10 +01:00
|
|
|
/* Parse file paths list. */
|
|
|
|
vector<string> input, output;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-19 14:38:57 +01:00
|
|
|
if (!image_parse_filepaths(pyinput, input)) {
|
2019-02-06 12:57:10 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-02-06 12:57:10 +01:00
|
|
|
if (pyoutput) {
|
2019-03-19 14:38:57 +01:00
|
|
|
if (!image_parse_filepaths(pyoutput, output)) {
|
2019-02-06 12:57:10 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2019-02-06 12:57:10 +01:00
|
|
|
else {
|
|
|
|
output = input;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-02-06 12:57:10 +01:00
|
|
|
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;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-02-06 12:57:10 +01:00
|
|
|
/* Create denoiser. */
|
2022-01-04 21:39:54 +01:00
|
|
|
DenoiserPipeline denoiser(device, params);
|
2019-02-06 12:57:10 +01:00
|
|
|
denoiser.input = input;
|
|
|
|
denoiser.output = output;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-02-06 12:57:10 +01:00
|
|
|
/* Run denoiser. */
|
|
|
|
if (!denoiser.run()) {
|
|
|
|
PyErr_SetString(PyExc_ValueError, denoiser.error.c_str());
|
|
|
|
return NULL;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-02-06 12:57:10 +01:00
|
|
|
Py_RETURN_NONE;
|
|
|
|
}
|
|
|
|
|
2019-03-19 14:38:57 +01:00
|
|
|
static PyObject *merge_func(PyObject * /*self*/, PyObject *args, PyObject *keywords)
|
|
|
|
{
|
|
|
|
static const char *keyword_list[] = {"input", "output", NULL};
|
|
|
|
PyObject *pyinput, *pyoutput = NULL;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-19 14:38:57 +01:00
|
|
|
if (!PyArg_ParseTupleAndKeywords(
|
|
|
|
args, keywords, "OO", (char **)keyword_list, &pyinput, &pyoutput)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-19 14:38:57 +01:00
|
|
|
/* Parse input list. */
|
|
|
|
vector<string> input;
|
|
|
|
if (!image_parse_filepaths(pyinput, input)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-19 14:38:57 +01:00
|
|
|
/* Parse output string. */
|
|
|
|
if (!PyUnicode_Check(pyoutput)) {
|
|
|
|
PyErr_SetString(PyExc_ValueError, "Output must be a string.");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
string output = PyUnicode_AsUTF8(pyoutput);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-19 14:38:57 +01:00
|
|
|
/* Merge. */
|
|
|
|
ImageMerger merger;
|
|
|
|
merger.input = input;
|
|
|
|
merger.output = output;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-19 14:38:57 +01:00
|
|
|
if (!merger.run()) {
|
|
|
|
PyErr_SetString(PyExc_ValueError, merger.error.c_str());
|
|
|
|
return NULL;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-19 14:38:57 +01:00
|
|
|
Py_RETURN_NONE;
|
|
|
|
}
|
|
|
|
|
2016-01-12 16:00:48 +05:00
|
|
|
static PyObject *debug_flags_update_func(PyObject * /*self*/, PyObject *args)
|
|
|
|
{
|
|
|
|
PyObject *pyscene;
|
|
|
|
if (!PyArg_ParseTuple(args, "O", &pyscene)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
PointerRNA sceneptr;
|
|
|
|
RNA_id_pointer_create((ID *)PyLong_AsVoidPtr(pyscene), &sceneptr);
|
|
|
|
BL::Scene b_scene(sceneptr);
|
|
|
|
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
debug_flags_sync_from_scene(b_scene);
|
2016-01-12 16:00:48 +05:00
|
|
|
|
|
|
|
debug_flags_set = true;
|
|
|
|
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *debug_flags_reset_func(PyObject * /*self*/, PyObject * /*args*/)
|
|
|
|
{
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
debug_flags_reset();
|
2016-01-12 16:00:48 +05:00
|
|
|
if (debug_flags_set) {
|
|
|
|
debug_flags_set = false;
|
|
|
|
}
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
}
|
|
|
|
|
2018-07-27 15:46:13 +02:00
|
|
|
static PyObject *enable_print_stats_func(PyObject * /*self*/, PyObject * /*args*/)
|
|
|
|
{
|
|
|
|
BlenderSession::print_render_stats = true;
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
}
|
|
|
|
|
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-01-29 16:39:30 +01:00
|
|
|
vector<DeviceType> device_types = Device::available_types();
|
2022-06-29 12:58:04 +02:00
|
|
|
bool has_cuda = false, has_optix = false, has_hip = false, has_metal = false, has_oneapi = false;
|
2019-01-29 16:39:30 +01: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);
|
2021-09-28 16:51:14 +02:00
|
|
|
has_hip |= (device_type == DEVICE_HIP);
|
2021-12-07 15:11:35 +00:00
|
|
|
has_metal |= (device_type == DEVICE_METAL);
|
2022-06-29 12:58:04 +02:00
|
|
|
has_oneapi |= (device_type == DEVICE_ONEAPI);
|
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
|
|
|
}
|
2022-06-29 12:58:04 +02:00
|
|
|
PyObject *list = PyTuple_New(5);
|
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
|
|
|
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));
|
2021-09-28 16:51:14 +02:00
|
|
|
PyTuple_SET_ITEM(list, 2, PyBool_FromLong(has_hip));
|
2021-12-07 15:11:35 +00:00
|
|
|
PyTuple_SET_ITEM(list, 3, PyBool_FromLong(has_metal));
|
2022-06-29 12:58:04 +02:00
|
|
|
PyTuple_SET_ITEM(list, 4, PyBool_FromLong(has_oneapi));
|
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
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
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 == "CUDA") {
|
|
|
|
BlenderSession::device_override = DEVICE_MASK_CUDA;
|
|
|
|
}
|
|
|
|
else if (override == "OPTIX") {
|
|
|
|
BlenderSession::device_override = DEVICE_MASK_OPTIX;
|
|
|
|
}
|
2021-09-28 16:51:14 +02:00
|
|
|
else if (override == "HIP") {
|
|
|
|
BlenderSession::device_override = DEVICE_MASK_HIP;
|
|
|
|
}
|
2021-12-07 15:11:35 +00:00
|
|
|
else if (override == "METAL") {
|
|
|
|
BlenderSession::device_override = DEVICE_MASK_METAL;
|
|
|
|
}
|
2022-06-29 12:58:04 +02:00
|
|
|
else if (override == "ONEAPI") {
|
|
|
|
BlenderSession::device_override = DEVICE_MASK_ONEAPI;
|
|
|
|
}
|
2020-10-02 00:48:01 +02:00
|
|
|
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[] = {
|
|
|
|
{"init", init_func, METH_VARARGS, ""},
|
2016-02-07 03:40:41 +05:00
|
|
|
{"exit", exit_func, METH_VARARGS, ""},
|
2011-04-27 11:58:34 +00:00
|
|
|
{"create", create_func, METH_VARARGS, ""},
|
2011-12-24 02:47:13 +00:00
|
|
|
{"free", free_func, METH_O, ""},
|
2018-02-26 16:46:48 +01:00
|
|
|
{"render", render_func, METH_VARARGS, ""},
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
{"render_frame_finish", render_frame_finish_func, METH_VARARGS, ""},
|
2011-04-27 11:58:34 +00:00
|
|
|
{"draw", draw_func, METH_VARARGS, ""},
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
{"bake", bake_func, METH_VARARGS, ""},
|
|
|
|
{"view_draw", view_draw_func, METH_VARARGS, ""},
|
2018-02-26 16:46:48 +01:00
|
|
|
{"sync", sync_func, METH_VARARGS, ""},
|
2012-11-09 08:46:53 +00:00
|
|
|
{"reset", reset_func, METH_VARARGS, ""},
|
2012-11-03 14:32:35 +00:00
|
|
|
#ifdef WITH_OSL
|
|
|
|
{"osl_update_node", osl_update_node_func, METH_VARARGS, ""},
|
|
|
|
{"osl_compile", osl_compile_func, METH_VARARGS, ""},
|
|
|
|
#endif
|
2019-01-29 16:39:30 +01:00
|
|
|
{"available_devices", available_devices_func, METH_VARARGS, ""},
|
2015-01-06 14:13:21 +05:00
|
|
|
{"system_info", system_info_func, METH_NOARGS, ""},
|
2016-03-30 15:55:12 +02:00
|
|
|
|
2019-02-06 12:57:10 +01:00
|
|
|
/* Standalone denoising */
|
|
|
|
{"denoise", (PyCFunction)denoise_func, METH_VARARGS | METH_KEYWORDS, ""},
|
2019-03-19 14:38:57 +01:00
|
|
|
{"merge", (PyCFunction)merge_func, METH_VARARGS | METH_KEYWORDS, ""},
|
2019-02-06 12:57:10 +01:00
|
|
|
|
2016-03-30 15:55:12 +02:00
|
|
|
/* Debugging routines */
|
2016-01-12 16:00:48 +05:00
|
|
|
{"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
|
|
|
|
2018-07-27 15:46:13 +02:00
|
|
|
/* Statistics. */
|
|
|
|
{"enable_print_stats", enable_print_stats_func, METH_NOARGS, ""},
|
|
|
|
|
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
|
|
|
/* 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
|
|
|
|
2011-05-31 16:19:02 +00:00
|
|
|
{NULL, NULL, 0, NULL},
|
2011-04-27 11:58:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct PyModuleDef module = {
|
|
|
|
PyModuleDef_HEAD_INIT,
|
2011-12-24 02:47:13 +00:00
|
|
|
"_cycles",
|
2011-11-07 17:13:32 +00:00
|
|
|
"Blender cycles render integration",
|
2011-04-27 11:58:34 +00:00
|
|
|
-1,
|
2011-05-31 16:19:02 +00:00
|
|
|
methods,
|
2019-01-19 13:21:18 +11:00
|
|
|
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
|
|
|
{
|
2012-06-09 18:56:12 +00:00
|
|
|
PyObject *mod = PyModule_Create(&ccl::module);
|
2011-12-24 02:47:13 +00:00
|
|
|
|
|
|
|
#ifdef WITH_OSL
|
2013-12-08 15:03:17 +06: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
|
2014-03-01 01:21:25 +01:00
|
|
|
* might use to get version in runtime.
|
2013-12-08 15:03:17 +06:00
|
|
|
*/
|
|
|
|
int curversion = OSL_LIBRARY_VERSION_CODE;
|
2011-12-24 02:47:13 +00:00
|
|
|
PyModule_AddObject(mod, "with_osl", Py_True);
|
|
|
|
Py_INCREF(Py_True);
|
2013-12-08 15:03:17 +06:00
|
|
|
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
|
|
|
|
PyModule_AddObject(mod, "with_osl", Py_False);
|
|
|
|
Py_INCREF(Py_False);
|
2013-12-08 15:19:21 +06:00
|
|
|
PyModule_AddStringConstant(mod, "osl_version", "unknown");
|
|
|
|
PyModule_AddStringConstant(mod, "osl_version_string", "unknown");
|
2011-12-24 02:47:13 +00:00
|
|
|
#endif
|
|
|
|
|
2022-09-21 17:58:34 +02:00
|
|
|
if (ccl::guiding_supported()) {
|
|
|
|
PyModule_AddObject(mod, "with_path_guiding", Py_True);
|
|
|
|
Py_INCREF(Py_True);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
PyModule_AddObject(mod, "with_path_guiding", Py_False);
|
|
|
|
Py_INCREF(Py_False);
|
|
|
|
}
|
|
|
|
|
2018-11-07 12:58:12 +01:00
|
|
|
#ifdef WITH_EMBREE
|
|
|
|
PyModule_AddObject(mod, "with_embree", Py_True);
|
|
|
|
Py_INCREF(Py_True);
|
|
|
|
#else /* WITH_EMBREE */
|
|
|
|
PyModule_AddObject(mod, "with_embree", Py_False);
|
|
|
|
Py_INCREF(Py_False);
|
|
|
|
#endif /* WITH_EMBREE */
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2021-11-25 14:32:53 +01:00
|
|
|
#ifdef WITH_CYCLES_DEBUG
|
|
|
|
PyModule_AddObject(mod, "with_debug", Py_True);
|
|
|
|
Py_INCREF(Py_True);
|
|
|
|
#else /* WITH_CYCLES_DEBUG */
|
|
|
|
PyModule_AddObject(mod, "with_debug", Py_False);
|
|
|
|
Py_INCREF(Py_False);
|
|
|
|
#endif /* WITH_CYCLES_DEBUG */
|
|
|
|
|
2012-01-09 16:58:01 +00:00
|
|
|
return (void *)mod;
|
|
|
|
}
|