diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-06-07 18:36:43 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2022-06-07 18:36:43 +0000 |
commit | c569c1e731f6444c48ef8e8c4b38f107006b4481 (patch) | |
tree | 13ae4556c37b2155f2db85f08a426e887e931422 | |
parent | 585904efe64e6bef91d64213cf4e657083fd5e95 (diff) | |
parent | bb59a12e88c562e1b2424ebbb7d43af7a7ec6c6e (diff) | |
download | qemu-snap-temp-L88800000955019715.tar.gz |
Merge "Merge cherrypicks of [2081640, 2086165, 2094447, 2098587, 2105307, 2116562] into emu-31-release." into emu-31-releasesnap-temp-L88800000955019715
-rw-r--r-- | android-qemu2-glue/emulation/virtio-goldfish-pipe.cpp | 72 | ||||
-rw-r--r-- | android/android-emugl/host/libs/libOpenglRender/ColorBuffer.cpp | 6 | ||||
-rw-r--r-- | android/android-emugl/host/libs/libOpenglRender/FrameBuffer.cpp | 2 | ||||
-rw-r--r-- | hw/display/virtio-gpu.c | 8 | ||||
-rwxr-xr-x | hw/misc/goldfish_pipe.c | 16 | ||||
-rw-r--r-- | include/qemu/iov.h | 2 |
6 files changed, 67 insertions, 39 deletions
diff --git a/android-qemu2-glue/emulation/virtio-goldfish-pipe.cpp b/android-qemu2-glue/emulation/virtio-goldfish-pipe.cpp index a554132dc5..2e4d018b8f 100644 --- a/android-qemu2-glue/emulation/virtio-goldfish-pipe.cpp +++ b/android-qemu2-glue/emulation/virtio-goldfish-pipe.cpp @@ -329,7 +329,7 @@ static inline uint32_t gl_format_to_natural_type(uint32_t format) { static inline size_t virgl_format_to_linear_base( uint32_t format, uint32_t totalWidth, uint32_t totalHeight, - uint32_t x, uint32_t y, uint32_t w, uint32_t h) { + uint32_t x, uint32_t y) { if (virgl_format_is_yuv(format)) { return 0; } else { @@ -361,15 +361,13 @@ static inline size_t virgl_format_to_linear_base( static inline size_t virgl_format_to_total_xfer_len( uint32_t format, uint32_t totalWidth, uint32_t totalHeight, - uint32_t x, uint32_t y, uint32_t w, uint32_t h) { + uint32_t w, uint32_t h) { if (virgl_format_is_yuv(format)) { - uint32_t yAlign = (format == VIRGL_FORMAT_YV12) ? 32 : 16; uint32_t yWidth = totalWidth; uint32_t yHeight = totalHeight; - uint32_t yStride = align_up_power_of_2(yWidth, yAlign); + uint32_t yStride = yWidth; uint32_t ySize = yStride * yHeight; - uint32_t uvAlign = 16; uint32_t uvWidth; uint32_t uvPlaneCount; @@ -384,7 +382,7 @@ static inline size_t virgl_format_to_total_xfer_len( } uint32_t uvHeight = totalHeight / 2; - uint32_t uvStride = align_up_power_of_2(uvWidth, uvAlign); + uint32_t uvStride = uvWidth; uint32_t uvSize = uvStride * uvHeight * uvPlaneCount; uint32_t dataSize = ySize + uvSize; @@ -443,7 +441,8 @@ static int sync_iov(PipeResEntry* res, uint64_t offset, const virgl_box* box, Io res->args.format, res->args.width, res->args.height, - box->x, box->y, box->w, box->h); + box->x, + box->y); size_t start = linearBase; // height - 1 in order to treat the (w * bpp) row specially // (i.e., the last row does not occupy the full stride) @@ -451,7 +450,8 @@ static int sync_iov(PipeResEntry* res, uint64_t offset, const virgl_box* box, Io res->args.format, res->args.width, res->args.height, - box->x, box->y, box->w, box->h); + box->w, + box->h); size_t end = start + length; if (end > res->linearSize) { @@ -1154,7 +1154,6 @@ public: } VGPLOG("Linear first word: %d", *(int*)(entry.linear)); - auto syncRes = sync_iov(&entry, offset, box, LINEAR_TO_IOV); mLastSubmitCmdCtxExists = true; mLastSubmitCmdCtx = entry.ctxId; @@ -1253,8 +1252,8 @@ public: // Associate the host pipe of the resource entry with the host pipe of // the context entry. That is, the last context to call attachResource // wins if there is any conflict. - auto ctxEntryIt = mContexts.find(ctxId); auto resEntryIt = - mResources.find(resId); + auto ctxEntryIt = mContexts.find(ctxId); + auto resEntryIt = mResources.find(resId); if (ctxEntryIt == mContexts.end() || resEntryIt == mResources.end()) return; @@ -1412,13 +1411,6 @@ public: void saveSnapshot(void* opaque) { QEMUFile* file = (QEMUFile*)opaque; - uint32_t cookie; - if (!mCookie) { - cookie = 0; - } else { - memcpy(&cookie, mCookie, sizeof(uint32_t)); - } - qemu_put_be32(file, cookie); qemu_put_be32(file, mFlags); qemu_put_be32(file, mContexts.size()); @@ -1449,30 +1441,45 @@ public: qemu_put_be32(file, mLastSubmitCmdCtx); saveFenceDeque(file, mFenceDeque); + + auto ops = ensureAndGetServiceOps(); + ops->guest_post_save(file); + } + + void cleanStates() { + auto itContext = mContexts.begin(); + while (itContext != mContexts.end()) { + destroyContext(itContext->first); + itContext = mContexts.begin(); + } + auto itResource = mResources.begin(); + while (itResource != mResources.end()) { + unrefResource(itResource->first); + itResource = mResources.begin(); + } + mContextResources.clear(); + mResourceContexts.clear(); + mFenceDeque.clear(); } void loadSnapshot(void* opaque) { QEMUFile* file = (QEMUFile*)opaque; - uint32_t cookie = qemu_get_be32(file); - if (mCookie) memcpy(mCookie, &cookie, sizeof(uint32_t)); + cleanStates(); mFlags = qemu_get_be32(file); uint32_t contextCount = qemu_get_be32(file); - for (uint32_t i = 0; i < contextCount; ++i) { loadContext(file); } uint32_t resourceCount = qemu_get_be32(file); - for (uint32_t i = 0; i < resourceCount; ++i) { loadResource(file); } uint32_t contextResourceListCount = qemu_get_be32(file); - for (uint32_t i = 0; i < contextResourceListCount; ++i) { uint32_t ctxId; auto ids = loadContextResourceList(file, &ctxId); @@ -1480,7 +1487,6 @@ public: } uint32_t resourceContextListCount = qemu_get_be32(file); - for (uint32_t i = 0; i < resourceContextListCount; ++i) { uint32_t resId; auto ids = loadResourceContextList(file, &resId); @@ -1491,6 +1497,8 @@ public: mLastSubmitCmdCtx = qemu_get_be32(file); loadFenceDeque(file); + auto ops = ensureAndGetServiceOps(); + ops->guest_post_load(file); } void setResourceHvSlot(uint32_t res_handle, uint32_t slot) { @@ -1561,12 +1569,6 @@ private: entry.linearSize = linearSize; entry.addrs = nullptr; - virgl_box initbox; - initbox.x = 0; - initbox.y = 0; - initbox.w = (uint32_t)linearSize; - initbox.h = 1; - if (addrs) { entry.addrs = (uint64_t*)malloc(sizeof(uint64_t) * num_iovs); for (int i = 0; i < num_iovs; ++i) { @@ -1682,7 +1684,6 @@ private: } void loadContext(QEMUFile* file) { - auto ops = ensureAndGetServiceOps(); PipeCtxEntry pipeCtxEntry; @@ -1693,8 +1694,9 @@ private: pipeCtxEntry.hasAddressSpaceHandle = qemu_get_be32(file); char force_close = 1; - void* hwpipe = malloc(sizeof(uint64_t)); - pipeCtxEntry.hostPipe = ops->guest_load(file, (GoldfishHwPipe*)hwpipe, &force_close); + pipeCtxEntry.hostPipe = ops->guest_load(file, + (GoldfishHwPipe*)(uintptr_t)(pipeCtxEntry.ctxId), + &force_close); mContexts[pipeCtxEntry.ctxId] = pipeCtxEntry; } @@ -1747,6 +1749,10 @@ private: // No need to save hva itself or its contents, as that should be // managed by address space device pipeResEntry.ctxId = qemu_get_be32(file); + auto context = mContexts.find(pipeResEntry.ctxId); + if (context != mContexts.end()) { + pipeResEntry.hostPipe = context->second.hostPipe; + } pipeResEntry.hvaSize = qemu_get_be64(file); pipeResEntry.hvaId = qemu_get_be64(file); pipeResEntry.hvSlot = qemu_get_be32(file); diff --git a/android/android-emugl/host/libs/libOpenglRender/ColorBuffer.cpp b/android/android-emugl/host/libs/libOpenglRender/ColorBuffer.cpp index 83870dcf67..fc6e0abee5 100644 --- a/android/android-emugl/host/libs/libOpenglRender/ColorBuffer.cpp +++ b/android/android-emugl/host/libs/libOpenglRender/ColorBuffer.cpp @@ -490,7 +490,6 @@ void ColorBuffer::readPixelsYUVCached(int x, assert(m_yuv_converter.get()); #endif - m_yuv_converter->readPixels((uint8_t*)pixels, pixels_size); return; @@ -1020,13 +1019,10 @@ void ColorBuffer::restore() { switch (m_frameworkFormat) { case FRAMEWORK_FORMAT_GL_COMPATIBLE: break; - case FRAMEWORK_FORMAT_YV12: - case FRAMEWORK_FORMAT_YUV_420_888: + default: // any YUV format m_yuv_converter.reset( new YUVConverter(m_width, m_height, m_frameworkFormat)); break; - default: - break; } } diff --git a/android/android-emugl/host/libs/libOpenglRender/FrameBuffer.cpp b/android/android-emugl/host/libs/libOpenglRender/FrameBuffer.cpp index ed4c81be4f..7204085bda 100644 --- a/android/android-emugl/host/libs/libOpenglRender/FrameBuffer.cpp +++ b/android/android-emugl/host/libs/libOpenglRender/FrameBuffer.cpp @@ -2958,6 +2958,7 @@ void FrameBuffer::onSave(Stream* stream, // information to reconstruct it when loading. System::Duration now = System::get()->getUnixTime(); + stream->putByte(m_guestManagedColorBufferLifetime); saveCollection(stream, m_colorbuffers, [now](Stream* s, const ColorBufferMap::value_type& pair) { pair.second.cb->onSave(s); @@ -3132,6 +3133,7 @@ bool FrameBuffer::onLoad(Stream* stream, assert(!android::base::find(m_contexts, 0)); auto now = System::get()->getUnixTime(); + m_guestManagedColorBufferLifetime = stream->getByte(); loadCollection(stream, &m_colorbuffers, [this, now](Stream* stream) -> ColorBufferMap::value_type { ColorBufferPtr cb(ColorBuffer::onLoad(stream, m_eglDisplay, diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index f3bc20c551..f82ec06822 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -29,6 +29,13 @@ #define VIRTIO_GPU_VM_VERSION 1 +#ifdef CONFIG_ANDROID +static bool virgl_as_proxy = false; +bool virtio_gpu_use_virgl_as_proxy() { + return virgl_as_proxy; +} +#endif + static struct virtio_gpu_simple_resource* virtio_gpu_find_resource(VirtIOGPU *g, uint32_t resource_id); @@ -1323,6 +1330,7 @@ static void virtio_gpu_device_realize(DeviceState *qdev, Error **errp) g->virgl_as_proxy = true; g->virgl = get_goldfish_pipe_virgl_renderer_virtio_interface(); g->gpu_3d_cbs = &proxy_3d_cbs; + virgl_as_proxy = true; #else g->use_virgl_renderer = false; #endif diff --git a/hw/misc/goldfish_pipe.c b/hw/misc/goldfish_pipe.c index 2816628eb5..30ea860a05 100755 --- a/hw/misc/goldfish_pipe.c +++ b/hw/misc/goldfish_pipe.c @@ -1442,12 +1442,22 @@ enum { GOLDFISH_PIPE_SAVE_VERSION = 1, }; +#ifdef CONFIG_ANDROID +extern bool virtio_gpu_use_virgl_as_proxy(); +#endif + static void goldfish_pipe_save(QEMUFile* f, void* opaque) { GoldfishPipeState* s = opaque; PipeDevice* dev = s->dev; service_ops->guest_pre_save(f); dev->ops->save(f, dev); +#ifdef CONFIG_ANDROID + if (!virtio_gpu_use_virgl_as_proxy()) { + service_ops->guest_post_save(f); + } +#else service_ops->guest_post_save(f); +#endif } static void goldfish_pipe_save_v1(QEMUFile* file, PipeDevice* dev) { @@ -1821,7 +1831,13 @@ static int goldfish_pipe_load(QEMUFile* f, void* opaque, int version_id) { service_ops->guest_pre_load(f); int res = goldfish_pipe_load_v2(f, dev); +#ifdef CONFIG_ANDROID + if (!virtio_gpu_use_virgl_as_proxy()) { + service_ops->guest_post_load(f); + } +#else service_ops->guest_post_load(f); +#endif return res; } diff --git a/include/qemu/iov.h b/include/qemu/iov.h index 6d17d3d136..508a550809 100644 --- a/include/qemu/iov.h +++ b/include/qemu/iov.h @@ -35,7 +35,7 @@ size_t iov_size(const struct iovec *iov, const unsigned int iov_cnt); size_t iov_from_buf_full(const struct iovec *iov, unsigned int iov_cnt, size_t offset, const void *buf, size_t bytes); size_t iov_to_buf_full(const struct iovec *iov, const unsigned int iov_cnt, - size_t offset, void *buf, size_t bytes); + size_t offset, void *buf, size_t bytes); static inline size_t iov_from_buf(const struct iovec *iov, unsigned int iov_cnt, |