Windows C++ fast RGBA32 DX texture to RGB24 buffer

馋奶兔 提交于 2020-04-30 08:20:19

问题


If already have a DirectX texture in hand, what is the fast(low CPU utilization) way to get a RGB24 buffer in main RAM from it (skip the A)?

Strictly the format is DXGI_FORMAT_B8G8R8A8_UNORM, does this mean ARGB?

I'm using https://github.com/bmharper/WindowsDesktopDuplicationSample to capture Windows desktop and the result is to be converted into RGB24 lossless format in main RAM.

The existing code copy GPU texture to CPU texture then use memcpy to copy each line of the RGBA32 data to main RAM:

ID3D11Texture2D* gpuTex = nullptr;
hr                      = deskRes->QueryInterface(__uuidof(ID3D11Texture2D), (void**) &gpuTex);
....
ID3D11Texture2D* cpuTex = nullptr;
hr                      = D3DDevice->CreateTexture2D(&desc, nullptr, &cpuTex);
....
D3DDeviceContext->CopyResource(cpuTex, gpuTex);
....
D3D11_MAPPED_SUBRESOURCE sr;
hr = D3DDeviceContext->Map(cpuTex, 0, D3D11_MAP_READ, 0, &sr);
....    
for (int y = 0; y < (int) desc.Height; y++)
    memcpy(Latest.Buf.data() + y * desc.Width * 4, (uint8_t*) sr.pData + sr.RowPitch * y, desc.Width * 4);

Some possible way:

(1) Is it possible to let GPU convert the texture to RGB24 texture before copy it to CPU texture? How to do this in DX?

(2) If not, some assembly code to replace the line memcpy

memcpy(Latest.Buf.data() + y * desc.Width * 4, (uint8_t*) sr.pData + sr.RowPitch * y, desc.Width * 4);

to do RGBA32 to RGB24 conversion for a line may be the best way, can some example or reference be provided?

来源:https://stackoverflow.com/questions/61269423/windows-c-fast-rgba32-dx-texture-to-rgb24-buffer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!