|
TachyonUI 0.1.0
High-performance UI for building tools.
|
The default graphics backend, on Vulkan 1.3. More...
#include <gui_core/graphics/vulkan/vk_graphics_context.h>
Public Member Functions | |
| VulkanGraphicsContext () | |
| tachyon::GraphicsAPI | GetAPI () const override |
| The API it presents with; window backends make their windows for it. | |
| void | SetExternalDevice (const VulkanDeviceContext::ExternalDevice &external) |
| Render on the host's device instead of creating one. | |
| void | SetSurfaceFactory (VulkanDeviceContext::SurfaceFactory factory) |
| How surfaces are made for the window backend's windows; SDLWindowBackend installs its own. | |
| void | SetShaderDirectory (std::string_view directory) |
| Loads the compiled shaders (box_shader.vert.spv, ...) from directory instead of the ones built into the library, for working on the shaders. | |
| void | SetAllocationHooks (const tachyon::AllocationHooks &hooks) override |
| Host memory functions for the graphics API's allocations. Call before Initialize. | |
| Result< void > | Initialize (tachyon::IWindowBackend *windowBackend) override |
| Brings the device up; GUIApplication::Initialize calls it once, before any window context. | |
| void | Cleanup () override |
| Waits for the GPU and destroys what the backend made, the renderer included. | |
| bool | DeviceLost () const override |
| True once the GPU device is lost; RecreateDevice then makes a new one. | |
| tachyon::Result< void > | RecreateDevice (tachyon::IWindowBackend *windowBackend) override |
| Makes a new device after DeviceLost, and everything the backend owns on it (the window contexts are the caller's to make again). | |
| void | SimulateDeviceLoss () |
| Diagnostic: as if the device were lost, so the next frame recreates it. | |
| void | BeginFrame () override |
| Starts a frame's UI build: resets the renderer for new primitives (Vulkan: also frees what frame-scoped deletions held long enough). | |
| void | EndFrame () override |
| Ends the UI build, before the uploads and the window contexts' recording. | |
| tachyon::Image * | CreateImage (tachyon::uint2 size, tachyon::ImageFormat format, tachyon::Sampler sampler, bool mipmapped=false) |
| An image nothing is uploaded to (undefined contents), for sampling only. | |
| tachyon::Image * | CreateImage (void *data, tachyon::uint2 size, tachyon::ImageFormat format, tachyon::Sampler sampler, bool mipmapped=false) override |
| GraphicsContext::CreateImage; null data makes a cleared image. | |
| void | DestroyImage (tachyon::Image *img) |
| Destroys the image's Vulkan objects now, without waiting for the GPU; doesn't delete the object. | |
| void | DestroyImageAtEnd (tachyon::Image *img, tachyon::DeviceScope scope, const std::source_location &loc=std::source_location::current()) override |
| Destroys the image and deletes the object once the GPU is done with it: a few frames on for DeviceScope::Frame, at Cleanup for DeviceScope::Application. | |
| tachyon::Buffer * | UploadVisualColorStyles (std::span< const tachyon::VisualColorStyle > colorStyles) |
| 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 > visualBoxStyles) |
| 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. | |
| tachyon::IWindowContext * | CreateWindowContext (void *nativeHandle, tachyon::OSWindowHandle osHandle, tachyon::ID id, tachyon::int2 size, tachyon::WindowFlags windowFlags, tachyon::OnGuiFunc onGui) override |
| Makes the context that renders an OS window: nativeWindowHandle comes from IWindowBackend::GetNativeHandle, size is in pixels and onGui builds the window's UI. | |
| void | DestroyWindowContext (tachyon::IWindowContext *context) override |
| Waits for the context's GPU work and destroys it now; its native window must still exist. | |
| tachyon::TextAtlasManager * | CreateTextAtlasManager () override |
| A new text atlas manager for the backend. The caller owns it and keeps it past Cleanup. | |
| tachyon::ImageSet * | GetImageSet () const override |
| The images the shaders sample, by ImageIndex. | |
| tachyon::ImageIndex | RegisterImage (tachyon::Image *image) override |
| Adds the image to the image set; elements draw it by the returned index. | |
| void | UnregisterImage (tachyon::ImageIndex index) override |
| Frees the index for reuse; the image stays (DestroyImageAtEnd destroys it). | |
| tachyon::ImageIndex | RegisterExternalImage (VkImageView view, VkSampler sampler) |
| An image the host renders itself (a 3D viewport, a preview) as an ImageIndex, drawn like GUI-owned images (CustomDrawContext::RenderQuad, Element::Image). | |
| void | UpdateExternalImage (tachyon::ImageIndex index, VkImageView view, VkSampler sampler) |
| Points an existing index at a new view, for example after a resize, under the same rules as RegisterExternalImage. | |
| void | SetWindowImageTarget (tachyon::ID window, VkImage image, VkExtent2D extent) |
| The host image a render-to-image window (WindowFlags::RenderToImage) is copied into after each of its frames; VK_NULL_HANDLE stops the copies. | |
| void | AddFrameWait (VkSemaphore semaphore, uint64_t value, VkPipelineStageFlags2 stageMask) |
| The GUI's next frame waits for the timeline semaphore semaphore (made on the GUI's device) to reach value before stageMask: every window's submission of that frame does. | |
| bool | StartResizing (tachyon::ID id) |
| Library internal: a window's live-resize redraw starts (GUIRenderer::StartResizing). | |
| void | StopResizing () |
| Library internal: the live-resize redraw ends. | |
| void | Reset () |
| Library internal: clears the renderer's recorded primitives. | |
| tachyon::Buffer * | PrepareVisualBoxStylesBuffer (tachyon::StyleManager &styleManager) |
| Library internal: the box styles' buffer, uploaded again when they changed. | |
| tachyon::Buffer * | PrepareVisualColorStylesBuffer (tachyon::StyleManager &styleManager, tachyon::GradientManager &gradientManager) |
| Library internal: the color styles' buffer, uploaded again when they changed. | |
| void | PrepareFrame (tachyon::StyleManager &styleManager, tachyon::GradientManager &gradientManager, float elapsedTimeSecs) override |
| GraphicsContext::PrepareFrame: uploads changed styles and registers the gradient pages. | |
| void | RePrepareFrame () |
| Library internal: PrepareFrame with the last call's arguments; lets a live resize pick up the style changes its onGui just made. | |
| bool | RenderWindowFrame (VkCommandBuffer cmd, FrameData ¤tFrame, tachyon::ID windowID, tachyon::uint2 extent) |
| Library internal: records a window's primitives into cmd. | |
| float | GetLastFrameBuildSeconds () const override |
| Wall-clock seconds of CPU work in the last frame: from just after one present returns to just before the next, so without the vsync wait. | |
| void | SetFrameBuildSeconds (float seconds) |
| Library internal: window contexts report their CPU seconds between presents (GetLastFrameBuildSeconds); the last one in a frame wins. | |
| Public Member Functions inherited from tachyon::GraphicsContext | |
| GraphicsContext ()=default | |
| virtual | ~GraphicsContext () |
Public Attributes | |
| VulkanImageSet * | vulkanImageSet = nullptr |
| Library internal: the image set behind GetImageSet. | |
| tachyon::Buffer * | visualBoxStylesMesh = nullptr |
| Library internal: the box styles' GPU buffer. | |
| tachyon::Buffer * | colorStylesMesh = nullptr |
| Library internal: the color styles' GPU buffer. | |
| std::vector< tachyon::ImageIndex > | gradientPageImageIndices |
| Library internal: the gradient pages' image indices. | |
| VulkanDeviceContext | deviceContext |
| The device; set it up (external device, debug config) before Initialize. | |
| tachyon::GPUDrawPushConstants | pushConstants {} |
| Library internal: the push constants PrepareFrame sets for the frame's draws. | |
| Public Attributes inherited from tachyon::GraphicsContext | |
| GUIRenderer * | guiRenderer = nullptr |
| Where the UI records its draw primitives. | |
The default graphics backend, on Vulkan 1.3.
Makes its own device, or renders on a host's (SetExternalDevice); a lost device it made is made again (RecreateDevice).
| tachyon::vulkan::VulkanGraphicsContext::VulkanGraphicsContext | ( | ) |
|
inlineoverridevirtual |
The API it presents with; window backends make their windows for it.
Implements tachyon::GraphicsContext.
|
inline |
Render on the host's device instead of creating one.
|
inline |
How surfaces are made for the window backend's windows; SDLWindowBackend installs its own.
|
inline |
Loads the compiled shaders (box_shader.vert.spv, ...) from directory instead of the ones built into the library, for working on the shaders.
|
inlineoverridevirtual |
Host memory functions for the graphics API's allocations. Call before Initialize.
Implements tachyon::GraphicsContext.
|
overridevirtual |
Brings the device up; GUIApplication::Initialize calls it once, before any window context.
It may make windows with the backend (Vulkan: a hidden one, to pick a GPU that can present to it).
Implements tachyon::GraphicsContext.
|
overridevirtual |
Waits for the GPU and destroys what the backend made, the renderer included.
The window contexts are destroyed before it.
Implements tachyon::GraphicsContext.
|
inlineoverridevirtual |
True once the GPU device is lost; RecreateDevice then makes a new one.
Reimplemented from tachyon::GraphicsContext.
|
overridevirtual |
Makes a new device after DeviceLost, and everything the backend owns on it (the window contexts are the caller's to make again).
The default fails with ErrorCode::Unsupported.
Reimplemented from tachyon::GraphicsContext.
|
inline |
Diagnostic: as if the device were lost, so the next frame recreates it.
|
overridevirtual |
Starts a frame's UI build: resets the renderer for new primitives (Vulkan: also frees what frame-scoped deletions held long enough).
Implements tachyon::GraphicsContext.
|
inlineoverridevirtual |
Ends the UI build, before the uploads and the window contexts' recording.
Implements tachyon::GraphicsContext.
| tachyon::Image * tachyon::vulkan::VulkanGraphicsContext::CreateImage | ( | tachyon::uint2 | size, |
| tachyon::ImageFormat | format, | ||
| tachyon::Sampler | sampler, | ||
| bool | mipmapped = false ) |
An image nothing is uploaded to (undefined contents), for sampling only.
|
overridevirtual |
GraphicsContext::CreateImage; null data makes a cleared image.
Implements tachyon::GraphicsContext.
| void tachyon::vulkan::VulkanGraphicsContext::DestroyImage | ( | tachyon::Image * | img | ) |
Destroys the image's Vulkan objects now, without waiting for the GPU; doesn't delete the object.
DestroyImageAtEnd is the safe way.
|
overridevirtual |
Destroys the image and deletes the object once the GPU is done with it: a few frames on for DeviceScope::Frame, at Cleanup for DeviceScope::Application.
loc is for diagnostics.
Implements tachyon::GraphicsContext.
| tachyon::Buffer * tachyon::vulkan::VulkanGraphicsContext::UploadVisualColorStyles | ( | std::span< const tachyon::VisualColorStyle > | colorStyles | ) |
Library internal: the color styles in a GPU buffer for the shaders.
| void tachyon::vulkan::VulkanGraphicsContext::DestroyVisualColorStyles | ( | tachyon::Buffer * | buffer | ) |
Library internal: destroys the buffer's GPU objects now.
| void tachyon::vulkan::VulkanGraphicsContext::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::VulkanGraphicsContext::UploadVisualBoxStyles | ( | std::span< const tachyon::VisualBoxStyle > | visualBoxStyles | ) |
Library internal: the box styles in a GPU buffer for the shaders.
| void tachyon::vulkan::VulkanGraphicsContext::DestroyVisualBoxStyles | ( | tachyon::Buffer * | buffer | ) |
Library internal: destroys the buffer's GPU objects now.
| void tachyon::vulkan::VulkanGraphicsContext::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.
|
overridevirtual |
Makes the context that renders an OS window: nativeWindowHandle comes from IWindowBackend::GetNativeHandle, size is in pixels and onGui builds the window's UI.
nullptr on failure. Destroy it with DestroyWindowContext.
Implements tachyon::GraphicsContext.
|
overridevirtual |
Waits for the context's GPU work and destroys it now; its native window must still exist.
Implements tachyon::GraphicsContext.
|
overridevirtual |
A new text atlas manager for the backend. The caller owns it and keeps it past Cleanup.
Implements tachyon::GraphicsContext.
|
overridevirtual |
The images the shaders sample, by ImageIndex.
Implements tachyon::GraphicsContext.
|
overridevirtual |
Adds the image to the image set; elements draw it by the returned index.
Implements tachyon::GraphicsContext.
|
overridevirtual |
Frees the index for reuse; the image stays (DestroyImageAtEnd destroys it).
Implements tachyon::GraphicsContext.
| tachyon::ImageIndex tachyon::vulkan::VulkanGraphicsContext::RegisterExternalImage | ( | VkImageView | view, |
| VkSampler | sampler ) |
An image the host renders itself (a 3D viewport, a preview) as an ImageIndex, drawn like GUI-owned images (CustomDrawContext::RenderQuad, Element::Image).
The view and sampler stay the host's and must outlive every GUI frame that uses the index. Call it while the UI is built (OnGUI).
The GUI samples the image in the fragment stage as SHADER_READ_ONLY_OPTIMAL, in its frame submission. The host must (1) have it in that layout, with its writes made available to the fragment stage, in a command buffer submitted to the GUI's queue (the one given to SetExternalDevice) before the GUI's frame, and (2) before writing it again, transition it away with a FRAGMENT_SHADER source stage so the write waits for the GUI's reads.
| void tachyon::vulkan::VulkanGraphicsContext::UpdateExternalImage | ( | tachyon::ImageIndex | index, |
| VkImageView | view, | ||
| VkSampler | sampler ) |
Points an existing index at a new view, for example after a resize, under the same rules as RegisterExternalImage.
No in-flight GUI frame may still sample the old view.
| void tachyon::vulkan::VulkanGraphicsContext::SetWindowImageTarget | ( | tachyon::ID | window, |
| VkImage | image, | ||
| VkExtent2D | extent ) |
The host image a render-to-image window (WindowFlags::RenderToImage) is copied into after each of its frames; VK_NULL_HANDLE stops the copies.
May be set before the window exists. The image needs TRANSFER_DST usage; the window's pixels are scaled to extent. The GUI's frame (one submission on the shared queue) moves it from SHADER_READ_ONLY_OPTIMAL (UNDEFINED the first time) to TRANSFER_DST, copies, and leaves it in SHADER_READ_ONLY_OPTIMAL for the fragment stage. The host reads it in work submitted after the GUI's frame and must leave it in SHADER_READ_ONLY_OPTIMAL.
|
inline |
The GUI's next frame waits for the timeline semaphore semaphore (made on the GUI's device) to reach value before stageMask: every window's submission of that frame does.
For work the host submits to another queue (async compute) that the GUI shows, without a hop through the GUI's queue. Waits on the same semaphore merge: the higher value, both stages. Call it while the UI is built (OnGUI) or before the frame; the frame after that one doesn't wait on it again.
|
inline |
Library internal: a window's live-resize redraw starts (GUIRenderer::StartResizing).
|
inline |
Library internal: the live-resize redraw ends.
|
inline |
Library internal: clears the renderer's recorded primitives.
| tachyon::Buffer * tachyon::vulkan::VulkanGraphicsContext::PrepareVisualBoxStylesBuffer | ( | tachyon::StyleManager & | styleManager | ) |
Library internal: the box styles' buffer, uploaded again when they changed.
| tachyon::Buffer * tachyon::vulkan::VulkanGraphicsContext::PrepareVisualColorStylesBuffer | ( | tachyon::StyleManager & | styleManager, |
| tachyon::GradientManager & | gradientManager ) |
Library internal: the color styles' buffer, uploaded again when they changed.
|
overridevirtual |
GraphicsContext::PrepareFrame: uploads changed styles and registers the gradient pages.
Implements tachyon::GraphicsContext.
| void tachyon::vulkan::VulkanGraphicsContext::RePrepareFrame | ( | ) |
Library internal: PrepareFrame with the last call's arguments; lets a live resize pick up the style changes its onGui just made.
| bool tachyon::vulkan::VulkanGraphicsContext::RenderWindowFrame | ( | VkCommandBuffer | cmd, |
| FrameData & | currentFrame, | ||
| tachyon::ID | windowID, | ||
| tachyon::uint2 | extent ) |
Library internal: records a window's primitives into cmd.
|
inlineoverridevirtual |
Wall-clock seconds of CPU work in the last frame: from just after one present returns to just before the next, so without the vsync wait.
0 for backends that don't measure it.
Reimplemented from tachyon::GraphicsContext.
|
inline |
Library internal: window contexts report their CPU seconds between presents (GetLastFrameBuildSeconds); the last one in a frame wins.
| VulkanImageSet* tachyon::vulkan::VulkanGraphicsContext::vulkanImageSet = nullptr |
Library internal: the image set behind GetImageSet.
| tachyon::Buffer* tachyon::vulkan::VulkanGraphicsContext::visualBoxStylesMesh = nullptr |
Library internal: the box styles' GPU buffer.
| tachyon::Buffer* tachyon::vulkan::VulkanGraphicsContext::colorStylesMesh = nullptr |
Library internal: the color styles' GPU buffer.
| std::vector<tachyon::ImageIndex> tachyon::vulkan::VulkanGraphicsContext::gradientPageImageIndices |
Library internal: the gradient pages' image indices.
| VulkanDeviceContext tachyon::vulkan::VulkanGraphicsContext::deviceContext |
The device; set it up (external device, debug config) before Initialize.
| tachyon::GPUDrawPushConstants tachyon::vulkan::VulkanGraphicsContext::pushConstants {} |
Library internal: the push constants PrepareFrame sets for the frame's draws.