From 4dd32b54e3cad6ba903881ad7cf49ec0b0eee60d Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sat, 14 Apr 2012 17:14:50 -0400 Subject: [PATCH] Pixel Shader Model 1 writes color output to r0, not oC0. Deal with this. --- mojoshader.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/mojoshader.c b/mojoshader.c index 813ab3bf..1387a3b1 100644 --- a/mojoshader.c +++ b/mojoshader.c @@ -2153,6 +2153,16 @@ static void emit_GLSL_start(Context *ctx, const char *profilestr) static void emit_GLSL_RET(Context *ctx); static void emit_GLSL_end(Context *ctx) { + // ps_1_* writes color to r0 instead oC0. We move it to the right place. + // We don't have to worry about a RET opcode messing this up, since + // RET isn't available before ps_2_0. + if (shader_is_pixel(ctx) && !shader_version_atleast(ctx, 2, 0)) + { + const char *shstr = ctx->shader_type_str; + set_used_register(ctx, REG_TYPE_COLOROUT, 0); + output_line(ctx, "%s_oC0 = %s_r0;", shstr, shstr); + } // if + // force a RET opcode if we're at the end of the stream without one. if (ctx->previous_opcode != OPCODE_RET) emit_GLSL_RET(ctx); @@ -4021,6 +4031,15 @@ static void emit_ARB1_start(Context *ctx, const char *profilestr) static void emit_ARB1_end(Context *ctx) { + // ps_1_* writes color to r0 instead oC0. We move it to the right place. + // We don't have to worry about a RET opcode messing this up, since + // RET isn't available before ps_2_0. + if (shader_is_pixel(ctx) && !shader_version_atleast(ctx, 2, 0)) + { + set_used_register(ctx, REG_TYPE_COLOROUT, 0); + output_line(ctx, "MOV oC0, r0;"); + } // if + output_line(ctx, "END"); } // emit_ARB1_end @@ -8369,6 +8388,11 @@ static void verify_swizzles(Context *ctx) // API entry point... +// !!! FIXME: +// MSDN: "Shader validation will fail CreatePixelShader on any shader that +// attempts to read from a temporary register that has not been written by a +// previous instruction." (true for ps_1_*, maybe others). Check this. + const MOJOSHADER_parseData *MOJOSHADER_parse(const char *profile, const unsigned char *tokenbuf, const unsigned int bufsize,