Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 9D86FCDB479 for ; Mon, 22 Jun 2026 12:09:01 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 01E3E10E671; Mon, 22 Jun 2026 12:09:00 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=igalia.com header.i=@igalia.com header.b="gkhjEfGl"; dkim-atps=neutral Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) by gabe.freedesktop.org (Postfix) with ESMTPS id 976C710E664 for ; Mon, 22 Jun 2026 12:08:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=Cedt0Kr4nR8a0o2egHDaIBWCcX+0El5pbXgu4KQuReg=; b=gkhjEfGluZhiRoO0uHFFiLsjjp JKMQKl5atY86171SG2lFcfxydqPVYC5c8hhmMDqK5EOb+wJE56nNLwzlbrBYAq6OgmVa0cNKQLW9N UMX8gnuEH0tFIsAU2Q0QJXrbOH7ExR784xlu5XS7+MHEJIGZiqLAq9AyoSg6BYj3MLmmbWAGPsEnJ bnmX9TxbJJldbBUWgVP8r7HuPYIl9CU3SFSLz2I+mJJ22W6eD0TH5phRPs56nbYbzIYJbV+ojjMSs 0Mf9gelRBP+aGBdHjSUgRBWv+RtSVUVtr0JDwSDWbYeF/NKxJmGlJU/y3DgKjEJWhPI9d/hBHNNgk 7wWyvAVw==; Received: from [90.240.106.137] (helo=localhost) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1wbdSQ-003iz4-MO; Mon, 22 Jun 2026 14:08:54 +0200 From: Tvrtko Ursulin To: amd-gfx@lists.freedesktop.org Cc: kernel-dev@igalia.com, Tvrtko Ursulin Subject: [PATCH 04/16] drm/amdgpu: More compact UVD 7 IB emission Date: Mon, 22 Jun 2026 13:08:23 +0100 Message-ID: <20260622120835.52473-5-tvrtko.ursulin@igalia.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260622120835.52473-1-tvrtko.ursulin@igalia.com> References: <20260622120835.52473-1-tvrtko.ursulin@igalia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: amd-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion list for AMD gfx List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: amd-gfx-bounces@lists.freedesktop.org Sender: "amd-gfx" Avoid constant register reloads while emitting IBs by using a local write pointer and only updating the size at the end of each helper. Signed-off-by: Tvrtko Ursulin --- drivers/gpu/drm/amd/amdgpu/uvd_v7_0.c | 72 ++++++++++++++------------- 1 file changed, 38 insertions(+), 34 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/uvd_v7_0.c b/drivers/gpu/drm/amd/amdgpu/uvd_v7_0.c index df2c83348315..97e51ec2d525 100644 --- a/drivers/gpu/drm/amd/amdgpu/uvd_v7_0.c +++ b/drivers/gpu/drm/amd/amdgpu/uvd_v7_0.c @@ -222,7 +222,8 @@ static int uvd_v7_0_enc_get_create_msg(struct amdgpu_ring *ring, u32 handle, struct amdgpu_ib *ib; struct dma_fence *f = NULL; uint64_t addr; - int i, r; + u32 *ptr; + int r; r = amdgpu_job_alloc_with_ib(ring->adev, NULL, NULL, ib_size_dw * 4, AMDGPU_IB_POOL_DIRECT, &job, @@ -231,27 +232,28 @@ static int uvd_v7_0_enc_get_create_msg(struct amdgpu_ring *ring, u32 handle, return r; ib = &job->ibs[0]; + ptr = ib->ptr; addr = amdgpu_bo_gpu_offset(bo); - ib->length_dw = 0; - ib->ptr[ib->length_dw++] = 0x00000018; - ib->ptr[ib->length_dw++] = 0x00000001; /* session info */ - ib->ptr[ib->length_dw++] = handle; - ib->ptr[ib->length_dw++] = 0x00000000; - ib->ptr[ib->length_dw++] = upper_32_bits(addr); - ib->ptr[ib->length_dw++] = addr; + *ptr++ = 0x00000018; + *ptr++ = 0x00000001; /* session info */ + *ptr++ = handle; + *ptr++ = 0x00000000; + *ptr++ = upper_32_bits(addr); + *ptr++ = addr; - ib->ptr[ib->length_dw++] = 0x00000014; - ib->ptr[ib->length_dw++] = 0x00000002; /* task info */ - ib->ptr[ib->length_dw++] = 0x0000001c; - ib->ptr[ib->length_dw++] = 0x00000000; - ib->ptr[ib->length_dw++] = 0x00000000; + *ptr++ = 0x00000014; + *ptr++ = 0x00000002; /* task info */ + *ptr++ = 0x0000001c; + *ptr++ = 0x00000000; + *ptr++ = 0x00000000; - ib->ptr[ib->length_dw++] = 0x00000008; - ib->ptr[ib->length_dw++] = 0x08000001; /* op initialize */ + *ptr++ = 0x00000008; + *ptr++ = 0x08000001; /* op initialize */ - for (i = ib->length_dw; i < ib_size_dw; ++i) - ib->ptr[i] = 0x0; + ib->length_dw = ptr - ib->ptr; + + memset32(ptr, 0, ib_size_dw - ib->length_dw); r = amdgpu_job_submit_direct(job, ring, &f); if (r) @@ -286,7 +288,8 @@ static int uvd_v7_0_enc_get_destroy_msg(struct amdgpu_ring *ring, u32 handle, struct amdgpu_ib *ib; struct dma_fence *f = NULL; uint64_t addr; - int i, r; + u32 *ptr; + int r; r = amdgpu_job_alloc_with_ib(ring->adev, NULL, NULL, ib_size_dw * 4, AMDGPU_IB_POOL_DIRECT, &job, @@ -295,27 +298,28 @@ static int uvd_v7_0_enc_get_destroy_msg(struct amdgpu_ring *ring, u32 handle, return r; ib = &job->ibs[0]; + ptr = ib->ptr; addr = amdgpu_bo_gpu_offset(bo); - ib->length_dw = 0; - ib->ptr[ib->length_dw++] = 0x00000018; - ib->ptr[ib->length_dw++] = 0x00000001; - ib->ptr[ib->length_dw++] = handle; - ib->ptr[ib->length_dw++] = 0x00000000; - ib->ptr[ib->length_dw++] = upper_32_bits(addr); - ib->ptr[ib->length_dw++] = addr; + *ptr++ = 0x00000018; + *ptr++ = 0x00000001; + *ptr++ = handle; + *ptr++ = 0x00000000; + *ptr++ = upper_32_bits(addr); + *ptr++ = addr; - ib->ptr[ib->length_dw++] = 0x00000014; - ib->ptr[ib->length_dw++] = 0x00000002; - ib->ptr[ib->length_dw++] = 0x0000001c; - ib->ptr[ib->length_dw++] = 0x00000000; - ib->ptr[ib->length_dw++] = 0x00000000; + *ptr++ = 0x00000014; + *ptr++ = 0x00000002; + *ptr++ = 0x0000001c; + *ptr++ = 0x00000000; + *ptr++ = 0x00000000; - ib->ptr[ib->length_dw++] = 0x00000008; - ib->ptr[ib->length_dw++] = 0x08000002; /* op close session */ + *ptr++ = 0x00000008; + *ptr++ = 0x08000002; /* op close session */ - for (i = ib->length_dw; i < ib_size_dw; ++i) - ib->ptr[i] = 0x0; + ib->length_dw = ptr - ib->ptr; + + memset32(ptr, 0, ib_size_dw - ib->length_dw); r = amdgpu_job_submit_direct(job, ring, &f); if (r) -- 2.54.0