summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Li <davidxli@google.com>2011-02-01 14:07:48 -0800
committerDavid Li <davidxli@google.com>2011-02-01 14:07:48 -0800
commitc0025eb1a3d421c0355a21db9d8ea2bd81278460 (patch)
treefe513aadba1bd81519afbad7b3e39ac8a6707049
parent3b02c91d7b1fcc777dbdafeb044e0df61e1ff0d8 (diff)
Attribute, varying and uniform linking.
Signed-off-by: David Li <davidxli@google.com>
-rw-r--r--Android.mk1
-rw-r--r--src/glsl/linker.cpp296
-rw-r--r--src/glsl/main.cpp255
-rw-r--r--src/mesa/main/mtypes.h393
-rw-r--r--src/mesa/program/prog_parameter.cpp34
-rw-r--r--src/mesa/program/prog_parameter.h118
-rw-r--r--src/mesa/program/prog_uniform.h8
7 files changed, 544 insertions, 561 deletions
diff --git a/Android.mk b/Android.mk
index 4264b61..f627284 100644
--- a/Android.mk
+++ b/Android.mk
@@ -103,6 +103,7 @@ mesa_SRC_FILES := \
src/glsl/ir_to_llvm.cpp \
src/glsl/ir_to_llvm_helper.cpp \
src/mesa/program/hash_table.c \
+ src/mesa/program/prog_parameter.cpp \
src/mesa/program/symbol_table.c \
src/pixelflinger2/buffer.cpp \
src/pixelflinger2/format.cpp \
diff --git a/src/glsl/linker.cpp b/src/glsl/linker.cpp
index 57bf4dd..2508b36 100644
--- a/src/glsl/linker.cpp
+++ b/src/glsl/linker.cpp
@@ -68,6 +68,8 @@
#include <cstdarg>
#include <climits>
+#include <pixelflinger2/pixelflinger2_interface.h>
+
extern "C" {
#include <hieralloc.h>
}
@@ -983,19 +985,22 @@ update_array_sizes(struct gl_shader_program *prog)
}
}
-static void
+static int // returns location assigned
add_uniform(void *mem_ctx, exec_list *uniforms, struct hash_table *ht,
const char *name, const glsl_type *type, GLenum shader_type,
unsigned *next_shader_pos, unsigned *total_uniforms, unsigned *next_sampler_pos)
{
+ int index = -1;
if (type->is_record()) {
for (unsigned int i = 0; i < type->length; i++) {
- const glsl_type *field_type = type->fields.structure[i].type;
- char *field_name = hieralloc_asprintf(mem_ctx, "%s.%s", name,
+ const glsl_type *field_type = type->fields.structure[i].type;
+ char *field_name = hieralloc_asprintf(mem_ctx, "%s.%s", name,
type->fields.structure[i].name);
- add_uniform(mem_ctx, uniforms, ht, field_name, field_type,
- shader_type, next_shader_pos, total_uniforms, next_sampler_pos);
+ int firstIndex = add_uniform(mem_ctx, uniforms, ht, field_name, field_type,
+ shader_type, next_shader_pos, total_uniforms, next_sampler_pos);
+ if (i == 0)
+ index = firstIndex;
}
} else {
uniform_node *n = (uniform_node *) hash_table_find(ht, name);
@@ -1003,69 +1008,56 @@ add_uniform(void *mem_ctx, exec_list *uniforms, struct hash_table *ht,
const glsl_type *array_elem_type = NULL;
if (type->is_array()) {
- array_elem_type = type->fields.array;
- /* Array of structures. */
- if (array_elem_type->is_record()) {
- for (unsigned int i = 0; i < type->length; i++) {
- char *elem_name = hieralloc_asprintf(mem_ctx, "%s[%d]", name, i);
- add_uniform(mem_ctx, uniforms, ht, elem_name, array_elem_type,
- shader_type, next_shader_pos, total_uniforms, next_sampler_pos);
- }
- return;
- }
+ array_elem_type = type->fields.array;
+ /* Array of structures. */
+ if (array_elem_type->is_record()) {
+ for (unsigned int i = 0; i < type->length; i++) {
+ char *elem_name = hieralloc_asprintf(mem_ctx, "%s[%d]", name, i);
+ int firstIndex = add_uniform(mem_ctx, uniforms, ht, elem_name, array_elem_type,
+ shader_type, next_shader_pos, total_uniforms, next_sampler_pos);
+ if (i == 0)
+ index = firstIndex;
+ }
+ return index;
+ }
}
/* Fix the storage size of samplers at 1 vec4 each. Be sure to pad out
* vectors to vec4 slots.
*/
if (type->is_array()) {
- if (array_elem_type->is_sampler())
- vec4_slots = type->length;
- else
- vec4_slots = type->length * array_elem_type->matrix_columns;
- } else if (type->is_sampler()) {
- vec4_slots = 1;
- } else {
- vec4_slots = type->matrix_columns;
- }
+ if (array_elem_type->is_sampler())
+ vec4_slots = type->length;
+ else
+ vec4_slots = type->length * array_elem_type->matrix_columns;
+ } else if (type->is_sampler())
+ vec4_slots = 1;
+ else
+ vec4_slots = type->matrix_columns;
if (n == NULL) {
- n = (uniform_node *) calloc(1, sizeof(struct uniform_node));
- n->u = (gl_uniform *) calloc(1, sizeof(struct gl_uniform));
- n->slots = vec4_slots;
-
- n->u->Name = strdup(name);
- n->u->Type = type;
- n->u->VertPos = -1;
- n->u->FragPos = -1;
- n->u->GeomPos = -1;
- (*total_uniforms)++;
+ n = (uniform_node *) calloc(1, sizeof(struct uniform_node));
+ n->u = (gl_uniform *) calloc(1, sizeof(struct gl_uniform));
+ n->slots = vec4_slots;
+
+ n->u->Name = strdup(name);
+ n->u->Type = type;
+ n->u->Pos = *next_shader_pos;
+ (*total_uniforms)++;
- if (type->is_sampler() || (array_elem_type && array_elem_type->is_sampler()))
- {
- n->u->VertPos = n->u->FragPos = n->u->GeomPos = *next_sampler_pos;
- *next_sampler_pos += vec4_slots;
- }
- hash_table_insert(ht, n, name);
- uniforms->push_tail(& n->link);
- }
-
- if (!(type->is_sampler() || (array_elem_type && array_elem_type->is_sampler())))
- {
- switch (shader_type) {
- case GL_VERTEX_SHADER:
- n->u->VertPos = *next_shader_pos;
- break;
- case GL_FRAGMENT_SHADER:
- n->u->FragPos = *next_shader_pos;
- break;
- case GL_GEOMETRY_SHADER:
- n->u->GeomPos = *next_shader_pos;
- break;
- }
- (*next_shader_pos) += vec4_slots;
+ if (type->is_sampler() || (array_elem_type && array_elem_type->is_sampler()))
+ {
+ n->u->Pos = *next_sampler_pos;
+ *next_sampler_pos += vec4_slots;
+ }
+ else
+ (*next_shader_pos) += vec4_slots;
+ hash_table_insert(ht, n, name);
+ uniforms->push_tail(&n->link);
}
+ index = n->u->Pos;
}
+ return index;
}
void
@@ -1077,14 +1069,15 @@ assign_uniform_locations(struct gl_shader_program *prog)
unsigned next_sampler_pos = 0; // all shaders in prog share same sampler location
hash_table *ht = hash_table_ctor(32, hash_table_string_hash,
hash_table_string_compare);
- void *mem_ctx = hieralloc_new(NULL);
+ void *mem_ctx = hieralloc_new(prog);
+
+ unsigned next_position = 0; // also number of slots for uniforms
for (unsigned i = 0; i < MESA_SHADER_TYPES; i++) {
if (prog->_LinkedShaders[i] == NULL)
continue;
- unsigned next_position = 0; // TODO: shouldn't shaders of same prog share uniform location?
-
+
foreach_list(node, prog->_LinkedShaders[i]->ir) {
ir_variable *const var = ((ir_instruction *) node)->as_variable();
@@ -1099,24 +1092,17 @@ assign_uniform_locations(struct gl_shader_program *prog)
continue;
}
- if (var->type->is_sampler() || (var->type->is_array() && var->type->fields.array->is_sampler()))
- var->location = next_sampler_pos;
- else
- var->location = next_position;
- add_uniform(mem_ctx, &uniforms, ht, var->name, var->type,
+ var->location = add_uniform(mem_ctx, &uniforms, ht, var->name, var->type,
prog->_LinkedShaders[i]->Type,
&next_position, &total_uniforms, &next_sampler_pos);
}
}
- hieralloc_free(mem_ctx);
-
- gl_uniform_list *ul = (gl_uniform_list *)
- calloc(1, sizeof(gl_uniform_list));
+ gl_uniform_list *ul = hieralloc_zero(prog, gl_uniform_list);
ul->Size = total_uniforms;
ul->NumUniforms = total_uniforms;
- ul->Uniforms = (gl_uniform *) calloc(total_uniforms, sizeof(gl_uniform));
+ ul->Uniforms = (gl_uniform *)hieralloc_zero_size(ul, total_uniforms * sizeof(gl_uniform));
unsigned idx = 0;
uniform_node *next;
@@ -1136,6 +1122,9 @@ assign_uniform_locations(struct gl_shader_program *prog)
hash_table_dtor(ht);
prog->Uniforms = ul;
+ prog->Uniforms->Slots = next_position;
+
+ hieralloc_free(mem_ctx);
}
@@ -1184,7 +1173,8 @@ assign_attribute_locations(gl_shader_program *prog, unsigned max_attribute_index
/* Operate in a total of four passes.
*
- * 1. Invalidate the location assignments for all vertex shader inputs.
+ * 1. Invalidate the location assignments for all vertex shader inputs,
+ * except for explicit_location and glBindAttribLocation
*
* 2. Assign locations for inputs that have user-defined (via
* glBindVertexAttribLocation) locatoins.
@@ -1196,21 +1186,34 @@ assign_attribute_locations(gl_shader_program *prog, unsigned max_attribute_index
*
* 4. Assign locations to any inputs without assigned locations.
*/
-
- invalidate_variable_locations(sh, ir_var_in, VERT_ATTRIB_GENERIC0);
-
if (prog->Attributes != NULL) {
- for (unsigned i = 0; i < prog->Attributes->NumParameters; i++) {
- ir_variable *const var =
- sh->symbols->get_variable(prog->Attributes->Parameters[i].Name);
-
- /* Note: attributes that occupy multiple slots, such as arrays or
- * matrices, may appear in the attrib array multiple times.
- */
- if ((var == NULL) || (var->location != -1))
- continue;
-
- /* From page 61 of the OpenGL 4.0 spec:
+ // declare attributes if they haven't been already by BindAttribLocation
+ gl_program_parameter_list * attributes = prog->Attributes;
+ foreach_list(node, sh->ir) {
+ ir_variable *const var = ((ir_instruction *) node)->as_variable();
+ if ((var == NULL) || (var->mode != ir_var_in))
+ continue;
+ if (_mesa_get_parameter(attributes, var->name) < 0)
+ _mesa_add_parameter(attributes, var->name);
+ }
+
+ for (unsigned i = 0; i < attributes->NumParameters; i++) {
+ gl_program_parameter * param = attributes->Parameters + i;
+ ir_variable * const var = sh->symbols->get_variable(param->Name);
+ if (!var || ir_var_in != var->mode)
+ continue;
+
+ if (param->BindLocation >= 0 && !var->explicit_location)
+ var->location = param->Location = param->BindLocation;
+ else if (var->explicit_location)
+ param->Location = var->location;
+ else
+ var->location = -1;
+ const unsigned slots = count_attribute_slots(var->type);
+ param->Slots = slots;
+ if (0 > var->location)
+ continue;
+ /* From page 61 of the OpenGL 4.0 spec:
*
* "LinkProgram will fail if the attribute bindings assigned by
* BindAttribLocation do not leave not enough space to assign a
@@ -1240,26 +1243,22 @@ assign_attribute_locations(gl_shader_program *prog, unsigned max_attribute_index
/* FINISHME: The code as currently written does not support attribute
* FINISHME: location aliasing (see comment above).
*/
- const int attr = prog->Attributes->Parameters[i].StateIndexes[0];
- const unsigned slots = count_attribute_slots(var->type);
-
+ const int attr = param->Location;
/* Mask representing the contiguous slots that will be used by this
* attribute.
*/
const unsigned use_mask = (1 << slots) - 1;
-
/* Generate a link error if the set of bits requested for this
* attribute overlaps any previously allocated bits.
*/
- if ((~(use_mask << attr) & used_locations) != used_locations) {
+ if ((use_mask << attr) & used_locations) {
linker_error_printf(prog,
"insufficient contiguous attribute locations "
"available for vertex shader input `%s'",
var->name);
return false;
}
-
- var->location = VERT_ATTRIB_GENERIC0 + attr;
+
used_locations |= (use_mask << attr);
}
}
@@ -1285,16 +1284,14 @@ assign_attribute_locations(gl_shader_program *prog, unsigned max_attribute_index
foreach_list(node, sh->ir) {
ir_variable *const var = ((ir_instruction *) node)->as_variable();
-
if ((var == NULL) || (var->mode != ir_var_in))
- continue;
-
+ continue;
if (var->explicit_location) {
const unsigned slots = count_attribute_slots(var->type);
const unsigned use_mask = (1 << slots) - 1;
- const int attr = var->location - VERT_ATTRIB_GENERIC0;
+ const int attr = var->location/* - VERT_ATTRIB_GENERIC0*/;
- if ((var->location >= (int)(max_attribute_index + VERT_ATTRIB_GENERIC0))
+ if ((var->location >= (int)(max_attribute_index/* + VERT_ATTRIB_GENERIC0*/))
|| (var->location < 0)) {
linker_error_printf(prog,
"invalid explicit location %d specified for "
@@ -1302,7 +1299,7 @@ assign_attribute_locations(gl_shader_program *prog, unsigned max_attribute_index
(var->location < 0) ? var->location : attr,
var->name);
return false;
- } else if (var->location >= VERT_ATTRIB_GENERIC0) {
+ } else if (var->location >= 0/*VERT_ATTRIB_GENERIC0*/) {
used_locations |= (use_mask << attr);
}
}
@@ -1351,8 +1348,11 @@ assign_attribute_locations(gl_shader_program *prog, unsigned max_attribute_index
return false;
}
- to_assign[i].var->location = VERT_ATTRIB_GENERIC0 + location;
+ to_assign[i].var->location = /*VERT_ATTRIB_GENERIC0 +*/ location;
used_locations |= (use_mask << location);
+ int paramIndex = _mesa_get_parameter(prog->Attributes, to_assign[i].var->name);
+ if (0 <= paramIndex)
+ prog->Attributes->Parameters[paramIndex].Location = location;
}
return true;
@@ -1381,14 +1381,15 @@ demote_shader_inputs_and_outputs(gl_shader *sh, enum ir_variable_mode mode)
}
}
+#define VertexOutputOffset(FIELD) (offsetof(VertexOutput,FIELD)/sizeof(Vector4))
void
assign_varying_locations(struct gl_shader_program *prog,
gl_shader *producer, gl_shader *consumer)
{
/* FINISHME: Set dynamically when geometry shader support is added. */
- unsigned output_index = VERT_RESULT_VAR0;
- unsigned input_index = FRAG_ATTRIB_VAR0;
+ unsigned output_index = VertexOutputOffset(varyings); /*VERT_RESULT_VAR0*/;
+ unsigned input_index = VertexOutputOffset(varyings);
/* Operate in a total of three passes.
*
@@ -1400,16 +1401,45 @@ assign_varying_locations(struct gl_shader_program *prog,
* 3. Mark input variables in the consumer that do not have locations as
* not being inputs. This lets the optimizer eliminate them.
*/
-
- invalidate_variable_locations(producer, ir_var_out, VERT_RESULT_VAR0);
- invalidate_variable_locations(consumer, ir_var_in, FRAG_ATTRIB_VAR0);
+ foreach_list(node, producer->ir) {
+ ir_variable *const var = ((ir_instruction *) node)->as_variable();
+ if (!var || ir_var_out != var->mode)
+ continue;
+ if (!strcmp("gl_Position", var->name))
+ var->location = VertexOutputOffset(position);
+ else if (!strcmp("gl_PointSize", var->name))
+ var->location = VertexOutputOffset(pointSize);
+ else
+ var->location = -1;
+ }
+ foreach_list(node, consumer->ir) {
+ ir_variable *const var = ((ir_instruction *) node)->as_variable();
+ if (!var || ir_var_in != var->mode)
+ continue;
+ if (!strcmp("gl_FragCoord", var->name))
+ var->location = VertexOutputOffset(position);
+ else if (!strcmp("gl_FrontFacing", var->name))
+ var->location = VertexOutputOffset(frontFacingPointCoord);
+ else if (!strcmp("gl_PointCoord", var->name))
+ var->location = VertexOutputOffset(frontFacingPointCoord);
+ else
+ var->location = -1;
+ }
foreach_list(node, producer->ir) {
ir_variable *const output_var = ((ir_instruction *) node)->as_variable();
- if ((output_var == NULL) || (output_var->mode != ir_var_out)
- || (output_var->location != -1))
- continue;
+ if ((output_var == NULL) || (output_var->mode != ir_var_out))
+ continue;
+ int paramIndex = _mesa_get_parameter(prog->Varying, output_var->name);
+ if (paramIndex < 0)
+ paramIndex = _mesa_add_parameter(prog->Varying, output_var->name);
+ gl_program_parameter * param = prog->Varying->Parameters + paramIndex;
+ if (output_var->location != -1)
+ {
+ param->BindLocation = output_var->location;
+ continue;
+ }
ir_variable *const input_var =
consumer->symbols->get_variable(output_var->name);
@@ -1419,8 +1449,8 @@ assign_varying_locations(struct gl_shader_program *prog,
assert(input_var->location == -1);
- output_var->location = output_index;
- input_var->location = input_index;
+ param->BindLocation = output_var->location = output_index;
+ param->Location = input_var->location = input_index;
/* FINISHME: Support for "varying" records in GLSL 1.50. */
assert(!output_var->type->is_record());
@@ -1444,9 +1474,13 @@ assign_varying_locations(struct gl_shader_program *prog,
if ((var == NULL) || (var->mode != ir_var_in))
continue;
-
+ int paramIndex = _mesa_get_parameter(prog->Varying, var->name);
+ if (paramIndex < 0)
+ paramIndex = _mesa_add_parameter(prog->Varying, var->name);
+ gl_program_parameter * param = prog->Varying->Parameters + paramIndex;
+
if (var->location == -1) {
- if (prog->Version <= 120) {
+ if (prog->Version <= 120) {
/* On page 25 (page 31 of the PDF) of the GLSL 1.20 spec:
*
* Only those varying variables used (i.e. read) in
@@ -1460,16 +1494,18 @@ assign_varying_locations(struct gl_shader_program *prog,
* "glsl1-varying read but not written" in piglit.
*/
- linker_error_printf(prog, "fragment shader varying %s not written "
- "by vertex shader\n.", var->name);
- prog->LinkStatus = false;
- }
+ linker_error_printf(prog, "fragment shader varying %s not written "
+ "by vertex shader\n.", var->name);
+ prog->LinkStatus = false;
+ }
/* An 'in' variable is only really a shader input if its
* value is written by the previous stage.
*/
- var->mode = ir_var_auto;
+ var->mode = ir_var_auto;
}
+ else
+ param->Location = var->location;
}
}
@@ -1646,7 +1682,7 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog)
assign_varying_locations(prog,
prog->_LinkedShaders[prev],
- prog->_LinkedShaders[i]);
+ prog->_LinkedShaders[i]);
prev = i;
}
@@ -1667,9 +1703,31 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog)
gl_shader *const sh = prog->_LinkedShaders[MESA_SHADER_FRAGMENT];
//demote_shader_inputs_and_outputs(sh, ir_var_in); for testing, don't demote
+
+ foreach_list(node, sh->ir) {
+ ir_variable *const var = ((ir_instruction *) node)->as_variable();
+ if (!var || ir_var_out != var->mode)
+ continue;
+ if (!strcmp("gl_FragColor", var->name) || !strcmp("gl_FragData", var->name))
+ {
+ int paramIndex = _mesa_get_parameter(prog->Varying, var->name);
+ if (0 > paramIndex)
+ paramIndex = _mesa_add_parameter(prog->Varying, var->name);
+ var->location= VertexOutputOffset(fragColor);
+ prog->Varying->Parameters[paramIndex].Location = var->location;
+ }
+ else
+ assert(0);
+ }
}
- /* FINISHME: Assign fragment shader output locations. */
+ //prog->InputOuputBase = malloc(1024 * 8);
+ //memset(prog->InputOuputBase, 0xdd, 1024 * 8);
+ prog->InputOuputBase = hieralloc_realloc(prog, prog->InputOuputBase, char,
+ prog->Uniforms->Slots * 16 + sizeof(VertexInput) + sizeof(VertexOutput) + 16);
+ prog->ValuesVertexInput = (float (*)[4])((((unsigned long)prog->InputOuputBase) + 15) & (~15L));
+ prog->ValuesVertexOutput = (float (*)[4])((unsigned long)prog->ValuesVertexInput + sizeof(VertexInput));
+ prog->ValuesUniform = (float (*)[4])((unsigned long)prog->ValuesVertexOutput + sizeof(VertexOutput));
done:
free(vert_shader_list);
@@ -1684,3 +1742,5 @@ done:
//hieralloc_free(mem_ctx);
}
+
+#undef VertexOutputOffset
diff --git a/src/glsl/main.cpp b/src/glsl/main.cpp
index a4262c1..3d04b8e 100644
--- a/src/glsl/main.cpp
+++ b/src/glsl/main.cpp
@@ -258,6 +258,13 @@ compile_shader(struct gl_context *ctx, struct gl_shader *shader)
return;
}
+struct SymbolLookupContext
+{
+ const GGLContext * gglCtx;
+ const gl_shader_program * program;
+ const gl_shader * shader;
+};
+
#define DRAW_TO_SCREEN 1
#include "image_file.h"
@@ -267,8 +274,9 @@ extern "C" void * PresentDrawingSurface();
extern "C" void DisposeDrawingSurface();
#endif
-void execute(void (* function)(), gl_shader * shader)
+void execute(SymbolLookupContext * ctx)
{
+ const gl_shader * shader = ctx->shader;
#if defined __arm__ && DRAW_TO_SCREEN
unsigned width = 0, height = 0, bpp = 0;
int err = SetupDrawingSurface(&width, &height, &bpp);
@@ -282,11 +290,11 @@ void execute(void (* function)(), gl_shader * shader)
//const unsigned scale = 16, portWidth = 80, portHeight = 50;
//unsigned scale = 1, portWidth = width / scale, portHeight = height / scale;
unsigned scale = 1, portWidth = width / 4, portHeight = height / 4;
-
- float * data = (float *)shader->Source;
- float * constants = data + 36;
- float * outputs = data + 0;
- float * inputs = data + 12;
+
+ float * uniform = (float *)ctx->program->ValuesUniform;
+ float * attribute = (float *)ctx->program->ValuesVertexInput;
+ float * varying = (float *)ctx->program->ValuesVertexOutput;
+ float * output = ((VertexOutput*)ctx->program->ValuesVertexOutput)->fragColor[0].f;
int glFragColorLocation = 0;
int vTexCoordLocation = -1;
if (shader->symbols->get_variable("vTexCoord"))
@@ -294,9 +302,10 @@ void execute(void (* function)(), gl_shader * shader)
int vNormalLocation = -1;
if (shader->symbols->get_variable("vNormal"))
vNormalLocation = shader->symbols->get_variable("vNormal")->location;
- if (shader->symbols->get_variable("uRotM"))
+ if (shader->symbols->get_variable("uRotM") && 0)
{
- float * matrix = data + 4 * 1 + 4 * shader->symbols->get_variable("uRotM")->location;
+ ir_variable * var = shader->symbols->get_variable("uRotM");
+ float * matrix = uniform + 4 * 1 + 4 * shader->symbols->get_variable("uRotM")->location;
memset(matrix, 0, 16 * sizeof(*matrix));
matrix[0] = matrix[5] = matrix[10] = matrix[15] = 1;
matrix[28] = 0;
@@ -304,7 +313,7 @@ void execute(void (* function)(), gl_shader * shader)
matrix[30] = 0;
matrix[31] = 0;
}
- printf("executing... \n function=%p, data=%p \n", function, data);
+ printf("executing... \n function=%p \n", shader->function);
/*
#ifdef __arm__
@@ -325,36 +334,27 @@ void execute(void (* function)(), gl_shader * shader)
//while(true)
for (frames = 1; frames <= 10; frames++)
{
- inputs[2] = 0;
- inputs[3] = 1;
- constants[0] = frames * 0.6f;
-
- //for (unsigned i = 0; i < 480 * 800; i++)
for (unsigned y = 0; y < portHeight; y++)
for (unsigned x = 0; x < portWidth; x++) {
- //data[36] = (float)i / 10000;
- //memset(data, i, sizeof(data));
- //inputs[0] = ((float)x) / (portWidth - 1);
- //inputs[1] = ((float)y) / (portHeight - 1);
if (vTexCoordLocation > -1)
{
- data[1 * 4 + vTexCoordLocation * 4 + 0] = ((float)x) / (portWidth - 1);
- data[1 * 4 + vTexCoordLocation * 4 + 1] = ((float)y) / (portHeight - 1);
- data[1 * 4 + vTexCoordLocation * 4 + 2] = 0;
- data[1 * 4 + vTexCoordLocation * 4 + 3] = 1;
+ varying[vTexCoordLocation * 4 + 0] = ((float)x) / (portWidth - 1);
+ varying[vTexCoordLocation * 4 + 1] = ((float)y) / (portHeight - 1);
+ varying[vTexCoordLocation * 4 + 2] = 0;
+ varying[vTexCoordLocation * 4 + 3] = 1;
}
if (vNormalLocation > -1)
{
- data[1 * 4 + vNormalLocation * 4 + 0] = 0;
- data[1 * 4 + vNormalLocation * 4 + 1] = 1;
- data[1 * 4 + vNormalLocation * 4 + 2] = 0;
- data[1 * 4 + vNormalLocation * 4 + 3] = 1;
+ varying[vNormalLocation * 4 + 0] = 0;
+ varying[vNormalLocation * 4 + 1] = 1;
+ varying[vNormalLocation * 4 + 2] = 0;
+ varying[vNormalLocation * 4 + 3] = 1;
}
- function();
- unsigned r = outputs[0] * 255;
- unsigned g = outputs[1] * 255;
- unsigned b = outputs[2] * 255;
- unsigned a = outputs[3] * 255;
+ shader->function();
+ unsigned r = output[0] * 255;
+ unsigned g = output[1] * 255;
+ unsigned b = output[2] * 255;
+ unsigned a = output[3] * 255;
// unsigned r = *(unsigned *)(outputs + 0);
// unsigned g = *(unsigned *)(outputs + 1);
// unsigned b = *(unsigned *)(outputs + 2);
@@ -381,7 +381,7 @@ void execute(void (* function)(), gl_shader * shader)
float elapsed = (float)(clock() - c0) / CLOCKS_PER_SEC;
printf ("\n *** test_scan elapsed CPU time: %fs \n *** fps=%.2f, tpf=%.2fms \n",
elapsed, frames / elapsed, elapsed / frames * 1000);
- printf("gl_FragColor=%.2f, %.2f, %.2f %.2f \n", outputs[0], outputs[1], outputs[2], outputs[3]);
+ printf("gl_FragColor=%.2f, %.2f, %.2f %.2f \n", output[0], output[1], output[2], output[3]);
//assert(0.1f < outputs[3]);
#if defined __arm__
SaveBMP("/sdcard/mesa.bmp", frameSurface, width, height);
@@ -401,7 +401,7 @@ void execute(void (* function)(), gl_shader * shader)
#include <llvm/ExecutionEngine/JIT.h>
#include <llvm/Target/TargetSelect.h>
-void jit(llvm::Module * mod, gl_shader * shader)
+/*void jit(llvm::Module * mod, gl_shader * shader)
{
#ifndef __arm__
__attribute__ ((aligned (16))) // LLVM generates movaps on X86, needs 16 bytes align
@@ -448,7 +448,7 @@ void jit(llvm::Module * mod, gl_shader * shader)
void (* function)() = (void (*)())ee->getPointerToFunction(func);
execute(function, data);
puts("USE_LLVM_EXECUTIONENGINE");
-}
+}*/
#else
@@ -457,84 +457,61 @@ void jit(llvm::Module * mod, gl_shader * shader)
static void* symbolLookup(void* pContext, const char* name)
{
- gl_shader * shader = (gl_shader *)pContext;
- const GGLContext * gglCtx = (const GGLContext *)shader->Program;
-
- float * data = (float *)shader->Source;
- void * symbol = (void*)dlsym(RTLD_DEFAULT, name);
+ SymbolLookupContext * ctx = (SymbolLookupContext *)pContext;
+ const gl_shader * shader = ctx->shader;
+ const gl_shader_program * program = ctx->program;
+ const GGLContext * gglCtx = ctx->gglCtx;
+ const void * symbol = (void*)dlsym(RTLD_DEFAULT, name);
if (NULL == symbol) {
-// if (0 == strcmp("gl_FragColor", name))
-// symbol = data + 0;
-// else if (0 == strcmp("gl_FragCoord", name))
-// symbol = data + 4;
-// else if (0 == strcmp("gl_FrontFacing", name))
-// symbol = data + 8;
-// else if (0 == strcmp("vTexCoord", name)) {
-// symbol = data + 12;
-// *(data + 12) = 1.1;
-// *(data + 13) = 1.2;
-// *(data + 14) = 1.3;
-// *(data + 15) = 1;
-// } else if (0 == strcmp("uRotM", name)) {
-// symbol = data + 16;
-// memset(data + 16, 0, 16 * sizeof(*data));
-// data[16] = data[21] = data[26] = data[31] = 1;
-// data[28] = 11;
-// data[29] = 22;
-// data[30] = 33;
-// //data[31] = 44;
-// } else if (0 == strcmp("uFragmentColor", name)) {
-// symbol = data + 32;
-// data[32] = 1.57075f;
-// data[33] = 1.57075f;
-// data[34] = 1.57075f;
-// data[35] = 1.57075f;
-// } else if (0 == strcmp("t", name)) {
-// symbol = data + 36;
-// data[36] = 0.1f;
-// }
-
- if (!strcmp("gl_FragColor", name))
- symbol = data + 0;
- else if (!strcmp(_PF2_TEXTURE_DATA_NAME_, name))
+ if (!strcmp(_PF2_TEXTURE_DATA_NAME_, name))
symbol = (void *)gglCtx->textureState.textureData;
else if (!strcmp(_PF2_TEXTURE_DIMENSIONS_NAME_, name))
symbol = (void *)gglCtx->textureState.textureDimensions;
else
{
- ir_variable * var = shader->symbols->get_variable(name);
- if (-1 == var->location)
- var->location = shader->SourceChecksum++;
- else
- shader->SourceChecksum = MAX2(var->location + var->type->matrix_columns, shader->SourceChecksum);
- symbol = data + 4 * 1 + var->location * 4;
- printf("'%s' at %d \n", var->name, var->location);
+ for (unsigned i = 0; i < program->Uniforms->NumUniforms && !symbol; i++)
+ if (!strcmp(program->Uniforms->Uniforms[i].Name, name))
+ symbol = program->ValuesUniform + program->Uniforms->Uniforms[i].Pos;
+ for (unsigned i = 0; i < program->Attributes->NumParameters && !symbol; i++)
+ if (!strcmp(program->Attributes->Parameters[i].Name, name))
+ {
+ assert(program->Attributes->Parameters[i].Location
+ < sizeof(VertexInput) / sizeof(float[4]));
+ symbol = program->ValuesVertexInput + program->Attributes->Parameters[i].Location;
+ }
+ for (unsigned i = 0; i < program->Varying->NumParameters && !symbol; i++)
+ if (!strcmp(program->Varying->Parameters[i].Name, name))
+ {
+ int index = -1;
+ if (GL_VERTEX_SHADER == shader->Type)
+ index = program->Varying->Parameters[i].BindLocation;
+ else if (GL_FRAGMENT_SHADER == shader->Type)
+ index = program->Varying->Parameters[i].Location;
+ else
+ assert(0);
+ assert(index >= 0);
+ assert(index < sizeof(VertexOutput) / sizeof(float[4]));
+ symbol = program->ValuesVertexOutput + index;
+ }
+ assert(symbol >= program->ValuesVertexInput &&
+ symbol < (char *)program->ValuesUniform + 16 * program->Uniforms->Slots - 3);
};
}
printf("symbolLookup '%s'=%p \n", name, symbol);
//getchar();
assert(symbol);
- return symbol;
+ return (void *)symbol;
}
-void jit(llvm::Module * mod, gl_shader * shader)
+void jit(gl_shader * shader, gl_shader_program * program, const GGLContext * gglCtx)
{
-#ifndef __arm__
- __attribute__ ((aligned (16))) // LLVM generates movaps on X86, needs 16 bytes align
-#endif
- float data [64];
- memset(data, 0xff, sizeof(data));
-
- assert(!shader->Source);
- shader->Source = (char *)data; // i/o pool
- assert(!shader->Program);
- shader->Program = (gl_program *)ggl; // pass in context
+ SymbolLookupContext ctx = {gglCtx, program, shader};
BCCScriptRef script = bccCreateScript();
- bccReadModule(script, "glsl", (LLVMModuleRef)mod, 0);
+ bccReadModule(script, "glsl", (LLVMModuleRef)shader->module, 0);
int result = 0;
assert(0 == bccGetError(script));
- bccRegisterSymbolCallback(script, symbolLookup, shader);
+ bccRegisterSymbolCallback(script, symbolLookup, &ctx);
assert(0 == bccGetError(script));
bccPrepareExecutable(script, NULL, 0);
result = bccGetError(script);
@@ -544,18 +521,15 @@ void jit(llvm::Module * mod, gl_shader * shader)
return;
}
- void (* function)() = (void (*)())bccGetFuncAddr(script, "main");
+ shader->function = (void (*)())bccGetFuncAddr(script, "main");
result = bccGetError(script);
if (result != BCC_NO_ERROR)
fprintf(stderr, "Could not find '%s': %d\n", "main", result);
else
- printf("bcc_compile %s=%p \n", "main", function);
+ printf("bcc_compile %s=%p \n", "main", shader->function);
if (GL_FRAGMENT_SHADER == shader->Type)
- execute(function, shader);
-
- shader->Source = NULL;
- shader->Program = NULL;
+ execute(&ctx);
}
#endif
@@ -603,13 +577,14 @@ main(int argc, char **argv)
usage_fail(argv[0]);
initialize_context(ctx, (glsl_es) ? API_OPENGLES2 : API_OPENGL);
-
+ ggl = CreateGGLInterface();
+
struct gl_shader_program *whole_program;
whole_program = hieralloc_zero (NULL, struct gl_shader_program);
assert(whole_program != NULL);
whole_program->Attributes = hieralloc_zero(whole_program, gl_program_parameter_list);
-
+ whole_program->Varying = hieralloc_zero(whole_program, gl_program_parameter_list);
for (/* empty */; argc > optind; optind++) {
whole_program->Shaders = (struct gl_shader **)
hieralloc_realloc(whole_program, whole_program->Shaders,
@@ -648,42 +623,6 @@ main(int argc, char **argv)
status = EXIT_FAILURE;
break;
}
-
- if (GL_VERTEX_SHADER == shader->Type)
- {
- gl_program_parameter_list * attributes = whole_program->Attributes;
- foreach_list(node, shader->ir) {
- ir_variable *const var = ((ir_instruction *) node)->as_variable();
- if ((var == NULL) || (var->mode != ir_var_in))
- continue;
- bool exists = false;
- for (unsigned i = 0; i < attributes->NumParameters; i++)
- if (!strcmp(var->name, attributes->Parameters[i].Name))
- {
- exists = true;
- break;
- }
- if (exists)
- continue;
-
- unsigned vec4_slots = 0;
- if (var->type->is_array())
- vec4_slots = var->type->length * var->type->fields.array->matrix_columns;
- else
- vec4_slots = var->type->matrix_columns;
-
- attributes->NumParameters++;
- attributes->Parameters = hieralloc_realloc(attributes, attributes->Parameters,
- gl_program_parameter, attributes->NumParameters);
-
- gl_program_parameter * attribute = attributes->Parameters + attributes->NumParameters - 1;
- memset(attribute, 0, sizeof(*attribute));
- attribute->Name = hieralloc_strdup(attributes->Parameters, var->name);
- attribute->ExplicitLocation = -1;
- attribute->Location = -1;
- attribute->Slots = vec4_slots;
- }
- }
}
puts("link");
@@ -696,9 +635,24 @@ main(int argc, char **argv)
printf("Info log for linking:\n%s\n", whole_program->InfoLog);
}
+ for (unsigned i = 0; i < whole_program->Attributes->NumParameters; i++)
+ {
+ const gl_program_parameter & attribute = whole_program->Attributes->Parameters[i];
+ printf("attribute '%s': location=%d slots=%d \n", attribute.Name, attribute.Location, attribute.Slots);
+ }
+ for (unsigned i = 0; i < whole_program->Varying->NumParameters; i++)
+ {
+ const gl_program_parameter & varying = whole_program->Varying->Parameters[i];
+ printf("varying '%s': vs_location=%d fs_location=%d \n", varying.Name, varying.BindLocation, varying.Location);
+ }
+ for (unsigned i = 0; i < whole_program->Uniforms->NumUniforms; i++)
+ {
+ const gl_uniform & uniform = whole_program->Uniforms->Uniforms[i];
+ printf("uniform '%s': location=%d type=%s \n", uniform.Name, uniform.Pos, uniform.Type->name);
+ }
+
puts("jit");
- ggl = CreateGGLInterface();
GGLTexture texture = {0};
LoadTGA(texturePath, &texture.width, &texture.height, &texture.levels);
texture.format = GGL_PIXEL_FORMAT_RGBA_8888;
@@ -716,20 +670,6 @@ main(int argc, char **argv)
struct gl_shader *shader = whole_program->_LinkedShaders[i];
if (!shader)
continue;
- for (unsigned i = 0; i < whole_program->Uniforms->NumUniforms; i++)
- {
- const gl_uniform & uniform = whole_program->Uniforms->Uniforms[i];
- ir_variable * var = NULL;
- if (!(var = shader->symbols->get_variable(uniform.Name)))
- continue;
- assert(var->location >= 0);
- printf("uniform '%s': location=%d type=%s \n", uniform.Name, uniform.FragPos, uniform.Type->name);
- }
- for (unsigned i = 0; i < whole_program->Attributes->NumParameters; i++)
- {
- const gl_program_parameter & attribute = whole_program->Attributes->Parameters[i];
- printf("attribute '%s': location=%d slots=%d \n", attribute.Name, attribute.Location, attribute.Slots);
- }
ir_variable * sampler = NULL;
if ((sampler = shader->symbols->get_variable("samp2D")) && sampler->location >= 0)
ggl->SetSampler(ggl, sampler->location, &texture);
@@ -738,18 +678,17 @@ main(int argc, char **argv)
if ((sampler = shader->symbols->get_variable("sampCube")) && sampler->location >= 0)
ggl->SetSampler(ggl, sampler->location, &cubeTexture);
- exec_list * ir = shader->ir;
-
- do_mat_op_to_vec(ir);
+ do_mat_op_to_vec(shader->ir);
puts("\n *** IR for JIT *** \n");
//_mesa_print_ir(ir, NULL);
- llvm::Module * module = glsl_ir_to_llvm_module(ir, (GGLContext *)ggl);
+ llvm::Module * module = glsl_ir_to_llvm_module(shader->ir, (GGLContext *)ggl);
assert(module);
+ shader->module = module;
puts("\n *** Module for JIT *** \n");
//module->dump();
- jit(module, shader);
+ jit(shader, whole_program, (GGLContext *)ggl);
puts("jitted");
}
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 1c549a8..3012396 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2069,8 +2069,8 @@ struct gl_shader
GLboolean Main; /**< shader defines main() */
GLboolean UnresolvedRefs;
const GLchar *Source; /**< Source code string */
- GLuint SourceChecksum; /**< for debug/logging purposes */
- struct gl_program *Program; /**< Post-compile assembly code */
+// GLuint SourceChecksum; /**< for debug/logging purposes */
+// struct gl_program *Program; /**< Post-compile assembly code */
GLchar *InfoLog;
struct gl_sl_pragmas Pragmas;
@@ -2078,6 +2078,8 @@ struct gl_shader
struct exec_list *ir;
struct glsl_symbol_table *symbols;
+ void * module;
+ void (*function)();
/** Shaders containing built-in functions that are used for linking. */
struct gl_shader *builtins_to_link[16];
@@ -2103,31 +2105,30 @@ struct gl_shader_program
struct gl_program_parameter_list *Attributes;
/** Transform feedback varyings */
- struct {
- GLenum BufferMode;
- GLuint NumVarying;
- GLchar **VaryingNames; /**< Array [NumVarying] of char * */
- } TransformFeedback;
+// struct {
+// GLenum BufferMode;
+// GLuint NumVarying;
+// GLchar **VaryingNames; /**< Array [NumVarying] of char * */
+// } TransformFeedback;
/** Geometry shader state - copied into gl_geometry_program at link time */
- struct {
- GLint VerticesOut;
- GLenum InputType; /**< GL_POINTS, GL_LINES, GL_LINES_ADJACENCY_ARB,
- GL_TRIANGLES, or GL_TRIANGLES_ADJACENCY_ARB */
- GLenum OutputType; /**< GL_POINTS, GL_LINE_STRIP or GL_TRIANGLE_STRIP */
- } Geom;
+// struct {
+// GLint VerticesOut;
+// GLenum InputType; /**< GL_POINTS, GL_LINES, GL_LINES_ADJACENCY_ARB,
+// GL_TRIANGLES, or GL_TRIANGLES_ADJACENCY_ARB */
+// GLenum OutputType; /**< GL_POINTS, GL_LINE_STRIP or GL_TRIANGLE_STRIP */
+// } Geom;
/* post-link info: */
- struct gl_vertex_program *VertexProgram; /**< Linked vertex program */
- struct gl_fragment_program *FragmentProgram; /**< Linked fragment prog */
- struct gl_geometry_program *GeometryProgram; /**< Linked geometry prog */
+// struct gl_vertex_program *VertexProgram; /**< Linked vertex program */
+// struct gl_fragment_program *FragmentProgram; /**< Linked fragment prog */
+// struct gl_geometry_program *GeometryProgram; /**< Linked geometry prog */
struct gl_uniform_list *Uniforms;
struct gl_program_parameter_list *Varying;
GLboolean LinkStatus; /**< GL_LINK_STATUS */
GLboolean Validated;
GLboolean _Used; /**< Ever used for drawing? */
GLchar *InfoLog;
-
unsigned Version; /**< GLSL version used for linking */
/**
@@ -2138,6 +2139,10 @@ struct gl_shader_program
* \c NULL.
*/
struct gl_shader *_LinkedShaders[MESA_SHADER_TYPES];
+ GLfloat (*ValuesUniform)[4];
+ GLfloat (*ValuesVertexInput)[4]; /**< actually a VertexInput */
+ GLfloat (*ValuesVertexOutput)[4]; /**< actually a VertexOutput */
+ void * InputOuputBase; /**< allocation base for Values* */
};
@@ -3065,200 +3070,200 @@ typedef enum {
struct gl_context
{
/** State possibly shared with other contexts in the address space */
- struct gl_shared_state *Shared;
+// struct gl_shared_state *Shared;
/** \name API function pointer tables */
/*@{*/
gl_api API;
- struct _glapi_table *Save; /**< Display list save functions */
- struct _glapi_table *Exec; /**< Execute functions */
- struct _glapi_table *CurrentDispatch; /**< == Save or Exec !! */
+// struct _glapi_table *Save; /**< Display list save functions */
+// struct _glapi_table *Exec; /**< Execute functions */
+// struct _glapi_table *CurrentDispatch; /**< == Save or Exec !! */
/*@}*/
- struct gl_config Visual;
- struct gl_framebuffer *DrawBuffer; /**< buffer for writing */
- struct gl_framebuffer *ReadBuffer; /**< buffer for reading */
- struct gl_framebuffer *WinSysDrawBuffer; /**< set with MakeCurrent */
- struct gl_framebuffer *WinSysReadBuffer; /**< set with MakeCurrent */
+// struct gl_config Visual;
+// struct gl_framebuffer *DrawBuffer; /**< buffer for writing */
+// struct gl_framebuffer *ReadBuffer; /**< buffer for reading */
+// struct gl_framebuffer *WinSysDrawBuffer; /**< set with MakeCurrent */
+// struct gl_framebuffer *WinSysReadBuffer; /**< set with MakeCurrent */
/**
* Device driver function pointer table
*/
struct dd_function_table Driver;
- void *DriverCtx; /**< Points to device driver context/state */
+// void *DriverCtx; /**< Points to device driver context/state */
/** Core/Driver constants */
struct gl_constants Const;
- /** \name The various 4x4 matrix stacks */
- /*@{*/
- struct gl_matrix_stack ModelviewMatrixStack;
- struct gl_matrix_stack ProjectionMatrixStack;
- struct gl_matrix_stack TextureMatrixStack[MAX_TEXTURE_UNITS];
- struct gl_matrix_stack ProgramMatrixStack[MAX_PROGRAM_MATRICES];
- struct gl_matrix_stack *CurrentStack; /**< Points to one of the above stacks */
- /*@}*/
-
- /** Combined modelview and projection matrix */
- GLmatrix _ModelProjectMatrix;
-
- /** \name Display lists */
- struct gl_dlist_state ListState;
-
- GLboolean ExecuteFlag; /**< Execute GL commands? */
- GLboolean CompileFlag; /**< Compile GL commands into display list? */
-
- /** Extension information */
+// /** \name The various 4x4 matrix stacks */
+// /*@{*/
+// struct gl_matrix_stack ModelviewMatrixStack;
+// struct gl_matrix_stack ProjectionMatrixStack;
+// struct gl_matrix_stack TextureMatrixStack[MAX_TEXTURE_UNITS];
+// struct gl_matrix_stack ProgramMatrixStack[MAX_PROGRAM_MATRICES];
+// struct gl_matrix_stack *CurrentStack; /**< Points to one of the above stacks */
+// /*@}*/
+//
+// /** Combined modelview and projection matrix */
+// GLmatrix _ModelProjectMatrix;
+
+// /** \name Display lists */
+// struct gl_dlist_state ListState;
+
+// GLboolean ExecuteFlag; /**< Execute GL commands? */
+// GLboolean CompileFlag; /**< Compile GL commands into display list? */
+
+// /** Extension information */
struct gl_extensions Extensions;
-
- /** Version info */
- GLuint VersionMajor, VersionMinor;
- char *VersionString;
-
- /** \name State attribute stack (for glPush/PopAttrib) */
- /*@{*/
- GLuint AttribStackDepth;
- struct gl_attrib_node *AttribStack[MAX_ATTRIB_STACK_DEPTH];
- /*@}*/
-
- /** \name Renderer attribute groups
- *
- * We define a struct for each attribute group to make pushing and popping
- * attributes easy. Also it's a good organization.
- */
- /*@{*/
- struct gl_accum_attrib Accum; /**< Accum buffer attributes */
- struct gl_colorbuffer_attrib Color; /**< Color buffer attributes */
- struct gl_current_attrib Current; /**< Current attributes */
- struct gl_depthbuffer_attrib Depth; /**< Depth buffer attributes */
- struct gl_eval_attrib Eval; /**< Eval attributes */
- struct gl_fog_attrib Fog; /**< Fog attributes */
- struct gl_hint_attrib Hint; /**< Hint attributes */
- struct gl_light_attrib Light; /**< Light attributes */
- struct gl_line_attrib Line; /**< Line attributes */
- struct gl_list_attrib List; /**< List attributes */
- struct gl_multisample_attrib Multisample;
- struct gl_pixel_attrib Pixel; /**< Pixel attributes */
- struct gl_point_attrib Point; /**< Point attributes */
- struct gl_polygon_attrib Polygon; /**< Polygon attributes */
- GLuint PolygonStipple[32]; /**< Polygon stipple */
- struct gl_scissor_attrib Scissor; /**< Scissor attributes */
- struct gl_stencil_attrib Stencil; /**< Stencil buffer attributes */
- struct gl_texture_attrib Texture; /**< Texture attributes */
- struct gl_transform_attrib Transform; /**< Transformation attributes */
- struct gl_viewport_attrib Viewport; /**< Viewport attributes */
- /*@}*/
-
- /** \name Client attribute stack */
- /*@{*/
- GLuint ClientAttribStackDepth;
- struct gl_attrib_node *ClientAttribStack[MAX_CLIENT_ATTRIB_STACK_DEPTH];
- /*@}*/
-
- /** \name Client attribute groups */
- /*@{*/
- struct gl_array_attrib Array; /**< Vertex arrays */
- struct gl_pixelstore_attrib Pack; /**< Pixel packing */
- struct gl_pixelstore_attrib Unpack; /**< Pixel unpacking */
- struct gl_pixelstore_attrib DefaultPacking; /**< Default params */
- /*@}*/
-
- /** \name Other assorted state (not pushed/popped on attribute stack) */
- /*@{*/
- struct gl_pixelmaps PixelMaps;
-
- struct gl_evaluators EvalMap; /**< All evaluators */
- struct gl_feedback Feedback; /**< Feedback */
- struct gl_selection Select; /**< Selection */
-
- struct gl_program_state Program; /**< general program state */
- struct gl_vertex_program_state VertexProgram;
- struct gl_fragment_program_state FragmentProgram;
- struct gl_geometry_program_state GeometryProgram;
- struct gl_ati_fragment_shader_state ATIFragmentShader;
-
- struct gl_shader_state Shader; /**< GLSL shader object state */
- struct gl_shader_compiler_options ShaderCompilerOptions[MESA_SHADER_TYPES];
-
- struct gl_query_state Query; /**< occlusion, timer queries */
-
- struct gl_transform_feedback TransformFeedback;
-
- struct gl_buffer_object *CopyReadBuffer; /**< GL_ARB_copy_buffer */
- struct gl_buffer_object *CopyWriteBuffer; /**< GL_ARB_copy_buffer */
- /*@}*/
-
- struct gl_meta_state *Meta; /**< for "meta" operations */
-
- /* GL_EXT_framebuffer_object */
- struct gl_renderbuffer *CurrentRenderbuffer;
-
- GLenum ErrorValue; /**< Last error code */
-
- /**
- * Recognize and silence repeated error debug messages in buggy apps.
- */
- const char *ErrorDebugFmtString;
- GLuint ErrorDebugCount;
-
- GLenum RenderMode; /**< either GL_RENDER, GL_SELECT, GL_FEEDBACK */
- GLbitfield NewState; /**< bitwise-or of _NEW_* flags */
-
- GLboolean ViewportInitialized; /**< has viewport size been initialized? */
-
- GLbitfield varying_vp_inputs; /**< mask of VERT_BIT_* flags */
-
- /** \name Derived state */
- /*@{*/
- /** Bitwise-or of DD_* flags. Note that this bitfield may be used before
- * state validation so they need to always be current.
- */
- GLbitfield _TriangleCaps;
- GLbitfield _ImageTransferState;/**< bitwise-or of IMAGE_*_BIT flags */
- GLfloat _EyeZDir[3];
- GLfloat _ModelViewInvScale;
- GLboolean _NeedEyeCoords;
- GLboolean _ForceEyeCoords;
-
- GLuint TextureStateTimestamp; /**< detect changes to shared state */
-
- struct gl_shine_tab *_ShineTable[2]; /**< Active shine tables */
- struct gl_shine_tab *_ShineTabList; /**< MRU list of inactive shine tables */
- /**@}*/
-
- struct gl_list_extensions *ListExt; /**< driver dlist extensions */
-
- /** \name For debugging/development only */
- /*@{*/
- GLboolean FirstTimeCurrent;
- /*@}*/
-
- /** Dither disable via MESA_NO_DITHER env var */
- GLboolean NoDither;
-
- /** software compression/decompression supported or not */
- GLboolean Mesa_DXTn;
-
- /**
- * Use dp4 (rather than mul/mad) instructions for position
- * transformation?
- */
- GLboolean mvp_with_dp4;
-
- /**
- * \name Hooks for module contexts.
- *
- * These will eventually live in the driver or elsewhere.
- */
- /*@{*/
- void *swrast_context;
- void *swsetup_context;
- void *swtnl_context;
- void *swtnl_im;
- struct st_context *st;
- void *aelt_context;
- /*@}*/
+//
+// /** Version info */
+// GLuint VersionMajor, VersionMinor;
+// char *VersionString;
+//
+// /** \name State attribute stack (for glPush/PopAttrib) */
+// /*@{*/
+// GLuint AttribStackDepth;
+// struct gl_attrib_node *AttribStack[MAX_ATTRIB_STACK_DEPTH];
+// /*@}*/
+
+// /** \name Renderer attribute groups
+// *
+// * We define a struct for each attribute group to make pushing and popping
+// * attributes easy. Also it's a good organization.
+// */
+// /*@{*/
+// struct gl_accum_attrib Accum; /**< Accum buffer attributes */
+// struct gl_colorbuffer_attrib Color; /**< Color buffer attributes */
+// struct gl_current_attrib Current; /**< Current attributes */
+// struct gl_depthbuffer_attrib Depth; /**< Depth buffer attributes */
+// struct gl_eval_attrib Eval; /**< Eval attributes */
+// struct gl_fog_attrib Fog; /**< Fog attributes */
+// struct gl_hint_attrib Hint; /**< Hint attributes */
+// struct gl_light_attrib Light; /**< Light attributes */
+// struct gl_line_attrib Line; /**< Line attributes */
+// struct gl_list_attrib List; /**< List attributes */
+// struct gl_multisample_attrib Multisample;
+// struct gl_pixel_attrib Pixel; /**< Pixel attributes */
+// struct gl_point_attrib Point; /**< Point attributes */
+// struct gl_polygon_attrib Polygon; /**< Polygon attributes */
+// GLuint PolygonStipple[32]; /**< Polygon stipple */
+// struct gl_scissor_attrib Scissor; /**< Scissor attributes */
+// struct gl_stencil_attrib Stencil; /**< Stencil buffer attributes */
+// struct gl_texture_attrib Texture; /**< Texture attributes */
+// struct gl_transform_attrib Transform; /**< Transformation attributes */
+// struct gl_viewport_attrib Viewport; /**< Viewport attributes */
+// /*@}*/
+//
+// /** \name Client attribute stack */
+// /*@{*/
+// GLuint ClientAttribStackDepth;
+// struct gl_attrib_node *ClientAttribStack[MAX_CLIENT_ATTRIB_STACK_DEPTH];
+// /*@}*/
+//
+// /** \name Client attribute groups */
+// /*@{*/
+// struct gl_array_attrib Array; /**< Vertex arrays */
+// struct gl_pixelstore_attrib Pack; /**< Pixel packing */
+// struct gl_pixelstore_attrib Unpack; /**< Pixel unpacking */
+// struct gl_pixelstore_attrib DefaultPacking; /**< Default params */
+// /*@}*/
+//
+// /** \name Other assorted state (not pushed/popped on attribute stack) */
+// /*@{*/
+// struct gl_pixelmaps PixelMaps;
+
+// struct gl_evaluators EvalMap; /**< All evaluators */
+// struct gl_feedback Feedback; /**< Feedback */
+// struct gl_selection Select; /**< Selection */
+
+// struct gl_program_state Program; /**< general program state */
+// struct gl_vertex_program_state VertexProgram;
+// struct gl_fragment_program_state FragmentProgram;
+// struct gl_geometry_program_state GeometryProgram;
+// struct gl_ati_fragment_shader_state ATIFragmentShader;
+
+// struct gl_shader_state Shader; /**< GLSL shader object state */
+// struct gl_shader_compiler_options ShaderCompilerOptions[MESA_SHADER_TYPES];
+
+// struct gl_query_state Query; /**< occlusion, timer queries */
+
+// struct gl_transform_feedback TransformFeedback;
+
+// struct gl_buffer_object *CopyReadBuffer; /**< GL_ARB_copy_buffer */
+// struct gl_buffer_object *CopyWriteBuffer; /**< GL_ARB_copy_buffer */
+// /*@}*/
+//
+// struct gl_meta_state *Meta; /**< for "meta" operations */
+//
+// /* GL_EXT_framebuffer_object */
+// struct gl_renderbuffer *CurrentRenderbuffer;
+//
+// GLenum ErrorValue; /**< Last error code */
+//
+// /**
+// * Recognize and silence repeated error debug messages in buggy apps.
+// */
+// const char *ErrorDebugFmtString;
+// GLuint ErrorDebugCount;
+
+// GLenum RenderMode; /**< either GL_RENDER, GL_SELECT, GL_FEEDBACK */
+// GLbitfield NewState; /**< bitwise-or of _NEW_* flags */
+
+// GLboolean ViewportInitialized; /**< has viewport size been initialized? */
+
+// GLbitfield varying_vp_inputs; /**< mask of VERT_BIT_* flags */
+//
+// /** \name Derived state */
+// /*@{*/
+// /** Bitwise-or of DD_* flags. Note that this bitfield may be used before
+// * state validation so they need to always be current.
+// */
+// GLbitfield _TriangleCaps;
+// GLbitfield _ImageTransferState;/**< bitwise-or of IMAGE_*_BIT flags */
+// GLfloat _EyeZDir[3];
+// GLfloat _ModelViewInvScale;
+// GLboolean _NeedEyeCoords;
+// GLboolean _ForceEyeCoords;
+//
+// GLuint TextureStateTimestamp; /**< detect changes to shared state */
+
+// struct gl_shine_tab *_ShineTable[2]; /**< Active shine tables */
+// struct gl_shine_tab *_ShineTabList; /**< MRU list of inactive shine tables */
+// /**@}*/
+//
+// struct gl_list_extensions *ListExt; /**< driver dlist extensions */
+//
+// /** \name For debugging/development only */
+// /*@{*/
+// GLboolean FirstTimeCurrent;
+// /*@}*/
+//
+// /** Dither disable via MESA_NO_DITHER env var */
+// GLboolean NoDither;
+//
+// /** software compression/decompression supported or not */
+// GLboolean Mesa_DXTn;
+//
+// /**
+// * Use dp4 (rather than mul/mad) instructions for position
+// * transformation?
+// */
+// GLboolean mvp_with_dp4;
+//
+// /**
+// * \name Hooks for module contexts.
+// *
+// * These will eventually live in the driver or elsewhere.
+// */
+// /*@{*/
+// void *swrast_context;
+// void *swsetup_context;
+// void *swtnl_context;
+// void *swtnl_im;
+// struct st_context *st;
+// void *aelt_context;
+// /*@}*/
};
diff --git a/src/mesa/program/prog_parameter.cpp b/src/mesa/program/prog_parameter.cpp
new file mode 100644
index 0000000..fef639a
--- /dev/null
+++ b/src/mesa/program/prog_parameter.cpp
@@ -0,0 +1,34 @@
+// all allocations need to use hieralloc
+typedef unsigned int size_t;
+
+#include "prog_parameter.h"
+
+#include "src/glsl/ir.h"
+
+extern GLint _mesa_add_parameter(struct gl_program_parameter_list * paramList,
+ const char * name)
+{
+ paramList->NumParameters++;
+ if (paramList->NumParameters > paramList->Size) {
+ paramList->Size = paramList->NumParameters + 4;
+ paramList->Parameters = hieralloc_realloc(paramList, paramList->Parameters,
+ gl_program_parameter, paramList->Size);
+ }
+
+ gl_program_parameter * param = paramList->Parameters + paramList->NumParameters - 1;
+ memset(param, 0, sizeof(*param));
+ param->Name = hieralloc_strdup(paramList, name);
+ param->BindLocation = -1;
+ param->Location = -1;
+
+ return paramList->NumParameters - 1;
+}
+
+extern GLint _mesa_get_parameter(const struct gl_program_parameter_list * paramList,
+ const char * name)
+{
+ for (unsigned i = 0; i < paramList->NumParameters; i++)
+ if (!strcmp(name, paramList->Parameters[i].Name))
+ return i;
+ return -1;
+}
diff --git a/src/mesa/program/prog_parameter.h b/src/mesa/program/prog_parameter.h
index 46df4a1..608b835 100644
--- a/src/mesa/program/prog_parameter.h
+++ b/src/mesa/program/prog_parameter.h
@@ -55,24 +55,28 @@
struct gl_program_parameter
{
const char *Name; /**< Null-terminated string */
- gl_register_file Type; /**< PROGRAM_NAMED_PARAM, CONSTANT or STATE_VAR */
- GLenum DataType; /**< GL_FLOAT, GL_FLOAT_VEC2, etc */
+ //gl_register_file Type; /**< PROGRAM_NAMED_PARAM, CONSTANT or STATE_VAR */
+ //GLenum DataType; /**< GL_FLOAT, GL_FLOAT_VEC2, etc */
/**
* Number of components (1..4), or more.
* If the number of components is greater than 4,
* this parameter is part of a larger uniform like a GLSL matrix or array.
* The next program parameter's Size will be Size-4 of this parameter.
*/
- GLuint Size;
- GLuint Slots; /**< how many slots occupied */
- GLint ExplicitLocation; /**< for attributes, set by BindAttribLocation */
+ //GLuint Size;
+ GLuint Slots; /**< how many float[4] slots occupied */
+ // location starts from 0, such that VERT_ATTRIB_GENERIC0 = 0
+ // since there are no predefined vertex attribs in es20
+ // for varyings BindLocation is vertex output location
+ // and Loctation is fragment input location
+ GLint BindLocation; /**< requested by BindAttribLocation for attributes */
GLint Location; /**< actual location assigned after linking */
- GLboolean Initialized; /**< debug: Has the ParameterValue[] been set? */
- GLbitfield Flags; /**< Bitmask of PROG_PARAM_*_BIT */
+ //GLboolean Initialized; /**< debug: Has the ParameterValue[] been set? */
+ //GLbitfield Flags; /**< Bitmask of PROG_PARAM_*_BIT */
/**
* A sequence of STATE_* tokens and integers to identify GL state.
*/
- gl_state_index StateIndexes[STATE_LENGTH];
+ //gl_state_index StateIndexes[STATE_LENGTH];
};
@@ -84,88 +88,26 @@ struct gl_program_parameter_list
GLuint Size; /**< allocated size of Parameters, ParameterValues */
GLuint NumParameters; /**< number of parameters in arrays */
struct gl_program_parameter *Parameters; /**< Array [Size] */
- GLfloat (*ParameterValues)[4]; /**< Array [Size] of GLfloat[4] */
- GLbitfield StateFlags; /**< _NEW_* flags indicating which state changes
- might invalidate ParameterValues[] */
+ //GLfloat (*ParameterValues)[4]; /**< Array [Size] of GLfloat[4] */
+ //GLbitfield StateFlags; /**< _NEW_* flags indicating which state changes
+ // might invalidate ParameterValues[] */
};
-
-extern struct gl_program_parameter_list *
-_mesa_new_parameter_list(void);
-
-extern struct gl_program_parameter_list *
-_mesa_new_parameter_list_sized(unsigned size);
-
-extern void
-_mesa_free_parameter_list(struct gl_program_parameter_list *paramList);
-
-extern struct gl_program_parameter_list *
-_mesa_clone_parameter_list(const struct gl_program_parameter_list *list);
-
-extern struct gl_program_parameter_list *
-_mesa_combine_parameter_lists(const struct gl_program_parameter_list *a,
- const struct gl_program_parameter_list *b);
-
-static INLINE GLuint
-_mesa_num_parameters(const struct gl_program_parameter_list *list)
-{
- return list ? list->NumParameters : 0;
+#ifdef __cplusplus
+extern "C" {
+class ir_variable;
+#else
+typedef struct ir_variable ir_variable;
+#endif
+
+// returns index in paramList or -1
+GLint _mesa_add_parameter(struct gl_program_parameter_list * paramList,
+ const char * name);
+
+GLint _mesa_get_parameter(const struct gl_program_parameter_list * paramList,
+ const char * name);
+#ifdef __cplusplus
}
-
-extern GLint
-_mesa_add_parameter(struct gl_program_parameter_list *paramList,
- gl_register_file type, const char *name,
- GLuint size, GLenum datatype, const GLfloat *values,
- const gl_state_index state[STATE_LENGTH],
- GLbitfield flags);
-
-extern GLint
-_mesa_add_named_parameter(struct gl_program_parameter_list *paramList,
- const char *name, const GLfloat values[4]);
-
-extern GLint
-_mesa_add_named_constant(struct gl_program_parameter_list *paramList,
- const char *name, const GLfloat values[4],
- GLuint size);
-
-extern GLint
-_mesa_add_unnamed_constant(struct gl_program_parameter_list *paramList,
- const GLfloat values[4], GLuint size,
- GLuint *swizzleOut);
-
-extern GLint
-_mesa_add_varying(struct gl_program_parameter_list *paramList,
- const char *name, GLuint size, GLenum datatype,
- GLbitfield flags);
-
-extern GLint
-_mesa_add_attribute(struct gl_program_parameter_list *paramList,
- const char *name, GLint size, GLenum datatype, GLint attrib);
-
-extern GLint
-_mesa_add_state_reference(struct gl_program_parameter_list *paramList,
- const gl_state_index stateTokens[STATE_LENGTH]);
-
-extern GLfloat *
-_mesa_lookup_parameter_value(const struct gl_program_parameter_list *paramList,
- GLsizei nameLen, const char *name);
-
-extern GLint
-_mesa_lookup_parameter_index(const struct gl_program_parameter_list *paramList,
- GLsizei nameLen, const char *name);
-
-extern GLboolean
-_mesa_lookup_parameter_constant(const struct gl_program_parameter_list *list,
- const GLfloat v[], GLuint vSize,
- GLint *posOut, GLuint *swizzleOut);
-
-extern GLuint
-_mesa_longest_parameter_name(const struct gl_program_parameter_list *list,
- gl_register_file type);
-
-extern GLuint
-_mesa_num_parameters_of_type(const struct gl_program_parameter_list *list,
- gl_register_file type);
-
+#endif
#endif /* PROG_PARAMETER_H */
diff --git a/src/mesa/program/prog_uniform.h b/src/mesa/program/prog_uniform.h
index 67f7800..18c5c71 100644
--- a/src/mesa/program/prog_uniform.h
+++ b/src/mesa/program/prog_uniform.h
@@ -47,9 +47,10 @@
struct gl_uniform
{
const char *Name; /**< Null-terminated string */
- GLint VertPos;
- GLint FragPos;
- GLint GeomPos;
+ //GLint VertPos;
+ //GLint FragPos;
+ //GLint GeomPos;
+ GLint Pos;
GLboolean Initialized; /**< For debug. Has this uniform been set? */
const struct glsl_type *Type;
};
@@ -62,6 +63,7 @@ struct gl_uniform_list
{
GLuint Size; /**< allocated size of Uniforms array */
GLuint NumUniforms; /**< number of uniforms in the array */
+ GLuint Slots; /**< number of float[4] slots uniforms will occupy */
struct gl_uniform *Uniforms; /**< Array [Size] */
};