windows include files are broken
windows include files are broken
in FreeBASIC-1.07.1 you get many errors when you #include "crt.bi" both win32 and win64
Last edited by srvaldez on Mar 05, 2020 10:50, edited 1 time in total.
Re: crt.bi is broken
A small example, please.
Re: crt.bi is broken
hello fxm
while trying the example by D.J. Peter viewtopic.php?p=267408#p267408 I encountered the type size_t which is defined in crt\ctype, well, since I didn't remember which .bi to include I thought just include crt.bi, that's when the problem showed up
code by D.J. Peters
while trying the example by D.J. Peter viewtopic.php?p=267408#p267408 I encountered the type size_t which is defined in crt\ctype, well, since I didn't remember which .bi to include I thought just include crt.bi, that's when the problem showed up
code by D.J. Peters
Code: Select all
#include "cl.bi"
#include "crt.bi" ''#include "crt\ctype.bi"
dim as string CODE
CODE &= !"kernel void shader (global uchar4 * pixels, uint width, uint height, float time) \n"
CODE &= !"{\n"
CODE &= !" uint ix = get_global_id(0); \n"
CODE &= !" uint iy = get_global_id(1); \n"
CODE &= !" uint i = ix+width*iy; \n"
CODE &= !" float x = ix/(float)width; \n"
CODE &= !" float y = iy/(float)height; \n"
CODE &= !" uchar r = (uchar)(x*255.f); \n"
CODE &= !" uchar g = (uchar)(y*255.f); \n"
CODE &= !" uchar b = (uchar)(255.f * (0.5f + 0.5f*sin(time))); \n"
CODE &= !" pixels[i] = (uchar4)(b,g,r,255); \n"
CODE &= !"}\n"
dim as zstring ptr pCode = strptr(CODE)
dim as cl_platform_id platform
' get first platform
dim as cl_int status = clGetPlatformIDs(1,@platform,NULL)
' get first device from platform try a GPU device at first
dim as cl_device_id device
status = clGetDeviceIDs(platform,CL_DEVICE_TYPE_GPU,1,@device,NULL)
if status = CL_INVALID_DEVICE_TYPE then
' fallback: try a CPU device also
status = clGetDeviceIDs(Platform,CL_DEVICE_TYPE_CPU,1,@device,NULL)
end if
if status then
print "error: can't create OpenCL device !"
flip : beep : sleep : end 1
end if
' create a device context
dim as cl_context context = clCreateContext(0,1,@device,NULL,NULL,@status)
' create program object in context from sourcecode
dim as cl_program program = clCreateProgramWithSource(context,1,@pCode,NULL,@status)
' compile and link the program
status = clBuildProgram(program, 0, NULL, NULL, NULL, NULL)
if status then
print "error: can't create compile unand link kernel !"
dim as size_t nChars ' get size of log
clGetProgramBuildInfo(program,device,CL_PROGRAM_BUILD_LOG,0,0,@nChars)
dim as string strLog=space(nChars)
' get log from compiler/linker
clGetProgramBuildInfo(program,device,CL_PROGRAM_BUILD_LOG,nChars,strptr(strLog),NULL)
print strLog
flip : beep : sleep : end 1
end if
' create a kernel object
dim as cl_kernel kernel = clCreateKernel(program, "shader", @status)
' get size of workgroup from device
dim as size_t WorkGroupSize
status = clGetKernelWorkGroupInfo(kernel,device,CL_KERNEL_WORK_GROUP_SIZE, sizeof(size_t),@WorkGroupSize,NULL)
' calculate local worksize
'(must be workgroupsize div power of two)
dim as size_t LocalSize = WorkGroupSize
while LocalSize*LocalSize > WorkGroupSize
LocalSize shr=1
wend
dim as cl_int GlobalWidth=640,GlobalHeight = GlobalWidth/16*9
' calculate global worksize (should be a multiply of local worksize
GlobalWidth -=GlobalWidth mod LocalSize
GlobalHeight-=GlobalHeight mod LocalSize
screenres GlobalWidth,GlobalHeight,32,2
screenset 1,0
windowtitle "global: " & GlobalWidth & " x " & GlobalHeight & " local: " & LocalSize & " x " & LocalSize & " worksize"
dim as any ptr pixels,img=imagecreate(GlobalWidth,GlobalHeight)
imageinfo img,,,,,pixels
dim as size_t bufSize = GlobalWidth*GlobalHeight*4
dim as size_t globalSizes(...) => {GlobalWidth,GlobalHeight}
dim as size_t localSizes (...) => {LocalSize ,LocalSize}
' create a memory buffer in the context
dim as cl_mem buffer = clCreateBuffer(context, CL_MEM_READ_WRITE, bufSize, NULL, @status)
' set the parameters of the kernel
status = clSetKernelArg(kernel, 0, sizeof(cl_mem ),@buffer)
status = clSetKernelArg(kernel, 1, sizeof(cl_uint),@GlobalWidth)
status = clSetKernelArg(kernel, 2, sizeof(cl_uint),@GlobalHeight)
' create command queue
dim as cl_command_queue queue = clCreateCommandQueue(context,device,0,@status)
if status then
print "error: can't create a command queue !"
flip : beep : sleep : end 1
end if
dim as integer frames,fps
dim as double tStart=timer
dim as double tLast =tStart
while inkey()=""
dim as single runtime = timer()-tStart
' set the time parameter
status = clSetKernelArg(kernel, 3, sizeof(cl_float),@runtime)
' execute the "2D" kernel
status = clEnqueueNDRangeKernel(queue,kernel,2, NULL, @globalSizes(0), @localSizes(0),0,NULL,NULL)
' read/copy the device buffer in the image buffer
status = clEnqueueReadBuffer (queue,buffer,CL_TRUE,0,bufSize,pixels,0,NULL,NULL)
' draw the runtime and fps in the image
draw string img,(0,0),"fps: " & fps & " time: " & runtime
' put it on the screen
put (0,0),img,PSET
' make hiden page visible
flip
' count the frames
frames+=1
' update every 60 frame the fps
if frames mod 60=0 then
var tNow=timer()
fps=60/(tNow-tLast)
tLast=tNow
end if
wend
' free all resources
clReleaseCommandQueue queue
clReleaseProgram program
clReleaseMemObject buffer
clReleaseContext context
-
- Posts: 8586
- Joined: May 28, 2005 3:28
- Contact:
Re: crt.bi is broken
you have to replace size_t with cl_size_t !!!
if you need size_t in a none OpenCL app you have to include:
#include "crt/stdint.bi"
'#include "crt/stdlib.bi"
if you need size_t in a none OpenCL app you have to include:
#include "crt/stdint.bi"
'#include "crt/stdlib.bi"
Re: crt.bi is broken
sorry for being so late, at the time I couldn't come up with a simple and short example, but today I came across some problems, try to compile the followingfxm wrote:A small example, please.
Code: Select all
#include once "win/winbase.bi"
#include once "win/winnt.bi"
#include once "crt/time.bi"
the problematic include file seems to be "win/winbase.bi" this one line will trigger the errorsD:\dev\FreeBASIC-1.07.1-gcc640-win32\fbc -arch native -s console -gen gcc -Wc -O2 -v "utime.bas"
FreeBASIC Compiler - Version 1.07.1 (2019-11-12), built for win32 (32bit)
Copyright (C) 2004-2019 The FreeBASIC development team.
standalone
target: win32, 686, 32bit
compiling: utime.bas -o utime.c (main module)
D:\dev\FreeBASIC-1.07.1-gcc640-win32\inc\win\winbase.bi(2746) error 59: Illegal specification, at parameter 7 (Arguments) of FormatMessageA() in 'declare function FormatMessageA(byval dwFlags as DWORD, byval lpSource as LPCVOID, byval dwMessageId as DWORD, byval dwLanguageId as DWORD, byval lpBuffer as LPSTR, byval nSize as DWORD, byval Arguments as va_list ptr) as DWORD'
D:\dev\FreeBASIC-1.07.1-gcc640-win32\inc\win\winbase.bi(2747) error 59: Illegal specification, at parameter 7 (Arguments) of FormatMessageW() in 'declare function FormatMessageW(byval dwFlags as DWORD, byval lpSource as LPCVOID, byval dwMessageId as DWORD, byval dwLanguageId as DWORD, byval lpBuffer as LPWSTR, byval nSize as DWORD, byval Arguments as va_list ptr) as DWORD'
D:\dev\FreeBASIC-1.07.1-gcc640-win32\inc\win\winbase.bi(2752) error 59: Illegal specification, at parameter 7 (Arguments) of FormatMessage() in 'declare function FormatMessage alias "FormatMessageA"(byval dwFlags as DWORD, byval lpSource as LPCVOID, byval dwMessageId as DWORD, byval dwLanguageId as DWORD, byval lpBuffer as LPSTR, byval nSize as DWORD, byval Arguments as va_list ptr) as DWORD'
Compilation failed.
Code: Select all
#include once "win/winbase.bi"
Re: windows include files are broken
Code: Select all
#include once "windows.bi"
''#include once "win/winbase.bi"
#include once "win/winnt.bi"
#include once "crt/time.bi"
Re: windows include files are broken
so if I find a snippet in MS help on the web that has an example like
I am supposed to know that winbase should be replaced by windows?
Code: Select all
#include <winbase.h>
#include <winnt.h>
#include <time.h>
void UnixTimeToFileTime(time_t t, LPFILETIME pft)
{
// Note that LONGLONG is a 64-bit value
LONGLONG ll;
ll = Int32x32To64(t, 10000000) + 116444736000000000;
pft->dwLowDateTime = (DWORD)ll;
pft->dwHighDateTime = ll >> 32;
}
Re: windows include files are broken
Neither do I.
In fact "crt/stdarg.bi" is sufficient to declare the only unknown symbol "va_list" ('type va_list as cva_list'):
In fact "crt/stdarg.bi" is sufficient to declare the only unknown symbol "va_list" ('type va_list as cva_list'):
Code: Select all
#include once "crt/stdarg.bi"
#include once "win/winbase.bi"
#include once "win/winnt.bi"
#include once "crt/time.bi"