Flutter Engine
The Flutter Engine
GrVkTextureRenderTarget.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
9
17
18#include "src/core/SkMipmap.h"
19
22
23#define VK_CALL(GPU, X) GR_VK_CALL(GPU->vkInterface(), X)
24
25GrVkTextureRenderTarget::GrVkTextureRenderTarget(GrVkGpu* gpu,
26 skgpu::Budgeted budgeted,
27 SkISize dimensions,
29 sk_sp<GrVkImage> colorAttachment,
30 sk_sp<GrVkImage> resolveAttachment,
31 GrMipmapStatus mipmapStatus,
32 std::string_view label)
33 : GrSurface(gpu,
34 dimensions,
35 texture->isProtected() ? GrProtected::kYes : GrProtected::kNo,
36 label)
37 , GrVkTexture(gpu, dimensions, std::move(texture), mipmapStatus, label)
38 , GrVkRenderTarget(gpu,
39 dimensions,
40 std::move(colorAttachment),
41 std::move(resolveAttachment),
42 CreateType::kFromTextureRT,
43 label) {
44 this->registerWithCache(budgeted);
45}
46
47GrVkTextureRenderTarget::GrVkTextureRenderTarget(
48 GrVkGpu* gpu,
49 SkISize dimensions,
51 sk_sp<GrVkImage> colorAttachment,
52 sk_sp<GrVkImage> resolveAttachment,
53 GrMipmapStatus mipmapStatus,
54 GrWrapCacheable cacheable,
55 std::string_view label)
56 : GrSurface(gpu,
57 dimensions,
58 texture->isProtected() ? GrProtected::kYes : GrProtected::kNo,
59 label)
60 , GrVkTexture(gpu, dimensions, std::move(texture), mipmapStatus, label)
61 , GrVkRenderTarget(gpu, dimensions, std::move(colorAttachment),
62 std::move(resolveAttachment), CreateType::kFromTextureRT, label) {
63 this->registerWithCacheWrapped(cacheable);
64}
65
66bool create_rt_attachments(GrVkGpu* gpu, SkISize dimensions, VkFormat format, int sampleCnt,
67 GrProtected isProtected,
69 sk_sp<GrVkImage>* colorAttachment,
70 sk_sp<GrVkImage>* resolveAttachment) {
71 if (sampleCnt > 1) {
72 auto rp = gpu->getContext()->priv().resourceProvider();
73 sk_sp<GrAttachment> msaaAttachment = rp->makeMSAAAttachment(
74 dimensions, GrBackendFormats::MakeVk(format), sampleCnt, isProtected,
76 if (!msaaAttachment) {
77 return false;
78 }
79 *colorAttachment = sk_sp<GrVkImage>(static_cast<GrVkImage*>(msaaAttachment.release()));
80 *resolveAttachment = std::move(texture);
81 } else {
82 *colorAttachment = std::move(texture);
83 }
84 return true;
85}
86
88 GrVkGpu* gpu,
89 skgpu::Budgeted budgeted,
90 SkISize dimensions,
92 uint32_t mipLevels,
93 int sampleCnt,
94 GrMipmapStatus mipmapStatus,
95 GrProtected isProtected,
96 std::string_view label) {
99 format,
100 mipLevels,
102 /*numSamples=*/1,
103 budgeted,
105 if (!texture) {
106 return nullptr;
107 }
108
113 return nullptr;
114 }
116 SkASSERT(sampleCnt == 1 || resolveAttachment);
118 budgeted,
120 std::move(texture),
121 std::move(colorAttachment),
122 std::move(resolveAttachment),
124 label));
125}
126
128 GrVkGpu* gpu,
129 SkISize dimensions,
130 int sampleCnt,
131 GrWrapOwnership wrapOwnership,
132 GrWrapCacheable cacheable,
133 const GrVkImageInfo& info,
135 // Adopted textures require both image and allocation because we're responsible for freeing
136 SkASSERT(VK_NULL_HANDLE != info.fImage &&
137 (kBorrow_GrWrapOwnership == wrapOwnership || VK_NULL_HANDLE != info.fAlloc.fMemory));
138
140 if (info.fImageUsageFlags & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) {
142 }
143
146 info,
147 std::move(mutableState),
148 textureUsageFlags,
149 wrapOwnership,
150 cacheable,
151 "VkImage_MakeWrappedTextureRenderTarget");
152 if (!texture) {
153 return nullptr;
154 }
155
158 if (!create_rt_attachments(gpu, dimensions, info.fFormat, sampleCnt, info.fProtected, texture,
160 return nullptr;
161 }
163 SkASSERT(sampleCnt == 1 || resolveAttachment);
164
167
171 std::move(texture),
172 std::move(colorAttachment),
173 std::move(resolveAttachment),
175 cacheable,
176 /*label=*/"Vk_MakeWrappedTextureRenderTarget"));
177}
178
179size_t GrVkTextureRenderTarget::onGpuMemorySize() const {
180 // The GrTexture[RenderTarget] is built up by a bunch of attachments each of which are their
181 // own GrGpuResource. Ideally the GrRenderTarget would not be a GrGpuResource and the GrTexture
182 // would just merge with the new GrSurface/Attachment world. Then we could just depend on each
183 // attachment to give its own size since we don't have GrGpuResources owning other
184 // GrGpuResources. Until we get to that point we need to live in some hybrid world. We will let
185 // the msaa and stencil attachments track their own size because they do get cached separately.
186 // For all GrTexture* based things we will continue to to use the GrTexture* to report size and
187 // the owned attachments will have no size and be uncached.
188#ifdef SK_DEBUG
189 // The nonMSAA attachment (either color or resolve depending on numSamples should have size of
190 // zero since it is a texture attachment.
192 if (this->numSamples() > 1) {
193 // Msaa attachment should have a valid size
196 this->dimensions(),
197 this->numSamples(),
199 }
200#endif
201 return GrSurface::ComputeSize(this->backendFormat(), this->dimensions(),
202 1 /*colorSamplesPerPixel*/, this->mipmapped());
203}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
GrWrapCacheable
Definition: GrTypesPriv.h:85
GrMipmapStatus
Definition: GrTypesPriv.h:523
GrWrapOwnership
Definition: GrTypesPriv.h:77
@ kBorrow_GrWrapOwnership
Definition: GrTypesPriv.h:79
bool create_rt_attachments(GrVkGpu *gpu, SkISize dimensions, VkFormat format, int sampleCnt, GrProtected isProtected, sk_sp< GrVkImage > texture, sk_sp< GrVkImage > *colorAttachment, sk_sp< GrVkImage > *resolveAttachment)
#define SkASSERT(cond)
Definition: SkAssert.h:116
@ kYes
Do pre-clip the geometry before applying the (perspective) matrix.
@ kNo
Don't pre-clip the geometry before applying the (perspective) matrix.
GrResourceProvider * resourceProvider()
GrDirectContextPriv priv()
size_t gpuMemorySize() const
GrDirectContext * getContext()
Definition: GrGpu.h:67
int numSamples() const
SkISize dimensions() const
Definition: GrSurface.h:27
bool isProtected() const
Definition: GrSurface.h:87
static size_t ComputeSize(const GrBackendFormat &, SkISize dimensions, int colorSamplesPerPixel, skgpu::Mipmapped, bool binSize=false)
Definition: GrSurface.cpp:21
skgpu::Mipmapped mipmapped() const
Definition: GrTexture.h:62
GrMipmapStatus mipmapStatus() const
Definition: GrTexture.h:66
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)
Definition: GrVkImage.cpp:179
static sk_sp< GrVkImage > MakeTexture(GrVkGpu *gpu, SkISize dimensions, VkFormat format, uint32_t mipLevels, GrRenderable renderable, int numSamples, skgpu::Budgeted budgeted, GrProtected isProtected)
Definition: GrVkImage.cpp:65
GrVkImage * nonMSAAAttachment() const
GrVkImage * colorAttachment() const
GrVkImage * resolveAttachment() const
GrBackendFormat backendFormat() const override
static sk_sp< GrVkTextureRenderTarget > MakeNewTextureRenderTarget(GrVkGpu *gpu, skgpu::Budgeted budgeted, SkISize dimensions, VkFormat format, uint32_t mipLevels, int sampleCnt, GrMipmapStatus mipmapStatus, GrProtected isProtected, std::string_view label)
static sk_sp< GrVkTextureRenderTarget > MakeWrappedTextureRenderTarget(GrVkGpu *, SkISize dimensions, int sampleCnt, GrWrapOwnership, GrWrapCacheable, const GrVkImageInfo &, sk_sp< skgpu::MutableTextureState >)
T * release()
Definition: SkRefCnt.h:324
uint32_t uint32_t * format
FlTexture * texture
SK_API GrBackendFormat MakeVk(VkFormat format, bool willUseDRMFormatModifiers=false)
Budgeted
Definition: GpuTypes.h:35
Protected
Definition: GpuTypes.h:61
Definition: ref_ptr.h:256
Definition: SkSize.h:16
@ VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
Definition: vulkan_core.h:2356
#define VK_NULL_HANDLE
Definition: vulkan_core.h:46
VkFormat
Definition: vulkan_core.h:1458