It would seem you're using your own Hlms implementation?
Because if so, then you can retrieve the samplerblock once at the Hlms level, instead of datablock level.
If that's so, that greatly simplifies the solution, because you can send per-renderable data such as the texture indices in the buffers that are meant to be per renderable (mCurrentMappedConstBuffer or mCurrentMappedTexBuffer); and get the samplerblock once at the Hlms level, instead of datablock level.
The material model does not fit well because this model assumes it's going to be reused/shared with multiple Items.
Your idea sounds fine, I cannot judge it well because you know better what your goals are and the problems to be solved. Just one thing:
the 16x16 texture essentially tells me which 2D array and its index to sample
If you mean:
Code: Select all
float index = texture.Load( uv );
float4 diffuseCol = diffuseMap.Sample( bilinearSampler, uv, index );
Then all is well.
But if you mean something like this:
Code: Select all
float index = texture.Load( uv );
float4 diffuseCol = diffuseMap[index].Sample( bilinearSampler, uv );
You're going to hit a wall because it's not valid Shader Model 5.0 syntax (HW does not support it). You can do that with bindless textures (Vulkan/DX12) but not with DX11/GL.
Btw
From what I can tell, HlmsManager will now simply require slightly more than 16k more memory (if my math is right) to store the additional data based on the two 4096 entry vectors and the several other vectors which are negligible.
I don't think I follow. mRefCount is used when the same sampler is retrieved multiple times.
The entries you're talking about (like mSamplerblocks[OGRE_HLMS_NUM_SAMPLERBLOCKS] and co.) hold
unique samplerblocks.
One thing is to use the same samplerblocks more than 65k times, another is to use more than 65k samplerblocks all of them with different settings (eg. one uses bilinear filtering, the other point filtering, the other trilinear, the other aniso, another has rare min/mag filter settings, etc) these are two different problems.
And mRefCount only means the same samplerblocks is being used too many times. Did you try just changing mRefCount's type and see what happens? (it should work, I think)
The reason I'm asking this is because I want to rule out any other bug (like leaks, corruption, etc)