Skip to content

Commit 42eec62

Browse files
author
Jonah Williams
authored
[Impeller] uniform offsets account for size (flutter#39077)
* uniform offsets account for size * re-arrange fixtures
1 parent f02a704 commit 42eec62

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

impeller/entity/contents/runtime_effect_contents.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ bool RuntimeEffectContents::Render(const ContentContext& renderer,
152152
///
153153

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

186187
ShaderUniformSlot uniform_slot;
187188
uniform_slot.name = uniform.name.c_str();
188189
uniform_slot.ext_res_0 = buffer_index;
189190
cmd.BindResource(ShaderStage::kFragment, uniform_slot, metadata,
190191
buffer_view);
191192
buffer_index++;
193+
buffer_offset += uniform.GetSize();
192194
break;
193195
}
194196
case kBoolean:

impeller/entity/entity_unittests.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2097,11 +2097,11 @@ TEST_P(EntityTest, RuntimeEffect) {
20972097
contents->SetRuntimeStage(runtime_stage);
20982098

20992099
struct FragUniforms {
2100-
Scalar iTime;
21012100
Vector2 iResolution;
2101+
Scalar iTime;
21022102
} frag_uniforms = {
2103-
.iTime = static_cast<Scalar>(GetSecondsElapsed()),
21042103
.iResolution = Vector2(GetWindowSize().width, GetWindowSize().height),
2104+
.iTime = static_cast<Scalar>(GetSecondsElapsed()),
21052105
};
21062106
auto uniform_data = std::make_shared<std::vector<uint8_t>>();
21072107
uniform_data->resize(sizeof(FragUniforms));

impeller/fixtures/runtime_stage_example.frag

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
layout(location = 0) uniform float iTime;
6-
layout(location = 1) uniform vec2 iResolution;
5+
layout(location = 0) uniform vec2 iResolution;
6+
layout(location = 1) uniform float iTime;
77

88
layout(location = 0) out vec4 fragColor;
99

0 commit comments

Comments
 (0)