luv

Workshop wiki

slug-serialization.lisp

hal/shader/slug-serialization.lisp

system luv · 21 definitions · on GitHub

Dense single-glyph texture data matching the open Slug shader contract.

in-package#:luv.slug
ieee-floats:make-float-convertersencode-slug-halfdecode-slug-half510t
defconstant+slug-texture-width+4096
defstructslug-serialized-outlinepacked-outline
curve-width+slug-texture-width+:type
eql4096
band-width+slug-texture-width+:type
eql4096
curve-half-wordscurve-texel-countcurve-upload-databand-uint16-wordsband-texel-countband-upload-datahorizontal-band-countvertical-band-count
defunslug-half-bits
value
encode-slug-half
coercevalue'single-float
defunslug-half-value
value
let
decoded
decode-slug-half
unless
realpdecoded
error'slug-outline-error:reason:non-finite-curve-coordinate:detailsvalue
decoded
defunquantize-slug-point
point
make-slug-point:x
slug-half-value
slug-point-xpoint
:y
slug-half-value
slug-point-ypoint
defunquantize-slug-outline
outline
make-slug-outline:contours
loopforcontourin
slug-outline-contoursoutline
collect
loopforcurveincontourcollect
make-slug-quadratic:start
quantize-slug-point
slug-quadratic-startcurve
:control
quantize-slug-point
slug-quadratic-controlcurve
:end
quantize-slug-point
slug-quadratic-endcurve
defunmake-slug-word-vector
make-array0:element-type'
unsigned-byte16
:adjustablet:fill-pointer0
defunpush-slug-half-point
pointwords
vector-push-extend
slug-half-bits
slug-point-xpoint
words
vector-push-extend
slug-half-bits
slug-point-ypoint
words
defunpush-slug-curve-texel
curvewords
push-slug-half-point
slug-quadratic-startcurve
words
push-slug-half-point
slug-quadratic-controlcurve
words
defunpush-slug-endpoint-texel
pointwords
vector-push-extend0words
vector-push-extend0words
defunslug-texel-location
offsetwidth
values
modoffsetwidth
defunensure-slug-uint16
valuerole
unless
typepvalue'
unsigned-byte16
error'slug-outline-error:reason:texture-address-overflow:details
listrolevalue
value
defunpush-slug-band-word-pair
leftrightwords
vector-push-extend
ensure-slug-uint16left:band-left
words
vector-push-extend
ensure-slug-uint16right:band-right
words
defunappend-slug-band-curve-locations
bandcurve-offsetscurve-widthband-words
dolist
curve-index
slug-band-curve-indicesband
multiple-value-bind
xy
slug-texel-location
arefcurve-offsetscurve-index
curve-width
defparameter*slug-share-band-lists*t

Whether a band whose sorted curve list is a contiguous run of a list already written points into that list instead of writing its own. The reference recommends it: adjacent bands often hold the same curves, and the sharing shrinks the band texture and keeps the texel cache warm.

defunslug-shared-band-offset
indiceswritten

The texel offset at which indices already stands as a contiguous run of one of the written (indices . OFFSET) lists, or NIL.

loopfor
list.offset
inwrittenforposition=
searchindiceslist
whenpositionreturn
+offsetposition
defunpack-slug-uint16-words
wordsstartcount
loopforindexbelowcountforword-indexfromstartsum
ash
if
<word-index
lengthwords
arefwordsword-index
0
*index16
defunmake-slug-upload-data
wordswords-per-texelwidthelement-type
let*
texel-count
ceiling
lengthwords
words-per-texel
height
max1
ceilingtexel-countwidth
data
make-array:element-typeelement-type:initial-element0
dotimes
texeltexel-countdata
setf
row-major-arefdatatexel
pack-slug-uint16-wordswords
*texelwords-per-texel
words-per-texel
defunslug-serialized-outline-curve-texture-size
serialized
list
slug-serialized-outline-curve-widthserialized
array-dimension
slug-serialized-outline-curve-upload-dataserialized
0
defunslug-serialized-outline-band-texture-size
serialized
list
slug-serialized-outline-band-widthserialized
array-dimension
slug-serialized-outline-band-upload-dataserialized
0
defunserialize-slug-outline
outline&keyhorizontal-band-countvertical-band-count

Quantize outline to RGBA16F, repack bands, and emit Slug's RG16U index data.

let*
quantized
packed
pack-slug-outlinequantized:horizontal-band-counthorizontal-band-count:vertical-band-countvertical-band-count
curves
slug-packed-outline-curvespacked
curve-offsets
make-array
lengthcurves
curve-index0
curve-texel0
dolist
contour
slug-outline-contoursquantized
dolist
curvecontour
setf
arefcurve-offsetscurve-index
curve-texel
incfcurve-index
incfcurve-texel
push-slug-curve-texelcurvecurve-words
push-slug-endpoint-texel
slug-quadratic-end
car
lastcontour
curve-words
incfcurve-texel
multiple-value-bind
curve-xcurve-y
slug-texel-location
max0
1-curve-texel
curve-width
declare
ignorecurve-x
ensure-slug-uint16curve-y:curve-row
let*
horizontal
slug-packed-outline-horizontal-bandspacked
vertical
slug-packed-outline-vertical-bandspacked
bands
appendhorizontalvertical
header-count
lengthbands

Reserve every header so its offset can point past the complete header block.

looprepeatheader-countdo
let
writtennil
loopforbandinbandsforheaderfrom0forindices=
slug-band-curve-indicesband
forshared=foroffset=
orshared
/
lengthband-words
2
do
setf
arefband-words
*header2
ensure-slug-uint16
lengthindices
:curve-count
arefband-words
1+
*header2
ensure-slug-uint16offset:curve-list-offset
unlessshared
whenindices
push
consindicesoffset
written
append-slug-band-curve-locationsbandcurve-offsetscurve-widthband-words
multiple-value-bind
band-xband-y
slug-texel-location
max0
1-
/
lengthband-words
2
band-width
declare
ignoreband-x
ensure-slug-uint16band-y:band-row
make-slug-serialized-outline:packed-outlinepacked:curve-widthcurve-width:band-widthband-width:curve-half-wordscurve-words:curve-texel-countcurve-texel:curve-upload-data
make-slug-upload-datacurve-words4curve-width'
unsigned-byte64
:band-uint16-wordsband-words:band-texel-count
/
lengthband-words
2
:band-upload-data
make-slug-upload-databand-words2band-width'
unsigned-byte32
:horizontal-band-count
lengthhorizontal
:vertical-band-count
lengthvertical