rhi: Clean up some inconsistencies
Some of the offsets are already quint32 in the API (vertex input attributes, dynamic offsets, offsets in draw calls), matching the reality of the underlying 3D APIs, but many buffer-related functions use int as of now, simply because that used to be the default choice, and the same goes for sizes (such as buffer or range sizes). This is not quite consistent and should be cleaned up if for nothing else then just to make the classes consistent, but also because no 3D API use a signed type for offsets, sizes, and strides. (except OpenGL for some) When it comes to strides (for vertex inputs and raw image texture uploads), those are already all quint32s. This is straightforward because most of the 3D APIs use 32-bit uints for these regardless of the architecture. Sizes and offsets are often architecture-dependent (Vulkan, Metal), but there is at least one API where they are always 32-bit even on 64-bit Windows (UINT == unsigned int, D3D11). In addition, we do not really care about buffer or texture data larger than 4 GB, at least not without realistic use cases and real world testing, which are quite unlikely to materialize for now (esp. since we still have the width/height of 2D textures limited to 16 or 32K in many cases even on desktops, whereas 2GB+ buffers are not guaranteed in practice even when an API seemingly allows it). In any case, the important change here is the signed->unsigned switch. A number of casts can now be removed here and there in the backends, because the offsets and sizes are now unsigned as well, matching the underlying API reality. The size can be potentially increased later on with minimal effort, if that becomes necessary for some reason. Change-Id: I404dbc365ac397eaeeb3bd2da9ce7eb98916da5f Reviewed-by: Inho Lee <inho.lee@qt.io> Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
This commit is contained in:
parent
7b6350fa77
commit
7de0f3e9cc
@ -1767,7 +1767,7 @@ QRhiTextureSubresourceUploadDescription::QRhiTextureSubresourceUploadDescription
|
|||||||
|
|
||||||
\a data can safely be destroyed or changed once this function returns.
|
\a data can safely be destroyed or changed once this function returns.
|
||||||
*/
|
*/
|
||||||
QRhiTextureSubresourceUploadDescription::QRhiTextureSubresourceUploadDescription(const void *data, int size)
|
QRhiTextureSubresourceUploadDescription::QRhiTextureSubresourceUploadDescription(const void *data, quint32 size)
|
||||||
: m_data(reinterpret_cast<const char *>(data), size)
|
: m_data(reinterpret_cast<const char *>(data), size)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -2238,7 +2238,7 @@ quint64 QRhiResource::globalResourceId() const
|
|||||||
/*!
|
/*!
|
||||||
\internal
|
\internal
|
||||||
*/
|
*/
|
||||||
QRhiBuffer::QRhiBuffer(QRhiImplementation *rhi, Type type_, UsageFlags usage_, int size_)
|
QRhiBuffer::QRhiBuffer(QRhiImplementation *rhi, Type type_, UsageFlags usage_, quint32 size_)
|
||||||
: QRhiResource(rhi),
|
: QRhiResource(rhi),
|
||||||
m_type(type_), m_usage(usage_), m_size(size_)
|
m_type(type_), m_usage(usage_), m_size(size_)
|
||||||
{
|
{
|
||||||
@ -3399,7 +3399,7 @@ QRhiShaderResourceBinding QRhiShaderResourceBinding::uniformBuffer(
|
|||||||
unexpected errors may occur.
|
unexpected errors may occur.
|
||||||
*/
|
*/
|
||||||
QRhiShaderResourceBinding QRhiShaderResourceBinding::uniformBuffer(
|
QRhiShaderResourceBinding QRhiShaderResourceBinding::uniformBuffer(
|
||||||
int binding, StageFlags stage, QRhiBuffer *buf, int offset, int size)
|
int binding, StageFlags stage, QRhiBuffer *buf, quint32 offset, quint32 size)
|
||||||
{
|
{
|
||||||
Q_ASSERT(size > 0);
|
Q_ASSERT(size > 0);
|
||||||
QRhiShaderResourceBinding b;
|
QRhiShaderResourceBinding b;
|
||||||
@ -3436,7 +3436,7 @@ QRhiShaderResourceBinding QRhiShaderResourceBinding::uniformBuffer(
|
|||||||
unexpected errors may occur.
|
unexpected errors may occur.
|
||||||
*/
|
*/
|
||||||
QRhiShaderResourceBinding QRhiShaderResourceBinding::uniformBufferWithDynamicOffset(
|
QRhiShaderResourceBinding QRhiShaderResourceBinding::uniformBufferWithDynamicOffset(
|
||||||
int binding, StageFlags stage, QRhiBuffer *buf, int size)
|
int binding, StageFlags stage, QRhiBuffer *buf, quint32 size)
|
||||||
{
|
{
|
||||||
Q_ASSERT(size > 0);
|
Q_ASSERT(size > 0);
|
||||||
QRhiShaderResourceBinding b;
|
QRhiShaderResourceBinding b;
|
||||||
@ -3762,7 +3762,7 @@ QRhiShaderResourceBinding QRhiShaderResourceBinding::bufferLoad(
|
|||||||
resources present passed to QRhiCommandBuffer::setShaderResources().
|
resources present passed to QRhiCommandBuffer::setShaderResources().
|
||||||
*/
|
*/
|
||||||
QRhiShaderResourceBinding QRhiShaderResourceBinding::bufferLoad(
|
QRhiShaderResourceBinding QRhiShaderResourceBinding::bufferLoad(
|
||||||
int binding, StageFlags stage, QRhiBuffer *buf, int offset, int size)
|
int binding, StageFlags stage, QRhiBuffer *buf, quint32 offset, quint32 size)
|
||||||
{
|
{
|
||||||
Q_ASSERT(size > 0);
|
Q_ASSERT(size > 0);
|
||||||
QRhiShaderResourceBinding b;
|
QRhiShaderResourceBinding b;
|
||||||
@ -3818,7 +3818,7 @@ QRhiShaderResourceBinding QRhiShaderResourceBinding::bufferStore(
|
|||||||
resources present passed to QRhiCommandBuffer::setShaderResources().
|
resources present passed to QRhiCommandBuffer::setShaderResources().
|
||||||
*/
|
*/
|
||||||
QRhiShaderResourceBinding QRhiShaderResourceBinding::bufferStore(
|
QRhiShaderResourceBinding QRhiShaderResourceBinding::bufferStore(
|
||||||
int binding, StageFlags stage, QRhiBuffer *buf, int offset, int size)
|
int binding, StageFlags stage, QRhiBuffer *buf, quint32 offset, quint32 size)
|
||||||
{
|
{
|
||||||
Q_ASSERT(size > 0);
|
Q_ASSERT(size > 0);
|
||||||
QRhiShaderResourceBinding b;
|
QRhiShaderResourceBinding b;
|
||||||
@ -3874,7 +3874,7 @@ QRhiShaderResourceBinding QRhiShaderResourceBinding::bufferLoadStore(
|
|||||||
resources present passed to QRhiCommandBuffer::setShaderResources().
|
resources present passed to QRhiCommandBuffer::setShaderResources().
|
||||||
*/
|
*/
|
||||||
QRhiShaderResourceBinding QRhiShaderResourceBinding::bufferLoadStore(
|
QRhiShaderResourceBinding QRhiShaderResourceBinding::bufferLoadStore(
|
||||||
int binding, StageFlags stage, QRhiBuffer *buf, int offset, int size)
|
int binding, StageFlags stage, QRhiBuffer *buf, quint32 offset, quint32 size)
|
||||||
{
|
{
|
||||||
Q_ASSERT(size > 0);
|
Q_ASSERT(size > 0);
|
||||||
QRhiShaderResourceBinding b;
|
QRhiShaderResourceBinding b;
|
||||||
@ -5760,7 +5760,7 @@ bool QRhiResourceUpdateBatch::hasOptimalCapacity() const
|
|||||||
multiple native underneath can be safely ignored when using the QRhi and
|
multiple native underneath can be safely ignored when using the QRhi and
|
||||||
QRhiResourceUpdateBatch.
|
QRhiResourceUpdateBatch.
|
||||||
*/
|
*/
|
||||||
void QRhiResourceUpdateBatch::updateDynamicBuffer(QRhiBuffer *buf, int offset, int size, const void *data)
|
void QRhiResourceUpdateBatch::updateDynamicBuffer(QRhiBuffer *buf, quint32 offset, quint32 size, const void *data)
|
||||||
{
|
{
|
||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
const int idx = d->activeBufferOpCount++;
|
const int idx = d->activeBufferOpCount++;
|
||||||
@ -5780,7 +5780,7 @@ void QRhiResourceUpdateBatch::updateDynamicBuffer(QRhiBuffer *buf, int offset, i
|
|||||||
are specified by \a data which must have at least \a size bytes available.
|
are specified by \a data which must have at least \a size bytes available.
|
||||||
\a data can safely be destroyed or changed once this function returns.
|
\a data can safely be destroyed or changed once this function returns.
|
||||||
*/
|
*/
|
||||||
void QRhiResourceUpdateBatch::uploadStaticBuffer(QRhiBuffer *buf, int offset, int size, const void *data)
|
void QRhiResourceUpdateBatch::uploadStaticBuffer(QRhiBuffer *buf, quint32 offset, quint32 size, const void *data)
|
||||||
{
|
{
|
||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
const int idx = d->activeBufferOpCount++;
|
const int idx = d->activeBufferOpCount++;
|
||||||
@ -5830,7 +5830,7 @@ void QRhiResourceUpdateBatch::uploadStaticBuffer(QRhiBuffer *buf, const void *da
|
|||||||
|
|
||||||
\sa readBackTexture(), QRhi::isFeatureSupported(), QRhi::resourceLimit()
|
\sa readBackTexture(), QRhi::isFeatureSupported(), QRhi::resourceLimit()
|
||||||
*/
|
*/
|
||||||
void QRhiResourceUpdateBatch::readBackBuffer(QRhiBuffer *buf, int offset, int size, QRhiBufferReadbackResult *result)
|
void QRhiResourceUpdateBatch::readBackBuffer(QRhiBuffer *buf, quint32 offset, quint32 size, QRhiBufferReadbackResult *result)
|
||||||
{
|
{
|
||||||
const int idx = d->activeBufferOpCount++;
|
const int idx = d->activeBufferOpCount++;
|
||||||
if (idx < d->bufferOps.size())
|
if (idx < d->bufferOps.size())
|
||||||
@ -7076,7 +7076,7 @@ QRhiShaderResourceBindings *QRhi::newShaderResourceBindings()
|
|||||||
*/
|
*/
|
||||||
QRhiBuffer *QRhi::newBuffer(QRhiBuffer::Type type,
|
QRhiBuffer *QRhi::newBuffer(QRhiBuffer::Type type,
|
||||||
QRhiBuffer::UsageFlags usage,
|
QRhiBuffer::UsageFlags usage,
|
||||||
int size)
|
quint32 size)
|
||||||
{
|
{
|
||||||
return d->createBuffer(type, usage, size);
|
return d->createBuffer(type, usage, size);
|
||||||
}
|
}
|
||||||
|
@ -328,8 +328,8 @@ public:
|
|||||||
bool isLayoutCompatible(const QRhiShaderResourceBinding &other) const;
|
bool isLayoutCompatible(const QRhiShaderResourceBinding &other) const;
|
||||||
|
|
||||||
static QRhiShaderResourceBinding uniformBuffer(int binding, StageFlags stage, QRhiBuffer *buf);
|
static QRhiShaderResourceBinding uniformBuffer(int binding, StageFlags stage, QRhiBuffer *buf);
|
||||||
static QRhiShaderResourceBinding uniformBuffer(int binding, StageFlags stage, QRhiBuffer *buf, int offset, int size);
|
static QRhiShaderResourceBinding uniformBuffer(int binding, StageFlags stage, QRhiBuffer *buf, quint32 offset, quint32 size);
|
||||||
static QRhiShaderResourceBinding uniformBufferWithDynamicOffset(int binding, StageFlags stage, QRhiBuffer *buf, int size);
|
static QRhiShaderResourceBinding uniformBufferWithDynamicOffset(int binding, StageFlags stage, QRhiBuffer *buf, quint32 size);
|
||||||
|
|
||||||
static QRhiShaderResourceBinding sampledTexture(int binding, StageFlags stage, QRhiTexture *tex, QRhiSampler *sampler);
|
static QRhiShaderResourceBinding sampledTexture(int binding, StageFlags stage, QRhiTexture *tex, QRhiSampler *sampler);
|
||||||
|
|
||||||
@ -348,11 +348,11 @@ public:
|
|||||||
static QRhiShaderResourceBinding imageLoadStore(int binding, StageFlags stage, QRhiTexture *tex, int level);
|
static QRhiShaderResourceBinding imageLoadStore(int binding, StageFlags stage, QRhiTexture *tex, int level);
|
||||||
|
|
||||||
static QRhiShaderResourceBinding bufferLoad(int binding, StageFlags stage, QRhiBuffer *buf);
|
static QRhiShaderResourceBinding bufferLoad(int binding, StageFlags stage, QRhiBuffer *buf);
|
||||||
static QRhiShaderResourceBinding bufferLoad(int binding, StageFlags stage, QRhiBuffer *buf, int offset, int size);
|
static QRhiShaderResourceBinding bufferLoad(int binding, StageFlags stage, QRhiBuffer *buf, quint32 offset, quint32 size);
|
||||||
static QRhiShaderResourceBinding bufferStore(int binding, StageFlags stage, QRhiBuffer *buf);
|
static QRhiShaderResourceBinding bufferStore(int binding, StageFlags stage, QRhiBuffer *buf);
|
||||||
static QRhiShaderResourceBinding bufferStore(int binding, StageFlags stage, QRhiBuffer *buf, int offset, int size);
|
static QRhiShaderResourceBinding bufferStore(int binding, StageFlags stage, QRhiBuffer *buf, quint32 offset, quint32 size);
|
||||||
static QRhiShaderResourceBinding bufferLoadStore(int binding, StageFlags stage, QRhiBuffer *buf);
|
static QRhiShaderResourceBinding bufferLoadStore(int binding, StageFlags stage, QRhiBuffer *buf);
|
||||||
static QRhiShaderResourceBinding bufferLoadStore(int binding, StageFlags stage, QRhiBuffer *buf, int offset, int size);
|
static QRhiShaderResourceBinding bufferLoadStore(int binding, StageFlags stage, QRhiBuffer *buf, quint32 offset, quint32 size);
|
||||||
|
|
||||||
struct Data
|
struct Data
|
||||||
{
|
{
|
||||||
@ -361,8 +361,8 @@ public:
|
|||||||
QRhiShaderResourceBinding::Type type;
|
QRhiShaderResourceBinding::Type type;
|
||||||
struct UniformBufferData {
|
struct UniformBufferData {
|
||||||
QRhiBuffer *buf;
|
QRhiBuffer *buf;
|
||||||
int offset;
|
quint32 offset;
|
||||||
int maybeSize;
|
quint32 maybeSize;
|
||||||
bool hasDynamicOffset;
|
bool hasDynamicOffset;
|
||||||
};
|
};
|
||||||
static const int MAX_TEX_SAMPLER_ARRAY_SIZE = 16;
|
static const int MAX_TEX_SAMPLER_ARRAY_SIZE = 16;
|
||||||
@ -376,8 +376,8 @@ public:
|
|||||||
};
|
};
|
||||||
struct StorageBufferData {
|
struct StorageBufferData {
|
||||||
QRhiBuffer *buf;
|
QRhiBuffer *buf;
|
||||||
int offset;
|
quint32 offset;
|
||||||
int maybeSize;
|
quint32 maybeSize;
|
||||||
};
|
};
|
||||||
union {
|
union {
|
||||||
UniformBufferData ubuf;
|
UniformBufferData ubuf;
|
||||||
@ -512,7 +512,7 @@ class Q_GUI_EXPORT QRhiTextureSubresourceUploadDescription
|
|||||||
public:
|
public:
|
||||||
QRhiTextureSubresourceUploadDescription() = default;
|
QRhiTextureSubresourceUploadDescription() = default;
|
||||||
explicit QRhiTextureSubresourceUploadDescription(const QImage &image);
|
explicit QRhiTextureSubresourceUploadDescription(const QImage &image);
|
||||||
QRhiTextureSubresourceUploadDescription(const void *data, int size);
|
QRhiTextureSubresourceUploadDescription(const void *data, quint32 size);
|
||||||
explicit QRhiTextureSubresourceUploadDescription(const QByteArray &data);
|
explicit QRhiTextureSubresourceUploadDescription(const QByteArray &data);
|
||||||
|
|
||||||
QImage image() const { return m_image; }
|
QImage image() const { return m_image; }
|
||||||
@ -723,8 +723,8 @@ public:
|
|||||||
UsageFlags usage() const { return m_usage; }
|
UsageFlags usage() const { return m_usage; }
|
||||||
void setUsage(UsageFlags u) { m_usage = u; }
|
void setUsage(UsageFlags u) { m_usage = u; }
|
||||||
|
|
||||||
int size() const { return m_size; }
|
quint32 size() const { return m_size; }
|
||||||
void setSize(int sz) { m_size = sz; }
|
void setSize(quint32 sz) { m_size = sz; }
|
||||||
|
|
||||||
virtual bool create() = 0;
|
virtual bool create() = 0;
|
||||||
|
|
||||||
@ -734,10 +734,10 @@ public:
|
|||||||
virtual void endFullDynamicBufferUpdateForCurrentFrame();
|
virtual void endFullDynamicBufferUpdateForCurrentFrame();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QRhiBuffer(QRhiImplementation *rhi, Type type_, UsageFlags usage_, int size_);
|
QRhiBuffer(QRhiImplementation *rhi, Type type_, UsageFlags usage_, quint32 size_);
|
||||||
Type m_type;
|
Type m_type;
|
||||||
UsageFlags m_usage;
|
UsageFlags m_usage;
|
||||||
int m_size;
|
quint32 m_size;
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiBuffer::UsageFlags)
|
Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiBuffer::UsageFlags)
|
||||||
@ -1542,10 +1542,10 @@ public:
|
|||||||
void merge(QRhiResourceUpdateBatch *other);
|
void merge(QRhiResourceUpdateBatch *other);
|
||||||
bool hasOptimalCapacity() const;
|
bool hasOptimalCapacity() const;
|
||||||
|
|
||||||
void updateDynamicBuffer(QRhiBuffer *buf, int offset, int size, const void *data);
|
void updateDynamicBuffer(QRhiBuffer *buf, quint32 offset, quint32 size, const void *data);
|
||||||
void uploadStaticBuffer(QRhiBuffer *buf, int offset, int size, const void *data);
|
void uploadStaticBuffer(QRhiBuffer *buf, quint32 offset, quint32 size, const void *data);
|
||||||
void uploadStaticBuffer(QRhiBuffer *buf, const void *data);
|
void uploadStaticBuffer(QRhiBuffer *buf, const void *data);
|
||||||
void readBackBuffer(QRhiBuffer *buf, int offset, int size, QRhiBufferReadbackResult *result);
|
void readBackBuffer(QRhiBuffer *buf, quint32 offset, quint32 size, QRhiBufferReadbackResult *result);
|
||||||
void uploadTexture(QRhiTexture *tex, const QRhiTextureUploadDescription &desc);
|
void uploadTexture(QRhiTexture *tex, const QRhiTextureUploadDescription &desc);
|
||||||
void uploadTexture(QRhiTexture *tex, const QImage &image);
|
void uploadTexture(QRhiTexture *tex, const QImage &image);
|
||||||
void copyTexture(QRhiTexture *dst, QRhiTexture *src, const QRhiTextureCopyDescription &desc = QRhiTextureCopyDescription());
|
void copyTexture(QRhiTexture *dst, QRhiTexture *src, const QRhiTextureCopyDescription &desc = QRhiTextureCopyDescription());
|
||||||
@ -1719,7 +1719,7 @@ public:
|
|||||||
|
|
||||||
QRhiBuffer *newBuffer(QRhiBuffer::Type type,
|
QRhiBuffer *newBuffer(QRhiBuffer::Type type,
|
||||||
QRhiBuffer::UsageFlags usage,
|
QRhiBuffer::UsageFlags usage,
|
||||||
int size);
|
quint32 size);
|
||||||
|
|
||||||
QRhiRenderBuffer *newRenderBuffer(QRhiRenderBuffer::Type type,
|
QRhiRenderBuffer *newRenderBuffer(QRhiRenderBuffer::Type type,
|
||||||
const QSize &pixelSize,
|
const QSize &pixelSize,
|
||||||
|
@ -43,7 +43,7 @@ public:
|
|||||||
virtual QRhiShaderResourceBindings *createShaderResourceBindings() = 0;
|
virtual QRhiShaderResourceBindings *createShaderResourceBindings() = 0;
|
||||||
virtual QRhiBuffer *createBuffer(QRhiBuffer::Type type,
|
virtual QRhiBuffer *createBuffer(QRhiBuffer::Type type,
|
||||||
QRhiBuffer::UsageFlags usage,
|
QRhiBuffer::UsageFlags usage,
|
||||||
int size) = 0;
|
quint32 size) = 0;
|
||||||
virtual QRhiRenderBuffer *createRenderBuffer(QRhiRenderBuffer::Type type,
|
virtual QRhiRenderBuffer *createRenderBuffer(QRhiRenderBuffer::Type type,
|
||||||
const QSize &pixelSize,
|
const QSize &pixelSize,
|
||||||
int sampleCount,
|
int sampleCount,
|
||||||
@ -288,10 +288,10 @@ struct QRhiBufferDataPrivate
|
|||||||
QRhiBufferDataPrivate() { }
|
QRhiBufferDataPrivate() { }
|
||||||
~QRhiBufferDataPrivate() { delete[] largeData; }
|
~QRhiBufferDataPrivate() { delete[] largeData; }
|
||||||
int ref = 1;
|
int ref = 1;
|
||||||
int size = 0;
|
quint32 size = 0;
|
||||||
int largeAlloc = 0;
|
quint32 largeAlloc = 0;
|
||||||
char *largeData = nullptr;
|
char *largeData = nullptr;
|
||||||
static constexpr int SMALL_DATA_SIZE = 1024;
|
static constexpr quint32 SMALL_DATA_SIZE = 1024;
|
||||||
char data[SMALL_DATA_SIZE];
|
char data[SMALL_DATA_SIZE];
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -326,11 +326,11 @@ public:
|
|||||||
{
|
{
|
||||||
return d->size <= QRhiBufferDataPrivate::SMALL_DATA_SIZE ? d->data : d->largeData;
|
return d->size <= QRhiBufferDataPrivate::SMALL_DATA_SIZE ? d->data : d->largeData;
|
||||||
}
|
}
|
||||||
int size() const
|
quint32 size() const
|
||||||
{
|
{
|
||||||
return d->size;
|
return d->size;
|
||||||
}
|
}
|
||||||
void assign(const char *s, int size)
|
void assign(const char *s, quint32 size)
|
||||||
{
|
{
|
||||||
if (!d) {
|
if (!d) {
|
||||||
d = new QRhiBufferDataPrivate;
|
d = new QRhiBufferDataPrivate;
|
||||||
@ -367,12 +367,12 @@ public:
|
|||||||
};
|
};
|
||||||
Type type;
|
Type type;
|
||||||
QRhiBuffer *buf;
|
QRhiBuffer *buf;
|
||||||
int offset;
|
quint32 offset;
|
||||||
QRhiBufferData data;
|
QRhiBufferData data;
|
||||||
int readSize;
|
quint32 readSize;
|
||||||
QRhiBufferReadbackResult *result;
|
QRhiBufferReadbackResult *result;
|
||||||
|
|
||||||
static BufferOp dynamicUpdate(QRhiBuffer *buf, int offset, int size, const void *data)
|
static BufferOp dynamicUpdate(QRhiBuffer *buf, quint32 offset, quint32 size, const void *data)
|
||||||
{
|
{
|
||||||
BufferOp op = {};
|
BufferOp op = {};
|
||||||
op.type = DynamicUpdate;
|
op.type = DynamicUpdate;
|
||||||
@ -383,7 +383,7 @@ public:
|
|||||||
return op;
|
return op;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void changeToDynamicUpdate(BufferOp *op, QRhiBuffer *buf, int offset, int size, const void *data)
|
static void changeToDynamicUpdate(BufferOp *op, QRhiBuffer *buf, quint32 offset, quint32 size, const void *data)
|
||||||
{
|
{
|
||||||
op->type = DynamicUpdate;
|
op->type = DynamicUpdate;
|
||||||
op->buf = buf;
|
op->buf = buf;
|
||||||
@ -392,7 +392,7 @@ public:
|
|||||||
op->data.assign(reinterpret_cast<const char *>(data), effectiveSize);
|
op->data.assign(reinterpret_cast<const char *>(data), effectiveSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
static BufferOp staticUpload(QRhiBuffer *buf, int offset, int size, const void *data)
|
static BufferOp staticUpload(QRhiBuffer *buf, quint32 offset, quint32 size, const void *data)
|
||||||
{
|
{
|
||||||
BufferOp op = {};
|
BufferOp op = {};
|
||||||
op.type = StaticUpload;
|
op.type = StaticUpload;
|
||||||
@ -403,7 +403,7 @@ public:
|
|||||||
return op;
|
return op;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void changeToStaticUpload(BufferOp *op, QRhiBuffer *buf, int offset, int size, const void *data)
|
static void changeToStaticUpload(BufferOp *op, QRhiBuffer *buf, quint32 offset, quint32 size, const void *data)
|
||||||
{
|
{
|
||||||
op->type = StaticUpload;
|
op->type = StaticUpload;
|
||||||
op->buf = buf;
|
op->buf = buf;
|
||||||
@ -412,7 +412,7 @@ public:
|
|||||||
op->data.assign(reinterpret_cast<const char *>(data), effectiveSize);
|
op->data.assign(reinterpret_cast<const char *>(data), effectiveSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
static BufferOp read(QRhiBuffer *buf, int offset, int size, QRhiBufferReadbackResult *result)
|
static BufferOp read(QRhiBuffer *buf, quint32 offset, quint32 size, QRhiBufferReadbackResult *result)
|
||||||
{
|
{
|
||||||
BufferOp op = {};
|
BufferOp op = {};
|
||||||
op.type = Read;
|
op.type = Read;
|
||||||
|
@ -435,7 +435,7 @@ QRhiSwapChain *QRhiD3D11::createSwapChain()
|
|||||||
return new QD3D11SwapChain(this);
|
return new QD3D11SwapChain(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
QRhiBuffer *QRhiD3D11::createBuffer(QRhiBuffer::Type type, QRhiBuffer::UsageFlags usage, int size)
|
QRhiBuffer *QRhiD3D11::createBuffer(QRhiBuffer::Type type, QRhiBuffer::UsageFlags usage, quint32 size)
|
||||||
{
|
{
|
||||||
return new QD3D11Buffer(this, type, usage, size);
|
return new QD3D11Buffer(this, type, usage, size);
|
||||||
}
|
}
|
||||||
@ -1000,8 +1000,8 @@ void QRhiD3D11::setShaderResources(QRhiCommandBuffer *cb, QRhiShaderResourceBind
|
|||||||
for (int i = 0; i < dynamicOffsetCount; ++i) {
|
for (int i = 0; i < dynamicOffsetCount; ++i) {
|
||||||
const QRhiCommandBuffer::DynamicOffset &dynOfs(dynamicOffsets[i]);
|
const QRhiCommandBuffer::DynamicOffset &dynOfs(dynamicOffsets[i]);
|
||||||
const uint binding = uint(dynOfs.first);
|
const uint binding = uint(dynOfs.first);
|
||||||
Q_ASSERT(aligned(dynOfs.second, quint32(256)) == dynOfs.second);
|
Q_ASSERT(aligned(dynOfs.second, 256u) == dynOfs.second);
|
||||||
const uint offsetInConstants = dynOfs.second / 16;
|
const quint32 offsetInConstants = dynOfs.second / 16;
|
||||||
*p++ = binding;
|
*p++ = binding;
|
||||||
*p++ = offsetInConstants;
|
*p++ = offsetInConstants;
|
||||||
}
|
}
|
||||||
@ -1628,10 +1628,10 @@ void QRhiD3D11::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate
|
|||||||
// since the ID3D11Buffer's size is rounded up to be a multiple of 256
|
// since the ID3D11Buffer's size is rounded up to be a multiple of 256
|
||||||
// while the data we have has the original size.
|
// while the data we have has the original size.
|
||||||
D3D11_BOX box;
|
D3D11_BOX box;
|
||||||
box.left = UINT(u.offset);
|
box.left = u.offset;
|
||||||
box.top = box.front = 0;
|
box.top = box.front = 0;
|
||||||
box.back = box.bottom = 1;
|
box.back = box.bottom = 1;
|
||||||
box.right = UINT(u.offset + u.data.size()); // no -1: right, bottom, back are exclusive, see D3D11_BOX doc
|
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.hasDstBox = true;
|
||||||
cmd.args.updateSubRes.dstBox = box;
|
cmd.args.updateSubRes.dstBox = box;
|
||||||
} else if (u.type == QRhiResourceUpdateBatchPrivate::BufferOp::Read) {
|
} else if (u.type == QRhiResourceUpdateBatchPrivate::BufferOp::Read) {
|
||||||
@ -1666,10 +1666,10 @@ void QRhiD3D11::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate
|
|||||||
cmd.args.copySubRes.srcSubRes = 0;
|
cmd.args.copySubRes.srcSubRes = 0;
|
||||||
cmd.args.copySubRes.hasSrcBox = true;
|
cmd.args.copySubRes.hasSrcBox = true;
|
||||||
D3D11_BOX box;
|
D3D11_BOX box;
|
||||||
box.left = UINT(u.offset);
|
box.left = u.offset;
|
||||||
box.top = box.front = 0;
|
box.top = box.front = 0;
|
||||||
box.back = box.bottom = 1;
|
box.back = box.bottom = 1;
|
||||||
box.right = UINT(u.offset + u.readSize);
|
box.right = u.offset + u.readSize;
|
||||||
cmd.args.copySubRes.srcBox = box;
|
cmd.args.copySubRes.srcBox = box;
|
||||||
|
|
||||||
activeBufferReadbacks.append(readback);
|
activeBufferReadbacks.append(readback);
|
||||||
@ -2165,7 +2165,7 @@ void QRhiD3D11::updateShaderResourceBindings(QD3D11ShaderResourceBindings *srbD,
|
|||||||
case QRhiShaderResourceBinding::UniformBuffer:
|
case QRhiShaderResourceBinding::UniformBuffer:
|
||||||
{
|
{
|
||||||
QD3D11Buffer *bufD = QRHI_RES(QD3D11Buffer, b->u.ubuf.buf);
|
QD3D11Buffer *bufD = QRHI_RES(QD3D11Buffer, b->u.ubuf.buf);
|
||||||
Q_ASSERT(aligned(b->u.ubuf.offset, 256) == b->u.ubuf.offset);
|
Q_ASSERT(aligned(b->u.ubuf.offset, 256u) == b->u.ubuf.offset);
|
||||||
bd.ubuf.id = bufD->m_id;
|
bd.ubuf.id = bufD->m_id;
|
||||||
bd.ubuf.generation = bufD->generation;
|
bd.ubuf.generation = bufD->generation;
|
||||||
// Dynamic ubuf offsets are not considered here, those are baked in
|
// Dynamic ubuf offsets are not considered here, those are baked in
|
||||||
@ -2174,11 +2174,11 @@ void QRhiD3D11::updateShaderResourceBindings(QD3D11ShaderResourceBindings *srbD,
|
|||||||
// Metal) are different in this respect since those do not store
|
// Metal) are different in this respect since those do not store
|
||||||
// per-srb vsubufoffsets etc. data so life's a bit easier for them.
|
// per-srb vsubufoffsets etc. data so life's a bit easier for them.
|
||||||
// But here we have to defer baking in the dynamic offset.
|
// But here we have to defer baking in the dynamic offset.
|
||||||
const uint offsetInConstants = uint(b->u.ubuf.offset) / 16;
|
const quint32 offsetInConstants = b->u.ubuf.offset / 16;
|
||||||
// size must be 16 mult. (in constants, i.e. multiple of 256 bytes).
|
// size must be 16 mult. (in constants, i.e. multiple of 256 bytes).
|
||||||
// We can round up if needed since the buffers's actual size
|
// We can round up if needed since the buffers's actual size
|
||||||
// (ByteWidth) is always a multiple of 256.
|
// (ByteWidth) is always a multiple of 256.
|
||||||
const uint sizeInConstants = uint(aligned(b->u.ubuf.maybeSize ? b->u.ubuf.maybeSize : bufD->m_size, 256) / 16);
|
const quint32 sizeInConstants = aligned(b->u.ubuf.maybeSize ? b->u.ubuf.maybeSize : bufD->m_size, 256u) / 16;
|
||||||
if (b->stage.testFlag(QRhiShaderResourceBinding::VertexStage)) {
|
if (b->stage.testFlag(QRhiShaderResourceBinding::VertexStage)) {
|
||||||
QPair<int, int> nativeBinding = mapBinding(b->binding, RBM_VERTEX, nativeResourceBindingMaps);
|
QPair<int, int> nativeBinding = mapBinding(b->binding, RBM_VERTEX, nativeResourceBindingMaps);
|
||||||
if (nativeBinding.first >= 0)
|
if (nativeBinding.first >= 0)
|
||||||
@ -2378,7 +2378,7 @@ void QRhiD3D11::executeBufferHostWrites(QD3D11Buffer *bufD)
|
|||||||
D3D11_MAPPED_SUBRESOURCE mp;
|
D3D11_MAPPED_SUBRESOURCE mp;
|
||||||
HRESULT hr = context->Map(bufD->buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mp);
|
HRESULT hr = context->Map(bufD->buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mp);
|
||||||
if (SUCCEEDED(hr)) {
|
if (SUCCEEDED(hr)) {
|
||||||
memcpy(mp.pData, bufD->dynBuf, size_t(bufD->m_size));
|
memcpy(mp.pData, bufD->dynBuf, bufD->m_size);
|
||||||
context->Unmap(bufD->buffer, 0);
|
context->Unmap(bufD->buffer, 0);
|
||||||
} else {
|
} else {
|
||||||
qWarning("Failed to map buffer: %s", qPrintable(comErrorMessage(hr)));
|
qWarning("Failed to map buffer: %s", qPrintable(comErrorMessage(hr)));
|
||||||
@ -2814,7 +2814,7 @@ void QRhiD3D11::executeCommandBuffer(QD3D11CommandBuffer *cbD, QD3D11SwapChain *
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QD3D11Buffer::QD3D11Buffer(QRhiImplementation *rhi, Type type, UsageFlags usage, int size)
|
QD3D11Buffer::QD3D11Buffer(QRhiImplementation *rhi, Type type, UsageFlags usage, quint32 size)
|
||||||
: QRhiBuffer(rhi, type, usage, size)
|
: QRhiBuffer(rhi, type, usage, size)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -2874,12 +2874,12 @@ bool QD3D11Buffer::create()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const int nonZeroSize = m_size <= 0 ? 256 : m_size;
|
const quint32 nonZeroSize = m_size <= 0 ? 256 : m_size;
|
||||||
const int roundedSize = aligned(nonZeroSize, m_usage.testFlag(QRhiBuffer::UniformBuffer) ? 256 : 4);
|
const quint32 roundedSize = aligned(nonZeroSize, m_usage.testFlag(QRhiBuffer::UniformBuffer) ? 256u : 4u);
|
||||||
|
|
||||||
D3D11_BUFFER_DESC desc;
|
D3D11_BUFFER_DESC desc;
|
||||||
memset(&desc, 0, sizeof(desc));
|
memset(&desc, 0, sizeof(desc));
|
||||||
desc.ByteWidth = UINT(roundedSize);
|
desc.ByteWidth = roundedSize;
|
||||||
desc.Usage = m_type == Dynamic ? D3D11_USAGE_DYNAMIC : D3D11_USAGE_DEFAULT;
|
desc.Usage = m_type == Dynamic ? D3D11_USAGE_DYNAMIC : D3D11_USAGE_DEFAULT;
|
||||||
desc.BindFlags = toD3DBufferUsage(m_usage);
|
desc.BindFlags = toD3DBufferUsage(m_usage);
|
||||||
desc.CPUAccessFlags = m_type == Dynamic ? D3D11_CPU_ACCESS_WRITE : 0;
|
desc.CPUAccessFlags = m_type == Dynamic ? D3D11_CPU_ACCESS_WRITE : 0;
|
||||||
@ -2950,7 +2950,7 @@ ID3D11UnorderedAccessView *QD3D11Buffer::unorderedAccessView()
|
|||||||
desc.Format = DXGI_FORMAT_R32_TYPELESS;
|
desc.Format = DXGI_FORMAT_R32_TYPELESS;
|
||||||
desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
|
desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
|
||||||
desc.Buffer.FirstElement = 0;
|
desc.Buffer.FirstElement = 0;
|
||||||
desc.Buffer.NumElements = UINT(aligned(m_size, 4) / 4);
|
desc.Buffer.NumElements = aligned(m_size, 4u) / 4;
|
||||||
desc.Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
|
desc.Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
|
||||||
|
|
||||||
QRHI_RES_RHI(QRhiD3D11);
|
QRHI_RES_RHI(QRhiD3D11);
|
||||||
|
@ -27,7 +27,7 @@ QT_BEGIN_NAMESPACE
|
|||||||
|
|
||||||
struct QD3D11Buffer : public QRhiBuffer
|
struct QD3D11Buffer : public QRhiBuffer
|
||||||
{
|
{
|
||||||
QD3D11Buffer(QRhiImplementation *rhi, Type type, UsageFlags usage, int size);
|
QD3D11Buffer(QRhiImplementation *rhi, Type type, UsageFlags usage, quint32 size);
|
||||||
~QD3D11Buffer();
|
~QD3D11Buffer();
|
||||||
void destroy() override;
|
void destroy() override;
|
||||||
bool create() override;
|
bool create() override;
|
||||||
@ -566,7 +566,7 @@ public:
|
|||||||
QRhiShaderResourceBindings *createShaderResourceBindings() override;
|
QRhiShaderResourceBindings *createShaderResourceBindings() override;
|
||||||
QRhiBuffer *createBuffer(QRhiBuffer::Type type,
|
QRhiBuffer *createBuffer(QRhiBuffer::Type type,
|
||||||
QRhiBuffer::UsageFlags usage,
|
QRhiBuffer::UsageFlags usage,
|
||||||
int size) override;
|
quint32 size) override;
|
||||||
QRhiRenderBuffer *createRenderBuffer(QRhiRenderBuffer::Type type,
|
QRhiRenderBuffer *createRenderBuffer(QRhiRenderBuffer::Type type,
|
||||||
const QSize &pixelSize,
|
const QSize &pixelSize,
|
||||||
int sampleCount,
|
int sampleCount,
|
||||||
|
@ -982,7 +982,7 @@ QRhiSwapChain *QRhiGles2::createSwapChain()
|
|||||||
return new QGles2SwapChain(this);
|
return new QGles2SwapChain(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
QRhiBuffer *QRhiGles2::createBuffer(QRhiBuffer::Type type, QRhiBuffer::UsageFlags usage, int size)
|
QRhiBuffer *QRhiGles2::createBuffer(QRhiBuffer::Type type, QRhiBuffer::UsageFlags usage, quint32 size)
|
||||||
{
|
{
|
||||||
return new QGles2Buffer(this, type, usage, size);
|
return new QGles2Buffer(this, type, usage, size);
|
||||||
}
|
}
|
||||||
@ -4680,7 +4680,7 @@ void QRhiGles2::trySaveToPipelineCache(GLuint program, const QByteArray &cacheKe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QGles2Buffer::QGles2Buffer(QRhiImplementation *rhi, Type type, UsageFlags usage, int size)
|
QGles2Buffer::QGles2Buffer(QRhiImplementation *rhi, Type type, UsageFlags usage, quint32 size)
|
||||||
: QRhiBuffer(rhi, type, usage, size)
|
: QRhiBuffer(rhi, type, usage, size)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ class QOpenGLExtensions;
|
|||||||
|
|
||||||
struct QGles2Buffer : public QRhiBuffer
|
struct QGles2Buffer : public QRhiBuffer
|
||||||
{
|
{
|
||||||
QGles2Buffer(QRhiImplementation *rhi, Type type, UsageFlags usage, int size);
|
QGles2Buffer(QRhiImplementation *rhi, Type type, UsageFlags usage, quint32 size);
|
||||||
~QGles2Buffer();
|
~QGles2Buffer();
|
||||||
void destroy() override;
|
void destroy() override;
|
||||||
bool create() override;
|
bool create() override;
|
||||||
@ -38,7 +38,7 @@ struct QGles2Buffer : public QRhiBuffer
|
|||||||
char *beginFullDynamicBufferUpdateForCurrentFrame() override;
|
char *beginFullDynamicBufferUpdateForCurrentFrame() override;
|
||||||
void endFullDynamicBufferUpdateForCurrentFrame() override;
|
void endFullDynamicBufferUpdateForCurrentFrame() override;
|
||||||
|
|
||||||
int nonZeroSize = 0;
|
quint32 nonZeroSize = 0;
|
||||||
GLuint buffer = 0;
|
GLuint buffer = 0;
|
||||||
GLenum targetForDataOps;
|
GLenum targetForDataOps;
|
||||||
QByteArray data;
|
QByteArray data;
|
||||||
@ -232,8 +232,8 @@ struct QGles2UniformDescription
|
|||||||
QShaderDescription::VariableType type;
|
QShaderDescription::VariableType type;
|
||||||
int glslLocation;
|
int glslLocation;
|
||||||
int binding;
|
int binding;
|
||||||
uint offset;
|
quint32 offset;
|
||||||
int size;
|
quint32 size;
|
||||||
int arrayDim;
|
int arrayDim;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -717,7 +717,7 @@ public:
|
|||||||
QRhiShaderResourceBindings *createShaderResourceBindings() override;
|
QRhiShaderResourceBindings *createShaderResourceBindings() override;
|
||||||
QRhiBuffer *createBuffer(QRhiBuffer::Type type,
|
QRhiBuffer *createBuffer(QRhiBuffer::Type type,
|
||||||
QRhiBuffer::UsageFlags usage,
|
QRhiBuffer::UsageFlags usage,
|
||||||
int size) override;
|
quint32 size) override;
|
||||||
QRhiRenderBuffer *createRenderBuffer(QRhiRenderBuffer::Type type,
|
QRhiRenderBuffer *createRenderBuffer(QRhiRenderBuffer::Type type,
|
||||||
const QSize &pixelSize,
|
const QSize &pixelSize,
|
||||||
int sampleCount,
|
int sampleCount,
|
||||||
|
@ -192,7 +192,7 @@ struct QMetalBufferData
|
|||||||
bool slotted;
|
bool slotted;
|
||||||
id<MTLBuffer> buf[QMTL_FRAMES_IN_FLIGHT];
|
id<MTLBuffer> buf[QMTL_FRAMES_IN_FLIGHT];
|
||||||
struct BufferUpdate {
|
struct BufferUpdate {
|
||||||
int offset;
|
quint32 offset;
|
||||||
QRhiBufferData data;
|
QRhiBufferData data;
|
||||||
};
|
};
|
||||||
QVarLengthArray<BufferUpdate, 16> pendingUpdates[QMTL_FRAMES_IN_FLIGHT];
|
QVarLengthArray<BufferUpdate, 16> pendingUpdates[QMTL_FRAMES_IN_FLIGHT];
|
||||||
@ -472,7 +472,7 @@ QRhiSwapChain *QRhiMetal::createSwapChain()
|
|||||||
return new QMetalSwapChain(this);
|
return new QMetalSwapChain(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
QRhiBuffer *QRhiMetal::createBuffer(QRhiBuffer::Type type, QRhiBuffer::UsageFlags usage, int size)
|
QRhiBuffer *QRhiMetal::createBuffer(QRhiBuffer::Type type, QRhiBuffer::UsageFlags usage, quint32 size)
|
||||||
{
|
{
|
||||||
return new QMetalBuffer(this, type, usage, size);
|
return new QMetalBuffer(this, type, usage, size);
|
||||||
}
|
}
|
||||||
@ -772,7 +772,7 @@ void QRhiMetal::enqueueShaderResourceBindings(QMetalShaderResourceBindings *srbD
|
|||||||
struct Buffer {
|
struct Buffer {
|
||||||
int nativeBinding;
|
int nativeBinding;
|
||||||
id<MTLBuffer> mtlbuf;
|
id<MTLBuffer> mtlbuf;
|
||||||
uint offset;
|
quint32 offset;
|
||||||
};
|
};
|
||||||
struct Texture {
|
struct Texture {
|
||||||
int nativeBinding;
|
int nativeBinding;
|
||||||
@ -799,7 +799,7 @@ void QRhiMetal::enqueueShaderResourceBindings(QMetalShaderResourceBindings *srbD
|
|||||||
{
|
{
|
||||||
QMetalBuffer *bufD = QRHI_RES(QMetalBuffer, b->u.ubuf.buf);
|
QMetalBuffer *bufD = QRHI_RES(QMetalBuffer, b->u.ubuf.buf);
|
||||||
id<MTLBuffer> mtlbuf = bufD->d->buf[bufD->d->slotted ? currentFrameSlot : 0];
|
id<MTLBuffer> mtlbuf = bufD->d->buf[bufD->d->slotted ? currentFrameSlot : 0];
|
||||||
uint offset = uint(b->u.ubuf.offset);
|
quint32 offset = b->u.ubuf.offset;
|
||||||
for (int i = 0; i < dynamicOffsetCount; ++i) {
|
for (int i = 0; i < dynamicOffsetCount; ++i) {
|
||||||
const QRhiCommandBuffer::DynamicOffset &dynOfs(dynamicOffsets[i]);
|
const QRhiCommandBuffer::DynamicOffset &dynOfs(dynamicOffsets[i]);
|
||||||
if (dynOfs.first == b->binding) {
|
if (dynOfs.first == b->binding) {
|
||||||
@ -895,7 +895,7 @@ void QRhiMetal::enqueueShaderResourceBindings(QMetalShaderResourceBindings *srbD
|
|||||||
{
|
{
|
||||||
QMetalBuffer *bufD = QRHI_RES(QMetalBuffer, b->u.sbuf.buf);
|
QMetalBuffer *bufD = QRHI_RES(QMetalBuffer, b->u.sbuf.buf);
|
||||||
id<MTLBuffer> mtlbuf = bufD->d->buf[0];
|
id<MTLBuffer> mtlbuf = bufD->d->buf[0];
|
||||||
uint offset = uint(b->u.sbuf.offset);
|
quint32 offset = b->u.sbuf.offset;
|
||||||
if (b->stage.testFlag(QRhiShaderResourceBinding::VertexStage)) {
|
if (b->stage.testFlag(QRhiShaderResourceBinding::VertexStage)) {
|
||||||
const int nativeBinding = mapBinding(b->binding, VERTEX, nativeResourceBindingMaps, BindingType::Buffer);
|
const int nativeBinding = mapBinding(b->binding, VERTEX, nativeResourceBindingMaps, BindingType::Buffer);
|
||||||
if (nativeBinding >= 0)
|
if (nativeBinding >= 0)
|
||||||
@ -1365,7 +1365,7 @@ void QRhiMetal::drawIndexed(QRhiCommandBuffer *cb, quint32 indexCount,
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
const quint32 indexOffset = cbD->currentIndexOffset + firstIndex * (cbD->currentIndexFormat == QRhiCommandBuffer::IndexUInt16 ? 2 : 4);
|
const quint32 indexOffset = cbD->currentIndexOffset + firstIndex * (cbD->currentIndexFormat == QRhiCommandBuffer::IndexUInt16 ? 2 : 4);
|
||||||
Q_ASSERT(indexOffset == aligned<quint32>(indexOffset, 4));
|
Q_ASSERT(indexOffset == aligned(indexOffset, 4u));
|
||||||
|
|
||||||
QMetalBuffer *ibufD = QRHI_RES(QMetalBuffer, cbD->currentIndexBuffer);
|
QMetalBuffer *ibufD = QRHI_RES(QMetalBuffer, cbD->currentIndexBuffer);
|
||||||
id<MTLBuffer> mtlbuf = ibufD->d->buf[ibufD->d->slotted ? currentFrameSlot : 0];
|
id<MTLBuffer> mtlbuf = ibufD->d->buf[ibufD->d->slotted ? currentFrameSlot : 0];
|
||||||
@ -1971,17 +1971,17 @@ void QRhiMetal::executeBufferHostWritesForSlot(QMetalBuffer *bufD, int slot)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
void *p = [bufD->d->buf[slot] contents];
|
void *p = [bufD->d->buf[slot] contents];
|
||||||
int changeBegin = -1;
|
quint32 changeBegin = UINT32_MAX;
|
||||||
int changeEnd = -1;
|
quint32 changeEnd = 0;
|
||||||
for (const QMetalBufferData::BufferUpdate &u : qAsConst(bufD->d->pendingUpdates[slot])) {
|
for (const QMetalBufferData::BufferUpdate &u : qAsConst(bufD->d->pendingUpdates[slot])) {
|
||||||
memcpy(static_cast<char *>(p) + u.offset, u.data.constData(), size_t(u.data.size()));
|
memcpy(static_cast<char *>(p) + u.offset, u.data.constData(), size_t(u.data.size()));
|
||||||
if (changeBegin == -1 || u.offset < changeBegin)
|
if (u.offset < changeBegin)
|
||||||
changeBegin = u.offset;
|
changeBegin = u.offset;
|
||||||
if (changeEnd == -1 || u.offset + u.data.size() > changeEnd)
|
if (u.offset + u.data.size() > changeEnd)
|
||||||
changeEnd = u.offset + u.data.size();
|
changeEnd = u.offset + u.data.size();
|
||||||
}
|
}
|
||||||
#ifdef Q_OS_MACOS
|
#ifdef Q_OS_MACOS
|
||||||
if (changeBegin >= 0 && bufD->d->managed)
|
if (changeBegin < UINT32_MAX && changeBegin < changeEnd && bufD->d->managed)
|
||||||
[bufD->d->buf[slot] didModifyRange: NSMakeRange(NSUInteger(changeBegin), NSUInteger(changeEnd - changeBegin))];
|
[bufD->d->buf[slot] didModifyRange: NSMakeRange(NSUInteger(changeBegin), NSUInteger(changeEnd - changeBegin))];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -2254,7 +2254,7 @@ void QRhiMetal::finishActiveReadbacks(bool forced)
|
|||||||
f();
|
f();
|
||||||
}
|
}
|
||||||
|
|
||||||
QMetalBuffer::QMetalBuffer(QRhiImplementation *rhi, Type type, UsageFlags usage, int size)
|
QMetalBuffer::QMetalBuffer(QRhiImplementation *rhi, Type type, UsageFlags usage, quint32 size)
|
||||||
: QRhiBuffer(rhi, type, usage, size),
|
: QRhiBuffer(rhi, type, usage, size),
|
||||||
d(new QMetalBufferData)
|
d(new QMetalBufferData)
|
||||||
{
|
{
|
||||||
@ -2300,8 +2300,8 @@ bool QMetalBuffer::create()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint nonZeroSize = m_size <= 0 ? 256 : uint(m_size);
|
const quint32 nonZeroSize = m_size <= 0 ? 256 : m_size;
|
||||||
const uint roundedSize = m_usage.testFlag(QRhiBuffer::UniformBuffer) ? aligned<uint>(nonZeroSize, 256) : nonZeroSize;
|
const quint32 roundedSize = m_usage.testFlag(QRhiBuffer::UniformBuffer) ? aligned(nonZeroSize, 256u) : nonZeroSize;
|
||||||
|
|
||||||
d->managed = false;
|
d->managed = false;
|
||||||
MTLResourceOptions opts = MTLResourceStorageModeShared;
|
MTLResourceOptions opts = MTLResourceStorageModeShared;
|
||||||
|
@ -28,7 +28,7 @@ struct QMetalBufferData;
|
|||||||
|
|
||||||
struct QMetalBuffer : public QRhiBuffer
|
struct QMetalBuffer : public QRhiBuffer
|
||||||
{
|
{
|
||||||
QMetalBuffer(QRhiImplementation *rhi, Type type, UsageFlags usage, int size);
|
QMetalBuffer(QRhiImplementation *rhi, Type type, UsageFlags usage, quint32 size);
|
||||||
~QMetalBuffer();
|
~QMetalBuffer();
|
||||||
void destroy() override;
|
void destroy() override;
|
||||||
bool create() override;
|
bool create() override;
|
||||||
@ -327,7 +327,7 @@ public:
|
|||||||
QRhiShaderResourceBindings *createShaderResourceBindings() override;
|
QRhiShaderResourceBindings *createShaderResourceBindings() override;
|
||||||
QRhiBuffer *createBuffer(QRhiBuffer::Type type,
|
QRhiBuffer *createBuffer(QRhiBuffer::Type type,
|
||||||
QRhiBuffer::UsageFlags usage,
|
QRhiBuffer::UsageFlags usage,
|
||||||
int size) override;
|
quint32 size) override;
|
||||||
QRhiRenderBuffer *createRenderBuffer(QRhiRenderBuffer::Type type,
|
QRhiRenderBuffer *createRenderBuffer(QRhiRenderBuffer::Type type,
|
||||||
const QSize &pixelSize,
|
const QSize &pixelSize,
|
||||||
int sampleCount,
|
int sampleCount,
|
||||||
|
@ -59,7 +59,7 @@ QRhiSwapChain *QRhiNull::createSwapChain()
|
|||||||
return new QNullSwapChain(this);
|
return new QNullSwapChain(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
QRhiBuffer *QRhiNull::createBuffer(QRhiBuffer::Type type, QRhiBuffer::UsageFlags usage, int size)
|
QRhiBuffer *QRhiNull::createBuffer(QRhiBuffer::Type type, QRhiBuffer::UsageFlags usage, quint32 size)
|
||||||
{
|
{
|
||||||
return new QNullBuffer(this, type, usage, size);
|
return new QNullBuffer(this, type, usage, size);
|
||||||
}
|
}
|
||||||
@ -550,7 +550,7 @@ void QRhiNull::endComputePass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *re
|
|||||||
resourceUpdate(cb, resourceUpdates);
|
resourceUpdate(cb, resourceUpdates);
|
||||||
}
|
}
|
||||||
|
|
||||||
QNullBuffer::QNullBuffer(QRhiImplementation *rhi, Type type, UsageFlags usage, int size)
|
QNullBuffer::QNullBuffer(QRhiImplementation *rhi, Type type, UsageFlags usage, quint32 size)
|
||||||
: QRhiBuffer(rhi, type, usage, size)
|
: QRhiBuffer(rhi, type, usage, size)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ QT_BEGIN_NAMESPACE
|
|||||||
|
|
||||||
struct QNullBuffer : public QRhiBuffer
|
struct QNullBuffer : public QRhiBuffer
|
||||||
{
|
{
|
||||||
QNullBuffer(QRhiImplementation *rhi, Type type, UsageFlags usage, int size);
|
QNullBuffer(QRhiImplementation *rhi, Type type, UsageFlags usage, quint32 size);
|
||||||
~QNullBuffer();
|
~QNullBuffer();
|
||||||
void destroy() override;
|
void destroy() override;
|
||||||
bool create() override;
|
bool create() override;
|
||||||
@ -183,7 +183,7 @@ public:
|
|||||||
QRhiShaderResourceBindings *createShaderResourceBindings() override;
|
QRhiShaderResourceBindings *createShaderResourceBindings() override;
|
||||||
QRhiBuffer *createBuffer(QRhiBuffer::Type type,
|
QRhiBuffer *createBuffer(QRhiBuffer::Type type,
|
||||||
QRhiBuffer::UsageFlags usage,
|
QRhiBuffer::UsageFlags usage,
|
||||||
int size) override;
|
quint32 size) override;
|
||||||
QRhiRenderBuffer *createRenderBuffer(QRhiRenderBuffer::Type type,
|
QRhiRenderBuffer *createRenderBuffer(QRhiRenderBuffer::Type type,
|
||||||
const QSize &pixelSize,
|
const QSize &pixelSize,
|
||||||
int sampleCount,
|
int sampleCount,
|
||||||
|
@ -2668,8 +2668,8 @@ void QRhiVulkan::updateShaderResourceBindings(QRhiShaderResourceBindings *srb, i
|
|||||||
bd.ubuf.generation = bufD->generation;
|
bd.ubuf.generation = bufD->generation;
|
||||||
VkDescriptorBufferInfo bufInfo;
|
VkDescriptorBufferInfo bufInfo;
|
||||||
bufInfo.buffer = bufD->m_type == QRhiBuffer::Dynamic ? bufD->buffers[frameSlot] : bufD->buffers[0];
|
bufInfo.buffer = bufD->m_type == QRhiBuffer::Dynamic ? bufD->buffers[frameSlot] : bufD->buffers[0];
|
||||||
bufInfo.offset = VkDeviceSize(b->u.ubuf.offset);
|
bufInfo.offset = b->u.ubuf.offset;
|
||||||
bufInfo.range = VkDeviceSize(b->u.ubuf.maybeSize ? b->u.ubuf.maybeSize : bufD->m_size);
|
bufInfo.range = b->u.ubuf.maybeSize ? b->u.ubuf.maybeSize : bufD->m_size;
|
||||||
// be nice and assert when we know the vulkan device would die a horrible death due to non-aligned reads
|
// be nice and assert when we know the vulkan device would die a horrible death due to non-aligned reads
|
||||||
Q_ASSERT(aligned(bufInfo.offset, ubufAlign) == bufInfo.offset);
|
Q_ASSERT(aligned(bufInfo.offset, ubufAlign) == bufInfo.offset);
|
||||||
bufferInfoIndex = bufferInfos.count();
|
bufferInfoIndex = bufferInfos.count();
|
||||||
@ -2764,8 +2764,8 @@ void QRhiVulkan::updateShaderResourceBindings(QRhiShaderResourceBindings *srb, i
|
|||||||
bd.sbuf.generation = bufD->generation;
|
bd.sbuf.generation = bufD->generation;
|
||||||
VkDescriptorBufferInfo bufInfo;
|
VkDescriptorBufferInfo bufInfo;
|
||||||
bufInfo.buffer = bufD->m_type == QRhiBuffer::Dynamic ? bufD->buffers[frameSlot] : bufD->buffers[0];
|
bufInfo.buffer = bufD->m_type == QRhiBuffer::Dynamic ? bufD->buffers[frameSlot] : bufD->buffers[0];
|
||||||
bufInfo.offset = VkDeviceSize(b->u.ubuf.offset);
|
bufInfo.offset = b->u.ubuf.offset;
|
||||||
bufInfo.range = VkDeviceSize(b->u.ubuf.maybeSize ? b->u.ubuf.maybeSize : bufD->m_size);
|
bufInfo.range = b->u.ubuf.maybeSize ? b->u.ubuf.maybeSize : bufD->m_size;
|
||||||
bufferInfoIndex = bufferInfos.count();
|
bufferInfoIndex = bufferInfos.count();
|
||||||
bufferInfos.append(bufInfo);
|
bufferInfos.append(bufInfo);
|
||||||
}
|
}
|
||||||
@ -3089,7 +3089,7 @@ void QRhiVulkan::enqueueResourceUpdates(QVkCommandBuffer *cbD, QRhiResourceUpdat
|
|||||||
bufferInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
|
bufferInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
|
||||||
// must cover the entire buffer - this way multiple, partial updates per frame
|
// must cover the entire buffer - this way multiple, partial updates per frame
|
||||||
// are supported even when the staging buffer is reused (Static)
|
// are supported even when the staging buffer is reused (Static)
|
||||||
bufferInfo.size = VkDeviceSize(bufD->m_size);
|
bufferInfo.size = bufD->m_size;
|
||||||
bufferInfo.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
|
bufferInfo.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
|
||||||
|
|
||||||
VmaAllocationCreateInfo allocInfo;
|
VmaAllocationCreateInfo allocInfo;
|
||||||
@ -3102,7 +3102,7 @@ void QRhiVulkan::enqueueResourceUpdates(QVkCommandBuffer *cbD, QRhiResourceUpdat
|
|||||||
if (err == VK_SUCCESS) {
|
if (err == VK_SUCCESS) {
|
||||||
bufD->stagingAllocations[currentFrameSlot] = allocation;
|
bufD->stagingAllocations[currentFrameSlot] = allocation;
|
||||||
} else {
|
} else {
|
||||||
qWarning("Failed to create staging buffer of size %d: %d", bufD->m_size, err);
|
qWarning("Failed to create staging buffer of size %u: %d", bufD->m_size, err);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3114,18 +3114,18 @@ void QRhiVulkan::enqueueResourceUpdates(QVkCommandBuffer *cbD, QRhiResourceUpdat
|
|||||||
qWarning("Failed to map buffer: %d", err);
|
qWarning("Failed to map buffer: %d", err);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
memcpy(static_cast<uchar *>(p) + u.offset, u.data.constData(), size_t(u.data.size()));
|
memcpy(static_cast<uchar *>(p) + u.offset, u.data.constData(), u.data.size());
|
||||||
vmaUnmapMemory(toVmaAllocator(allocator), a);
|
vmaUnmapMemory(toVmaAllocator(allocator), a);
|
||||||
vmaFlushAllocation(toVmaAllocator(allocator), a, VkDeviceSize(u.offset), VkDeviceSize(u.data.size()));
|
vmaFlushAllocation(toVmaAllocator(allocator), a, u.offset, u.data.size());
|
||||||
|
|
||||||
trackedBufferBarrier(cbD, bufD, 0,
|
trackedBufferBarrier(cbD, bufD, 0,
|
||||||
VK_ACCESS_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT);
|
VK_ACCESS_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT);
|
||||||
|
|
||||||
VkBufferCopy copyInfo;
|
VkBufferCopy copyInfo;
|
||||||
memset(©Info, 0, sizeof(copyInfo));
|
memset(©Info, 0, sizeof(copyInfo));
|
||||||
copyInfo.srcOffset = VkDeviceSize(u.offset);
|
copyInfo.srcOffset = u.offset;
|
||||||
copyInfo.dstOffset = VkDeviceSize(u.offset);
|
copyInfo.dstOffset = u.offset;
|
||||||
copyInfo.size = VkDeviceSize(u.data.size());
|
copyInfo.size = u.data.size();
|
||||||
|
|
||||||
QVkCommandBuffer::Command &cmd(cbD->commands.get());
|
QVkCommandBuffer::Command &cmd(cbD->commands.get());
|
||||||
cmd.cmd = QVkCommandBuffer::Command::CopyBuffer;
|
cmd.cmd = QVkCommandBuffer::Command::CopyBuffer;
|
||||||
@ -3161,7 +3161,7 @@ void QRhiVulkan::enqueueResourceUpdates(QVkCommandBuffer *cbD, QRhiResourceUpdat
|
|||||||
VkResult err = vmaMapMemory(toVmaAllocator(allocator), a, &p);
|
VkResult err = vmaMapMemory(toVmaAllocator(allocator), a, &p);
|
||||||
if (err == VK_SUCCESS) {
|
if (err == VK_SUCCESS) {
|
||||||
u.result->data.resize(u.readSize);
|
u.result->data.resize(u.readSize);
|
||||||
memcpy(u.result->data.data(), reinterpret_cast<char *>(p) + u.offset, size_t(u.readSize));
|
memcpy(u.result->data.data(), reinterpret_cast<char *>(p) + u.offset, u.readSize);
|
||||||
vmaUnmapMemory(toVmaAllocator(allocator), a);
|
vmaUnmapMemory(toVmaAllocator(allocator), a);
|
||||||
}
|
}
|
||||||
if (u.result->completed)
|
if (u.result->completed)
|
||||||
@ -3181,7 +3181,7 @@ void QRhiVulkan::enqueueResourceUpdates(QVkCommandBuffer *cbD, QRhiResourceUpdat
|
|||||||
VkBufferCreateInfo bufferInfo;
|
VkBufferCreateInfo bufferInfo;
|
||||||
memset(&bufferInfo, 0, sizeof(bufferInfo));
|
memset(&bufferInfo, 0, sizeof(bufferInfo));
|
||||||
bufferInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
|
bufferInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
|
||||||
bufferInfo.size = VkDeviceSize(readback.byteSize);
|
bufferInfo.size = readback.byteSize;
|
||||||
bufferInfo.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
|
bufferInfo.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
|
||||||
|
|
||||||
VmaAllocationCreateInfo allocInfo;
|
VmaAllocationCreateInfo allocInfo;
|
||||||
@ -3201,8 +3201,8 @@ void QRhiVulkan::enqueueResourceUpdates(QVkCommandBuffer *cbD, QRhiResourceUpdat
|
|||||||
|
|
||||||
VkBufferCopy copyInfo;
|
VkBufferCopy copyInfo;
|
||||||
memset(©Info, 0, sizeof(copyInfo));
|
memset(©Info, 0, sizeof(copyInfo));
|
||||||
copyInfo.srcOffset = VkDeviceSize(u.offset);
|
copyInfo.srcOffset = u.offset;
|
||||||
copyInfo.size = VkDeviceSize(u.readSize);
|
copyInfo.size = u.readSize;
|
||||||
|
|
||||||
QVkCommandBuffer::Command &cmd(cbD->commands.get());
|
QVkCommandBuffer::Command &cmd(cbD->commands.get());
|
||||||
cmd.cmd = QVkCommandBuffer::Command::CopyBuffer;
|
cmd.cmd = QVkCommandBuffer::Command::CopyBuffer;
|
||||||
@ -3573,18 +3573,18 @@ void QRhiVulkan::executeBufferHostWritesForSlot(QVkBuffer *bufD, int slot)
|
|||||||
qWarning("Failed to map buffer: %d", err);
|
qWarning("Failed to map buffer: %d", err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int changeBegin = -1;
|
quint32 changeBegin = UINT32_MAX;
|
||||||
int changeEnd = -1;
|
quint32 changeEnd = 0;
|
||||||
for (const QVkBuffer::DynamicUpdate &u : qAsConst(bufD->pendingDynamicUpdates[slot])) {
|
for (const QVkBuffer::DynamicUpdate &u : qAsConst(bufD->pendingDynamicUpdates[slot])) {
|
||||||
memcpy(static_cast<char *>(p) + u.offset, u.data.constData(), size_t(u.data.size()));
|
memcpy(static_cast<char *>(p) + u.offset, u.data.constData(), u.data.size());
|
||||||
if (changeBegin == -1 || u.offset < changeBegin)
|
if (u.offset < changeBegin)
|
||||||
changeBegin = u.offset;
|
changeBegin = u.offset;
|
||||||
if (changeEnd == -1 || u.offset + u.data.size() > changeEnd)
|
if (u.offset + u.data.size() > changeEnd)
|
||||||
changeEnd = u.offset + u.data.size();
|
changeEnd = u.offset + u.data.size();
|
||||||
}
|
}
|
||||||
vmaUnmapMemory(toVmaAllocator(allocator), a);
|
vmaUnmapMemory(toVmaAllocator(allocator), a);
|
||||||
if (changeBegin >= 0)
|
if (changeBegin < UINT32_MAX && changeBegin < changeEnd)
|
||||||
vmaFlushAllocation(toVmaAllocator(allocator), a, VkDeviceSize(changeBegin), VkDeviceSize(changeEnd - changeBegin));
|
vmaFlushAllocation(toVmaAllocator(allocator), a, changeBegin, changeEnd - changeBegin);
|
||||||
|
|
||||||
bufD->pendingDynamicUpdates[slot].clear();
|
bufD->pendingDynamicUpdates[slot].clear();
|
||||||
}
|
}
|
||||||
@ -3712,7 +3712,7 @@ void QRhiVulkan::finishActiveReadbacks(bool forced)
|
|||||||
VkResult err = vmaMapMemory(toVmaAllocator(allocator), a, &p);
|
VkResult err = vmaMapMemory(toVmaAllocator(allocator), a, &p);
|
||||||
if (err == VK_SUCCESS && p) {
|
if (err == VK_SUCCESS && p) {
|
||||||
readback.result->data.resize(readback.byteSize);
|
readback.result->data.resize(readback.byteSize);
|
||||||
memcpy(readback.result->data.data(), p, size_t(readback.byteSize));
|
memcpy(readback.result->data.data(), p, readback.byteSize);
|
||||||
vmaUnmapMemory(toVmaAllocator(allocator), a);
|
vmaUnmapMemory(toVmaAllocator(allocator), a);
|
||||||
} else {
|
} else {
|
||||||
qWarning("Failed to map buffer readback buffer of size %d: %d", readback.byteSize, err);
|
qWarning("Failed to map buffer readback buffer of size %d: %d", readback.byteSize, err);
|
||||||
@ -4159,7 +4159,7 @@ QRhiSwapChain *QRhiVulkan::createSwapChain()
|
|||||||
return new QVkSwapChain(this);
|
return new QVkSwapChain(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
QRhiBuffer *QRhiVulkan::createBuffer(QRhiBuffer::Type type, QRhiBuffer::UsageFlags usage, int size)
|
QRhiBuffer *QRhiVulkan::createBuffer(QRhiBuffer::Type type, QRhiBuffer::UsageFlags usage, quint32 size)
|
||||||
{
|
{
|
||||||
return new QVkBuffer(this, type, usage, size);
|
return new QVkBuffer(this, type, usage, size);
|
||||||
}
|
}
|
||||||
@ -5575,7 +5575,7 @@ static inline VkCompareOp toVkTextureCompareOp(QRhiSampler::CompareOp op)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QVkBuffer::QVkBuffer(QRhiImplementation *rhi, Type type, UsageFlags usage, int size)
|
QVkBuffer::QVkBuffer(QRhiImplementation *rhi, Type type, UsageFlags usage, quint32 size)
|
||||||
: QRhiBuffer(rhi, type, usage, size)
|
: QRhiBuffer(rhi, type, usage, size)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < QVK_FRAMES_IN_FLIGHT; ++i) {
|
for (int i = 0; i < QVK_FRAMES_IN_FLIGHT; ++i) {
|
||||||
@ -5631,12 +5631,12 @@ bool QVkBuffer::create()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const int nonZeroSize = m_size <= 0 ? 256 : m_size;
|
const quint32 nonZeroSize = m_size <= 0 ? 256 : m_size;
|
||||||
|
|
||||||
VkBufferCreateInfo bufferInfo;
|
VkBufferCreateInfo bufferInfo;
|
||||||
memset(&bufferInfo, 0, sizeof(bufferInfo));
|
memset(&bufferInfo, 0, sizeof(bufferInfo));
|
||||||
bufferInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
|
bufferInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
|
||||||
bufferInfo.size = uint32_t(nonZeroSize);
|
bufferInfo.size = nonZeroSize;
|
||||||
bufferInfo.usage = toVkBufferUsage(m_usage);
|
bufferInfo.usage = toVkBufferUsage(m_usage);
|
||||||
|
|
||||||
VmaAllocationCreateInfo allocInfo;
|
VmaAllocationCreateInfo allocInfo;
|
||||||
|
@ -39,7 +39,7 @@ typedef void * QVkAllocator;
|
|||||||
|
|
||||||
struct QVkBuffer : public QRhiBuffer
|
struct QVkBuffer : public QRhiBuffer
|
||||||
{
|
{
|
||||||
QVkBuffer(QRhiImplementation *rhi, Type type, UsageFlags usage, int size);
|
QVkBuffer(QRhiImplementation *rhi, Type type, UsageFlags usage, quint32 size);
|
||||||
~QVkBuffer();
|
~QVkBuffer();
|
||||||
void destroy() override;
|
void destroy() override;
|
||||||
bool create() override;
|
bool create() override;
|
||||||
@ -50,7 +50,7 @@ struct QVkBuffer : public QRhiBuffer
|
|||||||
VkBuffer buffers[QVK_FRAMES_IN_FLIGHT];
|
VkBuffer buffers[QVK_FRAMES_IN_FLIGHT];
|
||||||
QVkAlloc allocations[QVK_FRAMES_IN_FLIGHT];
|
QVkAlloc allocations[QVK_FRAMES_IN_FLIGHT];
|
||||||
struct DynamicUpdate {
|
struct DynamicUpdate {
|
||||||
int offset;
|
quint32 offset;
|
||||||
QRhiBufferData data;
|
QRhiBufferData data;
|
||||||
};
|
};
|
||||||
QVarLengthArray<DynamicUpdate, 16> pendingDynamicUpdates[QVK_FRAMES_IN_FLIGHT];
|
QVarLengthArray<DynamicUpdate, 16> pendingDynamicUpdates[QVK_FRAMES_IN_FLIGHT];
|
||||||
@ -640,7 +640,7 @@ public:
|
|||||||
QRhiShaderResourceBindings *createShaderResourceBindings() override;
|
QRhiShaderResourceBindings *createShaderResourceBindings() override;
|
||||||
QRhiBuffer *createBuffer(QRhiBuffer::Type type,
|
QRhiBuffer *createBuffer(QRhiBuffer::Type type,
|
||||||
QRhiBuffer::UsageFlags usage,
|
QRhiBuffer::UsageFlags usage,
|
||||||
int size) override;
|
quint32 size) override;
|
||||||
QRhiRenderBuffer *createRenderBuffer(QRhiRenderBuffer::Type type,
|
QRhiRenderBuffer *createRenderBuffer(QRhiRenderBuffer::Type type,
|
||||||
const QSize &pixelSize,
|
const QSize &pixelSize,
|
||||||
int sampleCount,
|
int sampleCount,
|
||||||
@ -913,7 +913,7 @@ public:
|
|||||||
struct BufferReadback {
|
struct BufferReadback {
|
||||||
int activeFrameSlot = -1;
|
int activeFrameSlot = -1;
|
||||||
QRhiBufferReadbackResult *result;
|
QRhiBufferReadbackResult *result;
|
||||||
int byteSize;
|
quint32 byteSize;
|
||||||
VkBuffer stagingBuf;
|
VkBuffer stagingBuf;
|
||||||
QVkAlloc stagingAlloc;
|
QVkAlloc stagingAlloc;
|
||||||
};
|
};
|
||||||
|
@ -1051,7 +1051,7 @@ void tst_QRhi::resourceUpdateBatchRGBATextureUpload()
|
|||||||
|
|
||||||
QRhiResourceUpdateBatch *batch = rhi->nextResourceUpdateBatch();
|
QRhiResourceUpdateBatch *batch = rhi->nextResourceUpdateBatch();
|
||||||
|
|
||||||
QRhiTextureUploadEntry upload(0, 0, { image.constBits(), int(image.sizeInBytes()) });
|
QRhiTextureUploadEntry upload(0, 0, { image.constBits(), quint32(image.sizeInBytes()) });
|
||||||
QRhiTextureUploadDescription uploadDesc(upload);
|
QRhiTextureUploadDescription uploadDesc(upload);
|
||||||
batch->uploadTexture(texture.data(), uploadDesc);
|
batch->uploadTexture(texture.data(), uploadDesc);
|
||||||
|
|
||||||
@ -1139,8 +1139,8 @@ void tst_QRhi::resourceUpdateBatchRGBATextureUpload()
|
|||||||
// SourceTopLeft is not supported for non-QImage-based uploads.
|
// SourceTopLeft is not supported for non-QImage-based uploads.
|
||||||
const QImage im = image.copy(QRect(greenRectPos, copySize));
|
const QImage im = image.copy(QRect(greenRectPos, copySize));
|
||||||
QRhiTextureSubresourceUploadDescription desc;
|
QRhiTextureSubresourceUploadDescription desc;
|
||||||
desc.setData(QByteArray::fromRawData(reinterpret_cast<const char *>(im.constBits()),
|
desc.setData(QByteArray::fromRawData(reinterpret_cast<const char *>(im.constBits()), im.sizeInBytes()));
|
||||||
int(im.sizeInBytes())));
|
|
||||||
desc.setSourceSize(copySize);
|
desc.setSourceSize(copySize);
|
||||||
desc.setDestinationTopLeft(QPoint(gap, gap));
|
desc.setDestinationTopLeft(QPoint(gap, gap));
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ void Window::customRender()
|
|||||||
}
|
}
|
||||||
if (!d.compressedData.isEmpty()) {
|
if (!d.compressedData.isEmpty()) {
|
||||||
{
|
{
|
||||||
QRhiTextureUploadDescription desc({ 0, 0, { d.compressedData[0].constData(), int(d.compressedData[0].size()) } });
|
QRhiTextureUploadDescription desc({ 0, 0, { d.compressedData[0].constData(), quint32(d.compressedData[0].size()) } });
|
||||||
u->uploadTexture(d.tex, desc);
|
u->uploadTexture(d.tex, desc);
|
||||||
d.compressedData.clear();
|
d.compressedData.clear();
|
||||||
}
|
}
|
||||||
|
@ -242,7 +242,7 @@ void Window::customInit()
|
|||||||
qint32 flip = 1;
|
qint32 flip = 1;
|
||||||
d.initialUpdates->updateDynamicBuffer(d.ubuf, 64, 4, &flip);
|
d.initialUpdates->updateDynamicBuffer(d.ubuf, 64, 4, &flip);
|
||||||
|
|
||||||
QRhiTextureUploadDescription desc({ 0, 0, { floatData.constData(), int(floatData.size()) } });
|
QRhiTextureUploadDescription desc({ 0, 0, { floatData.constData(), quint32(floatData.size()) } });
|
||||||
d.initialUpdates->uploadTexture(d.tex, desc);
|
d.initialUpdates->uploadTexture(d.tex, desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user