47 flatbuffers::FlatBufferBuilder builder;
48 fb::RuntimeStagesBuilder stages_builder(builder);
49 stages_builder.add_format_version(0);
50 auto stages = stages_builder.Finish();
51 builder.Finish(stages, fb::RuntimeStagesIdentifier());
52 auto mapping = std::make_shared<fml::NonOwnedMapping>(
53 builder.GetBufferPointer(), builder.GetSize());
55 EXPECT_FALSE(runtime_stages.ok());
56 EXPECT_EQ(runtime_stages.status().code(), absl::StatusCode::kInvalidArgument);
76 const std::shared_ptr<fml::Mapping> fixture =
78 "all_supported_uniforms.frag.iplr");
80 ASSERT_GT(fixture->GetSize(), 0u);
82 ABSL_ASSERT_OK(stages);
83 auto stage = stages.value()[GetRuntimeStageBackend()];
86 switch (GetBackend()) {
94 ASSERT_EQ(stage->GetUniforms().size(), 14u);
97 auto uni = stage->GetUniform(
"uFloat");
98 ASSERT_NE(uni,
nullptr);
99 EXPECT_EQ(uni->dimensions.rows, 1u);
100 EXPECT_EQ(uni->dimensions.cols, 1u);
101 EXPECT_EQ(uni->location, 0u);
103 EXPECT_TRUE(uni->padding_layout.empty());
107 auto uni = stage->GetUniform(
"uVec2");
108 ASSERT_NE(uni,
nullptr);
109 EXPECT_EQ(uni->dimensions.rows, 2u);
110 EXPECT_EQ(uni->dimensions.cols, 1u);
111 EXPECT_EQ(uni->location, 1u);
113 EXPECT_TRUE(uni->padding_layout.empty());
117 auto uni = stage->GetUniform(
"uVec3");
118 ASSERT_NE(uni,
nullptr);
119 EXPECT_EQ(uni->dimensions.rows, 3u);
120 EXPECT_EQ(uni->dimensions.cols, 1u);
121 EXPECT_EQ(uni->location, 2u);
123 auto padding = uni->padding_layout;
137 auto uni = stage->GetUniform(
"uVec4");
138 ASSERT_NE(uni,
nullptr);
139 EXPECT_EQ(uni->dimensions.rows, 4u);
140 EXPECT_EQ(uni->dimensions.cols, 1u);
141 EXPECT_EQ(uni->location, 3u);
143 EXPECT_TRUE(uni->padding_layout.empty());
147 auto uni = stage->GetUniform(
"uMat2");
148 ASSERT_NE(uni,
nullptr);
149 EXPECT_EQ(uni->dimensions.rows, 2u);
150 EXPECT_EQ(uni->dimensions.cols, 2u);
151 EXPECT_EQ(uni->location, 4u);
153 EXPECT_TRUE(uni->padding_layout.empty());
157 auto uni = stage->GetUniform(
"uMat3");
158 ASSERT_NE(uni,
nullptr);
159 EXPECT_EQ(uni->dimensions.rows, 3u);
160 EXPECT_EQ(uni->dimensions.cols, 3u);
161 EXPECT_EQ(uni->location, 5u);
166 auto uni = stage->GetUniform(
"uMat4");
167 ASSERT_NE(uni,
nullptr);
168 EXPECT_EQ(uni->dimensions.rows, 4u);
169 EXPECT_EQ(uni->dimensions.cols, 4u);
170 EXPECT_EQ(uni->location, 6u);
172 EXPECT_TRUE(uni->padding_layout.empty());
176 auto uni = stage->GetUniform(
"uFloatArray");
177 ASSERT_NE(uni,
nullptr);
178 EXPECT_EQ(uni->dimensions.rows, 1u);
179 EXPECT_EQ(uni->dimensions.cols, 1u);
180 EXPECT_EQ(uni->location, 7u);
182 EXPECT_TRUE(uni->padding_layout.empty());
185 auto uni = stage->GetUniform(
"uVec2Array");
186 ASSERT_NE(uni,
nullptr);
187 EXPECT_EQ(uni->dimensions.rows, 2u);
188 EXPECT_EQ(uni->dimensions.cols, 1u);
189 EXPECT_EQ(uni->location, 9u);
191 EXPECT_TRUE(uni->padding_layout.empty());
195 auto uni = stage->GetUniform(
"uVec3Array");
196 ASSERT_NE(uni,
nullptr);
197 EXPECT_EQ(uni->dimensions.rows, 3u);
198 EXPECT_EQ(uni->dimensions.cols, 1u);
199 EXPECT_EQ(uni->location, 11u);
204 auto uni = stage->GetUniform(
"uVec4Array");
205 ASSERT_NE(uni,
nullptr);
206 EXPECT_EQ(uni->dimensions.rows, 4u);
207 EXPECT_EQ(uni->dimensions.cols, 1u);
208 EXPECT_EQ(uni->location, 13u);
210 EXPECT_TRUE(uni->padding_layout.empty());
214 auto uni = stage->GetUniform(
"uMat2Array");
215 ASSERT_NE(uni,
nullptr);
216 EXPECT_EQ(uni->dimensions.rows, 2u);
217 EXPECT_EQ(uni->dimensions.cols, 2u);
218 EXPECT_EQ(uni->location, 15u);
220 EXPECT_TRUE(uni->padding_layout.empty());
224 auto uni = stage->GetUniform(
"uMat3Array");
225 ASSERT_NE(uni,
nullptr);
226 EXPECT_EQ(uni->dimensions.rows, 3u);
227 EXPECT_EQ(uni->dimensions.cols, 3u);
228 EXPECT_EQ(uni->location, 17u);
233 auto uni = stage->GetUniform(
"uMat4Array");
234 ASSERT_NE(uni,
nullptr);
235 EXPECT_EQ(uni->dimensions.rows, 4u);
236 EXPECT_EQ(uni->dimensions.cols, 4u);
237 EXPECT_EQ(uni->location, 19u);
239 EXPECT_TRUE(uni->padding_layout.empty());
244 EXPECT_EQ(stage->GetUniforms().size(), 1u);
252 std::vector<RuntimePaddingType> layout(uni->
GetGPUSize() /
sizeof(
float),
314 EXPECT_THAT(uni->
padding_layout, ::testing::ElementsAreArray(layout));
316 std::vector<std::pair<std::string, unsigned int>> expected_uniforms = {
317 {
"uFloat", 4}, {
"uVec2", 8}, {
"uVec3", 12},
318 {
"uVec4", 16}, {
"uMat2", 16}, {
"uMat3", 36},
319 {
"uMat4", 64}, {
"uFloatArray", 8}, {
"uVec2Array", 16},
320 {
"uVec3Array", 24}, {
"uVec4Array", 32}, {
"uMat2Array", 32},
321 {
"uMat3Array", 72}, {
"uMat4Array", 128}};
323 ASSERT_EQ(uni->
struct_fields.size(), expected_uniforms.size());
325 for (
size_t i = 0;
i < expected_uniforms.size(); ++
i) {
327 const auto& expected = expected_uniforms[
i];
329 EXPECT_EQ(element.name, expected.first) <<
"index: " <<
i;
330 EXPECT_EQ(element.byte_size, expected.second) <<
"index: " <<
i;
390 const std::shared_ptr<fml::Mapping> fixture =
392 ASSERT_TRUE(fixture);
393 ASSERT_GT(fixture->GetSize(), 0u);
395 ABSL_ASSERT_OK(stages);
396 auto stage = stages.value()[GetRuntimeStageBackend()];
398 std::promise<bool> registration;
399 auto future = registration.get_future();
400 auto library = GetContext()->GetShaderLibrary();
401 library->RegisterFunction(
402 stage->GetEntrypoint(),
404 stage->GetCodeMapping(),
406 reg.set_value(result);
408 ASSERT_TRUE(future.get());
426 auto stages_result = OpenAssetAsRuntimeStage(
"ink_sparkle.frag.iplr");
427 ABSL_ASSERT_OK(stages_result);
428 auto stage = stages_result.value()[GetRuntimeStageBackend()];
431 ASSERT_NE(stage,
nullptr);
432 ASSERT_TRUE(RegisterStage(*stage));
433 auto library = GetContext()->GetShaderLibrary();
434 using VS = RuntimeEffectVertexShader;
436 desc.
SetLabel(
"Runtime Stage InkSparkle");
441 auto vertex_descriptor = std::make_shared<VertexDescriptor>();
442 vertex_descriptor->SetStageInputs(VS::kAllShaderStageInputs,
443 VS::kInterleavedBufferLayout);
445 std::array<DescriptorSetLayout, 2> descriptor_set_layouts = {
446 VS::kDescriptorSetLayouts[0],
453 vertex_descriptor->RegisterDescriptorSetLayouts(descriptor_set_layouts);
457 color0.
format = GetContext()->GetCapabilities()->GetDefaultColorFormat();
462 const auto stencil_fmt =
463 GetContext()->GetCapabilities()->GetDefaultStencilFormat();
465 auto pipeline = GetContext()->GetPipelineLibrary()->GetPipeline(desc).Get();
532TEST(ShaderKeyTest, MakeUserScopedNameHandlesLongInputs) {
537 const std::string long_library_id(4096,
'a');
538 const std::string long_entrypoint(2048,
'b');
542 long_library_id.size() + 1 +
543 long_entrypoint.size());
544 EXPECT_EQ(scoped.substr(0, 3),
"fg:");
545 EXPECT_EQ(scoped.substr(3, long_library_id.size()), long_library_id);
546 EXPECT_EQ(scoped.substr(3 + long_library_id.size(), 1),
":");
547 EXPECT_EQ(scoped.substr(3 + long_library_id.size() + 1), long_entrypoint);
Vector2 padding
The halo padding in source space.