From: Jason Ekstrand Date: Mon, 18 Jan 2016 23:42:41 +0000 (-0800) Subject: anv/gem: Add a helper for getting bit6 swizzling information X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=587842a0cab1e24f561bf99de94e91fa6710f2a5;p=mesa.git anv/gem: Add a helper for getting bit6 swizzling information --- diff --git a/src/vulkan/anv_gem.c b/src/vulkan/anv_gem.c index 9d0d0332001..0a7be353327 100644 --- a/src/vulkan/anv_gem.c +++ b/src/vulkan/anv_gem.c @@ -227,6 +227,61 @@ anv_gem_get_param(int fd, uint32_t param) return 0; } +bool +anv_gem_get_bit6_swizzle(int fd, uint32_t tiling) +{ + struct drm_gem_close close; + int ret; + + struct drm_i915_gem_create gem_create; + VG_CLEAR(gem_create); + gem_create.size = 4096; + + if (anv_ioctl(fd, DRM_IOCTL_I915_GEM_CREATE, &gem_create)) { + assert(!"Failed to create GEM BO"); + return false; + } + + bool swizzled = false; + + /* set_tiling overwrites the input on the error path, so we have to open + * code anv_ioctl. + */ + struct drm_i915_gem_set_tiling set_tiling; + do { + VG_CLEAR(set_tiling); + set_tiling.handle = gem_create.handle; + set_tiling.tiling_mode = tiling; + set_tiling.stride = tiling == I915_TILING_X ? 512 : 128; + + ret = ioctl(fd, DRM_IOCTL_I915_GEM_SET_TILING, &set_tiling); + } while (ret == -1 && (errno == EINTR || errno == EAGAIN)); + + if (ret != 0) { + assert(!"Failed to set BO tiling"); + goto close_and_return; + } + + struct drm_i915_gem_get_tiling get_tiling; + VG_CLEAR(get_tiling); + get_tiling.handle = gem_create.handle; + + if (anv_ioctl(fd, DRM_IOCTL_I915_GEM_GET_TILING, &get_tiling)) { + assert(!"Failed to get BO tiling"); + goto close_and_return; + } + + swizzled = get_tiling.swizzle_mode != I915_BIT_6_SWIZZLE_NONE; + +close_and_return: + + VG_CLEAR(close); + close.handle = gem_create.handle; + anv_ioctl(fd, DRM_IOCTL_GEM_CLOSE, &close); + + return swizzled; +} + int anv_gem_create_context(struct anv_device *device) { diff --git a/src/vulkan/anv_private.h b/src/vulkan/anv_private.h index 574fd66e4c7..307e07ef246 100644 --- a/src/vulkan/anv_private.h +++ b/src/vulkan/anv_private.h @@ -665,6 +665,7 @@ int anv_gem_set_tiling(struct anv_device *device, uint32_t gem_handle, int anv_gem_create_context(struct anv_device *device); int anv_gem_destroy_context(struct anv_device *device, int context); int anv_gem_get_param(int fd, uint32_t param); +bool anv_gem_get_bit6_swizzle(int fd, uint32_t tiling); int anv_gem_get_aperture(int fd, uint64_t *size); int anv_gem_handle_to_fd(struct anv_device *device, uint32_t gem_handle); uint32_t anv_gem_fd_to_handle(struct anv_device *device, int fd);