Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
2 changes: 1 addition & 1 deletion impeller/compiler/code_gen_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Contributor 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.

std::move({{ arg.argument_name }}){% if not loop.is_last %}, {% endif %}
{% endif %}
{% endfor %});
Expand Down
6 changes: 6 additions & 0 deletions impeller/compiler/reflector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1308,6 +1308,7 @@ std::vector<Reflector::BindPrototype> Reflector::ReflectBindPrototypes(
auto& proto = prototypes.emplace_back(BindPrototype{});
proto.return_type = "bool";
proto.name = ToCamelCase(uniform_buffer.name);
proto.descriptor_type = "DescriptorType::kUniformBuffer";
{
std::stringstream stream;
stream << "Bind uniform buffer for resource named " << uniform_buffer.name
Expand All @@ -1327,6 +1328,7 @@ std::vector<Reflector::BindPrototype> Reflector::ReflectBindPrototypes(
auto& proto = prototypes.emplace_back(BindPrototype{});
proto.return_type = "bool";
proto.name = ToCamelCase(storage_buffer.name);
proto.descriptor_type = "DescriptorType::kStorageBuffer";
{
std::stringstream stream;
stream << "Bind storage buffer for resource named " << storage_buffer.name
Expand All @@ -1346,6 +1348,7 @@ std::vector<Reflector::BindPrototype> Reflector::ReflectBindPrototypes(
auto& proto = prototypes.emplace_back(BindPrototype{});
proto.return_type = "bool";
proto.name = ToCamelCase(sampled_image.name);
proto.descriptor_type = "DescriptorType::kSampledImage";
{
std::stringstream stream;
stream << "Bind combined image sampler for resource named "
Expand All @@ -1369,6 +1372,7 @@ std::vector<Reflector::BindPrototype> Reflector::ReflectBindPrototypes(
auto& proto = prototypes.emplace_back(BindPrototype{});
proto.return_type = "bool";
proto.name = ToCamelCase(separate_image.name);
proto.descriptor_type = "DescriptorType::kImage";
{
std::stringstream stream;
stream << "Bind separate image for resource named " << separate_image.name
Expand All @@ -1388,6 +1392,7 @@ std::vector<Reflector::BindPrototype> Reflector::ReflectBindPrototypes(
auto& proto = prototypes.emplace_back(BindPrototype{});
proto.return_type = "bool";
proto.name = ToCamelCase(separate_sampler.name);
proto.descriptor_type = "DescriptorType::kSampler";
{
std::stringstream stream;
stream << "Bind separate sampler for resource named "
Expand Down Expand Up @@ -1416,6 +1421,7 @@ nlohmann::json::array_t Reflector::EmitBindPrototypes(
item["return_type"] = res.return_type;
item["name"] = res.name;
item["docstring"] = res.docstring;
item["descriptor_type"] = res.descriptor_type;
auto& args = item["args"] = nlohmann::json::array_t{};
for (const auto& arg : res.args) {
auto& json_arg = args.emplace_back(nlohmann::json::object_t{});
Expand Down
1 change: 1 addition & 0 deletions impeller/compiler/reflector.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ class Reflector {
std::string name;
std::string return_type;
std::string docstring;
std::string descriptor_type = "";
std::vector<BindPrototypeArgument> args;
};

Expand Down
2 changes: 2 additions & 0 deletions impeller/core/resource_binder.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ struct ResourceBinder {
virtual ~ResourceBinder() = default;

virtual bool BindResource(ShaderStage stage,
DescriptorType type,
const ShaderUniformSlot& slot,
const ShaderMetadata& metadata,
BufferView view) = 0;

virtual bool BindResource(ShaderStage stage,
DescriptorType type,
const SampledImageSlot& slot,
const ShaderMetadata& metadata,
std::shared_ptr<const Texture> texture,
Expand Down
12 changes: 7 additions & 5 deletions impeller/entity/contents/runtime_effect_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,9 @@ bool RuntimeEffectContents::Render(const ContentContext& renderer,
ShaderUniformSlot uniform_slot;
uniform_slot.name = uniform.name.c_str();
uniform_slot.ext_res_0 = uniform.location;
pass.BindResource(ShaderStage::kFragment, uniform_slot, metadata,
buffer_view);
pass.BindResource(ShaderStage::kFragment,
DescriptorType::kUniformBuffer, uniform_slot,
metadata, buffer_view);
buffer_index++;
buffer_offset += uniform.GetSize();
break;
Expand Down Expand Up @@ -229,7 +230,8 @@ bool RuntimeEffectContents::Render(const ContentContext& renderer,
auto buffer_view = renderer.GetTransientsBuffer().Emplace(
reinterpret_cast<const void*>(uniform_buffer.data()),
sizeof(float) * uniform_buffer.size(), alignment);
pass.BindResource(ShaderStage::kFragment, uniform_slot,
pass.BindResource(ShaderStage::kFragment,
DescriptorType::kUniformBuffer, uniform_slot,
ShaderMetadata{}, buffer_view);
}
}
Expand Down Expand Up @@ -263,8 +265,8 @@ bool RuntimeEffectContents::Render(const ContentContext& renderer,

image_slot.binding = sampler_binding_location;
image_slot.texture_index = uniform.location - minimum_sampler_index;
pass.BindResource(ShaderStage::kFragment, image_slot, *metadata,
input.texture, sampler);
pass.BindResource(ShaderStage::kFragment, DescriptorType::kSampledImage,
image_slot, *metadata, input.texture, sampler);

sampler_index++;
break;
Expand Down
66 changes: 0 additions & 66 deletions impeller/renderer/backend/vulkan/binding_helpers_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@

namespace impeller {

// Warning: if any of the constant values or layouts are changed in the
// framebuffer fetch shader, then this input binding may need to be
// manually changed.
static constexpr size_t kMagicSubpassInputBinding = 64;

static bool BindImages(
const Bindings& bindings,
Allocator& allocator,
Expand Down Expand Up @@ -125,67 +120,6 @@ static bool BindBuffers(
return true;
}

fml::StatusOr<vk::DescriptorSet> AllocateAndBindDescriptorSets(
const ContextVK& context,
const std::shared_ptr<CommandEncoderVK>& encoder,
Allocator& allocator,
const Command& command,
const TextureVK& input_attachment,
std::array<vk::DescriptorImageInfo, kMaxBindings>& image_workspace,
std::array<vk::DescriptorBufferInfo, kMaxBindings>& buffer_workspace,
std::array<vk::WriteDescriptorSet, kMaxBindings + kMaxBindings>&
write_workspace) {
auto descriptor_result = encoder->AllocateDescriptorSets(
PipelineVK::Cast(*command.pipeline).GetDescriptorSetLayout(), context);
if (!descriptor_result.ok()) {
return descriptor_result.status();
}
vk::DescriptorSet descriptor_set = descriptor_result.value();

size_t buffer_offset = 0u;
size_t image_offset = 0u;
size_t write_offset = 0u;

auto& pipeline_descriptor = command.pipeline->GetDescriptor();
auto& desc_set =
pipeline_descriptor.GetVertexDescriptor()->GetDescriptorSetLayouts();

if (!BindBuffers(command.vertex_bindings, allocator, encoder, descriptor_set,
desc_set, buffer_workspace, buffer_offset, write_workspace,
write_offset) ||
!BindBuffers(command.fragment_bindings, allocator, encoder,
descriptor_set, desc_set, buffer_workspace, buffer_offset,
write_workspace, write_offset) ||
!BindImages(command.fragment_bindings, allocator, encoder, descriptor_set,
image_workspace, image_offset, write_workspace,
write_offset)) {
return fml::Status(fml::StatusCode::kUnknown,
"Failed to bind texture or buffer.");
}

if (pipeline_descriptor.UsesSubpassInput()) {
vk::DescriptorImageInfo image_info;
image_info.imageLayout = vk::ImageLayout::eGeneral;
image_info.sampler = VK_NULL_HANDLE;
image_info.imageView = input_attachment.GetImageView();
image_workspace[image_offset++] = image_info;

vk::WriteDescriptorSet write_set;
write_set.dstSet = descriptor_set;
write_set.dstBinding = kMagicSubpassInputBinding;
write_set.descriptorCount = 1u;
write_set.descriptorType = vk::DescriptorType::eInputAttachment;
write_set.pImageInfo = &image_workspace[image_offset - 1];

write_workspace[write_offset++] = write_set;
}

context.GetDevice().updateDescriptorSets(write_offset, write_workspace.data(),
0u, {});

return descriptor_set;
}

fml::StatusOr<vk::DescriptorSet> AllocateAndBindDescriptorSets(
const ContextVK& context,
const std::shared_ptr<CommandEncoderVK>& encoder,
Expand Down
11 changes: 0 additions & 11 deletions impeller/renderer/backend/vulkan/binding_helpers_vk.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,6 @@ namespace impeller {
// backend to avoid dynamic heap allocations.
static constexpr size_t kMaxBindings = 32;

fml::StatusOr<vk::DescriptorSet> AllocateAndBindDescriptorSets(
const ContextVK& context,
const std::shared_ptr<CommandEncoderVK>& encoder,
Allocator& allocator,
const Command& command,
const TextureVK& input_attachment,
std::array<vk::DescriptorImageInfo, kMaxBindings>& image_workspace,
std::array<vk::DescriptorBufferInfo, kMaxBindings>& buffer_workspace,
std::array<vk::WriteDescriptorSet, kMaxBindings + kMaxBindings>&
write_workspace);

fml::StatusOr<vk::DescriptorSet> AllocateAndBindDescriptorSets(
const ContextVK& context,
const std::shared_ptr<CommandEncoderVK>& encoder,
Expand Down
9 changes: 3 additions & 6 deletions impeller/renderer/backend/vulkan/command_buffer_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@
#include <memory>
#include <utility>

#include "flutter/fml/logging.h"
#include "impeller/base/validation.h"
#include "impeller/renderer/backend/vulkan/blit_pass_vk.h"
#include "impeller/renderer/backend/vulkan/command_encoder_vk.h"
#include "impeller/renderer/backend/vulkan/compute_pass_vk.h"
#include "impeller/renderer/backend/vulkan/context_vk.h"
#include "impeller/renderer/backend/vulkan/formats_vk.h"
#include "impeller/renderer/backend/vulkan/render_pass_vk.h"
#include "impeller/renderer/command_buffer.h"
#include "impeller/renderer/render_target.h"
Expand Down Expand Up @@ -73,9 +70,9 @@ std::shared_ptr<RenderPass> CommandBufferVK::OnCreateRenderPass(
return nullptr;
}
auto pass =
std::shared_ptr<RenderPassVK>(new RenderPassVK(context, //
target, //
weak_from_this() //
std::shared_ptr<RenderPassVK>(new RenderPassVK(context, //
target, //
shared_from_this() //
));
if (!pass->IsValid()) {
return nullptr;
Expand Down
1 change: 0 additions & 1 deletion impeller/renderer/backend/vulkan/command_buffer_vk.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#ifndef FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_COMMAND_BUFFER_VK_H_
#define FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_COMMAND_BUFFER_VK_H_

#include "flutter/fml/macros.h"
#include "impeller/base/backend_cast.h"
#include "impeller/renderer/backend/vulkan/vk.h"
#include "impeller/renderer/command_buffer.h"
Expand Down
4 changes: 1 addition & 3 deletions impeller/renderer/backend/vulkan/gpu_tracer_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ GPUTracerVK::GPUTracerVK(const std::shared_ptr<DeviceHolder>& device_holder)
return;
}
// Disable tracing in release mode.
#ifdef IMPELLER_DEBUG
enabled_ = true;
#endif
enabled_ = false;
}

bool GPUTracerVK::IsEnabled() const {
Expand Down
Loading