I am trying to map a Texture2D resource in DirectX11 via SharpDX.

The resource is declared as a ShaderResource, with Dynamic usage and the 'Write' CPU flag specified.

My call however fails with a generic exception from SharpDX:

  out stream

I see from this question that it is supported. The MSDN docs and this other question hint that instead of using Context.MapSubresource() I should be using Texture2D.Map(), however, the DirectX11 Texture2D class does not define Map() (though it does for the D3D 10 equivalent).

If I call the above with MapMode.WriteDiscard, the call succeeds but in this case the previous content of the texture is lost, which is no good when I only want to update a section of it.

Has the Map() method been removed in Direct3D 11 or am I looking in the wrong place? Is the MapSubresource() method unsuitable or am I using it wrong?

EDIT: I declared my resource as Dynamic with CPU Write Flags - not Default as I originaly wrote - sorry for the fairly huge 'typo' that changes the entire question!


1 Answer 1


The main reason Direct3D10 Map methods were moved to Direct3D11 DeviceContext is to support multithreading. They were previously attached to each resource (thus implicitly, a single device), but with Direct3D11, It is now possible to update the same resource from different deffered context.

Concerning your issue with MapSubresource, you need to check this documentation on Resource Usage.

You will see that it is not possible to use Map method with Usage.Default, as it is only working with dynamic texture. Usage.Default is suitable if you are only using UpdateSubresource. The correct way to use Map is to declare the texture with Usage.Dynamic and Map with WriteDiscard. It is not possible to keep the content of the dynamic texture (update partially) as a race condition between the GPU and CPU would arise.

  • \$\begingroup\$ Thank you for your answer, I understand now. I made a mistake in my original question, but it applies entirely still. I will use an intermediate buffer and CopySubresourceRegion() to update my texture, as I assume that since the GPU will process these calls 'serially' the race condition no longer applies? \$\endgroup\$
    – sebf
    Nov 29, 2011 at 9:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .