Commit e1639302 authored by Laszlo Agocs's avatar Laszlo Agocs

d3d: add float texture upload, with example

parent 2f1a7a80
This diff is collapsed.
TEMPLATE = app
QT += rhi
SOURCES = \
floattexture.cpp
RESOURCES = floattexture.qrc
target.path = $$[QT_INSTALL_EXAMPLES]/rhi/floattexture
INSTALLS += target
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file alias="texture.vert.qsb">../shared/texture.vert.qsb</file>
<file alias="texture.frag.qsb">../shared/texture.frag.qsb</file>
<file alias="OpenfootageNET_fieldairport-512.hdr">../shared/OpenfootageNET_fieldairport-512.hdr</file>
</qresource>
</RCC>
......@@ -12,7 +12,8 @@ SUBDIRS += \
multiwindow_threaded \
imguidemo \
triquadcube \
offscreen
offscreen \
floattexture
qtConfig(vulkan) {
SUBDIRS += \
......
......@@ -1351,8 +1351,8 @@ QRhiTextureRenderTargetDescription::QRhiTextureRenderTargetDescription(const QRh
\note With compressed textures the first upload must always match the
subresource size due to graphics API limitations with some backends.
sourceTopLeft() is is only supported for uncompressed textures, and
specifies the top-left corner of the source rectangle.
sourceTopLeft() is supported only for uncompressed, non-floating point
textures, and specifies the top-left corner of the source rectangle.
\note Setting sourceSize() or sourceTopLeft() may trigger a QImage copy
internally, depending on the format and the backend.
......@@ -3093,6 +3093,11 @@ bool QRhiImplementation::isCompressedFormat(QRhiTexture::Format format) const
|| (format >= QRhiTexture::ASTC_4x4 && format <= QRhiTexture::ASTC_12x12);
}
bool QRhiImplementation::isFloatFormat(QRhiTexture::Format format) const
{
return format == QRhiTexture::RGBA16F || format == QRhiTexture::RGBA32F;
}
void QRhiImplementation::compressedFormatInfo(QRhiTexture::Format format, const QSize &size,
quint32 *bpl, quint32 *byteSize,
QSize *blockDim) const
......
......@@ -142,6 +142,7 @@ public:
void compressedFormatInfo(QRhiTexture::Format format, const QSize &size,
quint32 *bpl, quint32 *byteSize,
QSize *blockDim) const;
bool isFloatFormat(QRhiTexture::Format format) const;
void textureFormatInfo(QRhiTexture::Format format, const QSize &size,
quint32 *bpl, quint32 *byteSize) const;
quint32 approxByteSizeForTexture(QRhiTexture::Format format, const QSize &baseSize,
......
......@@ -1053,6 +1053,7 @@ void QRhiD3D11::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate
cmd.args.updateSubRes.dst = texD->tex;
cmd.args.updateSubRes.dstSubRes = subres;
bool cmdValid = true;
if (!mipDesc.image().isNull()) {
QImage img = mipDesc.image();
QSize size = img.size();
......@@ -1096,8 +1097,26 @@ void QRhiD3D11::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate
cmd.args.updateSubRes.dstBox = box;
cmd.args.updateSubRes.src = cbD->retainData(mipDesc.data());
cmd.args.updateSubRes.srcRowPitch = bpl;
} else if (!mipDesc.data().isEmpty() && isFloatFormat(texD->m_format)) {
const QSize size = mipDesc.sourceSize().isEmpty() ? q->sizeForMipLevel(level, texD->m_pixelSize)
: mipDesc.sourceSize();
quint32 bpl = 0;
QSize blockDim;
textureFormatInfo(texD->m_format, size, &bpl, nullptr);
box.left = dp.x();
box.top = dp.y();
box.right = dp.x() + size.width();
box.bottom = dp.y() + size.height();
cmd.args.updateSubRes.hasDstBox = true;
cmd.args.updateSubRes.dstBox = box;
cmd.args.updateSubRes.src = cbD->retainData(mipDesc.data());
cmd.args.updateSubRes.srcRowPitch = bpl;
} else {
qWarning("Invalid texture upload for %p layer=%d mip=%d", texD, layer, level);
cmdValid = false;
}
cbD->commands.append(cmd);
if (cmdValid)
cbD->commands.append(cmd);
}
}
} else if (u.type == QRhiResourceUpdateBatchPrivate::TextureOp::TexCopy) {
......
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