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/SkImageInfo.h"
12 #include "include/core/SkString.h"
13 #include "include/core/SkTextureCompressionType.h"
14 #include "include/gpu/graphite/dawn/DawnGraphiteTypes.h"
15 #include "src/gpu/SkSLToBackend.h"
16 #include "src/gpu/graphite/ResourceTypes.h"
17 #include "src/sksl/SkSLProgramKind.h"
18 #include "src/sksl/codegen/SkSLWGSLCodeGenerator.h"
19 #include "src/sksl/ir/SkSLProgram.h"
20
21 #include "webgpu/webgpu_cpp.h" // NO_G3_REWRITE
22
23 namespace SkSL {
24
25 enum class ProgramKind : int8_t;
26 struct ProgramInterface;
27 struct ProgramSettings;
28 struct ShaderCaps;
29
30 } // namespace SkSL
31
32 namespace skgpu {
33
34 class ShaderErrorHandler;
35
SkSLToWGSL(const SkSL::ShaderCaps * caps,const std::string & sksl,SkSL::ProgramKind programKind,const SkSL::ProgramSettings & settings,std::string * wgsl,SkSL::ProgramInterface * outInterface,ShaderErrorHandler * errorHandler)36 inline bool SkSLToWGSL(const SkSL::ShaderCaps* caps,
37 const std::string& sksl,
38 SkSL::ProgramKind programKind,
39 const SkSL::ProgramSettings& settings,
40 std::string* wgsl,
41 SkSL::ProgramInterface* outInterface,
42 ShaderErrorHandler* errorHandler) {
43 return SkSLToBackend(caps, &SkSL::ToWGSL, "WGSL",
44 sksl, programKind, settings, wgsl, outInterface, errorHandler);
45 }
46
47 } // namespace skgpu
48
49 namespace skgpu::graphite {
50
51 class DawnSharedContext;
52 enum class TextureFormat : uint8_t;
53
54 bool DawnCompileWGSLShaderModule(const DawnSharedContext* sharedContext,
55 const char* label,
56 const std::string& wgsl,
57 wgpu::ShaderModule* module,
58 ShaderErrorHandler*);
59
60 #if !defined(__EMSCRIPTEN__)
61
62 bool DawnDescriptorIsValid(const wgpu::YCbCrVkDescriptor&);
63
64 bool DawnDescriptorUsesExternalFormat(const wgpu::YCbCrVkDescriptor&);
65
66 bool DawnDescriptorsAreEquivalent(const wgpu::YCbCrVkDescriptor&, const wgpu::YCbCrVkDescriptor&);
67
68 ImmutableSamplerInfo DawnDescriptorToImmutableSamplerInfo(const wgpu::YCbCrVkDescriptor&);
69 wgpu::YCbCrVkDescriptor DawnDescriptorFromImmutableSamplerInfo(ImmutableSamplerInfo);
70
71 #endif // !defined(__EMSCRIPTEN__)
72
73 SkTextureCompressionType DawnFormatToCompressionType(wgpu::TextureFormat format);
74
75 bool DawnFormatIsDepthOrStencil(wgpu::TextureFormat);
76 bool DawnFormatIsDepth(wgpu::TextureFormat);
77 bool DawnFormatIsStencil(wgpu::TextureFormat);
78
79 wgpu::TextureFormat DawnDepthStencilFlagsToFormat(SkEnumBitMask<DepthStencilFlags>);
80
81 TextureFormat DawnFormatToTextureFormat(wgpu::TextureFormat);
82
83 namespace BackendTextures {
84
85 WGPUTexture GetDawnTexturePtr(const BackendTexture&);
86 WGPUTextureView GetDawnTextureViewPtr(const BackendTexture&);
87
88 } // namespace BackendTextures
89
90 } // namespace skgpu::graphite
91
92 #endif // skgpu_graphite_DawnTypesPriv_DEFINED
93