31#include <OpenColorIO/OpenColorIO.h>
41namespace OCIO = OCIO_NAMESPACE;
61 std::shared_ptr<GPUShaderCreator> instance = std::make_shared<GPUShaderCreator>();
62 instance->setLanguage(OCIO::GPU_LANGUAGE_GLSL_4_0);
63 instance->precision_ = precision;
68 OCIO::GpuShaderCreatorRcPtr
clone()
const override
70 return OCIO::GpuShaderCreatorRcPtr();
81#if OCIO_VERSION_HEX >= 0x02030000
82 void setAllowTexture1D(
bool allowed)
override
84 allow_texture_1D_ = allowed;
87 bool getAllowTexture1D()
const override
89 return allow_texture_1D_;
93 bool addUniform(
const char *name,
const DoubleGetter &get_double)
override
97 if (!resource_names_.add(std::make_unique<std::string>(name))) {
104 std::string &resource_name = *resource_names_[resource_names_.size() - 1];
105 shader_create_info_.push_constant(
Type::float_t, resource_name);
107 float_uniforms_.add(resource_name, get_double);
112 bool addUniform(
const char *name,
const BoolGetter &get_bool)
override
116 if (!resource_names_.add(std::make_unique<std::string>(name))) {
123 const std::string &resource_name = *resource_names_[resource_names_.size() - 1];
124 shader_create_info_.push_constant(
Type::bool_t, resource_name);
126 boolean_uniforms_.add(name, get_bool);
131 bool addUniform(
const char *name,
const Float3Getter &get_float3)
override
135 if (!resource_names_.add(std::make_unique<std::string>(name))) {
142 std::string &resource_name = *resource_names_[resource_names_.size() - 1];
145 vector_uniforms_.add(resource_name, get_float3);
151 const SizeGetter &get_size,
152 const VectorFloatGetter &get_vector_float
153#
if OCIO_VERSION_HEX >= 0x02050000
161 if (!resource_names_.add(std::make_unique<std::string>(name))) {
168 std::string &resource_name = *resource_names_[resource_names_.size() - 1];
169 shader_create_info_.uniform_buf(buffers_sizes_.size(),
"float", resource_name);
171 float_buffers_.add(resource_name, get_vector_float);
172 buffers_sizes_.add(resource_name, get_size);
178 const SizeGetter &get_size,
179 const VectorIntGetter &get_vector_int
180#
if OCIO_VERSION_HEX >= 0x02050000
188 if (!resource_names_.add(std::make_unique<std::string>(name))) {
195 std::string &resource_name = *resource_names_[resource_names_.size() - 1];
196 shader_create_info_.uniform_buf(buffers_sizes_.size(),
"int", resource_name);
198 int_buffers_.add(name, get_vector_int);
199 buffers_sizes_.add(name, get_size);
204#if OCIO_VERSION_HEX >= 0x02050000
210 const char *sampler_name,
214#
if OCIO_VERSION_HEX >= 0x02030000
215 OCIO::GpuShaderDesc::TextureDimensions dimensions,
217 OCIO::Interpolation interpolation,
218 const float *values)
override
221 if (!resource_names_.add(std::make_unique<std::string>(sampler_name))) {
227 const std::string &resource_name = *resource_names_[resource_names_.size() - 1];
231 gpu::TextureFormat::SFLOAT_32_32_32 :
232 gpu::TextureFormat::SFLOAT_32;
235#if OCIO_VERSION_HEX >= 0x02030000
236 if (dimensions == OCIO::GpuShaderDesc::TEXTURE_1D)
243 shader_create_info_.sampler(textures_.size() + 1, ImageType::Float1D, resource_name);
248 shader_create_info_.sampler(textures_.size() + 1, ImageType::Float2D, resource_name);
252 textures_.add(sampler_name,
texture);
253#if OCIO_VERSION_HEX >= 0x02050000
254 return textures_.size() - 1;
258#if OCIO_VERSION_HEX >= 0x02050000
264 const char *sampler_name,
266 OCIO::Interpolation interpolation,
267 const float *values)
override
270 if (!resource_names_.add(std::make_unique<std::string>(sampler_name))) {
276 const std::string &resource_name = *resource_names_[resource_names_.size() - 1];
277 shader_create_info_.sampler(textures_.size() + 1, ImageType::Float3D, resource_name);
290 textures_.add(sampler_name,
texture);
291#if OCIO_VERSION_HEX >= 0x02050000
292 return textures_.size() - 1;
300#
if OCIO_VERSION_HEX >= 0x02050000
303 const char *helper_methods,
304 const char *function_header,
305 const char *function_body,
306 const char *function_footer)
override
308 shader_code_ += helper_methods;
309 shader_code_ += function_header;
310 shader_code_ += function_body;
311 shader_code_ += function_footer;
319 GpuShaderCreator::finalize();
321 shader_create_info_.local_group_size(16, 16);
324 shader_create_info_.push_constant(
Type::bool_t,
"premultiply_output");
325 shader_create_info_.image(0,
328 ImageReadWriteType::Float2D,
330 shader_create_info_.compute_source(
"gpu_shader_compositor_ocio_processor.glsl");
331 shader_create_info_.generated_sources.append(
332 {
"gpu_shader_compositor_ocio_processor_lib.glsl",
336 GPUShaderCreateInfo *info =
reinterpret_cast<GPUShaderCreateInfo *
>(&shader_create_info_);
348 for (
auto item : float_uniforms_.items()) {
352 for (
auto item : boolean_uniforms_.items()) {
356 for (
auto item : vector_uniforms_.items()) {
360 for (
auto item : float_buffers_.items()) {
362 buffers_sizes_.lookup(item.key)(), item.value(), item.key.c_str());
365 uniform_buffers_.append(buffer);
368 for (
auto item : int_buffers_.items()) {
370 buffers_sizes_.lookup(item.key)(), item.value(), item.key.c_str());
373 uniform_buffers_.append(buffer);
376 for (
auto item : textures_.items()) {
425 std::string shader_code_;
456#if OCIO_VERSION_HEX >= 0x02030000
458 bool allow_texture_1D_ =
true;
500 OCIO::ConstConfigRcPtr config = OCIO::GetCurrentConfig();
501 OCIO::ConstProcessorRcPtr processor = config->getProcessor(source.c_str(), target.c_str());
502 OCIO::ConstGPUProcessorRcPtr gpu_processor = processor->getDefaultGPUProcessor();
504 auto ocio_shader_creator = std::static_pointer_cast<OCIO::GpuShaderCreator>(shader_creator_);
505 gpu_processor->extractGpuShaderInfo(ocio_shader_creator);
507 catch (
const OCIO::Exception &
e) {
508 CLOG_ERROR(&
LOG,
"Failed to create OpenColorIO shader: %s",
e.what());
514 return shader_creator_->bind_shader_and_resources();
519 shader_creator_->unbind_shader_and_resources();
524 return shader_creator_->input_sampler_name();
529 return shader_creator_->output_image_name();
539 map_.remove_if([](
auto item) {
return !item.value->needed; });
543 for (
auto &value : map_.values()) {
544 value->needed =
false;
553 std::string config_cache_id = OCIO::GetCurrentConfig()->getCacheID();
558 return std::make_unique<OCIOColorSpaceConversionShader>(context, source, target);
610 OCIO::ConstConfigRcPtr config = OCIO::GetCurrentConfig();
620 group->setDirection(OCIO::TRANSFORM_DIR_INVERSE);
623 OCIO::ConstProcessorRcPtr processor = config->getProcessor(group);
624 OCIO::ConstGPUProcessorRcPtr gpu_processor = processor->getDefaultGPUProcessor();
626 auto ocio_shader_creator = std::static_pointer_cast<OCIO::GpuShaderCreator>(shader_creator_);
627 gpu_processor->extractGpuShaderInfo(ocio_shader_creator);
629 catch (
const OCIO::Exception &
e) {
630 CLOG_ERROR(&
LOG,
"Failed to create OpenColorIO shader: %s",
e.what());
636 return shader_creator_->bind_shader_and_resources();
641 shader_creator_->unbind_shader_and_resources();
646 return shader_creator_->input_sampler_name();
651 return shader_creator_->output_image_name();
661 map_.remove_if([](
auto item) {
return !item.value->needed; });
665 for (
auto &value : map_.values()) {
666 value->needed =
false;
677 std::string config_cache_id = OCIO::GetCurrentConfig()->getCacheID();
682 return std::make_unique<OCIOToDisplayShader>(
683 context, display_settings, view_settings,
inverse);
#define CLOG_ERROR(clg_ref,...)
#define BLI_assert_unreachable()
void add3DTexture(const char *texture_name, const char *sampler_name, uint size, OCIO::Interpolation interpolation, const float *values) override
const char * output_image_name()
const char * input_sampler_name()
bool addUniform(const char *name, const SizeGetter &get_size, const VectorFloatGetter &get_vector_float) override
bool addUniform(const char *name, const SizeGetter &get_size, const VectorIntGetter &get_vector_int) override
bool addUniform(const char *name, const Float3Getter &get_float3) override
OCIO::GpuShaderCreatorRcPtr clone() const override
void setTextureMaxWidth(uint) override
void unbind_shader_and_resources()
bool addUniform(const char *name, const BoolGetter &get_bool) override
bool addUniform(const char *name, const DoubleGetter &get_double) override
void addTexture(const char *texture_name, const char *sampler_name, uint width, uint height, TextureType channel, OCIO::Interpolation interpolation, const float *values) override
gpu::Shader * bind_shader_and_resources()
void createShaderText(const char *, const char *helper_methods, const char *function_header, const char *function_body, const char *function_footer) override
~GPUShaderCreator() override
static std::shared_ptr< GPUShaderCreator > Create(ResultPrecision precision)
uint getTextureMaxWidth() const noexcept override
OCIOColorSpaceConversionShader & get(Context &context, std::string source, std::string target)
OCIOColorSpaceConversionShaderKey(const std::string &source, const std::string &target, const std::string &config_cache_id)
std::string config_cache_id
void unbind_shader_and_resources()
const char * input_sampler_name()
gpu::Shader * bind_shader_and_resources()
const char * output_image_name()
OCIOColorSpaceConversionShader(Context &context, std::string source, std::string target)
OCIOToDisplayShader & get(Context &context, const ColorManagedDisplaySettings &display_settings, const ColorManagedViewSettings &view_settings, const bool inverse)
std::string view_transform
std::string config_cache_id
std::string display_device
OCIOToDisplayShaderKey(const ColorManagedDisplaySettings &display_settings, const ColorManagedViewSettings &view_settings, const bool inverse, const std::string &config_cache_id)
const char * input_sampler_name()
const char * output_image_name()
void unbind_shader_and_resources()
gpu::Shader * bind_shader_and_resources()
OCIOToDisplayShader(Context &context, const ColorManagedDisplaySettings &display_settings, const ColorManagedViewSettings &view_settings, const bool inverse)
static gpu::TextureFormat gpu_texture_format(ResultType type, ResultPrecision precision)
MatBase< C, R > inverse(MatBase< C, R >) RET
TEX_TEMPLATE DataVec texture(T, FltCoord, float=0.0f) RET
bool operator==(const BokehKernelKey &a, const BokehKernelKey &b)
OCIO_NAMESPACE::TransformRcPtr create_ocio_display_transform(const OCIO_NAMESPACE::ConstConfigRcPtr &ocio_config, StringRefNull display, StringRefNull view, StringRefNull look, StringRefNull from_colorspace)
int GPU_shader_get_sampler_binding(gpu::Shader *shader, const char *name)
unsigned __int64 uint64_t
gpu::Texture * GPU_texture_create_1d(const char *name, int width, int mip_len, gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
void GPU_uniformbuf_free(gpu::UniformBuf *ubo)
std::string GPU_shader_preprocess_source(StringRefNull original, gpu::shader::ShaderCreateInfo &info)
gpu::Shader * GPU_shader_create_from_info(const GPUShaderCreateInfo *_info)
int GPU_max_texture_size()
void GPU_shader_uniform_1b(gpu::Shader *sh, const char *name, bool value)
@ GPU_TEXTURE_USAGE_SHADER_READ
void GPU_shader_uniform_3fv(gpu::Shader *sh, const char *name, const float data[3])
void GPU_texture_filter_mode(gpu::Texture *texture, bool use_filter)
gpu::Texture * GPU_texture_create_3d(const char *name, int width, int height, int depth, int mip_len, gpu::TextureFormat format, eGPUTextureUsage usage, const void *data)
void GPU_shader_bind(gpu::Shader *shader, const gpu::shader::SpecializationConstants *constants_state=nullptr)
void GPU_uniformbuf_bind(gpu::UniformBuf *ubo, int slot)
gpu::UniformBuf * GPU_uniformbuf_create_ex(size_t size, const void *data, const char *name)
void GPU_shader_uniform_1f(gpu::Shader *sh, const char *name, float value)
void GPU_texture_bind(gpu::Texture *texture, int unit)
void GPU_texture_free(gpu::Texture *texture)
int GPU_shader_get_ubo_binding(gpu::Shader *shader, const char *name)
void GPU_texture_unbind(gpu::Texture *texture)
void GPU_shader_free(gpu::Shader *shader)
void GPU_uniformbuf_unbind(gpu::UniformBuf *ubo)
constexpr uint64_t get_default_hash(const T &v, const Args &...args)
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
gpu::Texture * GPU_texture_create_2d(const char *name, int width, int height, int mip_len, gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
Describe inputs & outputs, stage interfaces, resources and sources of a shader. If all data is correc...
ShaderCreateInfo(const char *name)