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
qssgrendererimplshaders_rhi.cpp
Go to the documentation of this file.
1// Copyright (C) 2008-2012 NVIDIA Corporation.
2// Copyright (C) 2019 The Qt Company Ltd.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
4
6
7#include <QtQuick3DRuntimeRender/private/qssgrenderer_p.h>
8#include <QtQuick3DRuntimeRender/private/qssgrenderlight_p.h>
10#include <QtQuick3DRuntimeRender/private/qssgrendershadercache_p.h>
11#include <QtQuick3DRuntimeRender/private/qssgrendershaderlibrarymanager_p.h>
12#include <QtQuick3DRuntimeRender/private/qssgrendershadercodegenerator_p.h>
13#include <QtQuick3DRuntimeRender/private/qssgrenderdefaultmaterialshadergenerator_p.h>
14#include <QtQuick3DRuntimeRender/private/qssgvertexpipelineimpl_p.h>
15
16// this file contains the getXxxxShader implementations suitable for the QRhi-based rendering path
17
19
20QSSGRhiShaderPipelinePtr QSSGBuiltInRhiShaderCache::getBuiltinRhiShader(const QByteArray &name,
21 BuiltinShader &storage,
22 int viewCount)
23{
24 if (storage.shaderPipeline && storage.viewCount != viewCount)
25 storage = {};
26
27 if (!storage.shaderPipeline) {
28 // loadBuiltin must always return a valid QSSGRhiShaderPipeline.
29 // There will just be no stages if loading fails.
30 storage.shaderPipeline = m_shaderCache.loadBuiltinUncached(name, viewCount);
31 storage.viewCount = viewCount;
32 }
33
34 return storage.shaderPipeline;
35}
36
41
43{
44 return getBuiltinRhiShader(QByteArrayLiteral("cubeshadowblurx"), m_cache.cubemapShadowBlurXRhiShader);
45}
46
48{
49 return getBuiltinRhiShader(QByteArrayLiteral("cubeshadowblury"), m_cache.cubemapShadowBlurYRhiShader);
50}
51
53{
54 return getBuiltinRhiShader(QByteArrayLiteral("grid"), m_cache.gridShader, viewCount);
55}
56
58{
59 return getBuiltinRhiShader(QByteArrayLiteral("orthoshadowblurx"), m_cache.orthographicShadowBlurXRhiShader);
60}
61
63{
64 return getBuiltinRhiShader(QByteArrayLiteral("orthoshadowblury"), m_cache.orthographicShadowBlurYRhiShader);
65}
66
68{
69 return getBuiltinRhiShader(QByteArrayLiteral("ssao"), m_cache.ssaoRhiShader, viewCount);
70}
71
73{
74 return getBuiltinRhiShader(QByteArrayLiteral("skyboxcube"), m_cache.skyBoxCubeRhiShader, viewCount);
75}
76
77static inline constexpr size_t getSkyboxIndex(QSSGRenderLayer::TonemapMode tonemapMode, bool isRGBE)
78{
79 switch (tonemapMode) {
81 return 0 + (size_t(isRGBE) * QSSGRenderLayer::TonemapModeCount);
83 return 1 + (size_t(isRGBE) * QSSGRenderLayer::TonemapModeCount);
85 return 2 + (size_t(isRGBE) * QSSGRenderLayer::TonemapModeCount);
87 return 3 + (size_t(isRGBE) * QSSGRenderLayer::TonemapModeCount);
89 return 4 + (size_t(isRGBE) * QSSGRenderLayer::TonemapModeCount);
91 return 5 + (size_t(isRGBE) * QSSGRenderLayer::TonemapModeCount);
92 }
93
94 Q_UNREACHABLE_RETURN(0);
95}
96
98{
99 // Skybox shader is special and has multiple possible shaders so we have to do
100 // a bit of manual work here (mapping resolved in getSkyboxIndex()).
101 static constexpr char variant[][23] { "skybox_hdr_none",
102 "skybox_hdr_linear",
103 "skybox_hdr_aces",
104 "skybox_hdr_hejldawson",
105 "skybox_hdr_filmic",
106 "skybox_hdr_custom",
107 "skybox_rgbe_none",
108 "skybox_rgbe_linear",
109 "skybox_rgbe_aces",
110 "skybox_rgbe_hejldawson",
111 "skybox_rgbe_filmic",
112 "skybox_rgbe_custom",
113 };
114
115 const size_t skyboxIndex = getSkyboxIndex(tonemapMode, isRGBE);
116 return getBuiltinRhiShader(QByteArray::fromRawData(variant[skyboxIndex], std::char_traits<char>::length(variant[skyboxIndex])), m_cache.skyBoxRhiShader[skyboxIndex], viewCount);
117}
118
120{
121 return getBuiltinRhiShader(QByteArrayLiteral("ssaaresolve"), m_cache.supersampleResolveRhiShader, viewCount);
122}
123
125{
126 return getBuiltinRhiShader(QByteArrayLiteral("progressiveaa"), m_cache.progressiveAARhiShader);
127}
128
130{
131 switch (featureLevel) {
133 return getBuiltinRhiShader(QByteArrayLiteral("particlesnolightsimple"), m_cache.particlesNoLightingSimpleRhiShader, viewCount);
134 break;
136 return getBuiltinRhiShader(QByteArrayLiteral("particlesnolightmapped"), m_cache.particlesNoLightingMappedRhiShader, viewCount);
137 break;
139 return getBuiltinRhiShader(QByteArrayLiteral("particlesnolightanimated"), m_cache.particlesNoLightingAnimatedRhiShader, viewCount);
140 break;
142 return getBuiltinRhiShader(QByteArrayLiteral("particlesvlightsimple"), m_cache.particlesVLightingSimpleRhiShader, viewCount);
143 break;
145 return getBuiltinRhiShader(QByteArrayLiteral("particlesvlightmapped"), m_cache.particlesVLightingMappedRhiShader, viewCount);
146 break;
148 return getBuiltinRhiShader(QByteArrayLiteral("particlesvlightanimated"), m_cache.particlesVLightingAnimatedRhiShader, viewCount);
149 break;
151 return getBuiltinRhiShader(QByteArrayLiteral("lineparticles"), m_cache.lineParticlesRhiShader, viewCount);
152 break;
154 return getBuiltinRhiShader(QByteArrayLiteral("lineparticlesmapped"), m_cache.lineParticlesMappedRhiShader, viewCount);
155 break;
157 return getBuiltinRhiShader(QByteArrayLiteral("lineparticlesanimated"), m_cache.lineParticlesAnimatedRhiShader, viewCount);
158 break;
160 return getBuiltinRhiShader(QByteArrayLiteral("lineparticlesvlightsimple"), m_cache.lineParticlesVLightRhiShader, viewCount);
161 break;
163 return getBuiltinRhiShader(QByteArrayLiteral("lineparticlesvlightmapped"), m_cache.lineParticlesMappedVLightRhiShader, viewCount);
164 break;
166 return getBuiltinRhiShader(QByteArrayLiteral("lineparticlesvlightanimated"), m_cache.lineParticlesAnimatedVLightRhiShader, viewCount);
167 break;
168 }
169 return getBuiltinRhiShader(QByteArrayLiteral("particlesnolightanimated"), m_cache.particlesNoLightingAnimatedRhiShader, viewCount);
170}
171
173{
174 return getBuiltinRhiShader(QByteArrayLiteral("simplequad"), m_cache.simpleQuadRhiShader, viewCount);
175}
176
178{
179 switch (mode) {
181 return getBuiltinRhiShader(QByteArrayLiteral("lightmapuvraster_uv"), m_cache.lightmapUVRasterShader_uv);
183 return getBuiltinRhiShader(QByteArrayLiteral("lightmapuvraster_uv_tangent"), m_cache.lightmapUVRasterShader_uv_tangent);
185 return getBuiltinRhiShader(QByteArrayLiteral("lightmapuvraster"), m_cache.lightmapUVRasterShader);
186 }
187
188 Q_UNREACHABLE_RETURN(getBuiltinRhiShader(QByteArrayLiteral("lightmapuvraster"), m_cache.lightmapUVRasterShader));
189}
190
192{
193 return getBuiltinRhiShader(QByteArrayLiteral("lightmapdilate"), m_cache.lightmapDilateShader);
194}
195
197{
198 return getBuiltinRhiShader(QByteArrayLiteral("debugobject"), m_cache.debugObjectShader);
199}
200
202{
203 return getBuiltinRhiShader(QByteArrayLiteral("reflectionprobeprefilter"), m_cache.reflectionprobePreFilterShader);
204}
205
207{
208 static constexpr char variant[][29] { "environmentmapprefilter", "environmentmapprefilter_rgbe" };
209 const quint8 idx = quint8(isRGBE);
210 return getBuiltinRhiShader(QByteArray::fromRawData(variant[idx], std::char_traits<char>::length(variant[idx])), m_cache.environmentmapPreFilterShader[idx]);
211}
212
214{
215 return getBuiltinRhiShader(QByteArrayLiteral("environmentmap"), m_cache.environmentmapShader);
216}
217
\inmodule QtCore
Definition qbytearray.h:57
static QByteArray fromRawData(const char *data, qsizetype size)
Constructs a QByteArray that uses the first size bytes of the data array.
Definition qbytearray.h:409
QSSGRhiShaderPipelinePtr getRhiOrthographicShadowBlurXShader()
QSSGRhiShaderPipelinePtr getRhiSkyBoxCubeShader(int viewCount)
QSSGRhiShaderPipelinePtr getRhiParticleShader(QSSGRenderParticles::FeatureLevel featureLevel, int viewCount)
QSSGRhiShaderPipelinePtr getRhiOrthographicShadowBlurYShader()
QSSGRhiShaderPipelinePtr getRhiCubemapShadowBlurXShader()
QSSGRhiShaderPipelinePtr getRhiSsaoShader(int viewCount)
QSSGRhiShaderPipelinePtr getRhiSimpleQuadShader(int viewCount)
QSSGRhiShaderPipelinePtr getRhiReflectionprobePreFilterShader()
QSSGRhiShaderPipelinePtr getRhiProgressiveAAShader()
QSSGRhiShaderPipelinePtr getRhiEnvironmentmapShader()
QSSGRhiShaderPipelinePtr getRhienvironmentmapPreFilterShader(bool isRGBE)
QSSGRhiShaderPipelinePtr getRhiSupersampleResolveShader(int viewCount)
QSSGRhiShaderPipelinePtr getRhiLightmapUVRasterizationShader(LightmapUVRasterizationShaderMode mode)
QSSGRhiShaderPipelinePtr getRhiLightmapDilateShader()
QSSGRhiShaderPipelinePtr getRhiDebugObjectShader()
QSSGRhiShaderPipelinePtr getRhiGridShader(int viewCount)
QSSGRhiShaderPipelinePtr getRhiSkyBoxShader(QSSGRenderLayer::TonemapMode tonemapMode, bool isRGBE, int viewCount)
QSSGRhiShaderPipelinePtr getRhiCubemapShadowBlurYShader()
Combined button and popup list for selecting options.
#define QByteArrayLiteral(str)
Definition qbytearray.h:52
GLenum mode
GLuint name
static constexpr size_t getSkyboxIndex(QSSGRenderLayer::TonemapMode tonemapMode, bool isRGBE)
std::shared_ptr< QSSGRhiShaderPipeline > QSSGRhiShaderPipelinePtr
unsigned char quint8
Definition qtypes.h:46
QStorageInfo storage
[1]
QVariant variant
[1]
static size_t constexpr TonemapModeCount