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
4 changes: 2 additions & 2 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 Bindings& vertex_bindings,
const Bindings& fragment_bindings) const {
for (const auto& buffer : vertex_bindings.buffers) {
if (!BindUniformBuffer(gl, transients_allocator, buffer.second)) {
if (!BindUniformBuffer(gl, transients_allocator, buffer.second.view)) {
return false;
}
}
for (const auto& buffer : fragment_bindings.buffers) {
if (!BindUniformBuffer(gl, transients_allocator, buffer.second)) {
if (!BindUniformBuffer(gl, transients_allocator, buffer.second.view)) {
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion impeller/renderer/backend/metal/compute_pass_mtl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ static bool Bind(ComputePassBindingsCache& pass,

for (const auto& buffer : command.bindings.buffers) {
if (!Bind(pass_bindings, *allocator, buffer.first,
buffer.second.resource)) {
buffer.second.view.resource)) {
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion impeller/renderer/backend/metal/render_pass_mtl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ static bool Bind(PassBindingsCache& pass,
ShaderStage stage) -> bool {
for (const auto& buffer : bindings.buffers) {
if (!Bind(pass_bindings, *allocator, stage, buffer.first,
buffer.second.resource)) {
buffer.second.view.resource)) {
return false;
}
}
Expand Down
10 changes: 5 additions & 5 deletions impeller/renderer/backend/vulkan/compute_pass_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ static bool AllocateAndBindDescriptorSets(const ContextVK& context,
&desc_set, //
&vk_desc_set //
](const Bindings& bindings) -> bool {
for (const auto& [buffer_index, view] : bindings.buffers) {
const auto& buffer_view = view.resource.buffer;
for (const auto& [buffer_index, data] : bindings.buffers) {
const auto& buffer_view = data.view.resource.buffer;

auto device_buffer = buffer_view->GetDeviceBuffer(allocator);
if (!device_buffer) {
Expand All @@ -143,14 +143,14 @@ static bool AllocateAndBindDescriptorSets(const ContextVK& context,
return false;
}

uint32_t offset = view.resource.range.offset;
uint32_t offset = data.view.resource.range.offset;

vk::DescriptorBufferInfo buffer_info;
buffer_info.buffer = buffer;
buffer_info.offset = offset;
buffer_info.range = view.resource.range.length;
buffer_info.range = data.view.resource.range.length;

const ShaderUniformSlot& uniform = bindings.uniforms.at(buffer_index);
const ShaderUniformSlot& uniform = data.slot;
auto layout_it = std::find_if(desc_set.begin(), desc_set.end(),
[&uniform](DescriptorSetLayout& layout) {
return layout.binding == uniform.binding;
Expand Down
10 changes: 5 additions & 5 deletions impeller/renderer/backend/vulkan/render_pass_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,8 @@ static bool AllocateAndBindDescriptorSets(const ContextVK& context,
&desc_set, //
&vk_desc_set //
](const Bindings& bindings) -> bool {
for (const auto& [buffer_index, view] : bindings.buffers) {
const auto& buffer_view = view.resource.buffer;
for (const auto& [buffer_index, data] : bindings.buffers) {
const auto& buffer_view = data.view.resource.buffer;

auto device_buffer = buffer_view->GetDeviceBuffer(allocator);
if (!device_buffer) {
Expand All @@ -391,14 +391,14 @@ static bool AllocateAndBindDescriptorSets(const ContextVK& context,
return false;
}

uint32_t offset = view.resource.range.offset;
uint32_t offset = data.view.resource.range.offset;

vk::DescriptorBufferInfo buffer_info;
buffer_info.buffer = buffer;
buffer_info.offset = offset;
buffer_info.range = view.resource.range.length;
buffer_info.range = data.view.resource.range.length;

const ShaderUniformSlot& uniform = bindings.uniforms.at(buffer_index);
const ShaderUniformSlot& uniform = data.slot;
auto layout_it = std::find_if(desc_set.begin(), desc_set.end(),
[&uniform](DescriptorSetLayout& layout) {
return layout.binding == uniform.binding;
Expand Down
15 changes: 7 additions & 8 deletions impeller/renderer/command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ bool Command::BindVertices(const VertexBuffer& buffer) {
return false;
}

vertex_bindings.buffers[VertexDescriptor::kReservedVertexBufferIndex] = {
nullptr, buffer.vertex_buffer};
vertex_bindings.buffers[VertexDescriptor::kReservedVertexBufferIndex] =
BufferAndUniformSlot{.slot = {}, .view = {nullptr, buffer.vertex_buffer}};
index_buffer = buffer.index_buffer;
vertex_count = buffer.vertex_count;
index_type = buffer.index_type;
Expand All @@ -30,7 +30,7 @@ BufferView Command::GetVertexBuffer() const {
auto found = vertex_bindings.buffers.find(
VertexDescriptor::kReservedVertexBufferIndex);
if (found != vertex_bindings.buffers.end()) {
return found->second.resource;
return found->second.view.resource;
}
return {};
}
Expand Down Expand Up @@ -61,13 +61,12 @@ bool Command::DoBindResource(ShaderStage stage,

switch (stage) {
case ShaderStage::kVertex:
vertex_bindings.uniforms[slot.ext_res_0] = slot;
vertex_bindings.buffers[slot.ext_res_0] = BufferResource(metadata, view);
Comment on lines -64 to -65
Copy link
Member

Choose a reason for hiding this comment

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

Note one has versus 2.

vertex_bindings.buffers[slot.ext_res_0] = {
.slot = slot, .view = BufferResource(metadata, view)};
return true;
case ShaderStage::kFragment:
fragment_bindings.uniforms[slot.ext_res_0] = slot;
fragment_bindings.buffers[slot.ext_res_0] =
BufferResource(metadata, view);
fragment_bindings.buffers[slot.ext_res_0] = {
.slot = slot, .view = BufferResource(metadata, view)};
return true;
case ShaderStage::kCompute:
VALIDATION_LOG << "Use ComputeCommands for compute shader stages.";
Expand Down
9 changes: 7 additions & 2 deletions impeller/renderer/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,15 @@ struct TextureAndSampler {
SamplerResource sampler;
};

/// @brief combines the buffer resource and its uniform slot information.
struct BufferAndUniformSlot {
ShaderUniformSlot slot;
BufferResource view;
};

struct Bindings {
std::map<size_t, ShaderUniformSlot> uniforms;
std::map<size_t, TextureAndSampler> sampled_images;
std::map<size_t, BufferResource> buffers;
std::map<size_t, BufferAndUniformSlot> buffers;
};

//------------------------------------------------------------------------------
Expand Down
3 changes: 1 addition & 2 deletions impeller/renderer/compute_command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ bool ComputeCommand::BindResource(ShaderStage stage,
return false;
}

bindings.uniforms[slot.ext_res_0] = slot;
bindings.buffers[slot.ext_res_0] = {&metadata, view};
bindings.buffers[slot.ext_res_0] = {.slot = slot, .view = {&metadata, view}};
return true;
}

Expand Down