28#define VK_CALL(GPU, X) GR_VK_CALL(GPU->vkInterface(), X)
59 std::string_view label)
67 colorAttachment->numSamples(),
70 , fColorAttachment(
std::move(colorAttachment))
71 , fResolveAttachment(
std::move(resolveAttachment))
72 , fCachedFramebuffers() {
80 fResolveAttachment = fColorAttachment;
95 std::string_view label)
98 externalFramebuffer->colorAttachment()->isProtected() ?
GrProtected::
kYes
104 externalFramebuffer->colorAttachment()->isProtected() ?
GrProtected::
kYes
107 , fCachedFramebuffers()
108 , fExternalFramebuffer(externalFramebuffer) {
120void GrVkRenderTarget::setFlags() {
140 int wrappedImageSampleCnt =
static_cast<int>(
info.fSampleCount);
141 if (sampleCnt != wrappedImageSampleCnt && wrappedImageSampleCnt != 1) {
149 std::move(mutableState),
153 "VkImage_WrappedAttachment");
154 if (!wrappedAttachment) {
170 "Vk_MakeWrappedRenderTarget");
202 std::move(mutableState),
206 "VkImage_ColorAttachment",
209 std::unique_ptr<GrVkSecondaryCommandBuffer> scb(
221 "Vk_MakeSecondaryCBRenderTarget");
235 return fColorAttachment.
get();
237 return fResolveAttachment.
get();
241GrVkImage* GrVkRenderTarget::dynamicMSAAAttachment() {
242 if (fDynamicMSAAAttachment) {
243 return fDynamicMSAAAttachment.
get();
248 GrVkGpu* gpu = this->getVkGpu();
257 rp->getDiscardableMSAAAttachment(nonMSAAColorAttachment->
dimensions(),
262 if (!msaaAttachment) {
266 return fDynamicMSAAAttachment.
get();
269GrVkImage* GrVkRenderTarget::msaaAttachment() {
276 this->getVkGpu()->vkCaps().supportsDiscardableMSAAForDMSAA());
277 if (!useMSAASurface && this->
numSamples() > 1) {
280 bool validMSAA =
true;
281 if (useMSAASurface) {
291bool GrVkRenderTarget::completeStencilAttachment(
GrAttachment* stencil,
bool useMSAASurface) {
295 this->getVkGpu()->vkCaps().supportsDiscardableMSAAForDMSAA());
300 return fExternalFramebuffer;
311 this->
getFramebuffer(withResolve, withStencil, selfDepFlags, loadFromResolve);
328 this->
getFramebuffer(withResolve, withStencil, selfDepFlags, loadFromResolve);
336std::pair<const GrVkRenderPass*, GrVkResourceProvider::CompatibleRPHandle>
337GrVkRenderTarget::createSimpleRenderPass(
bool withResolve,
339 SelfDependencyFlags selfDepFlags,
340 LoadFromResolve loadFromResolve) {
345 GrVkResourceProvider::CompatibleRPHandle handle;
347 this, &handle, withResolve, withStencil, selfDepFlags,
349 SkASSERT(!renderPass || handle.isValid());
350 return {renderPass, handle};
359 SkASSERT(cacheIndex < GrVkRenderTarget::kNumCachedFramebuffers);
360 if (
auto fb = fCachedFramebuffers[cacheIndex]) {
364 this->createFramebuffer(withResolve, withStencil, selfDepFlags, loadFromResolve);
365 return fCachedFramebuffers[cacheIndex].
get();
368void GrVkRenderTarget::createFramebuffer(
bool withResolve,
370 SelfDependencyFlags selfDepFlags,
371 LoadFromResolve loadFromResolve) {
373 GrVkGpu* gpu = this->getVkGpu();
375 auto[renderPass, compatibleHandle] =
376 this->createSimpleRenderPass(withResolve, withStencil, selfDepFlags, loadFromResolve);
380 SkASSERT(compatibleHandle.isValid());
384 SkASSERT(cacheIndex < GrVkRenderTarget::kNumCachedFramebuffers);
390 bool useMSAA = this->
numSamples() > 1 || withResolve;
393 fCachedFramebuffers[cacheIndex] =
406 if (!colorAttachment) {
407 SkDebugf(
"WARNING: Invalid color attachment -- possibly dmsaa attachment creation failed?");
414 uint32_t attachmentCount = 1;
417 desc->fResolve.fFormat =
desc->fColor.fFormat;
418 desc->fResolve.fSamples = 1;
424 bool useMSAA = this->
numSamples() > 1 || withResolve;
434 desc->fAttachmentCount = attachmentCount;
449 uint32_t attachmentCount = 1;
452 desc->fResolve.fFormat =
desc->fColor.fFormat;
453 desc->fResolve.fSamples = 1;
461 desc->fStencil.fFormat = stencilFormat;
467 desc->fAttachmentCount = attachmentCount;
476 for (
int i = 0;
i < kNumCachedFramebuffers; ++
i) {
480 SkASSERT(!fCachedInputDescriptorSet);
483void GrVkRenderTarget::releaseInternalObjects() {
484 fColorAttachment.
reset();
485 fResolveAttachment.
reset();
486 fDynamicMSAAAttachment.
reset();
488 for (
int i = 0;
i < kNumCachedFramebuffers; ++
i) {
489 if (fCachedFramebuffers[
i]) {
490 fCachedFramebuffers[
i].reset();
494 if (fCachedInputDescriptorSet) {
495 fCachedInputDescriptorSet->
recycle();
496 fCachedInputDescriptorSet =
nullptr;
499 fExternalFramebuffer.
reset();
503 this->releaseInternalObjects();
508 this->releaseInternalObjects();
524GrVkGpu* GrVkRenderTarget::getVkGpu()
const {
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
SkAssertResult(font.textToGlyphs("Hello", 5, SkTextEncoding::kUTF8, glyphs, std::size(glyphs))==count)
@ kBorrow_GrWrapOwnership
static int renderpass_features_to_index(bool hasResolve, bool hasStencil, GrVkRenderPass::SelfDependencyFlags selfDepFlags, GrVkRenderPass::LoadFromResolve loadFromReslove)
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
@ kYes
Do pre-clip the geometry before applying the (perspective) matrix.
@ kNo
Don't pre-clip the geometry before applying the (perspective) matrix.
SkDEBUGCODE(SK_SPI) SkThreadID SkGetThreadID()
static constexpr bool SkToBool(const T &x)
int internalMultisampleCount(const GrBackendFormat &format) const
GrResourceProvider * resourceProvider()
GrDirectContextPriv priv()
bool wasDestroyed() const
void registerWithCacheWrapped(GrWrapCacheable)
const GrCaps * caps() const
GrDirectContext * getContext()
bool isStencilEnabled() const
const GrBackendFormat & backendFormat() const
GrAttachment * getStencilAttachment() const
void onAbandon() override
void onRelease() override
SkISize dimensions() const
void setVkRTSupportsInputAttachment()
GrInternalSurfaceFlags flags() const
bool programInfoWillUseDiscardableMSAA(const GrProgramInfo &) const
bool supportsDiscardableMSAAForDMSAA() const
bool supportsMemorylessAttachments() const
VkFormat preferredStencilFormat() const
const GrVkRenderPass * compatibleRenderPass() const
GrVkResourceProvider::CompatibleRPHandle compatibleRenderPassHandle() const
const GrVkRenderPass * externalRenderPass() const
GrVkImage * colorAttachment()
static sk_sp< const GrVkFramebuffer > Make(GrVkGpu *gpu, SkISize dimensions, sk_sp< const GrVkRenderPass > compatibleRenderPass, GrVkImage *colorAttachment, GrVkImage *resolveAttachment, GrVkImage *stencilAttachment, GrVkResourceProvider::CompatibleRPHandle)
const GrVkCaps & vkCaps() const
GrVkResourceProvider & resourceProvider()
GrBackendFormat backendFormat() const override
bool supportsInputAttachmentUsage() const
VkFormat imageFormat() const
sk_sp< skgpu::MutableTextureState > getMutableState() const
VkImageUsageFlags vkUsageFlags()
static sk_sp< GrVkImage > MakeWrapped(GrVkGpu *gpu, SkISize dimensions, const GrVkImageInfo &, sk_sp< skgpu::MutableTextureState >, UsageFlags attachmentUsages, GrWrapOwnership, GrWrapCacheable, std::string_view label, bool forSecondaryCB=false)
const GrVkImageInfo & vkImageInfo() const
@ kForNonCoherentAdvBlend
@ kStencil_AttachmentFlag
@ kResolve_AttachmentFlag
GrBackendRenderTarget getBackendRenderTarget() const override
bool getAttachmentsDescriptor(GrVkRenderPass::AttachmentsDescriptor *desc, GrVkRenderPass::AttachmentFlags *flags, bool withResolve, bool withStencil)
~GrVkRenderTarget() override
bool wrapsSecondaryCommandBuffer() const
GrVkImage * externalAttachment() const
sk_sp< GrVkFramebuffer > externalFramebuffer() const
GrVkImage * nonMSAAAttachment() const
bool canAttemptStencilAttachment(bool useMSAASurface) const override
void onAbandon() override
static void ReconstructAttachmentsDescriptor(const GrVkCaps &vkCaps, const GrProgramInfo &programInfo, GrVkRenderPass::AttachmentsDescriptor *desc, GrVkRenderPass::AttachmentFlags *flags)
const GrVkFramebuffer * getFramebuffer(bool withResolve, bool withStencil, SelfDependencyFlags selfDepFlags, LoadFromResolve)
GrVkImage * colorAttachment() const
GrBackendFormat backendFormat() const override
void onRelease() override
GrVkRenderTarget(GrVkGpu *gpu, SkISize dimensions, sk_sp< GrVkImage > colorAttachment, sk_sp< GrVkImage > resolveImage, CreateType createType, std::string_view label)
GrVkImage * resolveAttachment() const
GrVkResourceProvider::CompatibleRPHandle compatibleRenderPassHandle(bool withResolve, bool withStencil, SelfDependencyFlags selfDepFlags, LoadFromResolve)
static sk_sp< GrVkRenderTarget > MakeSecondaryCBRenderTarget(GrVkGpu *, SkISize, const GrVkDrawableInfo &vkInfo)
static sk_sp< GrVkRenderTarget > MakeWrappedRenderTarget(GrVkGpu *, SkISize, int sampleCnt, const GrVkImageInfo &, sk_sp< skgpu::MutableTextureState >)
const GrVkRenderPass * getSimpleRenderPass(bool withResolve, bool withStencil, SelfDependencyFlags selfDepFlags, LoadFromResolve)
const GrVkRenderPass * findCompatibleRenderPass(GrVkRenderTarget *target, CompatibleRPHandle *compatibleHandle, bool withResolve, bool withStencil, SelfDependencyFlags selfDepFlags, LoadFromResolve)
const GrVkRenderPass * findCompatibleExternalRenderPass(VkRenderPass, uint32_t colorAttachmentIndex)
static GrVkSecondaryCommandBuffer * Create(GrVkGpu *gpu, GrVkCommandPool *cmdPool)
void reset(T *ptr=nullptr)
FlutterSemanticsFlag flags
uint32_t uint32_t * format
SK_API GrBackendRenderTarget MakeVk(int width, int height, const GrVkImageInfo &)
SK_API MutableTextureState MakeVulkan(VkImageLayout layout, uint32_t queueFamilyIndex)
uint32_t fColorAttachmentIndex
VkRenderPass fCompatibleRenderPass
VkCommandBuffer fSecondaryCommandBuffer
@ VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
@ VK_IMAGE_USAGE_TRANSFER_DST_BIT
@ VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
@ VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
@ VK_IMAGE_USAGE_TRANSFER_SRC_BIT
#define VK_QUEUE_FAMILY_IGNORED