Typical rendering strategy for many and varied complex objects in directx?
Asked Answered
C

2

9

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 3 I 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?

Chromatic answered 20/6, 2011 at 23:12 Comment(3)
AFAIK, each new version of DirectX makes things a little easier. Recent versions (I believe from 8 up) automatically move data (vertices, textures etc.) from RAM to VRAM and vice versa. So you always need to look into the latest and greatest version. The standard advice is to count your cycles vigorously and avoid state changes (like selecting textures) as much as possible.Synaeresis
Found documentation on number of vertex buffers, currently resides under odd heading "Direct3D 11 on Downlevel Hardware > Introduction" msdn.microsoft.com/en-us/library/ff476876%28v=vs.85%29.aspxChromatic
Found better directx 11 limits documentation :msdn.microsoft.com/en-us/library/ff819065%28v=VS.85%29.aspxChromatic
C
2

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

Cinereous answered 21/6, 2011 at 23:54 Comment(0)
C
1

Other answers are better answers to the question per se, but by far the most relevant thing I found since asking was this discussion on gamedev.net in which some big title games are profiled for state changes and draw calls.

What comes out of it is that big name games don't appear to actually worry too much about this, i.e. it can take significant time to write code that addresses this sort of issue and the time it takes to spend writing code fussing with it probably isn't worth the time lost getting your application finished.

Chromatic answered 22/6, 2011 at 15:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.