question

Abhisheksharma-7232 avatar image
0 Votes"
Abhisheksharma-7232 asked Abhisheksharma-7232 answered

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

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(
&textureDesc,
nullptr,
&texture);

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;
D3D11_MAPPED_SUBRESOURCE ms;
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

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

private:
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 https://github.com/AbhishekSharma-SEG/Demo_DXPlayer 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

windows-uwpc++
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Abhisheksharma-7232 avatar image
0 Votes"
Abhisheksharma-7232 answered

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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.