possible to set halfs to ComputeBuffer

Hello,

For performance reasons I want my StructuredBuffer to contain halfs, not floats. However, I’m streaming data from the CPU to the buffer. Streaming a float array is easy, but how would you stream an array of halfs? C# does not have native halfs. Just streaming floats and setting the buffer to use halfs works on ATI 5770, but I don’t think it works on nvidia cards. Thanks for the help!

Arthur

So… Hmm, I geuss Aras and other shader gurus are in the shaderlab Section.

It’s totally possible, just shadow the half data using short or ushort on the C# side and make your own converter function float → ushort which converts to half precision bit layout. It’s easy: Half-precision floating-point format - Wikipedia I made a little struct which wraps the thing and looks a lot like a native type, I’m sure you’d love the code for that. But I’m leaving it as an exercise for the reader, because it’s pretty trivial.

2 Likes

In fact someone wrote one already: Half-precision floating point in C# / Code / [r2]

1 Like