diff options
| author | Tilka <tilkax@gmail.com> | 2023-12-04 13:06:19 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-12-04 13:06:19 +0000 |
| commit | 7dfea144b9eaa4d6cce1b8ed8d48f51816812687 (patch) | |
| tree | b866d77ae82d55261e22496bad82d5e88d407090 /Source/UnitTests/VideoCommon/VertexLoaderTest.cpp | |
| parent | b7ba3f56318f95d3bf13464bdf6f3ed916b3793f (diff) | |
| parent | 69cf8b3470d4c7009b8f1bfc2014d2b853e08be0 (diff) | |
Merge pull request #12324 from Pokechu22/vertex-loader-dummy-tex-coords
VertexLoader: Fixes and cleanup related to skipped components
Diffstat (limited to 'Source/UnitTests/VideoCommon/VertexLoaderTest.cpp')
| -rw-r--r-- | Source/UnitTests/VideoCommon/VertexLoaderTest.cpp | 278 |
1 files changed, 278 insertions, 0 deletions
diff --git a/Source/UnitTests/VideoCommon/VertexLoaderTest.cpp b/Source/UnitTests/VideoCommon/VertexLoaderTest.cpp index c554db88ef..f467fcd23b 100644 --- a/Source/UnitTests/VideoCommon/VertexLoaderTest.cpp +++ b/Source/UnitTests/VideoCommon/VertexLoaderTest.cpp @@ -759,6 +759,284 @@ TEST_P(VertexLoaderNormalTest, NormalAll) } } +class VertexLoaderSkippedColorsTest : public VertexLoaderTest, + public ::testing::WithParamInterface<std::tuple<bool, bool>> +{ +}; +INSTANTIATE_TEST_SUITE_P(AllCombinations, VertexLoaderSkippedColorsTest, + ::testing::Combine(::testing::Values(false, true), + ::testing::Values(false, true))); + +TEST_P(VertexLoaderSkippedColorsTest, SkippedColors) +{ + bool enable_color_0, enable_color_1; + std::tie(enable_color_0, enable_color_1) = GetParam(); + + size_t input_size = 1; + size_t output_size = 3 * sizeof(float); + size_t color_0_offset = 0; + size_t color_1_offset = 0; + + m_vtx_desc.low.Position = VertexComponentFormat::Index8; + if (enable_color_0) + { + m_vtx_desc.low.Color0 = VertexComponentFormat::Index8; + input_size++; + color_0_offset = output_size; + output_size += sizeof(u32); + } + if (enable_color_1) + { + m_vtx_desc.low.Color1 = VertexComponentFormat::Index8; + input_size++; + color_1_offset = output_size; + output_size += sizeof(u32); + } + + m_vtx_attr.g0.PosElements = CoordComponentCount::XYZ; + m_vtx_attr.g0.PosFormat = ComponentFormat::Float; + m_vtx_attr.g0.Color0Elements = ColorComponentCount::RGBA; + m_vtx_attr.g0.Color0Comp = ColorFormat::RGBA8888; + m_vtx_attr.g0.Color1Elements = ColorComponentCount::RGBA; + m_vtx_attr.g0.Color1Comp = ColorFormat::RGBA8888; + + CreateAndCheckSizes(input_size, output_size); + + // Vertex 0 + Input<u8>(1); + if (enable_color_0) + Input<u8>(1); + if (enable_color_1) + Input<u8>(1); + // Vertex 1 + Input<u8>(0); + if (enable_color_0) + Input<u8>(0); + if (enable_color_1) + Input<u8>(0); + // Position array + VertexLoaderManager::cached_arraybases[CPArray::Position] = m_src.GetPointer(); + g_main_cp_state.array_strides[CPArray::Position] = + sizeof(float); // so 1, 2, 3 for index 0; 2, 3, 4 for index 1 + Input(1.f); + Input(2.f); + Input(3.f); + Input(4.f); + // Color array 0 + VertexLoaderManager::cached_arraybases[CPArray::Color0] = m_src.GetPointer(); + g_main_cp_state.array_strides[CPArray::Color0] = sizeof(u32); + Input<u32>(0x00010203u); + Input<u32>(0x04050607u); + // Color array 1 + VertexLoaderManager::cached_arraybases[CPArray::Color1] = m_src.GetPointer(); + g_main_cp_state.array_strides[CPArray::Color1] = sizeof(u32); + Input<u32>(0x08090a0bu); + Input<u32>(0x0c0d0e0fu); + + ASSERT_EQ(m_loader->m_native_vtx_decl.colors[0].enable, enable_color_0); + if (enable_color_0) + ASSERT_EQ(m_loader->m_native_vtx_decl.colors[0].offset, color_0_offset); + ASSERT_EQ(m_loader->m_native_vtx_decl.colors[1].enable, enable_color_1); + if (enable_color_1) + ASSERT_EQ(m_loader->m_native_vtx_decl.colors[1].offset, color_1_offset); + + RunVertices(2); + // Vertex 0 + ExpectOut(2); + ExpectOut(3); + ExpectOut(4); + if (enable_color_0) + EXPECT_EQ((m_dst.Read<u32, true>()), 0x04050607u); + if (enable_color_1) + EXPECT_EQ((m_dst.Read<u32, true>()), 0x0c0d0e0fu); + // Vertex 1 + ExpectOut(1); + ExpectOut(2); + ExpectOut(3); + if (enable_color_0) + EXPECT_EQ((m_dst.Read<u32, true>()), 0x00010203u); + if (enable_color_1) + EXPECT_EQ((m_dst.Read<u32, true>()), 0x08090a0bu); +} + +class VertexLoaderSkippedTexCoordsTest : public VertexLoaderTest, + public ::testing::WithParamInterface<u32> +{ +public: + static constexpr u32 NUM_COMPONENTS_TO_TEST = 3; + static constexpr u32 NUM_PARAMETERS_PER_COMPONENT = 3; + static constexpr u32 NUM_COMBINATIONS = + 1 << (NUM_COMPONENTS_TO_TEST * NUM_PARAMETERS_PER_COMPONENT); +}; +INSTANTIATE_TEST_SUITE_P(AllCombinations, VertexLoaderSkippedTexCoordsTest, + ::testing::Range(0u, VertexLoaderSkippedTexCoordsTest::NUM_COMBINATIONS)); + +TEST_P(VertexLoaderSkippedTexCoordsTest, SkippedTextures) +{ + std::array<bool, NUM_COMPONENTS_TO_TEST> enable_tex, enable_matrix, use_st; + const u32 param = GetParam(); + for (u32 component = 0; component < NUM_COMPONENTS_TO_TEST; component++) + { + const u32 bits = param >> (component * NUM_PARAMETERS_PER_COMPONENT); + enable_tex[component] = (bits & 1); + enable_matrix[component] = (bits & 2); + use_st[component] = (bits & 4); + } + + size_t input_size = 1; + size_t output_size = 3 * sizeof(float); + + std::array<bool, NUM_COMPONENTS_TO_TEST> component_enabled{}; + std::array<size_t, NUM_COMPONENTS_TO_TEST> component_offset{}; + + m_vtx_desc.low.Position = VertexComponentFormat::Index8; + m_vtx_attr.g0.PosElements = CoordComponentCount::XYZ; + m_vtx_attr.g0.PosFormat = ComponentFormat::Float; + + for (size_t i = 0; i < NUM_COMPONENTS_TO_TEST; i++) + { + if (enable_matrix[i] || enable_tex[i]) + { + component_enabled[i] = true; + component_offset[i] = output_size; + if (enable_matrix[i]) + { + output_size += 3 * sizeof(float); + } + else + { + if (use_st[i]) + { + output_size += 2 * sizeof(float); + } + else + { + output_size += sizeof(float); + } + } + } + if (enable_matrix[i]) + { + m_vtx_desc.low.TexMatIdx[i] = enable_matrix[i]; + input_size++; + } + if (enable_tex[i]) + { + m_vtx_desc.high.TexCoord[i] = VertexComponentFormat::Index8; + input_size++; + } + + m_vtx_attr.SetTexElements(i, use_st[i] ? TexComponentCount::ST : TexComponentCount::S); + m_vtx_attr.SetTexFormat(i, ComponentFormat::Float); + m_vtx_attr.SetTexFrac(i, 0); + } + + CreateAndCheckSizes(input_size, output_size); + + // Vertex 0 + for (size_t i = 0; i < NUM_COMPONENTS_TO_TEST; i++) + { + if (enable_matrix[i]) + Input<u8>(u8(20 + i)); + } + Input<u8>(1); // Position + for (size_t i = 0; i < NUM_COMPONENTS_TO_TEST; i++) + { + if (enable_tex[i]) + Input<u8>(1); + } + // Vertex 1 + for (size_t i = 0; i < NUM_COMPONENTS_TO_TEST; i++) + { + if (enable_matrix[i]) + Input<u8>(u8(10 + i)); + } + Input<u8>(0); // Position + for (size_t i = 0; i < NUM_COMPONENTS_TO_TEST; i++) + { + if (enable_tex[i]) + Input<u8>(0); + } + // Position array + VertexLoaderManager::cached_arraybases[CPArray::Position] = m_src.GetPointer(); + g_main_cp_state.array_strides[CPArray::Position] = + sizeof(float); // so 1, 2, 3 for index 0; 2, 3, 4 for index 1 + Input(1.f); + Input(2.f); + Input(3.f); + Input(4.f); + // Texture coord arrays + for (u8 i = 0; i < NUM_COMPONENTS_TO_TEST; i++) + { + VertexLoaderManager::cached_arraybases[CPArray::TexCoord0 + i] = m_src.GetPointer(); + g_main_cp_state.array_strides[CPArray::TexCoord0 + i] = 2 * sizeof(float); + Input<float>(i * 100 + 11); + Input<float>(i * 100 + 12); + Input<float>(i * 100 + 21); + Input<float>(i * 100 + 22); + } + + for (size_t i = 0; i < NUM_COMPONENTS_TO_TEST; i++) + { + ASSERT_EQ(m_loader->m_native_vtx_decl.texcoords[i].enable, component_enabled[i]); + if (component_enabled[i]) + ASSERT_EQ(m_loader->m_native_vtx_decl.texcoords[i].offset, component_offset[i]); + } + + RunVertices(2); + + // Vertex 0 + ExpectOut(2); + ExpectOut(3); + ExpectOut(4); + for (size_t i = 0; i < NUM_COMPONENTS_TO_TEST; i++) + { + size_t num_read = 0; + if (enable_tex[i]) + { + ExpectOut(i * 100 + 21); + num_read++; + if (use_st[i]) + { + ExpectOut(i * 100 + 22); + num_read++; + } + } + if (enable_matrix[i]) + { + // With a matrix there are always 3 components; otherwise-unused components should be 0 + while (num_read++ < 2) + ExpectOut(0); + ExpectOut(20 + i); + } + } + // Vertex 1 + ExpectOut(1); + ExpectOut(2); + ExpectOut(3); + for (size_t i = 0; i < NUM_COMPONENTS_TO_TEST; i++) + { + size_t num_read = 0; + if (enable_tex[i]) + { + ExpectOut(i * 100 + 11); + num_read++; + if (use_st[i]) + { + ExpectOut(i * 100 + 12); + num_read++; + } + } + if (enable_matrix[i]) + { + // With a matrix there are always 3 components; otherwise-unused components should be 0 + while (num_read++ < 2) + ExpectOut(0); + ExpectOut(10 + i); + } + } +} + // For gtest, which doesn't know about our fmt::formatters by default static void PrintTo(const VertexComponentFormat& t, std::ostream* os) { |
