40 # pragma warning(push)
41 # pragma warning(disable : 4251 4275)
43 #include <OpenColorIO/OpenColorIO.h>
52 using namespace OCIO_NAMESPACE;
76 float curve_mapping_mintable[4];
77 float curve_mapping_range[4];
78 float curve_mapping_ext_in_x[4];
79 float curve_mapping_ext_in_y[4];
80 float curve_mapping_ext_out_x[4];
81 float curve_mapping_ext_out_y[4];
82 float curve_mapping_first_x[4];
83 float curve_mapping_first_y[4];
84 float curve_mapping_last_x[4];
85 float curve_mapping_last_y[4];
86 float curve_mapping_black[4];
87 float curve_mapping_bwmul[4];
100 int exponent_loc = 0;
103 int predivide_loc = 0;
121 GpuShaderDesc::UniformData
data;
127 std::vector<OCIO_GPULutTexture>
luts;
177 bool use_curve_mapping =
false;
192 const GpuShaderDescRcPtr &shaderdesc_to_scene_linear,
193 const GpuShaderDescRcPtr &shaderdesc_to_display,
194 const bool use_curve_mapping)
196 std::ostringstream os;
201 os <<
"#define texture2D texture\n";
202 os <<
"#define texture3D texture\n";
204 if (use_curve_mapping) {
205 os <<
"#define USE_CURVE_MAPPING\n";
208 os << shaderdesc_to_scene_linear->getShaderText() <<
"\n";
209 os << shaderdesc_to_display->getShaderText() <<
"\n";
221 if (
shader.shader ==
nullptr) {
231 "OCIO_GPUCurveMappingParameters");
240 if (use_curve_mapping) {
246 for (
int i = 0; i <
textures.luts.size(); i++) {
254 const GpuShaderDesc::UniformData &
data = uniform.
data;
255 const char *name = uniform.
name.c_str();
257 if (
data.m_getDouble) {
260 else if (
data.m_getBool) {
263 else if (
data.m_getFloat3) {
266 (
float)
data.m_getFloat3()[0],
267 (
float)
data.m_getFloat3()[1],
268 (
float)
data.m_getFloat3()[2]);
270 else if (
data.m_vectorFloat.m_getSize &&
data.m_vectorFloat.m_getVector) {
273 (
int)
data.m_vectorFloat.m_getSize(),
275 (
float *)
data.m_vectorFloat.m_getVector());
277 else if (
data.m_vectorInt.m_getSize &&
data.m_vectorInt.m_getVector) {
280 (
int)
data.m_vectorInt.m_getSize(),
282 (
int *)
data.m_vectorInt.m_getVector());
296 const GpuShaderDescRcPtr &shader_desc,
300 uniform.
name = shader_desc->getUniform(index, uniform.
data);
301 if (uniform.
data.m_type == UNIFORM_UNKNOWN) {
305 textures.uniforms.push_back(uniform);
310 const GpuShaderDescRcPtr &shader_desc,
313 const char *texture_name =
nullptr;
314 const char *sampler_name =
nullptr;
315 unsigned int width = 0;
317 GpuShaderCreator::TextureType channel = GpuShaderCreator::TEXTURE_RGB_CHANNEL;
318 Interpolation interpolation = INTERP_LINEAR;
319 shader_desc->getTexture(
320 index, texture_name, sampler_name,
width,
height, channel, interpolation);
323 shader_desc->getTextureValues(index, values);
324 if (texture_name ==
nullptr || sampler_name ==
nullptr ||
width == 0 ||
height == 0 ||
348 const GpuShaderDescRcPtr &shader_desc,
351 const char *texture_name =
nullptr;
352 const char *sampler_name =
nullptr;
353 unsigned int edgelen = 0;
354 Interpolation interpolation = INTERP_LINEAR;
355 shader_desc->get3DTexture(index, texture_name, sampler_name, edgelen, interpolation);
358 shader_desc->get3DTextureValues(index, values);
359 if (texture_name ==
nullptr || sampler_name ==
nullptr || edgelen == 0 || values ==
nullptr) {
380 const GpuShaderDescRcPtr &shaderdesc_to_scene_linear,
381 const GpuShaderDescRcPtr &shaderdesc_to_display)
388 for (
int index = 0; index < shaderdesc_to_scene_linear->getNumUniforms(); index++) {
393 for (
int index = 0; index < shaderdesc_to_scene_linear->getNumTextures(); index++) {
398 for (
int index = 0; index < shaderdesc_to_scene_linear->getNum3DTextures(); index++) {
403 for (
int index = 0; index < shaderdesc_to_display->getNumUniforms(); index++) {
408 for (
int index = 0; index < shaderdesc_to_display->getNumTextures(); index++) {
413 for (
int index = 0; index < shaderdesc_to_display->getNum3DTextures(); index++) {
431 if (curve_mapping_settings) {
432 int lut_size = curve_mapping_settings->
lut_size;
440 if (curvemap.
texture ==
nullptr || curvemap.
buffer ==
nullptr) {
453 if (curve_mapping_settings ==
nullptr || curvemap.
cache_id == curve_mapping_settings->
cache_id) {
460 int offset[3] = {0, 0, 0};
461 int extent[3] = {curve_mapping_settings->
lut_size, 0, 0};
462 const float *pixels = curve_mapping_settings->
lut;
468 for (
int i = 0; i < 4; i++) {
469 data.curve_mapping_range[i] = curve_mapping_settings->
range[i];
470 data.curve_mapping_mintable[i] = curve_mapping_settings->
mintable[i];
471 data.curve_mapping_ext_in_x[i] = curve_mapping_settings->
ext_in_x[i];
472 data.curve_mapping_ext_in_y[i] = curve_mapping_settings->
ext_in_y[i];
473 data.curve_mapping_ext_out_x[i] = curve_mapping_settings->
ext_out_x[i];
474 data.curve_mapping_ext_out_y[i] = curve_mapping_settings->
ext_out_y[i];
475 data.curve_mapping_first_x[i] = curve_mapping_settings->
first_x[i];
476 data.curve_mapping_first_y[i] = curve_mapping_settings->
first_y[i];
477 data.curve_mapping_last_x[i] = curve_mapping_settings->
last_x[i];
478 data.curve_mapping_last_y[i] = curve_mapping_settings->
last_y[i];
480 for (
int i = 0; i < 3; i++) {
481 data.curve_mapping_black[i] = curve_mapping_settings->
black[i];
482 data.curve_mapping_bwmul[i] = curve_mapping_settings->
bwmul[i];
484 data.curve_mapping_lut_size = curve_mapping_settings->
lut_size;
496 bool OCIOImpl::supportGPUShader()
503 OCIO_ConstConfigRcPtr *config,
511 const bool use_curve_mapping = (curve_mapping_settings !=
nullptr);
512 for (std::list<OCIO_GPUDisplayShader>::iterator it =
SHADER_CACHE.begin();
515 if (it->input == input && it->view ==
view && it->display == display && it->look == look &&
516 it->use_curve_mapping == use_curve_mapping) {
535 display_shader.
input = input;
537 display_shader.
display = display;
538 display_shader.
look = look;
540 display_shader.
valid =
false;
555 config, input, ROLE_SCENE_LINEAR);
557 config, ROLE_SCENE_LINEAR,
view, display, look, 1.0f, 1.0f);
560 if (processor_to_scene_linear && processor_to_display) {
561 GpuShaderDescRcPtr shaderdesc_to_scene_linear = GpuShaderDesc::CreateShaderDesc();
562 shaderdesc_to_scene_linear->setLanguage(GPU_LANGUAGE_GLSL_1_3);
563 shaderdesc_to_scene_linear->setFunctionName(
"OCIO_to_scene_linear");
564 shaderdesc_to_scene_linear->setResourcePrefix(
"to_scene");
565 (*(ConstProcessorRcPtr *)processor_to_scene_linear)
566 ->getDefaultGPUProcessor()
567 ->extractGpuShaderInfo(shaderdesc_to_scene_linear);
568 shaderdesc_to_scene_linear->finalize();
570 GpuShaderDescRcPtr shaderdesc_to_display = GpuShaderDesc::CreateShaderDesc();
571 shaderdesc_to_display->setLanguage(GPU_LANGUAGE_GLSL_1_3);
572 shaderdesc_to_display->setFunctionName(
"OCIO_to_display");
573 shaderdesc_to_scene_linear->setResourcePrefix(
"to_display");
574 (*(ConstProcessorRcPtr *)processor_to_display)
575 ->getDefaultGPUProcessor()
576 ->extractGpuShaderInfo(shaderdesc_to_display);
577 shaderdesc_to_display->finalize();
581 display_shader.
textures, shaderdesc_to_scene_linear, shaderdesc_to_display) &&
585 shaderdesc_to_scene_linear,
586 shaderdesc_to_display,
587 use_curve_mapping)) {
588 display_shader.
valid =
true;
593 if (processor_to_scene_linear) {
596 if (processor_to_display) {
600 return display_shader;
613 bool OCIOImpl::gpuDisplayShaderBind(OCIO_ConstConfigRcPtr *config,
620 const float exponent,
622 const bool use_predivide,
623 const bool use_overlay)
627 config, input,
view, display, look, curve_mapping_settings);
628 if (!display_shader.
valid) {
638 if (curve_mapping_settings) {
650 for (
int i = 0; i <
textures.luts.size(); i++) {
668 void OCIOImpl::gpuDisplayShaderUnbind()
673 void OCIOImpl::gpuCacheFree()
_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
_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 * textures
GPUShader * GPU_shader_create(const char *vertcode, const char *fragcode, const char *geomcode, const char *libcode, const char *defines, const char *shname)
int GPU_shader_get_uniform(GPUShader *shader, const char *name)
void GPU_shader_uniform_vector_int(GPUShader *shader, int location, int length, int arraysize, const int *value)
struct GPUShader GPUShader
void GPU_shader_uniform_3f(GPUShader *sh, const char *name, float x, float y, float z)
void GPU_shader_uniform_1f(GPUShader *sh, const char *name, float value)
void GPU_shader_uniform_vector(GPUShader *shader, int location, int length, int arraysize, const float *value)
void GPU_shader_uniform_int(GPUShader *shader, int location, int value)
int GPU_shader_get_uniform_block_binding(GPUShader *shader, const char *name)
void GPU_shader_bind(GPUShader *shader)
void GPU_shader_free(GPUShader *shader)
void GPU_shader_uniform_float(GPUShader *shader, int location, float value)
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)
void GPU_texture_bind(GPUTexture *tex, int unit)
GPUTexture * GPU_texture_create_error(int dimension, bool array)
Read Guarded memory(de)allocation.
void KERNEL_FUNCTION_FULL_NAME() shader(KernelGlobals *kg, uint4 *input, float4 *output, int type, int filter, int i, int offset, int sample)
__kernel void ccl_constant KernelData ccl_global void ccl_global char ccl_global int ccl_global char ccl_global unsigned int ccl_global float * buffer
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)
OCIO_ConstProcessorRcPtr * OCIO_configGetProcessorWithNames(OCIO_ConstConfigRcPtr *config, const char *srcName, const char *dstName)
void OCIO_processorRelease(OCIO_ConstProcessorRcPtr *processor)
char datatoc_gpu_shader_display_transform_glsl[]
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 bool createGPUCurveMapping(OCIO_GPUCurveMappping &curvemap, OCIO_CurveMappingSettings *curve_mapping_settings)
static bool addGPUUniform(OCIO_GPUTextures &textures, const GpuShaderDescRcPtr &shader_desc, int index)
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
char datatoc_gpu_shader_display_transform_vertex_glsl[]
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 bool addGPULut2D(OCIO_GPUTextures &textures, const GpuShaderDescRcPtr &shader_desc, int index)
static void updateGPUCurveMapping(OCIO_GPUCurveMappping &curvemap, OCIO_CurveMappingSettings *curve_mapping_settings)
std::list< OCIO_GPUDisplayShader > SHADER_CACHE
int use_extend_extrapolate
int curve_mapping_lut_size
int curve_mapping_use_extend_extrapolate
OCIO_GPUCurveMappping curvemap
OCIO_GPUTextures textures
std::vector< OCIO_GPUUniform > uniforms
std::vector< OCIO_GPULutTexture > luts