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 OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 * OTHER DEALINGS IN THE SOFTWARE. 21 * 22 * Authors: Ben Skeggs 23 * 24 */ 25 26 #include "nv30/nv30-40_3d.xml.h" 27 #include "nv30/nv30_context.h" 28 #include "nv30/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 _(BGRX8888_UNORM , SB__), 82 _(BGRX8888_SRGB , S___), 83 _(BGRA8888_UNORM , SB__), 84 _(BGRA8888_SRGB , S___), 85 _(R8G8B8A8_UNORM , __V_), 86 _(RGBA8888_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 _(R8G8B8A8_USCALED , __V_), 115 _(R16_FLOAT , __V_), 116 _(R16G16_FLOAT , __V_), //S_V_), 117 _(R16G16B16_FLOAT , __V_), 118 _(R16G16B16A16_FLOAT , __V_), //SBV_), 119 _(R16_SSCALED , __V_), 120 _(R16G16_SSCALED , __V_), 121 _(R16G16B16_SSCALED , __V_), 122 _(R16G16B16A16_SSCALED, __V_), 123 _(R32_FLOAT , __V_), //SRV_), 124 _(R32G32_FLOAT , __V_), 125 _(R32G32B32_FLOAT , __V_), 126 _(R32G32B32A32_FLOAT , __V_), //SRV_), 127 }; 128 #undef _ 129 #undef ____ 130 131 #define R_(a,b) [PIPE_FORMAT_##a] = { \ 132 .hw = NV30_3D_RT_FORMAT_COLOR_##b, \ 133 } 134 #define Z_(a,b) [PIPE_FORMAT_##a] = { \ 135 .hw = NV30_3D_RT_FORMAT_ZETA_##b, \ 136 } 137 const struct nv30_format 138 nv30_format_table[PIPE_FORMAT_COUNT] = { 139 R_(B5G5R5X1_UNORM , X1R5G5B5 ), 140 R_(B5G6R5_UNORM , R5G6B5 ), 141 R_(BGRX8888_UNORM , X8R8G8B8 ), 142 R_(BGRA8888_UNORM , A8R8G8B8 ), 143 Z_(Z16_UNORM , Z16 ), 144 Z_(X8Z24_UNORM , Z24S8 ), 145 Z_(S8_UINT_Z24_UNORM , Z24S8 ), 146 R_(R16G16B16A16_FLOAT, A16B16G16R16_FLOAT), 147 R_(R32G32B32A32_FLOAT, A32B32G32R32_FLOAT), 148 R_(R32_FLOAT , R32_FLOAT ), 149 }; 150 151 #define _(a,b,c) [PIPE_FORMAT_##a] = { \ 152 .hw = NV30_3D_VTXFMT_TYPE_##b | ((c) << NV30_3D_VTXFMT_SIZE__SHIFT) \ 153 } 154 const struct nv30_vtxfmt 155 nv30_vtxfmt_table[PIPE_FORMAT_COUNT] = { 156 _(R8_UNORM , U8_UNORM , 1), 157 _(R8G8_UNORM , U8_UNORM , 2), 158 _(R8G8B8_UNORM , U8_UNORM , 3), 159 _(R8G8B8A8_UNORM , U8_UNORM , 4), 160 _(R8G8B8A8_USCALED , U8_USCALED , 4), 161 _(R16_SNORM , V16_SNORM , 1), 162 _(R16G16_SNORM , V16_SNORM , 2), 163 _(R16G16B16_SNORM , V16_SNORM , 3), 164 _(R16G16B16A16_SNORM , V16_SNORM , 4), 165 _(R16_SSCALED , V16_SSCALED, 1), 166 _(R16G16_SSCALED , V16_SSCALED, 2), 167 _(R16G16B16_SSCALED , V16_SSCALED, 3), 168 _(R16G16B16A16_SSCALED, V16_SSCALED, 4), 169 _(R16_FLOAT , V16_FLOAT , 1), 170 _(R16G16_FLOAT , V16_FLOAT , 2), 171 _(R16G16B16_FLOAT , V16_FLOAT , 3), 172 _(R16G16B16A16_FLOAT , V16_FLOAT , 4), 173 _(R32_FLOAT , V32_FLOAT , 1), 174 _(R32G32_FLOAT , V32_FLOAT , 2), 175 _(R32G32B32_FLOAT , V32_FLOAT , 3), 176 _(R32G32B32A32_FLOAT , V32_FLOAT , 4), 177 }; 178 #undef _ 179 180 #define SWZ_OUT_0 0 181 #define SWZ_OUT_1 1 182 #define SWZ_OUT_C 2 183 184 #define SWZ_SRC_0 3 185 #define SWZ_SRC_1 2 186 #define SWZ_SRC_2 1 187 #define SWZ_SRC_3 0 188 #define SWZ_SRC_x 0 189 190 #define NONE 0x00000000 191 #define SRGB 0x00700000 192 193 #define ____ 0x00000000 194 #define SSSS 0xf0000000 195 196 #define _(a,b,c,d,e,f,g,h,i,j,k,l,m) [PIPE_FORMAT_##a] = { \ 197 .nv30 = NV30_3D_TEX_FORMAT_FORMAT_##b, \ 198 .nv30_rect = NV30_3D_TEX_FORMAT_FORMAT_##b##_RECT, \ 199 .nv40 = NV40_3D_TEX_FORMAT_FORMAT_##b, \ 200 .swz[0] = { SWZ_OUT_##d, SWZ_SRC_##h }, \ 201 .swz[1] = { SWZ_OUT_##e, SWZ_SRC_##i }, \ 202 .swz[2] = { SWZ_OUT_##f, SWZ_SRC_##j }, \ 203 .swz[3] = { SWZ_OUT_##g, SWZ_SRC_##k }, \ 204 .swz[4] = { SWZ_OUT_0, SWZ_SRC_x }, \ 205 .swz[5] = { SWZ_OUT_1, SWZ_SRC_x }, \ 206 .swizzle = (c) * 0x00010000, \ 207 .wrap = (l), \ 208 .filter = (m), \ 209 } 210 const struct nv30_texfmt 211 nv30_texfmt_table[PIPE_FORMAT_COUNT] = { 212 _(L8_UNORM , L8 , 0, C, C, C, 1, 0, 0, 0, x, NONE, ____), 213 _(L8_SNORM , L8 , 0, C, C, C, 1, 0, 0, 0, x, NONE, SSSS), 214 _(L8_SRGB , L8 , 0, C, C, C, 1, 0, 0, 0, x, SRGB, ____), 215 _(I8_UNORM , L8 , 0, C, C, C, C, 0, 0, 0, 0, NONE, ____), 216 _(I8_SNORM , L8 , 0, C, C, C, C, 0, 0, 0, 0, NONE, SSSS), 217 _(A8_UNORM , L8 , 0, 0, 0, 0, C, x, x, x, 0, NONE, ____), 218 _(A8_SNORM , L8 , 0, 0, 0, 0, C, x, x, x, 0, NONE, SSSS), 219 _(R8_UNORM , L8 , 0, C, 0, 0, 1, 0, x, x, x, NONE, ____), 220 _(R8_SNORM , L8 , 0, C, 0, 0, 1, 0, x, x, x, NONE, SSSS), 221 _(B5G5R5X1_UNORM , A1R5G5B5, 0, C, C, C, 1, 2, 1, 0, x, NONE, ____), 222 _(B5G5R5A1_UNORM , A1R5G5B5, 0, C, C, C, C, 2, 1, 0, 3, NONE, ____), 223 _(B4G4R4X4_UNORM , A4R4G4B4, 0, C, C, C, 1, 2, 1, 0, x, NONE, ____), 224 _(B4G4R4A4_UNORM , A4R4G4B4, 0, C, C, C, C, 2, 1, 0, 3, NONE, ____), 225 _(B5G6R5_UNORM , R5G6B5 , 0, C, C, C, 1, 2, 1, 0, x, NONE, ____), 226 _(BGRX8888_UNORM , A8R8G8B8, 0, C, C, C, 1, 2, 1, 0, x, NONE, ____), 227 _(BGRX8888_SRGB , A8R8G8B8, 0, C, C, C, 1, 2, 1, 0, x, SRGB, ____), 228 _(BGRA8888_UNORM , A8R8G8B8, 0, C, C, C, C, 2, 1, 0, 3, NONE, ____), 229 _(BGRA8888_SRGB , A8R8G8B8, 0, C, C, C, C, 2, 1, 0, 3, SRGB, ____), 230 _(RGBA8888_SNORM , A8R8G8B8, 0, C, C, C, C, 0, 1, 2, 3, NONE, SSSS), 231 _(DXT1_RGB , DXT1 , 0, C, C, C, 1, 2, 1, 0, x, NONE, ____), 232 _(DXT1_SRGB , DXT1 , 0, C, C, C, 1, 2, 1, 0, x, SRGB, ____), 233 _(DXT1_RGBA , DXT1 , 0, C, C, C, C, 2, 1, 0, 3, NONE, ____), 234 _(DXT1_SRGBA , DXT1 , 0, C, C, C, C, 2, 1, 0, 3, SRGB, ____), 235 _(DXT3_RGBA , DXT3 , 0, C, C, C, C, 2, 1, 0, 3, NONE, ____), 236 _(DXT3_SRGBA , DXT3 , 0, C, C, C, C, 2, 1, 0, 3, SRGB, ____), 237 _(DXT5_RGBA , DXT5 , 0, C, C, C, C, 2, 1, 0, 3, NONE, ____), 238 _(DXT5_SRGBA , DXT5 , 0, C, C, C, C, 2, 1, 0, 3, SRGB, ____), 239 _(L8A8_UNORM , A8L8 , 0, C, C, C, C, 0, 0, 0, 3, NONE, ____), 240 _(L8A8_SRGB , A8L8 , 0, C, C, C, C, 0, 0, 0, 3, SRGB, ____), 241 _(R8G8_UNORM , A8L8 , 0, C, C, 0, 1, 0, 3, x, x, NONE, ____), 242 _(R8G8_SNORM , A8L8 , 0, C, C, 0, 1, 0, 3, x, x, NONE, SSSS), 243 _(Z16_UNORM , Z16 , 0, C, C, C, 1, 3, 3, 3, x, NONE, ____), 244 _(X8Z24_UNORM , Z24 , 0, C, C, C, 1, 3, 3, 3, x, NONE, ____), 245 _(S8_UINT_Z24_UNORM , Z24 , 0, C, C, C, 1, 3, 3, 3, x, NONE, ____), 246 _(L16_UNORM , A16 , 0, C, C, C, 1, 1, 1, 1, 1, NONE, ____), 247 _(L16_SNORM , A16 , 0, C, C, C, 1, 1, 1, 1, 1, NONE, SSSS), 248 _(I16_UNORM , A16 , 0, C, C, C, C, 1, 1, 1, 1, NONE, ____), 249 _(I16_SNORM , A16 , 0, C, C, C, C, 1, 1, 1, 1, NONE, SSSS), 250 _(A16_UNORM , A16 , 0, 0, 0, 0, C, 1, 1, 1, 1, NONE, ____), 251 _(A16_SNORM , A16 , 0, 0, 0, 0, C, 1, 1, 1, 1, NONE, SSSS), 252 _(R16_UNORM , A16 , 0, C, 0, 0, 1, 1, 1, 1, 1, NONE, ____), 253 _(R16_SNORM , A16 , 0, C, 0, 0, 1, 1, 1, 1, 1, NONE, SSSS), 254 _(R16G16_FLOAT , RG16F , 0, C, C, 0, 1, 2, 1, 0, 3, NONE, ____), 255 _(R16G16B16A16_FLOAT, RGBA16F , 0, C, C, C, C, 2, 1, 0, 3, NONE, ____), 256 _(R32_FLOAT , R32F , 0, C, 0, 0, 1, 2, 1, 0, 3, NONE, ____), 257 _(R32G32B32A32_FLOAT, RGBA32F , 0, C, C, C, C, 2, 1, 0, 3, NONE, ____), 258 }; 259 #undef _ 260