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_DawnGraphiteUtilsPriv_DEFINED 9 #define skgpu_graphite_DawnGraphiteUtilsPriv_DEFINED 10 11 #include "include/core/SkImageInfo.h" 12 #include "src/gpu/graphite/ResourceTypes.h" 13 #include "src/gpu/graphite/dawn/DawnGraphiteTypesPriv.h" 14 #include "src/sksl/SkSLProgramKind.h" 15 #include "src/sksl/ir/SkSLProgram.h" 16 17 #include "webgpu/webgpu_cpp.h" // NO_G3_REWRITE 18 19 namespace SkSL { 20 class Compiler; 21 struct ProgramSettings; 22 } 23 24 namespace skgpu { 25 class ShaderErrorHandler; 26 } 27 28 namespace skgpu::graphite { 29 class DawnSharedContext; 30 31 bool DawnFormatIsDepthOrStencil(wgpu::TextureFormat); 32 bool DawnFormatIsDepth(wgpu::TextureFormat); 33 bool DawnFormatIsStencil(wgpu::TextureFormat); 34 35 wgpu::TextureFormat DawnDepthStencilFlagsToFormat(SkEnumBitMask<DepthStencilFlags>); 36 37 bool DawnCompileWGSLShaderModule(const DawnSharedContext* sharedContext, 38 const char* label, 39 const std::string& wgsl, 40 wgpu::ShaderModule* module, 41 ShaderErrorHandler*); 42 43 #if !defined(__EMSCRIPTEN__) 44 namespace ycbcrUtils { 45 46 bool DawnDescriptorIsValid(const wgpu::YCbCrVkDescriptor&); 47 48 bool DawnDescriptorUsesExternalFormat(const wgpu::YCbCrVkDescriptor&); 49 50 static constexpr int kUsesExternalFormatBits = 1; 51 static constexpr int kYcbcrModelBits = 3; 52 static constexpr int kYcbcrRangeBits = 1; 53 static constexpr int kXChromaOffsetBits = 1; 54 static constexpr int kYChromaOffsetBits = 1; 55 // wgpu::FilterMode contains Undefined/Nearest/Linear entries (Linear is 2). 56 static constexpr int kChromaFilterBits = 2; 57 static constexpr int kForceExplicitReconBits = 1; 58 static constexpr int kComponentBits = 3; 59 60 static constexpr int kUsesExternalFormatShift = 0; 61 static constexpr int kYcbcrModelShift = kUsesExternalFormatShift + kUsesExternalFormatBits; 62 static constexpr int kYcbcrRangeShift = kYcbcrModelShift + kYcbcrModelBits; 63 static constexpr int kXChromaOffsetShift = kYcbcrRangeShift + kYcbcrRangeBits; 64 static constexpr int kYChromaOffsetShift = kXChromaOffsetShift + kXChromaOffsetBits; 65 static constexpr int kChromaFilterShift = kYChromaOffsetShift + kYChromaOffsetBits; 66 static constexpr int kForceExplicitReconShift = kChromaFilterShift + kChromaFilterBits; 67 static constexpr int kComponentRShift = kForceExplicitReconShift + kForceExplicitReconBits; 68 static constexpr int kComponentGShift = kComponentRShift + kComponentBits; 69 static constexpr int kComponentBShift = kComponentGShift + kComponentBits; 70 static constexpr int kComponentAShift = kComponentBShift + kComponentBits; 71 72 static constexpr uint32_t kUseExternalFormatMask = 73 ((1 << kUsesExternalFormatBits) - 1) << kUsesExternalFormatShift; 74 static constexpr uint32_t kYcbcrModelMask = 75 ((1 << kYcbcrModelBits) - 1) << kYcbcrModelShift; 76 static constexpr uint32_t kYcbcrRangeMask = 77 ((1 << kYcbcrRangeBits) - 1) << kYcbcrRangeShift; 78 static constexpr uint32_t kXChromaOffsetMask = 79 ((1 << kXChromaOffsetBits) - 1) << kXChromaOffsetShift; 80 static constexpr uint32_t kYChromaOffsetMask = 81 ((1 << kYChromaOffsetBits) - 1) << kYChromaOffsetShift; 82 static constexpr uint32_t kChromaFilterMask = 83 ((1 << kChromaFilterBits) - 1) << kChromaFilterShift; 84 static constexpr uint32_t kForceExplicitReconMask = 85 ((1 << kForceExplicitReconBits) - 1) << kForceExplicitReconShift; 86 static constexpr uint32_t kComponentRMask = ((1 << kComponentBits) - 1) << kComponentRShift; 87 static constexpr uint32_t kComponentBMask = ((1 << kComponentBits) - 1) << kComponentBShift; 88 static constexpr uint32_t kComponentGMask = ((1 << kComponentBits) - 1) << kComponentGShift; 89 static constexpr uint32_t kComponentAMask = ((1 << kComponentBits) - 1) << kComponentAShift; 90 } // namespace ycbcrUtils 91 #endif // !defined(__EMSCRIPTEN__) 92 93 } // namespace skgpu::graphite 94 95 #endif // skgpu_graphite_DawnGraphiteUtilsPriv_DEFINED 96