Blender V5.3
gpu_codegen.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2005 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#include "MEM_guardedalloc.h"
12
13#include "DNA_material_types.h"
14
15#include "BLI_span.hh"
16#include "BLI_string.hh"
17#include "BLI_utildefines.hh"
18#include "BLI_vector.hh"
19
20#include "BKE_cryptomatte.hh"
21
23
24#include "GPU_capabilities.hh"
25#include "GPU_shader.hh"
26#include "GPU_uniform_buffer.hh"
27#include "GPU_vertex_format.hh"
28
29#include "gpu_codegen.hh"
32
33#include <cstdarg>
34#include <cstring>
35
36namespace blender {
37
38using namespace blender::gpu::shader;
39
40/* -------------------------------------------------------------------- */
43
44static std::ostream &operator<<(std::ostream &stream, const GPUInput *input)
45{
46 switch (input->source) {
49 return stream << (input->is_zone_io ? "zone" : "tmp") << input->id;
51 return stream << (input->is_zone_io ? "zone" : "cons") << input->id;
53 return stream << "node_tree.u" << input->id << (input->is_duplicate ? "b" : "");
54 case GPU_SOURCE_ATTR:
55 return stream << "var_attrs.v" << input->attr->id;
57 return stream << "UNI_ATTR(unf_attrs[resource_id].attr" << input->uniform_attr->id << ")";
59 return stream << "attr_load_layer(kg, " << input->layer_attr->hash_code << ")";
61 return stream << (input->is_zone_io ? "zone" : "strct") << input->id;
63 return stream << "sd";
65 return stream << "kg";
66 case GPU_SOURCE_TEX:
67 return stream << input->texture->sampler_name;
69 return stream << input->texture->tiled_mapping_name;
70 default:
71 BLI_assert(0);
72 return stream;
73 }
74}
75
76static std::ostream &operator<<(std::ostream &stream, const GPUOutput *output)
77{
78 return stream << (output->is_zone_io ? "zone" : "tmp") << output->id;
79}
80
81/* Print data constructor (i.e: vec2(1.0f, 1.0f)). */
82static std::ostream &operator<<(std::ostream &stream, const Span<float> &span)
83{
84 stream << gpu_float_type_from_element_count(span.size()) << "(";
85 /* Use uint representation to allow exact same bit pattern even if NaN. This is
86 * because we can pass UINTs as floats for constants. */
87 const Span<uint32_t> uint_span = span.cast<uint32_t>();
88 for (const uint32_t &element : uint_span) {
89 char formatted_float[32];
90 SNPRINTF(formatted_float, "uintBitsToFloat(%uu)", element);
91 stream << formatted_float;
92 if (&element != &uint_span.last()) {
93 stream << ", ";
94 }
95 }
96 stream << ")";
97 return stream;
98}
99
100/* Print data constructor (i.e: int2(1, 1)). */
101static std::ostream &operator<<(std::ostream &stream, const Span<int> &span)
102{
103 stream << gpu_int_type_from_element_count(span.size()) << "(";
104 for (const int &element : span) {
105 stream << element;
106 if (&element != &span.last()) {
107 stream << ", ";
108 }
109 }
110 stream << ")";
111 return stream;
112}
113
114/* Trick type to change overload and keep a somewhat nice syntax. */
115struct GPUConstant : public GPUInput {};
116
117static std::ostream &operator<<(std::ostream &stream, const GPUConstant *input)
118{
119 switch (input->type) {
120 case GPU_FLOAT:
121 case GPU_VEC2:
122 case GPU_VEC3:
123 case GPU_VEC4:
124 case GPU_MAT3:
125 case GPU_MAT4:
126 return stream << gpu_constant_to_float_span(input->constant_data, input->type);
127 case GPU_INT:
128 case GPU_INT2:
129 case GPU_INT3:
130 case GPU_INT4:
131 return stream << gpu_constant_to_int_span(input->constant_data, input->type);
132 case GPU_BOOL:
133 return stream << "bool(" << (gpu_constant_to_bool(input->constant_data) ? "true" : "false")
134 << ")";
135 default:
136 break;
137 }
138
140 return stream;
141}
142
143namespace gpu::shader {
144/* Needed to use the << operators from nested namespaces. :(
145 * https://stackoverflow.com/questions/5195512/namespaces-and-operator-resolution */
146using blender::operator<<;
147} // namespace gpu::shader
148
150
151/* -------------------------------------------------------------------- */
154
156{
157 auto index = sampler_names.size();
158 sampler_names.append(std::make_unique<NameEntry>());
159 char *name_buffer = sampler_names[index]->data();
160 memcpy(name_buffer, name, 32);
161 return name_buffer;
162}
163
164GPUCodegen::GPUCodegen(GPUMaterial *mat_, GPUNodeGraph *graph_, const char *debug_name)
165 : mat(*mat_), graph(*graph_)
166{
169 create_info = MEM_new<GPUCodegenCreateInfo>(__func__, debug_name);
170 output.create_info = reinterpret_cast<GPUShaderCreateInfo *>(
171 static_cast<ShaderCreateInfo *>(create_info));
172}
173
175{
176 MEM_SAFE_DELETE(cryptomatte_input_);
177 MEM_SAFE_DELETE(thickness_input_);
178 MEM_delete(create_info);
179 ubo_inputs_.free_no_destruct();
180};
181
183{
184 /* If each of the maximal attributes are exceeded, we can optimize, but we should also ensure
185 * the baseline is met. */
186 bool do_optimize = (nodes_total_ >= 60 || textures_total_ >= 4 || uniforms_total_ >= 64) &&
187 (textures_total_ >= 1 && uniforms_total_ >= 8 && nodes_total_ >= 4);
188 return do_optimize;
189}
190
192{
193 if (graph.attributes.is_empty()) {
194 output.attr_load.clear();
195 return;
196 }
197
199
200 info.interface_generated = MEM_new<StageInterfaceInfo>(__func__, "codegen_iface", "var_attrs");
202 info.vertex_out(iface);
203
204 /* Input declaration, loading / assignment to interface and geometry shader passthrough. */
205 std::stringstream load_ss;
206
207 /* Index of the attribute as ordered in graph.attributes. */
208 int attr_n = 0;
209 int slot = 15;
211 if (slot == -1) {
212 BLI_assert_msg(0, "Too many attributes");
213 break;
214 }
215 STRNCPY(info.name_buffer.attr_names[slot], attr.input_name);
216 SNPRINTF(info.name_buffer.var_names[slot], "v%d", attr.id);
217
218 StringRefNull attr_name = info.name_buffer.attr_names[slot];
219 StringRefNull var_name = info.name_buffer.var_names[slot];
220
221 GPUType input_type, iface_type;
222
223 load_ss << "var_attrs." << var_name;
224 if (attr.is_hair_length || attr.is_hair_intercept) {
225 iface_type = input_type = GPU_FLOAT;
226 load_ss << " = attr_load_" << input_type << "(domain, " << attr_name << ", " << attr_n
227 << ");\n";
228 }
229 else {
230 switch (attr.type) {
231 case CD_ORCO:
232 /* Need vec4 to detect usage of default attribute. */
233 input_type = GPU_VEC4;
234 iface_type = GPU_VEC3;
235 load_ss << " = attr_load_orco(domain, " << attr_name << ", " << attr_n << ");\n";
236 break;
237 case CD_TANGENT:
238 iface_type = input_type = GPU_VEC4;
239 load_ss << " = attr_load_tangent(domain, " << attr_name << ", " << attr_n << ");\n";
240 break;
241 default:
242 iface_type = input_type = GPU_VEC4;
243 load_ss << " = attr_load_" << input_type << "(domain, " << attr_name << ", " << attr_n
244 << ");\n";
245 break;
246 }
247 }
248 attr_n++;
249
250 info.vertex_in(slot--, to_type(input_type), attr_name);
251 iface.smooth(to_type(iface_type), var_name);
252 }
253
254 output.attr_load = load_ss.str();
255}
256
258{
260
261 std::stringstream ss;
262 /* Improve error logging. */
263 ss << "#line 1 \"" __FILE__ "\"\n";
264 ss << "#line " STRINGIFY(__LINE__) "\n";
265
266 /* Textures. */
267 int slot = 0;
268 for (GPUMaterialTexture &tex : graph.textures) {
269 if (tex.colorband) {
270 const char *name = info.name_buffer.append_sampler_name(tex.sampler_name);
271 info.sampler(slot++, ImageType::Float1DArray, name, Frequency::BATCH);
272 }
273 else if (tex.sky) {
274 const char *name = info.name_buffer.append_sampler_name(tex.sampler_name);
275 info.sampler(0, ImageType::Float2DArray, name, Frequency::BATCH);
276 }
277 else if (tex.tiled_mapping_name[0] != '\0') {
278 const char *name = info.name_buffer.append_sampler_name(tex.sampler_name);
279 info.sampler(slot++, ImageType::Float2DArray, name, Frequency::BATCH);
280
281 const char *name_mapping = info.name_buffer.append_sampler_name(tex.tiled_mapping_name);
282 info.sampler(slot++, ImageType::Float1DArray, name_mapping, Frequency::BATCH);
283 }
284 else {
285 const char *name = info.name_buffer.append_sampler_name(tex.sampler_name);
286 info.sampler(slot++, ImageType::Float2D, name, Frequency::BATCH);
287 }
288 }
289
290 /* Increment heuristic. */
291 textures_total_ = slot;
292
293 if (!ubo_inputs_.is_empty()) {
294 const char *linted_struct_suffix = "_host_shared_";
295 /* NOTE: generate_uniform_buffer() should have sorted the inputs before this. */
296 ss << "struct NodeTree {\n";
297 for (LinkData &link : ubo_inputs_) {
298 GPUInput *input = static_cast<GPUInput *>(link.data);
299 if (input->source == GPU_SOURCE_THICKNESS_MODE) {
300 ss << "bool32_t thickness_mode;\n";
301 }
302 else if (input->source == GPU_SOURCE_CRYPTOMATTE) {
303 ss << input->type << " crypto_hash;\n";
304 }
305 else {
306 /* MSL does not pad bool to 4 bytes; use bool32_t so UBO layout matches correctly. */
307 if (input->type == GPU_BOOL) {
308 ss << "bool32_t";
309 }
310 else {
311 ss << input->type;
312 }
313 ss << " u" << input->id << (input->is_duplicate ? "b" : "") << ";\n";
314 }
315 }
316 ss << "};\n";
317 ss << "#define NodeTree" << linted_struct_suffix << " NodeTree\n";
318 ss << "#define NodeTree" << linted_struct_suffix << "uniform_ NodeTree\n";
319 ss << "\n";
320
321 info.uniform_buf(GPU_NODE_TREE_UBO_SLOT, "NodeTree", GPU_UBO_BLOCK_NAME, Frequency::BATCH);
322 }
323
324 if (!graph.uniform_attrs.list.is_empty()) {
325 ss << "struct UniformAttrs {\n";
326 for (GPUUniformAttr &attr : graph.uniform_attrs.list) {
327 ss << "vec4 attr" << attr.id << ";\n";
328 }
329 ss << "};\n\n";
330
331 /* TODO(fclem): Use the macro for length. Currently not working for EEVEE. */
332 /* DRW_RESOURCE_CHUNK_LEN = 512 */
333 info.uniform_buf(2, "UniformAttrs", GPU_ATTRIBUTE_UBO_BLOCK_NAME "[512]", Frequency::BATCH);
334 }
335
336 info.typedef_source_generated = ss.str();
337}
338
339void GPUCodegen::node_serialize(Set<StringRefNull> &used_libraries,
340 std::stringstream &eval_ss,
341 const GPUNode *node)
342{
343 gpu_material_library_use_function(used_libraries, node->name);
344
345 auto source_reference = [&](GPUInput *input) {
347 /* These inputs can have non matching types. Do conversion. */
348 GPUType to = input->type;
349 GPUType from = (input->source == GPU_SOURCE_ATTR) ? input->attr->gputype :
350 input->link->output->type;
351 if (from != to) {
352 /* Use defines declared inside codegen_lib (e.g. vec4_from_float). */
353 eval_ss << to << "_from_" << from << "(";
354 }
355
356 if (input->source == GPU_SOURCE_ATTR) {
357 eval_ss << input;
358 }
359 else {
360 eval_ss << input->link->output;
361 }
362
363 if (from != to) {
364 /* Special case that needs luminance coefficients as argument. */
365 if (from == GPU_VEC4 && ELEM(to, GPU_FLOAT, GPU_INT, GPU_BOOL)) {
366 float coefficients[3];
368 eval_ss << ", " << Span<float>(coefficients, 3);
369 }
370 eval_ss << ")";
371 }
372 };
373
374 /* Declare constants. */
375 for (GPUInput &input : node->inputs) {
376 auto type = [&]() {
377 /* Don't declare zone io variables twice. */
378 std::stringstream ss;
379 if (!input.is_duplicate) {
380 ss << input.type;
381 }
382 return ss.str();
383 };
384 switch (input.source) {
386 eval_ss << type() << " " << &input << "; " << input.function_call << &input << ");\n";
387 break;
390 /* Defined as inputs to the node-tree eval function. */
391 break;
393 eval_ss << input.type << " " << &input << " = CLOSURE_DEFAULT;\n";
394 break;
396 if (!input.is_duplicate) {
397 eval_ss << type() << " " << &input << " = " << static_cast<GPUConstant *>(&input)
398 << ";\n";
399 }
400 break;
402 case GPU_SOURCE_ATTR:
403 if (input.is_zone_io) {
404 eval_ss << type() << " " << &input << " = ";
405 source_reference(&input);
406 eval_ss << ";\n";
407 }
408 break;
409 default:
410 if (input.is_zone_io && (!input.is_duplicate || !input.link)) {
411 eval_ss << type() << " zone" << input.id << " = " << &input << ";\n";
412 }
413 break;
414 }
415 }
416 /* Declare temporary variables for node output storage. */
417 for (GPUOutput &output : node->outputs) {
418 if (output.is_zone_io) {
419 break;
420 }
421 switch (output.type) {
422 case GPU_SHADING_DATA:
424 /* Defined as inputs to the node-tree eval function. */
425 break;
426 default:
427 eval_ss << output.type << " " << &output << ";\n";
428 break;
429 }
430 }
431
432 /* Function call. */
433 eval_ss << node->name << "(";
434 /* Input arguments. */
435 for (GPUInput &input : node->inputs) {
436 if (input.is_zone_io) {
437 break;
438 }
439 switch (input.source) {
441 case GPU_SOURCE_ATTR: {
442 source_reference(&input);
443 break;
444 }
445 default:
446 eval_ss << &input;
447 break;
448 }
449 GPUOutput *output = node->outputs.first();
450 if ((input.next && !input.next->is_zone_io) || (output && !output->is_zone_io)) {
451 eval_ss << ", ";
452 }
453 }
454 /* Output arguments. */
455 for (GPUOutput &output : node->outputs) {
456 if (output.is_zone_io) {
457 break;
458 }
459 switch (output.type) {
461 eval_ss << "kg";
462 break;
463 case GPU_SHADING_DATA:
464 eval_ss << "sd";
465 break;
466 default:
467 eval_ss << &output;
468 break;
469 }
470 if (output.next && !output.next->is_zone_io) {
471 eval_ss << ", ";
472 }
473 }
474 eval_ss << ");\n\n";
475
476 /* Increment heuristic. */
477 nodes_total_++;
478}
479
481{
482 Vector<StringRefNull> source_files;
483 for (const StringRefNull &str : set) {
484 source_files.append(str);
485 }
486 /* Sort dependencies to avoid random order causing shader caching to fail (see #108289). */
487 std::ranges::sort(source_files);
488 return source_files;
489}
490
491GPUGraphOutput GPUCodegen::graph_serialize(GPUNodeTag tree_tag,
492 GPUNodeLink *output_link,
493 const char *output_default)
494{
495 if (output_link == nullptr && output_default == nullptr) {
496 return {};
497 }
498
499 Set<StringRefNull> used_libraries;
500 std::stringstream eval_ss;
501 bool has_nodes = false;
502 /* NOTE: The node order is already top to bottom (or left to right in node editor)
503 * because of the evaluation order inside ntreeExecGPUNodes(). */
504 for (GPUNode &node : graph.nodes) {
505 if ((node.tag & tree_tag) == 0) {
506 continue;
507 }
508 node_serialize(used_libraries, eval_ss, &node);
509 has_nodes = true;
510 }
511
512 if (!has_nodes) {
513 return {};
514 }
515
516 if (output_link) {
517 eval_ss << "return " << output_link->output << ";\n";
518 }
519 else {
520 /* Default output in case there are only AOVs. */
521 eval_ss << "return " << output_default << ";\n";
522 }
523
524 std::string str = eval_ss.str();
525 BLI_hash_mm2a_add(&hm2a_, reinterpret_cast<const uchar *>(str.c_str()), str.size());
526 return {str, set_to_vector_stable(used_libraries)};
527}
528
529GPUGraphOutput GPUCodegen::graph_serialize(GPUNodeTag tree_tag)
530{
531 std::stringstream eval_ss;
532 Set<StringRefNull> used_libraries;
533 for (GPUNode &node : graph.nodes) {
534 if (node.tag & tree_tag) {
535 node_serialize(used_libraries, eval_ss, &node);
536 }
537 }
538 std::string str = eval_ss.str();
539 BLI_hash_mm2a_add(&hm2a_, reinterpret_cast<const uchar *>(str.c_str()), str.size());
540 return {str, set_to_vector_stable(used_libraries)};
541}
542
544{
545 {
546 cryptomatte_input_ = MEM_new<GPUInput>(__func__);
547 cryptomatte_input_->type = GPU_FLOAT;
548 cryptomatte_input_->source = GPU_SOURCE_CRYPTOMATTE;
549
550 float material_hash = 0.0f;
552 if (material) {
553 bke::cryptomatte::CryptomatteHash hash(material->id.name + 2,
554 BLI_strnlen(material->id.name + 2, MAX_NAME - 2));
555 material_hash = hash.float_encoded();
556 }
557 cryptomatte_input_->constant_data = material_hash;
558
559 BLI_addtail(&ubo_inputs_, BLI_genericNodeN(cryptomatte_input_));
560 }
561 {
562 thickness_input_ = MEM_new<GPUInput>(__func__);
563 thickness_input_->type = GPU_BOOL;
564 thickness_input_->source = GPU_SOURCE_THICKNESS_MODE;
565
566 int thickness_mode = MA_THICKNESS_SPHERE;
568 if (material) {
569 thickness_mode = material->thickness_mode;
570 }
571 thickness_input_->constant_data = bool(thickness_mode);
572
573 BLI_addtail(&ubo_inputs_, BLI_genericNodeN(thickness_input_));
574 }
575}
576
578{
579 /* Extract uniform inputs. */
580 for (GPUNode &node : graph.nodes) {
581 for (GPUInput &input : node.inputs) {
582 if (input.source == GPU_SOURCE_UNIFORM && !input.link) {
583 /* We handle the UBO uniforms separately. */
584 BLI_addtail(&ubo_inputs_, BLI_genericNodeN(&input));
585 uniforms_total_++;
586 }
587 }
588 }
589}
590
592{
593 if (!ubo_inputs_.is_empty()) {
594 /* This sorts the inputs based on size. */
596 }
597}
598
600{
601 if (!ubo_inputs_.is_empty()) {
602 /* This sorts the inputs based on size. */
603 GPU_uniformbuf_inputs_sort(&ubo_inputs_);
604 }
605}
606
607/* Sets id for unique names for all inputs, resources and temp variables. */
608void GPUCodegen::set_unique_ids()
609{
610 Map<int, GPUNode *> zone_starts;
611 Map<int, GPUNode *> zone_ends;
612
613 int id = 1;
614 for (GPUNode &node : graph.nodes) {
615 for (GPUInput &input : node.inputs) {
616 input.id = id++;
617 }
618 for (GPUOutput &output : node.outputs) {
619 output.id = id++;
620 }
621 if (node.zone_index != -1) {
622 auto &map = node.is_zone_end ? zone_ends : zone_starts;
623 map.add(node.zone_index, &node);
624 }
625 }
626
627 auto find_zone_io = [](auto first) {
628 while (first && !first->is_zone_io && first->next) {
629 first = first->next;
630 }
631 return first;
632 };
633
634 /* Assign the same id to inputs and outputs of start and end zones. */
635 for (GPUNode *end : zone_ends.values()) {
636
637 GPUInput *end_input = find_zone_io(end->inputs.first());
638 GPUOutput *end_output = find_zone_io(end->outputs.first());
639
640 GPUNode *start = zone_starts.lookup(end->zone_index);
641
642 GPUInput *start_input = find_zone_io(start->inputs.first());
643 GPUOutput *start_output = find_zone_io(start->outputs.first());
644
645 for (; start_input; start_input = start_input->next,
646 start_output = start_output->next,
647 end_input = end_input->next,
648 end_output = end_output->next)
649 {
650 start_output->id = start_input->id;
651 end_input->id = start_input->id;
652 end_output->id = start_input->id;
653 }
654 }
655}
656
658{
659 set_unique_ids();
660
661 output.surface = graph_serialize(
663 output.volume = graph_serialize(GPU_NODE_TAG_VOLUME, graph.outlink_volume, "CLOSURE_DEFAULT");
664 output.displacement = graph_serialize(
666 output.thickness = graph_serialize(GPU_NODE_TAG_THICKNESS, graph.outlink_thickness, nullptr);
667 if (!graph.outlink_compositor.is_empty()) {
668 output.composite = graph_serialize(GPU_NODE_TAG_COMPOSITOR);
669 }
670
671 if (!graph.material_functions.is_empty()) {
673 std::stringstream eval_ss;
674 /* Untag every node in the graph to avoid serializing nodes from other functions */
675 for (GPUNode &node : graph.nodes) {
677 }
678 /* Tag only the nodes needed for the current function */
680 GPUGraphOutput graph = graph_serialize(GPU_NODE_TAG_FUNCTION, func_link.outlink);
681 eval_ss << "float " << func_link.name << "(KernelGlobals kg, ShadingData sd) {\n"
682 << graph.serialized << "}\n\n";
683 output.material_functions.append({eval_ss.str(), graph.dependencies});
684 }
685 /* Leave the function tags as they were before serialization */
688 }
689 }
690
692 BLI_hash_mm2a_add(&hm2a_, reinterpret_cast<uchar *>(attr.name), strlen(attr.name));
693 }
694
695 hash_ = BLI_hash_mm2a_end(&hm2a_);
696}
697
699
700} // namespace blender
#define SNPRINTF(dst, format,...)
#define MAX_NAME
Definition DNA_defs.h:63
#define GPU_UBO_BLOCK_NAME
#define GPU_ATTRIBUTE_UBO_BLOCK_NAME
Read Blender memory allocation and freeing.
#define BLI_assert_unreachable()
#define STRINGIFY(x)
#define ELEM(...)
#define BLI_assert_msg(a, msg)
#define output
ValueIterator values() const &
Definition BLI_map.hh:884
bool add(const Key &key, const Value &value)
Definition BLI_map.hh:295
const Value & lookup(const Key &key) const
Definition BLI_map.hh:545
Span< NewT > constexpr cast() const
Definition BLI_span.hh:422
constexpr int64_t size() const
Definition BLI_span.hh:256
constexpr const T & last(const int64_t n=0) const
Definition BLI_span.hh:329
void append(const T &value)
GPUCodegenCreateInfo * create_info
GPUCodegen(GPUMaterial *mat_, GPUNodeGraph *graph_, const char *debug_name)
#define str(s)
uint to_type(bool)
std::ostream & operator<<(std::ostream &stream, const AssetCatalogPath &path_to_append)
BMesh Iterators.
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
uint32_t BLI_hash_mm2a_end(BLI_HashMurmur2A *mm2)
Definition hash_mm2a.cc:92
char * STRNCPY(char(&dst)[N], const char *src)
constexpr GPUType gpu_int_type_from_element_count(const int count)
void BLI_hash_mm2a_add(BLI_HashMurmur2A *mm2, const unsigned char *data, size_t len)
Definition hash_mm2a.cc:72
Span< float > gpu_constant_to_float_span(const GPUInputConstantData &data, const GPUType type)
Span< int > gpu_constant_to_int_span(const GPUInputConstantData &data, const GPUType type)
constexpr GPUType gpu_float_type_from_element_count(const int count)
BLI_INLINE void IMB_colormanagement_get_luminance_coefficients(float r_rgb[3])
void gpu_material_library_use_function(Set< StringRefNull > &used_libraries, const char *name)
@ GPU_KERNEL_GLOBALS
void gpu_nodes_tag(GPUNodeGraph *graph, GPUNodeLink *link_start, GPUNodeTag tag)
void GPU_material_uniform_buffer_create(GPUMaterial *material, ListBaseT< LinkData > *inputs)
eGPUMaterialFlag GPU_material_flag(const GPUMaterial *mat)
unsigned int uint32_t
Definition BKE_text.h:81
unsigned char uchar
Definition BKE_text.h:58
bool gpu_constant_to_bool(const GPUInputConstantData &data)
@ GPU_NODE_TAG_SURFACE
@ GPU_NODE_TAG_THICKNESS
@ GPU_NODE_TAG_VOLUME
@ GPU_NODE_TAG_FUNCTION
@ GPU_NODE_TAG_COMPOSITOR
@ GPU_NODE_TAG_DISPLACEMENT
int char char int int int int size_t BLI_strnlen(const char *str, size_t maxlen) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
LinkData * BLI_genericNodeN(void *data)
Definition listbase.cc:936
void BLI_hash_mm2a_add_int(BLI_HashMurmur2A *mm2, int data)
Definition hash_mm2a.cc:87
void BLI_hash_mm2a_init(BLI_HashMurmur2A *mm2, uint32_t seed)
Definition hash_mm2a.cc:64
@ GPU_SOURCE_TEX_TILED_MAPPING
@ GPU_SOURCE_SHADING_DATA
@ GPU_SOURCE_FUNCTION_CALL
@ GPU_SOURCE_LAYER_ATTR
@ GPU_SOURCE_CONSTANT
@ GPU_SOURCE_THICKNESS_MODE
@ GPU_SOURCE_CRYPTOMATTE
@ GPU_SOURCE_UNIFORM_ATTR
@ GPU_SOURCE_KERNEL_GLOBALS
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
uint64_t GPU_material_uuid_get(GPUMaterial *mat)
Material * GPU_material_get_material(GPUMaterial *material)
void GPU_uniformbuf_inputs_sort(ListBaseT< LinkData > *inputs)
ATTR_WARN_UNUSED_RESULT const void * element
static Vector< StringRefNull > set_to_vector_stable(Set< StringRefNull > &set)
#define hash
Definition noise_c.cc:156
GPUShaderCreateInfo * create_info
Vector< StringRefNull > dependencies
GPUDataSource source
ListBaseT< GPUMaterialAttribute > attributes
ListBaseT< GPUNodeGraphFunctionLink > material_functions
GPUNodeLink * outlink_surface
GPUNodeLink * outlink_displacement
GPUNodeLink * outlink_thickness
ListBaseT< GPUNode > nodes
ListBaseT< GPUNodeGraphOutputLink > outlink_compositor
GPUNodeLink * outlink_volume
ListBaseT< GPUMaterialTexture > textures
GPUUniformAttrList uniform_attrs
ListBaseT< GPUOutput > outputs
ListBaseT< GPUInput > inputs
ListBaseT< GPUUniformAttr > list
char attr_names[16][GPU_MAX_SAFE_ATTR_NAME+1]
Vector< std::unique_ptr< NameEntry >, 16 > sampler_names
const char * append_sampler_name(const char name[32])
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 & vertex_in(int slot, Type type, StringRefNull name, 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 & smooth(Type type, StringRefNull _name)