Kale
Loading...
Searching...
No Matches
DeviceMemory.cpp
Go to the documentation of this file.
1/*
2 Copyright 2022 Rishi Challa
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17#ifdef KALE_VULKAN
18
19#include "DeviceMemory.hpp"
20
22
23using namespace Kale;
24using namespace Kale::Vulkan;
25
30 // Empty Body
31}
32
39DeviceMemory::DeviceMemory(Device& device, const vk::MemoryRequirements& requirements, vk::MemoryPropertyFlags properties) :
40 ChildResource(device), memoryInfo(requirements), memoryProperties(properties) {
42}
43
50void DeviceMemory::init(Device& device, const vk::MemoryRequirements& requirements, vk::MemoryPropertyFlags properties) {
51 ChildResource::init(device);
52 memoryInfo = requirements;
53 memoryProperties = properties;
55}
56
63DeviceMemory::DeviceMemory(Device& device, vk::MemoryRequirements&& requirements, vk::MemoryPropertyFlags properties) :
64 ChildResource(device), memoryInfo(std::move(requirements)), memoryProperties(properties) {
66}
67
74void DeviceMemory::init(Device& device, vk::MemoryRequirements&& requirements, vk::MemoryPropertyFlags properties) {
75 ChildResource::init(device);
76 memoryInfo = std::move(requirements);
77 memoryProperties = properties;
79}
80
85 uint32_t memoryType = parentPtr->findMemoryType(memoryInfo.memoryTypeBits, memoryProperties);
86 vk::MemoryAllocateInfo allocInfo(memoryInfo.size, memoryType);
87 deviceMemory = parentPtr->logicalDevice.get().allocateMemoryUnique(allocInfo);
88}
89
93void DeviceMemory::freeResources(bool remove) {
96 deviceMemory.reset();
97 memoryInfo = vk::MemoryRequirements();
98}
99
100#endif
virtual void freeResources(bool remove=true)
virtual void init(Parent &parent)
vk::UniqueDevice logicalDevice
Definition Device.hpp:59
uint32_t findMemoryType(uint32_t typeFilter, vk::MemoryPropertyFlags properties) const
Definition Device.cpp:178
vk::MemoryPropertyFlags memoryProperties
void init(Device &device, const vk::MemoryRequirements &requirements, vk::MemoryPropertyFlags properties)
vk::MemoryRequirements memoryInfo
vk::UniqueDeviceMemory deviceMemory
void freeResources(bool remove=true) override