Blender V5.0
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.h"
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
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
46 std::string info_name_;
47
49 {
50 /* Base class is always initialized first, so we need to update the name_ pointer here. */
51 name_ = info_name_.c_str();
52 };
54 {
55 MEM_delete(interface_generated);
56 }
57};
58
60 public:
65
66 private:
67 uint32_t hash_ = 0;
68 BLI_HashMurmur2A hm2a_;
69 ListBase ubo_inputs_ = {nullptr, nullptr};
70 GPUInput *cryptomatte_input_ = nullptr;
71
73 uint nodes_total_ = 0;
74 uint textures_total_ = 0;
75 uint uniforms_total_ = 0;
76
77 public:
78 GPUCodegen(GPUMaterial *mat_, GPUNodeGraph *graph_, const char *debug_name);
80
81 void generate_graphs();
84 void generate_attribs();
85 void generate_resources();
86
87 uint32_t hash_get() const
88 {
89 return hash_;
90 }
91
92 /* Heuristic determined during pass codegen for whether a
93 * more optimal variant of this material should be compiled. */
94 bool should_optimize_heuristic() const;
95
96 private:
97 void set_unique_ids();
98
99 void node_serialize(blender::Set<blender::StringRefNull> &used_libraries,
100 std::stringstream &eval_ss,
101 const GPUNode *node);
102 GPUGraphOutput graph_serialize(GPUNodeTag tree_tag,
103 GPUNodeLink *output_link,
104 const char *output_default = nullptr);
105 GPUGraphOutput graph_serialize(GPUNodeTag tree_tag);
106};
107
108} // namespace blender::gpu::shader
unsigned int uint
static constexpr int GPU_MAX_SAFE_ATTR_NAME
GPUCodegenCreateInfo * create_info
GPUCodegen(GPUMaterial *mat_, GPUNodeGraph *graph_, const char *debug_name)
GPUNodeTag
const char * name
char attr_names[16][GPU_MAX_SAFE_ATTR_NAME+1]
const char * append_sampler_name(const char name[32])
Vector< std::unique_ptr< NameEntry >, 16 > sampler_names