draw: use tgsi transform prolog/epilog callbacks in AA line code
Reviewed-by: Charmaine Lee <charmainel@vmware.com>
This commit is contained in:
parent
d77c0a2b52
commit
6581aa441e
|
@ -140,7 +140,6 @@ struct aa_transform_context {
|
||||||
int freeSampler; /** an available sampler for the pstipple */
|
int freeSampler; /** an available sampler for the pstipple */
|
||||||
int maxInput, maxGeneric; /**< max input index found */
|
int maxInput, maxGeneric; /**< max input index found */
|
||||||
int colorTemp, texTemp; /**< temp registers */
|
int colorTemp, texTemp; /**< temp registers */
|
||||||
boolean firstInstruction;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -197,80 +196,80 @@ free_bit(uint bitfield)
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TGSI instruction transform callback.
|
* TGSI transform prolog callback.
|
||||||
* Replace writes to result.color w/ a temp reg.
|
|
||||||
* Upon END instruction, insert texture sampling code for antialiasing.
|
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
aa_transform_inst(struct tgsi_transform_context *ctx,
|
aa_transform_prolog(struct tgsi_transform_context *ctx)
|
||||||
struct tgsi_full_instruction *inst)
|
{
|
||||||
|
struct aa_transform_context *aactx = (struct aa_transform_context *) ctx;
|
||||||
|
struct tgsi_full_declaration decl;
|
||||||
|
uint i;
|
||||||
|
|
||||||
|
/* find free sampler */
|
||||||
|
aactx->freeSampler = free_bit(aactx->samplersUsed);
|
||||||
|
if (aactx->freeSampler >= PIPE_MAX_SAMPLERS)
|
||||||
|
aactx->freeSampler = PIPE_MAX_SAMPLERS - 1;
|
||||||
|
|
||||||
|
/* find two free temp regs */
|
||||||
|
for (i = 0; i < 32; i++) {
|
||||||
|
if ((aactx->tempsUsed & (1 << i)) == 0) {
|
||||||
|
/* found a free temp */
|
||||||
|
if (aactx->colorTemp < 0)
|
||||||
|
aactx->colorTemp = i;
|
||||||
|
else if (aactx->texTemp < 0)
|
||||||
|
aactx->texTemp = i;
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert(aactx->colorTemp >= 0);
|
||||||
|
assert(aactx->texTemp >= 0);
|
||||||
|
|
||||||
|
/* declare new generic input/texcoord */
|
||||||
|
decl = tgsi_default_full_declaration();
|
||||||
|
decl.Declaration.File = TGSI_FILE_INPUT;
|
||||||
|
/* XXX this could be linear... */
|
||||||
|
decl.Declaration.Interpolate = 1;
|
||||||
|
decl.Declaration.Semantic = 1;
|
||||||
|
decl.Semantic.Name = TGSI_SEMANTIC_GENERIC;
|
||||||
|
decl.Semantic.Index = aactx->maxGeneric + 1;
|
||||||
|
decl.Range.First =
|
||||||
|
decl.Range.Last = aactx->maxInput + 1;
|
||||||
|
decl.Interp.Interpolate = TGSI_INTERPOLATE_PERSPECTIVE;
|
||||||
|
ctx->emit_declaration(ctx, &decl);
|
||||||
|
|
||||||
|
/* declare new sampler */
|
||||||
|
decl = tgsi_default_full_declaration();
|
||||||
|
decl.Declaration.File = TGSI_FILE_SAMPLER;
|
||||||
|
decl.Range.First =
|
||||||
|
decl.Range.Last = aactx->freeSampler;
|
||||||
|
ctx->emit_declaration(ctx, &decl);
|
||||||
|
|
||||||
|
/* declare new temp regs */
|
||||||
|
decl = tgsi_default_full_declaration();
|
||||||
|
decl.Declaration.File = TGSI_FILE_TEMPORARY;
|
||||||
|
decl.Range.First =
|
||||||
|
decl.Range.Last = aactx->texTemp;
|
||||||
|
ctx->emit_declaration(ctx, &decl);
|
||||||
|
|
||||||
|
decl = tgsi_default_full_declaration();
|
||||||
|
decl.Declaration.File = TGSI_FILE_TEMPORARY;
|
||||||
|
decl.Range.First =
|
||||||
|
decl.Range.Last = aactx->colorTemp;
|
||||||
|
ctx->emit_declaration(ctx, &decl);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TGSI transform epilog callback.
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
aa_transform_epilog(struct tgsi_transform_context *ctx)
|
||||||
{
|
{
|
||||||
struct aa_transform_context *aactx = (struct aa_transform_context *) ctx;
|
struct aa_transform_context *aactx = (struct aa_transform_context *) ctx;
|
||||||
|
|
||||||
if (aactx->firstInstruction) {
|
if (aactx->colorOutput != -1) {
|
||||||
/* emit our new declarations before the first instruction */
|
/* insert texture sampling code for antialiasing. */
|
||||||
|
|
||||||
struct tgsi_full_declaration decl;
|
|
||||||
uint i;
|
|
||||||
|
|
||||||
/* find free sampler */
|
|
||||||
aactx->freeSampler = free_bit(aactx->samplersUsed);
|
|
||||||
if (aactx->freeSampler >= PIPE_MAX_SAMPLERS)
|
|
||||||
aactx->freeSampler = PIPE_MAX_SAMPLERS - 1;
|
|
||||||
|
|
||||||
/* find two free temp regs */
|
|
||||||
for (i = 0; i < 32; i++) {
|
|
||||||
if ((aactx->tempsUsed & (1 << i)) == 0) {
|
|
||||||
/* found a free temp */
|
|
||||||
if (aactx->colorTemp < 0)
|
|
||||||
aactx->colorTemp = i;
|
|
||||||
else if (aactx->texTemp < 0)
|
|
||||||
aactx->texTemp = i;
|
|
||||||
else
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
assert(aactx->colorTemp >= 0);
|
|
||||||
assert(aactx->texTemp >= 0);
|
|
||||||
|
|
||||||
/* declare new generic input/texcoord */
|
|
||||||
decl = tgsi_default_full_declaration();
|
|
||||||
decl.Declaration.File = TGSI_FILE_INPUT;
|
|
||||||
/* XXX this could be linear... */
|
|
||||||
decl.Declaration.Interpolate = 1;
|
|
||||||
decl.Declaration.Semantic = 1;
|
|
||||||
decl.Semantic.Name = TGSI_SEMANTIC_GENERIC;
|
|
||||||
decl.Semantic.Index = aactx->maxGeneric + 1;
|
|
||||||
decl.Range.First =
|
|
||||||
decl.Range.Last = aactx->maxInput + 1;
|
|
||||||
decl.Interp.Interpolate = TGSI_INTERPOLATE_PERSPECTIVE;
|
|
||||||
ctx->emit_declaration(ctx, &decl);
|
|
||||||
|
|
||||||
/* declare new sampler */
|
|
||||||
decl = tgsi_default_full_declaration();
|
|
||||||
decl.Declaration.File = TGSI_FILE_SAMPLER;
|
|
||||||
decl.Range.First =
|
|
||||||
decl.Range.Last = aactx->freeSampler;
|
|
||||||
ctx->emit_declaration(ctx, &decl);
|
|
||||||
|
|
||||||
/* declare new temp regs */
|
|
||||||
decl = tgsi_default_full_declaration();
|
|
||||||
decl.Declaration.File = TGSI_FILE_TEMPORARY;
|
|
||||||
decl.Range.First =
|
|
||||||
decl.Range.Last = aactx->texTemp;
|
|
||||||
ctx->emit_declaration(ctx, &decl);
|
|
||||||
|
|
||||||
decl = tgsi_default_full_declaration();
|
|
||||||
decl.Declaration.File = TGSI_FILE_TEMPORARY;
|
|
||||||
decl.Range.First =
|
|
||||||
decl.Range.Last = aactx->colorTemp;
|
|
||||||
ctx->emit_declaration(ctx, &decl);
|
|
||||||
|
|
||||||
aactx->firstInstruction = FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (inst->Instruction.Opcode == TGSI_OPCODE_END &&
|
|
||||||
aactx->colorOutput != -1) {
|
|
||||||
struct tgsi_full_instruction newInst;
|
struct tgsi_full_instruction newInst;
|
||||||
|
|
||||||
/* TEX */
|
/* TEX */
|
||||||
|
@ -286,7 +285,6 @@ aa_transform_inst(struct tgsi_transform_context *ctx,
|
||||||
newInst.Src[0].Register.Index = aactx->maxInput + 1;
|
newInst.Src[0].Register.Index = aactx->maxInput + 1;
|
||||||
newInst.Src[1].Register.File = TGSI_FILE_SAMPLER;
|
newInst.Src[1].Register.File = TGSI_FILE_SAMPLER;
|
||||||
newInst.Src[1].Register.Index = aactx->freeSampler;
|
newInst.Src[1].Register.Index = aactx->freeSampler;
|
||||||
|
|
||||||
ctx->emit_instruction(ctx, &newInst);
|
ctx->emit_instruction(ctx, &newInst);
|
||||||
|
|
||||||
/* MOV rgb */
|
/* MOV rgb */
|
||||||
|
@ -314,31 +312,34 @@ aa_transform_inst(struct tgsi_transform_context *ctx,
|
||||||
newInst.Src[1].Register.File = TGSI_FILE_TEMPORARY;
|
newInst.Src[1].Register.File = TGSI_FILE_TEMPORARY;
|
||||||
newInst.Src[1].Register.Index = aactx->texTemp;
|
newInst.Src[1].Register.Index = aactx->texTemp;
|
||||||
ctx->emit_instruction(ctx, &newInst);
|
ctx->emit_instruction(ctx, &newInst);
|
||||||
|
|
||||||
/* END */
|
|
||||||
newInst = tgsi_default_full_instruction();
|
|
||||||
newInst.Instruction.Opcode = TGSI_OPCODE_END;
|
|
||||||
newInst.Instruction.NumDstRegs = 0;
|
|
||||||
newInst.Instruction.NumSrcRegs = 0;
|
|
||||||
ctx->emit_instruction(ctx, &newInst);
|
|
||||||
}
|
}
|
||||||
else {
|
}
|
||||||
/* Not an END instruction.
|
|
||||||
* Look for writes to result.color and replace with colorTemp reg.
|
|
||||||
*/
|
|
||||||
uint i;
|
|
||||||
|
|
||||||
for (i = 0; i < inst->Instruction.NumDstRegs; i++) {
|
|
||||||
struct tgsi_full_dst_register *dst = &inst->Dst[i];
|
/**
|
||||||
if (dst->Register.File == TGSI_FILE_OUTPUT &&
|
* TGSI instruction transform callback.
|
||||||
dst->Register.Index == aactx->colorOutput) {
|
* Replace writes to result.color w/ a temp reg.
|
||||||
dst->Register.File = TGSI_FILE_TEMPORARY;
|
*/
|
||||||
dst->Register.Index = aactx->colorTemp;
|
static void
|
||||||
}
|
aa_transform_inst(struct tgsi_transform_context *ctx,
|
||||||
|
struct tgsi_full_instruction *inst)
|
||||||
|
{
|
||||||
|
struct aa_transform_context *aactx = (struct aa_transform_context *) ctx;
|
||||||
|
uint i;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Look for writes to result.color and replace with colorTemp reg.
|
||||||
|
*/
|
||||||
|
for (i = 0; i < inst->Instruction.NumDstRegs; i++) {
|
||||||
|
struct tgsi_full_dst_register *dst = &inst->Dst[i];
|
||||||
|
if (dst->Register.File == TGSI_FILE_OUTPUT &&
|
||||||
|
dst->Register.Index == aactx->colorOutput) {
|
||||||
|
dst->Register.File = TGSI_FILE_TEMPORARY;
|
||||||
|
dst->Register.Index = aactx->colorTemp;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx->emit_instruction(ctx, inst);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ctx->emit_instruction(ctx, inst);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -366,7 +367,8 @@ generate_aaline_fs(struct aaline_stage *aaline)
|
||||||
transform.maxGeneric = -1;
|
transform.maxGeneric = -1;
|
||||||
transform.colorTemp = -1;
|
transform.colorTemp = -1;
|
||||||
transform.texTemp = -1;
|
transform.texTemp = -1;
|
||||||
transform.firstInstruction = TRUE;
|
transform.base.prolog = aa_transform_prolog;
|
||||||
|
transform.base.epilog = aa_transform_epilog;
|
||||||
transform.base.transform_instruction = aa_transform_inst;
|
transform.base.transform_instruction = aa_transform_inst;
|
||||||
transform.base.transform_declaration = aa_transform_decl;
|
transform.base.transform_declaration = aa_transform_decl;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue