From patchwork Tue Sep 4 01:00:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bas Nieuwenhuizen X-Patchwork-Id: 10586433 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9D307139B for ; Tue, 4 Sep 2018 01:02:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8373529113 for ; Tue, 4 Sep 2018 01:02:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 758B629119; Tue, 4 Sep 2018 01:02:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1405629113 for ; Tue, 4 Sep 2018 01:02:53 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 83EA989C37; Tue, 4 Sep 2018 01:02:50 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x244.google.com (mail-wm0-x244.google.com [IPv6:2a00:1450:400c:c09::244]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3FEAE89D46 for ; Tue, 4 Sep 2018 01:02:49 +0000 (UTC) Received: by mail-wm0-x244.google.com with SMTP id f21-v6so2592317wmc.5 for ; Mon, 03 Sep 2018 18:02:49 -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=aU7+misVSO2oPLoxTVuqs2wbWCSrBvNr9nOmNrWJUBg=; b=NTXTI6fMZBjeWQq7RmSeCe/h58QbpsdCE2v9oo+/cW79LyrB57+POYn5VGW+fdZfM4 7fjUCCXqM1Uvk4vZw5IYcYPt17Ze3OqoeMjkX1PLhnvofVZk4DWJ0y7+U9Wf/D2omrtK XPZy1PGxGgHt82+kUuxIf5EbDa0iXSuI0FfTxw6GFysrID8g7ZAqJDq5HXTGjBWChRxd JvDyHGpHRcGpC6jLU/Qv3R3v3nCxWUVFtLKnb/8kRFuiZkI4Hcr1rp+4om1LQduAm2kQ G0r9Q71z9S9hnOXOm26UHHeKoM/+hn4NLqo9dUAvyHrKy6G+0a9OUOwfeKwOz2mSsWJZ fHzQ== X-Gm-Message-State: APzg51C3i+3K18E/q2aeXhbtamD3QsPbk5UwiWB6bfm5fSySYrQ6rl+A N4qLnaotD3jJpwBc5K8U2BZb7g== X-Google-Smtp-Source: ANB0VdbznSVSWQK0owLSSetfM/rugCXcZDwcu+sJjGGKre++e3mdQ66fJfE2hOXHh+UMZv0TZx4Z0Q== X-Received: by 2002:a1c:be14:: with SMTP id o20-v6mr961739wmf.73.1536022967891; Mon, 03 Sep 2018 18:02:47 -0700 (PDT) Received: from localhost.localdomain ([2a02:aa12:a77f:2000:7285:c2ff:fe4e:b21b]) by smtp.gmail.com with ESMTPSA id g129-v6sm15482463wmf.42.2018.09.03.18.02.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Sep 2018 18:02:47 -0700 (PDT) From: Bas Nieuwenhuizen To: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Subject: [RFC] drm/amdgpu: Add macros and documentation for format modifiers. Date: Tue, 4 Sep 2018 03:00:33 +0200 Message-Id: <20180904010033.67611-1-bas@basnieuwenhuizen.nl> X-Mailer: git-send-email 2.18.0 MIME-Version: 1.0 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: =?utf-8?q?Nicolai_H=C3=A4hnle?= , Daniel Vetter , Chad Versace , Alex Deucher , Dave Airlie , =?utf-8?b?TWFyZWsgT2zFocOhaw==?= Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP This is an initial proposal for format modifiers for AMD hardware. It uses 48 bits including a chip generation, leaving 8 bits for a format version number. On gfx6-gfx8 we have all the fields influencing sample locations in memory. Tile split bytes are optional for single sample buffers as no hardware reaches the split size with 1 sample and hence the actual size does not matter. The macrotile fields are duplicated for images with multiple planes. If the planes have different bitdepth they need different macro tile fields and different tile split bytes if multisample. I could not fit multiple copies in for tile split bytes, but multisample & multiplane images are very rare. Overall, I think we should punt on multisample for a later format version since they are generally not shared on any modifier aware windowing system, and we have more issues like fmask & cmask. We need these copies because the drm modifier of all planes in an image needs to be equal, so we need to fit these together. This adds fields for compression support, using metadata that is compatible with AMDVLK and for which radv and radeonsi can reasonably be extended. The big open question for compression is between which generations the format changed to see if we can share more. This explicitly does not try to solve the linear stride alignment issue, thoguh we could internally just use the tiling modes for the linear modes to indicate linear images with the stride for the given chip. Signed-off-by: Bas Nieuwenhuizen CC: Chad Versace CC: Dave Airlie CC: Marek Olšák CC: Nicolai Hähnle CC: Alex Deucher CC: Daniel Vetter --- include/uapi/drm/amdgpu_drm.h | 130 ++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) diff --git a/include/uapi/drm/amdgpu_drm.h b/include/uapi/drm/amdgpu_drm.h index 94444eeba55b..4e1452161dbf 100644 --- a/include/uapi/drm/amdgpu_drm.h +++ b/include/uapi/drm/amdgpu_drm.h @@ -990,6 +990,136 @@ struct drm_amdgpu_info_vce_clock_table { #define AMDGPU_FAMILY_AI 141 /* Vega10 */ #define AMDGPU_FAMILY_RV 142 /* Raven */ +#define AMDGPU_CHIP_TAHITI 0 +#define AMDGPU_CHIP_PITCAIRN 1 +#define AMDGPU_CHIP_VERDE 2 +#define AMDGPU_CHIP_OLAND 3 +#define AMDGPU_CHIP_HAINAN 4 +#define AMDGPU_CHIP_BONAIRE 5 +#define AMDGPU_CHIP_KAVERI 6 +#define AMDGPU_CHIP_KABINI 7 +#define AMDGPU_CHIP_HAWAII 8 +#define AMDGPU_CHIP_MULLINS 9 +#define AMDGPU_CHIP_TOPAZ 10 +#define AMDGPU_CHIP_TONGA 11 +#define AMDGPU_CHIP_FIJI 12 +#define AMDGPU_CHIP_CARRIZO 13 +#define AMDGPU_CHIP_STONEY 14 +#define AMDGPU_CHIP_POLARIS10 15 +#define AMDGPU_CHIP_POLARIS11 16 +#define AMDGPU_CHIP_POLARIS12 17 +#define AMDGPU_CHIP_VEGAM 18 +#define AMDGPU_CHIP_VEGA10 19 +#define AMDGPU_CHIP_VEGA12 20 +#define AMDGPU_CHIP_VEGA20 21 +#define AMDGPU_CHIP_RAVEN 22 + +/* Format for GFX6-GFX8 DRM format modifiers. These are intentionally the same + * as AMDGPU_TILING_*. However, the the rules as to when to set them are + * different. + * + * Do not use linear ARRAY_MODEs or SWIZZLE_MODEs. Use DRM_FORMAT_MOD_LINEAR + * instead. + * + * If ARRAY_MODE is 1D, only the micro tile mode and the pipe config should be + * set. + * + * For other ARRAY_MODEs: + * - Only set TILE_SPLIT if the image is multisample. + * + * We have 1 extra bit for the micro tile mode, as GFX6 and GFX7+ have 1 + * different value there. The values are + * - depth : 0 + * - displayable : 1 + * - thin : 2 + * - thick (GFX6) : 3 + * - rotated (GFX7+) : 4 + * + * TODO: What to do with multisample multi plane images? More tile split + * fields don't fit if we want to keep a few bits for a format version. + */ +#define AMDGPU_MODIFIER_GFX8_ARRAY_MODE_SHIFT 0 +#define AMDGPU_MODIFIER_GFX8_ARRAY_MODE_MASK 0xf +#define AMDGPU_MODIFIER_GFX8_PIPE_CONFIG_SHIFT 4 +#define AMDGPU_MODIFIER_GFX8_PIPE_CONFIG_MASK 0x1f +#define AMDGPU_MODIFIER_GFX8_TILE_SPLIT_SHIFT 9 +#define AMDGPU_MODIFIER_GFX8_TILE_SPLIT_MASK 0x7 +#define AMDGPU_MODIFIER_GFX8_MICRO_TILE_MODE_SHIFT 12 +#define AMDGPU_MODIFIER_GFX8_MICRO_TILE_MODE_MASK 0x7 +#define AMDGPU_MODIFIER_GFX8_BANK_WIDTH_SHIFT 15 +#define AMDGPU_MODIFIER_GFX8_BANK_WIDTH_MASK 0x3 +#define AMDGPU_MODIFIER_GFX8_BANK_HEIGHT_SHIFT 17 +#define AMDGPU_MODIFIER_GFX8_BANK_HEIGHT_MASK 0x3 +#define AMDGPU_MODIFIER_GFX8_MACRO_TILE_ASPECT_SHIFT 19 +#define AMDGPU_MODIFIER_GFX8_MACRO_TILE_ASPECT_MASK 0x3 +#define AMDGPU_MODIFIER_GFX8_NUM_BANKS_SHIFT 21 +#define AMDGPU_MODIFIER_GFX8_NUM_BANKS_MASK 0x3 + +/* Macrotile parameters for a second plane if existing */ +#define AMDGPU_MODIFIER_GFX8_BANK_WIDTH_1_SHIFT 23 +#define AMDGPU_MODIFIER_GFX8_BANK_WIDTH_1_MASK 0x3 +#define AMDGPU_MODIFIER_GFX8_BANK_HEIGHT_1_SHIFT 25 +#define AMDGPU_MODIFIER_GFX8_BANK_HEIGHT_1_MASK 0x3 +#define AMDGPU_MODIFIER_GFX8_MACRO_TILE_ASPECT_1_SHIFT 27 +#define AMDGPU_MODIFIER_GFX8_MACRO_TILE_ASPECT_1_MASK 0x3 +#define AMDGPU_MODIFIER_GFX8_NUM_BANKS_1_SHIFT 29 +#define AMDGPU_MODIFIER_GFX8_NUM_BANKS_1_MASK 0x3 + +/* Macrotile parameters for a third plane if existing */ +#define AMDGPU_MODIFIER_GFX8_BANK_WIDTH_2_SHIFT 31 +#define AMDGPU_MODIFIER_GFX8_BANK_WIDTH_2_MASK 0x3 +#define AMDGPU_MODIFIER_GFX8_BANK_HEIGHT_2_SHIFT 33 +#define AMDGPU_MODIFIER_GFX8_BANK_HEIGHT_2_MASK 0x3 +#define AMDGPU_MODIFIER_GFX8_MACRO_TILE_ASPECT_2_SHIFT 35 +#define AMDGPU_MODIFIER_GFX8_MACRO_TILE_ASPECT_2_MASK 0x3 +#define AMDGPU_MODIFIER_GFX8_NUM_BANKS_2_SHIFT 37 +#define AMDGPU_MODIFIER_GFX8_NUM_BANKS_2_MASK 0x3 + +#define AMDGPU_MODIFIER_GFX9_SWIZZLE_MODE_SHIFT 0 +#define AMDGPU_MODIFIER_GFX9_SWIZZLE_MODE_MASK 0x1f + +/* Whether to enable DCC compression. + * + * If enabled, exporting the surface results in three + * planes: + * - color data + * - DCC data + * - a 64-byte block with + * - a 16 byte 0/1 bool as to whether the surface is currently DCC compressed. + * - a 16-byte 0/1 bool as to whether the surface has fastclear data + * - a 8-byte chunk with the current fastclear colors + * + * To ensure we do not keep compressing and decompressing the surface, once it + * has been decompressed no party may recompress again. + * + * Applications should not hand over images with fastclear data as not + * all users can support it, however, to help both Vulkan implementations + * with the allocation we keep it in the 64-byte block. + * + * TODO: Can scanout really not support fastclear data? + * TODO: What to do with multiplane images? + */ +#define AMDGPU_MODIFIER_COMPRESSION_SHIFT 39 +#define AMDGPU_MODIFIER_COMPRESSION_MASK 0x1 + +/* The chip this is compatible with. + * + * If compression is disabled, use + * - AMDGPU_CHIP_TAHITI for GFX6-GFX8 + * - AMDGPU_CHIP_VEGA10 for GFX9+ + * + * With compression enabled please use the exact chip. + * + * TODO: Do some generations share DCC format? + */ +#define AMDGPU_MODIFIER_CHIP_GEN_SHIFT 40 +#define AMDGPU_MODIFIER_CHIP_GEN_MASK 0xff + +#define AMDGPU_MODIFIER_SET(field, value) \ + (((__u64)(value) & AMDGPU_MODIFIER_##field##_MASK) << AMDGPU_MODIFIER_##field##_SHIFT) +#define AMDGPU_MODIFIER_GET(value, field) \ + (((__u64)(value) >> AMDGPU_MODIFIER_##field##_SHIFT) & AMDGPU_MODIFIER_##field##_MASK) + /* * Definition of free sync enter and exit signals * We may have more options in the future