Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

[Impeller] uniform offsets account for size #39077

Merged
merged 2 commits into from
Jan 23, 2023
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
6 changes: 4 additions & 2 deletions impeller/entity/contents/runtime_effect_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ bool RuntimeEffectContents::Render(const ContentContext& renderer,
///

size_t buffer_index = 0;
size_t buffer_offset = 0;
size_t sampler_index = 0;
for (auto uniform : runtime_stage_->GetUniforms()) {
// TODO(113715): Populate this metadata once GLES is able to handle
Expand Down Expand Up @@ -180,15 +181,16 @@ bool RuntimeEffectContents::Render(const ContentContext& renderer,
size_t alignment =
std::max(uniform.bit_width / 8, DefaultUniformAlignment());
auto buffer_view = pass.GetTransientsBuffer().Emplace(
uniform_data_->data() + uniform.location * sizeof(float),
uniform.GetSize(), alignment);
uniform_data_->data() + buffer_offset, uniform.GetSize(),
alignment);

ShaderUniformSlot uniform_slot;
uniform_slot.name = uniform.name.c_str();
uniform_slot.ext_res_0 = buffer_index;
cmd.BindResource(ShaderStage::kFragment, uniform_slot, metadata,
buffer_view);
buffer_index++;
buffer_offset += uniform.GetSize();
break;
}
case kBoolean:
Expand Down
4 changes: 2 additions & 2 deletions impeller/entity/entity_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2097,11 +2097,11 @@ TEST_P(EntityTest, RuntimeEffect) {
contents->SetRuntimeStage(runtime_stage);

struct FragUniforms {
Scalar iTime;
Vector2 iResolution;
Copy link
Member Author

Choose a reason for hiding this comment

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

By re-arranging these uniforms we can observe that the shader does not work without this fix. Thus, tested.

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 doesn't animate without the fix, because the first uniform gets data in 0, 1, and the second uniform gets the fixed data in 1 instead of at 2.

Scalar iTime;
} frag_uniforms = {
.iTime = static_cast<Scalar>(GetSecondsElapsed()),
.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));
Expand Down
4 changes: 2 additions & 2 deletions impeller/fixtures/runtime_stage_example.frag
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

layout(location = 0) uniform float iTime;
layout(location = 1) uniform vec2 iResolution;
layout(location = 0) uniform vec2 iResolution;
layout(location = 1) uniform float iTime;

layout(location = 0) out vec4 fragColor;

Expand Down