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_DawnTypes_DEFINED 9 #define skgpu_graphite_DawnTypes_DEFINED 10 11 #include "include/gpu/graphite/GraphiteTypes.h" 12 #include "webgpu/webgpu_cpp.h" // NO_G3_REWRITE 13 14 namespace skgpu::graphite { 15 16 struct DawnTextureInfo { 17 uint32_t fSampleCount = 1; 18 Mipmapped fMipmapped = Mipmapped::kNo; 19 20 // wgpu::TextureDescriptor properties 21 wgpu::TextureFormat fFormat = wgpu::TextureFormat::Undefined; 22 // `fViewFormat` for multiplanar formats corresponds to the plane TextureView's format. 23 wgpu::TextureFormat fViewFormat = wgpu::TextureFormat::Undefined; 24 wgpu::TextureUsage fUsage = wgpu::TextureUsage::None; 25 // TODO(b/308944094): Migrate aspect information to BackendTextureViews. 26 wgpu::TextureAspect fAspect = wgpu::TextureAspect::All; 27 uint32_t fSlice = 0; 28 29 #if !defined(__EMSCRIPTEN__) 30 // The descriptor of the YCbCr info (if any) for this texture. Dawn's YCbCr 31 // sampling will be used for this texture if this info is set. Setting the 32 // info is supported only on Android and only if using Vulkan as the 33 // underlying GPU driver. 34 wgpu::YCbCrVkDescriptor fYcbcrVkDescriptor = {}; 35 #endif 36 getViewFormatDawnTextureInfo37 wgpu::TextureFormat getViewFormat() const { 38 return fViewFormat != wgpu::TextureFormat::Undefined ? fViewFormat : fFormat; 39 } 40 41 DawnTextureInfo() = default; 42 DawnTextureInfoDawnTextureInfo43 DawnTextureInfo(uint32_t sampleCount, 44 Mipmapped mipmapped, 45 wgpu::TextureFormat format, 46 wgpu::TextureUsage usage, 47 wgpu::TextureAspect aspect) 48 : DawnTextureInfo(sampleCount, 49 mipmapped, 50 /*format=*/format, 51 /*viewFormat=*/format, 52 usage, 53 aspect, 54 /*slice=*/0) {} 55 DawnTextureInfoDawnTextureInfo56 DawnTextureInfo(uint32_t sampleCount, 57 Mipmapped mipmapped, 58 wgpu::TextureFormat format, 59 wgpu::TextureFormat viewFormat, 60 wgpu::TextureUsage usage, 61 wgpu::TextureAspect aspect, 62 uint32_t slice) 63 : fSampleCount(sampleCount) 64 , fMipmapped(mipmapped) 65 , fFormat(format) 66 , fViewFormat(viewFormat) 67 , fUsage(usage) 68 , fAspect(aspect) 69 , fSlice(slice) {} 70 71 #if !defined(__EMSCRIPTEN__) DawnTextureInfoDawnTextureInfo72 DawnTextureInfo(uint32_t sampleCount, 73 Mipmapped mipmapped, 74 wgpu::TextureFormat format, 75 wgpu::TextureFormat viewFormat, 76 wgpu::TextureUsage usage, 77 wgpu::TextureAspect aspect, 78 uint32_t slice, 79 wgpu::YCbCrVkDescriptor ycbcrVkDescriptor) 80 : fSampleCount(sampleCount) 81 , fMipmapped(mipmapped) 82 , fFormat(format) 83 , fViewFormat(viewFormat) 84 , fUsage(usage) 85 , fAspect(aspect) 86 , fSlice(slice) 87 , fYcbcrVkDescriptor(ycbcrVkDescriptor) {} 88 #endif 89 }; 90 91 } // namespace skgpu::graphite 92 93 #endif // skgpu_graphite_DawnTypes_DEFINED 94 95 96