vulkan: make VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT conditional
authorJonathan Gray <jsg@jsg.id.au>
Tue, 1 Sep 2020 02:13:43 +0000 (12:13 +1000)
committerJonathan Gray <jsg@jsg.id.au>
Wed, 2 Sep 2020 02:15:07 +0000 (12:15 +1000)
Only advertise VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT if CLOCK_MONOTONIC_RAW
is defined.  Fixes the build on OpenBSD which has CLOCK_MONOTONIC but not
CLOCK_MONOTONIC_RAW.

Fixes: 67a2c1493c0 ("vulkan: Add VK_EXT_calibrated_timestamps extension (radv and anv) [v5]")
Signed-off-by: Jonathan Gray <jsg@jsg.id.au>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6517>

src/amd/vulkan/radv_device.c
src/intel/vulkan/anv_device.c

index 9113615607c18c5e56d8cd673aecdeb4c3d736da..b0eba6abe8677f9cfcb2afc53c816bf0228f9dcb 100644 (file)
@@ -7931,7 +7931,9 @@ radv_GetDeviceGroupPeerMemoryFeatures(
 static const VkTimeDomainEXT radv_time_domains[] = {
        VK_TIME_DOMAIN_DEVICE_EXT,
        VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT,
 static const VkTimeDomainEXT radv_time_domains[] = {
        VK_TIME_DOMAIN_DEVICE_EXT,
        VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT,
+#ifdef CLOCK_MONOTONIC_RAW
        VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT,
        VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT,
+#endif
 };
 
 VkResult radv_GetPhysicalDeviceCalibrateableTimeDomainsEXT(
 };
 
 VkResult radv_GetPhysicalDeviceCalibrateableTimeDomainsEXT(
@@ -7958,8 +7960,10 @@ radv_clock_gettime(clockid_t clock_id)
        int ret;
 
        ret = clock_gettime(clock_id, &current);
        int ret;
 
        ret = clock_gettime(clock_id, &current);
+#ifdef CLOCK_MONOTONIC_RAW
        if (ret < 0 && clock_id == CLOCK_MONOTONIC_RAW)
                ret = clock_gettime(CLOCK_MONOTONIC, &current);
        if (ret < 0 && clock_id == CLOCK_MONOTONIC_RAW)
                ret = clock_gettime(CLOCK_MONOTONIC, &current);
+#endif
        if (ret < 0)
                return 0;
 
        if (ret < 0)
                return 0;
 
@@ -7979,7 +7983,11 @@ VkResult radv_GetCalibratedTimestampsEXT(
        uint64_t begin, end;
         uint64_t max_clock_period = 0;
 
        uint64_t begin, end;
         uint64_t max_clock_period = 0;
 
+#ifdef CLOCK_MONOTONIC_RAW
        begin = radv_clock_gettime(CLOCK_MONOTONIC_RAW);
        begin = radv_clock_gettime(CLOCK_MONOTONIC_RAW);
+#else
+       begin = radv_clock_gettime(CLOCK_MONOTONIC);
+#endif
 
        for (d = 0; d < timestampCount; d++) {
                switch (pTimestampInfos[d].timeDomain) {
 
        for (d = 0; d < timestampCount; d++) {
                switch (pTimestampInfos[d].timeDomain) {
@@ -7994,16 +8002,22 @@ VkResult radv_GetCalibratedTimestampsEXT(
                         max_clock_period = MAX2(max_clock_period, 1);
                        break;
 
                         max_clock_period = MAX2(max_clock_period, 1);
                        break;
 
+#ifdef CLOCK_MONOTONIC_RAW
                case VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT:
                        pTimestamps[d] = begin;
                        break;
                case VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT:
                        pTimestamps[d] = begin;
                        break;
+#endif
                default:
                        pTimestamps[d] = 0;
                        break;
                }
        }
 
                default:
                        pTimestamps[d] = 0;
                        break;
                }
        }
 
+#ifdef CLOCK_MONOTONIC_RAW
        end = radv_clock_gettime(CLOCK_MONOTONIC_RAW);
        end = radv_clock_gettime(CLOCK_MONOTONIC_RAW);
+#else
+       end = radv_clock_gettime(CLOCK_MONOTONIC);
+#endif
 
         /*
          * The maximum deviation is the sum of the interval over which we
 
         /*
          * The maximum deviation is the sum of the interval over which we
index 7470d0cf17f64ba52117d8dcc8e91a37f862c4fa..789913d57b88cd1cff6a4fd4f7d1a189ad8fad7f 100644 (file)
@@ -4442,7 +4442,9 @@ void anv_DestroyFramebuffer(
 static const VkTimeDomainEXT anv_time_domains[] = {
    VK_TIME_DOMAIN_DEVICE_EXT,
    VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT,
 static const VkTimeDomainEXT anv_time_domains[] = {
    VK_TIME_DOMAIN_DEVICE_EXT,
    VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT,
+#ifdef CLOCK_MONOTONIC_RAW
    VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT,
    VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT,
+#endif
 };
 
 VkResult anv_GetPhysicalDeviceCalibrateableTimeDomainsEXT(
 };
 
 VkResult anv_GetPhysicalDeviceCalibrateableTimeDomainsEXT(
@@ -4469,8 +4471,10 @@ anv_clock_gettime(clockid_t clock_id)
    int ret;
 
    ret = clock_gettime(clock_id, &current);
    int ret;
 
    ret = clock_gettime(clock_id, &current);
+#ifdef CLOCK_MONOTONIC_RAW
    if (ret < 0 && clock_id == CLOCK_MONOTONIC_RAW)
       ret = clock_gettime(CLOCK_MONOTONIC, &current);
    if (ret < 0 && clock_id == CLOCK_MONOTONIC_RAW)
       ret = clock_gettime(CLOCK_MONOTONIC, &current);
+#endif
    if (ret < 0)
       return 0;
 
    if (ret < 0)
       return 0;
 
@@ -4491,7 +4495,11 @@ VkResult anv_GetCalibratedTimestampsEXT(
    uint64_t begin, end;
    uint64_t max_clock_period = 0;
 
    uint64_t begin, end;
    uint64_t max_clock_period = 0;
 
+#ifdef CLOCK_MONOTONIC_RAW
    begin = anv_clock_gettime(CLOCK_MONOTONIC_RAW);
    begin = anv_clock_gettime(CLOCK_MONOTONIC_RAW);
+#else
+   begin = anv_clock_gettime(CLOCK_MONOTONIC);
+#endif
 
    for (d = 0; d < timestampCount; d++) {
       switch (pTimestampInfos[d].timeDomain) {
 
    for (d = 0; d < timestampCount; d++) {
       switch (pTimestampInfos[d].timeDomain) {
@@ -4511,16 +4519,22 @@ VkResult anv_GetCalibratedTimestampsEXT(
          max_clock_period = MAX2(max_clock_period, 1);
          break;
 
          max_clock_period = MAX2(max_clock_period, 1);
          break;
 
+#ifdef CLOCK_MONOTONIC_RAW
       case VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT:
          pTimestamps[d] = begin;
          break;
       case VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT:
          pTimestamps[d] = begin;
          break;
+#endif
       default:
          pTimestamps[d] = 0;
          break;
       }
    }
 
       default:
          pTimestamps[d] = 0;
          break;
       }
    }
 
+#ifdef CLOCK_MONOTONIC_RAW
    end = anv_clock_gettime(CLOCK_MONOTONIC_RAW);
    end = anv_clock_gettime(CLOCK_MONOTONIC_RAW);
+#else
+   end = anv_clock_gettime(CLOCK_MONOTONIC);
+#endif
 
     /*
      * The maximum deviation is the sum of the interval over which we
 
     /*
      * The maximum deviation is the sum of the interval over which we