Blender V4.5
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_vector.hh"
16
17#include "GPU_material.hh"
18#include "GPU_vertex_format.hh"
19#include "gpu_node_graph.hh"
21
22#include <sstream>
23#include <string>
24
25namespace blender::gpu::shader {
26
28 struct NameBuffer {
29 using NameEntry = std::array<char, 32>;
30
33 char var_names[16][8];
35
36 /* Returns the appended name memory location */
37 const char *append_sampler_name(const char name[32]);
38 };
39
45 std::string info_name_;
46
47 GPUCodegenCreateInfo(const char *name) : ShaderCreateInfo(name), info_name_(name)
48 {
49 /* Base class is always initialized first, so we need to update the name_ pointer here. */
50 name_ = info_name_.c_str();
51 };
53 {
54 MEM_delete(interface_generated);
55 }
56};
57
59 public:
64
65 private:
66 uint32_t hash_ = 0;
67 BLI_HashMurmur2A hm2a_;
68 ListBase ubo_inputs_ = {nullptr, nullptr};
69 GPUInput *cryptomatte_input_ = nullptr;
70
72 uint nodes_total_ = 0;
73 uint textures_total_ = 0;
74 uint uniforms_total_ = 0;
75
76 public:
77 GPUCodegen(GPUMaterial *mat_, GPUNodeGraph *graph_, const char *debug_name);
79
80 void generate_graphs();
83 void generate_attribs();
84 void generate_resources();
85 void generate_library();
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(std::stringstream &eval_ss, const GPUNode *node);
100 std::string graph_serialize(eGPUNodeTag tree_tag,
101 GPUNodeLink *output_link,
102 const char *output_default = nullptr);
103 std::string graph_serialize(eGPUNodeTag tree_tag);
104};
105
106} // 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)
eGPUNodeTag
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