1bf215546Sopenharmony_ci/**************************************************************************
2bf215546Sopenharmony_ci *
3bf215546Sopenharmony_ci * Copyright 2007 VMware, Inc.
4bf215546Sopenharmony_ci * All Rights Reserved.
5bf215546Sopenharmony_ci *
6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the
8bf215546Sopenharmony_ci * "Software"), to deal in the Software without restriction, including
9bf215546Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish,
10bf215546Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to
11bf215546Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to
12bf215546Sopenharmony_ci * the following conditions:
13bf215546Sopenharmony_ci *
14bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the
15bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions
16bf215546Sopenharmony_ci * of the Software.
17bf215546Sopenharmony_ci *
18bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20bf215546Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21bf215546Sopenharmony_ci * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22bf215546Sopenharmony_ci * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23bf215546Sopenharmony_ci * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24bf215546Sopenharmony_ci * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25bf215546Sopenharmony_ci *
26bf215546Sopenharmony_ci **************************************************************************/
27bf215546Sopenharmony_ci
28bf215546Sopenharmony_ci#include "util/u_debug.h"
29bf215546Sopenharmony_ci#include "pipe/p_format.h"
30bf215546Sopenharmony_ci#include "pipe/p_shader_tokens.h"
31bf215546Sopenharmony_ci#include "tgsi_build.h"
32bf215546Sopenharmony_ci#include "tgsi_parse.h"
33bf215546Sopenharmony_ci
34bf215546Sopenharmony_ci
35bf215546Sopenharmony_ci/*
36bf215546Sopenharmony_ci * header
37bf215546Sopenharmony_ci */
38bf215546Sopenharmony_ci
39bf215546Sopenharmony_cistruct tgsi_header
40bf215546Sopenharmony_citgsi_build_header( void )
41bf215546Sopenharmony_ci{
42bf215546Sopenharmony_ci   struct tgsi_header header;
43bf215546Sopenharmony_ci
44bf215546Sopenharmony_ci   header.HeaderSize = 1;
45bf215546Sopenharmony_ci   header.BodySize = 0;
46bf215546Sopenharmony_ci
47bf215546Sopenharmony_ci   return header;
48bf215546Sopenharmony_ci}
49bf215546Sopenharmony_ci
50bf215546Sopenharmony_cistatic void
51bf215546Sopenharmony_ciheader_headersize_grow( struct tgsi_header *header )
52bf215546Sopenharmony_ci{
53bf215546Sopenharmony_ci   assert( header->HeaderSize < 0xFF );
54bf215546Sopenharmony_ci   assert( header->BodySize == 0 );
55bf215546Sopenharmony_ci
56bf215546Sopenharmony_ci   header->HeaderSize++;
57bf215546Sopenharmony_ci}
58bf215546Sopenharmony_ci
59bf215546Sopenharmony_cistatic void
60bf215546Sopenharmony_ciheader_bodysize_grow( struct tgsi_header *header )
61bf215546Sopenharmony_ci{
62bf215546Sopenharmony_ci   assert( header->BodySize < 0xFFFFFF );
63bf215546Sopenharmony_ci
64bf215546Sopenharmony_ci   header->BodySize++;
65bf215546Sopenharmony_ci}
66bf215546Sopenharmony_ci
67bf215546Sopenharmony_cistruct tgsi_processor
68bf215546Sopenharmony_citgsi_build_processor(
69bf215546Sopenharmony_ci   unsigned type,
70bf215546Sopenharmony_ci   struct tgsi_header *header )
71bf215546Sopenharmony_ci{
72bf215546Sopenharmony_ci   struct tgsi_processor processor;
73bf215546Sopenharmony_ci
74bf215546Sopenharmony_ci   processor.Processor = type;
75bf215546Sopenharmony_ci   processor.Padding = 0;
76bf215546Sopenharmony_ci
77bf215546Sopenharmony_ci   header_headersize_grow( header );
78bf215546Sopenharmony_ci
79bf215546Sopenharmony_ci   return processor;
80bf215546Sopenharmony_ci}
81bf215546Sopenharmony_ci
82bf215546Sopenharmony_ci/*
83bf215546Sopenharmony_ci * declaration
84bf215546Sopenharmony_ci */
85bf215546Sopenharmony_ci
86bf215546Sopenharmony_cistatic void
87bf215546Sopenharmony_cideclaration_grow(
88bf215546Sopenharmony_ci   struct tgsi_declaration *declaration,
89bf215546Sopenharmony_ci   struct tgsi_header *header )
90bf215546Sopenharmony_ci{
91bf215546Sopenharmony_ci   assert( declaration->NrTokens < 0xFF );
92bf215546Sopenharmony_ci
93bf215546Sopenharmony_ci   declaration->NrTokens++;
94bf215546Sopenharmony_ci
95bf215546Sopenharmony_ci   header_bodysize_grow( header );
96bf215546Sopenharmony_ci}
97bf215546Sopenharmony_ci
98bf215546Sopenharmony_cistatic struct tgsi_declaration
99bf215546Sopenharmony_citgsi_default_declaration( void )
100bf215546Sopenharmony_ci{
101bf215546Sopenharmony_ci   struct tgsi_declaration declaration;
102bf215546Sopenharmony_ci
103bf215546Sopenharmony_ci   declaration.Type = TGSI_TOKEN_TYPE_DECLARATION;
104bf215546Sopenharmony_ci   declaration.NrTokens = 1;
105bf215546Sopenharmony_ci   declaration.File = TGSI_FILE_NULL;
106bf215546Sopenharmony_ci   declaration.UsageMask = TGSI_WRITEMASK_XYZW;
107bf215546Sopenharmony_ci   declaration.Interpolate = 0;
108bf215546Sopenharmony_ci   declaration.Dimension = 0;
109bf215546Sopenharmony_ci   declaration.Semantic = 0;
110bf215546Sopenharmony_ci   declaration.Invariant = 0;
111bf215546Sopenharmony_ci   declaration.Local = 0;
112bf215546Sopenharmony_ci   declaration.Array = 0;
113bf215546Sopenharmony_ci   declaration.Atomic = 0;
114bf215546Sopenharmony_ci   declaration.MemType = TGSI_MEMORY_TYPE_GLOBAL;
115bf215546Sopenharmony_ci   declaration.Padding = 0;
116bf215546Sopenharmony_ci
117bf215546Sopenharmony_ci   return declaration;
118bf215546Sopenharmony_ci}
119bf215546Sopenharmony_ci
120bf215546Sopenharmony_cistatic struct tgsi_declaration
121bf215546Sopenharmony_citgsi_build_declaration(
122bf215546Sopenharmony_ci   unsigned file,
123bf215546Sopenharmony_ci   unsigned usage_mask,
124bf215546Sopenharmony_ci   unsigned interpolate,
125bf215546Sopenharmony_ci   unsigned dimension,
126bf215546Sopenharmony_ci   unsigned semantic,
127bf215546Sopenharmony_ci   unsigned invariant,
128bf215546Sopenharmony_ci   unsigned local,
129bf215546Sopenharmony_ci   unsigned array,
130bf215546Sopenharmony_ci   unsigned atomic,
131bf215546Sopenharmony_ci   unsigned mem_type,
132bf215546Sopenharmony_ci   struct tgsi_header *header )
133bf215546Sopenharmony_ci{
134bf215546Sopenharmony_ci   struct tgsi_declaration declaration;
135bf215546Sopenharmony_ci
136bf215546Sopenharmony_ci   assert( file < TGSI_FILE_COUNT );
137bf215546Sopenharmony_ci   assert( interpolate < TGSI_INTERPOLATE_COUNT );
138bf215546Sopenharmony_ci
139bf215546Sopenharmony_ci   declaration = tgsi_default_declaration();
140bf215546Sopenharmony_ci   declaration.File = file;
141bf215546Sopenharmony_ci   declaration.UsageMask = usage_mask;
142bf215546Sopenharmony_ci   declaration.Interpolate = interpolate;
143bf215546Sopenharmony_ci   declaration.Dimension = dimension;
144bf215546Sopenharmony_ci   declaration.Semantic = semantic;
145bf215546Sopenharmony_ci   declaration.Invariant = invariant;
146bf215546Sopenharmony_ci   declaration.Local = local;
147bf215546Sopenharmony_ci   declaration.Array = array;
148bf215546Sopenharmony_ci   declaration.Atomic = atomic;
149bf215546Sopenharmony_ci   declaration.MemType = mem_type;
150bf215546Sopenharmony_ci   header_bodysize_grow( header );
151bf215546Sopenharmony_ci
152bf215546Sopenharmony_ci   return declaration;
153bf215546Sopenharmony_ci}
154bf215546Sopenharmony_ci
155bf215546Sopenharmony_cistatic struct tgsi_declaration_range
156bf215546Sopenharmony_citgsi_default_declaration_range( void )
157bf215546Sopenharmony_ci{
158bf215546Sopenharmony_ci   struct tgsi_declaration_range dr;
159bf215546Sopenharmony_ci
160bf215546Sopenharmony_ci   dr.First = 0;
161bf215546Sopenharmony_ci   dr.Last = 0;
162bf215546Sopenharmony_ci
163bf215546Sopenharmony_ci   return dr;
164bf215546Sopenharmony_ci}
165bf215546Sopenharmony_ci
166bf215546Sopenharmony_cistatic struct tgsi_declaration_dimension
167bf215546Sopenharmony_citgsi_default_declaration_dimension()
168bf215546Sopenharmony_ci{
169bf215546Sopenharmony_ci   struct tgsi_declaration_dimension dim;
170bf215546Sopenharmony_ci
171bf215546Sopenharmony_ci   dim.Index2D = 0;
172bf215546Sopenharmony_ci   dim.Padding = 0;
173bf215546Sopenharmony_ci
174bf215546Sopenharmony_ci   return dim;
175bf215546Sopenharmony_ci}
176bf215546Sopenharmony_ci
177bf215546Sopenharmony_cistatic struct tgsi_declaration_range
178bf215546Sopenharmony_citgsi_build_declaration_range(
179bf215546Sopenharmony_ci   unsigned first,
180bf215546Sopenharmony_ci   unsigned last,
181bf215546Sopenharmony_ci   struct tgsi_declaration *declaration,
182bf215546Sopenharmony_ci   struct tgsi_header *header )
183bf215546Sopenharmony_ci{
184bf215546Sopenharmony_ci   struct tgsi_declaration_range declaration_range;
185bf215546Sopenharmony_ci
186bf215546Sopenharmony_ci   assert( last >= first );
187bf215546Sopenharmony_ci   assert( last <= 0xFFFF );
188bf215546Sopenharmony_ci
189bf215546Sopenharmony_ci   declaration_range.First = first;
190bf215546Sopenharmony_ci   declaration_range.Last = last;
191bf215546Sopenharmony_ci
192bf215546Sopenharmony_ci   declaration_grow( declaration, header );
193bf215546Sopenharmony_ci
194bf215546Sopenharmony_ci   return declaration_range;
195bf215546Sopenharmony_ci}
196bf215546Sopenharmony_ci
197bf215546Sopenharmony_cistatic struct tgsi_declaration_dimension
198bf215546Sopenharmony_citgsi_build_declaration_dimension(unsigned index_2d,
199bf215546Sopenharmony_ci                                 struct tgsi_declaration *declaration,
200bf215546Sopenharmony_ci                                 struct tgsi_header *header)
201bf215546Sopenharmony_ci{
202bf215546Sopenharmony_ci   struct tgsi_declaration_dimension dd;
203bf215546Sopenharmony_ci
204bf215546Sopenharmony_ci   assert(index_2d <= 0xFFFF);
205bf215546Sopenharmony_ci
206bf215546Sopenharmony_ci   dd.Index2D = index_2d;
207bf215546Sopenharmony_ci   dd.Padding = 0;
208bf215546Sopenharmony_ci
209bf215546Sopenharmony_ci   declaration_grow(declaration, header);
210bf215546Sopenharmony_ci
211bf215546Sopenharmony_ci   return dd;
212bf215546Sopenharmony_ci}
213bf215546Sopenharmony_ci
214bf215546Sopenharmony_cistatic struct tgsi_declaration_interp
215bf215546Sopenharmony_citgsi_default_declaration_interp( void )
216bf215546Sopenharmony_ci{
217bf215546Sopenharmony_ci   struct tgsi_declaration_interp di;
218bf215546Sopenharmony_ci
219bf215546Sopenharmony_ci   di.Interpolate = TGSI_INTERPOLATE_CONSTANT;
220bf215546Sopenharmony_ci   di.Location = TGSI_INTERPOLATE_LOC_CENTER;
221bf215546Sopenharmony_ci   di.Padding = 0;
222bf215546Sopenharmony_ci
223bf215546Sopenharmony_ci   return di;
224bf215546Sopenharmony_ci}
225bf215546Sopenharmony_ci
226bf215546Sopenharmony_cistatic struct tgsi_declaration_interp
227bf215546Sopenharmony_citgsi_build_declaration_interp(unsigned interpolate,
228bf215546Sopenharmony_ci                              unsigned interpolate_location,
229bf215546Sopenharmony_ci                              struct tgsi_declaration *declaration,
230bf215546Sopenharmony_ci                              struct tgsi_header *header)
231bf215546Sopenharmony_ci{
232bf215546Sopenharmony_ci   struct tgsi_declaration_interp di;
233bf215546Sopenharmony_ci
234bf215546Sopenharmony_ci   di.Interpolate = interpolate;
235bf215546Sopenharmony_ci   di.Location = interpolate_location;
236bf215546Sopenharmony_ci   di.Padding = 0;
237bf215546Sopenharmony_ci
238bf215546Sopenharmony_ci   declaration_grow(declaration, header);
239bf215546Sopenharmony_ci
240bf215546Sopenharmony_ci   return di;
241bf215546Sopenharmony_ci}
242bf215546Sopenharmony_ci
243bf215546Sopenharmony_cistatic struct tgsi_declaration_semantic
244bf215546Sopenharmony_citgsi_default_declaration_semantic( void )
245bf215546Sopenharmony_ci{
246bf215546Sopenharmony_ci   struct tgsi_declaration_semantic ds;
247bf215546Sopenharmony_ci
248bf215546Sopenharmony_ci   ds.Name = TGSI_SEMANTIC_POSITION;
249bf215546Sopenharmony_ci   ds.Index = 0;
250bf215546Sopenharmony_ci   ds.StreamX = 0;
251bf215546Sopenharmony_ci   ds.StreamY = 0;
252bf215546Sopenharmony_ci   ds.StreamZ = 0;
253bf215546Sopenharmony_ci   ds.StreamW = 0;
254bf215546Sopenharmony_ci
255bf215546Sopenharmony_ci   return ds;
256bf215546Sopenharmony_ci}
257bf215546Sopenharmony_ci
258bf215546Sopenharmony_cistatic struct tgsi_declaration_semantic
259bf215546Sopenharmony_citgsi_build_declaration_semantic(
260bf215546Sopenharmony_ci   unsigned semantic_name,
261bf215546Sopenharmony_ci   unsigned semantic_index,
262bf215546Sopenharmony_ci   unsigned streamx,
263bf215546Sopenharmony_ci   unsigned streamy,
264bf215546Sopenharmony_ci   unsigned streamz,
265bf215546Sopenharmony_ci   unsigned streamw,
266bf215546Sopenharmony_ci   struct tgsi_declaration *declaration,
267bf215546Sopenharmony_ci   struct tgsi_header *header )
268bf215546Sopenharmony_ci{
269bf215546Sopenharmony_ci   struct tgsi_declaration_semantic ds;
270bf215546Sopenharmony_ci
271bf215546Sopenharmony_ci   assert( semantic_name <= TGSI_SEMANTIC_COUNT );
272bf215546Sopenharmony_ci   assert( semantic_index <= 0xFFFF );
273bf215546Sopenharmony_ci
274bf215546Sopenharmony_ci   ds.Name = semantic_name;
275bf215546Sopenharmony_ci   ds.Index = semantic_index;
276bf215546Sopenharmony_ci   ds.StreamX = streamx;
277bf215546Sopenharmony_ci   ds.StreamY = streamy;
278bf215546Sopenharmony_ci   ds.StreamZ = streamz;
279bf215546Sopenharmony_ci   ds.StreamW = streamw;
280bf215546Sopenharmony_ci
281bf215546Sopenharmony_ci   declaration_grow( declaration, header );
282bf215546Sopenharmony_ci
283bf215546Sopenharmony_ci   return ds;
284bf215546Sopenharmony_ci}
285bf215546Sopenharmony_ci
286bf215546Sopenharmony_cistatic struct tgsi_declaration_image
287bf215546Sopenharmony_citgsi_default_declaration_image(void)
288bf215546Sopenharmony_ci{
289bf215546Sopenharmony_ci   struct tgsi_declaration_image di;
290bf215546Sopenharmony_ci
291bf215546Sopenharmony_ci   di.Resource = TGSI_TEXTURE_BUFFER;
292bf215546Sopenharmony_ci   di.Raw = 0;
293bf215546Sopenharmony_ci   di.Writable = 0;
294bf215546Sopenharmony_ci   di.Format = 0;
295bf215546Sopenharmony_ci   di.Padding = 0;
296bf215546Sopenharmony_ci
297bf215546Sopenharmony_ci   return di;
298bf215546Sopenharmony_ci}
299bf215546Sopenharmony_ci
300bf215546Sopenharmony_cistatic struct tgsi_declaration_image
301bf215546Sopenharmony_citgsi_build_declaration_image(unsigned texture,
302bf215546Sopenharmony_ci                             unsigned format,
303bf215546Sopenharmony_ci                             unsigned raw,
304bf215546Sopenharmony_ci                             unsigned writable,
305bf215546Sopenharmony_ci                             struct tgsi_declaration *declaration,
306bf215546Sopenharmony_ci                             struct tgsi_header *header)
307bf215546Sopenharmony_ci{
308bf215546Sopenharmony_ci   struct tgsi_declaration_image di;
309bf215546Sopenharmony_ci
310bf215546Sopenharmony_ci   di = tgsi_default_declaration_image();
311bf215546Sopenharmony_ci   di.Resource = texture;
312bf215546Sopenharmony_ci   di.Format = format;
313bf215546Sopenharmony_ci   di.Raw = raw;
314bf215546Sopenharmony_ci   di.Writable = writable;
315bf215546Sopenharmony_ci
316bf215546Sopenharmony_ci   declaration_grow(declaration, header);
317bf215546Sopenharmony_ci
318bf215546Sopenharmony_ci   return di;
319bf215546Sopenharmony_ci}
320bf215546Sopenharmony_ci
321bf215546Sopenharmony_cistatic struct tgsi_declaration_sampler_view
322bf215546Sopenharmony_citgsi_default_declaration_sampler_view(void)
323bf215546Sopenharmony_ci{
324bf215546Sopenharmony_ci   struct tgsi_declaration_sampler_view dsv;
325bf215546Sopenharmony_ci
326bf215546Sopenharmony_ci   dsv.Resource = TGSI_TEXTURE_BUFFER;
327bf215546Sopenharmony_ci   dsv.ReturnTypeX = TGSI_RETURN_TYPE_UNORM;
328bf215546Sopenharmony_ci   dsv.ReturnTypeY = TGSI_RETURN_TYPE_UNORM;
329bf215546Sopenharmony_ci   dsv.ReturnTypeZ = TGSI_RETURN_TYPE_UNORM;
330bf215546Sopenharmony_ci   dsv.ReturnTypeW = TGSI_RETURN_TYPE_UNORM;
331bf215546Sopenharmony_ci
332bf215546Sopenharmony_ci   return dsv;
333bf215546Sopenharmony_ci}
334bf215546Sopenharmony_ci
335bf215546Sopenharmony_cistatic struct tgsi_declaration_sampler_view
336bf215546Sopenharmony_citgsi_build_declaration_sampler_view(unsigned texture,
337bf215546Sopenharmony_ci                                    unsigned return_type_x,
338bf215546Sopenharmony_ci                                    unsigned return_type_y,
339bf215546Sopenharmony_ci                                    unsigned return_type_z,
340bf215546Sopenharmony_ci                                    unsigned return_type_w,
341bf215546Sopenharmony_ci                                    struct tgsi_declaration *declaration,
342bf215546Sopenharmony_ci                                    struct tgsi_header *header)
343bf215546Sopenharmony_ci{
344bf215546Sopenharmony_ci   struct tgsi_declaration_sampler_view dsv;
345bf215546Sopenharmony_ci
346bf215546Sopenharmony_ci   dsv = tgsi_default_declaration_sampler_view();
347bf215546Sopenharmony_ci   dsv.Resource = texture;
348bf215546Sopenharmony_ci   dsv.ReturnTypeX = return_type_x;
349bf215546Sopenharmony_ci   dsv.ReturnTypeY = return_type_y;
350bf215546Sopenharmony_ci   dsv.ReturnTypeZ = return_type_z;
351bf215546Sopenharmony_ci   dsv.ReturnTypeW = return_type_w;
352bf215546Sopenharmony_ci
353bf215546Sopenharmony_ci   declaration_grow(declaration, header);
354bf215546Sopenharmony_ci
355bf215546Sopenharmony_ci   return dsv;
356bf215546Sopenharmony_ci}
357bf215546Sopenharmony_ci
358bf215546Sopenharmony_ci
359bf215546Sopenharmony_cistatic struct tgsi_declaration_array
360bf215546Sopenharmony_citgsi_default_declaration_array( void )
361bf215546Sopenharmony_ci{
362bf215546Sopenharmony_ci   struct tgsi_declaration_array a;
363bf215546Sopenharmony_ci
364bf215546Sopenharmony_ci   a.ArrayID = 0;
365bf215546Sopenharmony_ci   a.Padding = 0;
366bf215546Sopenharmony_ci
367bf215546Sopenharmony_ci   return a;
368bf215546Sopenharmony_ci}
369bf215546Sopenharmony_ci
370bf215546Sopenharmony_cistatic struct tgsi_declaration_array
371bf215546Sopenharmony_citgsi_build_declaration_array(unsigned arrayid,
372bf215546Sopenharmony_ci                             struct tgsi_declaration *declaration,
373bf215546Sopenharmony_ci                             struct tgsi_header *header)
374bf215546Sopenharmony_ci{
375bf215546Sopenharmony_ci   struct tgsi_declaration_array da;
376bf215546Sopenharmony_ci
377bf215546Sopenharmony_ci   da = tgsi_default_declaration_array();
378bf215546Sopenharmony_ci   da.ArrayID = arrayid;
379bf215546Sopenharmony_ci
380bf215546Sopenharmony_ci   declaration_grow(declaration, header);
381bf215546Sopenharmony_ci
382bf215546Sopenharmony_ci   return da;
383bf215546Sopenharmony_ci}
384bf215546Sopenharmony_ci
385bf215546Sopenharmony_cistruct tgsi_full_declaration
386bf215546Sopenharmony_citgsi_default_full_declaration( void )
387bf215546Sopenharmony_ci{
388bf215546Sopenharmony_ci   struct tgsi_full_declaration  full_declaration;
389bf215546Sopenharmony_ci
390bf215546Sopenharmony_ci   full_declaration.Declaration  = tgsi_default_declaration();
391bf215546Sopenharmony_ci   full_declaration.Range = tgsi_default_declaration_range();
392bf215546Sopenharmony_ci   full_declaration.Dim = tgsi_default_declaration_dimension();
393bf215546Sopenharmony_ci   full_declaration.Semantic = tgsi_default_declaration_semantic();
394bf215546Sopenharmony_ci   full_declaration.Interp = tgsi_default_declaration_interp();
395bf215546Sopenharmony_ci   full_declaration.Image = tgsi_default_declaration_image();
396bf215546Sopenharmony_ci   full_declaration.SamplerView = tgsi_default_declaration_sampler_view();
397bf215546Sopenharmony_ci   full_declaration.Array = tgsi_default_declaration_array();
398bf215546Sopenharmony_ci
399bf215546Sopenharmony_ci   return full_declaration;
400bf215546Sopenharmony_ci}
401bf215546Sopenharmony_ci
402bf215546Sopenharmony_ciunsigned
403bf215546Sopenharmony_citgsi_build_full_declaration(
404bf215546Sopenharmony_ci   const struct tgsi_full_declaration *full_decl,
405bf215546Sopenharmony_ci   struct tgsi_token *tokens,
406bf215546Sopenharmony_ci   struct tgsi_header *header,
407bf215546Sopenharmony_ci   unsigned maxsize )
408bf215546Sopenharmony_ci{
409bf215546Sopenharmony_ci   unsigned size = 0;
410bf215546Sopenharmony_ci   struct tgsi_declaration *declaration;
411bf215546Sopenharmony_ci   struct tgsi_declaration_range *dr;
412bf215546Sopenharmony_ci
413bf215546Sopenharmony_ci   if( maxsize <= size )
414bf215546Sopenharmony_ci      return 0;
415bf215546Sopenharmony_ci   declaration = (struct tgsi_declaration *) &tokens[size];
416bf215546Sopenharmony_ci   size++;
417bf215546Sopenharmony_ci
418bf215546Sopenharmony_ci   *declaration = tgsi_build_declaration(
419bf215546Sopenharmony_ci      full_decl->Declaration.File,
420bf215546Sopenharmony_ci      full_decl->Declaration.UsageMask,
421bf215546Sopenharmony_ci      full_decl->Declaration.Interpolate,
422bf215546Sopenharmony_ci      full_decl->Declaration.Dimension,
423bf215546Sopenharmony_ci      full_decl->Declaration.Semantic,
424bf215546Sopenharmony_ci      full_decl->Declaration.Invariant,
425bf215546Sopenharmony_ci      full_decl->Declaration.Local,
426bf215546Sopenharmony_ci      full_decl->Declaration.Array,
427bf215546Sopenharmony_ci      full_decl->Declaration.Atomic,
428bf215546Sopenharmony_ci      full_decl->Declaration.MemType,
429bf215546Sopenharmony_ci      header );
430bf215546Sopenharmony_ci
431bf215546Sopenharmony_ci   if (maxsize <= size)
432bf215546Sopenharmony_ci      return 0;
433bf215546Sopenharmony_ci   dr = (struct tgsi_declaration_range *) &tokens[size];
434bf215546Sopenharmony_ci   size++;
435bf215546Sopenharmony_ci
436bf215546Sopenharmony_ci   *dr = tgsi_build_declaration_range(
437bf215546Sopenharmony_ci      full_decl->Range.First,
438bf215546Sopenharmony_ci      full_decl->Range.Last,
439bf215546Sopenharmony_ci      declaration,
440bf215546Sopenharmony_ci      header );
441bf215546Sopenharmony_ci
442bf215546Sopenharmony_ci   if (full_decl->Declaration.Dimension) {
443bf215546Sopenharmony_ci      struct tgsi_declaration_dimension *dd;
444bf215546Sopenharmony_ci
445bf215546Sopenharmony_ci      if (maxsize <= size) {
446bf215546Sopenharmony_ci         return 0;
447bf215546Sopenharmony_ci      }
448bf215546Sopenharmony_ci      dd = (struct tgsi_declaration_dimension *)&tokens[size];
449bf215546Sopenharmony_ci      size++;
450bf215546Sopenharmony_ci
451bf215546Sopenharmony_ci      *dd = tgsi_build_declaration_dimension(full_decl->Dim.Index2D,
452bf215546Sopenharmony_ci                                             declaration,
453bf215546Sopenharmony_ci                                             header);
454bf215546Sopenharmony_ci   }
455bf215546Sopenharmony_ci
456bf215546Sopenharmony_ci   if (full_decl->Declaration.Interpolate) {
457bf215546Sopenharmony_ci      struct tgsi_declaration_interp *di;
458bf215546Sopenharmony_ci
459bf215546Sopenharmony_ci      if (maxsize <= size) {
460bf215546Sopenharmony_ci         return 0;
461bf215546Sopenharmony_ci      }
462bf215546Sopenharmony_ci      di = (struct tgsi_declaration_interp *)&tokens[size];
463bf215546Sopenharmony_ci      size++;
464bf215546Sopenharmony_ci
465bf215546Sopenharmony_ci      *di = tgsi_build_declaration_interp(full_decl->Interp.Interpolate,
466bf215546Sopenharmony_ci                                          full_decl->Interp.Location,
467bf215546Sopenharmony_ci                                          declaration,
468bf215546Sopenharmony_ci                                          header);
469bf215546Sopenharmony_ci   }
470bf215546Sopenharmony_ci
471bf215546Sopenharmony_ci   if( full_decl->Declaration.Semantic ) {
472bf215546Sopenharmony_ci      struct tgsi_declaration_semantic *ds;
473bf215546Sopenharmony_ci
474bf215546Sopenharmony_ci      if( maxsize <= size )
475bf215546Sopenharmony_ci         return  0;
476bf215546Sopenharmony_ci      ds = (struct tgsi_declaration_semantic *) &tokens[size];
477bf215546Sopenharmony_ci      size++;
478bf215546Sopenharmony_ci
479bf215546Sopenharmony_ci      *ds = tgsi_build_declaration_semantic(
480bf215546Sopenharmony_ci         full_decl->Semantic.Name,
481bf215546Sopenharmony_ci         full_decl->Semantic.Index,
482bf215546Sopenharmony_ci         full_decl->Semantic.StreamX,
483bf215546Sopenharmony_ci         full_decl->Semantic.StreamY,
484bf215546Sopenharmony_ci         full_decl->Semantic.StreamZ,
485bf215546Sopenharmony_ci         full_decl->Semantic.StreamW,
486bf215546Sopenharmony_ci         declaration,
487bf215546Sopenharmony_ci         header );
488bf215546Sopenharmony_ci   }
489bf215546Sopenharmony_ci
490bf215546Sopenharmony_ci   if (full_decl->Declaration.File == TGSI_FILE_IMAGE) {
491bf215546Sopenharmony_ci      struct tgsi_declaration_image *di;
492bf215546Sopenharmony_ci
493bf215546Sopenharmony_ci      if (maxsize <= size) {
494bf215546Sopenharmony_ci         return  0;
495bf215546Sopenharmony_ci      }
496bf215546Sopenharmony_ci      di = (struct tgsi_declaration_image *)&tokens[size];
497bf215546Sopenharmony_ci      size++;
498bf215546Sopenharmony_ci
499bf215546Sopenharmony_ci      *di = tgsi_build_declaration_image(full_decl->Image.Resource,
500bf215546Sopenharmony_ci                                         full_decl->Image.Format,
501bf215546Sopenharmony_ci                                         full_decl->Image.Raw,
502bf215546Sopenharmony_ci                                         full_decl->Image.Writable,
503bf215546Sopenharmony_ci                                         declaration,
504bf215546Sopenharmony_ci                                         header);
505bf215546Sopenharmony_ci   }
506bf215546Sopenharmony_ci
507bf215546Sopenharmony_ci   if (full_decl->Declaration.File == TGSI_FILE_SAMPLER_VIEW) {
508bf215546Sopenharmony_ci      struct tgsi_declaration_sampler_view *dsv;
509bf215546Sopenharmony_ci
510bf215546Sopenharmony_ci      if (maxsize <= size) {
511bf215546Sopenharmony_ci         return  0;
512bf215546Sopenharmony_ci      }
513bf215546Sopenharmony_ci      dsv = (struct tgsi_declaration_sampler_view *)&tokens[size];
514bf215546Sopenharmony_ci      size++;
515bf215546Sopenharmony_ci
516bf215546Sopenharmony_ci      *dsv = tgsi_build_declaration_sampler_view(
517bf215546Sopenharmony_ci         full_decl->SamplerView.Resource,
518bf215546Sopenharmony_ci         full_decl->SamplerView.ReturnTypeX,
519bf215546Sopenharmony_ci         full_decl->SamplerView.ReturnTypeY,
520bf215546Sopenharmony_ci         full_decl->SamplerView.ReturnTypeZ,
521bf215546Sopenharmony_ci         full_decl->SamplerView.ReturnTypeW,
522bf215546Sopenharmony_ci         declaration,
523bf215546Sopenharmony_ci         header);
524bf215546Sopenharmony_ci   }
525bf215546Sopenharmony_ci
526bf215546Sopenharmony_ci   if (full_decl->Declaration.Array) {
527bf215546Sopenharmony_ci      struct tgsi_declaration_array *da;
528bf215546Sopenharmony_ci
529bf215546Sopenharmony_ci      if (maxsize <= size) {
530bf215546Sopenharmony_ci         return 0;
531bf215546Sopenharmony_ci      }
532bf215546Sopenharmony_ci      da = (struct tgsi_declaration_array *)&tokens[size];
533bf215546Sopenharmony_ci      size++;
534bf215546Sopenharmony_ci      *da = tgsi_build_declaration_array(
535bf215546Sopenharmony_ci         full_decl->Array.ArrayID,
536bf215546Sopenharmony_ci         declaration,
537bf215546Sopenharmony_ci         header);
538bf215546Sopenharmony_ci   }
539bf215546Sopenharmony_ci   return size;
540bf215546Sopenharmony_ci}
541bf215546Sopenharmony_ci
542bf215546Sopenharmony_ci/*
543bf215546Sopenharmony_ci * immediate
544bf215546Sopenharmony_ci */
545bf215546Sopenharmony_ci
546bf215546Sopenharmony_cistatic struct tgsi_immediate
547bf215546Sopenharmony_citgsi_default_immediate( void )
548bf215546Sopenharmony_ci{
549bf215546Sopenharmony_ci   struct tgsi_immediate immediate;
550bf215546Sopenharmony_ci
551bf215546Sopenharmony_ci   immediate.Type = TGSI_TOKEN_TYPE_IMMEDIATE;
552bf215546Sopenharmony_ci   immediate.NrTokens = 1;
553bf215546Sopenharmony_ci   immediate.DataType = TGSI_IMM_FLOAT32;
554bf215546Sopenharmony_ci   immediate.Padding = 0;
555bf215546Sopenharmony_ci
556bf215546Sopenharmony_ci   return immediate;
557bf215546Sopenharmony_ci}
558bf215546Sopenharmony_ci
559bf215546Sopenharmony_cistatic struct tgsi_immediate
560bf215546Sopenharmony_citgsi_build_immediate(
561bf215546Sopenharmony_ci   struct tgsi_header *header,
562bf215546Sopenharmony_ci   unsigned type )
563bf215546Sopenharmony_ci{
564bf215546Sopenharmony_ci   struct tgsi_immediate immediate;
565bf215546Sopenharmony_ci
566bf215546Sopenharmony_ci   immediate = tgsi_default_immediate();
567bf215546Sopenharmony_ci   immediate.DataType = type;
568bf215546Sopenharmony_ci
569bf215546Sopenharmony_ci   header_bodysize_grow( header );
570bf215546Sopenharmony_ci
571bf215546Sopenharmony_ci   return immediate;
572bf215546Sopenharmony_ci}
573bf215546Sopenharmony_ci
574bf215546Sopenharmony_cistruct tgsi_full_immediate
575bf215546Sopenharmony_citgsi_default_full_immediate( void )
576bf215546Sopenharmony_ci{
577bf215546Sopenharmony_ci   struct tgsi_full_immediate fullimm;
578bf215546Sopenharmony_ci
579bf215546Sopenharmony_ci   fullimm.Immediate = tgsi_default_immediate();
580bf215546Sopenharmony_ci   fullimm.u[0].Float = 0.0f;
581bf215546Sopenharmony_ci   fullimm.u[1].Float = 0.0f;
582bf215546Sopenharmony_ci   fullimm.u[2].Float = 0.0f;
583bf215546Sopenharmony_ci   fullimm.u[3].Float = 0.0f;
584bf215546Sopenharmony_ci
585bf215546Sopenharmony_ci   return fullimm;
586bf215546Sopenharmony_ci}
587bf215546Sopenharmony_ci
588bf215546Sopenharmony_cistatic void
589bf215546Sopenharmony_ciimmediate_grow(
590bf215546Sopenharmony_ci   struct tgsi_immediate *immediate,
591bf215546Sopenharmony_ci   struct tgsi_header *header )
592bf215546Sopenharmony_ci{
593bf215546Sopenharmony_ci   assert( immediate->NrTokens < 0xFF );
594bf215546Sopenharmony_ci
595bf215546Sopenharmony_ci   immediate->NrTokens++;
596bf215546Sopenharmony_ci
597bf215546Sopenharmony_ci   header_bodysize_grow( header );
598bf215546Sopenharmony_ci}
599bf215546Sopenharmony_ci
600bf215546Sopenharmony_ciunsigned
601bf215546Sopenharmony_citgsi_build_full_immediate(
602bf215546Sopenharmony_ci   const struct tgsi_full_immediate *full_imm,
603bf215546Sopenharmony_ci   struct tgsi_token *tokens,
604bf215546Sopenharmony_ci   struct tgsi_header *header,
605bf215546Sopenharmony_ci   unsigned maxsize )
606bf215546Sopenharmony_ci{
607bf215546Sopenharmony_ci   unsigned size = 0;
608bf215546Sopenharmony_ci   int i;
609bf215546Sopenharmony_ci   struct tgsi_immediate *immediate;
610bf215546Sopenharmony_ci
611bf215546Sopenharmony_ci   if( maxsize <= size )
612bf215546Sopenharmony_ci      return 0;
613bf215546Sopenharmony_ci   immediate = (struct tgsi_immediate *) &tokens[size];
614bf215546Sopenharmony_ci   size++;
615bf215546Sopenharmony_ci
616bf215546Sopenharmony_ci   *immediate = tgsi_build_immediate( header, full_imm->Immediate.DataType );
617bf215546Sopenharmony_ci
618bf215546Sopenharmony_ci   assert( full_imm->Immediate.NrTokens <= 4 + 1 );
619bf215546Sopenharmony_ci
620bf215546Sopenharmony_ci   for( i = 0; i < full_imm->Immediate.NrTokens - 1; i++ ) {
621bf215546Sopenharmony_ci      union tgsi_immediate_data *data;
622bf215546Sopenharmony_ci
623bf215546Sopenharmony_ci      if( maxsize <= size )
624bf215546Sopenharmony_ci         return  0;
625bf215546Sopenharmony_ci
626bf215546Sopenharmony_ci      data = (union tgsi_immediate_data *) &tokens[size];
627bf215546Sopenharmony_ci      *data = full_imm->u[i];
628bf215546Sopenharmony_ci
629bf215546Sopenharmony_ci      immediate_grow( immediate, header );
630bf215546Sopenharmony_ci      size++;
631bf215546Sopenharmony_ci   }
632bf215546Sopenharmony_ci
633bf215546Sopenharmony_ci   return size;
634bf215546Sopenharmony_ci}
635bf215546Sopenharmony_ci
636bf215546Sopenharmony_ci/*
637bf215546Sopenharmony_ci * instruction
638bf215546Sopenharmony_ci */
639bf215546Sopenharmony_ci
640bf215546Sopenharmony_cistruct tgsi_instruction
641bf215546Sopenharmony_citgsi_default_instruction( void )
642bf215546Sopenharmony_ci{
643bf215546Sopenharmony_ci   struct tgsi_instruction instruction;
644bf215546Sopenharmony_ci
645bf215546Sopenharmony_ci   instruction.Type = TGSI_TOKEN_TYPE_INSTRUCTION;
646bf215546Sopenharmony_ci   instruction.NrTokens = 0;
647bf215546Sopenharmony_ci   instruction.Opcode = TGSI_OPCODE_MOV;
648bf215546Sopenharmony_ci   instruction.Saturate = 0;
649bf215546Sopenharmony_ci   instruction.NumDstRegs = 1;
650bf215546Sopenharmony_ci   instruction.NumSrcRegs = 1;
651bf215546Sopenharmony_ci   instruction.Label = 0;
652bf215546Sopenharmony_ci   instruction.Texture = 0;
653bf215546Sopenharmony_ci   instruction.Memory = 0;
654bf215546Sopenharmony_ci   instruction.Precise = 0;
655bf215546Sopenharmony_ci   instruction.Padding = 0;
656bf215546Sopenharmony_ci
657bf215546Sopenharmony_ci   return instruction;
658bf215546Sopenharmony_ci}
659bf215546Sopenharmony_ci
660bf215546Sopenharmony_cistatic struct tgsi_instruction
661bf215546Sopenharmony_citgsi_build_instruction(enum tgsi_opcode opcode,
662bf215546Sopenharmony_ci                       unsigned saturate,
663bf215546Sopenharmony_ci                       unsigned precise,
664bf215546Sopenharmony_ci                       unsigned num_dst_regs,
665bf215546Sopenharmony_ci                       unsigned num_src_regs,
666bf215546Sopenharmony_ci                       struct tgsi_header *header)
667bf215546Sopenharmony_ci{
668bf215546Sopenharmony_ci   struct tgsi_instruction instruction;
669bf215546Sopenharmony_ci
670bf215546Sopenharmony_ci   assert (opcode <= TGSI_OPCODE_LAST);
671bf215546Sopenharmony_ci   assert (saturate <= 1);
672bf215546Sopenharmony_ci   assert (num_dst_regs <= 3);
673bf215546Sopenharmony_ci   assert (num_src_regs <= 15);
674bf215546Sopenharmony_ci
675bf215546Sopenharmony_ci   instruction = tgsi_default_instruction();
676bf215546Sopenharmony_ci   instruction.Opcode = opcode;
677bf215546Sopenharmony_ci   instruction.Saturate = saturate;
678bf215546Sopenharmony_ci   instruction.Precise = precise;
679bf215546Sopenharmony_ci   instruction.NumDstRegs = num_dst_regs;
680bf215546Sopenharmony_ci   instruction.NumSrcRegs = num_src_regs;
681bf215546Sopenharmony_ci
682bf215546Sopenharmony_ci   header_bodysize_grow( header );
683bf215546Sopenharmony_ci
684bf215546Sopenharmony_ci   return instruction;
685bf215546Sopenharmony_ci}
686bf215546Sopenharmony_ci
687bf215546Sopenharmony_cistatic void
688bf215546Sopenharmony_ciinstruction_grow(
689bf215546Sopenharmony_ci   struct tgsi_instruction *instruction,
690bf215546Sopenharmony_ci   struct tgsi_header *header )
691bf215546Sopenharmony_ci{
692bf215546Sopenharmony_ci   assert (instruction->NrTokens <   0xFF);
693bf215546Sopenharmony_ci
694bf215546Sopenharmony_ci   instruction->NrTokens++;
695bf215546Sopenharmony_ci
696bf215546Sopenharmony_ci   header_bodysize_grow( header );
697bf215546Sopenharmony_ci}
698bf215546Sopenharmony_ci
699bf215546Sopenharmony_cistatic struct tgsi_instruction_label
700bf215546Sopenharmony_citgsi_default_instruction_label( void )
701bf215546Sopenharmony_ci{
702bf215546Sopenharmony_ci   struct tgsi_instruction_label instruction_label;
703bf215546Sopenharmony_ci
704bf215546Sopenharmony_ci   instruction_label.Label = 0;
705bf215546Sopenharmony_ci   instruction_label.Padding = 0;
706bf215546Sopenharmony_ci
707bf215546Sopenharmony_ci   return instruction_label;
708bf215546Sopenharmony_ci}
709bf215546Sopenharmony_ci
710bf215546Sopenharmony_cistatic struct tgsi_instruction_label
711bf215546Sopenharmony_citgsi_build_instruction_label(
712bf215546Sopenharmony_ci   unsigned label,
713bf215546Sopenharmony_ci   struct tgsi_instruction *instruction,
714bf215546Sopenharmony_ci   struct tgsi_header *header )
715bf215546Sopenharmony_ci{
716bf215546Sopenharmony_ci   struct tgsi_instruction_label instruction_label;
717bf215546Sopenharmony_ci
718bf215546Sopenharmony_ci   instruction_label.Label = label;
719bf215546Sopenharmony_ci   instruction_label.Padding = 0;
720bf215546Sopenharmony_ci   instruction->Label = 1;
721bf215546Sopenharmony_ci
722bf215546Sopenharmony_ci   instruction_grow( instruction, header );
723bf215546Sopenharmony_ci
724bf215546Sopenharmony_ci   return instruction_label;
725bf215546Sopenharmony_ci}
726bf215546Sopenharmony_ci
727bf215546Sopenharmony_cistatic struct tgsi_instruction_texture
728bf215546Sopenharmony_citgsi_default_instruction_texture( void )
729bf215546Sopenharmony_ci{
730bf215546Sopenharmony_ci   struct tgsi_instruction_texture instruction_texture;
731bf215546Sopenharmony_ci
732bf215546Sopenharmony_ci   instruction_texture.Texture = TGSI_TEXTURE_UNKNOWN;
733bf215546Sopenharmony_ci   instruction_texture.NumOffsets = 0;
734bf215546Sopenharmony_ci   instruction_texture.ReturnType = TGSI_RETURN_TYPE_UNKNOWN;
735bf215546Sopenharmony_ci   instruction_texture.Padding = 0;
736bf215546Sopenharmony_ci
737bf215546Sopenharmony_ci   return instruction_texture;
738bf215546Sopenharmony_ci}
739bf215546Sopenharmony_ci
740bf215546Sopenharmony_cistatic struct tgsi_instruction_texture
741bf215546Sopenharmony_citgsi_build_instruction_texture(
742bf215546Sopenharmony_ci   unsigned texture,
743bf215546Sopenharmony_ci   unsigned num_offsets,
744bf215546Sopenharmony_ci   unsigned return_type,
745bf215546Sopenharmony_ci   struct tgsi_instruction *instruction,
746bf215546Sopenharmony_ci   struct tgsi_header *header )
747bf215546Sopenharmony_ci{
748bf215546Sopenharmony_ci   struct tgsi_instruction_texture instruction_texture;
749bf215546Sopenharmony_ci
750bf215546Sopenharmony_ci   instruction_texture.Texture = texture;
751bf215546Sopenharmony_ci   instruction_texture.NumOffsets = num_offsets;
752bf215546Sopenharmony_ci   instruction_texture.ReturnType = return_type;
753bf215546Sopenharmony_ci   instruction_texture.Padding = 0;
754bf215546Sopenharmony_ci   instruction->Texture = 1;
755bf215546Sopenharmony_ci
756bf215546Sopenharmony_ci   instruction_grow( instruction, header );
757bf215546Sopenharmony_ci
758bf215546Sopenharmony_ci   return instruction_texture;
759bf215546Sopenharmony_ci}
760bf215546Sopenharmony_ci
761bf215546Sopenharmony_cistatic struct tgsi_instruction_memory
762bf215546Sopenharmony_citgsi_default_instruction_memory( void )
763bf215546Sopenharmony_ci{
764bf215546Sopenharmony_ci   struct tgsi_instruction_memory instruction_memory;
765bf215546Sopenharmony_ci
766bf215546Sopenharmony_ci   instruction_memory.Qualifier = 0;
767bf215546Sopenharmony_ci   instruction_memory.Texture = 0;
768bf215546Sopenharmony_ci   instruction_memory.Format = 0;
769bf215546Sopenharmony_ci   instruction_memory.Padding = 0;
770bf215546Sopenharmony_ci
771bf215546Sopenharmony_ci   return instruction_memory;
772bf215546Sopenharmony_ci}
773bf215546Sopenharmony_ci
774bf215546Sopenharmony_cistatic struct tgsi_instruction_memory
775bf215546Sopenharmony_citgsi_build_instruction_memory(
776bf215546Sopenharmony_ci   unsigned qualifier,
777bf215546Sopenharmony_ci   unsigned texture,
778bf215546Sopenharmony_ci   unsigned format,
779bf215546Sopenharmony_ci   struct tgsi_instruction *instruction,
780bf215546Sopenharmony_ci   struct tgsi_header *header )
781bf215546Sopenharmony_ci{
782bf215546Sopenharmony_ci   struct tgsi_instruction_memory instruction_memory;
783bf215546Sopenharmony_ci
784bf215546Sopenharmony_ci   instruction_memory.Qualifier = qualifier;
785bf215546Sopenharmony_ci   instruction_memory.Texture = texture;
786bf215546Sopenharmony_ci   instruction_memory.Format = format;
787bf215546Sopenharmony_ci   instruction_memory.Padding = 0;
788bf215546Sopenharmony_ci   instruction->Memory = 1;
789bf215546Sopenharmony_ci
790bf215546Sopenharmony_ci   instruction_grow( instruction, header );
791bf215546Sopenharmony_ci
792bf215546Sopenharmony_ci   return instruction_memory;
793bf215546Sopenharmony_ci}
794bf215546Sopenharmony_ci
795bf215546Sopenharmony_cistatic struct tgsi_texture_offset
796bf215546Sopenharmony_citgsi_default_texture_offset( void )
797bf215546Sopenharmony_ci{
798bf215546Sopenharmony_ci   struct tgsi_texture_offset texture_offset;
799bf215546Sopenharmony_ci
800bf215546Sopenharmony_ci   texture_offset.Index = 0;
801bf215546Sopenharmony_ci   texture_offset.File = 0;
802bf215546Sopenharmony_ci   texture_offset.SwizzleX = 0;
803bf215546Sopenharmony_ci   texture_offset.SwizzleY = 0;
804bf215546Sopenharmony_ci   texture_offset.SwizzleZ = 0;
805bf215546Sopenharmony_ci   texture_offset.Padding = 0;
806bf215546Sopenharmony_ci
807bf215546Sopenharmony_ci   return texture_offset;
808bf215546Sopenharmony_ci}
809bf215546Sopenharmony_ci
810bf215546Sopenharmony_cistatic struct tgsi_texture_offset
811bf215546Sopenharmony_citgsi_build_texture_offset(
812bf215546Sopenharmony_ci   int index, int file, int swizzle_x, int swizzle_y, int swizzle_z,
813bf215546Sopenharmony_ci   struct tgsi_instruction *instruction,
814bf215546Sopenharmony_ci   struct tgsi_header *header )
815bf215546Sopenharmony_ci{
816bf215546Sopenharmony_ci   struct tgsi_texture_offset texture_offset;
817bf215546Sopenharmony_ci
818bf215546Sopenharmony_ci   texture_offset.Index = index;
819bf215546Sopenharmony_ci   texture_offset.File = file;
820bf215546Sopenharmony_ci   texture_offset.SwizzleX = swizzle_x;
821bf215546Sopenharmony_ci   texture_offset.SwizzleY = swizzle_y;
822bf215546Sopenharmony_ci   texture_offset.SwizzleZ = swizzle_z;
823bf215546Sopenharmony_ci   texture_offset.Padding = 0;
824bf215546Sopenharmony_ci
825bf215546Sopenharmony_ci   instruction_grow( instruction, header );
826bf215546Sopenharmony_ci
827bf215546Sopenharmony_ci   return texture_offset;
828bf215546Sopenharmony_ci}
829bf215546Sopenharmony_ci
830bf215546Sopenharmony_cistatic struct tgsi_src_register
831bf215546Sopenharmony_citgsi_default_src_register( void )
832bf215546Sopenharmony_ci{
833bf215546Sopenharmony_ci   struct tgsi_src_register src_register;
834bf215546Sopenharmony_ci
835bf215546Sopenharmony_ci   src_register.File = TGSI_FILE_NULL;
836bf215546Sopenharmony_ci   src_register.SwizzleX = TGSI_SWIZZLE_X;
837bf215546Sopenharmony_ci   src_register.SwizzleY = TGSI_SWIZZLE_Y;
838bf215546Sopenharmony_ci   src_register.SwizzleZ = TGSI_SWIZZLE_Z;
839bf215546Sopenharmony_ci   src_register.SwizzleW = TGSI_SWIZZLE_W;
840bf215546Sopenharmony_ci   src_register.Negate = 0;
841bf215546Sopenharmony_ci   src_register.Absolute = 0;
842bf215546Sopenharmony_ci   src_register.Indirect = 0;
843bf215546Sopenharmony_ci   src_register.Dimension = 0;
844bf215546Sopenharmony_ci   src_register.Index = 0;
845bf215546Sopenharmony_ci
846bf215546Sopenharmony_ci   return src_register;
847bf215546Sopenharmony_ci}
848bf215546Sopenharmony_ci
849bf215546Sopenharmony_cistatic struct tgsi_src_register
850bf215546Sopenharmony_citgsi_build_src_register(
851bf215546Sopenharmony_ci   unsigned file,
852bf215546Sopenharmony_ci   unsigned swizzle_x,
853bf215546Sopenharmony_ci   unsigned swizzle_y,
854bf215546Sopenharmony_ci   unsigned swizzle_z,
855bf215546Sopenharmony_ci   unsigned swizzle_w,
856bf215546Sopenharmony_ci   unsigned negate,
857bf215546Sopenharmony_ci   unsigned absolute,
858bf215546Sopenharmony_ci   unsigned indirect,
859bf215546Sopenharmony_ci   unsigned dimension,
860bf215546Sopenharmony_ci   int index,
861bf215546Sopenharmony_ci   struct tgsi_instruction *instruction,
862bf215546Sopenharmony_ci   struct tgsi_header *header )
863bf215546Sopenharmony_ci{
864bf215546Sopenharmony_ci   struct tgsi_src_register   src_register;
865bf215546Sopenharmony_ci
866bf215546Sopenharmony_ci   assert( file < TGSI_FILE_COUNT );
867bf215546Sopenharmony_ci   assert( swizzle_x <= TGSI_SWIZZLE_W );
868bf215546Sopenharmony_ci   assert( swizzle_y <= TGSI_SWIZZLE_W );
869bf215546Sopenharmony_ci   assert( swizzle_z <= TGSI_SWIZZLE_W );
870bf215546Sopenharmony_ci   assert( swizzle_w <= TGSI_SWIZZLE_W );
871bf215546Sopenharmony_ci   assert( negate <= 1 );
872bf215546Sopenharmony_ci   assert( index >= -0x8000 && index <= 0x7FFF );
873bf215546Sopenharmony_ci
874bf215546Sopenharmony_ci   src_register.File = file;
875bf215546Sopenharmony_ci   src_register.SwizzleX = swizzle_x;
876bf215546Sopenharmony_ci   src_register.SwizzleY = swizzle_y;
877bf215546Sopenharmony_ci   src_register.SwizzleZ = swizzle_z;
878bf215546Sopenharmony_ci   src_register.SwizzleW = swizzle_w;
879bf215546Sopenharmony_ci   src_register.Negate = negate;
880bf215546Sopenharmony_ci   src_register.Absolute = absolute;
881bf215546Sopenharmony_ci   src_register.Indirect = indirect;
882bf215546Sopenharmony_ci   src_register.Dimension = dimension;
883bf215546Sopenharmony_ci   src_register.Index = index;
884bf215546Sopenharmony_ci
885bf215546Sopenharmony_ci   instruction_grow( instruction, header );
886bf215546Sopenharmony_ci
887bf215546Sopenharmony_ci   return src_register;
888bf215546Sopenharmony_ci}
889bf215546Sopenharmony_ci
890bf215546Sopenharmony_cistatic struct tgsi_ind_register
891bf215546Sopenharmony_citgsi_default_ind_register( void )
892bf215546Sopenharmony_ci{
893bf215546Sopenharmony_ci   struct tgsi_ind_register ind_register;
894bf215546Sopenharmony_ci
895bf215546Sopenharmony_ci   ind_register.File = TGSI_FILE_NULL;
896bf215546Sopenharmony_ci   ind_register.Index = 0;
897bf215546Sopenharmony_ci   ind_register.Swizzle = TGSI_SWIZZLE_X;
898bf215546Sopenharmony_ci   ind_register.ArrayID = 0;
899bf215546Sopenharmony_ci
900bf215546Sopenharmony_ci   return ind_register;
901bf215546Sopenharmony_ci}
902bf215546Sopenharmony_ci
903bf215546Sopenharmony_cistatic struct tgsi_ind_register
904bf215546Sopenharmony_citgsi_build_ind_register(
905bf215546Sopenharmony_ci   unsigned file,
906bf215546Sopenharmony_ci   unsigned swizzle,
907bf215546Sopenharmony_ci   int index,
908bf215546Sopenharmony_ci   unsigned arrayid,
909bf215546Sopenharmony_ci   struct tgsi_instruction *instruction,
910bf215546Sopenharmony_ci   struct tgsi_header *header )
911bf215546Sopenharmony_ci{
912bf215546Sopenharmony_ci   struct tgsi_ind_register   ind_register;
913bf215546Sopenharmony_ci
914bf215546Sopenharmony_ci   assert( file < TGSI_FILE_COUNT );
915bf215546Sopenharmony_ci   assert( swizzle <= TGSI_SWIZZLE_W );
916bf215546Sopenharmony_ci   assert( index >= -0x8000 && index <= 0x7FFF );
917bf215546Sopenharmony_ci
918bf215546Sopenharmony_ci   ind_register.File = file;
919bf215546Sopenharmony_ci   ind_register.Swizzle = swizzle;
920bf215546Sopenharmony_ci   ind_register.Index = index;
921bf215546Sopenharmony_ci   ind_register.ArrayID = arrayid;
922bf215546Sopenharmony_ci
923bf215546Sopenharmony_ci   instruction_grow( instruction, header );
924bf215546Sopenharmony_ci
925bf215546Sopenharmony_ci   return ind_register;
926bf215546Sopenharmony_ci}
927bf215546Sopenharmony_ci
928bf215546Sopenharmony_cistatic struct tgsi_dimension
929bf215546Sopenharmony_citgsi_default_dimension( void )
930bf215546Sopenharmony_ci{
931bf215546Sopenharmony_ci   struct tgsi_dimension dimension;
932bf215546Sopenharmony_ci
933bf215546Sopenharmony_ci   dimension.Indirect = 0;
934bf215546Sopenharmony_ci   dimension.Dimension = 0;
935bf215546Sopenharmony_ci   dimension.Padding = 0;
936bf215546Sopenharmony_ci   dimension.Index = 0;
937bf215546Sopenharmony_ci
938bf215546Sopenharmony_ci   return dimension;
939bf215546Sopenharmony_ci}
940bf215546Sopenharmony_ci
941bf215546Sopenharmony_cistatic struct tgsi_full_src_register
942bf215546Sopenharmony_citgsi_default_full_src_register( void )
943bf215546Sopenharmony_ci{
944bf215546Sopenharmony_ci   struct tgsi_full_src_register full_src_register;
945bf215546Sopenharmony_ci
946bf215546Sopenharmony_ci   full_src_register.Register = tgsi_default_src_register();
947bf215546Sopenharmony_ci   full_src_register.Indirect = tgsi_default_ind_register();
948bf215546Sopenharmony_ci   full_src_register.Dimension = tgsi_default_dimension();
949bf215546Sopenharmony_ci   full_src_register.DimIndirect = tgsi_default_ind_register();
950bf215546Sopenharmony_ci
951bf215546Sopenharmony_ci   return full_src_register;
952bf215546Sopenharmony_ci}
953bf215546Sopenharmony_ci
954bf215546Sopenharmony_cistatic struct tgsi_dimension
955bf215546Sopenharmony_citgsi_build_dimension(
956bf215546Sopenharmony_ci   unsigned indirect,
957bf215546Sopenharmony_ci   unsigned index,
958bf215546Sopenharmony_ci   struct tgsi_instruction *instruction,
959bf215546Sopenharmony_ci   struct tgsi_header *header )
960bf215546Sopenharmony_ci{
961bf215546Sopenharmony_ci   struct tgsi_dimension dimension;
962bf215546Sopenharmony_ci
963bf215546Sopenharmony_ci   dimension.Indirect = indirect;
964bf215546Sopenharmony_ci   dimension.Dimension = 0;
965bf215546Sopenharmony_ci   dimension.Padding = 0;
966bf215546Sopenharmony_ci   dimension.Index = index;
967bf215546Sopenharmony_ci
968bf215546Sopenharmony_ci   instruction_grow( instruction, header );
969bf215546Sopenharmony_ci
970bf215546Sopenharmony_ci   return dimension;
971bf215546Sopenharmony_ci}
972bf215546Sopenharmony_ci
973bf215546Sopenharmony_cistatic struct tgsi_dst_register
974bf215546Sopenharmony_citgsi_default_dst_register( void )
975bf215546Sopenharmony_ci{
976bf215546Sopenharmony_ci   struct tgsi_dst_register dst_register;
977bf215546Sopenharmony_ci
978bf215546Sopenharmony_ci   dst_register.File = TGSI_FILE_NULL;
979bf215546Sopenharmony_ci   dst_register.WriteMask = TGSI_WRITEMASK_XYZW;
980bf215546Sopenharmony_ci   dst_register.Indirect = 0;
981bf215546Sopenharmony_ci   dst_register.Dimension = 0;
982bf215546Sopenharmony_ci   dst_register.Index = 0;
983bf215546Sopenharmony_ci   dst_register.Padding = 0;
984bf215546Sopenharmony_ci
985bf215546Sopenharmony_ci   return dst_register;
986bf215546Sopenharmony_ci}
987bf215546Sopenharmony_ci
988bf215546Sopenharmony_cistatic struct tgsi_dst_register
989bf215546Sopenharmony_citgsi_build_dst_register(
990bf215546Sopenharmony_ci   unsigned file,
991bf215546Sopenharmony_ci   unsigned mask,
992bf215546Sopenharmony_ci   unsigned indirect,
993bf215546Sopenharmony_ci   unsigned dimension,
994bf215546Sopenharmony_ci   int index,
995bf215546Sopenharmony_ci   struct tgsi_instruction *instruction,
996bf215546Sopenharmony_ci   struct tgsi_header *header )
997bf215546Sopenharmony_ci{
998bf215546Sopenharmony_ci   struct tgsi_dst_register dst_register;
999bf215546Sopenharmony_ci
1000bf215546Sopenharmony_ci   assert( file < TGSI_FILE_COUNT );
1001bf215546Sopenharmony_ci   assert( mask <= TGSI_WRITEMASK_XYZW );
1002bf215546Sopenharmony_ci   assert( index >= -32768 && index <= 32767 );
1003bf215546Sopenharmony_ci
1004bf215546Sopenharmony_ci   dst_register.File = file;
1005bf215546Sopenharmony_ci   dst_register.WriteMask = mask;
1006bf215546Sopenharmony_ci   dst_register.Indirect = indirect;
1007bf215546Sopenharmony_ci   dst_register.Dimension = dimension;
1008bf215546Sopenharmony_ci   dst_register.Index = index;
1009bf215546Sopenharmony_ci   dst_register.Padding = 0;
1010bf215546Sopenharmony_ci
1011bf215546Sopenharmony_ci   instruction_grow( instruction, header );
1012bf215546Sopenharmony_ci
1013bf215546Sopenharmony_ci   return dst_register;
1014bf215546Sopenharmony_ci}
1015bf215546Sopenharmony_ci
1016bf215546Sopenharmony_cistatic struct tgsi_full_dst_register
1017bf215546Sopenharmony_citgsi_default_full_dst_register( void )
1018bf215546Sopenharmony_ci{
1019bf215546Sopenharmony_ci   struct tgsi_full_dst_register full_dst_register;
1020bf215546Sopenharmony_ci
1021bf215546Sopenharmony_ci   full_dst_register.Register = tgsi_default_dst_register();
1022bf215546Sopenharmony_ci   full_dst_register.Indirect = tgsi_default_ind_register();
1023bf215546Sopenharmony_ci   full_dst_register.Dimension = tgsi_default_dimension();
1024bf215546Sopenharmony_ci   full_dst_register.DimIndirect = tgsi_default_ind_register();
1025bf215546Sopenharmony_ci
1026bf215546Sopenharmony_ci   return full_dst_register;
1027bf215546Sopenharmony_ci}
1028bf215546Sopenharmony_ci
1029bf215546Sopenharmony_cistruct tgsi_full_instruction
1030bf215546Sopenharmony_citgsi_default_full_instruction( void )
1031bf215546Sopenharmony_ci{
1032bf215546Sopenharmony_ci   struct tgsi_full_instruction full_instruction;
1033bf215546Sopenharmony_ci   unsigned i;
1034bf215546Sopenharmony_ci
1035bf215546Sopenharmony_ci   full_instruction.Instruction = tgsi_default_instruction();
1036bf215546Sopenharmony_ci   full_instruction.Label = tgsi_default_instruction_label();
1037bf215546Sopenharmony_ci   full_instruction.Texture = tgsi_default_instruction_texture();
1038bf215546Sopenharmony_ci   full_instruction.Memory = tgsi_default_instruction_memory();
1039bf215546Sopenharmony_ci   for( i = 0;  i < TGSI_FULL_MAX_TEX_OFFSETS; i++ ) {
1040bf215546Sopenharmony_ci      full_instruction.TexOffsets[i] = tgsi_default_texture_offset();
1041bf215546Sopenharmony_ci   }
1042bf215546Sopenharmony_ci   for( i = 0;  i < TGSI_FULL_MAX_DST_REGISTERS; i++ ) {
1043bf215546Sopenharmony_ci      full_instruction.Dst[i] = tgsi_default_full_dst_register();
1044bf215546Sopenharmony_ci   }
1045bf215546Sopenharmony_ci   for( i = 0;  i < TGSI_FULL_MAX_SRC_REGISTERS; i++ ) {
1046bf215546Sopenharmony_ci      full_instruction.Src[i] = tgsi_default_full_src_register();
1047bf215546Sopenharmony_ci   }
1048bf215546Sopenharmony_ci
1049bf215546Sopenharmony_ci   return full_instruction;
1050bf215546Sopenharmony_ci}
1051bf215546Sopenharmony_ci
1052bf215546Sopenharmony_ciunsigned
1053bf215546Sopenharmony_citgsi_build_full_instruction(
1054bf215546Sopenharmony_ci   const struct tgsi_full_instruction *full_inst,
1055bf215546Sopenharmony_ci   struct  tgsi_token *tokens,
1056bf215546Sopenharmony_ci   struct  tgsi_header *header,
1057bf215546Sopenharmony_ci   unsigned  maxsize )
1058bf215546Sopenharmony_ci{
1059bf215546Sopenharmony_ci   unsigned size = 0;
1060bf215546Sopenharmony_ci   unsigned i;
1061bf215546Sopenharmony_ci   struct tgsi_instruction *instruction;
1062bf215546Sopenharmony_ci
1063bf215546Sopenharmony_ci   if( maxsize <= size )
1064bf215546Sopenharmony_ci      return 0;
1065bf215546Sopenharmony_ci   instruction = (struct tgsi_instruction *) &tokens[size];
1066bf215546Sopenharmony_ci   size++;
1067bf215546Sopenharmony_ci
1068bf215546Sopenharmony_ci   *instruction = tgsi_build_instruction(full_inst->Instruction.Opcode,
1069bf215546Sopenharmony_ci                                         full_inst->Instruction.Saturate,
1070bf215546Sopenharmony_ci                                         full_inst->Instruction.Precise,
1071bf215546Sopenharmony_ci                                         full_inst->Instruction.NumDstRegs,
1072bf215546Sopenharmony_ci                                         full_inst->Instruction.NumSrcRegs,
1073bf215546Sopenharmony_ci                                         header);
1074bf215546Sopenharmony_ci
1075bf215546Sopenharmony_ci   if (full_inst->Instruction.Label) {
1076bf215546Sopenharmony_ci      struct tgsi_instruction_label *instruction_label;
1077bf215546Sopenharmony_ci
1078bf215546Sopenharmony_ci      if( maxsize <= size )
1079bf215546Sopenharmony_ci         return 0;
1080bf215546Sopenharmony_ci      instruction_label =
1081bf215546Sopenharmony_ci         (struct  tgsi_instruction_label *) &tokens[size];
1082bf215546Sopenharmony_ci      size++;
1083bf215546Sopenharmony_ci
1084bf215546Sopenharmony_ci      *instruction_label = tgsi_build_instruction_label(
1085bf215546Sopenharmony_ci         full_inst->Label.Label,
1086bf215546Sopenharmony_ci         instruction,
1087bf215546Sopenharmony_ci	 header );
1088bf215546Sopenharmony_ci   }
1089bf215546Sopenharmony_ci
1090bf215546Sopenharmony_ci   if (full_inst->Instruction.Texture) {
1091bf215546Sopenharmony_ci      struct tgsi_instruction_texture *instruction_texture;
1092bf215546Sopenharmony_ci
1093bf215546Sopenharmony_ci      if( maxsize <= size )
1094bf215546Sopenharmony_ci         return 0;
1095bf215546Sopenharmony_ci      instruction_texture =
1096bf215546Sopenharmony_ci         (struct  tgsi_instruction_texture *) &tokens[size];
1097bf215546Sopenharmony_ci      size++;
1098bf215546Sopenharmony_ci
1099bf215546Sopenharmony_ci      *instruction_texture = tgsi_build_instruction_texture(
1100bf215546Sopenharmony_ci         full_inst->Texture.Texture,
1101bf215546Sopenharmony_ci         full_inst->Texture.NumOffsets,
1102bf215546Sopenharmony_ci         full_inst->Texture.ReturnType,
1103bf215546Sopenharmony_ci         instruction,
1104bf215546Sopenharmony_ci         header   );
1105bf215546Sopenharmony_ci
1106bf215546Sopenharmony_ci      for (i = 0; i < full_inst->Texture.NumOffsets; i++) {
1107bf215546Sopenharmony_ci         struct tgsi_texture_offset *texture_offset;
1108bf215546Sopenharmony_ci
1109bf215546Sopenharmony_ci         if ( maxsize <= size )
1110bf215546Sopenharmony_ci            return 0;
1111bf215546Sopenharmony_ci	 texture_offset = (struct tgsi_texture_offset *)&tokens[size];
1112bf215546Sopenharmony_ci         size++;
1113bf215546Sopenharmony_ci         *texture_offset = tgsi_build_texture_offset(
1114bf215546Sopenharmony_ci            full_inst->TexOffsets[i].Index,
1115bf215546Sopenharmony_ci            full_inst->TexOffsets[i].File,
1116bf215546Sopenharmony_ci            full_inst->TexOffsets[i].SwizzleX,
1117bf215546Sopenharmony_ci            full_inst->TexOffsets[i].SwizzleY,
1118bf215546Sopenharmony_ci            full_inst->TexOffsets[i].SwizzleZ,
1119bf215546Sopenharmony_ci            instruction,
1120bf215546Sopenharmony_ci            header);
1121bf215546Sopenharmony_ci      }
1122bf215546Sopenharmony_ci   }
1123bf215546Sopenharmony_ci
1124bf215546Sopenharmony_ci   if (full_inst->Instruction.Memory) {
1125bf215546Sopenharmony_ci      struct tgsi_instruction_memory *instruction_memory;
1126bf215546Sopenharmony_ci
1127bf215546Sopenharmony_ci      if( maxsize <= size )
1128bf215546Sopenharmony_ci         return 0;
1129bf215546Sopenharmony_ci      instruction_memory =
1130bf215546Sopenharmony_ci         (struct  tgsi_instruction_memory *) &tokens[size];
1131bf215546Sopenharmony_ci      size++;
1132bf215546Sopenharmony_ci
1133bf215546Sopenharmony_ci      *instruction_memory = tgsi_build_instruction_memory(
1134bf215546Sopenharmony_ci         full_inst->Memory.Qualifier,
1135bf215546Sopenharmony_ci         full_inst->Memory.Texture,
1136bf215546Sopenharmony_ci         full_inst->Memory.Format,
1137bf215546Sopenharmony_ci         instruction,
1138bf215546Sopenharmony_ci         header );
1139bf215546Sopenharmony_ci   }
1140bf215546Sopenharmony_ci
1141bf215546Sopenharmony_ci   for( i = 0;  i <   full_inst->Instruction.NumDstRegs; i++ ) {
1142bf215546Sopenharmony_ci      const struct tgsi_full_dst_register *reg = &full_inst->Dst[i];
1143bf215546Sopenharmony_ci      struct tgsi_dst_register *dst_register;
1144bf215546Sopenharmony_ci
1145bf215546Sopenharmony_ci      if( maxsize <= size )
1146bf215546Sopenharmony_ci         return 0;
1147bf215546Sopenharmony_ci      dst_register = (struct tgsi_dst_register *) &tokens[size];
1148bf215546Sopenharmony_ci      size++;
1149bf215546Sopenharmony_ci
1150bf215546Sopenharmony_ci      *dst_register = tgsi_build_dst_register(
1151bf215546Sopenharmony_ci         reg->Register.File,
1152bf215546Sopenharmony_ci         reg->Register.WriteMask,
1153bf215546Sopenharmony_ci         reg->Register.Indirect,
1154bf215546Sopenharmony_ci         reg->Register.Dimension,
1155bf215546Sopenharmony_ci         reg->Register.Index,
1156bf215546Sopenharmony_ci         instruction,
1157bf215546Sopenharmony_ci         header );
1158bf215546Sopenharmony_ci
1159bf215546Sopenharmony_ci      if( reg->Register.Indirect ) {
1160bf215546Sopenharmony_ci         struct tgsi_ind_register *ind;
1161bf215546Sopenharmony_ci
1162bf215546Sopenharmony_ci         if( maxsize <= size )
1163bf215546Sopenharmony_ci            return 0;
1164bf215546Sopenharmony_ci         ind = (struct tgsi_ind_register *) &tokens[size];
1165bf215546Sopenharmony_ci         size++;
1166bf215546Sopenharmony_ci
1167bf215546Sopenharmony_ci         *ind = tgsi_build_ind_register(
1168bf215546Sopenharmony_ci            reg->Indirect.File,
1169bf215546Sopenharmony_ci            reg->Indirect.Swizzle,
1170bf215546Sopenharmony_ci            reg->Indirect.Index,
1171bf215546Sopenharmony_ci            reg->Indirect.ArrayID,
1172bf215546Sopenharmony_ci            instruction,
1173bf215546Sopenharmony_ci            header );
1174bf215546Sopenharmony_ci      }
1175bf215546Sopenharmony_ci
1176bf215546Sopenharmony_ci      if( reg->Register.Dimension ) {
1177bf215546Sopenharmony_ci         struct  tgsi_dimension *dim;
1178bf215546Sopenharmony_ci
1179bf215546Sopenharmony_ci         assert( !reg->Dimension.Dimension );
1180bf215546Sopenharmony_ci
1181bf215546Sopenharmony_ci         if( maxsize <= size )
1182bf215546Sopenharmony_ci            return 0;
1183bf215546Sopenharmony_ci         dim = (struct tgsi_dimension *) &tokens[size];
1184bf215546Sopenharmony_ci         size++;
1185bf215546Sopenharmony_ci
1186bf215546Sopenharmony_ci         *dim = tgsi_build_dimension(
1187bf215546Sopenharmony_ci            reg->Dimension.Indirect,
1188bf215546Sopenharmony_ci            reg->Dimension.Index,
1189bf215546Sopenharmony_ci            instruction,
1190bf215546Sopenharmony_ci            header );
1191bf215546Sopenharmony_ci
1192bf215546Sopenharmony_ci         if( reg->Dimension.Indirect ) {
1193bf215546Sopenharmony_ci            struct tgsi_ind_register *ind;
1194bf215546Sopenharmony_ci
1195bf215546Sopenharmony_ci            if( maxsize <= size )
1196bf215546Sopenharmony_ci               return 0;
1197bf215546Sopenharmony_ci            ind = (struct tgsi_ind_register *) &tokens[size];
1198bf215546Sopenharmony_ci            size++;
1199bf215546Sopenharmony_ci
1200bf215546Sopenharmony_ci            *ind = tgsi_build_ind_register(
1201bf215546Sopenharmony_ci               reg->DimIndirect.File,
1202bf215546Sopenharmony_ci               reg->DimIndirect.Swizzle,
1203bf215546Sopenharmony_ci               reg->DimIndirect.Index,
1204bf215546Sopenharmony_ci               reg->DimIndirect.ArrayID,
1205bf215546Sopenharmony_ci               instruction,
1206bf215546Sopenharmony_ci               header );
1207bf215546Sopenharmony_ci         }
1208bf215546Sopenharmony_ci      }
1209bf215546Sopenharmony_ci   }
1210bf215546Sopenharmony_ci
1211bf215546Sopenharmony_ci   for( i = 0;  i < full_inst->Instruction.NumSrcRegs; i++ ) {
1212bf215546Sopenharmony_ci      const struct tgsi_full_src_register *reg = &full_inst->Src[i];
1213bf215546Sopenharmony_ci      struct tgsi_src_register *src_register;
1214bf215546Sopenharmony_ci
1215bf215546Sopenharmony_ci      if( maxsize <= size )
1216bf215546Sopenharmony_ci         return 0;
1217bf215546Sopenharmony_ci      src_register = (struct tgsi_src_register *)  &tokens[size];
1218bf215546Sopenharmony_ci      size++;
1219bf215546Sopenharmony_ci
1220bf215546Sopenharmony_ci      *src_register = tgsi_build_src_register(
1221bf215546Sopenharmony_ci         reg->Register.File,
1222bf215546Sopenharmony_ci         reg->Register.SwizzleX,
1223bf215546Sopenharmony_ci         reg->Register.SwizzleY,
1224bf215546Sopenharmony_ci         reg->Register.SwizzleZ,
1225bf215546Sopenharmony_ci         reg->Register.SwizzleW,
1226bf215546Sopenharmony_ci         reg->Register.Negate,
1227bf215546Sopenharmony_ci         reg->Register.Absolute,
1228bf215546Sopenharmony_ci         reg->Register.Indirect,
1229bf215546Sopenharmony_ci         reg->Register.Dimension,
1230bf215546Sopenharmony_ci         reg->Register.Index,
1231bf215546Sopenharmony_ci         instruction,
1232bf215546Sopenharmony_ci         header );
1233bf215546Sopenharmony_ci
1234bf215546Sopenharmony_ci      if( reg->Register.Indirect ) {
1235bf215546Sopenharmony_ci         struct  tgsi_ind_register *ind;
1236bf215546Sopenharmony_ci
1237bf215546Sopenharmony_ci         if( maxsize <= size )
1238bf215546Sopenharmony_ci            return 0;
1239bf215546Sopenharmony_ci         ind = (struct tgsi_ind_register *) &tokens[size];
1240bf215546Sopenharmony_ci         size++;
1241bf215546Sopenharmony_ci
1242bf215546Sopenharmony_ci         *ind = tgsi_build_ind_register(
1243bf215546Sopenharmony_ci            reg->Indirect.File,
1244bf215546Sopenharmony_ci            reg->Indirect.Swizzle,
1245bf215546Sopenharmony_ci            reg->Indirect.Index,
1246bf215546Sopenharmony_ci            reg->Indirect.ArrayID,
1247bf215546Sopenharmony_ci            instruction,
1248bf215546Sopenharmony_ci            header );
1249bf215546Sopenharmony_ci      }
1250bf215546Sopenharmony_ci
1251bf215546Sopenharmony_ci      if( reg->Register.Dimension ) {
1252bf215546Sopenharmony_ci         struct  tgsi_dimension *dim;
1253bf215546Sopenharmony_ci
1254bf215546Sopenharmony_ci         assert( !reg->Dimension.Dimension );
1255bf215546Sopenharmony_ci
1256bf215546Sopenharmony_ci         if( maxsize <= size )
1257bf215546Sopenharmony_ci            return 0;
1258bf215546Sopenharmony_ci         dim = (struct tgsi_dimension *) &tokens[size];
1259bf215546Sopenharmony_ci         size++;
1260bf215546Sopenharmony_ci
1261bf215546Sopenharmony_ci         *dim = tgsi_build_dimension(
1262bf215546Sopenharmony_ci            reg->Dimension.Indirect,
1263bf215546Sopenharmony_ci            reg->Dimension.Index,
1264bf215546Sopenharmony_ci            instruction,
1265bf215546Sopenharmony_ci            header );
1266bf215546Sopenharmony_ci
1267bf215546Sopenharmony_ci         if( reg->Dimension.Indirect ) {
1268bf215546Sopenharmony_ci            struct tgsi_ind_register *ind;
1269bf215546Sopenharmony_ci
1270bf215546Sopenharmony_ci            if( maxsize <= size )
1271bf215546Sopenharmony_ci               return 0;
1272bf215546Sopenharmony_ci            ind = (struct tgsi_ind_register *) &tokens[size];
1273bf215546Sopenharmony_ci            size++;
1274bf215546Sopenharmony_ci
1275bf215546Sopenharmony_ci            *ind = tgsi_build_ind_register(
1276bf215546Sopenharmony_ci               reg->DimIndirect.File,
1277bf215546Sopenharmony_ci               reg->DimIndirect.Swizzle,
1278bf215546Sopenharmony_ci               reg->DimIndirect.Index,
1279bf215546Sopenharmony_ci               reg->DimIndirect.ArrayID,
1280bf215546Sopenharmony_ci               instruction,
1281bf215546Sopenharmony_ci               header );
1282bf215546Sopenharmony_ci         }
1283bf215546Sopenharmony_ci      }
1284bf215546Sopenharmony_ci   }
1285bf215546Sopenharmony_ci
1286bf215546Sopenharmony_ci   return size;
1287bf215546Sopenharmony_ci}
1288bf215546Sopenharmony_ci
1289bf215546Sopenharmony_cistatic struct tgsi_property
1290bf215546Sopenharmony_citgsi_default_property( void )
1291bf215546Sopenharmony_ci{
1292bf215546Sopenharmony_ci   struct tgsi_property property;
1293bf215546Sopenharmony_ci
1294bf215546Sopenharmony_ci   property.Type = TGSI_TOKEN_TYPE_PROPERTY;
1295bf215546Sopenharmony_ci   property.NrTokens = 1;
1296bf215546Sopenharmony_ci   property.PropertyName = TGSI_PROPERTY_GS_INPUT_PRIM;
1297bf215546Sopenharmony_ci   property.Padding = 0;
1298bf215546Sopenharmony_ci
1299bf215546Sopenharmony_ci   return property;
1300bf215546Sopenharmony_ci}
1301bf215546Sopenharmony_ci
1302bf215546Sopenharmony_cistatic struct tgsi_property
1303bf215546Sopenharmony_citgsi_build_property(unsigned property_name,
1304bf215546Sopenharmony_ci                    struct tgsi_header *header)
1305bf215546Sopenharmony_ci{
1306bf215546Sopenharmony_ci   struct tgsi_property property;
1307bf215546Sopenharmony_ci
1308bf215546Sopenharmony_ci   property = tgsi_default_property();
1309bf215546Sopenharmony_ci   property.PropertyName = property_name;
1310bf215546Sopenharmony_ci
1311bf215546Sopenharmony_ci   header_bodysize_grow( header );
1312bf215546Sopenharmony_ci
1313bf215546Sopenharmony_ci   return property;
1314bf215546Sopenharmony_ci}
1315bf215546Sopenharmony_ci
1316bf215546Sopenharmony_ci
1317bf215546Sopenharmony_cistruct tgsi_full_property
1318bf215546Sopenharmony_citgsi_default_full_property( void )
1319bf215546Sopenharmony_ci{
1320bf215546Sopenharmony_ci   struct tgsi_full_property  full_property;
1321bf215546Sopenharmony_ci
1322bf215546Sopenharmony_ci   full_property.Property  = tgsi_default_property();
1323bf215546Sopenharmony_ci   memset(full_property.u, 0,
1324bf215546Sopenharmony_ci          sizeof(struct tgsi_property_data) * 8);
1325bf215546Sopenharmony_ci
1326bf215546Sopenharmony_ci   return full_property;
1327bf215546Sopenharmony_ci}
1328bf215546Sopenharmony_ci
1329bf215546Sopenharmony_cistatic void
1330bf215546Sopenharmony_ciproperty_grow(
1331bf215546Sopenharmony_ci   struct tgsi_property *property,
1332bf215546Sopenharmony_ci   struct tgsi_header *header )
1333bf215546Sopenharmony_ci{
1334bf215546Sopenharmony_ci   assert( property->NrTokens < 0xFF );
1335bf215546Sopenharmony_ci
1336bf215546Sopenharmony_ci   property->NrTokens++;
1337bf215546Sopenharmony_ci
1338bf215546Sopenharmony_ci   header_bodysize_grow( header );
1339bf215546Sopenharmony_ci}
1340bf215546Sopenharmony_ci
1341bf215546Sopenharmony_cistatic struct tgsi_property_data
1342bf215546Sopenharmony_citgsi_build_property_data(
1343bf215546Sopenharmony_ci   unsigned value,
1344bf215546Sopenharmony_ci   struct tgsi_property *property,
1345bf215546Sopenharmony_ci   struct tgsi_header *header )
1346bf215546Sopenharmony_ci{
1347bf215546Sopenharmony_ci   struct tgsi_property_data property_data;
1348bf215546Sopenharmony_ci
1349bf215546Sopenharmony_ci   property_data.Data = value;
1350bf215546Sopenharmony_ci
1351bf215546Sopenharmony_ci   property_grow( property, header );
1352bf215546Sopenharmony_ci
1353bf215546Sopenharmony_ci   return property_data;
1354bf215546Sopenharmony_ci}
1355bf215546Sopenharmony_ci
1356bf215546Sopenharmony_ciunsigned
1357bf215546Sopenharmony_citgsi_build_full_property(
1358bf215546Sopenharmony_ci   const struct tgsi_full_property *full_prop,
1359bf215546Sopenharmony_ci   struct tgsi_token *tokens,
1360bf215546Sopenharmony_ci   struct tgsi_header *header,
1361bf215546Sopenharmony_ci   unsigned maxsize )
1362bf215546Sopenharmony_ci{
1363bf215546Sopenharmony_ci   unsigned size = 0;
1364bf215546Sopenharmony_ci   int i;
1365bf215546Sopenharmony_ci   struct tgsi_property *property;
1366bf215546Sopenharmony_ci
1367bf215546Sopenharmony_ci   if( maxsize <= size )
1368bf215546Sopenharmony_ci      return 0;
1369bf215546Sopenharmony_ci   property = (struct tgsi_property *) &tokens[size];
1370bf215546Sopenharmony_ci   size++;
1371bf215546Sopenharmony_ci
1372bf215546Sopenharmony_ci   *property = tgsi_build_property(
1373bf215546Sopenharmony_ci      full_prop->Property.PropertyName,
1374bf215546Sopenharmony_ci      header );
1375bf215546Sopenharmony_ci
1376bf215546Sopenharmony_ci   assert( full_prop->Property.NrTokens <= 8 + 1 );
1377bf215546Sopenharmony_ci
1378bf215546Sopenharmony_ci   for( i = 0; i < full_prop->Property.NrTokens - 1; i++ ) {
1379bf215546Sopenharmony_ci      struct tgsi_property_data *data;
1380bf215546Sopenharmony_ci
1381bf215546Sopenharmony_ci      if( maxsize <= size )
1382bf215546Sopenharmony_ci         return  0;
1383bf215546Sopenharmony_ci      data = (struct tgsi_property_data *) &tokens[size];
1384bf215546Sopenharmony_ci      size++;
1385bf215546Sopenharmony_ci
1386bf215546Sopenharmony_ci      *data = tgsi_build_property_data(
1387bf215546Sopenharmony_ci         full_prop->u[i].Data,
1388bf215546Sopenharmony_ci         property,
1389bf215546Sopenharmony_ci         header );
1390bf215546Sopenharmony_ci   }
1391bf215546Sopenharmony_ci
1392bf215546Sopenharmony_ci   return size;
1393bf215546Sopenharmony_ci}
1394bf215546Sopenharmony_ci
1395bf215546Sopenharmony_cistruct tgsi_full_src_register
1396bf215546Sopenharmony_citgsi_full_src_register_from_dst(const struct tgsi_full_dst_register *dst)
1397bf215546Sopenharmony_ci{
1398bf215546Sopenharmony_ci   struct tgsi_full_src_register src;
1399bf215546Sopenharmony_ci   src.Register = tgsi_default_src_register();
1400bf215546Sopenharmony_ci   src.Register.File = dst->Register.File;
1401bf215546Sopenharmony_ci   src.Register.Indirect = dst->Register.Indirect;
1402bf215546Sopenharmony_ci   src.Register.Dimension = dst->Register.Dimension;
1403bf215546Sopenharmony_ci   src.Register.Index = dst->Register.Index;
1404bf215546Sopenharmony_ci   src.Indirect = dst->Indirect;
1405bf215546Sopenharmony_ci   src.Dimension = dst->Dimension;
1406bf215546Sopenharmony_ci   src.DimIndirect = dst->DimIndirect;
1407bf215546Sopenharmony_ci   return src;
1408bf215546Sopenharmony_ci}
1409