Blender V4.5
gpu_shader_binder_internal.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
12
13#pragma once
14
15#include <list>
16
17#include "BLI_string_ref.hh"
18#include "BLI_utility_mixins.hh"
19#include "BLI_vector.hh"
20
21#include "ocio_shader_shared.hh"
22
23#if defined(WITH_OPENCOLORIO)
24# include "opencolorio.hh"
25#endif
26
27struct CurveMapping;
28struct GPUUniformBuf;
29struct GPUShader;
30struct GPUTexture;
31
32namespace blender::ocio {
33
35
36namespace internal {
37
38/* Namespaces mnemonic index for texture slot that can be passed as integer argument. */
40 enum {
41 IMAGE = 0,
45 };
46};
47
48/* Namespaces mnemonic index for uniform buffer slot that can be passed as integer argument. */
50 enum {
53 LUTS = 2,
54 };
55};
56
58 GPUTexture *texture = nullptr;
59 std::string sampler_name;
60};
61
62struct GPUUniform {
63 std::string name;
64
65 /* They are only required for processors generated by the OpenColorIO. For the simplicity of the
66 * internal API use OpenColorIO type (avoiding making extra copies of the data coming from the
67 * OpenColorIO library). */
68#if defined(WITH_OPENCOLORIO)
69 OCIO_NAMESPACE::GpuShaderDesc::UniformData data;
70#endif
71};
72
74 public:
76
77 /* Dummy in case of no overlay. */
78 GPUTexture *dummy = nullptr;
79
80 /* Uniforms */
82 GPUUniformBuf *uniforms_buffer = nullptr;
83
85
92 bool initialize_common();
93};
94
96 public:
97 int lut_size = 0;
98 float *lut = nullptr;
99
100 GPUUniformBuf *buffer = nullptr;
101 GPUTexture *texture = nullptr;
102 size_t cache_id = 0;
103
105
109 void rasterize(CurveMapping &curve_mapping);
110
119 bool initialize_common(bool use_curve_mapping);
120};
121
123 public:
124 /* Cache variables. */
125 std::string from_colorspace;
126 std::string view;
127 std::string display;
128 std::string look;
129 bool use_curve_mapping = false;
130
131 /* The shader is valid and can be bound.
132 * Note that the cache might contain invalid shaders to prevent Blender from attempting to keep
133 * re-trying to build the same failing shader. */
134 bool is_valid = false;
135
136 GPUShader *shader = nullptr;
137
138 /* Uniform parameters. */
140 GPUUniformBuf *parameters_buffer = nullptr;
141
144
146
147 bool matches(const GPUDisplayParameters &display_parameters) const;
148
158 bool initialize_common();
159};
160
162 /* The maximum number of cached shaders. */
163 static constexpr int MAX_SIZE = 4;
164
165 public:
167
172 GPUDisplayShader *get(const GPUDisplayParameters &display_parameters);
173
179
183 void clear();
184
185 private:
186 std::list<GPUDisplayShader> cache_;
187};
188
189} // namespace internal
190} // namespace blender::ocio
BMesh const char void * data
NonCopyable(const NonCopyable &other)=delete
NonMovable(NonMovable &&other)=delete
void rasterize(CurveMapping &curve_mapping)
bool initialize_common(bool use_curve_mapping)
bool matches(const GPUDisplayParameters &display_parameters) const
GPUDisplayShader * get(const GPUDisplayParameters &display_parameters)