简体   繁体   English

我可以在已编译的D3D着色器中更改绑定点吗?

[英]Can I change binding points in a compiled D3D shader?

I have an HLSL shader that defines some resources, say a constant buffer: 我有一个HLSL着色器,它定义了一些资源,比如一个常量缓冲区:

cbuffer MyCB : register(b0);

If I compile my shader, I will then be able to query the register through the reflection API. 如果我编译着色器,我将能够通过反射API查询寄存器。 But is it possible to change the register (for instance, to b3 ) in a compiled shader blob in a similar manner you can assign bind points to resources in a compiled OpenGL program? 但是,是否可以以类似的方式更改已编译的着色器blob中的寄存器(例如, 更改b3 ),您可以将绑定点分配给已编译的OpenGL程序中的资源?

There is no API to change the shader bindings at runtime in a compiled shader. 在编译的着色器中,没有API可以在运行时更改着色器绑定。

If you jumped through many hoops, you might be able to achieve this with dynamic shader linking in Shader Model 5.0, although it would be lots of work and not really worth it, when there is a very easy alternative - simply create a new compiled shader with the bindings you want. 如果你跳过了许多箍,你可以用Shader Model 5.0中的动态着色器链接实现这一点,虽然它有很多工作而且不值得,当有一个非常简单的选择 - 只需创建一个新的编译着色器与你想要的绑定。

You can accomplish this in by specifying a BaseShaderRegister other than zero, or using different RegisterSpace values, in the D3D12_DESCRIPTOR_RANGE struct. 您可以在通过在D3D12_DESCRIPTOR_RANGE结构中指定除零之外的BaseShaderRegister或使用不同的RegisterSpace值来完成此操作。 If code changes are not feasible, you can isolate each set of registers implicitly by setting the root parameter's ShaderVisibility property. 如果代码更改不可行,则可以通过设置root参数的ShaderVisibility属性来隐式隔离每组寄存器。 This will isolate, for example, VS b0 from PS b0 . 这将隔离,例如, VS b0PS b0 For more details, you can check out the developer video on the topic. 有关更多详细信息,您可以查看有关该主题的开发人员视频

The only time you will run into trouble is if you've actually explicitly bound two resources to the same slot and register space (by explicitly specifying it using shader model 5.1 syntax). 您遇到麻烦的唯一一次是,您实际上是将两个资源显式绑定到同一个插槽并注册空间(通过使用着色器模型5.1语法显式指定它)。 In this case, you are expected to understand that in D3D12, registers are shared cross-stage, and it's up to you to make sure you have no collisions. 在这种情况下,您需要了解在D3D12中,寄存器是跨阶段共享的,并且由您决定是否没有冲突。

In D3D11, this problem does not occur as each stage has its own register space ( VS b0 is not the same as PS b0 ) and you can't share even if you wanted to. 在D3D11中,不会发生此问题,因为每个阶段都有自己的寄存器空间( VS b0PS b0 ),即使您想要也无法共享。 Still, if you for some reason have a component hard-coded to attach data to VS b0 but your vertex shader has already been compiled to expect it at b1 , there's not much you can do. 尽管如此,如果由于某种原因你有一个硬编码的组件将数据附加到VS b0但你的顶点着色器已经被编译为期望它在b1 ,你可以做的并不多。

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

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