Unused buffers bound to pipeline and performance.

Started by
1 comment, last by Happy SDE 8 years, 2 months ago

I found that some buffers are bound to pipeline after they are no longer needed.

For example, I used Geometry shader with constant buffer.

After Draw() call, I forgot to set it to null.

In all Draw() calls after that I see it bound to the pipeline.

I have 3 concerns:

  1. Performance penalties (the main concern)
  2. Harder to debug: (I see these buffers in debugger as Active)
  3. The code is not perfect smile.png

I wonder: should I strive to set all unused resources to null after I’ve used them?

Advertisement

No, I wouldn't spend any time unbinding resources between draw calls unless it is required for correctness (eg, not having a texture bound as input and output at the same time). There won't be any GPU performance penalty that I can think of to having a few constant buffers bound that aren't used. There will however be a CPU performance penalty to spending a lot of time unsetting them, so aside from perhaps extra debuggability I can only think of downsides.

You could always have a configuration of your game that does make an effort to clear out unused bindings in such a way that they're left alone in 'Release' if it's important for you to be able to use Graphics debuggers without seeing lots of unused bindings.

Adam Miles - Principal Software Development Engineer - Microsoft Xbox Advanced Technology Group

Thank you Adam!

So, lets take an example:

I have 2 classes, that setup pipeline draw calls for rendering bounding box and vertex normals.

They use Geometry shader and different constant buffers.

Every frame each of them will bind its own constant buffer to geometry shader.

The only difference - 2x GSSetConstantBuffers(0,0,nullptr);

If I will forget to bind CB (GS CB == nullptr), I would probably have a runtime error.

If I will not unbind buffer, and will use data from previous renderer, I probably will have visual artifacts, that are harder to find than looking at error messages.

In this case it seems for me using different code paths for Debug/Release mode is not a very good idea =(

Is it possible to measure particular call penalty? (I use VS2015)

I am asking this question not because I want to improve performance in this particular Draw() call, but because I want to learn how to measure performance in DX without speculations/guessing. smile.png

BTW, I am using DX11. Would DX12 solve this problem automatically?

This topic is closed to new replies.

Advertisement