Revert "st/mesa: Make the frontbuffer visible on st_flush(PIPE_FLUSH_FRAME)."
[mesa.git] / src / mesa / shader / prog_print.c
index 20d3fdec477378ad5ec21f1b294a2d4a84638bab..54fd88ad4fba3f6ad1c66b905e5f75ed790521ba 100644 (file)
@@ -150,6 +150,10 @@ arb_input_attrib_string(GLint index, GLenum progType)
       "fragment.varying[7]"
    };
 
+   /* sanity checks */
+   assert(strcmp(vertAttribs[VERT_ATTRIB_TEX0], "vertex.texcoord[0]") == 0);
+   assert(strcmp(vertAttribs[VERT_ATTRIB_GENERIC15], "vertex.attrib[15]") == 0);
+
    if (progType == GL_VERTEX_PROGRAM_ARB) {
       assert(index < sizeof(vertAttribs) / sizeof(vertAttribs[0]));
       return vertAttribs[index];
@@ -161,6 +165,43 @@ arb_input_attrib_string(GLint index, GLenum progType)
 }
 
 
+/**
+ * Print a vertex program's InputsRead field in human-readable format.
+ * For debugging.
+ */
+void
+_mesa_print_vp_inputs(GLbitfield inputs)
+{
+   _mesa_printf("VP Inputs 0x%x: \n", inputs);
+   while (inputs) {
+      GLint attr = _mesa_ffs(inputs) - 1;
+      const char *name = arb_input_attrib_string(attr,
+                                                 GL_VERTEX_PROGRAM_ARB);
+      _mesa_printf("  %d: %s\n", attr, name);
+      inputs &= ~(1 << attr);
+   }
+}
+
+
+/**
+ * Print a fragment program's InputsRead field in human-readable format.
+ * For debugging.
+ */
+void
+_mesa_print_fp_inputs(GLbitfield inputs)
+{
+   _mesa_printf("FP Inputs 0x%x: \n", inputs);
+   while (inputs) {
+      GLint attr = _mesa_ffs(inputs) - 1;
+      const char *name = arb_input_attrib_string(attr,
+                                                 GL_FRAGMENT_PROGRAM_ARB);
+      _mesa_printf("  %d: %s\n", attr, name);
+      inputs &= ~(1 << attr);
+   }
+}
+
+
+
 /**
  * Return ARB_v/f_prog-style output attrib string.
  */
@@ -533,7 +574,7 @@ void
 _mesa_print_alu_instruction(const struct prog_instruction *inst,
                             const char *opcode_string, GLuint numRegs)
 {
-   fprint_alu_instruction(stdout, inst, opcode_string,
+   fprint_alu_instruction(stderr, inst, opcode_string,
                           numRegs, PROG_PRINT_DEBUG, NULL);
 }
 
@@ -757,7 +798,7 @@ _mesa_print_instruction_opt(const struct prog_instruction *inst,
                             gl_prog_print_mode mode,
                             const struct gl_program *prog)
 {
-   return _mesa_fprint_instruction_opt(stdout, inst, indent, mode, prog);
+   return _mesa_fprint_instruction_opt(stderr, inst, indent, mode, prog);
 }
 
 
@@ -765,7 +806,7 @@ void
 _mesa_print_instruction(const struct prog_instruction *inst)
 {
    /* note: 4th param should be ignored for PROG_PRINT_DEBUG */
-   _mesa_fprint_instruction_opt(stdout, inst, 0, PROG_PRINT_DEBUG, NULL);
+   _mesa_fprint_instruction_opt(stderr, inst, 0, PROG_PRINT_DEBUG, NULL);
 }
 
 
@@ -788,7 +829,7 @@ _mesa_fprint_program_opt(FILE *f,
       else if (mode == PROG_PRINT_NV)
          _mesa_fprintf(f, "!!VP1.0\n");
       else
-         _mesa_fprintf(f, "# Vertex Program/Shader\n");
+         _mesa_fprintf(f, "# Vertex Program/Shader %u\n", prog->Id);
       break;
    case GL_FRAGMENT_PROGRAM_ARB:
    case GL_FRAGMENT_PROGRAM_NV:
@@ -797,7 +838,7 @@ _mesa_fprint_program_opt(FILE *f,
       else if (mode == PROG_PRINT_NV)
          _mesa_fprintf(f, "!!FP1.0\n");
       else
-         _mesa_fprintf(f, "# Fragment Program/Shader\n");
+         _mesa_fprintf(f, "# Fragment Program/Shader %u\n", prog->Id);
       break;
    }
 
@@ -811,12 +852,37 @@ _mesa_fprint_program_opt(FILE *f,
 
 
 /**
- * Print program to stdout, default options.
+ * Print program to stderr, default options.
  */
 void
 _mesa_print_program(const struct gl_program *prog)
 {
-   _mesa_fprint_program_opt(stdout, prog, PROG_PRINT_DEBUG, GL_TRUE);
+   _mesa_fprint_program_opt(stderr, prog, PROG_PRINT_DEBUG, GL_TRUE);
+}
+
+
+/**
+ * Return binary representation of 64-bit value (as a string).
+ * Insert a comma to separate each group of 8 bits.
+ * Note we return a pointer to local static storage so this is not
+ * re-entrant, etc.
+ * XXX move to imports.[ch] if useful elsewhere.
+ */
+static const char *
+binary(GLbitfield64 val)
+{
+   static char buf[80];
+   GLint i, len = 0;
+   for (i = 63; i >= 0; --i) {
+      if (val & (1ULL << i))
+         buf[len++] = '1';
+      else if (len > 0 || i == 0)
+         buf[len++] = '0';
+      if (len > 0 && ((i-1) % 8) == 7)
+         buf[len++] = ',';
+   }
+   buf[len] = '\0';
+   return buf;
 }
 
 
@@ -830,13 +896,17 @@ _mesa_fprint_program_parameters(FILE *f,
 {
    GLuint i;
 
-   _mesa_fprintf(f, "InputsRead: 0x%x\n", prog->InputsRead);
-   _mesa_fprintf(f, "OutputsWritten: 0x%x\n", prog->OutputsWritten);
+   _mesa_fprintf(f, "InputsRead: 0x%x (0b%s)\n",
+                 prog->InputsRead, binary(prog->InputsRead));
+   _mesa_fprintf(f, "OutputsWritten: 0x%llx (0b%s)\n",
+                 prog->OutputsWritten, binary(prog->OutputsWritten));
    _mesa_fprintf(f, "NumInstructions=%d\n", prog->NumInstructions);
    _mesa_fprintf(f, "NumTemporaries=%d\n", prog->NumTemporaries);
    _mesa_fprintf(f, "NumParameters=%d\n", prog->NumParameters);
    _mesa_fprintf(f, "NumAttributes=%d\n", prog->NumAttributes);
    _mesa_fprintf(f, "NumAddressRegs=%d\n", prog->NumAddressRegs);
+   _mesa_fprintf(f, "SamplersUsed: 0x%x (0b%s)\n",
+                 prog->SamplersUsed, binary(prog->SamplersUsed));
    _mesa_fprintf(f, "Samplers=[ ");
    for (i = 0; i < MAX_SAMPLERS; i++) {
       _mesa_fprintf(f, "%d ", prog->SamplerUnits[i]);
@@ -857,12 +927,12 @@ _mesa_fprint_program_parameters(FILE *f,
 
 
 /**
- * Print all of a program's parameters/fields to stdout.
+ * Print all of a program's parameters/fields to stderr.
  */
 void
 _mesa_print_program_parameters(GLcontext *ctx, const struct gl_program *prog)
 {
-   _mesa_fprint_program_parameters(stdout, ctx, prog);
+   _mesa_fprint_program_parameters(stderr, ctx, prog);
 }
 
 
@@ -879,7 +949,8 @@ _mesa_fprint_parameter_list(FILE *f,
    if (!list)
       return;
 
-   _mesa_fprintf(f, "param list %p\n", (void *) list);
+   if (0)
+      _mesa_fprintf(f, "param list %p\n", (void *) list);
    _mesa_fprintf(f, "dirty state flags: 0x%x\n", list->StateFlags);
    for (i = 0; i < list->NumParameters; i++){
       struct gl_program_parameter *param = list->Parameters + i;
@@ -902,12 +973,12 @@ _mesa_fprint_parameter_list(FILE *f,
 
 
 /**
- * Print a program parameter list to stdout.
+ * Print a program parameter list to stderr.
  */
 void
 _mesa_print_parameter_list(const struct gl_program_parameter_list *list)
 {
-   _mesa_fprint_parameter_list(stdout, list);
+   _mesa_fprint_parameter_list(stderr, list);
 }
 
 
@@ -958,3 +1029,35 @@ _mesa_write_shader_to_file(const struct gl_shader *shader)
 }
 
 
+/**
+ * Append the shader's uniform info/values to the shader log file.
+ * The log file will typically have been created by the
+ * _mesa_write_shader_to_file function.
+ */
+void
+_mesa_append_uniforms_to_file(const struct gl_shader *shader,
+                              const struct gl_program *prog)
+{
+   const char *type;
+   char filename[100];
+   FILE *f;
+
+   if (shader->Type == GL_FRAGMENT_SHADER)
+      type = "frag";
+   else
+      type = "vert";
+
+   _mesa_snprintf(filename, sizeof(filename), "shader_%u.%s", shader->Name, type);
+   f = fopen(filename, "a"); /* append */
+   if (!f) {
+      fprintf(stderr, "Unable to open %s for appending\n", filename);
+      return;
+   }
+
+   fprintf(f, "/* First-draw parameters / constants */\n");
+   fprintf(f, "/*\n");
+   _mesa_fprint_parameter_list(f, prog->Parameters);
+   fprintf(f, "*/\n");
+
+   fclose(f);
+}