Debug and fix buffer management.

This commit is contained in:
Chinmay Garde
2021-06-21 15:01:40 -07:00
committed by Dan Field
parent b36aba2dbb
commit 27a7f7e831
8 changed files with 20 additions and 19 deletions

View File

@@ -378,7 +378,6 @@ Compiler::SourceType Compiler::SourceTypeFromFileName(
std::string Compiler::EntryPointFromSourceName(const std::string& file_name,
SourceType type) {
std::stringstream stream;
stream << "__impeller_";
std::filesystem::path file_path(file_name);
stream << file_path.stem().native() << "_";
switch (type) {
@@ -392,7 +391,7 @@ std::string Compiler::EntryPointFromSourceName(const std::string& file_name,
stream << "fragment";
break;
}
stream << "_main__";
stream << "_main";
return stream.str();
}

View File

@@ -32,7 +32,7 @@ id<MTLBuffer> DeviceBuffer::GetMTLBuffer() const {
return false;
}
::memcpy(dest + offset, source + source_range.offset, source_range.length);
::memmove(dest + offset, source + source_range.offset, source_range.length);
[buffer_ didModifyRange:NSMakeRange(offset, source_range.length)];

View File

@@ -61,7 +61,7 @@ BufferView HostBuffer::Emplace(const void* buffer, size_t length) {
FML_DCHECK(buffer_);
generation_++;
if (buffer) {
::memmove(buffer_, buffer, length);
::memmove(buffer_ + old_length, buffer, length);
}
return BufferView{shared_from_this(), Range{old_length, length}};
}

View File

@@ -258,6 +258,8 @@ bool RenderPass::EncodeCommands(Allocator& allocator,
if (!mtl_index_buffer) {
return false;
}
FML_DCHECK(command.index_count * sizeof(uint32_t) ==
command.index_buffer.range.length);
[pass drawIndexedPrimitives:MTLPrimitiveTypeTriangleStrip
indexCount:command.index_count
indexType:MTLIndexTypeUInt32

View File

@@ -41,13 +41,14 @@ class VertexDescriptor final : public Comparable<VertexDescriptor> {
struct StageInput {
size_t location;
MTLVertexFormat format;
size_t stride;
size_t length;
StageInput(size_t p_location, MTLVertexFormat p_format, size_t p_stride)
: location(p_location), format(p_format), stride(p_stride) {}
StageInput(size_t p_location, MTLVertexFormat p_format, size_t p_length)
: location(p_location), format(p_format), length(p_length) {}
constexpr bool operator==(const StageInput& other) const {
return location == other.location && format == other.format;
return location == other.location && format == other.format &&
length == other.length;
}
};
std::vector<StageInput> stage_inputs_;

View File

@@ -181,7 +181,8 @@ bool VertexDescriptor::SetStageInputs(
return false;
}
stage_inputs_.emplace_back(
StageInput{input->location, vertex_format, input->bit_width / 8});
StageInput{input->location, vertex_format,
(input->bit_width * input->vec_size) / 8});
}
return true;
@@ -198,7 +199,7 @@ MTLVertexDescriptor* VertexDescriptor::GetMTLVertexDescriptor() const {
// All vertex inputs are interleaved and tightly packed in one buffer at
// zero index.
attrib.bufferIndex = 0u;
stride += input.stride;
stride += input.length;
}
descriptor.layouts[0].stride = stride;

View File

@@ -42,20 +42,18 @@ bool EntityRenderer::OnRender(RenderPass& pass) {
uniforms.mvp = Matrix::MakeOrthographic({800, 600});
VertexBufferBuilder vertices;
vertices.AddVertices({
{-0.5, 0.5}, //
{0.5, 0.5}, //
{0.5, -0.5}, //
{-0.5, 0.5}, //
{-0.5, 0.5, 1.0}, //
{0.5, 0.5, 1.0}, //
{0.5, -0.5, 1.0}, //
{-0.5, -0.5, 1.0}, //
});
Command cmd;
cmd.label = "Box";
cmd.pipeline = box_primitive_->GetPipeline();
cmd.vertex_bindings
.buffers[shader::BoxVertexInfo::kInputVertexPosition.location] =
cmd.vertex_bindings.buffers[0u] =
vertices.CreateVertexBuffer(pass.GetTransientsBuffer());
cmd.vertex_bindings
.buffers[shader::BoxVertexInfo::kUniformUniformBuffer.location] =
cmd.vertex_bindings.buffers[1u] =
pass.GetTransientsBuffer().EmplaceUniform(uniforms);
cmd.index_buffer = vertices.CreateIndexBuffer(pass.GetTransientsBuffer());
cmd.index_count = vertices.GetIndexCount();

View File

@@ -9,5 +9,5 @@ uniform UniformBuffer {
in vec3 vertexPosition;
void main() {
gl_Position = uniforms.mvp * vec4(vertexPosition, 1.0);
gl_Position = vec4(vertexPosition, 1.0);
}