From 5f6795309f3377f114f8c7ca22047cf0251801ec Mon Sep 17 00:00:00 2001 From: Jesse Natalie Date: Sat, 9 Jul 2022 14:47:02 -0700 Subject: [PATCH] d3d12: Compute UUIDs required by external objects extension Reviewed-by: Bill Kristiansen Reviewed-by: Giancarlo Devich Part-of: --- src/gallium/drivers/d3d12/d3d12_screen.cpp | 24 ++++++++++++++++++++++ src/gallium/drivers/d3d12/d3d12_screen.h | 2 ++ src/gallium/drivers/d3d12/meson.build | 2 +- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/gallium/drivers/d3d12/d3d12_screen.cpp b/src/gallium/drivers/d3d12/d3d12_screen.cpp index 48c5eb6652c..472a8fb0e80 100644 --- a/src/gallium/drivers/d3d12/d3d12_screen.cpp +++ b/src/gallium/drivers/d3d12/d3d12_screen.cpp @@ -42,11 +42,13 @@ #include "util/u_memory.h" #include "util/u_screen.h" #include "util/u_dl.h" +#include "util/mesa-sha1.h" #include "nir.h" #include "frontend/sw_winsys.h" #include "nir_to_dxil.h" +#include "git_sha1.h" #include @@ -1311,6 +1313,28 @@ d3d12_init_screen(struct d3d12_screen *screen, IUnknown *adapter) if (!screen->opts.DoublePrecisionFloatShaderOps) screen->nir_options.lower_doubles_options = (nir_lower_doubles_options)~0; + const char *mesa_version = "Mesa " PACKAGE_VERSION MESA_GIT_SHA1; + struct mesa_sha1 sha1_ctx; + uint8_t sha1[SHA1_DIGEST_LENGTH]; + STATIC_ASSERT(PIPE_UUID_SIZE <= sizeof(sha1)); + + /* The driver UUID is used for determining sharability of images and memory + * between two instances in separate processes. People who want to + * share memory need to also check the device UUID or LUID so all this + * needs to be is the build-id. + */ + _mesa_sha1_compute(mesa_version, strlen(mesa_version), sha1); + memcpy(screen->driver_uuid, sha1, PIPE_UUID_SIZE); + + /* The device UUID uniquely identifies the given device within the machine. */ + _mesa_sha1_init(&sha1_ctx); + _mesa_sha1_update(&sha1_ctx, &screen->vendor_id, sizeof(screen->vendor_id)); + _mesa_sha1_update(&sha1_ctx, &screen->device_id, sizeof(screen->device_id)); + _mesa_sha1_update(&sha1_ctx, &screen->subsys_id, sizeof(screen->subsys_id)); + _mesa_sha1_update(&sha1_ctx, &screen->revision, sizeof(screen->revision)); + _mesa_sha1_final(&sha1_ctx, sha1); + memcpy(screen->device_uuid, sha1, PIPE_UUID_SIZE); + glsl_type_singleton_init_or_ref(); return true; } diff --git a/src/gallium/drivers/d3d12/d3d12_screen.h b/src/gallium/drivers/d3d12/d3d12_screen.h index 0f23b83a833..6c96aefe807 100644 --- a/src/gallium/drivers/d3d12/d3d12_screen.h +++ b/src/gallium/drivers/d3d12/d3d12_screen.h @@ -60,6 +60,8 @@ struct d3d12_screen { struct pipe_screen base; struct sw_winsys *winsys; LUID adapter_luid; + char driver_uuid[PIPE_UUID_SIZE]; + char device_uuid[PIPE_UUID_SIZE]; ID3D12Device3 *dev; ID3D12CommandQueue *cmdqueue; diff --git a/src/gallium/drivers/d3d12/meson.build b/src/gallium/drivers/d3d12/meson.build index 9c961d323e4..a0de2cb1866 100644 --- a/src/gallium/drivers/d3d12/meson.build +++ b/src/gallium/drivers/d3d12/meson.build @@ -71,7 +71,7 @@ endif libd3d12 = static_library( 'd3d12', - files_libd3d12, + [files_libd3d12, sha1_h], gnu_symbol_visibility : 'hidden', include_directories : [inc_include, inc_src, inc_mesa, inc_gallium, inc_gallium_aux], dependencies: [idep_nir_headers, idep_libdxil_compiler, dep_dxheaders],