简体   繁体   English

DirectX 11着色器资源管理

[英]DirectX 11 Shader Resource Management

I'm creating a shader management system instead of using the Effects 11 library. 我正在创建一个着色器管理系统,而不是使用Effects 11库。 I have a couple of questions about resource management for shaders. 关于着色器的资源管理,我有几个问题。

If I have a Constant Buffer set to a certain register in the shader code, does it need to be set to that register when I set it on the device? 如果在着色器代码中将某个常量缓冲区设置为某个寄存器,那么在设备上对其进行设置时是否需要将该常量设置为该寄存器? What if I have multiple shaders that use that register? 如果我有多个使用该寄存器的着色器怎么办?

Are constant buffers maintained in memory between draws, or are they cleared? 是在两次绘制之间在内存中保持不变的缓冲区,还是将其清除? Say for example I have a constant buffer that is not changed from the last draw, do I need to set it again? 举例来说,我有一个常量缓冲区,该缓冲区在上次绘制后没有更改,是否需要重新设置?

Is it slower to set constant buffers one at a time or all at once? 一次设置一个或一次全部设置恒定缓冲区是否较慢?

Thanks in advance. 提前致谢。

Yes, you need to set to that register, think of it as a constant buffer slot. 是的,您需要设置该寄存器,将其视为恒定的缓冲区插槽。

Yes, it will keep there until you switch it by another. 是的,它会一直保留在那里,直到您切换它为止。

"Is it slower to set constant buffers one at a time or all at once?" “一次设置一个或一次全部设置恒定缓冲区会更慢吗?”

What do you mean by "all at once"? “一次全部”是什么意思?

Anyway, check this nvidia presentation for great info on cbuffer management: https://developer.nvidia.com/sites/default/files/akamai/gamedev/files/gdc12/Efficient_Buffer_Management_McDonald.pdf 无论如何,请查看此nvidia演示以获取有关cbuffer管理的详细信息: https : //developer.nvidia.com/sites/default/files/akamai/gamedev/files/gdc12/Efficient_Buffer_Management_McDonald.pdf

Note that pixel shaders and vertex shaders (different shader types) use different registers EVEN if you are using the exactly same "variable" on the hlsl code. 请注意,即使您在hlsl代码上使用完全相同的“变量”,像素着色器和顶点着色器(不同的着色器类型)也会使用不同的寄存器。 Thats handled for you, the thing to note is that to update the cbuffer to the register, you use the pixel shader version of the d3d function(VSSetConstantBuffer vs PSSetConstantBuffer, etc.). 多数民众赞成为您处理,要注意的是,要使用寄存器d3d的像素着色器版本(VSSetConstantBuffer与PSSetConstantBuffer等)将cbuffer更新到寄存器。 Thats for all types of shaders of course. 当然,这适用于所有类型的着色器。

So for example, in the hlsl code, you can have 2 constant buffers using the same slot(register), BUT, remember to not use both on the same shader..Or, again, you can use the same constant buffer on both shaders, just remember that its not really the same. 因此,例如,在hlsl代码中,您可以有两个使用相同插槽(寄存器)的常量缓冲区,但请记住不要在同一个着色器上同时使用它们。或者再次,您可以在两个着色器上使用相同的常量缓冲区,只记得它不是真的一样。

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

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