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