Merge remote-tracking branch 'origin/master' into claude/issue-47

# Conflicts:
#	project.cpp
This commit is contained in:
catbot 2026-06-16 17:10:39 +00:00
commit c670bc70b7
3 changed files with 144 additions and 9 deletions

View file

@ -35,6 +35,11 @@ namespace Crafter {
std::uint32_t size;
VkBuffer buffer = VK_NULL_HANDLE;
VkDeviceMemory memory;
// Property flags of the memory type actually chosen by GetMemoryType —
// not the requested flags. GetMemoryType may land a request without the
// COHERENT bit on a coherent type (and vice versa), so the flush/
// invalidate paths gate on this recorded value, never on the request.
VkMemoryPropertyFlags memoryPropertyFlagsChosen = 0;
};
export template<typename T>
@ -79,10 +84,12 @@ namespace Crafter {
VkMemoryRequirements memReqs;
vkGetBufferMemoryRequirements(Device::device, buffer, &memReqs);
std::uint32_t memoryTypeIndex = Device::GetMemoryType(memReqs.memoryTypeBits, memoryPropertyFlags, preferredPropertyFlags);
memoryPropertyFlagsChosen = Device::memoryProperties.memoryTypes[memoryTypeIndex].propertyFlags;
VkMemoryAllocateInfo memAlloc {
.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
.allocationSize = memReqs.size,
.memoryTypeIndex = Device::GetMemoryType(memReqs.memoryTypeBits, memoryPropertyFlags, preferredPropertyFlags)
.memoryTypeIndex = memoryTypeIndex
};
VkMemoryAllocateFlagsInfoKHR allocFlagsInfo {
@ -163,6 +170,11 @@ namespace Crafter {
}
void FlushDevice() requires(Mapped) {
// Coherent memory needs no explicit flush — host writes are
// automatically visible to the device.
if (memoryPropertyFlagsChosen & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) {
return;
}
VkMappedMemoryRange range = {
.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE,
.memory = memory,
@ -197,6 +209,11 @@ namespace Crafter {
}
void FlushHost() requires(Mapped) {
// Coherent memory needs no explicit invalidate — device writes are
// automatically visible to the host.
if (memoryPropertyFlagsChosen & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) {
return;
}
VkMappedMemoryRange range = {
.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE,
.memory = memory,
@ -210,6 +227,7 @@ namespace Crafter {
buffer = other.buffer;
memory = other.memory;
size = other.size;
memoryPropertyFlagsChosen = other.memoryPropertyFlagsChosen;
other.buffer = VK_NULL_HANDLE;
address = other.address;
if constexpr(Mapped) {