0
\$\begingroup\$

I have some code below that is Directx 11 that im using to make a resource texture.

D3D11_TEXTURE2D_DESC fullScreenTextureDesc;
        ZeroMemory(&fullScreenTextureDesc, sizeof(fullScreenTextureDesc));
        fullScreenTextureDesc.Width = 800;
        fullScreenTextureDesc.Height = 600;
        fullScreenTextureDesc.MipLevels = 1;
        fullScreenTextureDesc.ArraySize = 1;
        fullScreenTextureDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
        fullScreenTextureDesc.SampleDesc.Count = 1;
        fullScreenTextureDesc.SampleDesc.Quality = 0;
        fullScreenTextureDesc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
        fullScreenTextureDesc.Usage = D3D11_USAGE_DEFAULT;


        HR(device->CreateTexture2D(&fullScreenTextureDesc, nullptr, &fullScreenTexture));

How can i convert this to directx 12?

\$\endgroup\$
1
  • \$\begingroup\$ I believe you're going to be using the ID3D12Device::CreateCommittedResource method if you want to look into that \$\endgroup\$ Commented Feb 18, 2020 at 19:45

1 Answer 1

1
\$\begingroup\$

The conversion of that code is easy:

D3D12_RESOURCE_DESC desc = {};
desc.Width = 800;
desc.Height = 600;
desc.MipLevels = 1;
desc.DepthOrArraySize = 1;
desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
desc.SampleDesc.Count = 1;
desc.SampleDesc.Quality = 0;
desc.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET;
desc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;

CD3DX12_HEAP_PROPERTIES defaultHeapProperties(D3D12_HEAP_TYPE_DEFAULT);

hr = device->CreateCommittedResource(
    &defaultHeapProperties,
    D3D12_HEAP_FLAG_NONE,
    &desc,
    D3D12_RESOURCE_STATE_COPY_DEST,
    nullptr,
    IID_PPV_ARGS(&tex)); // tex is type ID3D12Resource*

That said, it's very challenging to just do a naive port of DirectX 11 to DirectX 12. There's a lot of differences needed to get good performance, and your application is responsible for a lot of conditions, edge-cases, and timing.

You should take a look at DirectX Tool Kit for DX12.

\$\endgroup\$

You must log in to answer this question.

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