23#include <winpr/crypto.h>
24#include <winpr/sysinfo.h>
25#include <freerdp/primitives.h>
33 BYTE* outputChannels[3];
37} primitives_YUV_benchmark;
39static void primitives_YUV_benchmark_free(primitives_YUV_benchmark* bench)
44 free(bench->outputBuffer);
45 free(bench->rgbBuffer);
47 for (
size_t i = 0; i < 3; i++)
49 free(bench->outputChannels[i]);
50 free(bench->channels[i]);
53 const primitives_YUV_benchmark empty = WINPR_C_ARRAY_INIT;
57static primitives_YUV_benchmark primitives_YUV_benchmark_init(
void)
59 primitives_YUV_benchmark ret = WINPR_C_ARRAY_INIT;
60 ret.roi.width = 3840 * 4;
61 ret.roi.height = 2160 * 4;
62 ret.outputStride = ret.roi.width * 4;
63 ret.testedFormat = PIXEL_FORMAT_BGRA32;
65 ret.outputBuffer = calloc(ret.outputStride, ret.roi.height);
66 if (!ret.outputBuffer)
68 ret.rgbBuffer = calloc(ret.outputStride, ret.roi.height);
71 if (winpr_RAND(ret.rgbBuffer, 1ULL * ret.outputStride * ret.roi.height) < 0)
74 for (
size_t i = 0; i < 3; i++)
76 ret.channels[i] = calloc(ret.roi.width, ret.roi.height);
77 ret.outputChannels[i] = calloc(ret.roi.width, ret.roi.height);
78 if (!ret.channels[i] || !ret.outputChannels[i])
81 if (winpr_RAND(ret.channels[i], 1ull * ret.roi.width * ret.roi.height) < 0)
83 ret.steps[i] = ret.roi.width;
89 primitives_YUV_benchmark_free(&ret);
93static const char* print_time(UINT64 t,
char* buffer,
size_t size)
95 (void)_snprintf(buffer, size,
"%u.%03u.%03u.%03u", (
unsigned)(t / 1000000000ull),
96 (
unsigned)((t / 1000000ull) % 1000), (unsigned)((t / 1000ull) % 1000),
97 (
unsigned)((t) % 1000));
101static BOOL primitives_YUV420_benchmark_run(primitives_YUV_benchmark* bench,
primitives_t* prims)
103 const BYTE* channels[3] = WINPR_C_ARRAY_INIT;
105 for (
size_t i = 0; i < 3; i++)
106 channels[i] = bench->channels[i];
108 for (
size_t x = 0; x < 10; x++)
110 const UINT64 start = winpr_GetTickCount64NS();
112 prims->YUV420ToRGB_8u_P3AC4R(channels, bench->steps, bench->outputBuffer,
113 bench->outputStride, bench->testedFormat, &bench->roi);
114 const UINT64 end = winpr_GetTickCount64NS();
115 if (status != PRIMITIVES_SUCCESS)
117 (void)fprintf(stderr,
"Running YUV420ToRGB_8u_P3AC4R failed\n");
120 const UINT64 diff = end - start;
121 char buffer[32] = WINPR_C_ARRAY_INIT;
122 printf(
"[%" PRIuz
"] YUV420ToRGB_8u_P3AC4R %" PRIu32
"x%" PRIu32
" took %sns\n", x,
123 bench->roi.width, bench->roi.height, print_time(diff, buffer,
sizeof(buffer)));
129static BOOL primitives_YUV444_benchmark_run(primitives_YUV_benchmark* bench,
primitives_t* prims)
131 const BYTE* channels[3] = WINPR_C_ARRAY_INIT;
133 for (
size_t i = 0; i < 3; i++)
134 channels[i] = bench->channels[i];
136 for (
size_t x = 0; x < 10; x++)
138 const UINT64 start = winpr_GetTickCount64NS();
140 prims->YUV444ToRGB_8u_P3AC4R(channels, bench->steps, bench->outputBuffer,
141 bench->outputStride, bench->testedFormat, &bench->roi);
142 const UINT64 end = winpr_GetTickCount64NS();
143 if (status != PRIMITIVES_SUCCESS)
145 (void)fprintf(stderr,
"Running YUV444ToRGB_8u_P3AC4R failed\n");
148 const UINT64 diff = end - start;
149 char buffer[32] = WINPR_C_ARRAY_INIT;
150 printf(
"[%" PRIuz
"] YUV444ToRGB_8u_P3AC4R %" PRIu32
"x%" PRIu32
" took %sns\n", x,
151 bench->roi.width, bench->roi.height, print_time(diff, buffer,
sizeof(buffer)));
157static BOOL primitives_RGB2420_benchmark_run(primitives_YUV_benchmark* bench,
primitives_t* prims)
159 for (
size_t x = 0; x < 10; x++)
161 const UINT64 start = winpr_GetTickCount64NS();
163 prims->RGBToYUV420_8u_P3AC4R(bench->rgbBuffer, bench->testedFormat, bench->outputStride,
164 bench->outputChannels, bench->steps, &bench->roi);
165 const UINT64 end = winpr_GetTickCount64NS();
166 if (status != PRIMITIVES_SUCCESS)
168 (void)fprintf(stderr,
"Running RGBToYUV420_8u_P3AC4R failed\n");
171 const UINT64 diff = end - start;
172 char buffer[32] = WINPR_C_ARRAY_INIT;
173 printf(
"[%" PRIuz
"] RGBToYUV420_8u_P3AC4R %" PRIu32
"x%" PRIu32
" took %sns\n", x,
174 bench->roi.width, bench->roi.height, print_time(diff, buffer,
sizeof(buffer)));
180static BOOL primitives_RGB2444_benchmark_run(primitives_YUV_benchmark* bench,
primitives_t* prims)
182 for (
size_t x = 0; x < 10; x++)
184 const UINT64 start = winpr_GetTickCount64NS();
186 prims->RGBToYUV444_8u_P3AC4R(bench->rgbBuffer, bench->testedFormat, bench->outputStride,
187 bench->outputChannels, bench->steps, &bench->roi);
188 const UINT64 end = winpr_GetTickCount64NS();
189 if (status != PRIMITIVES_SUCCESS)
191 (void)fprintf(stderr,
"Running RGBToYUV444_8u_P3AC4R failed\n");
194 const UINT64 diff = end - start;
195 char buffer[32] = WINPR_C_ARRAY_INIT;
196 printf(
"[%" PRIuz
"] RGBToYUV444_8u_P3AC4R %" PRIu32
"x%" PRIu32
" took %sns\n", x,
197 bench->roi.width, bench->roi.height, print_time(diff, buffer,
sizeof(buffer)));
203int main(
int argc,
char* argv[])
207 primitives_YUV_benchmark bench = primitives_YUV_benchmark_init();
209 for (primitive_hints hint = PRIMITIVES_PURE_SOFT; hint < PRIMITIVES_AUTODETECT; hint++)
211 const char* hintstr = primtives_hint_str(hint);
215 (void)fprintf(stderr,
"failed to get primitives: %s\n", hintstr);
219 printf(
"Running YUV420 -> RGB benchmark on %s implementation:\n", hintstr);
220 if (!primitives_YUV420_benchmark_run(&bench, prim))
222 (void)fprintf(stderr,
"YUV420 -> RGB benchmark failed\n");
227 printf(
"Running RGB -> YUV420 benchmark on %s implementation:\n", hintstr);
228 if (!primitives_RGB2420_benchmark_run(&bench, prim))
230 (void)fprintf(stderr,
"RGB -> YUV420 benchmark failed\n");
235 printf(
"Running YUV444 -> RGB benchmark on %s implementation:\n", hintstr);
236 if (!primitives_YUV444_benchmark_run(&bench, prim))
238 (void)fprintf(stderr,
"YUV444 -> RGB benchmark failed\n");
243 printf(
"Running RGB -> YUV444 benchmark on %s implementation:\n", hintstr);
244 if (!primitives_RGB2444_benchmark_run(&bench, prim))
246 (void)fprintf(stderr,
"RGB -> YUV444 benchmark failed\n");
252 primitives_YUV_benchmark_free(&bench);