1 /*
2 * Copyright 2023 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "tests/Test.h"
9
10 #include "include/gpu/graphite/BackendTexture.h"
11 #include "include/gpu/graphite/Context.h"
12 #include "include/gpu/graphite/Recorder.h"
13 #include "include/gpu/graphite/vk/VulkanGraphiteTypes.h"
14 #include "src/gpu/graphite/Caps.h"
15 #include "src/gpu/graphite/ContextPriv.h"
16
17 using namespace skgpu::graphite;
18
19 namespace {
20 const SkISize kSize = {16, 16};
21 }
22
DEF_GRAPHITE_TEST_FOR_VULKAN_CONTEXT(VulkanBackendTextureSimpleCreationTest,reporter,context,CtsEnforcement::kNextRelease)23 DEF_GRAPHITE_TEST_FOR_VULKAN_CONTEXT(VulkanBackendTextureSimpleCreationTest, reporter, context,
24 CtsEnforcement::kNextRelease) {
25 auto recorder = context->makeRecorder();
26
27 bool isProtected = context->priv().caps()->protectedSupport();
28
29 VulkanTextureInfo textureInfo;
30 textureInfo.fSampleCount = 1;
31 textureInfo.fMipmapped = skgpu::Mipmapped::kNo;
32 textureInfo.fFlags = isProtected ? VK_IMAGE_CREATE_PROTECTED_BIT : 0;
33 textureInfo.fFormat = VK_FORMAT_R8G8B8A8_UNORM;
34 textureInfo.fImageTiling = VK_IMAGE_TILING_OPTIMAL;
35 textureInfo.fImageUsageFlags = VK_IMAGE_USAGE_SAMPLED_BIT;
36 textureInfo.fSharingMode = VK_SHARING_MODE_EXCLUSIVE;
37
38 auto beTexture = recorder->createBackendTexture(kSize, textureInfo);
39 REPORTER_ASSERT(reporter, beTexture.isValid());
40 recorder->deleteBackendTexture(beTexture);
41
42 // It should also pass if we set the usage to be a render target
43 textureInfo.fImageUsageFlags |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
44 beTexture = recorder->createBackendTexture(kSize, textureInfo);
45 REPORTER_ASSERT(reporter, beTexture.isValid());
46 recorder->deleteBackendTexture(beTexture);
47 }
48
49 // Test that copying BackendTexture variables works.
DEF_GRAPHITE_TEST_FOR_VULKAN_CONTEXT(VulkanBackendTextureCopyVariableTest,reporter,context,CtsEnforcement::kNextRelease)50 DEF_GRAPHITE_TEST_FOR_VULKAN_CONTEXT(VulkanBackendTextureCopyVariableTest, reporter, context,
51 CtsEnforcement::kNextRelease) {
52 auto recorder = context->makeRecorder();
53
54 bool isProtected = context->priv().caps()->protectedSupport();
55
56 VulkanTextureInfo textureInfo;
57 textureInfo.fSampleCount = 1;
58 textureInfo.fMipmapped = skgpu::Mipmapped::kNo;
59 textureInfo.fFlags = isProtected ? VK_IMAGE_CREATE_PROTECTED_BIT : 0;
60 textureInfo.fFormat = VK_FORMAT_R8G8B8A8_UNORM;
61 textureInfo.fImageTiling = VK_IMAGE_TILING_OPTIMAL;
62 textureInfo.fImageUsageFlags = VK_IMAGE_USAGE_SAMPLED_BIT;
63 textureInfo.fSharingMode = VK_SHARING_MODE_EXCLUSIVE;
64
65 BackendTexture beTexture = recorder->createBackendTexture(kSize, textureInfo);
66 REPORTER_ASSERT(reporter, beTexture.isValid());
67
68 BackendTexture beTexture2;
69 REPORTER_ASSERT(reporter, beTexture2 != beTexture);
70 REPORTER_ASSERT(reporter, beTexture2.getVkImage() == VK_NULL_HANDLE);
71 REPORTER_ASSERT(reporter, beTexture2.getVkImageLayout() == VK_IMAGE_LAYOUT_UNDEFINED);
72
73 beTexture2 = beTexture;
74 REPORTER_ASSERT(reporter, beTexture2 == beTexture);
75 REPORTER_ASSERT(reporter, beTexture2.getVkImage() == beTexture.getVkImage());
76 REPORTER_ASSERT(reporter, beTexture2.getVkImageLayout() == beTexture.getVkImageLayout());
77 REPORTER_ASSERT(
78 reporter, beTexture2.getVkQueueFamilyIndex() == beTexture.getVkQueueFamilyIndex());
79
80 recorder->deleteBackendTexture(beTexture);
81 // The backend memory of beTexture2 == that of beTexture, so only call delete once.
82 }
83