diff options
Diffstat (limited to 'tests/manual/rhi/shared')
17 files changed, 56 insertions, 37 deletions
diff --git a/tests/manual/rhi/shared/buildshaders.bat b/tests/manual/rhi/shared/buildshaders.bat index d0212bc7a7..faa253c8bc 100644 --- a/tests/manual/rhi/shared/buildshaders.bat +++ b/tests/manual/rhi/shared/buildshaders.bat @@ -1,7 +1,9 @@ -qsb --glsl "100 es,120" --hlsl 50 --msl 12 -c color.vert -o color.vert.qsb -qsb --glsl "100 es,120" --hlsl 50 --msl 12 -c color.frag -o color.frag.qsb -qsb --glsl "100 es,120" --hlsl 50 --msl 12 -c texture.vert -o texture.vert.qsb -qsb --glsl "100 es,120" --hlsl 50 --msl 12 -c texture.frag -o texture.frag.qsb +:: Copyright (C) 2024 The Qt Company Ltd. +:: SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +qsb --glsl "100 es,120,150" --hlsl 50 --msl 12 -c color.vert -o color.vert.qsb +qsb --glsl "100 es,120,150" --hlsl 50 --msl 12 -c color.frag -o color.frag.qsb +qsb --glsl "100 es,120,150" --hlsl 50 --msl 12 -c texture.vert -o texture.vert.qsb +qsb --glsl "100 es,120,150" --hlsl 50 --msl 12 -c texture.frag -o texture.frag.qsb qsb --glsl "310 es,150" --hlsl 50 --msl 12 -c texture_ms4.frag -o texture_ms4.frag.qsb qsb --glsl "100 es,120,150" --hlsl 50 --msl 12 -c texture_arr.vert -o texture_arr.vert.qsb qsb --glsl "100 es,120,150" --hlsl 50 --msl 12 -c texture_arr.frag -o texture_arr.frag.qsb diff --git a/tests/manual/rhi/shared/color.frag.qsb b/tests/manual/rhi/shared/color.frag.qsb Binary files differindex 0c3815b8be..753acda690 100644 --- a/tests/manual/rhi/shared/color.frag.qsb +++ b/tests/manual/rhi/shared/color.frag.qsb diff --git a/tests/manual/rhi/shared/color.vert.qsb b/tests/manual/rhi/shared/color.vert.qsb Binary files differindex dfa577f668..ef7545b621 100644 --- a/tests/manual/rhi/shared/color.vert.qsb +++ b/tests/manual/rhi/shared/color.vert.qsb diff --git a/tests/manual/rhi/shared/dds_bc1.h b/tests/manual/rhi/shared/dds_bc1.h index aebf7fdac8..6d7236d068 100644 --- a/tests/manual/rhi/shared/dds_bc1.h +++ b/tests/manual/rhi/shared/dds_bc1.h @@ -1,5 +1,5 @@ // Copyright (C) 2018 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only static const quint32 DDS_MAGIC = 0x20534444; // 'DDS ' static const quint32 DDS_FOURCC = 4; diff --git a/tests/manual/rhi/shared/examplefw.h b/tests/manual/rhi/shared/examplefw.h index 9879e8c5ba..f2ca57341c 100644 --- a/tests/manual/rhi/shared/examplefw.h +++ b/tests/manual/rhi/shared/examplefw.h @@ -1,5 +1,5 @@ // Copyright (C) 2018 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only // Adapted from hellominimalcrossgfxtriangle with the frame rendering stripped out. // Include this file and implement Window::customInit, release and render. @@ -13,28 +13,9 @@ #include <QTimer> #include <QLoggingCategory> #include <QColorSpace> - -#include <QtGui/private/qshader_p.h> #include <QFile> -#include <QtGui/private/qrhinull_p.h> - -#ifndef QT_NO_OPENGL -#include <QtGui/private/qrhigles2_p.h> #include <QOffscreenSurface> -#endif - -#if QT_CONFIG(vulkan) -#include <QtGui/private/qrhivulkan_p.h> -#endif - -#ifdef Q_OS_WIN -#include <QtGui/private/qrhid3d11_p.h> -#include <QtGui/private/qrhid3d12_p.h> -#endif - -#if defined(Q_OS_MACOS) || defined(Q_OS_IOS) -#include <QtGui/private/qrhimetal_p.h> -#endif +#include <rhi/qrhi.h> #ifdef EXAMPLEFW_IMGUI #include "qrhiimgui_p.h" @@ -92,13 +73,15 @@ QString graphicsApiName() return QString(); } -QRhi::Flags rhiFlags = QRhi::EnableDebugMarkers; +QRhi::Flags rhiFlags = QRhi::EnableDebugMarkers | QRhi::EnableTimestamps; int sampleCount = 1; QRhiSwapChain::Flags scFlags; QRhi::BeginFrameFlags beginFrameFlags; QRhi::EndFrameFlags endFrameFlags; bool transparentBackground = false; bool debugLayer = true; +QRhiSwapChain::Format swapchainFormat = QRhiSwapChain::SDR; +float imguiHDRMultiplier = 0.0f; class Window : public QWindow { @@ -278,7 +261,7 @@ void Window::init() } #endif -#if defined(Q_OS_MACOS) || defined(Q_OS_IOS) +#if QT_CONFIG(metal) if (graphicsApi == Metal) { QRhiMetalInitParams params; m_r = QRhi::create(QRhi::Metal, ¶ms, rhiFlags); @@ -299,6 +282,10 @@ void Window::init() m_sc->setDepthStencil(m_ds); m_sc->setSampleCount(sampleCount); m_sc->setFlags(scFlags); + if (!m_sc->isFormatSupported(swapchainFormat)) + qWarning("Swapchain reports that requested format %d is not supported", int(swapchainFormat)); + else + m_sc->setFormat(swapchainFormat); m_rp = m_sc->newCompatibleRenderPassDescriptor(); m_sc->setRenderPassDescriptor(m_rp); @@ -417,7 +404,7 @@ void Window::render() QMatrix4x4 guiMvp = m_r->clipSpaceCorrMatrix(); guiMvp.ortho(0, outputSizeInPixels.width() / dpr, outputSizeInPixels.height() / dpr, 0, 1, -1); - m_imguiRenderer->prepare(m_r, rt, cb, guiMvp, 1.0f); + m_imguiRenderer->prepare(m_r, rt, cb, guiMvp, 1.0f, imguiHDRMultiplier); #endif customRender(); @@ -439,7 +426,7 @@ int main(int argc, char **argv) // Defaults. #if defined(Q_OS_WIN) graphicsApi = D3D11; -#elif defined(Q_OS_MACOS) || defined(Q_OS_IOS) +#elif QT_CONFIG(metal) graphicsApi = Metal; #elif QT_CONFIG(vulkan) graphicsApi = Vulkan; diff --git a/tests/manual/rhi/shared/imgui/buildshaders.bat b/tests/manual/rhi/shared/imgui/buildshaders.bat index eec4e3a070..560c634134 100644 --- a/tests/manual/rhi/shared/imgui/buildshaders.bat +++ b/tests/manual/rhi/shared/imgui/buildshaders.bat @@ -1,2 +1,4 @@ +:: Copyright (C) 2024 The Qt Company Ltd. +:: SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 qsb --glsl "100 es,120,150" --hlsl 50 --msl 12 -c imgui.vert -o imgui.vert.qsb qsb --glsl "100 es,120,150" --hlsl 50 --msl 12 -c imgui.frag -o imgui.frag.qsb diff --git a/tests/manual/rhi/shared/imgui/imgui.frag b/tests/manual/rhi/shared/imgui/imgui.frag index 51bd615deb..6169dd639f 100644 --- a/tests/manual/rhi/shared/imgui/imgui.frag +++ b/tests/manual/rhi/shared/imgui/imgui.frag @@ -8,14 +8,30 @@ layout(location = 0) out vec4 fragColor; layout(std140, binding = 0) uniform buf { mat4 mvp; float opacity; + // Windows HDR: set to SDR_white_level_in_nits / 80 + // macOS/iOS EDR: set to 1.0 + // No HDR: set to 0.0, will do linear to sRGB at the end then. + float hdrWhiteLevelMult; }; layout(binding = 1) uniform sampler2D tex; +vec3 linearToSRGB(vec3 color) +{ + vec3 S1 = sqrt(color); + vec3 S2 = sqrt(S1); + vec3 S3 = sqrt(S2); + return 0.585122381 * S1 + 0.783140355 * S2 - 0.368262736 * S3; +} + void main() { vec4 c = v_color * texture(tex, v_texcoord); c.a *= opacity; - c.rgb *= c.a; + if (hdrWhiteLevelMult > 0.0) + c.rgb *= hdrWhiteLevelMult; + else + c.rgb = linearToSRGB(c.rgb); + c.rgb *= c.a; // premultiplied alpha fragColor = c; } diff --git a/tests/manual/rhi/shared/imgui/imgui.frag.qsb b/tests/manual/rhi/shared/imgui/imgui.frag.qsb Binary files differindex 2abf236f56..09b1e44697 100644 --- a/tests/manual/rhi/shared/imgui/imgui.frag.qsb +++ b/tests/manual/rhi/shared/imgui/imgui.frag.qsb diff --git a/tests/manual/rhi/shared/imgui/imgui.vert b/tests/manual/rhi/shared/imgui/imgui.vert index bb24a22c13..45510ea0fe 100644 --- a/tests/manual/rhi/shared/imgui/imgui.vert +++ b/tests/manual/rhi/shared/imgui/imgui.vert @@ -10,6 +10,7 @@ layout(location = 1) out vec4 v_color; layout(std140, binding = 0) uniform buf { mat4 mvp; float opacity; + float sdrMult; }; void main() diff --git a/tests/manual/rhi/shared/imgui/imgui.vert.qsb b/tests/manual/rhi/shared/imgui/imgui.vert.qsb Binary files differindex 0f2300f676..3ee5a7b716 100644 --- a/tests/manual/rhi/shared/imgui/imgui.vert.qsb +++ b/tests/manual/rhi/shared/imgui/imgui.vert.qsb diff --git a/tests/manual/rhi/shared/imgui/qrhiimgui.cpp b/tests/manual/rhi/shared/imgui/qrhiimgui.cpp index d4330238b9..88b0a5d897 100644 --- a/tests/manual/rhi/shared/imgui/qrhiimgui.cpp +++ b/tests/manual/rhi/shared/imgui/qrhiimgui.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2022 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "qrhiimgui_p.h" #include <QtCore/qfile.h> @@ -48,7 +48,12 @@ void QRhiImguiRenderer::releaseResources() m_rhi = nullptr; } -void QRhiImguiRenderer::prepare(QRhi *rhi, QRhiRenderTarget *rt, QRhiCommandBuffer *cb, const QMatrix4x4 &mvp, float opacity) +void QRhiImguiRenderer::prepare(QRhi *rhi, + QRhiRenderTarget *rt, + QRhiCommandBuffer *cb, + const QMatrix4x4 &mvp, + float opacity, + float hdrWhiteLevelMultiplierOrZeroForSDRsRGB) { if (!m_rhi) { m_rhi = rhi; @@ -89,7 +94,7 @@ void QRhiImguiRenderer::prepare(QRhi *rhi, QRhiRenderTarget *rt, QRhiCommandBuff } if (!m_ubuf) { - m_ubuf.reset(m_rhi->newBuffer(QRhiBuffer::Dynamic, QRhiBuffer::UniformBuffer, 64 + 4)); + m_ubuf.reset(m_rhi->newBuffer(QRhiBuffer::Dynamic, QRhiBuffer::UniformBuffer, 64 + 4 + 4)); m_ubuf->setName(QByteArrayLiteral("imgui uniform buffer")); if (!m_ubuf->create()) return; @@ -201,6 +206,7 @@ void QRhiImguiRenderer::prepare(QRhi *rhi, QRhiRenderTarget *rt, QRhiCommandBuff u->updateDynamicBuffer(m_ubuf.get(), 0, 64, mvp.constData()); u->updateDynamicBuffer(m_ubuf.get(), 64, 4, &opacity); + u->updateDynamicBuffer(m_ubuf.get(), 68, 4, &hdrWhiteLevelMultiplierOrZeroForSDRsRGB); for (int i = 0; i < texturesNeedUpdate.count(); ++i) { Texture &t(m_textures[texturesNeedUpdate[i]]); diff --git a/tests/manual/rhi/shared/imgui/qrhiimgui_p.h b/tests/manual/rhi/shared/imgui/qrhiimgui_p.h index 1b4b4d67b6..ec86c2af7f 100644 --- a/tests/manual/rhi/shared/imgui/qrhiimgui_p.h +++ b/tests/manual/rhi/shared/imgui/qrhiimgui_p.h @@ -1,10 +1,10 @@ // Copyright (C) 2022 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef QRHIIMGUI_P_H #define QRHIIMGUI_P_H -#include <QtGui/private/qrhi_p.h> +#include <rhi/qrhi.h> QT_BEGIN_NAMESPACE @@ -45,7 +45,12 @@ public: StaticRenderData sf; FrameRenderData f; - void prepare(QRhi *rhi, QRhiRenderTarget *rt, QRhiCommandBuffer *cb, const QMatrix4x4 &mvp, float opacity); + void prepare(QRhi *rhi, + QRhiRenderTarget *rt, + QRhiCommandBuffer *cb, + const QMatrix4x4 &mvp, + float opacity = 1.0f, + float hdrWhiteLevelMultiplierOrZeroForSDRsRGB = 0.0f); void render(); void releaseResources(); diff --git a/tests/manual/rhi/shared/texture.frag.qsb b/tests/manual/rhi/shared/texture.frag.qsb Binary files differindex b535db90a5..fc1896df76 100644 --- a/tests/manual/rhi/shared/texture.frag.qsb +++ b/tests/manual/rhi/shared/texture.frag.qsb diff --git a/tests/manual/rhi/shared/texture.vert.qsb b/tests/manual/rhi/shared/texture.vert.qsb Binary files differindex f09ed73ef8..40ac8a0691 100644 --- a/tests/manual/rhi/shared/texture.vert.qsb +++ b/tests/manual/rhi/shared/texture.vert.qsb diff --git a/tests/manual/rhi/shared/texture_arr.frag.qsb b/tests/manual/rhi/shared/texture_arr.frag.qsb Binary files differindex 3674fdad1d..7229c9f5fc 100644 --- a/tests/manual/rhi/shared/texture_arr.frag.qsb +++ b/tests/manual/rhi/shared/texture_arr.frag.qsb diff --git a/tests/manual/rhi/shared/texture_arr.vert.qsb b/tests/manual/rhi/shared/texture_arr.vert.qsb Binary files differindex fe46d2c385..fd34dcaf51 100644 --- a/tests/manual/rhi/shared/texture_arr.vert.qsb +++ b/tests/manual/rhi/shared/texture_arr.vert.qsb diff --git a/tests/manual/rhi/shared/texture_ms4.frag.qsb b/tests/manual/rhi/shared/texture_ms4.frag.qsb Binary files differindex 4080308652..896df41645 100644 --- a/tests/manual/rhi/shared/texture_ms4.frag.qsb +++ b/tests/manual/rhi/shared/texture_ms4.frag.qsb |