I've noticed that buffers allocated with GL_MAP_WRITE_BIT or GL_MAP_READ_BIT end up in HOST memory. Example:
uint32_t size = 1 << 22; // 4MiB
uint32_t buf;
glCreateBuffers(1, &buf);
glNamedBufferStorage(buf, size, nullptr, GL_MAP_PERSISTENT_BIT | GL_MAP_WRITE_BIT);
//glMapNamedBufferRange(buf, 0, size, GL_MAP_PERSISTENT_BIT | GL_MAP_WRITE_BIT); // not needed to reproduceIt happens with any other additional combination of flags too.
What's interersting is that the memory report of a RX 5700 XT
shows a 256MiB DEVICE_LOCAL_BIT | HOST_VISIBLE_BIT | HOST_COHERENT_BIT heap. So at least in theory I think it should be
possible to place the buffer in DEVICE memory. This is with ReBAR/SAM disabled.
In an attempt to "fix" that behaviour I enabled ReBar/SAM. With it the above buffer actually goes into DEVICE memory!
Unfortunately when either the GL_MAP_READ_BIT or GL_MAP_COHERENT_BIT flag are used its back to HOST memory.
The memory report for my RX 5700 XT with ReBar/SAM enabled shows Memory Heap 1
exposing all 8GiB of VRAM with DEVICE_LOCAL_BIT | HOST_VISIBLE_BIT | HOST_COHERENT_BIT.
So my questions are:
- With ReBAR/SAM, why does the
GL_MAP_READ_BITorGL_MAP_COHERENT_BITflag in particular cause mapped buffers to go into HOST memory? - Without ReBAR/SAM, why do mapped buffers go into HOST memory?
For performance reasons it would be nice if DEVICE memory was prioritised since I did not specify GL_CLIENT_STORAGE_BIT.