diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2024-02-12 20:30:40 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2024-02-12 20:30:40 +0000 |
commit | 620068b213bda77895489dc51bbb2bafdedcb2df (patch) | |
tree | 16c2aab804b7e69d56062831a0139bb0fee0b7a4 | |
parent | 8d6dafd3b3b11c285be2bf70c58d4cc34a3d0318 (diff) | |
parent | 8c067674c0fc30334d92d122ebb0bf39ce6e6847 (diff) | |
download | qemu-620068b213bda77895489dc51bbb2bafdedcb2df.tar.gz |
Snap for 11438001 from 8c067674c0fc30334d92d122ebb0bf39ce6e6847 to emu-34-release
Change-Id: Ied4c187c8e5d554927d047a84de6c2a08eebda3f
17 files changed, 121 insertions, 26 deletions
diff --git a/android-qemu2-glue/emulation/android_address_space_device.cpp b/android-qemu2-glue/emulation/android_address_space_device.cpp index ed13a76f5e..7bc42b35af 100644 --- a/android-qemu2-glue/emulation/android_address_space_device.cpp +++ b/android-qemu2-glue/emulation/android_address_space_device.cpp @@ -56,6 +56,8 @@ static const struct AddressSpaceHwFuncs address_space_hw_funcs = { goldfish_address_space_get_phys_addr_start, // getPhysAddrStartLocked() goldfish_address_space_get_phys_addr_start_locked, + // getGuestPageSize() + goldfish_address_space_get_guest_page_size, // allocSharedHostRegionFixedLocked goldfish_address_space_alloc_shared_host_region_fixed_locked, }; diff --git a/android-qemu2-glue/main.cpp b/android-qemu2-glue/main.cpp index 803120f8d8..7b24f20bf3 100644 --- a/android-qemu2-glue/main.cpp +++ b/android-qemu2-glue/main.cpp @@ -3213,6 +3213,22 @@ extern "C" int main(int argc, char** argv) { RendererConfig rendererConfig; configAndStartRenderer(uiPreferredGlesBackend, &rendererConfig); +#if defined(__linux__) + { + // bug: 324086743 + // we have to enable SystemBlob to work around the kvm+amdgpu driver bug + // where kvm apparently error out with Bad Address + char* glVendor = nullptr; + char* glRenderer = nullptr; + char* glVersion = nullptr; + android_getOpenglesHardwareStrings(&glVendor, &glRenderer, &glVersion); + if (glVendor && strcmp("AMD",glVendor) == 0) { + dinfo("Enable SystemBlob feature for gpu vendor %s on Linux\n", glVendor); + feature_set_enabled_override(kFeature_SystemBlob, true); + } + } +#endif + // Gpu configuration is set, now initialize the multi display, screen // recorder and screenshot callback bool isGuestMode = diff --git a/android/android-emu/android/emulation/address_space_device.cpp b/android/android-emu/android/emulation/address_space_device.cpp index bb5d7d5b92..f5975dde5c 100644 --- a/android/android-emu/android/emulation/address_space_device.cpp +++ b/android/android-emu/android/emulation/address_space_device.cpp @@ -370,7 +370,8 @@ private: return nullptr; case AddressSpaceDeviceType::HostMemoryAllocator: return DeviceContextPtr(new AddressSpaceHostMemoryAllocatorContext( - get_address_space_device_control_ops())); + get_address_space_device_control_ops(), + get_address_space_device_hw_funcs())); case AddressSpaceDeviceType::SharedSlotsHostMemoryAllocator: return DeviceContextPtr(new AddressSpaceSharedSlotsHostMemoryAllocatorContext( get_address_space_device_control_ops(), diff --git a/android/android-emu/android/emulation/address_space_host_memory_allocator.cpp b/android/android-emu/android/emulation/address_space_host_memory_allocator.cpp index 82045f2030..4ea291c889 100644 --- a/android/android-emu/android/emulation/address_space_host_memory_allocator.cpp +++ b/android/android-emu/android/emulation/address_space_host_memory_allocator.cpp @@ -16,15 +16,16 @@ #include "host-common/address_space_device.hpp" #include "host-common/vm_operations.h" #include "aemu/base/AlignedBuf.h" +#include "android/utils/misc.h" #include "host-common/crash-handler.h" namespace android { namespace emulation { AddressSpaceHostMemoryAllocatorContext::AddressSpaceHostMemoryAllocatorContext( - const address_space_device_control_ops *ops) - : m_ops(ops) { -} + const address_space_device_control_ops *ops, const AddressSpaceHwFuncs* hw) + : m_ops(ops), + m_hw(hw) {} AddressSpaceHostMemoryAllocatorContext::~AddressSpaceHostMemoryAllocatorContext() { clear(); @@ -53,13 +54,13 @@ void AddressSpaceHostMemoryAllocatorContext::perform(AddressSpaceDevicePingInfo void *AddressSpaceHostMemoryAllocatorContext::allocate_impl(const uint64_t phys_addr, const uint64_t size) { #if defined(__APPLE__) && defined(__arm64__) - constexpr uint64_t alignment = 16384; + constexpr uint64_t k_alloc_alignment = 16384; #else - constexpr uint64_t alignment = 4096; + constexpr uint64_t k_alloc_alignment = 4096; #endif - const uint64_t aligned_size = ((size + alignment - 1) / alignment) * alignment; + const uint32_t aligned_size = align(size, (*m_hw->getGuestPageSize)()); - void *host_ptr = android::aligned_buf_alloc(alignment, aligned_size); + void *host_ptr = android::aligned_buf_alloc(k_alloc_alignment, aligned_size); if (host_ptr) { auto r = m_paddr2ptr.insert({phys_addr, {host_ptr, aligned_size}}); if (r.second) { diff --git a/android/android-emu/android/emulation/address_space_host_memory_allocator_unittests.cpp b/android/android-emu/android/emulation/address_space_host_memory_allocator_unittests.cpp index 77f0517f6c..8ec3fa2208 100644 --- a/android/android-emu/android/emulation/address_space_host_memory_allocator_unittests.cpp +++ b/android/android-emu/android/emulation/address_space_host_memory_allocator_unittests.cpp @@ -29,6 +29,10 @@ int empty_add_memory_mapping(uint64_t gpa, void *ptr, uint64_t size) { int empty_remove_memory_mapping(uint64_t gpa, void *ptr, uint64_t size) { return 1; } +uint32_t getGuestPageSize() { + return 4096; +} + struct address_space_device_control_ops create_address_space_device_control_ops() { struct address_space_device_control_ops ops = {}; @@ -38,6 +42,14 @@ struct address_space_device_control_ops create_address_space_device_control_ops( return ops; } +AddressSpaceHwFuncs create_address_space_device_hw_funcs() { + AddressSpaceHwFuncs hw_funcs = {}; + + hw_funcs.getGuestPageSize = &getGuestPageSize; + + return hw_funcs; +} + AddressSpaceDevicePingInfo createAllocateRequest(uint64_t phys_addr) { AddressSpaceDevicePingInfo req = {}; @@ -64,7 +76,9 @@ TEST(AddressSpaceHostMemoryAllocatorContext, getDeviceType) { struct address_space_device_control_ops ops = create_address_space_device_control_ops(); - AddressSpaceHostMemoryAllocatorContext ctx(&ops); + AddressSpaceHwFuncs hw_funcs = create_address_space_device_hw_funcs(); + + AddressSpaceHostMemoryAllocatorContext ctx(&ops, &hw_funcs); EXPECT_EQ(ctx.getDeviceType(), AddressSpaceDeviceType::HostMemoryAllocator); } @@ -73,7 +87,9 @@ TEST(AddressSpaceHostMemoryAllocatorContext, AllocateDeallocate) { struct address_space_device_control_ops ops = create_address_space_device_control_ops(); - AddressSpaceHostMemoryAllocatorContext ctx(&ops); + AddressSpaceHwFuncs hw_funcs = create_address_space_device_hw_funcs(); + + AddressSpaceHostMemoryAllocatorContext ctx(&ops, &hw_funcs); AddressSpaceDevicePingInfo req; @@ -90,7 +106,9 @@ TEST(AddressSpaceHostMemoryAllocatorContext, AllocateSamePhysAddr) { struct address_space_device_control_ops ops = create_address_space_device_control_ops(); - AddressSpaceHostMemoryAllocatorContext ctx(&ops); + AddressSpaceHwFuncs hw_funcs = create_address_space_device_hw_funcs(); + + AddressSpaceHostMemoryAllocatorContext ctx(&ops, &hw_funcs); AddressSpaceDevicePingInfo req; @@ -127,7 +145,9 @@ TEST(AddressSpaceHostMemoryAllocatorContext, AllocateMappingFail) { struct address_space_device_control_ops ops = create_address_space_device_control_ops(); - AddressSpaceHostMemoryAllocatorContext ctx(&ops); + AddressSpaceHwFuncs hw_funcs = create_address_space_device_hw_funcs(); + + AddressSpaceHostMemoryAllocatorContext ctx(&ops, &hw_funcs); AddressSpaceDevicePingInfo req; @@ -140,7 +160,9 @@ TEST(AddressSpaceHostMemoryAllocatorContext, UnallocateTwice) { struct address_space_device_control_ops ops = create_address_space_device_control_ops(); - AddressSpaceHostMemoryAllocatorContext ctx(&ops); + AddressSpaceHwFuncs hw_funcs = create_address_space_device_hw_funcs(); + + AddressSpaceHostMemoryAllocatorContext ctx(&ops, &hw_funcs); AddressSpaceDevicePingInfo req; diff --git a/android/android-emu/android/emulation/address_space_shared_slots_host_memory_allocator.cpp b/android/android-emu/android/emulation/address_space_shared_slots_host_memory_allocator.cpp index 8c25223ff6..afdea8f38f 100644 --- a/android/android-emu/android/emulation/address_space_shared_slots_host_memory_allocator.cpp +++ b/android/android-emu/android/emulation/address_space_shared_slots_host_memory_allocator.cpp @@ -17,6 +17,7 @@ #include "host-common/vm_operations.h" #include "aemu/base/AlignedBuf.h" #include "aemu/base/synchronization/Lock.h" +#include "android/utils/misc.h" #include "host-common/crash-handler.h" #include <map> #include <unordered_set> @@ -34,9 +35,9 @@ using base::AutoLock; using base::Lock; #if defined(__APPLE__) && defined(__arm64__) -constexpr uint32_t kAlignment = 16384; +constexpr uint32_t kAllocAlignment = 16384; #else -constexpr uint32_t kAlignment = 4096; +constexpr uint32_t kAllocAlignment = 4096; #endif uint64_t allocateAddressSpaceBlock(const AddressSpaceHwFuncs* hw, uint32_t size) { @@ -88,7 +89,7 @@ std::pair<uint64_t, MemBlock*> translatePhysAddr(uint64_t p) { MemBlock::MemBlock(const address_space_device_control_ops* o, const AddressSpaceHwFuncs* h, uint32_t sz) : ops(o), hw(h) { - bits = android::aligned_buf_alloc(kAlignment, sz); + bits = android::aligned_buf_alloc(kAllocAlignment, sz); bitsSize = sz; physBase = allocateAddressSpaceBlock(hw, sz); if (!physBase) { @@ -246,7 +247,7 @@ bool MemBlock::load(base::Stream* stream, MemBlock* block) { const uint64_t physBaseLoaded = stream->getBe64(); const uint32_t bitsSize = stream->getBe32(); - void* const bits = android::aligned_buf_alloc(kAlignment, bitsSize); + void* const bits = android::aligned_buf_alloc(kAllocAlignment, bitsSize); if (!bits) { return false; } @@ -323,8 +324,7 @@ void AddressSpaceSharedSlotsHostMemoryAllocatorContext::perform(AddressSpaceDevi uint64_t AddressSpaceSharedSlotsHostMemoryAllocatorContext::allocate( AddressSpaceDevicePingInfo *info) { - const uint32_t alignedSize = - ((info->size + kAlignment - 1) / kAlignment) * kAlignment; + const uint32_t alignedSize = align(info->size, (*m_hw->getGuestPageSize)()); AutoLock lock(g_blocksLock); for (auto& kv : g_blocks) { diff --git a/android/android-emu/android/emulation/hostdevices/HostAddressSpace.cpp b/android/android-emu/android/emulation/hostdevices/HostAddressSpace.cpp index ce06a196b5..7e2b0664be 100644 --- a/android/android-emu/android/emulation/hostdevices/HostAddressSpace.cpp +++ b/android/android-emu/android/emulation/hostdevices/HostAddressSpace.cpp @@ -480,6 +480,10 @@ uint64_t HostAddressSpaceDevice::getPhysAddrStart() { return HostAddressSpaceDevice::getImpl()->getPhysAddrStart(); } +uint32_t HostAddressSpaceDevice::getGuestPageSize() { + return 4096; +} + int HostAddressSpaceDevice::allocSharedHostRegionFixedLocked(uint64_t page_aligned_size, uint64_t offset) { return HostAddressSpaceDevice::getImpl()->allocSharedHostRegionFixedLocked(page_aligned_size, offset); } @@ -491,6 +495,7 @@ static const AddressSpaceHwFuncs sAddressSpaceHwFuncs = { &HostAddressSpaceDevice::freeSharedHostRegionLocked, &HostAddressSpaceDevice::getPhysAddrStart, &HostAddressSpaceDevice::getPhysAddrStart, + &HostAddressSpaceDevice::getGuestPageSize, &HostAddressSpaceDevice::allocSharedHostRegionFixedLocked, }; diff --git a/android/android-emu/android/emulation/hostdevices/HostAddressSpace.h b/android/android-emu/android/emulation/hostdevices/HostAddressSpace.h index 3890717645..4daf7dd09f 100644 --- a/android/android-emu/android/emulation/hostdevices/HostAddressSpace.h +++ b/android/android-emu/android/emulation/hostdevices/HostAddressSpace.h @@ -64,6 +64,7 @@ public: static int allocSharedHostRegionFixedLocked(uint64_t page_aligned_size, uint64_t offset); static uint64_t getPhysAddrStart(); static uint64_t getPhysAddrStartLocked(); + static uint32_t getGuestPageSize(); private: class Impl; diff --git a/android/android-emu/android/recording/codecs/Codec.h b/android/android-emu/android/recording/codecs/Codec.h index 79ac483a26..c36b68d772 100644 --- a/android/android-emu/android/recording/codecs/Codec.h +++ b/android/android-emu/android/recording/codecs/Codec.h @@ -57,6 +57,8 @@ public: // Configures and initializes either the SwsContext or SwrContext virtual bool initSwxContext(const AVCodecContext* c, T* swxCxt) const = 0; + virtual void updateFbWidthHeight(uint32_t fbW, uint32_t fbH) { }; + // Configures and initializes the resampling context // Returns the codec id. AVCodecID getCodecId() const { return mCodecId; } @@ -65,6 +67,8 @@ public: // Returns the codec parameters const CodecParams* getCodecParams() const { return &mParams; } + virtual double getScale() const { return 1.0; } + protected: explicit Codec(AVCodecID id, CodecParams&& params) : mCodecId(id), mParams(std::move(params)) { diff --git a/android/android-ui/modules/aemu-recording/src/android/recording/FfmpegRecorder.cpp b/android/android-ui/modules/aemu-recording/src/android/recording/FfmpegRecorder.cpp index 2b9a28974c..789e1fc930 100644 --- a/android/android-ui/modules/aemu-recording/src/android/recording/FfmpegRecorder.cpp +++ b/android/android-ui/modules/aemu-recording/src/android/recording/FfmpegRecorder.cpp @@ -73,6 +73,8 @@ struct SwsContext; #include <stdarg.h> // for va_list #include <stdio.h> // for vprintf, NULL #include <string.h> // for memcpy +#include <algorithm> +#include <cmath> #include <cstdint> // for uint8_t #include <functional> // for __base #include <string> // for string, basic_string @@ -80,6 +82,7 @@ struct SwsContext; #include <utility> // for move #include <vector> // for vector + #include "android/recording/ffmpegdefs.h" #define D(...) VERBOSE_PRINT(record, __VA_ARGS__) @@ -213,6 +216,8 @@ private: // Callback for av_log_set_callback() to get logging info static void avLoggingCallback(void *ptr, int level, const char *fmt, va_list vargs); + uint32_t scaledOutput(uint32_t original) const; + private: std::string mEncodedOutputPath; AVScopedPtr<AVFormatContext> mOutputContext; @@ -257,14 +262,23 @@ bool FfmpegRecorderImpl::isValid() { return mValid; } +uint32_t FfmpegRecorderImpl::scaledOutput(uint32_t original) const { + double scale = mCodec->getScale(); + double output = original * scale; + return (uint32_t)(std::rint(output)); +} + void FfmpegRecorderImpl::reInitWidthAndHeight(uint16_t w, uint16_t h) { if (mFbWidth != w || mFbHeight != h) { mFbWidth = w; mFbHeight = h; + mCodec->updateFbWidthHeight(w,h); auto c = mVideoStream.codecCtx.get(); auto cctx = c; - cctx->width = w; - cctx->height = h; + uint32_t outputw = scaledOutput(w); + uint32_t outputh = scaledOutput(h); + cctx->width = outputw; + cctx->height = outputh; mCodec->getCodec()->init(cctx); // allocate and init a re-usable frame auto frame = allocVideoFrame(cctx->pix_fmt, cctx->width, cctx->height); diff --git a/android/android-ui/modules/aemu-recording/src/android/recording/codecs/video/VP9Codec.cpp b/android/android-ui/modules/aemu-recording/src/android/recording/codecs/video/VP9Codec.cpp index 9fe24b6614..6c23c14fa3 100644 --- a/android/android-ui/modules/aemu-recording/src/android/recording/codecs/video/VP9Codec.cpp +++ b/android/android-ui/modules/aemu-recording/src/android/recording/codecs/video/VP9Codec.cpp @@ -40,7 +40,10 @@ VP9Codec::VP9Codec(CodecParams&& p, : Codec(AV_CODEC_ID_VP9, std::move(p)), mFbWidth(fbWidth), mFbHeight(fbHeight), - mFbFormat(fbFormat) {} + mFbFormat(fbFormat) { + mScale = std::min(mScale, getCodecParams()->width / (double)fbWidth); + mScale = std::min(mScale, getCodecParams()->height / (double)fbHeight); +} VP9Codec::~VP9Codec() {} @@ -94,11 +97,24 @@ bool VP9Codec::configAndOpenEncoder(const AVFormatContext* oc, return true; } +void VP9Codec::updateFbWidthHeight(uint32_t fbW, uint32_t fbH) { + mFbWidth = fbW; + mFbHeight = fbH; +} + +double VP9Codec::getScale() const { + return mScale; +} + bool VP9Codec::initSwxContext(const AVCodecContext* c, SwsContext** swsCxt) const { *swsCxt = - sws_getContext(c->width, c->height, mFbFormat, c->width, c->height, + sws_getContext(mFbWidth, mFbHeight, mFbFormat, c->width, c->height, c->pix_fmt, SCALE_FLAGS, NULL, NULL, NULL); +#if 0 + LOG(INFO)<<" fb " << mFbWidth << " x " << mFbHeight; + LOG(INFO)<<" target " << c->width << " x " << c->height; +#endif if (*swsCxt == nullptr) { LOG(ERROR) << "Could not initialize the conversion context"; return false; diff --git a/android/android-ui/modules/aemu-recording/src/android/recording/codecs/video/VP9Codec.h b/android/android-ui/modules/aemu-recording/src/android/recording/codecs/video/VP9Codec.h index b53e713356..e8247601c9 100644 --- a/android/android-ui/modules/aemu-recording/src/android/recording/codecs/video/VP9Codec.h +++ b/android/android-ui/modules/aemu-recording/src/android/recording/codecs/video/VP9Codec.h @@ -47,7 +47,13 @@ public: virtual bool initSwxContext(const AVCodecContext* c, SwsContext** swsCxt) const override; + // when resize, this will change and we need to update + virtual void updateFbWidthHeight(uint32_t fbW, uint32_t fbH) override; + + virtual double getScale() const override; + protected: + double mScale = 1.0; uint32_t mFbWidth = 0; uint32_t mFbHeight = 0; AVPixelFormat mFbFormat = AV_PIX_FMT_NONE; diff --git a/hw/pci/goldfish_address_space.c b/hw/pci/goldfish_address_space.c index 8313fdfb95..486519ee06 100644 --- a/hw/pci/goldfish_address_space.c +++ b/hw/pci/goldfish_address_space.c @@ -1248,3 +1248,8 @@ uint64_t goldfish_address_space_get_phys_addr_start_locked(void) return res; } + +uint32_t goldfish_address_space_get_guest_page_size(void) +{ + return s_current_state->registers.guest_page_size; +} diff --git a/include/hw/pci/goldfish_address_space.h b/include/hw/pci/goldfish_address_space.h index ea73ccc09c..ca3884519d 100644 --- a/include/hw/pci/goldfish_address_space.h +++ b/include/hw/pci/goldfish_address_space.h @@ -53,6 +53,8 @@ extern uint64_t goldfish_address_space_get_phys_addr_start(void); extern uint64_t goldfish_address_space_get_phys_addr_start_locked(void); +extern uint32_t +goldfish_address_space_get_guest_page_size(void); /* Version of alloc for a fixed offset */ extern int goldfish_address_space_alloc_shared_host_region_fixed_locked(uint64_t page_aligned_size, uint64_t offset); diff --git a/mac.source.properties b/mac.source.properties index c5011f16b9..d51b9ecdea 100644 --- a/mac.source.properties +++ b/mac.source.properties @@ -1,4 +1,4 @@ Pkg.UserSrc=false -Pkg.Revision=34.1.16 +Pkg.Revision=34.1.17 Pkg.Path=emulator Pkg.Desc=Android Emulator diff --git a/source.properties b/source.properties index c5011f16b9..d51b9ecdea 100644 --- a/source.properties +++ b/source.properties @@ -1,4 +1,4 @@ Pkg.UserSrc=false -Pkg.Revision=34.1.16 +Pkg.Revision=34.1.17 Pkg.Path=emulator Pkg.Desc=Android Emulator diff --git a/win.source.properties b/win.source.properties index c5011f16b9..d51b9ecdea 100644 --- a/win.source.properties +++ b/win.source.properties @@ -1,4 +1,4 @@ Pkg.UserSrc=false -Pkg.Revision=34.1.16 +Pkg.Revision=34.1.17 Pkg.Path=emulator Pkg.Desc=Android Emulator |