From 857dcc09fa89aa676fdc95d318ecc4f7ad9cd70a Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Wed, 16 Jul 2014 21:39:05 -0700 Subject: [PATCH] vc4: Add support for texture rectangles v2: Rebase on helpers change. --- src/gallium/drivers/vc4/vc4_program.c | 39 +++++++++++++++++++++++++++ src/gallium/drivers/vc4/vc4_qir.h | 3 +++ 2 files changed, 42 insertions(+) diff --git a/src/gallium/drivers/vc4/vc4_program.c b/src/gallium/drivers/vc4/vc4_program.c index b45507d154d..a85a0b4d293 100644 --- a/src/gallium/drivers/vc4/vc4_program.c +++ b/src/gallium/drivers/vc4/vc4_program.c @@ -303,6 +303,22 @@ tgsi_to_qir_tex(struct tgsi_to_qir *trans, t = qir_FMUL(c, t, proj); } + /* There is no native support for GL texture rectangle coordinates, so + * we have to rescale from ([0, width], [0, height]) to ([0, 1], [0, + * 1]). + */ + if (tgsi_inst->Texture.Texture == TGSI_TEXTURE_RECT) { + uint32_t sampler = 0; /* XXX */ + s = qir_FMUL(c, s, + get_temp_for_uniform(trans, + QUNIFORM_TEXRECT_SCALE_X, + sampler)); + t = qir_FMUL(c, t, + get_temp_for_uniform(trans, + QUNIFORM_TEXRECT_SCALE_Y, + sampler)); + } + uint32_t tex_and_sampler = 0; /* XXX */ qir_TEX_T(c, t, add_uniform(trans, QUNIFORM_TEXTURE_CONFIG_P0, tex_and_sampler)); @@ -1170,6 +1186,22 @@ get_texture_p1(struct vc4_texture_stateobj *texstate, (translate_wrap(sampler->wrap_s) << 0)); } +static uint32_t +get_texrect_scale(struct vc4_texture_stateobj *texstate, + enum quniform_contents contents, + uint32_t data) +{ + struct pipe_sampler_view *texture = texstate->textures[data]; + uint32_t dim; + + if (contents == QUNIFORM_TEXRECT_SCALE_X) + dim = texture->texture->width0; + else + dim = texture->texture->height0; + + return fui(1.0f / dim); +} + void vc4_get_uniform_bo(struct vc4_context *vc4, struct vc4_compiled_shader *shader, struct vc4_constbuf_stateobj *cb, @@ -1205,6 +1237,13 @@ vc4_get_uniform_bo(struct vc4_context *vc4, struct vc4_compiled_shader *shader, case QUNIFORM_TEXTURE_CONFIG_P1: map[i] = get_texture_p1(texstate, uinfo->data[i]); break; + + case QUNIFORM_TEXRECT_SCALE_X: + case QUNIFORM_TEXRECT_SCALE_Y: + map[i] = get_texrect_scale(texstate, + uinfo->contents[i], + uinfo->data[i]); + break; } #if 0 fprintf(stderr, "%p/%d: %d: 0x%08x (%f)\n", diff --git a/src/gallium/drivers/vc4/vc4_qir.h b/src/gallium/drivers/vc4/vc4_qir.h index a76d091b327..1b450cac8c5 100644 --- a/src/gallium/drivers/vc4/vc4_qir.h +++ b/src/gallium/drivers/vc4/vc4_qir.h @@ -157,6 +157,9 @@ enum quniform_contents { * sequence. */ QUNIFORM_TEXTURE_CONFIG_P1, + + QUNIFORM_TEXRECT_SCALE_X, + QUNIFORM_TEXRECT_SCALE_Y, }; struct qcompile { -- 2.30.2