1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright 2017 Intel Corporation 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 10bf215546Sopenharmony_ci * 11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next 12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 13bf215546Sopenharmony_ci * Software. 14bf215546Sopenharmony_ci * 15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21bf215546Sopenharmony_ci * IN THE SOFTWARE. 22bf215546Sopenharmony_ci */ 23bf215546Sopenharmony_ci 24bf215546Sopenharmony_ci#include <assert.h> 25bf215546Sopenharmony_ci#include <stdlib.h> 26bf215546Sopenharmony_ci 27bf215546Sopenharmony_ci#include "drm-uapi/drm_fourcc.h" 28bf215546Sopenharmony_ci#include "drm-uapi/i915_drm.h" 29bf215546Sopenharmony_ci 30bf215546Sopenharmony_ci#include "isl.h" 31bf215546Sopenharmony_ci#include "dev/intel_device_info.h" 32bf215546Sopenharmony_ci#include "dev/intel_debug.h" 33bf215546Sopenharmony_ci 34bf215546Sopenharmony_ciuint32_t 35bf215546Sopenharmony_ciisl_tiling_to_i915_tiling(enum isl_tiling tiling) 36bf215546Sopenharmony_ci{ 37bf215546Sopenharmony_ci switch (tiling) { 38bf215546Sopenharmony_ci case ISL_TILING_LINEAR: 39bf215546Sopenharmony_ci return I915_TILING_NONE; 40bf215546Sopenharmony_ci 41bf215546Sopenharmony_ci case ISL_TILING_X: 42bf215546Sopenharmony_ci return I915_TILING_X; 43bf215546Sopenharmony_ci 44bf215546Sopenharmony_ci case ISL_TILING_Y0: 45bf215546Sopenharmony_ci case ISL_TILING_HIZ: 46bf215546Sopenharmony_ci case ISL_TILING_CCS: 47bf215546Sopenharmony_ci return I915_TILING_Y; 48bf215546Sopenharmony_ci 49bf215546Sopenharmony_ci case ISL_TILING_W: 50bf215546Sopenharmony_ci case ISL_TILING_Yf: 51bf215546Sopenharmony_ci case ISL_TILING_Ys: 52bf215546Sopenharmony_ci case ISL_TILING_4: 53bf215546Sopenharmony_ci case ISL_TILING_64: 54bf215546Sopenharmony_ci case ISL_TILING_GFX12_CCS: 55bf215546Sopenharmony_ci return I915_TILING_NONE; 56bf215546Sopenharmony_ci } 57bf215546Sopenharmony_ci 58bf215546Sopenharmony_ci unreachable("Invalid ISL tiling"); 59bf215546Sopenharmony_ci} 60bf215546Sopenharmony_ci 61bf215546Sopenharmony_cienum isl_tiling 62bf215546Sopenharmony_ciisl_tiling_from_i915_tiling(uint32_t tiling) 63bf215546Sopenharmony_ci{ 64bf215546Sopenharmony_ci switch (tiling) { 65bf215546Sopenharmony_ci case I915_TILING_NONE: 66bf215546Sopenharmony_ci return ISL_TILING_LINEAR; 67bf215546Sopenharmony_ci 68bf215546Sopenharmony_ci case I915_TILING_X: 69bf215546Sopenharmony_ci return ISL_TILING_X; 70bf215546Sopenharmony_ci 71bf215546Sopenharmony_ci case I915_TILING_Y: 72bf215546Sopenharmony_ci return ISL_TILING_Y0; 73bf215546Sopenharmony_ci } 74bf215546Sopenharmony_ci 75bf215546Sopenharmony_ci unreachable("Invalid i915 tiling"); 76bf215546Sopenharmony_ci} 77bf215546Sopenharmony_ci 78bf215546Sopenharmony_ci/** Sentinel is DRM_FORMAT_MOD_INVALID. */ 79bf215546Sopenharmony_ciconst struct isl_drm_modifier_info 80bf215546Sopenharmony_ciisl_drm_modifier_info_list[] = { 81bf215546Sopenharmony_ci { 82bf215546Sopenharmony_ci .modifier = DRM_FORMAT_MOD_NONE, 83bf215546Sopenharmony_ci .name = "DRM_FORMAT_MOD_NONE", 84bf215546Sopenharmony_ci .tiling = ISL_TILING_LINEAR, 85bf215546Sopenharmony_ci }, 86bf215546Sopenharmony_ci { 87bf215546Sopenharmony_ci .modifier = I915_FORMAT_MOD_X_TILED, 88bf215546Sopenharmony_ci .name = "I915_FORMAT_MOD_X_TILED", 89bf215546Sopenharmony_ci .tiling = ISL_TILING_X, 90bf215546Sopenharmony_ci }, 91bf215546Sopenharmony_ci { 92bf215546Sopenharmony_ci .modifier = I915_FORMAT_MOD_Y_TILED, 93bf215546Sopenharmony_ci .name = "I915_FORMAT_MOD_Y_TILED", 94bf215546Sopenharmony_ci .tiling = ISL_TILING_Y0, 95bf215546Sopenharmony_ci }, 96bf215546Sopenharmony_ci { 97bf215546Sopenharmony_ci .modifier = I915_FORMAT_MOD_Y_TILED_CCS, 98bf215546Sopenharmony_ci .name = "I915_FORMAT_MOD_Y_TILED_CCS", 99bf215546Sopenharmony_ci .tiling = ISL_TILING_Y0, 100bf215546Sopenharmony_ci .aux_usage = ISL_AUX_USAGE_CCS_E, 101bf215546Sopenharmony_ci .supports_clear_color = false, 102bf215546Sopenharmony_ci }, 103bf215546Sopenharmony_ci { 104bf215546Sopenharmony_ci .modifier = I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS, 105bf215546Sopenharmony_ci .name = "I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS", 106bf215546Sopenharmony_ci .tiling = ISL_TILING_Y0, 107bf215546Sopenharmony_ci .aux_usage = ISL_AUX_USAGE_GFX12_CCS_E, 108bf215546Sopenharmony_ci .supports_clear_color = false, 109bf215546Sopenharmony_ci }, 110bf215546Sopenharmony_ci { 111bf215546Sopenharmony_ci .modifier = I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS, 112bf215546Sopenharmony_ci .name = "I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS", 113bf215546Sopenharmony_ci .tiling = ISL_TILING_Y0, 114bf215546Sopenharmony_ci .aux_usage = ISL_AUX_USAGE_MC, 115bf215546Sopenharmony_ci .supports_clear_color = false, 116bf215546Sopenharmony_ci }, 117bf215546Sopenharmony_ci { 118bf215546Sopenharmony_ci .modifier = I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS_CC, 119bf215546Sopenharmony_ci .name = "I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS_CC", 120bf215546Sopenharmony_ci .tiling = ISL_TILING_Y0, 121bf215546Sopenharmony_ci .aux_usage = ISL_AUX_USAGE_GFX12_CCS_E, 122bf215546Sopenharmony_ci .supports_clear_color = true, 123bf215546Sopenharmony_ci }, 124bf215546Sopenharmony_ci { 125bf215546Sopenharmony_ci .modifier = I915_FORMAT_MOD_4_TILED, 126bf215546Sopenharmony_ci .name = "I915_FORMAT_MOD_4_TILED", 127bf215546Sopenharmony_ci .tiling = ISL_TILING_4, 128bf215546Sopenharmony_ci }, 129bf215546Sopenharmony_ci { 130bf215546Sopenharmony_ci .modifier = I915_FORMAT_MOD_4_TILED_DG2_RC_CCS, 131bf215546Sopenharmony_ci .name = "I915_FORMAT_MOD_4_TILED_DG2_RC_CCS", 132bf215546Sopenharmony_ci .tiling = ISL_TILING_4, 133bf215546Sopenharmony_ci .aux_usage = ISL_AUX_USAGE_GFX12_CCS_E, 134bf215546Sopenharmony_ci .supports_clear_color = false, 135bf215546Sopenharmony_ci }, 136bf215546Sopenharmony_ci { 137bf215546Sopenharmony_ci .modifier = I915_FORMAT_MOD_4_TILED_DG2_MC_CCS, 138bf215546Sopenharmony_ci .name = "I915_FORMAT_MOD_4_TILED_DG2_MC_CCS", 139bf215546Sopenharmony_ci .tiling = ISL_TILING_4, 140bf215546Sopenharmony_ci .aux_usage = ISL_AUX_USAGE_MC, 141bf215546Sopenharmony_ci .supports_clear_color = false, 142bf215546Sopenharmony_ci }, 143bf215546Sopenharmony_ci { 144bf215546Sopenharmony_ci .modifier = I915_FORMAT_MOD_4_TILED_DG2_RC_CCS_CC, 145bf215546Sopenharmony_ci .name = "I915_FORMAT_MOD_4_TILED_DG2_RC_CCS_CC", 146bf215546Sopenharmony_ci .tiling = ISL_TILING_4, 147bf215546Sopenharmony_ci .aux_usage = ISL_AUX_USAGE_GFX12_CCS_E, 148bf215546Sopenharmony_ci .supports_clear_color = true, 149bf215546Sopenharmony_ci }, 150bf215546Sopenharmony_ci { 151bf215546Sopenharmony_ci .modifier = DRM_FORMAT_MOD_INVALID, 152bf215546Sopenharmony_ci }, 153bf215546Sopenharmony_ci}; 154bf215546Sopenharmony_ci 155bf215546Sopenharmony_ciconst struct isl_drm_modifier_info * 156bf215546Sopenharmony_ciisl_drm_modifier_get_info(uint64_t modifier) 157bf215546Sopenharmony_ci{ 158bf215546Sopenharmony_ci isl_drm_modifier_info_for_each(info) { 159bf215546Sopenharmony_ci if (info->modifier == modifier) 160bf215546Sopenharmony_ci return info; 161bf215546Sopenharmony_ci } 162bf215546Sopenharmony_ci 163bf215546Sopenharmony_ci return NULL; 164bf215546Sopenharmony_ci} 165bf215546Sopenharmony_ci 166bf215546Sopenharmony_ciuint32_t 167bf215546Sopenharmony_ciisl_drm_modifier_get_score(const struct intel_device_info *devinfo, 168bf215546Sopenharmony_ci uint64_t modifier) 169bf215546Sopenharmony_ci{ 170bf215546Sopenharmony_ci /* FINISHME: Add gfx12 modifiers */ 171bf215546Sopenharmony_ci switch (modifier) { 172bf215546Sopenharmony_ci default: 173bf215546Sopenharmony_ci return 0; 174bf215546Sopenharmony_ci case DRM_FORMAT_MOD_LINEAR: 175bf215546Sopenharmony_ci return 1; 176bf215546Sopenharmony_ci case I915_FORMAT_MOD_X_TILED: 177bf215546Sopenharmony_ci return 2; 178bf215546Sopenharmony_ci case I915_FORMAT_MOD_Y_TILED: 179bf215546Sopenharmony_ci /* Gfx12.5 doesn't have Y-tiling. */ 180bf215546Sopenharmony_ci if (devinfo->verx10 >= 125) 181bf215546Sopenharmony_ci return 0; 182bf215546Sopenharmony_ci 183bf215546Sopenharmony_ci return 3; 184bf215546Sopenharmony_ci case I915_FORMAT_MOD_4_TILED: 185bf215546Sopenharmony_ci /* Gfx12.5 introduces Tile4. */ 186bf215546Sopenharmony_ci if (devinfo->verx10 < 125) 187bf215546Sopenharmony_ci return 0; 188bf215546Sopenharmony_ci 189bf215546Sopenharmony_ci return 3; 190bf215546Sopenharmony_ci case I915_FORMAT_MOD_Y_TILED_CCS: 191bf215546Sopenharmony_ci /* Gfx12's CCS layout differs from Gfx9-11. */ 192bf215546Sopenharmony_ci if (devinfo->ver >= 12) 193bf215546Sopenharmony_ci return 0; 194bf215546Sopenharmony_ci 195bf215546Sopenharmony_ci if (INTEL_DEBUG(DEBUG_NO_CCS)) 196bf215546Sopenharmony_ci return 0; 197bf215546Sopenharmony_ci 198bf215546Sopenharmony_ci return 4; 199bf215546Sopenharmony_ci } 200bf215546Sopenharmony_ci} 201