|
TachyonUI 1.1.0
High-performance UI for building tools.
|
#include <gui_core/graphics/d3d12/d3d12_graphics_context.h>
Classes | |
| struct | Impl |
Public Member Functions | |
| D3D12GraphicsContext () | |
| ~D3D12GraphicsContext () override | |
| void | SetExternalDevice (const ExternalDevice &external) |
| Render on the host's device and queue instead of making them. | |
| GraphicsAPI | GetAPI () const override |
| The API it presents with; window backends make their windows for it. | |
| std::string_view | GetDeviceName () const override |
| The GPU it renders with, as the driver names it ("NVIDIA GeForce RTX 4070"); empty before Initialize and for a backend without a device. | |
| bool | DeviceLost () const override |
| The device was removed. | |
| void | SetGpuPreference (std::string_view preference) override |
| Which GPU to render with, when there's more than one: a kind ("integrated", "discrete"), the GPU's number in the log's list of detected GPUs, or part of its name ("radeon"); see ChooseGpu. | |
| void | SetImageSlotCount (uint32_t slots) override |
| 4096 by default, 1,000,000 at most (a shader-visible descriptor heap's size). | |
| uint32_t | GetImageSlotCount () const override |
| How many images can be registered at once; 0 when the backend doesn't say. | |
| void | SetDebugConfig (const DebugConfig &config) |
| Call before Initialize. | |
| Result< void > | Initialize (IWindowBackend *windowBackend) override |
| Picks a GPU that runs Shader Model 6.6 with resource binding tier 3 (the shaders' descriptor heap indexing) and makes the device, its queue and the GUI's pipelines. | |
| void | Cleanup () override |
| Waits for the GPU and destroys what the backend made, the renderer included. | |
| void | BeginFrame () override |
| Frees what the GPU is done with, and resets the renderer. | |
| Image * | CreateImage (void *data, uint2 size, ImageFormat format, Sampler sampler, bool mipmapped=false) override |
| R8G8B8 is widened to R8G8B8A8 (Direct3D 12 has no 3-byte format), and R8 and R8G8 in sRGB too (it has no sRGB format of fewer channels). | |
| 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. | |
| IWindowContext * | CreateWindowContext (void *nativeWindowHandle, OSWindowHandle osHandle, ID id, int2 size, WindowFlags windowFlags, OnGuiFunc onGui) override |
| An OS window gets a swapchain, a layered (transparent) one none: its frames are read back and shown with UpdateLayeredWindow. | |
| void | DestroyWindowContext (IWindowContext *context) override |
| Waits for the context's GPU work and destroys it now; its native window must still exist. | |
| 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 |
| Frees the index for reuse; the image stays (DestroyImageAtEnd destroys it). | |
| void | PrepareFrame (StyleManager &styleManager, GradientManager &gradientManager, float elapsedTimeSecs) override |
| The gradient pages into the image set, and the styles uploaded where they changed. | |
| void | RePrepareFrame () |
| PrepareFrame again with its last arguments: a live resize's redraw changes styles. | |
| 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 (ID3D12Resource *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, ID3D12Resource *texture, Sampler sampler) |
| Points an existing index at another texture, for example after a resize, under the same rules. | |
| void | SetWindowImageTarget (ID window, ID3D12Resource *texture) |
| The host texture a render-to-image window (WindowFlags::RenderToImage) is copied into each frame; null stops. | |
| void | AddFrameWait (ID3D12Fence *fence, uint64_t value) |
| The GUI's next frame waits on the queue for fence to reach value: for work the host submits to another queue (async compute) that the GUI shows. | |
| void | WaitIdle () |
| Waits until the GPU has done all work submitted so far. | |
| uint64_t | ImageViewWrites () const |
| How many image views the image set has written: a slot set to the image it holds writes none. | |
| Impl & | Internal () |
| Library internal: the device, its queue, and what the window contexts draw with. | |
| Public Member Functions inherited from tachyon::NullGraphicsContext | |
| NullGraphicsContext () | |
| ~NullGraphicsContext () override | |
| GraphicsAPI | GetAPI () const override |
| The API it presents with; window backends make their windows for it. | |
| void | SetAllocationHooks (const AllocationHooks &) override |
| Host memory functions for the graphics API's allocations. Call before Initialize. | |
| Result< void > | Initialize (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. | |
| 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. | |
| Image * | CreateImage (void *data, uint2 size, ImageFormat format, Sampler sampler, bool mipmapped=false) override |
| Makes an image from size.x x size.y tightly packed pixels of format (Vulkan: data null for a cleared image); mipmapped generates its mip levels. | |
| 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. | |
| IWindowContext * | CreateWindowContext (void *nativeWindowHandle, OSWindowHandle osHandle, ID id, int2 size, WindowFlags windowFlags, 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 (IWindowContext *context) override |
| Waits for the context's GPU work and destroys it now; its native window must still exist. | |
| 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 |
| Frees the index for reuse; the image stays (DestroyImageAtEnd destroys it). | |
| void | PrepareFrame (StyleManager &styleManager, GradientManager &gradientManager, float) override |
| Nothing to upload: takes the style and gradient changes, as a GPU backend's upload does. | |
| 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 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 bool | CheckDeviceSupport (ID3D12Device *device, std::string *problems=nullptr) |
| Whether device runs 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. | |
| tachyon::d3d12::D3D12GraphicsContext::D3D12GraphicsContext | ( | ) |
|
override |
|
static |
Whether device runs the GUI's shaders; what it lacks, one line each, in problems.
| void tachyon::d3d12::D3D12GraphicsContext::SetExternalDevice | ( | const ExternalDevice & | external | ) |
Render on the host's device and queue instead of making them.
Call before Initialize, which fails when they can't be used. The debug layer is the host's to turn on; its messages go to the DebugConfig. A device the host made isn't checked for leaks at Cleanup, as the host's own references remain.
|
inlineoverridevirtual |
The API it presents with; window backends make their windows for it.
Implements tachyon::GraphicsContext.
|
overridevirtual |
The GPU it renders with, as the driver names it ("NVIDIA GeForce RTX 4070"); empty before Initialize and for a backend without a device.
Reimplemented from tachyon::GraphicsContext.
|
overridevirtual |
The device was removed.
This backend doesn't make a new one: the app's frames end with the error, for it to start again.
Reimplemented from tachyon::GraphicsContext.
|
overridevirtual |
Which GPU to render with, when there's more than one: a kind ("integrated", "discrete"), the GPU's number in the log's list of detected GPUs, or part of its name ("radeon"); see ChooseGpu.
Empty, the default, leaves it to the backend (a discrete GPU first). The TACHYON_GPU environment variable takes its place when set. Call before Initialize. The default does nothing.
Reimplemented from tachyon::GraphicsContext.
|
overridevirtual |
4096 by default, 1,000,000 at most (a shader-visible descriptor heap's size).
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.
| void tachyon::d3d12::D3D12GraphicsContext::SetDebugConfig | ( | const DebugConfig & | config | ) |
Call before Initialize.
|
overridevirtual |
Picks a GPU that runs Shader Model 6.6 with resource binding tier 3 (the shaders' descriptor heap indexing) and makes the device, its queue and the GUI's pipelines.
Fails when none can, which a Windows 10 without the newer D3D12 runtime is.
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.
|
overridevirtual |
Frees what the GPU is done with, and resets the renderer.
Implements tachyon::GraphicsContext.
|
overridevirtual |
R8G8B8 is widened to R8G8B8A8 (Direct3D 12 has no 3-byte format), and R8 and R8G8 in sRGB too (it has no sRGB format of fewer channels).
mipmapped makes the base level only: the samplers read nothing else, as on Vulkan. The pixels go to the GPU with the next window frame.
Implements tachyon::GraphicsContext.
|
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.
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 |
An OS window gets a swapchain, a layered (transparent) one none: its frames are read back and shown with UpdateLayeredWindow.
A render-to-image window's are read back.
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 |
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.
|
overridevirtual |
The gradient pages into the image set, and the styles uploaded where they changed.
Implements tachyon::GraphicsContext.
| void tachyon::d3d12::D3D12GraphicsContext::RePrepareFrame | ( | ) |
PrepareFrame again with its last arguments: a live resize's redraw changes styles.
|
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::d3d12::D3D12GraphicsContext::RegisterExternalImage | ( | ID3D12Resource * | 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.
The texture stays the host's and must outlive every GUI frame that samples it. Call it while the UI is built (OnGUI).
The GUI's frame reads it in D3D12_RESOURCE_STATE_ALL_SHADER_RESOURCE: the host leaves it so in work submitted to the GUI's queue before the GUI's frame (which orders the two), and moves it out only in work submitted after.
| void tachyon::d3d12::D3D12GraphicsContext::UpdateExternalImage | ( | ImageIndex | index, |
| ID3D12Resource * | 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::d3d12::D3D12GraphicsContext::SetWindowImageTarget | ( | ID | window, |
| ID3D12Resource * | texture ) |
The host texture a render-to-image window (WindowFlags::RenderToImage) is copied into each frame; null stops.
Can be set before the window exists. A DXGI_FORMAT_B8G8R8A8_UNORM texture the window's size: a texture of another size gets the part they share, as it isn't scaled. The GUI's frame moves it from D3D12_RESOURCE_STATE_ALL_SHADER_RESOURCE to COPY_DEST, copies, and leaves it in ALL_SHADER_RESOURCE; the host reads it in work submitted after the GUI's frame and leaves it in that state.
| void tachyon::d3d12::D3D12GraphicsContext::AddFrameWait | ( | ID3D12Fence * | fence, |
| uint64_t | value ) |
The GUI's next frame waits on the queue for fence to reach value: for work the host submits to another queue (async compute) that the GUI shows.
Waits on the same fence merge (the higher value). Call it while the UI is built (OnGUI) or before the frame; the frame after that one doesn't wait on it again.
| void tachyon::d3d12::D3D12GraphicsContext::WaitIdle | ( | ) |
Waits until the GPU has done all work submitted so far.
| uint64_t tachyon::d3d12::D3D12GraphicsContext::ImageViewWrites | ( | ) | const |
How many image views the image set has written: a slot set to the image it holds writes none.
|
inline |
Library internal: the device, its queue, and what the window contexts draw with.