2
\$\begingroup\$

I am trying to render an image to my window using Direct X but I don't really want a "3D" world as such, and I don't really want to set up all the vertex/index buffers as I won't need them. I am performing all of my calculations and operations using compute shaders which returns me an image. As the file io is quite a bottleneck, I am looking to just render the image directly to the screen to increase performance. My question is, how would I go about this using Direct X 11? I have looked at some examples already such as rastertek and other questions on SO but they are either over-complicating the matter, or they want a solution to font drawing etc.

At the moment I am able to produce a blank screen using the following code and the screen size is the size of the image retrieved from the GPU. I am looking to draw this entire image to my back buffer or some render target, and then display it.

void Application::Draw()
{
    float ClearColor[4] = { 0.5f, 0.125f, 0.3f, 1.0f }; 
    context->ClearRenderTargetView(_pRenderTargetView, ClearColor);

    // compute shader operations, retrieve image data from gpu
    // draw image to back buffer/render target then present

    swapChain->Present(0, 0);
}

enter image description here


From Why can't I write to my render targets?, I have tried the solution using

ID3D11Resource * backBufferResource;
_pRenderTargetView->GetResource(&backBufferResource);//backbuffer render target
context->CopyResource(backBufferResource, gpuResource);

This doesn't seem to throw any errors, but it doesn't change the output on the screen. It is mentioned that the back buffer must be the exact same format as the image we're trying to copy to it so this may be the issue. My swap chain desc is as follows

DXGI_SWAP_CHAIN_DESC sd;
ZeroMemory(&sd, sizeof(sd));
sd.BufferCount = 1;
sd.BufferDesc.Width = _WindowWidth;
sd.BufferDesc.Height = _WindowHeight;
sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;//FORMAT DIFFERENT
sd.BufferDesc.RefreshRate.Numerator = 60;
sd.BufferDesc.RefreshRate.Denominator = 1;
sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
sd.OutputWindow = _hWnd;
sd.SampleDesc.Count = 1;
sd.SampleDesc.Quality = 0;
sd.Windowed = TRUE;

and my image format is

DXGI_FORMAT_R32G32B32A32_FLOAT

If I try to change the swap chain format it throws a memory access violation.

\$\endgroup\$
1
  • \$\begingroup\$ Hi, I was looking for the exact same things but with no luck after 4 years... Render 2D image with simple and minimized code. Do you still have this full code available? \$\endgroup\$
    – Josh Chiu
    Commented Sep 5, 2022 at 8:25

1 Answer 1

1
\$\begingroup\$

Changing my image format to match the swap chain's format seemed to do the trick!

DXGI_FORMAT_R8G8B8A8_UNORM

\$\endgroup\$
2
  • \$\begingroup\$ CopyResource is not really a reasonable way to 'draw' in most cases. That's why so much of the GPU hardware is dedicated to textured triangle rasterization. See SpriteBtach in DirectX Tool Kit \$\endgroup\$ Commented Dec 2, 2017 at 18:20
  • \$\begingroup\$ If your issue is solved, can you mark your answer as correct? This prevents it appearing in the from page repeatedly . \$\endgroup\$ Commented Jan 7, 2019 at 15:19

You must log in to answer this question.

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