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 9405EC982DD for ; Fri, 18 Sep 2026 12:05:35 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A267B10F301; Fri, 18 Sep 2026 12:05:32 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=igalia.com header.i=@igalia.com header.b="TGT+tMQq"; dkim-atps=neutral Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) by gabe.freedesktop.org (Postfix) with ESMTPS id 222EE10F305 for ; Fri, 18 Sep 2026 12:05:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:Content-Type:MIME-Version:Message-ID: Date:Subject:Cc:To:From:From:Reply-To; bh=u2IEKEWnCdJHofXQ6eOGW32oTD1Xe0xFgr+JgFeWF9w=; b=TGT+tMQqTOI0gAMA6Mu3LYgOjU IiIsMUM8Vx9PdokFPL75tsxgN79qwD9uBAQnKqcN8BO1VsvXiWDInhBgOv6hk+HCOAaKYEpq2qZf/ 02F6Ek7QJmo0/kgWmXyvVJvyp+POlf7fr5Tt8maKPAzGVPhED4jhLO5PB56JpqGnAdjtCWYd3wVe2 owC9rgNfkGeG1+NKLLeNpyFhP029Hv3PfE3tYlYa8BaSSL9KUrndmS2bNhZ6wZraEteb2gZIArnpk N9yEh7AJ+yXCzeR6lWL4vUsR4h4ULEq73+g7jomOkqpQPiCXR7hVlZqG9Cf5TJFtMbgUpPDbT4a4Y Z0f3GEyA==; Received: from [81.79.79.1] (helo=localhost) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1x7XLL-003vMu-FP; Fri, 18 Sep 2026 14:05:27 +0200 From: Tvrtko Ursulin To: amd-gfx@lists.freedesktop.org Cc: kernel-dev@igalia.com, Tvrtko Ursulin , =?UTF-8?q?Timur=20Krist=C3=B3f?= , Alex Deucher Subject: [PATCH 03/18] drm/amdgpu: More compact UVD 6 IB emission Date: Fri, 18 Sep 2026 13:05:03 +0100 Message-ID: <20260918120518.96922-4-tvrtko.ursulin@igalia.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260918120518.96922-1-tvrtko.ursulin@igalia.com> References: <20260918120518.96922-1-tvrtko.ursulin@igalia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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.uvd 6 Signed-off-by: Tvrtko Ursulin Cc: Timur Kristóf Cc: Alex Deucher --- drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c | 72 ++++++++++++++------------- 1 file changed, 38 insertions(+), 34 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c b/drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c index dcb8487e22b1..2267323333e8 100644 --- a/drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c +++ b/drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c @@ -214,7 +214,8 @@ static int uvd_v6_0_enc_get_create_msg(struct amdgpu_ring *ring, uint32_t 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, @@ -224,27 +225,28 @@ static int uvd_v6_0_enc_get_create_msg(struct amdgpu_ring *ring, uint32_t 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++] = 0x00010000; - ib->ptr[ib->length_dw++] = upper_32_bits(addr); - ib->ptr[ib->length_dw++] = addr; + *ptr++ = 0x00000018; + *ptr++ = 0x00000001; /* session info */ + *ptr++ = handle; + *ptr++ = 0x00010000; + *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++] = 0x00000001; - ib->ptr[ib->length_dw++] = 0x00000000; + *ptr++ = 0x00000014; + *ptr++ = 0x00000002; /* task info */ + *ptr++ = 0x0000001c; + *ptr++ = 0x00000001; + *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) @@ -280,7 +282,8 @@ static int uvd_v6_0_enc_get_destroy_msg(struct amdgpu_ring *ring, 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, @@ -290,27 +293,28 @@ static int uvd_v6_0_enc_get_destroy_msg(struct amdgpu_ring *ring, 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++] = 0x00010000; - ib->ptr[ib->length_dw++] = upper_32_bits(addr); - ib->ptr[ib->length_dw++] = addr; + *ptr++ = 0x00000018; + *ptr++ = 0x00000001; /* session info */ + *ptr++ = handle; + *ptr++ = 0x00010000; + *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++] = 0x00000001; - ib->ptr[ib->length_dw++] = 0x00000000; + *ptr++ = 0x00000014; + *ptr++ = 0x00000002; /* task info */ + *ptr++ = 0x0000001c; + *ptr++ = 0x00000001; + *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.55.0