Path: blob/21.2-virgl/src/intel/isl/isl_format.c
4547 views
/*1* Copyright 2015 Intel Corporation2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20* IN THE SOFTWARE.21*/2223#include <assert.h>2425#include "isl.h"26#include "isl_priv.h"27#include "dev/intel_device_info.h"2829#include "main/macros.h" /* Needed for MAX3 and MAX2 for format_rgb9e5 */30#include "util/format_srgb.h"31#include "util/format_rgb9e5.h"32#include "util/format_r11g11b10f.h"3334/* Header-only format conversion include */35#include "main/format_utils.h"3637struct surface_format_info {38bool exists;39uint8_t sampling;40uint8_t filtering;41uint8_t shadow_compare;42uint8_t chroma_key;43uint8_t render_target;44uint8_t alpha_blend;45uint8_t input_vb;46uint8_t streamed_output_vb;47uint8_t color_processing;48uint8_t typed_write;49uint8_t typed_read;50uint8_t ccs_e;51};5253/* This macro allows us to write the table almost as it appears in the PRM,54* while restructuring it to turn it into the C code we want.55*/56#define SF(sampl, filt, shad, ck, rt, ab, vb, so, color, tw, tr, ccs_e, sf) \57[ISL_FORMAT_##sf] = { true, sampl, filt, shad, ck, rt, ab, vb, so, color, tw, tr, ccs_e},5859#define Y 060#define x 25561/**62* This is the table of support for surface (texture, renderbuffer, and vertex63* buffer, but not depthbuffer) formats across the various hardware generations.64*65* The table is formatted to match the documentation, except that the docs have66* this ridiculous mapping of Y[*+~^#&] for "supported on DevWhatever". To put67* it in our table, here's the mapping:68*69* Y*: 4570* Y+: 45 (g45/gm45)71* Y~: 50 (gfx5)72* Y^: 60 (gfx6)73* Y#: 70 (gfx7)74*75* The abbreviations in the header below are:76* smpl - Sampling Engine77* filt - Sampling Engine Filtering78* shad - Sampling Engine Shadow Map79* CK - Sampling Engine Chroma Key80* RT - Render Target81* AB - Alpha Blend Render Target82* VB - Input Vertex Buffer83* SO - Steamed Output Vertex Buffers (transform feedback)84* color - Color Processing85* TW - Typed Write86* TR - Typed Read87* ccs_e - Lossless Compression Support (gfx9+ only)88* sf - Surface Format89*90* See page 88 of the Sandybridge PRM VOL4_Part1 PDF.91*92* As of Ivybridge, the columns are no longer in that table and the93* information can be found spread across:94*95* - VOL2_Part1 section 2.5.11 Format Conversion (vertex fetch).96* - VOL4_Part1 section 2.12.2.1.2 Sampler Output Channel Mapping.97* - VOL4_Part1 section 3.9.11 Render Target Write.98* - Render Target Surface Types [SKL+]99*/100static const struct surface_format_info format_info[] = {101/* smpl filt shad CK RT AB VB SO color TW TR ccs_e */102SF( Y, 50, x, x, Y, Y, Y, Y, x, 70, 90, 90, R32G32B32A32_FLOAT)103SF( Y, x, x, x, Y, x, Y, Y, x, 70, 90, 90, R32G32B32A32_SINT)104SF( Y, x, x, x, Y, x, Y, Y, x, 70, 90, 90, R32G32B32A32_UINT)105SF( x, x, x, x, x, x, Y, x, x, x, x, x, R32G32B32A32_UNORM)106SF( x, x, x, x, x, x, Y, x, x, x, x, x, R32G32B32A32_SNORM)107SF( x, x, x, x, x, x, Y, x, x, x, x, x, R64G64_FLOAT)108SF( Y, 50, x, x, 100, 100, x, x, x, x, x, 100, R32G32B32X32_FLOAT)109SF( x, x, x, x, x, x, Y, x, x, x, x, x, R32G32B32A32_SSCALED)110SF( x, x, x, x, x, x, Y, x, x, x, x, x, R32G32B32A32_USCALED)111SF( x, x, x, x, x, x, 75, x, x, x, x, x, R32G32B32A32_SFIXED)112SF( x, x, x, x, x, x, 80, x, x, x, x, x, R64G64_PASSTHRU)113SF( Y, 50, x, x, x, x, Y, Y, x, x, x, x, R32G32B32_FLOAT)114SF( Y, x, x, x, x, x, Y, Y, x, x, x, x, R32G32B32_SINT)115SF( Y, x, x, x, x, x, Y, Y, x, x, x, x, R32G32B32_UINT)116SF( x, x, x, x, x, x, Y, x, x, x, x, x, R32G32B32_UNORM)117SF( x, x, x, x, x, x, Y, x, x, x, x, x, R32G32B32_SNORM)118SF( x, x, x, x, x, x, Y, x, x, x, x, x, R32G32B32_SSCALED)119SF( x, x, x, x, x, x, Y, x, x, x, x, x, R32G32B32_USCALED)120SF( x, x, x, x, x, x, 75, x, x, x, x, x, R32G32B32_SFIXED)121SF( Y, Y, x, x, Y, 45, Y, x, 60, 70, 110, 90, R16G16B16A16_UNORM)122SF( Y, Y, x, x, Y, 60, Y, x, x, 70, 110, 90, R16G16B16A16_SNORM)123SF( Y, x, x, x, Y, x, Y, x, x, 70, 90, 90, R16G16B16A16_SINT)124SF( Y, x, x, x, Y, x, Y, x, x, 70, 75, 90, R16G16B16A16_UINT)125SF( Y, Y, x, x, Y, Y, Y, x, x, 70, 90, 90, R16G16B16A16_FLOAT)126SF( Y, 50, x, x, Y, Y, Y, Y, x, 70, 90, 90, R32G32_FLOAT)127SF( Y, 70, x, x, Y, Y, Y, Y, x, x, x, x, R32G32_FLOAT_LD)128SF( Y, x, x, x, Y, x, Y, Y, x, 70, 90, 90, R32G32_SINT)129SF( Y, x, x, x, Y, x, Y, Y, x, 70, 90, 90, R32G32_UINT)130SF( Y, 50, Y, x, x, x, x, x, x, x, x, x, R32_FLOAT_X8X24_TYPELESS)131SF( Y, x, x, x, x, x, x, x, x, x, x, x, X32_TYPELESS_G8X24_UINT)132SF( Y, 50, x, x, x, x, x, x, x, x, x, x, L32A32_FLOAT)133SF( x, x, x, x, x, x, Y, x, x, x, x, x, R32G32_UNORM)134SF( x, x, x, x, x, x, Y, x, x, x, x, x, R32G32_SNORM)135SF( x, x, x, x, x, x, Y, x, x, x, x, x, R64_FLOAT)136SF( Y, Y, x, x, x, x, x, x, x, x, x, x, R16G16B16X16_UNORM)137SF( Y, Y, x, x, 90, 90, x, x, x, x, x, 90, R16G16B16X16_FLOAT)138SF( Y, 50, x, x, x, x, x, x, x, x, x, x, A32X32_FLOAT)139SF( Y, 50, x, x, x, x, x, x, x, x, x, x, L32X32_FLOAT)140SF( Y, 50, x, x, x, x, x, x, x, x, x, x, I32X32_FLOAT)141SF( x, x, x, x, x, x, Y, x, x, x, x, x, R16G16B16A16_SSCALED)142SF( x, x, x, x, x, x, Y, x, x, x, x, x, R16G16B16A16_USCALED)143SF( x, x, x, x, x, x, Y, x, x, x, x, x, R32G32_SSCALED)144SF( x, x, x, x, x, x, Y, x, x, x, x, x, R32G32_USCALED)145SF( x, x, x, x, x, x, 75, x, x, x, x, x, R32G32_SFIXED)146SF( x, x, x, x, x, x, 80, x, x, x, x, x, R64_PASSTHRU)147SF( Y, Y, x, Y, Y, Y, Y, x, 60, 70, x, 90, B8G8R8A8_UNORM)148SF( Y, Y, x, x, Y, Y, x, x, x, x, x, 100, B8G8R8A8_UNORM_SRGB)149/* smpl filt shad CK RT AB VB SO color TW TR ccs_e */150SF( Y, Y, x, x, Y, Y, Y, x, 60, 70, x, 100, R10G10B10A2_UNORM)151SF( Y, Y, x, x, x, x, x, x, 60, x, x, 120, R10G10B10A2_UNORM_SRGB)152SF( Y, x, x, x, Y, x, Y, x, x, 70, x, 100, R10G10B10A2_UINT)153SF( Y, Y, x, x, x, x, Y, x, x, x, x, x, R10G10B10_SNORM_A2_UNORM)154SF( Y, Y, x, x, Y, Y, Y, x, 60, 70, 110, 90, R8G8B8A8_UNORM)155SF( Y, Y, x, x, Y, Y, x, x, 60, x, x, 100, R8G8B8A8_UNORM_SRGB)156SF( Y, Y, x, x, Y, 60, Y, x, x, 70, 110, 90, R8G8B8A8_SNORM)157SF( Y, x, x, x, Y, x, Y, x, x, 70, 90, 90, R8G8B8A8_SINT)158SF( Y, x, x, x, Y, x, Y, x, x, 70, 75, 90, R8G8B8A8_UINT)159SF( Y, Y, x, x, Y, 45, Y, x, x, 70, 110, 90, R16G16_UNORM)160SF( Y, Y, x, x, Y, 60, Y, x, x, 70, 110, 90, R16G16_SNORM)161SF( Y, x, x, x, Y, x, Y, x, x, 70, 90, 90, R16G16_SINT)162SF( Y, x, x, x, Y, x, Y, x, x, 70, 75, 90, R16G16_UINT)163SF( Y, Y, x, x, Y, Y, Y, x, x, 70, 90, 90, R16G16_FLOAT)164SF( Y, Y, x, x, Y, Y, 75, x, 60, 70, x, 100, B10G10R10A2_UNORM)165SF( Y, Y, x, x, Y, Y, x, x, 60, x, x, 100, B10G10R10A2_UNORM_SRGB)166SF( Y, Y, x, x, Y, Y, Y, x, x, 70, x, 100, R11G11B10_FLOAT)167SF(120, 120, x, x, 120, 120, x, x, x, x, x, 120, R10G10B10_FLOAT_A2_UNORM)168SF( Y, x, x, x, Y, x, Y, Y, x, 70, 70, 90, R32_SINT)169SF( Y, x, x, x, Y, x, Y, Y, x, 70, 70, 90, R32_UINT)170SF( Y, 50, Y, x, Y, Y, Y, Y, x, 70, 70, 90, R32_FLOAT)171SF( Y, 50, Y, x, x, x, x, x, x, x, x, 120, R24_UNORM_X8_TYPELESS)172SF( Y, x, x, x, x, x, x, x, x, x, x, x, X24_TYPELESS_G8_UINT)173SF( Y, Y, x, x, x, x, x, x, x, x, x, x, L16A16_UNORM)174SF( Y, 50, Y, x, x, x, x, x, x, x, x, x, I24X8_UNORM)175SF( Y, 50, Y, x, x, x, x, x, x, x, x, x, L24X8_UNORM)176SF( Y, 50, Y, x, x, x, x, x, x, x, x, x, A24X8_UNORM)177SF( Y, 50, Y, x, x, x, x, x, x, x, x, x, I32_FLOAT)178SF( Y, 50, Y, x, x, x, x, x, x, x, x, x, L32_FLOAT)179SF( Y, 50, Y, x, x, x, x, x, x, x, x, x, A32_FLOAT)180SF( Y, Y, x, Y, 80, 80, x, x, 60, x, x, 90, B8G8R8X8_UNORM)181SF( Y, Y, x, x, 80, 80, x, x, x, x, x, 100, B8G8R8X8_UNORM_SRGB)182SF( Y, Y, x, x, x, x, x, x, x, x, x, x, R8G8B8X8_UNORM)183SF( Y, Y, x, x, x, x, x, x, x, x, x, x, R8G8B8X8_UNORM_SRGB)184SF( Y, Y, x, x, x, x, x, x, x, x, x, x, R9G9B9E5_SHAREDEXP)185SF( Y, Y, x, x, x, x, x, x, x, x, x, x, B10G10R10X2_UNORM)186SF( Y, Y, x, x, x, x, x, x, x, x, x, x, L16A16_FLOAT)187SF( x, x, x, x, x, x, Y, x, x, x, x, x, R32_UNORM)188SF( x, x, x, x, x, x, Y, x, x, x, x, x, R32_SNORM)189/* smpl filt shad CK RT AB VB SO color TW TR ccs_e */190SF( x, x, x, x, x, x, Y, x, x, x, x, x, R10G10B10X2_USCALED)191SF( x, x, x, x, x, x, Y, x, x, x, x, x, R8G8B8A8_SSCALED)192SF( x, x, x, x, x, x, Y, x, x, x, x, x, R8G8B8A8_USCALED)193SF( x, x, x, x, x, x, Y, x, x, x, x, x, R16G16_SSCALED)194SF( x, x, x, x, x, x, Y, x, x, x, x, x, R16G16_USCALED)195SF( x, x, x, x, x, x, Y, x, x, x, x, x, R32_SSCALED)196SF( x, x, x, x, x, x, Y, x, x, x, x, x, R32_USCALED)197SF( Y, Y, x, Y, Y, Y, x, x, x, 70, x, 120, B5G6R5_UNORM)198SF( Y, Y, x, x, Y, Y, x, x, x, x, x, 120, B5G6R5_UNORM_SRGB)199SF( Y, Y, x, Y, Y, Y, x, x, x, 70, x, 120, B5G5R5A1_UNORM)200SF( Y, Y, x, x, Y, Y, x, x, x, x, x, 120, B5G5R5A1_UNORM_SRGB)201SF( Y, Y, x, Y, Y, Y, x, x, x, 70, x, 120, B4G4R4A4_UNORM)202SF( Y, Y, x, x, Y, Y, x, x, x, x, x, 120, B4G4R4A4_UNORM_SRGB)203SF( Y, Y, x, x, Y, Y, Y, x, x, 70, 110, 120, R8G8_UNORM)204SF( Y, Y, x, Y, Y, 60, Y, x, x, 70, 110, 120, R8G8_SNORM)205SF( Y, x, x, x, Y, x, Y, x, x, 70, 90, 120, R8G8_SINT)206SF( Y, x, x, x, Y, x, Y, x, x, 70, 75, 120, R8G8_UINT)207SF( Y, Y, Y, x, Y, 45, Y, x, 70, 70, 110, 120, R16_UNORM)208SF( Y, Y, x, x, Y, 60, Y, x, x, 70, 110, 120, R16_SNORM)209SF( Y, x, x, x, Y, x, Y, x, x, 70, 90, 120, R16_SINT)210SF( Y, x, x, x, Y, x, Y, x, x, 70, 75, 120, R16_UINT)211SF( Y, Y, x, x, Y, Y, Y, x, x, 70, 90, 120, R16_FLOAT)212SF( 50, 50, x, x, x, x, x, x, x, x, x, x, A8P8_UNORM_PALETTE0)213SF( 50, 50, x, x, x, x, x, x, x, x, x, x, A8P8_UNORM_PALETTE1)214SF( Y, Y, Y, x, x, x, x, x, x, x, x, x, I16_UNORM)215SF( Y, Y, Y, x, x, x, x, x, x, x, x, x, L16_UNORM)216SF( Y, Y, Y, x, x, x, x, x, x, x, x, x, A16_UNORM)217SF( Y, Y, x, Y, x, x, x, x, x, x, x, x, L8A8_UNORM)218SF( Y, Y, Y, x, x, x, x, x, x, x, x, x, I16_FLOAT)219SF( Y, Y, Y, x, x, x, x, x, x, x, x, x, L16_FLOAT)220SF( Y, Y, Y, x, x, x, x, x, x, x, x, x, A16_FLOAT)221SF( 45, 45, x, x, x, x, x, x, x, x, x, x, L8A8_UNORM_SRGB)222SF( Y, Y, x, Y, x, x, x, x, x, x, x, x, R5G5_SNORM_B6_UNORM)223SF( x, x, x, x, Y, Y, x, x, x, 70, x, 120, B5G5R5X1_UNORM)224SF( x, x, x, x, Y, Y, x, x, x, x, x, 120, B5G5R5X1_UNORM_SRGB)225SF( x, x, x, x, x, x, Y, x, x, x, x, x, R8G8_SSCALED)226SF( x, x, x, x, x, x, Y, x, x, x, x, x, R8G8_USCALED)227/* smpl filt shad CK RT AB VB SO color TW TR ccs_e */228SF( x, x, x, x, x, x, Y, x, x, x, x, x, R16_SSCALED)229SF( x, x, x, x, x, x, Y, x, x, x, x, x, R16_USCALED)230SF( 50, 50, x, x, x, x, x, x, x, x, x, x, P8A8_UNORM_PALETTE0)231SF( 50, 50, x, x, x, x, x, x, x, x, x, x, P8A8_UNORM_PALETTE1)232SF(120, 120, x, x, 120, 120, x, x, x, x, x, 120, A1B5G5R5_UNORM)233/* According to the PRM, A4B4G4R4_UNORM isn't supported until Sky Lake234* but empirical testing indicates that at least sampling works just fine235* on Broadwell.236*/237SF( 80, 80, x, x, 90, 120, x, x, x, x, x, 120, A4B4G4R4_UNORM)238SF( 90, x, x, x, x, x, x, x, x, x, x, x, L8A8_UINT)239SF( 90, x, x, x, x, x, x, x, x, x, x, x, L8A8_SINT)240SF( Y, Y, x, 45, Y, Y, Y, x, x, 70, 110, 120, R8_UNORM)241SF( Y, Y, x, x, Y, 60, Y, x, x, 70, 110, 120, R8_SNORM)242SF( Y, x, x, x, Y, x, Y, x, x, 70, 90, 120, R8_SINT)243SF( Y, x, x, x, Y, x, Y, x, x, 70, 75, 120, R8_UINT)244SF( Y, Y, x, Y, Y, Y, x, x, x, 70, 110, 120, A8_UNORM)245SF( Y, Y, x, x, x, x, x, x, x, x, x, x, I8_UNORM)246SF( Y, Y, x, Y, x, x, x, x, x, x, x, x, L8_UNORM)247SF( Y, Y, x, x, x, x, x, x, x, x, x, x, P4A4_UNORM_PALETTE0)248SF( Y, Y, x, x, x, x, x, x, x, x, x, x, A4P4_UNORM_PALETTE0)249SF( x, x, x, x, x, x, Y, x, x, x, x, x, R8_SSCALED)250SF( x, x, x, x, x, x, Y, x, x, x, x, x, R8_USCALED)251SF( 45, 45, x, x, x, x, x, x, x, x, x, x, P8_UNORM_PALETTE0)252SF( 45, 45, x, x, x, x, x, x, x, x, x, x, L8_UNORM_SRGB)253SF( 45, 45, x, x, x, x, x, x, x, x, x, x, P8_UNORM_PALETTE1)254SF( 45, 45, x, x, x, x, x, x, x, x, x, x, P4A4_UNORM_PALETTE1)255SF( 45, 45, x, x, x, x, x, x, x, x, x, x, A4P4_UNORM_PALETTE1)256SF( x, x, x, x, x, x, x, x, x, x, x, x, Y8_UNORM)257SF( 90, x, x, x, x, x, x, x, x, x, x, x, L8_UINT)258SF( 90, x, x, x, x, x, x, x, x, x, x, x, L8_SINT)259SF( 90, x, x, x, x, x, x, x, x, x, x, x, I8_UINT)260SF( 90, x, x, x, x, x, x, x, x, x, x, x, I8_SINT)261SF( 45, 45, x, x, x, x, x, x, x, x, x, x, DXT1_RGB_SRGB)262SF( Y, Y, x, x, x, x, x, x, x, x, x, x, R1_UNORM)263SF( Y, Y, x, Y, Y, x, x, x, 60, x, x, x, YCRCB_NORMAL)264SF( Y, Y, x, Y, Y, x, x, x, 60, x, x, x, YCRCB_SWAPUVY)265SF( 45, 45, x, x, x, x, x, x, x, x, x, x, P2_UNORM_PALETTE0)266SF( 45, 45, x, x, x, x, x, x, x, x, x, x, P2_UNORM_PALETTE1)267SF( Y, Y, x, Y, x, x, x, x, x, x, x, x, BC1_UNORM)268SF( Y, Y, x, Y, x, x, x, x, x, x, x, x, BC2_UNORM)269SF( Y, Y, x, Y, x, x, x, x, x, x, x, x, BC3_UNORM)270SF( Y, Y, x, x, x, x, x, x, x, x, x, x, BC4_UNORM)271SF( Y, Y, x, x, x, x, x, x, x, x, x, x, BC5_UNORM)272SF( Y, Y, x, x, x, x, x, x, x, x, x, x, BC1_UNORM_SRGB)273SF( Y, Y, x, x, x, x, x, x, x, x, x, x, BC2_UNORM_SRGB)274SF( Y, Y, x, x, x, x, x, x, x, x, x, x, BC3_UNORM_SRGB)275SF( Y, x, x, x, x, x, x, x, x, x, x, x, MONO8)276SF( Y, Y, x, x, Y, x, x, x, 60, x, x, x, YCRCB_SWAPUV)277SF( Y, Y, x, x, Y, x, x, x, 60, x, x, x, YCRCB_SWAPY)278SF( Y, Y, x, x, x, x, x, x, x, x, x, x, DXT1_RGB)279/* smpl filt shad CK RT AB VB SO color TW TR ccs_e */280SF( Y, Y, x, x, x, x, x, x, x, x, x, x, FXT1)281SF( 75, 75, x, x, x, x, Y, x, x, x, x, x, R8G8B8_UNORM)282SF( 75, 75, x, x, x, x, Y, x, x, x, x, x, R8G8B8_SNORM)283SF( x, x, x, x, x, x, Y, x, x, x, x, x, R8G8B8_SSCALED)284SF( x, x, x, x, x, x, Y, x, x, x, x, x, R8G8B8_USCALED)285SF( x, x, x, x, x, x, Y, x, x, x, x, x, R64G64B64A64_FLOAT)286SF( x, x, x, x, x, x, Y, x, x, x, x, x, R64G64B64_FLOAT)287SF( Y, Y, x, x, x, x, x, x, x, x, x, x, BC4_SNORM)288SF( Y, Y, x, x, x, x, x, x, x, x, x, x, BC5_SNORM)289SF( 50, 50, x, x, x, x, 60, x, x, x, x, x, R16G16B16_FLOAT)290SF( 75, 75, x, x, x, x, Y, x, x, x, x, x, R16G16B16_UNORM)291SF( 75, 75, x, x, x, x, Y, x, x, x, x, x, R16G16B16_SNORM)292SF( x, x, x, x, x, x, Y, x, x, x, x, x, R16G16B16_SSCALED)293SF( x, x, x, x, x, x, Y, x, x, x, x, x, R16G16B16_USCALED)294SF( 70, 70, x, x, x, x, x, x, x, x, x, x, BC6H_SF16)295SF( 70, 70, x, x, x, x, x, x, x, x, x, x, BC7_UNORM)296SF( 70, 70, x, x, x, x, x, x, x, x, x, x, BC7_UNORM_SRGB)297SF( 70, 70, x, x, x, x, x, x, x, x, x, x, BC6H_UF16)298SF( x, x, x, x, x, x, x, x, x, x, x, x, PLANAR_420_8)299/* The format enum for R8G8B8_UNORM_SRGB first shows up in the HSW PRM but300* empirical testing indicates that it doesn't actually sRGB decode and301* acts identical to R8G8B8_UNORM. It does work on gfx8+.302*/303SF( 80, 80, x, x, x, x, x, x, x, x, x, x, R8G8B8_UNORM_SRGB)304SF( 80, 80, x, x, x, x, x, x, x, x, x, x, ETC1_RGB8)305SF( 80, 80, x, x, x, x, x, x, x, x, x, x, ETC2_RGB8)306SF( 80, 80, x, x, x, x, x, x, x, x, x, x, EAC_R11)307SF( 80, 80, x, x, x, x, x, x, x, x, x, x, EAC_RG11)308SF( 80, 80, x, x, x, x, x, x, x, x, x, x, EAC_SIGNED_R11)309SF( 80, 80, x, x, x, x, x, x, x, x, x, x, EAC_SIGNED_RG11)310SF( 80, 80, x, x, x, x, x, x, x, x, x, x, ETC2_SRGB8)311SF( 90, x, x, x, x, x, 75, x, x, x, x, x, R16G16B16_UINT)312SF( 90, x, x, x, x, x, 75, x, x, x, x, x, R16G16B16_SINT)313SF( x, x, x, x, x, x, 75, x, x, x, x, x, R32_SFIXED)314SF( x, x, x, x, x, x, 75, x, x, x, x, x, R10G10B10A2_SNORM)315SF( x, x, x, x, x, x, 75, x, x, x, x, x, R10G10B10A2_USCALED)316SF( x, x, x, x, x, x, 75, x, x, x, x, x, R10G10B10A2_SSCALED)317SF( x, x, x, x, x, x, 75, x, x, x, x, x, R10G10B10A2_SINT)318SF( x, x, x, x, x, x, 75, x, x, x, x, x, B10G10R10A2_SNORM)319SF( x, x, x, x, x, x, 75, x, x, x, x, x, B10G10R10A2_USCALED)320SF( x, x, x, x, x, x, 75, x, x, x, x, x, B10G10R10A2_SSCALED)321SF( x, x, x, x, x, x, 75, x, x, x, x, x, B10G10R10A2_UINT)322SF( x, x, x, x, x, x, 75, x, x, x, x, x, B10G10R10A2_SINT)323SF( x, x, x, x, x, x, 80, x, x, x, x, x, R64G64B64A64_PASSTHRU)324SF( x, x, x, x, x, x, 80, x, x, x, x, x, R64G64B64_PASSTHRU)325SF( 80, 80, x, x, x, x, x, x, x, x, x, x, ETC2_RGB8_PTA)326SF( 80, 80, x, x, x, x, x, x, x, x, x, x, ETC2_SRGB8_PTA)327SF( 80, 80, x, x, x, x, x, x, x, x, x, x, ETC2_EAC_RGBA8)328SF( 80, 80, x, x, x, x, x, x, x, x, x, x, ETC2_EAC_SRGB8_A8)329SF( 90, x, x, x, x, x, 75, x, x, x, x, x, R8G8B8_UINT)330SF( 90, x, x, x, x, x, 75, x, x, x, x, x, R8G8B8_SINT)331SF( 90, 90, x, x, x, x, x, x, x, x, x, x, ASTC_LDR_2D_4X4_FLT16)332SF( 90, 90, x, x, x, x, x, x, x, x, x, x, ASTC_LDR_2D_5X4_FLT16)333SF( 90, 90, x, x, x, x, x, x, x, x, x, x, ASTC_LDR_2D_5X5_FLT16)334SF( 90, 90, x, x, x, x, x, x, x, x, x, x, ASTC_LDR_2D_6X5_FLT16)335SF( 90, 90, x, x, x, x, x, x, x, x, x, x, ASTC_LDR_2D_6X6_FLT16)336SF( 90, 90, x, x, x, x, x, x, x, x, x, x, ASTC_LDR_2D_8X5_FLT16)337SF( 90, 90, x, x, x, x, x, x, x, x, x, x, ASTC_LDR_2D_8X6_FLT16)338SF( 90, 90, x, x, x, x, x, x, x, x, x, x, ASTC_LDR_2D_8X8_FLT16)339SF( 90, 90, x, x, x, x, x, x, x, x, x, x, ASTC_LDR_2D_10X5_FLT16)340SF( 90, 90, x, x, x, x, x, x, x, x, x, x, ASTC_LDR_2D_10X6_FLT16)341SF( 90, 90, x, x, x, x, x, x, x, x, x, x, ASTC_LDR_2D_10X8_FLT16)342SF( 90, 90, x, x, x, x, x, x, x, x, x, x, ASTC_LDR_2D_10X10_FLT16)343SF( 90, 90, x, x, x, x, x, x, x, x, x, x, ASTC_LDR_2D_12X10_FLT16)344SF( 90, 90, x, x, x, x, x, x, x, x, x, x, ASTC_LDR_2D_12X12_FLT16)345SF( 90, 90, x, x, x, x, x, x, x, x, x, x, ASTC_LDR_2D_4X4_U8SRGB)346SF( 90, 90, x, x, x, x, x, x, x, x, x, x, ASTC_LDR_2D_5X4_U8SRGB)347SF( 90, 90, x, x, x, x, x, x, x, x, x, x, ASTC_LDR_2D_5X5_U8SRGB)348SF( 90, 90, x, x, x, x, x, x, x, x, x, x, ASTC_LDR_2D_6X5_U8SRGB)349SF( 90, 90, x, x, x, x, x, x, x, x, x, x, ASTC_LDR_2D_6X6_U8SRGB)350SF( 90, 90, x, x, x, x, x, x, x, x, x, x, ASTC_LDR_2D_8X5_U8SRGB)351SF( 90, 90, x, x, x, x, x, x, x, x, x, x, ASTC_LDR_2D_8X6_U8SRGB)352SF( 90, 90, x, x, x, x, x, x, x, x, x, x, ASTC_LDR_2D_8X8_U8SRGB)353SF( 90, 90, x, x, x, x, x, x, x, x, x, x, ASTC_LDR_2D_10X5_U8SRGB)354SF( 90, 90, x, x, x, x, x, x, x, x, x, x, ASTC_LDR_2D_10X6_U8SRGB)355SF( 90, 90, x, x, x, x, x, x, x, x, x, x, ASTC_LDR_2D_10X8_U8SRGB)356SF( 90, 90, x, x, x, x, x, x, x, x, x, x, ASTC_LDR_2D_10X10_U8SRGB)357SF( 90, 90, x, x, x, x, x, x, x, x, x, x, ASTC_LDR_2D_12X10_U8SRGB)358SF( 90, 90, x, x, x, x, x, x, x, x, x, x, ASTC_LDR_2D_12X12_U8SRGB)359SF(100, 100, x, x, x, x, x, x, x, x, x, x, ASTC_HDR_2D_4X4_FLT16)360SF(100, 100, x, x, x, x, x, x, x, x, x, x, ASTC_HDR_2D_5X4_FLT16)361SF(100, 100, x, x, x, x, x, x, x, x, x, x, ASTC_HDR_2D_5X5_FLT16)362SF(100, 100, x, x, x, x, x, x, x, x, x, x, ASTC_HDR_2D_6X5_FLT16)363SF(100, 100, x, x, x, x, x, x, x, x, x, x, ASTC_HDR_2D_6X6_FLT16)364SF(100, 100, x, x, x, x, x, x, x, x, x, x, ASTC_HDR_2D_8X5_FLT16)365SF(100, 100, x, x, x, x, x, x, x, x, x, x, ASTC_HDR_2D_8X6_FLT16)366SF(100, 100, x, x, x, x, x, x, x, x, x, x, ASTC_HDR_2D_8X8_FLT16)367SF(100, 100, x, x, x, x, x, x, x, x, x, x, ASTC_HDR_2D_10X5_FLT16)368SF(100, 100, x, x, x, x, x, x, x, x, x, x, ASTC_HDR_2D_10X6_FLT16)369SF(100, 100, x, x, x, x, x, x, x, x, x, x, ASTC_HDR_2D_10X8_FLT16)370SF(100, 100, x, x, x, x, x, x, x, x, x, x, ASTC_HDR_2D_10X10_FLT16)371SF(100, 100, x, x, x, x, x, x, x, x, x, x, ASTC_HDR_2D_12X10_FLT16)372SF(100, 100, x, x, x, x, x, x, x, x, x, x, ASTC_HDR_2D_12X12_FLT16)373};374#undef x375#undef Y376377378enum isl_format379isl_format_for_pipe_format(enum pipe_format pf)380{381static const enum isl_format table[PIPE_FORMAT_COUNT] = {382[0 ... PIPE_FORMAT_COUNT-1] = ISL_FORMAT_UNSUPPORTED,383384[PIPE_FORMAT_B8G8R8A8_UNORM] = ISL_FORMAT_B8G8R8A8_UNORM,385[PIPE_FORMAT_B8G8R8X8_UNORM] = ISL_FORMAT_B8G8R8X8_UNORM,386[PIPE_FORMAT_B5G5R5A1_UNORM] = ISL_FORMAT_B5G5R5A1_UNORM,387[PIPE_FORMAT_B4G4R4A4_UNORM] = ISL_FORMAT_B4G4R4A4_UNORM,388[PIPE_FORMAT_B5G6R5_UNORM] = ISL_FORMAT_B5G6R5_UNORM,389[PIPE_FORMAT_R10G10B10A2_UNORM] = ISL_FORMAT_R10G10B10A2_UNORM,390391[PIPE_FORMAT_Z16_UNORM] = ISL_FORMAT_R16_UNORM,392[PIPE_FORMAT_Z32_UNORM] = ISL_FORMAT_R32_UNORM,393[PIPE_FORMAT_Z32_FLOAT] = ISL_FORMAT_R32_FLOAT,394395/* We translate the combined depth/stencil formats to depth only here */396[PIPE_FORMAT_Z24_UNORM_S8_UINT] = ISL_FORMAT_R24_UNORM_X8_TYPELESS,397[PIPE_FORMAT_Z24X8_UNORM] = ISL_FORMAT_R24_UNORM_X8_TYPELESS,398[PIPE_FORMAT_Z32_FLOAT_S8X24_UINT] = ISL_FORMAT_R32_FLOAT,399400[PIPE_FORMAT_S8_UINT] = ISL_FORMAT_R8_UINT,401[PIPE_FORMAT_X24S8_UINT] = ISL_FORMAT_R8_UINT,402[PIPE_FORMAT_X32_S8X24_UINT] = ISL_FORMAT_R8_UINT,403404[PIPE_FORMAT_R64_FLOAT] = ISL_FORMAT_R64_FLOAT,405[PIPE_FORMAT_R64G64_FLOAT] = ISL_FORMAT_R64G64_FLOAT,406[PIPE_FORMAT_R64G64B64_FLOAT] = ISL_FORMAT_R64G64B64_FLOAT,407[PIPE_FORMAT_R64G64B64A64_FLOAT] = ISL_FORMAT_R64G64B64A64_FLOAT,408[PIPE_FORMAT_R32_FLOAT] = ISL_FORMAT_R32_FLOAT,409[PIPE_FORMAT_R32G32_FLOAT] = ISL_FORMAT_R32G32_FLOAT,410[PIPE_FORMAT_R32G32B32_FLOAT] = ISL_FORMAT_R32G32B32_FLOAT,411[PIPE_FORMAT_R32G32B32A32_FLOAT] = ISL_FORMAT_R32G32B32A32_FLOAT,412[PIPE_FORMAT_R32_UNORM] = ISL_FORMAT_R32_UNORM,413[PIPE_FORMAT_R32G32_UNORM] = ISL_FORMAT_R32G32_UNORM,414[PIPE_FORMAT_R32G32B32_UNORM] = ISL_FORMAT_R32G32B32_UNORM,415[PIPE_FORMAT_R32G32B32A32_UNORM] = ISL_FORMAT_R32G32B32A32_UNORM,416[PIPE_FORMAT_R32_USCALED] = ISL_FORMAT_R32_USCALED,417[PIPE_FORMAT_R32G32_USCALED] = ISL_FORMAT_R32G32_USCALED,418[PIPE_FORMAT_R32G32B32_USCALED] = ISL_FORMAT_R32G32B32_USCALED,419[PIPE_FORMAT_R32G32B32A32_USCALED] = ISL_FORMAT_R32G32B32A32_USCALED,420[PIPE_FORMAT_R32_SNORM] = ISL_FORMAT_R32_SNORM,421[PIPE_FORMAT_R32G32_SNORM] = ISL_FORMAT_R32G32_SNORM,422[PIPE_FORMAT_R32G32B32_SNORM] = ISL_FORMAT_R32G32B32_SNORM,423[PIPE_FORMAT_R32G32B32A32_SNORM] = ISL_FORMAT_R32G32B32A32_SNORM,424[PIPE_FORMAT_R32_SSCALED] = ISL_FORMAT_R32_SSCALED,425[PIPE_FORMAT_R32G32_SSCALED] = ISL_FORMAT_R32G32_SSCALED,426[PIPE_FORMAT_R32G32B32_SSCALED] = ISL_FORMAT_R32G32B32_SSCALED,427[PIPE_FORMAT_R32G32B32A32_SSCALED] = ISL_FORMAT_R32G32B32A32_SSCALED,428[PIPE_FORMAT_R16_UNORM] = ISL_FORMAT_R16_UNORM,429[PIPE_FORMAT_R16G16_UNORM] = ISL_FORMAT_R16G16_UNORM,430[PIPE_FORMAT_R16G16B16_UNORM] = ISL_FORMAT_R16G16B16_UNORM,431[PIPE_FORMAT_R16G16B16A16_UNORM] = ISL_FORMAT_R16G16B16A16_UNORM,432[PIPE_FORMAT_R16_USCALED] = ISL_FORMAT_R16_USCALED,433[PIPE_FORMAT_R16G16_USCALED] = ISL_FORMAT_R16G16_USCALED,434[PIPE_FORMAT_R16G16B16_USCALED] = ISL_FORMAT_R16G16B16_USCALED,435[PIPE_FORMAT_R16G16B16A16_USCALED] = ISL_FORMAT_R16G16B16A16_USCALED,436[PIPE_FORMAT_R16_SNORM] = ISL_FORMAT_R16_SNORM,437[PIPE_FORMAT_R16G16_SNORM] = ISL_FORMAT_R16G16_SNORM,438[PIPE_FORMAT_R16G16B16_SNORM] = ISL_FORMAT_R16G16B16_SNORM,439[PIPE_FORMAT_R16G16B16A16_SNORM] = ISL_FORMAT_R16G16B16A16_SNORM,440[PIPE_FORMAT_R16_SSCALED] = ISL_FORMAT_R16_SSCALED,441[PIPE_FORMAT_R16G16_SSCALED] = ISL_FORMAT_R16G16_SSCALED,442[PIPE_FORMAT_R16G16B16_SSCALED] = ISL_FORMAT_R16G16B16_SSCALED,443[PIPE_FORMAT_R16G16B16A16_SSCALED] = ISL_FORMAT_R16G16B16A16_SSCALED,444[PIPE_FORMAT_R8_UNORM] = ISL_FORMAT_R8_UNORM,445[PIPE_FORMAT_R8G8_UNORM] = ISL_FORMAT_R8G8_UNORM,446[PIPE_FORMAT_R8G8B8_UNORM] = ISL_FORMAT_R8G8B8_UNORM,447[PIPE_FORMAT_R8G8B8A8_UNORM] = ISL_FORMAT_R8G8B8A8_UNORM,448[PIPE_FORMAT_R8_USCALED] = ISL_FORMAT_R8_USCALED,449[PIPE_FORMAT_R8G8_USCALED] = ISL_FORMAT_R8G8_USCALED,450[PIPE_FORMAT_R8G8B8_USCALED] = ISL_FORMAT_R8G8B8_USCALED,451[PIPE_FORMAT_R8G8B8A8_USCALED] = ISL_FORMAT_R8G8B8A8_USCALED,452[PIPE_FORMAT_R8_SNORM] = ISL_FORMAT_R8_SNORM,453[PIPE_FORMAT_R8G8_SNORM] = ISL_FORMAT_R8G8_SNORM,454[PIPE_FORMAT_R8G8B8_SNORM] = ISL_FORMAT_R8G8B8_SNORM,455[PIPE_FORMAT_R8G8B8A8_SNORM] = ISL_FORMAT_R8G8B8A8_SNORM,456[PIPE_FORMAT_R8_SSCALED] = ISL_FORMAT_R8_SSCALED,457[PIPE_FORMAT_R8G8_SSCALED] = ISL_FORMAT_R8G8_SSCALED,458[PIPE_FORMAT_R8G8B8_SSCALED] = ISL_FORMAT_R8G8B8_SSCALED,459[PIPE_FORMAT_R8G8B8A8_SSCALED] = ISL_FORMAT_R8G8B8A8_SSCALED,460[PIPE_FORMAT_R32_FIXED] = ISL_FORMAT_R32_SFIXED,461[PIPE_FORMAT_R32G32_FIXED] = ISL_FORMAT_R32G32_SFIXED,462[PIPE_FORMAT_R32G32B32_FIXED] = ISL_FORMAT_R32G32B32_SFIXED,463[PIPE_FORMAT_R32G32B32A32_FIXED] = ISL_FORMAT_R32G32B32A32_SFIXED,464[PIPE_FORMAT_R16_FLOAT] = ISL_FORMAT_R16_FLOAT,465[PIPE_FORMAT_R16G16_FLOAT] = ISL_FORMAT_R16G16_FLOAT,466[PIPE_FORMAT_R16G16B16_FLOAT] = ISL_FORMAT_R16G16B16_FLOAT,467[PIPE_FORMAT_R16G16B16A16_FLOAT] = ISL_FORMAT_R16G16B16A16_FLOAT,468469[PIPE_FORMAT_R8G8B8_SRGB] = ISL_FORMAT_R8G8B8_UNORM_SRGB,470[PIPE_FORMAT_B8G8R8A8_SRGB] = ISL_FORMAT_B8G8R8A8_UNORM_SRGB,471[PIPE_FORMAT_B8G8R8X8_SRGB] = ISL_FORMAT_B8G8R8X8_UNORM_SRGB,472[PIPE_FORMAT_R8G8B8A8_SRGB] = ISL_FORMAT_R8G8B8A8_UNORM_SRGB,473474[PIPE_FORMAT_DXT1_RGB] = ISL_FORMAT_BC1_UNORM,475[PIPE_FORMAT_DXT1_RGBA] = ISL_FORMAT_BC1_UNORM,476[PIPE_FORMAT_DXT3_RGBA] = ISL_FORMAT_BC2_UNORM,477[PIPE_FORMAT_DXT5_RGBA] = ISL_FORMAT_BC3_UNORM,478479[PIPE_FORMAT_DXT1_SRGB] = ISL_FORMAT_BC1_UNORM_SRGB,480[PIPE_FORMAT_DXT1_SRGBA] = ISL_FORMAT_BC1_UNORM_SRGB,481[PIPE_FORMAT_DXT3_SRGBA] = ISL_FORMAT_BC2_UNORM_SRGB,482[PIPE_FORMAT_DXT5_SRGBA] = ISL_FORMAT_BC3_UNORM_SRGB,483484[PIPE_FORMAT_RGTC1_UNORM] = ISL_FORMAT_BC4_UNORM,485[PIPE_FORMAT_RGTC1_SNORM] = ISL_FORMAT_BC4_SNORM,486[PIPE_FORMAT_RGTC2_UNORM] = ISL_FORMAT_BC5_UNORM,487[PIPE_FORMAT_RGTC2_SNORM] = ISL_FORMAT_BC5_SNORM,488489[PIPE_FORMAT_R10G10B10A2_USCALED] = ISL_FORMAT_R10G10B10A2_USCALED,490[PIPE_FORMAT_R11G11B10_FLOAT] = ISL_FORMAT_R11G11B10_FLOAT,491[PIPE_FORMAT_R9G9B9E5_FLOAT] = ISL_FORMAT_R9G9B9E5_SHAREDEXP,492[PIPE_FORMAT_R1_UNORM] = ISL_FORMAT_R1_UNORM,493[PIPE_FORMAT_R10G10B10X2_USCALED] = ISL_FORMAT_R10G10B10X2_USCALED,494[PIPE_FORMAT_B10G10R10A2_UNORM] = ISL_FORMAT_B10G10R10A2_UNORM,495[PIPE_FORMAT_R8G8B8X8_UNORM] = ISL_FORMAT_R8G8B8X8_UNORM,496497/* Just use red formats for these - they're actually renderable,498* and faster to sample than the legacy L/I/A/LA formats.499*/500[PIPE_FORMAT_I8_UNORM] = ISL_FORMAT_R8_UNORM,501[PIPE_FORMAT_I8_UINT] = ISL_FORMAT_R8_UINT,502[PIPE_FORMAT_I8_SINT] = ISL_FORMAT_R8_SINT,503[PIPE_FORMAT_I8_SNORM] = ISL_FORMAT_R8_SNORM,504[PIPE_FORMAT_I16_UINT] = ISL_FORMAT_R16_UINT,505[PIPE_FORMAT_I16_UNORM] = ISL_FORMAT_R16_UNORM,506[PIPE_FORMAT_I16_SINT] = ISL_FORMAT_R16_SINT,507[PIPE_FORMAT_I16_SNORM] = ISL_FORMAT_R16_SNORM,508[PIPE_FORMAT_I16_FLOAT] = ISL_FORMAT_R16_FLOAT,509[PIPE_FORMAT_I32_UINT] = ISL_FORMAT_R32_UINT,510[PIPE_FORMAT_I32_SINT] = ISL_FORMAT_R32_SINT,511[PIPE_FORMAT_I32_FLOAT] = ISL_FORMAT_R32_FLOAT,512513[PIPE_FORMAT_L8_UINT] = ISL_FORMAT_R8_UINT,514[PIPE_FORMAT_L8_UNORM] = ISL_FORMAT_R8_UNORM,515[PIPE_FORMAT_L8_SINT] = ISL_FORMAT_R8_SINT,516[PIPE_FORMAT_L8_SNORM] = ISL_FORMAT_R8_SNORM,517[PIPE_FORMAT_L16_UINT] = ISL_FORMAT_R16_UINT,518[PIPE_FORMAT_L16_UNORM] = ISL_FORMAT_R16_UNORM,519[PIPE_FORMAT_L16_SINT] = ISL_FORMAT_R16_SINT,520[PIPE_FORMAT_L16_SNORM] = ISL_FORMAT_R16_SNORM,521[PIPE_FORMAT_L16_FLOAT] = ISL_FORMAT_R16_FLOAT,522[PIPE_FORMAT_L32_UINT] = ISL_FORMAT_R32_UINT,523[PIPE_FORMAT_L32_SINT] = ISL_FORMAT_R32_SINT,524[PIPE_FORMAT_L32_FLOAT] = ISL_FORMAT_R32_FLOAT,525526/* We also map alpha and luminance-alpha formats to red as well,527* though most of these (other than A8_UNORM) will be non-renderable.528*/529[PIPE_FORMAT_A8_UINT] = ISL_FORMAT_R8_UINT,530[PIPE_FORMAT_A8_UNORM] = ISL_FORMAT_R8_UNORM,531[PIPE_FORMAT_A8_SINT] = ISL_FORMAT_R8_SINT,532[PIPE_FORMAT_A8_SNORM] = ISL_FORMAT_R8_SNORM,533[PIPE_FORMAT_A16_UINT] = ISL_FORMAT_R16_UINT,534[PIPE_FORMAT_A16_UNORM] = ISL_FORMAT_R16_UNORM,535[PIPE_FORMAT_A16_SINT] = ISL_FORMAT_R16_SINT,536[PIPE_FORMAT_A16_SNORM] = ISL_FORMAT_R16_SNORM,537[PIPE_FORMAT_A16_FLOAT] = ISL_FORMAT_R16_FLOAT,538[PIPE_FORMAT_A32_UINT] = ISL_FORMAT_R32_UINT,539[PIPE_FORMAT_A32_SINT] = ISL_FORMAT_R32_SINT,540[PIPE_FORMAT_A32_FLOAT] = ISL_FORMAT_R32_FLOAT,541542[PIPE_FORMAT_L8A8_UINT] = ISL_FORMAT_R8G8_UINT,543[PIPE_FORMAT_L8A8_UNORM] = ISL_FORMAT_R8G8_UNORM,544[PIPE_FORMAT_L8A8_SINT] = ISL_FORMAT_R8G8_SINT,545[PIPE_FORMAT_L8A8_SNORM] = ISL_FORMAT_R8G8_SNORM,546[PIPE_FORMAT_L16A16_UINT] = ISL_FORMAT_R16G16_UINT,547[PIPE_FORMAT_L16A16_UNORM] = ISL_FORMAT_R16G16_UNORM,548[PIPE_FORMAT_L16A16_SINT] = ISL_FORMAT_R16G16_SINT,549[PIPE_FORMAT_L16A16_SNORM] = ISL_FORMAT_R16G16_SNORM,550[PIPE_FORMAT_L16A16_FLOAT] = ISL_FORMAT_R16G16_FLOAT,551[PIPE_FORMAT_L32A32_UINT] = ISL_FORMAT_R32G32_UINT,552[PIPE_FORMAT_L32A32_SINT] = ISL_FORMAT_R32G32_SINT,553[PIPE_FORMAT_L32A32_FLOAT] = ISL_FORMAT_R32G32_FLOAT,554555/* Sadly, we have to use luminance[-alpha] formats for sRGB decoding. */556[PIPE_FORMAT_R8_SRGB] = ISL_FORMAT_L8_UNORM_SRGB,557[PIPE_FORMAT_L8_SRGB] = ISL_FORMAT_L8_UNORM_SRGB,558[PIPE_FORMAT_L8A8_SRGB] = ISL_FORMAT_L8A8_UNORM_SRGB,559560[PIPE_FORMAT_R10G10B10A2_SSCALED] = ISL_FORMAT_R10G10B10A2_SSCALED,561[PIPE_FORMAT_R10G10B10A2_SNORM] = ISL_FORMAT_R10G10B10A2_SNORM,562563[PIPE_FORMAT_B10G10R10A2_USCALED] = ISL_FORMAT_B10G10R10A2_USCALED,564[PIPE_FORMAT_B10G10R10A2_SSCALED] = ISL_FORMAT_B10G10R10A2_SSCALED,565[PIPE_FORMAT_B10G10R10A2_SNORM] = ISL_FORMAT_B10G10R10A2_SNORM,566567[PIPE_FORMAT_R8_UINT] = ISL_FORMAT_R8_UINT,568[PIPE_FORMAT_R8G8_UINT] = ISL_FORMAT_R8G8_UINT,569[PIPE_FORMAT_R8G8B8_UINT] = ISL_FORMAT_R8G8B8_UINT,570[PIPE_FORMAT_R8G8B8A8_UINT] = ISL_FORMAT_R8G8B8A8_UINT,571572[PIPE_FORMAT_R8_SINT] = ISL_FORMAT_R8_SINT,573[PIPE_FORMAT_R8G8_SINT] = ISL_FORMAT_R8G8_SINT,574[PIPE_FORMAT_R8G8B8_SINT] = ISL_FORMAT_R8G8B8_SINT,575[PIPE_FORMAT_R8G8B8A8_SINT] = ISL_FORMAT_R8G8B8A8_SINT,576577[PIPE_FORMAT_R16_UINT] = ISL_FORMAT_R16_UINT,578[PIPE_FORMAT_R16G16_UINT] = ISL_FORMAT_R16G16_UINT,579[PIPE_FORMAT_R16G16B16_UINT] = ISL_FORMAT_R16G16B16_UINT,580[PIPE_FORMAT_R16G16B16A16_UINT] = ISL_FORMAT_R16G16B16A16_UINT,581582[PIPE_FORMAT_R16_SINT] = ISL_FORMAT_R16_SINT,583[PIPE_FORMAT_R16G16_SINT] = ISL_FORMAT_R16G16_SINT,584[PIPE_FORMAT_R16G16B16_SINT] = ISL_FORMAT_R16G16B16_SINT,585[PIPE_FORMAT_R16G16B16A16_SINT] = ISL_FORMAT_R16G16B16A16_SINT,586587[PIPE_FORMAT_R32_UINT] = ISL_FORMAT_R32_UINT,588[PIPE_FORMAT_R32G32_UINT] = ISL_FORMAT_R32G32_UINT,589[PIPE_FORMAT_R32G32B32_UINT] = ISL_FORMAT_R32G32B32_UINT,590[PIPE_FORMAT_R32G32B32A32_UINT] = ISL_FORMAT_R32G32B32A32_UINT,591592[PIPE_FORMAT_R32_SINT] = ISL_FORMAT_R32_SINT,593[PIPE_FORMAT_R32G32_SINT] = ISL_FORMAT_R32G32_SINT,594[PIPE_FORMAT_R32G32B32_SINT] = ISL_FORMAT_R32G32B32_SINT,595[PIPE_FORMAT_R32G32B32A32_SINT] = ISL_FORMAT_R32G32B32A32_SINT,596597[PIPE_FORMAT_B10G10R10A2_UINT] = ISL_FORMAT_B10G10R10A2_UINT,598599[PIPE_FORMAT_ETC1_RGB8] = ISL_FORMAT_ETC1_RGB8,600601/* The formats say YCrCb, but there's no colorspace conversion. */602[PIPE_FORMAT_R8G8_R8B8_UNORM] = ISL_FORMAT_YCRCB_NORMAL,603[PIPE_FORMAT_G8R8_B8R8_UNORM] = ISL_FORMAT_YCRCB_SWAPY,604605[PIPE_FORMAT_R8G8B8X8_SRGB] = ISL_FORMAT_R8G8B8X8_UNORM_SRGB,606[PIPE_FORMAT_B10G10R10X2_UNORM] = ISL_FORMAT_B10G10R10X2_UNORM,607[PIPE_FORMAT_R16G16B16X16_UNORM] = ISL_FORMAT_R16G16B16X16_UNORM,608[PIPE_FORMAT_R16G16B16X16_FLOAT] = ISL_FORMAT_R16G16B16X16_FLOAT,609[PIPE_FORMAT_R32G32B32X32_FLOAT] = ISL_FORMAT_R32G32B32X32_FLOAT,610611[PIPE_FORMAT_R10G10B10A2_UINT] = ISL_FORMAT_R10G10B10A2_UINT,612613[PIPE_FORMAT_B5G6R5_SRGB] = ISL_FORMAT_B5G6R5_UNORM_SRGB,614615[PIPE_FORMAT_BPTC_RGBA_UNORM] = ISL_FORMAT_BC7_UNORM,616[PIPE_FORMAT_BPTC_SRGBA] = ISL_FORMAT_BC7_UNORM_SRGB,617[PIPE_FORMAT_BPTC_RGB_FLOAT] = ISL_FORMAT_BC6H_SF16,618[PIPE_FORMAT_BPTC_RGB_UFLOAT] = ISL_FORMAT_BC6H_UF16,619620[PIPE_FORMAT_ETC2_RGB8] = ISL_FORMAT_ETC2_RGB8,621[PIPE_FORMAT_ETC2_SRGB8] = ISL_FORMAT_ETC2_SRGB8,622[PIPE_FORMAT_ETC2_RGB8A1] = ISL_FORMAT_ETC2_RGB8_PTA,623[PIPE_FORMAT_ETC2_SRGB8A1] = ISL_FORMAT_ETC2_SRGB8_PTA,624[PIPE_FORMAT_ETC2_RGBA8] = ISL_FORMAT_ETC2_EAC_RGBA8,625[PIPE_FORMAT_ETC2_SRGBA8] = ISL_FORMAT_ETC2_EAC_SRGB8_A8,626[PIPE_FORMAT_ETC2_R11_UNORM] = ISL_FORMAT_EAC_R11,627[PIPE_FORMAT_ETC2_R11_SNORM] = ISL_FORMAT_EAC_SIGNED_R11,628[PIPE_FORMAT_ETC2_RG11_UNORM] = ISL_FORMAT_EAC_RG11,629[PIPE_FORMAT_ETC2_RG11_SNORM] = ISL_FORMAT_EAC_SIGNED_RG11,630631[PIPE_FORMAT_FXT1_RGB] = ISL_FORMAT_FXT1,632[PIPE_FORMAT_FXT1_RGBA] = ISL_FORMAT_FXT1,633634[PIPE_FORMAT_ASTC_4x4] = ISL_FORMAT_ASTC_LDR_2D_4X4_FLT16,635[PIPE_FORMAT_ASTC_5x4] = ISL_FORMAT_ASTC_LDR_2D_5X4_FLT16,636[PIPE_FORMAT_ASTC_5x5] = ISL_FORMAT_ASTC_LDR_2D_5X5_FLT16,637[PIPE_FORMAT_ASTC_6x5] = ISL_FORMAT_ASTC_LDR_2D_6X5_FLT16,638[PIPE_FORMAT_ASTC_6x6] = ISL_FORMAT_ASTC_LDR_2D_6X6_FLT16,639[PIPE_FORMAT_ASTC_8x5] = ISL_FORMAT_ASTC_LDR_2D_8X5_FLT16,640[PIPE_FORMAT_ASTC_8x6] = ISL_FORMAT_ASTC_LDR_2D_8X6_FLT16,641[PIPE_FORMAT_ASTC_8x8] = ISL_FORMAT_ASTC_LDR_2D_8X8_FLT16,642[PIPE_FORMAT_ASTC_10x5] = ISL_FORMAT_ASTC_LDR_2D_10X5_FLT16,643[PIPE_FORMAT_ASTC_10x6] = ISL_FORMAT_ASTC_LDR_2D_10X6_FLT16,644[PIPE_FORMAT_ASTC_10x8] = ISL_FORMAT_ASTC_LDR_2D_10X8_FLT16,645[PIPE_FORMAT_ASTC_10x10] = ISL_FORMAT_ASTC_LDR_2D_10X10_FLT16,646[PIPE_FORMAT_ASTC_12x10] = ISL_FORMAT_ASTC_LDR_2D_12X10_FLT16,647[PIPE_FORMAT_ASTC_12x12] = ISL_FORMAT_ASTC_LDR_2D_12X12_FLT16,648649[PIPE_FORMAT_ASTC_4x4_SRGB] = ISL_FORMAT_ASTC_LDR_2D_4X4_U8SRGB,650[PIPE_FORMAT_ASTC_5x4_SRGB] = ISL_FORMAT_ASTC_LDR_2D_5X4_U8SRGB,651[PIPE_FORMAT_ASTC_5x5_SRGB] = ISL_FORMAT_ASTC_LDR_2D_5X5_U8SRGB,652[PIPE_FORMAT_ASTC_6x5_SRGB] = ISL_FORMAT_ASTC_LDR_2D_6X5_U8SRGB,653[PIPE_FORMAT_ASTC_6x6_SRGB] = ISL_FORMAT_ASTC_LDR_2D_6X6_U8SRGB,654[PIPE_FORMAT_ASTC_8x5_SRGB] = ISL_FORMAT_ASTC_LDR_2D_8X5_U8SRGB,655[PIPE_FORMAT_ASTC_8x6_SRGB] = ISL_FORMAT_ASTC_LDR_2D_8X6_U8SRGB,656[PIPE_FORMAT_ASTC_8x8_SRGB] = ISL_FORMAT_ASTC_LDR_2D_8X8_U8SRGB,657[PIPE_FORMAT_ASTC_10x5_SRGB] = ISL_FORMAT_ASTC_LDR_2D_10X5_U8SRGB,658[PIPE_FORMAT_ASTC_10x6_SRGB] = ISL_FORMAT_ASTC_LDR_2D_10X6_U8SRGB,659[PIPE_FORMAT_ASTC_10x8_SRGB] = ISL_FORMAT_ASTC_LDR_2D_10X8_U8SRGB,660[PIPE_FORMAT_ASTC_10x10_SRGB] = ISL_FORMAT_ASTC_LDR_2D_10X10_U8SRGB,661[PIPE_FORMAT_ASTC_12x10_SRGB] = ISL_FORMAT_ASTC_LDR_2D_12X10_U8SRGB,662[PIPE_FORMAT_ASTC_12x12_SRGB] = ISL_FORMAT_ASTC_LDR_2D_12X12_U8SRGB,663664[PIPE_FORMAT_A1B5G5R5_UNORM] = ISL_FORMAT_A1B5G5R5_UNORM,665666/* We support these so that we know the API expects no alpha channel.667* Otherwise, the state tracker would just give us a format with alpha668* and we wouldn't know to override the swizzle to 1.669*/670[PIPE_FORMAT_R16G16B16X16_UINT] = ISL_FORMAT_R16G16B16A16_UINT,671[PIPE_FORMAT_R16G16B16X16_SINT] = ISL_FORMAT_R16G16B16A16_SINT,672[PIPE_FORMAT_R32G32B32X32_UINT] = ISL_FORMAT_R32G32B32A32_UINT,673[PIPE_FORMAT_R32G32B32X32_SINT] = ISL_FORMAT_R32G32B32A32_SINT,674[PIPE_FORMAT_R10G10B10X2_SNORM] = ISL_FORMAT_R10G10B10A2_SNORM,675};676assert(pf < PIPE_FORMAT_COUNT);677return table[pf];678}679680static bool681format_info_exists(enum isl_format format)682{683assert(format != ISL_FORMAT_UNSUPPORTED);684assert(format < ISL_NUM_FORMATS);685return format < ARRAY_SIZE(format_info) && format_info[format].exists;686}687688bool689isl_format_supports_rendering(const struct intel_device_info *devinfo,690enum isl_format format)691{692if (!format_info_exists(format))693return false;694695return devinfo->verx10 >= format_info[format].render_target;696}697698bool699isl_format_supports_alpha_blending(const struct intel_device_info *devinfo,700enum isl_format format)701{702if (!format_info_exists(format))703return false;704705return devinfo->verx10 >= format_info[format].alpha_blend;706}707708bool709isl_format_supports_sampling(const struct intel_device_info *devinfo,710enum isl_format format)711{712if (!format_info_exists(format))713return false;714715if (devinfo->is_baytrail) {716const struct isl_format_layout *fmtl = isl_format_get_layout(format);717/* Support for ETC1 and ETC2 exists on Bay Trail even though big-core718* GPUs didn't get it until Broadwell.719*/720if (fmtl->txc == ISL_TXC_ETC1 || fmtl->txc == ISL_TXC_ETC2)721return true;722} else if (devinfo->is_cherryview) {723const struct isl_format_layout *fmtl = isl_format_get_layout(format);724/* Support for ASTC LDR exists on Cherry View even though big-core725* GPUs didn't get it until Skylake.726*/727if (fmtl->txc == ISL_TXC_ASTC)728return format < ISL_FORMAT_ASTC_HDR_2D_4X4_FLT16;729} else if (intel_device_info_is_9lp(devinfo)) {730const struct isl_format_layout *fmtl = isl_format_get_layout(format);731/* Support for ASTC HDR exists on Broxton even though big-core732* GPUs didn't get it until Cannonlake.733*/734if (fmtl->txc == ISL_TXC_ASTC)735return true;736}737738return devinfo->verx10 >= format_info[format].sampling;739}740741bool742isl_format_supports_filtering(const struct intel_device_info *devinfo,743enum isl_format format)744{745if (!format_info_exists(format))746return false;747748if (devinfo->is_baytrail) {749const struct isl_format_layout *fmtl = isl_format_get_layout(format);750/* Support for ETC1 and ETC2 exists on Bay Trail even though big-core751* GPUs didn't get it until Broadwell.752*/753if (fmtl->txc == ISL_TXC_ETC1 || fmtl->txc == ISL_TXC_ETC2)754return true;755} else if (devinfo->is_cherryview) {756const struct isl_format_layout *fmtl = isl_format_get_layout(format);757/* Support for ASTC LDR exists on Cherry View even though big-core758* GPUs didn't get it until Skylake.759*/760if (fmtl->txc == ISL_TXC_ASTC)761return format < ISL_FORMAT_ASTC_HDR_2D_4X4_FLT16;762} else if (intel_device_info_is_9lp(devinfo)) {763const struct isl_format_layout *fmtl = isl_format_get_layout(format);764/* Support for ASTC HDR exists on Broxton even though big-core765* GPUs didn't get it until Cannonlake.766*/767if (fmtl->txc == ISL_TXC_ASTC)768return true;769}770771return devinfo->verx10 >= format_info[format].filtering;772}773774bool775isl_format_supports_vertex_fetch(const struct intel_device_info *devinfo,776enum isl_format format)777{778if (!format_info_exists(format))779return false;780781/* For vertex fetch, Bay Trail supports the same set of formats as Haswell782* but is a superset of Ivy Bridge.783*/784if (devinfo->is_baytrail)785return 75 >= format_info[format].input_vb;786787return devinfo->verx10 >= format_info[format].input_vb;788}789790/**791* Returns true if the given format can support typed writes.792*/793bool794isl_format_supports_typed_writes(const struct intel_device_info *devinfo,795enum isl_format format)796{797if (!format_info_exists(format))798return false;799800return devinfo->verx10 >= format_info[format].typed_write;801}802803804/**805* Returns true if the given format can support typed reads with format806* conversion fully handled by hardware. On Sky Lake, all formats which are807* supported for typed writes also support typed reads but some of them return808* the raw image data and don't provide format conversion.809*810* For anyone looking to find this data in the PRM, the easiest way to find811* format tables is to search for R11G11B10. There are only a few812* occurrences.813*/814bool815isl_format_supports_typed_reads(const struct intel_device_info *devinfo,816enum isl_format format)817{818if (!format_info_exists(format))819return false;820821return devinfo->verx10 >= format_info[format].typed_read;822}823824/**825* Returns true if the given format can support single-sample fast clears.826* This function only checks the format. In order to determine if a surface827* supports CCS_E, several other factors need to be considered such as tiling828* and sample count. See isl_surf_get_ccs_surf for details.829*/830bool831isl_format_supports_ccs_d(const struct intel_device_info *devinfo,832enum isl_format format)833{834/* Clear-only compression was first added on Ivy Bridge and was last835* implemented on Ice lake (see BSpec: 43862).836*/837if (devinfo->ver < 7 || devinfo->ver > 11)838return false;839840if (!isl_format_supports_rendering(devinfo, format))841return false;842843const struct isl_format_layout *fmtl = isl_format_get_layout(format);844845return fmtl->bpb == 32 || fmtl->bpb == 64 || fmtl->bpb == 128;846}847848/**849* Returns true if the given format can support single-sample color850* compression. This function only checks the format. In order to determine851* if a surface supports CCS_E, several other factors need to be considered852* such as tiling and sample count. See isl_surf_get_ccs_surf for details.853*/854bool855isl_format_supports_ccs_e(const struct intel_device_info *devinfo,856enum isl_format format)857{858/* Wa_22011186057: Disable compression on ADL-P A0 */859if (devinfo->is_alderlake && devinfo->gt == 2 && devinfo->revision == 0)860return false;861862if (!format_info_exists(format))863return false;864865/* For simplicity, only report that a format supports CCS_E if blorp can866* perform bit-for-bit copies with an image of that format while compressed.867* Unfortunately, R11G11B10_FLOAT is in a compression class of its own and868* there is no way to copy to/from it which doesn't potentially loose data869* if one of the bit patterns being copied isn't valid finite floats.870*/871if (format == ISL_FORMAT_R11G11B10_FLOAT)872return false;873874return devinfo->verx10 >= format_info[format].ccs_e;875}876877bool878isl_format_supports_multisampling(const struct intel_device_info *devinfo,879enum isl_format format)880{881/* From the Sandybridge PRM, Volume 4 Part 1 p72, SURFACE_STATE, Surface882* Format:883*884* If Number of Multisamples is set to a value other than885* MULTISAMPLECOUNT_1, this field cannot be set to the following886* formats:887*888* - any format with greater than 64 bits per element889* - any compressed texture format (BC*)890* - any YCRCB* format891*892* The restriction on the format's size is removed on Broadwell. Moreover,893* empirically it looks that even IvyBridge can handle multisampled surfaces894* with format sizes all the way to 128-bits (RGBA32F, RGBA32I, RGBA32UI).895*896* Also, there is an exception for HiZ which we treat as a compressed897* format and is allowed to be multisampled on Broadwell and earlier.898*/899if (format == ISL_FORMAT_HIZ) {900/* On SKL+, HiZ is always single-sampled even when the primary surface901* is multisampled. See also isl_surf_get_hiz_surf().902*/903return devinfo->ver <= 8;904} else if (devinfo->ver < 7 && isl_format_get_layout(format)->bpb > 64) {905return false;906} else if (isl_format_is_compressed(format)) {907return false;908} else if (isl_format_is_yuv(format)) {909return false;910} else {911return true;912}913}914915/**916* Returns true if the two formats are "CCS_E compatible" meaning that you can917* render in one format with CCS_E enabled and then texture using the other918* format without needing a resolve.919*920* Note: Even if the formats are compatible, special care must be taken if a921* clear color is involved because the encoding of the clear color is heavily922* format-dependent.923*/924bool925isl_formats_are_ccs_e_compatible(const struct intel_device_info *devinfo,926enum isl_format format1,927enum isl_format format2)928{929/* They must support CCS_E */930if (!isl_format_supports_ccs_e(devinfo, format1) ||931!isl_format_supports_ccs_e(devinfo, format2))932return false;933934/* Gfx12 added CCS_E support for A8_UNORM, A8_UNORM and R8_UNORM share the935* same aux map format encoding so they are definitely compatible.936*/937if (format1 == ISL_FORMAT_A8_UNORM)938format1 = ISL_FORMAT_R8_UNORM;939940if (format2 == ISL_FORMAT_A8_UNORM)941format2 = ISL_FORMAT_R8_UNORM;942943const struct isl_format_layout *fmtl1 = isl_format_get_layout(format1);944const struct isl_format_layout *fmtl2 = isl_format_get_layout(format2);945946/* The compression used by CCS is not dependent on the actual data encoding947* of the format but only depends on the bit-layout of the channels.948*/949return fmtl1->channels.r.bits == fmtl2->channels.r.bits &&950fmtl1->channels.g.bits == fmtl2->channels.g.bits &&951fmtl1->channels.b.bits == fmtl2->channels.b.bits &&952fmtl1->channels.a.bits == fmtl2->channels.a.bits;953}954955static bool956isl_format_has_channel_type(enum isl_format fmt, enum isl_base_type type)957{958const struct isl_format_layout *fmtl = isl_format_get_layout(fmt);959960return fmtl->channels.r.type == type ||961fmtl->channels.g.type == type ||962fmtl->channels.b.type == type ||963fmtl->channels.a.type == type ||964fmtl->channels.l.type == type ||965fmtl->channels.i.type == type ||966fmtl->channels.p.type == type;967}968969bool970isl_format_has_unorm_channel(enum isl_format fmt)971{972return isl_format_has_channel_type(fmt, ISL_UNORM);973}974975bool976isl_format_has_snorm_channel(enum isl_format fmt)977{978return isl_format_has_channel_type(fmt, ISL_SNORM);979}980981bool982isl_format_has_ufloat_channel(enum isl_format fmt)983{984return isl_format_has_channel_type(fmt, ISL_UFLOAT);985}986987bool988isl_format_has_sfloat_channel(enum isl_format fmt)989{990return isl_format_has_channel_type(fmt, ISL_SFLOAT);991}992993bool994isl_format_has_uint_channel(enum isl_format fmt)995{996return isl_format_has_channel_type(fmt, ISL_UINT);997}998999bool1000isl_format_has_sint_channel(enum isl_format fmt)1001{1002return isl_format_has_channel_type(fmt, ISL_SINT);1003}10041005bool1006isl_format_has_color_component(enum isl_format fmt, int component)1007{1008const struct isl_format_layout *fmtl = isl_format_get_layout(fmt);1009const uint8_t intensity = fmtl->channels.i.bits;1010const uint8_t luminance = fmtl->channels.l.bits;10111012switch (component) {1013case 0:1014return (fmtl->channels.r.bits + intensity + luminance) > 0;1015case 1:1016return (fmtl->channels.g.bits + intensity + luminance) > 0;1017case 2:1018return (fmtl->channels.b.bits + intensity + luminance) > 0;1019case 3:1020return (fmtl->channels.a.bits + intensity) > 0;1021default:1022assert(!"Invalid color component: must be 0..3");1023return false;1024}1025}10261027unsigned1028isl_format_get_num_channels(enum isl_format fmt)1029{1030const struct isl_format_layout *fmtl = isl_format_get_layout(fmt);10311032assert(fmtl->channels.p.bits == 0);10331034return (fmtl->channels.r.bits > 0) +1035(fmtl->channels.g.bits > 0) +1036(fmtl->channels.b.bits > 0) +1037(fmtl->channels.a.bits > 0) +1038(fmtl->channels.l.bits > 0) +1039(fmtl->channels.i.bits > 0);1040}10411042uint32_t1043isl_format_get_depth_format(enum isl_format fmt, bool has_stencil)1044{1045switch (fmt) {1046default:1047unreachable("bad isl depth format");1048case ISL_FORMAT_R32_FLOAT_X8X24_TYPELESS:1049assert(has_stencil);1050return 0; /* D32_FLOAT_S8X24_UINT */1051case ISL_FORMAT_R32_FLOAT:1052assert(!has_stencil);1053return 1; /* D32_FLOAT */1054case ISL_FORMAT_R24_UNORM_X8_TYPELESS:1055if (has_stencil) {1056return 2; /* D24_UNORM_S8_UINT */1057} else {1058return 3; /* D24_UNORM_X8_UINT */1059}1060case ISL_FORMAT_R16_UNORM:1061assert(!has_stencil);1062return 5; /* D16_UNORM */1063}1064}10651066enum isl_format1067isl_format_rgb_to_rgba(enum isl_format rgb)1068{1069assert(isl_format_is_rgb(rgb));10701071switch (rgb) {1072case ISL_FORMAT_R32G32B32_FLOAT: return ISL_FORMAT_R32G32B32A32_FLOAT;1073case ISL_FORMAT_R32G32B32_SINT: return ISL_FORMAT_R32G32B32A32_SINT;1074case ISL_FORMAT_R32G32B32_UINT: return ISL_FORMAT_R32G32B32A32_UINT;1075case ISL_FORMAT_R32G32B32_UNORM: return ISL_FORMAT_R32G32B32A32_UNORM;1076case ISL_FORMAT_R32G32B32_SNORM: return ISL_FORMAT_R32G32B32A32_SNORM;1077case ISL_FORMAT_R32G32B32_SSCALED: return ISL_FORMAT_R32G32B32A32_SSCALED;1078case ISL_FORMAT_R32G32B32_USCALED: return ISL_FORMAT_R32G32B32A32_USCALED;1079case ISL_FORMAT_R32G32B32_SFIXED: return ISL_FORMAT_R32G32B32A32_SFIXED;1080case ISL_FORMAT_R8G8B8_UNORM: return ISL_FORMAT_R8G8B8A8_UNORM;1081case ISL_FORMAT_R8G8B8_SNORM: return ISL_FORMAT_R8G8B8A8_SNORM;1082case ISL_FORMAT_R8G8B8_SSCALED: return ISL_FORMAT_R8G8B8A8_SSCALED;1083case ISL_FORMAT_R8G8B8_USCALED: return ISL_FORMAT_R8G8B8A8_USCALED;1084case ISL_FORMAT_R16G16B16_FLOAT: return ISL_FORMAT_R16G16B16A16_FLOAT;1085case ISL_FORMAT_R16G16B16_UNORM: return ISL_FORMAT_R16G16B16A16_UNORM;1086case ISL_FORMAT_R16G16B16_SNORM: return ISL_FORMAT_R16G16B16A16_SNORM;1087case ISL_FORMAT_R16G16B16_SSCALED: return ISL_FORMAT_R16G16B16A16_SSCALED;1088case ISL_FORMAT_R16G16B16_USCALED: return ISL_FORMAT_R16G16B16A16_USCALED;1089case ISL_FORMAT_R8G8B8_UNORM_SRGB: return ISL_FORMAT_R8G8B8A8_UNORM_SRGB;1090case ISL_FORMAT_R16G16B16_UINT: return ISL_FORMAT_R16G16B16A16_UINT;1091case ISL_FORMAT_R16G16B16_SINT: return ISL_FORMAT_R16G16B16A16_SINT;1092case ISL_FORMAT_R8G8B8_UINT: return ISL_FORMAT_R8G8B8A8_UINT;1093case ISL_FORMAT_R8G8B8_SINT: return ISL_FORMAT_R8G8B8A8_SINT;1094default:1095return ISL_FORMAT_UNSUPPORTED;1096}1097}10981099enum isl_format1100isl_format_rgb_to_rgbx(enum isl_format rgb)1101{1102assert(isl_format_is_rgb(rgb));11031104switch (rgb) {1105case ISL_FORMAT_R32G32B32_FLOAT:1106return ISL_FORMAT_R32G32B32X32_FLOAT;1107case ISL_FORMAT_R16G16B16_UNORM:1108return ISL_FORMAT_R16G16B16X16_UNORM;1109case ISL_FORMAT_R16G16B16_FLOAT:1110return ISL_FORMAT_R16G16B16X16_FLOAT;1111case ISL_FORMAT_R8G8B8_UNORM:1112return ISL_FORMAT_R8G8B8X8_UNORM;1113case ISL_FORMAT_R8G8B8_UNORM_SRGB:1114return ISL_FORMAT_R8G8B8X8_UNORM_SRGB;1115default:1116return ISL_FORMAT_UNSUPPORTED;1117}1118}11191120enum isl_format1121isl_format_rgbx_to_rgba(enum isl_format rgbx)1122{1123assert(isl_format_is_rgbx(rgbx));11241125switch (rgbx) {1126case ISL_FORMAT_R32G32B32X32_FLOAT:1127return ISL_FORMAT_R32G32B32A32_FLOAT;1128case ISL_FORMAT_R16G16B16X16_UNORM:1129return ISL_FORMAT_R16G16B16A16_UNORM;1130case ISL_FORMAT_R16G16B16X16_FLOAT:1131return ISL_FORMAT_R16G16B16A16_FLOAT;1132case ISL_FORMAT_B8G8R8X8_UNORM:1133return ISL_FORMAT_B8G8R8A8_UNORM;1134case ISL_FORMAT_B8G8R8X8_UNORM_SRGB:1135return ISL_FORMAT_B8G8R8A8_UNORM_SRGB;1136case ISL_FORMAT_R8G8B8X8_UNORM:1137return ISL_FORMAT_R8G8B8A8_UNORM;1138case ISL_FORMAT_R8G8B8X8_UNORM_SRGB:1139return ISL_FORMAT_R8G8B8A8_UNORM_SRGB;1140case ISL_FORMAT_B10G10R10X2_UNORM:1141return ISL_FORMAT_B10G10R10A2_UNORM;1142case ISL_FORMAT_B5G5R5X1_UNORM:1143return ISL_FORMAT_B5G5R5A1_UNORM;1144case ISL_FORMAT_B5G5R5X1_UNORM_SRGB:1145return ISL_FORMAT_B5G5R5A1_UNORM_SRGB;1146default:1147assert(!"Invalid RGBX format");1148return rgbx;1149}1150}11511152static inline void1153pack_channel(const union isl_color_value *value, unsigned i,1154const struct isl_channel_layout *layout,1155enum isl_colorspace colorspace,1156uint32_t data_out[4])1157{1158if (layout->type == ISL_VOID)1159return;11601161if (colorspace == ISL_COLORSPACE_SRGB)1162assert(layout->type == ISL_UNORM);11631164uint32_t packed;1165switch (layout->type) {1166case ISL_UNORM:1167if (colorspace == ISL_COLORSPACE_SRGB) {1168if (layout->bits == 8) {1169packed = util_format_linear_float_to_srgb_8unorm(value->f32[i]);1170} else {1171float srgb = util_format_linear_to_srgb_float(value->f32[i]);1172packed = _mesa_float_to_unorm(srgb, layout->bits);1173}1174} else {1175packed = _mesa_float_to_unorm(value->f32[i], layout->bits);1176}1177break;1178case ISL_SNORM:1179packed = _mesa_float_to_snorm(value->f32[i], layout->bits);1180break;1181case ISL_SFLOAT:1182assert(layout->bits == 16 || layout->bits == 32);1183if (layout->bits == 16) {1184packed = _mesa_float_to_half(value->f32[i]);1185} else {1186packed = value->u32[i];1187}1188break;1189case ISL_UINT:1190packed = MIN(value->u32[i], MAX_UINT(layout->bits));1191break;1192case ISL_SINT:1193packed = MIN(MAX(value->u32[i], MIN_INT(layout->bits)),1194MAX_INT(layout->bits));1195break;11961197default:1198unreachable("Invalid channel type");1199}12001201unsigned dword = layout->start_bit / 32;1202unsigned bit = layout->start_bit % 32;1203assert(bit + layout->bits <= 32);1204data_out[dword] |= (packed & MAX_UINT(layout->bits)) << bit;1205}12061207/**1208* Take an isl_color_value and pack it into the actual bits as specified by1209* the isl_format. This function is very slow for a format conversion1210* function but should be fine for a single pixel worth of data.1211*/1212void1213isl_color_value_pack(const union isl_color_value *value,1214enum isl_format format,1215uint32_t *data_out)1216{1217const struct isl_format_layout *fmtl = isl_format_get_layout(format);1218assert(fmtl->colorspace == ISL_COLORSPACE_LINEAR ||1219fmtl->colorspace == ISL_COLORSPACE_SRGB);1220assert(!isl_format_is_compressed(format));12211222memset(data_out, 0, isl_align(fmtl->bpb, 32) / 8);12231224if (format == ISL_FORMAT_R9G9B9E5_SHAREDEXP) {1225data_out[0] = float3_to_rgb9e5(value->f32);1226return;1227} else if (format == ISL_FORMAT_R11G11B10_FLOAT) {1228data_out[0] = float3_to_r11g11b10f(value->f32);1229return;1230}12311232pack_channel(value, 0, &fmtl->channels.r, fmtl->colorspace, data_out);1233pack_channel(value, 1, &fmtl->channels.g, fmtl->colorspace, data_out);1234pack_channel(value, 2, &fmtl->channels.b, fmtl->colorspace, data_out);1235pack_channel(value, 3, &fmtl->channels.a, ISL_COLORSPACE_LINEAR, data_out);1236pack_channel(value, 0, &fmtl->channels.l, fmtl->colorspace, data_out);1237pack_channel(value, 0, &fmtl->channels.i, ISL_COLORSPACE_LINEAR, data_out);1238assert(fmtl->channels.p.bits == 0);1239}12401241/** Extend an N-bit signed integer to 32 bits */1242static inline int32_t1243sign_extend(int32_t x, unsigned bits)1244{1245if (bits < 32) {1246unsigned shift = 32 - bits;1247return (x << shift) >> shift;1248} else {1249return x;1250}1251}12521253static inline void1254unpack_channel(union isl_color_value *value,1255unsigned start, unsigned count,1256const struct isl_channel_layout *layout,1257enum isl_colorspace colorspace,1258const uint32_t *data_in)1259{1260if (layout->type == ISL_VOID)1261return;12621263unsigned dword = layout->start_bit / 32;1264unsigned bit = layout->start_bit % 32;1265assert(bit + layout->bits <= 32);1266uint32_t packed = (data_in[dword] >> bit) & MAX_UINT(layout->bits);12671268union {1269uint32_t u32;1270float f32;1271} unpacked;12721273if (colorspace == ISL_COLORSPACE_SRGB)1274assert(layout->type == ISL_UNORM);12751276switch (layout->type) {1277case ISL_UNORM:1278if (colorspace == ISL_COLORSPACE_SRGB) {1279if (layout->bits == 8) {1280unpacked.f32 = util_format_srgb_8unorm_to_linear_float(packed);1281} else {1282float srgb = _mesa_unorm_to_float(packed, layout->bits);1283unpacked.f32 = util_format_srgb_to_linear_float(srgb);1284}1285} else {1286unpacked.f32 = _mesa_unorm_to_float(packed, layout->bits);1287}1288break;1289case ISL_SNORM:1290unpacked.f32 = _mesa_snorm_to_float(sign_extend(packed, layout->bits),1291layout->bits);1292break;1293case ISL_SFLOAT:1294assert(layout->bits == 16 || layout->bits == 32);1295if (layout->bits == 16) {1296unpacked.f32 = _mesa_half_to_float(packed);1297} else {1298unpacked.u32 = packed;1299}1300break;1301case ISL_UINT:1302unpacked.u32 = packed;1303break;1304case ISL_SINT:1305unpacked.u32 = sign_extend(packed, layout->bits);1306break;13071308default:1309unreachable("Invalid channel type");1310}13111312for (unsigned i = 0; i < count; i++)1313value->u32[start + i] = unpacked.u32;1314}13151316/**1317* Take unpack an isl_color_value from the actual bits as specified by1318* the isl_format. This function is very slow for a format conversion1319* function but should be fine for a single pixel worth of data.1320*/1321void1322isl_color_value_unpack(union isl_color_value *value,1323enum isl_format format,1324const uint32_t *data_in)1325{1326const struct isl_format_layout *fmtl = isl_format_get_layout(format);1327assert(fmtl->colorspace == ISL_COLORSPACE_LINEAR ||1328fmtl->colorspace == ISL_COLORSPACE_SRGB);1329assert(!isl_format_is_compressed(format));13301331/* Default to opaque black. */1332memset(value, 0, sizeof(*value));1333if (isl_format_has_int_channel(format)) {1334value->u32[3] = 1u;1335} else {1336value->f32[3] = 1.0f;1337}13381339if (format == ISL_FORMAT_R9G9B9E5_SHAREDEXP) {1340rgb9e5_to_float3(data_in[0], value->f32);1341return;1342} else if (format == ISL_FORMAT_R11G11B10_FLOAT) {1343r11g11b10f_to_float3(data_in[0], value->f32);1344return;1345}13461347unpack_channel(value, 0, 1, &fmtl->channels.r, fmtl->colorspace, data_in);1348unpack_channel(value, 1, 1, &fmtl->channels.g, fmtl->colorspace, data_in);1349unpack_channel(value, 2, 1, &fmtl->channels.b, fmtl->colorspace, data_in);1350unpack_channel(value, 3, 1, &fmtl->channels.a, ISL_COLORSPACE_LINEAR, data_in);1351unpack_channel(value, 0, 3, &fmtl->channels.l, fmtl->colorspace, data_in);1352unpack_channel(value, 0, 4, &fmtl->channels.i, ISL_COLORSPACE_LINEAR, data_in);1353assert(fmtl->channels.p.bits == 0);1354}135513561357