Merge branch 'master' into new_gc

db4
Slava Pestov 2009-10-19 00:22:53 -05:00
commit 3202ab25a4
5 changed files with 134 additions and 21 deletions

View File

@ -0,0 +1,75 @@
! (c)2009 Joe Groff bsd license
USING: classes help.markup help.syntax kernel quotations ;
IN: math.vectors.conversion
HELP: bad-vconvert
{ $values
{ "from-type" "a SIMD type" } { "to-type" "a SIMD type" }
}
{ $description "This error is thrown when " { $link vconvert } " is given two SIMD types it cannot directly convert." } ;
HELP: bad-vconvert-input
{ $values
{ "value" object } { "expected-type" class }
}
{ $description "This error is thrown when an input to " { $link vconvert } " does not match the expected " { $snippet "from-type" } "." } ;
{ bad-vconvert bad-vconvert-input } related-words
HELP: vconvert
{ $values
{ "from-type" "a SIMD type" } { "to-type" "a SIMD type" }
}
{ $description "Converts SIMD vectors of " { $snippet "from-type" } " to " { $snippet "to-type" } ". The number of inputs and outputs depends on the relationship of the two types:"
{ $list
{ "If " { $snippet "to-type" } " is a floating-point vector type with the same byte length and element count as the integer vector type " { $snippet "from-type" } " (for example, from " { $snippet "int-8" } " to " { $snippet "float-8" } " or from " { $snippet "longlong-2" } " to " { $snippet "double-2" } "), " { $snippet "vconvert" } " takes one vector of " { $snippet "from-type" } " and converts its elements to floating-point, outputting one vector of " { $snippet "to-type" } "." }
{ "Likewise, if " { $snippet "to-type" } " is an integer vector type with the same byte length and element count as the floating-point vector type " { $snippet "from-type" } ", " { $snippet "vconvert" } " takes one vector of " { $snippet "from-type" } " and truncates its elements to integers, outputting one vector of " { $snippet "to-type" } "." }
{ "If " { $snippet "to-type" } " is a vector type with the same byte length as and twice the element count of the vector type " { $snippet "from-type" } " (for example, from " { $snippet "int-4" } " to " { $snippet "ushort-8" } ", from " { $snippet "double-2" } " to " { $snippet "float-4" } ", or from " { $snippet "short-8" } " to " { $snippet "char-16" } "), " { $snippet "vconvert" } " takes two vectors of " { $snippet "from-type" } " and packs them into one vector of " { $snippet "to-type" } ", saturating values too large or small to be representable as elements of " { $snippet "to-type" } "." }
{ "If " { $snippet "to-type" } " is a vector type with the same byte length as and half the element count of the vector type " { $snippet "from-type" } " (for example, from " { $snippet "ushort-8" } " to " { $snippet "int-4" } ", from " { $snippet "float-4" } " to " { $snippet "double-2" } ", or from " { $snippet "char-16" } " to " { $snippet "short-8" } "), " { $snippet "vconvert" } " takes one vector of " { $snippet "from-type" } " and unpacks it into two vectors of " { $snippet "to-type" } "." }
}
{ $snippet "from-type" } " and " { $snippet "to-type" } " must adhere to the following restrictions; a " { $link bad-vconvert } " error will be thrown otherwise:"
{ $list
{ { $snippet "from-type" } " and " { $snippet "to-type" } " must have the same byte length. You cannot currently convert between 128- and 256-bit vector types." }
{ "For conversions between floating-point and integer vectors, " { $snippet "from-type" } " and " { $snippet "to-type" } " must have the same element length." }
{ "For packing conversions, " { $snippet "from-type" } " and " { $snippet "to-type" } " must be both floating-point or both integer types. Integer types can be packed from signed to unsigned or from unsigned to unsigned types. Unsigned to signed packing is invalid." }
{ "For unpacking conversions, " { $snippet "from-type" } " and " { $snippet "to-type" } " must be both floating-point or both integer types. Integer types can be unpacked from unsigned to signed or from unsigned to unsigned types. Signed to unsigned unpacking is invalid." }
}
}
{ $examples
"Conversion between integer and float vectors:"
{ $example """USING: alien.c-types math.vectors.conversion math.vectors.simd
prettyprint ;
SIMDS: int float longlong double ;
int-8{ 0 1 2 3 4 5 6 7 } int-8 float-8 vconvert .
double-2{ 1.25 3.75 } double-2 longlong-2 vconvert ."""
"""float-8{ 0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 }
longlong-2{ 1 3 }""" }
"Packing conversions:"
{ $example """USING: alien.c-types math.vectors.conversion math.vectors.simd
prettyprint ;
SIMDS: ushort int float double ;
int-4{ -8 70000 6000 50 } int-4{ 4 3 2 -1 } int-4 ushort-8 vconvert .
double-4{ 0.0 1.5 1.0e100 2.0 }
double-4{ -1.0e100 0.0 1.0 2.0 } double-4 float-8 vconvert ."""
"""ushort-8{ 0 65535 6000 50 4 3 2 0 }
float-8{ 0.0 1.5 1/0. 2.0 -1/0. 0.0 1.0 2.0 }""" }
"Unpacking conversions:"
{ $example """USING: alien.c-types kernel math.vectors.conversion
math.vectors.simd prettyprint ;
SIMDS: uchar short ;
uchar-16{ 8 70 60 50 4 30 200 1 9 10 110 102 133 143 115 0 }
uchar-16 short-8 vconvert [ . ] bi@"""
"""short-8{ 8 70 60 50 4 30 200 1 }
short-8{ 9 10 110 102 133 143 115 0 }""" }
} ;
ARTICLE: "math.vectors.conversion" "SIMD vector conversion"
"The " { $vocab-link "math.vectors.conversion" } " vocabulary provides facilities for converting SIMD vectors between floating-point and integer representations and between different-sized integer representations."
{ $subsections
vconvert
} ;
ABOUT: "math.vectors.conversion"

View File

@ -55,12 +55,15 @@ ARTICLE: "math-vectors-shuffle" "Vector shuffling, packing, and unpacking"
"These operations are primarily meant to be used with " { $vocab-link "math.vectors.simd" } " types. The software fallbacks for types not supported by hardware will not perform well." "These operations are primarily meant to be used with " { $vocab-link "math.vectors.simd" } " types. The software fallbacks for types not supported by hardware will not perform well."
} }
$nl $nl
{ $subsection vshuffle } { $subsections
{ $subsection vbroadcast } vshuffle
{ $subsection hlshift } vbroadcast
{ $subsection hrshift } hlshift
{ $subsection vmerge } hrshift
{ $subsection (vmerge) } ; vmerge
(vmerge)
}
"See the " { $vocab-link "math.vectors.conversion" } " vocabulary for packing, unpacking, and converting vectors." ;
ARTICLE: "math-vectors-logic" "Vector component- and bit-wise logic" ARTICLE: "math-vectors-logic" "Vector component- and bit-wise logic"
{ $notes { $notes
@ -416,8 +419,12 @@ HELP: vbroadcast
} ; } ;
HELP: vshuffle HELP: vshuffle
{ $values { "u" "a SIMD array" } { "perm" "an array of integers" } { "v" "a SIMD array" } } { $values { "u" "a SIMD array" } { "perm" "an array of integers, or a byte-array" } { "v" "a SIMD array" } }
{ $description "Permutes the elements of a SIMD array. Duplicate entries are allowed in the permutation." } { $description "Permutes the elements of a SIMD array. Duplicate entries are allowed in the permutation. The " { $snippet "perm" } " argument can have one of two forms:"
{ $list
{ "A literal array of integers of the same length as the vector. This will perform a static, elementwise shuffle." }
{ "A byte array or SIMD vector of the same byte length as the vector. This will perform a variable bytewise shuffle." }
} }
{ $examples { $examples
{ $example { $example
"USING: alien.c-types math.vectors math.vectors.simd" "prettyprint ;" "USING: alien.c-types math.vectors math.vectors.simd" "prettyprint ;"
@ -425,6 +432,29 @@ HELP: vshuffle
"int-4{ 69 42 911 13 } { 1 3 2 3 } vshuffle ." "int-4{ 69 42 911 13 } { 1 3 2 3 } vshuffle ."
"int-4{ 42 13 911 13 }" "int-4{ 42 13 911 13 }"
} }
{ $example
"USING: alien.c-types combinators math.vectors math.vectors.simd"
"namespaces prettyprint prettyprint.config ;"
"SIMDS: int uchar ;"
"IN: scratchpad"
""
": endian-swap ( size -- vector )"
" {"
" { 1 [ uchar-16{ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 } ] }"
" { 2 [ uchar-16{ 1 0 3 2 5 4 7 6 9 8 11 10 13 12 15 14 } ] }"
" { 4 [ uchar-16{ 3 2 1 0 7 6 5 4 11 10 9 8 15 14 13 12 } ] }"
" } case ;"
""
"int-4{ HEX: 11223344 HEX: 11223344 HEX: 11223344 HEX: 11223344 }"
"4 endian-swap vshuffle"
"16 number-base [ . ] with-variable"
"""int-4{
HEX: 44332211
HEX: 44332211
HEX: 44332211
HEX: 44332211
}"""
}
} ; } ;
HELP: norm-sq HELP: norm-sq

View File

@ -226,6 +226,11 @@ HELP: render-set
} } } }
{ $notes "User-created framebuffers require OpenGL 3.0 or one of the " { $snippet "GL_EXT_framebuffer_object" } " or " { $snippet "GL_ARB_framebuffer_object" } " extensions. Disabling rasterization requires OpenGL 3.0 or the " { $snippet "GL_EXT_transform_feedback" } " extension. Named output-attachment values are available in GLSL 1.30 or later, and GLSL 1.20 and earlier using the " { $snippet "GL_EXT_gpu_shader4" } " extension. Transform feedback requires OpenGL 3.0 or one of the " { $snippet "GL_EXT_transform_feedback" } " or " { $snippet "GL_ARB_transform_feedback" } " extensions." } ; { $notes "User-created framebuffers require OpenGL 3.0 or one of the " { $snippet "GL_EXT_framebuffer_object" } " or " { $snippet "GL_ARB_framebuffer_object" } " extensions. Disabling rasterization requires OpenGL 3.0 or the " { $snippet "GL_EXT_transform_feedback" } " extension. Named output-attachment values are available in GLSL 1.30 or later, and GLSL 1.20 and earlier using the " { $snippet "GL_EXT_gpu_shader4" } " extension. Transform feedback requires OpenGL 3.0 or one of the " { $snippet "GL_EXT_transform_feedback" } " or " { $snippet "GL_ARB_transform_feedback" } " extensions." } ;
HELP: bind-uniforms
{ $values { "program-instance" program-instance } { "uniforms" uniform-tuple } }
{ $description "Binds the uniform shader parameters for " { $snippet "program-instance" } " using values from the given uniform tuple." }
{ $notes "The " { $link render } " word uses this word. Calling this word directly is only necessary if uniform parameters need to be bound independently of a " { $snippet "render" } " operation." } ;
{ render render-set } related-words { render render-set } related-words
HELP: texture-uniform HELP: texture-uniform

View File

@ -168,12 +168,12 @@ M: multi-index-elements render-vertex-indexes
: (bind-texture-unit) ( texture texture-unit -- ) : (bind-texture-unit) ( texture texture-unit -- )
swap [ GL_TEXTURE0 + glActiveTexture ] [ bind-texture drop ] bi* ; inline swap [ GL_TEXTURE0 + glActiveTexture ] [ bind-texture drop ] bi* ; inline
GENERIC: bind-uniform-textures ( program-instance uniform-tuple -- ) GENERIC: (bind-uniform-textures) ( program-instance uniform-tuple -- )
GENERIC: bind-uniforms ( program-instance uniform-tuple -- ) GENERIC: (bind-uniforms) ( program-instance uniform-tuple -- )
M: uniform-tuple bind-uniform-textures M: uniform-tuple (bind-uniform-textures)
2drop ; 2drop ;
M: uniform-tuple bind-uniforms M: uniform-tuple (bind-uniforms)
2drop ; 2drop ;
: uniform-slot-type ( uniform -- type ) : uniform-slot-type ( uniform -- type )
@ -363,7 +363,7 @@ DEFER: [bind-uniform-tuple]
:: [bind-uniforms] ( superclass uniforms -- quot ) :: [bind-uniforms] ( superclass uniforms -- quot )
superclass "uniform-tuple-texture-units" word-prop 0 or :> first-texture-unit superclass "uniform-tuple-texture-units" word-prop 0 or :> first-texture-unit
superclass \ bind-uniforms method :> next-method superclass \ (bind-uniforms) method :> next-method
first-texture-unit uniforms "" [bind-uniform-tuple] nip :> bind-quot first-texture-unit uniforms "" [bind-uniform-tuple] nip :> bind-quot
{ 2dup next-method } bind-quot [ ] append-as ; { 2dup next-method } bind-quot [ ] append-as ;
@ -371,10 +371,10 @@ DEFER: [bind-uniform-tuple]
: define-uniform-tuple-methods ( class superclass uniforms -- ) : define-uniform-tuple-methods ( class superclass uniforms -- )
[ [
2drop 2drop
[ \ bind-uniform-textures create-method-in ] [ \ (bind-uniform-textures) create-method-in ]
[ [bind-uniform-textures] ] bi define [ [bind-uniform-textures] ] bi define
] [ ] [
[ \ bind-uniforms create-method-in ] 2dip [ \ (bind-uniforms) create-method-in ] 2dip
[bind-uniforms] define [bind-uniforms] define
] 3bi ; ] 3bi ;
@ -481,12 +481,15 @@ TUPLE: render-set
: 3<render-set> ( x y z quot-assoc -- render-set ) : 3<render-set> ( x y z quot-assoc -- render-set )
render-set swap 3make-tuple ; inline render-set swap 3make-tuple ; inline
: bind-uniforms ( program-instance uniforms -- )
[ (bind-uniform-textures) ] [ (bind-uniforms) ] 2bi ; inline
: render ( render-set -- ) : render ( render-set -- )
{ {
[ vertex-array>> program-instance>> handle>> glUseProgram ] [ vertex-array>> program-instance>> handle>> glUseProgram ]
[ [
[ vertex-array>> program-instance>> ] [ uniforms>> ] bi [ vertex-array>> program-instance>> ] [ uniforms>> ] bi
[ bind-uniform-textures ] [ bind-uniforms ] 2bi bind-uniforms
] ]
[ [
framebuffer>> framebuffer>>

View File

@ -3,12 +3,12 @@
namespace factor namespace factor
{ {
aging_collector::aging_collector(factor_vm *myvm_) : aging_collector::aging_collector(factor_vm *parent_) :
copying_collector<aging_space,aging_policy>( copying_collector<aging_space,aging_policy>(
myvm_, parent_,
&myvm_->gc_stats.aging_stats, &parent_->gc_stats.aging_stats,
myvm_->data->aging, parent_->data->aging,
aging_policy(myvm_)) {} aging_policy(parent_)) {}
void factor_vm::collect_aging() void factor_vm::collect_aging()
{ {