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 //#include "winddk/winddk_compat.h" 39 #include "winddk/d3d10tokenizedprogramformat.hpp" 40 41 #ifdef __cplusplus 42 extern "C" { 43 #endif 44 45 struct Shader_header { 46 D3D10_SB_TOKENIZED_PROGRAM_TYPE type; 47 unsigned major_version; 48 unsigned minor_version; 49 unsigned size; 50 }; 51 52 struct dx10_imm_const_buf { 53 unsigned count; 54 unsigned *data; 55 }; 56 57 struct dx10_customdata { 58 D3D10_SB_CUSTOMDATA_CLASS _class; 59 union { 60 struct dx10_imm_const_buf constbuf; 61 } u; 62 }; 63 64 struct dx10_indexable_temp { 65 unsigned index; 66 unsigned count; 67 unsigned components; 68 }; 69 70 struct dx10_global_flags { 71 unsigned refactoring_allowed:1; 72 }; 73 74 struct Shader_relative_index { 75 unsigned imm; 76 }; 77 78 struct Shader_relative_operand { 79 D3D10_SB_OPERAND_TYPE type; 80 struct Shader_relative_index index[2]; 81 D3D10_SB_4_COMPONENT_NAME comp; 82 }; 83 84 struct Shader_index { 85 unsigned imm; 86 struct Shader_relative_operand rel; 87 D3D10_SB_OPERAND_INDEX_REPRESENTATION index_rep; 88 }; 89 90 struct Shader_operand { 91 D3D10_SB_OPERAND_TYPE type; 92 struct Shader_index index[2]; 93 unsigned index_dim; 94 }; 95 96 struct Shader_dst_operand { 97 struct Shader_operand base; 98 unsigned mask; 99 }; 100 101 union Shader_immediate { 102 float f32; 103 int i32; 104 unsigned u32; 105 }; 106 107 struct Shader_src_operand { 108 struct Shader_operand base; 109 union Shader_immediate imm[4]; 110 D3D10_SB_4_COMPONENT_NAME swizzle[4]; 111 D3D10_SB_OPERAND_MODIFIER modifier; 112 }; 113 114 #define SHADER_MAX_DST_OPERANDS 2 115 #define SHADER_MAX_SRC_OPERANDS 5 116 117 struct Shader_opcode { 118 D3D10_SB_OPCODE_TYPE type; 119 unsigned num_dst; 120 unsigned num_src; 121 struct Shader_dst_operand dst[SHADER_MAX_DST_OPERANDS]; 122 struct Shader_src_operand src[SHADER_MAX_SRC_OPERANDS]; 123 124 /* Opcode specific data. 125 */ 126 union { 127 D3D10_SB_RESOURCE_DIMENSION dcl_resource_dimension; 128 D3D10_SB_SAMPLER_MODE dcl_sampler_mode; 129 D3D10_SB_CONSTANT_BUFFER_ACCESS_PATTERN dcl_cb_access_pattern; 130 D3D10_SB_INTERPOLATION_MODE dcl_in_ps_interp; 131 D3D10_SB_PRIMITIVE_TOPOLOGY dcl_gs_output_primitive_topology; 132 D3D10_SB_PRIMITIVE dcl_gs_input_primitive; 133 D3D10_SB_INSTRUCTION_TEST_BOOLEAN test_boolean; 134 D3D10_SB_RESINFO_INSTRUCTION_RETURN_TYPE resinfo_ret_type; 135 unsigned dcl_max_output_vertex_count; 136 unsigned dcl_num_temps; 137 struct dx10_indexable_temp dcl_indexable_temp; 138 unsigned index_range_count; 139 struct dx10_global_flags global_flags; 140 } specific; 141 D3D10_SB_NAME dcl_siv_name; 142 D3D10_SB_RESOURCE_RETURN_TYPE dcl_resource_ret_type[4]; 143 144 boolean saturate; 145 146 struct { 147 int u:4; 148 int v:4; 149 int w:4; 150 } imm_texel_offset; 151 152 struct dx10_customdata customdata; 153 }; 154 155 struct Shader_parser { 156 const unsigned *code; 157 const unsigned *curr; 158 159 struct Shader_header header; 160 }; 161 162 void 163 Shader_parse_init(struct Shader_parser *parser, 164 const unsigned *code); 165 166 boolean 167 Shader_parse_opcode(struct Shader_parser *parser, 168 struct Shader_opcode *opcode); 169 170 void 171 Shader_opcode_free(struct Shader_opcode *opcode); 172 173 174 const struct tgsi_token * 175 Shader_tgsi_translate(const unsigned *code, 176 unsigned *output_mapping); 177 178 179 #ifdef __cplusplus 180 } 181 #endif 182 183 #endif /* SHADER_PARSE_H */ 184