2

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).

Goz
  • 61,365
  • 24
  • 124
  • 204
  • 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? – elmattic Jul 07 '10 at 22:04
  • 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. – elmattic Jul 08 '10 at 11:27
  • 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 Jul 08 '10 at 11:41
  • You're perfectly right. Unless you know DiffuseSampler leads to DiffuseMap.. But maybe it's not the case. – elmattic Jul 08 '10 at 12:25
  • 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 :D – Goz Jul 09 '10 at 08:32
  • Sure, you always can parse the shader file, unless you have just blobs... – elmattic Jul 12 '10 at 10:17

1 Answers1

1

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.

elmattic
  • 12,046
  • 5
  • 43
  • 79
  • 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 Jul 08 '10 at 11:05
  • 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). – elmattic Jul 08 '10 at 11:18
  • 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 Jul 08 '10 at 11:40
  • 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, ...). – elmattic Jul 08 '10 at 12:18
  • Ahh ... I see what you mean :) – Goz Jul 08 '10 at 13:43