baldurk / renderdoc

RenderDoc is a stand-alone graphics debugging tool.
https://renderdoc.org
MIT License
9.02k stars 1.35k forks source link

D3D12 - RenderDoc make texture artifacts #3437

Closed Cat-dll closed 1 month ago

Cat-dll commented 1 month ago

Description

Hello, I have a C project that uses DirectX 12, the program so far is pretty simple. I'm drawing a textured cube and the camera can move in 4 directions.

In the project, my texture is 8x8 If I run the project without RenderDoc, everything works fine.

BUT, if I launch with RenderDoc, with the 8x8 texture, the first 8-pixel row at the top is glitched. What's even weirder is that if I use auto-capture at frame 0, the bug doesn't occur for the rest of the program's lifetime. It's as if capturing the first frame fixes the problem.

(It glitch with bigger texture too, 256x256 in the project if you want to try)

Without RenderDoc attached Screenshot_54

With RenderDoc attached Screenshot_55

Steps to reproduce

You can run the project with RenderDoc, and test. Project Code: https://www.dropbox.com/scl/fo/gw7c42xl1qj8pk0d2dh0l/AIFFhtYy3jU1nx1cd493P0I?rlkey=5uvni2fj4lhgko1ykepqvk4ky&st=vdu3tne2&dl=0 The main part of the code is in one big file :`)

Environment

baldurk commented 1 month ago

I can't reproduce this from the project your provided. I had to make a minimal change to the program to run without crashing but after doing so I'm able to capture in RenderDoc with no visible corruption.

Looking briefly at your code I suspect this is a race condition - you use the vertex buffer as a staging buffer to upload the texture data but then write into it later with the vertex data with no synchronisation to ensure the texture copy has completed. With D3D12's default row alignment of 256 bytes and the 240 bytes of vertex data, that would explain the first row only being corrupted if the vertex data write ran on the CPU before the texture copy on the GPU.

Cat-dll commented 1 month ago

I take a look, and yes you're right, I should have checked if the copy had finished before modifying the buffer. Thanks