57 return (
dummy !=
nullptr);
93 if (!use_curve_mapping) {
100 blender::gpu::TextureFormat::SFLOAT_16_16_16_16,
135 this->view == display_parameters.
view && this->display == display_parameters.
display &&
144 if (!
textures.initialize_common()) {
170 for (std::list<GPUDisplayShader>::iterator it = cache_.begin(); it != cache_.end(); it++) {
171 if (it->matches(display_parameters)) {
173 if (it != cache_.begin()) {
174 cache_.splice(cache_.begin(), cache_, it);
185 while (cache_.size() >= MAX_SIZE) {
190 cache_.emplace_front();
192 return cache_.front();
216static void process_source(std::string &source)
230 source,
"if ( gamma != vec3(1., 1., 1.) )",
"if (! all(equal(gamma, vec3(1., 1., 1.))) )");
233static void gpu_curve_mapping_update(internal::GPUCurveMappping &gpu_curve_mapping,
239 const size_t cache_id = size_t(&curve_mapping) + curve_mapping.
changed_timestamp;
240 if (gpu_curve_mapping.cache_id == cache_id) {
243 gpu_curve_mapping.cache_id = cache_id;
246 const int offset[3] = {0, 0, 0};
247 const int extent[3] = {gpu_curve_mapping.lut_size, 0, 0};
250 gpu_curve_mapping.lut,
255 OCIO_GPUCurveMappingParameters
data;
256 for (
int i = 0;
i < 4;
i++) {
269 for (
int i = 0;
i < 3;
i++) {
273 data.lut_size = gpu_curve_mapping.lut_size;
283 bool do_update =
false;
284 if (display_shader.parameters_buffer ==
nullptr) {
289 OCIO_GPUParameters &
data = display_shader.parameters;
290 if (
data.scene_linear_matrix != scene_linear_matrix) {
291 data.scene_linear_matrix = scene_linear_matrix;
294 if (
data.exponent != display_parameters.exponent) {
295 data.exponent = display_parameters.exponent;
298 if (
data.dither != display_parameters.dither) {
299 data.dither = display_parameters.dither;
302 if (
bool(
data.use_predivide) != display_parameters.use_predivide) {
303 data.use_predivide = display_parameters.use_predivide;
306 if (
bool(
data.do_overlay_merge) != display_parameters.do_overlay_merge) {
307 data.do_overlay_merge = display_parameters.do_overlay_merge;
310 if (
bool(
data.use_hdr_display) != display_parameters.use_hdr_display) {
311 data.use_hdr_display = display_parameters.use_hdr_display;
321static bool gpu_shader_bind(
const Config &config,
329 if (!display_shader.is_valid) {
334 if (display_parameters.curve_mapping) {
335 gpu_curve_mapping_update(display_shader.curve_mapping, *display_parameters.curve_mapping);
336 GPU_uniformbuf_bind(display_shader.curve_mapping.buffer, UniformBufferSlot::CURVE_MAPPING);
337 GPU_texture_bind(display_shader.curve_mapping.texture, TextureSlot::CURVE_MAPPING);
344 if (!display_parameters.do_overlay_merge) {
348 for (
int i = 0;
i < display_shader.textures.luts.size();
i++) {
349 GPU_texture_bind(display_shader.textures.luts[
i].texture, TextureSlot::LUTS_OFFSET +
i);
352 if (display_shader.textures.uniforms_buffer) {
357 if (display_parameters.use_white_balance) {
359 config, display_parameters.temperature, display_parameters.tint);
362 gpu_display_shader_parameters_update(display_shader, display_parameters,
float4x4(matrix));
376 : display_cache_(std::make_unique<
internal::GPUShaderCache>()),
377 scene_linear_cache_(std::make_unique<
internal::GPUShaderCache>()),
391 if (!display_shader) {
392 display_shader = &display_cache_->create_default();
396 display_shader->
view = display_parameters.
view;
398 display_shader->
look = display_parameters.
look;
420 return gpu_shader_bind(
config_, *display_shader, display_parameters);
424 const bool use_predivide)
const
439 shader = &scene_linear_cache_->create_default();
449 return gpu_shader_bind(
config_, *shader, display_parameters);
460 const Span<std::array<StringRefNull, 2>> additional_defines)
469 for (
const auto &additional_define : additional_defines) {
470 info.
define(additional_define[0], additional_define[1]);
474 info.
define(
"texture1D",
"texture");
475 info.
define(
"texture2D",
"texture");
476 info.
define(
"texture3D",
"texture");
492 info.
vertex_source(
"gpu_shader_display_transform_vert.glsl");
504 info.
define(
"USE_CURVE_MAPPING");
506 "OCIO_GPUCurveMappingParameters",
516 const ImageType type = (dimensions == 1) ? ImageType::Float1D :
517 (dimensions == 2) ? ImageType::Float2D :
523#if defined(WITH_OPENCOLORIO)
530 uint32_t *ubo_data =
reinterpret_cast<uint32_t *
>(ubo_data_buf.
data());
532 std::stringstream ss;
533 ss <<
"struct OCIO_GPULutParameters {\n";
538 const OCIO_NAMESPACE::GpuShaderDesc::UniformData &
data = uniform.data;
539 const char *
name = uniform.
name.c_str();
542 switch (
data.m_type) {
543 case OCIO_NAMESPACE::UNIFORM_DOUBLE: {
546 memcpy(ubo_data, &value,
sizeof(
float));
549 case OCIO_NAMESPACE::UNIFORM_BOOL: {
552 int value = int(
data.m_getBool());
553 memcpy(ubo_data, &value,
sizeof(
int));
556 case OCIO_NAMESPACE::UNIFORM_FLOAT3:
558 memcpy(ubo_data,
data.m_getFloat3().data(),
sizeof(
float) * 3);
560 case OCIO_NAMESPACE::UNIFORM_VECTOR_FLOAT:
561 vec_len =
data.m_vectorFloat.m_getSize();
562 memcpy(ubo_data,
data.m_vectorFloat.m_getVector(),
sizeof(
float) * vec_len);
564 case OCIO_NAMESPACE::UNIFORM_VECTOR_INT:
566 vec_len =
data.m_vectorInt.m_getSize();
567 memcpy(ubo_data,
data.m_vectorInt.m_getVector(),
sizeof(
int) * vec_len);
576 ss <<
" " << prefix <<
"vec4 var" << index <<
";\n";
579 ss <<
"#define " <<
name <<
" lut_parameters.var" << index <<
"." << suffix <<
"\n";
587 ubo_size, ubo_data_buf.
data(),
"OCIO_LutParameters");
592 reinterpret_cast<GPUShaderCreateInfo *
>(&info));
594 return (display_shader.
shader !=
nullptr);
599 scene_linear_cache_->clear();
600 display_cache_->clear();
void BLI_string_replace(std::string &haystack, blender::StringRef needle, blender::StringRef other)
@ CUMA_EXTEND_EXTRAPOLATE
void GPU_shader_free(blender::gpu::Shader *shader)
blender::gpu::Shader * GPU_shader_create_from_info(const GPUShaderCreateInfo *_info)
std::string GPU_shader_preprocess_source(blender::StringRefNull original)
void GPU_texture_update_sub(blender::gpu::Texture *texture, eGPUDataFormat data_format, const void *pixels, int offset_x, int offset_y, int offset_z, int width, int height, int depth)
void GPU_texture_extend_mode(blender::gpu::Texture *texture, GPUSamplerExtendMode extend_mode)
@ GPU_TEXTURE_USAGE_SHADER_READ
@ GPU_SAMPLER_EXTEND_MODE_EXTEND
int GPU_texture_dimensions(const blender::gpu::Texture *texture)
void GPU_texture_filter_mode(blender::gpu::Texture *texture, bool use_filter)
void GPU_texture_bind(blender::gpu::Texture *texture, int unit)
blender::gpu::Texture * GPU_texture_create_error(int dimension, bool array)
void GPU_texture_free(blender::gpu::Texture *texture)
blender::gpu::Texture * GPU_texture_create_1d(const char *name, int width, int mip_len, blender::gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
Read Guarded memory(de)allocation.
BMesh const char void * data
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)
blender::gpu::Texture * texture
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()
blender::gpu::Texture * dummy
Vector< GPUUniform > uniforms
Vector< GPULutTexture > luts
gpu::UniformBuf * uniforms_buffer
TEX_TEMPLATE DataVec texture(T, FltCoord, float=0.0f) RET
void MEM_freeN(void *vmemh)
float3x3 calculate_white_point_matrix(const Config &config, const float temperature, const float tint)
void source_comment_out_uniforms(std::string &source)
MatBase< float, 4, 4 > float4x4
MatBase< float, 3, 3 > float3x3
Describe inputs & outputs, stage interfaces, resources and sources of a shader. If all data is correc...
Self & fragment_source(StringRefNull filename)
std::string fragment_source_generated
Self & vertex_in(int slot, Type type, StringRefNull name)
Self & push_constant(Type type, StringRefNull name, int array_size=0)
Self & typedef_source(StringRefNull filename)
Self & fragment_out(int slot, Type type, StringRefNull name, DualBlend blend=DualBlend::NONE, int raster_order_group=-1)
Self & vertex_out(StageInterfaceInfo &interface)
std::string typedef_source_generated
Self & vertex_source(StringRefNull filename)
Self & sampler(int slot, ImageType type, StringRefNull name, Frequency freq=Frequency::PASS, GPUSamplerState sampler=GPUSamplerState::internal_sampler())
Self & uniform_buf(int slot, StringRefNull type_name, StringRefNull name, Frequency freq=Frequency::PASS)
Self & define(StringRefNull name, StringRefNull value="")
Self & smooth(Type type, StringRefNull _name)
static MatBase identity()
bool use_display_emulation
CurveMapping * curve_mapping
StringRefNull from_colorspace