It’d assist if you happen to defined what you might be doing with that texture precisely… Usually, there are many good efficiency the explanation why you’ll be able to’t simply entry texture knowledge in Direct3D assets from the CPU…
You may’t map D3D11_USAGE_DEFAULT textures as they’re allowed to be positioned into reminiscence that’s doubtlessly inaccessible the CPU, and is subsequently the quickest for the GPU to entry.
You may’t map D3D11_USAGE_IMMUTABLE in any respect, and may solely initialize them with initData at creation time.
You may map D3D11_USAGE_DYNAMIC textures, however there is a efficiency penalty for each the GPU and CPU to learn them. Usually you utilize them with solely D3D11_CPU_ACCESS_WRITE and never attempt to learn them from the CPU.
You may in fact map D3D11_USAGE_STAGING since they’re solely accessible by the CPU, to allow them to’t be rendered.
Each DirectXTex and DirectX Device Equipment‘s texture loaders have an Ex model that might can help you specify a utilization apart from D3D11_USAGE_DEFAULT and to offer D3D11_CPU_ACCESS_READ which is required to entry the pixels with Map
You might additionally create a second D3D11_USAGE_STAGING useful resource after which CopyResource from the unique to the staging useful resource, after which you’ll be able to Map the staging useful resource. Be aware that that is what DirectX Device Equipment’s ScreenGrab and DirectXTex’s CaptureTexture are doing.
It is also price noting that if you happen to actually wish to entry the feel’s pixel shade knowledge, you do not need to make use of D3D11_MAP_WRITE_DISCARD as the entire goal of that flag is to inform the driving force that you do not really care about any present knowledge from the CPU side–this permits the driving force to simply offer you again a pointer to another reminiscence of the identical dimension whereas persevering with to make use of any present copy for rendering with out slowing issues down–this is known as ‘buffer renaming’.
BTW, you’ll want to learn this put up as to why there are texture features in each DirectXTex & DirectX Device Equipment.
PS: In case you get an HRESULT like E_INVALIDARG, if you happen to allow the Debug Machine you’re going to get diagnostic output that tells you why…
