-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
198 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
|
||
#include <imgui/imgui.h> | ||
|
||
#include "memory.h" | ||
|
||
namespace rvk::impl { | ||
|
||
using namespace rpp; | ||
|
||
Device_Memory::Device_Memory(const Arc<Physical_Device, Alloc>& physical_device, | ||
Arc<Device, Alloc> D, Heap location, u64 heap_size) | ||
: device(move(D)), allocator(heap_size), location(location) { | ||
|
||
VkMemoryAllocateFlagsInfo flags = {}; | ||
flags.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_FLAGS_INFO; | ||
flags.flags = VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT; | ||
|
||
VkMemoryAllocateInfo info = {}; | ||
info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; | ||
info.pNext = &flags; | ||
info.allocationSize = heap_size; | ||
info.memoryTypeIndex = device->heap_index(location); | ||
|
||
RVK_CHECK(vkAllocateMemory(*device, &info, null, &device_memory)); | ||
|
||
vkSetDeviceMemoryPriorityEXT(*device, device_memory, 1.0f); | ||
|
||
buffer_image_granularity = | ||
physical_device->properties().device.properties.limits.bufferImageGranularity; | ||
|
||
if(location == Heap::host) { | ||
RVK_CHECK(vkMapMemory(*device, device_memory, 0, VK_WHOLE_SIZE, 0, | ||
reinterpret_cast<void**>(&persistent_map))); | ||
} | ||
} | ||
|
||
Device_Memory::~Device_Memory() { | ||
if(persistent_map) { | ||
vkUnmapMemory(*device, device_memory); | ||
} | ||
if(device_memory) { | ||
vkFreeMemory(*device, device_memory, null); | ||
allocator.statistics().assert_clear(); | ||
info("[rvk] Freed GPU heap."); | ||
} | ||
persistent_map = null; | ||
device_memory = null; | ||
} | ||
|
||
typename Heap_Allocator::Stats Device_Memory::stats() { | ||
return allocator.statistics(); | ||
} | ||
|
||
} // namespace rvk::impl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
|
||
#pragma once | ||
|
||
#include <rpp/base.h> | ||
#include <rpp/range_allocator.h> | ||
#include <rpp/rc.h> | ||
|
||
#include "fwd.h" | ||
|
||
#include "device.h" | ||
|
||
namespace rvk::impl { | ||
|
||
using namespace rpp; | ||
|
||
using Heap_Allocator = Range_Allocator<Alloc, 32, 10>; | ||
using Buffer_Allocator = Range_Allocator<Alloc, 24, 6>; | ||
|
||
struct Device_Memory { | ||
|
||
explicit Device_Memory(const Arc<Physical_Device, Alloc>& physical_device, | ||
Arc<Device, Alloc> device, Heap location, u64 size); | ||
~Device_Memory(); | ||
|
||
Device_Memory(const Device_Memory&) = delete; | ||
Device_Memory& operator=(const Device_Memory&) = delete; | ||
Device_Memory(Device_Memory&&) = delete; | ||
Device_Memory& operator=(Device_Memory&&) = delete; | ||
|
||
// Opt<Buffer> allocate(u64 size, VkBufferUsageFlags usage); | ||
// Opt<Image> allocate(u32 width, u32 height, VkFormat format, VkImageUsageFlags usage); | ||
|
||
Heap_Allocator::Stats stats(); | ||
|
||
private: | ||
Arc<Device, Alloc> device; | ||
|
||
VkDeviceMemory device_memory = null; | ||
|
||
Heap location = Heap::device; | ||
u8* persistent_map = null; | ||
u64 buffer_image_granularity = 0; | ||
Heap_Allocator allocator; | ||
}; | ||
|
||
} // namespace rvk::impl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
#include <imgui/imgui.h> | ||
|
||
#include "device.h" | ||
#include "swapchain.h" | ||
|
||
namespace rvk::impl { | ||
|
||
using namespace rpp; | ||
|
||
} // namespace rvk::impl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
|
||
#pragma once | ||
|
||
#include <rpp/base.h> | ||
#include <rpp/rc.h> | ||
|
||
#include "fwd.h" | ||
|
||
namespace rvk::impl { | ||
|
||
using namespace rpp; | ||
|
||
struct Swapchain { | ||
|
||
explicit Swapchain(const Arc<Physical_Device, Alloc>& physical_device, | ||
Arc<Device, Alloc> device, VkSurfaceKHR surface); | ||
~Swapchain(); | ||
|
||
Swapchain(const Swapchain&) = delete; | ||
Swapchain& operator=(const Swapchain&) = delete; | ||
Swapchain(Swapchain&&) = delete; | ||
Swapchain& operator=(Swapchain&&) = delete; | ||
|
||
VkFormat format() { | ||
return surface_format.format; | ||
} | ||
VkExtent2D dimensions() { | ||
return extent; | ||
} | ||
u64 slot_count() { | ||
return slots.length(); | ||
} | ||
u32 min_image_count() { | ||
return min_images; | ||
} | ||
// Image_View& slot(u64 i) { | ||
// return slots[i].view; | ||
// } | ||
|
||
operator VkSwapchainKHR() { | ||
return swapchain; | ||
} | ||
|
||
private: | ||
static VkExtent2D choose_extent(VkSurfaceCapabilitiesKHR capabilities); | ||
static VkSurfaceFormatKHR choose_format(Slice<VkSurfaceFormatKHR> formats); | ||
static VkPresentModeKHR choose_present_mode(Slice<VkPresentModeKHR> modes); | ||
|
||
Arc<Device, Alloc> device; | ||
|
||
struct Slot { | ||
// Image image; | ||
// Image_View view; | ||
}; | ||
Vec<Slot, Alloc> slots; | ||
|
||
VkSwapchainKHR swapchain = null; | ||
|
||
u32 min_images = 0; | ||
VkExtent2D extent = {}; | ||
VkPresentModeKHR present_mode = {}; | ||
VkSurfaceFormatKHR surface_format = {}; | ||
}; | ||
|
||
} // namespace rvk::impl |