简体   繁体   English

D3D10 HLSL:如何通过反射将纹理绑定到全局Texture2D?

[英]D3D10 HLSL: How do I bind a texture to a global Texture2D via reflection?

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): 好吧,假设我在着色器中的某处有一条如下语句(请注意,我启用了旧版支持以在DX9和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". 我可以毫无问题地编译着色器,但是我对如何将ShaderResourceView绑定到“ 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? 那么,我怎么知道我也应该绑定ShaderResourceView的纹理“阶段”(使用DX9术语)?

Edit: I've discovered I can identify the sampler name by using "GetResourceBindingDesc". 编辑:我发现我可以使用“ 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. Edit2:同样,我也没有注意到在DX9下它也是如此……也就是说,我只能得到采样器。

Edit3: My Texture2D and Sampler look like this: Edit3:我的Texture2D和Sampler如下所示:

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". 现在在效果框架中,我可以通过语义“ DiffuseTexture”获得Texture2D。 I could then set a ResourceView(D3D10)/Texture(D3D9) to the Texture2D. 然后,我可以将ResourceView(D3D10)/ Texture(D3D9)设置为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). las,似乎没有任何方法可以使用沼泽标准着色器来处理“语义”(很高兴知道D3D是如何做到的,但是到目前为止,研究D3D11效果框架仍然无济于事。似乎正在阅读它从二进制(即已编译)数据中删除,我自己只能在其中看到“ DiffuseSampler”。

Hmm let me rephrase that. 嗯,我再说一遍。 On the C++ side you have a bunch of loaded textures and associated SRVs. 在C ++方面,有一堆已加载的纹理和关联的SRV。 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). 现在,您要设置一个着色器(来自DX9),而无需查看着色器的编写方式,而是绑定SRV(将其漫反射到漫射槽,镜面反射,法线贴图-您命名)。 Right? 对?

Then I think as you said that you best bet is using GetResourceBindingDesc : 然后,我想正如您所说,最好的选择是使用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. 我认为您必须迭代每个ResourceIndex (从0开始,然后是1、2等),如果HRESULTS_OK则您将具有pDesc.BindPoint ,它将表示关联的SRV在*SetShaderResources调用的ppShaderResourceViews数组中的*SetShaderResources And pDesc.Name (like "DiffuseMap") gives you the association information. pDesc.Name (如“ DiffuseMap”)为您提供关联信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM