]> git.sesse.net Git - movit/blobdiff - effect_chain_test.cpp
Support top-left origin for compute shaders.
[movit] / effect_chain_test.cpp
index 551cdbcaabd607d1cc50f762f00190e1b99a3816..31e8a5d996bae15c65b91aa49aba1c74009fe9c2 100644 (file)
@@ -99,7 +99,22 @@ TEST(MirrorTest, BasicTest) {
        expect_equal(expected_data, out_data, 3, 2);
 }
 
-TEST(EffectChainTest, TopLeftOrigin) {
+class WithAndWithoutComputeShaderTest : public testing::TestWithParam<string> {
+};
+INSTANTIATE_TEST_CASE_P(WithAndWithoutComputeShaderTest,
+                        WithAndWithoutComputeShaderTest,
+                        testing::Values("fragment", "compute"));
+
+// An effect that does nothing, but as a compute shader.
+class IdentityComputeEffect : public Effect {
+public:
+       IdentityComputeEffect() {}
+       virtual string effect_type_id() const { return "IdentityComputeEffect"; }
+       virtual bool is_compute_shader() const { return true; }
+       string output_fragment_shader() { return read_file("identity.comp"); }
+};
+
+TEST_P(WithAndWithoutComputeShaderTest, TopLeftOrigin) {
        float data[] = {
                0.0f, 0.25f, 0.3f,
                0.75f, 1.0f, 1.0f,
@@ -113,6 +128,9 @@ TEST(EffectChainTest, TopLeftOrigin) {
        float out_data[6];
        EffectChainTester tester(data, 3, 2, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
        tester.get_chain()->set_output_origin(OUTPUT_ORIGIN_TOP_LEFT);
+       if (GetParam() == "compute") {
+               tester.get_chain()->add_effect(new IdentityComputeEffect());
+       }
        tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
 
        expect_equal(expected_data, out_data, 3, 2);
@@ -1113,21 +1131,6 @@ public:
        bool sets_virtual_output_size() const override { return false; }
 };
 
-class WithAndWithoutComputeShaderTest : public testing::TestWithParam<string> {
-};
-INSTANTIATE_TEST_CASE_P(WithAndWithoutComputeShaderTest,
-                        WithAndWithoutComputeShaderTest,
-                        testing::Values("fragment", "compute"));
-
-// An effect that does nothing, but as a compute shader.
-class IdentityComputeEffect : public Effect {
-public:
-       IdentityComputeEffect() {}
-       virtual string effect_type_id() const { return "IdentityComputeEffect"; }
-       virtual bool is_compute_shader() const { return true; }
-       string output_fragment_shader() { return read_file("identity.comp"); }
-};
-
 // An effect that promises one-to-one sampling (unlike IdentityEffect).
 class OneToOneEffect : public Effect {
 public:
@@ -1547,4 +1550,37 @@ TEST(ComputeShaderTest, Render8BitTo8Bit) {
        expect_equal(data, out_data, 3, 2);
 }
 
+// A compute shader to mirror the inputs, in 2x2 blocks.
+class MirrorComputeEffect : public Effect {
+public:
+       MirrorComputeEffect() {}
+       string effect_type_id() const override { return "MirrorComputeEffect"; }
+       bool is_compute_shader() const override { return true; }
+       string output_fragment_shader() override { return read_file("mirror.comp"); }
+       void get_compute_dimensions(unsigned output_width, unsigned output_height,
+                                   unsigned *x, unsigned *y, unsigned *z) const override {
+               *x = output_width / 2;
+               *y = output_height / 2;
+               *z = 1;
+       }
+};
+
+TEST(ComputeShaderTest, ComputeThenOneToOne) {
+       float data[] = {
+               0.0f, 0.25f, 0.3f, 0.8f,
+               0.75f, 1.0f, 1.0f, 0.2f,
+       };
+       float expected_data[] = {
+               0.8f, 0.3f, 0.25f, 0.0f,
+               0.2f, 1.0f, 1.0f, 0.75f,
+       };
+       float out_data[8];
+       EffectChainTester tester(data, 4, 2, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
+       tester.get_chain()->add_effect(new MirrorComputeEffect());
+       tester.get_chain()->add_effect(new OneToOneEffect());
+       tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_LINEAR);
+
+       expect_equal(expected_data, out_data, 4, 2);
+}
+
 }  // namespace movit