extra_dim = get_extra_dim(sampler_type, variant & Proj, unused_fields)
offset_dim = get_sampler_dim(sampler_type)
- # Print parameters
- print " (signature",
if variant & Single:
- print "float"
+ return_type = "float"
else:
- print g + "vec4"
+ return_type = g + "vec4"
+
+ # Print parameters
+ print " (signature", return_type
print " (parameters"
print " (declare (in) " + g + "sampler" + sampler_type + " sampler)"
print " (declare (in) " + vec_type("i" if tex_inst == "txf" else "", coord_dim + extra_dim) + " P)",
if tex_inst == "txb":
print "\n (declare (in) float bias)",
- print ")\n ((return (" + tex_inst + " (var_ref sampler)",
+ print ")\n ((return (" + tex_inst, return_type, "(var_ref sampler)",
# Coordinate
if extra_dim > 0:
void
-ir_texture::set_sampler(ir_dereference *sampler)
+ir_texture::set_sampler(ir_dereference *sampler, const glsl_type *type)
{
assert(sampler != NULL);
+ assert(type != NULL);
this->sampler = sampler;
+ this->type = type;
- switch (sampler->type->sampler_type) {
- case GLSL_TYPE_FLOAT:
- this->type = glsl_type::vec4_type;
- break;
- case GLSL_TYPE_INT:
- this->type = glsl_type::ivec4_type;
- break;
- case GLSL_TYPE_UINT:
- this->type = glsl_type::uvec4_type;
- break;
- }
+ assert(sampler->type->sampler_type == type->base_type);
+ if (sampler->type->sampler_shadow)
+ assert(type->vector_elements == 4 || type->vector_elements == 1);
+ else
+ assert(type->vector_elements == 4);
}
* selected from \c ir_texture_opcodes. In the printed IR, these will
* appear as:
*
- * Texel offset (0 or an expression)
- * | Projection divisor
- * | | Shadow comparitor
- * | | |
- * v v v
- * (tex <sampler> <coordinate> 0 1 ( ))
- * (txb <sampler> <coordinate> 0 1 ( ) <bias>)
- * (txl <sampler> <coordinate> 0 1 ( ) <lod>)
- * (txd <sampler> <coordinate> 0 1 ( ) (dPdx dPdy))
- * (txf <sampler> <coordinate> 0 <lod>)
+ * Texel offset (0 or an expression)
+ * | Projection divisor
+ * | | Shadow comparitor
+ * | | |
+ * v v v
+ * (tex <type> <sampler> <coordinate> 0 1 ( ))
+ * (txb <type> <sampler> <coordinate> 0 1 ( ) <bias>)
+ * (txl <type> <sampler> <coordinate> 0 1 ( ) <lod>)
+ * (txd <type> <sampler> <coordinate> 0 1 ( ) (dPdx dPdy))
+ * (txf <type> <sampler> <coordinate> 0 <lod>)
*/
class ir_texture : public ir_rvalue {
public:
*/
const char *opcode_string();
- /** Set the sampler and infer the type. */
- void set_sampler(ir_dereference *sampler);
+ /** Set the sampler and type. */
+ void set_sampler(ir_dereference *sampler, const glsl_type *type);
/**
* Do a reverse-lookup to translate a string into an ir_texture_opcode.
{
printf("(%s ", ir->opcode_string());
+ print_type(ir->type);
+ printf(" ");
+
ir->sampler->accept(this);
printf(" ");
ir_reader::read_texture(s_expression *expr)
{
s_symbol *tag = NULL;
+ s_expression *s_type = NULL;
s_expression *s_sampler = NULL;
s_expression *s_coord = NULL;
s_expression *s_offset = NULL;
ir_texture_opcode op = ir_tex; /* silence warning */
s_pattern tex_pattern[] =
- { "tex", s_sampler, s_coord, s_offset, s_proj, s_shadow };
+ { "tex", s_type, s_sampler, s_coord, s_offset, s_proj, s_shadow };
s_pattern txf_pattern[] =
- { "txf", s_sampler, s_coord, s_offset, s_lod };
+ { "txf", s_type, s_sampler, s_coord, s_offset, s_lod };
s_pattern other_pattern[] =
- { tag, s_sampler, s_coord, s_offset, s_proj, s_shadow, s_lod };
+ { tag, s_type, s_sampler, s_coord, s_offset, s_proj, s_shadow, s_lod };
if (MATCH(expr, tex_pattern)) {
op = ir_tex;
ir_texture *tex = new(mem_ctx) ir_texture(op);
+ // Read return type
+ const glsl_type *type = read_type(s_type);
+ if (type == NULL) {
+ ir_read_error(NULL, "when reading type in (%s ...)",
+ tex->opcode_string());
+ return NULL;
+ }
+
// Read sampler (must be a deref)
ir_dereference *sampler = read_dereference(s_sampler);
if (sampler == NULL) {
tex->opcode_string());
return NULL;
}
- tex->set_sampler(sampler);
+ tex->set_sampler(sampler, type);
// Read coordinate (any rvalue)
tex->coordinate = read_rvalue(s_coord);