/src/skia/src/gpu/ganesh/vk/GrVkTextureRenderTarget.cpp
Line | Count | Source (jump to first uncovered line) |
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 | | |
8 | | #include "src/gpu/ganesh/vk/GrVkTextureRenderTarget.h" |
9 | | |
10 | | #include "src/gpu/ganesh/GrDirectContextPriv.h" |
11 | | #include "src/gpu/ganesh/GrResourceProvider.h" |
12 | | #include "src/gpu/ganesh/GrTexture.h" |
13 | | #include "src/gpu/ganesh/vk/GrVkGpu.h" |
14 | | #include "src/gpu/ganesh/vk/GrVkImage.h" |
15 | | #include "src/gpu/ganesh/vk/GrVkImageView.h" |
16 | | #include "src/gpu/ganesh/vk/GrVkUtil.h" |
17 | | |
18 | | #include "src/core/SkMipmap.h" |
19 | | |
20 | | #include "include/gpu/ganesh/vk/GrVkBackendSurface.h" |
21 | | #include "include/gpu/vk/GrVkTypes.h" |
22 | | |
23 | | #define VK_CALL(GPU, X) GR_VK_CALL(GPU->vkInterface(), X) |
24 | | |
25 | | GrVkTextureRenderTarget::GrVkTextureRenderTarget(GrVkGpu* gpu, |
26 | | skgpu::Budgeted budgeted, |
27 | | SkISize dimensions, |
28 | | sk_sp<GrVkImage> texture, |
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 | 0 | label) { |
44 | 0 | this->registerWithCache(budgeted); |
45 | 0 | } Unexecuted instantiation: GrVkTextureRenderTarget::GrVkTextureRenderTarget(GrVkGpu*, skgpu::Budgeted, SkISize, sk_sp<GrVkImage>, sk_sp<GrVkImage>, sk_sp<GrVkImage>, GrMipmapStatus, std::__1::basic_string_view<char, std::__1::char_traits<char> >) Unexecuted instantiation: GrVkTextureRenderTarget::GrVkTextureRenderTarget(GrVkGpu*, skgpu::Budgeted, SkISize, sk_sp<GrVkImage>, sk_sp<GrVkImage>, sk_sp<GrVkImage>, GrMipmapStatus, std::__1::basic_string_view<char, std::__1::char_traits<char> >) |
46 | | |
47 | | GrVkTextureRenderTarget::GrVkTextureRenderTarget( |
48 | | GrVkGpu* gpu, |
49 | | SkISize dimensions, |
50 | | sk_sp<GrVkImage> texture, |
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 | 0 | std::move(resolveAttachment), CreateType::kFromTextureRT, label) { |
63 | 0 | this->registerWithCacheWrapped(cacheable); |
64 | 0 | } Unexecuted instantiation: GrVkTextureRenderTarget::GrVkTextureRenderTarget(GrVkGpu*, SkISize, sk_sp<GrVkImage>, sk_sp<GrVkImage>, sk_sp<GrVkImage>, GrMipmapStatus, GrWrapCacheable, std::__1::basic_string_view<char, std::__1::char_traits<char> >) Unexecuted instantiation: GrVkTextureRenderTarget::GrVkTextureRenderTarget(GrVkGpu*, SkISize, sk_sp<GrVkImage>, sk_sp<GrVkImage>, sk_sp<GrVkImage>, GrMipmapStatus, GrWrapCacheable, std::__1::basic_string_view<char, std::__1::char_traits<char> >) |
65 | | |
66 | | bool create_rt_attachments(GrVkGpu* gpu, SkISize dimensions, VkFormat format, int sampleCnt, |
67 | | GrProtected isProtected, |
68 | | sk_sp<GrVkImage> texture, |
69 | | sk_sp<GrVkImage>* colorAttachment, |
70 | 0 | sk_sp<GrVkImage>* resolveAttachment) { |
71 | 0 | if (sampleCnt > 1) { |
72 | 0 | auto rp = gpu->getContext()->priv().resourceProvider(); |
73 | 0 | sk_sp<GrAttachment> msaaAttachment = rp->makeMSAAAttachment( |
74 | 0 | dimensions, GrBackendFormats::MakeVk(format), sampleCnt, isProtected, |
75 | 0 | GrMemoryless::kNo); |
76 | 0 | if (!msaaAttachment) { |
77 | 0 | return false; |
78 | 0 | } |
79 | 0 | *colorAttachment = sk_sp<GrVkImage>(static_cast<GrVkImage*>(msaaAttachment.release())); |
80 | 0 | *resolveAttachment = std::move(texture); |
81 | 0 | } else { |
82 | 0 | *colorAttachment = std::move(texture); |
83 | 0 | } |
84 | 0 | return true; |
85 | 0 | } |
86 | | |
87 | | sk_sp<GrVkTextureRenderTarget> GrVkTextureRenderTarget::MakeNewTextureRenderTarget( |
88 | | GrVkGpu* gpu, |
89 | | skgpu::Budgeted budgeted, |
90 | | SkISize dimensions, |
91 | | VkFormat format, |
92 | | uint32_t mipLevels, |
93 | | int sampleCnt, |
94 | | GrMipmapStatus mipmapStatus, |
95 | | GrProtected isProtected, |
96 | 0 | std::string_view label) { |
97 | 0 | sk_sp<GrVkImage> texture = GrVkImage::MakeTexture(gpu, |
98 | 0 | dimensions, |
99 | 0 | format, |
100 | 0 | mipLevels, |
101 | 0 | GrRenderable::kYes, |
102 | 0 | /*numSamples=*/1, |
103 | 0 | budgeted, |
104 | 0 | isProtected); |
105 | 0 | if (!texture) { |
106 | 0 | return nullptr; |
107 | 0 | } |
108 | | |
109 | 0 | sk_sp<GrVkImage> colorAttachment; |
110 | 0 | sk_sp<GrVkImage> resolveAttachment; |
111 | 0 | if (!create_rt_attachments(gpu, dimensions, format, sampleCnt, isProtected, texture, |
112 | 0 | &colorAttachment, &resolveAttachment)) { |
113 | 0 | return nullptr; |
114 | 0 | } |
115 | 0 | SkASSERT(colorAttachment); |
116 | 0 | SkASSERT(sampleCnt == 1 || resolveAttachment); |
117 | 0 | return sk_sp<GrVkTextureRenderTarget>(new GrVkTextureRenderTarget(gpu, |
118 | 0 | budgeted, |
119 | 0 | dimensions, |
120 | 0 | std::move(texture), |
121 | 0 | std::move(colorAttachment), |
122 | 0 | std::move(resolveAttachment), |
123 | 0 | mipmapStatus, |
124 | 0 | label)); |
125 | 0 | } Unexecuted instantiation: GrVkTextureRenderTarget::MakeNewTextureRenderTarget(GrVkGpu*, skgpu::Budgeted, SkISize, VkFormat, unsigned int, int, GrMipmapStatus, skgpu::Protected, std::__1::basic_string_view<char, std::__1::char_traits<char> >) Unexecuted instantiation: GrVkTextureRenderTarget::MakeNewTextureRenderTarget(GrVkGpu*, skgpu::Budgeted, SkISize, VkFormat, unsigned int, int, GrMipmapStatus, skgpu::Protected, std::__1::basic_string_view<char, std::__1::char_traits<char> >) |
126 | | |
127 | | sk_sp<GrVkTextureRenderTarget> GrVkTextureRenderTarget::MakeWrappedTextureRenderTarget( |
128 | | GrVkGpu* gpu, |
129 | | SkISize dimensions, |
130 | | int sampleCnt, |
131 | | GrWrapOwnership wrapOwnership, |
132 | | GrWrapCacheable cacheable, |
133 | | const GrVkImageInfo& info, |
134 | 0 | sk_sp<skgpu::MutableTextureState> mutableState) { |
135 | | // Adopted textures require both image and allocation because we're responsible for freeing |
136 | 0 | SkASSERT(VK_NULL_HANDLE != info.fImage && |
137 | 0 | (kBorrow_GrWrapOwnership == wrapOwnership || VK_NULL_HANDLE != info.fAlloc.fMemory)); |
138 | |
|
139 | 0 | GrAttachment::UsageFlags textureUsageFlags = GrAttachment::UsageFlags::kTexture; |
140 | 0 | if (info.fImageUsageFlags & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) { |
141 | 0 | textureUsageFlags |= GrAttachment::UsageFlags::kColorAttachment; |
142 | 0 | } |
143 | |
|
144 | 0 | sk_sp<GrVkImage> texture = GrVkImage::MakeWrapped(gpu, |
145 | 0 | dimensions, |
146 | 0 | info, |
147 | 0 | std::move(mutableState), |
148 | 0 | textureUsageFlags, |
149 | 0 | wrapOwnership, |
150 | 0 | cacheable, |
151 | 0 | "VkImage_MakeWrappedTextureRenderTarget"); |
152 | 0 | if (!texture) { |
153 | 0 | return nullptr; |
154 | 0 | } |
155 | | |
156 | 0 | sk_sp<GrVkImage> colorAttachment; |
157 | 0 | sk_sp<GrVkImage> resolveAttachment; |
158 | 0 | if (!create_rt_attachments(gpu, dimensions, info.fFormat, sampleCnt, info.fProtected, texture, |
159 | 0 | &colorAttachment, &resolveAttachment)) { |
160 | 0 | return nullptr; |
161 | 0 | } |
162 | 0 | SkASSERT(colorAttachment); |
163 | 0 | SkASSERT(sampleCnt == 1 || resolveAttachment); |
164 | |
|
165 | 0 | GrMipmapStatus mipmapStatus = |
166 | 0 | info.fLevelCount > 1 ? GrMipmapStatus::kDirty : GrMipmapStatus::kNotAllocated; |
167 | |
|
168 | 0 | return sk_sp<GrVkTextureRenderTarget>( |
169 | 0 | new GrVkTextureRenderTarget(gpu, |
170 | 0 | dimensions, |
171 | 0 | std::move(texture), |
172 | 0 | std::move(colorAttachment), |
173 | 0 | std::move(resolveAttachment), |
174 | 0 | mipmapStatus, |
175 | 0 | cacheable, |
176 | 0 | /*label=*/"Vk_MakeWrappedTextureRenderTarget")); |
177 | 0 | } Unexecuted instantiation: GrVkTextureRenderTarget::MakeWrappedTextureRenderTarget(GrVkGpu*, SkISize, int, GrWrapOwnership, GrWrapCacheable, GrVkImageInfo const&, sk_sp<skgpu::MutableTextureState>) Unexecuted instantiation: GrVkTextureRenderTarget::MakeWrappedTextureRenderTarget(GrVkGpu*, SkISize, int, GrWrapOwnership, GrWrapCacheable, GrVkImageInfo const&, sk_sp<skgpu::MutableTextureState>) |
178 | | |
179 | 0 | size_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. |
191 | 0 | SkASSERT(this->nonMSAAAttachment()->gpuMemorySize() == 0); |
192 | 0 | if (this->numSamples() > 1) { |
193 | | // Msaa attachment should have a valid size |
194 | 0 | SkASSERT(this->colorAttachment()->gpuMemorySize() == |
195 | 0 | GrSurface::ComputeSize(this->backendFormat(), |
196 | 0 | this->dimensions(), |
197 | 0 | this->numSamples(), |
198 | 0 | skgpu::Mipmapped::kNo)); |
199 | 0 | } |
200 | | #endif |
201 | 0 | return GrSurface::ComputeSize(this->backendFormat(), this->dimensions(), |
202 | 0 | 1 /*colorSamplesPerPixel*/, this->mipmapped()); |
203 | 0 | } Unexecuted instantiation: GrVkTextureRenderTarget::onGpuMemorySize() const Unexecuted instantiation: GrVkTextureRenderTarget::onGpuMemorySize() const |