mojoshader.c
changeset 1102 0af2fb8af7fc
parent 1101 3a1384bf9ca1
child 1103 8b7c29c019d5
equal deleted inserted replaced
1101:3a1384bf9ca1 1102:0af2fb8af7fc
  3693 
  3693 
  3694 EMIT_GLSL_OPCODE_UNIMPLEMENTED_FUNC(TEXREG2RGB) // !!! FIXME
  3694 EMIT_GLSL_OPCODE_UNIMPLEMENTED_FUNC(TEXREG2RGB) // !!! FIXME
  3695 EMIT_GLSL_OPCODE_UNIMPLEMENTED_FUNC(TEXDP3TEX) // !!! FIXME
  3695 EMIT_GLSL_OPCODE_UNIMPLEMENTED_FUNC(TEXDP3TEX) // !!! FIXME
  3696 EMIT_GLSL_OPCODE_UNIMPLEMENTED_FUNC(TEXM3X2DEPTH) // !!! FIXME
  3696 EMIT_GLSL_OPCODE_UNIMPLEMENTED_FUNC(TEXM3X2DEPTH) // !!! FIXME
  3697 EMIT_GLSL_OPCODE_UNIMPLEMENTED_FUNC(TEXDP3) // !!! FIXME
  3697 EMIT_GLSL_OPCODE_UNIMPLEMENTED_FUNC(TEXDP3) // !!! FIXME
  3698 EMIT_GLSL_OPCODE_UNIMPLEMENTED_FUNC(TEXM3X3) // !!! FIXME
  3698 
       
  3699 static void emit_GLSL_TEXM3X3(Context *ctx)
       
  3700 {
       
  3701     if (ctx->texm3x3pad_src1 == -1)
       
  3702         return;
       
  3703 
       
  3704     char dst[64];
       
  3705     char src0[64];
       
  3706     char src1[64];
       
  3707     char src2[64];
       
  3708     char src3[64];
       
  3709     char src4[64];
       
  3710     char code[512];
       
  3711 
       
  3712     // !!! FIXME: this code counts on the register not having swizzles, etc.
       
  3713     get_GLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x3pad_dst0,
       
  3714                             src0, sizeof (src0));
       
  3715     get_GLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x3pad_src0,
       
  3716                             src1, sizeof (src1));
       
  3717     get_GLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x3pad_dst1,
       
  3718                             src2, sizeof (src2));
       
  3719     get_GLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x3pad_src1,
       
  3720                             src3, sizeof (src3));
       
  3721     get_GLSL_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->source_args[0].regnum,
       
  3722                             src4, sizeof (src4));
       
  3723     get_GLSL_destarg_varname(ctx, dst, sizeof (dst));
       
  3724 
       
  3725     make_GLSL_destarg_assign(ctx, code, sizeof (code),
       
  3726         "vec4(dot(%s.xyz, %s.xyz), dot(%s.xyz, %s.xyz), dot(%s.xyz, %s.xyz), 1.0)",
       
  3727         src0, src1, src2, src3, dst, src4);
       
  3728 
       
  3729     output_line(ctx, "%s", code);
       
  3730 } // emit_GLSL_TEXM3X3
       
  3731 
  3699 EMIT_GLSL_OPCODE_UNIMPLEMENTED_FUNC(TEXDEPTH) // !!! FIXME
  3732 EMIT_GLSL_OPCODE_UNIMPLEMENTED_FUNC(TEXDEPTH) // !!! FIXME
  3700 
  3733 
  3701 static void emit_GLSL_CMP(Context *ctx)
  3734 static void emit_GLSL_CMP(Context *ctx)
  3702 {
  3735 {
  3703     emit_GLSL_comparison_operations(ctx, ">= 0.0");
  3736     emit_GLSL_comparison_operations(ctx, ">= 0.0");
  5707 
  5740 
  5708 EMIT_ARB1_OPCODE_UNIMPLEMENTED_FUNC(TEXREG2RGB)
  5741 EMIT_ARB1_OPCODE_UNIMPLEMENTED_FUNC(TEXREG2RGB)
  5709 EMIT_ARB1_OPCODE_UNIMPLEMENTED_FUNC(TEXDP3TEX)
  5742 EMIT_ARB1_OPCODE_UNIMPLEMENTED_FUNC(TEXDP3TEX)
  5710 EMIT_ARB1_OPCODE_UNIMPLEMENTED_FUNC(TEXM3X2DEPTH)
  5743 EMIT_ARB1_OPCODE_UNIMPLEMENTED_FUNC(TEXM3X2DEPTH)
  5711 EMIT_ARB1_OPCODE_UNIMPLEMENTED_FUNC(TEXDP3)
  5744 EMIT_ARB1_OPCODE_UNIMPLEMENTED_FUNC(TEXDP3)
  5712 EMIT_ARB1_OPCODE_UNIMPLEMENTED_FUNC(TEXM3X3)
  5745 
       
  5746 static void emit_ARB1_TEXM3X3(Context *ctx)
       
  5747 {
       
  5748     if (ctx->texm3x3pad_src1 == -1)
       
  5749         return;
       
  5750 
       
  5751     char dst[64];
       
  5752     char src0[64];
       
  5753     char src1[64];
       
  5754     char src2[64];
       
  5755     char src3[64];
       
  5756     char src4[64];
       
  5757 
       
  5758     // !!! FIXME: this code counts on the register not having swizzles, etc.
       
  5759     get_ARB1_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x3pad_dst0,
       
  5760                             src0, sizeof (src0));
       
  5761     get_ARB1_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x3pad_src0,
       
  5762                             src1, sizeof (src1));
       
  5763     get_ARB1_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x3pad_dst1,
       
  5764                             src2, sizeof (src2));
       
  5765     get_ARB1_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->texm3x3pad_src1,
       
  5766                             src3, sizeof (src3));
       
  5767     get_ARB1_varname_in_buf(ctx, REG_TYPE_TEXTURE, ctx->source_args[0].regnum,
       
  5768                             src4, sizeof (src4));
       
  5769     get_ARB1_destarg_varname(ctx, dst, sizeof (dst));
       
  5770 
       
  5771     output_line(ctx, "DP3 %s.z, %s, %s;", dst, dst, src4);
       
  5772     output_line(ctx, "DP3 %s.x, %s, %s;", dst, src0, src1);
       
  5773     output_line(ctx, "DP3 %s.y, %s, %s;", dst, src2, src3);
       
  5774     output_line(ctx, "MOV %s.w, { 1.0, 1.0, 1.0, 1.0 };", dst);
       
  5775     emit_ARB1_dest_modifiers(ctx);
       
  5776 } // emit_ARB1_TEXM3X3
       
  5777 
  5713 EMIT_ARB1_OPCODE_UNIMPLEMENTED_FUNC(TEXDEPTH)
  5778 EMIT_ARB1_OPCODE_UNIMPLEMENTED_FUNC(TEXDEPTH)
  5714 
  5779 
  5715 static void emit_ARB1_CMP(Context *ctx)
  5780 static void emit_ARB1_CMP(Context *ctx)
  5716 {
  5781 {
  5717     char dst[64]; make_ARB1_destarg_string(ctx, dst, sizeof (dst));
  5782     char dst[64]; make_ARB1_destarg_string(ctx, dst, sizeof (dst));
  7449         ctx->texm3x3pad_src1 = ctx->source_args[0].regnum;
  7514         ctx->texm3x3pad_src1 = ctx->source_args[0].regnum;
  7450         ctx->texm3x3pad_dst1 = ctx->dest_arg.regnum;
  7515         ctx->texm3x3pad_dst1 = ctx->dest_arg.regnum;
  7451     } // else
  7516     } // else
  7452 } // state_TEXM3X3PAD
  7517 } // state_TEXM3X3PAD
  7453 
  7518 
  7454 static void state_texm3x3(Context *ctx, const char *opcode)
  7519 static void state_texm3x3(Context *ctx, const char *opcode, const int dims)
  7455 {
  7520 {
  7456     // !!! FIXME: check for correct opcode existance and order more rigorously?
  7521     // !!! FIXME: check for correct opcode existance and order more rigorously?
  7457     if (shader_version_atleast(ctx, 1, 4))
  7522     if (shader_version_atleast(ctx, 1, 4))
  7458         failf(ctx, "%s opcode not available after Shader Model 1.3", opcode);
  7523         failf(ctx, "%s opcode not available after Shader Model 1.3", opcode);
  7459     if (ctx->texm3x3pad_dst1 == -1)
  7524     if (ctx->texm3x3pad_dst1 == -1)
  7460         failf(ctx, "%s opcode without matching TEXM3X3PADs", opcode);
  7525         failf(ctx, "%s opcode without matching TEXM3X3PADs", opcode);
  7461     state_texops(ctx, opcode, 3, 0);
  7526     state_texops(ctx, opcode, dims, 0);
  7462     ctx->reset_texmpad = 1;
  7527     ctx->reset_texmpad = 1;
  7463 } // state_texm3x3
  7528 } // state_texm3x3
  7464 
  7529 
  7465 static void state_TEXM3X3(Context *ctx)
  7530 static void state_TEXM3X3(Context *ctx)
  7466 {
  7531 {
  7467     if (!shader_version_atleast(ctx, 1, 2))
  7532     if (!shader_version_atleast(ctx, 1, 2))
  7468         fail(ctx, "TEXM3X3 opcode not available in Shader Model 1.1");
  7533         fail(ctx, "TEXM3X3 opcode not available in Shader Model 1.1");
  7469     state_texm3x3(ctx, "TEXM3X3");
  7534     state_texm3x3(ctx, "TEXM3X3", 0);
  7470 } // state_TEXM3X3
  7535 } // state_TEXM3X3
  7471 
  7536 
  7472 static void state_TEXM3X3TEX(Context *ctx)
  7537 static void state_TEXM3X3TEX(Context *ctx)
  7473 {
  7538 {
  7474     state_texm3x3(ctx, "TEXM3X3TEX");
  7539     state_texm3x3(ctx, "TEXM3X3TEX", 3);
  7475 } // state_TEXM3X3TEX
  7540 } // state_TEXM3X3TEX
  7476 
  7541 
  7477 static void state_TEXM3X3SPEC(Context *ctx)
  7542 static void state_TEXM3X3SPEC(Context *ctx)
  7478 {
  7543 {
  7479     state_texm3x3(ctx, "TEXM3X3SPEC");
  7544     state_texm3x3(ctx, "TEXM3X3SPEC", 3);
  7480     if (ctx->source_args[1].regtype != REG_TYPE_CONST)
  7545     if (ctx->source_args[1].regtype != REG_TYPE_CONST)
  7481         fail(ctx, "TEXM3X3SPEC final arg must be a constant register");
  7546         fail(ctx, "TEXM3X3SPEC final arg must be a constant register");
  7482 } // state_TEXM3X3SPEC
  7547 } // state_TEXM3X3SPEC
  7483 
  7548 
  7484 static void state_TEXM3X3VSPEC(Context *ctx)
  7549 static void state_TEXM3X3VSPEC(Context *ctx)
  7485 {
  7550 {
  7486     state_texm3x3(ctx, "TEXM3X3VSPEC");
  7551     state_texm3x3(ctx, "TEXM3X3VSPEC", 3);
  7487 } // state_TEXM3X3VSPEC
  7552 } // state_TEXM3X3VSPEC
  7488 
  7553 
  7489 
  7554 
  7490 static void state_TEXLD(Context *ctx)
  7555 static void state_TEXLD(Context *ctx)
  7491 {
  7556 {