Blender V5.3
vk_vertex_input_description.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
11#include "vk_common.hh"
12
13#include "BLI_map.hh"
14#include "BLI_mutex.hh"
15#include "BLI_vector.hh"
16
17#include "xxhash.h"
18
19#include <mutex>
20
21namespace blender::gpu {
22
31
33
34 void clear();
35
36 bool operator==(const VKVertexInputDescription &other) const
37 {
38 return attributes.size() == other.attributes.size() &&
39 bindings.size() == other.bindings.size() &&
40 memcmp(attributes.data(),
41 other.attributes.data(),
42 attributes.size() * sizeof(VkVertexInputAttributeDescription2EXT)) == 0 &&
43 memcmp(bindings.data(),
44 other.bindings.data(),
45 bindings.size() * sizeof(VkVertexInputBindingDescription2EXT)) == 0;
46 }
47
48 uint64_t hash() const
49 {
50 uint64_t hash = XXH3_64bits(attributes.data(),
51 attributes.size() * sizeof(VkVertexInputAttributeDescription2EXT));
52 hash = hash * 33 ^ XXH3_64bits(bindings.data(),
53 bindings.size() * sizeof(VkVertexInputBindingDescription2EXT));
54 return hash;
55 }
56};
57
64 public:
66 using Key = int64_t;
68 static constexpr Key invalid_key = INT64_MIN;
69
70 private:
71 Mutex mutex_;
72
75
76 public:
81 {
82 std::scoped_lock lock(mutex_);
83 Key *result_ptr = lookup_.lookup_ptr(description);
84 if (result_ptr != nullptr) {
85 return *result_ptr;
86 }
87
88 Key result = vertex_inputs_.size();
89 lookup_.add(description, result);
90 vertex_inputs_.append(std::make_unique<VKVertexInputDescription>(description));
91 return result;
92 }
93
100 {
101 std::scoped_lock lock(mutex_);
102 return *vertex_inputs_[key].get();
103 }
104};
105
106} // namespace blender::gpu
#define INT64_MIN
volatile int lock
Pool with all used vertex input descriptions.
const VKVertexInputDescription & get(Key key)
Get the vertex input description of the given key.
Key get_or_insert(VKVertexInputDescription &description)
Get the key of the given description. Will insert the description when it wasn't known.
unsigned __int64 uint64_t
Definition BKE_text.h:91
__int64 int64_t
Definition BKE_text.h:90
std::mutex Mutex
Definition BLI_mutex.hh:51
Description of vertex inputs used by graphic pipelines.
Vector< VkVertexInputAttributeDescription2EXT > attributes
bool operator==(const VKVertexInputDescription &other) const
Vector< VkVertexInputBindingDescription2EXT > bindings
int size() const
Definition vector.hh:130