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/SkString.h" 12 #include "include/gpu/graphite/dawn/DawnTypes.h" 13 14 namespace skgpu::graphite { 15 16 struct DawnTextureSpec { 17 DawnTextureSpec() = default; DawnTextureSpecDawnTextureSpec18 DawnTextureSpec(const DawnTextureInfo& info) 19 : fFormat(info.fFormat) 20 , fViewFormat(info.fViewFormat) 21 , fUsage(info.fUsage) 22 , fAspect(info.fAspect) 23 #if !defined(__EMSCRIPTEN__) 24 , fYcbcrVkDescriptor(info.fYcbcrVkDescriptor) 25 #endif 26 , fSlice(info.fSlice) { 27 } 28 29 bool operator==(const DawnTextureSpec& that) const { 30 return fUsage == that.fUsage && fFormat == that.fFormat && 31 fViewFormat == that.fViewFormat && fAspect == that.fAspect && 32 #if !defined(__EMSCRIPTEN__) 33 IsEqualToYCbCrVkDescriptorField(that.fYcbcrVkDescriptor) && 34 #endif 35 fSlice == that.fSlice; 36 } 37 isCompatibleDawnTextureSpec38 bool isCompatible(const DawnTextureSpec& that) const { 39 // The usages may match or the usage passed in may be a superset of the usage stored within. 40 // The YCbCrInfo must be equal. 41 // The aspect should either match the plane aspect or should be All. 42 return getViewFormat() == that.getViewFormat() && (fUsage & that.fUsage) == fUsage && 43 #if !defined(__EMSCRIPTEN__) 44 IsEqualToYCbCrVkDescriptorField(that.fYcbcrVkDescriptor) && 45 #endif 46 (fAspect == that.fAspect || fAspect == wgpu::TextureAspect::All); 47 } 48 getViewFormatDawnTextureSpec49 wgpu::TextureFormat getViewFormat() const { 50 return fViewFormat != wgpu::TextureFormat::Undefined ? fViewFormat : fFormat; 51 } 52 53 SkString toString() const; 54 55 wgpu::TextureFormat fFormat = wgpu::TextureFormat::Undefined; 56 // `fViewFormat` is always single plane format or plane view format for a multiplanar 57 // wgpu::Texture. 58 wgpu::TextureFormat fViewFormat = wgpu::TextureFormat::Undefined; 59 wgpu::TextureUsage fUsage = wgpu::TextureUsage::None; 60 wgpu::TextureAspect fAspect = wgpu::TextureAspect::All; 61 #if !defined(__EMSCRIPTEN__) 62 wgpu::YCbCrVkDescriptor fYcbcrVkDescriptor = {}; 63 #endif 64 uint32_t fSlice = 0; 65 66 private: 67 #if !defined(__EMSCRIPTEN__) IsEqualToYCbCrVkDescriptorFieldDawnTextureSpec68 bool IsEqualToYCbCrVkDescriptorField(wgpu::YCbCrVkDescriptor that) const { 69 return fYcbcrVkDescriptor.vkFormat == that.vkFormat && 70 fYcbcrVkDescriptor.vkYCbCrRange == that.vkYCbCrRange && 71 fYcbcrVkDescriptor.vkComponentSwizzleRed == that.vkComponentSwizzleRed && 72 fYcbcrVkDescriptor.vkComponentSwizzleGreen == that.vkComponentSwizzleGreen && 73 fYcbcrVkDescriptor.vkComponentSwizzleBlue == that.vkComponentSwizzleBlue && 74 fYcbcrVkDescriptor.vkComponentSwizzleAlpha == that.vkComponentSwizzleAlpha && 75 fYcbcrVkDescriptor.vkXChromaOffset == that.vkXChromaOffset && 76 fYcbcrVkDescriptor.vkYChromaOffset == that.vkYChromaOffset && 77 fYcbcrVkDescriptor.vkChromaFilter == that.vkChromaFilter && 78 fYcbcrVkDescriptor.forceExplicitReconstruction == that.forceExplicitReconstruction && 79 fYcbcrVkDescriptor.externalFormat == that.externalFormat; 80 } 81 #endif 82 }; 83 84 DawnTextureInfo DawnTextureSpecToTextureInfo(const DawnTextureSpec& dawnSpec, 85 uint32_t sampleCount, 86 Mipmapped mipmapped); 87 88 DawnTextureInfo DawnTextureInfoFromWGPUTexture(WGPUTexture texture); 89 90 } // namespace skgpu::graphite 91 92 #endif // skgpu_graphite_DawnTypesPriv_DEFINED 93