xref: /aosp_15_r20/external/skia/src/gpu/graphite/dawn/DawnGraphiteTypesPriv.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2022 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 #ifndef skgpu_graphite_DawnTypesPriv_DEFINED
9 #define skgpu_graphite_DawnTypesPriv_DEFINED
10 
11 #include "include/core/SkString.h"
12 #include "include/gpu/graphite/dawn/DawnTypes.h"
13 
14 namespace skgpu::graphite {
15 #if !defined(__EMSCRIPTEN__)
16 namespace ycbcrUtils {
17 bool DawnDescriptorsAreEquivalent(const wgpu::YCbCrVkDescriptor&, const wgpu::YCbCrVkDescriptor&);
18 }
19 #endif
20 
21 struct DawnTextureSpec {
22     DawnTextureSpec() = default;
DawnTextureSpecDawnTextureSpec23     DawnTextureSpec(const DawnTextureInfo& info)
24             : fFormat(info.fFormat)
25             , fViewFormat(info.fViewFormat)
26             , fUsage(info.fUsage)
27             , fAspect(info.fAspect)
28 #if !defined(__EMSCRIPTEN__)
29             , fYcbcrVkDescriptor(info.fYcbcrVkDescriptor)
30 #endif
31             , fSlice(info.fSlice) {
32     }
33 
34     bool operator==(const DawnTextureSpec& that) const {
35         return fUsage == that.fUsage && fFormat == that.fFormat &&
36                fViewFormat == that.fViewFormat && fAspect == that.fAspect &&
37 #if !defined(__EMSCRIPTEN__)
38                ycbcrUtils::DawnDescriptorsAreEquivalent(fYcbcrVkDescriptor,
39                                                         that.fYcbcrVkDescriptor) &&
40 #endif
41                fSlice == that.fSlice;
42     }
43 
isCompatibleDawnTextureSpec44     bool isCompatible(const DawnTextureSpec& that) const {
45         // The usages may match or the usage passed in may be a superset of the usage stored within.
46         // The YCbCrInfo must be equal.
47         // The aspect should either match the plane aspect or should be All.
48         return getViewFormat() == that.getViewFormat() && (fUsage & that.fUsage) == fUsage &&
49 #if !defined(__EMSCRIPTEN__)
50                ycbcrUtils::DawnDescriptorsAreEquivalent(fYcbcrVkDescriptor,
51                                                         that.fYcbcrVkDescriptor) &&
52 #endif
53                (fAspect == that.fAspect || fAspect == wgpu::TextureAspect::All);
54     }
55 
getViewFormatDawnTextureSpec56     wgpu::TextureFormat getViewFormat() const {
57         return fViewFormat != wgpu::TextureFormat::Undefined ? fViewFormat : fFormat;
58     }
59 
60     SkString toString() const;
61 
62     wgpu::TextureFormat fFormat = wgpu::TextureFormat::Undefined;
63     // `fViewFormat` is always single plane format or plane view format for a multiplanar
64     // wgpu::Texture.
65     wgpu::TextureFormat fViewFormat = wgpu::TextureFormat::Undefined;
66     wgpu::TextureUsage fUsage = wgpu::TextureUsage::None;
67     wgpu::TextureAspect fAspect = wgpu::TextureAspect::All;
68 #if !defined(__EMSCRIPTEN__)
69     wgpu::YCbCrVkDescriptor fYcbcrVkDescriptor = {};
70 #endif
71     uint32_t fSlice = 0;
72 };
73 
74 DawnTextureInfo DawnTextureSpecToTextureInfo(const DawnTextureSpec& dawnSpec,
75                                              uint32_t sampleCount,
76                                              Mipmapped mipmapped);
77 
78 DawnTextureInfo DawnTextureInfoFromWGPUTexture(WGPUTexture texture);
79 
80 namespace TextureInfos {
81 DawnTextureSpec GetDawnTextureSpec(const TextureInfo& dawnInfo);
82 
83 wgpu::TextureFormat GetDawnViewFormat(const TextureInfo& dawnInfo);
84 wgpu::TextureAspect GetDawnAspect(const TextureInfo& dawnInfo);
85 }  // namespace TextureInfos
86 
87 namespace BackendTextures {
88 WGPUTexture GetDawnTexturePtr(const BackendTexture&);
89 WGPUTextureView GetDawnTextureViewPtr(const BackendTexture&);
90 }  // namespace BackendTextures
91 
92 }  // namespace skgpu::graphite
93 
94 #endif  // skgpu_graphite_DawnTypesPriv_DEFINED
95