Commit f972c4fd authored by Niklas Haas's avatar Niklas Haas

gpu: expose the device UUID for interop purposes

The exported memory/sync handles don't really make sense if we don't
expose the device UUID they belong to. This is a cross-API concept.
parent d3951371
......@@ -69,6 +69,26 @@ void pl_gpu_print_info(const struct pl_gpu *gpu, enum pl_log_level lev)
LOG(PRIu32, align_tex_xfer_stride);
LOG("zu", align_tex_xfer_offset);
#undef LOG
if (pl_gpu_supports_interop(gpu)) {
PL_MSG(gpu, lev, " External API interop:");
// Pretty-print the device UUID
static const char *hexdigits = "0123456789ABCDEF";
char buf[3 * sizeof(gpu->uuid)];
for (int i = 0; i < sizeof(gpu->uuid); i++) {
uint8_t x = gpu->uuid[i];
buf[3 * i + 0] = hexdigits[x >> 4];
buf[3 * i + 1] = hexdigits[x & 0xF];
buf[3 * i + 2] = i == sizeof(gpu->uuid) - 1 ? '\0' : ':';
}
PL_MSG(gpu, lev, " UUID: %s", buf);
PL_MSG(gpu, lev, " shared memory caps: 0x%x",
(unsigned int) gpu->handle_caps.shared_mem);
PL_MSG(gpu, lev, " sync caps: 0x%x",
(unsigned int) gpu->handle_caps.sync);
}
}
static int cmp_fmt(const void *pa, const void *pb)
......
......@@ -54,6 +54,13 @@ struct pl_gpu_fns {
// destroyed before calling pl_destroy.
void pl_gpu_destroy(const struct pl_gpu *gpu);
// Returns true if the device supports interop. This is considered to be
// the case if at least one of `gpu->handle_caps` is nonzero.
static inline bool pl_gpu_supports_interop(const struct pl_gpu *gpu)
{
return gpu->handle_caps.shared_mem || gpu->handle_caps.sync;
}
// GPU-internal helpers: these should not be used outside of GPU implementations
// Log some metadata about the created GPU
......
......@@ -121,7 +121,9 @@ struct pl_gpu {
// Note: Every GPU must support at least one of PL_GPU_CAP_INPUT_VARIABLES
// or uniform buffers (limits.max_ubo_size > 0).
// Structure defining the handle types for external API interop
// Fields relevant to external API interop. If the underlying device does
// not support interop with other APIs, these will all be {0}.
uint8_t uuid[16]; // underlying device UUID
struct {
pl_handle_caps shared_mem; // supported handles for pl_shared_mem
pl_handle_caps sync; // supported handles for pl_sync
......
......@@ -263,6 +263,22 @@ const struct pl_gpu *pl_gpu_create_vk(struct vk_ctx *vk)
gpu->handle_caps.shared_mem = vk_malloc_handle_caps(p->alloc);
gpu->handle_caps.sync = vk_sync_handle_caps(vk);
if (pl_gpu_supports_interop(gpu)) {
VkPhysicalDeviceIDPropertiesKHR id_props = {
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES_KHR,
};
VkPhysicalDeviceProperties2KHR props = {
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR,
.pNext = &id_props,
};
VK_LOAD_FUN(vk->inst, vkGetPhysicalDeviceProperties2KHR);
vkGetPhysicalDeviceProperties2KHR(vk->physd, &props);
assert(sizeof(gpu->uuid) == VK_UUID_SIZE);
memcpy(gpu->uuid, id_props.deviceUUID, sizeof(gpu->uuid));
}
if (vk->vkCmdPushDescriptorSetKHR) {
VkPhysicalDevicePushDescriptorPropertiesKHR pushd = {
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment