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