Skip to content

Apple's open-source XNU kernel on Android phones: its own loader and drivers, Metal on the Adreno. Runs from RAM; a reboot gives the phone back to Android.

C

Turnip on Darwin: VK_NV_linear_color_attachment; the plug-in counts Turnip's GPU trace (m2v_utrace=1)

yehorkaa015ed5007402
diff --git a/tools/mesa/turnip-darwin.patch b/tools/mesa/turnip-darwin.patch
index c3f2a1c..b79c641 100644
--- a/tools/mesa/turnip-darwin.patch
+++ b/tools/mesa/turnip-darwin.patch
@@ -52,7 +52,7 @@ index 2474ad8..74d6f0c 100644
}
}
diff --git a/src/freedreno/vulkan/tu_device.cc b/src/freedreno/vulkan/tu_device.cc
-index 62ebfd0..951a198 100644
+index 62ebfd0..adb4e9c 100644
--- a/src/freedreno/vulkan/tu_device.cc
+++ b/src/freedreno/vulkan/tu_device.cc
@@ -8,6 +8,10 @@
@@ -66,18 +66,30 @@ index 62ebfd0..951a198 100644
#include "drm-uapi/drm_fourcc.h"
#include "fdl/freedreno_layout.h"
-@@ -269,6 +273,10 @@ get_device_extensions(const struct tu_physical_device *device,
+@@ -269,6 +273,12 @@ get_device_extensions(const struct tu_physical_device *device,
.EXT_extended_dynamic_state2 = true,
.EXT_extended_dynamic_state3 = true,
.EXT_external_memory_dma_buf = true,
+#if defined(__APPLE__) && defined(TU_HAS_MSM)
+ /* the memory of IOSurfaces, by their address (src/hakios-drm: hakios_drm_host_surface) */
+ .EXT_external_memory_host = true,
++ /* linear images rendered in place, as the hardware does (metal2vulkan renders an IOSurface so, not through a copy) */
++ .NV_linear_color_attachment = true,
+#endif
.EXT_filter_cubic = device->info->a6xx.has_tex_filter_cubic,
.EXT_fragment_density_map = true,
.EXT_global_priority = true,
-@@ -1160,6 +1168,9 @@ tu_get_properties(struct tu_physical_device *pdevice,
+@@ -697,6 +707,9 @@ tu_get_features(struct tu_physical_device *pdevice,
+
+ /* VK_EXT_rasterization_order_attachment_access */
+ features->rasterizationOrderColorAttachmentAccess = true;
++#if defined(__APPLE__) && defined(TU_HAS_MSM)
++ features->linearColorAttachment = true;
++#endif
+ features->rasterizationOrderDepthAttachmentAccess = true;
+ features->rasterizationOrderStencilAttachmentAccess = true;
+
+@@ -1160,6 +1173,9 @@ tu_get_properties(struct tu_physical_device *pdevice,
/* VK_EXT_custom_border_color */
props->maxCustomBorderColorSamplers = TU_BORDER_COLOR_COUNT;
@@ -87,7 +99,7 @@ index 62ebfd0..951a198 100644
/* VK_KHR_performance_query */
props->allowCommandBufferQueryCopies = false;
-@@ -2709,6 +2720,7 @@ tu_CreateDevice(VkPhysicalDevice physicalDevice,
+@@ -2709,6 +2725,7 @@ tu_CreateDevice(VkPhysicalDevice physicalDevice,
"pthread condattr init");
goto fail_timeline_cond;
}
@@ -95,7 +107,7 @@ index 62ebfd0..951a198 100644
if (pthread_condattr_setclock(&condattr, CLOCK_MONOTONIC) != 0) {
pthread_condattr_destroy(&condattr);
result = vk_startup_errorf(physical_device->instance,
-@@ -2716,6 +2728,7 @@ tu_CreateDevice(VkPhysicalDevice physicalDevice,
+@@ -2716,6 +2733,7 @@ tu_CreateDevice(VkPhysicalDevice physicalDevice,
"pthread condattr clock setup");
goto fail_timeline_cond;
}
@@ -103,7 +115,7 @@ index 62ebfd0..951a198 100644
if (pthread_cond_init(&device->timeline_cond, &condattr) != 0) {
pthread_condattr_destroy(&condattr);
result = vk_startup_errorf(physical_device->instance,
-@@ -3015,6 +3028,16 @@ vk_icdGetInstanceProcAddr(VkInstance instance, const char *pName)
+@@ -3015,6 +3033,16 @@ vk_icdGetInstanceProcAddr(VkInstance instance, const char *pName)
return tu_GetInstanceProcAddr(instance, pName);
}
@@ -120,7 +132,7 @@ index 62ebfd0..951a198 100644
VKAPI_ATTR VkResult VKAPI_CALL
tu_AllocateMemory(VkDevice _device,
const VkMemoryAllocateInfo *pAllocateInfo,
-@@ -3064,6 +3087,17 @@ tu_AllocateMemory(VkDevice _device,
+@@ -3064,6 +3092,17 @@ tu_AllocateMemory(VkDevice _device,
/* take ownership and close the fd */
close(fd_info->fd);
}
@@ -138,7 +150,7 @@ index 62ebfd0..951a198 100644
} else if (mem->vk.ahardware_buffer) {
#if DETECT_OS_ANDROID
const native_handle_t *handle = AHardwareBuffer_getNativeHandle(mem->vk.ahardware_buffer);
-@@ -3402,6 +3436,21 @@ tu_GetMemoryFdPropertiesKHR(VkDevice _device,
+@@ -3402,6 +3441,21 @@ tu_GetMemoryFdPropertiesKHR(VkDevice _device,
return VK_SUCCESS;
}
@@ -160,6 +172,21 @@ index 62ebfd0..951a198 100644
VKAPI_ATTR void VKAPI_CALL
tu_GetPhysicalDeviceMultisamplePropertiesEXT(
VkPhysicalDevice physicalDevice,
+diff --git a/src/freedreno/vulkan/tu_formats.cc b/src/freedreno/vulkan/tu_formats.cc
+index cb134a9..3ac1bf9 100644
+--- a/src/freedreno/vulkan/tu_formats.cc
++++ b/src/freedreno/vulkan/tu_formats.cc
+@@ -236,6 +236,10 @@ tu_physical_device_get_format_properties(
+ * DEPTH_STENCIL_ATTACHMENT_BIT for the optimal features.
+ */
+ linear = optimal;
++#if defined(__APPLE__) && defined(TU_HAS_MSM)
++ if (linear & VK_FORMAT_FEATURE_2_COLOR_ATTACHMENT_BIT)
++ linear |= VK_FORMAT_FEATURE_2_LINEAR_COLOR_ATTACHMENT_BIT_NV;
++#endif
+ if (tu6_pipe2depth(vk_format) != DEPTH6_NONE)
+ optimal |= VK_FORMAT_FEATURE_2_DEPTH_STENCIL_ATTACHMENT_BIT;
+
diff --git a/src/freedreno/vulkan/tu_knl.cc b/src/freedreno/vulkan/tu_knl.cc
index 80e3900..3f00525 100644
--- a/src/freedreno/vulkan/tu_knl.cc
diff --git a/userland/src/HakiosMetalCA.m b/userland/src/HakiosMetalCA.m
index 15ad59c..4084cc3 100644
--- a/userland/src/HakiosMetalCA.m
+++ b/userland/src/HakiosMetalCA.m
@@ -2099,6 +2099,11 @@ hm_boot_arg_set(const char *what)
});
}
}
+ /* boot-arg m2v_utrace=1: Turnip's GPU trace of every render pass (u_trace) into a file, printed during the run */
+ if (hm_boot_arg_set("m2v_utrace=1")) {
+ setenv("MESA_GPU_TRACES", "print", 1);
+ setenv("MESA_GPU_TRACEFILE", "/private/var/tmp/m2v-utrace.txt", 1);
+ }
if (&native_bridge_metal_variant_hook != NULL) {
native_bridge_metal_variant_hook = hm_m2v_variant;
}
@@ -2138,6 +2143,38 @@ hm_boot_arg_set(const char *what)
if (hm_m2v_last_stderr[0] != 0) {
hm_print("metal2vulkan: last stderr: %s", hm_m2v_last_stderr);
}
+ /* the GPU trace (m2v_utrace=1): each kind of event since the last status, counted, at the 16th to the
+ * 34th status (the gestures), the 30 commonest */
+ {
+ static int tick;
+ static long read_to;
+ FILE *trace = fopen("/private/var/tmp/m2v-utrace.txt", "r");
+ ++tick;
+ if (trace != NULL) {
+ char line[400];
+ NSCountedSet *kinds = (tick >= 16 && tick <= 34) ? [NSCountedSet set] : nil;
+ fseek(trace, read_to, SEEK_SET);
+ while (fgets(line, sizeof(line), trace) != NULL) {
+ char *at = strstr(line, ": ");
+ if (kinds == nil || at == NULL) continue;
+ at += 2;
+ at[strcspn(at, "\n")] = 0;
+ if (strncmp(at, "end_", 4) == 0) continue;
+ [kinds addObject:@(at)];
+ }
+ read_to = ftell(trace);
+ fclose(trace);
+ if ([kinds count] > 0) {
+ NSArray *sorted = [[kinds allObjects] sortedArrayUsingComparator:^NSComparisonResult(id a, id b) {
+ return [@([kinds countForObject:b]) compare:@([kinds countForObject:a])];
+ }];
+ for (NSUInteger i = 0; i < [sorted count] && i < 30; i++) {
+ hm_print("utrace %d: %6lu %s\n", tick, (unsigned long)[kinds countForObject:sorted[i]],
+ [[sorted[i] substringToIndex:MIN([sorted[i] length], 200)] UTF8String]);
+ }
+ }
+ }
+ }
/* the textures the runtime keeps a shadow image of, and why (its shadow.log): the first 40 */
{
static long read_to;