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

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

Inheritance diagram for tachyon::vulkan::VulkanWindowContext:

Public Member Functions

FrameData & GetCurrentFrame ()
FrameData & GetLastFrame ()
bool IsTransparent () const override
 Whether the window has WindowFlags::Transparent.
void CreateSwapchain ()
void DestroySwapchain ()
void ResizeSwapchain (tachyon::int2 size)
void FlushWindowContext ()
void CreateDrawDepthImages (VulkanImage &drawImage, VulkanImage &depthImage, VkFormat colorFormat)
 Creates a draw and depth image pair sized to windowExtent; each FRAME_OVERLAP slot has its own.
void DestroyDrawDepthImages (VulkanImage &drawImage, VulkanImage &depthImage)
VkCommandBuffer BeginWindowFrame (FrameData &currentFrame, VulkanGraphicsContext *graphics=nullptr)
void EndWindowFrame (FrameData &currentFrame)
void PerformReadback (FrameData &frame)
 Copies frame's draw image into the readback buffer in a submit of its own, waits, and reads it (ReadPixels of a window whose frames aren't copied out themselves).
void RecordReadbackCopy (VkCommandBuffer cmd, FrameData &frame)
 Records the copy of frame's draw image into the readback buffer, made visible to the host, into cmd.
void ReadBackBuffer ()
 The readback buffer into cachedBitmap, once the copy into it is done.
double LastGpuFrameSeconds () const
 GPU time of the drawing of this window's most recent finished frame, in seconds; 0 until one finished, or when the device can't time.
bool ReadPixels (std::span< uint8_t > bgra) override
 The last rendered frame, BGRA8 with tightly packed rows; bgra holds width x height x 4 bytes of the window's pixel size.
void SetImageTarget (VkImage image, VkExtent2D extent)
 The host image each frame is copied into (render-to-image windows); VK_NULL_HANDLE stops.
void TransitionTarget (VkCommandBuffer cmd, VkImageLayout from, VkImageLayout to, VkPipelineStageFlags2 srcStage, VkAccessFlags2 srcAccess, VkPipelineStageFlags2 dstStage, VkAccessFlags2 dstAccess)
void Destroy ()
 ~VulkanWindowContext () override
tachyon::ID GetID () const override
 The GUI window's ID; the backend passes it with the window's input.
void RenderWindowFrame (tachyon::GraphicsContext *graphicsContext, tachyon::IntRect rect, bool resizing) override
 A frame is recorded (drawn and submitted), then presented.
void RecordWindowFrame (tachyon::GraphicsContext *graphicsContext, tachyon::IntRect rect) override
 Records and submits a frame without presenting it; PresentWindowFrame presents.
std::optional< double > PresentWindowFrame () override
 May wait for vsync; nothing to do for a render-to-image window.
double LastSwapchainWaitSeconds () const
 The last presented frame's wait on the swapchain, in seconds (PresentWindowFrame's).
bool NeedsRecord () const override
 True when the window must be recorded this frame even though its draws didn't change (its swapchain is out of date).
bool RecordFrame (tachyon::GraphicsContext *graphicsContext, tachyon::IntRect rect, bool resizing)
 False when the frame a live resize ran deleted this context: nothing of it may be used then.
void UpdateTransparentWindow () override
 A transparent window the OS composites from a CPU copy (a layered window on Windows): shows its last frame again, where the window is.
tachyon::OSWindowHandle GetWindowHandle () const override
 The window it was created for.
Public Member Functions inherited from tachyon::IWindowContext
virtual ~IWindowContext ()=default

Static Public Member Functions

static VulkanWindowContext * Create (tachyon::ID id, void *nativeHandle, tachyon::OSWindowHandle osHandle, tachyon::int2 size, tachyon::WindowFlags windowFlags, VulkanDeviceContext *deviceContext, tachyon::OnGuiFunc onGUI)

Public Attributes

tachyon::ID id { tachyon::ID::Invalid()}
VulkanDeviceContext * deviceContext { nullptr }
tachyon::OSWindowHandle osHandle { nullptr }
void * nativeHandle { nullptr }
tachyon::OnGuiFunc onGui {}
std::shared_ptr< bool > alive = std::make_shared<bool>(true)
 False once the context is deleted: a live resize's onGui runs a whole app frame, which may close this very window (a drag preview whose drag ended).
tachyon::WindowFlags windowFlags = tachyon::WindowFlags::None
SwapchainState swapchain = {}
WindowVulkanState state = {}
VkSurfaceKHR surface = {}
VkExtent2D windowExtent = {}
VkExtent2D drawExtent = {}
VkExtent2D requestedExtent = {}
 The size the last frame was recorded for; without a swapchain, what's drawn.
VkExtent2D swapchainRequest = {}
 The size the swapchain was last remade for: a window grown smaller than its swapchain asks again once, even on drivers that don't report it out of date.
bool resize_requested { false }
bool freeze_rendering { false }
tachyon::int2 mouse_pos = { 0,0 }
uint64_t frameNumber { 0 }
 frames recorded; never wraps
std::chrono::steady_clock::time_point lastPresentEnd {}
 When the last vkQueuePresentKHR returned.
bool havePresentEnd { false }
double lastBuildSeconds { 0.0 }
bool lastBuildValid { false }
double acquireSeconds { 0.0 }
 How long this frame's swapchain image took to acquire; counted with present's wait.
double lastSwapchainWaitSeconds { 0.0 }
 The last presented frame's swapchain wait: acquiring its image and presenting it.
bool presentPending { false }
 Recorded and submitted, waiting for PresentWindowFrame.
FrameData * readbackPending { nullptr }
bool needsReadback { false }
 Transparent window: each frame is read back for the Windows layered window.
bool renderToImage { false }
 WindowFlags::RenderToImage: no surface.
VkImage targetImage { VK_NULL_HANDLE }
 host image each frame is copied into
VkExtent2D targetExtent {}
bool targetWritten { false }
 targetImage holds a previous frame
tachyon::vulkan::AllocatedBuffer readbackBuffer = {}
std::vector< uint8_t > cachedBitmap
uint64_t immediateReadbacks = 0
 Readbacks that needed a submit of their own (PerformReadback).
double lastGpuFrameSeconds = 0.0
float timestampPeriodNs = 0.0f
 nanoseconds per timestamp tick; 0: no timestamps

Static Public Attributes

static constexpr VkImageUsageFlags kDrawImageUsage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
 The draw image is drawn into as a color attachment and copied out; it's no storage image, which would keep drivers from compressing it (DCC).

Constructor & Destructor Documentation

◆ ~VulkanWindowContext()

tachyon::vulkan::VulkanWindowContext::~VulkanWindowContext ( )
inlineoverride

Member Function Documentation

◆ GetCurrentFrame()

FrameData & tachyon::vulkan::VulkanWindowContext::GetCurrentFrame ( )

◆ GetLastFrame()

FrameData & tachyon::vulkan::VulkanWindowContext::GetLastFrame ( )

◆ IsTransparent()

bool tachyon::vulkan::VulkanWindowContext::IsTransparent ( ) const
inlineoverridevirtual

Whether the window has WindowFlags::Transparent.

Implements tachyon::IWindowContext.

◆ CreateSwapchain()

void tachyon::vulkan::VulkanWindowContext::CreateSwapchain ( )

◆ DestroySwapchain()

void tachyon::vulkan::VulkanWindowContext::DestroySwapchain ( )

◆ ResizeSwapchain()

void tachyon::vulkan::VulkanWindowContext::ResizeSwapchain ( tachyon::int2 size)

◆ FlushWindowContext()

void tachyon::vulkan::VulkanWindowContext::FlushWindowContext ( )

◆ CreateDrawDepthImages()

void tachyon::vulkan::VulkanWindowContext::CreateDrawDepthImages ( VulkanImage & drawImage,
VulkanImage & depthImage,
VkFormat colorFormat )

Creates a draw and depth image pair sized to windowExtent; each FRAME_OVERLAP slot has its own.

◆ DestroyDrawDepthImages()

void tachyon::vulkan::VulkanWindowContext::DestroyDrawDepthImages ( VulkanImage & drawImage,
VulkanImage & depthImage )

◆ BeginWindowFrame()

VkCommandBuffer tachyon::vulkan::VulkanWindowContext::BeginWindowFrame ( FrameData & currentFrame,
VulkanGraphicsContext * graphics = nullptr )

◆ EndWindowFrame()

void tachyon::vulkan::VulkanWindowContext::EndWindowFrame ( FrameData & currentFrame)

◆ PerformReadback()

void tachyon::vulkan::VulkanWindowContext::PerformReadback ( FrameData & frame)

Copies frame's draw image into the readback buffer in a submit of its own, waits, and reads it (ReadPixels of a window whose frames aren't copied out themselves).

◆ RecordReadbackCopy()

void tachyon::vulkan::VulkanWindowContext::RecordReadbackCopy ( VkCommandBuffer cmd,
FrameData & frame )

Records the copy of frame's draw image into the readback buffer, made visible to the host, into cmd.

◆ ReadBackBuffer()

void tachyon::vulkan::VulkanWindowContext::ReadBackBuffer ( )

The readback buffer into cachedBitmap, once the copy into it is done.

◆ LastGpuFrameSeconds()

double tachyon::vulkan::VulkanWindowContext::LastGpuFrameSeconds ( ) const
inline

GPU time of the drawing of this window's most recent finished frame, in seconds; 0 until one finished, or when the device can't time.

◆ ReadPixels()

bool tachyon::vulkan::VulkanWindowContext::ReadPixels ( std::span< uint8_t > bgra)
overridevirtual

The last rendered frame, BGRA8 with tightly packed rows; bgra holds width x height x 4 bytes of the window's pixel size.

False when it can't be read.

Reimplemented from tachyon::IWindowContext.

◆ SetImageTarget()

void tachyon::vulkan::VulkanWindowContext::SetImageTarget ( VkImage image,
VkExtent2D extent )

The host image each frame is copied into (render-to-image windows); VK_NULL_HANDLE stops.

◆ TransitionTarget()

void tachyon::vulkan::VulkanWindowContext::TransitionTarget ( VkCommandBuffer cmd,
VkImageLayout from,
VkImageLayout to,
VkPipelineStageFlags2 srcStage,
VkAccessFlags2 srcAccess,
VkPipelineStageFlags2 dstStage,
VkAccessFlags2 dstAccess )

◆ Create()

VulkanWindowContext * tachyon::vulkan::VulkanWindowContext::Create ( tachyon::ID id,
void * nativeHandle,
tachyon::OSWindowHandle osHandle,
tachyon::int2 size,
tachyon::WindowFlags windowFlags,
VulkanDeviceContext * deviceContext,
tachyon::OnGuiFunc onGUI )
static

◆ Destroy()

void tachyon::vulkan::VulkanWindowContext::Destroy ( )

◆ GetID()

tachyon::ID tachyon::vulkan::VulkanWindowContext::GetID ( ) const
inlineoverridevirtual

The GUI window's ID; the backend passes it with the window's input.

Implements tachyon::IWindowContext.

◆ RenderWindowFrame()

void tachyon::vulkan::VulkanWindowContext::RenderWindowFrame ( tachyon::GraphicsContext * graphicsContext,
tachyon::IntRect rect,
bool resizing )
overridevirtual

A frame is recorded (drawn and submitted), then presented.

RenderWindowFrame does both; a host loop records every window before presenting any.

Implements tachyon::IWindowContext.

◆ RecordWindowFrame()

void tachyon::vulkan::VulkanWindowContext::RecordWindowFrame ( tachyon::GraphicsContext * graphicsContext,
tachyon::IntRect rect )
overridevirtual

Records and submits a frame without presenting it; PresentWindowFrame presents.

The default does both, through RenderWindowFrame.

Reimplemented from tachyon::IWindowContext.

◆ PresentWindowFrame()

std::optional< double > tachyon::vulkan::VulkanWindowContext::PresentWindowFrame ( )
overridevirtual

May wait for vsync; nothing to do for a render-to-image window.

Returns the seconds the frame waited on the OS to show it: getting its image and presenting it, since a driver may hold the vsync wait in either. Nothing when no frame was presented to it (a render-to-image window, a window not recorded this frame).

Reimplemented from tachyon::IWindowContext.

◆ LastSwapchainWaitSeconds()

double tachyon::vulkan::VulkanWindowContext::LastSwapchainWaitSeconds ( ) const
inline

The last presented frame's wait on the swapchain, in seconds (PresentWindowFrame's).

◆ NeedsRecord()

bool tachyon::vulkan::VulkanWindowContext::NeedsRecord ( ) const
inlineoverridevirtual

True when the window must be recorded this frame even though its draws didn't change (its swapchain is out of date).

False by default.

Reimplemented from tachyon::IWindowContext.

◆ RecordFrame()

bool tachyon::vulkan::VulkanWindowContext::RecordFrame ( tachyon::GraphicsContext * graphicsContext,
tachyon::IntRect rect,
bool resizing )

False when the frame a live resize ran deleted this context: nothing of it may be used then.

◆ UpdateTransparentWindow()

void tachyon::vulkan::VulkanWindowContext::UpdateTransparentWindow ( )
overridevirtual

A transparent window the OS composites from a CPU copy (a layered window on Windows): shows its last frame again, where the window is.

Only its picture: the window manager places it. The default does nothing.

Reimplemented from tachyon::IWindowContext.

◆ GetWindowHandle()

tachyon::OSWindowHandle tachyon::vulkan::VulkanWindowContext::GetWindowHandle ( ) const
inlineoverridevirtual

The window it was created for.

Implements tachyon::IWindowContext.

Member Data Documentation

◆ id

tachyon::ID tachyon::vulkan::VulkanWindowContext::id { tachyon::ID::Invalid()}

◆ deviceContext

VulkanDeviceContext* tachyon::vulkan::VulkanWindowContext::deviceContext { nullptr }

◆ osHandle

tachyon::OSWindowHandle tachyon::vulkan::VulkanWindowContext::osHandle { nullptr }

◆ nativeHandle

void* tachyon::vulkan::VulkanWindowContext::nativeHandle { nullptr }

◆ onGui

tachyon::OnGuiFunc tachyon::vulkan::VulkanWindowContext::onGui {}

◆ alive

std::shared_ptr<bool> tachyon::vulkan::VulkanWindowContext::alive = std::make_shared<bool>(true)

False once the context is deleted: a live resize's onGui runs a whole app frame, which may close this very window (a drag preview whose drag ended).

◆ windowFlags

tachyon::WindowFlags tachyon::vulkan::VulkanWindowContext::windowFlags = tachyon::WindowFlags::None

◆ swapchain

SwapchainState tachyon::vulkan::VulkanWindowContext::swapchain = {}

◆ state

WindowVulkanState tachyon::vulkan::VulkanWindowContext::state = {}

◆ surface

VkSurfaceKHR tachyon::vulkan::VulkanWindowContext::surface = {}

◆ windowExtent

VkExtent2D tachyon::vulkan::VulkanWindowContext::windowExtent = {}

◆ drawExtent

VkExtent2D tachyon::vulkan::VulkanWindowContext::drawExtent = {}

◆ requestedExtent

VkExtent2D tachyon::vulkan::VulkanWindowContext::requestedExtent = {}

The size the last frame was recorded for; without a swapchain, what's drawn.

◆ swapchainRequest

VkExtent2D tachyon::vulkan::VulkanWindowContext::swapchainRequest = {}

The size the swapchain was last remade for: a window grown smaller than its swapchain asks again once, even on drivers that don't report it out of date.

◆ resize_requested

bool tachyon::vulkan::VulkanWindowContext::resize_requested { false }

◆ freeze_rendering

bool tachyon::vulkan::VulkanWindowContext::freeze_rendering { false }

◆ mouse_pos

tachyon::int2 tachyon::vulkan::VulkanWindowContext::mouse_pos = { 0,0 }

◆ frameNumber

uint64_t tachyon::vulkan::VulkanWindowContext::frameNumber { 0 }

frames recorded; never wraps

◆ lastPresentEnd

std::chrono::steady_clock::time_point tachyon::vulkan::VulkanWindowContext::lastPresentEnd {}

When the last vkQueuePresentKHR returned.

The frame-build time runs from here to just before the next present: the CPU work, without the vsync wait.

◆ havePresentEnd

bool tachyon::vulkan::VulkanWindowContext::havePresentEnd { false }

◆ lastBuildSeconds

double tachyon::vulkan::VulkanWindowContext::lastBuildSeconds { 0.0 }

◆ lastBuildValid

bool tachyon::vulkan::VulkanWindowContext::lastBuildValid { false }

◆ acquireSeconds

double tachyon::vulkan::VulkanWindowContext::acquireSeconds { 0.0 }

How long this frame's swapchain image took to acquire; counted with present's wait.

◆ lastSwapchainWaitSeconds

double tachyon::vulkan::VulkanWindowContext::lastSwapchainWaitSeconds { 0.0 }

The last presented frame's swapchain wait: acquiring its image and presenting it.

◆ presentPending

bool tachyon::vulkan::VulkanWindowContext::presentPending { false }

Recorded and submitted, waiting for PresentWindowFrame.

◆ readbackPending

FrameData* tachyon::vulkan::VulkanWindowContext::readbackPending { nullptr }

◆ needsReadback

bool tachyon::vulkan::VulkanWindowContext::needsReadback { false }

Transparent window: each frame is read back for the Windows layered window.

◆ renderToImage

bool tachyon::vulkan::VulkanWindowContext::renderToImage { false }

◆ targetImage

VkImage tachyon::vulkan::VulkanWindowContext::targetImage { VK_NULL_HANDLE }

host image each frame is copied into

◆ targetExtent

VkExtent2D tachyon::vulkan::VulkanWindowContext::targetExtent {}

◆ targetWritten

bool tachyon::vulkan::VulkanWindowContext::targetWritten { false }

targetImage holds a previous frame

◆ readbackBuffer

tachyon::vulkan::AllocatedBuffer tachyon::vulkan::VulkanWindowContext::readbackBuffer = {}

◆ cachedBitmap

std::vector<uint8_t> tachyon::vulkan::VulkanWindowContext::cachedBitmap

◆ kDrawImageUsage

VkImageUsageFlags tachyon::vulkan::VulkanWindowContext::kDrawImageUsage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
staticconstexpr

The draw image is drawn into as a color attachment and copied out; it's no storage image, which would keep drivers from compressing it (DCC).

◆ immediateReadbacks

uint64_t tachyon::vulkan::VulkanWindowContext::immediateReadbacks = 0

Readbacks that needed a submit of their own (PerformReadback).

◆ lastGpuFrameSeconds

double tachyon::vulkan::VulkanWindowContext::lastGpuFrameSeconds = 0.0

◆ timestampPeriodNs

float tachyon::vulkan::VulkanWindowContext::timestampPeriodNs = 0.0f

nanoseconds per timestamp tick; 0: no timestamps


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