57 return (
dummy !=
nullptr);
93 if (!use_curve_mapping) {
137 if (!
textures.initialize_common()) {
163 for (std::list<GPUDisplayShader>::iterator it = cache_.begin(); it != cache_.end(); it++) {
164 if (it->matches(display_parameters)) {
166 if (it != cache_.begin()) {
167 cache_.splice(cache_.begin(), cache_, it);
178 while (cache_.size() >= MAX_SIZE) {
183 cache_.emplace_front();
185 return cache_.front();
209static void process_source(std::string &source)
223 source,
"if ( gamma != vec3(1., 1., 1.) )",
"if (! all(equal(gamma, vec3(1., 1., 1.))) )");
226static void gpu_curve_mapping_update(internal::GPUCurveMappping &gpu_curve_mapping,
232 const size_t cache_id = size_t(&curve_mapping) + curve_mapping.
changed_timestamp;
233 if (gpu_curve_mapping.cache_id == cache_id) {
236 gpu_curve_mapping.cache_id = cache_id;
239 const int offset[3] = {0, 0, 0};
240 const int extent[3] = {gpu_curve_mapping.lut_size, 0, 0};
243 gpu_curve_mapping.lut,
248 OCIO_GPUCurveMappingParameters
data;
249 for (
int i = 0;
i < 4;
i++) {
262 for (
int i = 0;
i < 3;
i++) {
266 data.lut_size = gpu_curve_mapping.lut_size;
277 if (display_shader.parameters_buffer ==
nullptr) {
282 OCIO_GPUParameters &
data = display_shader.parameters;
283 if (
data.scene_linear_matrix != scene_linear_matrix) {
284 data.scene_linear_matrix = scene_linear_matrix;
287 if (
data.exponent != display_parameters.exponent) {
288 data.exponent = display_parameters.exponent;
291 if (
data.dither != display_parameters.dither) {
292 data.dither = display_parameters.dither;
295 if (
bool(
data.use_predivide) != display_parameters.use_predivide) {
296 data.use_predivide = display_parameters.use_predivide;
299 if (
bool(
data.do_overlay_merge) != display_parameters.do_overlay_merge) {
300 data.do_overlay_merge = display_parameters.do_overlay_merge;
303 if (
bool(
data.use_hdr) != display_parameters.use_hdr) {
304 data.use_hdr = display_parameters.use_hdr;
314static bool gpu_shader_bind(
const Config &config,
322 if (!display_shader.is_valid) {
327 if (display_parameters.curve_mapping) {
328 gpu_curve_mapping_update(display_shader.curve_mapping, *display_parameters.curve_mapping);
329 GPU_uniformbuf_bind(display_shader.curve_mapping.buffer, UniformBufferSlot::CURVE_MAPPING);
330 GPU_texture_bind(display_shader.curve_mapping.texture, TextureSlot::CURVE_MAPPING);
337 if (!display_parameters.do_overlay_merge) {
341 for (
int i = 0;
i < display_shader.textures.luts.size();
i++) {
342 GPU_texture_bind(display_shader.textures.luts[
i].texture, TextureSlot::LUTS_OFFSET +
i);
345 if (display_shader.textures.uniforms_buffer) {
350 if (display_parameters.use_white_balance) {
352 config, display_parameters.temperature, display_parameters.tint);
355 gpu_display_shader_parameters_update(display_shader, display_parameters,
float4x4(matrix));
369 : display_cache_(std::make_unique<
internal::GPUShaderCache>()),
370 scene_linear_cache_(std::make_unique<
internal::GPUShaderCache>()),
384 if (!display_shader) {
385 display_shader = &display_cache_->create_default();
389 display_shader->
view = display_parameters.
view;
391 display_shader->
look = display_parameters.
look;
410 return gpu_shader_bind(
config_, *display_shader, display_parameters);
414 const bool use_predivide)
const
428 if (!display_shader) {
429 display_shader = &display_cache_->create_default();
439 return gpu_shader_bind(
config_, *display_shader, display_parameters);
450 const Span<std::array<StringRefNull, 2>> additional_defines)
459 for (
const auto &additional_define : additional_defines) {
460 info.
define(additional_define[0], additional_define[1]);
464 info.
define(
"texture1D",
"texture");
465 info.
define(
"texture2D",
"texture");
466 info.
define(
"texture3D",
"texture");
482 info.
vertex_source(
"gpu_shader_display_transform_vert.glsl");
494 info.
define(
"USE_CURVE_MAPPING");
496 "OCIO_GPUCurveMappingParameters",
506 const ImageType type = (dimensions == 1) ? ImageType::Float1D :
507 (dimensions == 2) ? ImageType::Float2D :
513#if defined(WITH_OPENCOLORIO)
517 const size_t ubo_size = display_shader.
textures.
uniforms.size() *
sizeof(float) * 4;
520 uint32_t *ubo_data =
reinterpret_cast<uint32_t *
>(ubo_data_buf.
data());
522 std::stringstream ss;
523 ss <<
"struct OCIO_GPULutParameters {\n";
528 const OCIO_NAMESPACE::GpuShaderDesc::UniformData &
data = uniform.data;
529 const char *name = uniform.
name.c_str();
532 switch (
data.m_type) {
533 case OCIO_NAMESPACE::UNIFORM_DOUBLE: {
535 float value = float(
data.m_getDouble());
536 memcpy(ubo_data, &value,
sizeof(
float));
539 case OCIO_NAMESPACE::UNIFORM_BOOL: {
542 int value = int(
data.m_getBool());
543 memcpy(ubo_data, &value,
sizeof(
int));
546 case OCIO_NAMESPACE::UNIFORM_FLOAT3:
548 memcpy(ubo_data,
data.m_getFloat3().data(),
sizeof(
float) * 3);
550 case OCIO_NAMESPACE::UNIFORM_VECTOR_FLOAT:
551 vec_len =
data.m_vectorFloat.m_getSize();
552 memcpy(ubo_data,
data.m_vectorFloat.m_getVector(),
sizeof(
float) * vec_len);
554 case OCIO_NAMESPACE::UNIFORM_VECTOR_INT:
556 vec_len =
data.m_vectorInt.m_getSize();
557 memcpy(ubo_data,
data.m_vectorInt.m_getVector(),
sizeof(
int) * vec_len);
566 ss <<
" " << prefix <<
"vec4 var" << index <<
";\n";
569 ss <<
"#define " << name <<
" lut_parameters.var" << index <<
"." << suffix <<
"\n";
577 ubo_size, ubo_data_buf.
data(),
"OCIO_LutParameters");
582 reinterpret_cast<GPUShaderCreateInfo *
>(&info));
584 return (display_shader.
shader !=
nullptr);
void BLI_string_replace(std::string &haystack, blender::StringRef needle, blender::StringRef other)
@ CUMA_EXTEND_EXTRAPOLATE
std::string GPU_shader_preprocess_source(blender::StringRefNull original)
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_1d(const char *name, int width, int mip_len, eGPUTextureFormat format, eGPUTextureUsage usage, const float *data)
void GPU_texture_free(GPUTexture *texture)
int GPU_texture_dimensions(const GPUTexture *texture)
GPUTexture * GPU_texture_create_error(int dimension, bool array)
void GPU_texture_extend_mode(GPUTexture *texture, GPUSamplerExtendMode extend_mode)
@ GPU_TEXTURE_USAGE_SHADER_READ
@ GPU_SAMPLER_EXTEND_MODE_EXTEND
void GPU_texture_update_sub(GPUTexture *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_filter_mode(GPUTexture *texture, bool use_filter)
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)
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
std::string from_colorspace
GPUUniformBuf * parameters_buffer
GPUCurveMappping curve_mapping
GPUDisplayShader * get(const GPUDisplayParameters &display_parameters)
GPUDisplayShader & create_default()
GPUUniformBuf * uniforms_buffer
Vector< GPUUniform > uniforms
Vector< GPULutTexture > luts
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()
CurveMapping * curve_mapping
StringRefNull from_colorspace