xref: /aosp_15_r20/external/skia/src/gpu/graphite/dawn/DawnGraphiteTypesPriv.cpp (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 #include "src/gpu/graphite/dawn/DawnGraphiteTypesPriv.h"
9 
10 namespace skgpu::graphite {
11 
12 #if !defined(__EMSCRIPTEN__)
13 namespace ycbcrUtils {
DawnDescriptorsAreEquivalent(const wgpu::YCbCrVkDescriptor & desc1,const wgpu::YCbCrVkDescriptor & desc2)14 bool DawnDescriptorsAreEquivalent(const wgpu::YCbCrVkDescriptor& desc1,
15                                   const wgpu::YCbCrVkDescriptor& desc2) {
16     return desc1.vkFormat                    == desc2.vkFormat                    &&
17            desc1.vkYCbCrRange                == desc2.vkYCbCrRange                &&
18            desc1.vkComponentSwizzleRed       == desc2.vkComponentSwizzleRed       &&
19            desc1.vkComponentSwizzleGreen     == desc2.vkComponentSwizzleGreen     &&
20            desc1.vkComponentSwizzleBlue      == desc2.vkComponentSwizzleBlue      &&
21            desc1.vkComponentSwizzleAlpha     == desc2.vkComponentSwizzleAlpha     &&
22            desc1.vkXChromaOffset             == desc2.vkXChromaOffset             &&
23            desc1.vkYChromaOffset             == desc2.vkYChromaOffset             &&
24            desc1.vkChromaFilter              == desc2.vkChromaFilter              &&
25            desc1.forceExplicitReconstruction == desc2.forceExplicitReconstruction &&
26            desc1.externalFormat              == desc2.externalFormat;
27 }
28 }  // namespace ycbcrUtils
29 #endif
30 
toString() const31 SkString DawnTextureSpec::toString() const {
32     return SkStringPrintf("format=%u,viewFormat=%u,usage=0x%08X,aspect=0x%08X,slice=%u",
33                           static_cast<unsigned int>(fFormat),
34                           static_cast<unsigned int>(fViewFormat),
35                           static_cast<unsigned int>(fUsage),
36                           static_cast<unsigned int>(fAspect),
37                           fSlice);
38 }
39 
DawnTextureInfoFromWGPUTexture(WGPUTexture texture)40 DawnTextureInfo DawnTextureInfoFromWGPUTexture(WGPUTexture texture) {
41     SkASSERT(texture);
42     return DawnTextureInfo(
43             wgpuTextureGetSampleCount(texture),
44             wgpuTextureGetMipLevelCount(texture) > 1 ? Mipmapped::kYes : Mipmapped::kNo,
45             /*format=*/static_cast<wgpu::TextureFormat>(wgpuTextureGetFormat(texture)),
46             /*viewFormat=*/static_cast<wgpu::TextureFormat>(wgpuTextureGetFormat(texture)),
47             static_cast<wgpu::TextureUsage>(wgpuTextureGetUsage(texture)),
48             wgpu::TextureAspect::All,
49             /*slice=*/0);
50 }
51 
DawnTextureSpecToTextureInfo(const DawnTextureSpec & dawnSpec,uint32_t sampleCount,Mipmapped mipmapped)52 DawnTextureInfo DawnTextureSpecToTextureInfo(const DawnTextureSpec& dawnSpec,
53                                              uint32_t sampleCount,
54                                              Mipmapped mipmapped) {
55     DawnTextureInfo info;
56     // Shared info
57     info.fSampleCount = sampleCount;
58     info.fMipmapped = mipmapped;
59 
60     // Dawn info
61     info.fFormat = dawnSpec.fFormat;
62     info.fViewFormat = dawnSpec.fViewFormat;
63     info.fUsage = dawnSpec.fUsage;
64     info.fAspect = dawnSpec.fAspect;
65 #if !defined(__EMSCRIPTEN__)
66     info.fYcbcrVkDescriptor = dawnSpec.fYcbcrVkDescriptor;
67 #endif
68 
69     return info;
70 }
71 
72 }  // namespace skgpu::graphite
73