Commit f38f0bb6 authored by Laszlo Agocs's avatar Laszlo Agocs

add unfinished msaatexture test

...including some buffer upload improvements...
parent 36bce9c5
This diff is collapsed.
TEMPLATE = app
QT += shadertools rhi
SOURCES = \
msaatexture.cpp
RESOURCES = msaatexture.qrc
target.path = $$[QT_INSTALL_EXAMPLES]/rhi/msaatexture
INSTALLS += target
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file alias="qt256.png">../shared/qt256.png</file>
<file alias="color.vert.qsb">../shared/color.vert.qsb</file>
<file alias="color.frag.qsb">../shared/color.frag.qsb</file>
<file alias="texture.vert.qsb">../shared/texture.vert.qsb</file>
<file alias="texture.frag.qsb">../shared/texture.frag.qsb</file>
<file alias="texture_ms4.frag.qsb">../shared/texture_ms4.frag.qsb</file>
</qresource>
</RCC>
......@@ -5,6 +5,7 @@ SUBDIRS += \
compressedtexture_bc1 \
compressedtexture_bc1_subupload \
texuploads \
msaatexture \
plainqwindow_gles2 \
offscreen_gles2
......
......@@ -2,3 +2,4 @@ qsb --glsl "100 es,120" --hlsl 50 --msl 12 -c color.vert -o color.vert.qsb
qsb --glsl "100 es,120" --hlsl 50 --msl 12 -c color.frag -o color.frag.qsb
qsb --glsl "100 es,120" --hlsl 50 --msl 12 -c texture.vert -o texture.vert.qsb
qsb --glsl "100 es,120" --hlsl 50 --msl 12 -c texture.frag -o texture.frag.qsb
qsb --hlsl 50 --msl 12 -c texture_ms4.frag -o texture_ms4.frag.qsb
#version 440
layout(location = 0) in vec2 v_texcoord;
layout(location = 0) out vec4 fragColor;
layout(std140, binding = 0) uniform buf {
mat4 mvp;
int flip;
} ubuf;
layout(binding = 1) uniform sampler2DMS tex;
void main()
{
ivec2 tc = ivec2(floor(vec2(textureSize(tex)) * v_texcoord));
vec4 c = texelFetch(tex, tc, 0) + texelFetch(tex, tc, 1) + texelFetch(tex, tc, 2) + texelFetch(tex, tc, 3);
c /= 4.0;
fragColor = vec4(c.rgb * c.a, c.a);
}
......@@ -434,9 +434,14 @@ void QRhiResourceUpdateBatch::updateDynamicBuffer(QRhiBuffer *buf, int offset, i
d->dynamicBufferUpdates.append({ buf, offset, size, data });
}
void QRhiResourceUpdateBatch::uploadStaticBuffer(QRhiBuffer *buf, int offset, int size, const void *data)
{
d->staticBufferUploads.append({ buf, offset, size, data });
}
void QRhiResourceUpdateBatch::uploadStaticBuffer(QRhiBuffer *buf, const void *data)
{
d->staticBufferUploads.append({ buf, data });
d->staticBufferUploads.append({ buf, 0, 0, data });
}
void QRhiResourceUpdateBatch::uploadTexture(QRhiTexture *tex, const QRhiTextureUploadDescription &desc)
......
......@@ -994,6 +994,7 @@ public:
// beginPass/endPass/resourceUpdate. What exactly then happens underneath
// is hidden from the applications.
void updateDynamicBuffer(QRhiBuffer *buf, int offset, int size, const void *data);
void uploadStaticBuffer(QRhiBuffer *buf, int offset, int size, const void *data);
void uploadStaticBuffer(QRhiBuffer *buf, const void *data);
void uploadTexture(QRhiTexture *tex, const QRhiTextureUploadDescription &desc);
void uploadTexture(QRhiTexture *tex, const QImage &image); // shortcut
......
......@@ -153,11 +153,12 @@ struct QRhiResourceUpdateBatchPrivate
struct StaticBufferUpload {
StaticBufferUpload() { }
StaticBufferUpload(QRhiBuffer *buf_, const void *data_)
: buf(buf_), data(reinterpret_cast<const char *>(data_), buf_->size())
StaticBufferUpload(QRhiBuffer *buf_, int offset_, int size_, const void *data_)
: buf(buf_), offset(offset_), data(reinterpret_cast<const char *>(data_), size_ ? size_ : buf_->size())
{ }
QRhiBuffer *buf = nullptr;
int offset = 0;
QByteArray data;
};
......
......@@ -681,25 +681,23 @@ void QRhiD3D11::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate
for (const QRhiResourceUpdateBatchPrivate::StaticBufferUpload &u : ud->staticBufferUploads) {
QD3D11Buffer *bufD = QRHI_RES(QD3D11Buffer, u.buf);
Q_ASSERT(bufD->m_type != QRhiBuffer::Dynamic);
Q_ASSERT(u.data.size() == bufD->m_size);
Q_ASSERT(u.offset + u.data.size() <= bufD->m_size);
QD3D11CommandBuffer::Command cmd;
cmd.cmd = QD3D11CommandBuffer::Command::UpdateSubRes;
cmd.args.updateSubRes.dst = bufD->buffer;
cmd.args.updateSubRes.dstSubRes = 0;
cmd.args.updateSubRes.src = cbD->retainData(u.data);
cmd.args.updateSubRes.srcRowPitch = 0;
if (!(u.data.size() & 0xFF)) {
cmd.args.updateSubRes.hasDstBox = false;
} else {
// Specify the region since the ID3D11Buffer's size is rounded up to be
// a multiple of 256 while the data we have has the original size.
D3D11_BOX box;
box.left = box.top = box.front = 0;
box.back = box.bottom = 1;
box.right = u.data.size(); // no -1: right, bottom, back are exclusive, see D3D11_BOX doc
cmd.args.updateSubRes.hasDstBox = true;
cmd.args.updateSubRes.dstBox = box;
}
// Specify the region (even when offset is 0 and all data is provided)
// since the ID3D11Buffer's size is rounded up to be a multiple of 256
// while the data we have has the original size.
D3D11_BOX box;
box.left = u.offset;
box.top = box.front = 0;
box.back = box.bottom = 1;
box.right = u.offset + u.data.size(); // no -1: right, bottom, back are exclusive, see D3D11_BOX doc
cmd.args.updateSubRes.hasDstBox = true;
cmd.args.updateSubRes.dstBox = box;
cbD->commands.append(cmd);
}
......@@ -735,7 +733,7 @@ void QRhiD3D11::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate
}
if (img.depth() == 32) {
const int offset = sy * img.bytesPerLine() + sx * 4;
cmd.args.updateSubRes.src = static_cast<const uchar *>(cbD->retainImage(img)) + offset;
cmd.args.updateSubRes.src = cbD->retainImage(img) + offset;
} else {
img = img.copy(sx, sy, w, h);
bpl = img.bytesPerLine();
......
......@@ -335,11 +335,11 @@ struct QD3D11CommandBuffer : public QRhiCommandBuffer
QVector<QImage> imageRetainPool;
// relies heavily on implicit sharing (no copies of the actual data will be made)
const void *retainData(const QByteArray &data) {
const uchar *retainData(const QByteArray &data) {
dataRetainPool.append(data);
return dataRetainPool.constLast().constData();
return reinterpret_cast<const uchar *>(dataRetainPool.constLast().constData());
}
const void *retainImage(const QImage &image) {
const uchar *retainImage(const QImage &image) {
imageRetainPool.append(image);
return imageRetainPool.constLast().constBits();
}
......
......@@ -553,7 +553,7 @@ void QRhiGles2::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate
Q_ASSERT(bufD->m_type != QRhiBuffer::Dynamic);
Q_ASSERT(u.data.size() == bufD->m_size);
if (bufD->m_usage.testFlag(QRhiBuffer::UniformBuffer)) {
memcpy(bufD->ubuf.data(), u.data.constData(), u.data.size());
memcpy(bufD->ubuf.data() + u.offset, u.data.constData(), u.data.size());
bufD->ubufChangeRange = { 0, u.data.size() };
} else {
QGles2CommandBuffer::Command cmd;
......@@ -563,6 +563,7 @@ void QRhiGles2::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate
cmd.args.bufferData.size = u.data.size();
cmd.args.bufferData.data = cbD->retainData(u.data);
cbD->commands.append(cmd);
// ### offset??
}
}
......
......@@ -1786,7 +1786,7 @@ void QRhiVulkan::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdat
for (const QRhiResourceUpdateBatchPrivate::StaticBufferUpload &u : ud->staticBufferUploads) {
QVkBuffer *bufD = QRHI_RES(QVkBuffer, u.buf);
Q_ASSERT(bufD->m_type != QRhiBuffer::Dynamic);
Q_ASSERT(u.data.size() == bufD->m_size);
Q_ASSERT(u.offset + u.data.size() <= bufD->m_size);
if (!bufD->stagingBuffers[currentFrameSlot]) {
VkBufferCreateInfo bufferInfo;
......@@ -1817,13 +1817,15 @@ void QRhiVulkan::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdat
qWarning("Failed to map buffer: %d", err);
continue;
}
memcpy(p, u.data.constData(), bufD->m_size);
memcpy(static_cast<uchar *>(p) + u.offset, u.data.constData(), u.data.size());
vmaUnmapMemory(toVmaAllocator(allocator), a);
vmaFlushAllocation(toVmaAllocator(allocator), a, 0, bufD->m_size);
vmaFlushAllocation(toVmaAllocator(allocator), a, u.offset, u.data.size());
VkBufferCopy copyInfo;
memset(&copyInfo, 0, sizeof(copyInfo));
copyInfo.size = bufD->m_size;
copyInfo.srcOffset = u.offset;
copyInfo.dstOffset = u.offset;
copyInfo.size = u.data.size();
df->vkCmdCopyBuffer(cbD->cb, bufD->stagingBuffers[currentFrameSlot], bufD->buffers[0], 1, &copyInfo);
bufferBarrier(cb, u.buf);
......
......@@ -9,11 +9,14 @@ mtl: msaa (onscreen)
mtl: srgb (tex, swapchain buf)
mtl: msaa tex+rt
mtl: resolveimage (color)
mtl: buffer upload with offset/size
test cubemap
test cubemap face as target
face cubemap readback? (test vk/d3d, impl for gl/mtl)
gl: buffer upload with offset/size
d3d: resolveimage (color)
vk, gl: msaa tex+rt
vk, gl: resolveimage (color)
......@@ -69,6 +72,9 @@ dxc for d3d as an alternative to fxc?
hlsl -> dxc -> spirv -> spirv-cross hmmm...
+++ done
d3d: buffer upload with offset/size
vk: buffer upload with offset/size
buffer upload with offset
resourceUpdate (run updates without begin/endPass)
resourceUpdates in endPass
d3d: msaa tex+rt
......
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