• Advertisement
Sign in to follow this  

Use 16 bits values instead of 32 bits values

This topic is 1464 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Edited by phil_t

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

 

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement