Skip to content
This repository has been archived by the owner on Feb 25, 2025. It is now read-only.

[Impeller] Encode directly to command buffer for Vulkan. #49780

Merged
merged 15 commits into from
Jan 16, 2024

Conversation

jonahwilliams
Copy link
Member

@jonahwilliams jonahwilliams commented Jan 13, 2024

Part of flutter/flutter#140804

Rather than using impeller::Command, the impeller::RenderPass records most state directly into the Vulkan command buffer. This should remove allocation/free overhead of the intermediary structures and make further improvements to the backend even easier. This required a number of other changes to the renderer:

  1. The render pass holds a strong ptr to the context. This helps avoid locking continually while encoding, which is quite slow.
  2. barriers need to be encoded on the producing side, and not the consuming side. This is because we'll actually run the consuming code before the producing code. i.e. we transition to shader read at the end of a render pass instead of when binding.
  3. I've updated the binding code to also provide the descriptor type so that we don't need to look it up from the desc. set.
  4. I added a test render pass class that records commands.

@jonahwilliams jonahwilliams changed the title Direct encoding vulkan [Impeller] Encode directly to command buffer. Jan 13, 2024
@@ -161,7 +161,7 @@ struct {{camel_case(shader_name)}}{{camel_case(shader_stage)}}Shader {
{% endfor %}) {
return {{ proto.args.0.argument_name }}.BindResource({% for arg in proto.args %}
{% if loop.is_first %}
{{to_shader_stage(shader_stage)}}, kResource{{ proto.name }}, kMetadata{{ proto.name }}, {% else %}
{{to_shader_stage(shader_stage)}}, {{ proto.descriptor_type }}, kResource{{ proto.name }}, kMetadata{{ proto.name }}, {% else %}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the descriptor type so that bind calls don't need to look up the layout information to determine if a BufferView is a uniform buffer or storage buffer.

@jonahwilliams jonahwilliams changed the title [Impeller] Encode directly to command buffer. [Impeller] Encode directly to command buffer for Vulkan. Jan 14, 2024
@jonahwilliams jonahwilliams force-pushed the direct_encoding_vulkan branch from caffebc to dbaf4e4 Compare January 16, 2024 06:18
@jonahwilliams jonahwilliams marked this pull request as ready for review January 16, 2024 06:49

namespace impeller {

RecordingRenderPass::RecordingRenderPass(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a test only class that lets us inspect individual commands.

@@ -199,61 +248,87 @@ SharedHandleVK<vk::RenderPass> RenderPassVK::CreateVKRenderPass(

RenderPassVK::RenderPassVK(const std::shared_ptr<const Context>& context,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the pass bindings cache is mostly removed, as I was not able to measure a performance improvement from it.

Copy link
Member

@bdero bdero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

render_pass_->BindResource(impeller::ShaderStage::kVertex, texture.slot,
*texture.texture.GetMetadata(),
render_pass_->BindResource(impeller::ShaderStage::kVertex,
impeller::DescriptorType::kUniformBuffer,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
impeller::DescriptorType::kUniformBuffer,
impeller::DescriptorType::kSampledImage,

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

render_pass_->BindResource(impeller::ShaderStage::kFragment, buffer.slot,
*buffer.view.GetMetadata(),
render_pass_->BindResource(impeller::ShaderStage::kFragment,
impeller::DescriptorType::kSampledImage,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
impeller::DescriptorType::kSampledImage,
impeller::DescriptorType::kUniformBuffer,

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


const auto& cmd = render_pass->GetCommands()[0];
const auto& cmd = recording_pass->GetCommands()[0];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: assert command list is not empty before indexing

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

return delegate_->BindResource(stage, type, slot, metadata, texture, sampler);
}

} // namespace impeller
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} // namespace impeller
} // namespace impeller

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -25,20 +25,92 @@ class RenderPassVK final : public RenderPass {
private:
friend class CommandBufferVK;

std::weak_ptr<CommandBufferVK> command_buffer_;
std::shared_ptr<CommandBufferVK> command_buffer_;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this just to remove weak check churn?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, locking weak ptrs is actually very espensive. Since the RenderPass is immediately doing the recording and using the ContextVK to allocate descriptor sets, it would potentially lock multiple times per command otherwise.

@jonahwilliams jonahwilliams added the autosubmit Merge PR when tree becomes green via auto submit App label Jan 16, 2024
@auto-submit auto-submit bot merged commit 602c354 into flutter:main Jan 16, 2024
26 checks passed
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Jan 17, 2024
…141651)

flutter/engine@d4b6b7e...021a5ff

2024-01-16 [email protected] [web] Leave blob URLs untouched in TT policy. (flutter/engine#49782)
2024-01-16 [email protected] [Impeller] Fix a race between SwapchainImplVK::Present and WaitForFence (flutter/engine#49777)
2024-01-16 [email protected] Reland "[Windows] Move to FlutterCompositor for rendering" (flutter/engine#49726)
2024-01-16 [email protected] [Impeller] Add an API for sampling strictly within the bounds of the source rect in DrawImageRect (flutter/engine#49696)
2024-01-16 [email protected] [Impeller] Encode directly to command buffer for Vulkan. (flutter/engine#49780)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
@jonahwilliams jonahwilliams added the revert Label used to revert changes in a closed and merged pull request. label Jan 17, 2024
@jonahwilliams
Copy link
Member Author

Reverting as this broke the query pool reset and is breaking the framework tree.

auto-submit bot pushed a commit that referenced this pull request Jan 17, 2024
@auto-submit auto-submit bot removed the revert Label used to revert changes in a closed and merged pull request. label Jan 17, 2024
auto-submit bot added a commit that referenced this pull request Jan 17, 2024
…49818)

Reverts #49780
Initiated by: jonahwilliams
This change reverts the following previous change:
Original Description:
Part of flutter/flutter#140804

Rather than using impeller::Command, the impeller::RenderPass records most state directly into the Vulkan command buffer. This should remove allocation/free overhead of the intermediary structures and make further improvements to the backend even easier. This required a number of other changes to the renderer:

1. The render pass holds a strong ptr to the context. This helps avoid locking continually while encoding, which is quite slow.
2. barriers need to be encoded on the _producing_ side, and not the consuming side. This is because we'll actually run the consuming code before the producing code. i.e. we transition to shader read at the end of a render pass instead of when binding.
3. I've updated the binding code to also provide the descriptor type so that we don't need to look it up from the desc. set.
4. I added a test render pass class that records commands.
auto-submit bot added a commit to flutter/flutter that referenced this pull request Jan 17, 2024
…isions)" (#141659)

Reverts #141651
Initiated by: jonahwilliams
This change reverts the following previous change:
Original Description:

flutter/engine@d4b6b7e...021a5ff

2024-01-16 [email protected] [web] Leave blob URLs untouched in TT policy. (flutter/engine#49782)
2024-01-16 [email protected] [Impeller] Fix a race between SwapchainImplVK::Present and WaitForFence (flutter/engine#49777)
2024-01-16 [email protected] Reland "[Windows] Move to FlutterCompositor for rendering" (flutter/engine#49726)
2024-01-16 [email protected] [Impeller] Add an API for sampling strictly within the bounds of the source rect in DrawImageRect (flutter/engine#49696)
2024-01-16 [email protected] [Impeller] Encode directly to command buffer for Vulkan. (flutter/engine#49780)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Jan 17, 2024
…141664)

flutter/engine@d4b6b7e...1382ff7

2024-01-16 [email protected] Remove iOS 12 availability checks (flutter/engine#49771)
2024-01-16 [email protected] [Impeller] generate mipmaps for imagefilters (flutter/engine#49794)
2024-01-16 [email protected] [web] Leave blob URLs untouched in TT policy. (flutter/engine#49782)
2024-01-16 [email protected] [Impeller] Fix a race between SwapchainImplVK::Present and WaitForFence (flutter/engine#49777)
2024-01-16 [email protected] Reland "[Windows] Move to FlutterCompositor for rendering" (flutter/engine#49726)
2024-01-16 [email protected] [Impeller] Add an API for sampling strictly within the bounds of the source rect in DrawImageRect (flutter/engine#49696)
2024-01-16 [email protected] [Impeller] Encode directly to command buffer for Vulkan. (flutter/engine#49780)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
autosubmit Merge PR when tree becomes green via auto submit App e: impeller
Projects
No open projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

2 participants