1 /*---------------------------------------------------------------------------*
2   Project:  Horizon
3   File:     gr_Vertex.h
4   Copyright (C)2010 Nintendo Co., Ltd.  All rights reserved.
5   These coded instructions, statements, and computer programs contain
6   proprietary information of Nintendo of America Inc. and/or Nintendo
7   Company Ltd., and are protected by Federal copyright law. They may
8   not be disclosed to third parties or copied or duplicated in any form,
9   in whole or in part, without the prior written consent of Nintendo.
10   $Rev: 33970 $
11  *---------------------------------------------------------------------------
12 
13 
14 */
15 
16 #ifndef NN_GR_VERTEX_H_
17 #define NN_GR_VERTEX_H_
18 
19 #include <nn/gr/CTR/gr_Prefix.h>
20 #include <nn/gr/CTR/gr_BindSymbol.h>
21 
22 namespace nn
23 {
24     namespace gr
25     {
26         namespace CTR
27         {
28 
29             /* Please see man pages for details
30 
31              */
32             class Vertex
33             {
34             public :
35                 //
36                 static const u32 VERTEX_ATTRIBUTE_MAX           = 12;
37 
38                 //
39                 static const u32 VERTEX_ATTRIBUTE_DIMENSION_MAX = 4;
40 
41                 //
42                 static const u32 VERTEX_ENABLE_COMMAND_MAX = 12 + VERTEX_ATTRIBUTE_MAX * 6;
43 
44                 /* Please see man pages for details
45 
46                 */
47                 class InterleaveInfo
48                 {
49                 public:
50                     /* Please see man pages for details
51 
52                     */
InterleaveInfo()53                     InterleaveInfo()
54                     {
55                         dataNum = 0;
56 
57                         for ( u32 index = 0; index < VERTEX_ATTRIBUTE_MAX; index++ )
58                         {
59                             // Initialize to 0x0.
60                             dataType[ index ] = PICA_DATA_SIZE_1_BYTE;
61                         }
62 
63                         for ( u32 index = 0; index < VERTEX_ATTRIBUTE_MAX; index++ )
64                         {
65                             // Initialize to NULL.
66                             symbol[ index ] = NULL;
67                         }
68                     }
69 
70                     /* Please see man pages for details
71 
72                     */
73                     u8                            dataNum;
74                     NN_PADDING3;
75 
76                     /* Please see man pages for details
77 
78 
79                     */
80                     PicaDataVertexAttrType       dataType[ VERTEX_ATTRIBUTE_MAX ];
81 
82                     /* Please see man pages for details
83 
84 
85                     */
86                     const nn::gr::CTR::BindSymbolVSInput* symbol[ VERTEX_ATTRIBUTE_MAX ];
87                 };
88 
89             public :
90                 /* Please see man pages for details
91 
92                  */
93                 class IndexStream
94                 {
95                 public :
96                     /* Please see man pages for details
97 
98                     */
IndexStream()99                     IndexStream() :
100                     physicalAddr( 0 ),
101                     drawVtxNum( 0 ),
102                     isUnsignedByte( false )
103                     {
104                     }
105 
106                     /* Please see man pages for details
107 
108                     */
109                     uptr  physicalAddr;
110 
111                     /* Please see man pages for details
112 
113                     */
114                     u32  drawVtxNum;
115 
116                     /* Please see man pages for details
117 
118                     */
119                     bool isUnsignedByte;
120                     NN_PADDING3;
121                 };
122 
123             public: // Attribute settings
124                 /* Please see man pages for details
125 
126 
127 
128 
129 
130 */
131                 void EnableAttrAsArray( const nn::gr::CTR::BindSymbolVSInput& symbol, const uptr physical_addr, const PicaDataVertexAttrType type );
132 
133                 /* Please see man pages for details
134 
135 
136 
137 
138 
139 
140 
141 
142 */
143                 void EnableAttrAsConst( const nn::gr::CTR::BindSymbolVSInput& symbol, const u8 dimension, const f32 param[] );
144 
145                 /* Please see man pages for details
146 
147 
148 
149 
150 */
151                 void EnableInterleavedArray( const nn::gr::CTR::Vertex::InterleaveInfo& interleave_info, const uptr physical_addr );
152 
153             public : // Generate commands from settings
154                 /* Please see man pages for details
155 
156 
157 
158 
159 
160                  */
161 
MakeEnableAttrCommand(bit32 * command)162                 bit32* MakeEnableAttrCommand( bit32* command ) const
163                 {
164                     if ( m_CmdCacheVertexNum == 0 )
165                     {
166                         // Generate cache
167                         m_CmdCacheVertexNum = MakeEnableAttrCommand_( m_CmdCacheVertex ) - m_CmdCacheVertex;
168                     }
169 
170                     std::memcpy( command, m_CmdCacheVertex, m_CmdCacheVertexNum * sizeof( bit32 ) );
171                     return command + m_CmdCacheVertexNum;
172                 }
173 
174                 /* Please see man pages for details
175 
176 
177 
178 
179 
180 
181 */
182                 bit32* MakeDrawCommand( bit32* command, const IndexStream& index_stream ) const;
183 
184                 /* Please see man pages for details
185 
186 
187 
188 
189 
190                  */
MakeDisableAttrCommand(bit32 * command)191                 bit32* MakeDisableAttrCommand( bit32* command ) const
192                 {
193                     for ( int index = 0; index < VERTEX_ATTRIBUTE_MAX; ++index )
194                     {
195                         // Generate command that invalidates the valid load array
196                         if ( m_LoadArray[ index ].IsEnable() )
197                         {
198                             // 0x203 + 3N, generate command that invalidates load array address offset
199                             *command++ = 0;
200                             *command++ =
201                                 PICA_CMD_HEADER_BURSTSEQ( PICA_REG_LOAD_ARRAY0_ATTR_OFFSET + 3 * index, 0x3 );
202                             // 0x204 + 3N, generate command that invalidates load array elements 0-7
203                             *command++ = 0;
204                             // 0x205 + 3N [15:0] Generate command that invalidates load array elements 8 through 11
205                             //            [23:16] generate a command that invalidates the number of bytes in one vertex in the load array
206                             //            [31:28] generate command that invalidates load array element count
207                             *command++ = 0;
208                         }
209                         else
210                         {
211                             *command++ = 0;
212                             // 0x205 + 3N [23:16] generate command that invalidates the number of bytes in one vertex in the load array
213                             //            [31:28] generate command that invalidates load array element count
214                             *command++ =
215                                 PICA_CMD_HEADER_SINGLE( PICA_REG_LOAD_ARRAY0_ELEMENT1 + 3 * index );
216                         }
217 
218                         // Generate command that invalidates the enabled, fixed vertex attributes
219                         if ( m_AttrConst[ index ].IsEnable() )
220                         {
221                             *command++ = index;
222                             *command++ = PICA_CMD_HEADER_BURSTSEQ( PICA_REG_VS_FIXED_ATTR, 4 );
223                             *command++ = 0;
224                             *command++ = 0;
225                             *command++ = 0;
226                             // Padding
227                             *command++ = 0;
228                         }
229                     }
230 
231                     return command;
232                 }
233 
234                 /* Please see man pages for details
235 
236 
237 
238 
239 
240                  */
MakeDisableCommand(bit32 * command)241                 static bit32* MakeDisableCommand( bit32* command )
242                 {
243                     *command++ = 0;
244                     *command++ = PICA_CMD_HEADER_SINGLE( 0x201 );
245 
246                     *command++ = 0;
247                     *command++ = PICA_CMD_HEADER_SINGLE( 0x202 );
248 
249                     // Generate command that invalidates all of 0x203 + 3N, 0x204 + 3N, and 0x205 + 3N (N = 0-11)
250                     const int size = ( 2 + 3 * VERTEX_ATTRIBUTE_MAX ) * sizeof( bit32 );
251                     std::memset( command, 0, size );
252                     command[ 1 ] = PICA_CMD_HEADER_BURSTSEQ( PICA_REG_LOAD_ARRAY0_ATTR_OFFSET, VERTEX_ATTRIBUTE_MAX * 3 );
253                     command += size / sizeof( bit32 );
254 
255                     for ( int i = 0; i < VERTEX_ATTRIBUTE_MAX; ++i )
256                     {
257                         // 0x232
258                         *command++ = i;
259                         *command++ = PICA_CMD_HEADER_BURSTSEQ( PICA_REG_VS_FIXED_ATTR, 4 );
260 
261                         // 0x233
262                         *command++ = 0;
263                         // 0x234
264                         *command++ = 0;
265 
266                         // 0x235
267                         *command++ = 0;
268                         // Padding
269                         *command++ = 0;
270                     }
271 
272                     return command;
273                 }
274 
275             public : // Invalidate
276 
277                 /* Please see man pages for details
278 
279 
280 
281                  */
DisableAttr(const nn::gr::CTR::BindSymbolVSInput & symbol)282                 void DisableAttr( const nn::gr::CTR::BindSymbolVSInput& symbol )
283                 {
284                     DisableAttr_( symbol.start );
285                 }
286 
287                 /* Please see man pages for details
288 
289                  */
DisableAll()290                 void DisableAll()
291                 {
292                     m_CmdCacheVertexNum = 0;
293 
294                     for ( u32 index = 0; index < VERTEX_ENABLE_COMMAND_MAX; index++ )
295                     {
296                         m_CmdCacheVertex[ index ] = 0;
297                     }
298 
299                     for ( u32 index = 0; index < VERTEX_ATTRIBUTE_MAX; index++ )
300                     {
301                         m_IsEnableReg[ index ] = false;
302                         m_LoadArray[ index ].DisableAll();
303                         m_AttrConst[ index ].DisableAll();
304                     }
305                 }
306 
307             public :
308                 /* Please see man pages for details
309 
310                  */
Vertex()311                 explicit Vertex()
312                 {
313                     DisableAll();
314                 }
315 
316             protected :
317                 /* Please see man pages for details
318 
319                  */
320                 class LoadArray
321                 {
322                 public:
LoadArray()323                     LoadArray() :
324                     physicalAddr( 0 )
325                     {
326                     }
327 
328                     /* Please see man pages for details
329 
330                     */
331                     uptr physicalAddr;
332 
333                     /* Please see man pages for details
334 
335 
336                     */
337                     PicaDataVertexAttrType type[ VERTEX_ATTRIBUTE_MAX ];
338 
339                     /* Please see man pages for details
340 
341 
342 
343                     */
344                     u32 byte[ VERTEX_ATTRIBUTE_MAX ];
345 
346                     /* Please see man pages for details
347 
348 
349 
350                     */
351                     s32 bind[ VERTEX_ATTRIBUTE_MAX ];
352 
353                     /* Please see man pages for details
354 
355 
356 
357 */
IsEnable()358                     bool IsEnable() const { return physicalAddr != 0; }
359 
360                     /* Please see man pages for details
361 
362                     */
363                     void CheckDisable();
364 
365                     /* Please see man pages for details
366 
367                     */
368                     void DisableAll();
369                 };
370 
371                 /* Please see man pages for details
372 
373                  */
374                 class AttrConst
375                 {
376                 public :
377                     /* Please see man pages for details
378 
379                     */
AttrConst()380                     AttrConst() :
381                     dimension( 0 )
382                     {
383                     }
384 
385                     /* Please see man pages for details
386 
387 
388                     */
389                     u8 dimension;
390                     NN_PADDING3;
391 
392                     /* Please see man pages for details
393 
394 
395                     */
396                     f32 param[ VERTEX_ATTRIBUTE_DIMENSION_MAX ];
397 
398                     /* Please see man pages for details
399 
400                     */
IsEnable()401                     bool IsEnable() const { return dimension != 0; }
402 
403                     /* Please see man pages for details
404 
405                     */
Disable()406                     void Disable()
407                     {
408                         dimension = 0;
409                     }
410 
411                     /* Please see man pages for details
412 
413                     */
DisableAll()414                     void DisableAll()
415                     {
416                         dimension = 0;
417 
418                         for ( u32 index = 0; index < VERTEX_ATTRIBUTE_DIMENSION_MAX; index++ )
419                         {
420                             param[ index ] = 0;
421                         }
422                     }
423                 };
424 
425             protected :
426                 /* Please see man pages for details
427 
428 
429 
430 */
431                 void DisableAttr_( const bit32 bind_reg );
432 
433                 /* Please see man pages for details
434 
435 
436 
437 
438 
439 */
440                 bit32* MakeEnableAttrCommand_( bit32* command ) const;
441 
442             protected :
443                 mutable u32 m_CmdCacheVertexNum;
444                 mutable bit32 m_CmdCacheVertex[ VERTEX_ENABLE_COMMAND_MAX ];
445 
446                 bool        m_IsEnableReg[ VERTEX_ATTRIBUTE_MAX ];
447 
448                 LoadArray   m_LoadArray[ VERTEX_ATTRIBUTE_MAX ];
449                 AttrConst   m_AttrConst[ VERTEX_ATTRIBUTE_MAX ];
450             };
451 
452         }  // namespace CTR
453     }  // namespace gr
454 } // namespace nn
455 
456 
457 #endif // NN_GR_VERTEX_H_
458