简体   繁体   中英

Can I change binding points in a compiled D3D shader?

I have an HLSL shader that defines some resources, say a constant buffer:

cbuffer MyCB : register(b0);

If I compile my shader, I will then be able to query the register through the reflection 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?

There is no API to change the shader bindings at runtime in a compiled shader.

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.

You can accomplish this in by specifying a BaseShaderRegister other than zero, or using different RegisterSpace values, in the D3D12_DESCRIPTOR_RANGE struct. If code changes are not feasible, you can isolate each set of registers implicitly by setting the root parameter's ShaderVisibility property. This will isolate, for example, VS b0 from PS 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). 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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