xref: /aosp_15_r20/external/skia/tests/graphite/DawnBackendTextureTest.cpp (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
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/dawn/DawnTypes.h"
14 #include "src/gpu/graphite/dawn/DawnGraphiteTypesPriv.h"
15 
16 #include "webgpu/webgpu_cpp.h"  // NO_G3_REWRITE
17 
18 using namespace skgpu::graphite;
19 
20 namespace {
21 const SkISize kSize = {16, 16};
22 }
23 
DEF_GRAPHITE_TEST_FOR_DAWN_CONTEXT(DawnBackendTextureSimpleCreationTest,reporter,context,testContext)24 DEF_GRAPHITE_TEST_FOR_DAWN_CONTEXT(DawnBackendTextureSimpleCreationTest,
25                                    reporter,
26                                    context,
27                                    testContext) {
28     auto recorder = context->makeRecorder();
29 
30     DawnTextureInfo textureInfo;
31     textureInfo.fSampleCount = 1;
32     textureInfo.fMipmapped = skgpu::Mipmapped::kNo;
33     textureInfo.fFormat = wgpu::TextureFormat::RGBA8Unorm;
34     textureInfo.fUsage = wgpu::TextureUsage::TextureBinding;
35 
36     auto beTexture = recorder->createBackendTexture(kSize, TextureInfos::MakeDawn(textureInfo));
37     REPORTER_ASSERT(reporter, beTexture.isValid());
38     recorder->deleteBackendTexture(beTexture);
39 
40     // It should also pass if we set the usage to be a render target
41     textureInfo.fUsage |= wgpu::TextureUsage::RenderAttachment;
42     beTexture = recorder->createBackendTexture(kSize, TextureInfos::MakeDawn(textureInfo));
43     REPORTER_ASSERT(reporter, beTexture.isValid());
44     recorder->deleteBackendTexture(beTexture);
45 }
46 
47 // Test that copying BackendTexture variables works.
DEF_GRAPHITE_TEST_FOR_DAWN_CONTEXT(DawnBackendTextureCopyVariableTest,reporter,context,testContext)48 DEF_GRAPHITE_TEST_FOR_DAWN_CONTEXT(DawnBackendTextureCopyVariableTest,
49                                    reporter,
50                                    context,
51                                    testContext) {
52     auto recorder = context->makeRecorder();
53 
54     DawnTextureInfo textureInfo;
55     textureInfo.fSampleCount = 1;
56     textureInfo.fMipmapped = skgpu::Mipmapped::kNo;
57     textureInfo.fFormat = wgpu::TextureFormat::RGBA8Unorm;
58     textureInfo.fUsage = wgpu::TextureUsage::TextureBinding;
59 
60     BackendTexture beTexture =
61             recorder->createBackendTexture(kSize, TextureInfos::MakeDawn(textureInfo));
62     REPORTER_ASSERT(reporter, beTexture.isValid());
63 
64     BackendTexture beTexture2;
65     REPORTER_ASSERT(reporter, beTexture2 != beTexture);
66     REPORTER_ASSERT(reporter, BackendTextures::GetDawnTexturePtr(beTexture2) == nullptr);
67     REPORTER_ASSERT(reporter, BackendTextures::GetDawnTextureViewPtr(beTexture2) == nullptr);
68 
69     beTexture2 = beTexture;
70     REPORTER_ASSERT(reporter, beTexture2 == beTexture);
71     REPORTER_ASSERT(reporter, BackendTextures::GetDawnTexturePtr(beTexture2) != nullptr);
72     REPORTER_ASSERT(reporter,
73                     BackendTextures::GetDawnTexturePtr(beTexture2) ==
74                             BackendTextures::GetDawnTexturePtr(beTexture));
75 
76     recorder->deleteBackendTexture(beTexture);
77 }
78