summaryrefslogtreecommitdiff
path: root/lib/mesa/src/intel/vulkan
diff options
context:
space:
mode:
Diffstat (limited to 'lib/mesa/src/intel/vulkan')
-rw-r--r--lib/mesa/src/intel/vulkan/anv_allocator.c20
-rw-r--r--lib/mesa/src/intel/vulkan/anv_device.c17
-rw-r--r--lib/mesa/src/intel/vulkan/anv_private.h10
-rw-r--r--lib/mesa/src/intel/vulkan/anv_queue.c2
4 files changed, 49 insertions, 0 deletions
diff --git a/lib/mesa/src/intel/vulkan/anv_allocator.c b/lib/mesa/src/intel/vulkan/anv_allocator.c
index e9cc57649..2dd9f8804 100644
--- a/lib/mesa/src/intel/vulkan/anv_allocator.c
+++ b/lib/mesa/src/intel/vulkan/anv_allocator.c
@@ -25,9 +25,21 @@
#include <unistd.h>
#include <limits.h>
#include <assert.h>
+#ifdef __linux__
#include <linux/memfd.h>
+#else
+#include <fcntl.h>
+#endif
#include <sys/mman.h>
+#ifndef MAP_POPULATE
+#define MAP_POPULATE 0
+#endif
+
+#ifndef MFD_CLOEXEC
+#define MFD_CLOEXEC O_CLOEXEC
+#endif
+
#include "anv_private.h"
#include "util/hash_table.h"
@@ -115,7 +127,15 @@ struct anv_mmap_cleanup {
static inline int
memfd_create(const char *name, unsigned int flags)
{
+#ifdef __linux__
return syscall(SYS_memfd_create, name, flags);
+#else
+ char template[] = "/tmp/mesa-XXXXXXXXXX";
+ int fd = shm_mkstemp(template);
+ if (fd != -1)
+ shm_unlink(template);
+ return fd;
+#endif
}
#endif
diff --git a/lib/mesa/src/intel/vulkan/anv_device.c b/lib/mesa/src/intel/vulkan/anv_device.c
index 99b512a03..0768b1aa2 100644
--- a/lib/mesa/src/intel/vulkan/anv_device.c
+++ b/lib/mesa/src/intel/vulkan/anv_device.c
@@ -25,7 +25,12 @@
#include <stdbool.h>
#include <string.h>
#include <sys/mman.h>
+#ifdef __linux__
#include <sys/sysinfo.h>
+#else
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#endif
#include <unistd.h>
#include <fcntl.h>
#include <xf86drm.h>
@@ -64,10 +69,22 @@ static uint64_t
anv_compute_heap_size(int fd, uint64_t gtt_size)
{
/* Query the total ram from the system */
+#ifdef __linux__
struct sysinfo info;
sysinfo(&info);
uint64_t total_ram = (uint64_t)info.totalram * (uint64_t)info.mem_unit;
+#else
+ int mib[2];
+ uint64_t total_ram;
+ size_t size;
+
+ mib[0] = CTL_HW;
+ mib[1] = HW_PHYSMEM64;
+ size = sizeof(total_ram);
+ if (sysctl(mib, 2, &total_ram, &size, NULL, 0) == -1)
+ return vk_error(VK_ERROR_INITIALIZATION_FAILED);
+#endif
/* We don't want to burn too much ram with the GPU. If the user has 4GiB
* or less, we use at most half. If they have more than 4GiB, we use 3/4.
diff --git a/lib/mesa/src/intel/vulkan/anv_private.h b/lib/mesa/src/intel/vulkan/anv_private.h
index 9979b832a..c0d27df0b 100644
--- a/lib/mesa/src/intel/vulkan/anv_private.h
+++ b/lib/mesa/src/intel/vulkan/anv_private.h
@@ -32,6 +32,16 @@
#include <stdint.h>
#include <i915_drm.h>
+#include <errno.h>
+#ifndef ETIME
+#define ETIME ETIMEDOUT
+#endif
+
+#include <time.h>
+#ifndef CLOCK_MONOTONIC_RAW
+#define CLOCK_MONOTONIC_RAW CLOCK_MONOTONIC
+#endif
+
#ifdef HAVE_VALGRIND
#include <valgrind.h>
#include <memcheck.h>
diff --git a/lib/mesa/src/intel/vulkan/anv_queue.c b/lib/mesa/src/intel/vulkan/anv_queue.c
index 55465c5eb..7e6ae109a 100644
--- a/lib/mesa/src/intel/vulkan/anv_queue.c
+++ b/lib/mesa/src/intel/vulkan/anv_queue.c
@@ -27,7 +27,9 @@
#include <fcntl.h>
#include <unistd.h>
+#ifdef __linux__
#include <sys/eventfd.h>
+#endif
#include "anv_private.h"
#include "vk_util.h"