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 #include "src/gpu/graphite/vk/VulkanGraphiteTypesPriv.h"
17
18 using namespace skgpu::graphite;
19
20 namespace {
21 const SkISize kSize = {16, 16};
22 }
23
DEF_GRAPHITE_TEST_FOR_VULKAN_CONTEXT(VulkanBackendTextureSimpleCreationTest,reporter,context,CtsEnforcement::kApiLevel_V)24 DEF_GRAPHITE_TEST_FOR_VULKAN_CONTEXT(VulkanBackendTextureSimpleCreationTest, reporter, context,
25 CtsEnforcement::kApiLevel_V) {
26 auto recorder = context->makeRecorder();
27
28 bool isProtected = context->priv().caps()->protectedSupport();
29
30 VulkanTextureInfo textureInfo;
31 textureInfo.fSampleCount = 1;
32 textureInfo.fMipmapped = skgpu::Mipmapped::kNo;
33 textureInfo.fFlags = isProtected ? VK_IMAGE_CREATE_PROTECTED_BIT : 0;
34 textureInfo.fFormat = VK_FORMAT_R8G8B8A8_UNORM;
35 textureInfo.fImageTiling = VK_IMAGE_TILING_OPTIMAL;
36 textureInfo.fImageUsageFlags = VK_IMAGE_USAGE_SAMPLED_BIT;
37 textureInfo.fSharingMode = VK_SHARING_MODE_EXCLUSIVE;
38
39 auto beTexture = recorder->createBackendTexture(kSize, TextureInfos::MakeVulkan(textureInfo));
40 REPORTER_ASSERT(reporter, beTexture.isValid());
41 recorder->deleteBackendTexture(beTexture);
42
43 // It should also pass if we set the usage to be a render target
44 textureInfo.fImageUsageFlags |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
45 beTexture = recorder->createBackendTexture(kSize, TextureInfos::MakeVulkan(textureInfo));
46 REPORTER_ASSERT(reporter, beTexture.isValid());
47 recorder->deleteBackendTexture(beTexture);
48 }
49
50 // Test that copying BackendTexture variables works.
DEF_GRAPHITE_TEST_FOR_VULKAN_CONTEXT(VulkanBackendTextureCopyVariableTest,reporter,context,CtsEnforcement::kApiLevel_V)51 DEF_GRAPHITE_TEST_FOR_VULKAN_CONTEXT(VulkanBackendTextureCopyVariableTest, reporter, context,
52 CtsEnforcement::kApiLevel_V) {
53 auto recorder = context->makeRecorder();
54
55 bool isProtected = context->priv().caps()->protectedSupport();
56
57 VulkanTextureInfo textureInfo;
58 textureInfo.fSampleCount = 1;
59 textureInfo.fMipmapped = skgpu::Mipmapped::kNo;
60 textureInfo.fFlags = isProtected ? VK_IMAGE_CREATE_PROTECTED_BIT : 0;
61 textureInfo.fFormat = VK_FORMAT_R8G8B8A8_UNORM;
62 textureInfo.fImageTiling = VK_IMAGE_TILING_OPTIMAL;
63 textureInfo.fImageUsageFlags = VK_IMAGE_USAGE_SAMPLED_BIT;
64 textureInfo.fSharingMode = VK_SHARING_MODE_EXCLUSIVE;
65
66 BackendTexture beTexture =
67 recorder->createBackendTexture(kSize, TextureInfos::MakeVulkan(textureInfo));
68 REPORTER_ASSERT(reporter, beTexture.isValid());
69
70 BackendTexture beTexture2;
71 REPORTER_ASSERT(reporter, beTexture2 != beTexture);
72 REPORTER_ASSERT(reporter, BackendTextures::GetVkImage(beTexture2) == VK_NULL_HANDLE);
73 REPORTER_ASSERT(reporter,
74 BackendTextures::GetVkImageLayout(beTexture2) == VK_IMAGE_LAYOUT_UNDEFINED);
75
76 beTexture2 = beTexture;
77 REPORTER_ASSERT(reporter, beTexture2 == beTexture);
78 REPORTER_ASSERT(
79 reporter,
80 BackendTextures::GetVkImage(beTexture2) == BackendTextures::GetVkImage(beTexture));
81 REPORTER_ASSERT(reporter,
82 BackendTextures::GetVkImageLayout(beTexture2) ==
83 BackendTextures::GetVkImageLayout(beTexture));
84 REPORTER_ASSERT(reporter,
85 BackendTextures::GetVkQueueFamilyIndex(beTexture2) ==
86 BackendTextures::GetVkQueueFamilyIndex(beTexture));
87
88 recorder->deleteBackendTexture(beTexture);
89 // The backend memory of beTexture2 == that of beTexture, so only call delete once.
90 }
91