Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Impeller] Don't place vertex buffer bindings in the Binding map. #45040

Merged
merged 3 commits into from
Aug 24, 2023
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
2 changes: 1 addition & 1 deletion impeller/core/buffer_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct BufferView {
uint8_t* contents;
Range range;

constexpr operator bool() const { return static_cast<bool>(buffer); }
constexpr explicit operator bool() const { return static_cast<bool>(buffer); }
};

} // namespace impeller
6 changes: 0 additions & 6 deletions impeller/renderer/backend/gles/buffer_bindings_gles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,6 @@ bool BufferBindingsGLES::BindUniformBuffer(const ProcTableGLES& gl,
Allocator& transients_allocator,
const BufferResource& buffer) const {
const auto* metadata = buffer.GetMetadata();
if (metadata == nullptr) {
// Vertex buffer bindings don't have metadata as those definitions are
// already handled by vertex attrib pointers. Keep going.
return true;
}

auto device_buffer =
buffer.resource.buffer->GetDeviceBuffer(transients_allocator);
if (!device_buffer) {
Expand Down
8 changes: 8 additions & 0 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/vertex_descriptor.h"

namespace impeller {

Expand Down Expand Up @@ -407,6 +408,13 @@ static bool Bind(PassBindingsCache& pass,
auto bind_stage_resources = [&allocator, &pass_bindings](
const Bindings& bindings,
ShaderStage stage) -> bool {
if (stage == ShaderStage::kVertex) {
if (!Bind(pass_bindings, *allocator, stage,
VertexDescriptor::kReservedVertexBufferIndex,
bindings.vertex_buffer.view.resource)) {
return false;
}
}
for (const auto& buffer : bindings.buffers) {
if (!Bind(pass_bindings, *allocator, stage, buffer.first,
buffer.second.view.resource)) {
Expand Down
5 changes: 0 additions & 5 deletions impeller/renderer/backend/vulkan/render_pass_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,6 @@ static bool AllocateAndBindDescriptorSets(const ContextVK& context,
return false;
}

// Reserved index used for per-vertex data.
if (buffer_index == VertexDescriptor::kReservedVertexBufferIndex) {
continue;
}

if (!encoder.Track(device_buffer)) {
return false;
}
Expand Down
10 changes: 3 additions & 7 deletions impeller/renderer/command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ bool Command::BindVertices(const VertexBuffer& buffer) {
return false;
}

vertex_bindings.buffers[VertexDescriptor::kReservedVertexBufferIndex] =
vertex_bindings.vertex_buffer =
BufferAndUniformSlot{.slot = {}, .view = {nullptr, buffer.vertex_buffer}};
index_buffer = buffer.index_buffer;
vertex_count = buffer.vertex_count;
Expand All @@ -27,12 +27,7 @@ bool Command::BindVertices(const VertexBuffer& buffer) {
}

BufferView Command::GetVertexBuffer() const {
auto found = vertex_bindings.buffers.find(
VertexDescriptor::kReservedVertexBufferIndex);
if (found != vertex_bindings.buffers.end()) {
return found->second.view.resource;
}
return {};
return vertex_bindings.vertex_buffer.view.resource;
}

bool Command::BindResource(ShaderStage stage,
Expand All @@ -55,6 +50,7 @@ bool Command::DoBindResource(ShaderStage stage,
const ShaderUniformSlot& slot,
const T metadata,
const BufferView& view) {
FML_DCHECK(slot.ext_res_0 != VertexDescriptor::kReservedVertexBufferIndex);
if (!view) {
return false;
}
Expand Down
2 changes: 2 additions & 0 deletions impeller/renderer/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ struct BufferAndUniformSlot {
struct Bindings {
std::map<size_t, TextureAndSampler> sampled_images;
std::map<size_t, BufferAndUniformSlot> buffers;
// This is only valid for vertex bindings.
BufferAndUniformSlot vertex_buffer;
};

//------------------------------------------------------------------------------
Expand Down