Blender V5.3
gpu_codegen.hh
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#pragma once
12
13#include "BLI_hash_mm2a.hh"
14#include "BLI_listbase.hh"
15#include "BLI_set.hh"
16#include "BLI_vector.hh"
17
18#include "GPU_material.hh"
19#include "GPU_vertex_format.hh"
20#include "gpu_node_graph.hh"
22
23#include <sstream>
24#include <string>
25
26namespace blender::gpu::shader {
27
29 struct NameBuffer {
30 using NameEntry = std::array<char, 32>;
31
33 char attr_names[16][GPU_MAX_SAFE_ATTR_NAME + 1];
34 char var_names[16][8];
36
37 /* Returns the appended name memory location */
38 const char *append_sampler_name(const char name[32]);
39 };
40
45
46 GPUCodegenCreateInfo(const char *name) : ShaderCreateInfo(name) {};
47
49 {
50 MEM_delete(interface_generated);
51 }
52};
53
55 public:
60
61 private:
62 uint32_t hash_ = 0;
63 BLI_HashMurmur2A hm2a_;
64 ListBaseT<LinkData> ubo_inputs_ = {nullptr, nullptr};
65 GPUInput *cryptomatte_input_ = nullptr;
66 GPUInput *thickness_input_ = nullptr;
67
69 uint nodes_total_ = 0;
70 uint textures_total_ = 0;
71 uint uniforms_total_ = 0;
72
73 public:
74 GPUCodegen(GPUMaterial *mat_, GPUNodeGraph *graph_, const char *debug_name);
76
77 void generate_graphs();
80 void generate_attribs();
81 void generate_resources();
82
83 /* Populates `ubo_inputs_`. */
85 /* Sorts `ubo_inputs_` but does not create a UBO. */
87
89 {
90 return hash_;
91 }
92
93 /* Heuristic determined during pass codegen for whether a
94 * more optimal variant of this material should be compiled. */
95 bool should_optimize_heuristic() const;
96
97 private:
98 void set_unique_ids();
99
100 void node_serialize(Set<StringRefNull> &used_libraries,
101 std::stringstream &eval_ss,
102 const GPUNode *node);
103 GPUGraphOutput graph_serialize(GPUNodeTag tree_tag,
104 GPUNodeLink *output_link,
105 const char *output_default = nullptr);
106 GPUGraphOutput graph_serialize(GPUNodeTag tree_tag);
107};
108
109} // namespace blender::gpu::shader
GPUCodegenCreateInfo * create_info
GPUCodegen(GPUMaterial *mat_, GPUNodeGraph *graph_, const char *debug_name)
void generate_resources(GeneratedStreams &generated, const ShaderStage stage, const ShaderCreateInfo &info)
unsigned int uint
Definition BKE_text.h:55
unsigned int uint32_t
Definition BKE_text.h:81
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])