Hello Guest

Map Memory question + Android Question

  • 1 Replies
  • 41 Views
Map Memory question + Android Question
« on: December 06, 2018, 08:48:40 »
I am converting my opengl code to vulkan (going pretty well so far) but I have a couple of questions

1) The below is a selection of the triangle demo code. specifically from the createVertices method. My question is around the map and unmap, I am coming from a setup in opengl where I had a persistent mapped buffer and during that setup I got a ByteBuffer which I could edit directly which would then update the data on the GPU. The example below maps GPU memory to memory accessible by the CPU, the CPU accessible memory is indexed by a pointer, you then copy your data using the MemoryUtil class and then unmap. The actual question is, is it possible to get a ByteBuffer from pData so I don't need use MemoryUtils (can just write directly) and can keep the map memory open so I can make frequent updates. I might be missing something obvious but I thought I would ask. If you need to do this, what is the general best practise for updating segments of the vertex buffer?

Code: [Select]
PointerBuffer pData = memAllocPointer(1);
        err = vkMapMemory(device, verticesMem, 0, memAlloc.allocationSize(), 0, pData);
        memAlloc.free();
        long data = pData.get(0);
        memFree(pData);
        if (err != VK_SUCCESS) {
            throw new AssertionError("Failed to map vertex memory: " + translateVulkanResult(err));
        }

        MemoryUtil.memCopy(memAddress(vertexBuffer), data, vertexBuffer.remaining());
        memFree(vertexBuffer);
        vkUnmapMemory(device, verticesMem);

2) Did I read somewhere there were Android bindings somewhere for Vulkan? Would the java code be exaclty the same from a porting perspective?

*

Offline elect

  • *
  • 18
Re: Map Memory question + Android Question
« Reply #1 on: December 07, 2018, 09:02:15 »
The actual question is, is it possible to get a ByteBuffer from pData so I don't need use MemoryUtils (can just write directly) and can keep the map memory open so I can make frequent updates

You can

Code: [Select]
MemoryUtil.memByteBuffer(pData.get(0), memAlloc.allocationSize())
Although I'd keep using the
Code: [Select]
memCopy because it's a native single call and thus shall be faster than copying byte by byte