summaryrefslogtreecommitdiffstats
path: root/src/gui/rhi
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@qt.io>2022-01-02 20:21:46 +0100
committerLaszlo Agocs <laszlo.agocs@qt.io>2022-01-06 02:43:40 +0100
commit8efe2d54b7d0427badee1edee221849f19629845 (patch)
treedf673cc49b96efb7a8b89bea45f4225963158778 /src/gui/rhi
parentabe802cd00bb28e95c63d318b0360db6fbf51666 (diff)
rhi: Expose HDR output info in a saner way
Don't bother with exposing the IDXGIOutput6. Instead, report the values, just the ones that matter for tonemapping or transfer functions in a cross-platform way that's also prepared for Metal's different way of doing things. Change-Id: I28c7b6144f8267a9d3d44eff1e40697fb543385f Reviewed-by: Andy Nichols <andy.nichols@qt.io>
Diffstat (limited to 'src/gui/rhi')
-rw-r--r--src/gui/rhi/qrhi.cpp35
-rw-r--r--src/gui/rhi/qrhi_p.h28
-rw-r--r--src/gui/rhi/qrhid3d11.cpp47
-rw-r--r--src/gui/rhi/qrhid3d11_p.h5
-rw-r--r--src/gui/rhi/qrhid3d11_p_p.h5
5 files changed, 72 insertions, 48 deletions
diff --git a/src/gui/rhi/qrhi.cpp b/src/gui/rhi/qrhi.cpp
index 408122f621..3da1edfdac 100644
--- a/src/gui/rhi/qrhi.cpp
+++ b/src/gui/rhi/qrhi.cpp
@@ -4465,17 +4465,36 @@ QRhiResource::Type QRhiSwapChain::resourceType() const
Regardless of the return value, calling destroy() is always safe.
*/
-/*!
- \return a pointer to a backend-specific QRhiNativeHandles subclass, such as
- QRhiD3D11SwapChainNativeHandles. The returned value is \nullptr when
- exposing the underlying native resources is not supported by the backend.
+QRhiSwapChainHdrInfo QRhiSwapChain::hdrInfo()
+{
+ QRhiSwapChainHdrInfo info;
+ info.isHardCodedDefaults = true;
+ info.limitsType = QRhiSwapChainHdrInfo::LuminanceInNits;
+ info.limits.luminanceInNits.minLuminance = 0.0f;
+ info.limits.luminanceInNits.maxLuminance = 1000.0f;
+ return info;
+}
- \sa QRhiD3D11SwapChainNativeHandles
- */
-const QRhiNativeHandles *QRhiSwapChain::nativeHandles()
+#ifndef QT_NO_DEBUG_STREAM
+QDebug operator<<(QDebug dbg, const QRhiSwapChainHdrInfo &info)
{
- return nullptr;
+ QDebugStateSaver saver(dbg);
+ dbg.nospace() << "QRhiSwapChainHdrInfo(" << (info.isHardCodedDefaults ? "with hard-coded defaults" : "queried from system");
+ switch (info.limitsType) {
+ case QRhiSwapChainHdrInfo::LuminanceInNits:
+ dbg.nospace() << " minLuminance=" << info.limits.luminanceInNits.minLuminance
+ << " maxLuminance=" << info.limits.luminanceInNits.maxLuminance;
+ break;
+ case QRhiSwapChainHdrInfo::ColorComponentValue:
+ dbg.nospace() << " maxColorComponentValue=" << info.limits.colorComponentValue.maxColorComponentValue;
+ break;
+ default:
+ break;
+ }
+ dbg.nospace() << ')';
+ return dbg;
}
+#endif
/*!
\class QRhiComputePipeline
diff --git a/src/gui/rhi/qrhi_p.h b/src/gui/rhi/qrhi_p.h
index 7aae71771e..9edad2e10c 100644
--- a/src/gui/rhi/qrhi_p.h
+++ b/src/gui/rhi/qrhi_p.h
@@ -1313,6 +1313,31 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiGraphicsPipeline::Flags)
Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiGraphicsPipeline::ColorMask)
Q_DECLARE_TYPEINFO(QRhiGraphicsPipeline::TargetBlend, Q_RELOCATABLE_TYPE);
+struct QRhiSwapChainHdrInfo
+{
+ bool isHardCodedDefaults;
+ enum LimitsType {
+ LuminanceInNits,
+ ColorComponentValue
+ };
+ LimitsType limitsType;
+ union {
+ struct {
+ float minLuminance;
+ float maxLuminance;
+ } luminanceInNits;
+ struct {
+ float maxColorComponentValue;
+ } colorComponentValue;
+ } limits;
+};
+
+Q_DECLARE_TYPEINFO(QRhiSwapChainHdrInfo, Q_RELOCATABLE_TYPE);
+
+#ifndef QT_NO_DEBUG_STREAM
+Q_GUI_EXPORT QDebug operator<<(QDebug, const QRhiSwapChainHdrInfo &);
+#endif
+
class Q_GUI_EXPORT QRhiSwapChain : public QRhiResource
{
public:
@@ -1360,8 +1385,7 @@ public:
virtual bool isFormatSupported(Format f) = 0;
virtual QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor() = 0;
virtual bool createOrResize() = 0;
-
- virtual const QRhiNativeHandles *nativeHandles();
+ virtual QRhiSwapChainHdrInfo hdrInfo();
protected:
QRhiSwapChain(QRhiImplementation *rhi);
diff --git a/src/gui/rhi/qrhid3d11.cpp b/src/gui/rhi/qrhid3d11.cpp
index ca1c362bdd..0c8fff88df 100644
--- a/src/gui/rhi/qrhid3d11.cpp
+++ b/src/gui/rhi/qrhid3d11.cpp
@@ -115,18 +115,6 @@ QT_BEGIN_NAMESPACE
\c{ID3D11Device *} and \c{ID3D11DeviceContext *}.
*/
-/*!
- \class QRhiD3D11SwapChainNativeHandles
- \internal
- \inmodule QtGui
- \brief Exposes D3D/DXGI specific data for a swapchain
-
- dxgiOutput6 is the IDXGIOutput6* for the swapchain's current output, if
- supported, null otherwise. The current output is determined based on the
- position of the swapchain's associated window at the time of calling
- QRhiSwapChain::createOrResize().
- */
-
// help mingw with its ancient sdk headers
#ifndef DXGI_ADAPTER_FLAG_SOFTWARE
#define DXGI_ADAPTER_FLAG_SOFTWARE 2
@@ -4376,11 +4364,6 @@ void QD3D11SwapChain::destroy()
swapChain->Release();
swapChain = nullptr;
- if (output6) {
- output6->Release();
- output6 = nullptr;
- }
-
QRHI_RES_RHI(QRhiD3D11);
if (rhiD)
rhiD->unregisterResource(this);
@@ -4458,6 +4441,22 @@ bool QD3D11SwapChain::isFormatSupported(Format f)
return false;
}
+QRhiSwapChainHdrInfo QD3D11SwapChain::hdrInfo()
+{
+ QRhiSwapChainHdrInfo info = QRhiSwapChain::hdrInfo();
+ if (m_format != QRhiSwapChain::SDR && m_window) {
+ QRHI_RES_RHI(QRhiD3D11);
+ DXGI_OUTPUT_DESC1 hdrOutputDesc;
+ if (outputDesc1ForWindow(m_window, rhiD->activeAdapter, &hdrOutputDesc)) {
+ info.isHardCodedDefaults = false;
+ info.limitsType = QRhiSwapChainHdrInfo::LuminanceInNits;
+ info.limits.luminanceInNits.minLuminance = hdrOutputDesc.MinLuminance;
+ info.limits.luminanceInNits.maxLuminance = hdrOutputDesc.MaxLuminance;
+ }
+ }
+ return info;
+}
+
QRhiRenderPassDescriptor *QD3D11SwapChain::newCompatibleRenderPassDescriptor()
{
return new QD3D11RenderPassDescriptor(m_rhi);
@@ -4546,13 +4545,9 @@ bool QD3D11SwapChain::createOrResize()
HRESULT hr;
if (useFlipDiscard) {
DXGI_COLOR_SPACE_TYPE hdrColorSpace = DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709; // SDR
- if (output6) {
- output6->Release();
- output6 = nullptr;
- }
- if (output6ForWindow(m_window, rhiD->activeAdapter, &output6) && m_format != SDR) {
+ DXGI_OUTPUT_DESC1 hdrOutputDesc;
+ if (outputDesc1ForWindow(m_window, rhiD->activeAdapter, &hdrOutputDesc) && m_format != SDR) {
// https://docs.microsoft.com/en-us/windows/win32/direct3darticles/high-dynamic-range
- output6->GetDesc1(&hdrOutputDesc);
if (hdrOutputDesc.ColorSpace == DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020) {
switch (m_format) {
case HDRExtendedSrgbLinear:
@@ -4767,12 +4762,6 @@ bool QD3D11SwapChain::createOrResize()
return true;
}
-const QRhiNativeHandles *QD3D11SwapChain::nativeHandles()
-{
- nativeHandlesStruct.dxgiOutput6 = output6;
- return &nativeHandlesStruct;
-}
-
void QRhiD3D11::DeviceCurse::initResources()
{
framesLeft = framesToActivate;
diff --git a/src/gui/rhi/qrhid3d11_p.h b/src/gui/rhi/qrhid3d11_p.h
index f4237d911d..ed26e9af16 100644
--- a/src/gui/rhi/qrhid3d11_p.h
+++ b/src/gui/rhi/qrhid3d11_p.h
@@ -76,11 +76,6 @@ struct Q_GUI_EXPORT QRhiD3D11NativeHandles : public QRhiNativeHandles
qint32 adapterLuidHigh = 0;
};
-struct Q_GUI_EXPORT QRhiD3D11SwapChainNativeHandles : public QRhiNativeHandles
-{
- void *dxgiOutput6 = nullptr;
-};
-
QT_END_NAMESPACE
#endif
diff --git a/src/gui/rhi/qrhid3d11_p_p.h b/src/gui/rhi/qrhid3d11_p_p.h
index edc38978bd..dcd66c9f67 100644
--- a/src/gui/rhi/qrhid3d11_p_p.h
+++ b/src/gui/rhi/qrhid3d11_p_p.h
@@ -560,10 +560,10 @@ struct QD3D11SwapChain : public QRhiSwapChain
QSize surfacePixelSize() override;
bool isFormatSupported(Format f) override;
+ QRhiSwapChainHdrInfo hdrInfo() override;
QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor() override;
bool createOrResize() override;
- const QRhiNativeHandles *nativeHandles() override;
void releaseBuffers();
bool newColorBuffer(const QSize &size, DXGI_FORMAT format, DXGI_SAMPLE_DESC sampleDesc,
@@ -589,9 +589,6 @@ struct QD3D11SwapChain : public QRhiSwapChain
ID3D11Query *timestampDisjointQuery[BUFFER_COUNT];
ID3D11Query *timestampQuery[BUFFER_COUNT * 2];
UINT swapInterval = 1;
- IDXGIOutput6 *output6 = nullptr;
- DXGI_OUTPUT_DESC1 hdrOutputDesc;
- QRhiD3D11SwapChainNativeHandles nativeHandlesStruct;
};
class QRhiD3D11 : public QRhiImplementation