Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
BackendSurfaceMutableStateTest.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2020 Google LLC
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
9#include "tests/Test.h"
10
11#ifdef SK_VULKAN
20#include "include/gpu/GrTypes.h"
35
36#include <vulkan/vulkan_core.h>
37#include <cstdint>
38
39class GrTexture;
40struct GrContextOptions;
41
44
45DEF_GANESH_TEST_FOR_VULKAN_CONTEXT(VkBackendSurfaceMutableStateTest,
47 ctxInfo,
49 using namespace skgpu;
50
51 auto dContext = ctxInfo.directContext();
52
53 Protected isProtected = Protected(dContext->priv().caps()->supportsProtectedContent());
54
56 GrBackendTexture backendTex = dContext->createBackendTexture(
57 32, 32, format, Mipmapped::kNo, GrRenderable::kNo, isProtected);
58
59 REPORTER_ASSERT(reporter, backendTex.isValid());
60
63 VkImageLayout initLayout = info.fImageLayout;
64 uint32_t initQueue = info.fCurrentQueueFamily;
65 MutableTextureState initState = skgpu::MutableTextureStates::MakeVulkan(initLayout, initQueue);
66
67 // Verify that setting that state via a copy of a backendTexture is reflected in all the
68 // backendTextures.
69 GrBackendTexture backendTexCopy = backendTex;
71 REPORTER_ASSERT(reporter, initLayout == info.fImageLayout);
72 REPORTER_ASSERT(reporter, initQueue == info.fCurrentQueueFamily);
73
76 backendTexCopy.setMutableState(newState);
77
81
85
86 // Setting back to the init state since we didn't actually change it
87 backendTex.setMutableState(initState);
88
89 sk_sp<SkImage> wrappedImage = SkImages::BorrowTextureFrom(dContext,
90 backendTex,
94 nullptr);
95
96 GrSurfaceProxy* proxy = sk_gpu_test::GetTextureImageProxy(wrappedImage.get(), dContext);
97
100 GrTexture* texture = proxy->peekTexture();
102
103 // Verify that modifying the layout via the GrVkTexture is reflected in the GrBackendTexture
104 GrVkImage* vkTexture = static_cast<GrVkTexture*>(texture)->textureImage();
105 REPORTER_ASSERT(reporter, initLayout == vkTexture->currentLayout());
106 REPORTER_ASSERT(reporter, initQueue == vkTexture->currentQueueFamilyIndex());
108
111 REPORTER_ASSERT(reporter, initQueue == info.fCurrentQueueFamily);
112
113 GrBackendTexture backendTexImage;
114 bool ok = SkImages::GetBackendTextureFromImage(wrappedImage, &backendTexImage, false);
118 REPORTER_ASSERT(reporter, initQueue == info.fCurrentQueueFamily);
119
120 // Verify that modifying the layout via the GrBackendTexutre is reflected in the GrVkTexture
121 backendTexImage.setMutableState(newState);
124 REPORTER_ASSERT(reporter, VK_QUEUE_FAMILY_IGNORED == info.fCurrentQueueFamily);
125
126 vkTexture->setQueueFamilyIndex(initQueue);
127 vkTexture->updateImageLayout(initLayout);
128
130 REPORTER_ASSERT(reporter, initLayout == info.fImageLayout);
131 REPORTER_ASSERT(reporter, initQueue == info.fCurrentQueueFamily);
132
134 REPORTER_ASSERT(reporter, initLayout == info.fImageLayout);
135 REPORTER_ASSERT(reporter, initQueue == info.fCurrentQueueFamily);
136
138 REPORTER_ASSERT(reporter, initLayout == info.fImageLayout);
139 REPORTER_ASSERT(reporter, initQueue == info.fCurrentQueueFamily);
140
141 // Test using the setBackendTextureStateAPI. Unlike the previous test this will actually add
142 // real transitions to the image so we need to be careful about doing actual valid transitions.
143 GrVkGpu* gpu = static_cast<GrVkGpu*>(dContext->priv().getGpu());
144
145 MutableTextureState previousState;
146
147 dContext->setBackendTextureState(backendTex, newState, &previousState);
148
151 REPORTER_ASSERT(reporter, gpu->queueIndex() == info.fCurrentQueueFamily);
152
153 REPORTER_ASSERT(reporter, previousState.isValid());
154 REPORTER_ASSERT(reporter, previousState.backend() == BackendApi::kVulkan);
155 REPORTER_ASSERT(reporter, GetVkImageLayout(previousState) == initLayout);
156 REPORTER_ASSERT(reporter, GetVkQueueFamilyIndex(previousState) == initQueue);
157
158 // Make sure passing in VK_IMAGE_LAYOUT_UNDEFINED does not change the layout
161 dContext->setBackendTextureState(backendTex, noopState, &previousState);
164 REPORTER_ASSERT(reporter, gpu->queueIndex() == info.fCurrentQueueFamily);
165
166 REPORTER_ASSERT(reporter, previousState.isValid());
167 REPORTER_ASSERT(reporter, previousState.backend() == BackendApi::kVulkan);
170 REPORTER_ASSERT(reporter, GetVkQueueFamilyIndex(previousState) == gpu->queueIndex());
171
172 // To test queue transitions, we don't have any other valid queue available so instead we try
173 // to transition to external queue.
174 if (gpu->vkCaps().supportsExternalMemory()) {
177
178 dContext->setBackendTextureState(backendTex, externalState, &previousState);
179
182 REPORTER_ASSERT(reporter, VK_QUEUE_FAMILY_EXTERNAL == info.fCurrentQueueFamily);
183
184 REPORTER_ASSERT(reporter, previousState.isValid());
185 REPORTER_ASSERT(reporter, previousState.backend() == BackendApi::kVulkan);
188 REPORTER_ASSERT(reporter, GetVkQueueFamilyIndex(previousState) == gpu->queueIndex());
189
190 dContext->submit();
191
192 // Go back to the initial queue. Also we should stay in VK_IMAGE_LAYOUT_GENERAL since we
193 // are passing in VK_IMAGE_LAYOUT_UNDEFINED
194 MutableTextureState externalState2 =
196 dContext->setBackendTextureState(backendTex, externalState2, &previousState);
197
200 REPORTER_ASSERT(reporter, gpu->queueIndex() == info.fCurrentQueueFamily);
201
202 REPORTER_ASSERT(reporter, previousState.isValid());
203 REPORTER_ASSERT(reporter, previousState.backend() == BackendApi::kVulkan);
206 }
207
208 // We must submit this work before we try to delete the backend texture.
209 dContext->submit(GrSyncCpu::kYes);
210
211 dContext->deleteBackendTexture(backendTex);
212}
213
214#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
void setMutableState(const skgpu::MutableTextureState &)
GrTexture * peekTexture() const
bool isInstantiated() const
bool supportsExternalMemory() const
Definition GrVkCaps.h:148
uint32_t queueIndex() const
Definition GrVkGpu.h:73
const GrVkCaps & vkCaps() const
Definition GrVkGpu.h:61
void setQueueFamilyIndex(uint32_t queueFamilyIndex)
Definition GrVkImage.h:156
VkImageLayout currentLayout() const
Definition GrVkImage.h:132
void updateImageLayout(VkImageLayout newLayout)
Definition GrVkImage.h:170
uint32_t currentQueueFamilyIndex() const
Definition GrVkImage.h:152
T * get() const
Definition SkRefCnt.h:303
uint32_t uint32_t * format
FlTexture * texture
SK_API GrBackendFormat MakeVk(VkFormat format, bool willUseDRMFormatModifiers=false)
SK_API bool GetVkImageInfo(const GrBackendTexture &, GrVkImageInfo *)
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)
SK_API uint32_t GetVkQueueFamilyIndex(const MutableTextureState &state)
SK_API MutableTextureState MakeVulkan(VkImageLayout layout, uint32_t queueFamilyIndex)
SK_API VkImageLayout GetVkImageLayout(const MutableTextureState &state)
Protected
Definition GpuTypes.h:61
VkImageLayout
@ VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL
@ VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
@ VK_IMAGE_LAYOUT_UNDEFINED
@ VK_IMAGE_LAYOUT_GENERAL
#define VK_QUEUE_FAMILY_EXTERNAL
@ VK_FORMAT_R8G8B8A8_UNORM
#define VK_QUEUE_FAMILY_IGNORED