• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 _D__ PIPE_BIND_SCANOUT | PIPE_BIND_DISPLAY_TARGET | _B__
54 #define _Z__ PIPE_BIND_DEPTH_STENCIL
55 #define __V_ PIPE_BIND_VERTEX_BUFFER
56 #define SR__ (S___ | _R__)
57 #define SB__ (S___ | _B__)
58 #define SD__ (S___ | _D__)
59 #define SZ__ (S___ | _Z__)
60 #define S_V_ (S___ | __V_)
61 #define SRV_ (SR__ | __V_)
62 #define SBV_ (SB__ | __V_)
63 
64 #define _(a,b) [PIPE_FORMAT_##a] = {                                           \
65    .bindings = (b),                                                            \
66 }
67 const struct nv30_format_info
68 nv30_format_info_table[PIPE_FORMAT_COUNT] = {
69    _(L8_UNORM            , S___),
70    _(L8_SNORM            , S___),
71    _(L8_SRGB             , S___),
72    _(I8_UNORM            , S___),
73    _(I8_SNORM            , S___),
74    _(A8_UNORM            , S___),
75    _(A8_SNORM            , S___),
76    _(R8_UNORM            , S_V_),
77    _(R8_SNORM            , S___),
78    _(B5G5R5X1_UNORM      , SD__),
79    _(B5G5R5A1_UNORM      , S___),
80    _(B4G4R4X4_UNORM      , S___),
81    _(B4G4R4A4_UNORM      , S___),
82    _(B5G6R5_UNORM        , SD__),
83    _(BGRX8888_UNORM      , SD__),
84    _(BGRX8888_SRGB       , S___),
85    _(BGRA8888_UNORM      , SD__),
86    _(BGRA8888_SRGB       , S___),
87    _(R8G8B8A8_UNORM      , __V_),
88    _(RGBA8888_SNORM      , S___),
89    _(DXT1_RGB            , S___),
90    _(DXT1_SRGB           , S___),
91    _(DXT1_RGBA           , S___),
92    _(DXT1_SRGBA          , S___),
93    _(DXT3_RGBA           , S___),
94    _(DXT3_SRGBA          , S___),
95    _(DXT5_RGBA           , S___),
96    _(DXT5_SRGBA          , S___),
97    _(L8A8_UNORM          , S___),
98    _(L8A8_SRGB           , S___),
99    _(R8G8_UNORM          , S_V_),
100    _(R8G8_SNORM          , S___),
101    _(R8G8B8_UNORM        , __V_),
102    _(Z16_UNORM           , SZ__),
103    _(X8Z24_UNORM         , SZ__),
104    _(S8_UINT_Z24_UNORM   , SZ__),
105    _(L16_UNORM           , S___),
106    _(L16_SNORM           , S___),
107    _(I16_UNORM           , S___),
108    _(I16_SNORM           , S___),
109    _(A16_UNORM           , S___),
110    _(A16_SNORM           , S___),
111    _(R16_UNORM           , S___),
112    _(R16_SNORM           , S_V_),
113    _(R16G16_SNORM        , __V_),
114    _(R16G16B16_SNORM     , __V_),
115    _(R16G16B16A16_SNORM  , __V_),
116    _(R8G8B8A8_USCALED    , __V_),
117    _(R16_FLOAT           , __V_),
118    _(R16G16_FLOAT        , __V_), //S_V_),
119    _(R16G16B16_FLOAT     , __V_),
120    _(R16G16B16A16_FLOAT  , __V_), //SBV_),
121    _(R16_SSCALED         , __V_),
122    _(R16G16_SSCALED      , __V_),
123    _(R16G16B16_SSCALED   , __V_),
124    _(R16G16B16A16_SSCALED, __V_),
125    _(R32_FLOAT           , __V_), //SRV_),
126    _(R32G32_FLOAT        , __V_),
127    _(R32G32B32_FLOAT     , __V_),
128    _(R32G32B32A32_FLOAT  , __V_), //SRV_),
129 };
130 #undef _
131 #undef ____
132 
133 #define R_(a,b) [PIPE_FORMAT_##a] = {                                          \
134    .hw = NV30_3D_RT_FORMAT_COLOR_##b,                                          \
135 }
136 #define Z_(a,b) [PIPE_FORMAT_##a] = {                                          \
137    .hw = NV30_3D_RT_FORMAT_ZETA_##b,                                           \
138 }
139 const struct nv30_format
140 nv30_format_table[PIPE_FORMAT_COUNT] = {
141    R_(B5G5R5X1_UNORM    , X1R5G5B5          ),
142    R_(B5G6R5_UNORM      , R5G6B5            ),
143    R_(BGRX8888_UNORM    , X8R8G8B8          ),
144    R_(BGRA8888_UNORM    , A8R8G8B8          ),
145    Z_(Z16_UNORM         , Z16               ),
146    Z_(X8Z24_UNORM       , Z24S8             ),
147    Z_(S8_UINT_Z24_UNORM , Z24S8             ),
148    R_(R16G16B16A16_FLOAT, A16B16G16R16_FLOAT),
149    R_(R32G32B32A32_FLOAT, A32B32G32R32_FLOAT),
150    R_(R32_FLOAT         , R32_FLOAT         ),
151 };
152 
153 #define _(a,b,c) [PIPE_FORMAT_##a] = {                                         \
154    .hw = NV30_3D_VTXFMT_TYPE_##b | ((c) << NV30_3D_VTXFMT_SIZE__SHIFT)         \
155 }
156 const struct nv30_vtxfmt
157 nv30_vtxfmt_table[PIPE_FORMAT_COUNT] = {
158    _(R8_UNORM            , U8_UNORM   , 1),
159    _(R8G8_UNORM          , U8_UNORM   , 2),
160    _(R8G8B8_UNORM        , U8_UNORM   , 3),
161    _(R8G8B8A8_UNORM      , U8_UNORM   , 4),
162    _(R8G8B8A8_USCALED    , U8_USCALED , 4),
163    _(R16_SNORM           , V16_SNORM  , 1),
164    _(R16G16_SNORM        , V16_SNORM  , 2),
165    _(R16G16B16_SNORM     , V16_SNORM  , 3),
166    _(R16G16B16A16_SNORM  , V16_SNORM  , 4),
167    _(R16_SSCALED         , V16_SSCALED, 1),
168    _(R16G16_SSCALED      , V16_SSCALED, 2),
169    _(R16G16B16_SSCALED   , V16_SSCALED, 3),
170    _(R16G16B16A16_SSCALED, V16_SSCALED, 4),
171    _(R16_FLOAT           , V16_FLOAT  , 1),
172    _(R16G16_FLOAT        , V16_FLOAT  , 2),
173    _(R16G16B16_FLOAT     , V16_FLOAT  , 3),
174    _(R16G16B16A16_FLOAT  , V16_FLOAT  , 4),
175    _(R32_FLOAT           , V32_FLOAT  , 1),
176    _(R32G32_FLOAT        , V32_FLOAT  , 2),
177    _(R32G32B32_FLOAT     , V32_FLOAT  , 3),
178    _(R32G32B32A32_FLOAT  , V32_FLOAT  , 4),
179 };
180 #undef _
181 
182 #define SWZ_OUT_0 0
183 #define SWZ_OUT_1 1
184 #define SWZ_OUT_C 2
185 
186 #define SWZ_SRC_0 3
187 #define SWZ_SRC_1 2
188 #define SWZ_SRC_2 1
189 #define SWZ_SRC_3 0
190 #define SWZ_SRC_x 0
191 
192 #define NONE 0x00000000
193 #define SRGB 0x00700000
194 
195 #define ____ 0x00000000
196 #define SSSS 0xf0000000
197 
198 #define _(a,b,c,d,e,f,g,h,i,j,k,l,m) [PIPE_FORMAT_##a] = {                     \
199    .nv30 = NV30_3D_TEX_FORMAT_FORMAT_##b,                                      \
200    .nv30_rect = NV30_3D_TEX_FORMAT_FORMAT_##b##_RECT,                          \
201    .nv40 = NV40_3D_TEX_FORMAT_FORMAT_##b,                                      \
202    .swz[0] = { SWZ_OUT_##d, SWZ_SRC_##h },                                     \
203    .swz[1] = { SWZ_OUT_##e, SWZ_SRC_##i },                                     \
204    .swz[2] = { SWZ_OUT_##f, SWZ_SRC_##j },                                     \
205    .swz[3] = { SWZ_OUT_##g, SWZ_SRC_##k },                                     \
206    .swz[4] = { SWZ_OUT_0, SWZ_SRC_x },                                         \
207    .swz[5] = { SWZ_OUT_1, SWZ_SRC_x },                                         \
208    .swizzle = (c) * 0x00010000,                                                \
209    .wrap =  (l),                                                               \
210    .filter = (m),                                                              \
211 }
212 const struct nv30_texfmt
213 nv30_texfmt_table[PIPE_FORMAT_COUNT] = {
214    _(L8_UNORM          , L8      , 0, C, C, C, 1, 0, 0, 0, x, NONE, ____),
215    _(L8_SNORM          , L8      , 0, C, C, C, 1, 0, 0, 0, x, NONE, SSSS),
216    _(L8_SRGB           , L8      , 0, C, C, C, 1, 0, 0, 0, x, SRGB, ____),
217    _(I8_UNORM          , L8      , 0, C, C, C, C, 0, 0, 0, 0, NONE, ____),
218    _(I8_SNORM          , L8      , 0, C, C, C, C, 0, 0, 0, 0, NONE, SSSS),
219    _(A8_UNORM          , L8      , 0, 0, 0, 0, C, x, x, x, 0, NONE, ____),
220    _(A8_SNORM          , L8      , 0, 0, 0, 0, C, x, x, x, 0, NONE, SSSS),
221    _(R8_UNORM          , L8      , 0, C, 0, 0, 1, 0, x, x, x, NONE, ____),
222    _(R8_SNORM          , L8      , 0, C, 0, 0, 1, 0, x, x, x, NONE, SSSS),
223    _(B5G5R5X1_UNORM    , A1R5G5B5, 0, C, C, C, 1, 2, 1, 0, x, NONE, ____),
224    _(B5G5R5A1_UNORM    , A1R5G5B5, 0, C, C, C, C, 2, 1, 0, 3, NONE, ____),
225    _(B4G4R4X4_UNORM    , A4R4G4B4, 0, C, C, C, 1, 2, 1, 0, x, NONE, ____),
226    _(B4G4R4A4_UNORM    , A4R4G4B4, 0, C, C, C, C, 2, 1, 0, 3, NONE, ____),
227    _(B5G6R5_UNORM      , R5G6B5  , 0, C, C, C, 1, 2, 1, 0, x, NONE, ____),
228    _(BGRX8888_UNORM    , A8R8G8B8, 0, C, C, C, 1, 2, 1, 0, x, NONE, ____),
229    _(BGRX8888_SRGB     , A8R8G8B8, 0, C, C, C, 1, 2, 1, 0, x, SRGB, ____),
230    _(BGRA8888_UNORM    , A8R8G8B8, 0, C, C, C, C, 2, 1, 0, 3, NONE, ____),
231    _(BGRA8888_SRGB     , A8R8G8B8, 0, C, C, C, C, 2, 1, 0, 3, SRGB, ____),
232    _(RGBA8888_SNORM    , A8R8G8B8, 0, C, C, C, C, 0, 1, 2, 3, NONE, SSSS),
233    _(DXT1_RGB          , DXT1    , 0, C, C, C, 1, 2, 1, 0, x, NONE, ____),
234    _(DXT1_SRGB         , DXT1    , 0, C, C, C, 1, 2, 1, 0, x, SRGB, ____),
235    _(DXT1_RGBA         , DXT1    , 0, C, C, C, C, 2, 1, 0, 3, NONE, ____),
236    _(DXT1_SRGBA        , DXT1    , 0, C, C, C, C, 2, 1, 0, 3, SRGB, ____),
237    _(DXT3_RGBA         , DXT3    , 0, C, C, C, C, 2, 1, 0, 3, NONE, ____),
238    _(DXT3_SRGBA        , DXT3    , 0, C, C, C, C, 2, 1, 0, 3, SRGB, ____),
239    _(DXT5_RGBA         , DXT5    , 0, C, C, C, C, 2, 1, 0, 3, NONE, ____),
240    _(DXT5_SRGBA        , DXT5    , 0, C, C, C, C, 2, 1, 0, 3, SRGB, ____),
241    _(L8A8_UNORM        , A8L8    , 0, C, C, C, C, 0, 0, 0, 3, NONE, ____),
242    _(L8A8_SRGB         , A8L8    , 0, C, C, C, C, 0, 0, 0, 3, SRGB, ____),
243    _(R8G8_UNORM        , A8L8    , 0, C, C, 0, 1, 0, 3, x, x, NONE, ____),
244    _(R8G8_SNORM        , A8L8    , 0, C, C, 0, 1, 0, 3, x, x, NONE, SSSS),
245    _(Z16_UNORM         , Z16     , 0, C, C, C, 1, 3, 3, 3, x, NONE, ____),
246    _(X8Z24_UNORM       , Z24     , 0, C, C, C, 1, 3, 3, 3, x, NONE, ____),
247    _(S8_UINT_Z24_UNORM , Z24     , 0, C, C, C, 1, 3, 3, 3, x, NONE, ____),
248    _(L16_UNORM         , A16     , 0, C, C, C, 1, 1, 1, 1, 1, NONE, ____),
249    _(L16_SNORM         , A16     , 0, C, C, C, 1, 1, 1, 1, 1, NONE, SSSS),
250    _(I16_UNORM         , A16     , 0, C, C, C, C, 1, 1, 1, 1, NONE, ____),
251    _(I16_SNORM         , A16     , 0, C, C, C, C, 1, 1, 1, 1, NONE, SSSS),
252    _(A16_UNORM         , A16     , 0, 0, 0, 0, C, 1, 1, 1, 1, NONE, ____),
253    _(A16_SNORM         , A16     , 0, 0, 0, 0, C, 1, 1, 1, 1, NONE, SSSS),
254    _(R16_UNORM         , A16     , 0, C, 0, 0, 1, 1, 1, 1, 1, NONE, ____),
255    _(R16_SNORM         , A16     , 0, C, 0, 0, 1, 1, 1, 1, 1, NONE, SSSS),
256    _(R16G16_FLOAT      , RG16F   , 0, C, C, 0, 1, 2, 1, 0, 3, NONE, ____),
257    _(R16G16B16A16_FLOAT, RGBA16F , 0, C, C, C, C, 2, 1, 0, 3, NONE, ____),
258    _(R32_FLOAT         , R32F    , 0, C, 0, 0, 1, 2, 1, 0, 3, NONE, ____),
259    _(R32G32B32A32_FLOAT, RGBA32F , 0, C, C, C, C, 2, 1, 0, 3, NONE, ____),
260 };
261 #undef _
262