Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Friends | List of all members
impeller::ComputePassVK Class Referencefinal

#include <compute_pass_vk.h>

Inheritance diagram for impeller::ComputePassVK:
impeller::ComputePass impeller::ResourceBinder

Public Member Functions

 ~ComputePassVK () override
 
- Public Member Functions inherited from impeller::ComputePass
virtual ~ComputePass ()
 
void SetLabel (const std::string &label)
 
const ContextGetContext () const
 
- Public Member Functions inherited from impeller::ResourceBinder
virtual ~ResourceBinder ()=default
 

Private Member Functions

bool IsValid () const override
 
void OnSetLabel (const std::string &label) override
 
bool EncodeCommands () const override
 Encode the recorded commands to the underlying command buffer.
 
void SetCommandLabel (std::string_view label) override
 
void SetPipeline (const std::shared_ptr< Pipeline< ComputePipelineDescriptor > > &pipeline) override
 
void AddBufferMemoryBarrier () override
 Ensures all previously encoded compute command's buffer writes are visible to any subsequent compute commands.
 
void AddTextureMemoryBarrier () override
 Ensures all previously encoded compute command's texture writes are visible to any subsequent compute commands.
 
fml::Status Compute (const ISize &grid_size) override
 
bool BindResource (ShaderStage stage, DescriptorType type, const ShaderUniformSlot &slot, const ShaderMetadata &metadata, BufferView view) override
 
bool BindResource (ShaderStage stage, DescriptorType type, const SampledImageSlot &slot, const ShaderMetadata &metadata, std::shared_ptr< const Texture > texture, const std::unique_ptr< const Sampler > &sampler) override
 

Friends

class CommandBufferVK
 

Additional Inherited Members

- Protected Member Functions inherited from impeller::ComputePass
 ComputePass (std::shared_ptr< const Context > context)
 
- Protected Attributes inherited from impeller::ComputePass
const std::shared_ptr< const Contextcontext_
 

Detailed Description

Definition at line 15 of file compute_pass_vk.h.

Constructor & Destructor Documentation

◆ ~ComputePassVK()

impeller::ComputePassVK::~ComputePassVK ( )
overridedefault

Member Function Documentation

◆ AddBufferMemoryBarrier()

void impeller::ComputePassVK::AddBufferMemoryBarrier ( )
overrideprivatevirtual

Ensures all previously encoded compute command's buffer writes are visible to any subsequent compute commands.

On Vulkan, it does not matter if the compute command is in a different command buffer, only that it is executed later in queue order.

Implements impeller::ComputePass.

Definition at line 222 of file compute_pass_vk.cc.

222 {
223 vk::MemoryBarrier barrier;
224 barrier.srcAccessMask = vk::AccessFlagBits::eShaderWrite;
225 barrier.dstAccessMask = vk::AccessFlagBits::eShaderRead;
226
227 command_buffer_->GetEncoder()->GetCommandBuffer().pipelineBarrier(
228 vk::PipelineStageFlagBits::eComputeShader,
229 vk::PipelineStageFlagBits::eComputeShader, {}, 1, &barrier, 0, {}, 0, {});
230}

◆ AddTextureMemoryBarrier()

void impeller::ComputePassVK::AddTextureMemoryBarrier ( )
overrideprivatevirtual

Ensures all previously encoded compute command's texture writes are visible to any subsequent compute commands.

On Vulkan, it does not matter if the compute command is in a different command buffer, only that it is executed later in queue order.

Implements impeller::ComputePass.

Definition at line 233 of file compute_pass_vk.cc.

233 {
234 vk::MemoryBarrier barrier;
235 barrier.srcAccessMask = vk::AccessFlagBits::eShaderWrite;
236 barrier.dstAccessMask = vk::AccessFlagBits::eShaderRead;
237
238 command_buffer_->GetEncoder()->GetCommandBuffer().pipelineBarrier(
239 vk::PipelineStageFlagBits::eComputeShader,
240 vk::PipelineStageFlagBits::eComputeShader, {}, 1, &barrier, 0, {}, 0, {});
241}

◆ BindResource() [1/2]

bool impeller::ComputePassVK::BindResource ( ShaderStage  stage,
DescriptorType  type,
const SampledImageSlot slot,
const ShaderMetadata metadata,
std::shared_ptr< const Texture texture,
const std::unique_ptr< const Sampler > &  sampler 
)
overrideprivatevirtual

Implements impeller::ResourceBinder.

Definition at line 144 of file compute_pass_vk.cc.

150 {
151 if (bound_image_offset_ >= kMaxBindings) {
152 return false;
153 }
154 if (!texture->IsValid() || !sampler) {
155 return false;
156 }
157 const TextureVK& texture_vk = TextureVK::Cast(*texture);
158 const SamplerVK& sampler_vk = SamplerVK::Cast(*sampler);
159
160 if (!command_buffer_->GetEncoder()->Track(texture)) {
161 return false;
162 }
163
164 vk::DescriptorImageInfo image_info;
165 image_info.imageLayout = vk::ImageLayout::eShaderReadOnlyOptimal;
166 image_info.sampler = sampler_vk.GetSampler();
167 image_info.imageView = texture_vk.GetImageView();
168 image_workspace_[bound_image_offset_++] = image_info;
169
170 vk::WriteDescriptorSet write_set;
171 write_set.dstBinding = slot.binding;
172 write_set.descriptorCount = 1u;
173 write_set.descriptorType = ToVKDescriptorType(type);
174 write_set.pImageInfo = &image_workspace_[bound_image_offset_ - 1];
175
176 write_workspace_[descriptor_write_offset_++] = write_set;
177 return true;
178}
static TextureVK & Cast(Texture &base)
FlTexture * texture
constexpr vk::DescriptorType ToVKDescriptorType(DescriptorType type)
Definition formats_vk.h:267
static constexpr size_t kMaxBindings
Definition pipeline_vk.h:26

◆ BindResource() [2/2]

bool impeller::ComputePassVK::BindResource ( ShaderStage  stage,
DescriptorType  type,
const ShaderUniformSlot slot,
const ShaderMetadata metadata,
BufferView  view 
)
overrideprivatevirtual

Implements impeller::ResourceBinder.

Definition at line 135 of file compute_pass_vk.cc.

139 {
140 return BindResource(slot.binding, type, view);
141}
bool BindResource(ShaderStage stage, DescriptorType type, const ShaderUniformSlot &slot, const ShaderMetadata &metadata, BufferView view) override

◆ Compute()

fml::Status impeller::ComputePassVK::Compute ( const ISize grid_size)
overrideprivatevirtual

Implements impeller::ComputePass.

Definition at line 71 of file compute_pass_vk.cc.

71 {
72 if (grid_size.IsEmpty() || !pipeline_valid_) {
73 bound_image_offset_ = 0u;
74 bound_buffer_offset_ = 0u;
75 descriptor_write_offset_ = 0u;
76 has_label_ = false;
77 pipeline_valid_ = false;
79 "Invalid pipeline or empty grid.");
80 }
81
82 const ContextVK& context_vk = ContextVK::Cast(*context_);
83 for (auto i = 0u; i < descriptor_write_offset_; i++) {
84 write_workspace_[i].dstSet = descriptor_set_;
85 }
86
87 context_vk.GetDevice().updateDescriptorSets(descriptor_write_offset_,
88 write_workspace_.data(), 0u, {});
89 const vk::CommandBuffer& command_buffer_vk =
90 command_buffer_->GetEncoder()->GetCommandBuffer();
91
92 command_buffer_vk.bindDescriptorSets(
93 vk::PipelineBindPoint::eCompute, // bind point
94 pipeline_layout_, // layout
95 0, // first set
96 1, // set count
97 &descriptor_set_, // sets
98 0, // offset count
99 nullptr // offsets
100 );
101
102 int64_t width = grid_size.width;
103 int64_t height = grid_size.height;
104
105 // Special case for linear processing.
106 if (height == 1) {
107 command_buffer_vk.dispatch(width, 1, 1);
108 } else {
109 while (width > max_wg_size_[0]) {
110 width = std::max(static_cast<int64_t>(1), width / 2);
111 }
112 while (height > max_wg_size_[1]) {
113 height = std::max(static_cast<int64_t>(1), height / 2);
114 }
115 command_buffer_vk.dispatch(width, height, 1);
116 }
117
118#ifdef IMPELLER_DEBUG
119 if (has_label_) {
120 command_buffer_->GetEncoder()->PopDebugGroup();
121 }
122 has_label_ = false;
123#endif // IMPELLER_DEBUG
124
125 bound_image_offset_ = 0u;
126 bound_buffer_offset_ = 0u;
127 descriptor_write_offset_ = 0u;
128 has_label_ = false;
129 pipeline_valid_ = false;
130
131 return fml::Status();
132}
const std::shared_ptr< const Context > context_
int32_t height
int32_t width

◆ EncodeCommands()

bool impeller::ComputePassVK::EncodeCommands ( ) const
overrideprivatevirtual

Encode the recorded commands to the underlying command buffer.

Returns
If the commands were encoded to the underlying command buffer.

Implements impeller::ComputePass.

Definition at line 244 of file compute_pass_vk.cc.

244 {
245 // Since we only use global memory barrier, we don't have to worry about
246 // compute to compute dependencies across cmd buffers. Instead, we pessimize
247 // here and assume that we wrote to a storage image or buffer and that a
248 // render pass will read from it. if there are ever scenarios where we end up
249 // with compute to compute dependencies this should be revisited.
250
251 // This does not currently handle image barriers as we do not use them
252 // for anything.
253 vk::MemoryBarrier barrier;
254 barrier.srcAccessMask = vk::AccessFlagBits::eShaderWrite;
255 barrier.dstAccessMask =
256 vk::AccessFlagBits::eIndexRead | vk::AccessFlagBits::eVertexAttributeRead;
257
258 command_buffer_->GetEncoder()->GetCommandBuffer().pipelineBarrier(
259 vk::PipelineStageFlagBits::eComputeShader,
260 vk::PipelineStageFlagBits::eVertexInput, {}, 1, &barrier, 0, {}, 0, {});
261
262 return true;
263}

◆ IsValid()

bool impeller::ComputePassVK::IsValid ( ) const
overrideprivatevirtual

Implements impeller::ComputePass.

Definition at line 31 of file compute_pass_vk.cc.

31 {
32 return is_valid_;
33}

◆ OnSetLabel()

void impeller::ComputePassVK::OnSetLabel ( const std::string &  label)
overrideprivatevirtual

Implements impeller::ComputePass.

Definition at line 35 of file compute_pass_vk.cc.

35 {
36 if (label.empty()) {
37 return;
38 }
39 label_ = label;
40}

◆ SetCommandLabel()

void impeller::ComputePassVK::SetCommandLabel ( std::string_view  label)
overrideprivatevirtual

Implements impeller::ComputePass.

Definition at line 43 of file compute_pass_vk.cc.

43 {
44#ifdef IMPELLER_DEBUG
45 command_buffer_->GetEncoder()->PushDebugGroup(label);
46 has_label_ = true;
47#endif // IMPELLER_DEBUG
48}

◆ SetPipeline()

void impeller::ComputePassVK::SetPipeline ( const std::shared_ptr< Pipeline< ComputePipelineDescriptor > > &  pipeline)
overrideprivatevirtual

Implements impeller::ComputePass.

Definition at line 51 of file compute_pass_vk.cc.

52 {
53 const auto& pipeline_vk = ComputePipelineVK::Cast(*pipeline);
54 const vk::CommandBuffer& command_buffer_vk =
55 command_buffer_->GetEncoder()->GetCommandBuffer();
56 command_buffer_vk.bindPipeline(vk::PipelineBindPoint::eCompute,
57 pipeline_vk.GetPipeline());
58 pipeline_layout_ = pipeline_vk.GetPipelineLayout();
59
60 auto descriptor_result =
61 command_buffer_->GetEncoder()->AllocateDescriptorSets(
62 pipeline_vk.GetDescriptorSetLayout(), ContextVK::Cast(*context_));
63 if (!descriptor_result.ok()) {
64 return;
65 }
66 descriptor_set_ = descriptor_result.value();
67 pipeline_valid_ = true;
68}

Friends And Related Symbol Documentation

◆ CommandBufferVK

friend class CommandBufferVK
friend

Definition at line 21 of file compute_pass_vk.h.


The documentation for this class was generated from the following files: