diff --git a/cros_gralloc/cros_gralloc_driver.cc b/cros_gralloc/cros_gralloc_driver.cc index 00747e8..99bcfe9 100644 --- a/cros_gralloc/cros_gralloc_driver.cc +++ b/cros_gralloc/cros_gralloc_driver.cc @@ -310,14 +310,6 @@ cros_gralloc_driver::cros_gralloc_driver() drv_kms_ = drv_render_; } - if (ivshm_node_idx != -1) { - if (!(drv_ivshmem_ = drv_create(node_fd[ivshm_node_idx]))) { - drv_loge("Failed to create driver for the ivshm device with card id %d\n", - ivshm_node_idx); - close(node_fd[ivshm_node_idx]); - } - } - // Init drv DRV_INIT(drv_render_, gpu_grp_type_, renderer_idx) if (video_idx != renderer_idx) @@ -326,25 +318,39 @@ cros_gralloc_driver::cros_gralloc_driver() DRV_INIT(drv_kms_, gpu_grp_type_, virtio_node_idx) if (drv_kms_ && (virtio_node_idx != renderer_idx) && (drv_kms_ != drv_render_)) { bool virtiopic_with_blob = drv_virtpci_with_blob(drv_kms_); - // The virtio pci device with blob feature could import buffers - // from i915, otherwise need use virtio to allocate scanout - // non-video buffers. if (virtiopic_with_blob) { + //igpu SRIOV or dGPU SRIOV case drv_logi("Virtio gpu device with blob\n"); if ((drv_kms_ != drv_render_) && drv_kms_) DRV_DESTROY(drv_kms_) drv_kms_ = drv_render_; + } else if (drv_is_dgpu(drv_video_) && drv_virtgpu_is_ivshm(drv_kms_)){ + //is dgpu passthrough + ivshm case + drv_logi("dGPU with Virtio ivshm\n"); + drv_ivshmem_ = drv_kms_; + drv_kms_ = drv_render_; + if (ivshm_node_idx != -1) { + close(node_fd[ivshm_node_idx]); + ivshm_node_idx = -1; + } } else { - drv_logi("Virtio ivshmem device or no blob\n"); + // is QNX or redhat case + drv_logi("Virtio ivshm or no blob\n"); } } if (ivshm_node_idx != -1) { - DRV_INIT(drv_ivshmem_, gpu_grp_type_, ivshm_node_idx) - if (drv_virtgpu_is_ivshm(drv_ivshmem_)) { - drv_logi("Node is virtio-ivishmem node"); + if (!(drv_ivshmem_ = drv_create(node_fd[ivshm_node_idx]))) { + drv_loge("Failed to create driver for the ivshm device with card id %d\n", + ivshm_node_idx); + close(node_fd[ivshm_node_idx]); } else { - drv_logi("Node is NOT virtio-ivishmem node"); - DRV_DESTROY(drv_ivshmem_) + DRV_INIT(drv_ivshmem_, gpu_grp_type_, ivshm_node_idx) + if (drv_virtgpu_is_ivshm(drv_ivshmem_)) { + drv_logi("Node is virtio-ivishmem node"); + } else { + drv_logi("Node is NOT virtio-ivishmem node"); + DRV_DESTROY(drv_ivshmem_) + } } } } diff --git a/cros_gralloc/cros_gralloc_driver.h b/cros_gralloc/cros_gralloc_driver.h index 89bce9f..8efc9fa 100644 --- a/cros_gralloc/cros_gralloc_driver.h +++ b/cros_gralloc/cros_gralloc_driver.h @@ -92,7 +92,10 @@ class cros_gralloc_driver struct driver *drv_render_ = nullptr; struct driver *drv_video_ = nullptr; // the drv_kms_ is used to allocate scanout non-video buffer. + // in dGPU/iGPU SRIOV, BM or dual GPU scenario, the drv_kms_ = drv_render_ struct driver *drv_kms_ = nullptr; + // the drv_ivshmem_ is used to allocate scanout buffer with + // certain resolution(screen cast). struct driver *drv_ivshmem_ = nullptr; uint32_t drv_num_ = 0; uint64_t gpu_grp_type_ = GPU_TYPE_NORMAL; diff --git a/drv.c b/drv.c index 43a430d..fdf2478 100644 --- a/drv.c +++ b/drv.c @@ -857,3 +857,15 @@ bool drv_virtgpu_is_ivshm(struct driver * drv) } return ret; } + +bool drv_is_dgpu(struct driver * drv) +{ + bool ret = false; + assert(drv); + assert(drv->backend); + + if (drv->backend->is_dgpu) { + ret = drv->backend->is_dgpu(drv); + } + return ret; +} diff --git a/drv.h b/drv.h index 834f2d8..3614e2e 100644 --- a/drv.h +++ b/drv.h @@ -254,6 +254,8 @@ bool drv_virtpci_with_blob(struct driver * drv); bool drv_virtgpu_is_ivshm(struct driver * drv); +bool drv_is_dgpu(struct driver * drv); + enum drv_log_level { DRV_LOGV, DRV_LOGD, diff --git a/drv_priv.h b/drv_priv.h index 9a38f49..488bbc3 100644 --- a/drv_priv.h +++ b/drv_priv.h @@ -108,6 +108,7 @@ struct backend { uint32_t (*get_max_texture_2d_size)(struct driver *drv); bool (*virtpci_with_blob)(struct driver *drv); bool (*virtgpu_is_ivshm)(struct driver *drv); + bool (*is_dgpu)(struct driver *drv); }; // clang-format off diff --git a/i915.c b/i915.c index c7b10ad..3701253 100644 --- a/i915.c +++ b/i915.c @@ -1398,6 +1398,12 @@ static int i915_bo_flush(struct bo *bo, struct mapping *mapping) return 0; } +static bool i915_is_dgpu(struct driver *drv) +{ + struct i915_device *i915 = drv->priv; + return i915->has_local_mem; +} + const struct backend backend_i915 = { .name = "i915", .init = i915_init, @@ -1412,6 +1418,7 @@ const struct backend backend_i915 = { .bo_flush = i915_bo_flush, .resolve_format_and_use_flags = drv_resolve_format_and_use_flags_helper, .num_planes_from_modifier = i915_num_planes_from_modifier, + .is_dgpu = i915_is_dgpu, }; #endif diff --git a/virtgpu_virgl.c b/virtgpu_virgl.c index f969e64..0509d69 100644 --- a/virtgpu_virgl.c +++ b/virtgpu_virgl.c @@ -1185,7 +1185,7 @@ static bool virgl_virtpci_with_blob(struct driver *drv) { static bool virgl_drv_virtgpu_is_ivshm(struct driver *drv) { struct virgl_priv *prv = (struct virgl_priv *)drv->priv; - return !(prv->dev_feature & VIRTGPU_PARAM_QUERY_DEV_BIT); + return (!(prv->dev_feature & VIRTGPU_PARAM_QUERY_DEV_BIT) && (prv->dev_feature & VIRTGPU_PARAM_RESOURCE_BLOB_BIT)); } const struct backend virtgpu_virgl = { .name = "virtgpu_virgl",