mojoshader.c
changeset 1081 0318ad91ed5d
parent 1080 b92bdbf78621
child 1082 6fbcfbef2a63
equal deleted inserted replaced
1080:b92bdbf78621 1081:0318ad91ed5d
  2151 } // emit_GLSL_start
  2151 } // emit_GLSL_start
  2152 
  2152 
  2153 static void emit_GLSL_RET(Context *ctx);
  2153 static void emit_GLSL_RET(Context *ctx);
  2154 static void emit_GLSL_end(Context *ctx)
  2154 static void emit_GLSL_end(Context *ctx)
  2155 {
  2155 {
       
  2156     // ps_1_* writes color to r0 instead oC0. We move it to the right place.
       
  2157     // We don't have to worry about a RET opcode messing this up, since
       
  2158     //  RET isn't available before ps_2_0.
       
  2159     if (shader_is_pixel(ctx) && !shader_version_atleast(ctx, 2, 0))
       
  2160     {
       
  2161         const char *shstr = ctx->shader_type_str;
       
  2162         set_used_register(ctx, REG_TYPE_COLOROUT, 0);
       
  2163         output_line(ctx, "%s_oC0 = %s_r0;", shstr, shstr);
       
  2164     } // if
       
  2165 
  2156     // force a RET opcode if we're at the end of the stream without one.
  2166     // force a RET opcode if we're at the end of the stream without one.
  2157     if (ctx->previous_opcode != OPCODE_RET)
  2167     if (ctx->previous_opcode != OPCODE_RET)
  2158         emit_GLSL_RET(ctx);
  2168         emit_GLSL_RET(ctx);
  2159 } // emit_GLSL_end
  2169 } // emit_GLSL_end
  2160 
  2170 
  4019     set_output(ctx, &ctx->mainline);
  4029     set_output(ctx, &ctx->mainline);
  4020 } // emit_ARB1_start
  4030 } // emit_ARB1_start
  4021 
  4031 
  4022 static void emit_ARB1_end(Context *ctx)
  4032 static void emit_ARB1_end(Context *ctx)
  4023 {
  4033 {
       
  4034     // ps_1_* writes color to r0 instead oC0. We move it to the right place.
       
  4035     // We don't have to worry about a RET opcode messing this up, since
       
  4036     //  RET isn't available before ps_2_0.
       
  4037     if (shader_is_pixel(ctx) && !shader_version_atleast(ctx, 2, 0))
       
  4038     {
       
  4039         set_used_register(ctx, REG_TYPE_COLOROUT, 0);
       
  4040         output_line(ctx, "MOV oC0, r0;");
       
  4041     } // if
       
  4042 
  4024     output_line(ctx, "END");
  4043     output_line(ctx, "END");
  4025 } // emit_ARB1_end
  4044 } // emit_ARB1_end
  4026 
  4045 
  4027 static void emit_ARB1_phase(Context *ctx)
  4046 static void emit_ARB1_phase(Context *ctx)
  4028 {
  4047 {
  8367 } // verify_swizzles
  8386 } // verify_swizzles
  8368 
  8387 
  8369 
  8388 
  8370 // API entry point...
  8389 // API entry point...
  8371 
  8390 
       
  8391 // !!! FIXME:
       
  8392 // MSDN: "Shader validation will fail CreatePixelShader on any shader that
       
  8393 //  attempts to read from a temporary register that has not been written by a
       
  8394 //  previous instruction."  (true for ps_1_*, maybe others). Check this.
       
  8395 
  8372 const MOJOSHADER_parseData *MOJOSHADER_parse(const char *profile,
  8396 const MOJOSHADER_parseData *MOJOSHADER_parse(const char *profile,
  8373                                              const unsigned char *tokenbuf,
  8397                                              const unsigned char *tokenbuf,
  8374                                              const unsigned int bufsize,
  8398                                              const unsigned int bufsize,
  8375                                              const MOJOSHADER_swizzle *swiz,
  8399                                              const MOJOSHADER_swizzle *swiz,
  8376                                              const unsigned int swizcount,
  8400                                              const unsigned int swizcount,