summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMichal Krol <[email protected]>2006-02-18 15:11:18 +0000
committerMichal Krol <[email protected]>2006-02-18 15:11:18 +0000
commit3654193a4d417560c90b4bbe47d8070919cdc348 (patch)
tree9c984f7fe482f9af08575d6b3338cd4128e5455c /src
parente94be8d5c0b28c4eecf8492cb07ae9dff9026ada (diff)
More GLSL code.
- general constructors allowed; - implement noise functions (from Stefan Gustavson - thanks!) - cosmetic stuff.
Diffstat (limited to 'src')
-rwxr-xr-xsrc/mesa/shader/shaderobjects_3dlabs.c48
-rwxr-xr-xsrc/mesa/shader/slang/library/slang_common_builtin.gc645
-rw-r--r--src/mesa/shader/slang/library/slang_common_builtin_gc.h76
-rw-r--r--src/mesa/shader/slang/slang_assemble.c867
-rw-r--r--src/mesa/shader/slang/slang_assemble.h85
-rw-r--r--src/mesa/shader/slang/slang_assemble_assignment.c135
-rw-r--r--src/mesa/shader/slang/slang_assemble_assignment.h5
-rw-r--r--src/mesa/shader/slang/slang_assemble_conditional.c574
-rw-r--r--src/mesa/shader/slang/slang_assemble_conditional.h28
-rw-r--r--src/mesa/shader/slang/slang_assemble_constructor.c169
-rw-r--r--src/mesa/shader/slang/slang_assemble_constructor.h40
-rw-r--r--src/mesa/shader/slang/slang_assemble_typeinfo.c141
-rw-r--r--src/mesa/shader/slang/slang_assemble_typeinfo.h39
-rw-r--r--src/mesa/shader/slang/slang_compile.c1413
-rw-r--r--src/mesa/shader/slang/slang_compile_variable.c4
-rw-r--r--src/mesa/shader/slang/slang_compile_variable.h2
-rw-r--r--src/mesa/shader/slang/slang_execute.c33
-rw-r--r--src/mesa/shader/slang/slang_library_noise.c514
-rw-r--r--src/mesa/shader/slang/slang_library_noise.h42
-rw-r--r--src/mesa/shader/slang/slang_storage.c124
-rw-r--r--src/mesa/shader/slang/slang_storage.h80
-rw-r--r--src/mesa/sources1
-rw-r--r--src/mesa/tnl/t_vb_arbshader.c60
23 files changed, 2845 insertions, 2280 deletions
diff --git a/src/mesa/shader/shaderobjects_3dlabs.c b/src/mesa/shader/shaderobjects_3dlabs.c
index 66f3cba944b..84aba0862e4 100755
--- a/src/mesa/shader/shaderobjects_3dlabs.c
+++ b/src/mesa/shader/shaderobjects_3dlabs.c
@@ -1086,13 +1086,13 @@ static int fetch_mem (struct gl2_vertex_shader_intf **vs, const char *name, GLvo
{
GLubyte *data;
- data = get_address_of (vs, name) + index * size;
+ data = get_address_of (vs, name);
if (data == NULL)
return 0;
if (write)
- _mesa_memcpy (data, val, size);
+ _mesa_memcpy (data + index * size, val, size);
else
- _mesa_memcpy (val, data, size);
+ _mesa_memcpy (val, data + index * size, size);
return 1;
}
@@ -1101,13 +1101,13 @@ static int fetch_mem_f (struct gl2_fragment_shader_intf **fs, const char *name,
{
GLubyte *data;
- data = get_address_of_f (fs, name) + index * size;
+ data = get_address_of_f (fs, name);
if (data == NULL)
return 0;
if (write)
- _mesa_memcpy (data, val, size);
+ _mesa_memcpy (data + index * size, val, size);
else
- _mesa_memcpy (val, data, size);
+ _mesa_memcpy (val, data + index * size, size);
return 1;
}
@@ -1174,28 +1174,24 @@ void exec_vertex_shader (struct gl2_vertex_shader_intf **vs)
slang_function *f;
slang_assembly_file_restore_point point;
slang_machine mach;
- slang_assembly_local_info info;
- slang_assembly_name_space space;
slang_assemble_ctx A;
f = &unit->functions.functions[i];
slang_assembly_file_restore_point_save (unit->assembly, &point);
mach = *unit->machine;
mach.ip = unit->assembly->count;
- info.ret_size = 0;
- info.addr_tmp = 0;
- info.swizzle_tmp = 4;
- slang_assembly_file_push_label (unit->assembly, slang_asm_local_alloc, 20);
- slang_assembly_file_push_label (unit->assembly, slang_asm_enter, 20);
- space.funcs = &unit->functions;
- space.structs = &unit->structs;
- space.vars = &unit->globals;
+
A.file = unit->assembly;
A.mach = unit->machine;
A.atoms = unit->atom_pool;
- A.space = space;
+ A.space.funcs = &unit->functions;
+ A.space.structs = &unit->structs;
+ A.space.vars = &unit->globals;
+ slang_assembly_file_push_label (unit->assembly, slang_asm_local_alloc, 20);
+ slang_assembly_file_push_label (unit->assembly, slang_asm_enter, 20);
_slang_assemble_function_call (&A, f, NULL, 0, GL_FALSE);
slang_assembly_file_push (unit->assembly, slang_asm_exit);
+
_slang_execute2 (unit->assembly, &mach);
slang_assembly_file_restore_point_load (unit->assembly, &point);
_mesa_memcpy (unit->machine->mem, mach.mem, SLANG_MACHINE_MEMORY_SIZE * sizeof (slang_machine_slot));
@@ -1220,8 +1216,6 @@ void exec_fragment_shader (struct gl2_fragment_shader_intf **fs)
slang_function *f;
slang_assembly_file_restore_point point;
slang_machine mach;
- slang_assembly_local_info info;
- slang_assembly_name_space space;
slang_assemble_ctx A;
f = &unit->functions.functions[i];
@@ -1229,20 +1223,18 @@ void exec_fragment_shader (struct gl2_fragment_shader_intf **fs)
mach = *unit->machine;
mach.ip = unit->assembly->count;
mach.kill = 0;
- info.ret_size = 0;
- info.addr_tmp = 0;
- info.swizzle_tmp = 4;
- slang_assembly_file_push_label (unit->assembly, slang_asm_local_alloc, 20);
- slang_assembly_file_push_label (unit->assembly, slang_asm_enter, 20);
- space.funcs = &unit->functions;
- space.structs = &unit->structs;
- space.vars = &unit->globals;
+
A.file = unit->assembly;
A.mach = unit->machine;
A.atoms = unit->atom_pool;
- A.space = space;
+ A.space.funcs = &unit->functions;
+ A.space.structs = &unit->structs;
+ A.space.vars = &unit->globals;
+ slang_assembly_file_push_label (unit->assembly, slang_asm_local_alloc, 20);
+ slang_assembly_file_push_label (unit->assembly, slang_asm_enter, 20);
_slang_assemble_function_call (&A, f, NULL, 0, GL_FALSE);
slang_assembly_file_push (unit->assembly, slang_asm_exit);
+
_slang_execute2 (unit->assembly, &mach);
slang_assembly_file_restore_point_load (unit->assembly, &point);
_mesa_memcpy (unit->machine->mem, mach.mem, SLANG_MACHINE_MEMORY_SIZE * sizeof (slang_machine_slot));
diff --git a/src/mesa/shader/slang/library/slang_common_builtin.gc b/src/mesa/shader/slang/library/slang_common_builtin.gc
index 094bc798846..c7c27419a91 100755
--- a/src/mesa/shader/slang/library/slang_common_builtin.gc
+++ b/src/mesa/shader/slang/library/slang_common_builtin.gc
@@ -3,7 +3,6 @@
// TODO:
// - implement texture1D, texture2D, texture3D, textureCube,
// - implement shadow1D, shadow2D,
-// - implement noise1, noise2, noise3, noise4,
//
//
@@ -351,14 +350,14 @@ vec4 atan (vec4 y_over_x) {
float atan (float y, float x) {
float z;
- z = atan (y / x);
+ z = atan (y / x);
if (x < 0.0)
- {
- if (y < 0.0)
- return z - 3.141593;
- return z + 3.141593;
- }
- return z;
+ {
+ if (y < 0.0)
+ return z - 3.141593;
+ return z + 3.141593;
+ }
+ return z;
}
vec2 atan (vec2 u, vec2 v) {
@@ -538,26 +537,26 @@ float abs (float x) {
}
vec2 abs (vec2 v) {
- vec2 u;
- u.x = abs (v.x);
- u.y = abs (v.y);
+ vec2 u;
+ u.x = abs (v.x);
+ u.y = abs (v.y);
return u;
}
vec3 abs (vec3 v) {
vec3 u;
- u.x = abs (v.x);
- u.y = abs (v.y);
- u.z = abs (v.z);
+ u.x = abs (v.x);
+ u.y = abs (v.y);
+ u.z = abs (v.z);
return u;
}
vec4 abs (vec4 v) {
vec4 u;
- u.x = abs (v.x);
- u.y = abs (v.y);
- u.z = abs (v.z);
- u.w = abs (v.w);
+ u.x = abs (v.x);
+ u.y = abs (v.y);
+ u.z = abs (v.z);
+ u.w = abs (v.w);
return u;
}
@@ -567,85 +566,85 @@ float sign (float x) {
vec2 sign (vec2 v) {
vec2 u;
- u.x = sign (v.x);
- u.y = sign (v.y);
+ u.x = sign (v.x);
+ u.y = sign (v.y);
return u;
}
vec3 sign (vec3 v) {
vec3 u;
- u.x = sign (v.x);
- u.y = sign (v.y);
- u.z = sign (v.z);
+ u.x = sign (v.x);
+ u.y = sign (v.y);
+ u.z = sign (v.z);
return u;
}
vec4 sign (vec4 v) {
vec4 u;
- u.x = sign (v.x);
- u.y = sign (v.y);
- u.z = sign (v.z);
- u.w = sign (v.w);
+ u.x = sign (v.x);
+ u.y = sign (v.y);
+ u.z = sign (v.z);
+ u.w = sign (v.w);
return u;
}
float floor (float x) {
float y;
- __asm float_floor y, x;
- return y;
+ __asm float_floor y, x;
+ return y;
}
vec2 floor (vec2 v) {
vec2 u;
- u.x = floor (v.x);
- u.y = floor (v.y);
+ u.x = floor (v.x);
+ u.y = floor (v.y);
return u;
}
vec3 floor (vec3 v) {
vec3 u;
- u.x = floor (v.x);
- u.y = floor (v.y);
- u.z = floor (v.z);
+ u.x = floor (v.x);
+ u.y = floor (v.y);
+ u.z = floor (v.z);
return u;
}
vec4 floor (vec4 v) {
vec4 u;
- u.x = floor (v.x);
- u.y = floor (v.y);
- u.z = floor (v.z);
- u.w = floor (v.w);
+ u.x = floor (v.x);
+ u.y = floor (v.y);
+ u.z = floor (v.z);
+ u.w = floor (v.w);
return u;
}
float ceil (float x) {
float y;
- __asm float_ceil y, x;
- return y;
+ __asm float_ceil y, x;
+ return y;
}
vec2 ceil (vec2 v) {
vec2 u;
- u.x = ceil (v.x);
- u.y = ceil (v.y);
+ u.x = ceil (v.x);
+ u.y = ceil (v.y);
return u;
}
vec3 ceil (vec3 v) {
vec3 u;
- u.x = ceil (v.x);
- u.y = ceil (v.y);
- u.z = ceil (v.z);
+ u.x = ceil (v.x);
+ u.y = ceil (v.y);
+ u.z = ceil (v.z);
return u;
}
vec4 ceil (vec4 v) {
vec4 u;
- u.x = ceil (v.x);
- u.y = ceil (v.y);
- u.z = ceil (v.z);
- u.w = ceil (v.w);
+ u.x = ceil (v.x);
+ u.y = ceil (v.y);
+ u.z = ceil (v.z);
+ u.w = ceil (v.w);
return u;
}
@@ -699,26 +698,26 @@ float min (float x, float y) {
vec2 min (vec2 v, vec2 u) {
vec2 t;
- t.x = min (v.x, u.x);
- t.y = min (v.y, u.y);
- return t;
+ t.x = min (v.x, u.x);
+ t.y = min (v.y, u.y);
+ return t;
}
vec3 min (vec3 v, vec3 u) {
vec3 t;
- t.x = min (v.x, u.x);
- t.y = min (v.y, u.y);
- t.z = min (v.z, u.z);
- return t;
+ t.x = min (v.x, u.x);
+ t.y = min (v.y, u.y);
+ t.z = min (v.z, u.z);
+ return t;
}
vec4 min (vec4 v, vec4 u) {
vec4 t;
- t.x = min (v.x, u.x);
- t.y = min (v.y, u.y);
- t.z = min (v.z, u.z);
- t.w = min (v.w, u.w);
- return t;
+ t.x = min (v.x, u.x);
+ t.y = min (v.y, u.y);
+ t.z = min (v.z, u.z);
+ t.w = min (v.w, u.w);
+ return t;
}
vec2 min (vec2 v, float y) {
@@ -739,26 +738,26 @@ float max (float x, float y) {
vec2 max (vec2 v, vec2 u) {
vec2 t;
- t.x = max (v.x, u.x);
- t.y = max (v.y, u.y);
- return t;
+ t.x = max (v.x, u.x);
+ t.y = max (v.y, u.y);
+ return t;
}
vec3 max (vec3 v, vec3 u) {
vec3 t;
- t.x = max (v.x, u.x);
- t.y = max (v.y, u.y);
- t.z = max (v.z, u.z);
- return t;
+ t.x = max (v.x, u.x);
+ t.y = max (v.y, u.y);
+ t.z = max (v.z, u.z);
+ return t;
}
vec4 max (vec4 v, vec4 u) {
vec4 t;
- t.x = max (v.x, u.x);
- t.y = max (v.y, u.y);
- t.z = max (v.z, u.z);
- t.w = max (v.w, u.w);
- return t;
+ t.x = max (v.x, u.x);
+ t.y = max (v.y, u.y);
+ t.z = max (v.z, u.z);
+ t.w = max (v.w, u.w);
+ return t;
}
vec2 max (vec2 v, float y) {
@@ -835,26 +834,26 @@ float step (float edge, float x) {
vec2 step (vec2 edge, vec2 v) {
vec2 u;
- u.x = step (edge.x, v.x);
- u.y = step (edge.y, v.y);
- return u;
+ u.x = step (edge.x, v.x);
+ u.y = step (edge.y, v.y);
+ return u;
}
vec3 step (vec3 edge, vec3 v) {
vec3 u;
- u.x = step (edge.x, v.x);
- u.y = step (edge.y, v.y);
- u.z = step (edge.z, v.z);
- return u;
+ u.x = step (edge.x, v.x);
+ u.y = step (edge.y, v.y);
+ u.z = step (edge.z, v.z);
+ return u;
}
vec4 step (vec4 edge, vec4 v) {
vec4 u;
- u.x = step (edge.x, v.x);
- u.y = step (edge.y, v.y);
- u.z = step (edge.z, v.z);
- u.w = step (edge.w, v.w);
- return u;
+ u.x = step (edge.x, v.x);
+ u.y = step (edge.y, v.y);
+ u.z = step (edge.z, v.z);
+ u.w = step (edge.w, v.w);
+ return u;
}
vec2 step (float edge, vec2 v) {
@@ -871,56 +870,56 @@ vec4 step (float edge, vec4 v) {
float smoothstep (float edge0, float edge1, float x) {
float t;
- t = clamp ((x - edge0) / (edge1 - edge0), 0.0, 1.0);
+ t = clamp ((x - edge0) / (edge1 - edge0), 0.0, 1.0);
return t * t * (3.0 - 2.0 * t);
}
vec2 smoothstep (vec2 edge0, vec2 edge1, vec2 v) {
vec2 u;
- u.x = smoothstep (edge0.x, edge1.x, v.x);
- u.y = smoothstep (edge0.y, edge1.y, v.y);
- return u;
+ u.x = smoothstep (edge0.x, edge1.x, v.x);
+ u.y = smoothstep (edge0.y, edge1.y, v.y);
+ return u;
}
vec3 smoothstep (vec3 edge0, vec3 edge1, vec3 v) {
vec3 u;
- u.x = smoothstep (edge0.x, edge1.x, v.x);
- u.y = smoothstep (edge0.y, edge1.y, v.y);
- u.z = smoothstep (edge0.z, edge1.z, v.z);
- return u;
+ u.x = smoothstep (edge0.x, edge1.x, v.x);
+ u.y = smoothstep (edge0.y, edge1.y, v.y);
+ u.z = smoothstep (edge0.z, edge1.z, v.z);
+ return u;
}
vec4 smoothstep (vec4 edge0, vec4 edge1, vec4 v) {
vec4 u;
- u.x = smoothstep (edge0.x, edge1.x, v.x);
- u.y = smoothstep (edge0.y, edge1.y, v.y);
- u.z = smoothstep (edge0.z, edge1.z, v.z);
- u.w = smoothstep (edge0.w, edge1.w, v.w);
- return u;
+ u.x = smoothstep (edge0.x, edge1.x, v.x);
+ u.y = smoothstep (edge0.y, edge1.y, v.y);
+ u.z = smoothstep (edge0.z, edge1.z, v.z);
+ u.w = smoothstep (edge0.w, edge1.w, v.w);
+ return u;
}
vec2 smoothstep (float edge0, float edge1, vec2 v) {
vec2 u;
- u.x = smoothstep (edge0, edge1, v.x);
- u.y = smoothstep (edge0, edge1, v.y);
- return u;
+ u.x = smoothstep (edge0, edge1, v.x);
+ u.y = smoothstep (edge0, edge1, v.y);
+ return u;
}
vec3 smoothstep (float edge0, float edge1, vec3 v) {
vec3 u;
- u.x = smoothstep (edge0, edge1, v.x);
- u.y = smoothstep (edge0, edge1, v.y);
- u.z = smoothstep (edge0, edge1, v.z);
- return u;
+ u.x = smoothstep (edge0, edge1, v.x);
+ u.y = smoothstep (edge0, edge1, v.y);
+ u.z = smoothstep (edge0, edge1, v.z);
+ return u;
}
vec4 smoothstep (float edge0, float edge1, vec4 v) {
vec4 u;
- u.x = smoothstep (edge0, edge1, v.x);
- u.y = smoothstep (edge0, edge1, v.y);
- u.z = smoothstep (edge0, edge1, v.z);
- u.w = smoothstep (edge0, edge1, v.w);
- return u;
+ u.x = smoothstep (edge0, edge1, v.x);
+ u.y = smoothstep (edge0, edge1, v.y);
+ u.z = smoothstep (edge0, edge1, v.z);
+ u.w = smoothstep (edge0, edge1, v.w);
+ return u;
}
//
@@ -1033,7 +1032,7 @@ vec4 reflect (vec4 I, vec4 N) {
float refract (float I, float N, float eta) {
float k;
- k = 1.0 - eta * eta * (1.0 - dot (N, I) * dot (N, I));
+ k = 1.0 - eta * eta * (1.0 - dot (N, I) * dot (N, I));
if (k < 0.0)
return 0.0;
return eta * I - (eta * dot (N, I) + sqrt (k)) * N;
@@ -1041,7 +1040,7 @@ float refract (float I, float N, float eta) {
vec2 refract (vec2 I, vec2 N, float eta) {
float k;
- k = 1.0 - eta * eta * (1.0 - dot (N, I) * dot (N, I));
+ k = 1.0 - eta * eta * (1.0 - dot (N, I) * dot (N, I));
if (k < 0.0)
return 0.0;
return eta * I - (eta * dot (N, I) + sqrt (k)) * N;
@@ -1049,7 +1048,7 @@ vec2 refract (vec2 I, vec2 N, float eta) {
vec3 refract (vec3 I, vec3 N, float eta) {
float k;
- k = 1.0 - eta * eta * (1.0 - dot (N, I) * dot (N, I));
+ k = 1.0 - eta * eta * (1.0 - dot (N, I) * dot (N, I));
if (k < 0.0)
return 0.0;
return eta * I - (eta * dot (N, I) + sqrt (k)) * N;
@@ -1057,7 +1056,7 @@ vec3 refract (vec3 I, vec3 N, float eta) {
vec4 refract (vec4 I, vec4 N, float eta) {
float k;
- k = 1.0 - eta * eta * (1.0 - dot (N, I) * dot (N, I));
+ k = 1.0 - eta * eta * (1.0 - dot (N, I) * dot (N, I));
if (k < 0.0)
return 0.0;
return eta * I - (eta * dot (N, I) + sqrt (k)) * N;
@@ -1096,291 +1095,291 @@ mat4 matrixCompMult (mat4 m, mat4 n) {
//
bvec2 lessThan (vec2 v, vec2 u) {
- bvec2 b;
- b.x = v.x < u.x;
- b.y = v.y < u.y;
- return b;
+ bvec2 b;
+ b.x = v.x < u.x;
+ b.y = v.y < u.y;
+ return b;
}
bvec3 lessThan (vec3 v, vec3 u) {
bvec3 b;
- b.x = v.x < u.x;
- b.y = v.y < u.y;
- b.z = v.z < u.z;
- return b;
+ b.x = v.x < u.x;
+ b.y = v.y < u.y;
+ b.z = v.z < u.z;
+ return b;
}
bvec4 lessThan (vec4 v, vec4 u) {
bvec4 b;
- b.x = v.x < u.x;
- b.y = v.y < u.y;
- b.z = v.z < u.z;
- b.w = v.w < u.w;
- return b;
+ b.x = v.x < u.x;
+ b.y = v.y < u.y;
+ b.z = v.z < u.z;
+ b.w = v.w < u.w;
+ return b;
}
bvec2 lessThan (ivec2 v, ivec2 u) {
bvec2 b;
- b.x = v.x < u.x;
- b.y = v.y < u.y;
- return b;
+ b.x = v.x < u.x;
+ b.y = v.y < u.y;
+ return b;
}
bvec3 lessThan (ivec3 v, ivec3 u) {
bvec3 b;
- b.x = v.x < u.x;
- b.y = v.y < u.y;
- b.z = v.z < u.z;
- return b;
+ b.x = v.x < u.x;
+ b.y = v.y < u.y;
+ b.z = v.z < u.z;
+ return b;
}
bvec4 lessThan (ivec4 v, ivec4 u) {
bvec4 b;
- b.x = v.x < u.x;
- b.y = v.y < u.y;
- b.z = v.z < u.z;
- b.w = v.w < u.w;
- return b;
+ b.x = v.x < u.x;
+ b.y = v.y < u.y;
+ b.z = v.z < u.z;
+ b.w = v.w < u.w;
+ return b;
}
bvec2 lessThanEqual (vec2 v, vec2 u) {
bvec2 b;
- b.x = v.x <= u.x;
- b.y = v.y <= u.y;
- return b;
+ b.x = v.x <= u.x;
+ b.y = v.y <= u.y;
+ return b;
}
bvec3 lessThanEqual (vec3 v, vec3 u) {
bvec3 b;
- b.x = v.x <= u.x;
- b.y = v.y <= u.y;
- b.z = v.z <= u.z;
- return b;
+ b.x = v.x <= u.x;
+ b.y = v.y <= u.y;
+ b.z = v.z <= u.z;
+ return b;
}
bvec4 lessThanEqual (vec4 v, vec4 u) {
bvec4 b;
- b.x = v.x <= u.x;
- b.y = v.y <= u.y;
- b.z = v.z <= u.z;
- b.w = v.w <= u.w;
- return b;
+ b.x = v.x <= u.x;
+ b.y = v.y <= u.y;
+ b.z = v.z <= u.z;
+ b.w = v.w <= u.w;
+ return b;
}
bvec2 lessThanEqual (ivec2 v, ivec2 u) {
bvec2 b;
- b.x = v.x <= u.x;
- b.y = v.y <= u.y;
- return b;
+ b.x = v.x <= u.x;
+ b.y = v.y <= u.y;
+ return b;
}
bvec3 lessThanEqual (ivec3 v, ivec3 u) {
bvec3 b;
- b.x = v.x <= u.x;
- b.y = v.y <= u.y;
- b.z = v.z <= u.z;
- return b;
+ b.x = v.x <= u.x;
+ b.y = v.y <= u.y;
+ b.z = v.z <= u.z;
+ return b;
}
bvec4 lessThanEqual (ivec4 v, ivec4 u) {
bvec4 b;
- b.x = v.x <= u.x;
- b.y = v.y <= u.y;
- b.z = v.z <= u.z;
- b.w = v.w <= u.w;
- return b;
+ b.x = v.x <= u.x;
+ b.y = v.y <= u.y;
+ b.z = v.z <= u.z;
+ b.w = v.w <= u.w;
+ return b;
}
bvec2 greaterThan (vec2 v, vec2 u) {
bvec2 b;
- b.x = v.x > u.x;
- b.y = v.y > u.y;
- return b;
+ b.x = v.x > u.x;
+ b.y = v.y > u.y;
+ return b;
}
bvec3 greaterThan (vec3 v, vec3 u) {
bvec3 b;
- b.x = v.x > u.x;
- b.y = v.y > u.y;
- b.z = v.z > u.z;
- return b;
+ b.x = v.x > u.x;
+ b.y = v.y > u.y;
+ b.z = v.z > u.z;
+ return b;
}
bvec4 greaterThan (vec4 v, vec4 u) {
bvec4 b;
- b.x = v.x > u.x;
- b.y = v.y > u.y;
- b.z = v.z > u.z;
- b.w = v.w > u.w;
- return b;
+ b.x = v.x > u.x;
+ b.y = v.y > u.y;
+ b.z = v.z > u.z;
+ b.w = v.w > u.w;
+ return b;
}
bvec2 greaterThan (ivec2 v, ivec2 u) {
bvec2 b;
- b.x = v.x > u.x;
- b.y = v.y > u.y;
- return b;
+ b.x = v.x > u.x;
+ b.y = v.y > u.y;
+ return b;
}
bvec3 greaterThan (ivec3 v, ivec3 u) {
bvec3 b;
- b.x = v.x > u.x;
- b.y = v.y > u.y;
- b.z = v.z > u.z;
- return b;
+ b.x = v.x > u.x;
+ b.y = v.y > u.y;
+ b.z = v.z > u.z;
+ return b;
}
bvec4 greaterThan (ivec4 v, ivec4 u) {
bvec4 b;
- b.x = v.x > u.x;
- b.y = v.y > u.y;
- b.z = v.z > u.z;
- b.w = v.w > u.w;
- return b;
+ b.x = v.x > u.x;
+ b.y = v.y > u.y;
+ b.z = v.z > u.z;
+ b.w = v.w > u.w;
+ return b;
}
bvec2 greaterThanEqual (vec2 v, vec2 u) {
bvec2 b;
- b.x = v.x >= u.x;
- b.y = v.y >= u.y;
- return b;
+ b.x = v.x >= u.x;
+ b.y = v.y >= u.y;
+ return b;
}
bvec3 greaterThanEqual (vec3 v, vec3 u) {
bvec3 b;
- b.x = v.x >= u.x;
- b.y = v.y >= u.y;
- b.z = v.z >= u.z;
- return b;
+ b.x = v.x >= u.x;
+ b.y = v.y >= u.y;
+ b.z = v.z >= u.z;
+ return b;
}
bvec4 greaterThanEqual (vec4 v, vec4 u) {
bvec4 b;
- b.x = v.x >= u.x;
- b.y = v.y >= u.y;
- b.z = v.z >= u.z;
- b.w = v.w >= u.w;
- return b;
+ b.x = v.x >= u.x;
+ b.y = v.y >= u.y;
+ b.z = v.z >= u.z;
+ b.w = v.w >= u.w;
+ return b;
}
bvec2 greaterThanEqual (ivec2 v, ivec2 u) {
bvec2 b;
- b.x = v.x >= u.x;
- b.y = v.y >= u.y;
- return b;
+ b.x = v.x >= u.x;
+ b.y = v.y >= u.y;
+ return b;
}
bvec3 greaterThanEqual (ivec3 v, ivec3 u) {
bvec3 b;
- b.x = v.x >= u.x;
- b.y = v.y >= u.y;
- b.z = v.z >= u.z;
- return b;
+ b.x = v.x >= u.x;
+ b.y = v.y >= u.y;
+ b.z = v.z >= u.z;
+ return b;
}
bvec4 greaterThanEqual (ivec4 v, ivec4 u) {
bvec4 b;
- b.x = v.x >= u.x;
- b.y = v.y >= u.y;
- b.z = v.z >= u.z;
- b.w = v.w >= u.w;
- return b;
+ b.x = v.x >= u.x;
+ b.y = v.y >= u.y;
+ b.z = v.z >= u.z;
+ b.w = v.w >= u.w;
+ return b;
}
bvec2 equal (vec2 v, vec2 u) {
bvec2 b;
- b.x = v.x == u.x;
- b.y = v.y == u.y;
- return b;
+ b.x = v.x == u.x;
+ b.y = v.y == u.y;
+ return b;
}
bvec3 equal (vec3 v, vec3 u) {
bvec3 b;
- b.x = v.x == u.x;
- b.y = v.y == u.y;
- b.z = v.z == u.z;
- return b;
+ b.x = v.x == u.x;
+ b.y = v.y == u.y;
+ b.z = v.z == u.z;
+ return b;
}
bvec4 equal (vec4 v, vec4 u) {
bvec4 b;
- b.x = v.x == u.x;
- b.y = v.y == u.y;
- b.z = v.z == u.z;
- b.w = v.w == u.w;
- return b;
+ b.x = v.x == u.x;
+ b.y = v.y == u.y;
+ b.z = v.z == u.z;
+ b.w = v.w == u.w;
+ return b;
}
bvec2 equal (ivec2 v, ivec2 u) {
bvec2 b;
- b.x = v.x == u.x;
- b.y = v.y == u.y;
- return b;
+ b.x = v.x == u.x;
+ b.y = v.y == u.y;
+ return b;
}
bvec3 equal (ivec3 v, ivec3 u) {
bvec3 b;
- b.x = v.x == u.x;
- b.y = v.y == u.y;
- b.z = v.z == u.z;
- return b;
+ b.x = v.x == u.x;
+ b.y = v.y == u.y;
+ b.z = v.z == u.z;
+ return b;
}
bvec4 equal (ivec4 v, ivec4 u) {
bvec4 b;
- b.x = v.x == u.x;
- b.y = v.y == u.y;
- b.z = v.z == u.z;
- b.w = v.w == u.w;
- return b;
+ b.x = v.x == u.x;
+ b.y = v.y == u.y;
+ b.z = v.z == u.z;
+ b.w = v.w == u.w;
+ return b;
}
bvec2 notEqual (vec2 v, vec2 u) {
bvec2 b;
- b.x = v.x != u.x;
- b.y = v.y != u.y;
- return b;
+ b.x = v.x != u.x;
+ b.y = v.y != u.y;
+ return b;
}
bvec3 notEqual (vec3 v, vec3 u) {
bvec3 b;
- b.x = v.x != u.x;
- b.y = v.y != u.y;
- b.z = v.z != u.z;
- return b;
+ b.x = v.x != u.x;
+ b.y = v.y != u.y;
+ b.z = v.z != u.z;
+ return b;
}
bvec4 notEqual (vec4 v, vec4 u) {
bvec4 b;
- b.x = v.x != u.x;
- b.y = v.y != u.y;
- b.z = v.z != u.z;
- b.w = v.w != u.w;
- return b;
+ b.x = v.x != u.x;
+ b.y = v.y != u.y;
+ b.z = v.z != u.z;
+ b.w = v.w != u.w;
+ return b;
}
bvec2 notEqual (ivec2 v, ivec2 u) {
bvec2 b;
- b.x = v.x != u.x;
- b.y = v.y != u.y;
- return b;
+ b.x = v.x != u.x;
+ b.y = v.y != u.y;
+ return b;
}
bvec3 notEqual (ivec3 v, ivec3 u) {
bvec3 b;
- b.x = v.x != u.x;
- b.y = v.y != u.y;
- b.z = v.z != u.z;
- return b;
+ b.x = v.x != u.x;
+ b.y = v.y != u.y;
+ b.z = v.z != u.z;
+ return b;
}
bvec4 notEqual (ivec4 v, ivec4 u) {
bvec4 b;
- b.x = v.x != u.x;
- b.y = v.y != u.y;
- b.z = v.z != u.z;
- b.w = v.w != u.w;
- return b;
+ b.x = v.x != u.x;
+ b.y = v.y != u.y;
+ b.z = v.z != u.z;
+ b.w = v.w != u.w;
+ return b;
}
bool any (bvec2 v) {
@@ -1408,26 +1407,26 @@ bool all (bvec4 v) {
}
bvec2 not (bvec2 v) {
- bvec2 u;
- u.x = !v.x;
- u.y = !v.y;
+ bvec2 u;
+ u.x = !v.x;
+ u.y = !v.y;
return u;
}
bvec3 not (bvec3 v) {
bvec3 u;
- u.x = !v.x;
- u.y = !v.y;
- u.z = !v.z;
+ u.x = !v.x;
+ u.y = !v.y;
+ u.z = !v.z;
return u;
}
bvec4 not (bvec4 v) {
bvec4 u;
- u.x = !v.x;
- u.y = !v.y;
- u.z = !v.z;
- u.w = !v.w;
+ u.x = !v.x;
+ u.y = !v.y;
+ u.z = !v.z;
+ u.w = !v.w;
return u;
}
@@ -1512,86 +1511,128 @@ vec4 shadow2DProj (sampler2DShadow sampler, vec4 coord) {
}
//
-// 8.9 Noise Functions
+// 8.9 Noise Functions
+//
+// AUTHOR: Stefan Gustavson ([email protected]), Nov 26, 2005
//
float noise1 (float x) {
- // XXX:
- return 0.0;
+ float a;
+ __asm float_noise1 a, x;
+ return a;
}
float noise1 (vec2 x) {
- // XXX:
- return 0.0;
+ float a;
+ __asm float_noise2 a, x;
+ return a;
}
float noise1 (vec3 x) {
- // XXX:
- return 0.0;
+ float a;
+ __asm float_noise3 a, x;
+ return a;
}
float noise1 (vec4 x) {
- // XXX:
- return 0.0;
+ float a;
+ __asm float_noise4 a, x;
+ return a;
}
vec2 noise2 (float x) {
- // XXX:
- return vec2 (0.0);
+ vec2 u;
+ u.x = noise1 (x);
+ u.y = noise1 (x + 19.34);
+ return u;
}
vec2 noise2 (vec2 x) {
- // XXX:
- return vec2 (0.0);
+ vec2 u;
+ u.x = noise1 (x);
+ u.y = noise1 (x + vec2 (19.34, 7.66));
+ return u;
}
vec2 noise2 (vec3 x) {
- // XXX:
- return vec2 (0.0);
+ vec2 u;
+ u.x = noise1 (x);
+ u.y = noise1 (x + vec3 (19.34, 7.66, 3.23));
+ return u;
}
vec2 noise2 (vec4 x) {
- // XXX:
- return vec2 (0.0);
+ vec2 u;
+ u.x = noise1 (x);
+ u.y = noise1 (x + vec4 (19.34, 7.66, 3.23, 2.77));
+ return u;
}
vec3 noise3 (float x) {
- // XXX:
- return vec3 (0.0);
+ vec3 u;
+ u.x = noise1 (x);
+ u.y = noise1 (x + 19.34);
+ u.z = noise1 (x + 5.47);
+ return u;
}
vec3 noise3 (vec2 x) {
- // XXX:
- return vec3 (0.0);
+ vec3 u;
+ u.x = noise1 (x);
+ u.y = noise1 (x + vec2 (19.34, 7.66));
+ u.z = noise1 (x + vec2 (5.47, 17.85));
+ return u;
}
vec3 noise3 (vec3 x) {
- // XXX:
- return vec3 (0.0);
+ vec3 u;
+ u.x = noise1 (x);
+ u.y = noise1 (x + vec3 (19.34, 7.66, 3.23));
+ u.z = noise1 (x + vec3 (5.47, 17.85, 11.04));
+ return u;
}
vec3 noise3 (vec4 x) {
- // XXX:
- return vec3 (0.0);
+ vec3 u;
+ u.x = noise1 (x);
+ u.y = noise1 (x + vec4 (19.34, 7.66, 3.23, 2.77));
+ u.z = noise1 (x + vec4 (5.47, 17.85, 11.04, 13.19));
+ return u;
}
vec4 noise4 (float x) {
- // XXX:
- return vec4 (0.0);
+ vec4 u;
+ u.x = noise1 (x);
+ u.y = noise1 (x + 19.34);
+ u.z = noise1 (x + 5.47);
+ u.w = noise1 (x + 23.54);
+ return u;
}
vec4 noise4 (vec2 x) {
- // XXX:
- return vec4 (0.0);
+ vec4 u;
+ u.x = noise1 (x);
+ u.y = noise1 (x + vec2 (19.34, 7.66));
+ u.z = noise1 (x + vec2 (5.47, 17.85));
+ u.w = noise1 (x + vec2 (23.54, 29.11));
+ return u;
}
vec4 noise4 (vec3 x) {
- // XXX:
- return vec4 (0.0);
+ vec4 u;
+ u.x = noise1 (x);
+ u.y = noise1 (x + vec3 (19.34, 7.66, 3.23));
+ u.z = noise1 (x + vec3 (5.47, 17.85, 11.04));
+ u.w = noise1 (x + vec3 (23.54, 29.11, 31.91));
+ return u;
}
vec4 noise4 (vec4 x) {
- // XXX:
- return vec4 (0.0);
+ vec4 u;
+ u.x = noise1 (x);
+ u.y = noise1 (x + vec4 (19.34, 7.66, 3.23, 2.77));
+ u.z = noise1 (x + vec4 (5.47, 17.85, 11.04, 13.19));
+ u.w = noise1 (x + vec4 (23.54, 29.11, 31.91, 37.48));
+ return u;
}
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 f72da4407b4..0422790cdad 100644
--- a/src/mesa/shader/slang/library/slang_common_builtin_gc.h
+++ b/src/mesa/shader/slang/library/slang_common_builtin_gc.h
@@ -661,19 +661,63 @@
111,114,100,0,59,115,0,18,99,111,111,114,100,0,59,113,0,49,20,0,9,18,117,0,59,116,0,18,99,111,111,
114,100,0,59,116,0,18,99,111,111,114,100,0,59,113,0,49,20,0,9,18,117,0,59,112,0,18,99,111,111,114,
100,0,59,112,0,18,99,111,111,114,100,0,59,113,0,49,20,0,8,58,115,104,97,100,111,119,50,68,0,18,115,
-97,109,112,108,101,114,0,0,18,117,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,8,
-17,48,0,48,0,0,0,0,1,0,9,0,110,111,105,115,101,49,0,1,0,0,10,120,0,0,0,1,8,17,48,0,48,0,0,0,0,1,0,
-9,0,110,111,105,115,101,49,0,1,0,0,11,120,0,0,0,1,8,17,48,0,48,0,0,0,0,1,0,9,0,110,111,105,115,101,
-49,0,1,0,0,12,120,0,0,0,1,8,17,48,0,48,0,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,17,48,0,48,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,17,48,0,48,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,17,48,0,48,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,17,48,0,48,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,17,48,0,48,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,17,48,0,48,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,17,48,0,48,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,17,48,0,48,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,17,48,0,48,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,17,48,0,48,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,17,48,0,48,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,17,48,0,48,0,0,0,0,0,0,0
+97,109,112,108,101,114,0,0,18,117,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,3,2,0,10,1,117,0,0,0,9,18,117,0,59,120,0,58,110,111,
+105,115,101,49,0,18,120,0,0,0,20,0,9,18,117,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,8,18,117,0,0,0,1,0,10,0,110,111,105,115,101,50,0,1,0,0,10,120,0,0,0,1,3,
+2,0,10,1,117,0,0,0,9,18,117,0,59,120,0,58,110,111,105,115,101,49,0,18,120,0,0,0,20,0,9,18,117,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,8,18,117,0,0,0,1,0,10,0,110,111,105,115,101,50,0,1,0,0,11,120,0,0,0,1,3,2,0,10,
+1,117,0,0,0,9,18,117,0,59,120,0,58,110,111,105,115,101,49,0,18,120,0,0,0,20,0,9,18,117,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,8,18,117,0,0,0,1,0,10,0,110,111,105,115,101,50,0,1,0,0,12,120,0,
+0,0,1,3,2,0,10,1,117,0,0,0,9,18,117,0,59,120,0,58,110,111,105,115,101,49,0,18,120,0,0,0,20,0,9,18,
+117,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,8,18,117,0,0,0,1,0,11,0,110,
+111,105,115,101,51,0,1,0,0,9,120,0,0,0,1,3,2,0,11,1,117,0,0,0,9,18,117,0,59,120,0,58,110,111,105,
+115,101,49,0,18,120,0,0,0,20,0,9,18,117,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,117,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,8,18,117,0,0,0,1,0,11,0,110,111,105,115,101,51,0,1,0,0,10,120,0,0,0,1,3,2,0,11,1,117,0,
+0,0,9,18,117,0,59,120,0,58,110,111,105,115,101,49,0,18,120,0,0,0,20,0,9,18,117,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,117,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,8,18,117,0,0,0,1,0,11,0,110,111,105,115,101,51,0,1,0,0,11,
+120,0,0,0,1,3,2,0,11,1,117,0,0,0,9,18,117,0,59,120,0,58,110,111,105,115,101,49,0,18,120,0,0,0,20,0,
+9,18,117,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,117,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,8,18,117,0,0,0,1,0,11,0,110,111,105,115,101,51,0,1,0,0,12,120,0,0,0,1,3,2,0,11,1,117,
+0,0,0,9,18,117,0,59,120,0,58,110,111,105,115,101,49,0,18,120,0,0,0,20,0,9,18,117,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,117,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,8,18,117,0,0,0,1,0,12,0,110,111,105,115,101,52,0,1,0,0,9,120,0,0,0,
+1,3,2,0,12,1,117,0,0,0,9,18,117,0,59,120,0,58,110,111,105,115,101,49,0,18,120,0,0,0,20,0,9,18,117,
+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,117,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,117,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,8,18,117,0,0,0,1,0,12,0,110,111,105,
+115,101,52,0,1,0,0,10,120,0,0,0,1,3,2,0,12,1,117,0,0,0,9,18,117,0,59,120,0,58,110,111,105,115,101,
+49,0,18,120,0,0,0,20,0,9,18,117,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,117,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,
+117,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,8,18,117,0,0,0,1,0,12,0,110,111,105,115,101,52,0,1,0,0,11,120,0,
+0,0,1,3,2,0,12,1,117,0,0,0,9,18,117,0,59,120,0,58,110,111,105,115,101,49,0,18,120,0,0,0,20,0,9,18,
+117,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,117,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,117,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,8,18,117,0,0,0,1,0,12,0,110,
+111,105,115,101,52,0,1,0,0,12,120,0,0,0,1,3,2,0,12,1,117,0,0,0,9,18,117,0,59,120,0,58,110,111,105,
+115,101,49,0,18,120,0,0,0,20,0,9,18,117,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,117,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,117,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,8,18,117,0,0,0,0
diff --git a/src/mesa/shader/slang/slang_assemble.c b/src/mesa/shader/slang/slang_assemble.c
index 30a80b7f3de..b8f9d78b7af 100644
--- a/src/mesa/shader/slang/slang_assemble.c
+++ b/src/mesa/shader/slang/slang_assemble.c
@@ -31,9 +31,7 @@
#include "imports.h"
#include "slang_utility.h"
#include "slang_assemble.h"
-/*#include "slang_compile.h"*/
#include "slang_storage.h"
-/*#include "slang_assemble_constructor.h"*/
#include "slang_assemble_typeinfo.h"
#include "slang_assemble_conditional.h"
#include "slang_assemble_assignment.h"
@@ -41,40 +39,40 @@
/* slang_assembly */
-static int slang_assembly_construct (slang_assembly *assem)
+static GLboolean slang_assembly_construct (slang_assembly *assem)
{
assem->type = slang_asm_none;
- return 1;
+ return GL_TRUE;
}
-static void slang_assembly_destruct (slang_assembly *assem)
+static GLvoid slang_assembly_destruct (slang_assembly *assem)
{
}
/* slang_assembly_file */
-int slang_assembly_file_construct (slang_assembly_file *file)
+GLboolean slang_assembly_file_construct (slang_assembly_file *file)
{
file->code = NULL;
file->count = 0;
file->capacity = 0;
- return 1;
+ return GL_TRUE;
}
-void slang_assembly_file_destruct (slang_assembly_file *file)
+GLvoid slang_assembly_file_destruct (slang_assembly_file *file)
{
- unsigned int i;
+ GLuint i;
for (i = 0; i < file->count; i++)
slang_assembly_destruct (&file->code[i]);
slang_alloc_free (file->code);
}
-static int push_new (slang_assembly_file *file)
+static GLboolean push_new (slang_assembly_file *file)
{
if (file->count == file->capacity)
{
- unsigned int n;
+ GLuint n;
if (file->capacity == 0)
n = 256;
@@ -83,48 +81,48 @@ static int push_new (slang_assembly_file *file)
file->code = (slang_assembly *) slang_alloc_realloc (file->code,
file->capacity * sizeof (slang_assembly), n * sizeof (slang_assembly));
if (file->code == NULL)
- return 0;
+ return GL_FALSE;
file->capacity = n;
}
if (!slang_assembly_construct (&file->code[file->count]))
- return 0;
+ return GL_FALSE;
file->count++;
- return 1;
+ return GL_TRUE;
}
-static int push_gen (slang_assembly_file *file, slang_assembly_type type, GLfloat literal,
+static GLboolean push_gen (slang_assembly_file *file, slang_assembly_type type, GLfloat literal,
GLuint label, GLuint size)
{
slang_assembly *assem;
if (!push_new (file))
- return 0;
+ return GL_FALSE;
assem = &file->code[file->count - 1];
assem->type = type;
assem->literal = literal;
assem->param[0] = label;
assem->param[1] = size;
- return 1;
+ return GL_TRUE;
}
-int slang_assembly_file_push (slang_assembly_file *file, slang_assembly_type type)
+GLboolean slang_assembly_file_push (slang_assembly_file *file, slang_assembly_type type)
{
return push_gen (file, type, (GLfloat) 0, 0, 0);
}
-int slang_assembly_file_push_label (slang_assembly_file *file, slang_assembly_type type,
+GLboolean slang_assembly_file_push_label (slang_assembly_file *file, slang_assembly_type type,
GLuint label)
{
return push_gen (file, type, (GLfloat) 0, label, 0);
}
-int slang_assembly_file_push_label2 (slang_assembly_file *file, slang_assembly_type type,
+GLboolean slang_assembly_file_push_label2 (slang_assembly_file *file, slang_assembly_type type,
GLuint label1, GLuint label2)
{
return push_gen (file, type, (GLfloat) 0, label1, label2);
}
-int slang_assembly_file_push_literal (slang_assembly_file *file, slang_assembly_type type,
+GLboolean slang_assembly_file_push_literal (slang_assembly_file *file, slang_assembly_type type,
GLfloat literal)
{
return push_gen (file, type, literal, 0, 0);
@@ -137,40 +135,39 @@ int slang_assembly_file_push_literal (slang_assembly_file *file, slang_assembly_
/* slang_assembly_file_restore_point */
-int slang_assembly_file_restore_point_save (slang_assembly_file *file,
+GLboolean slang_assembly_file_restore_point_save (slang_assembly_file *file,
slang_assembly_file_restore_point *point)
{
point->count = file->count;
- return 1;
+ return GL_TRUE;
}
-int slang_assembly_file_restore_point_load (slang_assembly_file *file,
+GLboolean slang_assembly_file_restore_point_load (slang_assembly_file *file,
slang_assembly_file_restore_point *point)
{
- unsigned int i;
+ GLuint i;
for (i = point->count; i < file->count; i++)
slang_assembly_destruct (&file->code[i]);
file->count = point->count;
- return 1;
+ return GL_TRUE;
}
/* utility functions */
-static int sizeof_variable (slang_type_specifier *spec, slang_type_qualifier qual,
- slang_operation *array_size, slang_assembly_name_space *space, unsigned int *size,
- slang_machine *mach, slang_assembly_file *pfile, slang_atom_pool *atoms)
+static GLboolean sizeof_variable (slang_assemble_ctx *A, slang_type_specifier *spec,
+ slang_type_qualifier qual, slang_operation *array_size, GLuint *size)
{
slang_storage_aggregate agg;
/* calculate the size of the variable's aggregate */
if (!slang_storage_aggregate_construct (&agg))
- return 0;
- if (!_slang_aggregate_variable (&agg, spec, array_size, space->funcs, space->structs,
- space->vars, mach, pfile, atoms))
+ return GL_FALSE;
+ if (!_slang_aggregate_variable (&agg, spec, array_size, A->space.funcs, A->space.structs,
+ A->space.vars, A->mach, A->file, A->atoms))
{
slang_storage_aggregate_destruct (&agg);
- return 0;
+ return GL_FALSE;
}
*size += _slang_sizeof_aggregate (&agg);
slang_storage_aggregate_destruct (&agg);
@@ -178,56 +175,52 @@ static int sizeof_variable (slang_type_specifier *spec, slang_type_qualifier qua
/* for reference variables consider the additional address overhead */
if (qual == slang_qual_out || qual == slang_qual_inout)
*size += 4;
- return 1;
+
+ return GL_TRUE;
}
-static int sizeof_variable2 (slang_variable *var, slang_assembly_name_space *space,
- unsigned int *size, slang_machine *mach, slang_assembly_file *pfile, slang_atom_pool *atoms)
+static GLboolean sizeof_variable2 (slang_assemble_ctx *A, slang_variable *var, GLuint *size)
{
var->address = *size;
if (var->type.qualifier == slang_qual_out || var->type.qualifier == slang_qual_inout)
var->address += 4;
- return sizeof_variable (&var->type.specifier, var->type.qualifier, var->array_size, space,
- size, mach, pfile, atoms);
+ return sizeof_variable (A, &var->type.specifier, var->type.qualifier, var->array_size, size);
}
-static int sizeof_variables (slang_variable_scope *vars, unsigned int start, unsigned int stop,
- slang_assembly_name_space *space, unsigned int *size, slang_machine *mach,
- slang_assembly_file *pfile, slang_atom_pool *atoms)
+static GLboolean sizeof_variables (slang_assemble_ctx *A, slang_variable_scope *vars, GLuint start,
+ GLuint stop, GLuint *size)
{
- unsigned int i;
+ GLuint i;
for (i = start; i < stop; i++)
- if (!sizeof_variable2 (&vars->variables[i], space, size, mach, pfile, atoms))
- return 0;
- return 1;
+ if (!sizeof_variable2 (A, &vars->variables[i], size))
+ return GL_FALSE;
+ return GL_TRUE;
}
-static int collect_locals (slang_operation *op, slang_assembly_name_space *space,
- unsigned int *size, slang_machine *mach, slang_assembly_file *pfile, slang_atom_pool *atoms)
+static GLboolean collect_locals (slang_assemble_ctx *A, slang_operation *op, GLuint *size)
{
- unsigned int i;
+ GLuint i;
- if (!sizeof_variables (op->locals, 0, op->locals->num_variables, space, size, mach, pfile,
- atoms))
- return 0;
+ if (!sizeof_variables (A, op->locals, 0, op->locals->num_variables, size))
+ return GL_FALSE;
for (i = 0; i < op->num_children; i++)
- if (!collect_locals (&op->children[i], space, size, mach, pfile, atoms))
- return 0;
- return 1;
+ if (!collect_locals (A, &op->children[i], size))
+ return GL_FALSE;
+ return GL_TRUE;
}
/* _slang_locate_function() */
slang_function *_slang_locate_function (slang_function_scope *funcs, slang_atom a_name,
- slang_operation *params, unsigned int num_params, slang_assembly_name_space *space,
+ slang_operation *params, GLuint num_params, slang_assembly_name_space *space,
slang_atom_pool *atoms)
{
- unsigned int i;
+ GLuint i;
for (i = 0; i < funcs->num_functions; i++)
{
- unsigned int j;
+ GLuint j;
slang_function *f = &funcs->functions[i];
if (a_name != f->header.a_name)
@@ -239,11 +232,11 @@ slang_function *_slang_locate_function (slang_function_scope *funcs, slang_atom
slang_assembly_typeinfo ti;
if (!slang_assembly_typeinfo_construct (&ti))
- return 0;
+ return NULL;
if (!_slang_typeof_operation (&params[j], space, &ti, atoms))
{
slang_assembly_typeinfo_destruct (&ti);
- return 0;
+ return NULL;
}
if (!slang_type_specifier_equal (&ti.spec, &f->parameters->variables[j].type.specifier))
{
@@ -268,10 +261,10 @@ slang_function *_slang_locate_function (slang_function_scope *funcs, slang_atom
/* _slang_assemble_function() */
-int _slang_assemble_function (slang_assemble_ctx *A, slang_function *fun)
+GLboolean _slang_assemble_function (slang_assemble_ctx *A, slang_function *fun)
{
- unsigned int param_size, local_size;
- unsigned int skip, cleanup;
+ GLuint param_size, local_size;
+ GLuint skip, cleanup;
fun->address = A->file->count;
@@ -282,12 +275,12 @@ int _slang_assemble_function (slang_assemble_ctx *A, slang_function *fun)
fun->fixups.table = (GLuint *) slang_alloc_realloc (fun->fixups.table,
fun->fixups.count * sizeof (GLuint), (fun->fixups.count + 1) * sizeof (GLuint));
if (fun->fixups.table == NULL)
- return 0;
+ return GL_FALSE;
fun->fixups.table[fun->fixups.count] = fun->address;
fun->fixups.count++;
if (!PUSH (A->file, slang_asm_jump))
- return 0;
- return 1;
+ return GL_FALSE;
+ return GL_TRUE;
}
else
{
@@ -308,15 +301,13 @@ int _slang_assemble_function (slang_assemble_ctx *A, slang_function *fun)
/* calculate return value size */
param_size = 0;
if (fun->header.type.specifier.type != slang_spec_void)
- if (!sizeof_variable (&fun->header.type.specifier, slang_qual_none, NULL, &A->space,
- &param_size, A->mach, A->file, A->atoms))
- return 0;
+ if (!sizeof_variable (A, &fun->header.type.specifier, slang_qual_none, NULL, &param_size))
+ return GL_FALSE;
A->local.ret_size = param_size;
/* calculate formal parameter list size */
- if (!sizeof_variables (fun->parameters, 0, fun->param_count, &A->space, &param_size, A->mach, A->file,
- A->atoms))
- return 0;
+ if (!sizeof_variables (A, fun->parameters, 0, fun->param_count, &param_size))
+ return GL_FALSE;
/* calculate local variables size - take into account the four-byte return address and
* temporaries for various tasks (4 for addr and 16 for swizzle temporaries).
@@ -324,85 +315,74 @@ int _slang_assemble_function (slang_assemble_ctx *A, slang_function *fun)
A->local.addr_tmp = param_size + 4;
A->local.swizzle_tmp = param_size + 4 + 4;
local_size = param_size + 4 + 4 + 16;
- if (!sizeof_variables (fun->parameters, fun->param_count, fun->parameters->num_variables, &A->space,
- &local_size, A->mach, A->file, A->atoms))
- return 0;
- if (!collect_locals (fun->body, &A->space, &local_size, A->mach, A->file, A->atoms))
- return 0;
+ if (!sizeof_variables (A, fun->parameters, fun->param_count, fun->parameters->num_variables,
+ &local_size))
+ return GL_FALSE;
+ if (!collect_locals (A, fun->body, &local_size))
+ return GL_FALSE;
/* allocate local variable storage */
if (!PLAB (A->file, slang_asm_local_alloc, local_size - param_size - 4))
- return 0;
+ return GL_FALSE;
/* mark a new frame for function variable storage */
if (!PLAB (A->file, slang_asm_enter, local_size))
- return 0;
+ return GL_FALSE;
/* jump directly to the actual code */
skip = A->file->count;
if (!push_new (A->file))
- return 0;
+ return GL_FALSE;
A->file->code[skip].type = slang_asm_jump;
/* all "return" statements will be directed here */
A->flow.function_end = A->file->count;
cleanup = A->file->count;
if (!push_new (A->file))
- return 0;
+ return GL_FALSE;
A->file->code[cleanup].type = slang_asm_jump;
/* execute the function body */
A->file->code[skip].param[0] = A->file->count;
- if (!_slang_assemble_operation_ (A, fun->body, slang_ref_freelance))
- return 0;
+ if (!_slang_assemble_operation_ (A, fun->body, /*slang_ref_freelance*/slang_ref_forbid))
+ return GL_FALSE;
/* this is the end of the function - restore the old function frame */
A->file->code[cleanup].param[0] = A->file->count;
if (!PUSH (A->file, slang_asm_leave))
- return 0;
+ return GL_FALSE;
/* free local variable storage */
if (!PLAB (A->file, slang_asm_local_free, local_size - param_size - 4))
- return 0;
+ return GL_FALSE;
/* return from the function */
if (!PUSH (A->file, slang_asm_return))
- return 0;
- return 1;
-}
+ return GL_FALSE;
-int _slang_cleanup_stack (slang_assembly_file *file, slang_operation *op, int ref,
- slang_assembly_name_space *space, struct slang_machine_ *mach, slang_atom_pool *atoms)
-{
- slang_assemble_ctx A;
-
- A.file = file;
- A.mach = mach;
- A.atoms = atoms;
- A.space = *space;
- return _slang_cleanup_stack_ (&A, op);
+ return GL_TRUE;
}
-int _slang_cleanup_stack_ (slang_assemble_ctx *A, slang_operation *op)
+GLboolean _slang_cleanup_stack_ (slang_assemble_ctx *A, slang_operation *op)
{
slang_assembly_typeinfo ti;
- unsigned int size = 0;
+ GLuint size = 0;
/* get type info of the operation and calculate its size */
if (!slang_assembly_typeinfo_construct (&ti))
- return 0;
+ return GL_FALSE;
if (!_slang_typeof_operation (op, &A->space, &ti, A->atoms))
{
slang_assembly_typeinfo_destruct (&ti);
- return 0;
+ return GL_FALSE;
}
- if (A->ref == slang_ref_force)
- size = 4;
- else if (ti.spec.type != slang_spec_void)
- if (!sizeof_variable (&ti.spec, slang_qual_none, NULL, &A->space, &size, A->mach, A->file, A->atoms))
+ if (ti.spec.type != slang_spec_void)
+ if (A->ref == slang_ref_force)
+ size = 4;
+ else if (!sizeof_variable (A, &ti.spec, slang_qual_none, NULL, &size))
{
slang_assembly_typeinfo_destruct (&ti);
- return 0;
+ return GL_FALSE;
}
slang_assembly_typeinfo_destruct (&ti);
@@ -410,33 +390,34 @@ int _slang_cleanup_stack_ (slang_assemble_ctx *A, slang_operation *op)
if (size != 0)
{
if (!PLAB (A->file, slang_asm_local_free, size))
- return 0;
+ return GL_FALSE;
}
- return 1;
+
+ return GL_TRUE;
}
/* _slang_assemble_operation() */
-static int dereference_aggregate (slang_assembly_file *file, const slang_storage_aggregate *agg,
- unsigned int *size, slang_assembly_local_info *info, slang_swizzle *swz, int is_swizzled)
+static GLboolean dereference_aggregate (slang_assemble_ctx *A, const slang_storage_aggregate *agg,
+ GLuint *size, slang_swizzle *swz, GLboolean is_swizzled)
{
- unsigned int i;
+ GLuint i;
for (i = agg->count; i > 0; i--)
{
const slang_storage_array *arr = &agg->arrays[i - 1];
- unsigned int j;
+ GLuint j;
for (j = arr->length; j > 0; j--)
{
if (arr->type == slang_stor_aggregate)
{
- if (!dereference_aggregate (file, arr->aggregate, size, info, swz, is_swizzled))
- return 0;
+ if (!dereference_aggregate (A, arr->aggregate, size, swz, is_swizzled))
+ return GL_FALSE;
}
else
{
- unsigned int src_offset;
+ GLuint src_offset;
slang_assembly_type ty;
*size -= 4;
@@ -454,14 +435,14 @@ static int dereference_aggregate (slang_assembly_file *file, const slang_storage
}
/* dereference data slot of a basic type */
- if (!PLAB2 (file, slang_asm_local_addr, info->addr_tmp, 4))
- return 0;
- if (!PUSH (file, slang_asm_addr_deref))
- return 0;
- if (!PLAB (file, slang_asm_addr_push, src_offset))
- return 0;
- if (!PUSH (file, slang_asm_addr_add))
- return 0;
+ if (!PLAB2 (A->file, slang_asm_local_addr, A->local.addr_tmp, 4))
+ return GL_FALSE;
+ if (!PUSH (A->file, slang_asm_addr_deref))
+ return GL_FALSE;
+ if (!PLAB (A->file, slang_asm_addr_push, src_offset))
+ return GL_FALSE;
+ if (!PUSH (A->file, slang_asm_addr_add))
+ return GL_FALSE;
switch (arr->type)
{
@@ -478,75 +459,66 @@ static int dereference_aggregate (slang_assembly_file *file, const slang_storage
_mesa_problem(NULL, "Unexpected arr->type in dereference_aggregate");
ty = slang_asm_none;
}
- if (!PUSH (file, ty))
- return 0;
+ if (!PUSH (A->file, ty))
+ return GL_FALSE;
}
}
}
- return 1;
+
+ return GL_TRUE;
}
-int _slang_dereference (slang_assembly_file *file, slang_operation *op,
- slang_assembly_name_space *space, slang_assembly_local_info *info, slang_machine *mach,
- slang_atom_pool *atoms)
+GLboolean _slang_dereference (slang_assemble_ctx *A, slang_operation *op)
{
slang_assembly_typeinfo ti;
- int result;
+ GLboolean result = GL_FALSE;
slang_storage_aggregate agg;
- unsigned int size;
+ GLuint size;
/* get type information of the given operation */
if (!slang_assembly_typeinfo_construct (&ti))
- return 0;
- if (!_slang_typeof_operation (op, space, &ti, atoms))
- {
- slang_assembly_typeinfo_destruct (&ti);
- return 0;
- }
+ return GL_FALSE;
+ if (!_slang_typeof_operation (op, &A->space, &ti, A->atoms))
+ goto end1;
/* construct aggregate from the type info */
if (!slang_storage_aggregate_construct (&agg))
- {
- slang_assembly_typeinfo_destruct (&ti);
- return 0;
- }
- if (!_slang_aggregate_variable (&agg, &ti.spec, ti.array_size, space->funcs, space->structs,
- space->vars, mach, file, atoms))
- {
- slang_storage_aggregate_destruct (&agg);
- slang_assembly_typeinfo_destruct (&ti);
- return 0;
- }
+ goto end1;
+ if (!_slang_aggregate_variable (&agg, &ti.spec, ti.array_size, A->space.funcs, A->space.structs,
+ A->space.vars, A->mach, A->file, A->atoms))
+ goto end;
/* dereference the resulting aggregate */
size = _slang_sizeof_aggregate (&agg);
- result = dereference_aggregate (file, &agg, &size, info, &ti.swz, ti.is_swizzled);
+ result = dereference_aggregate (A, &agg, &size, &ti.swz, ti.is_swizzled);
+end:
slang_storage_aggregate_destruct (&agg);
+end1:
slang_assembly_typeinfo_destruct (&ti);
return result;
}
-int _slang_assemble_function_call (slang_assemble_ctx *A, slang_function *fun,
+GLboolean _slang_assemble_function_call (slang_assemble_ctx *A, slang_function *fun,
slang_operation *params, GLuint param_count, GLboolean assignment)
{
- unsigned int i;
- slang_assembly_stack_info p_stk[64];
+ GLuint i;
+ slang_swizzle p_swz[64];
+ slang_ref_type p_ref[64];
/* TODO: fix this, allocate dynamically */
if (param_count > 64)
- return 0;
+ return GL_FALSE;
/* make room for the return value, if any */
if (fun->header.type.specifier.type != slang_spec_void)
{
- unsigned int ret_size = 0;
+ GLuint ret_size = 0;
- if (!sizeof_variable (&fun->header.type.specifier, slang_qual_none, NULL, &A->space,
- &ret_size, A->mach, A->file, A->atoms))
- return 0;
+ if (!sizeof_variable (A, &fun->header.type.specifier, slang_qual_none, NULL, &ret_size))
+ return GL_FALSE;
if (!PLAB (A->file, slang_asm_local_alloc, ret_size))
- return 0;
+ return GL_FALSE;
}
/* push the actual parameters on the stack */
@@ -556,67 +528,70 @@ int _slang_assemble_function_call (slang_assemble_ctx *A, slang_function *fun,
fun->parameters->variables[i].type.qualifier == slang_qual_out)
{
if (!PLAB2 (A->file, slang_asm_local_addr, A->local.addr_tmp, 4))
- return 0;
+ return GL_FALSE;
/* TODO: optimize the "out" parameter case */
if (!_slang_assemble_operation_ (A, &params[i], slang_ref_force))
- return 0;
- p_stk[i] = A->swz;
+ return GL_FALSE;
+ p_swz[i] = A->swz;
+ p_ref[i] = A->ref;
if (!PUSH (A->file, slang_asm_addr_copy))
- return 0;
+ return GL_FALSE;
if (!PUSH (A->file, slang_asm_addr_deref))
- return 0;
+ return GL_FALSE;
if (i == 0 && assignment)
{
/* duplicate the resulting address */
if (!PLAB2 (A->file, slang_asm_local_addr, A->local.addr_tmp, 4))
- return 0;
+ return GL_FALSE;
if (!PUSH (A->file, slang_asm_addr_deref))
- return 0;
+ return GL_FALSE;
}
- if (!_slang_dereference (A->file, &params[i], &A->space, &A->local, A->mach, A->atoms))
- return 0;
+ if (!_slang_dereference (A, &params[i]))
+ return GL_FALSE;
}
else
{
if (!_slang_assemble_operation_ (A, &params[i], slang_ref_forbid))
- return 0;
- p_stk[i] = A->swz;
+ return GL_FALSE;
+ p_swz[i] = A->swz;
+ p_ref[i] = A->ref;
}
}
/* call the function */
if (!PLAB (A->file, slang_asm_call, fun->address))
- return 0;
+ return GL_FALSE;
/* pop the parameters from the stack */
for (i = param_count; i > 0; i--)
{
- unsigned int j = i - 1;
+ GLuint j = i - 1;
+ A->swz = p_swz[j];
+ A->ref = p_ref[j];
if (fun->parameters->variables[j].type.qualifier == slang_qual_inout ||
fun->parameters->variables[j].type.qualifier == slang_qual_out)
{
/* for output parameter copy the contents of the formal parameter
* back to the original actual parameter */
- A->swz = p_stk[j];
if (!_slang_assemble_assignment (A, &params[j]))
- return 0;
+ return GL_FALSE;
/* pop the actual parameter's address */
if (!PLAB (A->file, slang_asm_local_free, 4))
- return 0;
+ return GL_FALSE;
}
else
{
/* pop the value of the parameter */
if (!_slang_cleanup_stack_ (A, &params[j]))
- return 0;
+ return GL_FALSE;
}
}
- return 1;
+ return GL_TRUE;
}
-int _slang_assemble_function_call_name (slang_assemble_ctx *A, const char *name,
+GLboolean _slang_assemble_function_call_name (slang_assemble_ctx *A, const char *name,
slang_operation *params, GLuint param_count, GLboolean assignment)
{
slang_atom atom;
@@ -624,22 +599,22 @@ int _slang_assemble_function_call_name (slang_assemble_ctx *A, const char *name,
atom = slang_atom_pool_atom (A->atoms, name);
if (atom == SLANG_ATOM_NULL)
- return 0;
+ return GL_FALSE;
fun = _slang_locate_function (A->space.funcs, atom, params, param_count, &A->space, A->atoms);
if (fun == NULL)
- return 0;
+ return GL_FALSE;
return _slang_assemble_function_call (A, fun, params, param_count, assignment);
}
-static int assemble_function_call_name_dummyint (slang_assemble_ctx *A, const char *name,
+static GLboolean assemble_function_call_name_dummyint (slang_assemble_ctx *A, const char *name,
slang_operation *params)
{
slang_operation p[2];
- int result;
+ GLboolean result;
p[0] = params[0];
if (!slang_operation_construct (&p[1]))
- return 0;
+ return GL_FALSE;
p[1].type = slang_oper_literal_int;
result = _slang_assemble_function_call_name (A, name, p, 2, GL_FALSE);
slang_operation_destruct (&p[1]);
@@ -666,6 +641,10 @@ static const struct
{ "float_log2", slang_asm_float_log2, slang_asm_float_copy },
{ "float_floor", slang_asm_float_floor, slang_asm_float_copy },
{ "float_ceil", slang_asm_float_ceil, slang_asm_float_copy },
+ { "float_noise1", slang_asm_float_noise1, slang_asm_float_copy },
+ { "float_noise2", slang_asm_float_noise2, slang_asm_float_copy },
+ { "float_noise3", slang_asm_float_noise3, slang_asm_float_copy },
+ { "float_noise4", slang_asm_float_noise4, slang_asm_float_copy },
{ "int_to_float", slang_asm_int_to_float, slang_asm_float_copy },
/* mesa-specific extensions */
{ "float_print", slang_asm_float_deref, slang_asm_float_print },
@@ -674,125 +653,124 @@ static const struct
{ NULL, slang_asm_none, slang_asm_none }
};
-static int call_asm_instruction (slang_assembly_file *file, slang_atom a_name, slang_atom_pool *atoms)
+static GLboolean call_asm_instruction (slang_assemble_ctx *A, slang_atom a_name)
{
const char *id;
- unsigned int i;
+ GLuint i;
- id = slang_atom_pool_id (atoms, a_name);
+ id = slang_atom_pool_id (A->atoms, a_name);
for (i = 0; inst[i].name != NULL; i++)
if (slang_string_compare (id, inst[i].name) == 0)
break;
if (inst[i].name == NULL)
- return 0;
+ return GL_FALSE;
- if (!PLAB2 (file, inst[i].code1, 4, 0))
- return 0;
+ if (!PLAB2 (A->file, inst[i].code1, 4, 0))
+ return GL_FALSE;
if (inst[i].code2 != slang_asm_none)
- if (!PLAB2 (file, inst[i].code2, 4, 0))
- return 0;
+ if (!PLAB2 (A->file, inst[i].code2, 4, 0))
+ return GL_FALSE;
/* clean-up the stack from the remaining dst address */
- if (!PLAB (file, slang_asm_local_free, 4))
- return 0;
+ if (!PLAB (A->file, slang_asm_local_free, 4))
+ return GL_FALSE;
- return 1;
+ return GL_TRUE;
}
-static int equality_aggregate (slang_assembly_file *file, const slang_storage_aggregate *agg,
- unsigned int *index, unsigned int size, slang_assembly_local_info *info, unsigned int z_label)
+static GLboolean equality_aggregate (slang_assemble_ctx *A, const slang_storage_aggregate *agg,
+ GLuint *index, GLuint size, GLuint z_label)
{
- unsigned int i;
+ GLuint i;
for (i = 0; i < agg->count; i++)
{
const slang_storage_array *arr = &agg->arrays[i];
- unsigned int j;
+ GLuint j;
for (j = 0; j < arr->length; j++)
{
if (arr->type == slang_stor_aggregate)
{
- if (!equality_aggregate (file, arr->aggregate, index, size, info, z_label))
- return 0;
+ if (!equality_aggregate (A, arr->aggregate, index, size, z_label))
+ return GL_FALSE;
}
else
{
- if (!PLAB2 (file, slang_asm_float_equal_int, size + *index, *index))
- return 0;
+ if (!PLAB2 (A->file, slang_asm_float_equal_int, size + *index, *index))
+ return GL_FALSE;
*index += 4;
- if (!PLAB (file, slang_asm_jump_if_zero, z_label))
- return 0;
+ if (!PLAB (A->file, slang_asm_jump_if_zero, z_label))
+ return GL_FALSE;
}
}
}
- return 1;
+
+ return GL_TRUE;
}
-static int equality (slang_assembly_file *file, slang_operation *op,
- slang_assembly_name_space *space, slang_assembly_local_info *info, int equal,
- slang_machine *mach, slang_atom_pool *atoms)
+static GLboolean equality (slang_assemble_ctx *A, slang_operation *op, GLboolean equal)
{
slang_assembly_typeinfo ti;
- int result = 0;
+ GLboolean result = GL_FALSE;
slang_storage_aggregate agg;
- unsigned int index, size;
- unsigned int skip_jump, true_label, true_jump, false_label, false_jump;
+ GLuint index, size;
+ GLuint skip_jump, true_label, true_jump, false_label, false_jump;
/* get type of operation */
if (!slang_assembly_typeinfo_construct (&ti))
- return 0;
- if (!_slang_typeof_operation (op, space, &ti, atoms))
+ return GL_FALSE;
+ if (!_slang_typeof_operation (op, &A->space, &ti, A->atoms))
goto end1;
/* convert it to an aggregate */
if (!slang_storage_aggregate_construct (&agg))
goto end1;
- if (!_slang_aggregate_variable (&agg, &ti.spec, NULL, space->funcs, space->structs,
- space->vars, mach, file, atoms))
+ if (!_slang_aggregate_variable (&agg, &ti.spec, NULL, A->space.funcs, A->space.structs,
+ A->space.vars, A->mach, A->file, A->atoms))
goto end;
/* compute the size of the agregate - there are two such aggregates on the stack */
size = _slang_sizeof_aggregate (&agg);
/* jump to the actual data-comparison code */
- skip_jump = file->count;
- if (!PUSH (file, slang_asm_jump))
+ skip_jump = A->file->count;
+ if (!PUSH (A->file, slang_asm_jump))
goto end;
/* pop off the stack the compared data and push 1 */
- true_label = file->count;
- if (!PLAB (file, slang_asm_local_free, size * 2))
+ true_label = A->file->count;
+ if (!PLAB (A->file, slang_asm_local_free, size * 2))
goto end;
- if (!PLIT (file, slang_asm_bool_push, (GLfloat) 1))
+ if (!PLIT (A->file, slang_asm_bool_push, (GLfloat) 1))
goto end;
- true_jump = file->count;
- if (!PUSH (file, slang_asm_jump))
+ true_jump = A->file->count;
+ if (!PUSH (A->file, slang_asm_jump))
goto end;
- false_label = file->count;
- if (!PLAB (file, slang_asm_local_free, size * 2))
+ false_label = A->file->count;
+ if (!PLAB (A->file, slang_asm_local_free, size * 2))
goto end;
- if (!PLIT (file, slang_asm_bool_push, (GLfloat) 0))
+ if (!PLIT (A->file, slang_asm_bool_push, (GLfloat) 0))
goto end;
- false_jump = file->count;
- if (!PUSH (file, slang_asm_jump))
+ false_jump = A->file->count;
+ if (!PUSH (A->file, slang_asm_jump))
goto end;
- file->code[skip_jump].param[0] = file->count;
+ A->file->code[skip_jump].param[0] = A->file->count;
/* compare the data on stack, it will eventually jump either to true or false label */
index = 0;
- if (!equality_aggregate (file, &agg, &index, size, info, equal ? false_label : true_label))
+ if (!equality_aggregate (A, &agg, &index, size, equal ? false_label : true_label))
goto end;
- if (!PLAB (file, slang_asm_jump, equal ? true_label : false_label))
+ if (!PLAB (A->file, slang_asm_jump, equal ? true_label : false_label))
goto end;
- file->code[true_jump].param[0] = file->count;
- file->code[false_jump].param[0] = file->count;
+ A->file->code[true_jump].param[0] = A->file->count;
+ A->file->code[false_jump].param[0] = A->file->count;
- result = 1;
+ result = GL_TRUE;
end:
slang_storage_aggregate_destruct (&agg);
end1:
@@ -800,144 +778,130 @@ end1:
return result;
}
-static int handle_subscript (slang_assembly_typeinfo *tie, slang_assembly_typeinfo *tia,
- slang_assembly_file *file, slang_operation *op, int reference, slang_assembly_flow_control *flow,
- slang_assembly_name_space *space, slang_assembly_local_info *info, slang_machine *mach,
- slang_atom_pool *atoms)
+static GLboolean handle_subscript (slang_assemble_ctx *A, slang_assembly_typeinfo *tie,
+ slang_assembly_typeinfo *tia, slang_operation *op, slang_ref_type ref)
{
- unsigned int asize = 0, esize = 0;
- slang_assembly_stack_info _stk;
+ GLuint asize = 0, esize = 0;
/* get type info of the master expression (matrix, vector or an array */
- if (!_slang_typeof_operation (&op->children[0], space, tia, atoms))
- return 0;
- if (!sizeof_variable (&tia->spec, slang_qual_none, tia->array_size, space, &asize, mach, file,
- atoms))
- return 0;
+ if (!_slang_typeof_operation (&op->children[0], &A->space, tia, A->atoms))
+ return GL_FALSE;
+ if (!sizeof_variable (A, &tia->spec, slang_qual_none, tia->array_size, &asize))
+ return GL_FALSE;
/* get type info of the result (matrix column, vector row or array element) */
- if (!_slang_typeof_operation (op, space, tie, atoms))
- return 0;
- if (!sizeof_variable (&tie->spec, slang_qual_none, NULL, space, &esize, mach, file, atoms))
- return 0;
+ if (!_slang_typeof_operation (op, &A->space, tie, A->atoms))
+ return GL_FALSE;
+ if (!sizeof_variable (A, &tie->spec, slang_qual_none, NULL, &esize))
+ return GL_FALSE;
/* assemble the master expression */
- if (!_slang_assemble_operation (file, &op->children[0], reference, flow, space, info, &_stk,
- mach, atoms))
- return 0;
- /* ignre the _stk */
+ if (!_slang_assemble_operation_ (A, &op->children[0], ref))
+ return GL_FALSE;
/* when indexing an l-value swizzle, push the swizzle_tmp */
- if (reference && tia->is_swizzled)
- {
- if (!PLAB2 (file, slang_asm_local_addr, info->swizzle_tmp, 16))
- return 0;
- }
+ if (ref == slang_ref_force && tia->is_swizzled)
+ if (!PLAB2 (A->file, slang_asm_local_addr, A->local.swizzle_tmp, 16))
+ return GL_FALSE;
/* assemble the subscript expression */
- if (!_slang_assemble_operation (file, &op->children[1], 0, flow, space, info, &_stk, mach, atoms))
- return 0;
- /* ignore the _stk */
+ if (!_slang_assemble_operation_ (A, &op->children[1], slang_ref_forbid))
+ return GL_FALSE;
- if (reference && tia->is_swizzled)
+ if (ref == slang_ref_force && tia->is_swizzled)
{
- unsigned int i;
+ GLuint i;
/* copy the swizzle indexes to the swizzle_tmp */
for (i = 0; i < tia->swz.num_components; i++)
{
- if (!PLAB2 (file, slang_asm_local_addr, info->swizzle_tmp, 16))
- return 0;
- if (!PLAB (file, slang_asm_addr_push, i * 4))
- return 0;
- if (!PUSH (file, slang_asm_addr_add))
- return 0;
- if (!PLAB (file, slang_asm_addr_push, tia->swz.swizzle[i]))
- return 0;
- if (!PUSH (file, slang_asm_addr_copy))
- return 0;
- if (!PLAB (file, slang_asm_local_free, 4))
- return 0;
+ if (!PLAB2 (A->file, slang_asm_local_addr, A->local.swizzle_tmp, 16))
+ return GL_FALSE;
+ if (!PLAB (A->file, slang_asm_addr_push, i * 4))
+ return GL_FALSE;
+ if (!PUSH (A->file, slang_asm_addr_add))
+ return GL_FALSE;
+ if (!PLAB (A->file, slang_asm_addr_push, tia->swz.swizzle[i]))
+ return GL_FALSE;
+ if (!PUSH (A->file, slang_asm_addr_copy))
+ return GL_FALSE;
+ if (!PLAB (A->file, slang_asm_local_free, 4))
+ return GL_FALSE;
}
/* offset the pushed swizzle_tmp address and dereference it */
- if (!PUSH (file, slang_asm_int_to_addr))
- return 0;
- if (!PLAB (file, slang_asm_addr_push, 4))
- return 0;
- if (!PUSH (file, slang_asm_addr_multiply))
- return 0;
- if (!PUSH (file, slang_asm_addr_add))
- return 0;
- if (!PUSH (file, slang_asm_addr_deref))
- return 0;
+ if (!PUSH (A->file, slang_asm_int_to_addr))
+ return GL_FALSE;
+ if (!PLAB (A->file, slang_asm_addr_push, 4))
+ return GL_FALSE;
+ if (!PUSH (A->file, slang_asm_addr_multiply))
+ return GL_FALSE;
+ if (!PUSH (A->file, slang_asm_addr_add))
+ return GL_FALSE;
+ if (!PUSH (A->file, slang_asm_addr_deref))
+ return GL_FALSE;
}
else
{
/* convert the integer subscript to a relative address */
- if (!PUSH (file, slang_asm_int_to_addr))
- return 0;
+ if (!PUSH (A->file, slang_asm_int_to_addr))
+ return GL_FALSE;
}
- if (!PLAB (file, slang_asm_addr_push, esize))
- return 0;
- if (!PUSH (file, slang_asm_addr_multiply))
- return 0;
+ if (!PLAB (A->file, slang_asm_addr_push, esize))
+ return GL_FALSE;
+ if (!PUSH (A->file, slang_asm_addr_multiply))
+ return GL_FALSE;
- if (reference)
+ if (ref == slang_ref_force)
{
/* offset the base address with the relative address */
- if (!PUSH (file, slang_asm_addr_add))
- return 0;
+ if (!PUSH (A->file, slang_asm_addr_add))
+ return GL_FALSE;
}
else
{
- unsigned int i;
+ GLuint i;
/* move the selected element to the beginning of the master expression */
for (i = 0; i < esize; i += 4)
- if (!PLAB2 (file, slang_asm_float_move, asize - esize + i + 4, i + 4))
- return 0;
- if (!PLAB (file, slang_asm_local_free, 4))
- return 0;
+ if (!PLAB2 (A->file, slang_asm_float_move, asize - esize + i + 4, i + 4))
+ return GL_FALSE;
+ if (!PLAB (A->file, slang_asm_local_free, 4))
+ return GL_FALSE;
/* free the rest of the master expression */
- if (!PLAB (file, slang_asm_local_free, asize - esize))
- return 0;
+ if (!PLAB (A->file, slang_asm_local_free, asize - esize))
+ return GL_FALSE;
}
- return 1;
+
+ return GL_TRUE;
}
-static int handle_field (slang_assembly_typeinfo *tia, slang_assembly_typeinfo *tib,
- slang_assembly_file *file, slang_operation *op, int reference, slang_assembly_flow_control *flow,
- slang_assembly_name_space *space, slang_assembly_local_info *info, slang_assembly_stack_info *stk,
- slang_machine *mach, slang_atom_pool *atoms)
+static GLboolean handle_field (slang_assemble_ctx *A, slang_assembly_typeinfo *tia,
+ slang_assembly_typeinfo *tib, slang_operation *op, slang_ref_type ref)
{
- slang_assembly_stack_info _stk;
-
/* get type info of the result (field or swizzle) */
- if (!_slang_typeof_operation (op, space, tia, atoms))
- return 0;
+ if (!_slang_typeof_operation (op, &A->space, tia, A->atoms))
+ return GL_FALSE;
/* get type info of the master expression being accessed (struct or vector) */
- if (!_slang_typeof_operation (&op->children[0], space, tib, atoms))
- return 0;
+ if (!_slang_typeof_operation (&op->children[0], &A->space, tib, A->atoms))
+ return GL_FALSE;
/* if swizzling a vector in-place, the swizzle temporary is needed */
- if (!reference && tia->is_swizzled)
- if (!PLAB2 (file, slang_asm_local_addr, info->swizzle_tmp, 16))
- return 0;
+ if (ref == slang_ref_forbid && tia->is_swizzled)
+ if (!PLAB2 (A->file, slang_asm_local_addr, A->local.swizzle_tmp, 16))
+ return GL_FALSE;
/* assemble the master expression */
- if (!_slang_assemble_operation (file, &op->children[0], reference, flow, space, info, &_stk,
- mach, atoms))
- return 0;
- /* ignore _stk.swizzle - we'll have it in tia->swz */
+ if (!_slang_assemble_operation_ (A, &op->children[0], ref))
+ return GL_FALSE;
/* assemble the field expression */
if (tia->is_swizzled)
{
- if (reference)
+ if (ref == slang_ref_force)
{
#if 0
if (tia->swz.num_components == 1)
@@ -954,15 +918,14 @@ static int handle_field (slang_assembly_typeinfo *tia, slang_assembly_typeinfo *
/* two or more vector components are being referenced - the so-called write mask
* must be passed to the upper operations and applied when assigning value
* to this swizzle */
- stk->swizzle = tia->swz;
+ A->swz = tia->swz;
}
}
else
{
/* swizzle the vector in-place using the swizzle temporary */
- if (!_slang_assemble_constructor_from_swizzle (file, &tia->swz, &tia->spec, &tib->spec,
- info))
- return 0;
+ if (!_slang_assemble_constructor_from_swizzle (A, &tia->swz, &tia->spec, &tib->spec))
+ return GL_FALSE;
}
}
else
@@ -977,12 +940,12 @@ static int handle_field (slang_assembly_typeinfo *tia, slang_assembly_typeinfo *
field = &tib->spec._struct->fields->variables[i];
if (!slang_storage_aggregate_construct (&agg))
- return 0;
+ return GL_FALSE;
if (!_slang_aggregate_variable (&agg, &field->type.specifier, field->array_size,
- space->funcs, space->structs, space->vars, mach, file, atoms))
+ A->space.funcs, A->space.structs, A->space.vars, A->mach, A->file, A->atoms))
{
slang_storage_aggregate_destruct (&agg);
- return 0;
+ return GL_FALSE;
}
size = _slang_sizeof_aggregate (&agg);
slang_storage_aggregate_destruct (&agg);
@@ -998,86 +961,65 @@ static int handle_field (slang_assembly_typeinfo *tia, slang_assembly_typeinfo *
field_offset += size;
}
- if (!PLAB (file, slang_asm_addr_push, field_offset))
- return 0;
+ if (!PLAB (A->file, slang_asm_addr_push, field_offset))
+ return GL_FALSE;
- if (reference)
+ if (ref == slang_ref_force)
{
- if (!PUSH (file, slang_asm_addr_add))
- return 0;
+ if (!PUSH (A->file, slang_asm_addr_add))
+ return GL_FALSE;
}
else
{
- unsigned int i;
+ GLuint i;
/* move the selected element to the beginning of the master expression */
for (i = 0; i < field_size; i += 4)
- if (!PLAB2 (file, slang_asm_float_move, struct_size - field_size + i + 4, i + 4))
- return 0;
- if (!PLAB (file, slang_asm_local_free, 4))
- return 0;
+ if (!PLAB2 (A->file, slang_asm_float_move, struct_size - field_size + i + 4, i + 4))
+ return GL_FALSE;
+ if (!PLAB (A->file, slang_asm_local_free, 4))
+ return GL_FALSE;
/* free the rest of the master expression */
- if (!PLAB (file, slang_asm_local_free, struct_size - field_size))
- return 0;
+ if (!PLAB (A->file, slang_asm_local_free, struct_size - field_size))
+ return GL_FALSE;
}
}
- return 1;
-}
-int _slang_assemble_operation (slang_assembly_file *file, struct slang_operation_ *op, int reference,
- slang_assembly_flow_control *flow, slang_assembly_name_space *space, slang_assembly_local_info *info,
- slang_assembly_stack_info *stk, struct slang_machine_ *mach, slang_atom_pool *atoms)
-{
- slang_assemble_ctx A;
-
- A.file = file;
- A.mach = mach;
- A.atoms = atoms;
- A.space = *space;
- A.flow = *flow;
- A.local = *info;
- if (!_slang_assemble_operation_ (&A, op, reference ? slang_ref_force : slang_ref_forbid))
- return 0;
- *stk = A.swz;
- return 1;
+ return GL_TRUE;
}
-int _slang_assemble_operation_ (slang_assemble_ctx *A, slang_operation *op, slang_ref_type ref)
+GLboolean _slang_assemble_operation_ (slang_assemble_ctx *A, slang_operation *op, slang_ref_type ref)
{
- unsigned int assem;
- slang_assembly_stack_info swz;
+ GLuint assem;
assem = A->file->count;
if (!push_new (A->file))
- return 0;
-
-if (ref == slang_ref_freelance)
-ref = slang_ref_forbid;
+ return GL_FALSE;
/* set default results */
- A->ref = (ref == slang_ref_freelance) ? slang_ref_force : ref;
- swz.swizzle.num_components = 0;
+ A->ref = /*(ref == slang_ref_freelance) ? slang_ref_force : */ref;
+ A->swz.num_components = 0;
switch (op->type)
{
case slang_oper_block_no_new_scope:
case slang_oper_block_new_scope:
{
- unsigned int i;
+ GLuint i;
for (i = 0; i < op->num_children; i++)
{
- if (!_slang_assemble_operation_ (A, &op->children[i], slang_ref_freelance))
- return 0;
+ if (!_slang_assemble_operation_ (A, &op->children[i], slang_ref_forbid/*slang_ref_freelance*/))
+ return GL_FALSE;
if (!_slang_cleanup_stack_ (A, &op->children[i]))
- return 0;
+ return GL_FALSE;
}
}
break;
case slang_oper_variable_decl:
{
- unsigned int i;
+ GLuint i;
for (i = 0; i < op->num_children; i++)
{
@@ -1088,15 +1030,15 @@ ref = slang_ref_forbid;
break;
case slang_oper_asm:
{
- unsigned int i;
+ GLuint i;
if (!_slang_assemble_operation_ (A, &op->children[0], slang_ref_force))
- return 0;
+ return GL_FALSE;
for (i = 1; i < op->num_children; i++)
if (!_slang_assemble_operation_ (A, &op->children[i], slang_ref_forbid))
- return 0;
- if (!call_asm_instruction (A->file, op->a_id, A->atoms))
- return 0;
+ return GL_FALSE;
+ if (!call_asm_instruction (A, op->a_id))
+ return GL_FALSE;
}
break;
case slang_oper_break:
@@ -1110,69 +1052,69 @@ ref = slang_ref_forbid;
case slang_oper_discard:
A->file->code[assem].type = slang_asm_discard;
if (!PUSH (A->file, slang_asm_exit))
- return 0;
+ return GL_FALSE;
break;
case slang_oper_return:
if (A->local.ret_size != 0)
{
/* push the result's address */
if (!PLAB2 (A->file, slang_asm_local_addr, 0, A->local.ret_size))
- return 0;
+ return GL_FALSE;
if (!_slang_assemble_operation_ (A, &op->children[0], slang_ref_forbid))
- return 0;
+ return GL_FALSE;
- A->swz.swizzle.num_components = 0;
+ A->swz.num_components = 0;
/* assign the operation to the function result (it was reserved on the stack) */
if (!_slang_assemble_assignment (A, op->children))
- return 0;
+ return GL_FALSE;
if (!PLAB (A->file, slang_asm_local_free, 4))
- return 0;
+ return GL_FALSE;
}
if (!PLAB (A->file, slang_asm_jump, A->flow.function_end))
- return 0;
+ return GL_FALSE;
break;
case slang_oper_expression:
if (ref == slang_ref_force)
- return 0;
+ return GL_FALSE;
if (!_slang_assemble_operation_ (A, &op->children[0], ref))
- return 0;
+ return GL_FALSE;
break;
case slang_oper_if:
- if (!_slang_assemble_if (A->file, op, &A->flow, &A->space, &A->local, A->mach, A->atoms))
- return 0;
+ if (!_slang_assemble_if (A, op))
+ return GL_FALSE;
break;
case slang_oper_while:
- if (!_slang_assemble_while (A->file, op, &A->flow, &A->space, &A->local, A->mach, A->atoms))
- return 0;
+ if (!_slang_assemble_while (A, op))
+ return GL_FALSE;
break;
case slang_oper_do:
- if (!_slang_assemble_do (A->file, op, &A->flow, &A->space, &A->local, A->mach, A->atoms))
- return 0;
+ if (!_slang_assemble_do (A, op))
+ return GL_FALSE;
break;
case slang_oper_for:
- if (!_slang_assemble_for (A->file, op, &A->flow, &A->space, &A->local, A->mach, A->atoms))
- return 0;
+ if (!_slang_assemble_for (A, op))
+ return GL_FALSE;
break;
case slang_oper_void:
break;
case slang_oper_literal_bool:
if (ref == slang_ref_force)
- return 0;
+ return GL_FALSE;
A->file->code[assem].type = slang_asm_bool_push;
A->file->code[assem].literal = op->literal;
A->ref = slang_ref_forbid;
break;
case slang_oper_literal_int:
if (ref == slang_ref_force)
- return 0;
+ return GL_FALSE;
A->file->code[assem].type = slang_asm_int_push;
A->file->code[assem].literal = op->literal;
A->ref = slang_ref_forbid;
break;
case slang_oper_literal_float:
if (ref == slang_ref_force)
- return 0;
+ return GL_FALSE;
A->file->code[assem].type = slang_asm_float_push;
A->file->code[assem].literal = op->literal;
A->ref = slang_ref_forbid;
@@ -1180,72 +1122,71 @@ ref = slang_ref_forbid;
case slang_oper_identifier:
{
slang_variable *var;
- unsigned int size;
+ GLuint size;
/* find the variable and calculate its size */
- var = _slang_locate_variable (op->locals, op->a_id, 1);
+ var = _slang_locate_variable (op->locals, op->a_id, GL_TRUE);
if (var == NULL)
- return 0;
+ return GL_FALSE;
size = 0;
- if (!sizeof_variable (&var->type.specifier, slang_qual_none, var->array_size, &A->space,
- &size, A->mach, A->file, A->atoms))
- return 0;
+ if (!sizeof_variable (A, &var->type.specifier, slang_qual_none, var->array_size, &size))
+ return GL_FALSE;
/* prepare stack for dereferencing */
if (ref == slang_ref_forbid)
if (!PLAB2 (A->file, slang_asm_local_addr, A->local.addr_tmp, 4))
- return 0;
+ return GL_FALSE;
/* push the variable's address */
if (var->global)
{
if (!PLAB (A->file, slang_asm_addr_push, var->address))
- return 0;
+ return GL_FALSE;
}
else
{
if (!PLAB2 (A->file, slang_asm_local_addr, var->address, size))
- return 0;
+ return GL_FALSE;
}
/* perform the dereference */
if (ref == slang_ref_forbid)
{
if (!PUSH (A->file, slang_asm_addr_copy))
- return 0;
+ return GL_FALSE;
if (!PLAB (A->file, slang_asm_local_free, 4))
- return 0;
- if (!_slang_dereference (A->file, op, &A->space, &A->local, A->mach, A->atoms))
- return 0;
+ return GL_FALSE;
+ if (!_slang_dereference (A, op))
+ return GL_FALSE;
}
}
break;
case slang_oper_sequence:
if (ref == slang_ref_force)
- return 0;
- if (!_slang_assemble_operation_ (A, &op->children[0], slang_ref_freelance))
- return 0;
+ return GL_FALSE;
+ if (!_slang_assemble_operation_ (A, &op->children[0], slang_ref_forbid/*slang_ref_freelance*/))
+ return GL_FALSE;
if (!_slang_cleanup_stack_ (A, &op->children[0]))
- return 0;
+ return GL_FALSE;
if (!_slang_assemble_operation_ (A, &op->children[1], slang_ref_forbid))
- return 0;
+ return GL_FALSE;
A->ref = slang_ref_forbid;
break;
case slang_oper_assign:
if (!_slang_assemble_assign (A, op, "=", ref))
- return 0;
+ return GL_FALSE;
break;
case slang_oper_addassign:
if (!_slang_assemble_assign (A, op, "+=", ref))
- return 0;
+ return GL_FALSE;
break;
case slang_oper_subassign:
if (!_slang_assemble_assign (A, op, "-=", ref))
- return 0;
+ return GL_FALSE;
break;
case slang_oper_mulassign:
if (!_slang_assemble_assign (A, op, "*=", ref))
- return 0;
+ return GL_FALSE;
break;
/*case slang_oper_modassign:*/
/*case slang_oper_lshassign:*/
@@ -1255,26 +1196,26 @@ ref = slang_ref_forbid;
/*case slang_oper_andassign:*/
case slang_oper_divassign:
if (!_slang_assemble_assign (A, op, "/=", ref))
- return 0;
+ return GL_FALSE;
break;
case slang_oper_select:
- if (!_slang_assemble_select (A->file, op, &A->flow, &A->space, &A->local, A->mach, A->atoms))
- return 0;
+ if (!_slang_assemble_select (A, op))
+ return GL_FALSE;
A->ref = slang_ref_forbid;
break;
case slang_oper_logicalor:
- if (!_slang_assemble_logicalor (A->file, op, &A->flow, &A->space, &A->local, A->mach, A->atoms))
- return 0;
+ if (!_slang_assemble_logicalor (A, op))
+ return GL_FALSE;
A->ref = slang_ref_forbid;
break;
case slang_oper_logicaland:
- if (!_slang_assemble_logicaland (A->file, op, &A->flow, &A->space, &A->local, A->mach, A->atoms))
- return 0;
+ if (!_slang_assemble_logicaland (A, op))
+ return GL_FALSE;
A->ref = slang_ref_forbid;
break;
case slang_oper_logicalxor:
if (!_slang_assemble_function_call_name (A, "^^", op->children, 2, GL_FALSE))
- return 0;
+ return GL_FALSE;
A->ref = slang_ref_forbid;
break;
/*case slang_oper_bitor:*/
@@ -1282,87 +1223,87 @@ ref = slang_ref_forbid;
/*case slang_oper_bitand:*/
case slang_oper_less:
if (!_slang_assemble_function_call_name (A, "<", op->children, 2, GL_FALSE))
- return 0;
+ return GL_FALSE;
A->ref = slang_ref_forbid;
break;
case slang_oper_greater:
if (!_slang_assemble_function_call_name (A, ">", op->children, 2, GL_FALSE))
- return 0;
+ return GL_FALSE;
A->ref = slang_ref_forbid;
break;
case slang_oper_lessequal:
if (!_slang_assemble_function_call_name (A, "<=", op->children, 2, GL_FALSE))
- return 0;
+ return GL_FALSE;
A->ref = slang_ref_forbid;
break;
case slang_oper_greaterequal:
if (!_slang_assemble_function_call_name (A, ">=", op->children, 2, GL_FALSE))
- return 0;
+ return GL_FALSE;
A->ref = slang_ref_forbid;
break;
/*case slang_oper_lshift:*/
/*case slang_oper_rshift:*/
case slang_oper_add:
if (!_slang_assemble_function_call_name (A, "+", op->children, 2, GL_FALSE))
- return 0;
+ return GL_FALSE;
A->ref = slang_ref_forbid;
break;
case slang_oper_subtract:
if (!_slang_assemble_function_call_name (A, "-", op->children, 2, GL_FALSE))
- return 0;
+ return GL_FALSE;
A->ref = slang_ref_forbid;
break;
case slang_oper_multiply:
if (!_slang_assemble_function_call_name (A, "*", op->children, 2, GL_FALSE))
- return 0;
+ return GL_FALSE;
A->ref = slang_ref_forbid;
break;
/*case slang_oper_modulus:*/
case slang_oper_divide:
if (!_slang_assemble_function_call_name (A, "/", op->children, 2, GL_FALSE))
- return 0;
+ return GL_FALSE;
A->ref = slang_ref_forbid;
break;
case slang_oper_equal:
if (!_slang_assemble_operation_ (A, &op->children[0], slang_ref_forbid))
- return 0;
+ return GL_FALSE;
if (!_slang_assemble_operation_ (A, &op->children[1], slang_ref_forbid))
- return 0;
- if (!equality (A->file, op->children, &A->space, &A->local, 1, A->mach, A->atoms))
- return 0;
+ return GL_FALSE;
+ if (!equality (A, op->children, GL_TRUE))
+ return GL_FALSE;
A->ref = slang_ref_forbid;
break;
case slang_oper_notequal:
if (!_slang_assemble_operation_ (A, &op->children[0], slang_ref_forbid))
- return 0;
+ return GL_FALSE;
if (!_slang_assemble_operation_ (A, &op->children[1], slang_ref_forbid))
- return 0;
- if (!equality (A->file, op->children, &A->space, &A->local, 0, A->mach, A->atoms))
- return 0;
+ return GL_FALSE;
+ if (!equality (A, op->children, GL_FALSE))
+ return GL_FALSE;
A->ref = slang_ref_forbid;
break;
case slang_oper_preincrement:
if (!_slang_assemble_assign (A, op, "++", ref))
- return 0;
+ return GL_FALSE;
break;
case slang_oper_predecrement:
if (!_slang_assemble_assign (A, op, "--", ref))
- return 0;
+ return GL_FALSE;
break;
case slang_oper_plus:
- if (!_slang_dereference (A->file, op, &A->space, &A->local, A->mach, A->atoms))
- return 0;
+ if (!_slang_dereference (A, op))
+ return GL_FALSE;
A->ref = slang_ref_forbid;
break;
case slang_oper_minus:
if (!_slang_assemble_function_call_name (A, "-", op->children, 1, GL_FALSE))
- return 0;
+ return GL_FALSE;
A->ref = slang_ref_forbid;
break;
/*case slang_oper_complement:*/
case slang_oper_not:
if (!_slang_assemble_function_call_name (A, "!", op->children, 1, GL_FALSE))
- return 0;
+ return GL_FALSE;
A->ref = slang_ref_forbid;
break;
case slang_oper_subscript:
@@ -1370,18 +1311,17 @@ ref = slang_ref_forbid;
slang_assembly_typeinfo ti_arr, ti_elem;
if (!slang_assembly_typeinfo_construct (&ti_arr))
- return 0;
+ return GL_FALSE;
if (!slang_assembly_typeinfo_construct (&ti_elem))
{
slang_assembly_typeinfo_destruct (&ti_arr);
- return 0;
+ return GL_FALSE;
}
- if (!handle_subscript (&ti_elem, &ti_arr, A->file, op, ref != slang_ref_forbid, &A->flow, &A->space, &A->local,
- A->mach, A->atoms))
+ if (!handle_subscript (A, &ti_elem, &ti_arr, op, ref))
{
slang_assembly_typeinfo_destruct (&ti_arr);
slang_assembly_typeinfo_destruct (&ti_elem);
- return 0;
+ return GL_FALSE;
}
slang_assembly_typeinfo_destruct (&ti_arr);
slang_assembly_typeinfo_destruct (&ti_elem);
@@ -1395,13 +1335,13 @@ ref = slang_ref_forbid;
&A->space, A->atoms);
if (fun == NULL)
{
-/* if (!_slang_assemble_constructor (file, op, flow, space, info, mach))
-*/ return 0;
+ if (!_slang_assemble_constructor (A, op))
+ return GL_FALSE;
}
else
{
if (!_slang_assemble_function_call (A, fun, op->children, op->num_children, GL_FALSE))
- return 0;
+ return GL_FALSE;
}
A->ref = slang_ref_forbid;
}
@@ -1411,18 +1351,17 @@ ref = slang_ref_forbid;
slang_assembly_typeinfo ti_after, ti_before;
if (!slang_assembly_typeinfo_construct (&ti_after))
- return 0;
+ return GL_FALSE;
if (!slang_assembly_typeinfo_construct (&ti_before))
{
slang_assembly_typeinfo_destruct (&ti_after);
- return 0;
+ return GL_FALSE;
}
- if (!handle_field (&ti_after, &ti_before, A->file, op, ref != slang_ref_forbid, &A->flow, &A->space, &A->local, &swz,
- A->mach, A->atoms))
+ if (!handle_field (A, &ti_after, &ti_before, op, ref))
{
slang_assembly_typeinfo_destruct (&ti_after);
slang_assembly_typeinfo_destruct (&ti_before);
- return 0;
+ return GL_FALSE;
}
slang_assembly_typeinfo_destruct (&ti_after);
slang_assembly_typeinfo_destruct (&ti_before);
@@ -1430,20 +1369,18 @@ ref = slang_ref_forbid;
break;
case slang_oper_postincrement:
if (!assemble_function_call_name_dummyint (A, "++", op->children))
- return 0;
+ return GL_FALSE;
A->ref = slang_ref_forbid;
break;
case slang_oper_postdecrement:
if (!assemble_function_call_name_dummyint (A, "--", op->children))
- return 0;
+ return GL_FALSE;
A->ref = slang_ref_forbid;
break;
default:
- return 0;
+ return GL_FALSE;
}
- A->swz = swz;
-
- return 1;
+ return GL_TRUE;
}
diff --git a/src/mesa/shader/slang/slang_assemble.h b/src/mesa/shader/slang/slang_assemble.h
index 3d5eec21047..ec273aa308c 100644
--- a/src/mesa/shader/slang/slang_assemble.h
+++ b/src/mesa/shader/slang/slang_assemble.h
@@ -54,6 +54,10 @@ typedef enum slang_assembly_type_
slang_asm_float_log2,
slang_asm_float_floor,
slang_asm_float_ceil,
+ slang_asm_float_noise1,
+ slang_asm_float_noise2,
+ slang_asm_float_noise3,
+ slang_asm_float_noise4,
slang_asm_int_copy,
slang_asm_int_move,
slang_asm_int_push,
@@ -97,64 +101,59 @@ typedef struct slang_assembly_
typedef struct slang_assembly_file_
{
slang_assembly *code;
- unsigned int count;
- unsigned int capacity;
+ GLuint count;
+ GLuint capacity;
} slang_assembly_file;
-int slang_assembly_file_construct (slang_assembly_file *);
-void slang_assembly_file_destruct (slang_assembly_file *);
-int slang_assembly_file_push (slang_assembly_file *, slang_assembly_type);
-int slang_assembly_file_push_label (slang_assembly_file *, slang_assembly_type, GLuint);
-int slang_assembly_file_push_label2 (slang_assembly_file *, slang_assembly_type, GLuint, GLuint);
-int slang_assembly_file_push_literal (slang_assembly_file *, slang_assembly_type, GLfloat);
+GLboolean slang_assembly_file_construct (slang_assembly_file *);
+GLvoid slang_assembly_file_destruct (slang_assembly_file *);
+GLboolean slang_assembly_file_push (slang_assembly_file *, slang_assembly_type);
+GLboolean slang_assembly_file_push_label (slang_assembly_file *, slang_assembly_type, GLuint);
+GLboolean slang_assembly_file_push_label2 (slang_assembly_file *, slang_assembly_type, GLuint, GLuint);
+GLboolean slang_assembly_file_push_literal (slang_assembly_file *, slang_assembly_type, GLfloat);
typedef struct slang_assembly_file_restore_point_
{
- unsigned int count;
+ GLuint count;
} slang_assembly_file_restore_point;
-int slang_assembly_file_restore_point_save (slang_assembly_file *,
+GLboolean slang_assembly_file_restore_point_save (slang_assembly_file *,
slang_assembly_file_restore_point *);
-int slang_assembly_file_restore_point_load (slang_assembly_file *,
+GLboolean slang_assembly_file_restore_point_load (slang_assembly_file *,
slang_assembly_file_restore_point *);
typedef struct slang_assembly_flow_control_
{
- unsigned int loop_start; /* for "continue" statement */
- unsigned int loop_end; /* for "break" statement */
- unsigned int function_end; /* for "return" statement */
+ GLuint loop_start; /* for "continue" statement */
+ GLuint loop_end; /* for "break" statement */
+ GLuint function_end; /* for "return" statement */
} slang_assembly_flow_control;
typedef struct slang_assembly_local_info_
{
- unsigned int ret_size;
- unsigned int addr_tmp;
- unsigned int swizzle_tmp;
+ GLuint ret_size;
+ GLuint addr_tmp;
+ GLuint swizzle_tmp;
} slang_assembly_local_info;
typedef enum
{
slang_ref_force,
- slang_ref_forbid,
- slang_ref_freelance
+ slang_ref_forbid/*,
+ slang_ref_freelance*/
} slang_ref_type;
/*
- holds a complete information about vector swizzle - the <swizzle> array contains
- vector component sources indices, where 0 is "x", 1 is "y", ...
- example: "xwz" --> { 3, { 0, 3, 2, n/u } }
-*/
+ * Holds a complete information about vector swizzle - the <swizzle> array contains
+ * vector component source indices, where 0 is "x", 1 is "y", 2 is "z" and 3 is "w".
+ * Example: "xwz" --> { 3, { 0, 3, 2, not used } }.
+ */
typedef struct slang_swizzle_
{
- unsigned int num_components;
- unsigned int swizzle[4];
+ GLuint num_components;
+ GLuint swizzle[4];
} slang_swizzle;
-typedef struct slang_assembly_stack_info_
-{
- slang_swizzle swizzle;
-} slang_assembly_stack_info;
-
typedef struct slang_assembly_name_space_
{
struct slang_function_scope_ *funcs;
@@ -171,32 +170,26 @@ typedef struct slang_assemble_ctx_
slang_assembly_flow_control flow;
slang_assembly_local_info local;
slang_ref_type ref;
- slang_assembly_stack_info swz;
+ slang_swizzle swz;
} slang_assemble_ctx;
slang_function *_slang_locate_function (slang_function_scope *funcs, slang_atom a_name,
- slang_operation *params, unsigned int num_params, slang_assembly_name_space *space,
+ slang_operation *params, GLuint num_params, slang_assembly_name_space *space,
slang_atom_pool *);
-int _slang_assemble_function (slang_assemble_ctx *, struct slang_function_ *);
+GLboolean _slang_assemble_function (slang_assemble_ctx *, struct slang_function_ *);
-int _slang_cleanup_stack (slang_assembly_file *, slang_operation *, int ref,
- slang_assembly_name_space *, struct slang_machine_ *, slang_atom_pool *);
-int _slang_cleanup_stack_ (slang_assemble_ctx *, slang_operation *);
+GLboolean _slang_cleanup_stack_ (slang_assemble_ctx *, slang_operation *);
-int _slang_dereference (slang_assembly_file *, slang_operation *, slang_assembly_name_space *,
- slang_assembly_local_info *, struct slang_machine_ *, slang_atom_pool *);
+GLboolean _slang_dereference (slang_assemble_ctx *, slang_operation *);
-int _slang_assemble_function_call (slang_assemble_ctx *, slang_function *,
- slang_operation *, GLuint, GLboolean);
+GLboolean _slang_assemble_function_call (slang_assemble_ctx *, slang_function *, slang_operation *,
+ GLuint, GLboolean);
-int _slang_assemble_function_call_name (slang_assemble_ctx *, const char *,
- slang_operation *, GLuint, GLboolean);
+GLboolean _slang_assemble_function_call_name (slang_assemble_ctx *, const char *, slang_operation *,
+ GLuint, GLboolean);
-int _slang_assemble_operation (slang_assembly_file *, struct slang_operation_ *, int reference,
- slang_assembly_flow_control *, slang_assembly_name_space *, slang_assembly_local_info *,
- slang_assembly_stack_info *, struct slang_machine_ *, slang_atom_pool *);
-int _slang_assemble_operation_ (slang_assemble_ctx *, struct slang_operation_ *, slang_ref_type);
+GLboolean _slang_assemble_operation_ (slang_assemble_ctx *, struct slang_operation_ *, slang_ref_type);
#ifdef __cplusplus
}
diff --git a/src/mesa/shader/slang/slang_assemble_assignment.c b/src/mesa/shader/slang/slang_assemble_assignment.c
index ca857fad2fc..186c4886f70 100644
--- a/src/mesa/shader/slang/slang_assemble_assignment.c
+++ b/src/mesa/shader/slang/slang_assemble_assignment.c
@@ -36,57 +36,56 @@
#include "slang_execute.h"
/*
- _slang_assemble_assignment()
-
- copies values on the stack (<component 0> to <component N-1>) to a memory
- location pointed by <addr of variable>;
-
- in:
- +------------------+
- | addr of variable |
- +------------------+
- | component N-1 |
- | ... |
- | component 0 |
- +------------------+
-
- out:
- +------------------+
- | addr of variable |
- +------------------+
-*/
-
-static int assign_aggregate (slang_assembly_file *file, const slang_storage_aggregate *agg,
- unsigned int *index, unsigned int size, slang_assembly_local_info *info,
- slang_assembly_stack_info *stk)
+ * _slang_assemble_assignment()
+ *
+ * Copies values on the stack (<component 0> to <component N-1>) to a memory
+ * location pointed by <addr of variable>.
+ *
+ * in:
+ * +------------------+
+ * | addr of variable |
+ * +------------------+
+ * | component N-1 |
+ * | ... |
+ * | component 0 |
+ * +------------------+
+ *
+ * out:
+ * +------------------+
+ * | addr of variable |
+ * +------------------+
+ */
+
+static GLboolean assign_aggregate (slang_assemble_ctx *A, const slang_storage_aggregate *agg,
+ GLuint *index, GLuint size)
{
- unsigned int i;
+ GLuint i;
for (i = 0; i < agg->count; i++)
{
const slang_storage_array *arr = &agg->arrays[i];
- unsigned int j;
+ GLuint j;
for (j = 0; j < arr->length; j++)
{
if (arr->type == slang_stor_aggregate)
{
- if (!assign_aggregate (file, arr->aggregate, index, size, info, stk))
- return 0;
+ if (!assign_aggregate (A, arr->aggregate, index, size))
+ return GL_FALSE;
}
else
{
- unsigned int dst_addr_loc, dst_offset;
+ GLuint dst_addr_loc, dst_offset;
slang_assembly_type ty;
/* calculate the distance from top of the stack to the destination address */
dst_addr_loc = size - *index;
/* calculate the offset within destination variable to write */
- if (stk->swizzle.num_components != 0)
+ if (A->swz.num_components != 0)
{
/* swizzle the index to get the actual offset */
- dst_offset = stk->swizzle.swizzle[*index / 4] * 4;
+ dst_offset = A->swz.swizzle[*index / 4] * 4;
}
else
{
@@ -106,101 +105,93 @@ static int assign_aggregate (slang_assembly_file *file, const slang_storage_aggr
ty = slang_asm_float_copy;
break;
default:
- _mesa_problem(NULL, "Unexpected arr->type in assign_aggregate");
- ty = slang_asm_none;
break;
}
- if (!slang_assembly_file_push_label2 (file, ty, dst_addr_loc, dst_offset))
- return 0;
+ if (!slang_assembly_file_push_label2 (A->file, ty, dst_addr_loc, dst_offset))
+ return GL_FALSE;
+
*index += 4;
}
}
}
- return 1;
+
+ return GL_TRUE;
}
-int _slang_assemble_assignment (slang_assemble_ctx *A, slang_operation *op)
+GLboolean _slang_assemble_assignment (slang_assemble_ctx *A, slang_operation *op)
{
slang_assembly_typeinfo ti;
- int result;
+ GLboolean result = GL_FALSE;
slang_storage_aggregate agg;
- unsigned int index, size;
+ GLuint index, size;
if (!slang_assembly_typeinfo_construct (&ti))
- return 0;
+ return GL_FALSE;
if (!_slang_typeof_operation (op, &A->space, &ti, A->atoms))
- {
- slang_assembly_typeinfo_destruct (&ti);
- return 0;
- }
+ goto end1;
if (!slang_storage_aggregate_construct (&agg))
- {
- slang_assembly_typeinfo_destruct (&ti);
- return 0;
- }
+ goto end1;
if (!_slang_aggregate_variable (&agg, &ti.spec, NULL, A->space.funcs, A->space.structs,
A->space.vars, A->mach, A->file, A->atoms))
- {
- slang_storage_aggregate_destruct (&agg);
- slang_assembly_typeinfo_destruct (&ti);
- return 0;
- }
+ goto end;
index = 0;
size = _slang_sizeof_aggregate (&agg);
- result = assign_aggregate (A->file, &agg, &index, size, &A->local, &A->swz);
+ result = assign_aggregate (A, &agg, &index, size);
+end1:
slang_storage_aggregate_destruct (&agg);
+end:
slang_assembly_typeinfo_destruct (&ti);
return result;
}
/*
- _slang_assemble_assign()
-
- performs unary (pre ++ and --) or binary (=, +=, -=, *=, /=) assignment on the operation's
- children
-*/
+ * _slang_assemble_assign()
+ *
+ * Performs unary (pre ++ and --) or binary (=, +=, -=, *=, /=) assignment on the operation's
+ * children.
+ */
-int _slang_assemble_assign (slang_assemble_ctx *A, slang_operation *op, const char *oper,
+GLboolean _slang_assemble_assign (slang_assemble_ctx *A, slang_operation *op, const char *oper,
slang_ref_type ref)
{
- slang_assembly_stack_info stk;
+ slang_swizzle swz;
if (ref == slang_ref_forbid)
{
if (!slang_assembly_file_push_label2 (A->file, slang_asm_local_addr, A->local.addr_tmp, 4))
- return 0;
+ return GL_FALSE;
}
if (slang_string_compare ("=", oper) == 0)
{
if (!_slang_assemble_operation_ (A, &op->children[0], slang_ref_force))
- return 0;
- stk = A->swz;
+ return GL_FALSE;
+ swz = A->swz;
if (!_slang_assemble_operation_ (A, &op->children[1], slang_ref_forbid))
- return 0;
- A->swz = stk;
+ return GL_FALSE;
+ A->swz = swz;
if (!_slang_assemble_assignment (A, op->children))
- return 0;
+ return GL_FALSE;
}
else
{
if (!_slang_assemble_function_call_name (A, oper, op->children, op->num_children, GL_TRUE))
- return 0;
+ return GL_FALSE;
}
if (ref == slang_ref_forbid)
{
if (!slang_assembly_file_push (A->file, slang_asm_addr_copy))
- return 0;
+ return GL_FALSE;
if (!slang_assembly_file_push_label (A->file, slang_asm_local_free, 4))
- return 0;
- if (!_slang_dereference (A->file, op->children, &A->space, &A->local, A->mach, A->atoms))
- return 0;
+ return GL_FALSE;
+ if (!_slang_dereference (A, op->children))
+ return GL_FALSE;
}
- return 1;
+ return GL_TRUE;
}
diff --git a/src/mesa/shader/slang/slang_assemble_assignment.h b/src/mesa/shader/slang/slang_assemble_assignment.h
index dfec8b0138f..ef05ebd71d4 100644
--- a/src/mesa/shader/slang/slang_assemble_assignment.h
+++ b/src/mesa/shader/slang/slang_assemble_assignment.h
@@ -31,9 +31,10 @@
extern "C" {
#endif
-int _slang_assemble_assignment (slang_assemble_ctx *, slang_operation *);
+GLboolean _slang_assemble_assignment (slang_assemble_ctx *, slang_operation *);
-int _slang_assemble_assign (slang_assemble_ctx *, slang_operation *, const char *, slang_ref_type);
+GLboolean _slang_assemble_assign (slang_assemble_ctx *, slang_operation *, const char *,
+ slang_ref_type);
#ifdef __cplusplus
}
diff --git a/src/mesa/shader/slang/slang_assemble_conditional.c b/src/mesa/shader/slang/slang_assemble_conditional.c
index 74324cfe6c2..067a5bf9417 100644
--- a/src/mesa/shader/slang/slang_assemble_conditional.c
+++ b/src/mesa/shader/slang/slang_assemble_conditional.c
@@ -34,453 +34,417 @@
#include "slang_assemble.h"
#include "slang_execute.h"
-/* _slang_assemble_logicaland() */
+/*
+ * _slang_assemble_logicaland()
+ *
+ * and:
+ * <left-expression>
+ * jumpz zero
+ * <right-expression>
+ * jump end
+ * zero:
+ * push 0
+ * end:
+ */
-int _slang_assemble_logicaland (slang_assembly_file *file, slang_operation *op,
- slang_assembly_flow_control *flow, slang_assembly_name_space *space,
- slang_assembly_local_info *info, slang_machine *mach, slang_atom_pool *atoms)
+GLboolean _slang_assemble_logicaland (slang_assemble_ctx *A, slang_operation *op)
{
- /*
- and:
- <left-expression>
- jumpz zero
- <right-expression>
- jump end
- zero:
- push 0
- end:
- */
-
- unsigned int zero_jump, end_jump;
- slang_assembly_stack_info stk;
+ GLuint zero_jump, end_jump;
/* evaluate left expression */
- if (!_slang_assemble_operation (file, &op->children[0], 0, flow, space, info, &stk, mach, atoms))
- return 0;
- /* TODO: inspect stk */
+ if (!_slang_assemble_operation_ (A, &op->children[0], slang_ref_forbid))
+ return GL_FALSE;
/* jump to pushing 0 if not true */
- zero_jump = file->count;
- if (!slang_assembly_file_push (file, slang_asm_jump_if_zero))
- return 0;
+ zero_jump = A->file->count;
+ if (!slang_assembly_file_push (A->file, slang_asm_jump_if_zero))
+ return GL_FALSE;
/* evaluate right expression */
- if (!_slang_assemble_operation (file, &op->children[1], 0, flow, space, info, &stk, mach, atoms))
- return 0;
- /* TODO: inspect stk */
+ if (!_slang_assemble_operation_ (A, &op->children[1], slang_ref_forbid))
+ return GL_FALSE;
/* jump to the end of the expression */
- end_jump = file->count;
- if (!slang_assembly_file_push (file, slang_asm_jump))
- return 0;
+ end_jump = A->file->count;
+ if (!slang_assembly_file_push (A->file, slang_asm_jump))
+ return GL_FALSE;
/* push 0 on stack */
- file->code[zero_jump].param[0] = file->count;
- if (!slang_assembly_file_push_literal (file, slang_asm_bool_push, (GLfloat) 0))
- return 0;
+ A->file->code[zero_jump].param[0] = A->file->count;
+ if (!slang_assembly_file_push_literal (A->file, slang_asm_bool_push, (GLfloat) 0))
+ return GL_FALSE;
/* the end of the expression */
- file->code[end_jump].param[0] = file->count;
+ A->file->code[end_jump].param[0] = A->file->count;
- return 1;
+ return GL_TRUE;
}
-/* _slang_assemble_logicalor() */
+/*
+ * _slang_assemble_logicalor()
+ *
+ * or:
+ * <left-expression>
+ * jumpz right
+ * push 1
+ * jump end
+ * right:
+ * <right-expression>
+ * end:
+ */
-int _slang_assemble_logicalor (slang_assembly_file *file, slang_operation *op,
- slang_assembly_flow_control *flow, slang_assembly_name_space *space,
- slang_assembly_local_info *info, slang_machine *mach, slang_atom_pool *atoms)
+GLboolean _slang_assemble_logicalor (slang_assemble_ctx *A, slang_operation *op)
{
- /*
- or:
- <left-expression>
- jumpz right
- push 1
- jump end
- right:
- <right-expression>
- end:
- */
-
- unsigned int right_jump, end_jump;
- slang_assembly_stack_info stk;
+ GLuint right_jump, end_jump;
/* evaluate left expression */
- if (!_slang_assemble_operation (file, &op->children[0], 0, flow, space, info, &stk, mach, atoms))
- return 0;
- /* TODO: inspect stk */
+ if (!_slang_assemble_operation_ (A, &op->children[0], slang_ref_forbid))
+ return GL_FALSE;
/* jump to evaluation of right expression if not true */
- right_jump = file->count;
- if (!slang_assembly_file_push (file, slang_asm_jump_if_zero))
- return 0;
+ right_jump = A->file->count;
+ if (!slang_assembly_file_push (A->file, slang_asm_jump_if_zero))
+ return GL_FALSE;
/* push 1 on stack */
- if (!slang_assembly_file_push_literal (file, slang_asm_bool_push, (GLfloat) 1))
- return 0;
+ if (!slang_assembly_file_push_literal (A->file, slang_asm_bool_push, (GLfloat) 1))
+ return GL_FALSE;
/* jump to the end of the expression */
- end_jump = file->count;
- if (!slang_assembly_file_push (file, slang_asm_jump))
- return 0;
+ end_jump = A->file->count;
+ if (!slang_assembly_file_push (A->file, slang_asm_jump))
+ return GL_FALSE;
/* evaluate right expression */
- file->code[right_jump].param[0] = file->count;
- if (!_slang_assemble_operation (file, &op->children[1], 0, flow, space, info, &stk, mach, atoms))
- return 0;
- /* TODO: inspect stk */
+ A->file->code[right_jump].param[0] = A->file->count;
+ if (!_slang_assemble_operation_ (A, &op->children[1], slang_ref_forbid))
+ return GL_FALSE;
/* the end of the expression */
- file->code[end_jump].param[0] = file->count;
+ A->file->code[end_jump].param[0] = A->file->count;
- return 1;
+ return GL_TRUE;
}
-/* _slang_assemble_select() */
+/*
+ * _slang_assemble_select()
+ *
+ * select:
+ * <condition-expression>
+ * jumpz false
+ * <true-expression>
+ * jump end
+ * false:
+ * <false-expression>
+ * end:
+ */
-int _slang_assemble_select (slang_assembly_file *file, slang_operation *op,
- slang_assembly_flow_control *flow, slang_assembly_name_space *space,
- slang_assembly_local_info *info, slang_machine *mach, slang_atom_pool *atoms)
+GLboolean _slang_assemble_select (slang_assemble_ctx *A, slang_operation *op)
{
- /*
- select:
- <condition-expression>
- jumpz false
- <true-expression>
- jump end
- false:
- <false-expression>
- end:
- */
-
- unsigned int cond_jump, end_jump;
- slang_assembly_stack_info stk;
+ GLuint cond_jump, end_jump;
/* execute condition expression */
- if (!_slang_assemble_operation (file, &op->children[0], 0, flow, space, info, &stk, mach, atoms))
- return 0;
- /* TODO: inspect stk */
+ if (!_slang_assemble_operation_ (A, &op->children[0], slang_ref_forbid))
+ return GL_FALSE;
/* jump to false expression if not true */
- cond_jump = file->count;
- if (!slang_assembly_file_push (file, slang_asm_jump_if_zero))
- return 0;
+ cond_jump = A->file->count;
+ if (!slang_assembly_file_push (A->file, slang_asm_jump_if_zero))
+ return GL_FALSE;
/* execute true expression */
- if (!_slang_assemble_operation (file, &op->children[1], 0, flow, space, info, &stk, mach, atoms))
- return 0;
- /* TODO: inspect stk */
+ if (!_slang_assemble_operation_ (A, &op->children[1], slang_ref_forbid))
+ return GL_FALSE;
/* jump to the end of the expression */
- end_jump = file->count;
- if (!slang_assembly_file_push (file, slang_asm_jump))
- return 0;
+ end_jump = A->file->count;
+ if (!slang_assembly_file_push (A->file, slang_asm_jump))
+ return GL_FALSE;
/* resolve false point */
- file->code[cond_jump].param[0] = file->count;
+ A->file->code[cond_jump].param[0] = A->file->count;
/* execute false expression */
- if (!_slang_assemble_operation (file, &op->children[2], 0, flow, space, info, &stk, mach, atoms))
- return 0;
- /* TODO: inspect stk */
+ if (!_slang_assemble_operation_ (A, &op->children[2], slang_ref_forbid))
+ return GL_FALSE;
/* resolve the end of the expression */
- file->code[end_jump].param[0] = file->count;
+ A->file->code[end_jump].param[0] = A->file->count;
- return 1;
+ return GL_TRUE;
}
-/* _slang_assemble_for() */
+/*
+ * _slang_assemble_for()
+ *
+ * for:
+ * <init-statement>
+ * jump start
+ * break:
+ * jump end
+ * continue:
+ * <loop-increment>
+ * start:
+ * <condition-statement>
+ * jumpz end
+ * <loop-body>
+ * jump continue
+ * end:
+ */
-int _slang_assemble_for (slang_assembly_file *file, slang_operation *op,
- slang_assembly_flow_control *flow, slang_assembly_name_space *space,
- slang_assembly_local_info *info, slang_machine *mach, slang_atom_pool *atoms)
+GLboolean _slang_assemble_for (slang_assemble_ctx *A, slang_operation *op)
{
- /*
- for:
- <init-statement>
- jump start
- break:
- jump end
- continue:
- <loop-increment>
- start:
- <condition-statement>
- jumpz end
- <loop-body>
- jump continue
- end:
- */
-
- unsigned int start_jump, end_jump, cond_jump;
- unsigned int break_label, cont_label;
- slang_assembly_flow_control loop_flow = *flow;
- slang_assembly_stack_info stk;
+ GLuint start_jump, end_jump, cond_jump;
+ GLuint break_label, cont_label;
+ slang_assembly_flow_control save_flow = A->flow;
/* execute initialization statement */
- if (!_slang_assemble_operation (file, &op->children[0], 0, flow, space, info, &stk, mach, atoms))
- return 0;
- /* TODO: pass-in stk to cleanup */
- if (!_slang_cleanup_stack (file, &op->children[0], 0, space, mach, atoms))
- return 0;
+ if (!_slang_assemble_operation_ (A, &op->children[0], slang_ref_forbid/*slang_ref_freelance*/))
+ return GL_FALSE;
+ if (!_slang_cleanup_stack_ (A, &op->children[0]))
+ return GL_FALSE;
/* skip the "go to the end of the loop" and loop-increment statements */
- start_jump = file->count;
- if (!slang_assembly_file_push (file, slang_asm_jump))
- return 0;
+ start_jump = A->file->count;
+ if (!slang_assembly_file_push (A->file, slang_asm_jump))
+ return GL_FALSE;
/* go to the end of the loop - break statements are directed here */
- break_label = file->count;
- end_jump = file->count;
- if (!slang_assembly_file_push (file, slang_asm_jump))
- return 0;
+ break_label = A->file->count;
+ end_jump = A->file->count;
+ if (!slang_assembly_file_push (A->file, slang_asm_jump))
+ return GL_FALSE;
/* resolve the beginning of the loop - continue statements are directed here */
- cont_label = file->count;
+ cont_label = A->file->count;
/* execute loop-increment statement */
- if (!_slang_assemble_operation (file, &op->children[2], 0, flow, space, info, &stk, mach, atoms))
- return 0;
- /* TODO: pass-in stk to cleanup */
- if (!_slang_cleanup_stack (file, &op->children[2], 0, space, mach, atoms))
- return 0;
+ if (!_slang_assemble_operation_ (A, &op->children[2], slang_ref_forbid/*slang_ref_freelance*/))
+ return GL_FALSE;
+ if (!_slang_cleanup_stack_ (A, &op->children[2]))
+ return GL_FALSE;
/* resolve the condition point */
- file->code[start_jump].param[0] = file->count;
+ A->file->code[start_jump].param[0] = A->file->count;
/* execute condition statement */
- if (!_slang_assemble_operation (file, &op->children[1], 0, flow, space, info, &stk, mach, atoms))
- return 0;
- /* TODO: inspect stk */
+ if (!_slang_assemble_operation_ (A, &op->children[1], slang_ref_forbid))
+ return GL_FALSE;
/* jump to the end of the loop if not true */
- cond_jump = file->count;
- if (!slang_assembly_file_push (file, slang_asm_jump_if_zero))
- return 0;
+ cond_jump = A->file->count;
+ if (!slang_assembly_file_push (A->file, slang_asm_jump_if_zero))
+ return GL_FALSE;
/* execute loop body */
- loop_flow.loop_start = cont_label;
- loop_flow.loop_end = break_label;
- if (!_slang_assemble_operation (file, &op->children[3], 0, &loop_flow, space, info, &stk, mach, atoms))
- return 0;
- /* TODO: pass-in stk to cleanup */
- if (!_slang_cleanup_stack (file, &op->children[3], 0, space, mach, atoms))
- return 0;
+ A->flow.loop_start = cont_label;
+ A->flow.loop_end = break_label;
+ if (!_slang_assemble_operation_ (A, &op->children[3], slang_ref_forbid/*slang_ref_freelance*/))
+ return GL_FALSE;
+ if (!_slang_cleanup_stack_ (A, &op->children[3]))
+ return GL_FALSE;
+ A->flow = save_flow;
/* go to the beginning of the loop */
- if (!slang_assembly_file_push_label (file, slang_asm_jump, cont_label))
- return 0;
+ if (!slang_assembly_file_push_label (A->file, slang_asm_jump, cont_label))
+ return GL_FALSE;
/* resolve the end of the loop */
- file->code[end_jump].param[0] = file->count;
- file->code[cond_jump].param[0] = file->count;
+ A->file->code[end_jump].param[0] = A->file->count;
+ A->file->code[cond_jump].param[0] = A->file->count;
- return 1;
+ return GL_TRUE;
}
-/* _slang_assemble_do() */
+/*
+ * _slang_assemble_do()
+ *
+ * do:
+ * jump start
+ * break:
+ * jump end
+ * continue:
+ * jump condition
+ * start:
+ * <loop-body>
+ * condition:
+ * <condition-statement>
+ * jumpz end
+ * jump start
+ * end:
+ */
-int _slang_assemble_do (slang_assembly_file *file, slang_operation *op,
- slang_assembly_flow_control *flow, slang_assembly_name_space *space,
- slang_assembly_local_info *info, slang_machine *mach, slang_atom_pool *atoms)
+GLboolean _slang_assemble_do (slang_assemble_ctx *A, slang_operation *op)
{
- /*
- do:
- jump start
- break:
- jump end
- continue:
- jump condition
- start:
- <loop-body>
- condition:
- <condition-statement>
- jumpz end
- jump start
- end:
- */
-
- unsigned int skip_jump, end_jump, cont_jump, cond_jump;
- unsigned int break_label, cont_label;
- slang_assembly_flow_control loop_flow = *flow;
- slang_assembly_stack_info stk;
+ GLuint skip_jump, end_jump, cont_jump, cond_jump;
+ GLuint break_label, cont_label;
+ slang_assembly_flow_control save_flow = A->flow;
/* skip the "go to the end of the loop" and "go to condition" statements */
- skip_jump = file->count;
- if (!slang_assembly_file_push (file, slang_asm_jump))
- return 0;
+ skip_jump = A->file->count;
+ if (!slang_assembly_file_push (A->file, slang_asm_jump))
+ return GL_FALSE;
/* go to the end of the loop - break statements are directed here */
- break_label = file->count;
- end_jump = file->count;
- if (!slang_assembly_file_push (file, slang_asm_jump))
- return 0;
+ break_label = A->file->count;
+ end_jump = A->file->count;
+ if (!slang_assembly_file_push (A->file, slang_asm_jump))
+ return GL_FALSE;
/* go to condition - continue statements are directed here */
- cont_label = file->count;
- cont_jump = file->count;
- if (!slang_assembly_file_push (file, slang_asm_jump))
- return 0;
+ cont_label = A->file->count;
+ cont_jump = A->file->count;
+ if (!slang_assembly_file_push (A->file, slang_asm_jump))
+ return GL_FALSE;
/* resolve the beginning of the loop */
- file->code[skip_jump].param[0] = file->count;
+ A->file->code[skip_jump].param[0] = A->file->count;
/* execute loop body */
- loop_flow.loop_start = cont_label;
- loop_flow.loop_end = break_label;
- if (!_slang_assemble_operation (file, &op->children[0], 0, &loop_flow, space, info, &stk, mach, atoms))
- return 0;
- /* TODO: pass-in stk to cleanup */
- if (!_slang_cleanup_stack (file, &op->children[0], 0, space, mach, atoms))
- return 0;
+ A->flow.loop_start = cont_label;
+ A->flow.loop_end = break_label;
+ if (!_slang_assemble_operation_ (A, &op->children[0], slang_ref_forbid/*slang_ref_freelance*/))
+ return GL_FALSE;
+ if (!_slang_cleanup_stack_ (A, &op->children[0]))
+ return GL_FALSE;
+ A->flow = save_flow;
/* resolve condition point */
- file->code[cont_jump].param[0] = file->count;
+ A->file->code[cont_jump].param[0] = A->file->count;
/* execute condition statement */
- if (!_slang_assemble_operation (file, &op->children[1], 0, flow, space, info, &stk, mach, atoms))
- return 0;
- /* TODO: pass-in stk to cleanup */
+ if (!_slang_assemble_operation_ (A, &op->children[1], slang_ref_forbid))
+ return GL_FALSE;
/* jump to the end of the loop if not true */
- cond_jump = file->count;
- if (!slang_assembly_file_push (file, slang_asm_jump_if_zero))
- return 0;
+ cond_jump = A->file->count;
+ if (!slang_assembly_file_push (A->file, slang_asm_jump_if_zero))
+ return GL_FALSE;
/* jump to the beginning of the loop */
- if (!slang_assembly_file_push_label (file, slang_asm_jump, file->code[skip_jump].param[0]))
- return 0;
+ if (!slang_assembly_file_push_label (A->file, slang_asm_jump, A->file->code[skip_jump].param[0]))
+ return GL_FALSE;
/* resolve the end of the loop */
- file->code[end_jump].param[0] = file->count;
- file->code[cond_jump].param[0] = file->count;
+ A->file->code[end_jump].param[0] = A->file->count;
+ A->file->code[cond_jump].param[0] = A->file->count;
- return 1;
+ return GL_TRUE;
}
-/* _slang_assemble_while() */
+/*
+ * _slang_assemble_while()
+ *
+ * while:
+ * jump continue
+ * break:
+ * jump end
+ * continue:
+ * <condition-statement>
+ * jumpz end
+ * <loop-body>
+ * jump continue
+ * end:
+ */
-int _slang_assemble_while (slang_assembly_file *file, slang_operation *op,
- slang_assembly_flow_control *flow, slang_assembly_name_space *space,
- slang_assembly_local_info *info, slang_machine *mach, slang_atom_pool *atoms)
+GLboolean _slang_assemble_while (slang_assemble_ctx *A, slang_operation *op)
{
- /*
- while:
- jump continue
- break:
- jump end
- continue:
- <condition-statement>
- jumpz end
- <loop-body>
- jump continue
- end:
- */
-
- unsigned int skip_jump, end_jump, cond_jump;
- unsigned int break_label;
- slang_assembly_flow_control loop_flow = *flow;
- slang_assembly_stack_info stk;
+ GLuint skip_jump, end_jump, cond_jump;
+ GLuint break_label;
+ slang_assembly_flow_control save_flow = A->flow;
/* skip the "go to the end of the loop" statement */
- skip_jump = file->count;
- if (!slang_assembly_file_push (file, slang_asm_jump))
- return 0;
+ skip_jump = A->file->count;
+ if (!slang_assembly_file_push (A->file, slang_asm_jump))
+ return GL_FALSE;
/* go to the end of the loop - break statements are directed here */
- break_label = file->count;
- end_jump = file->count;
- if (!slang_assembly_file_push (file, slang_asm_jump))
- return 0;
+ break_label = A->file->count;
+ end_jump = A->file->count;
+ if (!slang_assembly_file_push (A->file, slang_asm_jump))
+ return GL_FALSE;
/* resolve the beginning of the loop - continue statements are directed here */
- file->code[skip_jump].param[0] = file->count;
+ A->file->code[skip_jump].param[0] = A->file->count;
/* execute condition statement */
- if (!_slang_assemble_operation (file, &op->children[0], 0, flow, space, info, &stk, mach, atoms))
- return 0;
- /* TODO: pass-in stk to cleanup */
+ if (!_slang_assemble_operation_ (A, &op->children[0], slang_ref_forbid))
+ return GL_FALSE;
/* jump to the end of the loop if not true */
- cond_jump = file->count;
- if (!slang_assembly_file_push (file, slang_asm_jump_if_zero))
- return 0;
+ cond_jump = A->file->count;
+ if (!slang_assembly_file_push (A->file, slang_asm_jump_if_zero))
+ return GL_FALSE;
/* execute loop body */
- loop_flow.loop_start = file->code[skip_jump].param[0];
- loop_flow.loop_end = break_label;
- if (!_slang_assemble_operation (file, &op->children[1], 0, &loop_flow, space, info, &stk, mach, atoms))
- return 0;
- /* TODO: pass-in stk to cleanup */
- if (!_slang_cleanup_stack (file, &op->children[1], 0, space, mach, atoms))
- return 0;
+ A->flow.loop_start = A->file->code[skip_jump].param[0];
+ A->flow.loop_end = break_label;
+ if (!_slang_assemble_operation_ (A, &op->children[1], slang_ref_forbid/*slang_ref_freelance*/))
+ return GL_FALSE;
+ if (!_slang_cleanup_stack_ (A, &op->children[1]))
+ return GL_FALSE;
+ A->flow = save_flow;
/* jump to the beginning of the loop */
- if (!slang_assembly_file_push_label (file, slang_asm_jump, file->code[skip_jump].param[0]))
- return 0;
+ if (!slang_assembly_file_push_label (A->file, slang_asm_jump, A->file->code[skip_jump].param[0]))
+ return GL_FALSE;
/* resolve the end of the loop */
- file->code[end_jump].param[0] = file->count;
- file->code[cond_jump].param[0] = file->count;
+ A->file->code[end_jump].param[0] = A->file->count;
+ A->file->code[cond_jump].param[0] = A->file->count;
- return 1;
+ return GL_TRUE;
}
-/* _slang_assemble_if() */
+/*
+ * _slang_assemble_if()
+ *
+ * if:
+ * <condition-statement>
+ * jumpz else
+ * <true-statement>
+ * jump end
+ * else:
+ * <false-statement>
+ * end:
+ */
-int _slang_assemble_if (slang_assembly_file *file, slang_operation *op,
- slang_assembly_flow_control *flow, slang_assembly_name_space *space,
- slang_assembly_local_info *info, slang_machine *mach, slang_atom_pool *atoms)
+GLboolean _slang_assemble_if (slang_assemble_ctx *A, slang_operation *op)
{
- /*
- if:
- <condition-statement>
- jumpz else
- <true-statement>
- jump end
- else:
- <false-statement>
- end:
- */
-
- unsigned int cond_jump, else_jump;
- slang_assembly_stack_info stk;
+ GLuint cond_jump, else_jump;
/* execute condition statement */
- if (!_slang_assemble_operation (file, &op->children[0], 0, flow, space, info, &stk, mach, atoms))
- return 0;
- /* TODO: pass-in stk to cleanup */
+ if (!_slang_assemble_operation_ (A, &op->children[0], slang_ref_forbid))
+ return GL_FALSE;
/* jump to false-statement if not true */
- cond_jump = file->count;
- if (!slang_assembly_file_push (file, slang_asm_jump_if_zero))
- return 0;
+ cond_jump = A->file->count;
+ if (!slang_assembly_file_push (A->file, slang_asm_jump_if_zero))
+ return GL_FALSE;
/* execute true-statement */
- if (!_slang_assemble_operation (file, &op->children[1], 0, flow, space, info, &stk, mach, atoms))
- return 0;
- /* TODO: pass-in stk to cleanup */
- if (!_slang_cleanup_stack (file, &op->children[1], 0, space, mach, atoms))
- return 0;
+ if (!_slang_assemble_operation_ (A, &op->children[1], slang_ref_forbid/*slang_ref_freelance*/))
+ return GL_FALSE;
+ if (!_slang_cleanup_stack_ (A, &op->children[1]))
+ return GL_FALSE;
/* skip if-false statement */
- else_jump = file->count;
- if (!slang_assembly_file_push (file, slang_asm_jump))
- return 0;
+ else_jump = A->file->count;
+ if (!slang_assembly_file_push (A->file, slang_asm_jump))
+ return GL_FALSE;
/* resolve start of false-statement */
- file->code[cond_jump].param[0] = file->count;
+ A->file->code[cond_jump].param[0] = A->file->count;
/* execute false-statement */
- if (!_slang_assemble_operation (file, &op->children[2], 0, flow, space, info, &stk, mach, atoms))
- return 0;
- /* TODO: pass-in stk to cleanup */
- if (!_slang_cleanup_stack (file, &op->children[2], 0, space, mach, atoms))
- return 0;
+ if (!_slang_assemble_operation_ (A, &op->children[2], slang_ref_forbid/*slang_ref_freelance*/))
+ return GL_FALSE;
+ if (!_slang_cleanup_stack_ (A, &op->children[2]))
+ return GL_FALSE;
/* resolve end of if-false statement */
- file->code[else_jump].param[0] = file->count;
+ A->file->code[else_jump].param[0] = A->file->count;
- return 1;
+ return GL_TRUE;
}
diff --git a/src/mesa/shader/slang/slang_assemble_conditional.h b/src/mesa/shader/slang/slang_assemble_conditional.h
index f5aa0d48261..9ea1ed265ea 100644
--- a/src/mesa/shader/slang/slang_assemble_conditional.h
+++ b/src/mesa/shader/slang/slang_assemble_conditional.h
@@ -31,33 +31,19 @@
extern "C" {
#endif
-int _slang_assemble_logicaland (slang_assembly_file *file, slang_operation *op,
- slang_assembly_flow_control *flow, slang_assembly_name_space *space,
- slang_assembly_local_info *info, struct slang_machine_ *, slang_atom_pool *);
+GLboolean _slang_assemble_logicaland (slang_assemble_ctx *, slang_operation *);
-int _slang_assemble_logicalor (slang_assembly_file *file, slang_operation *op,
- slang_assembly_flow_control *flow, slang_assembly_name_space *space,
- slang_assembly_local_info *info, struct slang_machine_ *, slang_atom_pool *);
+GLboolean _slang_assemble_logicalor (slang_assemble_ctx *, slang_operation *);
-int _slang_assemble_select (slang_assembly_file *file, slang_operation *op,
- slang_assembly_flow_control *flow, slang_assembly_name_space *space,
- slang_assembly_local_info *info, struct slang_machine_ *, slang_atom_pool *);
+GLboolean _slang_assemble_select (slang_assemble_ctx *, slang_operation *);
-int _slang_assemble_for (slang_assembly_file *file, slang_operation *op,
- slang_assembly_flow_control *flow, slang_assembly_name_space *space,
- slang_assembly_local_info *info, struct slang_machine_ *, slang_atom_pool *);
+GLboolean _slang_assemble_for (slang_assemble_ctx *, slang_operation *);
-int _slang_assemble_do (slang_assembly_file *file, slang_operation *op,
- slang_assembly_flow_control *flow, slang_assembly_name_space *space,
- slang_assembly_local_info *info, struct slang_machine_ *, slang_atom_pool *);
+GLboolean _slang_assemble_do (slang_assemble_ctx *, slang_operation *);
-int _slang_assemble_while (slang_assembly_file *file, slang_operation *op,
- slang_assembly_flow_control *flow, slang_assembly_name_space *space,
- slang_assembly_local_info *info, struct slang_machine_ *, slang_atom_pool *);
+GLboolean _slang_assemble_while (slang_assemble_ctx *, slang_operation *);
-int _slang_assemble_if (slang_assembly_file *file, slang_operation *op,
- slang_assembly_flow_control *flow, slang_assembly_name_space *space,
- slang_assembly_local_info *info, struct slang_machine_ *, slang_atom_pool *);
+GLboolean _slang_assemble_if (slang_assemble_ctx *, slang_operation *);
#ifdef __cplusplus
}
diff --git a/src/mesa/shader/slang/slang_assemble_constructor.c b/src/mesa/shader/slang/slang_assemble_constructor.c
index 8d910f3c749..d7d2e422d31 100644
--- a/src/mesa/shader/slang/slang_assemble_constructor.c
+++ b/src/mesa/shader/slang/slang_assemble_constructor.c
@@ -36,15 +36,15 @@
/* _slang_is_swizzle() */
-int _slang_is_swizzle (const char *field, unsigned int rows, slang_swizzle *swz)
+GLboolean _slang_is_swizzle (const char *field, GLuint rows, slang_swizzle *swz)
{
- unsigned int i;
- int xyzw = 0, rgba = 0, stpq = 0;
+ GLuint i;
+ GLboolean xyzw = GL_FALSE, rgba = GL_FALSE, stpq = GL_FALSE;
/* the swizzle can be at most 4-component long */
swz->num_components = slang_string_length (field);
if (swz->num_components > 4)
- return 0;
+ return GL_FALSE;
for (i = 0; i < swz->num_components; i++)
{
@@ -55,22 +55,22 @@ int _slang_is_swizzle (const char *field, unsigned int rows, slang_swizzle *swz)
case 'y':
case 'z':
case 'w':
- xyzw = 1;
+ xyzw = GL_TRUE;
break;
case 'r':
case 'g':
case 'b':
case 'a':
- rgba = 1;
+ rgba = GL_TRUE;
break;
case 's':
case 't':
case 'p':
case 'q':
- stpq = 1;
+ stpq = GL_TRUE;
break;
default:
- return 0;
+ return GL_FALSE;
}
/* collect swizzle component */
@@ -100,42 +100,43 @@ int _slang_is_swizzle (const char *field, unsigned int rows, slang_swizzle *swz)
/* check if the component is valid for given vector's row count */
if (rows <= swz->swizzle[i])
- return 0;
+ return GL_FALSE;
}
/* only one swizzle group can be used */
if ((xyzw && rgba) || (xyzw && stpq) || (rgba && stpq))
- return 0;
+ return GL_FALSE;
- return 1;
+ return GL_TRUE;
}
/* _slang_is_swizzle_mask() */
-int _slang_is_swizzle_mask (const slang_swizzle *swz, unsigned int rows)
+GLboolean _slang_is_swizzle_mask (const slang_swizzle *swz, GLuint rows)
{
- unsigned int i, c = 0;
+ GLuint i, c = 0;
/* the swizzle may not be longer than the vector dim */
if (swz->num_components > rows)
- return 0;
+ return GL_FALSE;
/* the swizzle components cannot be duplicated */
for (i = 0; i < swz->num_components; i++)
{
if ((c & (1 << swz->swizzle[i])) != 0)
- return 0;
+ return GL_FALSE;
c |= 1 << swz->swizzle[i];
}
- return 1;
+
+ return GL_TRUE;
}
/* _slang_multiply_swizzles() */
-void _slang_multiply_swizzles (slang_swizzle *dst, const slang_swizzle *left,
+GLvoid _slang_multiply_swizzles (slang_swizzle *dst, const slang_swizzle *left,
const slang_swizzle *right)
{
- unsigned int i;
+ GLuint i;
dst->num_components = right->num_components;
for (i = 0; i < right->num_components; i++)
@@ -143,37 +144,38 @@ void _slang_multiply_swizzles (slang_swizzle *dst, const slang_swizzle *left,
}
/* _slang_assemble_constructor() */
-#if 0
-static int constructor_aggregate (slang_assembly_file *file, const slang_storage_aggregate *flat,
- unsigned int *index, slang_operation *op, unsigned int size, slang_assembly_flow_control *flow,
- slang_assembly_name_space *space, slang_assembly_local_info *info)
+
+static GLboolean constructor_aggregate (slang_assemble_ctx *A, const slang_storage_aggregate *flat,
+ GLuint *index, slang_operation *op, GLuint size)
{
slang_assembly_typeinfo ti;
- int result;
+ GLboolean result = GL_FALSE;
slang_storage_aggregate agg, flat_agg;
- slang_assembly_stack_info stk;
- unsigned int i;
+ GLuint i;
- slang_assembly_typeinfo_construct (&ti);
- if (!(result = _slang_typeof_operation (op, space, &ti)))
+ if (!slang_assembly_typeinfo_construct (&ti))
+ return GL_FALSE;
+ if (!_slang_typeof_operation (op, &A->space, &ti, A->atoms))
goto end1;
- slang_storage_aggregate_construct (&agg);
- if (!(result = _slang_aggregate_variable (&agg, &ti.spec, NULL, space->funcs, space->structs,
- space->vars)))
+ if (!slang_storage_aggregate_construct (&agg))
+ goto end1;
+ if (!_slang_aggregate_variable (&agg, &ti.spec, NULL, A->space.funcs, A->space.structs,
+ A->space.vars, A->mach, A->file, A->atoms))
goto end2;
- slang_storage_aggregate_construct (&flat_agg);
- if (!(result = _slang_flatten_aggregate (&flat_agg, &agg)))
+ if (!slang_storage_aggregate_construct (&flat_agg))
+ goto end2;
+ if (!_slang_flatten_aggregate (&flat_agg, &agg))
goto end;
- if (!(result = _slang_assemble_operation (file, op, 0, flow, space, info, &stk)))
+ if (!_slang_assemble_operation_ (A, op, slang_ref_forbid))
goto end;
for (i = 0; i < flat_agg.count; i++)
{
- const slang_storage_array *arr1 = flat_agg.arrays + i;
- const slang_storage_array *arr2 = flat->arrays + *index;
+ const slang_storage_array *arr1 = &flat_agg.arrays[i];
+ const slang_storage_array *arr2 = &flat->arrays[*index];
if (arr1->type != arr2->type)
{
@@ -183,7 +185,7 @@ static int constructor_aggregate (slang_assembly_file *file, const slang_storage
/* TODO: watch the index, if it reaches the size, pop off the stack subsequent values */
}
- result = 1;
+ result = GL_TRUE;
end:
slang_storage_aggregate_destruct (&flat_agg);
end2:
@@ -192,48 +194,49 @@ end1:
slang_assembly_typeinfo_destruct (&ti);
return result;
}
-#endif
-
-/* XXX: general swizzle! */
-#if 0
-int _slang_assemble_constructor (slang_assembly_file *file, slang_operation *op,
- slang_assembly_flow_control *flow, slang_assembly_name_space *space,
- slang_assembly_local_info *info, struct slang_machine_ *pmach)
+GLboolean _slang_assemble_constructor (slang_assemble_ctx *A, slang_operation *op)
{
slang_assembly_typeinfo ti;
- int result;
+ GLboolean result = GL_FALSE;
slang_storage_aggregate agg, flat;
- unsigned int size, index, i;
+ GLuint size, index, i;
+ /* get typeinfo of the constructor (the result of constructor expression) */
if (!slang_assembly_typeinfo_construct (&ti))
- return 0;
- if (!(result = _slang_typeof_operation (op, space, &ti)))
+ return GL_FALSE;
+ if (!_slang_typeof_operation (op, &A->space, &ti, A->atoms))
goto end1;
- if (!(result = slang_storage_aggregate_construct (&agg)))
+ /* create an aggregate of the constructor */
+ if (!slang_storage_aggregate_construct (&agg))
goto end1;
- if (!(result = _slang_aggregate_variable (&agg, &ti.spec, NULL, space->funcs, space->structs,
- space->vars, pmach, file)))
+ if (!_slang_aggregate_variable (&agg, &ti.spec, NULL, A->space.funcs, A->space.structs,
+ A->space.vars, A->mach, A->file, A->atoms))
goto end2;
+ /* calculate size of the constructor */
size = _slang_sizeof_aggregate (&agg);
- if (!(result = slang_storage_aggregate_construct (&flat)))
+ /* flatten the constructor */
+ if (!slang_storage_aggregate_construct (&flat))
goto end2;
- if (!(result = _slang_flatten_aggregate (&flat, &agg)))
+ if (!_slang_flatten_aggregate (&flat, &agg))
goto end;
+ /* XXX: The children operations are traversed in a reversed order, so it poses a
+ * problem when there is more data than the constructor needs. We must fix it! */
+
+ /* traverse the children that form the constructor expression */
index = 0;
- for (i = 0; i < op->num_children; i++)
+ for (i = op->num_children; i > 0; i--)
{
- if (!(result = constructor_aggregate (file, &flat, &index, op->children + i, size, flow,
- space, info)))
+ if (!constructor_aggregate (A, &flat, &index, &op->children[i - 1], size))
goto end;
/* TODO: watch the index, if it reaches the size, raise an error */
}
- result = 1;
+ result = GL_TRUE;
end:
slang_storage_aggregate_destruct (&flat);
end2:
@@ -242,14 +245,13 @@ end1:
slang_assembly_typeinfo_destruct (&ti);
return result;
}
-#endif
/* _slang_assemble_constructor_from_swizzle() */
-int _slang_assemble_constructor_from_swizzle (slang_assembly_file *file, const slang_swizzle *swz,
- slang_type_specifier *spec, slang_type_specifier *master_spec, slang_assembly_local_info *info)
+GLboolean _slang_assemble_constructor_from_swizzle (slang_assemble_ctx *A, const slang_swizzle *swz,
+ slang_type_specifier *spec, slang_type_specifier *master_spec)
{
- unsigned int master_rows, i;
+ GLuint master_rows, i;
master_rows = _slang_type_dim (master_spec->type);
for (i = 0; i < master_rows; i++)
@@ -257,54 +259,55 @@ int _slang_assemble_constructor_from_swizzle (slang_assembly_file *file, const s
switch (_slang_type_base (master_spec->type))
{
case slang_spec_bool:
- if (!slang_assembly_file_push_label2 (file, slang_asm_bool_copy,
+ if (!slang_assembly_file_push_label2 (A->file, slang_asm_bool_copy,
(master_rows - i) * 4, i * 4))
- return 0;
+ return GL_FALSE;
break;
case slang_spec_int:
- if (!slang_assembly_file_push_label2 (file, slang_asm_int_copy,
+ if (!slang_assembly_file_push_label2 (A->file, slang_asm_int_copy,
(master_rows - i) * 4, i * 4))
- return 0;
+ return GL_FALSE;
break;
case slang_spec_float:
- if (!slang_assembly_file_push_label2 (file, slang_asm_float_copy,
+ if (!slang_assembly_file_push_label2 (A->file, slang_asm_float_copy,
(master_rows - i) * 4, i * 4))
- return 0;
+ return GL_FALSE;
break;
default:
break;
}
}
- if (!slang_assembly_file_push_label (file, slang_asm_local_free, 4))
- return 0;
+ if (!slang_assembly_file_push_label (A->file, slang_asm_local_free, 4))
+ return GL_FALSE;
for (i = swz->num_components; i > 0; i--)
{
- unsigned int n = i - 1;
-
- if (!slang_assembly_file_push_label2 (file, slang_asm_local_addr, info->swizzle_tmp, 16))
- return 0;
- if (!slang_assembly_file_push_label (file, slang_asm_addr_push, swz->swizzle[n] * 4))
- return 0;
- if (!slang_assembly_file_push (file, slang_asm_addr_add))
- return 0;
+ GLuint n = i - 1;
+
+ if (!slang_assembly_file_push_label2 (A->file, slang_asm_local_addr, A->local.swizzle_tmp, 16))
+ return GL_FALSE;
+ if (!slang_assembly_file_push_label (A->file, slang_asm_addr_push, swz->swizzle[n] * 4))
+ return GL_FALSE;
+ if (!slang_assembly_file_push (A->file, slang_asm_addr_add))
+ return GL_FALSE;
switch (_slang_type_base (master_spec->type))
{
case slang_spec_bool:
- if (!slang_assembly_file_push (file, slang_asm_bool_deref))
- return 0;
+ if (!slang_assembly_file_push (A->file, slang_asm_bool_deref))
+ return GL_FALSE;
break;
case slang_spec_int:
- if (!slang_assembly_file_push (file, slang_asm_int_deref))
- return 0;
+ if (!slang_assembly_file_push (A->file, slang_asm_int_deref))
+ return GL_FALSE;
break;
case slang_spec_float:
- if (!slang_assembly_file_push (file, slang_asm_float_deref))
- return 0;
+ if (!slang_assembly_file_push (A->file, slang_asm_float_deref))
+ return GL_FALSE;
break;
default:
break;
}
}
- return 1;
+
+ return GL_TRUE;
}
diff --git a/src/mesa/shader/slang/slang_assemble_constructor.h b/src/mesa/shader/slang/slang_assemble_constructor.h
index b87e9cce7de..3b556379978 100644
--- a/src/mesa/shader/slang/slang_assemble_constructor.h
+++ b/src/mesa/shader/slang/slang_assemble_constructor.h
@@ -33,33 +33,31 @@ extern "C" {
#endif
/*
- checks if a field selector is a general swizzle (an r-value swizzle with replicated
- components or an l-value swizzle mask) for a vector
- returns 1 if this is the case, <swz> is filled with swizzle information
- returns 0 otherwise
-*/
-int _slang_is_swizzle (const char *field, unsigned int rows, slang_swizzle *swz);
+ * Checks if a field selector is a general swizzle (an r-value swizzle with replicated
+ * components or an l-value swizzle mask) for a vector.
+ * Returns GL_TRUE if this is the case, <swz> is filled with swizzle information.
+ * Returns GL_FALSE otherwise.
+ */
+GLboolean _slang_is_swizzle (const char *field, GLuint rows, slang_swizzle *swz);
/*
- checks if a general swizzle is an l-value swizzle - these swizzles do not have
- duplicated fields and they are specified in order
- returns 1 if this is a swizzle mask
- returns 0 otherwise
-*/
-int _slang_is_swizzle_mask (const slang_swizzle *swz, unsigned int rows);
+ * Checks if a general swizzle is an l-value swizzle - these swizzles do not have
+ * duplicated fields.
+ * Returns GL_TRUE if this is a swizzle mask.
+ * Returns GL_FALSE otherwise
+ */
+GLboolean _slang_is_swizzle_mask (const slang_swizzle *swz, GLuint rows);
/*
- combines two swizzles to form single swizzle
- example: "wzyx.yx" --> "zw"
-*/
-void _slang_multiply_swizzles (slang_swizzle *, const slang_swizzle *, const slang_swizzle *);
+ * Combines (multiplies) two swizzles to form single swizzle.
+ * Example: "vec.wzyx.yx" --> "vec.zw".
+ */
+GLvoid _slang_multiply_swizzles (slang_swizzle *, const slang_swizzle *, const slang_swizzle *);
-int _slang_assemble_constructor (slang_assembly_file *file, slang_operation *op,
- slang_assembly_flow_control *flow, slang_assembly_name_space *space,
- slang_assembly_local_info *info, struct slang_machine_ *);
+GLboolean _slang_assemble_constructor (slang_assemble_ctx *, slang_operation *);
-int _slang_assemble_constructor_from_swizzle (slang_assembly_file *file, const slang_swizzle *swz,
- slang_type_specifier *spec, slang_type_specifier *master_spec, slang_assembly_local_info *info);
+GLboolean _slang_assemble_constructor_from_swizzle (slang_assemble_ctx *, const slang_swizzle *,
+ slang_type_specifier *, slang_type_specifier *);
#ifdef __cplusplus
}
diff --git a/src/mesa/shader/slang/slang_assemble_typeinfo.c b/src/mesa/shader/slang/slang_assemble_typeinfo.c
index 830597e9c2e..2fcdd33718b 100644
--- a/src/mesa/shader/slang/slang_assemble_typeinfo.c
+++ b/src/mesa/shader/slang/slang_assemble_typeinfo.c
@@ -34,15 +34,15 @@
/* slang_assembly_typeinfo */
-int slang_assembly_typeinfo_construct (slang_assembly_typeinfo *ti)
+GLboolean slang_assembly_typeinfo_construct (slang_assembly_typeinfo *ti)
{
if (!slang_type_specifier_construct (&ti->spec))
- return 0;
+ return GL_FALSE;
ti->array_size = NULL;
- return 1;
+ return GL_TRUE;
}
-void slang_assembly_typeinfo_destruct (slang_assembly_typeinfo *ti)
+GLvoid slang_assembly_typeinfo_destruct (slang_assembly_typeinfo *ti)
{
slang_type_specifier_destruct (&ti->spec);
/* do not free ti->array_size */
@@ -50,24 +50,24 @@ void slang_assembly_typeinfo_destruct (slang_assembly_typeinfo *ti)
/* _slang_typeof_operation() */
-static int typeof_existing_function (const char *name, slang_operation *params,
- unsigned int num_params, slang_assembly_name_space *space, slang_type_specifier *spec,
+static GLboolean typeof_existing_function (const char *name, slang_operation *params,
+ GLuint num_params, slang_assembly_name_space *space, slang_type_specifier *spec,
slang_atom_pool *atoms)
{
slang_atom atom;
- int exists;
+ GLboolean exists;
atom = slang_atom_pool_atom (atoms, name);
if (!_slang_typeof_function (atom, params, num_params, space, spec, &exists, atoms))
- return 0;
+ return GL_FALSE;
return exists;
}
-int _slang_typeof_operation (slang_operation *op, slang_assembly_name_space *space,
+GLboolean _slang_typeof_operation (slang_operation *op, slang_assembly_name_space *space,
slang_assembly_typeinfo *ti, slang_atom_pool *atoms)
{
- ti->can_be_referenced = 0;
- ti->is_swizzled = 0;
+ ti->can_be_referenced = GL_FALSE;
+ ti->is_swizzled = GL_FALSE;
switch (op->type)
{
@@ -120,21 +120,21 @@ int _slang_typeof_operation (slang_operation *op, slang_assembly_name_space *spa
{
slang_variable *var;
- var = _slang_locate_variable (op->locals, op->a_id, 1);
+ var = _slang_locate_variable (op->locals, op->a_id, GL_TRUE);
if (var == NULL)
- return 0;
+ return GL_FALSE;
if (!slang_type_specifier_copy (&ti->spec, &var->type.specifier))
- return 0;
- ti->can_be_referenced = 1;
+ return GL_FALSE;
+ ti->can_be_referenced = GL_TRUE;
ti->array_size = var->array_size;
}
break;
case slang_oper_sequence:
/* TODO: check [0] and [1] if they match */
if (!_slang_typeof_operation (&op->children[1], space, ti, atoms))
- return 0;
- ti->can_be_referenced = 0;
- ti->is_swizzled = 0;
+ return GL_FALSE;
+ ti->can_be_referenced = GL_FALSE;
+ ti->is_swizzled = GL_FALSE;
break;
/*case slang_oper_modassign:*/
/*case slang_oper_lshassign:*/
@@ -145,9 +145,9 @@ int _slang_typeof_operation (slang_operation *op, slang_assembly_name_space *spa
case slang_oper_select:
/* TODO: check [1] and [2] if they match */
if (!_slang_typeof_operation (&op->children[1], space, ti, atoms))
- return 0;
- ti->can_be_referenced = 0;
- ti->is_swizzled = 0;
+ return GL_FALSE;
+ ti->can_be_referenced = GL_FALSE;
+ ti->is_swizzled = GL_FALSE;
break;
/*case slang_oper_bitor:*/
/*case slang_oper_bitxor:*/
@@ -156,30 +156,30 @@ int _slang_typeof_operation (slang_operation *op, slang_assembly_name_space *spa
/*case slang_oper_rshift:*/
case slang_oper_add:
if (!typeof_existing_function ("+", op->children, 2, space, &ti->spec, atoms))
- return 0;
+ return GL_FALSE;
break;
case slang_oper_subtract:
if (!typeof_existing_function ("-", op->children, 2, space, &ti->spec, atoms))
- return 0;
+ return GL_FALSE;
break;
case slang_oper_multiply:
if (!typeof_existing_function ("*", op->children, 2, space, &ti->spec, atoms))
- return 0;
+ return GL_FALSE;
break;
case slang_oper_divide:
if (!typeof_existing_function ("/", op->children, 2, space, &ti->spec, atoms))
- return 0;
+ return GL_FALSE;
break;
/*case slang_oper_modulus:*/
case slang_oper_plus:
if (!_slang_typeof_operation (op->children, space, ti, atoms))
- return 0;
- ti->can_be_referenced = 0;
- ti->is_swizzled = 0;
+ return GL_FALSE;
+ ti->can_be_referenced = GL_FALSE;
+ ti->is_swizzled = GL_FALSE;
break;
case slang_oper_minus:
if (!typeof_existing_function ("-", op->children, 1, space, &ti->spec, atoms))
- return 0;
+ return GL_FALSE;
break;
/*case slang_oper_complement:*/
case slang_oper_subscript:
@@ -187,11 +187,11 @@ int _slang_typeof_operation (slang_operation *op, slang_assembly_name_space *spa
slang_assembly_typeinfo _ti;
if (!slang_assembly_typeinfo_construct (&_ti))
- return 0;
+ return GL_FALSE;
if (!_slang_typeof_operation (op->children, space, &_ti, atoms))
{
slang_assembly_typeinfo_destruct (&_ti);
- return 0;
+ return GL_FALSE;
}
ti->can_be_referenced = _ti.can_be_referenced;
if (_ti.spec.type == slang_spec_array)
@@ -199,7 +199,7 @@ int _slang_typeof_operation (slang_operation *op, slang_assembly_name_space *spa
if (!slang_type_specifier_copy (&ti->spec, _ti.spec._array))
{
slang_assembly_typeinfo_destruct (&_ti);
- return 0;
+ return GL_FALSE;
}
}
else
@@ -207,7 +207,7 @@ int _slang_typeof_operation (slang_operation *op, slang_assembly_name_space *spa
if (!_slang_type_is_vector (_ti.spec.type) && !_slang_type_is_matrix (_ti.spec.type))
{
slang_assembly_typeinfo_destruct (&_ti);
- return 0;
+ return GL_FALSE;
}
ti->spec.type = _slang_type_base (_ti.spec.type);
}
@@ -216,38 +216,38 @@ int _slang_typeof_operation (slang_operation *op, slang_assembly_name_space *spa
break;
case slang_oper_call:
{
- int exists;
+ GLboolean exists;
if (!_slang_typeof_function (op->a_id, op->children, op->num_children, space, &ti->spec,
&exists, atoms))
- return 0;
+ return GL_FALSE;
if (!exists)
{
-/* slang_struct *s = slang_struct_scope_find (space->structs, op->identifier, 1);
+ slang_struct *s = slang_struct_scope_find (space->structs, op->a_id, GL_TRUE);
if (s != NULL)
{
ti->spec.type = slang_spec_struct;
ti->spec._struct = (slang_struct *) slang_alloc_malloc (sizeof (slang_struct));
if (ti->spec._struct == NULL)
- return 0;
+ return GL_FALSE;
if (!slang_struct_construct (ti->spec._struct))
{
slang_alloc_free (ti->spec._struct);
ti->spec._struct = NULL;
- return 0;
+ return GL_FALSE;
}
if (!slang_struct_copy (ti->spec._struct, s))
- return 0;
+ return GL_FALSE;
}
else
-*/ {
+ {
const char *name;
slang_type_specifier_type type;
name = slang_atom_pool_id (atoms, op->a_id);
type = slang_type_specifier_type_from_string (name);
if (type == slang_spec_void)
- return 0;
+ return GL_FALSE;
ti->spec.type = type;
}
}
@@ -258,32 +258,32 @@ int _slang_typeof_operation (slang_operation *op, slang_assembly_name_space *spa
slang_assembly_typeinfo _ti;
if (!slang_assembly_typeinfo_construct (&_ti))
- return 0;
+ return GL_FALSE;
if (!_slang_typeof_operation (op->children, space, &_ti, atoms))
{
slang_assembly_typeinfo_destruct (&_ti);
- return 0;
+ return GL_FALSE;
}
if (_ti.spec.type == slang_spec_struct)
{
slang_variable *field;
- field = _slang_locate_variable (_ti.spec._struct->fields, op->a_id, 0);
+ field = _slang_locate_variable (_ti.spec._struct->fields, op->a_id, GL_FALSE);
if (field == NULL)
{
slang_assembly_typeinfo_destruct (&_ti);
- return 0;
+ return GL_FALSE;
}
if (!slang_type_specifier_copy (&ti->spec, &field->type.specifier))
{
slang_assembly_typeinfo_destruct (&_ti);
- return 0;
+ return GL_FALSE;
}
ti->can_be_referenced = _ti.can_be_referenced;
}
else
{
- unsigned int rows;
+ GLuint rows;
const char *swizzle;
slang_type_specifier_type base;
@@ -291,16 +291,16 @@ int _slang_typeof_operation (slang_operation *op, slang_assembly_name_space *spa
if (!_slang_type_is_vector (_ti.spec.type))
{
slang_assembly_typeinfo_destruct (&_ti);
- return 0;
+ return GL_FALSE;
}
rows = _slang_type_dim (_ti.spec.type);
swizzle = slang_atom_pool_id (atoms, op->a_id);
if (!_slang_is_swizzle (swizzle, rows, &ti->swz))
{
slang_assembly_typeinfo_destruct (&_ti);
- return 0;
+ return GL_FALSE;
}
- ti->is_swizzled = 1;
+ ti->is_swizzled = GL_TRUE;
ti->can_be_referenced = _ti.can_be_referenced && _slang_is_swizzle_mask (&ti->swz,
rows);
if (_ti.is_swizzled)
@@ -330,8 +330,7 @@ int _slang_typeof_operation (slang_operation *op, slang_assembly_name_space *spa
ti->spec.type = slang_spec_bvec2;
break;
default:
- _mesa_problem(NULL, "unexepected base in _slang_typeof_operation");
- ti->spec.type = slang_spec_void;
+ break;
}
break;
case 3:
@@ -347,8 +346,7 @@ int _slang_typeof_operation (slang_operation *op, slang_assembly_name_space *spa
ti->spec.type = slang_spec_bvec3;
break;
default:
- _mesa_problem(NULL, "unexepected base in _slang_typeof_operation");
- ti->spec.type = slang_spec_void;
+ break;
}
break;
case 4:
@@ -364,8 +362,7 @@ int _slang_typeof_operation (slang_operation *op, slang_assembly_name_space *spa
ti->spec.type = slang_spec_bvec4;
break;
default:
- _mesa_problem(NULL, "unexepected base in _slang_typeof_operation");
- ti->spec.type = slang_spec_void;
+ break;
}
break;
default:
@@ -378,48 +375,50 @@ int _slang_typeof_operation (slang_operation *op, slang_assembly_name_space *spa
case slang_oper_postincrement:
case slang_oper_postdecrement:
if (!_slang_typeof_operation (op->children, space, ti, atoms))
- return 0;
- ti->can_be_referenced = 0;
- ti->is_swizzled = 0;
+ return GL_FALSE;
+ ti->can_be_referenced = GL_FALSE;
+ ti->is_swizzled = GL_FALSE;
break;
default:
- return 0;
+ return GL_FALSE;
}
- return 1;
+
+ return GL_TRUE;
}
/* _slang_typeof_function() */
-int _slang_typeof_function (slang_atom a_name, slang_operation *params, unsigned int num_params,
- slang_assembly_name_space *space, slang_type_specifier *spec, int *exists, slang_atom_pool *atoms)
+GLboolean _slang_typeof_function (slang_atom a_name, slang_operation *params, GLuint num_params,
+ slang_assembly_name_space *space, slang_type_specifier *spec, GLboolean *exists,
+ slang_atom_pool *atoms)
{
slang_function *fun;
fun = _slang_locate_function (space->funcs, a_name, params, num_params, space, atoms);
*exists = fun != NULL;
if (fun == NULL)
- return 1;
+ return GL_TRUE;
return slang_type_specifier_copy (spec, &fun->header.type.specifier);
}
/* _slang_type_is_matrix() */
-int _slang_type_is_matrix (slang_type_specifier_type ty)
+GLboolean _slang_type_is_matrix (slang_type_specifier_type ty)
{
switch (ty)
{
case slang_spec_mat2:
case slang_spec_mat3:
case slang_spec_mat4:
- return 1;
+ return GL_TRUE;
default:
- return 0;
+ return GL_FALSE;
}
}
/* _slang_type_is_vector() */
-int _slang_type_is_vector (slang_type_specifier_type ty)
+GLboolean _slang_type_is_vector (slang_type_specifier_type ty)
{
switch (ty)
{
@@ -432,9 +431,9 @@ int _slang_type_is_vector (slang_type_specifier_type ty)
case slang_spec_bvec2:
case slang_spec_bvec3:
case slang_spec_bvec4:
- return 1;
+ return GL_TRUE;
default:
- return 0;
+ return GL_FALSE;
}
}
@@ -472,7 +471,7 @@ slang_type_specifier_type _slang_type_base (slang_type_specifier_type ty)
/* _slang_type_dim */
-unsigned int _slang_type_dim (slang_type_specifier_type ty)
+GLuint _slang_type_dim (slang_type_specifier_type ty)
{
switch (ty)
{
diff --git a/src/mesa/shader/slang/slang_assemble_typeinfo.h b/src/mesa/shader/slang/slang_assemble_typeinfo.h
index cd16440e1a7..9f32b4c6456 100644
--- a/src/mesa/shader/slang/slang_assemble_typeinfo.h
+++ b/src/mesa/shader/slang/slang_assemble_typeinfo.h
@@ -34,36 +34,39 @@ extern "C" {
typedef struct slang_assembly_typeinfo_
{
- int can_be_referenced;
- int is_swizzled;
+ GLboolean can_be_referenced;
+ GLboolean is_swizzled;
slang_swizzle swz;
slang_type_specifier spec;
slang_operation *array_size;
} slang_assembly_typeinfo;
-int slang_assembly_typeinfo_construct (slang_assembly_typeinfo *);
-void slang_assembly_typeinfo_destruct (slang_assembly_typeinfo *);
+GLboolean slang_assembly_typeinfo_construct (slang_assembly_typeinfo *);
+GLvoid slang_assembly_typeinfo_destruct (slang_assembly_typeinfo *);
/*
- retrieves type information about an operation
- returns 1 on success
- returns 0 otherwise
-*/
-int _slang_typeof_operation (slang_operation *, slang_assembly_name_space *,
+ * Retrieves type information about an operation.
+ * Returns GL_TRUE on success.
+ * Returns GL_FALSE otherwise.
+ */
+GLboolean _slang_typeof_operation (slang_operation *, slang_assembly_name_space *,
slang_assembly_typeinfo *, slang_atom_pool *);
/*
- retrieves type of a function prototype, if one exists
- returns 1 on success, even if the function was not found
- returns 0 otherwise
-*/
-int _slang_typeof_function (slang_atom a_name, slang_operation *params, unsigned int num_params,
- slang_assembly_name_space *space, slang_type_specifier *spec, int *exists, slang_atom_pool *);
+ * Retrieves type of a function prototype, if one exists.
+ * Returns GL_TRUE on success, even if the function was not found.
+ * Returns GL_FALSE otherwise.
+ */
+GLboolean _slang_typeof_function (slang_atom a_name, slang_operation *params, GLuint num_params,
+ slang_assembly_name_space *, slang_type_specifier *spec, GLboolean *exists, slang_atom_pool *);
+
+GLboolean _slang_type_is_matrix (slang_type_specifier_type);
+
+GLboolean _slang_type_is_vector (slang_type_specifier_type);
-int _slang_type_is_matrix (slang_type_specifier_type);
-int _slang_type_is_vector (slang_type_specifier_type);
slang_type_specifier_type _slang_type_base (slang_type_specifier_type);
-unsigned int _slang_type_dim (slang_type_specifier_type);
+
+GLuint _slang_type_dim (slang_type_specifier_type);
#ifdef __cplusplus
}
diff --git a/src/mesa/shader/slang/slang_compile.c b/src/mesa/shader/slang/slang_compile.c
index 02850ebf129..808cf9b82a0 100644
--- a/src/mesa/shader/slang/slang_compile.c
+++ b/src/mesa/shader/slang/slang_compile.c
@@ -27,135 +27,135 @@
* slang front-end compiler
* \author Michal Krol
*/
-
-#include "imports.h"
-#include "grammar_mesa.h"
+
+#include "imports.h"
+#include "grammar_mesa.h"
#include "slang_utility.h"
#include "slang_compile.h"
#include "slang_preprocess.h"
-#include "slang_storage.h"
-#include "slang_assemble.h"
-#include "slang_execute.h"
+#include "slang_storage.h"
+#include "slang_assemble.h"
+#include "slang_execute.h"
/*
- This is a straightforward implementation of the slang front-end compiler.
- Lots of error-checking functionality is missing but every well-formed shader source should
- compile successfully and execute as expected. However, some semantically ill-formed shaders
- may be accepted resulting in undefined behaviour.
-*/
-
-/* slang_var_pool */
-
-static GLuint slang_var_pool_alloc (slang_var_pool *pool, unsigned int size)
-{
- GLuint addr;
-
- addr = pool->next_addr;
- pool->next_addr += size;
- return addr;
+ * This is a straightforward implementation of the slang front-end compiler.
+ * Lots of error-checking functionality is missing but every well-formed shader source should
+ * compile successfully and execute as expected. However, some semantically ill-formed shaders
+ * may be accepted resulting in undefined behaviour.
+ */
+
+/* slang_var_pool */
+
+static GLuint slang_var_pool_alloc (slang_var_pool *pool, unsigned int size)
+{
+ GLuint addr;
+
+ addr = pool->next_addr;
+ pool->next_addr += size;
+ return addr;
}
/* slang_translation_unit */
int slang_translation_unit_construct (slang_translation_unit *unit)
{
- unit->assembly = (slang_assembly_file *) slang_alloc_malloc (sizeof (slang_assembly_file));
- if (unit->assembly == NULL)
- return 0;
- if (!slang_assembly_file_construct (unit->assembly))
- {
- slang_alloc_free (unit->assembly);
- return 0;
- }
- unit->global_pool = (slang_var_pool *) slang_alloc_malloc (sizeof (slang_var_pool));
- if (unit->global_pool == NULL)
- {
- slang_assembly_file_destruct (unit->assembly);
- slang_alloc_free (unit->assembly);
- return 0;
- }
- unit->global_pool->next_addr = 0;
- unit->machine = (slang_machine *) slang_alloc_malloc (sizeof (slang_machine));
- if (unit->machine == NULL)
- {
- slang_alloc_free (unit->global_pool);
- slang_assembly_file_destruct (unit->assembly);
- slang_alloc_free (unit->assembly);
- return 0;
- }
- slang_machine_init (unit->machine);
- unit->atom_pool = (slang_atom_pool *) slang_alloc_malloc (sizeof (slang_atom_pool));
- if (unit->atom_pool == NULL)
- {
- slang_alloc_free (unit->machine);
- slang_alloc_free (unit->global_pool);
- slang_assembly_file_destruct (unit->assembly);
- slang_alloc_free (unit->assembly);
- return 0;
- }
- slang_atom_pool_construct (unit->atom_pool);
- if (!slang_translation_unit_construct2 (unit, unit->assembly, unit->global_pool, unit->machine,
- unit->atom_pool))
- {
- slang_alloc_free (unit->atom_pool);
- slang_alloc_free (unit->machine);
- slang_alloc_free (unit->global_pool);
- slang_assembly_file_destruct (unit->assembly);
- slang_alloc_free (unit->assembly);
- return 0;
- }
- unit->free_assembly = 1;
- unit->free_global_pool = 1;
- unit->free_machine = 1;
- unit->free_atom_pool = 1;
+ unit->assembly = (slang_assembly_file *) slang_alloc_malloc (sizeof (slang_assembly_file));
+ if (unit->assembly == NULL)
+ return 0;
+ if (!slang_assembly_file_construct (unit->assembly))
+ {
+ slang_alloc_free (unit->assembly);
+ return 0;
+ }
+ unit->global_pool = (slang_var_pool *) slang_alloc_malloc (sizeof (slang_var_pool));
+ if (unit->global_pool == NULL)
+ {
+ slang_assembly_file_destruct (unit->assembly);
+ slang_alloc_free (unit->assembly);
+ return 0;
+ }
+ unit->global_pool->next_addr = 0;
+ unit->machine = (slang_machine *) slang_alloc_malloc (sizeof (slang_machine));
+ if (unit->machine == NULL)
+ {
+ slang_alloc_free (unit->global_pool);
+ slang_assembly_file_destruct (unit->assembly);
+ slang_alloc_free (unit->assembly);
+ return 0;
+ }
+ slang_machine_init (unit->machine);
+ unit->atom_pool = (slang_atom_pool *) slang_alloc_malloc (sizeof (slang_atom_pool));
+ if (unit->atom_pool == NULL)
+ {
+ slang_alloc_free (unit->machine);
+ slang_alloc_free (unit->global_pool);
+ slang_assembly_file_destruct (unit->assembly);
+ slang_alloc_free (unit->assembly);
+ return 0;
+ }
+ slang_atom_pool_construct (unit->atom_pool);
+ if (!slang_translation_unit_construct2 (unit, unit->assembly, unit->global_pool, unit->machine,
+ unit->atom_pool))
+ {
+ slang_alloc_free (unit->atom_pool);
+ slang_alloc_free (unit->machine);
+ slang_alloc_free (unit->global_pool);
+ slang_assembly_file_destruct (unit->assembly);
+ slang_alloc_free (unit->assembly);
+ return 0;
+ }
+ unit->free_assembly = 1;
+ unit->free_global_pool = 1;
+ unit->free_machine = 1;
+ unit->free_atom_pool = 1;
+ return 1;
+}
+
+int slang_translation_unit_construct2 (slang_translation_unit *unit, slang_assembly_file *file,
+ slang_var_pool *pool, struct slang_machine_ *mach, slang_atom_pool *atoms)
+{
+ if (!slang_variable_scope_construct (&unit->globals))
+ return 0;
+ if (!slang_function_scope_construct (&unit->functions))
+ {
+ slang_variable_scope_destruct (&unit->globals);
+ return 0;
+ }
+ if (!slang_struct_scope_construct (&unit->structs))
+ {
+ slang_variable_scope_destruct (&unit->globals);
+ slang_function_scope_destruct (&unit->functions);
+ return 0;
+ }
+ unit->assembly = file;
+ unit->free_assembly = 0;
+ unit->global_pool = pool;
+ unit->free_global_pool = 0;
+ unit->machine = mach;
+ unit->free_machine = 0;
+ unit->atom_pool = atoms;
+ unit->free_atom_pool = 0;
return 1;
-}
-
-int slang_translation_unit_construct2 (slang_translation_unit *unit, slang_assembly_file *file,
- slang_var_pool *pool, struct slang_machine_ *mach, slang_atom_pool *atoms)
-{
- if (!slang_variable_scope_construct (&unit->globals))
- return 0;
- if (!slang_function_scope_construct (&unit->functions))
- {
- slang_variable_scope_destruct (&unit->globals);
- return 0;
- }
- if (!slang_struct_scope_construct (&unit->structs))
- {
- slang_variable_scope_destruct (&unit->globals);
- slang_function_scope_destruct (&unit->functions);
- return 0;
- }
- unit->assembly = file;
- unit->free_assembly = 0;
- unit->global_pool = pool;
- unit->free_global_pool = 0;
- unit->machine = mach;
- unit->free_machine = 0;
- unit->atom_pool = atoms;
- unit->free_atom_pool = 0;
- return 1;
}
void slang_translation_unit_destruct (slang_translation_unit *unit)
{
slang_variable_scope_destruct (&unit->globals);
slang_function_scope_destruct (&unit->functions);
- slang_struct_scope_destruct (&unit->structs);
- if (unit->free_assembly)
- {
- slang_assembly_file_destruct (unit->assembly);
- slang_alloc_free (unit->assembly);
- }
- if (unit->free_global_pool)
- slang_alloc_free (unit->global_pool);
- if (unit->free_machine)
- slang_alloc_free (unit->machine);
- if (unit->free_atom_pool)
- {
- slang_atom_pool_destruct (unit->atom_pool);
- slang_alloc_free (unit->atom_pool);
+ slang_struct_scope_destruct (&unit->structs);
+ if (unit->free_assembly)
+ {
+ slang_assembly_file_destruct (unit->assembly);
+ slang_alloc_free (unit->assembly);
+ }
+ if (unit->free_global_pool)
+ slang_alloc_free (unit->global_pool);
+ if (unit->free_machine)
+ slang_alloc_free (unit->machine);
+ if (unit->free_atom_pool)
+ {
+ slang_atom_pool_destruct (unit->atom_pool);
+ slang_alloc_free (unit->atom_pool);
}
}
@@ -177,14 +177,14 @@ void slang_info_log_destruct (slang_info_log *log)
static int slang_info_log_message (slang_info_log *log, const char *prefix, const char *msg)
{
- unsigned int new_size;
+ unsigned int new_size;
if (log->dont_free_text)
return 0;
new_size = slang_string_length (prefix) + 3 + slang_string_length (msg);
if (log->text != NULL)
- {
- unsigned int text_len = slang_string_length (log->text);
+ {
+ unsigned int text_len = slang_string_length (log->text);
log->text = (char *) slang_alloc_realloc (log->text, text_len + 1, new_size + text_len + 1);
}
@@ -246,38 +246,38 @@ typedef struct slang_parse_ctx_
{
const byte *I;
slang_info_log *L;
- int parsing_builtin;
- int global_scope;
+ int parsing_builtin;
+ int global_scope;
slang_atom_pool *atoms;
-} slang_parse_ctx;
-
-/* slang_output_ctx */
-
-typedef struct slang_output_ctx_
-{
- slang_variable_scope *vars;
- slang_function_scope *funs;
- slang_struct_scope *structs;
- slang_assembly_file *assembly;
- slang_var_pool *global_pool;
- slang_machine *machine;
+} slang_parse_ctx;
+
+/* slang_output_ctx */
+
+typedef struct slang_output_ctx_
+{
+ slang_variable_scope *vars;
+ slang_function_scope *funs;
+ slang_struct_scope *structs;
+ slang_assembly_file *assembly;
+ slang_var_pool *global_pool;
+ slang_machine *machine;
} slang_output_ctx;
/* _slang_compile() */
static void parse_identifier_str (slang_parse_ctx *C, char **id)
{
- *id = (char *) C->I;
+ *id = (char *) C->I;
C->I += _mesa_strlen (*id) + 1;
-}
-
-static slang_atom parse_identifier (slang_parse_ctx *C)
-{
- const char *id;
-
- id = (const char *) C->I;
- C->I += _mesa_strlen (id) + 1;
- return slang_atom_pool_atom (C->atoms, id);
+}
+
+static slang_atom parse_identifier (slang_parse_ctx *C)
+{
+ const char *id;
+
+ id = (const char *) C->I;
+ C->I += _mesa_strlen (id) + 1;
+ return slang_atom_pool_atom (C->atoms, id);
}
static int parse_number (slang_parse_ctx *C, int *number)
@@ -311,9 +311,9 @@ static int parse_float (slang_parse_ctx *C, float *number)
parse_identifier_str (C, &integral);
parse_identifier_str (C, &fractional);
- parse_identifier_str (C, &exponent);
+ parse_identifier_str (C, &exponent);
- whole = (char *) (slang_alloc_malloc ((_mesa_strlen (integral) + _mesa_strlen (fractional) +
+ whole = (char *) (slang_alloc_malloc ((_mesa_strlen (integral) + _mesa_strlen (fractional) +
_mesa_strlen (exponent) + 3) * sizeof (char)));
if (whole == NULL)
{
@@ -348,151 +348,151 @@ static int check_revision (slang_parse_ctx *C)
}
static int parse_statement (slang_parse_ctx *, slang_output_ctx *, slang_operation *);
-static int parse_expression (slang_parse_ctx *, slang_output_ctx *, slang_operation *);
-static int parse_type_specifier (slang_parse_ctx *, slang_output_ctx *, slang_type_specifier *);
-
-/* structure field */
-#define FIELD_NONE 0
-#define FIELD_NEXT 1
-#define FIELD_ARRAY 2
-
-static int parse_struct_field_var (slang_parse_ctx *C, slang_output_ctx *O, slang_variable *var)
-{
- var->a_name = parse_identifier (C);
- if (var->a_name == SLANG_ATOM_NULL)
- return 0;
-
- switch (*C->I++)
- {
- case FIELD_NONE:
- break;
- case FIELD_ARRAY:
- var->array_size = (slang_operation *) slang_alloc_malloc (sizeof (slang_operation));
- if (var->array_size == NULL)
- {
- slang_info_log_memory (C->L);
- return 0;
- }
- if (!slang_operation_construct (var->array_size))
- {
- slang_alloc_free (var->array_size);
- var->array_size = NULL;
- return 0;
- }
- if (!parse_expression (C, O, var->array_size))
- return 0;
- break;
- default:
- return 0;
- }
-
- return 1;
-}
-
-static int parse_struct_field (slang_parse_ctx *C, slang_output_ctx *O, slang_struct *st,
- slang_type_specifier *sp)
-{
- slang_output_ctx o = *O;
-
- o.structs = st->structs;
- if (!parse_type_specifier (C, &o, sp))
- return 0;
- do
- {
- slang_variable *var;
-
- st->fields->variables = (slang_variable *) slang_alloc_realloc (st->fields->variables,
- st->fields->num_variables * sizeof (slang_variable),
- (st->fields->num_variables + 1) * sizeof (slang_variable));
- if (st->fields->variables == NULL)
- {
- slang_info_log_memory (C->L);
- return 0;
- }
- var = &st->fields->variables[st->fields->num_variables];
- if (!slang_variable_construct (var))
- return 0;
- st->fields->num_variables++;
- if (!slang_type_specifier_copy (&var->type.specifier, sp))
- return 0;
- if (!parse_struct_field_var (C, &o, var))
- return 0;
- }
- while (*C->I++ != FIELD_NONE);
-
- return 1;
-}
-
-static int parse_struct (slang_parse_ctx *C, slang_output_ctx *O, slang_struct **st)
-{
- slang_atom a_name;
- const char *name;
-
- /* parse struct name (if any) and make sure it is unique in current scope */
- a_name = parse_identifier (C);
- if (a_name == SLANG_ATOM_NULL)
- return 0;
- name = slang_atom_pool_id (C->atoms, a_name);
- if (name[0] != '\0' && slang_struct_scope_find (O->structs, a_name, 0) != NULL)
- {
- slang_info_log_error (C->L, "%s: duplicate type name", name);
- return 0;
- }
-
- /* set-up a new struct */
- *st = (slang_struct *) slang_alloc_malloc (sizeof (slang_struct));
- if (*st == NULL)
- {
- slang_info_log_memory (C->L);
- return 0;
- }
- if (!slang_struct_construct (*st))
- {
- slang_alloc_free (*st);
- *st = NULL;
- slang_info_log_memory (C->L);
- return 0;
- }
- (**st).a_name = a_name;
- (**st).structs->outer_scope = O->structs;
-
- /* parse individual struct fields */
- do
- {
- slang_type_specifier sp;
-
- if (!slang_type_specifier_construct (&sp))
- return 0;
- if (!parse_struct_field (C, O, *st, &sp))
- {
- slang_type_specifier_destruct (&sp);
- return 0;
- }
- }
- while (*C->I++ != FIELD_NONE);
-
- /* if named struct, copy it to current scope */
- if (name[0] != '\0')
- {
- slang_struct *s;
-
- O->structs->structs = (slang_struct *) slang_alloc_realloc (O->structs->structs,
- O->structs->num_structs * sizeof (slang_struct),
- (O->structs->num_structs + 1) * sizeof (slang_struct));
- if (O->structs->structs == NULL)
- {
- slang_info_log_memory (C->L);
- return 0;
- }
- s = &O->structs->structs[O->structs->num_structs];
- if (!slang_struct_construct (s))
- return 0;
- O->structs->num_structs++;
- if (!slang_struct_copy (s, *st))
- return 0;
- }
-
- return 1;
+static int parse_expression (slang_parse_ctx *, slang_output_ctx *, slang_operation *);
+static int parse_type_specifier (slang_parse_ctx *, slang_output_ctx *, slang_type_specifier *);
+
+/* structure field */
+#define FIELD_NONE 0
+#define FIELD_NEXT 1
+#define FIELD_ARRAY 2
+
+static int parse_struct_field_var (slang_parse_ctx *C, slang_output_ctx *O, slang_variable *var)
+{
+ var->a_name = parse_identifier (C);
+ if (var->a_name == SLANG_ATOM_NULL)
+ return 0;
+
+ switch (*C->I++)
+ {
+ case FIELD_NONE:
+ break;
+ case FIELD_ARRAY:
+ var->array_size = (slang_operation *) slang_alloc_malloc (sizeof (slang_operation));
+ if (var->array_size == NULL)
+ {
+ slang_info_log_memory (C->L);
+ return 0;
+ }
+ if (!slang_operation_construct (var->array_size))
+ {
+ slang_alloc_free (var->array_size);
+ var->array_size = NULL;
+ return 0;
+ }
+ if (!parse_expression (C, O, var->array_size))
+ return 0;
+ break;
+ default:
+ return 0;
+ }
+
+ return 1;
+}
+
+static int parse_struct_field (slang_parse_ctx *C, slang_output_ctx *O, slang_struct *st,
+ slang_type_specifier *sp)
+{
+ slang_output_ctx o = *O;
+
+ o.structs = st->structs;
+ if (!parse_type_specifier (C, &o, sp))
+ return 0;
+ do
+ {
+ slang_variable *var;
+
+ st->fields->variables = (slang_variable *) slang_alloc_realloc (st->fields->variables,
+ st->fields->num_variables * sizeof (slang_variable),
+ (st->fields->num_variables + 1) * sizeof (slang_variable));
+ if (st->fields->variables == NULL)
+ {
+ slang_info_log_memory (C->L);
+ return 0;
+ }
+ var = &st->fields->variables[st->fields->num_variables];
+ if (!slang_variable_construct (var))
+ return 0;
+ st->fields->num_variables++;
+ if (!slang_type_specifier_copy (&var->type.specifier, sp))
+ return 0;
+ if (!parse_struct_field_var (C, &o, var))
+ return 0;
+ }
+ while (*C->I++ != FIELD_NONE);
+
+ return 1;
+}
+
+static int parse_struct (slang_parse_ctx *C, slang_output_ctx *O, slang_struct **st)
+{
+ slang_atom a_name;
+ const char *name;
+
+ /* parse struct name (if any) and make sure it is unique in current scope */
+ a_name = parse_identifier (C);
+ if (a_name == SLANG_ATOM_NULL)
+ return 0;
+ name = slang_atom_pool_id (C->atoms, a_name);
+ if (name[0] != '\0' && slang_struct_scope_find (O->structs, a_name, 0) != NULL)
+ {
+ slang_info_log_error (C->L, "%s: duplicate type name", name);
+ return 0;
+ }
+
+ /* set-up a new struct */
+ *st = (slang_struct *) slang_alloc_malloc (sizeof (slang_struct));
+ if (*st == NULL)
+ {
+ slang_info_log_memory (C->L);
+ return 0;
+ }
+ if (!slang_struct_construct (*st))
+ {
+ slang_alloc_free (*st);
+ *st = NULL;
+ slang_info_log_memory (C->L);
+ return 0;
+ }
+ (**st).a_name = a_name;
+ (**st).structs->outer_scope = O->structs;
+
+ /* parse individual struct fields */
+ do
+ {
+ slang_type_specifier sp;
+
+ if (!slang_type_specifier_construct (&sp))
+ return 0;
+ if (!parse_struct_field (C, O, *st, &sp))
+ {
+ slang_type_specifier_destruct (&sp);
+ return 0;
+ }
+ }
+ while (*C->I++ != FIELD_NONE);
+
+ /* if named struct, copy it to current scope */
+ if (name[0] != '\0')
+ {
+ slang_struct *s;
+
+ O->structs->structs = (slang_struct *) slang_alloc_realloc (O->structs->structs,
+ O->structs->num_structs * sizeof (slang_struct),
+ (O->structs->num_structs + 1) * sizeof (slang_struct));
+ if (O->structs->structs == NULL)
+ {
+ slang_info_log_memory (C->L);
+ return 0;
+ }
+ s = &O->structs->structs[O->structs->num_structs];
+ if (!slang_struct_construct (s))
+ return 0;
+ O->structs->num_structs++;
+ if (!slang_struct_copy (s, *st))
+ return 0;
+ }
+
+ return 1;
}
/* type qualifier */
@@ -632,24 +632,24 @@ static int parse_type_specifier (slang_parse_ctx *C, slang_output_ctx *O, slang_
spec->type = slang_spec_sampler2DShadow;
break;
case TYPE_SPECIFIER_STRUCT:
- spec->type = slang_spec_struct;
+ spec->type = slang_spec_struct;
if (!parse_struct (C, O, &spec->_struct))
return 0;
break;
- case TYPE_SPECIFIER_TYPENAME:
+ case TYPE_SPECIFIER_TYPENAME:
spec->type = slang_spec_struct;
{
slang_atom a_name;
- slang_struct *stru;
+ slang_struct *stru;
- a_name = parse_identifier (C);
+ a_name = parse_identifier (C);
if (a_name == NULL)
- return 0;
+ return 0;
stru = slang_struct_scope_find (O->structs, a_name, 1);
if (stru == NULL)
{
- slang_info_log_error (C->L, "%s: undeclared type name",
+ slang_info_log_error (C->L, "%s: undeclared type name",
slang_atom_pool_id (C->atoms, a_name));
return 0;
}
@@ -676,7 +676,7 @@ static int parse_type_specifier (slang_parse_ctx *C, slang_output_ctx *O, slang_
return 1;
}
-static int parse_fully_specified_type (slang_parse_ctx *C, slang_output_ctx *O,
+static int parse_fully_specified_type (slang_parse_ctx *C, slang_output_ctx *O,
slang_fully_specified_type *type)
{
if (!parse_type_qualifier (C, &type->qualifier))
@@ -748,10 +748,10 @@ static int parse_fully_specified_type (slang_parse_ctx *C, slang_output_ctx *O,
#define OP_POSTINCREMENT 60
#define OP_POSTDECREMENT 61
-static int parse_child_operation (slang_parse_ctx *C, slang_output_ctx *O, slang_operation *oper,
+static int parse_child_operation (slang_parse_ctx *C, slang_output_ctx *O, slang_operation *oper,
int statement)
-{
- slang_operation *ch;
+{
+ slang_operation *ch;
oper->children = (slang_operation *) slang_alloc_realloc (oper->children,
oper->num_children * sizeof (slang_operation),
@@ -760,7 +760,7 @@ static int parse_child_operation (slang_parse_ctx *C, slang_output_ctx *O, slang
{
slang_info_log_memory (C->L);
return 0;
- }
+ }
ch = &oper->children[oper->num_children];
if (!slang_operation_construct (ch))
{
@@ -780,7 +780,7 @@ static int parse_statement (slang_parse_ctx *C, slang_output_ctx *O, slang_opera
oper->locals->outer_scope = O->vars;
switch (*C->I++)
{
- case OP_BLOCK_BEGIN_NO_NEW_SCOPE:
+ case OP_BLOCK_BEGIN_NO_NEW_SCOPE:
/* parse child statements, do not create new variable scope */
oper->type = slang_oper_block_no_new_scope;
while (*C->I != OP_END)
@@ -788,32 +788,32 @@ static int parse_statement (slang_parse_ctx *C, slang_output_ctx *O, slang_opera
return 0;
C->I++;
break;
- case OP_BLOCK_BEGIN_NEW_SCOPE:
+ case OP_BLOCK_BEGIN_NEW_SCOPE:
/* parse child statements, create new variable scope */
- {
- slang_output_ctx o = *O;
-
- oper->type = slang_oper_block_new_scope;
+ {
+ slang_output_ctx o = *O;
+
+ oper->type = slang_oper_block_new_scope;
o.vars = oper->locals;
- while (*C->I != OP_END)
+ while (*C->I != OP_END)
if (!parse_child_operation (C, &o, oper, 1))
- return 0;
- C->I++;
+ return 0;
+ C->I++;
}
break;
- case OP_DECLARE:
+ case OP_DECLARE:
/* local variable declaration, individual declarators are stored as children identifiers */
oper->type = slang_oper_variable_decl;
{
- const unsigned int first_var = O->vars->num_variables;
-
+ const unsigned int first_var = O->vars->num_variables;
+
/* parse the declaration, note that there can be zero or more than one declarators */
if (!parse_declaration (C, O))
return 0;
if (first_var < O->vars->num_variables)
{
const unsigned int num_vars = O->vars->num_variables - first_var;
- unsigned int i;
+ unsigned int i;
oper->children = (slang_operation *) slang_alloc_malloc (num_vars * sizeof (
slang_operation));
@@ -830,7 +830,7 @@ static int parse_statement (slang_parse_ctx *C, slang_output_ctx *O, slang_opera
}
for (i = first_var; i < O->vars->num_variables; i++)
{
- slang_operation *o = &oper->children[i - first_var];
+ slang_operation *o = &oper->children[i - first_var];
o->type = slang_oper_identifier;
o->locals->outer_scope = O->vars;
@@ -839,10 +839,10 @@ static int parse_statement (slang_parse_ctx *C, slang_output_ctx *O, slang_opera
}
}
break;
- case OP_ASM:
+ case OP_ASM:
/* the __asm statement, parse the mnemonic and all its arguments as expressions */
- oper->type = slang_oper_asm;
- oper->a_id = parse_identifier (C);
+ oper->type = slang_oper_asm;
+ oper->a_id = parse_identifier (C);
if (oper->a_id == SLANG_ATOM_NULL)
return 0;
while (*C->I != OP_END)
@@ -879,15 +879,15 @@ static int parse_statement (slang_parse_ctx *C, slang_output_ctx *O, slang_opera
return 0;
break;
case OP_WHILE:
- {
- slang_output_ctx o = *O;
-
- oper->type = slang_oper_while;
+ {
+ slang_output_ctx o = *O;
+
+ oper->type = slang_oper_while;
o.vars = oper->locals;
if (!parse_child_operation (C, &o, oper, 1))
return 0;
if (!parse_child_operation (C, &o, oper, 1))
- return 0;
+ return 0;
}
break;
case OP_DO:
@@ -898,10 +898,10 @@ static int parse_statement (slang_parse_ctx *C, slang_output_ctx *O, slang_opera
return 0;
break;
case OP_FOR:
- {
- slang_output_ctx o = *O;
-
- oper->type = slang_oper_for;
+ {
+ slang_output_ctx o = *O;
+
+ oper->type = slang_oper_for;
o.vars = oper->locals;
if (!parse_child_operation (C, &o, oper, 1))
return 0;
@@ -910,41 +910,41 @@ static int parse_statement (slang_parse_ctx *C, slang_output_ctx *O, slang_opera
if (!parse_child_operation (C, &o, oper, 0))
return 0;
if (!parse_child_operation (C, &o, oper, 1))
- return 0;
+ return 0;
}
break;
default:
return 0;
}
return 1;
-}
-
-static int handle_nary_expression (slang_parse_ctx *C, slang_operation *op, slang_operation **ops,
- unsigned int *total_ops, unsigned int n)
-{
- unsigned int i;
-
- op->children = (slang_operation *) slang_alloc_malloc (n * sizeof (slang_operation));
- if (op->children == NULL)
- {
- slang_info_log_memory (C->L);
- return 0;
- }
- op->num_children = n;
-
- for (i = 0; i < n; i++)
- op->children[i] = (*ops)[*total_ops - (n + 1 - i)];
- (*ops)[*total_ops - (n + 1)] = (*ops)[*total_ops - 1];
- *total_ops -= n;
-
- *ops = (slang_operation *) slang_alloc_realloc (*ops, (*total_ops + n) * sizeof (slang_operation),
- *total_ops * sizeof (slang_operation));
- if (*ops == NULL)
- {
- slang_info_log_memory (C->L);
- return 0;
- }
- return 1;
+}
+
+static int handle_nary_expression (slang_parse_ctx *C, slang_operation *op, slang_operation **ops,
+ unsigned int *total_ops, unsigned int n)
+{
+ unsigned int i;
+
+ op->children = (slang_operation *) slang_alloc_malloc (n * sizeof (slang_operation));
+ if (op->children == NULL)
+ {
+ slang_info_log_memory (C->L);
+ return 0;
+ }
+ op->num_children = n;
+
+ for (i = 0; i < n; i++)
+ op->children[i] = (*ops)[*total_ops - (n + 1 - i)];
+ (*ops)[*total_ops - (n + 1)] = (*ops)[*total_ops - 1];
+ *total_ops -= n;
+
+ *ops = (slang_operation *) slang_alloc_realloc (*ops, (*total_ops + n) * sizeof (slang_operation),
+ *total_ops * sizeof (slang_operation));
+ if (*ops == NULL)
+ {
+ slang_info_log_memory (C->L);
+ return 0;
+ }
+ return 1;
}
static int is_constructor_name (const char *name, slang_atom a_name, slang_struct_scope *structs)
@@ -963,8 +963,8 @@ static int parse_expression (slang_parse_ctx *C, slang_output_ctx *O, slang_oper
while (*C->I != OP_END)
{
slang_operation *op;
- const unsigned int op_code = *C->I++;
-
+ const unsigned int op_code = *C->I++;
+
/* allocate default operation, becomes a no-op if not used */
ops = (slang_operation *) slang_alloc_realloc (ops,
num_ops * sizeof (slang_operation), (num_ops + 1) * sizeof (slang_operation));
@@ -980,7 +980,7 @@ static int parse_expression (slang_parse_ctx *C, slang_output_ctx *O, slang_oper
return 0;
}
num_ops++;
- op->locals->outer_scope = O->vars;
+ op->locals->outer_scope = O->vars;
switch (op_code)
{
@@ -1006,7 +1006,7 @@ static int parse_expression (slang_parse_ctx *C, slang_output_ctx *O, slang_oper
break;
case OP_PUSH_IDENTIFIER:
op->type = slang_oper_identifier;
- op->a_id = parse_identifier (C);
+ op->a_id = parse_identifier (C);
if (op->a_id == SLANG_ATOM_NULL)
return 0;
break;
@@ -1155,28 +1155,28 @@ static int parse_expression (slang_parse_ctx *C, slang_output_ctx *O, slang_oper
break;
case OP_CALL:
op->type = slang_oper_call;
- op->a_id = parse_identifier (C);
+ op->a_id = parse_identifier (C);
if (op->a_id == SLANG_ATOM_NULL)
return 0;
while (*C->I != OP_END)
if (!parse_child_operation (C, O, op, 0))
return 0;
C->I++;
- if (!C->parsing_builtin && !slang_function_scope_find_by_name (O->funs, op->a_id, 1))
- {
- const char *id;
-
+ if (!C->parsing_builtin && !slang_function_scope_find_by_name (O->funs, op->a_id, 1))
+ {
+ const char *id;
+
id = slang_atom_pool_id (C->atoms, op->a_id);
if (!is_constructor_name (id, op->a_id, O->structs))
{
slang_info_log_error (C->L, "%s: undeclared function name", id);
return 0;
- }
+ }
}
break;
case OP_FIELD:
op->type = slang_oper_field;
- op->a_id = parse_identifier (C);
+ op->a_id = parse_identifier (C);
if (op->a_id == SLANG_ATOM_NULL)
return 0;
if (!handle_nary_expression (C, op, &ops, &num_ops, 1))
@@ -1196,7 +1196,7 @@ static int parse_expression (slang_parse_ctx *C, slang_output_ctx *O, slang_oper
return 0;
}
}
- C->I++;
+ C->I++;
*oper = *ops;
slang_alloc_free (ops);
@@ -1212,12 +1212,12 @@ static int parse_expression (slang_parse_ctx *C, slang_output_ctx *O, slang_oper
#define PARAMETER_ARRAY_NOT_PRESENT 0
#define PARAMETER_ARRAY_PRESENT 1
-static int parse_parameter_declaration (slang_parse_ctx *C, slang_output_ctx *O,
+static int parse_parameter_declaration (slang_parse_ctx *C, slang_output_ctx *O,
slang_variable *param)
{
- slang_storage_aggregate agg;
-
- /* parse and validate the parameter's type qualifiers (there can be two at most) because
+ slang_storage_aggregate agg;
+
+ /* parse and validate the parameter's type qualifiers (there can be two at most) because
* not all combinations are valid */
if (!parse_type_qualifier (C, &param->type.qualifier))
return 0;
@@ -1250,15 +1250,15 @@ static int parse_parameter_declaration (slang_parse_ctx *C, slang_output_ctx *O,
break;
default:
return 0;
- }
-
+ }
+
/* parse parameter's type specifier and name */
if (!parse_type_specifier (C, O, &param->type.specifier))
- return 0;
+ return 0;
param->a_name = parse_identifier (C);
- if (param->a_name == SLANG_ATOM_NULL)
- return 0;
-
+ if (param->a_name == SLANG_ATOM_NULL)
+ return 0;
+
/* if the parameter is an array, parse its size (the size must be explicitly defined */
if (*C->I++ == PARAMETER_ARRAY_PRESENT)
{
@@ -1276,22 +1276,22 @@ static int parse_parameter_declaration (slang_parse_ctx *C, slang_output_ctx *O,
return 0;
}
if (!parse_expression (C, O, param->array_size))
- return 0;
+ return 0;
/* TODO: execute the array_size */
- }
-
- /* calculate the parameter size */
- if (!slang_storage_aggregate_construct (&agg))
- return 0;
- if (!_slang_aggregate_variable (&agg, &param->type.specifier, param->array_size, O->funs,
- O->structs, O->vars, O->machine, O->assembly, C->atoms))
- {
- slang_storage_aggregate_destruct (&agg);
- return 0;
- }
- param->size = _slang_sizeof_aggregate (&agg);
- slang_storage_aggregate_destruct (&agg);
- /* TODO: allocate the local address here? */
+ }
+
+ /* calculate the parameter size */
+ if (!slang_storage_aggregate_construct (&agg))
+ return 0;
+ if (!_slang_aggregate_variable (&agg, &param->type.specifier, param->array_size, O->funs,
+ O->structs, O->vars, O->machine, O->assembly, C->atoms))
+ {
+ slang_storage_aggregate_destruct (&agg);
+ return 0;
+ }
+ param->size = _slang_sizeof_aggregate (&agg);
+ slang_storage_aggregate_destruct (&agg);
+ /* TODO: allocate the local address here? */
return 1;
}
@@ -1372,9 +1372,9 @@ static const struct {
static slang_atom parse_operator_name (slang_parse_ctx *C)
{
- unsigned int i;
+ unsigned int i;
- for (i = 0; i < sizeof (operator_names) / sizeof (*operator_names); i++)
+ for (i = 0; i < sizeof (operator_names) / sizeof (*operator_names); i++)
{
if (operator_names[i].o_code == (unsigned int) (*C->I))
{
@@ -1386,23 +1386,23 @@ static slang_atom parse_operator_name (slang_parse_ctx *C)
}
C->I++;
return atom;
- }
+ }
}
return 0;
}
static int parse_function_prototype (slang_parse_ctx *C, slang_output_ctx *O, slang_function *func)
-{
+{
/* parse function type and name */
if (!parse_fully_specified_type (C, O, &func->header.type))
return 0;
switch (*C->I++)
{
- case FUNCTION_ORDINARY:
+ case FUNCTION_ORDINARY:
func->kind = slang_func_ordinary;
func->header.a_name = parse_identifier (C);
- if (func->header.a_name == SLANG_ATOM_NULL)
- return 0;
+ if (func->header.a_name == SLANG_ATOM_NULL)
+ return 0;
break;
case FUNCTION_CONSTRUCTOR:
func->kind = slang_func_constructor;
@@ -1418,18 +1418,18 @@ static int parse_function_prototype (slang_parse_ctx *C, slang_output_ctx *O, sl
break;
case FUNCTION_OPERATOR:
func->kind = slang_func_operator;
- func->header.a_name = parse_operator_name (C);
+ func->header.a_name = parse_operator_name (C);
if (func->header.a_name == SLANG_ATOM_NULL)
return 0;
break;
default:
return 0;
- }
-
+ }
+
/* parse function parameters */
while (*C->I++ == PARAMETER_NEXT)
- {
- slang_variable *p;
+ {
+ slang_variable *p;
func->parameters->variables = (slang_variable *) slang_alloc_realloc (
func->parameters->variables,
@@ -1439,31 +1439,31 @@ static int parse_function_prototype (slang_parse_ctx *C, slang_output_ctx *O, sl
{
slang_info_log_memory (C->L);
return 0;
- }
+ }
p = &func->parameters->variables[func->parameters->num_variables];
- if (!slang_variable_construct (p))
- return 0;
+ if (!slang_variable_construct (p))
+ return 0;
func->parameters->num_variables++;
if (!parse_parameter_declaration (C, O, p))
return 0;
- }
-
- /* function formal parameters and local variables share the same scope, so save
- * the information about param count in a seperate place
- * also link the scope to the global variable scope so when a given identifier is not
+ }
+
+ /* function formal parameters and local variables share the same scope, so save
+ * the information about param count in a seperate place
+ * also link the scope to the global variable scope so when a given identifier is not
* found here, the search process continues in the global space */
- func->param_count = func->parameters->num_variables;
+ func->param_count = func->parameters->num_variables;
func->parameters->outer_scope = O->vars;
return 1;
}
static int parse_function_definition (slang_parse_ctx *C, slang_output_ctx *O, slang_function *func)
-{
- slang_output_ctx o = *O;
+{
+ slang_output_ctx o = *O;
if (!parse_function_prototype (C, O, func))
- return 0;
-
+ return 0;
+
/* create function's body operation */
func->body = (slang_operation *) slang_alloc_malloc (sizeof (slang_operation));
if (func->body == NULL)
@@ -1477,110 +1477,109 @@ static int parse_function_definition (slang_parse_ctx *C, slang_output_ctx *O, s
func->body = NULL;
slang_info_log_memory (C->L);
return 0;
- }
-
- /* to parse the body the parse context is modified in order to capture parsed variables
- * into function's local variable scope */
- C->global_scope = 0;
+ }
+
+ /* to parse the body the parse context is modified in order to capture parsed variables
+ * into function's local variable scope */
+ C->global_scope = 0;
o.vars = func->parameters;
if (!parse_statement (C, &o, func->body))
- return 0;
+ return 0;
C->global_scope = 1;
return 1;
-}
-
-static int initialize_global (slang_assemble_ctx *A, slang_variable *var)
-{
- slang_assembly_file_restore_point point;
- slang_machine mach;
- slang_assembly_local_info info;
- slang_operation op_id, op_assign;
- int result;
- slang_assembly_flow_control flow;
- slang_assembly_stack_info stk;
-
- /* save the current assembly */
- if (!slang_assembly_file_restore_point_save (A->file, &point))
- return 0;
-
- /* setup the machine */
- mach = *A->mach;
- mach.ip = A->file->count;
-
- /* allocate local storage for expression */
- info.ret_size = 0;
- info.addr_tmp = 0;
- info.swizzle_tmp = 4;
- if (!slang_assembly_file_push_label (A->file, slang_asm_local_alloc, 20))
- return 0;
- if (!slang_assembly_file_push_label (A->file, slang_asm_enter, 20))
- return 0;
-
- /* construct the left side of assignment */
- if (!slang_operation_construct (&op_id))
- return 0;
- op_id.type = slang_oper_identifier;
- op_id.a_id = var->a_name;
-
- /* put the variable into operation's scope */
- op_id.locals->variables = (slang_variable *) slang_alloc_malloc (sizeof (slang_variable));
- if (op_id.locals->variables == NULL)
- {
- slang_operation_destruct (&op_id);
- return 0;
- }
- op_id.locals->num_variables = 1;
- op_id.locals->variables[0] = *var;
-
- /* construct the assignment expression */
- if (!slang_operation_construct (&op_assign))
- {
- op_id.locals->num_variables = 0;
- slang_operation_destruct (&op_id);
- return 0;
- }
- op_assign.type = slang_oper_assign;
- op_assign.children = (slang_operation *) slang_alloc_malloc (2 * sizeof (slang_operation));
- if (op_assign.children == NULL)
- {
- slang_operation_destruct (&op_assign);
- op_id.locals->num_variables = 0;
- slang_operation_destruct (&op_id);
- return 0;
- }
- op_assign.num_children = 2;
- op_assign.children[0] = op_id;
- op_assign.children[1] = *var->initializer;
-
- /* insert the actual expression */
- result = _slang_assemble_operation (A->file, &op_assign, 0, &flow, &A->space, &info, &stk, A->mach, A->atoms);
-
- /* carefully destroy the operations */
- op_assign.num_children = 0;
- slang_alloc_free (op_assign.children);
- op_assign.children = NULL;
- slang_operation_destruct (&op_assign);
- op_id.locals->num_variables = 0;
- slang_operation_destruct (&op_id);
-
- if (!result)
- return 0;
- if (!slang_assembly_file_push (A->file, slang_asm_exit))
- return 0;
-
- /* execute the expression */
- if (!_slang_execute2 (A->file, &mach))
- return 0;
-
- /* restore the old assembly */
- if (!slang_assembly_file_restore_point_load (A->file, &point))
- return 0;
-
- /* now we copy the contents of the initialized variable back to the original machine */
- _mesa_memcpy ((GLubyte *) A->mach->mem + var->address, (GLubyte *) mach.mem + var->address,
- var->size);
-
- return 1;
+}
+
+static GLboolean initialize_global (slang_assemble_ctx *A, slang_variable *var)
+{
+ slang_assembly_file_restore_point point;
+ slang_machine mach;
+ slang_assembly_local_info save_local = A->local;
+ slang_operation op_id, op_assign;
+ GLboolean result;
+
+ /* save the current assembly */
+ if (!slang_assembly_file_restore_point_save (A->file, &point))
+ return GL_FALSE;
+
+ /* setup the machine */
+ mach = *A->mach;
+ mach.ip = A->file->count;
+
+ /* allocate local storage for expression */
+ A->local.ret_size = 0;
+ A->local.addr_tmp = 0;
+ A->local.swizzle_tmp = 4;
+ if (!slang_assembly_file_push_label (A->file, slang_asm_local_alloc, 20))
+ return GL_FALSE;
+ if (!slang_assembly_file_push_label (A->file, slang_asm_enter, 20))
+ return GL_FALSE;
+
+ /* construct the left side of assignment */
+ if (!slang_operation_construct (&op_id))
+ return GL_FALSE;
+ op_id.type = slang_oper_identifier;
+ op_id.a_id = var->a_name;
+
+ /* put the variable into operation's scope */
+ op_id.locals->variables = (slang_variable *) slang_alloc_malloc (sizeof (slang_variable));
+ if (op_id.locals->variables == NULL)
+ {
+ slang_operation_destruct (&op_id);
+ return GL_FALSE;
+ }
+ op_id.locals->num_variables = 1;
+ op_id.locals->variables[0] = *var;
+
+ /* construct the assignment expression */
+ if (!slang_operation_construct (&op_assign))
+ {
+ op_id.locals->num_variables = 0;
+ slang_operation_destruct (&op_id);
+ return GL_FALSE;
+ }
+ op_assign.type = slang_oper_assign;
+ op_assign.children = (slang_operation *) slang_alloc_malloc (2 * sizeof (slang_operation));
+ if (op_assign.children == NULL)
+ {
+ slang_operation_destruct (&op_assign);
+ op_id.locals->num_variables = 0;
+ slang_operation_destruct (&op_id);
+ return GL_FALSE;
+ }
+ op_assign.num_children = 2;
+ op_assign.children[0] = op_id;
+ op_assign.children[1] = *var->initializer;
+
+ /* insert the actual expression */
+ result = _slang_assemble_operation_ (A, &op_assign, slang_ref_forbid);
+
+ /* carefully destroy the operations */
+ op_assign.num_children = 0;
+ slang_alloc_free (op_assign.children);
+ op_assign.children = NULL;
+ slang_operation_destruct (&op_assign);
+ op_id.locals->num_variables = 0;
+ slang_operation_destruct (&op_id);
+
+ if (!result)
+ return GL_FALSE;
+ if (!slang_assembly_file_push (A->file, slang_asm_exit))
+ return GL_FALSE;
+
+ /* execute the expression */
+ if (!_slang_execute2 (A->file, &mach))
+ return GL_FALSE;
+
+ /* restore the old assembly */
+ if (!slang_assembly_file_restore_point_load (A->file, &point))
+ return GL_FALSE;
+ A->local = save_local;
+
+ /* now we copy the contents of the initialized variable back to the original machine */
+ _mesa_memcpy ((GLubyte *) A->mach->mem + var->address, (GLubyte *) mach.mem + var->address,
+ var->size);
+
+ return GL_TRUE;
}
/* init declarator list */
@@ -1594,15 +1593,15 @@ static int initialize_global (slang_assemble_ctx *A, slang_variable *var)
#define VARIABLE_ARRAY_EXPLICIT 3
#define VARIABLE_ARRAY_UNKNOWN 4
-static int parse_init_declarator (slang_parse_ctx *C, slang_output_ctx *O,
+static int parse_init_declarator (slang_parse_ctx *C, slang_output_ctx *O,
const slang_fully_specified_type *type)
{
- slang_variable *var;
-
- /* empty init declatator (without name, e.g. "float ;") */
+ slang_variable *var;
+
+ /* empty init declatator (without name, e.g. "float ;") */
if (*C->I++ == VARIABLE_NONE)
- return 1;
-
+ return 1;
+
/* make room for the new variable and initialize it */
O->vars->variables = (slang_variable *) slang_alloc_realloc (O->vars->variables,
O->vars->num_variables * sizeof (slang_variable),
@@ -1613,25 +1612,25 @@ static int parse_init_declarator (slang_parse_ctx *C, slang_output_ctx *O,
return 0;
}
var = &O->vars->variables[O->vars->num_variables];
- if (!slang_variable_construct (var))
- return 0;
- O->vars->num_variables++;
-
- /* copy the declarator qualifier type, parse the identifier */
+ if (!slang_variable_construct (var))
+ return 0;
+ O->vars->num_variables++;
+
+ /* copy the declarator qualifier type, parse the identifier */
var->global = C->global_scope;
var->type.qualifier = type->qualifier;
var->a_name = parse_identifier (C);
- if (var->a_name == SLANG_ATOM_NULL)
- return 0;
+ if (var->a_name == SLANG_ATOM_NULL)
+ return 0;
switch (*C->I++)
{
- case VARIABLE_NONE:
+ case VARIABLE_NONE:
/* simple variable declarator - just copy the specifier */
if (!slang_type_specifier_copy (&var->type.specifier, &type->specifier))
return 0;
break;
- case VARIABLE_INITIALIZER:
+ case VARIABLE_INITIALIZER:
/* initialized variable - copy the specifier and parse the expression */
if (!slang_type_specifier_copy (&var->type.specifier, &type->specifier))
return 0;
@@ -1679,12 +1678,12 @@ static int parse_init_declarator (slang_parse_ctx *C, slang_output_ctx *O,
slang_info_log_memory (C->L);
return 0;
}
- if (!slang_type_specifier_construct (var->type.specifier._array))
- {
- slang_alloc_free (var->type.specifier._array);
- var->type.specifier._array = NULL;
- slang_info_log_memory (C->L);
- return 0;
+ if (!slang_type_specifier_construct (var->type.specifier._array))
+ {
+ slang_alloc_free (var->type.specifier._array);
+ var->type.specifier._array = NULL;
+ slang_info_log_memory (C->L);
+ return 0;
}
if (!slang_type_specifier_copy (var->type.specifier._array, &type->specifier))
return 0;
@@ -1706,39 +1705,39 @@ static int parse_init_declarator (slang_parse_ctx *C, slang_output_ctx *O,
break;
default:
return 0;
- }
-
+ }
+
/* allocate global address space for a variable with a known size */
if (C->global_scope && !(var->type.specifier.type == slang_spec_array && var->array_size == NULL))
{
slang_storage_aggregate agg;
- if (!slang_storage_aggregate_construct (&agg))
+ if (!slang_storage_aggregate_construct (&agg))
return 0;
if (!_slang_aggregate_variable (&agg, &var->type.specifier, var->array_size, O->funs,
O->structs, O->vars, O->machine, O->assembly, C->atoms))
{
slang_storage_aggregate_destruct (&agg);
return 0;
- }
- var->size = _slang_sizeof_aggregate (&agg);
- slang_storage_aggregate_destruct (&agg);
+ }
+ var->size = _slang_sizeof_aggregate (&agg);
+ slang_storage_aggregate_destruct (&agg);
var->address = slang_var_pool_alloc (O->global_pool, var->size);
- }
-
- /* initialize global variable */
- if (C->global_scope && var->initializer != NULL)
- {
- slang_assemble_ctx A;
-
- A.file = O->assembly;
- A.mach = O->machine;
- A.atoms = C->atoms;
- A.space.funcs = O->funs;
- A.space.structs = O->structs;
- A.space.vars = O->vars;
- if (!initialize_global (&A, var))
- return 0;
+ }
+
+ /* initialize global variable */
+ if (C->global_scope && var->initializer != NULL)
+ {
+ slang_assemble_ctx A;
+
+ A.file = O->assembly;
+ A.mach = O->machine;
+ A.atoms = C->atoms;
+ A.space.funcs = O->funs;
+ A.space.structs = O->structs;
+ A.space.vars = O->vars;
+ if (!initialize_global (&A, var))
+ return 0;
}
return 1;
}
@@ -1746,16 +1745,16 @@ static int parse_init_declarator (slang_parse_ctx *C, slang_output_ctx *O,
static int parse_init_declarator_list (slang_parse_ctx *C, slang_output_ctx *O)
{
slang_fully_specified_type type;
-
+
/* parse the fully specified type, common to all declarators */
- if (!slang_fully_specified_type_construct (&type))
+ if (!slang_fully_specified_type_construct (&type))
return 0;
if (!parse_fully_specified_type (C, O, &type))
{
slang_fully_specified_type_destruct (&type);
return 0;
- }
-
+ }
+
/* parse declarators, pass-in the parsed type */
do
{
@@ -1765,19 +1764,19 @@ static int parse_init_declarator_list (slang_parse_ctx *C, slang_output_ctx *O)
return 0;
}
}
- while (*C->I++ == DECLARATOR_NEXT);
+ while (*C->I++ == DECLARATOR_NEXT);
slang_fully_specified_type_destruct (&type);
return 1;
}
-static int parse_function (slang_parse_ctx *C, slang_output_ctx *O, int definition,
+static int parse_function (slang_parse_ctx *C, slang_output_ctx *O, int definition,
slang_function **parsed_func_ret)
{
slang_function parsed_func, *found_func;
/* parse function definition/declaration */
- if (!slang_function_construct (&parsed_func))
+ if (!slang_function_construct (&parsed_func))
return 0;
if (definition)
{
@@ -1803,7 +1802,7 @@ static int parse_function (slang_parse_ctx *C, slang_output_ctx *O, int definiti
{
/* add the parsed function to the function list */
O->funs->functions = (slang_function *) slang_alloc_realloc (O->funs->functions,
- O->funs->num_functions * sizeof (slang_function),
+ O->funs->num_functions * sizeof (slang_function),
(O->funs->num_functions + 1) * sizeof (slang_function));
if (O->funs->functions == NULL)
{
@@ -1821,18 +1820,18 @@ static int parse_function (slang_parse_ctx *C, slang_output_ctx *O, int definiti
{
/* TODO: check function return type qualifiers and specifiers */
if (definition)
- {
+ {
if (found_func->body != NULL)
{
slang_info_log_error (C->L, "%s: function already has a body",
slang_atom_pool_id (C->atoms, parsed_func.header.a_name));
slang_function_destruct (&parsed_func);
return 0;
- }
-
- /* destroy the existing function declaration and replace it with the new one,
- * remember to save the fixup table */
- parsed_func.fixups = found_func->fixups;
+ }
+
+ /* destroy the existing function declaration and replace it with the new one,
+ * remember to save the fixup table */
+ parsed_func.fixups = found_func->fixups;
slang_fixup_table_init (&found_func->fixups);
slang_function_destruct (found_func);
*found_func = parsed_func;
@@ -1850,15 +1849,15 @@ static int parse_function (slang_parse_ctx *C, slang_output_ctx *O, int definiti
/* assemble the parsed function */
{
slang_assemble_ctx A;
-
- A.file = O->assembly;
- A.mach = O->machine;
- A.atoms = C->atoms;
+
+ A.file = O->assembly;
+ A.mach = O->machine;
+ A.atoms = C->atoms;
A.space.funcs = O->funs;
A.space.structs = O->structs;
- A.space.vars = O->vars;
- if (!_slang_assemble_function (&A, *parsed_func_ret))
- return 0;
+ A.space.vars = O->vars;
+ if (!_slang_assemble_function (&A, *parsed_func_ret))
+ return 0;
}
return 1;
}
@@ -1875,12 +1874,12 @@ static int parse_declaration (slang_parse_ctx *C, slang_output_ctx *O)
if (!parse_init_declarator_list (C, O))
return 0;
break;
- case DECLARATION_FUNCTION_PROTOTYPE:
- {
- slang_function *dummy_func;
+ case DECLARATION_FUNCTION_PROTOTYPE:
+ {
+ slang_function *dummy_func;
if (!parse_function (C, O, 0, &dummy_func))
- return 0;
+ return 0;
}
break;
default:
@@ -1895,28 +1894,28 @@ static int parse_declaration (slang_parse_ctx *C, slang_output_ctx *O)
#define EXTERNAL_DECLARATION 2
static int parse_translation_unit (slang_parse_ctx *C, slang_translation_unit *unit)
-{
- slang_output_ctx o;
-
- /* setup output context */
- o.funs = &unit->functions;
- o.structs = &unit->structs;
- o.vars = &unit->globals;
- o.assembly = unit->assembly;
- o.global_pool = unit->global_pool;
- o.machine = unit->machine;
-
+{
+ slang_output_ctx o;
+
+ /* setup output context */
+ o.funs = &unit->functions;
+ o.structs = &unit->structs;
+ o.vars = &unit->globals;
+ o.assembly = unit->assembly;
+ o.global_pool = unit->global_pool;
+ o.machine = unit->machine;
+
/* parse individual functions and declarations */
while (*C->I != EXTERNAL_NULL)
{
switch (*C->I++)
{
- case EXTERNAL_FUNCTION_DEFINITION:
- {
- slang_function *func;
+ case EXTERNAL_FUNCTION_DEFINITION:
+ {
+ slang_function *func;
if (!parse_function (C, &o, 1, &func))
- return 0;
+ return 0;
}
break;
case EXTERNAL_DECLARATION:
@@ -1929,39 +1928,39 @@ static int parse_translation_unit (slang_parse_ctx *C, slang_translation_unit *u
}
C->I++;
return 1;
-}
-
-#define BUILTIN_CORE 0
-#define BUILTIN_COMMON 1
-#define BUILTIN_TARGET 2
+}
+
+#define BUILTIN_CORE 0
+#define BUILTIN_COMMON 1
+#define BUILTIN_TARGET 2
#define BUILTIN_TOTAL 3
static int compile_binary (const byte *prod, slang_translation_unit *unit, slang_unit_type type,
- slang_info_log *log, slang_translation_unit *builtins, slang_assembly_file *file,
- slang_var_pool *pool, slang_machine *mach, slang_translation_unit *downlink,
+ slang_info_log *log, slang_translation_unit *builtins, slang_assembly_file *file,
+ slang_var_pool *pool, slang_machine *mach, slang_translation_unit *downlink,
slang_atom_pool *atoms)
{
- slang_parse_ctx C;
-
- /* create translation unit object */
- if (file != NULL)
- {
- if (!slang_translation_unit_construct2 (unit, file, pool, mach, atoms))
- return 0;
- unit->type = type;
+ slang_parse_ctx C;
+
+ /* create translation unit object */
+ if (file != NULL)
+ {
+ if (!slang_translation_unit_construct2 (unit, file, pool, mach, atoms))
+ return 0;
+ unit->type = type;
}
/* set-up parse context */
C.I = prod;
C.L = log;
- C.parsing_builtin = builtins == NULL;
- C.global_scope = 1;
- C.atoms = unit->atom_pool;
+ C.parsing_builtin = builtins == NULL;
+ C.global_scope = 1;
+ C.atoms = unit->atom_pool;
if (!check_revision (&C))
- {
- slang_translation_unit_destruct (unit);
- return 0;
+ {
+ slang_translation_unit_destruct (unit);
+ return 0;
}
if (downlink != NULL)
@@ -2000,9 +1999,9 @@ static int compile_with_grammar (grammar id, const char *source, slang_translati
slang_info_log_error (log, buf);
return 0;
}
-
+
/* syntax is okay - translate it to internal representation */
- if (!compile_binary (prod, unit, type, log, builtins, NULL, NULL, NULL,
+ if (!compile_binary (prod, unit, type, log, builtins, NULL, NULL, NULL,
&builtins[BUILTIN_TARGET], NULL))
{
grammar_alloc_free (prod);
@@ -2031,109 +2030,109 @@ static const byte slang_fragment_builtin_gc[] = {
static const byte slang_vertex_builtin_gc[] = {
#include "library/slang_vertex_builtin_gc.h"
-};
-
-static int compile (grammar *id, slang_translation_unit *builtin_units, int *compiled,
- const char *source, slang_translation_unit *unit, slang_unit_type type, slang_info_log *log)
-{
- slang_translation_unit *builtins = NULL;
-
- /* load slang grammar */
- *id = grammar_load_from_text ((const byte *) (slang_shader_syn));
- if (*id == 0)
- {
- byte buf[1024];
- int pos;
-
- grammar_get_last_error (buf, 1024, &pos);
- slang_info_log_error (log, (const char *) (buf));
- return 0;
- }
-
- /* set shader type - the syntax is slightly different for different shaders */
- if (type == slang_unit_fragment_shader || type == slang_unit_fragment_builtin)
- grammar_set_reg8 (*id, (const byte *) "shader_type", 1);
- else
- grammar_set_reg8 (*id, (const byte *) "shader_type", 2);
-
- /* enable language extensions */
- grammar_set_reg8 (*id, (const byte *) "parsing_builtin", 1);
-
- /* if parsing user-specified shader, load built-in library */
- if (type == slang_unit_fragment_shader || type == slang_unit_vertex_shader)
- {
- /* compile core functionality first */
- if (!compile_binary (slang_core_gc, &builtin_units[BUILTIN_CORE],
- slang_unit_fragment_builtin, log, NULL, unit->assembly, unit->global_pool,
- unit->machine, NULL, unit->atom_pool))
- return 0;
- compiled[BUILTIN_CORE] = 1;
-
- /* compile common functions and variables, link to core */
- if (!compile_binary (slang_common_builtin_gc, &builtin_units[BUILTIN_COMMON],
- slang_unit_fragment_builtin, log, NULL, unit->assembly, unit->global_pool,
- unit->machine, &builtin_units[BUILTIN_CORE], unit->atom_pool))
- return 0;
- compiled[BUILTIN_COMMON] = 1;
-
- /* compile target-specific functions and variables, link to common */
- if (type == slang_unit_fragment_shader)
- {
- if (!compile_binary (slang_fragment_builtin_gc, &builtin_units[BUILTIN_TARGET],
- slang_unit_fragment_builtin, log, NULL, unit->assembly, unit->global_pool,
- unit->machine, &builtin_units[BUILTIN_COMMON], unit->atom_pool))
- return 0;
- }
- else if (type == slang_unit_vertex_shader)
- {
- if (!compile_binary (slang_vertex_builtin_gc, &builtin_units[BUILTIN_TARGET],
- slang_unit_vertex_builtin, log, NULL, unit->assembly, unit->global_pool,
- unit->machine, &builtin_units[BUILTIN_COMMON], unit->atom_pool))
- return 0;
- }
- compiled[BUILTIN_TARGET] = 1;
-
- /* disable language extensions */
- grammar_set_reg8 (*id, (const byte *) "parsing_builtin", 0);
- builtins = builtin_units;
- }
-
- /* compile the actual shader - pass-in built-in library for external shader */
- if (!compile_with_grammar (*id, source, unit, type, log, builtins))
- return 0;
-
- return 1;
+};
+
+static int compile (grammar *id, slang_translation_unit *builtin_units, int *compiled,
+ const char *source, slang_translation_unit *unit, slang_unit_type type, slang_info_log *log)
+{
+ slang_translation_unit *builtins = NULL;
+
+ /* load slang grammar */
+ *id = grammar_load_from_text ((const byte *) (slang_shader_syn));
+ if (*id == 0)
+ {
+ byte buf[1024];
+ int pos;
+
+ grammar_get_last_error (buf, 1024, &pos);
+ slang_info_log_error (log, (const char *) (buf));
+ return 0;
+ }
+
+ /* set shader type - the syntax is slightly different for different shaders */
+ if (type == slang_unit_fragment_shader || type == slang_unit_fragment_builtin)
+ grammar_set_reg8 (*id, (const byte *) "shader_type", 1);
+ else
+ grammar_set_reg8 (*id, (const byte *) "shader_type", 2);
+
+ /* enable language extensions */
+ grammar_set_reg8 (*id, (const byte *) "parsing_builtin", 1);
+
+ /* if parsing user-specified shader, load built-in library */
+ if (type == slang_unit_fragment_shader || type == slang_unit_vertex_shader)
+ {
+ /* compile core functionality first */
+ if (!compile_binary (slang_core_gc, &builtin_units[BUILTIN_CORE],
+ slang_unit_fragment_builtin, log, NULL, unit->assembly, unit->global_pool,
+ unit->machine, NULL, unit->atom_pool))
+ return 0;
+ compiled[BUILTIN_CORE] = 1;
+
+ /* compile common functions and variables, link to core */
+ if (!compile_binary (slang_common_builtin_gc, &builtin_units[BUILTIN_COMMON],
+ slang_unit_fragment_builtin, log, NULL, unit->assembly, unit->global_pool,
+ unit->machine, &builtin_units[BUILTIN_CORE], unit->atom_pool))
+ return 0;
+ compiled[BUILTIN_COMMON] = 1;
+
+ /* compile target-specific functions and variables, link to common */
+ if (type == slang_unit_fragment_shader)
+ {
+ if (!compile_binary (slang_fragment_builtin_gc, &builtin_units[BUILTIN_TARGET],
+ slang_unit_fragment_builtin, log, NULL, unit->assembly, unit->global_pool,
+ unit->machine, &builtin_units[BUILTIN_COMMON], unit->atom_pool))
+ return 0;
+ }
+ else if (type == slang_unit_vertex_shader)
+ {
+ if (!compile_binary (slang_vertex_builtin_gc, &builtin_units[BUILTIN_TARGET],
+ slang_unit_vertex_builtin, log, NULL, unit->assembly, unit->global_pool,
+ unit->machine, &builtin_units[BUILTIN_COMMON], unit->atom_pool))
+ return 0;
+ }
+ compiled[BUILTIN_TARGET] = 1;
+
+ /* disable language extensions */
+ grammar_set_reg8 (*id, (const byte *) "parsing_builtin", 0);
+ builtins = builtin_units;
+ }
+
+ /* compile the actual shader - pass-in built-in library for external shader */
+ if (!compile_with_grammar (*id, source, unit, type, log, builtins))
+ return 0;
+
+ return 1;
}
-
+
int _slang_compile (const char *source, slang_translation_unit *unit, slang_unit_type type,
slang_info_log *log)
-{
+{
int success;
grammar id = 0;
-// slang_translation_unit builtin_units[BUILTIN_TOTAL];
- slang_translation_unit *builtin_units;
- int compiled[BUILTIN_TOTAL] = { 0 };
-
- /* create the main unit first */
- if (!slang_translation_unit_construct (unit))
- return 0;
+/* slang_translation_unit builtin_units[BUILTIN_TOTAL];*/
+ slang_translation_unit *builtin_units;
+ int compiled[BUILTIN_TOTAL] = { 0 };
+
+ /* create the main unit first */
+ if (!slang_translation_unit_construct (unit))
+ return 0;
unit->type = type;
-
+
builtin_units = (slang_translation_unit *) slang_alloc_malloc (BUILTIN_TOTAL * sizeof (slang_translation_unit));
success = compile (&id, builtin_units, compiled, source, unit, type, log);
- /* destroy built-in library */
+ /* destroy built-in library */
/* XXX: free with the unit */
/*if (type == slang_unit_fragment_shader || type == slang_unit_vertex_shader)
- {
- int i;
-
- for (i = 0; i < BUILTIN_TOTAL; i++)
+ {
+ int i;
+
+ for (i = 0; i < BUILTIN_TOTAL; i++)
if (compiled[i] != 0)
slang_translation_unit_destruct (&builtin_units[i]);
- }*/
+ }*/
if (id != 0)
- grammar_destroy (id);
+ grammar_destroy (id);
return success;
}
diff --git a/src/mesa/shader/slang/slang_compile_variable.c b/src/mesa/shader/slang/slang_compile_variable.c
index da3b24fb7ef..ff042bb65fc 100644
--- a/src/mesa/shader/slang/slang_compile_variable.c
+++ b/src/mesa/shader/slang/slang_compile_variable.c
@@ -352,9 +352,9 @@ int slang_variable_copy (slang_variable *x, const slang_variable *y)
return 1;
}
-slang_variable *_slang_locate_variable (slang_variable_scope *scope, slang_atom a_name, int all)
+slang_variable *_slang_locate_variable (slang_variable_scope *scope, slang_atom a_name, GLboolean all)
{
- unsigned int i;
+ GLuint i;
for (i = 0; i < scope->num_variables; i++)
if (a_name == scope->variables[i].a_name)
diff --git a/src/mesa/shader/slang/slang_compile_variable.h b/src/mesa/shader/slang/slang_compile_variable.h
index fc42280ae56..7ef83852f45 100644
--- a/src/mesa/shader/slang/slang_compile_variable.h
+++ b/src/mesa/shader/slang/slang_compile_variable.h
@@ -121,7 +121,7 @@ int slang_variable_construct (slang_variable *);
void slang_variable_destruct (slang_variable *);
int slang_variable_copy (slang_variable *, const slang_variable *);
-slang_variable *_slang_locate_variable (slang_variable_scope *scope, slang_atom a_name, int all);
+slang_variable *_slang_locate_variable (slang_variable_scope *, slang_atom a_name, GLboolean all);
#ifdef __cplusplus
}
diff --git a/src/mesa/shader/slang/slang_execute.c b/src/mesa/shader/slang/slang_execute.c
index a40a35cd578..22dba0119a7 100644
--- a/src/mesa/shader/slang/slang_execute.c
+++ b/src/mesa/shader/slang/slang_execute.c
@@ -33,6 +33,7 @@
#include "slang_assemble.h"
#include "slang_storage.h"
#include "slang_execute.h"
+#include "slang_library_noise.h"
#define DEBUG_SLANG 0
@@ -122,6 +123,18 @@ static void dump_instruction (FILE *f, slang_assembly *a, unsigned int i)
case slang_asm_float_ceil:
fprintf (f, "float_ceil");
break;
+ case slang_asm_float_noise1:
+ fprintf (f, "float_noise1");
+ break;
+ case slang_asm_float_noise2:
+ fprintf (f, "float_noise2");
+ break;
+ case slang_asm_float_noise3:
+ fprintf (f, "float_noise3");
+ break;
+ case slang_asm_float_noise4:
+ fprintf (f, "float_noise4");
+ break;
case slang_asm_int_copy:
fprintf (f, "int_copy\t%d, %d", a->param[0], a->param[1]);
break;
@@ -365,6 +378,24 @@ int _slang_execute2 (const slang_assembly_file *file, slang_machine *mach)
case slang_asm_float_ceil:
stack[mach->sp]._float = CEILF (stack[mach->sp]._float);
break;
+ case slang_asm_float_noise1:
+ stack[mach->sp]._float = _slang_library_noise1 (stack[mach->sp]._float);
+ break;
+ case slang_asm_float_noise2:
+ stack[mach->sp + 1]._float = _slang_library_noise2 (stack[mach->sp]._float,
+ stack[mach->sp + 1]._float);
+ mach->sp++;
+ break;
+ case slang_asm_float_noise3:
+ stack[mach->sp + 2]._float = _slang_library_noise3 (stack[mach->sp]._float,
+ stack[mach->sp + 1]._float, stack[mach->sp + 2]._float);
+ mach->sp += 2;
+ break;
+ case slang_asm_float_noise4:
+ stack[mach->sp + 3]._float = _slang_library_noise4 (stack[mach->sp]._float,
+ stack[mach->sp + 1]._float, stack[mach->sp + 2]._float, stack[mach->sp + 3]._float);
+ mach->sp += 3;
+ break;
case slang_asm_int_to_float:
break;
case slang_asm_int_to_addr:
@@ -442,6 +473,8 @@ int _slang_execute2 (const slang_assembly_file *file, slang_machine *mach)
case slang_asm_bool_print:
_mesa_printf ("slang print: %s\n", (GLint) stack[mach->sp]._float ? "true" : "false");
break;
+ default:
+ assert (0);
}
}
diff --git a/src/mesa/shader/slang/slang_library_noise.c b/src/mesa/shader/slang/slang_library_noise.c
new file mode 100644
index 00000000000..05c6906d514
--- /dev/null
+++ b/src/mesa/shader/slang/slang_library_noise.c
@@ -0,0 +1,514 @@
+/*
+ * Mesa 3-D graphics library
+ * Version: 6.5
+ *
+ * Copyright (C) 2006 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.
+ */
+
+#include "imports.h"
+
+/*
+ * SimplexNoise1234
+ * Copyright � 2003-2005, Stefan Gustavson
+ *
+ * Contact: [email protected]
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/** \file
+ \brief C implementation of Perlin Simplex Noise over 1,2,3, and 4 dimensions.
+ \author Stefan Gustavson ([email protected])
+*/
+
+/*
+ * This implementation is "Simplex Noise" as presented by
+ * Ken Perlin at a relatively obscure and not often cited course
+ * session "Real-Time Shading" at Siggraph 2001 (before real
+ * time shading actually took on), under the title "hardware noise".
+ * The 3D function is numerically equivalent to his Java reference
+ * code available in the PDF course notes, although I re-implemented
+ * it from scratch to get more readable code. The 1D, 2D and 4D cases
+ * were implemented from scratch by me from Ken Perlin's text.
+ *
+ * This file has no dependencies on any other file, not even its own
+ * header file. The header file is made for use by external code only.
+ */
+
+
+#define FASTFLOOR(x) ( ((x)>0) ? ((int)x) : (((int)x)-1) )
+
+/*
+ * ---------------------------------------------------------------------
+ * Static data
+ */
+
+/*
+ * Permutation table. This is just a random jumble of all numbers 0-255,
+ * repeated twice to avoid wrapping the index at 255 for each lookup.
+ * This needs to be exactly the same for all instances on all platforms,
+ * so it's easiest to just keep it as static explicit data.
+ * This also removes the need for any initialisation of this class.
+ *
+ * Note that making this an int[] instead of a char[] might make the
+ * code run faster on platforms with a high penalty for unaligned single
+ * byte addressing. Intel x86 is generally single-byte-friendly, but
+ * some other CPUs are faster with 4-aligned reads.
+ * However, a char[] is smaller, which avoids cache trashing, and that
+ * is probably the most important aspect on most architectures.
+ * This array is accessed a *lot* by the noise functions.
+ * A vector-valued noise over 3D accesses it 96 times, and a
+ * float-valued 4D noise 64 times. We want this to fit in the cache!
+ */
+unsigned char perm[512] = {151,160,137,91,90,15,
+ 131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,23,
+ 190, 6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33,
+ 88,237,149,56,87,174,20,125,136,171,168, 68,175,74,165,71,134,139,48,27,166,
+ 77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,55,46,245,40,244,
+ 102,143,54, 65,25,63,161, 1,216,80,73,209,76,132,187,208, 89,18,169,200,196,
+ 135,130,116,188,159,86,164,100,109,198,173,186, 3,64,52,217,226,250,124,123,
+ 5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,189,28,42,
+ 223,183,170,213,119,248,152, 2,44,154,163, 70,221,153,101,155,167, 43,172,9,
+ 129,22,39,253, 19,98,108,110,79,113,224,232,178,185, 112,104,218,246,97,228,
+ 251,34,242,193,238,210,144,12,191,179,162,241, 81,51,145,235,249,14,239,107,
+ 49,192,214, 31,181,199,106,157,184, 84,204,176,115,121,50,45,127, 4,150,254,
+ 138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180,
+ 151,160,137,91,90,15,
+ 131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,23,
+ 190, 6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33,
+ 88,237,149,56,87,174,20,125,136,171,168, 68,175,74,165,71,134,139,48,27,166,
+ 77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,55,46,245,40,244,
+ 102,143,54, 65,25,63,161, 1,216,80,73,209,76,132,187,208, 89,18,169,200,196,
+ 135,130,116,188,159,86,164,100,109,198,173,186, 3,64,52,217,226,250,124,123,
+ 5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,189,28,42,
+ 223,183,170,213,119,248,152, 2,44,154,163, 70,221,153,101,155,167, 43,172,9,
+ 129,22,39,253, 19,98,108,110,79,113,224,232,178,185, 112,104,218,246,97,228,
+ 251,34,242,193,238,210,144,12,191,179,162,241, 81,51,145,235,249,14,239,107,
+ 49,192,214, 31,181,199,106,157,184, 84,204,176,115,121,50,45,127, 4,150,254,
+ 138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180
+};
+
+/*
+ * ---------------------------------------------------------------------
+ */
+
+/*
+ * Helper functions to compute gradients-dot-residualvectors (1D to 4D)
+ * Note that these generate gradients of more than unit length. To make
+ * a close match with the value range of classic Perlin noise, the final
+ * noise values need to be rescaled to fit nicely within [-1,1].
+ * (The simplex noise functions as such also have different scaling.)
+ * Note also that these noise functions are the most practical and useful
+ * signed version of Perlin noise. To return values according to the
+ * RenderMan specification from the SL noise() and pnoise() functions,
+ * the noise values need to be scaled and offset to [0,1], like this:
+ * float SLnoise = (SimplexNoise1234::noise(x,y,z) + 1.0) * 0.5;
+ */
+
+static float grad1( int hash, float x ) {
+ int h = hash & 15;
+ float grad = 1.0f + (h & 7); /* Gradient value 1.0, 2.0, ..., 8.0 */
+ if (h&8) grad = -grad; /* Set a random sign for the gradient */
+ return ( grad * x ); /* Multiply the gradient with the distance */
+}
+
+static float grad2( int hash, float x, float y ) {
+ int h = hash & 7; /* Convert low 3 bits of hash code */
+ float u = h<4 ? x : y; /* into 8 simple gradient directions, */
+ float v = h<4 ? y : x; /* and compute the dot product with (x,y). */
+ return ((h&1)? -u : u) + ((h&2)? -2.0f*v : 2.0f*v);
+}
+
+static float grad3( int hash, float x, float y , float z ) {
+ int h = hash & 15; /* Convert low 4 bits of hash code into 12 simple */
+ float u = h<8 ? x : y; /* gradient directions, and compute dot product. */
+ float v = h<4 ? y : h==12||h==14 ? x : z; /* Fix repeats at h = 12 to 15 */
+ return ((h&1)? -u : u) + ((h&2)? -v : v);
+}
+
+static float grad4( int hash, float x, float y, float z, float t ) {
+ int h = hash & 31; /* Convert low 5 bits of hash code into 32 simple */
+ float u = h<24 ? x : y; /* gradient directions, and compute dot product. */
+ float v = h<16 ? y : z;
+ float w = h<8 ? z : t;
+ return ((h&1)? -u : u) + ((h&2)? -v : v) + ((h&4)? -w : w);
+}
+
+ /* A lookup table to traverse the simplex around a given point in 4D. */
+ /* Details can be found where this table is used, in the 4D noise method. */
+ /* TODO: This should not be required, backport it from Bill's GLSL code! */
+ static unsigned char simplex[64][4] = {
+ {0,1,2,3},{0,1,3,2},{0,0,0,0},{0,2,3,1},{0,0,0,0},{0,0,0,0},{0,0,0,0},{1,2,3,0},
+ {0,2,1,3},{0,0,0,0},{0,3,1,2},{0,3,2,1},{0,0,0,0},{0,0,0,0},{0,0,0,0},{1,3,2,0},
+ {0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},
+ {1,2,0,3},{0,0,0,0},{1,3,0,2},{0,0,0,0},{0,0,0,0},{0,0,0,0},{2,3,0,1},{2,3,1,0},
+ {1,0,2,3},{1,0,3,2},{0,0,0,0},{0,0,0,0},{0,0,0,0},{2,0,3,1},{0,0,0,0},{2,1,3,0},
+ {0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},
+ {2,0,1,3},{0,0,0,0},{0,0,0,0},{0,0,0,0},{3,0,1,2},{3,0,2,1},{0,0,0,0},{3,1,2,0},
+ {2,1,0,3},{0,0,0,0},{0,0,0,0},{0,0,0,0},{3,1,0,2},{0,0,0,0},{3,2,0,1},{3,2,1,0}};
+
+/* 1D simplex noise */
+GLfloat _slang_library_noise1 (GLfloat x)
+{
+ int i0 = FASTFLOOR(x);
+ int i1 = i0 + 1;
+ float x0 = x - i0;
+ float x1 = x0 - 1.0f;
+ float t1 = 1.0f - x1*x1;
+ float n0, n1;
+
+ float t0 = 1.0f - x0*x0;
+/* if(t0 < 0.0f) t0 = 0.0f; // this never happens for the 1D case */
+ t0 *= t0;
+ n0 = t0 * t0 * grad1(perm[i0 & 0xff], x0);
+
+/* if(t1 < 0.0f) t1 = 0.0f; // this never happens for the 1D case */
+ t1 *= t1;
+ n1 = t1 * t1 * grad1(perm[i1 & 0xff], x1);
+ /* The maximum value of this noise is 8*(3/4)^4 = 2.53125 */
+ /* A factor of 0.395 would scale to fit exactly within [-1,1], but */
+ /* we want to match PRMan's 1D noise, so we scale it down some more. */
+ return 0.25f * (n0 + n1);
+}
+
+/* 2D simplex noise */
+GLfloat _slang_library_noise2 (GLfloat x, GLfloat y)
+{
+#define F2 0.366025403f /* F2 = 0.5*(sqrt(3.0)-1.0) */
+#define G2 0.211324865f /* G2 = (3.0-Math.sqrt(3.0))/6.0 */
+
+ float n0, n1, n2; /* Noise contributions from the three corners */
+
+ /* Skew the input space to determine which simplex cell we're in */
+ float s = (x+y)*F2; /* Hairy factor for 2D */
+ float xs = x + s;
+ float ys = y + s;
+ int i = FASTFLOOR(xs);
+ int j = FASTFLOOR(ys);
+
+ float t = (float)(i+j)*G2;
+ float X0 = i-t; /* Unskew the cell origin back to (x,y) space */
+ float Y0 = j-t;
+ float x0 = x-X0; /* The x,y distances from the cell origin */
+ float y0 = y-Y0;
+
+ float x1, y1, x2, y2;
+ int ii, jj;
+ float t0, t1, t2;
+
+ /* For the 2D case, the simplex shape is an equilateral triangle. */
+ /* Determine which simplex we are in. */
+ int i1, j1; /* Offsets for second (middle) corner of simplex in (i,j) coords */
+ if(x0>y0) {i1=1; j1=0;} /* lower triangle, XY order: (0,0)->(1,0)->(1,1) */
+ else {i1=0; j1=1;} /* upper triangle, YX order: (0,0)->(0,1)->(1,1) */
+
+ /* A step of (1,0) in (i,j) means a step of (1-c,-c) in (x,y), and */
+ /* a step of (0,1) in (i,j) means a step of (-c,1-c) in (x,y), where */
+ /* c = (3-sqrt(3))/6 */
+
+ x1 = x0 - i1 + G2; /* Offsets for middle corner in (x,y) unskewed coords */
+ y1 = y0 - j1 + G2;
+ x2 = x0 - 1.0f + 2.0f * G2; /* Offsets for last corner in (x,y) unskewed coords */
+ y2 = y0 - 1.0f + 2.0f * G2;
+
+ /* Wrap the integer indices at 256, to avoid indexing perm[] out of bounds */
+ ii = i % 256;
+ jj = j % 256;
+
+ /* Calculate the contribution from the three corners */
+ t0 = 0.5f - x0*x0-y0*y0;
+ if(t0 < 0.0f) n0 = 0.0f;
+ else {
+ t0 *= t0;
+ n0 = t0 * t0 * grad2(perm[ii+perm[jj]], x0, y0);
+ }
+
+ t1 = 0.5f - x1*x1-y1*y1;
+ if(t1 < 0.0f) n1 = 0.0f;
+ else {
+ t1 *= t1;
+ n1 = t1 * t1 * grad2(perm[ii+i1+perm[jj+j1]], x1, y1);
+ }
+
+ t2 = 0.5f - x2*x2-y2*y2;
+ if(t2 < 0.0f) n2 = 0.0f;
+ else {
+ t2 *= t2;
+ n2 = t2 * t2 * grad2(perm[ii+1+perm[jj+1]], x2, y2);
+ }
+
+ /* Add contributions from each corner to get the final noise value. */
+ /* The result is scaled to return values in the interval [-1,1]. */
+ return 40.0f * (n0 + n1 + n2); /* TODO: The scale factor is preliminary! */
+}
+
+/* 3D simplex noise */
+GLfloat _slang_library_noise3 (GLfloat x, GLfloat y, GLfloat z)
+{
+/* Simple skewing factors for the 3D case */
+#define F3 0.333333333f
+#define G3 0.166666667f
+
+ float n0, n1, n2, n3; /* Noise contributions from the four corners */
+
+ /* Skew the input space to determine which simplex cell we're in */
+ float s = (x+y+z)*F3; /* Very nice and simple skew factor for 3D */
+ float xs = x+s;
+ float ys = y+s;
+ float zs = z+s;
+ int i = FASTFLOOR(xs);
+ int j = FASTFLOOR(ys);
+ int k = FASTFLOOR(zs);
+
+ float t = (float)(i+j+k)*G3;
+ float X0 = i-t; /* Unskew the cell origin back to (x,y,z) space */
+ float Y0 = j-t;
+ float Z0 = k-t;
+ float x0 = x-X0; /* The x,y,z distances from the cell origin */
+ float y0 = y-Y0;
+ float z0 = z-Z0;
+
+ float x1, y1, z1, x2, y2, z2, x3, y3, z3;
+ int ii, jj, kk;
+ float t0, t1, t2, t3;
+
+ /* For the 3D case, the simplex shape is a slightly irregular tetrahedron. */
+ /* Determine which simplex we are in. */
+ int i1, j1, k1; /* Offsets for second corner of simplex in (i,j,k) coords */
+ int i2, j2, k2; /* Offsets for third corner of simplex in (i,j,k) coords */
+
+/* This code would benefit from a backport from the GLSL version! */
+ if(x0>=y0) {
+ if(y0>=z0)
+ { i1=1; j1=0; k1=0; i2=1; j2=1; k2=0; } /* X Y Z order */
+ else if(x0>=z0) { i1=1; j1=0; k1=0; i2=1; j2=0; k2=1; } /* X Z Y order */
+ else { i1=0; j1=0; k1=1; i2=1; j2=0; k2=1; } /* Z X Y order */
+ }
+ else { /* x0<y0 */
+ if(y0<z0) { i1=0; j1=0; k1=1; i2=0; j2=1; k2=1; } /* Z Y X order */
+ else if(x0<z0) { i1=0; j1=1; k1=0; i2=0; j2=1; k2=1; } /* Y Z X order */
+ else { i1=0; j1=1; k1=0; i2=1; j2=1; k2=0; } /* Y X Z order */
+ }
+
+ /* A step of (1,0,0) in (i,j,k) means a step of (1-c,-c,-c) in (x,y,z), */
+ /* a step of (0,1,0) in (i,j,k) means a step of (-c,1-c,-c) in (x,y,z), and */
+ /* a step of (0,0,1) in (i,j,k) means a step of (-c,-c,1-c) in (x,y,z), where */
+ /* c = 1/6. */
+
+ x1 = x0 - i1 + G3; /* Offsets for second corner in (x,y,z) coords */
+ y1 = y0 - j1 + G3;
+ z1 = z0 - k1 + G3;
+ x2 = x0 - i2 + 2.0f*G3; /* Offsets for third corner in (x,y,z) coords */
+ y2 = y0 - j2 + 2.0f*G3;
+ z2 = z0 - k2 + 2.0f*G3;
+ x3 = x0 - 1.0f + 3.0f*G3; /* Offsets for last corner in (x,y,z) coords */
+ y3 = y0 - 1.0f + 3.0f*G3;
+ z3 = z0 - 1.0f + 3.0f*G3;
+
+ /* Wrap the integer indices at 256, to avoid indexing perm[] out of bounds */
+ ii = i % 256;
+ jj = j % 256;
+ kk = k % 256;
+
+ /* Calculate the contribution from the four corners */
+ t0 = 0.6f - x0*x0 - y0*y0 - z0*z0;
+ if(t0 < 0.0f) n0 = 0.0f;
+ else {
+ t0 *= t0;
+ n0 = t0 * t0 * grad3(perm[ii+perm[jj+perm[kk]]], x0, y0, z0);
+ }
+
+ t1 = 0.6f - x1*x1 - y1*y1 - z1*z1;
+ if(t1 < 0.0f) n1 = 0.0f;
+ else {
+ t1 *= t1;
+ n1 = t1 * t1 * grad3(perm[ii+i1+perm[jj+j1+perm[kk+k1]]], x1, y1, z1);
+ }
+
+ t2 = 0.6f - x2*x2 - y2*y2 - z2*z2;
+ if(t2 < 0.0f) n2 = 0.0f;
+ else {
+ t2 *= t2;
+ n2 = t2 * t2 * grad3(perm[ii+i2+perm[jj+j2+perm[kk+k2]]], x2, y2, z2);
+ }
+
+ t3 = 0.6f - x3*x3 - y3*y3 - z3*z3;
+ if(t3<0.0f) n3 = 0.0f;
+ else {
+ t3 *= t3;
+ n3 = t3 * t3 * grad3(perm[ii+1+perm[jj+1+perm[kk+1]]], x3, y3, z3);
+ }
+
+ /* Add contributions from each corner to get the final noise value. */
+ /* The result is scaled to stay just inside [-1,1] */
+ return 32.0f * (n0 + n1 + n2 + n3); /* TODO: The scale factor is preliminary! */
+}
+
+/* 4D simplex noise */
+GLfloat _slang_library_noise4 (GLfloat x, GLfloat y, GLfloat z, GLfloat w)
+{
+ /* The skewing and unskewing factors are hairy again for the 4D case */
+#define F4 0.309016994f /* F4 = (Math.sqrt(5.0)-1.0)/4.0 */
+#define G4 0.138196601f /* G4 = (5.0-Math.sqrt(5.0))/20.0 */
+
+ float n0, n1, n2, n3, n4; /* Noise contributions from the five corners */
+
+ /* Skew the (x,y,z,w) space to determine which cell of 24 simplices we're in */
+ float s = (x + y + z + w) * F4; /* Factor for 4D skewing */
+ float xs = x + s;
+ float ys = y + s;
+ float zs = z + s;
+ float ws = w + s;
+ int i = FASTFLOOR(xs);
+ int j = FASTFLOOR(ys);
+ int k = FASTFLOOR(zs);
+ int l = FASTFLOOR(ws);
+
+ float t = (i + j + k + l) * G4; /* Factor for 4D unskewing */
+ float X0 = i - t; /* Unskew the cell origin back to (x,y,z,w) space */
+ float Y0 = j - t;
+ float Z0 = k - t;
+ float W0 = l - t;
+
+ float x0 = x - X0; /* The x,y,z,w distances from the cell origin */
+ float y0 = y - Y0;
+ float z0 = z - Z0;
+ float w0 = w - W0;
+
+ /* For the 4D case, the simplex is a 4D shape I won't even try to describe. */
+ /* To find out which of the 24 possible simplices we're in, we need to */
+ /* determine the magnitude ordering of x0, y0, z0 and w0. */
+ /* The method below is a good way of finding the ordering of x,y,z,w and */
+ /* then find the correct traversal order for the simplex we�re in. */
+ /* First, six pair-wise comparisons are performed between each possible pair */
+ /* of the four coordinates, and the results are used to add up binary bits */
+ /* for an integer index. */
+ int c1 = (x0 > y0) ? 32 : 0;
+ int c2 = (x0 > z0) ? 16 : 0;
+ int c3 = (y0 > z0) ? 8 : 0;
+ int c4 = (x0 > w0) ? 4 : 0;
+ int c5 = (y0 > w0) ? 2 : 0;
+ int c6 = (z0 > w0) ? 1 : 0;
+ int c = c1 + c2 + c3 + c4 + c5 + c6;
+
+ int i1, j1, k1, l1; /* The integer offsets for the second simplex corner */
+ int i2, j2, k2, l2; /* The integer offsets for the third simplex corner */
+ int i3, j3, k3, l3; /* The integer offsets for the fourth simplex corner */
+
+ float x1, y1, z1, w1, x2, y2, z2, w2, x3, y3, z3, w3, x4, y4, z4, w4;
+ int ii, jj, kk, ll;
+ float t0, t1, t2, t3, t4;
+
+ /* simplex[c] is a 4-vector with the numbers 0, 1, 2 and 3 in some order. */
+ /* Many values of c will never occur, since e.g. x>y>z>w makes x<z, y<w and x<w */
+ /* impossible. Only the 24 indices which have non-zero entries make any sense. */
+ /* We use a thresholding to set the coordinates in turn from the largest magnitude. */
+ /* The number 3 in the "simplex" array is at the position of the largest coordinate. */
+ i1 = simplex[c][0]>=3 ? 1 : 0;
+ j1 = simplex[c][1]>=3 ? 1 : 0;
+ k1 = simplex[c][2]>=3 ? 1 : 0;
+ l1 = simplex[c][3]>=3 ? 1 : 0;
+ /* The number 2 in the "simplex" array is at the second largest coordinate. */
+ i2 = simplex[c][0]>=2 ? 1 : 0;
+ j2 = simplex[c][1]>=2 ? 1 : 0;
+ k2 = simplex[c][2]>=2 ? 1 : 0;
+ l2 = simplex[c][3]>=2 ? 1 : 0;
+ /* The number 1 in the "simplex" array is at the second smallest coordinate. */
+ i3 = simplex[c][0]>=1 ? 1 : 0;
+ j3 = simplex[c][1]>=1 ? 1 : 0;
+ k3 = simplex[c][2]>=1 ? 1 : 0;
+ l3 = simplex[c][3]>=1 ? 1 : 0;
+ /* The fifth corner has all coordinate offsets = 1, so no need to look that up. */
+
+ x1 = x0 - i1 + G4; /* Offsets for second corner in (x,y,z,w) coords */
+ y1 = y0 - j1 + G4;
+ z1 = z0 - k1 + G4;
+ w1 = w0 - l1 + G4;
+ x2 = x0 - i2 + 2.0f*G4; /* Offsets for third corner in (x,y,z,w) coords */
+ y2 = y0 - j2 + 2.0f*G4;
+ z2 = z0 - k2 + 2.0f*G4;
+ w2 = w0 - l2 + 2.0f*G4;
+ x3 = x0 - i3 + 3.0f*G4; /* Offsets for fourth corner in (x,y,z,w) coords */
+ y3 = y0 - j3 + 3.0f*G4;
+ z3 = z0 - k3 + 3.0f*G4;
+ w3 = w0 - l3 + 3.0f*G4;
+ x4 = x0 - 1.0f + 4.0f*G4; /* Offsets for last corner in (x,y,z,w) coords */
+ y4 = y0 - 1.0f + 4.0f*G4;
+ z4 = z0 - 1.0f + 4.0f*G4;
+ w4 = w0 - 1.0f + 4.0f*G4;
+
+ /* Wrap the integer indices at 256, to avoid indexing perm[] out of bounds */
+ ii = i % 256;
+ jj = j % 256;
+ kk = k % 256;
+ ll = l % 256;
+
+ /* Calculate the contribution from the five corners */
+ t0 = 0.6f - x0*x0 - y0*y0 - z0*z0 - w0*w0;
+ if(t0 < 0.0f) n0 = 0.0f;
+ else {
+ t0 *= t0;
+ n0 = t0 * t0 * grad4(perm[ii+perm[jj+perm[kk+perm[ll]]]], x0, y0, z0, w0);
+ }
+
+ t1 = 0.6f - x1*x1 - y1*y1 - z1*z1 - w1*w1;
+ if(t1 < 0.0f) n1 = 0.0f;
+ else {
+ t1 *= t1;
+ n1 = t1 * t1 * grad4(perm[ii+i1+perm[jj+j1+perm[kk+k1+perm[ll+l1]]]], x1, y1, z1, w1);
+ }
+
+ t2 = 0.6f - x2*x2 - y2*y2 - z2*z2 - w2*w2;
+ if(t2 < 0.0f) n2 = 0.0f;
+ else {
+ t2 *= t2;
+ n2 = t2 * t2 * grad4(perm[ii+i2+perm[jj+j2+perm[kk+k2+perm[ll+l2]]]], x2, y2, z2, w2);
+ }
+
+ t3 = 0.6f - x3*x3 - y3*y3 - z3*z3 - w3*w3;
+ if(t3 < 0.0f) n3 = 0.0f;
+ else {
+ t3 *= t3;
+ n3 = t3 * t3 * grad4(perm[ii+i3+perm[jj+j3+perm[kk+k3+perm[ll+l3]]]], x3, y3, z3, w3);
+ }
+
+ t4 = 0.6f - x4*x4 - y4*y4 - z4*z4 - w4*w4;
+ if(t4 < 0.0f) n4 = 0.0f;
+ else {
+ t4 *= t4;
+ n4 = t4 * t4 * grad4(perm[ii+1+perm[jj+1+perm[kk+1+perm[ll+1]]]], x4, y4, z4, w4);
+ }
+
+ /* Sum up and scale the result to cover the range [-1,1] */
+ return 27.0f * (n0 + n1 + n2 + n3 + n4); /* TODO: The scale factor is preliminary! */
+}
+
diff --git a/src/mesa/shader/slang/slang_library_noise.h b/src/mesa/shader/slang/slang_library_noise.h
new file mode 100644
index 00000000000..e4f419d8dbe
--- /dev/null
+++ b/src/mesa/shader/slang/slang_library_noise.h
@@ -0,0 +1,42 @@
+/*
+ * Mesa 3-D graphics library
+ * Version: 6.5
+ *
+ * Copyright (C) 2006 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.
+ */
+
+#if !defined SLANG_LIBRARY_NOISE_H
+#define SLANG_LIBRARY_NOISE_H
+
+#if defined __cplusplus
+extern "C" {
+#endif
+
+GLfloat _slang_library_noise1 (GLfloat);
+GLfloat _slang_library_noise2 (GLfloat, GLfloat);
+GLfloat _slang_library_noise3 (GLfloat, GLfloat, GLfloat);
+GLfloat _slang_library_noise4 (GLfloat, GLfloat, GLfloat, GLfloat);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
diff --git a/src/mesa/shader/slang/slang_storage.c b/src/mesa/shader/slang/slang_storage.c
index a2d1ab9314b..2654ee0404b 100644
--- a/src/mesa/shader/slang/slang_storage.c
+++ b/src/mesa/shader/slang/slang_storage.c
@@ -36,15 +36,15 @@
/* slang_storage_array */
-int slang_storage_array_construct (slang_storage_array *arr)
+GLboolean slang_storage_array_construct (slang_storage_array *arr)
{
arr->type = slang_stor_aggregate;
arr->aggregate = NULL;
arr->length = 0;
- return 1;
+ return GL_TRUE;
}
-void slang_storage_array_destruct (slang_storage_array *arr)
+GLvoid slang_storage_array_destruct (slang_storage_array *arr)
{
if (arr->aggregate != NULL)
{
@@ -55,16 +55,16 @@ void slang_storage_array_destruct (slang_storage_array *arr)
/* slang_storage_aggregate */
-int slang_storage_aggregate_construct (slang_storage_aggregate *agg)
+GLboolean slang_storage_aggregate_construct (slang_storage_aggregate *agg)
{
agg->arrays = NULL;
agg->count = 0;
- return 1;
+ return GL_TRUE;
}
-void slang_storage_aggregate_destruct (slang_storage_aggregate *agg)
+GLvoid slang_storage_aggregate_destruct (slang_storage_aggregate *agg)
{
- unsigned int i;
+ GLuint i;
for (i = 0; i < agg->count; i++)
slang_storage_array_destruct (agg->arrays + i);
@@ -73,7 +73,8 @@ void slang_storage_aggregate_destruct (slang_storage_aggregate *agg)
static slang_storage_array *slang_storage_aggregate_push_new (slang_storage_aggregate *agg)
{
- slang_storage_array *arr = NULL;
+ slang_storage_array *arr = NULL;
+
agg->arrays = (slang_storage_array *) slang_alloc_realloc (agg->arrays, agg->count * sizeof (
slang_storage_array), (agg->count + 1) * sizeof (slang_storage_array));
if (agg->arrays != NULL)
@@ -88,88 +89,91 @@ static slang_storage_array *slang_storage_aggregate_push_new (slang_storage_aggr
/* _slang_aggregate_variable() */
-static int aggregate_vector (slang_storage_aggregate *agg, slang_storage_type basic_type,
- unsigned int row_count)
+static GLboolean aggregate_vector (slang_storage_aggregate *agg, slang_storage_type basic_type,
+ GLuint row_count)
{
slang_storage_array *arr = slang_storage_aggregate_push_new (agg);
if (arr == NULL)
- return 0;
+ return GL_FALSE;
arr->type = basic_type;
arr->length = row_count;
- return 1;
+ return GL_TRUE;
}
-static int aggregate_matrix (slang_storage_aggregate *agg, slang_storage_type basic_type,
- unsigned int dimension)
+static GLboolean aggregate_matrix (slang_storage_aggregate *agg, slang_storage_type basic_type,
+ GLuint dimension)
{
slang_storage_array *arr = slang_storage_aggregate_push_new (agg);
if (arr == NULL)
- return 0;
+ return GL_FALSE;
arr->type = slang_stor_aggregate;
arr->length = dimension;
- arr->aggregate = (slang_storage_aggregate *) slang_alloc_malloc (sizeof (
- slang_storage_aggregate));
+ arr->aggregate = (slang_storage_aggregate *) slang_alloc_malloc (sizeof (slang_storage_aggregate));
if (arr->aggregate == NULL)
- return 0;
+ return GL_FALSE;
if (!slang_storage_aggregate_construct (arr->aggregate))
{
slang_alloc_free (arr->aggregate);
arr->aggregate = NULL;
- return 0;
+ return GL_FALSE;
}
if (!aggregate_vector (arr->aggregate, basic_type, dimension))
- return 0;
- return 1;
+ return GL_FALSE;
+ return GL_TRUE;
}
-static int aggregate_variables (slang_storage_aggregate *agg, slang_variable_scope *vars,
+static GLboolean aggregate_variables (slang_storage_aggregate *agg, slang_variable_scope *vars,
slang_function_scope *funcs, slang_struct_scope *structs, slang_variable_scope *globals,
slang_machine *mach, slang_assembly_file *file, slang_atom_pool *atoms)
{
- unsigned int i;
+ GLuint i;
+
for (i = 0; i < vars->num_variables; i++)
if (!_slang_aggregate_variable (agg, &vars->variables[i].type.specifier,
vars->variables[i].array_size, funcs, structs, globals, mach, file, atoms))
- return 0;
- return 1;
+ return GL_FALSE;
+ return GL_TRUE;
}
-static int eval_array_size (slang_assembly_file *file, slang_machine *pmach,
+static GLboolean eval_array_size (slang_assembly_file *file, slang_machine *pmach,
slang_assembly_name_space *space, slang_operation *array_size, GLuint *plength,
slang_atom_pool *atoms)
{
slang_assembly_file_restore_point point;
- slang_assembly_local_info info;
- slang_assembly_flow_control flow;
- slang_assembly_stack_info stk;
slang_machine mach;
+ slang_assemble_ctx A;
+
+ A.file = file;
+ A.mach = pmach;
+ A.atoms = atoms;
+ A.space = *space;
+ A.local.ret_size = 0;
+ A.local.addr_tmp = 0;
+ A.local.swizzle_tmp = 4;
/* save the current assembly */
if (!slang_assembly_file_restore_point_save (file, &point))
- return 0;
+ return GL_FALSE;
/* setup the machine */
mach = *pmach;
mach.ip = file->count;
/* allocate local storage for expression */
- info.ret_size = 0;
- info.addr_tmp = 0;
- info.swizzle_tmp = 4;
if (!slang_assembly_file_push_label (file, slang_asm_local_alloc, 20))
- return 0;
+ return GL_FALSE;
if (!slang_assembly_file_push_label (file, slang_asm_enter, 20))
- return 0;
+ return GL_FALSE;
/* insert the actual expression */
- if (!_slang_assemble_operation (file, array_size, 0, &flow, space, &info, &stk, pmach, atoms))
- return 0;
+ if (!_slang_assemble_operation_ (&A, array_size, slang_ref_forbid))
+ return GL_FALSE;
if (!slang_assembly_file_push (file, slang_asm_exit))
- return 0;
+ return GL_FALSE;
/* execute the expression */
if (!_slang_execute2 (file, &mach))
- return 0;
+ return GL_FALSE;
/* the evaluated expression is on top of the stack */
*plength = (GLuint) mach.mem[mach.sp + SLANG_MACHINE_GLOBAL_SIZE]._float;
@@ -177,11 +181,12 @@ static int eval_array_size (slang_assembly_file *file, slang_machine *pmach,
/* restore the old assembly */
if (!slang_assembly_file_restore_point_load (file, &point))
- return 0;
- return 1;
+ return GL_FALSE;
+
+ return GL_TRUE;
}
-int _slang_aggregate_variable (slang_storage_aggregate *agg, slang_type_specifier *spec,
+GLboolean _slang_aggregate_variable (slang_storage_aggregate *agg, slang_type_specifier *spec,
slang_operation *array_size, slang_function_scope *funcs, slang_struct_scope *structs,
slang_variable_scope *vars, slang_machine *mach, slang_assembly_file *file,
slang_atom_pool *atoms)
@@ -235,42 +240,41 @@ int _slang_aggregate_variable (slang_storage_aggregate *agg, slang_type_specifie
arr = slang_storage_aggregate_push_new (agg);
if (arr == NULL)
- return 0;
+ return GL_FALSE;
arr->type = slang_stor_aggregate;
- arr->aggregate = (slang_storage_aggregate *) slang_alloc_malloc (sizeof (
- slang_storage_aggregate));
+ arr->aggregate = (slang_storage_aggregate *) slang_alloc_malloc (sizeof (slang_storage_aggregate));
if (arr->aggregate == NULL)
- return 0;
+ return GL_FALSE;
if (!slang_storage_aggregate_construct (arr->aggregate))
{
slang_alloc_free (arr->aggregate);
arr->aggregate = NULL;
- return 0;
+ return GL_FALSE;
}
if (!_slang_aggregate_variable (arr->aggregate, spec->_array, NULL, funcs, structs,
vars, mach, file, atoms))
- return 0;
+ return GL_FALSE;
space.funcs = funcs;
space.structs = structs;
space.vars = vars;
if (!eval_array_size (file, mach, &space, array_size, &arr->length, atoms))
- return 0;
+ return GL_FALSE;
}
- return 1;
+ return GL_TRUE;
default:
- return 0;
+ return GL_FALSE;
}
}
/* _slang_sizeof_aggregate() */
-unsigned int _slang_sizeof_aggregate (const slang_storage_aggregate *agg)
+GLuint _slang_sizeof_aggregate (const slang_storage_aggregate *agg)
{
- unsigned int i, size = 0;
+ GLuint i, size = 0;
for (i = 0; i < agg->count; i++)
{
- unsigned int element_size;
+ GLuint element_size;
if (agg->arrays[i].type == slang_stor_aggregate)
element_size = _slang_sizeof_aggregate (agg->arrays[i].aggregate);
@@ -283,20 +287,20 @@ unsigned int _slang_sizeof_aggregate (const slang_storage_aggregate *agg)
/* _slang_flatten_aggregate () */
-int _slang_flatten_aggregate (slang_storage_aggregate *flat, const slang_storage_aggregate *agg)
+GLboolean _slang_flatten_aggregate (slang_storage_aggregate *flat, const slang_storage_aggregate *agg)
{
- unsigned int i;
+ GLuint i;
for (i = 0; i < agg->count; i++)
{
- unsigned int j;
+ GLuint j;
for (j = 0; j < agg->arrays[i].length; j++)
{
if (agg->arrays[i].type == slang_stor_aggregate)
{
if (!_slang_flatten_aggregate (flat, agg->arrays[i].aggregate))
- return 0;
+ return GL_FALSE;
}
else
{
@@ -304,12 +308,12 @@ int _slang_flatten_aggregate (slang_storage_aggregate *flat, const slang_storage
arr = slang_storage_aggregate_push_new (flat);
if (arr == NULL)
- return 0;
+ return GL_FALSE;
arr->type = agg->arrays[i].type;
arr->length = 1;
}
}
}
- return 1;
+ return GL_TRUE;
}
diff --git a/src/mesa/shader/slang/slang_storage.h b/src/mesa/shader/slang/slang_storage.h
index a99f38f65c8..84206d01563 100644
--- a/src/mesa/shader/slang/slang_storage.h
+++ b/src/mesa/shader/slang/slang_storage.h
@@ -32,14 +32,14 @@ extern "C" {
#endif
/*
- Program variable data storage is kept completely transparent to the front-end compiler. It is
- up to the back-end how the data is actually allocated. The slang_storage_type enum
- provides the basic information about how the memory is interpreted. This abstract piece
- of memory is called a data slot. A data slot of a particular type has a fixed size.
-
- For now, only the three basic types are supported, that is bool, int and float. Other built-in
- types like vector or matrix can easily be decomposed into a series of basic types.
-*/
+ * Program variable data storage is kept completely transparent to the front-end compiler. It is
+ * up to the back-end how the data is actually allocated. The slang_storage_type enum
+ * provides the basic information about how the memory is interpreted. This abstract piece
+ * of memory is called a data slot. A data slot of a particular type has a fixed size.
+ *
+ * For now, only the three basic types are supported, that is bool, int and float. Other built-in
+ * types like vector or matrix can easily be decomposed into a series of basic types.
+ */
typedef enum slang_storage_type_
{
slang_stor_aggregate,
@@ -49,59 +49,59 @@ typedef enum slang_storage_type_
} slang_storage_type;
/*
- The slang_storage_array structure groups data slots of the same type into an array. This
- array has a fixed length. Arrays are required to have a size equal to the sum of sizes of its
- elements. They are also required to support indirect addressing. That is, if B references
- first data slot in the array, S is the size of the data slot and I is the integral index that
- is not known at compile time, B+I*S references I-th data slot.
-
- This structure is also used to break down built-in data types that are not supported directly.
- Vectors, like vec3, are constructed from arrays of their basic types. Matrices are formed of
- an array of column vectors, which are in turn processed as other vectors.
-*/
+ * The slang_storage_array structure groups data slots of the same type into an array. This
+ * array has a fixed length. Arrays are required to have a size equal to the sum of sizes of its
+ * elements. They are also required to support indirect addressing. That is, if B references
+ * first data slot in the array, S is the size of the data slot and I is the integral index that
+ * is not known at compile time, B+I*S references I-th data slot.
+ *
+ * This structure is also used to break down built-in data types that are not supported directly.
+ * Vectors, like vec3, are constructed from arrays of their basic types. Matrices are formed of
+ * an array of column vectors, which are in turn processed as other vectors.
+ */
typedef struct slang_storage_array_
{
slang_storage_type type;
struct slang_storage_aggregate_ *aggregate; /* slang_stor_aggregate */
- unsigned int length;
+ GLuint length;
} slang_storage_array;
-int slang_storage_array_construct (slang_storage_array *);
-void slang_storage_array_destruct (slang_storage_array *);
+GLboolean slang_storage_array_construct (slang_storage_array *);
+GLvoid slang_storage_array_destruct (slang_storage_array *);
/*
- The slang_storage_aggregate structure relaxes the indirect addressing requirement for
- slang_storage_array structure. Aggregates are always accessed statically - its member
- addresses are well-known at compile time. For example, user-defined types are implemented as
- aggregates. Aggregates can collect data of a different type.
-*/
+ * The slang_storage_aggregate structure relaxes the indirect addressing requirement for
+ * slang_storage_array structure. Aggregates are always accessed statically - its member
+ * addresses are well-known at compile time. For example, user-defined types are implemented as
+ * aggregates. Aggregates can collect data of a different type.
+ */
typedef struct slang_storage_aggregate_
{
slang_storage_array *arrays;
- unsigned int count;
+ GLuint count;
} slang_storage_aggregate;
-int slang_storage_aggregate_construct (slang_storage_aggregate *);
-void slang_storage_aggregate_destruct (slang_storage_aggregate *);
+GLboolean slang_storage_aggregate_construct (slang_storage_aggregate *);
+GLvoid slang_storage_aggregate_destruct (slang_storage_aggregate *);
-int _slang_aggregate_variable (slang_storage_aggregate *, struct slang_type_specifier_ *,
+GLboolean _slang_aggregate_variable (slang_storage_aggregate *, struct slang_type_specifier_ *,
struct slang_operation_ *, struct slang_function_scope_ *, slang_struct_scope *,
slang_variable_scope *, struct slang_machine_ *, struct slang_assembly_file_ *,
slang_atom_pool *);
/*
- returns total size (in machine units) of the given aggregate
- returns 0 on error
-*/
-unsigned int _slang_sizeof_aggregate (const slang_storage_aggregate *);
+ * Returns total size (in machine units) of the given aggregate.
+ * Returns 0 on error.
+ */
+GLuint _slang_sizeof_aggregate (const slang_storage_aggregate *);
/*
- converts structured aggregate to a flat one, with arrays of generic type being
- one-element long
- returns 1 on success
- returns 0 otherwise
-*/
-int _slang_flatten_aggregate (slang_storage_aggregate *, const slang_storage_aggregate *);
+ * Converts structured aggregate to a flat one, with arrays of generic type being
+ * one-element long.
+ * Returns GL_TRUE on success.
+ * Returns GL_FALSE otherwise.
+ */
+GLboolean _slang_flatten_aggregate (slang_storage_aggregate *, const slang_storage_aggregate *);
#ifdef __cplusplus
}
diff --git a/src/mesa/sources b/src/mesa/sources
index b07170f7f08..250e44d49b6 100644
--- a/src/mesa/sources
+++ b/src/mesa/sources
@@ -200,6 +200,7 @@ SLANG_SOURCES = \
shader/slang/slang_compile_struct.c \
shader/slang/slang_compile_variable.c \
shader/slang/slang_execute.c \
+ shader/slang/slang_library_noise.c \
shader/slang/slang_preprocess.c \
shader/slang/slang_storage.c \
shader/slang/slang_utility.c
diff --git a/src/mesa/tnl/t_vb_arbshader.c b/src/mesa/tnl/t_vb_arbshader.c
index c1244ba9257..50b23cf1332 100644
--- a/src/mesa/tnl/t_vb_arbshader.c
+++ b/src/mesa/tnl/t_vb_arbshader.c
@@ -176,11 +176,41 @@ static void fetch_output_vec4 (const char *name, GLuint attr, GLuint i, GLuint i
_mesa_memcpy (&store->outputs[attr].data[i], vec, 16);
}
-static void fetch_uniform_mat4 (const char *name, const GLmatrix *matrix, GLuint index,
+static void fetch_uniform_mat4 (const char *name, GLmatrix *matrix, GLuint index,
struct gl2_vertex_shader_intf **vs)
{
- /* XXX: transpose? */
+ GLuint len;
+ GLfloat mat[16];
+ char buffer[64];
+
+ _mesa_strcpy (buffer, name);
+ len = _mesa_strlen (name);
+
+ /* we want inverse matrix */
+ if (!matrix->inv)
+ {
+ /* allocate inverse matrix and make it dirty */
+ _math_matrix_alloc_inv (matrix);
+ _math_matrix_loadf (matrix, matrix->m);
+ }
+ _math_matrix_analyse (matrix);
+
+ /* identity */
_slang_fetch_mat4 (vs, name, matrix->m, index, 1);
+
+ /* transpose */
+ _mesa_strcpy (buffer + len, "Transpose");
+ _math_transposef (mat, matrix->m);
+ _slang_fetch_mat4 (vs, buffer, mat, index, 1);
+
+ /* inverse */
+ _mesa_strcpy (buffer + len, "Inverse");
+ _slang_fetch_mat4 (vs, buffer, matrix->inv, index, 1);
+
+ /* inverse transpose */
+ _mesa_strcpy (buffer + len, "InverseTranspose");
+ _math_transposef (mat, matrix->inv);
+ _slang_fetch_mat4 (vs, buffer, mat, index, 1);
}
static void fetch_normal_matrix (const char *name, GLmatrix *matrix,
@@ -189,14 +219,16 @@ static void fetch_normal_matrix (const char *name, GLmatrix *matrix,
GLfloat mat[9];
_math_matrix_analyse (matrix);
+
+ /* inverse transpose */
mat[0] = matrix->inv[0];
- mat[1] = matrix->inv[1];
- mat[2] = matrix->inv[2];
- mat[3] = matrix->inv[4];
+ mat[1] = matrix->inv[4];
+ mat[2] = matrix->inv[8];
+ mat[3] = matrix->inv[1];
mat[4] = matrix->inv[5];
- mat[5] = matrix->inv[6];
- mat[6] = matrix->inv[8];
- mat[7] = matrix->inv[9];
+ mat[5] = matrix->inv[9];
+ mat[6] = matrix->inv[2];
+ mat[7] = matrix->inv[6];
mat[8] = matrix->inv[10];
_slang_fetch_mat3 (vs, name, mat, 0, 1);
}
@@ -238,18 +270,6 @@ static GLboolean run_arb_vertex_shader (GLcontext *ctx, struct tnl_pipeline_stag
for (j = 0; j < 8; j++)
fetch_uniform_mat4 ("gl_TextureMatrix", ctx->TextureMatrixStack[j].Top, j, vs);
fetch_normal_matrix ("gl_NormalMatrix", ctx->ModelviewMatrixStack.Top, vs);
- /* XXX: fetch uniform mat4 gl_ModelViewMatrixInverse */
- /* XXX: fetch uniform mat4 gl_ProjectionMatrixInverse */
- /* XXX: fetch uniform mat4 gl_ModelViewProjectionMatrixInverse */
- /* XXX: fetch uniform mat4 gl_TextureMatrixInverse */
- /* XXX: fetch uniform mat4 gl_ModelViewMatrixTranspose */
- /* XXX: fetch uniform mat4 gl_ProjectionMatrixTranspose */
- /* XXX: fetch uniform mat4 gl_ModelViewProjectionMatrixTranspose */
- /* XXX: fetch uniform mat4 gl_TextureMatrixTranspose */
- /* XXX: fetch uniform mat4 gl_ModelViewMatrixInverseTranspose */
- /* XXX: fetch uniform mat4 gl_ProjectionMatrixInverseTranspose */
- /* XXX: fetch uniform mat4 gl_ModelViewProjectionMatrixInverseTranspose */
- /* XXX: fetch uniform mat4 gl_TextureMatrixInverseTranspose */
/* XXX: fetch uniform float gl_NormalScale */
/* XXX: fetch uniform mat4 gl_ClipPlane */
/* XXX: fetch uniform mat4 gl_TextureEnvColor */