[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 21/26] hw/display/apple-gfx: Implements texture syncing for non-U
From: |
Phil Dennis-Jordan |
Subject: |
[PATCH 21/26] hw/display/apple-gfx: Implements texture syncing for non-UMA GPUs |
Date: |
Mon, 15 Jul 2024 23:07:00 +0200 |
Renderable Metal textures are handled differently depending on
whether the GPU uses a unified memory architecture (no physical
distinction between VRAM and system RAM, CPU and GPU share the
memory bus) or not. (Traditional discrete GPU with its own VRAM)
In the discrete GPU case, textures must be explicitly
synchronised to the CPU or the GPU before use after being
modified by the other. In this case, we sync after the PV
graphics framework has rendered the next frame into the
texture using the GPU so that we can read out its contents using
the CPU. This fixes the issue where the guest screen stayed
black on AMD Radeon GPUs.
Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu>
---
hw/display/apple-gfx.h | 1 +
hw/display/apple-gfx.m | 10 +++++++++-
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/hw/display/apple-gfx.h b/hw/display/apple-gfx.h
index 9d6d40795e..995ecf7f4a 100644
--- a/hw/display/apple-gfx.h
+++ b/hw/display/apple-gfx.h
@@ -43,6 +43,7 @@ struct AppleGFXState {
/* The following fields should only be accessed from render_queue: */
bool gfx_update_requested;
bool new_frame_ready;
+ bool using_managed_texture_storage;
int32_t pending_frames;
void *vram;
DisplaySurface *surface;
diff --git a/hw/display/apple-gfx.m b/hw/display/apple-gfx.m
index bc9722b420..801ae4ad51 100644
--- a/hw/display/apple-gfx.m
+++ b/hw/display/apple-gfx.m
@@ -125,7 +125,12 @@ static void apple_gfx_render_new_frame(AppleGFXState *s)
return;
}
[texture retain];
-
+ if (s->using_managed_texture_storage) {
+ /* "Managed" textures exist in both VRAM and RAM and must be synced. */
+ id<MTLBlitCommandEncoder> blit = [command_buffer blitCommandEncoder];
+ [blit synchronizeResource:texture];
+ [blit endEncoding];
+ }
[command_buffer retain];
[command_buffer addCompletedHandler:
^(id<MTLCommandBuffer> cb)
@@ -268,6 +273,9 @@ static void set_mode(AppleGFXState *s, uint32_t width,
uint32_t height)
texture = [s->mtl newTextureWithDescriptor:textureDescriptor];
}
+ s->using_managed_texture_storage =
+ (texture.storageMode == MTLStorageModeManaged);
+
dispatch_sync(s->render_queue,
^{
id<MTLTexture> old_texture = nil;
--
2.39.3 (Apple Git-146)
- Re:, (continued)
- Re:, Akihiko Odaki, 2024/07/16
- Re:, Phil Dennis-Jordan, 2024/07/17
- [PATCH 09/26] hw/display/apple-gfx: Wraps ObjC autorelease code in pool, Phil Dennis-Jordan, 2024/07/17
- [PATCH 10/26] hw/display/apple-gfx: Fixes ObjC new/init misuse, plugs leaks, Phil Dennis-Jordan, 2024/07/17
- [PATCH 08/26] hw/display/apple-gfx: Adds migration blocker, Phil Dennis-Jordan, 2024/07/17
- [PATCH 24/26] hw/display/apple-gfx: Adds configurable mode list, Phil Dennis-Jordan, 2024/07/17
- [PATCH 25/26] MAINTAINERS: Add myself as maintainer for apple-gfx, reviewer for HVF, Phil Dennis-Jordan, 2024/07/17
- [PATCH 21/26] hw/display/apple-gfx: Implements texture syncing for non-UMA GPUs,
Phil Dennis-Jordan <=
- [PATCH 04/26] hw/display/apple-gfx: uses DEFINE_TYPES macro, Phil Dennis-Jordan, 2024/07/17
- [PATCH 23/26] hw/display/apple-gfx: Host GPU picking improvements, Phil Dennis-Jordan, 2024/07/17
- [PATCH 01/26] hw/vmapple/apple-gfx: Introduce ParavirtualizedGraphics.Framework support, Phil Dennis-Jordan, 2024/07/17
- [PATCH 02/26] hw/vmapple/apple-gfx: BQL renaming update, Phil Dennis-Jordan, 2024/07/17
- [PATCH 05/26] hw/display/apple-gfx: native -> little endian memory ops, Phil Dennis-Jordan, 2024/07/17
- [PATCH 07/26] hw/display/apple-gfx: Makes set_mode thread & memory safe, Phil Dennis-Jordan, 2024/07/17
- [PATCH 20/26] hw/display/apple-gfx: Fixes cursor hotspot handling, Phil Dennis-Jordan, 2024/07/17
- [PATCH 06/26] hw/display/apple-gfx: Removes dead/superfluous code, Phil Dennis-Jordan, 2024/07/17
- [PATCH 17/26] hw/display/apple-gfx: Asynchronous rendering and graphics update, Phil Dennis-Jordan, 2024/07/17
- [PATCH 13/26] hw/display/apple-gfx: Defines PGTask_s struct instead of casting, Phil Dennis-Jordan, 2024/07/17