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:

committed by
Marge Bot

parent
ce4a7e7d40
commit
f928ead625
@@ -1517,10 +1517,9 @@ init_cache_buckets(struct crocus_bufmgr *bufmgr)
|
||||
uint32_t
|
||||
crocus_create_hw_context(struct crocus_bufmgr *bufmgr)
|
||||
{
|
||||
struct drm_i915_gem_context_create create = { };
|
||||
int ret = intel_ioctl(bufmgr->fd, DRM_IOCTL_I915_GEM_CONTEXT_CREATE, &create);
|
||||
if (ret != 0) {
|
||||
DBG("DRM_IOCTL_I915_GEM_CONTEXT_CREATE failed: %s\n", strerror(errno));
|
||||
uint32_t ctx_id;
|
||||
if (!intel_gem_create_context(bufmgr->fd, &ctx_id)) {
|
||||
DBG("intel_gem_create_context failed: %s\n", strerror(errno));
|
||||
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.
|
||||
*/
|
||||
struct drm_i915_gem_context_param p = {
|
||||
.ctx_id = create.ctx_id,
|
||||
.ctx_id = ctx_id,
|
||||
.param = I915_CONTEXT_PARAM_RECOVERABLE,
|
||||
.value = false,
|
||||
};
|
||||
drmIoctl(bufmgr->fd, DRM_IOCTL_I915_GEM_CONTEXT_SETPARAM, &p);
|
||||
|
||||
return create.ctx_id;
|
||||
return ctx_id;
|
||||
}
|
||||
|
||||
static int
|
||||
|
@@ -2223,14 +2223,10 @@ iris_create_hw_context(struct iris_bufmgr *bufmgr, bool protected)
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
struct drm_i915_gem_context_create create = { };
|
||||
int ret = intel_ioctl(bufmgr->fd, DRM_IOCTL_I915_GEM_CONTEXT_CREATE, &create);
|
||||
if (ret != 0) {
|
||||
DBG("DRM_IOCTL_I915_GEM_CONTEXT_CREATE failed: %s\n", strerror(errno));
|
||||
if (!intel_gem_create_context(bufmgr->fd, &ctx_id)) {
|
||||
DBG("intel_gem_create_context failed: %s\n", strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
|
||||
ctx_id = create.ctx_id;
|
||||
iris_hw_context_set_unrecoverable(bufmgr, ctx_id);
|
||||
}
|
||||
|
||||
|
@@ -58,6 +58,16 @@ intel_gem_supports_syncobj_wait(int fd)
|
||||
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
|
||||
intel_gem_create_context_engines(int fd,
|
||||
const struct intel_query_engine_info *info,
|
||||
|
@@ -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_create_context(int fd, uint32_t *context_id);
|
||||
bool
|
||||
intel_gem_create_context_engines(int fd,
|
||||
const struct intel_query_engine_info *info,
|
||||
|
@@ -124,7 +124,7 @@ if with_tests and not with_platform_android
|
||||
],
|
||||
gnu_symbol_visibility : 'hidden',
|
||||
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],
|
||||
install : install_intel_gpu_tests,
|
||||
)
|
||||
|
@@ -28,6 +28,7 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "c99_compat.h"
|
||||
#include "common/intel_gem.h"
|
||||
#include "dev/intel_device_info.h"
|
||||
#include "drm-uapi/i915_drm.h"
|
||||
#include "genxml/gen_macros.h"
|
||||
@@ -128,7 +129,7 @@ public:
|
||||
}
|
||||
|
||||
int fd;
|
||||
int ctx_id;
|
||||
uint32_t ctx_id;
|
||||
intel_device_info devinfo;
|
||||
|
||||
uint32_t batch_bo_handle;
|
||||
@@ -209,10 +210,7 @@ mi_builder_test::SetUp()
|
||||
}
|
||||
ASSERT_TRUE(i < max_devices) << "Failed to find a DRM device";
|
||||
|
||||
drm_i915_gem_context_create ctx_create = drm_i915_gem_context_create();
|
||||
ASSERT_EQ(drmIoctl(fd, DRM_IOCTL_I915_GEM_CONTEXT_CREATE,
|
||||
(void *)&ctx_create), 0) << strerror(errno);
|
||||
ctx_id = ctx_create.ctx_id;
|
||||
ASSERT_TRUE(intel_gem_create_context(fd, &ctx_id)) << strerror(errno);
|
||||
|
||||
if (GFX_VER >= 8) {
|
||||
/* On gfx8+, we require softpin */
|
||||
|
@@ -3163,15 +3163,12 @@ anv_device_setup_context(struct anv_device *device,
|
||||
"kernel context creation failed");
|
||||
} else {
|
||||
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)
|
||||
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
|
||||
* immediately (on the next batchbuffer submission) report that the
|
||||
|
@@ -302,18 +302,6 @@ anv_gem_has_context_priority(int fd, VkQueueGlobalPriorityKHR 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
|
||||
anv_gem_destroy_context(struct anv_device *device, int context)
|
||||
{
|
||||
|
@@ -124,12 +124,6 @@ anv_gem_get_param(int fd, uint32_t param)
|
||||
unreachable("Unused");
|
||||
}
|
||||
|
||||
int
|
||||
anv_gem_create_context(struct anv_device *device)
|
||||
{
|
||||
unreachable("Unused");
|
||||
}
|
||||
|
||||
int
|
||||
anv_gem_destroy_context(struct anv_device *device, int context)
|
||||
{
|
||||
|
@@ -1135,7 +1135,7 @@ struct anv_device {
|
||||
struct anv_physical_device * physical;
|
||||
const struct intel_device_info * info;
|
||||
struct isl_device isl_dev;
|
||||
int context_id;
|
||||
uint32_t context_id;
|
||||
int fd;
|
||||
bool robust_buffer_access;
|
||||
|
||||
@@ -1346,7 +1346,6 @@ int anv_gem_execbuffer(struct anv_device *device,
|
||||
struct drm_i915_gem_execbuffer2 *execbuf);
|
||||
int anv_gem_set_tiling(struct anv_device *device, uint32_t gem_handle,
|
||||
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);
|
||||
int anv_gem_destroy_context(struct anv_device *device, int context);
|
||||
int anv_gem_set_context_param(int fd, int context, uint32_t param,
|
||||
|
@@ -2812,15 +2812,12 @@ anv_device_setup_context(struct anv_device *device,
|
||||
"kernel context creation failed");
|
||||
} else {
|
||||
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)
|
||||
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
|
||||
* immediately (on the next batchbuffer submission) report that the
|
||||
|
@@ -273,18 +273,6 @@ anv_gem_has_context_priority(int fd, int 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
|
||||
anv_gem_destroy_context(struct anv_device *device, int context)
|
||||
{
|
||||
|
@@ -116,12 +116,6 @@ anv_gem_get_param(int fd, uint32_t param)
|
||||
unreachable("Unused");
|
||||
}
|
||||
|
||||
int
|
||||
anv_gem_create_context(struct anv_device *device)
|
||||
{
|
||||
unreachable("Unused");
|
||||
}
|
||||
|
||||
int
|
||||
anv_gem_destroy_context(struct anv_device *device, int context)
|
||||
{
|
||||
|
@@ -1116,7 +1116,7 @@ struct anv_device {
|
||||
struct anv_physical_device * physical;
|
||||
const struct intel_device_info * info;
|
||||
struct isl_device isl_dev;
|
||||
int context_id;
|
||||
uint32_t context_id;
|
||||
int fd;
|
||||
bool can_chain_batches;
|
||||
bool robust_buffer_access;
|
||||
@@ -1381,7 +1381,6 @@ int anv_gem_execbuffer(struct anv_device *device,
|
||||
struct drm_i915_gem_execbuffer2 *execbuf);
|
||||
int anv_gem_set_tiling(struct anv_device *device, uint32_t gem_handle,
|
||||
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);
|
||||
int anv_gem_destroy_context(struct anv_device *device, int context);
|
||||
int anv_gem_set_context_param(int fd, int context, uint32_t param,
|
||||
|
Reference in New Issue
Block a user