2
votes

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
So you have a DX9 .fx file (or just .vs/.ps ?), and want to compile it and run it in a DX10 context using reflection?Stringer
Hmm, I see your problem now. But if you have "DiffuseSampler", it's enough to know that you need to bind to a given slot an SRV of a diffuse texture, no? Not sure if you need to bind also a DX10 sampler state using *SetSamplers to the same slot.Stringer
Well the sampler state is defined in the shader so I shouldn't need to bind it. But again knowing the sampler does not, necessarily, tell me what the attached texture/resview is ...Goz
You're perfectly right. Unless you know DiffuseSampler leads to DiffuseMap.. But maybe it's not the case.Stringer
I haven't had a chance to check but according to the guys on the DirectXDev group it DOES give me access to the Texture and Sampler. I still haven't had a chance to check this out. The other info I got suggests I'm going to need to manually parse the DX9 shader to get this info... But at least that means I can have my semantics back :DGoz

1 Answers

1
votes

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.