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