Commit c446d98d authored by Laszlo Agocs's avatar Laszlo Agocs

constify the struct in nativeHandles and buildFrom

parent cf56f87a
......@@ -251,11 +251,11 @@ void Window::customRender()
// Exercise texture object export/import.
if (d.testStage == 6) {
QRhiNativeHandles *h = d.tex->nativeHandles();
const QRhiNativeHandles *h = d.tex->nativeHandles();
if (h) {
#ifdef Q_OS_DARWIN
if (graphicsApi == Metal) {
qDebug() << "Metal texture: " << static_cast<QRhiMetalTextureNativeHandles *>(h)->texture;
qDebug() << "Metal texture: " << static_cast<const QRhiMetalTextureNativeHandles *>(h)->texture;
// Now could cast to id<MTLTexture> and do something with
// it, keeping in mind that copy operations are only done
// in beginPass, while rendering into a texture may only
......
......@@ -85,12 +85,12 @@ QRhiTexture::QRhiTexture(QRhiImplementation *rhi, Format format_, const QSize &p
{
}
QRhiNativeHandles *QRhiTexture::nativeHandles()
const QRhiNativeHandles *QRhiTexture::nativeHandles()
{
return nullptr;
}
bool QRhiTexture::buildFrom(QRhiNativeHandles *src)
bool QRhiTexture::buildFrom(const QRhiNativeHandles *src)
{
Q_UNUSED(src);
return false;
......@@ -640,11 +640,16 @@ bool QRhi::isFeatureSupported(QRhi::Feature feature) const
return d->isFeatureSupported(feature);
}
QRhiNativeHandles *QRhi::nativeHandles()
const QRhiNativeHandles *QRhi::nativeHandles()
{
return d->nativeHandles();
}
const QRhiProfiler *QRhi::profiler() const
{
return &d->profiler;
}
QRhiGraphicsPipeline *QRhi::newGraphicsPipeline()
{
return d->createGraphicsPipeline();
......
......@@ -58,6 +58,7 @@ class QRhiSampler;
class QRhiCommandBuffer;
class QRhiResourceUpdateBatch;
struct QRhiResourceUpdateBatchPrivate;
class QRhiProfiler;
// C++ object ownership rules:
// 1. new*() and create() return value owned by the caller.
......@@ -478,13 +479,13 @@ public:
// Returns a ptr to a QRhi<backend>TextureNativeHandles struct.
// Ownership of the native objects is not transfered.
virtual QRhiNativeHandles *nativeHandles();
virtual const QRhiNativeHandles *nativeHandles();
// Calling this instead of build() allows importing an existing native
// texture object (must belong to the same device or a sharing context).
// Note that format, pixelSize, etc. must still be set correctly (typically
// via QRhi::newTexture()). Ownership of the native resource is not taken.
virtual bool buildFrom(QRhiNativeHandles *src);
virtual bool buildFrom(const QRhiNativeHandles *src);
protected:
QRhiTexture(QRhiImplementation *rhi, Format format_, const QSize &pixelSize_,
......@@ -1237,7 +1238,9 @@ public:
// Returns a ptr to a QRhi<backend>NativeHandles struct.
// Ownership of the native objects is not transfered.
QRhiNativeHandles *nativeHandles();
const QRhiNativeHandles *nativeHandles();
const QRhiProfiler *profiler() const;
protected:
QRhi();
......
......@@ -43,6 +43,7 @@
#include "qtrhiglobal_p.h"
#include "qrhi.h"
#include "qrhiprofiler_p.h"
#include <QBitArray>
QT_BEGIN_NAMESPACE
......@@ -126,7 +127,7 @@ public:
virtual QMatrix4x4 clipSpaceCorrMatrix() const = 0;
virtual bool isTextureFormatSupported(QRhiTexture::Format format, QRhiTexture::Flags flags) const = 0;
virtual bool isFeatureSupported(QRhi::Feature) const = 0;
virtual QRhiNativeHandles *nativeHandles() = 0;
virtual const QRhiNativeHandles *nativeHandles() = 0;
bool isCompressedFormat(QRhiTexture::Format format) const;
void compressedFormatInfo(QRhiTexture::Format format, const QSize &size,
......@@ -138,6 +139,7 @@ public:
protected:
QVector<QRhiResourceUpdateBatch *> resUpdPool;
QBitArray resUpdPoolMap;
QRhiProfiler profiler;
friend class QRhi;
friend struct QRhiResourceUpdateBatchPrivate;
......
......@@ -255,7 +255,7 @@ bool QRhiD3D11::isFeatureSupported(QRhi::Feature feature) const
}
}
QRhiNativeHandles *QRhiD3D11::nativeHandles()
const QRhiNativeHandles *QRhiD3D11::nativeHandles()
{
return &nativeHandlesStruct;
}
......
......@@ -485,7 +485,7 @@ public:
QMatrix4x4 clipSpaceCorrMatrix() const override;
bool isTextureFormatSupported(QRhiTexture::Format format, QRhiTexture::Flags flags) const override;
bool isFeatureSupported(QRhi::Feature feature) const override;
QRhiNativeHandles *nativeHandles() override;
const QRhiNativeHandles *nativeHandles() override;
void enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resourceUpdates);
void updateShaderResourceBindings(QD3D11ShaderResourceBindings *srbD);
......
......@@ -266,7 +266,7 @@ bool QRhiGles2::isFeatureSupported(QRhi::Feature feature) const
}
}
QRhiNativeHandles *QRhiGles2::nativeHandles()
const QRhiNativeHandles *QRhiGles2::nativeHandles()
{
return &nativeHandlesStruct;
}
......@@ -1709,9 +1709,9 @@ bool QGles2Texture::build()
return true;
}
bool QGles2Texture::buildFrom(QRhiNativeHandles *src)
bool QGles2Texture::buildFrom(const QRhiNativeHandles *src)
{
QRhiGles2TextureNativeHandles *h = static_cast<QRhiGles2TextureNativeHandles *>(src);
const QRhiGles2TextureNativeHandles *h = static_cast<const QRhiGles2TextureNativeHandles *>(src);
if (!h || !h->texture)
return false;
......@@ -1728,7 +1728,7 @@ bool QGles2Texture::buildFrom(QRhiNativeHandles *src)
return true;
}
QRhiNativeHandles *QGles2Texture::nativeHandles()
const QRhiNativeHandles *QGles2Texture::nativeHandles()
{
return &nativeHandlesStruct;
}
......
......@@ -91,8 +91,8 @@ struct QGles2Texture : public QRhiTexture
int sampleCount, Flags flags);
void release() override;
bool build() override;
bool buildFrom(QRhiNativeHandles *src) override;
QRhiNativeHandles *nativeHandles() override;
bool buildFrom(const QRhiNativeHandles *src) override;
const QRhiNativeHandles *nativeHandles() override;
bool prepareBuild(QSize *adjustedSize = nullptr);
......@@ -507,7 +507,7 @@ public:
QMatrix4x4 clipSpaceCorrMatrix() const override;
bool isTextureFormatSupported(QRhiTexture::Format format, QRhiTexture::Flags flags) const override;
bool isFeatureSupported(QRhi::Feature feature) const override;
QRhiNativeHandles *nativeHandles() override;
const QRhiNativeHandles *nativeHandles() override;
bool ensureContext(QSurface *surface = nullptr) const;
void executeDeferredReleases();
......
......@@ -340,7 +340,7 @@ bool QRhiMetal::isFeatureSupported(QRhi::Feature feature) const
}
}
QRhiNativeHandles *QRhiMetal::nativeHandles()
const QRhiNativeHandles *QRhiMetal::nativeHandles()
{
return &nativeHandlesStruct;
}
......@@ -1536,9 +1536,9 @@ bool QMetalTexture::build()
return true;
}
bool QMetalTexture::buildFrom(QRhiNativeHandles *src)
bool QMetalTexture::buildFrom(const QRhiNativeHandles *src)
{
QRhiMetalTextureNativeHandles *h = static_cast<QRhiMetalTextureNativeHandles *>(src);
const QRhiMetalTextureNativeHandles *h = static_cast<const QRhiMetalTextureNativeHandles *>(src);
if (!h || !h->texture)
return false;
......@@ -1555,7 +1555,7 @@ bool QMetalTexture::buildFrom(QRhiNativeHandles *src)
return true;
}
QRhiNativeHandles *QMetalTexture::nativeHandles()
const QRhiNativeHandles *QMetalTexture::nativeHandles()
{
return &nativeHandlesStruct;
}
......
......@@ -93,8 +93,8 @@ struct QMetalTexture : public QRhiTexture
~QMetalTexture();
void release() override;
bool build() override;
bool buildFrom(QRhiNativeHandles *src) override;
QRhiNativeHandles *nativeHandles() override;
bool buildFrom(const QRhiNativeHandles *src) override;
const QRhiNativeHandles *nativeHandles() override;
bool prepareBuild(QSize *adjustedSize = nullptr);
......@@ -322,7 +322,7 @@ public:
QMatrix4x4 clipSpaceCorrMatrix() const override;
bool isTextureFormatSupported(QRhiTexture::Format format, QRhiTexture::Flags flags) const override;
bool isFeatureSupported(QRhi::Feature feature) const override;
QRhiNativeHandles *nativeHandles() override;
const QRhiNativeHandles *nativeHandles() override;
void executeDeferredReleases(bool forced = false);
void finishActiveReadbacks(bool forced = false);
......
......@@ -38,4 +38,14 @@
QT_BEGIN_NAMESPACE
QRhiProfiler::QRhiProfiler()
: d(new QRhiProfilerPrivate)
{
}
QRhiProfiler::~QRhiProfiler()
{
delete d;
}
QT_END_NAMESPACE
......@@ -41,9 +41,17 @@
QT_BEGIN_NAMESPACE
class QRhiProfilerPrivate;
class Q_RHI_EXPORT QRhiProfiler
{
public:
QRhiProfiler();
~QRhiProfiler();
private:
QRhiProfilerPrivate *d;
friend class QRhiProfilerPrivate;
};
QT_END_NAMESPACE
......
......@@ -46,6 +46,12 @@
QT_BEGIN_NAMESPACE
class QRhiProfilerPrivate
{
public:
static QRhiProfilerPrivate *get(QRhiProfiler *p) { return p->d; }
};
QT_END_NAMESPACE
#endif
......@@ -2637,7 +2637,7 @@ bool QRhiVulkan::isFeatureSupported(QRhi::Feature feature) const
}
}
QRhiNativeHandles *QRhiVulkan::nativeHandles()
const QRhiNativeHandles *QRhiVulkan::nativeHandles()
{
return &nativeHandlesStruct;
}
......@@ -3531,9 +3531,9 @@ bool QVkTexture::build()
return true;
}
bool QVkTexture::buildFrom(QRhiNativeHandles *src)
bool QVkTexture::buildFrom(const QRhiNativeHandles *src)
{
QRhiVulkanTextureNativeHandles *h = static_cast<QRhiVulkanTextureNativeHandles *>(src);
const QRhiVulkanTextureNativeHandles *h = static_cast<const QRhiVulkanTextureNativeHandles *>(src);
if (!h || !h->image)
return false;
......@@ -3550,7 +3550,7 @@ bool QVkTexture::buildFrom(QRhiNativeHandles *src)
return true;
}
QRhiNativeHandles *QVkTexture::nativeHandles()
const QRhiNativeHandles *QVkTexture::nativeHandles()
{
nativeHandlesStruct.layout = layout;
return &nativeHandlesStruct;
......
......@@ -103,8 +103,8 @@ struct QVkTexture : public QRhiTexture
int sampleCount, Flags flags);
void release() override;
bool build() override;
bool buildFrom(QRhiNativeHandles *src) override;
QRhiNativeHandles *nativeHandles() override;
bool buildFrom(const QRhiNativeHandles *src) override;
const QRhiNativeHandles *nativeHandles() override;
bool prepareBuild(QSize *adjustedSize = nullptr);
bool finishBuild();
......@@ -393,7 +393,7 @@ public:
QMatrix4x4 clipSpaceCorrMatrix() const override;
bool isTextureFormatSupported(QRhiTexture::Format format, QRhiTexture::Flags flags) const override;
bool isFeatureSupported(QRhi::Feature feature) const override;
QRhiNativeHandles *nativeHandles() override;
const QRhiNativeHandles *nativeHandles() override;
VkResult createDescriptorPool(VkDescriptorPool *pool);
bool allocateDescriptorSet(VkDescriptorSetAllocateInfo *allocInfo, VkDescriptorSet *result, int *resultPoolIndex);
......
texture export
texture import
d3d: texture import/export
add a basic resource info (profiler) api
multiwindow_threaded should demo pulling out the device and importing to another rhi
mtl: reduce set*
advanced blend modes
......
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