summaryrefslogtreecommitdiff
path: root/src/mesa/shader
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesa/shader')
-rw-r--r--src/mesa/shader/arbprogparse.c6
-rw-r--r--src/mesa/shader/arbprogparse.h2
-rw-r--r--src/mesa/shader/arbprogram.c12
-rw-r--r--src/mesa/shader/atifragshader.c14
-rw-r--r--src/mesa/shader/grammar/grammar_mesa.h2
-rw-r--r--src/mesa/shader/nvfragparse.c8
-rw-r--r--src/mesa/shader/nvprogram.c10
-rw-r--r--src/mesa/shader/nvvertparse.c8
-rw-r--r--src/mesa/shader/prog_debug.c6
-rw-r--r--src/mesa/shader/prog_execute.c6
-rw-r--r--src/mesa/shader/prog_instruction.c6
-rw-r--r--src/mesa/shader/prog_parameter.c6
-rw-r--r--src/mesa/shader/prog_parameter.h2
-rw-r--r--src/mesa/shader/prog_print.c6
-rw-r--r--src/mesa/shader/prog_statevars.c12
-rw-r--r--src/mesa/shader/prog_statevars.h2
-rw-r--r--src/mesa/shader/program.c6
-rw-r--r--src/mesa/shader/program.h2
-rw-r--r--src/mesa/shader/programopt.c4
-rw-r--r--src/mesa/shader/shader_api.c17
-rw-r--r--src/mesa/shader/shader_api.h4
-rw-r--r--src/mesa/shader/slang/library/slang_120_core.gc50
-rw-r--r--src/mesa/shader/slang/library/slang_120_core_gc.h22
-rw-r--r--src/mesa/shader/slang/library/slang_core.gc24
-rw-r--r--src/mesa/shader/slang/library/slang_core_gc.h18
-rw-r--r--src/mesa/shader/slang/slang_codegen.c249
-rw-r--r--src/mesa/shader/slang/slang_codegen.h2
-rw-r--r--src/mesa/shader/slang/slang_compile.c77
-rw-r--r--src/mesa/shader/slang/slang_compile.h4
-rw-r--r--src/mesa/shader/slang/slang_compile_function.c2
-rw-r--r--src/mesa/shader/slang/slang_compile_operation.c2
-rw-r--r--src/mesa/shader/slang/slang_compile_struct.c2
-rw-r--r--src/mesa/shader/slang/slang_compile_variable.c24
-rw-r--r--src/mesa/shader/slang/slang_emit.c70
-rw-r--r--src/mesa/shader/slang/slang_emit.h4
-rw-r--r--src/mesa/shader/slang/slang_ir.c4
-rw-r--r--src/mesa/shader/slang/slang_ir.h4
-rw-r--r--src/mesa/shader/slang/slang_library_noise.c2
-rw-r--r--src/mesa/shader/slang/slang_link.c11
-rw-r--r--src/mesa/shader/slang/slang_log.c2
-rw-r--r--src/mesa/shader/slang/slang_mem.c4
-rw-r--r--src/mesa/shader/slang/slang_mem.h2
-rw-r--r--src/mesa/shader/slang/slang_preprocess.c2
-rw-r--r--src/mesa/shader/slang/slang_print.c2
-rw-r--r--src/mesa/shader/slang/slang_simplify.c278
-rw-r--r--src/mesa/shader/slang/slang_simplify.h28
-rw-r--r--src/mesa/shader/slang/slang_storage.c2
-rw-r--r--src/mesa/shader/slang/slang_typeinfo.c100
-rw-r--r--src/mesa/shader/slang/slang_typeinfo.h7
-rw-r--r--src/mesa/shader/slang/slang_utility.c2
50 files changed, 643 insertions, 498 deletions
diff --git a/src/mesa/shader/arbprogparse.c b/src/mesa/shader/arbprogparse.c
index ff583352ce..78cc6aa9cc 100644
--- a/src/mesa/shader/arbprogparse.c
+++ b/src/mesa/shader/arbprogparse.c
@@ -38,9 +38,9 @@
#include "programopt.h"
#include "prog_parameter.h"
#include "prog_statevars.h"
-#include "context.h"
-#include "macros.h"
-#include "mtypes.h"
+#include "main/context.h"
+#include "main/macros.h"
+#include "main/mtypes.h"
#include "prog_instruction.h"
diff --git a/src/mesa/shader/arbprogparse.h b/src/mesa/shader/arbprogparse.h
index 4574e5cd55..980d39fb9f 100644
--- a/src/mesa/shader/arbprogparse.h
+++ b/src/mesa/shader/arbprogparse.h
@@ -26,7 +26,7 @@
#ifndef ARBPROGPARSE_H
#define ARBPROGPARSE_H
-#include "mtypes.h"
+#include "main/mtypes.h"
extern void
_mesa_parse_arb_vertex_program(GLcontext *ctx, GLenum target,
diff --git a/src/mesa/shader/arbprogram.c b/src/mesa/shader/arbprogram.c
index 81c20a0150..beb5deea50 100644
--- a/src/mesa/shader/arbprogram.c
+++ b/src/mesa/shader/arbprogram.c
@@ -29,14 +29,14 @@
*/
-#include "glheader.h"
+#include "main/glheader.h"
#include "arbprogram.h"
#include "arbprogparse.h"
-#include "context.h"
-#include "hash.h"
-#include "imports.h"
-#include "macros.h"
-#include "mtypes.h"
+#include "main/context.h"
+#include "main/hash.h"
+#include "main/imports.h"
+#include "main/macros.h"
+#include "main/mtypes.h"
#include "program.h"
diff --git a/src/mesa/shader/atifragshader.c b/src/mesa/shader/atifragshader.c
index 854c911874..ac087d415c 100644
--- a/src/mesa/shader/atifragshader.c
+++ b/src/mesa/shader/atifragshader.c
@@ -21,13 +21,13 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-#include "glheader.h"
-#include "context.h"
-#include "hash.h"
-#include "imports.h"
-#include "macros.h"
-#include "enums.h"
-#include "mtypes.h"
+#include "main/glheader.h"
+#include "main/context.h"
+#include "main/hash.h"
+#include "main/imports.h"
+#include "main/macros.h"
+#include "main/enums.h"
+#include "main/mtypes.h"
#include "atifragshader.h"
#define MESA_DEBUG_ATI_FS 0
diff --git a/src/mesa/shader/grammar/grammar_mesa.h b/src/mesa/shader/grammar/grammar_mesa.h
index c14033a9d4..6c92c5812d 100644
--- a/src/mesa/shader/grammar/grammar_mesa.h
+++ b/src/mesa/shader/grammar/grammar_mesa.h
@@ -26,7 +26,7 @@
#define GRAMMAR_MESA_H
-#include "imports.h"
+#include "main/imports.h"
/* NOTE: include Mesa 3-D specific headers here */
diff --git a/src/mesa/shader/nvfragparse.c b/src/mesa/shader/nvfragparse.c
index 0f1a1eade4..a2a7a5f3f4 100644
--- a/src/mesa/shader/nvfragparse.c
+++ b/src/mesa/shader/nvfragparse.c
@@ -37,10 +37,10 @@
* including any use thereof or modifications thereto.
*/
-#include "glheader.h"
-#include "context.h"
-#include "imports.h"
-#include "macros.h"
+#include "main/glheader.h"
+#include "main/context.h"
+#include "main/imports.h"
+#include "main/macros.h"
#include "prog_parameter.h"
#include "prog_instruction.h"
#include "nvfragparse.h"
diff --git a/src/mesa/shader/nvprogram.c b/src/mesa/shader/nvprogram.c
index 409c61cdc1..d656d4b28b 100644
--- a/src/mesa/shader/nvprogram.c
+++ b/src/mesa/shader/nvprogram.c
@@ -37,11 +37,11 @@
* including any use thereof or modifications thereto.
*/
-#include "glheader.h"
-#include "context.h"
-#include "hash.h"
-#include "imports.h"
-#include "macros.h"
+#include "main/glheader.h"
+#include "main/context.h"
+#include "main/hash.h"
+#include "main/imports.h"
+#include "main/macros.h"
#include "prog_parameter.h"
#include "prog_instruction.h"
#include "nvfragparse.h"
diff --git a/src/mesa/shader/nvvertparse.c b/src/mesa/shader/nvvertparse.c
index ac96d4a60e..08538c0ee4 100644
--- a/src/mesa/shader/nvvertparse.c
+++ b/src/mesa/shader/nvvertparse.c
@@ -37,10 +37,10 @@
* including any use thereof or modifications thereto.
*/
-#include "glheader.h"
-#include "context.h"
-#include "imports.h"
-#include "macros.h"
+#include "main/glheader.h"
+#include "main/context.h"
+#include "main/imports.h"
+#include "main/macros.h"
#include "nvprogram.h"
#include "nvvertparse.h"
#include "prog_instruction.h"
diff --git a/src/mesa/shader/prog_debug.c b/src/mesa/shader/prog_debug.c
index 57929fcbca..7bcb2ef734 100644
--- a/src/mesa/shader/prog_debug.c
+++ b/src/mesa/shader/prog_debug.c
@@ -23,9 +23,9 @@
*/
-#include "glheader.h"
-#include "context.h"
-#include "macros.h"
+#include "main/glheader.h"
+#include "main/context.h"
+#include "main/macros.h"
#include "nvfragparse.h"
#include "nvvertparse.h"
#include "program.h"
diff --git a/src/mesa/shader/prog_execute.c b/src/mesa/shader/prog_execute.c
index 4745211c65..5afd9eb153 100644
--- a/src/mesa/shader/prog_execute.c
+++ b/src/mesa/shader/prog_execute.c
@@ -35,9 +35,9 @@
*/
-#include "glheader.h"
-#include "colormac.h"
-#include "context.h"
+#include "main/glheader.h"
+#include "main/colormac.h"
+#include "main/context.h"
#include "program.h"
#include "prog_execute.h"
#include "prog_instruction.h"
diff --git a/src/mesa/shader/prog_instruction.c b/src/mesa/shader/prog_instruction.c
index bea5d0551e..1033496d97 100644
--- a/src/mesa/shader/prog_instruction.c
+++ b/src/mesa/shader/prog_instruction.c
@@ -23,9 +23,9 @@
*/
-#include "glheader.h"
-#include "imports.h"
-#include "mtypes.h"
+#include "main/glheader.h"
+#include "main/imports.h"
+#include "main/mtypes.h"
#include "prog_instruction.h"
diff --git a/src/mesa/shader/prog_parameter.c b/src/mesa/shader/prog_parameter.c
index d87e8f6e15..e0d2096b30 100644
--- a/src/mesa/shader/prog_parameter.c
+++ b/src/mesa/shader/prog_parameter.c
@@ -29,9 +29,9 @@
*/
-#include "glheader.h"
-#include "imports.h"
-#include "macros.h"
+#include "main/glheader.h"
+#include "main/imports.h"
+#include "main/macros.h"
#include "prog_instruction.h"
#include "prog_parameter.h"
#include "prog_statevars.h"
diff --git a/src/mesa/shader/prog_parameter.h b/src/mesa/shader/prog_parameter.h
index dfb8c39ca4..ac5c629fab 100644
--- a/src/mesa/shader/prog_parameter.h
+++ b/src/mesa/shader/prog_parameter.h
@@ -31,7 +31,7 @@
#ifndef PROG_PARAMETER_H
#define PROG_PARAMETER_H
-#include "mtypes.h"
+#include "main/mtypes.h"
#include "prog_statevars.h"
diff --git a/src/mesa/shader/prog_print.c b/src/mesa/shader/prog_print.c
index 5368ab2187..10c5afec18 100644
--- a/src/mesa/shader/prog_print.c
+++ b/src/mesa/shader/prog_print.c
@@ -28,9 +28,9 @@
* \author Brian Paul
*/
-#include "glheader.h"
-#include "context.h"
-#include "imports.h"
+#include "main/glheader.h"
+#include "main/context.h"
+#include "main/imports.h"
#include "prog_instruction.h"
#include "prog_parameter.h"
#include "prog_print.h"
diff --git a/src/mesa/shader/prog_statevars.c b/src/mesa/shader/prog_statevars.c
index 81bb4122f2..819db25a00 100644
--- a/src/mesa/shader/prog_statevars.c
+++ b/src/mesa/shader/prog_statevars.c
@@ -29,12 +29,12 @@
*/
-#include "glheader.h"
-#include "context.h"
-#include "hash.h"
-#include "imports.h"
-#include "macros.h"
-#include "mtypes.h"
+#include "main/glheader.h"
+#include "main/context.h"
+#include "main/hash.h"
+#include "main/imports.h"
+#include "main/macros.h"
+#include "main/mtypes.h"
#include "prog_statevars.h"
#include "prog_parameter.h"
diff --git a/src/mesa/shader/prog_statevars.h b/src/mesa/shader/prog_statevars.h
index a515fda3aa..0a1c235828 100644
--- a/src/mesa/shader/prog_statevars.h
+++ b/src/mesa/shader/prog_statevars.h
@@ -25,7 +25,7 @@
#ifndef PROG_STATEVARS_H
#define PROG_STATEVARS_H
-#include "mtypes.h"
+#include "main/mtypes.h"
/**
diff --git a/src/mesa/shader/program.c b/src/mesa/shader/program.c
index 13d6df1ce6..02e23aaa3a 100644
--- a/src/mesa/shader/program.c
+++ b/src/mesa/shader/program.c
@@ -29,9 +29,9 @@
*/
-#include "glheader.h"
-#include "context.h"
-#include "hash.h"
+#include "main/glheader.h"
+#include "main/context.h"
+#include "main/hash.h"
#include "program.h"
#include "prog_cache.h"
#include "prog_parameter.h"
diff --git a/src/mesa/shader/program.h b/src/mesa/shader/program.h
index 7484961364..f8bd63233e 100644
--- a/src/mesa/shader/program.h
+++ b/src/mesa/shader/program.h
@@ -40,7 +40,7 @@
#ifndef PROGRAM_H
#define PROGRAM_H
-#include "mtypes.h"
+#include "main/mtypes.h"
extern struct gl_program _mesa_DummyProgram;
diff --git a/src/mesa/shader/programopt.c b/src/mesa/shader/programopt.c
index f3511ba00e..d6a3231055 100644
--- a/src/mesa/shader/programopt.c
+++ b/src/mesa/shader/programopt.c
@@ -31,8 +31,8 @@
*/
-#include "glheader.h"
-#include "context.h"
+#include "main/glheader.h"
+#include "main/context.h"
#include "prog_parameter.h"
#include "prog_statevars.h"
#include "program.h"
diff --git a/src/mesa/shader/shader_api.c b/src/mesa/shader/shader_api.c
index bd3745cfe6..5c18e55dac 100644
--- a/src/mesa/shader/shader_api.c
+++ b/src/mesa/shader/shader_api.c
@@ -35,10 +35,10 @@
*/
-#include "glheader.h"
-#include "context.h"
-#include "hash.h"
-#include "macros.h"
+#include "main/glheader.h"
+#include "main/context.h"
+#include "main/hash.h"
+#include "main/macros.h"
#include "program.h"
#include "prog_parameter.h"
#include "prog_print.h"
@@ -262,15 +262,11 @@ _mesa_new_shader(GLcontext *ctx, GLuint name, GLenum type)
void
_mesa_free_shader(GLcontext *ctx, struct gl_shader *sh)
{
- GLuint i;
if (sh->Source)
_mesa_free((void *) sh->Source);
if (sh->InfoLog)
_mesa_free(sh->InfoLog);
- for (i = 0; i < sh->NumPrograms; i++)
- _mesa_reference_program(ctx, &sh->Programs[i], NULL);
- if (sh->Programs)
- _mesa_free(sh->Programs);
+ _mesa_reference_program(ctx, &sh->Program, NULL);
_mesa_free(sh);
}
@@ -513,7 +509,7 @@ _mesa_bind_attrib_location(GLcontext *ctx, GLuint program, GLuint index,
struct gl_shader_program *shProg;
const GLint size = -1; /* unknown size */
GLint i, oldIndex;
- GLenum datatype;
+ GLenum datatype = GL_FLOAT_VEC4;
shProg = _mesa_lookup_shader_program_err(ctx, program,
"glBindAttribLocation");
@@ -547,6 +543,7 @@ _mesa_bind_attrib_location(GLcontext *ctx, GLuint program, GLuint index,
i = _mesa_add_attribute(shProg->Attributes, name, size, datatype, index);
if (i < 0) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindAttribLocation");
+ return;
}
if (shProg->VertexProgram && oldIndex >= 0 && oldIndex != index) {
diff --git a/src/mesa/shader/shader_api.h b/src/mesa/shader/shader_api.h
index 5521c585b5..e7f1266915 100644
--- a/src/mesa/shader/shader_api.h
+++ b/src/mesa/shader/shader_api.h
@@ -27,8 +27,8 @@
#define SHADER_API_H
-#include "glheader.h"
-#include "mtypes.h"
+#include "main/glheader.h"
+#include "main/mtypes.h"
/**
diff --git a/src/mesa/shader/slang/library/slang_120_core.gc b/src/mesa/shader/slang/library/slang_120_core.gc
index 15ca3a81ad..04c5ec2ec5 100644
--- a/src/mesa/shader/slang/library/slang_120_core.gc
+++ b/src/mesa/shader/slang/library/slang_120_core.gc
@@ -1976,53 +1976,3 @@ void __operator ++ (inout mat4x3 m) {
++m[3];
}
-
-mat2x3 __operator -- (inout mat2x3 m, const int) {
- return mat2x3 (m[0]--, m[1]--);
-}
-
-mat2x4 __operator -- (inout mat2x4 m, const int) {
- return mat2x4 (m[0]--, m[1]--);
-}
-
-mat3x2 __operator -- (inout mat3x2 m, const int) {
- return mat3x2 (m[0]--, m[1]--, m[2]--);
-}
-
-mat3x4 __operator -- (inout mat3x4 m, const int) {
- return mat3x4 (m[0]--, m[1]--, m[2]--);
-}
-
-mat4x2 __operator -- (inout mat4x2 m, const int) {
- return mat4x2 (m[0]--, m[1]--, m[2]--, m[3]--);
-}
-
-mat4x3 __operator -- (inout mat4x3 m, const int) {
- return mat4x3 (m[0]--, m[1]--, m[2]--, m[3]--);
-}
-
-
-mat2x3 __operator ++ (inout mat2x3 m, const int) {
- return mat2x3 (m[0]++, m[1]++);
-}
-
-mat2x4 __operator ++ (inout mat2x4 m, const int) {
- return mat2x4 (m[0]++, m[1]++);
-}
-
-mat3x2 __operator ++ (inout mat3x2 m, const int) {
- return mat3x2 (m[0]++, m[1]++, m[2]++);
-}
-
-mat3x4 __operator ++ (inout mat3x4 m, const int) {
- return mat3x4 (m[0]++, m[1]++, m[2]++);
-}
-
-mat4x2 __operator ++ (inout mat4x2 m, const int) {
- return mat4x2 (m[0]++, m[1]++, m[2]++, m[3]++);
-}
-
-mat4x3 __operator ++ (inout mat4x3 m, const int) {
- return mat4x3 (m[0]++, m[1]++, m[2]++, m[3]++);
-}
-
diff --git a/src/mesa/shader/slang/library/slang_120_core_gc.h b/src/mesa/shader/slang/library/slang_120_core_gc.h
index b7ef5ed6c6..1bd781ffe5 100644
--- a/src/mesa/shader/slang/library/slang_120_core_gc.h
+++ b/src/mesa/shader/slang/library/slang_120_core_gc.h
@@ -707,24 +707,4 @@
109,0,16,10,49,0,57,51,0,9,18,109,0,16,10,50,0,57,51,0,0,1,0,0,2,24,1,0,2,29,109,0,0,0,1,9,18,109,
0,16,8,48,0,57,51,0,9,18,109,0,16,10,49,0,57,51,0,9,18,109,0,16,10,50,0,57,51,0,9,18,109,0,16,10,
51,0,57,51,0,0,1,0,0,2,24,1,0,2,31,109,0,0,0,1,9,18,109,0,16,8,48,0,57,51,0,9,18,109,0,16,10,49,0,
-57,51,0,9,18,109,0,16,10,50,0,57,51,0,9,18,109,0,16,10,51,0,57,51,0,0,1,0,26,2,25,1,0,2,26,109,0,0,
-1,1,0,5,0,0,0,1,8,58,109,97,116,50,120,51,0,18,109,0,16,8,48,0,57,61,0,18,109,0,16,10,49,0,57,61,0,
-0,0,0,1,0,28,2,25,1,0,2,28,109,0,0,1,1,0,5,0,0,0,1,8,58,109,97,116,50,120,52,0,18,109,0,16,8,48,0,
-57,61,0,18,109,0,16,10,49,0,57,61,0,0,0,0,1,0,27,2,25,1,0,2,27,109,0,0,1,1,0,5,0,0,0,1,8,58,109,97,
-116,51,120,50,0,18,109,0,16,8,48,0,57,61,0,18,109,0,16,10,49,0,57,61,0,18,109,0,16,10,50,0,57,61,0,
-0,0,0,1,0,30,2,25,1,0,2,30,109,0,0,1,1,0,5,0,0,0,1,8,58,109,97,116,51,120,52,0,18,109,0,16,8,48,0,
-57,61,0,18,109,0,16,10,49,0,57,61,0,18,109,0,16,10,50,0,57,61,0,0,0,0,1,0,29,2,25,1,0,2,29,109,0,0,
-1,1,0,5,0,0,0,1,8,58,109,97,116,52,120,50,0,18,109,0,16,8,48,0,57,61,0,18,109,0,16,10,49,0,57,61,0,
-18,109,0,16,10,50,0,57,61,0,18,109,0,16,10,51,0,57,61,0,0,0,0,1,0,31,2,25,1,0,2,31,109,0,0,1,1,0,5,
-0,0,0,1,8,58,109,97,116,52,120,51,0,18,109,0,16,8,48,0,57,61,0,18,109,0,16,10,49,0,57,61,0,18,109,
-0,16,10,50,0,57,61,0,18,109,0,16,10,51,0,57,61,0,0,0,0,1,0,26,2,24,1,0,2,26,109,0,0,1,1,0,5,0,0,0,
-1,8,58,109,97,116,50,120,51,0,18,109,0,16,8,48,0,57,60,0,18,109,0,16,10,49,0,57,60,0,0,0,0,1,0,28,
-2,24,1,0,2,28,109,0,0,1,1,0,5,0,0,0,1,8,58,109,97,116,50,120,52,0,18,109,0,16,8,48,0,57,60,0,18,
-109,0,16,10,49,0,57,60,0,0,0,0,1,0,27,2,24,1,0,2,27,109,0,0,1,1,0,5,0,0,0,1,8,58,109,97,116,51,120,
-50,0,18,109,0,16,8,48,0,57,60,0,18,109,0,16,10,49,0,57,60,0,18,109,0,16,10,50,0,57,60,0,0,0,0,1,0,
-30,2,24,1,0,2,30,109,0,0,1,1,0,5,0,0,0,1,8,58,109,97,116,51,120,52,0,18,109,0,16,8,48,0,57,60,0,18,
-109,0,16,10,49,0,57,60,0,18,109,0,16,10,50,0,57,60,0,0,0,0,1,0,29,2,24,1,0,2,29,109,0,0,1,1,0,5,0,
-0,0,1,8,58,109,97,116,52,120,50,0,18,109,0,16,8,48,0,57,60,0,18,109,0,16,10,49,0,57,60,0,18,109,0,
-16,10,50,0,57,60,0,18,109,0,16,10,51,0,57,60,0,0,0,0,1,0,31,2,24,1,0,2,31,109,0,0,1,1,0,5,0,0,0,1,
-8,58,109,97,116,52,120,51,0,18,109,0,16,8,48,0,57,60,0,18,109,0,16,10,49,0,57,60,0,18,109,0,16,10,
-50,0,57,60,0,18,109,0,16,10,51,0,57,60,0,0,0,0,0
+57,51,0,9,18,109,0,16,10,50,0,57,51,0,9,18,109,0,16,10,51,0,57,51,0,0,0
diff --git a/src/mesa/shader/slang/library/slang_core.gc b/src/mesa/shader/slang/library/slang_core.gc
index 2c3a5a6c45..1f57997051 100644
--- a/src/mesa/shader/slang/library/slang_core.gc
+++ b/src/mesa/shader/slang/library/slang_core.gc
@@ -110,6 +110,16 @@ int __constructor(const float f)
__asm float_to_int __retVal, f;
}
+int __constructor(const bool b)
+{
+ __retVal = b;
+}
+
+int __constructor(const int i)
+{
+ __retVal = i;
+}
+
bool __constructor(const int i)
{
const float zero = 0.0;
@@ -122,12 +132,7 @@ bool __constructor(const float f)
__asm vec4_sne __retVal, f, zero;
}
-int __constructor(const bool b)
-{
- __retVal = b;
-}
-
-float __constructor(const bool b)
+bool __constructor(const bool b)
{
__retVal = b;
}
@@ -137,16 +142,11 @@ float __constructor(const int i)
__asm int_to_float __retVal, i;
}
-bool __constructor(const bool b)
+float __constructor(const bool b)
{
__retVal = b;
}
-int __constructor(const int i)
-{
- __retVal = i;
-}
-
float __constructor(const float f)
{
__retVal = f;
diff --git a/src/mesa/shader/slang/library/slang_core_gc.h b/src/mesa/shader/slang/library/slang_core_gc.h
index f71fe28cda..44170946ce 100644
--- a/src/mesa/shader/slang/library/slang_core_gc.h
+++ b/src/mesa/shader/slang/library/slang_core_gc.h
@@ -3,15 +3,15 @@
/* slang_core.gc */
3,1,0,5,1,1,1,0,9,102,0,0,0,1,4,102,108,111,97,116,95,116,111,95,105,110,116,0,18,95,95,114,101,
-116,86,97,108,0,0,18,102,0,0,0,0,1,0,1,1,1,1,0,5,105,0,0,0,1,3,2,1,9,1,122,101,114,111,0,2,17,48,0,
-48,0,0,0,0,4,118,101,99,52,95,115,110,101,0,18,95,95,114,101,116,86,97,108,0,0,18,105,0,0,18,122,
-101,114,111,0,0,0,0,1,0,1,1,1,1,0,9,102,0,0,0,1,3,2,1,9,1,122,101,114,111,0,2,17,48,0,48,0,0,0,0,4,
-118,101,99,52,95,115,110,101,0,18,95,95,114,101,116,86,97,108,0,0,18,102,0,0,18,122,101,114,111,0,
-0,0,0,1,0,5,1,1,1,0,1,98,0,0,0,1,9,18,95,95,114,101,116,86,97,108,0,18,98,0,20,0,0,1,0,9,1,1,1,0,1,
-98,0,0,0,1,9,18,95,95,114,101,116,86,97,108,0,18,98,0,20,0,0,1,0,9,1,1,1,0,5,105,0,0,0,1,4,105,110,
-116,95,116,111,95,102,108,111,97,116,0,18,95,95,114,101,116,86,97,108,0,0,18,105,0,0,0,0,1,0,1,1,1,
-1,0,1,98,0,0,0,1,9,18,95,95,114,101,116,86,97,108,0,18,98,0,20,0,0,1,0,5,1,1,1,0,5,105,0,0,0,1,9,
-18,95,95,114,101,116,86,97,108,0,18,105,0,20,0,0,1,0,9,1,1,1,0,9,102,0,0,0,1,9,18,95,95,114,101,
+116,86,97,108,0,0,18,102,0,0,0,0,1,0,5,1,1,1,0,1,98,0,0,0,1,9,18,95,95,114,101,116,86,97,108,0,18,
+98,0,20,0,0,1,0,5,1,1,1,0,5,105,0,0,0,1,9,18,95,95,114,101,116,86,97,108,0,18,105,0,20,0,0,1,0,1,1,
+1,1,0,5,105,0,0,0,1,3,2,1,9,1,122,101,114,111,0,2,17,48,0,48,0,0,0,0,4,118,101,99,52,95,115,110,
+101,0,18,95,95,114,101,116,86,97,108,0,0,18,105,0,0,18,122,101,114,111,0,0,0,0,1,0,1,1,1,1,0,9,102,
+0,0,0,1,3,2,1,9,1,122,101,114,111,0,2,17,48,0,48,0,0,0,0,4,118,101,99,52,95,115,110,101,0,18,95,95,
+114,101,116,86,97,108,0,0,18,102,0,0,18,122,101,114,111,0,0,0,0,1,0,1,1,1,1,0,1,98,0,0,0,1,9,18,95,
+95,114,101,116,86,97,108,0,18,98,0,20,0,0,1,0,9,1,1,1,0,5,105,0,0,0,1,4,105,110,116,95,116,111,95,
+102,108,111,97,116,0,18,95,95,114,101,116,86,97,108,0,0,18,105,0,0,0,0,1,0,9,1,1,1,0,1,98,0,0,0,1,
+9,18,95,95,114,101,116,86,97,108,0,18,98,0,20,0,0,1,0,9,1,1,1,0,9,102,0,0,0,1,9,18,95,95,114,101,
116,86,97,108,0,18,102,0,20,0,0,1,0,10,1,1,1,0,9,120,0,0,1,1,0,9,121,0,0,0,1,9,18,95,95,114,101,
116,86,97,108,0,59,120,0,18,120,0,20,0,9,18,95,95,114,101,116,86,97,108,0,59,121,0,18,121,0,20,0,0,
1,0,10,1,1,1,0,9,102,0,0,0,1,9,18,95,95,114,101,116,86,97,108,0,59,120,121,0,18,102,0,59,120,120,0,
diff --git a/src/mesa/shader/slang/slang_codegen.c b/src/mesa/shader/slang/slang_codegen.c
index d4bf99f78f..ad9cf06e27 100644
--- a/src/mesa/shader/slang/slang_codegen.c
+++ b/src/mesa/shader/slang/slang_codegen.c
@@ -1178,7 +1178,8 @@ slang_inline_function_call(slang_assemble_ctx * A, slang_function *fun,
slang_operation_copy(inlined, fun->body);
/*** XXX review this */
- assert(inlined->type == SLANG_OPER_BLOCK_NO_NEW_SCOPE);
+ assert(inlined->type == SLANG_OPER_BLOCK_NO_NEW_SCOPE ||
+ inlined->type == SLANG_OPER_BLOCK_NEW_SCOPE);
inlined->type = SLANG_OPER_BLOCK_NEW_SCOPE;
#if 0
@@ -1702,7 +1703,7 @@ print_funcs(struct slang_function_scope_ *scope, const char *name)
/**
- * Return first function in the scope that has the given name.
+ * Find a function of the given name, taking 'numArgs' arguments.
* This is the function we'll try to call when there is no exact match
* between function parameters and call arguments.
*
@@ -1710,20 +1711,51 @@ print_funcs(struct slang_function_scope_ *scope, const char *name)
* all of them...
*/
static slang_function *
-_slang_first_function(struct slang_function_scope_ *scope, const char *name)
-{
- GLuint i;
- for (i = 0; i < scope->num_functions; i++) {
- slang_function *f = &scope->functions[i];
- if (strcmp(name, (char*) f->header.a_name) == 0)
- return f;
+_slang_find_function_by_argc(slang_function_scope *scope,
+ const char *name, int numArgs)
+{
+ while (scope) {
+ GLuint i;
+ for (i = 0; i < scope->num_functions; i++) {
+ slang_function *f = &scope->functions[i];
+ if (strcmp(name, (char*) f->header.a_name) == 0) {
+ int haveRetValue = _slang_function_has_return_value(f);
+ if (numArgs == f->param_count - haveRetValue)
+ return f;
+ }
+ }
+ scope = scope->outer_scope;
}
- if (scope->outer_scope)
- return _slang_first_function(scope->outer_scope, name);
+
return NULL;
}
+static slang_function *
+_slang_find_function_by_max_argc(slang_function_scope *scope,
+ const char *name)
+{
+ slang_function *maxFunc = NULL;
+ GLuint maxArgs = 0;
+
+ while (scope) {
+ GLuint i;
+ for (i = 0; i < scope->num_functions; i++) {
+ slang_function *f = &scope->functions[i];
+ if (strcmp(name, (char*) f->header.a_name) == 0) {
+ if (f->param_count > maxArgs) {
+ maxArgs = f->param_count;
+ maxFunc = f;
+ }
+ }
+ }
+ scope = scope->outer_scope;
+ }
+
+ return maxFunc;
+}
+
+
/**
* Generate a new slang_function which is a constructor for a user-defined
* struct type.
@@ -1754,7 +1786,8 @@ _slang_make_constructor(slang_assemble_ctx *A, slang_struct *str)
printf("Field %d: %s\n", i, (char*) str->fields->variables[i]->a_name);
*/
slang_variable *p = slang_variable_scope_grow(fun->parameters);
- *p = *str->fields->variables[i];
+ *p = *str->fields->variables[i]; /* copy the type */
+ p->type.qualifier = SLANG_QUAL_CONST;
}
fun->param_count = fun->parameters->num_variables;
}
@@ -1780,16 +1813,20 @@ _slang_make_constructor(slang_assemble_ctx *A, slang_struct *str)
* return T;
*/
{
+ slang_variable_scope *scope;
slang_variable *var;
GLint i;
fun->body = slang_operation_new(1);
- fun->body->type = SLANG_OPER_BLOCK_NO_NEW_SCOPE;
+ fun->body->type = SLANG_OPER_BLOCK_NEW_SCOPE;
fun->body->num_children = numFields + 2;
fun->body->children = slang_operation_new(numFields + 2);
+ scope = fun->body->locals;
+ scope->outer_scope = fun->parameters;
+
/* create local var 't' */
- var = slang_variable_scope_grow(fun->parameters);
+ var = slang_variable_scope_grow(scope);
var->a_name = slang_atom_pool_atom(A->atoms, "t");
var->type = fun->header.type;
@@ -1799,7 +1836,7 @@ _slang_make_constructor(slang_assemble_ctx *A, slang_struct *str)
decl = &fun->body->children[0];
decl->type = SLANG_OPER_VARIABLE_DECL;
- decl->locals = _slang_variable_scope_new(fun->parameters);
+ decl->locals = _slang_variable_scope_new(scope);
decl->a_id = var->a_name;
}
@@ -1808,7 +1845,7 @@ _slang_make_constructor(slang_assemble_ctx *A, slang_struct *str)
slang_operation *assign = &fun->body->children[1 + i];
assign->type = SLANG_OPER_ASSIGN;
- assign->locals = _slang_variable_scope_new(fun->parameters);
+ assign->locals = _slang_variable_scope_new(scope);
assign->num_children = 2;
assign->children = slang_operation_new(2);
@@ -1816,21 +1853,21 @@ _slang_make_constructor(slang_assemble_ctx *A, slang_struct *str)
slang_operation *lhs = &assign->children[0];
lhs->type = SLANG_OPER_FIELD;
- lhs->locals = _slang_variable_scope_new(fun->parameters);
+ lhs->locals = _slang_variable_scope_new(scope);
lhs->num_children = 1;
lhs->children = slang_operation_new(1);
lhs->a_id = str->fields->variables[i]->a_name;
lhs->children[0].type = SLANG_OPER_IDENTIFIER;
lhs->children[0].a_id = var->a_name;
- lhs->children[0].locals = _slang_variable_scope_new(fun->parameters);
+ lhs->children[0].locals = _slang_variable_scope_new(scope);
#if 0
lhs->children[1].num_children = 1;
lhs->children[1].children = slang_operation_new(1);
lhs->children[1].children[0].type = SLANG_OPER_IDENTIFIER;
lhs->children[1].children[0].a_id = str->fields->variables[i]->a_name;
- lhs->children[1].children->locals = _slang_variable_scope_new(fun->parameters);
+ lhs->children[1].children->locals = _slang_variable_scope_new(scope);
#endif
}
@@ -1838,7 +1875,7 @@ _slang_make_constructor(slang_assemble_ctx *A, slang_struct *str)
slang_operation *rhs = &assign->children[1];
rhs->type = SLANG_OPER_IDENTIFIER;
- rhs->locals = _slang_variable_scope_new(fun->parameters);
+ rhs->locals = _slang_variable_scope_new(scope);
rhs->a_id = str->fields->variables[i]->a_name;
}
}
@@ -1848,12 +1885,12 @@ _slang_make_constructor(slang_assemble_ctx *A, slang_struct *str)
slang_operation *ret = &fun->body->children[numFields + 1];
ret->type = SLANG_OPER_RETURN;
- ret->locals = _slang_variable_scope_new(fun->parameters);
+ ret->locals = _slang_variable_scope_new(scope);
ret->num_children = 1;
ret->children = slang_operation_new(1);
ret->children[0].type = SLANG_OPER_IDENTIFIER;
ret->children[0].a_id = var->a_name;
- ret->children[0].locals = _slang_variable_scope_new(fun->parameters);
+ ret->children[0].locals = _slang_variable_scope_new(scope);
}
}
@@ -1870,7 +1907,7 @@ _slang_make_constructor(slang_assemble_ctx *A, slang_struct *str)
static slang_function *
_slang_locate_struct_constructor(slang_assemble_ctx *A, const char *name)
{
- int i;
+ unsigned int i;
for (i = 0; i < A->space.structs->num_structs; i++) {
slang_struct *str = &A->space.structs->structs[i];
if (strcmp(name, (const char *) str->a_name) == 0) {
@@ -1886,6 +1923,27 @@ _slang_locate_struct_constructor(slang_assemble_ctx *A, const char *name)
}
+
+static GLboolean
+_slang_is_vec_mat_type(const char *name)
+{
+ static const char *vecmat_types[] = {
+ "float", "int", "bool",
+ "vec2", "vec3", "vec4",
+ "ivec2", "ivec3", "ivec4",
+ "bvec2", "bvec3", "bvec4",
+ "mat2", "mat3", "mat4",
+ "mat2x3", "mat2x4", "mat3x2", "mat3x4", "mat4x2", "mat4x3",
+ NULL
+ };
+ int i;
+ for (i = 0; vecmat_types[i]; i++)
+ if (_mesa_strcmp(name, vecmat_types[i]) == 0)
+ return GL_TRUE;
+ return GL_FALSE;
+}
+
+
/**
* Assemble a function call, given a particular function name.
* \param name the function's name (operators like '*' are possible).
@@ -1898,28 +1956,53 @@ _slang_gen_function_call_name(slang_assemble_ctx *A, const char *name,
const GLuint param_count = oper->num_children;
slang_atom atom;
slang_function *fun;
+ GLboolean error;
atom = slang_atom_pool_atom(A->atoms, name);
if (atom == SLANG_ATOM_NULL)
return NULL;
/*
- * Use 'name' to find the function to call
+ * First, try to find function by name and exact argument type matching.
*/
fun = _slang_locate_function(A->space.funcs, atom, params, param_count,
- &A->space, A->atoms, A->log);
+ &A->space, A->atoms, A->log, &error);
+
+ if (error) {
+ slang_info_log_error(A->log,
+ "Function '%s' not found (check argument types)",
+ name);
+ return NULL;
+ }
if (!fun) {
+ /* Next, try locating a constructor function for a user-defined type */
fun = _slang_locate_struct_constructor(A, name);
}
- if (!fun) {
- /* A function with exactly the right parameters/types was not found.
- * Try adapting the parameters.
+ if (!fun && _slang_is_vec_mat_type(name)) {
+ /* Next, if this call looks like a vec() or mat() constructor call,
+ * try "unwinding" the args to satisfy a constructor.
*/
- fun = _slang_first_function(A->space.funcs, name);
- if (!fun || !_slang_adapt_call(oper, fun, &A->space, A->atoms, A->log)) {
- slang_info_log_error(A->log, "Function '%s' not found (check argument types)", name);
+ fun = _slang_find_function_by_max_argc(A->space.funcs, name);
+ if (fun) {
+ if (!_slang_adapt_call(oper, fun, &A->space, A->atoms, A->log)) {
+ slang_info_log_error(A->log,
+ "Function '%s' not found (check argument types)",
+ name);
+ return NULL;
+ }
+ }
+ }
+
+ if (!fun) {
+ /* Next, try casting args to the types of the formal parameters */
+ int numArgs = oper->num_children;
+ fun = _slang_find_function_by_argc(A->space.funcs, name, numArgs);
+ if (!fun || !_slang_cast_func_params(oper, fun, &A->space, A->atoms, A->log)) {
+ slang_info_log_error(A->log,
+ "Function '%s' not found (check argument types)",
+ name);
return NULL;
}
assert(fun);
@@ -2193,22 +2276,16 @@ _slang_gen_if(slang_assemble_ctx * A, const slang_operation *oper)
cond = _slang_gen_operation(A, &oper->children[0]);
cond = new_cond(cond);
- if (is_operation_type(&oper->children[1], SLANG_OPER_BREAK)) {
+ if (is_operation_type(&oper->children[1], SLANG_OPER_BREAK)
+ && !haveElseClause) {
/* Special case: generate a conditional break */
ifBody = new_break_if_true(A->CurLoop, cond);
- if (haveElseClause) {
- elseBody = _slang_gen_operation(A, &oper->children[2]);
- return new_seq(ifBody, elseBody);
- }
return ifBody;
}
- else if (is_operation_type(&oper->children[1], SLANG_OPER_CONTINUE)) {
+ else if (is_operation_type(&oper->children[1], SLANG_OPER_CONTINUE)
+ && !haveElseClause) {
/* Special case: generate a conditional break */
ifBody = new_cont_if_true(A->CurLoop, cond);
- if (haveElseClause) {
- elseBody = _slang_gen_operation(A, &oper->children[2]);
- return new_seq(ifBody, elseBody);
- }
return ifBody;
}
else {
@@ -2318,6 +2395,11 @@ _slang_gen_var_decl(slang_assemble_ctx *A, slang_variable *var)
n->Store->File = PROGRAM_TEMPORARY;
n->Store->Size = _slang_sizeof_type_specifier(&n->Var->type.specifier);
+ if (n->Store->Size <= 0) {
+ slang_info_log_error(A->log, "invalid declaration for '%s'",
+ (char*) var->a_name);
+ return NULL;
+ }
#if 0
printf("%s var %p %s store=%p index=%d size=%d\n",
__FUNCTION__, (void *) var, (char *) var->a_name,
@@ -2553,8 +2635,16 @@ _slang_gen_declaration(slang_assemble_ctx *A, slang_operation *oper)
assert(oper->num_children == 0 || oper->num_children == 1);
v = _slang_locate_variable(oper->locals, oper->a_id, GL_TRUE);
+ /*printf("Declare %s at %p\n", varName, v);*/
assert(v);
+#if 0
+ if (v->declared) {
+ slang_info_log_error(A->log, "variable '%s' redeclared", varName);
+ return NULL;
+ }
+#endif
+
varDecl = _slang_gen_var_decl(A, v);
if (oper->num_children > 0) {
@@ -2711,6 +2801,11 @@ _slang_gen_assignment(slang_assemble_ctx * A, slang_operation *oper)
lhs = _slang_gen_operation(A, &oper->children[0]);
if (lhs) {
+ if (!lhs->Store) {
+ slang_info_log_error(A->log,
+ "invalid left hand side for assignment");
+ return NULL;
+ }
if (!(lhs->Store->File == PROGRAM_OUTPUT ||
lhs->Store->File == PROGRAM_TEMPORARY ||
(lhs->Store->File == PROGRAM_VARYING &&
@@ -2764,6 +2859,7 @@ _slang_gen_struct_field(slang_assemble_ctx * A, slang_operation *oper)
GLuint swizzle;
if (!_slang_is_swizzle((char *) oper->a_id, rows, &swz)) {
slang_info_log_error(A->log, "Bad swizzle");
+ return NULL;
}
swizzle = MAKE_SWIZZLE4(swz.swizzle[0],
swz.swizzle[1],
@@ -2812,10 +2908,14 @@ _slang_gen_struct_field(slang_assemble_ctx * A, slang_operation *oper)
fieldOffset = _slang_field_offset(&ti.spec, oper->a_id);
if (fieldSize == 0 || fieldOffset < 0) {
+ const char *structName;
+ if (ti.spec._struct)
+ structName = (char *) ti.spec._struct->a_name;
+ else
+ structName = "unknown";
slang_info_log_error(A->log,
"\"%s\" is not a member of struct \"%s\"",
- (char *) oper->a_id,
- (char *) ti.spec._struct->a_name);
+ (char *) oper->a_id, structName);
return NULL;
}
assert(fieldSize >= 0);
@@ -2889,6 +2989,7 @@ _slang_gen_array_element(slang_assemble_ctx * A, slang_operation *oper)
/*n->Store = _slang_clone_ir_storage_swz(n->Store, */
n->Writemask = WRITEMASK_X << index;
}
+ assert(n->Store);
return n;
}
else {
@@ -2933,11 +3034,17 @@ _slang_gen_array_element(slang_assemble_ctx * A, slang_operation *oper)
}
}
+ if (!array->Store) {
+ slang_info_log_error(A->log, "Invalid array");
+ return NULL;
+ }
+
elem = new_node2(IR_ELEMENT, array, index);
elem->Store = _slang_new_ir_storage_relative(constIndex,
elemSize,
array->Store);
+ assert(elem->Store->Parent);
/* XXX try to do some array bounds checking here */
return elem;
}
@@ -2950,6 +3057,39 @@ _slang_gen_array_element(slang_assemble_ctx * A, slang_operation *oper)
}
+#if 0
+static void
+print_vars(slang_variable_scope *s)
+{
+ int i;
+ printf("vars: ");
+ for (i = 0; i < s->num_variables; i++) {
+ printf("%s %d, \n",
+ (char*) s->variables[i]->a_name,
+ s->variables[i]->declared);
+ }
+
+ printf("\n");
+}
+#endif
+
+
+#if 0
+static void
+_slang_undeclare_vars(slang_variable_scope *locals)
+{
+ if (locals->num_variables > 0) {
+ int i;
+ for (i = 0; i < locals->num_variables; i++) {
+ slang_variable *v = locals->variables[i];
+ printf("undeclare %s at %p\n", (char*) v->a_name, v);
+ v->declared = GL_FALSE;
+ }
+ }
+}
+#endif
+
+
/**
* Generate IR tree for a slang_operation (AST node)
*/
@@ -2969,6 +3109,9 @@ _slang_gen_operation(slang_assemble_ctx * A, slang_operation *oper)
_slang_pop_var_table(A->vartable);
+ /*_slang_undeclare_vars(oper->locals);*/
+ /*print_vars(oper->locals);*/
+
if (n)
n = new_node1(IR_SCOPE, n);
return n;
@@ -2991,26 +3134,6 @@ _slang_gen_operation(slang_assemble_ctx * A, slang_operation *oper)
tree = new_seq(tree, n);
}
-#if 00
- if (oper->locals->num_variables > 0) {
- int i;
- /*
- printf("\n****** Deallocate vars in scope!\n");
- */
- for (i = 0; i < oper->locals->num_variables; i++) {
- slang_variable *v = oper->locals->variables + i;
- if (v->aux) {
- slang_ir_storage *store = (slang_ir_storage *) v->aux;
- /*
- printf(" Deallocate var %s\n", (char*) v->a_name);
- */
- assert(store->File == PROGRAM_TEMPORARY);
- assert(store->Index >= 0);
- _slang_free_temp(A->vartable, store->Index, store->Size);
- }
- }
- }
-#endif
return tree;
}
else {
diff --git a/src/mesa/shader/slang/slang_codegen.h b/src/mesa/shader/slang/slang_codegen.h
index 821d396162..ba7ca4c142 100644
--- a/src/mesa/shader/slang/slang_codegen.h
+++ b/src/mesa/shader/slang/slang_codegen.h
@@ -27,7 +27,7 @@
#define SLANG_CODEGEN_H
-#include "imports.h"
+#include "main/imports.h"
#include "slang_compile.h"
diff --git a/src/mesa/shader/slang/slang_compile.c b/src/mesa/shader/slang/slang_compile.c
index fd5d4afacb..60539f19b6 100644
--- a/src/mesa/shader/slang/slang_compile.c
+++ b/src/mesa/shader/slang/slang_compile.c
@@ -337,9 +337,10 @@ convert_to_array(slang_parse_ctx * C, slang_variable * var,
static GLboolean
parse_struct_field_var(slang_parse_ctx * C, slang_output_ctx * O,
- slang_variable * var, const slang_type_specifier * sp)
+ slang_variable * var, slang_atom a_name,
+ const slang_type_specifier * sp)
{
- var->a_name = parse_identifier(C);
+ var->a_name = a_name;
if (var->a_name == SLANG_ATOM_NULL)
return GL_FALSE;
@@ -372,12 +373,19 @@ parse_struct_field(slang_parse_ctx * C, slang_output_ctx * O,
return 0;
do {
+ slang_atom a_name;
slang_variable *var = slang_variable_scope_grow(st->fields);
if (!var) {
slang_info_log_memory(C->L);
return 0;
}
- if (!parse_struct_field_var(C, &o, var, sp))
+ a_name = parse_identifier(C);
+ if (_slang_locate_variable(st->fields, a_name, GL_FALSE)) {
+ slang_info_log_error(C->L, "duplicate field '%s'", (char *) a_name);
+ return 0;
+ }
+
+ if (!parse_struct_field_var(C, &o, var, a_name, sp))
return 0;
}
while (*C->I++ != FIELD_NONE);
@@ -1579,11 +1587,22 @@ parse_init_declarator(slang_parse_ctx * C, slang_output_ctx * O,
const slang_fully_specified_type * type)
{
slang_variable *var;
+ slang_atom a_name;
/* empty init declatator (without name, e.g. "float ;") */
if (*C->I++ == VARIABLE_NONE)
return 1;
+ a_name = parse_identifier(C);
+
+ /* check if name is already in this scope */
+ if (_slang_locate_variable(O->vars, a_name, GL_FALSE)) {
+ slang_info_log_error(C->L,
+ "declaration of '%s' conflicts with previous declaration",
+ (char *) a_name);
+ return 0;
+ }
+
/* make room for the new variable and initialize it */
var = slang_variable_scope_grow(O->vars);
if (!var) {
@@ -1593,7 +1612,7 @@ parse_init_declarator(slang_parse_ctx * C, slang_output_ctx * O,
/* copy the declarator qualifier type, parse the identifier */
var->type.qualifier = type->qualifier;
- var->a_name = parse_identifier(C);
+ var->a_name = a_name;
if (var->a_name == SLANG_ATOM_NULL)
return 0;
@@ -1657,6 +1676,7 @@ parse_init_declarator(slang_parse_ctx * C, slang_output_ctx * O,
A.space.vars = O->vars;
A.program = O->program;
A.vartable = O->vartable;
+ A.log = C->L;
A.curFuncEndLabel = NULL;
if (!_slang_codegen_global_variable(&A, var, C->type))
return 0;
@@ -1930,7 +1950,7 @@ parse_invariant(slang_parse_ctx * C, slang_output_ctx * O)
static GLboolean
parse_code_unit(slang_parse_ctx * C, slang_code_unit * unit,
- struct gl_program *program)
+ struct gl_shader *shader)
{
GET_CURRENT_CONTEXT(ctx);
slang_output_ctx o;
@@ -1954,7 +1974,7 @@ parse_code_unit(slang_parse_ctx * C, slang_code_unit * unit,
o.structs = &unit->structs;
o.vars = &unit->vars;
o.global_pool = &unit->object->varpool;
- o.program = program;
+ o.program = shader ? shader->Program : NULL;
o.vartable = _slang_new_var_table(maxRegs);
_slang_push_var_table(o.vartable);
@@ -2007,6 +2027,7 @@ parse_code_unit(slang_parse_ctx * C, slang_code_unit * unit,
_slang_codegen_function(&A, mainFunc);
+ shader->Main = GL_TRUE; /* this shader defines main() */
}
_slang_pop_var_table(o.vartable);
@@ -2020,7 +2041,7 @@ compile_binary(const byte * prod, slang_code_unit * unit,
GLuint version,
slang_unit_type type, slang_info_log * infolog,
slang_code_unit * builtin, slang_code_unit * downlink,
- struct gl_program *program)
+ struct gl_shader *shader)
{
slang_parse_ctx C;
@@ -2045,14 +2066,14 @@ compile_binary(const byte * prod, slang_code_unit * unit,
}
/* parse translation unit */
- return parse_code_unit(&C, unit, program);
+ return parse_code_unit(&C, unit, shader);
}
static GLboolean
compile_with_grammar(grammar id, const char *source, slang_code_unit * unit,
slang_unit_type type, slang_info_log * infolog,
slang_code_unit * builtin,
- struct gl_program *program)
+ struct gl_shader *shader)
{
byte *prod;
GLuint size, start, version;
@@ -2114,7 +2135,7 @@ compile_with_grammar(grammar id, const char *source, slang_code_unit * unit,
/* Syntax is okay - translate it to internal representation. */
if (!compile_binary(prod, unit, version, type, infolog, builtin,
&builtin[SLANG_BUILTIN_TOTAL - 1],
- program)) {
+ shader)) {
grammar_alloc_free(prod);
return GL_FALSE;
}
@@ -2153,7 +2174,7 @@ static const byte slang_vertex_builtin_gc[] = {
static GLboolean
compile_object(grammar * id, const char *source, slang_code_object * object,
slang_unit_type type, slang_info_log * infolog,
- struct gl_program *program)
+ struct gl_shader *shader)
{
slang_code_unit *builtins = NULL;
GLuint base_version = 110;
@@ -2252,7 +2273,7 @@ compile_object(grammar * id, const char *source, slang_code_object * object,
/* compile the actual shader - pass-in built-in library for external shader */
return compile_with_grammar(*id, source, &object->unit, type, infolog,
- builtins, program);
+ builtins, shader);
}
@@ -2261,22 +2282,21 @@ compile_shader(GLcontext *ctx, slang_code_object * object,
slang_unit_type type, slang_info_log * infolog,
struct gl_shader *shader)
{
- struct gl_program *program = shader->Programs[0];
GLboolean success;
grammar id = 0;
-#if 0 /* for debug */
+#if 1 /* for debug */
_mesa_printf("********* COMPILE SHADER ***********\n");
_mesa_printf("%s\n", shader->Source);
_mesa_printf("************************************\n");
#endif
- assert(program);
+ assert(shader->Program);
_slang_code_object_dtr(object);
_slang_code_object_ctr(object);
- success = compile_object(&id, shader->Source, object, type, infolog, program);
+ success = compile_object(&id, shader->Source, object, type, infolog, shader);
if (id != 0)
grammar_destroy(id);
if (!success)
@@ -2308,21 +2328,18 @@ _slang_compile(GLcontext *ctx, struct gl_shader *shader)
ctx->Shader.MemPool = _slang_new_mempool(1024*1024);
- /* XXX temporary hack */
- if (!shader->Programs) {
+ shader->Main = GL_FALSE;
+
+ if (!shader->Program) {
GLenum progTarget;
if (shader->Type == GL_VERTEX_SHADER)
progTarget = GL_VERTEX_PROGRAM_ARB;
else
progTarget = GL_FRAGMENT_PROGRAM_ARB;
- shader->Programs
- = (struct gl_program **) malloc(sizeof(struct gl_program*));
- shader->Programs[0] = ctx->Driver.NewProgram(ctx, progTarget, 1);
- shader->NumPrograms = 1;
-
- shader->Programs[0]->Parameters = _mesa_new_parameter_list();
- shader->Programs[0]->Varying = _mesa_new_parameter_list();
- shader->Programs[0]->Attributes = _mesa_new_parameter_list();
+ shader->Program = ctx->Driver.NewProgram(ctx, progTarget, 1);
+ shader->Program->Parameters = _mesa_new_parameter_list();
+ shader->Program->Varying = _mesa_new_parameter_list();
+ shader->Program->Attributes = _mesa_new_parameter_list();
}
slang_info_log_construct(&info_log);
@@ -2355,13 +2372,13 @@ _slang_compile(GLcontext *ctx, struct gl_shader *shader)
/* remove any reads of varying (output) registers */
#if 0
printf("Pre-remove output reads:\n");
- _mesa_print_program(shader->Programs[0]);
+ _mesa_print_program(shader->Programs);
#endif
- _mesa_remove_output_reads(shader->Programs[0], PROGRAM_VARYING);
- _mesa_remove_output_reads(shader->Programs[0], PROGRAM_OUTPUT);
+ _mesa_remove_output_reads(shader->Program, PROGRAM_VARYING);
+ _mesa_remove_output_reads(shader->Program, PROGRAM_OUTPUT);
#if 0
printf("Post-remove output reads:\n");
- _mesa_print_program(shader->Programs[0]);
+ _mesa_print_program(shader->Programs);
#endif
}
diff --git a/src/mesa/shader/slang/slang_compile.h b/src/mesa/shader/slang/slang_compile.h
index 0f1f820d2e..35e468b44e 100644
--- a/src/mesa/shader/slang/slang_compile.h
+++ b/src/mesa/shader/slang/slang_compile.h
@@ -25,8 +25,8 @@
#if !defined SLANG_COMPILE_H
#define SLANG_COMPILE_H
-#include "imports.h"
-#include "mtypes.h"
+#include "main/imports.h"
+#include "main/mtypes.h"
#include "slang_typeinfo.h"
#include "slang_compile_variable.h"
#include "slang_compile_struct.h"
diff --git a/src/mesa/shader/slang/slang_compile_function.c b/src/mesa/shader/slang/slang_compile_function.c
index 80769b33ae..8405d7f778 100644
--- a/src/mesa/shader/slang/slang_compile_function.c
+++ b/src/mesa/shader/slang/slang_compile_function.c
@@ -28,7 +28,7 @@
* \author Michal Krol
*/
-#include "imports.h"
+#include "main/imports.h"
#include "slang_compile.h"
#include "slang_mem.h"
diff --git a/src/mesa/shader/slang/slang_compile_operation.c b/src/mesa/shader/slang/slang_compile_operation.c
index 4d2fd5b666..c0d469c829 100644
--- a/src/mesa/shader/slang/slang_compile_operation.c
+++ b/src/mesa/shader/slang/slang_compile_operation.c
@@ -28,7 +28,7 @@
* \author Michal Krol
*/
-#include "imports.h"
+#include "main/imports.h"
#include "slang_compile.h"
#include "slang_mem.h"
diff --git a/src/mesa/shader/slang/slang_compile_struct.c b/src/mesa/shader/slang/slang_compile_struct.c
index 96bdb1f491..e6c38730d7 100644
--- a/src/mesa/shader/slang/slang_compile_struct.c
+++ b/src/mesa/shader/slang/slang_compile_struct.c
@@ -28,7 +28,7 @@
* \author Michal Krol
*/
-#include "imports.h"
+#include "main/imports.h"
#include "slang_mem.h"
#include "slang_compile.h"
diff --git a/src/mesa/shader/slang/slang_compile_variable.c b/src/mesa/shader/slang/slang_compile_variable.c
index d53255075f..3428b49e16 100644
--- a/src/mesa/shader/slang/slang_compile_variable.c
+++ b/src/mesa/shader/slang/slang_compile_variable.c
@@ -28,7 +28,7 @@
* \author Michal Krol
*/
-#include "imports.h"
+#include "main/imports.h"
#include "slang_compile.h"
#include "slang_mem.h"
@@ -267,6 +267,7 @@ slang_variable_construct(slang_variable * var)
var->size = 0;
var->isTemp = GL_FALSE;
var->aux = NULL;
+ var->declared = 0;
return 1;
}
@@ -325,16 +326,23 @@ slang_variable_copy(slang_variable * x, const slang_variable * y)
}
+/**
+ * Search for named variable in given scope.
+ * \param all if true, search parent scopes too.
+ */
slang_variable *
_slang_locate_variable(const slang_variable_scope * scope,
const slang_atom a_name, GLboolean all)
{
- GLuint i;
-
- for (i = 0; i < scope->num_variables; i++)
- if (a_name == scope->variables[i]->a_name)
- return scope->variables[i];
- if (all && scope->outer_scope != NULL)
- return _slang_locate_variable(scope->outer_scope, a_name, 1);
+ while (scope) {
+ GLuint i;
+ for (i = 0; i < scope->num_variables; i++)
+ if (a_name == scope->variables[i]->a_name)
+ return scope->variables[i];
+ if (all)
+ scope = scope->outer_scope;
+ else
+ scope = NULL;
+ }
return NULL;
}
diff --git a/src/mesa/shader/slang/slang_emit.c b/src/mesa/shader/slang/slang_emit.c
index 912c325bb2..f1af6902ea 100644
--- a/src/mesa/shader/slang/slang_emit.c
+++ b/src/mesa/shader/slang/slang_emit.c
@@ -161,9 +161,7 @@ free_temp_storage(slang_var_table *vt, slang_ir_node *n)
if (_slang_is_temp(vt, n->Store)) {
_slang_free_temp(vt, n->Store);
n->Store->Index = -1;
- n->Store->Size = -1;
- /*_mesa_free(n->Store);*/ /* XXX leak */
- n->Store = NULL;
+ n->Store = NULL; /* XXX this may not be needed */
}
}
}
@@ -258,6 +256,12 @@ storage_to_src_reg(struct prog_src_register *src, const slang_ir_storage *st)
}
assert(st->File >= 0);
+#if 1 /* XXX temporary */
+ if (st->File == PROGRAM_UNDEFINED) {
+ slang_ir_storage *st0 = (slang_ir_storage *) st;
+ st0->File = PROGRAM_TEMPORARY;
+ }
+#endif
assert(st->File < PROGRAM_UNDEFINED);
src->File = st->File;
@@ -627,7 +631,11 @@ emit_compare(slang_emit_info *emitInfo, slang_ir_node *n)
emit(emitInfo, n->Children[0]);
emit(emitInfo, n->Children[1]);
- assert(n->Children[0]->Store->Size == n->Children[1]->Store->Size);
+ if (n->Children[0]->Store->Size != n->Children[1]->Store->Size) {
+ slang_info_log_error(emitInfo->log, "invalid operands to == or !=");
+ return NULL;
+ }
+
size = n->Children[0]->Store->Size;
if (size == 1) {
@@ -717,10 +725,10 @@ emit_compare(slang_emit_info *emitInfo, slang_ir_node *n)
for (i = 0; i < num; i++) {
/* SNE t0, left[i], right[i] */
inst = new_instruction(emitInfo, OPCODE_SNE);
- inst->SrcReg[0].File = n->Children[0]->Store->File;
- inst->SrcReg[0].Index = n->Children[0]->Store->Index + i;
- inst->SrcReg[1].File = n->Children[1]->Store->File;
- inst->SrcReg[1].Index = n->Children[1]->Store->Index + i;
+ storage_to_src_reg(&inst->SrcReg[0], n->Children[0]->Store);
+ storage_to_src_reg(&inst->SrcReg[1], n->Children[1]->Store);
+ inst->SrcReg[0].Index += i;
+ inst->SrcReg[1].Index += i;
if (i == 0) {
inst->DstReg.File = accTemp.File;
inst->DstReg.Index = accTemp.Index;
@@ -1547,48 +1555,24 @@ emit_array_element(slang_emit_info *emitInfo, slang_ir_node *n)
return NULL;
}
- if (n->Children[1]->Opcode == IR_FLOAT) {
- /* Constant array index */
-#if 0 /* just debug code */
- const GLint arrayAddr = n->Children[0]->Store->Index;
- const GLint index = (GLint) n->Children[1]->Value[0];
- assert(index == n->Store->Index);
- assert(arrayAddr == parent->Index);
- assert(n->Children[0]->Store == parent);
- assert(n->Children[0]->Store->Index == parent->Index);
-#endif
-
- GLint index = n->Store->Index;
-
- slang_ir_storage *p = n->Store;
- index = 0;
- while (p->Parent) {
- int sz = (p->Size + 3) / 4;
- /*printf("element [%d] of size %d (%d)\n", p->Index, p->Size, sz);*/
- index += sz * p->Index;
- p = p->Parent;
- }
- index += p->Index;
-
- assert(root->File != PROGRAM_UNDEFINED);
+ /* do codegen for array */
+ emit(emitInfo, n->Children[0]);
- /* resolve new absolute storage location */
- assert(n->Store);
- n->Store->File = root->File;
- if (root->File == PROGRAM_STATE_VAR)
- n->Store->Index = 0;
- else
- n->Store->Index = index;
+ if (n->Children[1]->Opcode == IR_FLOAT) {
+ /* Constant array index.
+ * Set Store's index to be the offset of the array element in
+ * the register file.
+ */
+ const GLint element = (GLint) n->Children[1]->Value[0];
+ const GLint sz = (n->Store->Size + 3) / 4; /* size in slots/registers */
- n->Store->Parent = NULL;
+ n->Store->Index = sz * element;
+ assert(n->Store->Parent);
}
else {
/* Variable array index */
struct prog_instruction *inst;
- /* do codegen for array */
- emit(emitInfo, n->Children[0]);
-
/* do codegen for array index expression */
emit(emitInfo, n->Children[1]);
diff --git a/src/mesa/shader/slang/slang_emit.h b/src/mesa/shader/slang/slang_emit.h
index 153e872d74..4db4bbe562 100644
--- a/src/mesa/shader/slang/slang_emit.h
+++ b/src/mesa/shader/slang/slang_emit.h
@@ -26,10 +26,10 @@
#define SLANG_EMIT_H
-#include "imports.h"
+#include "main/imports.h"
#include "slang_compile.h"
#include "slang_ir.h"
-#include "mtypes.h"
+#include "main/mtypes.h"
extern void
diff --git a/src/mesa/shader/slang/slang_ir.c b/src/mesa/shader/slang/slang_ir.c
index a414036a36..23d554234e 100644
--- a/src/mesa/shader/slang/slang_ir.c
+++ b/src/mesa/shader/slang/slang_ir.c
@@ -23,8 +23,8 @@
*/
-#include "imports.h"
-#include "context.h"
+#include "main/imports.h"
+#include "main/context.h"
#include "slang_ir.h"
#include "slang_mem.h"
#include "shader/prog_print.h"
diff --git a/src/mesa/shader/slang/slang_ir.h b/src/mesa/shader/slang/slang_ir.h
index 61ff649e5c..e4697ba3b4 100644
--- a/src/mesa/shader/slang/slang_ir.h
+++ b/src/mesa/shader/slang/slang_ir.h
@@ -33,10 +33,10 @@
#define SLANG_IR_H
-#include "imports.h"
+#include "main/imports.h"
#include "slang_compile.h"
#include "slang_label.h"
-#include "mtypes.h"
+#include "main/mtypes.h"
/**
diff --git a/src/mesa/shader/slang/slang_library_noise.c b/src/mesa/shader/slang/slang_library_noise.c
index 46075c492c..25a05657cc 100644
--- a/src/mesa/shader/slang/slang_library_noise.c
+++ b/src/mesa/shader/slang/slang_library_noise.c
@@ -49,7 +49,7 @@
*/
-#include "imports.h"
+#include "main/imports.h"
#include "slang_library_noise.h"
#define FASTFLOOR(x) ( ((x)>0) ? ((int)x) : (((int)x)-1) )
diff --git a/src/mesa/shader/slang/slang_link.c b/src/mesa/shader/slang/slang_link.c
index e9b9bbc43f..1de561930a 100644
--- a/src/mesa/shader/slang/slang_link.c
+++ b/src/mesa/shader/slang/slang_link.c
@@ -401,15 +401,16 @@ _slang_link(GLcontext *ctx,
shProg->Varying = _mesa_new_parameter_list();
/**
- * Find attached vertex shader, fragment shader
+ * Find attached vertex, fragment shaders defining main()
*/
vertProg = NULL;
fragProg = NULL;
for (i = 0; i < shProg->NumShaders; i++) {
- if (shProg->Shaders[i]->Type == GL_VERTEX_SHADER)
- vertProg = vertex_program(shProg->Shaders[i]->Programs[0]);
- else if (shProg->Shaders[i]->Type == GL_FRAGMENT_SHADER)
- fragProg = fragment_program(shProg->Shaders[i]->Programs[0]);
+ struct gl_shader *shader = shProg->Shaders[i];
+ if (shader->Type == GL_VERTEX_SHADER && shader->Main)
+ vertProg = vertex_program(shader->Program);
+ else if (shader->Type == GL_FRAGMENT_SHADER && shader->Main)
+ fragProg = fragment_program(shader->Program);
else
_mesa_problem(ctx, "unexpected shader target in slang_link()");
}
diff --git a/src/mesa/shader/slang/slang_log.c b/src/mesa/shader/slang/slang_log.c
index c963914fe3..01591ceba5 100644
--- a/src/mesa/shader/slang/slang_log.c
+++ b/src/mesa/shader/slang/slang_log.c
@@ -22,7 +22,7 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-#include "imports.h"
+#include "main/imports.h"
#include "slang_log.h"
#include "slang_utility.h"
diff --git a/src/mesa/shader/slang/slang_mem.c b/src/mesa/shader/slang/slang_mem.c
index e1d1e6ba14..21d6bfce88 100644
--- a/src/mesa/shader/slang/slang_mem.c
+++ b/src/mesa/shader/slang/slang_mem.c
@@ -32,8 +32,8 @@
* \author Brian Paul
*/
-#include "context.h"
-#include "macros.h"
+#include "main/context.h"
+#include "main/macros.h"
#include "slang_mem.h"
diff --git a/src/mesa/shader/slang/slang_mem.h b/src/mesa/shader/slang/slang_mem.h
index 49885b6c98..b5bfae2479 100644
--- a/src/mesa/shader/slang/slang_mem.h
+++ b/src/mesa/shader/slang/slang_mem.h
@@ -27,7 +27,7 @@
#define SLANG_MEM_H
-#include "imports.h"
+#include "main/imports.h"
typedef struct slang_mempool_ slang_mempool;
diff --git a/src/mesa/shader/slang/slang_preprocess.c b/src/mesa/shader/slang/slang_preprocess.c
index d3f412c211..bfe29b6bc9 100644
--- a/src/mesa/shader/slang/slang_preprocess.c
+++ b/src/mesa/shader/slang/slang_preprocess.c
@@ -28,7 +28,7 @@
* \author Michal Krol
*/
-#include "imports.h"
+#include "main/imports.h"
#include "shader/grammar/grammar_mesa.h"
#include "slang_preprocess.h"
diff --git a/src/mesa/shader/slang/slang_print.c b/src/mesa/shader/slang/slang_print.c
index f48762fb11..4422f70159 100644
--- a/src/mesa/shader/slang/slang_print.c
+++ b/src/mesa/shader/slang/slang_print.c
@@ -4,7 +4,7 @@
*/
-#include "imports.h"
+#include "main/imports.h"
#include "slang_compile.h"
#include "slang_print.h"
diff --git a/src/mesa/shader/slang/slang_simplify.c b/src/mesa/shader/slang/slang_simplify.c
index 88ca83d288..c4bf0175be 100644
--- a/src/mesa/shader/slang/slang_simplify.c
+++ b/src/mesa/shader/slang/slang_simplify.c
@@ -1,8 +1,8 @@
/*
* Mesa 3-D graphics library
- * Version: 6.5.2
+ * Version: 7.1
*
- * Copyright (C) 2005-2006 Brian Paul All Rights Reserved.
+ * Copyright (C) 2005-2008 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -23,20 +23,29 @@
*/
/**
- * \file slang_assemble_typeinfo.c
- * slang type info
- * \author Michal Krol
+ * Functions for constant folding, built-in constant lookup, and function
+ * call casting.
*/
-#include "imports.h"
-#include "macros.h"
-#include "get.h"
+
+#include "main/imports.h"
+#include "main/macros.h"
+#include "main/get.h"
#include "slang_compile.h"
#include "slang_codegen.h"
#include "slang_simplify.h"
#include "slang_print.h"
+#ifndef GL_MAX_FRAGMENT_UNIFORM_VECTORS
+#define GL_MAX_FRAGMENT_UNIFORM_VECTORS 0x8DFD
+#endif
+#ifndef GL_MAX_VERTEX_UNIFORM_VECTORS
+#define GL_MAX_VERTEX_UNIFORM_VECTORS 0x8DFB
+#endif
+#ifndef GL_MAX_VARYING_VECTORS
+#define GL_MAX_VARYING_VECTORS 0x8DFC
+#endif
/**
@@ -49,25 +58,24 @@ _slang_lookup_constant(const char *name)
struct constant_info {
const char *Name;
const GLenum Token;
- GLint Divisor;
};
static const struct constant_info info[] = {
- { "gl_MaxClipPlanes", GL_MAX_CLIP_PLANES, 1 },
- { "gl_MaxCombinedTextureImageUnits", GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, 1 },
- { "gl_MaxDrawBuffers", GL_MAX_DRAW_BUFFERS, 1 },
- { "gl_MaxFragmentUniformComponents", GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, 1 },
- { "gl_MaxLights", GL_MAX_LIGHTS, 1 },
- { "gl_MaxTextureUnits", GL_MAX_TEXTURE_UNITS, 1 },
- { "gl_MaxTextureCoords", GL_MAX_TEXTURE_COORDS, 1 },
- { "gl_MaxVertexAttribs", GL_MAX_VERTEX_ATTRIBS, 1 },
- { "gl_MaxVertexUniformComponents", GL_MAX_VERTEX_UNIFORM_COMPONENTS, 1 },
- { "gl_MaxVaryingFloats", GL_MAX_VARYING_FLOATS, 1 },
- { "gl_MaxVertexTextureImageUnits", GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, 1 },
- { "gl_MaxTextureImageUnits", GL_MAX_TEXTURE_IMAGE_UNITS, 1 },
+ { "gl_MaxClipPlanes", GL_MAX_CLIP_PLANES },
+ { "gl_MaxCombinedTextureImageUnits", GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS },
+ { "gl_MaxDrawBuffers", GL_MAX_DRAW_BUFFERS },
+ { "gl_MaxFragmentUniformComponents", GL_MAX_FRAGMENT_UNIFORM_COMPONENTS },
+ { "gl_MaxLights", GL_MAX_LIGHTS },
+ { "gl_MaxTextureUnits", GL_MAX_TEXTURE_UNITS },
+ { "gl_MaxTextureCoords", GL_MAX_TEXTURE_COORDS },
+ { "gl_MaxVertexAttribs", GL_MAX_VERTEX_ATTRIBS },
+ { "gl_MaxVertexUniformComponents", GL_MAX_VERTEX_UNIFORM_COMPONENTS },
+ { "gl_MaxVaryingFloats", GL_MAX_VARYING_FLOATS },
+ { "gl_MaxVertexTextureImageUnits", GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS },
+ { "gl_MaxTextureImageUnits", GL_MAX_TEXTURE_IMAGE_UNITS },
#if FEATURE_es2_glsl
- { "gl_MaxVertexUniformVectors", GL_MAX_VERTEX_UNIFORM_COMPONENTS, 4 },
- { "gl_MaxVaryingVectors", GL_MAX_VARYING_FLOATS, 4 },
- { "gl_MaxFragmentUniformVectors", GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, 4 },
+ { "gl_MaxVertexUniformVectors", GL_MAX_VERTEX_UNIFORM_VECTORS },
+ { "gl_MaxVaryingVectors", GL_MAX_VARYING_VECTORS },
+ { "gl_MaxFragmentUniformVectors", GL_MAX_FRAGMENT_UNIFORM_VECTORS },
#endif
{ NULL, 0 }
};
@@ -79,7 +87,7 @@ _slang_lookup_constant(const char *name)
GLint value = -1;
_mesa_GetIntegerv(info[i].Token, &value);
ASSERT(value >= 0); /* sanity check that glGetFloatv worked */
- return value / info[i].Divisor;
+ return value;
}
}
return -1;
@@ -306,112 +314,28 @@ _slang_simplify(slang_operation *oper,
/**
- * Adapt the arguments for a function call to match the parameters of
- * the given function.
- * This is for:
- * 1. converting/casting argument types to match parameters
- * 2. breaking up vector/matrix types into individual components to
- * satisfy constructors.
+ * Insert casts to try to adapt actual parameters to formal parameters for a
+ * function call when an exact match for the parameter types is not found.
+ * Example:
+ * void foo(int i, bool b) {}
+ * x = foo(3.15, 9);
+ * Gets translated into:
+ * x = foo(int(3.15), bool(9))
*/
GLboolean
-_slang_adapt_call(slang_operation *callOper, const slang_function *fun,
- const slang_name_space * space,
- slang_atom_pool * atoms, slang_info_log *log)
+_slang_cast_func_params(slang_operation *callOper, const slang_function *fun,
+ const slang_name_space * space,
+ slang_atom_pool * atoms, slang_info_log *log)
{
const GLboolean haveRetValue = _slang_function_has_return_value(fun);
const int numParams = fun->param_count - haveRetValue;
int i;
int dbg = 0;
- if (dbg) printf("Adapt %d args to %d parameters\n",
- callOper->num_children, numParams);
-
- /* Only try adapting for constructors */
- if (fun->kind != SLANG_FUNC_CONSTRUCTOR)
- return GL_FALSE;
-
- if (callOper->num_children != numParams) {
- /* number of arguments doesn't match number of parameters */
-
- if (fun->kind == SLANG_FUNC_CONSTRUCTOR) {
- /* For constructor calls, we can try to unroll vector/matrix args
- * into individual floats/ints and try to match the function params.
- */
- for (i = 0; i < numParams; i++) {
- slang_typeinfo argType;
- GLint argSz, j;
-
- /* Get type of arg[i] */
- if (!slang_typeinfo_construct(&argType))
- return GL_FALSE;
- if (!_slang_typeof_operation_(&callOper->children[i], space,
- &argType, atoms, log)) {
- slang_typeinfo_destruct(&argType);
- return GL_FALSE;
- }
-
- /*
- paramSz = _slang_sizeof_type_specifier(&paramVar->type.specifier);
- assert(paramSz == 1);
- */
- argSz = _slang_sizeof_type_specifier(&argType.spec);
- if (argSz > 1) {
- slang_operation origArg;
- /* break up arg[i] into components */
- if (dbg)
- printf("Break up arg %d from 1 to %d elements\n", i, argSz);
-
- slang_operation_construct(&origArg);
- slang_operation_copy(&origArg,
- &callOper->children[i]);
-
- /* insert argSz-1 new children/args */
- for (j = 0; j < argSz - 1; j++) {
- (void) slang_operation_insert(&callOper->num_children,
- &callOper->children, i);
- }
-
- /* replace arg[i+j] with subscript/index oper */
- for (j = 0; j < argSz; j++) {
- callOper->children[i + j].type = SLANG_OPER_SUBSCRIPT;
- callOper->children[i + j].num_children = 2;
- callOper->children[i + j].children = slang_operation_new(2);
- slang_operation_copy(&callOper->children[i + j].children[0],
- &origArg);
- callOper->children[i + j].children[1].type
- = SLANG_OPER_LITERAL_INT;
- callOper->children[i + j].children[1].literal[0] = (GLfloat) j;
- }
+ if (dbg)
+ printf("Adapt call of %d args to func %s (%d params)\n",
+ callOper->num_children, (char*) fun->header.a_name, numParams);
- }
- } /* for i */
- }
- else {
- /* non-constructor function: number of args must match number
- * of function params.
- */
- return GL_FALSE; /* caller will record an error msg */
- }
- }
-
- if (callOper->num_children < (GLuint) numParams) {
- /* still not enough args for all params */
- return GL_FALSE;
- }
- else if (callOper->num_children > (GLuint) numParams) {
- /* now too many arguments */
- /* XXX this isn't always an error, see spec */
- return GL_FALSE;
- }
-
- /*
- * Second phase, argument casting.
- * Example:
- * void foo(int i, bool b) {}
- * x = foo(3.15, 9);
- * Gets translated into:
- * x = foo(int(3.15), bool(9))
- */
for (i = 0; i < numParams; i++) {
slang_typeinfo argType;
slang_variable *paramVar = fun->parameters->variables[i];
@@ -433,9 +357,18 @@ _slang_adapt_call(slang_operation *callOper, const slang_function *fun,
slang_type_specifier_type_to_string(paramVar->type.specifier.type);
slang_operation *child = slang_operation_new(1);
+ if (dbg)
+ printf("Need to adapt types of arg %d\n", i);
+
slang_operation_copy(child, &callOper->children[i]);
child->locals->outer_scope = callOper->children[i].locals;
+#if 0
+ if (_slang_sizeof_type_specifier(&argType.spec) >
+ _slang_sizeof_type_specifier(&paramVar->type.specifier)) {
+ }
+#endif
+
callOper->children[i].type = SLANG_OPER_CALL;
callOper->children[i].a_id = slang_atom_pool_atom(atoms, constructorName);
callOper->children[i].num_children = 1;
@@ -446,6 +379,107 @@ _slang_adapt_call(slang_operation *callOper, const slang_function *fun,
}
if (dbg) {
+ printf("===== New call to %s with cast arguments ===============\n",
+ (char*) fun->header.a_name);
+ slang_print_tree(callOper, 5);
+ }
+
+ return GL_TRUE;
+}
+
+
+/**
+ * Adapt the arguments for a function call to match the parameters of
+ * the given function.
+ * This is for:
+ * 1. converting/casting argument types to match parameters
+ * 2. breaking up vector/matrix types into individual components to
+ * satisfy constructors.
+ */
+GLboolean
+_slang_adapt_call(slang_operation *callOper, const slang_function *fun,
+ const slang_name_space * space,
+ slang_atom_pool * atoms, slang_info_log *log)
+{
+ const GLboolean haveRetValue = _slang_function_has_return_value(fun);
+ const int numParams = fun->param_count - haveRetValue;
+ int i;
+ int dbg = 0;
+
+ if (dbg)
+ printf("Adapt %d args to %d parameters for %s\n",
+ callOper->num_children, numParams, (char *) fun->header.a_name);
+
+ /* Only try adapting for constructors */
+ if (fun->kind != SLANG_FUNC_CONSTRUCTOR)
+ return GL_FALSE;
+
+ if (callOper->num_children != numParams) {
+ /* number of arguments doesn't match number of parameters */
+
+ /* For constructor calls, we can try to unroll vector/matrix args
+ * into individual floats/ints and try to match the function params.
+ */
+ for (i = 0; i < numParams; i++) {
+ slang_typeinfo argType;
+ GLint argSz, j;
+
+ /* Get type of arg[i] */
+ if (!slang_typeinfo_construct(&argType))
+ return GL_FALSE;
+ if (!_slang_typeof_operation_(&callOper->children[i], space,
+ &argType, atoms, log)) {
+ slang_typeinfo_destruct(&argType);
+ return GL_FALSE;
+ }
+
+ /*
+ paramSz = _slang_sizeof_type_specifier(&paramVar->type.specifier);
+ assert(paramSz == 1);
+ */
+ argSz = _slang_sizeof_type_specifier(&argType.spec);
+ if (argSz > 1) {
+ slang_operation origArg;
+ /* break up arg[i] into components */
+ if (dbg)
+ printf("Break up arg %d from 1 to %d elements\n", i, argSz);
+
+ slang_operation_construct(&origArg);
+ slang_operation_copy(&origArg, &callOper->children[i]);
+
+ /* insert argSz-1 new children/args */
+ for (j = 0; j < argSz - 1; j++) {
+ (void) slang_operation_insert(&callOper->num_children,
+ &callOper->children, i);
+ }
+
+ /* replace arg[i+j] with subscript/index oper */
+ for (j = 0; j < argSz; j++) {
+ callOper->children[i + j].type = SLANG_OPER_SUBSCRIPT;
+ callOper->children[i + j].locals = _slang_variable_scope_new(callOper->locals);
+ callOper->children[i + j].num_children = 2;
+ callOper->children[i + j].children = slang_operation_new(2);
+ slang_operation_copy(&callOper->children[i + j].children[0],
+ &origArg);
+ callOper->children[i + j].children[1].type
+ = SLANG_OPER_LITERAL_INT;
+ callOper->children[i + j].children[1].literal[0] = (GLfloat) j;
+ }
+ }
+ }
+ }
+
+ if (callOper->num_children < (GLuint) numParams) {
+ /* still not enough args for all params */
+ return GL_FALSE;
+ }
+ else if (callOper->num_children > (GLuint) numParams) {
+ /* now too many arguments */
+ /* just truncate */
+ callOper->num_children = (GLuint) numParams;
+ }
+
+ if (dbg) {
printf("===== New call to %s with adapted arguments ===============\n",
(char*) fun->header.a_name);
slang_print_tree(callOper, 5);
diff --git a/src/mesa/shader/slang/slang_simplify.h b/src/mesa/shader/slang/slang_simplify.h
index b3840ee9df..8689c23b1a 100644
--- a/src/mesa/shader/slang/slang_simplify.h
+++ b/src/mesa/shader/slang/slang_simplify.h
@@ -1,3 +1,26 @@
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.1
+ *
+ * Copyright (C) 2005-2008 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
#ifndef SLANG_SIMPLIFY_H
#define SLANG_SIMPLIFY_H
@@ -14,6 +37,11 @@ _slang_simplify(slang_operation *oper,
extern GLboolean
+_slang_cast_func_params(slang_operation *callOper, const slang_function *fun,
+ const slang_name_space * space,
+ slang_atom_pool * atoms, slang_info_log *log);
+
+extern GLboolean
_slang_adapt_call(slang_operation *callOper, const slang_function *fun,
const slang_name_space * space,
slang_atom_pool * atoms, slang_info_log *log);
diff --git a/src/mesa/shader/slang/slang_storage.c b/src/mesa/shader/slang/slang_storage.c
index bc32aa4b02..e8b0fb7747 100644
--- a/src/mesa/shader/slang/slang_storage.c
+++ b/src/mesa/shader/slang/slang_storage.c
@@ -28,7 +28,7 @@
* \author Michal Krol
*/
-#include "imports.h"
+#include "main/imports.h"
#include "slang_storage.h"
#include "slang_mem.h"
diff --git a/src/mesa/shader/slang/slang_typeinfo.c b/src/mesa/shader/slang/slang_typeinfo.c
index 8a1c3abf48..26f9f6ca85 100644
--- a/src/mesa/shader/slang/slang_typeinfo.c
+++ b/src/mesa/shader/slang/slang_typeinfo.c
@@ -273,6 +273,7 @@ slang_type_specifier_compatible(const slang_type_specifier * x,
GLboolean
slang_typeinfo_construct(slang_typeinfo * ti)
{
+ /*_mesa_bzero(ti, sizeof(*ti));*/
slang_type_specifier_ctr(&ti->spec);
ti->array_len = 0;
return GL_TRUE;
@@ -304,10 +305,16 @@ _slang_typeof_function(slang_atom a_name,
slang_function **funFound,
slang_atom_pool *atoms, slang_info_log *log)
{
+ GLboolean error;
+
*funFound = _slang_locate_function(space->funcs, a_name, params,
- num_params, space, atoms, log);
+ num_params, space, atoms, log, &error);
+ if (error)
+ return GL_FALSE;
+
if (!*funFound)
return GL_TRUE; /* yes, not false */
+
return slang_type_specifier_copy(spec, &(*funFound)->header.type.specifier);
}
@@ -755,51 +762,66 @@ slang_function *
_slang_locate_function(const slang_function_scope * funcs, slang_atom a_name,
slang_operation * args, GLuint num_args,
const slang_name_space * space, slang_atom_pool * atoms,
- slang_info_log *log)
+ slang_info_log *log, GLboolean *error)
{
+ slang_typeinfo arg_ti[100];
GLuint i;
- for (i = 0; i < funcs->num_functions; i++) {
- slang_function *f = &funcs->functions[i];
- const GLuint haveRetValue = _slang_function_has_return_value(f);
- GLuint j;
-
- if (a_name != f->header.a_name)
- continue;
- if (f->param_count - haveRetValue != num_args)
- continue;
-
- /* compare parameter / argument types */
- for (j = 0; j < num_args; j++) {
- slang_typeinfo ti;
-
- if (!slang_typeinfo_construct(&ti))
- return NULL;
- if (!_slang_typeof_operation_(&args[j], space, &ti, atoms, log)) {
- slang_typeinfo_destruct(&ti);
- return NULL;
+ *error = GL_FALSE;
+
+ /* determine type of each argument */
+ assert(num_args < 100);
+ for (i = 0; i < num_args; i++) {
+ if (!slang_typeinfo_construct(&arg_ti[i]))
+ return NULL;
+ if (!_slang_typeof_operation_(&args[i], space, &arg_ti[i], atoms, log)) {
+ return NULL;
+ }
+ }
+
+ /* loop over function scopes */
+ while (funcs) {
+
+ /* look for function with matching name and argument/param types */
+ for (i = 0; i < funcs->num_functions; i++) {
+ slang_function *f = &funcs->functions[i];
+ const GLuint haveRetValue = _slang_function_has_return_value(f);
+ GLuint j;
+
+ if (a_name != f->header.a_name)
+ continue;
+ if (f->param_count - haveRetValue != num_args)
+ continue;
+
+ /* compare parameter / argument types */
+ for (j = 0; j < num_args; j++) {
+ if (!slang_type_specifier_compatible(&arg_ti[j].spec,
+ &f->parameters->variables[j]->type.specifier)) {
+ /* param/arg types don't match */
+ break;
+ }
+
+ /* "out" and "inout" formal parameter requires the actual
+ * argument to be an l-value.
+ */
+ if (!arg_ti[j].can_be_referenced &&
+ (f->parameters->variables[j]->type.qualifier == SLANG_QUAL_OUT ||
+ f->parameters->variables[j]->type.qualifier == SLANG_QUAL_INOUT)) {
+ /* param is not an lvalue! */
+ *error = GL_TRUE;
+ return NULL;
+ }
}
- if (!slang_type_specifier_compatible(&ti.spec,
- &f->parameters->variables[j]->type.specifier)) {
- slang_typeinfo_destruct(&ti);
- break;
+
+ if (j == num_args) {
+ /* name and args match! */
+ return f;
}
- slang_typeinfo_destruct(&ti);
-
- /* "out" and "inout" formal parameter requires the actual
- * parameter to be l-value.
- */
- if (!ti.can_be_referenced &&
- (f->parameters->variables[j]->type.qualifier == SLANG_QUAL_OUT ||
- f->parameters->variables[j]->type.qualifier == SLANG_QUAL_INOUT))
- break;
}
- if (j == num_args)
- return f;
+
+ funcs = funcs->outer_scope;
}
- if (funcs->outer_scope != NULL)
- return _slang_locate_function(funcs->outer_scope, a_name, args,
- num_args, space, atoms, log);
+
return NULL;
}
diff --git a/src/mesa/shader/slang/slang_typeinfo.h b/src/mesa/shader/slang/slang_typeinfo.h
index 587331e8b1..960e99bda2 100644
--- a/src/mesa/shader/slang/slang_typeinfo.h
+++ b/src/mesa/shader/slang/slang_typeinfo.h
@@ -25,8 +25,8 @@
#ifndef SLANG_TYPEINFO_H
#define SLANG_TYPEINFO_H 1
-#include "imports.h"
-#include "mtypes.h"
+#include "main/imports.h"
+#include "main/mtypes.h"
#include "slang_log.h"
#include "slang_utility.h"
#include "slang_vartable.h"
@@ -73,7 +73,8 @@ _slang_locate_function(const struct slang_function_scope_ *funcs,
slang_atom name, struct slang_operation_ *params,
GLuint num_params,
const slang_name_space *space,
- slang_atom_pool *atoms, slang_info_log *log);
+ slang_atom_pool *atoms, slang_info_log *log,
+ GLboolean *error);
extern GLboolean
diff --git a/src/mesa/shader/slang/slang_utility.c b/src/mesa/shader/slang/slang_utility.c
index 2a2dc8e54f..3631e32b3c 100644
--- a/src/mesa/shader/slang/slang_utility.c
+++ b/src/mesa/shader/slang/slang_utility.c
@@ -28,7 +28,7 @@
* \author Michal Krol
*/
-#include "imports.h"
+#include "main/imports.h"
#include "slang_utility.h"
#include "slang_mem.h"