2013-01-19 02:32:58 +04:00
|
|
|
/* primitives.c
|
|
|
|
* This code queries processor features and calls the init/deinit routines.
|
|
|
|
* vi:ts=4 sw=4
|
|
|
|
*
|
2013-12-04 14:37:57 +04:00
|
|
|
* Copyright 2011 Martin Fleisz <martin.fleisz@thincast.com>
|
2013-01-19 02:32:58 +04:00
|
|
|
* (c) Copyright 2012 Hewlett-Packard Development Company, L.P.
|
2018-01-29 18:20:59 +03:00
|
|
|
* Copyright 2019 David Fort <contact@hardening-consulting.com>
|
2013-01-19 02:32:58 +04:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
* not use this file except in compliance with the License. You may obtain
|
|
|
|
* a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
|
|
|
* or implied. See the License for the specific language governing
|
|
|
|
* permissions and limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2013-01-19 23:27:34 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2013-01-19 02:32:58 +04:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
2013-01-19 23:27:34 +04:00
|
|
|
|
2018-01-29 00:15:54 +03:00
|
|
|
#include <winpr/synch.h>
|
2018-01-29 18:20:59 +03:00
|
|
|
#include <winpr/sysinfo.h>
|
|
|
|
#include <winpr/crypto.h>
|
2013-01-19 02:32:58 +04:00
|
|
|
#include <freerdp/primitives.h>
|
2013-01-20 00:16:28 +04:00
|
|
|
|
2013-01-19 02:32:58 +04:00
|
|
|
#include "prim_internal.h"
|
2013-01-20 00:16:28 +04:00
|
|
|
|
2018-01-29 18:20:59 +03:00
|
|
|
#define TAG FREERDP_TAG("primitives")
|
|
|
|
|
|
|
|
/* hints to know which kind of primitives to use */
|
|
|
|
static primitive_hints primitivesHints = PRIMITIVES_AUTODETECT;
|
2019-11-07 17:19:49 +03:00
|
|
|
static BOOL primitives_init_optimized(primitives_t* prims);
|
2018-01-29 18:20:59 +03:00
|
|
|
|
|
|
|
void primitives_set_hints(primitive_hints hints)
|
|
|
|
{
|
|
|
|
primitivesHints = hints;
|
|
|
|
}
|
|
|
|
|
|
|
|
primitive_hints primitives_get_hints(void)
|
|
|
|
{
|
|
|
|
return primitivesHints;
|
|
|
|
}
|
|
|
|
|
2013-01-19 02:32:58 +04:00
|
|
|
/* Singleton pointer used throughout the program when requested. */
|
2016-04-05 18:07:45 +03:00
|
|
|
static primitives_t pPrimitivesGeneric = { 0 };
|
2018-01-29 00:15:54 +03:00
|
|
|
static INIT_ONCE generic_primitives_InitOnce = INIT_ONCE_STATIC_INIT;
|
2018-01-29 18:20:59 +03:00
|
|
|
|
2019-11-07 17:19:49 +03:00
|
|
|
#if defined(HAVE_CPU_OPTIMIZED_PRIMITIVES)
|
|
|
|
static primitives_t pPrimitivesCpu = { 0 };
|
2019-11-07 18:04:48 +03:00
|
|
|
static INIT_ONCE cpu_primitives_InitOnce = INIT_ONCE_STATIC_INIT;
|
|
|
|
|
2019-11-07 17:19:49 +03:00
|
|
|
#endif
|
|
|
|
#if defined(WITH_OPENCL)
|
|
|
|
static primitives_t pPrimitivesGpu = { 0 };
|
2019-11-07 18:04:48 +03:00
|
|
|
static INIT_ONCE gpu_primitives_InitOnce = INIT_ONCE_STATIC_INIT;
|
|
|
|
|
2019-11-07 17:19:49 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static INIT_ONCE auto_primitives_InitOnce = INIT_ONCE_STATIC_INIT;
|
|
|
|
|
2018-05-16 23:15:50 +03:00
|
|
|
static primitives_t pPrimitives = { 0 };
|
2018-01-29 00:15:54 +03:00
|
|
|
|
2013-01-19 02:32:58 +04:00
|
|
|
/* ------------------------------------------------------------------------- */
|
2019-11-13 10:28:14 +03:00
|
|
|
static BOOL primitives_init_generic(primitives_t* prims)
|
2018-01-29 18:20:59 +03:00
|
|
|
{
|
|
|
|
primitives_init_add(prims);
|
|
|
|
primitives_init_andor(prims);
|
|
|
|
primitives_init_alphaComp(prims);
|
|
|
|
primitives_init_copy(prims);
|
|
|
|
primitives_init_set(prims);
|
|
|
|
primitives_init_shift(prims);
|
|
|
|
primitives_init_sign(prims);
|
|
|
|
primitives_init_colors(prims);
|
|
|
|
primitives_init_YCoCg(prims);
|
|
|
|
primitives_init_YUV(prims);
|
|
|
|
prims->uninit = NULL;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL CALLBACK primitives_init_generic_cb(PINIT_ONCE once, PVOID param, PVOID* context)
|
2013-01-19 02:32:58 +04:00
|
|
|
{
|
2019-05-08 13:20:43 +03:00
|
|
|
WINPR_UNUSED(once);
|
|
|
|
WINPR_UNUSED(param);
|
|
|
|
WINPR_UNUSED(context);
|
2018-01-29 18:20:59 +03:00
|
|
|
return primitives_init_generic(&pPrimitivesGeneric);
|
|
|
|
}
|
|
|
|
|
2019-11-13 10:28:14 +03:00
|
|
|
static BOOL primitives_init_optimized(primitives_t* prims)
|
2018-01-29 18:20:59 +03:00
|
|
|
{
|
|
|
|
primitives_init_generic(prims);
|
|
|
|
|
|
|
|
#if defined(HAVE_CPU_OPTIMIZED_PRIMITIVES)
|
|
|
|
primitives_init_add_opt(prims);
|
|
|
|
primitives_init_andor_opt(prims);
|
|
|
|
primitives_init_alphaComp_opt(prims);
|
|
|
|
primitives_init_copy_opt(prims);
|
|
|
|
primitives_init_set_opt(prims);
|
|
|
|
primitives_init_shift_opt(prims);
|
|
|
|
primitives_init_sign_opt(prims);
|
|
|
|
primitives_init_colors_opt(prims);
|
|
|
|
primitives_init_YCoCg_opt(prims);
|
|
|
|
primitives_init_YUV_opt(prims);
|
|
|
|
prims->flags |= PRIM_FLAGS_HAVE_EXTCPU;
|
|
|
|
#endif
|
2018-01-29 00:15:54 +03:00
|
|
|
return TRUE;
|
2016-04-05 18:07:45 +03:00
|
|
|
}
|
2013-01-19 02:32:58 +04:00
|
|
|
|
2019-11-13 10:28:14 +03:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
BYTE* channels[3];
|
2018-01-29 18:20:59 +03:00
|
|
|
UINT32 steps[3];
|
|
|
|
prim_size_t roi;
|
2019-11-13 10:28:14 +03:00
|
|
|
BYTE* outputBuffer;
|
2018-01-29 18:20:59 +03:00
|
|
|
UINT32 outputStride;
|
|
|
|
UINT32 testedFormat;
|
|
|
|
} primitives_YUV_benchmark;
|
|
|
|
|
2019-11-07 17:44:41 +03:00
|
|
|
static void primitives_YUV_benchmark_free(primitives_YUV_benchmark* bench)
|
2018-01-29 18:20:59 +03:00
|
|
|
{
|
|
|
|
int i;
|
2019-11-07 17:44:41 +03:00
|
|
|
if (!bench)
|
|
|
|
return;
|
|
|
|
|
|
|
|
free(bench->outputBuffer);
|
|
|
|
|
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
free(bench->channels[i]);
|
|
|
|
memset(bench, 0, sizeof(primitives_YUV_benchmark));
|
|
|
|
}
|
|
|
|
|
|
|
|
static primitives_YUV_benchmark* primitives_YUV_benchmark_init(primitives_YUV_benchmark* ret)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
prim_size_t* roi;
|
2018-01-29 18:20:59 +03:00
|
|
|
if (!ret)
|
|
|
|
return NULL;
|
|
|
|
|
2019-11-07 17:44:41 +03:00
|
|
|
memset(ret, 0, sizeof(primitives_YUV_benchmark));
|
2018-01-29 18:20:59 +03:00
|
|
|
roi = &ret->roi;
|
|
|
|
roi->width = 1024;
|
|
|
|
roi->height = 768;
|
2019-11-07 17:44:41 +03:00
|
|
|
ret->outputStride = roi->width * 4;
|
2018-01-29 18:20:59 +03:00
|
|
|
ret->testedFormat = PIXEL_FORMAT_BGRA32;
|
|
|
|
|
2019-11-07 17:44:41 +03:00
|
|
|
ret->outputBuffer = malloc(ret->outputStride * roi->height);
|
2018-01-29 18:20:59 +03:00
|
|
|
if (!ret->outputBuffer)
|
2019-11-07 17:44:41 +03:00
|
|
|
goto fail;
|
2018-01-29 18:20:59 +03:00
|
|
|
|
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
{
|
2019-11-13 10:28:14 +03:00
|
|
|
BYTE* buf = ret->channels[i] = malloc(roi->width * roi->height);
|
2018-01-29 18:20:59 +03:00
|
|
|
if (!buf)
|
2019-11-07 17:44:41 +03:00
|
|
|
goto fail;
|
2018-01-29 18:20:59 +03:00
|
|
|
|
|
|
|
winpr_RAND(buf, roi->width * roi->height);
|
|
|
|
ret->steps[i] = roi->width;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
2019-11-07 17:44:41 +03:00
|
|
|
fail:
|
|
|
|
primitives_YUV_benchmark_free(ret);
|
|
|
|
return ret;
|
2018-01-29 18:20:59 +03:00
|
|
|
}
|
|
|
|
|
2019-11-13 10:28:14 +03:00
|
|
|
static BOOL primitives_YUV_benchmark_run(primitives_YUV_benchmark* bench, primitives_t* prims,
|
|
|
|
UINT64 runTime, UINT32* computations)
|
2018-01-29 18:20:59 +03:00
|
|
|
{
|
2019-11-13 10:28:14 +03:00
|
|
|
ULONGLONG dueDate;
|
|
|
|
const BYTE* channels[3];
|
2019-11-13 18:35:03 +03:00
|
|
|
size_t i;
|
|
|
|
pstatus_t status;
|
2018-01-29 18:20:59 +03:00
|
|
|
|
|
|
|
*computations = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
channels[i] = bench->channels[i];
|
|
|
|
|
2019-11-13 10:28:14 +03:00
|
|
|
/* do a first dry run to initialize cache and such */
|
2019-11-13 18:35:03 +03:00
|
|
|
status = prims->YUV420ToRGB_8u_P3AC4R(channels, bench->steps, bench->outputBuffer,
|
|
|
|
bench->outputStride, bench->testedFormat, &bench->roi);
|
2019-11-13 10:28:14 +03:00
|
|
|
if (status != PRIMITIVES_SUCCESS)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* let's run the benchmark */
|
|
|
|
dueDate = GetTickCount64() + runTime;
|
2018-01-29 18:20:59 +03:00
|
|
|
while (GetTickCount64() < dueDate)
|
|
|
|
{
|
2019-11-13 10:28:14 +03:00
|
|
|
pstatus_t status =
|
|
|
|
prims->YUV420ToRGB_8u_P3AC4R(channels, bench->steps, bench->outputBuffer,
|
|
|
|
bench->outputStride, bench->testedFormat, &bench->roi);
|
2018-01-29 18:20:59 +03:00
|
|
|
if (status != PRIMITIVES_SUCCESS)
|
|
|
|
return FALSE;
|
|
|
|
*computations = *computations + 1;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2019-11-13 10:28:14 +03:00
|
|
|
static BOOL primitives_autodetect_best(primitives_t* prims)
|
2018-01-29 18:20:59 +03:00
|
|
|
{
|
2019-11-13 18:35:03 +03:00
|
|
|
size_t x;
|
2018-01-29 18:20:59 +03:00
|
|
|
BOOL ret = FALSE;
|
2019-11-13 10:28:14 +03:00
|
|
|
UINT64 benchDuration = 150; /* 150 ms */
|
2019-11-13 18:35:03 +03:00
|
|
|
struct prim_benchmark
|
|
|
|
{
|
|
|
|
const char* name;
|
|
|
|
primitives_t* prims;
|
|
|
|
UINT32 flags;
|
|
|
|
UINT32 count;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct prim_benchmark testcases[] =
|
|
|
|
{
|
|
|
|
{ "generic", NULL, PRIMITIVES_PURE_SOFT, 0 },
|
2019-11-07 17:19:49 +03:00
|
|
|
#if defined(HAVE_CPU_OPTIMIZED_PRIMITIVES)
|
2019-11-13 18:35:03 +03:00
|
|
|
{ "optimized", NULL, PRIMITIVES_ONLY_CPU, 0 },
|
2019-11-07 17:19:49 +03:00
|
|
|
#endif
|
2018-01-29 18:20:59 +03:00
|
|
|
#if defined(WITH_OPENCL)
|
2019-11-13 18:35:03 +03:00
|
|
|
{ "opencl", NULL, PRIMITIVES_ONLY_GPU, 0 },
|
2018-01-29 18:20:59 +03:00
|
|
|
#endif
|
2019-11-13 18:35:03 +03:00
|
|
|
};
|
|
|
|
const struct prim_benchmark* best = NULL;
|
|
|
|
|
2019-11-07 17:44:41 +03:00
|
|
|
primitives_YUV_benchmark bench;
|
|
|
|
primitives_YUV_benchmark* yuvBench = primitives_YUV_benchmark_init(&bench);
|
2018-01-29 18:20:59 +03:00
|
|
|
if (!yuvBench)
|
|
|
|
return FALSE;
|
|
|
|
|
2019-11-13 18:35:03 +03:00
|
|
|
WLog_DBG(TAG, "primitives benchmark result:");
|
|
|
|
for (x = 0; x < ARRAYSIZE(testcases); x++)
|
2018-01-29 18:20:59 +03:00
|
|
|
{
|
2019-11-13 18:35:03 +03:00
|
|
|
struct prim_benchmark* cur = &testcases[x];
|
|
|
|
cur->prims = primitives_get_by_type(cur->flags);
|
|
|
|
if (!cur->prims)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to initialize %s primitives", cur->name);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (!primitives_YUV_benchmark_run(yuvBench, cur->prims, benchDuration, &cur->count))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "error running %s YUV bench", cur->name);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
WLog_DBG(TAG, " * %s\t= %" PRIu32, cur->name, cur->count);
|
|
|
|
if (!best || (best->count < cur->count))
|
|
|
|
best = cur;
|
2018-01-29 18:20:59 +03:00
|
|
|
}
|
|
|
|
|
2019-11-13 18:35:03 +03:00
|
|
|
if (!best)
|
2018-01-29 18:20:59 +03:00
|
|
|
{
|
2019-11-13 18:35:03 +03:00
|
|
|
WLog_ERR(TAG, "No primitives to test, aborting.");
|
2018-01-29 18:20:59 +03:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
/* finally compute the results */
|
2019-11-13 18:35:03 +03:00
|
|
|
*prims = *best->prims;
|
2018-01-29 18:20:59 +03:00
|
|
|
|
2019-11-13 18:35:03 +03:00
|
|
|
WLog_INFO(TAG, "primitives autodetect, using %s", best->name);
|
2018-01-29 18:20:59 +03:00
|
|
|
ret = TRUE;
|
|
|
|
out:
|
2019-11-07 17:44:41 +03:00
|
|
|
primitives_YUV_benchmark_free(yuvBench);
|
2018-01-29 18:20:59 +03:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-11-07 18:04:48 +03:00
|
|
|
#if defined(WITH_OPENCL)
|
|
|
|
static BOOL CALLBACK primitives_init_gpu_cb(PINIT_ONCE once, PVOID param, PVOID* context)
|
2016-04-05 18:07:45 +03:00
|
|
|
{
|
2019-05-08 13:20:43 +03:00
|
|
|
WINPR_UNUSED(once);
|
|
|
|
WINPR_UNUSED(param);
|
|
|
|
WINPR_UNUSED(context);
|
2018-01-29 18:20:59 +03:00
|
|
|
|
2019-11-07 17:19:49 +03:00
|
|
|
if (!primitives_init_opencl(&pPrimitivesGpu))
|
2018-01-29 18:20:59 +03:00
|
|
|
return FALSE;
|
2019-11-07 18:04:48 +03:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2019-11-07 17:19:49 +03:00
|
|
|
#endif
|
2018-01-29 18:20:59 +03:00
|
|
|
|
2019-11-07 18:04:48 +03:00
|
|
|
#if defined(HAVE_CPU_OPTIMIZED_PRIMITIVES)
|
|
|
|
static BOOL CALLBACK primitives_init_cpu_cb(PINIT_ONCE once, PVOID param, PVOID* context)
|
|
|
|
{
|
|
|
|
WINPR_UNUSED(once);
|
|
|
|
WINPR_UNUSED(param);
|
|
|
|
WINPR_UNUSED(context);
|
|
|
|
|
2019-11-13 18:35:03 +03:00
|
|
|
if (!primitives_init_optimized(&pPrimitivesCpu))
|
|
|
|
return FALSE;
|
2019-11-07 18:04:48 +03:00
|
|
|
|
2019-11-13 18:35:03 +03:00
|
|
|
return TRUE;
|
2018-01-29 18:20:59 +03:00
|
|
|
}
|
2019-11-07 18:04:48 +03:00
|
|
|
#endif
|
2018-01-29 18:20:59 +03:00
|
|
|
|
2019-11-07 17:19:49 +03:00
|
|
|
static BOOL CALLBACK primitives_auto_init_cb(PINIT_ONCE once, PVOID param, PVOID* context)
|
2018-01-29 18:20:59 +03:00
|
|
|
{
|
2019-11-07 17:19:49 +03:00
|
|
|
WINPR_UNUSED(once);
|
|
|
|
WINPR_UNUSED(param);
|
|
|
|
WINPR_UNUSED(context);
|
2018-01-29 18:20:59 +03:00
|
|
|
|
2019-11-07 17:19:49 +03:00
|
|
|
return primitives_init(&pPrimitives, primitivesHints);
|
2013-01-19 02:32:58 +04:00
|
|
|
}
|
2018-01-29 18:20:59 +03:00
|
|
|
|
2019-11-07 17:19:49 +03:00
|
|
|
BOOL primitives_init(primitives_t* p, primitive_hints hints)
|
2018-01-29 18:20:59 +03:00
|
|
|
{
|
2019-11-13 10:28:14 +03:00
|
|
|
switch (hints)
|
2018-01-29 18:20:59 +03:00
|
|
|
{
|
2019-11-07 17:19:49 +03:00
|
|
|
case PRIMITIVES_AUTODETECT:
|
|
|
|
return primitives_autodetect_best(p);
|
|
|
|
case PRIMITIVES_PURE_SOFT:
|
|
|
|
*p = pPrimitivesGeneric;
|
|
|
|
return TRUE;
|
|
|
|
case PRIMITIVES_ONLY_CPU:
|
2019-11-13 10:28:14 +03:00
|
|
|
#if defined(HAVE_CPU_OPTIMIZED_PRIMITIVES)
|
2019-11-07 17:19:49 +03:00
|
|
|
*p = pPrimitivesCpu;
|
2019-11-13 10:28:14 +03:00
|
|
|
return TRUE;
|
2019-11-13 18:35:03 +03:00
|
|
|
#endif
|
2019-11-07 17:19:49 +03:00
|
|
|
case PRIMITIVES_ONLY_GPU:
|
2019-11-13 10:28:14 +03:00
|
|
|
#if defined(WITH_OPENCL)
|
2019-11-07 17:19:49 +03:00
|
|
|
*p = pPrimitivesGpu;
|
|
|
|
return TRUE;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
WLog_ERR(TAG, "unknown hint %d", hints);
|
|
|
|
return FALSE;
|
2018-01-29 18:20:59 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-13 18:35:03 +03:00
|
|
|
void primitives_uninit(void)
|
2019-11-07 17:44:41 +03:00
|
|
|
{
|
|
|
|
#if defined(WITH_OPENCL)
|
|
|
|
if (pPrimitivesGpu.uninit)
|
|
|
|
pPrimitivesGpu.uninit();
|
|
|
|
#endif
|
|
|
|
#if defined(HAVE_CPU_OPTIMIZED_PRIMITIVES)
|
|
|
|
if (pPrimitivesCpu.uninit)
|
|
|
|
pPrimitivesCpu.uninit();
|
|
|
|
#endif
|
|
|
|
if (pPrimitivesGeneric.uninit)
|
|
|
|
pPrimitivesGeneric.uninit();
|
2018-01-29 18:20:59 +03:00
|
|
|
}
|
|
|
|
|
2013-01-19 02:32:58 +04:00
|
|
|
/* ------------------------------------------------------------------------- */
|
2019-11-07 17:19:49 +03:00
|
|
|
static void setup(void)
|
2013-01-19 02:32:58 +04:00
|
|
|
{
|
2018-01-29 18:20:59 +03:00
|
|
|
InitOnceExecuteOnce(&generic_primitives_InitOnce, primitives_init_generic_cb, NULL, NULL);
|
2019-11-07 18:04:48 +03:00
|
|
|
#if defined(HAVE_CPU_OPTIMIZED_PRIMITIVES)
|
|
|
|
InitOnceExecuteOnce(&cpu_primitives_InitOnce, primitives_init_cpu_cb, NULL, NULL);
|
|
|
|
#endif
|
2019-11-13 10:28:14 +03:00
|
|
|
#if defined(WITH_OPENCL)
|
2019-11-07 18:04:48 +03:00
|
|
|
InitOnceExecuteOnce(&gpu_primitives_InitOnce, primitives_init_gpu_cb, NULL, NULL);
|
|
|
|
#endif
|
2019-11-07 17:19:49 +03:00
|
|
|
InitOnceExecuteOnce(&auto_primitives_InitOnce, primitives_auto_init_cb, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
primitives_t* primitives_get(void)
|
|
|
|
{
|
|
|
|
setup();
|
2016-04-05 18:07:45 +03:00
|
|
|
return &pPrimitives;
|
2013-01-19 02:32:58 +04:00
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
primitives_t* primitives_get_generic(void)
|
2013-01-19 02:32:58 +04:00
|
|
|
{
|
2018-01-29 18:20:59 +03:00
|
|
|
InitOnceExecuteOnce(&generic_primitives_InitOnce, primitives_init_generic_cb, NULL, NULL);
|
2016-07-13 15:04:48 +03:00
|
|
|
return &pPrimitivesGeneric;
|
2013-01-19 02:32:58 +04:00
|
|
|
}
|
2018-01-29 18:20:59 +03:00
|
|
|
|
2019-11-07 17:19:49 +03:00
|
|
|
primitives_t* primitives_get_by_type(DWORD type)
|
|
|
|
{
|
|
|
|
InitOnceExecuteOnce(&generic_primitives_InitOnce, primitives_init_generic_cb, NULL, NULL);
|
2019-11-13 10:28:14 +03:00
|
|
|
|
2019-11-07 17:19:49 +03:00
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case PRIMITIVES_ONLY_GPU:
|
2019-11-13 10:28:14 +03:00
|
|
|
#if defined(WITH_OPENCL)
|
2019-11-13 18:35:03 +03:00
|
|
|
if (!InitOnceExecuteOnce(&gpu_primitives_InitOnce, primitives_init_gpu_cb, NULL, NULL))
|
|
|
|
return NULL;
|
|
|
|
return &pPrimitivesGpu;
|
2019-11-07 17:19:49 +03:00
|
|
|
#endif
|
|
|
|
case PRIMITIVES_ONLY_CPU:
|
2019-11-13 10:28:14 +03:00
|
|
|
#if defined(HAVE_CPU_OPTIMIZED_PRIMITIVES)
|
2019-11-13 18:35:03 +03:00
|
|
|
if (!InitOnceExecuteOnce(&cpu_primitives_InitOnce, primitives_init_cpu_cb, NULL, NULL))
|
|
|
|
return NULL;
|
|
|
|
return &pPrimitivesCpu;
|
2019-11-07 17:19:49 +03:00
|
|
|
#endif
|
|
|
|
case PRIMITIVES_PURE_SOFT:
|
|
|
|
default:
|
|
|
|
return &pPrimitivesGeneric;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD primitives_flags(primitives_t* p)
|
2018-01-29 18:20:59 +03:00
|
|
|
{
|
|
|
|
return p->flags;
|
|
|
|
}
|