5#include "flutter/lib/gpu/render_pass.h"
7#include "flutter/lib/gpu/formats.h"
8#include "flutter/lib/gpu/render_pipeline.h"
9#include "flutter/lib/gpu/shader.h"
32 return render_pass_->GetContext();
44 return render_target_;
48 return render_target_;
52 size_t color_attachment_index) {
53 auto color = color_descriptors_.find(color_attachment_index);
54 if (
color == color_descriptors_.end()) {
55 return color_descriptors_[color_attachment_index] = {};
66 return vertex_buffer_;
80 render_pipeline_ = std::move(pipeline);
83std::shared_ptr<impeller::Pipeline<impeller::PipelineDescriptor>>
86 auto pipeline_desc = pipeline_descriptor_;
91 pipeline_desc.SetColorAttachmentDescriptors(color_descriptors_);
96 stencil->texture->GetTextureDescriptor().format)) {
97 pipeline_desc.SetStencilPixelFormat(
98 stencil->texture->GetTextureDescriptor().format);
99 pipeline_desc.SetStencilAttachmentDescriptors(stencil_front_desc_,
102 pipeline_desc.ClearStencilAttachments();
109 depth->texture->GetTextureDescriptor().format)) {
110 pipeline_desc.SetDepthPixelFormat(
111 depth->texture->GetTextureDescriptor().format);
112 pipeline_desc.SetDepthStencilAttachmentDescriptor(depth_desc_);
114 pipeline_desc.ClearDepthAttachment();
120 render_pipeline_->BindToPipelineDescriptor(*context.GetShaderLibrary(),
124 context.GetPipelineLibrary()->GetPipeline(pipeline_desc).Get();
125 FML_DCHECK(pipeline) <<
"Couldn't resolve render pipeline";
133 result.BindVertices(vertex_buffer_);
141 render_pass_->SetCommandLabel(
result.label);
143 render_pass_->SetPipeline(
result.pipeline);
144 render_pass_->SetStencilReference(
result.stencil_reference);
145 render_pass_->SetBaseVertex(
result.base_vertex);
146 if (
result.viewport.has_value()) {
147 render_pass_->SetViewport(
result.viewport.value());
149 if (
result.scissor.has_value()) {
150 render_pass_->SetScissor(
result.scissor.value());
152 render_pass_->SetVertexBuffer(
result.vertex_buffer);
153 for (
const auto&
buffer :
result.vertex_bindings.buffers) {
159 for (
const auto&
texture :
result.vertex_bindings.sampled_images) {
165 for (
const auto&
buffer :
result.fragment_bindings.buffers) {
171 for (
const auto&
texture :
result.fragment_bindings.sampled_images) {
177 return render_pass_->Draw().ok();
195 auto res = fml::MakeRefCounted<flutter::gpu::RenderPass>();
196 res->AssociateWithDartWrapper(wrapper);
201 int color_attachment_index,
215 resolve_texture_wrapper);
224 int depth_load_action,
225 int depth_store_action,
226 float depth_clear_value,
227 int stencil_load_action,
228 int stencil_store_action,
229 int stencil_clear_value,
235 desc.clear_depth = depth_clear_value;
244 desc.clear_stencil = stencil_clear_value;
255 if (!wrapper->
Begin(*command_buffer)) {
268template <
typename TBuffer>
288 vertex_buffer.vertex_count = vertex_count;
299 length_in_bytes, vertex_count);
308 std::optional<impeller::BufferView> view =
310 if (!view.has_value()) {
312 <<
"Failed to bind vertex buffer due to invalid HostBuffer offset: "
317 view->range.length, vertex_count);
320template <
typename TBuffer>
333 vertex_buffer.vertex_count = index_count;
344 length_in_bytes, index_type, index_count);
355 if (!view.has_value()) {
357 <<
"Failed to bind index buffer due to invalid HostBuffer offset: "
361 BindIndexBuffer(wrapper, view->buffer, view->range.offset, view->range.length,
362 index_type, index_count);
365template <
typename TBuffer>
371 int length_in_bytes) {
379 if (!uniform_struct) {
388 .range = impeller::Range(offset_in_bytes, length_in_bytes),
398 int length_in_bytes) {
399 return BindUniform(wrapper, shader, uniform_name_handle,
400 device_buffer->
GetBuffer(), offset_in_bytes,
410 int length_in_bytes) {
412 if (!view.has_value()) {
414 <<
"Failed to bind index buffer due to invalid HostBuffer offset: "
418 return BindUniform(wrapper, shader, uniform_name_handle, view->buffer,
419 view->range.offset, view->range.length);
430 int width_address_mode,
431 int height_address_mode) {
451 const std::unique_ptr<const impeller::Sampler>& sampler =
452 wrapper->
GetContext()->GetSamplerLibrary()->GetSampler(sampler_desc);
464 command.fragment_bindings = {};
469 int color_attachment_index,
472 color.blending_enabled = enable;
477 int color_attachment_index,
478 int color_blend_operation,
479 int source_color_blend_factor,
480 int destination_color_blend_factor,
481 int alpha_blend_operation,
482 int source_alpha_blend_factor,
483 int destination_alpha_blend_factor) {
485 color.color_blend_op =
487 color.src_color_blend_factor =
489 color.dst_color_blend_factor =
491 color.alpha_blend_op =
493 color.src_alpha_blend_factor =
495 color.dst_alpha_blend_factor =
508 int compare_operation) {
515 return wrapper->
Draw();
std::shared_ptr< impeller::CommandBuffer > GetCommandBuffer()
void AddRenderPass(std::shared_ptr< impeller::RenderPass > render_pass)
std::shared_ptr< impeller::DeviceBuffer > GetBuffer()
std::optional< impeller::BufferView > GetBufferViewForOffset(size_t offset)
impeller::Command & GetCommand()
void SetPipeline(fml::RefPtr< RenderPipeline > pipeline)
impeller::RenderTarget & GetRenderTarget()
bool Begin(flutter::gpu::CommandBuffer &command_buffer)
std::shared_ptr< impeller::Pipeline< impeller::PipelineDescriptor > > GetOrCreatePipeline()
impeller::DepthAttachmentDescriptor & GetDepthAttachmentDescriptor()
impeller::Command ProvisionRasterCommand()
impeller::VertexBuffer & GetVertexBuffer()
impeller::ColorAttachmentDescriptor & GetColorAttachmentDescriptor(size_t color_attachment_index)
const std::shared_ptr< const impeller::Context > & GetContext() const
An immutable collection of shaders loaded from a shader bundle asset.
const Shader::UniformBinding * GetUniformStruct(const std::string &name) const
impeller::ShaderStage GetShaderStage() const
const impeller::SampledImageSlot * GetUniformTexture(const std::string &name) const
std::shared_ptr< impeller::Texture > GetTexture()
const std::map< size_t, ColorAttachment > & GetColorAttachments() const
RenderTarget & SetColorAttachment(const ColorAttachment &attachment, size_t index)
RenderTarget & SetDepthAttachment(std::optional< DepthAttachment > attachment)
PixelFormat GetRenderTargetPixelFormat() const
RenderTarget & SetStencilAttachment(std::optional< StencilAttachment > attachment)
const std::optional< DepthAttachment > & GetDepthAttachment() const
const std::optional< StencilAttachment > & GetStencilAttachment() const
struct _Dart_Handle * Dart_Handle
DART_EXPORT Dart_Handle Dart_Null(void)
DART_EXPORT bool Dart_IsNull(Dart_Handle object)
#define FML_LOG(severity)
#define FML_DCHECK(condition)
void InternalFlutterGpu_RenderPass_BindPipeline(flutter::gpu::RenderPass *wrapper, flutter::gpu::RenderPipeline *pipeline)
static bool BindUniform(flutter::gpu::RenderPass *wrapper, flutter::gpu::Shader *shader, Dart_Handle uniform_name_handle, TBuffer buffer, int offset_in_bytes, int length_in_bytes)
void InternalFlutterGpu_RenderPass_ClearBindings(flutter::gpu::RenderPass *wrapper)
void InternalFlutterGpu_RenderPass_BindIndexBufferHost(flutter::gpu::RenderPass *wrapper, flutter::gpu::HostBuffer *host_buffer, int offset_in_bytes, int length_in_bytes, int index_type, int index_count)
void InternalFlutterGpu_RenderPass_SetColorBlendEquation(flutter::gpu::RenderPass *wrapper, int color_attachment_index, int color_blend_operation, int source_color_blend_factor, int destination_color_blend_factor, int alpha_blend_operation, int source_alpha_blend_factor, int destination_alpha_blend_factor)
void InternalFlutterGpu_RenderPass_BindVertexBufferDevice(flutter::gpu::RenderPass *wrapper, flutter::gpu::DeviceBuffer *device_buffer, int offset_in_bytes, int length_in_bytes, int vertex_count)
void InternalFlutterGpu_RenderPass_BindIndexBufferDevice(flutter::gpu::RenderPass *wrapper, flutter::gpu::DeviceBuffer *device_buffer, int offset_in_bytes, int length_in_bytes, int index_type, int index_count)
void InternalFlutterGpu_RenderPass_BindVertexBufferHost(flutter::gpu::RenderPass *wrapper, flutter::gpu::HostBuffer *host_buffer, int offset_in_bytes, int length_in_bytes, int vertex_count)
bool InternalFlutterGpu_RenderPass_BindTexture(flutter::gpu::RenderPass *wrapper, flutter::gpu::Shader *shader, Dart_Handle uniform_name_handle, flutter::gpu::Texture *texture, int min_filter, int mag_filter, int mip_filter, int width_address_mode, int height_address_mode)
Dart_Handle InternalFlutterGpu_RenderPass_Begin(flutter::gpu::RenderPass *wrapper, flutter::gpu::CommandBuffer *command_buffer)
Dart_Handle InternalFlutterGpu_RenderPass_SetColorAttachment(flutter::gpu::RenderPass *wrapper, int color_attachment_index, int load_action, int store_action, int clear_color, flutter::gpu::Texture *texture, Dart_Handle resolve_texture_wrapper)
static void BindVertexBuffer(flutter::gpu::RenderPass *wrapper, TBuffer buffer, int offset_in_bytes, int length_in_bytes, int vertex_count)
void InternalFlutterGpu_RenderPass_SetDepthCompareOperation(flutter::gpu::RenderPass *wrapper, int compare_operation)
static impeller::Color ToImpellerColor(uint32_t argb)
bool InternalFlutterGpu_RenderPass_BindUniformDevice(flutter::gpu::RenderPass *wrapper, flutter::gpu::Shader *shader, Dart_Handle uniform_name_handle, flutter::gpu::DeviceBuffer *device_buffer, int offset_in_bytes, int length_in_bytes)
bool InternalFlutterGpu_RenderPass_BindUniformHost(flutter::gpu::RenderPass *wrapper, flutter::gpu::Shader *shader, Dart_Handle uniform_name_handle, flutter::gpu::HostBuffer *host_buffer, int offset_in_bytes, int length_in_bytes)
static void BindIndexBuffer(flutter::gpu::RenderPass *wrapper, TBuffer buffer, int offset_in_bytes, int length_in_bytes, int index_type, int index_count)
void InternalFlutterGpu_RenderPass_SetColorBlendEnable(flutter::gpu::RenderPass *wrapper, int color_attachment_index, bool enable)
void InternalFlutterGpu_RenderPass_Initialize(Dart_Handle wrapper)
void InternalFlutterGpu_RenderPass_SetDepthWriteEnable(flutter::gpu::RenderPass *wrapper, bool enable)
Dart_Handle InternalFlutterGpu_RenderPass_SetDepthStencilAttachment(flutter::gpu::RenderPass *wrapper, int depth_load_action, int depth_store_action, float depth_clear_value, int stencil_load_action, int stencil_store_action, int stencil_clear_value, flutter::gpu::Texture *texture)
bool InternalFlutterGpu_RenderPass_Draw(flutter::gpu::RenderPass *wrapper)
constexpr impeller::BlendFactor ToImpellerBlendFactor(FlutterGPUBlendFactor value)
constexpr impeller::BlendOperation ToImpellerBlendOperation(FlutterGPUBlendOperation value)
constexpr impeller::SamplerAddressMode ToImpellerSamplerAddressMode(FlutterGPUSamplerAddressMode value)
constexpr impeller::MipFilter ToImpellerMipFilter(FlutterGPUMipFilter value)
constexpr impeller::CompareFunction ToImpellerCompareFunction(FlutterGPUCompareFunction value)
IMPLEMENT_WRAPPERTYPEINFO(flutter_gpu, CommandBuffer)
constexpr impeller::LoadAction ToImpellerLoadAction(FlutterGPULoadAction value)
constexpr impeller::StoreAction ToImpellerStoreAction(FlutterGPUStoreAction value)
constexpr impeller::IndexType ToImpellerIndexType(FlutterGPUIndexType value)
constexpr impeller::MinMagFilter ToImpellerMinMagFilter(FlutterGPUMinMagFilter value)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
@ kNone
Does not use the index buffer.
constexpr bool IsDepthWritable(PixelFormat format)
constexpr bool IsStencilWritable(PixelFormat format)
Dart_Handle ToDart(const T &object)
std::string StdStringFromDart(Dart_Handle handle)
std::shared_ptr< const DeviceBuffer > buffer
Describe the color attachment that will be used with this pipeline.
static constexpr Color MakeRGBA8(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
An object used to specify work to the GPU along with references to resources the GPU will used when d...
CompareFunction depth_compare
Metadata required to bind a combined texture and sampler.
SamplerAddressMode width_address_mode
SamplerAddressMode height_address_mode
BufferView index_buffer
The index buffer binding used by the vertex shader stage.