|
48 | 48 | #include "impeller/renderer/command.h"
|
49 | 49 | #include "impeller/renderer/pipeline_descriptor.h"
|
50 | 50 | #include "impeller/renderer/render_pass.h"
|
| 51 | +#include "impeller/renderer/render_target.h" |
| 52 | +#include "impeller/renderer/testing/mocks.h" |
51 | 53 | #include "impeller/renderer/vertex_buffer_builder.h"
|
52 | 54 | #include "impeller/typographer/backends/skia/text_frame_skia.h"
|
53 | 55 | #include "impeller/typographer/backends/skia/typographer_context_skia.h"
|
@@ -2178,6 +2180,53 @@ TEST_P(EntityTest, RuntimeEffect) {
|
2178 | 2180 | ASSERT_TRUE(OpenPlaygroundHere(callback));
|
2179 | 2181 | }
|
2180 | 2182 |
|
| 2183 | +TEST_P(EntityTest, RuntimeEffectSetsRightSizeWhenUniformIsStruct) { |
| 2184 | + if (GetBackend() != PlaygroundBackend::kVulkan) { |
| 2185 | + GTEST_SKIP() << "Test only applies to Vulkan"; |
| 2186 | + } |
| 2187 | + |
| 2188 | + auto runtime_stages = |
| 2189 | + OpenAssetAsRuntimeStage("runtime_stage_example.frag.iplr"); |
| 2190 | + auto runtime_stage = |
| 2191 | + runtime_stages[PlaygroundBackendToRuntimeStageBackend(GetBackend())]; |
| 2192 | + ASSERT_TRUE(runtime_stage); |
| 2193 | + ASSERT_TRUE(runtime_stage->IsDirty()); |
| 2194 | + |
| 2195 | + auto contents = std::make_shared<RuntimeEffectContents>(); |
| 2196 | + contents->SetGeometry(Geometry::MakeCover()); |
| 2197 | + |
| 2198 | + contents->SetRuntimeStage(runtime_stage); |
| 2199 | + |
| 2200 | + struct FragUniforms { |
| 2201 | + Vector2 iResolution; |
| 2202 | + Scalar iTime; |
| 2203 | + } frag_uniforms = { |
| 2204 | + .iResolution = Vector2(GetWindowSize().width, GetWindowSize().height), |
| 2205 | + .iTime = static_cast<Scalar>(GetSecondsElapsed()), |
| 2206 | + }; |
| 2207 | + auto uniform_data = std::make_shared<std::vector<uint8_t>>(); |
| 2208 | + uniform_data->resize(sizeof(FragUniforms)); |
| 2209 | + memcpy(uniform_data->data(), &frag_uniforms, sizeof(FragUniforms)); |
| 2210 | + contents->SetUniformData(uniform_data); |
| 2211 | + |
| 2212 | + Entity entity; |
| 2213 | + entity.SetContents(contents); |
| 2214 | + |
| 2215 | + auto context = GetContentContext(); |
| 2216 | + RenderTarget target; |
| 2217 | + testing::MockRenderPass pass(GetContext(), target); |
| 2218 | + ASSERT_TRUE(contents->Render(*context, entity, pass)); |
| 2219 | + ASSERT_EQ(pass.GetCommands().size(), 1u); |
| 2220 | + const auto& command = pass.GetCommands()[0]; |
| 2221 | + ASSERT_EQ(command.fragment_bindings.buffers.size(), 1u); |
| 2222 | + // 16 bytes: |
| 2223 | + // 8 bytes for iResolution |
| 2224 | + // 4 bytes padding |
| 2225 | + // 4 bytes for iTime |
| 2226 | + EXPECT_EQ(command.fragment_bindings.buffers[0].view.resource.range.length, |
| 2227 | + 16u); |
| 2228 | +} |
| 2229 | + |
2181 | 2230 | TEST_P(EntityTest, InheritOpacityTest) {
|
2182 | 2231 | Entity entity;
|
2183 | 2232 |
|
|
0 commit comments