41 class VulkanWindowContext;
103 const std::source_location& loc = std::source_location::current())
override;
111 const std::source_location& loc = std::source_location::current());
119 const std::source_location& loc = std::source_location::current());
169 void AddFrameWait(VkSemaphore semaphore, uint64_t value, VkPipelineStageFlags2 stageMask)
180 struct ImageTarget { VkImage image; VkExtent2D extent; };
181 std::unordered_map<tachyon::ID, ImageTarget> m_imageTargets;
182 std::unordered_map<tachyon::ID, tachyon::vulkan::VulkanWindowContext*> m_windowContexts;
227 VkExtent2D extent {};
228 uint64_t lastFrame = 0;
237 std::unordered_map<tachyon::ID, SceneTarget> m_scenes;
238 std::vector<SceneRequest> m_sceneRequests;
239 uint64_t m_sceneFrame = 0;
240 void ReleaseScene(SceneTarget& scene);
242 tachyon::StyleManager* m_lastStyleManager{
nullptr };
243 tachyon::GradientManager* m_lastGradientManager{
nullptr };
244 float m_lastElapsedTimeSecs{ 0.0f };
245 float m_frameBuildSeconds{ 0.0f };
246 uint64_t m_imageDescriptorSetWrites{ 0 };
Definition gui_buffer.h:9
virtual void StopResizing()=0
virtual bool StartResizing(ID id)=0
The atlas that the colors of color styles are baked into: pages of 2D textures, one row per gradient,...
Definition gui_gradient_manager.h:65
A graphics backend: the device, the window contexts that render the GUI's windows,...
Definition gui_graphics_context.h:53
GUIRenderer * guiRenderer
Where the UI records its draw primitives.
Definition gui_graphics_context.h:57
Makes and manages the OS windows and delivers their input; GUIApplication::SetWindowBackend sets one,...
Definition gui_window_backend.h:112
A window's rendering state: made by GraphicsContext::CreateWindowContext for each OS window,...
Definition gui_window_backend.h:72
The images the shaders can sample, each at an ImageIndex. Implemented by the backend.
Definition gui_image.h:106
An image made by GraphicsContext::CreateImage; the backend defines its contents.
Definition gui_image.h:102
A value, or the Error saying why there is none.
Definition gui_result.h:36
What GraphicsContext::RenderScene's record gets: the backend's recording state, as the struct of the ...
Definition gui_graphics_api.h:41
Bakes serializable Styles into deduplicated runtime layout/visual styles; a StyleRef holds indices in...
Definition gui_style_manager.h:39
Definition gui_text_atlas_manager.h:17
The Vulkan device the GUI renders with: its own, or a host's (SetExternalDevice).
Definition vk_device_context.h:114
uint32_t imageSlots
The image slots there are: the ones asked for, or fewer when the device holds fewer sampled images pe...
Definition vk_device_context.h:344
std::string deviceName
chosenGPU's name, as its driver reports it.
Definition vk_device_context.h:321
void SetAllocationHooks(const tachyon::AllocationHooks &hooks)
Host memory functions for every Vulkan object, vk-bootstrap and VMA.
std::string shaderDirectory
Where to load the compiled shaders from; empty uses the built-in ones.
Definition vk_device_context.h:308
uint32_t requestedImageSlots
Image slots asked for (VulkanGraphicsContext::SetImageSlotCount); set before Initialize.
Definition vk_device_context.h:339
void SetSurfaceFactory(SurfaceFactory factory)
How surfaces are made; set before initialization. SDLWindowBackend installs its own.
Definition vk_device_context.h:120
void SetExternalDevice(const ExternalDevice &external)
Renders on the host's device instead of making one; call before initialization.
Definition vk_device_context.h:171
std::string gpuPreference
The GPU asked for (GraphicsContext::SetGpuPreference); set before Initialize.
Definition vk_device_context.h:341
std::function< VkSurfaceKHR(VkInstance, const VkAllocationCallbacks *, tachyon::OSWindowHandle)> SurfaceFactory
Makes a VkSurfaceKHR for one of the window backend's windows with the given instance and allocation c...
Definition vk_device_context.h:118
FrameWaits frameWaits
Library internal: the timeline semaphores the frame's submissions wait on.
Definition vk_device_context.h:269
uint32_t GetImageSlotCount() const override
The slots asked for before Initialize; the ones there are after it.
Definition vk_graphics_context.h:80
std::vector< tachyon::ImageIndex > gradientPageImageIndices
Library internal: the gradient pages' image indices.
Definition vk_graphics_context.h:55
void Reset()
Library internal: clears the renderer's recorded primitives.
Definition vk_graphics_context.h:186
tachyon::Buffer * PrepareVisualBoxStylesBuffer(tachyon::StyleManager &styleManager)
Library internal: the box styles' buffer, uploaded again when they changed.
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 t...
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 SetAllocationHooks(const tachyon::AllocationHooks &hooks) override
Host memory functions for the graphics API's allocations. Call before Initialize.
Definition vk_graphics_context.h:75
void EndFrame() override
Ends the UI build, before the uploads and the window contexts' recording.
Definition vk_graphics_context.h:91
void SimulateDeviceLoss()
Diagnostic: as if the device were lost, so the next frame recreates it.
Definition vk_graphics_context.h:89
tachyon::ImageIndex RegisterImage(tachyon::Image *image) override
Adds the image to the image set; elements draw it by the returned index.
void DestroyVisualBoxStyles(tachyon::Buffer *buffer)
Library internal: destroys the buffer's GPU objects now.
tachyon::GPUDrawPushConstants pushConstants
Library internal: the push constants PrepareFrame sets for the frame's draws.
Definition vk_graphics_context.h:194
void DestroyVisualColorStyles(tachyon::Buffer *buffer)
Library internal: destroys the buffer's GPU objects now.
void SetGpuPreference(std::string_view preference) override
Which GPU to render with, when there's more than one: a kind ("integrated", "discrete"),...
Definition vk_graphics_context.h:78
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::GetNativeH...
void PrepareFrame(tachyon::StyleManager &styleManager, tachyon::GradientManager &gradientManager, float elapsedTimeSecs) override
GraphicsContext::PrepareFrame: uploads changed styles and registers the gradient pages.
void StopResizing()
Library internal: the live-resize redraw ends.
Definition vk_graphics_context.h:177
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 v...
Definition vk_graphics_context.h:169
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...
void DestroyWindowContext(tachyon::IWindowContext *context) override
Waits for the context's GPU work and destroys it now; its native window must still exist.
tachyon::Buffer * PrepareVisualColorStylesBuffer(tachyon::StyleManager &styleManager, tachyon::GradientManager &gradientManager)
Library internal: the color styles' buffer, uploaded again when they changed.
bool UpdateImageRows(tachyon::Image *image, uint32_t firstRow, uint32_t rowCount, const void *data) override
Writes rowCount rows from firstRow into an image CreateImage made with pixels (not mipmapped): tightl...
Result< void > Initialize(tachyon::IWindowBackend *windowBackend) override
Brings the device up; GUIApplication::Initialize calls it once, before any window context.
tachyon::Buffer * visualBoxStylesMesh
Library internal: the box styles' GPU buffer.
Definition vk_graphics_context.h:51
void SetSurfaceFactory(VulkanDeviceContext::SurfaceFactory factory)
How surfaces are made for the window backend's windows; SDLWindowBackend installs its own.
Definition vk_graphics_context.h:70
bool DeviceLost() const override
True once the GPU device is lost; RecreateDevice then makes a new one.
Definition vk_graphics_context.h:86
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 RegisterE...
void RecordScenes(VkCommandBuffer cmd, tachyon::ID window)
Library internal: records the scenes asked for in window this frame into cmd, before the window's own...
VulkanDeviceContext deviceContext
The device; set it up (external device, debug config) before Initialize.
Definition vk_graphics_context.h:57
tachyon::ImageSet * GetImageSet() const override
The images the shaders sample, by ImageIndex.
tachyon::Buffer * colorStylesMesh
Library internal: the color styles' GPU buffer.
Definition vk_graphics_context.h:53
VulkanImageSet * vulkanImageSet
Library internal: the image set behind GetImageSet.
Definition vk_graphics_context.h:49
tachyon::Buffer * UploadVisualColorStyles(std::span< const tachyon::VisualColorStyle > colorStyles)
Library internal: the color styles in a GPU buffer for the shaders.
tachyon::Buffer * UploadVisualBoxStyles(std::span< const tachyon::VisualBoxStyle > visualBoxStyles)
Library internal: the box styles in a GPU buffer for the shaders.
class VulkanTextAtlasManager * m_textAtlas
The atlas manager made last (the text system owns it), its slots refreshed when a lost device is rema...
Definition vk_graphics_context.h:130
void DestroyImage(tachyon::Image *img)
Destroys the image's Vulkan objects now, without waiting for the GPU; doesn't delete the object.
void SetShaderDirectory(std::string_view directory)
Loads the compiled shaders (box_shader.vert.spv, ...) from directory instead of the ones built into t...
Definition vk_graphics_context.h:74
void SetFrameBuildSeconds(float seconds)
Library internal: window contexts report their CPU seconds between presents (GetLastFrameBuildSeconds...
Definition vk_graphics_context.h:218
std::string_view GetDeviceName() const override
The GPU it renders with, as the driver names it ("NVIDIA GeForce RTX 4070"); empty before Initialize ...
Definition vk_graphics_context.h:64
bool StartResizing(tachyon::ID id)
Library internal: a window's live-resize redraw starts (GUIRenderer::StartResizing).
Definition vk_graphics_context.h:175
tachyon::GraphicsAPI GetAPI() const override
The API it presents with; window backends make their windows for it.
Definition vk_graphics_context.h:63
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 im...
tachyon::TextAtlasManager * CreateTextAtlasManager() override
A new text atlas manager for the backend. The caller owns it and keeps it past Cleanup.
void BeginFrame() override
Starts a frame's UI build: resets the renderer for new primitives (Vulkan: also frees what frame-scop...
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.
uint64_t ImageDescriptorSetWrites() const
How many times a window frame wrote its image descriptor set: once per frame slot after the image set...
Definition vk_graphics_context.h:205
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.
void RePrepareFrame()
Library internal: PrepareFrame with the last call's arguments; lets a live resize pick up the style c...
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.
~VulkanGraphicsContext() override
float GetLastFrameBuildSeconds() const override
Wall-clock seconds of CPU work in the last frame: from just after one present returns to just before ...
Definition vk_graphics_context.h:215
void SetExternalDevice(const VulkanDeviceContext::ExternalDevice &external)
Render on the host's device instead of creating one.
Definition vk_graphics_context.h:68
void Cleanup() override
Waits for the GPU and destroys what the backend made, the renderer included.
void UnregisterImage(tachyon::ImageIndex index) override
Frees the index for reuse; the image stays (DestroyImageAtEnd destroys it).
bool RenderWindowFrame(VkCommandBuffer cmd, FrameData ¤tFrame, tachyon::ID windowID, tachyon::uint2 extent)
Library internal: records a window's primitives into cmd.
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: for DeviceScope::Frame once i...
tachyon::ImageIndex RenderScene(tachyon::ID key, tachyon::ID window, tachyon::uint2 size, tachyon::color4f clear, std::function< void(const tachyon::ScenePayload &scene)> record) override
GraphicsContext::RenderScene: a color image (R8G8B8A8_UNORM) and a depth one (D32_SFLOAT); record get...
void SetImageSlotCount(uint32_t count) override
4096 by default; fewer when the device can't sample that many in a shader stage.
Definition vk_graphics_context.h:77
Definition vk_text_atlas_manager.h:27
void SetDeviceLost(bool lost)
Sampler
How an image is filtered and addressed when sampled.
Definition gui_image.h:89
ImageFormat
Pixel formats for GraphicsContext::CreateImage, 8 bits per channel.
Definition gui_image.h:75
ImageIndex
Index of an image in the graphics context's image set, as the shaders sample it.
Definition gui_image.h:99
DeviceScope
When a deferred GPU resource destruction runs: Frame once the GPU has finished the frames that may us...
Definition gui_graphics_context.h:44
@ Invalid
Definition gui_image.h:99
std::function< void()> OnGuiFunc
Definition gui_base_types.h:13
WindowFlags
How an OS window is made and behaves (IWindowBackend::CreateWindow); flags combine with |.
Definition gui_window_flags.h:14
void * OSWindowHandle
An OS window, opaque; what it points to is up to the window backend.
Definition gui_window_backend.h:37
Definition vk_defaults.h:6
Definition gui_logging.h:24
GraphicsAPI
The graphics API a backend presents with; window backends create their windows to match (SDL: SDL_WIN...
Definition gui_graphics_api.h:14
@ Vulkan
Definition gui_graphics_api.h:16
Memory functions a host gives the library, for the allocations that can be routed: Vulkan objects,...
Definition gui_allocation_hooks.h:17
Definition gui_render_primitives.h:257
A 64-bit element ID whose bit layout depends on its IDMode.
Definition gui_id.h:23
Definition gui_base_types.h:394
Integer 2D vector.
Definition gui_base_types.h:18
Definition gui_base_types.h:74
Definition vk_window_context.h:29
void Add(VkSemaphore semaphore, uint64_t value, VkPipelineStageFlags2 stageMask)
Waits for semaphore to reach value before stageMask.
Definition vk_device_context.h:76
A host's Vulkan handles for SetExternalDevice, so the GUI renders on the host's device (an engine hos...
Definition vk_device_context.h:148
What GraphicsContext::RenderScene's record gets on Vulkan (ScenePayload::As): the frame's command buf...
Definition vk_graphics_context.h:27
VkFormat colorFormat
Definition vk_graphics_context.h:31
VkFormat depthFormat
Definition vk_graphics_context.h:32
VkCommandBuffer commandBuffer
Definition vk_graphics_context.h:30
static constexpr tachyon::GraphicsAPI kAPI
Definition vk_graphics_context.h:28
VkExtent2D extent
Definition vk_graphics_context.h:33