2010-05-14 18:59:31 -04:00
|
|
|
! (c)2010 Joe Groff bsd license
|
|
|
|
USING: accessors alien.c-types alien.data alien.destructors
|
|
|
|
continuations cuda cuda.ffi cuda.gl.ffi cuda.utils destructors
|
|
|
|
fry gpu.buffers kernel ;
|
|
|
|
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-14 18:59:31 -04:00
|
|
|
[ [ create-gl-cuda-context ] (set-up-cuda-context) ] dip (with-cuda-context) ; inline
|
|
|
|
|
|
|
|
: gl-buffer>resource ( gl-buffer flags -- resource )
|
|
|
|
[ 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
|