| 1 | /** |
| 2 | * MojoShader; generate shader programs from bytecode of compiled |
| 3 | * Direct3D shaders. |
| 4 | * |
| 5 | * Please see the file LICENSE.txt in the source's root directory. |
| 6 | * |
| 7 | * This file written by Ryan C. Gordon. |
| 8 | */ |
| 9 | |
| 10 | #include <stdio.h> |
| 11 | #include <stdlib.h> |
| 12 | #include <string.h> |
| 13 | #include <assert.h> |
| 14 | #include "../mojoshader.h"cxx . . $ `<file>/mojoshader.h`/ |
| 15 | #define __MOJOSHADER_INTERNAL__cxx . . $ `utils/testparse.c:15:9`! 1 |
| 16 | #include "../mojoshader_internal.h"cxx . . $ `<file>/mojoshader_internal.h`/ |
| 17 | #ifdef MOJOSHADER_HAS_SPIRV_TOOLS |
| 18 | #include "spirv-tools/libspirv.h" |
| 19 | #endif |
| 20 | |
| 21 | #ifdef _MSC_VER |
| 22 | #define snprintf _snprintf |
| 23 | #endif |
| 24 | |
| 25 | #if MOJOSHADER_DEBUG_MALLOC |
| 26 | static void *Malloc(int len) |
| 27 | { |
| 28 | void *ptr = malloc(len + sizeof (int)); |
| 29 | int *store = (int *) ptr; |
| 30 | printf("malloc() %d bytes (%p)\n", len, ptr); |
| 31 | if (ptr == NULL) return NULL; |
| 32 | *store = len; |
| 33 | return (void *) (store + 1); |
| 34 | } // Malloc |
| 35 | |
| 36 | |
| 37 | static void Free(void *_ptr) |
| 38 | { |
| 39 | int *ptr = (((int *) _ptr) - 1); |
| 40 | int len = *ptr; |
| 41 | printf("free() %d bytes (%p)\n", len, ptr); |
| 42 | free(ptr); |
| 43 | } // Free |
| 44 | #else |
| 45 | #define Malloccxx . . $ `utils/testparse.c:45:9`! NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! |
| 46 | #define Freecxx . . $ `utils/testparse.c:46:9`! NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! |
| 47 | #endif |
| 48 | |
| 49 | static inline void do_indentcxx . . $ do_indent(cb2f890c2fdad230).(const unsigned int indent) |
| 50 | { |
| 51 | unsigned int i; |
| 52 | for (i = 0; i < indent; i++) |
| 53 | printfcxx . . $ printf(581fddd72a8db8fc).(" "); |
| 54 | } |
| 55 | |
| 56 | #define INDENTcxx . . $ `utils/testparse.c:56:9`!() do { if (indent) { do_indent(indent); } } while (0) |
| 57 | |
| 58 | |
| 59 | static const char *shader_typecxx . . $ shader_type(2fa709a0b3e26fab).(const MOJOSHADER_shaderTypecxx . . $ MOJOSHADER_shaderType# s) |
| 60 | { |
| 61 | switch (s) |
| 62 | { |
| 63 | case MOJOSHADER_TYPE_UNKNOWNcxx . . $ MOJOSHADER_TYPE_UNKNOWN.: return "unknown"; |
| 64 | case MOJOSHADER_TYPE_PIXELcxx . . $ MOJOSHADER_TYPE_PIXEL.: return "pixel"; |
| 65 | case MOJOSHADER_TYPE_VERTEXcxx . . $ MOJOSHADER_TYPE_VERTEX.: return "vertex"; |
| 66 | case MOJOSHADER_TYPE_GEOMETRYcxx . . $ MOJOSHADER_TYPE_GEOMETRY.: return "geometry"; |
| 67 | default: return "(bogus value?)"; |
| 68 | } // switch |
| 69 | |
| 70 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; // shouldn't hit this. |
| 71 | } // shader_type |
| 72 | |
| 73 | |
| 74 | static void print_typeinfocxx . . $ print_typeinfo(31aba02ed19d638d).(const MOJOSHADER_symbolTypeInfocxx . . $ MOJOSHADER_symbolTypeInfo# *info, |
| 75 | unsigned int indent) |
| 76 | { |
| 77 | static const char *symclasses[] = { |
| 78 | "scalar", "vector", "row-major matrix", |
| 79 | "column-major matrix", "object", "struct" |
| 80 | }; |
| 81 | |
| 82 | static const char *symtypes[] = { |
| 83 | "void", "bool", "int", "float", "string", "texture", |
| 84 | "texture1d", "texture2d", "texture3d", "texturecube", |
| 85 | "sampler", "sampler1d", "sampler2d", "sampler3d", |
| 86 | "samplercube", "pixelshader", "vertexshader", "unsupported" |
| 87 | }; |
| 88 | |
| 89 | INDENTcxx . . $ `utils/testparse.c:56:9`!(); |
| 90 | printfcxx . . $ printf(581fddd72a8db8fc).(" symbol class %s\n", symclasses[info->parameter_classcxx . . $ MOJOSHADER_symbolTypeInfo#parameter_class.]); |
| 91 | INDENTcxx . . $ `utils/testparse.c:56:9`!(); |
| 92 | printfcxx . . $ printf(581fddd72a8db8fc).(" symbol type %s\n", symtypes[info->parameter_typecxx . . $ MOJOSHADER_symbolTypeInfo#parameter_type.]); |
| 93 | INDENTcxx . . $ `utils/testparse.c:56:9`!(); |
| 94 | printfcxx . . $ printf(581fddd72a8db8fc).(" rows %u\n", info->rowscxx . . $ MOJOSHADER_symbolTypeInfo#rows.); |
| 95 | INDENTcxx . . $ `utils/testparse.c:56:9`!(); |
| 96 | printfcxx . . $ printf(581fddd72a8db8fc).(" columns %u\n", info->columnscxx . . $ MOJOSHADER_symbolTypeInfo#columns.); |
| 97 | INDENTcxx . . $ `utils/testparse.c:56:9`!(); |
| 98 | printfcxx . . $ printf(581fddd72a8db8fc).(" elements %u\n", info->elementscxx . . $ MOJOSHADER_symbolTypeInfo#elements.); |
| 99 | |
| 100 | if (info->member_countcxx . . $ MOJOSHADER_symbolTypeInfo#member_count. > 0) |
| 101 | { |
| 102 | int i; |
| 103 | INDENTcxx . . $ `utils/testparse.c:56:9`!(); printfcxx . . $ printf(581fddd72a8db8fc).(" MEMBERS:\n"); |
| 104 | for (i = 0; i < info->member_countcxx . . $ MOJOSHADER_symbolTypeInfo#member_count.; i++) |
| 105 | { |
| 106 | const MOJOSHADER_symbolStructMembercxx . . $ MOJOSHADER_symbolStructMember# *member = &info->memberscxx . . $ MOJOSHADER_symbolTypeInfo#members.[i]; |
| 107 | INDENTcxx . . $ `utils/testparse.c:56:9`!(); printfcxx . . $ printf(581fddd72a8db8fc).(" MEMBERS:\n"); |
| 108 | indent++; |
| 109 | INDENTcxx . . $ `utils/testparse.c:56:9`!(); printfcxx . . $ printf(581fddd72a8db8fc).(" * %d: \"%s\"\n", i, member->namecxx . . $ MOJOSHADER_symbolStructMember#name.); |
| 110 | print_typeinfocxx . . $ print_typeinfo(31aba02ed19d638d).(&member->infocxx . . $ MOJOSHADER_symbolStructMember#info., indent); |
| 111 | indent--; |
| 112 | } // for |
| 113 | } // if |
| 114 | } // print_typeinfo |
| 115 | |
| 116 | |
| 117 | static void print_symbolscxx . . $ print_symbols(c3b4269f936c92d0).(const MOJOSHADER_symbolcxx . . $ MOJOSHADER_symbol# *sym, |
| 118 | const unsigned int symbol_count, |
| 119 | const unsigned int indent) |
| 120 | { |
| 121 | INDENTcxx . . $ `utils/testparse.c:56:9`!(); printfcxx . . $ printf(581fddd72a8db8fc).("SYMBOLS:"); |
| 122 | if (symbol_count == 0) |
| 123 | printfcxx . . $ printf(581fddd72a8db8fc).(" (none.)\n"); |
| 124 | else |
| 125 | { |
| 126 | int i; |
| 127 | printfcxx . . $ printf(581fddd72a8db8fc).("\n"); |
| 128 | for (i = 0; i < symbol_count; i++, sym++) |
| 129 | { |
| 130 | static const char *regsets[] = { |
| 131 | "bool", "int4", "float4", "sampler" |
| 132 | }; |
| 133 | |
| 134 | INDENTcxx . . $ `utils/testparse.c:56:9`!(); printfcxx . . $ printf(581fddd72a8db8fc).(" * %d: \"%s\"\n", i, sym->namecxx . . $ MOJOSHADER_symbol#name.); |
| 135 | INDENTcxx . . $ `utils/testparse.c:56:9`!(); printfcxx . . $ printf(581fddd72a8db8fc).(" register set %s\n", regsets[sym->register_setcxx . . $ MOJOSHADER_symbol#register_set.]); |
| 136 | INDENTcxx . . $ `utils/testparse.c:56:9`!(); printfcxx . . $ printf(581fddd72a8db8fc).(" register index %u\n", sym->register_indexcxx . . $ MOJOSHADER_symbol#register_index.); |
| 137 | INDENTcxx . . $ `utils/testparse.c:56:9`!(); printfcxx . . $ printf(581fddd72a8db8fc).(" register count %u\n", sym->register_countcxx . . $ MOJOSHADER_symbol#register_count.); |
| 138 | print_typeinfocxx . . $ print_typeinfo(31aba02ed19d638d).(&sym->infocxx . . $ MOJOSHADER_symbol#info., indent); |
| 139 | } // for |
| 140 | printfcxx . . $ printf(581fddd72a8db8fc).("\n"); |
| 141 | } // else |
| 142 | } // print_symbols |
| 143 | |
| 144 | |
| 145 | static void print_preshader_operandcxx . . $ print_preshader_operand(f034b88aed08ba91).(const MOJOSHADER_preshadercxx . . $ MOJOSHADER_preshader# *preshader, |
| 146 | const int instidx, const int opidx) |
| 147 | { |
| 148 | static char mask[] = { 'x', 'y', 'z', 'w' }; |
| 149 | const MOJOSHADER_preshaderInstructioncxx . . $ MOJOSHADER_preshaderInstruction# *inst = &preshader->instructionscxx . . $ MOJOSHADER_preshader#instructions.[instidx]; |
| 150 | const MOJOSHADER_preshaderOperandcxx . . $ MOJOSHADER_preshaderOperand# *operand = &inst->operandscxx . . $ MOJOSHADER_preshaderInstruction#operands.[opidx]; |
| 151 | const int elems = inst->element_countcxx . . $ MOJOSHADER_preshaderInstruction#element_count.; |
| 152 | const int isscalarop = (inst->opcodecxx . . $ MOJOSHADER_preshaderInstruction#opcode. >= MOJOSHADER_PRESHADEROP_SCALAR_OPScxx . . $ MOJOSHADER_PRESHADEROP_SCALAR_OPS.); |
| 153 | const int isscalar = ((isscalarop) && (opidx == 0)); // probably wrong. |
| 154 | int i; |
| 155 | |
| 156 | switch (operand->typecxx . . $ MOJOSHADER_preshaderOperand#type.) |
| 157 | { |
| 158 | case MOJOSHADER_PRESHADEROPERAND_LITERALcxx . . $ MOJOSHADER_PRESHADEROPERAND_LITERAL.: |
| 159 | { |
| 160 | const double *lit = &preshader->literalscxx . . $ MOJOSHADER_preshader#literals.[operand->indexcxx . . $ MOJOSHADER_preshaderOperand#index.]; |
| 161 | printfcxx . . $ printf(581fddd72a8db8fc).("("); |
| 162 | if (isscalar) |
| 163 | { |
| 164 | const double val = *lit; |
| 165 | for (i = 0; i < elems-1; i++) |
| 166 | printfcxx . . $ printf(581fddd72a8db8fc).("%g, ", val); |
| 167 | printfcxx . . $ printf(581fddd72a8db8fc).("%g)", val); |
| 168 | } // if |
| 169 | else |
| 170 | { |
| 171 | for (i = 0; i < elems-1; i++, lit++) |
| 172 | printfcxx . . $ printf(581fddd72a8db8fc).("%g, ", *lit); |
| 173 | printfcxx . . $ printf(581fddd72a8db8fc).("%g)", *lit); |
| 174 | } // else |
| 175 | break; |
| 176 | } // case |
| 177 | |
| 178 | case MOJOSHADER_PRESHADEROPERAND_INPUTcxx . . $ MOJOSHADER_PRESHADEROPERAND_INPUT.: |
| 179 | case MOJOSHADER_PRESHADEROPERAND_OUTPUTcxx . . $ MOJOSHADER_PRESHADEROPERAND_OUTPUT.: |
| 180 | case MOJOSHADER_PRESHADEROPERAND_TEMPcxx . . $ MOJOSHADER_PRESHADEROPERAND_TEMP.: |
| 181 | { |
| 182 | int idx = operand->indexcxx . . $ MOJOSHADER_preshaderOperand#index. % 4; |
| 183 | char regch = 'c'; |
| 184 | if (operand->typecxx . . $ MOJOSHADER_preshaderOperand#type. == MOJOSHADER_PRESHADEROPERAND_TEMPcxx . . $ MOJOSHADER_PRESHADEROPERAND_TEMP.) |
| 185 | regch = 'r'; |
| 186 | |
| 187 | if (operand->array_register_countcxx . . $ MOJOSHADER_preshaderOperand#array_register_count. > 0) |
| 188 | { |
| 189 | for (i = operand->array_register_countcxx . . $ MOJOSHADER_preshaderOperand#array_register_count. - 1; i >= 0; i--) |
| 190 | printfcxx . . $ printf(581fddd72a8db8fc).("c%d[", operand->array_registerscxx . . $ MOJOSHADER_preshaderOperand#array_registers.[i]); |
| 191 | printfcxx . . $ printf(581fddd72a8db8fc).("%c%d.%c", regch, operand->indexcxx . . $ MOJOSHADER_preshaderOperand#index. / 4, mask[idx]); |
| 192 | for (i = 0; i < operand->array_register_countcxx . . $ MOJOSHADER_preshaderOperand#array_register_count.; i++) |
| 193 | printfcxx . . $ printf(581fddd72a8db8fc).("]"); |
| 194 | break; |
| 195 | } // if |
| 196 | printfcxx . . $ printf(581fddd72a8db8fc).("%c%d", regch, operand->indexcxx . . $ MOJOSHADER_preshaderOperand#index. / 4); |
| 197 | if (isscalar) |
| 198 | printfcxx . . $ printf(581fddd72a8db8fc).(".%c", mask[idx]); |
| 199 | else if (elems != 4) |
| 200 | { |
| 201 | printfcxx . . $ printf(581fddd72a8db8fc).("."); |
| 202 | for (i = 0; i < elems; i++) |
| 203 | printfcxx . . $ printf(581fddd72a8db8fc).("%c", mask[idx++]); |
| 204 | } // else if |
| 205 | break; |
| 206 | } // case |
| 207 | |
| 208 | default: |
| 209 | printfcxx . . $ printf(581fddd72a8db8fc).("[???{%d, %u}???]", (int) operand->typecxx . . $ MOJOSHADER_preshaderOperand#type., operand->indexcxx . . $ MOJOSHADER_preshaderOperand#index.); |
| 210 | break; |
| 211 | } // switch |
| 212 | } // print_preshader_operand |
| 213 | |
| 214 | |
| 215 | static void print_preshadercxx . . $ print_preshader(3ac49e7599cd227).(const MOJOSHADER_preshadercxx . . $ MOJOSHADER_preshader# *preshader, |
| 216 | const int indent) |
| 217 | { |
| 218 | MOJOSHADER_preshaderInstructioncxx . . $ MOJOSHADER_preshaderInstruction# *inst = preshader->instructionscxx . . $ MOJOSHADER_preshader#instructions.; |
| 219 | int i, j; |
| 220 | |
| 221 | static const char *opcodestr[] = { |
| 222 | "nop", "mov", "neg", "rcp", "frc", "exp", "log", "rsq", "sin", "cos", |
| 223 | "asin", "acos", "atan", "min", "max", "lt", "ge", "add", "mul", |
| 224 | "atan2", "div", "cmp", "movc", "dot", "noise", "min", "max", "lt", |
| 225 | "ge", "add", "mul", "atan2", "div", "dot", "noise" |
| 226 | }; |
| 227 | |
| 228 | INDENTcxx . . $ `utils/testparse.c:56:9`!(); printfcxx . . $ printf(581fddd72a8db8fc).("PRESHADER:\n"); |
| 229 | |
| 230 | print_symbolscxx . . $ print_symbols(c3b4269f936c92d0).(preshader->symbolscxx . . $ MOJOSHADER_preshader#symbols., preshader->symbol_countcxx . . $ MOJOSHADER_preshader#symbol_count., indent + 1); |
| 231 | |
| 232 | for (i = 0; i < preshader->instruction_countcxx . . $ MOJOSHADER_preshader#instruction_count.; i++, inst++) |
| 233 | { |
| 234 | INDENTcxx . . $ `utils/testparse.c:56:9`!(); printfcxx . . $ printf(581fddd72a8db8fc).(" %s ", opcodestr[inst->opcodecxx . . $ MOJOSHADER_preshaderInstruction#opcode.]); |
| 235 | |
| 236 | // print dest register first... |
| 237 | print_preshader_operandcxx . . $ print_preshader_operand(f034b88aed08ba91).(preshader, i, inst->operand_countcxx . . $ MOJOSHADER_preshaderInstruction#operand_count. - 1); |
| 238 | |
| 239 | // ...then the source registers. |
| 240 | for (j = 0; j < inst->operand_countcxx . . $ MOJOSHADER_preshaderInstruction#operand_count. - 1; j++) |
| 241 | { |
| 242 | printfcxx . . $ printf(581fddd72a8db8fc).(", "); |
| 243 | print_preshader_operandcxx . . $ print_preshader_operand(f034b88aed08ba91).(preshader, i, j); |
| 244 | } // for |
| 245 | |
| 246 | printfcxx . . $ printf(581fddd72a8db8fc).("\n"); |
| 247 | } // for |
| 248 | |
| 249 | printfcxx . . $ printf(581fddd72a8db8fc).("\n"); |
| 250 | } // print_preshader |
| 251 | |
| 252 | |
| 253 | static void print_attrscxx . . $ print_attrs(707109755779ca79).(const char *category, const int count, |
| 254 | const MOJOSHADER_attributecxx . . $ MOJOSHADER_attribute# *attributes, |
| 255 | const int indent) |
| 256 | { |
| 257 | INDENTcxx . . $ `utils/testparse.c:56:9`!(); printfcxx . . $ printf(581fddd72a8db8fc).("%s:", category); |
| 258 | if (count == 0) |
| 259 | printfcxx . . $ printf(581fddd72a8db8fc).(" (none.)\n"); |
| 260 | else |
| 261 | { |
| 262 | int i; |
| 263 | printfcxx . . $ printf(581fddd72a8db8fc).("\n"); |
| 264 | for (i = 0; i < count; i++) |
| 265 | { |
| 266 | static const char *usagenames[] = { |
| 267 | "<unknown>", |
| 268 | "position", "blendweight", "blendindices", "normal", |
| 269 | "psize", "texcoord", "tangent", "binormal", "tessfactor", |
| 270 | "positiont", "color", "fog", "depth", "sample" |
| 271 | }; |
| 272 | const MOJOSHADER_attributecxx . . $ MOJOSHADER_attribute# *a = &attributes[i]; |
| 273 | char numstr[16] = { 0 }; |
| 274 | if (a->indexcxx . . $ MOJOSHADER_attribute#index. != 0) |
| 275 | snprintfcxx . . $ snprintf(ea502d73e74c754c).(numstr, sizeof (numstr), "%d", a->indexcxx . . $ MOJOSHADER_attribute#index.); |
| 276 | INDENTcxx . . $ `utils/testparse.c:56:9`!(); |
| 277 | printfcxx . . $ printf(581fddd72a8db8fc).(" * %s%s", usagenames[1 + (int) a->usagecxx . . $ MOJOSHADER_attribute#usage.], numstr); |
| 278 | if (a->namecxx . . $ MOJOSHADER_attribute#name. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 279 | printfcxx . . $ printf(581fddd72a8db8fc).(" (\"%s\")", a->namecxx . . $ MOJOSHADER_attribute#name.); |
| 280 | printfcxx . . $ printf(581fddd72a8db8fc).("\n"); |
| 281 | } // for |
| 282 | } // else |
| 283 | } // print_attrs |
| 284 | |
| 285 | |
| 286 | static void print_shadercxx . . $ print_shader(93a9e575b963e19).(const char *fname, const MOJOSHADER_parseDatacxx . . $ MOJOSHADER_parseData# *pd, |
| 287 | unsigned int indent) |
| 288 | { |
| 289 | INDENTcxx . . $ `utils/testparse.c:56:9`!(); printfcxx . . $ printf(581fddd72a8db8fc).("PROFILE: %s\n", pd->profilecxx . . $ MOJOSHADER_parseData#profile.); |
| 290 | if (pd->error_countcxx . . $ MOJOSHADER_parseData#error_count. > 0) |
| 291 | { |
| 292 | int i; |
| 293 | for (i = 0; i < pd->error_countcxx . . $ MOJOSHADER_parseData#error_count.; i++) |
| 294 | { |
| 295 | const MOJOSHADER_errorcxx . . $ MOJOSHADER_error# *err = &pd->errorscxx . . $ MOJOSHADER_parseData#errors.[i]; |
| 296 | INDENTcxx . . $ `utils/testparse.c:56:9`!(); |
| 297 | printfcxx . . $ printf(581fddd72a8db8fc).("%s:%d: ERROR: %s\n", |
| 298 | err->filenamecxx . . $ MOJOSHADER_error#filename. ? err->filenamecxx . . $ MOJOSHADER_error#filename. : fname, |
| 299 | err->error_positioncxx . . $ MOJOSHADER_error#error_position., err->errorcxx . . $ MOJOSHADER_error#error.); |
| 300 | } // for |
| 301 | } // if |
| 302 | else |
| 303 | { |
| 304 | INDENTcxx . . $ `utils/testparse.c:56:9`!(); printfcxx . . $ printf(581fddd72a8db8fc).("SHADER TYPE: %s\n", shader_typecxx . . $ shader_type(2fa709a0b3e26fab).(pd->shader_typecxx . . $ MOJOSHADER_parseData#shader_type.)); |
| 305 | INDENTcxx . . $ `utils/testparse.c:56:9`!(); printfcxx . . $ printf(581fddd72a8db8fc).("VERSION: %d.%d\n", pd->major_vercxx . . $ MOJOSHADER_parseData#major_ver., pd->minor_vercxx . . $ MOJOSHADER_parseData#minor_ver.); |
| 306 | INDENTcxx . . $ `utils/testparse.c:56:9`!(); printfcxx . . $ printf(581fddd72a8db8fc).("INSTRUCTION COUNT: %d\n", (int) pd->instruction_countcxx . . $ MOJOSHADER_parseData#instruction_count.); |
| 307 | INDENTcxx . . $ `utils/testparse.c:56:9`!(); printfcxx . . $ printf(581fddd72a8db8fc).("MAIN FUNCTION: %s\n", pd->mainfncxx . . $ MOJOSHADER_parseData#mainfn.); |
| 308 | print_attrscxx . . $ print_attrs(707109755779ca79).("INPUTS", pd->attribute_countcxx . . $ MOJOSHADER_parseData#attribute_count., pd->attributescxx . . $ MOJOSHADER_parseData#attributes., indent); |
| 309 | print_attrscxx . . $ print_attrs(707109755779ca79).("OUTPUTS", pd->output_countcxx . . $ MOJOSHADER_parseData#output_count., pd->outputscxx . . $ MOJOSHADER_parseData#outputs., indent); |
| 310 | |
| 311 | INDENTcxx . . $ `utils/testparse.c:56:9`!(); printfcxx . . $ printf(581fddd72a8db8fc).("CONSTANTS:"); |
| 312 | if (pd->constant_countcxx . . $ MOJOSHADER_parseData#constant_count. == 0) |
| 313 | printfcxx . . $ printf(581fddd72a8db8fc).(" (none.)\n"); |
| 314 | else |
| 315 | { |
| 316 | int i; |
| 317 | printfcxx . . $ printf(581fddd72a8db8fc).("\n"); |
| 318 | for (i = 0; i < pd->constant_countcxx . . $ MOJOSHADER_parseData#constant_count.; i++) |
| 319 | { |
| 320 | static const char *typenames[] = { "float", "int", "bool" }; |
| 321 | const MOJOSHADER_constantcxx . . $ MOJOSHADER_constant# *c = &pd->constantscxx . . $ MOJOSHADER_parseData#constants.[i]; |
| 322 | INDENTcxx . . $ `utils/testparse.c:56:9`!(); |
| 323 | printfcxx . . $ printf(581fddd72a8db8fc).(" * %d: %s (", c->indexcxx . . $ MOJOSHADER_constant#index., typenames[(int) c->typecxx . . $ MOJOSHADER_constant#type.]); |
| 324 | if (c->typecxx . . $ MOJOSHADER_constant#type. == MOJOSHADER_UNIFORM_FLOATcxx . . $ MOJOSHADER_UNIFORM_FLOAT.) |
| 325 | { |
| 326 | printfcxx . . $ printf(581fddd72a8db8fc).("%f %f %f %f", c->valuecxx . . $ MOJOSHADER_constant#value..fcxx . . $ MOJOSHADER_constant#$anonymous_type_3#f.[0], c->valuecxx . . $ MOJOSHADER_constant#value..fcxx . . $ MOJOSHADER_constant#$anonymous_type_3#f.[1], |
| 327 | c->valuecxx . . $ MOJOSHADER_constant#value..fcxx . . $ MOJOSHADER_constant#$anonymous_type_3#f.[2], c->valuecxx . . $ MOJOSHADER_constant#value..fcxx . . $ MOJOSHADER_constant#$anonymous_type_3#f.[3]); |
| 328 | } // if |
| 329 | else if (c->typecxx . . $ MOJOSHADER_constant#type. == MOJOSHADER_UNIFORM_INTcxx . . $ MOJOSHADER_UNIFORM_INT.) |
| 330 | { |
| 331 | printfcxx . . $ printf(581fddd72a8db8fc).("%d %d %d %d", c->valuecxx . . $ MOJOSHADER_constant#value..icxx . . $ MOJOSHADER_constant#$anonymous_type_3#i.[0], c->valuecxx . . $ MOJOSHADER_constant#value..icxx . . $ MOJOSHADER_constant#$anonymous_type_3#i.[1], |
| 332 | c->valuecxx . . $ MOJOSHADER_constant#value..icxx . . $ MOJOSHADER_constant#$anonymous_type_3#i.[2], c->valuecxx . . $ MOJOSHADER_constant#value..icxx . . $ MOJOSHADER_constant#$anonymous_type_3#i.[3]); |
| 333 | } // else if |
| 334 | else if (c->typecxx . . $ MOJOSHADER_constant#type. == MOJOSHADER_UNIFORM_BOOLcxx . . $ MOJOSHADER_UNIFORM_BOOL.) |
| 335 | { |
| 336 | printfcxx . . $ printf(581fddd72a8db8fc).("%s", c->valuecxx . . $ MOJOSHADER_constant#value..bcxx . . $ MOJOSHADER_constant#$anonymous_type_3#b. ? "true" : "false"); |
| 337 | } // else if |
| 338 | else |
| 339 | { |
| 340 | printfcxx . . $ printf(581fddd72a8db8fc).("???"); |
| 341 | } // else |
| 342 | printfcxx . . $ printf(581fddd72a8db8fc).(")\n"); |
| 343 | } // for |
| 344 | } // else |
| 345 | |
| 346 | INDENTcxx . . $ `utils/testparse.c:56:9`!(); printfcxx . . $ printf(581fddd72a8db8fc).("UNIFORMS:"); |
| 347 | if (pd->uniform_countcxx . . $ MOJOSHADER_parseData#uniform_count. == 0) |
| 348 | printfcxx . . $ printf(581fddd72a8db8fc).(" (none.)\n"); |
| 349 | else |
| 350 | { |
| 351 | int i; |
| 352 | printfcxx . . $ printf(581fddd72a8db8fc).("\n"); |
| 353 | for (i = 0; i < pd->uniform_countcxx . . $ MOJOSHADER_parseData#uniform_count.; i++) |
| 354 | { |
| 355 | static const char *typenames[] = { "float", "int", "bool" }; |
| 356 | const MOJOSHADER_uniformcxx . . $ MOJOSHADER_uniform# *u = &pd->uniformscxx . . $ MOJOSHADER_parseData#uniforms.[i]; |
| 357 | const char *arrayof = ""; |
| 358 | const char *constant = u->constantcxx . . $ MOJOSHADER_uniform#constant. ? "const " : ""; |
| 359 | char arrayrange[64] = { '\0' }; |
| 360 | if (u->array_countcxx . . $ MOJOSHADER_uniform#array_count. > 0) |
| 361 | { |
| 362 | arrayof = "array["; |
| 363 | snprintfcxx . . $ snprintf(ea502d73e74c754c).(arrayrange, sizeof (arrayrange), "%d] ", |
| 364 | u->array_countcxx . . $ MOJOSHADER_uniform#array_count.); |
| 365 | } // if |
| 366 | |
| 367 | INDENTcxx . . $ `utils/testparse.c:56:9`!(); |
| 368 | printfcxx . . $ printf(581fddd72a8db8fc).(" * %d: %s%s%s%s", u->indexcxx . . $ MOJOSHADER_uniform#index., constant, arrayof, |
| 369 | arrayrange, typenames[(int) u->typecxx . . $ MOJOSHADER_uniform#type.]); |
| 370 | if (u->namecxx . . $ MOJOSHADER_uniform#name. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 371 | printfcxx . . $ printf(581fddd72a8db8fc).(" (\"%s\")", u->namecxx . . $ MOJOSHADER_uniform#name.); |
| 372 | printfcxx . . $ printf(581fddd72a8db8fc).("\n"); |
| 373 | } // for |
| 374 | } // else |
| 375 | |
| 376 | INDENTcxx . . $ `utils/testparse.c:56:9`!(); printfcxx . . $ printf(581fddd72a8db8fc).("SAMPLERS:"); |
| 377 | if (pd->sampler_countcxx . . $ MOJOSHADER_parseData#sampler_count. == 0) |
| 378 | printfcxx . . $ printf(581fddd72a8db8fc).(" (none.)\n"); |
| 379 | else |
| 380 | { |
| 381 | int i; |
| 382 | printfcxx . . $ printf(581fddd72a8db8fc).("\n"); |
| 383 | for (i = 0; i < pd->sampler_countcxx . . $ MOJOSHADER_parseData#sampler_count.; i++) |
| 384 | { |
| 385 | static const char *typenames[] = { "2d", "cube", "volume" }; |
| 386 | const MOJOSHADER_samplercxx . . $ MOJOSHADER_sampler# *s = &pd->samplerscxx . . $ MOJOSHADER_parseData#samplers.[i]; |
| 387 | INDENTcxx . . $ `utils/testparse.c:56:9`!(); |
| 388 | printfcxx . . $ printf(581fddd72a8db8fc).(" * %d: %s", s->indexcxx . . $ MOJOSHADER_sampler#index., typenames[(int) s->typecxx . . $ MOJOSHADER_sampler#type.]); |
| 389 | if (s->namecxx . . $ MOJOSHADER_sampler#name. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 390 | printfcxx . . $ printf(581fddd72a8db8fc).(" (\"%s\")", s->namecxx . . $ MOJOSHADER_sampler#name.); |
| 391 | if (s->texbemcxx . . $ MOJOSHADER_sampler#texbem.) |
| 392 | printfcxx . . $ printf(581fddd72a8db8fc).(" [TEXBEM]"); |
| 393 | printfcxx . . $ printf(581fddd72a8db8fc).("\n"); |
| 394 | } // for |
| 395 | } // else |
| 396 | |
| 397 | print_symbolscxx . . $ print_symbols(c3b4269f936c92d0).(pd->symbolscxx . . $ MOJOSHADER_parseData#symbols., pd->symbol_countcxx . . $ MOJOSHADER_parseData#symbol_count., indent); |
| 398 | |
| 399 | if (pd->preshadercxx . . $ MOJOSHADER_parseData#preshader. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 400 | print_preshadercxx . . $ print_preshader(3ac49e7599cd227).(pd->preshadercxx . . $ MOJOSHADER_parseData#preshader., indent); |
| 401 | |
| 402 | if (pd->outputcxx . . $ MOJOSHADER_parseData#output. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 403 | { |
| 404 | const char *output; |
| 405 | int output_len; |
| 406 | int i; |
| 407 | |
| 408 | if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(pd->profilecxx . . $ MOJOSHADER_parseData#profile., "spirv") == 0) |
| 409 | { |
| 410 | #if SUPPORT_PROFILE_SPIRVcxx . . $ `mojoshader_internal.h:210:9`! && defined(MOJOSHADER_HAS_SPIRV_TOOLS) |
| 411 | int binary_len = pd->output_len - sizeof(SpirvPatchTable); |
| 412 | |
| 413 | uint32_t *words = (uint32_t *) pd->output; |
| 414 | size_t word_count = binary_len / 4; |
| 415 | |
| 416 | spv_text text; |
| 417 | spv_diagnostic diagnostic; |
| 418 | spv_context ctx = spvContextCreate(SPV_ENV_UNIVERSAL_1_0); |
| 419 | int options = /*SPV_BINARY_TO_TEXT_OPTION_COLOR |*/ SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES; |
| 420 | spv_result_t disResult = spvBinaryToText(ctx, words, word_count, options, &text, &diagnostic); |
| 421 | if (disResult == SPV_SUCCESS) |
| 422 | { |
| 423 | output = text->str; |
| 424 | output_len = text->length; |
| 425 | } // if |
| 426 | else |
| 427 | { |
| 428 | fprintf(stderr, "\nERROR DIAGNOSTIC: %s\n\n", diagnostic->error); |
| 429 | } // else |
| 430 | |
| 431 | spv_result_t validateResult = spvValidateBinary(ctx, words, word_count, &diagnostic); |
| 432 | if (validateResult != SPV_SUCCESS) |
| 433 | { |
| 434 | fprintf(stderr, "\nVALIDATION FAILURE: %s\n\n", diagnostic->error); |
| 435 | } // if |
| 436 | |
| 437 | if (disResult != SPV_SUCCESS || validateResult != SPV_SUCCESS) |
| 438 | { |
| 439 | exit(EXIT_FAILURE); |
| 440 | } // if |
| 441 | |
| 442 | // FIXME: we're currently just leaking this disassembly... |
| 443 | #else |
| 444 | output = pd->outputcxx . . $ MOJOSHADER_parseData#output.; |
| 445 | output_len = pd->output_lencxx . . $ MOJOSHADER_parseData#output_len.; |
| 446 | #endif |
| 447 | } // if |
| 448 | else |
| 449 | { |
| 450 | output = pd->outputcxx . . $ MOJOSHADER_parseData#output.; |
| 451 | output_len = pd->output_lencxx . . $ MOJOSHADER_parseData#output_len.; |
| 452 | } // else |
| 453 | |
| 454 | INDENTcxx . . $ `utils/testparse.c:56:9`!(); |
| 455 | printfcxx . . $ printf(581fddd72a8db8fc).("OUTPUT:\n"); |
| 456 | indent++; |
| 457 | INDENTcxx . . $ `utils/testparse.c:56:9`!(); |
| 458 | for (i = 0; i < output_len; i++) |
| 459 | { |
| 460 | putcharcxx . . $ putchar(7864480464b09eea).((int) output[i]); |
| 461 | if (output[i] == '\n') |
| 462 | INDENTcxx . . $ `utils/testparse.c:56:9`!(); |
| 463 | } // for |
| 464 | printfcxx . . $ printf(581fddd72a8db8fc).("\n"); |
| 465 | indent--; |
| 466 | } // if |
| 467 | } // else |
| 468 | |
| 469 | printfcxx . . $ printf(581fddd72a8db8fc).("\n\n"); |
| 470 | } // print_shader |
| 471 | |
| 472 | |
| 473 | #ifdef MOJOSHADER_EFFECT_SUPPORTcxx . . $ `<built-in>:412:9`! |
| 474 | |
| 475 | |
| 476 | static void print_valuecxx . . $ print_value(7643ff8468a6f473).(const MOJOSHADER_effectValuecxx . . $ MOJOSHADER_effectValue# *value, |
| 477 | const unsigned int indent) |
| 478 | { |
| 479 | int i, r, c; |
| 480 | |
| 481 | INDENTcxx . . $ `utils/testparse.c:56:9`!(); |
| 482 | printfcxx . . $ printf(581fddd72a8db8fc).("VALUE: %s -> %s\n", value->namecxx . . $ MOJOSHADER_effectValue#name., value->semanticcxx . . $ MOJOSHADER_effectValue#semantic.); |
| 483 | |
| 484 | static const char *classes[] = |
| 485 | { |
| 486 | "SCALAR", |
| 487 | "VECTOR", |
| 488 | "ROW-MAJOR MATRIX", |
| 489 | "COLUMN-MAJOR MATRIX", |
| 490 | "OBJECT", |
| 491 | "STRUCT" |
| 492 | }; |
| 493 | static const char *types[] = |
| 494 | { |
| 495 | "VOID", |
| 496 | "BOOL", |
| 497 | "INT", |
| 498 | "FLOAT", |
| 499 | "STRING", |
| 500 | "TEXTURE", |
| 501 | "TEXTURE1D", |
| 502 | "TEXTURE2D", |
| 503 | "TEXTURE3D", |
| 504 | "TEXTURECUBE", |
| 505 | "SAMPLER", |
| 506 | "SAMPLER1D", |
| 507 | "SAMPLER2D", |
| 508 | "SAMPLER3D", |
| 509 | "SAMPLERCUBE", |
| 510 | "PIXELSHADER", |
| 511 | "VERTEXSHADER", |
| 512 | "UNSUPPORTED" |
| 513 | }; |
| 514 | do_indentcxx . . $ do_indent(cb2f890c2fdad230).(indent + 1); |
| 515 | printfcxx . . $ printf(581fddd72a8db8fc).("CLASS: %s\n", classes[value->typecxx . . $ MOJOSHADER_effectValue#type..parameter_classcxx . . $ MOJOSHADER_symbolTypeInfo#parameter_class.]); |
| 516 | do_indentcxx . . $ do_indent(cb2f890c2fdad230).(indent + 1); |
| 517 | printfcxx . . $ printf(581fddd72a8db8fc).("TYPE: %s\n", types[value->typecxx . . $ MOJOSHADER_effectValue#type..parameter_typecxx . . $ MOJOSHADER_symbolTypeInfo#parameter_type.]); |
| 518 | |
| 519 | do_indentcxx . . $ do_indent(cb2f890c2fdad230).(indent + 1); |
| 520 | printfcxx . . $ printf(581fddd72a8db8fc).("ROWS/COLUMNS/ELEMENTS: %d, %d, %d\n", |
| 521 | value->typecxx . . $ MOJOSHADER_effectValue#type..rowscxx . . $ MOJOSHADER_symbolTypeInfo#rows., value->typecxx . . $ MOJOSHADER_effectValue#type..columnscxx . . $ MOJOSHADER_symbolTypeInfo#columns., value->typecxx . . $ MOJOSHADER_effectValue#type..elementscxx . . $ MOJOSHADER_symbolTypeInfo#elements.); |
| 522 | do_indentcxx . . $ do_indent(cb2f890c2fdad230).(indent + 1); |
| 523 | printfcxx . . $ printf(581fddd72a8db8fc).("TOTAL VALUES: %d\n", value->value_countcxx . . $ MOJOSHADER_effectValue#value_count.); |
| 524 | |
| 525 | if (value->typecxx . . $ MOJOSHADER_effectValue#type..parameter_typecxx . . $ MOJOSHADER_symbolTypeInfo#parameter_type. == MOJOSHADER_SYMTYPE_SAMPLERcxx . . $ MOJOSHADER_SYMTYPE_SAMPLER. |
| 526 | || value->typecxx . . $ MOJOSHADER_effectValue#type..parameter_typecxx . . $ MOJOSHADER_symbolTypeInfo#parameter_type. == MOJOSHADER_SYMTYPE_SAMPLER1Dcxx . . $ MOJOSHADER_SYMTYPE_SAMPLER1D. |
| 527 | || value->typecxx . . $ MOJOSHADER_effectValue#type..parameter_typecxx . . $ MOJOSHADER_symbolTypeInfo#parameter_type. == MOJOSHADER_SYMTYPE_SAMPLER2Dcxx . . $ MOJOSHADER_SYMTYPE_SAMPLER2D. |
| 528 | || value->typecxx . . $ MOJOSHADER_effectValue#type..parameter_typecxx . . $ MOJOSHADER_symbolTypeInfo#parameter_type. == MOJOSHADER_SYMTYPE_SAMPLER3Dcxx . . $ MOJOSHADER_SYMTYPE_SAMPLER3D. |
| 529 | || value->typecxx . . $ MOJOSHADER_effectValue#type..parameter_typecxx . . $ MOJOSHADER_symbolTypeInfo#parameter_type. == MOJOSHADER_SYMTYPE_SAMPLERCUBEcxx . . $ MOJOSHADER_SYMTYPE_SAMPLERCUBE.) |
| 530 | { |
| 531 | do_indentcxx . . $ do_indent(cb2f890c2fdad230).(indent + 1); |
| 532 | printfcxx . . $ printf(581fddd72a8db8fc).("SAMPLER VALUES:\n"); |
| 533 | for (i = 0; i < value->value_countcxx . . $ MOJOSHADER_effectValue#value_count.; i++) |
| 534 | { |
| 535 | MOJOSHADER_effectSamplerStatecxx . . $ MOJOSHADER_effectSamplerState# *state = &value->valuesSScxx . . $ MOJOSHADER_effectValue#$anonymous_type_0#valuesSS.[i]; |
| 536 | |
| 537 | static const char *samplerstatetypes[] = |
| 538 | { |
| 539 | "UNKNOWN0", |
| 540 | "UNKNOWN1", |
| 541 | "UNKNOWN2", |
| 542 | "UNKNOWN3", |
| 543 | "TEXTURE", |
| 544 | "ADDRESSU", |
| 545 | "ADDRESSV", |
| 546 | "ADDRESSW", |
| 547 | "BORDERCOLOR", |
| 548 | "MAGFILTER", |
| 549 | "MINFILTER", |
| 550 | "MIPFILTER", |
| 551 | "MIPMAPLODBIAS", |
| 552 | "MAXMIPLEVEL", |
| 553 | "MAXANISOTROPY", |
| 554 | "SRGBTEXTURE", |
| 555 | "ELEMENTINDEX", |
| 556 | "DMAPOFFSET", |
| 557 | }; |
| 558 | do_indentcxx . . $ do_indent(cb2f890c2fdad230).(indent + 2); |
| 559 | printfcxx . . $ printf(581fddd72a8db8fc).("TYPE: %s -> ", samplerstatetypes[state->typecxx . . $ MOJOSHADER_effectSamplerState#type.]); |
| 560 | |
| 561 | /* Assuming only one value per state! */ |
| 562 | if (state->typecxx . . $ MOJOSHADER_effectSamplerState#type. == MOJOSHADER_SAMP_MIPMAPLODBIAScxx . . $ MOJOSHADER_SAMP_MIPMAPLODBIAS.) |
| 563 | { |
| 564 | /* float types */ |
| 565 | printfcxx . . $ printf(581fddd72a8db8fc).("%.2f\n", *state->valuecxx . . $ MOJOSHADER_effectSamplerState#value..valuesFcxx . . $ MOJOSHADER_effectValue#$anonymous_type_0#valuesF.); |
| 566 | } // if |
| 567 | else |
| 568 | { |
| 569 | /* int/enum types */ |
| 570 | printfcxx . . $ printf(581fddd72a8db8fc).("%d\n", *state->valuecxx . . $ MOJOSHADER_effectSamplerState#value..valuesIcxx . . $ MOJOSHADER_effectValue#$anonymous_type_0#valuesI.); |
| 571 | } // else |
| 572 | } // for |
| 573 | } // if |
| 574 | else |
| 575 | { |
| 576 | do_indentcxx . . $ do_indent(cb2f890c2fdad230).(indent + 1); |
| 577 | printfcxx . . $ printf(581fddd72a8db8fc).("%s VALUES:\n", types[value->typecxx . . $ MOJOSHADER_effectValue#type..parameter_typecxx . . $ MOJOSHADER_symbolTypeInfo#parameter_type.]); |
| 578 | i = 0; |
| 579 | do |
| 580 | { |
| 581 | static const char *prints[] = |
| 582 | { |
| 583 | "%X ", |
| 584 | "%d ", |
| 585 | "%d ", |
| 586 | "%.2f ", |
| 587 | "%d ", |
| 588 | "%d ", |
| 589 | "%d ", |
| 590 | "%d ", |
| 591 | "%d ", |
| 592 | "%d ", |
| 593 | "SAMPLER?! ", |
| 594 | "SAMPLER?! ", |
| 595 | "SAMPLER?! ", |
| 596 | "SAMPLER?! ", |
| 597 | "SAMPLER?! ", |
| 598 | "%d ", |
| 599 | "%d ", |
| 600 | "%X " |
| 601 | }; |
| 602 | for (r = 0; r < value->typecxx . . $ MOJOSHADER_effectValue#type..rowscxx . . $ MOJOSHADER_symbolTypeInfo#rows.; r++) |
| 603 | { |
| 604 | do_indentcxx . . $ do_indent(cb2f890c2fdad230).(indent + 2); |
| 605 | for (c = 0; c < value->typecxx . . $ MOJOSHADER_effectValue#type..columnscxx . . $ MOJOSHADER_symbolTypeInfo#columns.; c++) |
| 606 | { |
| 607 | const int offset = (i * value->typecxx . . $ MOJOSHADER_effectValue#type..rowscxx . . $ MOJOSHADER_symbolTypeInfo#rows. * 4) + (r * 4) + c; |
| 608 | if (value->typecxx . . $ MOJOSHADER_effectValue#type..parameter_typecxx . . $ MOJOSHADER_symbolTypeInfo#parameter_type. == MOJOSHADER_SYMTYPE_FLOATcxx . . $ MOJOSHADER_SYMTYPE_FLOAT.) |
| 609 | printfcxx . . $ printf(581fddd72a8db8fc).(prints[value->typecxx . . $ MOJOSHADER_effectValue#type..parameter_typecxx . . $ MOJOSHADER_symbolTypeInfo#parameter_type.], value->valuesFcxx . . $ MOJOSHADER_effectValue#$anonymous_type_0#valuesF.[offset]); |
| 610 | else |
| 611 | printfcxx . . $ printf(581fddd72a8db8fc).(prints[value->typecxx . . $ MOJOSHADER_effectValue#type..parameter_typecxx . . $ MOJOSHADER_symbolTypeInfo#parameter_type.], value->valuesIcxx . . $ MOJOSHADER_effectValue#$anonymous_type_0#valuesI.[offset]); |
| 612 | } // for |
| 613 | printfcxx . . $ printf(581fddd72a8db8fc).("\n"); |
| 614 | } // for |
| 615 | } while (++i < value->typecxx . . $ MOJOSHADER_effectValue#type..elementscxx . . $ MOJOSHADER_symbolTypeInfo#elements.); |
| 616 | } // else |
| 617 | } // print_value |
| 618 | |
| 619 | |
| 620 | static void print_effectcxx . . $ print_effect(667140cc1ee56eb).(const char *fname, const MOJOSHADER_effectcxx . . $ MOJOSHADER_effect# *effect, |
| 621 | const unsigned int indent) |
| 622 | { |
| 623 | INDENTcxx . . $ `utils/testparse.c:56:9`!(); |
| 624 | printfcxx . . $ printf(581fddd72a8db8fc).("\n"); |
| 625 | if (effect->error_countcxx . . $ MOJOSHADER_effect#error_count. > 0) |
| 626 | { |
| 627 | int i; |
| 628 | for (i = 0; i < effect->error_countcxx . . $ MOJOSHADER_effect#error_count.; i++) |
| 629 | { |
| 630 | const MOJOSHADER_errorcxx . . $ MOJOSHADER_error# *err = &effect->errorscxx . . $ MOJOSHADER_effect#errors.[i]; |
| 631 | INDENTcxx . . $ `utils/testparse.c:56:9`!(); |
| 632 | printfcxx . . $ printf(581fddd72a8db8fc).("%s:%d: ERROR: %s\n", |
| 633 | err->filenamecxx . . $ MOJOSHADER_error#filename. ? err->filenamecxx . . $ MOJOSHADER_error#filename. : fname, |
| 634 | err->error_positioncxx . . $ MOJOSHADER_error#error_position., err->errorcxx . . $ MOJOSHADER_error#error.); |
| 635 | } // for |
| 636 | } // if |
| 637 | else |
| 638 | { |
| 639 | int i, j, k; |
| 640 | const MOJOSHADER_effectTechniquecxx . . $ MOJOSHADER_effectTechnique# *technique = effect->techniquescxx . . $ MOJOSHADER_effect#techniques.; |
| 641 | const MOJOSHADER_effectObjectcxx . . $ MOJOSHADER_effectObject# *object = effect->objectscxx . . $ MOJOSHADER_effect#objects.; |
| 642 | const MOJOSHADER_effectParamcxx . . $ MOJOSHADER_effectParam# *param = effect->paramscxx . . $ MOJOSHADER_effect#params.; |
| 643 | |
| 644 | for (i = 0; i < effect->param_countcxx . . $ MOJOSHADER_effect#param_count.; i++, param++) |
| 645 | { |
| 646 | INDENTcxx . . $ `utils/testparse.c:56:9`!(); |
| 647 | printfcxx . . $ printf(581fddd72a8db8fc).("PARAM #%d\n", i); |
| 648 | print_valuecxx . . $ print_value(7643ff8468a6f473).(¶m->valuecxx . . $ MOJOSHADER_effectParam#value., indent + 1); |
| 649 | |
| 650 | if (param->annotation_countcxx . . $ MOJOSHADER_effectParam#annotation_count. > 0) |
| 651 | { |
| 652 | do_indentcxx . . $ do_indent(cb2f890c2fdad230).(indent + 1); |
| 653 | printfcxx . . $ printf(581fddd72a8db8fc).("ANNOTATIONS:\n"); |
| 654 | } // if |
| 655 | for (j = 0; j < param->annotation_countcxx . . $ MOJOSHADER_effectParam#annotation_count.; j++) |
| 656 | { |
| 657 | print_valuecxx . . $ print_value(7643ff8468a6f473).(¶m->annotationscxx . . $ MOJOSHADER_effectParam#annotations.[j], indent + 2); |
| 658 | } // for |
| 659 | } // for |
| 660 | printfcxx . . $ printf(581fddd72a8db8fc).("\n"); |
| 661 | |
| 662 | for (i = 0; i < effect->technique_countcxx . . $ MOJOSHADER_effect#technique_count.; i++, technique++) |
| 663 | { |
| 664 | const MOJOSHADER_effectPasscxx . . $ MOJOSHADER_effectPass# *pass = technique->passescxx . . $ MOJOSHADER_effectTechnique#passes.; |
| 665 | INDENTcxx . . $ `utils/testparse.c:56:9`!(); |
| 666 | printfcxx . . $ printf(581fddd72a8db8fc).("TECHNIQUE #%d ('%s'):\n", i, technique->namecxx . . $ MOJOSHADER_effectTechnique#name.); |
| 667 | for (j = 0; j < technique->pass_countcxx . . $ MOJOSHADER_effectTechnique#pass_count.; j++, pass++) |
| 668 | { |
| 669 | const MOJOSHADER_effectStatecxx . . $ MOJOSHADER_effectState# *state = pass->statescxx . . $ MOJOSHADER_effectPass#states.; |
| 670 | do_indentcxx . . $ do_indent(cb2f890c2fdad230).(indent + 1); |
| 671 | printfcxx . . $ printf(581fddd72a8db8fc).("PASS #%d ('%s'):\n", j, pass->namecxx . . $ MOJOSHADER_effectPass#name.); |
| 672 | for (k = 0; k < pass->state_countcxx . . $ MOJOSHADER_effectPass#state_count.; k++, state++) |
| 673 | { |
| 674 | do_indentcxx . . $ do_indent(cb2f890c2fdad230).(indent + 2); |
| 675 | printfcxx . . $ printf(581fddd72a8db8fc).("STATE %d:\n", state->typecxx . . $ MOJOSHADER_effectState#type.); |
| 676 | print_valuecxx . . $ print_value(7643ff8468a6f473).(&state->valuecxx . . $ MOJOSHADER_effectState#value., indent + 3); |
| 677 | } // for |
| 678 | } // for |
| 679 | } // for |
| 680 | printfcxx . . $ printf(581fddd72a8db8fc).("\n"); |
| 681 | |
| 682 | /* Start at index 1, 0 is always empty (thanks Microsoft!) */ |
| 683 | object++; |
| 684 | for (i = 1; i < effect->object_countcxx . . $ MOJOSHADER_effect#object_count.; i++, object++) |
| 685 | { |
| 686 | INDENTcxx . . $ `utils/testparse.c:56:9`!(); |
| 687 | if (object->typecxx . . $ MOJOSHADER_effectObject#type. == MOJOSHADER_SYMTYPE_PIXELSHADERcxx . . $ MOJOSHADER_SYMTYPE_PIXELSHADER. |
| 688 | || object->typecxx . . $ MOJOSHADER_effectObject#type. == MOJOSHADER_SYMTYPE_VERTEXSHADERcxx . . $ MOJOSHADER_SYMTYPE_VERTEXSHADER.) |
| 689 | { |
| 690 | if (object->shadercxx . . $ MOJOSHADER_effectObject#$anonymous_type_2#shader..is_preshadercxx . . $ MOJOSHADER_effectShader#is_preshader.) |
| 691 | { |
| 692 | printfcxx . . $ printf(581fddd72a8db8fc).("OBJECT #%d: PRESHADER, technique %u, pass %u, param %s\n", i, |
| 693 | object->shadercxx . . $ MOJOSHADER_effectObject#$anonymous_type_2#shader..techniquecxx . . $ MOJOSHADER_effectShader#technique., object->shadercxx . . $ MOJOSHADER_effectObject#$anonymous_type_2#shader..passcxx . . $ MOJOSHADER_effectShader#pass., |
| 694 | effect->paramscxx . . $ MOJOSHADER_effect#params.[object->shadercxx . . $ MOJOSHADER_effectObject#$anonymous_type_2#shader..paramscxx . . $ MOJOSHADER_effectShader#params.[0]].valuecxx . . $ MOJOSHADER_effectParam#value..namecxx . . $ MOJOSHADER_effectValue#name.); |
| 695 | print_preshadercxx . . $ print_preshader(3ac49e7599cd227).(object->shadercxx . . $ MOJOSHADER_effectObject#$anonymous_type_2#shader..preshadercxx . . $ MOJOSHADER_effectShader#$anonymous_type_1#preshader., indent + 1); |
| 696 | } // if |
| 697 | else |
| 698 | { |
| 699 | printfcxx . . $ printf(581fddd72a8db8fc).("OBJECT #%d: SHADER, technique %u, pass %u\n", i, |
| 700 | object->shadercxx . . $ MOJOSHADER_effectObject#$anonymous_type_2#shader..techniquecxx . . $ MOJOSHADER_effectShader#technique., object->shadercxx . . $ MOJOSHADER_effectObject#$anonymous_type_2#shader..passcxx . . $ MOJOSHADER_effectShader#pass.); |
| 701 | print_shadercxx . . $ print_shader(93a9e575b963e19).(fname, |
| 702 | (MOJOSHADER_parseDatacxx . . $ MOJOSHADER_parseData#*) object->shadercxx . . $ MOJOSHADER_effectObject#$anonymous_type_2#shader..shadercxx . . $ MOJOSHADER_effectShader#$anonymous_type_1#shader., |
| 703 | indent + 1); |
| 704 | } // else |
| 705 | } // if |
| 706 | else if (object->typecxx . . $ MOJOSHADER_effectObject#type. == MOJOSHADER_SYMTYPE_STRINGcxx . . $ MOJOSHADER_SYMTYPE_STRING.) |
| 707 | printfcxx . . $ printf(581fddd72a8db8fc).("OBJECT #%d: STRING, '%s'\n", i, |
| 708 | object->stringcxx . . $ MOJOSHADER_effectObject#$anonymous_type_2#string..stringcxx . . $ MOJOSHADER_effectString#string.); |
| 709 | else if (object->typecxx . . $ MOJOSHADER_effectObject#type. == MOJOSHADER_SYMTYPE_SAMPLERcxx . . $ MOJOSHADER_SYMTYPE_SAMPLER. |
| 710 | || object->typecxx . . $ MOJOSHADER_effectObject#type. == MOJOSHADER_SYMTYPE_SAMPLER1Dcxx . . $ MOJOSHADER_SYMTYPE_SAMPLER1D. |
| 711 | || object->typecxx . . $ MOJOSHADER_effectObject#type. == MOJOSHADER_SYMTYPE_SAMPLER2Dcxx . . $ MOJOSHADER_SYMTYPE_SAMPLER2D. |
| 712 | || object->typecxx . . $ MOJOSHADER_effectObject#type. == MOJOSHADER_SYMTYPE_SAMPLER3Dcxx . . $ MOJOSHADER_SYMTYPE_SAMPLER3D. |
| 713 | || object->typecxx . . $ MOJOSHADER_effectObject#type. == MOJOSHADER_SYMTYPE_SAMPLERCUBEcxx . . $ MOJOSHADER_SYMTYPE_SAMPLERCUBE.) |
| 714 | printfcxx . . $ printf(581fddd72a8db8fc).("OBJECT #%d: MAPPING, '%s'\n", i, |
| 715 | object->mappingcxx . . $ MOJOSHADER_effectObject#$anonymous_type_2#mapping..namecxx . . $ MOJOSHADER_effectSamplerMap#name.); |
| 716 | else if (object->typecxx . . $ MOJOSHADER_effectObject#type. == MOJOSHADER_SYMTYPE_TEXTUREcxx . . $ MOJOSHADER_SYMTYPE_TEXTURE. |
| 717 | || object->typecxx . . $ MOJOSHADER_effectObject#type. == MOJOSHADER_SYMTYPE_TEXTURE1Dcxx . . $ MOJOSHADER_SYMTYPE_TEXTURE1D. |
| 718 | || object->typecxx . . $ MOJOSHADER_effectObject#type. == MOJOSHADER_SYMTYPE_TEXTURE2Dcxx . . $ MOJOSHADER_SYMTYPE_TEXTURE2D. |
| 719 | || object->typecxx . . $ MOJOSHADER_effectObject#type. == MOJOSHADER_SYMTYPE_TEXTURE3Dcxx . . $ MOJOSHADER_SYMTYPE_TEXTURE3D. |
| 720 | || object->typecxx . . $ MOJOSHADER_effectObject#type. == MOJOSHADER_SYMTYPE_TEXTURECUBEcxx . . $ MOJOSHADER_SYMTYPE_TEXTURECUBE.) |
| 721 | printfcxx . . $ printf(581fddd72a8db8fc).("OBJECT #%d: TEXTURE\n", i); |
| 722 | else |
| 723 | printfcxx . . $ printf(581fddd72a8db8fc).("UNKNOWN OBJECT: #%d\n", i); |
| 724 | } // for |
| 725 | } // else |
| 726 | } // print_effect |
| 727 | |
| 728 | |
| 729 | static const char *effect_profilecxx . . $ effect_profile. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 730 | |
| 731 | |
| 732 | static void* MOJOSHADERCALLcxx . . $ `mojoshader.h:42:9`! effect_compile_shadercxx . . $ effect_compile_shader(68f6eaaacfd647d2).( |
| 733 | const void *ctx, |
| 734 | const char *mainfn, |
| 735 | const unsigned char *tokenbuf, |
| 736 | const unsigned int bufsize, |
| 737 | const MOJOSHADER_swizzlecxx . . $ MOJOSHADER_swizzle# *swiz, |
| 738 | const unsigned int swizcount, |
| 739 | const MOJOSHADER_samplerMapcxx . . $ MOJOSHADER_samplerMap# *smap, |
| 740 | const unsigned int smapcount |
| 741 | ) { |
| 742 | return (MOJOSHADER_parseDatacxx . . $ MOJOSHADER_parseData#*) MOJOSHADER_parsecxx . . $ MOJOSHADER_parse(ff0909865cf9979a).(effect_profilecxx . . $ effect_profile., mainfn, |
| 743 | tokenbuf, bufsize, |
| 744 | swiz, swizcount, |
| 745 | smap, smapcount, |
| 746 | Malloccxx . . $ `utils/testparse.c:45:9`!, Freecxx . . $ `utils/testparse.c:46:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 747 | } // effect_compile_shader |
| 748 | |
| 749 | |
| 750 | static void MOJOSHADERCALLcxx . . $ `mojoshader.h:42:9`! effect_delete_shadercxx . . $ effect_delete_shader(f73ea46a8f2f0896).(const void *ctx, void *shader) |
| 751 | { |
| 752 | MOJOSHADER_freeParseDatacxx . . $ MOJOSHADER_freeParseData(c292f651a0772a1d).((MOJOSHADER_parseDatacxx . . $ MOJOSHADER_parseData#*) shader); |
| 753 | } // effect_delete_shader |
| 754 | |
| 755 | |
| 756 | static MOJOSHADER_parseDatacxx . . $ MOJOSHADER_parseData#* MOJOSHADERCALLcxx . . $ `mojoshader.h:42:9`! effect_get_parse_datacxx . . $ effect_get_parse_data(bb5859e60c5bbe9d).(void *shader) |
| 757 | { |
| 758 | return (MOJOSHADER_parseDatacxx . . $ MOJOSHADER_parseData#*) shader; |
| 759 | } // effect_get_parse_data |
| 760 | |
| 761 | |
| 762 | #endif // MOJOSHADER_EFFECT_SUPPORT |
| 763 | |
| 764 | |
| 765 | static int do_parsecxx . . $ do_parse(c79d52b0ffbee706).(const char *fname, const unsigned char *buf, |
| 766 | const int len, const char *prof) |
| 767 | { |
| 768 | int i; |
| 769 | int retval = 0; |
| 770 | |
| 771 | // magic for an effects file (!!! FIXME: I _think_). |
| 772 | if ( ((buf[0] == 0x01) && (buf[1] == 0x09) && |
| 773 | (buf[2] == 0xFF) && (buf[3] == 0xFE)) || |
| 774 | ((buf[0] == 0xCF) && (buf[1] == 0x0B) && |
| 775 | (buf[2] == 0xF0) && (buf[3] == 0xBC)) ) |
| 776 | { |
| 777 | #ifdef MOJOSHADER_EFFECT_SUPPORTcxx . . $ `<built-in>:412:9`! |
| 778 | const MOJOSHADER_effectcxx . . $ MOJOSHADER_effect# *effect; |
| 779 | const MOJOSHADER_effectShaderContextcxx . . $ MOJOSHADER_effectShaderContext# ctx = |
| 780 | { |
| 781 | effect_compile_shadercxx . . $ effect_compile_shader(68f6eaaacfd647d2)., |
| 782 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, /* Meh! */ |
| 783 | effect_delete_shadercxx . . $ effect_delete_shader(f73ea46a8f2f0896)., |
| 784 | effect_get_parse_datacxx . . $ effect_get_parse_data(bb5859e60c5bbe9d)., |
| 785 | /* Meh! */ |
| 786 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, |
| 787 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, |
| 788 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, |
| 789 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! |
| 790 | }; |
| 791 | effect_profilecxx . . $ effect_profile. = prof; |
| 792 | effect = MOJOSHADER_compileEffectcxx . . $ MOJOSHADER_compileEffect(12c7c1c1bd2eab4f).(buf, len, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0, &ctx); |
| 793 | int error_count = effect->error_countcxx . . $ MOJOSHADER_effect#error_count.; |
| 794 | for (i = 0; i < effect->object_countcxx . . $ MOJOSHADER_effect#object_count.; i++) |
| 795 | { |
| 796 | MOJOSHADER_effectObjectcxx . . $ MOJOSHADER_effectObject# *object = &effect->objectscxx . . $ MOJOSHADER_effect#objects.[i]; |
| 797 | switch (object->typecxx . . $ MOJOSHADER_effectObject#type.) |
| 798 | { |
| 799 | case MOJOSHADER_SYMTYPE_VERTEXSHADERcxx . . $ MOJOSHADER_SYMTYPE_VERTEXSHADER.: |
| 800 | case MOJOSHADER_SYMTYPE_PIXELSHADERcxx . . $ MOJOSHADER_SYMTYPE_PIXELSHADER.: |
| 801 | if (!object->shadercxx . . $ MOJOSHADER_effectObject#$anonymous_type_2#shader..is_preshadercxx . . $ MOJOSHADER_effectShader#is_preshader.) |
| 802 | { |
| 803 | const MOJOSHADER_parseDatacxx . . $ MOJOSHADER_parseData# *shader = |
| 804 | ctx.getParseDatacxx . . $ MOJOSHADER_effectShaderContext#getParseData.(object->shadercxx . . $ MOJOSHADER_effectObject#$anonymous_type_2#shader..shadercxx . . $ MOJOSHADER_effectShader#$anonymous_type_1#shader.); |
| 805 | if (shader) |
| 806 | error_count += shader->error_countcxx . . $ MOJOSHADER_parseData#error_count.; |
| 807 | } // if |
| 808 | break; |
| 809 | default: |
| 810 | break; |
| 811 | } |
| 812 | } |
| 813 | retval = (error_count == 0); |
| 814 | printfcxx . . $ printf(581fddd72a8db8fc).("EFFECT: %s\n", fname); |
| 815 | print_effectcxx . . $ print_effect(667140cc1ee56eb).(fname, effect, 1); |
| 816 | MOJOSHADER_deleteEffectcxx . . $ MOJOSHADER_deleteEffect(22c98fed39e565dd).(effect); |
| 817 | #else |
| 818 | printf("Is an effect, but effect support is disabled!\n"); |
| 819 | #endif |
| 820 | } // if |
| 821 | |
| 822 | else // do it as a regular compiled shader. |
| 823 | { |
| 824 | const MOJOSHADER_parseDatacxx . . $ MOJOSHADER_parseData# *pd; |
| 825 | pd = MOJOSHADER_parsecxx . . $ MOJOSHADER_parse(ff0909865cf9979a).(prof, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, buf, len, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0, |
| 826 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0, Malloccxx . . $ `utils/testparse.c:45:9`!, Freecxx . . $ `utils/testparse.c:46:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 827 | retval = (pd->error_countcxx . . $ MOJOSHADER_parseData#error_count. == 0); |
| 828 | printfcxx . . $ printf(581fddd72a8db8fc).("SHADER: %s\n", fname); |
| 829 | print_shadercxx . . $ print_shader(93a9e575b963e19).(fname, pd, 1); |
| 830 | MOJOSHADER_freeParseDatacxx . . $ MOJOSHADER_freeParseData(c292f651a0772a1d).(pd); |
| 831 | } // else |
| 832 | |
| 833 | return retval; |
| 834 | } // do_parse |
| 835 | |
| 836 | |
| 837 | int maincxx . . $ main(afcd3168fc1188a4).(int argc, char **argv) |
| 838 | { |
| 839 | int retval = 0; |
| 840 | |
| 841 | printfcxx . . $ printf(581fddd72a8db8fc).("MojoShader testparse\n"); |
| 842 | printfcxx . . $ printf(581fddd72a8db8fc).("Compiled against changeset %s\n", MOJOSHADER_CHANGESETcxx . . $ `mojoshader_version.h:5:9`!); |
| 843 | printfcxx . . $ printf(581fddd72a8db8fc).("Linked against changeset %s\n", MOJOSHADER_changesetcxx . . $ MOJOSHADER_changeset(33a1f659e94feb42).()); |
| 844 | printfcxx . . $ printf(581fddd72a8db8fc).("\n"); |
| 845 | |
| 846 | if (argc <= 2) |
| 847 | printfcxx . . $ printf(581fddd72a8db8fc).("\n\nUSAGE: %s <profile> [file1] ... [fileN]\n\n", argv[0]); |
| 848 | else |
| 849 | { |
| 850 | const char *profile = argv[1]; |
| 851 | int i; |
| 852 | |
| 853 | for (i = 2; i < argc; i++) |
| 854 | { |
| 855 | FILEcxx . . $ FILE# *io = fopencxx . . $ fopen(82ec0787cd37e0a3).(argv[i], "rb"); |
| 856 | if (io == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 857 | printfcxx . . $ printf(581fddd72a8db8fc).(" ... fopen('%s') failed.\n", argv[i]); |
| 858 | else |
| 859 | { |
| 860 | unsigned char *buf = (unsigned char *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(1000000); |
| 861 | int rc = freadcxx . . $ fread(738fc8ac1d711e58).(buf, 1, 1000000, io); |
| 862 | fclosecxx . . $ fclose(89bc1efcdac0ca22).(io); |
| 863 | if (!do_parsecxx . . $ do_parse(c79d52b0ffbee706).(argv[i], buf, rc, profile)) |
| 864 | retval = 1; |
| 865 | freecxx . . $ free(5d22bdacc48458e8).(buf); |
| 866 | } // else |
| 867 | } // for |
| 868 | } // else |
| 869 | |
| 870 | return retval; |
| 871 | } // main |
| 872 | |
| 873 | // end of testparse.c ... |
| 874 |