From 3559b216df102fb518876e1d567e2a3558283d31 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sun, 19 Nov 2017 01:28:02 +0100 Subject: [PATCH] Add a helper class to easier test fragment and compute shader versions of the same effect alongside each other. --- test_util.cpp | 33 +++++++++++++++++++++++++++++++++ test_util.h | 24 ++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/test_util.cpp b/test_util.cpp index ed8b92a..99ab731 100644 --- a/test_util.cpp +++ b/test_util.cpp @@ -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 diff --git a/test_util.h b/test_util.h index a5124bd..a0767ad 100644 --- a/test_util.h +++ b/test_util.h @@ -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) -- 2.39.2