Setting a Sampler state in an Effect using C++ Code

Long time listener, first time caller . . .

Is there a good clean way to set the sampler used in an effect? I've got an FX file with a sampler and a texture.

Texture2D tex;

SamplerState sam;

...

tex.Sample( sam, inputTex.xy )

What I'm trying to do is set the sampler from the app, so that it can be changed at runtime. The reason is that with our existing codebase, sampler states are set in the code, and concievably, two different textures could have different samplers. In my C code, I've got an ID3D10SamplerState* with the state that I want to set. Now, does anyone know how to set the Sampler?

The low lever way to set the sampler would be to call Apply() from my pass followed by ID3D10Device::PSSetSamplers() before the draw call, but I have no way of knowing which sampler slot to use. Does anyone know how to either find the sampler slot, or set the sampler using the effect interface.

Thanks!

[1027 byte] By [big4ared] at [2008-2-15]
# 1

Unfortunately Sampler states can like the other state objects not override within the effect framework. The way to get the right slot is a little bit complicated

1. For every pass that would be involved you have to use GetVertexShaderDesc, GetGeometryShaderDesc and GetPixelShaderDesc. They will fill a D3D10_PASS_SHADER_DESC for you.

2. You need to call GetShaderDesc which fills a D3D10_EFFECT_SHADER_DESC.

3. pByteCode and BytecodeLength can now use to create a reflection object. (D3D10ReflectShader)

4. Now call GetDesc to fill the D3D10_SHADER_DESC structure.

5. The BoundResources element will tell you how many resources are bound to this shader.

6. Call GetResourceBindingDesc for each resource.

7. Compare the Name element with the name of the sampler you are looking for. If it is equal BindPoint contains your slot.

As this is an expensive operation you should do this only once after effect creation. Additional it will not work after you have called Optimize for the effect.

RalfKornmann at 2007-9-3 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Direct3D 10...