[Mesa-dev] [PATCH mesa 2/3] anv: Add new VK_MESA_query_timestamp extension to anv driver [v3]
Keith Packard
keithp at keithp.com
Tue Jul 10 00:35:29 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.
v2: Adopt Jason Ekstrand's coding conventions
Declare variables at first use, eliminate extra whitespace between
types and names. Wrap lines to 80 columns.
Add extension to list in alphabetical order
Suggested-by: Jason Ekstrand <jason.ekstrand at intel.com>
v3: Update to track extension API that now returns both device and
surface timestamps.
Signed-off-by: Keith Packard <keithp at keithp.com>
---
src/intel/vulkan/anv_extensions.py | 1 +
src/intel/vulkan/anv_gem.c | 13 +++++++++++++
src/intel/vulkan/anv_private.h | 3 +++
src/intel/vulkan/genX_query.c | 30 ++++++++++++++++++++++++++++++
4 files changed, 47 insertions(+)
diff --git a/src/intel/vulkan/anv_extensions.py b/src/intel/vulkan/anv_extensions.py
index adc1d758982..2dbbd70976c 100644
--- a/src/intel/vulkan/anv_extensions.py
+++ b/src/intel/vulkan/anv_extensions.py
@@ -124,6 +124,7 @@ EXTENSIONS = [
Extension('VK_EXT_shader_viewport_index_layer', 1, True),
Extension('VK_EXT_shader_stencil_export', 1, 'device->info.gen >= 9'),
Extension('VK_EXT_vertex_attribute_divisor', 2, True),
+ 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 3ba6d198a8a..8a31940e7aa 100644
--- a/src/intel/vulkan/anv_gem.c
+++ b/src/intel/vulkan/anv_gem.c
@@ -423,6 +423,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 cec28427923..fa250b9c8d8 100644
--- a/src/intel/vulkan/anv_private.h
+++ b/src/intel/vulkan/anv_private.h
@@ -76,6 +76,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"
@@ -1078,6 +1079,8 @@ int anv_gem_get_aperture(int fd, uint64_t *size);
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 e35e9b85844..05e4c32f5f2 100644
--- a/src/intel/vulkan/genX_query.c
+++ b/src/intel/vulkan/genX_query.c
@@ -552,6 +552,36 @@ void genX(CmdWriteTimestamp)(
}
}
+VkResult genX(QueryCurrentTimestampMESA)(
+ VkDevice _device,
+ VkSurfaceKHR _surface,
+ VkCurrentTimestampMESA *timestamp)
+{
+ ANV_FROM_HANDLE(anv_device, device, _device);
+ struct wsi_device *wsi_device = &device->instance->physicalDevice.wsi_device;
+ int ret;
+
+ /* XXX older kernels don't support this interface. */
+ ret = anv_gem_reg_read(device, TIMESTAMP | 1,
+ ×tamp->deviceTimestamp);
+
+ if (ret != 0)
+ return VK_ERROR_DEVICE_LOST;
+
+ struct timespec current;
+ clock_gettime(CLOCK_MONOTONIC, ¤t);
+
+ uint64_t current_ns = (uint64_t) current.tv_sec * 1000000000ULL +
+ current.tv_nsec;
+
+
+ return wsi_common_convert_timestamp(wsi_device,
+ _device,
+ _surface,
+ current_ns,
+ ×tamp->surfaceTimestamp);
+}
+
#if GEN_GEN > 7 || GEN_IS_HASWELL
static uint32_t
--
2.18.0
More information about the mesa-dev
mailing list