trying to copy pixal data from cpu to gpu using map every thing runs fine but the screen comes empty directx

Abhishek sharma 136 Reputation points

in my TextureHendler class, I create an empty texture using this

D3D11_TEXTURE2D_DESC textureDesc = { 0 };
textureDesc.Width = textureWidth;
textureDesc.Height = textureHeight;
textureDesc.Format = dxgiFormat;
textureDesc.Usage = D3D11_USAGE_DYNAMIC;
textureDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
textureDesc.MiscFlags = 0;
textureDesc.MipLevels = 1;
textureDesc.ArraySize = 1;
textureDesc.SampleDesc.Count = 1;
textureDesc.SampleDesc.Quality = 0;
textureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
hr = m_deviceResource->GetD3DDevice()->CreateTexture2D(

and on runtime, I want to load data from CPU memory using the code below

Platform::Array<unsigned char>^ datapointer = GetPixelBytes();
static constexpr int BYTES_IN_RGBA_PIXEL = 4;
auto rowspan = BYTES_IN_RGBA_PIXEL * width;
auto device_context = m_deviceResource->GetD3DDeviceContext();
auto hr = device_context->Map(m_texture->GetTexture2d(), 0, D3D11_MAP_WRITE_DISCARD, 0, &ms);
uint8_t* mappedData = reinterpret_cast<uint8_t*>(ms.pData);
for (int i = 0; i < datapointer->Length; i++)
mappedData[i] = datapointer[i];
device_context->Unmap(m_texture->GetTexture2d(), 0);

everything runs fine but the output screen comes black

std::shared_ptr<TextureHendler> m_texture;

TextureHendler Holds

ID3D11Texture2D* GetTexture2d() { return texture.Get(); }

Microsoft::WRL::ComPtr<ID3D11Texture2D> texture;

and a load function which content is shown above

hr from map function returns S_OK

here are the sample code thanks for the help

in this example, I have changed most of the code to make it available but in the future, there will be video frames that come and get updated on demand and I might be using FFmpeg and it's just to show that whenever I want to update texture data from CPU it does not and I removed all of the video parts from it just to keep it simple

Universal Windows Platform (UWP)
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,523 questions
0 comments No comments
{count} votes

Accepted answer
  1. Abhishek sharma 136 Reputation points

    ok there is something I found that I was creating a texture of format DXGI_FORMAT_R32G32B32A32_UINT While I was filling texture data as of DXGI_FORMAT_R8G8B8A8_UNORM or DXGI_FORMAT_R8G8B8A8_UINT and the data that I was filling is not complete maybe that's why it's causing this issue but I am not sure because when I changed the format it started to fill up but something is still wrong in length because that calculated length must be equal to width * height * noOfBytePerPixel (4 in this case ) and still I get some texture is missing Color most of the part get colored but not whole I will update my finding in git

    0 comments No comments

0 additional answers

Sort by: Most helpful