mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-22 06:15:58 +00:00
fix(display): read linear client frames at their row pitch when the driver has no explicit modifier layouts (#2927)
* fix(display): read linear client frames at their row pitch when the driver has no explicit modifier layouts * fix(display): keep row-pitch copied client frames eligible for layer presentation * fix(display): order the readback layout change after the staging copy * fix(display): skip the modifier import query when the driver lacks VK_EXT_image_drm_format_modifier * test(display): the compositor's source-extracting tests follow the linear dma-buf helpers vkp_image_destroy now frees through destroy_image_objects, render_impl stages linear dma-bufs and the external-image release asks foreign_image; the two tests that compile these functions out of vk_present.c extract or stub them, with the image's new buffer fields in their fakes. --------- Co-authored-by: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com>
This commit is contained in:
1 parent
6f45b5347d
commit
3c0d25d83b
7 files changed
+488
-21
No files matched your search
@@ -26,7 +26,7 @@ class EffectsSourceResolutionTest(unittest.TestCase):
|
||||
header = (REPO / 'app/src/main/cpp/waylandcomp/src/vk_present.h').read_text()
|
||||
effects = (REPO / 'app/src/main/cpp/waylandcomp/src/effects_chain.c').read_text()
|
||||
functions = '\n'.join(function(source, signature) for signature in (
|
||||
'static void release_external_client_image(', 'static void release_external_client_draws(',
|
||||
'static int foreign_image(', 'static void release_external_client_image(', 'static void release_external_client_draws(',
|
||||
'static int map_draw(', 'static int draw_to_blit(',
|
||||
'static int draw_to_scene_blit(', 'static int effects_source_draw(',
|
||||
'static void effects_source_note(',
|
||||
@@ -113,7 +113,7 @@ TYPES = r'''
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
typedef int VkImage, VkDeviceMemory, VkFormat, VkCommandBuffer, VkResult, VkFilter;
|
||||
typedef int VkImage, VkDeviceMemory, VkFormat, VkCommandBuffer, VkResult, VkFilter, VkBuffer;
|
||||
typedef int VkImageLayout, VkPipelineStageFlags, VkImageUsageFlags;
|
||||
typedef uint64_t VkDeviceSize;
|
||||
typedef struct { unsigned width, height; } VkExtent2D;
|
||||
@@ -126,6 +126,13 @@ typedef struct {
|
||||
VkImageSubresourceLayers dstSubresource;
|
||||
VkOffset3D dstOffsets[2];
|
||||
} VkImageBlit;
|
||||
typedef struct {
|
||||
VkDeviceSize bufferOffset;
|
||||
unsigned bufferRowLength, bufferImageHeight;
|
||||
VkImageSubresourceLayers imageSubresource;
|
||||
VkOffset3D imageOffset;
|
||||
struct { unsigned width, height, depth; } imageExtent;
|
||||
} VkBufferImageCopy;
|
||||
typedef struct { int sType, flags; } VkCommandBufferBeginInfo;
|
||||
typedef struct {
|
||||
int sType, oldLayout, newLayout, srcQueueFamilyIndex, dstQueueFamilyIndex;
|
||||
@@ -161,6 +168,8 @@ typedef struct AHardwareBuffer AHardwareBuffer;
|
||||
|
||||
|
||||
STUBS = r'''
|
||||
static void stage_linear_dmabufs(VkCommandBuffer cmd, const struct vkp_draw *draws, int count) { (void)cmd; (void)draws; (void)count; }
|
||||
static int vkp_linear_dmabuf_foreign_image(int dmabuf, int staged) { return dmabuf && !staged; }
|
||||
static void quarantine_pending_work(VkResult result, const char *where) { (void)result; (void)where; }
|
||||
static int noop(int handle, ...) { return VK_SUCCESS; }
|
||||
static VkImageMemoryBarrier recorded_barriers[64];
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
from tools.tests.test_vk_external_image_sync import vulkan_include_args
|
||||
from tools.tests.test_vk_pending_completion import function
|
||||
|
||||
TESTS = Path(__file__).resolve().parent
|
||||
SRC = TESTS.parents[1] / "app/src/main/cpp/waylandcomp/src"
|
||||
|
||||
LAYER_HARNESS = r'''
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <vulkan/vulkan.h>
|
||||
#include "vk_external_image_sync.h"
|
||||
#include "vk_linear_dmabuf.h"
|
||||
|
||||
typedef struct AHardwareBuffer AHardwareBuffer;
|
||||
%(image)s
|
||||
struct vkp_draw {
|
||||
struct vkp_image *img;
|
||||
float sx, sy, sw, sh;
|
||||
int dx, dy, dw, dh;
|
||||
int blend;
|
||||
};
|
||||
struct draw_list { struct vkp_draw *d; int n, cap; };
|
||||
static const uint32_t g_qfam = 2;
|
||||
%(foreign)s
|
||||
%(is_dmabuf)s
|
||||
%(width)s
|
||||
%(height)s
|
||||
%(candidate)s
|
||||
|
||||
static int candidate(struct vkp_image *img) {
|
||||
struct vkp_draw d = {.img = img, .sw = 1560, .sh = 720, .dw = 1560, .dh = 720};
|
||||
struct draw_list dl = {.d = &d, .n = 1, .cap = 1};
|
||||
return layer_candidate(&dl, 1560, 720);
|
||||
}
|
||||
|
||||
static int foreign_pair(struct vkp_image *img) {
|
||||
struct vkp_external_client_barrier_pair pair;
|
||||
return vkp_external_client_barrier_pair(img->image, g_qfam, foreign_image(img), img->blit_dst, &pair);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
struct vkp_image staged = {.w = 1560, .h = 720, .dmabuf = 1, .staged = 1};
|
||||
assert(candidate(&staged) == 0);
|
||||
assert(!foreign_pair(&staged));
|
||||
|
||||
struct vkp_image client = {.w = 1560, .h = 720, .dmabuf = 1};
|
||||
assert(candidate(&client) == 0);
|
||||
assert(foreign_pair(&client));
|
||||
|
||||
struct vkp_image shm = {.w = 1560, .h = 720};
|
||||
assert(candidate(&shm) == -1);
|
||||
assert(!foreign_pair(&shm));
|
||||
|
||||
struct vkp_image layer = {.w = 1560, .h = 720, .dmabuf = 1, .blit_dst = 1};
|
||||
assert(candidate(&layer) == -1);
|
||||
assert(!foreign_pair(&layer));
|
||||
return 0;
|
||||
}
|
||||
'''
|
||||
|
||||
|
||||
def compile_and_run(test, source, tmp, name):
|
||||
compiler = shutil.which(os.environ.get("CC", "cc"))
|
||||
if not compiler:
|
||||
test.fail("A C compiler is required for the linear dma-buf regression tests")
|
||||
program = Path(tmp) / name
|
||||
command = [
|
||||
compiler,
|
||||
"-std=c11",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Werror",
|
||||
"-UNDEBUG",
|
||||
"-I",
|
||||
str(SRC),
|
||||
*vulkan_include_args(),
|
||||
str(source),
|
||||
"-o",
|
||||
str(program),
|
||||
]
|
||||
built = subprocess.run(command, capture_output=True, text=True)
|
||||
test.assertEqual(built.returncode, 0, built.stdout + built.stderr)
|
||||
ran = subprocess.run([str(program)], capture_output=True, text=True, timeout=30)
|
||||
test.assertEqual(ran.returncode, 0, ran.stdout + ran.stderr)
|
||||
|
||||
|
||||
class VkLinearDmabufTest(unittest.TestCase):
|
||||
def test_linear_dmabuf_copy(self):
|
||||
with tempfile.TemporaryDirectory(prefix="droiddeck-vk-linear-") as tmp:
|
||||
compile_and_run(self, TESTS / "vk_linear_dmabuf_test.c", tmp, "vk-linear-dmabuf")
|
||||
|
||||
def test_readback_orders_general_transition_after_staging_copy(self):
|
||||
body = function((SRC / "vk_present.c").read_text(), "vkp_image_readback")
|
||||
stage = body.index("stage_linear_dmabuf(cmd, src);")
|
||||
barrier = body.index("vkp_linear_dmabuf_readback_stage(src->in_general)")
|
||||
self.assertLess(stage, barrier)
|
||||
self.assertIn(".srcAccessMask = vkp_linear_dmabuf_readback_access(src->in_general)", body[stage:barrier])
|
||||
self.assertNotIn("CmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT", body)
|
||||
|
||||
def test_modifier_query_needs_drm_modifier_extension(self):
|
||||
body = function((SRC / "vk_present.c").read_text(), "vkp_image_import_dmabuf")
|
||||
query = re.search(r"const int modifier_sampled = (.*?);", body, re.S)
|
||||
self.assertIsNotNone(query, "modifier_sampled not found in vkp_image_import_dmabuf")
|
||||
terms = [t.strip() for t in query.group(1).split("&&")]
|
||||
self.assertIn("g_drm_modifiers", terms)
|
||||
self.assertLess(terms.index("g_drm_modifiers"), terms.index("modifier_importable(img->fmt, modifier, sampled_usage)"))
|
||||
self.assertIn("!as_blit_dst", terms)
|
||||
self.assertIn("g_vk.GetPhysicalDeviceImageFormatProperties2", terms)
|
||||
|
||||
def test_staged_client_image_stays_layer_candidate(self):
|
||||
vk = (SRC / "vk_present.c").read_text()
|
||||
comp = (SRC / "compositor.c").read_text()
|
||||
image = re.search(r"^struct vkp_image \{.*?^\};", vk, re.M | re.S)
|
||||
self.assertIsNotNone(image, "struct vkp_image not found in vk_present.c")
|
||||
harness = LAYER_HARNESS % {
|
||||
"image": image.group(0),
|
||||
"foreign": function(vk, "foreign_image"),
|
||||
"is_dmabuf": function(vk, "vkp_image_is_dmabuf"),
|
||||
"width": function(vk, "vkp_image_width"),
|
||||
"height": function(vk, "vkp_image_height"),
|
||||
"candidate": function(comp, "layer_candidate"),
|
||||
}
|
||||
with tempfile.TemporaryDirectory(prefix="droiddeck-vk-linear-layer-") as tmp:
|
||||
source = Path(tmp) / "layer_candidate_test.c"
|
||||
source.write_text(harness)
|
||||
compile_and_run(self, source, tmp, "vk-linear-layer")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -56,16 +56,20 @@ static VkResult wait_fn(uintptr_t dev, unsigned n, const VkFence *f, int all, ui
|
||||
static void unmap_fn(uintptr_t dev, uintptr_t mem) { (void)dev; (void)mem; ++unmapped; }
|
||||
static void destroy_fn(uintptr_t dev, uintptr_t img, void *allocator) { (void)dev; (void)img; (void)allocator; ++destroyed; }
|
||||
static void free_fn(uintptr_t dev, uintptr_t mem, void *allocator) { (void)dev; (void)mem; (void)allocator; ++freed_memory; }
|
||||
static unsigned destroyed_buffers;
|
||||
static void destroy_buffer_fn(uintptr_t dev, uintptr_t buf, void *allocator) { (void)dev; (void)buf; (void)allocator; ++destroyed_buffers; }
|
||||
#define VK_NULL_HANDLE 0
|
||||
static struct {
|
||||
VkResult (*WaitForFences)(uintptr_t, unsigned, const VkFence *, int, uint64_t);
|
||||
void (*UnmapMemory)(uintptr_t, uintptr_t);
|
||||
void (*DestroyImage)(uintptr_t, uintptr_t, void *);
|
||||
void (*FreeMemory)(uintptr_t, uintptr_t, void *);
|
||||
} g_vk = {wait_fn, unmap_fn, destroy_fn, free_fn};
|
||||
void (*DestroyBuffer)(uintptr_t, uintptr_t, void *);
|
||||
} g_vk = {wait_fn, unmap_fn, destroy_fn, free_fn, destroy_buffer_fn};
|
||||
typedef struct AHardwareBuffer AHardwareBuffer;
|
||||
static int released_buffers;
|
||||
static void AHardwareBuffer_release(AHardwareBuffer *b) { (void)b; ++released_buffers; }
|
||||
struct vkp_image { uintptr_t image, mem; void *map; AHardwareBuffer *android_buffer; };
|
||||
struct vkp_image { uintptr_t image, mem; void *map; AHardwareBuffer *android_buffer; uintptr_t linear_buf, linear_mem; int staged, in_general; };
|
||||
static void blendp_forget_image(uintptr_t image) { (void)image; ++forgotten; }
|
||||
/* PRODUCTION_FUNCTIONS */
|
||||
static struct vkp_image *image(void) {
|
||||
@@ -173,7 +177,7 @@ class VkPendingCompletionTest(unittest.TestCase):
|
||||
self.assertEqual(ran.returncode,0,ran.stdout+ran.stderr)
|
||||
|
||||
def test_unknown_completion_retains_gpu_resources(self):
|
||||
self.compile_and_run(HARNESS, ['quarantine_pending_work', 'timed_wait', 'vkp_image_destroy'])
|
||||
self.compile_and_run(HARNESS, ['quarantine_pending_work', 'timed_wait', 'destroy_image_objects', 'vkp_image_destroy'])
|
||||
|
||||
def test_failed_device_idle_does_not_destroy_swapchain(self):
|
||||
# LOGE's arguments must be evaluated as real production logging does.
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "vk_linear_dmabuf.h"
|
||||
|
||||
static void check_padded_rows(void) {
|
||||
VkBufferImageCopy copy;
|
||||
memset(©, 0xa5, sizeof(copy));
|
||||
const VkDeviceSize need = vkp_linear_dmabuf_copy(VK_FORMAT_R8G8B8A8_UNORM, 1560, 720, 6400, 0, ©);
|
||||
assert(copy.bufferRowLength == 1600);
|
||||
assert(copy.bufferRowLength != 1560);
|
||||
assert(copy.bufferOffset == 0);
|
||||
assert(copy.bufferImageHeight == 720);
|
||||
assert(copy.imageSubresource.aspectMask == VK_IMAGE_ASPECT_COLOR_BIT);
|
||||
assert(copy.imageSubresource.mipLevel == 0);
|
||||
assert(copy.imageSubresource.baseArrayLayer == 0);
|
||||
assert(copy.imageSubresource.layerCount == 1);
|
||||
assert(copy.imageOffset.x == 0 && copy.imageOffset.y == 0 && copy.imageOffset.z == 0);
|
||||
assert(copy.imageExtent.width == 1560);
|
||||
assert(copy.imageExtent.height == 720);
|
||||
assert(copy.imageExtent.depth == 1);
|
||||
assert(need == (VkDeviceSize)6400 * 719 + 1560 * 4);
|
||||
}
|
||||
|
||||
static void check_offset_and_wide_texels(void) {
|
||||
VkBufferImageCopy copy;
|
||||
const VkDeviceSize need = vkp_linear_dmabuf_copy(VK_FORMAT_R16G16B16A16_SFLOAT, 1920, 1080, 15360, 4096, ©);
|
||||
assert(copy.bufferRowLength == 1920);
|
||||
assert(copy.bufferOffset == 4096);
|
||||
assert(need == 4096 + (VkDeviceSize)15360 * 1079 + 1920 * 8);
|
||||
|
||||
assert(vkp_linear_dmabuf_copy(VK_FORMAT_B8G8R8A8_UNORM, 1, 1, 64, 0, ©) == 4);
|
||||
assert(copy.bufferRowLength == 16);
|
||||
}
|
||||
|
||||
static void check_rejected_layouts(void) {
|
||||
VkBufferImageCopy copy;
|
||||
assert(vkp_linear_dmabuf_copy(VK_FORMAT_R8G8B8A8_UNORM, 1560, 720, 6236, 0, ©) == 0);
|
||||
assert(vkp_linear_dmabuf_copy(VK_FORMAT_R8G8B8A8_UNORM, 1560, 720, 6402, 0, ©) == 0);
|
||||
assert(vkp_linear_dmabuf_copy(VK_FORMAT_R8G8B8A8_UNORM, 1560, 720, 6400, 2, ©) == 0);
|
||||
assert(vkp_linear_dmabuf_copy(VK_FORMAT_R16G16B16A16_SFLOAT, 1560, 720, 6240, 0, ©) == 0);
|
||||
assert(vkp_linear_dmabuf_copy(VK_FORMAT_R8G8B8A8_UNORM, 0, 720, 6400, 0, ©) == 0);
|
||||
assert(vkp_linear_dmabuf_copy(VK_FORMAT_R8G8B8A8_UNORM, 1560, 0, 6400, 0, ©) == 0);
|
||||
assert(vkp_linear_dmabuf_copy(VK_FORMAT_R8G8B8A8_UNORM, 1560, 720, 6400, 0, NULL) == 0);
|
||||
}
|
||||
|
||||
static void check_path_choice(void) {
|
||||
const uint64_t linear = 0;
|
||||
const uint64_t qcom_compressed = 0x0500000000000001ULL;
|
||||
assert(vkp_linear_dmabuf_through_buffer(0, linear, 0));
|
||||
assert(!vkp_linear_dmabuf_through_buffer(1, linear, 0));
|
||||
assert(!vkp_linear_dmabuf_through_buffer(1, qcom_compressed, 0));
|
||||
assert(!vkp_linear_dmabuf_through_buffer(0, qcom_compressed, 0));
|
||||
assert(!vkp_linear_dmabuf_through_buffer(0, linear, 1));
|
||||
assert(!vkp_linear_dmabuf_through_buffer(1, linear, 1));
|
||||
}
|
||||
|
||||
static void check_foreign_image(void) {
|
||||
assert(vkp_linear_dmabuf_foreign_image(1, 0));
|
||||
assert(!vkp_linear_dmabuf_foreign_image(1, 1));
|
||||
assert(!vkp_linear_dmabuf_foreign_image(0, 0));
|
||||
assert(!vkp_linear_dmabuf_foreign_image(0, 1));
|
||||
}
|
||||
|
||||
static void check_readback_order(void) {
|
||||
assert(vkp_linear_dmabuf_readback_stage(1) & VK_PIPELINE_STAGE_TRANSFER_BIT);
|
||||
assert(vkp_linear_dmabuf_readback_access(1) & VK_ACCESS_TRANSFER_WRITE_BIT);
|
||||
assert(vkp_linear_dmabuf_readback_stage(0) == VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
|
||||
assert(vkp_linear_dmabuf_readback_access(0) == 0);
|
||||
}
|
||||
|
||||
static void check_ownership(void) {
|
||||
const VkBuffer buffer = (VkBuffer)(uintptr_t)0x4321;
|
||||
const uint32_t queue_family = 3;
|
||||
const VkBufferMemoryBarrier acquire = vkp_linear_dmabuf_ownership(buffer, queue_family, 1);
|
||||
assert(acquire.sType == VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER);
|
||||
assert(acquire.pNext == NULL);
|
||||
assert(acquire.srcQueueFamilyIndex == VK_QUEUE_FAMILY_FOREIGN_EXT);
|
||||
assert(acquire.dstQueueFamilyIndex == queue_family);
|
||||
assert(acquire.srcAccessMask == 0);
|
||||
assert(acquire.dstAccessMask == VK_ACCESS_TRANSFER_READ_BIT);
|
||||
assert(acquire.buffer == buffer);
|
||||
assert(acquire.offset == 0);
|
||||
assert(acquire.size == VK_WHOLE_SIZE);
|
||||
|
||||
const VkBufferMemoryBarrier release = vkp_linear_dmabuf_ownership(buffer, queue_family, 0);
|
||||
assert(release.sType == VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER);
|
||||
assert(release.srcQueueFamilyIndex == queue_family);
|
||||
assert(release.dstQueueFamilyIndex == VK_QUEUE_FAMILY_FOREIGN_EXT);
|
||||
assert(release.srcAccessMask == VK_ACCESS_TRANSFER_READ_BIT);
|
||||
assert(release.dstAccessMask == 0);
|
||||
assert(release.buffer == buffer);
|
||||
assert(release.size == VK_WHOLE_SIZE);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
check_padded_rows();
|
||||
check_offset_and_wide_texels();
|
||||
check_rejected_layouts();
|
||||
check_path_choice();
|
||||
check_foreign_image();
|
||||
check_readback_order();
|
||||
check_ownership();
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user