permanently map host-visible buffers

pull/50/head
cosmonaut 2024-02-16 18:51:09 -08:00
parent a0414d0a4f
commit 74f26e605d
1 changed files with 20 additions and 54 deletions

View File

@ -449,6 +449,7 @@ struct VulkanMemoryAllocation
uint8_t availableForAllocation; uint8_t availableForAllocation;
VkDeviceSize freeSpace; VkDeviceSize freeSpace;
VkDeviceSize usedSpace; VkDeviceSize usedSpace;
uint8_t *mapPointer;
SDL_mutex *memoryLock; SDL_mutex *memoryLock;
}; };
@ -745,7 +746,6 @@ typedef struct VulkanUniformBufferObject
VkDescriptorSet descriptorSet; VkDescriptorSet descriptorSet;
VulkanBuffer *buffer; VulkanBuffer *buffer;
uint32_t currentOffset; uint32_t currentOffset;
uint8_t *mapPointer; /* uniform buffers are permanently mapped */
SDL_mutex *lock; SDL_mutex *lock;
} VulkanUniformBufferObject; } VulkanUniformBufferObject;
@ -2552,6 +2552,24 @@ static uint8_t VULKAN_INTERNAL_AllocateMemory(
return 0; return 0;
} }
/* Persistent mapping for host-visible memory */
if (isHostVisible)
{
result = renderer->vkMapMemory(
renderer->logicalDevice,
allocation->memory,
0,
VK_WHOLE_SIZE,
0,
(void**) &allocation->mapPointer
);
VULKAN_ERROR_CHECK(result, vkMapMemory, 0)
}
else
{
allocation->mapPointer = NULL;
}
VULKAN_INTERNAL_NewMemoryFreeRegion( VULKAN_INTERNAL_NewMemoryFreeRegion(
renderer, renderer,
allocation, allocation,
@ -4300,16 +4318,6 @@ static VulkanUniformBufferObject* VULKAN_INTERNAL_CreateUniformBufferObject(
NULL NULL
); );
/* Permanently map the memory */
renderer->vkMapMemory(
renderer->logicalDevice,
uniformBufferObject->buffer->usedRegion->allocation->memory,
0,
VK_WHOLE_SIZE,
0,
(void**) &uniformBufferObject->mapPointer
);
return uniformBufferObject; return uniformBufferObject;
} }
@ -4354,11 +4362,6 @@ static void VULKAN_INTERNAL_DestroyUniformBufferObject(
VulkanRenderer *renderer, VulkanRenderer *renderer,
VulkanUniformBufferObject *uniformBufferObject VulkanUniformBufferObject *uniformBufferObject
) { ) {
renderer->vkUnmapMemory(
renderer->logicalDevice,
uniformBufferObject->buffer->usedRegion->allocation->memory
);
VULKAN_INTERNAL_DestroyBuffer(renderer, uniformBufferObject->buffer); VULKAN_INTERNAL_DestroyBuffer(renderer, uniformBufferObject->buffer);
SDL_DestroyMutex(uniformBufferObject->lock); SDL_DestroyMutex(uniformBufferObject->lock);
@ -6843,7 +6846,7 @@ static void VULKAN_INTERNAL_SetUniformBufferData(
uint32_t dataLength uint32_t dataLength
) { ) {
uint8_t *dst = uint8_t *dst =
uniformBufferObject->mapPointer + uniformBufferObject->buffer->usedRegion->allocation->mapPointer +
uniformBufferObject->buffer->usedRegion->resourceOffset + uniformBufferObject->buffer->usedRegion->resourceOffset +
uniformBufferObject->currentOffset; uniformBufferObject->currentOffset;
@ -8336,43 +8339,6 @@ static void VULKAN_EndComputePass(
vulkanCommandBuffer->currentComputePipeline = NULL; vulkanCommandBuffer->currentComputePipeline = NULL;
} }
static void* VULKAN_MapCpuBuffer(
Refresh_Renderer *driverData,
Refresh_CpuBuffer *buffer,
uint32_t offsetInBytes,
uint32_t sizeInBytes
) {
VulkanRenderer *renderer = (VulkanRenderer*) driverData;
VulkanBuffer *vulkanBuffer = (VulkanBuffer*) buffer;
VkResult result;
void* mapPointer;
result = renderer->vkMapMemory(
renderer->logicalDevice,
vulkanBuffer->usedRegion->allocation->memory,
offsetInBytes,
sizeInBytes,
0,
&mapPointer
);
VULKAN_ERROR_CHECK(result, vkMapMemory, NULL)
return mapPointer;
}
static void VULKAN_UnmapCpuBuffer(
Refresh_Renderer *driverData,
Refresh_CpuBuffer *buffer
) {
VulkanRenderer *renderer = (VulkanRenderer*) driverData;
VulkanBuffer *vulkanBuffer = (VulkanBuffer*) buffer;
renderer->vkUnmapMemory(
renderer->logicalDevice,
vulkanBuffer->usedRegion->allocation->memory
);
}
static void VULKAN_BeginCopyPass( static void VULKAN_BeginCopyPass(
Refresh_Renderer *driverData, Refresh_Renderer *driverData,
Refresh_CommandBuffer *commandBuffer Refresh_CommandBuffer *commandBuffer