Blender V5.0
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
21/* TODO(fclem): add unique ID for debugging. */
26
28{
29 /* Free memory used by name_buffer. */
32}
33
35{
36 if (dst.is_empty()) {
37 return;
38 }
39
42 src.copy_from(dst);
43
44 /* Simple sorting by going through the array and selecting the biggest element each time. */
45 for (uint i = 0; i < dst.size(); i++) {
46 ShaderInput *input_src = src.data();
47 for (uint j = 1; j < src.size(); j++) {
48 if (src[j].name_hash > input_src->name_hash) {
49 input_src = &src[j];
50 }
51 }
52 dst[i] = *input_src;
53 input_src->name_hash = 0;
54 }
55}
56
58{
59 /* Sorts all inputs inside their respective array.
60 * This is to allow fast hash collision detection.
61 * See `ShaderInterface::input_lookup` for more details. */
62 uint offset = 0;
64 offset += attr_len_;
66 offset += ubo_len_;
68 offset += uniform_len_;
70 offset += ssbo_len_;
72 offset += constant_len_;
73}
74
93
95{
100 ssbo_len_);
101 char *name_buf = name_buffer_;
102 const char format[] = " | %.8x : %4d : %s\n";
103
104 if (attrs.size() > 0) {
105 printf("\n Attributes :\n");
106 }
107 for (const ShaderInput &attr : attrs) {
108 printf(format, attr.name_hash, attr.location, name_buf + attr.name_offset);
109 }
110
111 if (uniforms.size() > 0) {
112 printf("\n Uniforms :\n");
113 }
114 for (const ShaderInput &uni : uniforms) {
115 /* Bypass samplers. */
116 if (uni.binding == -1) {
117 printf(format, uni.name_hash, uni.location, name_buf + uni.name_offset);
118 }
119 }
120
121 if (ubos.size() > 0) {
122 printf("\n Uniform Buffer Objects :\n");
123 }
124 for (const ShaderInput &ubo : ubos) {
125 printf(format, ubo.name_hash, ubo.binding, name_buf + ubo.name_offset);
126 }
127
128 if (enabled_tex_mask_ > 0) {
129 printf("\n Samplers :\n");
130 }
131 for (const ShaderInput &samp : uniforms) {
132 /* Bypass uniforms. */
133 if (samp.binding != -1) {
134 printf(format, samp.name_hash, samp.binding, name_buf + samp.name_offset);
135 }
136 }
137
138 if (ssbos.size() > 0) {
139 printf("\n Shader Storage Objects :\n");
140 }
141 for (const ShaderInput &ssbo : ssbos) {
142 printf(format, ssbo.name_hash, ssbo.binding, name_buf + ssbo.name_offset);
143 }
144
145 printf("\n");
146}
147
148} // namespace blender::gpu
unsigned int uint
Read Guarded memory(de)allocation.
#define MEM_SAFE_FREE(v)
constexpr int64_t size() const
Definition BLI_span.hh:493
constexpr bool is_empty() const
Definition BLI_span.hh:509
constexpr T * data() const
Definition BLI_span.hh:539
constexpr void copy_from(Span< T > values) const
Definition BLI_span.hh:739
constexpr int64_t size() const
Definition BLI_span.hh:252
MutableSpan< T > as_mutable_span()
void set_image_formats_from_info(const shader::ShaderCreateInfo &info)
std::array< TextureWriteFormat, GPU_MAX_IMAGE > image_formats_
#define printf(...)
format
static void sort_input_list(MutableSpan< ShaderInput > dst)
Describe inputs & outputs, stage interfaces, resources and sources of a shader. If all data is correc...
i
Definition text_draw.cc:230