Commit 2f1a7a80 authored by Laszlo Agocs's avatar Laszlo Agocs

Prepare for providing raw float data in tex.uploads

parent 69e66609
......@@ -1333,18 +1333,20 @@ QRhiTextureRenderTargetDescription::QRhiTextureRenderTargetDescription(const QRh
\brief Describes one mip level in a layer in a texture upload operation.
The source content is specified either as a QImage or as a raw blob. The
former is only allowed for uncompressed textures, while the latter is only
supported for compressed ones.
former is only allowed for uncompressed textures with a format that can be
mapped to QImage, while the latter is only supported for floating point and
compressed textures.
\note image() and compressedData() cannot be both set at the same time.
\note image() and data() cannot be both set at the same time.
destinationTopLeft() specifies the top-left corner of the target
rectangle. Defaults to (0, 0).
An empty sourceSize() (the default) indicates that size is assumed to be
the size of the subresource. For uncompressed textures this implies that
the size of the source image() must match the subresource. For compressed
textures sufficient amount of data must be provided in compressedData().
the size of the source image() must match the subresource. For floating
point and compressed textures sufficient amount of data must be provided in
data().
\note With compressed textures the first upload must always match the
subresource size due to graphics API limitations with some backends.
......@@ -1381,11 +1383,12 @@ QRhiTextureMipLevel::QRhiTextureMipLevel(const QImage &image)
}
/*!
Constructs a mip level description suitable for compressed textures. The
compressed data is specified in \a compressedData.
Constructs a mip level description suitable for textures with a format that
does not map to QImage. The floating point or compressed data is specified
in \a data.
*/
QRhiTextureMipLevel::QRhiTextureMipLevel(const QByteArray &compressedData)
: m_compressedData(compressedData)
QRhiTextureMipLevel::QRhiTextureMipLevel(const QByteArray &data)
: m_data(data)
{
}
......
......@@ -432,13 +432,13 @@ class Q_RHI_EXPORT QRhiTextureMipLevel
public:
QRhiTextureMipLevel();
QRhiTextureMipLevel(const QImage &image);
QRhiTextureMipLevel(const QByteArray &compressedData);
QRhiTextureMipLevel(const QByteArray &data);
QImage image() const { return m_image; }
void setImage(const QImage &image) { m_image = image; }
QByteArray compressedData() const { return m_compressedData; }
void setCompressedData(const QByteArray &data) { m_compressedData = data; }
QByteArray data() const { return m_data; }
void setData(const QByteArray &data) { m_data = data; }
QPoint destinationTopLeft() const { return m_destinationTopLeft; }
void setDestinationTopLeft(const QPoint &p) { m_destinationTopLeft = p; }
......@@ -451,7 +451,7 @@ public:
private:
QImage m_image;
QByteArray m_compressedData;
QByteArray m_data;
QPoint m_destinationTopLeft;
QSize m_sourceSize;
QPoint m_sourceTopLeft;
......
......@@ -1079,7 +1079,7 @@ void QRhiD3D11::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate
cmd.args.updateSubRes.hasDstBox = true;
cmd.args.updateSubRes.dstBox = box;
cmd.args.updateSubRes.srcRowPitch = bpl;
} else if (!mipDesc.compressedData().isEmpty() && isCompressedFormat(texD->m_format)) {
} else if (!mipDesc.data().isEmpty() && isCompressedFormat(texD->m_format)) {
const QSize size = mipDesc.sourceSize().isEmpty() ? q->sizeForMipLevel(level, texD->m_pixelSize)
: mipDesc.sourceSize();
quint32 bpl = 0;
......@@ -1094,7 +1094,7 @@ void QRhiD3D11::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate
box.bottom = aligned(dp.y() + size.height(), blockDim.height());
cmd.args.updateSubRes.hasDstBox = true;
cmd.args.updateSubRes.dstBox = box;
cmd.args.updateSubRes.src = cbD->retainData(mipDesc.compressedData());
cmd.args.updateSubRes.src = cbD->retainData(mipDesc.data());
cmd.args.updateSubRes.srcRowPitch = bpl;
}
cbD->commands.append(cmd);
......
......@@ -950,8 +950,8 @@ void QRhiGles2::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate
for (int level = 0, levelCount = mipImages.count(); level != levelCount; ++level) {
const QRhiTextureMipLevel &mipDesc(mipImages[level]);
const QPoint dp = mipDesc.destinationTopLeft();
const QByteArray compressedData = mipDesc.compressedData();
if (isCompressed && !compressedData.isEmpty()) {
const QByteArray rawData = mipDesc.data();
if (isCompressed && !rawData.isEmpty()) {
const QSize size = mipDesc.sourceSize().isEmpty() ? q->sizeForMipLevel(level, texD->m_pixelSize)
: mipDesc.sourceSize();
if (texD->specified) {
......@@ -966,8 +966,8 @@ void QRhiGles2::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate
cmd.args.compressedSubImage.w = size.width();
cmd.args.compressedSubImage.h = size.height();
cmd.args.compressedSubImage.glintformat = texD->glintformat;
cmd.args.compressedSubImage.size = compressedData.size();
cmd.args.compressedSubImage.data = cbD->retainData(compressedData);
cmd.args.compressedSubImage.size = rawData.size();
cmd.args.compressedSubImage.data = cbD->retainData(rawData);
cbD->commands.append(cmd);
} else {
QGles2CommandBuffer::Command cmd;
......@@ -979,8 +979,8 @@ void QRhiGles2::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate
cmd.args.compressedImage.glintformat = texD->glintformat;
cmd.args.compressedImage.w = size.width();
cmd.args.compressedImage.h = size.height();
cmd.args.compressedImage.size = compressedData.size();
cmd.args.compressedImage.data = cbD->retainData(compressedData);
cmd.args.compressedImage.size = rawData.size();
cmd.args.compressedImage.data = cbD->retainData(rawData);
cbD->commands.append(cmd);
}
} else {
......
......@@ -1197,7 +1197,7 @@ void QRhiMetal::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate
for (int level = 0, levelCount = mipImages.count(); level != levelCount; ++level) {
const QRhiTextureMipLevel &mipDesc(mipImages[level]);
const qsizetype imageSizeBytes = mipDesc.image().isNull() ?
mipDesc.compressedData().size() : mipDesc.image().sizeInBytes();
mipDesc.data().size() : mipDesc.image().sizeInBytes();
if (imageSizeBytes > 0)
stagingSize += aligned(imageSizeBytes, texbufAlign);
}
......@@ -1218,7 +1218,7 @@ void QRhiMetal::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate
for (int level = 0, levelCount = mipImages.count(); level != levelCount; ++level) {
const QRhiTextureMipLevel &mipDesc(mipImages[level]);
const QPoint dp = mipDesc.destinationTopLeft();
const QByteArray compressedData = mipDesc.compressedData();
const QByteArray rawData = mipDesc.data();
QImage img = mipDesc.image();
if (!img.isNull()) {
......@@ -1261,7 +1261,7 @@ void QRhiMetal::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate
options: MTLBlitOptionNone];
curOfs += aligned(fullImageSizeBytes, texbufAlign);
} else if (!compressedData.isEmpty() && isCompressedFormat(utexD->m_format)) {
} else if (!rawData.isEmpty() && isCompressedFormat(utexD->m_format)) {
const QSize subresSize = q->sizeForMipLevel(level, utexD->m_pixelSize);
const int subresw = subresSize.width();
const int subresh = subresSize.height();
......@@ -1285,7 +1285,7 @@ void QRhiMetal::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate
if (dy + h != subresh)
h = aligned(h, blockDim.height());
memcpy(reinterpret_cast<char *>(mp) + curOfs, compressedData.constData(), compressedData.size());
memcpy(reinterpret_cast<char *>(mp) + curOfs, rawData.constData(), rawData.size());
[blitEnc copyFromBuffer: utexD->d->stagingBuf[currentFrameSlot]
sourceOffset: curOfs
......@@ -1298,7 +1298,7 @@ void QRhiMetal::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate
destinationOrigin: MTLOriginMake(dx, dy, 0)
options: MTLBlitOptionNone];
curOfs += aligned(compressedData.size(), texbufAlign);
curOfs += aligned(rawData.size(), texbufAlign);
}
}
}
......
......@@ -2300,7 +2300,7 @@ void QRhiVulkan::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdat
for (int level = 0, levelCount = mipImages.count(); level != levelCount; ++level) {
const QRhiTextureMipLevel &mipDesc(mipImages[level]);
const qsizetype imageSizeBytes = mipDesc.image().isNull() ?
mipDesc.compressedData().size() : mipDesc.image().sizeInBytes();
mipDesc.data().size() : mipDesc.image().sizeInBytes();
if (imageSizeBytes > 0)
stagingSize += aligned(imageSizeBytes, texbufAlign);
}
......@@ -2357,7 +2357,7 @@ void QRhiVulkan::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdat
const QPoint dp = mipDesc.destinationTopLeft();
const QImage image = mipDesc.image();
const QByteArray compressedData = mipDesc.compressedData();
const QByteArray rawData = mipDesc.data();
if (!image.isNull()) {
copySizeBytes = imageSizeBytes = image.sizeInBytes();
QImage img = image;
......@@ -2396,9 +2396,9 @@ void QRhiVulkan::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdat
copyInfo.imageExtent.width = size.width();
copyInfo.imageExtent.height = size.height();
copyInfos.append(copyInfo);
} else if (!compressedData.isEmpty()) {
copySizeBytes = imageSizeBytes = compressedData.size();
src = compressedData.constData();
} else if (!rawData.isEmpty()) {
copySizeBytes = imageSizeBytes = rawData.size();
src = rawData.constData();
QSize size = q->sizeForMipLevel(level, utexD->m_pixelSize);
const int subresw = size.width();
const int subresh = size.height();
......
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