Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
DawnUtils.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2023 Google Inc.
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
9
13
14#if defined(__EMSCRIPTEN__)
15#include <emscripten.h>
16#endif // __EMSCRIPTEN__
17
18namespace skgpu::graphite {
19
20// TODO: A lot of these values are not correct
21size_t DawnFormatBytesPerBlock(wgpu::TextureFormat format) {
22 switch (format) {
23 case wgpu::TextureFormat::RGBA8Unorm: return 4;
24 case wgpu::TextureFormat::BGRA8Unorm: return 4;
25 case wgpu::TextureFormat::R8Unorm: return 1;
26 case wgpu::TextureFormat::RGBA16Float: return 8;
27 case wgpu::TextureFormat::R16Float: return 2;
28 case wgpu::TextureFormat::RG8Unorm: return 2;
29 case wgpu::TextureFormat::RGB10A2Unorm: return 4;
30 case wgpu::TextureFormat::RG16Float: return 4;
31 // The depth stencil values are not neccessarily correct in Dawn since Dawn is allowed to
32 // implement Stencil8 as a real stencil8 or depth24stencil8 format. Similarly the depth in
33 // Depth24PlusStencil8 can either be a 24 bit value or Depth32Float value. There is also
34 // currently no way to query this in WebGPU so we just use the highest values here.
35 case wgpu::TextureFormat::Stencil8: return 4; // could be backed by d24s8
36 case wgpu::TextureFormat::Depth32Float: return 4;
37 case wgpu::TextureFormat::Depth32FloatStencil8: return 5;
38 case wgpu::TextureFormat::Depth24PlusStencil8: return 5; // could be backed by d32s8
39
40#if !defined(__EMSCRIPTEN__)
41 case wgpu::TextureFormat::R16Unorm: return 2;
42 case wgpu::TextureFormat::RG16Unorm: return 4;
43#endif
44 default:
46 }
47}
48
50 switch (format) {
51 case wgpu::TextureFormat::ETC2RGB8Unorm: return SkTextureCompressionType::kETC2_RGB8_UNORM;
52 case wgpu::TextureFormat::BC1RGBAUnorm: return SkTextureCompressionType::kBC1_RGBA8_UNORM;
53 default: return SkTextureCompressionType::kNone;
54 }
55}
56
57uint32_t DawnFormatChannels(wgpu::TextureFormat format) {
58 switch (format) {
59 case wgpu::TextureFormat::RGBA8Unorm: return kRGBA_SkColorChannelFlags;
60 case wgpu::TextureFormat::BGRA8Unorm: return kRGBA_SkColorChannelFlags;
61 case wgpu::TextureFormat::R8Unorm: return kRed_SkColorChannelFlag;
62 case wgpu::TextureFormat::RGBA16Float: return kRGBA_SkColorChannelFlags;
63 case wgpu::TextureFormat::R16Float: return kRed_SkColorChannelFlag;
64 case wgpu::TextureFormat::RG8Unorm: return kRG_SkColorChannelFlags;
65 case wgpu::TextureFormat::RGB10A2Unorm: return kRGBA_SkColorChannelFlags;
66 case wgpu::TextureFormat::RG16Float: return kRG_SkColorChannelFlags;
67
68#if !defined(__EMSCRIPTEN__)
69 case wgpu::TextureFormat::R16Unorm: return kRed_SkColorChannelFlag;
70 case wgpu::TextureFormat::RG16Unorm: return kRG_SkColorChannelFlags;
71#endif
72
73 default: return 0;
74 }
76}
77
78} // namespace skgpu::graphite
79
#define SkUNREACHABLE
Definition SkAssert.h:135
@ kRGBA_SkColorChannelFlags
Definition SkColor.h:248
@ kRed_SkColorChannelFlag
Definition SkColor.h:239
@ kRG_SkColorChannelFlags
Definition SkColor.h:246
uint32_t uint32_t * format
SkTextureCompressionType DawnFormatToCompressionType(wgpu::TextureFormat format)
Definition DawnUtils.cpp:49
uint32_t DawnFormatChannels(wgpu::TextureFormat format)
Definition DawnUtils.cpp:57
size_t DawnFormatBytesPerBlock(wgpu::TextureFormat format)
Definition DawnUtils.cpp:21