7

If you want to unbind a shader resource in directx11, all code I've found does something along these lines:

ID3D10ShaderResourceView* nullSRV[1] = {nullptr};
context->PSSetShaderResources(0, 1, &nullSRV);

Why not simply use this?

context->PSSetShaderResources(0, 0, nullptr);

It seems supported by the docs (https://msdn.microsoft.com/en-us/library/windows/desktop/ff476473%28v=vs.85%29.aspx), is there really any difference between the two?

2
  • And be clear you are not unbinding all shader resources, just the first slot. Commented Apr 21, 2015 at 17:58
  • While I do agree the second form would be better (or even better - a PSResetShaderResources() or something like that), unfortunately there is nothing in that MSDN link that says it is supported. Since I believe many would try to do what you wanted to do, it would be great if the docs were explicit about that invalid code not being allowed and what is the correct way to unbind a resource. @Chuck Walbourn, what do you think? Commented Oct 19, 2018 at 16:11

1 Answer 1

4

In the first case, you are unbinding one SRV, starting in slot zero. In the second case, you are not unbinding anything because NumViews is zero. If you wanted to unbind in the second case, you'd have to use:

context->PSSetShaderResources(0, 1, nullptr);

However, this will cause the runtime to crash:

D3D11 CORRUPTION: ID3D11DeviceContext::PSSetShaderResources: Third parameter corrupt or unexpectedly NULL. [ MISCELLANEOUS CORRUPTION #15: CORRUPTED_PARAMETER3]

This is why the first form is used.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.