Immediate-Mode-UI / Immediate-Mode-UI/Nuklear
Possible fix/improvement for d3d12 demo
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 11.4k
- Forks
- 686
- Avg merge
- 4d 1h
- Merged PRs (30d)
- 3
Description
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](https://github.com/Immediate-Mode-UI/Nuklear/blob/master/demo/d3d12/nuklear_d3d12.h#L322) 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:

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.

Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in demo/d3d12/nuklear_d3d12.h at the CreateCommittedResource calls and the access violation near line 322. Compare the original C implementation with the reported C++ adaptation and investigate why the upload buffers remain NULL. Done means determining whether the resource state is incorrect in the original demo or only in the adaptation, with the finding validated on the reported path.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- computer-graphics
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100