Use 16 bits values instead of 32 bits values

Started by
5 comments, last by 21st Century Moose 10 years, 3 months ago

Hi,

(Using DirectX 9)

Is it possible and usefull to use 16 bits values instead of 32 bits values for vertexbuffer and/or in hlsl shaders in order to have better performance and/or memory ressources ?

I can use D3DFMT_INDEX16 for my index buffer, can i have 16 bits values in by vertexbuffers ?

What about HLSL shaders ?

Thanks.

Advertisement

Yes, you can use 16 bit values in your vertex buffer. And yes, this can be useful as it shrinks the size of your vertex buffer. This of course results in less memory usage, reduces bandwidth needed when sending vertices to the gpu, and also lets more vertices fit into the pre-transform vertex cache. This can result in the vertex shader being run fewer times. In some cases I've seen fairly significant performance improvements from "compressing" vertices like this.

As for using 16 bits floats for calculations in your shaders, I don't know enough to say whether this is still useful on today's GPUs.

Yes, it's possible, using D3DDECLTYPE_FLOAT16_2 or D3DDECLTYPE_FLOAT16_4 in your vertex declaration and the D3DXFLOAT16 struct (optionally with D3DXFloat32To16Array as a helper to set your data). As well as reduced memory usage (which is not always the key determinant of performance) this can help with aligning odd-sized vertex structs.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

Thanks.

There is not a lot of documentation about D3DDECLTYPE_FLOAT16_2 and D3DDECLTYPE_FLOAT16_4.

Can i use 16 bits in CreateVertexBuffer() ? using which FVF flag ?

I can also read Microsoft documentation:

"The most important things with vertex performance is to use a 32-byte vertex, and to maintain good cache ordering."
http://msdn.microsoft.com/en-us/library/windows/desktop/bb173428%28v=vs.85%29.aspx

Hi.

One thing to remember is the range the 16 byte is less then 32 bytes.

got me many years ago on my terrain 16 bytes runs out of range quickly.

Thanks.

There is not a lot of documentation about D3DDECLTYPE_FLOAT16_2 and D3DDECLTYPE_FLOAT16_4.

Can i use 16 bits in CreateVertexBuffer() ? using which FVF flag ?

I can also read Microsoft documentation:

"The most important things with vertex performance is to use a 32-byte vertex, and to maintain good cache ordering."
http://msdn.microsoft.com/en-us/library/windows/desktop/bb173428%28v=vs.85%29.aspx

It's not possible to use 16-bit floats with FVF codes; you need to use shaders. Also be aware that converting from 32-bit float to 16-bit float isn't trivial since there's no built-in half type in C++. Also what ankhd said - generally you only want to use 16-bit floats for texture coordinates and maybe normals - elements with a limited range.

Thanks.

There is not a lot of documentation about D3DDECLTYPE_FLOAT16_2 and D3DDECLTYPE_FLOAT16_4.

Can i use 16 bits in CreateVertexBuffer() ? using which FVF flag ?

I can also read Microsoft documentation:

"The most important things with vertex performance is to use a 32-byte vertex, and to maintain good cache ordering."
http://msdn.microsoft.com/en-us/library/windows/desktop/bb173428%28v=vs.85%29.aspx

It's not possible to use 16-bit floats with FVF codes; you need to use shaders. Also be aware that converting from 32-bit float to 16-bit float isn't trivial since there's no built-in half type in C++. Also what ankhd said - generally you only want to use 16-bit floats for texture coordinates and maybe normals - elements with a limited range.

The D3DXFLOAT16 type will handle the conversion for you.

Also, if the OP is talking about FVF codes in CreateVertexBuffer, but is using vertex declarations for actual drawing, then he's probably not aware that the FVF code in CreateVertexBuffer is only necessary if using the buffer as a destination buffer for the old IDirect3DDevice9::ProcessVertices call (broadly equivalent to compiled vertex arrays in OpenGL). Otherwise FVF for CreateVertexBuffer can and should be set to 0. See further: http://msdn.microsoft.com/en-us/library/windows/desktop/bb173428%28v=vs.85%29.aspx.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

This topic is closed to new replies.

Advertisement