2 Answers
2

I still haven't found an "official" way to do this via the API. In fact, there is no provision for extracting any of the contents of a SamplerState block - either the texture or any of the state settings.

There are some hacky, roundabout ways one could do this:

You could give each sampler state an annotation that names the corresponding texture variable, or vice versa. A variant on this approach is to set up a naming convention, e.g. the texture is named texFoo and sampler samplerFoo. Of course, nothing would prevent these from getting out of sync with the actual texture variable assignments.

Scan the HLSL file for SamplerState definitions and parse them yourself. You'd probably want to run it through the preprocessor first. The parser doesn't have to be too complicated if you make a few simplifying assumptions, e.g. that the word "SamplerState" never occurs anywhere but the definition of a sampler variable.

You could create a dummy texture, assign it to a texture variable with ID3DXBaseEffect::SetTexture, then run through all the texture units with IDirect3DDevice9::GetTexture and see which one ended up with your dummy texture. You could then correlate this with the sampler index obtained by ID3DXConstantTable::GetSamplerIndex from each sampler variable in the effect. You could also use IDirect3DDevice9::GetSamplerState to get the rest of the sampler state.

Similar to solution #3 in your answer, but perhaps a little cleaner in that no device state will be modified: you could create an ID3DXEffectStateManager that no-ops all of the operations, but tracks the index to which your dummy texture was assigned. (You could also use your custom state manager to snoop the sampler state settings.)