From patchwork Wed Oct 2 01:49:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gurchetan Singh X-Patchwork-Id: 11170163 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 002FC1599 for ; Wed, 2 Oct 2019 01:49:45 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DC91620815 for ; Wed, 2 Oct 2019 01:49:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DC91620815 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D612189198; Wed, 2 Oct 2019 01:49:42 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1D9D56E5CF for ; Wed, 2 Oct 2019 01:49:41 +0000 (UTC) Received: by mail-pf1-x444.google.com with SMTP id 205so9458931pfw.2 for ; Tue, 01 Oct 2019 18:49:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=1Ebjptdz2m5kxB+3iL69Y2gpNQMsC3ZxXi6iLvTnhmU=; b=QZ+OJx6pMvRXdbNWPExS3ltyls84dMApXYieXNvUOdeLdcm9or3RLWAMA7PZEZgKoG b0nIhfQNKq7IiNGzmlzUZoGbjtbvflfJOuMWvQEdLu2O0x+5G28wuG10Rc0MEgSXwYIA TgFZ+ko31gb7HMGI1Xg2GhHibhpx9j0A5cnPuaJ2JciTOcQNdWdYjQnLVDJlxDKQ2Tzi YZ/f7Ql1DqHy2+f4fWBfno/ic7vSy2srLZqrcbcnbJDHJMOIdSQN3P7CffOiFjeGW18U k7qTDHYJCJas6lrxQDW0e2TUq3j/n48KlturKfRBNh0SRQHcpJimVdY6vayU9m589v0e BzBA== X-Gm-Message-State: APjAAAVZft8P+gOTKSwI25d+dL0q1I/dm2kaBV9Uj4468HF2F1d1RHqr VzLJ/OswiAAiNi+EPeEnxGRk+iyDk8Q= X-Google-Smtp-Source: APXvYqwwCYLibN++pbDmb8JgapmrwUr5omMv5p1Nw0t2I/A7M/xctTmUi25AYwiAjJ+Tc754vGX1qQ== X-Received: by 2002:aa7:8816:: with SMTP id c22mr1632312pfo.197.1569980980244; Tue, 01 Oct 2019 18:49:40 -0700 (PDT) Received: from gurchetansingh0.mtv.corp.google.com ([2620:15c:202:201:bc97:5740:52a7:6875]) by smtp.gmail.com with ESMTPSA id k15sm19404326pgt.66.2019.10.01.18.49.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 01 Oct 2019 18:49:39 -0700 (PDT) From: Gurchetan Singh To: dri-devel@lists.freedesktop.org Subject: [PATCH 1/2] drm/virtgpu: plumb fix for virtgpu_drm.h / virtio_gpu.h discrepancy Date: Tue, 1 Oct 2019 18:49:34 -0700 Message-Id: <20191002014935.33171-1-gurchetansingh@chromium.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=1Ebjptdz2m5kxB+3iL69Y2gpNQMsC3ZxXi6iLvTnhmU=; b=m54sNT9+Oe6H9z+Sc5ihrPT0SPOZp0/DzaTh4qaR9dNoklBzIxLR61MMxLvgiC8lxZ lGYxLuuxnflEmFxqmHkyjhwhXnc1yyM+GZ+Q3xEdBOEWsFQQgE8snbLBCrxzxFVWJCT5 myfu+lLYJwTzA0uhCu6TNQ4sSME7dIw9HcgxA= X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: airlied@linux.ie, kraxel@redhat.com, Gurchetan Singh Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" virglrenderer has logic to validate both stride and layer_stride, but both are always zero. The fallback for that case is: stride = width * bytes_per_pixel layer_stride = stride * num_layers However, this assumption causes trouble in the following cases: 1) When allocating host-compatible buffers for the planned wayland integration. 2) Certain YUV buffers, which Gallium imports as 3 R8 buffers with variable strides. For example, HAL_PIXEL_FORMAT_YV12 requires that the chroma planes are aligned to 16 bytes. This commit doesn't fix the discrepancy, but adds the necessary plumbing so we don't forget. Signed-off-by: Gurchetan Singh --- drivers/gpu/drm/virtio/virtgpu_drv.h | 2 ++ drivers/gpu/drm/virtio/virtgpu_ioctl.c | 9 ++++++--- drivers/gpu/drm/virtio/virtgpu_vq.c | 6 ++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/virtio/virtgpu_drv.h b/drivers/gpu/drm/virtio/virtgpu_drv.h index 314e02f94d9c..c1c9a9b8e25c 100644 --- a/drivers/gpu/drm/virtio/virtgpu_drv.h +++ b/drivers/gpu/drm/virtio/virtgpu_drv.h @@ -312,12 +312,14 @@ void virtio_gpu_cmd_submit(struct virtio_gpu_device *vgdev, void virtio_gpu_cmd_transfer_from_host_3d(struct virtio_gpu_device *vgdev, uint32_t ctx_id, uint64_t offset, uint32_t level, + uint32_t stride, uint32_t layer_stride, struct virtio_gpu_box *box, struct virtio_gpu_object_array *objs, struct virtio_gpu_fence *fence); void virtio_gpu_cmd_transfer_to_host_3d(struct virtio_gpu_device *vgdev, uint32_t ctx_id, uint64_t offset, uint32_t level, + uint32_t stride, uint32_t layer_stride, struct virtio_gpu_box *box, struct virtio_gpu_object_array *objs, struct virtio_gpu_fence *fence); diff --git a/drivers/gpu/drm/virtio/virtgpu_ioctl.c b/drivers/gpu/drm/virtio/virtgpu_ioctl.c index 9af1ec62434f..98b72dead962 100644 --- a/drivers/gpu/drm/virtio/virtgpu_ioctl.c +++ b/drivers/gpu/drm/virtio/virtgpu_ioctl.c @@ -324,8 +324,10 @@ static int virtio_gpu_transfer_from_host_ioctl(struct drm_device *dev, ret = -ENOMEM; goto err_unlock; } + + /* TODO: add the correct stride / layer_stride. */ virtio_gpu_cmd_transfer_from_host_3d - (vgdev, vfpriv->ctx_id, offset, args->level, + (vgdev, vfpriv->ctx_id, offset, args->level, 0, 0, &box, objs, fence); dma_fence_put(&fence->f); return 0; @@ -369,10 +371,11 @@ static int virtio_gpu_transfer_to_host_ioctl(struct drm_device *dev, void *data, if (!fence) goto err_unlock; + /* TODO: add the correct stride / layer_stride. */ virtio_gpu_cmd_transfer_to_host_3d (vgdev, - vfpriv ? vfpriv->ctx_id : 0, offset, - args->level, &box, objs, fence); + vfpriv ? vfpriv->ctx_id : 0, offset, args->level, + 0, 0, &box, objs, fence); dma_fence_put(&fence->f); } return 0; diff --git a/drivers/gpu/drm/virtio/virtgpu_vq.c b/drivers/gpu/drm/virtio/virtgpu_vq.c index 80176f379ad5..9fb3c8c3b687 100644 --- a/drivers/gpu/drm/virtio/virtgpu_vq.c +++ b/drivers/gpu/drm/virtio/virtgpu_vq.c @@ -965,6 +965,7 @@ virtio_gpu_cmd_resource_create_3d(struct virtio_gpu_device *vgdev, void virtio_gpu_cmd_transfer_to_host_3d(struct virtio_gpu_device *vgdev, uint32_t ctx_id, uint64_t offset, uint32_t level, + uint32_t stride, uint32_t layer_stride, struct virtio_gpu_box *box, struct virtio_gpu_object_array *objs, struct virtio_gpu_fence *fence) @@ -990,6 +991,8 @@ void virtio_gpu_cmd_transfer_to_host_3d(struct virtio_gpu_device *vgdev, cmd_p->box = *box; cmd_p->offset = cpu_to_le64(offset); cmd_p->level = cpu_to_le32(level); + cmd_p->stride = cpu_to_le32(stride); + cmd_p->layer_stride = cpu_to_le32(layer_stride); virtio_gpu_queue_fenced_ctrl_buffer(vgdev, vbuf, &cmd_p->hdr, fence); } @@ -997,6 +1000,7 @@ void virtio_gpu_cmd_transfer_to_host_3d(struct virtio_gpu_device *vgdev, void virtio_gpu_cmd_transfer_from_host_3d(struct virtio_gpu_device *vgdev, uint32_t ctx_id, uint64_t offset, uint32_t level, + uint32_t stride, uint32_t layer_stride, struct virtio_gpu_box *box, struct virtio_gpu_object_array *objs, struct virtio_gpu_fence *fence) @@ -1016,6 +1020,8 @@ void virtio_gpu_cmd_transfer_from_host_3d(struct virtio_gpu_device *vgdev, cmd_p->box = *box; cmd_p->offset = cpu_to_le64(offset); cmd_p->level = cpu_to_le32(level); + cmd_p->stride = cpu_to_le32(stride); + cmd_p->layer_stride = cpu_to_le32(layer_stride); virtio_gpu_queue_fenced_ctrl_buffer(vgdev, vbuf, &cmd_p->hdr, fence); } From patchwork Wed Oct 2 01:49:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gurchetan Singh X-Patchwork-Id: 11170165 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4E29F1599 for ; Wed, 2 Oct 2019 01:49:47 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3640720815 for ; Wed, 2 Oct 2019 01:49:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3640720815 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7DF5E897DC; Wed, 2 Oct 2019 01:49:45 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) by gabe.freedesktop.org (Postfix) with ESMTPS id BA826897DC for ; Wed, 2 Oct 2019 01:49:43 +0000 (UTC) Received: by mail-pg1-x541.google.com with SMTP id v27so10975891pgk.10 for ; Tue, 01 Oct 2019 18:49:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fqt1llNkQVMjtqE7BXPtP6+dPRgbYEn9xPiuVRxKYdA=; b=QDpDyiLlwU9xD61leeCcjpMcJBR2aDNOpTbgOvDuQmL6uj2VYJwvm2v34NrkVr+b+W wCZBz6/HXN4XyS+gELFqYILuA/H+qBuiuG66yle8m5EHsEqZOt1ec4ZbDxrrSy6xyUuy qbySDvt0SM2NySf45kBnBK++6USxBHOK5XcTPqFCRaAkEv05VOED25SHJVQ8Ek8S5q5K ZTOjBUau9Yq5K1sIgEVxj+trgKnLl8A6ArOI7TE63Jfg1prr31kk+j3cFDsXGg7zoyfE H/JXol2wUtGv06Km+OX4LaDtL5mAvX2kDwneOoafxW0V1VLqrM7u37U3zO7l5qPLf1dH SNrg== X-Gm-Message-State: APjAAAV/xgwXtXySXX0KzXdYQxNaz5PUFVzCd0fMeUomSmmeCc1x+nWE 7ekYqRWneOt551MKJ2Q2LIQFjxu5XiQ= X-Google-Smtp-Source: APXvYqy5Z/ypPSHttbSNXeYae8/YavPqj5itIz9cwIjHCtD9ei8gaAsujlV/LuLlqwfig5n/GhNmZQ== X-Received: by 2002:a62:1888:: with SMTP id 130mr1669883pfy.72.1569980982859; Tue, 01 Oct 2019 18:49:42 -0700 (PDT) Received: from gurchetansingh0.mtv.corp.google.com ([2620:15c:202:201:bc97:5740:52a7:6875]) by smtp.gmail.com with ESMTPSA id k15sm19404326pgt.66.2019.10.01.18.49.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 01 Oct 2019 18:49:42 -0700 (PDT) From: Gurchetan Singh To: dri-devel@lists.freedesktop.org Subject: [PATCH 2/2] [RFC] drm/virtgpu: modify uapi with stride/layer_stride fix Date: Tue, 1 Oct 2019 18:49:35 -0700 Message-Id: <20191002014935.33171-2-gurchetansingh@chromium.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191002014935.33171-1-gurchetansingh@chromium.org> References: <20191002014935.33171-1-gurchetansingh@chromium.org> MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fqt1llNkQVMjtqE7BXPtP6+dPRgbYEn9xPiuVRxKYdA=; b=mMAr8AOFU3D4uRRpi/Zg8lNoiBCrxnbgtUQc8QUsjgT1uI0fPA+0Aj5b2MbL8GU58/ rFtpnAsumMWazf2DFqpCAkT4GgJuVMk9h9MxlaPE2ob1irkN8IHbtIdJsXge4zvn6qZP rFKH4pT+EDrg2mGoxhzdEyueUbhSgTE1SFwko= X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: airlied@linux.ie, kraxel@redhat.com, Gurchetan Singh Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" This doesn't really break userspace, since it always passes down 0 for stride/layer_stride currently. We could: (1) modify UAPI now and add a VIRTGPU_PARAM_STRIDE_FIX feature (2) modify the UAPI now, and not expose a corresponding feature (i.e, VIRTGPU_PARAM_STRIDE_FIX). This would fold this minor fix into another bigger feature (like the proposed metadata query). (3) don't modify UAPI now, wait until another feature lands. I don't have a preference either way, as long as we get something like this eventually. The corresponding userspace is: https://gitlab.freedesktop.org/mesa/mesa/merge_requests/2129 Signed-off-by: Gurchetan Singh --- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 8 +++----- include/uapi/drm/virtgpu_drm.h | 4 ++++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/virtio/virtgpu_ioctl.c b/drivers/gpu/drm/virtio/virtgpu_ioctl.c index 98b72dead962..c29473ac24a1 100644 --- a/drivers/gpu/drm/virtio/virtgpu_ioctl.c +++ b/drivers/gpu/drm/virtio/virtgpu_ioctl.c @@ -325,10 +325,9 @@ static int virtio_gpu_transfer_from_host_ioctl(struct drm_device *dev, goto err_unlock; } - /* TODO: add the correct stride / layer_stride. */ virtio_gpu_cmd_transfer_from_host_3d - (vgdev, vfpriv->ctx_id, offset, args->level, 0, 0, - &box, objs, fence); + (vgdev, vfpriv->ctx_id, offset, args->level, args->stride, + args->layer_stride, &box, objs, fence); dma_fence_put(&fence->f); return 0; @@ -371,11 +370,10 @@ static int virtio_gpu_transfer_to_host_ioctl(struct drm_device *dev, void *data, if (!fence) goto err_unlock; - /* TODO: add the correct stride / layer_stride. */ virtio_gpu_cmd_transfer_to_host_3d (vgdev, vfpriv ? vfpriv->ctx_id : 0, offset, args->level, - 0, 0, &box, objs, fence); + args->stride, args->layer_stride, &box, objs, fence); dma_fence_put(&fence->f); } return 0; diff --git a/include/uapi/drm/virtgpu_drm.h b/include/uapi/drm/virtgpu_drm.h index f06a789f34cd..b2fc92c3d2be 100644 --- a/include/uapi/drm/virtgpu_drm.h +++ b/include/uapi/drm/virtgpu_drm.h @@ -117,6 +117,8 @@ struct drm_virtgpu_3d_transfer_to_host { struct drm_virtgpu_3d_box box; __u32 level; __u32 offset; + __u32 stride; + __u32 layer_stride; }; struct drm_virtgpu_3d_transfer_from_host { @@ -124,6 +126,8 @@ struct drm_virtgpu_3d_transfer_from_host { struct drm_virtgpu_3d_box box; __u32 level; __u32 offset; + __u32 stride; + __u32 layer_stride; }; #define VIRTGPU_WAIT_NOWAIT 1 /* like it */