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()) {
92 ASSERT_EQ(stage->GetUniforms().size(), 14u);
95 auto uni = stage->GetUniform(
"uFloat");
96 ASSERT_NE(uni,
nullptr);
97 EXPECT_EQ(uni->dimensions.rows, 1u);
98 EXPECT_EQ(uni->dimensions.cols, 1u);
99 EXPECT_EQ(uni->location, 0u);
101 EXPECT_TRUE(uni->padding_layout.empty());
105 auto uni = stage->GetUniform(
"uVec2");
106 ASSERT_NE(uni,
nullptr);
107 EXPECT_EQ(uni->dimensions.rows, 2u);
108 EXPECT_EQ(uni->dimensions.cols, 1u);
109 EXPECT_EQ(uni->location, 1u);
111 EXPECT_TRUE(uni->padding_layout.empty());
115 auto uni = stage->GetUniform(
"uVec3");
116 ASSERT_NE(uni,
nullptr);
117 EXPECT_EQ(uni->dimensions.rows, 3u);
118 EXPECT_EQ(uni->dimensions.cols, 1u);
119 EXPECT_EQ(uni->location, 2u);
121 auto padding = uni->padding_layout;
135 auto uni = stage->GetUniform(
"uVec4");
136 ASSERT_NE(uni,
nullptr);
137 EXPECT_EQ(uni->dimensions.rows, 4u);
138 EXPECT_EQ(uni->dimensions.cols, 1u);
139 EXPECT_EQ(uni->location, 3u);
141 EXPECT_TRUE(uni->padding_layout.empty());
145 auto uni = stage->GetUniform(
"uMat2");
146 ASSERT_NE(uni,
nullptr);
147 EXPECT_EQ(uni->dimensions.rows, 2u);
148 EXPECT_EQ(uni->dimensions.cols, 2u);
149 EXPECT_EQ(uni->location, 4u);
151 EXPECT_TRUE(uni->padding_layout.empty());
155 auto uni = stage->GetUniform(
"uMat3");
156 ASSERT_NE(uni,
nullptr);
157 EXPECT_EQ(uni->dimensions.rows, 3u);
158 EXPECT_EQ(uni->dimensions.cols, 3u);
159 EXPECT_EQ(uni->location, 5u);
164 auto uni = stage->GetUniform(
"uMat4");
165 ASSERT_NE(uni,
nullptr);
166 EXPECT_EQ(uni->dimensions.rows, 4u);
167 EXPECT_EQ(uni->dimensions.cols, 4u);
168 EXPECT_EQ(uni->location, 6u);
170 EXPECT_TRUE(uni->padding_layout.empty());
174 auto uni = stage->GetUniform(
"uFloatArray");
175 ASSERT_NE(uni,
nullptr);
176 EXPECT_EQ(uni->dimensions.rows, 1u);
177 EXPECT_EQ(uni->dimensions.cols, 1u);
178 EXPECT_EQ(uni->location, 7u);
180 EXPECT_TRUE(uni->padding_layout.empty());
183 auto uni = stage->GetUniform(
"uVec2Array");
184 ASSERT_NE(uni,
nullptr);
185 EXPECT_EQ(uni->dimensions.rows, 2u);
186 EXPECT_EQ(uni->dimensions.cols, 1u);
187 EXPECT_EQ(uni->location, 9u);
189 EXPECT_TRUE(uni->padding_layout.empty());
193 auto uni = stage->GetUniform(
"uVec3Array");
194 ASSERT_NE(uni,
nullptr);
195 EXPECT_EQ(uni->dimensions.rows, 3u);
196 EXPECT_EQ(uni->dimensions.cols, 1u);
197 EXPECT_EQ(uni->location, 11u);
202 auto uni = stage->GetUniform(
"uVec4Array");
203 ASSERT_NE(uni,
nullptr);
204 EXPECT_EQ(uni->dimensions.rows, 4u);
205 EXPECT_EQ(uni->dimensions.cols, 1u);
206 EXPECT_EQ(uni->location, 13u);
208 EXPECT_TRUE(uni->padding_layout.empty());
212 auto uni = stage->GetUniform(
"uMat2Array");
213 ASSERT_NE(uni,
nullptr);
214 EXPECT_EQ(uni->dimensions.rows, 2u);
215 EXPECT_EQ(uni->dimensions.cols, 2u);
216 EXPECT_EQ(uni->location, 15u);
218 EXPECT_TRUE(uni->padding_layout.empty());
222 auto uni = stage->GetUniform(
"uMat3Array");
223 ASSERT_NE(uni,
nullptr);
224 EXPECT_EQ(uni->dimensions.rows, 3u);
225 EXPECT_EQ(uni->dimensions.cols, 3u);
226 EXPECT_EQ(uni->location, 17u);
231 auto uni = stage->GetUniform(
"uMat4Array");
232 ASSERT_NE(uni,
nullptr);
233 EXPECT_EQ(uni->dimensions.rows, 4u);
234 EXPECT_EQ(uni->dimensions.cols, 4u);
235 EXPECT_EQ(uni->location, 19u);
237 EXPECT_TRUE(uni->padding_layout.empty());
242 EXPECT_EQ(stage->GetUniforms().size(), 1u);
250 std::vector<RuntimePaddingType> layout(uni->
GetGPUSize() /
sizeof(
float),
312 EXPECT_THAT(uni->
padding_layout, ::testing::ElementsAreArray(layout));
314 std::vector<std::pair<std::string, unsigned int>> expected_uniforms = {
315 {
"uFloat", 4}, {
"uVec2", 8}, {
"uVec3", 12},
316 {
"uVec4", 16}, {
"uMat2", 16}, {
"uMat3", 36},
317 {
"uMat4", 64}, {
"uFloatArray", 8}, {
"uVec2Array", 16},
318 {
"uVec3Array", 24}, {
"uVec4Array", 32}, {
"uMat2Array", 32},
319 {
"uMat3Array", 72}, {
"uMat4Array", 128}};
321 ASSERT_EQ(uni->
struct_fields.size(), expected_uniforms.size());
323 for (
size_t i = 0;
i < expected_uniforms.size(); ++
i) {
325 const auto& expected = expected_uniforms[
i];
327 EXPECT_EQ(element.name, expected.first) <<
"index: " <<
i;
328 EXPECT_EQ(element.byte_size, expected.second) <<
"index: " <<
i;
388 const std::shared_ptr<fml::Mapping> fixture =
390 ASSERT_TRUE(fixture);
391 ASSERT_GT(fixture->GetSize(), 0u);
393 ABSL_ASSERT_OK(stages);
394 auto stage = stages.value()[GetRuntimeStageBackend()];
396 std::promise<bool> registration;
397 auto future = registration.get_future();
398 auto library = GetContext()->GetShaderLibrary();
399 library->RegisterFunction(
400 stage->GetEntrypoint(),
402 stage->GetCodeMapping(),
404 reg.set_value(result);
406 ASSERT_TRUE(future.get());
424 auto stages_result = OpenAssetAsRuntimeStage(
"ink_sparkle.frag.iplr");
425 ABSL_ASSERT_OK(stages_result);
426 auto stage = stages_result.value()[GetRuntimeStageBackend()];
429 ASSERT_NE(stage,
nullptr);
430 ASSERT_TRUE(RegisterStage(*stage));
431 auto library = GetContext()->GetShaderLibrary();
432 using VS = RuntimeEffectVertexShader;
434 desc.
SetLabel(
"Runtime Stage InkSparkle");
439 auto vertex_descriptor = std::make_shared<VertexDescriptor>();
440 vertex_descriptor->SetStageInputs(VS::kAllShaderStageInputs,
441 VS::kInterleavedBufferLayout);
443 std::array<DescriptorSetLayout, 2> descriptor_set_layouts = {
444 VS::kDescriptorSetLayouts[0],
451 vertex_descriptor->RegisterDescriptorSetLayouts(descriptor_set_layouts);
455 color0.
format = GetContext()->GetCapabilities()->GetDefaultColorFormat();
460 const auto stencil_fmt =
461 GetContext()->GetCapabilities()->GetDefaultStencilFormat();
463 auto pipeline = GetContext()->GetPipelineLibrary()->GetPipeline(desc).Get();
464 ASSERT_NE(pipeline,
nullptr);
530TEST(ShaderKeyTest, MakeUserScopedNameHandlesLongInputs) {
535 const std::string long_library_id(4096,
'a');
536 const std::string long_entrypoint(2048,
'b');
540 long_library_id.size() + 1 +
541 long_entrypoint.size());
542 EXPECT_EQ(scoped.substr(0, 3),
"fg:");
543 EXPECT_EQ(scoped.substr(3, long_library_id.size()), long_library_id);
544 EXPECT_EQ(scoped.substr(3 + long_library_id.size(), 1),
":");
545 EXPECT_EQ(scoped.substr(3 + long_library_id.size() + 1), long_entrypoint);
Vector2 padding
The halo padding in source space.