tgsi: correct handling of return value from util_vsnprintf
[mesa.git] / src / gallium / auxiliary / tgsi / tgsi_scan.c
index cfc7ea8e898fb3e5988ebd330338530f3bb4231b..c535788819f99f068effe3606a8ff59aad767348 100644 (file)
@@ -43,6 +43,9 @@
 
 
 /**
+ * Scan the given TGSI shader to collect information such as number of
+ * registers used, special instructions used, etc.
+ * \return info  the result of the scan
  */
 void
 tgsi_scan_shader(const struct tgsi_token *tokens,
@@ -115,7 +118,7 @@ tgsi_scan_shader(const struct tgsi_token *tokens,
          {
             const struct tgsi_full_declaration *fulldecl
                = &parse.FullToken.FullDeclaration;
-            uint file = fulldecl->Declaration.File;
+            const uint file = fulldecl->Declaration.File;
             uint reg;
             for (reg = fulldecl->DeclarationRange.First;
                  reg <= fulldecl->DeclarationRange.Last;
@@ -124,15 +127,14 @@ tgsi_scan_shader(const struct tgsi_token *tokens,
                /* only first 32 regs will appear in this bitfield */
                info->file_mask[file] |= (1 << reg);
                info->file_count[file]++;
-               info->file_max[file] = MAX2(info->file_max[file], (int)i);
+               info->file_max[file] = MAX2(info->file_max[file], (int)reg);
 
                if (file == TGSI_FILE_INPUT) {
                   info->input_semantic_name[reg] = (ubyte)fulldecl->Semantic.SemanticName;
                   info->input_semantic_index[reg] = (ubyte)fulldecl->Semantic.SemanticIndex;
                   info->num_inputs++;
                }
-
-               if (file == TGSI_FILE_OUTPUT) {
+               else if (file == TGSI_FILE_OUTPUT) {
                   info->output_semantic_name[reg] = (ubyte)fulldecl->Semantic.SemanticName;
                   info->output_semantic_index[reg] = (ubyte)fulldecl->Semantic.SemanticIndex;
                   info->num_outputs++;
@@ -149,7 +151,14 @@ tgsi_scan_shader(const struct tgsi_token *tokens,
          break;
 
       case TGSI_TOKEN_TYPE_IMMEDIATE:
-         info->immediate_count++;
+         {
+            uint reg = info->immediate_count++;
+            uint file = TGSI_FILE_IMMEDIATE;
+
+            info->file_mask[file] |= (1 << reg);
+            info->file_count[file]++;
+            info->file_max[file] = MAX2(info->file_max[file], (int)reg);
+         }
          break;
 
       default: