Home My Page Projects Code Snippets Project Openings 3D graphics for Standard ML
Summary Activity SCM

SCM Repository

[sml3d] View of /trunk/sml3d/src/raw-data/data-buffer-sig.sml
ViewVC logotype

View of /trunk/sml3d/src/raw-data/data-buffer-sig.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 777 - (download) (annotate)
Mon Mar 8 14:26:56 2010 UTC (9 years, 9 months ago) by jhr
File size: 11508 byte(s)
  Added support for dealing with buffers of C structs (we need this feature for
  OpenCL)
(* data-buffer-sig.sml
 *
 * COPYRIGHT (c) 2010 John Reppy (http://cs.uchicago.edu/~jhr)
 * All rights reserved.
 *
 * This is an interface to arrays of scalar types that are allocated in the C heap.
 * It is designed to support the images, vertex arrays, draw buffers, etc.
 *)

signature DATA_BUFFER =
  sig

    type float = Real32.real
    type double = Real64.real

    type 'a buffer
    type 'a buffer2 = ('a * 'a) buffer
    type 'a buffer3 = ('a * 'a * 'a) buffer
    type 'a buffer4 = ('a * 'a * 'a * 'a) buffer

  (* element types *)
    type 'a ty
    val ty2   : 'a ty -> ('a * 'a) ty
    val ty3   : 'a ty -> ('a * 'a * 'a) ty
    val ty4   : 'a ty -> ('a * 'a * 'a * 'a) ty
    val tyb   : Int8.int ty
    val ty2b  : (Int8.int * Int8.int) ty
    val ty3b  : (Int8.int * Int8.int * Int8.int) ty
    val ty4b  : (Int8.int * Int8.int * Int8.int * Int8.int) ty
    val tyub  : Word8.word ty
    val ty2ub : (Word8.word * Word8.word) ty
    val ty3ub : (Word8.word * Word8.word * Word8.word) ty
    val ty4ub : (Word8.word * Word8.word * Word8.word * Word8.word) ty
    val tys   : Int16.int ty
    val ty2s  : (Int16.int * Int16.int) ty
    val ty3s  : (Int16.int * Int16.int * Int16.int) ty
    val ty4s  : (Int16.int * Int16.int * Int16.int * Int16.int) ty
    val tyus  : Word16.word ty
    val ty2us : (Word16.word * Word16.word) ty
    val ty3us : (Word16.word * Word16.word * Word16.word) ty
    val ty4us : (Word16.word * Word16.word * Word16.word * Word16.word) ty
    val tyi   : Int32.int ty
    val ty2i  : (Int32.int * Int32.int) ty
    val ty3i  : (Int32.int * Int32.int * Int32.int) ty
    val ty4i  : (Int32.int * Int32.int * Int32.int * Int32.int) ty
    val tyui  : Word32.word ty
    val ty2ui : (Word32.word * Word32.word) ty
    val ty3ui : (Word32.word * Word32.word * Word32.word) ty
    val ty4ui : (Word32.word * Word32.word * Word32.word * Word32.word) ty
    val tyf   : float ty
    val ty2f  : (float * float) ty
    val ty3f  : (float * float * float) ty
    val ty4f  : (float * float * float * float) ty
    val tyd   : double ty
    val ty2d  : (double * double) ty
    val ty3d  : (double * double * double) ty
    val ty4d  : (double * double * double * double) ty

  (* a "cstruct" element type is a C struct type of some size and alignment; it is up to the
   * user to get these right!.  The only way to get/set values in a cstruct buffer is by using
   * the C pointers.  Note that the alignment must be a power of two!
   *)
    type cstruct
    val tyStruct : {szb : C_Size.word, align : C_Size.word} -> cstruct ty

    val sizeOf : 'a ty -> C_Size.word		(* element size in bytes *)

    val make : {
	    alloc : C_Size.word -> C_Pointer.t,
	    free : C_Pointer.t -> unit
	  } -> ('a ty * int) -> 'a buffer

    val new : ('a ty * int) -> 'a buffer

  (* create a buffer from a pointer to C data.  The first argument is the free
   * function and the second argument is the element type/number of elements/
   * data pointer triple.
   *) 
    val wrapCData : (C_Pointer.t -> unit) -> ('a ty * int * C_Pointer.t) -> 'a buffer

    val delete : 'a buffer -> unit
    val valid  : 'a buffer -> bool
    val length : 'a buffer -> int
    val typeOf : 'a buffer -> 'a ty		(* element type *)

  (* monomorphic get/set operations on buffers *)
    val getb  : (Int8.int buffer * int) -> Int8.int
    val setb  : (Int8.int buffer * int * Int8.int) -> unit
    val getub : (Word8.word buffer * int) -> Word8.word
    val setub : (Word8.word buffer * int * Word8.word) -> unit
    val gets  : (Int16.int buffer * int) -> Int16.int
    val sets  : (Int16.int buffer * int * Int16.int) -> unit
    val getus : (Word16.word buffer * int) -> Word16.word
    val setus : (Word16.word buffer * int * Word16.word) -> unit
    val geti  : (Int32.int buffer * int) -> Int32.int
    val seti  : (Int32.int buffer * int * Int32.int) -> unit
    val getui : (Word32.word buffer * int) -> Word32.word
    val setui : (Word32.word buffer * int * Word32.word) -> unit
    val getf  : (float buffer * int) -> float
    val setf  : (float buffer * int * float) -> unit
    val getd  : (double buffer * int) -> double
    val setd  : (double buffer * int * double) -> unit

    val get2b  : (Int8.int buffer2 * int) -> (Int8.int * Int8.int)
    val set2b  : (Int8.int buffer2 * int * (Int8.int * Int8.int)) -> unit
    val get2ub : (Word8.word buffer2 * int) -> (Word8.word * Word8.word)
    val set2ub : (Word8.word buffer2 * int * (Word8.word * Word8.word)) -> unit
    val get2s  : (Int16.int buffer2 * int) -> (Int16.int * Int16.int)
    val set2s  : (Int16.int buffer2 * int * (Int16.int * Int16.int)) -> unit
    val get2us : (Word16.word buffer2 * int) -> (Word16.word * Word16.word)
    val set2us : (Word16.word buffer2 * int * (Word16.word * Word16.word)) -> unit
    val get2i  : (Int32.int buffer2 * int) -> (Int32.int * Int32.int)
    val set2i  : (Int32.int buffer2 * int * (Int32.int * Int32.int)) -> unit
    val get2ui : (Word32.word buffer2 * int) -> (Word32.word * Word32.word)
    val set2ui : (Word32.word buffer2 * int * (Word32.word * Word32.word)) -> unit
    val get2f  : (float buffer2 * int) -> (float * float)
    val set2f  : (float buffer2 * int * (float * float)) -> unit
    val get2d  : (double buffer2 * int) -> (double * double)
    val set2d  : (double buffer2 * int * (double * double)) -> unit

    val get3b  : (Int8.int buffer3 * int) -> (Int8.int * Int8.int * Int8.int)
    val set3b  : (Int8.int buffer3 * int * (Int8.int * Int8.int * Int8.int)) -> unit
    val get3ub : (Word8.word buffer3 * int) -> (Word8.word * Word8.word * Word8.word)
    val set3ub : (Word8.word buffer3 * int * (Word8.word * Word8.word * Word8.word)) -> unit
    val get3s  : (Int16.int buffer3 * int) -> (Int16.int * Int16.int * Int16.int)
    val set3s  : (Int16.int buffer3 * int * (Int16.int * Int16.int * Int16.int)) -> unit
    val get3us : (Word16.word buffer3 * int) -> (Word16.word * Word16.word * Word16.word)
    val set3us : (Word16.word buffer3 * int * (Word16.word * Word16.word * Word16.word)) -> unit
    val get3i  : (Int32.int buffer3 * int) -> (Int32.int * Int32.int * Int32.int)
    val set3i  : (Int32.int buffer3 * int * (Int32.int * Int32.int * Int32.int)) -> unit
    val get3ui : (Word32.word buffer3 * int) -> (Word32.word * Word32.word * Word32.word)
    val set3ui : (Word32.word buffer3 * int * (Word32.word * Word32.word * Word32.word)) -> unit
    val get3f  : (float buffer3 * int) -> (float * float * float)
    val set3f  : (float buffer3 * int * (float * float * float)) -> unit
    val get3d  : (double buffer3 * int) -> (double * double * double)
    val set3d  : (double buffer3 * int * (double * double * double)) -> unit

    val get4b  : (Int8.int buffer4 * int) -> (Int8.int * Int8.int * Int8.int * Int8.int)
    val set4b  : (Int8.int buffer4 * int * (Int8.int * Int8.int * Int8.int * Int8.int)) -> unit
    val get4ub : (Word8.word buffer4 * int) -> (Word8.word * Word8.word * Word8.word * Word8.word)
    val set4ub : (Word8.word buffer4 * int * (Word8.word * Word8.word * Word8.word * Word8.word)) -> unit
    val get4s  : (Int16.int buffer4 * int) -> (Int16.int * Int16.int * Int16.int * Int16.int)
    val set4s  : (Int16.int buffer4 * int * (Int16.int * Int16.int * Int16.int * Int16.int)) -> unit
    val get4us : (Word16.word buffer4 * int) -> (Word16.word * Word16.word * Word16.word * Word16.word)
    val set4us : (Word16.word buffer4 * int * (Word16.word * Word16.word * Word16.word * Word16.word)) -> unit
    val get4i  : (Int32.int buffer4 * int) -> (Int32.int * Int32.int * Int32.int * Int32.int)
    val set4i  : (Int32.int buffer4 * int * (Int32.int * Int32.int * Int32.int * Int32.int)) -> unit
    val get4ui : (Word32.word buffer4 * int) -> (Word32.word * Word32.word * Word32.word * Word32.word)
    val set4ui : (Word32.word buffer4 * int * (Word32.word * Word32.word * Word32.word * Word32.word)) -> unit
    val get4f  : (float buffer4 * int) -> (float * float * float * float)
    val set4f  : (float buffer4 * int * (float * float * float * float)) -> unit
    val get4d  : (double buffer4 * int) -> (double * double * double * double)
    val set4d  : (double buffer4 * int * (double * double * double * double)) -> unit

  (* interpolation between buffers *)
    val lerpf  : {a : float buffer, t : float, b : float buffer, dst : float buffer} -> unit
    val lerp2f : {a : float buffer2, t : float, b : float buffer2, dst : float buffer2} -> unit
    val lerp3f : {a : float buffer3, t : float, b : float buffer3, dst : float buffer3} -> unit
    val lerp4f : {a : float buffer4, t : float, b : float buffer4, dst : float buffer4} -> unit

(*
  (* return a flat view of a buffer *)
    val flat2b  : Int8.int buffer2 -> Int8.int buffer
    val flat2ub : Word8.word buffer2 -> Word8.word buffer
    val flat2s  : Int16.int buffer2 -> Int16.int buffer
    val flat2us : Word16.word buffer2 -> Word16.word buffer
    val flat2i  : Int32.int buffer2 -> Int32.int buffer
    val flat2ui : Word32.word buffer2 -> Word32.word buffer
    val flat2f  : float buffer2 -> float buffer
    val flat2d  : double buffer2 -> double buffer

    val flat3b  : Int8.int buffer3 -> Int8.int buffer
    val flat3ub : Word8.word buffer3 -> Word8.word buffer
    val flat3s  : Int16.int buffer3 -> Int16.int buffer
    val flat3us : Word16.word buffer3 -> Word16.word buffer
    val flat3i  : Int32.int buffer3 -> Int32.int buffer
    val flat3ui : Word32.word buffer3 -> Word32.word buffer
    val flat3f  : float buffer3 -> float buffer
    val flat3d  : double buffer3 -> double buffer

    val flat4b  : Int8.int buffer4 -> Int8.int buffer
    val flat4ub : Word8.word buffer4 -> Word8.word buffer
    val flat4s  : Int16.int buffer4 -> Int16.int buffer
    val flat4us : Word16.word buffer4 -> Word16.word buffer
    val flat4i  : Int32.int buffer4 -> Int32.int buffer
    val flat4ui : Word32.word buffer4 -> Word32.word buffer
    val flat4f  : float buffer4 -> float buffer
    val flat4d  : double buffer4 -> double buffer
*)

  (* polymorphic operations on buffers *)
    val get : 'a buffer * int -> 'a
    val set : 'a buffer * int * 'a -> unit
    val update : 'a buffer * int * ('a -> 'a) -> unit
    val app : ('a -> unit) -> 'a buffer -> unit
    val appi : (int * 'a -> unit) -> 'a buffer -> unit
    val modify : ('a -> 'a) -> 'a buffer -> unit
    val modifyi : (int * 'a -> 'a) -> 'a buffer -> unit
    val init : ('a buffer * (int -> 'a)) -> unit

  (* moving data in and out of SML *)
    val mapToVector : 'a buffer * ('a -> 'b) -> 'b vector
    val mapToArray : 'a buffer * ('a -> 'b) -> 'b array
    val mapFromVector : ('a -> 'b) -> ('a vector * 'b buffer) -> unit
    val mapFromArray : ('a -> 'b) -> ('a array * 'b buffer) -> unit
    val copyFromVector : ('a vector * 'a buffer) -> unit
    val copyFromArray : ('a array * 'a buffer) -> unit
    val fromVector : 'a ty -> 'a vector -> 'a buffer
    val fromArray  : 'a ty -> 'a array -> 'a buffer
    val tabulate : ('a ty * int * (int -> 'a)) -> 'a buffer

  (* support for passing buffers to C code.  Note that it is the responsibility of client code to
   * make sure that data that is visibile to C is also retained by the SML heap.
   *)
    val withPtr : ('a buffer * ({data : C_Pointer.t, szb :  C_Size.word, elemSzb : C_Size.word} -> 'b)) -> 'b
    val touch : 'a buffer -> unit

  (* apply an operation to a given element in a cstruct buffer *)
    val withCStruct : (cstruct buffer * (C_Pointer.t -> 'a)) -> int -> 'a

  end

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0