Blender  V2.93
gpu_shader_interface.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2016 by Mike Erwin.
17  * All rights reserved.
18  */
19 
26 #include "MEM_guardedalloc.h"
27 
28 #include "BLI_span.hh"
29 #include "BLI_vector.hh"
30 
31 #include "gpu_shader_interface.hh"
32 
33 namespace blender::gpu {
34 
35 /* TODO(fclem): add unique ID for debugging. */
37 
39 {
40  /* Free memory used by name_buffer. */
43 }
44 
46 {
47  if (dst.size() == 0) {
48  return;
49  }
50 
51  Vector<ShaderInput> inputs_vec = Vector<ShaderInput>(dst.size());
52  MutableSpan<ShaderInput> src = inputs_vec.as_mutable_span();
53  src.copy_from(dst);
54 
55  /* Simple sorting by going through the array and selecting the biggest element each time. */
56  for (uint i = 0; i < dst.size(); i++) {
57  ShaderInput *input_src = &src[0];
58  for (uint j = 1; j < src.size(); j++) {
59  if (src[j].name_hash > input_src->name_hash) {
60  input_src = &src[j];
61  }
62  }
63  dst[i] = *input_src;
64  input_src->name_hash = 0;
65  }
66 }
67 
68 /* Sorts all inputs inside their respective array.
69  * This is to allow fast hash collision detection.
70  * See ShaderInterface::input_lookup for more details. */
72 {
76 }
77 
79 {
83  char *name_buf = name_buffer_;
84  const char format[] = " | %.8x : %4d : %s\n";
85 
86  if (attrs.size() > 0) {
87  printf("\n Attributes :\n");
88  }
89  for (const ShaderInput &attr : attrs) {
90  printf(format, attr.name_hash, attr.location, name_buf + attr.name_offset);
91  }
92 
93  if (uniforms.size() > 0) {
94  printf("\n Uniforms :\n");
95  }
96  for (const ShaderInput &uni : uniforms) {
97  /* Bypass samplers. */
98  if (uni.binding == -1) {
99  printf(format, uni.name_hash, uni.location, name_buf + uni.name_offset);
100  }
101  }
102 
103  if (ubos.size() > 0) {
104  printf("\n Uniform Buffer Objects :\n");
105  }
106  for (const ShaderInput &ubo : ubos) {
107  printf(format, ubo.name_hash, ubo.binding, name_buf + ubo.name_offset);
108  }
109 
110  if (enabled_tex_mask_ > 0) {
111  printf("\n Samplers :\n");
112  }
113  for (const ShaderInput &samp : uniforms) {
114  /* Bypass uniforms. */
115  if (samp.binding != -1) {
116  printf(format, samp.name_hash, samp.binding, name_buf + samp.name_offset);
117  }
118  }
119 
120  printf("\n");
121 }
122 
123 } // namespace blender::gpu
unsigned int uint
Definition: BLI_sys_types.h:83
Read Guarded memory(de)allocation.
constexpr int64_t size() const
Definition: BLI_span.hh:524
constexpr void copy_from(Span< T > values)
Definition: BLI_span.hh:694
constexpr int64_t size() const
Definition: BLI_span.hh:254
MutableSpan< T > as_mutable_span()
Definition: BLI_vector.hh:345
format
Definition: logImageCore.h:47
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:41
static void sort_input_list(MutableSpan< ShaderInput > dst)