| 1 |
/* |
| 2 |
* Copyright 2024 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 |
#include "include/core/SkStream.h" |
| 8 |
#include "include/core/SkString.h" |
| 9 |
#include "include/gpu/graphite/dawn/DawnGraphiteTypes.h" |
| 10 |
#include "src/gpu/graphite/TextureInfoPriv.h" |
| 11 |
#include "src/gpu/graphite/dawn/DawnGraphiteUtils.h" |
| 12 |
|
| 13 |
#include <cstdint> |
| 14 |
|
| 15 |
namespace skgpu::graphite { |
| 16 |
|
| 17 |
DawnTextureInfo::DawnTextureInfo(WGPUTexture texture) |
| 18 |
: DawnTextureInfo( |
| 19 |
ToSampleCount(wgpuTextureGetSampleCount(texture)), |
| 20 |
wgpuTextureGetMipLevelCount(texture) > 1 ? Mipmapped::kYes : Mipmapped::kNo, |
| 21 |
/*format=*/static_cast<wgpu::TextureFormat>(wgpuTextureGetFormat(texture)), |
| 22 |
/*viewFormat=*/static_cast<wgpu::TextureFormat>(wgpuTextureGetFormat(texture)), |
| 23 |
static_cast<wgpu::TextureUsage>(wgpuTextureGetUsage(texture)), |
| 24 |
wgpu::TextureAspect::All, |
| 25 |
/*slice=*/0) {} |
| 26 |
|
| 27 |
TextureFormat DawnTextureInfo::viewFormat() const { |
| 28 |
#if !defined(__EMSCRIPTEN__) |
| 29 |
if (fYcbcrVkDescriptor.externalFormat != 0) { |
| 30 |
return TextureFormat::kExternal; |
| 31 |
} |
| 32 |
#endif |
| 33 |
return DawnFormatToTextureFormat(this->getViewFormat()); |
| 34 |
} |
| 35 |
|
| 36 |
SkString DawnTextureInfo::toBackendString() const { |
| 37 |
return SkStringPrintf("wgpuFormat=%u,usage=0x%08X,aspect=0x%08X,slice=%u", |
| 38 |
static_cast<unsigned int>(fFormat), |
| 39 |
static_cast<unsigned int>(fUsage), |
| 40 |
static_cast<unsigned int>(fAspect), |
| 41 |
fSlice); |
| 42 |
} |
| 43 |
|
| 44 |
bool DawnTextureInfo::isCompatible(const TextureInfo& that, bool requireExact) const { |
| 45 |
const auto& dt = TextureInfoPriv::Get<DawnTextureInfo>(that); |
| 46 |
|
| 47 |
// The usages may match or the usage passed in may be a superset of the usage stored within. The |
| 48 |
// YCbCrInfo must be equal. The aspect should either match the plane aspect or should be All. |
| 49 |
return this->getViewFormat() == dt.getViewFormat() && |
| 50 |
(fUsage & dt.fUsage) == fUsage && |
| 51 |
#if !defined(__EMSCRIPTEN__) |
| 52 |
DawnDescriptorsAreEquivalent(fYcbcrVkDescriptor, dt.fYcbcrVkDescriptor) && |
| 53 |
#endif |
| 54 |
(fAspect == dt.fAspect || (!requireExact && fAspect == wgpu::TextureAspect::All)); |
| 55 |
} |
| 56 |
|
| 57 |
namespace TextureInfos { |
| 58 |
|
| 59 |
TextureInfo MakeDawn(const DawnTextureInfo& dawnInfo) { |
| 60 |
return TextureInfoPriv::Make(dawnInfo); |
| 61 |
} |
| 62 |
|
| 63 |
bool GetDawnTextureInfo(const TextureInfo& info, DawnTextureInfo* out) { |
| 64 |
return TextureInfoPriv::Copy(info, out); |
| 65 |
} |
| 66 |
|
| 67 |
} // namespace TextureInfos |
| 68 |
|
| 69 |
} // namespace skgpu::graphite |