Add a helper class to easier test fragment and compute shader versions of the same...
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 19 Nov 2017 00:28:02 +0000 (01:28 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 19 Nov 2017 00:28:14 +0000 (01:28 +0100)
test_util.cpp
test_util.h

index ed8b92a..99ab731 100644 (file)
@@ -42,6 +42,11 @@ void vertical_flip(T *data, unsigned width, unsigned height)
        }
 }
 
+void init_movit_for_test()
+{
+       CHECK(init_movit(".", MOVIT_DEBUG_OFF));
+}
+
 }  // namespace
 
 EffectChainTester::EffectChainTester(const float *data, unsigned width, unsigned height,
@@ -512,4 +517,32 @@ double linear_to_srgb(double x)
        }
 }
 
+DisableComputeShadersTemporarily::DisableComputeShadersTemporarily(bool disable_compute_shaders)
+       : disable_compute_shaders(disable_compute_shaders)
+{
+       init_movit_for_test();
+       saved_compute_shaders_supported = movit_compute_shaders_supported;
+       if (disable_compute_shaders) {
+               movit_compute_shaders_supported = false;
+       }
+}
+
+DisableComputeShadersTemporarily::~DisableComputeShadersTemporarily()
+{
+       movit_compute_shaders_supported = saved_compute_shaders_supported;
+}
+
+bool DisableComputeShadersTemporarily::should_skip()
+{
+       if (disable_compute_shaders) {
+               return false;
+       }
+
+       if (!movit_compute_shaders_supported) {
+               fprintf(stderr, "Compute shaders not supported; skipping.\n");
+               return true;
+       }
+       return false;
+}
+
 }  // namespace movit
index a5124bd..a0767ad 100644 (file)
@@ -83,6 +83,30 @@ double srgb_to_linear(double x);
 // Undefined for values outside 0.0..1.0.
 double linear_to_srgb(double x);
 
+// A RAII class to pretend temporarily that we don't support compute shaders
+// even if we do. Useful for testing or benchmarking the fragment shader path
+// also on systems that support compute shaders.
+class DisableComputeShadersTemporarily
+{
+public:
+       // If disable_compute_shaders is false, this class effectively does nothing.
+       // Otherwise, sets movit_compute_shaders_supported unconditionally to false.
+       DisableComputeShadersTemporarily(bool disable_compute_shaders);
+
+       // Restore the old value of movit_compute_shaders_supported.
+       ~DisableComputeShadersTemporarily();
+
+       // Whether the current test should be skipped due to lack of compute shaders
+       // (ie., disable_compute_shaders was _false_, but the system does not support
+       // compute shaders). Will also output a message to stderr if so.
+       bool should_skip();
+
+       bool active() const { return disable_compute_shaders; }
+
+private:
+       bool disable_compute_shaders, saved_compute_shaders_supported;
+};
+
 }  // namespace movit
 
 #endif  // !defined(_MOVIT_TEST_UTIL_H)