summaryrefslogtreecommitdiffstats
path: root/src/mesa/program/ir_to_mesa.cpp
diff options
context:
space:
mode:
authorEric Anholt <eric@anholt.net>2010-09-28 10:43:56 -0700
committerEric Anholt <eric@anholt.net>2010-09-28 11:37:08 -0700
commita32893221ce253da7bb465e0ec9d0df5f7208d8f (patch)
tree29089780041abb00e713d6e289cfac7e56b46525 /src/mesa/program/ir_to_mesa.cpp
parent723a655ed3f3092f6fa74a903fb774a3cec93b79 (diff)
mesa: Pull ir_to_mesa's sampler number fetcher out to shared code.
Diffstat (limited to 'src/mesa/program/ir_to_mesa.cpp')
-rw-r--r--src/mesa/program/ir_to_mesa.cpp90
1 files changed, 4 insertions, 86 deletions
diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp
index 93b6c305f19..aa2add4174c 100644
--- a/src/mesa/program/ir_to_mesa.cpp
+++ b/src/mesa/program/ir_to_mesa.cpp
@@ -54,6 +54,7 @@ extern "C" {
#include "program/program.h"
#include "program/prog_uniform.h"
#include "program/prog_parameter.h"
+#include "program/sampler.h"
}
static int swizzle_for_size(int size);
@@ -274,8 +275,6 @@ public:
GLboolean try_emit_mad(ir_expression *ir,
int mul_operand);
- int get_sampler_uniform_value(ir_dereference *deref);
-
void *mem_ctx;
};
@@ -1894,89 +1893,6 @@ ir_to_mesa_visitor::visit(ir_call *ir)
this->result = entry->return_reg;
}
-class get_sampler_name : public ir_hierarchical_visitor
-{
-public:
- get_sampler_name(ir_to_mesa_visitor *mesa, ir_dereference *last)
- {
- this->mem_ctx = mesa->mem_ctx;
- this->mesa = mesa;
- this->name = NULL;
- this->offset = 0;
- this->last = last;
- }
-
- virtual ir_visitor_status visit(ir_dereference_variable *ir)
- {
- this->name = ir->var->name;
- return visit_continue;
- }
-
- virtual ir_visitor_status visit_leave(ir_dereference_record *ir)
- {
- this->name = talloc_asprintf(mem_ctx, "%s.%s", name, ir->field);
- return visit_continue;
- }
-
- virtual ir_visitor_status visit_leave(ir_dereference_array *ir)
- {
- ir_constant *index = ir->array_index->as_constant();
- int i;
-
- if (index) {
- i = index->value.i[0];
- } else {
- /* GLSL 1.10 and 1.20 allowed variable sampler array indices,
- * while GLSL 1.30 requires that the array indices be
- * constant integer expressions. We don't expect any driver
- * to actually work with a really variable array index, so
- * all that would work would be an unrolled loop counter that ends
- * up being constant above.
- */
- mesa->shader_program->InfoLog =
- talloc_asprintf_append(mesa->shader_program->InfoLog,
- "warning: Variable sampler array index "
- "unsupported.\nThis feature of the language "
- "was removed in GLSL 1.20 and is unlikely "
- "to be supported for 1.10 in Mesa.\n");
- i = 0;
- }
- if (ir != last) {
- this->name = talloc_asprintf(mem_ctx, "%s[%d]", name, i);
- } else {
- offset = i;
- }
- return visit_continue;
- }
-
- ir_to_mesa_visitor *mesa;
- const char *name;
- void *mem_ctx;
- int offset;
- ir_dereference *last;
-};
-
-int
-ir_to_mesa_visitor::get_sampler_uniform_value(ir_dereference *sampler)
-{
- get_sampler_name getname(this, sampler);
-
- sampler->accept(&getname);
-
- GLint index = _mesa_lookup_parameter_index(prog->Parameters, -1,
- getname.name);
-
- if (index < 0) {
- fail_link(this->shader_program,
- "failed to find sampler named %s.\n", getname.name);
- return 0;
- }
-
- index += getname.offset;
-
- return this->prog->Parameters->ParameterValues[index][0];
-}
-
void
ir_to_mesa_visitor::visit(ir_texture *ir)
{
@@ -2076,7 +1992,9 @@ ir_to_mesa_visitor::visit(ir_texture *ir)
if (ir->shadow_comparitor)
inst->tex_shadow = GL_TRUE;
- inst->sampler = get_sampler_uniform_value(ir->sampler);
+ inst->sampler = _mesa_get_sampler_uniform_value(ir->sampler,
+ this->shader_program,
+ this->prog);
const glsl_type *sampler_type = ir->sampler->type;