So, are you sure PIX is displaying the calls in the expected order?? My PIX-fu is not strong (ok, I just opened it for the first time a couple of hours ago), but I did a capture and tried to make sense of it. Here is the PIX file: WeTransfer - Send Large Files & Share Photos Online - Up to 2GB Free
First, I found the Texture itself, with resource address 0x1EDAE5C0. Then I looked at who references that texture, and I get these:
8038 <0x0C7A6B28> ID3D11Device::CreateRenderTargetView(0x1EDAE5C0, 0x1C19F34C, 0x105873E4 → 0x1EDADE88)
8040 <0x0C7A6B28> ID3D11Device::CreateRenderTargetView(0x1EDAE5C0, 0x1C19F304, 0x105873FC → 0x1EDADEE0)
8042 <0x0C7A6B28> ID3D11Device::CreateShaderResourceView(0x1EDAE5C0, 0x1C19F300, 0x105873BC → 0x1EDADF38)
8045 <0x0C7A6B28> ID3D11Device::CreateUnorderedAccessView(0x1EDAE5C0, 0x1C19F2E8, 0x105873C4 → 0x1EDADF90)
Resource 0x1EDADEE0 and 0x1EDADF38 are never used it seems (??), but 0x1EDADE88 and 0x1EDADF90 are. 0x1EDADE88 corresponds to the initialization I do, clearing the texture to black. 0x1EDADF90 corresponds to the UAV usage. Frame 20 is the one working frame. Frame 21 seems to be Unity drawing its own UI (I closed as many Unity windows as I could to make PIX spew a little less). And frame 22 is the second frame, where everything is black.
The thing is, I’m not convinced Unity is setting things up properly after the first frame. Here is a (very abridged) set of DX calls, tracking usage of that texture, the first draw call for each frame, and when render targets (and UAVs) are set up. And it’s curious:
8038 <0x0C7A6B28> ID3D11Device::CreateRenderTargetView(0x1EDAE5C0, 0x1C19F34C, 0x105873E4 → 0x1EDADE88)
8045 <0x0C7A6B28> ID3D11Device::CreateUnorderedAccessView(0x1EDAE5C0, 0x1C19F2E8, 0x105873C4 → 0x1EDADF90)
8053 <0x0C802FD8> ID3D11DeviceContext::OMSetRenderTargets(1, 0x1C19F330 → { 0x1EDADE88 }, 0x1EDADFE8)
8055 <0x0C802FD8> ID3D11DeviceContext::ClearRenderTargetView(0x1EDADE88, 0x1A74E680)
8065 <0x0C802FD8> ID3D11DeviceContext::OMSetRenderTargetsAndUnorderedAccessViews(1, 0x1C19F330 → { 0x1EDCB3C8 }, 0x1EDCB4D0, 1, 2, 0x1C19F320 → { 0x1EDADF90, NULL }, 0x1C19F370 → { 0, 0 })
8096 <0x0C802FD8> ID3D11DeviceContext:
rawIndexed(36, 0, 0)
8170 <0x0C802FD8> ID3D11DeviceContext::OMSetRenderTargetsAndUnorderedAccessViews(1, 0x1C19F330 → { 0x1EDADE88 }, 0x1EDADFE8, 1, 2, 0x1C19F320 → { 0x1EDADF90, NULL }, 0x1C19F370 → { 0, 0 })
8173 <0x0C802FD8> ID3D11DeviceContext::OMSetRenderTargets(1, 0x1C19F35C → { 0x1EDADE88 }, 0x1EDADFE8)
8252 <0x0C802FD8> ID3D11DeviceContext::OMSetRenderTargets(1, 0x1C19F330 → { 0x0C846198 }, 0x0C8462A0)
8718 <0x0C802FD8> ID3D11DeviceContext::OMSetRenderTargets(1, 0x1C19F338 → { 0x1EDCB3C8 }, 0x1EDCB4D0)
8720 <0x0C802FD8> ID3D11DeviceContext::OMSetRenderTargets(1, 0x1C19F330 → { 0x1EDCB3C8 }, 0x1EDCB4D0)
9183 <0x0C802FD8> ID3D11DeviceContext:
rawIndexed(36, 0, 0)
There are two things here I don’t understand and find curious:
-
OMSetRenderTargets is set many times after the first frame, but OMSetRenderTargetsAndUnorderedAccessViews is not. When I read the docs on OMSetRenderTargetsAndUnorderedAccessViews and OMSetRenderTargets, they appear to be setting the same resources (there are 8 possible slots, shared between render targets and UAV). That is, OMSetRenderTargets would appear to possibly kill any UAV. Or, at least I saw nothing indicating what the exact interaction was between OMSetRenderTargets andOMSetRenderTargetsAndUnorderedAccessViews, which makes me suspicious that if you call one, the settings of the other may not be defined?
-
Event 8173 is a curious one. It sets both a color target and a depth target. But isn’t the color target the same one as the 1x1 texture target view? And this is right before rendering the GUI stuff?? Maybe the render state is such that this doesn’t matter (maybe color writes are disabled?), but according to the MSDN docs, whenever a render target is set using a view that overlaps a UAV, the UAV gets set to NULL and reads as black. And this sounds mighty familiar.
Does this make any sense to you? I’m no DX expert, so I could totally be missing something - but still, at first glance it looks like Unity might be doing something wonky here…
Ben