Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions core/libs/prx/libSceAgcDriver/Graphics/src/Resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,21 @@
#include "prx/libSceAgcDriver/Execution/include/GuestMemory.hpp"
#include <algorithm>
#include <exception>
#ifdef __APPLE__
#include <cstring>
#endif

namespace AgcDriver::Graphics {

namespace {

#ifdef __APPLE__
void ClearPooledTail(void* mapping, std::size_t size, VkDeviceSize mappedBytes, VkMemoryPropertyFlags properties) {
if (mapping == nullptr || (properties & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) == 0 || mappedBytes <= size) return;
std::memset(static_cast<std::byte*>(mapping) + size, 0, static_cast<std::size_t>(mappedBytes - size));
}

#endif
VkDeviceSize ClassAllocationBytes(const VkMemoryRequirements& requirements, std::size_t capacity) {
const auto alignment = std::max<VkDeviceSize>(requirements.alignment, 1);
return std::max<VkDeviceSize>(requirements.size, (static_cast<VkDeviceSize>(capacity) + alignment - 1) / alignment * alignment);
Expand Down Expand Up @@ -52,6 +62,9 @@ Buffer::Buffer(const Context& context, std::size_t size, VkBufferUsageFlags usag
capacity = allocation->bytes;
offset = allocation->offset;
slab = allocation->slab;
#ifdef __APPLE__
ClearPooledTail(mapping, size, std::min<VkDeviceSize>(capacity, allocationBytes), properties);
#endif
if (allocation->bufferBytes != size) {
context.Function<PFN_vkDestroyBuffer>("vkDestroyBuffer")(context.device, buffer, nullptr);
buffer = VK_NULL_HANDLE;
Expand Down Expand Up @@ -93,6 +106,9 @@ Buffer::Buffer(const Context& context, std::size_t size, VkBufferUsageFlags usag
Check(context.Function<PFN_vkBindBufferMemory>("vkBindBufferMemory")(context.device, buffer, memory, offset), "vkBindBufferMemory slab");
initializeAddress(usage);
mapping = slot.mapping;
#ifdef __APPLE__
ClearPooledTail(mapping, size, capacity, properties);
#endif
ready = true;
return;
}
Expand Down
Loading