Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
VkWrapTests.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2016 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// This is a GPU-backend specific test. It relies on static initializers to work
9
11
12#if defined(SK_VULKAN)
13
19#include "include/gpu/GrTypes.h"
31#include "tests/Test.h"
33
34#include <vulkan/vulkan_core.h>
35#include <initializer_list>
36
37struct GrContextOptions;
38
40
41const int kW = 1024;
42const int kH = 1024;
44
45void wrap_tex_test(skiatest::Reporter* reporter, GrDirectContext* dContext) {
46 using namespace skgpu;
47
48 GrGpu* gpu = dContext->priv().getGpu();
49
50 Protected isProtected = Protected(dContext->priv().caps()->supportsProtectedContent());
51
52 auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData(
53 dContext, kW, kH, kRGBA_8888_SkColorType, skgpu::Mipmapped::kNo, GrRenderable::kNo,
54 isProtected);
55 if (!mbet) {
56 ERRORF(reporter, "Could not create backend texture.");
57 return;
58 }
59
60 GrBackendTexture origBackendTex = mbet->texture();
61
62 GrVkImageInfo imageInfo;
63 SkAssertResult(GrBackendTextures::GetVkImageInfo(origBackendTex, &imageInfo));
64
65 {
69 }
70
71 // image is null
72 {
73 GrVkImageInfo backendCopy = imageInfo;
74 backendCopy.fImage = VK_NULL_HANDLE;
75 GrBackendTexture backendTex = GrBackendTextures::MakeVk(kW, kH, backendCopy);
79 tex = gpu->wrapBackendTexture(
82 }
83
84 // alloc is null
85 {
86 GrVkImageInfo backendCopy = imageInfo;
87 backendCopy.fAlloc = skgpu::VulkanAlloc();
88 GrBackendTexture backendTex = GrBackendTextures::MakeVk(kW, kH, backendCopy);
92 tex = gpu->wrapBackendTexture(
95 }
96
97 // check adopt creation
98 {
99 GrVkImageInfo backendCopy = imageInfo;
100 GrBackendTexture backendTex = GrBackendTextures::MakeVk(kW, kH, backendCopy);
103
105 if (tex) {
106 mbet->wasAdopted();
107 }
108 }
109}
110
111void wrap_rt_test(skiatest::Reporter* reporter, GrDirectContext* dContext) {
112 using namespace skgpu;
113
114 GrGpu* gpu = dContext->priv().getGpu();
116
117 Protected isProtected = Protected(dContext->priv().caps()->supportsProtectedContent());
118
119 for (int sampleCnt : {1, 4}) {
120 GrBackendFormat format = gpu->caps()->getDefaultBackendFormat(ct, GrRenderable::kYes);
121 if (sampleCnt > gpu->caps()->maxRenderTargetSampleCount(format)) {
122 continue;
123 }
124
125 GrBackendRenderTarget origBackendRT =
126 gpu->createTestingOnlyBackendRenderTarget({kW, kH}, ct, sampleCnt, isProtected);
127 if (!origBackendRT.isValid()) {
128 ERRORF(reporter, "Could not create backend render target.");
129 }
130
131 GrVkImageInfo imageInfo;
133 GrBackendRenderTargets::GetVkImageInfo(origBackendRT, &imageInfo));
134
135 sk_sp<GrRenderTarget> rt = gpu->wrapBackendRenderTarget(origBackendRT);
137
138 // image is null
139 {
140 GrVkImageInfo backendCopy = imageInfo;
141 backendCopy.fImage = VK_NULL_HANDLE;
143 rt = gpu->wrapBackendRenderTarget(backendRT);
145 }
146
147 // alloc is null
148 {
149 GrVkImageInfo backendCopy = imageInfo;
150 backendCopy.fAlloc = VulkanAlloc();
151 // can wrap null alloc
153 rt = gpu->wrapBackendRenderTarget(backendRT);
155 }
156
157 gpu->deleteTestingOnlyBackendRenderTarget(origBackendRT);
158 }
159}
160
161void wrap_trt_test(skiatest::Reporter* reporter, GrDirectContext* dContext) {
162 using namespace skgpu;
163
164 GrGpu* gpu = dContext->priv().getGpu();
165
166 Protected isProtected = Protected(dContext->priv().caps()->supportsProtectedContent());
167
168 auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData(
169 dContext, kW, kH, kRGBA_8888_SkColorType, Mipmapped::kNo, GrRenderable::kYes,
170 isProtected);
171 if (!mbet) {
172 ERRORF(reporter, "Could not create renderable backend texture.");
173 return;
174 }
175 GrBackendTexture origBackendTex = mbet->texture();
176
177 GrVkImageInfo imageInfo;
178 SkAssertResult(GrBackendTextures::GetVkImageInfo(origBackendTex, &imageInfo));
179
183
184 // image is null
185 {
186 GrVkImageInfo backendCopy = imageInfo;
187 backendCopy.fImage = VK_NULL_HANDLE;
188 GrBackendTexture backendTex = GrBackendTextures::MakeVk(kW, kH, backendCopy);
195 }
196
197 // alloc is null
198 {
199 GrVkImageInfo backendCopy = imageInfo;
200 backendCopy.fAlloc = VulkanAlloc();
201 GrBackendTexture backendTex = GrBackendTextures::MakeVk(kW, kH, backendCopy);
208 }
209
210 // check rendering with MSAA
211 {
212 int maxSamples = dContext->priv().caps()->maxRenderTargetSampleCount(
213 origBackendTex.getBackendFormat());
214 bool shouldSucceed = maxSamples > 1;
215 tex = gpu->wrapRenderableBackendTexture(origBackendTex, 2, kBorrow_GrWrapOwnership,
217 REPORTER_ASSERT(reporter, SkToBool(tex) == shouldSucceed);
218 }
219
220 // check adopt creation
221 {
222 GrVkImageInfo backendCopy = imageInfo;
223 GrBackendTexture backendTex = GrBackendTextures::MakeVk(kW, kH, backendCopy);
227 if (tex) {
228 mbet->wasAdopted();
229 }
230 }
231}
232
234 auto dContext = ctxInfo.directContext();
235
236 wrap_tex_test(reporter, dContext);
237 wrap_rt_test(reporter, dContext);
238 wrap_trt_test(reporter, dContext);
239}
240
241#endif
reporter
@ kRead_GrIOType
@ kAdopt_GrWrapOwnership
Definition GrTypesPriv.h:81
@ kBorrow_GrWrapOwnership
Definition GrTypesPriv.h:78
GrColorType
static constexpr GrColorType SkColorTypeToGrColorType(SkColorType ct)
skgpu::Protected Protected
#define SkAssertResult(cond)
Definition SkAssert.h:123
SkColorType
Definition SkColorType.h:19
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition SkColorType.h:24
static constexpr bool SkToBool(const T &x)
Definition SkTo.h:35
#define DEF_GANESH_TEST_FOR_VULKAN_CONTEXT(name, reporter, context_info, ctsEnforcement)
Definition Test.h:458
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
#define ERRORF(r,...)
Definition Test.h:293
static constexpr auto kColorType
constexpr int kH
constexpr int kW
GrBackendFormat getBackendFormat() const
const GrCaps * caps() const
virtual int maxRenderTargetSampleCount(const GrBackendFormat &) const =0
bool supportsProtectedContent() const
Definition GrCaps.h:422
GrBackendFormat getDefaultBackendFormat(GrColorType, GrRenderable) const
Definition GrCaps.cpp:400
GrDirectContextPriv priv()
Definition GrGpu.h:62
const GrCaps * caps() const
Definition GrGpu.h:73
sk_sp< GrTexture > wrapBackendTexture(const GrBackendTexture &, GrWrapOwnership, GrWrapCacheable, GrIOType)
Definition GrGpu.cpp:297
sk_sp< GrRenderTarget > wrapBackendRenderTarget(const GrBackendRenderTarget &)
Definition GrGpu.cpp:366
sk_sp< GrTexture > wrapRenderableBackendTexture(const GrBackendTexture &, int sampleCnt, GrWrapOwnership, GrWrapCacheable)
Definition GrGpu.cpp:337
uint32_t uint32_t * format
SK_API bool GetVkImageInfo(const GrBackendRenderTarget &, GrVkImageInfo *)
SK_API GrBackendRenderTarget MakeVk(int width, int height, const GrVkImageInfo &)
SK_API GrBackendTexture MakeVk(int width, int height, const GrVkImageInfo &, std::string_view label={})
SK_API bool GetVkImageInfo(const GrBackendTexture &, GrVkImageInfo *)
Protected
Definition GpuTypes.h:61
VkImage fImage
Definition GrVkTypes.h:26
skgpu::VulkanAlloc fAlloc
Definition GrVkTypes.h:27
#define VK_NULL_HANDLE
Definition vulkan_core.h:46