Revert "Share the same rendernode for all host memory block"
This reverts commit 85359c376980d6f32c7bb138057cc993b5c58dd9.
Reason for revert: This breaks various emulator targets.
Change-Id: If600d4a4980d72dd8c082fd790dad5c86578ad39
diff --git a/system/vulkan_enc/HostVisibleMemoryVirtualization.cpp b/system/vulkan_enc/HostVisibleMemoryVirtualization.cpp
index 96ab677..e66c951 100644
--- a/system/vulkan_enc/HostVisibleMemoryVirtualization.cpp
+++ b/system/vulkan_enc/HostVisibleMemoryVirtualization.cpp
@@ -28,7 +28,6 @@
#ifdef ANDROID
#include <unistd.h>
#include <errno.h>
-#include <drm/drm.h>
#endif
#include <sys/mman.h>
@@ -262,48 +261,26 @@
VkDevice device,
HostMemAlloc* toDestroy) {
-#ifdef ANDROID
- int rendernodeFd = toDestroy->rendernodeFd;
- if (rendernodeFd >= 0) {
-
- if (toDestroy->memoryAddr) {
- int ret = munmap((void*)toDestroy->memoryAddr, toDestroy->memorySize);
- if (ret != 0) {
- ALOGE("%s: fail to unmap addr = 0x%" PRIx64", size = %d, ret = "
- "%d, errno = %d", __func__, toDestroy->memoryAddr,
- (int32_t)toDestroy->memorySize, ret, errno);
- }
- }
-
- if (toDestroy->boCreated) {
- ALOGV("%s: trying to destroy bo = %u\n", __func__,
- toDestroy->boHandle);
- struct drm_gem_close drmGemClose = {};
- drmGemClose.handle = toDestroy->boHandle;
- int ret = ioctl(rendernodeFd, DRM_IOCTL_GEM_CLOSE, &drmGemClose);
- if (ret != 0) {
- ALOGE("%s: fail to close gem = %u, ret = %d, errno = %d\n",
- __func__, toDestroy->boHandle, ret, errno);
- } else {
- ALOGV("%s: successfully close gem = %u, ret = %d\n", __func__,
- toDestroy->boHandle, ret);
- }
- }
- ALOGV("%s: trying to close fd = %d\n", __func__, rendernodeFd);
- int ret = close(rendernodeFd);
- if (ret != 0) {
- ALOGE("%s: fail to close fd = %d, ret = %d, errno = %d\n", __func__,
- rendernodeFd, ret, errno);
- } else {
- ALOGV("%s: successfully close fd = %d, ret = %d\n", __func__,
- rendernodeFd, ret);
- }
- }
-#endif
-
if (toDestroy->initResult != VK_SUCCESS) return;
if (!toDestroy->initialized) return;
+#ifdef ANDROID
+ if (toDestroy->fd > 0) {
+
+ if (toDestroy->memoryAddr) {
+ int ret = munmap((void*)toDestroy->memoryAddr, toDestroy->memorySize);
+ ALOGE("%s: trying to unmap addr = 0x%" PRIx64", size = %d, ret = %d, errno = %d\n", __func__, toDestroy->memoryAddr, (int32_t)toDestroy->memorySize, ret, errno);
+ }
+
+ ALOGE("%s: trying to close fd = %d\n", __func__, toDestroy->fd);
+ int ret = close(toDestroy->fd);
+ if (ret != 0) {
+ ALOGE("%s: fail to close fd = %d, ret = %d, errno = %d\n", __func__, toDestroy->fd, ret, errno);
+ } else {
+ ALOGE("%s: successfully close fd = %d, ret = %d\n", __func__, toDestroy->fd, ret);
+ }
+ }
+#endif
if (freeMemorySyncSupported) {
enc->vkFreeMemorySyncGOOGLE(device, toDestroy->memory, nullptr, false /* no lock */);
diff --git a/system/vulkan_enc/HostVisibleMemoryVirtualization.h b/system/vulkan_enc/HostVisibleMemoryVirtualization.h
index e3b6dd5..8697206 100644
--- a/system/vulkan_enc/HostVisibleMemoryVirtualization.h
+++ b/system/vulkan_enc/HostVisibleMemoryVirtualization.h
@@ -83,9 +83,7 @@
VkDeviceSize mappedSize = 0;
uint8_t* mappedPtr = nullptr;
android::base::guest::SubAllocator* subAlloc = nullptr;
- int rendernodeFd = -1;
- bool boCreated = false;
- uint32_t boHandle = 0;
+ int fd = -1;
uint64_t memoryAddr = 0;
size_t memorySize = 0;
};
diff --git a/system/vulkan_enc/ResourceTracker.cpp b/system/vulkan_enc/ResourceTracker.cpp
index 7a5b196..81b3fa0 100644
--- a/system/vulkan_enc/ResourceTracker.cpp
+++ b/system/vulkan_enc/ResourceTracker.cpp
@@ -3027,14 +3027,8 @@
#if !defined(HOST_BUILD) && defined(VK_USE_PLATFORM_ANDROID_KHR)
uint64_t hvaSizeId[3];
- int rendernodeFdForMem = dup(mRendernodeFd);
- if (rendernodeFdForMem < 0) {
- ALOGE("%s: Failed to dup rendernode fd(%d): error: %s,"
- "errno: %d", __func__, mRendernodeFd,
- strerror(errno), errno);
- abort();
- }
- hostMemAlloc.rendernodeFd = rendernodeFdForMem;
+ int rendernodeFdForMem = drmOpenRender(128 /* RENDERNODE_MINOR */);
+ ALOGE("%s: render fd = %d\n", __func__, rendernodeFdForMem);
mLock.unlock();
enc->vkGetMemoryHostAddressInfoGOOGLE(
@@ -3060,8 +3054,6 @@
strerror(errno), errno);
abort();
}
- hostMemAlloc.boCreated = true;
- hostMemAlloc.boHandle = drm_rc_blob.bo_handle;
drm_virtgpu_map map_info;
memset(&map_info, 0, sizeof(map_info));
@@ -3087,8 +3079,9 @@
// add the host's page offset
directMappedAddr += (uint64_t)(uintptr_t)(hvaSizeId[0]) & (PAGE_SIZE - 1);
- directMapResult = VK_SUCCESS;
+ directMapResult = VK_SUCCESS;
+ hostMemAlloc.fd = rendernodeFdForMem;
#endif // VK_USE_PLATFORM_ANDROID_KHR
}