nv50/gallium: shader generation patches, update
Hi ! Here are some more changes to the shader code to be applied in addition to the previous ones.
Well, I've though about getting an account so I could commit some (or all) of this stuff, probably in splitting some patches up a bit more. But I'd feel much better doing so (if I was even allowed to) if someone (darktama) had a look at my code before, preferably with some comments on how to improve / do / not do things.
Someone testing this stuff and reporting to me whether they see improve- ments as compared to the code currently in mesa master wouldn't be bad either.
Well, if no one has any major complaints, and once I feel a little bit more comfortable with what I've done so far, I'll probably have to ask/apply for a mesa account as Maarten suggested ...
Thank you, Christoph
commit 78f4b96b9b874e487571b59cec22e683f23d2e3e
Author: chr <chr@ECHELON.(none)> Date: Sat May 16 15:33:34 2009 +0200
- Introduce argument negation for MUL, MAD, ADD, DP3, DP4 and POW. This is now done via a negation bitmask in nv50_pc that is checked in the emit functions, the 'neg' member of nv50_reg is obsolete with this.
(maybe I should have used it instead, but I completely forgot
about it and went with this way ...)
- changed emit_sub and emit_msb to use negated emit_add and emit_mad
src/gallium/drivers/nv50/nv50_program.c +81 -49
@@ -117,6 +117,7 @@ struct nv50_pc {unsigned insn_cur;unsigned insn_nr; +unsigned negate;boolean allow32;/* TRUE when half insns are allowed */ };
@@ -531,6 +532,8 @@ emit_mov(struct nv50_pc *pc, struct nv50_reg *dst, struct nv50_reg *src)emit (pc, e); } +#define BITS_0_1_SWAPPED (x) ((x & 1) << 1) | ((x & 2) >> 1) +static boolean check_swap_src_0_1 (struct nv50_pc *pc,struct nv50_reg **s0,struct nv50_reg **s1)
@@ -628,14 +631,6 @@ set_src_2(struct nv50_pc *pc, struct nv50_reg *src, struct nv50_program_exec *e) e->inst[1 ] |= (src->hw <<14 ); } -static boolean -requires_long (struct nv50_program_exec *e,struct nv50_reg *src) -{ -if (is_long (e) || src->type ==P_IMMD || src->type ==P_CONST ) -return TRUE; -return FALSE; -} -static void emit_mul (struct nv50_pc *pc,struct nv50_reg *dst,struct nv50_reg *src0,struct nv50_reg *src1)
@@ -650,6 +645,13 @@ emit_mul(struct nv50_pc *pc, struct nv50_reg *dst, struct nv50_reg *src0,set_src_0 (pc, src0, e);set_src_1 (pc, src1, e); +if (pc->negate &1 ) { +if (is_long (e)) + e->inst[1 ] |=0x08000000 ; +else + e->inst[0 ] |=0x00008000 ; + } +emit (pc, e); }
@@ -658,18 +660,25 @@ emit_add(struct nv50_pc *pc, struct nv50_reg *dst, struct nv50_reg *src0, struct nv50_reg *src1) { struct nv50_program_exec *e = exec(pc); +unsigned neg = pc->negate; e->inst[0 ] |=0xb0000000 ; -check_swap_src_0_1 (pc, &src0, &src1); +if (check_swap_src_0_1 (pc, &src0, &src1)) + neg =BITS_0_1_SWAPPED (neg); +if (!pc->allow32 || neg) { +set_long (pc, e); + e->inst[1 ] |= (neg <<26 ); + } +set_dst (pc, dst, e);set_src_0 (pc, src0, e); -if (!is_long (e) && src1->type ==P_IMMD && pc->allow32) -set_immd (pc, src1, e); -else -if (requires_long (e, src1)) +if (src1->type ==P_CONST ||is_long (e))set_src_2 (pc, src1, e);else +if (src1->type ==P_IMMD ) +set_immd (pc, src1, e); +else set_src_1 (pc, src1, e);emit (pc, e);
@@ -693,25 +702,13 @@ emit_minmax(struct nv50_pc *pc, unsigned sub, struct nv50_reg *dst,emit (pc, e); } -static void +static INLINE voidemit_sub (struct nv50_pc *pc,struct nv50_reg *dst,struct nv50_reg *src0,struct nv50_reg *src1) { -struct nv50_program_exec *e =exec (pc); - - e->inst[0 ] |=0xb0000000 ; - -set_long (pc, e); -if (check_swap_src_0_1 (pc, &src0, &src1)) - e->inst[1 ] |=0x04000000 ; -else - e->inst[1 ] |=0x08000000 ; - -set_dst (pc, dst, e); -set_src_0 (pc, src0, e); -set_src_2 (pc, src1, e); - -emit (pc, e); + pc->negate ^=2 ; +emit_add (pc, dst, src0, src1); + pc->negate ^=2 ; } static void
@@ -728,26 +725,21 @@ emit_mad(struct nv50_pc *pc, struct nv50_reg *dst, struct nv50_reg *src0,set_src_1 (pc, src1, e);set_src_2 (pc, src2, e); +if (pc->negate &1 ) + e->inst[1 ] |=0x04000000 ; +if (pc->negate &2 ) + e->inst[1 ] |=0x08000000 ; +emit (pc, e); } -static void +static INLINE voidemit_msb (struct nv50_pc *pc,struct nv50_reg *dst,struct nv50_reg *src0,struct nv50_reg *src1,struct nv50_reg *src2) { -struct nv50_program_exec *e =exec (pc); - - e->inst[0 ] |=0xe0000000 ; -set_long (pc, e); - e->inst[1 ] |=0x08000000 ;/* src0 * src1 - src2 */ - -check_swap_src_0_1 (pc, &src0, &src1); -set_dst (pc, dst, e); -set_src_0 (pc, src0, e); -set_src_1 (pc, src1, e); -set_src_2 (pc, src2, e); - -emit (pc, e); + pc->negate ^=2 ; +emit_mad (pc, dst, src0, src1, src2); + pc->negate ^=2 ; } static void
@@ -1012,8 +1004,15 @@ convert_to_long(struct nv50_pc *pc, struct nv50_program_exec *e)if (e->inst[0 ] &0x02000000 ) q =0x00020000 ;break ; +case 0xB : +/* ADD */ + m = ~(127 <<16 ); + q = ((e->inst[0 ] & (~m)) >>2 ); +break ;case 0xC :/* MUL */ + m = ~0x00008000 ; + q = ((e->inst[0 ] & (~m)) <<12 );break ;case 0x9 :/* RCP */
@@ -1090,8 +1089,33 @@ tgsi_dst(struct nv50_pc *pc, int c, const struct tgsi_full_dst_register *dst)return NULL ; } +/* Returns bit with which to XOR pc->negate on negation, or -1 if negation +* is not supported for the instruction. This is used in tgsi_src, and set +* to -2 in tx_insn to indicate XOR has already been taken care of in c 0. +*/ +static int +negate_supported (const struct tgsi_full_instruction *insn,int i) +{ +switch (insn->Instruction.Opcode) { +case TGSI_OPCODE_DP3 : +case TGSI_OPCODE_DP4 : +case TGSI_OPCODE_MUL : +return 0 ; +case TGSI_OPCODE_ADD : +case TGSI_OPCODE_SUB : +return i; +case TGSI_OPCODE_MAD : +return (i ==2 ) ?1 :0 ; +case TGSI_OPCODE_POW : +return (i ==1 ) ?0 :-1 ; +default : +return -1 ; + } +} +static struct nv50_reg * -tgsi_src (struct nv50_pc *pc,int chan,const struct tgsi_full_src_register *src) +tgsi_src (struct nv50_pc *pc,int chan,const struct tgsi_full_src_register *src, +int neg) {struct nv50_reg *r =NULL ;struct nv50_reg *temp;
@@ -1146,9 +1170,12 @@ tgsi_src(struct nv50_pc *pc, int chan, const struct tgsi_full_src_register *src) r = temp;break ;case TGSI_UTIL_SIGN_TOGGLE : - temp =temp_temp (pc); -emit_neg (pc, temp, r); - r = temp; +if (neg ==-1 ) { + temp =temp_temp (pc); +emit_neg (pc, temp, r); + r = temp; + }else if (neg >=0 ) + pc->negate ^= (1 << neg);break ;case TGSI_UTIL_SIGN_SET : temp =temp_temp (pc);
@@ -1202,6 +1229,7 @@ nv50_program_tx_insn(struct nv50_pc *pc, const union tgsi_full_token *tok) mask = inst->FullDstRegisters[0 ].DstRegister.WriteMask; sat = inst->Instruction.Saturate ==TGSI_SAT_ZERO_ONE ; + pc->negate =0 ;for (c =0 ; c <4 ; c++) {if (mask & (1 << c))
@@ -1218,12 +1246,16 @@ nv50_program_tx_insn(struct nv50_pc *pc, const union tgsi_full_token *tok)for (i =0 ; i < inst->Instruction.NumSrcRegs; i++) {const struct tgsi_full_src_register *fs = &inst->FullSrcRegisters[i]; +int neg =negate_supported (inst, i);if (fs->SrcRegister.File ==TGSI_FILE_SAMPLER ) unit = fs->SrcRegister.Index; -for (c =0 ; c <4 ; c++) - src[i][c] =tgsi_src (pc, c, fs); +for (c =0 ; c <4 ; c++) { + src[i][c] =tgsi_src (pc, c, fs, neg); +if (neg >=0 ) + neg =-2 ;/* already negated */ + } }if (sat) {
commit e611bc623c1526d5c806964287edf31b4b346d0d
Author: chr <chr@ECHELON.(none)> Date: Sat May 16 16:50:23 2009 +0200
- Unify moving result from temporary to destination registers.
- Don't do mov and cvt.sat for MOV_SAT, just cvt.sat suffices.
src/gallium/drivers/nv50/nv50_program.c +30 -43
151 lines not on this page · raw message
commit 1b3a83bd57065aa015d5251f44bea0b710838581
Author: chr <chr@ECHELON.(none)> Date: Sat May 16 16:39:38 2009 +0200
- Make TXP do what it's supposed to (centroid not yet honored, could store interpolation mode in some per register flag maybe).
- FIX: don't set perspect_load = FALSE if we encounter a centroid attribute, instead make perspect/centroid_load counters.
src/gallium/drivers/nv50/nv50_program.c +43 -16
109 lines not on this page · raw message
commit 3f66c5d0daf7ef15ddc9f7bc22967d95d52ab2af
Author: chr <chr@ECHELON.(none)> Date: Sat May 16 16:43:09 2009 +0200
- Introduce emit_cvt and use it where applicable (flr, abs, sat, and in set).
- Restructure LIT again, now src == dst case is completely taken care of there.
- Change emit_kil and add negation support (the generated insn was different before, but this is how the blob does it here, should look into this).
- Remove unnecessary MALLOC and FREE in program dump ifdef block.
- In alloc_immd(), also put -f and 0.5 * f in the immd buffer, as it is now this might save some space.
Well, that's a lot of rather unrelated changes, maybe I should break things up more.
src/gallium/drivers/nv50/nv50_program.c +64 -74
223 lines not on this page · raw message
commit 0bd93153d45bec1616a40b81af28d0c5a1536539
Author: chr <chr@ECHELON.(none)> Date: Sat May 16 16:30:59 2009 +0200
Rewrite emit_set.
src/gallium/drivers/nv50/nv50_program.c +26 -19
78 lines not on this page · raw message
_______________________________________________
Nouveau mailing list [email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau