diff --git a/BUILD.gn b/BUILD.gn index a6da1bd4f32de2ede7fd910b39a5a7bb25c7366b..1f50018866ae99cddb52da32b177aa238d71ff17 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -100,6 +100,7 @@ shared_library("vulkan_goldfish") { deps = [ "//zircon/public/fidl/fuchsia-hardware-goldfish-address-space:fuchsia-hardware-goldfish-address-space_c", + "//zircon/public/fidl/fuchsia-hardware-goldfish-control:fuchsia-hardware-goldfish-control_c", "//zircon/public/fidl/fuchsia-sysmem", "//zircon/public/lib/fdio", "//zircon/public/lib/trace", diff --git a/system/vulkan/goldfish_vulkan.cpp b/system/vulkan/goldfish_vulkan.cpp index 4539c1b6849c506af47f1b6ed55b36762a2082d8..bf170e1cd9390b075884d32e48bbbb23fc37c8c4 100644 --- a/system/vulkan/goldfish_vulkan.cpp +++ b/system/vulkan/goldfish_vulkan.cpp @@ -569,20 +569,7 @@ int OpenDevice(const hw_module_t* /*module*/, class VulkanDevice { public: VulkanDevice() { - goldfish_vk::ResourceTracker::get()->setColorBufferFunctions( - [](uint32_t width, uint32_t height, uint32_t format) { - VK_HOST_CONNECTION((uint32_t)0) - uint32_t r = rcEnc->rcCreateColorBuffer(rcEnc, width, height, format); - return r; - }, - [](uint32_t id) { - VK_HOST_CONNECTION() - rcEnc->rcOpenColorBuffer(rcEnc, id); - }, - [](uint32_t id){ - VK_HOST_CONNECTION() - rcEnc->rcCloseColorBuffer(rcEnc, id); - }); + goldfish_vk::ResourceTracker::get(); } static VulkanDevice& GetInstance() { diff --git a/system/vulkan_enc/AndroidHardwareBuffer.cpp b/system/vulkan_enc/AndroidHardwareBuffer.cpp index a4478306863e15006d8e578f92edce2a8a7cbe59..05f14f1f3a3f9246592492a7dd94cd8c73c7f0d1 100644 --- a/system/vulkan_enc/AndroidHardwareBuffer.cpp +++ b/system/vulkan_enc/AndroidHardwareBuffer.cpp @@ -67,7 +67,7 @@ VkResult getAndroidHardwareBufferPropertiesANDROID( AHardwareBuffer_Desc desc; AHardwareBuffer_describe(buffer, &desc); - uint64_t gpu_usage = + const uint64_t gpu_usage = AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE | AHARDWAREBUFFER_USAGE_GPU_COLOR_OUTPUT | AHARDWAREBUFFER_USAGE_GPU_DATA_BUFFER; @@ -76,10 +76,8 @@ VkResult getAndroidHardwareBufferPropertiesANDROID( return VK_ERROR_INVALID_EXTERNAL_HANDLE; } - ahbFormatProps->format = - vk_format_from_android(desc.format); - - ahbFormatProps->externalFormat = VK_FORMAT_G8B8G8R8_422_UNORM; + ahbFormatProps->format = VK_FORMAT_UNDEFINED; + ahbFormatProps->externalFormat = desc.format; // The formatFeatures member must include // VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT and at least one of diff --git a/system/vulkan_enc/ResourceTracker.cpp b/system/vulkan_enc/ResourceTracker.cpp index 36c2a6b9a03f54de863323b264f2aa4b7ed7fcfb..631f24d1a1cceeed1420f6e1adf620e5cb88b9cc 100644 --- a/system/vulkan_enc/ResourceTracker.cpp +++ b/system/vulkan_enc/ResourceTracker.cpp @@ -58,6 +58,7 @@ typedef struct VkImportMemoryBufferCollectionFUCHSIA { #ifdef VK_USE_PLATFORM_FUCHSIA #include <cutils/native_handle.h> +#include <fuchsia/hardware/goldfish/control/c/fidl.h> #include <fuchsia/sysmem/cpp/fidl.h> #include <lib/fdio/directory.h> #include <lib/fdio/fd.h> @@ -272,7 +273,6 @@ public: SubAlloc subAlloc; AHardwareBuffer* ahw = nullptr; zx_handle_t vmoHandle = ZX_HANDLE_INVALID; - uint32_t cbHandle = 0; }; // custom guest-side structs for images/buffers because of AHardwareBuffer :(( @@ -284,7 +284,6 @@ public: VkDeviceMemory currentBacking = VK_NULL_HANDLE; VkDeviceSize currentBackingOffset = 0; VkDeviceSize currentBackingSize = 0; - uint32_t cbHandle = 0; }; struct VkBuffer_Info { @@ -363,10 +362,6 @@ public: AHardwareBuffer_release(memInfo.ahw); } - if (memInfo.cbHandle) { - (*mCloseColorBuffer)(memInfo.cbHandle); - } - if (memInfo.vmoHandle != ZX_HANDLE_INVALID) { zx_handle_close(memInfo.vmoHandle); } @@ -393,9 +388,6 @@ public: if (it == info_VkImage.end()) return; auto& imageInfo = it->second; - if (imageInfo.cbHandle) { - (*mCloseColorBuffer)(imageInfo.cbHandle); - } info_VkImage.erase(img); } @@ -478,8 +470,7 @@ public: uint8_t* ptr, uint32_t memoryTypeIndex, AHardwareBuffer* ahw = nullptr, - zx_handle_t vmoHandle = ZX_HANDLE_INVALID, - uint32_t cbHandle = 0) { + zx_handle_t vmoHandle = ZX_HANDLE_INVALID) { AutoLock lock(mLock); auto& deviceInfo = info_VkDevice[device]; auto& info = info_VkDeviceMemory[memory]; @@ -490,7 +481,6 @@ public: info.memoryTypeIndex = memoryTypeIndex; info.ahw = ahw; info.vmoHandle = vmoHandle; - info.cbHandle = cbHandle; } void setImageInfo(VkImage image, @@ -574,11 +564,24 @@ public: } #ifdef VK_USE_PLATFORM_FUCHSIA - zx_status_t status = fdio_service_connect( - "/svc/fuchsia.sysmem.Allocator", - mSysmemAllocator.NewRequest().TakeChannel().release()); - if (status != ZX_OK) { - ALOGE("failed to connect to sysmem service, status %d", status); + if (mFeatureInfo->hasVulkan) { + int fd = open("/dev/class/goldfish-control/000", O_RDWR); + if (fd < 0) { + ALOGE("failed to open control device"); + abort(); + } + zx_status_t status = fdio_get_service_handle(fd, &mControlDevice); + if (status != ZX_OK) { + ALOGE("failed to get control service handle, status %d", status); + abort(); + } + status = fuchsia_hardware_goldfish_control_DeviceConnectSysmem( + mControlDevice, + mSysmemAllocator.NewRequest().TakeChannel().release()); + if (status != ZX_OK) { + ALOGE("failed to get sysmem connection, status %d", status); + abort(); + } } #endif } @@ -620,14 +623,6 @@ public: return -1; } - void setColorBufferFunctions(PFN_CreateColorBuffer create, - PFN_OpenColorBuffer open, - PFN_CloseColorBuffer close) { - mCreateColorBuffer = create; - mOpenColorBuffer = open; - mCloseColorBuffer = close; - } - void deviceMemoryTransform_tohost( VkDeviceMemory* memory, uint32_t memoryCount, VkDeviceSize* offset, uint32_t offsetCount, @@ -1318,10 +1313,9 @@ public: delete sysmem_collection; } - VkResult on_vkSetBufferCollectionConstraintsFUCHSIA( - void*, VkResult, VkDevice, - VkBufferCollectionFUCHSIA collection, - const VkImageCreateInfo* pImageInfo) { + void setBufferCollectionConstraints(fuchsia::sysmem::BufferCollectionSyncPtr* collection, + const VkImageCreateInfo* pImageInfo, + size_t min_size_bytes) { fuchsia::sysmem::BufferCollectionConstraints constraints = {}; constraints.usage.vulkan = fuchsia::sysmem::vulkanUsageColorAttachment | fuchsia::sysmem::vulkanUsageTransferSrc | @@ -1331,13 +1325,14 @@ public: constraints.has_buffer_memory_constraints = true; fuchsia::sysmem::BufferMemoryConstraints& buffer_constraints = constraints.buffer_memory_constraints; - buffer_constraints.min_size_bytes = pImageInfo->extent.width * pImageInfo->extent.height * 4; + buffer_constraints.min_size_bytes = min_size_bytes; buffer_constraints.max_size_bytes = 0xffffffff; buffer_constraints.physically_contiguous_required = false; buffer_constraints.secure_required = false; buffer_constraints.secure_permitted = false; - buffer_constraints.ram_domain_supported = true; + buffer_constraints.ram_domain_supported = false; buffer_constraints.cpu_domain_supported = false; + buffer_constraints.gpu_domain_supported = true; constraints.image_format_constraints_count = 1; fuchsia::sysmem::ImageFormatConstraints& image_constraints = constraints.image_format_constraints[0]; @@ -1359,8 +1354,18 @@ public: image_constraints.display_width_divisor = 1; image_constraints.display_height_divisor = 1; - auto sysmem_collection = reinterpret_cast<fuchsia::sysmem::BufferCollectionSyncPtr*>(collection); - (*sysmem_collection)->SetConstraints(true, constraints); + (*collection)->SetConstraints(true, constraints); + } + + VkResult on_vkSetBufferCollectionConstraintsFUCHSIA( + void*, VkResult, VkDevice, + VkBufferCollectionFUCHSIA collection, + const VkImageCreateInfo* pImageInfo) { + auto sysmem_collection = + reinterpret_cast<fuchsia::sysmem::BufferCollectionSyncPtr*>(collection); + setBufferCollectionConstraints( + sysmem_collection, pImageInfo, + pImageInfo->extent.width * pImageInfo->extent.height * 4); return VK_SUCCESS; } @@ -1613,8 +1618,6 @@ public: // and then we attach a new VkDeviceMemory // to the AHardwareBuffer on the host via an "import" operation. AHardwareBuffer* ahw = nullptr; - zx_handle_t vmo_handle = ZX_HANDLE_INVALID; - uint32_t cbHandle = 0; if (exportAllocateInfoPtr) { exportAhb = @@ -1709,6 +1712,8 @@ public: vk_append_struct(structChain, (vk_struct_common*)(&importCbInfo)); } + zx_handle_t vmo_handle = ZX_HANDLE_INVALID; + if (importBufferCollection) { #ifdef VK_USE_PLATFORM_FUCHSIA @@ -1735,35 +1740,105 @@ public: vmo_handle = importVmoInfoPtr->handle; } - if (vmo_handle != ZX_HANDLE_INVALID) { - uint32_t cb = 0; - #ifdef VK_USE_PLATFORM_FUCHSIA - // TODO(reveman): Remove use of zx_vmo_read. Goldfish FIDL interface - // should provide a mechanism to query the color buffer ID associated - // with a VMO. - zx_status_t status = zx_vmo_read(vmo_handle, &cb, 0, sizeof(cb)); - if (status != ZX_OK) { - ALOGE("failed to read color buffer name"); - return VK_ERROR_INITIALIZATION_FAILED; + if (vmo_handle == ZX_HANDLE_INVALID && + !isHostVisibleMemoryTypeIndexForGuest( + &mHostVisibleMemoryVirtInfo, finalAllocInfo.memoryTypeIndex)) { + bool hasDedicatedImage = dedicatedAllocInfoPtr && + (dedicatedAllocInfoPtr->image != VK_NULL_HANDLE); + VkImageCreateInfo imageCreateInfo = {}; + + if (hasDedicatedImage) { + AutoLock lock(mLock); + + auto it = info_VkImage.find(dedicatedAllocInfoPtr->image); + if (it == info_VkImage.end()) return VK_ERROR_INITIALIZATION_FAILED; + const auto& imageInfo = it->second; + + imageCreateInfo = imageInfo.createInfo; } -#endif - if (cb) { - cbHandle = importCbInfo.colorBuffer = cb; - structChain = - vk_append_struct(structChain, (vk_struct_common*)(&importCbInfo)); + if (imageCreateInfo.usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) { + fuchsia::sysmem::BufferCollectionTokenSyncPtr token; + zx_status_t status = mSysmemAllocator->AllocateSharedCollection( + token.NewRequest()); + if (status != ZX_OK) { + ALOGE("AllocateSharedCollection failed: %d", status); + abort(); + } + + fuchsia::sysmem::BufferCollectionSyncPtr collection; + status = mSysmemAllocator->BindSharedCollection( + std::move(token), collection.NewRequest()); + if (status != ZX_OK) { + ALOGE("BindSharedCollection failed: %d", status); + abort(); + } + setBufferCollectionConstraints(&collection, + &imageCreateInfo, + finalAllocInfo.allocationSize); + + fuchsia::sysmem::BufferCollectionInfo_2 info; + zx_status_t status2; + status = collection->WaitForBuffersAllocated(&status2, &info); + if (status == ZX_OK && status2 == ZX_OK) { + if (!info.buffer_count) { + ALOGE("WaitForBuffersAllocated returned invalid count: %d", status); + abort(); + } + vmo_handle = info.buffers[0].vmo.release(); + } else { + ALOGE("WaitForBuffersAllocated failed: %d %d", status, status2); + abort(); + } + + collection->Close(); + + zx_handle_t vmo_copy; + status = zx_handle_duplicate(vmo_handle, ZX_RIGHT_SAME_RIGHTS, &vmo_copy); + if (status != ZX_OK) { + ALOGE("Failed to duplicate VMO: %d", status); + abort(); + } + status = fuchsia_hardware_goldfish_control_DeviceCreateColorBuffer( + mControlDevice, + vmo_copy, + imageCreateInfo.extent.width, + imageCreateInfo.extent.height, + fuchsia_hardware_goldfish_control_FormatType_BGRA, + &status2); + if (status != ZX_OK || status2 != ZX_OK) { + ALOGE("CreateColorBuffer failed: %d:%d", status, status2); + abort(); + } + } + } + + if (vmo_handle != ZX_HANDLE_INVALID) { + zx_handle_t vmo_copy; + zx_status_t status = zx_handle_duplicate(vmo_handle, + ZX_RIGHT_SAME_RIGHTS, + &vmo_copy); + if (status != ZX_OK) { + ALOGE("Failed to duplicate VMO: %d", status); + abort(); } + zx_status_t status2 = ZX_OK; + status = fuchsia_hardware_goldfish_control_DeviceGetColorBuffer( + mControlDevice, vmo_copy, &status2, &importCbInfo.colorBuffer); + if (status != ZX_OK || status2 != ZX_OK) { + ALOGE("GetColorBuffer failed: %d:%d", status, status2); + } + structChain = + vk_append_struct(structChain, (vk_struct_common*)(&importCbInfo)); } +#endif // TODO if (exportVmo) { } if (!isHostVisibleMemoryTypeIndexForGuest( &mHostVisibleMemoryVirtInfo, finalAllocInfo.memoryTypeIndex)) { - if (cbHandle) { - (*mOpenColorBuffer)(cbHandle); - } input_result = enc->vkAllocateMemory( device, &finalAllocInfo, pAllocator, pMemory); @@ -1777,8 +1852,7 @@ public: 0, nullptr, finalAllocInfo.memoryTypeIndex, ahw, - vmo_handle, - cbHandle); + vmo_handle); return VK_SUCCESS; } @@ -2101,8 +2175,6 @@ public: VkImage *pImage) { VkEncoder* enc = (VkEncoder*)context; - uint32_t cbHandle = 0; - VkImageCreateInfo localCreateInfo = *pCreateInfo; VkNativeBufferANDROID localAnb; VkExternalMemoryImageCreateInfo localExtImgCi; @@ -2142,12 +2214,6 @@ public: #endif #ifdef VK_USE_PLATFORM_FUCHSIA - VkFuchsiaImageFormatFUCHSIA* extFuchsiaImageFormatPtr = - (VkFuchsiaImageFormatFUCHSIA*) - vk_find_struct( - (vk_struct_common*)pCreateInfo_mut, - VK_STRUCTURE_TYPE_FUCHSIA_IMAGE_FORMAT_FUCHSIA); - VkBufferCollectionImageCreateInfoFUCHSIA* extBufferCollectionPtr = (VkBufferCollectionImageCreateInfoFUCHSIA*) vk_find_struct( @@ -2178,82 +2244,52 @@ public: if (extFormatAndroidPtr->externalFormat) { pCreateInfo_mut->format = vk_format_from_android(extFormatAndroidPtr->externalFormat); + if (pCreateInfo_mut->format == VK_FORMAT_UNDEFINED) + return VK_ERROR_VALIDATION_FAILED_EXT; } } #endif - #ifdef VK_USE_PLATFORM_FUCHSIA - VkNativeBufferANDROID native_info = { - .sType = VK_STRUCTURE_TYPE_NATIVE_BUFFER_ANDROID, - .pNext = NULL, - }; - cb_handle_t native_handle( - 0, 0, 0, 0, 0, 0, 0, 0, 0, FRAMEWORK_FORMAT_GL_COMPATIBLE); - - if (pCreateInfo->usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) { - // Create color buffer. - cbHandle = (*mCreateColorBuffer)(pCreateInfo_mut->extent.width, - pCreateInfo_mut->extent.height, - 0x1908 /*GL_RGBA*/); - native_handle.hostHandle = cbHandle; - native_info.handle = (uint32_t*)&native_handle; - native_info.stride = 0; - native_info.format = 1; // RGBA - native_info.usage = GRALLOC_USAGE_HW_FB; - if (pCreateInfo_mut->pNext) { - abort(); + if (extBufferCollectionPtr) { + auto collection = reinterpret_cast<fuchsia::sysmem::BufferCollectionSyncPtr*>( + extBufferCollectionPtr->collection); + uint32_t index = extBufferCollectionPtr->index; + zx_handle_t vmo_handle = ZX_HANDLE_INVALID; + + fuchsia::sysmem::BufferCollectionInfo_2 info; + zx_status_t status2; + zx_status_t status = (*collection)->WaitForBuffersAllocated(&status2, &info); + if (status == ZX_OK && status2 == ZX_OK) { + if (index < info.buffer_count) { + vmo_handle = info.buffers[index].vmo.release(); + } + } else { + ALOGE("WaitForBuffersAllocated failed: %d %d", status, status2); } - pCreateInfo_mut->pNext = &native_info; - - bool is_physically_contiguous = false; - if (extBufferCollectionPtr) { - auto collection = reinterpret_cast<fuchsia::sysmem::BufferCollectionSyncPtr*>( - extBufferCollectionPtr->collection); - fuchsia::sysmem::BufferCollectionInfo_2 info; - zx_status_t status2; - zx_status_t status = (*collection)->WaitForBuffersAllocated(&status2, &info); - if (status == ZX_OK && status2 == ZX_OK) { - is_physically_contiguous = - info.settings.has_image_format_constraints && - info.settings.buffer_settings.is_physically_contiguous; - } else { - ALOGE("WaitForBuffersAllocated failed: %d %d", status, status2); - } - } else if (extFuchsiaImageFormatPtr) { - auto imageFormat = static_cast<const uint8_t*>( - extFuchsiaImageFormatPtr->imageFormat); - size_t imageFormatSize = - extFuchsiaImageFormatPtr->imageFormatSize; - std::vector<uint8_t> message( - imageFormat, imageFormat + imageFormatSize); - fidl::Message msg(fidl::BytePart(message.data(), - imageFormatSize, - imageFormatSize), - fidl::HandlePart()); - const char* err_msg = nullptr; - zx_status_t status = msg.Decode( - fuchsia::sysmem::SingleBufferSettings::FidlType, &err_msg); - if (status != ZX_OK) { - ALOGE("Invalid SingleBufferSettings: %d %s", status, - err_msg); - abort(); + + if (vmo_handle != ZX_HANDLE_INVALID) { + zx_status_t status2 = ZX_OK; + status = fuchsia_hardware_goldfish_control_DeviceCreateColorBuffer( + mControlDevice, + vmo_handle, + pCreateInfo_mut->extent.width, + pCreateInfo_mut->extent.height, + fuchsia_hardware_goldfish_control_FormatType_BGRA, + &status2); + if (status != ZX_OK || status2 != ZX_OK) { + ALOGE("CreateColorBuffer failed: %d:%d", status, status2); } - fidl::Decoder decoder(std::move(msg)); - fuchsia::sysmem::SingleBufferSettings settings; - fuchsia::sysmem::SingleBufferSettings::Decode( - &decoder, &settings, 0); - is_physically_contiguous = - settings.buffer_settings.is_physically_contiguous; } + } - if (is_physically_contiguous) { - // Replace the local image pCreateInfo_mut format - // with the color buffer format if physically contiguous - // and a potential display layer candidate. - // TODO(reveman): Remove this after adding BGRA color - // buffer support. - pCreateInfo_mut->format = VK_FORMAT_R8G8B8A8_UNORM; + // Allow external memory for all color attachments on fuchsia. + if (pCreateInfo_mut->usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) { + if (!extImgCiPtr) { + localExtImgCi.sType = VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO; + localExtImgCi.pNext = nullptr; + localExtImgCi.handleTypes = ~0; // handle type just needs to be non-zero + extImgCiPtr = &localExtImgCi; } } #endif @@ -2272,7 +2308,6 @@ public: info.device = device; info.createInfo = *pCreateInfo_mut; info.createInfo.pNext = nullptr; - info.cbHandle = cbHandle; if (!extImgCiPtr) return res; @@ -2399,42 +2434,6 @@ public: void* context, VkResult, VkDevice device, VkImage image, VkDeviceMemory memory, VkDeviceSize memoryOffset) { -#ifdef VK_USE_PLATFORM_FUCHSIA - auto imageIt = info_VkImage.find(image); - if (imageIt == info_VkImage.end()) { - return VK_ERROR_INITIALIZATION_FAILED; - } - auto& imageInfo = imageIt->second; - - if (imageInfo.cbHandle) { - auto memoryIt = info_VkDeviceMemory.find(memory); - if (memoryIt == info_VkDeviceMemory.end()) { - return VK_ERROR_INITIALIZATION_FAILED; - } - auto& memoryInfo = memoryIt->second; - - zx_status_t status; - if (memoryInfo.vmoHandle == ZX_HANDLE_INVALID) { - status = zx_vmo_create(memoryInfo.allocationSize, 0, - &memoryInfo.vmoHandle); - if (status != ZX_OK) { - ALOGE("%s: failed to alloc vmo", __func__); - abort(); - } - } - // TODO(reveman): Remove use of zx_vmo_write. Sysmem - // and goldfish pipe driver should manage this association. - status = zx_vmo_write(memoryInfo.vmoHandle, &imageInfo.cbHandle, - 0, sizeof(imageInfo.cbHandle)); - if (status != ZX_OK) { - ALOGE("%s: failed writing color buffer id to vmo", __func__); - abort(); - } - // Color buffer backed images are already bound. - return VK_SUCCESS; - } -#endif - VkEncoder* enc = (VkEncoder*)context; return enc->vkBindImageMemory(device, image, memory, memoryOffset); } @@ -3283,9 +3282,6 @@ private: HostVisibleMemoryVirtualizationInfo mHostVisibleMemoryVirtInfo; std::unique_ptr<EmulatorFeatureInfo> mFeatureInfo; std::unique_ptr<GoldfishAddressSpaceBlockProvider> mGoldfishAddressSpaceBlockProvider; - PFN_CreateColorBuffer mCreateColorBuffer; - PFN_OpenColorBuffer mOpenColorBuffer; - PFN_CloseColorBuffer mCloseColorBuffer; std::vector<VkExtensionProperties> mHostInstanceExtensions; std::vector<VkExtensionProperties> mHostDeviceExtensions; @@ -3293,6 +3289,7 @@ private: int mSyncDeviceFd = -1; #ifdef VK_USE_PLATFORM_FUCHSIA + zx_handle_t mControlDevice = ZX_HANDLE_INVALID; fuchsia::sysmem::AllocatorSyncPtr mSysmemAllocator; #endif }; @@ -3378,13 +3375,6 @@ bool ResourceTracker::hasDeviceExtension(VkDevice device, const std::string &nam return mImpl->hasDeviceExtension(device, name); } -void ResourceTracker::setColorBufferFunctions( - PFN_CreateColorBuffer create, - PFN_OpenColorBuffer open, - PFN_CloseColorBuffer close) { - mImpl->setColorBufferFunctions(create, open, close); -} - VkResult ResourceTracker::on_vkEnumerateInstanceExtensionProperties( void* context, VkResult input_result, diff --git a/system/vulkan_enc/ResourceTracker.h b/system/vulkan_enc/ResourceTracker.h index e3189e4d6f0424d4ea9e4f4ff3ff04a45b9f8908..1f073c8f24897fc8e93b4ee7c74b84ff1e351461 100644 --- a/system/vulkan_enc/ResourceTracker.h +++ b/system/vulkan_enc/ResourceTracker.h @@ -28,10 +28,6 @@ struct EmulatorFeatureInfo; namespace goldfish_vk { -typedef uint32_t (*PFN_CreateColorBuffer)(uint32_t width, uint32_t height, uint32_t format); -typedef void (*PFN_OpenColorBuffer)(uint32_t id); -typedef void (*PFN_CloseColorBuffer)(uint32_t id); - class ResourceTracker { public: ResourceTracker(); @@ -350,9 +346,6 @@ public: uint32_t getApiVersionFromDevice(VkDevice device) const; bool hasInstanceExtension(VkInstance instance, const std::string& name) const; bool hasDeviceExtension(VkDevice instance, const std::string& name) const; - void setColorBufferFunctions(PFN_CreateColorBuffer create, - PFN_OpenColorBuffer open, - PFN_CloseColorBuffer close); // Transforms void deviceMemoryTransform_tohost( diff --git a/system/vulkan_enc/vk_util.h b/system/vulkan_enc/vk_util.h index 0c7f4b9823c13dcd645d74da6557608a7fe4ea36..da394f4ebfc4271b2be790c1c7d1cb89fc05e2c6 100644 --- a/system/vulkan_enc/vk_util.h +++ b/system/vulkan_enc/vk_util.h @@ -26,6 +26,7 @@ /* common inlines and macros for vulkan drivers */ #include <vulkan/vulkan.h> +#include <stdlib.h> struct vk_struct_common { VkStructureType sType; @@ -214,12 +215,29 @@ vk_init_struct_chain(vk_struct_common* start) return start; } +static inline vk_struct_common* +vk_last_struct_chain(vk_struct_common* i) +{ + for (int n = 1000000; n > 0; --n) { + vk_struct_common* next = i->pNext; + if (next) { + i = next; + } else { + return i; + } + } + + ::abort(); // crash on loops in the chain + return NULL; +} + static inline vk_struct_common* vk_append_struct(vk_struct_common* current, vk_struct_common* next) { - current->pNext = next; - next->pNext = nullptr; - return next; + vk_struct_common* last = vk_last_struct_chain(current); + last->pNext = next; + next->pNext = nullptr; + return current; } #endif /* VK_UTIL_H */