Return handle when getting simple render pass in vulkan.

We then store this handle on the GrVkFramebuffer. This will be used in
follow on CL to help remove the use of GrVkRenderTarget in the
GrVkOpsRenderPass.

Bug: skia:11809
Change-Id: I979de4e474be1d5e5683dc263fe347cfb63b2342
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/393376
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
This commit is contained in:
Greg Daniel 2021-04-07 11:08:36 -04:00 committed by Skia Commit-Bot
parent cbbd5653da
commit a92d78704d
5 changed files with 50 additions and 26 deletions

View File

@ -1842,8 +1842,8 @@ GrProgramDesc GrVkCaps::makeDesc(GrRenderTarget* rt,
bool needsStencil = programInfo.numStencilSamples() || programInfo.isStencilEnabled();
// TODO: support failure in getSimpleRenderPass
const GrVkRenderPass* rp = vkRT->getSimpleRenderPass(needsResolve, needsStencil,
selfDepFlags, loadFromResolve);
auto[rp, compatibleHandle] = vkRT->getSimpleRenderPass(needsResolve, needsStencil,
selfDepFlags, loadFromResolve);
SkASSERT(rp);
rp->genKey(&b);

View File

@ -12,12 +12,14 @@
#include "src/gpu/vk/GrVkImageView.h"
#include "src/gpu/vk/GrVkRenderPass.h"
GrVkFramebuffer* GrVkFramebuffer::Create(GrVkGpu* gpu,
int width, int height,
const GrVkRenderPass* renderPass,
const GrVkAttachment* colorAttachment,
const GrVkAttachment* resolveAttachment,
const GrVkAttachment* stencilAttachment) {
GrVkFramebuffer* GrVkFramebuffer::Create(
GrVkGpu* gpu,
int width, int height,
const GrVkRenderPass* renderPass,
const GrVkAttachment* colorAttachment,
const GrVkAttachment* resolveAttachment,
const GrVkAttachment* stencilAttachment,
GrVkResourceProvider::CompatibleRPHandle compatibleRenderPassHandle) {
// At the very least we need a renderPass and a colorAttachment
SkASSERT(renderPass);
SkASSERT(colorAttachment);
@ -53,7 +55,8 @@ GrVkFramebuffer* GrVkFramebuffer::Create(GrVkGpu* gpu,
}
return new GrVkFramebuffer(gpu, framebuffer, sk_ref_sp(colorAttachment),
sk_ref_sp(resolveAttachment), sk_ref_sp(stencilAttachment));
sk_ref_sp(resolveAttachment), sk_ref_sp(stencilAttachment),
compatibleRenderPassHandle);
}
GrVkFramebuffer::~GrVkFramebuffer() {}

View File

@ -11,6 +11,7 @@
#include "include/gpu/GrTypes.h"
#include "include/gpu/vk/GrVkTypes.h"
#include "src/gpu/vk/GrVkManagedResource.h"
#include "src/gpu/vk/GrVkResourceProvider.h"
class GrVkAttachment;
class GrVkGpu;
@ -24,7 +25,8 @@ public:
const GrVkRenderPass* renderPass,
const GrVkAttachment* colorAttachment,
const GrVkAttachment* resolveAttachment,
const GrVkAttachment* stencilAttachment);
const GrVkAttachment* stencilAttachment,
GrVkResourceProvider::CompatibleRPHandle);
VkFramebuffer framebuffer() const { return fFramebuffer; }
@ -34,17 +36,23 @@ public:
}
#endif
GrVkResourceProvider::CompatibleRPHandle compatibleRenderPassHandle() const {
return fCompatibleRenderPassHandle;
}
private:
GrVkFramebuffer(const GrVkGpu* gpu,
VkFramebuffer framebuffer,
sk_sp<GrVkAttachment> colorAttachment,
sk_sp<GrVkAttachment> resolveAttachment,
sk_sp<GrVkAttachment> stencilAttachment)
sk_sp<GrVkAttachment> stencilAttachment,
GrVkResourceProvider::CompatibleRPHandle compatibleRenderPassHandle)
: INHERITED(gpu)
, fFramebuffer(framebuffer)
, fColorAttachment(std::move(colorAttachment))
, fResolveAttachment(std::move(resolveAttachment))
, fStencilAttachment(std::move(stencilAttachment)) {}
, fStencilAttachment(std::move(stencilAttachment))
, fCompatibleRenderPassHandle(compatibleRenderPassHandle) {}
~GrVkFramebuffer() override;
@ -56,6 +64,8 @@ private:
sk_sp<const GrVkAttachment> fResolveAttachment;
sk_sp<const GrVkAttachment> fStencilAttachment;
GrVkResourceProvider::CompatibleRPHandle fCompatibleRenderPassHandle;
using INHERITED = GrVkManagedResource;
};

View File

@ -226,18 +226,27 @@ GrVkResourceProvider::CompatibleRPHandle GrVkRenderTarget::compatibleRenderPassH
return *pRPHandle;
}
const GrVkRenderPass* GrVkRenderTarget::getSimpleRenderPass(bool withResolve,
bool withStencil,
SelfDependencyFlags selfDepFlags,
LoadFromResolve loadFromResolve) {
std::pair<const GrVkRenderPass*, GrVkResourceProvider::CompatibleRPHandle>
GrVkRenderTarget::getSimpleRenderPass(bool withResolve,
bool withStencil,
SelfDependencyFlags selfDepFlags,
LoadFromResolve loadFromResolve) {
int cacheIndex = renderpass_features_to_index(withResolve, withStencil, selfDepFlags,
loadFromResolve);
SkASSERT(cacheIndex < GrVkRenderTarget::kNumCachedRenderPasses);
if (const GrVkRenderPass* rp = fCachedRenderPasses[cacheIndex]) {
return rp;
const GrVkRenderPass* rp = fCachedRenderPasses[cacheIndex];
if (this->wrapsSecondaryCommandBuffer()) {
SkASSERT(rp);
// The compatible handle is invalid for external render passes used in wrapped secondary
// command buffers. However, this should not be called by code using external render passes
// that needs to use the handle.
return {rp, GrVkResourceProvider::CompatibleRPHandle()};
}
return this->createSimpleRenderPass(withResolve, withStencil, selfDepFlags, loadFromResolve);
if (!rp) {
rp = this->createSimpleRenderPass(withResolve, withStencil, selfDepFlags, loadFromResolve);
}
SkASSERT(!rp || fCompatibleRPHandles[cacheIndex].isValid());
return {rp, fCompatibleRPHandles[cacheIndex]};
}
const GrVkRenderPass* GrVkRenderTarget::createSimpleRenderPass(bool withResolve,
@ -278,11 +287,12 @@ const GrVkFramebuffer* GrVkRenderTarget::createFramebuffer(bool withResolve,
SkASSERT(!this->wrapsSecondaryCommandBuffer());
GrVkGpu* gpu = this->getVkGpu();
const GrVkRenderPass* renderPass =
auto[renderPass, compatibleHandle] =
this->getSimpleRenderPass(withResolve, withStencil, selfDepFlags, loadFromResolve);
if (!renderPass) {
return nullptr;
}
SkASSERT(compatibleHandle.isValid());
int cacheIndex =
renderpass_features_to_index(withResolve, withStencil, selfDepFlags, loadFromResolve);
@ -296,7 +306,7 @@ const GrVkFramebuffer* GrVkRenderTarget::createFramebuffer(bool withResolve,
: nullptr;
fCachedFramebuffers[cacheIndex] =
GrVkFramebuffer::Create(gpu, this->width(), this->height(), renderPass,
this->colorAttachment(), resolve, stencil);
this->colorAttachment(), resolve, stencil, compatibleHandle);
return fCachedFramebuffers[cacheIndex];
}

View File

@ -74,10 +74,11 @@ public:
return fResolveAttachment ? fResolveAttachment.get() : fColorAttachment.get();
}
const GrVkRenderPass* getSimpleRenderPass(bool withResolve,
bool withStencil,
SelfDependencyFlags selfDepFlags,
LoadFromResolve);
std::pair<const GrVkRenderPass*, GrVkResourceProvider::CompatibleRPHandle> getSimpleRenderPass(
bool withResolve,
bool withStencil,
SelfDependencyFlags selfDepFlags,
LoadFromResolve);
GrVkResourceProvider::CompatibleRPHandle compatibleRenderPassHandle(
bool withResolve,
bool withStencil,