28# include <OpenColorIO/OpenColorIO.h>
60namespace OCIO = OCIO_NAMESPACE;
76class GPUShaderCreator :
public OCIO::GpuShaderCreator {
80 std::shared_ptr<GPUShaderCreator>
instance = std::make_shared<GPUShaderCreator>();
81 instance->setLanguage(OCIO::GPU_LANGUAGE_GLSL_4_0);
87 OCIO::GpuShaderCreatorRcPtr clone()
const override
89 return OCIO::GpuShaderCreatorRcPtr();
93 void setTextureMaxWidth(
uint )
override {}
95 uint getTextureMaxWidth() const noexcept
override
100# if OCIO_VERSION_HEX >= 0x02030000
101 void setAllowTexture1D(
bool allowed)
override
103 allow_texture_1D_ = allowed;
106 bool getAllowTexture1D()
const override
108 return allow_texture_1D_;
112 bool addUniform(
const char *name,
const DoubleGetter &get_double)
override
116 if (!resource_names_.add(std::make_unique<std::string>(name))) {
123 std::string &resource_name = *resource_names_[resource_names_.size() - 1];
124 shader_create_info_.push_constant(Type::FLOAT, resource_name);
126 float_uniforms_.add(resource_name, get_double);
131 bool addUniform(
const char *name,
const BoolGetter &get_bool)
override
135 if (!resource_names_.add(std::make_unique<std::string>(name))) {
142 const std::string &resource_name = *resource_names_[resource_names_.size() - 1];
143 shader_create_info_.push_constant(Type::BOOL, resource_name);
145 boolean_uniforms_.add(name, get_bool);
150 bool addUniform(
const char *name,
const Float3Getter &
get_float3)
override
154 if (!resource_names_.add(std::make_unique<std::string>(name))) {
161 std::string &resource_name = *resource_names_[resource_names_.size() - 1];
162 shader_create_info_.push_constant(Type::VEC3, resource_name);
164 vector_uniforms_.add(resource_name,
get_float3);
169 bool addUniform(
const char *name,
170 const SizeGetter &get_size,
171 const VectorFloatGetter &get_vector_float)
override
175 if (!resource_names_.add(std::make_unique<std::string>(name))) {
182 std::string &resource_name = *resource_names_[resource_names_.size() - 1];
183 shader_create_info_.uniform_buf(buffers_sizes_.size(),
"float", resource_name);
185 float_buffers_.add(resource_name, get_vector_float);
186 buffers_sizes_.add(resource_name, get_size);
191 bool addUniform(
const char *name,
192 const SizeGetter &get_size,
193 const VectorIntGetter &get_vector_int)
override
197 if (!resource_names_.add(std::make_unique<std::string>(name))) {
204 std::string &resource_name = *resource_names_[resource_names_.size() - 1];
205 shader_create_info_.uniform_buf(buffers_sizes_.size(),
"int", resource_name);
207 int_buffers_.add(name, get_vector_int);
208 buffers_sizes_.add(name, get_size);
213 void addTexture(
const char *texture_name,
214 const char *sampler_name,
218#
if OCIO_VERSION_HEX >= 0x02030000
219 OCIO::GpuShaderDesc::TextureDimensions dimensions,
221 OCIO::Interpolation interpolation,
222 const float *values)
override
225 if (!resource_names_.add(std::make_unique<std::string>(sampler_name))) {
231 const std::string &resource_name = *resource_names_[resource_names_.size() - 1];
238# if OCIO_VERSION_HEX >= 0x02030000
239 if (dimensions == OCIO::GpuShaderDesc::TEXTURE_1D) {
245 shader_create_info_.sampler(textures_.size() + 1, ImageType::FLOAT_1D, resource_name);
250 shader_create_info_.sampler(textures_.size() + 1, ImageType::FLOAT_2D, resource_name);
254 textures_.add(sampler_name,
texture);
257 void add3DTexture(
const char *texture_name,
258 const char *sampler_name,
260 OCIO::Interpolation interpolation,
261 const float *values)
override
264 if (!resource_names_.add(std::make_unique<std::string>(sampler_name))) {
270 const std::string &resource_name = *resource_names_[resource_names_.size() - 1];
271 shader_create_info_.sampler(textures_.size() + 1, ImageType::FLOAT_3D, resource_name);
284 textures_.add(sampler_name,
texture);
290 void createShaderText(
const char * ,
291 const char *helper_methods,
292 const char *function_header,
293 const char *function_body,
294 const char *function_footer)
override
296 shader_code_ += helper_methods;
297 shader_code_ += function_header;
298 shader_code_ += function_body;
299 shader_code_ += function_footer;
305 void finalize()
override
307 GpuShaderCreator::finalize();
309 shader_create_info_.local_group_size(16, 16);
311 shader_create_info_.image(0,
316 shader_create_info_.compute_source(
"gpu_shader_compositor_ocio_processor.glsl");
317 shader_create_info_.compute_source_generated += shader_code_;
319 GPUShaderCreateInfo *info =
reinterpret_cast<GPUShaderCreateInfo *
>(&shader_create_info_);
331 for (
auto item : float_uniforms_.items()) {
335 for (
auto item : boolean_uniforms_.items()) {
339 for (
auto item : vector_uniforms_.items()) {
343 for (
auto item : float_buffers_.items()) {
345 buffers_sizes_.lookup(item.key)(), item.value(), item.key.c_str());
348 uniform_buffers_.append(buffer);
351 for (
auto item : int_buffers_.items()) {
353 buffers_sizes_.lookup(item.key)(), item.value(), item.key.c_str());
356 uniform_buffers_.append(buffer);
359 for (
auto item : textures_.items()) {
369 for (GPUUniformBuf *buffer : uniform_buffers_) {
374 for (GPUTexture *
texture : textures_.values()) {
391 ~GPUShaderCreator()
override
393 for (GPUTexture *
texture : textures_.values()) {
404 ShaderCreateInfo shader_create_info_ = ShaderCreateInfo(
"OCIO Processor");
408 std::string shader_code_;
433 VectorSet<std::unique_ptr<std::string>> resource_names_;
439# if OCIO_VERSION_HEX >= 0x02030000
441 bool allow_texture_1D_ =
true;
455 return std::make_shared<GPUShaderCreator>();
490#if defined(WITH_OCIO)
493 OCIO::ConstConfigRcPtr config = OCIO::GetCurrentConfig();
494 OCIO::ConstProcessorRcPtr processor = config->getProcessor(source.c_str(), target.c_str());
495 OCIO::ConstGPUProcessorRcPtr gpu_processor = processor->getDefaultGPUProcessor();
497 auto ocio_shader_creator = std::static_pointer_cast<OCIO::GpuShaderCreator>(shader_creator_);
498 gpu_processor->extractGpuShaderInfo(ocio_shader_creator);
500 catch (
const OCIO::Exception &) {
509 return shader_creator_->bind_shader_and_resources();
514 shader_creator_->unbind_shader_and_resources();
519 return shader_creator_->input_sampler_name();
524 return shader_creator_->output_image_name();
534 map_.remove_if([](
auto item) {
return !item.value->needed; });
538 for (
auto &value : map_.values()) {
539 value->needed =
false;
547#if defined(WITH_OCIO)
549 std::string config_cache_id = OCIO::GetCurrentConfig()->getCacheID();
551 std::string config_cache_id;
557 return std::make_unique<OCIOColorSpaceConversionShader>(context, source, target);
#define BLI_assert_unreachable()
int GPU_max_texture_size()
int GPU_shader_get_sampler_binding(GPUShader *shader, const char *name)
int GPU_shader_get_ubo_binding(GPUShader *shader, const char *name)
void GPU_shader_uniform_1f(GPUShader *sh, const char *name, float value)
void GPU_shader_uniform_3fv(GPUShader *sh, const char *name, const float data[3])
void GPU_shader_bind(GPUShader *shader)
void GPU_shader_uniform_1b(GPUShader *sh, const char *name, bool value)
GPUShader * GPU_shader_create_from_info(const GPUShaderCreateInfo *_info)
void GPU_shader_free(GPUShader *shader)
void GPU_texture_bind(GPUTexture *texture, int unit)
GPUTexture * GPU_texture_create_2d(const char *name, int width, int height, int mip_len, eGPUTextureFormat format, eGPUTextureUsage usage, const float *data)
GPUTexture * GPU_texture_create_1d(const char *name, int width, int mip_len, eGPUTextureFormat format, eGPUTextureUsage usage, const float *data)
void GPU_texture_free(GPUTexture *texture)
void GPU_texture_unbind(GPUTexture *texture)
@ GPU_TEXTURE_USAGE_SHADER_READ
GPUTexture * GPU_texture_create_3d(const char *name, int width, int height, int depth, int mip_len, eGPUTextureFormat format, eGPUTextureUsage usage, const void *data)
void GPU_texture_filter_mode(GPUTexture *texture, bool use_filter)
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object instance
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Map
struct GPUShader GPUShader
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
static std::shared_ptr< GPUShaderCreator > Create(ResultPrecision)
void unbind_shader_and_resources()
GPUShader * bind_shader_and_resources()
const char * input_sampler_name()
const char * output_image_name()
OCIOColorSpaceConversionShader & get(Context &context, std::string source, std::string target)
std::string config_cache_id
OCIOColorSpaceConversionShaderKey(const std::string &source, const std::string &target, const std::string &config_cache_id)
const char * input_sampler_name()
const char * output_image_name()
OCIOColorSpaceConversionShader(Context &context, std::string source, std::string target)
void unbind_shader_and_resources()
GPUShader * bind_shader_and_resources()
static eGPUTextureFormat gpu_texture_format(ResultType type, ResultPrecision precision)
local_group_size(16, 16) .push_constant(Type b
local_group_size(16, 16) .push_constant(Type texture
static float3 get_float3(const BL::Array< float, 2 > &array)
bool operator==(const BokehKernelKey &a, const BokehKernelKey &b)
uint64_t get_default_hash(const T &v)
unsigned __int64 uint64_t