|
KiCad PCB EDA Suite
|
Thread that owns the RHI device. More...
#include <render_thread.h>
Public Member Functions | |
| RENDER_THREAD (RHI_DEVICE_FACTORY aDeviceFactory) | |
| ~RENDER_THREAD () | |
| RENDER_THREAD (const RENDER_THREAD &)=delete | |
| RENDER_THREAD & | operator= (const RENDER_THREAD &)=delete |
| bool | Start () |
| Block until the render thread has created the device and its pipelines. | |
| bool | IsRunning () const |
| void | SetGlyphAtlas (std::shared_ptr< const RHI_GLYPH_ATLAS_DATA > aAtlas) |
| Give the track shaders the font atlas glyph instances draw from. | |
| bool | SubmitControl (RHI_CONTROL_COMMAND aCmd) |
| void | SubmitUpload (RHI_UPLOAD_COMMAND aCmd) |
| Callable from any thread. | |
| bool | WaitForFence (std::chrono::milliseconds aTimeout=std::chrono::milliseconds(2000)) |
| Block until every command submitted before this call has been processed. | |
| void | Shutdown () |
| Block until the render thread exits. | |
| RHI_BACKEND | GetBackendType () const |
| uint32_t | GetMaxTextureSize () const |
| RHI_BufferHandle | ReserveBufferHandle () |
| Reserve a handle without creating the GPU resource, so RHI_DEVICE_PROXY can hand it out on the UI thread and create the resource on the render thread. | |
| RHI_TextureHandle | ReserveTextureHandle () |
| bool | ReadbackWindowPixels (RHI_WINDOW_ID aWindowId, wxImage &aImage) |
| Read back a window's picture at backing resolution without the overlay and cursor. | |
| int | GetLoopPhase () const |
| bool | IsDeviceLost () const |
| bool | HasPresented (RHI_WINDOW_ID aWindowId) const |
| void | AddDeviceLostListener (const void *aOwner, std::function< void()> aListener) |
| Call aListener on the render thread when the device is lost. | |
| void | RemoveDeviceLostListener (const void *aOwner) |
| Once this returns, the owner's listener is not running and will not be called. | |
| void | OnDeviceLost () |
| Stop drawing on a lost device. | |
Static Public Member Functions | |
| static void | ComputeBackingResolution (uint32_t aLogicalW, uint32_t aLogicalH, float aDpiScale, uint32_t &aBackingW, uint32_t &aBackingH) |
| Compute the physical pixel backing size from logical size and DPI scale, at least 1x1. | |
Private Types | |
| enum class | GEOMETRY_RANGES : uint8_t { ALL , NOT_OVERLAY , OVERLAY } |
| The ranges of a draw descriptor one geometry pass draws. More... | |
Private Member Functions | |
| void | ThreadMain (std::promise< bool > aStarted) |
| void | DrainControlQueue () |
| void | DrainUploadQueue () |
| void | HandleFrameRequest (const RHI_CMD_FRAME_REQUEST &aCmd) |
| void | HandleSwapchainCreate (const RHI_CMD_SWAPCHAIN_CREATE &aCmd) |
| void | HandleSwapchainResize (const RHI_CMD_SWAPCHAIN_RESIZE &aCmd) |
| void | HandleSwapchainDestroy (const RHI_CMD_SWAPCHAIN_DESTROY &aCmd) |
| void | HandleFence (const RHI_CMD_FENCE &aCmd) |
| void | ProcessActiveWindows (bool aIgnorePacing=false) |
| bool | EnsureSwapchain (WINDOW_STATE &aWS, const char *aReason) |
| void | recreateSwapchainAfterOutOfDate (WINDOW_STATE &aWS, bool aSurfaceLost=false) |
Retire and recreate an out of date swapchain, and its surface too when aSurfaceLost. | |
| bool | RenderWindow (WINDOW_STATE &aWS) |
| void | RenderGeometry (WINDOW_STATE &aWS) |
| void | RenderGeometryInto (WINDOW_STATE &aWS, const FRAME_DRAW_DESC &aDesc, RHI_FramebufferHandle aFBO, bool aLogSummary, GEOMETRY_RANGES aRanges=GEOMETRY_RANGES::ALL, uint32_t aStaticDrawMargin=0) |
| bool | prepareCursor (WINDOW_STATE &aWS) |
| Fill the cursor's uniforms. | |
| bool | runFenced (std::function< void()> aWork, std::chrono::milliseconds aTimeout) |
| Run work on the render thread after everything queued before it. | |
| bool | writeUniform (RHI_BufferHandle &aUBO, RHI_BindGroupHandle &aBG, RHI_BindGroupLayoutHandle aLayout, const void *aData, size_t aSize) |
| Write a uniform block, making its buffer and bind group on first use. | |
| void | drawCursor (WINDOW_STATE &aWS) |
| Draw the cursor into the open composite pass. | |
| void | DestroyAllWindows () |
| void | destroyWindow (WINDOW_STATE &aWS) |
| Free a window's targets, uniforms, swapchain and surface. | |
| bool | InitRenderInfrastructure () |
| void | DestroyRenderInfrastructure () |
| void | CreateWindowFBOs (WINDOW_STATE &aWS) |
| void | DestroyWindowFBOs (WINDOW_STATE &aWS) |
| void | DestroyWindowUniforms (WINDOW_STATE &aWS) |
| void | wakeRenderThread () |
| void | deferFrameUntil (WINDOW_STATE::Clock::time_point aDue) |
| RHI_BindGroupHandle | glyphBindGroup () |
| void | destroyGlyphResources () |
Private Attributes | |
| RHI_DEVICE_FACTORY | m_deviceFactory |
| std::unique_ptr< RHI_DEVICE > | m_device |
| std::mutex | m_deviceMutex |
| Guards the m_device pointer, not the device, against UI thread reads racing its creation or destruction. | |
| std::atomic< RHI_BACKEND > | m_backendType { RHI_BACKEND::NONE } |
| std::atomic< uint32_t > | m_maxTextureSize { 0 } |
| SYNC_QUEUE< RHI_CONTROL_COMMAND > | m_controlQueue |
| SYNC_QUEUE< RHI_UPLOAD_COMMAND > | m_uploadQueue |
| std::thread | m_thread |
| std::mutex | m_workMutex |
| std::condition_variable | m_workCV |
| std::atomic< bool > | m_running { false } |
| std::atomic< bool > | m_shutdownRequested { false } |
| bool | m_acceptingWork = false |
| Guarded by m_workMutex. | |
| std::atomic< bool > | m_uploadsPending { false } |
| Set by producers and cleared by the drain so the loop can sleep without missing uploads. | |
| std::atomic< bool > | m_deviceLost { false } |
| std::mutex | m_deviceLostMutex |
| Held while a listener runs, so removing one waits for it to return. | |
| std::unordered_map< const void *, std::function< void()> > | m_deviceLostListeners |
| std::mutex | m_presentedMutex |
| Window IDs are never reused, so an entry outliving its window is harmless. | |
| std::unordered_set< RHI_WINDOW_ID > | m_presentedWindows |
| std::atomic< int > | m_loopPhase { 0 } |
| see GetLoopPhase() | |
| std::unordered_map< RHI_WINDOW_ID, WINDOW_STATE > | m_windows |
| std::vector< WINDOW_STATE * > | m_activeWindowOrder |
| std::optional< WINDOW_STATE::Clock::time_point > | m_deferredFrameDue |
| Earliest time a window held to its display's refresh rate is due, so the loop wakes for it. | |
| std::unique_ptr< RHI_GAL_PIPELINES > | m_pipelines |
| Shared by all windows and created once with the device. | |
| std::unique_ptr< RHI_COMPOSITOR > | m_compositor |
| RHI_BufferHandle | m_unitQuadBuffer |
| RHI_BufferHandle | m_quadCornerBuffer |
| the unit quad's 4 corners | |
| RHI_BufferHandle | m_quadIndexBuffer |
| its 2 triangles over those corners | |
| RHI_TextureHandle | m_glyphTexture |
| The font atlas the track shaders draw glyphs from, its glyph table and their bind group. | |
| RHI_BufferHandle | m_glyphTable |
| RHI_BindGroupHandle | m_glyphBG |
| bool | m_glyphBGHasAtlas = false |
| std::mutex | m_glyphAtlasMutex |
| std::shared_ptr< const RHI_GLYPH_ATLAS_DATA > | m_glyphAtlas |
| RHI_RenderPassHandle | m_geometryRenderPass |
| RHI_RenderPassHandle | m_geometryLoadRenderPass |
| RHI_RenderPassHandle | m_geometryDepthLoadRenderPass |
| clears colour, keeps depth | |
| RHI_RenderPassHandle | m_geometryDepthDiscardRenderPass |
| As m_geometryRenderPass and m_geometryDepthLoadRenderPass, without storing depth nothing reads later. | |
| RHI_RenderPassHandle | m_geometryDepthLoadDiscardRenderPass |
Thread that owns the RHI device.
Other threads talk to it through a control queue for lifecycle and frame commands and an upload queue for data transfers.
Definition at line 66 of file render_thread.h.
|
strongprivate |
The ranges of a draw descriptor one geometry pass draws.
| Enumerator | |
|---|---|
| ALL | |
| NOT_OVERLAY | |
| OVERLAY | |
Definition at line 206 of file render_thread.h.
|
explicit |
Definition at line 309 of file render_thread.cpp.
References m_deviceFactory, and move.
Referenced by operator=(), and RENDER_THREAD().
| KIGFX::RENDER_THREAD::~RENDER_THREAD | ( | ) |
Definition at line 315 of file render_thread.cpp.
References Shutdown().
|
delete |
References RENDER_THREAD().
| void KIGFX::RENDER_THREAD::AddDeviceLostListener | ( | const void * | aOwner, |
| std::function< void()> | aListener ) |
Call aListener on the render thread when the device is lost.
Each owner has one listener.
Definition at line 2536 of file render_thread.cpp.
References m_deviceLostListeners, and m_deviceLostMutex.
|
static |
Compute the physical pixel backing size from logical size and DPI scale, at least 1x1.
Definition at line 2499 of file render_thread.cpp.
Referenced by HandleSwapchainCreate(), and HandleSwapchainResize().
|
private |
Definition at line 2427 of file render_thread.cpp.
References KIGFX::WINDOW_STATE::accumulationFBO, KIGFX::WINDOW_STATE::backingHeight, KIGFX::WINDOW_STATE::backingWidth, RHI_FRAMEBUFFER_DESC::colorFormats, KIGFX::WINDOW_STATE::dynamicFBO, fitSupersampleFactor(), RHI_FRAMEBUFFER_DESC::hasDepthStencil, RHI_FRAMEBUFFER_DESC::height, layerFramebufferDesc(), m_device, marginFramebufferDesc(), KIGFX::WINDOW_STATE::overlayShift, KIGFX::WINDOW_STATE::renderedOverlay, KIGFX::WINDOW_STATE::renderedStatic, KIGFX::WINDOW_STATE::RenderHeight(), KIGFX::WINDOW_STATE::RenderWidth(), RGBA8, KIGFX::WINDOW_STATE::staticFBO, KIGFX::WINDOW_STATE::staticMargin, staticMarginFor(), KIGFX::WINDOW_STATE::staticShift, KIGFX::WINDOW_STATE::supersampleFactor, KIGFX::WINDOW_STATE::tempFBO, KIGFX::WINDOW_STATE::RENDERED_CONTENT::valid, and RHI_FRAMEBUFFER_DESC::width.
Referenced by HandleSwapchainCreate(), HandleSwapchainResize(), and ProcessActiveWindows().
|
inlineprivate |
Definition at line 307 of file render_thread.h.
References m_deferredFrameDue.
Referenced by ProcessActiveWindows().
|
private |
Definition at line 2405 of file render_thread.cpp.
References destroyWindow(), m_device, and m_windows.
Referenced by ThreadMain().
|
private |
Definition at line 940 of file render_thread.cpp.
References m_device, m_glyphBG, m_glyphBGHasAtlas, m_glyphTable, and m_glyphTexture.
Referenced by DestroyRenderInfrastructure(), and glyphBindGroup().
|
private |
Definition at line 918 of file render_thread.cpp.
References destroyGlyphResources(), m_compositor, m_device, m_geometryDepthDiscardRenderPass, m_geometryDepthLoadDiscardRenderPass, m_geometryDepthLoadRenderPass, m_geometryLoadRenderPass, m_geometryRenderPass, m_pipelines, m_quadCornerBuffer, m_quadIndexBuffer, and m_unitQuadBuffer.
Referenced by ThreadMain().
|
private |
Free a window's targets, uniforms, swapchain and surface.
Definition at line 2418 of file render_thread.cpp.
References DestroyWindowFBOs(), DestroyWindowUniforms(), m_device, KIGFX::WINDOW_STATE::surface, and KIGFX::WINDOW_STATE::swapchain.
Referenced by DestroyAllWindows(), and HandleSwapchainDestroy().
|
private |
Definition at line 2459 of file render_thread.cpp.
References KIGFX::WINDOW_STATE::accumulationFBO, destroyDiffCopies(), KIGFX::WINDOW_STATE::dynamicFBO, m_compositor, m_device, KIGFX::WINDOW_STATE::overlayGeometryDrawn, KIGFX::WINDOW_STATE::overlayGeometryFBO, KIGFX::WINDOW_STATE::overlayInMargin, KIGFX::WINDOW_STATE::overlayMarginFBO, KIGFX::WINDOW_STATE::staticFBO, KIGFX::WINDOW_STATE::staticInMargin, KIGFX::WINDOW_STATE::staticTempFBO, KIGFX::WINDOW_STATE::staticViewFBO, and KIGFX::WINDOW_STATE::tempFBO.
Referenced by destroyWindow(), HandleSwapchainResize(), and ProcessActiveWindows().
|
private |
Definition at line 2480 of file render_thread.cpp.
References KIGFX::WINDOW_STATE::FRAME_UNIFORMS::cursorBG, KIGFX::WINDOW_STATE::FRAME_UNIFORMS::cursorUBO, KIGFX::WINDOW_STATE::FRAME_UNIFORMS::dynamicUniforms, m_device, KIGFX::WINDOW_STATE::FRAME_UNIFORMS::overlayUniforms, KIGFX::WINDOW_STATE::FRAME_UNIFORMS::staticUniforms, and KIGFX::WINDOW_STATE::uniformSets.
Referenced by destroyWindow().
|
private |
Definition at line 719 of file render_thread.cpp.
References HandleFence(), HandleFrameRequest(), HandleSwapchainCreate(), HandleSwapchainDestroy(), HandleSwapchainResize(), IsDeviceLost(), m_controlQueue, m_shutdownRequested, and T.
Referenced by ThreadMain().
|
private |
Definition at line 760 of file render_thread.cpp.
References IsDeviceLost(), m_device, m_uploadQueue, m_uploadsPending, and T.
Referenced by HandleFence(), ProcessActiveWindows(), and ThreadMain().
|
private |
Draw the cursor into the open composite pass.
Definition at line 2244 of file render_thread.cpp.
References KIGFX::WINDOW_STATE::FRAME_UNIFORMS::cursorBG, m_device, m_pipelines, m_unitQuadBuffer, and KIGFX::WINDOW_STATE::Uniforms().
|
private |
Definition at line 234 of file render_thread.cpp.
References KIGFX::WINDOW_STATE::backingHeight, KIGFX::WINDOW_STATE::backingWidth, KIGFX::WINDOW_STATE::dpiScale, RHI_SWAPCHAIN_DESC::dpiScale, RHI_SWAPCHAIN_DESC::height, KIGFX::WINDOW_STATE::lastSwapchainCreateAttemptTime, m_device, KIGFX::WINDOW_STATE::nativeHandle, RHI_NATIVE_WINDOW_HANDLE::nativeHandle, KIGFX::WINDOW_STATE::needsStaticInvalidate, ShouldRetrySwapchainCreate(), KIGFX::WINDOW_STATE::surface, RHI_SWAPCHAIN_DESC::surface, KIGFX::WINDOW_STATE::swapchain, KIGFX::WINDOW_STATE::swapchainCreateAttempts, traceRhi, RHI_SWAPCHAIN_DESC::width, RHI_SURFACE_DESC::window, and KIGFX::WINDOW_STATE::windowId.
Referenced by HandleSwapchainCreate(), HandleSwapchainResize(), ProcessActiveWindows(), recreateSwapchainAfterOutOfDate(), and RenderWindow().
|
inline |
Definition at line 116 of file render_thread.h.
References m_backendType.
|
inline |
Definition at line 140 of file render_thread.h.
References m_loopPhase.
|
inline |
Definition at line 121 of file render_thread.h.
References m_maxTextureSize.
|
private |
Definition at line 965 of file render_thread.cpp.
References BILINEAR, destroyGlyphResources(), RHI_BIND_GROUP_DESC::entries, RHI_TEXTURE_DESC::filter, RHI_TEXTURE_DESC::format, RHI_TEXTURE_DESC::height, RHI_BIND_GROUP_DESC::layout, m_device, m_glyphAtlas, m_glyphAtlasMutex, m_glyphBG, m_glyphBGHasAtlas, m_glyphTable, m_glyphTexture, m_pipelines, RHI_BUFFER_DESC::mappable, RGBA8, RHI_GLYPH_TABLE_BINDING, RHI_GLYPH_TABLE_SIZE, RHI_BUFFER_DESC::sizeBytes, table, RHI_BUFFER_DESC::type, UNIFORM, and RHI_TEXTURE_DESC::width.
Referenced by RenderGeometryInto().
|
private |
Definition at line 2385 of file render_thread.cpp.
References DrainUploadQueue(), RHI_CMD_FENCE::flushFrames, m_windows, RHI_CMD_FENCE::onComplete, and ProcessActiveWindows().
Referenced by DrainControlQueue().
|
private |
Definition at line 1020 of file render_thread.cpp.
References KIGFX::WINDOW_STATE::active, KIGFX::WINDOW_STATE::frameResultPending, RHI_CMD_FRAME_REQUEST::generation, KIGFX::WINDOW_STATE::lastActivityTime, KIGFX::WINDOW_STATE::lastFrameRequestTime, m_windows, KIGFX::WINDOW_STATE::nextPresentRetryAt, KIGFX::WINDOW_STATE::refreshHz, RHI_CMD_FRAME_REQUEST::refreshHz, KIGFX::WINDOW_STATE::requestedGeneration, traceRhi, and RHI_CMD_FRAME_REQUEST::windowId.
Referenced by DrainControlQueue().
|
private |
Definition at line 2253 of file render_thread.cpp.
References KIGFX::WINDOW_STATE::backingHeight, KIGFX::WINDOW_STATE::backingWidth, ComputeBackingResolution(), CreateWindowFBOs(), KIGFX::WINDOW_STATE::dpiScale, RHI_CMD_SWAPCHAIN_CREATE::dpiScale, EnsureSwapchain(), RHI_CMD_SWAPCHAIN_CREATE::frame2DMailbox, KIGFX::WINDOW_STATE::height, RHI_CMD_SWAPCHAIN_CREATE::height, m_device, m_windows, KIGFX::WINDOW_STATE::mailbox, KIGFX::WINDOW_STATE::nativeHandle, RHI_CMD_SWAPCHAIN_CREATE::nativeHandle, RHI_NATIVE_WINDOW_HANDLE::nativeHandle, KIGFX::WINDOW_STATE::surface, traceRhi, KIGFX::WINDOW_STATE::width, RHI_CMD_SWAPCHAIN_CREATE::width, RHI_SURFACE_DESC::window, KIGFX::WINDOW_STATE::windowId, and RHI_CMD_SWAPCHAIN_CREATE::windowId.
Referenced by DrainControlQueue().
|
private |
Definition at line 2368 of file render_thread.cpp.
References destroyWindow(), m_windows, traceRhi, and RHI_CMD_SWAPCHAIN_DESTROY::windowId.
Referenced by DrainControlQueue().
|
private |
Definition at line 2304 of file render_thread.cpp.
References KIGFX::WINDOW_STATE::backingHeight, KIGFX::WINDOW_STATE::backingWidth, ComputeBackingResolution(), CreateWindowFBOs(), DestroyWindowFBOs(), KIGFX::WINDOW_STATE::dpiScale, RHI_CMD_SWAPCHAIN_RESIZE::dpiScale, EnsureSwapchain(), KIGFX::WINDOW_STATE::height, RHI_CMD_SWAPCHAIN_RESIZE::height, m_device, m_windows, KIGFX::WINDOW_STATE::needsStaticInvalidate, KIGFX::WINDOW_STATE::nextPresentRetryAt, recreateSwapchainAfterOutOfDate(), KIGFX::WINDOW_STATE::surface, KIGFX::WINDOW_STATE::swapchain, traceRhi, KIGFX::WINDOW_STATE::width, RHI_CMD_SWAPCHAIN_RESIZE::width, and RHI_CMD_SWAPCHAIN_RESIZE::windowId.
Referenced by DrainControlQueue().
| bool KIGFX::RENDER_THREAD::HasPresented | ( | RHI_WINDOW_ID | aWindowId | ) | const |
Definition at line 2529 of file render_thread.cpp.
References m_presentedMutex, and m_presentedWindows.
|
private |
Definition at line 823 of file render_thread.cpp.
References CLEAR, RHI_COLOR_ATTACHMENT_DESC::clearColor, RHI_RENDER_PASS_DESC::colorAttachments, RHI_DEPTH_STENCIL_ATTACHMENT_DESC::depthLoadOp, RHI_RENDER_PASS_DESC::depthStencilAttachment, RHI_DEPTH_STENCIL_ATTACHMENT_DESC::depthStoreOp, DONT_CARE, RHI_DEPTH_STENCIL_ATTACHMENT_DESC::enabled, INDEX, LOAD, m_compositor, m_device, m_geometryDepthDiscardRenderPass, m_geometryDepthLoadDiscardRenderPass, m_geometryDepthLoadRenderPass, m_geometryLoadRenderPass, m_geometryRenderPass, m_pipelines, m_quadCornerBuffer, m_quadIndexBuffer, m_unitQuadBuffer, RHI_VERTEX::SetColor(), RHI_VERTEX::SetPosition(), RHI_VERTEX::SetUV(), RHI_BUFFER_DESC::sizeBytes, RHI_DEPTH_STENCIL_ATTACHMENT_DESC::stencilLoadOp, STORE, RHI_BUFFER_DESC::type, and VERTEX.
Referenced by ThreadMain().
|
inline |
Definition at line 145 of file render_thread.h.
References m_deviceLost.
Referenced by DrainControlQueue(), DrainUploadQueue(), ProcessActiveWindows(), ReadbackWindowPixels(), RenderWindow(), and ThreadMain().
| bool KIGFX::RENDER_THREAD::IsRunning | ( | ) | const |
Definition at line 345 of file render_thread.cpp.
References m_running.
| void KIGFX::RENDER_THREAD::OnDeviceLost | ( | ) |
Stop drawing on a lost device.
The GAL's buffers and textures died with it and only a new canvas remakes them, so the owner learns of the loss through IsDeviceLost(). Render thread only.
Definition at line 2514 of file render_thread.cpp.
References m_deviceLost, m_deviceLostListeners, m_deviceLostMutex, m_uploadQueue, and traceRhi.
Referenced by RenderWindow().
|
delete |
References RENDER_THREAD().
|
private |
Fill the cursor's uniforms.
Definition at line 2199 of file render_thread.cpp.
References KIGFX::WINDOW_STATE::FRAME_UNIFORMS::cursorBG, KIGFX::FRAME_DRAW_DESC::cursorUBO, KIGFX::WINDOW_STATE::FRAME_UNIFORMS::cursorUBO, KIGFX::FRAME_DRAW_DESC::drawCursor, KIGFX::WINDOW_STATE::drawDesc, m_pipelines, m_unitQuadBuffer, KIGFX::WINDOW_STATE::Uniforms(), and writeUniform().
Referenced by RenderWindow().
|
private |
| aIgnorePacing | draw every pending frame now, even one a window's refresh rate would defer. |
Definition at line 1043 of file render_thread.cpp.
References CreateWindowFBOs(), deferFrameUntil(), DestroyWindowFBOs(), DrainUploadQueue(), EnsureSwapchain(), FAILED, fitSupersampleFactor(), IDLE, IsDeviceLost(), KIGFX::FRAME_MAILBOX::Load(), m_activeWindowOrder, m_deferredFrameDue, m_device, m_loopPhase, m_windows, KIGFX::FRAME_MAILBOX::PendingInputSerial(), recreateSwapchainAfterOutOfDate(), RenderWindow(), RESIZED, RHI_PRESENTS_IN_FLIGHT, RhiNextFrameAt(), traceRhi, WAITING, and WindowStateAgeMs().
Referenced by HandleFence(), and ThreadMain().
| bool KIGFX::RENDER_THREAD::ReadbackWindowPixels | ( | RHI_WINDOW_ID | aWindowId, |
| wxImage & | aImage ) |
Read back a window's picture at backing resolution without the overlay and cursor.
Blocks the calling thread until the render thread has read it.
Definition at line 439 of file render_thread.cpp.
References KIGFX::FRAME_DRAW_DESC::backgroundColor, KIGFX::WINDOW_STATE::backingHeight, KIGFX::WINDOW_STATE::backingWidth, RHI_FRAMEBUFFER_DESC::colorFormats, KIGFX::WINDOW_STATE::drawDesc, KIGFX::WINDOW_STATE::dynamicFBO, KIGFX::WINDOW_STATE::dynamicGeometryDrawn, RHI_FRAMEBUFFER_DESC::height, IsDeviceLost(), m_compositor, m_device, m_windows, marginLayer(), KIGFX::WINDOW_STATE::RenderHeight(), KIGFX::WINDOW_STATE::RenderWidth(), RGBA8, runFenced(), KIGFX::WINDOW_STATE::ShownStaticFBO(), KIGFX::WINDOW_STATE::staticFBO, KIGFX::WINDOW_STATE::staticInMargin, KIGFX::WINDOW_STATE::staticShift, and RHI_FRAMEBUFFER_DESC::width.
|
private |
Retire and recreate an out of date swapchain, and its surface too when aSurfaceLost.
A failed recreation leaves the handle null so the retry backoff applies.
Definition at line 220 of file render_thread.cpp.
References EnsureSwapchain(), m_device, KIGFX::WINDOW_STATE::surface, and KIGFX::WINDOW_STATE::swapchain.
Referenced by HandleSwapchainResize(), ProcessActiveWindows(), and RenderWindow().
| void KIGFX::RENDER_THREAD::RemoveDeviceLostListener | ( | const void * | aOwner | ) |
Once this returns, the owner's listener is not running and will not be called.
Definition at line 2543 of file render_thread.cpp.
References m_deviceLostListeners, and m_deviceLostMutex.
|
private |
Definition at line 1638 of file render_thread.cpp.
References KIGFX::WINDOW_STATE::drawDesc, RenderGeometryInto(), KIGFX::WINDOW_STATE::staticFBO, and KIGFX::WINDOW_STATE::staticInMargin.
Referenced by RenderWindow().
|
private |
| aStaticDrawMargin | how much of the static target's margin to draw when aFBO is the static target. 0 draws only the view in its middle. |
Definition at line 1646 of file render_thread.cpp.
References ALL, COMPOSITOR_PUSH_CONSTANTS::alpha, KIGFX::LAYER_RANGE::alpha, KIGFX::LAYER_RANGE::bitmapCount, KIGFX::FRAME_DRAW_DESC::bitmapDraws, KIGFX::LAYER_RANGE::bitmapStart, KIGFX::BLEND, KIGFX::FRAME_DRAW_DESC::buffer, KIGFX::LAYER_RANGE::buffer, copied, KIGFX::FRAME_DRAW_DESC::count, KIGFX::LAYER_RANGE::cullRuns, KIGFX::LAYER_RANGE::depthFar, KIGFX::LAYER_RANGE::depthKnockout, KIGFX::LAYER_RANGE::depthNear, KIGFX::WINDOW_STATE::diffBelowFBO, KIGFX::LAYER_RANGE::difference, KIGFX::LAYER_RANGE::dim, drawBitmap(), KIGFX::FRAME_DRAW_DESC::drawCursor, KIGFX::FRAME_DRAW_DESC::drawGrid, KIGFX::WINDOW_STATE::dynamicFBO, KIGFX::WINDOW_STATE::FRAME_UNIFORMS::dynamicUniforms, RHI_BIND_GROUP_DESC::entries, KIGFX::WINDOW_STATE::PASS_UNIFORMS::frameBG, RHI_RENDER_PASS_BEGIN_DESC::framebuffer, KIGFX::WINDOW_STATE::framesProcessed, KIGFX::FRAME_DRAW_DESC::frameUBO, KIGFX::WINDOW_STATE::PASS_UNIFORMS::frameUBO, KIGFX::WINDOW_STATE::geometryRenderPasses, glyphBindGroup(), KIGFX::WINDOW_STATE::PASS_UNIFORMS::gridBG, KIGFX::FRAME_DRAW_DESC::gridFirst, KIGFX::FRAME_DRAW_DESC::gridUBO, KIGFX::WINDOW_STATE::PASS_UNIFORMS::gridUBO, KIGFX::LAYER_RANGE::HasGeometry(), RHI_FRAMEBUFFER_DESC::height, RHI_SCISSOR_RECT::height, RHI_VIEWPORT::height, layerFramebufferDesc(), KIGFX::FRAME_DRAW_DESC::layerRanges, RHI_BIND_GROUP_DESC::layout, KIGFX::FRAME_DRAW_DESC::linePipelineKind, m_compositor, m_device, m_geometryDepthDiscardRenderPass, m_geometryDepthLoadDiscardRenderPass, m_geometryDepthLoadRenderPass, m_geometryLoadRenderPass, m_geometryRenderPass, m_pipelines, m_quadCornerBuffer, m_quadIndexBuffer, m_unitQuadBuffer, KIGFX::MARK, RHI_VIEWPORT::maxDepth, RHI_VIEWPORT::minDepth, KIGFX::LAYER_RANGE::NeedsTempFBO(), KIGFX::NEGATIVE, KIGFX::LAYER_RANGE::negBuffer, KIGFX::FRAME_DRAW_DESC::negCount, KIGFX::ONCE, OVERLAY, KIGFX::LAYER_RANGE::overlayAlpha, KIGFX::WINDOW_STATE::overlayMarginFBO, KIGFX::WINDOW_STATE::FRAME_UNIFORMS::overlayUniforms, KIGFX::FRAME_DRAW_DESC::polarityRuns, KIGFX::WINDOW_STATE::RenderHeight(), RHI_RENDER_PASS_BEGIN_DESC::renderPass, KIGFX::WINDOW_STATE::RenderWidth(), KIGFX::RHI_INSTANCED_SHAPES, KIGFX::RHI_SHAPE_ARC, KIGFX::RHI_SHAPE_PAD, KIGFX::RHI_SHAPE_POLYGON, KIGFX::RHI_SHAPE_TRACK, KIGFX::RhiCullRunLength(), KIGFX::RhiCullView(), KIGFX::RhiForVisibleStretches(), KIGFX::RhiPlanLayerDraws(), KIGFX::RhiSupersampleFrame(), KIGFX::RhiSupersampleGrid(), KIGFX::RhiWidenFrame(), KIGFX::RhiWidenGrid(), KIGFX::SCH_WIRES, KIGFX::WINDOW_STATE::ShownStaticFBO(), KIGFX::WINDOW_STATE::ShownStaticX(), KIGFX::WINDOW_STATE::ShownStaticY(), KIGFX::WINDOW_STATE::staticDiffBelowFBO, KIGFX::WINDOW_STATE::staticFBO, KIGFX::WINDOW_STATE::StaticHeight(), KIGFX::WINDOW_STATE::staticMargin, KIGFX::WINDOW_STATE::staticTempFBO, KIGFX::WINDOW_STATE::FRAME_UNIFORMS::staticUniforms, KIGFX::WINDOW_STATE::staticViewFBO, KIGFX::WINDOW_STATE::StaticWidth(), KIGFX::WINDOW_STATE::supersampleFactor, KIGFX::TARGET_OVERLAY, KIGFX::WINDOW_STATE::tempFBO, KIGFX::FRAME_DRAW_DESC::testAgainstStatic, traceRhi, KIGFX::WINDOW_STATE::Uniforms(), RHI_FRAMEBUFFER_DESC::width, RHI_SCISSOR_RECT::width, RHI_VIEWPORT::width, KIGFX::WINDOW_STATE::windowId, writeUniform(), RHI_SCISSOR_RECT::x, RHI_VIEWPORT::x, RHI_SCISSOR_RECT::y, and RHI_VIEWPORT::y.
Referenced by RenderGeometry(), and RenderWindow().
|
private |
Definition at line 1279 of file render_thread.cpp.
References KIGFX::WINDOW_STATE::accumulationFBO, ALL, KIGFX::FRAME_DRAW_DESC::backgroundColor, KIGFX::WINDOW_STATE::backingHeight, KIGFX::WINDOW_STATE::backingWidth, KIGFX::FRAME_DRAW_DESC::bitmapDraws, KIGFX::FRAME_DRAW_DESC::count, cursor, destroyDiffCopies(), DEVICE_LOST, KIGFX::WINDOW_STATE::diffBelowFBO, KIGFX::WINDOW_STATE::drawDesc, KIGFX::FRAME_DRAW_DESC::drawGrid, KIGFX::WINDOW_STATE::RENDERED_CONTENT::drawGrid, MARGIN_PLAN::drawMargin, KIGFX::WINDOW_STATE::dynamicChanged, KIGFX::WINDOW_STATE::dynamicDrawDesc, KIGFX::WINDOW_STATE::dynamicEpoch, KIGFX::WINDOW_STATE::dynamicFBO, KIGFX::WINDOW_STATE::dynamicGeometryDrawn, KIGFX::WINDOW_STATE::dynamicPasses, EnsureSwapchain(), KIGFX::WINDOW_STATE::RENDERED_CONTENT::epoch, KIGFX::FRAME_DRAW_DESC::frameUBO, KIGFX::WINDOW_STATE::RENDERED_CONTENT::frameUBO, KIGFX::WINDOW_STATE::geometryRenderPasses, KIGFX::WINDOW_STATE::RENDERED_CONTENT::gridUBO, KIGFX::FRAME_DRAW_DESC::HasGeometry(), RHI_SCISSOR_RECT::height, IsDeviceLost(), KIGFX::WINDOW_STATE::lastFrameRequestTime, KIGFX::WINDOW_STATE::lastPresentAttemptTime, KIGFX::WINDOW_STATE::lastPresentedGeneration, KIGFX::WINDOW_STATE::lastPresentFailureTime, KIGFX::WINDOW_STATE::lastPresentSuccessTime, KIGFX::WINDOW_STATE::lastRenderCompleteTime, KIGFX::WINDOW_STATE::lastRenderStartTime, layerFramebufferDesc(), KIGFX::FRAME_DRAW_DESC::layerRanges, m_compositor, m_device, m_geometryRenderPass, m_loopPhase, m_pipelines, m_presentedMutex, m_presentedWindows, KIGFX::WINDOW_STATE::RENDERED_CONTENT::margin, marginFramebufferDesc(), marginLayer(), PROF_TIMER::msecs(), KIGFX::WINDOW_STATE::needsStaticInvalidate, KIGFX::FRAME_DRAW_DESC::negCount, NOT_OVERLAY, OK, OnDeviceLost(), OUT_OF_DATE, OVERLAY, KIGFX::WINDOW_STATE::overlayGeometryDrawn, KIGFX::WINDOW_STATE::overlayGeometryFBO, KIGFX::WINDOW_STATE::overlayInMargin, KIGFX::WINDOW_STATE::overlayMarginFBO, KIGFX::WINDOW_STATE::overlayShift, plan(), planMarginTarget(), prepareCursor(), KIGFX::WINDOW_STATE::presentFailureCount, KIGFX::WINDOW_STATE::presentSuccessCount, recreateSwapchainAfterOutOfDate(), KIGFX::WINDOW_STATE::renderedDynamic, KIGFX::WINDOW_STATE::renderedOverlay, KIGFX::WINDOW_STATE::renderedStatic, RenderGeometry(), RenderGeometryInto(), KIGFX::WINDOW_STATE::RenderHeight(), KIGFX::WINDOW_STATE::RenderWidth(), KIGFX::WINDOW_STATE::requestedGeneration, MARGIN_PLAN::reuse, KIGFX::FRAME_DRAW_DESC::reuseDynamicFBO, KIGFX::FRAME_DRAW_DESC::reuseStaticFBO, KIGFX::RHI_SHAPE_ARC, KIGFX::RHI_SHAPE_PAD, KIGFX::RHI_SHAPE_POLYGON, KIGFX::RHI_SHAPE_TRACK, KIGFX::RhiCullView(), KIGFX::RhiWidenFrame(), MARGIN_PLAN::shift, KIGFX::WINDOW_STATE::ShownStaticFBO(), KIGFX::WINDOW_STATE::ShownStaticX(), KIGFX::WINDOW_STATE::ShownStaticY(), KIGFX::WINDOW_STATE::staticChanged, KIGFX::WINDOW_STATE::staticDiffBelowFBO, KIGFX::WINDOW_STATE::staticDrawDesc, KIGFX::WINDOW_STATE::staticEpoch, KIGFX::WINDOW_STATE::staticFBO, KIGFX::WINDOW_STATE::staticInMargin, KIGFX::WINDOW_STATE::staticMargin, KIGFX::WINDOW_STATE::staticPasses, KIGFX::WINDOW_STATE::staticShift, KIGFX::WINDOW_STATE::staticViewFBO, SURFACE_LOST, KIGFX::WINDOW_STATE::swapchain, traceRhi, KIGFX::WINDOW_STATE::UNIFORM_GENERATIONS, KIGFX::WINDOW_STATE::uniformGeneration, KIGFX::WINDOW_STATE::RENDERED_CONTENT::valid, RHI_SCISSOR_RECT::width, KIGFX::WINDOW_STATE::windowId, WindowStateAgeMs(), WindowStateDurationMs(), RHI_SCISSOR_RECT::x, and RHI_SCISSOR_RECT::y.
Referenced by ProcessActiveWindows().
| RHI_BufferHandle KIGFX::RENDER_THREAD::ReserveBufferHandle | ( | ) |
Reserve a handle without creating the GPU resource, so RHI_DEVICE_PROXY can hand it out on the UI thread and create the resource on the render thread.
Null when there is no device.
Definition at line 396 of file render_thread.cpp.
References m_device, and m_deviceMutex.
| RHI_TextureHandle KIGFX::RENDER_THREAD::ReserveTextureHandle | ( | ) |
Definition at line 403 of file render_thread.cpp.
References m_device, and m_deviceMutex.
|
private |
Run work on the render thread after everything queued before it.
Definition at line 416 of file render_thread.cpp.
References RHI_CMD_FENCE::flushFrames, RHI_CMD_FENCE::onComplete, and SubmitControl().
Referenced by ReadbackWindowPixels(), and WaitForFence().
| void KIGFX::RENDER_THREAD::SetGlyphAtlas | ( | std::shared_ptr< const RHI_GLYPH_ATLAS_DATA > | aAtlas | ) |
Give the track shaders the font atlas glyph instances draw from.
Only the first atlas is kept. Callable from any thread.
Definition at line 956 of file render_thread.cpp.
References m_glyphAtlas, and m_glyphAtlasMutex.
| void KIGFX::RENDER_THREAD::Shutdown | ( | ) |
Block until the render thread exits.
Safe to call repeatedly or if the thread never started.
Definition at line 530 of file render_thread.cpp.
References m_running, m_shutdownRequested, m_thread, traceRhi, and wakeRenderThread().
Referenced by ~RENDER_THREAD().
| bool KIGFX::RENDER_THREAD::Start | ( | ) |
Block until the render thread has created the device and its pipelines.
Definition at line 321 of file render_thread.cpp.
References m_running, m_shutdownRequested, m_thread, and ThreadMain().
| bool KIGFX::RENDER_THREAD::SubmitControl | ( | RHI_CONTROL_COMMAND | aCmd | ) |
Definition at line 363 of file render_thread.cpp.
References m_acceptingWork, m_controlQueue, m_workCV, and m_workMutex.
Referenced by runFenced().
| void KIGFX::RENDER_THREAD::SubmitUpload | ( | RHI_UPLOAD_COMMAND | aCmd | ) |
Callable from any thread.
Definition at line 380 of file render_thread.cpp.
References m_acceptingWork, m_uploadQueue, m_uploadsPending, m_workCV, and m_workMutex.
|
private |
Definition at line 555 of file render_thread.cpp.
References DestroyAllWindows(), DestroyRenderInfrastructure(), DrainControlQueue(), DrainUploadQueue(), ADVANCED_CFG::GetCfg(), InitRenderInfrastructure(), IsDeviceLost(), m_acceptingWork, m_backendType, m_controlQueue, m_deferredFrameDue, m_device, m_deviceFactory, m_deviceMutex, m_loopPhase, m_maxTextureSize, m_running, m_shutdownRequested, m_uploadQueue, m_uploadsPending, m_windows, m_workCV, m_workMutex, ProcessActiveWindows(), and traceRhi.
Referenced by Start().
| bool KIGFX::RENDER_THREAD::WaitForFence | ( | std::chrono::milliseconds | aTimeout = std::chrono::milliseconds( 2000 ) | ) |
Block until every command submitted before this call has been processed.
Definition at line 410 of file render_thread.cpp.
References runFenced().
|
private |
Definition at line 351 of file render_thread.cpp.
References m_workCV, and m_workMutex.
Referenced by Shutdown().
|
private |
Write a uniform block, making its buffer and bind group on first use.
Definition at line 2214 of file render_thread.cpp.
References RHI_BIND_GROUP_DESC::entries, RHI_BIND_GROUP_DESC::layout, m_device, RHI_BUFFER_DESC::mappable, RHI_UBO_BINDING, RHI_BUFFER_DESC::sizeBytes, RHI_BUFFER_DESC::type, and UNIFORM.
Referenced by prepareCursor(), and RenderGeometryInto().
|
private |
Guarded by m_workMutex.
Cleared before the shutdown drain so nothing queued later is lost.
Definition at line 284 of file render_thread.h.
Referenced by SubmitControl(), SubmitUpload(), and ThreadMain().
|
private |
Definition at line 302 of file render_thread.h.
Referenced by ProcessActiveWindows().
|
private |
Definition at line 269 of file render_thread.h.
Referenced by GetBackendType(), and ThreadMain().
|
private |
Definition at line 314 of file render_thread.h.
Referenced by DestroyRenderInfrastructure(), DestroyWindowFBOs(), InitRenderInfrastructure(), ReadbackWindowPixels(), RenderGeometryInto(), and RenderWindow().
|
private |
Definition at line 272 of file render_thread.h.
Referenced by DrainControlQueue(), SubmitControl(), and ThreadMain().
|
private |
Earliest time a window held to its display's refresh rate is due, so the loop wakes for it.
Definition at line 305 of file render_thread.h.
Referenced by deferFrameUntil(), ProcessActiveWindows(), and ThreadMain().
|
private |
Definition at line 261 of file render_thread.h.
Referenced by CreateWindowFBOs(), DestroyAllWindows(), destroyGlyphResources(), DestroyRenderInfrastructure(), destroyWindow(), DestroyWindowFBOs(), DestroyWindowUniforms(), DrainUploadQueue(), drawCursor(), EnsureSwapchain(), glyphBindGroup(), HandleSwapchainCreate(), HandleSwapchainResize(), InitRenderInfrastructure(), ProcessActiveWindows(), ReadbackWindowPixels(), recreateSwapchainAfterOutOfDate(), RenderGeometryInto(), RenderWindow(), ReserveBufferHandle(), ReserveTextureHandle(), ThreadMain(), and writeUniform().
|
private |
Definition at line 259 of file render_thread.h.
Referenced by RENDER_THREAD(), and ThreadMain().
|
private |
Definition at line 288 of file render_thread.h.
Referenced by IsDeviceLost(), and OnDeviceLost().
|
private |
Definition at line 292 of file render_thread.h.
Referenced by AddDeviceLostListener(), OnDeviceLost(), and RemoveDeviceLostListener().
|
private |
Held while a listener runs, so removing one waits for it to return.
Definition at line 291 of file render_thread.h.
Referenced by AddDeviceLostListener(), OnDeviceLost(), and RemoveDeviceLostListener().
|
mutableprivate |
Guards the m_device pointer, not the device, against UI thread reads racing its creation or destruction.
The device's pools are thread-safe and its maps are render thread only.
Definition at line 267 of file render_thread.h.
Referenced by ReserveBufferHandle(), ReserveTextureHandle(), and ThreadMain().
|
private |
As m_geometryRenderPass and m_geometryDepthLoadRenderPass, without storing depth nothing reads later.
Definition at line 336 of file render_thread.h.
Referenced by DestroyRenderInfrastructure(), InitRenderInfrastructure(), and RenderGeometryInto().
|
private |
Definition at line 337 of file render_thread.h.
Referenced by DestroyRenderInfrastructure(), InitRenderInfrastructure(), and RenderGeometryInto().
|
private |
clears colour, keeps depth
Definition at line 333 of file render_thread.h.
Referenced by DestroyRenderInfrastructure(), InitRenderInfrastructure(), and RenderGeometryInto().
|
private |
Definition at line 332 of file render_thread.h.
Referenced by DestroyRenderInfrastructure(), InitRenderInfrastructure(), and RenderGeometryInto().
|
private |
Definition at line 331 of file render_thread.h.
Referenced by DestroyRenderInfrastructure(), InitRenderInfrastructure(), RenderGeometryInto(), and RenderWindow().
|
private |
Definition at line 326 of file render_thread.h.
Referenced by glyphBindGroup(), and SetGlyphAtlas().
|
mutableprivate |
Definition at line 325 of file render_thread.h.
Referenced by glyphBindGroup(), and SetGlyphAtlas().
|
private |
Definition at line 322 of file render_thread.h.
Referenced by destroyGlyphResources(), and glyphBindGroup().
|
private |
Definition at line 323 of file render_thread.h.
Referenced by destroyGlyphResources(), and glyphBindGroup().
|
private |
Definition at line 321 of file render_thread.h.
Referenced by destroyGlyphResources(), and glyphBindGroup().
|
private |
The font atlas the track shaders draw glyphs from, its glyph table and their bind group.
Definition at line 320 of file render_thread.h.
Referenced by destroyGlyphResources(), and glyphBindGroup().
|
private |
see GetLoopPhase()
Definition at line 298 of file render_thread.h.
Referenced by GetLoopPhase(), ProcessActiveWindows(), RenderWindow(), and ThreadMain().
|
private |
Definition at line 270 of file render_thread.h.
Referenced by GetMaxTextureSize(), and ThreadMain().
|
private |
Shared by all windows and created once with the device.
Definition at line 313 of file render_thread.h.
Referenced by DestroyRenderInfrastructure(), drawCursor(), glyphBindGroup(), InitRenderInfrastructure(), prepareCursor(), RenderGeometryInto(), and RenderWindow().
|
mutableprivate |
Window IDs are never reused, so an entry outliving its window is harmless.
Definition at line 295 of file render_thread.h.
Referenced by HasPresented(), and RenderWindow().
|
private |
Definition at line 296 of file render_thread.h.
Referenced by HasPresented(), and RenderWindow().
|
private |
the unit quad's 4 corners
Definition at line 316 of file render_thread.h.
Referenced by DestroyRenderInfrastructure(), InitRenderInfrastructure(), and RenderGeometryInto().
|
private |
its 2 triangles over those corners
Definition at line 317 of file render_thread.h.
Referenced by DestroyRenderInfrastructure(), InitRenderInfrastructure(), and RenderGeometryInto().
|
private |
Definition at line 280 of file render_thread.h.
Referenced by IsRunning(), Shutdown(), Start(), and ThreadMain().
|
private |
Definition at line 281 of file render_thread.h.
Referenced by DrainControlQueue(), Shutdown(), Start(), and ThreadMain().
|
private |
Definition at line 275 of file render_thread.h.
Referenced by Shutdown(), and Start().
|
private |
Definition at line 315 of file render_thread.h.
Referenced by DestroyRenderInfrastructure(), drawCursor(), InitRenderInfrastructure(), prepareCursor(), and RenderGeometryInto().
|
private |
Definition at line 273 of file render_thread.h.
Referenced by DrainUploadQueue(), OnDeviceLost(), SubmitUpload(), and ThreadMain().
|
private |
Set by producers and cleared by the drain so the loop can sleep without missing uploads.
Definition at line 287 of file render_thread.h.
Referenced by DrainUploadQueue(), SubmitUpload(), and ThreadMain().
|
private |
Definition at line 300 of file render_thread.h.
Referenced by DestroyAllWindows(), HandleFence(), HandleFrameRequest(), HandleSwapchainCreate(), HandleSwapchainDestroy(), HandleSwapchainResize(), ProcessActiveWindows(), ReadbackWindowPixels(), and ThreadMain().
|
private |
Definition at line 278 of file render_thread.h.
Referenced by SubmitControl(), SubmitUpload(), ThreadMain(), and wakeRenderThread().
|
private |
Definition at line 277 of file render_thread.h.
Referenced by SubmitControl(), SubmitUpload(), ThreadMain(), and wakeRenderThread().