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