Path: blob/21.2-virgl/src/gallium/drivers/svga/include/svga3d_surfacedefs.h
4574 views
/**************************************************************************1*2* Copyright © 1998-2015 VMware, Inc., Palo Alto, CA., USA3* All Rights Reserved.4*5* Permission is hereby granted, free of charge, to any person obtaining a6* copy of this software and associated documentation files (the7* "Software"), to deal in the Software without restriction, including8* without limitation the rights to use, copy, modify, merge, publish,9* distribute, sub license, and/or sell copies of the Software, and to10* permit persons to whom the Software is furnished to do so, subject to11* the following conditions:12*13* The above copyright notice and this permission notice (including the14* next paragraph) shall be included in all copies or substantial portions15* of the Software.16*17* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR18* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,19* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL20* THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,21* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR22* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE23* USE OR OTHER DEALINGS IN THE SOFTWARE.24*25**************************************************************************/2627/*28* svga3d_surfacedefs.h --29*30* Surface/format/image helper code.31*/3233#ifndef SVGA3D_SURFACEDEFS_H34#define SVGA3D_SURFACEDEFS_H3536#include "svga3d_reg.h"3738#define max_t(type, x, y) ((x) > (y) ? (x) : (y))3940/*41* enum svga3d_block_desc describes the active data channels in a block.42*43* There can be at-most four active channels in a block:44* 1. Red, bump W, luminance and depth are stored in the first channel.45* 2. Green, bump V and stencil are stored in the second channel.46* 3. Blue and bump U are stored in the third channel.47* 4. Alpha and bump Q are stored in the fourth channel.48*49* Block channels can be used to store compressed and buffer data:50* 1. For compressed formats, only the data channel is used and its size51* is equal to that of a singular block in the compression scheme.52* 2. For buffer formats, only the data channel is used and its size is53* exactly one byte in length.54* 3. In each case the bit depth represent the size of a singular block.55*56* Note: Compressed and IEEE formats do not use the bitMask structure.57*/5859enum svga3d_block_desc {6061SVGA3DBLOCKDESC_NONE = 0, /* No channels are active */62SVGA3DBLOCKDESC_BLUE = 1 << 0, /* Block with red channel data */63SVGA3DBLOCKDESC_U = 1 << 0, /* Block with bump U channel data */64SVGA3DBLOCKDESC_GREEN = 1 << 1, /* Block with green channel data */65SVGA3DBLOCKDESC_V = 1 << 1, /* Block with bump V channel data */66SVGA3DBLOCKDESC_RED = 1 << 2, /* Block with blue channel data */67SVGA3DBLOCKDESC_W = 1 << 2, /* Block with bump W channel data */68SVGA3DBLOCKDESC_LUMINANCE = 1 << 2, /* Block with luminance channel data */69SVGA3DBLOCKDESC_Y = 1 << 2, /* Block with video luminance data */70SVGA3DBLOCKDESC_ALPHA = 1 << 3, /* Block with an alpha channel */71SVGA3DBLOCKDESC_Q = 1 << 3, /* Block with bump Q channel data */72SVGA3DBLOCKDESC_BUFFER = 1 << 4, /* Block stores 1 byte of data */73SVGA3DBLOCKDESC_COMPRESSED = 1 << 5, /* Block stores n bytes of data depending74on the compression method used */75SVGA3DBLOCKDESC_IEEE_FP = 1 << 6, /* Block stores data in an IEEE floating point76representation in all channels */77SVGA3DBLOCKDESC_UV_VIDEO = 1 << 7, /* Block with alternating video U and V */78SVGA3DBLOCKDESC_PLANAR_YUV = 1 << 8, /* Three separate blocks store data. */79SVGA3DBLOCKDESC_U_VIDEO = 1 << 9, /* Block with U video data */80SVGA3DBLOCKDESC_V_VIDEO = 1 << 10, /* Block with V video data */81SVGA3DBLOCKDESC_EXP = 1 << 11, /* Shared exponent */82SVGA3DBLOCKDESC_SRGB = 1 << 12, /* Data is in sRGB format */83SVGA3DBLOCKDESC_2PLANAR_YUV = 1 << 13, /* 2 planes of Y, UV, e.g., NV12. */84SVGA3DBLOCKDESC_3PLANAR_YUV = 1 << 14, /* 3 planes of separate Y, U, V, e.g., YV12. */85SVGA3DBLOCKDESC_DEPTH = 1 << 15, /* Block with depth channel */86SVGA3DBLOCKDESC_STENCIL = 1 << 16, /* Block with a stencil channel */8788SVGA3DBLOCKDESC_RG = SVGA3DBLOCKDESC_RED |89SVGA3DBLOCKDESC_GREEN,90SVGA3DBLOCKDESC_RGB = SVGA3DBLOCKDESC_RG |91SVGA3DBLOCKDESC_BLUE,92SVGA3DBLOCKDESC_RGB_SRGB = SVGA3DBLOCKDESC_RGB |93SVGA3DBLOCKDESC_SRGB,94SVGA3DBLOCKDESC_RGBA = SVGA3DBLOCKDESC_RGB |95SVGA3DBLOCKDESC_ALPHA,96SVGA3DBLOCKDESC_RGBA_SRGB = SVGA3DBLOCKDESC_RGBA |97SVGA3DBLOCKDESC_SRGB,98SVGA3DBLOCKDESC_UV = SVGA3DBLOCKDESC_U |99SVGA3DBLOCKDESC_V,100SVGA3DBLOCKDESC_UVL = SVGA3DBLOCKDESC_UV |101SVGA3DBLOCKDESC_LUMINANCE,102SVGA3DBLOCKDESC_UVW = SVGA3DBLOCKDESC_UV |103SVGA3DBLOCKDESC_W,104SVGA3DBLOCKDESC_UVWA = SVGA3DBLOCKDESC_UVW |105SVGA3DBLOCKDESC_ALPHA,106SVGA3DBLOCKDESC_UVWQ = SVGA3DBLOCKDESC_U |107SVGA3DBLOCKDESC_V |108SVGA3DBLOCKDESC_W |109SVGA3DBLOCKDESC_Q,110SVGA3DBLOCKDESC_LA = SVGA3DBLOCKDESC_LUMINANCE |111SVGA3DBLOCKDESC_ALPHA,112SVGA3DBLOCKDESC_R_FP = SVGA3DBLOCKDESC_RED |113SVGA3DBLOCKDESC_IEEE_FP,114SVGA3DBLOCKDESC_RG_FP = SVGA3DBLOCKDESC_R_FP |115SVGA3DBLOCKDESC_GREEN,116SVGA3DBLOCKDESC_RGB_FP = SVGA3DBLOCKDESC_RG_FP |117SVGA3DBLOCKDESC_BLUE,118SVGA3DBLOCKDESC_RGBA_FP = SVGA3DBLOCKDESC_RGB_FP |119SVGA3DBLOCKDESC_ALPHA,120SVGA3DBLOCKDESC_DS = SVGA3DBLOCKDESC_DEPTH |121SVGA3DBLOCKDESC_STENCIL,122SVGA3DBLOCKDESC_YUV = SVGA3DBLOCKDESC_UV_VIDEO |123SVGA3DBLOCKDESC_Y,124SVGA3DBLOCKDESC_AYUV = SVGA3DBLOCKDESC_ALPHA |125SVGA3DBLOCKDESC_Y |126SVGA3DBLOCKDESC_U_VIDEO |127SVGA3DBLOCKDESC_V_VIDEO,128SVGA3DBLOCKDESC_RGBE = SVGA3DBLOCKDESC_RGB |129SVGA3DBLOCKDESC_EXP,130SVGA3DBLOCKDESC_COMPRESSED_SRGB = SVGA3DBLOCKDESC_COMPRESSED |131SVGA3DBLOCKDESC_SRGB,132SVGA3DBLOCKDESC_NV12 = SVGA3DBLOCKDESC_PLANAR_YUV |133SVGA3DBLOCKDESC_2PLANAR_YUV,134SVGA3DBLOCKDESC_YV12 = SVGA3DBLOCKDESC_PLANAR_YUV |135SVGA3DBLOCKDESC_3PLANAR_YUV,136};137138139typedef struct SVGA3dChannelDef {140union {141uint8 blue;142uint8 u;143uint8 uv_video;144uint8 u_video;145};146union {147uint8 green;148uint8 v;149uint8 stencil;150uint8 v_video;151};152union {153uint8 red;154uint8 w;155uint8 luminance;156uint8 y;157uint8 depth;158uint8 data;159};160union {161uint8 alpha;162uint8 q;163uint8 exp;164};165} SVGA3dChannelDef;166167struct svga3d_surface_desc {168SVGA3dSurfaceFormat format;169enum svga3d_block_desc block_desc;170171SVGA3dSize block_size;172uint32 bytes_per_block;173uint32 pitch_bytes_per_block;174175uint32 totalBitDepth;176SVGA3dChannelDef bitDepth;177SVGA3dChannelDef bitOffset;178};179180static const struct svga3d_surface_desc svga3d_surface_descs[] = {181{SVGA3D_FORMAT_INVALID, SVGA3DBLOCKDESC_NONE,182{1, 1, 1}, 0, 0,1830, {{0}, {0}, {0}, {0}},184{{0}, {0}, {0}, {0}}},185186{SVGA3D_X8R8G8B8, SVGA3DBLOCKDESC_RGB,187{1, 1, 1}, 4, 4,18824, {{8}, {8}, {8}, {0}},189{{0}, {8}, {16}, {24}}},190191{SVGA3D_A8R8G8B8, SVGA3DBLOCKDESC_RGBA,192{1, 1, 1}, 4, 4,19332, {{8}, {8}, {8}, {8}},194{{0}, {8}, {16}, {24}}},195196{SVGA3D_R5G6B5, SVGA3DBLOCKDESC_RGB,197{1, 1, 1}, 2, 2,19816, {{5}, {6}, {5}, {0}},199{{0}, {5}, {11}, {0}}},200201{SVGA3D_X1R5G5B5, SVGA3DBLOCKDESC_RGB,202{1, 1, 1}, 2, 2,20315, {{5}, {5}, {5}, {0}},204{{0}, {5}, {10}, {0}}},205206{SVGA3D_A1R5G5B5, SVGA3DBLOCKDESC_RGBA,207{1, 1, 1}, 2, 2,20816, {{5}, {5}, {5}, {1}},209{{0}, {5}, {10}, {15}}},210211{SVGA3D_A4R4G4B4, SVGA3DBLOCKDESC_RGBA,212{1, 1, 1}, 2, 2,21316, {{4}, {4}, {4}, {4}},214{{0}, {4}, {8}, {12}}},215216{SVGA3D_Z_D32, SVGA3DBLOCKDESC_DEPTH,217{1, 1, 1}, 4, 4,21832, {{0}, {0}, {32}, {0}},219{{0}, {0}, {0}, {0}}},220221{SVGA3D_Z_D16, SVGA3DBLOCKDESC_DEPTH,222{1, 1, 1}, 2, 2,22316, {{0}, {0}, {16}, {0}},224{{0}, {0}, {0}, {0}}},225226{SVGA3D_Z_D24S8, SVGA3DBLOCKDESC_DS,227{1, 1, 1}, 4, 4,22832, {{0}, {8}, {24}, {0}},229{{0}, {24}, {0}, {0}}},230231{SVGA3D_Z_D15S1, SVGA3DBLOCKDESC_DS,232{1, 1, 1}, 2, 2,23316, {{0}, {1}, {15}, {0}},234{{0}, {15}, {0}, {0}}},235236{SVGA3D_LUMINANCE8, SVGA3DBLOCKDESC_LUMINANCE,237{1, 1, 1}, 1, 1,2388, {{0}, {0}, {8}, {0}},239{{0}, {0}, {0}, {0}}},240241{SVGA3D_LUMINANCE4_ALPHA4, SVGA3DBLOCKDESC_LA,242{1 , 1, 1}, 1, 1,2438, {{0}, {0}, {4}, {4}},244{{0}, {0}, {0}, {4}}},245246{SVGA3D_LUMINANCE16, SVGA3DBLOCKDESC_LUMINANCE,247{1, 1, 1}, 2, 2,24816, {{0}, {0}, {16}, {0}},249{{0}, {0}, {0}, {0}}},250251{SVGA3D_LUMINANCE8_ALPHA8, SVGA3DBLOCKDESC_LA,252{1, 1, 1}, 2, 2,25316, {{0}, {0}, {8}, {8}},254{{0}, {0}, {0}, {8}}},255256{SVGA3D_DXT1, SVGA3DBLOCKDESC_COMPRESSED,257{4, 4, 1}, 8, 8,25864, {{0}, {0}, {64}, {0}},259{{0}, {0}, {0}, {0}}},260261{SVGA3D_DXT2, SVGA3DBLOCKDESC_COMPRESSED,262{4, 4, 1}, 16, 16,263128, {{0}, {0}, {128}, {0}},264{{0}, {0}, {0}, {0}}},265266{SVGA3D_DXT3, SVGA3DBLOCKDESC_COMPRESSED,267{4, 4, 1}, 16, 16,268128, {{0}, {0}, {128}, {0}},269{{0}, {0}, {0}, {0}}},270271{SVGA3D_DXT4, SVGA3DBLOCKDESC_COMPRESSED,272{4, 4, 1}, 16, 16,273128, {{0}, {0}, {128}, {0}},274{{0}, {0}, {0}, {0}}},275276{SVGA3D_DXT5, SVGA3DBLOCKDESC_COMPRESSED,277{4, 4, 1}, 16, 16,278128, {{0}, {0}, {128}, {0}},279{{0}, {0}, {0}, {0}}},280281{SVGA3D_BUMPU8V8, SVGA3DBLOCKDESC_UV,282{1, 1, 1}, 2, 2,28316, {{0}, {0}, {8}, {8}},284{{0}, {0}, {0}, {8}}},285286{SVGA3D_BUMPL6V5U5, SVGA3DBLOCKDESC_UVL,287{1, 1, 1}, 2, 2,28816, {{5}, {5}, {6}, {0}},289{{11}, {6}, {0}, {0}}},290291{SVGA3D_BUMPX8L8V8U8, SVGA3DBLOCKDESC_UVL,292{1, 1, 1}, 4, 4,29332, {{8}, {8}, {8}, {0}},294{{16}, {8}, {0}, {0}}},295296{SVGA3D_FORMAT_DEAD1, SVGA3DBLOCKDESC_UVL,297{0, 0, 0}, 0, 0,2980, {{0}, {0}, {0}, {0}},299{{0}, {0}, {0}, {0}}},300301{SVGA3D_ARGB_S10E5, SVGA3DBLOCKDESC_RGBA_FP,302{1, 1, 1}, 8, 8,30364, {{16}, {16}, {16}, {16}},304{{32}, {16}, {0}, {48}}},305306{SVGA3D_ARGB_S23E8, SVGA3DBLOCKDESC_RGBA_FP,307{1, 1, 1}, 16, 16,308128, {{32}, {32}, {32}, {32}},309{{64}, {32}, {0}, {96}}},310311{SVGA3D_A2R10G10B10, SVGA3DBLOCKDESC_RGBA,312{1, 1, 1}, 4, 4,31332, {{10}, {10}, {10}, {2}},314{{0}, {10}, {20}, {30}}},315316{SVGA3D_V8U8, SVGA3DBLOCKDESC_UV,317{1, 1, 1}, 2, 2,31816, {{8}, {8}, {0}, {0}},319{{8}, {0}, {0}, {0}}},320321{SVGA3D_Q8W8V8U8, SVGA3DBLOCKDESC_UVWQ,322{1, 1, 1}, 4, 4,32332, {{8}, {8}, {8}, {8}},324{{24}, {16}, {8}, {0}}},325326{SVGA3D_CxV8U8, SVGA3DBLOCKDESC_UV,327{1, 1, 1}, 2, 2,32816, {{8}, {8}, {0}, {0}},329{{8}, {0}, {0}, {0}}},330331{SVGA3D_X8L8V8U8, SVGA3DBLOCKDESC_UVL,332{1, 1, 1}, 4, 4,33324, {{8}, {8}, {8}, {0}},334{{16}, {8}, {0}, {0}}},335336{SVGA3D_A2W10V10U10, SVGA3DBLOCKDESC_UVWA,337{1, 1, 1}, 4, 4,33832, {{10}, {10}, {10}, {2}},339{{0}, {10}, {20}, {30}}},340341{SVGA3D_ALPHA8, SVGA3DBLOCKDESC_ALPHA,342{1, 1, 1}, 1, 1,3438, {{0}, {0}, {0}, {8}},344{{0}, {0}, {0}, {0}}},345346{SVGA3D_R_S10E5, SVGA3DBLOCKDESC_R_FP,347{1, 1, 1}, 2, 2,34816, {{0}, {0}, {16}, {0}},349{{0}, {0}, {0}, {0}}},350351{SVGA3D_R_S23E8, SVGA3DBLOCKDESC_R_FP,352{1, 1, 1}, 4, 4,35332, {{0}, {0}, {32}, {0}},354{{0}, {0}, {0}, {0}}},355356{SVGA3D_RG_S10E5, SVGA3DBLOCKDESC_RG_FP,357{1, 1, 1}, 4, 4,35832, {{0}, {16}, {16}, {0}},359{{0}, {16}, {0}, {0}}},360361{SVGA3D_RG_S23E8, SVGA3DBLOCKDESC_RG_FP,362{1, 1, 1}, 8, 8,36364, {{0}, {32}, {32}, {0}},364{{0}, {32}, {0}, {0}}},365366{SVGA3D_BUFFER, SVGA3DBLOCKDESC_BUFFER,367{1, 1, 1}, 1, 1,3688, {{0}, {0}, {8}, {0}},369{{0}, {0}, {0}, {0}}},370371{SVGA3D_Z_D24X8, SVGA3DBLOCKDESC_DEPTH,372{1, 1, 1}, 4, 4,37332, {{0}, {0}, {24}, {0}},374{{0}, {24}, {0}, {0}}},375376{SVGA3D_V16U16, SVGA3DBLOCKDESC_UV,377{1, 1, 1}, 4, 4,37832, {{16}, {16}, {0}, {0}},379{{16}, {0}, {0}, {0}}},380381{SVGA3D_G16R16, SVGA3DBLOCKDESC_RG,382{1, 1, 1}, 4, 4,38332, {{0}, {16}, {16}, {0}},384{{0}, {0}, {16}, {0}}},385386{SVGA3D_A16B16G16R16, SVGA3DBLOCKDESC_RGBA,387{1, 1, 1}, 8, 8,38864, {{16}, {16}, {16}, {16}},389{{32}, {16}, {0}, {48}}},390391{SVGA3D_UYVY, SVGA3DBLOCKDESC_YUV,392{1, 1, 1}, 2, 2,39316, {{8}, {0}, {8}, {0}},394{{0}, {0}, {8}, {0}}},395396{SVGA3D_YUY2, SVGA3DBLOCKDESC_YUV,397{1, 1, 1}, 2, 2,39816, {{8}, {0}, {8}, {0}},399{{8}, {0}, {0}, {0}}},400401{SVGA3D_NV12, SVGA3DBLOCKDESC_NV12,402{2, 2, 1}, 6, 2,40348, {{0}, {0}, {48}, {0}},404{{0}, {0}, {0}, {0}}},405406{SVGA3D_AYUV, SVGA3DBLOCKDESC_AYUV,407{1, 1, 1}, 4, 4,40832, {{8}, {8}, {8}, {8}},409{{0}, {8}, {16}, {24}}},410411{SVGA3D_R32G32B32A32_TYPELESS, SVGA3DBLOCKDESC_RGBA,412{1, 1, 1}, 16, 16,413128, {{32}, {32}, {32}, {32}},414{{64}, {32}, {0}, {96}}},415416{SVGA3D_R32G32B32A32_UINT, SVGA3DBLOCKDESC_RGBA,417{1, 1, 1}, 16, 16,418128, {{32}, {32}, {32}, {32}},419{{64}, {32}, {0}, {96}}},420421{SVGA3D_R32G32B32A32_SINT, SVGA3DBLOCKDESC_UVWQ,422{1, 1, 1}, 16, 16,423128, {{32}, {32}, {32}, {32}},424{{64}, {32}, {0}, {96}}},425426{SVGA3D_R32G32B32_TYPELESS, SVGA3DBLOCKDESC_RGB,427{1, 1, 1}, 12, 12,42896, {{32}, {32}, {32}, {0}},429{{64}, {32}, {0}, {0}}},430431{SVGA3D_R32G32B32_FLOAT, SVGA3DBLOCKDESC_RGB_FP,432{1, 1, 1}, 12, 12,43396, {{32}, {32}, {32}, {0}},434{{64}, {32}, {0}, {0}}},435436{SVGA3D_R32G32B32_UINT, SVGA3DBLOCKDESC_RGB,437{1, 1, 1}, 12, 12,43896, {{32}, {32}, {32}, {0}},439{{64}, {32}, {0}, {0}}},440441{SVGA3D_R32G32B32_SINT, SVGA3DBLOCKDESC_UVW,442{1, 1, 1}, 12, 12,44396, {{32}, {32}, {32}, {0}},444{{64}, {32}, {0}, {0}}},445446{SVGA3D_R16G16B16A16_TYPELESS, SVGA3DBLOCKDESC_RGBA,447{1, 1, 1}, 8, 8,44864, {{16}, {16}, {16}, {16}},449{{32}, {16}, {0}, {48}}},450451{SVGA3D_R16G16B16A16_UINT, SVGA3DBLOCKDESC_RGBA,452{1, 1, 1}, 8, 8,45364, {{16}, {16}, {16}, {16}},454{{32}, {16}, {0}, {48}}},455456{SVGA3D_R16G16B16A16_SNORM, SVGA3DBLOCKDESC_UVWQ,457{1, 1, 1}, 8, 8,45864, {{16}, {16}, {16}, {16}},459{{32}, {16}, {0}, {48}}},460461{SVGA3D_R16G16B16A16_SINT, SVGA3DBLOCKDESC_UVWQ,462{1, 1, 1}, 8, 8,46364, {{16}, {16}, {16}, {16}},464{{32}, {16}, {0}, {48}}},465466{SVGA3D_R32G32_TYPELESS, SVGA3DBLOCKDESC_RG,467{1, 1, 1}, 8, 8,46864, {{0}, {32}, {32}, {0}},469{{0}, {32}, {0}, {0}}},470471{SVGA3D_R32G32_UINT, SVGA3DBLOCKDESC_RG,472{1, 1, 1}, 8, 8,47364, {{0}, {32}, {32}, {0}},474{{0}, {32}, {0}, {0}}},475476{SVGA3D_R32G32_SINT, SVGA3DBLOCKDESC_UV,477{1, 1, 1}, 8, 8,47864, {{0}, {32}, {32}, {0}},479{{0}, {32}, {0}, {0}}},480481{SVGA3D_R32G8X24_TYPELESS, SVGA3DBLOCKDESC_RG,482{1, 1, 1}, 8, 8,48364, {{0}, {8}, {32}, {0}},484{{0}, {32}, {0}, {0}}},485486{SVGA3D_D32_FLOAT_S8X24_UINT, SVGA3DBLOCKDESC_DS,487{1, 1, 1}, 8, 8,48864, {{0}, {8}, {32}, {0}},489{{0}, {32}, {0}, {0}}},490491{SVGA3D_R32_FLOAT_X8X24, SVGA3DBLOCKDESC_R_FP,492{1, 1, 1}, 8, 8,49364, {{0}, {0}, {32}, {0}},494{{0}, {0}, {0}, {0}}},495496{SVGA3D_X32_G8X24_UINT, SVGA3DBLOCKDESC_GREEN,497{1, 1, 1}, 8, 8,49864, {{0}, {8}, {0}, {0}},499{{0}, {32}, {0}, {0}}},500501{SVGA3D_R10G10B10A2_TYPELESS, SVGA3DBLOCKDESC_RGBA,502{1, 1, 1}, 4, 4,50332, {{10}, {10}, {10}, {2}},504{{0}, {10}, {20}, {30}}},505506{SVGA3D_R10G10B10A2_UINT, SVGA3DBLOCKDESC_RGBA,507{1, 1, 1}, 4, 4,50832, {{10}, {10}, {10}, {2}},509{{0}, {10}, {20}, {30}}},510511{SVGA3D_R11G11B10_FLOAT, SVGA3DBLOCKDESC_RGB_FP,512{1, 1, 1}, 4, 4,51332, {{10}, {11}, {11}, {0}},514{{0}, {10}, {21}, {0}}},515516{SVGA3D_R8G8B8A8_TYPELESS, SVGA3DBLOCKDESC_RGBA,517{1, 1, 1}, 4, 4,51832, {{8}, {8}, {8}, {8}},519{{16}, {8}, {0}, {24}}},520521{SVGA3D_R8G8B8A8_UNORM, SVGA3DBLOCKDESC_RGBA,522{1, 1, 1}, 4, 4,52332, {{8}, {8}, {8}, {8}},524{{16}, {8}, {0}, {24}}},525526{SVGA3D_R8G8B8A8_UNORM_SRGB, SVGA3DBLOCKDESC_RGBA_SRGB,527{1, 1, 1}, 4, 4,52832, {{8}, {8}, {8}, {8}},529{{16}, {8}, {0}, {24}}},530531{SVGA3D_R8G8B8A8_UINT, SVGA3DBLOCKDESC_RGBA,532{1, 1, 1}, 4, 4,53332, {{8}, {8}, {8}, {8}},534{{16}, {8}, {0}, {24}}},535536{SVGA3D_R8G8B8A8_SINT, SVGA3DBLOCKDESC_RGBA,537{1, 1, 1}, 4, 4,53832, {{8}, {8}, {8}, {8}},539{{16}, {8}, {0}, {24}}},540541{SVGA3D_R16G16_TYPELESS, SVGA3DBLOCKDESC_RG,542{1, 1, 1}, 4, 4,54332, {{0}, {16}, {16}, {0}},544{{0}, {16}, {0}, {0}}},545546{SVGA3D_R16G16_UINT, SVGA3DBLOCKDESC_RG_FP,547{1, 1, 1}, 4, 4,54832, {{0}, {16}, {16}, {0}},549{{0}, {16}, {0}, {0}}},550551{SVGA3D_R16G16_SINT, SVGA3DBLOCKDESC_UV,552{1, 1, 1}, 4, 4,55332, {{0}, {16}, {16}, {0}},554{{0}, {16}, {0}, {0}}},555556{SVGA3D_R32_TYPELESS, SVGA3DBLOCKDESC_RED,557{1, 1, 1}, 4, 4,55832, {{0}, {0}, {32}, {0}},559{{0}, {0}, {0}, {0}}},560561{SVGA3D_D32_FLOAT, SVGA3DBLOCKDESC_DEPTH,562{1, 1, 1}, 4, 4,56332, {{0}, {0}, {32}, {0}},564{{0}, {0}, {0}, {0}}},565566{SVGA3D_R32_UINT, SVGA3DBLOCKDESC_RED,567{1, 1, 1}, 4, 4,56832, {{0}, {0}, {32}, {0}},569{{0}, {0}, {0}, {0}}},570571{SVGA3D_R32_SINT, SVGA3DBLOCKDESC_RED,572{1, 1, 1}, 4, 4,57332, {{0}, {0}, {32}, {0}},574{{0}, {0}, {0}, {0}}},575576{SVGA3D_R24G8_TYPELESS, SVGA3DBLOCKDESC_RG,577{1, 1, 1}, 4, 4,57832, {{0}, {8}, {24}, {0}},579{{0}, {24}, {0}, {0}}},580581{SVGA3D_D24_UNORM_S8_UINT, SVGA3DBLOCKDESC_DS,582{1, 1, 1}, 4, 4,58332, {{0}, {8}, {24}, {0}},584{{0}, {24}, {0}, {0}}},585586{SVGA3D_R24_UNORM_X8, SVGA3DBLOCKDESC_RED,587{1, 1, 1}, 4, 4,58832, {{0}, {0}, {24}, {0}},589{{0}, {0}, {0}, {0}}},590591{SVGA3D_X24_G8_UINT, SVGA3DBLOCKDESC_GREEN,592{1, 1, 1}, 4, 4,59332, {{0}, {8}, {0}, {0}},594{{0}, {24}, {0}, {0}}},595596{SVGA3D_R8G8_TYPELESS, SVGA3DBLOCKDESC_RG,597{1, 1, 1}, 2, 2,59816, {{0}, {8}, {8}, {0}},599{{0}, {8}, {0}, {0}}},600601{SVGA3D_R8G8_UNORM, SVGA3DBLOCKDESC_RG,602{1, 1, 1}, 2, 2,60316, {{0}, {8}, {8}, {0}},604{{0}, {8}, {0}, {0}}},605606{SVGA3D_R8G8_UINT, SVGA3DBLOCKDESC_RG,607{1, 1, 1}, 2, 2,60816, {{0}, {8}, {8}, {0}},609{{0}, {8}, {0}, {0}}},610611{SVGA3D_R8G8_SINT, SVGA3DBLOCKDESC_UV,612{1, 1, 1}, 2, 2,61316, {{0}, {8}, {8}, {0}},614{{0}, {8}, {0}, {0}}},615616{SVGA3D_R16_TYPELESS, SVGA3DBLOCKDESC_RED,617{1, 1, 1}, 2, 2,61816, {{0}, {0}, {16}, {0}},619{{0}, {0}, {0}, {0}}},620621{SVGA3D_R16_UNORM, SVGA3DBLOCKDESC_RED,622{1, 1, 1}, 2, 2,62316, {{0}, {0}, {16}, {0}},624{{0}, {0}, {0}, {0}}},625626{SVGA3D_R16_UINT, SVGA3DBLOCKDESC_RED,627{1, 1, 1}, 2, 2,62816, {{0}, {0}, {16}, {0}},629{{0}, {0}, {0}, {0}}},630631{SVGA3D_R16_SNORM, SVGA3DBLOCKDESC_U,632{1, 1, 1}, 2, 2,63316, {{0}, {0}, {16}, {0}},634{{0}, {0}, {0}, {0}}},635636{SVGA3D_R16_SINT, SVGA3DBLOCKDESC_U,637{1, 1, 1}, 2, 2,63816, {{0}, {0}, {16}, {0}},639{{0}, {0}, {0}, {0}}},640641{SVGA3D_R8_TYPELESS, SVGA3DBLOCKDESC_RED,642{1, 1, 1}, 1, 1,6438, {{0}, {0}, {8}, {0}},644{{0}, {0}, {0}, {0}}},645646{SVGA3D_R8_UNORM, SVGA3DBLOCKDESC_RED,647{1, 1, 1}, 1, 1,6488, {{0}, {0}, {8}, {0}},649{{0}, {0}, {0}, {0}}},650651{SVGA3D_R8_UINT, SVGA3DBLOCKDESC_RED,652{1, 1, 1}, 1, 1,6538, {{0}, {0}, {8}, {0}},654{{0}, {0}, {0}, {0}}},655656{SVGA3D_R8_SNORM, SVGA3DBLOCKDESC_U,657{1, 1, 1}, 1, 1,6588, {{0}, {0}, {8}, {0}},659{{0}, {0}, {0}, {0}}},660661{SVGA3D_R8_SINT, SVGA3DBLOCKDESC_U,662{1, 1, 1}, 1, 1,6638, {{0}, {0}, {8}, {0}},664{{0}, {0}, {0}, {0}}},665666{SVGA3D_P8, SVGA3DBLOCKDESC_RED,667{1, 1, 1}, 1, 1,6688, {{0}, {0}, {8}, {0}},669{{0}, {0}, {0}, {0}}},670671{SVGA3D_R9G9B9E5_SHAREDEXP, SVGA3DBLOCKDESC_RGBE,672{1, 1, 1}, 4, 4,67332, {{9}, {9}, {9}, {5}},674{{18}, {9}, {0}, {27}}},675676{SVGA3D_R8G8_B8G8_UNORM, SVGA3DBLOCKDESC_RG,677{1, 1, 1}, 2, 2,67816, {{0}, {8}, {8}, {0}},679{{0}, {8}, {0}, {0}}},680681{SVGA3D_G8R8_G8B8_UNORM, SVGA3DBLOCKDESC_RG,682{1, 1, 1}, 2, 2,68316, {{0}, {8}, {8}, {0}},684{{0}, {8}, {0}, {0}}},685686{SVGA3D_BC1_TYPELESS, SVGA3DBLOCKDESC_COMPRESSED,687{4, 4, 1}, 8, 8,68864, {{0}, {0}, {64}, {0}},689{{0}, {0}, {0}, {0}}},690691{SVGA3D_BC1_UNORM_SRGB, SVGA3DBLOCKDESC_COMPRESSED_SRGB,692{4, 4, 1}, 8, 8,69364, {{0}, {0}, {64}, {0}},694{{0}, {0}, {0}, {0}}},695696{SVGA3D_BC2_TYPELESS, SVGA3DBLOCKDESC_COMPRESSED,697{4, 4, 1}, 16, 16,698128, {{0}, {0}, {128}, {0}},699{{0}, {0}, {0}, {0}}},700701{SVGA3D_BC2_UNORM_SRGB, SVGA3DBLOCKDESC_COMPRESSED_SRGB,702{4, 4, 1}, 16, 16,703128, {{0}, {0}, {128}, {0}},704{{0}, {0}, {0}, {0}}},705706{SVGA3D_BC3_TYPELESS, SVGA3DBLOCKDESC_COMPRESSED,707{4, 4, 1}, 16, 16,708128, {{0}, {0}, {128}, {0}},709{{0}, {0}, {0}, {0}}},710711{SVGA3D_BC3_UNORM_SRGB, SVGA3DBLOCKDESC_COMPRESSED_SRGB,712{4, 4, 1}, 16, 16,713128, {{0}, {0}, {128}, {0}},714{{0}, {0}, {0}, {0}}},715716{SVGA3D_BC4_TYPELESS, SVGA3DBLOCKDESC_COMPRESSED,717{4, 4, 1}, 8, 8,71864, {{0}, {0}, {64}, {0}},719{{0}, {0}, {0}, {0}}},720721{SVGA3D_ATI1, SVGA3DBLOCKDESC_COMPRESSED,722{4, 4, 1}, 8, 8,72364, {{0}, {0}, {64}, {0}},724{{0}, {0}, {0}, {0}}},725726{SVGA3D_BC4_SNORM, SVGA3DBLOCKDESC_COMPRESSED,727{4, 4, 1}, 8, 8,72864, {{0}, {0}, {64}, {0}},729{{0}, {0}, {0}, {0}}},730731{SVGA3D_BC5_TYPELESS, SVGA3DBLOCKDESC_COMPRESSED,732{4, 4, 1}, 16, 16,733128, {{0}, {0}, {128}, {0}},734{{0}, {0}, {0}, {0}}},735736{SVGA3D_ATI2, SVGA3DBLOCKDESC_COMPRESSED,737{4, 4, 1}, 16, 16,738128, {{0}, {0}, {128}, {0}},739{{0}, {0}, {0}, {0}}},740741{SVGA3D_BC5_SNORM, SVGA3DBLOCKDESC_COMPRESSED,742{4, 4, 1}, 16, 16,743128, {{0}, {0}, {128}, {0}},744{{0}, {0}, {0}, {0}}},745746{SVGA3D_R10G10B10_XR_BIAS_A2_UNORM, SVGA3DBLOCKDESC_RGBA,747{1, 1, 1}, 4, 4,74832, {{10}, {10}, {10}, {2}},749{{0}, {10}, {20}, {30}}},750751{SVGA3D_B8G8R8A8_TYPELESS, SVGA3DBLOCKDESC_RGBA,752{1, 1, 1}, 4, 4,75332, {{8}, {8}, {8}, {8}},754{{0}, {8}, {16}, {24}}},755756{SVGA3D_B8G8R8A8_UNORM_SRGB, SVGA3DBLOCKDESC_RGBA_SRGB,757{1, 1, 1}, 4, 4,75832, {{8}, {8}, {8}, {8}},759{{0}, {8}, {16}, {24}}},760761{SVGA3D_B8G8R8X8_TYPELESS, SVGA3DBLOCKDESC_RGB,762{1, 1, 1}, 4, 4,76324, {{8}, {8}, {8}, {0}},764{{0}, {8}, {16}, {24}}},765766{SVGA3D_B8G8R8X8_UNORM_SRGB, SVGA3DBLOCKDESC_RGB_SRGB,767{1, 1, 1}, 4, 4,76824, {{8}, {8}, {8}, {0}},769{{0}, {8}, {16}, {24}}},770771{SVGA3D_Z_DF16, SVGA3DBLOCKDESC_DEPTH,772{1, 1, 1}, 2, 2,77316, {{0}, {0}, {16}, {0}},774{{0}, {0}, {0}, {0}}},775776{SVGA3D_Z_DF24, SVGA3DBLOCKDESC_DEPTH,777{1, 1, 1}, 4, 4,77832, {{0}, {8}, {24}, {0}},779{{0}, {24}, {0}, {0}}},780781{SVGA3D_Z_D24S8_INT, SVGA3DBLOCKDESC_DS,782{1, 1, 1}, 4, 4,78332, {{0}, {8}, {24}, {0}},784{{0}, {24}, {0}, {0}}},785786{SVGA3D_YV12, SVGA3DBLOCKDESC_YV12,787{2, 2, 1}, 6, 2,78848, {{0}, {0}, {48}, {0}},789{{0}, {0}, {0}, {0}}},790791{SVGA3D_R32G32B32A32_FLOAT, SVGA3DBLOCKDESC_RGBA_FP,792{1, 1, 1}, 16, 16,793128, {{32}, {32}, {32}, {32}},794{{64}, {32}, {0}, {96}}},795796{SVGA3D_R16G16B16A16_FLOAT, SVGA3DBLOCKDESC_RGBA_FP,797{1, 1, 1}, 8, 8,79864, {{16}, {16}, {16}, {16}},799{{32}, {16}, {0}, {48}}},800801{SVGA3D_R16G16B16A16_UNORM, SVGA3DBLOCKDESC_RGBA,802{1, 1, 1}, 8, 8,80364, {{16}, {16}, {16}, {16}},804{{32}, {16}, {0}, {48}}},805806{SVGA3D_R32G32_FLOAT, SVGA3DBLOCKDESC_RG_FP,807{1, 1, 1}, 8, 8,80864, {{0}, {32}, {32}, {0}},809{{0}, {32}, {0}, {0}}},810811{SVGA3D_R10G10B10A2_UNORM, SVGA3DBLOCKDESC_RGBA,812{1, 1, 1}, 4, 4,81332, {{10}, {10}, {10}, {2}},814{{0}, {10}, {20}, {30}}},815816{SVGA3D_R8G8B8A8_SNORM, SVGA3DBLOCKDESC_RGBA,817{1, 1, 1}, 4, 4,81832, {{8}, {8}, {8}, {8}},819{{24}, {16}, {8}, {0}}},820821{SVGA3D_R16G16_FLOAT, SVGA3DBLOCKDESC_RG_FP,822{1, 1, 1}, 4, 4,82332, {{0}, {16}, {16}, {0}},824{{0}, {16}, {0}, {0}}},825826{SVGA3D_R16G16_UNORM, SVGA3DBLOCKDESC_RG,827{1, 1, 1}, 4, 4,82832, {{0}, {16}, {16}, {0}},829{{0}, {0}, {16}, {0}}},830831{SVGA3D_R16G16_SNORM, SVGA3DBLOCKDESC_RG,832{1, 1, 1}, 4, 4,83332, {{16}, {16}, {0}, {0}},834{{16}, {0}, {0}, {0}}},835836{SVGA3D_R32_FLOAT, SVGA3DBLOCKDESC_R_FP,837{1, 1, 1}, 4, 4,83832, {{0}, {0}, {32}, {0}},839{{0}, {0}, {0}, {0}}},840841{SVGA3D_R8G8_SNORM, SVGA3DBLOCKDESC_RG,842{1, 1, 1}, 2, 2,84316, {{8}, {8}, {0}, {0}},844{{8}, {0}, {0}, {0}}},845846{SVGA3D_R16_FLOAT, SVGA3DBLOCKDESC_R_FP,847{1, 1, 1}, 2, 2,84816, {{0}, {0}, {16}, {0}},849{{0}, {0}, {0}, {0}}},850851{SVGA3D_D16_UNORM, SVGA3DBLOCKDESC_DEPTH,852{1, 1, 1}, 2, 2,85316, {{0}, {0}, {16}, {0}},854{{0}, {0}, {0}, {0}}},855856{SVGA3D_A8_UNORM, SVGA3DBLOCKDESC_ALPHA,857{1, 1, 1}, 1, 1,8588, {{0}, {0}, {0}, {8}},859{{0}, {0}, {0}, {0}}},860861{SVGA3D_BC1_UNORM, SVGA3DBLOCKDESC_COMPRESSED,862{4, 4, 1}, 8, 8,86364, {{0}, {0}, {64}, {0}},864{{0}, {0}, {0}, {0}}},865866{SVGA3D_BC2_UNORM, SVGA3DBLOCKDESC_COMPRESSED,867{4, 4, 1}, 16, 16,868128, {{0}, {0}, {128}, {0}},869{{0}, {0}, {0}, {0}}},870871{SVGA3D_BC3_UNORM, SVGA3DBLOCKDESC_COMPRESSED,872{4, 4, 1}, 16, 16,873128, {{0}, {0}, {128}, {0}},874{{0}, {0}, {0}, {0}}},875876{SVGA3D_B5G6R5_UNORM, SVGA3DBLOCKDESC_RGB,877{1, 1, 1}, 2, 2,87816, {{5}, {6}, {5}, {0}},879{{0}, {5}, {11}, {0}}},880881{SVGA3D_B5G5R5A1_UNORM, SVGA3DBLOCKDESC_RGBA,882{1, 1, 1}, 2, 2,88316, {{5}, {5}, {5}, {1}},884{{0}, {5}, {10}, {15}}},885886{SVGA3D_B8G8R8A8_UNORM, SVGA3DBLOCKDESC_RGBA,887{1, 1, 1}, 4, 4,88832, {{8}, {8}, {8}, {8}},889{{0}, {8}, {16}, {24}}},890891{SVGA3D_B8G8R8X8_UNORM, SVGA3DBLOCKDESC_RGB,892{1, 1, 1}, 4, 4,89324, {{8}, {8}, {8}, {0}},894{{0}, {8}, {16}, {24}}},895896{SVGA3D_BC4_UNORM, SVGA3DBLOCKDESC_COMPRESSED,897{4, 4, 1}, 8, 8,89864, {{0}, {0}, {64}, {0}},899{{0}, {0}, {0}, {0}}},900901{SVGA3D_BC5_UNORM, SVGA3DBLOCKDESC_COMPRESSED,902{4, 4, 1}, 16, 16,903128, {{0}, {0}, {128}, {0}},904{{0}, {0}, {0}, {0}}},905};906907908extern const struct svga3d_surface_desc g_SVGA3dSurfaceDescs[];909extern int g_SVGA3dSurfaceDescs_size;910911static inline uint32 clamped_umul32(uint32 a, uint32 b)912{913uint64_t tmp = (uint64_t) a*b;914return (tmp > (uint64_t) ((uint32) -1)) ? (uint32) -1 : tmp;915}916917static inline uint32 clamped_uadd32(uint32 a, uint32 b)918{919uint32 c = a + b;920if (c < a || c < b) {921return MAX_UINT32;922}923return c;924}925926927static inline const struct svga3d_surface_desc *928svga3dsurface_get_desc(SVGA3dSurfaceFormat format)929{930if (format < ARRAY_SIZE(svga3d_surface_descs))931return &svga3d_surface_descs[format];932933return &svga3d_surface_descs[SVGA3D_FORMAT_INVALID];934}935936/*937*----------------------------------------------------------------------938*939* svga3dsurface_get_mip_size --940*941* Given a base level size and the mip level, compute the size of942* the mip level.943*944* Results:945* See above.946*947* Side effects:948* None.949*950*----------------------------------------------------------------------951*/952953static inline SVGA3dSize954svga3dsurface_get_mip_size(SVGA3dSize base_level, uint32 mip_level)955{956SVGA3dSize size;957958size.width = max_t(uint32, base_level.width >> mip_level, 1);959size.height = max_t(uint32, base_level.height >> mip_level, 1);960size.depth = max_t(uint32, base_level.depth >> mip_level, 1);961return size;962}963964static inline void965svga3dsurface_get_size_in_blocks(const struct svga3d_surface_desc *desc,966const SVGA3dSize *pixel_size,967SVGA3dSize *block_size)968{969block_size->width = DIV_ROUND_UP(pixel_size->width,970desc->block_size.width);971block_size->height = DIV_ROUND_UP(pixel_size->height,972desc->block_size.height);973block_size->depth = DIV_ROUND_UP(pixel_size->depth,974desc->block_size.depth);975}976977static inline bool978svga3dsurface_is_planar_surface(const struct svga3d_surface_desc *desc)979{980return (desc->block_desc & SVGA3DBLOCKDESC_PLANAR_YUV) != 0;981}982983static inline uint32984svga3dsurface_calculate_pitch(const struct svga3d_surface_desc *desc,985const SVGA3dSize *size)986{987uint32 pitch;988SVGA3dSize blocks;989990svga3dsurface_get_size_in_blocks(desc, size, &blocks);991992pitch = blocks.width * desc->pitch_bytes_per_block;993994return pitch;995}996997/*998*-----------------------------------------------------------------------------999*1000* svga3dsurface_get_image_buffer_size --1001*1002* Return the number of bytes of buffer space required to store1003* one image of a surface, optionally using the specified pitch.1004*1005* If pitch is zero, it is assumed that rows are tightly packed.1006*1007* This function is overflow-safe. If the result would have1008* overflowed, instead we return MAX_UINT32.1009*1010* Results:1011* Byte count.1012*1013* Side effects:1014* None.1015*1016*-----------------------------------------------------------------------------1017*/10181019static inline uint321020svga3dsurface_get_image_buffer_size(const struct svga3d_surface_desc *desc,1021const SVGA3dSize *size,1022uint32 pitch)1023{1024SVGA3dSize image_blocks;1025uint32 slice_size, total_size;10261027svga3dsurface_get_size_in_blocks(desc, size, &image_blocks);10281029if (svga3dsurface_is_planar_surface(desc)) {1030total_size = clamped_umul32(image_blocks.width,1031image_blocks.height);1032total_size = clamped_umul32(total_size, image_blocks.depth);1033total_size = clamped_umul32(total_size, desc->bytes_per_block);1034return total_size;1035}10361037if (pitch == 0)1038pitch = svga3dsurface_calculate_pitch(desc, size);10391040slice_size = clamped_umul32(image_blocks.height, pitch);1041total_size = clamped_umul32(slice_size, image_blocks.depth);10421043return total_size;1044}104510461047static inline uint321048svga3dsurface_get_image_offset(SVGA3dSurfaceFormat format,1049SVGA3dSize baseLevelSize,1050uint32 numMipLevels,1051uint32 layer,1052uint32 mip)10531054{1055uint32 offset;1056uint32 mipChainBytes;1057uint32 mipChainBytesToLevel;1058uint32 i;1059const struct svga3d_surface_desc *desc;1060SVGA3dSize mipSize;1061uint32 bytes;10621063desc = svga3dsurface_get_desc(format);10641065mipChainBytes = 0;1066mipChainBytesToLevel = 0;1067for (i = 0; i < numMipLevels; i++) {1068mipSize = svga3dsurface_get_mip_size(baseLevelSize, i);1069bytes = svga3dsurface_get_image_buffer_size(desc, &mipSize, 0);1070mipChainBytes += bytes;1071if (i < mip) {1072mipChainBytesToLevel += bytes;1073}1074}10751076offset = mipChainBytes * layer + mipChainBytesToLevel;10771078return offset;1079}108010811082static inline uint321083svga3dsurface_get_serialized_size(SVGA3dSurfaceFormat format,1084SVGA3dSize base_level_size,1085uint32 num_mip_levels,1086uint32 num_layers)1087{1088const struct svga3d_surface_desc *desc = svga3dsurface_get_desc(format);1089uint64_t total_size = 0;1090uint32 mip;10911092for (mip = 0; mip < num_mip_levels; mip++) {1093SVGA3dSize size =1094svga3dsurface_get_mip_size(base_level_size, mip);1095total_size += svga3dsurface_get_image_buffer_size(desc,1096&size, 0);1097}10981099total_size *= num_layers;11001101return (total_size > (uint64_t) MAX_UINT32) ? MAX_UINT32 :1102(uint32) total_size;1103}110411051106/**1107* svga3dsurface_get_serialized_size_extended - Returns the number of bytes1108* required for a surface with given parameters. Support for sample count.1109*1110*/1111static inline uint321112svga3dsurface_get_serialized_size_extended(SVGA3dSurfaceFormat format,1113SVGA3dSize base_level_size,1114uint32 num_mip_levels,1115uint32 num_layers,1116uint32 num_samples)1117{1118uint64_t total_size = svga3dsurface_get_serialized_size(format,1119base_level_size,1120num_mip_levels,1121num_layers);11221123total_size *= (num_samples > 1 ? num_samples : 1);11241125return (total_size > (uint64_t) MAX_UINT32) ? MAX_UINT32 :1126(uint32) total_size;1127}112811291130/**1131* Compute the offset (in bytes) to a pixel in an image (or volume).1132* 'width' is the image width in pixels1133* 'height' is the image height in pixels1134*/1135static inline uint321136svga3dsurface_get_pixel_offset(SVGA3dSurfaceFormat format,1137uint32 width, uint32 height,1138uint32 x, uint32 y, uint32 z)1139{1140const struct svga3d_surface_desc *desc = svga3dsurface_get_desc(format);1141const uint32 bw = desc->block_size.width, bh = desc->block_size.height;1142const uint32 bd = desc->block_size.depth;1143const uint32 rowstride = DIV_ROUND_UP(width, bw) * desc->bytes_per_block;1144const uint32 imgstride = DIV_ROUND_UP(height, bh) * rowstride;1145const uint32 offset = (z / bd * imgstride +1146y / bh * rowstride +1147x / bw * desc->bytes_per_block);1148return offset;1149}11501151#endif115211531154