-
Notifications
You must be signed in to change notification settings - Fork 6k
[Impeller] Encode directly to command buffer for Metal. #49785
Changes from 7 commits
f8d98b1
26e4d6e
e504245
c8ccb10
bdd499c
d651b88
3fa0a9a
4e31962
087d202
cd5901c
403e151
8818531
be04fa0
3470e36
2d59557
275f9c7
411676d
fce4518
b0ac5ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,64 @@ | |
|
|
||
| namespace impeller { | ||
|
|
||
| //----------------------------------------------------------------------------- | ||
| /// @brief Ensures that bindings on the pass are not redundantly set or | ||
| /// updated. Avoids making the driver do additional checks and makes | ||
| /// the frame insights during profiling and instrumentation not | ||
| /// complain about the same. | ||
| /// | ||
| /// There should be no change to rendering if this caching was | ||
| /// absent. | ||
| /// | ||
| struct PassBindingsCache { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move to its own TU and rename as
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
| explicit PassBindingsCache() {} | ||
|
|
||
| ~PassBindingsCache() = default; | ||
|
|
||
| PassBindingsCache(const PassBindingsCache&) = delete; | ||
|
|
||
| PassBindingsCache(PassBindingsCache&&) = delete; | ||
|
|
||
| void SetEncoder(id<MTLRenderCommandEncoder> encoder); | ||
|
|
||
| void SetRenderPipelineState(id<MTLRenderPipelineState> pipeline); | ||
|
|
||
| void SetDepthStencilState(id<MTLDepthStencilState> depth_stencil); | ||
|
|
||
| bool SetBuffer(ShaderStage stage, | ||
| uint64_t index, | ||
| uint64_t offset, | ||
| id<MTLBuffer> buffer); | ||
|
|
||
| bool SetTexture(ShaderStage stage, uint64_t index, id<MTLTexture> texture); | ||
|
|
||
| bool SetSampler(ShaderStage stage, | ||
| uint64_t index, | ||
| id<MTLSamplerState> sampler); | ||
|
|
||
| void SetViewport(const Viewport& viewport); | ||
|
|
||
| void SetScissor(const IRect& scissor); | ||
|
|
||
| private: | ||
| struct BufferOffsetPair { | ||
| id<MTLBuffer> buffer = nullptr; | ||
| size_t offset = 0u; | ||
| }; | ||
| using BufferMap = std::map<uint64_t, BufferOffsetPair>; | ||
| using TextureMap = std::map<uint64_t, id<MTLTexture>>; | ||
| using SamplerMap = std::map<uint64_t, id<MTLSamplerState>>; | ||
|
|
||
| id<MTLRenderCommandEncoder> encoder_; | ||
| id<MTLRenderPipelineState> pipeline_ = nullptr; | ||
| id<MTLDepthStencilState> depth_stencil_ = nullptr; | ||
| std::map<ShaderStage, BufferMap> buffers_; | ||
| std::map<ShaderStage, TextureMap> textures_; | ||
| std::map<ShaderStage, SamplerMap> samplers_; | ||
| std::optional<Viewport> viewport_; | ||
| std::optional<IRect> scissor_; | ||
| }; | ||
|
|
||
| class RenderPassMTL final : public RenderPass { | ||
| public: | ||
| // |RenderPass| | ||
|
|
@@ -22,14 +80,31 @@ class RenderPassMTL final : public RenderPass { | |
| friend class CommandBufferMTL; | ||
|
|
||
| id<MTLCommandBuffer> buffer_ = nil; | ||
| id<MTLRenderCommandEncoder> encoder_ = nil; | ||
| MTLRenderPassDescriptor* desc_ = nil; | ||
| std::string label_; | ||
| bool is_metal_trace_active_ = false; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TODO: this
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
| bool is_valid_ = false; | ||
|
|
||
| PassBindingsCache pass_bindings_; | ||
|
|
||
| // Per-command state | ||
| size_t instance_count_ = 1u; | ||
| size_t base_vertex_ = 0u; | ||
| size_t vertex_count_ = 0u; | ||
| bool has_valid_pipeline_ = false; | ||
| bool has_label_ = false; | ||
| BufferView index_buffer_; | ||
| PrimitiveType primitive_type_; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Default this ivars.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
| MTLIndexType index_type_; | ||
|
|
||
| RenderPassMTL(std::shared_ptr<const Context> context, | ||
| const RenderTarget& target, | ||
| id<MTLCommandBuffer> buffer); | ||
|
|
||
| // |RenderPass| | ||
| void ReserveCommands(size_t command_count) override {} | ||
|
|
||
| // |RenderPass| | ||
| bool IsValid() const override; | ||
|
|
||
|
|
@@ -39,8 +114,55 @@ class RenderPassMTL final : public RenderPass { | |
| // |RenderPass| | ||
| bool OnEncodeCommands(const Context& context) const override; | ||
|
|
||
| bool EncodeCommands(const std::shared_ptr<Allocator>& transients_allocator, | ||
| id<MTLRenderCommandEncoder> pass) const; | ||
| // |RenderPass| | ||
| void SetPipeline( | ||
| const std::shared_ptr<Pipeline<PipelineDescriptor>>& pipeline) override; | ||
|
|
||
| // |RenderPass| | ||
| void SetCommandLabel(std::string_view label) override; | ||
|
|
||
| // |RenderPass| | ||
| void SetStencilReference(uint32_t value) override; | ||
|
|
||
| // |RenderPass| | ||
| void SetBaseVertex(uint64_t value) override; | ||
|
|
||
| // |RenderPass| | ||
| void SetViewport(Viewport viewport) override; | ||
|
|
||
| // |RenderPass| | ||
| void SetScissor(IRect scissor) override; | ||
|
|
||
| // |RenderPass| | ||
| void SetInstanceCount(size_t count) override; | ||
|
|
||
| // |RenderPass| | ||
| bool SetVertexBuffer(VertexBuffer buffer) override; | ||
|
|
||
| // |RenderPass| | ||
| fml::Status Draw() override; | ||
|
|
||
| // |RenderPass| | ||
| bool BindResource(ShaderStage stage, | ||
| DescriptorType type, | ||
| const ShaderUniformSlot& slot, | ||
| const ShaderMetadata& metadata, | ||
| BufferView view) override; | ||
|
|
||
| // |RenderPass| | ||
| bool BindResource(ShaderStage stage, | ||
| DescriptorType type, | ||
| const ShaderUniformSlot& slot, | ||
| const std::shared_ptr<const ShaderMetadata>& metadata, | ||
| BufferView view) override; | ||
|
|
||
| // |RenderPass| | ||
| bool BindResource(ShaderStage stage, | ||
| DescriptorType type, | ||
| const SampledImageSlot& slot, | ||
| const ShaderMetadata& metadata, | ||
| std::shared_ptr<const Texture> texture, | ||
| std::shared_ptr<const Sampler> sampler) override; | ||
|
|
||
| RenderPassMTL(const RenderPassMTL&) = delete; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Get rid of the corresponding Foundation.h header import above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done