Immediate-Mode-UI / Nuklear

A single-header ANSI C immediate mode cross-platform GUI library
https://immediate-mode-ui.github.io/Nuklear/doc/index.html
Other
9.17k stars 553 forks source link

Possible fix/improvement for d3d12 demo #569

Open saidwho12 opened 1 year ago

saidwho12 commented 1 year ago

I was trying to use the d3d12 demo but I had to adapt the code to work for C++ as our project is C++ (unfortunately 💀). I rewrote the file nuklear_d3d12.h to use the C++ version of D3D without changing any of the logic. I was getting an access violation here when trying to read d3d12.upload_buffer. I was trying to investigate and I found that both d3d12.upload_buffer and d3d12.font_upload_buffer were NULL however the other buffers were being initialized correctly.

After some digging I found this:

image

I then changed the parameter passed in to ID3D12Device_CreateCommittedResource from D3D12_RESOURCE_STATE_COPY_SOURCE to D3D12_RESOURCE_STATE_GENERIC_READ which seemed to solve the issue completely for me. Is this an issue with the original demo implementation or because I have adapted the code to use the C++? The lines that were causing an issue are this line:

    hr = device->CreateCommittedResource(&d3d12.heap_prop_upload, D3D12_HEAP_FLAG_NONE, &desc, D3D12_RESOURCE_STATE_GENERIC_READ, NULL, IID_ID3D12Resource, (void **)&d3d12.upload_buffer);
    NK_ASSERT(SUCCEEDED(hr));

and this one:

    hr = d3d12.device->CreateCommittedResource(&d3d12.heap_prop_upload, D3D12_HEAP_FLAG_NONE, &desc, D3D12_RESOURCE_STATE_GENERIC_READ, NULL, IID_ID3D12Resource, (void **)&d3d12.font_upload_buffer);
    NK_ASSERT(SUCCEEDED(hr));

I'm on Windows 10 my GPU is a GTX 1070 Ti. image