2010-05-14 18:59:31 -04:00
|
|
|
! (c)2010 Joe Groff bsd license
|
2010-05-25 01:57:10 -04:00
|
|
|
USING: accessors alien alien.c-types alien.data alien.destructors
|
2010-05-20 17:32:35 -04:00
|
|
|
alien.enums continuations cuda cuda.contexts cuda.ffi
|
|
|
|
cuda.gl.ffi destructors fry gpu.buffers kernel ;
|
2010-05-14 18:59:31 -04:00
|
|
|
IN: cuda.gl
|
|
|
|
|
2010-05-15 14:45:02 -04:00
|
|
|
: create-gl-cuda-context ( device flags -- context )
|
|
|
|
swap
|
2010-05-14 18:59:31 -04:00
|
|
|
[ CUcontext <c-object> ] 2dip
|
|
|
|
[ cuGLCtxCreate cuda-error ] 3keep 2drop *void* ; inline
|
|
|
|
|
2010-05-15 14:45:02 -04:00
|
|
|
: with-gl-cuda-context ( device flags quot -- )
|
2010-05-25 00:38:25 -04:00
|
|
|
[ set-up-cuda-context create-gl-cuda-context ] dip (with-cuda-context) ; inline
|
2010-05-14 18:59:31 -04:00
|
|
|
|
|
|
|
: gl-buffer>resource ( gl-buffer flags -- resource )
|
2010-05-15 19:25:27 -04:00
|
|
|
enum>number
|
2010-05-14 18:59:31 -04:00
|
|
|
[ CUgraphicsResource <c-object> ] 2dip
|
|
|
|
[ cuGraphicsGLRegisterBuffer cuda-error ] 3keep 2drop *void* ; inline
|
|
|
|
|
|
|
|
: buffer>resource ( buffer flags -- resource )
|
|
|
|
[ handle>> ] dip gl-buffer>resource ; inline
|
|
|
|
|
|
|
|
: map-resource ( resource -- device-ptr size )
|
|
|
|
[ 1 swap <void*> f cuGraphicsMapResources cuda-error ] [
|
|
|
|
[ CUdeviceptr <c-object> uint <c-object> ] dip
|
|
|
|
[ cuGraphicsResourceGetMappedPointer cuda-error ] 3keep drop
|
|
|
|
[ *uint ] [ *uint ] bi*
|
|
|
|
] bi ; inline
|
|
|
|
|
|
|
|
: unmap-resource ( resource -- )
|
|
|
|
1 swap <void*> f cuGraphicsUnmapResources cuda-error ; inline
|
|
|
|
|
|
|
|
DESTRUCTOR: unmap-resource
|
|
|
|
|
2010-05-14 19:17:03 -04:00
|
|
|
: free-resource ( resource -- )
|
|
|
|
cuGraphicsUnregisterResource cuda-error ; inline
|
|
|
|
|
|
|
|
DESTRUCTOR: free-resource
|
|
|
|
|
2010-05-14 18:59:31 -04:00
|
|
|
: with-mapped-resource ( ..a resource quot: ( ..a device-ptr size -- ..b ) -- ..b )
|
|
|
|
over [ map-resource ] 2dip '[ _ unmap-resource ] [ ] cleanup ; inline
|
2010-05-25 01:57:10 -04:00
|
|
|
|
|
|
|
TUPLE: cuda-buffer
|
|
|
|
{ buffer buffer }
|
|
|
|
{ resource pinned-c-ptr } ;
|
|
|
|
|
|
|
|
: <cuda-buffer> ( upload usage kind size initial-data flags -- buffer )
|
|
|
|
[ <buffer> dup ] dip buffer>resource cuda-buffer boa ; inline
|
|
|
|
|
|
|
|
M: cuda-buffer dispose
|
|
|
|
[ [ free-resource ] when* f ] change-resource
|
|
|
|
buffer>> dispose ; inline
|