mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Fix uniform alignment on a per platform basis.
This commit is contained in:
parent
fe94b51880
commit
b36aba2dbb
@ -34,6 +34,8 @@ impeller_component("compositor") {
|
||||
"pipeline_descriptor.mm",
|
||||
"pipeline_library.h",
|
||||
"pipeline_library.mm",
|
||||
"platform.h",
|
||||
"platform.mm",
|
||||
"range.cc",
|
||||
"range.h",
|
||||
"render_pass.h",
|
||||
|
||||
@ -12,6 +12,7 @@
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "impeller/compositor/buffer.h"
|
||||
#include "impeller/compositor/buffer_view.h"
|
||||
#include "impeller/compositor/platform.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
@ -29,6 +30,12 @@ class HostBuffer final : public std::enable_shared_from_this<HostBuffer>,
|
||||
|
||||
size_t GetReservedLength() const;
|
||||
|
||||
template <class T, class = std::enable_if_t<std::is_standard_layout_v<T>>>
|
||||
[[nodiscard]] BufferView EmplaceUniform(const T& t) {
|
||||
return Emplace(reinterpret_cast<const void*>(&t), sizeof(T),
|
||||
std::max(alignof(T), DefaultUniformAlignment()));
|
||||
}
|
||||
|
||||
template <class T, class = std::enable_if_t<std::is_standard_layout_v<T>>>
|
||||
[[nodiscard]] BufferView Emplace(const T& t) {
|
||||
return Emplace(reinterpret_cast<const void*>(&t), sizeof(T), alignof(T));
|
||||
|
||||
24
engine/src/flutter/impeller/compositor/platform.h
Normal file
24
engine/src/flutter/impeller/compositor/platform.h
Normal file
@ -0,0 +1,24 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
#include "flutter/fml/build_config.h"
|
||||
#include "flutter/fml/macros.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
constexpr size_t DefaultUniformAlignment() {
|
||||
#if OS_IOS
|
||||
return 16u;
|
||||
#elif OS_MACOSX
|
||||
return 256u;
|
||||
#else
|
||||
#error "Unsupported platform".
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
11
engine/src/flutter/impeller/compositor/platform.mm
Normal file
11
engine/src/flutter/impeller/compositor/platform.mm
Normal file
@ -0,0 +1,11 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "impeller/compositor/platform.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
//
|
||||
|
||||
} // namespace impeller
|
||||
@ -71,6 +71,8 @@ class RenderPass {
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
void SetLabel(std::string label);
|
||||
|
||||
HostBuffer& GetTransientsBuffer();
|
||||
|
||||
[[nodiscard]] bool RecordCommand(Command command);
|
||||
@ -84,6 +86,7 @@ class RenderPass {
|
||||
MTLRenderPassDescriptor* desc_ = nil;
|
||||
std::vector<Command> commands_;
|
||||
std::shared_ptr<HostBuffer> transients_buffer_;
|
||||
std::string label_;
|
||||
bool is_valid_ = false;
|
||||
|
||||
RenderPass(id<MTLCommandBuffer> buffer, const RenderPassDescriptor& desc);
|
||||
|
||||
@ -137,14 +137,24 @@ bool RenderPass::IsValid() const {
|
||||
return is_valid_;
|
||||
}
|
||||
|
||||
void RenderPass::SetLabel(std::string label) {
|
||||
label_ = std::move(label);
|
||||
}
|
||||
|
||||
bool RenderPass::FinishEncoding(Allocator& transients_allocator) const {
|
||||
if (!IsValid()) {
|
||||
return false;
|
||||
}
|
||||
auto pass = [buffer_ renderCommandEncoderWithDescriptor:desc_];
|
||||
|
||||
if (!pass) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!label_.empty()) {
|
||||
[pass setLabel:@(label_.c_str())];
|
||||
}
|
||||
|
||||
// Success or failure, the pass must end. The buffer can only process one pass
|
||||
// at a time.
|
||||
fml::ScopedCleanupClosure auto_end([pass]() { [pass endEncoding]; });
|
||||
|
||||
@ -36,6 +36,8 @@ bool EntityRenderer::OnIsValid() const {
|
||||
}
|
||||
|
||||
bool EntityRenderer::OnRender(RenderPass& pass) {
|
||||
pass.SetLabel("EntityRenderer");
|
||||
|
||||
shader::BoxVertexInfo::UniformBuffer uniforms;
|
||||
uniforms.mvp = Matrix::MakeOrthographic({800, 600});
|
||||
VertexBufferBuilder vertices;
|
||||
@ -47,14 +49,14 @@ bool EntityRenderer::OnRender(RenderPass& pass) {
|
||||
});
|
||||
|
||||
Command cmd;
|
||||
cmd.label = "Simple Box";
|
||||
cmd.label = "Box";
|
||||
cmd.pipeline = box_primitive_->GetPipeline();
|
||||
cmd.vertex_bindings
|
||||
.buffers[shader::BoxVertexInfo::kUniformUniformBuffer.location] =
|
||||
pass.GetTransientsBuffer().Emplace(uniforms);
|
||||
cmd.vertex_bindings
|
||||
.buffers[shader::BoxVertexInfo::kInputVertexPosition.location] =
|
||||
vertices.CreateVertexBuffer(pass.GetTransientsBuffer());
|
||||
cmd.vertex_bindings
|
||||
.buffers[shader::BoxVertexInfo::kUniformUniformBuffer.location] =
|
||||
pass.GetTransientsBuffer().EmplaceUniform(uniforms);
|
||||
cmd.index_buffer = vertices.CreateIndexBuffer(pass.GetTransientsBuffer());
|
||||
cmd.index_count = vertices.GetIndexCount();
|
||||
if (!pass.RecordCommand(std::move(cmd))) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user