mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-29 09:35:38 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ceb4c18531 |
No files matched your search
@@ -8,6 +8,10 @@ static inline int vkp_linear_dmabuf_through_buffer(int drm_modifiers, uint64_t m
|
||||
return !drm_modifiers && modifier == 0 && !blit_dst;
|
||||
}
|
||||
|
||||
static inline int vkp_dmabuf_layout_describable(int drm_modifiers, uint64_t modifier) {
|
||||
return drm_modifiers || modifier == 0;
|
||||
}
|
||||
|
||||
static inline int vkp_linear_dmabuf_foreign_image(int dmabuf, int staged) {
|
||||
return dmabuf && !staged;
|
||||
}
|
||||
|
||||
@@ -1324,6 +1324,11 @@ struct vkp_image *vkp_image_import_dmabuf(int fd, uint32_t drm_format, uint64_t
|
||||
uint32_t stride, uint32_t offset, int as_blit_dst) {
|
||||
if (modifier == MOD_INVALID || w <= 0 || h <= 0) return NULL;
|
||||
if (dev_init() != 0) return NULL;
|
||||
if (!vkp_dmabuf_layout_describable(g_drm_modifiers, modifier)) {
|
||||
LOGE("%s: the driver has no VK_EXT_image_drm_format_modifier to lay out the %s %dx%d dma-buf",
|
||||
as_blit_dst ? "layer" : "dmabuf", vkp_modifier_name(modifier), w, h);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const VkFormat format = drm_to_vk(drm_format);
|
||||
const int padded_target = as_blit_dst &&
|
||||
|
||||
@@ -109,9 +109,11 @@ static struct droiddeck_native_handle handle = {.numFds = 1, .data = {3}};
|
||||
static AHardwareBuffer *buffer = (AHardwareBuffer *)&handle;
|
||||
static struct vkp_image image;
|
||||
static int allocations, imports_10_bit, imports_8_bit, accept_10_bit, accept_8_bit;
|
||||
static int qti_handle, refuse_compressed, compressed_imports;
|
||||
static uint64_t allocated_usage;
|
||||
|
||||
static int AHardwareBuffer_allocate(const AHardwareBuffer_Desc *d, AHardwareBuffer **out) {
|
||||
(void)d; allocations++; *out = buffer; return 0;
|
||||
allocations++; allocated_usage = d->usage; *out = buffer; return 0;
|
||||
}
|
||||
static void AHardwareBuffer_describe(const AHardwareBuffer *b, AHardwareBuffer_Desc *d) {
|
||||
(void)b; d->stride = 1920; d->usage = 0;
|
||||
@@ -119,14 +121,20 @@ static void AHardwareBuffer_describe(const AHardwareBuffer *b, AHardwareBuffer_D
|
||||
static void AHardwareBuffer_release(AHardwareBuffer *b) { (void)b; }
|
||||
static const void *native_handle(const AHardwareBuffer *b) { (void)b; return &handle; }
|
||||
static struct { const void *(*getNativeHandle)(const AHardwareBuffer *); } api = {native_handle};
|
||||
static int sniff_modifier(const struct droiddeck_native_handle *h, uint64_t *mod) { (void)h; (void)mod; return 0; }
|
||||
static int sniff_modifier(const struct droiddeck_native_handle *h, uint64_t *mod) {
|
||||
(void)h;
|
||||
if (!qti_handle) return 0;
|
||||
*mod = (allocated_usage & SC_LAYER_AHB_USAGE_VENDOR_UBWC) ? MOD_QCOM_COMPRESSED : MOD_LINEAR;
|
||||
return 1;
|
||||
}
|
||||
static int vkp_can_import_ahb(void) { return 0; }
|
||||
static struct vkp_image *vkp_image_import_ahb(AHardwareBuffer *b, char *info, size_t n) {
|
||||
(void)b; (void)info; (void)n; return NULL;
|
||||
}
|
||||
static struct vkp_image *vkp_image_import_dmabuf(int fd, uint32_t drm, uint64_t mod, int w, int h, uint32_t pitch,
|
||||
uint32_t offset, int planes) {
|
||||
(void)fd; (void)mod; (void)w; (void)h; (void)pitch; (void)offset; (void)planes;
|
||||
(void)fd; (void)w; (void)h; (void)pitch; (void)offset; (void)planes;
|
||||
if (mod != MOD_LINEAR) { compressed_imports++; return refuse_compressed ? NULL : ℑ }
|
||||
if (drm == DRM_ABGR2101010) { imports_10_bit++; return accept_10_bit ? &image : NULL; }
|
||||
imports_8_bit++;
|
||||
return accept_8_bit ? &image : NULL;
|
||||
@@ -187,6 +195,26 @@ int main(void) {
|
||||
assert(frame(¬hing_imports) == -1 && g_alloc_failed);
|
||||
assert(allocations == tried);
|
||||
assert(imports_10_bit == 1 && imports_8_bit == 1);
|
||||
|
||||
int fd;
|
||||
struct layer ubwc_without_modifiers = {.name = "game", .pool_n = 3};
|
||||
reset(0, 1);
|
||||
qti_handle = 1; refuse_compressed = 1; compressed_imports = 0;
|
||||
assert(take_free_slot(&ubwc_without_modifiers, 1558, 720, AHB_RGBA8, &fd) == 0);
|
||||
assert(compressed_imports == 1 && imports_8_bit == 1);
|
||||
assert(ubwc_without_modifiers.alloc_tier == TIER_PLAIN);
|
||||
assert(ubwc_without_modifiers.pool_modifier == MOD_LINEAR);
|
||||
assert(!(allocated_usage & SC_LAYER_AHB_USAGE_VENDOR_UBWC));
|
||||
assert(take_free_slot(&ubwc_without_modifiers, 1558, 720, AHB_RGBA8, &fd) == 0);
|
||||
assert(compressed_imports == 1 && imports_8_bit == 2);
|
||||
|
||||
struct layer ubwc_with_modifiers = {.name = "game", .pool_n = 3};
|
||||
reset(0, 1);
|
||||
refuse_compressed = 0; compressed_imports = 0;
|
||||
assert(take_free_slot(&ubwc_with_modifiers, 1558, 720, AHB_RGBA8, &fd) == 0);
|
||||
assert(compressed_imports == 1 && imports_8_bit == 0);
|
||||
assert(ubwc_with_modifiers.alloc_tier == TIER_UBWC);
|
||||
assert(ubwc_with_modifiers.pool_modifier == MOD_QCOM_COMPRESSED);
|
||||
return 0;
|
||||
}
|
||||
'''
|
||||
|
||||
@@ -116,6 +116,14 @@ class VkLinearDmabufTest(unittest.TestCase):
|
||||
self.assertIn("!as_blit_dst", terms)
|
||||
self.assertIn("g_vk.GetPhysicalDeviceImageFormatProperties2", terms)
|
||||
|
||||
def test_undescribable_layout_is_refused_before_any_image_is_made(self):
|
||||
body = function((SRC / "vk_present.c").read_text(), "vkp_image_import_dmabuf")
|
||||
guard = body.index("if (!vkp_dmabuf_layout_describable(g_drm_modifiers, modifier))")
|
||||
self.assertLess(body.index("dev_init()"), guard)
|
||||
self.assertIn("return NULL;", body[guard:body.index("drm_to_vk(drm_format)")])
|
||||
self.assertLess(guard, body.index("calloc(1, sizeof(*img))"))
|
||||
self.assertLess(guard, body.index("VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT"))
|
||||
|
||||
def test_staged_client_image_stays_layer_candidate(self):
|
||||
vk = (SRC / "vk_present.c").read_text()
|
||||
comp = (SRC / "compositor.c").read_text()
|
||||
|
||||
@@ -56,6 +56,18 @@ static void check_path_choice(void) {
|
||||
assert(!vkp_linear_dmabuf_through_buffer(1, linear, 1));
|
||||
}
|
||||
|
||||
static void check_describable_layouts(void) {
|
||||
const uint64_t linear = 0;
|
||||
const uint64_t qcom_compressed = 0x0500000000000001ULL;
|
||||
const uint64_t arm_afbc = 0x0800000000000001ULL;
|
||||
assert(vkp_dmabuf_layout_describable(0, linear));
|
||||
assert(vkp_dmabuf_layout_describable(1, linear));
|
||||
assert(vkp_dmabuf_layout_describable(1, qcom_compressed));
|
||||
assert(vkp_dmabuf_layout_describable(1, arm_afbc));
|
||||
assert(!vkp_dmabuf_layout_describable(0, qcom_compressed));
|
||||
assert(!vkp_dmabuf_layout_describable(0, arm_afbc));
|
||||
}
|
||||
|
||||
static void check_foreign_image(void) {
|
||||
assert(vkp_linear_dmabuf_foreign_image(1, 0));
|
||||
assert(!vkp_linear_dmabuf_foreign_image(1, 1));
|
||||
@@ -117,6 +129,7 @@ int main(void) {
|
||||
check_rejected_layouts();
|
||||
check_path_choice();
|
||||
check_padded_layer_targets();
|
||||
check_describable_layouts();
|
||||
check_foreign_image();
|
||||
check_readback_order();
|
||||
check_ownership();
|
||||
|
||||
Reference in new issue
Block a user