更换 Direct3D 11 着色器时管理状态的好方法是什么?

发布于 2024-10-19 09:37:44 字数 309 浏览 2 评论 0原文

我目前有两个着色器,一个处理着色器(顶点和像素) - 用于计算照明和投影变换。然后将其渲染为纹理。然后我有第二个着色器,一个后处理着色器,它读取渲染的纹理并将其输出到屏幕(同样是顶点和像素着色器)。

将场景渲染为纹理后,我将立即上下文的顶点和像素着色器与后处理着色器交换,但我不确定应该如何管理状态(例如我的纹理参数和常量缓冲区)。交换着色器,然后每帧手动重置常量缓冲区和纹理两次似乎非常浪费,并且一开始就违背了常量缓冲区的要点,但据我所知,您无法在着色器对象上设置数据,它必须传递到上下文。

对于在换入和换出着色器时管理变量和纹理的相当简单且有效的方法,其他人有何建议?

I currently have two shaders, a processing shader (both vertex and pixel) - which calculates lighting and projection transformations. This is then rendered to a texture. I then have my second shader, a postprocessing shader, which reads the rendered texture and outputs it to the screen (again both vertex and pixel shaders).

Once I've rendered my scene to a texture I swap the Immediate Context's Vertex and Pixel shaders with my postprocessing ones, but I'm not sure how I should manage the state (e.g. my texture parameters and my constant buffers). Swapping shaders and then manually resetting the constant buffers and textures twice each frame seems incredibly wasteful, and kind of defeats the point of constant buffers in the first place, but as far as I can see you can't set the data on the shader object, it has to be passed to the context.

What do other people suggest for fairly simple and efficient ways of managing variables and textures when swapping in and out shaders?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

生寂 2024-10-26 09:37:44

由于您没有从 D3D11 专家那里得到答案,因此我提供我有限的 D3D9 经验,无论其价值如何。

...每帧两次似乎非常浪费...

“似乎”是一个可疑的词。您测量过性能影响吗?每帧两次听起来还不错。

对于纹理,我根据用途分配纹理寄存器。我使用寄存器< s4 用于特定于材质的纹理,>= s4 用于渲染目标纹理,这些纹理仅在游戏开始时分配一次。例如,我的主场景着色器具有以下内容:

sampler2D DiffuseMap : register(s0);
sampler2D DetailMap : register(s1);

sampler2D DepthMap : register(s4);
sampler2D ShadowMap : register(s5);
sampler2D LightMap : register(s6);
sampler2D PrevFrame : register(s7);

因此,我的粒子着色器具有缩减集,但 DepthMap 纹理仍位于同一插槽中...

sampler2D Tex : register(s0);
sampler2D DepthMap : register(s4);

我不知道其中有多少适用于 D3D11,但我希望这是有一定用处的。

Since you've had no answers from D3D11 experts, I offer my limited D3D9 experience, for what it's worth.

... twice each frame seems incredibly wasteful ...

"Seems" is a suspicious word there. Have you measured the performance hit? Twice per frame doesn't sound too bad.

For textures, I assign my texture registers according to purpose. I use registers < s4 for material-specific textures, and >= s4 for render target textures which are assigned only once at the beginning of the game. So for example my main scene shader has the following:

sampler2D DiffuseMap : register(s0);
sampler2D DetailMap : register(s1);

sampler2D DepthMap : register(s4);
sampler2D ShadowMap : register(s5);
sampler2D LightMap : register(s6);
sampler2D PrevFrame : register(s7);

So my particle shader has a reduced set, but the DepthMap texture is still in the same slot...

sampler2D Tex : register(s0);
sampler2D DepthMap : register(s4);

I don't know how much of this is applicable to D3D11, but I hope it's of some use.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文