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 B86D6C982E0 for ; Fri, 18 Sep 2026 12:05:39 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 98D5710F320; Fri, 18 Sep 2026 12:05:36 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=igalia.com header.i=@igalia.com header.b="nsCXBN/I"; dkim-atps=neutral Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) by gabe.freedesktop.org (Postfix) with ESMTPS id 82E0110F301 for ; Fri, 18 Sep 2026 12:05:28 +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=JwuG2MjBrs3oa3hAhqB6offRvQ9TX4+T1VmeRxfmLRA=; b=nsCXBN/ImgiQ5bkAg7PkkORx9d GyTznVpiEBZ3JfC2IETqdtWlmSgd2QuZyRbGbsYGCeRS8aO37ONZtvFsXP7tqDP1hU4QyN8JF+A40 ZxC9HUEfUCpE1DWpYlRSynInNaWxXqssqGd2VnODC2mT1Feiw3kXkUn6Gkd3NjB7Pk3xwzZiwU9vC hoovNeWgZlXbRNxBC9AyAhdzFOpylmGPN2E4dP5KKaDw5P3lpuLgGaJ0rp3rwuenk2zSguz1rGEIM Olv6c9YO2IVBo80OQNfU+AqUchAKWlJqP2/b3jDQ3BePV0vFsnfFNYTpzC77LAo9IofJbxpW5yB1P EcUnuTsw==; 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 1x7XLK-003vMj-NZ; Fri, 18 Sep 2026 14:05:26 +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 02/18] drm/amdgpu: More compact VCE IB emission Date: Fri, 18 Sep 2026 13:05:02 +0100 Message-ID: <20260918120518.96922-3-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. Signed-off-by: Tvrtko Ursulin Cc: Timur Kristóf Cc: Alex Deucher --- drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c | 96 +++++++++++++------------ 1 file changed, 50 insertions(+), 46 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c index 1f7a98cdce5a..bed02782b983 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c @@ -468,7 +468,8 @@ static int amdgpu_vce_get_create_msg(struct amdgpu_ring *ring, uint32_t handle, struct amdgpu_ib ib_msg; struct dma_fence *f = NULL; uint64_t addr; - int i, r; + u32 *ptr; + int r; r = amdgpu_job_alloc_with_ib(ring->adev, &ring->adev->vce.entity, AMDGPU_FENCE_OWNER_UNDEFINED, @@ -487,45 +488,46 @@ static int amdgpu_vce_get_create_msg(struct amdgpu_ring *ring, uint32_t handle, goto err; ib = &job->ibs[0]; + ptr = ib->ptr; /* let addr point to page boundary */ addr = AMDGPU_GPU_PAGE_ALIGN(ib_msg.gpu_addr); /* stitch together an VCE create msg */ - ib->length_dw = 0; - ib->ptr[ib->length_dw++] = 0x0000000c; /* len */ - ib->ptr[ib->length_dw++] = 0x00000001; /* session cmd */ - ib->ptr[ib->length_dw++] = handle; + *ptr++ = 0x0000000c; /* len */ + *ptr++ = 0x00000001; /* session cmd */ + *ptr++ = handle; if ((ring->adev->vce.fw_version >> 24) >= 52) - ib->ptr[ib->length_dw++] = 0x00000040; /* len */ + *ptr++ = 0x00000040; /* len */ else - ib->ptr[ib->length_dw++] = 0x00000030; /* len */ - ib->ptr[ib->length_dw++] = 0x01000001; /* create cmd */ - ib->ptr[ib->length_dw++] = 0x00000000; - ib->ptr[ib->length_dw++] = 0x00000042; - ib->ptr[ib->length_dw++] = 0x0000000a; - ib->ptr[ib->length_dw++] = 0x00000001; - ib->ptr[ib->length_dw++] = 0x00000080; - ib->ptr[ib->length_dw++] = 0x00000060; - ib->ptr[ib->length_dw++] = 0x00000100; - ib->ptr[ib->length_dw++] = 0x00000100; - ib->ptr[ib->length_dw++] = 0x0000000c; - ib->ptr[ib->length_dw++] = 0x00000000; + *ptr++ = 0x00000030; /* len */ + *ptr++ = 0x01000001; /* create cmd */ + *ptr++ = 0x00000000; + *ptr++ = 0x00000042; + *ptr++ = 0x0000000a; + *ptr++ = 0x00000001; + *ptr++ = 0x00000080; + *ptr++ = 0x00000060; + *ptr++ = 0x00000100; + *ptr++ = 0x00000100; + *ptr++ = 0x0000000c; + *ptr++ = 0x00000000; if ((ring->adev->vce.fw_version >> 24) >= 52) { - ib->ptr[ib->length_dw++] = 0x00000000; - ib->ptr[ib->length_dw++] = 0x00000000; - ib->ptr[ib->length_dw++] = 0x00000000; - ib->ptr[ib->length_dw++] = 0x00000000; + *ptr++ = 0x00000000; + *ptr++ = 0x00000000; + *ptr++ = 0x00000000; + *ptr++ = 0x00000000; } - ib->ptr[ib->length_dw++] = 0x00000014; /* len */ - ib->ptr[ib->length_dw++] = 0x05000005; /* feedback buffer */ - ib->ptr[ib->length_dw++] = upper_32_bits(addr); - ib->ptr[ib->length_dw++] = addr; - ib->ptr[ib->length_dw++] = 0x00000001; + *ptr++ = 0x00000014; /* len */ + *ptr++ = 0x05000005; /* feedback buffer */ + *ptr++ = upper_32_bits(addr); + *ptr++ = addr; + *ptr++ = 0x00000001; - 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); amdgpu_ib_free(&ib_msg, f); @@ -559,7 +561,8 @@ static int amdgpu_vce_get_destroy_msg(struct amdgpu_ring *ring, uint32_t handle, struct amdgpu_job *job; struct amdgpu_ib *ib; struct dma_fence *f = NULL; - int i, r; + u32 *ptr; + int r; r = amdgpu_job_alloc_with_ib(ring->adev, &ring->adev->vce.entity, AMDGPU_FENCE_OWNER_UNDEFINED, @@ -572,27 +575,28 @@ static int amdgpu_vce_get_destroy_msg(struct amdgpu_ring *ring, uint32_t handle, return r; ib = &job->ibs[0]; + ptr = ib->ptr; /* stitch together an VCE destroy msg */ - ib->length_dw = 0; - ib->ptr[ib->length_dw++] = 0x0000000c; /* len */ - ib->ptr[ib->length_dw++] = 0x00000001; /* session cmd */ - ib->ptr[ib->length_dw++] = handle; + *ptr++ = 0x0000000c; /* len */ + *ptr++ = 0x00000001; /* session cmd */ + *ptr++ = handle; - ib->ptr[ib->length_dw++] = 0x00000020; /* len */ - ib->ptr[ib->length_dw++] = 0x00000002; /* task info */ - ib->ptr[ib->length_dw++] = 0xffffffff; /* next task info, set to 0xffffffff if no */ - ib->ptr[ib->length_dw++] = 0x00000001; /* destroy session */ - ib->ptr[ib->length_dw++] = 0x00000000; - ib->ptr[ib->length_dw++] = 0x00000000; - ib->ptr[ib->length_dw++] = 0xffffffff; /* feedback is not needed, set to 0xffffffff and firmware will not output feedback */ - ib->ptr[ib->length_dw++] = 0x00000000; + *ptr++ = 0x00000020; /* len */ + *ptr++ = 0x00000002; /* task info */ + *ptr++ = 0xffffffff; /* next task info, set to 0xffffffff if no */ + *ptr++ = 0x00000001; /* destroy session */ + *ptr++ = 0x00000000; + *ptr++ = 0x00000000; + *ptr++ = 0xffffffff; /* feedback is not needed, set to 0xffffffff and firmware will not output feedback */ + *ptr++ = 0x00000000; - ib->ptr[ib->length_dw++] = 0x00000008; /* len */ - ib->ptr[ib->length_dw++] = 0x02000001; /* destroy cmd */ + *ptr++ = 0x00000008; /* len */ + *ptr++ = 0x02000001; /* destroy cmd */ - 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); if (direct) r = amdgpu_job_submit_direct(job, ring, &f); -- 2.55.0