2023-06-14 16:52:36 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0 */
|
2022-09-12 18:46:20 +02:00
|
|
|
|
|
|
|
|
#include <OSL/oslexec.h>
|
|
|
|
|
|
|
|
|
|
#include "kernel/osl/globals.h"
|
|
|
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
2024-12-29 23:13:45 +01:00
|
|
|
OSLThreadData::OSLThreadData(OSLGlobals *osl_globals, const int thread_index)
|
|
|
|
|
: globals(osl_globals), thread_index(thread_index)
|
2022-09-12 18:46:20 +02:00
|
|
|
{
|
2024-12-29 23:13:45 +01:00
|
|
|
if (globals == nullptr || globals->use == false) {
|
2022-09-12 18:46:20 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-29 23:13:45 +01:00
|
|
|
ss = globals->ss;
|
2022-09-12 18:46:20 +02:00
|
|
|
|
2024-12-29 23:13:45 +01:00
|
|
|
memset((void *)&shader_globals, 0, sizeof(shader_globals));
|
|
|
|
|
shader_globals.tracedata = &tracedata;
|
2022-09-12 18:46:20 +02:00
|
|
|
|
2024-12-29 23:13:45 +01:00
|
|
|
osl_thread_info = ss->create_thread_info();
|
|
|
|
|
context = ss->get_context(osl_thread_info);
|
|
|
|
|
oiio_thread_info = globals->ts->get_perthread_info();
|
2022-09-12 18:46:20 +02:00
|
|
|
}
|
|
|
|
|
|
2024-12-29 23:13:45 +01:00
|
|
|
OSLThreadData::~OSLThreadData()
|
2022-09-12 18:46:20 +02:00
|
|
|
{
|
2024-12-29 23:13:45 +01:00
|
|
|
if (context) {
|
|
|
|
|
ss->release_context(context);
|
2024-12-26 17:53:59 +01:00
|
|
|
}
|
2024-12-29 23:13:45 +01:00
|
|
|
if (osl_thread_info) {
|
|
|
|
|
ss->destroy_thread_info(osl_thread_info);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-09-12 18:46:20 +02:00
|
|
|
|
2024-12-29 23:13:45 +01:00
|
|
|
OSLThreadData::OSLThreadData(OSLThreadData &&other) noexcept
|
|
|
|
|
: globals(other.globals),
|
|
|
|
|
ss(other.ss),
|
|
|
|
|
thread_index(other.thread_index),
|
|
|
|
|
shader_globals(other.shader_globals),
|
|
|
|
|
tracedata(other.tracedata),
|
|
|
|
|
osl_thread_info(other.osl_thread_info),
|
|
|
|
|
context(other.context),
|
|
|
|
|
oiio_thread_info(other.oiio_thread_info)
|
|
|
|
|
{
|
|
|
|
|
shader_globals.tracedata = &tracedata;
|
|
|
|
|
|
|
|
|
|
memset((void *)&other.shader_globals, 0, sizeof(other.shader_globals));
|
|
|
|
|
memset((void *)&other.tracedata, 0, sizeof(other.tracedata));
|
|
|
|
|
other.thread_index = -1;
|
|
|
|
|
other.context = nullptr;
|
|
|
|
|
other.osl_thread_info = nullptr;
|
|
|
|
|
other.oiio_thread_info = nullptr;
|
2022-09-12 18:46:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|