Blender V5.3
gpu_shader_interface.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2016 by Mike Erwin. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#include "MEM_guardedalloc.h"
12
13#include "BLI_span.hh"
14#include "BLI_vector.hh"
15
18
19namespace blender::gpu {
20
21std::atomic<ShaderInterface::Key> ShaderInterface::next_uid_{1};
22
28
30{
31 /* Free memory used by name_buffer. */
32 MEM_SAFE_DELETE(name_buffer_);
33 MEM_SAFE_DELETE(inputs_);
34}
35
37{
38 if (dst.is_empty()) {
39 return;
40 }
41
43 MutableSpan<ShaderInput> src = inputs_vec.as_mutable_span();
44 src.copy_from(dst);
45
46 /* Simple sorting by going through the array and selecting the biggest element each time. */
47 for (uint i = 0; i < dst.size(); i++) {
48 ShaderInput *input_src = src.data();
49 for (uint j = 1; j < src.size(); j++) {
50 if (src[j].name_hash > input_src->name_hash) {
51 input_src = &src[j];
52 }
53 }
54 dst[i] = *input_src;
55 input_src->name_hash = 0;
56 }
57}
58
60{
61 /* Sorts all inputs inside their respective array.
62 * This is to allow fast hash collision detection.
63 * See `ShaderInterface::input_lookup` for more details. */
64 uint offset = 0;
66 offset += attr_len_;
68 offset += ubo_len_;
70 offset += uniform_len_;
72 offset += ssbo_len_;
74 offset += tlas_len_;
76 offset += constant_len_;
77}
78
97
99{
104 ssbo_len_);
105 char *name_buf = name_buffer_;
106 const char format[] = " | %.8x : %4d : %s\n";
107
108 if (attrs.size() > 0) {
109 printf("\n Attributes :\n");
110 }
111 for (const ShaderInput &attr : attrs) {
112 printf(format, attr.name_hash, attr.location, name_buf + attr.name_offset);
113 }
114
115 if (uniforms.size() > 0) {
116 printf("\n Uniforms :\n");
117 }
118 for (const ShaderInput &uni : uniforms) {
119 /* Bypass samplers. */
120 if (uni.binding == -1) {
121 printf(format, uni.name_hash, uni.location, name_buf + uni.name_offset);
122 }
123 }
124
125 if (ubos.size() > 0) {
126 printf("\n Uniform Buffer Objects :\n");
127 }
128 for (const ShaderInput &ubo : ubos) {
129 printf(format, ubo.name_hash, ubo.binding, name_buf + ubo.name_offset);
130 }
131
132 if (enabled_tex_mask_ > 0) {
133 printf("\n Samplers :\n");
134 }
135 for (const ShaderInput &samp : uniforms) {
136 /* Bypass uniforms. */
137 if (samp.binding != -1) {
138 printf(format, samp.name_hash, samp.binding, name_buf + samp.name_offset);
139 }
140 }
141
142 if (ssbos.size() > 0) {
143 printf("\n Shader Storage Objects :\n");
144 }
145 for (const ShaderInput &ssbo : ssbos) {
146 printf(format, ssbo.name_hash, ssbo.binding, name_buf + ssbo.name_offset);
147 }
148
149 printf("\n");
150}
151
152} // namespace blender::gpu
Read Blender memory allocation and freeing.
constexpr int64_t size() const
Definition BLI_span.hh:499
constexpr bool is_empty() const
Definition BLI_span.hh:515
constexpr T * data() const
Definition BLI_span.hh:545
constexpr void copy_from(Span< T > values) const
Definition BLI_span.hh:745
constexpr Span()=default
constexpr int64_t size() const
Definition BLI_span.hh:256
friend class Vector
void set_image_formats_from_info(const shader::ShaderCreateInfo &info)
static std::atomic< Key > next_uid_
std::array< TextureWriteFormat, GPU_MAX_IMAGE > image_formats_
static void sort_input_list(MutableSpan< ShaderInput > dst)
unsigned int uint
Definition BKE_text.h:55
Describe inputs & outputs, stage interfaces, resources and sources of a shader. If all data is correc...