Skip to main content
added 10 characters in body
Source Link
user1430
user1430

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;
    memset(&cputextdesc,0,sizeof(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;

    device->CreateTexture2D(&cputextdesc,NULL,&cpuTexture);

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

    D3D11_MAPPED_SUBRESOURCE mres1,mres2,mres3;

    icontext->Map(cpuTexture,text1,D3D11_MAP_READ,0,&mres1);
    icontext->Map(cpuTexture,text2,D3D11_MAP_READ,0,&mres2);
    icontext->Map(cpuTexture,text3,D3D11_MAP_READ,0,&mres3); 

    // (assert row and depth pitch are equals)
     
    icontext->Unmap(cpuTexture,text1);
    icontext->Unmap(cpuTexture,text2);
    icontext->Unmap(cpuTexture,text3);

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;
    memset(&cputextdesc,0,sizeof(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;

    device->CreateTexture2D(&cputextdesc,NULL,&cpuTexture);

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

    D3D11_MAPPED_SUBRESOURCE mres1,mres2,mres3;

    icontext->Map(cpuTexture,text1,D3D11_MAP_READ,0,&mres1);
    icontext->Map(cpuTexture,text2,D3D11_MAP_READ,0,&mres2);
    icontext->Map(cpuTexture,text3,D3D11_MAP_READ,0,&mres3);
//assert row and depth pitch are equals
        icontext->Unmap(cpuTexture,text1);
    icontext->Unmap(cpuTexture,text2);
    icontext->Unmap(cpuTexture,text3);

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;
    memset(&cputextdesc,0,sizeof(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;

    device->CreateTexture2D(&cputextdesc,NULL,&cpuTexture);

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

    D3D11_MAPPED_SUBRESOURCE mres1,mres2,mres3;

    icontext->Map(cpuTexture,text1,D3D11_MAP_READ,0,&mres1);
    icontext->Map(cpuTexture,text2,D3D11_MAP_READ,0,&mres2);
    icontext->Map(cpuTexture,text3,D3D11_MAP_READ,0,&mres3); 

    // (assert row and depth pitch are equals)
 
    icontext->Unmap(cpuTexture,text1);
    icontext->Unmap(cpuTexture,text2);
    icontext->Unmap(cpuTexture,text3);
added 1140 characters in body
Source Link

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;
    memset(&cputextdesc,0,sizeof(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;

    device->CreateTexture2D(&cputextdesc,NULL,&cpuTexture);

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

    D3D11_MAPPED_SUBRESOURCE mres1,mres2,mres3;

    icontext->Map(cpuTexture,text1,D3D11_MAP_READ,0,&mres1);
    icontext->Map(cpuTexture,text2,D3D11_MAP_READ,0,&mres2);
    icontext->Map(cpuTexture,text3,D3D11_MAP_READ,0,&mres3);
//assert row and depth pitch are equals
        icontext->Unmap(cpuTexture,text1);
    icontext->Unmap(cpuTexture,text2);
    icontext->Unmap(cpuTexture,text3);

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.

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;
    memset(&cputextdesc,0,sizeof(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;

    device->CreateTexture2D(&cputextdesc,NULL,&cpuTexture);

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

    D3D11_MAPPED_SUBRESOURCE mres1,mres2,mres3;

    icontext->Map(cpuTexture,text1,D3D11_MAP_READ,0,&mres1);
    icontext->Map(cpuTexture,text2,D3D11_MAP_READ,0,&mres2);
    icontext->Map(cpuTexture,text3,D3D11_MAP_READ,0,&mres3);
//assert row and depth pitch are equals
        icontext->Unmap(cpuTexture,text1);
    icontext->Unmap(cpuTexture,text2);
    icontext->Unmap(cpuTexture,text3);
Source Link

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.