I am trying to move some of my heavy calculations from the CPU to the GPU and have created a RWTexture2D object for this using
RWTexture2D<float3> image : register(u1);
In my shader the image is modified and I am looking to get this data back to the CPU so I can either display it or output the contents to a file.
I have this in my application to set up the shader resource views.
//create texture srv desc D3D11_TEXTURE2D_DESC textureDesc; ZeroMemory(&textureDesc, sizeof(textureDesc)); textureDesc.Width = 640; textureDesc.Height = 480; textureDesc.MipLevels = 1; textureDesc.ArraySize = 1; textureDesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT; textureDesc.SampleDesc.Count = 1; textureDesc.SampleDesc.Quality = 0; textureDesc.Usage = D3D11_USAGE_DEFAULT; textureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_UNORDERED_ACCESS; textureDesc.CPUAccessFlags = 0; textureDesc.MiscFlags = 0; device->CreateTexture2D(&textureDesc, 0, &m_tex); //UAV D3D11_UNORDERED_ACCESS_VIEW_DESC descUAV; ZeroMemory(&descUAV, sizeof(descUAV)); descUAV.Format = DXGI_FORMAT_UNKNOWN; descUAV.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D; descUAV.Texture2D.MipSlice = 0; device->CreateUnorderedAccessView(m_tex, &descUAV, &m_uavAccess); //SRV D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc; srvDesc.Format = textureDesc.Format; srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; srvDesc.Texture2D.MostDetailedMip = 0; srvDesc.Texture2D.MipLevels = 1; device->CreateShaderResourceView(m_tex, &srvDesc, &m_srvTexOutput);
Perhaps these are unnecessary as I’m not passing an already existing texture to the shader, but creating one and then trying to pass it to the CPU.
I’m looking to save the modified texture to a file using the code below, but it requires a ID3D11Resource *
to save
D3DX11SaveTextureToFile(context, ???, D3DX11_IFF_PNG, L"output.png");
Maybe I am missing the point on something, so how can I obtain the texture from the GPU?