Vulkan: move sidecar ownership to VulkanTexture.

This commit is contained in:
Philip Rideout
2021-07-20 10:17:33 -07:00
committed by Mathias Agopian
parent ee82f76846
commit cdb0bb9490
4 changed files with 16 additions and 17 deletions

View File

@@ -163,8 +163,12 @@ VulkanRenderTarget::VulkanRenderTarget(VulkanContext& context, uint32_t width, u
const VulkanAttachment& spec = color[index];
VulkanTexture* texture = spec.texture;
if (texture && texture->samples == 1) {
VulkanTexture* msTexture = new VulkanTexture(context, texture->target, level,
texture->format, samples, width, height, depth, texture->usage, stagePool);
VulkanTexture* msTexture = texture->getSidecar();
if (UTILS_UNLIKELY(msTexture == nullptr)) {
msTexture = new VulkanTexture(context, texture->target, level,
texture->format, samples, width, height, depth, texture->usage, stagePool);
texture->setSidecar(msTexture);
}
mMsaaAttachments[index] = createAttachment(context, { .texture = msTexture });
mMsaaAttachments[index].view = msTexture->getAttachmentView(0, 0,
VK_IMAGE_ASPECT_COLOR_BIT);
@@ -185,8 +189,12 @@ VulkanRenderTarget::VulkanRenderTarget(VulkanContext& context, uint32_t width, u
}
// Create sidecar MSAA texture for the depth attachment.
VulkanTexture* msTexture = new VulkanTexture(context, depthTexture->target, level,
depthTexture->format, samples, width, height, depth, depthTexture->usage, stagePool);
VulkanTexture* msTexture = depthTexture->getSidecar();
if (UTILS_UNLIKELY(msTexture == nullptr)) {
msTexture = new VulkanTexture(context, depthTexture->target, level,
depthTexture->format, samples, width, height, depth, depthTexture->usage, stagePool);
depthTexture->setSidecar(msTexture);
}
mMsaaDepthAttachment = createAttachment(context, {
.format = {},
.image = {},
@@ -201,17 +209,6 @@ VulkanRenderTarget::VulkanRenderTarget(VulkanContext& context, uint32_t width, u
VK_IMAGE_ASPECT_DEPTH_BIT);
}
VulkanRenderTarget::~VulkanRenderTarget() {
for (int index = 0; index < MRT::MAX_SUPPORTED_RENDER_TARGET_COUNT; index++) {
if (mMsaaAttachments[index].texture != mColor[index].texture) {
delete mMsaaAttachments[index].texture;
}
}
if (mMsaaDepthAttachment.texture != mDepth.texture) {
delete mMsaaDepthAttachment.texture;
}
}
void VulkanRenderTarget::transformClientRectToPlatform(VulkanSwapChain* currentSurface, VkRect2D* bounds) const {
const auto& extent = getExtent(currentSurface);
flipVertically(bounds, extent.height);

View File

@@ -53,8 +53,6 @@ struct VulkanRenderTarget : private HwRenderTarget {
// Creates a special "default" render target (i.e. associated with the swap chain)
explicit VulkanRenderTarget(VulkanContext& context);
~VulkanRenderTarget();
void transformClientRectToPlatform(VulkanSwapChain* currentSurface, VkRect2D* bounds) const;
void transformClientRectToPlatform(VulkanSwapChain* currentSurface, VkViewport* bounds) const;
VkExtent2D getExtent(VulkanSwapChain* currentSurface) const;

View File

@@ -245,6 +245,7 @@ VulkanTexture::VulkanTexture(VulkanContext& context, SamplerType target, uint8_t
}
VulkanTexture::~VulkanTexture() {
delete mSidecarMSAA;
vkDestroyImage(mContext.device, mTextureImage, VKALLOC);
vkFreeMemory(mContext.device, mTextureImageMemory, VKALLOC);
for (auto entry : mCachedImageViews) {

View File

@@ -49,6 +49,8 @@ struct VulkanTexture : public HwTexture {
VkFormat getVkFormat() const { return mVkFormat; }
VkImage getVkImage() const { return mTextureImage; }
void setSidecar(VulkanTexture* sidecar) { mSidecarMSAA = sidecar; }
VulkanTexture* getSidecar() const { return mSidecarMSAA; }
private:
// Gets or creates a cached VkImageView for a range of miplevels and array layers.
@@ -67,6 +69,7 @@ private:
void updateWithBlitImage(const PixelBufferDescriptor& hostData, uint32_t width,
uint32_t height, uint32_t depth, int miplevel);
VulkanTexture* mSidecarMSAA = nullptr;
const VkFormat mVkFormat;
const VkComponentMapping mSwizzle;
VkImageViewType mViewType;