Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
VkBackendSurfaceTest.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2018 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)
21#include "include/gpu/GrTypes.h"
35#include "tests/Test.h"
38
39#include <vulkan/vulkan_core.h>
40
41class GrTexture;
42struct GrContextOptions;
43
45 using namespace skgpu;
46
47 auto dContext = ctxInfo.directContext();
48
49 const GrVkCaps* vkCaps = static_cast<const GrVkCaps*>(dContext->priv().caps());
50 if (!vkCaps->supportsDRMFormatModifiers()) {
51 return;
52 }
53
54 Protected isProtected = Protected(vkCaps->supportsProtectedContent());
55
56 // First make a normal backend texture with DRM
57 auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData(
58 dContext, 1, 1, kRGBA_8888_SkColorType, Mipmapped::kNo, GrRenderable::kNo, isProtected);
59 if (!mbet) {
60 ERRORF(reporter, "Could not create backend texture.");
61 return;
62 }
63
66
67 // Next we will use the same VkImageInfo but lie to say tiling is a DRM modifier. This should
68 // cause us to think the resource is eternal/read only internally. Though since we don't
69 // explicitly pass in the tiling to anything, this shouldn't cause us to do anything illegal.
71
73 GrBackendFormat drmFormat = GrBackendFormats::MakeVk(info.fFormat, true);
74 REPORTER_ASSERT(reporter, drmFormat == drmBETex.getBackendFormat());
76
77 // Now wrap the texture in an SkImage and make sure we have the required read only properties
79 drmBETex,
83 nullptr);
84 REPORTER_ASSERT(reporter, drmImage);
85
86 GrBackendTexture actual;
87 bool ok = SkImages::GetBackendTextureFromImage(drmImage, &actual, false);
89 REPORTER_ASSERT(reporter, GrBackendTexture::TestingOnly_Equals(actual, drmBETex));
90
91 auto [view, _] = skgpu::ganesh::AsView(dContext, drmImage, Mipmapped::kNo);
93 const GrSurfaceProxy* proxy = view.proxy();
95
97
98 const GrSurface* surf = proxy->peekSurface();
101
102 drmImage.reset();
103}
104
106 using namespace skgpu;
107
108 auto dContext = ctxInfo.directContext();
109
110 Protected isProtected = Protected(dContext->priv().caps()->supportsProtectedContent());
111
112 auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData(
113 dContext, 1, 1, kRGBA_8888_SkColorType, Mipmapped::kNo, GrRenderable::kNo, isProtected);
114 if (!mbet) {
115 ERRORF(reporter, "Could not create backend texture.");
116 return;
117 }
118
121 VkImageLayout initLayout = info.fImageLayout;
122
123 // Verify that setting that layout via a copy of a backendTexture is reflected in all the
124 // backendTextures.
125 GrBackendTexture backendTex1 = mbet->texture();
126 GrBackendTexture backendTex2 = backendTex1;
128 REPORTER_ASSERT(reporter, initLayout == info.fImageLayout);
129
131
134
137
138 // Setting back the layout since we didn't actually change it
139 GrBackendTextures::SetVkImageLayout(&backendTex1, initLayout);
140
141 sk_sp<SkImage> wrappedImage =
143 backendTex1,
147 /*color space*/ nullptr,
148 sk_gpu_test::ManagedBackendTexture::ReleaseProc,
149 mbet->releaseContext());
150 REPORTER_ASSERT(reporter, wrappedImage.get());
151
152 GrSurfaceProxy* proxy = sk_gpu_test::GetTextureImageProxy(wrappedImage.get(), dContext);
155 GrTexture* texture = proxy->peekTexture();
157
158 // Verify that modifying the layout via the GrVkTexture is reflected in the GrBackendTexture
159 GrVkImage* vkTexture = static_cast<GrVkTexture*>(texture)->textureImage();
160 REPORTER_ASSERT(reporter, initLayout == vkTexture->currentLayout());
162
165
166 GrBackendTexture backendTexImage;
167 bool ok = SkImages::GetBackendTextureFromImage(wrappedImage, &backendTexImage, false);
171
172 // Verify that modifying the layout via the GrBackendTexutre is reflected in the GrVkTexture
175
176 vkTexture->updateImageLayout(initLayout);
177
179 REPORTER_ASSERT(reporter, initLayout == info.fImageLayout);
180
182 REPORTER_ASSERT(reporter, initLayout == info.fImageLayout);
183
185 REPORTER_ASSERT(reporter, initLayout == info.fImageLayout);
186
187 // Check that we can do things like assigning the backend texture to invalid one, assign an
188 // invalid one, assin a backend texture to inself etc. Success here is that we don't hit any of
189 // our ref counting asserts.
190 REPORTER_ASSERT(reporter, GrBackendTexture::TestingOnly_Equals(backendTex1, backendTex2));
191
192 GrBackendTexture invalidTexture;
193 REPORTER_ASSERT(reporter, !invalidTexture.isValid());
194 REPORTER_ASSERT(reporter, !GrBackendTexture::TestingOnly_Equals(invalidTexture, backendTex2));
195
196 backendTex2 = invalidTexture;
197 REPORTER_ASSERT(reporter, !backendTex2.isValid());
198 REPORTER_ASSERT(reporter, !GrBackendTexture::TestingOnly_Equals(invalidTexture, backendTex2));
199
200 invalidTexture = backendTex1;
201 REPORTER_ASSERT(reporter, invalidTexture.isValid());
202 REPORTER_ASSERT(reporter, GrBackendTexture::TestingOnly_Equals(invalidTexture, backendTex1));
203
204 invalidTexture = static_cast<decltype(invalidTexture)&>(invalidTexture);
205 REPORTER_ASSERT(reporter, invalidTexture.isValid());
206 REPORTER_ASSERT(reporter, GrBackendTexture::TestingOnly_Equals(invalidTexture, invalidTexture));
207}
208
209// This test is disabled because it executes illegal vulkan calls which cause the validations layers
210// to fail and makes us assert. Once fixed to use a valid vulkan call sequence it should be
211// renenabled, see skbug.com/8936.
212#if 0
213// Test to make sure we transition from the EXTERNAL queue even when no layout transition is needed.
214DEF_GANESH_TEST_FOR_VULKAN_CONTEXT(VkTransitionExternalQueueTest, reporter, ctxInfo,
216 auto dContext = ctxInfo.directContext();
217 GrGpu* gpu = dContext->priv().getGpu();
218 GrVkGpu* vkGpu = static_cast<GrVkGpu*>(gpu);
219 if (!vkGpu->vkCaps().supportsExternalMemory()) {
220 return;
221 }
222
223 GrBackendTexture backendTex = dContext->createBackendTexture(
225 SkColors::kTransparent, skgpu::Mipmapped::kNo, GrRenderable::kNo);
227 // Make a backend texture with an external queue family and general layout.
228 GrVkImageInfo vkInfo;
229 if (!GrBackendTextures::GetVkImageInfo(backendTex, &vkInfo)) {
230 return;
231 }
233 // Use a read-only layout as these are the ones where we can otherwise skip a transition.
235
236 GrBackendTexture vkExtTex(1, 1, vkInfo);
237 REPORTER_ASSERT(reporter, vkExtTex.isValid());
240 nullptr);
241
242 if (!image) {
243 return;
244 }
245
246 GrTexture* texture = image->getTexture();
248 GrVkTexture* vkTex = static_cast<GrVkTexture*>(texture);
249
250 // Change our backend texture to the internal queue, with the same layout. This should force a
251 // queue transition even though the layouts match.
252 vkTex->setImageLayout(vkGpu, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, 0,
254
255 // Get our image info again and make sure we transitioned queues.
256 GrBackendTexture newBackendTexture = image->getBackendTexture(true);
257 GrVkImageInfo newVkInfo;
258 REPORTER_ASSERT(reporter, GrBackendTextures::GetVkImageInfo(newBackendTexture, &newVkInfo));
260
261 image.reset();
262 dContext->submit(GrSyncCpu::kYes);
263 dContext->deleteBackendTexture(backendTex);
264}
265#endif
266
267#endif
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
reporter
@ kTopLeft_GrSurfaceOrigin
Definition GrTypes.h:148
skgpu::Protected Protected
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition SkAlphaType.h:29
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition SkColorType.h:24
static bool ok(int result)
#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
GrBackendFormat getBackendFormat() const
GrTextureType textureType() const
bool supportsProtectedContent() const
Definition GrCaps.h:422
Definition GrGpu.h:62
bool readOnly() const
GrTexture * peekTexture() const
GrSurface * peekSurface() const
bool isInstantiated() const
bool readOnly() const
Definition GrSurface.h:80
bool supportsExternalMemory() const
Definition GrVkCaps.h:148
bool supportsDRMFormatModifiers() const
Definition GrVkCaps.h:168
uint32_t queueIndex() const
Definition GrVkGpu.h:73
const GrVkCaps & vkCaps() const
Definition GrVkGpu.h:61
VkImageLayout currentLayout() const
Definition GrVkImage.h:132
void updateImageLayout(VkImageLayout newLayout)
Definition GrVkImage.h:170
T * get() const
Definition SkRefCnt.h:303
void reset(T *ptr=nullptr)
Definition SkRefCnt.h:310
sk_sp< SkImage > image
Definition examples.cpp:29
FlTexture * texture
SK_API GrBackendFormat MakeVk(VkFormat format, bool willUseDRMFormatModifiers=false)
SK_API void SetVkImageLayout(GrBackendTexture *, VkImageLayout)
SK_API GrBackendTexture MakeVk(int width, int height, const GrVkImageInfo &, std::string_view label={})
SK_API bool GetVkImageInfo(const GrBackendTexture &, GrVkImageInfo *)
constexpr SkColor4f kTransparent
Definition SkColor.h:434
SK_API bool GetBackendTextureFromImage(const SkImage *img, GrBackendTexture *outTexture, bool flushPendingGrContextIO, GrSurfaceOrigin *origin=nullptr)
SK_API sk_sp< SkImage > BorrowTextureFrom(GrRecordingContext *context, const GrBackendTexture &backendTexture, GrSurfaceOrigin origin, SkColorType colorType, SkAlphaType alphaType, sk_sp< SkColorSpace > colorSpace, TextureReleaseProc textureReleaseProc=nullptr, ReleaseContext releaseContext=nullptr)
GrTextureProxy * GetTextureImageProxy(SkImage *image, GrRecordingContext *rContext)
std::tuple< GrSurfaceProxyView, GrColorType > AsView(GrRecordingContext *rContext, const SkImage *img, skgpu::Mipmapped mipmapped, GrImageTexGenPolicy policy)
Protected
Definition GpuTypes.h:61
uint32_t fCurrentQueueFamily
Definition GrVkTypes.h:34
VkImageLayout fImageLayout
Definition GrVkTypes.h:29
VkImageLayout
@ VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL
@ VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
@ VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
@ VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT
#define VK_QUEUE_FAMILY_EXTERNAL
@ VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT