RetroArch
softfilter.h
Go to the documentation of this file.
1 /* RetroArch - A frontend for libretro.
2  * Copyright (C) 2010-2014 - Hans-Kristian Arntzen
3  * Copyright (C) 2011-2017 - Daniel De Matteis
4  *
5  * RetroArch is free software: you can redistribute it and/or modify it under the terms
6  * of the GNU General Public License as published by the Free Software Found-
7  * ation, either version 3 of the License, or (at your option) any later version.
8  *
9  * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11  * PURPOSE. See the GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along with RetroArch.
14  * If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 #ifndef SOFTFILTER_API_H__
18 #define SOFTFILTER_API_H__
19 
20 #include <stdint.h>
21 #include <stddef.h>
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 #define SOFTFILTER_SIMD_SSE (1 << 0)
28 #define SOFTFILTER_SIMD_SSE2 (1 << 1)
29 #define SOFTFILTER_SIMD_VMX (1 << 2)
30 #define SOFTFILTER_SIMD_VMX128 (1 << 3)
31 #define SOFTFILTER_SIMD_AVX (1 << 4)
32 #define SOFTFILTER_SIMD_NEON (1 << 5)
33 #define SOFTFILTER_SIMD_SSE3 (1 << 6)
34 #define SOFTFILTER_SIMD_SSSE3 (1 << 7)
35 #define SOFTFILTER_SIMD_MMX (1 << 8)
36 #define SOFTFILTER_SIMD_MMXEXT (1 << 9)
37 #define SOFTFILTER_SIMD_SSE4 (1 << 10)
38 #define SOFTFILTER_SIMD_SSE42 (1 << 11)
39 #define SOFTFILTER_SIMD_AVX2 (1 << 12)
40 #define SOFTFILTER_SIMD_VFPU (1 << 13)
41 #define SOFTFILTER_SIMD_PS (1 << 14)
42 
43 /* A bit-mask of all supported SIMD instruction sets.
44  * Allows an implementation to pick different
45  * softfilter_implementation structs. */
46 typedef unsigned softfilter_simd_mask_t;
47 
48 /* Returns true if config key was found. Otherwise, returns false,
49  * and sets value to default value. */
50 typedef int (*softfilter_config_get_float_t)(void *userdata,
51  const char *key, float *value, float default_value);
52 
53 typedef int (*softfilter_config_get_int_t)(void *userdata,
54  const char *key, int *value, int default_value);
55 
56 /* Allocates an array with values. free() with softfilter_config_free_t. */
57 typedef int (*softfilter_config_get_float_array_t)(void *userdata,
58  const char *key,
59  float **values, unsigned *out_num_values,
60  const float *default_values, unsigned num_default_values);
61 
62 typedef int (*softfilter_config_get_int_array_t)(void *userdata, const char *key,
63  int **values, unsigned *out_num_values,
64  const int *default_values, unsigned num_default_values);
65 
66 typedef int (*softfilter_config_get_string_t)(void *userdata,
67  const char *key, char **output, const char *default_output);
68 
69 /* Calls free() in host runtime.
70  * Sometimes needed on Windows. free() on NULL is fine. */
71 typedef void (*softfilter_config_free_t)(void *ptr);
72 
74 {
77 
80 
82  /* Avoid problems where softfilter plug and
83  * host are linked against different C runtimes. */
85 };
86 
87 /* Dynamic library entrypoint. */
88 typedef const struct softfilter_implementation
89 *(*softfilter_get_implementation_t)(softfilter_simd_mask_t);
90 
91 /* The same SIMD mask argument is forwarded to create() callback
92  * as well to avoid having to keep lots of state around. */
95 
96 #define SOFTFILTER_API_VERSION 2
97 
98 /* Required base color formats */
99 
100 #define SOFTFILTER_FMT_NONE 0
101 #define SOFTFILTER_FMT_RGB565 (1 << 0)
102 #define SOFTFILTER_FMT_XRGB8888 (1 << 1)
103 
104 /* Optional color formats */
105 #define SOFTFILTER_FMT_RGB4444 (1 << 2)
106 
107 #define SOFTFILTER_BPP_RGB565 2
108 #define SOFTFILTER_BPP_XRGB8888 4
109 
110 /* Softfilter implementation.
111  * Returns a bitmask of supported input formats. */
113 
114 /* Returns a bitmask of supported output formats
115  * for a given input format. */
116 typedef unsigned (*softfilter_query_output_formats_t)(unsigned input_format);
117 
118 /* In softfilter_process_t, the softfilter implementation
119  * submits work units to a worker thread pool. */
120 typedef void (*softfilter_work_t)(void *data, void *thread_data);
122 {
124  void *thread_data;
125 };
126 
127 /* Create a filter with given input and output formats as well as
128  * maximum possible input size.
129  *
130  * Input sizes can very per call to softfilter_process_t, but they
131  * will never be larger than the maximum. */
132 typedef void *(*softfilter_create_t)(const struct softfilter_config *config,
133  unsigned in_fmt, unsigned out_fmt,
134  unsigned max_width, unsigned max_height,
135  unsigned threads, softfilter_simd_mask_t simd, void *userdata);
136 
137 typedef void (*softfilter_destroy_t)(void *data);
138 
139 /* Given an input size, query the output size of the filter.
140  * If width and height == max_width/max_height, no other combination
141  * of width/height must return a larger size in any dimension. */
143  unsigned *out_width, unsigned *out_height,
144  unsigned width, unsigned height);
145 
146 /* First step of processing a frame. The filter submits work by
147  * filling in the packets array.
148  *
149  * The number of elements in the array is as returned by query_num_threads.
150  * The processing itself happens in worker threads after this returns.
151  */
153  struct softfilter_work_packet *packets,
154  void *output, size_t output_stride,
155  const void *input, unsigned width, unsigned height, size_t input_stride);
156 
157 /* Returns the number of worker threads the filter will use.
158  * This can differ from the value passed to create() instead the filter
159  * cannot be parallelized, etc. The number of threads must be less-or-equal
160  * compared to the value passed to create(). */
161 typedef unsigned (*softfilter_query_num_threads_t)(void *data);
162 
164 {
167 
170 
174 
175  /* Must be SOFTFILTER_API_VERSION. */
176  unsigned api_version;
177  /* Human readable identifier of implementation. */
178  const char *ident;
179  /* Computer-friendly short version of ident.
180  * Lower case, no spaces and special characters, etc. */
181  const char *short_ident;
182 };
183 
184 #ifdef __cplusplus
185 }
186 #endif
187 
188 #endif
189 
const GLvoid * ptr
Definition: nx_glsym.h:242
softfilter_create_t create
Definition: softfilter.h:168
softfilter_get_work_packets_t get_work_packets
Definition: softfilter.h:173
softfilter_config_get_float_t get_float
Definition: softfilter.h:75
GLboolean GLenum GLenum GLvoid * values
Definition: glext.h:6318
void(* softfilter_destroy_t)(void *data)
Definition: softfilter.h:137
const char * short_ident
Definition: softfilter.h:181
void(* softfilter_get_work_packets_t)(void *data, struct softfilter_work_packet *packets, void *output, size_t output_stride, const void *input, unsigned width, unsigned height, size_t input_stride)
Definition: softfilter.h:152
int(* softfilter_config_get_int_array_t)(void *userdata, const char *key, int **values, unsigned *out_num_values, const int *default_values, unsigned num_default_values)
Definition: softfilter.h:62
int(* softfilter_config_get_string_t)(void *userdata, const char *key, char **output, const char *default_output)
Definition: softfilter.h:66
typedef void(__stdcall *PFN_DESTRUCTION_CALLBACK)(void *pData)
GLenum GLenum GLenum input
Definition: glext.h:9938
int(* softfilter_config_get_int_t)(void *userdata, const char *key, int *value, int default_value)
Definition: softfilter.h:53
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: glext.h:6303
softfilter_work_t work
Definition: softfilter.h:123
softfilter_config_get_int_t get_int
Definition: softfilter.h:76
void(* softfilter_query_output_size_t)(void *data, unsigned *out_width, unsigned *out_height, unsigned width, unsigned height)
Definition: softfilter.h:142
softfilter_query_output_size_t query_output_size
Definition: softfilter.h:172
const char * ident
Definition: softfilter.h:178
Definition: softfilter.h:121
softfilter_config_get_string_t get_string
Definition: softfilter.h:81
softfilter_query_output_formats_t query_output_formats
Definition: softfilter.h:166
softfilter_query_input_formats_t query_input_formats
Definition: softfilter.h:165
void(* softfilter_work_t)(void *data, void *thread_data)
Definition: softfilter.h:120
static unsigned max_height
Definition: gx_gfx.c:278
unsigned softfilter_simd_mask_t
Definition: softfilter.h:46
Definition: softfilter.h:73
void(* softfilter_config_free_t)(void *ptr)
Definition: softfilter.h:71
Definition: rthreads.c:72
struct config_s config
Definition: softfilter.h:163
void *(* softfilter_create_t)(const struct softfilter_config *config, unsigned in_fmt, unsigned out_fmt, unsigned max_width, unsigned max_height, unsigned threads, softfilter_simd_mask_t simd, void *userdata)
Definition: softfilter.h:132
std::string output
Definition: Config.FromFile.cpp:44
softfilter_config_get_int_array_t get_int_array
Definition: softfilter.h:79
softfilter_destroy_t destroy
Definition: softfilter.h:169
unsigned(* softfilter_query_output_formats_t)(unsigned input_format)
Definition: softfilter.h:116
int(* softfilter_config_get_float_array_t)(void *userdata, const char *key, float **values, unsigned *out_num_values, const float *default_values, unsigned num_default_values)
Definition: softfilter.h:57
GLint GLint GLsizei width
Definition: glext.h:6293
GLsizei const GLfloat * value
Definition: glext.h:6709
void * thread_data
Definition: softfilter.h:124
int(* softfilter_config_get_float_t)(void *userdata, const char *key, float *value, float default_value)
Definition: softfilter.h:50
unsigned api_version
Definition: softfilter.h:176
unsigned(* softfilter_query_input_formats_t)(void)
Definition: softfilter.h:112
unsigned(* softfilter_query_num_threads_t)(void *data)
Definition: softfilter.h:161
softfilter_query_num_threads_t query_num_threads
Definition: softfilter.h:171
softfilter_config_free_t free
Definition: softfilter.h:84
const struct softfilter_implementation * softfilter_get_implementation(softfilter_simd_mask_t simd)
Definition: 2xbr.c:762
GLint GLint GLsizei GLsizei height
Definition: glext.h:6293
softfilter_config_get_float_array_t get_float_array
Definition: softfilter.h:78