22const char* texture_info_to_label(
const TextureInfo&
info,
23 const DawnTextureSpec& dawnSpec) {
24 if (dawnSpec.fUsage & wgpu::TextureUsage::RenderAttachment) {
26 return "DepthStencil";
28 if (
info.numSamples() > 1) {
29 if (dawnSpec.fUsage & wgpu::TextureUsage::TextureBinding) {
30 return "MSAA SampledTexture-ColorAttachment";
32 return "MSAA ColorAttachment";
35 if (dawnSpec.fUsage & wgpu::TextureUsage::TextureBinding) {
36 return "SampledTexture-ColorAttachment";
38 return "ColorAttachment";
43 SkASSERT(dawnSpec.fUsage & wgpu::TextureUsage::TextureBinding);
44 return "SampledTexture";
55 SKGPU_LOG_E(
"Texture creation failure: dimensions %d x %d too large.",
66 if (dawnSpec.
fUsage & wgpu::TextureUsage::RenderAttachment &&
76 if (
info.mipmapped() == Mipmapped::kYes) {
80 wgpu::TextureDescriptor desc;
82 desc.label = texture_info_to_label(
info, dawnSpec);
84 desc.usage = dawnSpec.
fUsage;
85 desc.dimension = wgpu::TextureDimension::e2D;
88 desc.size.depthOrArrayLayers = 1;
90 desc.mipLevelCount = numMipLevels;
91 desc.sampleCount =
info.numSamples();
92 desc.viewFormatCount = 0;
93 desc.viewFormats =
nullptr;
107 wgpu::TextureView sampleTextureView,
108 wgpu::TextureView renderTextureView,
118 , fSampleTextureView(
std::move(sampleTextureView))
119 , fRenderTextureView(
std::move(renderTextureView)) {}
122std::pair<wgpu::TextureView, wgpu::TextureView> DawnTexture::CreateTextureViews(
123 const wgpu::Texture&
texture,
const TextureInfo&
info) {
124 const auto aspect =
info.dawnTextureSpec().fAspect;
125 if (aspect == wgpu::TextureAspect::All) {
126 wgpu::TextureViewDescriptor viewDesc = {};
127 viewDesc.dimension = wgpu::TextureViewDimension::e2D;
128 viewDesc.baseArrayLayer =
info.dawnTextureSpec().fSlice;
129 viewDesc.arrayLayerCount = 1;
132 if (
info.mipmapped() == Mipmapped::kYes) {
133 viewDesc.baseMipLevel = 0;
134 viewDesc.mipLevelCount = 1;
142#if defined(__EMSCRIPTEN__)
146 SkASSERT(aspect == wgpu::TextureAspect::Plane0Only ||
147 aspect == wgpu::TextureAspect::Plane1Only ||
148 aspect == wgpu::TextureAspect::Plane2Only);
149 wgpu::TextureView planeTextureView;
150 wgpu::TextureViewDescriptor planeViewDesc = {};
151 planeViewDesc.format =
info.dawnTextureSpec().fViewFormat;
152 planeViewDesc.dimension = wgpu::TextureViewDimension::e2D;
153 planeViewDesc.aspect = aspect;
154 planeViewDesc.baseArrayLayer =
info.dawnTextureSpec().fSlice;
155 planeViewDesc.arrayLayerCount = 1;
156 planeTextureView =
texture.CreateView(&planeViewDesc);
157 return {planeTextureView, planeTextureView};
185 SKGPU_LOG_E(
"No valid texture passed into MakeWrapped\n");
203 const wgpu::TextureView& textureView) {
205 SKGPU_LOG_E(
"No valid texture view passed into MakeWrapped\n");
226 fSampleTextureView =
nullptr;
227 fRenderTextureView =
nullptr;
231 const char* dumpName)
const {
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
#define SKGPU_LOG_E(fmt,...)
static int ComputeLevelCount(int baseWidth, int baseHeight)
virtual void dumpStringValue(const char *, const char *, const char *)
bool isTexturable(const TextureInfo &) const
virtual bool isStorage(const TextureInfo &) const =0
virtual bool isRenderable(const TextureInfo &) const =0
int maxTextureSize() const
static sk_sp< Texture > MakeWrapped(const DawnSharedContext *, SkISize dimensions, const TextureInfo &, wgpu::Texture)
static wgpu::Texture MakeDawnTexture(const DawnSharedContext *, SkISize dimensions, const TextureInfo &)
const wgpu::TextureView & renderTextureView() const
const wgpu::TextureView & sampleTextureView() const
static sk_sp< Texture > Make(const DawnSharedContext *, SkISize dimensions, const TextureInfo &, skgpu::Budgeted)
void onDumpMemoryStatistics(SkTraceMemoryDump *traceMemoryDump, const char *dumpName) const override
void freeGpuData() override
skgpu::Budgeted budgeted() const
const SharedContext * sharedContext() const
Ownership ownership() const
const Caps * caps() const
void onDumpMemoryStatistics(SkTraceMemoryDump *traceMemoryDump, const char *dumpName) const override
SkISize dimensions() const
const TextureInfo & textureInfo() const
bool DawnFormatIsDepthOrStencil(wgpu::TextureFormat format)
constexpr int32_t width() const
constexpr int32_t height() const
wgpu::TextureUsage fUsage
wgpu::TextureFormat fFormat