Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
591aac5b30 |
No files matched your search
@@ -544,6 +544,26 @@ static int has_ext(VkExtensionProperties *e, uint32_t n, const char *name) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static VkResult create_device(const VkDeviceCreateInfo *dci, VkDeviceQueueCreateInfo *qci, int *high_priority) {
|
||||
VkDeviceQueueGlobalPriorityCreateInfoEXT gp = {
|
||||
.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_EXT,
|
||||
.globalPriority = VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT};
|
||||
qci->pNext = *high_priority ? &gp : NULL;
|
||||
VkResult dr = g_vk.CreateDevice(g_pd, dci, NULL, &g_dev);
|
||||
if (dr != VK_SUCCESS && *high_priority) {
|
||||
qci->pNext = NULL;
|
||||
const VkResult plain = g_vk.CreateDevice(g_pd, dci, NULL, &g_dev);
|
||||
if (plain == VK_SUCCESS) {
|
||||
droiddeck_log("gpu", "the driver refused a high-priority compositor queue (%s); using the default priority",
|
||||
vk_result_name(dr));
|
||||
*high_priority = 0;
|
||||
}
|
||||
dr = plain;
|
||||
}
|
||||
qci->pNext = NULL;
|
||||
return dr;
|
||||
}
|
||||
|
||||
static int is_proprietary(VkDriverId id) {
|
||||
return id == VK_DRIVER_ID_ARM_PROPRIETARY || id == VK_DRIVER_ID_QUALCOMM_PROPRIETARY ||
|
||||
id == VK_DRIVER_ID_IMAGINATION_PROPRIETARY || id == VK_DRIVER_ID_SAMSUNG_PROPRIETARY ||
|
||||
@@ -665,7 +685,7 @@ static int dev_init_once(void) {
|
||||
|
||||
static const char *const import_exts[4] = {"VK_KHR_external_memory_fd", "VK_EXT_external_memory_dma_buf",
|
||||
"VK_EXT_image_drm_format_modifier", "VK_KHR_image_format_list"};
|
||||
const char *dev_exts[9] = {VK_KHR_SWAPCHAIN_EXTENSION_NAME};
|
||||
const char *dev_exts[10] = {VK_KHR_SWAPCHAIN_EXTENSION_NAME};
|
||||
uint32_t n_dev_exts = 1;
|
||||
uint32_t ne = 0;
|
||||
g_vk.EnumerateDeviceExtensionProperties(g_pd, NULL, &ne, NULL);
|
||||
@@ -706,6 +726,11 @@ static int dev_init_once(void) {
|
||||
dev_exts[n_dev_exts++] = VK_ANDROID_EXTERNAL_MEMORY_ANDROID_HARDWARE_BUFFER_EXTENSION_NAME;
|
||||
dev_exts[n_dev_exts++] = VK_EXT_QUEUE_FAMILY_FOREIGN_EXTENSION_NAME;
|
||||
}
|
||||
const char *priority_ext = has_ext(exts, ne, "VK_KHR_global_priority") ? "VK_KHR_global_priority"
|
||||
: has_ext(exts, ne, VK_EXT_GLOBAL_PRIORITY_EXTENSION_NAME) ? VK_EXT_GLOBAL_PRIORITY_EXTENSION_NAME
|
||||
: NULL;
|
||||
if (priority_ext) dev_exts[n_dev_exts++] = priority_ext;
|
||||
int high_priority = priority_ext != NULL;
|
||||
free(exts);
|
||||
|
||||
float prio = 1.0f;
|
||||
@@ -715,13 +740,13 @@ static int dev_init_once(void) {
|
||||
VkDeviceCreateInfo dci = {.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, .pNext = fg_features,
|
||||
.queueCreateInfoCount = 1, .pQueueCreateInfos = &qci,
|
||||
.enabledExtensionCount = n_dev_exts, .ppEnabledExtensionNames = dev_exts};
|
||||
VkResult dr = g_vk.CreateDevice(g_pd, &dci, NULL, &g_dev);
|
||||
VkResult dr = create_device(&dci, &qci, &high_priority);
|
||||
if (dr != VK_SUCCESS && fg_features) {
|
||||
droiddeck_log("framegen", "the driver refused the LSFG feature set (%s); device created without it",
|
||||
vk_result_name(dr));
|
||||
dci.pNext = NULL;
|
||||
fg_features = NULL;
|
||||
dr = g_vk.CreateDevice(g_pd, &dci, NULL, &g_dev);
|
||||
dr = create_device(&dci, &qci, &high_priority);
|
||||
}
|
||||
if (dr != VK_SUCCESS) {
|
||||
LOGE("present: vkCreateDevice failed"); g_dev_state = -1;
|
||||
@@ -729,6 +754,7 @@ static int dev_init_once(void) {
|
||||
return -1;
|
||||
}
|
||||
vk_loader_load_device(g_dev);
|
||||
if (high_priority) droiddeck_log("gpu", "compositor queue runs at high GPU priority");
|
||||
log_display_driver();
|
||||
g_vk.GetDeviceQueue(g_dev, g_qfam, 0, &g_queue);
|
||||
vkp_gpu_busy_device(g_pd, g_dev, g_qfam);
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
from tools.tests.test_vk_pending_completion import function
|
||||
|
||||
SOURCE = Path(__file__).resolve().parents[2] / "app/src/main/cpp/waylandcomp/src/vk_present.c"
|
||||
|
||||
HARNESS = r'''
|
||||
#include <assert.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef int VkResult;
|
||||
typedef uintptr_t VkPhysicalDevice;
|
||||
typedef uintptr_t VkDevice;
|
||||
#define VK_SUCCESS 0
|
||||
#define VK_ERROR_INITIALIZATION_FAILED -3
|
||||
#define VK_ERROR_NOT_PERMITTED_EXT -1000174001
|
||||
#define VK_STRUCTURE_TYPE_DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_EXT 1000174000
|
||||
#define VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT 256
|
||||
#define VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT 512
|
||||
typedef struct { int sType; const void *pNext; int globalPriority; } VkDeviceQueueGlobalPriorityCreateInfoEXT;
|
||||
typedef struct { int sType; const void *pNext; uint32_t queueFamilyIndex; uint32_t queueCount;
|
||||
const float *pQueuePriorities; } VkDeviceQueueCreateInfo;
|
||||
typedef struct { int sType; const void *pNext; uint32_t queueCreateInfoCount;
|
||||
const VkDeviceQueueCreateInfo *pQueueCreateInfos; } VkDeviceCreateInfo;
|
||||
|
||||
static VkPhysicalDevice g_pd = 7;
|
||||
static VkDevice g_dev;
|
||||
static int calls, logs, high_seen[4];
|
||||
static VkResult answers[4];
|
||||
|
||||
static VkResult fake_create(VkPhysicalDevice pd, const VkDeviceCreateInfo *dci, const void *alloc, VkDevice *out) {
|
||||
assert(pd == 7 && !alloc && dci->queueCreateInfoCount == 1);
|
||||
const VkDeviceQueueGlobalPriorityCreateInfoEXT *gp = dci->pQueueCreateInfos[0].pNext;
|
||||
if (gp) assert(gp->sType == VK_STRUCTURE_TYPE_DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_EXT && !gp->pNext);
|
||||
high_seen[calls] = gp ? gp->globalPriority : VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT;
|
||||
const VkResult r = answers[calls++];
|
||||
if (r == VK_SUCCESS) *out = 42;
|
||||
return r;
|
||||
}
|
||||
static struct { VkResult (*CreateDevice)(VkPhysicalDevice, const VkDeviceCreateInfo *, const void *, VkDevice *); } g_vk = {
|
||||
fake_create};
|
||||
static const char *vk_result_name(VkResult r) { (void)r; return "result"; }
|
||||
static void droiddeck_log(const char *tag, const char *fmt, ...) { (void)tag; (void)fmt; logs++; }
|
||||
|
||||
%(create_device)s
|
||||
|
||||
static VkDeviceQueueCreateInfo qci;
|
||||
static VkDeviceCreateInfo dci = {.queueCreateInfoCount = 1, .pQueueCreateInfos = &qci};
|
||||
|
||||
static VkResult run(int *high, VkResult first, VkResult second) {
|
||||
calls = logs = 0;
|
||||
g_dev = 0;
|
||||
answers[0] = first;
|
||||
answers[1] = second;
|
||||
high_seen[0] = high_seen[1] = 0;
|
||||
const VkResult r = create_device(&dci, &qci, high);
|
||||
assert(qci.pNext == NULL);
|
||||
return r;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
int high = 1;
|
||||
assert(run(&high, VK_SUCCESS, -99) == VK_SUCCESS);
|
||||
assert(calls == 1 && high_seen[0] == VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT && high == 1 && logs == 0 && g_dev == 42);
|
||||
|
||||
high = 1;
|
||||
assert(run(&high, VK_ERROR_NOT_PERMITTED_EXT, VK_SUCCESS) == VK_SUCCESS);
|
||||
assert(calls == 2 && high_seen[0] == VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT);
|
||||
assert(high_seen[1] == VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT && high == 0 && logs == 1 && g_dev == 42);
|
||||
|
||||
assert(run(&high, VK_SUCCESS, -99) == VK_SUCCESS);
|
||||
assert(calls == 1 && high_seen[0] == VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT && logs == 0);
|
||||
|
||||
high = 1;
|
||||
assert(run(&high, VK_ERROR_INITIALIZATION_FAILED, VK_SUCCESS) == VK_SUCCESS);
|
||||
assert(calls == 2 && high == 0 && high_seen[1] == VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT);
|
||||
|
||||
high = 1;
|
||||
assert(run(&high, VK_ERROR_INITIALIZATION_FAILED, VK_ERROR_INITIALIZATION_FAILED) ==
|
||||
VK_ERROR_INITIALIZATION_FAILED);
|
||||
assert(calls == 2 && high == 1 && logs == 0 && g_dev == 0);
|
||||
assert(high_seen[0] == VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT && high_seen[1] == VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT);
|
||||
|
||||
high = 0;
|
||||
assert(run(&high, VK_ERROR_INITIALIZATION_FAILED, VK_SUCCESS) == VK_ERROR_INITIALIZATION_FAILED);
|
||||
assert(calls == 1 && high_seen[0] == VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT && logs == 0);
|
||||
return 0;
|
||||
}
|
||||
'''
|
||||
|
||||
|
||||
class CompositorQueuePriorityTest(unittest.TestCase):
|
||||
def test_high_priority_is_requested_and_dropped_when_the_driver_refuses_it(self):
|
||||
compiler = shutil.which(os.environ.get("CC", "cc"))
|
||||
if not compiler:
|
||||
self.fail("A C compiler is required for the compositor queue priority test")
|
||||
body = function(SOURCE.read_text(), "create_device")
|
||||
with tempfile.TemporaryDirectory(prefix="droiddeck-queue-priority-") as tmp:
|
||||
source = Path(tmp) / "queue_priority_test.c"
|
||||
source.write_text(HARNESS % {"create_device": body})
|
||||
program = Path(tmp) / "queue-priority"
|
||||
built = subprocess.run([compiler, "-std=c11", "-Wall", "-Wextra", "-Werror", "-UNDEBUG", str(source),
|
||||
"-o", str(program)], capture_output=True, text=True)
|
||||
self.assertEqual(built.returncode, 0, built.stdout + built.stderr)
|
||||
ran = subprocess.run([str(program)], capture_output=True, text=True, timeout=30)
|
||||
self.assertEqual(ran.returncode, 0, ran.stdout + ran.stderr)
|
||||
|
||||
def test_the_priority_extension_is_enabled_only_when_advertised_and_every_device_uses_it(self):
|
||||
text = SOURCE.read_text()
|
||||
self.assertEqual(len(re.findall(r"g_vk\.CreateDevice\(", text)), 2)
|
||||
self.assertEqual(len(re.findall(r"g_vk\.CreateDevice\(", function(text, "create_device"))), 2)
|
||||
self.assertEqual(len(re.findall(r"create_device\(&dci, &qci, &high_priority\)", text)), 2)
|
||||
self.assertRegex(text, r'has_ext\(exts, ne, "VK_KHR_global_priority"\)')
|
||||
self.assertRegex(text, r"has_ext\(exts, ne, VK_EXT_GLOBAL_PRIORITY_EXTENSION_NAME\)")
|
||||
self.assertRegex(text, r"if \(priority_ext\) dev_exts\[n_dev_exts\+\+\] = priority_ext;")
|
||||
self.assertRegex(text, r"int high_priority = priority_ext != NULL;")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user