mesa: Branch 'glsl-compiler-1' - 3 commits

Brian Paul brianp at kemper.freedesktop.org
Mon Jan 29 02:02:29 UTC 2007


 docs/shading.html                                       |    1 
 progs/glsl/Makefile                                     |    1 
 progs/glsl/noise.c                                      |  296 ++++++++++++++++
 src/mesa/shader/prog_instruction.c                      |    4 
 src/mesa/shader/prog_instruction.h                      |    4 
 src/mesa/shader/slang/library/slang_common_builtin.gc   |  162 +++-----
 src/mesa/shader/slang/library/slang_common_builtin_gc.h |  114 +++---
 src/mesa/shader/slang/slang_codegen.c                   |    7 
 src/mesa/shader/slang/slang_emit.c                      |    9 
 src/mesa/shader/slang/slang_ir.h                        |    4 
 src/mesa/swrast/s_fragprog.c                            |   45 ++
 src/mesa/tnl/t_vb_arbprogram.c                          |    4 
 12 files changed, 511 insertions(+), 140 deletions(-)

New commits:
diff-tree fc5a7ea5dec3a0a3e01d49559ba3cdad6c62222b (from 7aece10039ad4786d7f85d61ec8614b9f287ea23)
Author: Brian <brian at nostromo.localnet.net>
Date:   Sun Jan 28 19:02:03 2007 -0700

    noise() works now

diff --git a/docs/shading.html b/docs/shading.html
index 9c4feea..c4962a3 100644
--- a/docs/shading.html
+++ b/docs/shading.html
@@ -29,7 +29,6 @@ in Mesa:
 <li>Arrays
 <li>Structs
 <li>Linking of multiple shaders is not supported
-<li>Noise functions
 <li>Not all built-in OpenGL state variables are supported yet.
     Common variables such as gl_ModelViewMatrix and gl_NormalMatrix
     are supported.
diff-tree 7aece10039ad4786d7f85d61ec8614b9f287ea23 (from f94e4f216f56a12b9ea9150950b65e0e24794950)
Author: Brian <brian at nostromo.localnet.net>
Date:   Sun Jan 28 19:01:35 2007 -0700

    noise functions

diff --git a/src/mesa/shader/prog_instruction.c b/src/mesa/shader/prog_instruction.c
index 3de71b8..0523f42 100644
--- a/src/mesa/shader/prog_instruction.c
+++ b/src/mesa/shader/prog_instruction.c
@@ -150,6 +150,10 @@ static const struct instruction_info Ins
    { OPCODE_MIN,    "MIN",   2 },
    { OPCODE_MOV,    "MOV",   1 },
    { OPCODE_MUL,    "MUL",   2 },
+   { OPCODE_NOISE1, "NOISE1", 1 },
+   { OPCODE_NOISE2, "NOISE2", 1 },
+   { OPCODE_NOISE3, "NOISE3", 1 },
+   { OPCODE_NOISE4, "NOISE4", 1 },
    { OPCODE_PK2H,   "PK2H",  1 },
    { OPCODE_PK2US,  "PK2US", 1 },
    { OPCODE_PK4B,   "PK4B",  1 },
diff --git a/src/mesa/shader/prog_instruction.h b/src/mesa/shader/prog_instruction.h
index 83e8d70..3e88b4e 100644
--- a/src/mesa/shader/prog_instruction.h
+++ b/src/mesa/shader/prog_instruction.h
@@ -172,6 +172,10 @@ typedef enum prog_opcode {
    OPCODE_MIN,       /*   X        X       X       X         X   */
    OPCODE_MOV,       /*   X        X       X       X         X   */
    OPCODE_MUL,       /*   X        X       X       X         X   */
+   OPCODE_NOISE1,    /*                                      X   */
+   OPCODE_NOISE2,    /*                                      X   */
+   OPCODE_NOISE3,    /*                                      X   */
+   OPCODE_NOISE4,    /*                                      X   */
    OPCODE_PK2H,      /*                            X             */
    OPCODE_PK2US,     /*                            X             */
    OPCODE_PK4B,      /*                            X             */
diff --git a/src/mesa/shader/slang/library/slang_common_builtin.gc b/src/mesa/shader/slang/library/slang_common_builtin.gc
index 8812a73..e4a5584 100644
--- a/src/mesa/shader/slang/library/slang_common_builtin.gc
+++ b/src/mesa/shader/slang/library/slang_common_builtin.gc
@@ -1699,123 +1699,107 @@ vec4 shadow2DProj (sampler2DShadow sampl
 // AUTHOR: Stefan Gustavson (stegu at itn.liu.se), Nov 26, 2005
 //
 
-float noise1 (float x) {
-    float a;
-    __asm float_noise1 a, x;
-    return a;
+float noise1(const float x)
+{
+   __asm float_noise1 __retVal, x;
 }
 
-float noise1 (vec2 x) {
-    float a;
-    __asm float_noise2 a, x;
-    return a;
-}
 
-float noise1 (vec3 x) {
-    float a;
-    __asm float_noise3 a, x;
-    return a;
+float noise1(const vec2 x)
+{
+    __asm float_noise2 __retVal, x;
 }
 
-float noise1 (vec4 x) {
-    float a;
-    __asm float_noise4 a, x;
-    return a;
+float noise1(const vec3 x)
+{
+    __asm float_noise3 __retVal, x;
 }
 
-vec2 noise2 (float x) {
-    return vec2 (
-        noise1 (x),
-        noise1 (x + 19.34)
-    );
+float noise1(const vec4 x)
+{
+    __asm float_noise4 __retVal, x;
 }
 
-vec2 noise2 (vec2 x) {
-    return vec2 (
-        noise1 (x),
-        noise1 (x + vec2 (19.34, 7.66))
-    );
+vec2 noise2(const float x)
+{
+   __retVal.x = noise1(x);
+   __retVal.y = noise1(x + 19.34);
 }
 
-vec2 noise2 (vec3 x) {
-    return vec2 (
-        noise1 (x),
-        noise1 (x + vec3 (19.34, 7.66, 3.23))
-    );
+vec2 noise2(const vec2 x)
+{
+   __retVal.x = noise1(x);
+   __retVal.y = noise1(x + vec2(19.34, 7.66));
 }
 
-vec2 noise2 (vec4 x) {
-    return vec2 (
-        noise1 (x),
-        noise1 (x + vec4 (19.34, 7.66, 3.23, 2.77))
-    );
+vec2 noise2(const vec3 x)
+{
+   __retVal.x = noise1(x);
+   __retVal.y = noise1(x + vec3(19.34, 7.66, 3.23));
 }
 
-vec3 noise3 (float x) {
-    return vec3 (
-        noise1 (x),
-        noise1 (x + 19.34),
-        noise1 (x + 5.47)
-    );
+vec2 noise2(const vec4 x)
+{
+   __retVal.x = noise1(x);
+   __retVal.y = noise1(x + vec4(19.34, 7.66, 3.23, 2.77));
 }
 
-vec3 noise3 (vec2 x) {
-    return vec3 (
-        noise1 (x),
-        noise1 (x + vec2 (19.34, 7.66)),
-        noise1 (x + vec2 (5.47, 17.85))
-    );
+vec3 noise3(const float x)
+{
+   __retVal.x = noise1(x);
+   __retVal.y = noise1(x + 19.34);
+   __retVal.z = noise1(x + 5.47);
 }
 
-vec3 noise3 (vec3 x) {
-    return vec3 (
-        noise1 (x),
-        noise1 (x + vec3 (19.34, 7.66, 3.23)),
-        noise1 (x + vec3 (5.47, 17.85, 11.04))
-    );
+vec3 noise3(const vec2 x)
+{
+   __retVal.x = noise1(x);
+   __retVal.y = noise1(x + vec2(19.34, 7.66));
+   __retVal.z = noise1(x + vec2(5.47, 17.85));
 }
 
-vec3 noise3 (vec4 x) {
-    return vec3 (
-        noise1 (x),
-        noise1 (x + vec4 (19.34, 7.66, 3.23, 2.77)),
-        noise1 (x + vec4 (5.47, 17.85, 11.04, 13.19))
-    );
+vec3 noise3(const vec3 x)
+{
+   __retVal.x = noise1(x);
+   __retVal.y = noise1(x + vec3(19.34, 7.66, 3.23));
+   __retVal.z = noise1(x + vec3(5.47, 17.85, 11.04));
 }
 
-vec4 noise4 (float x) {
-    return vec4 (
-        noise1 (x),
-        noise1 (x + 19.34),
-        noise1 (x + 5.47),
-        noise1 (x + 23.54)
-    );
+vec3 noise3(const vec4 x)
+{
+   __retVal.x = noise1(x);
+   __retVal.y = noise1(x + vec4(19.34, 7.66, 3.23, 2.77));
+   __retVal.z = noise1(x + vec4(5.47, 17.85, 11.04, 13.19));
 }
 
-vec4 noise4 (vec2 x) {
-    return vec4 (
-        noise1 (x),
-        noise1 (x + vec2 (19.34, 7.66)),
-        noise1 (x + vec2 (5.47, 17.85)),
-        noise1 (x + vec2 (23.54, 29.11))
-    );
+vec4 noise4(const float x)
+{
+   __retVal.x = noise1(x);
+   __retVal.y = noise1(x + 19.34);
+   __retVal.z = noise1(x + 5.47);
+   __retVal.w = noise1(x + 23.54);
 }
 
-vec4 noise4 (vec3 x) {
-    return vec4 (
-        noise1 (x),
-        noise1 (x + vec3 (19.34, 7.66, 3.23)),
-        noise1 (x + vec3 (5.47, 17.85, 11.04)),
-        noise1 (x + vec3 (23.54, 29.11, 31.91))
-    );
+vec4 noise4(const vec2 x)
+{
+   __retVal.x = noise1(x);
+   __retVal.y = noise1(x + vec2 (19.34, 7.66));
+   __retVal.z = noise1(x + vec2 (5.47, 17.85));
+   __retVal.w = noise1(x + vec2 (23.54, 29.11));
 }
 
-vec4 noise4 (vec4 x) {
-    return vec4 (
-        noise1 (x),
-        noise1 (x + vec4 (19.34, 7.66, 3.23, 2.77)),
-        noise1 (x + vec4 (5.47, 17.85, 11.04, 13.19)),
-        noise1 (x + vec4 (23.54, 29.11, 31.91, 37.48))
-    );
+vec4 noise4(const vec3 x)
+{
+   __retVal.x = noise1(x);
+   __retVal.y = noise1(x + vec3(19.34, 7.66, 3.23));
+   __retVal.z = noise1(x + vec3(5.47, 17.85, 11.04));
+   __retVal.w = noise1(x + vec3(23.54, 29.11, 31.91));
 }
 
+vec4 noise4(const vec4 x)
+{
+   __retVal.x = noise1(x);
+   __retVal.y = noise1(x + vec4(19.34, 7.66, 3.23, 2.77));
+   __retVal.z = noise1(x + vec4(5.47, 17.85, 11.04, 13.19));
+   __retVal.w = noise1(x + vec4(23.54, 29.11, 31.91, 37.48));
+}
diff --git a/src/mesa/shader/slang/library/slang_common_builtin_gc.h b/src/mesa/shader/slang/library/slang_common_builtin_gc.h
index 655efdd..e64f401 100644
--- a/src/mesa/shader/slang/library/slang_common_builtin_gc.h
+++ b/src/mesa/shader/slang/library/slang_common_builtin_gc.h
@@ -717,54 +717,68 @@
 100,0,0,0,1,8,58,115,104,97,100,111,119,50,68,0,18,115,97,109,112,108,101,114,0,0,58,118,101,99,51,
 0,18,99,111,111,114,100,0,59,115,0,18,99,111,111,114,100,0,59,113,0,49,0,18,99,111,111,114,100,0,
 59,116,0,18,99,111,111,114,100,0,59,113,0,49,0,18,99,111,111,114,100,0,59,112,0,18,99,111,111,114,
-100,0,59,113,0,49,0,0,0,0,0,0,1,0,9,0,110,111,105,115,101,49,0,1,0,0,9,120,0,0,0,1,3,2,0,9,1,97,0,
-0,0,4,102,108,111,97,116,95,110,111,105,115,101,49,0,18,97,0,0,18,120,0,0,0,8,18,97,0,0,0,1,0,9,0,
-110,111,105,115,101,49,0,1,0,0,10,120,0,0,0,1,3,2,0,9,1,97,0,0,0,4,102,108,111,97,116,95,110,111,
-105,115,101,50,0,18,97,0,0,18,120,0,0,0,8,18,97,0,0,0,1,0,9,0,110,111,105,115,101,49,0,1,0,0,11,
-120,0,0,0,1,3,2,0,9,1,97,0,0,0,4,102,108,111,97,116,95,110,111,105,115,101,51,0,18,97,0,0,18,120,0,
-0,0,8,18,97,0,0,0,1,0,9,0,110,111,105,115,101,49,0,1,0,0,12,120,0,0,0,1,3,2,0,9,1,97,0,0,0,4,102,
-108,111,97,116,95,110,111,105,115,101,52,0,18,97,0,0,18,120,0,0,0,8,18,97,0,0,0,1,0,10,0,110,111,
-105,115,101,50,0,1,0,0,9,120,0,0,0,1,8,58,118,101,99,50,0,58,110,111,105,115,101,49,0,18,120,0,0,0,
-0,58,110,111,105,115,101,49,0,18,120,0,17,49,57,0,51,52,0,0,46,0,0,0,0,0,0,1,0,10,0,110,111,105,
-115,101,50,0,1,0,0,10,120,0,0,0,1,8,58,118,101,99,50,0,58,110,111,105,115,101,49,0,18,120,0,0,0,0,
-58,110,111,105,115,101,49,0,18,120,0,58,118,101,99,50,0,17,49,57,0,51,52,0,0,0,17,55,0,54,54,0,0,0,
-0,46,0,0,0,0,0,0,1,0,10,0,110,111,105,115,101,50,0,1,0,0,11,120,0,0,0,1,8,58,118,101,99,50,0,58,
-110,111,105,115,101,49,0,18,120,0,0,0,0,58,110,111,105,115,101,49,0,18,120,0,58,118,101,99,51,0,17,
-49,57,0,51,52,0,0,0,17,55,0,54,54,0,0,0,17,51,0,50,51,0,0,0,0,46,0,0,0,0,0,0,1,0,10,0,110,111,105,
-115,101,50,0,1,0,0,12,120,0,0,0,1,8,58,118,101,99,50,0,58,110,111,105,115,101,49,0,18,120,0,0,0,0,
-58,110,111,105,115,101,49,0,18,120,0,58,118,101,99,52,0,17,49,57,0,51,52,0,0,0,17,55,0,54,54,0,0,0,
-17,51,0,50,51,0,0,0,17,50,0,55,55,0,0,0,0,46,0,0,0,0,0,0,1,0,11,0,110,111,105,115,101,51,0,1,0,0,9,
-120,0,0,0,1,8,58,118,101,99,51,0,58,110,111,105,115,101,49,0,18,120,0,0,0,0,58,110,111,105,115,101,
-49,0,18,120,0,17,49,57,0,51,52,0,0,46,0,0,0,58,110,111,105,115,101,49,0,18,120,0,17,53,0,52,55,0,0,
-46,0,0,0,0,0,0,1,0,11,0,110,111,105,115,101,51,0,1,0,0,10,120,0,0,0,1,8,58,118,101,99,51,0,58,110,
-111,105,115,101,49,0,18,120,0,0,0,0,58,110,111,105,115,101,49,0,18,120,0,58,118,101,99,50,0,17,49,
-57,0,51,52,0,0,0,17,55,0,54,54,0,0,0,0,46,0,0,0,58,110,111,105,115,101,49,0,18,120,0,58,118,101,99,
-50,0,17,53,0,52,55,0,0,0,17,49,55,0,56,53,0,0,0,0,46,0,0,0,0,0,0,1,0,11,0,110,111,105,115,101,51,0,
-1,0,0,11,120,0,0,0,1,8,58,118,101,99,51,0,58,110,111,105,115,101,49,0,18,120,0,0,0,0,58,110,111,
-105,115,101,49,0,18,120,0,58,118,101,99,51,0,17,49,57,0,51,52,0,0,0,17,55,0,54,54,0,0,0,17,51,0,50,
-51,0,0,0,0,46,0,0,0,58,110,111,105,115,101,49,0,18,120,0,58,118,101,99,51,0,17,53,0,52,55,0,0,0,17,
-49,55,0,56,53,0,0,0,17,49,49,0,48,52,0,0,0,0,46,0,0,0,0,0,0,1,0,11,0,110,111,105,115,101,51,0,1,0,
-0,12,120,0,0,0,1,8,58,118,101,99,51,0,58,110,111,105,115,101,49,0,18,120,0,0,0,0,58,110,111,105,
-115,101,49,0,18,120,0,58,118,101,99,52,0,17,49,57,0,51,52,0,0,0,17,55,0,54,54,0,0,0,17,51,0,50,51,
-0,0,0,17,50,0,55,55,0,0,0,0,46,0,0,0,58,110,111,105,115,101,49,0,18,120,0,58,118,101,99,52,0,17,53,
-0,52,55,0,0,0,17,49,55,0,56,53,0,0,0,17,49,49,0,48,52,0,0,0,17,49,51,0,49,57,0,0,0,0,46,0,0,0,0,0,
-0,1,0,12,0,110,111,105,115,101,52,0,1,0,0,9,120,0,0,0,1,8,58,118,101,99,52,0,58,110,111,105,115,
-101,49,0,18,120,0,0,0,0,58,110,111,105,115,101,49,0,18,120,0,17,49,57,0,51,52,0,0,46,0,0,0,58,110,
-111,105,115,101,49,0,18,120,0,17,53,0,52,55,0,0,46,0,0,0,58,110,111,105,115,101,49,0,18,120,0,17,
-50,51,0,53,52,0,0,46,0,0,0,0,0,0,1,0,12,0,110,111,105,115,101,52,0,1,0,0,10,120,0,0,0,1,8,58,118,
-101,99,52,0,58,110,111,105,115,101,49,0,18,120,0,0,0,0,58,110,111,105,115,101,49,0,18,120,0,58,118,
-101,99,50,0,17,49,57,0,51,52,0,0,0,17,55,0,54,54,0,0,0,0,46,0,0,0,58,110,111,105,115,101,49,0,18,
-120,0,58,118,101,99,50,0,17,53,0,52,55,0,0,0,17,49,55,0,56,53,0,0,0,0,46,0,0,0,58,110,111,105,115,
-101,49,0,18,120,0,58,118,101,99,50,0,17,50,51,0,53,52,0,0,0,17,50,57,0,49,49,0,0,0,0,46,0,0,0,0,0,
-0,1,0,12,0,110,111,105,115,101,52,0,1,0,0,11,120,0,0,0,1,8,58,118,101,99,52,0,58,110,111,105,115,
-101,49,0,18,120,0,0,0,0,58,110,111,105,115,101,49,0,18,120,0,58,118,101,99,51,0,17,49,57,0,51,52,0,
-0,0,17,55,0,54,54,0,0,0,17,51,0,50,51,0,0,0,0,46,0,0,0,58,110,111,105,115,101,49,0,18,120,0,58,118,
-101,99,51,0,17,53,0,52,55,0,0,0,17,49,55,0,56,53,0,0,0,17,49,49,0,48,52,0,0,0,0,46,0,0,0,58,110,
-111,105,115,101,49,0,18,120,0,58,118,101,99,51,0,17,50,51,0,53,52,0,0,0,17,50,57,0,49,49,0,0,0,17,
-51,49,0,57,49,0,0,0,0,46,0,0,0,0,0,0,1,0,12,0,110,111,105,115,101,52,0,1,0,0,12,120,0,0,0,1,8,58,
-118,101,99,52,0,58,110,111,105,115,101,49,0,18,120,0,0,0,0,58,110,111,105,115,101,49,0,18,120,0,58,
+100,0,59,113,0,49,0,0,0,0,0,0,1,0,9,0,110,111,105,115,101,49,0,1,1,0,9,120,0,0,0,1,4,102,108,111,
+97,116,95,110,111,105,115,101,49,0,18,95,95,114,101,116,86,97,108,0,0,18,120,0,0,0,0,1,0,9,0,110,
+111,105,115,101,49,0,1,1,0,10,120,0,0,0,1,4,102,108,111,97,116,95,110,111,105,115,101,50,0,18,95,
+95,114,101,116,86,97,108,0,0,18,120,0,0,0,0,1,0,9,0,110,111,105,115,101,49,0,1,1,0,11,120,0,0,0,1,
+4,102,108,111,97,116,95,110,111,105,115,101,51,0,18,95,95,114,101,116,86,97,108,0,0,18,120,0,0,0,0,
+1,0,9,0,110,111,105,115,101,49,0,1,1,0,12,120,0,0,0,1,4,102,108,111,97,116,95,110,111,105,115,101,
+52,0,18,95,95,114,101,116,86,97,108,0,0,18,120,0,0,0,0,1,0,10,0,110,111,105,115,101,50,0,1,1,0,9,
+120,0,0,0,1,9,18,95,95,114,101,116,86,97,108,0,59,120,0,58,110,111,105,115,101,49,0,18,120,0,0,0,
+20,0,9,18,95,95,114,101,116,86,97,108,0,59,121,0,58,110,111,105,115,101,49,0,18,120,0,17,49,57,0,
+51,52,0,0,46,0,0,20,0,0,1,0,10,0,110,111,105,115,101,50,0,1,1,0,10,120,0,0,0,1,9,18,95,95,114,101,
+116,86,97,108,0,59,120,0,58,110,111,105,115,101,49,0,18,120,0,0,0,20,0,9,18,95,95,114,101,116,86,
+97,108,0,59,121,0,58,110,111,105,115,101,49,0,18,120,0,58,118,101,99,50,0,17,49,57,0,51,52,0,0,0,
+17,55,0,54,54,0,0,0,0,46,0,0,20,0,0,1,0,10,0,110,111,105,115,101,50,0,1,1,0,11,120,0,0,0,1,9,18,95,
+95,114,101,116,86,97,108,0,59,120,0,58,110,111,105,115,101,49,0,18,120,0,0,0,20,0,9,18,95,95,114,
+101,116,86,97,108,0,59,121,0,58,110,111,105,115,101,49,0,18,120,0,58,118,101,99,51,0,17,49,57,0,51,
+52,0,0,0,17,55,0,54,54,0,0,0,17,51,0,50,51,0,0,0,0,46,0,0,20,0,0,1,0,10,0,110,111,105,115,101,50,0,
+1,1,0,12,120,0,0,0,1,9,18,95,95,114,101,116,86,97,108,0,59,120,0,58,110,111,105,115,101,49,0,18,
+120,0,0,0,20,0,9,18,95,95,114,101,116,86,97,108,0,59,121,0,58,110,111,105,115,101,49,0,18,120,0,58,
 118,101,99,52,0,17,49,57,0,51,52,0,0,0,17,55,0,54,54,0,0,0,17,51,0,50,51,0,0,0,17,50,0,55,55,0,0,0,
-0,46,0,0,0,58,110,111,105,115,101,49,0,18,120,0,58,118,101,99,52,0,17,53,0,52,55,0,0,0,17,49,55,0,
-56,53,0,0,0,17,49,49,0,48,52,0,0,0,17,49,51,0,49,57,0,0,0,0,46,0,0,0,58,110,111,105,115,101,49,0,
-18,120,0,58,118,101,99,52,0,17,50,51,0,53,52,0,0,0,17,50,57,0,49,49,0,0,0,17,51,49,0,57,49,0,0,0,
-17,51,55,0,52,56,0,0,0,0,46,0,0,0,0,0,0,0
+0,46,0,0,20,0,0,1,0,11,0,110,111,105,115,101,51,0,1,1,0,9,120,0,0,0,1,9,18,95,95,114,101,116,86,97,
+108,0,59,120,0,58,110,111,105,115,101,49,0,18,120,0,0,0,20,0,9,18,95,95,114,101,116,86,97,108,0,59,
+121,0,58,110,111,105,115,101,49,0,18,120,0,17,49,57,0,51,52,0,0,46,0,0,20,0,9,18,95,95,114,101,116,
+86,97,108,0,59,122,0,58,110,111,105,115,101,49,0,18,120,0,17,53,0,52,55,0,0,46,0,0,20,0,0,1,0,11,0,
+110,111,105,115,101,51,0,1,1,0,10,120,0,0,0,1,9,18,95,95,114,101,116,86,97,108,0,59,120,0,58,110,
+111,105,115,101,49,0,18,120,0,0,0,20,0,9,18,95,95,114,101,116,86,97,108,0,59,121,0,58,110,111,105,
+115,101,49,0,18,120,0,58,118,101,99,50,0,17,49,57,0,51,52,0,0,0,17,55,0,54,54,0,0,0,0,46,0,0,20,0,
+9,18,95,95,114,101,116,86,97,108,0,59,122,0,58,110,111,105,115,101,49,0,18,120,0,58,118,101,99,50,
+0,17,53,0,52,55,0,0,0,17,49,55,0,56,53,0,0,0,0,46,0,0,20,0,0,1,0,11,0,110,111,105,115,101,51,0,1,1,
+0,11,120,0,0,0,1,9,18,95,95,114,101,116,86,97,108,0,59,120,0,58,110,111,105,115,101,49,0,18,120,0,
+0,0,20,0,9,18,95,95,114,101,116,86,97,108,0,59,121,0,58,110,111,105,115,101,49,0,18,120,0,58,118,
+101,99,51,0,17,49,57,0,51,52,0,0,0,17,55,0,54,54,0,0,0,17,51,0,50,51,0,0,0,0,46,0,0,20,0,9,18,95,
+95,114,101,116,86,97,108,0,59,122,0,58,110,111,105,115,101,49,0,18,120,0,58,118,101,99,51,0,17,53,
+0,52,55,0,0,0,17,49,55,0,56,53,0,0,0,17,49,49,0,48,52,0,0,0,0,46,0,0,20,0,0,1,0,11,0,110,111,105,
+115,101,51,0,1,1,0,12,120,0,0,0,1,9,18,95,95,114,101,116,86,97,108,0,59,120,0,58,110,111,105,115,
+101,49,0,18,120,0,0,0,20,0,9,18,95,95,114,101,116,86,97,108,0,59,121,0,58,110,111,105,115,101,49,0,
+18,120,0,58,118,101,99,52,0,17,49,57,0,51,52,0,0,0,17,55,0,54,54,0,0,0,17,51,0,50,51,0,0,0,17,50,0,
+55,55,0,0,0,0,46,0,0,20,0,9,18,95,95,114,101,116,86,97,108,0,59,122,0,58,110,111,105,115,101,49,0,
+18,120,0,58,118,101,99,52,0,17,53,0,52,55,0,0,0,17,49,55,0,56,53,0,0,0,17,49,49,0,48,52,0,0,0,17,
+49,51,0,49,57,0,0,0,0,46,0,0,20,0,0,1,0,12,0,110,111,105,115,101,52,0,1,1,0,9,120,0,0,0,1,9,18,95,
+95,114,101,116,86,97,108,0,59,120,0,58,110,111,105,115,101,49,0,18,120,0,0,0,20,0,9,18,95,95,114,
+101,116,86,97,108,0,59,121,0,58,110,111,105,115,101,49,0,18,120,0,17,49,57,0,51,52,0,0,46,0,0,20,0,
+9,18,95,95,114,101,116,86,97,108,0,59,122,0,58,110,111,105,115,101,49,0,18,120,0,17,53,0,52,55,0,0,
+46,0,0,20,0,9,18,95,95,114,101,116,86,97,108,0,59,119,0,58,110,111,105,115,101,49,0,18,120,0,17,50,
+51,0,53,52,0,0,46,0,0,20,0,0,1,0,12,0,110,111,105,115,101,52,0,1,1,0,10,120,0,0,0,1,9,18,95,95,114,
+101,116,86,97,108,0,59,120,0,58,110,111,105,115,101,49,0,18,120,0,0,0,20,0,9,18,95,95,114,101,116,
+86,97,108,0,59,121,0,58,110,111,105,115,101,49,0,18,120,0,58,118,101,99,50,0,17,49,57,0,51,52,0,0,
+0,17,55,0,54,54,0,0,0,0,46,0,0,20,0,9,18,95,95,114,101,116,86,97,108,0,59,122,0,58,110,111,105,115,
+101,49,0,18,120,0,58,118,101,99,50,0,17,53,0,52,55,0,0,0,17,49,55,0,56,53,0,0,0,0,46,0,0,20,0,9,18,
+95,95,114,101,116,86,97,108,0,59,119,0,58,110,111,105,115,101,49,0,18,120,0,58,118,101,99,50,0,17,
+50,51,0,53,52,0,0,0,17,50,57,0,49,49,0,0,0,0,46,0,0,20,0,0,1,0,12,0,110,111,105,115,101,52,0,1,1,0,
+11,120,0,0,0,1,9,18,95,95,114,101,116,86,97,108,0,59,120,0,58,110,111,105,115,101,49,0,18,120,0,0,
+0,20,0,9,18,95,95,114,101,116,86,97,108,0,59,121,0,58,110,111,105,115,101,49,0,18,120,0,58,118,101,
+99,51,0,17,49,57,0,51,52,0,0,0,17,55,0,54,54,0,0,0,17,51,0,50,51,0,0,0,0,46,0,0,20,0,9,18,95,95,
+114,101,116,86,97,108,0,59,122,0,58,110,111,105,115,101,49,0,18,120,0,58,118,101,99,51,0,17,53,0,
+52,55,0,0,0,17,49,55,0,56,53,0,0,0,17,49,49,0,48,52,0,0,0,0,46,0,0,20,0,9,18,95,95,114,101,116,86,
+97,108,0,59,119,0,58,110,111,105,115,101,49,0,18,120,0,58,118,101,99,51,0,17,50,51,0,53,52,0,0,0,
+17,50,57,0,49,49,0,0,0,17,51,49,0,57,49,0,0,0,0,46,0,0,20,0,0,1,0,12,0,110,111,105,115,101,52,0,1,
+1,0,12,120,0,0,0,1,9,18,95,95,114,101,116,86,97,108,0,59,120,0,58,110,111,105,115,101,49,0,18,120,
+0,0,0,20,0,9,18,95,95,114,101,116,86,97,108,0,59,121,0,58,110,111,105,115,101,49,0,18,120,0,58,118,
+101,99,52,0,17,49,57,0,51,52,0,0,0,17,55,0,54,54,0,0,0,17,51,0,50,51,0,0,0,17,50,0,55,55,0,0,0,0,
+46,0,0,20,0,9,18,95,95,114,101,116,86,97,108,0,59,122,0,58,110,111,105,115,101,49,0,18,120,0,58,
+118,101,99,52,0,17,53,0,52,55,0,0,0,17,49,55,0,56,53,0,0,0,17,49,49,0,48,52,0,0,0,17,49,51,0,49,57,
+0,0,0,0,46,0,0,20,0,9,18,95,95,114,101,116,86,97,108,0,59,119,0,58,110,111,105,115,101,49,0,18,120,
+0,58,118,101,99,52,0,17,50,51,0,53,52,0,0,0,17,50,57,0,49,49,0,0,0,17,51,49,0,57,49,0,0,0,17,51,55,
+0,52,56,0,0,0,0,46,0,0,20,0,0,0
diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c
index 6ae307d..9b932ca 100644
--- a/src/mesa/shader/slang/slang_codegen.c
+++ b/src/mesa/shader/slang/slang_codegen.c
@@ -494,6 +494,11 @@ static slang_asm_info AsmInfo[] = {
    { "float_rcp", IR_RCP, 1, 1 },
    { "float_sine", IR_SIN, 1, 1 },
    { "float_cosine", IR_COS, 1, 1 },
+   { "float_noise1", IR_NOISE1, 1, 1},
+   { "float_noise2", IR_NOISE2, 1, 1},
+   { "float_noise3", IR_NOISE3, 1, 1},
+   { "float_noise4", IR_NOISE4, 1, 1},
+
    { NULL, IR_NOP, 0, 0 }
 };
 
@@ -1657,6 +1662,8 @@ _slang_gen_var_decl(slang_assemble_ctx *
 
 /**
  * Generate code for a selection expression:   b ? x : y
+ * XXX in some cases we could implement a selection expression
+ * with an LRP instruction (use the boolean as the interpolant).
  */
 static slang_ir_node *
 _slang_gen_select(slang_assemble_ctx *A, slang_operation *oper)
diff --git a/src/mesa/shader/slang/slang_emit.c b/src/mesa/shader/slang/slang_emit.c
index 092c53b..8e598bf 100644
--- a/src/mesa/shader/slang/slang_emit.c
+++ b/src/mesa/shader/slang/slang_emit.c
@@ -89,6 +89,11 @@ static slang_ir_info IrInfo[] = {
    { IR_DDX, "IR_DDY", OPCODE_DDX, 4, 1 },
    { IR_SIN, "IR_SIN", OPCODE_SIN, 1, 1 },
    { IR_COS, "IR_COS", OPCODE_COS, 1, 1 },
+   { IR_NOISE1, "IR_NOISE1", OPCODE_NOISE1, 1, 1 },
+   { IR_NOISE2, "IR_NOISE2", OPCODE_NOISE2, 1, 1 },
+   { IR_NOISE3, "IR_NOISE3", OPCODE_NOISE3, 1, 1 },
+   { IR_NOISE4, "IR_NOISE4", OPCODE_NOISE4, 1, 1 },
+
    /* other */
    { IR_SEQ, "IR_SEQ", OPCODE_NOP, 0, 0 },
    { IR_SCOPE, "IR_SCOPE", OPCODE_NOP, 0, 0 },
@@ -994,6 +999,10 @@ emit(slang_var_table *vt, slang_ir_node 
    case IR_COS:
    case IR_DDX:
    case IR_DDY:
+   case IR_NOISE1:
+   case IR_NOISE2:
+   case IR_NOISE3:
+   case IR_NOISE4:
    /* binary */
    case IR_ADD:
    case IR_SUB:
diff --git a/src/mesa/shader/slang/slang_ir.h b/src/mesa/shader/slang/slang_ir.h
index 5617c56..39b4ab6 100644
--- a/src/mesa/shader/slang/slang_ir.h
+++ b/src/mesa/shader/slang/slang_ir.h
@@ -84,6 +84,10 @@ typedef enum
    IR_DDY,     /* derivative w.r.t. Y */
    IR_SIN,     /* sine */
    IR_COS,     /* cosine */
+   IR_NOISE1,  /* noise(x) */
+   IR_NOISE2,  /* noise(x, y) */
+   IR_NOISE3,  /* noise(x, y, z) */
+   IR_NOISE4,  /* noise(x, y, z, w) */
    IR_NOT,     /* logical not */
    IR_VAR,     /* variable reference */
    IR_VAR_DECL,/* var declaration */
diff --git a/src/mesa/swrast/s_fragprog.c b/src/mesa/swrast/s_fragprog.c
index 74250b3..ab1e586 100644
--- a/src/mesa/swrast/s_fragprog.c
+++ b/src/mesa/swrast/s_fragprog.c
@@ -32,6 +32,7 @@
 
 #include "s_fragprog.h"
 #include "s_span.h"
+#include "slang_library_noise.h"
 
 
 /* See comments below for info about this */
@@ -1133,6 +1134,50 @@ execute_program( GLcontext *ctx,
                }
             }
             break;
+         case OPCODE_NOISE1:
+            {
+               GLfloat a[4], result[4];
+               fetch_vector1( ctx, &inst->SrcReg[0], machine, program, a );
+               result[0] =
+               result[1] =
+               result[2] =
+               result[3] = _slang_library_noise1(a[0]);
+               store_vector4( inst, machine, result );
+            }
+            break;
+         case OPCODE_NOISE2:
+            {
+               GLfloat a[4], result[4];
+               fetch_vector4( ctx, &inst->SrcReg[0], machine, program, a );
+               result[0] =
+               result[1] =
+               result[2] =
+               result[3] = _slang_library_noise2(a[0], a[1]);
+               store_vector4( inst, machine, result );
+            }
+            break;
+         case OPCODE_NOISE3:
+            {
+               GLfloat a[4], result[4];
+               fetch_vector4( ctx, &inst->SrcReg[0], machine, program, a );
+               result[0] =
+               result[1] =
+               result[2] =
+               result[3] = _slang_library_noise3(a[0], a[1], a[2]);
+               store_vector4( inst, machine, result );
+            }
+            break;
+         case OPCODE_NOISE4:
+            {
+               GLfloat a[4], result[4];
+               fetch_vector4( ctx, &inst->SrcReg[0], machine, program, a );
+               result[0] =
+               result[1] =
+               result[2] =
+               result[3] = _slang_library_noise4(a[0], a[1], a[2], a[3]);
+               store_vector4( inst, machine, result );
+            }
+            break;
          case OPCODE_NOP:
             break;
          case OPCODE_PK2H: /* pack two 16-bit floats in one 32-bit float */
diff --git a/src/mesa/tnl/t_vb_arbprogram.c b/src/mesa/tnl/t_vb_arbprogram.c
index 5726a66..22b6089 100644
--- a/src/mesa/tnl/t_vb_arbprogram.c
+++ b/src/mesa/tnl/t_vb_arbprogram.c
@@ -766,6 +766,10 @@ static void (* const opcode_func[MAX_OPC
    do_MIN,
    do_MOV,
    do_MUL,
+   do_NOP,/*NOISE1*/
+   do_NOP,/*NOISE2*/
+   do_NOP,/*NOISE3*/
+   do_NOP,/*NOISE4*/
    do_NOP,/*PK2H*/
    do_NOP,/*PK2US*/
    do_NOP,/*PK4B*/
diff-tree f94e4f216f56a12b9ea9150950b65e0e24794950 (from a06f92936272dba3da4329a30ae3f08924428106)
Author: Brian <brian at nostromo.localnet.net>
Date:   Sun Jan 28 19:01:04 2007 -0700

    simple noise test

diff --git a/progs/glsl/Makefile b/progs/glsl/Makefile
index fa7f191..9ffffea 100644
--- a/progs/glsl/Makefile
+++ b/progs/glsl/Makefile
@@ -17,6 +17,7 @@ PROGS = \
 	brick \
 	bump \
 	mandelbrot \
+	noise \
 	toyball
 
 
diff --git a/progs/glsl/noise.c b/progs/glsl/noise.c
new file mode 100644
index 0000000..e115da3
--- /dev/null
+++ b/progs/glsl/noise.c
@@ -0,0 +1,296 @@
+/**
+ * Test noise() functions.
+ * 28 Jan 2007
+ */
+
+#include <assert.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include <GL/gl.h>
+#include <GL/glut.h>
+#include <GL/glext.h>
+#include "extfuncs.h"
+
+
+static const char *VertShaderText =
+   "void main() {\n"
+   "   gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
+   "}\n";
+
+static const char *FragShaderText =
+   "uniform vec4 Scale, Bias;\n"
+   "uniform float Slice;\n"
+   "void main()\n"
+   "{\n"
+   "   vec4 scale = vec4(5.0);\n"
+   "   vec4 p;\n"
+   "   p.xy = gl_TexCoord[0].xy;\n"
+   "   p.z = Slice;\n"
+   "   vec4 n = noise4(p * scale);\n"
+   "   gl_FragColor = n * Scale + Bias;\n"
+   "}\n";
+
+
+struct uniform_info {
+   const char *name;
+   GLuint size;
+   GLint location;
+   GLfloat value[4];
+};
+
+static struct uniform_info Uniforms[] = {
+   { "Scale",          4, -1, { 0.5, 0.4, 0.0, 0} },
+   { "Bias",           4, -1, { 0.5, 0.3, 0.0, 0} },
+   { "Slice",          1, -1, { 0.5, 0, 0, 0} },
+   { NULL, 0, 0, { 0, 0, 0, 0 } }
+};
+
+/* program/shader objects */
+static GLuint fragShader;
+static GLuint vertShader;
+static GLuint program;
+
+static GLint win = 0;
+static GLfloat xRot = 0.0f, yRot = 0.0f, zRot = 0.0f;
+static GLfloat Slice = 0.0;
+static GLboolean Anim = GL_FALSE;
+
+
+static void
+Idle(void)
+{
+   Slice += 0.01;
+   glutPostRedisplay();
+}
+
+
+static void
+Redisplay(void)
+{
+   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+   
+   glUniform1fv_func(Uniforms[2].location, 1, &Slice);
+
+   glPushMatrix();
+   glRotatef(xRot, 1.0f, 0.0f, 0.0f);
+   glRotatef(yRot, 0.0f, 1.0f, 0.0f);
+   glRotatef(zRot, 0.0f, 0.0f, 1.0f);
+
+   glBegin(GL_POLYGON);
+   glTexCoord2f(0, 0);   glVertex2f(-2, -2);
+   glTexCoord2f(1, 0);   glVertex2f( 2, -2);
+   glTexCoord2f(1, 1);   glVertex2f( 2,  2);
+   glTexCoord2f(0, 1);   glVertex2f(-2,  2);
+   glEnd();
+
+   glPopMatrix();
+
+   glutSwapBuffers();
+}
+
+
+static void
+Reshape(int width, int height)
+{
+   glViewport(0, 0, width, height);
+   glMatrixMode(GL_PROJECTION);
+   glLoadIdentity();
+   glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0);
+   glMatrixMode(GL_MODELVIEW);
+   glLoadIdentity();
+   glTranslatef(0.0f, 0.0f, -15.0f);
+}
+
+
+static void
+CleanUp(void)
+{
+   glDeleteShader_func(fragShader);
+   glDeleteShader_func(vertShader);
+   glDeleteProgram_func(program);
+   glutDestroyWindow(win);
+}
+
+
+static void
+Key(unsigned char key, int x, int y)
+{
+   const GLfloat step = 0.01;
+  (void) x;
+  (void) y;
+
+   switch(key) {
+   case 'a':
+      Anim = !Anim;
+      glutIdleFunc(Anim ? Idle : NULL);
+   case 's':
+      Slice -= step;
+      break;
+   case 'S':
+      Slice += step;
+      break;
+   case 'z':
+      zRot -= 1.0;
+      break;
+   case 'Z':
+      zRot += 1.0;
+      break;
+   case 27:
+      CleanUp();
+      exit(0);
+      break;
+   }
+   glutPostRedisplay();
+}
+
+
+static void
+SpecialKey(int key, int x, int y)
+{
+   const GLfloat step = 3.0f;
+
+  (void) x;
+  (void) y;
+
+   switch(key) {
+   case GLUT_KEY_UP:
+      xRot -= step;
+      break;
+   case GLUT_KEY_DOWN:
+      xRot += step;
+      break;
+   case GLUT_KEY_LEFT:
+      yRot -= step;
+      break;
+   case GLUT_KEY_RIGHT:
+      yRot += step;
+      break;
+   }
+   glutPostRedisplay();
+}
+
+
+
+static void
+LoadAndCompileShader(GLuint shader, const char *text)
+{
+   GLint stat;
+
+   glShaderSource_func(shader, 1, (const GLchar **) &text, NULL);
+
+   glCompileShader_func(shader);
+
+   glGetShaderiv_func(shader, GL_COMPILE_STATUS, &stat);
+   if (!stat) {
+      GLchar log[1000];
+      GLsizei len;
+      glGetShaderInfoLog_func(shader, 1000, &len, log);
+      fprintf(stderr, "brick: problem compiling shader: %s\n", log);
+      exit(1);
+   }
+   else {
+      printf("Shader compiled OK\n");
+   }
+}
+
+
+static void
+CheckLink(GLuint prog)
+{
+   GLint stat;
+   glGetProgramiv_func(prog, GL_LINK_STATUS, &stat);
+   if (!stat) {
+      GLchar log[1000];
+      GLsizei len;
+      glGetProgramInfoLog_func(prog, 1000, &len, log);
+      fprintf(stderr, "Linker error:\n%s\n", log);
+   }
+   else {
+      fprintf(stderr, "Link success!\n");
+   }
+}
+
+
+static void
+Init(void)
+{
+   const char *version;
+   GLint i;
+
+   version = (const char *) glGetString(GL_VERSION);
+   if (version[0] != '2' || version[1] != '.') {
+      printf("Warning: this program expects OpenGL 2.0\n");
+      /*exit(1);*/
+   }
+
+   GetExtensionFuncs();
+
+   vertShader = glCreateShader_func(GL_VERTEX_SHADER);
+   LoadAndCompileShader(vertShader, VertShaderText);
+
+   fragShader = glCreateShader_func(GL_FRAGMENT_SHADER);
+   LoadAndCompileShader(fragShader, FragShaderText);
+
+   program = glCreateProgram_func();
+   glAttachShader_func(program, fragShader);
+   glAttachShader_func(program, vertShader);
+   glLinkProgram_func(program);
+   CheckLink(program);
+   glUseProgram_func(program);
+
+   for (i = 0; Uniforms[i].name; i++) {
+      Uniforms[i].location
+         = glGetUniformLocation_func(program, Uniforms[i].name);
+      printf("Uniform %s location: %d\n", Uniforms[i].name,
+             Uniforms[i].location);
+      switch (Uniforms[i].size) {
+      case 1:
+         glUniform1fv_func(Uniforms[i].location, 1, Uniforms[i].value);
+         break;
+      case 2:
+         glUniform2fv_func(Uniforms[i].location, 1, Uniforms[i].value);
+         break;
+      case 3:
+         glUniform3fv_func(Uniforms[i].location, 1, Uniforms[i].value);
+         break;
+      case 4:
+         glUniform4fv_func(Uniforms[i].location, 1, Uniforms[i].value);
+         break;
+      default:
+         abort();
+      }
+   }
+
+   assert(glGetError() == 0);
+
+   glClearColor(0.4f, 0.4f, 0.8f, 0.0f);
+
+   printf("GL_RENDERER = %s\n",(const char *) glGetString(GL_RENDERER));
+
+   assert(glIsProgram_func(program));
+   assert(glIsShader_func(fragShader));
+   assert(glIsShader_func(vertShader));
+
+   glColor3f(1, 0, 0);
+}
+
+
+int
+main(int argc, char *argv[])
+{
+   glutInit(&argc, argv);
+   glutInitWindowPosition( 0, 0);
+   glutInitWindowSize(400, 400);
+   glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
+   win = glutCreateWindow(argv[0]);
+   glutReshapeFunc(Reshape);
+   glutKeyboardFunc(Key);
+   glutSpecialFunc(SpecialKey);
+   glutDisplayFunc(Redisplay);
+   Init();
+   glutMainLoop();
+   return 0;
+}
+



More information about the mesa-commit mailing list