Signed-off-by: Henri Verbeet <hverbeet(a)codeweavers.com>
---
Makefile.am | 21 ++++++++++++--------
include/vkd3d_shader.h | 4 ++++
libs/vkd3d-shader/vkd3d_shader.map | 1 +
libs/vkd3d-shader/vkd3d_shader_main.c | 19 ++++++++++++++++++
libs/vkd3d/device.c | 3 ++-
tests/vkd3d_shader_api.c | 37 +++++++++++++++++++++++++++++++++++
6 files changed, 76 insertions(+), 9 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index 00a5f58..b172517 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,6 +1,6 @@
ACLOCAL_AMFLAGS = -I m4
AM_CFLAGS = @VKD3D_CFLAGS@
-AM_CPPFLAGS = -I$(srcdir)/include -I$(srcdir)/include/dummy -I$(srcdir)/include/private
+AM_CPPFLAGS = -I$(srcdir)/include -I$(srcdir)/include/private -I$(builddir)/include/private
AM_LDFLAGS = -no-undefined
widl_headers = \
@@ -58,7 +58,8 @@ vkd3d_demos_headers = \
demos/demo_win32.h \
demos/demo_xcb.h
-BUILT_SOURCES = $(widl_headers)
+BUILT_SOURCES = $(widl_headers) \
+ include/private/vkd3d_version.h
noinst_LTLIBRARIES = libvkd3d-common.la
libvkd3d_common_la_SOURCES = \
@@ -109,8 +110,7 @@ libvkd3d_la_SOURCES = \
libs/vkd3d/vkd3d_main.c \
libs/vkd3d/vkd3d_private.h \
libs/vkd3d/vkd3d_shaders.h \
- libs/vkd3d/vulkan_procs.h \
- libs/vkd3d_version.c
+ libs/vkd3d/vulkan_procs.h
libvkd3d_la_LDFLAGS = $(AM_LDFLAGS) -version-info 2:0:1
libvkd3d_la_LIBADD = libvkd3d-common.la libvkd3d-shader.la @DL_LIBS@ @PTHREAD_LIBS@
if HAVE_LD_VERSION_SCRIPT
@@ -208,10 +208,15 @@ libvkd3d.pc: $(srcdir)/libs/vkd3d/libvkd3d.pc.in Makefile
-e 's![@]PACKAGE_VERSION[@]!$(PACKAGE_VERSION)!g' \
$< > $@
-libs/vkd3d_version.c: dummy-vkd3d-version
- $(AM_V_GEN)version=`(GIT_DIR=$(top_srcdir)/.git git describe HEAD 2>/dev/null || echo "vkd3d-$(PACKAGE_VERSION)") | $(SED) -n -e '$$s/\(.*\)/const char vkd3d_build[] = "\1";/p'` && (echo $$version | cmp -s - $@) || echo $$version >$@ || ($(RM) $@ && exit 1)
-.SILENT: libs/vkd3d_version.c
-CLEANFILES += libs/vkd3d_version.c
+include/private/vkd3d_version.h: dummy-vkd3d-version
+ @$(MKDIR_P) include/private
+ version=`(GIT_DIR=$(top_srcdir)/.git git rev-parse --short HEAD 2>/dev/null || echo '') \
+ | $(SED) -e 's!\(..*\)! (git \1)!' \
+ | $(SED) -n -e '$$s!\(.*\)!#define VKD3D_VCS_ID "\1"!p'` \
+ && (echo $$version | cmp -s - $@) \
+ || echo $$version >$@ || ($(RM) $@ && exit 1)
+.SILENT: include/private/vkd3d_version.h
+CLEANFILES += include/private/vkd3d_version.h
.PHONY: dummy-vkd3d-version
dummy-vkd3d-version:
diff --git a/include/vkd3d_shader.h b/include/vkd3d_shader.h
index de2c0c7..92ce9b9 100644
--- a/include/vkd3d_shader.h
+++ b/include/vkd3d_shader.h
@@ -749,6 +749,8 @@ struct vkd3d_shader_signature
#ifndef VKD3D_SHADER_NO_PROTOTYPES
+const char *vkd3d_shader_get_version(unsigned int *major, unsigned int *minor);
+
int vkd3d_shader_compile(const struct vkd3d_shader_compile_info *compile_info,
struct vkd3d_shader_code *out, char **messages);
void vkd3d_shader_free_messages(char *messages);
@@ -779,6 +781,8 @@ void vkd3d_shader_free_shader_signature(struct vkd3d_shader_signature *signature
/*
* Function pointer typedefs for vkd3d-shader functions.
*/
+typedef const char *(*PFN_vkd3d_shader_get_version)(unsigned int *major, unsigned int *minor);
+
typedef int (*PFN_vkd3d_shader_compile)(const struct vkd3d_shader_compile_info *compile_info,
struct vkd3d_shader_code *out, char **messages);
typedef void (*PFN_vkd3d_shader_free_messages)(char *messages);
diff --git a/libs/vkd3d-shader/vkd3d_shader.map b/libs/vkd3d-shader/vkd3d_shader.map
index 9c9f0a5..eca7278 100644
--- a/libs/vkd3d-shader/vkd3d_shader.map
+++ b/libs/vkd3d-shader/vkd3d_shader.map
@@ -9,6 +9,7 @@ global:
vkd3d_shader_free_scan_descriptor_info;
vkd3d_shader_free_shader_code;
vkd3d_shader_free_shader_signature;
+ vkd3d_shader_get_version;
vkd3d_shader_parse_input_signature;
vkd3d_shader_parse_root_signature;
vkd3d_shader_scan;
diff --git a/libs/vkd3d-shader/vkd3d_shader_main.c b/libs/vkd3d-shader/vkd3d_shader_main.c
index cfac8e2..140bdd4 100644
--- a/libs/vkd3d-shader/vkd3d_shader_main.c
+++ b/libs/vkd3d-shader/vkd3d_shader_main.c
@@ -17,6 +17,7 @@
*/
#include "vkd3d_shader_private.h"
+#include "vkd3d_version.h"
#include <stdio.h>
@@ -1027,3 +1028,21 @@ void vkd3d_shader_free_shader_signature(struct vkd3d_shader_signature *signature
vkd3d_free(signature->elements);
signature->elements = NULL;
}
+
+const char *vkd3d_shader_get_version(unsigned int *major, unsigned int *minor)
+{
+ int x, y;
+
+ TRACE("major %p, minor %p.\n", major, minor);
+
+ if (major || minor)
+ {
+ vkd3d_parse_version(PACKAGE_VERSION, &x, &y);
+ if (major)
+ *major = x;
+ if (minor)
+ *minor = y;
+ }
+
+ return "vkd3d-shader " PACKAGE_VERSION VKD3D_VCS_ID;
+}
diff --git a/libs/vkd3d/device.c b/libs/vkd3d/device.c
index d88fde9..bef6477 100644
--- a/libs/vkd3d/device.c
+++ b/libs/vkd3d/device.c
@@ -17,6 +17,7 @@
*/
#include "vkd3d_private.h"
+#include "vkd3d_version.h"
#ifdef HAVE_DLFCN_H
#include <dlfcn.h>
@@ -460,7 +461,7 @@ static HRESULT vkd3d_instance_init(struct vkd3d_instance *instance,
VkResult vr;
HRESULT hr;
- TRACE("Build: %s.\n", vkd3d_build);
+ TRACE("Build: " PACKAGE_STRING VKD3D_VCS_ID ".\n");
if (!create_info->pfn_signal_event)
{
diff --git a/tests/vkd3d_shader_api.c b/tests/vkd3d_shader_api.c
index e25dd20..fab17ad 100644
--- a/tests/vkd3d_shader_api.c
+++ b/tests/vkd3d_shader_api.c
@@ -83,15 +83,18 @@ static void test_vkd3d_shader_pfns(void)
PFN_vkd3d_shader_parse_root_signature pfn_vkd3d_shader_parse_root_signature;
PFN_vkd3d_shader_free_root_signature pfn_vkd3d_shader_free_root_signature;
PFN_vkd3d_shader_free_shader_code pfn_vkd3d_shader_free_shader_code;
+ PFN_vkd3d_shader_get_version pfn_vkd3d_shader_get_version;
PFN_vkd3d_shader_compile pfn_vkd3d_shader_compile;
PFN_vkd3d_shader_scan pfn_vkd3d_shader_scan;
struct vkd3d_shader_versioned_root_signature_desc root_signature_desc;
+ unsigned int major, minor, expected_major, expected_minor;
struct vkd3d_shader_scan_descriptor_info descriptor_info;
struct vkd3d_shader_signature_element *element;
struct vkd3d_shader_compile_info compile_info;
struct vkd3d_shader_signature signature;
struct vkd3d_shader_code dxbc, spirv;
+ const char *version, *p;
int rc;
static const struct vkd3d_shader_versioned_root_signature_desc empty_rs_desc =
@@ -124,9 +127,17 @@ static void test_vkd3d_shader_pfns(void)
pfn_vkd3d_shader_parse_root_signature = vkd3d_shader_parse_root_signature;
pfn_vkd3d_shader_free_root_signature = vkd3d_shader_free_root_signature;
pfn_vkd3d_shader_free_shader_code = vkd3d_shader_free_shader_code;
+ pfn_vkd3d_shader_get_version = vkd3d_shader_get_version;
pfn_vkd3d_shader_compile = vkd3d_shader_compile;
pfn_vkd3d_shader_scan = vkd3d_shader_scan;
+ sscanf(PACKAGE_VERSION, "%d.%d", &expected_major, &expected_minor);
+ version = pfn_vkd3d_shader_get_version(&major, &minor);
+ p = strstr(version, "vkd3d-shader " PACKAGE_VERSION);
+ ok(p == version, "Got unexpected version string \"%s\"\n", version);
+ ok(major == expected_major, "Got unexpected major version %u.\n", major);
+ ok(minor == expected_minor, "Got unexpected minor version %u.\n", minor);
+
rc = pfn_vkd3d_shader_serialize_root_signature(&empty_rs_desc, &dxbc, NULL);
ok(rc == VKD3D_OK, "Got unexpected error code %d.\n", rc);
rc = pfn_vkd3d_shader_parse_root_signature(&dxbc, &root_signature_desc, NULL);
@@ -163,10 +174,36 @@ static void test_vkd3d_shader_pfns(void)
pfn_vkd3d_shader_free_scan_descriptor_info(&descriptor_info);
}
+static void test_version(void)
+{
+ unsigned int major, minor, expected_major, expected_minor;
+ const char *version, *p;
+
+ sscanf(PACKAGE_VERSION, "%d.%d", &expected_major, &expected_minor);
+
+ version = vkd3d_shader_get_version(NULL, NULL);
+ p = strstr(version, "vkd3d-shader " PACKAGE_VERSION);
+ ok(p == version, "Got unexpected version string \"%s\"\n", version);
+
+ major = ~0u;
+ vkd3d_shader_get_version(&major, NULL);
+ ok(major == expected_major, "Got unexpected major version %u.\n", major);
+
+ minor = ~0u;
+ vkd3d_shader_get_version(NULL, &minor);
+ ok(minor == expected_minor, "Got unexpected minor version %u.\n", minor);
+
+ major = minor = ~0u;
+ vkd3d_shader_get_version(&major, &minor);
+ ok(major == expected_major, "Got unexpected major version %u.\n", major);
+ ok(minor == expected_minor, "Got unexpected minor version %u.\n", minor);
+}
+
START_TEST(vkd3d_shader_api)
{
setlocale(LC_ALL, "");
run_test(test_invalid_shaders);
run_test(test_vkd3d_shader_pfns);
+ run_test(test_version);
}
--
2.11.0