1bf215546Sopenharmony_ci/**************************************************************************
2bf215546Sopenharmony_ci *
3bf215546Sopenharmony_ci * Copyright 2012-2021 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 SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
17bf215546Sopenharmony_ci * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
18bf215546Sopenharmony_ci * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19bf215546Sopenharmony_ci * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20bf215546Sopenharmony_ci * USE OR OTHER DEALINGS IN THE SOFTWARE.
21bf215546Sopenharmony_ci *
22bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the
23bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions
24bf215546Sopenharmony_ci * of the Software.
25bf215546Sopenharmony_ci *
26bf215546Sopenharmony_ci **************************************************************************/
27bf215546Sopenharmony_ci
28bf215546Sopenharmony_ci/*
29bf215546Sopenharmony_ci * ShaderParse.h --
30bf215546Sopenharmony_ci *    Functions for parsing shader tokens.
31bf215546Sopenharmony_ci */
32bf215546Sopenharmony_ci
33bf215546Sopenharmony_ci#ifndef SHADER_PARSE_H
34bf215546Sopenharmony_ci#define SHADER_PARSE_H
35bf215546Sopenharmony_ci
36bf215546Sopenharmony_ci#include "DriverIncludes.h"
37bf215546Sopenharmony_ci
38bf215546Sopenharmony_ci#ifdef __cplusplus
39bf215546Sopenharmony_ciextern "C" {
40bf215546Sopenharmony_ci#endif
41bf215546Sopenharmony_ci
42bf215546Sopenharmony_cistruct Shader_header {
43bf215546Sopenharmony_ci   D3D10_SB_TOKENIZED_PROGRAM_TYPE type;
44bf215546Sopenharmony_ci   unsigned major_version;
45bf215546Sopenharmony_ci   unsigned minor_version;
46bf215546Sopenharmony_ci   unsigned size;
47bf215546Sopenharmony_ci};
48bf215546Sopenharmony_ci
49bf215546Sopenharmony_cistruct dx10_imm_const_buf {
50bf215546Sopenharmony_ci   unsigned count;
51bf215546Sopenharmony_ci   unsigned *data;
52bf215546Sopenharmony_ci};
53bf215546Sopenharmony_ci
54bf215546Sopenharmony_cistruct dx10_customdata {
55bf215546Sopenharmony_ci   D3D10_SB_CUSTOMDATA_CLASS _class;
56bf215546Sopenharmony_ci   union {
57bf215546Sopenharmony_ci      struct dx10_imm_const_buf constbuf;
58bf215546Sopenharmony_ci   } u;
59bf215546Sopenharmony_ci};
60bf215546Sopenharmony_ci
61bf215546Sopenharmony_cistruct dx10_indexable_temp {
62bf215546Sopenharmony_ci   unsigned index;
63bf215546Sopenharmony_ci   unsigned count;
64bf215546Sopenharmony_ci   unsigned components;
65bf215546Sopenharmony_ci};
66bf215546Sopenharmony_ci
67bf215546Sopenharmony_cistruct dx10_global_flags {
68bf215546Sopenharmony_ci   unsigned refactoring_allowed:1;
69bf215546Sopenharmony_ci};
70bf215546Sopenharmony_ci
71bf215546Sopenharmony_cistruct Shader_relative_index {
72bf215546Sopenharmony_ci   unsigned imm;
73bf215546Sopenharmony_ci};
74bf215546Sopenharmony_ci
75bf215546Sopenharmony_cistruct Shader_relative_operand {
76bf215546Sopenharmony_ci   D3D10_SB_OPERAND_TYPE type;
77bf215546Sopenharmony_ci   struct Shader_relative_index index[2];
78bf215546Sopenharmony_ci   D3D10_SB_4_COMPONENT_NAME comp;
79bf215546Sopenharmony_ci};
80bf215546Sopenharmony_ci
81bf215546Sopenharmony_cistruct Shader_index {
82bf215546Sopenharmony_ci   unsigned imm;
83bf215546Sopenharmony_ci   struct Shader_relative_operand rel;
84bf215546Sopenharmony_ci   D3D10_SB_OPERAND_INDEX_REPRESENTATION index_rep;
85bf215546Sopenharmony_ci};
86bf215546Sopenharmony_ci
87bf215546Sopenharmony_cistruct Shader_operand {
88bf215546Sopenharmony_ci   D3D10_SB_OPERAND_TYPE type;
89bf215546Sopenharmony_ci   struct Shader_index index[2];
90bf215546Sopenharmony_ci   unsigned index_dim;
91bf215546Sopenharmony_ci};
92bf215546Sopenharmony_ci
93bf215546Sopenharmony_cistruct Shader_dst_operand {
94bf215546Sopenharmony_ci   struct Shader_operand base;
95bf215546Sopenharmony_ci   unsigned mask;
96bf215546Sopenharmony_ci};
97bf215546Sopenharmony_ci
98bf215546Sopenharmony_ciunion Shader_immediate {
99bf215546Sopenharmony_ci   float f32;
100bf215546Sopenharmony_ci   int i32;
101bf215546Sopenharmony_ci   unsigned u32;
102bf215546Sopenharmony_ci};
103bf215546Sopenharmony_ci
104bf215546Sopenharmony_cistruct Shader_src_operand {
105bf215546Sopenharmony_ci   struct Shader_operand base;
106bf215546Sopenharmony_ci   union Shader_immediate imm[4];
107bf215546Sopenharmony_ci   D3D10_SB_4_COMPONENT_NAME swizzle[4];
108bf215546Sopenharmony_ci   D3D10_SB_OPERAND_MODIFIER modifier;
109bf215546Sopenharmony_ci};
110bf215546Sopenharmony_ci
111bf215546Sopenharmony_ci#define SHADER_MAX_DST_OPERANDS 2
112bf215546Sopenharmony_ci#define SHADER_MAX_SRC_OPERANDS 5
113bf215546Sopenharmony_ci
114bf215546Sopenharmony_cistruct Shader_opcode {
115bf215546Sopenharmony_ci   D3D10_SB_OPCODE_TYPE type;
116bf215546Sopenharmony_ci   unsigned num_dst;
117bf215546Sopenharmony_ci   unsigned num_src;
118bf215546Sopenharmony_ci   struct Shader_dst_operand dst[SHADER_MAX_DST_OPERANDS];
119bf215546Sopenharmony_ci   struct Shader_src_operand src[SHADER_MAX_SRC_OPERANDS];
120bf215546Sopenharmony_ci
121bf215546Sopenharmony_ci   /* Opcode specific data.
122bf215546Sopenharmony_ci    */
123bf215546Sopenharmony_ci   union {
124bf215546Sopenharmony_ci      D3D10_SB_RESOURCE_DIMENSION dcl_resource_dimension;
125bf215546Sopenharmony_ci      D3D10_SB_SAMPLER_MODE dcl_sampler_mode;
126bf215546Sopenharmony_ci      D3D10_SB_CONSTANT_BUFFER_ACCESS_PATTERN dcl_cb_access_pattern;
127bf215546Sopenharmony_ci      D3D10_SB_INTERPOLATION_MODE dcl_in_ps_interp;
128bf215546Sopenharmony_ci      D3D10_SB_PRIMITIVE_TOPOLOGY dcl_gs_output_primitive_topology;
129bf215546Sopenharmony_ci      D3D10_SB_PRIMITIVE dcl_gs_input_primitive;
130bf215546Sopenharmony_ci      D3D10_SB_INSTRUCTION_TEST_BOOLEAN test_boolean;
131bf215546Sopenharmony_ci      D3D10_SB_RESINFO_INSTRUCTION_RETURN_TYPE resinfo_ret_type;
132bf215546Sopenharmony_ci      unsigned dcl_max_output_vertex_count;
133bf215546Sopenharmony_ci      unsigned dcl_num_temps;
134bf215546Sopenharmony_ci      struct dx10_indexable_temp dcl_indexable_temp;
135bf215546Sopenharmony_ci      unsigned index_range_count;
136bf215546Sopenharmony_ci      struct dx10_global_flags global_flags;
137bf215546Sopenharmony_ci   } specific;
138bf215546Sopenharmony_ci   D3D10_SB_NAME dcl_siv_name;
139bf215546Sopenharmony_ci   D3D10_SB_RESOURCE_RETURN_TYPE dcl_resource_ret_type[4];
140bf215546Sopenharmony_ci
141bf215546Sopenharmony_ci   boolean saturate;
142bf215546Sopenharmony_ci
143bf215546Sopenharmony_ci   struct {
144bf215546Sopenharmony_ci      int u:4;
145bf215546Sopenharmony_ci      int v:4;
146bf215546Sopenharmony_ci      int w:4;
147bf215546Sopenharmony_ci   } imm_texel_offset;
148bf215546Sopenharmony_ci
149bf215546Sopenharmony_ci   struct dx10_customdata customdata;
150bf215546Sopenharmony_ci};
151bf215546Sopenharmony_ci
152bf215546Sopenharmony_cistruct Shader_parser {
153bf215546Sopenharmony_ci   const unsigned *code;
154bf215546Sopenharmony_ci   const unsigned *curr;
155bf215546Sopenharmony_ci
156bf215546Sopenharmony_ci   struct Shader_header header;
157bf215546Sopenharmony_ci};
158bf215546Sopenharmony_ci
159bf215546Sopenharmony_civoid
160bf215546Sopenharmony_ciShader_parse_init(struct Shader_parser *parser,
161bf215546Sopenharmony_ci                       const unsigned *code);
162bf215546Sopenharmony_ci
163bf215546Sopenharmony_ciboolean
164bf215546Sopenharmony_ciShader_parse_opcode(struct Shader_parser *parser,
165bf215546Sopenharmony_ci                         struct Shader_opcode *opcode);
166bf215546Sopenharmony_ci
167bf215546Sopenharmony_civoid
168bf215546Sopenharmony_ciShader_opcode_free(struct Shader_opcode *opcode);
169bf215546Sopenharmony_ci
170bf215546Sopenharmony_ci
171bf215546Sopenharmony_ciconst struct tgsi_token *
172bf215546Sopenharmony_ciShader_tgsi_translate(const unsigned *code,
173bf215546Sopenharmony_ci                      unsigned *output_mapping);
174bf215546Sopenharmony_ci
175bf215546Sopenharmony_ci
176bf215546Sopenharmony_ci#ifdef __cplusplus
177bf215546Sopenharmony_ci}
178bf215546Sopenharmony_ci#endif
179bf215546Sopenharmony_ci
180bf215546Sopenharmony_ci#endif /* SHADER_PARSE_H */
181