Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QRhiSwapChain Class Referenceabstract

\inmodule QtGui More...

#include <qrhi.h>

+ Inheritance diagram for QRhiSwapChain:
+ Collaboration diagram for QRhiSwapChain:

Public Types

enum  Flag {
  SurfaceHasPreMulAlpha = 1 << 0 , SurfaceHasNonPreMulAlpha = 1 << 1 , sRGB = 1 << 2 , UsedAsTransferSource = 1 << 3 ,
  NoVSync = 1 << 4 , MinimalBufferCount = 1 << 5
}
 Flag values to describe swapchain properties. More...
 
enum  Format { SDR , HDRExtendedSrgbLinear , HDR10 , HDRExtendedDisplayP3Linear }
 Describes the swapchain format. More...
 
enum  StereoTargetBuffer { LeftBuffer , RightBuffer }
 Selects the backbuffer to use with a stereoscopic swapchain. More...
 
- Public Types inherited from QRhiResource
enum  Type {
  Buffer , Texture , Sampler , RenderBuffer ,
  RenderPassDescriptor , SwapChainRenderTarget , TextureRenderTarget , ShaderResourceBindings ,
  GraphicsPipeline , SwapChain , ComputePipeline , CommandBuffer
}
 Specifies type of the resource. More...
 

Public Member Functions

QRhiResource::Type resourceType () const override
 
QWindowwindow () const
 
void setWindow (QWindow *window)
 Sets the window.
 
QRhiSwapChainProxyData proxyData () const
 
void setProxyData (const QRhiSwapChainProxyData &d)
 Sets the proxy data d.
 
Flags flags () const
 
void setFlags (Flags f)
 Sets the flags f.
 
Format format () const
 
void setFormat (Format f)
 Sets the format f.
 
QRhiRenderBufferdepthStencil () const
 
void setDepthStencil (QRhiRenderBuffer *ds)
 Sets the renderbuffer ds for use as a depth-stencil buffer.
 
int sampleCount () const
 
void setSampleCount (int samples)
 Sets the sample count.
 
QRhiRenderPassDescriptorrenderPassDescriptor () const
 
void setRenderPassDescriptor (QRhiRenderPassDescriptor *desc)
 Associates with the QRhiRenderPassDescriptor desc.
 
QSize currentPixelSize () const
 
virtual QRhiCommandBuffercurrentFrameCommandBuffer ()=0
 
virtual QRhiRenderTargetcurrentFrameRenderTarget ()=0
 
virtual QRhiRenderTargetcurrentFrameRenderTarget (StereoTargetBuffer targetBuffer)
 
virtual QSize surfacePixelSize ()=0
 
virtual bool isFormatSupported (Format f)=0
 
virtual QRhiRenderPassDescriptornewCompatibleRenderPassDescriptor ()=0
 
virtual bool createOrResize ()=0
 Creates the swapchain if not already done and resizes the swapchain buffers to match the current size of the targeted surface.
 
virtual QRhiSwapChainHdrInfo hdrInfo ()
 \variable QRhiSwapChainHdrInfo::limitsType
 
- Public Member Functions inherited from QRhiResource
virtual ~QRhiResource ()
 Destructor.
 
virtual void destroy ()=0
 Releases (or requests deferred releasing of) the underlying native graphics resources.
 
void deleteLater ()
 When called without a frame being recorded, this function is equivalent to deleting the object.
 
QByteArray name () const
 
void setName (const QByteArray &name)
 Sets a name for the object.
 
quint64 globalResourceId () const
 
QRhirhi () const
 

Protected Member Functions

 QRhiSwapChain (QRhiImplementation *rhi)
 
- Protected Member Functions inherited from QRhiResource
 QRhiResource (QRhiImplementation *rhi)
 

Protected Attributes

QWindowm_window = nullptr
 
Flags m_flags
 
Format m_format = SDR
 
QRhiRenderBufferm_depthStencil = nullptr
 
int m_sampleCount = 1
 
QRhiRenderPassDescriptorm_renderPassDesc = nullptr
 
QSize m_currentPixelSize
 
QRhiSwapChainProxyData m_proxyData
 
- Protected Attributes inherited from QRhiResource
QRhiImplementationm_rhi = nullptr
 
quint64 m_id
 
QByteArray m_objectName
 

Detailed Description

\inmodule QtGui

Since
6.6

Swapchain resource.

A swapchain enables presenting rendering results to a surface. A swapchain is typically backed by a set of color buffers. Of these, one is displayed at a time.

Below is a typical pattern for creating and managing a swapchain and some associated resources in order to render onto a QWindow:

void init()
{
sc = rhi->newSwapChain();
QSize(), // no need to set the size here due to UsedWithSwapChainOnly
1,
sc->setWindow(window);
sc->setDepthStencil(ds);
rp = sc->newCompatibleRenderPassDescriptor();
sc->setRenderPassDescriptor(rp);
resizeSwapChain();
}
void resizeSwapChain()
{
hasSwapChain = sc->createOrResize();
}
void render()
{
if (!hasSwapChain || notExposed)
return;
if (sc->currentPixelSize() != sc->surfacePixelSize() || newlyExposed) {
resizeSwapChain();
if (!hasSwapChain)
return;
newlyExposed = false;
}
// ...
rhi->endFrame(sc);
}
@ UsedWithSwapChainOnly
Definition qrhi.h:1102
QRhi * rhi() const
Definition qrhi.cpp:3603
QWindow * window() const
Definition qrhi.h:1575
QRhiRenderBuffer * newRenderBuffer(QRhiRenderBuffer::Type type, const QSize &pixelSize, int sampleCount=1, QRhiRenderBuffer::Flags flags={}, QRhiTexture::Format backingFormatHint=QRhiTexture::UnknownFormat)
Definition qrhi.cpp:10535
FrameOpResult beginFrame(QRhiSwapChain *swapChain, BeginFrameFlags flags={})
Starts a new frame targeting the next available buffer of swapChain.
Definition qrhi.cpp:10745
QRhiSwapChain * newSwapChain()
Definition qrhi.cpp:10693
FrameOpResult endFrame(QRhiSwapChain *swapChain, EndFrameFlags flags={})
Ends, commits, and presents a frame that was started in the last beginFrame() on swapChain.
Definition qrhi.cpp:10780
\inmodule QtCore
Definition qsize.h:25
static QT_BEGIN_NAMESPACE void init(QTextBoundaryFinder::BoundaryType type, QStringView str, QCharAttributes *attributes)
myWidget render(this)

Avoid relying on QWindow resize events to resize swapchains, especially considering that surface sizes may not always fully match the QWindow reported dimensions. The safe, cross-platform approach is to do the check via surfacePixelSize() whenever starting a new frame.

Releasing the swapchain must happen while the QWindow and the underlying native window is fully up and running. Building on the previous example:

void releaseSwapChain()
{
if (hasSwapChain) {
sc->destroy();
hasSwapChain = false;
}
}
// assuming Window is our QWindow subclass
{
switch (e->type()) {
case QEvent::UpdateRequest: // for QWindow::requestUpdate()
render();
break;
if (static_cast<QPlatformSurfaceEvent *>(e)->surfaceEventType() == QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed)
releaseSwapChain();
break;
default:
break;
}
return QWindow::event(e);
}
\inmodule QtCore
Definition qcoreevent.h:45
@ UpdateRequest
Definition qcoreevent.h:113
@ PlatformSurface
Definition qcoreevent.h:278
Type type() const
Returns the event type.
Definition qcoreevent.h:304
The QPlatformSurfaceEvent class is used to notify about native platform surface events....
Definition qevent.h:531
virtual bool event(QEvent *) override
Override this to handle any event (ev) sent to the window.
Definition qwindow.cpp:2511
bool event(QEvent *event) override
[dynamic_tooltip]
Definition main.cpp:52

Initializing the swapchain and starting to render the first frame cannot start at any time. The safe, cross-platform approach is to rely on expose events. QExposeEvent is a loosely specified event that is sent whenever a window gets mapped, obscured, and resized, depending on the platform.

void Window::exposeEvent(QExposeEvent *)
{
// initialize and start rendering when the window becomes usable for graphics purposes
if (isExposed() && !running) {
running = true;
init();
}
// stop pushing frames when not exposed or size becomes 0
if ((!isExposed() || (hasSwapChain && sc->surfacePixelSize().isEmpty())) && running)
notExposed = true;
// continue when exposed again and the surface has a valid size
if (isExposed() && running && notExposed && !sc->surfacePixelSize().isEmpty()) {
notExposed = false;
newlyExposed = true;
}
if (isExposed() && !sc->surfacePixelSize().isEmpty())
render();
}
The QExposeEvent class contains event parameters for expose events. \inmodule QtGui.
Definition qevent.h:515
static Q_CONSTINIT QBasicAtomicInt running

Once the rendering has started, a simple way to request a new frame is QWindow::requestUpdate(). While on some platforms this is merely a small timer, on others it has a specific implementation: for instance on macOS or iOS it may be backed by \l{https://developer.apple.com/documentation/corevideo/cvdisplaylink?language=objc}{CVDisplayLink}. The example above is already prepared for update requests by handling QEvent::UpdateRequest.

While acting as a QRhiRenderTarget, QRhiSwapChain also manages a QRhiCommandBuffer. Calling QRhi::endFrame() submits the recorded commands and also enqueues a present request. The default behavior is to do this with a swap interval of 1, meaning synchronizing to the display's vertical refresh is enabled. Thus the rendering thread calling beginFrame() and endFrame() will get throttled to vsync. On some backends this can be disabled by passing QRhiSwapChain:NoVSync in flags().

Multisampling (MSAA) is handled transparently to the applications when requested via setSampleCount(). Where applicable, QRhiSwapChain will take care of creating additional color buffers and issuing a multisample resolve command at the end of a frame. For OpenGL, it is necessary to request the appropriate sample count also via QSurfaceFormat, by calling QSurfaceFormat::setDefaultFormat() before initializing the QRhi.

Note
This is a RHI API with limited compatibility guarantees, see \l QRhi for details.

Definition at line 1548 of file qrhi.h.

Member Enumeration Documentation

◆ Flag

Flag values to describe swapchain properties.

\value SurfaceHasPreMulAlpha Indicates that the target surface has transparency with premultiplied alpha. For example, this is what Qt Quick uses when the alpha channel is enabled on the target QWindow, because the scenegraph rendrerer always outputs fragments with alpha multiplied into the red, green, and blue values. To ensure identical behavior across platforms, always set QSurfaceFormat::alphaBufferSize() to a non-zero value on the target QWindow whenever this flag is set on the swapchain.

\value SurfaceHasNonPreMulAlpha Indicates the target surface has transparency with non-premultiplied alpha. Be aware that this may not be supported on some systems, if the system compositor always expects content with premultiplied alpha. In that case the behavior with this flag set is expected to be equivalent to SurfaceHasPreMulAlpha.

\value sRGB Requests to pick an sRGB format for the swapchain's color buffers and/or render target views, where applicable. Note that this implies that sRGB framebuffer update and blending will get enabled for all content targeting this swapchain, and opting out is not possible. For OpenGL, set \l{QSurfaceFormat::sRGBColorSpace}{sRGBColorSpace} on the QSurfaceFormat of the QWindow in addition. Applicable only when the swapchain format is set to QRhiSwapChain::SDR.

\value UsedAsTransferSource Indicates the swapchain will be used as the source of a readback in QRhiResourceUpdateBatch::readBackTexture().

\value NoVSync Requests disabling waiting for vertical sync, also avoiding throttling the rendering thread. The behavior is backend specific and applicable only where it is possible to control this. Some may ignore the request altogether. For OpenGL, try instead setting the swap interval to 0 on the QWindow via QSurfaceFormat::setSwapInterval().

\value MinimalBufferCount Requests creating the swapchain with the minimum number of buffers, which is in practice 2, unless the graphics implementation has a higher minimum number than that. Only applicable with backends where such control is available via the graphics API, for example, Vulkan. By default it is up to the backend to decide what number of buffers it requests (in practice this is almost always either 2 or 3), and it is not the applications' concern. However, on Vulkan for instance the backend will likely prefer the higher number (3), for example to avoid odd performance issues with some Vulkan implementations on mobile devices. It could be that on some platforms it can prove to be beneficial to force the lower buffer count (2), so this flag allows forcing that. Note that all this has no effect on the number of frames kept in flight, so the CPU (QRhi) will still prepare frames at most {N - 1} frames ahead of the GPU, even when the swapchain image buffer count larger than N. ({N} = QRhi::FramesInFlight and typically 2).

Enumerator
SurfaceHasPreMulAlpha 
SurfaceHasNonPreMulAlpha 
sRGB 
UsedAsTransferSource 
NoVSync 
MinimalBufferCount 

Definition at line 1551 of file qrhi.h.

◆ Format

Describes the swapchain format.

The default format is SDR.

This enum is used with \l{QRhiSwapChain::isFormatSupported()}{isFormatSupported()} to check upfront if creating the swapchain with the given format is supported by the platform and the window's associated screen, and with \l{QRhiSwapChain::setFormat()}{setFormat()} to set the requested format in the swapchain before calling \l{QRhiSwapChain::createOrResize()}{createOrResize()} for the first time.

\value SDR 8-bit RGBA or BGRA, depending on the backend and platform. With OpenGL ES in particular, it could happen that the platform provides less than 8 bits (e.g. due to EGL and the QSurfaceFormat choosing a 565 or 444 format - this is outside the control of QRhi). Standard dynamic range. May be combined with setting the QRhiSwapChain::sRGB flag.

\value HDRExtendedSrgbLinear 16-bit float RGBA, high dynamic range, extended linear sRGB (scRGB) color space. This involves Rec. 709 primaries (same as SDR/sRGB) and linear colors. Conversion to the display's native color space (such as, HDR10) is performed by the windowing system. On Windows this is the canonical color space of the system compositor, and is the recommended format for HDR swapchains in general on desktop platforms.

\value HDR10 10-bit unsigned int RGB or BGR with 2 bit alpha, high dynamic range, HDR10 (Rec. 2020) color space with an ST2084 PQ transfer function.

\value HDRExtendedDisplayP3Linear 16-bit float RGBA, high dynamic range, extended linear Display P3 color space. The primary choice for HDR on platforms such as iOS and VisionOS.

Enumerator
SDR 
HDRExtendedSrgbLinear 
HDR10 
HDRExtendedDisplayP3Linear 

Definition at line 1561 of file qrhi.h.

◆ StereoTargetBuffer

Selects the backbuffer to use with a stereoscopic swapchain.

\value LeftBuffer \value RightBuffer

Enumerator
LeftBuffer 
RightBuffer 

Definition at line 1568 of file qrhi.h.

Constructor & Destructor Documentation

◆ QRhiSwapChain()

QRhiSwapChain::QRhiSwapChain ( QRhiImplementation * rhi)
protected

Definition at line 7313 of file qrhi.cpp.

Member Function Documentation

◆ createOrResize()

bool QRhiSwapChain::createOrResize ( )
pure virtual

Creates the swapchain if not already done and resizes the swapchain buffers to match the current size of the targeted surface.

Call this whenever the size of the target surface is different than before.

Note
call destroy() only when the swapchain needs to be released completely, typically upon QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed. To perform resizing, just call createOrResize().
Returns
true when successful, false when a graphics operation failed. Regardless of the return value, calling destroy() is always safe.

Implemented in QD3D11SwapChain, QGles2SwapChain, QMetalSwapChain, QNullSwapChain, and QVkSwapChain.

Referenced by QBackingStoreDefaultCompositor::flush(), QSGGuiThreadRenderLoop::renderWindow(), QBackingStoreRhiSupport::swapChainForWindow(), and QSGRenderThread::syncAndRender().

+ Here is the caller graph for this function:

◆ currentFrameCommandBuffer()

QRhiCommandBuffer * QRhiSwapChain::currentFrameCommandBuffer ( )
pure virtual
Returns
a command buffer on which rendering commands and resource updates can be recorded within a \l{QRhi::beginFrame()}{beginFrame} - \l{QRhi::endFrame()}{endFrame} block, assuming beginFrame() was called with this swapchain.
Note
The returned object is valid also after endFrame(), up until the next beginFrame(), but the returned command buffer should not be used to record any commands then. Rather, it can be used to query data collected during the frame (or previous frames), for example by calling \l{QRhiCommandBuffer::lastCompletedGpuTime()}{lastCompletedGpuTime()}.
The value must not be cached and reused between frames. The caller should not hold on to the returned object once \l{QRhi::beginFrame()}{beginFrame()} is called again. Instead, the command buffer object should be queried again by calling this function.

Implemented in QD3D11SwapChain, QGles2SwapChain, QMetalSwapChain, QNullSwapChain, and QVkSwapChain.

Referenced by QSGRenderThread::event(), QBackingStoreDefaultCompositor::flush(), QSGGuiThreadRenderLoop::grab(), QQuickRhiItemNode::queryCommandBuffer(), QQuick3DSceneRenderer::renderToRhiTexture(), QSGGuiThreadRenderLoop::renderWindow(), and QSGRenderThread::syncAndRender().

+ Here is the caller graph for this function:

◆ currentFrameRenderTarget() [1/2]

QRhiRenderTarget * QRhiSwapChain::currentFrameRenderTarget ( )
pure virtual
Returns
a render target that can used with beginPass() in order to render the swapchain's current backbuffer. Only valid within a QRhi::beginFrame() - QRhi::endFrame() block where beginFrame() was called with this swapchain.
Note
the value must not be cached and reused between frames

Implemented in QD3D11SwapChain, QGles2SwapChain, QMetalSwapChain, QNullSwapChain, and QVkSwapChain.

Referenced by currentFrameRenderTarget(), and QBackingStoreDefaultCompositor::flush().

+ Here is the caller graph for this function:

◆ currentFrameRenderTarget() [2/2]

QRhiRenderTarget * QRhiSwapChain::currentFrameRenderTarget ( StereoTargetBuffer targetBuffer)
virtual
Returns
a render target that can be used with beginPass() in order to render to the swapchain's left or right backbuffer. This overload should be used only with stereoscopic rendering, that is, when the associated QWindow is backed by two color buffers, one for each eye, instead of just one.

When stereoscopic rendering is not supported, the return value will be the default target. It is supported by all hardware backends except for Metal, in combination with \l QSurfaceFormat::StereoBuffers, assuming it is supported by the graphics and display driver stack at run time. Metal and Null backends are going to return the default render target from this overload.

Note
the value must not be cached and reused between frames

Reimplemented in QD3D11SwapChain, QGles2SwapChain, and QVkSwapChain.

Definition at line 7471 of file qrhi.cpp.

References currentFrameRenderTarget(), and Q_UNUSED.

+ Here is the call graph for this function:

◆ currentPixelSize()

QSize QRhiSwapChain::currentPixelSize ( ) const
inline
Returns
the size with which the swapchain was last successfully built. Use this to decide if createOrResize() needs to be called again: if {currentPixelSize() != surfacePixelSize()} then the swapchain needs to be resized.
Note
Typical rendering logic will call this function to get the output size when starting to prepare a new frame, and base dependent calculations (such as, the viewport) on the size returned from this function.

While in many cases the value is the same as {QWindow::size() * QWindow::devicePixelRatio()}, relying on the QWindow-reported size is not guaranteed to be correct on all platforms and graphics API implementations. Using this function is therefore strongly recommended whenever there is a need to identify the dimensions, in pixels, of the output layer or surface.

This also has the added benefit of avoiding potential data races when QRhi is used on a dedicated rendering thread, because the need to call QWindow functions, that may then access data updated on the main thread, is avoided.

See also
surfacePixelSize()

Definition at line 1596 of file qrhi.h.

Referenced by QBackingStoreDefaultCompositor::flush(), QSGGuiThreadRenderLoop::renderWindow(), QRhiNull::resourceUpdate(), and QSGRenderThread::syncAndRender().

+ Here is the caller graph for this function:

◆ depthStencil()

QRhiRenderBuffer * QRhiSwapChain::depthStencil ( ) const
inline
Returns
the currently associated renderbuffer for depth-stencil.

Definition at line 1587 of file qrhi.h.

◆ flags()

QRhiSwapChain::Flags QRhiSwapChain::flags ( ) const
inline
Returns
the currently set flags.

Definition at line 1581 of file qrhi.h.

◆ format()

QRhiSwapChain::Format QRhiSwapChain::format ( ) const
inline
Returns
the currently set format.

Definition at line 1584 of file qrhi.h.

Referenced by QD3D11SwapChain::newColorBuffer(), and qShouldUpdateSwapChainFormat().

+ Here is the caller graph for this function:

◆ hdrInfo()

QRhiSwapChainHdrInfo QRhiSwapChain::hdrInfo ( )
virtual

\variable QRhiSwapChainHdrInfo::limitsType

With Metal on macOS/iOS, there is no luminance values exposed in the platform APIs. Instead, the maximum color component value, that would be 1.0 in a non-HDR setup, is provided. This value indicates what kind of information is available in \l limits.

See also
QRhiSwapChain::hdrInfo()

\variable QRhiSwapChainHdrInfo::limits

Contains the actual values queried from the graphics API or the platform. The type of data is indicated by \l limitsType. This is therefore a union. There are currently two options:

Luminance values in nits:

struct {
float minLuminance;
float maxLuminance;
} luminanceInNits;

On Windows the minimum and maximum luminance depends on the screen brightness. While not relevant for desktops, on laptops the screen brightness may change at any time. Increasing brightness implies decreased maximum luminance. In addition, the results may also be dependent on the HDR Content Brightness set in Windows Settings' System/Display/HDR view, if there is such a setting.

Note however that the changes made to the laptop screen's brightness or in the system settings while the application is running are not necessarily reflected in the returned values, meaning calling hdrInfo() again may still return the same luminance range as before for the rest of the process' lifetime. The exact behavior is up to DXGI and Qt has no control over it.

Note
The Windows compositor works in scene-referred mode for HDR content. A color component value of 1.0 corresponds to a luminance of 80 nits. When rendering non-HDR content (e.g. 2D UI elements), the correction of the white level is often necessary. (e.g., outputting the fragment color (1, 1, 1) will likely lead to showing a shade of white that is too dim on-screen) See \l sdrWhiteLevel.

For macOS/iOS, the current maximum and potential maximum color component values are provided:

struct {
float maxColorComponentValue;
float maxPotentialColorComponentValue;
} colorComponentValue;

The value may depend on the screen brightness, which on laptops means that the result may change in the next call to hdrInfo() if the brightness was changed in the meantime. The maximum screen brightness implies a maximum color value of 1.0.

Note
Apple's EDR is display-referred. 1.0 corresponds to a luminance level of SDR white (e.g. 200 nits), the value of which varies based on the screen brightness and possibly other settings. The exact luminance value for that, or the maximum luminance of the display, are not exposed to the applications.
It has been observed that the color component values are not set to the correct larger-than-1 value right away on startup on some macOS systems, but the values tend to change during or after the first frame.
See also
QRhiSwapChain::hdrInfo()

\variable QRhiSwapChainHdrInfo::luminanceBehavior

Describes the platform's presumed behavior with regards to color values.

See also
sdrWhiteLevel

\variable QRhiSwapChainHdrInfo::sdrWhiteLevel

On Windows this is the dynamic SDR white level in nits. The value is dependent on the screen brightness (on laptops), and the SDR or HDR Content Brightness settings in the Windows settings' System/Display/HDR view.

To perform white level correction for non-HDR (SDR) content, such as 2D UI elemenents, multiply the final color with sdrWhiteLevel / 80.0 whenever \l luminanceBehavior is SceneReferred. (assuming Windows and a linear extended sRGB (scRGB) color space)

On other platforms the value is always a pre-defined value, 200. This may not match the system's actual SDR white level, but the value of this variable is not relevant in practice when the \l luminanceBehavior is DisplayReferred, because then the color component value of 1.0 refers to the SDR white by default.

See also
luminanceBehavior
Returns
the HDR information for the associated display.

Do not assume that this is a cheap operation. Depending on the platform, this function makes various platform queries which may have a performance impact.

Note
Can be called before createOrResize() as long as the window is \l{setWindow()}{set}.
What happens when moving a window with an initialized swapchain between displays (HDR to HDR with different characteristics, HDR to SDR, etc.) is not currently well-defined and depends heavily on the windowing system and compositor, with potentially varying behavior between platforms. Currently QRhi only guarantees that hdrInfo() returns valid data, if available, for the display to which the swapchain's associated window belonged at the time of createOrResize().
See also
QRhiSwapChainHdrInfo

Reimplemented in QD3D11SwapChain, and QMetalSwapChain.

Definition at line 7797 of file qrhi.cpp.

References info, QRhiSwapChainHdrInfo::LuminanceInNits, and QRhiSwapChainHdrInfo::SceneReferred.

Referenced by QD3D11SwapChain::hdrInfo().

+ Here is the caller graph for this function:

◆ isFormatSupported()

bool QRhiSwapChain::isFormatSupported ( Format f)
pure virtual
Returns
true if the given swapchain format f is supported. SDR is always supported.
Note
Can be called independently of createOrResize(), but window() must already be set. Calling without the window set may lead to unexpected results depending on the backend and platform (most likely false for any HDR format), because HDR format support is usually tied to the output (screen) to which the swapchain's associated window belongs at any given time. If the result is true for a HDR format, then creating the swapchain with that format is expected to succeed as long as the window is not moved to another screen in the meantime.

The main use of this function is to call it before the first createOrResize() after the window is already set. This allow the QRhi backends to perform platform or windowing system specific queries to determine if the window (and the screen it is on) is capable of true HDR output with the specified format.

When the format is reported as supported, call setFormat() to set the requested format and call createOrResize(). Be aware of the consequences however: successfully requesting a HDR format will involve having to deal with a different color space, possibly doing white level correction for non-HDR-aware content, adjusting tonemapping methods, adjusting offscreen render target settings, etc.

See also
setFormat()

Implemented in QD3D11SwapChain, QGles2SwapChain, QMetalSwapChain, QNullSwapChain, and QVkSwapChain.

Referenced by qShouldUpdateSwapChainFormat().

+ Here is the caller graph for this function:

◆ newCompatibleRenderPassDescriptor()

QRhiRenderPassDescriptor * QRhiSwapChain::newCompatibleRenderPassDescriptor ( )
pure virtual
Returns
a new QRhiRenderPassDescriptor that is compatible with this swapchain.

The returned value is used in two ways: it can be passed to setRenderPassDescriptor() and QRhiGraphicsPipeline::setRenderPassDescriptor(). A render pass descriptor describes the attachments (color, depth/stencil) and the load/store behavior that can be affected by flags(). A QRhiGraphicsPipeline can only be used in combination with a swapchain that has a \l{QRhiRenderPassDescriptor::isCompatible()}{compatible} QRhiRenderPassDescriptor set.

See also
createOrResize()

Implemented in QD3D11SwapChain, QGles2SwapChain, QMetalSwapChain, QNullSwapChain, and QVkSwapChain.

Referenced by QSGRenderThread::ensureRhi(), QSGGuiThreadRenderLoop::ensureRhi(), and QBackingStoreRhiSupport::swapChainForWindow().

+ Here is the caller graph for this function:

◆ proxyData()

QRhiSwapChainProxyData QRhiSwapChain::proxyData ( ) const
inline
Returns
the currently set proxy data.

Definition at line 1578 of file qrhi.h.

◆ renderPassDescriptor()

QRhiRenderPassDescriptor * QRhiSwapChain::renderPassDescriptor ( ) const
inline
Returns
the currently associated QRhiRenderPassDescriptor object.

Definition at line 1593 of file qrhi.h.

Referenced by QBackingStoreDefaultCompositor::flush(), and QBackingStoreRhiSupport::swapChainForWindow().

+ Here is the caller graph for this function:

◆ resourceType()

QRhiResource::Type QRhiSwapChain::resourceType ( ) const
overridevirtual
Returns
the resource type.

Implements QRhiResource.

Definition at line 7321 of file qrhi.cpp.

References QRhiResource::SwapChain.

◆ sampleCount()

int QRhiSwapChain::sampleCount ( ) const
inline
Returns
the currently set sample count. 1 means no multisample antialiasing.

Definition at line 1590 of file qrhi.h.

◆ setDepthStencil()

void QRhiSwapChain::setDepthStencil ( QRhiRenderBuffer * ds)
inline

Sets the renderbuffer ds for use as a depth-stencil buffer.

Definition at line 1588 of file qrhi.h.

Referenced by QSGRenderThread::ensureRhi(), and QSGGuiThreadRenderLoop::ensureRhi().

+ Here is the caller graph for this function:

◆ setFlags()

void QRhiSwapChain::setFlags ( Flags f)
inline

Sets the flags f.

Definition at line 1582 of file qrhi.h.

Referenced by QSGRenderThread::ensureRhi(), QSGGuiThreadRenderLoop::ensureRhi(), and QBackingStoreRhiSupport::swapChainForWindow().

+ Here is the caller graph for this function:

◆ setFormat()

void QRhiSwapChain::setFormat ( Format f)
inline

Sets the format f.

Avoid setting formats that are reported as unsupported from isFormatSupported(). Note that support for a given format may depend on the screen the swapchain's associated window is opened on. On some platforms, such as Windows and macOS, for HDR output to work it is necessary to have HDR output enabled in the display settings.

See isFormatSupported(), \l QRhiSwapChainHdrInfo, and \l Format for more information on high dynamic range output.

Definition at line 1585 of file qrhi.h.

◆ setProxyData()

void QRhiSwapChain::setProxyData ( const QRhiSwapChainProxyData & d)
inline

Sets the proxy data d.

See also
QRhi::updateSwapChainProxyData()

Definition at line 1579 of file qrhi.h.

References d.

Referenced by QSGRenderThread::ensureRhi(), and QSGRenderThread::syncAndRender().

+ Here is the caller graph for this function:

◆ setRenderPassDescriptor()

void QRhiSwapChain::setRenderPassDescriptor ( QRhiRenderPassDescriptor * desc)
inline

Associates with the QRhiRenderPassDescriptor desc.

Definition at line 1594 of file qrhi.h.

Referenced by QSGRenderThread::ensureRhi(), QSGGuiThreadRenderLoop::ensureRhi(), and QBackingStoreRhiSupport::swapChainForWindow().

+ Here is the caller graph for this function:

◆ setSampleCount()

void QRhiSwapChain::setSampleCount ( int samples)
inline

Sets the sample count.

Common values for samples are 1 (no MSAA), 4 (4x MSAA), or 8 (8x MSAA).

See also
QRhi::supportedSampleCounts()

Definition at line 1591 of file qrhi.h.

Referenced by QSGRenderThread::ensureRhi(), and QSGGuiThreadRenderLoop::ensureRhi().

+ Here is the caller graph for this function:

◆ setWindow()

void QRhiSwapChain::setWindow ( QWindow * window)
inline

Sets the window.

Definition at line 1576 of file qrhi.h.

References window().

Referenced by QSGRenderThread::ensureRhi(), QSGGuiThreadRenderLoop::ensureRhi(), and QBackingStoreRhiSupport::swapChainForWindow().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ surfacePixelSize()

QSize QRhiSwapChain::surfacePixelSize ( )
pure virtual
Returns
The size of the window's associated surface or layer.
Warning
Do not assume this is the same as {QWindow::size() * QWindow::devicePixelRatio()}. With some graphics APIs and windowing system interfaces (for example, Vulkan) there is a theoretical possibility for a surface to assume a size different from the associated window. To support these cases, {rendering logic must always base size-derived calculations (such as, viewports) on the size reported from QRhiSwapChain, and never on the size queried from QWindow}.
Note
{Can also be called before createOrResize(), if at least window() is already set. This in combination with currentPixelSize() allows to detect when a swapchain needs to be resized.} However, watch out for the fact that the size of the underlying native object (surface, layer, or similar) is "live", so whenever this function is called, it returns the latest value reported by the underlying implementation, without any atomicity guarantee. Therefore, using this function to determine pixel sizes for graphics resources that are used in a frame is strongly discouraged. Rely on currentPixelSize() instead which returns a size that is atomic and will not change between createOrResize() invocations.
For depth-stencil buffers used in combination with the swapchain's color buffers, it is strongly recommended to rely on the automatic sizing and rebuilding behavior provided by the QRhiRenderBuffer:UsedWithSwapChainOnly flag. Avoid querying the surface size via this function just to get a size that can be passed to QRhiRenderBuffer::setPixelSize() as that would suffer from the lack of atomicity as described above.
See also
currentPixelSize()

Implemented in QD3D11SwapChain, QGles2SwapChain, QMetalSwapChain, QNullSwapChain, and QVkSwapChain.

Referenced by QSGGuiThreadRenderLoop::exposureChanged(), QSGThreadedRenderLoop::exposureChanged(), QBackingStoreDefaultCompositor::flush(), QSGGuiThreadRenderLoop::renderWindow(), and QSGRenderThread::syncAndRender().

+ Here is the caller graph for this function:

◆ window()

QWindow * QRhiSwapChain::window ( ) const
inline
Returns
the currently set window.

Definition at line 1575 of file qrhi.h.

Referenced by QBackingStoreDefaultCompositor::flush().

+ Here is the caller graph for this function:

Member Data Documentation

◆ m_currentPixelSize

◆ m_depthStencil

◆ m_flags

◆ m_format

◆ m_proxyData

QRhiSwapChainProxyData QRhiSwapChain::m_proxyData
protected

◆ m_renderPassDesc

◆ m_sampleCount

◆ m_window


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