Blender V4.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
11#include "MEM_guardedalloc.h"
12
13#include "BLI_span.hh"
14#include "BLI_vector.hh"
15
17
18namespace blender::gpu {
19
20/* TODO(fclem): add unique ID for debugging. */
22
24{
25 /* Free memory used by name_buffer. */
28}
29
31{
32 if (dst.is_empty()) {
33 return;
34 }
35
38 src.copy_from(dst);
39
40 /* Simple sorting by going through the array and selecting the biggest element each time. */
41 for (uint i = 0; i < dst.size(); i++) {
42 ShaderInput *input_src = src.data();
43 for (uint j = 1; j < src.size(); j++) {
44 if (src[j].name_hash > input_src->name_hash) {
45 input_src = &src[j];
46 }
47 }
48 dst[i] = *input_src;
49 input_src->name_hash = 0;
50 }
51}
52
54{
55 /* Sorts all inputs inside their respective array.
56 * This is to allow fast hash collision detection.
57 * See `ShaderInterface::input_lookup` for more details. */
58 uint offset = 0;
60 offset += attr_len_;
62 offset += ubo_len_;
64 offset += uniform_len_;
66 offset += ssbo_len_;
68 offset += constant_len_;
69}
70
72{
77 ssbo_len_);
78 char *name_buf = name_buffer_;
79 const char format[] = " | %.8x : %4d : %s\n";
80
81 if (attrs.size() > 0) {
82 printf("\n Attributes :\n");
83 }
84 for (const ShaderInput &attr : attrs) {
85 printf(format, attr.name_hash, attr.location, name_buf + attr.name_offset);
86 }
87
88 if (uniforms.size() > 0) {
89 printf("\n Uniforms :\n");
90 }
91 for (const ShaderInput &uni : uniforms) {
92 /* Bypass samplers. */
93 if (uni.binding == -1) {
94 printf(format, uni.name_hash, uni.location, name_buf + uni.name_offset);
95 }
96 }
97
98 if (ubos.size() > 0) {
99 printf("\n Uniform Buffer Objects :\n");
100 }
101 for (const ShaderInput &ubo : ubos) {
102 printf(format, ubo.name_hash, ubo.binding, name_buf + ubo.name_offset);
103 }
104
105 if (enabled_tex_mask_ > 0) {
106 printf("\n Samplers :\n");
107 }
108 for (const ShaderInput &samp : uniforms) {
109 /* Bypass uniforms. */
110 if (samp.binding != -1) {
111 printf(format, samp.name_hash, samp.binding, name_buf + samp.name_offset);
112 }
113 }
114
115 if (ssbos.size() > 0) {
116 printf("\n Shader Storage Objects :\n");
117 }
118 for (const ShaderInput &ssbo : ssbos) {
119 printf(format, ssbo.name_hash, ssbo.binding, name_buf + ssbo.name_offset);
120 }
121
122 printf("\n");
123}
124
125} // 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:494
constexpr bool is_empty() const
Definition BLI_span.hh:510
constexpr T * data() const
Definition BLI_span.hh:540
constexpr void copy_from(Span< T > values) const
Definition BLI_span.hh:726
constexpr int64_t size() const
Definition BLI_span.hh:253
MutableSpan< T > as_mutable_span()
#define printf
format
static void sort_input_list(MutableSpan< ShaderInput > dst)