address_space: Don't reserve space again

This commit is contained in:
raphaelthegreat 2024-06-08 19:10:32 +03:00
parent edaeee194d
commit e9679f8309
2 changed files with 19 additions and 7 deletions

View File

@ -116,6 +116,7 @@ struct AddressSpace::Impl {
void* MapPrivate(VAddr virtual_addr, size_t size, u64 alignment, ULONG prot, void* MapPrivate(VAddr virtual_addr, size_t size, u64 alignment, ULONG prot,
bool no_commit = false) { bool no_commit = false) {
// Map a private allocation // Map a private allocation
PVOID addr = reinterpret_cast<PVOID>(virtual_addr);
MEM_ADDRESS_REQUIREMENTS req{}; MEM_ADDRESS_REQUIREMENTS req{};
MEM_EXTENDED_PARAMETER param{}; MEM_EXTENDED_PARAMETER param{};
// req.LowestStartingAddress = // req.LowestStartingAddress =
@ -129,9 +130,23 @@ struct AddressSpace::Impl {
if (!no_commit) { if (!no_commit) {
alloc_type |= MEM_COMMIT; alloc_type |= MEM_COMMIT;
} }
void* const ptr = VirtualAlloc2(process, reinterpret_cast<PVOID>(virtual_addr), size, // Check if the area has been reserved beforehand (typically for tesselation buffer)
alloc_type, prot, &param, 1); // and in that case don't reserve it again as Windows complains.
if (virtual_addr) {
MEMORY_BASIC_INFORMATION info;
VirtualQuery(addr, &info, sizeof(info));
if (info.State == MEM_RESERVE) {
alloc_type &= ~MEM_RESERVE;
}
}
void* ptr{};
if (virtual_addr) {
ptr = VirtualAlloc2(process, addr, size, alloc_type, prot, NULL, 0);
ASSERT_MSG(ptr && VAddr(ptr) == virtual_addr, "{}", Common::GetLastErrorMsg());
} else {
ptr = VirtualAlloc2(process, nullptr, size, alloc_type, prot, &param, 1);
ASSERT_MSG(ptr, "{}", Common::GetLastErrorMsg()); ASSERT_MSG(ptr, "{}", Common::GetLastErrorMsg());
}
return ptr; return ptr;
} }

View File

@ -92,10 +92,7 @@ int MemoryManager::MapMemory(void** out_addr, VAddr virtual_addr, size_t size, M
it++; it++;
} }
ASSERT(it != vma_map.end()); ASSERT(it != vma_map.end());
if (alignment > 0) { mapped_addr = alignment > 0 ? Common::AlignUp(it->second.base, alignment) : it->second.base;
ASSERT_MSG(it->second.base % alignment == 0, "Free region base is not aligned");
}
mapped_addr = it->second.base;
} }
// Perform the mapping. // Perform the mapping.