Hi, I am trying to integrate a single texture to my custom hlms and trying to understand the code in HlmsPbs. I see that in HlmsPbs::calculateHashForPreCreate some texture are set to fixed texture units - the indices are defined by PBSM_xxx values and set in HlmsPbs::calculateHashForPreCreate through setTextureProperty, but there are some which are assigned dynamically - like ssrTexture or gBuf_depthTexture. I don't see how it can possible work with this dynamic assignment. In HlmsPbs::notifyPropertiesMergedPreGenerationStep() the texUnit member is initialized to some starting offset and then incremented according to some properties.
- let's have there renderable A with properties HlmsBaseProp::UsePrePass, HlmsBaseProp::UseSsr and HlmsBaseProp::SsRefractionsAvailable
- another renderable B with properties HlmsBaseProp::UsePrePass and HlmsBaseProp::SsRefractionsAvailable (so no HlmsBaseProp::UseSsr)
According to implementation the renderable A will assign certain value to HlmsBaseProp::SsRefractionsAvailable, but renderable B will assign different value to the same property (which is minus 1 compared to renderable A because a lack of ssrTexture won't increment the texUnit variable). However in HlmsPbs::fillBuffersFor the textures are bound only if HLMS type is changed - so if there are multiple renderables with different properties, this dynamic assignment is, I think, somehow broken. I would expect the code which assign indices dynamically once, in the binding code cache the binds and then by new renderable compare whether the indices are the same and if not, update the texture binding.
Also I would expect that the conditions are identical. The current implementation set the ssrTexture based on presence of properties HlmsBaseProp::UsePrePass and HlmsBaseProp::UseSsr, but in HlmsPbs::fillBuffersFor the bode binds the texture (and increment texUnit local variable) if input parameter casterPass is false and mSsrTexture is not nullptr. It is necessary to search through code to verify that those properties are actually set based on same conditions - why is it implemented like that? (which it seems it is, but it is no so simple to follow it)
I suppose that there is no bug and the code somehow works - maybe some properties are set before rendering in the render target and are valid through the whole rendering pipeline in that window (or pass) and hence the binding of the textures is constant for all upcoming renderables for that particular HLMS.
Am I missing something here?