summaryrefslogtreecommitdiffstats
path: root/src/mesa/shader/slang/slang_emit.c
diff options
context:
space:
mode:
authorBrian Paul <[email protected]>2008-08-25 09:20:00 -0600
committerBrian Paul <[email protected]>2008-08-25 09:20:00 -0600
commit2d5087bf74f2d0e58037847058a123fe9d142038 (patch)
tree5e7069b458ac130267908f7e24ef66d2a25aa1d9 /src/mesa/shader/slang/slang_emit.c
parentd6df735f1c22c64c17103dd92fffd7b658a46cda (diff)
mesa: glsl: grab latest fixes from gallium-0.1 branch
Includes: 1. Fixes failed asserting about bad swizzles in src reg emit. 2. Tracks uniform var usage. 3. Emit exp() in terms of EXP2 instruction.
Diffstat (limited to 'src/mesa/shader/slang/slang_emit.c')
-rw-r--r--src/mesa/shader/slang/slang_emit.c158
1 files changed, 103 insertions, 55 deletions
diff --git a/src/mesa/shader/slang/slang_emit.c b/src/mesa/shader/slang/slang_emit.c
index f0c3791f2a1..9e8daa10517 100644
--- a/src/mesa/shader/slang/slang_emit.c
+++ b/src/mesa/shader/slang/slang_emit.c
@@ -108,7 +108,9 @@ writemask_to_swizzle(GLuint writemask)
/**
- * Swizzle a swizzle. That is, return swz2(swz1)
+ * Swizzle a swizzle (function composition).
+ * That is, return swz2(swz1), or said another way: swz1.szw2
+ * Example: swizzle_swizzle(".zwxx", ".xxyw") yields ".zzwx"
*/
GLuint
_slang_swizzle_swizzle(GLuint swz1, GLuint swz2)
@@ -279,7 +281,7 @@ storage_to_src_reg(struct prog_src_register *src, const slang_ir_storage *st)
while (st->Parent) {
st = st->Parent;
index += st->Index;
- swizzle = _slang_swizzle_swizzle(st->Swizzle, swizzle);
+ swizzle = _slang_swizzle_swizzle(fix_swizzle(st->Swizzle), swizzle);
}
assert(st->File >= 0);
@@ -1636,6 +1638,88 @@ emit_struct_field(slang_emit_info *emitInfo, slang_ir_node *n)
}
+/**
+ * Emit code for a variable declaration.
+ * This usually doesn't result in any code generation, but just
+ * memory allocation.
+ */
+static struct prog_instruction *
+emit_var_decl(slang_emit_info *emitInfo, slang_ir_node *n)
+{
+ struct prog_instruction *inst;
+
+ assert(n->Store);
+ assert(n->Store->File != PROGRAM_UNDEFINED);
+ assert(n->Store->Size > 0);
+ /*assert(n->Store->Index < 0);*/
+
+ if (!n->Var || n->Var->isTemp) {
+ /* a nameless/temporary variable, will be freed after first use */
+ /*NEW*/
+ if (n->Store->Index < 0 && !_slang_alloc_temp(emitInfo->vt, n->Store)) {
+ slang_info_log_error(emitInfo->log,
+ "Ran out of registers, too many temporaries");
+ return NULL;
+ }
+ }
+ else {
+ /* a regular variable */
+ _slang_add_variable(emitInfo->vt, n->Var);
+ if (!_slang_alloc_var(emitInfo->vt, n->Store)) {
+ slang_info_log_error(emitInfo->log,
+ "Ran out of registers, too many variables");
+ return NULL;
+ }
+ /*
+ printf("IR_VAR_DECL %s %d store %p\n",
+ (char*) n->Var->a_name, n->Store->Index, (void*) n->Store);
+ */
+ assert(n->Var->aux == n->Store);
+ }
+ if (emitInfo->EmitComments) {
+ /* emit NOP with comment describing the variable's storage location */
+ char s[1000];
+ sprintf(s, "TEMP[%d]%s = variable %s (size %d)",
+ n->Store->Index,
+ _mesa_swizzle_string(n->Store->Swizzle, 0, GL_FALSE),
+ (n->Var ? (char *) n->Var->a_name : "anonymous"),
+ n->Store->Size);
+ inst = emit_comment(emitInfo, s);
+ return inst;
+ }
+ return NULL;
+}
+
+
+/**
+ * Emit code for a reference to a variable.
+ * Actually, no code is generated but we may do some memory alloation.
+ * In particular, state vars (uniforms) are allocated on an as-needed basis.
+ */
+static struct prog_instruction *
+emit_var_ref(slang_emit_info *emitInfo, slang_ir_node *n)
+{
+ assert(n->Store);
+ assert(n->Store->File != PROGRAM_UNDEFINED);
+
+ if (n->Store->File == PROGRAM_STATE_VAR && n->Store->Index < 0) {
+ n->Store->Index = _slang_alloc_statevar(n, emitInfo->prog->Parameters);
+ }
+ else if (n->Store->File == PROGRAM_UNIFORM) {
+ /* mark var as used */
+ _mesa_use_uniform(emitInfo->prog->Parameters, (char *) n->Var->a_name);
+ }
+
+ if (n->Store->Index < 0) {
+ /* probably ran out of registers */
+ return NULL;
+ }
+ assert(n->Store->Size > 0);
+
+ return NULL;
+}
+
+
static struct prog_instruction *
emit(slang_emit_info *emitInfo, slang_ir_node *n)
{
@@ -1671,64 +1755,14 @@ emit(slang_emit_info *emitInfo, slang_ir_node *n)
case IR_VAR_DECL:
/* Variable declaration - allocate a register for it */
- assert(n->Store);
- assert(n->Store->File != PROGRAM_UNDEFINED);
- assert(n->Store->Size > 0);
- /*assert(n->Store->Index < 0);*/
- if (!n->Var || n->Var->isTemp) {
- /* a nameless/temporary variable, will be freed after first use */
- /*NEW*/
- if (n->Store->Index < 0 && !_slang_alloc_temp(emitInfo->vt, n->Store)) {
- slang_info_log_error(emitInfo->log,
- "Ran out of registers, too many temporaries");
- return NULL;
- }
- }
- else {
- /* a regular variable */
- _slang_add_variable(emitInfo->vt, n->Var);
- if (!_slang_alloc_var(emitInfo->vt, n->Store)) {
- slang_info_log_error(emitInfo->log,
- "Ran out of registers, too many variables");
- return NULL;
- }
- /*
- printf("IR_VAR_DECL %s %d store %p\n",
- (char*) n->Var->a_name, n->Store->Index, (void*) n->Store);
- */
- assert(n->Var->aux == n->Store);
- }
- if (emitInfo->EmitComments) {
- /* emit NOP with comment describing the variable's storage location */
- char s[1000];
- sprintf(s, "TEMP[%d]%s = variable %s (size %d)",
- n->Store->Index,
- _mesa_swizzle_string(n->Store->Swizzle, 0, GL_FALSE),
- (n->Var ? (char *) n->Var->a_name : "anonymous"),
- n->Store->Size);
- inst = emit_comment(emitInfo, s);
- return inst;
- }
- return NULL;
+ inst = emit_var_decl(emitInfo, n);
+ return inst;
case IR_VAR:
/* Reference to a variable
* Storage should have already been resolved/allocated.
*/
- assert(n->Store);
- assert(n->Store->File != PROGRAM_UNDEFINED);
-
- if (n->Store->File == PROGRAM_STATE_VAR &&
- n->Store->Index < 0) {
- n->Store->Index = _slang_alloc_statevar(n, emitInfo->prog->Parameters);
- }
-
- if (n->Store->Index < 0) {
- /* probably ran out of registers */
- return NULL;
- }
- assert(n->Store->Size > 0);
- break;
+ return emit_var_ref(emitInfo, n);
case IR_ELEMENT:
return emit_array_element(emitInfo, n);
@@ -1939,6 +1973,7 @@ _slang_emit_code(slang_ir_node *n, slang_var_table *vt,
GET_CURRENT_CONTEXT(ctx);
GLboolean success;
slang_emit_info emitInfo;
+ GLuint maxUniforms;
emitInfo.log = log;
emitInfo.vt = vt;
@@ -1955,6 +1990,19 @@ _slang_emit_code(slang_ir_node *n, slang_var_table *vt,
emitInfo.EmitHighLevelInstructions = GL_TRUE;
}
+ /* Check uniform/constant limits */
+ if (prog->Target == GL_FRAGMENT_PROGRAM_ARB) {
+ maxUniforms = ctx->Const.FragmentProgram.MaxUniformComponents / 4;
+ }
+ else {
+ assert(prog->Target == GL_VERTEX_PROGRAM_ARB);
+ maxUniforms = ctx->Const.VertexProgram.MaxUniformComponents / 4;
+ }
+ if (prog->Parameters->NumParameters > maxUniforms) {
+ slang_info_log_error(log, "Constant/uniform register limit exceeded");
+ return GL_FALSE;
+ }
+
(void) emit(&emitInfo, n);
/* finish up by adding the END opcode to program */