- static void load_texture( struct texenv_fragment_program *p, GLuint unit )
- {
- ir_dereference *deref;
- ir_assignment *assign;
-
- if (p->src_texture[unit])
- return;
-
- const GLuint texTarget = p->state->unit[unit].source_index;
- ir_rvalue *texcoord;
-
- if (p->texcoord_tex[unit]) {
- texcoord = new(p->mem_ctx) ir_dereference_variable(p->texcoord_tex[unit]);
- }
- else {
- ir_variable *tc_array = p->shader->symbols->get_variable("gl_TexCoord");
- assert(tc_array);
- texcoord = new(p->mem_ctx) ir_dereference_variable(tc_array);
- ir_rvalue *index = new(p->mem_ctx) ir_constant(unit);
- texcoord = new(p->mem_ctx) ir_dereference_array(texcoord, index);
- tc_array->max_array_access = MAX2(tc_array->max_array_access, unit);
- }
-
- if (!p->state->unit[unit].enabled) {
- p->src_texture[unit] = new(p->mem_ctx) ir_variable(glsl_type::vec4_type,
- "dummy_tex",
- ir_var_temporary);
- p->instructions->push_tail(p->src_texture[unit]);
-
- deref = new(p->mem_ctx) ir_dereference_variable(p->src_texture[unit]);
- assign = new(p->mem_ctx) ir_assignment(deref,
- new(p->mem_ctx) ir_constant(0.0f),
- NULL);
- p->instructions->push_tail(assign);
- return ;
- }
-
- const glsl_type *sampler_type = NULL;
- int coords = 0;
-
- switch (texTarget) {
- case TEXTURE_1D_INDEX:
- if (p->state->unit[unit].shadow)
- sampler_type = p->shader->symbols->get_type("sampler1DShadow");
- else
- sampler_type = p->shader->symbols->get_type("sampler1D");
- coords = 1;
- break;
- case TEXTURE_1D_ARRAY_INDEX:
- if (p->state->unit[unit].shadow)
- sampler_type = p->shader->symbols->get_type("sampler1DArrayShadow");
- else
- sampler_type = p->shader->symbols->get_type("sampler1DArray");
- coords = 2;
- break;
- case TEXTURE_2D_INDEX:
- if (p->state->unit[unit].shadow)
- sampler_type = p->shader->symbols->get_type("sampler2DShadow");
- else
- sampler_type = p->shader->symbols->get_type("sampler2D");
- coords = 2;
- break;
- case TEXTURE_2D_ARRAY_INDEX:
- if (p->state->unit[unit].shadow)
- sampler_type = p->shader->symbols->get_type("sampler2DArrayShadow");
- else
- sampler_type = p->shader->symbols->get_type("sampler2DArray");
- coords = 3;
- break;
- case TEXTURE_RECT_INDEX:
- if (p->state->unit[unit].shadow)
- sampler_type = p->shader->symbols->get_type("sampler2DRectShadow");
- else
- sampler_type = p->shader->symbols->get_type("sampler2DRect");
- coords = 2;
- break;
- case TEXTURE_3D_INDEX:
- assert(!p->state->unit[unit].shadow);
- sampler_type = p->shader->symbols->get_type("sampler3D");
- coords = 3;
- break;
- case TEXTURE_CUBE_INDEX:
- if (p->state->unit[unit].shadow)
- sampler_type = p->shader->symbols->get_type("samplerCubeShadow");
- else
- sampler_type = p->shader->symbols->get_type("samplerCube");
- coords = 3;
- break;
- }
-
- p->src_texture[unit] = new(p->mem_ctx) ir_variable(glsl_type::vec4_type,
- "tex",
- ir_var_temporary);
- p->instructions->push_tail(p->src_texture[unit]);
-
- ir_texture *tex = new(p->mem_ctx) ir_texture(ir_tex);
-
-
- char *sampler_name = ralloc_asprintf(p->mem_ctx, "sampler_%d", unit);
- ir_variable *sampler = new(p->mem_ctx) ir_variable(sampler_type,
- sampler_name,
- ir_var_uniform);
- p->top_instructions->push_head(sampler);
- deref = new(p->mem_ctx) ir_dereference_variable(sampler);
- tex->set_sampler(deref);
-
- tex->coordinate = new(p->mem_ctx) ir_swizzle(texcoord, 0, 1, 2, 3, coords);
-
- if (p->state->unit[unit].shadow) {
- texcoord = texcoord->clone(p->mem_ctx, NULL);
- tex->shadow_comparitor = new(p->mem_ctx) ir_swizzle(texcoord,
- coords, 0, 0, 0,
- 1);
- coords++;
- }
-
- texcoord = texcoord->clone(p->mem_ctx, NULL);
- tex->projector = new(p->mem_ctx) ir_swizzle(texcoord, 3, 0, 0, 0, 1);
-
- deref = new(p->mem_ctx) ir_dereference_variable(p->src_texture[unit]);
- assign = new(p->mem_ctx) ir_assignment(deref, tex, NULL);
- p->instructions->push_tail(assign);
- }
+static void load_texture( texenv_fragment_program *p, GLuint unit )
+{
+ ir_dereference *deref;
+
+ if (p->src_texture[unit])
+ return;
+
+ const GLuint texTarget = p->state->unit[unit].source_index;
+ ir_rvalue *texcoord;
+
+ if (!(p->state->inputs_available & (VARYING_BIT_TEX0 << unit))) {
+ texcoord = get_current_attrib(p, VERT_ATTRIB_TEX0 + unit);
+ } else if (p->texcoord_tex[unit]) {
+ texcoord = new(p->mem_ctx) ir_dereference_variable(p->texcoord_tex[unit]);
+ } else {
+ ir_variable *tc_array = p->shader->symbols->get_variable("gl_TexCoord");
+ assert(tc_array);
+ texcoord = new(p->mem_ctx) ir_dereference_variable(tc_array);
+ ir_rvalue *index = new(p->mem_ctx) ir_constant(unit);
+ texcoord = new(p->mem_ctx) ir_dereference_array(texcoord, index);
+ tc_array->data.max_array_access = MAX2(tc_array->data.max_array_access, (int)unit);
+ }
+
+ if (!p->state->unit[unit].enabled) {
+ p->src_texture[unit] = p->make_temp(glsl_type::vec4_type,
+ "dummy_tex");
+ p->emit(p->src_texture[unit]);
+
+ p->emit(assign(p->src_texture[unit], new(p->mem_ctx) ir_constant(0.0f)));
+ return ;
+ }
+
+ const glsl_type *sampler_type = NULL;
+ int coords = 0;
+
+ switch (texTarget) {
+ case TEXTURE_1D_INDEX:
+ if (p->state->unit[unit].shadow)
+ sampler_type = glsl_type::sampler1DShadow_type;
+ else
+ sampler_type = glsl_type::sampler1D_type;
+ coords = 1;
+ break;
+ case TEXTURE_1D_ARRAY_INDEX:
+ if (p->state->unit[unit].shadow)
+ sampler_type = glsl_type::sampler1DArrayShadow_type;
+ else
+ sampler_type = glsl_type::sampler1DArray_type;
+ coords = 2;
+ break;
+ case TEXTURE_2D_INDEX:
+ if (p->state->unit[unit].shadow)
+ sampler_type = glsl_type::sampler2DShadow_type;
+ else
+ sampler_type = glsl_type::sampler2D_type;
+ coords = 2;
+ break;
+ case TEXTURE_2D_ARRAY_INDEX:
+ if (p->state->unit[unit].shadow)
+ sampler_type = glsl_type::sampler2DArrayShadow_type;
+ else
+ sampler_type = glsl_type::sampler2DArray_type;
+ coords = 3;
+ break;
+ case TEXTURE_RECT_INDEX:
+ if (p->state->unit[unit].shadow)
+ sampler_type = glsl_type::sampler2DRectShadow_type;
+ else
+ sampler_type = glsl_type::sampler2DRect_type;
+ coords = 2;
+ break;
+ case TEXTURE_3D_INDEX:
+ assert(!p->state->unit[unit].shadow);
+ sampler_type = glsl_type::sampler3D_type;
+ coords = 3;
+ break;
+ case TEXTURE_CUBE_INDEX:
+ if (p->state->unit[unit].shadow)
+ sampler_type = glsl_type::samplerCubeShadow_type;
+ else
+ sampler_type = glsl_type::samplerCube_type;
+ coords = 3;
+ break;
+ case TEXTURE_EXTERNAL_INDEX:
+ assert(!p->state->unit[unit].shadow);
+ sampler_type = glsl_type::samplerExternalOES_type;
+ coords = 2;
+ break;
+ }
+
+ p->src_texture[unit] = p->make_temp(glsl_type::vec4_type,
+ "tex");
+
+ ir_texture *tex = new(p->mem_ctx) ir_texture(ir_tex);
+
+
+ char *sampler_name = ralloc_asprintf(p->mem_ctx, "sampler_%d", unit);
+ ir_variable *sampler = new(p->mem_ctx) ir_variable(sampler_type,
+ sampler_name,
+ ir_var_uniform);
+ p->top_instructions->push_head(sampler);
+
+ /* Set the texture unit for this sampler in the same way that
+ * layout(binding=X) would.
+ */
+ sampler->data.explicit_binding = true;
+ sampler->data.binding = unit;
+
+ deref = new(p->mem_ctx) ir_dereference_variable(sampler);
+ tex->set_sampler(deref, glsl_type::vec4_type);
+
+ tex->coordinate = new(p->mem_ctx) ir_swizzle(texcoord, 0, 1, 2, 3, coords);
+
+ if (p->state->unit[unit].shadow) {
+ texcoord = texcoord->clone(p->mem_ctx, NULL);
+ tex->shadow_comparator = new(p->mem_ctx) ir_swizzle(texcoord,
+ coords, 0, 0, 0,
+ 1);
+ coords++;
+ }
+
+ texcoord = texcoord->clone(p->mem_ctx, NULL);
+ tex->projector = swizzle_w(texcoord);
+
+ p->emit(assign(p->src_texture[unit], tex));
+}