Blender  V3.3
gpu_shader_interface.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2016 by Mike Erwin. All rights reserved. */
3 
10 #include "MEM_guardedalloc.h"
11 
12 #include "BLI_span.hh"
13 #include "BLI_vector.hh"
14 
15 #include "gpu_shader_interface.hh"
16 
17 namespace blender::gpu {
18 
19 /* TODO(fclem): add unique ID for debugging. */
21 
23 {
24  /* Free memory used by name_buffer. */
27 }
28 
30 {
31  if (dst.size() == 0) {
32  return;
33  }
34 
35  Vector<ShaderInput> inputs_vec = Vector<ShaderInput>(dst.size());
37  src.copy_from(dst);
38 
39  /* Simple sorting by going through the array and selecting the biggest element each time. */
40  for (uint i = 0; i < dst.size(); i++) {
41  ShaderInput *input_src = src.data();
42  for (uint j = 1; j < src.size(); j++) {
43  if (src[j].name_hash > input_src->name_hash) {
44  input_src = &src[j];
45  }
46  }
47  dst[i] = *input_src;
48  input_src->name_hash = 0;
49  }
50 }
51 
53 {
54  /* Sorts all inputs inside their respective array.
55  * This is to allow fast hash collision detection.
56  * See `ShaderInterface::input_lookup` for more details. */
57 
63 }
64 
66 {
71  ssbo_len_);
72  char *name_buf = name_buffer_;
73  const char format[] = " | %.8x : %4d : %s\n";
74 
75  if (attrs.size() > 0) {
76  printf("\n Attributes :\n");
77  }
78  for (const ShaderInput &attr : attrs) {
79  printf(format, attr.name_hash, attr.location, name_buf + attr.name_offset);
80  }
81 
82  if (uniforms.size() > 0) {
83  printf("\n Uniforms :\n");
84  }
85  for (const ShaderInput &uni : uniforms) {
86  /* Bypass samplers. */
87  if (uni.binding == -1) {
88  printf(format, uni.name_hash, uni.location, name_buf + uni.name_offset);
89  }
90  }
91 
92  if (ubos.size() > 0) {
93  printf("\n Uniform Buffer Objects :\n");
94  }
95  for (const ShaderInput &ubo : ubos) {
96  printf(format, ubo.name_hash, ubo.binding, name_buf + ubo.name_offset);
97  }
98 
99  if (enabled_tex_mask_ > 0) {
100  printf("\n Samplers :\n");
101  }
102  for (const ShaderInput &samp : uniforms) {
103  /* Bypass uniforms. */
104  if (samp.binding != -1) {
105  printf(format, samp.name_hash, samp.binding, name_buf + samp.name_offset);
106  }
107  }
108 
109  if (ssbos.size() > 0) {
110  printf("\n Shader Storage Objects :\n");
111  }
112  for (const ShaderInput &ssbo : ssbos) {
113  printf(format, ssbo.name_hash, ssbo.binding, name_buf + ssbo.name_offset);
114  }
115 
116  printf("\n");
117 }
118 
119 } // namespace blender::gpu
unsigned int uint
Definition: BLI_sys_types.h:67
Read Guarded memory(de)allocation.
constexpr int64_t size() const
Definition: BLI_span.hh:511
constexpr int64_t size() const
Definition: BLI_span.hh:240
MutableSpan< T > as_mutable_span()
Definition: BLI_vector.hh:330
SyclQueue void void * src
format
Definition: logImageCore.h:38
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:27
static void sort_input_list(MutableSpan< ShaderInput > dst)