rhi: Returns mapping tables by value from QShader
As these are QList and QHash. All existing usages are based on this anyway, no value in being able to indicate "not available" - an empty container fulfills the same role. Change-Id: I8059025fa7a4acb6fc674cd98b16fcafa19ed85d Reviewed-by: Andy Nichols <andy.nichols@qt.io>bb10
parent
521fea9169
commit
7cbac745dc
|
|
@ -4156,8 +4156,7 @@ bool QD3D11GraphicsPipeline::create()
|
|||
return false;
|
||||
}
|
||||
vsByteCode = bytecode;
|
||||
if (const QShader::NativeResourceBindingMap *map = shaderStage.shader().nativeResourceBindingMap(shaderKey))
|
||||
vs.nativeResourceBindingMap = *map;
|
||||
vs.nativeResourceBindingMap = shaderStage.shader().nativeResourceBindingMap(shaderKey);
|
||||
rhiD->m_shaderCache.insert(shaderStage, QRhiD3D11::Shader(vs.shader, bytecode, vs.nativeResourceBindingMap));
|
||||
vs.shader->AddRef();
|
||||
break;
|
||||
|
|
@ -4167,8 +4166,7 @@ bool QD3D11GraphicsPipeline::create()
|
|||
qWarning("Failed to create pixel shader: %s", qPrintable(comErrorMessage(hr)));
|
||||
return false;
|
||||
}
|
||||
if (const QShader::NativeResourceBindingMap *map = shaderStage.shader().nativeResourceBindingMap(shaderKey))
|
||||
fs.nativeResourceBindingMap = *map;
|
||||
fs.nativeResourceBindingMap = shaderStage.shader().nativeResourceBindingMap(shaderKey);
|
||||
rhiD->m_shaderCache.insert(shaderStage, QRhiD3D11::Shader(fs.shader, bytecode, fs.nativeResourceBindingMap));
|
||||
fs.shader->AddRef();
|
||||
break;
|
||||
|
|
@ -4286,8 +4284,7 @@ bool QD3D11ComputePipeline::create()
|
|||
return false;
|
||||
}
|
||||
|
||||
if (const QShader::NativeResourceBindingMap *map = m_shaderStage.shader().nativeResourceBindingMap(shaderKey))
|
||||
cs.nativeResourceBindingMap = *map;
|
||||
cs.nativeResourceBindingMap = m_shaderStage.shader().nativeResourceBindingMap(shaderKey);
|
||||
|
||||
if (rhiD->m_shaderCache.count() >= QRhiD3D11::MAX_SHADER_CACHE_ENTRIES)
|
||||
rhiD->clearShaderCache();
|
||||
|
|
|
|||
|
|
@ -5341,14 +5341,14 @@ bool QGles2GraphicsPipeline::create()
|
|||
if (shaderStage.type() == QRhiShaderStage::Vertex) {
|
||||
vsDesc = shader.description();
|
||||
if (!rhiD->shaderSource(shaderStage, &glslVersion).isEmpty()) {
|
||||
if (auto *m = shader.separateToCombinedImageSamplerMappingList({ QShader::GlslShader, glslVersion, shaderStage.shaderVariant() }))
|
||||
vsSamplerMappingList = *m;
|
||||
vsSamplerMappingList = shader.separateToCombinedImageSamplerMappingList(
|
||||
{ QShader::GlslShader, glslVersion, shaderStage.shaderVariant() });
|
||||
}
|
||||
} else if (shaderStage.type() == QRhiShaderStage::Fragment) {
|
||||
fsDesc = shader.description();
|
||||
if (!rhiD->shaderSource(shaderStage, &glslVersion).isEmpty()) {
|
||||
if (auto *m = shader.separateToCombinedImageSamplerMappingList({ QShader::GlslShader, glslVersion, shaderStage.shaderVariant() }))
|
||||
fsSamplerMappingList = *m;
|
||||
fsSamplerMappingList = shader.separateToCombinedImageSamplerMappingList(
|
||||
{ QShader::GlslShader, glslVersion, shaderStage.shaderVariant() });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -5484,8 +5484,8 @@ bool QGles2ComputePipeline::create()
|
|||
QShader::SeparateToCombinedImageSamplerMappingList csSamplerMappingList;
|
||||
int glslVersion = 0;
|
||||
if (!rhiD->shaderSource(m_shaderStage, &glslVersion).isEmpty()) {
|
||||
if (auto *m = m_shaderStage.shader().separateToCombinedImageSamplerMappingList({ QShader::GlslShader, glslVersion, m_shaderStage.shaderVariant() }))
|
||||
csSamplerMappingList = *m;
|
||||
csSamplerMappingList = m_shaderStage.shader().separateToCombinedImageSamplerMappingList(
|
||||
{ QShader::GlslShader, glslVersion, m_shaderStage.shaderVariant() });
|
||||
}
|
||||
|
||||
program = rhiD->f->glCreateProgram();
|
||||
|
|
|
|||
|
|
@ -3642,8 +3642,7 @@ bool QMetalGraphicsPipeline::create()
|
|||
case QRhiShaderStage::Vertex:
|
||||
d->vs.lib = lib;
|
||||
d->vs.func = func;
|
||||
if (const QShader::NativeResourceBindingMap *map = shader.nativeResourceBindingMap(activeKey))
|
||||
d->vs.nativeResourceBindingMap = *map;
|
||||
d->vs.nativeResourceBindingMap = shader.nativeResourceBindingMap(activeKey);
|
||||
rhiD->d->shaderCache.insert(shaderStage, d->vs);
|
||||
[d->vs.lib retain];
|
||||
[d->vs.func retain];
|
||||
|
|
@ -3652,8 +3651,7 @@ bool QMetalGraphicsPipeline::create()
|
|||
case QRhiShaderStage::Fragment:
|
||||
d->fs.lib = lib;
|
||||
d->fs.func = func;
|
||||
if (const QShader::NativeResourceBindingMap *map = shader.nativeResourceBindingMap(activeKey))
|
||||
d->fs.nativeResourceBindingMap = *map;
|
||||
d->fs.nativeResourceBindingMap = shader.nativeResourceBindingMap(activeKey);
|
||||
rhiD->d->shaderCache.insert(shaderStage, d->fs);
|
||||
[d->fs.lib retain];
|
||||
[d->fs.func retain];
|
||||
|
|
@ -3810,8 +3808,7 @@ bool QMetalComputePipeline::create()
|
|||
d->cs.lib = lib;
|
||||
d->cs.func = func;
|
||||
d->cs.localSize = shader.description().computeShaderLocalSize();
|
||||
if (const QShader::NativeResourceBindingMap *map = shader.nativeResourceBindingMap(activeKey))
|
||||
d->cs.nativeResourceBindingMap = *map;
|
||||
d->cs.nativeResourceBindingMap = shader.nativeResourceBindingMap(activeKey);
|
||||
|
||||
if (rhiD->d->shaderCache.count() >= QRhiMetal::MAX_SHADER_CACHE_ENTRIES) {
|
||||
for (QMetalShader &s : rhiD->d->shaderCache)
|
||||
|
|
|
|||
|
|
@ -742,16 +742,17 @@ QDebug operator<<(QDebug dbg, const QShaderVersion &v)
|
|||
*/
|
||||
|
||||
/*!
|
||||
\return the native binding map for \a key or null if no extra mapping is
|
||||
available, or is not applicable.
|
||||
\return the native binding map for \a key. The map is empty if no mapping
|
||||
is available for \a key (for example, because the map is not applicable for
|
||||
the API and shading language described by \a key).
|
||||
*/
|
||||
const QShader::NativeResourceBindingMap *QShader::nativeResourceBindingMap(const QShaderKey &key) const
|
||||
QShader::NativeResourceBindingMap QShader::nativeResourceBindingMap(const QShaderKey &key) const
|
||||
{
|
||||
auto it = d->bindings.constFind(key);
|
||||
if (it == d->bindings.cend())
|
||||
return nullptr;
|
||||
return {};
|
||||
|
||||
return &it.value();
|
||||
return it.value();
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -798,17 +799,17 @@ void QShader::removeResourceBindingMap(const QShaderKey &key)
|
|||
*/
|
||||
|
||||
/*!
|
||||
\return the combined image sampler mapping list for \a key or null if there
|
||||
is no data available for \a key, for example because such a mapping is not
|
||||
applicable for the shading language.
|
||||
\return the combined image sampler mapping list for \a key, or an empty
|
||||
list if there is no data available for \a key, for example because such a
|
||||
mapping is not applicable for the shading language.
|
||||
*/
|
||||
const QShader::SeparateToCombinedImageSamplerMappingList *QShader::separateToCombinedImageSamplerMappingList(const QShaderKey &key) const
|
||||
QShader::SeparateToCombinedImageSamplerMappingList QShader::separateToCombinedImageSamplerMappingList(const QShaderKey &key) const
|
||||
{
|
||||
auto it = d->combinedImageMap.constFind(key);
|
||||
if (it == d->combinedImageMap.cend())
|
||||
return nullptr;
|
||||
return {};
|
||||
|
||||
return &it.value();
|
||||
return it.value();
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
|
|||
|
|
@ -163,7 +163,7 @@ public:
|
|||
static QShader fromSerialized(const QByteArray &data);
|
||||
|
||||
using NativeResourceBindingMap = QHash<int, QPair<int, int> >; // binding -> native_binding[, native_binding]
|
||||
const NativeResourceBindingMap *nativeResourceBindingMap(const QShaderKey &key) const;
|
||||
NativeResourceBindingMap nativeResourceBindingMap(const QShaderKey &key) const;
|
||||
void setResourceBindingMap(const QShaderKey &key, const NativeResourceBindingMap &map);
|
||||
void removeResourceBindingMap(const QShaderKey &key);
|
||||
|
||||
|
|
@ -173,7 +173,7 @@ public:
|
|||
int samplerBinding;
|
||||
};
|
||||
using SeparateToCombinedImageSamplerMappingList = QList<SeparateToCombinedImageSamplerMapping>;
|
||||
const SeparateToCombinedImageSamplerMappingList *separateToCombinedImageSamplerMappingList(const QShaderKey &key) const;
|
||||
SeparateToCombinedImageSamplerMappingList separateToCombinedImageSamplerMappingList(const QShaderKey &key) const;
|
||||
void setSeparateToCombinedImageSamplerMappingList(const QShaderKey &key,
|
||||
const SeparateToCombinedImageSamplerMappingList &list);
|
||||
void removeSeparateToCombinedImageSamplerMappingList(const QShaderKey &key);
|
||||
|
|
|
|||
|
|
@ -279,19 +279,19 @@ void tst_QShader::mslResourceMapping()
|
|||
QVERIFY(availableShaders.contains(QShaderKey(QShader::GlslShader, QShaderVersion(150))));
|
||||
QVERIFY(availableShaders.contains(QShaderKey(QShader::GlslShader, QShaderVersion(330))));
|
||||
|
||||
const QShader::NativeResourceBindingMap *resMap =
|
||||
QShader::NativeResourceBindingMap resMap =
|
||||
s.nativeResourceBindingMap(QShaderKey(QShader::GlslShader, QShaderVersion(330)));
|
||||
QVERIFY(!resMap);
|
||||
QVERIFY(resMap.isEmpty());
|
||||
|
||||
// The Metal shader must come with a mapping table for binding points 0
|
||||
// (uniform buffer) and 1 (combined image sampler mapped to a texture and
|
||||
// sampler in the shader).
|
||||
resMap = s.nativeResourceBindingMap(QShaderKey(QShader::MslShader, QShaderVersion(12)));
|
||||
QVERIFY(resMap);
|
||||
QVERIFY(!resMap.isEmpty());
|
||||
|
||||
QCOMPARE(resMap->count(), 2);
|
||||
QCOMPARE(resMap->value(0).first, 0); // mapped to native buffer index 0
|
||||
QCOMPARE(resMap->value(1), qMakePair(0, 0)); // mapped to native texture index 0 and sampler index 0
|
||||
QCOMPARE(resMap.count(), 2);
|
||||
QCOMPARE(resMap.value(0).first, 0); // mapped to native buffer index 0
|
||||
QCOMPARE(resMap.value(1), qMakePair(0, 0)); // mapped to native texture index 0 and sampler index 0
|
||||
}
|
||||
|
||||
void tst_QShader::serializeShaderDesc()
|
||||
|
|
@ -586,13 +586,13 @@ void tst_QShader::loadV6WithSeparateImagesAndSamplers()
|
|||
QVERIFY(availableShaders.contains(QShaderKey(QShader::GlslShader, QShaderVersion(120))));
|
||||
QVERIFY(availableShaders.contains(QShaderKey(QShader::GlslShader, QShaderVersion(150))));
|
||||
|
||||
const QShader::NativeResourceBindingMap *resMap =
|
||||
QShader::NativeResourceBindingMap resMap =
|
||||
s.nativeResourceBindingMap(QShaderKey(QShader::HlslShader, QShaderVersion(50)));
|
||||
QVERIFY(resMap && resMap->count() == 4);
|
||||
QVERIFY(!s.separateToCombinedImageSamplerMappingList(QShaderKey(QShader::HlslShader, QShaderVersion(50))));
|
||||
QVERIFY(resMap.count() == 4);
|
||||
QVERIFY(s.separateToCombinedImageSamplerMappingList(QShaderKey(QShader::HlslShader, QShaderVersion(50))).isEmpty());
|
||||
resMap = s.nativeResourceBindingMap(QShaderKey(QShader::MslShader, QShaderVersion(12)));
|
||||
QVERIFY(resMap && resMap->count() == 4);
|
||||
QVERIFY(!s.separateToCombinedImageSamplerMappingList(QShaderKey(QShader::MslShader, QShaderVersion(12))));
|
||||
QVERIFY(resMap.count() == 4);
|
||||
QVERIFY(s.separateToCombinedImageSamplerMappingList(QShaderKey(QShader::MslShader, QShaderVersion(12))).isEmpty());
|
||||
|
||||
for (auto key : {
|
||||
QShaderKey(QShader::GlslShader, QShaderVersion(100, QShaderVersion::GlslEs)),
|
||||
|
|
@ -600,8 +600,7 @@ void tst_QShader::loadV6WithSeparateImagesAndSamplers()
|
|||
QShaderKey(QShader::GlslShader, QShaderVersion(150)) })
|
||||
{
|
||||
auto list = s.separateToCombinedImageSamplerMappingList(key);
|
||||
QVERIFY(list);
|
||||
QCOMPARE(list->count(), 2);
|
||||
QCOMPARE(list.count(), 2);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue