summaryrefslogtreecommitdiffstats
path: root/src/gui/rhi/qrhi_p.h
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@qt.io>2019-09-28 14:43:58 +0200
committerLaszlo Agocs <laszlo.agocs@qt.io>2019-09-30 20:07:36 +0200
commitd4c17725abe381d247d6c453dafe87b8e17e80de (patch)
tree9e3438ec23e08dac26a0407c243d91c794fffcec /src/gui/rhi/qrhi_p.h
parente1ed2c3864e2b9aeeebec25de60ab62eb254b591 (diff)
De-d-pointer QRhiShaderResourceBinding
Sad to see this go since the d pointer pattern with implicit sharing would have been perfect for this class, had this been a public API. However, as binary compatibility will not be a concern for QRhi classes, it is wasteful to allocate memory on every QRhiShaderResourceBinding. This allows users, such as Qt Quick, to use QRhiShaderResourceBinding as a cheap, simple, value class, without having to invent their own alternatives in performance critical places. The change brings a not insignficant improvement in certain qmlbench scenes (the ones with thousands of unbatched geometry nodes). Change-Id: I6d1dced6498d9ad625f90ead78bc0a417ea99ed8 Reviewed-by: Christian Strømme <christian.stromme@qt.io>
Diffstat (limited to 'src/gui/rhi/qrhi_p.h')
-rw-r--r--src/gui/rhi/qrhi_p.h50
1 files changed, 38 insertions, 12 deletions
diff --git a/src/gui/rhi/qrhi_p.h b/src/gui/rhi/qrhi_p.h
index c73f03cf72..fec69c607f 100644
--- a/src/gui/rhi/qrhi_p.h
+++ b/src/gui/rhi/qrhi_p.h
@@ -320,10 +320,6 @@ public:
Q_DECLARE_FLAGS(StageFlags, StageFlag)
QRhiShaderResourceBinding();
- QRhiShaderResourceBinding(const QRhiShaderResourceBinding &other);
- QRhiShaderResourceBinding &operator=(const QRhiShaderResourceBinding &other);
- ~QRhiShaderResourceBinding();
- void detach();
bool isLayoutCompatible(const QRhiShaderResourceBinding &other) const;
@@ -344,19 +340,49 @@ public:
static QRhiShaderResourceBinding bufferLoadStore(int binding, StageFlags stage, QRhiBuffer *buf);
static QRhiShaderResourceBinding bufferLoadStore(int binding, StageFlags stage, QRhiBuffer *buf, int offset, int size);
+ struct Data
+ {
+ int binding;
+ QRhiShaderResourceBinding::StageFlags stage;
+ QRhiShaderResourceBinding::Type type;
+ struct UniformBufferData {
+ QRhiBuffer *buf;
+ int offset;
+ int maybeSize;
+ bool hasDynamicOffset;
+ };
+ struct SampledTextureData {
+ QRhiTexture *tex;
+ QRhiSampler *sampler;
+ };
+ struct StorageImageData {
+ QRhiTexture *tex;
+ int level;
+ };
+ struct StorageBufferData {
+ QRhiBuffer *buf;
+ int offset;
+ int maybeSize;
+ };
+ union {
+ UniformBufferData ubuf;
+ SampledTextureData stex;
+ StorageImageData simage;
+ StorageBufferData sbuf;
+ } u;
+ };
+
+ Data *data() { return &d; }
+ const Data *data() const { return &d; }
+
private:
- QRhiShaderResourceBindingPrivate *d;
- friend class QRhiShaderResourceBindingPrivate;
- friend Q_GUI_EXPORT bool operator==(const QRhiShaderResourceBinding &, const QRhiShaderResourceBinding &) Q_DECL_NOTHROW;
- friend Q_GUI_EXPORT bool operator!=(const QRhiShaderResourceBinding &, const QRhiShaderResourceBinding &) Q_DECL_NOTHROW;
- friend Q_GUI_EXPORT uint qHash(const QRhiShaderResourceBinding &, uint) Q_DECL_NOTHROW;
-#ifndef QT_NO_DEBUG_STREAM
- friend Q_GUI_EXPORT QDebug operator<<(QDebug, const QRhiShaderResourceBinding &);
-#endif
+ Data d;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiShaderResourceBinding::StageFlags)
+Q_DECLARE_TYPEINFO(QRhiShaderResourceBinding, Q_MOVABLE_TYPE);
+
Q_GUI_EXPORT bool operator==(const QRhiShaderResourceBinding &a, const QRhiShaderResourceBinding &b) Q_DECL_NOTHROW;
Q_GUI_EXPORT bool operator!=(const QRhiShaderResourceBinding &a, const QRhiShaderResourceBinding &b) Q_DECL_NOTHROW;
Q_GUI_EXPORT uint qHash(const QRhiShaderResourceBinding &b, uint seed = 0) Q_DECL_NOTHROW;