Jump to content

  • Log In with Google      Sign In   
  • Create Account


Use 16 bits values instead of 32 bits values


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 texel3d   Members   -  Reputation: 133

Like
0Likes
Like

Posted 06 January 2014 - 09:37 AM

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.



Sponsor:

#2 phil_t   Crossbones+   -  Reputation: 3254

Like
0Likes
Like

Posted 06 January 2014 - 11:25 AM

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, 06 January 2014 - 11:26 AM.


#3 mhagain   Crossbones+   -  Reputation: 7802

Like
0Likes
Like

Posted 06 January 2014 - 01:36 PM

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.


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#4 texel3d   Members   -  Reputation: 133

Like
0Likes
Like

Posted 14 January 2014 - 03:49 AM

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



#5 ankhd   Members   -  Reputation: 1211

Like
0Likes
Like

Posted 14 January 2014 - 04:17 AM

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.



#6 Evil Steve   Members   -  Reputation: 1959

Like
1Likes
Like

Posted 14 January 2014 - 07:22 AM

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.


Steve Macpherson
Senior programmer, Firebrand Games


#7 mhagain   Crossbones+   -  Reputation: 7802

Like
1Likes
Like

Posted 14 January 2014 - 06:49 PM

 

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.


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS