[vulkan] Refactor all custom logic into ResourceTracker
bug: 111137294
Taking new generated code that lets us consolidate all custom logic into
ResourceTracker. Resources.cpp now contains only trivial definitions.
Change-Id: I5f7ef0237004ccb7b7229c9eedc852f7d0490079
diff --git a/system/vulkan_enc/Validation.cpp b/system/vulkan_enc/Validation.cpp
index 7653f76..e50fa27 100644
--- a/system/vulkan_enc/Validation.cpp
+++ b/system/vulkan_enc/Validation.cpp
@@ -14,27 +14,10 @@
#include "Validation.h"
#include "Resources.h"
+#include "ResourceTracker.h"
namespace goldfish_vk {
-static bool is_range_good(const VkMappedMemoryRange& range) {
- const goldfish_VkDeviceMemory* mem =
- as_goldfish_VkDeviceMemory(range.memory);
-
- if (!mem || !mem->ptr) {
- return false;
- }
-
- VkDeviceSize offset = range.offset;
- VkDeviceSize size = range.size;
-
- if (size == VK_WHOLE_SIZE) {
- return offset <= mem->mappedSize;
- };
-
- return offset + size <= mem->mappedSize;
-}
-
VkResult Validation::on_vkFlushMappedMemoryRanges(
void*,
VkResult,
@@ -42,8 +25,10 @@
uint32_t memoryRangeCount,
const VkMappedMemoryRange* pMemoryRanges) {
+ auto resources = ResourceTracker::get();
+
for (uint32_t i = 0; i < memoryRangeCount; ++i) {
- if (!is_range_good(pMemoryRanges[i])) {
+ if (!resources->isValidMemoryRange(pMemoryRanges[i])) {
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
}
@@ -58,8 +43,10 @@
uint32_t memoryRangeCount,
const VkMappedMemoryRange* pMemoryRanges) {
+ auto resources = ResourceTracker::get();
+
for (uint32_t i = 0; i < memoryRangeCount; ++i) {
- if (!is_range_good(pMemoryRanges[i])) {
+ if (!resources->isValidMemoryRange(pMemoryRanges[i])) {
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
}