Home | History | Annotate | Download | only in nv30
      1 /*
      2  * Copyright 2012 Red Hat Inc.
      3  *
      4  * Permission is hereby granted, free of charge, to any person obtaining a
      5  * copy of this software and associated documentation files (the "Software"),
      6  * to deal in the Software without restriction, including without limitation
      7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      8  * and/or sell copies of the Software, and to permit persons to whom the
      9  * Software is furnished to do so, subject to the following conditions:
     10  *
     11  * The above copyright notice and this permission notice shall be included in
     12  * all copies or substantial portions of the Software.
     13  *
     14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     17  * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
     18  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
     19  * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
     20  * SOFTWARE.
     21  *
     22  * Authors: Ben Skeggs
     23  *
     24  */
     25 
     26 #include "nv30-40_3d.xml.h"
     27 #include "nv30_context.h"
     28 #include "nv30_format.h"
     29 
     30 #define NV30_3D_RT_FORMAT_COLOR_X1R5G5B5 2
     31 
     32 #define NV30_3D_TEX_FORMAT_FORMAT_A16L16 NV30_3D_TEX_FORMAT_FORMAT_HILO16
     33 #define NV30_3D_TEX_FORMAT_FORMAT_A16L16_RECT NV30_3D_TEX_FORMAT_FORMAT_HILO16_RECT
     34 #define NV30_3D_TEX_FORMAT_FORMAT_RGBA16F 0x00004a00
     35 #define NV30_3D_TEX_FORMAT_FORMAT_RGBA16F_RECT NV30_3D_TEX_FORMAT_FORMAT_RGBA16F
     36 #define NV30_3D_TEX_FORMAT_FORMAT_RGBA32F 0x00004b00
     37 #define NV30_3D_TEX_FORMAT_FORMAT_RGBA32F_RECT NV30_3D_TEX_FORMAT_FORMAT_RGBA32F
     38 #define NV30_3D_TEX_FORMAT_FORMAT_R32F 0x00004c00
     39 #define NV30_3D_TEX_FORMAT_FORMAT_R32F_RECT NV30_3D_TEX_FORMAT_FORMAT_R32F
     40 #define NV30_3D_TEX_FORMAT_FORMAT_DXT1_RECT NV30_3D_TEX_FORMAT_FORMAT_DXT1
     41 #define NV30_3D_TEX_FORMAT_FORMAT_DXT3_RECT NV30_3D_TEX_FORMAT_FORMAT_DXT3
     42 #define NV30_3D_TEX_FORMAT_FORMAT_DXT5_RECT NV30_3D_TEX_FORMAT_FORMAT_DXT5
     43 #define NV30_3D_TEX_FORMAT_FORMAT_RG16F 0xdeadcafe
     44 #define NV30_3D_TEX_FORMAT_FORMAT_RG16F_RECT 0xdeadcafe
     45 
     46 #define NV40_3D_TEX_FORMAT_FORMAT_R32F 0x00001c00
     47 #define NV40_3D_TEX_FORMAT_FORMAT_RG16F 0x00001f00
     48 
     49 #define ____ 0
     50 #define S___ PIPE_BIND_SAMPLER_VIEW
     51 #define _R__ PIPE_BIND_RENDER_TARGET
     52 #define _B__ PIPE_BIND_RENDER_TARGET | PIPE_BIND_BLENDABLE
     53 #define _Z__ PIPE_BIND_DEPTH_STENCIL
     54 #define __V_ PIPE_BIND_VERTEX_BUFFER
     55 #define SR__ (S___ | _R__)
     56 #define SB__ (S___ | _B__)
     57 #define SZ__ (S___ | _Z__)
     58 #define S_V_ (S___ | __V_)
     59 #define SRV_ (SR__ | __V_)
     60 #define SBV_ (SB__ | __V_)
     61 
     62 #define _(a,b) [PIPE_FORMAT_##a] = {                                           \
     63    .bindings = (b),                                                            \
     64 }
     65 const struct nv30_format_info
     66 nv30_format_info_table[PIPE_FORMAT_COUNT] = {
     67    _(L8_UNORM            , S___),
     68    _(L8_SNORM            , S___),
     69    _(L8_SRGB             , S___),
     70    _(I8_UNORM            , S___),
     71    _(I8_SNORM            , S___),
     72    _(A8_UNORM            , S___),
     73    _(A8_SNORM            , S___),
     74    _(R8_UNORM            , S_V_),
     75    _(R8_SNORM            , S___),
     76    _(B5G5R5X1_UNORM      , SB__),
     77    _(B5G5R5A1_UNORM      , S___),
     78    _(B4G4R4X4_UNORM      , S___),
     79    _(B4G4R4A4_UNORM      , S___),
     80    _(B5G6R5_UNORM        , SB__),
     81    _(B8G8R8X8_UNORM      , SB__),
     82    _(B8G8R8X8_SRGB       , S___),
     83    _(B8G8R8A8_UNORM      , SB__),
     84    _(B8G8R8A8_SRGB       , S___),
     85    _(R8G8B8A8_UNORM      , __V_),
     86    _(R8G8B8A8_SNORM      , S___),
     87    _(DXT1_RGB            , S___),
     88    _(DXT1_SRGB           , S___),
     89    _(DXT1_RGBA           , S___),
     90    _(DXT1_SRGBA          , S___),
     91    _(DXT3_RGBA           , S___),
     92    _(DXT3_SRGBA          , S___),
     93    _(DXT5_RGBA           , S___),
     94    _(DXT5_SRGBA          , S___),
     95    _(L8A8_UNORM          , S___),
     96    _(L8A8_SRGB           , S___),
     97    _(R8G8_UNORM          , S_V_),
     98    _(R8G8_SNORM          , S___),
     99    _(R8G8B8_UNORM        , __V_),
    100    _(Z16_UNORM           , SZ__),
    101    _(X8Z24_UNORM         , SZ__),
    102    _(S8_UINT_Z24_UNORM   , SZ__),
    103    _(L16_UNORM           , S___),
    104    _(L16_SNORM           , S___),
    105    _(I16_UNORM           , S___),
    106    _(I16_SNORM           , S___),
    107    _(A16_UNORM           , S___),
    108    _(A16_SNORM           , S___),
    109    _(R16_UNORM           , S___),
    110    _(R16_SNORM           , S_V_),
    111    _(R16G16_SNORM        , __V_),
    112    _(R16G16B16_SNORM     , __V_),
    113    _(R16G16B16A16_SNORM  , __V_),
    114    _(R8_USCALED          , __V_),
    115    _(R8G8_USCALED        , __V_),
    116    _(R8G8B8_USCALED      , __V_),
    117    _(R8G8B8A8_USCALED    , __V_),
    118    _(R16_FLOAT           , __V_),
    119    _(R16G16_FLOAT        , __V_), //S_V_),
    120    _(R16G16B16_FLOAT     , __V_),
    121    _(R16G16B16A16_FLOAT  , __V_), //SBV_),
    122    _(R16_SSCALED         , __V_),
    123    _(R16G16_SSCALED      , __V_),
    124    _(R16G16B16_SSCALED   , __V_),
    125    _(R16G16B16A16_SSCALED, __V_),
    126    _(R32_FLOAT           , __V_), //SRV_),
    127    _(R32G32_FLOAT        , __V_),
    128    _(R32G32B32_FLOAT     , __V_),
    129    _(R32G32B32A32_FLOAT  , __V_), //SRV_),
    130 };
    131 #undef _
    132 #undef ____
    133 
    134 #define R_(a,b) [PIPE_FORMAT_##a] = {                                          \
    135    .hw = NV30_3D_RT_FORMAT_COLOR_##b,                                          \
    136 }
    137 #define Z_(a,b) [PIPE_FORMAT_##a] = {                                          \
    138    .hw = NV30_3D_RT_FORMAT_ZETA_##b,                                           \
    139 }
    140 const struct nv30_format
    141 nv30_format_table[PIPE_FORMAT_COUNT] = {
    142    R_(B5G5R5X1_UNORM    , X1R5G5B5          ),
    143    R_(B5G6R5_UNORM      , R5G6B5            ),
    144    R_(B8G8R8X8_UNORM    , X8R8G8B8          ),
    145    R_(B8G8R8A8_UNORM    , A8R8G8B8          ),
    146    Z_(Z16_UNORM         , Z16               ),
    147    Z_(X8Z24_UNORM       , Z24S8             ),
    148    Z_(S8_UINT_Z24_UNORM , Z24S8             ),
    149    R_(R16G16B16A16_FLOAT, A16B16G16R16_FLOAT),
    150    R_(R32G32B32A32_FLOAT, A32B32G32R32_FLOAT),
    151    R_(R32_FLOAT         , R32_FLOAT         ),
    152 };
    153 
    154 #define _(a,b,c) [PIPE_FORMAT_##a] = {                                         \
    155    .hw = NV30_3D_VTXFMT_TYPE_##b | ((c) << NV30_3D_VTXFMT_SIZE__SHIFT)         \
    156 }
    157 const struct nv30_vtxfmt
    158 nv30_vtxfmt_table[PIPE_FORMAT_COUNT] = {
    159    _(R8_UNORM            , U8_UNORM   , 1),
    160    _(R8G8_UNORM          , U8_UNORM   , 2),
    161    _(R8G8B8_UNORM        , U8_UNORM   , 3),
    162    _(R8G8B8A8_UNORM      , U8_UNORM   , 4),
    163    _(R8_USCALED          , U8_USCALED , 1),
    164    _(R8G8_USCALED        , U8_USCALED , 2),
    165    _(R8G8B8_USCALED      , U8_USCALED , 3),
    166    _(R8G8B8A8_USCALED    , U8_USCALED , 4),
    167    _(R16_SNORM           , V16_SNORM  , 1),
    168    _(R16G16_SNORM        , V16_SNORM  , 2),
    169    _(R16G16B16_SNORM     , V16_SNORM  , 3),
    170    _(R16G16B16A16_SNORM  , V16_SNORM  , 4),
    171    _(R16_SSCALED         , V16_SSCALED, 1),
    172    _(R16G16_SSCALED      , V16_SSCALED, 2),
    173    _(R16G16B16_SSCALED   , V16_SSCALED, 3),
    174    _(R16G16B16A16_SSCALED, V16_SSCALED, 4),
    175    _(R16_FLOAT           , V16_FLOAT  , 1),
    176    _(R16G16_FLOAT        , V16_FLOAT  , 2),
    177    _(R16G16B16_FLOAT     , V16_FLOAT  , 3),
    178    _(R16G16B16A16_FLOAT  , V16_FLOAT  , 4),
    179    _(R32_FLOAT           , V32_FLOAT  , 1),
    180    _(R32G32_FLOAT        , V32_FLOAT  , 2),
    181    _(R32G32B32_FLOAT     , V32_FLOAT  , 3),
    182    _(R32G32B32A32_FLOAT  , V32_FLOAT  , 4),
    183 };
    184 #undef _
    185 
    186 #define SWZ_OUT_0 0
    187 #define SWZ_OUT_1 1
    188 #define SWZ_OUT_C 2
    189 
    190 #define SWZ_SRC_0 3
    191 #define SWZ_SRC_1 2
    192 #define SWZ_SRC_2 1
    193 #define SWZ_SRC_3 0
    194 #define SWZ_SRC_x 0
    195 
    196 #define NONE 0x00000000
    197 #define SRGB 0x00700000
    198 
    199 #define ____ 0x00000000
    200 #define SSSS 0xf0000000
    201 
    202 #define _(a,b,c,d,e,f,g,h,i,j,k,l,m) [PIPE_FORMAT_##a] = {                     \
    203    .nv30 = NV30_3D_TEX_FORMAT_FORMAT_##b,                                      \
    204    .nv30_rect = NV30_3D_TEX_FORMAT_FORMAT_##b##_RECT,                          \
    205    .nv40 = NV40_3D_TEX_FORMAT_FORMAT_##b,                                      \
    206    .swz[0] = { SWZ_OUT_##d, SWZ_SRC_##h },                                     \
    207    .swz[1] = { SWZ_OUT_##e, SWZ_SRC_##i },                                     \
    208    .swz[2] = { SWZ_OUT_##f, SWZ_SRC_##j },                                     \
    209    .swz[3] = { SWZ_OUT_##g, SWZ_SRC_##k },                                     \
    210    .swz[4] = { SWZ_OUT_0, SWZ_SRC_x },                                         \
    211    .swz[5] = { SWZ_OUT_1, SWZ_SRC_x },                                         \
    212    .swizzle = (c) * 0x00010000,                                                \
    213    .wrap =  (l),                                                               \
    214    .filter = (m),                                                              \
    215 }
    216 const struct nv30_texfmt
    217 nv30_texfmt_table[PIPE_FORMAT_COUNT] = {
    218    _(L8_UNORM          , L8      , 0, C, C, C, 1, 0, 0, 0, x, NONE, ____),
    219    _(L8_SNORM          , L8      , 0, C, C, C, 1, 0, 0, 0, x, NONE, SSSS),
    220    _(L8_SRGB           , L8      , 0, C, C, C, 1, 0, 0, 0, x, SRGB, ____),
    221    _(I8_UNORM          , L8      , 0, C, C, C, C, 0, 0, 0, 0, NONE, ____),
    222    _(I8_SNORM          , L8      , 0, C, C, C, C, 0, 0, 0, 0, NONE, SSSS),
    223    _(A8_UNORM          , L8      , 0, 0, 0, 0, C, x, x, x, 0, NONE, ____),
    224    _(A8_SNORM          , L8      , 0, 0, 0, 0, C, x, x, x, 0, NONE, SSSS),
    225    _(R8_UNORM          , L8      , 0, C, 0, 0, 1, 0, x, x, x, NONE, ____),
    226    _(R8_SNORM          , L8      , 0, C, 0, 0, 1, 0, x, x, x, NONE, SSSS),
    227    _(B5G5R5X1_UNORM    , A1R5G5B5, 0, C, C, C, 1, 2, 1, 0, x, NONE, ____),
    228    _(B5G5R5A1_UNORM    , A1R5G5B5, 0, C, C, C, C, 2, 1, 0, 3, NONE, ____),
    229    _(B4G4R4X4_UNORM    , A4R4G4B4, 0, C, C, C, 1, 2, 1, 0, x, NONE, ____),
    230    _(B4G4R4A4_UNORM    , A4R4G4B4, 0, C, C, C, C, 2, 1, 0, 3, NONE, ____),
    231    _(B5G6R5_UNORM      , R5G6B5  , 0, C, C, C, 1, 2, 1, 0, x, NONE, ____),
    232    _(B8G8R8X8_UNORM    , A8R8G8B8, 0, C, C, C, 1, 2, 1, 0, x, NONE, ____),
    233    _(B8G8R8X8_SRGB     , A8R8G8B8, 0, C, C, C, 1, 2, 1, 0, x, SRGB, ____),
    234    _(B8G8R8A8_UNORM    , A8R8G8B8, 0, C, C, C, C, 2, 1, 0, 3, NONE, ____),
    235    _(B8G8R8A8_SRGB     , A8R8G8B8, 0, C, C, C, C, 2, 1, 0, 3, SRGB, ____),
    236    _(R8G8B8A8_SNORM    , A8R8G8B8, 0, C, C, C, C, 0, 1, 2, 3, NONE, SSSS),
    237    _(DXT1_RGB          , DXT1    , 0, C, C, C, 1, 2, 1, 0, x, NONE, ____),
    238    _(DXT1_SRGB         , DXT1    , 0, C, C, C, 1, 2, 1, 0, x, SRGB, ____),
    239    _(DXT1_RGBA         , DXT1    , 0, C, C, C, C, 2, 1, 0, 3, NONE, ____),
    240    _(DXT1_SRGBA        , DXT1    , 0, C, C, C, C, 2, 1, 0, 3, SRGB, ____),
    241    _(DXT3_RGBA         , DXT3    , 0, C, C, C, C, 2, 1, 0, 3, NONE, ____),
    242    _(DXT3_SRGBA        , DXT3    , 0, C, C, C, C, 2, 1, 0, 3, SRGB, ____),
    243    _(DXT5_RGBA         , DXT5    , 0, C, C, C, C, 2, 1, 0, 3, NONE, ____),
    244    _(DXT5_SRGBA        , DXT5    , 0, C, C, C, C, 2, 1, 0, 3, SRGB, ____),
    245    _(L8A8_UNORM        , A8L8    , 0, C, C, C, C, 0, 0, 0, 3, NONE, ____),
    246    _(L8A8_SRGB         , A8L8    , 0, C, C, C, C, 0, 0, 0, 3, SRGB, ____),
    247    _(R8G8_UNORM        , A8L8    , 0, C, C, 0, 1, 0, 3, x, x, NONE, ____),
    248    _(R8G8_SNORM        , A8L8    , 0, C, C, 0, 1, 0, 3, x, x, NONE, SSSS),
    249    _(Z16_UNORM         , Z16     , 0, C, C, C, 1, 3, 3, 3, x, NONE, ____),
    250    _(X8Z24_UNORM       , Z24     , 0, C, C, C, 1, 3, 3, 3, x, NONE, ____),
    251    _(S8_UINT_Z24_UNORM , Z24     , 0, C, C, C, 1, 3, 3, 3, x, NONE, ____),
    252    _(L16_UNORM         , A16     , 0, C, C, C, 1, 1, 1, 1, 1, NONE, ____),
    253    _(L16_SNORM         , A16     , 0, C, C, C, 1, 1, 1, 1, 1, NONE, SSSS),
    254    _(I16_UNORM         , A16     , 0, C, C, C, C, 1, 1, 1, 1, NONE, ____),
    255    _(I16_SNORM         , A16     , 0, C, C, C, C, 1, 1, 1, 1, NONE, SSSS),
    256    _(A16_UNORM         , A16     , 0, 0, 0, 0, C, 1, 1, 1, 1, NONE, ____),
    257    _(A16_SNORM         , A16     , 0, 0, 0, 0, C, 1, 1, 1, 1, NONE, SSSS),
    258    _(R16_UNORM         , A16     , 0, C, 0, 0, 1, 1, 1, 1, 1, NONE, ____),
    259    _(R16_SNORM         , A16     , 0, C, 0, 0, 1, 1, 1, 1, 1, NONE, SSSS),
    260    _(R16G16_FLOAT      , RG16F   , 0, C, C, 0, 1, 2, 1, 0, 3, NONE, ____),
    261    _(R16G16B16A16_FLOAT, RGBA16F , 0, C, C, C, C, 2, 1, 0, 3, NONE, ____),
    262    _(R32_FLOAT         , R32F    , 0, C, 0, 0, 1, 2, 1, 0, 3, NONE, ____),
    263    _(R32G32B32A32_FLOAT, RGBA32F , 0, C, C, C, C, 2, 1, 0, 3, NONE, ____),
    264 };
    265 #undef _
    266