waylonflinn / weblas

GPU Powered BLAS for Browsers :gem:
MIT License
702 stars 43 forks source link

Direct float texture reading #28

Closed gnonio closed 8 years ago

gnonio commented 8 years ago

Initial contribution. Hopefully dealing correctly with this github cooperative workflow. Learning as stepping through it, open to be advised on best practices or weblas conventions.

waylonflinn commented 8 years ago

It's probably my fault for not understanding, but can you go into more detail on what this enables? I'm curious about the benefits you're seeing (or hoping to see). The last thing I want to do is waste all of the work you've put into this.

gnonio commented 8 years ago

tl:dr The aim is to skip float encoding if possible and availble, saving those compute cycles.

This modifies your Tensor.transfer() function firstly, based on your webgl class "gl.hasFloat" support is available or not, if the float computation results must indeed be encoded into sets of four gl.UNSIGNED_BYTE in the output, otherwise an appropriate output texture is created instead (gl.FLOAT) and float results are output directly when read via native gl.readpixels(), or not so directly if the data shape requires padding given the texture constraints (columns as multiples of four), in which case, an alternate shader to keep individual values contiguous along the readPixels() buffer is used instead. Aside of the new method bindUniform(), this PR is all that is required to provide this functionality.

Bypassing float encode is a natural option for the unpacked format, encoding comes only as a necessity of the level of webgl support, not only or maybe as a convenience given the chosen data format ie. packed.

I gather that weblas aims to be used with smaller factor browsers, and the relevant extension(s) OES_texture_float and WEBGL_color_buffer_float (more info on chrome) are already enabled in some browsers. Looking forward webgl 2.0 will also account for this.

My personal aim is to keep as much of any arbitrary computation an algorithm requires at the GPU level, reducing transfers, if internaly the GPU deals with floats natively, encoding comes only as a requirement for CPU reads which I'm avoiding from the begining, hence my intent on a format which is free from encoding imposed/encouraged constraints.

Feel free if you need more clarifications.

waylonflinn commented 8 years ago

Are you available for Google Hangout or Skype some time? I want to understand this and feel like I need higher bandwidth to do so. Email me: github username AT gmail

waylonflinn commented 8 years ago

Good conversation. Going to go ahead close this.