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 MODULE = opencl.dll
UNIXLIB = opencl.so
EXTRALIBS = $(OPENCL_LIBS) EXTRALIBS = $(OPENCL_LIBS)
C_SRCS = \ C_SRCS = \
......
...@@ -83,6 +83,8 @@ sub generate_pe_thunk($$) ...@@ -83,6 +83,8 @@ sub generate_pe_thunk($$)
my $trace_arg = ""; my $trace_arg = "";
my $ret = get_func_proto( "%s WINAPI %s(%s)", $name, $func_ref ); 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]}) foreach my $arg (@{$func_ref->[1]})
{ {
my $ptype = get_arg_type( $arg ); my $ptype = get_arg_type( $arg );
...@@ -109,10 +111,26 @@ sub generate_pe_thunk($$) ...@@ -109,10 +111,26 @@ sub generate_pe_thunk($$)
$call_arg =~ s/,$/ /; $call_arg =~ s/,$/ /;
$trace_arg =~ s/^, //; $trace_arg =~ s/^, //;
$ret .= "\n{\n"; $ret .= "\n{\n";
$ret .= " TRACE( \"($trace_arg)\\n\"$trace_call_arg );\n" if $gen_traces; if (is_void_func( $func_ref ))
$ret .= " "; {
$ret .= "return " unless is_void_func( $func_ref ); $ret .= " struct ${name}_params params = {$call_arg};\n";
$ret .= "opencl_funcs->p$name($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 .= " OPENCL_CALL( $name, &params );\n";
$ret .= " return __retval;\n";
}
$ret .= "}\n"; $ret .= "}\n";
return $ret; return $ret;
} }
...@@ -122,19 +140,33 @@ sub generate_unix_thunk($$) ...@@ -122,19 +140,33 @@ sub generate_unix_thunk($$)
my ($name, $func_ref) = @_; my ($name, $func_ref) = @_;
my $call_arg = ""; 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]}) foreach my $arg (@{$func_ref->[1]})
{ {
my $ptype = get_arg_type( $arg ); my $ptype = get_arg_type( $arg );
next unless $arg->findnodes("./name"); next unless $arg->findnodes("./name");
my $pname = get_arg_name( $arg ); my $pname = get_arg_name( $arg );
my $param = $arg->textContent(); my $param = $arg->textContent();
$call_arg .= " " . $pname . ","; $call_arg .= " params->" . $pname . ",";
} }
$call_arg =~ s/,$/ /; $call_arg =~ s/,$/ /;
$ret .= "\n{\n "; $ret .= "{\n";
$ret .= "return " unless is_void_func( $func_ref ); $ret .= " struct ${name}_params *params = args;\n\n" if $call_arg;
$ret .= "$name($call_arg);\n"; 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"; $ret .= "}\n";
return $ret; return $ret;
} }
...@@ -178,6 +210,24 @@ sub get_func_proto($$$) ...@@ -178,6 +210,24 @@ sub get_func_proto($$$)
return sprintf $format, $proto, $name, $args; 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 # extract and check the number of arguments
if (@ARGV > 1) if (@ARGV > 1)
{ {
...@@ -480,7 +530,7 @@ foreach (sort keys %core_functions) ...@@ -480,7 +530,7 @@ foreach (sort keys %core_functions)
print UNIX "\n", generate_unix_thunk( $_, $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) foreach (sort keys %core_functions)
{ {
next unless needs_unix_function( $_ ); next unless needs_unix_function( $_ );
...@@ -495,15 +545,19 @@ open(UNIXHEADER, ">$unixheader_file") or die "cannot create $unixheader_file"; ...@@ -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 "/* Automatically generated from OpenCL registry files; DO NOT EDIT! */\n\n";
print UNIXHEADER "struct opencl_funcs\n{\n";
foreach (sort keys %core_functions) foreach (sort keys %core_functions)
{ {
next unless needs_unix_function( $_ ); 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); close(UNIXHEADER);
......
...@@ -28,9 +28,13 @@ ...@@ -28,9 +28,13 @@
#include "windef.h" #include "windef.h"
#include "winbase.h" #include "winbase.h"
#include "winternl.h" #include "winternl.h"
#include "wine/unixlib.h"
#include "wine/debug.h" #include "wine/debug.h"
BOOL extension_is_supported( const char *name, size_t len ) DECLSPEC_HIDDEN; 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 #endif
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
WINE_DEFAULT_DEBUG_CHANNEL(opencl); 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 ) 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, ...@@ -91,14 +91,18 @@ cl_int WINAPI clGetPlatformInfo( cl_platform_id platform, cl_platform_info name,
{ {
size_t unix_size; size_t unix_size;
char *unix_exts; 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) if (ret != CL_SUCCESS)
return ret; return ret;
if (!(unix_exts = malloc( unix_size ))) if (!(unix_exts = malloc( unix_size )))
return CL_OUT_OF_HOST_MEMORY; 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) if (ret != CL_SUCCESS)
{ {
free( unix_exts ); free( unix_exts );
...@@ -111,7 +115,8 @@ cl_int WINAPI clGetPlatformInfo( cl_platform_id platform, cl_platform_info name, ...@@ -111,7 +115,8 @@ cl_int WINAPI clGetPlatformInfo( cl_platform_id platform, cl_platform_info name,
} }
else 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; return ret;
...@@ -129,14 +134,18 @@ cl_int WINAPI clGetDeviceInfo( cl_device_id device, cl_device_info name, ...@@ -129,14 +134,18 @@ cl_int WINAPI clGetDeviceInfo( cl_device_id device, cl_device_info name,
{ {
size_t unix_size; size_t unix_size;
char *unix_exts; 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) if (ret != CL_SUCCESS)
return ret; return ret;
if (!(unix_exts = malloc( unix_size ))) if (!(unix_exts = malloc( unix_size )))
return CL_OUT_OF_HOST_MEMORY; 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) if (ret != CL_SUCCESS)
{ {
free( unix_exts ); free( unix_exts );
...@@ -149,7 +158,8 @@ cl_int WINAPI clGetDeviceInfo( cl_device_id device, cl_device_info name, ...@@ -149,7 +158,8 @@ cl_int WINAPI clGetDeviceInfo( cl_device_id device, cl_device_info name,
} }
else 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 */ /* Filter out the CL_EXEC_NATIVE_KERNEL flag */
...@@ -197,7 +207,8 @@ BOOL WINAPI DllMain( HINSTANCE instance, DWORD reason, void *reserved ) ...@@ -197,7 +207,8 @@ BOOL WINAPI DllMain( HINSTANCE instance, DWORD reason, void *reserved )
if (reason == DLL_PROCESS_ATTACH) if (reason == DLL_PROCESS_ATTACH)
{ {
DisableThreadLibraryCalls( instance ); 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; return TRUE;
} }
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
#include "windef.h" #include "windef.h"
#include "winbase.h" #include "winbase.h"
#include "winternl.h" #include "winternl.h"
#include "wine/unixlib.h"
#include "wine/debug.h" #include "wine/debug.h"
#define CL_SILENCE_DEPRECATION #define CL_SILENCE_DEPRECATION
...@@ -44,44 +44,13 @@ ...@@ -44,44 +44,13 @@
#include "unixlib.h" #include "unixlib.h"
cl_int WINAPI wrap_clBuildProgram( cl_program program, cl_uint num_devices, NTSTATUS wrap_clBuildProgram( void *args ) DECLSPEC_HIDDEN;
const cl_device_id *device_list, const char *options, NTSTATUS wrap_clCreateContext( void *args ) DECLSPEC_HIDDEN;
void (WINAPI *pfn_notify)(cl_program program, void *user_data), NTSTATUS wrap_clCreateContextFromType( void *args ) DECLSPEC_HIDDEN;
void *user_data ) DECLSPEC_HIDDEN; NTSTATUS wrap_clEnqueueNativeKernel( void *args ) DECLSPEC_HIDDEN;
NTSTATUS wrap_clSetEventCallback( void *args ) DECLSPEC_HIDDEN;
cl_context WINAPI wrap_clCreateContext( const cl_context_properties *properties, NTSTATUS wrap_clSetMemObjectDestructorCallback( void *args ) DECLSPEC_HIDDEN;
cl_uint num_devices, const cl_device_id *devices, NTSTATUS wrap_clCompileProgram( void *args ) DECLSPEC_HIDDEN;
void (WINAPI *pfn_notify)(const char *errinfo, const void *private_info, size_t cb, void *user_data), NTSTATUS wrap_clLinkProgram( void *args ) DECLSPEC_HIDDEN;
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;
#endif #endif
...@@ -26,81 +26,65 @@ ...@@ -26,81 +26,65 @@
WINE_DEFAULT_DEBUG_CHANNEL(opencl); WINE_DEFAULT_DEBUG_CHANNEL(opencl);
cl_int WINAPI wrap_clBuildProgram( cl_program program, cl_uint num_devices, NTSTATUS wrap_clBuildProgram( void *args )
const cl_device_id *device_list, const char *options,
void (WINAPI *pfn_notify)(cl_program program, void *user_data),
void *user_data )
{ {
if (pfn_notify) FIXME( "notify callback not supported\n" ); struct clBuildProgram_params *params = args;
return clBuildProgram( program, num_devices, device_list, options, NULL, NULL );
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, NTSTATUS wrap_clCreateContext( void *args )
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 )
{ {
if (pfn_notify) FIXME( "notify callback not supported\n" ); struct clCreateContext_params *params = args;
return clCreateContext( properties, num_devices, devices, NULL, NULL, errcode_ret );
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, NTSTATUS wrap_clCreateContextFromType( void *args )
void (WINAPI *pfn_notify)(const char *errinfo, const void *private_info, size_t cb, void *user_data),
void *user_data, cl_int *errcode_ret )
{ {
if (pfn_notify) FIXME( "notify callback not supported\n" ); struct clCreateContextFromType_params *params = args;
return clCreateContextFromType( properties, device_type, NULL, NULL, errcode_ret );
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, NTSTATUS wrap_clEnqueueNativeKernel( void *args )
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 )
{ {
/* we have no clear way to wrap user_func */ /* we have no clear way to wrap user_func */
FIXME( "not implemented\n" ); FIXME( "not implemented\n" );
return CL_INVALID_OPERATION; return CL_INVALID_OPERATION;
} }
cl_int WINAPI wrap_clSetEventCallback( cl_event event, cl_int type, NTSTATUS wrap_clSetEventCallback( void *args )
void (WINAPI *pfn_notify)(cl_event, cl_int, void *),
void *user_data)
{ {
FIXME( "not yet implemented\n" ); FIXME( "not yet implemented\n" );
return CL_INVALID_OPERATION; return CL_INVALID_OPERATION;
} }
cl_int WINAPI wrap_clSetMemObjectDestructorCallback(cl_mem memobj, NTSTATUS wrap_clSetMemObjectDestructorCallback( void *args )
void (WINAPI *pfn_notify)(cl_mem, void *),
void *user_data)
{ {
FIXME( "not yet implemented\n" ); FIXME( "not yet implemented\n" );
return CL_INVALID_OPERATION; return CL_INVALID_OPERATION;
} }
cl_int WINAPI wrap_clCompileProgram( cl_program program, cl_uint num_devices, NTSTATUS wrap_clCompileProgram( void *args )
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 )
{ {
FIXME( "not yet implemented\n" ); FIXME( "not yet implemented\n" );
return CL_INVALID_OPERATION; return CL_INVALID_OPERATION;
} }
cl_program WINAPI wrap_clLinkProgram( cl_context context, cl_uint num_devices, const cl_device_id *device_list, NTSTATUS wrap_clLinkProgram( void *args )
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 )
{ {
FIXME( "not yet implemented\n" ); struct clLinkProgram_params *params = args;
*errcode_ret = CL_INVALID_OPERATION;
return NULL;
}
NTSTATUS CDECL __wine_init_unix_lib( HMODULE module, DWORD reason, const void *ptr_in, void *ptr_out ) FIXME( "not yet implemented\n" );
{ *params->errcode_ret = CL_INVALID_OPERATION;
if (reason != DLL_PROCESS_ATTACH) return STATUS_SUCCESS;
*(const struct opencl_funcs **)ptr_out = &funcs;
return STATUS_SUCCESS; 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