Blender V5.3
gpu_shader_binder.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
6
7#include <sstream>
8
9#include "MEM_guardedalloc.h"
10
11#include "BLI_assert.hh"
12#include "BLI_build_config.hh"
13#include "BLI_string_utils.hh"
14#include "BLI_vector.hh"
15
16#include "BKE_colortools.hh"
17
18#include "GPU_context.hh"
19#include "GPU_immediate.hh"
20#include "GPU_shader.hh"
21#include "GPU_texture.hh"
22#include "GPU_uniform_buffer.hh"
23
25
26#include "OCIO_config.hh"
27
29#include "source_processor.hh"
30#include "white_point.hh"
31
32namespace blender::ocio {
33namespace internal {
34/* -------------------------------------------------------------------- */
37
50
52{
54
55 luts.clear();
56 uniforms.clear();
57
58 return (dummy != nullptr);
59}
60
62
63/* -------------------------------------------------------------------- */
66
68{
69 if (lut) {
70 MEM_delete(lut);
71 }
72
73 if (texture) {
75 }
76 if (buffer) {
78 }
80
82{
83 if (lut) {
84 MEM_delete(lut);
85 }
86
87 BKE_curvemapping_init(&curve_mapping);
88 BKE_curvemapping_premultiply(&curve_mapping, false);
89 BKE_curvemapping_table_RGBA(&curve_mapping, &lut, &lut_size);
90}
91
92bool GPUCurveMappping::initialize_common(const bool use_curve_mapping)
93{
94 if (!use_curve_mapping) {
95 return true;
96 }
97
98 texture = GPU_texture_create_1d("OCIOCurveMap",
100 1,
101 gpu::TextureFormat::SFLOAT_16_16_16_16,
103 nullptr);
106
108
109 if (texture == nullptr || buffer == nullptr) {
110 return false;
111 }
112
113 return true;
114}
115
117
118/* -------------------------------------------------------------------- */
121
131
132bool GPUDisplayShader::matches(const GPUDisplayParameters &display_parameters) const
133{
134 const bool use_curve_mapping = (display_parameters.curve_mapping != nullptr);
135 return (this->from_colorspace == display_parameters.from_colorspace &&
136 this->view == display_parameters.view && this->display == display_parameters.display &&
137 this->look == display_parameters.look && this->use_curve_mapping == use_curve_mapping &&
138 this->use_hdr_buffer == display_parameters.use_hdr_buffer &&
139 this->use_hdr_display == display_parameters.use_hdr_display &&
140 this->use_display_emulation == display_parameters.use_display_emulation &&
141 this->use_scope_space == display_parameters.use_scope_space);
142}
143
145{
147 is_valid = false;
148 return false;
149 }
150
152 is_valid = false;
153 return false;
154 }
155
156 return true;
157}
158
160
161/* -------------------------------------------------------------------- */
164
169
171{
172 for (std::list<GPUDisplayShader>::iterator it = cache_.begin(); it != cache_.end(); it++) {
173 if (it->matches(display_parameters)) {
174 /* Move to front of the cache to mark as most recently used. */
175 if (it != cache_.begin()) {
176 cache_.splice(cache_.begin(), cache_, it);
177 }
178 return &(*it);
179 }
180 }
181 return nullptr;
182}
183
185{
186 /* Remove least recently used element from cache. */
187 while (cache_.size() >= MAX_SIZE) {
188 cache_.pop_back();
189 }
190
191 /* Create GPU shader. */
192 cache_.emplace_front();
193
194 return cache_.front();
195}
196
198{
199 cache_.clear();
200}
201
203
204} // namespace internal
205
206namespace {
207
208/* -------------------------------------------------------------------- */
211
218static std::string process_source(std::string source, gpu::shader::ShaderCreateInfo &info)
219{
220 std::string res_declarations;
221 /* Insert resource declaration after types declaration. */
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";
232
234 source = res_declarations + GPU_shader_preprocess_source(source, info);
235
236 /* Comparison operator in Metal returns per-element comparison and returns a vector of booleans.
237 * Need a special syntax to see if two vec3 are matched.
238 *
239 * NOTE: The replacement is optimized for transforming code generated by
240 * GradingPrimaryTransform. A more general approach is possible, but for now prefer processing
241 * speed.
242 *
243 * NOTE: The syntax works for all backends Blender supports. */
245 source, "if ( gamma != vec3(1., 1., 1.) )", "if (! all(equal(gamma, vec3(1., 1., 1.))) )");
246
247 return source;
248}
249
250static void gpu_curve_mapping_update(internal::GPUCurveMappping &gpu_curve_mapping,
251 CurveMapping &curve_mapping)
252{
253 /* Test if we need to update. */
254 /* TODO(sergey): Use more reliable cache identifier.
255 * Something like monotonously incrementing change counter feels to have less collisions. */
256 const size_t cache_id = size_t(&curve_mapping) + curve_mapping.changed_timestamp;
257 if (gpu_curve_mapping.cache_id == cache_id) {
258 return;
259 }
260 gpu_curve_mapping.cache_id = cache_id;
261
262 /* Update texture. */
263 const int offset[3] = {0, 0, 0};
264 const int extent[3] = {gpu_curve_mapping.lut_size, 0, 0};
265 GPU_texture_update_sub(gpu_curve_mapping.texture,
267 gpu_curve_mapping.lut,
268 UNPACK3(offset),
269 UNPACK3(extent));
270
271 /* Update uniforms. */
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;
283 data.last_x[i] = curve_map.table[CM_TABLE].x;
284 data.last_y[i] = curve_map.table[CM_TABLE].y;
285 }
286 for (int i = 0; i < 3; i++) {
287 data.black[i] = curve_mapping.black[i];
288 data.bwmul[i] = curve_mapping.bwmul[i];
289 }
290 data.lut_size = gpu_curve_mapping.lut_size;
291 data.use_extend_extrapolate = (curve_mapping.flag & CUMA_EXTEND_EXTRAPOLATE) != 0;
292
293 GPU_uniformbuf_update(gpu_curve_mapping.buffer, &data);
294}
295
296static void gpu_display_shader_parameters_update(internal::GPUDisplayShader &display_shader,
297 const GPUDisplayParameters &display_parameters,
298 float4x4 scene_linear_matrix)
299{
300 bool do_update = false;
301 if (display_shader.parameters_buffer == nullptr) {
302 display_shader.parameters_buffer = GPU_uniformbuf_create(sizeof(OCIO_GPUParameters));
303 do_update = true;
304 }
305
306 OCIO_GPUParameters &data = display_shader.parameters;
307 if (data.scene_linear_matrix != scene_linear_matrix) {
308 data.scene_linear_matrix = scene_linear_matrix;
309 do_update = true;
310 }
311 if (data.exponent != display_parameters.exponent) {
312 data.exponent = display_parameters.exponent;
313 do_update = true;
314 }
315 if (data.dither != display_parameters.dither) {
316 data.dither = display_parameters.dither;
317 do_update = true;
318 }
319 if (data.opacity != display_parameters.opacity) {
320 data.opacity = display_parameters.opacity;
321 do_update = true;
322 }
323 if (bool(data.use_predivide) != display_parameters.use_predivide) {
324 data.use_predivide = display_parameters.use_predivide;
325 do_update = true;
326 }
327 if (bool(data.do_overlay_merge) != display_parameters.do_overlay_merge) {
328 data.do_overlay_merge = display_parameters.do_overlay_merge;
329 do_update = true;
330 }
331 if (bool(data.use_hdr_display) != display_parameters.use_hdr_display) {
332 data.use_hdr_display = display_parameters.use_hdr_display;
333 do_update = true;
334 }
335
336 if (do_update) {
337 GPU_uniformbuf_update(display_shader.parameters_buffer, &data);
338 }
339}
340
341/* Bind the shader and update parameters and uniforms. */
342static bool gpu_shader_bind(const Config &config,
343 internal::GPUDisplayShader &display_shader,
344 const GPUDisplayParameters &display_parameters)
345{
348
349 /* Verify the shader is valid. */
350 if (!display_shader.is_valid) {
351 return false;
352 }
353
354 /* Update and bind curve mapping data. */
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);
359 /* TODO(sergey): Can free the curve mapping's lookup table.
360 * Seems minor, maybe not that important. */
361 }
362
363 /* Bind textures to sampler units. Texture 0 is set by caller.
364 * Uniforms have already been set for texture bind points. */
365 if (!display_parameters.do_overlay_merge) {
366 /* Avoid missing binds. */
367 GPU_texture_bind(display_shader.textures.dummy, TextureSlot::OVERLAY);
368 }
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);
371 }
372
373 if (display_shader.textures.uniforms_buffer) {
374 GPU_uniformbuf_bind(display_shader.textures.uniforms_buffer, UniformBufferSlot::LUTS);
375 }
376
377 float3x3 matrix = float3x3::identity() * display_parameters.scale;
378 if (display_parameters.use_white_balance) {
380 config, display_parameters.temperature, display_parameters.tint);
381 }
382
383 gpu_display_shader_parameters_update(display_shader, display_parameters, float4x4(matrix));
384 GPU_uniformbuf_bind(display_shader.parameters_buffer, UniformBufferSlot::DISPLAY);
385
386 /* TODO(fclem): remove remains of IMM. */
387 immBindShader(display_shader.shader);
388
389 return true;
390}
391
393
394} // namespace
395
397 : display_cache_(std::make_unique<internal::GPUShaderCache>()),
398 scene_linear_cache_(std::make_unique<internal::GPUShaderCache>()),
399 config_(config)
400{
401}
402
403/* Keep private to the translation unit to allow proper destruction of smart pointers to internal
404 * data. */
406
407bool GPUShaderBinder::display_bind(const GPUDisplayParameters &display_parameters) const
408{
409 /* Attempt to get shader from the cache. */
410 internal::GPUDisplayShader *display_shader = display_cache_->get(display_parameters);
411
412 if (!display_shader) {
413 display_shader = &display_cache_->create_default();
414 BLI_assert(display_shader);
415
416 display_shader->from_colorspace = display_parameters.from_colorspace;
417 display_shader->view = display_parameters.view;
418 display_shader->display = display_parameters.display;
419 display_shader->look = display_parameters.look;
420 display_shader->use_curve_mapping = (display_parameters.curve_mapping != nullptr);
421 display_shader->use_hdr_buffer = display_parameters.use_hdr_buffer;
422 display_shader->use_hdr_display = display_parameters.use_hdr_display;
423 display_shader->use_display_emulation = display_parameters.use_display_emulation;
424 display_shader->use_scope_space = display_parameters.use_scope_space;
425 display_shader->is_valid = false;
426
427 if (display_parameters.curve_mapping) {
428 /* Rasterize curve mapping early so that texture allocation can know the size of the lookup
429 * table. */
430 display_shader->curve_mapping.rasterize(*display_parameters.curve_mapping);
431 }
432
433 if (display_shader->initialize_common()) {
434 construct_display_shader(*display_shader);
435 }
436 }
437 else if (display_parameters.curve_mapping) {
438 /* Update curve mapping's lookup table. */
439 display_shader->curve_mapping.rasterize(*display_parameters.curve_mapping);
440 }
441
442 return gpu_shader_bind(config_, *display_shader, display_parameters);
443}
444
446 const bool use_predivide) const
447{
448 /* Re-use code and logic with the conversion to the display space. This assumes that empty names
449 * for display, view, and look are not valid for the OpenColorIO configuration, and so they can
450 * be used to indicate that the processor is used to convert from the given space to the linear.
451 */
452
453 GPUDisplayParameters display_parameters;
454 display_parameters.from_colorspace = from_colorspace;
455 display_parameters.use_predivide = use_predivide;
456
457 /* Attempt to get shader from the cache. */
458 internal::GPUDisplayShader *shader = scene_linear_cache_->get(display_parameters);
459
460 if (!shader) {
461 shader = &scene_linear_cache_->create_default();
463
464 shader->from_colorspace = display_parameters.from_colorspace;
465
466 if (shader->initialize_common()) {
468 }
469 }
470
471 return gpu_shader_bind(config_, *shader, display_parameters);
472}
473
475{
477}
478
480 internal::GPUDisplayShader &display_shader,
481 StringRefNull fragment_source,
482 const Span<std::array<StringRefNull, 2>> additional_defines)
483{
484 using namespace blender::gpu::shader;
485
486 StageInterfaceInfo iface("OCIO_Interface", "");
487 iface.smooth(Type::float2_t, "texCoord_interp");
488
489 ShaderCreateInfo info("OCIO_Display");
491
492 for (const auto &additional_define : additional_defines) {
493 info.define(additional_define[0], additional_define[1]);
494 }
495
496 /* Work around OpenColorIO not supporting latest GLSL yet. */
497 info.define("texture1D", "texture");
498 info.define("texture2D", "texture");
499 info.define("texture3D", "texture");
500
501 /* Work around unsupported in keyword in Metal GLSL emulation. */
503 info.define("in", "");
504 }
505
506 info.typedef_source("ocio_shader_shared.hh");
507 info.sampler(internal::TextureSlot::IMAGE, ImageType::Float2D, "image_texture");
508 info.sampler(internal::TextureSlot::OVERLAY, ImageType::Float2D, "overlay_texture");
509 info.uniform_buf(internal::UniformBufferSlot::DISPLAY, "OCIO_GPUParameters", "parameters");
510 info.push_constant(Type::float4x4_t, "ModelViewProjectionMatrix");
511 info.vertex_in(0, Type::float2_t, "pos");
512 info.vertex_in(1, Type::float2_t, "texCoord");
513 info.vertex_out(iface);
514 info.fragment_out(0, Type::float4_t, "fragColor");
515 info.vertex_source("gpu_shader_display_transform_vert.glsl");
516 info.fragment_source("gpu_shader_display_transform_frag.glsl");
517
518 info.generated_sources.append(
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)});
522
523 /* #96502: Work around for incorrect OCIO GLSL code generation when using
524 * GradingPrimaryTransform. Should be reevaluated when changing to a next version of OCIO.
525 * (currently v2.1.1). */
526 info.define("inf 1e32");
527
528 if (display_shader.use_curve_mapping) {
529 info.define("USE_CURVE_MAPPING");
531 "OCIO_GPUCurveMappingParameters",
532 "curve_mapping");
533 info.sampler(
534 internal::TextureSlot::CURVE_MAPPING, ImageType::Float1D, "curve_mapping_texture");
535 }
536
537 /* Set LUT textures. */
539 for (const internal::GPULutTexture &texture : display_shader.textures.luts) {
540 const int dimensions = GPU_texture_dimensions(texture.texture);
541 const ImageType type = (dimensions == 1) ? ImageType::Float1D :
542 (dimensions == 2) ? ImageType::Float2D :
543 ImageType::Float3D;
544 info.sampler(slot++, type, texture.sampler_name.c_str());
545 }
546
547 /* Set LUT uniforms. */
548 if (!display_shader.textures.uniforms.is_empty()) {
549 /* NOTE: For simplicity, we pad everything to size of vec4 avoiding sorting and alignment
550 * issues. It is unlikely that this becomes a real issue. */
551 const size_t ubo_size = display_shader.textures.uniforms.size() * sizeof(float) * 4;
552 Vector<uint8_t> ubo_data_buf(ubo_size);
553
554 uint32_t *ubo_data = reinterpret_cast<uint32_t *>(ubo_data_buf.data());
555
556 std::stringstream ss;
557 ss << "struct OCIO_GPULutParameters {\n";
558
559 int index = 0;
560 for (internal::GPUUniform &uniform : display_shader.textures.uniforms) {
561 index += 1;
562 const OCIO_NAMESPACE::GpuShaderDesc::UniformData &data = uniform.data;
563 const char *name = uniform.name.c_str();
564 char prefix = ' ';
565 int vec_len;
566 switch (data.m_type) {
567 case OCIO_NAMESPACE::UNIFORM_DOUBLE: {
568 vec_len = 1;
569 float value = float(data.m_getDouble());
570 memcpy(ubo_data, &value, sizeof(float));
571 break;
572 }
573 case OCIO_NAMESPACE::UNIFORM_BOOL: {
574 prefix = 'b';
575 vec_len = 1;
576 int value = int(data.m_getBool());
577 memcpy(ubo_data, &value, sizeof(int));
578 break;
579 }
580 case OCIO_NAMESPACE::UNIFORM_FLOAT3:
581 vec_len = 3;
582 memcpy(ubo_data, data.m_getFloat3().data(), sizeof(float) * 3);
583 break;
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);
587 break;
588 case OCIO_NAMESPACE::UNIFORM_VECTOR_INT:
589 prefix = 'i';
590 vec_len = data.m_vectorInt.m_getSize();
591 memcpy(ubo_data, data.m_vectorInt.m_getVector(), sizeof(int) * vec_len);
592 break;
593 default:
594 continue;
595 }
596 /* Align every member to 16 bytes. */
597 ubo_data += 4;
598 /* Use a generic variable name because some GLSL compilers can interpret the preprocessor
599 * define as recursive. */
600 ss << " " << prefix << "vec4 var" << index << ";\n";
601 /* Use a define to keep the generated code working. */
602 StringRef suffix = StringRefNull("xyzw").substr(0, vec_len);
603 ss << "#define " << name << " lut_parameters.var" << index << "." << suffix << "\n";
604 }
605 ss << "};\n";
606 info.typedef_source_generated = ss.str();
607
608 info.uniform_buf(internal::UniformBufferSlot::LUTS, "OCIO_GPULutParameters", "lut_parameters");
609
611 ubo_size, ubo_data_buf.data(), "OCIO_LutParameters");
612 }
613
614 display_shader.shader = GPU_shader_create_from_info(
615 reinterpret_cast<GPUShaderCreateInfo *>(&info));
616
617 return (display_shader.shader != nullptr);
618}
619
621{
622 scene_linear_cache_->clear();
623 display_cache_->clear();
624}
625
626} // namespace blender::ocio
#define CM_TABLE
#define GPU_uniformbuf_create(size)
Read Blender memory allocation and freeing.
#define UNPACK3(a)
constexpr StringRefNull()
constexpr StringRef substr(int64_t start, int64_t size) const
virtual void construct_display_shader(internal::GPUDisplayShader &display_shader) const =0
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
GPUDisplayShader * get(const GPUDisplayParameters &display_parameters)
#define uniform(slot)
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)
void immUnbindProgram()
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)
unsigned int uint32_t
Definition BKE_text.h:81
@ 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
eCurveMappingFlags flag
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)
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)
Self & builtins(BuiltinBits builtin, ConditionFn cond=nullptr)
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)