forked from KhronosGroup/Vulkan-ValidationLayers
-
Notifications
You must be signed in to change notification settings - Fork 1
/
device_memory_state.cpp
103 lines (98 loc) · 3.98 KB
/
device_memory_state.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/* Copyright (c) 2015-2021 The Khronos Group Inc.
* Copyright (c) 2015-2021 Valve Corporation
* Copyright (c) 2015-2021 LunarG, Inc.
* Copyright (C) 2015-2021 Google Inc.
* Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Author: Courtney Goeltzenleuchter <[email protected]>
* Author: Tobin Ehlis <[email protected]>
* Author: Chris Forbes <[email protected]>
* Author: Mark Lobodzinski <[email protected]>
* Author: Dave Houlton <[email protected]>
* Author: John Zulauf <[email protected]>
* Author: Tobias Hector <[email protected]>
* Author: Jeremy Gebben <[email protected]>
*/
#include "device_memory_state.h"
#include "image_state.h"
void DEVICE_MEMORY_STATE::RemoveParent(BASE_NODE *parent) {
// Prevent Control Flow Integrity failures from casting any parent to IMAGE_STATE,
// Other parent types do not participate in the bound_images spider web.
// TODO: This is not a great solution and bound_images should be cleaned up by further
// state object refactoring.
if (parent->Handle().type == kVulkanObjectTypeImage) {
auto it = bound_images.find(static_cast<IMAGE_STATE *>(parent));
if (it != bound_images.end()) {
IMAGE_STATE *image_state = *it;
image_state->aliasing_images.clear();
bound_images.erase(it);
}
}
BASE_NODE::RemoveParent(parent);
}
void DEVICE_MEMORY_STATE::Destroy() {
// This is one way clear. Because the bound_images include cross references, the one way clear loop could clear the whole
// reference. It doesn't need two ways clear.
for (auto *bound_image : bound_images) {
if (bound_image) {
bound_image->aliasing_images.clear();
}
}
BASE_NODE::Destroy();
}
void BINDABLE::Destroy() {
if (!sparse) {
if (binding.mem_state) {
binding.mem_state->RemoveParent(this);
}
} else { // Sparse, clear all bindings
for (auto &sparse_mem_binding : sparse_bindings) {
if (sparse_mem_binding.mem_state) {
sparse_mem_binding.mem_state->RemoveParent(this);
}
}
}
BASE_NODE::Destroy();
}
// SetMemBinding is used to establish immutable, non-sparse binding between a single image/buffer object and memory object.
// Corresponding valid usage checks are in ValidateSetMemBinding().
void BINDABLE::SetMemBinding(std::shared_ptr<DEVICE_MEMORY_STATE> &mem, VkDeviceSize memory_offset) {
if (!mem) {
return;
}
binding.mem_state = mem;
binding.offset = memory_offset;
binding.size = requirements.size;
binding.mem_state->AddParent(this);
UpdateBoundMemorySet(); // force recreation of cached set
}
// For NULL mem case, clear any previous binding Else...
// Make sure given object is in its object map
// IF a previous binding existed, update binding
// Add reference from objectInfo to memoryInfo
// Add reference off of object's binding info
// Return VK_TRUE if addition is successful, VK_FALSE otherwise
void BINDABLE::SetSparseMemBinding(std::shared_ptr<DEVICE_MEMORY_STATE> &mem, const VkDeviceSize mem_offset,
const VkDeviceSize mem_size) {
if (!mem) {
return;
}
assert(sparse);
MEM_BINDING sparse_binding = {mem, mem_offset, mem_size};
sparse_binding.mem_state->AddParent(this);
// Need to set mem binding for this object
sparse_bindings.insert(sparse_binding);
UpdateBoundMemorySet();
}