Thursday, September 14, 2017

Dynamic map storage on a texture map in Metal 2(Apple)

   The idea is pretty straightforward here.  Namely, to implement this form of storage, you will probably want a texture that has at least 2 channels, but this can also work for 4 channels with 2 channels reserved for the key value map storage.  

It would be noted that in fact the 'dynamic' storage portion of this storage is actually reserved storage space containing texture.width*texture.height possible indices for storage.  Keying without any layer of lexical enumeration between indices would be an added implementation beyond the scope of what I'd like to cover in this article.  So it is assumed that the indices given by the total range on the set, will serve directly as the key value, and thus the mapped key will have such value.  Thus the key 1 is mapped to index 1 on the texture storage set.  

To map these hash values means then to have some storage value likely a boolean value 1 indicating the hash bucket is reserved,  or 0 that it isn't reserved.

The formulation for converting from a 2d array to 1d array is pretty simple.  

y = indexkey/ texture.width
x = indexkey% texture.width

Thus in metal if your texture point is set with a half4 vector

You can say reserve at such index by accessing (via sample or write) the position:
where 
samp = sampler
uint2 indexval = (indexkey/texture.width, indexkey%texture.width);
half4 color = currenttexture.sample(samp, indexval);
color.zw = half2(1.0, value);
desttexture.write(color,indexval);

Thus mapping to latter two channels on destination texture transposing first 2 channel values from the original texture.  

Lookups then are pretty straight forward if the key is known just plug into x,y formulation above and control check for boolean positive (storage allocation) and then its corresponding value pair.  Noted this is for half format numbers.

No comments:

Post a Comment

Oblivion

 Between the fascination of an upcoming pandemic ridden college football season, Taylor Swift, and Kim Kardashian, wildfires, crazier weathe...