From 1b830f9c82aa4801b8f2a8ea58b015d667484f4a Mon Sep 17 00:00:00 2001 From: Chinmay Garde Date: Thu, 15 Jul 2021 12:31:31 -0700 Subject: [PATCH] Wire up texture usage. --- engine/src/flutter/impeller/compositor/BUILD.gn | 2 +- engine/src/flutter/impeller/compositor/formats.h | 9 +++++++++ .../flutter/impeller/compositor/formats_metal.mm | 13 +++++++++++++ .../impeller/compositor/texture_descriptor.h | 2 ++ engine/src/flutter/impeller/playground/BUILD.gn | 2 +- 5 files changed, 26 insertions(+), 2 deletions(-) diff --git a/engine/src/flutter/impeller/compositor/BUILD.gn b/engine/src/flutter/impeller/compositor/BUILD.gn index 1b15d184f31..0a9c708e14d 100644 --- a/engine/src/flutter/impeller/compositor/BUILD.gn +++ b/engine/src/flutter/impeller/compositor/BUILD.gn @@ -73,7 +73,7 @@ impeller_component("compositor") { "../shader_glue", ] - libs = [ "Metal.framework" ] + frameworks = [ "Metal.framework" ] } source_set("compositor_unittests") { diff --git a/engine/src/flutter/impeller/compositor/formats.h b/engine/src/flutter/impeller/compositor/formats.h index 711d1684565..6de3d173be7 100644 --- a/engine/src/flutter/impeller/compositor/formats.h +++ b/engine/src/flutter/impeller/compositor/formats.h @@ -59,6 +59,15 @@ enum class StoreAction { kStore, }; +using TextureUsageMask = uint64_t; + +enum class TextureUsage : TextureUsageMask { + kUnknown, + kShaderRead, + kShaderWrite, + kRenderTarget, +}; + enum class PrimitiveType { kTriangle, kTriangleStrip, diff --git a/engine/src/flutter/impeller/compositor/formats_metal.mm b/engine/src/flutter/impeller/compositor/formats_metal.mm index cef3c06ba67..d0bffb5b79f 100644 --- a/engine/src/flutter/impeller/compositor/formats_metal.mm +++ b/engine/src/flutter/impeller/compositor/formats_metal.mm @@ -83,6 +83,19 @@ MTLTextureDescriptor* ToMTLTextureDescriptor(const TextureDescriptor& desc) { mtl_desc.width = desc.size.width; mtl_desc.height = desc.size.height; mtl_desc.mipmapLevelCount = desc.mip_count; + mtl_desc.usage = MTLTextureUsageUnknown; + if (desc.usage & static_cast(TextureUsage::kUnknown)) { + mtl_desc.usage |= MTLTextureUsageUnknown; + } + if (desc.usage & static_cast(TextureUsage::kShaderRead)) { + mtl_desc.usage |= MTLTextureUsageShaderRead; + } + if (desc.usage & static_cast(TextureUsage::kShaderWrite)) { + mtl_desc.usage |= MTLTextureUsageShaderWrite; + } + if (desc.usage & static_cast(TextureUsage::kRenderTarget)) { + mtl_desc.usage |= MTLTextureUsageRenderTarget; + } return mtl_desc; } diff --git a/engine/src/flutter/impeller/compositor/texture_descriptor.h b/engine/src/flutter/impeller/compositor/texture_descriptor.h index 07e52ca645b..fc647cbbb93 100644 --- a/engine/src/flutter/impeller/compositor/texture_descriptor.h +++ b/engine/src/flutter/impeller/compositor/texture_descriptor.h @@ -16,6 +16,8 @@ struct TextureDescriptor { PixelFormat format = PixelFormat::kUnknown; ISize size; size_t mip_count = 1u; // Size::MipCount is usually appropriate. + TextureUsageMask usage = + static_cast(TextureUsage::kShaderRead); constexpr size_t GetSizeOfBaseMipLevel() const { if (!IsValid()) { diff --git a/engine/src/flutter/impeller/playground/BUILD.gn b/engine/src/flutter/impeller/playground/BUILD.gn index 0a912bef5d8..5c142a125c8 100644 --- a/engine/src/flutter/impeller/playground/BUILD.gn +++ b/engine/src/flutter/impeller/playground/BUILD.gn @@ -20,7 +20,7 @@ impeller_component("playground") { ] if (is_mac) { - libs = [ + frameworks = [ "AppKit.framework", "QuartzCore.framework", ]