|
TachyonUI 1.1.0
High-performance UI for building tools.
|
#include <gui_core/graphics/sdlgpu/sdlgpu_graphics_context.h>
Classes | |
| struct | Impl |
Public Types | |
| using | WindowResolver = SDL_Window* (*)(OSWindowHandle window) |
| The SDL window of a window backend's window (OSWindowHandle): SDLWindowBackend sets it. | |
Public Member Functions | |
| SDLGPUGraphicsContext () | |
| ~SDLGPUGraphicsContext () override | |
| void | SetExternalDevice (SDL_GPUDevice *device) |
| Render on the host's device instead of making one. | |
| GraphicsAPI | GetAPI () const override |
| The API it presents with; window backends make their windows for it. | |
| std::string_view | GetDeviceName () const override |
| The GPU, and the driver SDL renders with: "NVIDIA GeForce RTX 4070 (vulkan)". | |
| void | SetGpuPreference (std::string_view preference) override |
| "integrated" or "cpu" ask SDL for its low-power GPU; SDL picks among the others. | |
| void | SetDriver (std::string_view driver) |
| The driver SDL renders with: "vulkan", "direct3d12" or "metal"; empty, SDL's choice. | |
| std::string_view | GetDriver () const |
| The driver in use, after Initialize. | |
| void | SetDebugConfig (const DebugConfig &config) |
| Call before Initialize. | |
| void | SetWindowResolver (WindowResolver resolver) |
| void | SetImageSlotCount (uint32_t slots) override |
| 4096 by default. Call before Initialize. | |
| uint32_t | GetImageSlotCount () const override |
| How many images can be registered at once; 0 when the backend doesn't say. | |
| Result< void > | Initialize (IWindowBackend *windowBackend) override |
| Makes the device, on a driver that takes the shaders the GUI has (SPIR-V, DXIL) and, on Vulkan, has the 16-bit types they use. | |
| void | Cleanup () override |
| Waits for the GPU and destroys what the backend made, the renderer included. | |
| Image * | CreateImage (void *data, uint2 size, ImageFormat format, Sampler sampler, bool mipmapped=false) override |
| R8G8B8 is widened to R8G8B8A8, and R8 and R8G8 in sRGB too (SDL GPU has no such formats). | |
| bool | UpdateImageRows (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): tightly packed in its format, the image's width each. | |
| void | DestroyImageAtEnd (Image *img, 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 it has finished the frames that may have drawn with it, however many frames draw nothing meanwhile; for DeviceScope::Application at Cleanup. | |
| TextAtlasManager * | CreateTextAtlasManager () override |
| A new text atlas manager for the backend. The caller owns it and keeps it past Cleanup. | |
| ImageSet * | GetImageSet () const override |
| The images the shaders sample, by ImageIndex. | |
| ImageIndex | RegisterImage (Image *image) override |
| Adds the image to the image set; elements draw it by the returned index. | |
| void | UnregisterImage (ImageIndex index) override |
| A host's texture's slot (RegisterExternalImage) goes too; the texture stays the host's. | |
| void | PrepareFrame (StyleManager &styleManager, GradientManager &gradientManager, float elapsedTimeSecs) override |
| The gradient pages into the image set, the styles uploaded where they changed, and the images each style reads, for cutting draws (ImageBatcher). | |
| void | RePrepareFrame () |
| PrepareFrame again with its last arguments: a live resize's redraw changes styles. | |
| IWindowContext * | CreateWindowContext (void *nativeWindowHandle, OSWindowHandle osHandle, ID id, int2 size, WindowFlags windowFlags, OnGuiFunc onGui) override |
| An OS window is claimed for the device: SDL makes its swapchain. | |
| void | DestroyWindowContext (IWindowContext *context) override |
| Waits for the context's GPU work and destroys it now; its native window must still exist. | |
| void | BeginFrame () override |
| Lets go of the scenes no longer asked for. | |
| ImageIndex | RenderScene (ID key, ID window, uint2 size, color4f clear, std::function< void(const ScenePayload &scene)> record) override |
| The scene's color texture (R8G8B8A8_UNORM, sampled with Sampler::LinearClampToEdge) and depth (D32_FLOAT), drawn by record in window's next frame before its UI. | |
| ImageIndex | RegisterExternalImage (SDL_GPUTexture *texture, Sampler sampler) |
| A texture the host renders (a 3D viewport) in the image set, for the Image control or a primitive to sample with sampler. | |
| void | UpdateExternalImage (ImageIndex index, SDL_GPUTexture *texture, Sampler sampler) |
| Points an existing index at another texture, for example after a resize, under the same rules. | |
| void | SetWindowImageTarget (ID window, SDL_GPUTexture *texture, uint2 size) |
| The host texture a render-to-image window (WindowFlags::RenderToImage) is copied into each frame; null stops. | |
| void | WaitIdle () |
| Waits until the GPU has done all work submitted so far. | |
| Impl & | Internal () |
| Library internal: the device and what the window contexts share. | |
| Public Member Functions inherited from tachyon::NullGraphicsContext | |
| NullGraphicsContext () | |
| ~NullGraphicsContext () override | |
| void | SetAllocationHooks (const AllocationHooks &) override |
| Host memory functions for the graphics API's allocations. Call before Initialize. | |
| void | EndFrame () override |
| Ends the UI build, before the uploads and the window contexts' recording. | |
| uint64_t | RecordedFrames (ID window) const |
| How many frames the window was recorded in (RecordWindowFrame), for tests. | |
| Public Member Functions inherited from tachyon::GraphicsContext | |
| bool | TakeContentChanged () |
| True when something drawn changed since the last call without a draw changing: an image registered or unregistered (a slot reused shows other pixels), or a scene rendered. | |
| GraphicsContext ()=default | |
| virtual | ~GraphicsContext () |
| virtual bool | DeviceLost () const |
| True once the GPU device is lost; RecreateDevice then makes a new one. | |
| virtual Result< void > | RecreateDevice (IWindowBackend *) |
| Makes a new device after DeviceLost, and everything the backend owns on it (the window contexts are the caller's to make again). | |
| virtual float | GetLastFrameBuildSeconds () const |
| 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. | |
Static Public Member Functions | |
| static void | ApplyDeviceRequirements (SDL_PropertiesID props) |
| Sets on props what the GUI's shaders need of a device a host makes with SDL_CreateGPUDeviceWithProperties: the shader formats they're built in (SPIR-V, and DXIL on Windows), and on Vulkan the feature they use (draw parameters), as SDL_PROP_GPU_DEVICE_CREATE_VULKAN_OPTIONS_POINTER. | |
| static bool | CheckDeviceSupport (SDL_GPUDevice *device, std::string *problems=nullptr) |
| Whether device takes the GUI's shaders; what it lacks, one line each, in problems. | |
Additional Inherited Members | |
| Public Attributes inherited from tachyon::GraphicsContext | |
| GUIRenderer * | guiRenderer = nullptr |
| Where the UI records its draw primitives. | |
| Protected Member Functions inherited from tachyon::GraphicsContext | |
| void | MarkContentChanged () |
| For backends: see TakeContentChanged. | |
| using tachyon::sdlgpu::SDLGPUGraphicsContext::WindowResolver = SDL_Window* (*)(OSWindowHandle window) |
The SDL window of a window backend's window (OSWindowHandle): SDLWindowBackend sets it.
| tachyon::sdlgpu::SDLGPUGraphicsContext::SDLGPUGraphicsContext | ( | ) |
|
override |
|
static |
Sets on props what the GUI's shaders need of a device a host makes with SDL_CreateGPUDeviceWithProperties: the shader formats they're built in (SPIR-V, and DXIL on Windows), and on Vulkan the feature they use (draw parameters), as SDL_PROP_GPU_DEVICE_CREATE_VULKAN_OPTIONS_POINTER.
Options of the host's own replace those: then enable shaderDrawParameters (Vulkan 1.1) in them, with Vulkan 1.2. What it points to lives as long as the program.
|
static |
Whether device takes the GUI's shaders; what it lacks, one line each, in problems.
SDL can't tell which Vulkan features a device has: one made without ApplyDeviceRequirements' may draw wrongly, which its debug mode reports.
| void tachyon::sdlgpu::SDLGPUGraphicsContext::SetExternalDevice | ( | SDL_GPUDevice * | device | ) |
Render on the host's device instead of making one.
Call before Initialize, which fails when the device can't be used. Debug mode is the host's choice when it makes the device; SDL GPU's messages go to the DebugConfig. Cleanup leaves the device to the host, which destroys it after.
|
inlineoverridevirtual |
The API it presents with; window backends make their windows for it.
Reimplemented from tachyon::NullGraphicsContext.
|
overridevirtual |
The GPU, and the driver SDL renders with: "NVIDIA GeForce RTX 4070 (vulkan)".
Reimplemented from tachyon::GraphicsContext.
|
overridevirtual |
"integrated" or "cpu" ask SDL for its low-power GPU; SDL picks among the others.
Reimplemented from tachyon::GraphicsContext.
| void tachyon::sdlgpu::SDLGPUGraphicsContext::SetDriver | ( | std::string_view | driver | ) |
The driver SDL renders with: "vulkan", "direct3d12" or "metal"; empty, SDL's choice.
Call before Initialize.
| std::string_view tachyon::sdlgpu::SDLGPUGraphicsContext::GetDriver | ( | ) | const |
The driver in use, after Initialize.
| void tachyon::sdlgpu::SDLGPUGraphicsContext::SetDebugConfig | ( | const DebugConfig & | config | ) |
Call before Initialize.
| void tachyon::sdlgpu::SDLGPUGraphicsContext::SetWindowResolver | ( | WindowResolver | resolver | ) |
|
overridevirtual |
4096 by default. Call before Initialize.
Reimplemented from tachyon::GraphicsContext.
|
overridevirtual |
How many images can be registered at once; 0 when the backend doesn't say.
Reimplemented from tachyon::GraphicsContext.
|
overridevirtual |
Makes the device, on a driver that takes the shaders the GUI has (SPIR-V, DXIL) and, on Vulkan, has the 16-bit types they use.
Fails when SDL finds none. With a host's device (SetExternalDevice), checks it instead (CheckDeviceSupport).
Reimplemented from tachyon::NullGraphicsContext.
|
overridevirtual |
Waits for the GPU and destroys what the backend made, the renderer included.
The window contexts are destroyed before it.
Reimplemented from tachyon::NullGraphicsContext.
|
overridevirtual |
R8G8B8 is widened to R8G8B8A8, and R8 and R8G8 in sRGB too (SDL GPU has no such formats).
mipmapped makes the base level only, as the samplers read no other. The pixels go to the GPU with the next window frame.
Reimplemented from tachyon::NullGraphicsContext.
|
overridevirtual |
Writes rowCount rows from firstRow into an image CreateImage made with pixels (not mipmapped): tightly packed in its format, the image's width each.
As CreateImage's upload, it doesn't wait for the GPU and goes with the next frame, ahead of its draws; the frames already sent draw what they had. False when the backend can't, and the caller makes the image again instead (the default).
Reimplemented from tachyon::GraphicsContext.
|
overridevirtual |
Destroys the image and deletes the object once the GPU is done with it: for DeviceScope::Frame once it has finished the frames that may have drawn with it, however many frames draw nothing meanwhile; for DeviceScope::Application at Cleanup.
Unregister it first (UnregisterImage): no frame may draw with it after this. Any thread. loc is for diagnostics.
Reimplemented from tachyon::NullGraphicsContext.
|
overridevirtual |
A new text atlas manager for the backend. The caller owns it and keeps it past Cleanup.
Reimplemented from tachyon::NullGraphicsContext.
|
overridevirtual |
The images the shaders sample, by ImageIndex.
Reimplemented from tachyon::NullGraphicsContext.
|
overridevirtual |
Adds the image to the image set; elements draw it by the returned index.
Reimplemented from tachyon::NullGraphicsContext.
|
overridevirtual |
A host's texture's slot (RegisterExternalImage) goes too; the texture stays the host's.
Reimplemented from tachyon::NullGraphicsContext.
|
overridevirtual |
The gradient pages into the image set, the styles uploaded where they changed, and the images each style reads, for cutting draws (ImageBatcher).
Reimplemented from tachyon::NullGraphicsContext.
| void tachyon::sdlgpu::SDLGPUGraphicsContext::RePrepareFrame | ( | ) |
PrepareFrame again with its last arguments: a live resize's redraw changes styles.
|
overridevirtual |
An OS window is claimed for the device: SDL makes its swapchain.
A layered one (transparent, on Windows) isn't: its frames are read back and shown with UpdateLayeredWindow. A render-to-image window's frames are read back.
Reimplemented from tachyon::NullGraphicsContext.
|
overridevirtual |
Waits for the context's GPU work and destroys it now; its native window must still exist.
Reimplemented from tachyon::NullGraphicsContext.
|
overridevirtual |
Lets go of the scenes no longer asked for.
Reimplemented from tachyon::NullGraphicsContext.
|
overridevirtual |
The scene's color texture (R8G8B8A8_UNORM, sampled with Sampler::LinearClampToEdge) and depth (D32_FLOAT), drawn by record in window's next frame before its UI.
Reimplemented from tachyon::GraphicsContext.
| ImageIndex tachyon::sdlgpu::SDLGPUGraphicsContext::RegisterExternalImage | ( | SDL_GPUTexture * | texture, |
| Sampler | sampler ) |
A texture the host renders (a 3D viewport) in the image set, for the Image control or a primitive to sample with sampler.
It has SDL_GPU_TEXTUREUSAGE_SAMPLER; it stays the host's and must outlive every GUI frame that samples it. SDL orders the host's submits and the GUI's on the device: render it in a command buffer submitted before the GUI's frame (during OnGUI), and it shows in that frame.
| void tachyon::sdlgpu::SDLGPUGraphicsContext::UpdateExternalImage | ( | ImageIndex | index, |
| SDL_GPUTexture * | texture, | ||
| Sampler | sampler ) |
Points an existing index at another texture, for example after a resize, under the same rules.
No GUI frame in flight may still sample the old one (WaitIdle).
| void tachyon::sdlgpu::SDLGPUGraphicsContext::SetWindowImageTarget | ( | ID | window, |
| SDL_GPUTexture * | texture, | ||
| uint2 | size ) |
The host texture a render-to-image window (WindowFlags::RenderToImage) is copied into each frame; null stops.
Can be set before the window exists. An SDL_GPU_TEXTUREFORMAT_B8G8R8A8_UNORM texture of size: the window's size, as the copy isn't scaled (another size gets the part they share). It holds premultiplied alpha, transparent where the UI draws nothing. Read it in work submitted after the GUI's frame.
| void tachyon::sdlgpu::SDLGPUGraphicsContext::WaitIdle | ( | ) |
Waits until the GPU has done all work submitted so far.
|
inline |
Library internal: the device and what the window contexts share.