14a49301eSmrg/**************************************************************************
24a49301eSmrg *
3af69d88dSmrg * Copyright 2007 VMware, Inc.
44a49301eSmrg * All Rights Reserved.
54a49301eSmrg *
64a49301eSmrg * Permission is hereby granted, free of charge, to any person obtaining a
74a49301eSmrg * copy of this software and associated documentation files (the
84a49301eSmrg * "Software"), to deal in the Software without restriction, including
94a49301eSmrg * without limitation the rights to use, copy, modify, merge, publish,
104a49301eSmrg * distribute, sub license, and/or sell copies of the Software, and to
114a49301eSmrg * permit persons to whom the Software is furnished to do so, subject to
124a49301eSmrg * the following conditions:
134a49301eSmrg *
144a49301eSmrg * The above copyright notice and this permission notice (including the
154a49301eSmrg * next paragraph) shall be included in all copies or substantial portions
164a49301eSmrg * of the Software.
174a49301eSmrg *
184a49301eSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
194a49301eSmrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
204a49301eSmrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21af69d88dSmrg * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
224a49301eSmrg * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
234a49301eSmrg * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
244a49301eSmrg * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
254a49301eSmrg *
264a49301eSmrg **************************************************************************/
274a49301eSmrg
284a49301eSmrg#include "util/u_debug.h"
293464ebd5Sriastradh#include "pipe/p_format.h"
304a49301eSmrg#include "pipe/p_shader_tokens.h"
314a49301eSmrg#include "tgsi_build.h"
324a49301eSmrg#include "tgsi_parse.h"
334a49301eSmrg
344a49301eSmrg
354a49301eSmrg/*
364a49301eSmrg * header
374a49301eSmrg */
384a49301eSmrg
394a49301eSmrgstruct tgsi_header
404a49301eSmrgtgsi_build_header( void )
414a49301eSmrg{
424a49301eSmrg   struct tgsi_header header;
434a49301eSmrg
444a49301eSmrg   header.HeaderSize = 1;
454a49301eSmrg   header.BodySize = 0;
464a49301eSmrg
474a49301eSmrg   return header;
484a49301eSmrg}
494a49301eSmrg
504a49301eSmrgstatic void
514a49301eSmrgheader_headersize_grow( struct tgsi_header *header )
524a49301eSmrg{
534a49301eSmrg   assert( header->HeaderSize < 0xFF );
544a49301eSmrg   assert( header->BodySize == 0 );
554a49301eSmrg
564a49301eSmrg   header->HeaderSize++;
574a49301eSmrg}
584a49301eSmrg
594a49301eSmrgstatic void
604a49301eSmrgheader_bodysize_grow( struct tgsi_header *header )
614a49301eSmrg{
624a49301eSmrg   assert( header->BodySize < 0xFFFFFF );
634a49301eSmrg
644a49301eSmrg   header->BodySize++;
654a49301eSmrg}
664a49301eSmrg
674a49301eSmrgstruct tgsi_processor
684a49301eSmrgtgsi_build_processor(
694a49301eSmrg   unsigned type,
704a49301eSmrg   struct tgsi_header *header )
714a49301eSmrg{
724a49301eSmrg   struct tgsi_processor processor;
734a49301eSmrg
744a49301eSmrg   processor.Processor = type;
753464ebd5Sriastradh   processor.Padding = 0;
764a49301eSmrg
774a49301eSmrg   header_headersize_grow( header );
784a49301eSmrg
794a49301eSmrg   return processor;
804a49301eSmrg}
814a49301eSmrg
824a49301eSmrg/*
834a49301eSmrg * declaration
844a49301eSmrg */
854a49301eSmrg
863464ebd5Sriastradhstatic void
873464ebd5Sriastradhdeclaration_grow(
883464ebd5Sriastradh   struct tgsi_declaration *declaration,
893464ebd5Sriastradh   struct tgsi_header *header )
903464ebd5Sriastradh{
913464ebd5Sriastradh   assert( declaration->NrTokens < 0xFF );
923464ebd5Sriastradh
933464ebd5Sriastradh   declaration->NrTokens++;
943464ebd5Sriastradh
953464ebd5Sriastradh   header_bodysize_grow( header );
963464ebd5Sriastradh}
973464ebd5Sriastradh
983464ebd5Sriastradhstatic struct tgsi_declaration
994a49301eSmrgtgsi_default_declaration( void )
1004a49301eSmrg{
1014a49301eSmrg   struct tgsi_declaration declaration;
1024a49301eSmrg
1034a49301eSmrg   declaration.Type = TGSI_TOKEN_TYPE_DECLARATION;
1044a49301eSmrg   declaration.NrTokens = 1;
1054a49301eSmrg   declaration.File = TGSI_FILE_NULL;
1064a49301eSmrg   declaration.UsageMask = TGSI_WRITEMASK_XYZW;
107af69d88dSmrg   declaration.Interpolate = 0;
108cdc920a0Smrg   declaration.Dimension = 0;
1094a49301eSmrg   declaration.Semantic = 0;
1104a49301eSmrg   declaration.Invariant = 0;
111af69d88dSmrg   declaration.Local = 0;
112af69d88dSmrg   declaration.Array = 0;
11301e04c3fSmrg   declaration.Atomic = 0;
11401e04c3fSmrg   declaration.MemType = TGSI_MEMORY_TYPE_GLOBAL;
115af69d88dSmrg   declaration.Padding = 0;
1164a49301eSmrg
1174a49301eSmrg   return declaration;
1184a49301eSmrg}
1194a49301eSmrg
1203464ebd5Sriastradhstatic struct tgsi_declaration
1214a49301eSmrgtgsi_build_declaration(
1224a49301eSmrg   unsigned file,
1234a49301eSmrg   unsigned usage_mask,
1244a49301eSmrg   unsigned interpolate,
125cdc920a0Smrg   unsigned dimension,
1264a49301eSmrg   unsigned semantic,
1274a49301eSmrg   unsigned invariant,
128af69d88dSmrg   unsigned local,
129af69d88dSmrg   unsigned array,
13001e04c3fSmrg   unsigned atomic,
13101e04c3fSmrg   unsigned mem_type,
1324a49301eSmrg   struct tgsi_header *header )
1334a49301eSmrg{
1344a49301eSmrg   struct tgsi_declaration declaration;
1354a49301eSmrg
1364a49301eSmrg   assert( file < TGSI_FILE_COUNT );
1374a49301eSmrg   assert( interpolate < TGSI_INTERPOLATE_COUNT );
1384a49301eSmrg
1394a49301eSmrg   declaration = tgsi_default_declaration();
1404a49301eSmrg   declaration.File = file;
1414a49301eSmrg   declaration.UsageMask = usage_mask;
1424a49301eSmrg   declaration.Interpolate = interpolate;
143cdc920a0Smrg   declaration.Dimension = dimension;
1444a49301eSmrg   declaration.Semantic = semantic;
1454a49301eSmrg   declaration.Invariant = invariant;
146af69d88dSmrg   declaration.Local = local;
147af69d88dSmrg   declaration.Array = array;
14801e04c3fSmrg   declaration.Atomic = atomic;
14901e04c3fSmrg   declaration.MemType = mem_type;
1504a49301eSmrg   header_bodysize_grow( header );
1514a49301eSmrg
1524a49301eSmrg   return declaration;
1534a49301eSmrg}
1544a49301eSmrg
1553464ebd5Sriastradhstatic struct tgsi_declaration_range
1563464ebd5Sriastradhtgsi_default_declaration_range( void )
1573464ebd5Sriastradh{
1583464ebd5Sriastradh   struct tgsi_declaration_range dr;
1593464ebd5Sriastradh
1603464ebd5Sriastradh   dr.First = 0;
1613464ebd5Sriastradh   dr.Last = 0;
1623464ebd5Sriastradh
1633464ebd5Sriastradh   return dr;
1643464ebd5Sriastradh}
1653464ebd5Sriastradh
16601e04c3fSmrgstatic struct tgsi_declaration_dimension
16701e04c3fSmrgtgsi_default_declaration_dimension()
16801e04c3fSmrg{
16901e04c3fSmrg   struct tgsi_declaration_dimension dim;
17001e04c3fSmrg
17101e04c3fSmrg   dim.Index2D = 0;
1727ec681f3Smrg   dim.Padding = 0;
17301e04c3fSmrg
17401e04c3fSmrg   return dim;
17501e04c3fSmrg}
17601e04c3fSmrg
1773464ebd5Sriastradhstatic struct tgsi_declaration_range
1783464ebd5Sriastradhtgsi_build_declaration_range(
1793464ebd5Sriastradh   unsigned first,
1803464ebd5Sriastradh   unsigned last,
1814a49301eSmrg   struct tgsi_declaration *declaration,
1824a49301eSmrg   struct tgsi_header *header )
1834a49301eSmrg{
1843464ebd5Sriastradh   struct tgsi_declaration_range declaration_range;
1854a49301eSmrg
1863464ebd5Sriastradh   assert( last >= first );
1873464ebd5Sriastradh   assert( last <= 0xFFFF );
1884a49301eSmrg
1893464ebd5Sriastradh   declaration_range.First = first;
1903464ebd5Sriastradh   declaration_range.Last = last;
1913464ebd5Sriastradh
1923464ebd5Sriastradh   declaration_grow( declaration, header );
1933464ebd5Sriastradh
1943464ebd5Sriastradh   return declaration_range;
1953464ebd5Sriastradh}
1963464ebd5Sriastradh
1973464ebd5Sriastradhstatic struct tgsi_declaration_dimension
1983464ebd5Sriastradhtgsi_build_declaration_dimension(unsigned index_2d,
1993464ebd5Sriastradh                                 struct tgsi_declaration *declaration,
2003464ebd5Sriastradh                                 struct tgsi_header *header)
2013464ebd5Sriastradh{
2023464ebd5Sriastradh   struct tgsi_declaration_dimension dd;
2033464ebd5Sriastradh
2043464ebd5Sriastradh   assert(index_2d <= 0xFFFF);
2053464ebd5Sriastradh
2063464ebd5Sriastradh   dd.Index2D = index_2d;
2073464ebd5Sriastradh   dd.Padding = 0;
2083464ebd5Sriastradh
2093464ebd5Sriastradh   declaration_grow(declaration, header);
2103464ebd5Sriastradh
2113464ebd5Sriastradh   return dd;
2123464ebd5Sriastradh}
2133464ebd5Sriastradh
214af69d88dSmrgstatic struct tgsi_declaration_interp
215af69d88dSmrgtgsi_default_declaration_interp( void )
216af69d88dSmrg{
217af69d88dSmrg   struct tgsi_declaration_interp di;
218af69d88dSmrg
219af69d88dSmrg   di.Interpolate = TGSI_INTERPOLATE_CONSTANT;
220af69d88dSmrg   di.Location = TGSI_INTERPOLATE_LOC_CENTER;
221af69d88dSmrg   di.Padding = 0;
222af69d88dSmrg
223af69d88dSmrg   return di;
224af69d88dSmrg}
225af69d88dSmrg
226af69d88dSmrgstatic struct tgsi_declaration_interp
227af69d88dSmrgtgsi_build_declaration_interp(unsigned interpolate,
228af69d88dSmrg                              unsigned interpolate_location,
229af69d88dSmrg                              struct tgsi_declaration *declaration,
230af69d88dSmrg                              struct tgsi_header *header)
231af69d88dSmrg{
232af69d88dSmrg   struct tgsi_declaration_interp di;
233af69d88dSmrg
234af69d88dSmrg   di.Interpolate = interpolate;
235af69d88dSmrg   di.Location = interpolate_location;
236af69d88dSmrg   di.Padding = 0;
237af69d88dSmrg
238af69d88dSmrg   declaration_grow(declaration, header);
239af69d88dSmrg
240af69d88dSmrg   return di;
241af69d88dSmrg}
242af69d88dSmrg
2433464ebd5Sriastradhstatic struct tgsi_declaration_semantic
2443464ebd5Sriastradhtgsi_default_declaration_semantic( void )
2453464ebd5Sriastradh{
2463464ebd5Sriastradh   struct tgsi_declaration_semantic ds;
2473464ebd5Sriastradh
2483464ebd5Sriastradh   ds.Name = TGSI_SEMANTIC_POSITION;
2493464ebd5Sriastradh   ds.Index = 0;
25001e04c3fSmrg   ds.StreamX = 0;
25101e04c3fSmrg   ds.StreamY = 0;
25201e04c3fSmrg   ds.StreamZ = 0;
25301e04c3fSmrg   ds.StreamW = 0;
2543464ebd5Sriastradh
2553464ebd5Sriastradh   return ds;
2563464ebd5Sriastradh}
2573464ebd5Sriastradh
2583464ebd5Sriastradhstatic struct tgsi_declaration_semantic
2593464ebd5Sriastradhtgsi_build_declaration_semantic(
2603464ebd5Sriastradh   unsigned semantic_name,
2613464ebd5Sriastradh   unsigned semantic_index,
26201e04c3fSmrg   unsigned streamx,
26301e04c3fSmrg   unsigned streamy,
26401e04c3fSmrg   unsigned streamz,
26501e04c3fSmrg   unsigned streamw,
2663464ebd5Sriastradh   struct tgsi_declaration *declaration,
2673464ebd5Sriastradh   struct tgsi_header *header )
2683464ebd5Sriastradh{
2693464ebd5Sriastradh   struct tgsi_declaration_semantic ds;
2703464ebd5Sriastradh
2713464ebd5Sriastradh   assert( semantic_name <= TGSI_SEMANTIC_COUNT );
2723464ebd5Sriastradh   assert( semantic_index <= 0xFFFF );
2733464ebd5Sriastradh
2743464ebd5Sriastradh   ds.Name = semantic_name;
2753464ebd5Sriastradh   ds.Index = semantic_index;
27601e04c3fSmrg   ds.StreamX = streamx;
27701e04c3fSmrg   ds.StreamY = streamy;
27801e04c3fSmrg   ds.StreamZ = streamz;
27901e04c3fSmrg   ds.StreamW = streamw;
2803464ebd5Sriastradh
2813464ebd5Sriastradh   declaration_grow( declaration, header );
2823464ebd5Sriastradh
2833464ebd5Sriastradh   return ds;
2844a49301eSmrg}
2854a49301eSmrg
28601e04c3fSmrgstatic struct tgsi_declaration_image
28701e04c3fSmrgtgsi_default_declaration_image(void)
2883464ebd5Sriastradh{
28901e04c3fSmrg   struct tgsi_declaration_image di;
2903464ebd5Sriastradh
29101e04c3fSmrg   di.Resource = TGSI_TEXTURE_BUFFER;
29201e04c3fSmrg   di.Raw = 0;
29301e04c3fSmrg   di.Writable = 0;
29401e04c3fSmrg   di.Format = 0;
29501e04c3fSmrg   di.Padding = 0;
2963464ebd5Sriastradh
29701e04c3fSmrg   return di;
2983464ebd5Sriastradh}
2993464ebd5Sriastradh
30001e04c3fSmrgstatic struct tgsi_declaration_image
30101e04c3fSmrgtgsi_build_declaration_image(unsigned texture,
30201e04c3fSmrg                             unsigned format,
30301e04c3fSmrg                             unsigned raw,
30401e04c3fSmrg                             unsigned writable,
30501e04c3fSmrg                             struct tgsi_declaration *declaration,
30601e04c3fSmrg                             struct tgsi_header *header)
3073464ebd5Sriastradh{
30801e04c3fSmrg   struct tgsi_declaration_image di;
3093464ebd5Sriastradh
31001e04c3fSmrg   di = tgsi_default_declaration_image();
31101e04c3fSmrg   di.Resource = texture;
31201e04c3fSmrg   di.Format = format;
31301e04c3fSmrg   di.Raw = raw;
31401e04c3fSmrg   di.Writable = writable;
3153464ebd5Sriastradh
3163464ebd5Sriastradh   declaration_grow(declaration, header);
3173464ebd5Sriastradh
31801e04c3fSmrg   return di;
3193464ebd5Sriastradh}
3203464ebd5Sriastradh
321af69d88dSmrgstatic struct tgsi_declaration_sampler_view
322af69d88dSmrgtgsi_default_declaration_sampler_view(void)
323af69d88dSmrg{
324af69d88dSmrg   struct tgsi_declaration_sampler_view dsv;
325af69d88dSmrg
326af69d88dSmrg   dsv.Resource = TGSI_TEXTURE_BUFFER;
32701e04c3fSmrg   dsv.ReturnTypeX = TGSI_RETURN_TYPE_UNORM;
32801e04c3fSmrg   dsv.ReturnTypeY = TGSI_RETURN_TYPE_UNORM;
32901e04c3fSmrg   dsv.ReturnTypeZ = TGSI_RETURN_TYPE_UNORM;
33001e04c3fSmrg   dsv.ReturnTypeW = TGSI_RETURN_TYPE_UNORM;
331af69d88dSmrg
332af69d88dSmrg   return dsv;
333af69d88dSmrg}
334af69d88dSmrg
335af69d88dSmrgstatic struct tgsi_declaration_sampler_view
336af69d88dSmrgtgsi_build_declaration_sampler_view(unsigned texture,
337af69d88dSmrg                                    unsigned return_type_x,
338af69d88dSmrg                                    unsigned return_type_y,
339af69d88dSmrg                                    unsigned return_type_z,
340af69d88dSmrg                                    unsigned return_type_w,
341af69d88dSmrg                                    struct tgsi_declaration *declaration,
342af69d88dSmrg                                    struct tgsi_header *header)
343af69d88dSmrg{
344af69d88dSmrg   struct tgsi_declaration_sampler_view dsv;
345af69d88dSmrg
346af69d88dSmrg   dsv = tgsi_default_declaration_sampler_view();
347af69d88dSmrg   dsv.Resource = texture;
348af69d88dSmrg   dsv.ReturnTypeX = return_type_x;
349af69d88dSmrg   dsv.ReturnTypeY = return_type_y;
350af69d88dSmrg   dsv.ReturnTypeZ = return_type_z;
351af69d88dSmrg   dsv.ReturnTypeW = return_type_w;
352af69d88dSmrg
353af69d88dSmrg   declaration_grow(declaration, header);
354af69d88dSmrg
355af69d88dSmrg   return dsv;
356af69d88dSmrg}
357af69d88dSmrg
358af69d88dSmrg
359af69d88dSmrgstatic struct tgsi_declaration_array
360af69d88dSmrgtgsi_default_declaration_array( void )
361af69d88dSmrg{
362af69d88dSmrg   struct tgsi_declaration_array a;
363af69d88dSmrg
364af69d88dSmrg   a.ArrayID = 0;
365af69d88dSmrg   a.Padding = 0;
366af69d88dSmrg
367af69d88dSmrg   return a;
368af69d88dSmrg}
369af69d88dSmrg
370af69d88dSmrgstatic struct tgsi_declaration_array
371af69d88dSmrgtgsi_build_declaration_array(unsigned arrayid,
372af69d88dSmrg                             struct tgsi_declaration *declaration,
373af69d88dSmrg                             struct tgsi_header *header)
374af69d88dSmrg{
375af69d88dSmrg   struct tgsi_declaration_array da;
376af69d88dSmrg
377af69d88dSmrg   da = tgsi_default_declaration_array();
378af69d88dSmrg   da.ArrayID = arrayid;
379af69d88dSmrg
380af69d88dSmrg   declaration_grow(declaration, header);
381af69d88dSmrg
382af69d88dSmrg   return da;
383af69d88dSmrg}
3843464ebd5Sriastradh
3854a49301eSmrgstruct tgsi_full_declaration
3864a49301eSmrgtgsi_default_full_declaration( void )
3874a49301eSmrg{
3884a49301eSmrg   struct tgsi_full_declaration  full_declaration;
3894a49301eSmrg
3904a49301eSmrg   full_declaration.Declaration  = tgsi_default_declaration();
391cdc920a0Smrg   full_declaration.Range = tgsi_default_declaration_range();
39201e04c3fSmrg   full_declaration.Dim = tgsi_default_declaration_dimension();
3934a49301eSmrg   full_declaration.Semantic = tgsi_default_declaration_semantic();
394af69d88dSmrg   full_declaration.Interp = tgsi_default_declaration_interp();
39501e04c3fSmrg   full_declaration.Image = tgsi_default_declaration_image();
396af69d88dSmrg   full_declaration.SamplerView = tgsi_default_declaration_sampler_view();
397af69d88dSmrg   full_declaration.Array = tgsi_default_declaration_array();
3984a49301eSmrg
3994a49301eSmrg   return full_declaration;
4004a49301eSmrg}
4014a49301eSmrg
4024a49301eSmrgunsigned
4034a49301eSmrgtgsi_build_full_declaration(
4044a49301eSmrg   const struct tgsi_full_declaration *full_decl,
4054a49301eSmrg   struct tgsi_token *tokens,
4064a49301eSmrg   struct tgsi_header *header,
4074a49301eSmrg   unsigned maxsize )
4084a49301eSmrg{
4094a49301eSmrg   unsigned size = 0;
4104a49301eSmrg   struct tgsi_declaration *declaration;
4114a49301eSmrg   struct tgsi_declaration_range *dr;
4124a49301eSmrg
4134a49301eSmrg   if( maxsize <= size )
4143464ebd5Sriastradh      return 0;
4154a49301eSmrg   declaration = (struct tgsi_declaration *) &tokens[size];
4164a49301eSmrg   size++;
4174a49301eSmrg
4184a49301eSmrg   *declaration = tgsi_build_declaration(
4194a49301eSmrg      full_decl->Declaration.File,
4204a49301eSmrg      full_decl->Declaration.UsageMask,
4214a49301eSmrg      full_decl->Declaration.Interpolate,
422cdc920a0Smrg      full_decl->Declaration.Dimension,
4234a49301eSmrg      full_decl->Declaration.Semantic,
4244a49301eSmrg      full_decl->Declaration.Invariant,
425af69d88dSmrg      full_decl->Declaration.Local,
426af69d88dSmrg      full_decl->Declaration.Array,
42701e04c3fSmrg      full_decl->Declaration.Atomic,
42801e04c3fSmrg      full_decl->Declaration.MemType,
4294a49301eSmrg      header );
4304a49301eSmrg
4314a49301eSmrg   if (maxsize <= size)
4324a49301eSmrg      return 0;
4334a49301eSmrg   dr = (struct tgsi_declaration_range *) &tokens[size];
4344a49301eSmrg   size++;
4354a49301eSmrg
4364a49301eSmrg   *dr = tgsi_build_declaration_range(
437cdc920a0Smrg      full_decl->Range.First,
438cdc920a0Smrg      full_decl->Range.Last,
4394a49301eSmrg      declaration,
4404a49301eSmrg      header );
4414a49301eSmrg
442cdc920a0Smrg   if (full_decl->Declaration.Dimension) {
443cdc920a0Smrg      struct tgsi_declaration_dimension *dd;
444cdc920a0Smrg
445cdc920a0Smrg      if (maxsize <= size) {
446cdc920a0Smrg         return 0;
447cdc920a0Smrg      }
448cdc920a0Smrg      dd = (struct tgsi_declaration_dimension *)&tokens[size];
449cdc920a0Smrg      size++;
450cdc920a0Smrg
451cdc920a0Smrg      *dd = tgsi_build_declaration_dimension(full_decl->Dim.Index2D,
452cdc920a0Smrg                                             declaration,
453cdc920a0Smrg                                             header);
454cdc920a0Smrg   }
455cdc920a0Smrg
456af69d88dSmrg   if (full_decl->Declaration.Interpolate) {
457af69d88dSmrg      struct tgsi_declaration_interp *di;
458af69d88dSmrg
459af69d88dSmrg      if (maxsize <= size) {
460af69d88dSmrg         return 0;
461af69d88dSmrg      }
462af69d88dSmrg      di = (struct tgsi_declaration_interp *)&tokens[size];
463af69d88dSmrg      size++;
464af69d88dSmrg
465af69d88dSmrg      *di = tgsi_build_declaration_interp(full_decl->Interp.Interpolate,
466af69d88dSmrg                                          full_decl->Interp.Location,
467af69d88dSmrg                                          declaration,
468af69d88dSmrg                                          header);
469af69d88dSmrg   }
470af69d88dSmrg
4714a49301eSmrg   if( full_decl->Declaration.Semantic ) {
4724a49301eSmrg      struct tgsi_declaration_semantic *ds;
4734a49301eSmrg
4744a49301eSmrg      if( maxsize <= size )
4754a49301eSmrg         return  0;
4764a49301eSmrg      ds = (struct tgsi_declaration_semantic *) &tokens[size];
4774a49301eSmrg      size++;
4784a49301eSmrg
4794a49301eSmrg      *ds = tgsi_build_declaration_semantic(
480cdc920a0Smrg         full_decl->Semantic.Name,
481cdc920a0Smrg         full_decl->Semantic.Index,
48201e04c3fSmrg         full_decl->Semantic.StreamX,
48301e04c3fSmrg         full_decl->Semantic.StreamY,
48401e04c3fSmrg         full_decl->Semantic.StreamZ,
48501e04c3fSmrg         full_decl->Semantic.StreamW,
4864a49301eSmrg         declaration,
4874a49301eSmrg         header );
4884a49301eSmrg   }
4894a49301eSmrg
49001e04c3fSmrg   if (full_decl->Declaration.File == TGSI_FILE_IMAGE) {
49101e04c3fSmrg      struct tgsi_declaration_image *di;
4924a49301eSmrg
4933464ebd5Sriastradh      if (maxsize <= size) {
4943464ebd5Sriastradh         return  0;
4953464ebd5Sriastradh      }
49601e04c3fSmrg      di = (struct tgsi_declaration_image *)&tokens[size];
4973464ebd5Sriastradh      size++;
4984a49301eSmrg
49901e04c3fSmrg      *di = tgsi_build_declaration_image(full_decl->Image.Resource,
50001e04c3fSmrg                                         full_decl->Image.Format,
50101e04c3fSmrg                                         full_decl->Image.Raw,
50201e04c3fSmrg                                         full_decl->Image.Writable,
50301e04c3fSmrg                                         declaration,
50401e04c3fSmrg                                         header);
5053464ebd5Sriastradh   }
5064a49301eSmrg
507af69d88dSmrg   if (full_decl->Declaration.File == TGSI_FILE_SAMPLER_VIEW) {
508af69d88dSmrg      struct tgsi_declaration_sampler_view *dsv;
509af69d88dSmrg
510af69d88dSmrg      if (maxsize <= size) {
511af69d88dSmrg         return  0;
512af69d88dSmrg      }
513af69d88dSmrg      dsv = (struct tgsi_declaration_sampler_view *)&tokens[size];
514af69d88dSmrg      size++;
515af69d88dSmrg
516af69d88dSmrg      *dsv = tgsi_build_declaration_sampler_view(
517af69d88dSmrg         full_decl->SamplerView.Resource,
518af69d88dSmrg         full_decl->SamplerView.ReturnTypeX,
519af69d88dSmrg         full_decl->SamplerView.ReturnTypeY,
520af69d88dSmrg         full_decl->SamplerView.ReturnTypeZ,
521af69d88dSmrg         full_decl->SamplerView.ReturnTypeW,
522af69d88dSmrg         declaration,
523af69d88dSmrg         header);
524af69d88dSmrg   }
525af69d88dSmrg
526af69d88dSmrg   if (full_decl->Declaration.Array) {
527af69d88dSmrg      struct tgsi_declaration_array *da;
528af69d88dSmrg
529af69d88dSmrg      if (maxsize <= size) {
530af69d88dSmrg         return 0;
531af69d88dSmrg      }
532af69d88dSmrg      da = (struct tgsi_declaration_array *)&tokens[size];
533af69d88dSmrg      size++;
534af69d88dSmrg      *da = tgsi_build_declaration_array(
535af69d88dSmrg         full_decl->Array.ArrayID,
536af69d88dSmrg         declaration,
537af69d88dSmrg         header);
538af69d88dSmrg   }
5393464ebd5Sriastradh   return size;
5404a49301eSmrg}
5414a49301eSmrg
5424a49301eSmrg/*
5434a49301eSmrg * immediate
5444a49301eSmrg */
5454a49301eSmrg
5463464ebd5Sriastradhstatic struct tgsi_immediate
5474a49301eSmrgtgsi_default_immediate( void )
5484a49301eSmrg{
5494a49301eSmrg   struct tgsi_immediate immediate;
5504a49301eSmrg
5514a49301eSmrg   immediate.Type = TGSI_TOKEN_TYPE_IMMEDIATE;
5524a49301eSmrg   immediate.NrTokens = 1;
5534a49301eSmrg   immediate.DataType = TGSI_IMM_FLOAT32;
5544a49301eSmrg   immediate.Padding = 0;
5554a49301eSmrg
5564a49301eSmrg   return immediate;
5574a49301eSmrg}
5584a49301eSmrg
5593464ebd5Sriastradhstatic struct tgsi_immediate
5604a49301eSmrgtgsi_build_immediate(
561af69d88dSmrg   struct tgsi_header *header,
562af69d88dSmrg   unsigned type )
5634a49301eSmrg{
5644a49301eSmrg   struct tgsi_immediate immediate;
5654a49301eSmrg
5664a49301eSmrg   immediate = tgsi_default_immediate();
567af69d88dSmrg   immediate.DataType = type;
5684a49301eSmrg
5694a49301eSmrg   header_bodysize_grow( header );
5704a49301eSmrg
5714a49301eSmrg   return immediate;
5724a49301eSmrg}
5734a49301eSmrg
5744a49301eSmrgstruct tgsi_full_immediate
5754a49301eSmrgtgsi_default_full_immediate( void )
5764a49301eSmrg{
5774a49301eSmrg   struct tgsi_full_immediate fullimm;
5784a49301eSmrg
5794a49301eSmrg   fullimm.Immediate = tgsi_default_immediate();
5804a49301eSmrg   fullimm.u[0].Float = 0.0f;
5814a49301eSmrg   fullimm.u[1].Float = 0.0f;
5824a49301eSmrg   fullimm.u[2].Float = 0.0f;
5834a49301eSmrg   fullimm.u[3].Float = 0.0f;
5844a49301eSmrg
5854a49301eSmrg   return fullimm;
5864a49301eSmrg}
5874a49301eSmrg
5884a49301eSmrgstatic void
5894a49301eSmrgimmediate_grow(
5904a49301eSmrg   struct tgsi_immediate *immediate,
5914a49301eSmrg   struct tgsi_header *header )
5924a49301eSmrg{
5934a49301eSmrg   assert( immediate->NrTokens < 0xFF );
5944a49301eSmrg
5954a49301eSmrg   immediate->NrTokens++;
5964a49301eSmrg
5974a49301eSmrg   header_bodysize_grow( header );
5984a49301eSmrg}
5994a49301eSmrg
6004a49301eSmrgunsigned
6014a49301eSmrgtgsi_build_full_immediate(
6024a49301eSmrg   const struct tgsi_full_immediate *full_imm,
6034a49301eSmrg   struct tgsi_token *tokens,
6044a49301eSmrg   struct tgsi_header *header,
6054a49301eSmrg   unsigned maxsize )
6064a49301eSmrg{
60701e04c3fSmrg   unsigned size = 0;
60801e04c3fSmrg   int i;
6094a49301eSmrg   struct tgsi_immediate *immediate;
6104a49301eSmrg
6114a49301eSmrg   if( maxsize <= size )
6124a49301eSmrg      return 0;
6134a49301eSmrg   immediate = (struct tgsi_immediate *) &tokens[size];
6144a49301eSmrg   size++;
6154a49301eSmrg
616af69d88dSmrg   *immediate = tgsi_build_immediate( header, full_imm->Immediate.DataType );
6174a49301eSmrg
6184a49301eSmrg   assert( full_imm->Immediate.NrTokens <= 4 + 1 );
6194a49301eSmrg
6204a49301eSmrg   for( i = 0; i < full_imm->Immediate.NrTokens - 1; i++ ) {
6214a49301eSmrg      union tgsi_immediate_data *data;
6224a49301eSmrg
6234a49301eSmrg      if( maxsize <= size )
6244a49301eSmrg         return  0;
625af69d88dSmrg
6264a49301eSmrg      data = (union tgsi_immediate_data *) &tokens[size];
627af69d88dSmrg      *data = full_imm->u[i];
6284a49301eSmrg
629af69d88dSmrg      immediate_grow( immediate, header );
630af69d88dSmrg      size++;
6314a49301eSmrg   }
6324a49301eSmrg
6334a49301eSmrg   return size;
6344a49301eSmrg}
6354a49301eSmrg
6364a49301eSmrg/*
6374a49301eSmrg * instruction
6384a49301eSmrg */
6394a49301eSmrg
6404a49301eSmrgstruct tgsi_instruction
6414a49301eSmrgtgsi_default_instruction( void )
6424a49301eSmrg{
6434a49301eSmrg   struct tgsi_instruction instruction;
6444a49301eSmrg
6454a49301eSmrg   instruction.Type = TGSI_TOKEN_TYPE_INSTRUCTION;
646cdc920a0Smrg   instruction.NrTokens = 0;
6474a49301eSmrg   instruction.Opcode = TGSI_OPCODE_MOV;
64801e04c3fSmrg   instruction.Saturate = 0;
6494a49301eSmrg   instruction.NumDstRegs = 1;
6504a49301eSmrg   instruction.NumSrcRegs = 1;
651cdc920a0Smrg   instruction.Label = 0;
652cdc920a0Smrg   instruction.Texture = 0;
65301e04c3fSmrg   instruction.Memory = 0;
65401e04c3fSmrg   instruction.Precise = 0;
65501e04c3fSmrg   instruction.Padding = 0;
6564a49301eSmrg
6574a49301eSmrg   return instruction;
6584a49301eSmrg}
6594a49301eSmrg
6603464ebd5Sriastradhstatic struct tgsi_instruction
66101e04c3fSmrgtgsi_build_instruction(enum tgsi_opcode opcode,
662cdc920a0Smrg                       unsigned saturate,
66301e04c3fSmrg                       unsigned precise,
664cdc920a0Smrg                       unsigned num_dst_regs,
665cdc920a0Smrg                       unsigned num_src_regs,
666cdc920a0Smrg                       struct tgsi_header *header)
6674a49301eSmrg{
6684a49301eSmrg   struct tgsi_instruction instruction;
6694a49301eSmrg
6704a49301eSmrg   assert (opcode <= TGSI_OPCODE_LAST);
67101e04c3fSmrg   assert (saturate <= 1);
6724a49301eSmrg   assert (num_dst_regs <= 3);
6734a49301eSmrg   assert (num_src_regs <= 15);
6744a49301eSmrg
6754a49301eSmrg   instruction = tgsi_default_instruction();
6764a49301eSmrg   instruction.Opcode = opcode;
6774a49301eSmrg   instruction.Saturate = saturate;
67801e04c3fSmrg   instruction.Precise = precise;
6794a49301eSmrg   instruction.NumDstRegs = num_dst_regs;
6804a49301eSmrg   instruction.NumSrcRegs = num_src_regs;
6814a49301eSmrg
6824a49301eSmrg   header_bodysize_grow( header );
6834a49301eSmrg
6844a49301eSmrg   return instruction;
6854a49301eSmrg}
6864a49301eSmrg
6874a49301eSmrgstatic void
6884a49301eSmrginstruction_grow(
6894a49301eSmrg   struct tgsi_instruction *instruction,
6904a49301eSmrg   struct tgsi_header *header )
6914a49301eSmrg{
6924a49301eSmrg   assert (instruction->NrTokens <   0xFF);
6934a49301eSmrg
6944a49301eSmrg   instruction->NrTokens++;
6954a49301eSmrg
6964a49301eSmrg   header_bodysize_grow( header );
6974a49301eSmrg}
6984a49301eSmrg
6993464ebd5Sriastradhstatic struct tgsi_instruction_label
700cdc920a0Smrgtgsi_default_instruction_label( void )
7014a49301eSmrg{
702cdc920a0Smrg   struct tgsi_instruction_label instruction_label;
703cdc920a0Smrg
704cdc920a0Smrg   instruction_label.Label = 0;
705cdc920a0Smrg   instruction_label.Padding = 0;
706cdc920a0Smrg
707cdc920a0Smrg   return instruction_label;
7084a49301eSmrg}
7094a49301eSmrg
7103464ebd5Sriastradhstatic struct tgsi_instruction_label
711cdc920a0Smrgtgsi_build_instruction_label(
7124a49301eSmrg   unsigned label,
7134a49301eSmrg   struct tgsi_instruction *instruction,
7144a49301eSmrg   struct tgsi_header *header )
7154a49301eSmrg{
716cdc920a0Smrg   struct tgsi_instruction_label instruction_label;
7174a49301eSmrg
718cdc920a0Smrg   instruction_label.Label = label;
7193464ebd5Sriastradh   instruction_label.Padding = 0;
720cdc920a0Smrg   instruction->Label = 1;
7214a49301eSmrg
7224a49301eSmrg   instruction_grow( instruction, header );
7234a49301eSmrg
724cdc920a0Smrg   return instruction_label;
7254a49301eSmrg}
7264a49301eSmrg
7273464ebd5Sriastradhstatic struct tgsi_instruction_texture
728cdc920a0Smrgtgsi_default_instruction_texture( void )
7294a49301eSmrg{
730cdc920a0Smrg   struct tgsi_instruction_texture instruction_texture;
7314a49301eSmrg
732cdc920a0Smrg   instruction_texture.Texture = TGSI_TEXTURE_UNKNOWN;
733af69d88dSmrg   instruction_texture.NumOffsets = 0;
73401e04c3fSmrg   instruction_texture.ReturnType = TGSI_RETURN_TYPE_UNKNOWN;
735cdc920a0Smrg   instruction_texture.Padding = 0;
7364a49301eSmrg
737cdc920a0Smrg   return instruction_texture;
7384a49301eSmrg}
7394a49301eSmrg
7403464ebd5Sriastradhstatic struct tgsi_instruction_texture
741cdc920a0Smrgtgsi_build_instruction_texture(
7424a49301eSmrg   unsigned texture,
743af69d88dSmrg   unsigned num_offsets,
74401e04c3fSmrg   unsigned return_type,
7454a49301eSmrg   struct tgsi_instruction *instruction,
7464a49301eSmrg   struct tgsi_header *header )
7474a49301eSmrg{
748cdc920a0Smrg   struct tgsi_instruction_texture instruction_texture;
7494a49301eSmrg
750cdc920a0Smrg   instruction_texture.Texture = texture;
751af69d88dSmrg   instruction_texture.NumOffsets = num_offsets;
75201e04c3fSmrg   instruction_texture.ReturnType = return_type;
7533464ebd5Sriastradh   instruction_texture.Padding = 0;
754cdc920a0Smrg   instruction->Texture = 1;
7554a49301eSmrg
7564a49301eSmrg   instruction_grow( instruction, header );
7574a49301eSmrg
758cdc920a0Smrg   return instruction_texture;
7594a49301eSmrg}
7604a49301eSmrg
76101e04c3fSmrgstatic struct tgsi_instruction_memory
76201e04c3fSmrgtgsi_default_instruction_memory( void )
76301e04c3fSmrg{
76401e04c3fSmrg   struct tgsi_instruction_memory instruction_memory;
76501e04c3fSmrg
76601e04c3fSmrg   instruction_memory.Qualifier = 0;
76701e04c3fSmrg   instruction_memory.Texture = 0;
76801e04c3fSmrg   instruction_memory.Format = 0;
76901e04c3fSmrg   instruction_memory.Padding = 0;
77001e04c3fSmrg
77101e04c3fSmrg   return instruction_memory;
77201e04c3fSmrg}
77301e04c3fSmrg
77401e04c3fSmrgstatic struct tgsi_instruction_memory
77501e04c3fSmrgtgsi_build_instruction_memory(
77601e04c3fSmrg   unsigned qualifier,
77701e04c3fSmrg   unsigned texture,
77801e04c3fSmrg   unsigned format,
77901e04c3fSmrg   struct tgsi_instruction *instruction,
78001e04c3fSmrg   struct tgsi_header *header )
78101e04c3fSmrg{
78201e04c3fSmrg   struct tgsi_instruction_memory instruction_memory;
78301e04c3fSmrg
78401e04c3fSmrg   instruction_memory.Qualifier = qualifier;
78501e04c3fSmrg   instruction_memory.Texture = texture;
78601e04c3fSmrg   instruction_memory.Format = format;
78701e04c3fSmrg   instruction_memory.Padding = 0;
78801e04c3fSmrg   instruction->Memory = 1;
78901e04c3fSmrg
79001e04c3fSmrg   instruction_grow( instruction, header );
79101e04c3fSmrg
79201e04c3fSmrg   return instruction_memory;
79301e04c3fSmrg}
794af69d88dSmrg
795af69d88dSmrgstatic struct tgsi_texture_offset
796af69d88dSmrgtgsi_default_texture_offset( void )
797af69d88dSmrg{
798af69d88dSmrg   struct tgsi_texture_offset texture_offset;
799af69d88dSmrg
800af69d88dSmrg   texture_offset.Index = 0;
801af69d88dSmrg   texture_offset.File = 0;
802af69d88dSmrg   texture_offset.SwizzleX = 0;
803af69d88dSmrg   texture_offset.SwizzleY = 0;
804af69d88dSmrg   texture_offset.SwizzleZ = 0;
805af69d88dSmrg   texture_offset.Padding = 0;
806af69d88dSmrg
807af69d88dSmrg   return texture_offset;
808af69d88dSmrg}
809af69d88dSmrg
810af69d88dSmrgstatic struct tgsi_texture_offset
811af69d88dSmrgtgsi_build_texture_offset(
812af69d88dSmrg   int index, int file, int swizzle_x, int swizzle_y, int swizzle_z,
813af69d88dSmrg   struct tgsi_instruction *instruction,
814af69d88dSmrg   struct tgsi_header *header )
815af69d88dSmrg{
816af69d88dSmrg   struct tgsi_texture_offset texture_offset;
817af69d88dSmrg
818af69d88dSmrg   texture_offset.Index = index;
819af69d88dSmrg   texture_offset.File = file;
820af69d88dSmrg   texture_offset.SwizzleX = swizzle_x;
821af69d88dSmrg   texture_offset.SwizzleY = swizzle_y;
822af69d88dSmrg   texture_offset.SwizzleZ = swizzle_z;
823af69d88dSmrg   texture_offset.Padding = 0;
824af69d88dSmrg
825af69d88dSmrg   instruction_grow( instruction, header );
826af69d88dSmrg
827af69d88dSmrg   return texture_offset;
828af69d88dSmrg}
829af69d88dSmrg
8303464ebd5Sriastradhstatic struct tgsi_src_register
8314a49301eSmrgtgsi_default_src_register( void )
8324a49301eSmrg{
8334a49301eSmrg   struct tgsi_src_register src_register;
8344a49301eSmrg
8354a49301eSmrg   src_register.File = TGSI_FILE_NULL;
8364a49301eSmrg   src_register.SwizzleX = TGSI_SWIZZLE_X;
8374a49301eSmrg   src_register.SwizzleY = TGSI_SWIZZLE_Y;
8384a49301eSmrg   src_register.SwizzleZ = TGSI_SWIZZLE_Z;
8394a49301eSmrg   src_register.SwizzleW = TGSI_SWIZZLE_W;
8404a49301eSmrg   src_register.Negate = 0;
841cdc920a0Smrg   src_register.Absolute = 0;
8424a49301eSmrg   src_register.Indirect = 0;
8434a49301eSmrg   src_register.Dimension = 0;
8444a49301eSmrg   src_register.Index = 0;
8454a49301eSmrg
8464a49301eSmrg   return src_register;
8474a49301eSmrg}
8484a49301eSmrg
8493464ebd5Sriastradhstatic struct tgsi_src_register
8504a49301eSmrgtgsi_build_src_register(
8514a49301eSmrg   unsigned file,
8524a49301eSmrg   unsigned swizzle_x,
8534a49301eSmrg   unsigned swizzle_y,
8544a49301eSmrg   unsigned swizzle_z,
8554a49301eSmrg   unsigned swizzle_w,
8564a49301eSmrg   unsigned negate,
857cdc920a0Smrg   unsigned absolute,
8584a49301eSmrg   unsigned indirect,
8594a49301eSmrg   unsigned dimension,
8604a49301eSmrg   int index,
8614a49301eSmrg   struct tgsi_instruction *instruction,
8624a49301eSmrg   struct tgsi_header *header )
8634a49301eSmrg{
8644a49301eSmrg   struct tgsi_src_register   src_register;
8654a49301eSmrg
8664a49301eSmrg   assert( file < TGSI_FILE_COUNT );
8674a49301eSmrg   assert( swizzle_x <= TGSI_SWIZZLE_W );
8684a49301eSmrg   assert( swizzle_y <= TGSI_SWIZZLE_W );
8694a49301eSmrg   assert( swizzle_z <= TGSI_SWIZZLE_W );
8704a49301eSmrg   assert( swizzle_w <= TGSI_SWIZZLE_W );
8714a49301eSmrg   assert( negate <= 1 );
8724a49301eSmrg   assert( index >= -0x8000 && index <= 0x7FFF );
8734a49301eSmrg
8744a49301eSmrg   src_register.File = file;
8754a49301eSmrg   src_register.SwizzleX = swizzle_x;
8764a49301eSmrg   src_register.SwizzleY = swizzle_y;
8774a49301eSmrg   src_register.SwizzleZ = swizzle_z;
8784a49301eSmrg   src_register.SwizzleW = swizzle_w;
8794a49301eSmrg   src_register.Negate = negate;
880cdc920a0Smrg   src_register.Absolute = absolute;
8814a49301eSmrg   src_register.Indirect = indirect;
8824a49301eSmrg   src_register.Dimension = dimension;
8834a49301eSmrg   src_register.Index = index;
8844a49301eSmrg
8854a49301eSmrg   instruction_grow( instruction, header );
8864a49301eSmrg
8874a49301eSmrg   return src_register;
8884a49301eSmrg}
8894a49301eSmrg
890af69d88dSmrgstatic struct tgsi_ind_register
891af69d88dSmrgtgsi_default_ind_register( void )
892af69d88dSmrg{
893af69d88dSmrg   struct tgsi_ind_register ind_register;
894af69d88dSmrg
895af69d88dSmrg   ind_register.File = TGSI_FILE_NULL;
896af69d88dSmrg   ind_register.Index = 0;
897af69d88dSmrg   ind_register.Swizzle = TGSI_SWIZZLE_X;
898af69d88dSmrg   ind_register.ArrayID = 0;
899af69d88dSmrg
900af69d88dSmrg   return ind_register;
901af69d88dSmrg}
902af69d88dSmrg
903af69d88dSmrgstatic struct tgsi_ind_register
904af69d88dSmrgtgsi_build_ind_register(
905af69d88dSmrg   unsigned file,
906af69d88dSmrg   unsigned swizzle,
907af69d88dSmrg   int index,
908af69d88dSmrg   unsigned arrayid,
909af69d88dSmrg   struct tgsi_instruction *instruction,
910af69d88dSmrg   struct tgsi_header *header )
911af69d88dSmrg{
912af69d88dSmrg   struct tgsi_ind_register   ind_register;
913af69d88dSmrg
914af69d88dSmrg   assert( file < TGSI_FILE_COUNT );
915af69d88dSmrg   assert( swizzle <= TGSI_SWIZZLE_W );
916af69d88dSmrg   assert( index >= -0x8000 && index <= 0x7FFF );
917af69d88dSmrg
918af69d88dSmrg   ind_register.File = file;
919af69d88dSmrg   ind_register.Swizzle = swizzle;
920af69d88dSmrg   ind_register.Index = index;
921af69d88dSmrg   ind_register.ArrayID = arrayid;
922af69d88dSmrg
923af69d88dSmrg   instruction_grow( instruction, header );
924af69d88dSmrg
925af69d88dSmrg   return ind_register;
926af69d88dSmrg}
927af69d88dSmrg
9283464ebd5Sriastradhstatic struct tgsi_dimension
9294a49301eSmrgtgsi_default_dimension( void )
9304a49301eSmrg{
9314a49301eSmrg   struct tgsi_dimension dimension;
9324a49301eSmrg
9334a49301eSmrg   dimension.Indirect = 0;
9344a49301eSmrg   dimension.Dimension = 0;
9354a49301eSmrg   dimension.Padding = 0;
9364a49301eSmrg   dimension.Index = 0;
9374a49301eSmrg
9384a49301eSmrg   return dimension;
9394a49301eSmrg}
9404a49301eSmrg
9413464ebd5Sriastradhstatic struct tgsi_full_src_register
9423464ebd5Sriastradhtgsi_default_full_src_register( void )
9433464ebd5Sriastradh{
9443464ebd5Sriastradh   struct tgsi_full_src_register full_src_register;
9453464ebd5Sriastradh
9463464ebd5Sriastradh   full_src_register.Register = tgsi_default_src_register();
947af69d88dSmrg   full_src_register.Indirect = tgsi_default_ind_register();
9483464ebd5Sriastradh   full_src_register.Dimension = tgsi_default_dimension();
949af69d88dSmrg   full_src_register.DimIndirect = tgsi_default_ind_register();
9503464ebd5Sriastradh
9513464ebd5Sriastradh   return full_src_register;
9523464ebd5Sriastradh}
9533464ebd5Sriastradh
9543464ebd5Sriastradhstatic struct tgsi_dimension
9554a49301eSmrgtgsi_build_dimension(
9564a49301eSmrg   unsigned indirect,
9574a49301eSmrg   unsigned index,
9584a49301eSmrg   struct tgsi_instruction *instruction,
9594a49301eSmrg   struct tgsi_header *header )
9604a49301eSmrg{
9614a49301eSmrg   struct tgsi_dimension dimension;
9624a49301eSmrg
9634a49301eSmrg   dimension.Indirect = indirect;
9643464ebd5Sriastradh   dimension.Dimension = 0;
9653464ebd5Sriastradh   dimension.Padding = 0;
9664a49301eSmrg   dimension.Index = index;
9674a49301eSmrg
9684a49301eSmrg   instruction_grow( instruction, header );
9694a49301eSmrg
9704a49301eSmrg   return dimension;
9714a49301eSmrg}
9724a49301eSmrg
9733464ebd5Sriastradhstatic struct tgsi_dst_register
9744a49301eSmrgtgsi_default_dst_register( void )
9754a49301eSmrg{
9764a49301eSmrg   struct tgsi_dst_register dst_register;
9774a49301eSmrg
9784a49301eSmrg   dst_register.File = TGSI_FILE_NULL;
9794a49301eSmrg   dst_register.WriteMask = TGSI_WRITEMASK_XYZW;
9804a49301eSmrg   dst_register.Indirect = 0;
9814a49301eSmrg   dst_register.Dimension = 0;
9824a49301eSmrg   dst_register.Index = 0;
9834a49301eSmrg   dst_register.Padding = 0;
9844a49301eSmrg
9854a49301eSmrg   return dst_register;
9864a49301eSmrg}
9874a49301eSmrg
9883464ebd5Sriastradhstatic struct tgsi_dst_register
9894a49301eSmrgtgsi_build_dst_register(
9904a49301eSmrg   unsigned file,
9914a49301eSmrg   unsigned mask,
9924a49301eSmrg   unsigned indirect,
9933464ebd5Sriastradh   unsigned dimension,
9944a49301eSmrg   int index,
9954a49301eSmrg   struct tgsi_instruction *instruction,
9964a49301eSmrg   struct tgsi_header *header )
9974a49301eSmrg{
9984a49301eSmrg   struct tgsi_dst_register dst_register;
9994a49301eSmrg
10004a49301eSmrg   assert( file < TGSI_FILE_COUNT );
10014a49301eSmrg   assert( mask <= TGSI_WRITEMASK_XYZW );
10024a49301eSmrg   assert( index >= -32768 && index <= 32767 );
10034a49301eSmrg
10044a49301eSmrg   dst_register.File = file;
10054a49301eSmrg   dst_register.WriteMask = mask;
10064a49301eSmrg   dst_register.Indirect = indirect;
10073464ebd5Sriastradh   dst_register.Dimension = dimension;
10083464ebd5Sriastradh   dst_register.Index = index;
10093464ebd5Sriastradh   dst_register.Padding = 0;
10104a49301eSmrg
10114a49301eSmrg   instruction_grow( instruction, header );
10124a49301eSmrg
10134a49301eSmrg   return dst_register;
10144a49301eSmrg}
10154a49301eSmrg
10163464ebd5Sriastradhstatic struct tgsi_full_dst_register
10174a49301eSmrgtgsi_default_full_dst_register( void )
10184a49301eSmrg{
10194a49301eSmrg   struct tgsi_full_dst_register full_dst_register;
10204a49301eSmrg
1021cdc920a0Smrg   full_dst_register.Register = tgsi_default_dst_register();
1022af69d88dSmrg   full_dst_register.Indirect = tgsi_default_ind_register();
10233464ebd5Sriastradh   full_dst_register.Dimension = tgsi_default_dimension();
1024af69d88dSmrg   full_dst_register.DimIndirect = tgsi_default_ind_register();
10254a49301eSmrg
10264a49301eSmrg   return full_dst_register;
10274a49301eSmrg}
10284a49301eSmrg
10293464ebd5Sriastradhstruct tgsi_full_instruction
10303464ebd5Sriastradhtgsi_default_full_instruction( void )
10313464ebd5Sriastradh{
10323464ebd5Sriastradh   struct tgsi_full_instruction full_instruction;
10333464ebd5Sriastradh   unsigned i;
10343464ebd5Sriastradh
10353464ebd5Sriastradh   full_instruction.Instruction = tgsi_default_instruction();
10363464ebd5Sriastradh   full_instruction.Label = tgsi_default_instruction_label();
10373464ebd5Sriastradh   full_instruction.Texture = tgsi_default_instruction_texture();
103801e04c3fSmrg   full_instruction.Memory = tgsi_default_instruction_memory();
1039af69d88dSmrg   for( i = 0;  i < TGSI_FULL_MAX_TEX_OFFSETS; i++ ) {
1040af69d88dSmrg      full_instruction.TexOffsets[i] = tgsi_default_texture_offset();
1041af69d88dSmrg   }
10423464ebd5Sriastradh   for( i = 0;  i < TGSI_FULL_MAX_DST_REGISTERS; i++ ) {
10433464ebd5Sriastradh      full_instruction.Dst[i] = tgsi_default_full_dst_register();
10443464ebd5Sriastradh   }
10453464ebd5Sriastradh   for( i = 0;  i < TGSI_FULL_MAX_SRC_REGISTERS; i++ ) {
10463464ebd5Sriastradh      full_instruction.Src[i] = tgsi_default_full_src_register();
10473464ebd5Sriastradh   }
10483464ebd5Sriastradh
10493464ebd5Sriastradh   return full_instruction;
10503464ebd5Sriastradh}
10513464ebd5Sriastradh
10523464ebd5Sriastradhunsigned
10533464ebd5Sriastradhtgsi_build_full_instruction(
10543464ebd5Sriastradh   const struct tgsi_full_instruction *full_inst,
10553464ebd5Sriastradh   struct  tgsi_token *tokens,
10563464ebd5Sriastradh   struct  tgsi_header *header,
10573464ebd5Sriastradh   unsigned  maxsize )
10583464ebd5Sriastradh{
10593464ebd5Sriastradh   unsigned size = 0;
10603464ebd5Sriastradh   unsigned i;
10613464ebd5Sriastradh   struct tgsi_instruction *instruction;
10623464ebd5Sriastradh
10633464ebd5Sriastradh   if( maxsize <= size )
10643464ebd5Sriastradh      return 0;
10653464ebd5Sriastradh   instruction = (struct tgsi_instruction *) &tokens[size];
10663464ebd5Sriastradh   size++;
10673464ebd5Sriastradh
10683464ebd5Sriastradh   *instruction = tgsi_build_instruction(full_inst->Instruction.Opcode,
10693464ebd5Sriastradh                                         full_inst->Instruction.Saturate,
107001e04c3fSmrg                                         full_inst->Instruction.Precise,
10713464ebd5Sriastradh                                         full_inst->Instruction.NumDstRegs,
10723464ebd5Sriastradh                                         full_inst->Instruction.NumSrcRegs,
10733464ebd5Sriastradh                                         header);
10743464ebd5Sriastradh
10753464ebd5Sriastradh   if (full_inst->Instruction.Label) {
10763464ebd5Sriastradh      struct tgsi_instruction_label *instruction_label;
10773464ebd5Sriastradh
10783464ebd5Sriastradh      if( maxsize <= size )
10793464ebd5Sriastradh         return 0;
10803464ebd5Sriastradh      instruction_label =
10813464ebd5Sriastradh         (struct  tgsi_instruction_label *) &tokens[size];
10823464ebd5Sriastradh      size++;
10833464ebd5Sriastradh
10843464ebd5Sriastradh      *instruction_label = tgsi_build_instruction_label(
10853464ebd5Sriastradh         full_inst->Label.Label,
10863464ebd5Sriastradh         instruction,
108701e04c3fSmrg	 header );
10883464ebd5Sriastradh   }
10893464ebd5Sriastradh
10903464ebd5Sriastradh   if (full_inst->Instruction.Texture) {
10913464ebd5Sriastradh      struct tgsi_instruction_texture *instruction_texture;
10923464ebd5Sriastradh
10933464ebd5Sriastradh      if( maxsize <= size )
10943464ebd5Sriastradh         return 0;
10953464ebd5Sriastradh      instruction_texture =
10963464ebd5Sriastradh         (struct  tgsi_instruction_texture *) &tokens[size];
10973464ebd5Sriastradh      size++;
10983464ebd5Sriastradh
10993464ebd5Sriastradh      *instruction_texture = tgsi_build_instruction_texture(
11003464ebd5Sriastradh         full_inst->Texture.Texture,
110101e04c3fSmrg         full_inst->Texture.NumOffsets,
110201e04c3fSmrg         full_inst->Texture.ReturnType,
11033464ebd5Sriastradh         instruction,
11043464ebd5Sriastradh         header   );
11053464ebd5Sriastradh
1106af69d88dSmrg      for (i = 0; i < full_inst->Texture.NumOffsets; i++) {
1107af69d88dSmrg         struct tgsi_texture_offset *texture_offset;
1108af69d88dSmrg
1109af69d88dSmrg         if ( maxsize <= size )
1110af69d88dSmrg            return 0;
1111af69d88dSmrg	 texture_offset = (struct tgsi_texture_offset *)&tokens[size];
1112af69d88dSmrg         size++;
1113af69d88dSmrg         *texture_offset = tgsi_build_texture_offset(
1114af69d88dSmrg            full_inst->TexOffsets[i].Index,
1115af69d88dSmrg            full_inst->TexOffsets[i].File,
1116af69d88dSmrg            full_inst->TexOffsets[i].SwizzleX,
1117af69d88dSmrg            full_inst->TexOffsets[i].SwizzleY,
1118af69d88dSmrg            full_inst->TexOffsets[i].SwizzleZ,
1119af69d88dSmrg            instruction,
1120af69d88dSmrg            header);
1121af69d88dSmrg      }
1122af69d88dSmrg   }
112301e04c3fSmrg
112401e04c3fSmrg   if (full_inst->Instruction.Memory) {
112501e04c3fSmrg      struct tgsi_instruction_memory *instruction_memory;
112601e04c3fSmrg
112701e04c3fSmrg      if( maxsize <= size )
112801e04c3fSmrg         return 0;
112901e04c3fSmrg      instruction_memory =
113001e04c3fSmrg         (struct  tgsi_instruction_memory *) &tokens[size];
113101e04c3fSmrg      size++;
113201e04c3fSmrg
113301e04c3fSmrg      *instruction_memory = tgsi_build_instruction_memory(
113401e04c3fSmrg         full_inst->Memory.Qualifier,
113501e04c3fSmrg         full_inst->Memory.Texture,
113601e04c3fSmrg         full_inst->Memory.Format,
113701e04c3fSmrg         instruction,
113801e04c3fSmrg         header );
113901e04c3fSmrg   }
114001e04c3fSmrg
11413464ebd5Sriastradh   for( i = 0;  i <   full_inst->Instruction.NumDstRegs; i++ ) {
11423464ebd5Sriastradh      const struct tgsi_full_dst_register *reg = &full_inst->Dst[i];
11433464ebd5Sriastradh      struct tgsi_dst_register *dst_register;
11443464ebd5Sriastradh
11453464ebd5Sriastradh      if( maxsize <= size )
11463464ebd5Sriastradh         return 0;
11473464ebd5Sriastradh      dst_register = (struct tgsi_dst_register *) &tokens[size];
11483464ebd5Sriastradh      size++;
11493464ebd5Sriastradh
11503464ebd5Sriastradh      *dst_register = tgsi_build_dst_register(
11513464ebd5Sriastradh         reg->Register.File,
11523464ebd5Sriastradh         reg->Register.WriteMask,
11533464ebd5Sriastradh         reg->Register.Indirect,
11543464ebd5Sriastradh         reg->Register.Dimension,
11553464ebd5Sriastradh         reg->Register.Index,
11563464ebd5Sriastradh         instruction,
11573464ebd5Sriastradh         header );
11583464ebd5Sriastradh
11593464ebd5Sriastradh      if( reg->Register.Indirect ) {
1160af69d88dSmrg         struct tgsi_ind_register *ind;
11613464ebd5Sriastradh
11623464ebd5Sriastradh         if( maxsize <= size )
11633464ebd5Sriastradh            return 0;
1164af69d88dSmrg         ind = (struct tgsi_ind_register *) &tokens[size];
11653464ebd5Sriastradh         size++;
11663464ebd5Sriastradh
1167af69d88dSmrg         *ind = tgsi_build_ind_register(
11683464ebd5Sriastradh            reg->Indirect.File,
1169af69d88dSmrg            reg->Indirect.Swizzle,
11703464ebd5Sriastradh            reg->Indirect.Index,
1171af69d88dSmrg            reg->Indirect.ArrayID,
11723464ebd5Sriastradh            instruction,
11733464ebd5Sriastradh            header );
11743464ebd5Sriastradh      }
11753464ebd5Sriastradh
11763464ebd5Sriastradh      if( reg->Register.Dimension ) {
11773464ebd5Sriastradh         struct  tgsi_dimension *dim;
11783464ebd5Sriastradh
11793464ebd5Sriastradh         assert( !reg->Dimension.Dimension );
11803464ebd5Sriastradh
11813464ebd5Sriastradh         if( maxsize <= size )
11823464ebd5Sriastradh            return 0;
11833464ebd5Sriastradh         dim = (struct tgsi_dimension *) &tokens[size];
11843464ebd5Sriastradh         size++;
11853464ebd5Sriastradh
11863464ebd5Sriastradh         *dim = tgsi_build_dimension(
11873464ebd5Sriastradh            reg->Dimension.Indirect,
11883464ebd5Sriastradh            reg->Dimension.Index,
11893464ebd5Sriastradh            instruction,
11903464ebd5Sriastradh            header );
11913464ebd5Sriastradh
11923464ebd5Sriastradh         if( reg->Dimension.Indirect ) {
1193af69d88dSmrg            struct tgsi_ind_register *ind;
11943464ebd5Sriastradh
11953464ebd5Sriastradh            if( maxsize <= size )
11963464ebd5Sriastradh               return 0;
1197af69d88dSmrg            ind = (struct tgsi_ind_register *) &tokens[size];
11983464ebd5Sriastradh            size++;
11993464ebd5Sriastradh
1200af69d88dSmrg            *ind = tgsi_build_ind_register(
12013464ebd5Sriastradh               reg->DimIndirect.File,
1202af69d88dSmrg               reg->DimIndirect.Swizzle,
12033464ebd5Sriastradh               reg->DimIndirect.Index,
1204af69d88dSmrg               reg->DimIndirect.ArrayID,
12053464ebd5Sriastradh               instruction,
12063464ebd5Sriastradh               header );
12073464ebd5Sriastradh         }
12083464ebd5Sriastradh      }
12093464ebd5Sriastradh   }
12103464ebd5Sriastradh
12113464ebd5Sriastradh   for( i = 0;  i < full_inst->Instruction.NumSrcRegs; i++ ) {
12123464ebd5Sriastradh      const struct tgsi_full_src_register *reg = &full_inst->Src[i];
12133464ebd5Sriastradh      struct tgsi_src_register *src_register;
12143464ebd5Sriastradh
12153464ebd5Sriastradh      if( maxsize <= size )
12163464ebd5Sriastradh         return 0;
12173464ebd5Sriastradh      src_register = (struct tgsi_src_register *)  &tokens[size];
12183464ebd5Sriastradh      size++;
12193464ebd5Sriastradh
12203464ebd5Sriastradh      *src_register = tgsi_build_src_register(
12213464ebd5Sriastradh         reg->Register.File,
12223464ebd5Sriastradh         reg->Register.SwizzleX,
12233464ebd5Sriastradh         reg->Register.SwizzleY,
12243464ebd5Sriastradh         reg->Register.SwizzleZ,
12253464ebd5Sriastradh         reg->Register.SwizzleW,
12263464ebd5Sriastradh         reg->Register.Negate,
12273464ebd5Sriastradh         reg->Register.Absolute,
12283464ebd5Sriastradh         reg->Register.Indirect,
12293464ebd5Sriastradh         reg->Register.Dimension,
12303464ebd5Sriastradh         reg->Register.Index,
12313464ebd5Sriastradh         instruction,
12323464ebd5Sriastradh         header );
12333464ebd5Sriastradh
12343464ebd5Sriastradh      if( reg->Register.Indirect ) {
1235af69d88dSmrg         struct  tgsi_ind_register *ind;
12363464ebd5Sriastradh
12373464ebd5Sriastradh         if( maxsize <= size )
12383464ebd5Sriastradh            return 0;
1239af69d88dSmrg         ind = (struct tgsi_ind_register *) &tokens[size];
12403464ebd5Sriastradh         size++;
12413464ebd5Sriastradh
1242af69d88dSmrg         *ind = tgsi_build_ind_register(
12433464ebd5Sriastradh            reg->Indirect.File,
1244af69d88dSmrg            reg->Indirect.Swizzle,
12453464ebd5Sriastradh            reg->Indirect.Index,
1246af69d88dSmrg            reg->Indirect.ArrayID,
12473464ebd5Sriastradh            instruction,
12483464ebd5Sriastradh            header );
12493464ebd5Sriastradh      }
12503464ebd5Sriastradh
12513464ebd5Sriastradh      if( reg->Register.Dimension ) {
12523464ebd5Sriastradh         struct  tgsi_dimension *dim;
12533464ebd5Sriastradh
12543464ebd5Sriastradh         assert( !reg->Dimension.Dimension );
12553464ebd5Sriastradh
12563464ebd5Sriastradh         if( maxsize <= size )
12573464ebd5Sriastradh            return 0;
12583464ebd5Sriastradh         dim = (struct tgsi_dimension *) &tokens[size];
12593464ebd5Sriastradh         size++;
12603464ebd5Sriastradh
12613464ebd5Sriastradh         *dim = tgsi_build_dimension(
12623464ebd5Sriastradh            reg->Dimension.Indirect,
12633464ebd5Sriastradh            reg->Dimension.Index,
12643464ebd5Sriastradh            instruction,
12653464ebd5Sriastradh            header );
12663464ebd5Sriastradh
12673464ebd5Sriastradh         if( reg->Dimension.Indirect ) {
1268af69d88dSmrg            struct tgsi_ind_register *ind;
12693464ebd5Sriastradh
12703464ebd5Sriastradh            if( maxsize <= size )
12713464ebd5Sriastradh               return 0;
1272af69d88dSmrg            ind = (struct tgsi_ind_register *) &tokens[size];
12733464ebd5Sriastradh            size++;
12743464ebd5Sriastradh
1275af69d88dSmrg            *ind = tgsi_build_ind_register(
12763464ebd5Sriastradh               reg->DimIndirect.File,
1277af69d88dSmrg               reg->DimIndirect.Swizzle,
12783464ebd5Sriastradh               reg->DimIndirect.Index,
1279af69d88dSmrg               reg->DimIndirect.ArrayID,
12803464ebd5Sriastradh               instruction,
12813464ebd5Sriastradh               header );
12823464ebd5Sriastradh         }
12833464ebd5Sriastradh      }
12843464ebd5Sriastradh   }
12853464ebd5Sriastradh
12863464ebd5Sriastradh   return size;
12873464ebd5Sriastradh}
12883464ebd5Sriastradh
12893464ebd5Sriastradhstatic struct tgsi_property
1290cdc920a0Smrgtgsi_default_property( void )
12914a49301eSmrg{
1292cdc920a0Smrg   struct tgsi_property property;
12934a49301eSmrg
1294cdc920a0Smrg   property.Type = TGSI_TOKEN_TYPE_PROPERTY;
1295cdc920a0Smrg   property.NrTokens = 1;
1296cdc920a0Smrg   property.PropertyName = TGSI_PROPERTY_GS_INPUT_PRIM;
1297cdc920a0Smrg   property.Padding = 0;
12984a49301eSmrg
1299cdc920a0Smrg   return property;
13004a49301eSmrg}
13014a49301eSmrg
13023464ebd5Sriastradhstatic struct tgsi_property
1303cdc920a0Smrgtgsi_build_property(unsigned property_name,
1304cdc920a0Smrg                    struct tgsi_header *header)
13054a49301eSmrg{
1306cdc920a0Smrg   struct tgsi_property property;
1307cdc920a0Smrg
1308cdc920a0Smrg   property = tgsi_default_property();
1309cdc920a0Smrg   property.PropertyName = property_name;
1310cdc920a0Smrg
1311cdc920a0Smrg   header_bodysize_grow( header );
1312cdc920a0Smrg
1313cdc920a0Smrg   return property;
13144a49301eSmrg}
13154a49301eSmrg
1316cdc920a0Smrg
1317cdc920a0Smrgstruct tgsi_full_property
1318cdc920a0Smrgtgsi_default_full_property( void )
1319cdc920a0Smrg{
1320cdc920a0Smrg   struct tgsi_full_property  full_property;
1321cdc920a0Smrg
1322cdc920a0Smrg   full_property.Property  = tgsi_default_property();
1323cdc920a0Smrg   memset(full_property.u, 0,
1324cdc920a0Smrg          sizeof(struct tgsi_property_data) * 8);
1325cdc920a0Smrg
1326cdc920a0Smrg   return full_property;
1327cdc920a0Smrg}
1328cdc920a0Smrg
1329cdc920a0Smrgstatic void
1330cdc920a0Smrgproperty_grow(
1331cdc920a0Smrg   struct tgsi_property *property,
13324a49301eSmrg   struct tgsi_header *header )
13334a49301eSmrg{
1334cdc920a0Smrg   assert( property->NrTokens < 0xFF );
13354a49301eSmrg
1336cdc920a0Smrg   property->NrTokens++;
13374a49301eSmrg
1338cdc920a0Smrg   header_bodysize_grow( header );
1339cdc920a0Smrg}
13404a49301eSmrg
13413464ebd5Sriastradhstatic struct tgsi_property_data
1342cdc920a0Smrgtgsi_build_property_data(
1343cdc920a0Smrg   unsigned value,
1344cdc920a0Smrg   struct tgsi_property *property,
1345cdc920a0Smrg   struct tgsi_header *header )
1346cdc920a0Smrg{
1347cdc920a0Smrg   struct tgsi_property_data property_data;
1348cdc920a0Smrg
1349cdc920a0Smrg   property_data.Data = value;
1350cdc920a0Smrg
1351cdc920a0Smrg   property_grow( property, header );
1352cdc920a0Smrg
1353cdc920a0Smrg   return property_data;
1354cdc920a0Smrg}
13554a49301eSmrg
1356cdc920a0Smrgunsigned
1357cdc920a0Smrgtgsi_build_full_property(
1358cdc920a0Smrg   const struct tgsi_full_property *full_prop,
1359cdc920a0Smrg   struct tgsi_token *tokens,
1360cdc920a0Smrg   struct tgsi_header *header,
1361cdc920a0Smrg   unsigned maxsize )
1362cdc920a0Smrg{
136301e04c3fSmrg   unsigned size = 0;
136401e04c3fSmrg   int i;
1365cdc920a0Smrg   struct tgsi_property *property;
1366cdc920a0Smrg
1367cdc920a0Smrg   if( maxsize <= size )
1368cdc920a0Smrg      return 0;
1369cdc920a0Smrg   property = (struct tgsi_property *) &tokens[size];
1370cdc920a0Smrg   size++;
1371cdc920a0Smrg
1372cdc920a0Smrg   *property = tgsi_build_property(
1373cdc920a0Smrg      full_prop->Property.PropertyName,
1374cdc920a0Smrg      header );
1375cdc920a0Smrg
1376cdc920a0Smrg   assert( full_prop->Property.NrTokens <= 8 + 1 );
1377cdc920a0Smrg
1378cdc920a0Smrg   for( i = 0; i < full_prop->Property.NrTokens - 1; i++ ) {
1379cdc920a0Smrg      struct tgsi_property_data *data;
1380cdc920a0Smrg
1381cdc920a0Smrg      if( maxsize <= size )
1382cdc920a0Smrg         return  0;
1383cdc920a0Smrg      data = (struct tgsi_property_data *) &tokens[size];
1384cdc920a0Smrg      size++;
1385cdc920a0Smrg
1386cdc920a0Smrg      *data = tgsi_build_property_data(
1387cdc920a0Smrg         full_prop->u[i].Data,
1388cdc920a0Smrg         property,
1389cdc920a0Smrg         header );
1390cdc920a0Smrg   }
1391cdc920a0Smrg
1392cdc920a0Smrg   return size;
13934a49301eSmrg}
139401e04c3fSmrg
139501e04c3fSmrgstruct tgsi_full_src_register
139601e04c3fSmrgtgsi_full_src_register_from_dst(const struct tgsi_full_dst_register *dst)
139701e04c3fSmrg{
139801e04c3fSmrg   struct tgsi_full_src_register src;
139901e04c3fSmrg   src.Register = tgsi_default_src_register();
140001e04c3fSmrg   src.Register.File = dst->Register.File;
140101e04c3fSmrg   src.Register.Indirect = dst->Register.Indirect;
140201e04c3fSmrg   src.Register.Dimension = dst->Register.Dimension;
140301e04c3fSmrg   src.Register.Index = dst->Register.Index;
140401e04c3fSmrg   src.Indirect = dst->Indirect;
140501e04c3fSmrg   src.Dimension = dst->Dimension;
140601e04c3fSmrg   src.DimIndirect = dst->DimIndirect;
140701e04c3fSmrg   return src;
140801e04c3fSmrg}
1409