views:

40

answers:

1

Ok so assuming I have, somewhere in my shader, a statement as follows (Note I am enabling legacy support to share shaders between DX9 and DX10):

Texture2D   DiffuseMap;

I can compile up the shader with no problems but I'm at a slight loss as to how I bind a ShaderResourceView to "DiffuseMap". When I "Reflect" the shader I rather assumed it would turn up amongst the variable in a constant buffer. It doesn't. In fact I can't seem to identify it anywhere. So how do I know what texture "stage" (to use the DX9 term) that I should bind the ShaderResourceView too?

Edit: I've discovered I can identify the sampler name by using "GetResourceBindingDesc". I'm not sure that helps me at all though :(

Edit2: Equally I hadn't noticed that its the same under DX9 as well ... ie I can only get the sampler.

Edit3: My Texture2D and Sampler look like this:

Texture2D DiffuseMap  : DiffuseTexture;
sampler   DiffuseSampler  = sampler_state
{
    Texture   = (DiffuseMap);
    MinFilter = Linear;
    MaxFilter = Linear;
};

Now in the effect frame work I could get the Texture2D by the semantic "DiffuseTexture". I could then set a ResourceView(D3D10)/Texture(D3D9) to the Texture2D. Alas there doesn't seem to be any way to handle "semantics" using bog standard shaders (It'd be great to know how D3D does it but studying the D3D11 effect framework has got me nowhere thus far. It seems to be reading it out of the binary, ie compiled, data and I can only see "DiffuseSampler" in there myself).

+1  A: 

Hmm let me rephrase that. On the C++ side you have a bunch of loaded textures and associated SRVs. Now you want to set a shader (that comes from DX9) and without looking at how the shader is written, bind SRVs (diffuse to diffuse slot, specular, normal maps—you name it). Right?

Then I think as you said that you best bet is using GetResourceBindingDesc:

HRESULT GetResourceBindingDesc(
  [in]  UINT ResourceIndex,
  [in]  D3D10_SHADER_INPUT_BIND_DESC *pDesc
);

I think you have to iterate each ResourceIndex (starting at 0, then 1, 2 etc), if HRESULT is S_OK then you have pDesc.BindPoint that will represent the position of associated SRV in ppShaderResourceViews array of a *SetShaderResources call. And pDesc.Name (like "DiffuseMap") gives you the association information.

Stringer Bell
GetResourceBindingDesc returns me the Sampler not the Texture2D, however :( Thanks for the confirmation on the BindPoint part however. I'd guessed that was the case but wasn't sure. What would be REALLY nice is if you could get at user-defined semantics (like in an effect file).
Goz
Well in DX9 Samplers and Textures are the same, isn't it? Only DX10/11 make a clean separation between Samplers and Textures (or Buffers).
Stringer Bell
They're not the same in DX9 AFAIK. You can have multiple samplers attached to the same texture if you so wish ... I can't see any reason you'd want to but you can do it (Again AFAIK).
Goz
Yes I'm aware of that. I wanted to say that from HLSL point of view there's no distinction. You use tex2d(mySampler, coord) and that's all. In SM4.0 and up, you have myTexture.Sample(mySampler, ...).
Stringer Bell
Ahh ... I see what you mean :)
Goz