summaryrefslogtreecommitdiff
path: root/Source/UnitTests/VideoCommon/VertexLoaderTest.cpp
diff options
context:
space:
mode:
authorPokechu22 <Pokechu022@gmail.com>2023-12-02 14:13:39 -0800
committerPokechu22 <Pokechu022@gmail.com>2023-12-02 15:53:59 -0800
commit530590d1622b09568ddfa74eaf8764490a59ca65 (patch)
treefcd215e259d78b4b54381f58c1d8705d0489cadc /Source/UnitTests/VideoCommon/VertexLoaderTest.cpp
parent4f3f208fe49e5a017cda7b5f5ea18928c73a0f1e (diff)
VertexLoaderTest: Add test for skipped colors
This test fails with the non-JIT vertex loader due to an issue fixed in a later commit in this PR. (Note that the non-JIT vertex loader is only used on machines where no JIT is available or if COMPARE_VERTEXLOADERS is enabled in VertexLoaderBase.cpp.)
Diffstat (limited to 'Source/UnitTests/VideoCommon/VertexLoaderTest.cpp')
-rw-r--r--Source/UnitTests/VideoCommon/VertexLoaderTest.cpp100
1 files changed, 100 insertions, 0 deletions
diff --git a/Source/UnitTests/VideoCommon/VertexLoaderTest.cpp b/Source/UnitTests/VideoCommon/VertexLoaderTest.cpp
index c554db88ef..828716e8a9 100644
--- a/Source/UnitTests/VideoCommon/VertexLoaderTest.cpp
+++ b/Source/UnitTests/VideoCommon/VertexLoaderTest.cpp
@@ -759,6 +759,106 @@ 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);
+}
+
// For gtest, which doesn't know about our fmt::formatters by default
static void PrintTo(const VertexComponentFormat& t, std::ostream* os)
{