Fix Metal playgrounds for Apple Silicon (flutter/engine#35877)

This commit is contained in:
Brandon DeRosier 2022-09-02 03:36:48 -07:00 committed by GitHub
parent 9439f622fd
commit 5af57a6565
3 changed files with 36 additions and 1 deletions

View File

@ -70,6 +70,7 @@ PlaygroundImplMTL::PlaygroundImplMTL()
data_->metal_layer.device = ContextMTL::Cast(*context).GetMTLDevice();
// This pixel format is one of the documented supported formats.
data_->metal_layer.pixelFormat = ToMTLPixelFormat(PixelFormat::kDefaultColor);
data_->metal_layer.framebufferOnly = NO;
cocoa_window.contentView.layer = data_->metal_layer;
cocoa_window.contentView.wantsLayer = YES;

View File

@ -93,7 +93,6 @@ bool ImGui_ImplImpeller_Init(std::shared_ptr<impeller::Context> context) {
auto desc = impeller::PipelineBuilder<impeller::ImguiRasterVertexShader,
impeller::ImguiRasterFragmentShader>::
MakeDefaultPipelineDescriptor(*context);
desc->SetSampleCount(impeller::SampleCount::kCount4);
auto stencil = desc->GetFrontStencilAttachmentDescriptor();
if (stencil.has_value()) {
stencil->stencil_compare = impeller::CompareFunction::kAlways;

View File

@ -242,9 +242,44 @@ bool Playground::OpenPlaygroundHere(Renderer::RenderCallback render_callback) {
if (render_target.GetColorAttachments().empty()) {
return false;
}
auto color0 = render_target.GetColorAttachments().find(0)->second;
color0.load_action = LoadAction::kLoad;
if (color0.resolve_texture) {
color0.texture = color0.resolve_texture;
color0.resolve_texture = nullptr;
color0.store_action = StoreAction::kStore;
}
render_target.SetColorAttachment(color0, 0);
{
TextureDescriptor stencil0_tex;
stencil0_tex.storage_mode = StorageMode::kDeviceTransient;
stencil0_tex.type = TextureType::kTexture2D;
stencil0_tex.sample_count = SampleCount::kCount1;
stencil0_tex.format = PixelFormat::kDefaultStencil;
stencil0_tex.size = color0.texture->GetSize();
stencil0_tex.usage =
static_cast<TextureUsageMask>(TextureUsage::kRenderTarget);
auto stencil_texture =
renderer->GetContext()->GetResourceAllocator()->CreateTexture(
stencil0_tex);
if (!stencil_texture) {
VALIDATION_LOG << "Could not create stencil texture.";
return false;
}
stencil_texture->SetLabel("ImguiStencil");
StencilAttachment stencil0;
stencil0.texture = stencil_texture;
stencil0.clear_stencil = 0;
stencil0.load_action = LoadAction::kClear;
stencil0.store_action = StoreAction::kDontCare;
render_target.SetStencilAttachment(stencil0);
}
auto pass = buffer->CreateRenderPass(render_target);
if (!pass) {
return false;