3

Can native vertex buffer be copied from on GPU using native plugin interface?

I'm asking specifically about directx12, vulkan, metal as I know for certain this can be done with directx11. Furthermore, I only ask about Unity versions prior to 2021.2.

Can I use APIs like:

ID3D12GraphicsCommandList::CopyResource

or

ID3D12GraphicsCommandList::CopyBufferRegion

in case of directx12,

or

vkCmdCopyBuffer

in case of vulkan, or is it strictly not doable no mater what ResourceBarrier (dx12) or AccessMode (vulkan) I'd try to apply to the resource.

I did try running some test code using unity's provided command queue as well as creating my own copy queue but nothing happens. I can only suspect it's something about the resource state of the native buffers but I have no way to be sure.

Because Unity don't publish any info as far as initial Resource States (StateBefore) of the native mesh buffers not to mention any info about what can actually be done with the pointers obtained from GetNativeVertexBufferPtr() depending on current GraphicsDeviceType (other than simple example @github) I felt like I have to resort to posting these kind of questions.

EDIT I will try to provide more details as required

I'm trying to achieve similar functionality as the one provided by Graphics.CopyBuffer() in Unity 2021.2+ just for Unity version prior to that one.

I want to copy the contents of the buffer as pointed to by the pointer returned from Mesh.GetNativeVertexBufferPtr() to say a buffer returned from GraphicsBuffer.GetNativeBufferPtr() or ComputeBuffer.GetNativeBufferPtr(). (Buffers do have matching sizes and strides).

It is important to not use any methods that would fetch this data back to the managed memory but rather to do it directly on GPU.

I already managed to do this for DirectX11 using a native plugin using this interface:

Github - Unity-Technologies/NativeRenderingPlugin

but when I tried doing this for DirectX12 or Vulkan using methods mentioned above I couldn't do it. Because Unity online Manuals and Comments in the example plugin code base provide little assistance I wasn't able to guess what could be the problem.

Does anyone know for certain if this sort of thing can be done at all or am I trying to do something absolutely impossible with the way Unity configures the native buffers of their meshes?

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
gregee123
  • 321
  • 3
  • 6

0 Answers0