Mesa (master): util: convert u_simple_shaders to use tgsi_ureg

Keith Whitwell keithw at kemper.freedesktop.org
Thu Aug 13 12:04:39 UTC 2009


Module: Mesa
Branch: master
Commit: 002c76cfefe8c1ab12fb7031a649a30fb349a3e3
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=002c76cfefe8c1ab12fb7031a649a30fb349a3e3

Author: Keith Whitwell <keithw at vmware.com>
Date:   Thu Aug 13 12:46:32 2009 +0100

util: convert u_simple_shaders to use tgsi_ureg

Much nicer now.

---

 src/gallium/auxiliary/util/u_simple_shaders.c |  318 +++++--------------------
 1 files changed, 60 insertions(+), 258 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_simple_shaders.c b/src/gallium/auxiliary/util/u_simple_shaders.c
index e519c35..1152d62 100644
--- a/src/gallium/auxiliary/util/u_simple_shaders.c
+++ b/src/gallium/auxiliary/util/u_simple_shaders.c
@@ -42,9 +42,7 @@
 #include "util/u_memory.h"
 #include "util/u_simple_shaders.h"
 
-#include "tgsi/tgsi_build.h"
-#include "tgsi/tgsi_dump.h"
-#include "tgsi/tgsi_parse.h"
+#include "tgsi/tgsi_ureg.h"
 
 
 
@@ -58,93 +56,31 @@ util_make_vertex_passthrough_shader(struct pipe_context *pipe,
                                     const uint *semantic_indexes)
                                     
 {
-   struct pipe_shader_state shader;
-   struct tgsi_token tokens[100];
-   struct tgsi_header *header;
-   struct tgsi_processor *processor;
-   struct tgsi_full_declaration decl;
-   struct tgsi_full_instruction inst;
-   const uint procType = TGSI_PROCESSOR_VERTEX;
-   uint ti, i;
+   struct ureg_program *ureg;
+   uint i;
 
-   /* shader header
-    */
-   *(struct tgsi_version *) &tokens[0] = tgsi_build_version();
+   ureg = ureg_create( pipe, TGSI_PROCESSOR_VERTEX );
+   if (ureg == NULL)
+      return NULL;
 
-   header = (struct tgsi_header *) &tokens[1];
-   *header = tgsi_build_header();
-
-   processor = (struct tgsi_processor *) &tokens[2];
-   *processor = tgsi_build_processor( procType, header );
-
-   ti = 3;
-
-   /* declare inputs */
-   for (i = 0; i < num_attribs; i++) {
-      decl = tgsi_default_full_declaration();
-      decl.Declaration.File = TGSI_FILE_INPUT;
-
-      decl.Declaration.Semantic = 1;
-      decl.Semantic.SemanticName = semantic_names[i];
-      decl.Semantic.SemanticIndex = semantic_indexes[i];
-
-      decl.DeclarationRange.First = 
-      decl.DeclarationRange.Last = i;
-      ti += tgsi_build_full_declaration(&decl,
-                                        &tokens[ti],
-                                        header,
-                                        Elements(tokens) - ti);
-   }
-
-   /* declare outputs */
    for (i = 0; i < num_attribs; i++) {
-      decl = tgsi_default_full_declaration();
-      decl.Declaration.File = TGSI_FILE_OUTPUT;
-      decl.Declaration.Semantic = 1;
-      decl.Semantic.SemanticName = semantic_names[i];
-      decl.Semantic.SemanticIndex = semantic_indexes[i];
-      decl.DeclarationRange.First = 
-         decl.DeclarationRange.Last = i;
-      ti += tgsi_build_full_declaration(&decl,
-                                        &tokens[ti],
-                                        header,
-                                        Elements(tokens) - ti);
+      struct ureg_src src;
+      struct ureg_dst dst;
+
+      src = ureg_DECL_vs_input( ureg,
+                                semantic_names[i],
+                                semantic_indexes[i]);
+      
+      dst = ureg_DECL_output( ureg,
+                              semantic_names[i],
+                              semantic_indexes[i]);
+      
+      ureg_MOV( ureg, dst, src );
    }
 
-   /* emit MOV instructions */
-   for (i = 0; i < num_attribs; i++) {
-      /* MOVE out[i], in[i]; */
-      inst = tgsi_default_full_instruction();
-      inst.Instruction.Opcode = TGSI_OPCODE_MOV;
-      inst.Instruction.NumDstRegs = 1;
-      inst.FullDstRegisters[0].DstRegister.File = TGSI_FILE_OUTPUT;
-      inst.FullDstRegisters[0].DstRegister.Index = i;
-      inst.Instruction.NumSrcRegs = 1;
-      inst.FullSrcRegisters[0].SrcRegister.File = TGSI_FILE_INPUT;
-      inst.FullSrcRegisters[0].SrcRegister.Index = i;
-      ti += tgsi_build_full_instruction(&inst,
-                                        &tokens[ti],
-                                        header,
-                                        Elements(tokens) - ti );
-   }
-
-   /* END instruction */
-   inst = tgsi_default_full_instruction();
-   inst.Instruction.Opcode = TGSI_OPCODE_END;
-   inst.Instruction.NumDstRegs = 0;
-   inst.Instruction.NumSrcRegs = 0;
-   ti += tgsi_build_full_instruction(&inst,
-                                     &tokens[ti],
-                                     header,
-                                     Elements(tokens) - ti );
-
-#if 0 /*debug*/
-   tgsi_dump(tokens, 0);
-#endif
-
-   shader.tokens = tokens;
+   ureg_END( ureg );
 
-   return pipe->create_vs_state(pipe, &shader);
+   return ureg_create_shader_and_destroy( ureg );
 }
 
 
@@ -158,99 +94,29 @@ util_make_vertex_passthrough_shader(struct pipe_context *pipe,
 void *
 util_make_fragment_tex_shader(struct pipe_context *pipe)
 {
-   struct pipe_shader_state shader;
-   struct tgsi_token tokens[100];
-   struct tgsi_header *header;
-   struct tgsi_processor *processor;
-   struct tgsi_full_declaration decl;
-   struct tgsi_full_instruction inst;
-   const uint procType = TGSI_PROCESSOR_FRAGMENT;
-   uint ti;
-
-   /* shader header
-    */
-   *(struct tgsi_version *) &tokens[0] = tgsi_build_version();
-
-   header = (struct tgsi_header *) &tokens[1];
-   *header = tgsi_build_header();
-
-   processor = (struct tgsi_processor *) &tokens[2];
-   *processor = tgsi_build_processor( procType, header );
-
-   ti = 3;
-
-   /* declare TEX[0] input */
-   decl = tgsi_default_full_declaration();
-   decl.Declaration.File = TGSI_FILE_INPUT;
-   /* XXX this could be linear... */
-   decl.Declaration.Interpolate = TGSI_INTERPOLATE_PERSPECTIVE;
-   decl.Declaration.Semantic = 1;
-   decl.Semantic.SemanticName = TGSI_SEMANTIC_GENERIC;
-   decl.Semantic.SemanticIndex = 0;
-   decl.DeclarationRange.First = 
-   decl.DeclarationRange.Last = 0;
-   ti += tgsi_build_full_declaration(&decl,
-                                     &tokens[ti],
-                                     header,
-                                     Elements(tokens) - ti);
-
-   /* declare color[0] output */
-   decl = tgsi_default_full_declaration();
-   decl.Declaration.File = TGSI_FILE_OUTPUT;
-   decl.Declaration.Semantic = 1;
-   decl.Semantic.SemanticName = TGSI_SEMANTIC_COLOR;
-   decl.Semantic.SemanticIndex = 0;
-   decl.DeclarationRange.First = 
-   decl.DeclarationRange.Last = 0;
-   ti += tgsi_build_full_declaration(&decl,
-                                     &tokens[ti],
-                                     header,
-                                     Elements(tokens) - ti);
-
-   /* declare sampler */
-   decl = tgsi_default_full_declaration();
-   decl.Declaration.File = TGSI_FILE_SAMPLER;
-   decl.DeclarationRange.First = 
-   decl.DeclarationRange.Last = 0;
-   ti += tgsi_build_full_declaration(&decl,
-                                     &tokens[ti],
-                                     header,
-                                     Elements(tokens) - ti);
-
-   /* TEX instruction */
-   inst = tgsi_default_full_instruction();
-   inst.Instruction.Opcode = TGSI_OPCODE_TEX;
-   inst.Instruction.NumDstRegs = 1;
-   inst.FullDstRegisters[0].DstRegister.File = TGSI_FILE_OUTPUT;
-   inst.FullDstRegisters[0].DstRegister.Index = 0;
-   inst.Instruction.NumSrcRegs = 2;
-   inst.InstructionExtTexture.Texture = TGSI_TEXTURE_2D;
-   inst.FullSrcRegisters[0].SrcRegister.File = TGSI_FILE_INPUT;
-   inst.FullSrcRegisters[0].SrcRegister.Index = 0;
-   inst.FullSrcRegisters[1].SrcRegister.File = TGSI_FILE_SAMPLER;
-   inst.FullSrcRegisters[1].SrcRegister.Index = 0;
-   ti += tgsi_build_full_instruction(&inst,
-                                     &tokens[ti],
-                                     header,
-                                     Elements(tokens) - ti );
-
-   /* END instruction */
-   inst = tgsi_default_full_instruction();
-   inst.Instruction.Opcode = TGSI_OPCODE_END;
-   inst.Instruction.NumDstRegs = 0;
-   inst.Instruction.NumSrcRegs = 0;
-   ti += tgsi_build_full_instruction(&inst,
-                                     &tokens[ti],
-                                     header,
-                                     Elements(tokens) - ti );
-
-#if 0 /*debug*/
-   tgsi_dump(tokens, 0);
-#endif
-
-   shader.tokens = tokens;
-
-   return pipe->create_fs_state(pipe, &shader);
+   struct ureg_program *ureg;
+   struct ureg_src sampler;
+   struct ureg_src tex;
+   struct ureg_dst out;
+
+   ureg = ureg_create( pipe, TGSI_PROCESSOR_FRAGMENT );
+   if (ureg == NULL)
+      return NULL;
+   
+   sampler = ureg_DECL_sampler( ureg );
+
+   tex = ureg_DECL_fs_input( ureg, 
+                             TGSI_SEMANTIC_GENERIC, 0, 
+                             TGSI_INTERPOLATE_PERSPECTIVE );
+
+   out = ureg_DECL_output( ureg, 
+                           TGSI_SEMANTIC_COLOR,
+                           0 );
+
+   ureg_TEX( ureg, out, TGSI_TEXTURE_2D, tex, sampler );
+   ureg_END( ureg );
+
+   return ureg_create_shader_and_destroy( ureg );
 }
 
 
@@ -263,87 +129,23 @@ util_make_fragment_tex_shader(struct pipe_context *pipe)
 void *
 util_make_fragment_passthrough_shader(struct pipe_context *pipe)
 {
-   struct pipe_shader_state shader;
-   struct tgsi_token tokens[40];
-   struct tgsi_header *header;
-   struct tgsi_processor *processor;
-   struct tgsi_full_declaration decl;
-   struct tgsi_full_instruction inst;
-   const uint procType = TGSI_PROCESSOR_FRAGMENT;
-   uint ti;
-
-   /* shader header
-    */
-   *(struct tgsi_version *) &tokens[0] = tgsi_build_version();
-
-   header = (struct tgsi_header *) &tokens[1];
-   *header = tgsi_build_header();
-
-   processor = (struct tgsi_processor *) &tokens[2];
-   *processor = tgsi_build_processor( procType, header );
-
-   ti = 3;
-
-   /* declare input */
-   decl = tgsi_default_full_declaration();
-   decl.Declaration.File = TGSI_FILE_INPUT;
-   decl.Declaration.Semantic = 1;
-   decl.Semantic.SemanticName = TGSI_SEMANTIC_COLOR;
-   decl.Semantic.SemanticIndex = 0;
-   decl.DeclarationRange.First = 
-      decl.DeclarationRange.Last = 0;
-   ti += tgsi_build_full_declaration(&decl,
-                                     &tokens[ti],
-                                     header,
-                                     Elements(tokens) - ti);
-
-   /* declare output */
-   decl = tgsi_default_full_declaration();
-   decl.Declaration.File = TGSI_FILE_OUTPUT;
-   decl.Declaration.Semantic = 1;
-   decl.Semantic.SemanticName = TGSI_SEMANTIC_COLOR;
-   decl.Semantic.SemanticIndex = 0;
-   decl.DeclarationRange.First = 
-      decl.DeclarationRange.Last = 0;
-   ti += tgsi_build_full_declaration(&decl,
-                                     &tokens[ti],
-                                     header,
-                                     Elements(tokens) - ti);
-
-
-   /* MOVE out[0], in[0]; */
-   inst = tgsi_default_full_instruction();
-   inst.Instruction.Opcode = TGSI_OPCODE_MOV;
-   inst.Instruction.NumDstRegs = 1;
-   inst.FullDstRegisters[0].DstRegister.File = TGSI_FILE_OUTPUT;
-   inst.FullDstRegisters[0].DstRegister.Index = 0;
-   inst.Instruction.NumSrcRegs = 1;
-   inst.FullSrcRegisters[0].SrcRegister.File = TGSI_FILE_INPUT;
-   inst.FullSrcRegisters[0].SrcRegister.Index = 0;
-   ti += tgsi_build_full_instruction(&inst,
-                                     &tokens[ti],
-                                     header,
-                                     Elements(tokens) - ti );
-
-   /* END instruction */
-   inst = tgsi_default_full_instruction();
-   inst.Instruction.Opcode = TGSI_OPCODE_END;
-   inst.Instruction.NumDstRegs = 0;
-   inst.Instruction.NumSrcRegs = 0;
-   ti += tgsi_build_full_instruction(&inst,
-                                     &tokens[ti],
-                                     header,
-                                     Elements(tokens) - ti );
-
-   assert(ti < Elements(tokens));
-
-#if 0 /*debug*/
-   tgsi_dump(tokens, 0);
-#endif
-
-   shader.tokens = tokens;
-
-   return pipe->create_fs_state(pipe, &shader);
+   struct ureg_program *ureg;
+   struct ureg_src src;
+   struct ureg_dst dst;
+
+   ureg = ureg_create( pipe, TGSI_PROCESSOR_FRAGMENT );
+   if (ureg == NULL)
+      return NULL;
+
+   src = ureg_DECL_fs_input( ureg, TGSI_SEMANTIC_COLOR, 0, 
+                             TGSI_INTERPOLATE_PERSPECTIVE );
+
+   dst = ureg_DECL_output( ureg, TGSI_SEMANTIC_COLOR, 0 );
+
+   ureg_MOV( ureg, dst, src );
+   ureg_END( ureg );
+
+   return ureg_create_shader_and_destroy( ureg );
 }
 
 




More information about the mesa-commit mailing list