intel: Add and use intel_gem_create_context()

Add intel_gem_create_context() to common/intel_gem.c/h and use it
on Iris, Crocus, ANV and HASVK.

Signed-off-by: José Roberto de Souza <jose.souza@intel.com>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18974>
This commit is contained in:
José Roberto de Souza
2022-10-05 08:20:47 -07:00
committed by Marge Bot
parent ce4a7e7d40
commit f928ead625
14 changed files with 28 additions and 68 deletions

View File

@@ -1517,10 +1517,9 @@ init_cache_buckets(struct crocus_bufmgr *bufmgr)
uint32_t uint32_t
crocus_create_hw_context(struct crocus_bufmgr *bufmgr) crocus_create_hw_context(struct crocus_bufmgr *bufmgr)
{ {
struct drm_i915_gem_context_create create = { }; uint32_t ctx_id;
int ret = intel_ioctl(bufmgr->fd, DRM_IOCTL_I915_GEM_CONTEXT_CREATE, &create); if (!intel_gem_create_context(bufmgr->fd, &ctx_id)) {
if (ret != 0) { DBG("intel_gem_create_context failed: %s\n", strerror(errno));
DBG("DRM_IOCTL_I915_GEM_CONTEXT_CREATE failed: %s\n", strerror(errno));
return 0; return 0;
} }
@@ -1540,13 +1539,13 @@ crocus_create_hw_context(struct crocus_bufmgr *bufmgr)
* we'll have two lost batches instead of a continual stream of hangs. * we'll have two lost batches instead of a continual stream of hangs.
*/ */
struct drm_i915_gem_context_param p = { struct drm_i915_gem_context_param p = {
.ctx_id = create.ctx_id, .ctx_id = ctx_id,
.param = I915_CONTEXT_PARAM_RECOVERABLE, .param = I915_CONTEXT_PARAM_RECOVERABLE,
.value = false, .value = false,
}; };
drmIoctl(bufmgr->fd, DRM_IOCTL_I915_GEM_CONTEXT_SETPARAM, &p); drmIoctl(bufmgr->fd, DRM_IOCTL_I915_GEM_CONTEXT_SETPARAM, &p);
return create.ctx_id; return ctx_id;
} }
static int static int

View File

@@ -2223,14 +2223,10 @@ iris_create_hw_context(struct iris_bufmgr *bufmgr, bool protected)
return 0; return 0;
} }
} else { } else {
struct drm_i915_gem_context_create create = { }; if (!intel_gem_create_context(bufmgr->fd, &ctx_id)) {
int ret = intel_ioctl(bufmgr->fd, DRM_IOCTL_I915_GEM_CONTEXT_CREATE, &create); DBG("intel_gem_create_context failed: %s\n", strerror(errno));
if (ret != 0) {
DBG("DRM_IOCTL_I915_GEM_CONTEXT_CREATE failed: %s\n", strerror(errno));
return 0; return 0;
} }
ctx_id = create.ctx_id;
iris_hw_context_set_unrecoverable(bufmgr, ctx_id); iris_hw_context_set_unrecoverable(bufmgr, ctx_id);
} }

View File

@@ -58,6 +58,16 @@ intel_gem_supports_syncobj_wait(int fd)
return ret == -1 && errno == ETIME; return ret == -1 && errno == ETIME;
} }
bool
intel_gem_create_context(int fd, uint32_t *context_id)
{
struct drm_i915_gem_context_create create = {};
if (intel_ioctl(fd, DRM_IOCTL_I915_GEM_CONTEXT_CREATE, &create))
return false;
*context_id = create.ctx_id;
return true;
}
bool bool
intel_gem_create_context_engines(int fd, intel_gem_create_context_engines(int fd,
const struct intel_query_engine_info *info, const struct intel_query_engine_info *info,

View File

@@ -159,6 +159,7 @@ intel_i915_query_alloc(int fd, uint64_t query_id, int32_t *query_length)
bool intel_gem_supports_syncobj_wait(int fd); bool intel_gem_supports_syncobj_wait(int fd);
bool intel_gem_create_context(int fd, uint32_t *context_id);
bool bool
intel_gem_create_context_engines(int fd, intel_gem_create_context_engines(int fd,
const struct intel_query_engine_info *info, const struct intel_query_engine_info *info,

View File

@@ -124,7 +124,7 @@ if with_tests and not with_platform_android
], ],
gnu_symbol_visibility : 'hidden', gnu_symbol_visibility : 'hidden',
include_directories : [inc_include, inc_src, inc_intel], include_directories : [inc_include, inc_src, inc_intel],
link_with : [libintel_dev], link_with : [libintel_dev, libintel_common],
dependencies : [dep_libdrm, idep_gtest, idep_genxml, idep_mesautil], dependencies : [dep_libdrm, idep_gtest, idep_genxml, idep_mesautil],
install : install_intel_gpu_tests, install : install_intel_gpu_tests,
) )

View File

@@ -28,6 +28,7 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "c99_compat.h" #include "c99_compat.h"
#include "common/intel_gem.h"
#include "dev/intel_device_info.h" #include "dev/intel_device_info.h"
#include "drm-uapi/i915_drm.h" #include "drm-uapi/i915_drm.h"
#include "genxml/gen_macros.h" #include "genxml/gen_macros.h"
@@ -128,7 +129,7 @@ public:
} }
int fd; int fd;
int ctx_id; uint32_t ctx_id;
intel_device_info devinfo; intel_device_info devinfo;
uint32_t batch_bo_handle; uint32_t batch_bo_handle;
@@ -209,10 +210,7 @@ mi_builder_test::SetUp()
} }
ASSERT_TRUE(i < max_devices) << "Failed to find a DRM device"; ASSERT_TRUE(i < max_devices) << "Failed to find a DRM device";
drm_i915_gem_context_create ctx_create = drm_i915_gem_context_create(); ASSERT_TRUE(intel_gem_create_context(fd, &ctx_id)) << strerror(errno);
ASSERT_EQ(drmIoctl(fd, DRM_IOCTL_I915_GEM_CONTEXT_CREATE,
(void *)&ctx_create), 0) << strerror(errno);
ctx_id = ctx_create.ctx_id;
if (GFX_VER >= 8) { if (GFX_VER >= 8) {
/* On gfx8+, we require softpin */ /* On gfx8+, we require softpin */

View File

@@ -3163,15 +3163,12 @@ anv_device_setup_context(struct anv_device *device,
"kernel context creation failed"); "kernel context creation failed");
} else { } else {
assert(num_queues == 1); assert(num_queues == 1);
device->context_id = anv_gem_create_context(device); if (!intel_gem_create_context(device->fd, &device->context_id))
result = vk_error(device, VK_ERROR_INITIALIZATION_FAILED);
} }
if (result != VK_SUCCESS) if (result != VK_SUCCESS)
return result; return result;
if (device->context_id == -1) {
result = vk_error(device, VK_ERROR_INITIALIZATION_FAILED);
return result;
}
/* Here we tell the kernel not to attempt to recover our context but /* Here we tell the kernel not to attempt to recover our context but
* immediately (on the next batchbuffer submission) report that the * immediately (on the next batchbuffer submission) report that the

View File

@@ -302,18 +302,6 @@ anv_gem_has_context_priority(int fd, VkQueueGlobalPriorityKHR priority)
priority); priority);
} }
int
anv_gem_create_context(struct anv_device *device)
{
struct drm_i915_gem_context_create create = { 0 };
int ret = intel_ioctl(device->fd, DRM_IOCTL_I915_GEM_CONTEXT_CREATE, &create);
if (ret == -1)
return -1;
return create.ctx_id;
}
int int
anv_gem_destroy_context(struct anv_device *device, int context) anv_gem_destroy_context(struct anv_device *device, int context)
{ {

View File

@@ -124,12 +124,6 @@ anv_gem_get_param(int fd, uint32_t param)
unreachable("Unused"); unreachable("Unused");
} }
int
anv_gem_create_context(struct anv_device *device)
{
unreachable("Unused");
}
int int
anv_gem_destroy_context(struct anv_device *device, int context) anv_gem_destroy_context(struct anv_device *device, int context)
{ {

View File

@@ -1135,7 +1135,7 @@ struct anv_device {
struct anv_physical_device * physical; struct anv_physical_device * physical;
const struct intel_device_info * info; const struct intel_device_info * info;
struct isl_device isl_dev; struct isl_device isl_dev;
int context_id; uint32_t context_id;
int fd; int fd;
bool robust_buffer_access; bool robust_buffer_access;
@@ -1346,7 +1346,6 @@ int anv_gem_execbuffer(struct anv_device *device,
struct drm_i915_gem_execbuffer2 *execbuf); struct drm_i915_gem_execbuffer2 *execbuf);
int anv_gem_set_tiling(struct anv_device *device, uint32_t gem_handle, int anv_gem_set_tiling(struct anv_device *device, uint32_t gem_handle,
uint32_t stride, uint32_t tiling); uint32_t stride, uint32_t tiling);
int anv_gem_create_context(struct anv_device *device);
bool anv_gem_has_context_priority(int fd, VkQueueGlobalPriorityKHR priority); bool anv_gem_has_context_priority(int fd, VkQueueGlobalPriorityKHR priority);
int anv_gem_destroy_context(struct anv_device *device, int context); int anv_gem_destroy_context(struct anv_device *device, int context);
int anv_gem_set_context_param(int fd, int context, uint32_t param, int anv_gem_set_context_param(int fd, int context, uint32_t param,

View File

@@ -2812,15 +2812,12 @@ anv_device_setup_context(struct anv_device *device,
"kernel context creation failed"); "kernel context creation failed");
} else { } else {
assert(num_queues == 1); assert(num_queues == 1);
device->context_id = anv_gem_create_context(device); if (!intel_gem_create_context(device->fd, &device->context_id))
result = vk_error(device, VK_ERROR_INITIALIZATION_FAILED);
} }
if (result != VK_SUCCESS) if (result != VK_SUCCESS)
return result; return result;
if (device->context_id == -1) {
result = vk_error(device, VK_ERROR_INITIALIZATION_FAILED);
return result;
}
/* Here we tell the kernel not to attempt to recover our context but /* Here we tell the kernel not to attempt to recover our context but
* immediately (on the next batchbuffer submission) report that the * immediately (on the next batchbuffer submission) report that the

View File

@@ -273,18 +273,6 @@ anv_gem_has_context_priority(int fd, int priority)
priority); priority);
} }
int
anv_gem_create_context(struct anv_device *device)
{
struct drm_i915_gem_context_create create = { 0 };
int ret = intel_ioctl(device->fd, DRM_IOCTL_I915_GEM_CONTEXT_CREATE, &create);
if (ret == -1)
return -1;
return create.ctx_id;
}
int int
anv_gem_destroy_context(struct anv_device *device, int context) anv_gem_destroy_context(struct anv_device *device, int context)
{ {

View File

@@ -116,12 +116,6 @@ anv_gem_get_param(int fd, uint32_t param)
unreachable("Unused"); unreachable("Unused");
} }
int
anv_gem_create_context(struct anv_device *device)
{
unreachable("Unused");
}
int int
anv_gem_destroy_context(struct anv_device *device, int context) anv_gem_destroy_context(struct anv_device *device, int context)
{ {

View File

@@ -1116,7 +1116,7 @@ struct anv_device {
struct anv_physical_device * physical; struct anv_physical_device * physical;
const struct intel_device_info * info; const struct intel_device_info * info;
struct isl_device isl_dev; struct isl_device isl_dev;
int context_id; uint32_t context_id;
int fd; int fd;
bool can_chain_batches; bool can_chain_batches;
bool robust_buffer_access; bool robust_buffer_access;
@@ -1381,7 +1381,6 @@ int anv_gem_execbuffer(struct anv_device *device,
struct drm_i915_gem_execbuffer2 *execbuf); struct drm_i915_gem_execbuffer2 *execbuf);
int anv_gem_set_tiling(struct anv_device *device, uint32_t gem_handle, int anv_gem_set_tiling(struct anv_device *device, uint32_t gem_handle,
uint32_t stride, uint32_t tiling); uint32_t stride, uint32_t tiling);
int anv_gem_create_context(struct anv_device *device);
bool anv_gem_has_context_priority(int fd, int priority); bool anv_gem_has_context_priority(int fd, int priority);
int anv_gem_destroy_context(struct anv_device *device, int context); int anv_gem_destroy_context(struct anv_device *device, int context);
int anv_gem_set_context_param(int fd, int context, uint32_t param, int anv_gem_set_context_param(int fd, int context, uint32_t param,