Quantcast
Channel: Questions in topic: "compute shader"
Viewing all articles
Browse latest Browse all 287

How can I convert bytearrays to floats in computeshader

$
0
0
Hi everyone, I'm struggling up with a speed problem of data parsing. I have a huge byte array, and my code copies a subarray of this with a given starting point and length. After the copying process, I change this into a float. The exact code is below: for(long i = 0; i < numberOfPoints; i++) { Array.Copy(_message.data, i * _message.point_step, byteSlice, 0, _message.point_step); points[i] = MakePoint(byteSlice, _message.fields); } private Point MakePoint(byte[] bytes, RosMessageTypes.Sensor.PointFieldMsg[] fields) { var point = new Point(); for(int i = 0; i < fields.Length; i++) { byte[] slice = null; switch (fields[i].name) { case "x": slice = new byte[fields[i].count * 4]; Array.Copy(bytes, fields[i].offset, slice, 0, fields[i].count * 4); point.position.x = GetValue(slice); break; case "y": slice = new byte[fields[i].count * 4]; Array.Copy(bytes, fields[i].offset, slice, 0, fields[i].count * 4); point.position.z = GetValue(slice); break; case "z": slice = new byte[fields[i].count * 4]; Array.Copy(bytes, fields[i].offset, slice, 0, fields[i].count * 4); point.position.y = GetValue(slice); break; case "intensity": slice = new byte[fields[i].count * 8]; Array.Copy(bytes, fields[i].offset, slice, 0, fields[i].count * 8); point.intensity = (sbyte)Math.Round(GetValue(slice)); break; case "timestamp": break; case "ring": break; } } return point; } float GetValue(byte[] bytes) { if (!BitConverter.IsLittleEndian) { Array.Reverse(bytes); } float result = BitConverter.ToSingle(bytes, 0); return result; } This works quite fast, but the problem is that the byte array can be really huge. The "numberOfPoints" variable can be more than 20,000,000, which cost about more than 1sec for the total process. So I'm trying to convert this process as a computeShader kernal function. But now the problem goes on with the convertion of byteArrays. I'm a newbie in hlsl and computeShaders and being stuck with this. In addition, I heard that hlsl does not have the "byte" computation implements. So, can anybody give me a solution??

Viewing all articles
Browse latest Browse all 287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>