eliemichel / LearnWebGPU-Code

The accompanying code of the Learn WebGPU C++ programming guide
https://eliemichel.github.io/LearnWebGPU
MIT License
90 stars 23 forks source link

step044 cannot get the same result as the book says #19

Open sleeplessai opened 10 months ago

sleeplessai commented 10 months ago

image

step044 code example uses dynamic uniforms to draw two different color logos. I run the code but cannot get the same result as the book showed.

I've checked the minimum uniform buffer alignment size is 64, but it seems the the second uniform binding with draw call disappeared.

eliemichel commented 10 months ago

I cannot reproduce on my side, could you let me know:

sleeplessai commented 9 months ago

I cannot reproduce on my side, could you let me know:

  • which backend do you use (I guess wgpu-native, given the tone mapping)?
  • which OS
  • which GPU (let me know if you are on a laptop with integrated+dedicated gpu as well!)

Step044 is the section of "Dynamic Uniforms", whose goal is to draw double webgpu logo by uploading two different uniform buffers. Here are my environment info. I use backend gfx-rs/wgpu-native // as the book says I didn't see any tone mapping setting. Windows 11 RTX3060 with 545.37 driver

eliemichel commented 9 months ago

Step044 is the section of "Dynamic Uniforms", whose goal is to draw double webgpu logo by uploading two different uniform buffers.

Did you use the step044 branch as is or did you rather follow the guide itself? In the latter case could you share your code? Do you see any suspicious error message in the terminal where the application runs?

sleeplessai commented 9 months ago

@eliemichel I directly cloned the repo and checkout-ed, then copied both provided and latest version of webgpu-native library to build the project. In fact, I did coding from scratch by myself, but cannot get the right result, then tried your code at step044 branch. Neither of them could get the double logo results. There is no validation error in terminal. All things seem working very well. So, I am confused and stuck here. :D Where should I show you or adapt ?

eliemichel commented 9 months ago

Hard to debug without being able to reproduce the issue on my side. What I'd suggest is that you use RenderDoc to inspect a frame of your prototype. You may even share the .rdc capture you get out of it afterwards so that I can have a look!

sleeplessai commented 9 months ago

@eliemichel I uploaded two frame caps for your help. Please tell me how to check debug from rdc. I found that there might be some artifacts of the uniform byte range in the drawIndex calls. app_rdc_cap.zip

eliemichel commented 9 months ago

Thanks for taking the time to upload the rdc, unfortunately my GPU isn't able to replay them (that happens). If you can locate the erronous draw call in the Event Browser (use the Texture Viewer to see what each event brings to the render), then check in Pipeline State that the different steps and uniform memory look as you'd expect (feel free to share screenshots here)

sleeplessai commented 9 months ago

@eliemichel I re-run the project on my Linux machine with a RTX2080Ti GPU, everything goes well. I re-checked the dynamic uniforms alignment range is 64 in device limits same as my Windows 11 machine required for. That's weird.

eliemichel commented 9 months ago

It must be an issue related to the DirectX12 backend, you can try forcing the Vulkan backend with the following wgpu-native specific instance options:

WGPUInstanceExtras instanceExtras = {};
instanceExtras.chain.next = nullptr;
instanceExtras.chain.sType = (WGPUSType)WGPUSType_InstanceExtras;
instanceExtras.backends = WGPUInstanceBackend_Vulkan; // We only accept Vulkan adapters here!

WGPUInstanceDescriptor instanceDesc = {};
instanceDesc.nextInChain = &instanceExtras.chain;
Instance instance = createInstance(instanceDesc);
sleeplessai commented 9 months ago

It must be an issue related to the DirectX12 backend, you can try forcing the Vulkan backend with the following wgpu-native specific instance options:

WGPUInstanceExtras instanceExtras = {};
instanceExtras.chain.next = nullptr;
instanceExtras.chain.sType = (WGPUSType)WGPUSType_InstanceExtras;
instanceExtras.backends = WGPUInstanceBackend_Vulkan; // We only accept Vulkan adapters here!

WGPUInstanceDescriptor instanceDesc = {};
instanceDesc.nextInChain = &instanceExtras.chain;
Instance instance = createInstance(instanceDesc);

The default backend on my Windows machine is certainly Vulkan. Renderdoc caps show the API calls are 'vk'-prefix indeed. I tried to switch to another backend (DX12, DX11, GL) just then, still the program cannot show the double logo result. You may provide another Windows-work code copy to me; this code repo is definitely not correct on my machine.

sleeplessai commented 9 months ago

Thanks for taking the time to upload the rdc, unfortunately my GPU isn't able to replay them (that happens). If you can locate the erronous draw call in the Event Browser (use the Texture Viewer to see what each event brings to the render), then check in Pipeline State that the different steps and uniform memory look as you'd expect (feel free to share screenshots here)

All is vulkan calls; here is the mesh view screenshot for the second draw call. image

I changed some magic number as color into the uniform buffer, everything seems to be normal. image

Guess, is there any problem on the blend state or else difference? Perhaps I should report this bug to the webgpu-native repo, i think.

eliemichel commented 9 months ago

A couple of things to check:

Interesting that it does not depend on the backend at least. I do work mainly on Windows, so I am puzzled that I cannot reproduce on my end, this is a tricky bug, maybe hardware related.