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
3 changes: 2 additions & 1 deletion impeller/entity/contents/text_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,9 @@ bool TextContents::Render(const ContentContext& renderer,
}
});

pass.SetVertexBuffer(std::move(buffer_view), vertex_count);
pass.SetVertexBuffer(std::move(buffer_view));
pass.SetIndexBuffer({}, IndexType::kNone);
pass.SetElementCount(vertex_count);

return pass.Draw().ok();
}
Expand Down
2 changes: 1 addition & 1 deletion impeller/renderer/backend/gles/buffer_bindings_gles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,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.sampler);
const auto& sampler_gles = SamplerGLES::Cast(**data.sampler);
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this count as making you a two star programmer? :)

Copy link
Member Author

Choose a reason for hiding this comment

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

One day I'll sneak three stars in and become a legend.

if (!sampler_gles.ConfigureBoundTexture(texture_gles, gl)) {
return std::nullopt;
}
Expand Down
4 changes: 2 additions & 2 deletions impeller/renderer/backend/gles/render_pass_gles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ static bool BindVertexBuffer(const ProcTableGLES& gl,
/// Finally! Invoke the draw call.
///
if (command.index_type == IndexType::kNone) {
gl.DrawArrays(mode, command.base_vertex, command.vertex_count);
gl.DrawArrays(mode, command.base_vertex, command.element_count);
} else {
// Bind the index buffer if necessary.
auto index_buffer_view = command.index_buffer;
Expand All @@ -466,7 +466,7 @@ static bool BindVertexBuffer(const ProcTableGLES& gl,
return false;
}
gl.DrawElements(mode, // mode
command.vertex_count, // count
command.element_count, // count
ToIndexType(command.index_type), // type
reinterpret_cast<const GLvoid*>(static_cast<GLsizei>(
index_buffer_view.range.offset)) // indices
Expand Down
6 changes: 4 additions & 2 deletions impeller/renderer/backend/metal/render_pass_mtl.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,15 @@ class RenderPassMTL final : public RenderPass {
// |RenderPass|
void SetScissor(IRect scissor) override;

// |RenderPass|
void SetElementCount(size_t count) override;

// |RenderPass|
void SetInstanceCount(size_t count) override;

// |RenderPass|
bool SetVertexBuffer(BufferView vertex_buffers[],
size_t vertex_buffer_count,
size_t vertex_count) override;
size_t vertex_buffer_count) override;

// |RenderPass|
bool SetIndexBuffer(BufferView index_buffer, IndexType index_type) override;
Expand Down
10 changes: 6 additions & 4 deletions impeller/renderer/backend/metal/render_pass_mtl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -283,15 +283,19 @@ static bool Bind(PassBindingsCacheMTL& pass,
pass_bindings_.SetScissor(scissor);
}

// |RenderPass|
void RenderPassMTL::SetElementCount(size_t count) {
vertex_count_ = count;
}

// |RenderPass|
void RenderPassMTL::SetInstanceCount(size_t count) {
instance_count_ = count;
}

// |RenderPass|
bool RenderPassMTL::SetVertexBuffer(BufferView vertex_buffers[],
size_t vertex_buffer_count,
size_t vertex_count) {
size_t vertex_buffer_count) {
if (!ValidateVertexBuffers(vertex_buffers, vertex_buffer_count)) {
return false;
}
Expand All @@ -304,8 +308,6 @@ static bool Bind(PassBindingsCacheMTL& pass,
}
}

vertex_count_ = vertex_count;

return true;
}

Expand Down
16 changes: 9 additions & 7 deletions impeller/renderer/backend/vulkan/render_pass_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -365,15 +365,19 @@ void RenderPassVK::SetScissor(IRect scissor) {
command_buffer_vk_.setScissor(0, 1, &scissor_vk);
}

// |RenderPass|
void RenderPassVK::SetElementCount(size_t count) {
element_count_ = count;
}

// |RenderPass|
void RenderPassVK::SetInstanceCount(size_t count) {
instance_count_ = count;
}

// |RenderPass|
bool RenderPassVK::SetVertexBuffer(BufferView vertex_buffers[],
size_t vertex_buffer_count,
size_t vertex_count) {
size_t vertex_buffer_count) {
if (!ValidateVertexBuffers(vertex_buffers, vertex_buffer_count)) {
return false;
}
Expand All @@ -390,8 +394,6 @@ bool RenderPassVK::SetVertexBuffer(BufferView vertex_buffers[],
command_buffer_vk_.bindVertexBuffers(0u, vertex_buffer_count, buffers,
vertex_buffer_offsets);

vertex_count_ = vertex_count;

return true;
}

Expand Down Expand Up @@ -507,14 +509,14 @@ fml::Status RenderPassVK::Draw() {
}

if (has_index_buffer_) {
command_buffer_vk_.drawIndexed(vertex_count_, // index count
command_buffer_vk_.drawIndexed(element_count_, // index count
instance_count_, // instance count
0u, // first index
base_vertex_, // vertex offset
0u // first instance
);
} else {
command_buffer_vk_.draw(vertex_count_, // vertex count
command_buffer_vk_.draw(element_count_, // vertex count
instance_count_, // instance count
base_vertex_, // vertex offset
0u // first instance
Expand All @@ -533,7 +535,7 @@ fml::Status RenderPassVK::Draw() {
descriptor_write_offset_ = 0u;
instance_count_ = 1u;
base_vertex_ = 0u;
vertex_count_ = 0u;
element_count_ = 0u;
pipeline_ = nullptr;
pipeline_uses_input_attachments_ = false;
immutable_sampler_ = nullptr;
Expand Down
8 changes: 5 additions & 3 deletions impeller/renderer/backend/vulkan/render_pass_vk.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class RenderPassVK final : public RenderPass {
size_t descriptor_write_offset_ = 0u;
size_t instance_count_ = 1u;
size_t base_vertex_ = 0u;
size_t vertex_count_ = 0u;
size_t element_count_ = 0u;
bool has_index_buffer_ = false;
bool has_label_ = false;
const Pipeline<PipelineDescriptor>* pipeline_;
Expand Down Expand Up @@ -76,13 +76,15 @@ class RenderPassVK final : public RenderPass {
// |RenderPass|
void SetScissor(IRect scissor) override;

// |RenderPass|
void SetElementCount(size_t count) override;

// |RenderPass|
void SetInstanceCount(size_t count) override;

// |RenderPass|
bool SetVertexBuffer(BufferView vertex_buffers[],
size_t vertex_buffer_count,
size_t vertex_count) override;
size_t vertex_buffer_count) override;

// |RenderPass|
bool SetIndexBuffer(BufferView index_buffer, IndexType index_type) override;
Expand Down
6 changes: 3 additions & 3 deletions impeller/renderer/command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ bool Command::BindVertices(const VertexBuffer& buffer) {

vertex_buffers = {buffer.vertex_buffer};
vertex_buffer_count = 1u;
vertex_count = buffer.vertex_count;
element_count = buffer.vertex_count;
index_buffer = buffer.index_buffer;
index_type = buffer.index_type;
return true;
Expand Down Expand Up @@ -89,14 +89,14 @@ bool Command::BindResource(ShaderStage stage,
vertex_bindings.sampled_images.emplace_back(TextureAndSampler{
.slot = slot,
.texture = {&metadata, std::move(texture)},
.sampler = sampler,
.sampler = &sampler,
});
return true;
case ShaderStage::kFragment:
fragment_bindings.sampled_images.emplace_back(TextureAndSampler{
.slot = slot,
.texture = {&metadata, std::move(texture)},
.sampler = sampler,
.sampler = &sampler,
});
return true;
case ShaderStage::kCompute:
Expand Down
9 changes: 4 additions & 5 deletions impeller/renderer/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ using TextureResource = Resource<std::shared_ptr<const Texture>>;
struct TextureAndSampler {
SampledImageSlot slot;
TextureResource texture;
const std::unique_ptr<const Sampler>& sampler;
const std::unique_ptr<const Sampler>* sampler;
};

/// @brief combines the buffer resource and its uniform slot information.
Expand Down Expand Up @@ -160,14 +160,13 @@ struct Command : public ResourceBinder {
BufferView index_buffer;

//----------------------------------------------------------------------------
/// The total count of vertices, either in the vertex_buffer if the
/// index_type is IndexType::kNone or in the index_buffer otherwise.
size_t vertex_count = 0u;
/// The number of elements to draw. When only a vertex buffer is set, this is
/// the vertex count. When an index buffer is set, this is the index count.
size_t element_count = 0u;

//----------------------------------------------------------------------------
/// The type of indices in the index buffer. The indices must be tightly
/// packed in the index buffer.
///
IndexType index_type = IndexType::kUnknown;

//----------------------------------------------------------------------------
Expand Down
24 changes: 12 additions & 12 deletions impeller/renderer/render_pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ bool RenderPass::AddCommand(Command&& command) {
}
}

if (command.vertex_count == 0u || command.instance_count == 0u) {
if (command.element_count == 0u || command.instance_count == 0u) {
// Essentially a no-op. Don't record the command but this is not necessary
// an error either.
return true;
Expand Down Expand Up @@ -117,40 +117,40 @@ void RenderPass::SetScissor(IRect scissor) {
pending_.scissor = scissor;
}

void RenderPass::SetElementCount(size_t count) {
pending_.element_count = count;
}

void RenderPass::SetInstanceCount(size_t count) {
pending_.instance_count = count;
}

bool RenderPass::SetVertexBuffer(VertexBuffer buffer) {
if (!SetVertexBuffer(&buffer.vertex_buffer, 1u, buffer.vertex_count)) {
if (!SetVertexBuffer(&buffer.vertex_buffer, 1u)) {
return false;
}
if (!SetIndexBuffer(buffer.index_buffer, buffer.index_type)) {
return false;
}
SetElementCount(buffer.vertex_count);

return true;
}

bool RenderPass::SetVertexBuffer(BufferView vertex_buffer,
size_t vertex_count) {
return SetVertexBuffer(&vertex_buffer, 1, vertex_count);
bool RenderPass::SetVertexBuffer(BufferView vertex_buffer) {
return SetVertexBuffer(&vertex_buffer, 1);
}

bool RenderPass::SetVertexBuffer(std::vector<BufferView> vertex_buffers,
size_t vertex_count) {
return SetVertexBuffer(vertex_buffers.data(), vertex_buffers.size(),
vertex_count);
bool RenderPass::SetVertexBuffer(std::vector<BufferView> vertex_buffers) {
return SetVertexBuffer(vertex_buffers.data(), vertex_buffers.size());
}

bool RenderPass::SetVertexBuffer(BufferView vertex_buffers[],
size_t vertex_buffer_count,
size_t vertex_count) {
size_t vertex_buffer_count) {
if (!ValidateVertexBuffers(vertex_buffers, vertex_buffer_count)) {
return false;
}

pending_.vertex_count = vertex_count;
pending_.vertex_buffer_count = vertex_buffer_count;
for (size_t i = 0; i < vertex_buffer_count; i++) {
pending_.vertex_buffers[i] = std::move(vertex_buffers[i]);
Expand Down
27 changes: 13 additions & 14 deletions impeller/renderer/render_pass.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ class RenderPass : public ResourceBinder {
///
virtual void SetScissor(IRect scissor);

//----------------------------------------------------------------------------
/// The number of elements to draw. When only a vertex buffer is set, this is
/// the vertex count. When an index buffer is set, this is the index count.
///
virtual void SetElementCount(size_t count);
Copy link
Member Author

Choose a reason for hiding this comment

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

New method in RenderPass here.


//----------------------------------------------------------------------------
/// The number of instances of the given set of vertices to render. Not all
/// backends support rendering more than one instance at a time.
Expand All @@ -115,11 +121,9 @@ class RenderPass : public ResourceBinder {
///
/// @param[in] vertex_buffer The buffer view to use for sourcing vertices.
///
/// @param[in] vertex_count The number of vertices to draw.
///
/// @return Returns false if the given buffer view is invalid.
///
bool SetVertexBuffer(BufferView vertex_buffer, size_t vertex_count);
bool SetVertexBuffer(BufferView vertex_buffer);
Copy link
Member Author

Choose a reason for hiding this comment

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

This patch removes vertex_count from SetVertexBuffer. It gets set via SetElementCount now. (This value becomes the index count when an index buffer is present)


//----------------------------------------------------------------------------
/// @brief Specify a set of vertex buffers to use for this command.
Expand All @@ -131,12 +135,9 @@ class RenderPass : public ResourceBinder {
/// @param[in] vertex_buffers The array of vertex buffer views to use.
/// The maximum number of vertex buffers is 16.
///
/// @param[in] vertex_count The number of vertices to draw.
///
/// @return Returns false if any of the given buffer views are invalid.
///
bool SetVertexBuffer(std::vector<BufferView> vertex_buffers,
size_t vertex_count);
bool SetVertexBuffer(std::vector<BufferView> vertex_buffers);

//----------------------------------------------------------------------------
/// @brief Specify a set of vertex buffers to use for this command.
Expand All @@ -152,22 +153,20 @@ class RenderPass : public ResourceBinder {
/// @param[in] vertex_buffer_count The number of vertex buffers to copy from
/// the array (max 16).
///
/// @param[in] vertex_count The number of vertices to draw.
///
/// @return Returns false if any of the given buffer views are invalid.
///
virtual bool SetVertexBuffer(BufferView vertex_buffers[],
size_t vertex_buffer_count,
size_t vertex_count);
size_t vertex_buffer_count);

//----------------------------------------------------------------------------
/// @brief Specify an index buffer to use for this command.
/// To unset the index buffer, pass IndexType::kNone to
/// index_type.
///
/// @param[in] index_buffer The buffer view to use for sourcing indices. The
/// total number of indices is inferred from the
/// buffer view size and index type.
/// @param[in] index_buffer The buffer view to use for sourcing indices.
/// When an index buffer is bound, the
/// `vertex_count` set via `SetVertexBuffer` is used
/// as the number of indices to draw.
///
/// @param[in] index_type The size of each index in the index buffer. Pass
/// IndexType::kNone to unset the index buffer.
Expand Down
3 changes: 2 additions & 1 deletion impeller/renderer/renderer_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,8 @@ TEST_P(RendererTest, CanRenderPerspectiveCube) {
BufferView index_buffer = {
.buffer = device_buffer,
.range = Range(offsetof(Cube, indices), sizeof(Cube::indices))};
pass.SetVertexBuffer(vertex_buffers.data(), vertex_buffers.size(), 36);
pass.SetVertexBuffer(vertex_buffers.data(), vertex_buffers.size());
pass.SetElementCount(36);
pass.SetIndexBuffer(index_buffer, IndexType::k16bit);

VS::UniformBuffer uniforms;
Expand Down
Loading