58 return (
dummy !=
nullptr);
94 if (!use_curve_mapping) {
101 gpu::TextureFormat::SFLOAT_16_16_16_16,
136 this->view == display_parameters.
view && this->display == display_parameters.
display &&
172 for (std::list<GPUDisplayShader>::iterator it = cache_.begin(); it != cache_.end(); it++) {
173 if (it->matches(display_parameters)) {
175 if (it != cache_.begin()) {
176 cache_.splice(cache_.begin(), cache_, it);
187 while (cache_.size() >= MAX_SIZE) {
192 cache_.emplace_front();
194 return cache_.front();
220 std::string res_declarations;
222 res_declarations +=
"#ifdef CREATE_INFO_RES_PASS_OCIO_Display\n";
223 res_declarations +=
"CREATE_INFO_RES_PASS_OCIO_Display\n";
224 res_declarations +=
"#endif\n";
225 res_declarations +=
"#ifdef CREATE_INFO_RES_BATCH_OCIO_Display\n";
226 res_declarations +=
"CREATE_INFO_RES_BATCH_OCIO_Display\n";
227 res_declarations +=
"#endif\n";
228 res_declarations +=
"#ifdef CREATE_INFO_RES_GEOMETRY_OCIO_Display\n";
229 res_declarations +=
"CREATE_INFO_RES_GEOMETRY_OCIO_Display\n";
230 res_declarations +=
"#endif\n";
231 res_declarations +=
"\n";
245 source,
"if ( gamma != vec3(1., 1., 1.) )",
"if (! all(equal(gamma, vec3(1., 1., 1.))) )");
250static void gpu_curve_mapping_update(internal::GPUCurveMappping &gpu_curve_mapping,
256 const size_t cache_id = size_t(&curve_mapping) + curve_mapping.
changed_timestamp;
257 if (gpu_curve_mapping.cache_id == cache_id) {
260 gpu_curve_mapping.cache_id = cache_id;
263 const int offset[3] = {0, 0, 0};
264 const int extent[3] = {gpu_curve_mapping.lut_size, 0, 0};
267 gpu_curve_mapping.lut,
272 OCIO_GPUCurveMappingParameters
data;
273 for (
int i = 0; i < 4; i++) {
274 const CurveMap &curve_map = curve_mapping.
cm[i];
275 data.range[i] = curve_map.range;
276 data.mintable[i] = curve_map.mintable;
277 data.ext_in_x[i] = curve_map.ext_in[0];
278 data.ext_in_y[i] = curve_map.ext_in[1];
279 data.ext_out_x[i] = curve_map.ext_out[0];
280 data.ext_out_y[i] = curve_map.ext_out[1];
281 data.first_x[i] = curve_map.table[0].x;
282 data.first_y[i] = curve_map.table[0].y;
286 for (
int i = 0; i < 3; i++) {
290 data.lut_size = gpu_curve_mapping.lut_size;
300 bool do_update =
false;
301 if (display_shader.parameters_buffer ==
nullptr) {
306 OCIO_GPUParameters &
data = display_shader.parameters;
307 if (
data.scene_linear_matrix != scene_linear_matrix) {
308 data.scene_linear_matrix = scene_linear_matrix;
311 if (
data.exponent != display_parameters.exponent) {
312 data.exponent = display_parameters.exponent;
315 if (
data.dither != display_parameters.dither) {
316 data.dither = display_parameters.dither;
319 if (
data.opacity != display_parameters.opacity) {
320 data.opacity = display_parameters.opacity;
323 if (
bool(
data.use_predivide) != display_parameters.use_predivide) {
324 data.use_predivide = display_parameters.use_predivide;
327 if (
bool(
data.do_overlay_merge) != display_parameters.do_overlay_merge) {
328 data.do_overlay_merge = display_parameters.do_overlay_merge;
331 if (
bool(
data.use_hdr_display) != display_parameters.use_hdr_display) {
332 data.use_hdr_display = display_parameters.use_hdr_display;
342static bool gpu_shader_bind(
const Config &config,
350 if (!display_shader.is_valid) {
355 if (display_parameters.curve_mapping) {
356 gpu_curve_mapping_update(display_shader.curve_mapping, *display_parameters.curve_mapping);
357 GPU_uniformbuf_bind(display_shader.curve_mapping.buffer, UniformBufferSlot::CURVE_MAPPING);
358 GPU_texture_bind(display_shader.curve_mapping.texture, TextureSlot::CURVE_MAPPING);
365 if (!display_parameters.do_overlay_merge) {
369 for (
int i = 0; i < display_shader.textures.luts.size(); i++) {
370 GPU_texture_bind(display_shader.textures.luts[i].texture, TextureSlot::LUTS_OFFSET + i);
373 if (display_shader.textures.uniforms_buffer) {
378 if (display_parameters.use_white_balance) {
380 config, display_parameters.temperature, display_parameters.tint);
383 gpu_display_shader_parameters_update(display_shader, display_parameters,
float4x4(matrix));
397 : display_cache_(std::make_unique<
internal::GPUShaderCache>()),
398 scene_linear_cache_(std::make_unique<
internal::GPUShaderCache>()),
412 if (!display_shader) {
413 display_shader = &display_cache_->create_default();
417 display_shader->
view = display_parameters.
view;
419 display_shader->
look = display_parameters.
look;
442 return gpu_shader_bind(
config_, *display_shader, display_parameters);
446 const bool use_predivide)
const
461 shader = &scene_linear_cache_->create_default();
466 if (
shader->initialize_common()) {
471 return gpu_shader_bind(
config_, *
shader, display_parameters);
482 const Span<std::array<StringRefNull, 2>> additional_defines)
492 for (
const auto &additional_define : additional_defines) {
493 info.
define(additional_define[0], additional_define[1]);
497 info.
define(
"texture1D",
"texture");
498 info.
define(
"texture2D",
"texture");
499 info.
define(
"texture3D",
"texture");
515 info.
vertex_source(
"gpu_shader_display_transform_vert.glsl");
519 {
"gpu_shader_display_transform_lib.glsl",
520 {
"gpu_shader_display_transform_fallback_lib.glsl",
"ocio_shader_shared.hh"},
521 process_source(fragment_source, info)});
529 info.
define(
"USE_CURVE_MAPPING");
531 "OCIO_GPUCurveMappingParameters",
541 const ImageType type = (dimensions == 1) ? ImageType::Float1D :
542 (dimensions == 2) ? ImageType::Float2D :
556 std::stringstream ss;
557 ss <<
"struct OCIO_GPULutParameters {\n";
562 const OCIO_NAMESPACE::GpuShaderDesc::UniformData &
data =
uniform.data;
563 const char *name =
uniform.name.c_str();
566 switch (
data.m_type) {
567 case OCIO_NAMESPACE::UNIFORM_DOUBLE: {
570 memcpy(ubo_data, &value,
sizeof(
float));
573 case OCIO_NAMESPACE::UNIFORM_BOOL: {
576 int value = int(
data.m_getBool());
577 memcpy(ubo_data, &value,
sizeof(
int));
580 case OCIO_NAMESPACE::UNIFORM_FLOAT3:
582 memcpy(ubo_data,
data.m_getFloat3().data(),
sizeof(
float) * 3);
584 case OCIO_NAMESPACE::UNIFORM_VECTOR_FLOAT:
585 vec_len =
data.m_vectorFloat.m_getSize();
586 memcpy(ubo_data,
data.m_vectorFloat.m_getVector(),
sizeof(
float) * vec_len);
588 case OCIO_NAMESPACE::UNIFORM_VECTOR_INT:
590 vec_len =
data.m_vectorInt.m_getSize();
591 memcpy(ubo_data,
data.m_vectorInt.m_getVector(),
sizeof(
int) * vec_len);
600 ss <<
" " << prefix <<
"vec4 var" <<
index <<
";\n";
603 ss <<
"#define " << name <<
" lut_parameters.var" <<
index <<
"." << suffix <<
"\n";
611 ubo_size, ubo_data_buf.
data(),
"OCIO_LutParameters");
615 reinterpret_cast<GPUShaderCreateInfo *
>(&info));
617 return (display_shader.
shader !=
nullptr);
622 scene_linear_cache_->clear();
623 display_cache_->clear();
Read Blender memory allocation and freeing.
constexpr StringRefNull()
constexpr StringRef substr(int64_t start, int64_t size) const
virtual void construct_display_shader(internal::GPUDisplayShader &display_shader) const =0
virtual ~GPUShaderBinder()
static bool create_gpu_shader(internal::GPUDisplayShader &display_shader, StringRefNull fragment_source, Span< std::array< StringRefNull, 2 > > additional_defines)
void clear_caches() const
bool to_scene_linear_bind(StringRefNull from_colorspace, bool use_predivide) const
bool display_bind(const GPUDisplayParameters &display_parameters) const
virtual void construct_scene_linear_shader(internal::GPUDisplayShader &display_shader) const =0
GPUShaderBinder(const Config &config)
void rasterize(CurveMapping &curve_mapping)
bool initialize_common(bool use_curve_mapping)
bool matches(const GPUDisplayParameters &display_parameters) const
gpu::UniformBuf * parameters_buffer
std::string from_colorspace
bool use_display_emulation
GPUCurveMappping curve_mapping
GPUDisplayShader * get(const GPUDisplayParameters &display_parameters)
GPUDisplayShader & create_default()
Vector< GPUUniform > uniforms
Vector< GPULutTexture > luts
gpu::UniformBuf * uniforms_buffer
TEX_TEMPLATE DataVec texture(T, FltCoord, float=0.0f) RET
float3x3 calculate_white_point_matrix(const Config &config, const float temperature, const float tint)
void source_comment_out_uniforms(std::string &source)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
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)
GPUBackendType GPU_backend_get_type()
gpu::Shader * GPU_shader_create_from_info(const GPUShaderCreateInfo *_info)
@ GPU_SAMPLER_EXTEND_MODE_EXTEND
MatBase< float, 4, 4 > float4x4
void BKE_curvemapping_premultiply(CurveMapping *cumap, bool restore)
int GPU_texture_dimensions(const gpu::Texture *texture)
void GPU_texture_update_sub(gpu::Texture *texture, eGPUDataFormat data_format, const void *pixels, int offset_x, int offset_y, int offset_z, int width, int height, int depth, uint unpack_row_length=0)
void BKE_curvemapping_init(CurveMapping *cumap)
@ GPU_TEXTURE_USAGE_SHADER_READ
BMesh const char void * data
void GPU_texture_filter_mode(gpu::Texture *texture, bool use_filter)
void BKE_curvemapping_table_RGBA(const CurveMapping *cumap, float **array, int *size)
void GPU_uniformbuf_bind(gpu::UniformBuf *ubo, int slot)
MatBase< float, 3, 3 > float3x3
gpu::UniformBuf * GPU_uniformbuf_create_ex(size_t size, const void *data, const char *name)
void GPU_uniformbuf_update(gpu::UniformBuf *ubo, const void *data)
void GPU_texture_extend_mode(gpu::Texture *texture, GPUSamplerExtendMode extend_mode)
void GPU_texture_bind(gpu::Texture *texture, int unit)
void GPU_texture_free(gpu::Texture *texture)
void immBindShader(gpu::Shader *shader)
gpu::Texture * GPU_texture_create_error(int dimension, bool array)
void GPU_shader_free(gpu::Shader *shader)
void BLI_string_replace(std::string &haystack, StringRef needle, StringRef other)
@ CUMA_EXTEND_EXTRAPOLATE
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
static MatBase identity()
Describe inputs & outputs, stage interfaces, resources and sources of a shader. If all data is correc...
Self & uniform_buf(int slot, StringRefNull type_name, StringRefNull name, Frequency freq=Frequency::PASS, ConditionFn cond=nullptr)
Self & fragment_source(StringRefNull filename)
Self & vertex_in(int slot, Type type, StringRefNull name, ConditionFn cond=nullptr)
GeneratedSourceList generated_sources
Self & fragment_out(int slot, Type type, StringRefNull name, DualBlend blend=DualBlend::NONE, int raster_order_group=-1, ConditionFn cond=nullptr)
Self & typedef_source(StringRefNull filename)
std::string typedef_source_generated
Self & builtins(BuiltinBits builtin, ConditionFn cond=nullptr)
Self & vertex_source(StringRefNull filename)
Self & vertex_out(StageInterfaceInfo &interface, ConditionFn cond=nullptr)
Self & sampler(int slot, ImageType type, StringRefNull name, Frequency freq=Frequency::PASS, ConditionFn cond=nullptr)
Self & define(StringRefNull name, StringRefNull value="")
Self & push_constant(Type type, StringRefNull name, int array_size=0, ConditionFn cond=nullptr)
Self & smooth(Type type, StringRefNull _name)
bool use_display_emulation
CurveMapping * curve_mapping
StringRefNull from_colorspace