1369 #undef EMIT_D3D_OPCODE_DSSSS_FUNC |
1374 #undef EMIT_D3D_OPCODE_DSSSS_FUNC |
1370 |
1375 |
1371 #endif // SUPPORT_PROFILE_D3D |
1376 #endif // SUPPORT_PROFILE_D3D |
1372 |
1377 |
1373 |
1378 |
|
1379 #if !SUPPORT_PROFILE_PASSTHROUGH |
|
1380 #define PROFILE_EMITTER_PASSTHROUGH(op) |
|
1381 #else |
|
1382 #undef AT_LEAST_ONE_PROFILE |
|
1383 #define AT_LEAST_ONE_PROFILE 1 |
|
1384 #define PROFILE_EMITTER_PASSTHROUGH(op) emit_PASSTHROUGH_##op, |
|
1385 |
|
1386 static void emit_PASSTHROUGH_start(Context *ctx) |
|
1387 { |
|
1388 // just copy the whole token stream and make all other emitters no-ops. |
|
1389 ctx->output_len = (ctx->tokencount * sizeof (uint32)); |
|
1390 ctx->output_bytes = Malloc(ctx, ctx->output_len); |
|
1391 if (ctx->output_bytes == NULL) |
|
1392 out_of_memory(ctx); |
|
1393 else |
|
1394 memcpy(ctx->output_bytes, ctx->tokens, ctx->output_len); |
|
1395 } // emit_PASSTHROUGH_start |
|
1396 |
|
1397 static void emit_PASSTHROUGH_RESERVED(Context *ctx) {} |
|
1398 static void emit_PASSTHROUGH_NOP(Context *ctx) {} |
|
1399 static void emit_PASSTHROUGH_MOV(Context *ctx) {} |
|
1400 static void emit_PASSTHROUGH_ADD(Context *ctx) {} |
|
1401 static void emit_PASSTHROUGH_SUB(Context *ctx) {} |
|
1402 static void emit_PASSTHROUGH_MAD(Context *ctx) {} |
|
1403 static void emit_PASSTHROUGH_MUL(Context *ctx) {} |
|
1404 static void emit_PASSTHROUGH_RCP(Context *ctx) {} |
|
1405 static void emit_PASSTHROUGH_RSQ(Context *ctx) {} |
|
1406 static void emit_PASSTHROUGH_DP3(Context *ctx) {} |
|
1407 static void emit_PASSTHROUGH_DP4(Context *ctx) {} |
|
1408 static void emit_PASSTHROUGH_MIN(Context *ctx) {} |
|
1409 static void emit_PASSTHROUGH_MAX(Context *ctx) {} |
|
1410 static void emit_PASSTHROUGH_SLT(Context *ctx) {} |
|
1411 static void emit_PASSTHROUGH_SGE(Context *ctx) {} |
|
1412 static void emit_PASSTHROUGH_EXP(Context *ctx) {} |
|
1413 static void emit_PASSTHROUGH_LOG(Context *ctx) {} |
|
1414 static void emit_PASSTHROUGH_LIT(Context *ctx) {} |
|
1415 static void emit_PASSTHROUGH_DST(Context *ctx) {} |
|
1416 static void emit_PASSTHROUGH_LRP(Context *ctx) {} |
|
1417 static void emit_PASSTHROUGH_FRC(Context *ctx) {} |
|
1418 static void emit_PASSTHROUGH_M4X4(Context *ctx) {} |
|
1419 static void emit_PASSTHROUGH_M4X3(Context *ctx) {} |
|
1420 static void emit_PASSTHROUGH_M3X4(Context *ctx) {} |
|
1421 static void emit_PASSTHROUGH_M3X3(Context *ctx) {} |
|
1422 static void emit_PASSTHROUGH_M3X2(Context *ctx) {} |
|
1423 static void emit_PASSTHROUGH_CALL(Context *ctx) {} |
|
1424 static void emit_PASSTHROUGH_CALLNZ(Context *ctx) {} |
|
1425 static void emit_PASSTHROUGH_LOOP(Context *ctx) {} |
|
1426 static void emit_PASSTHROUGH_RET(Context *ctx) {} |
|
1427 static void emit_PASSTHROUGH_ENDLOOP(Context *ctx) {} |
|
1428 static void emit_PASSTHROUGH_LABEL(Context *ctx) {} |
|
1429 static void emit_PASSTHROUGH_POW(Context *ctx) {} |
|
1430 static void emit_PASSTHROUGH_CRS(Context *ctx) {} |
|
1431 static void emit_PASSTHROUGH_SGN(Context *ctx) {} |
|
1432 static void emit_PASSTHROUGH_ABS(Context *ctx) {} |
|
1433 static void emit_PASSTHROUGH_NRM(Context *ctx) {} |
|
1434 static void emit_PASSTHROUGH_SINCOS(Context *ctx) {} |
|
1435 static void emit_PASSTHROUGH_REP(Context *ctx) {} |
|
1436 static void emit_PASSTHROUGH_ENDREP(Context *ctx) {} |
|
1437 static void emit_PASSTHROUGH_IF(Context *ctx) {} |
|
1438 static void emit_PASSTHROUGH_ELSE(Context *ctx) {} |
|
1439 static void emit_PASSTHROUGH_ENDIF(Context *ctx) {} |
|
1440 static void emit_PASSTHROUGH_BREAK(Context *ctx) {} |
|
1441 static void emit_PASSTHROUGH_MOVA(Context *ctx) {} |
|
1442 static void emit_PASSTHROUGH_TEXKILL(Context *ctx) {} |
|
1443 static void emit_PASSTHROUGH_TEXBEM(Context *ctx) {} |
|
1444 static void emit_PASSTHROUGH_TEXBEML(Context *ctx) {} |
|
1445 static void emit_PASSTHROUGH_TEXREG2AR(Context *ctx) {} |
|
1446 static void emit_PASSTHROUGH_TEXREG2GB(Context *ctx) {} |
|
1447 static void emit_PASSTHROUGH_TEXM3X2PAD(Context *ctx) {} |
|
1448 static void emit_PASSTHROUGH_TEXM3X2TEX(Context *ctx) {} |
|
1449 static void emit_PASSTHROUGH_TEXM3X3PAD(Context *ctx) {} |
|
1450 static void emit_PASSTHROUGH_TEXM3X3TEX(Context *ctx) {} |
|
1451 static void emit_PASSTHROUGH_TEXM3X3SPEC(Context *ctx) {} |
|
1452 static void emit_PASSTHROUGH_TEXM3X3VSPEC(Context *ctx) {} |
|
1453 static void emit_PASSTHROUGH_EXPP(Context *ctx) {} |
|
1454 static void emit_PASSTHROUGH_LOGP(Context *ctx) {} |
|
1455 static void emit_PASSTHROUGH_CND(Context *ctx) {} |
|
1456 static void emit_PASSTHROUGH_TEXREG2RGB(Context *ctx) {} |
|
1457 static void emit_PASSTHROUGH_TEXDP3TEX(Context *ctx) {} |
|
1458 static void emit_PASSTHROUGH_TEXM3X2DEPTH(Context *ctx) {} |
|
1459 static void emit_PASSTHROUGH_TEXDP3(Context *ctx) {} |
|
1460 static void emit_PASSTHROUGH_TEXM3X3(Context *ctx) {} |
|
1461 static void emit_PASSTHROUGH_TEXDEPTH(Context *ctx) {} |
|
1462 static void emit_PASSTHROUGH_CMP(Context *ctx) {} |
|
1463 static void emit_PASSTHROUGH_BEM(Context *ctx) {} |
|
1464 static void emit_PASSTHROUGH_DP2ADD(Context *ctx) {} |
|
1465 static void emit_PASSTHROUGH_DSX(Context *ctx) {} |
|
1466 static void emit_PASSTHROUGH_DSY(Context *ctx) {} |
|
1467 static void emit_PASSTHROUGH_TEXLDD(Context *ctx) {} |
|
1468 static void emit_PASSTHROUGH_TEXLDL(Context *ctx) {} |
|
1469 static void emit_PASSTHROUGH_BREAKP(Context *ctx) {} |
|
1470 static void emit_PASSTHROUGH_BREAKC(Context *ctx) {} |
|
1471 static void emit_PASSTHROUGH_IFC(Context *ctx) {} |
|
1472 static void emit_PASSTHROUGH_SETP(Context *ctx) {} |
|
1473 static void emit_PASSTHROUGH_DEF(Context *ctx) {} |
|
1474 static void emit_PASSTHROUGH_DEFI(Context *ctx) {} |
|
1475 static void emit_PASSTHROUGH_DEFB(Context *ctx) {} |
|
1476 static void emit_PASSTHROUGH_DCL(Context *ctx) {} |
|
1477 static void emit_PASSTHROUGH_TEXCOORD(Context *ctx) {} |
|
1478 static void emit_PASSTHROUGH_TEX(Context *ctx) {} |
|
1479 static void emit_PASSTHROUGH_end(Context *ctx) {} |
|
1480 static void emit_PASSTHROUGH_finalize(Context *ctx) {} |
|
1481 static void emit_PASSTHROUGH_global(Context *ctx, RegisterType t, int n) {} |
|
1482 static void emit_PASSTHROUGH_uniform(Context *ctx, RegisterType t, int n) {} |
|
1483 static void emit_PASSTHROUGH_comment(Context *ctx, const char *str) {} |
|
1484 static void emit_PASSTHROUGH_attribute(Context *ctx, RegisterType t, int n, |
|
1485 MOJOSHADER_usage u, int i, int w) {} |
|
1486 #endif // SUPPORT_PROFILE_PASSTHROUGH |
|
1487 |
1374 |
1488 |
1375 #if !SUPPORT_PROFILE_GLSL |
1489 #if !SUPPORT_PROFILE_GLSL |
1376 #define PROFILE_EMITTER_GLSL(op) |
1490 #define PROFILE_EMITTER_GLSL(op) |
1377 #else |
1491 #else |
1378 #undef AT_LEAST_ONE_PROFILE |
1492 #undef AT_LEAST_ONE_PROFILE |
3641 { |
3759 { |
3642 if (ctx != NULL) |
3760 if (ctx != NULL) |
3643 { |
3761 { |
3644 MOJOSHADER_free f = ((ctx->free != NULL) ? ctx->free : internal_free); |
3762 MOJOSHADER_free f = ((ctx->free != NULL) ? ctx->free : internal_free); |
3645 void *d = ctx->malloc_data; |
3763 void *d = ctx->malloc_data; |
|
3764 if (ctx->output_bytes != NULL) |
|
3765 f(d, ctx->output_bytes); |
3646 free_output_list(f, d, ctx->globals.head.next); |
3766 free_output_list(f, d, ctx->globals.head.next); |
3647 free_output_list(f, d, ctx->helpers.head.next); |
3767 free_output_list(f, d, ctx->helpers.head.next); |
3648 free_output_list(f, d, ctx->subroutines.head.next); |
3768 free_output_list(f, d, ctx->subroutines.head.next); |
3649 free_output_list(f, d, ctx->mainline.head.next); |
3769 free_output_list(f, d, ctx->mainline.head.next); |
3650 free_output_list(f, d, ctx->ignore.head.next); |
3770 free_output_list(f, d, ctx->ignore.head.next); |
3677 } // append_list |
3797 } // append_list |
3678 |
3798 |
3679 |
3799 |
3680 static char *build_output(Context *ctx) |
3800 static char *build_output(Context *ctx) |
3681 { |
3801 { |
3682 char *retval = (char *) Malloc(ctx, ctx->output_len + 1); |
3802 // add a byte for the null terminator if we're doing text output. |
|
3803 const int plusbytes = (ctx->output_bytes == NULL) ? 1 : 0; |
|
3804 char *retval = (char *) Malloc(ctx, ctx->output_len + plusbytes); |
3683 if (retval == NULL) |
3805 if (retval == NULL) |
3684 out_of_memory(ctx); |
3806 out_of_memory(ctx); |
3685 else |
3807 else |
3686 { |
3808 { |
3687 const char *endl = ctx->endline; |
3809 const char *endl = ctx->endline; |
3688 const size_t endllen = ctx->endline_len; |
3810 const size_t endllen = ctx->endline_len; |
3689 char *wptr = retval; |
3811 char *wptr = retval; |
3690 append_list(&wptr, endl, endllen, ctx->globals.head.next); |
3812 if (ctx->output_bytes != NULL) |
3691 append_list(&wptr, endl, endllen, ctx->helpers.head.next); |
3813 memcpy(retval, ctx->output_bytes, ctx->output_len); |
3692 append_list(&wptr, endl, endllen, ctx->subroutines.head.next); |
3814 else |
3693 append_list(&wptr, endl, endllen, ctx->mainline.head.next); |
3815 { |
3694 // don't append ctx->ignore ... that's why it's called "ignore" |
3816 append_list(&wptr, endl, endllen, ctx->globals.head.next); |
|
3817 append_list(&wptr, endl, endllen, ctx->helpers.head.next); |
|
3818 append_list(&wptr, endl, endllen, ctx->subroutines.head.next); |
|
3819 append_list(&wptr, endl, endllen, ctx->mainline.head.next); |
|
3820 // don't append ctx->ignore ... that's why it's called "ignore" |
|
3821 } // else |
3695 } // else |
3822 } // else |
3696 |
3823 |
3697 return retval; |
3824 return retval; |
3698 } // build_output |
3825 } // build_output |
3699 |
3826 |