TachyonUI 0.1.0
High-performance UI for building tools.
Loading...
Searching...
No Matches
tachyon::vulkan::VulkanGraphicsContext Class Reference

The default graphics backend, on Vulkan 1.3. More...

#include <gui_core/graphics/vulkan/vk_graphics_context.h>

Inheritance diagram for tachyon::vulkan::VulkanGraphicsContext:

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 &currentFrame, 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.

Detailed Description

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).

Constructor & Destructor Documentation

◆ VulkanGraphicsContext()

tachyon::vulkan::VulkanGraphicsContext::VulkanGraphicsContext ( )

Member Function Documentation

◆ GetAPI()

tachyon::GraphicsAPI tachyon::vulkan::VulkanGraphicsContext::GetAPI ( ) const
inlineoverridevirtual

The API it presents with; window backends make their windows for it.

Implements tachyon::GraphicsContext.

◆ SetExternalDevice()

void tachyon::vulkan::VulkanGraphicsContext::SetExternalDevice ( const VulkanDeviceContext::ExternalDevice & external)
inline

Render on the host's device instead of creating one.

◆ SetSurfaceFactory()

void tachyon::vulkan::VulkanGraphicsContext::SetSurfaceFactory ( VulkanDeviceContext::SurfaceFactory factory)
inline

How surfaces are made for the window backend's windows; SDLWindowBackend installs its own.

◆ SetShaderDirectory()

void tachyon::vulkan::VulkanGraphicsContext::SetShaderDirectory ( std::string_view directory)
inline

Loads the compiled shaders (box_shader.vert.spv, ...) from directory instead of the ones built into the library, for working on the shaders.

◆ SetAllocationHooks()

void tachyon::vulkan::VulkanGraphicsContext::SetAllocationHooks ( const tachyon::AllocationHooks & hooks)
inlineoverridevirtual

Host memory functions for the graphics API's allocations. Call before Initialize.

Implements tachyon::GraphicsContext.

◆ Initialize()

Result< void > tachyon::vulkan::VulkanGraphicsContext::Initialize ( tachyon::IWindowBackend * windowBackend)
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.

◆ Cleanup()

void tachyon::vulkan::VulkanGraphicsContext::Cleanup ( )
overridevirtual

Waits for the GPU and destroys what the backend made, the renderer included.

The window contexts are destroyed before it.

Implements tachyon::GraphicsContext.

◆ DeviceLost()

bool tachyon::vulkan::VulkanGraphicsContext::DeviceLost ( ) const
inlineoverridevirtual

True once the GPU device is lost; RecreateDevice then makes a new one.

Reimplemented from tachyon::GraphicsContext.

◆ RecreateDevice()

tachyon::Result< void > tachyon::vulkan::VulkanGraphicsContext::RecreateDevice ( tachyon::IWindowBackend * windowBackend)
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.

◆ SimulateDeviceLoss()

void tachyon::vulkan::VulkanGraphicsContext::SimulateDeviceLoss ( )
inline

Diagnostic: as if the device were lost, so the next frame recreates it.

◆ BeginFrame()

void tachyon::vulkan::VulkanGraphicsContext::BeginFrame ( )
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.

◆ EndFrame()

void tachyon::vulkan::VulkanGraphicsContext::EndFrame ( )
inlineoverridevirtual

Ends the UI build, before the uploads and the window contexts' recording.

Implements tachyon::GraphicsContext.

◆ CreateImage() [1/2]

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.

◆ CreateImage() [2/2]

tachyon::Image * tachyon::vulkan::VulkanGraphicsContext::CreateImage ( void * data,
tachyon::uint2 size,
tachyon::ImageFormat format,
tachyon::Sampler sampler,
bool mipmapped = false )
overridevirtual

GraphicsContext::CreateImage; null data makes a cleared image.

Implements tachyon::GraphicsContext.

◆ DestroyImage()

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.

◆ DestroyImageAtEnd()

void tachyon::vulkan::VulkanGraphicsContext::DestroyImageAtEnd ( tachyon::Image * img,
tachyon::DeviceScope scope,
const std::source_location & loc = std::source_location::current() )
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.

◆ UploadVisualColorStyles()

tachyon::Buffer * tachyon::vulkan::VulkanGraphicsContext::UploadVisualColorStyles ( std::span< const tachyon::VisualColorStyle > colorStyles)

Library internal: the color styles in a GPU buffer for the shaders.

◆ DestroyVisualColorStyles()

void tachyon::vulkan::VulkanGraphicsContext::DestroyVisualColorStyles ( tachyon::Buffer * buffer)

Library internal: destroys the buffer's GPU objects now.

◆ DestroyVisualColorStylesAtEnd()

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.

◆ UploadVisualBoxStyles()

tachyon::Buffer * tachyon::vulkan::VulkanGraphicsContext::UploadVisualBoxStyles ( std::span< const tachyon::VisualBoxStyle > visualBoxStyles)

Library internal: the box styles in a GPU buffer for the shaders.

◆ DestroyVisualBoxStyles()

void tachyon::vulkan::VulkanGraphicsContext::DestroyVisualBoxStyles ( tachyon::Buffer * buffer)

Library internal: destroys the buffer's GPU objects now.

◆ DestroyVisualBoxStylesAtEnd()

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.

◆ CreateWindowContext()

tachyon::IWindowContext * tachyon::vulkan::VulkanGraphicsContext::CreateWindowContext ( void * nativeWindowHandle,
tachyon::OSWindowHandle osHandle,
tachyon::ID id,
tachyon::int2 size,
tachyon::WindowFlags windowFlags,
tachyon::OnGuiFunc onGui )
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.

◆ DestroyWindowContext()

void tachyon::vulkan::VulkanGraphicsContext::DestroyWindowContext ( tachyon::IWindowContext * context)
overridevirtual

Waits for the context's GPU work and destroys it now; its native window must still exist.

Implements tachyon::GraphicsContext.

◆ CreateTextAtlasManager()

tachyon::TextAtlasManager * tachyon::vulkan::VulkanGraphicsContext::CreateTextAtlasManager ( )
overridevirtual

A new text atlas manager for the backend. The caller owns it and keeps it past Cleanup.

Implements tachyon::GraphicsContext.

◆ GetImageSet()

tachyon::ImageSet * tachyon::vulkan::VulkanGraphicsContext::GetImageSet ( ) const
overridevirtual

The images the shaders sample, by ImageIndex.

Implements tachyon::GraphicsContext.

◆ RegisterImage()

tachyon::ImageIndex tachyon::vulkan::VulkanGraphicsContext::RegisterImage ( tachyon::Image * image)
overridevirtual

Adds the image to the image set; elements draw it by the returned index.

Implements tachyon::GraphicsContext.

◆ UnregisterImage()

void tachyon::vulkan::VulkanGraphicsContext::UnregisterImage ( tachyon::ImageIndex index)
overridevirtual

Frees the index for reuse; the image stays (DestroyImageAtEnd destroys it).

Implements tachyon::GraphicsContext.

◆ RegisterExternalImage()

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.

◆ UpdateExternalImage()

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.

◆ SetWindowImageTarget()

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.

◆ AddFrameWait()

void tachyon::vulkan::VulkanGraphicsContext::AddFrameWait ( VkSemaphore semaphore,
uint64_t value,
VkPipelineStageFlags2 stageMask )
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.

◆ StartResizing()

bool tachyon::vulkan::VulkanGraphicsContext::StartResizing ( tachyon::ID id)
inline

Library internal: a window's live-resize redraw starts (GUIRenderer::StartResizing).

◆ StopResizing()

void tachyon::vulkan::VulkanGraphicsContext::StopResizing ( )
inline

Library internal: the live-resize redraw ends.

◆ Reset()

void tachyon::vulkan::VulkanGraphicsContext::Reset ( )
inline

Library internal: clears the renderer's recorded primitives.

◆ PrepareVisualBoxStylesBuffer()

tachyon::Buffer * tachyon::vulkan::VulkanGraphicsContext::PrepareVisualBoxStylesBuffer ( tachyon::StyleManager & styleManager)

Library internal: the box styles' buffer, uploaded again when they changed.

◆ PrepareVisualColorStylesBuffer()

tachyon::Buffer * tachyon::vulkan::VulkanGraphicsContext::PrepareVisualColorStylesBuffer ( tachyon::StyleManager & styleManager,
tachyon::GradientManager & gradientManager )

Library internal: the color styles' buffer, uploaded again when they changed.

◆ PrepareFrame()

void tachyon::vulkan::VulkanGraphicsContext::PrepareFrame ( tachyon::StyleManager & styleManager,
tachyon::GradientManager & gradientManager,
float elapsedTimeSecs )
overridevirtual

GraphicsContext::PrepareFrame: uploads changed styles and registers the gradient pages.

Implements tachyon::GraphicsContext.

◆ RePrepareFrame()

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.

◆ RenderWindowFrame()

bool tachyon::vulkan::VulkanGraphicsContext::RenderWindowFrame ( VkCommandBuffer cmd,
FrameData & currentFrame,
tachyon::ID windowID,
tachyon::uint2 extent )

Library internal: records a window's primitives into cmd.

◆ GetLastFrameBuildSeconds()

float tachyon::vulkan::VulkanGraphicsContext::GetLastFrameBuildSeconds ( ) const
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.

◆ SetFrameBuildSeconds()

void tachyon::vulkan::VulkanGraphicsContext::SetFrameBuildSeconds ( float seconds)
inline

Library internal: window contexts report their CPU seconds between presents (GetLastFrameBuildSeconds); the last one in a frame wins.

Member Data Documentation

◆ vulkanImageSet

VulkanImageSet* tachyon::vulkan::VulkanGraphicsContext::vulkanImageSet = nullptr

Library internal: the image set behind GetImageSet.

◆ visualBoxStylesMesh

tachyon::Buffer* tachyon::vulkan::VulkanGraphicsContext::visualBoxStylesMesh = nullptr

Library internal: the box styles' GPU buffer.

◆ colorStylesMesh

tachyon::Buffer* tachyon::vulkan::VulkanGraphicsContext::colorStylesMesh = nullptr

Library internal: the color styles' GPU buffer.

◆ gradientPageImageIndices

std::vector<tachyon::ImageIndex> tachyon::vulkan::VulkanGraphicsContext::gradientPageImageIndices

Library internal: the gradient pages' image indices.

◆ deviceContext

VulkanDeviceContext tachyon::vulkan::VulkanGraphicsContext::deviceContext

The device; set it up (external device, debug config) before Initialize.

◆ pushConstants

tachyon::GPUDrawPushConstants tachyon::vulkan::VulkanGraphicsContext::pushConstants {}

Library internal: the push constants PrepareFrame sets for the frame's draws.


The documentation for this class was generated from the following file: