Commit d500b540 authored by Laszlo Agocs's avatar Laszlo Agocs

Make the QRhi available in the backends

...in order to reduce code duplication.
parent cf2c1d95
......@@ -2658,10 +2658,10 @@ QRhi *QRhi::create(Implementation impl, QRhiInitParams *params, Flags flags, QRh
}
if (r->d) {
r->d->q = r.data();
if (flags.testFlag(EnableProfiling)) {
QRhiProfilerPrivate *profD = QRhiProfilerPrivate::get(&r->d->profiler);
profD->rhi = r.data();
profD->rhiD = r->d;
profD->rhiDWhenEnabled = r->d;
}
r->d->debugMarkers = flags.testFlag(EnableDebugMarkers);
if (r->d->create(flags))
......
......@@ -150,10 +150,13 @@ public:
QRhiProfilerPrivate *profilerPrivateOrNull()
{
// return null when QRhi::EnableProfiling was not set
QRhiProfilerPrivate *p = QRhiProfilerPrivate::get(&profiler);
return p->rhi ? p : nullptr;
return p->rhiDWhenEnabled ? p : nullptr;
}
QRhi *q;
protected:
QVector<QRhiResourceUpdateBatch *> resUpdPool;
QBitArray resUpdPoolMap;
......
......@@ -1063,13 +1063,8 @@ void QRhiD3D11::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate
cmd.args.updateSubRes.dstBox = box;
cmd.args.updateSubRes.srcRowPitch = bpl;
} else if (!mipDesc.compressedData().isEmpty() && isCompressedFormat(texD->m_format)) {
QSize size;
if (mipDesc.sourceSize().isEmpty()) {
size.setWidth(qFloor(float(qMax(1, texD->m_pixelSize.width() >> level))));
size.setHeight(qFloor(float(qMax(1, texD->m_pixelSize.height() >> level))));
} else {
size = mipDesc.sourceSize();
}
const QSize size = mipDesc.sourceSize().isEmpty() ? q->sizeForMipLevel(level, texD->m_pixelSize)
: mipDesc.sourceSize();
quint32 bpl = 0;
QSize blockDim;
compressedFormatInfo(texD->m_format, size, &bpl, nullptr, &blockDim);
......@@ -1140,11 +1135,7 @@ void QRhiD3D11::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate
}
src = texD->tex;
dxgiFormat = texD->dxgiFormat;
pixelSize = texD->m_pixelSize;
if (u.rb.level() > 0) {
pixelSize.setWidth(qFloor(float(qMax(1, pixelSize.width() >> u.rb.level()))));
pixelSize.setHeight(qFloor(float(qMax(1, pixelSize.height() >> u.rb.level()))));
}
pixelSize = u.rb.level() > 0 ? q->sizeForMipLevel(u.rb.level(), texD->m_pixelSize) : texD->m_pixelSize;
format = texD->m_format;
subres = D3D11CalcSubresource(u.rb.level(), u.rb.layer(), texD->mipLevelCount);
} else {
......@@ -1925,7 +1916,7 @@ bool QD3D11Texture::prepareBuild(QSize *adjustedSize)
const bool hasMipMaps = m_flags.testFlag(MipMapped);
dxgiFormat = toD3DTextureFormat(m_format, m_flags);
mipLevelCount = hasMipMaps ? qCeil(log2(qMax(size.width(), size.height()))) + 1 : 1;
mipLevelCount = hasMipMaps ? rhiD->q->mipLevelsForSize(size) : 1;
sampleDesc = rhiD->effectiveSampleCount(m_sampleCount);
if (sampleDesc.Count > 1) {
if (isCube) {
......
......@@ -857,13 +857,8 @@ void QRhiGles2::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate
const QPoint dp = mipDesc.destinationTopLeft();
const QByteArray compressedData = mipDesc.compressedData();
if (isCompressed && !compressedData.isEmpty()) {
QSize size;
if (mipDesc.sourceSize().isEmpty()) {
size.setWidth(qFloor(float(qMax(1, texD->m_pixelSize.width() >> level))));
size.setHeight(qFloor(float(qMax(1, texD->m_pixelSize.height() >> level))));
} else {
size = mipDesc.sourceSize();
}
const QSize size = mipDesc.sourceSize().isEmpty() ? q->sizeForMipLevel(level, texD->m_pixelSize)
: mipDesc.sourceSize();
if (texD->specified) {
QGles2CommandBuffer::Command cmd;
cmd.cmd = QGles2CommandBuffer::Command::CompressedSubImage;
......@@ -1925,7 +1920,7 @@ bool QGles2Texture::prepareBuild(QSize *adjustedSize)
glintformat = GL_RGBA;
glformat = GL_RGBA;
gltype = GL_UNSIGNED_BYTE;
mipLevelCount = hasMipMaps ? qCeil(log2(qMax(size.width(), size.height()))) + 1 : 1;
mipLevelCount = hasMipMaps ? rhiD->q->mipLevelsForSize(size) : 1;
if (isCompressed) {
glintformat = toGlCompressedTextureFormat(m_format, m_flags);
......@@ -1960,10 +1955,9 @@ bool QGles2Texture::build()
const GLenum faceTargetBase = isCube ? GL_TEXTURE_CUBE_MAP_POSITIVE_X : target;
for (int layer = 0, layerCount = isCube ? 6 : 1; layer != layerCount; ++layer) {
for (int level = 0; level != mipLevelCount; ++level) {
const int w = qFloor(float(qMax(1, size.width() >> level)));
const int h = qFloor(float(qMax(1, size.height() >> level)));
const QSize mipSize = rhiD->q->sizeForMipLevel(level, size);
rhiD->f->glTexImage2D(faceTargetBase + layer, level, glintformat,
w, h, 0,
mipSize.width(), mipSize.height(), 0,
glformat, gltype, nullptr);
}
}
......
......@@ -1194,8 +1194,9 @@ void QRhiMetal::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate
curOfs += aligned(fullImageSizeBytes, texbufAlign);
} else if (!compressedData.isEmpty() && isCompressedFormat(utexD->m_format)) {
const int subresw = qFloor(float(qMax(1, utexD->m_pixelSize.width() >> level)));
const int subresh = qFloor(float(qMax(1, utexD->m_pixelSize.height() >> level)));
const QSize subresSize = q->sizeForMipLevel(level, utexD->m_pixelSize);
const int subresw = subresSize.width();
const int subresh = subresSize.height();
int w, h;
if (mipDesc.sourceSize().isEmpty()) {
w = subresw;
......@@ -1282,11 +1283,8 @@ void QRhiMetal::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate
qWarning("Multisample texture cannot be read back");
continue;
}
aRb.pixelSize = texD->m_pixelSize;
if (u.rb.level() > 0) {
aRb.pixelSize.setWidth(qFloor(float(qMax(1, aRb.pixelSize.width() >> u.rb.level()))));
aRb.pixelSize.setHeight(qFloor(float(qMax(1, aRb.pixelSize.height() >> u.rb.level()))));
}
aRb.pixelSize = u.rb.level() > 0 ? q->sizeForMipLevel(u.rb.level(), texD->m_pixelSize)
: texD->m_pixelSize;
aRb.format = texD->m_format;
src = texD->d->tex;
srcSize = texD->m_pixelSize;
......@@ -1868,7 +1866,7 @@ bool QMetalTexture::prepareBuild(QSize *adjustedSize)
const bool hasMipMaps = m_flags.testFlag(MipMapped);
d->format = toMetalTextureFormat(m_format, m_flags);
mipLevelCount = hasMipMaps ? qCeil(log2(qMax(size.width(), size.height()))) + 1 : 1;
mipLevelCount = hasMipMaps ? rhiD->q->mipLevelsForSize(size) : 1;
samples = rhiD->effectiveSampleCount(m_sampleCount);
if (samples > 1) {
if (isCube) {
......
......@@ -201,8 +201,8 @@ void QRhiProfiler::setDevice(QIODevice *device)
*/
void QRhiProfiler::addVMemAllocatorStats()
{
if (d->rhiD)
d->rhiD->sendVMemStatsToProfiler();
if (d->rhiDWhenEnabled)
d->rhiDWhenEnabled->sendVMemStatsToProfiler();
}
/*!
......@@ -375,7 +375,7 @@ void QRhiProfilerPrivate::newRenderBuffer(QRhiRenderBuffer *rb, bool transientBa
const QSize sz = rb->pixelSize();
// just make up something, ds is likely D24S8 while color is RGBA8 or similar
const QRhiTexture::Format assumedFormat = type == QRhiRenderBuffer::DepthStencil ? QRhiTexture::D32 : QRhiTexture::RGBA8;
quint32 byteSize = rhiD->approxByteSizeForTexture(assumedFormat, sz, 1, 1);
quint32 byteSize = rhiDWhenEnabled->approxByteSizeForTexture(assumedFormat, sz, 1, 1);
if (sampleCount > 1)
byteSize *= sampleCount;
......@@ -406,7 +406,7 @@ void QRhiProfilerPrivate::newTexture(QRhiTexture *tex, bool owns, int mipCount,
const QRhiTexture::Format format = tex->format();
const QSize sz = tex->pixelSize();
quint32 byteSize = rhiD->approxByteSizeForTexture(format, sz, mipCount, layerCount);
quint32 byteSize = rhiDWhenEnabled->approxByteSizeForTexture(format, sz, mipCount, layerCount);
if (sampleCount > 1)
byteSize *= sampleCount;
......@@ -458,7 +458,7 @@ void QRhiProfilerPrivate::resizeSwapChain(QRhiSwapChain *sc, int bufferCount, in
return;
const QSize sz = sc->currentPixelSize();
quint32 byteSize = rhiD->approxByteSizeForTexture(QRhiTexture::BGRA8, sz, 1, 1);
quint32 byteSize = rhiDWhenEnabled->approxByteSizeForTexture(QRhiTexture::BGRA8, sz, 1, 1);
byteSize = byteSize * bufferCount + byteSize * msaaBufferCount * sampleCount;
startEntry(QRhiProfiler::ResizeSwapChain, ts.elapsed(), sc);
......
......@@ -83,8 +83,7 @@ public:
void writeFloat(const char *key, float f);
void endEntry();
QRhi *rhi = nullptr;
QRhiImplementation *rhiD = nullptr;
QRhiImplementation *rhiDWhenEnabled = nullptr;
QIODevice *outputDevice = nullptr;
QElapsedTimer ts;
QByteArray buf;
......
......@@ -2403,9 +2403,9 @@ void QRhiVulkan::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdat
imageSizeBytes = compressedData.size();
if (imageSizeBytes > 0) {
src = compressedData.constData();
const int subresw = qFloor(float(qMax(1, utexD->m_pixelSize.width() >> level)));
const int subresh = qFloor(float(qMax(1, utexD->m_pixelSize.height() >> level)));
QSize size(subresw, subresh);
QSize size = q->sizeForMipLevel(level, utexD->m_pixelSize);
const int subresw = size.width();
const int subresh = size.height();
if (!mipDesc.sourceSize().isEmpty())
size = mipDesc.sourceSize();
const int w = size.width();
......@@ -2508,11 +2508,8 @@ void QRhiVulkan::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdat
qWarning("Multisample texture cannot be read back");
continue;
}
aRb.pixelSize = texD->m_pixelSize;
if (u.rb.level() > 0) {
aRb.pixelSize.setWidth(qFloor(float(qMax(1, aRb.pixelSize.width() >> u.rb.level()))));
aRb.pixelSize.setHeight(qFloor(float(qMax(1, aRb.pixelSize.height() >> u.rb.level()))));
}
aRb.pixelSize = u.rb.level() > 0 ? q->sizeForMipLevel(u.rb.level(), texD->m_pixelSize)
: texD->m_pixelSize;
aRb.format = texD->m_format;
} else {
Q_ASSERT(currentSwapChain);
......@@ -3862,7 +3859,7 @@ bool QVkTexture::prepareBuild(QSize *adjustedSize)
const bool isCube = m_flags.testFlag(CubeMap);
const bool hasMipMaps = m_flags.testFlag(MipMapped);
mipLevelCount = hasMipMaps ? qCeil(log2(qMax(size.width(), size.height()))) + 1 : 1;
mipLevelCount = hasMipMaps ? rhiD->q->mipLevelsForSize(size) : 1;
samples = rhiD->effectiveSampleCount(m_sampleCount);
if (samples > VK_SAMPLE_COUNT_1_BIT) {
if (isCube) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment