本文介绍了directx中许多复杂对象的典型渲染策略?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习directx。它为如何做事提供了很大的自由度,但大概不同的状态可能会有不同的表现,并且对于性能良好的使用模式可能会提供一点指导。

当使用directx通常需要在每个渲染中多次交换一堆新数据?



使用它最显而易见的方法可能是效率低下。

Stragety 1


    $ b


    1. 为模型0(包含纹理)加载所有内容并渲染它(IASetVertexBuffers,VSSetShader,PSSetShader,PSSetShaderResources,PSSetConstantBuffers,VSSetConstantBuffers,Draw)

    2. 为模型1(包含纹理)加载所有内容并渲染它(IASetVertexBuffers,VSSetShader,PSSetShader,PSSetShaderResources,PSSetConstantBuffers,VSSetConstantBuffers,Draw)。

    3. 等等。 ..我猜你可以使这个更高效的部分,如果最大的东西要加载给予专用插槽,例如如果模型0的纹理非常复杂,那么不要在每一步重新加载它,只需将它加载到插槽1并留在那里。当然,因为我不确定DX11中每种类型的寄存器有多少,这是很复杂的(任何人都可以指出这一点?)

      Stragety 2



      选择一些用于加载的贴图槽和其他用于永久存储最复杂纹理的贴图。

      只有一次



      将最复杂的模型,着色器和纹理加载到专用于永久存储的槽中

      在每一次渲染中


      1. 加载所有不存在的模型0使用您预留的用于加载和渲染的插槽(IASetVertexBuffers,VSSetShader,PSSetShader,PSSetShaderResources,PSSetConstantBuffers,VSSetConstantBuffers,Draw)

      2. 加载所有不存在的东西模型1使用您预留用于加载和渲染的插槽(IASetVertexBuffers,VSSetShader,PSSetShader,PSSetShaderResources,PSSetConstantBuffers,VSSetConsta ntbuffers,Draw)
      3. etc ...




      4. 战略3
        我不知道,但上述可能都是错误的,因为我真的是新手。


        在directx(特别是DX11)上进行高效渲染的标准策略使其尽可能高效

        解决方案

        DirectX为您管理资源,并尽量将它们保留在视频内存中,只要它可以优化性能,但只能这样做视频内存限制在卡中。即使资源仍在视频内存中,每个状态变化也会有开销。



        优化此策略的一般策略是尽量减少渲染过程中状态变化的次数通过。通常这意味着绘制批处理中使用相同纹理的所有多边形以及批处理中使用相同顶点缓冲区的所有对象。所以一般情况下你会尝试绘制尽可能多的图元,然后再改变状态来绘制更多的图元。这通常会使渲染代码变得更加复杂和困难。保持,所以你会想要做一些分析,以确定你愿意做多少优化。



        一般来说,通过更广泛的算法更改,您可以获得更好的性能提升这个问题的范围。一些示例将减少远处对象和遮挡查询的多边形数量。一个流行的真正的短语是最快的多边形是你不会画的。这里有几个快速链接:








        I am learning directx. It provides a huge amount of freedom in how to do things, but presumably different stategies perform differently and it provides little guidance as to what well performing usage patterns might be.

        When using directx is it typical to have to swap in a bunch of new data multiple times on each render?

        The most obvious, and probably really inefficient, way to use it would be like this.

        Stragety 1

        On every single render

        1. Load everything for model 0 (textures included) and render it (IASetVertexBuffers, VSSetShader, PSSetShader, PSSetShaderResources, PSSetConstantBuffers, VSSetConstantBuffers, Draw)

        2. Load everything for model 1 (textures included) and render it (IASetVertexBuffers, VSSetShader, PSSetShader, PSSetShaderResources, PSSetConstantBuffers, VSSetConstantBuffers, Draw)

        3. etc...

        I am guessing you can make this more efficient partly if the biggest things to load are given dedicated slots, e.g. if the texture for model 0 is really complicated, don't reload it on each step, just load it into slot 1 and leave it there. Of course since I'm not sure how many registers there are certain to be of each type in DX11 this is complicated (can anyone point to docuemntation on that?)

        Stragety 2

        Choose some texture slots for loading and others for perpetual storage of your most complex textures.

        Once only

        Load most complicated models, shaders and textures into slots dedicated for perpetual storage

        On every single render

        1. Load everything not already present for model 0 using slots you set aside for loading and render it (IASetVertexBuffers, VSSetShader, PSSetShader, PSSetShaderResources, PSSetConstantBuffers, VSSetConstantBuffers, Draw)

        2. Load everything not already present for model 1 using slots you set aside for loading and render it (IASetVertexBuffers, VSSetShader, PSSetShader, PSSetShaderResources, PSSetConstantBuffers, VSSetConstantBuffers, Draw)

        3. etc...

        Strategy 3I have no idea, but the above are probably all wrong because I am really new at this.

        What are the standard strategies for efficient rendering on directx (specifically DX11) to make it as efficient as possible?

        解决方案

        DirectX manages the resources for you and tries to keep them in video memory as long as it can to optimize performance, but can only do so up to the limit of video memory in the card. There is also overhead in every state change even if the resource is still in video memory.

        A general strategy for optimizing this is to minimize the number of state changes during the rendering pass. Commonly this means drawing all polygons that use the same texture in a batch, and all objects using the same vertex buffers in a batch. So generally you would try to draw as many primitives as you can before changing the state to draw more primitives

        This often will make the rendering code a little more complicated and harder to maintain, so you will want to do some profiling to determine how much optimization you are willing to do.

        Generally you will get better performance increases through more general algorithm changes beyond the scope of this question. Some examples would be reducing polygon counts for distant objects and occlusion queries. A popular true phrase is "the fastest polygons are the ones you don't draw". Here are a couple of quick links:

        http://msdn.microsoft.com/en-us/library/bb147263%28v=vs.85%29.aspx

        http://www.gamasutra.com/view/feature/3243/optimizing_direct3d_applications_.php

        http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter06.html

        这篇关于directx中许多复杂对象的典型渲染策略?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 23:57