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 1 commit
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/entity/contents/runtime_effect_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ bool RuntimeEffectContents::Render(const ContentContext& renderer,
DefaultUniformAlignment());

auto buffer_view = renderer.GetTransientsBuffer().Emplace(
reinterpret_cast<const void*>(uniform_buffer.data()), alignment,
alignment);
reinterpret_cast<const void*>(uniform_buffer.data()),
sizeof(float) * uniform_buffer.size(), alignment);
cmd.BindResource(ShaderStage::kFragment, uniform_slot, ShaderMetadata{},
buffer_view);
}
Expand Down
49 changes: 49 additions & 0 deletions impeller/entity/entity_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
#include "impeller/renderer/command.h"
#include "impeller/renderer/pipeline_descriptor.h"
#include "impeller/renderer/render_pass.h"
#include "impeller/renderer/render_target.h"
#include "impeller/renderer/testing/mocks.h"
#include "impeller/renderer/vertex_buffer_builder.h"
#include "impeller/typographer/backends/skia/text_frame_skia.h"
#include "impeller/typographer/backends/skia/typographer_context_skia.h"
Expand Down Expand Up @@ -2178,6 +2180,53 @@ TEST_P(EntityTest, RuntimeEffect) {
ASSERT_TRUE(OpenPlaygroundHere(callback));
}

TEST_P(EntityTest, RuntimeEffectSetsRightSizeWhenUniformIsStruct) {
if (GetBackend() != PlaygroundBackend::kVulkan) {
GTEST_SKIP() << "Test only applies to Vulkan";
}

auto runtime_stages =
OpenAssetAsRuntimeStage("runtime_stage_example.frag.iplr");
auto runtime_stage =
runtime_stages[PlaygroundBackendToRuntimeStageBackend(GetBackend())];
ASSERT_TRUE(runtime_stage);
ASSERT_TRUE(runtime_stage->IsDirty());

auto contents = std::make_shared<RuntimeEffectContents>();
contents->SetGeometry(Geometry::MakeCover());

contents->SetRuntimeStage(runtime_stage);

struct FragUniforms {
Vector2 iResolution;
Scalar iTime;
} frag_uniforms = {
.iResolution = Vector2(GetWindowSize().width, GetWindowSize().height),
.iTime = static_cast<Scalar>(GetSecondsElapsed()),
};
auto uniform_data = std::make_shared<std::vector<uint8_t>>();
uniform_data->resize(sizeof(FragUniforms));
memcpy(uniform_data->data(), &frag_uniforms, sizeof(FragUniforms));
contents->SetUniformData(uniform_data);

Entity entity;
entity.SetContents(contents);

auto context = GetContentContext();
RenderTarget target;
testing::MockRenderPass pass(GetContext(), target);
ASSERT_TRUE(contents->Render(*context, entity, pass));
ASSERT_EQ(pass.GetCommands().size(), 1u);
const auto& command = pass.GetCommands()[0];
ASSERT_EQ(command.fragment_bindings.buffers.size(), 1u);
// 16 bytes:
// 8 bytes for iResolution
// 4 bytes for iTime
// 4 bytes padding
EXPECT_EQ(command.fragment_bindings.buffers[0].view.resource.range.length,
16u);
}

TEST_P(EntityTest, InheritOpacityTest) {
Entity entity;

Expand Down