Xbox LIVE Indie Games
Sort Discussions: Previous Discussion Next Discussion
Page 1 of 1 (5 posts)

Directx 12 : What is the best way to read back data from frame buffer?

Last post 6/14/2017 6:55 AM by Charybdis. 4 replies.
  • 2/18/2016 9:54 PM

    Directx 12 : What is the best way to read back data from frame buffer?

    Hi,
    I am trying to read back content from a frame buffer and save it in a file.
    After a lot of trial and error, I am doing the following (reverse of DX helper function UpdateSubresources)
    1) Created committed buffer resource with type  : D3D12_HEAP_TYPE_READBACK and state : D3D12_RESOURCE_STATE_COPY_DEST
    2) Switch frame buffer to D3D12_RESOURCE_COPY_SOURCE
    3) Call GetCopyableFootprint of the committed buffer created in step 1
    4) call CopyTextureRegion ( SCR : Framebuffer , DST : committed buffer created in step 1)
    5) Switch frame buffer to state it was before
    6) Map committed buffer created in step 1
    7) copy to image file
    8) Unmap committed buffer created in step 1
    It works, but is there a better way?
    Thanks
  • 3/9/2017 4:23 AM In reply to

    Re: Directx 12 : What is the best way to read back data from frame buffer?

    Hey!
    Can you please provide me with the code for reading back content from buffer to file . I am a beginner and have no clue how to proceed.
  • 3/9/2017 6:12 PM In reply to

    Re: Directx 12 : What is the best way to read back data from frame buffer?

    If you are a beginner, don't use DirectX 12. The DirectX 12 API is designed for graphics experts with a very strong background in DirectX 11 programming with a deep understanding of GPU hardware, and can take on the high-levels of validation that is required to successfully ship a robust application. DirectX 12 is particularly unforgiving to newbies. If you are new to DirectX, stick with DirectX 11.

    Some resources here:

    DirectX Tool Kit for DirectX 11: See ScreenGrab.

    DirectX Tool Kit for DirectX 12: See ScreenGrab.
  • 6/14/2017 6:20 AM In reply to

    Re: Directx 12 : What is the best way to read back data from frame buffer?

    Yes absolutely, I studied both the DirectX versions, but still stuck there. There is a frame buffer responsible for evreything being rendered. How can I get the frame buffer data into a vector or array so that I can process the image that is developed using this array.
  • 6/14/2017 6:55 AM In reply to

    Re: Directx 12 : What is the best way to read back data from frame buffer?

    If you look at the ScreenGrab source, you'll see it's copying the given 2D texture (which can be the render target) to a staging buffer that the CPU can read (in DX11 that's a STAGING resource which can be Mapped; in DX12 that's a resource allocated from the READBACK heap that can be Mapped). Once it's in CPU memory, you can access the pixel data depending on it's format. Remember that Direct3D pixel data rows are row-pitch bytes long, which may result in some padding at the end of each scanline.

    The 'frame buffer' is an old-school concept on modern Windows systems. An application renders to a swapchain and when Preset is called, the swapchain is flipped and the 'front buffer' is then composited by the Windows Desktop Manager to the actually visible surface.
Page 1 of 1 (5 posts) Previous Discussion Next Discussion