[Mesa-dev] [PATCH mesa 17/21] anv: Add new VK_MESA_query_timestamp extension to anv driver
Keith Packard
keithp at keithp.com
Thu Mar 8 07:25:15 UTC 2018
This extension adds a single function to query the current GPU
timestamp, just like glGetInteger64v(GL_TIMESTAMP, ×tamp). This
function is needed to complete the implementation of
GOOGLE_display_timing, which needs to be able to correlate GPU and CPU
timestamps.
Signed-off-by: Keith Packard <keithp at keithp.com>
---
src/intel/Makefile.vulkan.am | 7 +++++++
src/intel/vulkan/anv_extensions.py | 1 +
src/intel/vulkan/anv_gem.c | 13 +++++++++++++
src/intel/vulkan/anv_private.h | 2 ++
src/intel/vulkan/genX_query.c | 15 +++++++++++++++
src/intel/vulkan/meson.build | 12 ++++++------
6 files changed, 44 insertions(+), 6 deletions(-)
diff --git a/src/intel/Makefile.vulkan.am b/src/intel/Makefile.vulkan.am
index d4e36e8e36b..7d9646e40a7 100644
--- a/src/intel/Makefile.vulkan.am
+++ b/src/intel/Makefile.vulkan.am
@@ -24,36 +24,43 @@
# out and we'll fail at `make dist'
vulkan_api_xml = $(top_srcdir)/src/vulkan/registry/vk.xml
vk_android_native_buffer_xml = $(top_srcdir)/src/vulkan/registry/vk_android_native_buffer.xml
+vk_mesa_query_timestamp_xml = $(top_srcdir)/src/vulkan/registry/vk_mesa_query_timestamp.xml
vulkan/anv_entrypoints.c: vulkan/anv_entrypoints_gen.py \
vulkan/anv_extensions.py \
$(vulkan_api_xml) \
+ $(vk_mesa_query_timestamp_xml) \
$(vk_android_native_buffer_xml)
$(MKDIR_GEN)
$(AM_V_GEN)$(PYTHON2) $(srcdir)/vulkan/anv_entrypoints_gen.py \
--xml $(vulkan_api_xml) \
--xml $(vk_android_native_buffer_xml) \
+ --xml $(vk_mesa_query_timestamp_xml) \
--outdir $(builddir)/vulkan
vulkan/anv_entrypoints.h: vulkan/anv_entrypoints.c
vulkan/anv_extensions.c: vulkan/anv_extensions_gen.py \
vulkan/anv_extensions.py \
$(vulkan_api_xml) \
+ $(vk_mesa_query_timestamp_xml) \
$(vk_android_native_buffer_xml)
$(MKDIR_GEN)
$(AM_V_GEN)$(PYTHON2) $(srcdir)/vulkan/anv_extensions_gen.py \
--xml $(vulkan_api_xml) \
--xml $(vk_android_native_buffer_xml) \
+ --xml $(vk_mesa_query_timestamp_xml) \
--out-c $@
vulkan/anv_extensions.h: vulkan/anv_extensions_gen.py \
vulkan/anv_extensions.py \
$(vulkan_api_xml) \
+ $(vk_mesa_query_timestamp_xml) \
$(vk_android_native_buffer_xml)
$(MKDIR_GEN)
$(AM_V_GEN)$(PYTHON2) $(srcdir)/vulkan/anv_extensions_gen.py \
--xml $(vulkan_api_xml) \
--xml $(vk_android_native_buffer_xml) \
+ --xml $(vk_mesa_query_timestamp_xml) \
--out-h $@
BUILT_SOURCES += $(VULKAN_GENERATED_FILES)
diff --git a/src/intel/vulkan/anv_extensions.py b/src/intel/vulkan/anv_extensions.py
index 219919f11b8..508811ebd24 100644
--- a/src/intel/vulkan/anv_extensions.py
+++ b/src/intel/vulkan/anv_extensions.py
@@ -116,6 +116,7 @@ EXTENSIONS = [
'device->has_context_priority'),
Extension('VK_EXT_display_surface_counter', 1, 'VK_USE_PLATFORM_DISPLAY_KHR'),
Extension('VK_EXT_display_control', 1, 'VK_USE_PLATFORM_DISPLAY_KHR'),
+ Extension('VK_MESA_query_timestamp', 1, True),
]
class VkVersion:
diff --git a/src/intel/vulkan/anv_gem.c b/src/intel/vulkan/anv_gem.c
index 2a8f8b14b7e..a7eb5cf4366 100644
--- a/src/intel/vulkan/anv_gem.c
+++ b/src/intel/vulkan/anv_gem.c
@@ -441,6 +441,19 @@ anv_gem_fd_to_handle(struct anv_device *device, int fd)
return args.handle;
}
+int
+anv_gem_reg_read(struct anv_device *device, uint32_t offset, uint64_t *result)
+{
+ struct drm_i915_reg_read args = {
+ .offset = offset
+ };
+
+ int ret = anv_ioctl(device->fd, DRM_IOCTL_I915_REG_READ, &args);
+
+ *result = args.val;
+ return ret;
+}
+
#ifndef SYNC_IOC_MAGIC
/* duplicated from linux/sync_file.h to avoid build-time dependency
* on new (v4.7) kernel headers. Once distro's are mostly using
diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h
index 6eedc0a25ff..0b2380b2876 100644
--- a/src/intel/vulkan/anv_private.h
+++ b/src/intel/vulkan/anv_private.h
@@ -70,6 +70,7 @@ struct gen_l3_config;
#include <vulkan/vulkan_intel.h>
#include <vulkan/vk_icd.h>
#include <vulkan/vk_android_native_buffer.h>
+#include <vulkan/vk_mesa_query_timestamp.h>
#include "anv_entrypoints.h"
#include "anv_extensions.h"
@@ -960,6 +961,7 @@ bool anv_gem_supports_48b_addresses(int fd);
int anv_gem_gpu_get_reset_stats(struct anv_device *device,
uint32_t *active, uint32_t *pending);
int anv_gem_handle_to_fd(struct anv_device *device, uint32_t gem_handle);
+int anv_gem_reg_read(struct anv_device *device, uint32_t offset, uint64_t *result);
uint32_t anv_gem_fd_to_handle(struct anv_device *device, int fd);
int anv_gem_set_caching(struct anv_device *device, uint32_t gem_handle, uint32_t caching);
int anv_gem_set_domain(struct anv_device *device, uint32_t gem_handle,
diff --git a/src/intel/vulkan/genX_query.c b/src/intel/vulkan/genX_query.c
index 4efcc57e475..d2de7e5f45e 100644
--- a/src/intel/vulkan/genX_query.c
+++ b/src/intel/vulkan/genX_query.c
@@ -546,6 +546,21 @@ void genX(CmdWriteTimestamp)(
}
}
+VkResult genX(QueryCurrentTimestampMESA)(
+ VkDevice _device,
+ uint64_t *timestamp)
+{
+ ANV_FROM_HANDLE(anv_device, device, _device);
+ int ret;
+
+ /* XXX older kernels don't support this interface. */
+ ret = anv_gem_reg_read(device, TIMESTAMP | 1, timestamp);
+
+ if (ret != 0)
+ return VK_ERROR_DEVICE_LOST;
+ return VK_SUCCESS;
+}
+
#if GEN_GEN > 7 || GEN_IS_HASWELL
static uint32_t
diff --git a/src/intel/vulkan/meson.build b/src/intel/vulkan/meson.build
index 307464476a6..950662fb84c 100644
--- a/src/intel/vulkan/meson.build
+++ b/src/intel/vulkan/meson.build
@@ -22,10 +22,10 @@ anv_extensions_py = files('anv_extensions.py')
anv_entrypoints = custom_target(
'anv_entrypoints.[ch]',
- input : ['anv_entrypoints_gen.py', vk_api_xml, vk_android_native_buffer_xml],
+ input : ['anv_entrypoints_gen.py', vk_api_xml, vk_android_native_buffer_xml, vk_mesa_query_timestamp_xml ],
output : ['anv_entrypoints.h', 'anv_entrypoints.c'],
command : [
- prog_python2, '@INPUT0@', '--xml', '@INPUT1@', '--xml', '@INPUT2@',
+ prog_python2, '@INPUT0@', '--xml', '@INPUT1@', '--xml', '@INPUT2@', '--xml', '@INPUT3@',
'--outdir', meson.current_build_dir(),
],
depend_files : anv_extensions_py,
@@ -33,10 +33,10 @@ anv_entrypoints = custom_target(
anv_extensions_c = custom_target(
'anv_extensions.c',
- input : ['anv_extensions_gen.py', vk_api_xml, vk_android_native_buffer_xml],
+ input : ['anv_extensions_gen.py', vk_api_xml, vk_android_native_buffer_xml, vk_mesa_query_timestamp_xml ],
output : 'anv_extensions.c',
command : [
- prog_python2, '@INPUT0@', '--xml', '@INPUT1@', '--xml', '@INPUT2@',
+ prog_python2, '@INPUT0@', '--xml', '@INPUT1@', '--xml', '@INPUT2@', '--xml', '@INPUT3@',
'--out-c', '@OUTPUT@',
],
depend_files : anv_extensions_py,
@@ -44,10 +44,10 @@ anv_extensions_c = custom_target(
anv_extensions_h = custom_target(
'anv_extensions.h',
- input : ['anv_extensions_gen.py', vk_api_xml, vk_android_native_buffer_xml],
+ input : ['anv_extensions_gen.py', vk_api_xml, vk_android_native_buffer_xml, vk_mesa_query_timestamp_xml ],
output : 'anv_extensions.h',
command : [
- prog_python2, '@INPUT0@', '--xml', '@INPUT1@', '--xml', '@INPUT2@',
+ prog_python2, '@INPUT0@', '--xml', '@INPUT1@', '--xml', '@INPUT2@', '--xml', '@INPUT3@',
'--out-h', '@OUTPUT@',
],
depend_files : anv_extensions_py,
--
2.16.2
More information about the mesa-dev
mailing list