xref: /aosp_15_r20/external/skia/tests/graphite/DawnBackendTextureTest.cpp (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1*c8dee2aaSAndroid Build Coastguard Worker /*
2*c8dee2aaSAndroid Build Coastguard Worker  * Copyright 2023 Google LLC
3*c8dee2aaSAndroid Build Coastguard Worker  *
4*c8dee2aaSAndroid Build Coastguard Worker  * Use of this source code is governed by a BSD-style license that can be
5*c8dee2aaSAndroid Build Coastguard Worker  * found in the LICENSE file.
6*c8dee2aaSAndroid Build Coastguard Worker  */
7*c8dee2aaSAndroid Build Coastguard Worker 
8*c8dee2aaSAndroid Build Coastguard Worker #include "tests/Test.h"
9*c8dee2aaSAndroid Build Coastguard Worker 
10*c8dee2aaSAndroid Build Coastguard Worker #include "include/gpu/graphite/BackendTexture.h"
11*c8dee2aaSAndroid Build Coastguard Worker #include "include/gpu/graphite/Context.h"
12*c8dee2aaSAndroid Build Coastguard Worker #include "include/gpu/graphite/Recorder.h"
13*c8dee2aaSAndroid Build Coastguard Worker #include "include/gpu/graphite/dawn/DawnTypes.h"
14*c8dee2aaSAndroid Build Coastguard Worker #include "src/gpu/graphite/dawn/DawnGraphiteTypesPriv.h"
15*c8dee2aaSAndroid Build Coastguard Worker 
16*c8dee2aaSAndroid Build Coastguard Worker #include "webgpu/webgpu_cpp.h"  // NO_G3_REWRITE
17*c8dee2aaSAndroid Build Coastguard Worker 
18*c8dee2aaSAndroid Build Coastguard Worker using namespace skgpu::graphite;
19*c8dee2aaSAndroid Build Coastguard Worker 
20*c8dee2aaSAndroid Build Coastguard Worker namespace {
21*c8dee2aaSAndroid Build Coastguard Worker const SkISize kSize = {16, 16};
22*c8dee2aaSAndroid Build Coastguard Worker }
23*c8dee2aaSAndroid Build Coastguard Worker 
DEF_GRAPHITE_TEST_FOR_DAWN_CONTEXT(DawnBackendTextureSimpleCreationTest,reporter,context,testContext)24*c8dee2aaSAndroid Build Coastguard Worker DEF_GRAPHITE_TEST_FOR_DAWN_CONTEXT(DawnBackendTextureSimpleCreationTest,
25*c8dee2aaSAndroid Build Coastguard Worker                                    reporter,
26*c8dee2aaSAndroid Build Coastguard Worker                                    context,
27*c8dee2aaSAndroid Build Coastguard Worker                                    testContext) {
28*c8dee2aaSAndroid Build Coastguard Worker     auto recorder = context->makeRecorder();
29*c8dee2aaSAndroid Build Coastguard Worker 
30*c8dee2aaSAndroid Build Coastguard Worker     DawnTextureInfo textureInfo;
31*c8dee2aaSAndroid Build Coastguard Worker     textureInfo.fSampleCount = 1;
32*c8dee2aaSAndroid Build Coastguard Worker     textureInfo.fMipmapped = skgpu::Mipmapped::kNo;
33*c8dee2aaSAndroid Build Coastguard Worker     textureInfo.fFormat = wgpu::TextureFormat::RGBA8Unorm;
34*c8dee2aaSAndroid Build Coastguard Worker     textureInfo.fUsage = wgpu::TextureUsage::TextureBinding;
35*c8dee2aaSAndroid Build Coastguard Worker 
36*c8dee2aaSAndroid Build Coastguard Worker     auto beTexture = recorder->createBackendTexture(kSize, TextureInfos::MakeDawn(textureInfo));
37*c8dee2aaSAndroid Build Coastguard Worker     REPORTER_ASSERT(reporter, beTexture.isValid());
38*c8dee2aaSAndroid Build Coastguard Worker     recorder->deleteBackendTexture(beTexture);
39*c8dee2aaSAndroid Build Coastguard Worker 
40*c8dee2aaSAndroid Build Coastguard Worker     // It should also pass if we set the usage to be a render target
41*c8dee2aaSAndroid Build Coastguard Worker     textureInfo.fUsage |= wgpu::TextureUsage::RenderAttachment;
42*c8dee2aaSAndroid Build Coastguard Worker     beTexture = recorder->createBackendTexture(kSize, TextureInfos::MakeDawn(textureInfo));
43*c8dee2aaSAndroid Build Coastguard Worker     REPORTER_ASSERT(reporter, beTexture.isValid());
44*c8dee2aaSAndroid Build Coastguard Worker     recorder->deleteBackendTexture(beTexture);
45*c8dee2aaSAndroid Build Coastguard Worker }
46*c8dee2aaSAndroid Build Coastguard Worker 
47*c8dee2aaSAndroid Build Coastguard Worker // Test that copying BackendTexture variables works.
DEF_GRAPHITE_TEST_FOR_DAWN_CONTEXT(DawnBackendTextureCopyVariableTest,reporter,context,testContext)48*c8dee2aaSAndroid Build Coastguard Worker DEF_GRAPHITE_TEST_FOR_DAWN_CONTEXT(DawnBackendTextureCopyVariableTest,
49*c8dee2aaSAndroid Build Coastguard Worker                                    reporter,
50*c8dee2aaSAndroid Build Coastguard Worker                                    context,
51*c8dee2aaSAndroid Build Coastguard Worker                                    testContext) {
52*c8dee2aaSAndroid Build Coastguard Worker     auto recorder = context->makeRecorder();
53*c8dee2aaSAndroid Build Coastguard Worker 
54*c8dee2aaSAndroid Build Coastguard Worker     DawnTextureInfo textureInfo;
55*c8dee2aaSAndroid Build Coastguard Worker     textureInfo.fSampleCount = 1;
56*c8dee2aaSAndroid Build Coastguard Worker     textureInfo.fMipmapped = skgpu::Mipmapped::kNo;
57*c8dee2aaSAndroid Build Coastguard Worker     textureInfo.fFormat = wgpu::TextureFormat::RGBA8Unorm;
58*c8dee2aaSAndroid Build Coastguard Worker     textureInfo.fUsage = wgpu::TextureUsage::TextureBinding;
59*c8dee2aaSAndroid Build Coastguard Worker 
60*c8dee2aaSAndroid Build Coastguard Worker     BackendTexture beTexture =
61*c8dee2aaSAndroid Build Coastguard Worker             recorder->createBackendTexture(kSize, TextureInfos::MakeDawn(textureInfo));
62*c8dee2aaSAndroid Build Coastguard Worker     REPORTER_ASSERT(reporter, beTexture.isValid());
63*c8dee2aaSAndroid Build Coastguard Worker 
64*c8dee2aaSAndroid Build Coastguard Worker     BackendTexture beTexture2;
65*c8dee2aaSAndroid Build Coastguard Worker     REPORTER_ASSERT(reporter, beTexture2 != beTexture);
66*c8dee2aaSAndroid Build Coastguard Worker     REPORTER_ASSERT(reporter, BackendTextures::GetDawnTexturePtr(beTexture2) == nullptr);
67*c8dee2aaSAndroid Build Coastguard Worker     REPORTER_ASSERT(reporter, BackendTextures::GetDawnTextureViewPtr(beTexture2) == nullptr);
68*c8dee2aaSAndroid Build Coastguard Worker 
69*c8dee2aaSAndroid Build Coastguard Worker     beTexture2 = beTexture;
70*c8dee2aaSAndroid Build Coastguard Worker     REPORTER_ASSERT(reporter, beTexture2 == beTexture);
71*c8dee2aaSAndroid Build Coastguard Worker     REPORTER_ASSERT(reporter, BackendTextures::GetDawnTexturePtr(beTexture2) != nullptr);
72*c8dee2aaSAndroid Build Coastguard Worker     REPORTER_ASSERT(reporter,
73*c8dee2aaSAndroid Build Coastguard Worker                     BackendTextures::GetDawnTexturePtr(beTexture2) ==
74*c8dee2aaSAndroid Build Coastguard Worker                             BackendTextures::GetDawnTexturePtr(beTexture));
75*c8dee2aaSAndroid Build Coastguard Worker 
76*c8dee2aaSAndroid Build Coastguard Worker     recorder->deleteBackendTexture(beTexture);
77*c8dee2aaSAndroid Build Coastguard Worker }
78