[Impeller] uniform offsets account for size (flutter/engine#39077)

* uniform offsets account for size

* re-arrange fixtures
This commit is contained in:
Jonah Williams
2023-01-23 14:24:33 -08:00
committed by GitHub
parent fbb7aa2b4d
commit ce8689639f
3 changed files with 8 additions and 6 deletions

View File

@@ -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
@@ -180,8 +181,8 @@ 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();
@@ -189,6 +190,7 @@ bool RuntimeEffectContents::Render(const ContentContext& renderer,
cmd.BindResource(ShaderStage::kFragment, uniform_slot, metadata,
buffer_view);
buffer_index++;
buffer_offset += uniform.GetSize();
break;
}
case kBoolean:

View File

@@ -2097,11 +2097,11 @@ TEST_P(EntityTest, RuntimeEffect) {
contents->SetRuntimeStage(runtime_stage);
struct FragUniforms {
Scalar iTime;
Vector2 iResolution;
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));

View File

@@ -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;