From 145fef9636a7f6a1b371861a887657cef21bdb3d Mon Sep 17 00:00:00 2001 From: Roland Scheidegger Date: Mon, 15 Sep 2014 19:10:10 +0200 Subject: [PATCH] gallivm: handle SAMPLE opcode in aos sampling This is just a very limited version, in particular sampler and sampler view index must be the same. It cannot handle any modifiers neither. Works much the same as soa version otherwise, to figure out the target we need to store the sampler view dcls. While here, also handle (no-op) RET and get rid of a couple bogus deprecated comments. Reviewed-by: Jose Fonseca --- src/gallium/auxiliary/gallivm/lp_bld_tgsi.h | 2 + .../auxiliary/gallivm/lp_bld_tgsi_aos.c | 61 +++++++++++++++---- 2 files changed, 50 insertions(+), 13 deletions(-) diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h b/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h index 88ac3c9b068..85411ce4817 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h @@ -538,6 +538,8 @@ struct lp_build_tgsi_aos_context struct lp_build_sampler_aos *sampler; + struct tgsi_declaration_sampler_view sv[PIPE_MAX_SHADER_SAMPLER_VIEWS]; + LLVMValueRef immediates[LP_MAX_INLINED_IMMEDIATES]; LLVMValueRef temps[LP_MAX_INLINED_TEMPS]; LLVMValueRef addr[LP_MAX_TGSI_ADDRS]; diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_aos.c b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_aos.c index 4dee9bb4dd4..f2fc7b0e6e7 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_aos.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_aos.c @@ -391,6 +391,37 @@ emit_tex(struct lp_build_tgsi_aos_context *bld, } +static LLVMValueRef +emit_sample(struct lp_build_tgsi_aos_context *bld, + const struct tgsi_full_instruction *inst, + enum lp_build_tex_modifier modifier) +{ + unsigned target; + unsigned unit; + LLVMValueRef coords; + struct lp_derivatives derivs = { {NULL}, {NULL} }; + + if (!bld->sampler) { + _debug_printf("warning: found texture instruction but no sampler generator supplied\n"); + return bld->bld_base.base.undef; + } + + coords = lp_build_emit_fetch( &bld->bld_base, inst, 0 , LP_CHAN_ALL); + + /* ignore modifiers, can't handle different sampler / sampler view, etc... */ + unit = inst->Src[1].Register.Index; + assert(inst->Src[2].Register.Index == unit); + + target = bld->sv[unit].Resource; + + return bld->sampler->emit_fetch_texel(bld->sampler, + &bld->bld_base.base, + target, unit, + coords, derivs, + modifier); +} + + void lp_emit_declaration_aos( struct lp_build_tgsi_aos_context *bld, @@ -430,6 +461,17 @@ lp_emit_declaration_aos( bld->preds[idx] = lp_build_alloca(gallivm, vec_type, ""); break; + case TGSI_FILE_SAMPLER_VIEW: + /* + * The target stored here MUST match whatever there actually + * is in the set sampler views (what about return type?). + */ + assert(last < PIPE_MAX_SHADER_SAMPLER_VIEWS); + for (idx = first; idx <= last; ++idx) { + bld->sv[idx] = decl->SamplerView; + } + break; + default: /* don't need to declare other vars */ break; @@ -782,7 +824,8 @@ lp_emit_instruction_aos( return FALSE; case TGSI_OPCODE_RET: - return FALSE; + /* safe to ignore at end */ + break; case TGSI_OPCODE_END: *pc = -1; @@ -815,7 +858,6 @@ lp_emit_instruction_aos( return FALSE; case TGSI_OPCODE_DIV: - /* deprecated */ assert(0); return FALSE; break; @@ -874,13 +916,11 @@ lp_emit_instruction_aos( break; case TGSI_OPCODE_I2F: - /* deprecated? */ assert(0); return FALSE; break; case TGSI_OPCODE_NOT: - /* deprecated? */ assert(0); return FALSE; break; @@ -891,55 +931,46 @@ lp_emit_instruction_aos( break; case TGSI_OPCODE_SHL: - /* deprecated? */ assert(0); return FALSE; break; case TGSI_OPCODE_ISHR: - /* deprecated? */ assert(0); return FALSE; break; case TGSI_OPCODE_AND: - /* deprecated? */ assert(0); return FALSE; break; case TGSI_OPCODE_OR: - /* deprecated? */ assert(0); return FALSE; break; case TGSI_OPCODE_MOD: - /* deprecated? */ assert(0); return FALSE; break; case TGSI_OPCODE_XOR: - /* deprecated? */ assert(0); return FALSE; break; case TGSI_OPCODE_SAD: - /* deprecated? */ assert(0); return FALSE; break; case TGSI_OPCODE_TXF: - /* deprecated? */ assert(0); return FALSE; break; case TGSI_OPCODE_TXQ: - /* deprecated? */ assert(0); return FALSE; break; @@ -958,6 +989,10 @@ lp_emit_instruction_aos( case TGSI_OPCODE_NOP: break; + case TGSI_OPCODE_SAMPLE: + dst0 = emit_sample(bld, inst, LP_BLD_TEX_MODIFIER_NONE); + break; + default: return FALSE; } -- 2.30.2