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 = { 0 };
57static primitives_YUV_benchmark primitives_YUV_benchmark_init(
void)
59 primitives_YUV_benchmark ret = { 0 };
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 winpr_RAND(ret.rgbBuffer, 1ULL * ret.outputStride * ret.roi.height);
73 for (
size_t i = 0; i < 3; i++)
75 ret.channels[i] = calloc(ret.roi.width, ret.roi.height);
76 ret.outputChannels[i] = calloc(ret.roi.width, ret.roi.height);
77 if (!ret.channels[i] || !ret.outputChannels[i])
80 winpr_RAND(ret.channels[i], 1ull * ret.roi.width * ret.roi.height);
81 ret.steps[i] = ret.roi.width;
87 primitives_YUV_benchmark_free(&ret);
91static const char* print_time(UINT64 t,
char* buffer,
size_t size)
93 (void)_snprintf(buffer, size,
"%u.%03u.%03u.%03u", (
unsigned)(t / 1000000000ull),
94 (
unsigned)((t / 1000000ull) % 1000), (unsigned)((t / 1000ull) % 1000),
95 (
unsigned)((t) % 1000));
99static BOOL primitives_YUV420_benchmark_run(primitives_YUV_benchmark* bench,
primitives_t* prims)
101 const BYTE* channels[3] = { 0 };
103 for (
size_t i = 0; i < 3; i++)
104 channels[i] = bench->channels[i];
106 for (
size_t x = 0; x < 10; x++)
108 const UINT64 start = winpr_GetTickCount64NS();
110 prims->YUV420ToRGB_8u_P3AC4R(channels, bench->steps, bench->outputBuffer,
111 bench->outputStride, bench->testedFormat, &bench->roi);
112 const UINT64 end = winpr_GetTickCount64NS();
113 if (status != PRIMITIVES_SUCCESS)
115 (void)fprintf(stderr,
"Running YUV420ToRGB_8u_P3AC4R failed\n");
118 const UINT64 diff = end - start;
119 char buffer[32] = { 0 };
120 printf(
"[%" PRIuz
"] YUV420ToRGB_8u_P3AC4R %" PRIu32
"x%" PRIu32
" took %sns\n", x,
121 bench->roi.width, bench->roi.height, print_time(diff, buffer,
sizeof(buffer)));
127static BOOL primitives_YUV444_benchmark_run(primitives_YUV_benchmark* bench,
primitives_t* prims)
129 const BYTE* channels[3] = { 0 };
131 for (
size_t i = 0; i < 3; i++)
132 channels[i] = bench->channels[i];
134 for (
size_t x = 0; x < 10; x++)
136 const UINT64 start = winpr_GetTickCount64NS();
138 prims->YUV444ToRGB_8u_P3AC4R(channels, bench->steps, bench->outputBuffer,
139 bench->outputStride, bench->testedFormat, &bench->roi);
140 const UINT64 end = winpr_GetTickCount64NS();
141 if (status != PRIMITIVES_SUCCESS)
143 (void)fprintf(stderr,
"Running YUV444ToRGB_8u_P3AC4R failed\n");
146 const UINT64 diff = end - start;
147 char buffer[32] = { 0 };
148 printf(
"[%" PRIuz
"] YUV444ToRGB_8u_P3AC4R %" PRIu32
"x%" PRIu32
" took %sns\n", x,
149 bench->roi.width, bench->roi.height, print_time(diff, buffer,
sizeof(buffer)));
155static BOOL primitives_RGB2420_benchmark_run(primitives_YUV_benchmark* bench,
primitives_t* prims)
157 for (
size_t x = 0; x < 10; x++)
159 const UINT64 start = winpr_GetTickCount64NS();
161 prims->RGBToYUV420_8u_P3AC4R(bench->rgbBuffer, bench->testedFormat, bench->outputStride,
162 bench->outputChannels, bench->steps, &bench->roi);
163 const UINT64 end = winpr_GetTickCount64NS();
164 if (status != PRIMITIVES_SUCCESS)
166 (void)fprintf(stderr,
"Running RGBToYUV420_8u_P3AC4R failed\n");
169 const UINT64 diff = end - start;
170 char buffer[32] = { 0 };
171 printf(
"[%" PRIuz
"] RGBToYUV420_8u_P3AC4R %" PRIu32
"x%" PRIu32
" took %sns\n", x,
172 bench->roi.width, bench->roi.height, print_time(diff, buffer,
sizeof(buffer)));
178static BOOL primitives_RGB2444_benchmark_run(primitives_YUV_benchmark* bench,
primitives_t* prims)
180 for (
size_t x = 0; x < 10; x++)
182 const UINT64 start = winpr_GetTickCount64NS();
184 prims->RGBToYUV444_8u_P3AC4R(bench->rgbBuffer, bench->testedFormat, bench->outputStride,
185 bench->outputChannels, bench->steps, &bench->roi);
186 const UINT64 end = winpr_GetTickCount64NS();
187 if (status != PRIMITIVES_SUCCESS)
189 (void)fprintf(stderr,
"Running RGBToYUV444_8u_P3AC4R failed\n");
192 const UINT64 diff = end - start;
193 char buffer[32] = { 0 };
194 printf(
"[%" PRIuz
"] RGBToYUV444_8u_P3AC4R %" PRIu32
"x%" PRIu32
" took %sns\n", x,
195 bench->roi.width, bench->roi.height, print_time(diff, buffer,
sizeof(buffer)));
201int main(
int argc,
char* argv[])
205 primitives_YUV_benchmark bench = primitives_YUV_benchmark_init();
207 for (primitive_hints hint = PRIMITIVES_PURE_SOFT; hint < PRIMITIVES_AUTODETECT; hint++)
209 const char* hintstr = primtives_hint_str(hint);
213 (void)fprintf(stderr,
"failed to get primitives: %s\n", hintstr);
217 printf(
"Running YUV420 -> RGB benchmark on %s implementation:\n", hintstr);
218 if (!primitives_YUV420_benchmark_run(&bench, prim))
220 (void)fprintf(stderr,
"YUV420 -> RGB benchmark failed\n");
225 printf(
"Running RGB -> YUV420 benchmark on %s implementation:\n", hintstr);
226 if (!primitives_RGB2420_benchmark_run(&bench, prim))
228 (void)fprintf(stderr,
"RGB -> YUV420 benchmark failed\n");
233 printf(
"Running YUV444 -> RGB benchmark on %s implementation:\n", hintstr);
234 if (!primitives_YUV444_benchmark_run(&bench, prim))
236 (void)fprintf(stderr,
"YUV444 -> RGB benchmark failed\n");
241 printf(
"Running RGB -> YUV444 benchmark on %s implementation:\n", hintstr);
242 if (!primitives_RGB2444_benchmark_run(&bench, prim))
244 (void)fprintf(stderr,
"RGB -> YUV444 benchmark failed\n");
250 primitives_YUV_benchmark_free(&bench);