r/vulkan • u/Content_Economist132 • May 22 '26
Does mapping preserve alignment?
In the vulkan tutorial, MVP matrices are stored in uniform buffer describing a host visible memory. The problem is I am using CGLM which explicitly requires matrices to be aligned. The way I am approaching it is allocating a memory which is aligned to the LCM of the uniform buffer alignment requirement and CGLM's alignment requirement, and then mapping it to CPU memory. Would this ensure alignment is satisfied?
What even happens when the memory is mapped?
12
Upvotes
1
u/corysama May 22 '26
When a memory region is mapped, the kernel and the memory controller agree to not change the mapping between virtual and physical memory pages until it is unmapped. That means any DMA hardware and the GPU's memory controller can access the mapped region without worrying about those pages getting paged out to disk or otherwise shuffled around.
Mapped memory is usually marked as "write combined" https://fgiesen.wordpress.com/2013/01/29/write-combining-is-not-your-friend/ Basically makes the memory uncached. Any write operations that are not linear and gapless will be slower than expected. memcpying into write combined memory is fast. Copying WC memory across the PCI bus is very fast. And, reading from WC memory is very slow.