1*8975f5c5SAndroid Build Coastguard Worker //
2*8975f5c5SAndroid Build Coastguard Worker // Copyright 2019 The ANGLE Project Authors. All rights reserved.
3*8975f5c5SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
4*8975f5c5SAndroid Build Coastguard Worker // found in the LICENSE file.
5*8975f5c5SAndroid Build Coastguard Worker //
6*8975f5c5SAndroid Build Coastguard Worker
7*8975f5c5SAndroid Build Coastguard Worker // VulkanExternalImageTest.cpp : Tests of images allocated externally using Vulkan.
8*8975f5c5SAndroid Build Coastguard Worker
9*8975f5c5SAndroid Build Coastguard Worker #include "test_utils/ANGLETest.h"
10*8975f5c5SAndroid Build Coastguard Worker
11*8975f5c5SAndroid Build Coastguard Worker #include "common/debug.h"
12*8975f5c5SAndroid Build Coastguard Worker #include "test_utils/VulkanHelper.h"
13*8975f5c5SAndroid Build Coastguard Worker #include "test_utils/gl_raii.h"
14*8975f5c5SAndroid Build Coastguard Worker
15*8975f5c5SAndroid Build Coastguard Worker namespace angle
16*8975f5c5SAndroid Build Coastguard Worker {
17*8975f5c5SAndroid Build Coastguard Worker
18*8975f5c5SAndroid Build Coastguard Worker namespace
19*8975f5c5SAndroid Build Coastguard Worker {
20*8975f5c5SAndroid Build Coastguard Worker
21*8975f5c5SAndroid Build Coastguard Worker constexpr int kInvalidFd = -1;
22*8975f5c5SAndroid Build Coastguard Worker
23*8975f5c5SAndroid Build Coastguard Worker constexpr VkImageUsageFlags kDefaultImageUsageFlags =
24*8975f5c5SAndroid Build Coastguard Worker VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT |
25*8975f5c5SAndroid Build Coastguard Worker VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
26*8975f5c5SAndroid Build Coastguard Worker VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT;
27*8975f5c5SAndroid Build Coastguard Worker constexpr VkImageCreateFlags kDefaultImageCreateFlags = 0;
28*8975f5c5SAndroid Build Coastguard Worker
29*8975f5c5SAndroid Build Coastguard Worker constexpr VkImageUsageFlags kNoStorageImageUsageFlags =
30*8975f5c5SAndroid Build Coastguard Worker kDefaultImageUsageFlags & ~VK_IMAGE_USAGE_STORAGE_BIT;
31*8975f5c5SAndroid Build Coastguard Worker constexpr VkImageCreateFlags kMutableImageCreateFlags =
32*8975f5c5SAndroid Build Coastguard Worker kDefaultImageCreateFlags | VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
33*8975f5c5SAndroid Build Coastguard Worker
34*8975f5c5SAndroid Build Coastguard Worker // List of VkFormat/internalformat combinations Chrome uses.
35*8975f5c5SAndroid Build Coastguard Worker // This is compiled from the maps in
36*8975f5c5SAndroid Build Coastguard Worker // components/viz/common/resources/resource_format_utils.cc.
37*8975f5c5SAndroid Build Coastguard Worker const struct ImageFormatPair
38*8975f5c5SAndroid Build Coastguard Worker {
39*8975f5c5SAndroid Build Coastguard Worker VkFormat vkFormat;
40*8975f5c5SAndroid Build Coastguard Worker GLenum internalFormat;
41*8975f5c5SAndroid Build Coastguard Worker const char *requiredExtension;
42*8975f5c5SAndroid Build Coastguard Worker } kChromeFormats[] = {
43*8975f5c5SAndroid Build Coastguard Worker {VK_FORMAT_R8G8B8A8_UNORM, GL_RGBA8_OES}, // RGBA_8888
44*8975f5c5SAndroid Build Coastguard Worker {VK_FORMAT_B8G8R8A8_UNORM, GL_BGRA8_EXT}, // BGRA_8888
45*8975f5c5SAndroid Build Coastguard Worker {VK_FORMAT_R4G4B4A4_UNORM_PACK16, GL_RGBA4}, // RGBA_4444
46*8975f5c5SAndroid Build Coastguard Worker {VK_FORMAT_R16G16B16A16_SFLOAT, GL_RGBA16F_EXT}, // RGBA_F16
47*8975f5c5SAndroid Build Coastguard Worker {VK_FORMAT_R8_UNORM, GL_R8_EXT}, // RED_8
48*8975f5c5SAndroid Build Coastguard Worker {VK_FORMAT_R5G6B5_UNORM_PACK16, GL_RGB565}, // RGB_565
49*8975f5c5SAndroid Build Coastguard Worker {VK_FORMAT_R16_UNORM, GL_R16_EXT, "GL_EXT_texture_norm16"}, // R16_EXT
50*8975f5c5SAndroid Build Coastguard Worker {VK_FORMAT_A2B10G10R10_UNORM_PACK32, GL_RGB10_A2_EXT}, // RGBA_1010102
51*8975f5c5SAndroid Build Coastguard Worker {VK_FORMAT_R8_UNORM, GL_ALPHA8_EXT}, // ALPHA_8
52*8975f5c5SAndroid Build Coastguard Worker {VK_FORMAT_R8_UNORM, GL_LUMINANCE8_EXT}, // LUMINANCE_8
53*8975f5c5SAndroid Build Coastguard Worker {VK_FORMAT_R8G8_UNORM, GL_RG8_EXT}, // RG_88
54*8975f5c5SAndroid Build Coastguard Worker {VK_FORMAT_R8G8B8A8_UNORM, GL_RGB8_OES}, // RGBX_8888
55*8975f5c5SAndroid Build Coastguard Worker };
56*8975f5c5SAndroid Build Coastguard Worker
57*8975f5c5SAndroid Build Coastguard Worker struct OpaqueFdTraits
58*8975f5c5SAndroid Build Coastguard Worker {
59*8975f5c5SAndroid Build Coastguard Worker using Handle = int;
InvalidHandleangle::__anon91eea5720111::OpaqueFdTraits60*8975f5c5SAndroid Build Coastguard Worker static Handle InvalidHandle() { return kInvalidFd; }
61*8975f5c5SAndroid Build Coastguard Worker
MemoryObjectExtensionangle::__anon91eea5720111::OpaqueFdTraits62*8975f5c5SAndroid Build Coastguard Worker static const char *MemoryObjectExtension() { return "GL_EXT_memory_object_fd"; }
SemaphoreExtensionangle::__anon91eea5720111::OpaqueFdTraits63*8975f5c5SAndroid Build Coastguard Worker static const char *SemaphoreExtension() { return "GL_EXT_semaphore_fd"; }
64*8975f5c5SAndroid Build Coastguard Worker
CanCreateSemaphoreangle::__anon91eea5720111::OpaqueFdTraits65*8975f5c5SAndroid Build Coastguard Worker static bool CanCreateSemaphore(const VulkanHelper &helper)
66*8975f5c5SAndroid Build Coastguard Worker {
67*8975f5c5SAndroid Build Coastguard Worker return helper.canCreateSemaphoreOpaqueFd();
68*8975f5c5SAndroid Build Coastguard Worker }
69*8975f5c5SAndroid Build Coastguard Worker
CreateSemaphoreangle::__anon91eea5720111::OpaqueFdTraits70*8975f5c5SAndroid Build Coastguard Worker static VkResult CreateSemaphore(VulkanHelper *helper, VkSemaphore *semaphore)
71*8975f5c5SAndroid Build Coastguard Worker {
72*8975f5c5SAndroid Build Coastguard Worker return helper->createSemaphoreOpaqueFd(semaphore);
73*8975f5c5SAndroid Build Coastguard Worker }
74*8975f5c5SAndroid Build Coastguard Worker
ExportSemaphoreangle::__anon91eea5720111::OpaqueFdTraits75*8975f5c5SAndroid Build Coastguard Worker static VkResult ExportSemaphore(VulkanHelper *helper, VkSemaphore semaphore, Handle *handle)
76*8975f5c5SAndroid Build Coastguard Worker {
77*8975f5c5SAndroid Build Coastguard Worker return helper->exportSemaphoreOpaqueFd(semaphore, handle);
78*8975f5c5SAndroid Build Coastguard Worker }
79*8975f5c5SAndroid Build Coastguard Worker
ImportSemaphoreangle::__anon91eea5720111::OpaqueFdTraits80*8975f5c5SAndroid Build Coastguard Worker static void ImportSemaphore(GLuint semaphore, Handle handle)
81*8975f5c5SAndroid Build Coastguard Worker {
82*8975f5c5SAndroid Build Coastguard Worker glImportSemaphoreFdEXT(semaphore, GL_HANDLE_TYPE_OPAQUE_FD_EXT, handle);
83*8975f5c5SAndroid Build Coastguard Worker }
84*8975f5c5SAndroid Build Coastguard Worker
CanCreateImageangle::__anon91eea5720111::OpaqueFdTraits85*8975f5c5SAndroid Build Coastguard Worker static bool CanCreateImage(const VulkanHelper &helper,
86*8975f5c5SAndroid Build Coastguard Worker VkFormat format,
87*8975f5c5SAndroid Build Coastguard Worker VkImageType type,
88*8975f5c5SAndroid Build Coastguard Worker VkImageTiling tiling,
89*8975f5c5SAndroid Build Coastguard Worker VkImageCreateFlags createFlags,
90*8975f5c5SAndroid Build Coastguard Worker VkImageUsageFlags usageFlags)
91*8975f5c5SAndroid Build Coastguard Worker {
92*8975f5c5SAndroid Build Coastguard Worker return helper.canCreateImageOpaqueFd(format, type, tiling, createFlags, usageFlags);
93*8975f5c5SAndroid Build Coastguard Worker }
94*8975f5c5SAndroid Build Coastguard Worker
CreateImage2Dangle::__anon91eea5720111::OpaqueFdTraits95*8975f5c5SAndroid Build Coastguard Worker static VkResult CreateImage2D(VulkanHelper *helper,
96*8975f5c5SAndroid Build Coastguard Worker VkFormat format,
97*8975f5c5SAndroid Build Coastguard Worker VkImageCreateFlags createFlags,
98*8975f5c5SAndroid Build Coastguard Worker VkImageUsageFlags usageFlags,
99*8975f5c5SAndroid Build Coastguard Worker const void *imageCreateInfoPNext,
100*8975f5c5SAndroid Build Coastguard Worker VkExtent3D extent,
101*8975f5c5SAndroid Build Coastguard Worker VkImage *imageOut,
102*8975f5c5SAndroid Build Coastguard Worker VkDeviceMemory *deviceMemoryOut,
103*8975f5c5SAndroid Build Coastguard Worker VkDeviceSize *deviceMemorySizeOut)
104*8975f5c5SAndroid Build Coastguard Worker {
105*8975f5c5SAndroid Build Coastguard Worker return helper->createImage2DOpaqueFd(format, createFlags, usageFlags, imageCreateInfoPNext,
106*8975f5c5SAndroid Build Coastguard Worker extent, imageOut, deviceMemoryOut,
107*8975f5c5SAndroid Build Coastguard Worker deviceMemorySizeOut);
108*8975f5c5SAndroid Build Coastguard Worker }
109*8975f5c5SAndroid Build Coastguard Worker
ExportMemoryangle::__anon91eea5720111::OpaqueFdTraits110*8975f5c5SAndroid Build Coastguard Worker static VkResult ExportMemory(VulkanHelper *helper, VkDeviceMemory deviceMemory, Handle *handle)
111*8975f5c5SAndroid Build Coastguard Worker {
112*8975f5c5SAndroid Build Coastguard Worker return helper->exportMemoryOpaqueFd(deviceMemory, handle);
113*8975f5c5SAndroid Build Coastguard Worker }
114*8975f5c5SAndroid Build Coastguard Worker
ImportMemoryangle::__anon91eea5720111::OpaqueFdTraits115*8975f5c5SAndroid Build Coastguard Worker static void ImportMemory(GLuint memoryObject, GLuint64 size, Handle handle)
116*8975f5c5SAndroid Build Coastguard Worker {
117*8975f5c5SAndroid Build Coastguard Worker glImportMemoryFdEXT(memoryObject, size, GL_HANDLE_TYPE_OPAQUE_FD_EXT, handle);
118*8975f5c5SAndroid Build Coastguard Worker }
119*8975f5c5SAndroid Build Coastguard Worker };
120*8975f5c5SAndroid Build Coastguard Worker
121*8975f5c5SAndroid Build Coastguard Worker struct FuchsiaTraits
122*8975f5c5SAndroid Build Coastguard Worker {
123*8975f5c5SAndroid Build Coastguard Worker using Handle = zx_handle_t;
124*8975f5c5SAndroid Build Coastguard Worker
InvalidHandleangle::__anon91eea5720111::FuchsiaTraits125*8975f5c5SAndroid Build Coastguard Worker static Handle InvalidHandle() { return ZX_HANDLE_INVALID; }
126*8975f5c5SAndroid Build Coastguard Worker
MemoryObjectExtensionangle::__anon91eea5720111::FuchsiaTraits127*8975f5c5SAndroid Build Coastguard Worker static const char *MemoryObjectExtension() { return "GL_ANGLE_memory_object_fuchsia"; }
SemaphoreExtensionangle::__anon91eea5720111::FuchsiaTraits128*8975f5c5SAndroid Build Coastguard Worker static const char *SemaphoreExtension() { return "GL_ANGLE_semaphore_fuchsia"; }
129*8975f5c5SAndroid Build Coastguard Worker
CanCreateSemaphoreangle::__anon91eea5720111::FuchsiaTraits130*8975f5c5SAndroid Build Coastguard Worker static bool CanCreateSemaphore(const VulkanHelper &helper)
131*8975f5c5SAndroid Build Coastguard Worker {
132*8975f5c5SAndroid Build Coastguard Worker return helper.canCreateSemaphoreZirconEvent();
133*8975f5c5SAndroid Build Coastguard Worker }
134*8975f5c5SAndroid Build Coastguard Worker
CreateSemaphoreangle::__anon91eea5720111::FuchsiaTraits135*8975f5c5SAndroid Build Coastguard Worker static VkResult CreateSemaphore(VulkanHelper *helper, VkSemaphore *semaphore)
136*8975f5c5SAndroid Build Coastguard Worker {
137*8975f5c5SAndroid Build Coastguard Worker return helper->createSemaphoreZirconEvent(semaphore);
138*8975f5c5SAndroid Build Coastguard Worker }
139*8975f5c5SAndroid Build Coastguard Worker
ExportSemaphoreangle::__anon91eea5720111::FuchsiaTraits140*8975f5c5SAndroid Build Coastguard Worker static VkResult ExportSemaphore(VulkanHelper *helper, VkSemaphore semaphore, Handle *handle)
141*8975f5c5SAndroid Build Coastguard Worker {
142*8975f5c5SAndroid Build Coastguard Worker return helper->exportSemaphoreZirconEvent(semaphore, handle);
143*8975f5c5SAndroid Build Coastguard Worker }
144*8975f5c5SAndroid Build Coastguard Worker
ImportSemaphoreangle::__anon91eea5720111::FuchsiaTraits145*8975f5c5SAndroid Build Coastguard Worker static void ImportSemaphore(GLuint semaphore, Handle handle)
146*8975f5c5SAndroid Build Coastguard Worker {
147*8975f5c5SAndroid Build Coastguard Worker glImportSemaphoreZirconHandleANGLE(semaphore, GL_HANDLE_TYPE_ZIRCON_EVENT_ANGLE, handle);
148*8975f5c5SAndroid Build Coastguard Worker }
149*8975f5c5SAndroid Build Coastguard Worker
CanCreateImageangle::__anon91eea5720111::FuchsiaTraits150*8975f5c5SAndroid Build Coastguard Worker static bool CanCreateImage(const VulkanHelper &helper,
151*8975f5c5SAndroid Build Coastguard Worker VkFormat format,
152*8975f5c5SAndroid Build Coastguard Worker VkImageType type,
153*8975f5c5SAndroid Build Coastguard Worker VkImageTiling tiling,
154*8975f5c5SAndroid Build Coastguard Worker VkImageCreateFlags createFlags,
155*8975f5c5SAndroid Build Coastguard Worker VkImageUsageFlags usageFlags)
156*8975f5c5SAndroid Build Coastguard Worker {
157*8975f5c5SAndroid Build Coastguard Worker return helper.canCreateImageZirconVmo(format, type, tiling, createFlags, usageFlags);
158*8975f5c5SAndroid Build Coastguard Worker }
159*8975f5c5SAndroid Build Coastguard Worker
CreateImage2Dangle::__anon91eea5720111::FuchsiaTraits160*8975f5c5SAndroid Build Coastguard Worker static VkResult CreateImage2D(VulkanHelper *helper,
161*8975f5c5SAndroid Build Coastguard Worker VkFormat format,
162*8975f5c5SAndroid Build Coastguard Worker VkImageCreateFlags createFlags,
163*8975f5c5SAndroid Build Coastguard Worker VkImageUsageFlags usageFlags,
164*8975f5c5SAndroid Build Coastguard Worker const void *imageCreateInfoPNext,
165*8975f5c5SAndroid Build Coastguard Worker VkExtent3D extent,
166*8975f5c5SAndroid Build Coastguard Worker VkImage *imageOut,
167*8975f5c5SAndroid Build Coastguard Worker VkDeviceMemory *deviceMemoryOut,
168*8975f5c5SAndroid Build Coastguard Worker VkDeviceSize *deviceMemorySizeOut)
169*8975f5c5SAndroid Build Coastguard Worker {
170*8975f5c5SAndroid Build Coastguard Worker return helper->createImage2DZirconVmo(format, createFlags, usageFlags, imageCreateInfoPNext,
171*8975f5c5SAndroid Build Coastguard Worker extent, imageOut, deviceMemoryOut,
172*8975f5c5SAndroid Build Coastguard Worker deviceMemorySizeOut);
173*8975f5c5SAndroid Build Coastguard Worker }
174*8975f5c5SAndroid Build Coastguard Worker
ExportMemoryangle::__anon91eea5720111::FuchsiaTraits175*8975f5c5SAndroid Build Coastguard Worker static VkResult ExportMemory(VulkanHelper *helper, VkDeviceMemory deviceMemory, Handle *handle)
176*8975f5c5SAndroid Build Coastguard Worker {
177*8975f5c5SAndroid Build Coastguard Worker return helper->exportMemoryZirconVmo(deviceMemory, handle);
178*8975f5c5SAndroid Build Coastguard Worker }
179*8975f5c5SAndroid Build Coastguard Worker
ImportMemoryangle::__anon91eea5720111::FuchsiaTraits180*8975f5c5SAndroid Build Coastguard Worker static void ImportMemory(GLuint memoryObject, GLuint64 size, Handle handle)
181*8975f5c5SAndroid Build Coastguard Worker {
182*8975f5c5SAndroid Build Coastguard Worker glImportMemoryZirconHandleANGLE(memoryObject, size, GL_HANDLE_TYPE_ZIRCON_VMO_ANGLE,
183*8975f5c5SAndroid Build Coastguard Worker handle);
184*8975f5c5SAndroid Build Coastguard Worker }
185*8975f5c5SAndroid Build Coastguard Worker };
186*8975f5c5SAndroid Build Coastguard Worker
GetPostReleaseVulkanLayout(GLenum glLayout)187*8975f5c5SAndroid Build Coastguard Worker VkImageLayout GetPostReleaseVulkanLayout(GLenum glLayout)
188*8975f5c5SAndroid Build Coastguard Worker {
189*8975f5c5SAndroid Build Coastguard Worker switch (glLayout)
190*8975f5c5SAndroid Build Coastguard Worker {
191*8975f5c5SAndroid Build Coastguard Worker case GL_NONE:
192*8975f5c5SAndroid Build Coastguard Worker case GL_LAYOUT_GENERAL_EXT:
193*8975f5c5SAndroid Build Coastguard Worker default:
194*8975f5c5SAndroid Build Coastguard Worker return VK_IMAGE_LAYOUT_GENERAL;
195*8975f5c5SAndroid Build Coastguard Worker case GL_LAYOUT_COLOR_ATTACHMENT_EXT:
196*8975f5c5SAndroid Build Coastguard Worker return VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
197*8975f5c5SAndroid Build Coastguard Worker case GL_LAYOUT_DEPTH_STENCIL_ATTACHMENT_EXT:
198*8975f5c5SAndroid Build Coastguard Worker return VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
199*8975f5c5SAndroid Build Coastguard Worker case GL_LAYOUT_DEPTH_STENCIL_READ_ONLY_EXT:
200*8975f5c5SAndroid Build Coastguard Worker return VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
201*8975f5c5SAndroid Build Coastguard Worker case GL_LAYOUT_SHADER_READ_ONLY_EXT:
202*8975f5c5SAndroid Build Coastguard Worker return VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
203*8975f5c5SAndroid Build Coastguard Worker case GL_LAYOUT_TRANSFER_SRC_EXT:
204*8975f5c5SAndroid Build Coastguard Worker return VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
205*8975f5c5SAndroid Build Coastguard Worker case GL_LAYOUT_TRANSFER_DST_EXT:
206*8975f5c5SAndroid Build Coastguard Worker return VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
207*8975f5c5SAndroid Build Coastguard Worker case GL_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_EXT:
208*8975f5c5SAndroid Build Coastguard Worker return VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL_KHR;
209*8975f5c5SAndroid Build Coastguard Worker case GL_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_EXT:
210*8975f5c5SAndroid Build Coastguard Worker return VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL_KHR;
211*8975f5c5SAndroid Build Coastguard Worker }
212*8975f5c5SAndroid Build Coastguard Worker }
213*8975f5c5SAndroid Build Coastguard Worker
AdjustCreateFlags(bool useMemoryObjectFlags,VkImageCreateFlags * createFlags)214*8975f5c5SAndroid Build Coastguard Worker void AdjustCreateFlags(bool useMemoryObjectFlags, VkImageCreateFlags *createFlags)
215*8975f5c5SAndroid Build Coastguard Worker {
216*8975f5c5SAndroid Build Coastguard Worker // If the GL_ANGLE_memory_object_flags extension is not supported, GL assumes that the mutable
217*8975f5c5SAndroid Build Coastguard Worker // create flag is specified.
218*8975f5c5SAndroid Build Coastguard Worker if (!useMemoryObjectFlags)
219*8975f5c5SAndroid Build Coastguard Worker {
220*8975f5c5SAndroid Build Coastguard Worker *createFlags |= VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
221*8975f5c5SAndroid Build Coastguard Worker }
222*8975f5c5SAndroid Build Coastguard Worker
223*8975f5c5SAndroid Build Coastguard Worker // The spec is not clear about the other create flags.
224*8975f5c5SAndroid Build Coastguard Worker }
225*8975f5c5SAndroid Build Coastguard Worker
226*8975f5c5SAndroid Build Coastguard Worker constexpr uint32_t kWidth = 64;
227*8975f5c5SAndroid Build Coastguard Worker constexpr uint32_t kHeight = 64;
228*8975f5c5SAndroid Build Coastguard Worker
229*8975f5c5SAndroid Build Coastguard Worker } // namespace
230*8975f5c5SAndroid Build Coastguard Worker
231*8975f5c5SAndroid Build Coastguard Worker class VulkanExternalImageTest : public ANGLETest<>
232*8975f5c5SAndroid Build Coastguard Worker {
233*8975f5c5SAndroid Build Coastguard Worker protected:
VulkanExternalImageTest()234*8975f5c5SAndroid Build Coastguard Worker VulkanExternalImageTest()
235*8975f5c5SAndroid Build Coastguard Worker {
236*8975f5c5SAndroid Build Coastguard Worker setWindowWidth(1);
237*8975f5c5SAndroid Build Coastguard Worker setWindowHeight(1);
238*8975f5c5SAndroid Build Coastguard Worker setConfigRedBits(8);
239*8975f5c5SAndroid Build Coastguard Worker setConfigGreenBits(8);
240*8975f5c5SAndroid Build Coastguard Worker setConfigBlueBits(8);
241*8975f5c5SAndroid Build Coastguard Worker setConfigAlphaBits(8);
242*8975f5c5SAndroid Build Coastguard Worker }
243*8975f5c5SAndroid Build Coastguard Worker
244*8975f5c5SAndroid Build Coastguard Worker template <typename Traits>
245*8975f5c5SAndroid Build Coastguard Worker void runShouldDrawTest(bool isSwiftshader, bool enableDebugLayers);
246*8975f5c5SAndroid Build Coastguard Worker
247*8975f5c5SAndroid Build Coastguard Worker template <typename Traits>
248*8975f5c5SAndroid Build Coastguard Worker void runWaitSemaphoresRetainsContentTest(bool isSwiftshader, bool enableDebugLayers);
249*8975f5c5SAndroid Build Coastguard Worker };
250*8975f5c5SAndroid Build Coastguard Worker
251*8975f5c5SAndroid Build Coastguard Worker class VulkanExternalImageTestES31 : public VulkanExternalImageTest
252*8975f5c5SAndroid Build Coastguard Worker {};
253*8975f5c5SAndroid Build Coastguard Worker
254*8975f5c5SAndroid Build Coastguard Worker template <typename Traits>
RunShouldImportMemoryTest(VkImageCreateFlags createFlags,VkImageUsageFlags usageFlags,bool isSwiftshader,bool enableDebugLayers)255*8975f5c5SAndroid Build Coastguard Worker void RunShouldImportMemoryTest(VkImageCreateFlags createFlags,
256*8975f5c5SAndroid Build Coastguard Worker VkImageUsageFlags usageFlags,
257*8975f5c5SAndroid Build Coastguard Worker bool isSwiftshader,
258*8975f5c5SAndroid Build Coastguard Worker bool enableDebugLayers)
259*8975f5c5SAndroid Build Coastguard Worker {
260*8975f5c5SAndroid Build Coastguard Worker ASSERT(EnsureGLExtensionEnabled(Traits::MemoryObjectExtension()));
261*8975f5c5SAndroid Build Coastguard Worker
262*8975f5c5SAndroid Build Coastguard Worker VulkanHelper helper;
263*8975f5c5SAndroid Build Coastguard Worker helper.initialize(isSwiftshader, enableDebugLayers);
264*8975f5c5SAndroid Build Coastguard Worker
265*8975f5c5SAndroid Build Coastguard Worker VkFormat format = VK_FORMAT_R8G8B8A8_UNORM;
266*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!Traits::CanCreateImage(helper, format, VK_IMAGE_TYPE_2D,
267*8975f5c5SAndroid Build Coastguard Worker VK_IMAGE_TILING_OPTIMAL, createFlags, usageFlags));
268*8975f5c5SAndroid Build Coastguard Worker
269*8975f5c5SAndroid Build Coastguard Worker VkImage image = VK_NULL_HANDLE;
270*8975f5c5SAndroid Build Coastguard Worker VkDeviceMemory deviceMemory = VK_NULL_HANDLE;
271*8975f5c5SAndroid Build Coastguard Worker VkDeviceSize deviceMemorySize = 0;
272*8975f5c5SAndroid Build Coastguard Worker
273*8975f5c5SAndroid Build Coastguard Worker VkExtent3D extent = {1, 1, 1};
274*8975f5c5SAndroid Build Coastguard Worker VkResult result = Traits::CreateImage2D(&helper, format, createFlags, usageFlags, nullptr,
275*8975f5c5SAndroid Build Coastguard Worker extent, &image, &deviceMemory, &deviceMemorySize);
276*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(result, VK_SUCCESS);
277*8975f5c5SAndroid Build Coastguard Worker
278*8975f5c5SAndroid Build Coastguard Worker typename Traits::Handle memoryHandle = Traits::InvalidHandle();
279*8975f5c5SAndroid Build Coastguard Worker result = Traits::ExportMemory(&helper, deviceMemory, &memoryHandle);
280*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(result, VK_SUCCESS);
281*8975f5c5SAndroid Build Coastguard Worker EXPECT_NE(memoryHandle, Traits::InvalidHandle());
282*8975f5c5SAndroid Build Coastguard Worker
283*8975f5c5SAndroid Build Coastguard Worker {
284*8975f5c5SAndroid Build Coastguard Worker GLMemoryObject memoryObject;
285*8975f5c5SAndroid Build Coastguard Worker GLint dedicatedMemory = GL_TRUE;
286*8975f5c5SAndroid Build Coastguard Worker glMemoryObjectParameterivEXT(memoryObject, GL_DEDICATED_MEMORY_OBJECT_EXT,
287*8975f5c5SAndroid Build Coastguard Worker &dedicatedMemory);
288*8975f5c5SAndroid Build Coastguard Worker Traits::ImportMemory(memoryObject, deviceMemorySize, memoryHandle);
289*8975f5c5SAndroid Build Coastguard Worker
290*8975f5c5SAndroid Build Coastguard Worker // Test that after calling glImportMemoryFdEXT, the parameters of the memory object cannot
291*8975f5c5SAndroid Build Coastguard Worker // be changed
292*8975f5c5SAndroid Build Coastguard Worker dedicatedMemory = GL_FALSE;
293*8975f5c5SAndroid Build Coastguard Worker glMemoryObjectParameterivEXT(memoryObject, GL_DEDICATED_MEMORY_OBJECT_EXT,
294*8975f5c5SAndroid Build Coastguard Worker &dedicatedMemory);
295*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_ERROR(GL_INVALID_OPERATION);
296*8975f5c5SAndroid Build Coastguard Worker }
297*8975f5c5SAndroid Build Coastguard Worker
298*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
299*8975f5c5SAndroid Build Coastguard Worker
300*8975f5c5SAndroid Build Coastguard Worker vkDestroyImage(helper.getDevice(), image, nullptr);
301*8975f5c5SAndroid Build Coastguard Worker vkFreeMemory(helper.getDevice(), deviceMemory, nullptr);
302*8975f5c5SAndroid Build Coastguard Worker }
303*8975f5c5SAndroid Build Coastguard Worker
304*8975f5c5SAndroid Build Coastguard Worker // glImportMemoryFdEXT must be able to import a valid opaque fd.
TEST_P(VulkanExternalImageTest,ShouldImportMemoryOpaqueFd)305*8975f5c5SAndroid Build Coastguard Worker TEST_P(VulkanExternalImageTest, ShouldImportMemoryOpaqueFd)
306*8975f5c5SAndroid Build Coastguard Worker {
307*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_memory_object_fd"));
308*8975f5c5SAndroid Build Coastguard Worker RunShouldImportMemoryTest<OpaqueFdTraits>(kDefaultImageCreateFlags, kDefaultImageUsageFlags,
309*8975f5c5SAndroid Build Coastguard Worker isSwiftshader(), enableDebugLayers());
310*8975f5c5SAndroid Build Coastguard Worker }
311*8975f5c5SAndroid Build Coastguard Worker
312*8975f5c5SAndroid Build Coastguard Worker // glImportMemoryZirconHandleANGLE must be able to import a valid vmo.
TEST_P(VulkanExternalImageTest,ShouldImportMemoryZirconVmo)313*8975f5c5SAndroid Build Coastguard Worker TEST_P(VulkanExternalImageTest, ShouldImportMemoryZirconVmo)
314*8975f5c5SAndroid Build Coastguard Worker {
315*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_ANGLE_memory_object_fuchsia"));
316*8975f5c5SAndroid Build Coastguard Worker RunShouldImportMemoryTest<FuchsiaTraits>(kDefaultImageCreateFlags, kDefaultImageUsageFlags,
317*8975f5c5SAndroid Build Coastguard Worker isSwiftshader(), enableDebugLayers());
318*8975f5c5SAndroid Build Coastguard Worker }
319*8975f5c5SAndroid Build Coastguard Worker
320*8975f5c5SAndroid Build Coastguard Worker template <typename Traits>
RunShouldImportSemaphoreTest(bool isSwiftshader,bool enableDebugLayers)321*8975f5c5SAndroid Build Coastguard Worker void RunShouldImportSemaphoreTest(bool isSwiftshader, bool enableDebugLayers)
322*8975f5c5SAndroid Build Coastguard Worker {
323*8975f5c5SAndroid Build Coastguard Worker ASSERT(EnsureGLExtensionEnabled(Traits::SemaphoreExtension()));
324*8975f5c5SAndroid Build Coastguard Worker
325*8975f5c5SAndroid Build Coastguard Worker VulkanHelper helper;
326*8975f5c5SAndroid Build Coastguard Worker helper.initialize(isSwiftshader, enableDebugLayers);
327*8975f5c5SAndroid Build Coastguard Worker
328*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!Traits::CanCreateSemaphore(helper));
329*8975f5c5SAndroid Build Coastguard Worker
330*8975f5c5SAndroid Build Coastguard Worker VkSemaphore vkSemaphore = VK_NULL_HANDLE;
331*8975f5c5SAndroid Build Coastguard Worker VkResult result = helper.createSemaphoreOpaqueFd(&vkSemaphore);
332*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(result, VK_SUCCESS);
333*8975f5c5SAndroid Build Coastguard Worker
334*8975f5c5SAndroid Build Coastguard Worker typename Traits::Handle semaphoreHandle = Traits::InvalidHandle();
335*8975f5c5SAndroid Build Coastguard Worker result = Traits::ExportSemaphore(&helper, vkSemaphore, &semaphoreHandle);
336*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(result, VK_SUCCESS);
337*8975f5c5SAndroid Build Coastguard Worker EXPECT_NE(semaphoreHandle, Traits::InvalidHandle());
338*8975f5c5SAndroid Build Coastguard Worker
339*8975f5c5SAndroid Build Coastguard Worker {
340*8975f5c5SAndroid Build Coastguard Worker GLSemaphore glSemaphore;
341*8975f5c5SAndroid Build Coastguard Worker Traits::ImportSemaphore(glSemaphore, semaphoreHandle);
342*8975f5c5SAndroid Build Coastguard Worker }
343*8975f5c5SAndroid Build Coastguard Worker
344*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
345*8975f5c5SAndroid Build Coastguard Worker
346*8975f5c5SAndroid Build Coastguard Worker vkDestroySemaphore(helper.getDevice(), vkSemaphore, nullptr);
347*8975f5c5SAndroid Build Coastguard Worker }
348*8975f5c5SAndroid Build Coastguard Worker
349*8975f5c5SAndroid Build Coastguard Worker // glImportSemaphoreFdEXT must be able to import a valid opaque fd.
TEST_P(VulkanExternalImageTest,ShouldImportSemaphoreOpaqueFd)350*8975f5c5SAndroid Build Coastguard Worker TEST_P(VulkanExternalImageTest, ShouldImportSemaphoreOpaqueFd)
351*8975f5c5SAndroid Build Coastguard Worker {
352*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_semaphore_fd"));
353*8975f5c5SAndroid Build Coastguard Worker RunShouldImportSemaphoreTest<OpaqueFdTraits>(isSwiftshader(), enableDebugLayers());
354*8975f5c5SAndroid Build Coastguard Worker }
355*8975f5c5SAndroid Build Coastguard Worker
356*8975f5c5SAndroid Build Coastguard Worker // glImportSemaphoreZirconHandleANGLE must be able to import a valid handle.
TEST_P(VulkanExternalImageTest,ShouldImportSemaphoreZirconEvent)357*8975f5c5SAndroid Build Coastguard Worker TEST_P(VulkanExternalImageTest, ShouldImportSemaphoreZirconEvent)
358*8975f5c5SAndroid Build Coastguard Worker {
359*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_ANGLE_semaphore_fuchsia"));
360*8975f5c5SAndroid Build Coastguard Worker RunShouldImportSemaphoreTest<FuchsiaTraits>(isSwiftshader(), enableDebugLayers());
361*8975f5c5SAndroid Build Coastguard Worker }
362*8975f5c5SAndroid Build Coastguard Worker
363*8975f5c5SAndroid Build Coastguard Worker template <typename Traits>
RunShouldClearTest(bool useMemoryObjectFlags,VkImageCreateFlags createFlags,VkImageUsageFlags usageFlags,bool isSwiftshader,bool enableDebugLayers)364*8975f5c5SAndroid Build Coastguard Worker void RunShouldClearTest(bool useMemoryObjectFlags,
365*8975f5c5SAndroid Build Coastguard Worker VkImageCreateFlags createFlags,
366*8975f5c5SAndroid Build Coastguard Worker VkImageUsageFlags usageFlags,
367*8975f5c5SAndroid Build Coastguard Worker bool isSwiftshader,
368*8975f5c5SAndroid Build Coastguard Worker bool enableDebugLayers)
369*8975f5c5SAndroid Build Coastguard Worker {
370*8975f5c5SAndroid Build Coastguard Worker ASSERT(EnsureGLExtensionEnabled(Traits::MemoryObjectExtension()));
371*8975f5c5SAndroid Build Coastguard Worker
372*8975f5c5SAndroid Build Coastguard Worker VulkanHelper helper;
373*8975f5c5SAndroid Build Coastguard Worker helper.initialize(isSwiftshader, enableDebugLayers);
374*8975f5c5SAndroid Build Coastguard Worker
375*8975f5c5SAndroid Build Coastguard Worker AdjustCreateFlags(useMemoryObjectFlags, &createFlags);
376*8975f5c5SAndroid Build Coastguard Worker
377*8975f5c5SAndroid Build Coastguard Worker VkFormat format = VK_FORMAT_R8G8B8A8_UNORM;
378*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!Traits::CanCreateImage(helper, format, VK_IMAGE_TYPE_2D,
379*8975f5c5SAndroid Build Coastguard Worker VK_IMAGE_TILING_OPTIMAL, createFlags, usageFlags));
380*8975f5c5SAndroid Build Coastguard Worker
381*8975f5c5SAndroid Build Coastguard Worker VkImage image = VK_NULL_HANDLE;
382*8975f5c5SAndroid Build Coastguard Worker VkDeviceMemory deviceMemory = VK_NULL_HANDLE;
383*8975f5c5SAndroid Build Coastguard Worker VkDeviceSize deviceMemorySize = 0;
384*8975f5c5SAndroid Build Coastguard Worker
385*8975f5c5SAndroid Build Coastguard Worker VkExtent3D extent = {1, 1, 1};
386*8975f5c5SAndroid Build Coastguard Worker VkResult result = Traits::CreateImage2D(&helper, format, createFlags, usageFlags, nullptr,
387*8975f5c5SAndroid Build Coastguard Worker extent, &image, &deviceMemory, &deviceMemorySize);
388*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(result, VK_SUCCESS);
389*8975f5c5SAndroid Build Coastguard Worker
390*8975f5c5SAndroid Build Coastguard Worker typename Traits::Handle memoryHandle = Traits::InvalidHandle();
391*8975f5c5SAndroid Build Coastguard Worker result = Traits::ExportMemory(&helper, deviceMemory, &memoryHandle);
392*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(result, VK_SUCCESS);
393*8975f5c5SAndroid Build Coastguard Worker EXPECT_NE(memoryHandle, Traits::InvalidHandle());
394*8975f5c5SAndroid Build Coastguard Worker
395*8975f5c5SAndroid Build Coastguard Worker {
396*8975f5c5SAndroid Build Coastguard Worker GLMemoryObject memoryObject;
397*8975f5c5SAndroid Build Coastguard Worker GLint dedicatedMemory = GL_TRUE;
398*8975f5c5SAndroid Build Coastguard Worker glMemoryObjectParameterivEXT(memoryObject, GL_DEDICATED_MEMORY_OBJECT_EXT,
399*8975f5c5SAndroid Build Coastguard Worker &dedicatedMemory);
400*8975f5c5SAndroid Build Coastguard Worker Traits::ImportMemory(memoryObject, deviceMemorySize, memoryHandle);
401*8975f5c5SAndroid Build Coastguard Worker
402*8975f5c5SAndroid Build Coastguard Worker GLTexture texture;
403*8975f5c5SAndroid Build Coastguard Worker glBindTexture(GL_TEXTURE_2D, texture);
404*8975f5c5SAndroid Build Coastguard Worker if (useMemoryObjectFlags)
405*8975f5c5SAndroid Build Coastguard Worker {
406*8975f5c5SAndroid Build Coastguard Worker glTexStorageMemFlags2DANGLE(GL_TEXTURE_2D, 1, GL_RGBA8, 1, 1, memoryObject, 0,
407*8975f5c5SAndroid Build Coastguard Worker createFlags, usageFlags, nullptr);
408*8975f5c5SAndroid Build Coastguard Worker }
409*8975f5c5SAndroid Build Coastguard Worker else
410*8975f5c5SAndroid Build Coastguard Worker {
411*8975f5c5SAndroid Build Coastguard Worker glTexStorageMem2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8, 1, 1, memoryObject, 0);
412*8975f5c5SAndroid Build Coastguard Worker }
413*8975f5c5SAndroid Build Coastguard Worker
414*8975f5c5SAndroid Build Coastguard Worker GLFramebuffer framebuffer;
415*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
416*8975f5c5SAndroid Build Coastguard Worker glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
417*8975f5c5SAndroid Build Coastguard Worker
418*8975f5c5SAndroid Build Coastguard Worker glClearColor(0.5f, 0.5f, 0.5f, 0.5f);
419*8975f5c5SAndroid Build Coastguard Worker glClear(GL_COLOR_BUFFER_BIT);
420*8975f5c5SAndroid Build Coastguard Worker
421*8975f5c5SAndroid Build Coastguard Worker EXPECT_PIXEL_NEAR(0, 0, 128, 128, 128, 128, 1.0);
422*8975f5c5SAndroid Build Coastguard Worker }
423*8975f5c5SAndroid Build Coastguard Worker
424*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
425*8975f5c5SAndroid Build Coastguard Worker
426*8975f5c5SAndroid Build Coastguard Worker vkDestroyImage(helper.getDevice(), image, nullptr);
427*8975f5c5SAndroid Build Coastguard Worker vkFreeMemory(helper.getDevice(), deviceMemory, nullptr);
428*8975f5c5SAndroid Build Coastguard Worker }
429*8975f5c5SAndroid Build Coastguard Worker
430*8975f5c5SAndroid Build Coastguard Worker // Test creating and clearing a simple RGBA8 texture in an opaque fd.
TEST_P(VulkanExternalImageTest,ShouldClearOpaqueFdRGBA8)431*8975f5c5SAndroid Build Coastguard Worker TEST_P(VulkanExternalImageTest, ShouldClearOpaqueFdRGBA8)
432*8975f5c5SAndroid Build Coastguard Worker {
433*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_memory_object_fd"));
434*8975f5c5SAndroid Build Coastguard Worker // http://anglebug.com/42263236
435*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(IsAndroid() && IsOpenGL() && (IsPixel2() || IsPixel2XL()));
436*8975f5c5SAndroid Build Coastguard Worker RunShouldClearTest<OpaqueFdTraits>(false, kDefaultImageCreateFlags, kDefaultImageUsageFlags,
437*8975f5c5SAndroid Build Coastguard Worker isSwiftshader(), enableDebugLayers());
438*8975f5c5SAndroid Build Coastguard Worker }
439*8975f5c5SAndroid Build Coastguard Worker
440*8975f5c5SAndroid Build Coastguard Worker // Test creating and clearing a simple RGBA8 texture in an opaque fd, using
441*8975f5c5SAndroid Build Coastguard Worker // GL_ANGLE_memory_object_flags.
TEST_P(VulkanExternalImageTest,ShouldClearOpaqueWithFlagsFdRGBA8)442*8975f5c5SAndroid Build Coastguard Worker TEST_P(VulkanExternalImageTest, ShouldClearOpaqueWithFlagsFdRGBA8)
443*8975f5c5SAndroid Build Coastguard Worker {
444*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_memory_object_fd"));
445*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_ANGLE_memory_object_flags"));
446*8975f5c5SAndroid Build Coastguard Worker RunShouldClearTest<OpaqueFdTraits>(true, kDefaultImageCreateFlags, kDefaultImageUsageFlags,
447*8975f5c5SAndroid Build Coastguard Worker isSwiftshader(), enableDebugLayers());
448*8975f5c5SAndroid Build Coastguard Worker }
449*8975f5c5SAndroid Build Coastguard Worker
450*8975f5c5SAndroid Build Coastguard Worker // Test creating and clearing a simple RGBA8 texture without STORAGE usage in an opaque fd.
TEST_P(VulkanExternalImageTest,ShouldClearNoStorageUsageOpaqueFdRGBA8)451*8975f5c5SAndroid Build Coastguard Worker TEST_P(VulkanExternalImageTest, ShouldClearNoStorageUsageOpaqueFdRGBA8)
452*8975f5c5SAndroid Build Coastguard Worker {
453*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_memory_object_fd"));
454*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_ANGLE_memory_object_flags"));
455*8975f5c5SAndroid Build Coastguard Worker RunShouldClearTest<OpaqueFdTraits>(true, kDefaultImageCreateFlags, kNoStorageImageUsageFlags,
456*8975f5c5SAndroid Build Coastguard Worker isSwiftshader(), enableDebugLayers());
457*8975f5c5SAndroid Build Coastguard Worker }
458*8975f5c5SAndroid Build Coastguard Worker
459*8975f5c5SAndroid Build Coastguard Worker // Test creating and clearing a simple RGBA8 texture without STORAGE usage but with MUTABLE in an
460*8975f5c5SAndroid Build Coastguard Worker // opaque fd.
TEST_P(VulkanExternalImageTest,ShouldClearMutableNoStorageUsageOpaqueFdRGBA8)461*8975f5c5SAndroid Build Coastguard Worker TEST_P(VulkanExternalImageTest, ShouldClearMutableNoStorageUsageOpaqueFdRGBA8)
462*8975f5c5SAndroid Build Coastguard Worker {
463*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_memory_object_fd"));
464*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_ANGLE_memory_object_flags"));
465*8975f5c5SAndroid Build Coastguard Worker RunShouldClearTest<OpaqueFdTraits>(true, kMutableImageCreateFlags, kNoStorageImageUsageFlags,
466*8975f5c5SAndroid Build Coastguard Worker isSwiftshader(), enableDebugLayers());
467*8975f5c5SAndroid Build Coastguard Worker }
468*8975f5c5SAndroid Build Coastguard Worker
469*8975f5c5SAndroid Build Coastguard Worker // Test creating and clearing a simple RGBA8 texture in a zircon vmo.
TEST_P(VulkanExternalImageTest,ShouldClearZirconVmoRGBA8)470*8975f5c5SAndroid Build Coastguard Worker TEST_P(VulkanExternalImageTest, ShouldClearZirconVmoRGBA8)
471*8975f5c5SAndroid Build Coastguard Worker {
472*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_ANGLE_memory_object_fuchsia"));
473*8975f5c5SAndroid Build Coastguard Worker RunShouldClearTest<FuchsiaTraits>(false, kDefaultImageCreateFlags, kDefaultImageUsageFlags,
474*8975f5c5SAndroid Build Coastguard Worker isSwiftshader(), enableDebugLayers());
475*8975f5c5SAndroid Build Coastguard Worker }
476*8975f5c5SAndroid Build Coastguard Worker
477*8975f5c5SAndroid Build Coastguard Worker // Test creating and clearing a simple RGBA8 texture in a zircon vmo, using
478*8975f5c5SAndroid Build Coastguard Worker // GL_ANGLE_memory_object_flags.
TEST_P(VulkanExternalImageTest,ShouldClearZirconWithFlagsVmoRGBA8)479*8975f5c5SAndroid Build Coastguard Worker TEST_P(VulkanExternalImageTest, ShouldClearZirconWithFlagsVmoRGBA8)
480*8975f5c5SAndroid Build Coastguard Worker {
481*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_ANGLE_memory_object_fuchsia"));
482*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_ANGLE_memory_object_flags"));
483*8975f5c5SAndroid Build Coastguard Worker RunShouldClearTest<FuchsiaTraits>(true, kDefaultImageCreateFlags, kDefaultImageUsageFlags,
484*8975f5c5SAndroid Build Coastguard Worker isSwiftshader(), enableDebugLayers());
485*8975f5c5SAndroid Build Coastguard Worker }
486*8975f5c5SAndroid Build Coastguard Worker
487*8975f5c5SAndroid Build Coastguard Worker // Test creating and clearing a simple RGBA8 texture without STORAGE usage in a zircon vmo.
TEST_P(VulkanExternalImageTest,ShouldClearNoStorageUsageZirconVmoRGBA8)488*8975f5c5SAndroid Build Coastguard Worker TEST_P(VulkanExternalImageTest, ShouldClearNoStorageUsageZirconVmoRGBA8)
489*8975f5c5SAndroid Build Coastguard Worker {
490*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_ANGLE_memory_object_fuchsia"));
491*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_ANGLE_memory_object_flags"));
492*8975f5c5SAndroid Build Coastguard Worker RunShouldClearTest<FuchsiaTraits>(true, kDefaultImageCreateFlags, kNoStorageImageUsageFlags,
493*8975f5c5SAndroid Build Coastguard Worker isSwiftshader(), enableDebugLayers());
494*8975f5c5SAndroid Build Coastguard Worker }
495*8975f5c5SAndroid Build Coastguard Worker
496*8975f5c5SAndroid Build Coastguard Worker // Test creating and clearing a simple RGBA8 texture without STORAGE usage but with MUTABLE in a
497*8975f5c5SAndroid Build Coastguard Worker // zircon vmo.
TEST_P(VulkanExternalImageTest,ShouldClearMutableNoStorageUsageZirconVmoRGBA8)498*8975f5c5SAndroid Build Coastguard Worker TEST_P(VulkanExternalImageTest, ShouldClearMutableNoStorageUsageZirconVmoRGBA8)
499*8975f5c5SAndroid Build Coastguard Worker {
500*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_ANGLE_memory_object_fuchsia"));
501*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_ANGLE_memory_object_flags"));
502*8975f5c5SAndroid Build Coastguard Worker RunShouldClearTest<FuchsiaTraits>(true, kMutableImageCreateFlags, kNoStorageImageUsageFlags,
503*8975f5c5SAndroid Build Coastguard Worker isSwiftshader(), enableDebugLayers());
504*8975f5c5SAndroid Build Coastguard Worker }
505*8975f5c5SAndroid Build Coastguard Worker
506*8975f5c5SAndroid Build Coastguard Worker template <typename Traits>
RunTextureFormatCompatChromiumTest(bool useMemoryObjectFlags,VkImageCreateFlags createFlags,VkImageUsageFlags usageFlags,bool isSwiftshader,bool enableDebugLayers,bool isES3)507*8975f5c5SAndroid Build Coastguard Worker void RunTextureFormatCompatChromiumTest(bool useMemoryObjectFlags,
508*8975f5c5SAndroid Build Coastguard Worker VkImageCreateFlags createFlags,
509*8975f5c5SAndroid Build Coastguard Worker VkImageUsageFlags usageFlags,
510*8975f5c5SAndroid Build Coastguard Worker bool isSwiftshader,
511*8975f5c5SAndroid Build Coastguard Worker bool enableDebugLayers,
512*8975f5c5SAndroid Build Coastguard Worker bool isES3)
513*8975f5c5SAndroid Build Coastguard Worker {
514*8975f5c5SAndroid Build Coastguard Worker ASSERT(EnsureGLExtensionEnabled(Traits::MemoryObjectExtension()));
515*8975f5c5SAndroid Build Coastguard Worker
516*8975f5c5SAndroid Build Coastguard Worker AdjustCreateFlags(useMemoryObjectFlags, &createFlags);
517*8975f5c5SAndroid Build Coastguard Worker
518*8975f5c5SAndroid Build Coastguard Worker VulkanHelper helper;
519*8975f5c5SAndroid Build Coastguard Worker helper.initialize(isSwiftshader, enableDebugLayers);
520*8975f5c5SAndroid Build Coastguard Worker for (const ImageFormatPair &format : kChromeFormats)
521*8975f5c5SAndroid Build Coastguard Worker {
522*8975f5c5SAndroid Build Coastguard Worker // https://crbug.com/angleproject/5046
523*8975f5c5SAndroid Build Coastguard Worker if ((format.vkFormat == VK_FORMAT_R4G4B4A4_UNORM_PACK16) && IsIntel())
524*8975f5c5SAndroid Build Coastguard Worker {
525*8975f5c5SAndroid Build Coastguard Worker continue;
526*8975f5c5SAndroid Build Coastguard Worker }
527*8975f5c5SAndroid Build Coastguard Worker
528*8975f5c5SAndroid Build Coastguard Worker if (!Traits::CanCreateImage(helper, format.vkFormat, VK_IMAGE_TYPE_2D,
529*8975f5c5SAndroid Build Coastguard Worker VK_IMAGE_TILING_OPTIMAL, createFlags, usageFlags))
530*8975f5c5SAndroid Build Coastguard Worker {
531*8975f5c5SAndroid Build Coastguard Worker continue;
532*8975f5c5SAndroid Build Coastguard Worker }
533*8975f5c5SAndroid Build Coastguard Worker
534*8975f5c5SAndroid Build Coastguard Worker if (format.requiredExtension && !IsGLExtensionEnabled(format.requiredExtension))
535*8975f5c5SAndroid Build Coastguard Worker {
536*8975f5c5SAndroid Build Coastguard Worker continue;
537*8975f5c5SAndroid Build Coastguard Worker }
538*8975f5c5SAndroid Build Coastguard Worker
539*8975f5c5SAndroid Build Coastguard Worker if (format.internalFormat == GL_RGB10_A2_EXT && !isES3 &&
540*8975f5c5SAndroid Build Coastguard Worker !IsGLExtensionEnabled("GL_EXT_texture_type_2_10_10_10_REV"))
541*8975f5c5SAndroid Build Coastguard Worker {
542*8975f5c5SAndroid Build Coastguard Worker continue;
543*8975f5c5SAndroid Build Coastguard Worker }
544*8975f5c5SAndroid Build Coastguard Worker
545*8975f5c5SAndroid Build Coastguard Worker VkImage image = VK_NULL_HANDLE;
546*8975f5c5SAndroid Build Coastguard Worker VkDeviceMemory deviceMemory = VK_NULL_HANDLE;
547*8975f5c5SAndroid Build Coastguard Worker VkDeviceSize deviceMemorySize = 0;
548*8975f5c5SAndroid Build Coastguard Worker
549*8975f5c5SAndroid Build Coastguard Worker VkExtent3D extent = {113, 211, 1};
550*8975f5c5SAndroid Build Coastguard Worker VkResult result =
551*8975f5c5SAndroid Build Coastguard Worker Traits::CreateImage2D(&helper, format.vkFormat, createFlags, usageFlags, nullptr,
552*8975f5c5SAndroid Build Coastguard Worker extent, &image, &deviceMemory, &deviceMemorySize);
553*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(result, VK_SUCCESS);
554*8975f5c5SAndroid Build Coastguard Worker
555*8975f5c5SAndroid Build Coastguard Worker typename Traits::Handle memoryHandle = Traits::InvalidHandle();
556*8975f5c5SAndroid Build Coastguard Worker result = Traits::ExportMemory(&helper, deviceMemory, &memoryHandle);
557*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(result, VK_SUCCESS);
558*8975f5c5SAndroid Build Coastguard Worker EXPECT_NE(memoryHandle, Traits::InvalidHandle());
559*8975f5c5SAndroid Build Coastguard Worker
560*8975f5c5SAndroid Build Coastguard Worker {
561*8975f5c5SAndroid Build Coastguard Worker GLMemoryObject memoryObject;
562*8975f5c5SAndroid Build Coastguard Worker GLint dedicatedMemory = GL_TRUE;
563*8975f5c5SAndroid Build Coastguard Worker glMemoryObjectParameterivEXT(memoryObject, GL_DEDICATED_MEMORY_OBJECT_EXT,
564*8975f5c5SAndroid Build Coastguard Worker &dedicatedMemory);
565*8975f5c5SAndroid Build Coastguard Worker Traits::ImportMemory(memoryObject, deviceMemorySize, memoryHandle);
566*8975f5c5SAndroid Build Coastguard Worker
567*8975f5c5SAndroid Build Coastguard Worker GLTexture texture;
568*8975f5c5SAndroid Build Coastguard Worker glBindTexture(GL_TEXTURE_2D, texture);
569*8975f5c5SAndroid Build Coastguard Worker if (useMemoryObjectFlags)
570*8975f5c5SAndroid Build Coastguard Worker {
571*8975f5c5SAndroid Build Coastguard Worker glTexStorageMemFlags2DANGLE(GL_TEXTURE_2D, 1, format.internalFormat, extent.width,
572*8975f5c5SAndroid Build Coastguard Worker extent.height, memoryObject, 0, createFlags, usageFlags,
573*8975f5c5SAndroid Build Coastguard Worker nullptr);
574*8975f5c5SAndroid Build Coastguard Worker }
575*8975f5c5SAndroid Build Coastguard Worker else
576*8975f5c5SAndroid Build Coastguard Worker {
577*8975f5c5SAndroid Build Coastguard Worker glTexStorageMem2DEXT(GL_TEXTURE_2D, 1, format.internalFormat, extent.width,
578*8975f5c5SAndroid Build Coastguard Worker extent.height, memoryObject, 0);
579*8975f5c5SAndroid Build Coastguard Worker }
580*8975f5c5SAndroid Build Coastguard Worker }
581*8975f5c5SAndroid Build Coastguard Worker
582*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
583*8975f5c5SAndroid Build Coastguard Worker
584*8975f5c5SAndroid Build Coastguard Worker vkDestroyImage(helper.getDevice(), image, nullptr);
585*8975f5c5SAndroid Build Coastguard Worker vkFreeMemory(helper.getDevice(), deviceMemory, nullptr);
586*8975f5c5SAndroid Build Coastguard Worker }
587*8975f5c5SAndroid Build Coastguard Worker }
588*8975f5c5SAndroid Build Coastguard Worker
589*8975f5c5SAndroid Build Coastguard Worker // Test all format combinations used by Chrome import successfully (opaque fd).
TEST_P(VulkanExternalImageTest,TextureFormatCompatChromiumFd)590*8975f5c5SAndroid Build Coastguard Worker TEST_P(VulkanExternalImageTest, TextureFormatCompatChromiumFd)
591*8975f5c5SAndroid Build Coastguard Worker {
592*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_memory_object_fd"));
593*8975f5c5SAndroid Build Coastguard Worker RunTextureFormatCompatChromiumTest<OpaqueFdTraits>(
594*8975f5c5SAndroid Build Coastguard Worker false, kDefaultImageCreateFlags, kDefaultImageUsageFlags, isSwiftshader(),
595*8975f5c5SAndroid Build Coastguard Worker enableDebugLayers(), getClientMajorVersion() >= 3);
596*8975f5c5SAndroid Build Coastguard Worker }
597*8975f5c5SAndroid Build Coastguard Worker
598*8975f5c5SAndroid Build Coastguard Worker // Test all format combinations used by Chrome import successfully (opaque fd), using
599*8975f5c5SAndroid Build Coastguard Worker // GL_ANGLE_memory_object_flags.
TEST_P(VulkanExternalImageTest,TextureFormatCompatChromiumWithFlagsFd)600*8975f5c5SAndroid Build Coastguard Worker TEST_P(VulkanExternalImageTest, TextureFormatCompatChromiumWithFlagsFd)
601*8975f5c5SAndroid Build Coastguard Worker {
602*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_memory_object_fd"));
603*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_ANGLE_memory_object_flags"));
604*8975f5c5SAndroid Build Coastguard Worker RunTextureFormatCompatChromiumTest<OpaqueFdTraits>(
605*8975f5c5SAndroid Build Coastguard Worker true, kDefaultImageCreateFlags, kDefaultImageUsageFlags, isSwiftshader(),
606*8975f5c5SAndroid Build Coastguard Worker enableDebugLayers(), getClientMajorVersion() >= 3);
607*8975f5c5SAndroid Build Coastguard Worker }
608*8975f5c5SAndroid Build Coastguard Worker
609*8975f5c5SAndroid Build Coastguard Worker // Test all format combinations used by Chrome import successfully (opaque fd), without STORAGE
610*8975f5c5SAndroid Build Coastguard Worker // usage.
TEST_P(VulkanExternalImageTest,TextureFormatCompatChromiumNoStorageFd)611*8975f5c5SAndroid Build Coastguard Worker TEST_P(VulkanExternalImageTest, TextureFormatCompatChromiumNoStorageFd)
612*8975f5c5SAndroid Build Coastguard Worker {
613*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_memory_object_fd"));
614*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_ANGLE_memory_object_flags"));
615*8975f5c5SAndroid Build Coastguard Worker RunTextureFormatCompatChromiumTest<OpaqueFdTraits>(
616*8975f5c5SAndroid Build Coastguard Worker true, kDefaultImageCreateFlags, kNoStorageImageUsageFlags, isSwiftshader(),
617*8975f5c5SAndroid Build Coastguard Worker enableDebugLayers(), getClientMajorVersion() >= 3);
618*8975f5c5SAndroid Build Coastguard Worker }
619*8975f5c5SAndroid Build Coastguard Worker
620*8975f5c5SAndroid Build Coastguard Worker // Test all format combinations used by Chrome import successfully (opaque fd), without STORAGE
621*8975f5c5SAndroid Build Coastguard Worker // usage but with MUTABLE.
TEST_P(VulkanExternalImageTest,TextureFormatCompatChromiumMutableNoStorageFd)622*8975f5c5SAndroid Build Coastguard Worker TEST_P(VulkanExternalImageTest, TextureFormatCompatChromiumMutableNoStorageFd)
623*8975f5c5SAndroid Build Coastguard Worker {
624*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_memory_object_fd"));
625*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_ANGLE_memory_object_flags"));
626*8975f5c5SAndroid Build Coastguard Worker
627*8975f5c5SAndroid Build Coastguard Worker // http://anglebug.com/42264218
628*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(IsLinux() && IsAMD() && IsVulkan());
629*8975f5c5SAndroid Build Coastguard Worker
630*8975f5c5SAndroid Build Coastguard Worker RunTextureFormatCompatChromiumTest<OpaqueFdTraits>(
631*8975f5c5SAndroid Build Coastguard Worker true, kMutableImageCreateFlags, kNoStorageImageUsageFlags, isSwiftshader(),
632*8975f5c5SAndroid Build Coastguard Worker enableDebugLayers(), getClientMajorVersion() >= 3);
633*8975f5c5SAndroid Build Coastguard Worker }
634*8975f5c5SAndroid Build Coastguard Worker
635*8975f5c5SAndroid Build Coastguard Worker // Test all format combinations used by Chrome import successfully (fuchsia).
TEST_P(VulkanExternalImageTest,TextureFormatCompatChromiumZirconVmo)636*8975f5c5SAndroid Build Coastguard Worker TEST_P(VulkanExternalImageTest, TextureFormatCompatChromiumZirconVmo)
637*8975f5c5SAndroid Build Coastguard Worker {
638*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_ANGLE_memory_object_fuchsia"));
639*8975f5c5SAndroid Build Coastguard Worker RunTextureFormatCompatChromiumTest<FuchsiaTraits>(
640*8975f5c5SAndroid Build Coastguard Worker false, kDefaultImageCreateFlags, kDefaultImageUsageFlags, isSwiftshader(),
641*8975f5c5SAndroid Build Coastguard Worker enableDebugLayers(), getClientMajorVersion() >= 3);
642*8975f5c5SAndroid Build Coastguard Worker }
643*8975f5c5SAndroid Build Coastguard Worker
644*8975f5c5SAndroid Build Coastguard Worker // Test all format combinations used by Chrome import successfully (fuchsia), using
645*8975f5c5SAndroid Build Coastguard Worker // GL_ANGLE_memory_object_flags.
TEST_P(VulkanExternalImageTest,TextureFormatCompatChromiumWithFlagsZirconVmo)646*8975f5c5SAndroid Build Coastguard Worker TEST_P(VulkanExternalImageTest, TextureFormatCompatChromiumWithFlagsZirconVmo)
647*8975f5c5SAndroid Build Coastguard Worker {
648*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_ANGLE_memory_object_fuchsia"));
649*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_ANGLE_memory_object_flags"));
650*8975f5c5SAndroid Build Coastguard Worker RunTextureFormatCompatChromiumTest<FuchsiaTraits>(
651*8975f5c5SAndroid Build Coastguard Worker true, kDefaultImageCreateFlags, kDefaultImageUsageFlags, isSwiftshader(),
652*8975f5c5SAndroid Build Coastguard Worker enableDebugLayers(), getClientMajorVersion() >= 3);
653*8975f5c5SAndroid Build Coastguard Worker }
654*8975f5c5SAndroid Build Coastguard Worker
655*8975f5c5SAndroid Build Coastguard Worker // Test all format combinations used by Chrome import successfully (fuchsia), without STORAGE usage.
TEST_P(VulkanExternalImageTest,TextureFormatCompatChromiumNoStorageZirconVmo)656*8975f5c5SAndroid Build Coastguard Worker TEST_P(VulkanExternalImageTest, TextureFormatCompatChromiumNoStorageZirconVmo)
657*8975f5c5SAndroid Build Coastguard Worker {
658*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_ANGLE_memory_object_fuchsia"));
659*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_ANGLE_memory_object_flags"));
660*8975f5c5SAndroid Build Coastguard Worker RunTextureFormatCompatChromiumTest<FuchsiaTraits>(
661*8975f5c5SAndroid Build Coastguard Worker true, kDefaultImageCreateFlags, kNoStorageImageUsageFlags, isSwiftshader(),
662*8975f5c5SAndroid Build Coastguard Worker enableDebugLayers(), getClientMajorVersion() >= 3);
663*8975f5c5SAndroid Build Coastguard Worker }
664*8975f5c5SAndroid Build Coastguard Worker
665*8975f5c5SAndroid Build Coastguard Worker // Test all format combinations used by Chrome import successfully (fuchsia), without STORAGE usage
666*8975f5c5SAndroid Build Coastguard Worker // but with MUTABLE.
TEST_P(VulkanExternalImageTest,TextureFormatCompatChromiumMutableNoStorageZirconVmo)667*8975f5c5SAndroid Build Coastguard Worker TEST_P(VulkanExternalImageTest, TextureFormatCompatChromiumMutableNoStorageZirconVmo)
668*8975f5c5SAndroid Build Coastguard Worker {
669*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_ANGLE_memory_object_fuchsia"));
670*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_ANGLE_memory_object_flags"));
671*8975f5c5SAndroid Build Coastguard Worker RunTextureFormatCompatChromiumTest<FuchsiaTraits>(
672*8975f5c5SAndroid Build Coastguard Worker true, kMutableImageCreateFlags, kNoStorageImageUsageFlags, isSwiftshader(),
673*8975f5c5SAndroid Build Coastguard Worker enableDebugLayers(), getClientMajorVersion() >= 3);
674*8975f5c5SAndroid Build Coastguard Worker }
675*8975f5c5SAndroid Build Coastguard Worker
676*8975f5c5SAndroid Build Coastguard Worker template <typename Traits>
RunShouldClearWithSemaphoresTest(bool useMemoryObjectFlags,VkImageCreateFlags createFlags,VkImageUsageFlags usageFlags,bool isSwiftshader,bool enableDebugLayers)677*8975f5c5SAndroid Build Coastguard Worker void RunShouldClearWithSemaphoresTest(bool useMemoryObjectFlags,
678*8975f5c5SAndroid Build Coastguard Worker VkImageCreateFlags createFlags,
679*8975f5c5SAndroid Build Coastguard Worker VkImageUsageFlags usageFlags,
680*8975f5c5SAndroid Build Coastguard Worker bool isSwiftshader,
681*8975f5c5SAndroid Build Coastguard Worker bool enableDebugLayers)
682*8975f5c5SAndroid Build Coastguard Worker {
683*8975f5c5SAndroid Build Coastguard Worker ASSERT(EnsureGLExtensionEnabled(Traits::MemoryObjectExtension()));
684*8975f5c5SAndroid Build Coastguard Worker ASSERT(EnsureGLExtensionEnabled(Traits::SemaphoreExtension()));
685*8975f5c5SAndroid Build Coastguard Worker
686*8975f5c5SAndroid Build Coastguard Worker AdjustCreateFlags(useMemoryObjectFlags, &createFlags);
687*8975f5c5SAndroid Build Coastguard Worker
688*8975f5c5SAndroid Build Coastguard Worker VulkanHelper helper;
689*8975f5c5SAndroid Build Coastguard Worker helper.initialize(isSwiftshader, enableDebugLayers);
690*8975f5c5SAndroid Build Coastguard Worker
691*8975f5c5SAndroid Build Coastguard Worker VkFormat format = VK_FORMAT_R8G8B8A8_UNORM;
692*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!Traits::CanCreateImage(helper, format, VK_IMAGE_TYPE_2D,
693*8975f5c5SAndroid Build Coastguard Worker VK_IMAGE_TILING_OPTIMAL, createFlags, usageFlags));
694*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!Traits::CanCreateSemaphore(helper));
695*8975f5c5SAndroid Build Coastguard Worker
696*8975f5c5SAndroid Build Coastguard Worker VkSemaphore vkAcquireSemaphore = VK_NULL_HANDLE;
697*8975f5c5SAndroid Build Coastguard Worker VkResult result = Traits::CreateSemaphore(&helper, &vkAcquireSemaphore);
698*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(result, VK_SUCCESS);
699*8975f5c5SAndroid Build Coastguard Worker EXPECT_TRUE(vkAcquireSemaphore != VK_NULL_HANDLE);
700*8975f5c5SAndroid Build Coastguard Worker
701*8975f5c5SAndroid Build Coastguard Worker VkSemaphore vkReleaseSemaphore = VK_NULL_HANDLE;
702*8975f5c5SAndroid Build Coastguard Worker result = Traits::CreateSemaphore(&helper, &vkReleaseSemaphore);
703*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(result, VK_SUCCESS);
704*8975f5c5SAndroid Build Coastguard Worker EXPECT_TRUE(vkReleaseSemaphore != VK_NULL_HANDLE);
705*8975f5c5SAndroid Build Coastguard Worker
706*8975f5c5SAndroid Build Coastguard Worker typename Traits::Handle acquireSemaphoreHandle = Traits::InvalidHandle();
707*8975f5c5SAndroid Build Coastguard Worker result = Traits::ExportSemaphore(&helper, vkAcquireSemaphore, &acquireSemaphoreHandle);
708*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(result, VK_SUCCESS);
709*8975f5c5SAndroid Build Coastguard Worker EXPECT_NE(acquireSemaphoreHandle, Traits::InvalidHandle());
710*8975f5c5SAndroid Build Coastguard Worker
711*8975f5c5SAndroid Build Coastguard Worker typename Traits::Handle releaseSemaphoreHandle = Traits::InvalidHandle();
712*8975f5c5SAndroid Build Coastguard Worker result = Traits::ExportSemaphore(&helper, vkReleaseSemaphore, &releaseSemaphoreHandle);
713*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(result, VK_SUCCESS);
714*8975f5c5SAndroid Build Coastguard Worker EXPECT_NE(releaseSemaphoreHandle, Traits::InvalidHandle());
715*8975f5c5SAndroid Build Coastguard Worker
716*8975f5c5SAndroid Build Coastguard Worker VkImage image = VK_NULL_HANDLE;
717*8975f5c5SAndroid Build Coastguard Worker VkDeviceMemory deviceMemory = VK_NULL_HANDLE;
718*8975f5c5SAndroid Build Coastguard Worker VkDeviceSize deviceMemorySize = 0;
719*8975f5c5SAndroid Build Coastguard Worker
720*8975f5c5SAndroid Build Coastguard Worker VkExtent3D extent = {1, 1, 1};
721*8975f5c5SAndroid Build Coastguard Worker result = Traits::CreateImage2D(&helper, format, createFlags, usageFlags, nullptr, extent,
722*8975f5c5SAndroid Build Coastguard Worker &image, &deviceMemory, &deviceMemorySize);
723*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(result, VK_SUCCESS);
724*8975f5c5SAndroid Build Coastguard Worker
725*8975f5c5SAndroid Build Coastguard Worker typename Traits::Handle memoryHandle = Traits::InvalidHandle();
726*8975f5c5SAndroid Build Coastguard Worker result = Traits::ExportMemory(&helper, deviceMemory, &memoryHandle);
727*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(result, VK_SUCCESS);
728*8975f5c5SAndroid Build Coastguard Worker EXPECT_NE(memoryHandle, Traits::InvalidHandle());
729*8975f5c5SAndroid Build Coastguard Worker
730*8975f5c5SAndroid Build Coastguard Worker {
731*8975f5c5SAndroid Build Coastguard Worker GLMemoryObject memoryObject;
732*8975f5c5SAndroid Build Coastguard Worker GLint dedicatedMemory = GL_TRUE;
733*8975f5c5SAndroid Build Coastguard Worker glMemoryObjectParameterivEXT(memoryObject, GL_DEDICATED_MEMORY_OBJECT_EXT,
734*8975f5c5SAndroid Build Coastguard Worker &dedicatedMemory);
735*8975f5c5SAndroid Build Coastguard Worker Traits::ImportMemory(memoryObject, deviceMemorySize, memoryHandle);
736*8975f5c5SAndroid Build Coastguard Worker
737*8975f5c5SAndroid Build Coastguard Worker GLTexture texture;
738*8975f5c5SAndroid Build Coastguard Worker glBindTexture(GL_TEXTURE_2D, texture);
739*8975f5c5SAndroid Build Coastguard Worker if (useMemoryObjectFlags)
740*8975f5c5SAndroid Build Coastguard Worker {
741*8975f5c5SAndroid Build Coastguard Worker glTexStorageMemFlags2DANGLE(GL_TEXTURE_2D, 1, GL_RGBA8, 1, 1, memoryObject, 0,
742*8975f5c5SAndroid Build Coastguard Worker createFlags, usageFlags, nullptr);
743*8975f5c5SAndroid Build Coastguard Worker }
744*8975f5c5SAndroid Build Coastguard Worker else
745*8975f5c5SAndroid Build Coastguard Worker {
746*8975f5c5SAndroid Build Coastguard Worker glTexStorageMem2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8, 1, 1, memoryObject, 0);
747*8975f5c5SAndroid Build Coastguard Worker }
748*8975f5c5SAndroid Build Coastguard Worker
749*8975f5c5SAndroid Build Coastguard Worker GLSemaphore glAcquireSemaphore;
750*8975f5c5SAndroid Build Coastguard Worker Traits::ImportSemaphore(glAcquireSemaphore, acquireSemaphoreHandle);
751*8975f5c5SAndroid Build Coastguard Worker
752*8975f5c5SAndroid Build Coastguard Worker helper.releaseImageAndSignalSemaphore(image, VK_IMAGE_LAYOUT_UNDEFINED,
753*8975f5c5SAndroid Build Coastguard Worker VK_IMAGE_LAYOUT_GENERAL, vkAcquireSemaphore);
754*8975f5c5SAndroid Build Coastguard Worker
755*8975f5c5SAndroid Build Coastguard Worker const GLuint barrierTextures[] = {
756*8975f5c5SAndroid Build Coastguard Worker texture,
757*8975f5c5SAndroid Build Coastguard Worker };
758*8975f5c5SAndroid Build Coastguard Worker constexpr uint32_t textureBarriersCount = std::extent<decltype(barrierTextures)>();
759*8975f5c5SAndroid Build Coastguard Worker const GLenum textureSrcLayouts[] = {
760*8975f5c5SAndroid Build Coastguard Worker GL_LAYOUT_GENERAL_EXT,
761*8975f5c5SAndroid Build Coastguard Worker };
762*8975f5c5SAndroid Build Coastguard Worker constexpr uint32_t textureSrcLayoutsCount = std::extent<decltype(textureSrcLayouts)>();
763*8975f5c5SAndroid Build Coastguard Worker static_assert(textureBarriersCount == textureSrcLayoutsCount,
764*8975f5c5SAndroid Build Coastguard Worker "barrierTextures and textureSrcLayouts must be the same length");
765*8975f5c5SAndroid Build Coastguard Worker glWaitSemaphoreEXT(glAcquireSemaphore, 0, nullptr, textureBarriersCount, barrierTextures,
766*8975f5c5SAndroid Build Coastguard Worker textureSrcLayouts);
767*8975f5c5SAndroid Build Coastguard Worker
768*8975f5c5SAndroid Build Coastguard Worker GLFramebuffer framebuffer;
769*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
770*8975f5c5SAndroid Build Coastguard Worker glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
771*8975f5c5SAndroid Build Coastguard Worker
772*8975f5c5SAndroid Build Coastguard Worker glClearColor(0.5f, 0.5f, 0.5f, 0.5f);
773*8975f5c5SAndroid Build Coastguard Worker glClear(GL_COLOR_BUFFER_BIT);
774*8975f5c5SAndroid Build Coastguard Worker
775*8975f5c5SAndroid Build Coastguard Worker GLSemaphore glReleaseSemaphore;
776*8975f5c5SAndroid Build Coastguard Worker Traits::ImportSemaphore(glReleaseSemaphore, releaseSemaphoreHandle);
777*8975f5c5SAndroid Build Coastguard Worker
778*8975f5c5SAndroid Build Coastguard Worker const GLenum textureDstLayouts[] = {
779*8975f5c5SAndroid Build Coastguard Worker GL_LAYOUT_TRANSFER_SRC_EXT,
780*8975f5c5SAndroid Build Coastguard Worker };
781*8975f5c5SAndroid Build Coastguard Worker constexpr uint32_t textureDstLayoutsCount = std::extent<decltype(textureSrcLayouts)>();
782*8975f5c5SAndroid Build Coastguard Worker static_assert(textureBarriersCount == textureDstLayoutsCount,
783*8975f5c5SAndroid Build Coastguard Worker "barrierTextures and textureDstLayouts must be the same length");
784*8975f5c5SAndroid Build Coastguard Worker glSignalSemaphoreEXT(glReleaseSemaphore, 0, nullptr, textureBarriersCount, barrierTextures,
785*8975f5c5SAndroid Build Coastguard Worker textureDstLayouts);
786*8975f5c5SAndroid Build Coastguard Worker
787*8975f5c5SAndroid Build Coastguard Worker helper.waitSemaphoreAndAcquireImage(image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
788*8975f5c5SAndroid Build Coastguard Worker VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
789*8975f5c5SAndroid Build Coastguard Worker vkReleaseSemaphore);
790*8975f5c5SAndroid Build Coastguard Worker uint8_t pixels[4];
791*8975f5c5SAndroid Build Coastguard Worker VkOffset3D offset = {};
792*8975f5c5SAndroid Build Coastguard Worker helper.readPixels(image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, format, offset, extent,
793*8975f5c5SAndroid Build Coastguard Worker pixels, sizeof(pixels));
794*8975f5c5SAndroid Build Coastguard Worker
795*8975f5c5SAndroid Build Coastguard Worker EXPECT_NEAR(0x80, pixels[0], 1);
796*8975f5c5SAndroid Build Coastguard Worker EXPECT_NEAR(0x80, pixels[1], 1);
797*8975f5c5SAndroid Build Coastguard Worker EXPECT_NEAR(0x80, pixels[2], 1);
798*8975f5c5SAndroid Build Coastguard Worker EXPECT_NEAR(0x80, pixels[3], 1);
799*8975f5c5SAndroid Build Coastguard Worker }
800*8975f5c5SAndroid Build Coastguard Worker
801*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
802*8975f5c5SAndroid Build Coastguard Worker
803*8975f5c5SAndroid Build Coastguard Worker vkDeviceWaitIdle(helper.getDevice());
804*8975f5c5SAndroid Build Coastguard Worker vkDestroyImage(helper.getDevice(), image, nullptr);
805*8975f5c5SAndroid Build Coastguard Worker vkDestroySemaphore(helper.getDevice(), vkAcquireSemaphore, nullptr);
806*8975f5c5SAndroid Build Coastguard Worker vkDestroySemaphore(helper.getDevice(), vkReleaseSemaphore, nullptr);
807*8975f5c5SAndroid Build Coastguard Worker vkFreeMemory(helper.getDevice(), deviceMemory, nullptr);
808*8975f5c5SAndroid Build Coastguard Worker }
809*8975f5c5SAndroid Build Coastguard Worker
810*8975f5c5SAndroid Build Coastguard Worker // Test creating and clearing RGBA8 texture in opaque fd with acquire/release.
TEST_P(VulkanExternalImageTest,ShouldClearOpaqueFdWithSemaphores)811*8975f5c5SAndroid Build Coastguard Worker TEST_P(VulkanExternalImageTest, ShouldClearOpaqueFdWithSemaphores)
812*8975f5c5SAndroid Build Coastguard Worker {
813*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_memory_object_fd"));
814*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_semaphore_fd"));
815*8975f5c5SAndroid Build Coastguard Worker
816*8975f5c5SAndroid Build Coastguard Worker // http://issuetracker.google.com/173004081
817*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(IsVulkan() && IsIntel() && IsLinux() &&
818*8975f5c5SAndroid Build Coastguard Worker getEGLWindow()->isFeatureEnabled(Feature::AsyncCommandQueue));
819*8975f5c5SAndroid Build Coastguard Worker // http://anglebug.com/42263923
820*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(IsLinux() && IsAMD() && IsDesktopOpenGL());
821*8975f5c5SAndroid Build Coastguard Worker
822*8975f5c5SAndroid Build Coastguard Worker RunShouldClearWithSemaphoresTest<OpaqueFdTraits>(false, kDefaultImageCreateFlags,
823*8975f5c5SAndroid Build Coastguard Worker kDefaultImageUsageFlags, isSwiftshader(),
824*8975f5c5SAndroid Build Coastguard Worker enableDebugLayers());
825*8975f5c5SAndroid Build Coastguard Worker }
826*8975f5c5SAndroid Build Coastguard Worker
827*8975f5c5SAndroid Build Coastguard Worker // Test creating and clearing RGBA8 texture in opaque fd with acquire/release, using
828*8975f5c5SAndroid Build Coastguard Worker // GL_ANGLE_memory_object_flags.
TEST_P(VulkanExternalImageTest,ShouldClearOpaqueFdWithSemaphoresWithFlags)829*8975f5c5SAndroid Build Coastguard Worker TEST_P(VulkanExternalImageTest, ShouldClearOpaqueFdWithSemaphoresWithFlags)
830*8975f5c5SAndroid Build Coastguard Worker {
831*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_memory_object_fd"));
832*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_semaphore_fd"));
833*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_ANGLE_memory_object_flags"));
834*8975f5c5SAndroid Build Coastguard Worker
835*8975f5c5SAndroid Build Coastguard Worker // http://issuetracker.google.com/173004081
836*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(IsVulkan() && IsIntel() && IsLinux() &&
837*8975f5c5SAndroid Build Coastguard Worker getEGLWindow()->isFeatureEnabled(Feature::AsyncCommandQueue));
838*8975f5c5SAndroid Build Coastguard Worker
839*8975f5c5SAndroid Build Coastguard Worker RunShouldClearWithSemaphoresTest<OpaqueFdTraits>(true, kDefaultImageCreateFlags,
840*8975f5c5SAndroid Build Coastguard Worker kDefaultImageUsageFlags, isSwiftshader(),
841*8975f5c5SAndroid Build Coastguard Worker enableDebugLayers());
842*8975f5c5SAndroid Build Coastguard Worker }
843*8975f5c5SAndroid Build Coastguard Worker
844*8975f5c5SAndroid Build Coastguard Worker // Test creating and clearing RGBA8 texture without STORAGE usage in opaque fd with acquire/release.
TEST_P(VulkanExternalImageTest,ShouldClearOpaqueFdWithSemaphoresNoStorage)845*8975f5c5SAndroid Build Coastguard Worker TEST_P(VulkanExternalImageTest, ShouldClearOpaqueFdWithSemaphoresNoStorage)
846*8975f5c5SAndroid Build Coastguard Worker {
847*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_memory_object_fd"));
848*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_semaphore_fd"));
849*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_ANGLE_memory_object_flags"));
850*8975f5c5SAndroid Build Coastguard Worker
851*8975f5c5SAndroid Build Coastguard Worker // http://issuetracker.google.com/173004081
852*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(IsVulkan() && IsIntel() && IsLinux() &&
853*8975f5c5SAndroid Build Coastguard Worker getEGLWindow()->isFeatureEnabled(Feature::AsyncCommandQueue));
854*8975f5c5SAndroid Build Coastguard Worker
855*8975f5c5SAndroid Build Coastguard Worker RunShouldClearWithSemaphoresTest<OpaqueFdTraits>(true, kDefaultImageCreateFlags,
856*8975f5c5SAndroid Build Coastguard Worker kNoStorageImageUsageFlags, isSwiftshader(),
857*8975f5c5SAndroid Build Coastguard Worker enableDebugLayers());
858*8975f5c5SAndroid Build Coastguard Worker }
859*8975f5c5SAndroid Build Coastguard Worker
860*8975f5c5SAndroid Build Coastguard Worker // Test creating and clearing RGBA8 texture without STORAGE usage but with MUTABLE in opaque fd with
861*8975f5c5SAndroid Build Coastguard Worker // acquire/release.
TEST_P(VulkanExternalImageTest,ShouldClearOpaqueFdWithSemaphoresMutableNoStorage)862*8975f5c5SAndroid Build Coastguard Worker TEST_P(VulkanExternalImageTest, ShouldClearOpaqueFdWithSemaphoresMutableNoStorage)
863*8975f5c5SAndroid Build Coastguard Worker {
864*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_memory_object_fd"));
865*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_semaphore_fd"));
866*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_ANGLE_memory_object_flags"));
867*8975f5c5SAndroid Build Coastguard Worker
868*8975f5c5SAndroid Build Coastguard Worker // http://issuetracker.google.com/173004081
869*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(IsVulkan() && IsIntel() && IsLinux() &&
870*8975f5c5SAndroid Build Coastguard Worker getEGLWindow()->isFeatureEnabled(Feature::AsyncCommandQueue));
871*8975f5c5SAndroid Build Coastguard Worker
872*8975f5c5SAndroid Build Coastguard Worker RunShouldClearWithSemaphoresTest<OpaqueFdTraits>(true, kMutableImageCreateFlags,
873*8975f5c5SAndroid Build Coastguard Worker kNoStorageImageUsageFlags, isSwiftshader(),
874*8975f5c5SAndroid Build Coastguard Worker enableDebugLayers());
875*8975f5c5SAndroid Build Coastguard Worker }
876*8975f5c5SAndroid Build Coastguard Worker
877*8975f5c5SAndroid Build Coastguard Worker // Test creating and clearing RGBA8 texture in zircon vmo with acquire/release.
TEST_P(VulkanExternalImageTest,ShouldClearZirconVmoWithSemaphores)878*8975f5c5SAndroid Build Coastguard Worker TEST_P(VulkanExternalImageTest, ShouldClearZirconVmoWithSemaphores)
879*8975f5c5SAndroid Build Coastguard Worker {
880*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_ANGLE_memory_object_fuchsia"));
881*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_ANGLE_semaphore_fuchsia"));
882*8975f5c5SAndroid Build Coastguard Worker RunShouldClearWithSemaphoresTest<FuchsiaTraits>(false, kDefaultImageCreateFlags,
883*8975f5c5SAndroid Build Coastguard Worker kDefaultImageUsageFlags, isSwiftshader(),
884*8975f5c5SAndroid Build Coastguard Worker enableDebugLayers());
885*8975f5c5SAndroid Build Coastguard Worker }
886*8975f5c5SAndroid Build Coastguard Worker
887*8975f5c5SAndroid Build Coastguard Worker // Test creating and clearing RGBA8 texture in zircon vmo with acquire/release, using
888*8975f5c5SAndroid Build Coastguard Worker // GL_ANGLE_memory_object_flags.
TEST_P(VulkanExternalImageTest,ShouldClearZirconVmoWithSemaphoresWithFlags)889*8975f5c5SAndroid Build Coastguard Worker TEST_P(VulkanExternalImageTest, ShouldClearZirconVmoWithSemaphoresWithFlags)
890*8975f5c5SAndroid Build Coastguard Worker {
891*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_ANGLE_memory_object_fuchsia"));
892*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_ANGLE_semaphore_fuchsia"));
893*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_ANGLE_memory_object_flags"));
894*8975f5c5SAndroid Build Coastguard Worker RunShouldClearWithSemaphoresTest<FuchsiaTraits>(true, kDefaultImageCreateFlags,
895*8975f5c5SAndroid Build Coastguard Worker kDefaultImageUsageFlags, isSwiftshader(),
896*8975f5c5SAndroid Build Coastguard Worker enableDebugLayers());
897*8975f5c5SAndroid Build Coastguard Worker }
898*8975f5c5SAndroid Build Coastguard Worker
899*8975f5c5SAndroid Build Coastguard Worker // Test creating and clearing RGBA8 texture without STORAGE usage in zircon vmo with
900*8975f5c5SAndroid Build Coastguard Worker // acquire/release.
TEST_P(VulkanExternalImageTest,ShouldClearZirconVmoWithSemaphoresNoStorage)901*8975f5c5SAndroid Build Coastguard Worker TEST_P(VulkanExternalImageTest, ShouldClearZirconVmoWithSemaphoresNoStorage)
902*8975f5c5SAndroid Build Coastguard Worker {
903*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_ANGLE_memory_object_fuchsia"));
904*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_ANGLE_semaphore_fuchsia"));
905*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_ANGLE_memory_object_flags"));
906*8975f5c5SAndroid Build Coastguard Worker RunShouldClearWithSemaphoresTest<FuchsiaTraits>(true, kDefaultImageCreateFlags,
907*8975f5c5SAndroid Build Coastguard Worker kNoStorageImageUsageFlags, isSwiftshader(),
908*8975f5c5SAndroid Build Coastguard Worker enableDebugLayers());
909*8975f5c5SAndroid Build Coastguard Worker }
910*8975f5c5SAndroid Build Coastguard Worker
911*8975f5c5SAndroid Build Coastguard Worker // Test creating and clearing RGBA8 texture without STORAGE usage but with MUTABLE in zircon vmo
912*8975f5c5SAndroid Build Coastguard Worker // with acquire/release.
TEST_P(VulkanExternalImageTest,ShouldClearZirconVmoWithSemaphoresMutableNoStorage)913*8975f5c5SAndroid Build Coastguard Worker TEST_P(VulkanExternalImageTest, ShouldClearZirconVmoWithSemaphoresMutableNoStorage)
914*8975f5c5SAndroid Build Coastguard Worker {
915*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_ANGLE_memory_object_fuchsia"));
916*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_ANGLE_semaphore_fuchsia"));
917*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_ANGLE_memory_object_flags"));
918*8975f5c5SAndroid Build Coastguard Worker RunShouldClearWithSemaphoresTest<FuchsiaTraits>(true, kMutableImageCreateFlags,
919*8975f5c5SAndroid Build Coastguard Worker kNoStorageImageUsageFlags, isSwiftshader(),
920*8975f5c5SAndroid Build Coastguard Worker enableDebugLayers());
921*8975f5c5SAndroid Build Coastguard Worker }
922*8975f5c5SAndroid Build Coastguard Worker
923*8975f5c5SAndroid Build Coastguard Worker template <typename Traits>
runShouldDrawTest(bool isSwiftshader,bool enableDebugLayers)924*8975f5c5SAndroid Build Coastguard Worker void VulkanExternalImageTest::runShouldDrawTest(bool isSwiftshader, bool enableDebugLayers)
925*8975f5c5SAndroid Build Coastguard Worker {
926*8975f5c5SAndroid Build Coastguard Worker ASSERT(EnsureGLExtensionEnabled(Traits::MemoryObjectExtension()));
927*8975f5c5SAndroid Build Coastguard Worker ASSERT(EnsureGLExtensionEnabled(Traits::SemaphoreExtension()));
928*8975f5c5SAndroid Build Coastguard Worker
929*8975f5c5SAndroid Build Coastguard Worker VulkanHelper helper;
930*8975f5c5SAndroid Build Coastguard Worker helper.initialize(isSwiftshader, enableDebugLayers);
931*8975f5c5SAndroid Build Coastguard Worker
932*8975f5c5SAndroid Build Coastguard Worker VkFormat format = VK_FORMAT_R8G8B8A8_UNORM;
933*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!Traits::CanCreateImage(helper, format, VK_IMAGE_TYPE_2D,
934*8975f5c5SAndroid Build Coastguard Worker VK_IMAGE_TILING_OPTIMAL, kDefaultImageCreateFlags,
935*8975f5c5SAndroid Build Coastguard Worker kDefaultImageUsageFlags));
936*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!Traits::CanCreateSemaphore(helper));
937*8975f5c5SAndroid Build Coastguard Worker
938*8975f5c5SAndroid Build Coastguard Worker VkSemaphore vkAcquireSemaphore = VK_NULL_HANDLE;
939*8975f5c5SAndroid Build Coastguard Worker VkResult result = Traits::CreateSemaphore(&helper, &vkAcquireSemaphore);
940*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(result, VK_SUCCESS);
941*8975f5c5SAndroid Build Coastguard Worker EXPECT_TRUE(vkAcquireSemaphore != VK_NULL_HANDLE);
942*8975f5c5SAndroid Build Coastguard Worker
943*8975f5c5SAndroid Build Coastguard Worker VkSemaphore vkReleaseSemaphore = VK_NULL_HANDLE;
944*8975f5c5SAndroid Build Coastguard Worker result = Traits::CreateSemaphore(&helper, &vkReleaseSemaphore);
945*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(result, VK_SUCCESS);
946*8975f5c5SAndroid Build Coastguard Worker EXPECT_TRUE(vkReleaseSemaphore != VK_NULL_HANDLE);
947*8975f5c5SAndroid Build Coastguard Worker
948*8975f5c5SAndroid Build Coastguard Worker typename Traits::Handle acquireSemaphoreHandle = Traits::InvalidHandle();
949*8975f5c5SAndroid Build Coastguard Worker result = Traits::ExportSemaphore(&helper, vkAcquireSemaphore, &acquireSemaphoreHandle);
950*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(result, VK_SUCCESS);
951*8975f5c5SAndroid Build Coastguard Worker EXPECT_NE(acquireSemaphoreHandle, Traits::InvalidHandle());
952*8975f5c5SAndroid Build Coastguard Worker
953*8975f5c5SAndroid Build Coastguard Worker typename Traits::Handle releaseSemaphoreHandle = Traits::InvalidHandle();
954*8975f5c5SAndroid Build Coastguard Worker result = Traits::ExportSemaphore(&helper, vkReleaseSemaphore, &releaseSemaphoreHandle);
955*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(result, VK_SUCCESS);
956*8975f5c5SAndroid Build Coastguard Worker EXPECT_NE(releaseSemaphoreHandle, Traits::InvalidHandle());
957*8975f5c5SAndroid Build Coastguard Worker
958*8975f5c5SAndroid Build Coastguard Worker VkImage image = VK_NULL_HANDLE;
959*8975f5c5SAndroid Build Coastguard Worker VkDeviceMemory deviceMemory = VK_NULL_HANDLE;
960*8975f5c5SAndroid Build Coastguard Worker VkDeviceSize deviceMemorySize = 0;
961*8975f5c5SAndroid Build Coastguard Worker
962*8975f5c5SAndroid Build Coastguard Worker VkExtent3D extent = {1, 1, 1};
963*8975f5c5SAndroid Build Coastguard Worker result =
964*8975f5c5SAndroid Build Coastguard Worker Traits::CreateImage2D(&helper, format, kDefaultImageCreateFlags, kDefaultImageUsageFlags,
965*8975f5c5SAndroid Build Coastguard Worker nullptr, extent, &image, &deviceMemory, &deviceMemorySize);
966*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(result, VK_SUCCESS);
967*8975f5c5SAndroid Build Coastguard Worker
968*8975f5c5SAndroid Build Coastguard Worker typename Traits::Handle memoryHandle = Traits::InvalidHandle();
969*8975f5c5SAndroid Build Coastguard Worker result = Traits::ExportMemory(&helper, deviceMemory, &memoryHandle);
970*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(result, VK_SUCCESS);
971*8975f5c5SAndroid Build Coastguard Worker EXPECT_NE(memoryHandle, Traits::InvalidHandle());
972*8975f5c5SAndroid Build Coastguard Worker
973*8975f5c5SAndroid Build Coastguard Worker {
974*8975f5c5SAndroid Build Coastguard Worker GLMemoryObject memoryObject;
975*8975f5c5SAndroid Build Coastguard Worker GLint dedicatedMemory = GL_TRUE;
976*8975f5c5SAndroid Build Coastguard Worker glMemoryObjectParameterivEXT(memoryObject, GL_DEDICATED_MEMORY_OBJECT_EXT,
977*8975f5c5SAndroid Build Coastguard Worker &dedicatedMemory);
978*8975f5c5SAndroid Build Coastguard Worker Traits::ImportMemory(memoryObject, deviceMemorySize, memoryHandle);
979*8975f5c5SAndroid Build Coastguard Worker
980*8975f5c5SAndroid Build Coastguard Worker GLTexture texture;
981*8975f5c5SAndroid Build Coastguard Worker glBindTexture(GL_TEXTURE_2D, texture);
982*8975f5c5SAndroid Build Coastguard Worker glTexStorageMem2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8, 1, 1, memoryObject, 0);
983*8975f5c5SAndroid Build Coastguard Worker
984*8975f5c5SAndroid Build Coastguard Worker GLSemaphore glAcquireSemaphore;
985*8975f5c5SAndroid Build Coastguard Worker Traits::ImportSemaphore(glAcquireSemaphore, acquireSemaphoreHandle);
986*8975f5c5SAndroid Build Coastguard Worker
987*8975f5c5SAndroid Build Coastguard Worker // Transfer ownership to GL.
988*8975f5c5SAndroid Build Coastguard Worker helper.releaseImageAndSignalSemaphore(image, VK_IMAGE_LAYOUT_UNDEFINED,
989*8975f5c5SAndroid Build Coastguard Worker VK_IMAGE_LAYOUT_GENERAL, vkAcquireSemaphore);
990*8975f5c5SAndroid Build Coastguard Worker
991*8975f5c5SAndroid Build Coastguard Worker const GLuint barrierTextures[] = {
992*8975f5c5SAndroid Build Coastguard Worker texture,
993*8975f5c5SAndroid Build Coastguard Worker };
994*8975f5c5SAndroid Build Coastguard Worker constexpr uint32_t textureBarriersCount = std::extent<decltype(barrierTextures)>();
995*8975f5c5SAndroid Build Coastguard Worker const GLenum textureSrcLayouts[] = {
996*8975f5c5SAndroid Build Coastguard Worker GL_LAYOUT_GENERAL_EXT,
997*8975f5c5SAndroid Build Coastguard Worker };
998*8975f5c5SAndroid Build Coastguard Worker constexpr uint32_t textureSrcLayoutsCount = std::extent<decltype(textureSrcLayouts)>();
999*8975f5c5SAndroid Build Coastguard Worker static_assert(textureBarriersCount == textureSrcLayoutsCount,
1000*8975f5c5SAndroid Build Coastguard Worker "barrierTextures and textureSrcLayouts must be the same length");
1001*8975f5c5SAndroid Build Coastguard Worker glWaitSemaphoreEXT(glAcquireSemaphore, 0, nullptr, textureBarriersCount, barrierTextures,
1002*8975f5c5SAndroid Build Coastguard Worker textureSrcLayouts);
1003*8975f5c5SAndroid Build Coastguard Worker
1004*8975f5c5SAndroid Build Coastguard Worker GLFramebuffer framebuffer;
1005*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
1006*8975f5c5SAndroid Build Coastguard Worker glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
1007*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
1008*8975f5c5SAndroid Build Coastguard Worker
1009*8975f5c5SAndroid Build Coastguard Worker // Make the texture red.
1010*8975f5c5SAndroid Build Coastguard Worker ANGLE_GL_PROGRAM(drawRed, essl1_shaders::vs::Simple(), essl1_shaders::fs::Red());
1011*8975f5c5SAndroid Build Coastguard Worker drawQuad(drawRed, essl1_shaders::PositionAttrib(), 0.0f);
1012*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
1013*8975f5c5SAndroid Build Coastguard Worker
1014*8975f5c5SAndroid Build Coastguard Worker // Transfer ownership back to test.
1015*8975f5c5SAndroid Build Coastguard Worker GLSemaphore glReleaseSemaphore;
1016*8975f5c5SAndroid Build Coastguard Worker Traits::ImportSemaphore(glReleaseSemaphore, releaseSemaphoreHandle);
1017*8975f5c5SAndroid Build Coastguard Worker
1018*8975f5c5SAndroid Build Coastguard Worker const GLenum textureDstLayouts[] = {
1019*8975f5c5SAndroid Build Coastguard Worker GL_LAYOUT_TRANSFER_SRC_EXT,
1020*8975f5c5SAndroid Build Coastguard Worker };
1021*8975f5c5SAndroid Build Coastguard Worker constexpr uint32_t textureDstLayoutsCount = std::extent<decltype(textureSrcLayouts)>();
1022*8975f5c5SAndroid Build Coastguard Worker static_assert(textureBarriersCount == textureDstLayoutsCount,
1023*8975f5c5SAndroid Build Coastguard Worker "barrierTextures and textureDstLayouts must be the same length");
1024*8975f5c5SAndroid Build Coastguard Worker glSignalSemaphoreEXT(glReleaseSemaphore, 0, nullptr, textureBarriersCount, barrierTextures,
1025*8975f5c5SAndroid Build Coastguard Worker textureDstLayouts);
1026*8975f5c5SAndroid Build Coastguard Worker
1027*8975f5c5SAndroid Build Coastguard Worker helper.waitSemaphoreAndAcquireImage(image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
1028*8975f5c5SAndroid Build Coastguard Worker VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
1029*8975f5c5SAndroid Build Coastguard Worker vkReleaseSemaphore);
1030*8975f5c5SAndroid Build Coastguard Worker
1031*8975f5c5SAndroid Build Coastguard Worker uint8_t pixels[4];
1032*8975f5c5SAndroid Build Coastguard Worker VkOffset3D offset = {};
1033*8975f5c5SAndroid Build Coastguard Worker helper.readPixels(image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, format, offset, extent,
1034*8975f5c5SAndroid Build Coastguard Worker pixels, sizeof(pixels));
1035*8975f5c5SAndroid Build Coastguard Worker
1036*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0xFF, pixels[0]);
1037*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0x00, pixels[1]);
1038*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0x00, pixels[2]);
1039*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0xFF, pixels[3]);
1040*8975f5c5SAndroid Build Coastguard Worker }
1041*8975f5c5SAndroid Build Coastguard Worker
1042*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
1043*8975f5c5SAndroid Build Coastguard Worker
1044*8975f5c5SAndroid Build Coastguard Worker vkDeviceWaitIdle(helper.getDevice());
1045*8975f5c5SAndroid Build Coastguard Worker vkDestroyImage(helper.getDevice(), image, nullptr);
1046*8975f5c5SAndroid Build Coastguard Worker vkDestroySemaphore(helper.getDevice(), vkAcquireSemaphore, nullptr);
1047*8975f5c5SAndroid Build Coastguard Worker vkDestroySemaphore(helper.getDevice(), vkReleaseSemaphore, nullptr);
1048*8975f5c5SAndroid Build Coastguard Worker vkFreeMemory(helper.getDevice(), deviceMemory, nullptr);
1049*8975f5c5SAndroid Build Coastguard Worker }
1050*8975f5c5SAndroid Build Coastguard Worker
1051*8975f5c5SAndroid Build Coastguard Worker // Test drawing to RGBA8 texture in opaque fd with acquire/release.
TEST_P(VulkanExternalImageTest,ShouldDrawOpaqueFdWithSemaphores)1052*8975f5c5SAndroid Build Coastguard Worker TEST_P(VulkanExternalImageTest, ShouldDrawOpaqueFdWithSemaphores)
1053*8975f5c5SAndroid Build Coastguard Worker {
1054*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_memory_object_fd"));
1055*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_semaphore_fd"));
1056*8975f5c5SAndroid Build Coastguard Worker
1057*8975f5c5SAndroid Build Coastguard Worker // http://issuetracker.google.com/173004081
1058*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(IsVulkan() && IsIntel() && IsLinux() &&
1059*8975f5c5SAndroid Build Coastguard Worker getEGLWindow()->isFeatureEnabled(Feature::AsyncCommandQueue));
1060*8975f5c5SAndroid Build Coastguard Worker // http://anglebug.com/42263923
1061*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(IsLinux() && IsAMD() && IsDesktopOpenGL());
1062*8975f5c5SAndroid Build Coastguard Worker
1063*8975f5c5SAndroid Build Coastguard Worker runShouldDrawTest<OpaqueFdTraits>(isSwiftshader(), enableDebugLayers());
1064*8975f5c5SAndroid Build Coastguard Worker }
1065*8975f5c5SAndroid Build Coastguard Worker
1066*8975f5c5SAndroid Build Coastguard Worker // Test drawing to RGBA8 texture in zircon vmo with acquire/release multiple times.
TEST_P(VulkanExternalImageTest,ShouldDrawZirconVmoWithSemaphores)1067*8975f5c5SAndroid Build Coastguard Worker TEST_P(VulkanExternalImageTest, ShouldDrawZirconVmoWithSemaphores)
1068*8975f5c5SAndroid Build Coastguard Worker {
1069*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_ANGLE_memory_object_fuchsia"));
1070*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_ANGLE_semaphore_fuchsia"));
1071*8975f5c5SAndroid Build Coastguard Worker runShouldDrawTest<FuchsiaTraits>(isSwiftshader(), enableDebugLayers());
1072*8975f5c5SAndroid Build Coastguard Worker }
1073*8975f5c5SAndroid Build Coastguard Worker
1074*8975f5c5SAndroid Build Coastguard Worker template <typename Traits>
runWaitSemaphoresRetainsContentTest(bool isSwiftshader,bool enableDebugLayers)1075*8975f5c5SAndroid Build Coastguard Worker void VulkanExternalImageTest::runWaitSemaphoresRetainsContentTest(bool isSwiftshader,
1076*8975f5c5SAndroid Build Coastguard Worker bool enableDebugLayers)
1077*8975f5c5SAndroid Build Coastguard Worker {
1078*8975f5c5SAndroid Build Coastguard Worker ASSERT(EnsureGLExtensionEnabled(Traits::MemoryObjectExtension()));
1079*8975f5c5SAndroid Build Coastguard Worker ASSERT(EnsureGLExtensionEnabled(Traits::SemaphoreExtension()));
1080*8975f5c5SAndroid Build Coastguard Worker
1081*8975f5c5SAndroid Build Coastguard Worker VulkanHelper helper;
1082*8975f5c5SAndroid Build Coastguard Worker helper.initialize(isSwiftshader, enableDebugLayers);
1083*8975f5c5SAndroid Build Coastguard Worker
1084*8975f5c5SAndroid Build Coastguard Worker VkFormat format = VK_FORMAT_R8G8B8A8_UNORM;
1085*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!Traits::CanCreateImage(helper, format, VK_IMAGE_TYPE_2D,
1086*8975f5c5SAndroid Build Coastguard Worker VK_IMAGE_TILING_OPTIMAL, kDefaultImageCreateFlags,
1087*8975f5c5SAndroid Build Coastguard Worker kDefaultImageUsageFlags));
1088*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!Traits::CanCreateSemaphore(helper));
1089*8975f5c5SAndroid Build Coastguard Worker
1090*8975f5c5SAndroid Build Coastguard Worker VkSemaphore vkAcquireSemaphore = VK_NULL_HANDLE;
1091*8975f5c5SAndroid Build Coastguard Worker VkResult result = Traits::CreateSemaphore(&helper, &vkAcquireSemaphore);
1092*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(result, VK_SUCCESS);
1093*8975f5c5SAndroid Build Coastguard Worker EXPECT_TRUE(vkAcquireSemaphore != VK_NULL_HANDLE);
1094*8975f5c5SAndroid Build Coastguard Worker
1095*8975f5c5SAndroid Build Coastguard Worker VkSemaphore vkReleaseSemaphore = VK_NULL_HANDLE;
1096*8975f5c5SAndroid Build Coastguard Worker result = Traits::CreateSemaphore(&helper, &vkReleaseSemaphore);
1097*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(result, VK_SUCCESS);
1098*8975f5c5SAndroid Build Coastguard Worker EXPECT_TRUE(vkReleaseSemaphore != VK_NULL_HANDLE);
1099*8975f5c5SAndroid Build Coastguard Worker
1100*8975f5c5SAndroid Build Coastguard Worker typename Traits::Handle acquireSemaphoreHandle = Traits::InvalidHandle();
1101*8975f5c5SAndroid Build Coastguard Worker result = Traits::ExportSemaphore(&helper, vkAcquireSemaphore, &acquireSemaphoreHandle);
1102*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(result, VK_SUCCESS);
1103*8975f5c5SAndroid Build Coastguard Worker EXPECT_NE(acquireSemaphoreHandle, Traits::InvalidHandle());
1104*8975f5c5SAndroid Build Coastguard Worker
1105*8975f5c5SAndroid Build Coastguard Worker typename Traits::Handle releaseSemaphoreHandle = Traits::InvalidHandle();
1106*8975f5c5SAndroid Build Coastguard Worker result = Traits::ExportSemaphore(&helper, vkReleaseSemaphore, &releaseSemaphoreHandle);
1107*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(result, VK_SUCCESS);
1108*8975f5c5SAndroid Build Coastguard Worker EXPECT_NE(releaseSemaphoreHandle, Traits::InvalidHandle());
1109*8975f5c5SAndroid Build Coastguard Worker
1110*8975f5c5SAndroid Build Coastguard Worker VkImage image = VK_NULL_HANDLE;
1111*8975f5c5SAndroid Build Coastguard Worker VkDeviceMemory deviceMemory = VK_NULL_HANDLE;
1112*8975f5c5SAndroid Build Coastguard Worker VkDeviceSize deviceMemorySize = 0;
1113*8975f5c5SAndroid Build Coastguard Worker
1114*8975f5c5SAndroid Build Coastguard Worker VkExtent3D extent = {kWidth, kHeight, 1};
1115*8975f5c5SAndroid Build Coastguard Worker result =
1116*8975f5c5SAndroid Build Coastguard Worker Traits::CreateImage2D(&helper, format, kDefaultImageCreateFlags, kDefaultImageUsageFlags,
1117*8975f5c5SAndroid Build Coastguard Worker nullptr, extent, &image, &deviceMemory, &deviceMemorySize);
1118*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(result, VK_SUCCESS);
1119*8975f5c5SAndroid Build Coastguard Worker
1120*8975f5c5SAndroid Build Coastguard Worker typename Traits::Handle memoryHandle = Traits::InvalidHandle();
1121*8975f5c5SAndroid Build Coastguard Worker result = Traits::ExportMemory(&helper, deviceMemory, &memoryHandle);
1122*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(result, VK_SUCCESS);
1123*8975f5c5SAndroid Build Coastguard Worker EXPECT_NE(memoryHandle, Traits::InvalidHandle());
1124*8975f5c5SAndroid Build Coastguard Worker
1125*8975f5c5SAndroid Build Coastguard Worker {
1126*8975f5c5SAndroid Build Coastguard Worker GLMemoryObject memoryObject;
1127*8975f5c5SAndroid Build Coastguard Worker GLint dedicatedMemory = GL_TRUE;
1128*8975f5c5SAndroid Build Coastguard Worker glMemoryObjectParameterivEXT(memoryObject, GL_DEDICATED_MEMORY_OBJECT_EXT,
1129*8975f5c5SAndroid Build Coastguard Worker &dedicatedMemory);
1130*8975f5c5SAndroid Build Coastguard Worker Traits::ImportMemory(memoryObject, deviceMemorySize, memoryHandle);
1131*8975f5c5SAndroid Build Coastguard Worker
1132*8975f5c5SAndroid Build Coastguard Worker GLTexture texture;
1133*8975f5c5SAndroid Build Coastguard Worker glBindTexture(GL_TEXTURE_2D, texture);
1134*8975f5c5SAndroid Build Coastguard Worker glTexStorageMem2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8, kWidth, kHeight, memoryObject, 0);
1135*8975f5c5SAndroid Build Coastguard Worker
1136*8975f5c5SAndroid Build Coastguard Worker GLSemaphore glAcquireSemaphore;
1137*8975f5c5SAndroid Build Coastguard Worker Traits::ImportSemaphore(glAcquireSemaphore, acquireSemaphoreHandle);
1138*8975f5c5SAndroid Build Coastguard Worker
1139*8975f5c5SAndroid Build Coastguard Worker // Transfer ownership to GL.
1140*8975f5c5SAndroid Build Coastguard Worker helper.releaseImageAndSignalSemaphore(image, VK_IMAGE_LAYOUT_UNDEFINED,
1141*8975f5c5SAndroid Build Coastguard Worker VK_IMAGE_LAYOUT_GENERAL, vkAcquireSemaphore);
1142*8975f5c5SAndroid Build Coastguard Worker
1143*8975f5c5SAndroid Build Coastguard Worker const GLuint barrierTextures[] = {
1144*8975f5c5SAndroid Build Coastguard Worker texture,
1145*8975f5c5SAndroid Build Coastguard Worker };
1146*8975f5c5SAndroid Build Coastguard Worker constexpr uint32_t textureBarriersCount = std::extent<decltype(barrierTextures)>();
1147*8975f5c5SAndroid Build Coastguard Worker const GLenum textureSrcLayouts[] = {
1148*8975f5c5SAndroid Build Coastguard Worker GL_LAYOUT_GENERAL_EXT,
1149*8975f5c5SAndroid Build Coastguard Worker };
1150*8975f5c5SAndroid Build Coastguard Worker constexpr uint32_t textureSrcLayoutsCount = std::extent<decltype(textureSrcLayouts)>();
1151*8975f5c5SAndroid Build Coastguard Worker static_assert(textureBarriersCount == textureSrcLayoutsCount,
1152*8975f5c5SAndroid Build Coastguard Worker "barrierTextures and textureSrcLayouts must be the same length");
1153*8975f5c5SAndroid Build Coastguard Worker glWaitSemaphoreEXT(glAcquireSemaphore, 0, nullptr, textureBarriersCount, barrierTextures,
1154*8975f5c5SAndroid Build Coastguard Worker textureSrcLayouts);
1155*8975f5c5SAndroid Build Coastguard Worker
1156*8975f5c5SAndroid Build Coastguard Worker GLFramebuffer framebuffer;
1157*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
1158*8975f5c5SAndroid Build Coastguard Worker glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
1159*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
1160*8975f5c5SAndroid Build Coastguard Worker
1161*8975f5c5SAndroid Build Coastguard Worker // Make the texture red.
1162*8975f5c5SAndroid Build Coastguard Worker ANGLE_GL_PROGRAM(drawRed, essl1_shaders::vs::Simple(), essl1_shaders::fs::Red());
1163*8975f5c5SAndroid Build Coastguard Worker glViewport(0, 0, kWidth, kHeight);
1164*8975f5c5SAndroid Build Coastguard Worker drawQuad(drawRed, essl1_shaders::PositionAttrib(), 0.0f);
1165*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
1166*8975f5c5SAndroid Build Coastguard Worker
1167*8975f5c5SAndroid Build Coastguard Worker // Transfer ownership back to test.
1168*8975f5c5SAndroid Build Coastguard Worker GLSemaphore glReleaseSemaphore;
1169*8975f5c5SAndroid Build Coastguard Worker Traits::ImportSemaphore(glReleaseSemaphore, releaseSemaphoreHandle);
1170*8975f5c5SAndroid Build Coastguard Worker
1171*8975f5c5SAndroid Build Coastguard Worker const GLenum textureDstLayouts[] = {
1172*8975f5c5SAndroid Build Coastguard Worker GL_LAYOUT_TRANSFER_SRC_EXT,
1173*8975f5c5SAndroid Build Coastguard Worker };
1174*8975f5c5SAndroid Build Coastguard Worker constexpr uint32_t textureDstLayoutsCount = std::extent<decltype(textureSrcLayouts)>();
1175*8975f5c5SAndroid Build Coastguard Worker static_assert(textureBarriersCount == textureDstLayoutsCount,
1176*8975f5c5SAndroid Build Coastguard Worker "barrierTextures and textureDstLayouts must be the same length");
1177*8975f5c5SAndroid Build Coastguard Worker glSignalSemaphoreEXT(glReleaseSemaphore, 0, nullptr, textureBarriersCount, barrierTextures,
1178*8975f5c5SAndroid Build Coastguard Worker textureDstLayouts);
1179*8975f5c5SAndroid Build Coastguard Worker
1180*8975f5c5SAndroid Build Coastguard Worker helper.waitSemaphoreAndAcquireImage(image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
1181*8975f5c5SAndroid Build Coastguard Worker VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
1182*8975f5c5SAndroid Build Coastguard Worker vkReleaseSemaphore);
1183*8975f5c5SAndroid Build Coastguard Worker
1184*8975f5c5SAndroid Build Coastguard Worker // Transfer ownership to GL again, and make sure the contents are preserved.
1185*8975f5c5SAndroid Build Coastguard Worker helper.releaseImageAndSignalSemaphore(image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
1186*8975f5c5SAndroid Build Coastguard Worker VK_IMAGE_LAYOUT_GENERAL, vkAcquireSemaphore);
1187*8975f5c5SAndroid Build Coastguard Worker glWaitSemaphoreEXT(glAcquireSemaphore, 0, nullptr, textureBarriersCount, barrierTextures,
1188*8975f5c5SAndroid Build Coastguard Worker textureSrcLayouts);
1189*8975f5c5SAndroid Build Coastguard Worker
1190*8975f5c5SAndroid Build Coastguard Worker // Blend green
1191*8975f5c5SAndroid Build Coastguard Worker ANGLE_GL_PROGRAM(drawGreen, essl1_shaders::vs::Simple(), essl1_shaders::fs::Green());
1192*8975f5c5SAndroid Build Coastguard Worker glEnable(GL_BLEND);
1193*8975f5c5SAndroid Build Coastguard Worker glBlendFunc(GL_ONE, GL_ONE);
1194*8975f5c5SAndroid Build Coastguard Worker drawQuad(drawGreen, essl1_shaders::PositionAttrib(), 0.0f);
1195*8975f5c5SAndroid Build Coastguard Worker
1196*8975f5c5SAndroid Build Coastguard Worker // Transfer ownership back to test
1197*8975f5c5SAndroid Build Coastguard Worker glSignalSemaphoreEXT(glReleaseSemaphore, 0, nullptr, textureBarriersCount, barrierTextures,
1198*8975f5c5SAndroid Build Coastguard Worker textureDstLayouts);
1199*8975f5c5SAndroid Build Coastguard Worker helper.waitSemaphoreAndAcquireImage(image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
1200*8975f5c5SAndroid Build Coastguard Worker VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
1201*8975f5c5SAndroid Build Coastguard Worker vkReleaseSemaphore);
1202*8975f5c5SAndroid Build Coastguard Worker
1203*8975f5c5SAndroid Build Coastguard Worker uint8_t pixels[4 * kWidth * kHeight];
1204*8975f5c5SAndroid Build Coastguard Worker VkOffset3D offset = {};
1205*8975f5c5SAndroid Build Coastguard Worker helper.readPixels(image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, format, offset, extent,
1206*8975f5c5SAndroid Build Coastguard Worker pixels, sizeof(pixels));
1207*8975f5c5SAndroid Build Coastguard Worker
1208*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0xFF, pixels[0]);
1209*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0xFF, pixels[1]);
1210*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0x00, pixels[2]);
1211*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0xFF, pixels[3]);
1212*8975f5c5SAndroid Build Coastguard Worker
1213*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0xFF, pixels[4]);
1214*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0xFF, pixels[5]);
1215*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0x00, pixels[6]);
1216*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(0xFF, pixels[7]);
1217*8975f5c5SAndroid Build Coastguard Worker }
1218*8975f5c5SAndroid Build Coastguard Worker
1219*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
1220*8975f5c5SAndroid Build Coastguard Worker
1221*8975f5c5SAndroid Build Coastguard Worker vkDeviceWaitIdle(helper.getDevice());
1222*8975f5c5SAndroid Build Coastguard Worker vkDestroyImage(helper.getDevice(), image, nullptr);
1223*8975f5c5SAndroid Build Coastguard Worker vkDestroySemaphore(helper.getDevice(), vkAcquireSemaphore, nullptr);
1224*8975f5c5SAndroid Build Coastguard Worker vkDestroySemaphore(helper.getDevice(), vkReleaseSemaphore, nullptr);
1225*8975f5c5SAndroid Build Coastguard Worker vkFreeMemory(helper.getDevice(), deviceMemory, nullptr);
1226*8975f5c5SAndroid Build Coastguard Worker }
1227*8975f5c5SAndroid Build Coastguard Worker
1228*8975f5c5SAndroid Build Coastguard Worker // Test drawing to RGBA8 texture in opaque fd with acquire/release multiple times.
TEST_P(VulkanExternalImageTest,WaitSemaphoresRetainsContentOpaqueFd)1229*8975f5c5SAndroid Build Coastguard Worker TEST_P(VulkanExternalImageTest, WaitSemaphoresRetainsContentOpaqueFd)
1230*8975f5c5SAndroid Build Coastguard Worker {
1231*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_memory_object_fd"));
1232*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_semaphore_fd"));
1233*8975f5c5SAndroid Build Coastguard Worker
1234*8975f5c5SAndroid Build Coastguard Worker // http://issuetracker.google.com/173004081
1235*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(IsVulkan() && IsIntel() && IsLinux() &&
1236*8975f5c5SAndroid Build Coastguard Worker getEGLWindow()->isFeatureEnabled(Feature::AsyncCommandQueue));
1237*8975f5c5SAndroid Build Coastguard Worker // http://anglebug.com/42263923
1238*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(IsLinux() && IsAMD() && IsDesktopOpenGL());
1239*8975f5c5SAndroid Build Coastguard Worker
1240*8975f5c5SAndroid Build Coastguard Worker runWaitSemaphoresRetainsContentTest<OpaqueFdTraits>(isSwiftshader(), enableDebugLayers());
1241*8975f5c5SAndroid Build Coastguard Worker }
1242*8975f5c5SAndroid Build Coastguard Worker
1243*8975f5c5SAndroid Build Coastguard Worker // Test drawing to RGBA8 texture in zircon vmo with acquire/release multiple times.
TEST_P(VulkanExternalImageTest,WaitSemaphoresRetainsContentZirconVmo)1244*8975f5c5SAndroid Build Coastguard Worker TEST_P(VulkanExternalImageTest, WaitSemaphoresRetainsContentZirconVmo)
1245*8975f5c5SAndroid Build Coastguard Worker {
1246*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_ANGLE_memory_object_fuchsia"));
1247*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_ANGLE_semaphore_fuchsia"));
1248*8975f5c5SAndroid Build Coastguard Worker runWaitSemaphoresRetainsContentTest<FuchsiaTraits>(isSwiftshader(), enableDebugLayers());
1249*8975f5c5SAndroid Build Coastguard Worker }
1250*8975f5c5SAndroid Build Coastguard Worker
1251*8975f5c5SAndroid Build Coastguard Worker // Support for Zircon handle types is mandatory on Fuchsia.
TEST_P(VulkanExternalImageTest,ShouldSupportExternalHandlesFuchsia)1252*8975f5c5SAndroid Build Coastguard Worker TEST_P(VulkanExternalImageTest, ShouldSupportExternalHandlesFuchsia)
1253*8975f5c5SAndroid Build Coastguard Worker {
1254*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!IsFuchsia());
1255*8975f5c5SAndroid Build Coastguard Worker EXPECT_TRUE(EnsureGLExtensionEnabled("GL_ANGLE_memory_object_fuchsia"));
1256*8975f5c5SAndroid Build Coastguard Worker EXPECT_TRUE(EnsureGLExtensionEnabled("GL_ANGLE_semaphore_fuchsia"));
1257*8975f5c5SAndroid Build Coastguard Worker VulkanHelper helper;
1258*8975f5c5SAndroid Build Coastguard Worker helper.initialize(isSwiftshader(), enableDebugLayers());
1259*8975f5c5SAndroid Build Coastguard Worker EXPECT_TRUE(helper.canCreateSemaphoreZirconEvent());
1260*8975f5c5SAndroid Build Coastguard Worker EXPECT_TRUE(helper.canCreateImageZirconVmo(VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D,
1261*8975f5c5SAndroid Build Coastguard Worker VK_IMAGE_TILING_OPTIMAL, kDefaultImageCreateFlags,
1262*8975f5c5SAndroid Build Coastguard Worker kDefaultImageUsageFlags));
1263*8975f5c5SAndroid Build Coastguard Worker }
1264*8975f5c5SAndroid Build Coastguard Worker
1265*8975f5c5SAndroid Build Coastguard Worker template <typename Traits>
RunPreInitializedOnGLImportTest(bool useMemoryObjectFlags,VkImageTiling tiling,bool isSwiftshader,bool enableDebugLayers)1266*8975f5c5SAndroid Build Coastguard Worker void RunPreInitializedOnGLImportTest(bool useMemoryObjectFlags,
1267*8975f5c5SAndroid Build Coastguard Worker VkImageTiling tiling,
1268*8975f5c5SAndroid Build Coastguard Worker bool isSwiftshader,
1269*8975f5c5SAndroid Build Coastguard Worker bool enableDebugLayers)
1270*8975f5c5SAndroid Build Coastguard Worker {
1271*8975f5c5SAndroid Build Coastguard Worker ASSERT(EnsureGLExtensionEnabled(Traits::MemoryObjectExtension()));
1272*8975f5c5SAndroid Build Coastguard Worker ASSERT(EnsureGLExtensionEnabled(Traits::SemaphoreExtension()));
1273*8975f5c5SAndroid Build Coastguard Worker
1274*8975f5c5SAndroid Build Coastguard Worker VkImageCreateFlags createFlags = kDefaultImageCreateFlags;
1275*8975f5c5SAndroid Build Coastguard Worker VkImageUsageFlags usageFlags = kDefaultImageUsageFlags;
1276*8975f5c5SAndroid Build Coastguard Worker
1277*8975f5c5SAndroid Build Coastguard Worker AdjustCreateFlags(useMemoryObjectFlags, &createFlags);
1278*8975f5c5SAndroid Build Coastguard Worker
1279*8975f5c5SAndroid Build Coastguard Worker VulkanHelper helper;
1280*8975f5c5SAndroid Build Coastguard Worker helper.initialize(isSwiftshader, enableDebugLayers);
1281*8975f5c5SAndroid Build Coastguard Worker
1282*8975f5c5SAndroid Build Coastguard Worker VkFormat format = VK_FORMAT_R8G8B8A8_UNORM;
1283*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(
1284*8975f5c5SAndroid Build Coastguard Worker !Traits::CanCreateImage(helper, format, VK_IMAGE_TYPE_2D, tiling, createFlags, usageFlags));
1285*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!Traits::CanCreateSemaphore(helper));
1286*8975f5c5SAndroid Build Coastguard Worker
1287*8975f5c5SAndroid Build Coastguard Worker VkSemaphore vkAcquireSemaphore = VK_NULL_HANDLE;
1288*8975f5c5SAndroid Build Coastguard Worker VkResult result = Traits::CreateSemaphore(&helper, &vkAcquireSemaphore);
1289*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(result, VK_SUCCESS);
1290*8975f5c5SAndroid Build Coastguard Worker EXPECT_TRUE(vkAcquireSemaphore != VK_NULL_HANDLE);
1291*8975f5c5SAndroid Build Coastguard Worker
1292*8975f5c5SAndroid Build Coastguard Worker VkSemaphore vkReleaseSemaphore = VK_NULL_HANDLE;
1293*8975f5c5SAndroid Build Coastguard Worker result = Traits::CreateSemaphore(&helper, &vkReleaseSemaphore);
1294*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(result, VK_SUCCESS);
1295*8975f5c5SAndroid Build Coastguard Worker EXPECT_TRUE(vkReleaseSemaphore != VK_NULL_HANDLE);
1296*8975f5c5SAndroid Build Coastguard Worker
1297*8975f5c5SAndroid Build Coastguard Worker typename Traits::Handle acquireSemaphoreHandle = Traits::InvalidHandle();
1298*8975f5c5SAndroid Build Coastguard Worker result = Traits::ExportSemaphore(&helper, vkAcquireSemaphore, &acquireSemaphoreHandle);
1299*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(result, VK_SUCCESS);
1300*8975f5c5SAndroid Build Coastguard Worker EXPECT_NE(acquireSemaphoreHandle, Traits::InvalidHandle());
1301*8975f5c5SAndroid Build Coastguard Worker
1302*8975f5c5SAndroid Build Coastguard Worker typename Traits::Handle releaseSemaphoreHandle = Traits::InvalidHandle();
1303*8975f5c5SAndroid Build Coastguard Worker result = Traits::ExportSemaphore(&helper, vkReleaseSemaphore, &releaseSemaphoreHandle);
1304*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(result, VK_SUCCESS);
1305*8975f5c5SAndroid Build Coastguard Worker EXPECT_NE(releaseSemaphoreHandle, Traits::InvalidHandle());
1306*8975f5c5SAndroid Build Coastguard Worker
1307*8975f5c5SAndroid Build Coastguard Worker VkImage image = VK_NULL_HANDLE;
1308*8975f5c5SAndroid Build Coastguard Worker VkDeviceMemory deviceMemory = VK_NULL_HANDLE;
1309*8975f5c5SAndroid Build Coastguard Worker VkDeviceSize deviceMemorySize = 0;
1310*8975f5c5SAndroid Build Coastguard Worker
1311*8975f5c5SAndroid Build Coastguard Worker VkExtent3D extent = {kWidth, kHeight, 1};
1312*8975f5c5SAndroid Build Coastguard Worker result = Traits::CreateImage2D(&helper, format, createFlags, usageFlags, nullptr, extent,
1313*8975f5c5SAndroid Build Coastguard Worker &image, &deviceMemory, &deviceMemorySize);
1314*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(result, VK_SUCCESS);
1315*8975f5c5SAndroid Build Coastguard Worker
1316*8975f5c5SAndroid Build Coastguard Worker // Initialize a pixel in the image
1317*8975f5c5SAndroid Build Coastguard Worker constexpr uint32_t kPixel = 0x12345678;
1318*8975f5c5SAndroid Build Coastguard Worker helper.writePixels(image, VK_IMAGE_LAYOUT_UNDEFINED, VK_FORMAT_R8G8B8A8_UNORM, {0, 0, 0},
1319*8975f5c5SAndroid Build Coastguard Worker {1, 1, 1}, static_cast<const void *>(&kPixel), sizeof(kPixel));
1320*8975f5c5SAndroid Build Coastguard Worker
1321*8975f5c5SAndroid Build Coastguard Worker typename Traits::Handle memoryHandle = Traits::InvalidHandle();
1322*8975f5c5SAndroid Build Coastguard Worker result = Traits::ExportMemory(&helper, deviceMemory, &memoryHandle);
1323*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(result, VK_SUCCESS);
1324*8975f5c5SAndroid Build Coastguard Worker EXPECT_NE(memoryHandle, Traits::InvalidHandle());
1325*8975f5c5SAndroid Build Coastguard Worker
1326*8975f5c5SAndroid Build Coastguard Worker {
1327*8975f5c5SAndroid Build Coastguard Worker GLMemoryObject memoryObject;
1328*8975f5c5SAndroid Build Coastguard Worker GLint dedicatedMemory = GL_TRUE;
1329*8975f5c5SAndroid Build Coastguard Worker glMemoryObjectParameterivEXT(memoryObject, GL_DEDICATED_MEMORY_OBJECT_EXT,
1330*8975f5c5SAndroid Build Coastguard Worker &dedicatedMemory);
1331*8975f5c5SAndroid Build Coastguard Worker Traits::ImportMemory(memoryObject, deviceMemorySize, memoryHandle);
1332*8975f5c5SAndroid Build Coastguard Worker
1333*8975f5c5SAndroid Build Coastguard Worker GLTexture texture;
1334*8975f5c5SAndroid Build Coastguard Worker glBindTexture(GL_TEXTURE_2D, texture);
1335*8975f5c5SAndroid Build Coastguard Worker glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1336*8975f5c5SAndroid Build Coastguard Worker glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1337*8975f5c5SAndroid Build Coastguard Worker glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1338*8975f5c5SAndroid Build Coastguard Worker glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1339*8975f5c5SAndroid Build Coastguard Worker if (tiling == VK_IMAGE_TILING_LINEAR)
1340*8975f5c5SAndroid Build Coastguard Worker {
1341*8975f5c5SAndroid Build Coastguard Worker glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_TILING_EXT, GL_LINEAR_TILING_EXT);
1342*8975f5c5SAndroid Build Coastguard Worker }
1343*8975f5c5SAndroid Build Coastguard Worker if (useMemoryObjectFlags)
1344*8975f5c5SAndroid Build Coastguard Worker {
1345*8975f5c5SAndroid Build Coastguard Worker glTexStorageMemFlags2DANGLE(GL_TEXTURE_2D, 1, GL_RGBA8, kWidth, kHeight, memoryObject,
1346*8975f5c5SAndroid Build Coastguard Worker 0, createFlags, usageFlags, nullptr);
1347*8975f5c5SAndroid Build Coastguard Worker }
1348*8975f5c5SAndroid Build Coastguard Worker else
1349*8975f5c5SAndroid Build Coastguard Worker {
1350*8975f5c5SAndroid Build Coastguard Worker glTexStorageMem2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8, kWidth, kHeight, memoryObject, 0);
1351*8975f5c5SAndroid Build Coastguard Worker }
1352*8975f5c5SAndroid Build Coastguard Worker
1353*8975f5c5SAndroid Build Coastguard Worker GLSemaphore glAcquireSemaphore;
1354*8975f5c5SAndroid Build Coastguard Worker Traits::ImportSemaphore(glAcquireSemaphore, acquireSemaphoreHandle);
1355*8975f5c5SAndroid Build Coastguard Worker
1356*8975f5c5SAndroid Build Coastguard Worker // Note: writePixels leaves the image in TRANSFER_DST_OPTIMAL layout.
1357*8975f5c5SAndroid Build Coastguard Worker helper.releaseImageAndSignalSemaphore(image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
1358*8975f5c5SAndroid Build Coastguard Worker VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
1359*8975f5c5SAndroid Build Coastguard Worker vkAcquireSemaphore);
1360*8975f5c5SAndroid Build Coastguard Worker
1361*8975f5c5SAndroid Build Coastguard Worker const GLuint barrierTexture = texture;
1362*8975f5c5SAndroid Build Coastguard Worker const GLenum textureSrcLayout = GL_LAYOUT_COLOR_ATTACHMENT_EXT;
1363*8975f5c5SAndroid Build Coastguard Worker glWaitSemaphoreEXT(glAcquireSemaphore, 0, nullptr, 1, &barrierTexture, &textureSrcLayout);
1364*8975f5c5SAndroid Build Coastguard Worker
1365*8975f5c5SAndroid Build Coastguard Worker GLFramebuffer framebuffer;
1366*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
1367*8975f5c5SAndroid Build Coastguard Worker glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
1368*8975f5c5SAndroid Build Coastguard Worker
1369*8975f5c5SAndroid Build Coastguard Worker // Readback the initialized pixel, ensure it contains the value written to it.
1370*8975f5c5SAndroid Build Coastguard Worker uint32_t pixel = 0u;
1371*8975f5c5SAndroid Build Coastguard Worker glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixel);
1372*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(pixel, kPixel);
1373*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
1374*8975f5c5SAndroid Build Coastguard Worker
1375*8975f5c5SAndroid Build Coastguard Worker GLSemaphore glReleaseSemaphore;
1376*8975f5c5SAndroid Build Coastguard Worker Traits::ImportSemaphore(glReleaseSemaphore, releaseSemaphoreHandle);
1377*8975f5c5SAndroid Build Coastguard Worker
1378*8975f5c5SAndroid Build Coastguard Worker const GLenum textureDstLayout = GL_LAYOUT_TRANSFER_SRC_EXT;
1379*8975f5c5SAndroid Build Coastguard Worker glSignalSemaphoreEXT(glReleaseSemaphore, 0, nullptr, 1, &barrierTexture, &textureDstLayout);
1380*8975f5c5SAndroid Build Coastguard Worker
1381*8975f5c5SAndroid Build Coastguard Worker helper.waitSemaphoreAndAcquireImage(image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
1382*8975f5c5SAndroid Build Coastguard Worker VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
1383*8975f5c5SAndroid Build Coastguard Worker vkReleaseSemaphore);
1384*8975f5c5SAndroid Build Coastguard Worker }
1385*8975f5c5SAndroid Build Coastguard Worker
1386*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
1387*8975f5c5SAndroid Build Coastguard Worker
1388*8975f5c5SAndroid Build Coastguard Worker vkDeviceWaitIdle(helper.getDevice());
1389*8975f5c5SAndroid Build Coastguard Worker vkDestroyImage(helper.getDevice(), image, nullptr);
1390*8975f5c5SAndroid Build Coastguard Worker vkDestroySemaphore(helper.getDevice(), vkAcquireSemaphore, nullptr);
1391*8975f5c5SAndroid Build Coastguard Worker vkDestroySemaphore(helper.getDevice(), vkReleaseSemaphore, nullptr);
1392*8975f5c5SAndroid Build Coastguard Worker vkFreeMemory(helper.getDevice(), deviceMemory, nullptr);
1393*8975f5c5SAndroid Build Coastguard Worker }
1394*8975f5c5SAndroid Build Coastguard Worker
1395*8975f5c5SAndroid Build Coastguard Worker // Test that texture storage created from VkImage memory can be considered pre-initialized in GL.
TEST_P(VulkanExternalImageTest,PreInitializedOnGLImport)1396*8975f5c5SAndroid Build Coastguard Worker TEST_P(VulkanExternalImageTest, PreInitializedOnGLImport)
1397*8975f5c5SAndroid Build Coastguard Worker {
1398*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_memory_object_fd"));
1399*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_semaphore_fd"));
1400*8975f5c5SAndroid Build Coastguard Worker
1401*8975f5c5SAndroid Build Coastguard Worker RunPreInitializedOnGLImportTest<OpaqueFdTraits>(false, VK_IMAGE_TILING_OPTIMAL, isSwiftshader(),
1402*8975f5c5SAndroid Build Coastguard Worker enableDebugLayers());
1403*8975f5c5SAndroid Build Coastguard Worker }
1404*8975f5c5SAndroid Build Coastguard Worker
1405*8975f5c5SAndroid Build Coastguard Worker // Test that texture storage created from VkImage memory can be considered pre-initialized in GL.
1406*8975f5c5SAndroid Build Coastguard Worker // Uses linear tiling.
TEST_P(VulkanExternalImageTest,PreInitializedOnGLImportLinear)1407*8975f5c5SAndroid Build Coastguard Worker TEST_P(VulkanExternalImageTest, PreInitializedOnGLImportLinear)
1408*8975f5c5SAndroid Build Coastguard Worker {
1409*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_memory_object_fd"));
1410*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_semaphore_fd"));
1411*8975f5c5SAndroid Build Coastguard Worker
1412*8975f5c5SAndroid Build Coastguard Worker RunPreInitializedOnGLImportTest<OpaqueFdTraits>(false, VK_IMAGE_TILING_LINEAR, isSwiftshader(),
1413*8975f5c5SAndroid Build Coastguard Worker enableDebugLayers());
1414*8975f5c5SAndroid Build Coastguard Worker }
1415*8975f5c5SAndroid Build Coastguard Worker
1416*8975f5c5SAndroid Build Coastguard Worker // Test that texture storage created from VkImage memory can be considered pre-initialized in GL,
1417*8975f5c5SAndroid Build Coastguard Worker // using GL_ANGLE_memory_object_flags.
TEST_P(VulkanExternalImageTest,PreInitializedOnGLImportWithFlags)1418*8975f5c5SAndroid Build Coastguard Worker TEST_P(VulkanExternalImageTest, PreInitializedOnGLImportWithFlags)
1419*8975f5c5SAndroid Build Coastguard Worker {
1420*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_memory_object_fd"));
1421*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_semaphore_fd"));
1422*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_ANGLE_memory_object_flags"));
1423*8975f5c5SAndroid Build Coastguard Worker
1424*8975f5c5SAndroid Build Coastguard Worker RunPreInitializedOnGLImportTest<OpaqueFdTraits>(true, VK_IMAGE_TILING_OPTIMAL, isSwiftshader(),
1425*8975f5c5SAndroid Build Coastguard Worker enableDebugLayers());
1426*8975f5c5SAndroid Build Coastguard Worker }
1427*8975f5c5SAndroid Build Coastguard Worker
1428*8975f5c5SAndroid Build Coastguard Worker // Test that texture storage created from VkImage memory can be considered pre-initialized in GL,
1429*8975f5c5SAndroid Build Coastguard Worker // using GL_ANGLE_memory_object_flags. Uses linear tiling.
TEST_P(VulkanExternalImageTest,PreInitializedOnGLImportLinearWithFlags)1430*8975f5c5SAndroid Build Coastguard Worker TEST_P(VulkanExternalImageTest, PreInitializedOnGLImportLinearWithFlags)
1431*8975f5c5SAndroid Build Coastguard Worker {
1432*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_memory_object_fd"));
1433*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_semaphore_fd"));
1434*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_ANGLE_memory_object_flags"));
1435*8975f5c5SAndroid Build Coastguard Worker
1436*8975f5c5SAndroid Build Coastguard Worker RunPreInitializedOnGLImportTest<OpaqueFdTraits>(true, VK_IMAGE_TILING_LINEAR, isSwiftshader(),
1437*8975f5c5SAndroid Build Coastguard Worker enableDebugLayers());
1438*8975f5c5SAndroid Build Coastguard Worker }
1439*8975f5c5SAndroid Build Coastguard Worker
1440*8975f5c5SAndroid Build Coastguard Worker template <typename Traits>
RunUninitializedOnGLImportTest(bool useMemoryObjectFlags,std::function<GLenum (GLuint)> useTexture,const uint32_t * expectInVulkan,bool isSwiftshader,bool enableDebugLayers)1441*8975f5c5SAndroid Build Coastguard Worker void RunUninitializedOnGLImportTest(bool useMemoryObjectFlags,
1442*8975f5c5SAndroid Build Coastguard Worker std::function<GLenum(GLuint)> useTexture,
1443*8975f5c5SAndroid Build Coastguard Worker const uint32_t *expectInVulkan,
1444*8975f5c5SAndroid Build Coastguard Worker bool isSwiftshader,
1445*8975f5c5SAndroid Build Coastguard Worker bool enableDebugLayers)
1446*8975f5c5SAndroid Build Coastguard Worker {
1447*8975f5c5SAndroid Build Coastguard Worker ASSERT(EnsureGLExtensionEnabled(Traits::MemoryObjectExtension()));
1448*8975f5c5SAndroid Build Coastguard Worker ASSERT(EnsureGLExtensionEnabled(Traits::SemaphoreExtension()));
1449*8975f5c5SAndroid Build Coastguard Worker
1450*8975f5c5SAndroid Build Coastguard Worker VkImageCreateFlags createFlags = kDefaultImageCreateFlags;
1451*8975f5c5SAndroid Build Coastguard Worker VkImageUsageFlags usageFlags = kDefaultImageUsageFlags;
1452*8975f5c5SAndroid Build Coastguard Worker
1453*8975f5c5SAndroid Build Coastguard Worker AdjustCreateFlags(useMemoryObjectFlags, &createFlags);
1454*8975f5c5SAndroid Build Coastguard Worker
1455*8975f5c5SAndroid Build Coastguard Worker VulkanHelper helper;
1456*8975f5c5SAndroid Build Coastguard Worker helper.initialize(isSwiftshader, enableDebugLayers);
1457*8975f5c5SAndroid Build Coastguard Worker
1458*8975f5c5SAndroid Build Coastguard Worker VkFormat format = VK_FORMAT_R8G8B8A8_UNORM;
1459*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!Traits::CanCreateImage(helper, format, VK_IMAGE_TYPE_2D,
1460*8975f5c5SAndroid Build Coastguard Worker VK_IMAGE_TILING_OPTIMAL, createFlags, usageFlags));
1461*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!Traits::CanCreateSemaphore(helper));
1462*8975f5c5SAndroid Build Coastguard Worker
1463*8975f5c5SAndroid Build Coastguard Worker VkSemaphore vkAcquireSemaphore = VK_NULL_HANDLE;
1464*8975f5c5SAndroid Build Coastguard Worker VkResult result = Traits::CreateSemaphore(&helper, &vkAcquireSemaphore);
1465*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(result, VK_SUCCESS);
1466*8975f5c5SAndroid Build Coastguard Worker EXPECT_TRUE(vkAcquireSemaphore != VK_NULL_HANDLE);
1467*8975f5c5SAndroid Build Coastguard Worker
1468*8975f5c5SAndroid Build Coastguard Worker VkSemaphore vkReleaseSemaphore = VK_NULL_HANDLE;
1469*8975f5c5SAndroid Build Coastguard Worker result = Traits::CreateSemaphore(&helper, &vkReleaseSemaphore);
1470*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(result, VK_SUCCESS);
1471*8975f5c5SAndroid Build Coastguard Worker EXPECT_TRUE(vkReleaseSemaphore != VK_NULL_HANDLE);
1472*8975f5c5SAndroid Build Coastguard Worker
1473*8975f5c5SAndroid Build Coastguard Worker typename Traits::Handle acquireSemaphoreHandle = Traits::InvalidHandle();
1474*8975f5c5SAndroid Build Coastguard Worker result = Traits::ExportSemaphore(&helper, vkAcquireSemaphore, &acquireSemaphoreHandle);
1475*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(result, VK_SUCCESS);
1476*8975f5c5SAndroid Build Coastguard Worker EXPECT_NE(acquireSemaphoreHandle, Traits::InvalidHandle());
1477*8975f5c5SAndroid Build Coastguard Worker
1478*8975f5c5SAndroid Build Coastguard Worker typename Traits::Handle releaseSemaphoreHandle = Traits::InvalidHandle();
1479*8975f5c5SAndroid Build Coastguard Worker result = Traits::ExportSemaphore(&helper, vkReleaseSemaphore, &releaseSemaphoreHandle);
1480*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(result, VK_SUCCESS);
1481*8975f5c5SAndroid Build Coastguard Worker EXPECT_NE(releaseSemaphoreHandle, Traits::InvalidHandle());
1482*8975f5c5SAndroid Build Coastguard Worker
1483*8975f5c5SAndroid Build Coastguard Worker VkImage image = VK_NULL_HANDLE;
1484*8975f5c5SAndroid Build Coastguard Worker VkDeviceMemory deviceMemory = VK_NULL_HANDLE;
1485*8975f5c5SAndroid Build Coastguard Worker VkDeviceSize deviceMemorySize = 0;
1486*8975f5c5SAndroid Build Coastguard Worker
1487*8975f5c5SAndroid Build Coastguard Worker VkExtent3D extent = {kWidth, kHeight, 1};
1488*8975f5c5SAndroid Build Coastguard Worker result = Traits::CreateImage2D(&helper, format, createFlags, usageFlags, nullptr, extent,
1489*8975f5c5SAndroid Build Coastguard Worker &image, &deviceMemory, &deviceMemorySize);
1490*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(result, VK_SUCCESS);
1491*8975f5c5SAndroid Build Coastguard Worker
1492*8975f5c5SAndroid Build Coastguard Worker typename Traits::Handle memoryHandle = Traits::InvalidHandle();
1493*8975f5c5SAndroid Build Coastguard Worker result = Traits::ExportMemory(&helper, deviceMemory, &memoryHandle);
1494*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(result, VK_SUCCESS);
1495*8975f5c5SAndroid Build Coastguard Worker EXPECT_NE(memoryHandle, Traits::InvalidHandle());
1496*8975f5c5SAndroid Build Coastguard Worker
1497*8975f5c5SAndroid Build Coastguard Worker {
1498*8975f5c5SAndroid Build Coastguard Worker GLMemoryObject memoryObject;
1499*8975f5c5SAndroid Build Coastguard Worker GLint dedicatedMemory = GL_TRUE;
1500*8975f5c5SAndroid Build Coastguard Worker glMemoryObjectParameterivEXT(memoryObject, GL_DEDICATED_MEMORY_OBJECT_EXT,
1501*8975f5c5SAndroid Build Coastguard Worker &dedicatedMemory);
1502*8975f5c5SAndroid Build Coastguard Worker Traits::ImportMemory(memoryObject, deviceMemorySize, memoryHandle);
1503*8975f5c5SAndroid Build Coastguard Worker
1504*8975f5c5SAndroid Build Coastguard Worker GLTexture texture;
1505*8975f5c5SAndroid Build Coastguard Worker glBindTexture(GL_TEXTURE_2D, texture);
1506*8975f5c5SAndroid Build Coastguard Worker glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1507*8975f5c5SAndroid Build Coastguard Worker glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1508*8975f5c5SAndroid Build Coastguard Worker glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1509*8975f5c5SAndroid Build Coastguard Worker glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1510*8975f5c5SAndroid Build Coastguard Worker if (useMemoryObjectFlags)
1511*8975f5c5SAndroid Build Coastguard Worker {
1512*8975f5c5SAndroid Build Coastguard Worker glTexStorageMemFlags2DANGLE(GL_TEXTURE_2D, 1, GL_RGBA8, kWidth, kHeight, memoryObject,
1513*8975f5c5SAndroid Build Coastguard Worker 0, createFlags, usageFlags, nullptr);
1514*8975f5c5SAndroid Build Coastguard Worker }
1515*8975f5c5SAndroid Build Coastguard Worker else
1516*8975f5c5SAndroid Build Coastguard Worker {
1517*8975f5c5SAndroid Build Coastguard Worker glTexStorageMem2DEXT(GL_TEXTURE_2D, 1, GL_RGBA8, kWidth, kHeight, memoryObject, 0);
1518*8975f5c5SAndroid Build Coastguard Worker }
1519*8975f5c5SAndroid Build Coastguard Worker
1520*8975f5c5SAndroid Build Coastguard Worker GLSemaphore glAcquireSemaphore;
1521*8975f5c5SAndroid Build Coastguard Worker Traits::ImportSemaphore(glAcquireSemaphore, acquireSemaphoreHandle);
1522*8975f5c5SAndroid Build Coastguard Worker
1523*8975f5c5SAndroid Build Coastguard Worker // Submit the semaphore without touching the image
1524*8975f5c5SAndroid Build Coastguard Worker helper.signalSemaphore(vkAcquireSemaphore);
1525*8975f5c5SAndroid Build Coastguard Worker
1526*8975f5c5SAndroid Build Coastguard Worker const GLuint barrierTexture = texture;
1527*8975f5c5SAndroid Build Coastguard Worker const GLenum textureSrcLayout = GL_NONE;
1528*8975f5c5SAndroid Build Coastguard Worker glWaitSemaphoreEXT(glAcquireSemaphore, 0, nullptr, 1, &barrierTexture, &textureSrcLayout);
1529*8975f5c5SAndroid Build Coastguard Worker
1530*8975f5c5SAndroid Build Coastguard Worker GLSemaphore glReleaseSemaphore;
1531*8975f5c5SAndroid Build Coastguard Worker Traits::ImportSemaphore(glReleaseSemaphore, releaseSemaphoreHandle);
1532*8975f5c5SAndroid Build Coastguard Worker
1533*8975f5c5SAndroid Build Coastguard Worker const GLenum textureDstLayout = useTexture(texture);
1534*8975f5c5SAndroid Build Coastguard Worker glSignalSemaphoreEXT(glReleaseSemaphore, 0, nullptr, 1, &barrierTexture, &textureDstLayout);
1535*8975f5c5SAndroid Build Coastguard Worker
1536*8975f5c5SAndroid Build Coastguard Worker const VkImageLayout imageLayout = GetPostReleaseVulkanLayout(textureDstLayout);
1537*8975f5c5SAndroid Build Coastguard Worker helper.waitSemaphoreAndAcquireImage(
1538*8975f5c5SAndroid Build Coastguard Worker image, imageLayout, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, vkReleaseSemaphore);
1539*8975f5c5SAndroid Build Coastguard Worker }
1540*8975f5c5SAndroid Build Coastguard Worker
1541*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
1542*8975f5c5SAndroid Build Coastguard Worker
1543*8975f5c5SAndroid Build Coastguard Worker // Verify the contents of the image from the Vulkan side too if needed
1544*8975f5c5SAndroid Build Coastguard Worker if (expectInVulkan != nullptr)
1545*8975f5c5SAndroid Build Coastguard Worker {
1546*8975f5c5SAndroid Build Coastguard Worker uint8_t pixels[4];
1547*8975f5c5SAndroid Build Coastguard Worker const VkOffset3D offset = {};
1548*8975f5c5SAndroid Build Coastguard Worker const VkExtent3D readExtent = {1, 1, 1};
1549*8975f5c5SAndroid Build Coastguard Worker helper.readPixels(image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_FORMAT_R8G8B8A8_UNORM,
1550*8975f5c5SAndroid Build Coastguard Worker offset, readExtent, pixels, sizeof(pixels));
1551*8975f5c5SAndroid Build Coastguard Worker
1552*8975f5c5SAndroid Build Coastguard Worker const uint32_t pixel = pixels[0] | pixels[1] << 8 | pixels[2] << 16 | pixels[3] << 24;
1553*8975f5c5SAndroid Build Coastguard Worker
1554*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(pixel, *expectInVulkan);
1555*8975f5c5SAndroid Build Coastguard Worker }
1556*8975f5c5SAndroid Build Coastguard Worker
1557*8975f5c5SAndroid Build Coastguard Worker vkDeviceWaitIdle(helper.getDevice());
1558*8975f5c5SAndroid Build Coastguard Worker vkDestroyImage(helper.getDevice(), image, nullptr);
1559*8975f5c5SAndroid Build Coastguard Worker vkDestroySemaphore(helper.getDevice(), vkAcquireSemaphore, nullptr);
1560*8975f5c5SAndroid Build Coastguard Worker vkDestroySemaphore(helper.getDevice(), vkReleaseSemaphore, nullptr);
1561*8975f5c5SAndroid Build Coastguard Worker vkFreeMemory(helper.getDevice(), deviceMemory, nullptr);
1562*8975f5c5SAndroid Build Coastguard Worker }
1563*8975f5c5SAndroid Build Coastguard Worker
1564*8975f5c5SAndroid Build Coastguard Worker // Test that texture storage created from VkImage memory can be imported as uninitialized in GL.
TEST_P(VulkanExternalImageTest,UninitializedOnGLImport)1565*8975f5c5SAndroid Build Coastguard Worker TEST_P(VulkanExternalImageTest, UninitializedOnGLImport)
1566*8975f5c5SAndroid Build Coastguard Worker {
1567*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_memory_object_fd"));
1568*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_semaphore_fd"));
1569*8975f5c5SAndroid Build Coastguard Worker
1570*8975f5c5SAndroid Build Coastguard Worker constexpr uint32_t kExpect = 0xFF0000FF;
1571*8975f5c5SAndroid Build Coastguard Worker
1572*8975f5c5SAndroid Build Coastguard Worker auto render = [kExpect](GLuint texture) {
1573*8975f5c5SAndroid Build Coastguard Worker GLFramebuffer framebuffer;
1574*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
1575*8975f5c5SAndroid Build Coastguard Worker glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
1576*8975f5c5SAndroid Build Coastguard Worker
1577*8975f5c5SAndroid Build Coastguard Worker glClearColor(1, 0, 0, 1);
1578*8975f5c5SAndroid Build Coastguard Worker glClear(GL_COLOR_BUFFER_BIT);
1579*8975f5c5SAndroid Build Coastguard Worker
1580*8975f5c5SAndroid Build Coastguard Worker uint32_t pixel = 0u;
1581*8975f5c5SAndroid Build Coastguard Worker glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixel);
1582*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
1583*8975f5c5SAndroid Build Coastguard Worker
1584*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(pixel, kExpect);
1585*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
1586*8975f5c5SAndroid Build Coastguard Worker
1587*8975f5c5SAndroid Build Coastguard Worker return GL_LAYOUT_TRANSFER_SRC_EXT;
1588*8975f5c5SAndroid Build Coastguard Worker };
1589*8975f5c5SAndroid Build Coastguard Worker
1590*8975f5c5SAndroid Build Coastguard Worker RunUninitializedOnGLImportTest<OpaqueFdTraits>(false, render, &kExpect, isSwiftshader(),
1591*8975f5c5SAndroid Build Coastguard Worker enableDebugLayers());
1592*8975f5c5SAndroid Build Coastguard Worker }
1593*8975f5c5SAndroid Build Coastguard Worker
1594*8975f5c5SAndroid Build Coastguard Worker // Test that texture storage created from VkImage memory can be imported as uninitialized in GL and
1595*8975f5c5SAndroid Build Coastguard Worker // released without being touched.
TEST_P(VulkanExternalImageTest,UninitializedOnGLImportAndExport)1596*8975f5c5SAndroid Build Coastguard Worker TEST_P(VulkanExternalImageTest, UninitializedOnGLImportAndExport)
1597*8975f5c5SAndroid Build Coastguard Worker {
1598*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_memory_object_fd"));
1599*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_semaphore_fd"));
1600*8975f5c5SAndroid Build Coastguard Worker
1601*8975f5c5SAndroid Build Coastguard Worker auto doNothing = [](GLuint) { return GL_NONE; };
1602*8975f5c5SAndroid Build Coastguard Worker
1603*8975f5c5SAndroid Build Coastguard Worker RunUninitializedOnGLImportTest<OpaqueFdTraits>(false, doNothing, nullptr, isSwiftshader(),
1604*8975f5c5SAndroid Build Coastguard Worker enableDebugLayers());
1605*8975f5c5SAndroid Build Coastguard Worker }
1606*8975f5c5SAndroid Build Coastguard Worker
1607*8975f5c5SAndroid Build Coastguard Worker // Test that texture storage created from VkImage memory can be imported as uninitialized in GL and
1608*8975f5c5SAndroid Build Coastguard Worker // then used as the target of a copy.
TEST_P(VulkanExternalImageTest,UninitializedOnGLImportAndCopy)1609*8975f5c5SAndroid Build Coastguard Worker TEST_P(VulkanExternalImageTest, UninitializedOnGLImportAndCopy)
1610*8975f5c5SAndroid Build Coastguard Worker {
1611*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_memory_object_fd"));
1612*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_semaphore_fd"));
1613*8975f5c5SAndroid Build Coastguard Worker
1614*8975f5c5SAndroid Build Coastguard Worker constexpr uint32_t kExpect = 0xFF00FF00;
1615*8975f5c5SAndroid Build Coastguard Worker
1616*8975f5c5SAndroid Build Coastguard Worker auto copy = [kExpect](GLuint texture) {
1617*8975f5c5SAndroid Build Coastguard Worker std::vector<GLColor> initData(kWidth * kHeight, GLColor::green);
1618*8975f5c5SAndroid Build Coastguard Worker glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_BYTE,
1619*8975f5c5SAndroid Build Coastguard Worker initData.data());
1620*8975f5c5SAndroid Build Coastguard Worker
1621*8975f5c5SAndroid Build Coastguard Worker GLFramebuffer framebuffer;
1622*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
1623*8975f5c5SAndroid Build Coastguard Worker glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
1624*8975f5c5SAndroid Build Coastguard Worker
1625*8975f5c5SAndroid Build Coastguard Worker uint32_t pixel = 0u;
1626*8975f5c5SAndroid Build Coastguard Worker glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixel);
1627*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
1628*8975f5c5SAndroid Build Coastguard Worker
1629*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(pixel, kExpect);
1630*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
1631*8975f5c5SAndroid Build Coastguard Worker
1632*8975f5c5SAndroid Build Coastguard Worker return GL_LAYOUT_TRANSFER_SRC_EXT;
1633*8975f5c5SAndroid Build Coastguard Worker };
1634*8975f5c5SAndroid Build Coastguard Worker
1635*8975f5c5SAndroid Build Coastguard Worker RunUninitializedOnGLImportTest<OpaqueFdTraits>(false, copy, &kExpect, isSwiftshader(),
1636*8975f5c5SAndroid Build Coastguard Worker enableDebugLayers());
1637*8975f5c5SAndroid Build Coastguard Worker }
1638*8975f5c5SAndroid Build Coastguard Worker
1639*8975f5c5SAndroid Build Coastguard Worker // Test that texture storage created from VkImage memory can be imported as uninitialized in GL and
1640*8975f5c5SAndroid Build Coastguard Worker // then used as sampler. Because the image is initialized, sampled results would be garbage, so
1641*8975f5c5SAndroid Build Coastguard Worker // this test is primarily ensuring no validation errors are generated.
TEST_P(VulkanExternalImageTest,UninitializedOnGLImportAndSample)1642*8975f5c5SAndroid Build Coastguard Worker TEST_P(VulkanExternalImageTest, UninitializedOnGLImportAndSample)
1643*8975f5c5SAndroid Build Coastguard Worker {
1644*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_memory_object_fd"));
1645*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_semaphore_fd"));
1646*8975f5c5SAndroid Build Coastguard Worker
1647*8975f5c5SAndroid Build Coastguard Worker auto sample = [this](GLuint texture) {
1648*8975f5c5SAndroid Build Coastguard Worker GLProgram program;
1649*8975f5c5SAndroid Build Coastguard Worker program.makeRaster(essl1_shaders::vs::Texture2D(), essl1_shaders::fs::Texture2D());
1650*8975f5c5SAndroid Build Coastguard Worker drawQuad(program, std::string(essl1_shaders::PositionAttrib()), 0.0f);
1651*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
1652*8975f5c5SAndroid Build Coastguard Worker
1653*8975f5c5SAndroid Build Coastguard Worker return GL_LAYOUT_SHADER_READ_ONLY_EXT;
1654*8975f5c5SAndroid Build Coastguard Worker };
1655*8975f5c5SAndroid Build Coastguard Worker
1656*8975f5c5SAndroid Build Coastguard Worker RunUninitializedOnGLImportTest<OpaqueFdTraits>(false, sample, nullptr, isSwiftshader(),
1657*8975f5c5SAndroid Build Coastguard Worker enableDebugLayers());
1658*8975f5c5SAndroid Build Coastguard Worker }
1659*8975f5c5SAndroid Build Coastguard Worker
1660*8975f5c5SAndroid Build Coastguard Worker // Test that texture storage created from VkImage memory can be imported as uninitialized in GL and
1661*8975f5c5SAndroid Build Coastguard Worker // then used as storage image.
TEST_P(VulkanExternalImageTestES31,UninitializedOnGLImportAndStorageWrite)1662*8975f5c5SAndroid Build Coastguard Worker TEST_P(VulkanExternalImageTestES31, UninitializedOnGLImportAndStorageWrite)
1663*8975f5c5SAndroid Build Coastguard Worker {
1664*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_memory_object_fd"));
1665*8975f5c5SAndroid Build Coastguard Worker ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_semaphore_fd"));
1666*8975f5c5SAndroid Build Coastguard Worker
1667*8975f5c5SAndroid Build Coastguard Worker constexpr uint32_t kExpect = 0xFF00FFFF;
1668*8975f5c5SAndroid Build Coastguard Worker
1669*8975f5c5SAndroid Build Coastguard Worker auto storageWrite = [kExpect](GLuint texture) {
1670*8975f5c5SAndroid Build Coastguard Worker constexpr char kCS[] = R"(#version 310 es
1671*8975f5c5SAndroid Build Coastguard Worker layout(local_size_x=8, local_size_y=8) in;
1672*8975f5c5SAndroid Build Coastguard Worker layout(rgba8) uniform highp writeonly image2D img;
1673*8975f5c5SAndroid Build Coastguard Worker void main()
1674*8975f5c5SAndroid Build Coastguard Worker {
1675*8975f5c5SAndroid Build Coastguard Worker imageStore(img, ivec2(gl_GlobalInvocationID.xy), vec4(1, 1, 0, 1));
1676*8975f5c5SAndroid Build Coastguard Worker })";
1677*8975f5c5SAndroid Build Coastguard Worker
1678*8975f5c5SAndroid Build Coastguard Worker GLProgram program;
1679*8975f5c5SAndroid Build Coastguard Worker program.makeCompute(kCS);
1680*8975f5c5SAndroid Build Coastguard Worker glUseProgram(program);
1681*8975f5c5SAndroid Build Coastguard Worker
1682*8975f5c5SAndroid Build Coastguard Worker glBindImageTexture(0, texture, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA8);
1683*8975f5c5SAndroid Build Coastguard Worker glDispatchCompute(kWidth / 8, kHeight / 8, 1);
1684*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
1685*8975f5c5SAndroid Build Coastguard Worker
1686*8975f5c5SAndroid Build Coastguard Worker glMemoryBarrier(GL_FRAMEBUFFER_BARRIER_BIT);
1687*8975f5c5SAndroid Build Coastguard Worker
1688*8975f5c5SAndroid Build Coastguard Worker GLFramebuffer framebuffer;
1689*8975f5c5SAndroid Build Coastguard Worker glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
1690*8975f5c5SAndroid Build Coastguard Worker glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
1691*8975f5c5SAndroid Build Coastguard Worker
1692*8975f5c5SAndroid Build Coastguard Worker uint32_t pixel = 0u;
1693*8975f5c5SAndroid Build Coastguard Worker glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixel);
1694*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
1695*8975f5c5SAndroid Build Coastguard Worker
1696*8975f5c5SAndroid Build Coastguard Worker EXPECT_EQ(pixel, kExpect);
1697*8975f5c5SAndroid Build Coastguard Worker EXPECT_GL_NO_ERROR();
1698*8975f5c5SAndroid Build Coastguard Worker
1699*8975f5c5SAndroid Build Coastguard Worker return GL_LAYOUT_TRANSFER_SRC_EXT;
1700*8975f5c5SAndroid Build Coastguard Worker };
1701*8975f5c5SAndroid Build Coastguard Worker
1702*8975f5c5SAndroid Build Coastguard Worker RunUninitializedOnGLImportTest<OpaqueFdTraits>(false, storageWrite, &kExpect, isSwiftshader(),
1703*8975f5c5SAndroid Build Coastguard Worker enableDebugLayers());
1704*8975f5c5SAndroid Build Coastguard Worker }
1705*8975f5c5SAndroid Build Coastguard Worker
1706*8975f5c5SAndroid Build Coastguard Worker ANGLE_INSTANTIATE_TEST_ES2_AND_ES3(VulkanExternalImageTest);
1707*8975f5c5SAndroid Build Coastguard Worker ANGLE_INSTANTIATE_TEST_ES31(VulkanExternalImageTestES31);
1708*8975f5c5SAndroid Build Coastguard Worker } // namespace angle
1709