This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
[Impeller] Document impeller::Context.
#43389
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,31 +19,121 @@ class CommandBuffer; | |
| class PipelineLibrary; | ||
| class Allocator; | ||
|
|
||
| //------------------------------------------------------------------------------ | ||
| /// @brief Do do anything rendering related with Impeller, you need a | ||
| /// context. | ||
| /// | ||
| /// Contexts are expensive to construct and typically you only need | ||
| /// one in the process. The context represents a connection to a | ||
| /// graphics or compute accelerator on the device. | ||
| /// | ||
| /// If there are multiple context in a process, it would typically | ||
| /// be for separation of concerns (say, use with multiple engines in | ||
| /// Flutter), talking to multiple accelerators, or talking to the | ||
| /// same accelerator using different client APIs (Metal, Vulkan, | ||
| /// OpenGL ES, etc..). | ||
| /// | ||
| /// Contexts are thread-safe. They may be created, used, and | ||
|
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. There is a small caveat here in that they may still need to be destructed on the thread they were created from, at least as long as they own their own concurrent worker loop.
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. actually, I guess not on the thread it was constructed on - just not on a worker thread from an internal pool
Member
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. Added the clarification. |
||
| /// collected on any thread. They may also be accessed | ||
| /// simultaneously from multiple threads. | ||
| /// | ||
| /// Contexts are abstract and a concrete instance must be created | ||
| /// using one of the subclasses of `Context` in | ||
| /// `//impeller/renderer/backend`. | ||
| class Context { | ||
| public: | ||
| //---------------------------------------------------------------------------- | ||
| /// @brief Destroys an Impeller context. | ||
| /// | ||
| virtual ~Context(); | ||
|
|
||
| // TODO(129920): Refactor and move to capabilities. | ||
| virtual std::string DescribeGpuModel() const = 0; | ||
|
|
||
| //---------------------------------------------------------------------------- | ||
| /// @brief Determines if a context is valid. If the caller ever receives | ||
| /// an invalid context, they must discard it and construct a new | ||
| /// context. There is no recovery mechanism to repair a bad | ||
| /// context. | ||
| /// | ||
| /// It is convention in Impeller to never return an invalid | ||
| /// context from a call that returns an pointer to a context. The | ||
| /// call implementation performs validity checks itself and return | ||
| /// a null context instead of a pointer to an invalid context. | ||
| /// | ||
| /// How a context goes invalid is backend specific. It could | ||
| /// happen due to device loss, or any other unrecoverable error. | ||
| /// | ||
| /// @return If the context is valid. | ||
| /// | ||
| virtual bool IsValid() const = 0; | ||
|
|
||
| //---------------------------------------------------------------------------- | ||
| /// @brief Get the capabilities of Impeller context. All optionally | ||
| /// supported feature of the platform, client-rendering API, and | ||
| /// device can be queried using the `Capabilities`. | ||
| /// | ||
| /// @return The capabilities. Can never be `nullptr` for a valid context. | ||
| /// | ||
| virtual const std::shared_ptr<const Capabilities>& GetCapabilities() | ||
| const = 0; | ||
|
|
||
| // TODO(129920): Refactor and move to capabilities. | ||
| virtual bool UpdateOffscreenLayerPixelFormat(PixelFormat format); | ||
|
|
||
| //---------------------------------------------------------------------------- | ||
| /// @brief Returns the allocator used to create textures and buffers on | ||
| /// the device. | ||
| /// | ||
| /// @return The resource allocator. Can never be `nullptr` for a valid | ||
| /// context. | ||
| /// | ||
| virtual std::shared_ptr<Allocator> GetResourceAllocator() const = 0; | ||
|
|
||
| //---------------------------------------------------------------------------- | ||
| /// @brief Returns the library of shaders used to specify the | ||
| /// programmable stages of a pipeline. | ||
| /// | ||
| /// @return The shader library. Can never be `nullptr` for a valid | ||
| /// context. | ||
| /// | ||
| virtual std::shared_ptr<ShaderLibrary> GetShaderLibrary() const = 0; | ||
|
|
||
| //---------------------------------------------------------------------------- | ||
| /// @brief Returns the library of combined image samplers used in | ||
| /// shaders. | ||
| /// | ||
| /// @return The sampler library. Can never be `nullptr` for a valid | ||
| /// context. | ||
| /// | ||
| virtual std::shared_ptr<SamplerLibrary> GetSamplerLibrary() const = 0; | ||
|
|
||
| //---------------------------------------------------------------------------- | ||
| /// @brief Returns the library of pipelines used by render or compute | ||
| /// commands. | ||
| /// | ||
| /// @return The pipeline library. Can never be `nullptr` for a valid | ||
| /// context. | ||
| /// | ||
| virtual std::shared_ptr<PipelineLibrary> GetPipelineLibrary() const = 0; | ||
|
|
||
| //---------------------------------------------------------------------------- | ||
| /// @brief Create a new command buffer. Command buffers can be used to | ||
| /// encode graphics, blit, or compute commands to be submitted to | ||
| /// the device. | ||
| /// | ||
| /// A command buffer can only be used on a single thread. | ||
| /// Multi-threaded render, blit, or compute passes must create a | ||
| /// new command buffer on each thread. | ||
| /// | ||
| /// @return A new command buffer. | ||
| /// | ||
| virtual std::shared_ptr<CommandBuffer> CreateCommandBuffer() const = 0; | ||
|
|
||
| /// @brief Force all pending async work to finish by deleting any owned | ||
| /// concurrent message loops. | ||
| //---------------------------------------------------------------------------- | ||
| /// @brief Force all pending asynchronous work to finish. This is | ||
| /// achieved by deleting all owned concurrent message loops. | ||
| /// | ||
| virtual void Shutdown() = 0; | ||
|
|
||
| protected: | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nit: dodo
Uh oh!
There was an error while loading. Please reload this page.
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.