Mesa (master): svga: move temp register index assertions

Brian Paul brianp at kemper.freedesktop.org
Thu Feb 23 14:54:38 UTC 2012


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

Author: Brian Paul <brianp at vmware.com>
Date:   Mon Nov 21 14:53:46 2011 -0700

svga: move temp register index assertions

The assertion recently added in dst_register() was invalid because that
function is also (suprisingly) used to declare constant registers.

Move the assertion to the callers where we're really creating temp
registers and add some code to prevent emitting invalid temp register
indexes for release builds.

Also, update the comment for get_temp().  It didn't return -1 if it
ran out of registers and none of the callers checked for that.

Reviewed-by: Jose Fonseca <jfonseca at vmware.com>

---

 src/gallium/drivers/svga/svga_tgsi_emit.h |    8 ++++++--
 src/gallium/drivers/svga/svga_tgsi_insn.c |   15 +++++++++++----
 2 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/src/gallium/drivers/svga/svga_tgsi_emit.h b/src/gallium/drivers/svga/svga_tgsi_emit.h
index 1769d62..73c4cda 100644
--- a/src/gallium/drivers/svga/svga_tgsi_emit.h
+++ b/src/gallium/drivers/svga/svga_tgsi_emit.h
@@ -256,6 +256,12 @@ inst_token( unsigned opcode )
    return inst;
 }
 
+
+/**
+ * Create an instance of a SVGA3dShaderDestToken.
+ * Note that this function is used to create tokens for output registers,
+ * temp registers AND constants (see emit_def_const()).
+ */
 static INLINE SVGA3dShaderDestToken 
 dst_register( unsigned file,
               int number )
@@ -266,8 +272,6 @@ dst_register( unsigned file,
    assert(number < (1 << 11));
    assert(file <= SVGA3DREG_PREDICATE);
 
-   assert(number < SVGA3D_TEMPREG_MAX);
-
    dest.value = 0;
    dest.num = number;
    dest.type_upper = file >> 3;
diff --git a/src/gallium/drivers/svga/svga_tgsi_insn.c b/src/gallium/drivers/svga/svga_tgsi_insn.c
index 5a9af89..5e6d1fb 100644
--- a/src/gallium/drivers/svga/svga_tgsi_insn.c
+++ b/src/gallium/drivers/svga/svga_tgsi_insn.c
@@ -105,8 +105,12 @@ translate_dst_register( struct svga_shader_emitter *emit,
       break;
 
    default:
-      dest = dst_register( translate_file( reg->Register.File ),
-                           reg->Register.Index );
+      {
+         unsigned index = reg->Register.Index;
+         assert(index < SVGA3D_TEMPREG_MAX);
+         index = MIN2(index, SVGA3D_TEMPREG_MAX - 1);
+         dest = dst_register(translate_file(reg->Register.File), index);
+      }                 
       break;
    }
 
@@ -258,13 +262,16 @@ translate_src_register( const struct svga_shader_emitter *emit,
 
 
 /*
- * Get a temporary register, return -1 if none available
+ * Get a temporary register.
+ * Note: if we exceed the temporary register limit we just use
+ * register SVGA3D_TEMPREG_MAX - 1.
  */
 static INLINE SVGA3dShaderDestToken 
 get_temp( struct svga_shader_emitter *emit )
 {
    int i = emit->nr_hw_temp + emit->internal_temp_count++;
-
+   assert(i < SVGA3D_TEMPREG_MAX);
+   i = MIN2(i, SVGA3D_TEMPREG_MAX - 1);
    return dst_register( SVGA3DREG_TEMP, i );
 }
 




More information about the mesa-commit mailing list