mojoshader.c
changeset 1048 d58bd6348b15
parent 1046 097aefb03885
child 1049 ac4c2e745802
equal deleted inserted replaced
1047:6b92ce2fc809 1048:d58bd6348b15
   138     RegisterList samplers;
   138     RegisterList samplers;
   139     VariableList *variables;  // variables to register mapping.
   139     VariableList *variables;  // variables to register mapping.
   140     int centroid_allowed;
   140     int centroid_allowed;
   141     CtabData ctab;
   141     CtabData ctab;
   142     int have_relative_input_registers;
   142     int have_relative_input_registers;
       
   143     int have_multi_color_outputs;
   143     int determined_constants_arrays;
   144     int determined_constants_arrays;
   144     int predicated;
   145     int predicated;
   145     int glsl_generated_lit_opcode;
   146     int glsl_generated_lit_opcode;
   146     int glsl_generated_texldd_setup;
   147     int glsl_generated_texldd_setup;
   147     int have_preshader;
   148     int have_preshader;
   555 } // reglist_exists
   556 } // reglist_exists
   556 
   557 
   557 static inline void set_used_register(Context *ctx, const RegisterType regtype,
   558 static inline void set_used_register(Context *ctx, const RegisterType regtype,
   558                                      const int regnum)
   559                                      const int regnum)
   559 {
   560 {
       
   561     if ((regtype == REG_TYPE_COLOROUT) && (regnum > 0))
       
   562         ctx->have_multi_color_outputs = 1;
   560     reglist_insert(ctx, &ctx->used_registers, regtype, regnum);
   563     reglist_insert(ctx, &ctx->used_registers, regtype, regnum);
   561 } // set_used_register
   564 } // set_used_register
   562 
   565 
   563 static inline int get_used_register(Context *ctx, const RegisterType regtype,
   566 static inline int get_used_register(Context *ctx, const RegisterType regtype,
   564                                     const int regnum)
   567                                     const int regnum)
  2073         failf(ctx, "Shader type %u unsupported in this profile.",
  2076         failf(ctx, "Shader type %u unsupported in this profile.",
  2074               (uint) ctx->shader_type);
  2077               (uint) ctx->shader_type);
  2075         return;
  2078         return;
  2076     } // if
  2079     } // if
  2077 
  2080 
  2078     if (strcmp(profilestr, MOJOSHADER_PROFILE_GLSL) == 0)
  2081     else if (strcmp(profilestr, MOJOSHADER_PROFILE_GLSL) == 0)
  2079         /* no-op. */ ;
  2082     {
       
  2083         // No gl_FragData[] before GLSL 1.10, so we have to force the version.
       
  2084         push_output(ctx, &ctx->preflight);
       
  2085         output_line(ctx, "#version 110");
       
  2086         pop_output(ctx);
       
  2087     } // else if
  2080 
  2088 
  2081     #if SUPPORT_PROFILE_GLSL120
  2089     #if SUPPORT_PROFILE_GLSL120
  2082     else if (strcmp(profilestr, MOJOSHADER_PROFILE_GLSL120) == 0)
  2090     else if (strcmp(profilestr, MOJOSHADER_PROFILE_GLSL120) == 0)
  2083     {
  2091     {
  2084         ctx->profile_supports_glsl120 = 1;
  2092         ctx->profile_supports_glsl120 = 1;
  2454             failf(ctx, "centroid unsupported in %s profile", ctx->profile->name);
  2462             failf(ctx, "centroid unsupported in %s profile", ctx->profile->name);
  2455             return;
  2463             return;
  2456         } // if
  2464         } // if
  2457 
  2465 
  2458         if (regtype == REG_TYPE_COLOROUT)
  2466         if (regtype == REG_TYPE_COLOROUT)
  2459             usage_str = "gl_FragColor";
  2467         {
       
  2468             if (!ctx->have_multi_color_outputs)
       
  2469                 usage_str = "gl_FragColor";  // maybe faster?
       
  2470             else
       
  2471             {
       
  2472                 snprintf(index_str, sizeof (index_str), "%u", (uint) regnum);
       
  2473                 usage_str = "gl_FragData";
       
  2474                 arrayleft = "[";
       
  2475                 arrayright = "]";
       
  2476             } // else
       
  2477         } // if
  2460 
  2478 
  2461         else if (regtype == REG_TYPE_DEPTHOUT)
  2479         else if (regtype == REG_TYPE_DEPTHOUT)
  2462             usage_str = "gl_FragDepth";
  2480             usage_str = "gl_FragDepth";
  2463 
  2481 
  2464         // !!! FIXME: can you actualy have a texture register with COLOR usage?
  2482         // !!! FIXME: can you actualy have a texture register with COLOR usage?
  3932         failf(ctx, "Shader type %u unsupported in this profile.",
  3950         failf(ctx, "Shader type %u unsupported in this profile.",
  3933               (uint) ctx->shader_type);
  3951               (uint) ctx->shader_type);
  3934         return;
  3952         return;
  3935     } // if
  3953     } // if
  3936 
  3954 
  3937     set_output(ctx, &ctx->globals);
  3955     set_output(ctx, &ctx->preflight);
  3938 
  3956 
  3939     if (strcmp(profilestr, MOJOSHADER_PROFILE_ARB1) == 0)
  3957     if (strcmp(profilestr, MOJOSHADER_PROFILE_ARB1) == 0)
  3940         output_line(ctx, "!!ARB%s1.0", shader_str);
  3958         output_line(ctx, "!!ARB%s1.0", shader_str);
  3941 
  3959 
  3942     #if SUPPORT_PROFILE_ARB1_NV
  3960     #if SUPPORT_PROFILE_ARB1_NV
  3992 
  4010 
  3993 static void emit_ARB1_finalize(Context *ctx)
  4011 static void emit_ARB1_finalize(Context *ctx)
  3994 {
  4012 {
  3995     // !!! FIXME: if we never wrote the position register, add the
  4013     // !!! FIXME: if we never wrote the position register, add the
  3996     // !!! FIXME:  position_invariant program option here.
  4014     // !!! FIXME:  position_invariant program option here.
       
  4015 
       
  4016     if (shader_is_pixel(ctx) && ctx->have_multi_color_outputs)
       
  4017     {
       
  4018         // We have to gamble that you have GL_ARB_draw_buffers.
       
  4019         // You probably do at this point if you have a sane setup.
       
  4020         push_output(ctx, &ctx->preflight);
       
  4021         output_line(ctx, "OPTION ARB_draw_buffers;");
       
  4022         pop_output(ctx);
       
  4023     } // if
       
  4024 
  3997     const char *tmpstr = arb1_float_temp(ctx);
  4025     const char *tmpstr = arb1_float_temp(ctx);
  3998     int i;
  4026     int i;
  3999     push_output(ctx, &ctx->globals);
  4027     push_output(ctx, &ctx->globals);
  4000     for (i = 0; i < ctx->max_scratch_registers; i++)
  4028     for (i = 0; i < ctx->max_scratch_registers; i++)
  4001     {
  4029     {
  4312 
  4340 
  4313         if (regtype == REG_TYPE_COLOROUT)
  4341         if (regtype == REG_TYPE_COLOROUT)
  4314         {
  4342         {
  4315             paramtype_str = "OUTPUT";
  4343             paramtype_str = "OUTPUT";
  4316             usage_str = "result.color";
  4344             usage_str = "result.color";
       
  4345             if (ctx->have_multi_color_outputs)
       
  4346             {
       
  4347                 // We have to gamble that you have GL_ARB_draw_buffers.
       
  4348                 // You probably do at this point if you have a sane setup.
       
  4349                 snprintf(index_str, sizeof (index_str), "%u", (uint) regnum);
       
  4350                 arrayleft = "[";
       
  4351                 arrayright = "]";
       
  4352             } // if
  4317         } // if
  4353         } // if
  4318 
  4354 
  4319         else if (regtype == REG_TYPE_DEPTHOUT)
  4355         else if (regtype == REG_TYPE_DEPTHOUT)
  4320         {
  4356         {
  4321             paramtype_str = "OUTPUT";
  4357             paramtype_str = "OUTPUT";