I have a Texture3D. I want to read a part of it from CPU side. (I'm using the SharpDX toolkit (v2.5.1).)

My data is always 0, but the output shows no errors.

This is the source texture:

testTex = Texture3D.New<float>(GraphicsDevice, wx, wy, wz, PixelFormat.R32.Float, texDat, TextureFlags.ShaderResource, sdx11.ResourceUsage.Default);

I'm trying to read part of it here:

tempFloat = new float[1];
TextureDescription stagedTexDesc = new TextureDescription()
    Height = 1,
    Width = 1,
    Depth = 1,
    MipLevels = 1,
    ArraySize = 1,
    Format = testTex.Format,
    Usage = sdx11.ResourceUsage.Staging,
    CpuAccessFlags = sdx11.CpuAccessFlags.Read | sdx11.CpuAccessFlags.Write,
texNew = Texture3D.New(GraphicsDevice, stagedTexDesc);

deviceContext.CopySubresourceRegion(testTex, 0, new sdx11.ResourceRegion(iHPos.X, iHPos.Y, iHPos.Z, iHPos.X + 1, iHPos.Y + 1, iHPos.Z + 1), texNew, 0);

tempFloat[0] value is always 0.0. The GetData method performs Map and Unmap of the resource automatically

If I try to call GetData on the original texture, it seems to get the data correctly.

Also, is there a better way to read the data?

  • \$\begingroup\$ This could be a bug. Could you provide a reproducible simple VS project on github issues github.com/sharpdx/SharpDX/issues so that we can have a look at this? \$\endgroup\$
    – xoofx
    Commented Feb 17, 2014 at 1:13
  • \$\begingroup\$ Thank you for the quick response. I will try to create reproducible project this evening. \$\endgroup\$
    – Renesis
    Commented Feb 17, 2014 at 9:24
  • \$\begingroup\$ I have reported an issue and uploaded a sample project. github.com/sharpdx/SharpDX/issues/281 \$\endgroup\$
    – Renesis
    Commented Feb 17, 2014 at 19:11
  • 2
    \$\begingroup\$ This question appears to be off-topic because it is about a SharpDX bug best discussed with the developers. \$\endgroup\$
    – Anko
    Commented Feb 24, 2014 at 13:11
  • \$\begingroup\$ Actually it wasn't a bug, I posted a solution. \$\endgroup\$
    – Renesis
    Commented Feb 25, 2014 at 10:30

1 Answer 1


It seems I used deviceContext in wrong way. It should have been either initialized like this:

var deviceContext = (SharpDX.Direct3D11.DeviceContext)GraphicsDevice;

Here is the explanation what I did wrong here:

var deviceContext = new SharpDX.Direct3D11.DeviceContext(GraphicsDevice);

When creating a new DeviceContext, it is actually creating a deferred context, more relevant in multithreaded scenarios. In your case, all commands issued on this newly created deferred context were in fact no-op (because a deferred context needs a special pattern to replay it on the immediate context).

Another solution would be to use directly:

GraphicsDevice.Copy(testTex, 0, new sdx11.ResourceRegion(iHPos.X, iHPos.Y, iHPos.Z, iHPos.X + 1, iHPos.Y + 1, iHPos.Z + 1), texNew, 0);

You must log in to answer this question.

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