How to breakthrouth the limit of constants memory in shader
-
- Gnoblar
- Posts: 23
- Joined: Mon Sep 14, 2009 11:26 am
How to breakthrouth the limit of constants memory in shader
Hi there,
Ogre.log shows that the Number of floating-point constants for vertex programs is 256. I'm using GTX 970. The number is too low, not as I expected. Is there anyway to breakthrough the 256 limit if I want to pass more constant value to vertex shader ?
Thanks!
Ogre.log shows that the Number of floating-point constants for vertex programs is 256. I'm using GTX 970. The number is too low, not as I expected. Is there anyway to breakthrough the 256 limit if I want to pass more constant value to vertex shader ?
Thanks!
- dark_sylinc
- OGRE Team Member
- Posts: 5299
- Joined: Sat Jul 21, 2007 4:55 pm
- Location: Buenos Aires, Argentina
- x 1280
- Contact:
Re: How to breakthrouth the limit of constants memory in sha
What RenderSystrm? This is a D3D9 limitation and also a common number on many cards.
The best solution is to use constant buffers which were well implemented in 2.1. Const buffers have a minimum guaranteed of 16kb (ie. 1024 constants), the card you mentioned supports 64kb (i.e. 4096)
Any more than that and you'll have to pass the data via a texture buffer instead (which right now would mean writing your shader via Hlms) or store the data in a texture (yes, a literal texture) and use texelFetch/texture.Load
The best solution is to use constant buffers which were well implemented in 2.1. Const buffers have a minimum guaranteed of 16kb (ie. 1024 constants), the card you mentioned supports 64kb (i.e. 4096)
Any more than that and you'll have to pass the data via a texture buffer instead (which right now would mean writing your shader via Hlms) or store the data in a texture (yes, a literal texture) and use texelFetch/texture.Load
-
- Gnoblar
- Posts: 23
- Joined: Mon Sep 14, 2009 11:26 am
Re: How to breakthrouth the limit of constants memory in sha
Thank you very much for your advice.dark_sylinc wrote:What RenderSystrm? This is a D3D9 limitation and also a common number on many cards.
The best solution is to use constant buffers which were well implemented in 2.1. Const buffers have a minimum guaranteed of 16kb (ie. 1024 constants), the card you mentioned supports 64kb (i.e. 4096)
Any more than that and you'll have to pass the data via a texture buffer instead (which right now would mean writing your shader via Hlms) or store the data in a texture (yes, a literal texture) and use texelFetch/texture.Load
Yes I'am using D3D9 Render System and Ogre 1.9. Currently I can't transfer to 2.1. So I will try your second solution althouth it seems unfamiliar to me.
Thanks again !
- dark_sylinc
- OGRE Team Member
- Posts: 5299
- Joined: Sat Jul 21, 2007 4:55 pm
- Location: Buenos Aires, Argentina
- x 1280
- Contact:
Re: How to breakthrouth the limit of constants memory in sha
Yeah, for D3D9 the only possible solution is to use "VTF" (Vertex Texture Fetch).
Today in modern APIs any shader stage can access pretty much anything (buffers, textures), but back then having access to textures from the vertex shader was a huge deal, and the feature was named vertex texture fetch.
You'll need to set the binding_type to 'vertex' (make sure the textures are between texture units 0 and 3) and then sample the texture from the vertex shader.
Take note tex2D takes arguments in range [0; 1] and bilinear filtering is possible; so if you want to gather raw binary data, use point filtering and if the texture is 4096x1, you need to sample tex2dlod( vertexTexture, float2( (offset + 0.5) / 4096.0, 0.0 ), 0 ) where offset is a value between [0; 4096)
If the texture is 4096x2 then sample tex2dlod( vertexTexture, float2( (offsetX + 0.5) / 4096.0, (offsetY + 0.5) / 2 ), 0 ); and so on.
Today in modern APIs any shader stage can access pretty much anything (buffers, textures), but back then having access to textures from the vertex shader was a huge deal, and the feature was named vertex texture fetch.
You'll need to set the binding_type to 'vertex' (make sure the textures are between texture units 0 and 3) and then sample the texture from the vertex shader.
Take note tex2D takes arguments in range [0; 1] and bilinear filtering is possible; so if you want to gather raw binary data, use point filtering and if the texture is 4096x1, you need to sample tex2dlod( vertexTexture, float2( (offset + 0.5) / 4096.0, 0.0 ), 0 ) where offset is a value between [0; 4096)
If the texture is 4096x2 then sample tex2dlod( vertexTexture, float2( (offsetX + 0.5) / 4096.0, (offsetY + 0.5) / 2 ), 0 ); and so on.