Commit 37c40316 authored by Alexandre Julliard's avatar Alexandre Julliard

opencl: Convert the Unix library to the __wine_unix_call interface.

parent f91c0097
MODULE = opencl.dll
UNIXLIB = opencl.so
EXTRALIBS = $(OPENCL_LIBS)
C_SRCS = \
......
......@@ -83,6 +83,8 @@ sub generate_pe_thunk($$)
my $trace_arg = "";
my $ret = get_func_proto( "%s WINAPI %s(%s)", $name, $func_ref );
my $proto = $func_ref->[0]->textContent();
$proto =~ s/ +$//;
foreach my $arg (@{$func_ref->[1]})
{
my $ptype = get_arg_type( $arg );
......@@ -109,10 +111,26 @@ sub generate_pe_thunk($$)
$call_arg =~ s/,$/ /;
$trace_arg =~ s/^, //;
$ret .= "\n{\n";
if (is_void_func( $func_ref ))
{
$ret .= " struct ${name}_params params = {$call_arg};\n";
$ret .= " TRACE( \"($trace_arg)\\n\"$trace_call_arg );\n" if $gen_traces;
$ret .= " OPENCL_CALL( $name, &params );\n"
}
elsif ($proto eq "cl_int")
{
$ret .= " struct ${name}_params params = {$call_arg};\n";
$ret .= " TRACE( \"($trace_arg)\\n\"$trace_call_arg );\n" if $gen_traces;
$ret .= " return OPENCL_CALL( $name, &params );\n";
}
else
{
$ret .= " $proto __retval;\n";
$ret .= " struct ${name}_params params = { &__retval,$call_arg};\n";
$ret .= " TRACE( \"($trace_arg)\\n\"$trace_call_arg );\n" if $gen_traces;
$ret .= " ";
$ret .= "return " unless is_void_func( $func_ref );
$ret .= "opencl_funcs->p$name($call_arg);\n";
$ret .= " OPENCL_CALL( $name, &params );\n";
$ret .= " return __retval;\n";
}
$ret .= "}\n";
return $ret;
}
......@@ -122,19 +140,33 @@ sub generate_unix_thunk($$)
my ($name, $func_ref) = @_;
my $call_arg = "";
my $ret = get_func_proto( "static %s WINAPI wrap_%s(%s)", $name, $func_ref );
my $ret = "static NTSTATUS wrap_$name( void *args )\n";
my $proto = $func_ref->[0]->textContent();
$proto =~ s/ +$//;
foreach my $arg (@{$func_ref->[1]})
{
my $ptype = get_arg_type( $arg );
next unless $arg->findnodes("./name");
my $pname = get_arg_name( $arg );
my $param = $arg->textContent();
$call_arg .= " " . $pname . ",";
$call_arg .= " params->" . $pname . ",";
}
$call_arg =~ s/,$/ /;
$ret .= "\n{\n ";
$ret .= "return " unless is_void_func( $func_ref );
$ret .= "$name($call_arg);\n";
$ret .= "{\n";
$ret .= " struct ${name}_params *params = args;\n\n" if $call_arg;
if (is_void_func( $func_ref ))
{
$ret .= " $name($call_arg);\n";
}
elsif ($proto eq "cl_int")
{
$ret .= " return $name($call_arg);\n";
}
else
{
$ret .= " *params->__retval = $name($call_arg);\n";
$ret .= " return STATUS_SUCCESS;\n";
}
$ret .= "}\n";
return $ret;
}
......@@ -178,6 +210,24 @@ sub get_func_proto($$$)
return sprintf $format, $proto, $name, $args;
}
sub get_func_params($$)
{
my ($name, $func) = @_;
die "unknown func $name" unless defined $func->[0];
my $proto = $func->[0]->textContent();
$proto =~ s/ +$//;
my $params = "struct ${name}_params\n{\n";
$params .= " $proto* __retval;\n" unless $proto eq "cl_int";
foreach my $arg (@{$func->[1]})
{
next unless $arg->findnodes("./name");
(my $argtext = $arg->textContent()) =~ s/ +/ /g;
$argtext =~ s/CL_CALLBACK/WINAPI/g;
$params .= " $argtext;\n";
}
return $params . "};\n";
}
# extract and check the number of arguments
if (@ARGV > 1)
{
......@@ -480,7 +530,7 @@ foreach (sort keys %core_functions)
print UNIX "\n", generate_unix_thunk( $_, $core_functions{$_} );
}
print UNIX "\nconst struct opencl_funcs funcs =\n{\n";
print UNIX "\nconst unixlib_entry_t __wine_unix_call_funcs[] =\n{\n";
foreach (sort keys %core_functions)
{
next unless needs_unix_function( $_ );
......@@ -495,15 +545,19 @@ open(UNIXHEADER, ">$unixheader_file") or die "cannot create $unixheader_file";
print UNIXHEADER "/* Automatically generated from OpenCL registry files; DO NOT EDIT! */\n\n";
print UNIXHEADER "struct opencl_funcs\n{\n";
foreach (sort keys %core_functions)
{
next unless needs_unix_function( $_ );
print UNIXHEADER get_func_proto( " %s (WINAPI *p%s)(%s);\n", $_, $core_functions{$_} );
print UNIXHEADER get_func_params( $_, $core_functions{$_} ), "\n";
}
print UNIXHEADER "};\n\n";
print UNIXHEADER "extern const struct opencl_funcs *opencl_funcs;\n";
print UNIXHEADER "enum opencl_funcs\n{\n";
foreach (sort keys %core_functions)
{
next unless needs_unix_function( $_ );
print UNIXHEADER " unix_$_,\n";
}
print UNIXHEADER "};\n";
close(UNIXHEADER);
......
......@@ -28,9 +28,13 @@
#include "windef.h"
#include "winbase.h"
#include "winternl.h"
#include "wine/unixlib.h"
#include "wine/debug.h"
BOOL extension_is_supported( const char *name, size_t len ) DECLSPEC_HIDDEN;
extern unixlib_handle_t opencl_handle DECLSPEC_HIDDEN;
#define OPENCL_CALL( func, params ) __wine_unix_call( opencl_handle, unix_ ## func, params )
#endif
......@@ -24,7 +24,7 @@
WINE_DEFAULT_DEBUG_CHANNEL(opencl);
const struct opencl_funcs *opencl_funcs = NULL;
unixlib_handle_t opencl_handle = 0;
static cl_int filter_extensions( const char *unix_exts, SIZE_T size, char *win_exts, size_t *ret_size )
{
......@@ -91,14 +91,18 @@ cl_int WINAPI clGetPlatformInfo( cl_platform_id platform, cl_platform_info name,
{
size_t unix_size;
char *unix_exts;
struct clGetPlatformInfo_params params = { platform, name, 0, NULL, &unix_size };
ret = opencl_funcs->pclGetPlatformInfo( platform, name, 0, NULL, &unix_size );
ret = OPENCL_CALL( clGetPlatformInfo, &params );
if (ret != CL_SUCCESS)
return ret;
if (!(unix_exts = malloc( unix_size )))
return CL_OUT_OF_HOST_MEMORY;
ret = opencl_funcs->pclGetPlatformInfo( platform, name, unix_size, unix_exts, NULL );
params.param_value_size = unix_size;
params.param_value = unix_exts;
params.param_value_size_ret = NULL;
ret = OPENCL_CALL( clGetPlatformInfo, &params );
if (ret != CL_SUCCESS)
{
free( unix_exts );
......@@ -111,7 +115,8 @@ cl_int WINAPI clGetPlatformInfo( cl_platform_id platform, cl_platform_info name,
}
else
{
ret = opencl_funcs->pclGetPlatformInfo( platform, name, size, value, ret_size );
struct clGetPlatformInfo_params params = { platform, name, size, value, ret_size };
ret = OPENCL_CALL( clGetPlatformInfo, &params );
}
return ret;
......@@ -129,14 +134,18 @@ cl_int WINAPI clGetDeviceInfo( cl_device_id device, cl_device_info name,
{
size_t unix_size;
char *unix_exts;
struct clGetDeviceInfo_params params = { device, name, 0, NULL, &unix_size };
ret = opencl_funcs->pclGetDeviceInfo( device, name, 0, NULL, &unix_size );
ret = OPENCL_CALL( clGetDeviceInfo, &params );
if (ret != CL_SUCCESS)
return ret;
if (!(unix_exts = malloc( unix_size )))
return CL_OUT_OF_HOST_MEMORY;
ret = opencl_funcs->pclGetDeviceInfo( device, name, unix_size, unix_exts, NULL );
params.param_value_size = unix_size;
params.param_value = unix_exts;
params.param_value_size_ret = NULL;
ret = OPENCL_CALL( clGetDeviceInfo, &params );
if (ret != CL_SUCCESS)
{
free( unix_exts );
......@@ -149,7 +158,8 @@ cl_int WINAPI clGetDeviceInfo( cl_device_id device, cl_device_info name,
}
else
{
ret = opencl_funcs->pclGetDeviceInfo( device, name, size, value, ret_size );
struct clGetDeviceInfo_params params = { device, name, size, value, ret_size };
ret = OPENCL_CALL( clGetDeviceInfo, &params );
}
/* Filter out the CL_EXEC_NATIVE_KERNEL flag */
......@@ -197,7 +207,8 @@ BOOL WINAPI DllMain( HINSTANCE instance, DWORD reason, void *reserved )
if (reason == DLL_PROCESS_ATTACH)
{
DisableThreadLibraryCalls( instance );
return !__wine_init_unix_lib( instance, reason, NULL, &opencl_funcs );
return !NtQueryVirtualMemory( GetCurrentProcess(), instance, MemoryWineUnixFuncs,
&opencl_handle, sizeof(opencl_handle), NULL );
}
return TRUE;
}
......@@ -27,7 +27,7 @@
#include "windef.h"
#include "winbase.h"
#include "winternl.h"
#include "wine/unixlib.h"
#include "wine/debug.h"
#define CL_SILENCE_DEPRECATION
......@@ -44,44 +44,13 @@
#include "unixlib.h"
cl_int WINAPI wrap_clBuildProgram( cl_program program, cl_uint num_devices,
const cl_device_id *device_list, const char *options,
void (WINAPI *pfn_notify)(cl_program program, void *user_data),
void *user_data ) DECLSPEC_HIDDEN;
cl_context WINAPI wrap_clCreateContext( const cl_context_properties *properties,
cl_uint num_devices, const cl_device_id *devices,
void (WINAPI *pfn_notify)(const char *errinfo, const void *private_info, size_t cb, void *user_data),
void *user_data, cl_int *errcode_ret ) DECLSPEC_HIDDEN;
cl_context WINAPI wrap_clCreateContextFromType( const cl_context_properties *properties, cl_device_type device_type,
void (WINAPI *pfn_notify)(const char *errinfo, const void *private_info, size_t cb, void *user_data),
void *user_data, cl_int *errcode_ret ) DECLSPEC_HIDDEN;
cl_int WINAPI wrap_clEnqueueNativeKernel( cl_command_queue command_queue,
void (WINAPI *user_func)(void *),
void *args, size_t cb_args, cl_uint num_mem_objects, const cl_mem *mem_list, const void **args_mem_loc,
cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event ) DECLSPEC_HIDDEN;
cl_int WINAPI wrap_clSetEventCallback( cl_event event, cl_int type,
void (WINAPI *pfn_notify)(cl_event, cl_int, void *),
void *user_data) DECLSPEC_HIDDEN;
cl_int WINAPI wrap_clSetMemObjectDestructorCallback(cl_mem memobj,
void (WINAPI *pfn_notify)(cl_mem, void *),
void *user_data) DECLSPEC_HIDDEN;
cl_int WINAPI wrap_clCompileProgram( cl_program program, cl_uint num_devices,
const cl_device_id *device_list, const char *options, cl_uint num_input_headers,
const cl_program *input_headers, const char **header_include_names,
void (WINAPI *pfn_notify)(cl_program program, void *user_data),
void *user_data ) DECLSPEC_HIDDEN;
cl_program WINAPI wrap_clLinkProgram( cl_context context, cl_uint num_devices, const cl_device_id *device_list,
const char *options, cl_uint num_input_programs, const cl_program *input_programs,
void (WINAPI *pfn_notify)(cl_program program, void *user_data),
void *user_data, cl_int *errcode_ret ) DECLSPEC_HIDDEN;
extern const struct opencl_funcs funcs;
NTSTATUS wrap_clBuildProgram( void *args ) DECLSPEC_HIDDEN;
NTSTATUS wrap_clCreateContext( void *args ) DECLSPEC_HIDDEN;
NTSTATUS wrap_clCreateContextFromType( void *args ) DECLSPEC_HIDDEN;
NTSTATUS wrap_clEnqueueNativeKernel( void *args ) DECLSPEC_HIDDEN;
NTSTATUS wrap_clSetEventCallback( void *args ) DECLSPEC_HIDDEN;
NTSTATUS wrap_clSetMemObjectDestructorCallback( void *args ) DECLSPEC_HIDDEN;
NTSTATUS wrap_clCompileProgram( void *args ) DECLSPEC_HIDDEN;
NTSTATUS wrap_clLinkProgram( void *args ) DECLSPEC_HIDDEN;
#endif
......@@ -26,81 +26,65 @@
WINE_DEFAULT_DEBUG_CHANNEL(opencl);
cl_int WINAPI wrap_clBuildProgram( cl_program program, cl_uint num_devices,
const cl_device_id *device_list, const char *options,
void (WINAPI *pfn_notify)(cl_program program, void *user_data),
void *user_data )
NTSTATUS wrap_clBuildProgram( void *args )
{
if (pfn_notify) FIXME( "notify callback not supported\n" );
return clBuildProgram( program, num_devices, device_list, options, NULL, NULL );
struct clBuildProgram_params *params = args;
if (params->pfn_notify) FIXME( "notify callback not supported\n" );
return clBuildProgram( params->program, params->num_devices, params->device_list,
params->options, NULL, NULL );
}
cl_context WINAPI wrap_clCreateContext( const cl_context_properties *properties,
cl_uint num_devices, const cl_device_id *devices,
void (WINAPI *pfn_notify)(const char *errinfo, const void *private_info, size_t cb, void *user_data),
void *user_data, cl_int *errcode_ret )
NTSTATUS wrap_clCreateContext( void *args )
{
if (pfn_notify) FIXME( "notify callback not supported\n" );
return clCreateContext( properties, num_devices, devices, NULL, NULL, errcode_ret );
struct clCreateContext_params *params = args;
if (params->pfn_notify) FIXME( "notify callback not supported\n" );
*params->__retval = clCreateContext( params->properties, params->num_devices, params->devices,
NULL, NULL, params->errcode_ret );
return STATUS_SUCCESS;
}
cl_context WINAPI wrap_clCreateContextFromType( const cl_context_properties *properties, cl_device_type device_type,
void (WINAPI *pfn_notify)(const char *errinfo, const void *private_info, size_t cb, void *user_data),
void *user_data, cl_int *errcode_ret )
NTSTATUS wrap_clCreateContextFromType( void *args )
{
if (pfn_notify) FIXME( "notify callback not supported\n" );
return clCreateContextFromType( properties, device_type, NULL, NULL, errcode_ret );
struct clCreateContextFromType_params *params = args;
if (params->pfn_notify) FIXME( "notify callback not supported\n" );
*params->__retval = clCreateContextFromType( params->properties, params->device_type,
NULL, NULL, params->errcode_ret );
return STATUS_SUCCESS;
}
cl_int WINAPI wrap_clEnqueueNativeKernel( cl_command_queue command_queue,
void (WINAPI *user_func)(void *),
void *args, size_t cb_args, cl_uint num_mem_objects, const cl_mem *mem_list, const void **args_mem_loc,
cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event )
NTSTATUS wrap_clEnqueueNativeKernel( void *args )
{
/* we have no clear way to wrap user_func */
FIXME( "not implemented\n" );
return CL_INVALID_OPERATION;
}
cl_int WINAPI wrap_clSetEventCallback( cl_event event, cl_int type,
void (WINAPI *pfn_notify)(cl_event, cl_int, void *),
void *user_data)
NTSTATUS wrap_clSetEventCallback( void *args )
{
FIXME( "not yet implemented\n" );
return CL_INVALID_OPERATION;
}
cl_int WINAPI wrap_clSetMemObjectDestructorCallback(cl_mem memobj,
void (WINAPI *pfn_notify)(cl_mem, void *),
void *user_data)
NTSTATUS wrap_clSetMemObjectDestructorCallback( void *args )
{
FIXME( "not yet implemented\n" );
return CL_INVALID_OPERATION;
}
cl_int WINAPI wrap_clCompileProgram( cl_program program, cl_uint num_devices,
const cl_device_id *device_list, const char *options, cl_uint num_input_headers,
const cl_program *input_headers, const char **header_include_names,
void (WINAPI *pfn_notify)(cl_program program, void *user_data),
void *user_data )
NTSTATUS wrap_clCompileProgram( void *args )
{
FIXME( "not yet implemented\n" );
return CL_INVALID_OPERATION;
}
cl_program WINAPI wrap_clLinkProgram( cl_context context, cl_uint num_devices, const cl_device_id *device_list,
const char *options, cl_uint num_input_programs, const cl_program *input_programs,
void (WINAPI *pfn_notify)(cl_program program, void *user_data),
void *user_data, cl_int *errcode_ret )
NTSTATUS wrap_clLinkProgram( void *args )
{
FIXME( "not yet implemented\n" );
*errcode_ret = CL_INVALID_OPERATION;
return NULL;
}
struct clLinkProgram_params *params = args;
NTSTATUS CDECL __wine_init_unix_lib( HMODULE module, DWORD reason, const void *ptr_in, void *ptr_out )
{
if (reason != DLL_PROCESS_ATTACH) return STATUS_SUCCESS;
*(const struct opencl_funcs **)ptr_out = &funcs;
FIXME( "not yet implemented\n" );
*params->errcode_ret = CL_INVALID_OPERATION;
return STATUS_SUCCESS;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment