|
TachyonUI 0.1.0
High-performance UI for building tools.
|
The Vulkan device the GUI renders with: its own, or a host's (SetExternalDevice). More...
#include <gui_core/graphics/vulkan/vk_device_context.h>
Classes | |
| struct | InstanceDebugConfig |
| Diagnostic hook for the GPU test harness: the instance is built with this debug callback instead of the default printing messenger, and optionally with synchronization validation, so tests can fail on validation errors. More... | |
| struct | ExternalDevice |
| A host's Vulkan handles for SetExternalDevice, so the GUI renders on the host's device (an engine hosting it as its editor, say) and can share resources with it. More... | |
| struct | DeviceRequirements |
| What a device must provide for the GUI to run on it. More... | |
Public Types | |
| using | SurfaceFactory = std::function<VkSurfaceKHR(VkInstance, const VkAllocationCallbacks*, tachyon::OSWindowHandle)> |
| Makes a VkSurfaceKHR for one of the window backend's windows with the given instance and allocation callbacks; VK_NULL_HANDLE on failure. | |
Public Member Functions | |
| void | SetSurfaceFactory (SurfaceFactory factory) |
| How surfaces are made; set before initialization. SDLWindowBackend installs its own. | |
| void | SetAllocationHooks (const tachyon::AllocationHooks &hooks) |
| Host memory functions for every Vulkan object, vk-bootstrap and VMA. | |
| const VkAllocationCallbacks * | AllocationCallbacks () const |
| What the vkCreate*/vkDestroy* calls pass; null when no hooks are set. | |
| void | SetInstanceDebugConfig (const InstanceDebugConfig &cfg) |
| Sets the instance debug config; call before initialization (no effect after). | |
| void | SetExternalDevice (const ExternalDevice &external) |
| Renders on the host's device instead of making one; call before initialization. | |
| bool | UsesExternalDevice () const noexcept |
| Whether SetExternalDevice was called; a lost host device isn't recreated. | |
| std::unique_lock< std::mutex > | LockQueue () const |
| Locks the queue for the duration of a submit or present. | |
| void | WaitIdle () const |
| Waits until the device is idle, holding the queue lock (vkDeviceWaitIdle needs every queue externally synchronized). | |
| tachyon::Image * | CreateImage (tachyon::uint2 size, tachyon::ImageFormat format, tachyon::Sampler sampler, bool mipmapped=false) const |
| An image nothing is uploaded to (undefined contents), for sampling only. | |
| tachyon::Image * | CreateImage (const void *data, tachyon::uint2 size, tachyon::ImageFormat format, tachyon::Sampler sampler, bool mipmapped=false) |
| An image from data pixels (null: cleared). | |
| void | RecordPendingUploads (VkCommandBuffer cmd) |
| Records the queued uploads into cmd, outside any rendering scope. | |
| tachyon::RHI::ResidentBufferId | CreateResidentBuffer (std::span< const tachyon::RHI::UploadRequest > requests, std::span< tachyon::DeviceAddress > addresses) |
| Library internal: GPU-only storage for the packed requests, copied in from a staging buffer by the next RecordPendingUploads (see RHI::RenderCommandList::UploadResidentBuffers). | |
| tachyon::RHI::ResidentState | GetResidentBufferState (tachyon::RHI::ResidentBufferId id) const |
| Library internal: whether the buffer exists and has been copied to the GPU. | |
| void | ReleaseResidentBuffer (tachyon::RHI::ResidentBufferId id) |
| Library internal: frees the buffer now if its copy was never recorded, else when the frame deletion queue flushes. | |
| size_t | ResidentBufferCount () const |
| Library internal: the resident buffers not released. | |
| UploadWorker & | Uploads () const |
| Library internal: copies into mapped memory, off the main thread. | |
| void | WaitForUploads () const |
| void | DestroyImage (tachyon::Image *img) |
| Destroys the image's Vulkan objects now, without waiting for the GPU; doesn't delete the object. | |
| void | ReleaseLiveImages () |
| After a device loss: frees the live images' Vulkan objects; the image objects stay. | |
| void | RebuildLiveImages () |
| Makes the released images again on the new device, uploading the pixels they were made from. | |
| void | DestroyImageAtEnd (tachyon::Image *img, tachyon::DeviceScope scope, const std::source_location &loc=std::source_location::current()) |
| Destroys the image and deletes the object when the scope's deletion queue flushes. | |
| tachyon::Buffer * | UploadVisualColorStyles (::std::span< const tachyon::VisualColorStyle > colorStyles) const |
| Library internal: the color styles in a GPU buffer for the shaders. | |
| void | DestroyVisualColorStyles (tachyon::Buffer *buffer) |
| Library internal: destroys the buffer's GPU objects now. | |
| void | DestroyVisualColorStylesAtEnd (tachyon::Buffer *buffer, tachyon::DeviceScope scope, const std::source_location &loc=std::source_location::current()) |
| Library internal: destroys and deletes the buffer when the scope's queue flushes. | |
| tachyon::Buffer * | UploadVisualBoxStyles (::std::span< const tachyon::VisualBoxStyle > styles) const |
| Library internal: the box styles in a GPU buffer for the shaders. | |
| void | DestroyVisualBoxStyles (tachyon::Buffer *buffer) |
| Library internal: destroys the buffer's GPU objects now. | |
| void | DestroyVisualBoxStylesAtEnd (tachyon::Buffer *buffer, tachyon::DeviceScope scope, const std::source_location &loc=std::source_location::current()) |
| Library internal: destroys and deletes the buffer when the scope's queue flushes. | |
| DeletionQueue & | GetDeletionQueue (tachyon::DeviceScope scope) |
| Library internal: the current frame's deletion queue, or for DeviceScope::Application the one flushed at Destroy. | |
| void | AdvanceFrameAndFlushDeletions () |
| Call once per frame, after every window's BeginWindowFrame: flushes the slot last pushed to FRAME_OVERLAP frames ago, whose GPU work those fence waits have finished. | |
| bool | Initialize () |
| Library internal: finishes the bring-up that the first CreateSurface does; false when that failed (see initError). | |
| void | Flush () |
| Waits for the GPU and flushes the frame deletion queues. | |
| void | Destroy () |
| Waits for the GPU, flushes every deletion queue and destroys what the GUI made. | |
| VkSurfaceKHR | CreateSurface (tachyon::OSWindowHandle windowHandle) |
| A surface for the window, through the surface factory. | |
| Buffer | CreateBuffer (size_t allocSize, VkBufferUsageFlags usage, VmaMemoryUsage memoryUsage) const |
| Library internal: a VMA buffer. | |
| void | DestroyBuffer (const Buffer &buffer) const |
| Library internal: destroys a CreateBuffer buffer now. | |
| Buffer | CreateMappedStorageBuffer (const void *data, size_t size, VkDeviceAddress &outAddress) const |
| Library internal: a host-visible, persistently mapped storage buffer with a device address, filled by memcpy (no staging, no blocking submit). | |
| VulkanImage | CreateImage (VkExtent3D size, VkFormat format, VkImageUsageFlags usage, VkSampler sampler, bool mipmapped=false) const |
| Library internal: a VMA image with its view. | |
| void | DestroyImage (const VulkanImage &img) |
| Library internal: destroys the image and its view now. | |
| VisualBoxStyleBuffers | UploadMesh (::std::span< const tachyon::VisualBoxStyle > visualBoxStyles) const |
| Library internal: the box styles in GPU buffers. Per-primitive uploads go through the RHI. | |
| VisualColorStyleBuffers | UploadMesh (::std::span< const tachyon::VisualColorStyle > colorStyles) const |
| Library internal: the color styles in GPU buffers. | |
| void | DestroyMesh (const VisualBoxStyleBuffers &mesh) const |
| Library internal: destroys the style buffers now. | |
| void | DestroyMesh (const VisualColorStyleBuffers &mesh) const |
| Library internal: destroys the style buffers now. | |
| VkShaderModule | CreateShader (::std::span< uint32_t > spirvBuffer) const |
| Library internal: a shader module from SPIR-V words. | |
| void | DestroyShader (const VkShaderModule &shader) const |
| Library internal. | |
Static Public Member Functions | |
| static DeviceRequirements | GetDeviceRequirements () |
| What a host's device must enable for the GUI. | |
| static bool | CheckPhysicalDeviceSupport (VkPhysicalDevice physicalDevice, std::string *problems) |
| Checks that a physical device can support GetDeviceRequirements(). | |
Public Attributes | |
| FrameWaits | frameWaits |
| Library internal: the timeline semaphores the frame's submissions wait on. | |
| std::string | shaderDirectory |
| Where to load the compiled shaders from; empty uses the built-in ones. | |
| GUIRenderContext | renderContext |
| Library internal: the GUI's pipelines. | |
| VkInstance | instance |
| The instance; the host's with SetExternalDevice. | |
| VkDevice | device |
| The device; the host's with SetExternalDevice. | |
| VmaAllocator | allocator |
| The allocator; the host's when it passed one. | |
| VkPhysicalDevice | chosenGPU |
| The GPU the device runs on. | |
| VkFence | immFence |
| Library internal: the immediate-submit fence. | |
| VkCommandBuffer | immCommandBuffer |
| Library internal. | |
| VkCommandPool | immCommandPool |
| Library internal. | |
| VkQueue | graphicsQueue |
| The queue every GUI submit and present goes to; the host's with SetExternalDevice. | |
| uint32_t | graphicsQueueFamily |
| graphicsQueue's family. | |
| VkDescriptorSetLayout | singleImageDescriptorLayout |
| Library internal: the layout of a one-image descriptor set. | |
| VkSampler | defaultSamplerLinear |
| For Sampler::LinearRepeat. | |
| VkSampler | defaultSamplerNearest |
| For Sampler::NearestRepeat. | |
| VkSampler | defaultSamplerLinearClampToEdge |
| For Sampler::LinearClampToEdge. | |
| DeletionQueue | mainDeletionQueue |
| Flushed at Destroy (DeviceScope::Application). | |
| std::array< DeletionQueue, FRAME_DELETION_SLOT_COUNT > | frameDeletionQueues |
| One per frame slot; see AdvanceFrameAndFlushDeletions. | |
| uint64_t | frameNumber { 0 } |
| Frames advanced so far; picks the frame deletion slot. | |
| VkDebugUtilsMessengerEXT | debug_messenger |
| The default debug messenger, when the GUI made the instance with one. | |
| VkCommandPoolCreateInfo | commandPoolInfo |
| Library internal: reused for the window contexts' command pools. | |
| VkFenceCreateInfo | fenceCreateInfo |
| Library internal: reused for the window contexts' fences. | |
| bool | initialized { false } |
| Whether the device is up (made or adopted). | |
| tachyon::Error | initError {} |
| why the bring-up failed, when it did | |
The Vulkan device the GUI renders with: its own, or a host's (SetExternalDevice).
It lives in VulkanGraphicsContext::deviceContext; set it up before GUIApplication::Initialize.
| using tachyon::vulkan::VulkanDeviceContext::SurfaceFactory = std::function<VkSurfaceKHR(VkInstance, const VkAllocationCallbacks*, tachyon::OSWindowHandle)> |
Makes a VkSurfaceKHR for one of the window backend's windows with the given instance and allocation callbacks; VK_NULL_HANDLE on failure.
The GUI destroys the surfaces.
|
inline |
How surfaces are made; set before initialization. SDLWindowBackend installs its own.
| void tachyon::vulkan::VulkanDeviceContext::SetAllocationHooks | ( | const tachyon::AllocationHooks & | hooks | ) |
Host memory functions for every Vulkan object, vk-bootstrap and VMA.
Call before initialization.
|
inline |
What the vkCreate*/vkDestroy* calls pass; null when no hooks are set.
|
inline |
Sets the instance debug config; call before initialization (no effect after).
|
inline |
Renders on the host's device instead of making one; call before initialization.
|
inlinenodiscardnoexcept |
Whether SetExternalDevice was called; a lost host device isn't recreated.
|
staticnodiscard |
What a host's device must enable for the GUI.
The feature structs have no pNext chain; a host chains them itself.
|
staticnodiscard |
Checks that a physical device can support GetDeviceRequirements().
Appends a line per missing capability to problems when non-null. This cannot verify what the host actually enabled at device creation.
|
inlinenodiscard |
Locks the queue for the duration of a submit or present.
Every vkQueueSubmit/vkQueuePresentKHR on graphicsQueue must hold this.
| void tachyon::vulkan::VulkanDeviceContext::WaitIdle | ( | ) | const |
Waits until the device is idle, holding the queue lock (vkDeviceWaitIdle needs every queue externally synchronized).
| tachyon::Image * tachyon::vulkan::VulkanDeviceContext::CreateImage | ( | tachyon::uint2 | size, |
| tachyon::ImageFormat | format, | ||
| tachyon::Sampler | sampler, | ||
| bool | mipmapped = false ) const |
An image nothing is uploaded to (undefined contents), for sampling only.
| tachyon::Image * tachyon::vulkan::VulkanDeviceContext::CreateImage | ( | const void * | data, |
| tachyon::uint2 | size, | ||
| tachyon::ImageFormat | format, | ||
| tachyon::Sampler | sampler, | ||
| bool | mipmapped = false ) |
An image from data pixels (null: cleared).
Doesn't wait for the GPU: the upload and mip generation are recorded at the start of the next window frame (RecordPendingUploads).
| void tachyon::vulkan::VulkanDeviceContext::RecordPendingUploads | ( | VkCommandBuffer | cmd | ) |
Records the queued uploads into cmd, outside any rendering scope.
| tachyon::RHI::ResidentBufferId tachyon::vulkan::VulkanDeviceContext::CreateResidentBuffer | ( | std::span< const tachyon::RHI::UploadRequest > | requests, |
| std::span< tachyon::DeviceAddress > | addresses ) |
Library internal: GPU-only storage for the packed requests, copied in from a staging buffer by the next RecordPendingUploads (see RHI::RenderCommandList::UploadResidentBuffers).
| tachyon::RHI::ResidentState tachyon::vulkan::VulkanDeviceContext::GetResidentBufferState | ( | tachyon::RHI::ResidentBufferId | id | ) | const |
Library internal: whether the buffer exists and has been copied to the GPU.
| void tachyon::vulkan::VulkanDeviceContext::ReleaseResidentBuffer | ( | tachyon::RHI::ResidentBufferId | id | ) |
Library internal: frees the buffer now if its copy was never recorded, else when the frame deletion queue flushes.
|
inline |
Library internal: the resident buffers not released.
|
inline |
Library internal: copies into mapped memory, off the main thread.
Everything a submit reads must be copied first: WaitForUploads before vkQueueSubmit.
|
inline |
| void tachyon::vulkan::VulkanDeviceContext::DestroyImage | ( | tachyon::Image * | img | ) |
Destroys the image's Vulkan objects now, without waiting for the GPU; doesn't delete the object.
| void tachyon::vulkan::VulkanDeviceContext::ReleaseLiveImages | ( | ) |
After a device loss: frees the live images' Vulkan objects; the image objects stay.
| void tachyon::vulkan::VulkanDeviceContext::RebuildLiveImages | ( | ) |
Makes the released images again on the new device, uploading the pixels they were made from.
| void tachyon::vulkan::VulkanDeviceContext::DestroyImageAtEnd | ( | tachyon::Image * | img, |
| tachyon::DeviceScope | scope, | ||
| const std::source_location & | loc = std::source_location::current() ) |
Destroys the image and deletes the object when the scope's deletion queue flushes.
| tachyon::Buffer * tachyon::vulkan::VulkanDeviceContext::UploadVisualColorStyles | ( | ::std::span< const tachyon::VisualColorStyle > | colorStyles | ) | const |
Library internal: the color styles in a GPU buffer for the shaders.
| void tachyon::vulkan::VulkanDeviceContext::DestroyVisualColorStyles | ( | tachyon::Buffer * | buffer | ) |
Library internal: destroys the buffer's GPU objects now.
| void tachyon::vulkan::VulkanDeviceContext::DestroyVisualColorStylesAtEnd | ( | tachyon::Buffer * | buffer, |
| tachyon::DeviceScope | scope, | ||
| const std::source_location & | loc = std::source_location::current() ) |
Library internal: destroys and deletes the buffer when the scope's queue flushes.
| tachyon::Buffer * tachyon::vulkan::VulkanDeviceContext::UploadVisualBoxStyles | ( | ::std::span< const tachyon::VisualBoxStyle > | styles | ) | const |
Library internal: the box styles in a GPU buffer for the shaders.
| void tachyon::vulkan::VulkanDeviceContext::DestroyVisualBoxStyles | ( | tachyon::Buffer * | buffer | ) |
Library internal: destroys the buffer's GPU objects now.
| void tachyon::vulkan::VulkanDeviceContext::DestroyVisualBoxStylesAtEnd | ( | tachyon::Buffer * | buffer, |
| tachyon::DeviceScope | scope, | ||
| const std::source_location & | loc = std::source_location::current() ) |
Library internal: destroys and deletes the buffer when the scope's queue flushes.
|
inline |
Library internal: the current frame's deletion queue, or for DeviceScope::Application the one flushed at Destroy.
|
inline |
Call once per frame, after every window's BeginWindowFrame: flushes the slot last pushed to FRAME_OVERLAP frames ago, whose GPU work those fence waits have finished.
| bool tachyon::vulkan::VulkanDeviceContext::Initialize | ( | ) |
Library internal: finishes the bring-up that the first CreateSurface does; false when that failed (see initError).
| void tachyon::vulkan::VulkanDeviceContext::Flush | ( | ) |
Waits for the GPU and flushes the frame deletion queues.
| void tachyon::vulkan::VulkanDeviceContext::Destroy | ( | ) |
Waits for the GPU, flushes every deletion queue and destroys what the GUI made.
| VkSurfaceKHR tachyon::vulkan::VulkanDeviceContext::CreateSurface | ( | tachyon::OSWindowHandle | windowHandle | ) |
A surface for the window, through the surface factory.
The first call also makes the device (or adopts the host's) on a GPU that can present to it. VK_NULL_HANDLE on failure.
| Buffer tachyon::vulkan::VulkanDeviceContext::CreateBuffer | ( | size_t | allocSize, |
| VkBufferUsageFlags | usage, | ||
| VmaMemoryUsage | memoryUsage ) const |
Library internal: a VMA buffer.
| void tachyon::vulkan::VulkanDeviceContext::DestroyBuffer | ( | const Buffer & | buffer | ) | const |
Library internal: destroys a CreateBuffer buffer now.
| Buffer tachyon::vulkan::VulkanDeviceContext::CreateMappedStorageBuffer | ( | const void * | data, |
| size_t | size, | ||
| VkDeviceAddress & | outAddress ) const |
Library internal: a host-visible, persistently mapped storage buffer with a device address, filled by memcpy (no staging, no blocking submit).
Empty, with outAddress 0, for size 0.
| VulkanImage tachyon::vulkan::VulkanDeviceContext::CreateImage | ( | VkExtent3D | size, |
| VkFormat | format, | ||
| VkImageUsageFlags | usage, | ||
| VkSampler | sampler, | ||
| bool | mipmapped = false ) const |
Library internal: a VMA image with its view.
| void tachyon::vulkan::VulkanDeviceContext::DestroyImage | ( | const VulkanImage & | img | ) |
Library internal: destroys the image and its view now.
| VisualBoxStyleBuffers tachyon::vulkan::VulkanDeviceContext::UploadMesh | ( | ::std::span< const tachyon::VisualBoxStyle > | visualBoxStyles | ) | const |
Library internal: the box styles in GPU buffers. Per-primitive uploads go through the RHI.
| VisualColorStyleBuffers tachyon::vulkan::VulkanDeviceContext::UploadMesh | ( | ::std::span< const tachyon::VisualColorStyle > | colorStyles | ) | const |
Library internal: the color styles in GPU buffers.
| void tachyon::vulkan::VulkanDeviceContext::DestroyMesh | ( | const VisualBoxStyleBuffers & | mesh | ) | const |
Library internal: destroys the style buffers now.
| void tachyon::vulkan::VulkanDeviceContext::DestroyMesh | ( | const VisualColorStyleBuffers & | mesh | ) | const |
Library internal: destroys the style buffers now.
| VkShaderModule tachyon::vulkan::VulkanDeviceContext::CreateShader | ( | ::std::span< uint32_t > | spirvBuffer | ) | const |
Library internal: a shader module from SPIR-V words.
| void tachyon::vulkan::VulkanDeviceContext::DestroyShader | ( | const VkShaderModule & | shader | ) | const |
Library internal.
| FrameWaits tachyon::vulkan::VulkanDeviceContext::frameWaits |
Library internal: the timeline semaphores the frame's submissions wait on.
| std::string tachyon::vulkan::VulkanDeviceContext::shaderDirectory |
Where to load the compiled shaders from; empty uses the built-in ones.
| GUIRenderContext tachyon::vulkan::VulkanDeviceContext::renderContext |
Library internal: the GUI's pipelines.
| VkInstance tachyon::vulkan::VulkanDeviceContext::instance |
The instance; the host's with SetExternalDevice.
| VkDevice tachyon::vulkan::VulkanDeviceContext::device |
The device; the host's with SetExternalDevice.
| VmaAllocator tachyon::vulkan::VulkanDeviceContext::allocator |
The allocator; the host's when it passed one.
| VkPhysicalDevice tachyon::vulkan::VulkanDeviceContext::chosenGPU |
The GPU the device runs on.
| VkFence tachyon::vulkan::VulkanDeviceContext::immFence |
Library internal: the immediate-submit fence.
| VkCommandBuffer tachyon::vulkan::VulkanDeviceContext::immCommandBuffer |
Library internal.
| VkCommandPool tachyon::vulkan::VulkanDeviceContext::immCommandPool |
Library internal.
| VkQueue tachyon::vulkan::VulkanDeviceContext::graphicsQueue |
The queue every GUI submit and present goes to; the host's with SetExternalDevice.
| uint32_t tachyon::vulkan::VulkanDeviceContext::graphicsQueueFamily |
graphicsQueue's family.
| VkDescriptorSetLayout tachyon::vulkan::VulkanDeviceContext::singleImageDescriptorLayout |
Library internal: the layout of a one-image descriptor set.
| VkSampler tachyon::vulkan::VulkanDeviceContext::defaultSamplerLinear |
| VkSampler tachyon::vulkan::VulkanDeviceContext::defaultSamplerNearest |
| VkSampler tachyon::vulkan::VulkanDeviceContext::defaultSamplerLinearClampToEdge |
| DeletionQueue tachyon::vulkan::VulkanDeviceContext::mainDeletionQueue |
Flushed at Destroy (DeviceScope::Application).
| std::array<DeletionQueue, FRAME_DELETION_SLOT_COUNT> tachyon::vulkan::VulkanDeviceContext::frameDeletionQueues |
One per frame slot; see AdvanceFrameAndFlushDeletions.
| uint64_t tachyon::vulkan::VulkanDeviceContext::frameNumber { 0 } |
Frames advanced so far; picks the frame deletion slot.
| VkDebugUtilsMessengerEXT tachyon::vulkan::VulkanDeviceContext::debug_messenger |
The default debug messenger, when the GUI made the instance with one.
| VkCommandPoolCreateInfo tachyon::vulkan::VulkanDeviceContext::commandPoolInfo |
Library internal: reused for the window contexts' command pools.
| VkFenceCreateInfo tachyon::vulkan::VulkanDeviceContext::fenceCreateInfo |
Library internal: reused for the window contexts' fences.
| bool tachyon::vulkan::VulkanDeviceContext::initialized { false } |
Whether the device is up (made or adopted).
| tachyon::Error tachyon::vulkan::VulkanDeviceContext::initError {} |
why the bring-up failed, when it did