summaryrefslogtreecommitdiffstatsci
path: root/tests/common
diff options
context:
space:
mode:
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>2019-09-06 00:57:50 +0200
committerj-p <jp_bruyere@hotmail.com>2019-09-06 00:59:25 +0200
commitd9d2d2bba31ebcc34ae28843c8d4eef223d023c9 (patch)
tree9c79dad68c051fc2c78c7ab037152fe2cde8e504 /tests/common
parent77e4fbddfb6603a1a56b4c4fb482313fa26495ab (diff)
dyn sizing of vbo and ibo buffers
Diffstat (limited to 'tests/common')
-rw-r--r--tests/common/test.c119
-rw-r--r--tests/common/test.h12
2 files changed, 105 insertions, 26 deletions
diff --git a/tests/common/test.c b/tests/common/test.c
index 5b662e6..362ff31 100644
--- a/tests/common/test.c
+++ b/tests/common/test.c
@@ -10,15 +10,19 @@ bool mouseDown = false;
VkvgDevice device = NULL;
VkvgSurface surf = NULL;
-uint iterations = 1000; // items drawn in one run, or complexity
-uint runs = 10; // repeat test n times
+uint test_size = 250; // items drawn in one run, or complexity
+int iterations = 100; // repeat test n times
+static bool paused = false;
static vk_engine_t* e;
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) {
if (action != GLFW_PRESS)
return;
switch (key) {
+ case GLFW_KEY_SPACE:
+ paused = !paused;
+ break;
case GLFW_KEY_ESCAPE :
glfwSetWindowShouldClose(window, GLFW_TRUE);
break;
@@ -68,6 +72,42 @@ void randomize_color (VkvgContext ctx) {
0.5f//0.8f*rand()/RAND_MAX + 0.2f
);
}
+/* from caskbench */
+double
+get_tick (void)
+{
+ struct timeval now;
+ gettimeofday (&now, NULL);
+ return (double)now.tv_sec + (double)now.tv_usec / 1000000.0;
+}
+double median_run_time (double data[], int n)
+{
+ double temp;
+ int i, j;
+ for (i = 0; i < n; i++)
+ for (j = i+1; j < n; j++)
+ {
+ if (data[i] > data[j])
+ {
+ temp = data[j];
+ data[j] = data[i];
+ data[i] = temp;
+ }
+ }
+ if (n % 2 == 0)
+ return (data[n/2] + data[n/2-1])/2;
+ else
+ return data[n/2];
+}
+double standard_deviation (const double data[], int n, double mean)
+{
+ double sum_deviation = 0.0;
+ int i;
+ for (i = 0; i < n; ++i)
+ sum_deviation += (data[i]-mean) * (data[i]-mean);
+ return sqrt (sum_deviation / n);
+}
+/***************/
void init_test (uint width, uint height){
e = vkengine_create (VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU, VK_PRESENT_MODE_MAILBOX_KHR, width, height);
@@ -91,15 +131,18 @@ void run_test_func (void(*testfunc)(void),uint width, uint height) {
bool deferredResolve = false;
VkhPresenter r = e->renderer;
- struct timeval before , after;
- double frameTime = 0, frameTimeAccum = 0, frameCount = 0;
+ double start_time, stop_time, run_time, run_total, min_run_time = -1, max_run_time;
+ double run_time_values[iterations];
- while (!vkengine_should_close (e)) {
+ int i = 0;
+
+ while (!vkengine_should_close (e) && i < iterations) {
glfwPollEvents();
- gettimeofday(&before , NULL);
+ start_time = get_tick();
- testfunc();
+ if (!paused)
+ testfunc();
if (deferredResolve)
vkvg_multisample_surface_resolve(surf);
@@ -108,14 +151,26 @@ void run_test_func (void(*testfunc)(void),uint width, uint height) {
vkDeviceWaitIdle(e->dev->dev);
- gettimeofday(&after , NULL);
+ stop_time = get_tick();
+ run_time = stop_time - start_time;
+ run_time_values[i] = run_time;
- frameTimeAccum += time_diff(before , after);
- frameCount++;
+ if (min_run_time < 0)
+ min_run_time = run_time;
+ else
+ min_run_time = MIN(run_time, min_run_time);
+ max_run_time = MAX(run_time, max_run_time);
+ run_total += run_time;
+ i++;
}
- frameTime = frameTimeAccum / frameCount;
- printf ("frame (µs): %.0lf\nfps: %lf\n", frameTime, floor(1000000 / frameTime));
+ double avg_run_time = run_total / (double)iterations;
+ double med_run_time = median_run_time (run_time_values, iterations);
+ double standard_dev = standard_deviation (run_time_values, iterations, avg_run_time);
+ double avg_frames_per_second = (1.0 / avg_run_time);
+ avg_frames_per_second = (avg_frames_per_second<9999) ? avg_frames_per_second:9999;
+
+ printf ("size:%d iter:%d avgFps: %f avg: %4.2f%% med: %4.2f%% sd: %4.2f%% \n", test_size, iterations, avg_frames_per_second, avg_run_time, med_run_time, standard_dev);
}
void clear_test () {
@@ -143,7 +198,7 @@ void perform_test (void(*testfunc)(void),uint width, uint height) {
bool deferredResolve = false;
- device = vkvg_device_create_multisample(vkh_app_get_inst(e->app), r->dev->phy, r->dev->dev, r->qFam, 0, VK_SAMPLE_COUNT_4_BIT, deferredResolve);
+ device = vkvg_device_create_multisample(vkh_app_get_inst(e->app), r->dev->phy, r->dev->dev, r->qFam, 0, VK_SAMPLE_COUNT_1_BIT, deferredResolve);
vkvg_device_set_dpy(device, 96, 96);
@@ -155,13 +210,17 @@ void perform_test (void(*testfunc)(void),uint width, uint height) {
surf = vkvg_surface_create(device, width, height);
vkh_presenter_build_blit_cmd (r, vkvg_surface_get_vk_image(surf), width, height);
#endif
- struct timeval before , after;
- double frameTime = 0, frameTimeAccum = 0, frameCount = 0;
- while (!vkengine_should_close (e)) {
+
+ double start_time, stop_time, run_time, run_total, min_run_time = -1, max_run_time;
+ double run_time_values[iterations];
+
+ int i = 0;
+
+ while (!vkengine_should_close (e) && i < iterations) {
glfwPollEvents();
- gettimeofday(&before , NULL);
+ start_time = get_tick();
#ifdef VKVG_TEST_DIRECT_DRAW
@@ -189,7 +248,8 @@ void perform_test (void(*testfunc)(void),uint width, uint height) {
vkQueuePresentKHR(r->queue, &present);
}
#else
- testfunc();
+ if (!paused)
+ testfunc();
if (deferredResolve)
vkvg_multisample_surface_resolve(surf);
@@ -199,15 +259,26 @@ void perform_test (void(*testfunc)(void),uint width, uint height) {
vkDeviceWaitIdle(e->dev->dev);
- gettimeofday(&after , NULL);
+ stop_time = get_tick();
+ run_time = stop_time - start_time;
+ run_time_values[i] = run_time;
- frameTimeAccum += time_diff(before , after);
- frameCount++;
- //fflush(stdout);
+ if (min_run_time < 0)
+ min_run_time = run_time;
+ else
+ min_run_time = MIN(run_time, min_run_time);
+ max_run_time = MAX(run_time, max_run_time);
+ run_total += run_time;
+ i++;
}
- frameTime = frameTimeAccum / frameCount;
- printf ("frame (µs): %.0lf\nfps: %lf\n", frameTime, floor(1000000 / frameTime));
+ double avg_run_time = run_total / (double)iterations;
+ double med_run_time = median_run_time (run_time_values, iterations);
+ double standard_dev = standard_deviation (run_time_values, iterations, avg_run_time);
+ double avg_frames_per_second = (1.0 / avg_run_time);
+ avg_frames_per_second = (avg_frames_per_second<9999) ? avg_frames_per_second:9999;
+
+ printf ("size:%d iter:%d avgFps: %f avg: %4.2f%% med: %4.2f%% sd: %4.2f%% \n", test_size, iterations, avg_frames_per_second, avg_run_time, med_run_time, standard_dev);
vkDeviceWaitIdle(e->dev->dev);
diff --git a/tests/common/test.h b/tests/common/test.h
index 8d15d05..f916c45 100644
--- a/tests/common/test.h
+++ b/tests/common/test.h
@@ -10,6 +10,14 @@
#define M_PIF 3.14159265359f /* float pi */
#define M_PIF_MULT_2 6.28318530718f
+#ifndef MIN
+# define MIN(a,b) (((a) < (b)) ? (a) : (b))
+#endif
+
+#ifndef MAX
+# define MAX(a,b) (((a) > (b)) ? (a) : (b))
+#endif
+
#ifdef _WIN32 // MSC_VER
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
@@ -66,8 +74,8 @@
#include <sys/time.h>
#endif // _WIN32
-extern uint iterations;
-extern uint runs;
+extern uint test_size;
+extern int iterations;
extern float panX;
extern float panY;