| 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 | #define __MOJOSHADER_INTERNAL__ 1 |
| 11 | #include "mojoshader_profile.h" |
| 12 | |
| 13 | #pragma GCC visibility push(hidden) |
| 14 | |
| 15 | // !!! FIXME: A lot of this is cut-and-paste from the GLSL/Metal versions. |
| 16 | #if SUPPORT_PROFILE_HLSL |
| 17 | |
| 18 | #define EMIT_HLSL_OPCODE_UNIMPLEMENTED_FUNC(op) \ |
| 19 | void emit_HLSL_##op(Context *ctx) { \ |
| 20 | fail(ctx, #op " unimplemented in hlsl profile"); \ |
| 21 | } |
| 22 | |
| 23 | static inline const char *get_HLSL_register_string(Context *ctx, |
| 24 | const RegisterType regtype, const int regnum, |
| 25 | char *regnum_str, const size_t regnum_size) |
| 26 | { |
| 27 | // turns out these are identical at the moment. |
| 28 | return get_D3D_register_string(ctx,regtype,regnum,regnum_str,regnum_size); |
| 29 | } // get_HLSL_register_string |
| 30 | |
| 31 | const char *get_HLSL_uniform_type(Context *ctx, const RegisterType rtype) |
| 32 | { |
| 33 | switch (rtype) |
| 34 | { |
| 35 | case REG_TYPE_CONST: return "float4"; |
| 36 | case REG_TYPE_CONSTINT: return "int4"; |
| 37 | case REG_TYPE_CONSTBOOL: return "bool"; |
| 38 | default: fail(ctx, "BUG: used a uniform we don't know how to define."); |
| 39 | } // switch |
| 40 | |
| 41 | return NULL; |
| 42 | } // get_HLSL_uniform_type |
| 43 | |
| 44 | const char *get_HLSL_varname_in_buf(Context *ctx, RegisterType rt, |
| 45 | int regnum, char *buf, |
| 46 | const size_t len) |
| 47 | { |
| 48 | char regnum_str[16]; |
| 49 | const char *regtype_str = get_HLSL_register_string(ctx, rt, regnum, |
| 50 | regnum_str, sizeof (regnum_str)); |
| 51 | snprintf(buf,len,"%s%s", regtype_str, regnum_str); |
| 52 | return buf; |
| 53 | } // get_HLSL_varname_in_buf |
| 54 | |
| 55 | const char *get_HLSL_varname(Context *ctx, RegisterType rt, int regnum) |
| 56 | { |
| 57 | char buf[64]; |
| 58 | get_HLSL_varname_in_buf(ctx, rt, regnum, buf, sizeof(buf)); |
| 59 | return StrDup(ctx, buf); |
| 60 | } // get_HLSL_varname |
| 61 | |
| 62 | static inline const char *get_HLSL_const_array_varname_in_buf(Context *ctx, |
| 63 | const int base, const int size, |
| 64 | char *buf, const size_t buflen) |
| 65 | { |
| 66 | snprintf(buf, buflen, "const_array_%d_%d", base, size); |
| 67 | return buf; |
| 68 | } // get_HLSL_const_array_varname_in_buf |
| 69 | |
| 70 | const char *get_HLSL_const_array_varname(Context *ctx, int base, int size) |
| 71 | { |
| 72 | char buf[64]; |
| 73 | get_HLSL_const_array_varname_in_buf(ctx, base, size, buf, sizeof(buf)); |
| 74 | return StrDup(ctx, buf); |
| 75 | } // get_HLSL_const_array_varname |
| 76 | |
| 77 | static inline const char *get_HLSL_input_array_varname(Context *ctx, |
| 78 | char *buf, const size_t buflen) |
| 79 | { |
| 80 | snprintf(buf, buflen, "%s", "vertex_input_array"); |
| 81 | return buf; |
| 82 | } // get_HLSL_input_array_varname |
| 83 | |
| 84 | const char *get_HLSL_uniform_array_varname(Context *ctx, |
| 85 | const RegisterType regtype, |
| 86 | char *buf, const size_t len) |
| 87 | { |
| 88 | const char *type = get_HLSL_uniform_type(ctx, regtype); |
| 89 | snprintf(buf, len, "uniforms_%s", type); |
| 90 | return buf; |
| 91 | } // get_HLSL_uniform_array_varname |
| 92 | |
| 93 | const char *get_HLSL_destarg_varname(Context *ctx, char *buf, size_t len) |
| 94 | { |
| 95 | const DestArgInfo *arg = &ctx->dest_arg; |
| 96 | return get_HLSL_varname_in_buf(ctx, arg->regtype, arg->regnum, buf, len); |
| 97 | } // get_HLSL_destarg_varname |
| 98 | |
| 99 | const char *get_HLSL_srcarg_varname(Context *ctx, const size_t idx, |
| 100 | char *buf, size_t len) |
| 101 | { |
| 102 | if (idx >= STATICARRAYLEN(ctx->source_args)) |
| 103 | { |
| 104 | fail(ctx, "Too many source args"); |
| 105 | *buf = '\0'; |
| 106 | return buf; |
| 107 | } // if |
| 108 | |
| 109 | const SourceArgInfo *arg = &ctx->source_args[idx]; |
| 110 | return get_HLSL_varname_in_buf(ctx, arg->regtype, arg->regnum, buf, len); |
| 111 | } // get_HLSL_srcarg_varname |
| 112 | |
| 113 | const char *make_HLSL_destarg_assign(Context *, char *, const size_t, |
| 114 | const char *, ...) ISPRINTF(4,5); |
| 115 | |
| 116 | const char *make_HLSL_destarg_assign(Context *ctx, char *buf, |
| 117 | const size_t buflen, |
| 118 | const char *fmt, ...) |
| 119 | { |
| 120 | int need_parens = 0; |
| 121 | const DestArgInfo *arg = &ctx->dest_arg; |
| 122 | |
| 123 | if (arg->writemask == 0) |
| 124 | { |
| 125 | *buf = '\0'; |
| 126 | return buf; // no writemask? It's a no-op. |
| 127 | } // if |
| 128 | |
| 129 | const char *clampleft = ""; |
| 130 | const char *clampright = ""; |
| 131 | if (arg->result_mod & MOD_SATURATE) |
| 132 | { |
| 133 | clampleft = "saturate("; |
| 134 | clampright = ")"; |
| 135 | } // if |
| 136 | |
| 137 | // MSDN says MOD_PP is a hint and many implementations ignore it. So do we. |
| 138 | |
| 139 | // CENTROID only allowed in DCL opcodes, which shouldn't come through here. |
| 140 | assert((arg->result_mod & MOD_CENTROID) == 0); |
| 141 | |
| 142 | if (ctx->predicated) |
| 143 | { |
| 144 | fail(ctx, "predicated destinations unsupported"); // !!! FIXME |
| 145 | *buf = '\0'; |
| 146 | return buf; |
| 147 | } // if |
| 148 | |
| 149 | char operation[256]; |
| 150 | va_list ap; |
| 151 | va_start(ap, fmt); |
| 152 | const int len = vsnprintf(operation, sizeof (operation), fmt, ap); |
| 153 | va_end(ap); |
| 154 | if (len >= sizeof (operation)) |
| 155 | { |
| 156 | fail(ctx, "operation string too large"); // I'm lazy. :P |
| 157 | *buf = '\0'; |
| 158 | return buf; |
| 159 | } // if |
| 160 | |
| 161 | const char *result_shift_str = ""; |
| 162 | switch (arg->result_shift) |
| 163 | { |
| 164 | case 0x1: result_shift_str = " * 2.0"; break; |
| 165 | case 0x2: result_shift_str = " * 4.0"; break; |
| 166 | case 0x3: result_shift_str = " * 8.0"; break; |
| 167 | case 0xD: result_shift_str = " / 8.0"; break; |
| 168 | case 0xE: result_shift_str = " / 4.0"; break; |
| 169 | case 0xF: result_shift_str = " / 2.0"; break; |
| 170 | } // switch |
| 171 | need_parens |= (result_shift_str[0] != '\0'); |
| 172 | |
| 173 | char regnum_str[16]; |
| 174 | const char *regtype_str = get_HLSL_register_string(ctx, arg->regtype, |
| 175 | arg->regnum, regnum_str, |
| 176 | sizeof (regnum_str)); |
| 177 | char writemask_str[6]; |
| 178 | size_t i = 0; |
| 179 | const int scalar = isscalar(ctx, ctx->shader_type, arg->regtype, arg->regnum); |
| 180 | if (!scalar && !writemask_xyzw(arg->writemask)) |
| 181 | { |
| 182 | writemask_str[i++] = '.'; |
| 183 | if (arg->writemask0) writemask_str[i++] = 'x'; |
| 184 | if (arg->writemask1) writemask_str[i++] = 'y'; |
| 185 | if (arg->writemask2) writemask_str[i++] = 'z'; |
| 186 | if (arg->writemask3) writemask_str[i++] = 'w'; |
| 187 | } // if |
| 188 | writemask_str[i] = '\0'; |
| 189 | assert(i < sizeof (writemask_str)); |
| 190 | |
| 191 | const char *leftparen = (need_parens) ? "(" : ""; |
| 192 | const char *rightparen = (need_parens) ? ")" : ""; |
| 193 | |
| 194 | snprintf(buf, buflen, "%s%s%s = %s%s%s%s%s%s;", regtype_str, |
| 195 | regnum_str, writemask_str,clampleft, leftparen, |
| 196 | operation, rightparen, result_shift_str, clampright); |
| 197 | // !!! FIXME: make sure the scratch buffer was large enough. |
| 198 | return buf; |
| 199 | } // make_HLSL_destarg_assign |
| 200 | |
| 201 | |
| 202 | char *make_HLSL_swizzle_string(char *swiz_str, const size_t strsize, |
| 203 | const int swizzle, const int writemask) |
| 204 | { |
| 205 | size_t i = 0; |
| 206 | if ( (!no_swizzle(swizzle)) || (!writemask_xyzw(writemask)) ) |
| 207 | { |
| 208 | const int writemask0 = (writemask >> 0) & 0x1; |
| 209 | const int writemask1 = (writemask >> 1) & 0x1; |
| 210 | const int writemask2 = (writemask >> 2) & 0x1; |
| 211 | const int writemask3 = (writemask >> 3) & 0x1; |
| 212 | |
| 213 | const int swizzle_x = (swizzle >> 0) & 0x3; |
| 214 | const int swizzle_y = (swizzle >> 2) & 0x3; |
| 215 | const int swizzle_z = (swizzle >> 4) & 0x3; |
| 216 | const int swizzle_w = (swizzle >> 6) & 0x3; |
| 217 | |
| 218 | swiz_str[i++] = '.'; |
| 219 | if (writemask0) swiz_str[i++] = swizzle_channels[swizzle_x]; |
| 220 | if (writemask1) swiz_str[i++] = swizzle_channels[swizzle_y]; |
| 221 | if (writemask2) swiz_str[i++] = swizzle_channels[swizzle_z]; |
| 222 | if (writemask3) swiz_str[i++] = swizzle_channels[swizzle_w]; |
| 223 | } // if |
| 224 | assert(i < strsize); |
| 225 | swiz_str[i] = '\0'; |
| 226 | return swiz_str; |
| 227 | } // make_HLSL_swizzle_string |
| 228 | |
| 229 | |
| 230 | const char *make_HLSL_srcarg_string(Context *ctx, const size_t idx, |
| 231 | const int writemask, char *buf, |
| 232 | const size_t buflen) |
| 233 | { |
| 234 | *buf = '\0'; |
| 235 | |
| 236 | if (idx >= STATICARRAYLEN(ctx->source_args)) |
| 237 | { |
| 238 | fail(ctx, "Too many source args"); |
| 239 | return buf; |
| 240 | } // if |
| 241 | |
| 242 | const SourceArgInfo *arg = &ctx->source_args[idx]; |
| 243 | |
| 244 | const char *premod_str = ""; |
| 245 | const char *postmod_str = ""; |
| 246 | switch (arg->src_mod) |
| 247 | { |
| 248 | case SRCMOD_NEGATE: |
| 249 | premod_str = "-"; |
| 250 | break; |
| 251 | |
| 252 | case SRCMOD_BIASNEGATE: |
| 253 | premod_str = "-("; |
| 254 | postmod_str = " - 0.5)"; |
| 255 | break; |
| 256 | |
| 257 | case SRCMOD_BIAS: |
| 258 | premod_str = "("; |
| 259 | postmod_str = " - 0.5)"; |
| 260 | break; |
| 261 | |
| 262 | case SRCMOD_SIGNNEGATE: |
| 263 | premod_str = "-(("; |
| 264 | postmod_str = " - 0.5) * 2.0)"; |
| 265 | break; |
| 266 | |
| 267 | case SRCMOD_SIGN: |
| 268 | premod_str = "(("; |
| 269 | postmod_str = " - 0.5) * 2.0)"; |
| 270 | break; |
| 271 | |
| 272 | case SRCMOD_COMPLEMENT: |
| 273 | premod_str = "(1.0 - "; |
| 274 | postmod_str = ")"; |
| 275 | break; |
| 276 | |
| 277 | case SRCMOD_X2NEGATE: |
| 278 | premod_str = "-("; |
| 279 | postmod_str = " * 2.0)"; |
| 280 | break; |
| 281 | |
| 282 | case SRCMOD_X2: |
| 283 | premod_str = "("; |
| 284 | postmod_str = " * 2.0)"; |
| 285 | break; |
| 286 | |
| 287 | case SRCMOD_DZ: |
| 288 | fail(ctx, "SRCMOD_DZ unsupported"); return buf; // !!! FIXME |
| 289 | postmod_str = "_dz"; |
| 290 | break; |
| 291 | |
| 292 | case SRCMOD_DW: |
| 293 | fail(ctx, "SRCMOD_DW unsupported"); return buf; // !!! FIXME |
| 294 | postmod_str = "_dw"; |
| 295 | break; |
| 296 | |
| 297 | case SRCMOD_ABSNEGATE: |
| 298 | premod_str = "-abs("; |
| 299 | postmod_str = ")"; |
| 300 | break; |
| 301 | |
| 302 | case SRCMOD_ABS: |
| 303 | premod_str = "abs("; |
| 304 | postmod_str = ")"; |
| 305 | break; |
| 306 | |
| 307 | case SRCMOD_NOT: |
| 308 | premod_str = "!"; |
| 309 | break; |
| 310 | |
| 311 | case SRCMOD_NONE: |
| 312 | case SRCMOD_TOTAL: |
| 313 | break; // stop compiler whining. |
| 314 | } // switch |
| 315 | |
| 316 | const char *regtype_str = NULL; |
| 317 | |
| 318 | if (!arg->relative) |
| 319 | { |
| 320 | regtype_str = get_HLSL_varname_in_buf(ctx, arg->regtype, arg->regnum, |
| 321 | (char *) alloca(64), 64); |
| 322 | } // if |
| 323 | |
| 324 | const char *rel_lbracket = ""; |
| 325 | char rel_offset[32] = { '\0' }; |
| 326 | const char *rel_rbracket = ""; |
| 327 | char rel_swizzle[4] = { '\0' }; |
| 328 | const char *rel_regtype_str = ""; |
| 329 | if (arg->relative) |
| 330 | { |
| 331 | if (arg->regtype == REG_TYPE_INPUT) |
| 332 | regtype_str=get_HLSL_input_array_varname(ctx,(char*)alloca(64),64); |
| 333 | else |
| 334 | { |
| 335 | assert(arg->regtype == REG_TYPE_CONST); |
| 336 | const int arrayidx = arg->relative_array->index; |
| 337 | const int offset = arg->regnum - arrayidx; |
| 338 | assert(offset >= 0); |
| 339 | if (arg->relative_array->constant) |
| 340 | { |
| 341 | const int arraysize = arg->relative_array->count; |
| 342 | regtype_str = get_HLSL_const_array_varname_in_buf(ctx, |
| 343 | arrayidx, arraysize, (char *) alloca(64), 64); |
| 344 | if (offset != 0) |
| 345 | snprintf(rel_offset, sizeof (rel_offset), "%d + ", offset); |
| 346 | } // if |
| 347 | else |
| 348 | { |
| 349 | regtype_str = get_HLSL_uniform_array_varname(ctx, arg->regtype, |
| 350 | (char *) alloca(64), 64); |
| 351 | if (offset == 0) |
| 352 | { |
| 353 | snprintf(rel_offset, sizeof (rel_offset), |
| 354 | "ARRAYBASE_%d + ", arrayidx); |
| 355 | } // if |
| 356 | else |
| 357 | { |
| 358 | snprintf(rel_offset, sizeof (rel_offset), |
| 359 | "(ARRAYBASE_%d + %d) + ", arrayidx, offset); |
| 360 | } // else |
| 361 | } // else |
| 362 | } // else |
| 363 | |
| 364 | rel_lbracket = "["; |
| 365 | |
| 366 | rel_regtype_str = get_HLSL_varname_in_buf(ctx, arg->relative_regtype, |
| 367 | arg->relative_regnum, |
| 368 | (char *) alloca(64), 64); |
| 369 | rel_swizzle[0] = '.'; |
| 370 | rel_swizzle[1] = swizzle_channels[arg->relative_component]; |
| 371 | rel_swizzle[2] = '\0'; |
| 372 | rel_rbracket = "]"; |
| 373 | } // if |
| 374 | |
| 375 | char swiz_str[6] = { '\0' }; |
| 376 | if (!isscalar(ctx, ctx->shader_type, arg->regtype, arg->regnum)) |
| 377 | { |
| 378 | make_HLSL_swizzle_string(swiz_str, sizeof (swiz_str), |
| 379 | arg->swizzle, writemask); |
| 380 | } // if |
| 381 | |
| 382 | if (regtype_str == NULL) |
| 383 | { |
| 384 | fail(ctx, "Unknown source register type."); |
| 385 | return buf; |
| 386 | } // if |
| 387 | |
| 388 | snprintf(buf, buflen, "%s%s%s%s%s%s%s%s%s", |
| 389 | premod_str, regtype_str, rel_lbracket, rel_offset, |
| 390 | rel_regtype_str, rel_swizzle, rel_rbracket, swiz_str, |
| 391 | postmod_str); |
| 392 | // !!! FIXME: make sure the scratch buffer was large enough. |
| 393 | return buf; |
| 394 | } // make_HLSL_srcarg_string |
| 395 | |
| 396 | // generate some convenience functions. |
| 397 | #define MAKE_HLSL_SRCARG_STRING_(mask, bitmask) \ |
| 398 | static inline const char *make_HLSL_srcarg_string_##mask(Context *ctx, \ |
| 399 | const size_t idx, char *buf, \ |
| 400 | const size_t buflen) { \ |
| 401 | return make_HLSL_srcarg_string(ctx, idx, bitmask, buf, buflen); \ |
| 402 | } |
| 403 | MAKE_HLSL_SRCARG_STRING_(x, (1 << 0)) |
| 404 | MAKE_HLSL_SRCARG_STRING_(y, (1 << 1)) |
| 405 | MAKE_HLSL_SRCARG_STRING_(z, (1 << 2)) |
| 406 | MAKE_HLSL_SRCARG_STRING_(w, (1 << 3)) |
| 407 | MAKE_HLSL_SRCARG_STRING_(scalar, (1 << 0)) |
| 408 | MAKE_HLSL_SRCARG_STRING_(full, 0xF) |
| 409 | MAKE_HLSL_SRCARG_STRING_(masked, ctx->dest_arg.writemask) |
| 410 | MAKE_HLSL_SRCARG_STRING_(vec3, 0x7) |
| 411 | MAKE_HLSL_SRCARG_STRING_(vec2, 0x3) |
| 412 | #undef MAKE_HLSL_SRCARG_STRING_ |
| 413 | |
| 414 | // special cases for comparison opcodes... |
| 415 | |
| 416 | const char *get_HLSL_comparison_string_scalar(Context *ctx) |
| 417 | { |
| 418 | const char *comps[] = { "", ">", "==", ">=", "<", "!=", "<=" }; |
| 419 | if (ctx->instruction_controls >= STATICARRAYLEN(comps)) |
| 420 | { |
| 421 | fail(ctx, "unknown comparison control"); |
| 422 | return ""; |
| 423 | } // if |
| 424 | |
| 425 | return comps[ctx->instruction_controls]; |
| 426 | } // get_HLSL_comparison_string_scalar |
| 427 | |
| 428 | const char *get_HLSL_comparison_string_vector(Context *ctx) |
| 429 | { |
| 430 | return get_HLSL_comparison_string_scalar(ctx); // standard C operators work for vectors in HLSL. |
| 431 | } // get_HLSL_comparison_string_vector |
| 432 | |
| 433 | |
| 434 | void emit_HLSL_start(Context *ctx, const char *profilestr) |
| 435 | { |
| 436 | if (!shader_is_vertex(ctx) && !shader_is_pixel(ctx)) |
| 437 | { |
| 438 | failf(ctx, "Shader type %u unsupported in this profile.", |
| 439 | (uint) ctx->shader_type); |
| 440 | return; |
| 441 | } // if |
| 442 | |
| 443 | if (!ctx->mainfn) |
| 444 | { |
| 445 | if (shader_is_vertex(ctx)) |
| 446 | ctx->mainfn = StrDup(ctx, "VertexShader"); |
| 447 | else if (shader_is_pixel(ctx)) |
| 448 | ctx->mainfn = StrDup(ctx, "PixelShader"); |
| 449 | } // if |
| 450 | |
| 451 | set_output(ctx, &ctx->mainline); |
| 452 | ctx->indent++; |
| 453 | } // emit_HLSL_start |
| 454 | |
| 455 | void emit_HLSL_RET(Context *ctx); |
| 456 | void emit_HLSL_end(Context *ctx) |
| 457 | { |
| 458 | // !!! FIXME: maybe handle this at a higher level? |
| 459 | // ps_1_* writes color to r0 instead oC0. We move it to the right place. |
| 460 | // We don't have to worry about a RET opcode messing this up, since |
| 461 | // RET isn't available before ps_2_0. |
| 462 | if (shader_is_pixel(ctx) && !shader_version_atleast(ctx, 2, 0)) |
| 463 | { |
| 464 | set_used_register(ctx, REG_TYPE_COLOROUT, 0, 1); |
| 465 | output_line(ctx, "oC0 = r0;"); |
| 466 | } // if |
| 467 | |
| 468 | // !!! FIXME: maybe handle this at a higher level? |
| 469 | // force a RET opcode if we're at the end of the stream without one. |
| 470 | if (ctx->previous_opcode != OPCODE_RET) |
| 471 | emit_HLSL_RET(ctx); |
| 472 | } // emit_HLSL_end |
| 473 | |
| 474 | void emit_HLSL_phase(Context *ctx) |
| 475 | { |
| 476 | // no-op in HLSL. |
| 477 | } // emit_HLSL_phase |
| 478 | |
| 479 | void output_HLSL_uniform_array(Context *ctx, const RegisterType regtype, |
| 480 | const int size) |
| 481 | { |
| 482 | if (size > 0) |
| 483 | { |
| 484 | char buf[64]; |
| 485 | get_HLSL_uniform_array_varname(ctx, regtype, buf, sizeof (buf)); |
| 486 | const char *typ; |
| 487 | switch (regtype) |
| 488 | { |
| 489 | case REG_TYPE_CONST: typ = "float4"; break; |
| 490 | case REG_TYPE_CONSTINT: typ = "int4"; break; |
| 491 | case REG_TYPE_CONSTBOOL: typ = "bool"; break; |
| 492 | default: |
| 493 | { |
| 494 | fail(ctx, "BUG: used a uniform we don't know how to define."); |
| 495 | return; |
| 496 | } // default |
| 497 | } // switch |
| 498 | output_line(ctx, "%s %s[%d];", typ, buf, size); |
| 499 | } // if |
| 500 | } // output_HLSL_uniform_array |
| 501 | |
| 502 | void emit_HLSL_finalize(Context *ctx) |
| 503 | { |
| 504 | if (ctx->have_relative_input_registers) // !!! FIXME |
| 505 | fail(ctx, "Relative addressing of input registers not supported."); |
| 506 | |
| 507 | // Check uniform_float4_count too since TEXBEM affects it |
| 508 | if (ctx->uniform_count > 0 || ctx->uniform_float4_count > 0) |
| 509 | { |
| 510 | push_output(ctx, &ctx->preflight); |
| 511 | output_line(ctx, "cbuffer %s_Uniforms : register(b0)", ctx->mainfn); |
| 512 | output_line(ctx, "{"); |
| 513 | ctx->indent++; |
| 514 | output_HLSL_uniform_array(ctx, REG_TYPE_CONST, ctx->uniform_float4_count); |
| 515 | output_HLSL_uniform_array(ctx, REG_TYPE_CONSTINT, ctx->uniform_int4_count); |
| 516 | output_HLSL_uniform_array(ctx, REG_TYPE_CONSTBOOL, ctx->uniform_bool_count); |
| 517 | ctx->indent--; |
| 518 | output_line(ctx, "};"); |
| 519 | output_blank_line(ctx); |
| 520 | pop_output(ctx); |
| 521 | } // if |
| 522 | |
| 523 | // Fill in the shader's mainline function signature. |
| 524 | push_output(ctx, &ctx->mainline_intro); |
| 525 | output_line(ctx, "%s%s %s(%s%s%s)", |
| 526 | ctx->outputs ? ctx->mainfn : "void", |
| 527 | ctx->outputs ? "_Output" : "", |
| 528 | ctx->mainfn, |
| 529 | ctx->inputs ? ctx->mainfn : "", |
| 530 | ctx->inputs ? "_Input" : "", |
| 531 | ctx->inputs ? " input" : ""); |
| 532 | output_line(ctx, "{"); |
| 533 | |
| 534 | if (ctx->outputs) |
| 535 | { |
| 536 | ctx->indent++; |
| 537 | output_line(ctx, "%s%s output = (%s%s) 0;", |
| 538 | ctx->mainfn, "_Output", ctx->mainfn, "_Output"); |
| 539 | |
| 540 | push_output(ctx, &ctx->mainline); |
| 541 | ctx->indent++; |
| 542 | output_line(ctx, "return output;"); |
| 543 | pop_output(ctx); |
| 544 | } // if |
| 545 | pop_output(ctx); |
| 546 | |
| 547 | if (ctx->inputs) |
| 548 | { |
| 549 | push_output(ctx, &ctx->inputs); |
| 550 | output_line(ctx, "};"); |
| 551 | output_blank_line(ctx); |
| 552 | pop_output(ctx); |
| 553 | } // if |
| 554 | |
| 555 | if (ctx->outputs) |
| 556 | { |
| 557 | push_output(ctx, &ctx->outputs); |
| 558 | |
| 559 | // !!! FIXME: Maybe have a better check for this? |
| 560 | if (ctx->hlsl_outpos_name[0] != '\0') |
| 561 | { |
| 562 | output_line(ctx, "\tfloat4 m_%s : SV_Position;", |
| 563 | ctx->hlsl_outpos_name); |
| 564 | } // if |
| 565 | |
| 566 | output_line(ctx, "};"); |
| 567 | output_blank_line(ctx); |
| 568 | pop_output(ctx); |
| 569 | } // if |
| 570 | |
| 571 | // throw some blank lines around to make source more readable. |
| 572 | if (ctx->globals) // don't add a blank line if the section is empty. |
| 573 | { |
| 574 | push_output(ctx, &ctx->globals); |
| 575 | output_blank_line(ctx); |
| 576 | pop_output(ctx); |
| 577 | } // if |
| 578 | |
| 579 | if (ctx->need_max_float) |
| 580 | { |
| 581 | push_output(ctx, &ctx->mainline_top); |
| 582 | ctx->indent++; |
| 583 | output_line(ctx, "#define FLT_MAX 1e38"); |
| 584 | ctx->indent--; |
| 585 | pop_output(ctx); |
| 586 | } // if |
| 587 | } // emit_HLSL_finalize |
| 588 | |
| 589 | void emit_HLSL_global(Context *ctx, RegisterType regtype, int regnum) |
| 590 | { |
| 591 | char varname[64]; |
| 592 | get_HLSL_varname_in_buf(ctx, regtype, regnum, varname, sizeof (varname)); |
| 593 | |
| 594 | push_output(ctx, &ctx->mainline_top); |
| 595 | ctx->indent++; |
| 596 | |
| 597 | switch (regtype) |
| 598 | { |
| 599 | case REG_TYPE_ADDRESS: |
| 600 | if (shader_is_vertex(ctx)) |
| 601 | output_line(ctx, "int4 %s;", varname); |
| 602 | else if (shader_is_pixel(ctx)) // actually REG_TYPE_TEXTURE. |
| 603 | { |
| 604 | // We have to map texture registers to temps for ps_1_1, since |
| 605 | // they work like temps, initialize with tex coords, and the |
| 606 | // ps_1_1 TEX opcode expects to overwrite it. |
| 607 | if (!shader_version_atleast(ctx, 1, 4)) |
| 608 | output_line(ctx, "float4 %s = input.m_%s;",varname,varname); |
| 609 | } // else if |
| 610 | break; |
| 611 | case REG_TYPE_PREDICATE: |
| 612 | output_line(ctx, "bool4 %s;", varname); |
| 613 | break; |
| 614 | case REG_TYPE_TEMP: |
| 615 | output_line(ctx, "float4 %s;", varname); |
| 616 | break; |
| 617 | case REG_TYPE_LOOP: |
| 618 | break; // no-op. We declare these in for loops at the moment. |
| 619 | case REG_TYPE_LABEL: |
| 620 | break; // no-op. If we see it here, it means we optimized it out. |
| 621 | default: |
| 622 | fail(ctx, "BUG: we used a register we don't know how to define."); |
| 623 | break; |
| 624 | } // switch |
| 625 | |
| 626 | pop_output(ctx); |
| 627 | } // emit_HLSL_global |
| 628 | |
| 629 | void emit_HLSL_array(Context *ctx, VariableList *var) |
| 630 | { |
| 631 | // All uniforms (except constant arrays, which are literally constant |
| 632 | // data embedded in HLSL shaders) are now packed into a single array, |
| 633 | // so we can batch the uniform transfers. So this doesn't actually |
| 634 | // define an array here; the one, big array is emitted during |
| 635 | // finalization instead. |
| 636 | // However, we need to #define the offset into the one, big array here, |
| 637 | // and let dereferences use that #define. |
| 638 | const int base = var->index; |
| 639 | const int hlslbase = ctx->uniform_float4_count; |
| 640 | push_output(ctx, &ctx->mainline_top); |
| 641 | ctx->indent++; |
| 642 | output_line(ctx, "const int ARRAYBASE_%d = %d;", base, hlslbase); |
| 643 | pop_output(ctx); |
| 644 | var->emit_position = hlslbase; |
| 645 | } // emit_HLSL_array |
| 646 | |
| 647 | void emit_HLSL_const_array(Context *ctx, const ConstantsList *clist, |
| 648 | int base, int size) |
| 649 | { |
| 650 | char varname[64]; |
| 651 | get_HLSL_const_array_varname_in_buf(ctx,base,size,varname,sizeof(varname)); |
| 652 | |
| 653 | const char *cstr = NULL; |
| 654 | push_output(ctx, &ctx->mainline_top); |
| 655 | ctx->indent++; |
| 656 | output_line(ctx, "const float4 %s[%d] = {", varname, size); |
| 657 | ctx->indent++; |
| 658 | |
| 659 | int i; |
| 660 | for (i = 0; i < size; i++) |
| 661 | { |
| 662 | while (clist->constant.type != MOJOSHADER_UNIFORM_FLOAT) |
| 663 | clist = clist->next; |
| 664 | assert(clist->constant.index == (base + i)); |
| 665 | |
| 666 | char val0[32]; |
| 667 | char val1[32]; |
| 668 | char val2[32]; |
| 669 | char val3[32]; |
| 670 | floatstr(ctx, val0, sizeof (val0), clist->constant.value.f[0], 1); |
| 671 | floatstr(ctx, val1, sizeof (val1), clist->constant.value.f[1], 1); |
| 672 | floatstr(ctx, val2, sizeof (val2), clist->constant.value.f[2], 1); |
| 673 | floatstr(ctx, val3, sizeof (val3), clist->constant.value.f[3], 1); |
| 674 | |
| 675 | output_line(ctx, "float4(%s, %s, %s, %s)%s", val0, val1, val2, val3, |
| 676 | (i < (size-1)) ? "," : ""); |
| 677 | |
| 678 | clist = clist->next; |
| 679 | } // for |
| 680 | |
| 681 | ctx->indent--; |
| 682 | output_line(ctx, "};"); |
| 683 | pop_output(ctx); |
| 684 | } // emit_HLSL_const_array |
| 685 | |
| 686 | void emit_HLSL_uniform(Context *ctx, RegisterType regtype, int regnum, |
| 687 | const VariableList *var) |
| 688 | { |
| 689 | // Now that we're pushing all the uniforms as one big array, pack these |
| 690 | // down, so if we only use register c439, it'll actually map to |
| 691 | // HLSL_uniforms_vec4[0]. As we push one big array, this will prevent |
| 692 | // uploading unused data. |
| 693 | |
| 694 | char varname[64]; |
| 695 | char name[64]; |
| 696 | int index = 0; |
| 697 | |
| 698 | get_HLSL_varname_in_buf(ctx, regtype, regnum, varname, sizeof (varname)); |
| 699 | |
| 700 | push_output(ctx, &ctx->mainline_top); |
| 701 | ctx->indent++; |
| 702 | |
| 703 | if (var == NULL) |
| 704 | { |
| 705 | get_HLSL_uniform_array_varname(ctx, regtype, name, sizeof (name)); |
| 706 | |
| 707 | if (regtype == REG_TYPE_CONST) |
| 708 | index = ctx->uniform_float4_count; |
| 709 | else if (regtype == REG_TYPE_CONSTINT) |
| 710 | index = ctx->uniform_int4_count; |
| 711 | else if (regtype == REG_TYPE_CONSTBOOL) |
| 712 | index = ctx->uniform_bool_count; |
| 713 | else // get_HLSL_uniform_array_varname() would have called fail(). |
| 714 | assert(!(ctx->isfail)); |
| 715 | |
| 716 | output_line(ctx, "#define %s %s[%d]", varname, name, index); |
| 717 | push_output(ctx, &ctx->mainline); |
| 718 | ctx->indent++; |
| 719 | output_line(ctx, "#undef %s", varname); // !!! FIXME: gross. |
| 720 | pop_output(ctx); |
| 721 | } // if |
| 722 | |
| 723 | else |
| 724 | { |
| 725 | const int arraybase = var->index; |
| 726 | if (var->constant) |
| 727 | { |
| 728 | get_HLSL_const_array_varname_in_buf(ctx, arraybase, var->count, |
| 729 | name, sizeof (name)); |
| 730 | index = (regnum - arraybase); |
| 731 | } // if |
| 732 | else |
| 733 | { |
| 734 | assert(var->emit_position != -1); |
| 735 | get_HLSL_uniform_array_varname(ctx, regtype, name, sizeof (name)); |
| 736 | index = (regnum - arraybase) + var->emit_position; |
| 737 | } // else |
| 738 | |
| 739 | output_line(ctx, "#define %s %s[%d];", varname, name, index); |
| 740 | push_output(ctx, &ctx->mainline); |
| 741 | ctx->indent++; |
| 742 | output_line(ctx, "#undef %s", varname); // !!! FIXME: gross. |
| 743 | pop_output(ctx); |
| 744 | } // else |
| 745 | |
| 746 | pop_output(ctx); |
| 747 | } // emit_HLSL_uniform |
| 748 | |
| 749 | void emit_HLSL_sampler(Context *ctx,int stage,TextureType ttype,int tb) |
| 750 | { |
| 751 | char var[64]; |
| 752 | const char *texsuffix = NULL; |
| 753 | switch (ttype) |
| 754 | { |
| 755 | case TEXTURE_TYPE_2D: texsuffix = "2D"; break; |
| 756 | case TEXTURE_TYPE_CUBE: texsuffix = "Cube"; break; |
| 757 | case TEXTURE_TYPE_VOLUME: texsuffix = "3D"; break; |
| 758 | default: assert(!"unexpected texture type"); return; |
| 759 | } // switch |
| 760 | |
| 761 | get_HLSL_varname_in_buf(ctx, REG_TYPE_SAMPLER, stage, var, sizeof(var)); |
| 762 | |
| 763 | push_output(ctx, &ctx->globals); |
| 764 | output_line(ctx, "Texture%s %s_texture : register(t%d);", texsuffix, var, stage); |
| 765 | output_line(ctx, "SamplerState %s : register(%s);", var, var); |
| 766 | pop_output(ctx); |
| 767 | |
| 768 | if (tb) // This sampler used a ps_1_1 TEXBEM opcode? |
| 769 | { |
| 770 | push_output(ctx, &ctx->mainline_top); |
| 771 | ctx->indent++; |
| 772 | char name[64]; |
| 773 | const int index = ctx->uniform_float4_count; |
| 774 | ctx->uniform_float4_count += 2; |
| 775 | get_HLSL_uniform_array_varname(ctx, REG_TYPE_CONST, name, sizeof(name)); |
| 776 | output_line(ctx, "const float4 %s_texbem = %s[%d];", var, name, index); |
| 777 | output_line(ctx, "const float4 %s_texbeml = %s[%d];", var, name, index + 1); |
| 778 | pop_output(ctx); |
| 779 | } // if |
| 780 | } // emit_HLSL_sampler |
| 781 | |
| 782 | |
| 783 | void emit_HLSL_attribute(Context *ctx, RegisterType regtype, int regnum, |
| 784 | MOJOSHADER_usage usage, int index, int wmask, |
| 785 | int flags) |
| 786 | { |
| 787 | // !!! FIXME: this function doesn't deal with write masks at all yet! |
| 788 | const char *usage_str = NULL; |
| 789 | char index_str[16] = { '\0' }; |
| 790 | char var[64]; |
| 791 | char a[256]; |
| 792 | |
| 793 | get_HLSL_varname_in_buf(ctx, regtype, regnum, var, sizeof (var)); |
| 794 | |
| 795 | //assert((flags & MOD_PP) == 0); // !!! FIXME: is PP allowed? |
| 796 | |
| 797 | if (index != 0) // !!! FIXME: a lot of these MUST be zero. |
| 798 | snprintf(index_str, sizeof (index_str), "%u", (uint) index); |
| 799 | |
| 800 | if (shader_is_vertex(ctx)) |
| 801 | { |
| 802 | // pre-vs3 output registers. |
| 803 | // these don't ever happen in DCL opcodes, I think. Map to vs_3_* |
| 804 | // output registers. |
| 805 | if (!shader_version_atleast(ctx, 3, 0)) |
| 806 | { |
| 807 | if (regtype == REG_TYPE_RASTOUT) |
| 808 | { |
| 809 | regtype = REG_TYPE_OUTPUT; |
| 810 | index = regnum; |
| 811 | switch ((const RastOutType) regnum) |
| 812 | { |
| 813 | case RASTOUT_TYPE_POSITION: |
| 814 | usage = MOJOSHADER_USAGE_POSITION; |
| 815 | break; |
| 816 | case RASTOUT_TYPE_FOG: |
| 817 | usage = MOJOSHADER_USAGE_FOG; |
| 818 | break; |
| 819 | case RASTOUT_TYPE_POINT_SIZE: |
| 820 | usage = MOJOSHADER_USAGE_POINTSIZE; |
| 821 | break; |
| 822 | } // switch |
| 823 | } // if |
| 824 | |
| 825 | else if (regtype == REG_TYPE_ATTROUT) |
| 826 | { |
| 827 | regtype = REG_TYPE_OUTPUT; |
| 828 | usage = MOJOSHADER_USAGE_COLOR; |
| 829 | index = regnum; |
| 830 | } // else if |
| 831 | |
| 832 | else if (regtype == REG_TYPE_TEXCRDOUT) |
| 833 | { |
| 834 | regtype = REG_TYPE_OUTPUT; |
| 835 | usage = MOJOSHADER_USAGE_TEXCOORD; |
| 836 | index = regnum; |
| 837 | } // else if |
| 838 | } // if |
| 839 | |
| 840 | if (regtype == REG_TYPE_INPUT) |
| 841 | { |
| 842 | push_output(ctx, &ctx->inputs); |
| 843 | if (buffer_size(ctx->inputs) == 0) |
| 844 | { |
| 845 | output_line(ctx, "struct %s_Input", ctx->mainfn); |
| 846 | output_line(ctx, "{"); |
| 847 | } // if |
| 848 | |
| 849 | ctx->indent++; |
| 850 | switch (usage) |
| 851 | { |
| 852 | case MOJOSHADER_USAGE_BINORMAL: |
| 853 | output_line(ctx, "float4 m_%s : BINORMAL%d;", var, index); |
| 854 | break; |
| 855 | case MOJOSHADER_USAGE_BLENDINDICES: |
| 856 | output_line(ctx, "float4 m_%s : BLENDINDICES%d;", var, index); |
| 857 | break; |
| 858 | case MOJOSHADER_USAGE_BLENDWEIGHT: |
| 859 | output_line(ctx, "float4 m_%s : BLENDWEIGHT%d;", var, index); |
| 860 | break; |
| 861 | case MOJOSHADER_USAGE_COLOR: |
| 862 | output_line(ctx, "float4 m_%s : COLOR%d;", var, index); |
| 863 | break; |
| 864 | case MOJOSHADER_USAGE_NORMAL: |
| 865 | output_line(ctx, "float4 m_%s : NORMAL%d;", var, index); |
| 866 | break; |
| 867 | case MOJOSHADER_USAGE_POSITION: |
| 868 | output_line(ctx, "float4 m_%s : POSITION%d;", var, index); |
| 869 | break; |
| 870 | case MOJOSHADER_USAGE_POSITIONT: |
| 871 | output_line(ctx, "float4 m_%s : POSITIONT;", var); |
| 872 | break; |
| 873 | case MOJOSHADER_USAGE_POINTSIZE: |
| 874 | output_line(ctx, "float4 m_%s : PSIZE;", var); |
| 875 | break; |
| 876 | case MOJOSHADER_USAGE_TANGENT: |
| 877 | output_line(ctx, "float4 m_%s : TANGENT%d;", var, index); |
| 878 | break; |
| 879 | case MOJOSHADER_USAGE_TEXCOORD: |
| 880 | output_line(ctx, "float4 m_%s : TEXCOORD%d;", var, index); |
| 881 | break; |
| 882 | default: |
| 883 | fail(ctx, "Unknown vertex input semantic type!"); |
| 884 | break; |
| 885 | } // case |
| 886 | pop_output(ctx); |
| 887 | |
| 888 | push_output(ctx, &ctx->mainline_top); |
| 889 | ctx->indent++; |
| 890 | output_line(ctx, "#define %s input.m_%s", var, var); |
| 891 | pop_output(ctx); |
| 892 | push_output(ctx, &ctx->mainline); |
| 893 | ctx->indent++; |
| 894 | output_line(ctx, "#undef %s", var); // !!! FIXME: gross. |
| 895 | pop_output(ctx); |
| 896 | } // if |
| 897 | |
| 898 | else if (regtype == REG_TYPE_OUTPUT) |
| 899 | { |
| 900 | push_output(ctx, &ctx->outputs); |
| 901 | if (buffer_size(ctx->outputs) == 0) |
| 902 | { |
| 903 | output_line(ctx, "struct %s_Output", ctx->mainfn); |
| 904 | output_line(ctx, "{"); |
| 905 | } // if |
| 906 | |
| 907 | ctx->indent++; |
| 908 | |
| 909 | switch (usage) |
| 910 | { |
| 911 | case MOJOSHADER_USAGE_BINORMAL: |
| 912 | output_line(ctx, "float4 m_%s : BINORMAL%d;", var, index); |
| 913 | break; |
| 914 | case MOJOSHADER_USAGE_BLENDINDICES: |
| 915 | output_line(ctx, "float4 m_%s : BLENDINDICES%d;", var, index); |
| 916 | break; |
| 917 | case MOJOSHADER_USAGE_BLENDWEIGHT: |
| 918 | output_line(ctx, "float4 m_%s : BLENDWEIGHT%d;", var, index); |
| 919 | break; |
| 920 | case MOJOSHADER_USAGE_COLOR: |
| 921 | output_line(ctx, "float4 m_%s : COLOR%d;", var, index); |
| 922 | break; |
| 923 | case MOJOSHADER_USAGE_FOG: |
| 924 | output_line(ctx, "float m_%s : FOG;", var); |
| 925 | break; |
| 926 | case MOJOSHADER_USAGE_NORMAL: |
| 927 | output_line(ctx, "float4 m_%s : NORMAL%d;", var, index); |
| 928 | break; |
| 929 | case MOJOSHADER_USAGE_POSITION: |
| 930 | if (index == 0) |
| 931 | snprintf(ctx->hlsl_outpos_name, |
| 932 | sizeof(ctx->hlsl_outpos_name), "%s", var); |
| 933 | else |
| 934 | output_line(ctx, "float4 m_%s : POSITION%d;", var, index); |
| 935 | break; |
| 936 | case MOJOSHADER_USAGE_POSITIONT: |
| 937 | output_line(ctx, "float4 m_%s : POSITIONT;", var); |
| 938 | break; |
| 939 | case MOJOSHADER_USAGE_POINTSIZE: |
| 940 | output_line(ctx, "float m_%s : PSIZE;", var); |
| 941 | break; |
| 942 | case MOJOSHADER_USAGE_TANGENT: |
| 943 | output_line(ctx, "float4 m_%s : TANGENT%d;", var, index); |
| 944 | break; |
| 945 | case MOJOSHADER_USAGE_TESSFACTOR: |
| 946 | output_line(ctx, "float m_%s : TESSFACTOR%d;", var, index); |
| 947 | break; |
| 948 | case MOJOSHADER_USAGE_TEXCOORD: |
| 949 | output_line(ctx, "float4 m_%s : TEXCOORD%d;", var, index); |
| 950 | break; |
| 951 | default: |
| 952 | snprintf(a, sizeof(a), "Invalid vertex output semantic %d", usage); |
| 953 | fail(ctx, a); |
| 954 | break; |
| 955 | } // switch |
| 956 | |
| 957 | pop_output(ctx); |
| 958 | |
| 959 | push_output(ctx, &ctx->mainline_top); |
| 960 | ctx->indent++; |
| 961 | output_line(ctx, "#define %s output.m_%s", var, var); |
| 962 | pop_output(ctx); |
| 963 | push_output(ctx, &ctx->mainline); |
| 964 | ctx->indent++; |
| 965 | output_line(ctx, "#undef %s", var); // !!! FIXME: gross. |
| 966 | pop_output(ctx); |
| 967 | } // else if |
| 968 | |
| 969 | else |
| 970 | { |
| 971 | fail(ctx, "unknown vertex shader attribute register"); |
| 972 | } // else |
| 973 | } // if |
| 974 | |
| 975 | else if (shader_is_pixel(ctx)) |
| 976 | { |
| 977 | // samplers DCLs get handled in emit_HLSL_sampler(). |
| 978 | |
| 979 | if (flags & MOD_CENTROID) // !!! FIXME |
| 980 | { |
| 981 | failf(ctx, "centroid unsupported in %s profile", ctx->profile->name); |
| 982 | return; |
| 983 | } // if |
| 984 | |
| 985 | if ((regtype == REG_TYPE_COLOROUT) || (regtype == REG_TYPE_DEPTHOUT)) |
| 986 | { |
| 987 | push_output(ctx, &ctx->outputs); |
| 988 | if (buffer_size(ctx->outputs) == 0) |
| 989 | { |
| 990 | output_line(ctx, "struct %s_Output", ctx->mainfn); |
| 991 | output_line(ctx, "{"); |
| 992 | } // if |
| 993 | ctx->indent++; |
| 994 | |
| 995 | if (regtype == REG_TYPE_COLOROUT) |
| 996 | output_line(ctx, "float4 m_%s : SV_Target%d;", var, regnum); |
| 997 | else if (regtype == REG_TYPE_DEPTHOUT) |
| 998 | output_line(ctx, "float m_%s : SV_Depth;", var); |
| 999 | |
| 1000 | pop_output(ctx); |
| 1001 | |
| 1002 | push_output(ctx, &ctx->mainline_top); |
| 1003 | ctx->indent++; |
| 1004 | output_line(ctx, "#define %s output.m_%s", var, var); |
| 1005 | pop_output(ctx); |
| 1006 | push_output(ctx, &ctx->mainline); |
| 1007 | ctx->indent++; |
| 1008 | output_line(ctx, "#undef %s", var); // !!! FIXME: gross. |
| 1009 | pop_output(ctx); |
| 1010 | } // if |
| 1011 | |
| 1012 | // !!! FIXME: can you actualy have a texture register with COLOR usage? |
| 1013 | else if ((regtype == REG_TYPE_TEXTURE) || |
| 1014 | (regtype == REG_TYPE_INPUT) || |
| 1015 | (regtype == REG_TYPE_MISCTYPE)) |
| 1016 | { |
| 1017 | int skipreference = 0; |
| 1018 | const char *define_start = ""; |
| 1019 | const char *define_end = ""; |
| 1020 | |
| 1021 | push_output(ctx, &ctx->inputs); |
| 1022 | if (buffer_size(ctx->inputs) == 0) |
| 1023 | { |
| 1024 | output_line(ctx, "struct %s_Input", ctx->mainfn); |
| 1025 | output_line(ctx, "{"); |
| 1026 | output_line(ctx, "\t// This must match the vertex output!"); |
| 1027 | output_line(ctx, "\t// Rewrite at link time if needed!"); |
| 1028 | } // if |
| 1029 | ctx->indent++; |
| 1030 | |
| 1031 | if (regtype == REG_TYPE_MISCTYPE) |
| 1032 | { |
| 1033 | const MiscTypeType mt = (MiscTypeType) regnum; |
| 1034 | if (mt == MISCTYPE_TYPE_FACE) |
| 1035 | { |
| 1036 | // In SM 3.0, VFACE was a float whose sign determined |
| 1037 | // face direction. In SM 4.0+, it's just a bool, so |
| 1038 | // we convert the value when we output the #define. |
| 1039 | output_line(ctx, "bool m_%s : SV_IsFrontFace;", var); |
| 1040 | define_start = "("; |
| 1041 | define_end = " ? 1 : -1)"; |
| 1042 | } // if |
| 1043 | else if (mt == MISCTYPE_TYPE_POSITION) |
| 1044 | output_line(ctx, "float4 m_%s : SV_Position;", var); |
| 1045 | else |
| 1046 | fail(ctx, "BUG: unhandled misc register"); |
| 1047 | } // else if |
| 1048 | |
| 1049 | else |
| 1050 | { |
| 1051 | switch (usage) |
| 1052 | { |
| 1053 | case MOJOSHADER_USAGE_TEXCOORD: |
| 1054 | // ps_1_1 does a different hack for this attribute. |
| 1055 | // Refer to emit_HLSL_global()'s REG_TYPE_ADDRESS code. |
| 1056 | if (!shader_version_atleast(ctx, 1, 4)) |
| 1057 | skipreference = 1; |
| 1058 | output_line(ctx, "float4 m_%s : TEXCOORD%d;", var, index); |
| 1059 | break; |
| 1060 | case MOJOSHADER_USAGE_COLOR: |
| 1061 | output_line(ctx, "float4 m_%s : COLOR%d;", var, index); |
| 1062 | break; |
| 1063 | case MOJOSHADER_USAGE_FOG: |
| 1064 | output_line(ctx, "float m_%s : FOG;", var); |
| 1065 | break; |
| 1066 | case MOJOSHADER_USAGE_NORMAL: |
| 1067 | output_line(ctx, "float4 m_%s : NORMAL;", var); |
| 1068 | break; |
| 1069 | case MOJOSHADER_USAGE_POSITION: |
| 1070 | output_line(ctx, "float4 m_%s : POSITION%d;", var, index); |
| 1071 | break; |
| 1072 | default: |
| 1073 | fail(ctx, "BUG: unhandled pixel shader input"); |
| 1074 | break; |
| 1075 | } // switch |
| 1076 | } // else |
| 1077 | |
| 1078 | pop_output(ctx); |
| 1079 | |
| 1080 | if (!skipreference) |
| 1081 | { |
| 1082 | push_output(ctx, &ctx->mainline_top); |
| 1083 | ctx->indent++; |
| 1084 | output_line(ctx, "#define %s %sinput.m_%s%s", var, |
| 1085 | define_start, var, define_end); |
| 1086 | pop_output(ctx); |
| 1087 | push_output(ctx, &ctx->mainline); |
| 1088 | ctx->indent++; |
| 1089 | output_line(ctx, "#undef %s", var); // !!! FIXME: gross. |
| 1090 | pop_output(ctx); |
| 1091 | } // if |
| 1092 | } // else if |
| 1093 | |
| 1094 | else |
| 1095 | { |
| 1096 | fail(ctx, "unknown pixel shader attribute register"); |
| 1097 | } // else |
| 1098 | } // else if |
| 1099 | |
| 1100 | else |
| 1101 | { |
| 1102 | fail(ctx, "Unknown shader type"); // state machine should catch this. |
| 1103 | } // else |
| 1104 | } // emit_HLSL_attribute |
| 1105 | |
| 1106 | void emit_HLSL_NOP(Context *ctx) |
| 1107 | { |
| 1108 | // no-op is a no-op. :) |
| 1109 | } // emit_HLSL_NOP |
| 1110 | |
| 1111 | void emit_HLSL_MOV(Context *ctx) |
| 1112 | { |
| 1113 | char src0[64]; make_HLSL_srcarg_string_masked(ctx, 0, src0, sizeof (src0)); |
| 1114 | char code[128]; |
| 1115 | make_HLSL_destarg_assign(ctx, code, sizeof (code), "%s", src0); |
| 1116 | output_line(ctx, "%s", code); |
| 1117 | } // emit_HLSL_MOV |
| 1118 | |
| 1119 | void emit_HLSL_ADD(Context *ctx) |
| 1120 | { |
| 1121 | char src0[64]; make_HLSL_srcarg_string_masked(ctx, 0, src0, sizeof (src0)); |
| 1122 | char src1[64]; make_HLSL_srcarg_string_masked(ctx, 1, src1, sizeof (src1)); |
| 1123 | char code[128]; |
| 1124 | make_HLSL_destarg_assign(ctx, code, sizeof (code), "%s + %s", src0, src1); |
| 1125 | output_line(ctx, "%s", code); |
| 1126 | } // emit_HLSL_ADD |
| 1127 | |
| 1128 | void emit_HLSL_SUB(Context *ctx) |
| 1129 | { |
| 1130 | char src0[64]; make_HLSL_srcarg_string_masked(ctx, 0, src0, sizeof (src0)); |
| 1131 | char src1[64]; make_HLSL_srcarg_string_masked(ctx, 1, src1, sizeof (src1)); |
| 1132 | char code[128]; |
| 1133 | make_HLSL_destarg_assign(ctx, code, sizeof (code), "%s - %s", src0, src1); |
| 1134 | output_line(ctx, "%s", code); |
| 1135 | } // emit_HLSL_SUB |
| 1136 | |
| 1137 | void emit_HLSL_MAD(Context *ctx) |
| 1138 | { |
| 1139 | char src0[64]; make_HLSL_srcarg_string_masked(ctx, 0, src0, sizeof (src0)); |
| 1140 | char src1[64]; make_HLSL_srcarg_string_masked(ctx, 1, src1, sizeof (src1)); |
| 1141 | char src2[64]; make_HLSL_srcarg_string_masked(ctx, 2, src2, sizeof (src2)); |
| 1142 | char code[128]; |
| 1143 | make_HLSL_destarg_assign(ctx, code, sizeof (code), "(%s * %s) + %s", src0, src1, src2); |
| 1144 | output_line(ctx, "%s", code); |
| 1145 | } // emit_HLSL_MAD |
| 1146 | |
| 1147 | void emit_HLSL_MUL(Context *ctx) |
| 1148 | { |
| 1149 | char src0[64]; make_HLSL_srcarg_string_masked(ctx, 0, src0, sizeof (src0)); |
| 1150 | char src1[64]; make_HLSL_srcarg_string_masked(ctx, 1, src1, sizeof (src1)); |
| 1151 | char code[128]; |
| 1152 | make_HLSL_destarg_assign(ctx, code, sizeof (code), "%s * %s", src0, src1); |
| 1153 | output_line(ctx, "%s", code); |
| 1154 | } // emit_HLSL_MUL |
| 1155 | |
| 1156 | void emit_HLSL_RCP(Context *ctx) |
| 1157 | { |
| 1158 | char src0[64]; make_HLSL_srcarg_string_masked(ctx, 0, src0, sizeof (src0)); |
| 1159 | char code[128]; |
| 1160 | ctx->need_max_float = 1; |
| 1161 | make_HLSL_destarg_assign(ctx, code, sizeof (code), |
| 1162 | "(%s == 0.0) ? FLT_MAX : 1.0 / %s", src0, src0); |
| 1163 | output_line(ctx, "%s", code); |
| 1164 | } // emit_HLSL_RCP |
| 1165 | |
| 1166 | void emit_HLSL_RSQ(Context *ctx) |
| 1167 | { |
| 1168 | char src0[64]; make_HLSL_srcarg_string_masked(ctx, 0, src0, sizeof (src0)); |
| 1169 | char code[128]; |
| 1170 | ctx->need_max_float = 1; |
| 1171 | make_HLSL_destarg_assign(ctx, code, sizeof (code), |
| 1172 | "(%s == 0.0) ? FLT_MAX : rsqrt(abs(%s))", |
| 1173 | src0, src0); |
| 1174 | output_line(ctx, "%s", code); |
| 1175 | } // emit_HLSL_RSQ |
| 1176 | |
| 1177 | void emit_HLSL_dotprod(Context *ctx, const char *src0, const char *src1, |
| 1178 | const char *extra) |
| 1179 | { |
| 1180 | char code[128]; |
| 1181 | make_HLSL_destarg_assign(ctx, code, sizeof (code), "dot(%s, %s)%s", |
| 1182 | src0, src1, extra); |
| 1183 | output_line(ctx, "%s", code); |
| 1184 | } // emit_HLSL_dotprod |
| 1185 | |
| 1186 | void emit_HLSL_DP3(Context *ctx) |
| 1187 | { |
| 1188 | char src0[64]; make_HLSL_srcarg_string_vec3(ctx, 0, src0, sizeof (src0)); |
| 1189 | char src1[64]; make_HLSL_srcarg_string_vec3(ctx, 1, src1, sizeof (src1)); |
| 1190 | emit_HLSL_dotprod(ctx, src0, src1, ""); |
| 1191 | } // emit_HLSL_DP3 |
| 1192 | |
| 1193 | void emit_HLSL_DP4(Context *ctx) |
| 1194 | { |
| 1195 | char src0[64]; make_HLSL_srcarg_string_full(ctx, 0, src0, sizeof (src0)); |
| 1196 | char src1[64]; make_HLSL_srcarg_string_full(ctx, 1, src1, sizeof (src1)); |
| 1197 | emit_HLSL_dotprod(ctx, src0, src1, ""); |
| 1198 | } // emit_HLSL_DP4 |
| 1199 | |
| 1200 | void emit_HLSL_MIN(Context *ctx) |
| 1201 | { |
| 1202 | char src0[64]; make_HLSL_srcarg_string_masked(ctx, 0, src0, sizeof (src0)); |
| 1203 | char src1[64]; make_HLSL_srcarg_string_masked(ctx, 1, src1, sizeof (src1)); |
| 1204 | char code[128]; |
| 1205 | make_HLSL_destarg_assign(ctx, code, sizeof (code), "min(%s, %s)", src0, src1); |
| 1206 | output_line(ctx, "%s", code); |
| 1207 | } // emit_HLSL_MIN |
| 1208 | |
| 1209 | void emit_HLSL_MAX(Context *ctx) |
| 1210 | { |
| 1211 | char src0[64]; make_HLSL_srcarg_string_masked(ctx, 0, src0, sizeof (src0)); |
| 1212 | char src1[64]; make_HLSL_srcarg_string_masked(ctx, 1, src1, sizeof (src1)); |
| 1213 | char code[128]; |
| 1214 | make_HLSL_destarg_assign(ctx, code, sizeof (code), "max(%s, %s)", src0, src1); |
| 1215 | output_line(ctx, "%s", code); |
| 1216 | } // emit_HLSL_MAX |
| 1217 | |
| 1218 | void emit_HLSL_SLT(Context *ctx) |
| 1219 | { |
| 1220 | const int vecsize = vecsize_from_writemask(ctx->dest_arg.writemask); |
| 1221 | char src0[64]; make_HLSL_srcarg_string_masked(ctx, 0, src0, sizeof (src0)); |
| 1222 | char src1[64]; make_HLSL_srcarg_string_masked(ctx, 1, src1, sizeof (src1)); |
| 1223 | char code[128]; |
| 1224 | |
| 1225 | // float(bool) results in 0.0 or 1.0, like SLT wants. |
| 1226 | if (vecsize == 1) |
| 1227 | make_HLSL_destarg_assign(ctx, code, sizeof (code), "float(%s < %s)", src0, src1); |
| 1228 | else |
| 1229 | make_HLSL_destarg_assign(ctx, code, sizeof (code), "%s < %s", src0, src1); |
| 1230 | |
| 1231 | output_line(ctx, "%s", code); |
| 1232 | } // emit_HLSL_SLT |
| 1233 | |
| 1234 | void emit_HLSL_SGE(Context *ctx) |
| 1235 | { |
| 1236 | const int vecsize = vecsize_from_writemask(ctx->dest_arg.writemask); |
| 1237 | char src0[64]; make_HLSL_srcarg_string_masked(ctx, 0, src0, sizeof (src0)); |
| 1238 | char src1[64]; make_HLSL_srcarg_string_masked(ctx, 1, src1, sizeof (src1)); |
| 1239 | char code[128]; |
| 1240 | |
| 1241 | // float(bool) results in 0.0 or 1.0, like SGE wants. |
| 1242 | if (vecsize == 1) |
| 1243 | make_HLSL_destarg_assign(ctx, code, sizeof (code), "float(%s >= %s)", src0, src1); |
| 1244 | else |
| 1245 | make_HLSL_destarg_assign(ctx, code, sizeof (code), "%s >= %s", src0, src1); |
| 1246 | |
| 1247 | output_line(ctx, "%s", code); |
| 1248 | } // emit_HLSL_SGE |
| 1249 | |
| 1250 | void emit_HLSL_EXP(Context *ctx) |
| 1251 | { |
| 1252 | char src0[64]; make_HLSL_srcarg_string_masked(ctx, 0, src0, sizeof (src0)); |
| 1253 | char code[128]; |
| 1254 | make_HLSL_destarg_assign(ctx, code, sizeof (code), "exp2(%s)", src0); |
| 1255 | output_line(ctx, "%s", code); |
| 1256 | } // emit_HLSL_EXP |
| 1257 | |
| 1258 | void emit_HLSL_LOG(Context *ctx) |
| 1259 | { |
| 1260 | char src0[64]; make_HLSL_srcarg_string_masked(ctx, 0, src0, sizeof (src0)); |
| 1261 | char code[128]; |
| 1262 | make_HLSL_destarg_assign(ctx, code, sizeof (code), "log2(%s)", src0); |
| 1263 | output_line(ctx, "%s", code); |
| 1264 | } // emit_HLSL_LOG |
| 1265 | |
| 1266 | void emit_HLSL_LIT(Context *ctx) |
| 1267 | { |
| 1268 | char src0[64]; make_HLSL_srcarg_string_full(ctx, 0, src0, sizeof (src0)); |
| 1269 | char code[128]; |
| 1270 | const char *maxp = "127.9961"; // value from the dx9 reference. |
| 1271 | make_HLSL_destarg_assign(ctx, code, sizeof (code), |
| 1272 | "lit(%s.x, %s.y, clamp(%s.w, -%s, %s))", |
| 1273 | src0, src0, src0, maxp, maxp); |
| 1274 | output_line(ctx, "%s", code); |
| 1275 | } // emit_HLSL_LIT |
| 1276 | |
| 1277 | void emit_HLSL_DST(Context *ctx) |
| 1278 | { |
| 1279 | // !!! FIXME: needs to take ctx->dst_arg.writemask into account |
| 1280 | // !!! FIXME: can we use dst() intrinsic instead? -caleb |
| 1281 | char src0_y[64]; make_HLSL_srcarg_string_y(ctx, 0, src0_y, sizeof (src0_y)); |
| 1282 | char src1_y[64]; make_HLSL_srcarg_string_y(ctx, 1, src1_y, sizeof (src1_y)); |
| 1283 | char src0_z[64]; make_HLSL_srcarg_string_z(ctx, 0, src0_z, sizeof (src0_z)); |
| 1284 | char src1_w[64]; make_HLSL_srcarg_string_w(ctx, 1, src1_w, sizeof (src1_w)); |
| 1285 | |
| 1286 | char code[128]; |
| 1287 | make_HLSL_destarg_assign(ctx, code, sizeof (code), |
| 1288 | "float4(1.0, %s * %s, %s, %s)", |
| 1289 | src0_y, src1_y, src0_z, src1_w); |
| 1290 | output_line(ctx, "%s", code); |
| 1291 | } // emit_HLSL_DST |
| 1292 | |
| 1293 | void emit_HLSL_LRP(Context *ctx) |
| 1294 | { |
| 1295 | char src0[64]; make_HLSL_srcarg_string_masked(ctx, 0, src0, sizeof (src0)); |
| 1296 | char src1[64]; make_HLSL_srcarg_string_masked(ctx, 1, src1, sizeof (src1)); |
| 1297 | char src2[64]; make_HLSL_srcarg_string_masked(ctx, 2, src2, sizeof (src2)); |
| 1298 | char code[128]; |
| 1299 | make_HLSL_destarg_assign(ctx, code, sizeof (code), "lerp(%s, %s, %s)", |
| 1300 | src2, src1, src0); |
| 1301 | output_line(ctx, "%s", code); |
| 1302 | } // emit_HLSL_LRP |
| 1303 | |
| 1304 | void emit_HLSL_FRC(Context *ctx) |
| 1305 | { |
| 1306 | char src0[64]; make_HLSL_srcarg_string_masked(ctx, 0, src0, sizeof (src0)); |
| 1307 | char code[128]; |
| 1308 | make_HLSL_destarg_assign(ctx, code, sizeof (code), "frac(%s)", src0); |
| 1309 | output_line(ctx, "%s", code); |
| 1310 | } // emit_HLSL_FRC |
| 1311 | |
| 1312 | void emit_HLSL_M4X4(Context *ctx) |
| 1313 | { |
| 1314 | char src0[64]; make_HLSL_srcarg_string_full(ctx, 0, src0, sizeof (src0)); |
| 1315 | char row0[64]; make_HLSL_srcarg_string_full(ctx, 1, row0, sizeof (row0)); |
| 1316 | char row1[64]; make_HLSL_srcarg_string_full(ctx, 2, row1, sizeof (row1)); |
| 1317 | char row2[64]; make_HLSL_srcarg_string_full(ctx, 3, row2, sizeof (row2)); |
| 1318 | char row3[64]; make_HLSL_srcarg_string_full(ctx, 4, row3, sizeof (row3)); |
| 1319 | char code[256]; |
| 1320 | make_HLSL_destarg_assign(ctx, code, sizeof (code), |
| 1321 | "float4(dot(%s, %s), dot(%s, %s), dot(%s, %s), dot(%s, %s))", |
| 1322 | src0, row0, src0, row1, src0, row2, src0, row3); |
| 1323 | output_line(ctx, "%s", code); |
| 1324 | } // emit_HLSL_M4X4 |
| 1325 | |
| 1326 | void emit_HLSL_M4X3(Context *ctx) |
| 1327 | { |
| 1328 | char src0[64]; make_HLSL_srcarg_string_full(ctx, 0, src0, sizeof (src0)); |
| 1329 | char row0[64]; make_HLSL_srcarg_string_full(ctx, 1, row0, sizeof (row0)); |
| 1330 | char row1[64]; make_HLSL_srcarg_string_full(ctx, 2, row1, sizeof (row1)); |
| 1331 | char row2[64]; make_HLSL_srcarg_string_full(ctx, 3, row2, sizeof (row2)); |
| 1332 | char code[256]; |
| 1333 | make_HLSL_destarg_assign(ctx, code, sizeof (code), |
| 1334 | "float3(dot(%s, %s), dot(%s, %s), dot(%s, %s))", |
| 1335 | src0, row0, src0, row1, src0, row2); |
| 1336 | output_line(ctx, "%s", code); |
| 1337 | } // emit_HLSL_M4X3 |
| 1338 | |
| 1339 | void emit_HLSL_M3X4(Context *ctx) |
| 1340 | { |
| 1341 | char src0[64]; make_HLSL_srcarg_string_vec3(ctx, 0, src0, sizeof (src0)); |
| 1342 | char row0[64]; make_HLSL_srcarg_string_vec3(ctx, 1, row0, sizeof (row0)); |
| 1343 | char row1[64]; make_HLSL_srcarg_string_vec3(ctx, 2, row1, sizeof (row1)); |
| 1344 | char row2[64]; make_HLSL_srcarg_string_vec3(ctx, 3, row2, sizeof (row2)); |
| 1345 | char row3[64]; make_HLSL_srcarg_string_vec3(ctx, 4, row3, sizeof (row3)); |
| 1346 | |
| 1347 | char code[256]; |
| 1348 | make_HLSL_destarg_assign(ctx, code, sizeof (code), |
| 1349 | "float4(dot(%s, %s), dot(%s, %s), " |
| 1350 | "dot(%s, %s), dot(%s, %s))", |
| 1351 | src0, row0, src0, row1, |
| 1352 | src0, row2, src0, row3); |
| 1353 | output_line(ctx, "%s", code); |
| 1354 | } // emit_HLSL_M3X4 |
| 1355 | |
| 1356 | void emit_HLSL_M3X3(Context *ctx) |
| 1357 | { |
| 1358 | char src0[64]; make_HLSL_srcarg_string_vec3(ctx, 0, src0, sizeof (src0)); |
| 1359 | char row0[64]; make_HLSL_srcarg_string_vec3(ctx, 1, row0, sizeof (row0)); |
| 1360 | char row1[64]; make_HLSL_srcarg_string_vec3(ctx, 2, row1, sizeof (row1)); |
| 1361 | char row2[64]; make_HLSL_srcarg_string_vec3(ctx, 3, row2, sizeof (row2)); |
| 1362 | char code[256]; |
| 1363 | make_HLSL_destarg_assign(ctx, code, sizeof (code), |
| 1364 | "float3(dot(%s, %s), dot(%s, %s), dot(%s, %s))", |
| 1365 | src0, row0, src0, row1, src0, row2); |
| 1366 | output_line(ctx, "%s", code); |
| 1367 | } // emit_HLSL_M3X3 |
| 1368 | |
| 1369 | void emit_HLSL_M3X2(Context *ctx) |
| 1370 | { |
| 1371 | char src0[64]; make_HLSL_srcarg_string_vec3(ctx, 0, src0, sizeof (src0)); |
| 1372 | char row0[64]; make_HLSL_srcarg_string_vec3(ctx, 1, row0, sizeof (row0)); |
| 1373 | char row1[64]; make_HLSL_srcarg_string_vec3(ctx, 2, row1, sizeof (row1)); |
| 1374 | |
| 1375 | char code[256]; |
| 1376 | make_HLSL_destarg_assign(ctx, code, sizeof (code), |
| 1377 | "float2(dot(%s, %s), dot(%s, %s))", |
| 1378 | src0, row0, src0, row1); |
| 1379 | output_line(ctx, "%s", code); |
| 1380 | } // emit_HLSL_M3X2 |
| 1381 | |
| 1382 | void emit_HLSL_CALL(Context *ctx) |
| 1383 | { |
| 1384 | char src0[64]; make_HLSL_srcarg_string_masked(ctx, 0, src0, sizeof (src0)); |
| 1385 | if (ctx->loops > 0) |
| 1386 | output_line(ctx, "%s(aL);", src0); |
| 1387 | else |
| 1388 | output_line(ctx, "%s();", src0); |
| 1389 | } // emit_HLSL_CALL |
| 1390 | |
| 1391 | void emit_HLSL_CALLNZ(Context *ctx) |
| 1392 | { |
| 1393 | // !!! FIXME: if src1 is a constbool that's true, we can remove the |
| 1394 | // !!! FIXME: if. If it's false, we can make this a no-op. |
| 1395 | char src0[64]; make_HLSL_srcarg_string_masked(ctx, 0, src0, sizeof (src0)); |
| 1396 | char src1[64]; make_HLSL_srcarg_string_masked(ctx, 1, src1, sizeof (src1)); |
| 1397 | |
| 1398 | if (ctx->loops > 0) |
| 1399 | output_line(ctx, "if (%s) { %s(aL); }", src1, src0); |
| 1400 | else |
| 1401 | output_line(ctx, "if (%s) { %s(); }", src1, src0); |
| 1402 | } // emit_HLSL_CALLNZ |
| 1403 | |
| 1404 | void emit_HLSL_LOOP(Context *ctx) |
| 1405 | { |
| 1406 | // !!! FIXME: swizzle? |
| 1407 | char var[64]; get_HLSL_srcarg_varname(ctx, 1, var, sizeof (var)); |
| 1408 | assert(ctx->source_args[0].regnum == 0); // in case they add aL1 someday. |
| 1409 | output_line(ctx, "{"); |
| 1410 | ctx->indent++; |
| 1411 | output_line(ctx, "const int aLend = %s.x + %s.y;", var, var); |
| 1412 | output_line(ctx, "for (int aL = %s.y; aL < aLend; aL += %s.z) {", var, var); |
| 1413 | ctx->indent++; |
| 1414 | } // emit_HLSL_LOOP |
| 1415 | |
| 1416 | void emit_HLSL_RET(Context *ctx) |
| 1417 | { |
| 1418 | // thankfully, the MSDN specs say a RET _has_ to end a function...no |
| 1419 | // early returns. So if you hit one, you know you can safely close |
| 1420 | // a high-level function. |
| 1421 | push_output(ctx, &ctx->postflight); |
| 1422 | output_line(ctx, "}"); |
| 1423 | output_blank_line(ctx); |
| 1424 | set_output(ctx, &ctx->subroutines); // !!! FIXME: is this for LABEL? Maybe set it there so we don't allocate unnecessarily. |
| 1425 | } // emit_HLSL_RET |
| 1426 | |
| 1427 | void emit_HLSL_ENDLOOP(Context *ctx) |
| 1428 | { |
| 1429 | ctx->indent--; |
| 1430 | output_line(ctx, "}"); |
| 1431 | ctx->indent--; |
| 1432 | output_line(ctx, "}"); |
| 1433 | } // emit_HLSL_ENDLOOP |
| 1434 | |
| 1435 | void emit_HLSL_LABEL(Context *ctx) |
| 1436 | { |
| 1437 | char src0[64]; make_HLSL_srcarg_string_masked(ctx, 0, src0, sizeof (src0)); |
| 1438 | const int label = ctx->source_args[0].regnum; |
| 1439 | RegisterList *reg = reglist_find(&ctx->used_registers, REG_TYPE_LABEL, label); |
| 1440 | assert(ctx->output == ctx->subroutines); // not mainline, etc. |
| 1441 | assert(ctx->indent == 0); // we shouldn't be in the middle of a function. |
| 1442 | |
| 1443 | // MSDN specs say CALL* has to come before the LABEL, so we know if we |
| 1444 | // can ditch the entire function here as unused. |
| 1445 | if (reg == NULL) |
| 1446 | set_output(ctx, &ctx->ignore); // Func not used. Parse, but don't output. |
| 1447 | |
| 1448 | // !!! FIXME: it would be nice if we could determine if a function is |
| 1449 | // !!! FIXME: only called once and, if so, forcibly inline it. |
| 1450 | |
| 1451 | const char *uses_loopreg = ((reg) && (reg->misc == 1)) ? "int aL" : ""; |
| 1452 | output_line(ctx, "void %s(%s)", src0, uses_loopreg); |
| 1453 | output_line(ctx, "{"); |
| 1454 | ctx->indent++; |
| 1455 | } // emit_HLSL_LABEL |
| 1456 | |
| 1457 | void emit_HLSL_DCL(Context *ctx) |
| 1458 | { |
| 1459 | // no-op. We do this in our emit_attribute() and emit_uniform(). |
| 1460 | } // emit_HLSL_DCL |
| 1461 | |
| 1462 | void emit_HLSL_POW(Context *ctx) |
| 1463 | { |
| 1464 | char src0[64]; make_HLSL_srcarg_string_masked(ctx, 0, src0, sizeof (src0)); |
| 1465 | char src1[64]; make_HLSL_srcarg_string_masked(ctx, 1, src1, sizeof (src1)); |
| 1466 | char code[128]; |
| 1467 | make_HLSL_destarg_assign(ctx, code, sizeof (code), |
| 1468 | "pow(abs(%s), %s)", src0, src1); |
| 1469 | output_line(ctx, "%s", code); |
| 1470 | } // emit_HLSL_POW |
| 1471 | |
| 1472 | void emit_HLSL_CRS(Context *ctx) |
| 1473 | { |
| 1474 | // !!! FIXME: needs to take ctx->dst_arg.writemask into account. |
| 1475 | char src0[64]; make_HLSL_srcarg_string_vec3(ctx, 0, src0, sizeof (src0)); |
| 1476 | char src1[64]; make_HLSL_srcarg_string_vec3(ctx, 1, src1, sizeof (src1)); |
| 1477 | char code[128]; |
| 1478 | make_HLSL_destarg_assign(ctx, code, sizeof (code), |
| 1479 | "cross(%s, %s)", src0, src1); |
| 1480 | output_line(ctx, "%s", code); |
| 1481 | } // emit_HLSL_CRS |
| 1482 | |
| 1483 | void emit_HLSL_SGN(Context *ctx) |
| 1484 | { |
| 1485 | // (we don't need the temporary registers specified for the D3D opcode.) |
| 1486 | char src0[64]; make_HLSL_srcarg_string_masked(ctx, 0, src0, sizeof (src0)); |
| 1487 | char code[128]; |
| 1488 | make_HLSL_destarg_assign(ctx, code, sizeof (code), "sign(%s)", src0); |
| 1489 | output_line(ctx, "%s", code); |
| 1490 | } // emit_HLSL_SGN |
| 1491 | |
| 1492 | void emit_HLSL_ABS(Context *ctx) |
| 1493 | { |
| 1494 | char src0[64]; make_HLSL_srcarg_string_masked(ctx, 0, src0, sizeof (src0)); |
| 1495 | char code[128]; |
| 1496 | make_HLSL_destarg_assign(ctx, code, sizeof (code), "abs(%s)", src0); |
| 1497 | output_line(ctx, "%s", code); |
| 1498 | } // emit_HLSL_ABS |
| 1499 | |
| 1500 | void emit_HLSL_NRM(Context *ctx) |
| 1501 | { |
| 1502 | char src0[64]; make_HLSL_srcarg_string_masked(ctx, 0, src0, sizeof (src0)); |
| 1503 | char code[128]; |
| 1504 | make_HLSL_destarg_assign(ctx, code, sizeof (code), "normalize(%s)", src0); |
| 1505 | output_line(ctx, "%s", code); |
| 1506 | } // emit_HLSL_NRM |
| 1507 | |
| 1508 | void emit_HLSL_SINCOS(Context *ctx) |
| 1509 | { |
| 1510 | // we don't care about the temp registers that <= sm2 demands; ignore them. |
| 1511 | // sm2 also talks about what components are left untouched vs. undefined, |
| 1512 | // but we just leave those all untouched with HLSL write masks (which |
| 1513 | // would fulfill the "undefined" requirement, too). |
| 1514 | const int mask = ctx->dest_arg.writemask; |
| 1515 | char src0[64]; make_HLSL_srcarg_string_scalar(ctx, 0, src0, sizeof (src0)); |
| 1516 | char code[128] = { '\0' }; |
| 1517 | |
| 1518 | if (writemask_x(mask)) |
| 1519 | make_HLSL_destarg_assign(ctx, code, sizeof (code), "cos(%s)", src0); |
| 1520 | else if (writemask_y(mask)) |
| 1521 | make_HLSL_destarg_assign(ctx, code, sizeof (code), "sin(%s)", src0); |
| 1522 | else if (writemask_xy(mask)) |
| 1523 | { |
| 1524 | make_HLSL_destarg_assign(ctx, code, sizeof (code), |
| 1525 | "float2(cos(%s), sin(%s))", src0, src0); |
| 1526 | } // else if |
| 1527 | |
| 1528 | output_line(ctx, "%s", code); |
| 1529 | } // emit_HLSL_SINCOS |
| 1530 | |
| 1531 | void emit_HLSL_REP(Context *ctx) |
| 1532 | { |
| 1533 | // !!! FIXME: |
| 1534 | // msdn docs say legal loop values are 0 to 255. We can check DEFI values |
| 1535 | // at parse time, but if they are pulling a value from a uniform, do |
| 1536 | // we clamp here? |
| 1537 | // !!! FIXME: swizzle is legal here, right? |
| 1538 | char src0[64]; make_HLSL_srcarg_string_x(ctx, 0, src0, sizeof (src0)); |
| 1539 | const uint rep = (uint) ctx->reps; |
| 1540 | output_line(ctx, "for (int rep%u = 0; rep%u < %s; rep%u++) {", |
| 1541 | rep, rep, src0, rep); |
| 1542 | ctx->indent++; |
| 1543 | } // emit_HLSL_REP |
| 1544 | |
| 1545 | void emit_HLSL_ENDREP(Context *ctx) |
| 1546 | { |
| 1547 | ctx->indent--; |
| 1548 | output_line(ctx, "}"); |
| 1549 | } // emit_HLSL_ENDREP |
| 1550 | |
| 1551 | void emit_HLSL_IF(Context *ctx) |
| 1552 | { |
| 1553 | char src0[64]; make_HLSL_srcarg_string_scalar(ctx, 0, src0, sizeof (src0)); |
| 1554 | output_line(ctx, "if (%s) {", src0); |
| 1555 | ctx->indent++; |
| 1556 | } // emit_HLSL_IF |
| 1557 | |
| 1558 | void emit_HLSL_IFC(Context *ctx) |
| 1559 | { |
| 1560 | const char *comp = get_HLSL_comparison_string_scalar(ctx); |
| 1561 | char src0[64]; make_HLSL_srcarg_string_scalar(ctx, 0, src0, sizeof (src0)); |
| 1562 | char src1[64]; make_HLSL_srcarg_string_scalar(ctx, 1, src1, sizeof (src1)); |
| 1563 | output_line(ctx, "if (%s %s %s) {", src0, comp, src1); |
| 1564 | ctx->indent++; |
| 1565 | } // emit_HLSL_IFC |
| 1566 | |
| 1567 | void emit_HLSL_ELSE(Context *ctx) |
| 1568 | { |
| 1569 | ctx->indent--; |
| 1570 | output_line(ctx, "} else {"); |
| 1571 | ctx->indent++; |
| 1572 | } // emit_HLSL_ELSE |
| 1573 | |
| 1574 | void emit_HLSL_ENDIF(Context *ctx) |
| 1575 | { |
| 1576 | ctx->indent--; |
| 1577 | output_line(ctx, "}"); |
| 1578 | } // emit_HLSL_ENDIF |
| 1579 | |
| 1580 | void emit_HLSL_BREAK(Context *ctx) |
| 1581 | { |
| 1582 | output_line(ctx, "break;"); |
| 1583 | } // emit_HLSL_BREAK |
| 1584 | |
| 1585 | void emit_HLSL_BREAKC(Context *ctx) |
| 1586 | { |
| 1587 | const char *comp = get_HLSL_comparison_string_scalar(ctx); |
| 1588 | char src0[64]; make_HLSL_srcarg_string_scalar(ctx, 0, src0, sizeof (src0)); |
| 1589 | char src1[64]; make_HLSL_srcarg_string_scalar(ctx, 1, src1, sizeof (src1)); |
| 1590 | output_line(ctx, "if (%s %s %s) { break; }", src0, comp, src1); |
| 1591 | } // emit_HLSL_BREAKC |
| 1592 | |
| 1593 | void emit_HLSL_MOVA(Context *ctx) |
| 1594 | { |
| 1595 | const int vecsize = vecsize_from_writemask(ctx->dest_arg.writemask); |
| 1596 | char src0[64]; make_HLSL_srcarg_string_masked(ctx, 0, src0, sizeof (src0)); |
| 1597 | char code[128]; |
| 1598 | |
| 1599 | if (vecsize == 1) |
| 1600 | { |
| 1601 | make_HLSL_destarg_assign(ctx, code, sizeof (code), |
| 1602 | "int(floor(abs(%s) + 0.5) * sign(%s))", |
| 1603 | src0, src0); |
| 1604 | } // if |
| 1605 | |
| 1606 | else |
| 1607 | { |
| 1608 | make_HLSL_destarg_assign(ctx, code, sizeof (code), |
| 1609 | "int%d(floor(abs(%s) + 0.5) * sign(%s))", |
| 1610 | vecsize, src0, src0); |
| 1611 | } // else |
| 1612 | |
| 1613 | output_line(ctx, "%s", code); |
| 1614 | } // emit_HLSL_MOVA |
| 1615 | |
| 1616 | void emit_HLSL_DEFB(Context *ctx) |
| 1617 | { |
| 1618 | char varname[64]; get_HLSL_destarg_varname(ctx, varname, sizeof (varname)); |
| 1619 | push_output(ctx, &ctx->mainline_top); |
| 1620 | ctx->indent++; |
| 1621 | output_line(ctx, "const bool %s = %s;", |
| 1622 | varname, ctx->dwords[0] ? "true" : "false"); |
| 1623 | ctx->indent--; |
| 1624 | pop_output(ctx); |
| 1625 | } // emit_HLSL_DEFB |
| 1626 | |
| 1627 | void emit_HLSL_DEFI(Context *ctx) |
| 1628 | { |
| 1629 | char varname[64]; get_HLSL_destarg_varname(ctx, varname, sizeof (varname)); |
| 1630 | const int32 *x = (const int32 *) ctx->dwords; |
| 1631 | push_output(ctx, &ctx->mainline_top); |
| 1632 | ctx->indent++; |
| 1633 | output_line(ctx, "const int4 %s = int4(%d, %d, %d, %d);", |
| 1634 | varname, (int) x[0], (int) x[1], (int) x[2], (int) x[3]); |
| 1635 | ctx->indent--; |
| 1636 | pop_output(ctx); |
| 1637 | } // emit_HLSL_DEFI |
| 1638 | |
| 1639 | EMIT_HLSL_OPCODE_UNIMPLEMENTED_FUNC(TEXCRD) |
| 1640 | |
| 1641 | void emit_HLSL_TEXKILL(Context *ctx) |
| 1642 | { |
| 1643 | char dst[64]; get_HLSL_destarg_varname(ctx, dst, sizeof (dst)); |
| 1644 | output_line(ctx, "if (any(%s.xyz < 0.0)) discard;", dst); |
| 1645 | } // emit_HLSL_TEXKILL |
| 1646 | |
| 1647 | void emit_HLSL_TEXLD(Context *ctx) |
| 1648 | { |
| 1649 | if (!shader_version_atleast(ctx, 1, 4)) |
| 1650 | { |
| 1651 | DestArgInfo *info = &ctx->dest_arg; |
| 1652 | char dst[64]; |
| 1653 | char sampler[64]; |
| 1654 | char code[128] = {0}; |
| 1655 | |
| 1656 | RegisterList *sreg; |
| 1657 | sreg = reglist_find(&ctx->samplers, REG_TYPE_SAMPLER, info->regnum); |
| 1658 | const TextureType ttype = (TextureType) (sreg ? sreg->index : 0); |
| 1659 | |
| 1660 | // !!! FIXME: this code counts on the register not having swizzles, etc. |
| 1661 | get_HLSL_destarg_varname(ctx, dst, sizeof (dst)); |
| 1662 | get_HLSL_varname_in_buf(ctx, REG_TYPE_SAMPLER, info->regnum, |
| 1663 | sampler, sizeof (sampler)); |
| 1664 | |
| 1665 | if (ttype == TEXTURE_TYPE_2D) |
| 1666 | { |
| 1667 | make_HLSL_destarg_assign(ctx, code, sizeof (code), |
| 1668 | "%s_texture.Sample(%s, %s.xy)", |
| 1669 | sampler, sampler, dst); |
| 1670 | } // if |
| 1671 | else if (ttype == TEXTURE_TYPE_CUBE || ttype == TEXTURE_TYPE_VOLUME) |
| 1672 | { |
| 1673 | make_HLSL_destarg_assign(ctx, code, sizeof (code), |
| 1674 | "%s_texture.Sample(%s, %s.xyz)", |
| 1675 | sampler, sampler, dst); |
| 1676 | } // else if |
| 1677 | else |
| 1678 | { |
| 1679 | fail(ctx, "unexpected texture type"); |
| 1680 | } // else |
| 1681 | output_line(ctx, "%s", code); |
| 1682 | } // if |
| 1683 | |
| 1684 | else if (!shader_version_atleast(ctx, 2, 0)) |
| 1685 | { |
| 1686 | // ps_1_4 is different, too! |
| 1687 | fail(ctx, "TEXLD == Shader Model 1.4 unimplemented."); // !!! FIXME |
| 1688 | return; |
| 1689 | } // else if |
| 1690 | |
| 1691 | else |
| 1692 | { |
| 1693 | const SourceArgInfo *samp_arg = &ctx->source_args[1]; |
| 1694 | RegisterList *sreg = reglist_find(&ctx->samplers, REG_TYPE_SAMPLER, |
| 1695 | samp_arg->regnum); |
| 1696 | const char *funcname = NULL; |
| 1697 | char src0[64] = { '\0' }; |
| 1698 | char src1[64]; get_HLSL_srcarg_varname(ctx, 1, src1, sizeof (src1)); // !!! FIXME: SRC_MOD? |
| 1699 | |
| 1700 | if (sreg == NULL) |
| 1701 | { |
| 1702 | fail(ctx, "TEXLD using undeclared sampler"); |
| 1703 | return; |
| 1704 | } // if |
| 1705 | |
| 1706 | // !!! FIXME: does the d3d bias value map directly to HLSL? |
| 1707 | const char *biassep = ""; |
| 1708 | char bias[64] = { '\0' }; |
| 1709 | if (ctx->instruction_controls == CONTROL_TEXLDB) |
| 1710 | { |
| 1711 | biassep = ", "; |
| 1712 | make_HLSL_srcarg_string_w(ctx, 0, bias, sizeof (bias)); |
| 1713 | funcname = "SampleBias"; |
| 1714 | } // if |
| 1715 | else |
| 1716 | { |
| 1717 | funcname = "Sample"; |
| 1718 | } // else |
| 1719 | |
| 1720 | switch ((const TextureType) sreg->index) |
| 1721 | { |
| 1722 | case TEXTURE_TYPE_2D: |
| 1723 | make_HLSL_srcarg_string_vec2(ctx, 0, src0, sizeof (src0)); |
| 1724 | break; |
| 1725 | case TEXTURE_TYPE_CUBE: |
| 1726 | if (ctx->instruction_controls == CONTROL_TEXLDP) |
| 1727 | fail(ctx, "TEXLDP on a cubemap"); // !!! FIXME: is this legal? |
| 1728 | make_HLSL_srcarg_string_vec3(ctx, 0, src0, sizeof (src0)); |
| 1729 | break; |
| 1730 | case TEXTURE_TYPE_VOLUME: |
| 1731 | make_HLSL_srcarg_string_vec3(ctx, 0, src0, sizeof (src0)); |
| 1732 | break; |
| 1733 | default: |
| 1734 | fail(ctx, "unknown texture type"); |
| 1735 | return; |
| 1736 | } // switch |
| 1737 | |
| 1738 | assert(!isscalar(ctx, ctx->shader_type, samp_arg->regtype, samp_arg->regnum)); |
| 1739 | char swiz_str[6] = { '\0' }; |
| 1740 | make_HLSL_swizzle_string(swiz_str, sizeof (swiz_str), |
| 1741 | samp_arg->swizzle, ctx->dest_arg.writemask); |
| 1742 | |
| 1743 | char code[128]; |
| 1744 | make_HLSL_destarg_assign(ctx, code, sizeof (code), |
| 1745 | "%s_texture.%s(%s, %s%s%s)%s", src1, funcname, |
| 1746 | src1, src0, biassep, bias, swiz_str); |
| 1747 | |
| 1748 | output_line(ctx, "%s", code); |
| 1749 | } // else |
| 1750 | } // emit_HLSL_TEXLD |
| 1751 | |
| 1752 | void emit_HLSL_TEXBEM(Context *ctx) |
| 1753 | { |
| 1754 | // !!! FIXME: this code counts on the register not having swizzles, etc. |
| 1755 | DestArgInfo *info = &ctx->dest_arg; |
| 1756 | char dst[64]; get_HLSL_destarg_varname(ctx, dst, sizeof (dst)); |
| 1757 | char src[64]; get_HLSL_srcarg_varname(ctx, 0, src, sizeof (src)); |
| 1758 | char sampler[64]; |
| 1759 | char code[512]; |
| 1760 | |
| 1761 | get_HLSL_varname_in_buf(ctx, REG_TYPE_SAMPLER, info->regnum, |
| 1762 | sampler, sizeof (sampler)); |
| 1763 | |
| 1764 | make_HLSL_destarg_assign(ctx, code, sizeof (code), |
| 1765 | "%s_texture.Sample(%s, float2(%s.x + (%s_texbem.x * %s.x) + (%s_texbem.z * %s.y)," |
| 1766 | " %s.y + (%s_texbem.y * %s.x) + (%s_texbem.w * %s.y)))", |
| 1767 | sampler, sampler, |
| 1768 | dst, sampler, src, sampler, src, |
| 1769 | dst, sampler, src, sampler, src); |
| 1770 | |
| 1771 | output_line(ctx, "%s", code); |
| 1772 | } // emit_HLSL_TEXBEM |
| 1773 | |
| 1774 | void emit_HLSL_TEXBEML(Context *ctx) |
| 1775 | { |
| 1776 | // !!! FIXME: this code counts on the register not having swizzles, etc. |
| 1777 | DestArgInfo *info = &ctx->dest_arg; |
| 1778 | char dst[64]; get_HLSL_destarg_varname(ctx, dst, sizeof (dst)); |
| 1779 | char src[64]; get_HLSL_srcarg_varname(ctx, 0, src, sizeof (src)); |
| 1780 | char sampler[64]; |
| 1781 | char code[512]; |
| 1782 | |
| 1783 | get_HLSL_varname_in_buf(ctx, REG_TYPE_SAMPLER, info->regnum, |
| 1784 | sampler, sizeof (sampler)); |
| 1785 | |
| 1786 | make_HLSL_destarg_assign(ctx, code, sizeof (code), |
| 1787 | "(%s_texture.Sample(%s, float2(%s.x + (%s_texbem.x * %s.x) + (%s_texbem.z * %s.y)," |
| 1788 | " %s.y + (%s_texbem.y * %s.x) + (%s_texbem.w * %s.y)))) *" |
| 1789 | " ((%s.z * %s_texbeml.x) + %s_texbem.y)", |
| 1790 | sampler, sampler, |
| 1791 | dst, sampler, src, sampler, src, |
| 1792 | dst, sampler, src, sampler, src, |
| 1793 | src, sampler, sampler); |
| 1794 | |
| 1795 | output_line(ctx, "%s", code); |
| 1796 | } // emit_HLSL_TEXBEML |
| 1797 | |
| 1798 | EMIT_HLSL_OPCODE_UNIMPLEMENTED_FUNC(TEXREG2AR) // !!! FIXME |
| 1799 | EMIT_HLSL_OPCODE_UNIMPLEMENTED_FUNC(TEXREG2GB) // !!! FIXME |
| 1800 | |
| 1801 | void emit_HLSL_TEXM3X2PAD(Context *ctx) |
| 1802 | { |
| 1803 | // no-op ... work happens in emit_HLSL_TEXM3X2TEX(). |
| 1804 | } // emit_HLSL_TEXM3X2PAD |
| 1805 | |
| 1806 | void emit_HLSL_TEXM3X2TEX(Context *ctx) |
| 1807 | { |
| 1808 | if (ctx->texm3x2pad_src0 == -1) |
| 1809 | return; |
| 1810 | |
| 1811 | DestArgInfo *info = &ctx->dest_arg; |
| 1812 | char dst[64]; |
| 1813 | char src0[64]; |
| 1814 | char src1[64]; |
| 1815 | char src2[64]; |
| 1816 | char sampler[64]; |
| 1817 | char code[512]; |
| 1818 | |
| 1819 | // !!! FIXME: this code counts on the register not having swizzles, etc. |
| 1820 | get_HLSL_varname_in_buf(ctx, REG_TYPE_SAMPLER, info->regnum, |
| 1821 | sampler, sizeof (sampler)); |
| 1822 | get_HLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x2pad_src0, |
| 1823 | src0, sizeof (src0)); |
| 1824 | get_HLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x2pad_dst0, |
| 1825 | src1, sizeof (src1)); |
| 1826 | get_HLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->source_args[0].regnum, |
| 1827 | src2, sizeof (src2)); |
| 1828 | get_HLSL_destarg_varname(ctx, dst, sizeof (dst)); |
| 1829 | |
| 1830 | make_HLSL_destarg_assign(ctx, code, sizeof (code), |
| 1831 | "%s_texture.Sample(%s, float2(dot(%s.xyz, %s.xyz), dot(%s.xyz, %s.xyz)))", |
| 1832 | sampler, sampler, src0, src1, src2, dst); |
| 1833 | |
| 1834 | output_line(ctx, "%s", code); |
| 1835 | } // emit_HLSL_TEXM3X2TEX |
| 1836 | |
| 1837 | void emit_HLSL_TEXM3X3PAD(Context *ctx) |
| 1838 | { |
| 1839 | // no-op ... work happens in emit_HLSL_TEXM3X3*(). |
| 1840 | } // emit_HLSL_TEXM3X3PAD |
| 1841 | |
| 1842 | void emit_HLSL_TEXM3X3TEX(Context *ctx) |
| 1843 | { |
| 1844 | if (ctx->texm3x3pad_src1 == -1) |
| 1845 | return; |
| 1846 | |
| 1847 | DestArgInfo *info = &ctx->dest_arg; |
| 1848 | char dst[64]; |
| 1849 | char src0[64]; |
| 1850 | char src1[64]; |
| 1851 | char src2[64]; |
| 1852 | char src3[64]; |
| 1853 | char src4[64]; |
| 1854 | char sampler[64]; |
| 1855 | char code[512]; |
| 1856 | |
| 1857 | // !!! FIXME: this code counts on the register not having swizzles, etc. |
| 1858 | get_HLSL_varname_in_buf(ctx, REG_TYPE_SAMPLER, info->regnum, |
| 1859 | sampler, sizeof (sampler)); |
| 1860 | |
| 1861 | get_HLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x3pad_dst0, |
| 1862 | src0, sizeof (src0)); |
| 1863 | get_HLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x3pad_src0, |
| 1864 | src1, sizeof (src1)); |
| 1865 | get_HLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x3pad_dst1, |
| 1866 | src2, sizeof (src2)); |
| 1867 | get_HLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x3pad_src1, |
| 1868 | src3, sizeof (src3)); |
| 1869 | get_HLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->source_args[0].regnum, |
| 1870 | src4, sizeof (src4)); |
| 1871 | get_HLSL_destarg_varname(ctx, dst, sizeof (dst)); |
| 1872 | |
| 1873 | make_HLSL_destarg_assign(ctx, code, sizeof (code), |
| 1874 | "%s_texture.Sample(%s," |
| 1875 | " float3(dot(%s.xyz, %s.xyz)," |
| 1876 | " dot(%s.xyz, %s.xyz)," |
| 1877 | " dot(%s.xyz, %s.xyz)))", |
| 1878 | sampler, sampler, src0, src1, src2, src3, dst, src4); |
| 1879 | |
| 1880 | output_line(ctx, "%s", code); |
| 1881 | } // emit_HLSL_TEXM3X3TEX |
| 1882 | |
| 1883 | void emit_HLSL_TEXM3X3SPEC_helper(Context *ctx) |
| 1884 | { |
| 1885 | if (ctx->glsl_generated_texm3x3spec_helper) |
| 1886 | return; |
| 1887 | |
| 1888 | ctx->glsl_generated_texm3x3spec_helper = 1; |
| 1889 | |
| 1890 | push_output(ctx, &ctx->helpers); |
| 1891 | output_line(ctx, "float3 TEXM3X3SPEC_reflection(const float3 normal, const float3 eyeray)"); |
| 1892 | output_line(ctx, "{"); ctx->indent++; |
| 1893 | output_line(ctx, "return (2.0 * ((normal * eyeray) / (normal * normal)) * normal) - eyeray;"); ctx->indent--; |
| 1894 | output_line(ctx, "}"); |
| 1895 | output_blank_line(ctx); |
| 1896 | pop_output(ctx); |
| 1897 | } // emit_HLSL_TEXM3X3SPEC_helper |
| 1898 | |
| 1899 | void emit_HLSL_TEXM3X3SPEC(Context *ctx) |
| 1900 | { |
| 1901 | if (ctx->texm3x3pad_src1 == -1) |
| 1902 | return; |
| 1903 | |
| 1904 | DestArgInfo *info = &ctx->dest_arg; |
| 1905 | char dst[64]; |
| 1906 | char src0[64]; |
| 1907 | char src1[64]; |
| 1908 | char src2[64]; |
| 1909 | char src3[64]; |
| 1910 | char src4[64]; |
| 1911 | char src5[64]; |
| 1912 | char sampler[64]; |
| 1913 | char code[512]; |
| 1914 | |
| 1915 | emit_HLSL_TEXM3X3SPEC_helper(ctx); |
| 1916 | |
| 1917 | // !!! FIXME: this code counts on the register not having swizzles, etc. |
| 1918 | get_HLSL_varname_in_buf(ctx, REG_TYPE_SAMPLER, info->regnum, |
| 1919 | sampler, sizeof (sampler)); |
| 1920 | |
| 1921 | get_HLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x3pad_dst0, |
| 1922 | src0, sizeof (src0)); |
| 1923 | get_HLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x3pad_src0, |
| 1924 | src1, sizeof (src1)); |
| 1925 | get_HLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x3pad_dst1, |
| 1926 | src2, sizeof (src2)); |
| 1927 | get_HLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x3pad_src1, |
| 1928 | src3, sizeof (src3)); |
| 1929 | get_HLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->source_args[0].regnum, |
| 1930 | src4, sizeof (src4)); |
| 1931 | get_HLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->source_args[1].regnum, |
| 1932 | src5, sizeof (src5)); |
| 1933 | get_HLSL_destarg_varname(ctx, dst, sizeof (dst)); |
| 1934 | |
| 1935 | make_HLSL_destarg_assign(ctx, code, sizeof (code), |
| 1936 | "%s_texture.Sample(%s, " |
| 1937 | "TEXM3X3SPEC_reflection(" |
| 1938 | "float3(" |
| 1939 | "dot(%s.xyz, %s.xyz), " |
| 1940 | "dot(%s.xyz, %s.xyz), " |
| 1941 | "dot(%s.xyz, %s.xyz)" |
| 1942 | ")," |
| 1943 | "%s.xyz," |
| 1944 | ")" |
| 1945 | ")", |
| 1946 | sampler, sampler, src0, src1, src2, src3, dst, src4, src5); |
| 1947 | |
| 1948 | output_line(ctx, "%s", code); |
| 1949 | } // emit_HLSL_TEXM3X3SPEC |
| 1950 | |
| 1951 | void emit_HLSL_TEXM3X3VSPEC(Context *ctx) |
| 1952 | { |
| 1953 | if (ctx->texm3x3pad_src1 == -1) |
| 1954 | return; |
| 1955 | |
| 1956 | DestArgInfo *info = &ctx->dest_arg; |
| 1957 | char dst[64]; |
| 1958 | char src0[64]; |
| 1959 | char src1[64]; |
| 1960 | char src2[64]; |
| 1961 | char src3[64]; |
| 1962 | char src4[64]; |
| 1963 | char sampler[64]; |
| 1964 | char code[512]; |
| 1965 | |
| 1966 | emit_HLSL_TEXM3X3SPEC_helper(ctx); |
| 1967 | |
| 1968 | // !!! FIXME: this code counts on the register not having swizzles, etc. |
| 1969 | get_HLSL_varname_in_buf(ctx, REG_TYPE_SAMPLER, info->regnum, |
| 1970 | sampler, sizeof (sampler)); |
| 1971 | |
| 1972 | get_HLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x3pad_dst0, |
| 1973 | src0, sizeof (src0)); |
| 1974 | get_HLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x3pad_src0, |
| 1975 | src1, sizeof (src1)); |
| 1976 | get_HLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x3pad_dst1, |
| 1977 | src2, sizeof (src2)); |
| 1978 | get_HLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x3pad_src1, |
| 1979 | src3, sizeof (src3)); |
| 1980 | get_HLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->source_args[0].regnum, |
| 1981 | src4, sizeof (src4)); |
| 1982 | get_HLSL_destarg_varname(ctx, dst, sizeof (dst)); |
| 1983 | |
| 1984 | make_HLSL_destarg_assign(ctx, code, sizeof (code), |
| 1985 | "%s_texture.Sample(%s, " |
| 1986 | "TEXM3X3SPEC_reflection(" |
| 1987 | "float3(" |
| 1988 | "dot(%s.xyz, %s.xyz), " |
| 1989 | "dot(%s.xyz, %s.xyz), " |
| 1990 | "dot(%s.xyz, %s.xyz)" |
| 1991 | "), " |
| 1992 | "float3(%s.w, %s.w, %s.w)" |
| 1993 | ")" |
| 1994 | ")", |
| 1995 | sampler, sampler, src0, src1, src2, src3, dst, src4, src0, src2, dst); |
| 1996 | |
| 1997 | output_line(ctx, "%s", code); |
| 1998 | } // emit_HLSL_TEXM3X3VSPEC |
| 1999 | |
| 2000 | void emit_HLSL_EXPP(Context *ctx) |
| 2001 | { |
| 2002 | // !!! FIXME: msdn's asm docs don't list this opcode, I'll have to check the driver documentation. |
| 2003 | emit_HLSL_EXP(ctx); // I guess this is just partial precision EXP? |
| 2004 | } // emit_HLSL_EXPP |
| 2005 | |
| 2006 | void emit_HLSL_LOGP(Context *ctx) |
| 2007 | { |
| 2008 | // LOGP is just low-precision LOG, but we'll take the higher precision. |
| 2009 | emit_HLSL_LOG(ctx); |
| 2010 | } // emit_HLSL_LOGP |
| 2011 | |
| 2012 | // common code between CMP and CND. |
| 2013 | void emit_HLSL_comparison_operations(Context *ctx, const char *cmp) |
| 2014 | { |
| 2015 | int i, j; |
| 2016 | DestArgInfo *dst = &ctx->dest_arg; |
| 2017 | const SourceArgInfo *srcarg0 = &ctx->source_args[0]; |
| 2018 | const int origmask = dst->writemask; |
| 2019 | int used_swiz[4] = { 0, 0, 0, 0 }; |
| 2020 | const int writemask[4] = { dst->writemask0, dst->writemask1, |
| 2021 | dst->writemask2, dst->writemask3 }; |
| 2022 | const int src0swiz[4] = { srcarg0->swizzle_x, srcarg0->swizzle_y, |
| 2023 | srcarg0->swizzle_z, srcarg0->swizzle_w }; |
| 2024 | |
| 2025 | for (i = 0; i < 4; i++) |
| 2026 | { |
| 2027 | int mask = (1 << i); |
| 2028 | |
| 2029 | if (!writemask[i]) continue; |
| 2030 | if (used_swiz[i]) continue; |
| 2031 | |
| 2032 | // This is a swizzle we haven't checked yet. |
| 2033 | used_swiz[i] = 1; |
| 2034 | |
| 2035 | // see if there are any other elements swizzled to match (.yyyy) |
| 2036 | for (j = i + 1; j < 4; j++) |
| 2037 | { |
| 2038 | if (!writemask[j]) continue; |
| 2039 | if (src0swiz[i] != src0swiz[j]) continue; |
| 2040 | mask |= (1 << j); |
| 2041 | used_swiz[j] = 1; |
| 2042 | } // for |
| 2043 | |
| 2044 | // okay, (mask) should be the writemask of swizzles we like. |
| 2045 | |
| 2046 | char src0[64]; |
| 2047 | char src1[64]; |
| 2048 | char src2[64]; |
| 2049 | make_HLSL_srcarg_string(ctx, 0, (1 << i), src0, sizeof (src0)); |
| 2050 | make_HLSL_srcarg_string(ctx, 1, mask, src1, sizeof (src1)); |
| 2051 | make_HLSL_srcarg_string(ctx, 2, mask, src2, sizeof (src2)); |
| 2052 | |
| 2053 | set_dstarg_writemask(dst, mask); |
| 2054 | |
| 2055 | char code[128]; |
| 2056 | make_HLSL_destarg_assign(ctx, code, sizeof (code), |
| 2057 | "((%s %s) ? %s : %s)", |
| 2058 | src0, cmp, src1, src2); |
| 2059 | output_line(ctx, "%s", code); |
| 2060 | } // for |
| 2061 | |
| 2062 | set_dstarg_writemask(dst, origmask); |
| 2063 | } // emit_HLSL_comparison_operations |
| 2064 | |
| 2065 | void emit_HLSL_CND(Context *ctx) |
| 2066 | { |
| 2067 | emit_HLSL_comparison_operations(ctx, "> 0.5"); |
| 2068 | } // emit_HLSL_CND |
| 2069 | |
| 2070 | void emit_HLSL_DEF(Context *ctx) |
| 2071 | { |
| 2072 | const float *val = (const float *) ctx->dwords; // !!! FIXME: could be int? |
| 2073 | char varname[64]; get_HLSL_destarg_varname(ctx, varname, sizeof (varname)); |
| 2074 | char val0[32]; floatstr(ctx, val0, sizeof (val0), val[0], 1); |
| 2075 | char val1[32]; floatstr(ctx, val1, sizeof (val1), val[1], 1); |
| 2076 | char val2[32]; floatstr(ctx, val2, sizeof (val2), val[2], 1); |
| 2077 | char val3[32]; floatstr(ctx, val3, sizeof (val3), val[3], 1); |
| 2078 | |
| 2079 | push_output(ctx, &ctx->mainline_top); |
| 2080 | ctx->indent++; |
| 2081 | output_line(ctx, "const float4 %s = float4(%s, %s, %s, %s);", |
| 2082 | varname, val0, val1, val2, val3); |
| 2083 | ctx->indent--; |
| 2084 | pop_output(ctx); |
| 2085 | } // emit_HLSL_DEF |
| 2086 | |
| 2087 | EMIT_HLSL_OPCODE_UNIMPLEMENTED_FUNC(TEXREG2RGB) // !!! FIXME |
| 2088 | EMIT_HLSL_OPCODE_UNIMPLEMENTED_FUNC(TEXDP3TEX) // !!! FIXME |
| 2089 | EMIT_HLSL_OPCODE_UNIMPLEMENTED_FUNC(TEXM3X2DEPTH) // !!! FIXME |
| 2090 | EMIT_HLSL_OPCODE_UNIMPLEMENTED_FUNC(TEXDP3) // !!! FIXME |
| 2091 | |
| 2092 | void emit_HLSL_TEXM3X3(Context *ctx) |
| 2093 | { |
| 2094 | if (ctx->texm3x3pad_src1 == -1) |
| 2095 | return; |
| 2096 | |
| 2097 | char dst[64]; |
| 2098 | char src0[64]; |
| 2099 | char src1[64]; |
| 2100 | char src2[64]; |
| 2101 | char src3[64]; |
| 2102 | char src4[64]; |
| 2103 | char code[512]; |
| 2104 | |
| 2105 | // !!! FIXME: this code counts on the register not having swizzles, etc. |
| 2106 | get_HLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x3pad_dst0, |
| 2107 | src0, sizeof (src0)); |
| 2108 | get_HLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x3pad_src0, |
| 2109 | src1, sizeof (src1)); |
| 2110 | get_HLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x3pad_dst1, |
| 2111 | src2, sizeof (src2)); |
| 2112 | get_HLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x3pad_src1, |
| 2113 | src3, sizeof (src3)); |
| 2114 | get_HLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->source_args[0].regnum, |
| 2115 | src4, sizeof (src4)); |
| 2116 | get_HLSL_destarg_varname(ctx, dst, sizeof (dst)); |
| 2117 | |
| 2118 | make_HLSL_destarg_assign(ctx, code, sizeof (code), |
| 2119 | "float4(dot(%s.xyz, %s.xyz), dot(%s.xyz, %s.xyz), dot(%s.xyz, %s.xyz), 1.0)", |
| 2120 | src0, src1, src2, src3, dst, src4); |
| 2121 | |
| 2122 | output_line(ctx, "%s", code); |
| 2123 | } // emit_HLSL_TEXM3X3 |
| 2124 | |
| 2125 | EMIT_HLSL_OPCODE_UNIMPLEMENTED_FUNC(TEXDEPTH) // !!! FIXME |
| 2126 | |
| 2127 | void emit_HLSL_CMP(Context *ctx) |
| 2128 | { |
| 2129 | emit_HLSL_comparison_operations(ctx, ">= 0.0"); |
| 2130 | } // emit_HLSL_CMP |
| 2131 | |
| 2132 | EMIT_HLSL_OPCODE_UNIMPLEMENTED_FUNC(BEM) // !!! FIXME |
| 2133 | |
| 2134 | void emit_HLSL_DP2ADD(Context *ctx) |
| 2135 | { |
| 2136 | char src0[64]; make_HLSL_srcarg_string_vec2(ctx, 0, src0, sizeof (src0)); |
| 2137 | char src1[64]; make_HLSL_srcarg_string_vec2(ctx, 1, src1, sizeof (src1)); |
| 2138 | char src2[64]; make_HLSL_srcarg_string_scalar(ctx, 2, src2, sizeof (src2)); |
| 2139 | char extra[64]; snprintf(extra, sizeof (extra), " + %s", src2); |
| 2140 | emit_HLSL_dotprod(ctx, src0, src1, extra); |
| 2141 | } // emit_HLSL_DP2ADD |
| 2142 | |
| 2143 | void emit_HLSL_DSX(Context *ctx) |
| 2144 | { |
| 2145 | char src0[64]; make_HLSL_srcarg_string_masked(ctx, 0, src0, sizeof (src0)); |
| 2146 | char code[128]; |
| 2147 | make_HLSL_destarg_assign(ctx, code, sizeof (code), "ddx(%s)", src0); |
| 2148 | output_line(ctx, "%s", code); |
| 2149 | } // emit_HLSL_DSX |
| 2150 | |
| 2151 | void emit_HLSL_DSY(Context *ctx) |
| 2152 | { |
| 2153 | char src0[64]; make_HLSL_srcarg_string_masked(ctx, 0, src0, sizeof (src0)); |
| 2154 | char code[128]; |
| 2155 | make_HLSL_destarg_assign(ctx, code, sizeof (code), "ddy(%s)", src0); |
| 2156 | output_line(ctx, "%s", code); |
| 2157 | } // emit_HLSL_DSY |
| 2158 | |
| 2159 | void emit_HLSL_TEXLDD(Context *ctx) |
| 2160 | { |
| 2161 | const SourceArgInfo *samp_arg = &ctx->source_args[1]; |
| 2162 | RegisterList *sreg = reglist_find(&ctx->samplers, REG_TYPE_SAMPLER, |
| 2163 | samp_arg->regnum); |
| 2164 | char src0[64] = { '\0' }; |
| 2165 | char src1[64]; get_HLSL_srcarg_varname(ctx, 1, src1, sizeof (src1)); // !!! FIXME: SRC_MOD? |
| 2166 | char src2[64] = { '\0' }; |
| 2167 | char src3[64] = { '\0' }; |
| 2168 | |
| 2169 | if (sreg == NULL) |
| 2170 | { |
| 2171 | fail(ctx, "TEXLDD using undeclared sampler"); |
| 2172 | return; |
| 2173 | } // if |
| 2174 | |
| 2175 | switch ((const TextureType) sreg->index) |
| 2176 | { |
| 2177 | case TEXTURE_TYPE_2D: |
| 2178 | make_HLSL_srcarg_string_vec2(ctx, 0, src0, sizeof (src0)); |
| 2179 | make_HLSL_srcarg_string_vec2(ctx, 2, src2, sizeof (src2)); |
| 2180 | make_HLSL_srcarg_string_vec2(ctx, 3, src3, sizeof (src3)); |
| 2181 | break; |
| 2182 | case TEXTURE_TYPE_CUBE: |
| 2183 | case TEXTURE_TYPE_VOLUME: |
| 2184 | make_HLSL_srcarg_string_vec3(ctx, 0, src0, sizeof (src0)); |
| 2185 | make_HLSL_srcarg_string_vec3(ctx, 2, src2, sizeof (src2)); |
| 2186 | make_HLSL_srcarg_string_vec3(ctx, 3, src3, sizeof (src3)); |
| 2187 | break; |
| 2188 | default: |
| 2189 | fail(ctx, "unknown texture type"); |
| 2190 | return; |
| 2191 | } // switch |
| 2192 | |
| 2193 | assert(!isscalar(ctx, ctx->shader_type, samp_arg->regtype, samp_arg->regnum)); |
| 2194 | char swiz_str[6] = { '\0' }; |
| 2195 | make_HLSL_swizzle_string(swiz_str, sizeof (swiz_str), |
| 2196 | samp_arg->swizzle, ctx->dest_arg.writemask); |
| 2197 | |
| 2198 | char code[128]; |
| 2199 | make_HLSL_destarg_assign(ctx, code, sizeof (code), |
| 2200 | "%s_texture.SampleGrad(%s, %s, %s, %s)%s", |
| 2201 | src1, src1, src0, src2, src3, swiz_str); |
| 2202 | |
| 2203 | output_line(ctx, "%s", code); |
| 2204 | } // emit_HLSL_TEXLDD |
| 2205 | |
| 2206 | void emit_HLSL_SETP(Context *ctx) |
| 2207 | { |
| 2208 | const int vecsize = vecsize_from_writemask(ctx->dest_arg.writemask); |
| 2209 | char src0[64]; make_HLSL_srcarg_string_masked(ctx, 0, src0, sizeof (src0)); |
| 2210 | char src1[64]; make_HLSL_srcarg_string_masked(ctx, 1, src1, sizeof (src1)); |
| 2211 | char code[128]; |
| 2212 | |
| 2213 | // destination is always predicate register (which is type bvec4). |
| 2214 | const char *comp = (vecsize == 1) ? |
| 2215 | get_HLSL_comparison_string_scalar(ctx) : |
| 2216 | get_HLSL_comparison_string_vector(ctx); |
| 2217 | |
| 2218 | make_HLSL_destarg_assign(ctx, code, sizeof (code), |
| 2219 | "(%s %s %s)", src0, comp, src1); |
| 2220 | output_line(ctx, "%s", code); |
| 2221 | } // emit_HLSL_SETP |
| 2222 | |
| 2223 | void emit_HLSL_TEXLDL(Context *ctx) |
| 2224 | { |
| 2225 | const SourceArgInfo *samp_arg = &ctx->source_args[1]; |
| 2226 | RegisterList *sreg = reglist_find(&ctx->samplers, REG_TYPE_SAMPLER, |
| 2227 | samp_arg->regnum); |
| 2228 | const char *pattern = NULL; |
| 2229 | char src0[64]; |
| 2230 | char src1[64]; |
| 2231 | make_HLSL_srcarg_string_full(ctx, 0, src0, sizeof (src0)); |
| 2232 | get_HLSL_srcarg_varname(ctx, 1, src1, sizeof (src1)); // !!! FIXME: SRC_MOD? |
| 2233 | |
| 2234 | if (sreg == NULL) |
| 2235 | { |
| 2236 | fail(ctx, "TEXLDL using undeclared sampler"); |
| 2237 | return; |
| 2238 | } // if |
| 2239 | |
| 2240 | switch ((const TextureType) sreg->index) |
| 2241 | { |
| 2242 | case TEXTURE_TYPE_2D: |
| 2243 | pattern = "%s_texture.SampleLevel(%s, %s.xy, %s.w)%s"; |
| 2244 | break; |
| 2245 | case TEXTURE_TYPE_CUBE: |
| 2246 | case TEXTURE_TYPE_VOLUME: |
| 2247 | pattern = "%s_texture.SampleLevel(%s, %s.xyz, %s.w)%s"; |
| 2248 | break; |
| 2249 | default: |
| 2250 | fail(ctx, "unknown texture type"); |
| 2251 | return; |
| 2252 | } // switch |
| 2253 | |
| 2254 | assert(!isscalar(ctx, ctx->shader_type, samp_arg->regtype, samp_arg->regnum)); |
| 2255 | char swiz_str[6] = { '\0' }; |
| 2256 | make_HLSL_swizzle_string(swiz_str, sizeof (swiz_str), |
| 2257 | samp_arg->swizzle, ctx->dest_arg.writemask); |
| 2258 | |
| 2259 | char code[128]; |
| 2260 | make_HLSL_destarg_assign(ctx, code, sizeof(code), |
| 2261 | pattern, src1, src1, src0, src0, swiz_str); |
| 2262 | |
| 2263 | output_line(ctx, "%s", code); |
| 2264 | } // emit_HLSL_TEXLDL |
| 2265 | |
| 2266 | void emit_HLSL_BREAKP(Context *ctx) |
| 2267 | { |
| 2268 | char src0[64]; make_HLSL_srcarg_string_scalar(ctx, 0, src0, sizeof (src0)); |
| 2269 | output_line(ctx, "if (%s) { break; }", src0); |
| 2270 | } // emit_HLSL_BREAKP |
| 2271 | |
| 2272 | void emit_HLSL_RESERVED(Context *ctx) |
| 2273 | { |
| 2274 | // do nothing; fails in the state machine. |
| 2275 | } // emit_HLSL_RESERVED |
| 2276 | |
| 2277 | #endif // SUPPORT_PROFILE_HLSL |
| 2278 | |
| 2279 | #pragma GCC visibility pop |