Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CP] [Impeller] uniform offsets account for size (#39077) #39079

Merged
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 @@ -2088,11 +2088,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));
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