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 shader_desc->getTexture(
323 index, texture_name, sampler_name,
width,
height, channel, interpolation);
326 shader_desc->getTextureValues(index, values);
327 if (texture_name ==
nullptr || sampler_name ==
nullptr ||
width == 0 ||
height == 0 ||
338 std::string sampler1D_name = std::string(
"sampler1D ") + sampler_name;
339 if (strstr(shader_desc->getShaderText(), sampler1D_name.c_str()) !=
nullptr) {
359 const GpuShaderDescRcPtr &shader_desc,
362 const char *texture_name =
nullptr;
363 const char *sampler_name =
nullptr;
364 unsigned int edgelen = 0;
366 shader_desc->get3DTexture(index, texture_name, sampler_name, edgelen, interpolation);
369 shader_desc->get3DTextureValues(index, values);
370 if (texture_name ==
nullptr || sampler_name ==
nullptr || edgelen == 0 || values ==
nullptr) {
391 const GpuShaderDescRcPtr &shaderdesc_to_scene_linear,
392 const GpuShaderDescRcPtr &shaderdesc_to_display)
399 for (
int index = 0; index < shaderdesc_to_scene_linear->getNumUniforms(); index++) {
404 for (
int index = 0; index < shaderdesc_to_scene_linear->getNumTextures(); index++) {
409 for (
int index = 0; index < shaderdesc_to_scene_linear->getNum3DTextures(); index++) {
414 for (
int index = 0; index < shaderdesc_to_display->getNumUniforms(); index++) {
419 for (
int index = 0; index < shaderdesc_to_display->getNumTextures(); index++) {
424 for (
int index = 0; index < shaderdesc_to_display->getNum3DTextures(); index++) {
442 if (curve_mapping_settings) {
443 int lut_size = curve_mapping_settings->
lut_size;
451 if (curvemap.
texture ==
nullptr || curvemap.
buffer ==
nullptr) {
464 if (curve_mapping_settings ==
nullptr || curvemap.
cache_id == curve_mapping_settings->
cache_id) {
471 int offset[3] = {0, 0, 0};
472 int extent[3] = {curve_mapping_settings->
lut_size, 0, 0};
473 const float *pixels = curve_mapping_settings->
lut;
479 for (
int i = 0; i < 4; i++) {
480 data.range[i] = curve_mapping_settings->
range[i];
486 data.first_x[i] = curve_mapping_settings->
first_x[i];
487 data.first_y[i] = curve_mapping_settings->
first_y[i];
488 data.last_x[i] = curve_mapping_settings->
last_x[i];
489 data.last_y[i] = curve_mapping_settings->
last_y[i];
491 for (
int i = 0; i < 3; i++) {
492 data.black[i] = curve_mapping_settings->
black[i];
493 data.bwmul[i] = curve_mapping_settings->
bwmul[i];
508 bool do_update =
false;
514 if (
data.scale != scale) {
518 if (
data.exponent != exponent) {
519 data.exponent = exponent;
522 if (
data.dither != dither) {
523 data.dither = dither;
526 if (
bool(
data.use_predivide) != use_predivide) {
527 data.use_predivide = use_predivide;
530 if (
bool(
data.use_overlay) != use_overlay) {
531 data.use_overlay = use_overlay;
545 bool OCIOImpl::supportGPUShader()
552 OCIO_ConstConfigRcPtr *config,
560 const bool use_curve_mapping = (curve_mapping_settings !=
nullptr);
561 for (std::list<OCIO_GPUDisplayShader>::iterator it =
SHADER_CACHE.begin();
564 if (it->input ==
input && it->view ==
view && it->display == display && it->look == look &&
565 it->use_curve_mapping == use_curve_mapping) {
586 display_shader.
display = display;
587 display_shader.
look = look;
589 display_shader.
valid =
false;
604 config,
input, ROLE_SCENE_LINEAR);
606 config, ROLE_SCENE_LINEAR,
view, display, look, 1.0f, 1.0f,
false);
609 if (processor_to_scene_linear && processor_to_display) {
610 GpuShaderDescRcPtr shaderdesc_to_scene_linear = GpuShaderDesc::CreateShaderDesc();
611 shaderdesc_to_scene_linear->setLanguage(GPU_LANGUAGE_GLSL_1_3);
612 shaderdesc_to_scene_linear->setFunctionName(
"OCIO_to_scene_linear");
613 shaderdesc_to_scene_linear->setResourcePrefix(
"to_scene");
614 (*(ConstProcessorRcPtr *)processor_to_scene_linear)
615 ->getDefaultGPUProcessor()
616 ->extractGpuShaderInfo(shaderdesc_to_scene_linear);
617 shaderdesc_to_scene_linear->finalize();
619 GpuShaderDescRcPtr shaderdesc_to_display = GpuShaderDesc::CreateShaderDesc();
620 shaderdesc_to_display->setLanguage(GPU_LANGUAGE_GLSL_1_3);
621 shaderdesc_to_display->setFunctionName(
"OCIO_to_display");
622 shaderdesc_to_display->setResourcePrefix(
"to_display");
623 (*(ConstProcessorRcPtr *)processor_to_display)
624 ->getDefaultGPUProcessor()
625 ->extractGpuShaderInfo(shaderdesc_to_display);
626 shaderdesc_to_display->finalize();
630 display_shader.
textures, shaderdesc_to_scene_linear, shaderdesc_to_display) &&
634 shaderdesc_to_scene_linear,
635 shaderdesc_to_display,
636 use_curve_mapping)) {
637 display_shader.
valid =
true;
642 if (processor_to_scene_linear) {
645 if (processor_to_display) {
649 return display_shader;
662 bool OCIOImpl::gpuDisplayShaderBind(OCIO_ConstConfigRcPtr *config,
669 const float exponent,
671 const bool use_predivide,
672 const bool use_overlay)
676 config,
input,
view, display, look, curve_mapping_settings);
677 if (!display_shader.
valid) {
687 if (curve_mapping_settings) {
699 for (
int i = 0; i <
textures.luts.size(); i++) {
716 void OCIOImpl::gpuDisplayShaderUnbind()
721 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)