Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a DX10 program, where I create an array of 3 16x16 textures, then map, read, and unmap each subresource in turn. I use a single mip level, set resource usage to staging and CPU access to read. Now, here is the problem:

  • Subresource 0 contains 1024 bytes, pitch 64, as expected.
  • Subresource 1 contains 512 bytes, pitch 64.
  • Subresource 2 contains 256 bytes, pitch 64.

I expect all three to be the same size. Debugging output is enabled, but not reporting any warnings or errors. Am I missing something, or might this be some sort of driver issue?

Here is the code. The language is Nemerle, but C# and C++ would look almost the same. I have looked through the generated code, and am fairly confident the problem is not language-related.

def cpuTexture = Texture2D
    ( device
    , Texture2DDescription() <-
        Width     = 16;
        Height    = 16;
        MipLevels = 1;
        ArraySize = 3;
        Format    = Format.R32_Float;
        Usage     = ResourceUsage.Staging;
        CpuAccessFlags    = CpuAccessFlags.Read;
        SampleDescription = SampleDescription(count = 1, quality = 0);
foreach (subresource in [0 .. 2])
    def data = cpuTexture.Map(subresource, MapMode.Read, MapFlags.None);
    Console.WriteLine($"subresource $subresource");
    Console.WriteLine($"length = $(data.Data.Length)");
    Console.WriteLine($"pitch  = $(data.Pitch)");
share|improve this question
Can you post your code for initializing and mapping the texture array? – Nathan Reed Apr 20 '12 at 0:11
@NathanReed, sure, added the code. – Don Reba Apr 20 '12 at 4:05
Thanks. Your code looks right as far as I can see, though, and I checked against the D3D10 docs as well. I'm afraid I have no idea what's going on. :( – Nathan Reed Apr 20 '12 at 4:24

You're forgetting to consider mipLevels. When creating a texture, usually miplevels will be generated so you will not find texture element 2 at subresource 2 (there is a mipLevel in it, which is half of original texture and so on).

Use this function to get the right subresource index.

    ID3D11Texture2D *cpuTexture = NULL;

    D3D11_TEXTURE2D_DESC cputextdesc;

    cputextdesc.Width = cputextdesc.Height = 16;
    cputextdesc.ArraySize = 3;
    cputextdesc.MipLevels = 1;
    cputextdesc.Format = DXGI_FORMAT_R32_FLOAT;
    cputextdesc.Usage = D3D11_USAGE_STAGING;
    cputextdesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
    cputextdesc.SampleDesc.Count = 1;
    cputextdesc.SampleDesc.Quality = 0;


    int text1 = D3D11CalcSubresource(0,0,1);
    int text2 = D3D11CalcSubresource(0,1,1);
    int text3 = D3D11CalcSubresource(0,2,1);

    D3D11_MAPPED_SUBRESOURCE mres1,mres2,mres3;


    // (assert row and depth pitch are equals)

share|improve this answer
There is only a single mip level. – Don Reba Jun 13 '12 at 21:04
I modified my answer with a code example. 3 subresource have the same row and depth pitch. – Vincenzo Jun 14 '12 at 6:48
Still incorrect because "MipLevels = 1" in the OP, and besides - if it were mipmapping, the lengths would be quartering, not halving, for each subresource (the pitch would be expected to - but may not always - halve). I suspect it's more likely a problem in the calculation of "data.Data.Length" in the OP's environment. – Le Comte du Merde-fou Sep 12 '12 at 15:37

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.