All this is taking place in context of a Unity Native Plugin but the question is general.
Is it possible to copy the contents of native mesh buffers on GPU.
Unity exposes native buffer pointers and I have no problem with using them in D3D11 however 12 refuses to cooperate.
Not only I can't copy the contents of the native mesh buffers, I can't seem to even copy a freshly created ComputeBuffer.
I do realize Unity 2021.2 exposes such functionality on the managed side unfortunately I need this in earlier versions.
Code goes as follows:
ID3D12Resource *pSrcBufferHandle = (ID3D12Resource*) srcBufferHandle;
ID3D12Resource *pDstComputeBufferHandle = (ID3D12Resource*) dstComputeBufferHandle;
pGraphicsCommandList->CopyResource(pDstComputeBufferHandle, pSrcBufferHandle);
pGraphicsCommandList->Close();
// states are supposed to be optional. In any case I'm not sure what 'expected' state
// the buffers are in before executing the list.
fenceValue = iD3D12->ExecuteCommandList(pGraphicsCommandList, 0, NULL);
pCommandAllocator->Reset();
pGraphicsCommandList->Reset(pCommandAllocator, nullptr);
// If I try to wait for the fenceValue it simply hangs
// ID3D12Fence *fence = iD3D12->GetFrameFence();
// pFence->SetEventOnCompletion(fenceValue, sD3D12Event);
// WaitForSingleObject(sD3D12Event, INFINITE);
I was also trying to use ResourceBarrier() to change resource states before and after CopyResource() but because I don't know the ‘StateBefore’ of the buffers this had little chance of working.
Is there a way to peek the resource state?
I also tried to create my own fence, queue, and signal that queue in which case executing the list seems to set the expected value on the fence but the dest buffer is still full of zeros. No trace of the data src buffer was initialized with in Unity.