RavEngine
Loading...
Searching...
No Matches
VkDevice.hpp
1#pragma once
2#include <RGL/Types.hpp>
3#include <RGL/Device.hpp>
4#include <optional>
5#include <memory>
6#include <volk.h>
7#include <RGL/Pipeline.hpp>
8#include "FreeList.hpp"
9
10#undef CreateSemaphore
11
12struct VmaAllocator_T;
13
14namespace RGL {
16 std::optional<uint32_t> graphicsFamily;
17 std::optional<uint32_t> presentFamily;
18 bool isComplete() {
19 return graphicsFamily.has_value() && presentFamily.has_value();
20 }
21 };
22
23 struct DeviceVk : public IDevice, public std::enable_shared_from_this<DeviceVk> {
24 VkDevice device = VK_NULL_HANDLE;
25 VkPhysicalDevice physicalDevice = VK_NULL_HANDLE; // does not need to be destroyed
26 QueueFamilyIndices indices;
27 VkQueue presentQueue = VK_NULL_HANDLE; // do not need to be destroyed
28 VkCommandPool commandPool = VK_NULL_HANDLE;
29 VmaAllocator_T* vkallocator;
30 PFN_vkCmdPushDescriptorSetKHR vkCmdPushDescriptorSetKHR = nullptr; // device-tied extension function
31
32 PFN_vkCmdEndDebugUtilsLabelEXT rgl_vkCmdEndDebugUtilsLabelEXT = nullptr;
33 PFN_vkCmdBeginDebugUtilsLabelEXT rgl_vkCmdBeginDebugUtilsLabelEXT = nullptr;
34
35 virtual ~DeviceVk();
36 DeviceVk(decltype(physicalDevice) physicalDevice);
37
38 void SetDebugNameForResource(void* resource, VkObjectType type, const char* debugName);
39
40 // IDevice
41 std::string GetBrandString() final;
42 RGLSwapchainPtr CreateSwapchain(RGLSurfacePtr, RGLCommandQueuePtr, int width, int height) final;
43 RGLPipelineLayoutPtr CreatePipelineLayout(const PipelineLayoutDescriptor&) final;
44 RGLRenderPipelinePtr CreateRenderPipeline(const RenderPipelineDescriptor&) final;
45 RGLComputePipelinePtr CreateComputePipeline(const ComputePipelineDescriptor&) final;
46
47 RGLShaderLibraryPtr CreateShaderLibraryFromName(const std::string_view& name) final;
48 RGLShaderLibraryPtr CreateDefaultShaderLibrary() final;
49 RGLShaderLibraryPtr CreateShaderLibraryFromBytes(const std::span<const uint8_t>) final;
50 RGLShaderLibraryPtr CreateShaderLibrarySourceCode(const std::string_view, const FromSourceConfig& config) final;
51 RGLShaderLibraryPtr CreateShaderLibraryFromPath(const std::filesystem::path&) final;
52
53 RGLBufferPtr CreateBuffer(const BufferConfig&) final;
54 RGLTexturePtr CreateTextureWithData(const TextureConfig&, const TextureUploadData&) final;
55 RGLTexturePtr CreateTexture(const TextureConfig&) final;
56
57 RGLSamplerPtr CreateSampler(const SamplerConfig&) final;
58
59 DeviceData GetDeviceData() final;
60
61 TextureView GetGlobalBindlessTextureHeap() const final;
62
63 RGLCommandQueuePtr CreateCommandQueue(QueueType type) final;
64 RGLFencePtr CreateFence(bool preSignaled) final;
65 void BlockUntilIdle() final;
66
67 size_t GetTotalVRAM() const final;
68 size_t GetCurrentVRAMInUse() const final;
69
70 uint32_t frameIndex = 0;
71
72 VkDescriptorSetLayout globalTextureDescriptorSetLayout = VK_NULL_HANDLE, globalBufferDescriptorSetLayout;
73
74 constexpr static uint32_t nTextureDescriptors = 2048; // made-up number (matches the DX backend)
75 FreeList<uint32_t, nTextureDescriptors> globalTextureDescriptorFreeList;
76
77 constexpr static uint32_t nBufferDescriptors = 65536; // matches DX backend
78 FreeList<uint32_t, nBufferDescriptors> globalBufferDescriptorFreeList;
79 VkDescriptorSet globalTextureDescriptorSet = VK_NULL_HANDLE, globalBufferDescriptorSet = VK_NULL_HANDLE;
80
81 private:
82
83 VkDescriptorPool globalTextureDescriptorPool = VK_NULL_HANDLE, globalBufferDescriptorPool = VK_NULL_HANDLE;
84 };
85
86 RGLDevicePtr CreateDefaultDeviceVk();
87}
Definition Buffer.hpp:21
Definition Pipeline.hpp:269
Definition VkDevice.hpp:23
Definition FreeList.hpp:7
Definition ShaderLibrary.hpp:11
Definition Device.hpp:35
Definition Pipeline.hpp:59
Definition VkDevice.hpp:15
Definition Pipeline.hpp:164
Definition Sampler.hpp:33
Definition Texture.hpp:138
Definition Texture.hpp:162
Definition Texture.hpp:43
Definition Device.hpp:17