1

I have created a red colored texture of DXGI format DXGI_FORMAT_R32_FLOAT. I have a byte buffer of red color pixels where 4 byte per pixel is prepared. The byte buffer is then copied using device context map and unmap functions and after that I have created a shader resource view. I have get the resource back from resource view then passed that to SaveDDSTextureToFile() to save the bitmap data to dds file format. But when I am going to save it in dds in file to check it's saves a same sized texture which is total black. Where should I look at to debug?

    D3D11_TEXTURE2D_DESC desc;
    ZeroMemory(&desc, sizeof(desc));
    desc.Width = static_cast<UINT>(renderTarget.width);
    desc.Height = static_cast<UINT>(renderTarget.height);
    desc.ArraySize = 1;
    desc.Format = DXGI_FORMAT_R32_FLOAT;
    desc.Usage = D3D11_USAGE_DYNAMIC;
    desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
    desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
    desc.MipLevels = 1;
    desc.SampleDesc.Count = 1;

    ...

SaveDDSTextureToFile(renderer->Context(), texture2D, L"D:\\RED.dds");

I have created the red texture buffer by following:

CImage m_cImage;
// create a test image
m_cImage.Create(w, -h, 8 * 4); // 8 bit * 4 channel => 32 bpp or 4 byte per pixel
auto hdc = m_cImage.GetDC();
Gdiplus::Graphics graphics(hdc);

// Create a SolidBrush object.
Gdiplus::SolidBrush redBrush(Gdiplus::Color::Red);

// Fill the rectangle.
Gdiplus::Status status = graphics.FillRectangle(&redBrush, 0, 0, w, h);
TRY_CONDITION(status == Gdiplus::Status::Ok);
....
// Then saved the m_cImage.GetBits() to bmp file using Gdiplus::Bitmap
// and my expected texture is found
Chuck Walbourn
  • 38,259
  • 2
  • 58
  • 81
  • Your resource is "Write" only access from the CPU, so it probably fails when you try to copy it back. You can enable the Debug device and look for any additional diagnostic information. – Chuck Walbourn Dec 30 '18 at 07:46
  • I used D3D11_MAP_WRITE_DISCARD during the call of ID3D11DeviceContext::Map() for setting up virtual memory access to the texture resource. Is that correct? I can see the ScreenGrab.cpp takes WIC equivalent GUID_WICPixelFormat32bppGrayFloat while saving dds file format which in my case showing black instead of red texture. – Tajuddin Khandaker Jan 06 '19 at 06:12
  • 1
    When you called ``Map(DISCARD)``, it gave you back a blank buffer because that flag indicates the driver is free to use buffer renaming and not force the GPU to wait until the buffer is no longer in use. That pattern is intended for WRITE optimization, not READBACK. – Chuck Walbourn Jan 06 '19 at 20:26

0 Answers0