# WebGL GPGPU experiment - reading a floating point texture

## Initial test - writing and reading of random data.

Its purpose is to check if simple transfer of random data to the GPU memory and reading it back to the main memory introduce some numeric errors. These errors can occur, as WebGL does not provide any convenient function for reading floating point textures. readPixels function is limited to the RGBA format and the UNSIGNED_BYTE type (see: WebGL specification). A workaround for this problem is to create a special GLSL shader which packs each Float value into four Unsigned Byte components (RGBA). The biggest drawback of this solution is a performance overhead and possible numeric errors. If you are interested how it works, look at the encodeShader1 and encodeShader2 in the script.js.

This test consists of writing random data to the texture, conversion from Float to Unsigned Byte, reading of data using readPixels and a final comparison of received values with the initial data.

Results:

- Method 1: based on the Carlos Scheidegger's idea. See here for more information.
  - average difference between CPU and GPU value after conversion and transfer: %
  - reading a floating point texture time: ms
- Method 2: based on the Ultraist's idea. See here for more information.
  - average difference between CPU and GPU value after conversion and transfer: %
  - reading a floating point texture time: ms

## Continuous test - simple simulation.

This test is mainly focused on the measurement of different operations which are connected with GPGPU calculations.

One step consists of:

- rendering of the data: ms
- simple CPU calculations: ms
- simple GPU calculations: ms
- reading a floating point texture:
  - Method 1: ms
  - Method 2: ms

Step:

Each 5 steps, CPU and GPU data is being compared.

Average difference between CPU and GPU value: %

## Parameters

- Grid resolution: