Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions impeller/compiler/code_gen_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,9 @@ struct {{camel_case(shader_name)}}{{camel_case(shader_stage)}}Shader {

static constexpr auto kResource{{camel_case(sampled_image.name)}} = SampledImageSlot { // {{sampled_image.name}}
"{{sampled_image.name}}", // name
{{sampled_image.ext_res_0}}u, // texture
{{sampled_image.ext_res_1}}u, // sampler
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was unused

{{sampled_image.binding}}u, // binding
{{sampled_image.ext_res_0}}u, // ext_res_0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have a better name for this? This represents which texture unit this will be bound to right? ext_res_0 doesn't mean anything to me and seems to be a Metal-ism?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Back to texture_index, with a note that this is ext_res_0

{{sampled_image.set}}u, // set
{{sampled_image.binding}}u, // binding
};
static ShaderMetadata kMetadata{{camel_case(sampled_image.name)}};
{% endfor %}
Expand Down
4 changes: 0 additions & 4 deletions impeller/core/resource_binder.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@

#pragma once

#include <map>
#include <memory>
#include <optional>
#include <string>

#include "flutter/fml/logging.h"
#include "impeller/core/buffer_view.h"
#include "impeller/core/formats.h"
#include "impeller/core/sampler.h"
Expand Down
43 changes: 17 additions & 26 deletions impeller/core/shader_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,23 @@ struct ShaderUniformSlot {
size_t binding;
};

/// @brief Metadata required to bind a combined texture and sampler.
///
/// OpenGL binding requires the usage of the separate shader metadata struct.
struct SampledImageSlot {
/// @brief The name of the uniform slot.
const char* name;

/// @brief `ext_res_0` is the Metal binding value.
size_t texture_index;

/// @brief The Vulkan descriptor set index.
size_t set;

/// @brief The Vulkan binding value.
size_t binding;
};

struct ShaderStageIOSlot {
const char* name;
size_t location;
Expand Down Expand Up @@ -131,32 +148,6 @@ struct ShaderStageBufferLayout {
}
};

/// @brief Metadata required to bind a texture and sampler.
///
/// OpenGL binding requires the usage of the separate shader metadata struct.
struct SampledImageSlot {
/// @brief The name of the texture slot.
const char* name;

/// @brief This value is `ext_res_0`, the Metal binding value for the texture.
size_t texture_index;

/// @brief This value is `ext_res_1`, the Metal binding value for the sampler.
///
/// Since only combined texture and samplers are used, this index is unused.
size_t sampler_index;

/// @brief The Vulkan binding value for a combined texture and sampler.
size_t binding;

/// @brief The Vulkan descriptor set index.
size_t set;

constexpr bool HasTexture() const { return texture_index < 32u; }

constexpr bool HasSampler() const { return sampler_index < 32u; }
};

enum class DescriptorType {
kUniformBuffer,
kStorageBuffer,
Expand Down
1 change: 1 addition & 0 deletions impeller/entity/contents/checkerboard_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "impeller/entity/contents/content_context.h"
#include "impeller/renderer/command.h"
#include "impeller/renderer/render_pass.h"
#include "impeller/renderer/vertex_buffer_builder.h"

namespace impeller {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "impeller/entity/contents/contents.h"
#include "impeller/renderer/render_pass.h"
#include "impeller/renderer/sampler_library.h"
#include "impeller/renderer/vertex_buffer_builder.h"

namespace impeller {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "impeller/geometry/vector.h"
#include "impeller/renderer/render_pass.h"
#include "impeller/renderer/sampler_library.h"
#include "impeller/renderer/vertex_buffer_builder.h"

namespace impeller {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "impeller/renderer/render_pass.h"
#include "impeller/renderer/render_target.h"
#include "impeller/renderer/sampler_library.h"
#include "impeller/renderer/vertex_buffer_builder.h"

namespace impeller {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "impeller/renderer/command.h"
#include "impeller/renderer/render_pass.h"
#include "impeller/renderer/sampler_library.h"
#include "impeller/renderer/vertex_buffer_builder.h"

namespace impeller {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "impeller/geometry/vector.h"
#include "impeller/renderer/render_pass.h"
#include "impeller/renderer/sampler_library.h"
#include "impeller/renderer/vertex_buffer_builder.h"

namespace impeller {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "impeller/entity/contents/contents.h"
#include "impeller/renderer/render_pass.h"
#include "impeller/renderer/sampler_library.h"
#include "impeller/renderer/vertex_buffer_builder.h"

namespace impeller {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "impeller/geometry/vector.h"
#include "impeller/renderer/render_pass.h"
#include "impeller/renderer/sampler_library.h"
#include "impeller/renderer/vertex_buffer_builder.h"

namespace impeller {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "impeller/geometry/matrix.h"
#include "impeller/renderer/render_pass.h"
#include "impeller/renderer/sampler_library.h"
#include "impeller/renderer/vertex_buffer_builder.h"

namespace impeller {

Expand Down
1 change: 0 additions & 1 deletion impeller/entity/contents/runtime_effect_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ bool RuntimeEffectContents::Render(const ContentContext& renderer,
SampledImageSlot image_slot;
image_slot.name = uniform.name.c_str();
image_slot.texture_index = uniform.location - minimum_sampler_index;
image_slot.sampler_index = uniform.location - minimum_sampler_index;
cmd.BindResource(ShaderStage::kFragment, image_slot, metadata,
input.texture, sampler);

Expand Down
20 changes: 14 additions & 6 deletions impeller/entity/contents/test/contents_test_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,34 @@ namespace impeller {
/// @brief Retrieve the [VertInfo] struct data from the provided [command].
template <typename T>
typename T::VertInfo* GetVertInfo(const Command& command) {
auto resource = command.vertex_bindings.buffers.find(0u);
auto resource = std::find_if(command.vertex_bindings.buffers.begin(),
command.vertex_bindings.buffers.end(),
[](const BufferAndUniformSlot& data) {
return data.slot.ext_res_0 == 0u;
});
if (resource == command.vertex_bindings.buffers.end()) {
return nullptr;
}

auto data = (resource->second.view.resource.contents +
resource->second.view.resource.range.offset);
auto data =
(resource->view.resource.contents + resource->view.resource.range.offset);
return reinterpret_cast<typename T::VertInfo*>(data);
}

/// @brief Retrieve the [FragInfo] struct data from the provided [command].
template <typename T>
typename T::FragInfo* GetFragInfo(const Command& command) {
auto resource = command.fragment_bindings.buffers.find(0u);
auto resource = std::find_if(command.fragment_bindings.buffers.begin(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we are getting linear search here hopefully? This should be faster for the small sizes we have.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just for testing, so performance doesnt matter as much

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We dont ever have to look up particular bindings, we just iterate through the set of bindings and bind each one.

command.fragment_bindings.buffers.end(),
[](const BufferAndUniformSlot& data) {
return data.slot.ext_res_0 == 0u;
});
if (resource == command.fragment_bindings.buffers.end()) {
return nullptr;
}

auto data = (resource->second.view.resource.contents +
resource->second.view.resource.range.offset);
auto data =
(resource->view.resource.contents + resource->view.resource.range.offset);
return reinterpret_cast<typename T::FragInfo*>(data);
}

Expand Down
2 changes: 1 addition & 1 deletion impeller/entity/contents/texture_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
#include "impeller/entity/texture_fill.vert.h"
#include "impeller/entity/texture_fill_external.frag.h"
#include "impeller/geometry/constants.h"
#include "impeller/geometry/path_builder.h"
#include "impeller/renderer/render_pass.h"
#include "impeller/renderer/sampler_library.h"
#include "impeller/renderer/vertex_buffer_builder.h"

namespace impeller {

Expand Down
1 change: 1 addition & 0 deletions impeller/entity/geometry/geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "impeller/entity/entity.h"
#include "impeller/entity/texture_fill.vert.h"
#include "impeller/renderer/render_pass.h"
#include "impeller/renderer/vertex_buffer_builder.h"

namespace impeller {

Expand Down
12 changes: 6 additions & 6 deletions impeller/renderer/backend/gles/buffer_bindings_gles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,12 @@ bool BufferBindingsGLES::BindUniformData(const ProcTableGLES& gl,
const Bindings& vertex_bindings,
const Bindings& fragment_bindings) {
for (const auto& buffer : vertex_bindings.buffers) {
if (!BindUniformBuffer(gl, transients_allocator, buffer.second.view)) {
if (!BindUniformBuffer(gl, transients_allocator, buffer.view)) {
return false;
}
}
for (const auto& buffer : fragment_bindings.buffers) {
if (!BindUniformBuffer(gl, transients_allocator, buffer.second.view)) {
if (!BindUniformBuffer(gl, transients_allocator, buffer.view)) {
return false;
}
}
Expand Down Expand Up @@ -345,13 +345,13 @@ std::optional<size_t> BufferBindingsGLES::BindTextures(
size_t unit_start_index) {
size_t active_index = unit_start_index;
for (const auto& data : bindings.sampled_images) {
const auto& texture_gles = TextureGLES::Cast(*data.second.texture.resource);
if (data.second.texture.GetMetadata() == nullptr) {
const auto& texture_gles = TextureGLES::Cast(*data.texture.resource);
if (data.texture.GetMetadata() == nullptr) {
VALIDATION_LOG << "No metadata found for texture binding.";
return std::nullopt;
}

auto location = ComputeTextureLocation(data.second.texture.GetMetadata());
auto location = ComputeTextureLocation(data.texture.GetMetadata());
if (location == -1) {
return std::nullopt;
}
Expand All @@ -377,7 +377,7 @@ std::optional<size_t> BufferBindingsGLES::BindTextures(
/// If there is a sampler for the texture at the same index, configure the
/// bound texture using that sampler.
///
const auto& sampler_gles = SamplerGLES::Cast(*data.second.sampler);
const auto& sampler_gles = SamplerGLES::Cast(*data.sampler);
if (!sampler_gles.ConfigureBoundTexture(texture_gles, gl)) {
return std::nullopt;
}
Expand Down
15 changes: 8 additions & 7 deletions impeller/renderer/backend/metal/compute_pass_mtl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "impeller/renderer/backend/metal/formats_mtl.h"
#include "impeller/renderer/backend/metal/sampler_mtl.h"
#include "impeller/renderer/backend/metal/texture_mtl.h"
#include "impeller/renderer/command.h"
#include "impeller/renderer/compute_command.h"

namespace impeller {
Expand Down Expand Up @@ -209,7 +210,7 @@ static bool Bind(ComputePassBindingsCache& pass,
ComputePassBindingsCache pass_bindings(encoder);

fml::closure pop_debug_marker = [encoder]() { [encoder popDebugGroup]; };
for (const auto& command : commands_) {
for (const ComputeCommand& command : commands_) {
#ifdef IMPELLER_DEBUG
fml::ScopedCleanupClosure auto_pop_debug_marker(pop_debug_marker);
if (!command.label.empty()) {
Expand All @@ -223,16 +224,16 @@ static bool Bind(ComputePassBindingsCache& pass,
ComputePipelineMTL::Cast(*command.pipeline)
.GetMTLComputePipelineState());

for (const auto& buffer : command.bindings.buffers) {
if (!Bind(pass_bindings, *allocator, buffer.first,
buffer.second.view.resource)) {
for (const BufferAndUniformSlot& buffer : command.bindings.buffers) {
if (!Bind(pass_bindings, *allocator, buffer.slot.ext_res_0,
buffer.view.resource)) {
return false;
}
}

for (const auto& data : command.bindings.sampled_images) {
if (!Bind(pass_bindings, data.first, *data.second.sampler,
*data.second.texture.resource)) {
for (const TextureAndSampler& data : command.bindings.sampled_images) {
if (!Bind(pass_bindings, data.slot.texture_index, *data.sampler,
*data.texture.resource)) {
return false;
}
}
Expand Down
13 changes: 7 additions & 6 deletions impeller/renderer/backend/metal/render_pass_mtl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "impeller/renderer/backend/metal/pipeline_mtl.h"
#include "impeller/renderer/backend/metal/sampler_mtl.h"
#include "impeller/renderer/backend/metal/texture_mtl.h"
#include "impeller/renderer/command.h"
#include "impeller/renderer/vertex_descriptor.h"

namespace impeller {
Expand Down Expand Up @@ -408,15 +409,15 @@ static bool Bind(PassBindingsCache& pass,
auto bind_stage_resources = [&allocator, &pass_bindings](
const Bindings& bindings,
ShaderStage stage) -> bool {
for (const auto& buffer : bindings.buffers) {
if (!Bind(pass_bindings, *allocator, stage, buffer.first,
buffer.second.view.resource)) {
for (const BufferAndUniformSlot& buffer : bindings.buffers) {
if (!Bind(pass_bindings, *allocator, stage, buffer.slot.ext_res_0,
buffer.view.resource)) {
return false;
}
}
for (const auto& data : bindings.sampled_images) {
if (!Bind(pass_bindings, stage, data.first, *data.second.sampler,
*data.second.texture.resource)) {
for (const TextureAndSampler& data : bindings.sampled_images) {
if (!Bind(pass_bindings, stage, data.slot.texture_index, *data.sampler,
*data.texture.resource)) {
return false;
}
}
Expand Down
5 changes: 3 additions & 2 deletions impeller/renderer/backend/vulkan/binding_helpers_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "impeller/renderer/backend/vulkan/binding_helpers_vk.h"
#include "fml/status.h"
#include "impeller/core/shader_types.h"
#include "impeller/renderer/backend/vulkan/command_buffer_vk.h"
#include "impeller/renderer/backend/vulkan/command_encoder_vk.h"
#include "impeller/renderer/backend/vulkan/command_pool_vk.h"
Expand All @@ -28,7 +29,7 @@ static bool BindImages(const Bindings& bindings,
vk::DescriptorSet& vk_desc_set,
std::vector<vk::DescriptorImageInfo>& images,
std::vector<vk::WriteDescriptorSet>& writes) {
for (const auto& [index, data] : bindings.sampled_images) {
for (const TextureAndSampler& data : bindings.sampled_images) {
auto texture = data.texture.resource;
const auto& texture_vk = TextureVK::Cast(*texture);
const SamplerVK& sampler = SamplerVK::Cast(*data.sampler);
Expand Down Expand Up @@ -66,7 +67,7 @@ static bool BindBuffers(const Bindings& bindings,
const std::vector<DescriptorSetLayout>& desc_set,
std::vector<vk::DescriptorBufferInfo>& buffers,
std::vector<vk::WriteDescriptorSet>& writes) {
for (const auto& [buffer_index, data] : bindings.buffers) {
for (const BufferAndUniformSlot& data : bindings.buffers) {
const auto& buffer_view = data.view.resource.buffer;

auto device_buffer = buffer_view->GetDeviceBuffer(allocator);
Expand Down
5 changes: 3 additions & 2 deletions impeller/renderer/backend/vulkan/compute_pass_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "impeller/renderer/backend/vulkan/command_buffer_vk.h"
#include "impeller/renderer/backend/vulkan/compute_pipeline_vk.h"
#include "impeller/renderer/backend/vulkan/texture_vk.h"
#include "impeller/renderer/command.h"

namespace impeller {

Expand Down Expand Up @@ -43,7 +44,7 @@ static bool UpdateBindingLayouts(const Bindings& bindings,

barrier.new_layout = vk::ImageLayout::eShaderReadOnlyOptimal;

for (const auto& [_, data] : bindings.sampled_images) {
for (const TextureAndSampler& data : bindings.sampled_images) {
if (!TextureVK::Cast(*data.texture.resource).SetLayout(barrier)) {
return false;
}
Expand All @@ -58,7 +59,7 @@ static bool UpdateBindingLayouts(const ComputeCommand& command,

static bool UpdateBindingLayouts(const std::vector<ComputeCommand>& commands,
const vk::CommandBuffer& buffer) {
for (const auto& command : commands) {
for (const ComputeCommand& command : commands) {
if (!UpdateBindingLayouts(command, buffer)) {
return false;
}
Expand Down
Loading