RHI: Remove old native texture API

Task-number: QTBUG-78570
Change-Id: I8c4850828ac03319ac923a26c2e985883956c286
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
This commit is contained in:
Paul Olav Tvete 2019-12-17 15:15:24 +01:00
parent 908df199d0
commit 844ef184e8
18 changed files with 7 additions and 330 deletions

View File

@ -2214,20 +2214,6 @@ QRhiResource::Type QRhiTexture::resourceType() const
Regardless of the return value, calling release() is always safe.
*/
/*!
\return a pointer to a backend-specific QRhiNativeHandles subclass, such as
QRhiVulkanTextureNativeHandles. The returned value is null when exposing
the underlying native resources is not supported by the backend.
\sa QRhiVulkanTextureNativeHandles, QRhiD3D11TextureNativeHandles,
QRhiMetalTextureNativeHandles, QRhiGles2TextureNativeHandles
*/
// TODO: remove this version once QtQuick has stopped using it
const QRhiNativeHandles *QRhiTexture::nativeHandles()
{
return nullptr;
}
/*!
\return the underlying native resources for this texture. The returned value
will be empty if exposing the underlying native resources is not supported by
@ -2240,36 +2226,6 @@ QRhiTexture::NativeTexture QRhiTexture::nativeTexture()
return {};
}
/*!
Similar to build() except that no new native textures are created. Instead,
the texture from \a src is used.
This allows importing an existing native texture object (which must belong
to the same device or sharing context, depending on the graphics API) from
an external graphics engine.
\note format(), pixelSize(), sampleCount(), and flags() must still be set
correctly. Passing incorrect sizes and other values to QRhi::newTexture()
and then following it with a buildFrom() expecting that the native texture
object alone is sufficient to deduce such values is \b wrong and will lead
to problems.
\note QRhiTexture does not take ownership of the texture object. release()
does not free the object or any associated memory.
The opposite of this operation, exposing a QRhiTexture-created native
texture object to a foreign engine, is possible via nativeHandles().
\sa QRhiVulkanTextureNativeHandles, QRhiD3D11TextureNativeHandles,
QRhiMetalTextureNativeHandles, QRhiGles2TextureNativeHandles
*/
// TODO: remove this version once QtQuick has stopped using it
bool QRhiTexture::buildFrom(const QRhiNativeHandles *src)
{
Q_UNUSED(src);
return false;
}
/*!
Similar to build() except that no new native textures are created. Instead,
the native texture resources specified by \a src is used.

View File

@ -780,9 +780,7 @@ public:
void setSampleCount(int s) { m_sampleCount = s; }
virtual bool build() = 0;
virtual const QRhiNativeHandles *nativeHandles();
virtual NativeTexture nativeTexture();
virtual bool buildFrom(const QRhiNativeHandles *src);
virtual bool buildFrom(NativeTexture src);
protected:

View File

@ -108,17 +108,6 @@ QT_BEGIN_NAMESPACE
\c{ID3D11Device *} and \c{ID3D11DeviceContext *}.
*/
/*!
\class QRhiD3D11TextureNativeHandles
\internal
\inmodule QtGui
\brief Holds the D3D texture object that is backing a QRhiTexture instance.
\note The class uses \c{void *} as the type since including the COM-based
\c{d3d11.h} headers is not acceptable here. The actual type is
\c{ID3D11Texture2D *}.
*/
// help mingw with its ancient sdk headers
#ifndef DXGI_ADAPTER_FLAG_SOFTWARE
#define DXGI_ADAPTER_FLAG_SOFTWARE 2
@ -2674,8 +2663,6 @@ bool QD3D11Texture::finishBuild()
return false;
}
nativeHandlesStruct.texture = tex;
generation += 1;
return true;
}
@ -2741,29 +2728,6 @@ bool QD3D11Texture::build()
return true;
}
bool QD3D11Texture::buildFrom(const QRhiNativeHandles *src)
{
const QRhiD3D11TextureNativeHandles *h = static_cast<const QRhiD3D11TextureNativeHandles *>(src);
if (!h || !h->texture)
return false;
if (!prepareBuild())
return false;
tex = static_cast<ID3D11Texture2D *>(h->texture);
if (!finishBuild())
return false;
QRHI_PROF;
QRHI_PROF_F(newTexture(this, false, int(mipLevelCount), m_flags.testFlag(CubeMap) ? 6 : 1, int(sampleDesc.Count)));
owns = false;
QRHI_RES_RHI(QRhiD3D11);
rhiD->registerResource(this);
return true;
}
bool QD3D11Texture::buildFrom(QRhiTexture::NativeTexture src)
{
auto *srcTex = static_cast<ID3D11Texture2D * const *>(src.object);
@ -2787,14 +2751,9 @@ bool QD3D11Texture::buildFrom(QRhiTexture::NativeTexture src)
return true;
}
const QRhiNativeHandles *QD3D11Texture::nativeHandles()
{
return &nativeHandlesStruct;
}
QRhiTexture::NativeTexture QD3D11Texture::nativeTexture()
{
return {&nativeHandlesStruct.texture, 0};
return {&tex, 0};
}
ID3D11UnorderedAccessView *QD3D11Texture::unorderedAccessViewForLevel(int level)

View File

@ -69,11 +69,6 @@ struct Q_GUI_EXPORT QRhiD3D11NativeHandles : public QRhiNativeHandles
void *context = nullptr;
};
struct Q_GUI_EXPORT QRhiD3D11TextureNativeHandles : public QRhiNativeHandles
{
void *texture = nullptr; // ID3D11Texture2D*
};
QT_END_NAMESPACE
#endif

View File

@ -99,9 +99,7 @@ struct QD3D11Texture : public QRhiTexture
~QD3D11Texture();
void release() override;
bool build() override;
bool buildFrom(const QRhiNativeHandles *src) override;
bool buildFrom(NativeTexture src) override;
const QRhiNativeHandles *nativeHandles() override;
NativeTexture nativeTexture() override;
bool prepareBuild(QSize *adjustedSize = nullptr);
@ -114,7 +112,6 @@ struct QD3D11Texture : public QRhiTexture
DXGI_FORMAT dxgiFormat;
uint mipLevelCount = 0;
DXGI_SAMPLE_DESC sampleDesc;
QRhiD3D11TextureNativeHandles nativeHandlesStruct;
ID3D11UnorderedAccessView *perLevelViews[QRhi::MAX_LEVELS];
uint generation = 0;
friend class QRhiD3D11;

View File

@ -137,13 +137,6 @@ QT_BEGIN_NAMESPACE
\brief Holds the OpenGL context used by the QRhi.
*/
/*!
\class QRhiGles2TextureNativeHandles
\internal
\inmodule QtGui
\brief Holds the OpenGL texture object that is backing a QRhiTexture instance.
*/
#ifndef GL_BGRA
#define GL_BGRA 0x80E1
#endif
@ -3324,7 +3317,6 @@ void QGles2Texture::release()
texture = 0;
specified = false;
nativeHandlesStruct.texture = 0;
QRHI_RES_RHI(QRhiGles2);
if (owns)
@ -3483,31 +3475,6 @@ bool QGles2Texture::build()
QRHI_PROF_F(newTexture(this, true, mipLevelCount, isCube ? 6 : 1, 1));
owns = true;
nativeHandlesStruct.texture = texture;
generation += 1;
rhiD->registerResource(this);
return true;
}
bool QGles2Texture::buildFrom(const QRhiNativeHandles *src)
{
const QRhiGles2TextureNativeHandles *h = static_cast<const QRhiGles2TextureNativeHandles *>(src);
if (!h || !h->texture)
return false;
if (!prepareBuild())
return false;
texture = h->texture;
specified = true;
QRHI_RES_RHI(QRhiGles2);
QRHI_PROF;
QRHI_PROF_F(newTexture(this, false, mipLevelCount, m_flags.testFlag(CubeMap) ? 6 : 1, 1));
owns = false;
nativeHandlesStruct.texture = texture;
generation += 1;
rhiD->registerResource(this);
@ -3531,21 +3498,15 @@ bool QGles2Texture::buildFrom(QRhiTexture::NativeTexture src)
QRHI_PROF_F(newTexture(this, false, mipLevelCount, m_flags.testFlag(CubeMap) ? 6 : 1, 1));
owns = false;
nativeHandlesStruct.texture = texture;
generation += 1;
rhiD->registerResource(this);
return true;
}
const QRhiNativeHandles *QGles2Texture::nativeHandles()
{
return &nativeHandlesStruct;
}
QRhiTexture::NativeTexture QGles2Texture::nativeTexture()
{
return {&nativeHandlesStruct.texture, 0};
return {&texture, 0};
}
QGles2Sampler::QGles2Sampler(QRhiImplementation *rhi, Filter magFilter, Filter minFilter, Filter mipmapMode,

View File

@ -74,11 +74,6 @@ struct Q_GUI_EXPORT QRhiGles2NativeHandles : public QRhiNativeHandles
QOpenGLContext *context = nullptr;
};
struct Q_GUI_EXPORT QRhiGles2TextureNativeHandles : public QRhiNativeHandles
{
uint texture = 0;
};
QT_END_NAMESPACE
#endif

View File

@ -132,9 +132,7 @@ struct QGles2Texture : public QRhiTexture
~QGles2Texture();
void release() override;
bool build() override;
bool buildFrom(const QRhiNativeHandles *src) override;
bool buildFrom(NativeTexture src) override;
const QRhiNativeHandles *nativeHandles() override;
NativeTexture nativeTexture() override;
bool prepareBuild(QSize *adjustedSize = nullptr);
@ -149,7 +147,7 @@ struct QGles2Texture : public QRhiTexture
QGles2SamplerData samplerState;
bool specified = false;
int mipLevelCount = 0;
QRhiGles2TextureNativeHandles nativeHandlesStruct;
enum Access {
AccessNone,
AccessSample,

View File

@ -113,15 +113,6 @@ QT_BEGIN_NAMESPACE
\c{id<MTLCommandQueue>}.
*/
/*!
\class QRhiMetalTextureNativeHandles
\inmodule QtRhi
\brief Holds the Metal texture object that is backing a QRhiTexture instance.
\note The class uses \c{void *} as the type since including the Objective C
headers is not acceptable here. The actual type is \c{id<MTLTexture>}.
*/
/*!
\class QRhiMetalCommandBufferNativeHandles
\inmodule QtRhi
@ -2296,7 +2287,6 @@ void QMetalTexture::release()
e.texture.texture = d->owns ? d->tex : nil;
d->tex = nil;
nativeHandlesStruct.texture = nullptr;
for (int i = 0; i < QMTL_FRAMES_IN_FLIGHT; ++i) {
e.texture.stagingBuffers[i] = d->stagingBuf[i];
@ -2508,7 +2498,6 @@ bool QMetalTexture::build()
d->tex.label = [NSString stringWithUTF8String: m_objectName.constData()];
d->owns = true;
nativeHandlesStruct.texture = d->tex;
QRHI_PROF;
QRHI_PROF_F(newTexture(this, true, mipLevelCount, isCube ? 6 : 1, samples));
@ -2519,30 +2508,6 @@ bool QMetalTexture::build()
return true;
}
bool QMetalTexture::buildFrom(const QRhiNativeHandles *src)
{
const QRhiMetalTextureNativeHandles *h = static_cast<const QRhiMetalTextureNativeHandles *>(src);
if (!h || !h->texture)
return false;
if (!prepareBuild())
return false;
d->tex = (id<MTLTexture>) h->texture;
d->owns = false;
nativeHandlesStruct.texture = d->tex;
QRHI_PROF;
QRHI_PROF_F(newTexture(this, false, mipLevelCount, m_flags.testFlag(CubeMap) ? 6 : 1, samples));
lastActiveFrameSlot = -1;
generation += 1;
QRHI_RES_RHI(QRhiMetal);
rhiD->registerResource(this);
return true;
}
bool QMetalTexture::buildFrom(QRhiTexture::NativeTexture src)
{
void * const * tex = (void * const *) src.object;
@ -2555,7 +2520,6 @@ bool QMetalTexture::buildFrom(QRhiTexture::NativeTexture src)
d->tex = (id<MTLTexture>) *tex;
d->owns = false;
nativeHandlesStruct.texture = d->tex;
QRHI_PROF;
QRHI_PROF_F(newTexture(this, false, mipLevelCount, m_flags.testFlag(CubeMap) ? 6 : 1, samples));
@ -2567,14 +2531,9 @@ bool QMetalTexture::buildFrom(QRhiTexture::NativeTexture src)
return true;
}
const QRhiNativeHandles *QMetalTexture::nativeHandles()
{
return &nativeHandlesStruct;
}
QRhiTexture::NativeTexture QMetalTexture::nativeTexture()
{
return {&nativeHandlesStruct.texture, 0};
return {&d->tex, 0};
}
id<MTLTexture> QMetalTextureData::viewForLevel(int level)

View File

@ -64,11 +64,6 @@ struct Q_GUI_EXPORT QRhiMetalNativeHandles : public QRhiNativeHandles
void *cmdQueue = nullptr; // id<MTLCommandQueue>
};
struct Q_GUI_EXPORT QRhiMetalTextureNativeHandles : public QRhiNativeHandles
{
void *texture = nullptr; // id<MTLTexture>
};
struct Q_GUI_EXPORT QRhiMetalCommandBufferNativeHandles : public QRhiNativeHandles
{
void *commandBuffer = nullptr; // id<MTLCommandBuffer>

View File

@ -100,15 +100,12 @@ struct QMetalTexture : public QRhiTexture
~QMetalTexture();
void release() override;
bool build() override;
bool buildFrom(const QRhiNativeHandles *src) override;
bool buildFrom(NativeTexture src) override;
const QRhiNativeHandles *nativeHandles() override;
NativeTexture nativeTexture() override;
bool prepareBuild(QSize *adjustedSize = nullptr);
QMetalTextureData *d;
QRhiMetalTextureNativeHandles nativeHandlesStruct;
int mipLevelCount = 0;
int samples = 1;
uint generation = 0;

View File

@ -67,13 +67,6 @@ QT_BEGIN_NAMESPACE
\brief Empty.
*/
/*!
\class QRhiNullTextureNativeHandles
\internal
\inmodule QtGui
\brief Empty.
*/
QRhiNull::QRhiNull(QRhiNullInitParams *params)
: offscreenCommandBuffer(this)
{
@ -638,9 +631,9 @@ bool QNullTexture::build()
return true;
}
bool QNullTexture::buildFrom(const QRhiNativeHandles *src)
bool QNullTexture::buildFrom(QRhiTexture::NativeTexture src)
{
Q_UNUSED(src);
Q_UNUSED(src)
QRHI_RES_RHI(QRhiNull);
const bool isCube = m_flags.testFlag(CubeMap);
const bool hasMipMaps = m_flags.testFlag(MipMapped);
@ -651,17 +644,6 @@ bool QNullTexture::buildFrom(const QRhiNativeHandles *src)
return true;
}
bool QNullTexture::buildFrom(QRhiTexture::NativeTexture src)
{
Q_UNUSED(src)
return buildFrom(nullptr);
}
const QRhiNativeHandles *QNullTexture::nativeHandles()
{
return &nativeHandlesStruct;
}
QNullSampler::QNullSampler(QRhiImplementation *rhi, Filter magFilter, Filter minFilter, Filter mipmapMode,
AddressMode u, AddressMode v)
: QRhiSampler(rhi, magFilter, minFilter, mipmapMode, u, v)

View File

@ -60,10 +60,6 @@ struct Q_GUI_EXPORT QRhiNullNativeHandles : public QRhiNativeHandles
{
};
struct Q_GUI_EXPORT QRhiNullTextureNativeHandles : public QRhiNativeHandles
{
};
QT_END_NAMESPACE
#endif

View File

@ -80,11 +80,8 @@ struct QNullTexture : public QRhiTexture
~QNullTexture();
void release() override;
bool build() override;
bool buildFrom(const QRhiNativeHandles *src) override;
bool buildFrom(NativeTexture src) override;
const QRhiNativeHandles *nativeHandles() override;
QRhiNullTextureNativeHandles nativeHandlesStruct;
QImage image[QRhi::MAX_LAYERS][QRhi::MAX_LEVELS];
};

View File

@ -176,21 +176,6 @@ QT_BEGIN_NAMESPACE
\note Ownership of the Vulkan objects is never transferred.
*/
/*!
\class QRhiVulkanTextureNativeHandles
\internal
\inmodule QtGui
\brief Holds the Vulkan image object that is backing a QRhiTexture.
Importing and exporting Vulkan image objects that back a QRhiTexture when
running with the Vulkan backend is supported via this class. Ownership of
the Vulkan object is never transferred.
\note Memory allocation details are not exposed. This is intentional since
memory is typically suballocated from a bigger chunk of VkDeviceMemory, and
exposing the allocator details is not desirable for now.
*/
/*!
\class QRhiVulkanCommandBufferNativeHandles
\internal
@ -5198,7 +5183,6 @@ void QVkTexture::release()
image = VK_NULL_HANDLE;
imageView = VK_NULL_HANDLE;
imageAlloc = nullptr;
nativeHandlesStruct.image = VK_NULL_HANDLE;
QRHI_RES_RHI(QRhiVulkan);
rhiD->releaseQueue.append(e);
@ -5283,8 +5267,6 @@ bool QVkTexture::finishBuild()
return false;
}
nativeHandlesStruct.image = image;
lastActiveFrameSlot = -1;
generation += 1;
@ -5356,31 +5338,6 @@ bool QVkTexture::build()
return true;
}
bool QVkTexture::buildFrom(const QRhiNativeHandles *src)
{
const QRhiVulkanTextureNativeHandles *h = static_cast<const QRhiVulkanTextureNativeHandles *>(src);
if (!h || !h->image)
return false;
if (!prepareBuild())
return false;
image = h->image;
if (!finishBuild())
return false;
QRHI_PROF;
QRHI_PROF_F(newTexture(this, false, int(mipLevelCount), m_flags.testFlag(CubeMap) ? 6 : 1, samples));
usageState.layout = h->layout;
owns = false;
QRHI_RES_RHI(QRhiVulkan);
rhiD->registerResource(this);
return true;
}
bool QVkTexture::buildFrom(QRhiTexture::NativeTexture src)
{
auto *img = static_cast<const VkImage*>(src.object);
@ -5406,15 +5363,9 @@ bool QVkTexture::buildFrom(QRhiTexture::NativeTexture src)
return true;
}
const QRhiNativeHandles *QVkTexture::nativeHandles()
{
nativeHandlesStruct.layout = usageState.layout;
return &nativeHandlesStruct;
}
QRhiTexture::NativeTexture QVkTexture::nativeTexture()
{
return {&nativeHandlesStruct.image, usageState.layout};
return {&image, usageState.layout};
}
VkImageView QVkTexture::imageViewForLevel(int level)

View File

@ -69,12 +69,6 @@ struct Q_GUI_EXPORT QRhiVulkanNativeHandles : public QRhiNativeHandles
void *vmemAllocator = nullptr;
};
struct Q_GUI_EXPORT QRhiVulkanTextureNativeHandles : public QRhiNativeHandles
{
VkImage image = VK_NULL_HANDLE;
VkImageLayout layout = VK_IMAGE_LAYOUT_GENERAL;
};
struct Q_GUI_EXPORT QRhiVulkanCommandBufferNativeHandles : public QRhiNativeHandles
{
VkCommandBuffer commandBuffer = VK_NULL_HANDLE;

View File

@ -120,9 +120,7 @@ struct QVkTexture : public QRhiTexture
~QVkTexture();
void release() override;
bool build() override;
bool buildFrom(const QRhiNativeHandles *src) override;
bool buildFrom(NativeTexture src) override;
const QRhiNativeHandles *nativeHandles() override;
NativeTexture nativeTexture() override;
bool prepareBuild(QSize *adjustedSize = nullptr);
@ -136,7 +134,6 @@ struct QVkTexture : public QRhiTexture
QVkAlloc stagingAllocations[QVK_FRAMES_IN_FLIGHT];
VkImageView perLevelImageViews[QRhi::MAX_LEVELS];
bool owns = true;
QRhiVulkanTextureNativeHandles nativeHandlesStruct;
struct UsageState {
// no tracking of subresource layouts (some operations can keep
// subresources in different layouts for some time, but that does not

View File

@ -381,56 +381,6 @@ void tst_QRhi::nativeHandles()
}
}
// QRhiTexture::nativeHandles()
{
QScopedPointer<QRhiTexture> tex(rhi->newTexture(QRhiTexture::RGBA8, QSize(512, 256)));
QVERIFY(tex->build());
const QRhiNativeHandles *texHandles = tex->nativeHandles();
QVERIFY(texHandles);
switch (impl) {
case QRhi::Null:
break;
#ifdef TST_VK
case QRhi::Vulkan:
{
const QRhiVulkanTextureNativeHandles *vkHandles = static_cast<const QRhiVulkanTextureNativeHandles *>(texHandles);
QVERIFY(vkHandles->image);
QVERIFY(vkHandles->layout >= 1); // VK_IMAGE_LAYOUT_GENERAL
QVERIFY(vkHandles->layout <= 8); // VK_IMAGE_LAYOUT_PREINITIALIZED
}
break;
#endif
#ifdef TST_GL
case QRhi::OpenGLES2:
{
const QRhiGles2TextureNativeHandles *glHandles = static_cast<const QRhiGles2TextureNativeHandles *>(texHandles);
QVERIFY(glHandles->texture);
}
break;
#endif
#ifdef TST_D3D11
case QRhi::D3D11:
{
const QRhiD3D11TextureNativeHandles *d3dHandles = static_cast<const QRhiD3D11TextureNativeHandles *>(texHandles);
QVERIFY(d3dHandles->texture);
}
break;
#endif
#ifdef TST_MTL
case QRhi::Metal:
{
const QRhiMetalTextureNativeHandles *mtlHandles = static_cast<const QRhiMetalTextureNativeHandles *>(texHandles);
QVERIFY(mtlHandles->texture);
}
break;
#endif
default:
Q_ASSERT(false);
}
}
// QRhiCommandBuffer::nativeHandles()
{
QRhiCommandBuffer *cb = nullptr;