12 # pragma warning(push)
13 # pragma warning(disable : 4251 4275)
15 #include <OpenColorIO/OpenColorIO.h>
26 using namespace OCIO_NAMESPACE;
62 if (parameters_buffer) {
74 GpuShaderDesc::UniformData
data;
80 std::vector<OCIO_GPULutTexture>
luts;
98 if (uniforms_buffer) {
134 bool use_curve_mapping =
false;
149 const GpuShaderDescRcPtr &shaderdesc_to_scene_linear,
150 const GpuShaderDescRcPtr &shaderdesc_to_display,
151 const bool use_curve_mapping)
156 source += shaderdesc_to_scene_linear->getShaderText();
158 source += shaderdesc_to_display->getShaderText();
166 index = source.find(
"uniform ", index);
170 source.replace(index, 2,
"//");
176 iface.
smooth(Type::VEC2,
"texCoord_interp");
180 info.
define(
"texture1D",
"texture");
181 info.
define(
"texture2D",
"texture");
182 info.
define(
"texture3D",
"texture");
189 info.
vertex_in(1, Type::VEC2,
"texCoord");
192 info.
vertex_source(
"gpu_shader_display_transform_vert.glsl");
201 if (use_curve_mapping) {
202 info.
define(
"USE_CURVE_MAPPING");
212 (dimensions == 2) ? ImageType::FLOAT_2D :
222 size_t ubo_size =
textures.uniforms.size() *
sizeof(
float) * 4;
223 void *ubo_data_buf = malloc(ubo_size);
227 std::stringstream ss;
228 ss <<
"struct OCIO_GPULutParameters {\n";
233 const GpuShaderDesc::UniformData &
data = uniform.
data;
234 const char *name = uniform.
name.c_str();
237 switch (
data.m_type) {
238 case UNIFORM_DOUBLE: {
241 memcpy(ubo_data, &value,
sizeof(
float));
247 int value = int(
data.m_getBool());
248 memcpy(ubo_data, &value,
sizeof(
int));
253 memcpy(ubo_data,
data.m_getFloat3().data(),
sizeof(
float) * 3);
255 case UNIFORM_VECTOR_FLOAT:
256 vec_len =
data.m_vectorFloat.m_getSize();
257 memcpy(ubo_data,
data.m_vectorFloat.m_getVector(),
sizeof(
float) * vec_len);
259 case UNIFORM_VECTOR_INT:
261 vec_len =
data.m_vectorInt.m_getSize();
262 memcpy(ubo_data,
data.m_vectorInt.m_getVector(),
sizeof(
int) * vec_len);
271 ss <<
" " << prefix <<
"vec4 var" << index <<
";\n";
274 ss <<
"#define " << name <<
" lut_parameters.var" << index <<
"." << suffix <<
"\n";
282 ubo_size, ubo_data_buf,
"OCIO_LutParameters");
289 return (shader.
shader !=
nullptr);
299 const GpuShaderDescRcPtr &shader_desc,
303 uniform.
name = shader_desc->getUniform(index, uniform.
data);
304 if (uniform.
data.m_type == UNIFORM_UNKNOWN) {
308 textures.uniforms.push_back(uniform);
313 const GpuShaderDescRcPtr &shader_desc,
316 const char *texture_name =
nullptr;
317 const char *sampler_name =
nullptr;
318 unsigned int width = 0;
320 GpuShaderCreator::TextureType channel = GpuShaderCreator::TEXTURE_RGB_CHANNEL;
322 #if OCIO_VERSION_HEX >= 0x02030000
324 GpuShaderDesc::TextureDimensions dimensions = GpuShaderDesc::TEXTURE_2D;
325 shader_desc->getTexture(
326 index, texture_name, sampler_name,
width,
height, channel, dimensions, interpolation);
328 shader_desc->getTexture(
329 index, texture_name, sampler_name,
width,
height, channel, interpolation);
333 shader_desc->getTextureValues(index, values);
334 if (texture_name ==
nullptr || sampler_name ==
nullptr ||
width == 0 ||
height == 0 ||
343 #if OCIO_VERSION_HEX < 0x02030000
346 std::string sampler1D_name = std::string(
"sampler1D ") + sampler_name;
347 if (strstr(shader_desc->getShaderText(), sampler1D_name.c_str()) !=
nullptr) {
369 const GpuShaderDescRcPtr &shader_desc,
372 const char *texture_name =
nullptr;
373 const char *sampler_name =
nullptr;
374 unsigned int edgelen = 0;
376 shader_desc->get3DTexture(index, texture_name, sampler_name, edgelen, interpolation);
379 shader_desc->get3DTextureValues(index, values);
380 if (texture_name ==
nullptr || sampler_name ==
nullptr || edgelen == 0 || values ==
nullptr) {
401 const GpuShaderDescRcPtr &shaderdesc_to_scene_linear,
402 const GpuShaderDescRcPtr &shaderdesc_to_display)
409 for (
int index = 0; index < shaderdesc_to_scene_linear->getNumUniforms(); index++) {
414 for (
int index = 0; index < shaderdesc_to_scene_linear->getNumTextures(); index++) {
419 for (
int index = 0; index < shaderdesc_to_scene_linear->getNum3DTextures(); index++) {
424 for (
int index = 0; index < shaderdesc_to_display->getNumUniforms(); index++) {
429 for (
int index = 0; index < shaderdesc_to_display->getNumTextures(); index++) {
434 for (
int index = 0; index < shaderdesc_to_display->getNum3DTextures(); index++) {
452 if (curve_mapping_settings) {
453 int lut_size = curve_mapping_settings->
lut_size;
461 if (curvemap.
texture ==
nullptr || curvemap.
buffer ==
nullptr) {
474 if (curve_mapping_settings ==
nullptr || curvemap.
cache_id == curve_mapping_settings->
cache_id) {
481 int offset[3] = {0, 0, 0};
482 int extent[3] = {curve_mapping_settings->
lut_size, 0, 0};
483 const float *pixels = curve_mapping_settings->
lut;
489 for (
int i = 0; i < 4; i++) {
490 data.range[i] = curve_mapping_settings->
range[i];
496 data.first_x[i] = curve_mapping_settings->
first_x[i];
497 data.first_y[i] = curve_mapping_settings->
first_y[i];
498 data.last_x[i] = curve_mapping_settings->
last_x[i];
499 data.last_y[i] = curve_mapping_settings->
last_y[i];
501 for (
int i = 0; i < 3; i++) {
502 data.black[i] = curve_mapping_settings->
black[i];
503 data.bwmul[i] = curve_mapping_settings->
bwmul[i];
518 bool do_update =
false;
524 if (
data.scale != scale) {
528 if (
data.exponent != exponent) {
529 data.exponent = exponent;
532 if (
data.dither != dither) {
533 data.dither = dither;
536 if (
bool(
data.use_predivide) != use_predivide) {
537 data.use_predivide = use_predivide;
540 if (
bool(
data.use_overlay) != use_overlay) {
541 data.use_overlay = use_overlay;
555 bool OCIOImpl::supportGPUShader()
562 OCIO_ConstConfigRcPtr *config,
570 const bool use_curve_mapping = (curve_mapping_settings !=
nullptr);
571 for (std::list<OCIO_GPUDisplayShader>::iterator it =
SHADER_CACHE.begin();
574 if (it->input ==
input && it->view ==
view && it->display == display && it->look == look &&
575 it->use_curve_mapping == use_curve_mapping) {
596 display_shader.
display = display;
597 display_shader.
look = look;
599 display_shader.
valid =
false;
614 config,
input, ROLE_SCENE_LINEAR);
616 config, ROLE_SCENE_LINEAR,
view, display, look, 1.0f, 1.0f,
false);
619 if (processor_to_scene_linear && processor_to_display) {
620 GpuShaderDescRcPtr shaderdesc_to_scene_linear = GpuShaderDesc::CreateShaderDesc();
621 shaderdesc_to_scene_linear->setLanguage(GPU_LANGUAGE_GLSL_1_3);
622 shaderdesc_to_scene_linear->setFunctionName(
"OCIO_to_scene_linear");
623 shaderdesc_to_scene_linear->setResourcePrefix(
"to_scene");
624 (*(ConstProcessorRcPtr *)processor_to_scene_linear)
625 ->getDefaultGPUProcessor()
626 ->extractGpuShaderInfo(shaderdesc_to_scene_linear);
627 shaderdesc_to_scene_linear->finalize();
629 GpuShaderDescRcPtr shaderdesc_to_display = GpuShaderDesc::CreateShaderDesc();
630 shaderdesc_to_display->setLanguage(GPU_LANGUAGE_GLSL_1_3);
631 shaderdesc_to_display->setFunctionName(
"OCIO_to_display");
632 shaderdesc_to_display->setResourcePrefix(
"to_display");
633 (*(ConstProcessorRcPtr *)processor_to_display)
634 ->getDefaultGPUProcessor()
635 ->extractGpuShaderInfo(shaderdesc_to_display);
636 shaderdesc_to_display->finalize();
640 display_shader.
textures, shaderdesc_to_scene_linear, shaderdesc_to_display) &&
644 shaderdesc_to_scene_linear,
645 shaderdesc_to_display,
646 use_curve_mapping)) {
647 display_shader.
valid =
true;
652 if (processor_to_scene_linear) {
655 if (processor_to_display) {
659 return display_shader;
672 bool OCIOImpl::gpuDisplayShaderBind(OCIO_ConstConfigRcPtr *config,
679 const float exponent,
681 const bool use_predivide,
682 const bool use_overlay)
686 config,
input,
view, display, look, curve_mapping_settings);
687 if (!display_shader.
valid) {
697 if (curve_mapping_settings) {
709 for (
int i = 0; i <
textures.luts.size(); i++) {
726 void OCIOImpl::gpuDisplayShaderUnbind()
731 void OCIOImpl::gpuCacheFree()
typedef float(TangentPoint)[2]
void BLI_kdtree_nd_() free(KDTree *tree)
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint * textures
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei width
struct GPUShader GPUShader
struct GPUShaderCreateInfo GPUShaderCreateInfo
void GPU_shader_free(GPUShader *shader)
GPUShader * GPU_shader_create_from_info(const GPUShaderCreateInfo *_info)
void GPU_texture_update_sub(GPUTexture *tex, eGPUDataFormat data_format, const void *pixels, int offset_x, int offset_y, int offset_z, int width, int height, int depth)
void GPU_texture_wrap_mode(GPUTexture *tex, bool use_repeat, bool use_clamp)
GPUTexture * GPU_texture_create_1d(const char *name, int w, int mip_len, eGPUTextureFormat format, const float *data)
struct GPUTexture GPUTexture
void GPU_texture_free(GPUTexture *tex)
void GPU_texture_filter_mode(GPUTexture *tex, bool use_filter)
GPUTexture * GPU_texture_create_2d(const char *name, int w, int h, int mip_len, eGPUTextureFormat format, const float *data)
GPUTexture * GPU_texture_create_3d(const char *name, int w, int h, int d, int mip_len, eGPUTextureFormat texture_format, eGPUDataFormat data_format, const void *data)
int GPU_texture_dimensions(const GPUTexture *tex)
void GPU_texture_bind(GPUTexture *tex, int unit)
GPUTexture * GPU_texture_create_error(int dimension, bool array)
Read Guarded memory(de)allocation.
constexpr StringRef substr(int64_t start, int64_t size) const
depth_tx normal_tx diffuse_light_tx specular_light_tx volume_light_tx environment_tx ambient_occlusion_tx aov_value_tx in_weight_img GPU_RGBA16F
ccl_global float * buffer
ccl_gpu_kernel_postfix ccl_global float int int int int float bool int offset
ccl_global KernelShaderEvalInput * input
double parameters[NUM_PARAMETERS]
OCIO_ConstProcessorRcPtr * OCIO_configGetProcessorWithNames(OCIO_ConstConfigRcPtr *config, const char *srcName, const char *dstName)
OCIO_ConstProcessorRcPtr * OCIO_createDisplayProcessor(OCIO_ConstConfigRcPtr *config, const char *input, const char *view, const char *display, const char *look, const float scale, const float exponent, const bool inverse)
void OCIO_processorRelease(OCIO_ConstProcessorRcPtr *processor)
static bool addGPULut3D(OCIO_GPUTextures &textures, const GpuShaderDescRcPtr &shader_desc, int index)
static OCIO_GPUDisplayShader & getGPUDisplayShader(OCIO_ConstConfigRcPtr *config, const char *input, const char *view, const char *display, const char *look, OCIO_CurveMappingSettings *curve_mapping_settings)
static void updateGPUDisplayParameters(OCIO_GPUShader &shader, float scale, float exponent, float dither, bool use_predivide, bool use_overlay)
static bool createGPUCurveMapping(OCIO_GPUCurveMappping &curvemap, OCIO_CurveMappingSettings *curve_mapping_settings)
static bool addGPUUniform(OCIO_GPUTextures &textures, const GpuShaderDescRcPtr &shader_desc, int index)
@ UNIFORMBUF_SLOT_CURVEMAP
@ UNIFORMBUF_SLOT_DISPLAY
static bool createGPUShader(OCIO_GPUShader &shader, OCIO_GPUTextures &textures, const GpuShaderDescRcPtr &shaderdesc_to_scene_linear, const GpuShaderDescRcPtr &shaderdesc_to_display, const bool use_curve_mapping)
@ TEXTURE_SLOT_CURVE_MAPPING
@ TEXTURE_SLOT_LUTS_OFFSET
static const int SHADER_CACHE_MAX_SIZE
static bool createGPUTextures(OCIO_GPUTextures &textures, const GpuShaderDescRcPtr &shaderdesc_to_scene_linear, const GpuShaderDescRcPtr &shaderdesc_to_display)
static void updateGPUCurveMapping(OCIO_GPUCurveMappping &curvemap, OCIO_CurveMappingSettings *curve_mapping_settings)
static bool addGPULut1D2D(OCIO_GPUTextures &textures, const GpuShaderDescRcPtr &shader_desc, int index)
std::list< OCIO_GPUDisplayShader > SHADER_CACHE
int use_extend_extrapolate
OCIO_GPUCurveMappping curvemap
OCIO_GPUTextures textures
struct GPUShader * shader
GPUUniformBuf * parameters_buffer
OCIO_GPUParameters parameters
std::vector< OCIO_GPUUniform > uniforms
std::vector< OCIO_GPULutTexture > luts
Describe inputs & outputs, stage interfaces, resources and sources of a shader. If all data is correc...
Self & typedef_source(StringRefNull filename)
Self & uniform_buf(int slot, StringRefNull type_name, StringRefNull name, Frequency freq=Frequency::PASS)
Self & sampler(int slot, ImageType type, StringRefNull name, Frequency freq=Frequency::PASS, eGPUSamplerState sampler=(eGPUSamplerState) -1)
std::string fragment_source_generated
Self & fragment_source(StringRefNull filename)
Self & vertex_in(int slot, Type type, StringRefNull name)
std::string typedef_source_generated
Self & vertex_out(StageInterfaceInfo &interface)
Self & push_constant(Type type, StringRefNull name, int array_size=0)
Self & define(StringRefNull name, StringRefNull value="")
Self & vertex_source(StringRefNull filename)
Self & fragment_out(int slot, Type type, StringRefNull name, DualBlend blend=DualBlend::NONE)
Self & smooth(Type type, StringRefNull _name)