From 9f952cceb453d6273188a2c71d4e92dbdd454be0 Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Thu, 18 Feb 2010 11:26:18 +0100 Subject: tgsi: Rewrite exec implementations of NRM and NRM4. --- src/gallium/auxiliary/tgsi/tgsi_exec.c | 131 ++++++++++++++++++--------------- 1 file changed, 70 insertions(+), 61 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/auxiliary/tgsi/tgsi_exec.c b/src/gallium/auxiliary/tgsi/tgsi_exec.c index 262422364bf..14035d4b2d3 100644 --- a/src/gallium/auxiliary/tgsi/tgsi_exec.c +++ b/src/gallium/auxiliary/tgsi/tgsi_exec.c @@ -461,6 +461,10 @@ enum tgsi_exec_datatype { static const union tgsi_exec_channel ZeroVec = { { 0.0, 0.0, 0.0, 0.0 } }; +static const union tgsi_exec_channel OneVec = { + {1.0f, 1.0f, 1.0f, 1.0f} +}; + /** * Assert that none of the float values in 'chan' are infinite or NaN. @@ -2029,6 +2033,70 @@ exec_dp2(struct tgsi_exec_machine *mach, } } +static void +exec_nrm4(struct tgsi_exec_machine *mach, + const struct tgsi_full_instruction *inst) +{ + unsigned int chan; + union tgsi_exec_channel arg[4]; + union tgsi_exec_channel scale; + + fetch_source(mach, &arg[0], &inst->Src[0], CHAN_X, TGSI_EXEC_DATA_FLOAT); + micro_mul(&scale, &arg[0], &arg[0]); + + for (chan = CHAN_Y; chan <= CHAN_W; chan++) { + union tgsi_exec_channel product; + + fetch_source(mach, &arg[chan], &inst->Src[0], chan, TGSI_EXEC_DATA_FLOAT); + micro_mul(&product, &arg[chan], &arg[chan]); + micro_add(&scale, &scale, &product); + } + + micro_rsq(&scale, &scale); + + for (chan = CHAN_X; chan <= CHAN_W; chan++) { + if (inst->Dst[0].Register.WriteMask & (1 << chan)) { + micro_mul(&arg[chan], &arg[chan], &scale); + store_dest(mach, &arg[chan], &inst->Dst[0], inst, chan, TGSI_EXEC_DATA_FLOAT); + } + } +} + +static void +exec_nrm3(struct tgsi_exec_machine *mach, + const struct tgsi_full_instruction *inst) +{ + if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_XYZ) { + unsigned int chan; + union tgsi_exec_channel arg[3]; + union tgsi_exec_channel scale; + + fetch_source(mach, &arg[0], &inst->Src[0], CHAN_X, TGSI_EXEC_DATA_FLOAT); + micro_mul(&scale, &arg[0], &arg[0]); + + for (chan = CHAN_Y; chan <= CHAN_Z; chan++) { + union tgsi_exec_channel product; + + fetch_source(mach, &arg[chan], &inst->Src[0], chan, TGSI_EXEC_DATA_FLOAT); + micro_mul(&product, &arg[chan], &arg[chan]); + micro_add(&scale, &scale, &product); + } + + micro_rsq(&scale, &scale); + + for (chan = CHAN_X; chan <= CHAN_Z; chan++) { + if (inst->Dst[0].Register.WriteMask & (1 << chan)) { + micro_mul(&arg[chan], &arg[chan], &scale); + store_dest(mach, &arg[chan], &inst->Dst[0], inst, chan, TGSI_EXEC_DATA_FLOAT); + } + } + } + + if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_W) { + store_dest(mach, &OneVec, &inst->Dst[0], inst, CHAN_W, TGSI_EXEC_DATA_FLOAT); + } +} + static void exec_break(struct tgsi_exec_machine *mach) { @@ -3052,70 +3120,11 @@ exec_instruction( break; case TGSI_OPCODE_NRM: - /* 3-component vector normalize */ - if(IS_CHANNEL_ENABLED(*inst, CHAN_X) || - IS_CHANNEL_ENABLED(*inst, CHAN_Y) || - IS_CHANNEL_ENABLED(*inst, CHAN_Z)) { - /* r3 = sqrt(dp3(src0, src0)) */ - FETCH(&r[0], 0, CHAN_X); - micro_mul(&r[3], &r[0], &r[0]); - FETCH(&r[1], 0, CHAN_Y); - micro_mul(&r[4], &r[1], &r[1]); - micro_add(&r[3], &r[3], &r[4]); - FETCH(&r[2], 0, CHAN_Z); - micro_mul(&r[4], &r[2], &r[2]); - micro_add(&r[3], &r[3], &r[4]); - micro_sqrt(&r[3], &r[3]); - - if (IS_CHANNEL_ENABLED(*inst, CHAN_X)) { - micro_div(&r[0], &r[0], &r[3]); - STORE(&r[0], 0, CHAN_X); - } - if (IS_CHANNEL_ENABLED(*inst, CHAN_Y)) { - micro_div(&r[1], &r[1], &r[3]); - STORE(&r[1], 0, CHAN_Y); - } - if (IS_CHANNEL_ENABLED(*inst, CHAN_Z)) { - micro_div(&r[2], &r[2], &r[3]); - STORE(&r[2], 0, CHAN_Z); - } - } - if (IS_CHANNEL_ENABLED(*inst, CHAN_W)) { - STORE(&mach->Temps[TEMP_1_I].xyzw[TEMP_1_C], 0, CHAN_W); - } + exec_nrm3(mach, inst); break; case TGSI_OPCODE_NRM4: - /* 4-component vector normalize */ - { - union tgsi_exec_channel tmp, dot; - - /* tmp = dp4(src0, src0): */ - FETCH( &r[0], 0, CHAN_X ); - micro_mul( &tmp, &r[0], &r[0] ); - - FETCH( &r[1], 0, CHAN_Y ); - micro_mul( &dot, &r[1], &r[1] ); - micro_add( &tmp, &tmp, &dot ); - - FETCH( &r[2], 0, CHAN_Z ); - micro_mul( &dot, &r[2], &r[2] ); - micro_add( &tmp, &tmp, &dot ); - - FETCH( &r[3], 0, CHAN_W ); - micro_mul( &dot, &r[3], &r[3] ); - micro_add( &tmp, &tmp, &dot ); - - /* tmp = 1 / sqrt(tmp) */ - micro_sqrt( &tmp, &tmp ); - micro_div( &tmp, &mach->Temps[TEMP_1_I].xyzw[TEMP_1_C], &tmp ); - - FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) { - /* chan = chan * tmp */ - micro_mul( &r[chan_index], &tmp, &r[chan_index] ); - STORE( &r[chan_index], 0, chan_index ); - } - } + exec_nrm4(mach, inst); break; case TGSI_OPCODE_DIV: -- cgit v1.2.3 From 348d236afcde3beede16a2de58b8c423b98d0676 Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Thu, 18 Feb 2010 11:56:14 +0100 Subject: tgsi: Change prototypes of micro opcodes to explicitly indicates number of args. --- src/gallium/auxiliary/tgsi/tgsi_exec.c | 370 ++++++++++++++++++--------------- 1 file changed, 206 insertions(+), 164 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/auxiliary/tgsi/tgsi_exec.c b/src/gallium/auxiliary/tgsi/tgsi_exec.c index 14035d4b2d3..76ce3a8bf51 100644 --- a/src/gallium/auxiliary/tgsi/tgsi_exec.c +++ b/src/gallium/auxiliary/tgsi/tgsi_exec.c @@ -232,22 +232,26 @@ micro_lg2(union tgsi_exec_channel *dst, static void micro_lrp(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1, + const union tgsi_exec_channel *src2) { - dst->f[0] = src[0].f[0] * (src[1].f[0] - src[2].f[0]) + src[2].f[0]; - dst->f[1] = src[0].f[1] * (src[1].f[1] - src[2].f[1]) + src[2].f[1]; - dst->f[2] = src[0].f[2] * (src[1].f[2] - src[2].f[2]) + src[2].f[2]; - dst->f[3] = src[0].f[3] * (src[1].f[3] - src[2].f[3]) + src[2].f[3]; + dst->f[0] = src0->f[0] * (src1->f[0] - src2->f[0]) + src2->f[0]; + dst->f[1] = src0->f[1] * (src1->f[1] - src2->f[1]) + src2->f[1]; + dst->f[2] = src0->f[2] * (src1->f[2] - src2->f[2]) + src2->f[2]; + dst->f[3] = src0->f[3] * (src1->f[3] - src2->f[3]) + src2->f[3]; } static void micro_mad(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1, + const union tgsi_exec_channel *src2) { - dst->f[0] = src[0].f[0] * src[1].f[0] + src[2].f[0]; - dst->f[1] = src[0].f[1] * src[1].f[1] + src[2].f[1]; - dst->f[2] = src[0].f[2] * src[1].f[2] + src[2].f[2]; - dst->f[3] = src[0].f[3] * src[1].f[3] + src[2].f[3]; + dst->f[0] = src0->f[0] * src1->f[0] + src2->f[0]; + dst->f[1] = src0->f[1] * src1->f[1] + src2->f[1]; + dst->f[2] = src0->f[2] * src1->f[2] + src2->f[2]; + dst->f[3] = src0->f[3] * src1->f[3] + src2->f[3]; } static void @@ -304,22 +308,24 @@ micro_rsq(union tgsi_exec_channel *dst, static void micro_seq(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { - dst->f[0] = src[0].f[0] == src[1].f[0] ? 1.0f : 0.0f; - dst->f[1] = src[0].f[1] == src[1].f[1] ? 1.0f : 0.0f; - dst->f[2] = src[0].f[2] == src[1].f[2] ? 1.0f : 0.0f; - dst->f[3] = src[0].f[3] == src[1].f[3] ? 1.0f : 0.0f; + dst->f[0] = src0->f[0] == src1->f[0] ? 1.0f : 0.0f; + dst->f[1] = src0->f[1] == src1->f[1] ? 1.0f : 0.0f; + dst->f[2] = src0->f[2] == src1->f[2] ? 1.0f : 0.0f; + dst->f[3] = src0->f[3] == src1->f[3] ? 1.0f : 0.0f; } static void micro_sge(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { - dst->f[0] = src[0].f[0] >= src[1].f[0] ? 1.0f : 0.0f; - dst->f[1] = src[0].f[1] >= src[1].f[1] ? 1.0f : 0.0f; - dst->f[2] = src[0].f[2] >= src[1].f[2] ? 1.0f : 0.0f; - dst->f[3] = src[0].f[3] >= src[1].f[3] ? 1.0f : 0.0f; + dst->f[0] = src0->f[0] >= src1->f[0] ? 1.0f : 0.0f; + dst->f[1] = src0->f[1] >= src1->f[1] ? 1.0f : 0.0f; + dst->f[2] = src0->f[2] >= src1->f[2] ? 1.0f : 0.0f; + dst->f[3] = src0->f[3] >= src1->f[3] ? 1.0f : 0.0f; } static void @@ -334,12 +340,13 @@ micro_sgn(union tgsi_exec_channel *dst, static void micro_sgt(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { - dst->f[0] = src[0].f[0] > src[1].f[0] ? 1.0f : 0.0f; - dst->f[1] = src[0].f[1] > src[1].f[1] ? 1.0f : 0.0f; - dst->f[2] = src[0].f[2] > src[1].f[2] ? 1.0f : 0.0f; - dst->f[3] = src[0].f[3] > src[1].f[3] ? 1.0f : 0.0f; + dst->f[0] = src0->f[0] > src1->f[0] ? 1.0f : 0.0f; + dst->f[1] = src0->f[1] > src1->f[1] ? 1.0f : 0.0f; + dst->f[2] = src0->f[2] > src1->f[2] ? 1.0f : 0.0f; + dst->f[3] = src0->f[3] > src1->f[3] ? 1.0f : 0.0f; } static void @@ -354,32 +361,35 @@ micro_sin(union tgsi_exec_channel *dst, static void micro_sle(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { - dst->f[0] = src[0].f[0] <= src[1].f[0] ? 1.0f : 0.0f; - dst->f[1] = src[0].f[1] <= src[1].f[1] ? 1.0f : 0.0f; - dst->f[2] = src[0].f[2] <= src[1].f[2] ? 1.0f : 0.0f; - dst->f[3] = src[0].f[3] <= src[1].f[3] ? 1.0f : 0.0f; + dst->f[0] = src0->f[0] <= src1->f[0] ? 1.0f : 0.0f; + dst->f[1] = src0->f[1] <= src1->f[1] ? 1.0f : 0.0f; + dst->f[2] = src0->f[2] <= src1->f[2] ? 1.0f : 0.0f; + dst->f[3] = src0->f[3] <= src1->f[3] ? 1.0f : 0.0f; } static void micro_slt(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { - dst->f[0] = src[0].f[0] < src[1].f[0] ? 1.0f : 0.0f; - dst->f[1] = src[0].f[1] < src[1].f[1] ? 1.0f : 0.0f; - dst->f[2] = src[0].f[2] < src[1].f[2] ? 1.0f : 0.0f; - dst->f[3] = src[0].f[3] < src[1].f[3] ? 1.0f : 0.0f; + dst->f[0] = src0->f[0] < src1->f[0] ? 1.0f : 0.0f; + dst->f[1] = src0->f[1] < src1->f[1] ? 1.0f : 0.0f; + dst->f[2] = src0->f[2] < src1->f[2] ? 1.0f : 0.0f; + dst->f[3] = src0->f[3] < src1->f[3] ? 1.0f : 0.0f; } static void micro_sne(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { - dst->f[0] = src[0].f[0] != src[1].f[0] ? 1.0f : 0.0f; - dst->f[1] = src[0].f[1] != src[1].f[1] ? 1.0f : 0.0f; - dst->f[2] = src[0].f[2] != src[1].f[2] ? 1.0f : 0.0f; - dst->f[3] = src[0].f[3] != src[1].f[3] ? 1.0f : 0.0f; + dst->f[0] = src0->f[0] != src1->f[0] ? 1.0f : 0.0f; + dst->f[1] = src0->f[1] != src1->f[1] ? 1.0f : 0.0f; + dst->f[2] = src0->f[2] != src1->f[2] ? 1.0f : 0.0f; + dst->f[3] = src0->f[3] != src1->f[3] ? 1.0f : 0.0f; } static void @@ -1808,13 +1818,13 @@ exec_declaration(struct tgsi_exec_machine *mach, } } -typedef void (* micro_op)(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src); +typedef void (* micro_unary_op)(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src); static void exec_scalar_unary(struct tgsi_exec_machine *mach, const struct tgsi_full_instruction *inst, - micro_op op, + micro_unary_op op, enum tgsi_exec_datatype dst_datatype, enum tgsi_exec_datatype src_datatype) { @@ -1834,7 +1844,7 @@ exec_scalar_unary(struct tgsi_exec_machine *mach, static void exec_vector_unary(struct tgsi_exec_machine *mach, const struct tgsi_full_instruction *inst, - micro_op op, + micro_unary_op op, enum tgsi_exec_datatype dst_datatype, enum tgsi_exec_datatype src_datatype) { @@ -1856,10 +1866,14 @@ exec_vector_unary(struct tgsi_exec_machine *mach, } } +typedef void (* micro_binary_op)(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1); + static void exec_vector_binary(struct tgsi_exec_machine *mach, const struct tgsi_full_instruction *inst, - micro_op op, + micro_binary_op op, enum tgsi_exec_datatype dst_datatype, enum tgsi_exec_datatype src_datatype) { @@ -1872,7 +1886,7 @@ exec_vector_binary(struct tgsi_exec_machine *mach, fetch_source(mach, &src[0], &inst->Src[0], chan, src_datatype); fetch_source(mach, &src[1], &inst->Src[1], chan, src_datatype); - op(&dst.xyzw[chan], src); + op(&dst.xyzw[chan], &src[0], &src[1]); } } for (chan = 0; chan < NUM_CHANNELS; chan++) { @@ -1882,10 +1896,15 @@ exec_vector_binary(struct tgsi_exec_machine *mach, } } +typedef void (* micro_trinary_op)(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1, + const union tgsi_exec_channel *src2); + static void exec_vector_trinary(struct tgsi_exec_machine *mach, const struct tgsi_full_instruction *inst, - micro_op op, + micro_trinary_op op, enum tgsi_exec_datatype dst_datatype, enum tgsi_exec_datatype src_datatype) { @@ -1899,7 +1918,7 @@ exec_vector_trinary(struct tgsi_exec_machine *mach, fetch_source(mach, &src[0], &inst->Src[0], chan, src_datatype); fetch_source(mach, &src[1], &inst->Src[1], chan, src_datatype); fetch_source(mach, &src[2], &inst->Src[2], chan, src_datatype); - op(&dst.xyzw[chan], src); + op(&dst.xyzw[chan], &src[0], &src[1], &src[2]); } } for (chan = 0; chan < NUM_CHANNELS; chan++) { @@ -1923,7 +1942,7 @@ exec_dp3(struct tgsi_exec_machine *mach, for (chan = CHAN_Y; chan <= CHAN_Z; chan++) { fetch_source(mach, &arg[0], &inst->Src[0], chan, TGSI_EXEC_DATA_FLOAT); fetch_source(mach, &arg[1], &inst->Src[1], chan, TGSI_EXEC_DATA_FLOAT); - micro_mad(&arg[2], arg); + micro_mad(&arg[2], &arg[0], &arg[1], &arg[2]); } for (chan = 0; chan < NUM_CHANNELS; chan++) { @@ -1947,7 +1966,7 @@ exec_dp4(struct tgsi_exec_machine *mach, for (chan = CHAN_Y; chan <= CHAN_W; chan++) { fetch_source(mach, &arg[0], &inst->Src[0], chan, TGSI_EXEC_DATA_FLOAT); fetch_source(mach, &arg[1], &inst->Src[1], chan, TGSI_EXEC_DATA_FLOAT); - micro_mad(&arg[2], arg); + micro_mad(&arg[2], &arg[0], &arg[1], &arg[2]); } for (chan = 0; chan < NUM_CHANNELS; chan++) { @@ -1970,7 +1989,7 @@ exec_dp2a(struct tgsi_exec_machine *mach, fetch_source(mach, &arg[0], &inst->Src[0], CHAN_Y, TGSI_EXEC_DATA_FLOAT); fetch_source(mach, &arg[1], &inst->Src[1], CHAN_Y, TGSI_EXEC_DATA_FLOAT); - micro_mad(&arg[0], arg); + micro_mad(&arg[0], &arg[0], &arg[1], &arg[2]); fetch_source(mach, &arg[1], &inst->Src[2], CHAN_X, TGSI_EXEC_DATA_FLOAT); micro_add(&arg[0], &arg[0], &arg[1]); @@ -1995,11 +2014,11 @@ exec_dph(struct tgsi_exec_machine *mach, fetch_source(mach, &arg[0], &inst->Src[0], CHAN_Y, TGSI_EXEC_DATA_FLOAT); fetch_source(mach, &arg[1], &inst->Src[1], CHAN_Y, TGSI_EXEC_DATA_FLOAT); - micro_mad(&arg[2], arg); + micro_mad(&arg[2], &arg[0], &arg[1], &arg[2]); fetch_source(mach, &arg[0], &inst->Src[0], CHAN_Z, TGSI_EXEC_DATA_FLOAT); fetch_source(mach, &arg[1], &inst->Src[1], CHAN_Z, TGSI_EXEC_DATA_FLOAT); - micro_mad(&arg[0], arg); + micro_mad(&arg[0], &arg[0], &arg[1], &arg[2]); fetch_source(mach, &arg[1], &inst->Src[1], CHAN_W, TGSI_EXEC_DATA_FLOAT); micro_add(&arg[0], &arg[0], &arg[1]); @@ -2024,7 +2043,7 @@ exec_dp2(struct tgsi_exec_machine *mach, fetch_source(mach, &arg[0], &inst->Src[0], CHAN_Y, TGSI_EXEC_DATA_FLOAT); fetch_source(mach, &arg[1], &inst->Src[1], CHAN_Y, TGSI_EXEC_DATA_FLOAT); - micro_mad(&arg[2], arg); + micro_mad(&arg[2], &arg[0], &arg[1], &arg[2]); for (chan = 0; chan < NUM_CHANNELS; chan++) { if (inst->Dst[0].Register.WriteMask & (1 << chan)) { @@ -2203,42 +2222,46 @@ micro_not(union tgsi_exec_channel *dst, static void micro_shl(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { - dst->u[0] = src[0].u[0] << src[1].u[0]; - dst->u[1] = src[0].u[1] << src[1].u[1]; - dst->u[2] = src[0].u[2] << src[1].u[2]; - dst->u[3] = src[0].u[3] << src[1].u[3]; + dst->u[0] = src0->u[0] << src1->u[0]; + dst->u[1] = src0->u[1] << src1->u[1]; + dst->u[2] = src0->u[2] << src1->u[2]; + dst->u[3] = src0->u[3] << src1->u[3]; } static void micro_and(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { - dst->u[0] = src[0].u[0] & src[1].u[0]; - dst->u[1] = src[0].u[1] & src[1].u[1]; - dst->u[2] = src[0].u[2] & src[1].u[2]; - dst->u[3] = src[0].u[3] & src[1].u[3]; + dst->u[0] = src0->u[0] & src1->u[0]; + dst->u[1] = src0->u[1] & src1->u[1]; + dst->u[2] = src0->u[2] & src1->u[2]; + dst->u[3] = src0->u[3] & src1->u[3]; } static void micro_or(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { - dst->u[0] = src[0].u[0] | src[1].u[0]; - dst->u[1] = src[0].u[1] | src[1].u[1]; - dst->u[2] = src[0].u[2] | src[1].u[2]; - dst->u[3] = src[0].u[3] | src[1].u[3]; + dst->u[0] = src0->u[0] | src1->u[0]; + dst->u[1] = src0->u[1] | src1->u[1]; + dst->u[2] = src0->u[2] | src1->u[2]; + dst->u[3] = src0->u[3] | src1->u[3]; } static void micro_xor(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { - dst->u[0] = src[0].u[0] ^ src[1].u[0]; - dst->u[1] = src[0].u[1] ^ src[1].u[1]; - dst->u[2] = src[0].u[2] ^ src[1].u[2]; - dst->u[3] = src[0].u[3] ^ src[1].u[3]; + dst->u[0] = src0->u[0] ^ src1->u[0]; + dst->u[1] = src0->u[1] ^ src1->u[1]; + dst->u[2] = src0->u[2] ^ src1->u[2]; + dst->u[3] = src0->u[3] ^ src1->u[3]; } static void @@ -2253,62 +2276,68 @@ micro_f2i(union tgsi_exec_channel *dst, static void micro_idiv(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { - dst->i[0] = src[0].i[0] / src[1].i[0]; - dst->i[1] = src[0].i[1] / src[1].i[1]; - dst->i[2] = src[0].i[2] / src[1].i[2]; - dst->i[3] = src[0].i[3] / src[1].i[3]; + dst->i[0] = src0->i[0] / src1->i[0]; + dst->i[1] = src0->i[1] / src1->i[1]; + dst->i[2] = src0->i[2] / src1->i[2]; + dst->i[3] = src0->i[3] / src1->i[3]; } static void micro_imax(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { - dst->i[0] = src[0].i[0] > src[1].i[0] ? src[0].i[0] : src[1].i[0]; - dst->i[1] = src[0].i[1] > src[1].i[1] ? src[0].i[1] : src[1].i[1]; - dst->i[2] = src[0].i[2] > src[1].i[2] ? src[0].i[2] : src[1].i[2]; - dst->i[3] = src[0].i[3] > src[1].i[3] ? src[0].i[3] : src[1].i[3]; + dst->i[0] = src0->i[0] > src1->i[0] ? src0->i[0] : src1->i[0]; + dst->i[1] = src0->i[1] > src1->i[1] ? src0->i[1] : src1->i[1]; + dst->i[2] = src0->i[2] > src1->i[2] ? src0->i[2] : src1->i[2]; + dst->i[3] = src0->i[3] > src1->i[3] ? src0->i[3] : src1->i[3]; } static void micro_imin(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { - dst->i[0] = src[0].i[0] < src[1].i[0] ? src[0].i[0] : src[1].i[0]; - dst->i[1] = src[0].i[1] < src[1].i[1] ? src[0].i[1] : src[1].i[1]; - dst->i[2] = src[0].i[2] < src[1].i[2] ? src[0].i[2] : src[1].i[2]; - dst->i[3] = src[0].i[3] < src[1].i[3] ? src[0].i[3] : src[1].i[3]; + dst->i[0] = src0->i[0] < src1->i[0] ? src0->i[0] : src1->i[0]; + dst->i[1] = src0->i[1] < src1->i[1] ? src0->i[1] : src1->i[1]; + dst->i[2] = src0->i[2] < src1->i[2] ? src0->i[2] : src1->i[2]; + dst->i[3] = src0->i[3] < src1->i[3] ? src0->i[3] : src1->i[3]; } static void micro_isge(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { - dst->i[0] = src[0].i[0] >= src[1].i[0] ? -1 : 0; - dst->i[1] = src[0].i[1] >= src[1].i[1] ? -1 : 0; - dst->i[2] = src[0].i[2] >= src[1].i[2] ? -1 : 0; - dst->i[3] = src[0].i[3] >= src[1].i[3] ? -1 : 0; + dst->i[0] = src0->i[0] >= src1->i[0] ? -1 : 0; + dst->i[1] = src0->i[1] >= src1->i[1] ? -1 : 0; + dst->i[2] = src0->i[2] >= src1->i[2] ? -1 : 0; + dst->i[3] = src0->i[3] >= src1->i[3] ? -1 : 0; } static void micro_ishr(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { - dst->i[0] = src[0].i[0] >> src[1].i[0]; - dst->i[1] = src[0].i[1] >> src[1].i[1]; - dst->i[2] = src[0].i[2] >> src[1].i[2]; - dst->i[3] = src[0].i[3] >> src[1].i[3]; + dst->i[0] = src0->i[0] >> src1->i[0]; + dst->i[1] = src0->i[1] >> src1->i[1]; + dst->i[2] = src0->i[2] >> src1->i[2]; + dst->i[3] = src0->i[3] >> src1->i[3]; } static void micro_islt(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { - dst->i[0] = src[0].i[0] < src[1].i[0] ? -1 : 0; - dst->i[1] = src[0].i[1] < src[1].i[1] ? -1 : 0; - dst->i[2] = src[0].i[2] < src[1].i[2] ? -1 : 0; - dst->i[3] = src[0].i[3] < src[1].i[3] ? -1 : 0; + dst->i[0] = src0->i[0] < src1->i[0] ? -1 : 0; + dst->i[1] = src0->i[1] < src1->i[1] ? -1 : 0; + dst->i[2] = src0->i[2] < src1->i[2] ? -1 : 0; + dst->i[3] = src0->i[3] < src1->i[3] ? -1 : 0; } static void @@ -2333,122 +2362,135 @@ micro_u2f(union tgsi_exec_channel *dst, static void micro_uadd(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { - dst->u[0] = src[0].u[0] + src[1].u[0]; - dst->u[1] = src[0].u[1] + src[1].u[1]; - dst->u[2] = src[0].u[2] + src[1].u[2]; - dst->u[3] = src[0].u[3] + src[1].u[3]; + dst->u[0] = src0->u[0] + src1->u[0]; + dst->u[1] = src0->u[1] + src1->u[1]; + dst->u[2] = src0->u[2] + src1->u[2]; + dst->u[3] = src0->u[3] + src1->u[3]; } static void micro_udiv(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { - dst->u[0] = src[0].u[0] / src[1].u[0]; - dst->u[1] = src[0].u[1] / src[1].u[1]; - dst->u[2] = src[0].u[2] / src[1].u[2]; - dst->u[3] = src[0].u[3] / src[1].u[3]; + dst->u[0] = src0->u[0] / src1->u[0]; + dst->u[1] = src0->u[1] / src1->u[1]; + dst->u[2] = src0->u[2] / src1->u[2]; + dst->u[3] = src0->u[3] / src1->u[3]; } static void micro_umad(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1, + const union tgsi_exec_channel *src2) { - dst->u[0] = src[0].u[0] * src[1].u[0] + src[2].u[0]; - dst->u[1] = src[0].u[1] * src[1].u[1] + src[2].u[1]; - dst->u[2] = src[0].u[2] * src[1].u[2] + src[2].u[2]; - dst->u[3] = src[0].u[3] * src[1].u[3] + src[2].u[3]; + dst->u[0] = src0->u[0] * src1->u[0] + src2->u[0]; + dst->u[1] = src0->u[1] * src1->u[1] + src2->u[1]; + dst->u[2] = src0->u[2] * src1->u[2] + src2->u[2]; + dst->u[3] = src0->u[3] * src1->u[3] + src2->u[3]; } static void micro_umax(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { - dst->u[0] = src[0].u[0] > src[1].u[0] ? src[0].u[0] : src[1].u[0]; - dst->u[1] = src[0].u[1] > src[1].u[1] ? src[0].u[1] : src[1].u[1]; - dst->u[2] = src[0].u[2] > src[1].u[2] ? src[0].u[2] : src[1].u[2]; - dst->u[3] = src[0].u[3] > src[1].u[3] ? src[0].u[3] : src[1].u[3]; + dst->u[0] = src0->u[0] > src1->u[0] ? src0->u[0] : src1->u[0]; + dst->u[1] = src0->u[1] > src1->u[1] ? src0->u[1] : src1->u[1]; + dst->u[2] = src0->u[2] > src1->u[2] ? src0->u[2] : src1->u[2]; + dst->u[3] = src0->u[3] > src1->u[3] ? src0->u[3] : src1->u[3]; } static void micro_umin(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { - dst->u[0] = src[0].u[0] < src[1].u[0] ? src[0].u[0] : src[1].u[0]; - dst->u[1] = src[0].u[1] < src[1].u[1] ? src[0].u[1] : src[1].u[1]; - dst->u[2] = src[0].u[2] < src[1].u[2] ? src[0].u[2] : src[1].u[2]; - dst->u[3] = src[0].u[3] < src[1].u[3] ? src[0].u[3] : src[1].u[3]; + dst->u[0] = src0->u[0] < src1->u[0] ? src0->u[0] : src1->u[0]; + dst->u[1] = src0->u[1] < src1->u[1] ? src0->u[1] : src1->u[1]; + dst->u[2] = src0->u[2] < src1->u[2] ? src0->u[2] : src1->u[2]; + dst->u[3] = src0->u[3] < src1->u[3] ? src0->u[3] : src1->u[3]; } static void micro_umod(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { - dst->u[0] = src[0].u[0] % src[1].u[0]; - dst->u[1] = src[0].u[1] % src[1].u[1]; - dst->u[2] = src[0].u[2] % src[1].u[2]; - dst->u[3] = src[0].u[3] % src[1].u[3]; + dst->u[0] = src0->u[0] % src1->u[0]; + dst->u[1] = src0->u[1] % src1->u[1]; + dst->u[2] = src0->u[2] % src1->u[2]; + dst->u[3] = src0->u[3] % src1->u[3]; } static void micro_umul(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { - dst->u[0] = src[0].u[0] * src[1].u[0]; - dst->u[1] = src[0].u[1] * src[1].u[1]; - dst->u[2] = src[0].u[2] * src[1].u[2]; - dst->u[3] = src[0].u[3] * src[1].u[3]; + dst->u[0] = src0->u[0] * src1->u[0]; + dst->u[1] = src0->u[1] * src1->u[1]; + dst->u[2] = src0->u[2] * src1->u[2]; + dst->u[3] = src0->u[3] * src1->u[3]; } static void micro_useq(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { - dst->u[0] = src[0].u[0] == src[1].u[0] ? ~0 : 0; - dst->u[1] = src[0].u[1] == src[1].u[1] ? ~0 : 0; - dst->u[2] = src[0].u[2] == src[1].u[2] ? ~0 : 0; - dst->u[3] = src[0].u[3] == src[1].u[3] ? ~0 : 0; + dst->u[0] = src0->u[0] == src1->u[0] ? ~0 : 0; + dst->u[1] = src0->u[1] == src1->u[1] ? ~0 : 0; + dst->u[2] = src0->u[2] == src1->u[2] ? ~0 : 0; + dst->u[3] = src0->u[3] == src1->u[3] ? ~0 : 0; } static void micro_usge(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { - dst->u[0] = src[0].u[0] >= src[1].u[0] ? ~0 : 0; - dst->u[1] = src[0].u[1] >= src[1].u[1] ? ~0 : 0; - dst->u[2] = src[0].u[2] >= src[1].u[2] ? ~0 : 0; - dst->u[3] = src[0].u[3] >= src[1].u[3] ? ~0 : 0; + dst->u[0] = src0->u[0] >= src1->u[0] ? ~0 : 0; + dst->u[1] = src0->u[1] >= src1->u[1] ? ~0 : 0; + dst->u[2] = src0->u[2] >= src1->u[2] ? ~0 : 0; + dst->u[3] = src0->u[3] >= src1->u[3] ? ~0 : 0; } static void micro_ushr(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { - dst->u[0] = src[0].u[0] >> src[1].u[0]; - dst->u[1] = src[0].u[1] >> src[1].u[1]; - dst->u[2] = src[0].u[2] >> src[1].u[2]; - dst->u[3] = src[0].u[3] >> src[1].u[3]; + dst->u[0] = src0->u[0] >> src1->u[0]; + dst->u[1] = src0->u[1] >> src1->u[1]; + dst->u[2] = src0->u[2] >> src1->u[2]; + dst->u[3] = src0->u[3] >> src1->u[3]; } static void micro_uslt(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { - dst->u[0] = src[0].u[0] < src[1].u[0] ? ~0 : 0; - dst->u[1] = src[0].u[1] < src[1].u[1] ? ~0 : 0; - dst->u[2] = src[0].u[2] < src[1].u[2] ? ~0 : 0; - dst->u[3] = src[0].u[3] < src[1].u[3] ? ~0 : 0; + dst->u[0] = src0->u[0] < src1->u[0] ? ~0 : 0; + dst->u[1] = src0->u[1] < src1->u[1] ? ~0 : 0; + dst->u[2] = src0->u[2] < src1->u[2] ? ~0 : 0; + dst->u[3] = src0->u[3] < src1->u[3] ? ~0 : 0; } static void micro_usne(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { - dst->u[0] = src[0].u[0] != src[1].u[0] ? ~0 : 0; - dst->u[1] = src[0].u[1] != src[1].u[1] ? ~0 : 0; - dst->u[2] = src[0].u[2] != src[1].u[2] ? ~0 : 0; - dst->u[3] = src[0].u[3] != src[1].u[3] ? ~0 : 0; + dst->u[0] = src0->u[0] != src1->u[0] ? ~0 : 0; + dst->u[1] = src0->u[1] != src1->u[1] ? ~0 : 0; + dst->u[2] = src0->u[2] != src1->u[2] ? ~0 : 0; + dst->u[3] = src0->u[3] != src1->u[3] ? ~0 : 0; } static void -- cgit v1.2.3 From 3d0bfc6a4be73d43928493641bf819f77075bbc1 Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Thu, 18 Feb 2010 12:05:08 +0100 Subject: tgsi: Make more exec opcodes look pretty. --- src/gallium/auxiliary/tgsi/tgsi_exec.c | 84 ++++++++-------------------------- 1 file changed, 20 insertions(+), 64 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/auxiliary/tgsi/tgsi_exec.c b/src/gallium/auxiliary/tgsi/tgsi_exec.c index 76ce3a8bf51..fdbf2b436e4 100644 --- a/src/gallium/auxiliary/tgsi/tgsi_exec.c +++ b/src/gallium/auxiliary/tgsi/tgsi_exec.c @@ -773,10 +773,9 @@ tgsi_exec_machine_destroy(struct tgsi_exec_machine *mach) } static void -micro_add( - union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src0, - const union tgsi_exec_channel *src1 ) +micro_add(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { dst->f[0] = src0->f[0] + src1->f[0]; dst->f[1] = src0->f[1] + src1->f[1]; @@ -845,10 +844,9 @@ micro_lt( } static void -micro_max( - union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src0, - const union tgsi_exec_channel *src1 ) +micro_max(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { dst->f[0] = src0->f[0] > src1->f[0] ? src0->f[0] : src1->f[0]; dst->f[1] = src0->f[1] > src1->f[1] ? src0->f[1] : src1->f[1]; @@ -857,10 +855,9 @@ micro_max( } static void -micro_min( - union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src0, - const union tgsi_exec_channel *src1 ) +micro_min(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { dst->f[0] = src0->f[0] < src1->f[0] ? src0->f[0] : src1->f[0]; dst->f[1] = src0->f[1] < src1->f[1] ? src0->f[1] : src1->f[1]; @@ -869,10 +866,9 @@ micro_min( } static void -micro_mul( - union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src0, - const union tgsi_exec_channel *src1 ) +micro_mul(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { dst->f[0] = src0->f[0] * src1->f[0]; dst->f[1] = src0->f[1] * src1->f[1]; @@ -975,10 +971,9 @@ micro_sqrt( union tgsi_exec_channel *dst, } static void -micro_sub( - union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src0, - const union tgsi_exec_channel *src1 ) +micro_sub(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { dst->f[0] = src0->f[0] - src1->f[0]; dst->f[1] = src0->f[1] - src1->f[1]; @@ -2597,25 +2592,11 @@ exec_instruction( break; case TGSI_OPCODE_MUL: - FOR_EACH_ENABLED_CHANNEL(*inst, chan_index) { - FETCH(&r[0], 0, chan_index); - FETCH(&r[1], 1, chan_index); - micro_mul(&d[chan_index], &r[0], &r[1]); - } - FOR_EACH_ENABLED_CHANNEL(*inst, chan_index) { - STORE(&d[chan_index], 0, chan_index); - } + exec_vector_binary(mach, inst, micro_mul, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT); break; case TGSI_OPCODE_ADD: - FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) { - FETCH( &r[0], 0, chan_index ); - FETCH( &r[1], 1, chan_index ); - micro_add(&d[chan_index], &r[0], &r[1]); - } - FOR_EACH_ENABLED_CHANNEL(*inst, chan_index) { - STORE(&d[chan_index], 0, chan_index); - } + exec_vector_binary(mach, inst, micro_add, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT); break; case TGSI_OPCODE_DP3: @@ -2654,29 +2635,11 @@ exec_instruction( break; case TGSI_OPCODE_MIN: - FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) { - FETCH(&r[0], 0, chan_index); - FETCH(&r[1], 1, chan_index); - - /* XXX use micro_min()?? */ - micro_lt(&d[chan_index], &r[0], &r[1], &r[0], &r[1]); - } - FOR_EACH_ENABLED_CHANNEL(*inst, chan_index) { - STORE(&d[chan_index], 0, chan_index); - } + exec_vector_binary(mach, inst, micro_min, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT); break; case TGSI_OPCODE_MAX: - FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) { - FETCH(&r[0], 0, chan_index); - FETCH(&r[1], 1, chan_index); - - /* XXX use micro_max()?? */ - micro_lt(&d[chan_index], &r[0], &r[1], &r[1], &r[0] ); - } - FOR_EACH_ENABLED_CHANNEL(*inst, chan_index) { - STORE(&d[chan_index], 0, chan_index); - } + exec_vector_binary(mach, inst, micro_max, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT); break; case TGSI_OPCODE_SLT: @@ -2692,14 +2655,7 @@ exec_instruction( break; case TGSI_OPCODE_SUB: - FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) { - FETCH(&r[0], 0, chan_index); - FETCH(&r[1], 1, chan_index); - micro_sub(&d[chan_index], &r[0], &r[1]); - } - FOR_EACH_ENABLED_CHANNEL(*inst, chan_index) { - STORE(&d[chan_index], 0, chan_index); - } + exec_vector_binary(mach, inst, micro_sub, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT); break; case TGSI_OPCODE_LRP: -- cgit v1.2.3 From f6106566081978f663cf08e54bb8908cb58a5316 Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Fri, 19 Feb 2010 19:00:26 +0100 Subject: gallium: WIP: Introduce sampler views. --- src/gallium/auxiliary/Makefile | 13 ++-- src/gallium/auxiliary/SConscript | 12 +-- src/gallium/auxiliary/cso_cache/cso_context.c | 78 +++++++++++++++++--- src/gallium/auxiliary/draw/draw_pipe_aaline.c | 58 ++++++++++----- src/gallium/auxiliary/draw/draw_pipe_pstipple.c | 58 ++++++++++----- src/gallium/auxiliary/util/u_blitter.c | 36 +++++++-- src/gallium/auxiliary/util/u_blitter.h | 24 +++--- src/gallium/auxiliary/util/u_inlines.h | 10 +++ src/gallium/auxiliary/util/u_sampler.c | 97 +++++++++++++++++++++++++ src/gallium/auxiliary/util/u_sampler.h | 57 +++++++++++++++ src/gallium/drivers/failover/fo_context.h | 8 +- src/gallium/drivers/failover/fo_state.c | 60 +++++++-------- src/gallium/drivers/failover/fo_state_emit.c | 10 +-- src/gallium/drivers/identity/id_context.c | 52 ++++++------- src/gallium/drivers/identity/id_objects.h | 26 +++++++ src/gallium/drivers/softpipe/sp_context.c | 8 +- src/gallium/drivers/softpipe/sp_context.h | 8 +- src/gallium/drivers/softpipe/sp_flush.c | 4 +- src/gallium/drivers/softpipe/sp_state.h | 12 +-- src/gallium/drivers/softpipe/sp_state_sampler.c | 63 ++++++++++------ src/gallium/drivers/svga/svga_context.h | 4 +- src/gallium/drivers/svga/svga_pipe_sampler.c | 30 ++++---- src/gallium/drivers/svga/svga_state_constants.c | 2 +- src/gallium/drivers/svga/svga_state_fs.c | 9 ++- src/gallium/drivers/svga/svga_state_tss.c | 22 +++--- src/gallium/drivers/trace/tr_context.c | 76 +++++++++---------- src/gallium/drivers/trace/tr_context.h | 10 +-- src/gallium/drivers/trace/tr_rbug.c | 8 +- src/gallium/drivers/trace/tr_texture.h | 19 +++++ src/gallium/include/pipe/p_context.h | 22 ++++-- src/gallium/include/pipe/p_defines.h | 11 +++ src/gallium/include/pipe/p_state.h | 18 +++++ src/mesa/state_tracker/st_cb_drawpixels.c | 4 +- 33 files changed, 656 insertions(+), 273 deletions(-) create mode 100644 src/gallium/auxiliary/util/u_sampler.c create mode 100644 src/gallium/auxiliary/util/u_sampler.h (limited to 'src/gallium') diff --git a/src/gallium/auxiliary/Makefile b/src/gallium/auxiliary/Makefile index ff7695150e2..ec986355140 100644 --- a/src/gallium/auxiliary/Makefile +++ b/src/gallium/auxiliary/Makefile @@ -125,12 +125,13 @@ C_SOURCES = \ util/u_tile.c \ util/u_timed_winsys.c \ util/u_upload_mgr.c \ - util/u_simple_screen.c \ - vl/vl_bitstream_parser.c \ - vl/vl_mpeg12_mc_renderer.c \ - vl/vl_compositor.c \ - vl/vl_csc.c \ - vl/vl_shader_build.c + util/u_simple_screen.c + # Disabling until pipe-video branch gets merged in + #vl/vl_bitstream_parser.c \ + #vl/vl_mpeg12_mc_renderer.c \ + #vl/vl_compositor.c \ + #vl/vl_csc.c \ + #vl/vl_shader_build.c GALLIVM_SOURCES = \ gallivm/lp_bld_alpha.c \ diff --git a/src/gallium/auxiliary/SConscript b/src/gallium/auxiliary/SConscript index b531ad2dbd9..acb03e62829 100644 --- a/src/gallium/auxiliary/SConscript +++ b/src/gallium/auxiliary/SConscript @@ -153,6 +153,7 @@ source = [ 'util/u_mm.c', 'util/u_rect.c', 'util/u_ringbuffer.c', + 'util/u_sampler.c', 'util/u_simple_shaders.c', 'util/u_snprintf.c', 'util/u_surface.c', @@ -161,11 +162,12 @@ source = [ 'util/u_timed_winsys.c', 'util/u_upload_mgr.c', 'util/u_simple_screen.c', - 'vl/vl_bitstream_parser.c', - 'vl/vl_mpeg12_mc_renderer.c', - 'vl/vl_compositor.c', - 'vl/vl_csc.c', - 'vl/vl_shader_build.c', + # Disabling until pipe-video branch gets merged in + #'vl/vl_bitstream_parser.c', + #'vl/vl_mpeg12_mc_renderer.c', + #'vl/vl_compositor.c', + #'vl/vl_csc.c', + #'vl/vl_shader_build.c', ] if drawllvm: diff --git a/src/gallium/auxiliary/cso_cache/cso_context.c b/src/gallium/auxiliary/cso_cache/cso_context.c index b5241fa64c6..6ae765c8991 100644 --- a/src/gallium/auxiliary/cso_cache/cso_context.c +++ b/src/gallium/auxiliary/cso_cache/cso_context.c @@ -38,6 +38,7 @@ #include "pipe/p_state.h" #include "util/u_inlines.h" #include "util/u_memory.h" +#include "util/u_sampler.h" #include "tgsi/tgsi_parse.h" #include "cso_cache/cso_context.h" @@ -70,16 +71,20 @@ struct cso_context { void *vertex_samplers_saved[PIPE_MAX_VERTEX_SAMPLERS]; struct pipe_texture *textures[PIPE_MAX_SAMPLERS]; + struct pipe_sampler_view *sampler_views[PIPE_MAX_SAMPLERS]; uint nr_textures; struct pipe_texture *vertex_textures[PIPE_MAX_VERTEX_SAMPLERS]; + struct pipe_sampler_view *vertex_sampler_views[PIPE_MAX_VERTEX_SAMPLERS]; uint nr_vertex_textures; uint nr_textures_saved; struct pipe_texture *textures_saved[PIPE_MAX_SAMPLERS]; + struct pipe_sampler_view *sampler_views_saved[PIPE_MAX_SAMPLERS]; uint nr_vertex_textures_saved; - struct pipe_texture *vertex_textures_saved[PIPE_MAX_SAMPLERS]; + struct pipe_texture *vertex_textures_saved[PIPE_MAX_VERTEX_SAMPLERS]; + struct pipe_sampler_view *vertex_sampler_views_saved[PIPE_MAX_VERTEX_SAMPLERS]; /** Current and saved state. * The saved state is used as a 1-deep stack. @@ -273,11 +278,15 @@ void cso_release_all( struct cso_context *ctx ) for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { pipe_texture_reference(&ctx->textures[i], NULL); pipe_texture_reference(&ctx->textures_saved[i], NULL); + pipe_sampler_view_reference(&ctx->sampler_views[i], NULL); + pipe_sampler_view_reference(&ctx->sampler_views_saved[i], NULL); } for (i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; i++) { pipe_texture_reference(&ctx->vertex_textures[i], NULL); pipe_texture_reference(&ctx->vertex_textures_saved[i], NULL); + pipe_sampler_view_reference(&ctx->vertex_sampler_views[i], NULL); + pipe_sampler_view_reference(&ctx->vertex_sampler_views_saved[i], NULL); } free_framebuffer_state(&ctx->fb); @@ -602,12 +611,27 @@ enum pipe_error cso_set_sampler_textures( struct cso_context *ctx, ctx->nr_textures = count; - for (i = 0; i < count; i++) + for (i = 0; i < count; i++) { + struct pipe_sampler_view templ, *view; + + u_sampler_view_default_template(&templ, + textures[i], + textures[i]->format); + view = ctx->pipe->create_sampler_view(ctx->pipe, + textures[i], + &templ); + pipe_texture_reference(&ctx->textures[i], textures[i]); - for ( ; i < PIPE_MAX_SAMPLERS; i++) + pipe_sampler_view_reference(&ctx->sampler_views[i], view); + } + for ( ; i < PIPE_MAX_SAMPLERS; i++) { pipe_texture_reference(&ctx->textures[i], NULL); + pipe_sampler_view_reference(&ctx->sampler_views[i], NULL); + } - ctx->pipe->set_fragment_sampler_textures(ctx->pipe, count, textures); + ctx->pipe->set_fragment_sampler_views(ctx->pipe, + count, + ctx->sampler_views); return PIPE_OK; } @@ -619,7 +643,11 @@ void cso_save_sampler_textures( struct cso_context *ctx ) ctx->nr_textures_saved = ctx->nr_textures; for (i = 0; i < ctx->nr_textures; i++) { assert(!ctx->textures_saved[i]); + assert(!ctx->sampler_views_saved[i]); + pipe_texture_reference(&ctx->textures_saved[i], ctx->textures[i]); + pipe_sampler_view_reference(&ctx->sampler_views_saved[i], + ctx->sampler_views[i]); } } @@ -633,11 +661,19 @@ void cso_restore_sampler_textures( struct cso_context *ctx ) pipe_texture_reference(&ctx->textures[i], NULL); ctx->textures[i] = ctx->textures_saved[i]; ctx->textures_saved[i] = NULL; + + pipe_sampler_view_reference(&ctx->sampler_views[i], NULL); + ctx->sampler_views[i] = ctx->sampler_views_saved[i]; + ctx->sampler_views_saved[i] = NULL; } - for ( ; i < PIPE_MAX_SAMPLERS; i++) + for ( ; i < PIPE_MAX_SAMPLERS; i++) { pipe_texture_reference(&ctx->textures[i], NULL); + pipe_sampler_view_reference(&ctx->sampler_views[i], NULL); + } - ctx->pipe->set_fragment_sampler_textures(ctx->pipe, ctx->nr_textures, ctx->textures); + ctx->pipe->set_fragment_sampler_views(ctx->pipe, + ctx->nr_textures, + ctx->sampler_views); ctx->nr_textures_saved = 0; } @@ -654,13 +690,26 @@ cso_set_vertex_sampler_textures(struct cso_context *ctx, ctx->nr_vertex_textures = count; for (i = 0; i < count; i++) { + struct pipe_sampler_view templ, *view; + + u_sampler_view_default_template(&templ, + textures[i], + textures[i]->format); + view = ctx->pipe->create_sampler_view(ctx->pipe, + textures[i], + &templ); + pipe_texture_reference(&ctx->vertex_textures[i], textures[i]); + pipe_sampler_view_reference(&ctx->vertex_sampler_views[i], view); } for ( ; i < PIPE_MAX_VERTEX_SAMPLERS; i++) { pipe_texture_reference(&ctx->vertex_textures[i], NULL); + pipe_sampler_view_reference(&ctx->vertex_sampler_views[i], NULL); } - ctx->pipe->set_vertex_sampler_textures(ctx->pipe, count, textures); + ctx->pipe->set_vertex_sampler_views(ctx->pipe, + count, + ctx->vertex_sampler_views); return PIPE_OK; } @@ -673,7 +722,11 @@ cso_save_vertex_sampler_textures(struct cso_context *ctx) ctx->nr_vertex_textures_saved = ctx->nr_vertex_textures; for (i = 0; i < ctx->nr_vertex_textures; i++) { assert(!ctx->vertex_textures_saved[i]); + assert(!ctx->vertex_sampler_views_saved[i]); + pipe_texture_reference(&ctx->vertex_textures_saved[i], ctx->vertex_textures[i]); + pipe_sampler_view_reference(&ctx->vertex_sampler_views_saved[i], + ctx->vertex_sampler_views[i]); } } @@ -688,14 +741,19 @@ cso_restore_vertex_sampler_textures(struct cso_context *ctx) pipe_texture_reference(&ctx->vertex_textures[i], NULL); ctx->vertex_textures[i] = ctx->vertex_textures_saved[i]; ctx->vertex_textures_saved[i] = NULL; + + pipe_sampler_view_reference(&ctx->vertex_sampler_views[i], NULL); + ctx->vertex_sampler_views[i] = ctx->vertex_sampler_views_saved[i]; + ctx->vertex_sampler_views_saved[i] = NULL; } for ( ; i < PIPE_MAX_VERTEX_SAMPLERS; i++) { pipe_texture_reference(&ctx->vertex_textures[i], NULL); + pipe_sampler_view_reference(&ctx->vertex_sampler_views[i], NULL); } - ctx->pipe->set_vertex_sampler_textures(ctx->pipe, - ctx->nr_vertex_textures, - ctx->vertex_textures); + ctx->pipe->set_vertex_sampler_views(ctx->pipe, + ctx->nr_vertex_textures, + ctx->vertex_sampler_views); ctx->nr_vertex_textures_saved = 0; } diff --git a/src/gallium/auxiliary/draw/draw_pipe_aaline.c b/src/gallium/auxiliary/draw/draw_pipe_aaline.c index 8f6ca15dfa2..70d7dbdfc75 100644 --- a/src/gallium/auxiliary/draw/draw_pipe_aaline.c +++ b/src/gallium/auxiliary/draw/draw_pipe_aaline.c @@ -40,6 +40,7 @@ #include "util/u_format.h" #include "util/u_math.h" #include "util/u_memory.h" +#include "util/u_sampler.h" #include "tgsi/tgsi_transform.h" #include "tgsi/tgsi_dump.h" @@ -88,8 +89,9 @@ struct aaline_stage void *sampler_cso; struct pipe_texture *texture; + struct pipe_sampler_view *sampler_view; uint num_samplers; - uint num_textures; + uint num_sampler_views; /* @@ -98,7 +100,7 @@ struct aaline_stage struct aaline_fragment_shader *fs; struct { void *sampler[PIPE_MAX_SAMPLERS]; - struct pipe_texture *texture[PIPE_MAX_SAMPLERS]; + struct pipe_sampler_view *sampler_views[PIPE_MAX_SAMPLERS]; } state; /* @@ -111,8 +113,9 @@ struct aaline_stage void (*driver_bind_sampler_states)(struct pipe_context *, unsigned, void **); - void (*driver_set_sampler_textures)(struct pipe_context *, unsigned, - struct pipe_texture **); + void (*driver_set_sampler_views)(struct pipe_context *, + unsigned, + struct pipe_sampler_view **); struct pipe_context *pipe; }; @@ -394,6 +397,7 @@ aaline_create_texture(struct aaline_stage *aaline) struct pipe_context *pipe = aaline->pipe; struct pipe_screen *screen = pipe->screen; struct pipe_texture texTemp; + struct pipe_sampler_view viewTempl; uint level; memset(&texTemp, 0, sizeof(texTemp)); @@ -408,6 +412,16 @@ aaline_create_texture(struct aaline_stage *aaline) if (!aaline->texture) return FALSE; + u_sampler_view_default_template(&viewTempl, + aaline->texture, + aaline->texture->format); + aaline->sampler_view = pipe->create_sampler_view(pipe, + aaline->texture, + &viewTempl); + if (!aaline->sampler_view) { + return FALSE; + } + /* Fill in mipmap images. * Basically each level is solid opaque, except for the outermost * texels which are zero. Special case the 1x1 and 2x2 levels. @@ -669,16 +683,16 @@ aaline_first_line(struct draw_stage *stage, struct prim_header *header) /* how many samplers? */ /* we'll use sampler/texture[pstip->sampler_unit] for the stipple */ - num_samplers = MAX2(aaline->num_textures, aaline->num_samplers); + num_samplers = MAX2(aaline->num_sampler_views, aaline->num_samplers); num_samplers = MAX2(num_samplers, aaline->fs->sampler_unit + 1); aaline->state.sampler[aaline->fs->sampler_unit] = aaline->sampler_cso; - pipe_texture_reference(&aaline->state.texture[aaline->fs->sampler_unit], - aaline->texture); + pipe_sampler_view_reference(&aaline->state.sampler_views[aaline->fs->sampler_unit], + aaline->sampler_view); draw->suspend_flushing = TRUE; aaline->driver_bind_sampler_states(pipe, num_samplers, aaline->state.sampler); - aaline->driver_set_sampler_textures(pipe, num_samplers, aaline->state.texture); + aaline->driver_set_sampler_views(pipe, num_samplers, aaline->state.sampler_views); draw->suspend_flushing = FALSE; /* now really draw first line */ @@ -702,8 +716,9 @@ aaline_flush(struct draw_stage *stage, unsigned flags) aaline->driver_bind_fs_state(pipe, aaline->fs->driver_fs); aaline->driver_bind_sampler_states(pipe, aaline->num_samplers, aaline->state.sampler); - aaline->driver_set_sampler_textures(pipe, aaline->num_textures, - aaline->state.texture); + aaline->driver_set_sampler_views(pipe, + aaline->num_sampler_views, + aaline->state.sampler_views); draw->suspend_flushing = FALSE; draw->extra_shader_outputs.slot = 0; @@ -724,7 +739,7 @@ aaline_destroy(struct draw_stage *stage) uint i; for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { - pipe_texture_reference(&aaline->state.texture[i], NULL); + pipe_sampler_view_reference(&aaline->state.sampler_views[i], NULL); } if (aaline->sampler_cso) @@ -733,6 +748,10 @@ aaline_destroy(struct draw_stage *stage) if (aaline->texture) pipe_texture_reference(&aaline->texture, NULL); + if (aaline->sampler_view) { + pipe_sampler_view_reference(&aaline->sampler_view, NULL); + } + draw_free_temp_verts( stage ); FREE( stage ); @@ -844,23 +863,24 @@ aaline_bind_sampler_states(struct pipe_context *pipe, static void -aaline_set_sampler_textures(struct pipe_context *pipe, - unsigned num, struct pipe_texture **texture) +aaline_set_sampler_views(struct pipe_context *pipe, + unsigned num, + struct pipe_sampler_view **views) { struct aaline_stage *aaline = aaline_stage_from_pipe(pipe); uint i; /* save current */ for (i = 0; i < num; i++) { - pipe_texture_reference(&aaline->state.texture[i], texture[i]); + pipe_sampler_view_reference(&aaline->state.sampler_views[i], views[i]); } for ( ; i < PIPE_MAX_SAMPLERS; i++) { - pipe_texture_reference(&aaline->state.texture[i], NULL); + pipe_sampler_view_reference(&aaline->state.sampler_views[i], NULL); } - aaline->num_textures = num; + aaline->num_sampler_views = num; /* pass-through */ - aaline->driver_set_sampler_textures(aaline->pipe, num, texture); + aaline->driver_set_sampler_views(aaline->pipe, num, views); } @@ -898,7 +918,7 @@ draw_install_aaline_stage(struct draw_context *draw, struct pipe_context *pipe) aaline->driver_delete_fs_state = pipe->delete_fs_state; aaline->driver_bind_sampler_states = pipe->bind_fragment_sampler_states; - aaline->driver_set_sampler_textures = pipe->set_fragment_sampler_textures; + aaline->driver_set_sampler_views = pipe->set_fragment_sampler_views; /* override the driver's functions */ pipe->create_fs_state = aaline_create_fs_state; @@ -906,7 +926,7 @@ draw_install_aaline_stage(struct draw_context *draw, struct pipe_context *pipe) pipe->delete_fs_state = aaline_delete_fs_state; pipe->bind_fragment_sampler_states = aaline_bind_sampler_states; - pipe->set_fragment_sampler_textures = aaline_set_sampler_textures; + pipe->set_fragment_sampler_views = aaline_set_sampler_views; /* Install once everything is known to be OK: */ diff --git a/src/gallium/auxiliary/draw/draw_pipe_pstipple.c b/src/gallium/auxiliary/draw/draw_pipe_pstipple.c index d0d99aa331a..e03081d65c5 100644 --- a/src/gallium/auxiliary/draw/draw_pipe_pstipple.c +++ b/src/gallium/auxiliary/draw/draw_pipe_pstipple.c @@ -42,6 +42,7 @@ #include "util/u_format.h" #include "util/u_math.h" #include "util/u_memory.h" +#include "util/u_sampler.h" #include "tgsi/tgsi_transform.h" #include "tgsi/tgsi_dump.h" @@ -75,8 +76,9 @@ struct pstip_stage void *sampler_cso; struct pipe_texture *texture; + struct pipe_sampler_view *sampler_view; uint num_samplers; - uint num_textures; + uint num_sampler_views; /* * Currently bound state @@ -84,7 +86,7 @@ struct pstip_stage struct pstip_fragment_shader *fs; struct { void *samplers[PIPE_MAX_SAMPLERS]; - struct pipe_texture *textures[PIPE_MAX_SAMPLERS]; + struct pipe_sampler_view *sampler_views[PIPE_MAX_SAMPLERS]; const struct pipe_poly_stipple *stipple; } state; @@ -98,8 +100,9 @@ struct pstip_stage void (*driver_bind_sampler_states)(struct pipe_context *, unsigned, void **); - void (*driver_set_sampler_textures)(struct pipe_context *, unsigned, - struct pipe_texture **); + void (*driver_set_sampler_views)(struct pipe_context *, + unsigned, + struct pipe_sampler_view **); void (*driver_set_polygon_stipple)(struct pipe_context *, const struct pipe_poly_stipple *); @@ -422,6 +425,7 @@ pstip_create_texture(struct pstip_stage *pstip) struct pipe_context *pipe = pstip->pipe; struct pipe_screen *screen = pipe->screen; struct pipe_texture texTemp; + struct pipe_sampler_view viewTempl; memset(&texTemp, 0, sizeof(texTemp)); texTemp.target = PIPE_TEXTURE_2D; @@ -435,6 +439,16 @@ pstip_create_texture(struct pstip_stage *pstip) if (pstip->texture == NULL) return FALSE; + u_sampler_view_default_template(&viewTempl, + pstip->texture, + pstip->texture->format); + pstip->sampler_view = pipe->create_sampler_view(pipe, + pstip->texture, + &viewTempl); + if (!pstip->sampler_view) { + return FALSE; + } + return TRUE; } @@ -513,19 +527,19 @@ pstip_first_tri(struct draw_stage *stage, struct prim_header *header) /* how many samplers? */ /* we'll use sampler/texture[pstip->sampler_unit] for the stipple */ - num_samplers = MAX2(pstip->num_textures, pstip->num_samplers); + num_samplers = MAX2(pstip->num_sampler_views, pstip->num_samplers); num_samplers = MAX2(num_samplers, pstip->fs->sampler_unit + 1); /* plug in our sampler, texture */ pstip->state.samplers[pstip->fs->sampler_unit] = pstip->sampler_cso; - pipe_texture_reference(&pstip->state.textures[pstip->fs->sampler_unit], - pstip->texture); + pipe_sampler_view_reference(&pstip->state.sampler_views[pstip->fs->sampler_unit], + pstip->sampler_view); assert(num_samplers <= PIPE_MAX_SAMPLERS); draw->suspend_flushing = TRUE; pstip->driver_bind_sampler_states(pipe, num_samplers, pstip->state.samplers); - pstip->driver_set_sampler_textures(pipe, num_samplers, pstip->state.textures); + pstip->driver_set_sampler_views(pipe, num_samplers, pstip->state.sampler_views); draw->suspend_flushing = FALSE; /* now really draw first triangle */ @@ -549,8 +563,9 @@ pstip_flush(struct draw_stage *stage, unsigned flags) pstip->driver_bind_fs_state(pipe, pstip->fs->driver_fs); pstip->driver_bind_sampler_states(pipe, pstip->num_samplers, pstip->state.samplers); - pstip->driver_set_sampler_textures(pipe, pstip->num_textures, - pstip->state.textures); + pstip->driver_set_sampler_views(pipe, + pstip->num_sampler_views, + pstip->state.sampler_views); draw->suspend_flushing = FALSE; } @@ -569,13 +584,17 @@ pstip_destroy(struct draw_stage *stage) uint i; for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { - pipe_texture_reference(&pstip->state.textures[i], NULL); + pipe_sampler_view_reference(&pstip->state.sampler_views[i], NULL); } pstip->pipe->delete_sampler_state(pstip->pipe, pstip->sampler_cso); pipe_texture_reference(&pstip->texture, NULL); + if (pstip->sampler_view) { + pipe_sampler_view_reference(&pstip->sampler_view, NULL); + } + draw_free_temp_verts( stage ); FREE( stage ); } @@ -680,24 +699,25 @@ pstip_bind_sampler_states(struct pipe_context *pipe, static void -pstip_set_sampler_textures(struct pipe_context *pipe, - unsigned num, struct pipe_texture **texture) +pstip_set_sampler_views(struct pipe_context *pipe, + unsigned num, + struct pipe_sampler_view **views) { struct pstip_stage *pstip = pstip_stage_from_pipe(pipe); uint i; /* save current */ for (i = 0; i < num; i++) { - pipe_texture_reference(&pstip->state.textures[i], texture[i]); + pipe_sampler_view_reference(&pstip->state.sampler_views[i], views[i]); } for (; i < PIPE_MAX_SAMPLERS; i++) { - pipe_texture_reference(&pstip->state.textures[i], NULL); + pipe_sampler_view_reference(&pstip->state.sampler_views[i], NULL); } - pstip->num_textures = num; + pstip->num_sampler_views = num; /* pass-through */ - pstip->driver_set_sampler_textures(pstip->pipe, num, texture); + pstip->driver_set_sampler_views(pstip->pipe, num, views); } @@ -754,7 +774,7 @@ draw_install_pstipple_stage(struct draw_context *draw, pstip->driver_delete_fs_state = pipe->delete_fs_state; pstip->driver_bind_sampler_states = pipe->bind_fragment_sampler_states; - pstip->driver_set_sampler_textures = pipe->set_fragment_sampler_textures; + pstip->driver_set_sampler_views = pipe->set_fragment_sampler_views; pstip->driver_set_polygon_stipple = pipe->set_polygon_stipple; /* override the driver's functions */ @@ -763,7 +783,7 @@ draw_install_pstipple_stage(struct draw_context *draw, pipe->delete_fs_state = pstip_delete_fs_state; pipe->bind_fragment_sampler_states = pstip_bind_sampler_states; - pipe->set_fragment_sampler_textures = pstip_set_sampler_textures; + pipe->set_fragment_sampler_views = pstip_set_sampler_views; pipe->set_polygon_stipple = pstip_set_polygon_stipple; return TRUE; diff --git a/src/gallium/auxiliary/util/u_blitter.c b/src/gallium/auxiliary/util/u_blitter.c index 18f86068183..29060a1effe 100644 --- a/src/gallium/auxiliary/util/u_blitter.c +++ b/src/gallium/auxiliary/util/u_blitter.c @@ -45,6 +45,7 @@ #include "util/u_draw_quad.h" #include "util/u_pack_color.h" #include "util/u_rect.h" +#include "util/u_sampler.h" #include "util/u_simple_shaders.h" #include "util/u_texture.h" @@ -93,6 +94,8 @@ struct blitter_context_priv /* Rasterizer state. */ void *rs_state; + + struct pipe_sampler_view *sampler_view; }; struct blitter_context *util_blitter_create(struct pipe_context *pipe) @@ -117,7 +120,7 @@ struct blitter_context *util_blitter_create(struct pipe_context *pipe) ctx->blitter.saved_fs = INVALID_PTR; ctx->blitter.saved_vs = INVALID_PTR; ctx->blitter.saved_fb_state.nr_cbufs = ~0; - ctx->blitter.saved_num_textures = ~0; + ctx->blitter.saved_num_sampler_views = ~0; ctx->blitter.saved_num_sampler_states = ~0; /* blend state objects */ @@ -230,6 +233,10 @@ void util_blitter_destroy(struct blitter_context *blitter) if (ctx->sampler_state[i]) pipe->delete_sampler_state(pipe, ctx->sampler_state[i]); + if (ctx->sampler_view) { + pipe_sampler_view_reference(&ctx->sampler_view, NULL); + } + pipe_buffer_reference(&ctx->vbuf, NULL); FREE(ctx); } @@ -277,11 +284,11 @@ static void blitter_restore_CSOs(struct blitter_context_priv *ctx) ctx->blitter.saved_num_sampler_states = ~0; } - if (ctx->blitter.saved_num_textures != ~0) { - pipe->set_fragment_sampler_textures(pipe, - ctx->blitter.saved_num_textures, - ctx->blitter.saved_textures); - ctx->blitter.saved_num_textures = ~0; + if (ctx->blitter.saved_num_sampler_views != ~0) { + pipe->set_fragment_sampler_views(pipe, + ctx->blitter.saved_num_sampler_views, + ctx->blitter.saved_sampler_views); + ctx->blitter.saved_num_sampler_views = ~0; } } @@ -577,9 +584,10 @@ static void util_blitter_do_copy(struct blitter_context *blitter, struct blitter_context_priv *ctx = (struct blitter_context_priv*)blitter; struct pipe_context *pipe = ctx->pipe; struct pipe_framebuffer_state fb_state; + struct pipe_sampler_view viewTempl, *view; assert(blitter->saved_fb_state.nr_cbufs != ~0); - assert(blitter->saved_num_textures != ~0); + assert(blitter->saved_num_sampler_views != ~0); assert(blitter->saved_num_sampler_states != ~0); assert(src->texture->target < PIPE_MAX_TEXTURE_TYPES); @@ -607,11 +615,23 @@ static void util_blitter_do_copy(struct blitter_context *blitter, fb_state.zsbuf = 0; } + u_sampler_view_default_template(&viewTempl, + src->texture, + src->texture->format); + view = pipe->create_sampler_view(pipe, + src->texture, + &viewTempl); + + if (ctx->sampler_view) { + pipe_sampler_view_reference(&ctx->sampler_view, NULL); + } + ctx->sampler_view = view; + pipe->bind_rasterizer_state(pipe, ctx->rs_state); pipe->bind_vs_state(pipe, ctx->vs_tex); pipe->bind_fragment_sampler_states(pipe, 1, blitter_get_sampler_state(ctx, src->level)); - pipe->set_fragment_sampler_textures(pipe, 1, &src->texture); + pipe->set_fragment_sampler_views(pipe, 1, &view); pipe->set_framebuffer_state(pipe, &fb_state); /* set texture coordinates */ diff --git a/src/gallium/auxiliary/util/u_blitter.h b/src/gallium/auxiliary/util/u_blitter.h index a2f17073ac6..99119485603 100644 --- a/src/gallium/auxiliary/util/u_blitter.h +++ b/src/gallium/auxiliary/util/u_blitter.h @@ -50,10 +50,10 @@ struct blitter_context struct pipe_stencil_ref saved_stencil_ref; /**< stencil ref */ int saved_num_sampler_states; - void *saved_sampler_states[32]; + void *saved_sampler_states[PIPE_MAX_SAMPLERS]; - int saved_num_textures; - struct pipe_texture *saved_textures[32]; /* is 32 enough? */ + int saved_num_sampler_views; + struct pipe_sampler_view *saved_sampler_views[PIPE_MAX_SAMPLERS]; }; /** @@ -218,17 +218,17 @@ void util_blitter_save_fragment_sampler_states( num_sampler_states * sizeof(void *)); } -static INLINE -void util_blitter_save_fragment_sampler_textures( - struct blitter_context *blitter, - int num_textures, - struct pipe_texture **textures) +static INLINE void +util_blitter_save_fragment_sampler_views(struct blitter_context *blitter, + int num_views, + struct pipe_sampler_view **views) { - assert(num_textures <= Elements(blitter->saved_textures)); + assert(num_views <= Elements(blitter->saved_sampler_views)); - blitter->saved_num_textures = num_textures; - memcpy(blitter->saved_textures, textures, - num_textures * sizeof(struct pipe_texture *)); + blitter->saved_num_sampler_views = num_views; + memcpy(blitter->saved_sampler_views, + views, + num_views * sizeof(struct pipe_sampler_view *)); } #ifdef __cplusplus diff --git a/src/gallium/auxiliary/util/u_inlines.h b/src/gallium/auxiliary/util/u_inlines.h index e95d58ea863..f8dfea4e51a 100644 --- a/src/gallium/auxiliary/util/u_inlines.h +++ b/src/gallium/auxiliary/util/u_inlines.h @@ -117,6 +117,16 @@ pipe_texture_reference(struct pipe_texture **ptr, struct pipe_texture *tex) *ptr = tex; } +static INLINE void +pipe_sampler_view_reference(struct pipe_sampler_view **ptr, struct pipe_sampler_view *view) +{ + struct pipe_sampler_view *old_view = *ptr; + + if (pipe_reference(&(*ptr)->reference, &view->reference)) + old_view->context->sampler_view_destroy(old_view->context, old_view); + *ptr = view; +} + /* * Convenience wrappers for screen buffer functions. diff --git a/src/gallium/auxiliary/util/u_sampler.c b/src/gallium/auxiliary/util/u_sampler.c new file mode 100644 index 00000000000..3e45a2fa70d --- /dev/null +++ b/src/gallium/auxiliary/util/u_sampler.c @@ -0,0 +1,97 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +#include "u_format.h" +#include "u_sampler.h" + + +static void +default_template(struct pipe_sampler_view *view, + const struct pipe_texture *texture, + enum pipe_format format, + unsigned expand_green_blue) +{ + /* XXX: Check if format is compatible with texture->format. + */ + + view->format = format; + view->first_level = 0; + view->num_levels = texture->last_level + 1; + view->swizzle_r = PIPE_SWIZZLE_RED; + view->swizzle_g = PIPE_SWIZZLE_GREEN; + view->swizzle_b = PIPE_SWIZZLE_BLUE; + view->swizzle_a = PIPE_SWIZZLE_ALPHA; + + /* Override default green and blue component expansion to the requested one. + * + * Gallium expands nonexistent components to (0,0,0,1), DX9 expands to (1,1,1,1). + * Since alpha is always expanded to 1, and red is always present, we only really + * care about green and blue components. + * + * To make it look less hackish, one would have to add UTIL_FORMAT_SWIZZLE_EXPAND + * to indicate components for expansion and then override without exceptions or + * favoring one component over another. + */ + if (format != PIPE_FORMAT_A8_UNORM) { + const struct util_format_description *desc = util_format_description(format); + + assert(desc); + if (desc) { + if (desc->swizzle[1] == UTIL_FORMAT_SWIZZLE_0) { + view->swizzle_g = expand_green_blue; + } + if (desc->swizzle[2] == UTIL_FORMAT_SWIZZLE_0) { + view->swizzle_b = expand_green_blue; + } + } + } +} + +void +u_sampler_view_default_template(struct pipe_sampler_view *view, + const struct pipe_texture *texture, + enum pipe_format format) +{ + /* Expand to (0, 0, 0, 1) */ + default_template(view, + texture, + format, + PIPE_SWIZZLE_ZERO); +} + +void +u_sampler_view_default_dx9_template(struct pipe_sampler_view *view, + const struct pipe_texture *texture, + enum pipe_format format) +{ + /* Expand to (1, 1, 1, 1) */ + default_template(view, + texture, + format, + PIPE_SWIZZLE_ONE); +} diff --git a/src/gallium/auxiliary/util/u_sampler.h b/src/gallium/auxiliary/util/u_sampler.h new file mode 100644 index 00000000000..bdd061c851c --- /dev/null +++ b/src/gallium/auxiliary/util/u_sampler.h @@ -0,0 +1,57 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +#ifndef U_SAMPLER_H +#define U_SAMPLER_H + + +#include "pipe/p_defines.h" +#include "pipe/p_format.h" +#include "pipe/p_state.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +void +u_sampler_view_default_template(struct pipe_sampler_view *view, + const struct pipe_texture *texture, + enum pipe_format format); + +void +u_sampler_view_default_dx9_template(struct pipe_sampler_view *view, + const struct pipe_texture *texture, + enum pipe_format format); + + +#ifdef __cplusplus +} /* extern "C" { */ +#endif + +#endif /* U_SAMPLER_H */ diff --git a/src/gallium/drivers/failover/fo_context.h b/src/gallium/drivers/failover/fo_context.h index bb1a168ea7a..ae3b0b0c189 100644 --- a/src/gallium/drivers/failover/fo_context.h +++ b/src/gallium/drivers/failover/fo_context.h @@ -85,8 +85,8 @@ struct failover_context { struct pipe_framebuffer_state framebuffer; struct pipe_poly_stipple poly_stipple; struct pipe_scissor_state scissor; - struct pipe_texture *texture[PIPE_MAX_SAMPLERS]; - struct pipe_texture *vertex_textures[PIPE_MAX_VERTEX_SAMPLERS]; + struct pipe_sampler_view *sampler_views[PIPE_MAX_SAMPLERS]; + struct pipe_sampler_view *vertex_sampler_views[PIPE_MAX_VERTEX_SAMPLERS]; struct pipe_viewport_state viewport; struct pipe_vertex_buffer vertex_buffers[PIPE_MAX_ATTRIBS]; struct pipe_vertex_element vertex_elements[PIPE_MAX_ATTRIBS]; @@ -103,8 +103,8 @@ struct failover_context { unsigned num_samplers; unsigned num_vertex_samplers; - unsigned num_textures; - unsigned num_vertex_textures; + unsigned num_sampler_views; + unsigned num_vertex_sampler_views; unsigned mode; struct pipe_context *hw; diff --git a/src/gallium/drivers/failover/fo_state.c b/src/gallium/drivers/failover/fo_state.c index 970606a3f50..b16f2197f11 100644 --- a/src/gallium/drivers/failover/fo_state.c +++ b/src/gallium/drivers/failover/fo_state.c @@ -405,9 +405,9 @@ failover_delete_sampler_state(struct pipe_context *pipe, void *sampler) static void -failover_set_fragment_sampler_textures(struct pipe_context *pipe, - unsigned num, - struct pipe_texture **texture) +failover_set_fragment_sampler_views(struct pipe_context *pipe, + unsigned num, + struct pipe_sampler_view **views) { struct failover_context *failover = failover_context(pipe); uint i; @@ -415,49 +415,49 @@ failover_set_fragment_sampler_textures(struct pipe_context *pipe, assert(num <= PIPE_MAX_SAMPLERS); /* Check for no-op */ - if (num == failover->num_textures && - !memcmp(failover->texture, texture, num * sizeof(struct pipe_texture *))) + if (num == failover->num_sampler_views && + !memcmp(failover->sampler_views, views, num * sizeof(struct pipe_sampler_view *))) return; for (i = 0; i < num; i++) - pipe_texture_reference((struct pipe_texture **) &failover->texture[i], - texture[i]); - for (i = num; i < failover->num_textures; i++) - pipe_texture_reference((struct pipe_texture **) &failover->texture[i], - NULL); + pipe_sampler_view_reference((struct pipe_sampler_view **) &failover->sampler_views[i], + views[i]); + for (i = num; i < failover->num_sampler_views; i++) + pipe_sampler_view_reference((struct pipe_sampler_view **) &failover->sampler_views[i], + NULL); failover->dirty |= FO_NEW_TEXTURE; - failover->num_textures = num; - failover->sw->set_fragment_sampler_textures( failover->sw, num, texture ); - failover->hw->set_fragment_sampler_textures( failover->hw, num, texture ); + failover->num_sampler_views = num; + failover->sw->set_fragment_sampler_views( failover->sw, num, views ); + failover->hw->set_fragment_sampler_views( failover->hw, num, views ); } static void -failover_set_vertex_sampler_textures(struct pipe_context *pipe, - unsigned num_textures, - struct pipe_texture **textures) +failover_set_vertex_sampler_views(struct pipe_context *pipe, + unsigned num, + struct pipe_sampler_view **views) { struct failover_context *failover = failover_context(pipe); uint i; - assert(num_textures <= PIPE_MAX_VERTEX_SAMPLERS); + assert(num <= PIPE_MAX_VERTEX_SAMPLERS); /* Check for no-op */ - if (num_textures == failover->num_vertex_textures && - !memcmp(failover->vertex_textures, textures, num_textures * sizeof(struct pipe_texture *))) { + if (num == failover->num_vertex_sampler_views && + !memcmp(failover->vertex_sampler_views, views, num * sizeof(struct pipe_sampler_view *))) { return; } - for (i = 0; i < num_textures; i++) { - pipe_texture_reference((struct pipe_texture **)&failover->vertex_textures[i], - textures[i]); + for (i = 0; i < num; i++) { + pipe_sampler_view_reference((struct pipe_sampler_view **)&failover->vertex_sampler_views[i], + views[i]); } - for (i = num_textures; i < failover->num_vertex_textures; i++) { - pipe_texture_reference((struct pipe_texture **)&failover->vertex_textures[i], - NULL); + for (i = num; i < failover->num_vertex_sampler_views; i++) { + pipe_sampler_view_reference((struct pipe_sampler_view **)&failover->vertex_sampler_views[i], + NULL); } failover->dirty |= FO_NEW_TEXTURE; - failover->num_vertex_textures = num_textures; - failover->sw->set_vertex_sampler_textures(failover->sw, num_textures, textures); - failover->hw->set_vertex_sampler_textures(failover->hw, num_textures, textures); + failover->num_vertex_sampler_views = num; + failover->sw->set_vertex_sampler_views(failover->sw, num, views); + failover->hw->set_vertex_sampler_views(failover->hw, num, views); } @@ -550,8 +550,8 @@ failover_init_state_functions( struct failover_context *failover ) failover->pipe.set_framebuffer_state = failover_set_framebuffer_state; failover->pipe.set_polygon_stipple = failover_set_polygon_stipple; failover->pipe.set_scissor_state = failover_set_scissor_state; - failover->pipe.set_fragment_sampler_textures = failover_set_fragment_sampler_textures; - failover->pipe.set_vertex_sampler_textures = failover_set_vertex_sampler_textures; + failover->pipe.set_fragment_sampler_views = failover_set_fragment_sampler_views; + failover->pipe.set_vertex_sampler_views = failover_set_vertex_sampler_views; failover->pipe.set_viewport_state = failover_set_viewport_state; failover->pipe.set_vertex_buffers = failover_set_vertex_buffers; failover->pipe.set_vertex_elements = failover_set_vertex_elements; diff --git a/src/gallium/drivers/failover/fo_state_emit.c b/src/gallium/drivers/failover/fo_state_emit.c index 5c000808425..1c37668027f 100644 --- a/src/gallium/drivers/failover/fo_state_emit.c +++ b/src/gallium/drivers/failover/fo_state_emit.c @@ -103,11 +103,11 @@ failover_state_emit( struct failover_context *failover ) } if (failover->dirty & FO_NEW_TEXTURE) { - failover->sw->set_fragment_sampler_textures( failover->sw, failover->num_textures, - failover->texture ); - failover->sw->set_vertex_sampler_textures(failover->sw, - failover->num_vertex_textures, - failover->vertex_textures); + failover->sw->set_fragment_sampler_views( failover->sw, failover->num_sampler_views, + failover->sampler_views ); + failover->sw->set_vertex_sampler_views(failover->sw, + failover->num_vertex_sampler_views, + failover->vertex_sampler_views); } if (failover->dirty & FO_NEW_VERTEX_BUFFER) { diff --git a/src/gallium/drivers/identity/id_context.c b/src/gallium/drivers/identity/id_context.c index 8248b2a4132..2272f4a126a 100644 --- a/src/gallium/drivers/identity/id_context.c +++ b/src/gallium/drivers/identity/id_context.c @@ -492,53 +492,49 @@ identity_set_viewport_state(struct pipe_context *_pipe, } static void -identity_set_fragment_sampler_textures(struct pipe_context *_pipe, - unsigned num_textures, - struct pipe_texture **_textures) +identity_set_fragment_sampler_views(struct pipe_context *_pipe, + unsigned num, + struct pipe_sampler_view **_views) { struct identity_context *id_pipe = identity_context(_pipe); struct pipe_context *pipe = id_pipe->pipe; - struct pipe_texture *unwrapped_textures[PIPE_MAX_SAMPLERS]; - struct pipe_texture **textures = NULL; + struct pipe_sampler_view *unwrapped_views[PIPE_MAX_SAMPLERS]; + struct pipe_sampler_view **views = NULL; unsigned i; - if (_textures) { - for (i = 0; i < num_textures; i++) - unwrapped_textures[i] = identity_texture_unwrap(_textures[i]); + if (_views) { + for (i = 0; i < num; i++) + unwrapped_views[i] = identity_sampler_view_unwrap(_views[i]); for (; i < PIPE_MAX_SAMPLERS; i++) - unwrapped_textures[i] = NULL; + unwrapped_views[i] = NULL; - textures = unwrapped_textures; + views = unwrapped_views; } - pipe->set_fragment_sampler_textures(pipe, - num_textures, - textures); + pipe->set_fragment_sampler_views(pipe, num, views); } static void -identity_set_vertex_sampler_textures(struct pipe_context *_pipe, - unsigned num_textures, - struct pipe_texture **_textures) +identity_set_vertex_sampler_views(struct pipe_context *_pipe, + unsigned num, + struct pipe_sampler_view **_views) { struct identity_context *id_pipe = identity_context(_pipe); struct pipe_context *pipe = id_pipe->pipe; - struct pipe_texture *unwrapped_textures[PIPE_MAX_VERTEX_SAMPLERS]; - struct pipe_texture **textures = NULL; + struct pipe_sampler_view *unwrapped_views[PIPE_MAX_VERTEX_SAMPLERS]; + struct pipe_sampler_view **views = NULL; unsigned i; - if (_textures) { - for (i = 0; i < num_textures; i++) - unwrapped_textures[i] = identity_texture_unwrap(_textures[i]); + if (_views) { + for (i = 0; i < num; i++) + unwrapped_views[i] = identity_sampler_view_unwrap(_views[i]); for (; i < PIPE_MAX_VERTEX_SAMPLERS; i++) - unwrapped_textures[i] = NULL; + unwrapped_views[i] = NULL; - textures = unwrapped_textures; + views = unwrapped_views; } - pipe->set_vertex_sampler_textures(pipe, - num_textures, - textures); + pipe->set_vertex_sampler_views(pipe, num, views); } static void @@ -741,8 +737,8 @@ identity_context_create(struct pipe_screen *_screen, struct pipe_context *pipe) id_pipe->base.set_polygon_stipple = identity_set_polygon_stipple; id_pipe->base.set_scissor_state = identity_set_scissor_state; id_pipe->base.set_viewport_state = identity_set_viewport_state; - id_pipe->base.set_fragment_sampler_textures = identity_set_fragment_sampler_textures; - id_pipe->base.set_vertex_sampler_textures = identity_set_vertex_sampler_textures; + id_pipe->base.set_fragment_sampler_views = identity_set_fragment_sampler_views; + id_pipe->base.set_vertex_sampler_views = identity_set_vertex_sampler_views; id_pipe->base.set_vertex_buffers = identity_set_vertex_buffers; id_pipe->base.set_vertex_elements = identity_set_vertex_elements; id_pipe->base.surface_copy = identity_surface_copy; diff --git a/src/gallium/drivers/identity/id_objects.h b/src/gallium/drivers/identity/id_objects.h index 77cc7190798..b48df83b3ed 100644 --- a/src/gallium/drivers/identity/id_objects.h +++ b/src/gallium/drivers/identity/id_objects.h @@ -52,6 +52,14 @@ struct identity_texture }; +struct identity_sampler_view +{ + struct pipe_sampler_view base; + + struct pipe_sampler_view *sampler_view; +}; + + struct identity_surface { struct pipe_surface base; @@ -94,6 +102,15 @@ identity_texture(struct pipe_texture *_texture) return (struct identity_texture *)_texture; } +static INLINE struct identity_sampler_view * +identity_sampler_view(struct pipe_sampler_view *_sampler_view) +{ + if (!_sampler_view) { + return NULL; + } + return (struct identity_sampler_view *)_sampler_view; +} + static INLINE struct identity_surface * identity_surface(struct pipe_surface *_surface) { @@ -138,6 +155,15 @@ identity_texture_unwrap(struct pipe_texture *_texture) return identity_texture(_texture)->texture; } +static INLINE struct pipe_sampler_view * +identity_sampler_view_unwrap(struct pipe_sampler_view *_sampler_view) +{ + if (!_sampler_view) { + return NULL; + } + return identity_sampler_view(_sampler_view)->sampler_view; +} + static INLINE struct pipe_surface * identity_surface_unwrap(struct pipe_surface *_surface) { diff --git a/src/gallium/drivers/softpipe/sp_context.c b/src/gallium/drivers/softpipe/sp_context.c index ddc35bcd629..858e118bc66 100644 --- a/src/gallium/drivers/softpipe/sp_context.c +++ b/src/gallium/drivers/softpipe/sp_context.c @@ -103,12 +103,12 @@ softpipe_destroy( struct pipe_context *pipe ) for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { sp_destroy_tex_tile_cache(softpipe->tex_cache[i]); - pipe_texture_reference(&softpipe->texture[i], NULL); + pipe_sampler_view_reference(&softpipe->sampler_views[i], NULL); } for (i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; i++) { sp_destroy_tex_tile_cache(softpipe->vertex_tex_cache[i]); - pipe_texture_reference(&softpipe->vertex_textures[i], NULL); + pipe_sampler_view_reference(&softpipe->vertex_sampler_views[i], NULL); } for (i = 0; i < PIPE_SHADER_TYPES; i++) { @@ -252,8 +252,8 @@ softpipe_create_context( struct pipe_screen *screen, softpipe->pipe.set_framebuffer_state = softpipe_set_framebuffer_state; softpipe->pipe.set_polygon_stipple = softpipe_set_polygon_stipple; softpipe->pipe.set_scissor_state = softpipe_set_scissor_state; - softpipe->pipe.set_fragment_sampler_textures = softpipe_set_sampler_textures; - softpipe->pipe.set_vertex_sampler_textures = softpipe_set_vertex_sampler_textures; + softpipe->pipe.set_fragment_sampler_views = softpipe_set_sampler_views; + softpipe->pipe.set_vertex_sampler_views = softpipe_set_vertex_sampler_views; softpipe->pipe.set_viewport_state = softpipe_set_viewport_state; softpipe->pipe.set_vertex_buffers = softpipe_set_vertex_buffers; diff --git a/src/gallium/drivers/softpipe/sp_context.h b/src/gallium/drivers/softpipe/sp_context.h index 95def72c541..2f0f51de2c4 100644 --- a/src/gallium/drivers/softpipe/sp_context.h +++ b/src/gallium/drivers/softpipe/sp_context.h @@ -68,16 +68,16 @@ struct softpipe_context { struct pipe_framebuffer_state framebuffer; struct pipe_poly_stipple poly_stipple; struct pipe_scissor_state scissor; - struct pipe_texture *texture[PIPE_MAX_SAMPLERS]; - struct pipe_texture *vertex_textures[PIPE_MAX_VERTEX_SAMPLERS]; + struct pipe_sampler_view *sampler_views[PIPE_MAX_SAMPLERS]; + struct pipe_sampler_view *vertex_sampler_views[PIPE_MAX_VERTEX_SAMPLERS]; struct pipe_viewport_state viewport; struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS]; struct pipe_vertex_element vertex_element[PIPE_MAX_ATTRIBS]; unsigned num_samplers; - unsigned num_textures; + unsigned num_sampler_views; unsigned num_vertex_samplers; - unsigned num_vertex_textures; + unsigned num_vertex_sampler_views; unsigned num_vertex_elements; unsigned num_vertex_buffers; diff --git a/src/gallium/drivers/softpipe/sp_flush.c b/src/gallium/drivers/softpipe/sp_flush.c index e8952bf4fb8..38dea13c66b 100644 --- a/src/gallium/drivers/softpipe/sp_flush.c +++ b/src/gallium/drivers/softpipe/sp_flush.c @@ -50,10 +50,10 @@ softpipe_flush( struct pipe_context *pipe, draw_flush(softpipe->draw); if (flags & PIPE_FLUSH_TEXTURE_CACHE) { - for (i = 0; i < softpipe->num_textures; i++) { + for (i = 0; i < softpipe->num_sampler_views; i++) { sp_flush_tex_tile_cache(softpipe->tex_cache[i]); } - for (i = 0; i < softpipe->num_vertex_textures; i++) { + for (i = 0; i < softpipe->num_vertex_sampler_views; i++) { sp_flush_tex_tile_cache(softpipe->vertex_tex_cache[i]); } } diff --git a/src/gallium/drivers/softpipe/sp_state.h b/src/gallium/drivers/softpipe/sp_state.h index 4370bbeaee2..ba9bbfe68a4 100644 --- a/src/gallium/drivers/softpipe/sp_state.h +++ b/src/gallium/drivers/softpipe/sp_state.h @@ -166,14 +166,14 @@ void softpipe_set_polygon_stipple( struct pipe_context *, void softpipe_set_scissor_state( struct pipe_context *, const struct pipe_scissor_state * ); -void softpipe_set_sampler_textures( struct pipe_context *, - unsigned num, - struct pipe_texture ** ); +void softpipe_set_sampler_views( struct pipe_context *, + unsigned num, + struct pipe_sampler_view ** ); void -softpipe_set_vertex_sampler_textures(struct pipe_context *, - unsigned num_textures, - struct pipe_texture **); +softpipe_set_vertex_sampler_views(struct pipe_context *, + unsigned num, + struct pipe_sampler_view **); void softpipe_set_viewport_state( struct pipe_context *, const struct pipe_viewport_state * ); diff --git a/src/gallium/drivers/softpipe/sp_state_sampler.c b/src/gallium/drivers/softpipe/sp_state_sampler.c index ceb4e338f1a..c985b5c3e08 100644 --- a/src/gallium/drivers/softpipe/sp_state_sampler.c +++ b/src/gallium/drivers/softpipe/sp_state_sampler.c @@ -122,8 +122,9 @@ softpipe_bind_vertex_sampler_states(struct pipe_context *pipe, void -softpipe_set_sampler_textures(struct pipe_context *pipe, - unsigned num, struct pipe_texture **texture) +softpipe_set_sampler_views(struct pipe_context *pipe, + unsigned num, + struct pipe_sampler_view **views) { struct softpipe_context *softpipe = softpipe_context(pipe); uint i; @@ -131,51 +132,53 @@ softpipe_set_sampler_textures(struct pipe_context *pipe, assert(num <= PIPE_MAX_SAMPLERS); /* Check for no-op */ - if (num == softpipe->num_textures && - !memcmp(softpipe->texture, texture, num * sizeof(struct pipe_texture *))) + if (num == softpipe->num_sampler_views && + !memcmp(softpipe->sampler_views, views, num * sizeof(struct pipe_sampler_view *))) return; draw_flush(softpipe->draw); for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { - struct pipe_texture *tex = i < num ? texture[i] : NULL; + struct pipe_sampler_view *view = i < num ? views[i] : NULL; + struct pipe_texture *texture = view ? view->texture : NULL; - pipe_texture_reference(&softpipe->texture[i], tex); - sp_tex_tile_cache_set_texture(softpipe->tex_cache[i], tex); + pipe_sampler_view_reference(&softpipe->sampler_views[i], view); + sp_tex_tile_cache_set_texture(softpipe->tex_cache[i], texture); } - softpipe->num_textures = num; + softpipe->num_sampler_views = num; softpipe->dirty |= SP_NEW_TEXTURE; } void -softpipe_set_vertex_sampler_textures(struct pipe_context *pipe, - unsigned num_textures, - struct pipe_texture **textures) +softpipe_set_vertex_sampler_views(struct pipe_context *pipe, + unsigned num, + struct pipe_sampler_view **views) { struct softpipe_context *softpipe = softpipe_context(pipe); uint i; - assert(num_textures <= PIPE_MAX_VERTEX_SAMPLERS); + assert(num <= PIPE_MAX_VERTEX_SAMPLERS); /* Check for no-op */ - if (num_textures == softpipe->num_vertex_textures && - !memcmp(softpipe->vertex_textures, textures, num_textures * sizeof(struct pipe_texture *))) { + if (num == softpipe->num_vertex_sampler_views && + !memcmp(softpipe->vertex_sampler_views, views, num * sizeof(struct pipe_sampler_view *))) { return; } draw_flush(softpipe->draw); for (i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; i++) { - struct pipe_texture *tex = i < num_textures ? textures[i] : NULL; + struct pipe_sampler_view *view = i < num ? views[i] : NULL; + struct pipe_texture *texture = view ? view->texture : NULL; - pipe_texture_reference(&softpipe->vertex_textures[i], tex); - sp_tex_tile_cache_set_texture(softpipe->vertex_tex_cache[i], tex); + pipe_sampler_view_reference(&softpipe->vertex_sampler_views[i], view); + sp_tex_tile_cache_set_texture(softpipe->vertex_tex_cache[i], texture); } - softpipe->num_vertex_textures = num_textures; + softpipe->num_vertex_sampler_views = num; softpipe->dirty |= SP_NEW_TEXTURE; } @@ -245,29 +248,41 @@ softpipe_reset_sampler_varients(struct softpipe_context *softpipe) */ for (i = 0; i <= softpipe->vs->max_sampler; i++) { if (softpipe->vertex_samplers[i]) { + struct pipe_texture *texture = NULL; + + if (softpipe->vertex_sampler_views[i]) { + texture = softpipe->vertex_sampler_views[i]->texture; + } + softpipe->tgsi.vert_samplers_list[i] = get_sampler_varient( i, - sp_sampler(softpipe->vertex_samplers[i]), - softpipe->vertex_textures[i], + sp_sampler(softpipe->vertex_samplers[i]), + texture, TGSI_PROCESSOR_VERTEX ); sp_sampler_varient_bind_texture( softpipe->tgsi.vert_samplers_list[i], - softpipe->vertex_tex_cache[i], - softpipe->vertex_textures[i] ); + softpipe->vertex_tex_cache[i], + texture ); } } for (i = 0; i <= softpipe->fs->info.file_max[TGSI_FILE_SAMPLER]; i++) { if (softpipe->sampler[i]) { + struct pipe_texture *texture = NULL; + + if (softpipe->sampler_views[i]) { + texture = softpipe->sampler_views[i]->texture; + } + softpipe->tgsi.frag_samplers_list[i] = get_sampler_varient( i, sp_sampler(softpipe->sampler[i]), - softpipe->texture[i], + texture, TGSI_PROCESSOR_FRAGMENT ); sp_sampler_varient_bind_texture( softpipe->tgsi.frag_samplers_list[i], softpipe->tex_cache[i], - softpipe->texture[i] ); + texture ); } } } diff --git a/src/gallium/drivers/svga/svga_context.h b/src/gallium/drivers/svga/svga_context.h index 03302e2a6ec..b1022c3c996 100644 --- a/src/gallium/drivers/svga/svga_context.h +++ b/src/gallium/drivers/svga/svga_context.h @@ -179,7 +179,7 @@ struct svga_state const struct svga_rasterizer_state *rast; const struct svga_sampler_state *sampler[PIPE_MAX_SAMPLERS]; - struct pipe_texture *texture[PIPE_MAX_SAMPLERS]; /* or texture ID's? */ + struct pipe_sampler_view *sampler_views[PIPE_MAX_SAMPLERS]; /* or texture ID's? */ struct svga_fragment_shader *fs; struct svga_vertex_shader *vs; @@ -203,7 +203,7 @@ struct svga_state struct pipe_viewport_state viewport; unsigned num_samplers; - unsigned num_textures; + unsigned num_sampler_views; unsigned num_vertex_elements; unsigned num_vertex_buffers; unsigned reduced_prim; diff --git a/src/gallium/drivers/svga/svga_pipe_sampler.c b/src/gallium/drivers/svga/svga_pipe_sampler.c index 224c4f4c183..a2dfa4557df 100644 --- a/src/gallium/drivers/svga/svga_pipe_sampler.c +++ b/src/gallium/drivers/svga/svga_pipe_sampler.c @@ -176,9 +176,9 @@ static void svga_delete_sampler_state(struct pipe_context *pipe, } -static void svga_set_sampler_textures(struct pipe_context *pipe, - unsigned num, - struct pipe_texture **texture) +static void svga_set_sampler_views(struct pipe_context *pipe, + unsigned num, + struct pipe_sampler_view **views) { struct svga_context *svga = svga_context(pipe); unsigned flag_1d = 0; @@ -188,31 +188,31 @@ static void svga_set_sampler_textures(struct pipe_context *pipe, assert(num <= PIPE_MAX_SAMPLERS); /* Check for no-op */ - if (num == svga->curr.num_textures && - !memcmp(svga->curr.texture, texture, num * sizeof(struct pipe_texture *))) { + if (num == svga->curr.num_sampler_views && + !memcmp(svga->curr.sampler_views, views, num * sizeof(struct pipe_sampler_view *))) { if (0) debug_printf("texture noop\n"); return; } for (i = 0; i < num; i++) { - pipe_texture_reference(&svga->curr.texture[i], - texture[i]); + pipe_sampler_view_reference(&svga->curr.sampler_views[i], + views[i]); - if (!texture[i]) + if (!views[i]) continue; - if (texture[i]->format == PIPE_FORMAT_A8R8G8B8_SRGB) + if (views[i]->texture->format == PIPE_FORMAT_A8R8G8B8_SRGB) flag_srgb |= 1 << i; - if (texture[i]->target == PIPE_TEXTURE_1D) + if (views[i]->texture->target == PIPE_TEXTURE_1D) flag_1d |= 1 << i; } - for (i = num; i < svga->curr.num_textures; i++) - pipe_texture_reference(&svga->curr.texture[i], - NULL); + for (i = num; i < svga->curr.num_sampler_views; i++) + pipe_sampler_view_reference(&svga->curr.sampler_views[i], + NULL); - svga->curr.num_textures = num; + svga->curr.num_sampler_views = num; svga->dirty |= SVGA_NEW_TEXTURE_BINDING; if (flag_srgb != svga->curr.tex_flags.flag_srgb || @@ -231,7 +231,7 @@ void svga_init_sampler_functions( struct svga_context *svga ) svga->pipe.create_sampler_state = svga_create_sampler_state; svga->pipe.bind_fragment_sampler_states = svga_bind_sampler_states; svga->pipe.delete_sampler_state = svga_delete_sampler_state; - svga->pipe.set_fragment_sampler_textures = svga_set_sampler_textures; + svga->pipe.set_fragment_sampler_views = svga_set_sampler_views; } diff --git a/src/gallium/drivers/svga/svga_state_constants.c b/src/gallium/drivers/svga/svga_state_constants.c index bb92f818eae..493f78a9908 100644 --- a/src/gallium/drivers/svga/svga_state_constants.c +++ b/src/gallium/drivers/svga/svga_state_constants.c @@ -137,7 +137,7 @@ static int emit_fs_consts( struct svga_context *svga, for (i = 0; i < key->num_textures; i++) { if (key->tex[i].unnormalized) { - struct pipe_texture *tex = svga->curr.texture[i]; + struct pipe_texture *tex = svga->curr.sampler_views[i]->texture; float data[4]; data[0] = 1.0 / (float)tex->width0; diff --git a/src/gallium/drivers/svga/svga_state_fs.c b/src/gallium/drivers/svga/svga_state_fs.c index 2973444d0ab..1310fd9825f 100644 --- a/src/gallium/drivers/svga/svga_state_fs.c +++ b/src/gallium/drivers/svga/svga_state_fs.c @@ -158,10 +158,11 @@ static int make_fs_key( const struct svga_context *svga, * * SVGA_NEW_TEXTURE_BINDING | SVGA_NEW_SAMPLER */ - for (i = 0; i < svga->curr.num_textures; i++) { - if (svga->curr.texture[i]) { + for (i = 0; i < svga->curr.num_sampler_views; i++) { + if (svga->curr.sampler_views[i]) { assert(svga->curr.sampler[i]); - key->tex[i].texture_target = svga->curr.texture[i]->target; + assert(svga->curr.sampler_views[i]->texture); + key->tex[i].texture_target = svga->curr.sampler_views[i]->texture->target; if (!svga->curr.sampler[i]->normalized_coords) { key->tex[i].width_height_idx = idx++; key->tex[i].unnormalized = TRUE; @@ -169,7 +170,7 @@ static int make_fs_key( const struct svga_context *svga, } } } - key->num_textures = svga->curr.num_textures; + key->num_textures = svga->curr.num_sampler_views; idx = 0; for (i = 0; i < svga->curr.num_samplers; ++i) { diff --git a/src/gallium/drivers/svga/svga_state_tss.c b/src/gallium/drivers/svga/svga_state_tss.c index 17b47859781..c08ec7c2e8c 100644 --- a/src/gallium/drivers/svga/svga_state_tss.c +++ b/src/gallium/drivers/svga/svga_state_tss.c @@ -37,14 +37,14 @@ void svga_cleanup_tss_binding(struct svga_context *svga) { int i; - unsigned count = MAX2( svga->curr.num_textures, + unsigned count = MAX2( svga->curr.num_sampler_views, svga->state.hw_draw.num_views ); for (i = 0; i < count; i++) { struct svga_hw_view_state *view = &svga->state.hw_draw.views[i]; svga_sampler_view_reference(&view->v, NULL); - pipe_texture_reference( &svga->curr.texture[i], NULL ); + pipe_sampler_view_reference( &svga->curr.sampler_views[i], NULL ); pipe_texture_reference( &view->texture, NULL ); view->dirty = 1; @@ -57,7 +57,7 @@ update_tss_binding(struct svga_context *svga, unsigned dirty ) { unsigned i; - unsigned count = MAX2( svga->curr.num_textures, + unsigned count = MAX2( svga->curr.num_sampler_views, svga->state.hw_draw.num_views ); unsigned min_lod; unsigned max_lod; @@ -77,30 +77,32 @@ update_tss_binding(struct svga_context *svga, for (i = 0; i < count; i++) { const struct svga_sampler_state *s = svga->curr.sampler[i]; struct svga_hw_view_state *view = &svga->state.hw_draw.views[i]; + struct pipe_texture *texture = NULL; /* get min max lod */ - if (svga->curr.texture[i]) { + if (svga->curr.sampler_views[i]) { min_lod = MAX2(s->view_min_lod, 0); - max_lod = MIN2(s->view_max_lod, svga->curr.texture[i]->last_level); + max_lod = MIN2(s->view_max_lod, svga->curr.sampler_views[i]->texture->last_level); + texture = svga->curr.sampler_views[i]->texture; } else { min_lod = 0; max_lod = 0; } - if (view->texture != svga->curr.texture[i] || + if (view->texture != texture || view->min_lod != min_lod || view->max_lod != max_lod) { svga_sampler_view_reference(&view->v, NULL); - pipe_texture_reference( &view->texture, svga->curr.texture[i] ); + pipe_texture_reference( &view->texture, texture ); view->dirty = TRUE; view->min_lod = min_lod; view->max_lod = max_lod; - if (svga->curr.texture[i]) + if (texture) view->v = svga_get_tex_sampler_view(&svga->pipe, - svga->curr.texture[i], + texture, min_lod, max_lod); } @@ -115,7 +117,7 @@ update_tss_binding(struct svga_context *svga, } } - svga->state.hw_draw.num_views = svga->curr.num_textures; + svga->state.hw_draw.num_views = svga->curr.num_sampler_views; if (queue.bind_count) { SVGA3dTextureState *ts; diff --git a/src/gallium/drivers/trace/tr_context.c b/src/gallium/drivers/trace/tr_context.c index df40fbade6c..6293dd79acf 100644 --- a/src/gallium/drivers/trace/tr_context.c +++ b/src/gallium/drivers/trace/tr_context.c @@ -112,7 +112,7 @@ trace_context_draw_block(struct trace_context *tr_ctx, int flag) (void *) tr_ctx->draw_rule.fs, (void *) tr_ctx->curr.fs, (void *) tr_ctx->draw_rule.vs, (void *) tr_ctx->curr.vs, (void *) tr_ctx->draw_rule.surf, 0, - (void *) tr_ctx->draw_rule.tex, 0); + (void *) tr_ctx->draw_rule.sampler_view, 0); if (tr_ctx->draw_rule.fs && tr_ctx->draw_rule.fs == tr_ctx->curr.fs) block = TRUE; @@ -126,12 +126,12 @@ trace_context_draw_block(struct trace_context *tr_ctx, int flag) for (k = 0; k < tr_ctx->curr.nr_cbufs; k++) if (tr_ctx->draw_rule.surf == tr_ctx->curr.cbufs[k]) block = TRUE; - if (tr_ctx->draw_rule.tex) { - for (k = 0; k < tr_ctx->curr.num_texs; k++) - if (tr_ctx->draw_rule.tex == tr_ctx->curr.tex[k]) + if (tr_ctx->draw_rule.sampler_view) { + for (k = 0; k < tr_ctx->curr.num_sampler_views; k++) + if (tr_ctx->draw_rule.sampler_view == tr_ctx->curr.sampler_views[k]) block = TRUE; - for (k = 0; k < tr_ctx->curr.num_vert_texs; k++) { - if (tr_ctx->draw_rule.tex == tr_ctx->curr.vert_tex[k]) { + for (k = 0; k < tr_ctx->curr.num_vert_sampler_views; k++) { + if (tr_ctx->draw_rule.sampler_view == tr_ctx->curr.vert_sampler_views[k]) { block = TRUE; } } @@ -950,62 +950,62 @@ trace_context_set_viewport_state(struct pipe_context *_pipe, static INLINE void -trace_context_set_fragment_sampler_textures(struct pipe_context *_pipe, - unsigned num_textures, - struct pipe_texture **textures) +trace_context_set_fragment_sampler_views(struct pipe_context *_pipe, + unsigned num, + struct pipe_sampler_view **views) { struct trace_context *tr_ctx = trace_context(_pipe); - struct trace_texture *tr_tex; + struct trace_sampler_view *tr_view; struct pipe_context *pipe = tr_ctx->pipe; - struct pipe_texture *unwrapped_textures[PIPE_MAX_SAMPLERS]; + struct pipe_sampler_view *unwrapped_views[PIPE_MAX_SAMPLERS]; unsigned i; - tr_ctx->curr.num_texs = num_textures; - for(i = 0; i < num_textures; ++i) { - tr_tex = trace_texture(textures[i]); - tr_ctx->curr.tex[i] = tr_tex; - unwrapped_textures[i] = tr_tex ? tr_tex->texture : NULL; + tr_ctx->curr.num_sampler_views = num; + for(i = 0; i < num; ++i) { + tr_view = trace_sampler_view(views[i]); + tr_ctx->curr.sampler_views[i] = tr_view; + unwrapped_views[i] = tr_view ? tr_view->sampler_view : NULL; } - textures = unwrapped_textures; + views = unwrapped_views; - trace_dump_call_begin("pipe_context", "set_fragment_sampler_textures"); + trace_dump_call_begin("pipe_context", "set_fragment_sampler_views"); trace_dump_arg(ptr, pipe); - trace_dump_arg(uint, num_textures); - trace_dump_arg_array(ptr, textures, num_textures); + trace_dump_arg(uint, num); + trace_dump_arg_array(ptr, views, num); - pipe->set_fragment_sampler_textures(pipe, num_textures, textures); + pipe->set_fragment_sampler_views(pipe, num, views); trace_dump_call_end(); } static INLINE void -trace_context_set_vertex_sampler_textures(struct pipe_context *_pipe, - unsigned num_textures, - struct pipe_texture **textures) +trace_context_set_vertex_sampler_views(struct pipe_context *_pipe, + unsigned num, + struct pipe_sampler_view **views) { struct trace_context *tr_ctx = trace_context(_pipe); - struct trace_texture *tr_tex; + struct trace_sampler_view *tr_view; struct pipe_context *pipe = tr_ctx->pipe; - struct pipe_texture *unwrapped_textures[PIPE_MAX_VERTEX_SAMPLERS]; + struct pipe_sampler_view *unwrapped_views[PIPE_MAX_VERTEX_SAMPLERS]; unsigned i; - tr_ctx->curr.num_vert_texs = num_textures; - for(i = 0; i < num_textures; ++i) { - tr_tex = trace_texture(textures[i]); - tr_ctx->curr.vert_tex[i] = tr_tex; - unwrapped_textures[i] = tr_tex ? tr_tex->texture : NULL; + tr_ctx->curr.num_vert_sampler_views = num; + for(i = 0; i < num; ++i) { + tr_view = trace_sampler_view(views[i]); + tr_ctx->curr.vert_sampler_views[i] = tr_view; + unwrapped_views[i] = tr_view ? tr_view->sampler_view : NULL; } - textures = unwrapped_textures; + views = unwrapped_views; - trace_dump_call_begin("pipe_context", "set_vertex_sampler_textures"); + trace_dump_call_begin("pipe_context", "set_vertex_sampler_views"); trace_dump_arg(ptr, pipe); - trace_dump_arg(uint, num_textures); - trace_dump_arg_array(ptr, textures, num_textures); + trace_dump_arg(uint, num); + trace_dump_arg_array(ptr, views, num); - pipe->set_vertex_sampler_textures(pipe, num_textures, textures); + pipe->set_vertex_sampler_views(pipe, num, views); trace_dump_call_end(); } @@ -1311,8 +1311,8 @@ trace_context_create(struct trace_screen *tr_scr, tr_ctx->base.set_polygon_stipple = trace_context_set_polygon_stipple; tr_ctx->base.set_scissor_state = trace_context_set_scissor_state; tr_ctx->base.set_viewport_state = trace_context_set_viewport_state; - tr_ctx->base.set_fragment_sampler_textures = trace_context_set_fragment_sampler_textures; - tr_ctx->base.set_vertex_sampler_textures = trace_context_set_vertex_sampler_textures; + tr_ctx->base.set_fragment_sampler_views = trace_context_set_fragment_sampler_views; + tr_ctx->base.set_vertex_sampler_views = trace_context_set_vertex_sampler_views; tr_ctx->base.set_vertex_buffers = trace_context_set_vertex_buffers; tr_ctx->base.set_vertex_elements = trace_context_set_vertex_elements; if (pipe->surface_copy) diff --git a/src/gallium/drivers/trace/tr_context.h b/src/gallium/drivers/trace/tr_context.h index 14284232485..feec9b6bbf3 100644 --- a/src/gallium/drivers/trace/tr_context.h +++ b/src/gallium/drivers/trace/tr_context.h @@ -53,11 +53,11 @@ struct trace_context struct trace_shader *fs; struct trace_shader *vs; - struct trace_texture *tex[PIPE_MAX_SAMPLERS]; - unsigned num_texs; + struct trace_sampler_view *sampler_views[PIPE_MAX_SAMPLERS]; + unsigned num_sampler_views; - struct trace_texture *vert_tex[PIPE_MAX_VERTEX_SAMPLERS]; - unsigned num_vert_texs; + struct trace_sampler_view *vert_sampler_views[PIPE_MAX_VERTEX_SAMPLERS]; + unsigned num_vert_sampler_views; unsigned nr_cbufs; struct trace_texture *cbufs[PIPE_MAX_COLOR_BUFS]; @@ -68,7 +68,7 @@ struct trace_context struct trace_shader *fs; struct trace_shader *vs; - struct trace_texture *tex; + struct trace_sampler_view *sampler_view; struct trace_texture *surf; int blocker; diff --git a/src/gallium/drivers/trace/tr_rbug.c b/src/gallium/drivers/trace/tr_rbug.c index a43adac6940..07f9de253ec 100644 --- a/src/gallium/drivers/trace/tr_rbug.c +++ b/src/gallium/drivers/trace/tr_rbug.c @@ -313,12 +313,12 @@ trace_rbug_context_info(struct trace_rbug *tr_rbug, struct rbug_header *header, for (i = 0; i < tr_ctx->curr.nr_cbufs; i++) cbufs[i] = VOID2U64(tr_ctx->curr.cbufs[i]); - for (i = 0; i < tr_ctx->curr.num_texs; i++) - texs[i] = VOID2U64(tr_ctx->curr.tex[i]); + for (i = 0; i < tr_ctx->curr.num_sampler_views; i++) + texs[i] = VOID2U64(tr_ctx->curr.sampler_views[i]); rbug_send_context_info_reply(tr_rbug->con, serial, VOID2U64(tr_ctx->curr.vs), VOID2U64(tr_ctx->curr.fs), - texs, tr_ctx->curr.num_texs, + texs, tr_ctx->curr.num_sampler_views, cbufs, tr_ctx->curr.nr_cbufs, VOID2U64(tr_ctx->curr.zsbuf), tr_ctx->draw_blocker, tr_ctx->draw_blocked, NULL); @@ -444,7 +444,7 @@ trace_rbug_context_draw_rule(struct trace_rbug *tr_rbug, struct rbug_header *hea pipe_mutex_lock(tr_ctx->draw_mutex); tr_ctx->draw_rule.vs = U642VOID(rule->vertex); tr_ctx->draw_rule.fs = U642VOID(rule->fragment); - tr_ctx->draw_rule.tex = U642VOID(rule->texture); + tr_ctx->draw_rule.sampler_view = U642VOID(rule->texture); tr_ctx->draw_rule.surf = U642VOID(rule->surface); tr_ctx->draw_rule.blocker = rule->block; tr_ctx->draw_blocker |= RBUG_BLOCK_RULE; diff --git a/src/gallium/drivers/trace/tr_texture.h b/src/gallium/drivers/trace/tr_texture.h index 395e523e73a..a2ca3c21dbf 100644 --- a/src/gallium/drivers/trace/tr_texture.h +++ b/src/gallium/drivers/trace/tr_texture.h @@ -55,6 +55,16 @@ struct trace_surface }; +struct trace_sampler_view +{ + struct pipe_sampler_view base; + + struct pipe_sampler_view *sampler_view; + + struct tr_list list; +}; + + struct trace_transfer { struct pipe_transfer base; @@ -87,6 +97,15 @@ trace_surface(struct pipe_surface *surface) } +static INLINE struct trace_sampler_view * +trace_sampler_view(struct pipe_sampler_view *sampler_view) +{ + if (!sampler_view) + return NULL; + return (struct trace_sampler_view *)sampler_view; +} + + static INLINE struct trace_transfer * trace_transfer(struct pipe_transfer *transfer) { diff --git a/src/gallium/include/pipe/p_context.h b/src/gallium/include/pipe/p_context.h index f82b77903e9..0c265484e9a 100644 --- a/src/gallium/include/pipe/p_context.h +++ b/src/gallium/include/pipe/p_context.h @@ -208,13 +208,13 @@ struct pipe_context { void (*set_viewport_state)( struct pipe_context *, const struct pipe_viewport_state * ); - void (*set_fragment_sampler_textures)(struct pipe_context *, - unsigned num_textures, - struct pipe_texture **); + void (*set_fragment_sampler_views)(struct pipe_context *, + unsigned num_views, + struct pipe_sampler_view **); - void (*set_vertex_sampler_textures)(struct pipe_context *, - unsigned num_textures, - struct pipe_texture **); + void (*set_vertex_sampler_views)(struct pipe_context *, + unsigned num_views, + struct pipe_sampler_view **); void (*set_vertex_buffers)( struct pipe_context *, unsigned num_buffers, @@ -303,6 +303,16 @@ struct pipe_context { */ unsigned int (*is_buffer_referenced)(struct pipe_context *pipe, struct pipe_buffer *buf); + + /** + * Create a view on a texture to be used by a shader stage. + */ + struct pipe_sampler_view * (*create_sampler_view)(struct pipe_context *ctx, + struct pipe_texture *texture, + const struct pipe_sampler_view *templat); + + void (*sampler_view_destroy)(struct pipe_context *ctx, + struct pipe_sampler_view *view); }; diff --git a/src/gallium/include/pipe/p_defines.h b/src/gallium/include/pipe/p_defines.h index 5cebd43ace2..73c70b2fe40 100644 --- a/src/gallium/include/pipe/p_defines.h +++ b/src/gallium/include/pipe/p_defines.h @@ -368,6 +368,17 @@ enum pipe_transfer_usage { #define PIPE_SPRITE_COORD_LOWER_LEFT 1 +/** + * Texture swizzles + */ +#define PIPE_SWIZZLE_RED 0 +#define PIPE_SWIZZLE_GREEN 1 +#define PIPE_SWIZZLE_BLUE 2 +#define PIPE_SWIZZLE_ALPHA 3 +#define PIPE_SWIZZLE_ZERO 4 +#define PIPE_SWIZZLE_ONE 5 + + /** * Implementation capabilities/limits which are queried through * pipe_screen::get_param() and pipe_screen::get_paramf(). diff --git a/src/gallium/include/pipe/p_state.h b/src/gallium/include/pipe/p_state.h index 5ac5c878135..603848b11f4 100644 --- a/src/gallium/include/pipe/p_state.h +++ b/src/gallium/include/pipe/p_state.h @@ -309,6 +309,24 @@ struct pipe_surface }; +/** + * A view into a texture that can be bound to a shader stage. + */ +struct pipe_sampler_view +{ + struct pipe_reference reference; + enum pipe_format format; /**< typed PIPE_FORMAT_x */ + struct pipe_texture *texture; /**< texture into which this is a view */ + struct pipe_context *context; /**< context this view belongs to */ + unsigned first_level:8; /**< first mipmap level */ + unsigned num_levels:8; /**< number of mipamp levels */ + unsigned swizzle_r:3; /**< PIPE_SWIZZLE_x for red component */ + unsigned swizzle_g:3; /**< PIPE_SWIZZLE_x for green component */ + unsigned swizzle_b:3; /**< PIPE_SWIZZLE_x for blue component */ + unsigned swizzle_a:3; /**< PIPE_SWIZZLE_x for alpha component */ +}; + + /** * Transfer object. For data transfer to/from a texture. */ diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 36c0a2b0e1e..4c02e01e5b1 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -586,10 +586,10 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, struct pipe_texture *textures[2]; textures[0] = pt; textures[1] = st->pixel_xfer.pixelmap_texture; - pipe->set_fragment_sampler_textures(pipe, 2, textures); + cso_set_sampler_textures(cso, 2, textures); } else { - pipe->set_fragment_sampler_textures(pipe, 1, &pt); + cso_set_sampler_textures(cso, 1, &pt); } /* Compute window coords (y=0=bottom) with pixel zoom. -- cgit v1.2.3 From 9187b25a15145933ca014556e109b17ecf38ece4 Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Tue, 23 Feb 2010 16:09:10 +0100 Subject: failover: Fix after sampler view changes. --- src/gallium/drivers/failover/fo_context.h | 18 +++++-- src/gallium/drivers/failover/fo_state.c | 80 ++++++++++++++++++++-------- src/gallium/drivers/failover/fo_state_emit.c | 22 ++++++-- 3 files changed, 89 insertions(+), 31 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/failover/fo_context.h b/src/gallium/drivers/failover/fo_context.h index ae3b0b0c189..53e1a02bcba 100644 --- a/src/gallium/drivers/failover/fo_context.h +++ b/src/gallium/drivers/failover/fo_context.h @@ -47,7 +47,7 @@ #define FO_NEW_ALPHA_TEST 0x100 #define FO_NEW_DEPTH_STENCIL 0x200 #define FO_NEW_SAMPLER 0x400 -#define FO_NEW_TEXTURE 0x800 +#define FO_NEW_SAMPLER_VIEW 0x800 #define FO_NEW_VERTEX 0x2000 #define FO_NEW_VERTEX_SHADER 0x4000 #define FO_NEW_BLEND_COLOR 0x8000 @@ -65,6 +65,13 @@ struct fo_state { void *sw_state; void *hw_state; }; + +struct fo_sampler_view { + struct pipe_sampler_view base; + struct pipe_sampler_view *sw; + struct pipe_sampler_view *hw; +}; + struct failover_context { struct pipe_context pipe; /**< base class */ @@ -85,8 +92,6 @@ struct failover_context { struct pipe_framebuffer_state framebuffer; struct pipe_poly_stipple poly_stipple; struct pipe_scissor_state scissor; - struct pipe_sampler_view *sampler_views[PIPE_MAX_SAMPLERS]; - struct pipe_sampler_view *vertex_sampler_views[PIPE_MAX_VERTEX_SAMPLERS]; struct pipe_viewport_state viewport; struct pipe_vertex_buffer vertex_buffers[PIPE_MAX_ATTRIBS]; struct pipe_vertex_element vertex_elements[PIPE_MAX_ATTRIBS]; @@ -99,12 +104,15 @@ struct failover_context { void *sw_vertex_sampler_state[PIPE_MAX_VERTEX_SAMPLERS]; void *hw_vertex_sampler_state[PIPE_MAX_VERTEX_SAMPLERS]; + struct fo_sampler_view *fragment_sampler_views[PIPE_MAX_SAMPLERS]; + struct fo_sampler_view *vertex_sampler_views[PIPE_MAX_VERTEX_SAMPLERS]; + unsigned num_fragment_sampler_views; + unsigned num_vertex_sampler_views; + unsigned dirty; unsigned num_samplers; unsigned num_vertex_samplers; - unsigned num_sampler_views; - unsigned num_vertex_sampler_views; unsigned mode; struct pipe_context *hw; diff --git a/src/gallium/drivers/failover/fo_state.c b/src/gallium/drivers/failover/fo_state.c index b16f2197f11..d0c2f1474ae 100644 --- a/src/gallium/drivers/failover/fo_state.c +++ b/src/gallium/drivers/failover/fo_state.c @@ -404,30 +404,66 @@ failover_delete_sampler_state(struct pipe_context *pipe, void *sampler) } +static struct pipe_sampler_view * +failover_create_sampler_view(struct pipe_context *pipe, + struct pipe_texture *texture, + const struct pipe_sampler_view *templ) +{ + struct fo_sampler_view *view = malloc(sizeof(struct fo_sampler_view)); + struct failover_context *failover = failover_context(pipe); + + view->sw = failover->sw->create_sampler_view(failover->sw, texture, templ); + view->hw = failover->hw->create_sampler_view(failover->hw, texture, templ); + + view->base = *templ; + view->base.reference.count = 1; + view->base.texture = NULL; + pipe_texture_reference(&view->base.texture, texture); + view->base.context = pipe; + + return &view->base; +} + +static void +failover_sampler_view_destroy(struct pipe_context *pipe, + struct pipe_sampler_view *view) +{ + struct fo_sampler_view *fo_view = (struct fo_sampler_view *)view; + struct failover_context *failover = failover_context(pipe); + + failover->sw->sampler_view_destroy(failover->sw, fo_view->sw); + failover->hw->sampler_view_destroy(failover->hw, fo_view->hw); + + pipe_texture_reference(&fo_view->base.texture, NULL); + free(fo_view); +} + static void failover_set_fragment_sampler_views(struct pipe_context *pipe, unsigned num, struct pipe_sampler_view **views) { struct failover_context *failover = failover_context(pipe); + struct pipe_sampler_view *hw_views[PIPE_MAX_SAMPLERS]; uint i; assert(num <= PIPE_MAX_SAMPLERS); /* Check for no-op */ - if (num == failover->num_sampler_views && - !memcmp(failover->sampler_views, views, num * sizeof(struct pipe_sampler_view *))) + if (num == failover->num_fragment_sampler_views && + !memcmp(failover->fragment_sampler_views, views, num * sizeof(struct pipe_sampler_view *))) return; - for (i = 0; i < num; i++) - pipe_sampler_view_reference((struct pipe_sampler_view **) &failover->sampler_views[i], - views[i]); - for (i = num; i < failover->num_sampler_views; i++) - pipe_sampler_view_reference((struct pipe_sampler_view **) &failover->sampler_views[i], - NULL); - failover->dirty |= FO_NEW_TEXTURE; - failover->num_sampler_views = num; - failover->sw->set_fragment_sampler_views( failover->sw, num, views ); - failover->hw->set_fragment_sampler_views( failover->hw, num, views ); + for (i = 0; i < num; i++) { + struct fo_sampler_view *fo_view = (struct fo_sampler_view *)views[i]; + + pipe_sampler_view_reference((struct pipe_sampler_view **)&failover->fragment_sampler_views[i], views[i]); + hw_views[i] = fo_view->hw; + } + for (i = num; i < failover->num_fragment_sampler_views; i++) + pipe_sampler_view_reference((struct pipe_sampler_view **)&failover->fragment_sampler_views[i], NULL); + failover->dirty |= FO_NEW_SAMPLER_VIEW; + failover->num_fragment_sampler_views = num; + failover->hw->set_fragment_sampler_views(failover->hw, num, hw_views); } @@ -437,6 +473,7 @@ failover_set_vertex_sampler_views(struct pipe_context *pipe, struct pipe_sampler_view **views) { struct failover_context *failover = failover_context(pipe); + struct pipe_sampler_view *hw_views[PIPE_MAX_VERTEX_SAMPLERS]; uint i; assert(num <= PIPE_MAX_VERTEX_SAMPLERS); @@ -447,17 +484,16 @@ failover_set_vertex_sampler_views(struct pipe_context *pipe, return; } for (i = 0; i < num; i++) { - pipe_sampler_view_reference((struct pipe_sampler_view **)&failover->vertex_sampler_views[i], - views[i]); - } - for (i = num; i < failover->num_vertex_sampler_views; i++) { - pipe_sampler_view_reference((struct pipe_sampler_view **)&failover->vertex_sampler_views[i], - NULL); + struct fo_sampler_view *fo_view = (struct fo_sampler_view *)views[i]; + + pipe_sampler_view_reference((struct pipe_sampler_view **)&failover->vertex_sampler_views[i], views[i]); + hw_views[i] = fo_view->hw; } - failover->dirty |= FO_NEW_TEXTURE; + for (i = num; i < failover->num_vertex_sampler_views; i++) + pipe_sampler_view_reference((struct pipe_sampler_view **)&failover->vertex_sampler_views[i], NULL); + failover->dirty |= FO_NEW_SAMPLER_VIEW; failover->num_vertex_sampler_views = num; - failover->sw->set_vertex_sampler_views(failover->sw, num, views); - failover->hw->set_vertex_sampler_views(failover->hw, num, views); + failover->hw->set_vertex_sampler_views(failover->hw, num, hw_views); } @@ -556,4 +592,6 @@ failover_init_state_functions( struct failover_context *failover ) failover->pipe.set_vertex_buffers = failover_set_vertex_buffers; failover->pipe.set_vertex_elements = failover_set_vertex_elements; failover->pipe.set_constant_buffer = failover_set_constant_buffer; + failover->pipe.create_sampler_view = failover_create_sampler_view; + failover->pipe.sampler_view_destroy = failover_sampler_view_destroy; } diff --git a/src/gallium/drivers/failover/fo_state_emit.c b/src/gallium/drivers/failover/fo_state_emit.c index 1c37668027f..171151e1ee2 100644 --- a/src/gallium/drivers/failover/fo_state_emit.c +++ b/src/gallium/drivers/failover/fo_state_emit.c @@ -102,12 +102,24 @@ failover_state_emit( struct failover_context *failover ) failover->sw_vertex_sampler_state); } - if (failover->dirty & FO_NEW_TEXTURE) { - failover->sw->set_fragment_sampler_views( failover->sw, failover->num_sampler_views, - failover->sampler_views ); + if (failover->dirty & FO_NEW_SAMPLER_VIEW) { + struct pipe_sampler_view *fragment_views[PIPE_MAX_SAMPLERS]; + struct pipe_sampler_view *vertex_views[PIPE_MAX_VERTEX_SAMPLERS]; + uint i; + + for (i = 0; i < failover->num_fragment_sampler_views; i++) { + fragment_views[i] = failover->fragment_sampler_views[i]->sw; + } + failover->sw->set_fragment_sampler_views(failover->sw, + failover->num_fragment_sampler_views, + fragment_views); + + for (i = 0; i < failover->num_vertex_sampler_views; i++) { + vertex_views[i] = failover->vertex_sampler_views[i]->sw; + } failover->sw->set_vertex_sampler_views(failover->sw, - failover->num_vertex_sampler_views, - failover->vertex_sampler_views); + failover->num_vertex_sampler_views, + vertex_views); } if (failover->dirty & FO_NEW_VERTEX_BUFFER) { -- cgit v1.2.3 From 14a146c4995da5074eb1192a818b7a3dfc3bb438 Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Tue, 23 Feb 2010 16:09:40 +0100 Subject: identity: Fix after sampler view changes. --- src/gallium/drivers/identity/id_context.c | 42 +++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'src/gallium') diff --git a/src/gallium/drivers/identity/id_context.c b/src/gallium/drivers/identity/id_context.c index 2272f4a126a..442d851c135 100644 --- a/src/gallium/drivers/identity/id_context.c +++ b/src/gallium/drivers/identity/id_context.c @@ -685,6 +685,46 @@ identity_is_buffer_referenced(struct pipe_context *_pipe, buffer); } +static struct pipe_sampler_view * +identity_create_sampler_view(struct pipe_context *pipe, + struct pipe_texture *texture, + const struct pipe_sampler_view *templ) +{ + struct identity_context *id_pipe = identity_context(pipe); + struct identity_texture *id_texture = identity_texture(texture); + struct pipe_context *pipe_unwrapped = id_pipe->pipe; + struct pipe_texture *texture_unwrapped = id_texture->texture; + struct identity_sampler_view *view = malloc(sizeof(struct identity_sampler_view)); + + view->sampler_view = pipe_unwrapped->create_sampler_view(pipe_unwrapped, + texture_unwrapped, + templ); + + view->base = *templ; + view->base.reference.count = 1; + view->base.texture = NULL; + pipe_texture_reference(&view->base.texture, texture); + view->base.context = pipe; + + return &view->base; +} + +static void +identity_sampler_view_destroy(struct pipe_context *pipe, + struct pipe_sampler_view *view) +{ + struct identity_context *id_pipe = identity_context(pipe); + struct identity_sampler_view *id_view = identity_sampler_view(view); + struct pipe_context *pipe_unwrapped = id_pipe->pipe; + struct pipe_sampler_view *view_unwrapped = id_view->sampler_view; + + pipe_unwrapped->sampler_view_destroy(pipe_unwrapped, + view_unwrapped); + + pipe_texture_reference(&view->texture, NULL); + free(view); +} + struct pipe_context * identity_context_create(struct pipe_screen *_screen, struct pipe_context *pipe) { @@ -747,6 +787,8 @@ identity_context_create(struct pipe_screen *_screen, struct pipe_context *pipe) id_pipe->base.flush = identity_flush; id_pipe->base.is_texture_referenced = identity_is_texture_referenced; id_pipe->base.is_buffer_referenced = identity_is_buffer_referenced; + id_pipe->base.create_sampler_view = identity_create_sampler_view; + id_pipe->base.sampler_view_destroy = identity_sampler_view_destroy; id_pipe->pipe = pipe; -- cgit v1.2.3 From eb9c9efedf9e0b1fdb000a3d175285764759af2a Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Tue, 23 Feb 2010 16:37:42 +0100 Subject: softpipe: Fix after sampler view changes. --- src/gallium/drivers/softpipe/sp_context.c | 2 ++ src/gallium/drivers/softpipe/sp_state.h | 9 ++++++++ src/gallium/drivers/softpipe/sp_state_sampler.c | 29 +++++++++++++++++++++++++ 3 files changed, 40 insertions(+) (limited to 'src/gallium') diff --git a/src/gallium/drivers/softpipe/sp_context.c b/src/gallium/drivers/softpipe/sp_context.c index 858e118bc66..0c74b490fea 100644 --- a/src/gallium/drivers/softpipe/sp_context.c +++ b/src/gallium/drivers/softpipe/sp_context.c @@ -254,6 +254,8 @@ softpipe_create_context( struct pipe_screen *screen, softpipe->pipe.set_scissor_state = softpipe_set_scissor_state; softpipe->pipe.set_fragment_sampler_views = softpipe_set_sampler_views; softpipe->pipe.set_vertex_sampler_views = softpipe_set_vertex_sampler_views; + softpipe->pipe.create_sampler_view = softpipe_create_sampler_view; + softpipe->pipe.sampler_view_destroy = softpipe_sampler_view_destroy; softpipe->pipe.set_viewport_state = softpipe_set_viewport_state; softpipe->pipe.set_vertex_buffers = softpipe_set_vertex_buffers; diff --git a/src/gallium/drivers/softpipe/sp_state.h b/src/gallium/drivers/softpipe/sp_state.h index ba9bbfe68a4..b37bb951520 100644 --- a/src/gallium/drivers/softpipe/sp_state.h +++ b/src/gallium/drivers/softpipe/sp_state.h @@ -175,6 +175,15 @@ softpipe_set_vertex_sampler_views(struct pipe_context *, unsigned num, struct pipe_sampler_view **); +struct pipe_sampler_view * +softpipe_create_sampler_view(struct pipe_context *pipe, + struct pipe_texture *texture, + const struct pipe_sampler_view *templ); + +void +softpipe_sampler_view_destroy(struct pipe_context *pipe, + struct pipe_sampler_view *view); + void softpipe_set_viewport_state( struct pipe_context *, const struct pipe_viewport_state * ); diff --git a/src/gallium/drivers/softpipe/sp_state_sampler.c b/src/gallium/drivers/softpipe/sp_state_sampler.c index c985b5c3e08..5a92e2223ef 100644 --- a/src/gallium/drivers/softpipe/sp_state_sampler.c +++ b/src/gallium/drivers/softpipe/sp_state_sampler.c @@ -121,6 +121,35 @@ softpipe_bind_vertex_sampler_states(struct pipe_context *pipe, } +struct pipe_sampler_view * +softpipe_create_sampler_view(struct pipe_context *pipe, + struct pipe_texture *texture, + const struct pipe_sampler_view *templ) +{ + struct softpipe_context *softpipe = softpipe_context(pipe); + struct pipe_sampler_view *view = CALLOC_STRUCT(pipe_sampler_view); + + *view = *templ; + view->reference.count = 1; + view->texture = NULL; + pipe_texture_reference(&view->texture, texture); + view->context = pipe; + + return view; +} + + +void +softpipe_sampler_view_destroy(struct pipe_context *pipe, + struct pipe_sampler_view *view) +{ + struct softpipe_context *softpipe = softpipe_context(pipe); + + pipe_texture_reference(&view->texture, NULL); + FREE(view); +} + + void softpipe_set_sampler_views(struct pipe_context *pipe, unsigned num, -- cgit v1.2.3 From ad230a1fb12640ac515096d892b58e2bfdb995e7 Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Tue, 23 Feb 2010 17:03:56 +0100 Subject: svga: Fix after sampler view changes. --- src/gallium/drivers/svga/svga_pipe_sampler.c | 30 ++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/gallium') diff --git a/src/gallium/drivers/svga/svga_pipe_sampler.c b/src/gallium/drivers/svga/svga_pipe_sampler.c index a2dfa4557df..26878177308 100644 --- a/src/gallium/drivers/svga/svga_pipe_sampler.c +++ b/src/gallium/drivers/svga/svga_pipe_sampler.c @@ -176,6 +176,34 @@ static void svga_delete_sampler_state(struct pipe_context *pipe, } +static struct pipe_sampler_view * +svga_create_sampler_view(struct pipe_context *pipe, + struct pipe_texture *texture, + const struct pipe_sampler_view *templ) +{ + struct svga_context *softpipe = svga_context(pipe); + struct pipe_sampler_view *view = CALLOC_STRUCT(pipe_sampler_view); + + *view = *templ; + view->reference.count = 1; + view->texture = NULL; + pipe_texture_reference(&view->texture, texture); + view->context = pipe; + + return view; +} + + +static void +svga_sampler_view_destroy(struct pipe_context *pipe, + struct pipe_sampler_view *view) +{ + struct svga_context *svga = svga_context(pipe); + + pipe_texture_reference(&view->texture, NULL); + FREE(view); +} + static void svga_set_sampler_views(struct pipe_context *pipe, unsigned num, struct pipe_sampler_view **views) @@ -232,6 +260,8 @@ void svga_init_sampler_functions( struct svga_context *svga ) svga->pipe.bind_fragment_sampler_states = svga_bind_sampler_states; svga->pipe.delete_sampler_state = svga_delete_sampler_state; svga->pipe.set_fragment_sampler_views = svga_set_sampler_views; + svga->pipe.create_sampler_view = svga_create_sampler_view; + svga->pipe.sampler_view_destroy = svga_sampler_view_destroy; } -- cgit v1.2.3 From 92b781c2dda9ae5aeec7e32cfc9902057edd0a9d Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Tue, 23 Feb 2010 19:18:27 +0100 Subject: trace: Fix after sampler view changes. --- src/gallium/drivers/trace/tr_context.c | 59 ++++++++++++++++++++++++++++++++++ src/gallium/drivers/trace/tr_texture.h | 2 -- 2 files changed, 59 insertions(+), 2 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/trace/tr_context.c b/src/gallium/drivers/trace/tr_context.c index 6293dd79acf..c84cbd0e521 100644 --- a/src/gallium/drivers/trace/tr_context.c +++ b/src/gallium/drivers/trace/tr_context.c @@ -25,6 +25,7 @@ * **************************************************************************/ +#include "util/u_inlines.h" #include "util/u_memory.h" #include "util/u_simple_list.h" @@ -949,6 +950,62 @@ trace_context_set_viewport_state(struct pipe_context *_pipe, } +static struct pipe_sampler_view * +trace_create_sampler_view(struct pipe_context *_pipe, + struct pipe_texture *_texture, + const struct pipe_sampler_view *templ) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct trace_texture *tr_tex = trace_texture(_texture); + struct pipe_context *pipe = tr_ctx->pipe; + struct pipe_texture *texture = tr_tex->texture; + struct trace_sampler_view *result = CALLOC_STRUCT(trace_sampler_view); + + trace_dump_call_begin("pipe_context", "create_sampler_view"); + + trace_dump_arg(ptr, pipe); + trace_dump_arg(ptr, texture); + trace_dump_arg(ptr, templ); + + result->sampler_view = pipe->create_sampler_view(pipe, texture, templ); + + result->base = *templ; + result->base.reference.count = 1; + result->base.texture = NULL; + pipe_texture_reference(&result->base.texture, _texture); + result->base.context = _pipe; + + trace_dump_ret(ptr, result); + + trace_dump_call_end(); + + return &result->base; +} + + +static void +trace_sampler_view_destroy(struct pipe_context *_pipe, + struct pipe_sampler_view *_view) +{ + struct trace_context *tr_ctx = trace_context(_pipe); + struct trace_sampler_view *tr_view = trace_sampler_view(_view); + struct pipe_context *pipe = tr_ctx->pipe; + struct pipe_sampler_view *view = tr_view->sampler_view; + + trace_dump_call_begin("pipe_context", "sampler_view_destroy"); + + trace_dump_arg(ptr, pipe); + trace_dump_arg(ptr, view); + + pipe->sampler_view_destroy(pipe, view); + + trace_dump_call_end(); + + pipe_texture_reference(&_view->texture, NULL); + FREE(_view); +} + + static INLINE void trace_context_set_fragment_sampler_views(struct pipe_context *_pipe, unsigned num, @@ -1313,6 +1370,8 @@ trace_context_create(struct trace_screen *tr_scr, tr_ctx->base.set_viewport_state = trace_context_set_viewport_state; tr_ctx->base.set_fragment_sampler_views = trace_context_set_fragment_sampler_views; tr_ctx->base.set_vertex_sampler_views = trace_context_set_vertex_sampler_views; + tr_ctx->base.create_sampler_view = trace_create_sampler_view; + tr_ctx->base.sampler_view_destroy = trace_sampler_view_destroy; tr_ctx->base.set_vertex_buffers = trace_context_set_vertex_buffers; tr_ctx->base.set_vertex_elements = trace_context_set_vertex_elements; if (pipe->surface_copy) diff --git a/src/gallium/drivers/trace/tr_texture.h b/src/gallium/drivers/trace/tr_texture.h index a2ca3c21dbf..3a99dcdaece 100644 --- a/src/gallium/drivers/trace/tr_texture.h +++ b/src/gallium/drivers/trace/tr_texture.h @@ -60,8 +60,6 @@ struct trace_sampler_view struct pipe_sampler_view base; struct pipe_sampler_view *sampler_view; - - struct tr_list list; }; -- cgit v1.2.3 From 1f5285f99771243b636deb9ae0a17c54f818fac6 Mon Sep 17 00:00:00 2001 From: michal Date: Thu, 10 Dec 2009 07:52:45 +0100 Subject: i915: Fix for sampler view changes. --- src/gallium/drivers/i915/i915_context.h | 6 +-- src/gallium/drivers/i915/i915_state.c | 54 ++++++++++++++++++++------- src/gallium/drivers/i915/i915_state_derived.c | 4 +- src/gallium/drivers/i915/i915_state_emit.c | 3 +- src/gallium/drivers/i915/i915_state_sampler.c | 18 +++++---- 5 files changed, 59 insertions(+), 26 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/i915/i915_context.h b/src/gallium/drivers/i915/i915_context.h index da769e7b290..cd6dcd59a9f 100644 --- a/src/gallium/drivers/i915/i915_context.h +++ b/src/gallium/drivers/i915/i915_context.h @@ -239,14 +239,14 @@ struct i915_context struct pipe_framebuffer_state framebuffer; struct pipe_poly_stipple poly_stipple; struct pipe_scissor_state scissor; - struct i915_texture *texture[PIPE_MAX_SAMPLERS]; + struct pipe_sampler_view *fragment_sampler_views[PIPE_MAX_SAMPLERS]; struct pipe_viewport_state viewport; struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS]; unsigned dirty; unsigned num_samplers; - unsigned num_textures; + unsigned num_fragment_sampler_views; unsigned num_vertex_elements; unsigned num_vertex_buffers; @@ -276,7 +276,7 @@ struct i915_context #define I915_NEW_ALPHA_TEST 0x100 #define I915_NEW_DEPTH_STENCIL 0x200 #define I915_NEW_SAMPLER 0x400 -#define I915_NEW_TEXTURE 0x800 +#define I915_NEW_SAMPLER_VIEW 0x800 #define I915_NEW_CONSTANTS 0x1000 #define I915_NEW_VBO 0x2000 #define I915_NEW_VS 0x4000 diff --git a/src/gallium/drivers/i915/i915_state.c b/src/gallium/drivers/i915/i915_state.c index 62169918e2b..b38d1b2404a 100644 --- a/src/gallium/drivers/i915/i915_state.c +++ b/src/gallium/drivers/i915/i915_state.c @@ -560,9 +560,9 @@ static void i915_set_constant_buffer(struct pipe_context *pipe, } -static void i915_set_sampler_textures(struct pipe_context *pipe, - unsigned num, - struct pipe_texture **texture) +static void i915_set_fragment_sampler_views(struct pipe_context *pipe, + unsigned num, + struct pipe_sampler_view **views) { struct i915_context *i915 = i915_context(pipe); uint i; @@ -570,27 +570,53 @@ static void i915_set_sampler_textures(struct pipe_context *pipe, assert(num <= PIPE_MAX_SAMPLERS); /* Check for no-op */ - if (num == i915->num_textures && - !memcmp(i915->texture, texture, num * sizeof(struct pipe_texture *))) + if (num == i915->num_fragment_sampler_views && + !memcmp(i915->fragment_sampler_views, views, num * sizeof(struct pipe_sampler_view *))) return; /* Fixes wrong texture in texobj with VBUF */ draw_flush(i915->draw); for (i = 0; i < num; i++) - pipe_texture_reference((struct pipe_texture **) &i915->texture[i], - texture[i]); + pipe_sampler_view_reference(&i915->fragment_sampler_views[i], + views[i]); - for (i = num; i < i915->num_textures; i++) - pipe_texture_reference((struct pipe_texture **) &i915->texture[i], - NULL); + for (i = num; i < i915->num_fragment_sampler_views; i++) + pipe_sampler_view_reference(&i915->fragment_sampler_views[i], + NULL); - i915->num_textures = num; + i915->num_fragment_sampler_views = num; - i915->dirty |= I915_NEW_TEXTURE; + i915->dirty |= I915_NEW_SAMPLER_VIEW; } +static struct pipe_sampler_view * +i915_create_sampler_view(struct pipe_context *pipe, + struct pipe_texture *texture, + const struct pipe_sampler_view *templ) +{ + struct i915_context *i915 = i915_context(pipe); + struct pipe_sampler_view *view = CALLOC_STRUCT(pipe_sampler_view); + + *view = *templ; + view->reference.count = 1; + view->texture = NULL; + pipe_texture_reference(&view->texture, texture); + view->context = pipe; + + return view; +} + + +static void +i915_sampler_view_destroy(struct pipe_context *pipe, + struct pipe_sampler_view *view) +{ + pipe_texture_reference(&view->texture, NULL); + FREE(view); +} + static void i915_set_framebuffer_state(struct pipe_context *pipe, const struct pipe_framebuffer_state *fb) @@ -791,7 +817,9 @@ i915_init_state_functions( struct i915_context *i915 ) i915->base.set_polygon_stipple = i915_set_polygon_stipple; i915->base.set_scissor_state = i915_set_scissor_state; - i915->base.set_fragment_sampler_textures = i915_set_sampler_textures; + i915->base.set_fragment_sampler_views = i915_set_fragment_sampler_views; + i915->base.create_sampler_view = i915_create_sampler_view; + i915->base.sampler_view_destroy = i915_sampler_view_destroy; i915->base.set_viewport_state = i915_set_viewport_state; i915->base.set_vertex_buffers = i915_set_vertex_buffers; i915->base.set_vertex_elements = i915_set_vertex_elements; diff --git a/src/gallium/drivers/i915/i915_state_derived.c b/src/gallium/drivers/i915/i915_state_derived.c index f5b0e9f011e..0eb1e3f91a4 100644 --- a/src/gallium/drivers/i915/i915_state_derived.c +++ b/src/gallium/drivers/i915/i915_state_derived.c @@ -157,10 +157,10 @@ void i915_update_derived( struct i915_context *i915 ) if (i915->dirty & (I915_NEW_RASTERIZER | I915_NEW_FS | I915_NEW_VS)) calculate_vertex_layout( i915 ); - if (i915->dirty & (I915_NEW_SAMPLER | I915_NEW_TEXTURE)) + if (i915->dirty & (I915_NEW_SAMPLER | I915_NEW_SAMPLER_VIEW)) i915_update_samplers(i915); - if (i915->dirty & I915_NEW_TEXTURE) + if (i915->dirty & I915_NEW_SAMPLER_VIEW) i915_update_textures(i915); if (i915->dirty) diff --git a/src/gallium/drivers/i915/i915_state_emit.c b/src/gallium/drivers/i915/i915_state_emit.c index a3d4e3b04e5..202607a6563 100644 --- a/src/gallium/drivers/i915/i915_state_emit.c +++ b/src/gallium/drivers/i915/i915_state_emit.c @@ -289,7 +289,8 @@ i915_emit_hardware_state(struct i915_context *i915 ) OUT_BATCH(enabled); for (unit = 0; unit < I915_TEX_UNITS; unit++) { if (enabled & (1 << unit)) { - struct intel_buffer *buf = i915->texture[unit]->buffer; + struct i915_texture *texture = (struct i915_texture *)i915->fragment_sampler_views[unit]->texture; + struct intel_buffer *buf = texture->buffer; uint offset = 0; assert(buf); diff --git a/src/gallium/drivers/i915/i915_state_sampler.c b/src/gallium/drivers/i915/i915_state_sampler.c index e5c6d87215b..483947ece7f 100644 --- a/src/gallium/drivers/i915/i915_state_sampler.c +++ b/src/gallium/drivers/i915/i915_state_sampler.c @@ -144,20 +144,22 @@ void i915_update_samplers( struct i915_context *i915 ) i915->current.sampler_enable_nr = 0; i915->current.sampler_enable_flags = 0x0; - for (unit = 0; unit < i915->num_textures && unit < i915->num_samplers; + for (unit = 0; unit < i915->num_fragment_sampler_views && unit < i915->num_samplers; unit++) { /* determine unit enable/disable by looking for a bound texture */ /* could also examine the fragment program? */ - if (i915->texture[unit]) { + if (i915->fragment_sampler_views[unit]) { + struct i915_texture *texture = (struct i915_texture *)i915->fragment_sampler_views[unit]->texture; + update_sampler( i915, unit, i915->sampler[unit], /* sampler state */ - i915->texture[unit], /* texture */ + texture, /* texture */ i915->current.sampler[unit] /* the result */ ); i915_update_texture( i915, unit, - i915->texture[unit], /* texture */ + texture, /* texture */ i915->sampler[unit], /* sampler state */ i915->current.texbuffer[unit] ); @@ -281,14 +283,16 @@ i915_update_textures(struct i915_context *i915) { uint unit; - for (unit = 0; unit < i915->num_textures && unit < i915->num_samplers; + for (unit = 0; unit < i915->num_fragment_sampler_views && unit < i915->num_samplers; unit++) { /* determine unit enable/disable by looking for a bound texture */ /* could also examine the fragment program? */ - if (i915->texture[unit]) { + if (i915->fragment_sampler_views[unit]) { + struct i915_texture *texture = (struct i915_texture *)i915->fragment_sampler_views[unit]->texture; + i915_update_texture( i915, unit, - i915->texture[unit], /* texture */ + texture, /* texture */ i915->sampler[unit], /* sampler state */ i915->current.texbuffer[unit] ); } -- cgit v1.2.3 From 875f6d20b1180a4cafc747bd295b24ae1799a964 Mon Sep 17 00:00:00 2001 From: michal Date: Thu, 10 Dec 2009 08:05:45 +0100 Subject: i965: Fix after sampler view changes. --- src/gallium/drivers/i965/brw_context.h | 4 +- src/gallium/drivers/i965/brw_pipe_sampler.c | 53 +++++++++++++++++++------ src/gallium/drivers/i965/brw_wm.c | 4 +- src/gallium/drivers/i965/brw_wm_sampler_state.c | 8 ++-- src/gallium/drivers/i965/brw_wm_surface_state.c | 6 +-- 5 files changed, 52 insertions(+), 23 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/i965/brw_context.h b/src/gallium/drivers/i965/brw_context.h index 12cfa7b049c..8816714a7aa 100644 --- a/src/gallium/drivers/i965/brw_context.h +++ b/src/gallium/drivers/i965/brw_context.h @@ -550,11 +550,11 @@ struct brw_context const struct brw_sampler *sampler[PIPE_MAX_SAMPLERS]; unsigned num_samplers; - struct pipe_texture *texture[PIPE_MAX_SAMPLERS]; + struct pipe_sampler_view *fragment_sampler_views[PIPE_MAX_SAMPLERS]; struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS]; struct pipe_vertex_element vertex_element[PIPE_MAX_ATTRIBS]; unsigned num_vertex_elements; - unsigned num_textures; + unsigned num_fragment_sampler_views; unsigned num_vertex_buffers; struct pipe_scissor_state scissor; diff --git a/src/gallium/drivers/i965/brw_pipe_sampler.c b/src/gallium/drivers/i965/brw_pipe_sampler.c index c7c0e2ae95e..fe1d18ae773 100644 --- a/src/gallium/drivers/i965/brw_pipe_sampler.c +++ b/src/gallium/drivers/i965/brw_pipe_sampler.c @@ -183,26 +183,26 @@ static void brw_delete_sampler_state(struct pipe_context *pipe, FREE(cso); } -static void brw_set_sampler_textures(struct pipe_context *pipe, - unsigned num, - struct pipe_texture **texture) +static void brw_set_fragment_sampler_views(struct pipe_context *pipe, + unsigned num, + struct pipe_sampler_view **views) { struct brw_context *brw = brw_context(pipe); int i; for (i = 0; i < num; i++) - pipe_texture_reference(&brw->curr.texture[i], texture[i]); + pipe_sampler_view_reference(&brw->curr.fragment_sampler_views[i], views[i]); - for (i = num; i < brw->curr.num_textures; i++) - pipe_texture_reference(&brw->curr.texture[i], NULL); + for (i = num; i < brw->curr.num_fragment_sampler_views; i++) + pipe_sampler_view_reference(&brw->curr.fragment_sampler_views[i], NULL); - brw->curr.num_textures = num; + brw->curr.num_fragment_sampler_views = num; brw->state.dirty.mesa |= PIPE_NEW_BOUND_TEXTURES; } -static void brw_set_vertex_sampler_textures(struct pipe_context *pipe, - unsigned num, - struct pipe_texture **texture) +static void brw_set_vertex_sampler_views(struct pipe_context *pipe, + unsigned num, + struct pipe_sampler_view **views) { } @@ -212,17 +212,46 @@ static void brw_bind_vertex_sampler_state(struct pipe_context *pipe, } +static struct pipe_sampler_view * +brw_create_sampler_view(struct pipe_context *pipe, + struct pipe_texture *texture, + const struct pipe_sampler_view *templ) +{ + struct brw_context *brw = brw_context(pipe); + struct pipe_sampler_view *view = CALLOC_STRUCT(pipe_sampler_view); + + *view = *templ; + view->reference.count = 1; + view->texture = NULL; + pipe_texture_reference(&view->texture, texture); + view->context = pipe; + + return view; +} + + +static void +brw_sampler_view_destroy(struct pipe_context *pipe, + struct pipe_sampler_view *view) +{ + pipe_texture_reference(&view->texture, NULL); + FREE(view); +} + + void brw_pipe_sampler_init( struct brw_context *brw ) { brw->base.create_sampler_state = brw_create_sampler_state; brw->base.delete_sampler_state = brw_delete_sampler_state; - brw->base.set_fragment_sampler_textures = brw_set_sampler_textures; + brw->base.set_fragment_sampler_views = brw_set_fragment_sampler_views; brw->base.bind_fragment_sampler_states = brw_bind_sampler_state; - brw->base.set_vertex_sampler_textures = brw_set_vertex_sampler_textures; + brw->base.set_vertex_sampler_views = brw_set_vertex_sampler_views; brw->base.bind_vertex_sampler_states = brw_bind_vertex_sampler_state; + brw->base.create_sampler_view = brw_create_sampler_view; + brw->base.sampler_view_destroy = brw_sampler_view_destroy; } void brw_pipe_sampler_cleanup( struct brw_context *brw ) { diff --git a/src/gallium/drivers/i965/brw_wm.c b/src/gallium/drivers/i965/brw_wm.c index 5164c90ed60..3724adc040e 100644 --- a/src/gallium/drivers/i965/brw_wm.c +++ b/src/gallium/drivers/i965/brw_wm.c @@ -251,8 +251,8 @@ static void brw_wm_populate_key( struct brw_context *brw, /* PIPE_NEW_BOUND_TEXTURES */ - for (i = 0; i < brw->curr.num_textures; i++) { - const struct brw_texture *tex = brw_texture(brw->curr.texture[i]); + for (i = 0; i < brw->curr.num_fragment_sampler_views; i++) { + const struct brw_texture *tex = brw_texture(brw->curr.fragment_sampler_views[i]->texture); if (tex->base.format == PIPE_FORMAT_YCBCR) key->yuvtex_mask |= 1 << i; diff --git a/src/gallium/drivers/i965/brw_wm_sampler_state.c b/src/gallium/drivers/i965/brw_wm_sampler_state.c index a8bc31c9cef..a4bfa61ab30 100644 --- a/src/gallium/drivers/i965/brw_wm_sampler_state.c +++ b/src/gallium/drivers/i965/brw_wm_sampler_state.c @@ -78,11 +78,11 @@ brw_wm_sampler_populate_key(struct brw_context *brw, memset(key, 0, sizeof(*key)); - key->sampler_count = MIN2(brw->curr.num_textures, + key->sampler_count = MIN2(brw->curr.num_fragment_sampler_views, brw->curr.num_samplers); for (i = 0; i < key->sampler_count; i++) { - const struct brw_texture *tex = brw_texture(brw->curr.texture[i]); + const struct brw_texture *tex = brw_texture(brw->curr.fragment_sampler_views[i]->texture); const struct brw_sampler *sampler = brw->curr.sampler[i]; struct brw_sampler_state *entry = &key->sampler[i]; @@ -122,12 +122,12 @@ static enum pipe_error brw_wm_sampler_update_default_colors(struct brw_context *brw) { enum pipe_error ret; - int nr = MIN2(brw->curr.num_textures, + int nr = MIN2(brw->curr.num_fragment_sampler_views, brw->curr.num_samplers); int i; for (i = 0; i < nr; i++) { - const struct brw_texture *tex = brw_texture(brw->curr.texture[i]); + const struct brw_texture *tex = brw_texture(brw->curr.fragment_sampler_views[i]->texture); const struct brw_sampler *sampler = brw->curr.sampler[i]; const float *bc; diff --git a/src/gallium/drivers/i965/brw_wm_surface_state.c b/src/gallium/drivers/i965/brw_wm_surface_state.c index b01a7f194b7..2368ae3f808 100644 --- a/src/gallium/drivers/i965/brw_wm_surface_state.c +++ b/src/gallium/drivers/i965/brw_wm_surface_state.c @@ -242,9 +242,9 @@ static enum pipe_error prepare_wm_surfaces(struct brw_context *brw ) /* PIPE_NEW_TEXTURE */ - for (i = 0; i < brw->curr.num_textures; i++) { + for (i = 0; i < brw->curr.num_fragment_sampler_views; i++) { ret = brw_update_texture_surface(brw, - brw_texture(brw->curr.texture[i]), + brw_texture(brw->curr.fragment_sampler_views[i]->texture), &brw->wm.surf_bo[BTI_TEXTURE(i)]); if (ret) return ret; @@ -261,7 +261,7 @@ static enum pipe_error prepare_wm_surfaces(struct brw_context *brw ) bo_reference(&brw->wm.surf_bo[BTI_FRAGMENT_CONSTANTS], NULL); /* XXX: no pipe_max_textures define?? */ - for (i = brw->curr.num_textures; i < PIPE_MAX_SAMPLERS; i++) + for (i = brw->curr.num_fragment_sampler_views; i < PIPE_MAX_SAMPLERS; i++) bo_reference(&brw->wm.surf_bo[BTI_TEXTURE(i)], NULL); if (brw->wm.nr_surfaces != nr_surfaces) { -- cgit v1.2.3 From 3710a6f6cc84f46b6e1fb6a6a9f9eb6e7047c4e0 Mon Sep 17 00:00:00 2001 From: michal Date: Thu, 10 Dec 2009 08:46:19 +0100 Subject: r300: Fix after sampler view changes. --- src/gallium/drivers/r300/r300_blit.c | 6 ++-- src/gallium/drivers/r300/r300_context.h | 6 ++-- src/gallium/drivers/r300/r300_emit.c | 20 ++++++------ src/gallium/drivers/r300/r300_state.c | 54 ++++++++++++++++++++++++++------- 4 files changed, 59 insertions(+), 27 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/r300/r300_blit.c b/src/gallium/drivers/r300/r300_blit.c index eb9b0beeb5a..c48684fe51f 100644 --- a/src/gallium/drivers/r300/r300_blit.c +++ b/src/gallium/drivers/r300/r300_blit.c @@ -108,9 +108,9 @@ static void r300_hw_copy(struct pipe_context* pipe, util_blitter_save_fragment_sampler_states( r300->blitter, r300->sampler_count, (void**)r300->sampler_states); - util_blitter_save_fragment_sampler_textures( - r300->blitter, r300->texture_count, - (struct pipe_texture**)r300->textures); + util_blitter_save_fragment_sampler_views( + r300->blitter, r300->fragment_sampler_view_count, + r300->fragment_sampler_views); /* Do a copy */ util_blitter_copy(r300->blitter, diff --git a/src/gallium/drivers/r300/r300_context.h b/src/gallium/drivers/r300/r300_context.h index 1eba8a8ed12..2edf65797a2 100644 --- a/src/gallium/drivers/r300/r300_context.h +++ b/src/gallium/drivers/r300/r300_context.h @@ -300,9 +300,9 @@ struct r300_context { int sampler_count; /* Scissor state. */ struct r300_atom scissor_state; - /* Texture states. */ - struct r300_texture* textures[8]; - int texture_count; + /* Sampler view states. */ + struct pipe_sampler_view* fragment_sampler_views[8]; + int fragment_sampler_view_count; /* Vertex shader. */ struct r300_vertex_shader* vs; /* Viewport state. */ diff --git a/src/gallium/drivers/r300/r300_emit.c b/src/gallium/drivers/r300/r300_emit.c index 88fe166359b..4310ff1411d 100644 --- a/src/gallium/drivers/r300/r300_emit.c +++ b/src/gallium/drivers/r300/r300_emit.c @@ -159,7 +159,7 @@ static const float * get_shader_constant( /* Factor for converting rectangle coords to * normalized coords. Should only show up on non-r500. */ case RC_STATE_R300_TEXRECT_FACTOR: - tex = &r300->textures[constant->u.State[1]]->tex; + tex = r300->fragment_sampler_views[constant->u.State[1]]->texture; vec[0] = 1.0 / tex->width0; vec[1] = 1.0 / tex->height0; break; @@ -967,11 +967,11 @@ void r300_emit_texture_count(struct r300_context* r300) int i; CS_LOCALS(r300); - /* Notice that texture_count and sampler_count are just sizes + /* Notice that fragment_sampler_view_count and sampler_count are just sizes * of the respective arrays. We still have to check for the individual * elements. */ - for (i = 0; i < MIN2(r300->sampler_count, r300->texture_count); i++) { - if (r300->textures[i]) { + for (i = 0; i < MIN2(r300->sampler_count, r300->fragment_sampler_view_count); i++) { + if (r300->fragment_sampler_views[i]) { tx_enable |= 1 << i; } } @@ -1043,10 +1043,10 @@ validate: } } /* ...textures... */ - for (i = 0; i < r300->texture_count; i++) { - tex = r300->textures[i]; - if (!tex) + for (i = 0; i < r300->fragment_sampler_view_count; i++) { + if (!r300->fragment_sampler_views[i]) continue; + tex = (struct r300_texture *)r300->fragment_sampler_views[i]->texture; if (!r300->winsys->add_buffer(r300->winsys, tex->buffer, RADEON_GEM_DOMAIN_GTT | RADEON_GEM_DOMAIN_VRAM, 0)) { r300->context.flush(&r300->context, 0, NULL); @@ -1145,13 +1145,13 @@ void r300_emit_dirty_state(struct r300_context* r300) (R300_ANY_NEW_SAMPLERS | R300_ANY_NEW_TEXTURES)) { r300_emit_texture_count(r300); - for (i = 0; i < MIN2(r300->sampler_count, r300->texture_count); i++) { + for (i = 0; i < MIN2(r300->sampler_count, r300->fragment_sampler_view_count); i++) { if (r300->dirty_state & ((R300_NEW_SAMPLER << i) | (R300_NEW_TEXTURE << i))) { - if (r300->textures[i]) { + if (r300->fragment_sampler_views[i]) { r300_emit_texture(r300, r300->sampler_states[i], - r300->textures[i], + (struct r300_texture *)r300->fragment_sampler_views[i]->texture, i); dirty_tex |= r300->dirty_state & (R300_NEW_TEXTURE << i); } diff --git a/src/gallium/drivers/r300/r300_state.c b/src/gallium/drivers/r300/r300_state.c index 34bf81c1930..e5ec2701c81 100644 --- a/src/gallium/drivers/r300/r300_state.c +++ b/src/gallium/drivers/r300/r300_state.c @@ -932,9 +932,9 @@ static void r300_delete_sampler_state(struct pipe_context* pipe, void* state) FREE(state); } -static void r300_set_sampler_textures(struct pipe_context* pipe, - unsigned count, - struct pipe_texture** texture) +static void r300_set_fragment_sampler_views(struct pipe_context* pipe, + unsigned count, + struct pipe_sampler_view** views) { struct r300_context* r300 = r300_context(pipe); boolean is_r500 = r300_screen(r300->context.screen)->caps->is_r500; @@ -946,13 +946,17 @@ static void r300_set_sampler_textures(struct pipe_context* pipe, } for (i = 0; i < count; i++) { - if (r300->textures[i] != (struct r300_texture*)texture[i]) { - pipe_texture_reference((struct pipe_texture**)&r300->textures[i], - texture[i]); + if (r300->fragment_sampler_views[i] != views[i]) { + struct r300_texture *texture; + + pipe_sampler_view_reference(&r300->fragment_sampler_views[i], + views[i]); r300->dirty_state |= (R300_NEW_TEXTURE << i); + texture = (struct r300_texture *)views[i]->texture; + /* R300-specific - set the texrect factor in a fragment shader */ - if (!is_r500 && r300->textures[i]->is_npot) { + if (!is_r500 && texture->is_npot) { /* XXX It would be nice to re-emit just 1 constant, * XXX not all of them */ r300->dirty_state |= R300_NEW_FRAGMENT_SHADER_CONSTANTS; @@ -961,14 +965,40 @@ static void r300_set_sampler_textures(struct pipe_context* pipe, } for (i = count; i < 8; i++) { - if (r300->textures[i]) { - pipe_texture_reference((struct pipe_texture**)&r300->textures[i], + if (r300->fragment_sampler_views[i]) { + pipe_sampler_view_reference(&r300->fragment_sampler_views[i], NULL); r300->dirty_state |= (R300_NEW_TEXTURE << i); } } - r300->texture_count = count; + r300->fragment_sampler_view_count = count; +} + +static struct pipe_sampler_view * +r300_create_sampler_view(struct pipe_context *pipe, + struct pipe_texture *texture, + const struct pipe_sampler_view *templ) +{ + struct r300_context *r300 = r300_context(pipe); + struct pipe_sampler_view *view = CALLOC_STRUCT(pipe_sampler_view); + + *view = *templ; + view->reference.count = 1; + view->texture = NULL; + pipe_texture_reference(&view->texture, texture); + view->context = pipe; + + return view; +} + + +static void +r300_sampler_view_destroy(struct pipe_context *pipe, + struct pipe_sampler_view *view) +{ + pipe_texture_reference(&view->texture, NULL); + FREE(view); } static void r300_set_scissor_state(struct pipe_context* pipe, @@ -1234,7 +1264,9 @@ void r300_init_state_functions(struct r300_context* r300) r300->context.bind_vertex_sampler_states = r300_lacks_vertex_textures; r300->context.delete_sampler_state = r300_delete_sampler_state; - r300->context.set_fragment_sampler_textures = r300_set_sampler_textures; + r300->context.set_fragment_sampler_views = r300_set_fragment_sampler_views; + r300->context.create_sampler_view = r300_create_sampler_view; + r300->context.sampler_view_destroy = r300_sampler_view_destroy; r300->context.set_scissor_state = r300_set_scissor_state; -- cgit v1.2.3 From 1fb440beb9cccbe6f4bbd309792a89f6e1b4ee3f Mon Sep 17 00:00:00 2001 From: michal Date: Thu, 10 Dec 2009 09:23:15 +0100 Subject: llvmpipe: Fix after sampler view changes. --- src/gallium/drivers/llvmpipe/lp_context.c | 10 ++-- src/gallium/drivers/llvmpipe/lp_context.h | 8 ++-- src/gallium/drivers/llvmpipe/lp_setup.c | 12 +++-- src/gallium/drivers/llvmpipe/lp_setup.h | 5 +- src/gallium/drivers/llvmpipe/lp_state.h | 23 ++++++--- src/gallium/drivers/llvmpipe/lp_state_derived.c | 12 ++--- src/gallium/drivers/llvmpipe/lp_state_fs.c | 2 +- src/gallium/drivers/llvmpipe/lp_state_sampler.c | 63 ++++++++++++++++++------- 8 files changed, 88 insertions(+), 47 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/llvmpipe/lp_context.c b/src/gallium/drivers/llvmpipe/lp_context.c index 9120226de0c..0e385f843d1 100644 --- a/src/gallium/drivers/llvmpipe/lp_context.c +++ b/src/gallium/drivers/llvmpipe/lp_context.c @@ -68,11 +68,11 @@ static void llvmpipe_destroy( struct pipe_context *pipe ) pipe_surface_reference(&llvmpipe->framebuffer.zsbuf, NULL); for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { - pipe_texture_reference(&llvmpipe->texture[i], NULL); + pipe_sampler_view_reference(&llvmpipe->fragment_sampler_views[i], NULL); } for (i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; i++) { - pipe_texture_reference(&llvmpipe->vertex_textures[i], NULL); + pipe_sampler_view_reference(&llvmpipe->vertex_sampler_views[i], NULL); } for (i = 0; i < Elements(llvmpipe->constants); i++) { @@ -152,8 +152,10 @@ llvmpipe_create_context( struct pipe_screen *screen, void *priv ) llvmpipe->pipe.set_framebuffer_state = llvmpipe_set_framebuffer_state; llvmpipe->pipe.set_polygon_stipple = llvmpipe_set_polygon_stipple; llvmpipe->pipe.set_scissor_state = llvmpipe_set_scissor_state; - llvmpipe->pipe.set_fragment_sampler_textures = llvmpipe_set_sampler_textures; - llvmpipe->pipe.set_vertex_sampler_textures = llvmpipe_set_vertex_sampler_textures; + llvmpipe->pipe.set_fragment_sampler_views = llvmpipe_set_fragment_sampler_views; + llvmpipe->pipe.set_vertex_sampler_views = llvmpipe_set_vertex_sampler_views; + llvmpipe->pipe.create_sampler_view = llvmpipe_create_sampler_view; + llvmpipe->pipe.sampler_view_destroy = llvmpipe_sampler_view_destroy; llvmpipe->pipe.set_viewport_state = llvmpipe_set_viewport_state; llvmpipe->pipe.set_vertex_buffers = llvmpipe_set_vertex_buffers; diff --git a/src/gallium/drivers/llvmpipe/lp_context.h b/src/gallium/drivers/llvmpipe/lp_context.h index 955c7eb8e0e..1b98e3033db 100644 --- a/src/gallium/drivers/llvmpipe/lp_context.h +++ b/src/gallium/drivers/llvmpipe/lp_context.h @@ -67,16 +67,16 @@ struct llvmpipe_context { struct pipe_framebuffer_state framebuffer; struct pipe_poly_stipple poly_stipple; struct pipe_scissor_state scissor; - struct pipe_texture *texture[PIPE_MAX_SAMPLERS]; - struct pipe_texture *vertex_textures[PIPE_MAX_VERTEX_SAMPLERS]; + struct pipe_sampler_view *fragment_sampler_views[PIPE_MAX_SAMPLERS]; + struct pipe_sampler_view *vertex_sampler_views[PIPE_MAX_VERTEX_SAMPLERS]; struct pipe_viewport_state viewport; struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS]; struct pipe_vertex_element vertex_element[PIPE_MAX_ATTRIBS]; unsigned num_samplers; - unsigned num_textures; + unsigned num_fragment_sampler_views; unsigned num_vertex_samplers; - unsigned num_vertex_textures; + unsigned num_vertex_sampler_views; unsigned num_vertex_elements; unsigned num_vertex_buffers; diff --git a/src/gallium/drivers/llvmpipe/lp_setup.c b/src/gallium/drivers/llvmpipe/lp_setup.c index cb873667a20..7d52765970c 100644 --- a/src/gallium/drivers/llvmpipe/lp_setup.c +++ b/src/gallium/drivers/llvmpipe/lp_setup.c @@ -453,11 +453,12 @@ lp_setup_set_vertex_info( struct setup_context *setup, /** - * Called during state validation when LP_NEW_TEXTURE is set. + * Called during state validation when LP_NEW_SAMPLER_VIEW is set. */ void -lp_setup_set_sampler_textures( struct setup_context *setup, - unsigned num, struct pipe_texture **texture) +lp_setup_set_fragment_sampler_views(struct setup_context *setup, + unsigned num, + struct pipe_sampler_view **views) { unsigned i; @@ -466,9 +467,10 @@ lp_setup_set_sampler_textures( struct setup_context *setup, assert(num <= PIPE_MAX_SAMPLERS); for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { - struct pipe_texture *tex = i < num ? texture[i] : NULL; + struct pipe_sampler_view *view = i < num ? views[i] : NULL; - if(tex) { + if(view) { + struct pipe_texture *tex = view->texture; struct llvmpipe_texture *lp_tex = llvmpipe_texture(tex); struct lp_jit_texture *jit_tex; jit_tex = &setup->fs.current.jit_context.textures[i]; diff --git a/src/gallium/drivers/llvmpipe/lp_setup.h b/src/gallium/drivers/llvmpipe/lp_setup.h index 0e155a7dc31..5a5d3531f95 100644 --- a/src/gallium/drivers/llvmpipe/lp_setup.h +++ b/src/gallium/drivers/llvmpipe/lp_setup.h @@ -120,8 +120,9 @@ lp_setup_set_scissor( struct setup_context *setup, const struct pipe_scissor_state *scissor ); void -lp_setup_set_sampler_textures( struct setup_context *setup, - unsigned num, struct pipe_texture **texture); +lp_setup_set_fragment_sampler_views(struct setup_context *setup, + unsigned num, + struct pipe_sampler_view **views); unsigned lp_setup_is_texture_referenced( const struct setup_context *setup, diff --git a/src/gallium/drivers/llvmpipe/lp_state.h b/src/gallium/drivers/llvmpipe/lp_state.h index 9beba32271f..8a2a08b0759 100644 --- a/src/gallium/drivers/llvmpipe/lp_state.h +++ b/src/gallium/drivers/llvmpipe/lp_state.h @@ -50,7 +50,7 @@ #define LP_NEW_DEPTH_STENCIL_ALPHA 0x100 #define LP_NEW_CONSTANTS 0x200 #define LP_NEW_SAMPLER 0x400 -#define LP_NEW_TEXTURE 0x800 +#define LP_NEW_SAMPLER_VIEW 0x800 #define LP_NEW_VERTEX 0x1000 #define LP_NEW_VS 0x2000 #define LP_NEW_QUERY 0x4000 @@ -182,14 +182,23 @@ void llvmpipe_set_polygon_stipple( struct pipe_context *, void llvmpipe_set_scissor_state( struct pipe_context *, const struct pipe_scissor_state * ); -void llvmpipe_set_sampler_textures( struct pipe_context *, - unsigned num, - struct pipe_texture ** ); +void llvmpipe_set_fragment_sampler_views(struct pipe_context *, + unsigned num, + struct pipe_sampler_view **); void -llvmpipe_set_vertex_sampler_textures(struct pipe_context *, - unsigned num_textures, - struct pipe_texture **); +llvmpipe_set_vertex_sampler_views(struct pipe_context *, + unsigned num, + struct pipe_sampler_view **); + +struct pipe_sampler_view * +llvmpipe_create_sampler_view(struct pipe_context *pipe, + struct pipe_texture *texture, + const struct pipe_sampler_view *templ); + +void +llvmpipe_sampler_view_destroy(struct pipe_context *pipe, + struct pipe_sampler_view *view); void llvmpipe_set_viewport_state( struct pipe_context *, const struct pipe_viewport_state * ); diff --git a/src/gallium/drivers/llvmpipe/lp_state_derived.c b/src/gallium/drivers/llvmpipe/lp_state_derived.c index bdd906e1a73..9c91ce9238f 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_derived.c +++ b/src/gallium/drivers/llvmpipe/lp_state_derived.c @@ -150,7 +150,7 @@ void llvmpipe_update_derived( struct llvmpipe_context *llvmpipe ) */ if (llvmpipe->tex_timestamp != lp_screen->timestamp) { llvmpipe->tex_timestamp = lp_screen->timestamp; - llvmpipe->dirty |= LP_NEW_TEXTURE; + llvmpipe->dirty |= LP_NEW_SAMPLER_VIEW; } if (llvmpipe->dirty & (LP_NEW_RASTERIZER | @@ -164,7 +164,7 @@ void llvmpipe_update_derived( struct llvmpipe_context *llvmpipe ) LP_NEW_DEPTH_STENCIL_ALPHA | LP_NEW_RASTERIZER | LP_NEW_SAMPLER | - LP_NEW_TEXTURE)) + LP_NEW_SAMPLER_VIEW)) llvmpipe_update_fs( llvmpipe ); if (llvmpipe->dirty & LP_NEW_BLEND_COLOR) @@ -182,10 +182,10 @@ void llvmpipe_update_derived( struct llvmpipe_context *llvmpipe ) lp_setup_set_fs_constants(llvmpipe->setup, llvmpipe->constants[PIPE_SHADER_FRAGMENT]); - if (llvmpipe->dirty & LP_NEW_TEXTURE) - lp_setup_set_sampler_textures(llvmpipe->setup, - llvmpipe->num_textures, - llvmpipe->texture); + if (llvmpipe->dirty & LP_NEW_SAMPLER_VIEW) + lp_setup_set_fragment_sampler_views(llvmpipe->setup, + llvmpipe->num_fragment_sampler_views, + llvmpipe->fragment_sampler_views); llvmpipe->dirty = 0; } diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs.c b/src/gallium/drivers/llvmpipe/lp_state_fs.c index 90dae3f9101..2e018df05c0 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_fs.c +++ b/src/gallium/drivers/llvmpipe/lp_state_fs.c @@ -1084,7 +1084,7 @@ make_variant_key(struct llvmpipe_context *lp, for(i = 0; i < PIPE_MAX_SAMPLERS; ++i) if(shader->info.file_mask[TGSI_FILE_SAMPLER] & (1 << i)) - lp_sampler_static_state(&key->sampler[i], lp->texture[i], lp->sampler[i]); + lp_sampler_static_state(&key->sampler[i], lp->fragment_sampler_views[i]->texture, lp->sampler[i]); } diff --git a/src/gallium/drivers/llvmpipe/lp_state_sampler.c b/src/gallium/drivers/llvmpipe/lp_state_sampler.c index b30a0757768..2df86a08148 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_sampler.c +++ b/src/gallium/drivers/llvmpipe/lp_state_sampler.c @@ -105,8 +105,9 @@ llvmpipe_bind_vertex_sampler_states(struct pipe_context *pipe, void -llvmpipe_set_sampler_textures(struct pipe_context *pipe, - unsigned num, struct pipe_texture **texture) +llvmpipe_set_fragment_sampler_views(struct pipe_context *pipe, + unsigned num, + struct pipe_sampler_view **views) { struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe); uint i; @@ -114,51 +115,77 @@ llvmpipe_set_sampler_textures(struct pipe_context *pipe, assert(num <= PIPE_MAX_SAMPLERS); /* Check for no-op */ - if (num == llvmpipe->num_textures && - !memcmp(llvmpipe->texture, texture, num * sizeof(struct pipe_texture *))) + if (num == llvmpipe->num_fragment_sampler_views && + !memcmp(llvmpipe->fragment_sampler_views, views, num * sizeof(struct pipe_sampler_view *))) return; draw_flush(llvmpipe->draw); for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { - struct pipe_texture *tex = i < num ? texture[i] : NULL; + struct pipe_sampler_view *view = i < num ? views[i] : NULL; - pipe_texture_reference(&llvmpipe->texture[i], tex); + pipe_sampler_view_reference(&llvmpipe->fragment_sampler_views[i], view); } - llvmpipe->num_textures = num; + llvmpipe->num_fragment_sampler_views = num; - llvmpipe->dirty |= LP_NEW_TEXTURE; + llvmpipe->dirty |= LP_NEW_SAMPLER_VIEW; } void -llvmpipe_set_vertex_sampler_textures(struct pipe_context *pipe, - unsigned num_textures, - struct pipe_texture **textures) +llvmpipe_set_vertex_sampler_views(struct pipe_context *pipe, + unsigned num, + struct pipe_sampler_view **views) { struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe); uint i; - assert(num_textures <= PIPE_MAX_VERTEX_SAMPLERS); + assert(num <= PIPE_MAX_VERTEX_SAMPLERS); /* Check for no-op */ - if (num_textures == llvmpipe->num_vertex_textures && - !memcmp(llvmpipe->vertex_textures, textures, num_textures * sizeof(struct pipe_texture *))) { + if (num == llvmpipe->num_vertex_sampler_views && + !memcmp(llvmpipe->vertex_sampler_views, views, num * sizeof(struct pipe_sampler_view *))) { return; } draw_flush(llvmpipe->draw); for (i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; i++) { - struct pipe_texture *tex = i < num_textures ? textures[i] : NULL; + struct pipe_sampler_view *view = i < num ? views[i] : NULL; - pipe_texture_reference(&llvmpipe->vertex_textures[i], tex); + pipe_sampler_view_reference(&llvmpipe->vertex_sampler_views[i], view); } - llvmpipe->num_vertex_textures = num_textures; + llvmpipe->num_vertex_sampler_views = num; - llvmpipe->dirty |= LP_NEW_TEXTURE; + llvmpipe->dirty |= LP_NEW_SAMPLER_VIEW; +} + + +struct pipe_sampler_view * +llvmpipe_create_sampler_view(struct pipe_context *pipe, + struct pipe_texture *texture, + const struct pipe_sampler_view *templ) +{ + struct pipe_sampler_view *view = CALLOC_STRUCT(pipe_sampler_view); + + *view = *templ; + view->reference.count = 1; + view->texture = NULL; + pipe_texture_reference(&view->texture, texture); + view->context = pipe; + + return view; +} + + +void +llvmpipe_sampler_view_destroy(struct pipe_context *pipe, + struct pipe_sampler_view *view) +{ + pipe_texture_reference(&view->texture, NULL); + FREE(view); } -- cgit v1.2.3 From 3a7314a78d2d239aef4032445c41e530ec13d3e0 Mon Sep 17 00:00:00 2001 From: michal Date: Thu, 10 Dec 2009 09:29:15 +0100 Subject: gallium: Silence compiler warnings. --- src/gallium/drivers/i915/i915_state.c | 1 - src/gallium/drivers/i965/brw_pipe_sampler.c | 1 - src/gallium/drivers/softpipe/sp_state_sampler.c | 3 --- src/gallium/drivers/svga/svga_pipe_sampler.c | 3 --- 4 files changed, 8 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/i915/i915_state.c b/src/gallium/drivers/i915/i915_state.c index b38d1b2404a..46703dce350 100644 --- a/src/gallium/drivers/i915/i915_state.c +++ b/src/gallium/drivers/i915/i915_state.c @@ -596,7 +596,6 @@ i915_create_sampler_view(struct pipe_context *pipe, struct pipe_texture *texture, const struct pipe_sampler_view *templ) { - struct i915_context *i915 = i915_context(pipe); struct pipe_sampler_view *view = CALLOC_STRUCT(pipe_sampler_view); *view = *templ; diff --git a/src/gallium/drivers/i965/brw_pipe_sampler.c b/src/gallium/drivers/i965/brw_pipe_sampler.c index fe1d18ae773..fbc3a07d61e 100644 --- a/src/gallium/drivers/i965/brw_pipe_sampler.c +++ b/src/gallium/drivers/i965/brw_pipe_sampler.c @@ -217,7 +217,6 @@ brw_create_sampler_view(struct pipe_context *pipe, struct pipe_texture *texture, const struct pipe_sampler_view *templ) { - struct brw_context *brw = brw_context(pipe); struct pipe_sampler_view *view = CALLOC_STRUCT(pipe_sampler_view); *view = *templ; diff --git a/src/gallium/drivers/softpipe/sp_state_sampler.c b/src/gallium/drivers/softpipe/sp_state_sampler.c index 5a92e2223ef..8922941994a 100644 --- a/src/gallium/drivers/softpipe/sp_state_sampler.c +++ b/src/gallium/drivers/softpipe/sp_state_sampler.c @@ -126,7 +126,6 @@ softpipe_create_sampler_view(struct pipe_context *pipe, struct pipe_texture *texture, const struct pipe_sampler_view *templ) { - struct softpipe_context *softpipe = softpipe_context(pipe); struct pipe_sampler_view *view = CALLOC_STRUCT(pipe_sampler_view); *view = *templ; @@ -143,8 +142,6 @@ void softpipe_sampler_view_destroy(struct pipe_context *pipe, struct pipe_sampler_view *view) { - struct softpipe_context *softpipe = softpipe_context(pipe); - pipe_texture_reference(&view->texture, NULL); FREE(view); } diff --git a/src/gallium/drivers/svga/svga_pipe_sampler.c b/src/gallium/drivers/svga/svga_pipe_sampler.c index 26878177308..50fe962b28d 100644 --- a/src/gallium/drivers/svga/svga_pipe_sampler.c +++ b/src/gallium/drivers/svga/svga_pipe_sampler.c @@ -181,7 +181,6 @@ svga_create_sampler_view(struct pipe_context *pipe, struct pipe_texture *texture, const struct pipe_sampler_view *templ) { - struct svga_context *softpipe = svga_context(pipe); struct pipe_sampler_view *view = CALLOC_STRUCT(pipe_sampler_view); *view = *templ; @@ -198,8 +197,6 @@ static void svga_sampler_view_destroy(struct pipe_context *pipe, struct pipe_sampler_view *view) { - struct svga_context *svga = svga_context(pipe); - pipe_texture_reference(&view->texture, NULL); FREE(view); } -- cgit v1.2.3 From 92a8c42baa64fbf8e1a986a0b820fe1744c1b3b3 Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Thu, 25 Feb 2010 14:19:54 +0100 Subject: python: Fix after sampler view changes. --- src/gallium/state_trackers/python/gallium.i | 1 + src/gallium/state_trackers/python/p_context.i | 33 ++++++++++++++++++++------- src/gallium/state_trackers/python/st_device.c | 32 +++++++++++++++++++------- src/gallium/state_trackers/python/st_device.h | 4 ++-- 4 files changed, 52 insertions(+), 18 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/python/gallium.i b/src/gallium/state_trackers/python/gallium.i index ffb084e358b..632d71ccbee 100644 --- a/src/gallium/state_trackers/python/gallium.i +++ b/src/gallium/state_trackers/python/gallium.i @@ -49,6 +49,7 @@ #include "util/u_format.h" #include "util/u_dump.h" #include "util/u_memory.h" +#include "util/u_sampler.h" #include "cso_cache/cso_context.h" #include "tgsi/tgsi_text.h" #include "tgsi/tgsi_dump.h" diff --git a/src/gallium/state_trackers/python/p_context.i b/src/gallium/state_trackers/python/p_context.i index 3f36ccb6217..85c9598d069 100644 --- a/src/gallium/state_trackers/python/p_context.i +++ b/src/gallium/state_trackers/python/p_context.i @@ -169,22 +169,39 @@ struct st_context { void set_fragment_sampler_texture(unsigned index, struct pipe_texture *texture) { + struct pipe_sampler_view templ; + if(!texture) texture = $self->default_texture; - pipe_texture_reference(&$self->fragment_sampler_textures[index], texture); - $self->pipe->set_fragment_sampler_textures($self->pipe, - PIPE_MAX_SAMPLERS, - $self->fragment_sampler_textures); + pipe_sampler_view_reference(&$self->fragment_sampler_views[index], NULL); + u_sampler_view_default_template(&templ, + texture, + texture->format); + $self->fragment_sampler_views[index] = $self->pipe->create_sampler_view($self->pipe, + texture, + &templ); + $self->pipe->set_fragment_sampler_views($self->pipe, + PIPE_MAX_SAMPLERS, + $self->fragment_sampler_views); } void set_vertex_sampler_texture(unsigned index, struct pipe_texture *texture) { + struct pipe_sampler_view templ; + if(!texture) texture = $self->default_texture; - pipe_texture_reference(&$self->vertex_sampler_textures[index], texture); - $self->pipe->set_vertex_sampler_textures($self->pipe, - PIPE_MAX_VERTEX_SAMPLERS, - $self->vertex_sampler_textures); + pipe_sampler_view_reference(&$self->vertex_sampler_views[index], NULL); + u_sampler_view_default_template(&templ, + texture, + texture->format); + $self->vertex_sampler_views[index] = $self->pipe->create_sampler_view($self->pipe, + texture, + &templ); + + $self->pipe->set_vertex_sampler_views($self->pipe, + PIPE_MAX_VERTEX_SAMPLERS, + $self->vertex_sampler_views); } void set_vertex_buffer(unsigned index, diff --git a/src/gallium/state_trackers/python/st_device.c b/src/gallium/state_trackers/python/st_device.c index a3798a55212..d5a14fd795d 100644 --- a/src/gallium/state_trackers/python/st_device.c +++ b/src/gallium/state_trackers/python/st_device.c @@ -33,6 +33,7 @@ #include "cso_cache/cso_context.h" #include "util/u_math.h" #include "util/u_memory.h" +#include "util/u_sampler.h" #include "util/u_simple_shaders.h" #include "trace/tr_screen.h" #include "trace/tr_context.h" @@ -134,9 +135,9 @@ st_context_destroy(struct st_context *st_ctx) st_ctx->pipe->destroy(st_ctx->pipe); for(i = 0; i < PIPE_MAX_SAMPLERS; ++i) - pipe_texture_reference(&st_ctx->fragment_sampler_textures[i], NULL); + pipe_sampler_view_reference(&st_ctx->fragment_sampler_views[i], NULL); for(i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; ++i) - pipe_texture_reference(&st_ctx->vertex_sampler_textures[i], NULL); + pipe_sampler_view_reference(&st_ctx->vertex_sampler_views[i], NULL); pipe_texture_reference(&st_ctx->default_texture, NULL); FREE(st_ctx); @@ -240,6 +241,8 @@ st_context_create(struct st_device *st_dev) struct pipe_screen *screen = st_dev->screen; struct pipe_texture templat; struct pipe_transfer *transfer; + struct pipe_sampler_view view_templ; + struct pipe_sampler_view *view; unsigned i; memset( &templat, 0, sizeof( templat ) ); @@ -269,14 +272,27 @@ st_context_create(struct st_device *st_dev) screen->tex_transfer_destroy(transfer); } } - + + u_sampler_view_default_template(&view_templ, + st_ctx->default_texture, + st_ctx->default_texture->format); + view = st_ctx->pipe->create_sampler_view(st_ctx->pipe, + st_ctx->default_texture, + &view_templ); + for (i = 0; i < PIPE_MAX_SAMPLERS; i++) - pipe_texture_reference(&st_ctx->fragment_sampler_textures[i], st_ctx->default_texture); + pipe_sampler_view_reference(&st_ctx->fragment_sampler_views[i], view); for (i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; i++) - pipe_texture_reference(&st_ctx->vertex_sampler_textures[i], st_ctx->default_texture); - - cso_set_sampler_textures(st_ctx->cso, PIPE_MAX_SAMPLERS, st_ctx->fragment_sampler_textures); - cso_set_vertex_sampler_textures(st_ctx->cso, PIPE_MAX_VERTEX_SAMPLERS, st_ctx->vertex_sampler_textures); + pipe_sampler_view_reference(&st_ctx->vertex_sampler_views[i], view); + + st_ctx->pipe->set_fragment_sampler_views(st_ctx->pipe, + PIPE_MAX_SAMPLERS, + st_ctx->fragment_sampler_views); + st_ctx->pipe->set_vertex_sampler_views(st_ctx->pipe, + PIPE_MAX_VERTEX_SAMPLERS, + st_ctx->vertex_sampler_views); + + pipe_sampler_view_reference(&view, NULL); } /* vertex shader */ diff --git a/src/gallium/state_trackers/python/st_device.h b/src/gallium/state_trackers/python/st_device.h index de9e0215d8e..dee9a8ca7b5 100644 --- a/src/gallium/state_trackers/python/st_device.h +++ b/src/gallium/state_trackers/python/st_device.h @@ -59,8 +59,8 @@ struct st_context { void *gs; struct pipe_texture *default_texture; - struct pipe_texture *fragment_sampler_textures[PIPE_MAX_SAMPLERS]; - struct pipe_texture *vertex_sampler_textures[PIPE_MAX_VERTEX_SAMPLERS]; + struct pipe_sampler_view *fragment_sampler_views[PIPE_MAX_SAMPLERS]; + struct pipe_sampler_view *vertex_sampler_views[PIPE_MAX_VERTEX_SAMPLERS]; unsigned num_vertex_buffers; struct pipe_vertex_buffer vertex_buffers[PIPE_MAX_ATTRIBS]; -- cgit v1.2.3 From 3e0181f47334534be081caa912a20d278fd07149 Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Thu, 25 Feb 2010 14:21:50 +0100 Subject: python: Fix typo. --- src/gallium/state_trackers/python/p_state.i | 2 +- .../python/tests/regress/fragment-shader/frag-abs.png | Bin 0 -> 8750 bytes 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 src/gallium/state_trackers/python/tests/regress/fragment-shader/frag-abs.png (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/python/p_state.i b/src/gallium/state_trackers/python/p_state.i index 5afe4d49082..eda77b56f8e 100644 --- a/src/gallium/state_trackers/python/p_state.i +++ b/src/gallium/state_trackers/python/p_state.i @@ -69,7 +69,7 @@ pipe_blend_state(const char *STRING, unsigned LENGTH) { struct pipe_blend_state *state; - state = CALLOC_STRUCT(pipe_framebuffer_state); + state = CALLOC_STRUCT(pipe_blend_state); if (state) { LENGTH = MIN2(sizeof *state, LENGTH); memcpy(state, STRING, LENGTH); diff --git a/src/gallium/state_trackers/python/tests/regress/fragment-shader/frag-abs.png b/src/gallium/state_trackers/python/tests/regress/fragment-shader/frag-abs.png new file mode 100644 index 00000000000..c947a7b8813 Binary files /dev/null and b/src/gallium/state_trackers/python/tests/regress/fragment-shader/frag-abs.png differ -- cgit v1.2.3 From 06f63457908a997828e93f3141ecdde59392b7d5 Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Thu, 25 Feb 2010 14:27:34 +0100 Subject: docs: Update after sampler view changes. --- src/gallium/docs/source/context.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/docs/source/context.rst b/src/gallium/docs/source/context.rst index 9080addba44..827db8398ce 100644 --- a/src/gallium/docs/source/context.rst +++ b/src/gallium/docs/source/context.rst @@ -39,8 +39,10 @@ buffers, surfaces) are bound to the driver. are mostly restricted to the first one right now). * ``set_framebuffer_state`` -* ``set_fragment_sampler_textures`` -* ``set_vertex_sampler_textures`` +* ``set_fragment_sampler_views`` +* ``set_vertex_sampler_views`` +* ``create_sampler_view`` +* ``sampler_view_destroy`` * ``set_vertex_buffers`` -- cgit v1.2.3 From e3c2a053cf4ac761d672ec64cb18c099b4ac3bc2 Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Thu, 25 Feb 2010 14:40:56 +0100 Subject: nv30: Fix after sampler view changes. Did not test build. --- src/gallium/drivers/nv30/nv30_context.h | 1 + src/gallium/drivers/nv30/nv30_state.c | 38 +++++++++++++++++++++++++++++---- 2 files changed, 35 insertions(+), 4 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/nv30/nv30_context.h b/src/gallium/drivers/nv30/nv30_context.h index ca3d6aca7fa..04813526f40 100644 --- a/src/gallium/drivers/nv30/nv30_context.h +++ b/src/gallium/drivers/nv30/nv30_context.h @@ -138,6 +138,7 @@ struct nv30_context { unsigned idxbuf_format; struct nv30_sampler_state *tex_sampler[PIPE_MAX_SAMPLERS]; struct nv30_miptree *tex_miptree[PIPE_MAX_SAMPLERS]; + struct pipe_sampler_view *fragment_sampler_views[PIPE_MAX_SAMPLERS]; unsigned nr_samplers; unsigned nr_textures; unsigned dirty_samplers; diff --git a/src/gallium/drivers/nv30/nv30_state.c b/src/gallium/drivers/nv30/nv30_state.c index d911c807074..1d484ecb77f 100644 --- a/src/gallium/drivers/nv30/nv30_state.c +++ b/src/gallium/drivers/nv30/nv30_state.c @@ -272,19 +272,22 @@ nv30_sampler_state_delete(struct pipe_context *pipe, void *hwcso) } static void -nv30_set_sampler_texture(struct pipe_context *pipe, unsigned nr, - struct pipe_texture **miptree) +nv30_set_fragment_sampler_views(struct pipe_context *pipe, + unsigned nr, + struct pipe_sampler_view **views) { struct nv30_context *nv30 = nv30_context(pipe); unsigned unit; for (unit = 0; unit < nr; unit++) { + pipe_sampler_view_reference(&nv30->fragment_sampler_views[unit], views[unit]); pipe_texture_reference((struct pipe_texture **) - &nv30->tex_miptree[unit], miptree[unit]); + &nv30->tex_miptree[unit], views[unit]->texture); nv30->dirty_samplers |= (1 << unit); } for (unit = nr; unit < nv30->nr_textures; unit++) { + pipe_sampler_view_reference(&nv30->fragment_sampler_views[unit], NULL); pipe_texture_reference((struct pipe_texture **) &nv30->tex_miptree[unit], NULL); nv30->dirty_samplers |= (1 << unit); @@ -294,6 +297,31 @@ nv30_set_sampler_texture(struct pipe_context *pipe, unsigned nr, nv30->dirty |= NV30_NEW_SAMPLER; } +static struct pipe_sampler_view * +nv30_create_sampler_view(struct pipe_context *pipe, + struct pipe_texture *texture, + const struct pipe_sampler_view *templ) +{ + struct pipe_sampler_view *view = CALLOC_STRUCT(pipe_sampler_view); + + *view = *templ; + view->reference.count = 1; + view->texture = NULL; + pipe_texture_reference(&view->texture, texture); + view->context = pipe; + + return view; +} + + +static void +nv30_sampler_view_destroy(struct pipe_context *pipe, + struct pipe_sampler_view *view) +{ + pipe_texture_reference(&view->texture, NULL); + FREE(view); +} + static void * nv30_rasterizer_state_create(struct pipe_context *pipe, const struct pipe_rasterizer_state *cso) @@ -692,7 +720,9 @@ nv30_init_state_functions(struct nv30_context *nv30) nv30->pipe.create_sampler_state = nv30_sampler_state_create; nv30->pipe.bind_fragment_sampler_states = nv30_sampler_state_bind; nv30->pipe.delete_sampler_state = nv30_sampler_state_delete; - nv30->pipe.set_fragment_sampler_textures = nv30_set_sampler_texture; + nv30->pipe.set_fragment_sampler_views = nv30_set_fragment_sampler_view; + nv30->pipe.create_sampler_view = nv30_create_sampler_view; + nv30->pipe.sampler_view_destroy = nv30_sampler_view_destroy; nv30->pipe.create_rasterizer_state = nv30_rasterizer_state_create; nv30->pipe.bind_rasterizer_state = nv30_rasterizer_state_bind; -- cgit v1.2.3 From 512d3e691e43b663932fcf22a8c333c79033cb8b Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Thu, 25 Feb 2010 14:46:31 +0100 Subject: nv40: Fix after sampler view changes. Did not test build. --- src/gallium/drivers/nv40/nv40_context.h | 1 + src/gallium/drivers/nv40/nv40_state.c | 38 +++++++++++++++++++++++++++++---- 2 files changed, 35 insertions(+), 4 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/nv40/nv40_context.h b/src/gallium/drivers/nv40/nv40_context.h index 4861924dac7..3d41042a771 100644 --- a/src/gallium/drivers/nv40/nv40_context.h +++ b/src/gallium/drivers/nv40/nv40_context.h @@ -153,6 +153,7 @@ struct nv40_context { unsigned idxbuf_format; struct nv40_sampler_state *tex_sampler[PIPE_MAX_SAMPLERS]; struct nv40_miptree *tex_miptree[PIPE_MAX_SAMPLERS]; + struct pipe_sampler_view *fragment_sampler_views[PIPE_MAX_SAMPLERS]; unsigned nr_samplers; unsigned nr_textures; unsigned dirty_samplers; diff --git a/src/gallium/drivers/nv40/nv40_state.c b/src/gallium/drivers/nv40/nv40_state.c index 4f28675e64c..dbb52bf5bc9 100644 --- a/src/gallium/drivers/nv40/nv40_state.c +++ b/src/gallium/drivers/nv40/nv40_state.c @@ -282,19 +282,22 @@ nv40_sampler_state_delete(struct pipe_context *pipe, void *hwcso) } static void -nv40_set_sampler_texture(struct pipe_context *pipe, unsigned nr, - struct pipe_texture **miptree) +nv40_set_fragment_sampler_views(struct pipe_context *pipe, + unsigned nr, + struct pipe_sampler_view **views) { struct nv40_context *nv40 = nv40_context(pipe); unsigned unit; for (unit = 0; unit < nr; unit++) { + pipe_sampler_view_reference(&nv40->fragment_sampler_views[unit], views[unit]); pipe_texture_reference((struct pipe_texture **) - &nv40->tex_miptree[unit], miptree[unit]); + &nv40->tex_miptree[unit], views[unit]->texture); nv40->dirty_samplers |= (1 << unit); } for (unit = nr; unit < nv40->nr_textures; unit++) { + pipe_sampler_view_reference(&nv40->fragment_sampler_views[unit], NULL); pipe_texture_reference((struct pipe_texture **) &nv40->tex_miptree[unit], NULL); nv40->dirty_samplers |= (1 << unit); @@ -304,6 +307,31 @@ nv40_set_sampler_texture(struct pipe_context *pipe, unsigned nr, nv40->dirty |= NV40_NEW_SAMPLER; } +static struct pipe_sampler_view * +nv40_create_sampler_view(struct pipe_context *pipe, + struct pipe_texture *texture, + const struct pipe_sampler_view *templ) +{ + struct pipe_sampler_view *view = CALLOC_STRUCT(pipe_sampler_view); + + *view = *templ; + view->reference.count = 1; + view->texture = NULL; + pipe_texture_reference(&view->texture, texture); + view->context = pipe; + + return view; +} + + +static void +nv40_sampler_view_destroy(struct pipe_context *pipe, + struct pipe_sampler_view *view) +{ + pipe_texture_reference(&view->texture, NULL); + FREE(view); +} + static void * nv40_rasterizer_state_create(struct pipe_context *pipe, const struct pipe_rasterizer_state *cso) @@ -707,7 +735,9 @@ nv40_init_state_functions(struct nv40_context *nv40) nv40->pipe.create_sampler_state = nv40_sampler_state_create; nv40->pipe.bind_fragment_sampler_states = nv40_sampler_state_bind; nv40->pipe.delete_sampler_state = nv40_sampler_state_delete; - nv40->pipe.set_fragment_sampler_textures = nv40_set_sampler_texture; + nv40->pipe.set_fragment_sampler_views = nv40_set_fragment_sampler_views; + nv40->pipe.create_sampler_view = nv40_create_sampler_view; + nv40->pipe.sampler_view_destroy = nv40_sampler_view_destroy; nv40->pipe.create_rasterizer_state = nv40_rasterizer_state_create; nv40->pipe.bind_rasterizer_state = nv40_rasterizer_state_bind; -- cgit v1.2.3 From 6a8961a2479288df4ec736f94b8bf990c1fe0d72 Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Thu, 25 Feb 2010 14:56:19 +0100 Subject: nv50: Fix after sampler view changes. Did not test build. --- src/gallium/drivers/nv50/nv50_context.h | 1 + src/gallium/drivers/nv50/nv50_state.c | 61 ++++++++++++++++++++++++++------- 2 files changed, 49 insertions(+), 13 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/nv50/nv50_context.h b/src/gallium/drivers/nv50/nv50_context.h index b4de3e2ba57..7b879851b0e 100644 --- a/src/gallium/drivers/nv50/nv50_context.h +++ b/src/gallium/drivers/nv50/nv50_context.h @@ -173,6 +173,7 @@ struct nv50_context { struct nv50_sampler_stateobj *sampler[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS]; unsigned sampler_nr[PIPE_SHADER_TYPES]; struct nv50_miptree *miptree[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS]; + struct pipe_sampler_view *sampler_views[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS]; unsigned miptree_nr[PIPE_SHADER_TYPES]; uint16_t vbo_fifo; diff --git a/src/gallium/drivers/nv50/nv50_state.c b/src/gallium/drivers/nv50/nv50_state.c index 7d304907b65..8e5f1662eac 100644 --- a/src/gallium/drivers/nv50/nv50_state.c +++ b/src/gallium/drivers/nv50/nv50_state.c @@ -269,33 +269,66 @@ nv50_sampler_state_delete(struct pipe_context *pipe, void *hwcso) } static INLINE void -nv50_set_sampler_texture(struct pipe_context *pipe, unsigned type, - unsigned nr, struct pipe_texture **pt) +nv50_set_sampler_views(struct pipe_context *pipe, + unsigned type, + unsigned nr, + struct pipe_sampler_view **views) { struct nv50_context *nv50 = nv50_context(pipe); unsigned i; - for (i = 0; i < nr; i++) - pipe_texture_reference((void *)&nv50->miptree[type][i], pt[i]); - for (i = nr; i < nv50->miptree_nr[type]; i++) + for (i = 0; i < nr; i++) { + pipe_sampler_view_reference(&nv50->sampler_views[type][i], views[i]); + pipe_texture_reference((void *)&nv50->miptree[type][i], views[i]->texture); + } + for (i = nr; i < nv50->miptree_nr[type]; i++) { + pipe_sampler_view_reference(&nv50->sampler_views[type][i], NULL); pipe_texture_reference((void *)&nv50->miptree[type][i], NULL); + } nv50->miptree_nr[type] = nr; nv50->dirty |= NV50_NEW_TEXTURE; } static void -nv50_set_vp_sampler_textures(struct pipe_context *pipe, - unsigned nr, struct pipe_texture **pt) +nv50_set_vp_sampler_views(struct pipe_context *pipe, + unsigned nr, + struct pipe_sampler_view **views) +{ + nv50_set_sampler_views(pipe, PIPE_SHADER_VERTEX, nr, views); +} + +static void +nv50_set_fp_sampler_views(struct pipe_context *pipe, + unsigned nr, + struct pipe_sampler_view **views) { - nv50_set_sampler_texture(pipe, PIPE_SHADER_VERTEX, nr, pt); + nv50_set_sampler_views(pipe, PIPE_SHADER_FRAGMENT, nr, views); } +static struct pipe_sampler_view * +nv50_create_sampler_view(struct pipe_context *pipe, + struct pipe_texture *texture, + const struct pipe_sampler_view *templ) +{ + struct pipe_sampler_view *view = CALLOC_STRUCT(pipe_sampler_view); + + *view = *templ; + view->reference.count = 1; + view->texture = NULL; + pipe_texture_reference(&view->texture, texture); + view->context = pipe; + + return view; +} + + static void -nv50_set_fp_sampler_textures(struct pipe_context *pipe, - unsigned nr, struct pipe_texture **pt) +nv50_sampler_view_destroy(struct pipe_context *pipe, + struct pipe_sampler_view *view) { - nv50_set_sampler_texture(pipe, PIPE_SHADER_FRAGMENT, nr, pt); + pipe_texture_reference(&view->texture, NULL); + FREE(view); } static void * @@ -743,8 +776,10 @@ nv50_init_state_functions(struct nv50_context *nv50) nv50->pipe.delete_sampler_state = nv50_sampler_state_delete; nv50->pipe.bind_fragment_sampler_states = nv50_fp_sampler_state_bind; nv50->pipe.bind_vertex_sampler_states = nv50_vp_sampler_state_bind; - nv50->pipe.set_fragment_sampler_textures = nv50_set_fp_sampler_textures; - nv50->pipe.set_vertex_sampler_textures = nv50_set_vp_sampler_textures; + nv50->pipe.set_fragment_sampler_views = nv50_set_fp_sampler_views; + nv50->pipe.set_vertex_sampler_views = nv50_set_vp_sampler_views; + nv50->pipe.create_sampler_view = nv50_create_sampler_view; + nv50->pipe.sampler_view_destroy = nv50_sampler_view_destroy; nv50->pipe.create_rasterizer_state = nv50_rasterizer_state_create; nv50->pipe.bind_rasterizer_state = nv50_rasterizer_state_bind; -- cgit v1.2.3 From 9aeb206e17181dfba4a40a41dbfc11560269e942 Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Thu, 25 Feb 2010 15:16:18 +0100 Subject: cell: Fix after sampler view changes. Did not test build. --- src/gallium/drivers/cell/ppu/cell_context.h | 1 + src/gallium/drivers/cell/ppu/cell_pipe_state.c | 45 ++++++++++++++++++++++---- 2 files changed, 40 insertions(+), 6 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/cell/ppu/cell_context.h b/src/gallium/drivers/cell/ppu/cell_context.h index a77cc5b9067..0724da9a7aa 100644 --- a/src/gallium/drivers/cell/ppu/cell_context.h +++ b/src/gallium/drivers/cell/ppu/cell_context.h @@ -121,6 +121,7 @@ struct cell_context struct pipe_poly_stipple poly_stipple; struct pipe_scissor_state scissor; struct cell_texture *texture[PIPE_MAX_SAMPLERS]; + struct pipe_sampler_view *fragment_sampler_views[PIPE_MAX_SAMPLERS]; uint num_textures; struct pipe_viewport_state viewport; struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS]; diff --git a/src/gallium/drivers/cell/ppu/cell_pipe_state.c b/src/gallium/drivers/cell/ppu/cell_pipe_state.c index 3d8b4409c75..e1cf9dbbee8 100644 --- a/src/gallium/drivers/cell/ppu/cell_pipe_state.c +++ b/src/gallium/drivers/cell/ppu/cell_pipe_state.c @@ -257,8 +257,9 @@ cell_delete_sampler_state(struct pipe_context *pipe, static void -cell_set_sampler_textures(struct pipe_context *pipe, - unsigned num, struct pipe_texture **texture) +cell_set_fragment_sampler_views(struct pipe_context *pipe, + unsigned num, + struct pipe_sampler_view **views) { struct cell_context *cell = cell_context(pipe); uint i, changed = 0x0; @@ -266,10 +267,14 @@ cell_set_sampler_textures(struct pipe_context *pipe, assert(num <= CELL_MAX_SAMPLERS); for (i = 0; i < CELL_MAX_SAMPLERS; i++) { - struct cell_texture *new_tex = cell_texture(i < num ? texture[i] : NULL); - struct cell_texture *old_tex = cell->texture[i]; - if (old_tex != new_tex) { + struct pipe_sampler_view *new_view = i < num ? views[i] : NULL; + struct pipe_sampler_view *old_view = cell->fragment_sampler_views[i]; + if (old_view != new_view) { + struct pipe_texture *new_tex = new_view ? new_view->texture : NULL; + + pipe_sampler_view_reference(&cell->fragment_sampler_views[i], + views[i]); pipe_texture_reference((struct pipe_texture **) &cell->texture[i], (struct pipe_texture *) new_tex); @@ -286,6 +291,32 @@ cell_set_sampler_textures(struct pipe_context *pipe, } +static struct pipe_sampler_view * +cell_create_sampler_view(struct pipe_context *pipe, + struct pipe_texture *texture, + const struct pipe_sampler_view *templ) +{ + struct pipe_sampler_view *view = CALLOC_STRUCT(pipe_sampler_view); + + *view = *templ; + view->reference.count = 1; + view->texture = NULL; + pipe_texture_reference(&view->texture, texture); + view->context = pipe; + + return view; +} + + +static void +cell_sampler_view_destroy(struct pipe_context *pipe, + struct pipe_sampler_view *view) +{ + pipe_texture_reference(&view->texture, NULL); + FREE(view); +} + + /** * Map color and z/stencil framebuffer surfaces. */ @@ -399,7 +430,9 @@ cell_init_state_functions(struct cell_context *cell) cell->pipe.bind_fragment_sampler_states = cell_bind_sampler_states; cell->pipe.delete_sampler_state = cell_delete_sampler_state; - cell->pipe.set_fragment_sampler_textures = cell_set_sampler_textures; + cell->pipe.set_fragment_sampler_views = cell_set_fragment_sampler_views; + cell->pipe.create_sampler_view = cell_create_sampler_view; + cell->pipe.sampler_view_destroy = cell_sampler_view_destroy; cell->pipe.create_depth_stencil_alpha_state = cell_create_depth_stencil_alpha_state; cell->pipe.bind_depth_stencil_alpha_state = cell_bind_depth_stencil_alpha_state; -- cgit v1.2.3 From e81caade02a51da65eb28eba6816503305a97920 Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Thu, 25 Feb 2010 15:33:15 +0100 Subject: docs: Document sampler view entry points. --- src/gallium/docs/source/context.rst | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/docs/source/context.rst b/src/gallium/docs/source/context.rst index 827db8398ce..2d495f5d0e7 100644 --- a/src/gallium/docs/source/context.rst +++ b/src/gallium/docs/source/context.rst @@ -39,10 +39,24 @@ buffers, surfaces) are bound to the driver. are mostly restricted to the first one right now). * ``set_framebuffer_state`` -* ``set_fragment_sampler_views`` -* ``set_vertex_sampler_views`` -* ``create_sampler_view`` -* ``sampler_view_destroy`` + +* ``set_fragment_sampler_views`` binds an array of sampler views to + fragment shader stage. Every binding point acquires a reference + to a respective sampler view and releases a reference to the previous + sampler view. + +* ``set_vertex_sampler_views`` binds an array of sampler views to vertex + shader stage. Every binding point acquires a reference to a respective + sampler view and releases a reference to the previous sampler view. + +* ``create_sampler_view`` creates a new sampler view. texture is associated + with the sampler view which results in sampler view holding a reference + to the texture. Format specified in template must be compatible + with texture format. + +* ``sampler_view_destroy`` destroys a sampler view and releases its reference + to associated texture. + * ``set_vertex_buffers`` -- cgit v1.2.3 From 9960b3ed4b9a7b6eb92245820bdffdf5f70470a6 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Thu, 25 Feb 2010 08:04:29 -0700 Subject: gallium: added util/u_sampler.c to Makefile --- src/gallium/auxiliary/Makefile | 1 + 1 file changed, 1 insertion(+) (limited to 'src/gallium') diff --git a/src/gallium/auxiliary/Makefile b/src/gallium/auxiliary/Makefile index ec986355140..75dfd965afa 100644 --- a/src/gallium/auxiliary/Makefile +++ b/src/gallium/auxiliary/Makefile @@ -118,6 +118,7 @@ C_SOURCES = \ util/u_mm.c \ util/u_rect.c \ util/u_ringbuffer.c \ + util/u_sampler.c \ util/u_simple_shaders.c \ util/u_snprintf.c \ util/u_surface.c \ -- cgit v1.2.3 From 013dd29cca9b90555b7481a81ea1727fb7cea28b Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Thu, 25 Feb 2010 08:05:53 -0700 Subject: gallium/util: rewrap comment to fit in 80 columns --- src/gallium/auxiliary/util/u_sampler.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/auxiliary/util/u_sampler.c b/src/gallium/auxiliary/util/u_sampler.c index 3e45a2fa70d..08cf1fcf223 100644 --- a/src/gallium/auxiliary/util/u_sampler.c +++ b/src/gallium/auxiliary/util/u_sampler.c @@ -47,15 +47,18 @@ default_template(struct pipe_sampler_view *view, view->swizzle_b = PIPE_SWIZZLE_BLUE; view->swizzle_a = PIPE_SWIZZLE_ALPHA; - /* Override default green and blue component expansion to the requested one. + /* Override default green and blue component expansion to the requested + * one. * - * Gallium expands nonexistent components to (0,0,0,1), DX9 expands to (1,1,1,1). - * Since alpha is always expanded to 1, and red is always present, we only really - * care about green and blue components. + * Gallium expands nonexistent components to (0,0,0,1), DX9 expands + * to (1,1,1,1). Since alpha is always expanded to 1, and red is + * always present, we only really care about green and blue + * components. * - * To make it look less hackish, one would have to add UTIL_FORMAT_SWIZZLE_EXPAND - * to indicate components for expansion and then override without exceptions or - * favoring one component over another. + * To make it look less hackish, one would have to add + * UTIL_FORMAT_SWIZZLE_EXPAND to indicate components for expansion + * and then override without exceptions or favoring one component + * over another. */ if (format != PIPE_FORMAT_A8_UNORM) { const struct util_format_description *desc = util_format_description(format); -- cgit v1.2.3 From 44570063bf8a4f45807bc1598c8de291cdc64506 Mon Sep 17 00:00:00 2001 From: Christoph Bumiller Date: Thu, 25 Feb 2010 16:39:58 +0100 Subject: nv50: update to handle new sampler view state --- src/gallium/drivers/nv50/nv50_context.h | 23 ++- src/gallium/drivers/nv50/nv50_screen.c | 6 +- src/gallium/drivers/nv50/nv50_state.c | 64 +++++---- src/gallium/drivers/nv50/nv50_state_validate.c | 4 +- src/gallium/drivers/nv50/nv50_tex.c | 189 ++++++++++++++----------- src/gallium/drivers/nv50/nv50_texture.h | 32 ++++- 6 files changed, 188 insertions(+), 130 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/nv50/nv50_context.h b/src/gallium/drivers/nv50/nv50_context.h index 7b879851b0e..42405c1a890 100644 --- a/src/gallium/drivers/nv50/nv50_context.h +++ b/src/gallium/drivers/nv50/nv50_context.h @@ -72,6 +72,17 @@ struct nv50_sampler_stateobj { unsigned tsc[8]; }; +struct nv50_sampler_view { + struct pipe_sampler_view pipe; + uint32_t tic[8]; +}; + +static INLINE struct nv50_sampler_view * +nv50_sampler_view(struct pipe_sampler_view *view) +{ + return (struct nv50_sampler_view *)view; +} + static INLINE unsigned get_tile_height(uint32_t tile_mode) { @@ -130,7 +141,7 @@ struct nv50_state { unsigned viewport_bypass; struct nouveau_stateobj *tsc_upload; struct nouveau_stateobj *tic_upload; - unsigned miptree_nr[PIPE_SHADER_TYPES]; + unsigned sampler_view_nr[3]; struct nouveau_stateobj *vertprog; struct nouveau_stateobj *fragprog; struct nouveau_stateobj *geomprog; @@ -170,11 +181,10 @@ struct nv50_context { unsigned vtxbuf_nr; struct pipe_vertex_element vtxelt[PIPE_MAX_ATTRIBS]; unsigned vtxelt_nr; - struct nv50_sampler_stateobj *sampler[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS]; - unsigned sampler_nr[PIPE_SHADER_TYPES]; - struct nv50_miptree *miptree[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS]; - struct pipe_sampler_view *sampler_views[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS]; - unsigned miptree_nr[PIPE_SHADER_TYPES]; + struct nv50_sampler_stateobj *sampler[3][PIPE_MAX_SAMPLERS]; + unsigned sampler_nr[3]; + struct pipe_sampler_view *sampler_views[3][PIPE_MAX_SAMPLERS]; + unsigned sampler_view_nr[3]; uint16_t vbo_fifo; }; @@ -244,6 +254,7 @@ extern void nv50_so_init_sifc(struct nv50_context *nv50, /* nv50_tex.c */ extern void nv50_tex_validate(struct nv50_context *); +extern boolean nv50_tex_construct(struct nv50_sampler_view *view); /* nv50_transfer.c */ extern void diff --git a/src/gallium/drivers/nv50/nv50_screen.c b/src/gallium/drivers/nv50/nv50_screen.c index 2232461b9b6..ee54749443c 100644 --- a/src/gallium/drivers/nv50/nv50_screen.c +++ b/src/gallium/drivers/nv50/nv50_screen.c @@ -464,7 +464,7 @@ nv50_screen_create(struct pipe_winsys *ws, struct nouveau_device *dev) so_method(so, screen->tesla, NV50TCL_SET_PROGRAM_CB, 1); so_data (so, 0x00000131 | (NV50_CB_PFP << 12)); - ret = nouveau_bo_new(dev, NOUVEAU_BO_VRAM, 0, PIPE_SHADER_TYPES*32*32, + ret = nouveau_bo_new(dev, NOUVEAU_BO_VRAM, 0, 3 * 32 * (8 * 4), &screen->tic); if (ret) { nv50_screen_destroy(pscreen); @@ -476,9 +476,9 @@ nv50_screen_create(struct pipe_winsys *ws, struct nouveau_device *dev) NOUVEAU_BO_RD | NOUVEAU_BO_HIGH, 0, 0); so_reloc (so, screen->tic, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_RD | NOUVEAU_BO_LOW, 0, 0); - so_data (so, PIPE_SHADER_TYPES * 32 - 1); + so_data (so, 3 * 32 - 1); - ret = nouveau_bo_new(dev, NOUVEAU_BO_VRAM, 0, PIPE_SHADER_TYPES*32*32, + ret = nouveau_bo_new(dev, NOUVEAU_BO_VRAM, 0, 3 * 32 * (8 * 4), &screen->tsc); if (ret) { nv50_screen_destroy(pscreen); diff --git a/src/gallium/drivers/nv50/nv50_state.c b/src/gallium/drivers/nv50/nv50_state.c index 8e5f1662eac..dd457c0f00f 100644 --- a/src/gallium/drivers/nv50/nv50_state.c +++ b/src/gallium/drivers/nv50/nv50_state.c @@ -238,6 +238,9 @@ nv50_sampler_state_create(struct pipe_context *pipe, return (void *)sso; } +/* type == 0 for VPs, 1 for GPs, 2 for FPs, which is how the + * relevant tesla methods are indexed (NV50TCL_BIND_TSC etc.) + */ static INLINE void nv50_sampler_state_bind(struct pipe_context *pipe, unsigned type, unsigned nr, void **sampler) @@ -253,13 +256,13 @@ nv50_sampler_state_bind(struct pipe_context *pipe, unsigned type, static void nv50_vp_sampler_state_bind(struct pipe_context *pipe, unsigned nr, void **s) { - nv50_sampler_state_bind(pipe, PIPE_SHADER_VERTEX, nr, s); + nv50_sampler_state_bind(pipe, 0, nr, s); } static void nv50_fp_sampler_state_bind(struct pipe_context *pipe, unsigned nr, void **s) { - nv50_sampler_state_bind(pipe, PIPE_SHADER_FRAGMENT, nr, s); + nv50_sampler_state_bind(pipe, 2, nr, s); } static void @@ -269,24 +272,21 @@ nv50_sampler_state_delete(struct pipe_context *pipe, void *hwcso) } static INLINE void -nv50_set_sampler_views(struct pipe_context *pipe, - unsigned type, +nv50_set_sampler_views(struct pipe_context *pipe, unsigned p, unsigned nr, struct pipe_sampler_view **views) { struct nv50_context *nv50 = nv50_context(pipe); unsigned i; - for (i = 0; i < nr; i++) { - pipe_sampler_view_reference(&nv50->sampler_views[type][i], views[i]); - pipe_texture_reference((void *)&nv50->miptree[type][i], views[i]->texture); - } - for (i = nr; i < nv50->miptree_nr[type]; i++) { - pipe_sampler_view_reference(&nv50->sampler_views[type][i], NULL); - pipe_texture_reference((void *)&nv50->miptree[type][i], NULL); - } + for (i = 0; i < nr; i++) + pipe_sampler_view_reference(&nv50->sampler_views[p][i], + views[i]); - nv50->miptree_nr[type] = nr; + for (i = nr; i < nv50->sampler_view_nr[p]; i++) + pipe_sampler_view_reference(&nv50->sampler_views[p][i], NULL); + + nv50->sampler_view_nr[p] = nr; nv50->dirty |= NV50_NEW_TEXTURE; } @@ -295,7 +295,7 @@ nv50_set_vp_sampler_views(struct pipe_context *pipe, unsigned nr, struct pipe_sampler_view **views) { - nv50_set_sampler_views(pipe, PIPE_SHADER_VERTEX, nr, views); + nv50_set_sampler_views(pipe, 0, nr, views); } static void @@ -303,7 +303,15 @@ nv50_set_fp_sampler_views(struct pipe_context *pipe, unsigned nr, struct pipe_sampler_view **views) { - nv50_set_sampler_views(pipe, PIPE_SHADER_FRAGMENT, nr, views); + nv50_set_sampler_views(pipe, 2, nr, views); +} + +static void +nv50_sampler_view_destroy(struct pipe_context *pipe, + struct pipe_sampler_view *view) +{ + pipe_texture_reference(&view->texture, NULL); + FREE(nv50_sampler_view(view)); } static struct pipe_sampler_view * @@ -311,26 +319,22 @@ nv50_create_sampler_view(struct pipe_context *pipe, struct pipe_texture *texture, const struct pipe_sampler_view *templ) { - struct pipe_sampler_view *view = CALLOC_STRUCT(pipe_sampler_view); + struct nv50_sampler_view *view = CALLOC_STRUCT(nv50_sampler_view); - *view = *templ; - view->reference.count = 1; - view->texture = NULL; - pipe_texture_reference(&view->texture, texture); - view->context = pipe; + view->pipe = *templ; + view->pipe.reference.count = 1; + view->pipe.texture = NULL; + pipe_texture_reference(&view->pipe.texture, texture); + view->pipe.context = pipe; - return view; + if (!nv50_tex_construct(view)) { + nv50_sampler_view_destroy(pipe, &view->pipe); + return NULL; + } + return &view->pipe; } -static void -nv50_sampler_view_destroy(struct pipe_context *pipe, - struct pipe_sampler_view *view) -{ - pipe_texture_reference(&view->texture, NULL); - FREE(view); -} - static void * nv50_rasterizer_state_create(struct pipe_context *pipe, const struct pipe_rasterizer_state *cso) diff --git a/src/gallium/drivers/nv50/nv50_state_validate.c b/src/gallium/drivers/nv50/nv50_state_validate.c index efab94cab74..741f8e8f59d 100644 --- a/src/gallium/drivers/nv50/nv50_state_validate.c +++ b/src/gallium/drivers/nv50/nv50_state_validate.c @@ -436,8 +436,8 @@ viewport_uptodate: 1 + 19 * PIPE_SHADER_TYPES + nr * 8, PIPE_SHADER_TYPES * 2); - nv50_validate_samplers(nv50, so, PIPE_SHADER_VERTEX); - nv50_validate_samplers(nv50, so, PIPE_SHADER_FRAGMENT); + nv50_validate_samplers(nv50, so, 0); /* VP samplers */ + nv50_validate_samplers(nv50, so, 2); /* FP samplers */ so_method(so, tesla, 0x1334, 1); /* flush TSC */ so_data (so, 0); diff --git a/src/gallium/drivers/nv50/nv50_tex.c b/src/gallium/drivers/nv50/nv50_tex.c index 9f1a1713032..2f2ebc8ec43 100644 --- a/src/gallium/drivers/nv50/nv50_tex.c +++ b/src/gallium/drivers/nv50/nv50_tex.c @@ -28,26 +28,16 @@ #include "util/u_format.h" #define _MIXED(pf, t0, t1, t2, t3, cr, cg, cb, ca, f) \ -{ \ - PIPE_FORMAT_##pf, \ +[PIPE_FORMAT_##pf] = ( \ NV50TIC_0_0_MAPR_##cr | NV50TIC_0_0_TYPER_##t0 | \ NV50TIC_0_0_MAPG_##cg | NV50TIC_0_0_TYPEG_##t1 | \ NV50TIC_0_0_MAPB_##cb | NV50TIC_0_0_TYPEB_##t2 | \ NV50TIC_0_0_MAPA_##ca | NV50TIC_0_0_TYPEA_##t3 | \ - NV50TIC_0_0_FMT_##f \ -} + NV50TIC_0_0_FMT_##f) #define _(pf, t, cr, cg, cb, ca, f) _MIXED(pf, t, t, t, t, cr, cg, cb, ca, f) -struct nv50_texture_format { - enum pipe_format pf; - uint32_t hw; -}; - -#define NV50_TEX_FORMAT_LIST_SIZE \ - (sizeof(nv50_tex_format_list) / sizeof(struct nv50_texture_format)) - -static const struct nv50_texture_format nv50_tex_format_list[] = +static const uint32_t nv50_texture_formats[PIPE_FORMAT_COUNT] = { _(A8R8G8B8_UNORM, UNORM, C2, C1, C0, C3, 8_8_8_8), _(A8R8G8B8_SRGB, UNORM, C2, C1, C0, C3, 8_8_8_8), @@ -59,10 +49,12 @@ static const struct nv50_texture_format nv50_tex_format_list[] = _(R5G6B5_UNORM, UNORM, C2, C1, C0, ONE, 5_6_5), _(L8_UNORM, UNORM, C0, C0, C0, ONE, 8), + _(L8_SRGB, UNORM, C0, C0, C0, ONE, 8), _(A8_UNORM, UNORM, ZERO, ZERO, ZERO, C0, 8), _(I8_UNORM, UNORM, C0, C0, C0, C0, 8), _(A8L8_UNORM, UNORM, C0, C0, C0, C1, 8_8), + _(A8L8_SRGB, UNORM, C0, C0, C0, C1, 8_8), _(DXT1_RGB, UNORM, C0, C1, C2, ONE, DXT1), _(DXT1_RGBA, UNORM, C0, C1, C2, C3, DXT1), @@ -80,117 +72,144 @@ static const struct nv50_texture_format nv50_tex_format_list[] = _(R16G16_UNORM, UNORM, C0, C1, ZERO, ONE, 16_16), _MIXED(Z32_FLOAT, FLOAT, UINT, UINT, UINT, C0, C0, C0, ONE, 32_DEPTH) - }; #undef _ #undef _MIXED -static int -nv50_tex_construct(struct nv50_context *nv50, struct nouveau_stateobj *so, - struct nv50_miptree *mt, int unit, unsigned p) +static INLINE uint32_t +nv50_tic_swizzle(uint32_t tc, unsigned swz) +{ + switch (swz) { + case PIPE_SWIZZLE_RED: + return (tc & NV50TIC_0_0_MAPR_MASK) >> NV50TIC_0_0_MAPR_SHIFT; + case PIPE_SWIZZLE_GREEN: + return (tc & NV50TIC_0_0_MAPG_MASK) >> NV50TIC_0_0_MAPG_SHIFT; + case PIPE_SWIZZLE_BLUE: + return (tc & NV50TIC_0_0_MAPB_MASK) >> NV50TIC_0_0_MAPB_SHIFT; + case PIPE_SWIZZLE_ALPHA: + return (tc & NV50TIC_0_0_MAPA_MASK) >> NV50TIC_0_0_MAPA_SHIFT; + case PIPE_SWIZZLE_ONE: + return 7; + case PIPE_SWIZZLE_ZERO: + default: + return 0; + } +} + +boolean +nv50_tex_construct(struct nv50_sampler_view *view) { - unsigned i; - uint32_t mode; const struct util_format_description *desc; + struct nv50_miptree *mt = nv50_miptree(view->pipe.texture); + uint32_t swz[4], *tic = view->tic; - for (i = 0; i < NV50_TEX_FORMAT_LIST_SIZE; i++) - if (nv50_tex_format_list[i].pf == mt->base.base.format) - break; - if (i == NV50_TEX_FORMAT_LIST_SIZE) - return 1; - - if (nv50->sampler[p][unit]->normalized) - mode = 0x50001000 | (1 << 31); - else { - mode = 0x50001000 | (7 << 14); - assert(mt->base.base.target == PIPE_TEXTURE_2D); - } + tic[0] = nv50_texture_formats[mt->base.base.format]; - mode |= ((mt->base.bo->tile_mode & 0x0f) << 22) | - ((mt->base.bo->tile_mode & 0xf0) << 21); + swz[0] = nv50_tic_swizzle(tic[0], view->pipe.swizzle_r); + swz[1] = nv50_tic_swizzle(tic[0], view->pipe.swizzle_g); + swz[2] = nv50_tic_swizzle(tic[0], view->pipe.swizzle_b); + swz[3] = nv50_tic_swizzle(tic[0], view->pipe.swizzle_a); + view->tic[0] = (tic[0] & ~NV50TIC_0_0_SWIZZLE_MASK) | + (swz[0] << NV50TIC_0_0_MAPR_SHIFT) | + (swz[1] << NV50TIC_0_0_MAPG_SHIFT) | + (swz[2] << NV50TIC_0_0_MAPB_SHIFT) | + (swz[3] << NV50TIC_0_0_MAPA_SHIFT); - desc = util_format_description(mt->base.base.format); - assert(desc); + tic[2] = 0x50001000; + tic[2] |= ((mt->base.bo->tile_mode & 0x0f) << 22) | + ((mt->base.bo->tile_mode & 0xf0) << 21); + desc = util_format_description(mt->base.base.format); if (desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB) - mode |= 0x0400; + tic[2] |= NV50TIC_0_2_COLORSPACE_SRGB; switch (mt->base.base.target) { case PIPE_TEXTURE_1D: + tic[2] |= NV50TIC_0_2_TARGET_1D; break; case PIPE_TEXTURE_2D: - mode |= (1 << 14); + tic[2] |= NV50TIC_0_2_TARGET_2D; break; case PIPE_TEXTURE_3D: - mode |= (2 << 14); + tic[2] |= NV50TIC_0_2_TARGET_3D; break; case PIPE_TEXTURE_CUBE: - mode |= (3 << 14); + tic[2] |= NV50TIC_0_2_TARGET_CUBE; break; default: - assert(!"unsupported texture target"); - break; + NOUVEAU_ERR("invalid texture target: %d\n", + mt->base.base.target); + return FALSE; } - so_data (so, nv50_tex_format_list[i].hw); - so_reloc(so, mt->base.bo, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_LOW | - NOUVEAU_BO_RD, 0, 0); - so_data (so, mode); - so_data (so, 0x00300000); - so_data (so, mt->base.base.width0 | (1 << 31)); - so_data (so, (mt->base.base.last_level << 28) | - (mt->base.base.depth0 << 16) | mt->base.base.height0); - so_data (so, 0x03000000); - so_data (so, mt->base.base.last_level << 4); - - return 0; -} + tic[3] = 0x00300000; + + tic[4] = (1 << 31) | mt->base.base.width0; + tic[5] = (mt->base.base.last_level << 28) | + (mt->base.base.depth0 << 16) | mt->base.base.height0; + + tic[6] = 0x03000000; -#ifndef NV50TCL_BIND_TIC -#define NV50TCL_BIND_TIC(n) (0x1448 + 8 * n) -#endif + tic[7] = (view->pipe.num_levels - view->pipe.first_level - 1) << 4; + tic[7] |= view->pipe.first_level; + + return TRUE; +} -static boolean +static int nv50_validate_textures(struct nv50_context *nv50, struct nouveau_stateobj *so, unsigned p) { - static const unsigned p_remap[PIPE_SHADER_TYPES] = { 0, 2, 1 }; - struct nouveau_grobj *eng2d = nv50->screen->eng2d; struct nouveau_grobj *tesla = nv50->screen->tesla; - unsigned unit, j, p_hw = p_remap[p]; + unsigned unit, j; + + const unsigned rll = NOUVEAU_BO_VRAM | NOUVEAU_BO_RD | NOUVEAU_BO_LOW; + const unsigned rlh = NOUVEAU_BO_VRAM | NOUVEAU_BO_RD | NOUVEAU_BO_HIGH + | NOUVEAU_BO_OR; nv50_so_init_sifc(nv50, so, nv50->screen->tic, NOUVEAU_BO_VRAM, - p * (32 * 8 * 4), nv50->miptree_nr[p] * 8 * 4); + p * (32 * 8 * 4), nv50->sampler_view_nr[p] * 8 * 4); - for (unit = 0; unit < nv50->miptree_nr[p]; ++unit) { - struct nv50_miptree *mt = nv50->miptree[p][unit]; + for (unit = 0; unit < nv50->sampler_view_nr[p]; ++unit) { + struct nv50_sampler_view *view = + nv50_sampler_view(nv50->sampler_views[p][unit]); so_method(so, eng2d, NV50_2D_SIFC_DATA | (2 << 29), 8); - if (mt) { - if (nv50_tex_construct(nv50, so, mt, unit, p)) - return FALSE; + if (view) { + uint32_t tic2 = view->tic[2]; + struct nv50_miptree *mt = + nv50_miptree(view->pipe.texture); + + if (nv50->sampler[p][unit]->normalized) + tic2 |= NV50TIC_0_2_NORMALIZED_COORDS; + + so_data (so, view->tic[0]); + so_reloc (so, mt->base.bo, 0, rll, 0, 0); + so_reloc (so, mt->base.bo, 0, rlh, tic2, tic2); + so_datap (so, &view->tic[3], 5); + /* Set TEX insn $t src binding $unit in program type p * to TIC, TSC entry (32 * p + unit), mark valid (1). */ - so_method(so, tesla, NV50TCL_BIND_TIC(p_hw), 1); + so_method(so, tesla, NV50TCL_BIND_TIC(p), 1); so_data (so, ((32 * p + unit) << 9) | (unit << 1) | 1); } else { for (j = 0; j < 8; ++j) so_data(so, 0); - so_method(so, tesla, NV50TCL_BIND_TIC(p_hw), 1); + so_method(so, tesla, NV50TCL_BIND_TIC(p), 1); so_data (so, (unit << 1) | 0); } } - for (; unit < nv50->state.miptree_nr[p]; unit++) { + for (; unit < nv50->state.sampler_view_nr[p]; unit++) { /* Make other bindings invalid. */ - so_method(so, tesla, NV50TCL_BIND_TIC(p_hw), 1); + so_method(so, tesla, NV50TCL_BIND_TIC(p), 1); so_data (so, (unit << 1) | 0); } - nv50->state.miptree_nr[p] = nv50->miptree_nr[p]; + nv50->state.sampler_view_nr[p] = nv50->sampler_view_nr[p]; return TRUE; } @@ -199,21 +218,23 @@ nv50_tex_validate(struct nv50_context *nv50) { struct nouveau_stateobj *so; struct nouveau_grobj *tesla = nv50->screen->tesla; - unsigned p, start, push, nrlc; - - for (nrlc = 0, start = 0, push = 0, p = 0; p < PIPE_SHADER_TYPES; ++p) { - start += MAX2(nv50->miptree_nr[p], nv50->state.miptree_nr[p]); - push += MAX2(nv50->miptree_nr[p], nv50->state.miptree_nr[p]); - nrlc += nv50->miptree_nr[p]; + unsigned p, m = 0, d = 0, r = 0; + + for (p = 0; p < 3; ++p) { + unsigned nr = MAX2(nv50->sampler_view_nr[p], + nv50->state.sampler_view_nr[p]); + m += nr; + d += nr; + r += nv50->sampler_view_nr[p]; } - start = start * 2 + 4 * PIPE_SHADER_TYPES + 2; - push = push * 9 + 19 * PIPE_SHADER_TYPES + 2; - nrlc = nrlc * 2 + 2 * PIPE_SHADER_TYPES; + m = m * 2 + 3 * 4 + 1; + d = d * 9 + 3 * 19 + 1; + r = r * 2 + 3 * 2; - so = so_new(start, push, nrlc); + so = so_new(m, d, r); - if (nv50_validate_textures(nv50, so, PIPE_SHADER_VERTEX) == FALSE || - nv50_validate_textures(nv50, so, PIPE_SHADER_FRAGMENT) == FALSE) { + if (nv50_validate_textures(nv50, so, 0) == FALSE || + nv50_validate_textures(nv50, so, 2) == FALSE) { so_ref(NULL, &so); NOUVEAU_ERR("failed tex validate\n"); diff --git a/src/gallium/drivers/nv50/nv50_texture.h b/src/gallium/drivers/nv50/nv50_texture.h index b870302019a..3475d3e4326 100644 --- a/src/gallium/drivers/nv50/nv50_texture.h +++ b/src/gallium/drivers/nv50/nv50_texture.h @@ -7,7 +7,9 @@ */ /* Texture image control block */ +#define NV50TIC_0_0_SWIZZLE_MASK 0x3ffc0000 #define NV50TIC_0_0_MAPA_MASK 0x38000000 +#define NV50TIC_0_0_MAPA_SHIFT 27 #define NV50TIC_0_0_MAPA_ZERO 0x00000000 #define NV50TIC_0_0_MAPA_C0 0x10000000 #define NV50TIC_0_0_MAPA_C1 0x18000000 @@ -15,6 +17,7 @@ #define NV50TIC_0_0_MAPA_C3 0x28000000 #define NV50TIC_0_0_MAPA_ONE 0x38000000 #define NV50TIC_0_0_MAPB_MASK 0x07000000 +#define NV50TIC_0_0_MAPB_SHIFT 24 #define NV50TIC_0_0_MAPB_ZERO 0x00000000 #define NV50TIC_0_0_MAPB_C0 0x02000000 #define NV50TIC_0_0_MAPB_C1 0x03000000 @@ -22,6 +25,7 @@ #define NV50TIC_0_0_MAPB_C3 0x05000000 #define NV50TIC_0_0_MAPB_ONE 0x07000000 #define NV50TIC_0_0_MAPG_MASK 0x00e00000 +#define NV50TIC_0_0_MAPG_SHIFT 21 #define NV50TIC_0_0_MAPG_ZERO 0x00000000 #define NV50TIC_0_0_MAPG_C0 0x00400000 #define NV50TIC_0_0_MAPG_C1 0x00600000 @@ -29,6 +33,7 @@ #define NV50TIC_0_0_MAPG_C3 0x00a00000 #define NV50TIC_0_0_MAPG_ONE 0x00e00000 #define NV50TIC_0_0_MAPR_MASK 0x001c0000 +#define NV50TIC_0_0_MAPR_SHIFT 18 #define NV50TIC_0_0_MAPR_ZERO 0x00000000 #define NV50TIC_0_0_MAPR_C0 0x00080000 #define NV50TIC_0_0_MAPR_C1 0x000c0000 @@ -89,22 +94,39 @@ #define NV50TIC_0_1_OFFSET_LOW_MASK 0xffffffff #define NV50TIC_0_1_OFFSET_LOW_SHIFT 0 -#define NV50TIC_0_2_UNKNOWN_MASK 0xffffffff +#define NV50TIC_0_2_COLORSPACE_SRGB 0x00000400 +#define NV50TIC_0_2_TARGET_1D 0x00000000 +#define NV50TIC_0_2_TARGET_2D 0x00004000 +#define NV50TIC_0_2_TARGET_3D 0x00008000 +#define NV50TIC_0_2_TARGET_CUBE 0x0000c000 +#define NV50TIC_0_2_TARGET_1D_ARRAY 0x00010000 +#define NV50TIC_0_2_TARGET_2D_ARRAY 0x00014000 +#define NV50TIC_0_2_TARGET_BUFFER 0x00018000 +#define NV50TIC_0_2_TARGET_RECT 0x0001c000 +/* #define NV50TIC_0_0_TILE_MODE_LINEAR 0x00040000 */ +#define NV50TIC_0_2_TILE_MODE_Y_MASK 0x01c00000 +#define NV50TIC_0_2_TILE_MODE_Y_SHIFT 22 +#define NV50TIC_0_2_TILE_MODE_Z_MASK 0x0e000000 +#define NV50TIC_0_2_TILE_MODE_Z_SHIFT 25 +#define NV50TIC_0_2_NORMALIZED_COORDS 0x80000000 #define NV50TIC_0_3_UNKNOWN_MASK 0xffffffff #define NV50TIC_0_4_WIDTH_MASK 0x0000ffff #define NV50TIC_0_4_WIDTH_SHIFT 0 -#define NV50TIC_0_5_DEPTH_MASK 0xffff0000 +#define NV50TIC_0_5_LAST_LEVEL_MASK 0xf0000000 +#define NV50TIC_0_5_LAST_LEVEL_SHIFT 28 +#define NV50TIC_0_5_DEPTH_MASK 0x0fff0000 #define NV50TIC_0_5_DEPTH_SHIFT 16 #define NV50TIC_0_5_HEIGHT_MASK 0x0000ffff #define NV50TIC_0_5_HEIGHT_SHIFT 0 - #define NV50TIC_0_6_UNKNOWN_MASK 0xffffffff -#define NV50TIC_0_7_OFFSET_HIGH_MASK 0xffffffff -#define NV50TIC_0_7_OFFSET_HIGH_SHIFT 0 +#define NV50TIC_0_7_BASE_LEVEL_MASK 0x0000000f +#define NV50TIC_0_7_BASE_LEVEL_SHIFT 0 +#define NV50TIC_0_7_MAX_LEVEL_MASK 0x000000f0 +#define NV50TIC_0_7_MAX_LEVEL_SHIFT 4 /* Texture sampler control block */ #define NV50TSC_1_0_WRAPS_MASK 0x00000007 -- cgit v1.2.3 From a69fdb84df17dd91cbfd41fc90a54558cb334297 Mon Sep 17 00:00:00 2001 From: Christoph Bumiller Date: Thu, 25 Feb 2010 16:43:01 +0100 Subject: nv30: function is called nv30_set_fragment_sampler_views, plural --- src/gallium/drivers/nv30/nv30_state.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/nv30/nv30_state.c b/src/gallium/drivers/nv30/nv30_state.c index 1d484ecb77f..fdfb51a9b34 100644 --- a/src/gallium/drivers/nv30/nv30_state.c +++ b/src/gallium/drivers/nv30/nv30_state.c @@ -720,7 +720,7 @@ nv30_init_state_functions(struct nv30_context *nv30) nv30->pipe.create_sampler_state = nv30_sampler_state_create; nv30->pipe.bind_fragment_sampler_states = nv30_sampler_state_bind; nv30->pipe.delete_sampler_state = nv30_sampler_state_delete; - nv30->pipe.set_fragment_sampler_views = nv30_set_fragment_sampler_view; + nv30->pipe.set_fragment_sampler_views = nv30_set_fragment_sampler_views; nv30->pipe.create_sampler_view = nv30_create_sampler_view; nv30->pipe.sampler_view_destroy = nv30_sampler_view_destroy; -- cgit v1.2.3 From 5587097b53afbce52f7e26568d2dde11de96e1ec Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Tue, 2 Mar 2010 12:02:31 +0100 Subject: util: Add pipe_get_tile_swizzle(). --- src/gallium/auxiliary/util/u_tile.c | 42 +++++++++++++++++++++++++++++++++++++ src/gallium/auxiliary/util/u_tile.h | 12 +++++++++++ 2 files changed, 54 insertions(+) (limited to 'src/gallium') diff --git a/src/gallium/auxiliary/util/u_tile.c b/src/gallium/auxiliary/util/u_tile.c index 0051258e22a..813ce4eb7dc 100644 --- a/src/gallium/auxiliary/util/u_tile.c +++ b/src/gallium/auxiliary/util/u_tile.c @@ -1273,6 +1273,48 @@ pipe_get_tile_rgba(struct pipe_transfer *pt, } +void +pipe_get_tile_swizzle(struct pipe_transfer *pt, + uint x, + uint y, + uint w, + uint h, + uint swizzle_r, + uint swizzle_g, + uint swizzle_b, + uint swizzle_a, + float *p) +{ + uint i; + float rgba01[6]; + + pipe_get_tile_rgba(pt, x, y, w, h, p); + + if (swizzle_r == PIPE_SWIZZLE_RED && + swizzle_g == PIPE_SWIZZLE_GREEN && + swizzle_b == PIPE_SWIZZLE_BLUE && + swizzle_a == PIPE_SWIZZLE_ALPHA) { + /* no-op, skip */ + return; + } + + rgba01[PIPE_SWIZZLE_ZERO] = 0.0f; + rgba01[PIPE_SWIZZLE_ONE] = 1.0f; + + for (i = 0; i < w * h; i++) { + rgba01[PIPE_SWIZZLE_RED] = p[0]; + rgba01[PIPE_SWIZZLE_GREEN] = p[1]; + rgba01[PIPE_SWIZZLE_BLUE] = p[2]; + rgba01[PIPE_SWIZZLE_ALPHA] = p[3]; + + *p++ = rgba01[swizzle_r]; + *p++ = rgba01[swizzle_g]; + *p++ = rgba01[swizzle_b]; + *p++ = rgba01[swizzle_a]; + } +} + + void pipe_put_tile_rgba(struct pipe_transfer *pt, uint x, uint y, uint w, uint h, diff --git a/src/gallium/auxiliary/util/u_tile.h b/src/gallium/auxiliary/util/u_tile.h index 1453af38b8a..b4706179a55 100644 --- a/src/gallium/auxiliary/util/u_tile.h +++ b/src/gallium/auxiliary/util/u_tile.h @@ -71,6 +71,18 @@ pipe_get_tile_rgba(struct pipe_transfer *pt, uint x, uint y, uint w, uint h, float *p); +void +pipe_get_tile_swizzle(struct pipe_transfer *pt, + uint x, + uint y, + uint w, + uint h, + uint swizzle_r, + uint swizzle_g, + uint swizzle_b, + uint swizzle_a, + float *p); + void pipe_put_tile_rgba(struct pipe_transfer *pt, uint x, uint y, uint w, uint h, -- cgit v1.2.3 From f59f28093ea827bd234d8e1a36bdd56a9fce5f09 Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Tue, 2 Mar 2010 12:03:24 +0100 Subject: softpipe: Implement sampler view swizzling. --- src/gallium/drivers/softpipe/sp_state_sampler.c | 6 ++--- src/gallium/drivers/softpipe/sp_tex_tile_cache.c | 29 +++++++++++++++++------- src/gallium/drivers/softpipe/sp_tex_tile_cache.h | 9 ++++++-- 3 files changed, 30 insertions(+), 14 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/softpipe/sp_state_sampler.c b/src/gallium/drivers/softpipe/sp_state_sampler.c index 8922941994a..68ea13f8d51 100644 --- a/src/gallium/drivers/softpipe/sp_state_sampler.c +++ b/src/gallium/drivers/softpipe/sp_state_sampler.c @@ -166,10 +166,9 @@ softpipe_set_sampler_views(struct pipe_context *pipe, for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { struct pipe_sampler_view *view = i < num ? views[i] : NULL; - struct pipe_texture *texture = view ? view->texture : NULL; pipe_sampler_view_reference(&softpipe->sampler_views[i], view); - sp_tex_tile_cache_set_texture(softpipe->tex_cache[i], texture); + sp_tex_tile_cache_set_sampler_view(softpipe->tex_cache[i], view); } softpipe->num_sampler_views = num; @@ -198,10 +197,9 @@ softpipe_set_vertex_sampler_views(struct pipe_context *pipe, for (i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; i++) { struct pipe_sampler_view *view = i < num ? views[i] : NULL; - struct pipe_texture *texture = view ? view->texture : NULL; pipe_sampler_view_reference(&softpipe->vertex_sampler_views[i], view); - sp_tex_tile_cache_set_texture(softpipe->vertex_tex_cache[i], texture); + sp_tex_tile_cache_set_sampler_view(softpipe->vertex_tex_cache[i], view); } softpipe->num_vertex_sampler_views = num; diff --git a/src/gallium/drivers/softpipe/sp_tex_tile_cache.c b/src/gallium/drivers/softpipe/sp_tex_tile_cache.c index a0b95c88846..b9635bee78b 100644 --- a/src/gallium/drivers/softpipe/sp_tex_tile_cache.c +++ b/src/gallium/drivers/softpipe/sp_tex_tile_cache.c @@ -119,12 +119,13 @@ sp_tex_tile_cache_validate_texture(struct softpipe_tex_tile_cache *tc) } /** - * Specify the texture to cache. + * Specify the sampler view to cache. */ void -sp_tex_tile_cache_set_texture(struct softpipe_tex_tile_cache *tc, - struct pipe_texture *texture) +sp_tex_tile_cache_set_sampler_view(struct softpipe_tex_tile_cache *tc, + struct pipe_sampler_view *view) { + struct pipe_texture *texture = view ? view->texture : NULL; uint i; assert(!tc->transfer); @@ -144,6 +145,13 @@ sp_tex_tile_cache_set_texture(struct softpipe_tex_tile_cache *tc, tc->tex_trans = NULL; } + if (view) { + tc->swizzle_r = view->swizzle_r; + tc->swizzle_g = view->swizzle_g; + tc->swizzle_b = view->swizzle_b; + tc->swizzle_a = view->swizzle_a; + } + /* mark as entries as invalid/empty */ /* XXX we should try to avoid this when the teximage hasn't changed */ for (i = 0; i < NUM_ENTRIES; i++) { @@ -257,11 +265,16 @@ sp_find_cached_tile_tex(struct softpipe_tex_tile_cache *tc, } /* get tile from the transfer (view into texture) */ - pipe_get_tile_rgba(tc->tex_trans, - addr.bits.x * TILE_SIZE, - addr.bits.y * TILE_SIZE, - TILE_SIZE, TILE_SIZE, - (float *) tile->data.color); + pipe_get_tile_swizzle(tc->tex_trans, + addr.bits.x * TILE_SIZE, + addr.bits.y * TILE_SIZE, + TILE_SIZE, + TILE_SIZE, + tc->swizzle_r, + tc->swizzle_g, + tc->swizzle_b, + tc->swizzle_a, + (float *) tile->data.color); tile->addr = addr; } diff --git a/src/gallium/drivers/softpipe/sp_tex_tile_cache.h b/src/gallium/drivers/softpipe/sp_tex_tile_cache.h index ac6886a3df1..c562f721be7 100644 --- a/src/gallium/drivers/softpipe/sp_tex_tile_cache.h +++ b/src/gallium/drivers/softpipe/sp_tex_tile_cache.h @@ -83,6 +83,11 @@ struct softpipe_tex_tile_cache void *tex_trans_map; int tex_face, tex_level, tex_z; + unsigned swizzle_r; + unsigned swizzle_g; + unsigned swizzle_b; + unsigned swizzle_a; + struct softpipe_tex_cached_tile *last_tile; /**< most recently retrieved tile */ }; @@ -101,8 +106,8 @@ extern void sp_tex_tile_cache_unmap_transfers(struct softpipe_tex_tile_cache *tc); extern void -sp_tex_tile_cache_set_texture(struct softpipe_tex_tile_cache *tc, - struct pipe_texture *texture); +sp_tex_tile_cache_set_sampler_view(struct softpipe_tex_tile_cache *tc, + struct pipe_sampler_view *view); void sp_tex_tile_cache_validate_texture(struct softpipe_tex_tile_cache *tc); -- cgit v1.2.3 From 5d4360d10cd39e28ee3b563e95959f3dd22c5242 Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Wed, 10 Mar 2010 16:32:34 +0100 Subject: gallium: pipe_get_tile_swizzle() accepts format parameter. Enables casting of texture data. --- src/gallium/auxiliary/util/u_tile.c | 22 +++++++++++++++++++++- src/gallium/auxiliary/util/u_tile.h | 1 + src/gallium/drivers/softpipe/sp_tex_tile_cache.c | 2 ++ src/gallium/drivers/softpipe/sp_tex_tile_cache.h | 1 + 4 files changed, 25 insertions(+), 1 deletion(-) (limited to 'src/gallium') diff --git a/src/gallium/auxiliary/util/u_tile.c b/src/gallium/auxiliary/util/u_tile.c index 024d9577bc9..8a36d4d9d18 100644 --- a/src/gallium/auxiliary/util/u_tile.c +++ b/src/gallium/auxiliary/util/u_tile.c @@ -1283,12 +1283,32 @@ pipe_get_tile_swizzle(struct pipe_transfer *pt, uint swizzle_g, uint swizzle_b, uint swizzle_a, + enum pipe_format format, float *p) { + unsigned dst_stride = w * 4; + void *packed; uint i; float rgba01[6]; - pipe_get_tile_rgba(pt, x, y, w, h, p); + if (pipe_clip_tile(x, y, &w, &h, pt)) { + return; + } + + packed = MALLOC(util_format_get_nblocks(format, w, h) * util_format_get_blocksize(format)); + if (!packed) { + return; + } + + if (format == PIPE_FORMAT_UYVY || format == PIPE_FORMAT_YUYV) { + assert((x & 1) == 0); + } + + pipe_get_tile_raw(pt, x, y, w, h, packed, 0); + + pipe_tile_raw_to_rgba(format, packed, w, h, p, dst_stride); + + FREE(packed); if (swizzle_r == PIPE_SWIZZLE_RED && swizzle_g == PIPE_SWIZZLE_GREEN && diff --git a/src/gallium/auxiliary/util/u_tile.h b/src/gallium/auxiliary/util/u_tile.h index b4706179a55..d665fdb1bb1 100644 --- a/src/gallium/auxiliary/util/u_tile.h +++ b/src/gallium/auxiliary/util/u_tile.h @@ -81,6 +81,7 @@ pipe_get_tile_swizzle(struct pipe_transfer *pt, uint swizzle_g, uint swizzle_b, uint swizzle_a, + enum pipe_format format, float *p); void diff --git a/src/gallium/drivers/softpipe/sp_tex_tile_cache.c b/src/gallium/drivers/softpipe/sp_tex_tile_cache.c index b9635bee78b..dfa002a79b4 100644 --- a/src/gallium/drivers/softpipe/sp_tex_tile_cache.c +++ b/src/gallium/drivers/softpipe/sp_tex_tile_cache.c @@ -150,6 +150,7 @@ sp_tex_tile_cache_set_sampler_view(struct softpipe_tex_tile_cache *tc, tc->swizzle_g = view->swizzle_g; tc->swizzle_b = view->swizzle_b; tc->swizzle_a = view->swizzle_a; + tc->format = view->format; } /* mark as entries as invalid/empty */ @@ -274,6 +275,7 @@ sp_find_cached_tile_tex(struct softpipe_tex_tile_cache *tc, tc->swizzle_g, tc->swizzle_b, tc->swizzle_a, + tc->format, (float *) tile->data.color); tile->addr = addr; } diff --git a/src/gallium/drivers/softpipe/sp_tex_tile_cache.h b/src/gallium/drivers/softpipe/sp_tex_tile_cache.h index c562f721be7..f8770409d87 100644 --- a/src/gallium/drivers/softpipe/sp_tex_tile_cache.h +++ b/src/gallium/drivers/softpipe/sp_tex_tile_cache.h @@ -87,6 +87,7 @@ struct softpipe_tex_tile_cache unsigned swizzle_g; unsigned swizzle_b; unsigned swizzle_a; + unsigned format; struct softpipe_tex_cached_tile *last_tile; /**< most recently retrieved tile */ }; -- cgit v1.2.3 From 252dc5f897f9d124459e3afebf6686d1fe271511 Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Thu, 11 Mar 2010 15:25:52 +0100 Subject: gallium: Use last_level for pipe_sampler_view instead of num_levels. It's more consistent with the rest of the interfaces. --- src/gallium/auxiliary/util/u_sampler.c | 2 +- src/gallium/drivers/nv50/nv50_tex.c | 2 +- src/gallium/include/pipe/p_state.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/auxiliary/util/u_sampler.c b/src/gallium/auxiliary/util/u_sampler.c index 08cf1fcf223..4d8f861ce49 100644 --- a/src/gallium/auxiliary/util/u_sampler.c +++ b/src/gallium/auxiliary/util/u_sampler.c @@ -41,7 +41,7 @@ default_template(struct pipe_sampler_view *view, view->format = format; view->first_level = 0; - view->num_levels = texture->last_level + 1; + view->last_level = texture->last_level; view->swizzle_r = PIPE_SWIZZLE_RED; view->swizzle_g = PIPE_SWIZZLE_GREEN; view->swizzle_b = PIPE_SWIZZLE_BLUE; diff --git a/src/gallium/drivers/nv50/nv50_tex.c b/src/gallium/drivers/nv50/nv50_tex.c index c5029bad2d8..7ed73eac50f 100644 --- a/src/gallium/drivers/nv50/nv50_tex.c +++ b/src/gallium/drivers/nv50/nv50_tex.c @@ -152,7 +152,7 @@ nv50_tex_construct(struct nv50_sampler_view *view) tic[6] = 0x03000000; - tic[7] = (view->pipe.num_levels - view->pipe.first_level - 1) << 4; + tic[7] = (view->pipe.last_level - view->pipe.first_level) << 4; tic[7] |= view->pipe.first_level; return TRUE; diff --git a/src/gallium/include/pipe/p_state.h b/src/gallium/include/pipe/p_state.h index 3c7c0a5261c..11072407d93 100644 --- a/src/gallium/include/pipe/p_state.h +++ b/src/gallium/include/pipe/p_state.h @@ -309,7 +309,7 @@ struct pipe_sampler_view struct pipe_texture *texture; /**< texture into which this is a view */ struct pipe_context *context; /**< context this view belongs to */ unsigned first_level:8; /**< first mipmap level */ - unsigned num_levels:8; /**< number of mipamp levels */ + unsigned last_level:8; /**< last mipmap level */ unsigned swizzle_r:3; /**< PIPE_SWIZZLE_x for red component */ unsigned swizzle_g:3; /**< PIPE_SWIZZLE_x for green component */ unsigned swizzle_b:3; /**< PIPE_SWIZZLE_x for blue component */ -- cgit v1.2.3 From 530b9910c2fd25344e6d28b6d9aa0eaad31618e7 Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Thu, 11 Mar 2010 15:30:21 +0100 Subject: gallium: Check for OOM condition when creating a sampler view. --- src/gallium/drivers/cell/ppu/cell_pipe_state.c | 12 +++++++----- src/gallium/drivers/i915/i915_state.c | 12 +++++++----- src/gallium/drivers/i965/brw_pipe_sampler.c | 12 +++++++----- src/gallium/drivers/llvmpipe/lp_state_sampler.c | 12 +++++++----- src/gallium/drivers/nv30/nv30_state.c | 12 +++++++----- src/gallium/drivers/nv40/nv40_state.c | 12 +++++++----- src/gallium/drivers/r300/r300_state.c | 12 +++++++----- src/gallium/drivers/softpipe/sp_state_sampler.c | 12 +++++++----- src/gallium/drivers/svga/svga_pipe_sampler.c | 12 +++++++----- 9 files changed, 63 insertions(+), 45 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/cell/ppu/cell_pipe_state.c b/src/gallium/drivers/cell/ppu/cell_pipe_state.c index 2fc82933e4d..059ce8597bc 100644 --- a/src/gallium/drivers/cell/ppu/cell_pipe_state.c +++ b/src/gallium/drivers/cell/ppu/cell_pipe_state.c @@ -298,11 +298,13 @@ cell_create_sampler_view(struct pipe_context *pipe, { struct pipe_sampler_view *view = CALLOC_STRUCT(pipe_sampler_view); - *view = *templ; - view->reference.count = 1; - view->texture = NULL; - pipe_texture_reference(&view->texture, texture); - view->context = pipe; + if (view) { + *view = *templ; + view->reference.count = 1; + view->texture = NULL; + pipe_texture_reference(&view->texture, texture); + view->context = pipe; + } return view; } diff --git a/src/gallium/drivers/i915/i915_state.c b/src/gallium/drivers/i915/i915_state.c index 884abe622b3..e54997736f9 100644 --- a/src/gallium/drivers/i915/i915_state.c +++ b/src/gallium/drivers/i915/i915_state.c @@ -598,11 +598,13 @@ i915_create_sampler_view(struct pipe_context *pipe, { struct pipe_sampler_view *view = CALLOC_STRUCT(pipe_sampler_view); - *view = *templ; - view->reference.count = 1; - view->texture = NULL; - pipe_texture_reference(&view->texture, texture); - view->context = pipe; + if (view) { + *view = *templ; + view->reference.count = 1; + view->texture = NULL; + pipe_texture_reference(&view->texture, texture); + view->context = pipe; + } return view; } diff --git a/src/gallium/drivers/i965/brw_pipe_sampler.c b/src/gallium/drivers/i965/brw_pipe_sampler.c index fbc3a07d61e..d2aa2bc9f35 100644 --- a/src/gallium/drivers/i965/brw_pipe_sampler.c +++ b/src/gallium/drivers/i965/brw_pipe_sampler.c @@ -219,11 +219,13 @@ brw_create_sampler_view(struct pipe_context *pipe, { struct pipe_sampler_view *view = CALLOC_STRUCT(pipe_sampler_view); - *view = *templ; - view->reference.count = 1; - view->texture = NULL; - pipe_texture_reference(&view->texture, texture); - view->context = pipe; + if (view) { + *view = *templ; + view->reference.count = 1; + view->texture = NULL; + pipe_texture_reference(&view->texture, texture); + view->context = pipe; + } return view; } diff --git a/src/gallium/drivers/llvmpipe/lp_state_sampler.c b/src/gallium/drivers/llvmpipe/lp_state_sampler.c index 2df86a08148..2645441b58c 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_sampler.c +++ b/src/gallium/drivers/llvmpipe/lp_state_sampler.c @@ -170,11 +170,13 @@ llvmpipe_create_sampler_view(struct pipe_context *pipe, { struct pipe_sampler_view *view = CALLOC_STRUCT(pipe_sampler_view); - *view = *templ; - view->reference.count = 1; - view->texture = NULL; - pipe_texture_reference(&view->texture, texture); - view->context = pipe; + if (view) { + *view = *templ; + view->reference.count = 1; + view->texture = NULL; + pipe_texture_reference(&view->texture, texture); + view->context = pipe; + } return view; } diff --git a/src/gallium/drivers/nv30/nv30_state.c b/src/gallium/drivers/nv30/nv30_state.c index 321575da0a9..fb3075f4c81 100644 --- a/src/gallium/drivers/nv30/nv30_state.c +++ b/src/gallium/drivers/nv30/nv30_state.c @@ -304,11 +304,13 @@ nv30_create_sampler_view(struct pipe_context *pipe, { struct pipe_sampler_view *view = CALLOC_STRUCT(pipe_sampler_view); - *view = *templ; - view->reference.count = 1; - view->texture = NULL; - pipe_texture_reference(&view->texture, texture); - view->context = pipe; + if (view) { + *view = *templ; + view->reference.count = 1; + view->texture = NULL; + pipe_texture_reference(&view->texture, texture); + view->context = pipe; + } return view; } diff --git a/src/gallium/drivers/nv40/nv40_state.c b/src/gallium/drivers/nv40/nv40_state.c index 120dc42f7b1..28a48a63f1c 100644 --- a/src/gallium/drivers/nv40/nv40_state.c +++ b/src/gallium/drivers/nv40/nv40_state.c @@ -314,11 +314,13 @@ nv40_create_sampler_view(struct pipe_context *pipe, { struct pipe_sampler_view *view = CALLOC_STRUCT(pipe_sampler_view); - *view = *templ; - view->reference.count = 1; - view->texture = NULL; - pipe_texture_reference(&view->texture, texture); - view->context = pipe; + if (view) { + *view = *templ; + view->reference.count = 1; + view->texture = NULL; + pipe_texture_reference(&view->texture, texture); + view->context = pipe; + } return view; } diff --git a/src/gallium/drivers/r300/r300_state.c b/src/gallium/drivers/r300/r300_state.c index 09bbf6c60e2..d73ec78fda8 100644 --- a/src/gallium/drivers/r300/r300_state.c +++ b/src/gallium/drivers/r300/r300_state.c @@ -980,11 +980,13 @@ r300_create_sampler_view(struct pipe_context *pipe, struct r300_context *r300 = r300_context(pipe); struct pipe_sampler_view *view = CALLOC_STRUCT(pipe_sampler_view); - *view = *templ; - view->reference.count = 1; - view->texture = NULL; - pipe_texture_reference(&view->texture, texture); - view->context = pipe; + if (view) { + *view = *templ; + view->reference.count = 1; + view->texture = NULL; + pipe_texture_reference(&view->texture, texture); + view->context = pipe; + } return view; } diff --git a/src/gallium/drivers/softpipe/sp_state_sampler.c b/src/gallium/drivers/softpipe/sp_state_sampler.c index 68ea13f8d51..d501952bba9 100644 --- a/src/gallium/drivers/softpipe/sp_state_sampler.c +++ b/src/gallium/drivers/softpipe/sp_state_sampler.c @@ -128,11 +128,13 @@ softpipe_create_sampler_view(struct pipe_context *pipe, { struct pipe_sampler_view *view = CALLOC_STRUCT(pipe_sampler_view); - *view = *templ; - view->reference.count = 1; - view->texture = NULL; - pipe_texture_reference(&view->texture, texture); - view->context = pipe; + if (view) { + *view = *templ; + view->reference.count = 1; + view->texture = NULL; + pipe_texture_reference(&view->texture, texture); + view->context = pipe; + } return view; } diff --git a/src/gallium/drivers/svga/svga_pipe_sampler.c b/src/gallium/drivers/svga/svga_pipe_sampler.c index ebd1b949972..82d525ca33f 100644 --- a/src/gallium/drivers/svga/svga_pipe_sampler.c +++ b/src/gallium/drivers/svga/svga_pipe_sampler.c @@ -183,11 +183,13 @@ svga_create_sampler_view(struct pipe_context *pipe, { struct pipe_sampler_view *view = CALLOC_STRUCT(pipe_sampler_view); - *view = *templ; - view->reference.count = 1; - view->texture = NULL; - pipe_texture_reference(&view->texture, texture); - view->context = pipe; + if (view) { + *view = *templ; + view->reference.count = 1; + view->texture = NULL; + pipe_texture_reference(&view->texture, texture); + view->context = pipe; + } return view; } -- cgit v1.2.3 From 4da5d369fb6a724a03a3c2e79ed6623980fc72ac Mon Sep 17 00:00:00 2001 From: Christoph Bumiller Date: Thu, 11 Mar 2010 17:27:12 +0100 Subject: nv50: fix damage from merging master into sampler-view Fixed the state array sizes at 3 (instead of PIPE_SHADER_TYPES) because we'll never have domain and hull shaders on nv50; also the numbering doesn't correspond to the hw numbering. --- src/gallium/drivers/nv50/nv50_context.h | 8 +++----- src/gallium/drivers/nv50/nv50_state_validate.c | 10 ++++------ src/gallium/drivers/nv50/nv50_tex.c | 18 ++++++++++-------- 3 files changed, 17 insertions(+), 19 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/nv50/nv50_context.h b/src/gallium/drivers/nv50/nv50_context.h index 8a5f7cb2519..f35bc411feb 100644 --- a/src/gallium/drivers/nv50/nv50_context.h +++ b/src/gallium/drivers/nv50/nv50_context.h @@ -137,7 +137,7 @@ struct nv50_state { struct nouveau_stateobj *hw[64]; uint64_t hw_dirty; - unsigned miptree_nr[PIPE_SHADER_TYPES]; + unsigned sampler_view_nr[3]; struct nouveau_stateobj *vtxbuf; struct nouveau_stateobj *vtxattr; unsigned vtxelt_nr; @@ -169,12 +169,10 @@ struct nv50_context { struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS]; unsigned vtxbuf_nr; struct nv50_vtxelt_stateobj *vtxelt; - struct nv50_sampler_stateobj *sampler[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS]; - unsigned sampler_nr[PIPE_SHADER_TYPES]; + struct nv50_sampler_stateobj *sampler[3][PIPE_MAX_SAMPLERS]; + unsigned sampler_nr[3]; struct pipe_sampler_view *sampler_views[3][PIPE_MAX_SAMPLERS]; unsigned sampler_view_nr[3]; - struct nv50_miptree *miptree[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS]; - unsigned miptree_nr[PIPE_SHADER_TYPES]; unsigned vbo_fifo; }; diff --git a/src/gallium/drivers/nv50/nv50_state_validate.c b/src/gallium/drivers/nv50/nv50_state_validate.c index 2c8e7ca7982..63d73b5ce83 100644 --- a/src/gallium/drivers/nv50/nv50_state_validate.c +++ b/src/gallium/drivers/nv50/nv50_state_validate.c @@ -310,15 +310,13 @@ validate_sampler(struct nv50_context *nv50) struct nouveau_stateobj *so; unsigned nr = 0, i; - for (i = 0; i < PIPE_SHADER_TYPES; ++i) + for (i = 0; i < 3; ++i) nr += nv50->sampler_nr[i]; - so = so_new(1 + 5 * PIPE_SHADER_TYPES, - 1 + 19 * PIPE_SHADER_TYPES + nr * 8, - PIPE_SHADER_TYPES * 2); + so = so_new(1 + 5 * 3, 1 + 19 * 3 + nr * 8, 3 * 2); - nv50_validate_samplers(nv50, so, PIPE_SHADER_VERTEX); - nv50_validate_samplers(nv50, so, PIPE_SHADER_FRAGMENT); + nv50_validate_samplers(nv50, so, 0); /* VP */ + nv50_validate_samplers(nv50, so, 2); /* FP */ so_method(so, tesla, 0x1334, 1); /* flush TSC */ so_data (so, 0); diff --git a/src/gallium/drivers/nv50/nv50_tex.c b/src/gallium/drivers/nv50/nv50_tex.c index 7ed73eac50f..aa885e71688 100644 --- a/src/gallium/drivers/nv50/nv50_tex.c +++ b/src/gallium/drivers/nv50/nv50_tex.c @@ -54,8 +54,8 @@ static const uint32_t nv50_texture_formats[PIPE_FORMAT_COUNT] = _(A8_UNORM, UNORM, ZERO, ZERO, ZERO, C0, 8), _(I8_UNORM, UNORM, C0, C0, C0, C0, 8), - _(A8L8_UNORM, UNORM, C0, C0, C0, C1, 8_8), - _(A8L8_SRGB, UNORM, C0, C0, C0, C1, 8_8), + _(L8A8_UNORM, UNORM, C0, C0, C0, C1, 8_8), + _(L8A8_SRGB, UNORM, C0, C0, C0, C1, 8_8), _(DXT1_RGB, UNORM, C0, C1, C2, ONE, DXT1), _(DXT1_RGBA, UNORM, C0, C1, C2, C3, DXT1), @@ -221,23 +221,25 @@ nv50_tex_relocs(struct nv50_context *nv50) int p, unit; p = PIPE_SHADER_FRAGMENT; - for (unit = 0; unit < nv50->miptree_nr[p]; unit++) { - if (!nv50->miptree[p][unit]) + for (unit = 0; unit < nv50->sampler_view_nr[p]; unit++) { + struct pipe_sampler_view *view = nv50->sampler_views[p][unit]; + if (!view) continue; nouveau_reloc_emit(chan, nv50->screen->tic, ((p * 32) + unit) * 32, NULL, - nv50->miptree[p][unit]->base.bo, 0, 0, + nv50_miptree(view->texture)->base.bo, 0, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_LOW | NOUVEAU_BO_RD, 0, 0); } p = PIPE_SHADER_VERTEX; - for (unit = 0; unit < nv50->miptree_nr[p]; unit++) { - if (!nv50->miptree[p][unit]) + for (unit = 0; unit < nv50->sampler_view_nr[p]; unit++) { + struct pipe_sampler_view *view = nv50->sampler_views[p][unit]; + if (!view) continue; nouveau_reloc_emit(chan, nv50->screen->tic, ((p * 32) + unit) * 32, NULL, - nv50->miptree[p][unit]->base.bo, 0, 0, + nv50_miptree(view->texture)->base.bo, 0, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_LOW | NOUVEAU_BO_RD, 0, 0); } -- cgit v1.2.3 From 9e9839bd04b5d4e554a1a9ede22ccf44fc1306b6 Mon Sep 17 00:00:00 2001 From: Christoph Bumiller Date: Thu, 11 Mar 2010 17:12:10 +0100 Subject: nv50: put correct value into the TIC MAX_LEVEL field --- src/gallium/drivers/nv50/nv50_tex.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/nv50/nv50_tex.c b/src/gallium/drivers/nv50/nv50_tex.c index aa885e71688..79639e81eb3 100644 --- a/src/gallium/drivers/nv50/nv50_tex.c +++ b/src/gallium/drivers/nv50/nv50_tex.c @@ -152,8 +152,7 @@ nv50_tex_construct(struct nv50_sampler_view *view) tic[6] = 0x03000000; - tic[7] = (view->pipe.last_level - view->pipe.first_level) << 4; - tic[7] |= view->pipe.first_level; + tic[7] = (view->pipe.last_level << 4) | view->pipe.first_level; return TRUE; } -- cgit v1.2.3 From a671a9eed08e63e97ec4257adea2c09dd7d2b4e2 Mon Sep 17 00:00:00 2001 From: Christoph Bumiller Date: Thu, 11 Mar 2010 17:14:14 +0100 Subject: nv50: take format from sampler view, not the referenced texture --- src/gallium/drivers/nv50/nv50_tex.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/nv50/nv50_tex.c b/src/gallium/drivers/nv50/nv50_tex.c index 79639e81eb3..85ab947c006 100644 --- a/src/gallium/drivers/nv50/nv50_tex.c +++ b/src/gallium/drivers/nv50/nv50_tex.c @@ -105,7 +105,7 @@ nv50_tex_construct(struct nv50_sampler_view *view) struct nv50_miptree *mt = nv50_miptree(view->pipe.texture); uint32_t swz[4], *tic = view->tic; - tic[0] = nv50_texture_formats[mt->base.base.format]; + tic[0] = nv50_texture_formats[view->pipe.format]; swz[0] = nv50_tic_swizzle(tic[0], view->pipe.swizzle_r); swz[1] = nv50_tic_swizzle(tic[0], view->pipe.swizzle_g); -- cgit v1.2.3 From d2083056d56990a9bfba774d5bda272b74d27a6f Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Sun, 7 Feb 2010 00:52:02 +0800 Subject: gallium: Add st_api.h. This is a new interface to be implemented by st/mesa, st/vesa, and the window system APIs such as EGL or GLX. --- src/gallium/include/state_tracker/st_api.h | 407 +++++++++++++++++++++++++++++ 1 file changed, 407 insertions(+) create mode 100644 src/gallium/include/state_tracker/st_api.h (limited to 'src/gallium') diff --git a/src/gallium/include/state_tracker/st_api.h b/src/gallium/include/state_tracker/st_api.h new file mode 100644 index 00000000000..70ad215bfce --- /dev/null +++ b/src/gallium/include/state_tracker/st_api.h @@ -0,0 +1,407 @@ +/********************************************************** + * Copyright 2010 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + **********************************************************/ + + +#ifndef _ST_API_H_ +#define _ST_API_H_ + +#include "pipe/p_compiler.h" +#include "pipe/p_format.h" + +/** + * \file API for communication between state trackers and state tracker + * managers. + * + * While both are state tackers, we use the term state tracker for rendering + * APIs such as OpenGL or OpenVG, and state tracker manager for window system + * APIs such as EGL or GLX in this file. + * + * This file defines an API to be implemented by both state trackers and state + * tracker managers. + */ + +/** + * The entry points of the state trackers. + */ +#define ST_MODULE_OPENGL_SYMBOL "st_module_OpenGL" +#define ST_MODULE_OPENGL_ES1_SYMBOL "st_module_OpenGL_ES1" +#define ST_MODULE_OPENGL_ES2_SYMBOL "st_module_OpenGL_ES2" +#define ST_MODULE_OPENVG_SYMBOL "st_module_OpenVG" + +/** + * The supported rendering API of a state tracker. + */ +enum st_api_type { + ST_API_OPENGL, + ST_API_OPENGL_ES1, + ST_API_OPENGL_ES2, + ST_API_OPENVG, + + ST_API_COUNT +}; + +/** + * Used in st_context_iface->teximage. + */ +enum st_texture_type { + ST_TEXTURE_1D, + ST_TEXTURE_2D, + ST_TEXTURE_3D, + ST_TEXTURE_RECT, +}; + +/** + * Available attachments of framebuffer. + */ +enum st_attachment_type { + ST_ATTACHMENT_FRONT_LEFT, + ST_ATTACHMENT_BACK_LEFT, + ST_ATTACHMENT_FRONT_RIGHT, + ST_ATTACHMENT_BACK_RIGHT, + ST_ATTACHMENT_DEPTH_STENCIL, + ST_ATTACHMENT_ACCUM, + ST_ATTACHMENT_SAMPLE, + + ST_ATTACHMENT_COUNT, + ST_ATTACHMENT_INVALID = -1 +}; + +/* for buffer_mask in st_visual */ +#define ST_ATTACHMENT_FRONT_LEFT_MASK (1 << ST_ATTACHMENT_FRONT_LEFT) +#define ST_ATTACHMENT_BACK_LEFT_MASK (1 << ST_ATTACHMENT_BACK_LEFT) +#define ST_ATTACHMENT_FRONT_RIGHT_MASK (1 << ST_ATTACHMENT_FRONT_RIGHT) +#define ST_ATTACHMENT_BACK_RIGHT_MASK (1 << ST_ATTACHMENT_BACK_RIGHT) +#define ST_ATTACHMENT_DEPTH_STENCIL_MASK (1 << ST_ATTACHMENT_DEPTH_STENCIL) +#define ST_ATTACHMENT_ACCUM_MASK (1 << ST_ATTACHMENT_ACCUM) +#define ST_ATTACHMENT_SAMPLE_MASK (1 << ST_ATTACHMENT_SAMPLE) + +/** + * Enumerations of state tracker context resources. + */ +enum st_context_resource_type { + ST_CONTEXT_RESOURCE_OPENGL_TEXTURE_2D, + ST_CONTEXT_RESOURCE_OPENGL_TEXTURE_3D, + ST_CONTEXT_RESOURCE_OPENGL_TEXTURE_CUBE_MAP_POSITIVE_X, + ST_CONTEXT_RESOURCE_OPENGL_TEXTURE_CUBE_MAP_NEGATIVE_X, + ST_CONTEXT_RESOURCE_OPENGL_TEXTURE_CUBE_MAP_POSITIVE_Y, + ST_CONTEXT_RESOURCE_OPENGL_TEXTURE_CUBE_MAP_NEGATIVE_Y, + ST_CONTEXT_RESOURCE_OPENGL_TEXTURE_CUBE_MAP_POSITIVE_Z, + ST_CONTEXT_RESOURCE_OPENGL_TEXTURE_CUBE_MAP_NEGATIVE_Z, + ST_CONTEXT_RESOURCE_OPENGL_RENDERBUFFER, + ST_CONTEXT_RESOURCE_OPENVG_PARENT_IMAGE, +}; + +/** + * The return type of st_api->get_proc_address. + */ +typedef void (*st_proc_t)(void); + +struct pipe_context; +struct pipe_texture; +struct pipe_fence_handle; + +/** + * Used in st_context_iface->get_resource_for_egl_image. + */ +struct st_context_resource +{ + /* these fields are filled by the caller */ + enum st_context_resource_type type; + void *resource; + + /* this is owned by the caller */ + struct pipe_texture *texture; +}; + +/** + * Used in st_manager_iface->get_egl_image. + */ +struct st_egl_image +{ + /* these fields are filled by the caller */ + struct st_context_iface *stctxi; + void *egl_image; + + /* this is owned by the caller */ + struct pipe_texture *texture; + + unsigned face; + unsigned level; + unsigned zslice; +}; + +/** + * Represent the visual of a framebuffer. + */ +struct st_visual +{ + /** + * Available buffers. Tested with ST_FRAMEBUFFER_*_MASK. + */ + unsigned buffer_mask; + + /** + * Buffer formats. The formats are always set even when the buffer is + * not available. + */ + enum pipe_format color_format; + enum pipe_format depth_stencil_format; + enum pipe_format accum_format; + int samples; + + /** + * Desired render buffer. + */ + enum st_attachment_type render_buffer; +}; + +/** + * Represent a windowing system drawable. + * + * The framebuffer is implemented by the state tracker manager and + * used by the state trackers. + * + * Instead of the winsys pokeing into the API context to figure + * out what buffers that might be needed in the future by the API + * context, it calls into the framebuffer to get the textures. + * + * This structure along with the notify_invalid_framebuffer + * allows framebuffers to be shared between different threads + * but at the same make the API context free from thread + * syncronisation primitves, with the exception of a small + * atomic flag used for notification of framebuffer dirty status. + * + * The thread syncronisation is put inside the framebuffer + * and only called once the framebuffer has become dirty. + */ +struct st_framebuffer_iface +{ + /** + * Available for the state tracker manager to use. + */ + void *st_manager_private; + + /** + * The visual of a framebuffer. + */ + const struct st_visual *visual; + + /** + * Flush the front buffer. + * + * On some window systems, changes to the front buffers are not immediately + * visible. They need to be flushed. + * + * @att is one of the front buffer attachments. + */ + boolean (*flush_front)(struct st_framebuffer_iface *stfbi, + enum st_attachment_type statt); + + /** + * The state tracker asks for the textures it needs. + * + * It should try to only ask for attachments that it currently renders + * to, thus allowing the winsys to delay the allocation of textures not + * needed. For example front buffer attachments are not needed if you + * only do back buffer rendering. + * + * The implementor of this function needs to also ensure + * thread safty as this call might be done from multiple threads. + * + * The returned textures are owned by the caller. They should be + * unreferenced when no longer used. If this function is called multiple + * times with different sets of attachments, those buffers not included in + * the last call might be destroyed. This behavior might change in the + * future. + */ + boolean (*validate)(struct st_framebuffer_iface *stfbi, + const enum st_attachment_type *statts, + unsigned count, + struct pipe_texture **out); +}; + +/** + * Represent a rendering context. + * + * This entity is created from st_api and used by the state tracker manager. + */ +struct st_context_iface +{ + /** + * Available for the state tracker and the manager to use. + */ + void *st_context_private; + void *st_manager_private; + + /** + * Destroy the context. + */ + void (*destroy)(struct st_context_iface *stctxi); + + /** + * Invalidate the current textures that was taken from a framebuffer. + * + * The state tracker manager calls this function to let the rendering + * context know that it should update the textures it got from + * st_framebuffer_iface::validate. It should do so at the latest time possible. + * Possible right before sending triangles to the pipe context. + * + * For certain platforms this function might be called from a thread other + * than the thread that the context is currently bound in, and must + * therefore be thread safe. But it is the state tracker manager's + * responsibility to make sure that the framebuffer is bound to the context + * and the API context is current for the duration of this call. + * + * Thus reducing the sync primitive needed to a single atomic flag. + */ + void (*notify_invalid_framebuffer)(struct st_context_iface *stctxi, + struct st_framebuffer_iface *stfbi); + + /** + * Flush all drawing from context to the pipe also flushes the pipe. + */ + void (*flush)(struct st_context_iface *stctxi, unsigned flags, + struct pipe_fence_handle **fence); + + /** + * Replace the texture image of a texture object at the specified level. + * + * This function is optional. + */ + boolean (*teximage)(struct st_context_iface *stctxi, enum st_texture_type target, + int level, enum pipe_format internal_format, + struct pipe_texture *tex, boolean mipmap); + + /** + * Used to implement glXCopyContext. + */ + void (*copy)(struct st_context_iface *stctxi, + struct st_context_iface *stsrci, unsigned mask); + + /** + * Look up and return the info of a resource for EGLImage. + * + * This function is optional. + */ + boolean (*get_resource_for_egl_image)(struct st_context_iface *stctxi, + struct st_context_resource *stres); +}; + + +/** + * Represent a state tracker manager. + * + * This interface is implemented by the state tracker manager. It corresponds + * to a "display" in the window system. + */ +struct st_manager +{ + struct pipe_screen *screen; + + /** + * Look up and return the info of an EGLImage. + * + * This function is optional. + */ + boolean (*get_egl_image)(struct st_manager *smapi, + struct st_egl_image *stimg); +}; + +/** + * Represent a rendering API such as OpenGL or OpenVG. + * + * Implemented by the state tracker and used by the state tracker manager. + */ +struct st_api +{ + /** + * Destroy the API. + */ + void (*destroy)(struct st_api *stapi); + + /** + * Return an API entry point. + * + * For GL this is the same as _glapi_get_proc_address. + */ + st_proc_t (*get_proc_address)(struct st_api *stapi, const char *procname); + + /** + * Return true if the visual is supported by the state tracker. + */ + boolean (*is_visual_supported)(struct st_api *stapi, + const struct st_visual *visual); + + /** + * Create a rendering context. + */ + struct st_context_iface *(*create_context)(struct st_api *stapi, + struct st_manager *smapi, + const struct st_visual *visual, + struct st_context_iface *stsharei); + + /** + * Bind the context to the calling thread with draw and read as drawables. + * + * The framebuffers might have different visuals than the context does. + */ + boolean (*make_current)(struct st_api *stapi, + struct st_context_iface *stctxi, + struct st_framebuffer_iface *stdrawi, + struct st_framebuffer_iface *streadi); + + /** + * Get the currently bound context in the calling thread. + */ + struct st_context_iface *(*get_current)(struct st_api *stapi); +}; + +/** + * Represent a state tracker. + * + * This is the entry point of a state tracker. + */ +struct st_module +{ + enum st_api_type api; + struct st_api *(*create_api)(void); +}; + +/** + * Return true if the visual has the specified buffers. + */ +static INLINE boolean +st_visual_have_buffers(const struct st_visual *visual, unsigned mask) +{ + return ((visual->buffer_mask & mask) == mask); +} + +/* these symbols may need to be dynamically lookup up */ +extern PUBLIC const struct st_module st_module_OpenGL; +extern PUBLIC const struct st_module st_module_OpenGL_ES1; +extern PUBLIC const struct st_module st_module_OpenGL_ES2; +extern PUBLIC const struct st_module st_module_OpenVG; + +#endif /* _ST_API_H_ */ -- cgit v1.2.3 From 8bcd616a3ffd040ef28b61b38b22da2dad9e2242 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Thu, 14 Jan 2010 12:19:32 +0800 Subject: st/vega: Implement st_api.h. There is currently no user of this new interface. As the inteface can coexist with st_public.h, everthing should work as before. --- src/gallium/state_trackers/vega/Makefile | 1 + src/gallium/state_trackers/vega/api_context.c | 3 + src/gallium/state_trackers/vega/api_masks.c | 4 - src/gallium/state_trackers/vega/vg_context.c | 3 + src/gallium/state_trackers/vega/vg_context.h | 7 + src/gallium/state_trackers/vega/vg_manager.c | 373 ++++++++++++++++++++++++++ src/gallium/state_trackers/vega/vg_manager.h | 40 +++ 7 files changed, 427 insertions(+), 4 deletions(-) create mode 100644 src/gallium/state_trackers/vega/vg_manager.c create mode 100644 src/gallium/state_trackers/vega/vg_manager.h (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/vega/Makefile b/src/gallium/state_trackers/vega/Makefile index 7f04b2aa832..7c315de8271 100644 --- a/src/gallium/state_trackers/vega/Makefile +++ b/src/gallium/state_trackers/vega/Makefile @@ -25,6 +25,7 @@ VG_SOURCES = \ api_transform.c \ vgu.c \ vg_context.c \ + vg_manager.c \ vg_state.c \ vg_tracker.c \ vg_translate.c \ diff --git a/src/gallium/state_trackers/vega/api_context.c b/src/gallium/state_trackers/vega/api_context.c index 47db102dd2d..eb2fbe26e7f 100644 --- a/src/gallium/state_trackers/vega/api_context.c +++ b/src/gallium/state_trackers/vega/api_context.c @@ -26,6 +26,7 @@ #include "VG/openvg.h" +#include "vg_manager.h" #include "vg_context.h" #include "pipe/p_context.h" @@ -55,6 +56,8 @@ void vgFlush(void) pipe = ctx->pipe; pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL); + + vg_manager_flush_frontbuffer(ctx); } void vgFinish(void) diff --git a/src/gallium/state_trackers/vega/api_masks.c b/src/gallium/state_trackers/vega/api_masks.c index 7eb5ea1f078..2f2d925252d 100644 --- a/src/gallium/state_trackers/vega/api_masks.c +++ b/src/gallium/state_trackers/vega/api_masks.c @@ -117,10 +117,6 @@ clear_with_quad(struct vg_context *st, float x0, float y0, x1, y1); */ - if (st->pipe->screen && st->pipe->screen->update_buffer) - st->pipe->screen->update_buffer( st->pipe->screen, - st->pipe->priv ); - cso_save_blend(st->cso_context); cso_save_rasterizer(st->cso_context); cso_save_fragment_shader(st->cso_context); diff --git a/src/gallium/state_trackers/vega/vg_context.c b/src/gallium/state_trackers/vega/vg_context.c index 170391ec031..7769112a31e 100644 --- a/src/gallium/state_trackers/vega/vg_context.c +++ b/src/gallium/state_trackers/vega/vg_context.c @@ -32,6 +32,7 @@ #include "shader.h" #include "asm_util.h" #include "st_inlines.h" +#include "vg_manager.h" #include "pipe/p_context.h" #include "util/u_inlines.h" @@ -305,6 +306,8 @@ static void update_clip_state(struct vg_context *ctx) void vg_validate_state(struct vg_context *ctx) { + vg_manager_validate_framebuffer(ctx); + if ((ctx->state.dirty & BLEND_DIRTY)) { struct pipe_blend_state *blend = &ctx->state.g3d.blend; memset(blend, 0, sizeof(struct pipe_blend_state)); diff --git a/src/gallium/state_trackers/vega/vg_context.h b/src/gallium/state_trackers/vega/vg_context.h index 804e9e76d77..17c7d2ad1c5 100644 --- a/src/gallium/state_trackers/vega/vg_context.h +++ b/src/gallium/state_trackers/vega/vg_context.h @@ -33,6 +33,7 @@ #include "pipe/p_state.h" #include "util/u_pointer.h" #include "util/u_math.h" +#include "state_tracker/st_api.h" #include "cso_cache/cso_hash.h" #include "cso_cache/cso_context.h" @@ -58,6 +59,9 @@ struct st_framebuffer { struct pipe_texture *blend_texture; + struct st_framebuffer_iface *iface; + enum st_attachment_type strb_att; + void *privateData; }; @@ -84,6 +88,8 @@ enum dirty_state { struct vg_context { + struct st_context_iface iface; + struct pipe_context *pipe; struct { @@ -101,6 +107,7 @@ struct vg_context VGErrorCode _error; struct st_framebuffer *draw_buffer; + int32_t draw_buffer_invalid; struct cso_hash *owned_objects[VG_OBJECT_LAST]; diff --git a/src/gallium/state_trackers/vega/vg_manager.c b/src/gallium/state_trackers/vega/vg_manager.c new file mode 100644 index 00000000000..25c2e853f2a --- /dev/null +++ b/src/gallium/state_trackers/vega/vg_manager.c @@ -0,0 +1,373 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu + */ + +#include "state_tracker/st_api.h" + +#include "pipe/p_context.h" +#include "pipe/p_screen.h" +#include "util/u_memory.h" +#include "util/u_inlines.h" + +#include "vg_manager.h" +#include "vg_context.h" +#include "vg_tracker.h" /* for st_resize_framebuffer */ +#include "image.h" + +/** + * Flush the front buffer if the current context renders to the front buffer. + */ +void +vg_manager_flush_frontbuffer(struct vg_context *ctx) +{ + struct st_framebuffer *stfb = ctx->draw_buffer; + + if (!stfb) + return; + + /* st_public.h is used */ + if (!stfb->iface) { + struct pipe_screen *screen = ctx->pipe->screen; + if (screen->flush_frontbuffer) { + screen->flush_frontbuffer(screen, + stfb->strb->surface, ctx->pipe->priv); + } + return; + } + + switch (stfb->strb_att) { + case ST_ATTACHMENT_FRONT_LEFT: + case ST_ATTACHMENT_FRONT_RIGHT: + stfb->iface->flush_front(stfb->iface, stfb->strb_att); + break; + default: + break; + } +} + +/** + * Re-validate the framebuffer. + */ +void +vg_manager_validate_framebuffer(struct vg_context *ctx) +{ + struct pipe_screen *screen = ctx->pipe->screen; + struct st_framebuffer *stfb = ctx->draw_buffer; + struct st_renderbuffer *rb; + struct pipe_texture *pt; + + /* no binding surface */ + if (!stfb) + return; + + /* st_public.h is used */ + if (!stfb->iface) { + struct pipe_screen *screen = ctx->pipe->screen; + if (screen->update_buffer) + screen->update_buffer(screen, ctx->pipe->priv); + return; + } + + if (!p_atomic_read(&ctx->draw_buffer_invalid)) + return; + + /* validate the fb */ + if (!stfb->iface->validate(stfb->iface, &stfb->strb_att, 1, &pt) || !pt) + return; + + rb = stfb->strb; + if (rb->texture == pt) { + pipe_texture_reference(&pt, NULL); + return; + } + + /* unreference existing ones */ + pipe_surface_reference(&rb->surface, NULL); + pipe_texture_reference(&rb->texture, NULL); + + rb->texture = pt; + rb->surface = screen->get_tex_surface(screen, rb->texture, 0, 0, 0, + PIPE_BUFFER_USAGE_GPU_READ | PIPE_BUFFER_USAGE_GPU_WRITE); + + rb->width = rb->surface->width; + rb->height = rb->surface->height; + + st_resize_framebuffer(stfb, rb->width, rb->height); + + p_atomic_set(&ctx->draw_buffer_invalid, FALSE); +} + + +static void +vg_context_notify_invalid_framebuffer(struct st_context_iface *stctxi, + struct st_framebuffer_iface *stfbi) +{ + struct vg_context *ctx = (struct vg_context *) stctxi; + p_atomic_set(&ctx->draw_buffer_invalid, TRUE); +} + +static void +vg_context_flush(struct st_context_iface *stctxi, unsigned flags, + struct pipe_fence_handle **fence) +{ + struct vg_context *ctx = (struct vg_context *) stctxi; + ctx->pipe->flush(ctx->pipe, flags, fence); + if (flags & PIPE_FLUSH_RENDER_CACHE) + vg_manager_flush_frontbuffer(ctx); +} + +static void +vg_context_destroy(struct st_context_iface *stctxi) +{ + struct vg_context *ctx = (struct vg_context *) stctxi; + vg_destroy_context(ctx); +} + +static struct st_context_iface * +vg_api_create_context(struct st_api *stapi, struct st_manager *smapi, + const struct st_visual *visual, + struct st_context_iface *shared_stctxi) +{ + struct vg_context *shared_ctx = (struct vg_context *) shared_stctxi; + struct vg_context *ctx; + struct pipe_context *pipe; + + pipe = smapi->screen->context_create(smapi->screen, NULL); + if (!pipe) + return NULL; + ctx = vg_create_context(pipe, NULL, shared_ctx); + if (!ctx) { + pipe->destroy(pipe); + return NULL; + } + + ctx->iface.destroy = vg_context_destroy; + + ctx->iface.notify_invalid_framebuffer = + vg_context_notify_invalid_framebuffer; + ctx->iface.flush = vg_context_flush; + + ctx->iface.teximage = NULL; + ctx->iface.copy = NULL; + + ctx->iface.st_context_private = (void *) smapi; + + return &ctx->iface; +} + +static struct st_renderbuffer * +create_renderbuffer(enum pipe_format format) +{ + struct st_renderbuffer *strb; + + strb = CALLOC_STRUCT(st_renderbuffer); + if (strb) + strb->format = format; + + return strb; +} + +static void +destroy_renderbuffer(struct st_renderbuffer *strb) +{ + pipe_surface_reference(&strb->surface, NULL); + pipe_texture_reference(&strb->texture, NULL); + free(strb); +} + +/** + * Decide the buffer to render to. + */ +static enum st_attachment_type +choose_attachment(struct st_framebuffer_iface *stfbi) +{ + enum st_attachment_type statt; + + statt = stfbi->visual->render_buffer; + if (statt != ST_ATTACHMENT_INVALID) { + /* use the buffer given by the visual, unless it is unavailable */ + if (!st_visual_have_buffers(stfbi->visual, 1 << statt)) { + switch (statt) { + case ST_ATTACHMENT_BACK_LEFT: + statt = ST_ATTACHMENT_FRONT_LEFT; + break; + case ST_ATTACHMENT_BACK_RIGHT: + statt = ST_ATTACHMENT_FRONT_RIGHT; + break; + default: + break; + } + + if (!st_visual_have_buffers(stfbi->visual, 1 << statt)) + statt = ST_ATTACHMENT_INVALID; + } + } + + return statt; +} + +/** + * Bind the context to the given framebuffers. + */ +static boolean +vg_context_bind_framebuffers(struct st_context_iface *stctxi, + struct st_framebuffer_iface *stdrawi, + struct st_framebuffer_iface *streadi) +{ + struct vg_context *ctx = (struct vg_context *) stctxi; + struct st_framebuffer *stfb; + enum st_attachment_type strb_att; + + /* the draw and read framebuffers must be the same */ + if (stdrawi != streadi) + return FALSE; + + p_atomic_set(&ctx->draw_buffer_invalid, TRUE); + + strb_att = (stdrawi) ? choose_attachment(stdrawi) : ST_ATTACHMENT_INVALID; + + if (ctx->draw_buffer) { + stfb = ctx->draw_buffer; + + /* free the existing fb */ + if (!stdrawi || + stfb->strb_att != strb_att || + stfb->strb->format != stdrawi->visual->color_format || + stfb->dsrb->format != stdrawi->visual->depth_stencil_format) { + destroy_renderbuffer(stfb->strb); + destroy_renderbuffer(stfb->dsrb); + free(stfb); + + ctx->draw_buffer = NULL; + } + } + + if (!stdrawi) + return TRUE; + + if (strb_att == ST_ATTACHMENT_INVALID) + return FALSE; + + /* create a new fb */ + if (!ctx->draw_buffer) { + stfb = CALLOC_STRUCT(st_framebuffer); + if (!stfb) + return FALSE; + + stfb->strb = create_renderbuffer(stdrawi->visual->color_format); + if (!stfb->strb) { + free(stfb); + return FALSE; + } + + stfb->dsrb = create_renderbuffer(stdrawi->visual->depth_stencil_format); + if (!stfb->dsrb) { + free(stfb->strb); + free(stfb); + return FALSE; + } + + stfb->width = 0; + stfb->height = 0; + stfb->strb_att = strb_att; + + ctx->draw_buffer = stfb; + } + + ctx->draw_buffer->iface = stdrawi; + + return TRUE; +} + +static boolean +vg_api_make_current(struct st_api *stapi, struct st_context_iface *stctxi, + struct st_framebuffer_iface *stdrawi, + struct st_framebuffer_iface *streadi) +{ + struct vg_context *ctx = (struct vg_context *) stctxi; + + if (stctxi) + vg_context_bind_framebuffers(stctxi, stdrawi, streadi); + vg_set_current_context(ctx); + + return TRUE; +} + +static struct st_context_iface * +vg_api_get_current(struct st_api *stapi) +{ + struct vg_context *ctx = vg_current_context(); + + return (ctx) ? &ctx->iface : NULL; +} + +static boolean +vg_api_is_visual_supported(struct st_api *stapi, + const struct st_visual *visual) +{ + /* the impl requires a depth/stencil buffer */ + if (visual->depth_stencil_format == PIPE_FORMAT_NONE) + return FALSE; + + return TRUE; +} + +static st_proc_t +vg_api_get_proc_address(struct st_api *stapi, const char *procname) +{ + /* TODO */ + return (st_proc_t) NULL; +} + +static void +vg_api_destroy(struct st_api *stapi) +{ + free(stapi); +} + +static struct st_api * +vg_module_create_api(void) +{ + struct st_api *stapi; + + stapi = CALLOC_STRUCT(st_api); + if (stapi) { + stapi->destroy = vg_api_destroy; + stapi->get_proc_address = vg_api_get_proc_address; + stapi->is_visual_supported = vg_api_is_visual_supported; + + stapi->create_context = vg_api_create_context; + stapi->make_current = vg_api_make_current; + stapi->get_current = vg_api_get_current; + } + + return stapi; +} + +PUBLIC const struct st_module st_module_OpenVG = { + .api = ST_API_OPENVG, + .create_api = vg_module_create_api, +}; diff --git a/src/gallium/state_trackers/vega/vg_manager.h b/src/gallium/state_trackers/vega/vg_manager.h new file mode 100644 index 00000000000..1a276c0f35e --- /dev/null +++ b/src/gallium/state_trackers/vega/vg_manager.h @@ -0,0 +1,40 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu + */ + +#ifndef VG_MANAGER_H +#define VG_MANAGER_H + +#include "state_tracker/st_api.h" +#include "vg_context.h" + +void +vg_manager_flush_frontbuffer(struct vg_context *ctx); + +void +vg_manager_validate_framebuffer(struct vg_context *ctx); + +#endif /* VG_MANAGER_H */ -- cgit v1.2.3 From de8a879f5c77dbf5c31251e07b2f1b8d2635716c Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Sun, 7 Feb 2010 19:20:52 +0800 Subject: st/mesa: Implement st_api.h. There is currently no user of this new interface. As the inteface can coexist with st_public.h, everthing should work as before. ST_TEXTURE_2D is both defined by st_public.h and st_api.h. Reorder the headers in st/dri to avoid conflicts. --- src/gallium/state_trackers/dri/dri_context.c | 1 - src/gallium/state_trackers/dri/dri_drawable.c | 2 +- src/mesa/SConscript | 1 + src/mesa/sources.mak | 1 + src/mesa/state_tracker/st_atom.c | 5 +- src/mesa/state_tracker/st_cb_fbo.c | 18 +- src/mesa/state_tracker/st_cb_flush.c | 6 +- src/mesa/state_tracker/st_context.c | 2 +- src/mesa/state_tracker/st_context.h | 8 + src/mesa/state_tracker/st_manager.c | 781 ++++++++++++++++++++++++++ src/mesa/state_tracker/st_manager.h | 47 ++ 11 files changed, 861 insertions(+), 11 deletions(-) create mode 100644 src/mesa/state_tracker/st_manager.c create mode 100644 src/mesa/state_tracker/st_manager.h (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/dri/dri_context.c b/src/gallium/state_trackers/dri/dri_context.c index 2f991c39e33..75ac2e8adae 100644 --- a/src/gallium/state_trackers/dri/dri_context.c +++ b/src/gallium/state_trackers/dri/dri_context.c @@ -35,7 +35,6 @@ #include "state_tracker/drm_api.h" #include "state_tracker/dri1_api.h" #include "state_tracker/st_public.h" -#include "state_tracker/st_context.h" #include "pipe/p_context.h" #include "dri_context.h" diff --git a/src/gallium/state_trackers/dri/dri_drawable.c b/src/gallium/state_trackers/dri/dri_drawable.c index 458473853cf..c400725c7f2 100644 --- a/src/gallium/state_trackers/dri/dri_drawable.c +++ b/src/gallium/state_trackers/dri/dri_drawable.c @@ -39,8 +39,8 @@ #include "main/renderbuffer.h" #include "state_tracker/drm_api.h" #include "state_tracker/dri1_api.h" -#include "state_tracker/st_public.h" #include "state_tracker/st_context.h" +#include "state_tracker/st_public.h" #include "state_tracker/st_cb_fbo.h" #include "util/u_format.h" diff --git a/src/mesa/SConscript b/src/mesa/SConscript index e80ec5ee880..4db2c215d0a 100644 --- a/src/mesa/SConscript +++ b/src/mesa/SConscript @@ -182,6 +182,7 @@ if env['platform'] != 'winddk': 'state_tracker/st_format.c', 'state_tracker/st_framebuffer.c', 'state_tracker/st_gen_mipmap.c', + 'state_tracker/st_manager.c', 'state_tracker/st_mesa_to_tgsi.c', 'state_tracker/st_program.c', 'state_tracker/st_texture.c', diff --git a/src/mesa/sources.mak b/src/mesa/sources.mak index 74885548e5a..0c16fcb444c 100644 --- a/src/mesa/sources.mak +++ b/src/mesa/sources.mak @@ -213,6 +213,7 @@ STATETRACKER_SOURCES = \ state_tracker/st_format.c \ state_tracker/st_framebuffer.c \ state_tracker/st_gen_mipmap.c \ + state_tracker/st_manager.c \ state_tracker/st_mesa_to_tgsi.c \ state_tracker/st_program.c \ state_tracker/st_texture.c diff --git a/src/mesa/state_tracker/st_atom.c b/src/mesa/state_tracker/st_atom.c index 7806df4a531..9fa4dae5ca9 100644 --- a/src/mesa/state_tracker/st_atom.c +++ b/src/mesa/state_tracker/st_atom.c @@ -34,6 +34,7 @@ #include "st_atom.h" #include "st_cb_bitmap.h" #include "st_program.h" +#include "st_manager.h" #include "pipe/p_context.h" @@ -136,9 +137,7 @@ void st_validate_state( struct st_context *st ) check_program_state( st ); - if (st->pipe->screen->update_buffer) - st->pipe->screen->update_buffer(st->pipe->screen, - st->pipe->priv); + st_manager_validate_framebuffers(st); if (state->st == 0) return; diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index abf0c8d6cb1..114a8596adf 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -48,6 +48,7 @@ #include "st_format.h" #include "st_public.h" #include "st_texture.h" +#include "st_manager.h" #include "util/u_format.h" #include "util/u_rect.h" @@ -614,8 +615,18 @@ check_create_front_buffers(GLcontext *ctx, struct gl_framebuffer *fb) static void st_DrawBuffers(GLcontext *ctx, GLsizei count, const GLenum *buffers) { + GLframebuffer *fb = ctx->DrawBuffer; + GLuint i; + (void) count; (void) buffers; + + /* add the renderbuffers on demand */ + for (i = 0; i < fb->_NumColorDrawBuffers; i++) { + gl_buffer_index idx = fb->_ColorDrawBufferIndexes[i]; + st_manager_add_color_renderbuffer(ctx->st, fb, idx); + } + check_create_front_buffers(ctx, ctx->DrawBuffer); } @@ -626,8 +637,13 @@ st_DrawBuffers(GLcontext *ctx, GLsizei count, const GLenum *buffers) static void st_ReadBuffer(GLcontext *ctx, GLenum buffer) { + GLframebuffer *fb = ctx->ReadBuffer; + (void) buffer; - check_create_front_buffers(ctx, ctx->ReadBuffer); + + /* add the renderbuffer on demand */ + st_manager_add_color_renderbuffer(ctx->st, fb, fb->_ColorReadBufferIndex); + check_create_front_buffers(ctx, fb); } diff --git a/src/mesa/state_tracker/st_cb_flush.c b/src/mesa/state_tracker/st_cb_flush.c index 28a384ba49b..30e7afcf2a3 100644 --- a/src/mesa/state_tracker/st_cb_flush.c +++ b/src/mesa/state_tracker/st_cb_flush.c @@ -40,6 +40,7 @@ #include "st_cb_clear.h" #include "st_cb_fbo.h" #include "st_public.h" +#include "st_manager.h" #include "pipe/p_context.h" #include "pipe/p_defines.h" #include "pipe/p_screen.h" @@ -74,12 +75,9 @@ display_front_buffer(struct st_context *st) = st_renderbuffer(fb->Attachment[BUFFER_FRONT_LEFT].Renderbuffer); if (strb) { - struct pipe_surface *front_surf = strb->surface; - /* Hook for copying "fake" frontbuffer if necessary: */ - st->pipe->screen->flush_frontbuffer( st->pipe->screen, front_surf, - st->winsys_drawable_handle ); + st_manager_flush_frontbuffer(st); /* st->frontbuffer_status = FRONT_STATUS_UNDEFINED; diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index ca6d4dfb069..7c1a0b8bc54 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -30,9 +30,9 @@ #include "vbo/vbo.h" #include "shader/shader_api.h" #include "glapi/glapi.h" +#include "st_context.h" #include "st_public.h" #include "st_debug.h" -#include "st_context.h" #include "st_cb_accum.h" #include "st_cb_bitmap.h" #include "st_cb_blit.h" diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index e2d34fb3d10..2d81c4ca631 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -31,6 +31,7 @@ #include "main/mtypes.h" #include "shader/prog_cache.h" #include "pipe/p_state.h" +#include "state_tracker/st_api.h" struct st_context; @@ -73,6 +74,8 @@ struct st_tracked_state { struct st_context { + struct st_context_iface iface; + GLcontext *ctx; struct pipe_context *pipe; @@ -206,6 +209,11 @@ struct st_framebuffer GLframebuffer Base; void *Private; GLuint InitWidth, InitHeight; + + struct st_framebuffer_iface *iface; + enum st_attachment_type statts[ST_ATTACHMENT_COUNT]; + unsigned num_statts; + int32_t revalidate; }; diff --git a/src/mesa/state_tracker/st_manager.c b/src/mesa/state_tracker/st_manager.c new file mode 100644 index 00000000000..6c3cde09683 --- /dev/null +++ b/src/mesa/state_tracker/st_manager.c @@ -0,0 +1,781 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu + */ + +#include "state_tracker/st_api.h" + +#include "pipe/p_context.h" +#include "pipe/p_screen.h" +#include "util/u_format.h" +#include "util/u_pointer.h" +#include "util/u_inlines.h" +#include "util/u_atomic.h" + +#include "main/mtypes.h" +#include "main/context.h" +#include "main/texobj.h" +#include "main/teximage.h" +#include "main/texstate.h" +#include "main/texfetch.h" +#include "main/fbobject.h" +#include "main/framebuffer.h" +#include "main/renderbuffer.h" +#include "st_texture.h" + +#include "st_context.h" +#include "st_format.h" +#include "st_cb_fbo.h" +#include "st_manager.h" + +/* these functions are defined in st_context.c */ +struct st_context * +st_create_context(struct pipe_context *pipe, + const __GLcontextModes *visual, + struct st_context *share); +void st_destroy_context(struct st_context *st); +void st_flush(struct st_context *st, uint pipeFlushFlags, + struct pipe_fence_handle **fence); + +/** + * Map an attachment to a buffer index. + */ +static INLINE gl_buffer_index +attachment_to_buffer_index(enum st_attachment_type statt) +{ + gl_buffer_index index; + + switch (statt) { + case ST_ATTACHMENT_FRONT_LEFT: + index = BUFFER_FRONT_LEFT; + break; + case ST_ATTACHMENT_BACK_LEFT: + index = BUFFER_BACK_LEFT; + break; + case ST_ATTACHMENT_FRONT_RIGHT: + index = BUFFER_FRONT_RIGHT; + break; + case ST_ATTACHMENT_BACK_RIGHT: + index = BUFFER_BACK_RIGHT; + break; + case ST_ATTACHMENT_DEPTH_STENCIL: + index = BUFFER_DEPTH; + break; + case ST_ATTACHMENT_ACCUM: + index = BUFFER_ACCUM; + break; + case ST_ATTACHMENT_SAMPLE: + default: + index = BUFFER_COUNT; + break; + } + + return index; +} + +/** + * Map a buffer index to an attachment. + */ +static INLINE enum st_attachment_type +buffer_index_to_attachment(gl_buffer_index index) +{ + enum st_attachment_type statt; + + switch (index) { + case BUFFER_FRONT_LEFT: + statt = ST_ATTACHMENT_FRONT_LEFT; + break; + case BUFFER_BACK_LEFT: + statt = ST_ATTACHMENT_BACK_LEFT; + break; + case BUFFER_FRONT_RIGHT: + statt = ST_ATTACHMENT_FRONT_RIGHT; + break; + case BUFFER_BACK_RIGHT: + statt = ST_ATTACHMENT_BACK_RIGHT; + break; + case BUFFER_DEPTH: + statt = ST_ATTACHMENT_DEPTH_STENCIL; + break; + case BUFFER_ACCUM: + statt = ST_ATTACHMENT_ACCUM; + break; + default: + statt = ST_ATTACHMENT_INVALID; + break; + } + + return statt; +} + +/** + * Validate a framebuffer and update the states of the context. + */ +static void +st_framebuffer_validate(struct st_framebuffer *stfb, struct st_context *st) +{ + struct pipe_screen *screen = st->pipe->screen; + struct pipe_texture *textures[ST_ATTACHMENT_COUNT]; + uint width, height; + unsigned i; + boolean changed = FALSE; + + if (!p_atomic_read(&stfb->revalidate)) + return; + + /* validate the fb */ + if (!stfb->iface->validate(stfb->iface, stfb->statts, stfb->num_statts, textures)) + return; + + width = stfb->Base.Width; + height = stfb->Base.Height; + + for (i = 0; i < stfb->num_statts; i++) { + struct st_renderbuffer *strb; + struct pipe_surface *ps; + gl_buffer_index idx; + + if (!textures[i]) + continue; + + idx = attachment_to_buffer_index(stfb->statts[i]); + if (idx >= BUFFER_COUNT) { + pipe_texture_reference(&textures[i], NULL); + continue; + } + + strb = st_renderbuffer(stfb->Base.Attachment[idx].Renderbuffer); + assert(strb); + if (strb->texture == textures[i]) { + pipe_texture_reference(&textures[i], NULL); + continue; + } + + ps = screen->get_tex_surface(screen, textures[i], 0, 0, 0, + PIPE_BUFFER_USAGE_GPU_READ | PIPE_BUFFER_USAGE_GPU_WRITE); + if (ps) { + pipe_surface_reference(&strb->surface, ps); + pipe_texture_reference(&strb->texture, ps->texture); + /* ownership transfered */ + pipe_surface_reference(&ps, NULL); + + changed = TRUE; + + strb->Base.Width = strb->surface->width; + strb->Base.Height = strb->surface->height; + + width = strb->Base.Width; + height = strb->Base.Height; + } + + pipe_texture_reference(&textures[i], NULL); + } + + if (changed) { + st->dirty.st |= ST_NEW_FRAMEBUFFER; + _mesa_resize_framebuffer(st->ctx, &stfb->Base, width, height); + + assert(stfb->Base.Width == width); + assert(stfb->Base.Height == height); + } + + p_atomic_set(&stfb->revalidate, FALSE); +} + +/** + * Update the attachments to validate. + */ +static void +st_framebuffer_update_attachments(struct st_framebuffer *stfb) +{ + gl_buffer_index idx; + + stfb->num_statts = 0; + for (idx = 0; idx < BUFFER_COUNT; idx++) { + struct st_renderbuffer *strb; + enum st_attachment_type statt; + + strb = st_renderbuffer(stfb->Base.Attachment[idx].Renderbuffer); + if (!strb || strb->software) + continue; + + statt = buffer_index_to_attachment(idx); + if (statt != ST_ATTACHMENT_INVALID && + st_visual_have_buffers(stfb->iface->visual, 1 << statt)) + stfb->statts[stfb->num_statts++] = statt; + } +} + +/** + * Add a renderbuffer to the framebuffer. + */ +static boolean +st_framebuffer_add_renderbuffer(struct st_framebuffer *stfb, + gl_buffer_index idx) +{ + struct gl_renderbuffer *rb; + enum pipe_format format; + int samples; + boolean sw; + + /* do not distinguish depth/stencil buffers */ + if (idx == BUFFER_STENCIL) + idx = BUFFER_DEPTH; + + switch (idx) { + case BUFFER_DEPTH: + format = stfb->iface->visual->depth_stencil_format; + sw = FALSE; + break; + case BUFFER_ACCUM: + format = stfb->iface->visual->accum_format; + sw = TRUE; + break; + default: + format = stfb->iface->visual->color_format; + sw = FALSE; + break; + } + + if (format == PIPE_FORMAT_NONE) + return FALSE; + + samples = stfb->iface->visual->samples; + if (!samples) + samples = st_get_msaa(); + + rb = st_new_renderbuffer_fb(format, samples, sw); + if (!rb) + return FALSE; + + _mesa_add_renderbuffer(&stfb->Base, idx, rb); + if (idx == BUFFER_DEPTH) + _mesa_add_renderbuffer(&stfb->Base, BUFFER_STENCIL, rb); + + return TRUE; +} + +/** + * Intialize a __GLcontextModes from a visual. + */ +static void +st_visual_to_context_mode(const struct st_visual *visual, + __GLcontextModes *mode) +{ + memset(mode, 0, sizeof(*mode)); + + if (st_visual_have_buffers(visual, ST_ATTACHMENT_BACK_LEFT_MASK)) + mode->doubleBufferMode = GL_TRUE; + if (st_visual_have_buffers(visual, + ST_ATTACHMENT_FRONT_RIGHT_MASK | ST_ATTACHMENT_BACK_RIGHT_MASK)) + mode->stereoMode = GL_TRUE; + + if (visual->color_format != PIPE_FORMAT_NONE) { + mode->rgbMode = GL_TRUE; + + mode->redBits = + util_format_get_component_bits(visual->color_format, + UTIL_FORMAT_COLORSPACE_RGB, 0); + mode->greenBits = + util_format_get_component_bits(visual->color_format, + UTIL_FORMAT_COLORSPACE_RGB, 1); + mode->blueBits = + util_format_get_component_bits(visual->color_format, + UTIL_FORMAT_COLORSPACE_RGB, 2); + mode->alphaBits = + util_format_get_component_bits(visual->color_format, + UTIL_FORMAT_COLORSPACE_RGB, 3); + + mode->rgbBits = mode->redBits + + mode->greenBits + mode->blueBits + mode->alphaBits; + } + + if (visual->depth_stencil_format != PIPE_FORMAT_NONE) { + mode->haveDepthBuffer = GL_TRUE; + mode->haveStencilBuffer = GL_TRUE; + + mode->depthBits = + util_format_get_component_bits(visual->depth_stencil_format, + UTIL_FORMAT_COLORSPACE_ZS, 0); + mode->stencilBits = + util_format_get_component_bits(visual->depth_stencil_format, + UTIL_FORMAT_COLORSPACE_ZS, 1); + } + + if (visual->accum_format != PIPE_FORMAT_NONE) { + mode->haveAccumBuffer = GL_TRUE; + + mode->accumRedBits = + util_format_get_component_bits(visual->accum_format, + UTIL_FORMAT_COLORSPACE_RGB, 0); + mode->accumGreenBits = + util_format_get_component_bits(visual->accum_format, + UTIL_FORMAT_COLORSPACE_RGB, 1); + mode->accumBlueBits = + util_format_get_component_bits(visual->accum_format, + UTIL_FORMAT_COLORSPACE_RGB, 2); + mode->accumAlphaBits = + util_format_get_component_bits(visual->accum_format, + UTIL_FORMAT_COLORSPACE_RGB, 3); + } + + if (visual->samples) { + mode->sampleBuffers = 1; + mode->samples = visual->samples; + } +} + +/** + * Determine the default draw or read buffer from a visual. + */ +static void +st_visual_to_default_buffer(const struct st_visual *visual, + GLenum *buffer, GLint *index) +{ + enum st_attachment_type statt; + GLenum buf; + gl_buffer_index idx; + + statt = visual->render_buffer; + /* do nothing if an invalid render buffer is specified */ + if (statt == ST_ATTACHMENT_INVALID || + !st_visual_have_buffers(visual, 1 << statt)) + return; + + switch (statt) { + case ST_ATTACHMENT_FRONT_LEFT: + buf = GL_FRONT_LEFT; + idx = BUFFER_FRONT_LEFT; + break; + case ST_ATTACHMENT_BACK_LEFT: + buf = GL_BACK_LEFT; + idx = BUFFER_BACK_LEFT; + break; + case ST_ATTACHMENT_FRONT_RIGHT: + buf = GL_FRONT_RIGHT; + idx = BUFFER_FRONT_RIGHT; + break; + case ST_ATTACHMENT_BACK_RIGHT: + buf = GL_BACK_RIGHT; + idx = BUFFER_BACK_RIGHT; + break; + default: + buf = GL_NONE; + idx = BUFFER_COUNT; + break; + } + + if (buf != GL_NONE) { + if (buffer) + *buffer = buf; + if (index) + *index = idx; + } +} + +/** + * Create a framebuffer from a manager interface. + */ +static struct st_framebuffer * +st_framebuffer_create(struct st_framebuffer_iface *stfbi) +{ + struct st_framebuffer *stfb; + __GLcontextModes mode; + gl_buffer_index idx; + + stfb = CALLOC_STRUCT(st_framebuffer); + if (!stfb) + return NULL; + + st_visual_to_context_mode(stfbi->visual, &mode); + _mesa_initialize_window_framebuffer(&stfb->Base, &mode); + + /* modify the draw/read buffers of the fb */ + st_visual_to_default_buffer(stfbi->visual, &stfb->Base.ColorDrawBuffer[0], + &stfb->Base._ColorDrawBufferIndexes[0]); + st_visual_to_default_buffer(stfbi->visual, &stfb->Base.ColorReadBuffer, + &stfb->Base._ColorReadBufferIndex); + + stfb->iface = stfbi; + + /* add the color buffer */ + idx = stfb->Base._ColorDrawBufferIndexes[0]; + if (!st_framebuffer_add_renderbuffer(stfb, idx)) { + FREE(stfb); + return NULL; + } + + st_framebuffer_add_renderbuffer(stfb, BUFFER_DEPTH); + st_framebuffer_add_renderbuffer(stfb, BUFFER_ACCUM); + + st_framebuffer_update_attachments(stfb); + + p_atomic_set(&stfb->revalidate, TRUE); + stfb->Base.Initialized = GL_TRUE; + + return stfb; +} + +/** + * Reference a framebuffer. + */ +static void +st_framebuffer_reference(struct st_framebuffer **ptr, + struct st_framebuffer *stfb) +{ + GLframebuffer *fb = &stfb->Base; + _mesa_reference_framebuffer((GLframebuffer **) ptr, fb); +} + +static void +st_context_notify_invalid_framebuffer(struct st_context_iface *stctxi, + struct st_framebuffer_iface *stfbi) +{ + struct st_context *st = (struct st_context *) stctxi; + struct st_framebuffer *stfb; + + /* either draw or read winsys fb */ + stfb = (struct st_framebuffer *) st->ctx->WinSysDrawBuffer; + if (!stfb || stfb->iface != stfbi) + stfb = (struct st_framebuffer *) st->ctx->WinSysReadBuffer; + assert(stfb && stfb->iface == stfbi); + + p_atomic_set(&stfb->revalidate, TRUE); +} + +static void +st_context_flush(struct st_context_iface *stctxi, unsigned flags, + struct pipe_fence_handle **fence) +{ + struct st_context *st = (struct st_context *) stctxi; + st_flush(st, flags, fence); + if (flags & PIPE_FLUSH_RENDER_CACHE) + st_manager_flush_frontbuffer(st); +} + +static boolean +st_context_teximage(struct st_context_iface *stctxi, enum st_texture_type target, + int level, enum pipe_format internal_format, + struct pipe_texture *tex, boolean mipmap) +{ + struct st_context *st = (struct st_context *) stctxi; + GLcontext *ctx = st->ctx; + struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx); + struct gl_texture_object *texObj; + struct gl_texture_image *texImage; + struct st_texture_object *stObj; + struct st_texture_image *stImage; + GLenum internalFormat; + + switch (target) { + case ST_TEXTURE_1D: + target = GL_TEXTURE_1D; + break; + case ST_TEXTURE_2D: + target = GL_TEXTURE_2D; + break; + case ST_TEXTURE_3D: + target = GL_TEXTURE_3D; + break; + case ST_TEXTURE_RECT: + target = GL_TEXTURE_RECTANGLE_ARB; + break; + default: + return FALSE; + break; + } + + if (util_format_get_component_bits(internal_format, + UTIL_FORMAT_COLORSPACE_RGB, 3) > 0) + internalFormat = GL_RGBA; + else + internalFormat = GL_RGB; + + texObj = _mesa_select_tex_object(ctx, texUnit, target); + _mesa_lock_texture(ctx, texObj); + + stObj = st_texture_object(texObj); + /* switch to surface based */ + if (!stObj->surface_based) { + _mesa_clear_texture_object(ctx, texObj); + stObj->surface_based = GL_TRUE; + } + + texImage = _mesa_get_tex_image(ctx, texObj, target, level); + stImage = st_texture_image(texImage); + if (tex) { + _mesa_init_teximage_fields(ctx, target, texImage, + tex->width0, tex->height0, 1, 0, internalFormat); + texImage->TexFormat = st_ChooseTextureFormat(ctx, internalFormat, + GL_RGBA, GL_UNSIGNED_BYTE); + _mesa_set_fetch_functions(texImage, 2); + } + else { + _mesa_clear_texture_image(ctx, texImage); + } + + pipe_texture_reference(&stImage->pt, tex); + + _mesa_dirty_texobj(ctx, texObj, GL_TRUE); + _mesa_unlock_texture(ctx, texObj); + + return TRUE; +} + +static void +st_context_destroy(struct st_context_iface *stctxi) +{ + struct st_context *st = (struct st_context *) stctxi; + st_destroy_context(st); +} + +static struct st_context_iface * +st_api_create_context(struct st_api *stapi, struct st_manager *smapi, + const struct st_visual *visual, + struct st_context_iface *shared_stctxi) +{ + struct st_context *shared_ctx = (struct st_context *) shared_stctxi; + struct st_context *st; + struct pipe_context *pipe; + __GLcontextModes mode; + + pipe = smapi->screen->context_create(smapi->screen, NULL); + if (!pipe) + return NULL; + + st_visual_to_context_mode(visual, &mode); + st = st_create_context(pipe, &mode, shared_ctx); + if (!st) { + pipe->destroy(pipe); + return NULL; + } + + st->iface.destroy = st_context_destroy; + + st->iface.notify_invalid_framebuffer = + st_context_notify_invalid_framebuffer; + st->iface.flush = st_context_flush; + + st->iface.teximage = st_context_teximage; + st->iface.copy = NULL; + + st->iface.st_context_private = (void *) smapi; + + return &st->iface; +} + +static boolean +st_api_make_current(struct st_api *stapi, struct st_context_iface *stctxi, + struct st_framebuffer_iface *stdrawi, + struct st_framebuffer_iface *streadi) +{ + struct st_context *st = (struct st_context *) stctxi; + struct st_framebuffer *stdraw, *stread, *stfb; + boolean ret; + + _glapi_check_multithread(); + + if (st) { + /* reuse/create the draw fb */ + stfb = (struct st_framebuffer * ) st->ctx->DrawBuffer; + if (stfb && stfb->iface == stdrawi) { + stdraw = NULL; + st_framebuffer_reference(&stdraw, stfb); + } + else { + stdraw = st_framebuffer_create(stdrawi); + } + + /* reuse/create the read fb */ + stfb = (struct st_framebuffer * ) st->ctx->ReadBuffer; + if (!stfb || stfb->iface != streadi) + stfb = stdraw; + if (stfb && stfb->iface == streadi) { + stread = NULL; + st_framebuffer_reference(&stread, stfb); + } + else { + stread = st_framebuffer_create(streadi); + } + + if (stdraw && stread) { + st_framebuffer_validate(stdraw, st); + if (stread != stdraw) + st_framebuffer_validate(stread, st); + + /* modify the draw/read buffers of the context */ + st_visual_to_default_buffer(stdraw->iface->visual, + &st->ctx->Color.DrawBuffer[0], NULL); + st_visual_to_default_buffer(stread->iface->visual, + &st->ctx->Pixel.ReadBuffer, NULL); + + ret = _mesa_make_current(st->ctx, &stdraw->Base, &stread->Base); + } + else { + ret = FALSE; + } + + st_framebuffer_reference(&stdraw, NULL); + st_framebuffer_reference(&stread, NULL); + } + else { + ret = _mesa_make_current(NULL, NULL, NULL); + } + + return ret; +} + +static struct st_context_iface * +st_api_get_current(struct st_api *stapi) +{ + GET_CURRENT_CONTEXT(ctx); + struct st_context *st = (ctx) ? ctx->st : NULL; + + return (st) ? &st->iface : NULL; +} + +static boolean +st_api_is_visual_supported(struct st_api *stapi, + const struct st_visual *visual) +{ + return TRUE; +} + +static st_proc_t +st_api_get_proc_address(struct st_api *stapi, const char *procname) +{ + return (st_proc_t) _glapi_get_proc_address(procname); +} + +static void +st_api_destroy(struct st_api *stapi) +{ + FREE(stapi); +} + +/** + * Flush the front buffer if the current context renders to the front buffer. + */ +void +st_manager_flush_frontbuffer(struct st_context *st) +{ + struct st_framebuffer *stfb = (struct st_framebuffer *) st->ctx->DrawBuffer; + struct st_renderbuffer *strb = NULL; + + if (stfb) + strb = st_renderbuffer(stfb->Base.Attachment[BUFFER_FRONT_LEFT].Renderbuffer); + if (!strb) + return; + + /* st_public.h or FBO */ + if (!stfb->iface) { + struct pipe_surface *front_surf = strb->surface; + st->pipe->screen->flush_frontbuffer(st->pipe->screen, + front_surf, st->winsys_drawable_handle); + return; + } + + stfb->iface->flush_front(stfb->iface, ST_ATTACHMENT_FRONT_LEFT); +} + +/** + * Re-validate the framebuffer. + */ +void +st_manager_validate_framebuffers(struct st_context *st) +{ + struct st_framebuffer *stdraw, *stread; + + stdraw = (struct st_framebuffer *) st->ctx->DrawBuffer; + stread = (struct st_framebuffer *) st->ctx->ReadBuffer; + + /* st_public.h or FBO */ + if ((stdraw && !stdraw->iface) || (stread && !stread->iface)) { + struct pipe_screen *screen = st->pipe->screen; + if (screen->update_buffer) + screen->update_buffer(screen, st->pipe->priv); + return; + } + + if (stdraw) + st_framebuffer_validate(stdraw, st); + if (stread && stread != stdraw) + st_framebuffer_validate(stread, st); +} + +/** + * Add a color buffer on demand. + */ +boolean +st_manager_add_color_renderbuffer(struct st_context *st, GLframebuffer *fb, + gl_buffer_index idx) +{ + struct st_framebuffer *stfb = (struct st_framebuffer *) fb; + + if (stfb->Base.Attachment[idx].Renderbuffer) + return TRUE; + + /* st_public.h or FBO */ + if (!stfb->iface) + return FALSE; + + switch (idx) { + case BUFFER_FRONT_LEFT: + case BUFFER_BACK_LEFT: + case BUFFER_FRONT_RIGHT: + case BUFFER_BACK_RIGHT: + break; + default: + return FALSE; + break; + } + + if (!st_framebuffer_add_renderbuffer(stfb, idx)) + return FALSE; + + st_framebuffer_update_attachments(stfb); + st_invalidate_state(st->ctx, _NEW_BUFFERS); + + return TRUE; +} + +struct st_api * +st_manager_create_api(void) +{ + struct st_api *stapi; + + stapi = CALLOC_STRUCT(st_api); + if (stapi) { + stapi->destroy = st_api_destroy; + stapi->get_proc_address = st_api_get_proc_address; + stapi->is_visual_supported = st_api_is_visual_supported; + + stapi->create_context = st_api_create_context; + stapi->make_current = st_api_make_current; + stapi->get_current = st_api_get_current; + } + + return stapi; +} diff --git a/src/mesa/state_tracker/st_manager.h b/src/mesa/state_tracker/st_manager.h new file mode 100644 index 00000000000..a3f51992237 --- /dev/null +++ b/src/mesa/state_tracker/st_manager.h @@ -0,0 +1,47 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu + */ + +#ifndef ST_MANAGER_H +#define ST_MANAGER_H + +#include "state_tracker/st_api.h" +#include "st_context.h" + +void +st_manager_flush_frontbuffer(struct st_context *st); + +void +st_manager_validate_framebuffers(struct st_context *st); + +boolean +st_manager_add_color_renderbuffer(struct st_context *st, GLframebuffer *fb, + gl_buffer_index idx); + +struct st_api * +st_manager_create_api(void); + +#endif /* ST_MANAGER_H */ -- cgit v1.2.3 From 3a3a31bf88c42890fbc2e4211981f97bd43dff4a Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Sun, 7 Feb 2010 20:17:48 +0800 Subject: winsys/xlib, st/es: Advertise st_api.h support. This is done by defining one of st_module_OpenGL_ES1, st_module_OpenGL_ES2, and st_module_OpenGL. --- src/gallium/state_trackers/es/Makefile | 1 + src/gallium/state_trackers/es/st_es1.c | 7 ++++++- src/gallium/state_trackers/es/st_es2.c | 7 ++++++- src/gallium/targets/libgl-xlib/xlib.c | 6 ++++++ 4 files changed, 19 insertions(+), 2 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/es/Makefile b/src/gallium/state_trackers/es/Makefile index b0365512719..e33685d2471 100644 --- a/src/gallium/state_trackers/es/Makefile +++ b/src/gallium/state_trackers/es/Makefile @@ -38,6 +38,7 @@ SYS_LIBS = -lm -pthread INCLUDE_DIRS = \ + -I$(TOP)/src/mesa \ -I$(TOP)/src/gallium/include .c.o: diff --git a/src/gallium/state_trackers/es/st_es1.c b/src/gallium/state_trackers/es/st_es1.c index 25bc53b21eb..4e89e06b34c 100644 --- a/src/gallium/state_trackers/es/st_es1.c +++ b/src/gallium/state_trackers/es/st_es1.c @@ -1,3 +1,8 @@ -#include "pipe/p_compiler.h" +#include "state_tracker/st_manager.h" PUBLIC const int st_api_OpenGL_ES1 = 1; + +PUBLIC const struct st_module st_module_OpenGL_ES1 = { + .api = ST_API_OPENGL_ES1, + .create_api = st_manager_create_api +}; diff --git a/src/gallium/state_trackers/es/st_es2.c b/src/gallium/state_trackers/es/st_es2.c index 171ea62b97f..82e88b176ac 100644 --- a/src/gallium/state_trackers/es/st_es2.c +++ b/src/gallium/state_trackers/es/st_es2.c @@ -1,3 +1,8 @@ -#include "pipe/p_compiler.h" +#include "state_tracker/st_manager.h" PUBLIC const int st_api_OpenGL_ES2 = 1; + +PUBLIC const struct st_module st_module_OpenGL_ES2 = { + .api = ST_API_OPENGL_ES2, + .create_api = st_manager_create_api +}; diff --git a/src/gallium/targets/libgl-xlib/xlib.c b/src/gallium/targets/libgl-xlib/xlib.c index 05dc8db57d9..50dd99ffce1 100644 --- a/src/gallium/targets/libgl-xlib/xlib.c +++ b/src/gallium/targets/libgl-xlib/xlib.c @@ -39,9 +39,15 @@ #include "target-helpers/wrap_screen.h" #include "xm_public.h" +#include "state_tracker/st_manager.h" + /* advertise OpenGL support */ PUBLIC const int st_api_OpenGL = 1; +PUBLIC const struct st_module st_module_OpenGL = { + .api = ST_API_OPENGL, + .create_api = st_manager_create_api +}; /* Helper function to build a subset of a driver stack consisting of * one of the software rasterizers (cell, llvmpipe, softpipe) and the -- cgit v1.2.3 From a924dd18c32bbc0056a799cf621dc2835644c16e Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Thu, 14 Jan 2010 16:05:36 +0800 Subject: st/egl: Use st_api.h instead of st_public.h. Switch from st_public.h to st_api.h. The latter has intrinsic multiple APIs support and allows various EGLImage extensions to be supported. --- src/gallium/state_trackers/egl/common/egl_g3d.c | 562 +++++++-------------- src/gallium/state_trackers/egl/common/egl_g3d.h | 24 +- src/gallium/state_trackers/egl/common/egl_g3d_st.c | 227 +++++++++ src/gallium/state_trackers/egl/common/egl_g3d_st.h | 79 +++ src/gallium/state_trackers/egl/common/egl_st.c | 131 ----- src/gallium/state_trackers/egl/common/egl_st.h | 73 --- .../state_trackers/egl/common/st_public_tmp.h | 20 - 7 files changed, 507 insertions(+), 609 deletions(-) create mode 100644 src/gallium/state_trackers/egl/common/egl_g3d_st.c create mode 100644 src/gallium/state_trackers/egl/common/egl_g3d_st.h delete mode 100644 src/gallium/state_trackers/egl/common/egl_st.c delete mode 100644 src/gallium/state_trackers/egl/common/egl_st.h delete mode 100644 src/gallium/state_trackers/egl/common/st_public_tmp.h (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/egl/common/egl_g3d.c b/src/gallium/state_trackers/egl/common/egl_g3d.c index e4972d493d6..783b8e56b38 100644 --- a/src/gallium/state_trackers/egl/common/egl_g3d.c +++ b/src/gallium/state_trackers/egl/common/egl_g3d.c @@ -36,234 +36,27 @@ #include "native.h" #include "egl_g3d.h" +#include "egl_g3d_st.h" #include "egl_g3d_image.h" -#include "egl_st.h" - -/** - * Validate the draw/read surfaces of the context. - */ -static void -egl_g3d_validate_context(_EGLDisplay *dpy, _EGLContext *ctx) -{ - struct egl_g3d_display *gdpy = egl_g3d_display(dpy); - struct pipe_screen *screen = gdpy->native->screen; - struct egl_g3d_context *gctx = egl_g3d_context(ctx); - const uint st_att_map[NUM_NATIVE_ATTACHMENTS] = { - ST_SURFACE_FRONT_LEFT, - ST_SURFACE_BACK_LEFT, - ST_SURFACE_FRONT_RIGHT, - ST_SURFACE_BACK_RIGHT, - }; - EGLint num_surfaces, s; - - /* validate draw and/or read buffers */ - num_surfaces = (gctx->base.ReadSurface == gctx->base.DrawSurface) ? 1 : 2; - for (s = 0; s < num_surfaces; s++) { - struct pipe_texture *textures[NUM_NATIVE_ATTACHMENTS]; - struct egl_g3d_surface *gsurf; - struct egl_g3d_buffer *gbuf; - EGLint att; - - if (s == 0) { - gsurf = egl_g3d_surface(gctx->base.DrawSurface); - gbuf = &gctx->draw; - } - else { - gsurf = egl_g3d_surface(gctx->base.ReadSurface); - gbuf = &gctx->read; - } - - if (!gctx->force_validate) { - unsigned int seq_num; - - gsurf->native->validate(gsurf->native, gbuf->attachment_mask, - &seq_num, NULL, NULL, NULL); - /* skip validation */ - if (gsurf->sequence_number == seq_num) - continue; - } - - pipe_surface_reference(&gsurf->render_surface, NULL); - memset(textures, 0, sizeof(textures)); - - gsurf->native->validate(gsurf->native, gbuf->attachment_mask, - &gsurf->sequence_number, textures, - &gsurf->base.Width, &gsurf->base.Height); - for (att = 0; att < NUM_NATIVE_ATTACHMENTS; att++) { - struct pipe_texture *pt = textures[att]; - struct pipe_surface *ps; - - if (native_attachment_mask_test(gbuf->attachment_mask, att) && pt) { - ps = screen->get_tex_surface(screen, pt, 0, 0, 0, - PIPE_BUFFER_USAGE_GPU_READ | - PIPE_BUFFER_USAGE_GPU_WRITE); - gctx->stapi->st_set_framebuffer_surface(gbuf->st_fb, - st_att_map[att], ps); - - if (gsurf->render_att == att) - pipe_surface_reference(&gsurf->render_surface, ps); - - pipe_surface_reference(&ps, NULL); - pipe_texture_reference(&pt, NULL); - } - } - - gctx->stapi->st_resize_framebuffer(gbuf->st_fb, - gsurf->base.Width, gsurf->base.Height); - } - - gctx->force_validate = EGL_FALSE; - -} - -/** - * Create a st_framebuffer. - */ -static struct st_framebuffer * -create_framebuffer(_EGLContext *ctx, _EGLSurface *surf) -{ - struct egl_g3d_context *gctx = egl_g3d_context(ctx); - struct egl_g3d_surface *gsurf = egl_g3d_surface(surf); - struct egl_g3d_config *gconf = egl_g3d_config(gsurf->base.Config); - - return gctx->stapi->st_create_framebuffer(&gconf->native->mode, - gconf->native->color_format, gconf->native->depth_format, - gconf->native->stencil_format, - gsurf->base.Width, gsurf->base.Height, &gsurf->base); -} - -/** - * Update the attachments of draw/read surfaces. - */ -static void -egl_g3d_route_context(_EGLDisplay *dpy, _EGLContext *ctx) -{ - struct egl_g3d_context *gctx = egl_g3d_context(ctx); - EGLint s; - - /* route draw and read buffers' attachments */ - for (s = 0; s < 2; s++) { - struct egl_g3d_surface *gsurf; - struct egl_g3d_buffer *gbuf; - - if (s == 0) { - gsurf = egl_g3d_surface(gctx->base.DrawSurface); - gbuf = &gctx->draw; - } - else { - gsurf = egl_g3d_surface(gctx->base.ReadSurface); - gbuf = &gctx->read; - } - - gbuf->attachment_mask = (1 << gsurf->render_att); - - /* FIXME OpenGL defaults to draw the front or back buffer when the - * context is single-buffered or double-buffered respectively. In EGL, - * however, the buffer to be drawn is determined by the surface, instead - * of the context. As a result, rendering to a pixmap surface with a - * double-buffered context does not work as expected. - * - * gctx->stapi->st_draw_front_buffer(gctx->st_ctx, natt == - * NATIVE_ATTACHMENT_FRONT_LEFT); - */ - - /* - * FIXME If the back buffer is asked for here, and the front buffer is - * later needed by the client API (e.g. glDrawBuffer is called to draw - * the front buffer), it will create a new pipe texture and draw there. - * One fix is to ask for both buffers here, but it would be a waste if - * the front buffer is never used. A better fix is to add a callback to - * the pipe screen with context private (just like flush_frontbuffer). - */ - } -} - -/** - * Reallocate the context's framebuffers after draw/read surfaces change. - */ -static EGLBoolean -egl_g3d_realloc_context(_EGLDisplay *dpy, _EGLContext *ctx) -{ - struct egl_g3d_context *gctx = egl_g3d_context(ctx); - struct egl_g3d_surface *gdraw = egl_g3d_surface(gctx->base.DrawSurface); - struct egl_g3d_surface *gread = egl_g3d_surface(gctx->base.ReadSurface); - - /* unreference the old framebuffers */ - if (gctx->draw.st_fb) { - EGLBoolean is_equal = (gctx->draw.st_fb == gctx->read.st_fb); - void *priv; - - priv = gctx->stapi->st_framebuffer_private(gctx->draw.st_fb); - if (!gdraw || priv != (void *) &gdraw->base) { - gctx->stapi->st_unreference_framebuffer(gctx->draw.st_fb); - gctx->draw.st_fb = NULL; - gctx->draw.attachment_mask = 0x0; - } - - if (is_equal) { - gctx->read.st_fb = NULL; - gctx->draw.attachment_mask = 0x0; - } - else { - priv = gctx->stapi->st_framebuffer_private(gctx->read.st_fb); - if (!gread || priv != (void *) &gread->base) { - gctx->stapi->st_unreference_framebuffer(gctx->read.st_fb); - gctx->read.st_fb = NULL; - gctx->draw.attachment_mask = 0x0; - } - } - } - - if (!gdraw) - return EGL_TRUE; - - /* create the draw fb */ - if (!gctx->draw.st_fb) { - gctx->draw.st_fb = create_framebuffer(&gctx->base, &gdraw->base); - if (!gctx->draw.st_fb) - return EGL_FALSE; - } - - /* create the read fb */ - if (!gctx->read.st_fb) { - if (gread != gdraw) { - gctx->read.st_fb = create_framebuffer(&gctx->base, &gread->base); - if (!gctx->read.st_fb) { - gctx->stapi->st_unreference_framebuffer(gctx->draw.st_fb); - gctx->draw.st_fb = NULL; - return EGL_FALSE; - } - } - else { - /* there is no st_reference_framebuffer... */ - gctx->read.st_fb = gctx->draw.st_fb; - } - } - - egl_g3d_route_context(dpy, &gctx->base); - gctx->force_validate = EGL_TRUE; - - return EGL_TRUE; -} /** * Return the state tracker for the given context. */ -static const struct egl_g3d_st * +static struct st_api * egl_g3d_choose_st(_EGLDriver *drv, _EGLContext *ctx) { struct egl_g3d_driver *gdrv = egl_g3d_driver(drv); - const struct egl_g3d_st *stapi; + struct st_api *stapi; EGLint idx = -1; switch (ctx->ClientAPI) { case EGL_OPENGL_ES_API: switch (ctx->ClientVersion) { case 1: - idx = EGL_G3D_ST_OPENGL_ES; + idx = ST_API_OPENGL_ES1; break; case 2: - idx = EGL_G3D_ST_OPENGL_ES2; + idx = ST_API_OPENGL_ES2; break; default: _eglLog(_EGL_WARNING, "unknown client version %d", @@ -272,10 +65,10 @@ egl_g3d_choose_st(_EGLDriver *drv, _EGLContext *ctx) } break; case EGL_OPENVG_API: - idx = EGL_G3D_ST_OPENVG; + idx = ST_API_OPENVG; break; case EGL_OPENGL_API: - idx = EGL_G3D_ST_OPENGL; + idx = ST_API_OPENGL; break; default: _eglLog(_EGL_WARNING, "unknown client API 0x%04x", ctx->ClientAPI); @@ -299,10 +92,10 @@ egl_g3d_init_st(_EGLDriver *drv) if (gdrv->api_mask) return; - for (i = 0; i < NUM_EGL_G3D_STS; i++) { - gdrv->stapis[i] = egl_g3d_get_st(i); + for (i = 0; i < ST_API_COUNT; i++) { + gdrv->stapis[i] = egl_g3d_create_st_api(i); if (gdrv->stapis[i]) - gdrv->api_mask |= gdrv->stapis[i]->api_bit; + gdrv->api_mask |= egl_g3d_st_api_bit(i); } if (gdrv->api_mask) @@ -351,35 +144,6 @@ egl_g3d_destroy_probe(_EGLDriver *drv, _EGLDisplay *dpy) } } -/** - * Return an API mask that consists of the state trackers that supports the - * given mode. - * - * FIXME add st_is_mode_supported()? - */ -static EGLint -get_mode_api_mask(const __GLcontextModes *mode, EGLint api_mask) -{ - EGLint check; - - /* OpenGL ES 1.x and 2.x are checked together */ - check = EGL_OPENGL_ES_BIT | EGL_OPENGL_ES2_BIT; - if (api_mask & check) { - /* this is required by EGL, not by OpenGL ES */ - if (mode->drawableType & GLX_WINDOW_BIT && !mode->doubleBufferMode) - api_mask &= ~check; - } - - check = EGL_OPENVG_BIT; - if (api_mask & check) { - /* vega st needs the depth/stencil rb */ - if (!mode->depthBits && !mode->stencilBits) - api_mask &= ~check; - } - - return api_mask; -} - #ifdef EGL_MESA_screen_surface static void @@ -443,19 +207,89 @@ egl_g3d_add_screens(_EGLDriver *drv, _EGLDisplay *dpy) #endif /* EGL_MESA_screen_surface */ +/** + * Initialize an EGL config from the native config. + */ +static EGLBoolean +egl_g3d_init_config(_EGLDriver *drv, _EGLDisplay *dpy, + _EGLConfig *conf, const struct native_config *nconf) +{ + struct egl_g3d_driver *gdrv = egl_g3d_driver(drv); + struct egl_g3d_config *gconf = egl_g3d_config(conf); + const __GLcontextModes *mode = &nconf->mode; + EGLint buffer_mask, api_mask; + EGLBoolean valid; + EGLint i; + + buffer_mask = ST_ATTACHMENT_FRONT_LEFT_MASK; + if (mode->doubleBufferMode) + buffer_mask |= ST_ATTACHMENT_BACK_LEFT_MASK; + if (mode->stereoMode) { + buffer_mask |= ST_ATTACHMENT_FRONT_RIGHT_MASK; + if (mode->doubleBufferMode) + buffer_mask |= ST_ATTACHMENT_BACK_RIGHT_MASK; + } + + gconf->stvis.buffer_mask = buffer_mask; + gconf->stvis.color_format = nconf->color_format; + gconf->stvis.depth_stencil_format = nconf->depth_format; + gconf->stvis.accum_format = PIPE_FORMAT_NONE; + gconf->stvis.samples = 0; + + gconf->stvis.render_buffer = (buffer_mask & ST_ATTACHMENT_BACK_LEFT) ? + ST_ATTACHMENT_BACK_LEFT : ST_ATTACHMENT_FRONT_LEFT; + + api_mask = 0; + for (i = 0; i < ST_API_COUNT; i++) { + struct st_api *stapi = gdrv->stapis[i]; + if (stapi) { + if (stapi->is_visual_supported(stapi, &gconf->stvis)) + api_mask |= egl_g3d_st_api_bit(i); + } + } + /* this is required by EGL, not by OpenGL ES */ + if ((mode->drawableType & GLX_WINDOW_BIT) && !mode->doubleBufferMode) + api_mask &= ~(EGL_OPENGL_ES_BIT | EGL_OPENGL_ES2_BIT); + + if (!api_mask) { + _eglLog(_EGL_DEBUG, "no state tracker supports config 0x%x", + mode->visualID); + } + + valid = _eglConfigFromContextModesRec(&gconf->base, + mode, api_mask, api_mask); + if (valid) { +#ifdef EGL_MESA_screen_surface + /* check if scanout surface bit is set */ + if (nconf->scanout_bit) { + EGLint val = GET_CONFIG_ATTRIB(&gconf->base, EGL_SURFACE_TYPE); + val |= EGL_SCREEN_BIT_MESA; + SET_CONFIG_ATTRIB(&gconf->base, EGL_SURFACE_TYPE, val); + } +#endif + valid = _eglValidateConfig(&gconf->base, EGL_FALSE); + } + if (!valid) { + _eglLog(_EGL_DEBUG, "skip invalid config 0x%x", mode->visualID); + return EGL_FALSE; + } + + gconf->native = nconf; + + return EGL_TRUE; +} + /** * Add configs to display and return the next config ID. */ static EGLint egl_g3d_add_configs(_EGLDriver *drv, _EGLDisplay *dpy, EGLint id) { - struct egl_g3d_driver *gdrv = egl_g3d_driver(drv); struct egl_g3d_display *gdpy = egl_g3d_display(dpy); const struct native_config **native_configs; int num_configs, i; - native_configs = gdpy->native->get_configs(gdpy->native, - &num_configs); + native_configs = gdpy->native->get_configs(gdpy->native, &num_configs); if (!num_configs) { if (native_configs) free(native_configs); @@ -463,61 +297,25 @@ egl_g3d_add_configs(_EGLDriver *drv, _EGLDisplay *dpy, EGLint id) } for (i = 0; i < num_configs; i++) { - EGLint api_mask; struct egl_g3d_config *gconf; - EGLBoolean valid; gconf = CALLOC_STRUCT(egl_g3d_config); - if (!gconf) - continue; - - _eglInitConfig(&gconf->base, dpy, id); - - api_mask = get_mode_api_mask(&native_configs[i]->mode, gdrv->api_mask); - if (!api_mask) { - _eglLog(_EGL_DEBUG, "no state tracker supports config 0x%x", - native_configs[i]->mode.visualID); - } - - valid = _eglConfigFromContextModesRec(&gconf->base, - &native_configs[i]->mode, api_mask, api_mask); - if (valid) { -#ifdef EGL_MESA_screen_surface - /* check if scanout surface bit is set */ - if (native_configs[i]->scanout_bit) { - EGLint val = GET_CONFIG_ATTRIB(&gconf->base, EGL_SURFACE_TYPE); - val |= EGL_SCREEN_BIT_MESA; - SET_CONFIG_ATTRIB(&gconf->base, EGL_SURFACE_TYPE, val); + if (gconf) { + _eglInitConfig(&gconf->base, dpy, id); + if (!egl_g3d_init_config(drv, dpy, &gconf->base, native_configs[i])) { + free(gconf); + continue; } -#endif - valid = _eglValidateConfig(&gconf->base, EGL_FALSE); - } - if (!valid) { - _eglLog(_EGL_DEBUG, "skip invalid config 0x%x", - native_configs[i]->mode.visualID); - free(gconf); - continue; - } - gconf->native = native_configs[i]; - _eglAddConfig(dpy, &gconf->base); - id++; + _eglAddConfig(dpy, &gconf->base); + id++; + } } free(native_configs); return id; } -/** - * Re-validate the context. - */ -static void -egl_g3d_update_buffer(struct pipe_screen *screen, void *context_private) -{ - struct egl_g3d_context *gctx = egl_g3d_context(context_private); - egl_g3d_validate_context(gctx->base.Resource.Display, &gctx->base); -} - static void egl_g3d_invalid_surface(struct native_display *ndpy, struct native_surface *nsurf, @@ -527,9 +325,8 @@ egl_g3d_invalid_surface(struct native_display *ndpy, struct egl_g3d_surface *gsurf = egl_g3d_surface(nsurf->user_data); struct egl_g3d_context *gctx = egl_g3d_context(gsurf->base.CurrentContext); - /* set force_validate to skip an unnecessary check */ if (gctx) - gctx->force_validate = TRUE; + gctx->stctxi->notify_invalid_framebuffer(gctx->stctxi, gsurf->stfbi); } static struct native_event_handler egl_g3d_native_event_handler = { @@ -554,6 +351,9 @@ egl_g3d_terminate(_EGLDriver *drv, _EGLDisplay *dpy) free(dpy->Screens); } + if (gdpy->smapi) + egl_g3d_destroy_st_manager(gdpy->smapi); + if (gdpy->native) gdpy->native->destroy(gdpy->native); @@ -588,11 +388,17 @@ egl_g3d_initialize(_EGLDriver *drv, _EGLDisplay *dpy, } gdpy->native->user_data = (void *) dpy; - gdpy->native->screen->update_buffer = egl_g3d_update_buffer; egl_g3d_init_st(&gdrv->base); dpy->ClientAPIsMask = gdrv->api_mask; + gdpy->smapi = egl_g3d_create_st_manager(dpy); + if (!gdpy->smapi) { + _eglError(EGL_NOT_INITIALIZED, + "eglInitialize(failed to create st manager)"); + goto fail; + } + #ifdef EGL_MESA_screen_surface /* enable MESA_screen_surface before adding (and validating) configs */ if (gdpy->native->modeset) { @@ -629,7 +435,6 @@ egl_g3d_create_context(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, struct egl_g3d_context *gshare = egl_g3d_context(share); struct egl_g3d_config *gconf = egl_g3d_config(conf); struct egl_g3d_context *gctx; - const __GLcontextModes *mode; gctx = CALLOC_STRUCT(egl_g3d_context); if (!gctx) { @@ -648,24 +453,14 @@ egl_g3d_create_context(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, return NULL; } - mode = &gconf->native->mode; - - gctx->pipe = gdpy->native->screen->context_create( - gdpy->native->screen, - (void *) &gctx->base); - - if (!gctx->pipe) { + gctx->stctxi = gctx->stapi->create_context(gctx->stapi, gdpy->smapi, + &gconf->stvis, (gshare) ? gshare->stctxi : NULL); + if (!gctx->stctxi) { free(gctx); return NULL; } - gctx->st_ctx = gctx->stapi->st_create_context(gctx->pipe, mode, - (gshare) ? gshare->st_ctx : NULL); - if (!gctx->st_ctx) { - gctx->pipe->destroy(gctx->pipe); - free(gctx); - return NULL; - } + gctx->stctxi->st_manager_private = (void *) &gctx->base; return &gctx->base; } @@ -682,9 +477,7 @@ destroy_context(_EGLDisplay *dpy, _EGLContext *ctx) if (!dpy->Initialized) _eglLog(_EGL_FATAL, "destroy a context with an unitialized display"); - egl_g3d_realloc_context(dpy, &gctx->base); - /* it will destroy the associated pipe context */ - gctx->stapi->st_destroy_context(gctx->st_ctx); + gctx->stctxi->destroy(gctx->stctxi); free(gctx); } @@ -786,14 +579,20 @@ egl_g3d_create_surface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, return NULL; } + gsurf->stvis = gconf->stvis; + if (gsurf->base.RenderBuffer == EGL_SINGLE_BUFFER) + gsurf->stvis.render_buffer = ST_ATTACHMENT_FRONT_LEFT; + + gsurf->stfbi = egl_g3d_create_st_framebuffer(&gsurf->base); + if (!gsurf->stfbi) { + gsurf->native->destroy(gsurf->native); + free(gsurf); + return NULL; + } + nsurf->user_data = &gsurf->base; gsurf->native = nsurf; - gsurf->render_att = (gsurf->base.RenderBuffer == EGL_SINGLE_BUFFER) ? - NATIVE_ATTACHMENT_FRONT_LEFT : NATIVE_ATTACHMENT_BACK_LEFT; - if (!gconf->native->mode.doubleBufferMode) - gsurf->render_att = NATIVE_ATTACHMENT_FRONT_LEFT; - return &gsurf->base; } @@ -849,7 +648,8 @@ destroy_surface(_EGLDisplay *dpy, _EGLSurface *surf) if (!dpy->Initialized) _eglLog(_EGL_FATAL, "destroy a surface with an unitialized display"); - pipe_surface_reference(&gsurf->render_surface, NULL); + pipe_texture_reference(&gsurf->render_texture, NULL); + egl_g3d_destroy_st_framebuffer(gsurf->stfbi); gsurf->native->destroy(gsurf->native); free(gsurf); } @@ -868,6 +668,7 @@ egl_g3d_make_current(_EGLDriver *drv, _EGLDisplay *dpy, { struct egl_g3d_context *gctx = egl_g3d_context(ctx); struct egl_g3d_surface *gdraw = egl_g3d_surface(draw); + struct egl_g3d_surface *gread = egl_g3d_surface(read); struct egl_g3d_context *old_gctx; EGLBoolean ok = EGL_TRUE; @@ -878,39 +679,29 @@ egl_g3d_make_current(_EGLDriver *drv, _EGLDisplay *dpy, if (old_gctx) { /* flush old context */ - old_gctx->stapi->st_flush(old_gctx->st_ctx, + old_gctx->stctxi->flush(old_gctx->stctxi, PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_FRAME, NULL); - - /* - * The old context is no longer current, and egl_g3d_realloc_context() - * should be called to destroy the framebuffers. However, it is possible - * that it will be made current again with the same draw/read surfaces. - * It might be better to keep it around. - */ } if (gctx) { - ok = egl_g3d_realloc_context(dpy, &gctx->base); + ok = gctx->stapi->make_current(gctx->stapi, gctx->stctxi, + (gdraw) ? gdraw->stfbi : NULL, (gread) ? gread->stfbi : NULL); if (ok) { - /* XXX: need to pass the winsys argument for - * flush_frontbuffer in the fourth parameter here: - */ - ok = gctx->stapi->st_make_current(gctx->st_ctx, - gctx->draw.st_fb, - gctx->read.st_fb, - NULL); - if (ok) { - egl_g3d_validate_context(dpy, &gctx->base); - if (gdraw->base.Type == EGL_WINDOW_BIT) { - gctx->base.WindowRenderBuffer = - (gdraw->render_att == NATIVE_ATTACHMENT_FRONT_LEFT) ? - EGL_SINGLE_BUFFER : EGL_BACK_BUFFER; - } + gctx->stctxi->notify_invalid_framebuffer(gctx->stctxi, gdraw->stfbi); + if (gread != gdraw) { + gctx->stctxi->notify_invalid_framebuffer(gctx->stctxi, + gread->stfbi); + } + + if (gdraw->base.Type == EGL_WINDOW_BIT) { + gctx->base.WindowRenderBuffer = + (gdraw->stvis.render_buffer == ST_ATTACHMENT_FRONT_LEFT) ? + EGL_SINGLE_BUFFER : EGL_BACK_BUFFER; } } } else if (old_gctx) { - ok = old_gctx->stapi->st_make_current(NULL, NULL, NULL, NULL); + ok = old_gctx->stapi->make_current(old_gctx->stapi, NULL, NULL, NULL); old_gctx->base.WindowRenderBuffer = EGL_NONE; } @@ -937,15 +728,17 @@ egl_g3d_swap_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf) return EGL_TRUE; /* or when the surface is single-buffered */ - if (gsurf->render_att == NATIVE_ATTACHMENT_FRONT_LEFT) + if (gsurf->stvis.render_buffer == ST_ATTACHMENT_FRONT_LEFT) return EGL_TRUE; if (ctx && ctx->DrawSurface == surf) gctx = egl_g3d_context(ctx); /* flush if the surface is current */ - if (gctx) - gctx->stapi->st_notify_swapbuffers(gctx->draw.st_fb); + if (gctx) { + gctx->stctxi->flush(gctx->stctxi, + PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_FRAME, NULL); + } return gsurf->native->swap_buffers(gsurf->native); } @@ -1003,7 +796,7 @@ egl_g3d_copy_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, struct pipe_screen *screen = gdpy->native->screen; struct pipe_surface *psurf; - if (!gsurf->render_surface) + if (!gsurf->render_texture) return EGL_TRUE; gconf = egl_g3d_config(egl_g3d_find_pixmap_config(dpy, target)); @@ -1018,26 +811,33 @@ egl_g3d_copy_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, /* flush if the surface is current */ if (ctx && ctx->DrawSurface == &gsurf->base) { struct egl_g3d_context *gctx = egl_g3d_context(ctx); - gctx->stapi->st_flush(gctx->st_ctx, + gctx->stctxi->flush(gctx->stctxi, PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_FRAME, NULL); } psurf = get_pipe_surface(gdpy->native, nsurf, NATIVE_ATTACHMENT_FRONT_LEFT); if (psurf) { struct pipe_context pipe; + struct pipe_surface *psrc; /** - * XXX This is hacky. If we might allow the EGLDisplay to create a pipe - * context of its own and use the blitter context for this. + * XXX This is hacky. We should probably create a pipe context for + * EGLDisplay and use a blitter context for this. */ memset(&pipe, 0, sizeof(pipe)); pipe.screen = screen; - util_surface_copy(&pipe, FALSE, psurf, 0, 0, - gsurf->render_surface, 0, 0, psurf->width, psurf->height); + psrc = screen->get_tex_surface(screen, gsurf->render_texture, + 0, 0, 0, PIPE_BUFFER_USAGE_CPU_READ); + if (psrc) { + util_surface_copy(&pipe, FALSE, psurf, 0, 0, + psrc, 0, 0, psurf->width, psurf->height); + pipe_surface_reference(&psrc, NULL); + + nsurf->flush_frontbuffer(nsurf); + } pipe_surface_reference(&psurf, NULL); - nsurf->flush_frontbuffer(nsurf); } nsurf->destroy(nsurf); @@ -1048,8 +848,16 @@ egl_g3d_copy_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, static EGLBoolean egl_g3d_wait_client(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx) { + struct egl_g3d_display *gdpy = egl_g3d_display(dpy); struct egl_g3d_context *gctx = egl_g3d_context(ctx); - gctx->stapi->st_finish(gctx->st_ctx); + struct pipe_screen *screen = gdpy->native->screen; + struct pipe_fence_handle *fence = NULL; + + gctx->stctxi->flush(gctx->stctxi, + PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_FRAME, &fence); + screen->fence_finish(screen, fence, 0); + screen->fence_reference(screen, &fence, NULL); + return EGL_TRUE; } @@ -1079,10 +887,10 @@ egl_g3d_get_proc_address(_EGLDriver *drv, const char *procname) /* in case this is called before a display is initialized */ egl_g3d_init_st(&gdrv->base); - for (i = 0; i < NUM_EGL_G3D_STS; i++) { - const struct egl_g3d_st *stapi = gdrv->stapis[i]; + for (i = 0; i < ST_API_COUNT; i++) { + struct st_api *stapi = gdrv->stapis[i]; if (stapi) { - proc = (_EGLProc) stapi->st_get_proc_address(procname); + proc = (_EGLProc) stapi->get_proc_address(stapi, procname); if (proc) return proc; } @@ -1098,8 +906,8 @@ egl_g3d_bind_tex_image(_EGLDriver *drv, _EGLDisplay *dpy, struct egl_g3d_surface *gsurf = egl_g3d_surface(surf); _EGLContext *es1 = _eglGetAPIContext(EGL_OPENGL_ES_API); struct egl_g3d_context *gctx; - enum pipe_format target_format; - int target; + enum pipe_format internal_format; + enum st_texture_type target; if (!gsurf || gsurf->base.Type != EGL_PBUFFER_BIT) return _eglError(EGL_BAD_SURFACE, "eglBindTexImage"); @@ -1110,10 +918,10 @@ egl_g3d_bind_tex_image(_EGLDriver *drv, _EGLDisplay *dpy, switch (gsurf->base.TextureFormat) { case EGL_TEXTURE_RGB: - target_format = PIPE_FORMAT_R8G8B8_UNORM; + internal_format = PIPE_FORMAT_R8G8B8_UNORM; break; case EGL_TEXTURE_RGBA: - target_format = PIPE_FORMAT_B8G8R8A8_UNORM; + internal_format = PIPE_FORMAT_B8G8R8A8_UNORM; break; default: return _eglError(EGL_BAD_MATCH, "eglBindTexImage"); @@ -1129,21 +937,24 @@ egl_g3d_bind_tex_image(_EGLDriver *drv, _EGLDisplay *dpy, if (!es1) return EGL_TRUE; - if (!gsurf->render_surface) + if (!gsurf->render_texture) return EGL_FALSE; /* flush properly if the surface is bound */ if (gsurf->base.CurrentContext) { gctx = egl_g3d_context(gsurf->base.CurrentContext); - gctx->stapi->st_flush(gctx->st_ctx, + gctx->stctxi->flush(gctx->stctxi, PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_FRAME, NULL); } gctx = egl_g3d_context(es1); - gctx->stapi->st_bind_texture_surface(gsurf->render_surface, - target, gsurf->base.MipmapLevel, target_format); - - gsurf->base.BoundToTexture = EGL_TRUE; + if (gctx->stctxi->teximage) { + if (!gctx->stctxi->teximage(gctx->stctxi, target, + gsurf->base.MipmapLevel, internal_format, + gsurf->render_texture, gsurf->base.MipmapTexture)) + return EGL_FALSE; + gsurf->base.BoundToTexture = EGL_TRUE; + } return EGL_TRUE; } @@ -1160,14 +971,15 @@ egl_g3d_release_tex_image(_EGLDriver *drv, _EGLDisplay *dpy, if (buffer != EGL_BACK_BUFFER) return _eglError(EGL_BAD_PARAMETER, "eglReleaseTexImage"); - if (gsurf->render_surface) { + if (gsurf->render_texture) { _EGLContext *ctx = _eglGetAPIContext(EGL_OPENGL_ES_API); struct egl_g3d_context *gctx = egl_g3d_context(ctx); /* what if the context the surface binds to is no longer current? */ - if (gctx) - gctx->stapi->st_unbind_texture_surface(gsurf->render_surface, - ST_TEXTURE_2D, gsurf->base.MipmapLevel); + if (gctx) { + gctx->stctxi->teximage(gctx->stctxi, ST_TEXTURE_2D, + gsurf->base.MipmapLevel, PIPE_FORMAT_NONE, NULL, FALSE); + } } gsurf->base.BoundToTexture = EGL_FALSE; @@ -1279,6 +1091,12 @@ static void egl_g3d_unload(_EGLDriver *drv) { struct egl_g3d_driver *gdrv = egl_g3d_driver(drv); + EGLint i; + + for (i = 0; i < ST_API_COUNT; i++) { + if (gdrv->stapis[i]) + gdrv->stapis[i]->destroy(gdrv->stapis[i]); + } egl_g3d_destroy_probe(drv, NULL); free(gdrv); diff --git a/src/gallium/state_trackers/egl/common/egl_g3d.h b/src/gallium/state_trackers/egl/common/egl_g3d.h index e3e55e46d3b..07a87f8bc73 100644 --- a/src/gallium/state_trackers/egl/common/egl_g3d.h +++ b/src/gallium/state_trackers/egl/common/egl_g3d.h @@ -39,11 +39,11 @@ #include "eglmode.h" #include "native.h" -#include "egl_st.h" +#include "egl_g3d_st.h" struct egl_g3d_driver { _EGLDriver base; - const struct egl_g3d_st *stapis[NUM_EGL_G3D_STS]; + struct st_api *stapis[ST_API_COUNT]; EGLint api_mask; EGLint probe_key; @@ -51,35 +51,33 @@ struct egl_g3d_driver { struct egl_g3d_display { struct native_display *native; -}; -struct egl_g3d_buffer { - struct st_framebuffer *st_fb; - uint attachment_mask; + struct st_manager *smapi; }; struct egl_g3d_context { _EGLContext base; - const struct egl_g3d_st *stapi; - struct pipe_context *pipe; + struct st_api *stapi; - struct st_context *st_ctx; - EGLBoolean force_validate; - struct egl_g3d_buffer draw, read; + struct st_context_iface *stctxi; }; struct egl_g3d_surface { _EGLSurface base; + + struct st_visual stvis; + struct st_framebuffer_iface *stfbi; + struct native_surface *native; - enum native_attachment render_att; - struct pipe_surface *render_surface; + struct pipe_texture *render_texture; unsigned int sequence_number; }; struct egl_g3d_config { _EGLConfig base; const struct native_config *native; + struct st_visual stvis; }; struct egl_g3d_image { diff --git a/src/gallium/state_trackers/egl/common/egl_g3d_st.c b/src/gallium/state_trackers/egl/common/egl_g3d_st.c new file mode 100644 index 00000000000..36094096d36 --- /dev/null +++ b/src/gallium/state_trackers/egl/common/egl_g3d_st.c @@ -0,0 +1,227 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu + */ + +#include "util/u_memory.h" +#include "util/u_inlines.h" +#include "util/u_dl.h" +#include "eglimage.h" +#include "eglmutex.h" + +#include "egl_g3d.h" +#include "egl_g3d_st.h" + +struct egl_g3d_st_manager { + struct st_manager base; + _EGLDisplay *display; +}; + +static INLINE struct egl_g3d_st_manager * +egl_g3d_st_manager(struct st_manager *smapi) +{ + return (struct egl_g3d_st_manager *) smapi; +} + +struct st_api * +egl_g3d_create_st_api(enum st_api_type api) +{ + const char *stmod_name; + struct util_dl_library *lib; + const struct st_module *mod; + + switch (api) { + case ST_API_OPENGL: + stmod_name = ST_MODULE_OPENGL_SYMBOL; + break; + case ST_API_OPENGL_ES1: + stmod_name = ST_MODULE_OPENGL_ES1_SYMBOL; + break; + case ST_API_OPENGL_ES2: + stmod_name = ST_MODULE_OPENGL_ES2_SYMBOL; + break; + case ST_API_OPENVG: + stmod_name = ST_MODULE_OPENVG_SYMBOL; + break; + default: + stmod_name = NULL; + break; + } + if (!stmod_name) + return NULL; + + mod = NULL; + lib = util_dl_open(NULL); + if (lib) { + mod = (const struct st_module *) + util_dl_get_proc_address(lib, stmod_name); + util_dl_close(lib); + } + if (!mod || mod->api != api) + return NULL; + + return mod->create_api(); +} + +struct st_manager * +egl_g3d_create_st_manager(_EGLDisplay *dpy) +{ + struct egl_g3d_display *gdpy = egl_g3d_display(dpy); + struct egl_g3d_st_manager *gsmapi; + + gsmapi = CALLOC_STRUCT(egl_g3d_st_manager); + if (gsmapi) { + gsmapi->display = dpy; + + gsmapi->base.screen = gdpy->native->screen; + } + + return &gsmapi->base;; +} + +void +egl_g3d_destroy_st_manager(struct st_manager *smapi) +{ + struct egl_g3d_st_manager *gsmapi = egl_g3d_st_manager(smapi); + free(gsmapi); +} + +static boolean +egl_g3d_st_framebuffer_flush_front(struct st_framebuffer_iface *stfbi, + enum st_attachment_type statt) +{ + _EGLSurface *surf = (_EGLSurface *) stfbi->st_manager_private; + struct egl_g3d_surface *gsurf = egl_g3d_surface(surf); + + return gsurf->native->flush_frontbuffer(gsurf->native); +} + +static boolean +egl_g3d_st_framebuffer_validate(struct st_framebuffer_iface *stfbi, + const enum st_attachment_type *statts, + unsigned count, + struct pipe_texture **out) +{ + _EGLSurface *surf = (_EGLSurface *) stfbi->st_manager_private; + struct egl_g3d_surface *gsurf = egl_g3d_surface(surf); + struct pipe_texture *textures[NUM_NATIVE_ATTACHMENTS]; + uint attachment_mask = 0; + unsigned i; + + for (i = 0; i < count; i++) { + int natt; + + switch (statts[i]) { + case ST_ATTACHMENT_FRONT_LEFT: + natt = NATIVE_ATTACHMENT_FRONT_LEFT; + break; + case ST_ATTACHMENT_BACK_LEFT: + natt = NATIVE_ATTACHMENT_BACK_LEFT; + break; + case ST_ATTACHMENT_FRONT_RIGHT: + natt = NATIVE_ATTACHMENT_FRONT_RIGHT; + break; + case ST_ATTACHMENT_BACK_RIGHT: + natt = NATIVE_ATTACHMENT_BACK_RIGHT; + default: + natt = -1; + break; + } + + if (natt >= 0) + attachment_mask |= 1 << natt; + } + + if (!gsurf->native->validate(gsurf->native, attachment_mask, + &gsurf->sequence_number, textures, &gsurf->base.Width, + &gsurf->base.Height)) + return FALSE; + + for (i = 0; i < count; i++) { + struct pipe_texture *tex; + int natt; + + switch (statts[i]) { + case ST_ATTACHMENT_FRONT_LEFT: + natt = NATIVE_ATTACHMENT_FRONT_LEFT; + break; + case ST_ATTACHMENT_BACK_LEFT: + natt = NATIVE_ATTACHMENT_BACK_LEFT; + break; + case ST_ATTACHMENT_FRONT_RIGHT: + natt = NATIVE_ATTACHMENT_FRONT_RIGHT; + break; + case ST_ATTACHMENT_BACK_RIGHT: + natt = NATIVE_ATTACHMENT_BACK_RIGHT; + break; + default: + natt = -1; + break; + } + + if (natt >= 0) { + tex = textures[natt]; + + if (statts[i] == stfbi->visual->render_buffer) + pipe_texture_reference(&gsurf->render_texture, tex); + + if (attachment_mask & (1 << natt)) { + /* transfer the ownership to the caller */ + out[i] = tex; + attachment_mask &= ~(1 << natt); + } + else { + /* the attachment is listed more than once */ + pipe_texture_reference(&out[i], tex); + } + } + } + + return TRUE; +} + +struct st_framebuffer_iface * +egl_g3d_create_st_framebuffer(_EGLSurface *surf) +{ + struct egl_g3d_surface *gsurf = egl_g3d_surface(surf); + struct st_framebuffer_iface *stfbi; + + stfbi = CALLOC_STRUCT(st_framebuffer_iface); + if (!stfbi) + return NULL; + + stfbi->visual = &gsurf->stvis; + stfbi->flush_front = egl_g3d_st_framebuffer_flush_front; + stfbi->validate = egl_g3d_st_framebuffer_validate; + stfbi->st_manager_private = (void *) &gsurf->base; + + return stfbi; +} + +void +egl_g3d_destroy_st_framebuffer(struct st_framebuffer_iface *stfbi) +{ + free(stfbi); +} diff --git a/src/gallium/state_trackers/egl/common/egl_g3d_st.h b/src/gallium/state_trackers/egl/common/egl_g3d_st.h new file mode 100644 index 00000000000..ea8b4068cd8 --- /dev/null +++ b/src/gallium/state_trackers/egl/common/egl_g3d_st.h @@ -0,0 +1,79 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu + */ + +#ifndef _EGL_G3D_ST_H_ +#define _EGL_G3D_ST_H_ + +#include "pipe/p_compiler.h" +#include "state_tracker/st_api.h" +#include "egltypedefs.h" + +struct st_api * +egl_g3d_create_st_api(enum st_api_type api); + +struct st_manager * +egl_g3d_create_st_manager(_EGLDisplay *dpy); + +void +egl_g3d_destroy_st_manager(struct st_manager *smapi); + +struct st_framebuffer_iface * +egl_g3d_create_st_framebuffer(_EGLSurface *surf); + +void +egl_g3d_destroy_st_framebuffer(struct st_framebuffer_iface *stfbi); + +/** + * Return the EGL__BIT of the st api. + */ +static INLINE int +egl_g3d_st_api_bit(enum st_api_type api) +{ + int bit; + + switch (api) { + case ST_API_OPENGL: + bit = EGL_OPENGL_BIT; + break; + case ST_API_OPENGL_ES1: + bit = EGL_OPENGL_ES_BIT; + break; + case ST_API_OPENGL_ES2: + bit = EGL_OPENGL_ES2_BIT; + break; + case ST_API_OPENVG: + bit = EGL_OPENVG_BIT; + break; + default: + bit = 0; + break; + } + + return bit; +} + +#endif /* _EGL_G3D_ST_H_ */ diff --git a/src/gallium/state_trackers/egl/common/egl_st.c b/src/gallium/state_trackers/egl/common/egl_st.c deleted file mode 100644 index a88ff911cd5..00000000000 --- a/src/gallium/state_trackers/egl/common/egl_st.c +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Mesa 3-D graphics library - * Version: 7.8 - * - * Copyright (C) 2009-2010 Chia-I Wu - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -#include -#include "pipe/p_compiler.h" -#include "util/u_memory.h" -#include "egllog.h" -#include "EGL/egl.h" /* for EGL_api_BIT */ - -#include "egl_st.h" - -#ifndef HAVE_DLADDR -#define HAVE_DLADDR 1 -#endif - -#if HAVE_DLADDR - -static const char * -egl_g3d_st_names[] = { -#define ST_PUBLIC(name, ...) #name, -#include "st_public_tmp.h" - NULL -}; - -static boolean -egl_g3d_fill_st(struct egl_g3d_st *stapi, void *sym) -{ - st_proc *procs = (st_proc *) stapi; - void *handle; - Dl_info info; - const char **name; - - if (!dladdr(sym, &info)) - return FALSE; - handle = dlopen(info.dli_fname, RTLD_LAZY | RTLD_LOCAL | RTLD_NODELETE); - if (!handle) - return FALSE; - - for (name = egl_g3d_st_names; *name; name++) { - st_proc proc = (st_proc) dlsym(handle, *name); - if (!proc) { - _eglLog(_EGL_WARNING, "%s is missing in %s", *name, info.dli_fname); - memset(stapi, 0, sizeof(*stapi)); - dlclose(handle); - return FALSE; - } - *procs++ = proc; - } - - dlclose(handle); - return TRUE; -} - -#else /* HAVE_DLADDR */ - -static boolean -egl_g3d_fill_st(struct egl_g3d_st *stapi, void *sym) -{ -#define ST_PUBLIC(name, ...) stapi->name = name; -#include "st_public_tmp.h" - return TRUE; -} - -#endif /* HAVE_DLADDR */ - -static boolean -egl_g3d_init_st(struct egl_g3d_st *stapi, const char *api) -{ - void *handle, *sym; - boolean res = FALSE; - - /* already initialized */ - if (stapi->st_notify_swapbuffers != NULL) - return TRUE; - - handle = dlopen(NULL, RTLD_LAZY | RTLD_LOCAL); - if (!handle) - return FALSE; - - sym = dlsym(handle, api); - if (sym && egl_g3d_fill_st(stapi, sym)) - res = TRUE; - - dlclose(handle); - return res; -} - -static struct { - const char *symbol; - EGLint api_bit; -} egl_g3d_st_info[NUM_EGL_G3D_STS] = { - { "st_api_OpenGL_ES1", EGL_OPENGL_ES_BIT }, - { "st_api_OpenVG", EGL_OPENVG_BIT }, - { "st_api_OpenGL_ES2", EGL_OPENGL_ES2_BIT }, - { "st_api_OpenGL", EGL_OPENGL_BIT }, -}; - -const struct egl_g3d_st * -egl_g3d_get_st(enum egl_g3d_st_api api) -{ - static struct egl_g3d_st all_trackers[NUM_EGL_G3D_STS]; - - if (egl_g3d_init_st(&all_trackers[api], egl_g3d_st_info[api].symbol)) { - all_trackers[api].api_bit = egl_g3d_st_info[api].api_bit; - return &all_trackers[api]; - } - else { - return NULL; - } -} diff --git a/src/gallium/state_trackers/egl/common/egl_st.h b/src/gallium/state_trackers/egl/common/egl_st.h deleted file mode 100644 index 8fb464bd3d7..00000000000 --- a/src/gallium/state_trackers/egl/common/egl_st.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Mesa 3-D graphics library - * Version: 7.8 - * - * Copyright (C) 2009-2010 Chia-I Wu - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -#ifndef _EGL_ST_H_ -#define _EGL_ST_H_ - -#include "GL/gl.h" /* for GL types */ -#include "GL/internal/glcore.h" /* for __GLcontextModes */ - -#include "pipe/p_compiler.h" -#include "pipe/p_format.h" -#include "pipe/p_context.h" - -/* avoid calling st functions directly */ -#if 1 - -#define ST_SURFACE_FRONT_LEFT 0 -#define ST_SURFACE_BACK_LEFT 1 -#define ST_SURFACE_FRONT_RIGHT 2 -#define ST_SURFACE_BACK_RIGHT 3 - -#define ST_TEXTURE_2D 0x2 - -struct st_context; -struct st_framebuffer; -typedef void (*st_proc)(); - -#else -#include "state_tracker/st_public.h" -#endif - -/* remember to update egl_g3d_get_st() when update the enums */ -enum egl_g3d_st_api { - EGL_G3D_ST_OPENGL_ES = 0, - EGL_G3D_ST_OPENVG, - EGL_G3D_ST_OPENGL_ES2, - EGL_G3D_ST_OPENGL, - - NUM_EGL_G3D_STS -}; - -struct egl_g3d_st { -#define ST_PUBLIC(name, ret, ...) ret (*name)(__VA_ARGS__); -#include "st_public_tmp.h" - /* fields must be added here */ - EGLint api_bit; -}; - -const struct egl_g3d_st * -egl_g3d_get_st(enum egl_g3d_st_api api); - -#endif /* _EGL_ST_H_ */ diff --git a/src/gallium/state_trackers/egl/common/st_public_tmp.h b/src/gallium/state_trackers/egl/common/st_public_tmp.h deleted file mode 100644 index 562dd68c150..00000000000 --- a/src/gallium/state_trackers/egl/common/st_public_tmp.h +++ /dev/null @@ -1,20 +0,0 @@ -ST_PUBLIC(st_create_context, struct st_context *, struct pipe_context *pipe, const __GLcontextModes *visual, struct st_context *share) -ST_PUBLIC(st_destroy_context, void, struct st_context *st) -ST_PUBLIC(st_copy_context_state, void, struct st_context *dst, struct st_context *src, uint mask) -ST_PUBLIC(st_create_framebuffer, struct st_framebuffer *, const __GLcontextModes *visual, enum pipe_format colorFormat, enum pipe_format depthFormat, enum pipe_format stencilFormat, uint width, uint height, void *privateData) -ST_PUBLIC(st_resize_framebuffer, void, struct st_framebuffer *stfb, uint width, uint height) -ST_PUBLIC(st_set_framebuffer_surface, void, struct st_framebuffer *stfb, uint surfIndex, struct pipe_surface *surf) -ST_PUBLIC(st_get_framebuffer_dimensions, void, struct st_framebuffer *stfb, uint *width, uint *height) -ST_PUBLIC(st_get_framebuffer_surface, int, struct st_framebuffer *stfb, uint surfIndex, struct pipe_surface **surface) -ST_PUBLIC(st_get_framebuffer_texture, int, struct st_framebuffer *stfb, uint surfIndex, struct pipe_texture **texture) -ST_PUBLIC(st_framebuffer_private, void *, struct st_framebuffer *stfb) -ST_PUBLIC(st_unreference_framebuffer, void, struct st_framebuffer *stfb) -ST_PUBLIC(st_make_current, GLboolean, struct st_context *st, struct st_framebuffer *draw, struct st_framebuffer *read, void *winsys_drawable_handle) -ST_PUBLIC(st_get_current, struct st_context *, void) -ST_PUBLIC(st_flush, void, struct st_context *st, uint pipeFlushFlags, struct pipe_fence_handle **fence) -ST_PUBLIC(st_finish, void, struct st_context *st) -ST_PUBLIC(st_notify_swapbuffers, void, struct st_framebuffer *stfb) -ST_PUBLIC(st_bind_texture_surface, int, struct pipe_surface *ps, int target, int level, enum pipe_format format) -ST_PUBLIC(st_unbind_texture_surface, int, struct pipe_surface *ps, int target, int level) -ST_PUBLIC(st_get_proc_address, st_proc, const char *procname) -#undef ST_PUBLIC -- cgit v1.2.3 From 576d9af505bd19ccaac04a68c8744f36f887bd5c Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Wed, 10 Mar 2010 17:22:56 +0800 Subject: st/glx: Use st_api.h instead of st_public.h. --- src/gallium/state_trackers/glx/xlib/Makefile | 3 +- src/gallium/state_trackers/glx/xlib/glx_api.c | 5 +- src/gallium/state_trackers/glx/xlib/xm_api.c | 265 +++++++++++++------------ src/gallium/state_trackers/glx/xlib/xm_api.h | 39 ++-- src/gallium/state_trackers/glx/xlib/xm_st.c | 269 ++++++++++++++++++++++++++ src/gallium/state_trackers/glx/xlib/xm_st.h | 54 ++++++ 6 files changed, 470 insertions(+), 165 deletions(-) create mode 100644 src/gallium/state_trackers/glx/xlib/xm_st.c create mode 100644 src/gallium/state_trackers/glx/xlib/xm_st.h (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/glx/xlib/Makefile b/src/gallium/state_trackers/glx/xlib/Makefile index 7b2adc62c34..ddffdb162c7 100644 --- a/src/gallium/state_trackers/glx/xlib/Makefile +++ b/src/gallium/state_trackers/glx/xlib/Makefile @@ -11,6 +11,7 @@ C_SOURCES = \ glx_api.c \ glx_getproc.c \ glx_usefont.c \ - xm_api.c + xm_api.c \ + xm_st.c include ../../../Makefile.template diff --git a/src/gallium/state_trackers/glx/xlib/glx_api.c b/src/gallium/state_trackers/glx/xlib/glx_api.c index 24545858500..4930cd6cd50 100644 --- a/src/gallium/state_trackers/glx/xlib/glx_api.c +++ b/src/gallium/state_trackers/glx/xlib/glx_api.c @@ -35,12 +35,9 @@ #include "xm_api.h" #include "main/context.h" -#include "main/config.h" #include "main/macros.h" #include "main/imports.h" #include "main/version.h" -#include "state_tracker/st_context.h" -#include "state_tracker/st_public.h" /* This indicates the client-side GLX API and GLX encoder version. */ @@ -1304,7 +1301,7 @@ glXCopyContext( Display *dpy, GLXContext src, GLXContext dst, if (MakeCurrent_PrevContext == src) { _mesa_Flush(); } - st_copy_context_state( xm_src->st, xm_dst->st, (GLuint) mask ); + XMesaCopyContext(xm_src, xm_dst, mask); } diff --git a/src/gallium/state_trackers/glx/xlib/xm_api.c b/src/gallium/state_trackers/glx/xlib/xm_api.c index f4d7133d2ff..6a0f3146dbf 100644 --- a/src/gallium/state_trackers/glx/xlib/xm_api.c +++ b/src/gallium/state_trackers/glx/xlib/xm_api.c @@ -54,11 +54,9 @@ #endif #include "xm_api.h" -#include "main/context.h" -#include "main/framebuffer.h" +#include "xm_st.h" -#include "state_tracker/st_public.h" -#include "state_tracker/st_context.h" +#include "main/context.h" #include "pipe/p_defines.h" #include "pipe/p_screen.h" #include "pipe/p_context.h" @@ -84,6 +82,8 @@ void xmesa_set_driver( const struct xm_driver *templ ) pipe_mutex _xmesa_lock; static struct pipe_screen *screen = NULL; +static struct st_api *stapi = NULL; +static struct st_manager *smapi = NULL; /**********************************************************************/ @@ -273,49 +273,49 @@ choose_pixel_format(XMesaVisual v) return 0; } - - /** - * Query the default gallium screen for a Z/Stencil format that - * at least matches the given depthBits and stencilBits. + * Choose a depth/stencil format for the given depth and stencil sizes. */ -static void -xmesa_choose_z_stencil_format(int depthBits, int stencilBits, - enum pipe_format *depthFormat, - enum pipe_format *stencilFormat) +static enum pipe_format +choose_depth_stencil_format(int depth, int stencil) { const enum pipe_texture_target target = PIPE_TEXTURE_2D; const unsigned tex_usage = PIPE_TEXTURE_USAGE_DEPTH_STENCIL; const unsigned geom_flags = (PIPE_TEXTURE_GEOM_NON_SQUARE | PIPE_TEXTURE_GEOM_NON_POWER_OF_TWO); - static enum pipe_format formats[] = { - PIPE_FORMAT_S8Z24_UNORM, - PIPE_FORMAT_Z24S8_UNORM, - PIPE_FORMAT_Z16_UNORM, - PIPE_FORMAT_Z32_UNORM - }; - int i; + enum pipe_format formats[8], fmt; + int count, i; assert(screen); - *depthFormat = *stencilFormat = PIPE_FORMAT_NONE; + count = 0; + switch (depth) { + case 16: + if (!stencil) + formats[count++] = PIPE_FORMAT_Z16_UNORM; + break; + case 24: + formats[count++] = PIPE_FORMAT_S8Z24_UNORM; + formats[count++] = PIPE_FORMAT_Z24S8_UNORM; + break; + case 32: + if (!stencil) + formats[count++] = PIPE_FORMAT_Z32_UNORM; + break; + default: + break; + } - /* search for supported format */ - for (i = 0; i < Elements(formats); i++) { + fmt = PIPE_FORMAT_NONE; + for (i = 0; i < count; i++) { if (screen->is_format_supported(screen, formats[i], target, tex_usage, geom_flags)) { - *depthFormat = formats[i]; + fmt = formats[i]; break; } } - if (stencilBits) { - *stencilFormat = *depthFormat; - } - - /* XXX we should check that he chosen format has at least as many bits - * as what was requested. - */ + return fmt; } @@ -343,12 +343,14 @@ create_xmesa_buffer(Drawable d, BufferType type, XMesaVisual vis, Colormap cmap) { XMesaBuffer b; - GLframebuffer *fb; - enum pipe_format colorFormat, depthFormat, stencilFormat; uint width, height; ASSERT(type == WINDOW || type == PIXMAP || type == PBUFFER); + xmesa_init(vis->display); + if (!screen) + return NULL; + b = (XMesaBuffer) CALLOC_STRUCT(xmesa_buffer); if (!b) return NULL; @@ -361,24 +363,12 @@ create_xmesa_buffer(Drawable d, BufferType type, b->type = type; b->cmap = cmap; - /* determine PIPE_FORMATs for buffers */ - colorFormat = choose_pixel_format(vis); - - xmesa_choose_z_stencil_format(vis->mesa_visual.depthBits, - vis->mesa_visual.stencilBits, - &depthFormat, &stencilFormat); - - get_drawable_size(vis->display, d, &width, &height); /* * Create framebuffer, but we'll plug in our own renderbuffers below. */ - b->stfb = st_create_framebuffer(&vis->mesa_visual, - colorFormat, depthFormat, stencilFormat, - width, height, - (void *) b); - fb = &b->stfb->Base; + b->stfb = xmesa_create_st_framebuffer(screen, b); /* GLX_EXT_texture_from_pixmap */ b->TextureTarget = 0; @@ -422,24 +412,21 @@ xmesa_free_buffer(XMesaBuffer buffer) for (b = XMesaBufferList; b; b = b->Next) { if (b == buffer) { - struct gl_framebuffer *fb = &buffer->stfb->Base; - /* unlink buffer from list */ if (prev) prev->Next = buffer->Next; else XMesaBufferList = buffer->Next; - /* mark as delete pending */ - fb->DeletePending = GL_TRUE; - /* Since the X window for the XMesaBuffer is going away, we don't * want to dereference this pointer in the future. */ b->ws.drawable = 0; - /* Unreference. If count = zero we'll really delete the buffer */ - _mesa_reference_framebuffer(&fb, NULL); + /* XXX we should move the buffer to a delete-pending list and destroy + * the buffer until it is no longer current. + */ + xmesa_destroy_st_framebuffer(buffer->stfb); free(buffer); @@ -681,6 +668,26 @@ XMesaVisual XMesaCreateVisual( Display *display, accum_blue_size, accum_alpha_size, 0 ); + v->stvis.buffer_mask = ST_ATTACHMENT_FRONT_LEFT_MASK; + if (db_flag) + v->stvis.buffer_mask = ST_ATTACHMENT_BACK_LEFT_MASK; + if (stereo_flag) { + v->stvis.buffer_mask = ST_ATTACHMENT_FRONT_RIGHT_MASK; + if (db_flag) + v->stvis.buffer_mask = ST_ATTACHMENT_BACK_RIGHT_MASK; + } + + v->stvis.color_format = choose_pixel_format(v); + v->stvis.depth_stencil_format = + choose_depth_stencil_format(depth_size, stencil_size); + + v->stvis.accum_format = (accum_red_size + + accum_green_size + accum_blue_size + accum_alpha_size) ? + PIPE_FORMAT_R16G16B16A16_SNORM : PIPE_FORMAT_NONE; + + v->stvis.samples = num_samples; + v->stvis.render_buffer = ST_ATTACHMENT_INVALID; + /* XXX minor hack */ v->mesa_visual.level = level; return v; @@ -705,6 +712,26 @@ xmesa_init( Display *display ) if (firstTime) { pipe_mutex_init(_xmesa_lock); screen = driver.create_pipe_screen( display ); + stapi = xmesa_create_st_api(); + smapi = CALLOC_STRUCT(st_manager); + if (smapi) + smapi->screen = screen; + + if (!screen || !stapi || !smapi) { + if (screen) { + screen->destroy(screen); + screen = NULL; + } + if (stapi) { + stapi->destroy(stapi); + stapi = NULL; + } + if (smapi) { + FREE(smapi); + smapi = NULL; + } + } + firstTime = GL_FALSE; } } @@ -720,10 +747,7 @@ xmesa_init( Display *display ) PUBLIC XMesaContext XMesaCreateContext( XMesaVisual v, XMesaContext share_list ) { - struct pipe_context *pipe = NULL; XMesaContext c; - GLcontext *mesaCtx; - uint pf; xmesa_init( v->display ); @@ -732,9 +756,6 @@ XMesaContext XMesaCreateContext( XMesaVisual v, XMesaContext share_list ) if (!c) return NULL; - pf = choose_pixel_format(v); - assert(pf); - c->xm_visual = v; c->xm_buffer = NULL; /* set later by XMesaMakeCurrent */ c->xm_read_buffer = NULL; @@ -742,29 +763,18 @@ XMesaContext XMesaCreateContext( XMesaVisual v, XMesaContext share_list ) if (screen == NULL) goto fail; - /* Trace screen knows how to properly wrap context creation in the - * wrapped screen, so nothing special to do here: - */ - pipe = screen->context_create(screen, (void *) c); - if (pipe == NULL) - goto fail; - - c->st = st_create_context(pipe, - &v->mesa_visual, - share_list ? share_list->st : NULL); + c->st = stapi->create_context(stapi, smapi, + &v->stvis, (share_list) ? share_list->st : NULL); if (c->st == NULL) goto fail; - mesaCtx = c->st->ctx; - c->st->ctx->DriverCtx = c; + c->st->st_manager_private = (void *) c; return c; fail: if (c->st) - st_destroy_context(c->st); - else if (pipe) - pipe->destroy(pipe); + c->st->destroy(c->st); free(c); return NULL; @@ -775,7 +785,7 @@ fail: PUBLIC void XMesaDestroyContext( XMesaContext c ) { - st_destroy_context(c->st); + c->st->destroy(c->st); /* FIXME: We should destroy the screen here, but if we do so, surfaces may * outlive it, causing segfaults @@ -881,7 +891,6 @@ XMesaCreatePixmapTextureBuffer(XMesaVisual v, Pixmap p, { GET_CURRENT_CONTEXT(ctx); XMesaBuffer b; - GLuint width, height; assert(v); @@ -889,19 +898,18 @@ XMesaCreatePixmapTextureBuffer(XMesaVisual v, Pixmap p, if (!b) return NULL; - /* get pixmap size, update framebuffer/renderbuffer dims */ - xmesa_get_window_size(v->display, b, &width, &height); - _mesa_resize_framebuffer(NULL, &(b->stfb->Base), width, height); + /* get pixmap size */ + xmesa_get_window_size(v->display, b, &b->width, &b->height); if (target == 0) { /* examine dims */ if (ctx->Extensions.ARB_texture_non_power_of_two) { target = GLX_TEXTURE_2D_EXT; } - else if ( _mesa_bitcount(width) == 1 - && _mesa_bitcount(height) == 1) { + else if ( _mesa_bitcount(b->width) == 1 + && _mesa_bitcount(b->height) == 1) { /* power of two size */ - if (height == 1) { + if (b->height == 1) { target = GLX_TEXTURE_1D_EXT; } else { @@ -974,23 +982,20 @@ XMesaDestroyBuffer(XMesaBuffer b) /** - * Query the current window size and update the corresponding GLframebuffer - * and all attached renderbuffers. - * Called when: - * 1. the first time a buffer is bound to a context. - * 2. SwapBuffers. XXX probabaly from xm_flush_frontbuffer() too... - * Note: it's possible (and legal) for xmctx to be NULL. That can happen - * when resizing a buffer when no rendering context is bound. + * Query the current drawable size and notify the binding context. */ void -xmesa_check_and_update_buffer_size(XMesaContext xmctx, XMesaBuffer drawBuffer) +xmesa_check_buffer_size(XMesaBuffer b) { - GLuint width, height; - xmesa_get_window_size(drawBuffer->xm_visual->display, drawBuffer, &width, &height); - st_resize_framebuffer(drawBuffer->stfb, width, height); -} + XMesaContext xmctx = XMesaGetCurrentContext(); + if (b->type == PBUFFER) + return; + xmesa_get_window_size(b->xm_visual->display, b, &b->width, &b->height); + if (xmctx && xmctx->xm_buffer == b) + xmctx->st->notify_invalid_framebuffer(xmctx->st, b->stfb); +} /* @@ -1017,22 +1022,21 @@ GLboolean XMesaMakeCurrent2( XMesaContext c, XMesaBuffer drawBuffer, c->xm_read_buffer == readBuffer) return GL_TRUE; + xmesa_check_buffer_size(drawBuffer); + if (readBuffer != drawBuffer) + xmesa_check_buffer_size(readBuffer); + c->xm_buffer = drawBuffer; c->xm_read_buffer = readBuffer; - st_make_current(c->st, drawBuffer->stfb, readBuffer->stfb, - &drawBuffer->ws); - - xmesa_check_and_update_buffer_size(c, drawBuffer); - if (readBuffer != drawBuffer) - xmesa_check_and_update_buffer_size(c, readBuffer); + stapi->make_current(stapi, c->st, drawBuffer->stfb, readBuffer->stfb); /* Solution to Stephane Rehel's problem with glXReleaseBuffersMESA(): */ drawBuffer->wasCurrent = GL_TRUE; } else { /* Detach */ - st_make_current( NULL, NULL, NULL, NULL ); + stapi->make_current(stapi, NULL, NULL, NULL); } return GL_TRUE; @@ -1051,14 +1055,8 @@ GLboolean XMesaUnbindContext( XMesaContext c ) XMesaContext XMesaGetCurrentContext( void ) { - GET_CURRENT_CONTEXT(ctx); - if (ctx) { - XMesaContext xmesa = xmesa_context(ctx); - return xmesa; - } - else { - return 0; - } + struct st_context_iface *st = stapi->get_current(stapi); + return (XMesaContext) (st) ? st->st_manager_private : NULL; } @@ -1070,17 +1068,17 @@ XMesaContext XMesaGetCurrentContext( void ) PUBLIC void XMesaSwapBuffers( XMesaBuffer b ) { - struct pipe_surface *frontLeftSurf; - - st_swapbuffers(b->stfb, &frontLeftSurf, NULL); - - if (frontLeftSurf) { - screen->flush_frontbuffer( screen, - frontLeftSurf, - &b->ws ); + XMesaContext xmctx = XMesaGetCurrentContext(); + + if (xmctx && xmctx->xm_buffer == b) { + xmctx->st->flush( xmctx->st, + PIPE_FLUSH_RENDER_CACHE | + PIPE_FLUSH_SWAPBUFFERS | + PIPE_FLUSH_FRAME, + NULL); } - xmesa_check_and_update_buffer_size(NULL, b); + xmesa_swap_st_framebuffer(b->stfb); } @@ -1090,21 +1088,9 @@ void XMesaSwapBuffers( XMesaBuffer b ) */ void XMesaCopySubBuffer( XMesaBuffer b, int x, int y, int width, int height ) { - struct pipe_surface *surf_front; - struct pipe_surface *surf_back; - struct pipe_context *pipe = NULL; /* XXX fix */ - - st_get_framebuffer_surface(b->stfb, ST_SURFACE_FRONT_LEFT, &surf_front); - st_get_framebuffer_surface(b->stfb, ST_SURFACE_BACK_LEFT, &surf_back); - - if (!surf_front || !surf_back) - return; - - assert(pipe); - pipe->surface_copy(pipe, - surf_front, x, y, /* dest */ - surf_back, x, y, /* src */ - width, height); + xmesa_copy_st_framebuffer(b->stfb, + ST_ATTACHMENT_BACK_LEFT, ST_ATTACHMENT_FRONT_LEFT, + x, y, width, height); } @@ -1112,7 +1098,13 @@ void XMesaCopySubBuffer( XMesaBuffer b, int x, int y, int width, int height ) void XMesaFlush( XMesaContext c ) { if (c && c->xm_visual->display) { - st_finish(c->st); + struct pipe_fence_handle *fence = NULL; + + c->st->flush(c->st, PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_FRAME, &fence); + if (fence) { + screen->fence_finish(screen, fence, 0); + screen->fence_reference(screen, &fence, NULL); + } XSync( c->xm_visual->display, False ); } } @@ -1186,3 +1178,10 @@ XMesaReleaseTexImage(Display *dpy, XMesaBuffer drawable, int buffer) { } + +void +XMesaCopyContext(XMesaContext src, XMesaContext dst, unsigned long mask) +{ + if (dst->st->copy) + dst->st->copy(dst->st, src->st, mask); +} diff --git a/src/gallium/state_trackers/glx/xlib/xm_api.h b/src/gallium/state_trackers/glx/xlib/xm_api.h index de47064b410..258abf92554 100644 --- a/src/gallium/state_trackers/glx/xlib/xm_api.h +++ b/src/gallium/state_trackers/glx/xlib/xm_api.h @@ -58,8 +58,7 @@ and create a window, you must do the following to use the X/Mesa interface: #include "main/mtypes.h" -#include "state_tracker/st_context.h" -#include "state_tracker/st_public.h" +#include "state_tracker/st_api.h" #include "os/os_thread.h" #include "state_tracker/xlib_sw_winsys.h" @@ -258,6 +257,8 @@ XMesaCreatePixmapTextureBuffer(XMesaVisual v, Pixmap p, int format, int target, int mipmap); +extern void +XMesaCopyContext(XMesaContext src, XMesaContext dst, unsigned long mask); /*********************************************************************** @@ -280,6 +281,8 @@ struct xmesa_visual { GLint BitsPerPixel; /* True bits per pixel for XImages */ GLboolean ximage_flag; /* Use XImage for back buffer (not pixmap)? */ + + struct st_visual stvis; }; @@ -288,7 +291,7 @@ struct xmesa_visual { * Basically corresponds to a GLXContext. */ struct xmesa_context { - struct st_context *st; + struct st_context_iface *st; XMesaVisual xm_visual; /** pixel format info */ XMesaBuffer xm_buffer; /** current drawbuffer */ XMesaBuffer xm_read_buffer; /** current readbuffer */ @@ -311,7 +314,7 @@ typedef enum { * Basically corresponds to a GLXDrawable. */ struct xmesa_buffer { - struct st_framebuffer *stfb; + struct st_framebuffer_iface *stfb; struct xlib_drawable ws; GLboolean wasCurrent; /* was ever the current buffer? */ @@ -335,33 +338,15 @@ struct xmesa_buffer { GLint TextureMipmap; /** 0 or 1 */ struct xmesa_buffer *Next; /* Linked list pointer: */ -}; - - - -/** cast wrapper */ -static INLINE XMesaContext -xmesa_context(GLcontext *ctx) -{ - return (XMesaContext) ctx->DriverCtx; -} + unsigned width, height; +}; -/** cast wrapper */ -static INLINE XMesaBuffer -xmesa_buffer(GLframebuffer *fb) -{ - struct st_framebuffer *stfb = (struct st_framebuffer *) fb; - return (XMesaBuffer) st_framebuffer_private(stfb); -} extern void xmesa_init(Display *dpy); -extern void -xmesa_delete_framebuffer(struct gl_framebuffer *fb); - extern XMesaBuffer xmesa_find_buffer(Display *dpy, Colormap cmap, XMesaBuffer notThis); @@ -370,7 +355,7 @@ xmesa_get_window_size(Display *dpy, XMesaBuffer b, GLuint *width, GLuint *height); extern void -xmesa_check_and_update_buffer_size(XMesaContext xmctx, XMesaBuffer drawBuffer); +xmesa_check_buffer_size(XMesaBuffer b); extern void xmesa_destroy_buffers_on_display(Display *dpy); @@ -378,13 +363,13 @@ xmesa_destroy_buffers_on_display(Display *dpy); static INLINE GLuint xmesa_buffer_width(XMesaBuffer b) { - return b->stfb->Base.Width; + return b->width; } static INLINE GLuint xmesa_buffer_height(XMesaBuffer b) { - return b->stfb->Base.Height; + return b->height; } diff --git a/src/gallium/state_trackers/glx/xlib/xm_st.c b/src/gallium/state_trackers/glx/xlib/xm_st.c new file mode 100644 index 00000000000..c5ea5c1549b --- /dev/null +++ b/src/gallium/state_trackers/glx/xlib/xm_st.c @@ -0,0 +1,269 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu + */ + +#include "util/u_memory.h" +#include "util/u_inlines.h" + +#include "xm_api.h" +#include "xm_st.h" + +/* support OpenGL by default */ +#ifndef XMESA_ST_MODULE +#define XMESA_ST_MODULE st_module_OpenGL +#endif + +struct xmesa_st_framebuffer { + struct pipe_screen *screen; + XMesaBuffer buffer; + + struct st_visual stvis; + + unsigned texture_width, texture_height; + struct pipe_texture *textures[ST_ATTACHMENT_COUNT]; + + struct pipe_surface *display_surface; +}; + +static INLINE struct xmesa_st_framebuffer * +xmesa_st_framebuffer(struct st_framebuffer_iface *stfbi) +{ + return (struct xmesa_st_framebuffer *) stfbi->st_manager_private; +} + +/** + * Display an attachment to the xlib_drawable of the framebuffer. + */ +static boolean +xmesa_st_framebuffer_display(struct st_framebuffer_iface *stfbi, + enum st_attachment_type statt) +{ + struct xmesa_st_framebuffer *xstfb = xmesa_st_framebuffer(stfbi); + struct pipe_texture *ptex = xstfb->textures[statt]; + struct pipe_surface *psurf; + + if (!ptex) + return TRUE; + + psurf = xstfb->display_surface; + /* (re)allocate the surface for the texture to be displayed */ + if (!psurf || psurf->texture != ptex) { + pipe_surface_reference(&xstfb->display_surface, NULL); + + psurf = xstfb->screen->get_tex_surface(xstfb->screen, + ptex, 0, 0, 0, PIPE_BUFFER_USAGE_CPU_READ); + if (!psurf) + return FALSE; + + xstfb->display_surface = psurf; + } + + xstfb->screen->flush_frontbuffer(xstfb->screen, psurf, &xstfb->buffer->ws); + + return TRUE; +} + +/** + * Remove outdated textures and create the requested ones. + */ +static void +xmesa_st_framebuffer_validate_textures(struct st_framebuffer_iface *stfbi, + const enum st_attachment_type *statts, + unsigned count) +{ + struct xmesa_st_framebuffer *xstfb = xmesa_st_framebuffer(stfbi); + struct pipe_texture templ; + unsigned request_mask, i; + + request_mask = 0; + for (i = 0; i < count; i++) + request_mask |= 1 << statts[i]; + + memset(&templ, 0, sizeof(templ)); + templ.target = PIPE_TEXTURE_2D; + templ.width0 = xstfb->texture_width; + templ.height0 = xstfb->texture_height; + templ.depth0 = 1; + templ.last_level = 0; + + for (i = 0; i < ST_ATTACHMENT_COUNT; i++) { + struct pipe_texture *ptex = xstfb->textures[i]; + enum pipe_format format; + unsigned tex_usage; + + /* remove outdated textures */ + if (ptex && (ptex->width0 != xstfb->texture_width || + ptex->height0 != xstfb->texture_height)) { + pipe_texture_reference(&xstfb->textures[i], NULL); + ptex = NULL; + } + + /* the texture already exists or not requested */ + if (ptex || !(request_mask & (1 << i))) + continue; + + switch (i) { + case ST_ATTACHMENT_FRONT_LEFT: + case ST_ATTACHMENT_BACK_LEFT: + case ST_ATTACHMENT_FRONT_RIGHT: + case ST_ATTACHMENT_BACK_RIGHT: + format = xstfb->stvis.color_format; + tex_usage = PIPE_TEXTURE_USAGE_DISPLAY_TARGET | + PIPE_TEXTURE_USAGE_RENDER_TARGET; + break; + case ST_ATTACHMENT_DEPTH_STENCIL: + format = xstfb->stvis.depth_stencil_format; + tex_usage = PIPE_TEXTURE_USAGE_DEPTH_STENCIL; + break; + default: + format = PIPE_FORMAT_NONE; + break; + } + + if (format != PIPE_FORMAT_NONE) { + templ.format = format; + templ.tex_usage = tex_usage; + + xstfb->textures[i] = + xstfb->screen->texture_create(xstfb->screen, &templ); + } + } +} + +static boolean +xmesa_st_framebuffer_validate(struct st_framebuffer_iface *stfbi, + const enum st_attachment_type *statts, + unsigned count, + struct pipe_texture **out) +{ + struct xmesa_st_framebuffer *xstfb = xmesa_st_framebuffer(stfbi); + unsigned i; + + /* revalidate textures */ + if (xstfb->buffer->width != xstfb->texture_width || + xstfb->buffer->height != xstfb->texture_height) { + xstfb->texture_width = xstfb->buffer->width; + xstfb->texture_height = xstfb->buffer->height; + + xmesa_st_framebuffer_validate_textures(stfbi, statts, count); + } + + for (i = 0; i < count; i++) { + out[i] = NULL; + pipe_texture_reference(&out[i], xstfb->textures[statts[i]]); + } + + return TRUE; +} + +static boolean +xmesa_st_framebuffer_flush_front(struct st_framebuffer_iface *stfbi, + enum st_attachment_type statt) +{ + struct xmesa_st_framebuffer *xstfb = xmesa_st_framebuffer(stfbi); + boolean ret; + + ret = xmesa_st_framebuffer_flush_front(stfbi, statt); + if (ret) + xmesa_check_buffer_size(xstfb->buffer); + + return ret; +} + +struct st_framebuffer_iface * +xmesa_create_st_framebuffer(struct pipe_screen *screen, XMesaBuffer b) +{ + struct st_framebuffer_iface *stfbi; + struct xmesa_st_framebuffer *xstfb; + + stfbi = CALLOC_STRUCT(st_framebuffer_iface); + xstfb = CALLOC_STRUCT(xmesa_st_framebuffer); + if (!stfbi || !xstfb) { + if (stfbi) + FREE(stfbi); + if (xstfb) + FREE(xstfb); + return NULL; + } + + xstfb->screen = screen; + xstfb->buffer = b; + xstfb->stvis = b->xm_visual->stvis; + + stfbi->visual = &xstfb->stvis; + stfbi->flush_front = xmesa_st_framebuffer_flush_front; + stfbi->validate = xmesa_st_framebuffer_validate; + stfbi->st_manager_private = (void *) xstfb; + + return stfbi; +} + +void +xmesa_destroy_st_framebuffer(struct st_framebuffer_iface *stfbi) +{ + struct xmesa_st_framebuffer *xstfb = xmesa_st_framebuffer(stfbi); + + FREE(xstfb); + FREE(stfbi); +} + +void +xmesa_swap_st_framebuffer(struct st_framebuffer_iface *stfbi) +{ + struct xmesa_st_framebuffer *xstfb = xmesa_st_framebuffer(stfbi); + boolean ret; + + ret = xmesa_st_framebuffer_display(stfbi, ST_ATTACHMENT_BACK_LEFT); + if (ret) { + struct pipe_texture **front, **back, *tmp; + + front = &xstfb->textures[ST_ATTACHMENT_FRONT_LEFT]; + back = &xstfb->textures[ST_ATTACHMENT_BACK_LEFT]; + /* swap textures only if the front texture has been allocated */ + if (*front) { + tmp = *front; + *front = *back; + *back = tmp; + } + + xmesa_check_buffer_size(xstfb->buffer); + } +} + +void +xmesa_copy_st_framebuffer(struct st_framebuffer_iface *stfbi, + enum st_attachment_type src, + enum st_attachment_type dst, + int x, int y, int w, int h) +{ + /* TODO */ +} + +struct st_api * +xmesa_create_st_api(void) +{ + return XMESA_ST_MODULE.create_api(); +} diff --git a/src/gallium/state_trackers/glx/xlib/xm_st.h b/src/gallium/state_trackers/glx/xlib/xm_st.h new file mode 100644 index 00000000000..7ca7afe2531 --- /dev/null +++ b/src/gallium/state_trackers/glx/xlib/xm_st.h @@ -0,0 +1,54 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu + */ + +#ifndef _XM_ST_H_ +#define _XM_ST_H_ + +#include "pipe/p_compiler.h" +#include "state_tracker/st_api.h" + +#include "xm_api.h" + +struct st_api * +xmesa_create_st_api(void); + +struct st_framebuffer_iface * +xmesa_create_st_framebuffer(struct pipe_screen *screen, XMesaBuffer b); + +void +xmesa_destroy_st_framebuffer(struct st_framebuffer_iface *stfbi); + +void +xmesa_swap_st_framebuffer(struct st_framebuffer_iface *stfbi); + +void +xmesa_copy_st_framebuffer(struct st_framebuffer_iface *stfbi, + enum st_attachment_type src, + enum st_attachment_type dst, + int x, int y, int w, int h); + +#endif /* _XM_ST_H_ */ -- cgit v1.2.3 From 72ed7eb15a12ad88647dddefde5999ddd308b9e4 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Fri, 12 Mar 2010 10:04:47 +0800 Subject: st/glx: Fix an infinite recursion in flush_front. It was a stupid typo by me when I refactored the code. --- src/gallium/state_trackers/glx/xlib/xm_st.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/glx/xlib/xm_st.c b/src/gallium/state_trackers/glx/xlib/xm_st.c index c5ea5c1549b..3b5f78e98ad 100644 --- a/src/gallium/state_trackers/glx/xlib/xm_st.c +++ b/src/gallium/state_trackers/glx/xlib/xm_st.c @@ -186,7 +186,7 @@ xmesa_st_framebuffer_flush_front(struct st_framebuffer_iface *stfbi, struct xmesa_st_framebuffer *xstfb = xmesa_st_framebuffer(stfbi); boolean ret; - ret = xmesa_st_framebuffer_flush_front(stfbi, statt); + ret = xmesa_st_framebuffer_display(stfbi, statt); if (ret) xmesa_check_buffer_size(xstfb->buffer); -- cgit v1.2.3 From 3475e88442c16fb2b50b903fe246b3ebe49da226 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Fri, 12 Mar 2010 11:20:27 +0800 Subject: st/glx: Return a better format in choose_depth_stencil_format. Return a better format instead of an exact format in choose_depth_stencil_format. Also, prefer formats with stencil bits. --- src/gallium/state_trackers/glx/xlib/xm_api.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/glx/xlib/xm_api.c b/src/gallium/state_trackers/glx/xlib/xm_api.c index 6a0f3146dbf..3ea4d77805f 100644 --- a/src/gallium/state_trackers/glx/xlib/xm_api.c +++ b/src/gallium/state_trackers/glx/xlib/xm_api.c @@ -274,7 +274,8 @@ choose_pixel_format(XMesaVisual v) } /** - * Choose a depth/stencil format for the given depth and stencil sizes. + * Choose a depth/stencil format that is "better" than the given depth and + * stencil sizes. */ static enum pipe_format choose_depth_stencil_format(int depth, int stencil) @@ -289,21 +290,16 @@ choose_depth_stencil_format(int depth, int stencil) assert(screen); count = 0; - switch (depth) { - case 16: - if (!stencil) - formats[count++] = PIPE_FORMAT_Z16_UNORM; - break; - case 24: + if (depth <= 24 && stencil <= 8) { formats[count++] = PIPE_FORMAT_S8Z24_UNORM; formats[count++] = PIPE_FORMAT_Z24S8_UNORM; - break; - case 32: - if (!stencil) + } + + if (!stencil) { + if (depth <= 16) + formats[count++] = PIPE_FORMAT_Z16_UNORM; + if (depth <= 32) formats[count++] = PIPE_FORMAT_Z32_UNORM; - break; - default: - break; } fmt = PIPE_FORMAT_NONE; -- cgit v1.2.3 From 9dae0e0ff88957d16db47130a2646179fb5fc267 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Fri, 12 Mar 2010 13:26:18 +0800 Subject: st/glx: Add xm_st.c to SConscript. --- src/gallium/state_trackers/glx/xlib/SConscript | 1 + 1 file changed, 1 insertion(+) (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/glx/xlib/SConscript b/src/gallium/state_trackers/glx/xlib/SConscript index bb202351509..d6c16ad2f52 100644 --- a/src/gallium/state_trackers/glx/xlib/SConscript +++ b/src/gallium/state_trackers/glx/xlib/SConscript @@ -20,6 +20,7 @@ if env['platform'] == 'linux' \ 'glx_getproc.c', 'glx_usefont.c', 'xm_api.c', + 'xm_st.c', ] ) Export('st_xlib') -- cgit v1.2.3 From 08f89988c8738029c60e89c61c9da0522bd53087 Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Fri, 12 Mar 2010 14:36:23 +0100 Subject: cso: Add entry points for vertex/fragment sampler views. --- src/gallium/auxiliary/cso_cache/cso_context.c | 154 +++++++++++++++++++++++--- src/gallium/auxiliary/cso_cache/cso_context.h | 28 +++++ 2 files changed, 167 insertions(+), 15 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/auxiliary/cso_cache/cso_context.c b/src/gallium/auxiliary/cso_cache/cso_context.c index 8568a0052d0..5c16e0959d6 100644 --- a/src/gallium/auxiliary/cso_cache/cso_context.c +++ b/src/gallium/auxiliary/cso_cache/cso_context.c @@ -37,6 +37,7 @@ #include "pipe/p_state.h" #include "util/u_inlines.h" +#include "util/u_math.h" #include "util/u_memory.h" #include "util/u_sampler.h" #include "tgsi/tgsi_parse.h" @@ -71,19 +72,23 @@ struct cso_context { void *vertex_samplers_saved[PIPE_MAX_VERTEX_SAMPLERS]; struct pipe_texture *textures[PIPE_MAX_SAMPLERS]; - struct pipe_sampler_view *sampler_views[PIPE_MAX_SAMPLERS]; + uint nr_fragment_sampler_views; + struct pipe_sampler_view *fragment_sampler_views[PIPE_MAX_SAMPLERS]; uint nr_textures; struct pipe_texture *vertex_textures[PIPE_MAX_VERTEX_SAMPLERS]; + uint nr_vertex_sampler_views; struct pipe_sampler_view *vertex_sampler_views[PIPE_MAX_VERTEX_SAMPLERS]; uint nr_vertex_textures; uint nr_textures_saved; struct pipe_texture *textures_saved[PIPE_MAX_SAMPLERS]; - struct pipe_sampler_view *sampler_views_saved[PIPE_MAX_SAMPLERS]; + uint nr_fragment_sampler_views_saved; + struct pipe_sampler_view *fragment_sampler_views_saved[PIPE_MAX_SAMPLERS]; uint nr_vertex_textures_saved; struct pipe_texture *vertex_textures_saved[PIPE_MAX_VERTEX_SAMPLERS]; + uint nr_vertex_sampler_views_saved; struct pipe_sampler_view *vertex_sampler_views_saved[PIPE_MAX_VERTEX_SAMPLERS]; /** Current and saved state. @@ -300,8 +305,8 @@ void cso_release_all( struct cso_context *ctx ) for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { pipe_texture_reference(&ctx->textures[i], NULL); pipe_texture_reference(&ctx->textures_saved[i], NULL); - pipe_sampler_view_reference(&ctx->sampler_views[i], NULL); - pipe_sampler_view_reference(&ctx->sampler_views_saved[i], NULL); + pipe_sampler_view_reference(&ctx->fragment_sampler_views[i], NULL); + pipe_sampler_view_reference(&ctx->fragment_sampler_views_saved[i], NULL); } for (i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; i++) { @@ -644,16 +649,16 @@ enum pipe_error cso_set_sampler_textures( struct cso_context *ctx, &templ); pipe_texture_reference(&ctx->textures[i], textures[i]); - pipe_sampler_view_reference(&ctx->sampler_views[i], view); + pipe_sampler_view_reference(&ctx->fragment_sampler_views[i], view); } for ( ; i < PIPE_MAX_SAMPLERS; i++) { pipe_texture_reference(&ctx->textures[i], NULL); - pipe_sampler_view_reference(&ctx->sampler_views[i], NULL); + pipe_sampler_view_reference(&ctx->fragment_sampler_views[i], NULL); } ctx->pipe->set_fragment_sampler_views(ctx->pipe, count, - ctx->sampler_views); + ctx->fragment_sampler_views); return PIPE_OK; } @@ -665,11 +670,11 @@ void cso_save_sampler_textures( struct cso_context *ctx ) ctx->nr_textures_saved = ctx->nr_textures; for (i = 0; i < ctx->nr_textures; i++) { assert(!ctx->textures_saved[i]); - assert(!ctx->sampler_views_saved[i]); + assert(!ctx->fragment_sampler_views_saved[i]); pipe_texture_reference(&ctx->textures_saved[i], ctx->textures[i]); - pipe_sampler_view_reference(&ctx->sampler_views_saved[i], - ctx->sampler_views[i]); + pipe_sampler_view_reference(&ctx->fragment_sampler_views_saved[i], + ctx->fragment_sampler_views[i]); } } @@ -684,18 +689,18 @@ void cso_restore_sampler_textures( struct cso_context *ctx ) ctx->textures[i] = ctx->textures_saved[i]; ctx->textures_saved[i] = NULL; - pipe_sampler_view_reference(&ctx->sampler_views[i], NULL); - ctx->sampler_views[i] = ctx->sampler_views_saved[i]; - ctx->sampler_views_saved[i] = NULL; + pipe_sampler_view_reference(&ctx->fragment_sampler_views[i], NULL); + ctx->fragment_sampler_views[i] = ctx->fragment_sampler_views_saved[i]; + ctx->fragment_sampler_views_saved[i] = NULL; } for ( ; i < PIPE_MAX_SAMPLERS; i++) { pipe_texture_reference(&ctx->textures[i], NULL); - pipe_sampler_view_reference(&ctx->sampler_views[i], NULL); + pipe_sampler_view_reference(&ctx->fragment_sampler_views[i], NULL); } ctx->pipe->set_fragment_sampler_views(ctx->pipe, ctx->nr_textures, - ctx->sampler_views); + ctx->fragment_sampler_views); ctx->nr_textures_saved = 0; } @@ -1319,3 +1324,122 @@ void cso_restore_vertex_elements(struct cso_context *ctx) } ctx->velements_saved = NULL; } + +/* fragment sampler view state */ + +void +cso_set_fragment_sampler_views(struct cso_context *cso, + uint count, + struct pipe_sampler_view **views) +{ + uint i; + + for (i = 0; i < count; i++) { + pipe_sampler_view_reference(&cso->fragment_sampler_views[i], views[i]); + } + for (; i < cso->nr_fragment_sampler_views; i++) { + pipe_sampler_view_reference(&cso->fragment_sampler_views[i], NULL); + } + + cso->pipe->set_fragment_sampler_views(cso->pipe, + MAX2(count, cso->nr_fragment_sampler_views), + cso->fragment_sampler_views); + + cso->nr_fragment_sampler_views = count; +} + +void +cso_save_fragment_sampler_views(struct cso_context *cso) +{ + uint i; + + cso->nr_fragment_sampler_views_saved = cso->nr_fragment_sampler_views; + + for (i = 0; i < cso->nr_fragment_sampler_views; i++) { + assert(!cso->fragment_sampler_views_saved[i]); + + pipe_sampler_view_reference(&cso->fragment_sampler_views_saved[i], + cso->fragment_sampler_views[i]); + } +} + +void +cso_restore_fragment_sampler_views(struct cso_context *cso) +{ + uint i; + + for (i = 0; i < cso->nr_fragment_sampler_views_saved; i++) { + pipe_sampler_view_reference(&cso->fragment_sampler_views[i], cso->fragment_sampler_views_saved[i]); + pipe_sampler_view_reference(&cso->fragment_sampler_views_saved[i], NULL); + } + for (; i < cso->nr_fragment_sampler_views; i++) { + pipe_sampler_view_reference(&cso->fragment_sampler_views[i], NULL); + } + + cso->pipe->set_fragment_sampler_views(cso->pipe, + MAX2(cso->nr_fragment_sampler_views, cso->nr_fragment_sampler_views_saved), + cso->fragment_sampler_views); + + cso->nr_fragment_sampler_views = cso->nr_fragment_sampler_views_saved; + cso->nr_fragment_sampler_views_saved = 0; +} + + +/* vertex sampler view state */ + +void +cso_set_vertex_sampler_views(struct cso_context *cso, + uint count, + struct pipe_sampler_view **views) +{ + uint i; + + for (i = 0; i < count; i++) { + pipe_sampler_view_reference(&cso->vertex_sampler_views[i], views[i]); + } + for (; i < cso->nr_vertex_sampler_views; i++) { + pipe_sampler_view_reference(&cso->vertex_sampler_views[i], NULL); + } + + cso->pipe->set_vertex_sampler_views(cso->pipe, + MAX2(count, cso->nr_vertex_sampler_views), + cso->vertex_sampler_views); + + cso->nr_vertex_sampler_views = count; +} + +void +cso_save_vertex_sampler_views(struct cso_context *cso) +{ + uint i; + + cso->nr_vertex_sampler_views_saved = cso->nr_vertex_sampler_views; + + for (i = 0; i < cso->nr_vertex_sampler_views; i++) { + assert(!cso->vertex_sampler_views_saved[i]); + + pipe_sampler_view_reference(&cso->vertex_sampler_views_saved[i], + cso->vertex_sampler_views[i]); + } +} + +void +cso_restore_vertex_sampler_views(struct cso_context *cso) +{ + uint i; + + for (i = 0; i < cso->nr_vertex_sampler_views_saved; i++) { + pipe_sampler_view_reference(&cso->vertex_sampler_views[i], cso->vertex_sampler_views_saved[i]); + pipe_sampler_view_reference(&cso->vertex_sampler_views_saved[i], NULL); + } + for (; i < cso->nr_vertex_sampler_views; i++) { + pipe_sampler_view_reference(&cso->vertex_sampler_views[i], NULL); + } + + cso->pipe->set_vertex_sampler_views(cso->pipe, + MAX2(cso->nr_vertex_sampler_views, cso->nr_vertex_sampler_views_saved), + cso->vertex_sampler_views); + + cso->nr_vertex_sampler_views = cso->nr_vertex_sampler_views_saved; + cso->nr_vertex_sampler_views_saved = 0; +} diff --git a/src/gallium/auxiliary/cso_cache/cso_context.h b/src/gallium/auxiliary/cso_cache/cso_context.h index 9c16abd28dd..e476cf4adef 100644 --- a/src/gallium/auxiliary/cso_cache/cso_context.h +++ b/src/gallium/auxiliary/cso_cache/cso_context.h @@ -198,6 +198,34 @@ void cso_restore_clip(struct cso_context *cso); +/* fragment sampler view state */ + +void +cso_set_fragment_sampler_views(struct cso_context *cso, + uint count, + struct pipe_sampler_view **views); + +void +cso_save_fragment_sampler_views(struct cso_context *cso); + +void +cso_restore_fragment_sampler_views(struct cso_context *cso); + + +/* vertex sampler view state */ + +void +cso_set_vertex_sampler_views(struct cso_context *cso, + uint count, + struct pipe_sampler_view **views); + +void +cso_save_vertex_sampler_views(struct cso_context *cso); + +void +cso_restore_vertex_sampler_views(struct cso_context *cso); + + #ifdef __cplusplus } #endif -- cgit v1.2.3 From faa14818856e1e9a4ee624c2bc04d7aecabd07ab Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Fri, 12 Mar 2010 14:43:11 +0100 Subject: cso: Remove set/save/restore_vertex_sampler_textures(). --- src/gallium/auxiliary/cso_cache/cso_context.c | 87 --------------------------- src/gallium/auxiliary/cso_cache/cso_context.h | 11 ---- 2 files changed, 98 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/auxiliary/cso_cache/cso_context.c b/src/gallium/auxiliary/cso_cache/cso_context.c index 5c16e0959d6..648ba10a995 100644 --- a/src/gallium/auxiliary/cso_cache/cso_context.c +++ b/src/gallium/auxiliary/cso_cache/cso_context.c @@ -76,18 +76,14 @@ struct cso_context { struct pipe_sampler_view *fragment_sampler_views[PIPE_MAX_SAMPLERS]; uint nr_textures; - struct pipe_texture *vertex_textures[PIPE_MAX_VERTEX_SAMPLERS]; uint nr_vertex_sampler_views; struct pipe_sampler_view *vertex_sampler_views[PIPE_MAX_VERTEX_SAMPLERS]; - uint nr_vertex_textures; uint nr_textures_saved; struct pipe_texture *textures_saved[PIPE_MAX_SAMPLERS]; uint nr_fragment_sampler_views_saved; struct pipe_sampler_view *fragment_sampler_views_saved[PIPE_MAX_SAMPLERS]; - uint nr_vertex_textures_saved; - struct pipe_texture *vertex_textures_saved[PIPE_MAX_VERTEX_SAMPLERS]; uint nr_vertex_sampler_views_saved; struct pipe_sampler_view *vertex_sampler_views_saved[PIPE_MAX_VERTEX_SAMPLERS]; @@ -310,8 +306,6 @@ void cso_release_all( struct cso_context *ctx ) } for (i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; i++) { - pipe_texture_reference(&ctx->vertex_textures[i], NULL); - pipe_texture_reference(&ctx->vertex_textures_saved[i], NULL); pipe_sampler_view_reference(&ctx->vertex_sampler_views[i], NULL); pipe_sampler_view_reference(&ctx->vertex_sampler_views_saved[i], NULL); } @@ -706,87 +700,6 @@ void cso_restore_sampler_textures( struct cso_context *ctx ) } - -enum pipe_error -cso_set_vertex_sampler_textures(struct cso_context *ctx, - uint count, - struct pipe_texture **textures) -{ - uint i; - - ctx->nr_vertex_textures = count; - - for (i = 0; i < count; i++) { - struct pipe_sampler_view templ, *view; - - u_sampler_view_default_template(&templ, - textures[i], - textures[i]->format); - view = ctx->pipe->create_sampler_view(ctx->pipe, - textures[i], - &templ); - - pipe_texture_reference(&ctx->vertex_textures[i], textures[i]); - pipe_sampler_view_reference(&ctx->vertex_sampler_views[i], view); - } - for ( ; i < PIPE_MAX_VERTEX_SAMPLERS; i++) { - pipe_texture_reference(&ctx->vertex_textures[i], NULL); - pipe_sampler_view_reference(&ctx->vertex_sampler_views[i], NULL); - } - - ctx->pipe->set_vertex_sampler_views(ctx->pipe, - count, - ctx->vertex_sampler_views); - - return PIPE_OK; -} - -void -cso_save_vertex_sampler_textures(struct cso_context *ctx) -{ - uint i; - - ctx->nr_vertex_textures_saved = ctx->nr_vertex_textures; - for (i = 0; i < ctx->nr_vertex_textures; i++) { - assert(!ctx->vertex_textures_saved[i]); - assert(!ctx->vertex_sampler_views_saved[i]); - - pipe_texture_reference(&ctx->vertex_textures_saved[i], ctx->vertex_textures[i]); - pipe_sampler_view_reference(&ctx->vertex_sampler_views_saved[i], - ctx->vertex_sampler_views[i]); - } -} - -void -cso_restore_vertex_sampler_textures(struct cso_context *ctx) -{ - uint i; - - ctx->nr_vertex_textures = ctx->nr_vertex_textures_saved; - - for (i = 0; i < ctx->nr_vertex_textures; i++) { - pipe_texture_reference(&ctx->vertex_textures[i], NULL); - ctx->vertex_textures[i] = ctx->vertex_textures_saved[i]; - ctx->vertex_textures_saved[i] = NULL; - - pipe_sampler_view_reference(&ctx->vertex_sampler_views[i], NULL); - ctx->vertex_sampler_views[i] = ctx->vertex_sampler_views_saved[i]; - ctx->vertex_sampler_views_saved[i] = NULL; - } - for ( ; i < PIPE_MAX_VERTEX_SAMPLERS; i++) { - pipe_texture_reference(&ctx->vertex_textures[i], NULL); - pipe_sampler_view_reference(&ctx->vertex_sampler_views[i], NULL); - } - - ctx->pipe->set_vertex_sampler_views(ctx->pipe, - ctx->nr_vertex_textures, - ctx->vertex_sampler_views); - - ctx->nr_vertex_textures_saved = 0; -} - - - enum pipe_error cso_set_depth_stencil_alpha(struct cso_context *ctx, const struct pipe_depth_stencil_alpha_state *templ) { diff --git a/src/gallium/auxiliary/cso_cache/cso_context.h b/src/gallium/auxiliary/cso_cache/cso_context.h index e476cf4adef..a24077e009c 100644 --- a/src/gallium/auxiliary/cso_cache/cso_context.h +++ b/src/gallium/auxiliary/cso_cache/cso_context.h @@ -111,17 +111,6 @@ void cso_save_sampler_textures( struct cso_context *cso ); void cso_restore_sampler_textures( struct cso_context *cso ); - -enum pipe_error -cso_set_vertex_sampler_textures(struct cso_context *cso, - uint count, - struct pipe_texture **textures); -void -cso_save_vertex_sampler_textures(struct cso_context *cso); -void -cso_restore_vertex_sampler_textures(struct cso_context *cso); - - enum pipe_error cso_set_vertex_elements(struct cso_context *ctx, unsigned count, const struct pipe_vertex_element *states); -- cgit v1.2.3 From 495bfb0ad2e60638e7b2e94f36f0079e3f450091 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Sat, 13 Mar 2010 00:52:47 +0800 Subject: st/glx: Fix leaks in xmesa_st_framebuffer. The textures and surface of a framebuffer should be unreferenced when the framebuffer is destroyed. --- src/gallium/state_trackers/glx/xlib/xm_st.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/glx/xlib/xm_st.c b/src/gallium/state_trackers/glx/xlib/xm_st.c index 3b5f78e98ad..d462776363c 100644 --- a/src/gallium/state_trackers/glx/xlib/xm_st.c +++ b/src/gallium/state_trackers/glx/xlib/xm_st.c @@ -225,6 +225,12 @@ void xmesa_destroy_st_framebuffer(struct st_framebuffer_iface *stfbi) { struct xmesa_st_framebuffer *xstfb = xmesa_st_framebuffer(stfbi); + int i; + + pipe_surface_reference(&xstfb->display_surface, NULL); + + for (i = 0; i < ST_ATTACHMENT_COUNT; i++) + pipe_texture_reference(&xstfb->textures[i], NULL); FREE(xstfb); FREE(stfbi); -- cgit v1.2.3 From fecb97aab42e1a099f12cc7a47ed7219cd041809 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Sat, 13 Mar 2010 14:57:32 +0800 Subject: st/egl: Fix eglCopyBuffers. Use a (real) pipe context to copy between pipe surfaces. Fix a NULL dereference of the temporary native surface created for copying. --- src/gallium/state_trackers/egl/common/egl_g3d.c | 34 +++++++++++++++---------- src/gallium/state_trackers/egl/common/egl_g3d.h | 1 + 2 files changed, 22 insertions(+), 13 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/egl/common/egl_g3d.c b/src/gallium/state_trackers/egl/common/egl_g3d.c index 783b8e56b38..5eabe10558a 100644 --- a/src/gallium/state_trackers/egl/common/egl_g3d.c +++ b/src/gallium/state_trackers/egl/common/egl_g3d.c @@ -323,8 +323,13 @@ egl_g3d_invalid_surface(struct native_display *ndpy, { /* XXX not thread safe? */ struct egl_g3d_surface *gsurf = egl_g3d_surface(nsurf->user_data); - struct egl_g3d_context *gctx = egl_g3d_context(gsurf->base.CurrentContext); - + struct egl_g3d_context *gctx; + + /* + * Some functions such as egl_g3d_copy_buffers create a temporary native + * surface. There is no gsurf associated with it. + */ + gctx = (gsurf) ? egl_g3d_context(gsurf->base.CurrentContext) : NULL; if (gctx) gctx->stctxi->notify_invalid_framebuffer(gctx->stctxi, gsurf->stfbi); } @@ -342,6 +347,9 @@ egl_g3d_terminate(_EGLDriver *drv, _EGLDisplay *dpy) _eglReleaseDisplayResources(drv, dpy); _eglCleanupDisplay(dpy); + if (gdpy->pipe) + gdpy->pipe->destroy(gdpy->pipe); + if (dpy->Screens) { for (i = 0; i < dpy->NumScreens; i++) { struct egl_g3d_screen *gscr = egl_g3d_screen(dpy->Screens[i]); @@ -778,7 +786,7 @@ get_pipe_surface(struct native_display *ndpy, struct native_surface *nsurf, return NULL; psurf = ndpy->screen->get_tex_surface(ndpy->screen, textures[natt], - 0, 0, 0, PIPE_BUFFER_USAGE_CPU_WRITE); + 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE); pipe_texture_reference(&textures[natt], NULL); return psurf; @@ -815,22 +823,22 @@ egl_g3d_copy_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_FRAME, NULL); } + /* create a pipe context to copy surfaces */ + if (!gdpy->pipe) { + gdpy->pipe = + gdpy->native->screen->context_create(gdpy->native->screen, NULL); + if (!gdpy->pipe) + return EGL_FALSE; + } + psurf = get_pipe_surface(gdpy->native, nsurf, NATIVE_ATTACHMENT_FRONT_LEFT); if (psurf) { - struct pipe_context pipe; struct pipe_surface *psrc; - /** - * XXX This is hacky. We should probably create a pipe context for - * EGLDisplay and use a blitter context for this. - */ - memset(&pipe, 0, sizeof(pipe)); - pipe.screen = screen; - psrc = screen->get_tex_surface(screen, gsurf->render_texture, - 0, 0, 0, PIPE_BUFFER_USAGE_CPU_READ); + 0, 0, 0, PIPE_BUFFER_USAGE_GPU_READ); if (psrc) { - util_surface_copy(&pipe, FALSE, psurf, 0, 0, + gdpy->pipe->surface_copy(gdpy->pipe, psurf, 0, 0, psrc, 0, 0, psurf->width, psurf->height); pipe_surface_reference(&psrc, NULL); diff --git a/src/gallium/state_trackers/egl/common/egl_g3d.h b/src/gallium/state_trackers/egl/common/egl_g3d.h index 07a87f8bc73..2788f1bf4ac 100644 --- a/src/gallium/state_trackers/egl/common/egl_g3d.h +++ b/src/gallium/state_trackers/egl/common/egl_g3d.h @@ -53,6 +53,7 @@ struct egl_g3d_display { struct native_display *native; struct st_manager *smapi; + struct pipe_context *pipe; }; struct egl_g3d_context { -- cgit v1.2.3 From 813c58d77e21cb59adb914b4b4ee26be758ff0ea Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Sat, 13 Mar 2010 15:57:15 +0800 Subject: st/glx: Make xmesa_create_st_api a callback of xm_driver. Instead of guessing the API in st/glx, let the target decide how to create st_api. --- src/gallium/state_trackers/glx/xlib/xm_api.c | 2 +- src/gallium/state_trackers/glx/xlib/xm_public.h | 12 ++++++++---- src/gallium/state_trackers/glx/xlib/xm_st.c | 11 ----------- src/gallium/state_trackers/glx/xlib/xm_st.h | 3 --- src/gallium/targets/libgl-xlib/xlib.c | 3 ++- 5 files changed, 11 insertions(+), 20 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/glx/xlib/xm_api.c b/src/gallium/state_trackers/glx/xlib/xm_api.c index 3ea4d77805f..82384a4d284 100644 --- a/src/gallium/state_trackers/glx/xlib/xm_api.c +++ b/src/gallium/state_trackers/glx/xlib/xm_api.c @@ -708,7 +708,7 @@ xmesa_init( Display *display ) if (firstTime) { pipe_mutex_init(_xmesa_lock); screen = driver.create_pipe_screen( display ); - stapi = xmesa_create_st_api(); + stapi = driver.create_st_api(); smapi = CALLOC_STRUCT(st_manager); if (smapi) smapi->screen = screen; diff --git a/src/gallium/state_trackers/glx/xlib/xm_public.h b/src/gallium/state_trackers/glx/xlib/xm_public.h index ac6a8ffb27a..950eb21521f 100644 --- a/src/gallium/state_trackers/glx/xlib/xm_public.h +++ b/src/gallium/state_trackers/glx/xlib/xm_public.h @@ -26,19 +26,23 @@ * **************************************************************************/ -#ifndef XM_WINSYS_H -#define XM_WINSYS_H +#ifndef XM_PUBLIC_H +#define XM_PUBLIC_H -struct xm_driver; +#include + +struct pipe_screen; +struct st_api; /* This is the driver interface required by the glx/xlib state tracker. */ struct xm_driver { struct pipe_screen *(*create_pipe_screen)( Display *display ); + struct st_api *(*create_st_api)( void ); }; extern void xmesa_set_driver( const struct xm_driver *driver ); -#endif +#endif /* XM_PUBLIC_H */ diff --git a/src/gallium/state_trackers/glx/xlib/xm_st.c b/src/gallium/state_trackers/glx/xlib/xm_st.c index d462776363c..abe3b5429bc 100644 --- a/src/gallium/state_trackers/glx/xlib/xm_st.c +++ b/src/gallium/state_trackers/glx/xlib/xm_st.c @@ -31,11 +31,6 @@ #include "xm_api.h" #include "xm_st.h" -/* support OpenGL by default */ -#ifndef XMESA_ST_MODULE -#define XMESA_ST_MODULE st_module_OpenGL -#endif - struct xmesa_st_framebuffer { struct pipe_screen *screen; XMesaBuffer buffer; @@ -267,9 +262,3 @@ xmesa_copy_st_framebuffer(struct st_framebuffer_iface *stfbi, { /* TODO */ } - -struct st_api * -xmesa_create_st_api(void) -{ - return XMESA_ST_MODULE.create_api(); -} diff --git a/src/gallium/state_trackers/glx/xlib/xm_st.h b/src/gallium/state_trackers/glx/xlib/xm_st.h index 7ca7afe2531..b22a8373801 100644 --- a/src/gallium/state_trackers/glx/xlib/xm_st.h +++ b/src/gallium/state_trackers/glx/xlib/xm_st.h @@ -33,9 +33,6 @@ #include "xm_api.h" -struct st_api * -xmesa_create_st_api(void); - struct st_framebuffer_iface * xmesa_create_st_framebuffer(struct pipe_screen *screen, XMesaBuffer b); diff --git a/src/gallium/targets/libgl-xlib/xlib.c b/src/gallium/targets/libgl-xlib/xlib.c index 50dd99ffce1..1e6769367f4 100644 --- a/src/gallium/targets/libgl-xlib/xlib.c +++ b/src/gallium/targets/libgl-xlib/xlib.c @@ -104,9 +104,10 @@ fail: return NULL; } -struct xm_driver xlib_driver = +static struct xm_driver xlib_driver = { .create_pipe_screen = swrast_xlib_create_screen, + .create_st_api = st_manager_create_api, }; -- cgit v1.2.3 From 418b9ac2990fc6809de359a862ee809d3b86343c Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Sat, 13 Mar 2010 17:39:14 +0800 Subject: st/glx: Correctly set buffer_mask of a visual. Stupid typos again.. --- src/gallium/state_trackers/glx/xlib/xm_api.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/glx/xlib/xm_api.c b/src/gallium/state_trackers/glx/xlib/xm_api.c index 82384a4d284..94c0ad496d4 100644 --- a/src/gallium/state_trackers/glx/xlib/xm_api.c +++ b/src/gallium/state_trackers/glx/xlib/xm_api.c @@ -666,11 +666,11 @@ XMesaVisual XMesaCreateVisual( Display *display, v->stvis.buffer_mask = ST_ATTACHMENT_FRONT_LEFT_MASK; if (db_flag) - v->stvis.buffer_mask = ST_ATTACHMENT_BACK_LEFT_MASK; + v->stvis.buffer_mask |= ST_ATTACHMENT_BACK_LEFT_MASK; if (stereo_flag) { - v->stvis.buffer_mask = ST_ATTACHMENT_FRONT_RIGHT_MASK; + v->stvis.buffer_mask |= ST_ATTACHMENT_FRONT_RIGHT_MASK; if (db_flag) - v->stvis.buffer_mask = ST_ATTACHMENT_BACK_RIGHT_MASK; + v->stvis.buffer_mask |= ST_ATTACHMENT_BACK_RIGHT_MASK; } v->stvis.color_format = choose_pixel_format(v); -- cgit v1.2.3 From 66cd38f465499863de106e1ae83b5de85072c29b Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Sat, 13 Mar 2010 17:40:24 +0800 Subject: st/glx: Fix framebuffer validation. When xmesa_st_framebuffer_validate was called twice with different sets of attachments, the second call was ignored. Add a texture_mask to remember which textures have been requested to make sure the missing ones get created. --- src/gallium/state_trackers/glx/xlib/xm_st.c | 53 ++++++++++++++++------------- 1 file changed, 29 insertions(+), 24 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/glx/xlib/xm_st.c b/src/gallium/state_trackers/glx/xlib/xm_st.c index abe3b5429bc..8714da8b346 100644 --- a/src/gallium/state_trackers/glx/xlib/xm_st.c +++ b/src/gallium/state_trackers/glx/xlib/xm_st.c @@ -37,7 +37,7 @@ struct xmesa_st_framebuffer { struct st_visual stvis; - unsigned texture_width, texture_height; + unsigned texture_width, texture_height, texture_mask; struct pipe_texture *textures[ST_ATTACHMENT_COUNT]; struct pipe_surface *display_surface; @@ -86,39 +86,37 @@ xmesa_st_framebuffer_display(struct st_framebuffer_iface *stfbi, */ static void xmesa_st_framebuffer_validate_textures(struct st_framebuffer_iface *stfbi, - const enum st_attachment_type *statts, - unsigned count) + unsigned width, unsigned height, + unsigned mask) { struct xmesa_st_framebuffer *xstfb = xmesa_st_framebuffer(stfbi); struct pipe_texture templ; - unsigned request_mask, i; + unsigned i; - request_mask = 0; - for (i = 0; i < count; i++) - request_mask |= 1 << statts[i]; + /* remove outdated textures */ + if (xstfb->texture_width != width || xstfb->texture_height != height) { + for (i = 0; i < ST_ATTACHMENT_COUNT; i++) + pipe_texture_reference(&xstfb->textures[i], NULL); + } memset(&templ, 0, sizeof(templ)); templ.target = PIPE_TEXTURE_2D; - templ.width0 = xstfb->texture_width; - templ.height0 = xstfb->texture_height; + templ.width0 = width; + templ.height0 = height; templ.depth0 = 1; templ.last_level = 0; for (i = 0; i < ST_ATTACHMENT_COUNT; i++) { - struct pipe_texture *ptex = xstfb->textures[i]; enum pipe_format format; unsigned tex_usage; - /* remove outdated textures */ - if (ptex && (ptex->width0 != xstfb->texture_width || - ptex->height0 != xstfb->texture_height)) { - pipe_texture_reference(&xstfb->textures[i], NULL); - ptex = NULL; - } - /* the texture already exists or not requested */ - if (ptex || !(request_mask & (1 << i))) + if (xstfb->textures[i] || !(mask & (1 << i))) { + /* remember the texture */ + if (xstfb->textures[i]) + mask |= (1 << i); continue; + } switch (i) { case ST_ATTACHMENT_FRONT_LEFT: @@ -146,6 +144,10 @@ xmesa_st_framebuffer_validate_textures(struct st_framebuffer_iface *stfbi, xstfb->screen->texture_create(xstfb->screen, &templ); } } + + xstfb->texture_width = width; + xstfb->texture_height = height; + xstfb->texture_mask = mask; } static boolean @@ -155,15 +157,18 @@ xmesa_st_framebuffer_validate(struct st_framebuffer_iface *stfbi, struct pipe_texture **out) { struct xmesa_st_framebuffer *xstfb = xmesa_st_framebuffer(stfbi); - unsigned i; + unsigned statt_mask, i; + + statt_mask = 0x0; + for (i = 0; i < count; i++) + statt_mask |= 1 << statts[i]; /* revalidate textures */ if (xstfb->buffer->width != xstfb->texture_width || - xstfb->buffer->height != xstfb->texture_height) { - xstfb->texture_width = xstfb->buffer->width; - xstfb->texture_height = xstfb->buffer->height; - - xmesa_st_framebuffer_validate_textures(stfbi, statts, count); + xstfb->buffer->height != xstfb->texture_height || + (xstfb->texture_mask & statt_mask) != statt_mask) { + xmesa_st_framebuffer_validate_textures(stfbi, + xstfb->buffer->width, xstfb->buffer->height, statt_mask); } for (i = 0; i < count; i++) { -- cgit v1.2.3 From 6632915e957149c153a3f793c400a532b4995b18 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Sun, 14 Mar 2010 11:20:58 +0800 Subject: st/glx: Add xmesa_display to hold per-display variables. This basically adds a static xmesa_display to collect per-display static variables in xm_api.c. Multiple display support is still missing, but this is a step forward. --- src/gallium/state_trackers/glx/xlib/xm_api.c | 117 +++++++++++++++------------ src/gallium/state_trackers/glx/xlib/xm_api.h | 14 ++-- 2 files changed, 73 insertions(+), 58 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/glx/xlib/xm_api.c b/src/gallium/state_trackers/glx/xlib/xm_api.c index 94c0ad496d4..e7c1979b424 100644 --- a/src/gallium/state_trackers/glx/xlib/xm_api.c +++ b/src/gallium/state_trackers/glx/xlib/xm_api.c @@ -70,21 +70,56 @@ * global. */ static struct xm_driver driver; +static struct st_api *stapi; void xmesa_set_driver( const struct xm_driver *templ ) { driver = *templ; + stapi = driver.create_st_api(); } -/** - * Global X driver lock - */ -pipe_mutex _xmesa_lock; +static XMesaDisplay +xmesa_init_display( Display *display ) +{ + pipe_static_mutex(init_mutex); + static struct xmesa_display xm_display; + XMesaDisplay xmdpy; + + pipe_mutex_lock(init_mutex); + + /* TODO support for multiple displays */ + xmdpy = &xm_display; + + if (!xmdpy->display && display) { + xmdpy->display = display; + xmdpy->screen = driver.create_pipe_screen(display); + xmdpy->smapi = CALLOC_STRUCT(st_manager); + if (xmdpy->smapi) + xmdpy->smapi->screen = xmdpy->screen; + + if (xmdpy->screen && xmdpy->smapi) { + pipe_mutex_init(xmdpy->mutex); + } + else { + if (xmdpy->screen) { + xmdpy->screen->destroy(xmdpy->screen); + xmdpy->screen = NULL; + } + if (xmdpy->smapi) { + FREE(xmdpy->smapi); + xmdpy->smapi = NULL; + } -static struct pipe_screen *screen = NULL; -static struct st_api *stapi = NULL; -static struct st_manager *smapi = NULL; + xmdpy->display = NULL; + } + } + if (!xmdpy->display || xmdpy->display != display) + xmdpy = NULL; + pipe_mutex_unlock(init_mutex); + + return xmdpy; +} /**********************************************************************/ /***** X Utility Functions *****/ @@ -194,12 +229,13 @@ void xmesa_get_window_size(Display *dpy, XMesaBuffer b, GLuint *width, GLuint *height) { + XMesaDisplay xmdpy = xmesa_init_display(dpy); Status stat; - pipe_mutex_lock(_xmesa_lock); + pipe_mutex_lock(xmdpy->mutex); XSync(b->xm_visual->display, 0); /* added for Chromium */ stat = get_drawable_size(dpy, b->ws.drawable, width, height); - pipe_mutex_unlock(_xmesa_lock); + pipe_mutex_unlock(xmdpy->mutex); if (!stat) { /* probably querying a window that's recently been destroyed */ @@ -278,7 +314,7 @@ choose_pixel_format(XMesaVisual v) * stencil sizes. */ static enum pipe_format -choose_depth_stencil_format(int depth, int stencil) +choose_depth_stencil_format(XMesaDisplay xmdpy, int depth, int stencil) { const enum pipe_texture_target target = PIPE_TEXTURE_2D; const unsigned tex_usage = PIPE_TEXTURE_USAGE_DEPTH_STENCIL; @@ -287,8 +323,6 @@ choose_depth_stencil_format(int depth, int stencil) enum pipe_format formats[8], fmt; int count, i; - assert(screen); - count = 0; if (depth <= 24 && stencil <= 8) { formats[count++] = PIPE_FORMAT_S8Z24_UNORM; @@ -304,7 +338,7 @@ choose_depth_stencil_format(int depth, int stencil) fmt = PIPE_FORMAT_NONE; for (i = 0; i < count; i++) { - if (screen->is_format_supported(screen, formats[i], + if (xmdpy->screen->is_format_supported(xmdpy->screen, formats[i], target, tex_usage, geom_flags)) { fmt = formats[i]; break; @@ -320,7 +354,7 @@ choose_depth_stencil_format(int depth, int stencil) /***** Linked list of XMesaBuffers *****/ /**********************************************************************/ -XMesaBuffer XMesaBufferList = NULL; +static XMesaBuffer XMesaBufferList = NULL; /** @@ -338,13 +372,13 @@ static XMesaBuffer create_xmesa_buffer(Drawable d, BufferType type, XMesaVisual vis, Colormap cmap) { + XMesaDisplay xmdpy = xmesa_init_display(vis->display); XMesaBuffer b; uint width, height; ASSERT(type == WINDOW || type == PIXMAP || type == PBUFFER); - xmesa_init(vis->display); - if (!screen) + if (!xmdpy) return NULL; b = (XMesaBuffer) CALLOC_STRUCT(xmesa_buffer); @@ -364,7 +398,7 @@ create_xmesa_buffer(Drawable d, BufferType type, /* * Create framebuffer, but we'll plug in our own renderbuffers below. */ - b->stfb = xmesa_create_st_framebuffer(screen, b); + b->stfb = xmesa_create_st_framebuffer(xmdpy->screen, b); /* GLX_EXT_texture_from_pixmap */ b->TextureTarget = 0; @@ -579,10 +613,12 @@ XMesaVisual XMesaCreateVisual( Display *display, GLint level, GLint visualCaveat ) { + XMesaDisplay xmdpy = xmesa_init_display(display); XMesaVisual v; GLint red_bits, green_bits, blue_bits, alpha_bits; - xmesa_init( display ); + if (!xmdpy) + return NULL; /* For debugging only */ if (_mesa_getenv("MESA_XSYNC")) { @@ -675,7 +711,7 @@ XMesaVisual XMesaCreateVisual( Display *display, v->stvis.color_format = choose_pixel_format(v); v->stvis.depth_stencil_format = - choose_depth_stencil_format(depth_size, stencil_size); + choose_depth_stencil_format(xmdpy, depth_size, stencil_size); v->stvis.accum_format = (accum_red_size + accum_green_size + accum_blue_size + accum_alpha_size) ? @@ -699,37 +735,12 @@ void XMesaDestroyVisual( XMesaVisual v ) /** - * Do one-time initializations. + * Do per-display initializations. */ void xmesa_init( Display *display ) { - static GLboolean firstTime = GL_TRUE; - if (firstTime) { - pipe_mutex_init(_xmesa_lock); - screen = driver.create_pipe_screen( display ); - stapi = driver.create_st_api(); - smapi = CALLOC_STRUCT(st_manager); - if (smapi) - smapi->screen = screen; - - if (!screen || !stapi || !smapi) { - if (screen) { - screen->destroy(screen); - screen = NULL; - } - if (stapi) { - stapi->destroy(stapi); - stapi = NULL; - } - if (smapi) { - FREE(smapi); - smapi = NULL; - } - } - - firstTime = GL_FALSE; - } + xmesa_init_display(display); } @@ -743,9 +754,11 @@ xmesa_init( Display *display ) PUBLIC XMesaContext XMesaCreateContext( XMesaVisual v, XMesaContext share_list ) { + XMesaDisplay xmdpy = xmesa_init_display(v->display); XMesaContext c; - xmesa_init( v->display ); + if (!xmdpy) + return NULL; /* Note: the XMesaContext contains a Mesa GLcontext struct (inheritance) */ c = (XMesaContext) CALLOC_STRUCT(xmesa_context); @@ -756,10 +769,7 @@ XMesaContext XMesaCreateContext( XMesaVisual v, XMesaContext share_list ) c->xm_buffer = NULL; /* set later by XMesaMakeCurrent */ c->xm_read_buffer = NULL; - if (screen == NULL) - goto fail; - - c->st = stapi->create_context(stapi, smapi, + c->st = stapi->create_context(stapi, xmdpy->smapi, &v->stvis, (share_list) ? share_list->st : NULL); if (c->st == NULL) goto fail; @@ -1094,12 +1104,13 @@ void XMesaCopySubBuffer( XMesaBuffer b, int x, int y, int width, int height ) void XMesaFlush( XMesaContext c ) { if (c && c->xm_visual->display) { + XMesaDisplay xmdpy = xmesa_init_display(c->xm_visual->display); struct pipe_fence_handle *fence = NULL; c->st->flush(c->st, PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_FRAME, &fence); if (fence) { - screen->fence_finish(screen, fence, 0); - screen->fence_reference(screen, &fence, NULL); + xmdpy->screen->fence_finish(xmdpy->screen, fence, 0); + xmdpy->screen->fence_reference(xmdpy->screen, &fence, NULL); } XSync( c->xm_visual->display, False ); } diff --git a/src/gallium/state_trackers/glx/xlib/xm_api.h b/src/gallium/state_trackers/glx/xlib/xm_api.h index 258abf92554..11a08962b74 100644 --- a/src/gallium/state_trackers/glx/xlib/xm_api.h +++ b/src/gallium/state_trackers/glx/xlib/xm_api.h @@ -67,11 +67,20 @@ and create a window, you must do the following to use the X/Mesa interface: # include # include +typedef struct xmesa_display *XMesaDisplay; typedef struct xmesa_buffer *XMesaBuffer; typedef struct xmesa_context *XMesaContext; typedef struct xmesa_visual *XMesaVisual; +struct xmesa_display { + pipe_mutex mutex; + + Display *display; + struct pipe_screen *screen; + struct st_manager *smapi; +}; + /* * Create a new X/Mesa visual. @@ -264,11 +273,6 @@ XMesaCopyContext(XMesaContext src, XMesaContext dst, unsigned long mask); /*********************************************************************** */ -extern pipe_mutex _xmesa_lock; - -extern struct xmesa_buffer *XMesaBufferList; - - /** * Visual inforation, derived from GLvisual. * Basically corresponds to an XVisualInfo. -- cgit v1.2.3 From 48bc3cca89f7aecc40d1661e695796113df6e583 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Sun, 14 Mar 2010 11:34:16 +0800 Subject: st/glx: Add support for GLX_MESA_copy_sub_buffer. Create a per-display pipe_context as needed to copy the contents between framebuffer attachments. This allows us to support GLX_MESA_copy_sub_buffer. --- src/gallium/state_trackers/glx/xlib/xm_api.c | 2 +- src/gallium/state_trackers/glx/xlib/xm_api.h | 2 ++ src/gallium/state_trackers/glx/xlib/xm_st.c | 53 +++++++++++++++++++++++++--- src/gallium/state_trackers/glx/xlib/xm_st.h | 2 +- 4 files changed, 53 insertions(+), 6 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/glx/xlib/xm_api.c b/src/gallium/state_trackers/glx/xlib/xm_api.c index e7c1979b424..62a2bfcfa07 100644 --- a/src/gallium/state_trackers/glx/xlib/xm_api.c +++ b/src/gallium/state_trackers/glx/xlib/xm_api.c @@ -398,7 +398,7 @@ create_xmesa_buffer(Drawable d, BufferType type, /* * Create framebuffer, but we'll plug in our own renderbuffers below. */ - b->stfb = xmesa_create_st_framebuffer(xmdpy->screen, b); + b->stfb = xmesa_create_st_framebuffer(xmdpy, b); /* GLX_EXT_texture_from_pixmap */ b->TextureTarget = 0; diff --git a/src/gallium/state_trackers/glx/xlib/xm_api.h b/src/gallium/state_trackers/glx/xlib/xm_api.h index 11a08962b74..4f2c8a6e6a9 100644 --- a/src/gallium/state_trackers/glx/xlib/xm_api.h +++ b/src/gallium/state_trackers/glx/xlib/xm_api.h @@ -79,6 +79,8 @@ struct xmesa_display { Display *display; struct pipe_screen *screen; struct st_manager *smapi; + + struct pipe_context *pipe; }; diff --git a/src/gallium/state_trackers/glx/xlib/xm_st.c b/src/gallium/state_trackers/glx/xlib/xm_st.c index 8714da8b346..de5a35edca4 100644 --- a/src/gallium/state_trackers/glx/xlib/xm_st.c +++ b/src/gallium/state_trackers/glx/xlib/xm_st.c @@ -32,8 +32,9 @@ #include "xm_st.h" struct xmesa_st_framebuffer { - struct pipe_screen *screen; + XMesaDisplay display; XMesaBuffer buffer; + struct pipe_screen *screen; struct st_visual stvis; @@ -81,6 +82,45 @@ xmesa_st_framebuffer_display(struct st_framebuffer_iface *stfbi, return TRUE; } +/** + * Copy the contents between the attachments. + */ +static void +xmesa_st_framebuffer_copy_textures(struct st_framebuffer_iface *stfbi, + enum st_attachment_type src_statt, + enum st_attachment_type dst_statt, + unsigned x, unsigned y, + unsigned width, unsigned height) +{ + struct xmesa_st_framebuffer *xstfb = xmesa_st_framebuffer(stfbi); + struct pipe_texture *src_ptex = xstfb->textures[src_statt]; + struct pipe_texture *dst_ptex = xstfb->textures[dst_statt]; + struct pipe_surface *src, *dst; + struct pipe_context *pipe; + + if (!src_ptex || !dst_ptex) + return; + + pipe = xstfb->display->pipe; + if (!pipe) { + pipe = xstfb->screen->context_create(xstfb->screen, NULL); + if (!pipe) + return; + xstfb->display->pipe = pipe; + } + + src = xstfb->screen->get_tex_surface(xstfb->screen, + src_ptex, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_READ); + dst = xstfb->screen->get_tex_surface(xstfb->screen, + dst_ptex, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE); + + if (src && dst) + pipe->surface_copy(pipe, dst, 0, 0, src, 0, 0, src->width, src->height); + + pipe_surface_reference(&src, NULL); + pipe_surface_reference(&dst, NULL); +} + /** * Remove outdated textures and create the requested ones. */ @@ -194,11 +234,13 @@ xmesa_st_framebuffer_flush_front(struct st_framebuffer_iface *stfbi, } struct st_framebuffer_iface * -xmesa_create_st_framebuffer(struct pipe_screen *screen, XMesaBuffer b) +xmesa_create_st_framebuffer(XMesaDisplay xmdpy, XMesaBuffer b) { struct st_framebuffer_iface *stfbi; struct xmesa_st_framebuffer *xstfb; + assert(xmdpy->display == b->xm_visual->display); + stfbi = CALLOC_STRUCT(st_framebuffer_iface); xstfb = CALLOC_STRUCT(xmesa_st_framebuffer); if (!stfbi || !xstfb) { @@ -209,8 +251,9 @@ xmesa_create_st_framebuffer(struct pipe_screen *screen, XMesaBuffer b) return NULL; } - xstfb->screen = screen; + xstfb->display = xmdpy; xstfb->buffer = b; + xstfb->screen = xmdpy->screen; xstfb->stvis = b->xm_visual->stvis; stfbi->visual = &xstfb->stvis; @@ -265,5 +308,7 @@ xmesa_copy_st_framebuffer(struct st_framebuffer_iface *stfbi, enum st_attachment_type dst, int x, int y, int w, int h) { - /* TODO */ + xmesa_st_framebuffer_copy_textures(stfbi, src, dst, x, y, w, h); + if (dst == ST_ATTACHMENT_FRONT_LEFT) + xmesa_st_framebuffer_display(stfbi, dst); } diff --git a/src/gallium/state_trackers/glx/xlib/xm_st.h b/src/gallium/state_trackers/glx/xlib/xm_st.h index b22a8373801..396495c1893 100644 --- a/src/gallium/state_trackers/glx/xlib/xm_st.h +++ b/src/gallium/state_trackers/glx/xlib/xm_st.h @@ -34,7 +34,7 @@ #include "xm_api.h" struct st_framebuffer_iface * -xmesa_create_st_framebuffer(struct pipe_screen *screen, XMesaBuffer b); +xmesa_create_st_framebuffer(XMesaDisplay xmdpy, XMesaBuffer b); void xmesa_destroy_st_framebuffer(struct st_framebuffer_iface *stfbi); -- cgit v1.2.3 From d6262bdcfb64e1f88f6a890829f5c30c26bc372b Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Sun, 14 Mar 2010 12:01:27 +0800 Subject: st/glx: Sync the back buffer to the front buffer. Consider this rendering sequence * render to the back buffer * swap buffers * read from the front buffer The front buffer is expected to have the contents of the back buffer. --- src/gallium/state_trackers/glx/xlib/xm_st.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/glx/xlib/xm_st.c b/src/gallium/state_trackers/glx/xlib/xm_st.c index de5a35edca4..bcb8285d9f5 100644 --- a/src/gallium/state_trackers/glx/xlib/xm_st.c +++ b/src/gallium/state_trackers/glx/xlib/xm_st.c @@ -197,18 +197,36 @@ xmesa_st_framebuffer_validate(struct st_framebuffer_iface *stfbi, struct pipe_texture **out) { struct xmesa_st_framebuffer *xstfb = xmesa_st_framebuffer(stfbi); - unsigned statt_mask, i; + unsigned statt_mask, new_mask, i; + boolean resized; statt_mask = 0x0; for (i = 0; i < count; i++) statt_mask |= 1 << statts[i]; + /* record newly allocated textures */ + new_mask = statt_mask & ~xstfb->texture_mask; + + resized = (xstfb->buffer->width != xstfb->texture_width || + xstfb->buffer->height != xstfb->texture_height); /* revalidate textures */ - if (xstfb->buffer->width != xstfb->texture_width || - xstfb->buffer->height != xstfb->texture_height || - (xstfb->texture_mask & statt_mask) != statt_mask) { + if (resized || new_mask) { xmesa_st_framebuffer_validate_textures(stfbi, xstfb->buffer->width, xstfb->buffer->height, statt_mask); + + if (!resized) { + enum st_attachment_type back, front; + + back = ST_ATTACHMENT_BACK_LEFT; + front = ST_ATTACHMENT_FRONT_LEFT; + /* copy the contents if front is newly allocated and back is not */ + if ((statt_mask & (1 << back)) && + (new_mask & (1 << front)) && + !(new_mask & (1 << back))) { + xmesa_st_framebuffer_copy_textures(stfbi, back, front, + 0, 0, xstfb->texture_width, xstfb->texture_height); + } + } } for (i = 0; i < count; i++) { -- cgit v1.2.3 From 23e9a25e1ff01d9f3ef5cc99f59e0fda0ac2d421 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Sun, 14 Mar 2010 14:58:27 +0800 Subject: st/glx: Fix glXCopySubBufferMESA. Honor the (x, y) and (width, height) pairs. --- src/gallium/state_trackers/glx/xlib/xm_st.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/glx/xlib/xm_st.c b/src/gallium/state_trackers/glx/xlib/xm_st.c index bcb8285d9f5..b6ed7e8e1e8 100644 --- a/src/gallium/state_trackers/glx/xlib/xm_st.c +++ b/src/gallium/state_trackers/glx/xlib/xm_st.c @@ -115,7 +115,7 @@ xmesa_st_framebuffer_copy_textures(struct st_framebuffer_iface *stfbi, dst_ptex, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE); if (src && dst) - pipe->surface_copy(pipe, dst, 0, 0, src, 0, 0, src->width, src->height); + pipe->surface_copy(pipe, dst, x, y, src, x, y, width, height); pipe_surface_reference(&src, NULL); pipe_surface_reference(&dst, NULL); -- cgit v1.2.3 From 506130fff5685742d280bde8800be036c8e8ebfa Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Mon, 15 Mar 2010 10:24:55 +0000 Subject: r300g: fix up after merge --- src/gallium/drivers/r300/r300_blit.c | 4 ++-- src/gallium/drivers/r300/r300_context.h | 7 +++---- src/gallium/drivers/r300/r300_emit.c | 13 +++++++------ src/gallium/drivers/r300/r300_state.c | 21 +++++++++++---------- src/gallium/drivers/r300/r300_state_derived.c | 4 ++-- 5 files changed, 25 insertions(+), 24 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/r300/r300_blit.c b/src/gallium/drivers/r300/r300_blit.c index a60b12844d6..f99f9dffaa5 100644 --- a/src/gallium/drivers/r300/r300_blit.c +++ b/src/gallium/drivers/r300/r300_blit.c @@ -114,8 +114,8 @@ static void r300_hw_copy(struct pipe_context* pipe, r300->blitter, state->sampler_count, (void**)state->sampler_states); util_blitter_save_fragment_sampler_views( - r300->blitter, r300->fragment_sampler_view_count, - r300->fragment_sampler_views); + r300->blitter, state->texture_count, + state->fragment_sampler_views); /* Do a copy */ util_blitter_copy(r300->blitter, diff --git a/src/gallium/drivers/r300/r300_context.h b/src/gallium/drivers/r300/r300_context.h index 2763103fda1..0c8fb6860eb 100644 --- a/src/gallium/drivers/r300/r300_context.h +++ b/src/gallium/drivers/r300/r300_context.h @@ -139,7 +139,7 @@ struct r300_texture_fb_state { struct r300_textures_state { /* Textures. */ - struct r300_texture *textures[8]; + struct pipe_sampler_view *fragment_sampler_views[8]; int texture_count; /* Sampler states. */ struct r300_sampler_state *sampler_states[8]; @@ -343,9 +343,8 @@ struct r300_context { struct r300_atom rs_block_state; /* Scissor state. */ struct r300_atom scissor_state; - /* Sampler view states. */ - struct pipe_sampler_view* fragment_sampler_views[8]; - int fragment_sampler_view_count; + /* Textures state. */ + struct r300_atom textures_state; /* Vertex stream formatting state. */ struct r300_atom vertex_stream_state; /* VAP (vertex shader) output mapping state. */ diff --git a/src/gallium/drivers/r300/r300_emit.c b/src/gallium/drivers/r300/r300_emit.c index 0a3f0f45c03..3ad0e561bc1 100644 --- a/src/gallium/drivers/r300/r300_emit.c +++ b/src/gallium/drivers/r300/r300_emit.c @@ -165,7 +165,7 @@ static const float * get_shader_constant( /* Factor for converting rectangle coords to * normalized coords. Should only show up on non-r500. */ case RC_STATE_R300_TEXRECT_FACTOR: - tex = r300->fragment_sampler_views[constant->u.State[1]]->texture; + tex = texstate->fragment_sampler_views[constant->u.State[1]]->texture; vec[0] = 1.0 / tex->width0; vec[1] = 1.0 / tex->height0; break; @@ -749,8 +749,9 @@ void r300_emit_textures_state(struct r300_context *r300, OUT_CS_REG(R300_TX_FORMAT2_0 + (i * 4), texstate->format[2]); OUT_CS_REG_SEQ(R300_TX_OFFSET_0 + (i * 4), 1); - OUT_CS_TEX_RELOC(allstate->textures[i], texstate->tile_config, - RADEON_GEM_DOMAIN_GTT | RADEON_GEM_DOMAIN_VRAM, 0, 0); + OUT_CS_TEX_RELOC((struct r300_texture *)allstate->fragment_sampler_views[i]->texture, + texstate->tile_config, + RADEON_GEM_DOMAIN_GTT | RADEON_GEM_DOMAIN_VRAM, 0, 0); } } END_CS; @@ -1042,10 +1043,10 @@ validate: } } /* ...textures... */ - for (i = 0; i < r300->fragment_sampler_view_count; i++) { - if (!r300->fragment_sampler_views[i]) + for (i = 0; i < texstate->count; i++) { + tex = (struct r300_texture*)texstate->fragment_sampler_views[i]->texture; + if (!tex || !texstate->sampler_states[i]) continue; - tex = (struct r300_texture *)r300->fragment_sampler_views[i]->texture; if (!r300_add_texture(r300->rws, tex, RADEON_GEM_DOMAIN_GTT | RADEON_GEM_DOMAIN_VRAM, 0)) { r300->context.flush(&r300->context, 0, NULL); diff --git a/src/gallium/drivers/r300/r300_state.c b/src/gallium/drivers/r300/r300_state.c index 71ac89715cc..d7d654dc315 100644 --- a/src/gallium/drivers/r300/r300_state.c +++ b/src/gallium/drivers/r300/r300_state.c @@ -938,6 +938,8 @@ static void r300_set_fragment_sampler_views(struct pipe_context* pipe, struct pipe_sampler_view** views) { struct r300_context* r300 = r300_context(pipe); + struct r300_textures_state* state = + (struct r300_textures_state*)r300->textures_state.state; unsigned i; boolean is_r500 = r300_screen(r300->context.screen)->caps->is_r500; boolean dirty_tex = FALSE; @@ -948,16 +950,16 @@ static void r300_set_fragment_sampler_views(struct pipe_context* pipe, } for (i = 0; i < count; i++) { - if (r300->fragment_sampler_views[i] != views[i]) { + if (state->fragment_sampler_views[i] != views[i]) { struct r300_texture *texture; - - pipe_sampler_view_reference(&r300->fragment_sampler_views[i], - views[i]); + + pipe_sampler_view_reference(&state->fragment_sampler_views[i], + views[i]); dirty_tex = TRUE; texture = (struct r300_texture *)views[i]->texture; - /* R300-specific - set the texrect factor in a fragment shader */ + /* R300-specific - set the texrect factor in the fragment shader */ if (!is_r500 && texture->is_npot) { /* XXX It would be nice to re-emit just 1 constant, * XXX not all of them */ @@ -967,13 +969,13 @@ static void r300_set_fragment_sampler_views(struct pipe_context* pipe, } for (i = count; i < 8; i++) { - if (r300->fragment_sampler_views[i]) { - pipe_sampler_view_reference(&r300->fragment_sampler_views[i], - NULL); + if (state->fragment_sampler_views[i]) { + pipe_sampler_view_reference(&state->fragment_sampler_views[i], + NULL); } } - r300->fragment_sampler_view_count = count; + state->texture_count = count; r300->textures_state.dirty = TRUE; @@ -987,7 +989,6 @@ r300_create_sampler_view(struct pipe_context *pipe, struct pipe_texture *texture, const struct pipe_sampler_view *templ) { - struct r300_context *r300 = r300_context(pipe); struct pipe_sampler_view *view = CALLOC_STRUCT(pipe_sampler_view); if (view) { diff --git a/src/gallium/drivers/r300/r300_state_derived.c b/src/gallium/drivers/r300/r300_state_derived.c index 6b9f61acd7b..7947ec6641d 100644 --- a/src/gallium/drivers/r300/r300_state_derived.c +++ b/src/gallium/drivers/r300/r300_state_derived.c @@ -340,10 +340,10 @@ static void r300_merge_textures_and_samplers(struct r300_context* r300) size = 2; for (i = 0; i < count; i++) { - if (state->textures[i] && state->sampler_states[i]) { + if (state->fragment_sampler_views[i] && state->sampler_states[i]) { state->tx_enable |= 1 << i; - tex = state->textures[i]; + tex = (struct r300_texture *)state->fragment_sampler_views[i]->texture; sampler = state->sampler_states[i]; texstate = &state->regs[i]; -- cgit v1.2.3 From 08189e639195ecb619ed37250b6dbb63017584b8 Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Mon, 15 Mar 2010 10:27:25 +0000 Subject: nvfx: fix up after merge --- src/gallium/drivers/nvfx/nvfx_state.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/nvfx/nvfx_state.c b/src/gallium/drivers/nvfx/nvfx_state.c index 32a81997528..ecaa0dcb16a 100644 --- a/src/gallium/drivers/nvfx/nvfx_state.c +++ b/src/gallium/drivers/nvfx/nvfx_state.c @@ -145,18 +145,14 @@ nvfx_set_fragment_sampler_views(struct pipe_context *pipe, unsigned unit; for (unit = 0; unit < nr; unit++) { - pipe_sampler_view_reference(&nv30->fragment_sampler_views[unit], + pipe_sampler_view_reference(&nvfx->fragment_sampler_views[unit], views[unit]); - pipe_texture_reference((struct pipe_texture **) - &nvfx->tex_miptree[unit], miptree[unit]); nvfx->dirty_samplers |= (1 << unit); } for (unit = nr; unit < nvfx->nr_textures; unit++) { - pipe_sampler_view_reference(&nv30->fragment_sampler_views[unit], + pipe_sampler_view_reference(&nvfx->fragment_sampler_views[unit], NULL); - pipe_texture_reference((struct pipe_texture **) - &nvfx->tex_miptree[unit], NULL); nvfx->dirty_samplers |= (1 << unit); } @@ -166,7 +162,7 @@ nvfx_set_fragment_sampler_views(struct pipe_context *pipe, static struct pipe_sampler_view * -nv30_create_sampler_view(struct pipe_context *pipe, +nvfx_create_sampler_view(struct pipe_context *pipe, struct pipe_texture *texture, const struct pipe_sampler_view *templ) { @@ -185,7 +181,7 @@ nv30_create_sampler_view(struct pipe_context *pipe, static void -nv30_sampler_view_destroy(struct pipe_context *pipe, +nvfx_sampler_view_destroy(struct pipe_context *pipe, struct pipe_sampler_view *view) { pipe_texture_reference(&view->texture, NULL); @@ -614,7 +610,9 @@ nvfx_init_state_functions(struct nvfx_context *nvfx) nvfx->pipe.create_sampler_state = nvfx_sampler_state_create; nvfx->pipe.bind_fragment_sampler_states = nvfx_sampler_state_bind; nvfx->pipe.delete_sampler_state = nvfx_sampler_state_delete; - nvfx->pipe.set_fragment_sampler_textures = nvfx_set_sampler_texture; + nvfx->pipe.set_fragment_sampler_views = nvfx_set_fragment_sampler_views; + nvfx->pipe.create_sampler_view = nvfx_create_sampler_view; + nvfx->pipe.sampler_view_destroy = nvfx_sampler_view_destroy; nvfx->pipe.create_rasterizer_state = nvfx_rasterizer_state_create; nvfx->pipe.bind_rasterizer_state = nvfx_rasterizer_state_bind; -- cgit v1.2.3 From f2bc089d148253d7a411e94257633ce40ec1c6a9 Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Mon, 15 Mar 2010 13:20:37 +0100 Subject: gallium: util_blit_pixels() takes source sampler view as argument. --- src/gallium/auxiliary/util/u_blit.c | 28 ++++++++++++++++++++++------ src/gallium/auxiliary/util/u_blit.h | 2 ++ src/mesa/state_tracker/st_cb_blit.c | 15 ++++++++++----- src/mesa/state_tracker/st_cb_texture.c | 2 ++ 4 files changed, 36 insertions(+), 11 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/auxiliary/util/u_blit.c b/src/gallium/auxiliary/util/u_blit.c index 4d0737ccd3d..803086b93e6 100644 --- a/src/gallium/auxiliary/util/u_blit.c +++ b/src/gallium/auxiliary/util/u_blit.c @@ -45,6 +45,7 @@ #include "util/u_format.h" #include "util/u_math.h" #include "util/u_memory.h" +#include "util/u_sampler.h" #include "util/u_simple_shaders.h" #include "util/u_surface.h" #include "util/u_rect.h" @@ -280,6 +281,7 @@ regions_overlap(int srcX0, int srcY0, void util_blit_pixels_writemask(struct blit_state *ctx, struct pipe_surface *src, + struct pipe_sampler_view *src_sampler_view, int srcX0, int srcY0, int srcX1, int srcY1, struct pipe_surface *dst, @@ -291,6 +293,7 @@ util_blit_pixels_writemask(struct blit_state *ctx, struct pipe_context *pipe = ctx->pipe; struct pipe_screen *screen = pipe->screen; struct pipe_texture *tex = NULL; + struct pipe_sampler_view *sampler_view = NULL; struct pipe_framebuffer_state fb; const int srcW = abs(srcX1 - srcX0); const int srcH = abs(srcY1 - srcY0); @@ -345,6 +348,7 @@ util_blit_pixels_writemask(struct blit_state *ctx, src->texture->last_level != 0) { struct pipe_texture texTemp; + struct pipe_sampler_view sv_templ; struct pipe_surface *texSurf; const int srcLeft = MIN2(srcX0, srcX1); const int srcTop = MIN2(srcY0, srcY1); @@ -376,6 +380,14 @@ util_blit_pixels_writemask(struct blit_state *ctx, if (!tex) return; + u_sampler_view_default_template(&sv_templ, tex, tex->format); + + sampler_view = ctx->pipe->create_sampler_view(ctx->pipe, tex, &sv_templ); + if (!sampler_view) { + pipe_texture_reference(&tex, NULL); + return; + } + texSurf = screen->get_tex_surface(screen, tex, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE); @@ -399,22 +411,25 @@ util_blit_pixels_writemask(struct blit_state *ctx, s1 = 1.0f; t0 = 0.0f; t1 = 1.0f; + + pipe_texture_reference(&tex, NULL); } else { - pipe_texture_reference(&tex, src->texture); + pipe_sampler_view_reference(&sampler_view, src_sampler_view); s0 = srcX0 / (float)tex->width0; s1 = srcX1 / (float)tex->width0; t0 = srcY0 / (float)tex->height0; t1 = srcY1 / (float)tex->height0; } + /* save state (restored below) */ cso_save_blend(ctx->cso); cso_save_depth_stencil_alpha(ctx->cso); cso_save_rasterizer(ctx->cso); cso_save_samplers(ctx->cso); - cso_save_sampler_textures(ctx->cso); + cso_save_fragment_sampler_views(ctx->cso); cso_save_viewport(ctx->cso); cso_save_framebuffer(ctx->cso); cso_save_fragment_shader(ctx->cso); @@ -447,7 +462,7 @@ util_blit_pixels_writemask(struct blit_state *ctx, cso_set_viewport(ctx->cso, &ctx->viewport); /* texture */ - cso_set_sampler_textures(ctx->cso, 1, &tex); + cso_set_fragment_sampler_views(ctx->cso, 1, &sampler_view); if (ctx->fs[writemask] == NULL) ctx->fs[writemask] = @@ -486,7 +501,7 @@ util_blit_pixels_writemask(struct blit_state *ctx, cso_restore_depth_stencil_alpha(ctx->cso); cso_restore_rasterizer(ctx->cso); cso_restore_samplers(ctx->cso); - cso_restore_sampler_textures(ctx->cso); + cso_restore_fragment_sampler_views(ctx->cso); cso_restore_viewport(ctx->cso); cso_restore_framebuffer(ctx->cso); cso_restore_fragment_shader(ctx->cso); @@ -494,13 +509,14 @@ util_blit_pixels_writemask(struct blit_state *ctx, cso_restore_clip(ctx->cso); cso_restore_vertex_elements(ctx->cso); - pipe_texture_reference(&tex, NULL); + pipe_sampler_view_reference(&sampler_view, NULL); } void util_blit_pixels(struct blit_state *ctx, struct pipe_surface *src, + struct pipe_sampler_view *src_sampler_view, int srcX0, int srcY0, int srcX1, int srcY1, struct pipe_surface *dst, @@ -508,7 +524,7 @@ util_blit_pixels(struct blit_state *ctx, int dstX1, int dstY1, float z, uint filter ) { - util_blit_pixels_writemask( ctx, src, + util_blit_pixels_writemask( ctx, src, src_sampler_view, srcX0, srcY0, srcX1, srcY1, dst, diff --git a/src/gallium/auxiliary/util/u_blit.h b/src/gallium/auxiliary/util/u_blit.h index a102021529e..2d8cdd25fb9 100644 --- a/src/gallium/auxiliary/util/u_blit.h +++ b/src/gallium/auxiliary/util/u_blit.h @@ -53,6 +53,7 @@ util_destroy_blit(struct blit_state *ctx); extern void util_blit_pixels(struct blit_state *ctx, struct pipe_surface *src, + struct pipe_sampler_view *src_sampler_view, int srcX0, int srcY0, int srcX1, int srcY1, struct pipe_surface *dst, @@ -63,6 +64,7 @@ util_blit_pixels(struct blit_state *ctx, void util_blit_pixels_writemask(struct blit_state *ctx, struct pipe_surface *src, + struct pipe_sampler_view *src_sampler_view, int srcX0, int srcY0, int srcX1, int srcY1, struct pipe_surface *dst, diff --git a/src/mesa/state_tracker/st_cb_blit.c b/src/mesa/state_tracker/st_cb_blit.c index 36e03018d9f..abf0ac0fc82 100644 --- a/src/mesa/state_tracker/st_cb_blit.c +++ b/src/mesa/state_tracker/st_cb_blit.c @@ -69,6 +69,7 @@ st_BlitFramebuffer(GLcontext *ctx, const GLbitfield depthStencil = (GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); struct st_context *st = ctx->st; + struct pipe_context *pipe = st->pipe; const uint pFilter = ((filter == GL_NEAREST) ? PIPE_TEX_MIPFILTER_NEAREST : PIPE_TEX_MIPFILTER_LINEAR); @@ -111,8 +112,8 @@ st_BlitFramebuffer(GLcontext *ctx, &readFB->Attachment[readFB->_ColorReadBufferIndex]; if(srcAtt->Type == GL_TEXTURE) { - struct pipe_screen *screen = ctx->st->pipe->screen; - const struct st_texture_object *srcObj = + struct pipe_screen *screen = pipe->screen; + struct st_texture_object *srcObj = st_texture_object(srcAtt->Texture); struct st_renderbuffer *dstRb = st_renderbuffer(drawFB->_ColorDrawBuffers[0]); @@ -132,7 +133,8 @@ st_BlitFramebuffer(GLcontext *ctx, return; util_blit_pixels(st->blit, - srcSurf, srcX0, srcY0, srcX1, srcY1, + srcSurf, st_get_stobj_sampler_view(srcObj, pipe), + srcX0, srcY0, srcX1, srcY1, dstSurf, dstX0, dstY0, dstX1, dstY1, 0.0, pFilter); @@ -144,10 +146,11 @@ st_BlitFramebuffer(GLcontext *ctx, struct st_renderbuffer *dstRb = st_renderbuffer(drawFB->_ColorDrawBuffers[0]); struct pipe_surface *srcSurf = srcRb->surface; + struct pipe_sampler_view *srcView = st_renderbuffer_get_sampler_view(srcRb, pipe); struct pipe_surface *dstSurf = dstRb->surface; util_blit_pixels(st->blit, - srcSurf, srcX0, srcY0, srcX1, srcY1, + srcSurf, srcView, srcX0, srcY0, srcX1, srcY1, dstSurf, dstX0, dstY0, dstX1, dstY1, 0.0, pFilter); } @@ -179,11 +182,13 @@ st_BlitFramebuffer(GLcontext *ctx, if ((mask & depthStencil) == depthStencil && srcDepthSurf == srcStencilSurf && dstDepthSurf == dstStencilSurf) { + struct pipe_sampler_view *srcView = st_renderbuffer_get_sampler_view(srcDepthRb, pipe); + /* Blitting depth and stencil values between combined * depth/stencil buffers. This is the ideal case for such buffers. */ util_blit_pixels(st->blit, - srcDepthSurf, srcX0, srcY0, srcX1, srcY1, + srcDepthSurf, srcView, srcX0, srcY0, srcX1, srcY1, dstDepthSurf, dstX0, dstY0, dstX1, dstY1, 0.0, pFilter); } diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index 04c0ef8c84c..7fcd1e9ca74 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -1457,6 +1457,7 @@ st_copy_texsubimage(GLcontext *ctx, &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; struct gl_texture_object *texObj = _mesa_select_tex_object(ctx, texUnit, target); + struct st_texture_object *stObj = st_texture_object(texObj); struct gl_texture_image *texImage = _mesa_select_tex_image(ctx, texObj, target, level); struct st_texture_image *stImage = st_texture_image(texImage); @@ -1597,6 +1598,7 @@ st_copy_texsubimage(GLcontext *ctx, } util_blit_pixels_writemask(ctx->st->blit, strb->surface, + st_get_stobj_sampler_view(stObj), srcX, srcY0, srcX + width, srcY1, dest_surface, -- cgit v1.2.3 From df65fc8100f267b3167012d4f8502cf9eed526df Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Mon, 15 Mar 2010 14:42:44 +0100 Subject: util: Fix nil pointer reference. --- src/gallium/auxiliary/util/u_blit.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/auxiliary/util/u_blit.c b/src/gallium/auxiliary/util/u_blit.c index 803086b93e6..4d9168face3 100644 --- a/src/gallium/auxiliary/util/u_blit.c +++ b/src/gallium/auxiliary/util/u_blit.c @@ -292,7 +292,6 @@ util_blit_pixels_writemask(struct blit_state *ctx, { struct pipe_context *pipe = ctx->pipe; struct pipe_screen *screen = pipe->screen; - struct pipe_texture *tex = NULL; struct pipe_sampler_view *sampler_view = NULL; struct pipe_framebuffer_state fb; const int srcW = abs(srcX1 - srcX0); @@ -348,6 +347,7 @@ util_blit_pixels_writemask(struct blit_state *ctx, src->texture->last_level != 0) { struct pipe_texture texTemp; + struct pipe_texture *tex; struct pipe_sampler_view sv_templ; struct pipe_surface *texSurf; const int srcLeft = MIN2(srcX0, srcX1); @@ -416,10 +416,10 @@ util_blit_pixels_writemask(struct blit_state *ctx, } else { pipe_sampler_view_reference(&sampler_view, src_sampler_view); - s0 = srcX0 / (float)tex->width0; - s1 = srcX1 / (float)tex->width0; - t0 = srcY0 / (float)tex->height0; - t1 = srcY1 / (float)tex->height0; + s0 = srcX0 / (float)src->texture->width0; + s1 = srcX1 / (float)src->texture->width0; + t0 = srcY0 / (float)src->texture->height0; + t1 = srcY1 / (float)src->texture->height0; } -- cgit v1.2.3 From 6420aca08ba6910dce22ab9f813cc57d611b0aa8 Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Mon, 15 Mar 2010 17:56:19 +0100 Subject: cso: Do not hold references to bound textures. Sampler views already hold references to those. --- src/gallium/auxiliary/cso_cache/cso_context.c | 30 +++++++-------------------- 1 file changed, 8 insertions(+), 22 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/auxiliary/cso_cache/cso_context.c b/src/gallium/auxiliary/cso_cache/cso_context.c index 648ba10a995..4ed9e09c529 100644 --- a/src/gallium/auxiliary/cso_cache/cso_context.c +++ b/src/gallium/auxiliary/cso_cache/cso_context.c @@ -71,16 +71,12 @@ struct cso_context { unsigned nr_vertex_samplers_saved; void *vertex_samplers_saved[PIPE_MAX_VERTEX_SAMPLERS]; - struct pipe_texture *textures[PIPE_MAX_SAMPLERS]; uint nr_fragment_sampler_views; struct pipe_sampler_view *fragment_sampler_views[PIPE_MAX_SAMPLERS]; - uint nr_textures; uint nr_vertex_sampler_views; struct pipe_sampler_view *vertex_sampler_views[PIPE_MAX_VERTEX_SAMPLERS]; - uint nr_textures_saved; - struct pipe_texture *textures_saved[PIPE_MAX_SAMPLERS]; uint nr_fragment_sampler_views_saved; struct pipe_sampler_view *fragment_sampler_views_saved[PIPE_MAX_SAMPLERS]; @@ -299,8 +295,6 @@ void cso_release_all( struct cso_context *ctx ) } for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { - pipe_texture_reference(&ctx->textures[i], NULL); - pipe_texture_reference(&ctx->textures_saved[i], NULL); pipe_sampler_view_reference(&ctx->fragment_sampler_views[i], NULL); pipe_sampler_view_reference(&ctx->fragment_sampler_views_saved[i], NULL); } @@ -630,7 +624,7 @@ enum pipe_error cso_set_sampler_textures( struct cso_context *ctx, { uint i; - ctx->nr_textures = count; + ctx->nr_fragment_sampler_views = count; for (i = 0; i < count; i++) { struct pipe_sampler_view templ, *view; @@ -638,15 +632,14 @@ enum pipe_error cso_set_sampler_textures( struct cso_context *ctx, u_sampler_view_default_template(&templ, textures[i], textures[i]->format); + view = ctx->pipe->create_sampler_view(ctx->pipe, textures[i], &templ); - pipe_texture_reference(&ctx->textures[i], textures[i]); pipe_sampler_view_reference(&ctx->fragment_sampler_views[i], view); } for ( ; i < PIPE_MAX_SAMPLERS; i++) { - pipe_texture_reference(&ctx->textures[i], NULL); pipe_sampler_view_reference(&ctx->fragment_sampler_views[i], NULL); } @@ -661,12 +654,10 @@ void cso_save_sampler_textures( struct cso_context *ctx ) { uint i; - ctx->nr_textures_saved = ctx->nr_textures; - for (i = 0; i < ctx->nr_textures; i++) { - assert(!ctx->textures_saved[i]); + ctx->nr_fragment_sampler_views_saved = ctx->nr_fragment_sampler_views; + for (i = 0; i < ctx->nr_fragment_sampler_views; i++) { assert(!ctx->fragment_sampler_views_saved[i]); - pipe_texture_reference(&ctx->textures_saved[i], ctx->textures[i]); pipe_sampler_view_reference(&ctx->fragment_sampler_views_saved[i], ctx->fragment_sampler_views[i]); } @@ -676,27 +667,22 @@ void cso_restore_sampler_textures( struct cso_context *ctx ) { uint i; - ctx->nr_textures = ctx->nr_textures_saved; - - for (i = 0; i < ctx->nr_textures; i++) { - pipe_texture_reference(&ctx->textures[i], NULL); - ctx->textures[i] = ctx->textures_saved[i]; - ctx->textures_saved[i] = NULL; + ctx->nr_fragment_sampler_views = ctx->nr_fragment_sampler_views_saved; + for (i = 0; i < ctx->nr_fragment_sampler_views; i++) { pipe_sampler_view_reference(&ctx->fragment_sampler_views[i], NULL); ctx->fragment_sampler_views[i] = ctx->fragment_sampler_views_saved[i]; ctx->fragment_sampler_views_saved[i] = NULL; } for ( ; i < PIPE_MAX_SAMPLERS; i++) { - pipe_texture_reference(&ctx->textures[i], NULL); pipe_sampler_view_reference(&ctx->fragment_sampler_views[i], NULL); } ctx->pipe->set_fragment_sampler_views(ctx->pipe, - ctx->nr_textures, + ctx->nr_fragment_sampler_views, ctx->fragment_sampler_views); - ctx->nr_textures_saved = 0; + ctx->nr_fragment_sampler_views_saved = 0; } -- cgit v1.2.3 From 8e848d682e74f9ae3e105635fe55d19ed8c94547 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Tue, 16 Mar 2010 06:49:38 +1000 Subject: gallium: fix frontbuffer rendering with r300g No idea if this is the correct fix, but it makes it work again at least. Signed-off-by: Dave Airlie --- src/gallium/state_trackers/dri/dri_context.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/dri/dri_context.c b/src/gallium/state_trackers/dri/dri_context.c index 2f991c39e33..9811f8cf43c 100644 --- a/src/gallium/state_trackers/dri/dri_context.c +++ b/src/gallium/state_trackers/dri/dri_context.c @@ -167,7 +167,7 @@ dri_make_current(__DRIcontext * cPriv, * flush_frontbuffer directly (in front-buffer rendering), it * will have access to the drawable argument: */ - st_make_current(ctx->st, draw->stfb, read->stfb, NULL); + st_make_current(ctx->st, draw->stfb, read->stfb, ctx); if (__dri1_api_hooks) { dri1_update_drawables(ctx, draw, read); -- cgit v1.2.3 From 3eb4b7bbecc013f25a9d77b50c745514350f99f9 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Mon, 15 Mar 2010 21:03:59 +0000 Subject: libgl-xlib: Obey GALLIUM_SOFTPIPE define. --- src/gallium/targets/libgl-xlib/xlib.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/gallium') diff --git a/src/gallium/targets/libgl-xlib/xlib.c b/src/gallium/targets/libgl-xlib/xlib.c index 05dc8db57d9..5bb6c5c38ce 100644 --- a/src/gallium/targets/libgl-xlib/xlib.c +++ b/src/gallium/targets/libgl-xlib/xlib.c @@ -81,8 +81,10 @@ swrast_xlib_create_screen( Display *display ) screen = llvmpipe_create_screen( winsys ); #endif +#if defined(GALLIUM_SOFTPIPE) if (screen == NULL) screen = softpipe_create_screen( winsys ); +#endif if (screen == NULL) goto fail; -- cgit v1.2.3 From 0d71ba46e613230c84165106c1fcc9027dec4cd3 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 15 Mar 2010 13:50:40 -0600 Subject: gallivm/llvmpipe: rename os_llvm.h to lp_bld.h The llvm wrapper wasn't really an OS thing. Use lp_bld.h for now but we eventually should rename/re-prefix all the files/functions in the gallivm/ directory. --- src/gallium/auxiliary/gallivm/lp_bld.h | 47 ++++++++++++++++++++++++++ src/gallium/auxiliary/gallivm/lp_bld_alpha.h | 2 +- src/gallium/auxiliary/gallivm/lp_bld_arit.h | 2 +- src/gallium/auxiliary/gallivm/lp_bld_blend.h | 2 +- src/gallium/auxiliary/gallivm/lp_bld_const.h | 2 +- src/gallium/auxiliary/gallivm/lp_bld_conv.h | 2 +- src/gallium/auxiliary/gallivm/lp_bld_debug.h | 2 +- src/gallium/auxiliary/gallivm/lp_bld_depth.h | 2 +- src/gallium/auxiliary/gallivm/lp_bld_flow.h | 2 +- src/gallium/auxiliary/gallivm/lp_bld_format.h | 2 +- src/gallium/auxiliary/gallivm/lp_bld_interp.h | 2 +- src/gallium/auxiliary/gallivm/lp_bld_intr.h | 2 +- src/gallium/auxiliary/gallivm/lp_bld_logic.h | 2 +- src/gallium/auxiliary/gallivm/lp_bld_pack.h | 2 +- src/gallium/auxiliary/gallivm/lp_bld_sample.h | 2 +- src/gallium/auxiliary/gallivm/lp_bld_struct.h | 2 +- src/gallium/auxiliary/gallivm/lp_bld_swizzle.h | 2 +- src/gallium/auxiliary/gallivm/lp_bld_tgsi.h | 2 +- src/gallium/auxiliary/gallivm/lp_bld_type.h | 2 +- src/gallium/auxiliary/os/os_llvm.h | 47 -------------------------- src/gallium/drivers/llvmpipe/lp_screen.h | 2 +- src/gallium/drivers/llvmpipe/lp_state.h | 2 +- src/gallium/drivers/llvmpipe/lp_test.h | 2 +- src/gallium/drivers/llvmpipe/lp_test_format.c | 2 +- src/gallium/drivers/llvmpipe/lp_tex_sample.h | 2 +- 25 files changed, 70 insertions(+), 70 deletions(-) create mode 100644 src/gallium/auxiliary/gallivm/lp_bld.h delete mode 100644 src/gallium/auxiliary/os/os_llvm.h (limited to 'src/gallium') diff --git a/src/gallium/auxiliary/gallivm/lp_bld.h b/src/gallium/auxiliary/gallivm/lp_bld.h new file mode 100644 index 00000000000..70a4960f913 --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld.h @@ -0,0 +1,47 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @file + * Wrapper for LLVM header file #includes. + */ + + +#ifndef LP_BLD_H +#define LP_BLD_H + + +#include + + +/** Set version to 0 if missing to avoid #ifdef HAVE_LLVM everywhere */ +#ifndef HAVE_LLVM +#define HAVE_LLVM 0x0207 +#endif + + +#endif /* LP_BLD_H */ diff --git a/src/gallium/auxiliary/gallivm/lp_bld_alpha.h b/src/gallium/auxiliary/gallivm/lp_bld_alpha.h index fe3cedcc48c..0f99fec65ed 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_alpha.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_alpha.h @@ -35,7 +35,7 @@ #define LP_BLD_ALPHA_H -#include "os/os_llvm.h" +#include "gallivm/lp_bld.h" struct pipe_alpha_state; struct lp_type; diff --git a/src/gallium/auxiliary/gallivm/lp_bld_arit.h b/src/gallium/auxiliary/gallivm/lp_bld_arit.h index 7a10fe12209..31efa9921ce 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_arit.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_arit.h @@ -37,7 +37,7 @@ #define LP_BLD_ARIT_H -#include "os/os_llvm.h" +#include "gallivm/lp_bld.h" struct lp_type; diff --git a/src/gallium/auxiliary/gallivm/lp_bld_blend.h b/src/gallium/auxiliary/gallivm/lp_bld_blend.h index 5a9e1c1fb2f..ebbdb1a604c 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_blend.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_blend.h @@ -40,7 +40,7 @@ * for a standalone example. */ -#include "os/os_llvm.h" +#include "gallivm/lp_bld.h" #include "pipe/p_format.h" diff --git a/src/gallium/auxiliary/gallivm/lp_bld_const.h b/src/gallium/auxiliary/gallivm/lp_bld_const.h index 40786361031..5bd0db844d3 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_const.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_const.h @@ -37,7 +37,7 @@ #define LP_BLD_CONST_H -#include "os/os_llvm.h" +#include "gallivm/lp_bld.h" #include diff --git a/src/gallium/auxiliary/gallivm/lp_bld_conv.h b/src/gallium/auxiliary/gallivm/lp_bld_conv.h index 78e8155ff73..628831c3ada 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_conv.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_conv.h @@ -37,7 +37,7 @@ #define LP_BLD_CONV_H -#include "os/os_llvm.h" +#include "gallivm/lp_bld.h" struct lp_type; diff --git a/src/gallium/auxiliary/gallivm/lp_bld_debug.h b/src/gallium/auxiliary/gallivm/lp_bld_debug.h index 441ad94786f..7b010cbdb09 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_debug.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_debug.h @@ -30,7 +30,7 @@ #define LP_BLD_DEBUG_H -#include "os/os_llvm.h" +#include "gallivm/lp_bld.h" #include "pipe/p_compiler.h" #include "util/u_string.h" diff --git a/src/gallium/auxiliary/gallivm/lp_bld_depth.h b/src/gallium/auxiliary/gallivm/lp_bld_depth.h index 8be80024ae8..8375824cbf4 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_depth.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_depth.h @@ -36,7 +36,7 @@ #define LP_BLD_DEPTH_H -#include "os/os_llvm.h" +#include "gallivm/lp_bld.h" struct pipe_depth_state; diff --git a/src/gallium/auxiliary/gallivm/lp_bld_flow.h b/src/gallium/auxiliary/gallivm/lp_bld_flow.h index e1588365491..c2b50e1b602 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_flow.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_flow.h @@ -35,7 +35,7 @@ #define LP_BLD_FLOW_H -#include "os/os_llvm.h" +#include "gallivm/lp_bld.h" struct lp_type; diff --git a/src/gallium/auxiliary/gallivm/lp_bld_format.h b/src/gallium/auxiliary/gallivm/lp_bld_format.h index 8972c0dc178..73ab6de3f21 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_format.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_format.h @@ -34,7 +34,7 @@ * Pixel format helpers. */ -#include "os/os_llvm.h" +#include "gallivm/lp_bld.h" #include "pipe/p_format.h" diff --git a/src/gallium/auxiliary/gallivm/lp_bld_interp.h b/src/gallium/auxiliary/gallivm/lp_bld_interp.h index 177b5e943ee..a4937bbb048 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_interp.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_interp.h @@ -41,7 +41,7 @@ #define LP_BLD_INTERP_H -#include "os/os_llvm.h" +#include "gallivm/lp_bld.h" #include "tgsi/tgsi_exec.h" diff --git a/src/gallium/auxiliary/gallivm/lp_bld_intr.h b/src/gallium/auxiliary/gallivm/lp_bld_intr.h index 7d5506c7338..977f7673228 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_intr.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_intr.h @@ -37,7 +37,7 @@ #define LP_BLD_INTR_H -#include "os/os_llvm.h" +#include "gallivm/lp_bld.h" /** diff --git a/src/gallium/auxiliary/gallivm/lp_bld_logic.h b/src/gallium/auxiliary/gallivm/lp_bld_logic.h index b54ec13b701..d849d29e95d 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_logic.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_logic.h @@ -37,7 +37,7 @@ #define LP_BLD_LOGIC_H -#include "os/os_llvm.h" +#include "gallivm/lp_bld.h" #include "pipe/p_defines.h" /* For PIPE_FUNC_xxx */ diff --git a/src/gallium/auxiliary/gallivm/lp_bld_pack.h b/src/gallium/auxiliary/gallivm/lp_bld_pack.h index 346a17d5803..41adeed220c 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_pack.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_pack.h @@ -37,7 +37,7 @@ #define LP_BLD_PACK_H -#include "os/os_llvm.h" +#include "gallivm/lp_bld.h" struct lp_type; diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample.h b/src/gallium/auxiliary/gallivm/lp_bld_sample.h index 7f08bfaac1f..92f3c57435a 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_sample.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_sample.h @@ -36,7 +36,7 @@ #define LP_BLD_SAMPLE_H -#include "os/os_llvm.h" +#include "gallivm/lp_bld.h" struct pipe_texture; struct pipe_sampler_state; diff --git a/src/gallium/auxiliary/gallivm/lp_bld_struct.h b/src/gallium/auxiliary/gallivm/lp_bld_struct.h index 34478c10f51..147336edb4b 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_struct.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_struct.h @@ -37,7 +37,7 @@ #define LP_BLD_STRUCT_H -#include "os/os_llvm.h" +#include "gallivm/lp_bld.h" #include #include "util/u_debug.h" diff --git a/src/gallium/auxiliary/gallivm/lp_bld_swizzle.h b/src/gallium/auxiliary/gallivm/lp_bld_swizzle.h index 57b5cc079f2..138ca620e63 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_swizzle.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_swizzle.h @@ -37,7 +37,7 @@ #define LP_BLD_SWIZZLE_H -#include "os/os_llvm.h" +#include "gallivm/lp_bld.h" struct lp_type; diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h b/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h index 0f2f8a65b10..63b938bfa98 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h @@ -35,7 +35,7 @@ #ifndef LP_BLD_TGSI_H #define LP_BLD_TGSI_H -#include "os/os_llvm.h" +#include "gallivm/lp_bld.h" struct tgsi_token; diff --git a/src/gallium/auxiliary/gallivm/lp_bld_type.h b/src/gallium/auxiliary/gallivm/lp_bld_type.h index 5b351476ac2..8a80e4f09aa 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_type.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_type.h @@ -37,7 +37,7 @@ #define LP_BLD_TYPE_H -#include "os/os_llvm.h" +#include "gallivm/lp_bld.h" #include diff --git a/src/gallium/auxiliary/os/os_llvm.h b/src/gallium/auxiliary/os/os_llvm.h deleted file mode 100644 index d5edfbfe923..00000000000 --- a/src/gallium/auxiliary/os/os_llvm.h +++ /dev/null @@ -1,47 +0,0 @@ -/************************************************************************** - * - * Copyright 2010 VMware, Inc. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -/** - * @file - * Wrapper for LLVM header file #includes. - */ - - -#ifndef OS_LLVM_H -#define OS_LLVM_H - - -#include - - -/** Set version to 0 if missing to avoid #ifdef HAVE_LLVM everywhere */ -#ifndef HAVE_LLVM -#define HAVE_LLVM 0x0 -#endif - - -#endif /* OS_LLVM_H */ diff --git a/src/gallium/drivers/llvmpipe/lp_screen.h b/src/gallium/drivers/llvmpipe/lp_screen.h index d977f98cfaa..af25e043cc9 100644 --- a/src/gallium/drivers/llvmpipe/lp_screen.h +++ b/src/gallium/drivers/llvmpipe/lp_screen.h @@ -34,7 +34,7 @@ #ifndef LP_SCREEN_H #define LP_SCREEN_H -#include "os/os_llvm.h" +#include "gallivm/lp_bld.h" #include #include "pipe/p_screen.h" diff --git a/src/gallium/drivers/llvmpipe/lp_state.h b/src/gallium/drivers/llvmpipe/lp_state.h index a5a1a720742..34dd5234ce3 100644 --- a/src/gallium/drivers/llvmpipe/lp_state.h +++ b/src/gallium/drivers/llvmpipe/lp_state.h @@ -31,7 +31,7 @@ #ifndef LP_STATE_H #define LP_STATE_H -#include "os/os_llvm.h" +#include "gallivm/lp_bld.h" #include "pipe/p_state.h" #include "tgsi/tgsi_scan.h" diff --git a/src/gallium/drivers/llvmpipe/lp_test.h b/src/gallium/drivers/llvmpipe/lp_test.h index 1df98978988..338a04a4878 100644 --- a/src/gallium/drivers/llvmpipe/lp_test.h +++ b/src/gallium/drivers/llvmpipe/lp_test.h @@ -41,7 +41,7 @@ #include #include -#include "os/os_llvm.h" +#include "gallivm/lp_bld.h" #include #include #include diff --git a/src/gallium/drivers/llvmpipe/lp_test_format.c b/src/gallium/drivers/llvmpipe/lp_test_format.c index 2c4d7fb6e14..fb595893bd0 100644 --- a/src/gallium/drivers/llvmpipe/lp_test_format.c +++ b/src/gallium/drivers/llvmpipe/lp_test_format.c @@ -29,7 +29,7 @@ #include #include -#include "os/os_llvm.h" +#include "gallivm/lp_bld.h" #include #include #include diff --git a/src/gallium/drivers/llvmpipe/lp_tex_sample.h b/src/gallium/drivers/llvmpipe/lp_tex_sample.h index 799df182b6a..1228a831f3b 100644 --- a/src/gallium/drivers/llvmpipe/lp_tex_sample.h +++ b/src/gallium/drivers/llvmpipe/lp_tex_sample.h @@ -29,7 +29,7 @@ #define LP_TEX_SAMPLE_H -#include "os/os_llvm.h" +#include "gallivm/lp_bld.h" struct lp_sampler_static_state; -- cgit v1.2.3 From c86a499769d56fc59fa41b9c2d73ac181ab33e36 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 15 Mar 2010 13:54:43 -0600 Subject: gallivm: fix up some #includes --- src/gallium/auxiliary/gallivm/lp_bld_const.h | 2 +- src/gallium/auxiliary/gallivm/lp_bld_type.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/auxiliary/gallivm/lp_bld_const.h b/src/gallium/auxiliary/gallivm/lp_bld_const.h index 5bd0db844d3..0f426189003 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_const.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_const.h @@ -37,9 +37,9 @@ #define LP_BLD_CONST_H +#include "pipe/p_compiler.h" #include "gallivm/lp_bld.h" -#include struct lp_type; diff --git a/src/gallium/auxiliary/gallivm/lp_bld_type.h b/src/gallium/auxiliary/gallivm/lp_bld_type.h index 8a80e4f09aa..cd59d2faa66 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_type.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_type.h @@ -37,9 +37,9 @@ #define LP_BLD_TYPE_H +#include "pipe/p_compiler.h" #include "gallivm/lp_bld.h" -#include /** -- cgit v1.2.3 From 185be3a87a5b38e8821a560c073975c11dcbd3e9 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 15 Mar 2010 14:00:23 -0600 Subject: gallivm/llvmpipe: rename some constant building functions --- src/gallium/auxiliary/gallivm/lp_bld_arit.c | 60 +++++++++++------------ src/gallium/auxiliary/gallivm/lp_bld_const.c | 8 +-- src/gallium/auxiliary/gallivm/lp_bld_const.h | 6 +-- src/gallium/auxiliary/gallivm/lp_bld_conv.c | 34 ++++++------- src/gallium/auxiliary/gallivm/lp_bld_depth.c | 4 +- src/gallium/auxiliary/gallivm/lp_bld_format_soa.c | 4 +- src/gallium/auxiliary/gallivm/lp_bld_interp.c | 6 +-- src/gallium/auxiliary/gallivm/lp_bld_logic.c | 2 +- src/gallium/auxiliary/gallivm/lp_bld_pack.c | 4 +- src/gallium/auxiliary/gallivm/lp_bld_sample.c | 6 +-- src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c | 38 +++++++------- src/gallium/auxiliary/gallivm/lp_bld_swizzle.c | 4 +- src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c | 6 +-- src/gallium/drivers/llvmpipe/lp_state_fs.c | 4 +- 14 files changed, 92 insertions(+), 94 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/auxiliary/gallivm/lp_bld_arit.c b/src/gallium/auxiliary/gallivm/lp_bld_arit.c index 233a36669d4..8e8fcccf564 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_arit.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_arit.c @@ -361,12 +361,12 @@ lp_build_mul_u8n(LLVMBuilderRef builder, LLVMValueRef c8; LLVMValueRef ab; - c8 = lp_build_int_const_scalar(i16_type, 8); + c8 = lp_build_const_int_vec(i16_type, 8); #if 0 /* a*b/255 ~= (a*(b + 1)) >> 256 */ - b = LLVMBuildAdd(builder, b, lp_build_int_const_scalar(i16_type, 1), ""); + b = LLVMBuildAdd(builder, b, lp_build_const_int_vec(i16_type, 1), ""); ab = LLVMBuildMul(builder, a, b, ""); #else @@ -374,7 +374,7 @@ lp_build_mul_u8n(LLVMBuilderRef builder, /* ab/255 ~= (ab + (ab >> 8) + 0x80) >> 8 */ ab = LLVMBuildMul(builder, a, b, ""); ab = LLVMBuildAdd(builder, ab, LLVMBuildLShr(builder, ab, c8, ""), ""); - ab = LLVMBuildAdd(builder, ab, lp_build_int_const_scalar(i16_type, 0x80), ""); + ab = LLVMBuildAdd(builder, ab, lp_build_const_int_vec(i16_type, 0x80), ""); #endif @@ -429,7 +429,7 @@ lp_build_mul(struct lp_build_context *bld, } if(type.fixed) - shift = lp_build_int_const_scalar(type, type.width/2); + shift = lp_build_const_int_vec(type, type.width/2); else shift = NULL; @@ -491,7 +491,7 @@ lp_build_mul_imm(struct lp_build_context *bld, * for Inf and NaN. */ unsigned mantissa = lp_mantissa(bld->type); - factor = lp_build_int_const_scalar(bld->type, (unsigned long long)shift << mantissa); + factor = lp_build_const_int_vec(bld->type, (unsigned long long)shift << mantissa); a = LLVMBuildBitCast(bld->builder, a, lp_build_int_vec_type(bld->type), ""); a = LLVMBuildAdd(bld->builder, a, factor, ""); a = LLVMBuildBitCast(bld->builder, a, lp_build_vec_type(bld->type), ""); @@ -499,12 +499,12 @@ lp_build_mul_imm(struct lp_build_context *bld, #endif } else { - factor = lp_build_const_scalar(bld->type, shift); + factor = lp_build_const_vec(bld->type, shift); return LLVMBuildShl(bld->builder, a, factor, ""); } } - factor = lp_build_const_scalar(bld->type, (double)b); + factor = lp_build_const_vec(bld->type, (double)b); return lp_build_mul(bld, a, factor); } @@ -567,7 +567,7 @@ lp_build_lerp(struct lp_build_context *bld, * but it will be wrong for other uses. Basically we need a more * powerful lp_type, capable of further distinguishing the values * interpretation from the value storage. */ - res = LLVMBuildAnd(bld->builder, res, lp_build_int_const_scalar(bld->type, (1 << bld->type.width/2) - 1), ""); + res = LLVMBuildAnd(bld->builder, res, lp_build_const_int_vec(bld->type, (1 << bld->type.width/2) - 1), ""); return res; } @@ -689,7 +689,7 @@ lp_build_abs(struct lp_build_context *bld, /* vector of floats */ LLVMTypeRef int_vec_type = lp_build_int_vec_type(type); unsigned long long absMask = ~(1ULL << (type.width - 1)); - LLVMValueRef mask = lp_build_int_const_scalar(type, ((unsigned long long) absMask)); + LLVMValueRef mask = lp_build_const_int_vec(type, ((unsigned long long) absMask)); a = LLVMBuildBitCast(bld->builder, a, int_vec_type, ""); a = LLVMBuildAnd(bld->builder, a, mask, ""); a = LLVMBuildBitCast(bld->builder, a, vec_type, ""); @@ -751,7 +751,7 @@ lp_build_sgn(struct lp_build_context *bld, /* vector */ int_type = lp_build_int_vec_type(type); vec_type = lp_build_vec_type(type); - mask = lp_build_int_const_scalar(type, maskBit); + mask = lp_build_const_int_vec(type, maskBit); } /* Take the sign bit and add it to 1 constant */ @@ -763,7 +763,7 @@ lp_build_sgn(struct lp_build_context *bld, } else { - LLVMValueRef minus_one = lp_build_const_scalar(type, -1.0); + LLVMValueRef minus_one = lp_build_const_vec(type, -1.0); cond = lp_build_cmp(bld, PIPE_FUNC_GREATER, a, bld->zero); res = lp_build_select(bld, cond, bld->one, minus_one); } @@ -789,8 +789,8 @@ lp_build_set_sign(struct lp_build_context *bld, const struct lp_type type = bld->type; LLVMTypeRef int_vec_type = lp_build_int_vec_type(type); LLVMTypeRef vec_type = lp_build_vec_type(type); - LLVMValueRef shift = lp_build_int_const_scalar(type, type.width - 1); - LLVMValueRef mask = lp_build_int_const_scalar(type, + LLVMValueRef shift = lp_build_const_int_vec(type, type.width - 1); + LLVMValueRef mask = lp_build_const_int_vec(type, ~((unsigned long long) 1 << (type.width - 1))); LLVMValueRef val, res; @@ -1034,7 +1034,7 @@ lp_build_iround(struct lp_build_context *bld, } else { LLVMTypeRef vec_type = lp_build_vec_type(type); - LLVMValueRef mask = lp_build_int_const_scalar(type, (unsigned long long)1 << (type.width - 1)); + LLVMValueRef mask = lp_build_const_int_vec(type, (unsigned long long)1 << (type.width - 1)); LLVMValueRef sign; LLVMValueRef half; @@ -1043,7 +1043,7 @@ lp_build_iround(struct lp_build_context *bld, sign = LLVMBuildAnd(bld->builder, sign, mask, ""); /* sign * 0.5 */ - half = lp_build_const_scalar(type, 0.5); + half = lp_build_const_vec(type, 0.5); half = LLVMBuildBitCast(bld->builder, half, int_vec_type, ""); half = LLVMBuildOr(bld->builder, sign, half, ""); half = LLVMBuildBitCast(bld->builder, half, vec_type, ""); @@ -1086,18 +1086,18 @@ lp_build_ifloor(struct lp_build_context *bld, /* Take the sign bit and add it to 1 constant */ LLVMTypeRef vec_type = lp_build_vec_type(type); unsigned mantissa = lp_mantissa(type); - LLVMValueRef mask = lp_build_int_const_scalar(type, (unsigned long long)1 << (type.width - 1)); + LLVMValueRef mask = lp_build_const_int_vec(type, (unsigned long long)1 << (type.width - 1)); LLVMValueRef sign; LLVMValueRef offset; /* sign = a < 0 ? ~0 : 0 */ sign = LLVMBuildBitCast(bld->builder, a, int_vec_type, ""); sign = LLVMBuildAnd(bld->builder, sign, mask, ""); - sign = LLVMBuildAShr(bld->builder, sign, lp_build_int_const_scalar(type, type.width - 1), ""); + sign = LLVMBuildAShr(bld->builder, sign, lp_build_const_int_vec(type, type.width - 1), ""); lp_build_name(sign, "floor.sign"); /* offset = -0.99999(9)f */ - offset = lp_build_const_scalar(type, -(double)(((unsigned long long)1 << mantissa) - 1)/((unsigned long long)1 << mantissa)); + offset = lp_build_const_vec(type, -(double)(((unsigned long long)1 << mantissa) - 1)/((unsigned long long)1 << mantissa)); offset = LLVMConstBitCast(offset, int_vec_type); /* offset = a < 0 ? -0.99999(9)f : 0.0f */ @@ -1268,7 +1268,7 @@ lp_build_exp(struct lp_build_context *bld, LLVMValueRef x) { /* log2(e) = 1/log(2) */ - LLVMValueRef log2e = lp_build_const_scalar(bld->type, 1.4426950408889634); + LLVMValueRef log2e = lp_build_const_vec(bld->type, 1.4426950408889634); return lp_build_mul(bld, log2e, lp_build_exp2(bld, x)); } @@ -1282,7 +1282,7 @@ lp_build_log(struct lp_build_context *bld, LLVMValueRef x) { /* log(2) */ - LLVMValueRef log2 = lp_build_const_scalar(bld->type, 0.69314718055994529); + LLVMValueRef log2 = lp_build_const_vec(bld->type, 0.69314718055994529); return lp_build_mul(bld, log2, lp_build_exp2(bld, x)); } @@ -1318,7 +1318,7 @@ lp_build_polynomial(struct lp_build_context *bld, if (type.length == 1) coeff = LLVMConstReal(float_type, coeffs[i]); else - coeff = lp_build_const_scalar(type, coeffs[i]); + coeff = lp_build_const_vec(type, coeffs[i]); if(res) res = lp_build_add(bld, coeff, lp_build_mul(bld, x, res)); @@ -1375,11 +1375,11 @@ lp_build_exp2_approx(struct lp_build_context *bld, assert(type.floating && type.width == 32); - x = lp_build_min(bld, x, lp_build_const_scalar(type, 129.0)); - x = lp_build_max(bld, x, lp_build_const_scalar(type, -126.99999)); + x = lp_build_min(bld, x, lp_build_const_vec(type, 129.0)); + x = lp_build_max(bld, x, lp_build_const_vec(type, -126.99999)); /* ipart = int(x - 0.5) */ - ipart = LLVMBuildSub(bld->builder, x, lp_build_const_scalar(type, 0.5f), ""); + ipart = LLVMBuildSub(bld->builder, x, lp_build_const_vec(type, 0.5f), ""); ipart = LLVMBuildFPToSI(bld->builder, ipart, int_vec_type, ""); /* fpart = x - ipart */ @@ -1389,8 +1389,8 @@ lp_build_exp2_approx(struct lp_build_context *bld, if(p_exp2_int_part || p_exp2) { /* expipart = (float) (1 << ipart) */ - expipart = LLVMBuildAdd(bld->builder, ipart, lp_build_int_const_scalar(type, 127), ""); - expipart = LLVMBuildShl(bld->builder, expipart, lp_build_int_const_scalar(type, 23), ""); + expipart = LLVMBuildAdd(bld->builder, ipart, lp_build_const_int_vec(type, 127), ""); + expipart = LLVMBuildShl(bld->builder, expipart, lp_build_const_int_vec(type, 23), ""); expipart = LLVMBuildBitCast(bld->builder, expipart, vec_type, ""); } @@ -1456,8 +1456,8 @@ lp_build_log2_approx(struct lp_build_context *bld, LLVMTypeRef vec_type = lp_build_vec_type(type); LLVMTypeRef int_vec_type = lp_build_int_vec_type(type); - LLVMValueRef expmask = lp_build_int_const_scalar(type, 0x7f800000); - LLVMValueRef mantmask = lp_build_int_const_scalar(type, 0x007fffff); + LLVMValueRef expmask = lp_build_const_int_vec(type, 0x7f800000); + LLVMValueRef mantmask = lp_build_const_int_vec(type, 0x007fffff); LLVMValueRef one = LLVMConstBitCast(bld->one, int_vec_type); LLVMValueRef i = NULL; @@ -1482,8 +1482,8 @@ lp_build_log2_approx(struct lp_build_context *bld, } if(p_floor_log2 || p_log2) { - logexp = LLVMBuildLShr(bld->builder, exp, lp_build_int_const_scalar(type, 23), ""); - logexp = LLVMBuildSub(bld->builder, logexp, lp_build_int_const_scalar(type, 127), ""); + logexp = LLVMBuildLShr(bld->builder, exp, lp_build_const_int_vec(type, 23), ""); + logexp = LLVMBuildSub(bld->builder, logexp, lp_build_const_int_vec(type, 127), ""); logexp = LLVMBuildSIToFP(bld->builder, logexp, vec_type, ""); } diff --git a/src/gallium/auxiliary/gallivm/lp_bld_const.c b/src/gallium/auxiliary/gallivm/lp_bld_const.c index 8a275fa72f3..57843e9a60c 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_const.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_const.c @@ -263,7 +263,7 @@ lp_build_one(struct lp_type type) if(type.sign) /* TODO: Unfortunately this caused "Tried to create a shift operation * on a non-integer type!" */ - vec = LLVMConstLShr(vec, lp_build_int_const_scalar(type, 1)); + vec = LLVMConstLShr(vec, lp_build_const_int_vec(type, 1)); #endif return vec; @@ -283,8 +283,8 @@ lp_build_one(struct lp_type type) * Build constant-valued vector from a scalar value. */ LLVMValueRef -lp_build_const_scalar(struct lp_type type, - double val) +lp_build_const_vec(struct lp_type type, + double val) { LLVMTypeRef elem_type = lp_build_elem_type(type); LLVMValueRef elems[LP_MAX_VECTOR_LENGTH]; @@ -309,7 +309,7 @@ lp_build_const_scalar(struct lp_type type, LLVMValueRef -lp_build_int_const_scalar(struct lp_type type, +lp_build_const_int_vec(struct lp_type type, long long val) { LLVMTypeRef elem_type = lp_build_int_elem_type(type); diff --git a/src/gallium/auxiliary/gallivm/lp_bld_const.h b/src/gallium/auxiliary/gallivm/lp_bld_const.h index 0f426189003..9ca2f0664eb 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_const.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_const.h @@ -85,13 +85,11 @@ lp_build_one(struct lp_type type); LLVMValueRef -lp_build_const_scalar(struct lp_type type, - double val); +lp_build_const_vec(struct lp_type type, double val); LLVMValueRef -lp_build_int_const_scalar(struct lp_type type, - long long val); +lp_build_const_int_vec(struct lp_type type, long long val); LLVMValueRef diff --git a/src/gallium/auxiliary/gallivm/lp_bld_conv.c b/src/gallium/auxiliary/gallivm/lp_bld_conv.c index f77cf787213..3f7f2ebde9c 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_conv.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_conv.c @@ -114,13 +114,13 @@ lp_build_clamped_float_to_unsigned_norm(LLVMBuilderRef builder, scale = (double)mask/ubound; bias = (double)((unsigned long long)1 << (mantissa - n)); - res = LLVMBuildMul(builder, src, lp_build_const_scalar(src_type, scale), ""); - res = LLVMBuildAdd(builder, res, lp_build_const_scalar(src_type, bias), ""); + res = LLVMBuildMul(builder, src, lp_build_const_vec(src_type, scale), ""); + res = LLVMBuildAdd(builder, res, lp_build_const_vec(src_type, bias), ""); res = LLVMBuildBitCast(builder, res, int_vec_type, ""); if(dst_width > n) { int shift = dst_width - n; - res = LLVMBuildShl(builder, res, lp_build_int_const_scalar(src_type, shift), ""); + res = LLVMBuildShl(builder, res, lp_build_const_int_vec(src_type, shift), ""); /* TODO: Fill in the empty lower bits for additional precision? */ /* YES: this fixes progs/trivial/tri-z-eq.c. @@ -130,21 +130,21 @@ lp_build_clamped_float_to_unsigned_norm(LLVMBuilderRef builder, #if 0 { LLVMValueRef msb; - msb = LLVMBuildLShr(builder, res, lp_build_int_const_scalar(src_type, dst_width - 1), ""); - msb = LLVMBuildShl(builder, msb, lp_build_int_const_scalar(src_type, shift), ""); - msb = LLVMBuildSub(builder, msb, lp_build_int_const_scalar(src_type, 1), ""); + msb = LLVMBuildLShr(builder, res, lp_build_const_int_vec(src_type, dst_width - 1), ""); + msb = LLVMBuildShl(builder, msb, lp_build_const_int_vec(src_type, shift), ""); + msb = LLVMBuildSub(builder, msb, lp_build_const_int_vec(src_type, 1), ""); res = LLVMBuildOr(builder, res, msb, ""); } #elif 0 while(shift > 0) { - res = LLVMBuildOr(builder, res, LLVMBuildLShr(builder, res, lp_build_int_const_scalar(src_type, n), ""), ""); + res = LLVMBuildOr(builder, res, LLVMBuildLShr(builder, res, lp_build_const_int_vec(src_type, n), ""), ""); shift -= n; n *= 2; } #endif } else - res = LLVMBuildAnd(builder, res, lp_build_int_const_scalar(src_type, mask), ""); + res = LLVMBuildAnd(builder, res, lp_build_const_int_vec(src_type, mask), ""); return res; } @@ -183,10 +183,10 @@ lp_build_unsigned_norm_to_float(LLVMBuilderRef builder, if(src_width > mantissa) { int shift = src_width - mantissa; - res = LLVMBuildLShr(builder, res, lp_build_int_const_scalar(dst_type, shift), ""); + res = LLVMBuildLShr(builder, res, lp_build_const_int_vec(dst_type, shift), ""); } - bias_ = lp_build_const_scalar(dst_type, bias); + bias_ = lp_build_const_vec(dst_type, bias); res = LLVMBuildOr(builder, res, @@ -195,7 +195,7 @@ lp_build_unsigned_norm_to_float(LLVMBuilderRef builder, res = LLVMBuildBitCast(builder, res, vec_type, ""); res = LLVMBuildSub(builder, res, bias_, ""); - res = LLVMBuildMul(builder, res, lp_build_const_scalar(dst_type, scale), ""); + res = LLVMBuildMul(builder, res, lp_build_const_vec(dst_type, scale), ""); return res; } @@ -251,7 +251,7 @@ lp_build_conv(LLVMBuilderRef builder, if(dst_min == 0.0) thres = bld.zero; else - thres = lp_build_const_scalar(src_type, dst_min); + thres = lp_build_const_vec(src_type, dst_min); for(i = 0; i < num_tmps; ++i) tmp[i] = lp_build_max(&bld, tmp[i], thres); } @@ -260,7 +260,7 @@ lp_build_conv(LLVMBuilderRef builder, if(dst_max == 1.0) thres = bld.one; else - thres = lp_build_const_scalar(src_type, dst_max); + thres = lp_build_const_vec(src_type, dst_max); for(i = 0; i < num_tmps; ++i) tmp[i] = lp_build_min(&bld, tmp[i], thres); } @@ -288,7 +288,7 @@ lp_build_conv(LLVMBuilderRef builder, LLVMTypeRef tmp_vec_type; if (dst_scale != 1.0) { - LLVMValueRef scale = lp_build_const_scalar(tmp_type, dst_scale); + LLVMValueRef scale = lp_build_const_vec(tmp_type, dst_scale); for(i = 0; i < num_tmps; ++i) tmp[i] = LLVMBuildMul(builder, tmp[i], scale, ""); } @@ -315,7 +315,7 @@ lp_build_conv(LLVMBuilderRef builder, /* FIXME: compensate different offsets too */ if(src_shift > dst_shift) { - LLVMValueRef shift = lp_build_int_const_scalar(tmp_type, src_shift - dst_shift); + LLVMValueRef shift = lp_build_const_int_vec(tmp_type, src_shift - dst_shift); for(i = 0; i < num_tmps; ++i) if(src_type.sign) tmp[i] = LLVMBuildAShr(builder, tmp[i], shift, ""); @@ -388,7 +388,7 @@ lp_build_conv(LLVMBuilderRef builder, } if (src_scale != 1.0) { - LLVMValueRef scale = lp_build_const_scalar(tmp_type, 1.0/src_scale); + LLVMValueRef scale = lp_build_const_vec(tmp_type, 1.0/src_scale); for(i = 0; i < num_tmps; ++i) tmp[i] = LLVMBuildMul(builder, tmp[i], scale, ""); } @@ -400,7 +400,7 @@ lp_build_conv(LLVMBuilderRef builder, /* FIXME: compensate different offsets too */ if(src_shift < dst_shift) { - LLVMValueRef shift = lp_build_int_const_scalar(tmp_type, dst_shift - src_shift); + LLVMValueRef shift = lp_build_const_int_vec(tmp_type, dst_shift - src_shift); for(i = 0; i < num_tmps; ++i) tmp[i] = LLVMBuildShl(builder, tmp[i], shift, ""); } diff --git a/src/gallium/auxiliary/gallivm/lp_bld_depth.c b/src/gallium/auxiliary/gallivm/lp_bld_depth.c index f08f8eb6d8b..829cffea4c8 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_depth.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_depth.c @@ -185,11 +185,11 @@ lp_build_depth_test(LLVMBuilderRef builder, if(padding_left || padding_right) { const unsigned long long mask_left = ((unsigned long long)1 << (format_desc->block.bits - padding_left)) - 1; const unsigned long long mask_right = ((unsigned long long)1 << (padding_right)) - 1; - z_bitmask = lp_build_int_const_scalar(type, mask_left ^ mask_right); + z_bitmask = lp_build_const_int_vec(type, mask_left ^ mask_right); } if(padding_left) - src = LLVMBuildLShr(builder, src, lp_build_int_const_scalar(type, padding_left), ""); + src = LLVMBuildLShr(builder, src, lp_build_const_int_vec(type, padding_left), ""); if(padding_right) src = LLVMBuildAnd(builder, src, z_bitmask, ""); if(padding_left || padding_right) diff --git a/src/gallium/auxiliary/gallivm/lp_bld_format_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_format_soa.c index abb27e4c328..45ee4b12ced 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_format_soa.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_format_soa.c @@ -114,10 +114,10 @@ lp_build_unpack_rgba_soa(LLVMBuilderRef builder, case UTIL_FORMAT_TYPE_UNSIGNED: if(type.floating) { if(start) - input = LLVMBuildLShr(builder, input, lp_build_int_const_scalar(type, start), ""); + input = LLVMBuildLShr(builder, input, lp_build_const_int_vec(type, start), ""); if(stop < format_desc->block.bits) { unsigned mask = ((unsigned long long)1 << width) - 1; - input = LLVMBuildAnd(builder, input, lp_build_int_const_scalar(type, mask), ""); + input = LLVMBuildAnd(builder, input, lp_build_const_int_vec(type, mask), ""); } if(format_desc->channel[chan].normalized) diff --git a/src/gallium/auxiliary/gallivm/lp_bld_interp.c b/src/gallium/auxiliary/gallivm/lp_bld_interp.c index 2fc894017d8..09efb161217 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_interp.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_interp.c @@ -289,17 +289,17 @@ pos_update(struct lp_build_interp_soa_context *bld, int quad_index) /* top-right or bottom-right quad in block */ /* build x += xstep */ x = lp_build_add(&bld->base, x, - lp_build_const_scalar(bld->base.type, xstep)); + lp_build_const_vec(bld->base.type, xstep)); } if (quad_index == 2) { /* bottom-left quad in block */ /* build y += ystep */ y = lp_build_add(&bld->base, y, - lp_build_const_scalar(bld->base.type, ystep)); + lp_build_const_vec(bld->base.type, ystep)); /* build x -= xstep */ x = lp_build_sub(&bld->base, x, - lp_build_const_scalar(bld->base.type, xstep)); + lp_build_const_vec(bld->base.type, xstep)); } lp_build_name(x, "pos.x"); diff --git a/src/gallium/auxiliary/gallivm/lp_bld_logic.c b/src/gallium/auxiliary/gallivm/lp_bld_logic.c index f3df3dd1388..e2e533fa7ec 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_logic.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_logic.c @@ -193,7 +193,7 @@ lp_build_compare(LLVMBuilderRef builder, if(table[func].gt && ((type.width == 8 && type.sign) || (type.width != 8 && !type.sign))) { - LLVMValueRef msb = lp_build_int_const_scalar(type, (unsigned long long)1 << (type.width - 1)); + LLVMValueRef msb = lp_build_const_int_vec(type, (unsigned long long)1 << (type.width - 1)); a = LLVMBuildXor(builder, a, msb, ""); b = LLVMBuildXor(builder, b, msb, ""); } diff --git a/src/gallium/auxiliary/gallivm/lp_bld_pack.c b/src/gallium/auxiliary/gallivm/lp_bld_pack.c index 23398f41f99..2daa8a3b582 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_pack.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_pack.c @@ -164,7 +164,7 @@ lp_build_unpack2(LLVMBuilderRef builder, if(dst_type.sign && src_type.sign) { /* Replicate the sign bit in the most significant bits */ - msb = LLVMBuildAShr(builder, src, lp_build_int_const_scalar(src_type, src_type.width - 1), ""); + msb = LLVMBuildAShr(builder, src, lp_build_const_int_vec(src_type, src_type.width - 1), ""); } else /* Most significant bits always zero */ @@ -361,7 +361,7 @@ lp_build_packs2(LLVMBuilderRef builder, if(clamp) { struct lp_build_context bld; unsigned dst_bits = dst_type.sign ? dst_type.width - 1 : dst_type.width; - LLVMValueRef dst_max = lp_build_int_const_scalar(src_type, ((unsigned long long)1 << dst_bits) - 1); + LLVMValueRef dst_max = lp_build_const_int_vec(src_type, ((unsigned long long)1 << dst_bits) - 1); lp_build_context_init(&bld, builder, src_type); lo = lp_build_min(&bld, lo, dst_max); hi = lp_build_min(&bld, hi, dst_max); diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample.c b/src/gallium/auxiliary/gallivm/lp_bld_sample.c index 2f74aa5e00a..bb76ad4c6bf 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_sample.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_sample.c @@ -173,7 +173,7 @@ lp_build_sample_offset(struct lp_build_context *bld, LLVMValueRef x_stride; LLVMValueRef offset; - x_stride = lp_build_const_scalar(bld->type, format_desc->block.bits/8); + x_stride = lp_build_const_vec(bld->type, format_desc->block.bits/8); if(format_desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS) { LLVMValueRef x_lo, x_hi; @@ -195,9 +195,9 @@ lp_build_sample_offset(struct lp_build_context *bld, y_hi = LLVMBuildLShr(bld->builder, y, bld->one, ""); x_stride_lo = x_stride; - y_stride_lo = lp_build_const_scalar(bld->type, 2*format_desc->block.bits/8); + y_stride_lo = lp_build_const_vec(bld->type, 2*format_desc->block.bits/8); - x_stride_hi = lp_build_const_scalar(bld->type, 4*format_desc->block.bits/8); + x_stride_hi = lp_build_const_vec(bld->type, 4*format_desc->block.bits/8); y_stride_hi = LLVMBuildShl(bld->builder, y_stride, bld->one, ""); x_offset_lo = lp_build_mul(bld, x_lo, x_stride_lo); diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c index 9741dbb389c..995c016b9dd 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c @@ -292,7 +292,7 @@ lp_build_sample_texel_soa(struct lp_build_sample_context *bld, int chan; for (chan = 0; chan < 4; chan++) { LLVMValueRef border_chan = - lp_build_const_scalar(bld->texel_type, + lp_build_const_vec(bld->texel_type, bld->static_state->border_color[chan]); texel[chan] = lp_build_select(&bld->texel_bld, use_border, border_chan, texel[chan]); @@ -457,8 +457,8 @@ lp_build_sample_wrap_linear(struct lp_build_sample_context *bld, struct lp_build_context *coord_bld = &bld->coord_bld; struct lp_build_context *int_coord_bld = &bld->int_coord_bld; struct lp_build_context *uint_coord_bld = &bld->uint_coord_bld; - LLVMValueRef two = lp_build_const_scalar(coord_bld->type, 2.0); - LLVMValueRef half = lp_build_const_scalar(coord_bld->type, 0.5); + LLVMValueRef two = lp_build_const_vec(coord_bld->type, 2.0); + LLVMValueRef half = lp_build_const_vec(coord_bld->type, 0.5); LLVMValueRef length_f = lp_build_int_to_float(coord_bld, length); LLVMValueRef length_minus_one = lp_build_sub(uint_coord_bld, length, uint_coord_bld->one); LLVMValueRef length_f_minus_one = lp_build_sub(coord_bld, length_f, coord_bld->one); @@ -512,7 +512,7 @@ lp_build_sample_wrap_linear(struct lp_build_sample_context *bld, else { LLVMValueRef min, max; /* clamp to [0.5, length - 0.5] */ - min = lp_build_const_scalar(coord_bld->type, 0.5F); + min = lp_build_const_vec(coord_bld->type, 0.5F); max = lp_build_sub(coord_bld, length_f, min); coord = lp_build_clamp(coord_bld, coord, min, max); } @@ -533,7 +533,7 @@ lp_build_sample_wrap_linear(struct lp_build_sample_context *bld, if (bld->static_state->normalized_coords) { /* min = -1.0 / (2 * length) = -0.5 / length */ min = lp_build_mul(coord_bld, - lp_build_const_scalar(coord_bld->type, -0.5F), + lp_build_const_vec(coord_bld->type, -0.5F), lp_build_rcp(coord_bld, length_f)); /* max = 1.0 - min */ max = lp_build_sub(coord_bld, coord_bld->one, min); @@ -545,7 +545,7 @@ lp_build_sample_wrap_linear(struct lp_build_sample_context *bld, } else { /* clamp to [-0.5, length + 0.5] */ - min = lp_build_const_scalar(coord_bld->type, -0.5F); + min = lp_build_const_vec(coord_bld->type, -0.5F); max = lp_build_sub(coord_bld, length_f, min); coord = lp_build_clamp(coord_bld, coord, min, max); coord = lp_build_sub(coord_bld, coord, half); @@ -620,7 +620,7 @@ lp_build_sample_wrap_linear(struct lp_build_sample_context *bld, LLVMValueRef min, max; /* min = -1.0 / (2 * length) = -0.5 / length */ min = lp_build_mul(coord_bld, - lp_build_const_scalar(coord_bld->type, -0.5F), + lp_build_const_vec(coord_bld->type, -0.5F), lp_build_rcp(coord_bld, length_f)); /* max = 1.0 - min */ max = lp_build_sub(coord_bld, coord_bld->one, min); @@ -665,7 +665,7 @@ lp_build_sample_wrap_nearest(struct lp_build_sample_context *bld, struct lp_build_context *coord_bld = &bld->coord_bld; struct lp_build_context *int_coord_bld = &bld->int_coord_bld; struct lp_build_context *uint_coord_bld = &bld->uint_coord_bld; - LLVMValueRef two = lp_build_const_scalar(coord_bld->type, 2.0); + LLVMValueRef two = lp_build_const_vec(coord_bld->type, 2.0); LLVMValueRef length_f = lp_build_int_to_float(coord_bld, length); LLVMValueRef length_minus_one = lp_build_sub(uint_coord_bld, length, uint_coord_bld->one); LLVMValueRef length_f_minus_one = lp_build_sub(coord_bld, length_f, coord_bld->one); @@ -708,7 +708,7 @@ lp_build_sample_wrap_nearest(struct lp_build_sample_context *bld, } else { /* clamp to [0.5, length - 0.5] */ - min = lp_build_const_scalar(coord_bld->type, 0.5F); + min = lp_build_const_vec(coord_bld->type, 0.5F); max = lp_build_sub(coord_bld, length_f, min); } /* coord = clamp(coord, min, max) */ @@ -724,7 +724,7 @@ lp_build_sample_wrap_nearest(struct lp_build_sample_context *bld, if (bld->static_state->normalized_coords) { /* min = -1.0 / (2 * length) = -0.5 / length */ min = lp_build_mul(coord_bld, - lp_build_const_scalar(coord_bld->type, -0.5F), + lp_build_const_vec(coord_bld->type, -0.5F), lp_build_rcp(coord_bld, length_f)); /* max = length - min */ max = lp_build_sub(coord_bld, length_f, min); @@ -733,7 +733,7 @@ lp_build_sample_wrap_nearest(struct lp_build_sample_context *bld, } else { /* clamp to [-0.5, length + 0.5] */ - min = lp_build_const_scalar(coord_bld->type, -0.5F); + min = lp_build_const_vec(coord_bld->type, -0.5F); max = lp_build_sub(coord_bld, length_f, min); } /* coord = clamp(coord, min, max) */ @@ -1226,7 +1226,7 @@ static LLVMValueRef lp_build_cube_ima(struct lp_build_context *coord_bld, LLVMValueRef coord) { /* ima = -0.5 / abs(coord); */ - LLVMValueRef negHalf = lp_build_const_scalar(coord_bld->type, -0.5); + LLVMValueRef negHalf = lp_build_const_vec(coord_bld->type, -0.5); LLVMValueRef absCoord = lp_build_abs(coord_bld, coord); LLVMValueRef ima = lp_build_mul(coord_bld, negHalf, lp_build_rcp(coord_bld, absCoord)); @@ -1246,7 +1246,7 @@ lp_build_cube_coord(struct lp_build_context *coord_bld, LLVMValueRef coord, LLVMValueRef ima) { /* return negate(coord) * ima * sign + 0.5; */ - LLVMValueRef half = lp_build_const_scalar(coord_bld->type, 0.5); + LLVMValueRef half = lp_build_const_vec(coord_bld->type, 0.5); LLVMValueRef res; assert(negate_coord == +1 || negate_coord == -1); @@ -1708,7 +1708,7 @@ lp_build_rgba8_to_f32_soa(LLVMBuilderRef builder, LLVMValueRef packed, LLVMValueRef *rgba) { - LLVMValueRef mask = lp_build_int_const_scalar(dst_type, 0xff); + LLVMValueRef mask = lp_build_const_int_vec(dst_type, 0xff); unsigned chan; /* Decode the input vector components */ @@ -1720,7 +1720,7 @@ lp_build_rgba8_to_f32_soa(LLVMBuilderRef builder, input = packed; if(start) - input = LLVMBuildLShr(builder, input, lp_build_int_const_scalar(dst_type, start), ""); + input = LLVMBuildLShr(builder, input, lp_build_const_int_vec(dst_type, start), ""); if(stop < 32) input = LLVMBuildAnd(builder, input, mask, ""); @@ -1782,17 +1782,17 @@ lp_build_sample_2d_linear_aos(struct lp_build_sample_context *bld, t = LLVMBuildFPToSI(builder, t, i32_vec_type, ""); /* subtract 0.5 (add -128) */ - i32_c128 = lp_build_int_const_scalar(i32.type, -128); + i32_c128 = lp_build_const_int_vec(i32.type, -128); s = LLVMBuildAdd(builder, s, i32_c128, ""); t = LLVMBuildAdd(builder, t, i32_c128, ""); /* compute floor (shift right 8) */ - i32_c8 = lp_build_int_const_scalar(i32.type, 8); + i32_c8 = lp_build_const_int_vec(i32.type, 8); s_ipart = LLVMBuildAShr(builder, s, i32_c8, ""); t_ipart = LLVMBuildAShr(builder, t, i32_c8, ""); /* compute fractional part (AND with 0xff) */ - i32_c255 = lp_build_int_const_scalar(i32.type, 255); + i32_c255 = lp_build_const_int_vec(i32.type, 255); s_fpart = LLVMBuildAnd(builder, s, i32_c255, ""); t_fpart = LLVMBuildAnd(builder, t, i32_c255, ""); @@ -1959,7 +1959,7 @@ lp_build_sample_compare(struct lp_build_sample_context *bld, } assert(res); - res = lp_build_mul(texel_bld, res, lp_build_const_scalar(texel_bld->type, 0.25)); + res = lp_build_mul(texel_bld, res, lp_build_const_vec(texel_bld->type, 0.25)); /* XXX returning result for default GL_DEPTH_TEXTURE_MODE = GL_LUMINANCE */ for(chan = 0; chan < 3; ++chan) diff --git a/src/gallium/auxiliary/gallivm/lp_bld_swizzle.c b/src/gallium/auxiliary/gallivm/lp_bld_swizzle.c index 64e81f7b1fe..278c838eaca 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_swizzle.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_swizzle.c @@ -144,9 +144,9 @@ lp_build_broadcast_aos(struct lp_build_context *bld, #endif if(shift > 0) - tmp = LLVMBuildLShr(bld->builder, a, lp_build_int_const_scalar(type4, shift*type.width), ""); + tmp = LLVMBuildLShr(bld->builder, a, lp_build_const_int_vec(type4, shift*type.width), ""); if(shift < 0) - tmp = LLVMBuildShl(bld->builder, a, lp_build_int_const_scalar(type4, -shift*type.width), ""); + tmp = LLVMBuildShl(bld->builder, a, lp_build_const_int_vec(type4, -shift*type.width), ""); assert(tmp); if(tmp) diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c index 5ec59d636cb..f160be878f8 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c @@ -475,7 +475,7 @@ emit_store( break; case TGSI_SAT_MINUS_PLUS_ONE: - value = lp_build_max(&bld->base, value, lp_build_const_scalar(bld->base.type, -1.0)); + value = lp_build_max(&bld->base, value, lp_build_const_vec(bld->base.type, -1.0)); value = lp_build_min(&bld->base, value, bld->base.one); break; @@ -996,7 +996,7 @@ emit_instruction( src0 = emit_fetch( bld, inst, 0, chan_index ); src1 = emit_fetch( bld, inst, 1, chan_index ); src2 = emit_fetch( bld, inst, 2, chan_index ); - tmp1 = lp_build_const_scalar(bld->base.type, 0.5); + tmp1 = lp_build_const_vec(bld->base.type, 0.5); tmp0 = lp_build_cmp( &bld->base, PIPE_FUNC_GREATER, src2, tmp1); dst0[chan_index] = lp_build_select( &bld->base, tmp0, src0, src1 ); } @@ -1713,7 +1713,7 @@ lp_build_tgsi_soa(LLVMBuilderRef builder, assert(num_immediates < LP_MAX_IMMEDIATES); for( i = 0; i < size; ++i ) bld.immediates[num_immediates][i] = - lp_build_const_scalar(type, parse.FullToken.FullImmediate.u[i].Float); + lp_build_const_vec(type, parse.FullToken.FullImmediate.u[i].Float); for( i = size; i < 4; ++i ) bld.immediates[num_immediates][i] = bld.base.undef; num_immediates++; diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs.c b/src/gallium/drivers/llvmpipe/lp_state_fs.c index 9a8de0edfda..64f988d6d01 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_fs.c +++ b/src/gallium/drivers/llvmpipe/lp_state_fs.c @@ -252,7 +252,7 @@ generate_tri_edge_mask(LLVMBuilderRef builder, LLVMConstInt(LLVMInt32Type(), INT_MIN, 0), ""); - in_out_mask = lp_build_int_const_scalar(i32_type, ~0); + in_out_mask = lp_build_const_int_vec(i32_type, ~0); lp_build_flow_scope_declare(flow, &in_out_mask); @@ -367,7 +367,7 @@ build_int32_vec_const(int value) i32_type.norm = FALSE; /* values are not normalized */ i32_type.width = 32; /* 32-bit int values */ i32_type.length = 4; /* 4 elements per vector */ - return lp_build_int_const_scalar(i32_type, value); + return lp_build_const_int_vec(i32_type, value); } -- cgit v1.2.3 From cb1b0b4bec9a1c05bbb762ed04a78dfdf584e3a6 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 15 Mar 2010 18:19:04 -0600 Subject: gallivm: checkpoint: stencil test code --- src/gallium/auxiliary/gallivm/lp_bld_depth.c | 106 ++++++++++++++++++++++++++- 1 file changed, 105 insertions(+), 1 deletion(-) (limited to 'src/gallium') diff --git a/src/gallium/auxiliary/gallivm/lp_bld_depth.c b/src/gallium/auxiliary/gallivm/lp_bld_depth.c index 829cffea4c8..cbc48f98651 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_depth.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_depth.c @@ -61,11 +61,104 @@ #include "util/u_format.h" #include "lp_bld_type.h" +#include "lp_bld_arit.h" #include "lp_bld_const.h" #include "lp_bld_logic.h" #include "lp_bld_flow.h" #include "lp_bld_debug.h" #include "lp_bld_depth.h" +#include "lp_bld_swizzle.h" + + + +/** + * Do the stencil test comparison (compare fb Z values against ref value. + * \param stencilVals vector of stencil values from framebuffer + * \param stencilRef the stencil reference value, replicated as a vector + * \return mask of pass/fail values + */ +static LLVMValueRef +lp_build_stencil_test(struct lp_build_context *bld, + const struct pipe_stencil_state *stencil, + LLVMValueRef stencilVals, + LLVMValueRef stencilRef) +{ + const unsigned stencilMax = 255; /* XXX fix */ + struct lp_type type = bld->type; + LLVMValueRef res; + + assert(stencil->enabled); + + if (stencil->valuemask != stencilMax) { + /* compute stencilRef = stencilRef & valuemask */ + LLVMValueRef valuemask = lp_build_const_int_vec(type, stencil->valuemask); + stencilRef = LLVMBuildAnd(bld->builder, stencilRef, valuemask, ""); + /* compute stencilVals = stencilVals & valuemask */ + stencilVals = LLVMBuildAnd(bld->builder, stencilVals, valuemask, ""); + } + + res = lp_build_compare(bld->builder, bld->type, stencil->func, + stencilVals, stencilRef); + + return res; +} + + +/** + * Apply the stencil operator (add/sub/keep/etc) to the given vector + * of stencil values. + * \return new stencil values vector + */ +static LLVMValueRef +lp_build_stencil_op(struct lp_build_context *bld, + unsigned stencil_op, + LLVMValueRef stencilRef, + const struct pipe_stencil_state *stencil, + LLVMValueRef stencilVals) + +{ + const unsigned stencilMax = 255; /* XXX fix */ + struct lp_type type = bld->type; + LLVMValueRef res; + LLVMValueRef max = lp_build_const_int_vec(type, stencilMax); + + switch (stencil_op) { + case PIPE_STENCIL_OP_KEEP: + res = stencilVals; + case PIPE_STENCIL_OP_ZERO: + res = bld->zero; + case PIPE_STENCIL_OP_REPLACE: + res = lp_build_broadcast_scalar(bld, stencilRef); + case PIPE_STENCIL_OP_INCR: + res = lp_build_add(bld, stencilVals, bld->one); + res = lp_build_min(bld, res, max); + case PIPE_STENCIL_OP_DECR: + res = lp_build_sub(bld, stencilVals, bld->one); + res = lp_build_max(bld, res, bld->zero); + case PIPE_STENCIL_OP_INCR_WRAP: + res = lp_build_add(bld, stencilVals, bld->one); + res = LLVMBuildAnd(bld->builder, res, max, ""); + case PIPE_STENCIL_OP_DECR_WRAP: + res = lp_build_sub(bld, stencilVals, bld->one); + res = LLVMBuildAnd(bld->builder, res, max, ""); + case PIPE_STENCIL_OP_INVERT: + res = LLVMBuildNot(bld->builder, stencilVals, ""); + default: + assert(0 && "bad stencil op mode"); + res = NULL; + } + + if (stencil->writemask != stencilMax) { + /* compute res = (res & mask) | (stencilVals & ~mask) */ + LLVMValueRef mask = lp_build_const_int_vec(type, stencil->writemask); + LLVMValueRef cmask = LLVMBuildNot(bld->builder, mask, "notWritemask"); + LLVMValueRef t1 = LLVMBuildAnd(bld->builder, res, mask, "t1"); + LLVMValueRef t2 = LLVMBuildAnd(bld->builder, stencilVals, cmask, "t2"); + res = LLVMBuildOr(bld->builder, t1, t2, "t1_or_t2"); + } + + return res; +} /** @@ -109,7 +202,14 @@ lp_depth_type(const struct util_format_description *format_desc, /** - * Depth test. + * Generate code for performing depth and/or stencil tests. + * We operate on a vector of values (typically a 2x2 quad). + * + * \param type the data type of the fragment depth/stencil values + * \param format_desc description of the depth/stencil surface + * \param mask the alive/dead pixel mask for the quad + * \param src the incoming depth/stencil values (a 2x2 quad) + * \param dst_ptr the outgoing/updated depth/stencil values */ void lp_build_depth_test(LLVMBuilderRef builder, @@ -126,6 +226,9 @@ lp_build_depth_test(LLVMBuilderRef builder, LLVMValueRef z_bitmask = NULL; LLVMValueRef test; + (void) lp_build_stencil_test; + (void) lp_build_stencil_op; + if(!state->enabled) return; @@ -198,6 +301,7 @@ lp_build_depth_test(LLVMBuilderRef builder, lp_build_name(dst, "zsbuf.z"); + /* compare src Z to dst Z, returning 'pass' mask */ test = lp_build_cmp(&bld, state->func, src, dst); lp_build_mask_update(mask, test); -- cgit v1.2.3 From eaee22ac880e431028ac4c6854af1873d5765869 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Tue, 16 Mar 2010 00:12:37 +0000 Subject: i965g: Fix after context transfers --- src/gallium/drivers/i965/brw_context.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/gallium') diff --git a/src/gallium/drivers/i965/brw_context.c b/src/gallium/drivers/i965/brw_context.c index 3dbe2b91308..4bcdcdd17eb 100644 --- a/src/gallium/drivers/i965/brw_context.c +++ b/src/gallium/drivers/i965/brw_context.c @@ -118,6 +118,7 @@ struct pipe_context *brw_create_context(struct pipe_screen *screen, brw->sws = brw_screen(screen)->sws; brw->chipset = brw_screen(screen)->chipset; + brw_tex_init( brw ); brw_pipe_blend_init( brw ); brw_pipe_depth_stencil_init( brw ); brw_pipe_framebuffer_init( brw ); -- cgit v1.2.3 From 8b63f9b497c22cb59678588d921699189f8b712f Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Thu, 11 Mar 2010 03:33:03 +0000 Subject: winsys/sw: Add a software winsys layered on a pipe --- src/gallium/drivers/cell/ppu/cell_screen.c | 6 +- src/gallium/drivers/cell/ppu/cell_texture.c | 1 + src/gallium/drivers/llvmpipe/lp_screen.c | 6 +- src/gallium/drivers/llvmpipe/lp_texture.c | 51 +++++ src/gallium/drivers/softpipe/sp_screen.c | 6 +- src/gallium/drivers/softpipe/sp_texture.c | 54 ++++- src/gallium/include/state_tracker/sw_winsys.h | 20 ++ src/gallium/winsys/drm/Makefile | 2 +- src/gallium/winsys/drm/i965/dri/Makefile | 1 + src/gallium/winsys/drm/i965/gem/i965_drm_api.c | 12 +- src/gallium/winsys/drm/sw/Makefile | 14 ++ src/gallium/winsys/drm/sw/sw_drm_api.c | 97 +++++++++ src/gallium/winsys/drm/sw/sw_drm_api.h | 34 +++ src/gallium/winsys/drm/sw/wrapper_sw_winsys.c | 282 +++++++++++++++++++++++++ src/gallium/winsys/drm/sw/wrapper_sw_winsys.h | 35 +++ src/gallium/winsys/gdi/gdi_sw_winsys.c | 25 +++ src/gallium/winsys/null/null_sw_winsys.c | 24 +++ src/gallium/winsys/xlib/xlib_sw_winsys.c | 25 +++ 18 files changed, 685 insertions(+), 10 deletions(-) create mode 100644 src/gallium/winsys/drm/sw/Makefile create mode 100644 src/gallium/winsys/drm/sw/sw_drm_api.c create mode 100644 src/gallium/winsys/drm/sw/sw_drm_api.h create mode 100644 src/gallium/winsys/drm/sw/wrapper_sw_winsys.c create mode 100644 src/gallium/winsys/drm/sw/wrapper_sw_winsys.h (limited to 'src/gallium') diff --git a/src/gallium/drivers/cell/ppu/cell_screen.c b/src/gallium/drivers/cell/ppu/cell_screen.c index 31fd963d19a..f5528a7ec6b 100644 --- a/src/gallium/drivers/cell/ppu/cell_screen.c +++ b/src/gallium/drivers/cell/ppu/cell_screen.c @@ -142,8 +142,10 @@ cell_is_format_supported( struct pipe_screen *screen, format == PIPE_FORMAT_A8B8G8R8_SRGB) return FALSE; - if (tex_usage & PIPE_TEXTURE_USAGE_DISPLAY_TARGET) { - if (!winsys->is_displaytarget_format_supported(winsys, format)) + if (tex_usage & (PIPE_TEXTURE_USAGE_DISPLAY_TARGET | + PIPE_TEXTURE_USAGE_SCANOUT | + PIPE_TEXTURE_USAGE_SHARED)) { + if (!winsys->is_displaytarget_format_supported(winsys, tex_usage, format)) return FALSE; } diff --git a/src/gallium/drivers/cell/ppu/cell_texture.c b/src/gallium/drivers/cell/ppu/cell_texture.c index c65c3b4f885..5b169afaf88 100644 --- a/src/gallium/drivers/cell/ppu/cell_texture.c +++ b/src/gallium/drivers/cell/ppu/cell_texture.c @@ -105,6 +105,7 @@ cell_displaytarget_layout(struct pipe_screen *screen, /* Round up the surface size to a multiple of the tile size? */ ct->dt = winsys->displaytarget_create(winsys, + ct->base->tex_usage, ct->base.format, ct->base.width0, ct->base.height0, diff --git a/src/gallium/drivers/llvmpipe/lp_screen.c b/src/gallium/drivers/llvmpipe/lp_screen.c index 5093f58bb19..f1bbc2092c4 100644 --- a/src/gallium/drivers/llvmpipe/lp_screen.c +++ b/src/gallium/drivers/llvmpipe/lp_screen.c @@ -204,8 +204,10 @@ llvmpipe_is_format_supported( struct pipe_screen *_screen, return FALSE; } - if(tex_usage & PIPE_TEXTURE_USAGE_DISPLAY_TARGET) { - if(!winsys->is_displaytarget_format_supported(winsys, format)) + if(tex_usage & (PIPE_TEXTURE_USAGE_DISPLAY_TARGET | + PIPE_TEXTURE_USAGE_SCANOUT | + PIPE_TEXTURE_USAGE_SHARED)) { + if(!winsys->is_displaytarget_format_supported(winsys, tex_usage, format)) return FALSE; } diff --git a/src/gallium/drivers/llvmpipe/lp_texture.c b/src/gallium/drivers/llvmpipe/lp_texture.c index 9a85a42897d..10ede9bb045 100644 --- a/src/gallium/drivers/llvmpipe/lp_texture.c +++ b/src/gallium/drivers/llvmpipe/lp_texture.c @@ -103,6 +103,7 @@ llvmpipe_displaytarget_layout(struct llvmpipe_screen *screen, unsigned height = align(lpt->base.height0, TILE_SIZE); lpt->dt = winsys->displaytarget_create(winsys, + lpt->base.tex_usage, lpt->base.format, width, height, 16, @@ -250,6 +251,55 @@ llvmpipe_texture_unmap(struct pipe_texture *texture, } +static struct pipe_texture * +llvmpipe_texture_from_handle(struct pipe_screen *screen, + const struct pipe_texture *template, + struct winsys_handle *whandle) +{ + struct sw_winsys *winsys = llvmpipe_screen(screen)->winsys; + struct llvmpipe_texture *lpt = CALLOC_STRUCT(llvmpipe_texture); + if (!lpt) + return NULL; + + lpt->base = *template; + pipe_reference_init(&lpt->base.reference, 1); + lpt->base.screen = screen; + + lpt->pot = (util_is_power_of_two(template->width0) && + util_is_power_of_two(template->height0) && + util_is_power_of_two(template->depth0)); + + lpt->dt = winsys->displaytarget_from_handle(winsys, + template, + whandle, + &lpt->stride[0]); + if (!lpt->dt) + goto fail; + + return &lpt->base; + + fail: + FREE(lpt); + return NULL; +} + + +static boolean +llvmpipe_texture_get_handle(struct pipe_screen *screen, + struct pipe_texture *pt, + struct winsys_handle *whandle) +{ + struct sw_winsys *winsys = llvmpipe_screen(screen)->winsys; + struct llvmpipe_texture *lpt = llvmpipe_texture(pt); + + assert(lpt->dt); + if (!lpt->dt) + return FALSE; + + return winsys->displaytarget_get_handle(winsys, lpt->dt, whandle); +} + + static struct pipe_surface * llvmpipe_get_tex_surface(struct pipe_screen *screen, struct pipe_texture *pt, @@ -418,6 +468,7 @@ llvmpipe_init_screen_texture_funcs(struct pipe_screen *screen) { screen->texture_create = llvmpipe_texture_create; screen->texture_destroy = llvmpipe_texture_destroy; + screen->texture_get_handle = llvmpipe_texture_get_handle; screen->get_tex_surface = llvmpipe_get_tex_surface; screen->tex_surface_destroy = llvmpipe_tex_surface_destroy; diff --git a/src/gallium/drivers/softpipe/sp_screen.c b/src/gallium/drivers/softpipe/sp_screen.c index d62bfa3d633..757dc861284 100644 --- a/src/gallium/drivers/softpipe/sp_screen.c +++ b/src/gallium/drivers/softpipe/sp_screen.c @@ -173,8 +173,10 @@ softpipe_is_format_supported( struct pipe_screen *screen, break; } - if(tex_usage & PIPE_TEXTURE_USAGE_DISPLAY_TARGET) { - if(!winsys->is_displaytarget_format_supported(winsys, format)) + if(tex_usage & (PIPE_TEXTURE_USAGE_DISPLAY_TARGET | + PIPE_TEXTURE_USAGE_SCANOUT | + PIPE_TEXTURE_USAGE_SHARED)) { + if(!winsys->is_displaytarget_format_supported(winsys, tex_usage, format)) return FALSE; } diff --git a/src/gallium/drivers/softpipe/sp_texture.c b/src/gallium/drivers/softpipe/sp_texture.c index 2aff6118f41..f4983b7c8e8 100644 --- a/src/gallium/drivers/softpipe/sp_texture.c +++ b/src/gallium/drivers/softpipe/sp_texture.c @@ -91,6 +91,7 @@ softpipe_displaytarget_layout(struct pipe_screen *screen, /* Round up the surface size to a multiple of the tile size? */ spt->dt = winsys->displaytarget_create(winsys, + spt->base.tex_usage, spt->base.format, spt->base.width0, spt->base.height0, @@ -139,8 +140,6 @@ softpipe_texture_create(struct pipe_screen *screen, } - - static void softpipe_texture_destroy(struct pipe_texture *pt) { @@ -161,6 +160,55 @@ softpipe_texture_destroy(struct pipe_texture *pt) } +static struct pipe_texture * +softpipe_texture_from_handle(struct pipe_screen *screen, + const struct pipe_texture *template, + struct winsys_handle *whandle) +{ + struct sw_winsys *winsys = softpipe_screen(screen)->winsys; + struct softpipe_texture *spt = CALLOC_STRUCT(softpipe_texture); + if (!spt) + return NULL; + + spt->base = *template; + pipe_reference_init(&spt->base.reference, 1); + spt->base.screen = screen; + + spt->pot = (util_is_power_of_two(template->width0) && + util_is_power_of_two(template->height0) && + util_is_power_of_two(template->depth0)); + + spt->dt = winsys->displaytarget_from_handle(winsys, + template, + whandle, + &spt->stride[0]); + if (!spt->dt) + goto fail; + + return &spt->base; + + fail: + FREE(spt); + return NULL; +} + + +static boolean +softpipe_texture_get_handle(struct pipe_screen *screen, + struct pipe_texture *pt, + struct winsys_handle *whandle) +{ + struct sw_winsys *winsys = softpipe_screen(screen)->winsys; + struct softpipe_texture *spt = softpipe_texture(pt); + + assert(spt->dt); + if (!spt->dt) + return FALSE; + + return winsys->displaytarget_get_handle(winsys, spt->dt, whandle); +} + + /** * Get a pipe_surface "view" into a texture. */ @@ -461,6 +509,8 @@ softpipe_init_screen_texture_funcs(struct pipe_screen *screen) { screen->texture_create = softpipe_texture_create; screen->texture_destroy = softpipe_texture_destroy; + screen->texture_from_handle = softpipe_texture_from_handle; + screen->texture_get_handle = softpipe_texture_get_handle; screen->get_tex_surface = softpipe_get_tex_surface; screen->tex_surface_destroy = softpipe_tex_surface_destroy; diff --git a/src/gallium/include/state_tracker/sw_winsys.h b/src/gallium/include/state_tracker/sw_winsys.h index 0de98bbc1c9..9d202e48bfd 100644 --- a/src/gallium/include/state_tracker/sw_winsys.h +++ b/src/gallium/include/state_tracker/sw_winsys.h @@ -44,6 +44,7 @@ extern "C" { #endif +struct winsys_handle; struct pipe_screen; struct pipe_context; @@ -68,6 +69,7 @@ struct sw_winsys boolean (*is_displaytarget_format_supported)( struct sw_winsys *ws, + unsigned tex_usage, enum pipe_format format ); /** @@ -83,11 +85,29 @@ struct sw_winsys */ struct sw_displaytarget * (*displaytarget_create)( struct sw_winsys *ws, + unsigned tex_usage, enum pipe_format format, unsigned width, unsigned height, unsigned alignment, unsigned *stride ); + /** + * Used to implement texture_from_handle. + */ + struct sw_displaytarget * + (*displaytarget_from_handle)( struct sw_winsys *ws, + const struct pipe_texture *templat, + struct winsys_handle *whandle, + unsigned *stride ); + + /** + * Used to implement texture_get_handle. + */ + boolean + (*displaytarget_get_handle)( struct sw_winsys *ws, + struct sw_displaytarget *dt, + struct winsys_handle *whandle ); + /** * \param flags bitmask of PIPE_BUFFER_USAGE_x flags */ diff --git a/src/gallium/winsys/drm/Makefile b/src/gallium/winsys/drm/Makefile index fee01916432..a998aff931d 100644 --- a/src/gallium/winsys/drm/Makefile +++ b/src/gallium/winsys/drm/Makefile @@ -2,7 +2,7 @@ TOP = ../../../.. include $(TOP)/configs/current -SUBDIRS = $(GALLIUM_WINSYS_DRM_DIRS) +SUBDIRS = sw $(GALLIUM_WINSYS_DRM_DIRS) default install clean: @for dir in $(SUBDIRS) ; do \ diff --git a/src/gallium/winsys/drm/i965/dri/Makefile b/src/gallium/winsys/drm/i965/dri/Makefile index f7e81eed87b..56690769fc7 100644 --- a/src/gallium/winsys/drm/i965/dri/Makefile +++ b/src/gallium/winsys/drm/i965/dri/Makefile @@ -7,6 +7,7 @@ PIPE_DRIVERS = \ $(TOP)/src/gallium/state_trackers/dri/libdridrm.a \ $(TOP)/src/gallium/winsys/drm/i965/gem/libi965drm.a \ $(TOP)/src/gallium/drivers/trace/libtrace.a \ + $(TOP)/src/gallium/winsys/drm/sw/libswdrm.a \ $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ $(TOP)/src/gallium/drivers/identity/libidentity.a \ $(TOP)/src/gallium/drivers/i965/libi965.a diff --git a/src/gallium/winsys/drm/i965/gem/i965_drm_api.c b/src/gallium/winsys/drm/i965/gem/i965_drm_api.c index 21e82303f72..2ebc05f47e0 100644 --- a/src/gallium/winsys/drm/i965/gem/i965_drm_api.c +++ b/src/gallium/winsys/drm/i965/gem/i965_drm_api.c @@ -10,6 +10,8 @@ #include "trace/tr_drm.h" +#include "../../sw/sw_drm_api.h" + /* * Helper functions */ @@ -108,5 +110,13 @@ struct drm_api i965_libdrm_api = struct drm_api * drm_api_create() { - return trace_drm_create(&i965_libdrm_api); + struct drm_api *api; + + if (api == NULL && debug_get_bool_option("BRW_SOFTPIPE", FALSE)) + api = sw_drm_api_create(&i965_libdrm_api); + + if (api == NULL) + api = &i965_libdrm_api; + + return trace_drm_create(api); } diff --git a/src/gallium/winsys/drm/sw/Makefile b/src/gallium/winsys/drm/sw/Makefile new file mode 100644 index 00000000000..5f3c3ec325d --- /dev/null +++ b/src/gallium/winsys/drm/sw/Makefile @@ -0,0 +1,14 @@ +TOP = ../../../../.. +include $(TOP)/configs/current + +LIBNAME = swdrm + +C_SOURCES = \ + wrapper_sw_winsys.c \ + sw_drm_api.c + +LIBRARY_INCLUDES = + +LIBRARY_DEFINES = + +include ../../../Makefile.template diff --git a/src/gallium/winsys/drm/sw/sw_drm_api.c b/src/gallium/winsys/drm/sw/sw_drm_api.c new file mode 100644 index 00000000000..0fd2163913e --- /dev/null +++ b/src/gallium/winsys/drm/sw/sw_drm_api.c @@ -0,0 +1,97 @@ +/********************************************************** + * Copyright 2010 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + **********************************************************/ + + +#include "util/u_memory.h" +#include "softpipe/sp_public.h" +#include "state_tracker/drm_api.h" +#include "wrapper_sw_winsys.h" +#include "sw_drm_api.h" + + +/* + * Defines + */ + + +struct sw_drm_api +{ + struct drm_api base; + struct drm_api *api; + struct sw_winsys *sw; +}; + +static INLINE struct sw_drm_api * +sw_drm_api(struct drm_api *api) +{ + return (struct sw_drm_api *)api; +} + + +/* + * Exported functions + */ + + +static struct pipe_screen * +sw_drm_create_screen(struct drm_api *_api, int drmFD, + struct drm_create_screen_arg *arg) +{ + struct sw_drm_api *swapi = sw_drm_api(_api); + struct drm_api *api = swapi->api; + struct sw_winsys *sww; + struct pipe_screen *screen; + + screen = api->create_screen(api, drmFD, arg); + + sww = wrapper_sw_winsys_warp_pipe_screen(screen); + + return softpipe_create_screen(sww); +} + +static void +sw_drm_destroy(struct drm_api *api) +{ + struct sw_drm_api *swapi = sw_drm_api(api); + if (swapi->api->destroy) + swapi->api->destroy(swapi->api); + + FREE(swapi); +} + +struct drm_api * +sw_drm_api_create(struct drm_api *api) +{ + struct sw_drm_api *swapi = CALLOC_STRUCT(sw_drm_api); + + swapi->base.name = "sw"; + swapi->base.driver_name = api->driver_name; + swapi->base.create_screen = sw_drm_create_screen; + swapi->base.destroy = sw_drm_destroy; + + swapi->api = api; + + return &swapi->base; +} diff --git a/src/gallium/winsys/drm/sw/sw_drm_api.h b/src/gallium/winsys/drm/sw/sw_drm_api.h new file mode 100644 index 00000000000..ce90a04ae0c --- /dev/null +++ b/src/gallium/winsys/drm/sw/sw_drm_api.h @@ -0,0 +1,34 @@ +/********************************************************** + * Copyright 2010 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + **********************************************************/ + + +#ifndef SW_DRM_API_H +#define SW_DRM_API_H + +struct drm_api; + +struct drm_api * sw_drm_api_create(struct drm_api *api); + +#endif diff --git a/src/gallium/winsys/drm/sw/wrapper_sw_winsys.c b/src/gallium/winsys/drm/sw/wrapper_sw_winsys.c new file mode 100644 index 00000000000..459b1c1e2a3 --- /dev/null +++ b/src/gallium/winsys/drm/sw/wrapper_sw_winsys.c @@ -0,0 +1,282 @@ +/********************************************************** + * Copyright 2010 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + **********************************************************/ + + +#include "wrapper_sw_winsys.h" + +#include "pipe/p_format.h" +#include "pipe/p_state.h" + +#include "state_tracker/sw_winsys.h" + +#include "util/u_memory.h" +#include "util/u_inlines.h" + +/* + * This code wraps a pipe_screen and exposes a sw_winsys interface for use + * with software resterizers. This code is used by the DRM based winsys to + * allow access to the drm driver. + * + * We must borrow the whole stack because only the pipe screen knows how + * to decode the content of a buffer. Or how to create a buffer that + * can still be used by drivers using real hardware (as the case is + * with software st/xorg but hw st/dri). + * + * We also need a pipe context for the transfers. + */ + +struct wrapper_sw_winsys +{ + struct sw_winsys base; + struct pipe_screen *screen; + struct pipe_context *pipe; +}; + +struct wrapper_sw_displaytarget +{ + struct wrapper_sw_winsys *winsys; + struct pipe_texture *tex; + struct pipe_transfer *transfer; + + unsigned width; + unsigned height; + unsigned map_count; + unsigned stride; /**< because we give stride at create */ + void *ptr; +}; + +static INLINE struct wrapper_sw_winsys * +wrapper_sw_winsys(struct sw_winsys *ws) +{ + return (struct wrapper_sw_winsys *)ws; +} + +static INLINE struct wrapper_sw_displaytarget * +wrapper_sw_displaytarget(struct sw_displaytarget *dt) +{ + return (struct wrapper_sw_displaytarget *)dt; +} + + +/* + * Functions + */ + + +static boolean +wsw_dt_get_stride(struct wrapper_sw_displaytarget *wdt, unsigned *stride) +{ + struct pipe_context *pipe = wdt->winsys->pipe; + struct pipe_texture *tex = wdt->tex; + struct pipe_transfer *tr; + + tr = pipe->get_tex_transfer(pipe, tex, 0, 0, 0, + PIPE_TRANSFER_READ_WRITE, + 0, 0, wdt->width, wdt->height); + if (!tr) + return FALSE; + + *stride = tr->stride; + wdt->stride = tr->stride; + + pipe->tex_transfer_destroy(pipe, tr); + + return TRUE; +} + +static struct sw_displaytarget * +wsw_dt_wrap_texture(struct wrapper_sw_winsys *wsw, + struct pipe_texture *tex, unsigned *stride) +{ + struct wrapper_sw_displaytarget *wdt = CALLOC_STRUCT(wrapper_sw_displaytarget); + if (!wdt) + goto err_unref; + + wdt->tex = tex; + wdt->winsys = wsw; + + if (!wsw_dt_get_stride(wdt, stride)) + goto err_free; + + return (struct sw_displaytarget *)wdt; + +err_free: + FREE(wdt); +err_unref: + pipe_texture_reference(&tex, NULL); + return NULL; +} + +static struct sw_displaytarget * +wsw_dt_create(struct sw_winsys *ws, + unsigned tex_usage, + enum pipe_format format, + unsigned width, unsigned height, + unsigned alignment, + unsigned *stride) +{ + struct wrapper_sw_winsys *wsw = wrapper_sw_winsys(ws); + struct pipe_texture templ; + struct pipe_texture *tex; + + /* + * XXX Why don't we just get the template. + */ + memset(&templ, 0, sizeof(templ)); + templ.width0 = width; + templ.height0 = height; + templ.format = format; + templ.tex_usage = tex_usage; + + /* XXX alignment: we can't do anything about this */ + + tex = wsw->screen->texture_create(wsw->screen, &templ); + if (!tex) + return NULL; + + return wsw_dt_wrap_texture(wsw, tex, stride); +} + +static struct sw_displaytarget * +wsw_dt_from_handle(struct sw_winsys *ws, + const struct pipe_texture *templ, + struct winsys_handle *whandle, + unsigned *stride) +{ + struct wrapper_sw_winsys *wsw = wrapper_sw_winsys(ws); + struct pipe_texture *tex; + + tex = wsw->screen->texture_from_handle(wsw->screen, templ, whandle); + if (!tex) + return NULL; + + return wsw_dt_wrap_texture(wsw, tex, stride); +} + +static void * +wsw_dt_map(struct sw_winsys *ws, + struct sw_displaytarget *dt, + unsigned flags) +{ + struct wrapper_sw_displaytarget *wdt = wrapper_sw_displaytarget(dt); + struct pipe_context *pipe = wdt->winsys->pipe; + struct pipe_texture *tex = wdt->tex; + struct pipe_transfer *tr; + void *ptr; + + if (!wdt->map_count) { + + assert(!wdt->transfer); + + tr = pipe->get_tex_transfer(pipe, tex, 0, 0, 0, + PIPE_TRANSFER_READ_WRITE, + 0, 0, wdt->width, wdt->height); + if (!tr) + return NULL; + + ptr = pipe->transfer_map(pipe, tr); + if (!ptr) + goto err; + + wdt->transfer = tr; + wdt->ptr = ptr; + + /* XXX Handle this case */ + assert(tr->stride == wdt->stride); + } + + wdt->map_count++; + + return wdt->ptr; + +err: + pipe->tex_transfer_destroy(pipe, tr); + return NULL; +} + +static void +wsw_dt_unmap(struct sw_winsys *ws, + struct sw_displaytarget *dt) +{ + struct wrapper_sw_displaytarget *wdt = wrapper_sw_displaytarget(dt); + struct pipe_context *pipe = wdt->winsys->pipe; + + assert(wdt->transfer); + + wdt->map_count--; + + if (wdt->map_count) + return; + + pipe->transfer_unmap(pipe, wdt->transfer); + pipe->tex_transfer_destroy(pipe, wdt->transfer); + wdt->transfer = NULL; +} + +static void +wsw_dt_destroy(struct sw_winsys *ws, + struct sw_displaytarget *dt) +{ + struct wrapper_sw_displaytarget *wdt = wrapper_sw_displaytarget(dt); + + pipe_texture_reference(&wdt->tex, NULL); + + FREE(wdt); +} + +static void +wsw_destroy(struct sw_winsys *ws) +{ + struct wrapper_sw_winsys *wsw = wrapper_sw_winsys(ws); + + wsw->pipe->destroy(wsw->pipe); + wsw->screen->destroy(wsw->screen); + + FREE(wsw); +} + +struct sw_winsys * +wrapper_sw_winsys_warp_pipe_screen(struct pipe_screen *screen) +{ + struct wrapper_sw_winsys *wsw = CALLOC_STRUCT(wrapper_sw_winsys); + + wsw->base.displaytarget_create = wsw_dt_create; + wsw->base.displaytarget_from_handle = wsw_dt_from_handle; + wsw->base.displaytarget_map = wsw_dt_map; + wsw->base.displaytarget_unmap = wsw_dt_unmap; + wsw->base.displaytarget_destroy = wsw_dt_destroy; + wsw->base.destroy = wsw_destroy; + + wsw->screen = screen; + wsw->pipe = screen->context_create(screen, NULL); + if (!wsw->pipe) + goto err; + + return &wsw->base; + +err: + FREE(wsw); + return NULL; +} diff --git a/src/gallium/winsys/drm/sw/wrapper_sw_winsys.h b/src/gallium/winsys/drm/sw/wrapper_sw_winsys.h new file mode 100644 index 00000000000..b5c25a3c50f --- /dev/null +++ b/src/gallium/winsys/drm/sw/wrapper_sw_winsys.h @@ -0,0 +1,35 @@ +/********************************************************** + * Copyright 2010 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + **********************************************************/ + + +#ifndef WRAPPER_SW_WINSYS +#define WRAPPER_SW_WINSYS + +struct sw_winsys; +struct pipe_screen; + +struct sw_winsys *wrapper_sw_winsys_warp_pipe_screen(struct pipe_screen *screen); + +#endif diff --git a/src/gallium/winsys/gdi/gdi_sw_winsys.c b/src/gallium/winsys/gdi/gdi_sw_winsys.c index f5c0b7d56ec..4dba4b577b8 100644 --- a/src/gallium/winsys/gdi/gdi_sw_winsys.c +++ b/src/gallium/winsys/gdi/gdi_sw_winsys.c @@ -71,6 +71,7 @@ gdi_sw_displaytarget( struct sw_displaytarget *buf ) static boolean gdi_sw_is_displaytarget_format_supported( struct sw_winsys *ws, + unsigned tex_usage, enum pipe_format format ) { switch(format) { @@ -119,6 +120,7 @@ gdi_sw_displaytarget_destroy(struct sw_winsys *winsys, static struct sw_displaytarget * gdi_sw_displaytarget_create(struct sw_winsys *winsys, + unsigned tex_usage, enum pipe_format format, unsigned width, unsigned height, unsigned alignment, @@ -168,6 +170,27 @@ no_gdt: } +static struct sw_displaytarget * +gdi_sw_displaytarget_from_handle(struct sw_winsys *winsys, + const struct pipe_texture *templet, + struct winsys_handle *whandle, + unsigned *stride) +{ + assert(0); + return NULL; +} + + +static boolean +gdi_sw_displaytarget_get_handle(struct sw_winsys *winsys, + struct sw_displaytarget *dt, + struct winsys_handle *whandle) +{ + assert(0); + return FALSE; +} + + void gdi_sw_display( struct sw_winsys *winsys, struct sw_displaytarget *dt, @@ -212,6 +235,8 @@ gdi_create_sw_winsys(void) winsys->destroy = gdi_sw_destroy; winsys->is_displaytarget_format_supported = gdi_sw_is_displaytarget_format_supported; winsys->displaytarget_create = gdi_sw_displaytarget_create; + winsys->displaytarget_from_handle = gdi_sw_displaytarget_from_handle; + winsys->displaytarget_get_handle = gdi_sw_displaytarget_get_handle; winsys->displaytarget_map = gdi_sw_displaytarget_map; winsys->displaytarget_unmap = gdi_sw_displaytarget_unmap; winsys->displaytarget_display = gdi_sw_displaytarget_display; diff --git a/src/gallium/winsys/null/null_sw_winsys.c b/src/gallium/winsys/null/null_sw_winsys.c index d961d34860e..5027e57b303 100644 --- a/src/gallium/winsys/null/null_sw_winsys.c +++ b/src/gallium/winsys/null/null_sw_winsys.c @@ -44,6 +44,7 @@ static boolean null_sw_is_displaytarget_format_supported(struct sw_winsys *ws, + unsigned tex_usage, enum pipe_format format ) { return FALSE; @@ -78,6 +79,7 @@ null_sw_displaytarget_destroy(struct sw_winsys *winsys, static struct sw_displaytarget * null_sw_displaytarget_create(struct sw_winsys *winsys, + unsigned tex_usage, enum pipe_format format, unsigned width, unsigned height, unsigned alignment, @@ -87,6 +89,26 @@ null_sw_displaytarget_create(struct sw_winsys *winsys, } +static struct sw_displaytarget * +null_sw_displaytarget_from_handle(struct sw_winsys *winsys, + const struct pipe_texture *templet, + struct winsys_handle *whandle, + unsigned *stride) +{ + return NULL; +} + + +static boolean +null_sw_displaytarget_get_handle(struct sw_winsys *winsys, + struct sw_displaytarget *dt, + struct winsys_handle *whandle) +{ + assert(0); + return FALSE; +} + + static void null_sw_displaytarget_display(struct sw_winsys *winsys, struct sw_displaytarget *dt, @@ -115,6 +137,8 @@ null_sw_create(void) winsys->destroy = null_sw_destroy; winsys->is_displaytarget_format_supported = null_sw_is_displaytarget_format_supported; winsys->displaytarget_create = null_sw_displaytarget_create; + winsys->displaytarget_from_handle = null_sw_displaytarget_from_handle; + winsys->displaytarget_get_handle = null_sw_displaytarget_get_handle; winsys->displaytarget_map = null_sw_displaytarget_map; winsys->displaytarget_unmap = null_sw_displaytarget_unmap; winsys->displaytarget_display = null_sw_displaytarget_display; diff --git a/src/gallium/winsys/xlib/xlib_sw_winsys.c b/src/gallium/winsys/xlib/xlib_sw_winsys.c index cecfa4a53d4..54789d7a87c 100644 --- a/src/gallium/winsys/xlib/xlib_sw_winsys.c +++ b/src/gallium/winsys/xlib/xlib_sw_winsys.c @@ -208,6 +208,7 @@ alloc_ximage(struct xm_displaytarget *xm_dt, static boolean xm_is_displaytarget_format_supported( struct sw_winsys *ws, + unsigned tex_usage, enum pipe_format format ) { /* TODO: check visuals or other sensible thing here */ @@ -358,6 +359,7 @@ xm_displaytarget_display(struct sw_winsys *ws, static struct sw_displaytarget * xm_displaytarget_create(struct sw_winsys *winsys, + unsigned tex_usage, enum pipe_format format, unsigned width, unsigned height, unsigned alignment, @@ -406,6 +408,27 @@ no_xm_dt: } +static struct sw_displaytarget * +xm_displaytarget_from_handle(struct sw_winsys *winsys, + const struct pipe_texture *templet, + struct winsys_handle *whandle, + unsigned *stride) +{ + assert(0); + return NULL; +} + + +static boolean +xm_displaytarget_get_handle(struct sw_winsys *winsys, + struct sw_displaytarget *dt, + struct winsys_handle *whandle) +{ + assert(0); + return FALSE; +} + + static void xm_destroy( struct sw_winsys *ws ) { @@ -428,6 +451,8 @@ xlib_create_sw_winsys( Display *display ) ws->base.is_displaytarget_format_supported = xm_is_displaytarget_format_supported; ws->base.displaytarget_create = xm_displaytarget_create; + ws->base.displaytarget_from_handle = xm_displaytarget_from_handle; + ws->base.displaytarget_get_handle = xm_displaytarget_get_handle; ws->base.displaytarget_map = xm_displaytarget_map; ws->base.displaytarget_unmap = xm_displaytarget_unmap; ws->base.displaytarget_destroy = xm_displaytarget_destroy; -- cgit v1.2.3 From b586774016e2f5dd1541cd3b0c93f8ea69fe9e9a Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Tue, 16 Mar 2010 01:17:33 +0000 Subject: llvmpipe: Fix rebase typo --- src/gallium/drivers/llvmpipe/lp_texture.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/llvmpipe/lp_texture.c b/src/gallium/drivers/llvmpipe/lp_texture.c index 10ede9bb045..93ad789c35d 100644 --- a/src/gallium/drivers/llvmpipe/lp_texture.c +++ b/src/gallium/drivers/llvmpipe/lp_texture.c @@ -265,10 +265,6 @@ llvmpipe_texture_from_handle(struct pipe_screen *screen, pipe_reference_init(&lpt->base.reference, 1); lpt->base.screen = screen; - lpt->pot = (util_is_power_of_two(template->width0) && - util_is_power_of_two(template->height0) && - util_is_power_of_two(template->depth0)); - lpt->dt = winsys->displaytarget_from_handle(winsys, template, whandle, -- cgit v1.2.3 From 95d43bccde9ba5c0727bb2b9e52d050dacfa0cfa Mon Sep 17 00:00:00 2001 From: Ben Skeggs Date: Tue, 16 Mar 2010 13:18:39 +1000 Subject: nv50: fix texturing from >=4GiB mark --- src/gallium/drivers/nv50/nv50_tex.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/nv50/nv50_tex.c b/src/gallium/drivers/nv50/nv50_tex.c index 4c48b12cd87..eb64f6cee48 100644 --- a/src/gallium/drivers/nv50/nv50_tex.c +++ b/src/gallium/drivers/nv50/nv50_tex.c @@ -137,7 +137,8 @@ nv50_tex_construct(struct nv50_context *nv50, struct nouveau_stateobj *so, so_data (so, nv50_tex_format_list[i].hw); so_reloc(so, mt->base.bo, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_LOW | NOUVEAU_BO_RD, 0, 0); - so_data (so, mode); + so_reloc(so, mt->base.bo, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_HIGH | + NOUVEAU_BO_RD | NOUVEAU_BO_OR, mode, mode); so_data (so, 0x00300000); so_data (so, mt->base.base.width0 | (1 << 31)); so_data (so, (mt->base.base.last_level << 28) | -- cgit v1.2.3 From e0ce4a4a0994211ead8e5a77cccdd2a084e8a288 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Tue, 16 Mar 2010 15:48:03 +0800 Subject: i965g: Fix use of an uninitialized variable. --- src/gallium/winsys/drm/i965/gem/i965_drm_api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/gallium') diff --git a/src/gallium/winsys/drm/i965/gem/i965_drm_api.c b/src/gallium/winsys/drm/i965/gem/i965_drm_api.c index 2ebc05f47e0..c644eedcb31 100644 --- a/src/gallium/winsys/drm/i965/gem/i965_drm_api.c +++ b/src/gallium/winsys/drm/i965/gem/i965_drm_api.c @@ -110,7 +110,7 @@ struct drm_api i965_libdrm_api = struct drm_api * drm_api_create() { - struct drm_api *api; + struct drm_api *api = NULL; if (api == NULL && debug_get_bool_option("BRW_SOFTPIPE", FALSE)) api = sw_drm_api_create(&i965_libdrm_api); -- cgit v1.2.3 From e4b8a307b25146202b1fb64339b307bde5ec3b30 Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Tue, 16 Mar 2010 10:58:33 +0100 Subject: gallium/docs: Create a separate section for Sampler Views. --- src/gallium/docs/source/context.rst | 52 +++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 17 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/docs/source/context.rst b/src/gallium/docs/source/context.rst index ef3e4639314..1f022570dbb 100644 --- a/src/gallium/docs/source/context.rst +++ b/src/gallium/docs/source/context.rst @@ -41,23 +41,6 @@ buffers, surfaces) are bound to the driver. * ``set_framebuffer_state`` -* ``set_fragment_sampler_views`` binds an array of sampler views to - fragment shader stage. Every binding point acquires a reference - to a respective sampler view and releases a reference to the previous - sampler view. - -* ``set_vertex_sampler_views`` binds an array of sampler views to vertex - shader stage. Every binding point acquires a reference to a respective - sampler view and releases a reference to the previous sampler view. - -* ``create_sampler_view`` creates a new sampler view. texture is associated - with the sampler view which results in sampler view holding a reference - to the texture. Format specified in template must be compatible - with texture format. - -* ``sampler_view_destroy`` destroys a sampler view and releases its reference - to associated texture. - * ``set_vertex_buffers`` @@ -79,6 +62,41 @@ objects. They all follow simple, one-method binding calls, e.g. * ``set_viewport_state`` +Sampler Views +^^^^^^^^^^^^^ + +These are the means to bind textures to shader stages. To create one, specify +its format, swizzle and LOD range in sampler view template. + +If texture format is different than template format, it is said the texture +is being cast to another format. Casting can be done only between compatible +formats, that is formats that have matching component order and sizes. + +Swizzle fields specify they way in which fetched texel components are placed +in the result register. For example, swizzle_r specifies what is going to be +placed in destination register x (AKA r). + +first_level and last_level fields of sampler view template specify the LOD +range the texture is going to be constrained to. + +* ``set_fragment_sampler_views`` binds an array of sampler views to + fragment shader stage. Every binding point acquires a reference + to a respective sampler view and releases a reference to the previous + sampler view. + +* ``set_vertex_sampler_views`` binds an array of sampler views to vertex + shader stage. Every binding point acquires a reference to a respective + sampler view and releases a reference to the previous sampler view. + +* ``create_sampler_view`` creates a new sampler view. texture is associated + with the sampler view which results in sampler view holding a reference + to the texture. Format specified in template must be compatible + with texture format. + +* ``sampler_view_destroy`` destroys a sampler view and releases its reference + to associated texture. + + Clearing ^^^^^^^^ -- cgit v1.2.3 From 8f55a95178069d5e8b18647e6b675fc403d68073 Mon Sep 17 00:00:00 2001 From: Roland Scheidegger Date: Mon, 15 Mar 2010 21:55:08 +0100 Subject: gallium: change remaining util functions to use cso sampler views changes arguments of util_blit_pixels_tex and util_gen_mipmap to struct pipe_sampler_view * instead of struct pipe_texture *. --- src/gallium/auxiliary/util/u_blit.c | 22 ++++++++++++---------- src/gallium/auxiliary/util/u_blit.h | 2 +- src/gallium/auxiliary/util/u_gen_mipmap.c | 13 +++++++------ src/gallium/auxiliary/util/u_gen_mipmap.h | 2 +- src/mesa/state_tracker/st_cb_texture.c | 18 +++++++++++++++--- src/mesa/state_tracker/st_gen_mipmap.c | 11 ++++++----- 6 files changed, 42 insertions(+), 26 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/auxiliary/util/u_blit.c b/src/gallium/auxiliary/util/u_blit.c index 4d9168face3..cd95f85b63b 100644 --- a/src/gallium/auxiliary/util/u_blit.c +++ b/src/gallium/auxiliary/util/u_blit.c @@ -555,21 +555,23 @@ void util_blit_flush( struct blit_state *ctx ) */ void util_blit_pixels_tex(struct blit_state *ctx, - struct pipe_texture *tex, - int srcX0, int srcY0, - int srcX1, int srcY1, - struct pipe_surface *dst, - int dstX0, int dstY0, - int dstX1, int dstY1, - float z, uint filter) + struct pipe_sampler_view *src_sampler_view, + int srcX0, int srcY0, + int srcX1, int srcY1, + struct pipe_surface *dst, + int dstX0, int dstY0, + int dstX1, int dstY1, + float z, uint filter) { struct pipe_framebuffer_state fb; float s0, t0, s1, t1; unsigned offset; + struct pipe_texture *tex = src_sampler_view->texture; assert(filter == PIPE_TEX_MIPFILTER_NEAREST || filter == PIPE_TEX_MIPFILTER_LINEAR); + assert(tex); assert(tex->width0 != 0); assert(tex->height0 != 0); @@ -588,7 +590,7 @@ util_blit_pixels_tex(struct blit_state *ctx, cso_save_depth_stencil_alpha(ctx->cso); cso_save_rasterizer(ctx->cso); cso_save_samplers(ctx->cso); - cso_save_sampler_textures(ctx->cso); + cso_save_fragment_sampler_views(ctx->cso); cso_save_framebuffer(ctx->cso); cso_save_fragment_shader(ctx->cso); cso_save_vertex_shader(ctx->cso); @@ -620,7 +622,7 @@ util_blit_pixels_tex(struct blit_state *ctx, cso_set_viewport(ctx->cso, &ctx->viewport); /* texture */ - cso_set_sampler_textures(ctx->cso, 1, &tex); + cso_set_fragment_sampler_views(ctx->cso, 1, &src_sampler_view); /* shaders */ cso_set_fragment_shader_handle(ctx->cso, ctx->fs[TGSI_WRITEMASK_XYZW]); @@ -654,7 +656,7 @@ util_blit_pixels_tex(struct blit_state *ctx, cso_restore_depth_stencil_alpha(ctx->cso); cso_restore_rasterizer(ctx->cso); cso_restore_samplers(ctx->cso); - cso_restore_sampler_textures(ctx->cso); + cso_restore_fragment_sampler_views(ctx->cso); cso_restore_framebuffer(ctx->cso); cso_restore_fragment_shader(ctx->cso); cso_restore_vertex_shader(ctx->cso); diff --git a/src/gallium/auxiliary/util/u_blit.h b/src/gallium/auxiliary/util/u_blit.h index 2d8cdd25fb9..1ebe65b4558 100644 --- a/src/gallium/auxiliary/util/u_blit.h +++ b/src/gallium/auxiliary/util/u_blit.h @@ -75,7 +75,7 @@ util_blit_pixels_writemask(struct blit_state *ctx, extern void util_blit_pixels_tex(struct blit_state *ctx, - struct pipe_texture *tex, + struct pipe_sampler_view *src_sampler_view, int srcX0, int srcY0, int srcX1, int srcY1, struct pipe_surface *dst, diff --git a/src/gallium/auxiliary/util/u_gen_mipmap.c b/src/gallium/auxiliary/util/u_gen_mipmap.c index 5c51b53d7bd..61d64cff6d4 100644 --- a/src/gallium/auxiliary/util/u_gen_mipmap.c +++ b/src/gallium/auxiliary/util/u_gen_mipmap.c @@ -1460,7 +1460,7 @@ void util_gen_mipmap_flush( struct gen_mipmap_state *ctx ) * Generate mipmap images. It's assumed all needed texture memory is * already allocated. * - * \param pt the texture to generate mipmap levels for + * \param psv the sampler view to the texture to generate mipmap levels for * \param face which cube face to generate mipmaps for (0 for non-cube maps) * \param baseLevel the first mipmap level to use as a src * \param lastLevel the last mipmap level to generate @@ -1469,12 +1469,13 @@ void util_gen_mipmap_flush( struct gen_mipmap_state *ctx ) */ void util_gen_mipmap(struct gen_mipmap_state *ctx, - struct pipe_texture *pt, + struct pipe_sampler_view *psv, uint face, uint baseLevel, uint lastLevel, uint filter) { struct pipe_context *pipe = ctx->pipe; struct pipe_screen *screen = pipe->screen; struct pipe_framebuffer_state fb; + struct pipe_texture *pt = psv->texture; void *fs = (pt->target == PIPE_TEXTURE_CUBE) ? ctx->fsCube : ctx->fs2d; uint dstLevel; uint zslice = 0; @@ -1492,7 +1493,7 @@ util_gen_mipmap(struct gen_mipmap_state *ctx, filter == PIPE_TEX_FILTER_NEAREST); /* check if we can render in the texture's format */ - if (!screen->is_format_supported(screen, pt->format, PIPE_TEXTURE_2D, + if (!screen->is_format_supported(screen, psv->format, PIPE_TEXTURE_2D, PIPE_TEXTURE_USAGE_RENDER_TARGET, 0)) { fallback_gen_mipmap(ctx, pt, face, baseLevel, lastLevel); return; @@ -1503,7 +1504,7 @@ util_gen_mipmap(struct gen_mipmap_state *ctx, cso_save_depth_stencil_alpha(ctx->cso); cso_save_rasterizer(ctx->cso); cso_save_samplers(ctx->cso); - cso_save_sampler_textures(ctx->cso); + cso_save_fragment_sampler_views(ctx->cso); cso_save_framebuffer(ctx->cso); cso_save_fragment_shader(ctx->cso); cso_save_vertex_shader(ctx->cso); @@ -1572,7 +1573,7 @@ util_gen_mipmap(struct gen_mipmap_state *ctx, cso_single_sampler(ctx->cso, 0, &ctx->sampler); cso_single_sampler_done(ctx->cso); - cso_set_sampler_textures(ctx->cso, 1, &pt); + cso_set_fragment_sampler_views(ctx->cso, 1, &psv); /* quad coords in clip coords */ offset = set_vertex_data(ctx, @@ -1597,7 +1598,7 @@ util_gen_mipmap(struct gen_mipmap_state *ctx, cso_restore_depth_stencil_alpha(ctx->cso); cso_restore_rasterizer(ctx->cso); cso_restore_samplers(ctx->cso); - cso_restore_sampler_textures(ctx->cso); + cso_restore_fragment_sampler_views(ctx->cso); cso_restore_framebuffer(ctx->cso); cso_restore_fragment_shader(ctx->cso); cso_restore_vertex_shader(ctx->cso); diff --git a/src/gallium/auxiliary/util/u_gen_mipmap.h b/src/gallium/auxiliary/util/u_gen_mipmap.h index 54608f9466d..35ac9daeaa2 100644 --- a/src/gallium/auxiliary/util/u_gen_mipmap.h +++ b/src/gallium/auxiliary/util/u_gen_mipmap.h @@ -59,7 +59,7 @@ util_gen_mipmap_flush( struct gen_mipmap_state *ctx ); extern void util_gen_mipmap(struct gen_mipmap_state *ctx, - struct pipe_texture *pt, + struct pipe_sampler_view *psv, uint face, uint baseLevel, uint lastLevel, uint filter); diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index 0c518a7e031..6ed1c60a51e 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -63,6 +63,7 @@ #include "util/u_blit.h" #include "util/u_format.h" #include "util/u_surface.h" +#include "util/u_sampler.h" #include "util/u_math.h" @@ -380,6 +381,8 @@ compress_with_blit(GLcontext * ctx, gl_format mesa_format; struct pipe_texture templ; struct pipe_texture *src_tex; + struct pipe_sampler_view view_templ; + struct pipe_sampler_view *src_view; struct pipe_surface *dst_surface; struct pipe_transfer *tex_xfer; void *map; @@ -441,9 +444,16 @@ compress_with_blit(GLcontext * ctx, pipe->transfer_unmap(pipe, tex_xfer); pipe->tex_transfer_destroy(pipe, tex_xfer); + /* Create temporary sampler view */ + u_sampler_view_default_template(&view_templ, + src_tex, + src_tex->format); + src_view = pipe->create_sampler_view(pipe, src_tex, &view_templ); + + /* copy / compress image */ util_blit_pixels_tex(ctx->st->blit, - src_tex, /* pipe_texture (src) */ + src_view, /* sampler view (src) */ 0, 0, /* src x0, y0 */ width, height, /* src x1, y1 */ dst_surface, /* pipe_surface (dst) */ @@ -455,6 +465,7 @@ compress_with_blit(GLcontext * ctx, pipe_surface_reference(&dst_surface, NULL); pipe_texture_reference(&src_tex, NULL); + pipe_sampler_view_reference(&src_view, NULL); return GL_TRUE; } @@ -817,6 +828,8 @@ decompress_with_blit(GLcontext * ctx, GLenum target, GLint level, struct pipe_context *pipe = ctx->st->pipe; struct pipe_screen *screen = pipe->screen; struct st_texture_image *stImage = st_texture_image(texImage); + struct st_texture_object *stObj = st_texture_object(texObj); + struct pipe_sampler_view *src_view = st_get_stobj_sampler_view(stObj); const GLuint width = texImage->Width; const GLuint height = texImage->Height; struct pipe_surface *dst_surface; @@ -833,7 +846,7 @@ decompress_with_blit(GLcontext * ctx, GLenum target, GLint level, /* blit/render/decompress */ util_blit_pixels_tex(ctx->st->blit, - stImage->pt, /* pipe_texture (src) */ + src_view, /* pipe_texture (src) */ 0, 0, /* src x0, y0 */ width, height, /* src x1, y1 */ dst_surface, /* pipe_surface (dst) */ @@ -1457,7 +1470,6 @@ st_copy_texsubimage(GLcontext *ctx, &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; struct gl_texture_object *texObj = _mesa_select_tex_object(ctx, texUnit, target); - struct st_texture_object *stObj = st_texture_object(texObj); struct gl_texture_image *texImage = _mesa_select_tex_image(ctx, texObj, target, level); struct st_texture_image *stImage = st_texture_image(texImage); diff --git a/src/mesa/state_tracker/st_gen_mipmap.c b/src/mesa/state_tracker/st_gen_mipmap.c index b2521433c87..97f6903f9e2 100644 --- a/src/mesa/state_tracker/st_gen_mipmap.c +++ b/src/mesa/state_tracker/st_gen_mipmap.c @@ -79,22 +79,23 @@ st_destroy_generate_mipmap(struct st_context *st) static boolean st_render_mipmap(struct st_context *st, GLenum target, - struct pipe_texture *pt, + struct st_texture_object *stObj, uint baseLevel, uint lastLevel) { struct pipe_context *pipe = st->pipe; struct pipe_screen *screen = pipe->screen; + struct pipe_sampler_view *psv = st_get_stobj_sampler_view(stObj); const uint face = _mesa_tex_target_to_face(target); assert(target != GL_TEXTURE_3D); /* not done yet */ /* check if we can render in the texture's format */ - if (!screen->is_format_supported(screen, pt->format, pt->target, + if (!screen->is_format_supported(screen, psv->format, psv->texture->target, PIPE_TEXTURE_USAGE_RENDER_TARGET, 0)) { return FALSE; } - util_gen_mipmap(st->gen_mipmap, pt, face, baseLevel, lastLevel, + util_gen_mipmap(st->gen_mipmap, psv, face, baseLevel, lastLevel, PIPE_TEX_FILTER_LINEAR); return TRUE; @@ -211,6 +212,7 @@ st_generate_mipmap(GLcontext *ctx, GLenum target, struct gl_texture_object *texObj) { struct st_context *st = ctx->st; + struct st_texture_object *stObj = st_texture_object(texObj); struct pipe_texture *pt = st_get_texobj_texture(texObj); const uint baseLevel = texObj->BaseLevel; uint lastLevel; @@ -229,7 +231,6 @@ st_generate_mipmap(GLcontext *ctx, GLenum target, /* The current gallium texture doesn't have space for all the * mipmap levels we need to generate. So allocate a new texture. */ - struct st_texture_object *stObj = st_texture_object(texObj); struct pipe_texture *oldTex = stObj->pt; GLboolean needFlush; @@ -264,7 +265,7 @@ st_generate_mipmap(GLcontext *ctx, GLenum target, /* Recall that the Mesa BaseLevel image is stored in the gallium * texture's level[0] position. So pass baseLevel=0 here. */ - if (!st_render_mipmap(st, target, pt, 0, lastLevel)) { + if (!st_render_mipmap(st, target, stObj, 0, lastLevel)) { fallback_generate_mipmap(ctx, target, texObj); } -- cgit v1.2.3 From d731190ec3a0401376e877d5f2e6a988a2eb9eb9 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Tue, 16 Mar 2010 13:46:10 +0000 Subject: gallium: Silence warning. --- src/gallium/include/state_tracker/sw_winsys.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src/gallium') diff --git a/src/gallium/include/state_tracker/sw_winsys.h b/src/gallium/include/state_tracker/sw_winsys.h index 9d202e48bfd..a87650dc77d 100644 --- a/src/gallium/include/state_tracker/sw_winsys.h +++ b/src/gallium/include/state_tracker/sw_winsys.h @@ -47,6 +47,7 @@ extern "C" { struct winsys_handle; struct pipe_screen; struct pipe_context; +struct pipe_texture; /** -- cgit v1.2.3 From 759c1c287caddac2f9d398de8c626ca435ecb42a Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Tue, 16 Mar 2010 13:48:09 +0000 Subject: libgl-xlib: Use a simple GALLIUM_DRIVER env var to select the pipe driver. GALLIUM_DRIVER is being used in many other places, and it easier to memorizing and understand than all the GALLIUM_NO_XXX. --- src/gallium/targets/libgl-xlib/xlib.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/targets/libgl-xlib/xlib.c b/src/gallium/targets/libgl-xlib/xlib.c index eff4b4778bf..48e79fe4f3b 100644 --- a/src/gallium/targets/libgl-xlib/xlib.c +++ b/src/gallium/targets/libgl-xlib/xlib.c @@ -63,6 +63,8 @@ PUBLIC const struct st_module st_module_OpenGL = { static struct pipe_screen * swrast_xlib_create_screen( Display *display ) { + const char *default_driver; + const char *driver; struct sw_winsys *winsys; struct pipe_screen *screen = NULL; @@ -73,17 +75,29 @@ swrast_xlib_create_screen( Display *display ) if (winsys == NULL) return NULL; +#if defined(GALLIUM_CELL) + default_driver = "cell"; +#elif defined(GALLIUM_LLVMPIPE) + default_driver = "llvmpipe"; +#elif defined(GALLIUM_SOFTPIPE) + default_driver = "softpipe"; +#else + default_driver = ""; +#endif + + driver = debug_get_option("GALLIUM_DRIVER", default_driver); + /* Create a software rasterizer on top of that winsys: */ #if defined(GALLIUM_CELL) if (screen == NULL && - !debug_get_bool_option("GALLIUM_NO_CELL", FALSE)) + strcmp(driver, "cell") == 0) screen = cell_create_screen( winsys ); #endif #if defined(GALLIUM_LLVMPIPE) if (screen == NULL && - !debug_get_bool_option("GALLIUM_NO_LLVM", FALSE)) + strcmp(driver, "llvmpipe") == 0) screen = llvmpipe_create_screen( winsys ); #endif -- cgit v1.2.3 From ac8662c29dbf96b456d23308c1bc459eea63e36c Mon Sep 17 00:00:00 2001 From: Roland Scheidegger Date: Tue, 16 Mar 2010 15:49:23 +0100 Subject: st/xorg: fix up xorg state tracker to use cso changes use cso_set_fragment_sampler_views instead of cso_set_sampler_textures --- src/gallium/state_trackers/xorg/xorg_composite.c | 29 +++++++++++----- src/gallium/state_trackers/xorg/xorg_exa.c | 3 ++ src/gallium/state_trackers/xorg/xorg_exa.h | 2 +- src/gallium/state_trackers/xorg/xorg_renderer.c | 21 ++++++++---- src/gallium/state_trackers/xorg/xorg_renderer.h | 4 +-- src/gallium/state_trackers/xorg/xorg_xv.c | 42 ++++++++++++++++++++---- 6 files changed, 78 insertions(+), 23 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/xorg/xorg_composite.c b/src/gallium/state_trackers/xorg/xorg_composite.c index 715a5e7b943..4ff48026e50 100644 --- a/src/gallium/state_trackers/xorg/xorg_composite.c +++ b/src/gallium/state_trackers/xorg/xorg_composite.c @@ -4,6 +4,7 @@ #include "xorg_exa_tgsi.h" #include "cso_cache/cso_context.h" +#include "util/u_sampler.h" /*XXX also in Xrender.h but the including it here breaks compilition */ @@ -356,6 +357,9 @@ bind_samplers(struct exa_context *exa, int op, { struct pipe_sampler_state *samplers[PIPE_MAX_SAMPLERS]; struct pipe_sampler_state src_sampler, mask_sampler; + struct pipe_sampler_view view_templ; + struct pipe_sampler_view *src_view; + struct pipe_context *pipe = exa->pipe; exa->num_bound_samplers = 0; @@ -366,7 +370,7 @@ bind_samplers(struct exa_context *exa, int op, if (exa->has_solid_color) { debug_assert(!"solid color with textures"); samplers[0] = NULL; - exa->bound_textures[0] = NULL; + pipe_sampler_view_reference(&exa->bound_sampler_views[0], NULL); } else { unsigned src_wrap = render_repeat_to_gallium( pSrcPicture->repeatType); @@ -381,8 +385,13 @@ bind_samplers(struct exa_context *exa, int op, src_sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NEAREST; src_sampler.normalized_coords = 1; samplers[0] = &src_sampler; - exa->bound_textures[0] = pSrc->tex; exa->num_bound_samplers = 1; + u_sampler_view_default_template(&view_templ, + pSrc->tex, + pSrc->tex->format); + src_view = pipe->create_sampler_view(pipe, pSrc->tex, &view_templ); + pipe_sampler_view_reference(&exa->bound_sampler_views[0], NULL); + exa->bound_sampler_views[0] = src_view; } } @@ -400,14 +409,19 @@ bind_samplers(struct exa_context *exa, int op, src_sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NEAREST; mask_sampler.normalized_coords = 1; samplers[1] = &mask_sampler; - exa->bound_textures[1] = pMask->tex; exa->num_bound_samplers = 2; + u_sampler_view_default_template(&view_templ, + pMask->tex, + pMask->tex->format); + src_view = pipe->create_sampler_view(pipe, pMask->tex, &view_templ); + pipe_sampler_view_reference(&exa->bound_sampler_views[1], NULL); + exa->bound_sampler_views[1] = src_view; } cso_set_samplers(exa->renderer->cso, exa->num_bound_samplers, (const struct pipe_sampler_state **)samplers); - cso_set_sampler_textures(exa->renderer->cso, exa->num_bound_samplers, - exa->bound_textures); + cso_set_fragment_sampler_views(exa->renderer->cso, exa->num_bound_samplers, + exa->bound_sampler_views); } @@ -476,7 +490,6 @@ boolean xorg_composite_bind_state(struct exa_context *exa, renderer_begin_solid(exa->renderer); } else { renderer_begin_textures(exa->renderer, - exa->bound_textures, exa->num_bound_samplers); } @@ -506,7 +519,7 @@ void xorg_composite(struct exa_context *exa, renderer_texture(exa->renderer, pos, width, height, - exa->bound_textures, + exa->bound_sampler_views, exa->num_bound_samplers, src_matrix, mask_matrix); } @@ -538,7 +551,7 @@ boolean xorg_solid_bind_state(struct exa_context *exa, pixmap->width, pixmap->height); bind_blend_state(exa, PictOpSrc, NULL, NULL, NULL); cso_set_samplers(exa->renderer->cso, 0, NULL); - cso_set_sampler_textures(exa->renderer->cso, 0, NULL); + cso_set_fragment_sampler_views(exa->renderer->cso, 0, NULL); shader = xorg_shaders_get(exa->renderer->shaders, vs_traits, fs_traits); cso_set_vertex_shader_handle(exa->renderer->cso, shader.vs); diff --git a/src/gallium/state_trackers/xorg/xorg_exa.c b/src/gallium/state_trackers/xorg/xorg_exa.c index bdec0e254fa..76e6411bb8c 100644 --- a/src/gallium/state_trackers/xorg/xorg_exa.c +++ b/src/gallium/state_trackers/xorg/xorg_exa.c @@ -975,6 +975,9 @@ xorg_exa_close(ScrnInfoPtr pScrn) modesettingPtr ms = modesettingPTR(pScrn); struct exa_context *exa = ms->exa; + pipe_sampler_view_reference(&exa->bound_sampler_views[0], NULL); + pipe_sampler_view_reference(&exa->bound_sampler_views[1], NULL); + renderer_destroy(exa->renderer); if (exa->pipe) diff --git a/src/gallium/state_trackers/xorg/xorg_exa.h b/src/gallium/state_trackers/xorg/xorg_exa.h index f2cefe23b99..41b19061599 100644 --- a/src/gallium/state_trackers/xorg/xorg_exa.h +++ b/src/gallium/state_trackers/xorg/xorg_exa.h @@ -18,7 +18,7 @@ struct exa_context struct pipe_screen *scrn; struct xorg_renderer *renderer; - struct pipe_texture *bound_textures[MAX_EXA_SAMPLERS]; + struct pipe_sampler_view *bound_sampler_views[MAX_EXA_SAMPLERS]; int num_bound_samplers; float solid_color[4]; diff --git a/src/gallium/state_trackers/xorg/xorg_renderer.c b/src/gallium/state_trackers/xorg/xorg_renderer.c index 1eb926360b9..81b0dcf656f 100644 --- a/src/gallium/state_trackers/xorg/xorg_renderer.c +++ b/src/gallium/state_trackers/xorg/xorg_renderer.c @@ -8,6 +8,7 @@ #include "util/u_math.h" #include "util/u_memory.h" #include "util/u_rect.h" +#include "util/u_sampler.h" #include "util/u_inlines.h" @@ -482,8 +483,17 @@ void renderer_copy_prepare(struct xorg_renderer *r, dst_surface->width, dst_surface->height); - /* texture */ - cso_set_sampler_textures(r->cso, 1, &src_texture); + /* texture/sampler view */ + { + struct pipe_sampler_view templ; + struct pipe_sampler_view *src_view; + u_sampler_view_default_template(&templ, + src_texture, + src_texture->format); + src_view = pipe->create_sampler_view(pipe, src_texture, &templ); + cso_set_fragment_sampler_views(r->cso, 1, &src_view); + pipe_sampler_view_reference(&src_view, NULL); + } /* shaders */ shader = xorg_shaders_get(r->shaders, @@ -655,7 +665,6 @@ void renderer_draw_flush(struct xorg_renderer *r) } void renderer_begin_textures(struct xorg_renderer *r, - struct pipe_texture **textures, int num_textures) { r->attrs_per_vertex = 1 + num_textures; @@ -665,7 +674,7 @@ void renderer_begin_textures(struct xorg_renderer *r, void renderer_texture(struct xorg_renderer *r, int *pos, int width, int height, - struct pipe_texture **textures, + struct pipe_sampler_view **sampler_view, int num_textures, float *src_matrix, float *mask_matrix) @@ -693,7 +702,7 @@ void renderer_texture(struct xorg_renderer *r, pos[0], pos[1], /* src */ pos[4], pos[5], /* dst */ width, height, - textures[0], src_matrix); + sampler_view[0]->texture, src_matrix); break; case 3: renderer_draw_conditional(r, 4 * 12); @@ -702,7 +711,7 @@ void renderer_texture(struct xorg_renderer *r, pos[2], pos[3], /* mask */ pos[4], pos[5], /* dst */ width, height, - textures[0], textures[1], + sampler_view[0]->texture, sampler_view[1]->texture, src_matrix, mask_matrix); break; default: diff --git a/src/gallium/state_trackers/xorg/xorg_renderer.h b/src/gallium/state_trackers/xorg/xorg_renderer.h index 3d006287199..cc5802e79b2 100644 --- a/src/gallium/state_trackers/xorg/xorg_renderer.h +++ b/src/gallium/state_trackers/xorg/xorg_renderer.h @@ -65,12 +65,12 @@ void renderer_solid(struct xorg_renderer *r, float *color); void renderer_begin_textures(struct xorg_renderer *r, - struct pipe_texture **textures, int num_textures); + void renderer_texture(struct xorg_renderer *r, int *pos, int width, int height, - struct pipe_texture **textures, + struct pipe_sampler_view **textures, int num_textures, float *src_matrix, float *mask_matrix); diff --git a/src/gallium/state_trackers/xorg/xorg_xv.c b/src/gallium/state_trackers/xorg/xorg_xv.c index 5a195cb482d..5efda6837de 100644 --- a/src/gallium/state_trackers/xorg/xorg_xv.c +++ b/src/gallium/state_trackers/xorg/xorg_xv.c @@ -9,6 +9,7 @@ #include "xorg_exa_tgsi.h" #include "cso_cache/cso_context.h" +#include "util/u_sampler.h" #include "pipe/p_screen.h" @@ -91,6 +92,7 @@ struct xorg_xv_port_priv { /* juggle two sets of seperate Y, U and V * textures */ struct pipe_texture *yuv[2][3]; + struct pipe_sampler_view *yuv_views[2][3]; }; @@ -180,32 +182,60 @@ static int check_yuv_textures(struct xorg_xv_port_priv *priv, int width, int height) { struct pipe_texture **dst = priv->yuv[priv->current_set]; + struct pipe_sampler_view **dst_view = priv->yuv_views[priv->current_set]; + struct pipe_sampler_view view_templ; + struct pipe_context *pipe = priv->r->pipe; + if (!dst[0] || dst[0]->width0 != width || dst[0]->height0 != height) { pipe_texture_reference(&dst[0], NULL); + pipe_sampler_view_reference(&dst_view[0], NULL); } if (!dst[1] || dst[1]->width0 != width || dst[1]->height0 != height) { pipe_texture_reference(&dst[1], NULL); + pipe_sampler_view_reference(&dst_view[1], NULL); } if (!dst[2] || dst[2]->width0 != width || dst[2]->height0 != height) { pipe_texture_reference(&dst[2], NULL); + pipe_sampler_view_reference(&dst_view[2], NULL); } - if (!dst[0]) + if (!dst[0]) { dst[0] = create_component_texture(priv->r->pipe, width, height); + if (dst[0]) { + u_sampler_view_default_template(&view_templ, + dst[0], + dst[0]->format); + dst_view[0] = pipe->create_sampler_view(pipe, dst[0], &view_templ); + } + } - if (!dst[1]) + if (!dst[1]) { dst[1] = create_component_texture(priv->r->pipe, width, height); + if (dst[1]) { + u_sampler_view_default_template(&view_templ, + dst[1], + dst[1]->format); + dst_view[1] = pipe->create_sampler_view(pipe, dst[1], &view_templ); + } + } - if (!dst[2]) + if (!dst[2]) { dst[2] = create_component_texture(priv->r->pipe, width, height); + if (dst[2]) { + u_sampler_view_default_template(&view_templ, + dst[2], + dst[2]->format); + dst_view[2] = pipe->create_sampler_view(pipe, dst[2], &view_templ); + } + } - if (!dst[0] || !dst[1] || !dst[2]) + if (!dst[0] || !dst[1] || !dst[2] || !dst_view[0] || !dst_view[1] || !dst_view[2] ) return BadAlloc; return Success; @@ -450,6 +480,7 @@ bind_samplers(struct xorg_xv_port_priv *port) struct pipe_sampler_state *samplers[PIPE_MAX_SAMPLERS]; struct pipe_sampler_state sampler; struct pipe_texture **dst = port->yuv[port->current_set]; + struct pipe_sampler_view **dst_views = port->yuv_views[port->current_set]; memset(&sampler, 0, sizeof(struct pipe_sampler_state)); @@ -469,8 +500,7 @@ bind_samplers(struct xorg_xv_port_priv *port) cso_set_samplers(port->r->cso, 3, (const struct pipe_sampler_state **)samplers); - cso_set_sampler_textures(port->r->cso, 3, - dst); + cso_set_fragment_sampler_views(port->r->cso, 3, dst_views); } static int -- cgit v1.2.3 From 7c457108596ba6b95a17b8353a117fccbac486fc Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Tue, 16 Mar 2010 13:31:42 -0600 Subject: gallium: add target-helpers/wrap_screen.c to C_SOURCES Was commented out before. --- src/gallium/auxiliary/Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/auxiliary/Makefile b/src/gallium/auxiliary/Makefile index e2796d5bd38..e1c3bc43a24 100644 --- a/src/gallium/auxiliary/Makefile +++ b/src/gallium/auxiliary/Makefile @@ -127,14 +127,15 @@ C_SOURCES = \ util/u_tile.c \ util/u_timed_winsys.c \ util/u_upload_mgr.c \ - util/u_simple_screen.c + util/u_simple_screen.c \ + target-helpers/wrap_screen.c + # Disabling until pipe-video branch gets merged in #vl/vl_bitstream_parser.c \ #vl/vl_mpeg12_mc_renderer.c \ #vl/vl_compositor.c \ #vl/vl_csc.c \ #vl/vl_shader_build.c \ - target-helpers/wrap_screen.c GALLIVM_SOURCES = \ gallivm/lp_bld_alpha.c \ -- cgit v1.2.3 From e548babb1fc9230054674deb5e332f55319e5b91 Mon Sep 17 00:00:00 2001 From: Christoph Bumiller Date: Tue, 16 Mar 2010 22:32:42 +0100 Subject: nv50: support more formats in surface_copy,fill Fixes corrupted fonts in bzFlag, where we've been silently failing to copy I8 mipmaps to a new miptree. Print an error message on unsupported format now, since we can't return failure. --- src/gallium/drivers/nv50/nv50_surface.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/nv50/nv50_surface.c b/src/gallium/drivers/nv50/nv50_surface.c index cabd148bc5b..6467c48a32a 100644 --- a/src/gallium/drivers/nv50/nv50_surface.c +++ b/src/gallium/drivers/nv50/nv50_surface.c @@ -28,6 +28,7 @@ #include "util/u_inlines.h" #include "util/u_tile.h" +#include "util/u_format.h" static INLINE int nv50_format(enum pipe_format format) @@ -37,10 +38,35 @@ nv50_format(enum pipe_format format) return NV50_2D_DST_FORMAT_A8R8G8B8_UNORM; case PIPE_FORMAT_B8G8R8X8_UNORM: return NV50_2D_DST_FORMAT_X8R8G8B8_UNORM; + case PIPE_FORMAT_B8G8R8A8_SRGB: + return NV50_2D_DST_FORMAT_A8R8G8B8_SRGB; + case PIPE_FORMAT_B8G8R8X8_SRGB: + return NV50_2D_DST_FORMAT_X8R8G8B8_SRGB; case PIPE_FORMAT_B5G6R5_UNORM: return NV50_2D_DST_FORMAT_R5G6B5_UNORM; + case PIPE_FORMAT_B5G5R5A1_UNORM: + return NV50_2D_DST_FORMAT_A1R5G5B5_UNORM; case PIPE_FORMAT_A8_UNORM: + case PIPE_FORMAT_I8_UNORM: + case PIPE_FORMAT_L8_UNORM: return NV50_2D_DST_FORMAT_R8_UNORM; + case PIPE_FORMAT_R32G32B32A32_FLOAT: + return NV50_2D_DST_FORMAT_R32G32B32A32_FLOAT; + case PIPE_FORMAT_R32G32B32_FLOAT: + return NV50_2D_DST_FORMAT_R32G32B32X32_FLOAT; + case PIPE_FORMAT_Z32_FLOAT: + return NV50_2D_DST_FORMAT_R32_FLOAT; + + /* only because we require src format == dst format: */ + case PIPE_FORMAT_R16G16_SNORM: + case PIPE_FORMAT_R16G16_UNORM: + case PIPE_FORMAT_S8Z24_UNORM: + case PIPE_FORMAT_Z24S8_UNORM: + return NV50_2D_DST_FORMAT_A8R8G8B8_UNORM; + case PIPE_FORMAT_L8A8_UNORM: + case PIPE_FORMAT_B4G4R4A4_UNORM: + return NV50_2D_DST_FORMAT_R16_UNORM; + default: return -1; } @@ -57,8 +83,11 @@ nv50_surface_set(struct nv50_screen *screen, struct pipe_surface *ps, int dst) int flags = NOUVEAU_BO_VRAM | (dst ? NOUVEAU_BO_WR : NOUVEAU_BO_RD); format = nv50_format(ps->format); - if (format < 0) + if (format < 0) { + NOUVEAU_ERR("invalid/unsupported surface format: %s\n", + util_format_name(ps->format)); return 1; + } if (!bo->tile_flags) { MARK_RING (chan, 9, 2); /* flush on lack of space or relocs */ -- cgit v1.2.3 From a9a1b52f959f325affe89a093b05e9b0f100018c Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Tue, 16 Mar 2010 16:45:36 -0600 Subject: cell: add missing semicolon --- src/gallium/drivers/cell/ppu/cell_context.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/cell/ppu/cell_context.h b/src/gallium/drivers/cell/ppu/cell_context.h index 4d87f9a038a..f7e2284445d 100644 --- a/src/gallium/drivers/cell/ppu/cell_context.h +++ b/src/gallium/drivers/cell/ppu/cell_context.h @@ -97,7 +97,7 @@ struct cell_velems_state { unsigned count; struct pipe_vertex_element velem[PIPE_MAX_ATTRIBS]; -} +}; /** * Per-context state, subclass of pipe_context. -- cgit v1.2.3 From 6379e47ebde2767ec88504313c4cf2d99ac44920 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Tue, 16 Mar 2010 13:50:19 -0600 Subject: llvmpipe: break lines --- src/gallium/drivers/llvmpipe/lp_jit.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/llvmpipe/lp_jit.c b/src/gallium/drivers/llvmpipe/lp_jit.c index 5887613120d..4584135d335 100644 --- a/src/gallium/drivers/llvmpipe/lp_jit.c +++ b/src/gallium/drivers/llvmpipe/lp_jit.c @@ -95,7 +95,8 @@ lp_jit_init_globals(struct llvmpipe_screen *screen) LLVMTypeRef context_type; elem_types[0] = LLVMPointerType(LLVMFloatType(), 0); /* constants */ - elem_types[1] = LLVMFloatType(); /* alpha_ref_value */ elem_types[2] = LLVMFloatType(); /* scissor_xmin */ + elem_types[1] = LLVMFloatType(); /* alpha_ref_value */ + elem_types[2] = LLVMFloatType(); /* scissor_xmin */ elem_types[3] = LLVMFloatType(); /* scissor_ymin */ elem_types[4] = LLVMFloatType(); /* scissor_xmax */ elem_types[5] = LLVMFloatType(); /* scissor_ymax */ -- cgit v1.2.3 From eee51147979208feffdf37c588ebbce4df6b40d6 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Tue, 16 Mar 2010 14:00:40 -0600 Subject: llvmpipe: added stencil ref values to jit context state --- src/gallium/drivers/llvmpipe/lp_jit.c | 27 ++++++++++++++----------- src/gallium/drivers/llvmpipe/lp_jit.h | 17 ++++++++++------ src/gallium/drivers/llvmpipe/lp_setup.c | 14 +++++++++++++ src/gallium/drivers/llvmpipe/lp_setup.h | 4 ++++ src/gallium/drivers/llvmpipe/lp_state_derived.c | 5 ++++- 5 files changed, 48 insertions(+), 19 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/llvmpipe/lp_jit.c b/src/gallium/drivers/llvmpipe/lp_jit.c index 4584135d335..0254272eeca 100644 --- a/src/gallium/drivers/llvmpipe/lp_jit.c +++ b/src/gallium/drivers/llvmpipe/lp_jit.c @@ -91,17 +91,18 @@ lp_jit_init_globals(struct llvmpipe_screen *screen) /* struct lp_jit_context */ { - LLVMTypeRef elem_types[8]; + LLVMTypeRef elem_types[9]; LLVMTypeRef context_type; elem_types[0] = LLVMPointerType(LLVMFloatType(), 0); /* constants */ elem_types[1] = LLVMFloatType(); /* alpha_ref_value */ - elem_types[2] = LLVMFloatType(); /* scissor_xmin */ - elem_types[3] = LLVMFloatType(); /* scissor_ymin */ - elem_types[4] = LLVMFloatType(); /* scissor_xmax */ - elem_types[5] = LLVMFloatType(); /* scissor_ymax */ - elem_types[6] = LLVMPointerType(LLVMInt8Type(), 0); /* blend_color */ - elem_types[7] = LLVMArrayType(texture_type, PIPE_MAX_SAMPLERS); /* textures */ + elem_types[2] = LLVMArrayType(LLVMInt8Type(), 2); /* stencil_refs */ + elem_types[3] = LLVMFloatType(); /* scissor_xmin */ + elem_types[4] = LLVMFloatType(); /* scissor_ymin */ + elem_types[5] = LLVMFloatType(); /* scissor_xmax */ + elem_types[6] = LLVMFloatType(); /* scissor_ymax */ + elem_types[7] = LLVMPointerType(LLVMInt8Type(), 0); /* blend_color */ + elem_types[8] = LLVMArrayType(texture_type, PIPE_MAX_SAMPLERS); /* textures */ context_type = LLVMStructType(elem_types, Elements(elem_types), 0); @@ -109,16 +110,18 @@ lp_jit_init_globals(struct llvmpipe_screen *screen) screen->target, context_type, 0); LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, alpha_ref_value, screen->target, context_type, 1); - LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, scissor_xmin, + LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, stencil_ref, screen->target, context_type, 2); - LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, scissor_ymin, + LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, scissor_xmin, screen->target, context_type, 3); - LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, scissor_xmax, + LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, scissor_ymin, screen->target, context_type, 4); - LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, scissor_ymax, + LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, scissor_xmax, screen->target, context_type, 5); - LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, blend_color, + LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, scissor_ymax, screen->target, context_type, 6); + LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, blend_color, + screen->target, context_type, 7); LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, textures, screen->target, context_type, LP_JIT_CONTEXT_TEXTURES_INDEX); diff --git a/src/gallium/drivers/llvmpipe/lp_jit.h b/src/gallium/drivers/llvmpipe/lp_jit.h index 13167ae3bf4..6864265ed02 100644 --- a/src/gallium/drivers/llvmpipe/lp_jit.h +++ b/src/gallium/drivers/llvmpipe/lp_jit.h @@ -84,6 +84,8 @@ struct lp_jit_context float alpha_ref_value; + ubyte stencil_ref[2]; + /** floats, not ints */ float scissor_xmin, scissor_ymin, scissor_xmax, scissor_ymax; @@ -100,22 +102,25 @@ struct lp_jit_context #define lp_jit_context_alpha_ref_value(_builder, _ptr) \ lp_build_struct_get(_builder, _ptr, 1, "alpha_ref_value") +#define lp_jit_context_stencil_ref_value(_builder, _ptr) \ + lp_build_struct_get(_builder, _ptr, 2, "stencil_ref_values") + #define lp_jit_context_scissor_xmin_value(_builder, _ptr) \ - lp_build_struct_get(_builder, _ptr, 2, "scissor_xmin") + lp_build_struct_get(_builder, _ptr, 3, "scissor_xmin") #define lp_jit_context_scissor_ymin_value(_builder, _ptr) \ - lp_build_struct_get(_builder, _ptr, 3, "scissor_ymin") + lp_build_struct_get(_builder, _ptr, 4, "scissor_ymin") #define lp_jit_context_scissor_xmax_value(_builder, _ptr) \ - lp_build_struct_get(_builder, _ptr, 4, "scissor_xmax") + lp_build_struct_get(_builder, _ptr, 5, "scissor_xmax") #define lp_jit_context_scissor_ymax_value(_builder, _ptr) \ - lp_build_struct_get(_builder, _ptr, 5, "scissor_ymax") + lp_build_struct_get(_builder, _ptr, 6, "scissor_ymax") #define lp_jit_context_blend_color(_builder, _ptr) \ - lp_build_struct_get(_builder, _ptr, 6, "blend_color") + lp_build_struct_get(_builder, _ptr, 7, "blend_color") -#define LP_JIT_CONTEXT_TEXTURES_INDEX 7 +#define LP_JIT_CONTEXT_TEXTURES_INDEX 8 #define lp_jit_context_textures(_builder, _ptr) \ lp_build_struct_get_ptr(_builder, _ptr, LP_JIT_CONTEXT_TEXTURES_INDEX, "textures") diff --git a/src/gallium/drivers/llvmpipe/lp_setup.c b/src/gallium/drivers/llvmpipe/lp_setup.c index cd16b6b2d38..bcc9d1fc1a4 100644 --- a/src/gallium/drivers/llvmpipe/lp_setup.c +++ b/src/gallium/drivers/llvmpipe/lp_setup.c @@ -401,6 +401,20 @@ lp_setup_set_alpha_ref_value( struct lp_setup_context *setup, } } +void +lp_setup_set_stencil_ref_values( struct lp_setup_context *setup, + const ubyte refs[2] ) +{ + LP_DBG(DEBUG_SETUP, "%s %d %d\n", __FUNCTION__, refs[0], refs[1]); + + if (setup->fs.current.jit_context.stencil_ref[0] != refs[0] || + setup->fs.current.jit_context.stencil_ref[1] != refs[1]) { + setup->fs.current.jit_context.stencil_ref[0] = refs[0]; + setup->fs.current.jit_context.stencil_ref[1] = refs[1]; + setup->dirty |= LP_SETUP_NEW_FS; + } +} + void lp_setup_set_blend_color( struct lp_setup_context *setup, const struct pipe_blend_color *blend_color ) diff --git a/src/gallium/drivers/llvmpipe/lp_setup.h b/src/gallium/drivers/llvmpipe/lp_setup.h index 414eaec98d1..dbfc1bf8d4c 100644 --- a/src/gallium/drivers/llvmpipe/lp_setup.h +++ b/src/gallium/drivers/llvmpipe/lp_setup.h @@ -112,6 +112,10 @@ void lp_setup_set_alpha_ref_value( struct lp_setup_context *setup, float alpha_ref_value ); +void +lp_setup_set_stencil_ref_values( struct lp_setup_context *setup, + const ubyte refs[2] ); + void lp_setup_set_blend_color( struct lp_setup_context *setup, const struct pipe_blend_color *blend_color ); diff --git a/src/gallium/drivers/llvmpipe/lp_state_derived.c b/src/gallium/drivers/llvmpipe/lp_state_derived.c index 9c91ce9238f..777871638f6 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_derived.c +++ b/src/gallium/drivers/llvmpipe/lp_state_derived.c @@ -174,9 +174,12 @@ void llvmpipe_update_derived( struct llvmpipe_context *llvmpipe ) if (llvmpipe->dirty & LP_NEW_SCISSOR) lp_setup_set_scissor(llvmpipe->setup, &llvmpipe->scissor); - if (llvmpipe->dirty & LP_NEW_DEPTH_STENCIL_ALPHA) + if (llvmpipe->dirty & LP_NEW_DEPTH_STENCIL_ALPHA) { lp_setup_set_alpha_ref_value(llvmpipe->setup, llvmpipe->depth_stencil->alpha.ref_value); + lp_setup_set_stencil_ref_values(llvmpipe->setup, + llvmpipe->stencil_ref.ref_value); + } if (llvmpipe->dirty & LP_NEW_CONSTANTS) lp_setup_set_fs_constants(llvmpipe->setup, -- cgit v1.2.3 From b8b1bb946f0bc7d1646e0625c239e08ac60b4fc7 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Tue, 16 Mar 2010 14:11:43 -0600 Subject: llvmpipe: use new LP_JIT_CTX_ enums for jit context field positions Use the new enum values rather than integers in a few places. --- src/gallium/drivers/llvmpipe/lp_jit.c | 47 ++++++++++++++--------- src/gallium/drivers/llvmpipe/lp_jit.h | 40 +++++++++++++------ src/gallium/drivers/llvmpipe/lp_tex_sample_llvm.c | 2 +- 3 files changed, 57 insertions(+), 32 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/llvmpipe/lp_jit.c b/src/gallium/drivers/llvmpipe/lp_jit.c index 0254272eeca..1eee9212e6f 100644 --- a/src/gallium/drivers/llvmpipe/lp_jit.c +++ b/src/gallium/drivers/llvmpipe/lp_jit.c @@ -91,40 +91,49 @@ lp_jit_init_globals(struct llvmpipe_screen *screen) /* struct lp_jit_context */ { - LLVMTypeRef elem_types[9]; + LLVMTypeRef elem_types[LP_JIT_CTX_COUNT]; LLVMTypeRef context_type; - elem_types[0] = LLVMPointerType(LLVMFloatType(), 0); /* constants */ - elem_types[1] = LLVMFloatType(); /* alpha_ref_value */ - elem_types[2] = LLVMArrayType(LLVMInt8Type(), 2); /* stencil_refs */ - elem_types[3] = LLVMFloatType(); /* scissor_xmin */ - elem_types[4] = LLVMFloatType(); /* scissor_ymin */ - elem_types[5] = LLVMFloatType(); /* scissor_xmax */ - elem_types[6] = LLVMFloatType(); /* scissor_ymax */ - elem_types[7] = LLVMPointerType(LLVMInt8Type(), 0); /* blend_color */ - elem_types[8] = LLVMArrayType(texture_type, PIPE_MAX_SAMPLERS); /* textures */ + elem_types[LP_JIT_CTX_CONSTANTS] = LLVMPointerType(LLVMFloatType(), 0); + elem_types[LP_JIT_CTX_ALPHA_REF] = LLVMFloatType(); + elem_types[LP_JIT_CTX_STENCIL_REF] = LLVMArrayType(LLVMInt8Type(), 2); + elem_types[LP_JIT_CTX_SCISSOR_XMIN] = LLVMFloatType(); + elem_types[LP_JIT_CTX_SCISSOR_YMIN] = LLVMFloatType(); + elem_types[LP_JIT_CTX_SCISSOR_XMAX] = LLVMFloatType(); + elem_types[LP_JIT_CTX_SCISSOR_YMAX] = LLVMFloatType(); + elem_types[LP_JIT_CTX_BLEND_COLOR] = LLVMPointerType(LLVMInt8Type(), 0); + elem_types[LP_JIT_CTX_TEXTURES] = LLVMArrayType(texture_type, + PIPE_MAX_SAMPLERS); context_type = LLVMStructType(elem_types, Elements(elem_types), 0); LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, constants, - screen->target, context_type, 0); + screen->target, context_type, + LP_JIT_CTX_CONSTANTS); LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, alpha_ref_value, - screen->target, context_type, 1); + screen->target, context_type, + LP_JIT_CTX_ALPHA_REF); LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, stencil_ref, - screen->target, context_type, 2); + screen->target, context_type, + LP_JIT_CTX_STENCIL_REF); LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, scissor_xmin, - screen->target, context_type, 3); + screen->target, context_type, + LP_JIT_CTX_SCISSOR_XMIN); LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, scissor_ymin, - screen->target, context_type, 4); + screen->target, context_type, + LP_JIT_CTX_SCISSOR_YMIN); LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, scissor_xmax, - screen->target, context_type, 5); + screen->target, context_type, + LP_JIT_CTX_SCISSOR_XMAX); LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, scissor_ymax, - screen->target, context_type, 6); + screen->target, context_type, + LP_JIT_CTX_SCISSOR_YMAX); LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, blend_color, - screen->target, context_type, 7); + screen->target, context_type, + LP_JIT_CTX_BLEND_COLOR); LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, textures, screen->target, context_type, - LP_JIT_CONTEXT_TEXTURES_INDEX); + LP_JIT_CTX_TEXTURES); LP_CHECK_STRUCT_SIZE(struct lp_jit_context, screen->target, context_type); diff --git a/src/gallium/drivers/llvmpipe/lp_jit.h b/src/gallium/drivers/llvmpipe/lp_jit.h index 6864265ed02..8f796f76d5a 100644 --- a/src/gallium/drivers/llvmpipe/lp_jit.h +++ b/src/gallium/drivers/llvmpipe/lp_jit.h @@ -84,7 +84,7 @@ struct lp_jit_context float alpha_ref_value; - ubyte stencil_ref[2]; + uint8_t stencil_ref[2]; /** floats, not ints */ float scissor_xmin, scissor_ymin, scissor_xmax, scissor_ymax; @@ -96,34 +96,50 @@ struct lp_jit_context }; +/** + * These enum values must match the position of the fields in the + * lp_jit_context struct above. + */ +enum { + LP_JIT_CTX_CONSTANTS = 0, + LP_JIT_CTX_ALPHA_REF, + LP_JIT_CTX_STENCIL_REF, + LP_JIT_CTX_SCISSOR_XMIN, + LP_JIT_CTX_SCISSOR_YMIN, + LP_JIT_CTX_SCISSOR_XMAX, + LP_JIT_CTX_SCISSOR_YMAX, + LP_JIT_CTX_BLEND_COLOR, + LP_JIT_CTX_TEXTURES, + LP_JIT_CTX_COUNT +}; + + #define lp_jit_context_constants(_builder, _ptr) \ - lp_build_struct_get(_builder, _ptr, 0, "constants") + lp_build_struct_get(_builder, _ptr, LP_JIT_CTX_CONSTANTS, "constants") #define lp_jit_context_alpha_ref_value(_builder, _ptr) \ - lp_build_struct_get(_builder, _ptr, 1, "alpha_ref_value") + lp_build_struct_get(_builder, _ptr, LP_JIT_CTX_ALPHA_REF, "alpha_ref_value") #define lp_jit_context_stencil_ref_value(_builder, _ptr) \ - lp_build_struct_get(_builder, _ptr, 2, "stencil_ref_values") + lp_build_struct_get(_builder, _ptr, LP_JIT_CTX_STENCIL_REF, "stencil_ref") #define lp_jit_context_scissor_xmin_value(_builder, _ptr) \ - lp_build_struct_get(_builder, _ptr, 3, "scissor_xmin") + lp_build_struct_get(_builder, _ptr, LP_JIT_CTX_SCISSOR_XMIN, "scissor_xmin") #define lp_jit_context_scissor_ymin_value(_builder, _ptr) \ - lp_build_struct_get(_builder, _ptr, 4, "scissor_ymin") + lp_build_struct_get(_builder, _ptr, LP_JIT_CTX_SCISSOR_YMIN, "scissor_ymin") #define lp_jit_context_scissor_xmax_value(_builder, _ptr) \ - lp_build_struct_get(_builder, _ptr, 5, "scissor_xmax") + lp_build_struct_get(_builder, _ptr, LP_JIT_CTX_SCISSOR_XMAX, "scissor_xmax") #define lp_jit_context_scissor_ymax_value(_builder, _ptr) \ - lp_build_struct_get(_builder, _ptr, 6, "scissor_ymax") + lp_build_struct_get(_builder, _ptr, LP_JIT_CTX_SCISSOR_YMAX, "scissor_ymax") #define lp_jit_context_blend_color(_builder, _ptr) \ - lp_build_struct_get(_builder, _ptr, 7, "blend_color") - -#define LP_JIT_CONTEXT_TEXTURES_INDEX 8 + lp_build_struct_get(_builder, _ptr, LP_JIT_CTX_BLEND_COLOR, "blend_color") #define lp_jit_context_textures(_builder, _ptr) \ - lp_build_struct_get_ptr(_builder, _ptr, LP_JIT_CONTEXT_TEXTURES_INDEX, "textures") + lp_build_struct_get_ptr(_builder, _ptr, LP_JIT_CONTEXT_TEXTURES, "textures") typedef void diff --git a/src/gallium/drivers/llvmpipe/lp_tex_sample_llvm.c b/src/gallium/drivers/llvmpipe/lp_tex_sample_llvm.c index 662508af61a..4715cfe4f62 100644 --- a/src/gallium/drivers/llvmpipe/lp_tex_sample_llvm.c +++ b/src/gallium/drivers/llvmpipe/lp_tex_sample_llvm.c @@ -105,7 +105,7 @@ lp_llvm_texture_member(struct lp_sampler_dynamic_state *base, /* context[0] */ indices[0] = LLVMConstInt(LLVMInt32Type(), 0, 0); /* context[0].textures */ - indices[1] = LLVMConstInt(LLVMInt32Type(), LP_JIT_CONTEXT_TEXTURES_INDEX, 0); + indices[1] = LLVMConstInt(LLVMInt32Type(), LP_JIT_CTX_TEXTURES, 0); /* context[0].textures[unit] */ indices[2] = LLVMConstInt(LLVMInt32Type(), unit, 0); /* context[0].textures[unit].member */ -- cgit v1.2.3 From 67b82fc395fc9972fc08233044057ab540c7ab59 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Tue, 16 Mar 2010 14:32:18 -0600 Subject: gallivm/llmvpipe: pass stencil refs state into z/stencil build code --- src/gallium/auxiliary/gallivm/lp_bld_depth.c | 1 + src/gallium/auxiliary/gallivm/lp_bld_depth.h | 1 + src/gallium/drivers/llvmpipe/lp_jit.h | 2 +- src/gallium/drivers/llvmpipe/lp_state.h | 1 + src/gallium/drivers/llvmpipe/lp_state_fs.c | 22 ++++++++++++++++------ 5 files changed, 20 insertions(+), 7 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/auxiliary/gallivm/lp_bld_depth.c b/src/gallium/auxiliary/gallivm/lp_bld_depth.c index cbc48f98651..3a5da4edce7 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_depth.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_depth.c @@ -217,6 +217,7 @@ lp_build_depth_test(LLVMBuilderRef builder, struct lp_type type, const struct util_format_description *format_desc, struct lp_build_mask_context *mask, + LLVMValueRef stencil_refs, LLVMValueRef src, LLVMValueRef dst_ptr) { diff --git a/src/gallium/auxiliary/gallivm/lp_bld_depth.h b/src/gallium/auxiliary/gallivm/lp_bld_depth.h index 8375824cbf4..a7f67d21005 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_depth.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_depth.h @@ -56,6 +56,7 @@ lp_build_depth_test(LLVMBuilderRef builder, struct lp_type type, const struct util_format_description *format_desc, struct lp_build_mask_context *mask, + LLVMValueRef stencil_refs, LLVMValueRef src, LLVMValueRef dst_ptr); diff --git a/src/gallium/drivers/llvmpipe/lp_jit.h b/src/gallium/drivers/llvmpipe/lp_jit.h index 8f796f76d5a..843345c62d0 100644 --- a/src/gallium/drivers/llvmpipe/lp_jit.h +++ b/src/gallium/drivers/llvmpipe/lp_jit.h @@ -120,7 +120,7 @@ enum { #define lp_jit_context_alpha_ref_value(_builder, _ptr) \ lp_build_struct_get(_builder, _ptr, LP_JIT_CTX_ALPHA_REF, "alpha_ref_value") -#define lp_jit_context_stencil_ref_value(_builder, _ptr) \ +#define lp_jit_context_stencil_ref_values(_builder, _ptr) \ lp_build_struct_get(_builder, _ptr, LP_JIT_CTX_STENCIL_REF, "stencil_ref") #define lp_jit_context_scissor_xmin_value(_builder, _ptr) \ diff --git a/src/gallium/drivers/llvmpipe/lp_state.h b/src/gallium/drivers/llvmpipe/lp_state.h index be02e97648e..74ebf90d580 100644 --- a/src/gallium/drivers/llvmpipe/lp_state.h +++ b/src/gallium/drivers/llvmpipe/lp_state.h @@ -67,6 +67,7 @@ struct lp_fragment_shader; struct lp_fragment_shader_variant_key { struct pipe_depth_state depth; + struct pipe_stencil_state stencil[2]; struct pipe_alpha_state alpha; struct pipe_blend_state blend; enum pipe_format zsbuf_format; diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs.c b/src/gallium/drivers/llvmpipe/lp_state_fs.c index a2ec8c39435..5b00792eec4 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_fs.c +++ b/src/gallium/drivers/llvmpipe/lp_state_fs.c @@ -145,6 +145,7 @@ generate_depth(LLVMBuilderRef builder, const struct lp_fragment_shader_variant_key *key, struct lp_type src_type, struct lp_build_mask_context *mask, + LLVMValueRef stencil_refs, LLVMValueRef src, LLVMValueRef dst_ptr) { @@ -189,6 +190,7 @@ generate_depth(LLVMBuilderRef builder, dst_type, format_desc, mask, + stencil_refs, src, dst_ptr); } @@ -405,6 +407,7 @@ generate_fs(struct llvmpipe_context *lp, LLVMValueRef consts_ptr; LLVMValueRef outputs[PIPE_MAX_SHADER_OUTPUTS][NUM_CHANNELS]; LLVMValueRef z = interp->pos[2]; + LLVMValueRef stencil_refs; struct lp_build_flow_context *flow; struct lp_build_mask_context mask; boolean early_depth_test; @@ -414,6 +417,8 @@ generate_fs(struct llvmpipe_context *lp, assert(i < 4); + stencil_refs = lp_jit_context_stencil_ref_values(builder, context_ptr); + elem_type = lp_build_elem_type(type); vec_type = lp_build_vec_type(type); int_vec_type = lp_build_int_vec_type(type); @@ -462,7 +467,7 @@ generate_fs(struct llvmpipe_context *lp, if(early_depth_test) generate_depth(builder, key, type, &mask, - z, depth_ptr); + stencil_refs, z, depth_ptr); lp_build_tgsi_soa(builder, tokens, type, &mask, consts_ptr, interp->pos, interp->inputs, @@ -509,7 +514,7 @@ generate_fs(struct llvmpipe_context *lp, if(!early_depth_test) generate_depth(builder, key, type, &mask, - z, depth_ptr); + stencil_refs, z, depth_ptr); lp_build_mask_end(&mask); @@ -1054,10 +1059,15 @@ make_variant_key(struct llvmpipe_context *lp, memset(key, 0, sizeof *key); - if(lp->framebuffer.zsbuf && - lp->depth_stencil->depth.enabled) { - key->zsbuf_format = lp->framebuffer.zsbuf->format; - memcpy(&key->depth, &lp->depth_stencil->depth, sizeof key->depth); + if (lp->framebuffer.zsbuf) { + if (lp->depth_stencil->depth.enabled) { + key->zsbuf_format = lp->framebuffer.zsbuf->format; + memcpy(&key->depth, &lp->depth_stencil->depth, sizeof key->depth); + } + if (lp->depth_stencil->stencil[0].enabled) { + key->zsbuf_format = lp->framebuffer.zsbuf->format; + memcpy(&key->stencil, &lp->depth_stencil->stencil, sizeof key->stencil); + } } key->alpha.enabled = lp->depth_stencil->alpha.enabled; -- cgit v1.2.3 From d1c9e598838aeac3c8cb90afee00b2cc683be273 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Tue, 16 Mar 2010 18:26:51 -0600 Subject: gallivm/llvmpipe: more asst changes for stencil testing --- src/gallium/auxiliary/gallivm/lp_bld_depth.c | 60 +++++++++++++++------------- src/gallium/auxiliary/gallivm/lp_bld_depth.h | 17 ++++---- src/gallium/drivers/llvmpipe/lp_state_fs.c | 55 ++++++++++++------------- 3 files changed, 69 insertions(+), 63 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/auxiliary/gallivm/lp_bld_depth.c b/src/gallium/auxiliary/gallivm/lp_bld_depth.c index 3a5da4edce7..0cbe42c9e5a 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_depth.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_depth.c @@ -212,34 +212,36 @@ lp_depth_type(const struct util_format_description *format_desc, * \param dst_ptr the outgoing/updated depth/stencil values */ void -lp_build_depth_test(LLVMBuilderRef builder, - const struct pipe_depth_state *state, - struct lp_type type, - const struct util_format_description *format_desc, - struct lp_build_mask_context *mask, - LLVMValueRef stencil_refs, - LLVMValueRef src, - LLVMValueRef dst_ptr) +lp_build_depth_stencil_test(LLVMBuilderRef builder, + const struct pipe_depth_state *depth, + const struct pipe_stencil_state stencil[2], + struct lp_type type, + const struct util_format_description *format_desc, + struct lp_build_mask_context *mask, + LLVMValueRef stencil_refs, + LLVMValueRef z_src, + LLVMValueRef zs_dst_ptr) { struct lp_build_context bld; - unsigned z_swizzle; - LLVMValueRef dst; + unsigned z_swizzle, s_swizzle; + LLVMValueRef zs_dst; LLVMValueRef z_bitmask = NULL; - LLVMValueRef test; + LLVMValueRef z_pass; (void) lp_build_stencil_test; (void) lp_build_stencil_op; - if(!state->enabled) - return; + assert(depth->enabled || stencil[0].enabled); assert(format_desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS); assert(format_desc->block.width == 1); assert(format_desc->block.height == 1); z_swizzle = format_desc->swizzle[0]; - if(z_swizzle == UTIL_FORMAT_SWIZZLE_NONE) - return; + s_swizzle = format_desc->swizzle[1]; + + assert(z_swizzle != UTIL_FORMAT_SWIZZLE_NONE || + s_swizzle != UTIL_FORMAT_SWIZZLE_NONE); /* Sanity checking */ assert(z_swizzle < 4); @@ -260,9 +262,9 @@ lp_build_depth_test(LLVMBuilderRef builder, /* Setup build context */ lp_build_context_init(&bld, builder, type); - dst = LLVMBuildLoad(builder, dst_ptr, ""); + zs_dst = LLVMBuildLoad(builder, zs_dst_ptr, ""); - lp_build_name(dst, "zsbuf"); + lp_build_name(zs_dst, "zsbuf"); /* Align the source depth bits with the destination's, and mask out any * stencil or padding bits from both */ @@ -271,6 +273,7 @@ lp_build_depth_test(LLVMBuilderRef builder, /* nothing to do */ } else { + /* shift/mask bits to right-justify the Z bits */ unsigned padding_left; unsigned padding_right; unsigned chan; @@ -287,32 +290,33 @@ lp_build_depth_test(LLVMBuilderRef builder, (padding_right + format_desc->channel[z_swizzle].size); if(padding_left || padding_right) { - const unsigned long long mask_left = ((unsigned long long)1 << (format_desc->block.bits - padding_left)) - 1; - const unsigned long long mask_right = ((unsigned long long)1 << (padding_right)) - 1; + const unsigned long long mask_left = (1ULL << (format_desc->block.bits - padding_left)) - 1; + const unsigned long long mask_right = (1ULL << (padding_right)) - 1; z_bitmask = lp_build_const_int_vec(type, mask_left ^ mask_right); } if(padding_left) - src = LLVMBuildLShr(builder, src, lp_build_const_int_vec(type, padding_left), ""); + z_src = LLVMBuildLShr(builder, z_src, + lp_build_const_int_vec(type, padding_left), ""); if(padding_right) - src = LLVMBuildAnd(builder, src, z_bitmask, ""); + z_src = LLVMBuildAnd(builder, z_src, z_bitmask, ""); if(padding_left || padding_right) - dst = LLVMBuildAnd(builder, dst, z_bitmask, ""); + zs_dst = LLVMBuildAnd(builder, zs_dst, z_bitmask, ""); } - lp_build_name(dst, "zsbuf.z"); + lp_build_name(zs_dst, "zsbuf.z"); /* compare src Z to dst Z, returning 'pass' mask */ - test = lp_build_cmp(&bld, state->func, src, dst); - lp_build_mask_update(mask, test); + z_pass = lp_build_cmp(&bld, depth->func, z_src, zs_dst); + lp_build_mask_update(mask, z_pass); - if(state->writemask) { + if (depth->writemask) { if(z_bitmask) z_bitmask = LLVMBuildAnd(builder, mask->value, z_bitmask, ""); else z_bitmask = mask->value; - dst = lp_build_select(&bld, z_bitmask, src, dst); - LLVMBuildStore(builder, dst, dst_ptr); + zs_dst = lp_build_select(&bld, z_bitmask, z_src, zs_dst); + LLVMBuildStore(builder, zs_dst, zs_dst_ptr); } } diff --git a/src/gallium/auxiliary/gallivm/lp_bld_depth.h b/src/gallium/auxiliary/gallivm/lp_bld_depth.h index a7f67d21005..eedc1e419b5 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_depth.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_depth.h @@ -51,14 +51,15 @@ lp_depth_type(const struct util_format_description *format_desc, void -lp_build_depth_test(LLVMBuilderRef builder, - const struct pipe_depth_state *state, - struct lp_type type, - const struct util_format_description *format_desc, - struct lp_build_mask_context *mask, - LLVMValueRef stencil_refs, - LLVMValueRef src, - LLVMValueRef dst_ptr); +lp_build_depth_stencil_test(LLVMBuilderRef builder, + const struct pipe_depth_state *depth, + const struct pipe_stencil_state stencil[2], + struct lp_type type, + const struct util_format_description *format_desc, + struct lp_build_mask_context *mask, + LLVMValueRef stencil_refs, + LLVMValueRef zs_src, + LLVMValueRef zs_dst_ptr); #endif /* !LP_BLD_DEPTH_H */ diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs.c b/src/gallium/drivers/llvmpipe/lp_state_fs.c index 5b00792eec4..15317ce10f3 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_fs.c +++ b/src/gallium/drivers/llvmpipe/lp_state_fs.c @@ -141,13 +141,13 @@ generate_pos0(LLVMBuilderRef builder, * Generate the depth test. */ static void -generate_depth(LLVMBuilderRef builder, - const struct lp_fragment_shader_variant_key *key, - struct lp_type src_type, - struct lp_build_mask_context *mask, - LLVMValueRef stencil_refs, - LLVMValueRef src, - LLVMValueRef dst_ptr) +generate_depth_stencil(LLVMBuilderRef builder, + const struct lp_fragment_shader_variant_key *key, + struct lp_type src_type, + struct lp_build_mask_context *mask, + LLVMValueRef stencil_refs, + LLVMValueRef src, + LLVMValueRef dst_ptr) { const struct util_format_description *format_desc; struct lp_type dst_type; @@ -179,20 +179,21 @@ generate_depth(LLVMBuilderRef builder, assert(dst_type.width == src_type.width); assert(dst_type.length == src_type.length); + /* Convert fragment Z from float to integer */ lp_build_conv(builder, src_type, dst_type, &src, 1, &src, 1); dst_ptr = LLVMBuildBitCast(builder, dst_ptr, LLVMPointerType(lp_build_vec_type(dst_type), 0), ""); - - lp_build_depth_test(builder, - &key->depth, - dst_type, - format_desc, - mask, - stencil_refs, - src, - dst_ptr); + lp_build_depth_stencil_test(builder, + &key->depth, + key->stencil, + dst_type, + format_desc, + mask, + stencil_refs, + src, + dst_ptr); } @@ -410,7 +411,7 @@ generate_fs(struct llvmpipe_context *lp, LLVMValueRef stencil_refs; struct lp_build_flow_context *flow; struct lp_build_mask_context mask; - boolean early_depth_test; + boolean early_depth_stencil_test; unsigned attrib; unsigned chan; unsigned cbuf; @@ -458,16 +459,16 @@ generate_fs(struct llvmpipe_context *lp, lp_build_mask_update(&mask, smask); } - early_depth_test = - key->depth.enabled && + early_depth_stencil_test = + (key->depth.enabled || key->stencil[0].enabled) && !key->alpha.enabled && !shader->info.uses_kill && !shader->info.writes_z; - if(early_depth_test) - generate_depth(builder, key, - type, &mask, - stencil_refs, z, depth_ptr); + if (early_depth_stencil_test) + generate_depth_stencil(builder, key, + type, &mask, + stencil_refs, z, depth_ptr); lp_build_tgsi_soa(builder, tokens, type, &mask, consts_ptr, interp->pos, interp->inputs, @@ -511,10 +512,10 @@ generate_fs(struct llvmpipe_context *lp, } } - if(!early_depth_test) - generate_depth(builder, key, - type, &mask, - stencil_refs, z, depth_ptr); + if (!early_depth_stencil_test) + generate_depth_stencil(builder, key, + type, &mask, + stencil_refs, z, depth_ptr); lp_build_mask_end(&mask); -- cgit v1.2.3 From 8dc8c3f5b11d5f158b0027d1501555c898e0451e Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 17 Mar 2010 08:34:23 -0600 Subject: llvmpipe: silence some pointer/casting warnings --- src/gallium/drivers/llvmpipe/lp_state_fs.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs.c b/src/gallium/drivers/llvmpipe/lp_state_fs.c index 15317ce10f3..a4030269704 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_fs.c +++ b/src/gallium/drivers/llvmpipe/lp_state_fs.c @@ -591,6 +591,20 @@ generate_blend(const struct pipe_blend_state *blend, } +/** casting function to avoid compiler warnings */ +static lp_jit_frag_func +cast_voidptr_to_lp_jit_frag_func(void *p) +{ + union { + void *v; + lp_jit_frag_func f; + } tmp; + assert(sizeof(tmp.v) == sizeof(tmp.f)); + tmp.v = p; + return tmp.f; +} + + /** * Generate the runtime callable function for the whole fragment pipeline. * Note that the function which we generate operates on a block of 16 @@ -851,10 +865,14 @@ generate_fragment(struct llvmpipe_context *lp, /* * Translate the LLVM IR into machine code. */ - variant->jit_function[do_tri_test] = (lp_jit_frag_func)LLVMGetPointerToGlobal(screen->engine, function); + { + void *f = LLVMGetPointerToGlobal(screen->engine, function); + + variant->jit_function[do_tri_test] = cast_voidptr_to_lp_jit_frag_func(f); - if (LP_DEBUG & DEBUG_ASM) - lp_disassemble(variant->jit_function[do_tri_test]); + if (LP_DEBUG & DEBUG_ASM) + lp_disassemble(f); + } } -- cgit v1.2.3 From 2b8db4ce156fbd4d094f46fad0b8b3291b057fff Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 17 Mar 2010 15:07:45 -0600 Subject: gallivm: added lp_build_andc() --- src/gallium/auxiliary/gallivm/lp_bld_logic.c | 10 ++++++++++ src/gallium/auxiliary/gallivm/lp_bld_logic.h | 5 +++++ 2 files changed, 15 insertions(+) (limited to 'src/gallium') diff --git a/src/gallium/auxiliary/gallivm/lp_bld_logic.c b/src/gallium/auxiliary/gallivm/lp_bld_logic.c index e2e533fa7ec..a3b69701162 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_logic.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_logic.c @@ -483,3 +483,13 @@ lp_build_alloca(struct lp_build_context *bld) return LLVMBuildAlloca(bld->builder, lp_build_elem_type(type), ""); } } + + +/** Return (a & ~b) */ +LLVMValueRef +lp_build_andc(struct lp_build_context *bld, LLVMValueRef a, LLVMValueRef b) +{ + b = LLVMBuildNot(bld->builder, b, ""); + b = LLVMBuildAnd(bld->builder, a, b, ""); + return b; +} diff --git a/src/gallium/auxiliary/gallivm/lp_bld_logic.h b/src/gallium/auxiliary/gallivm/lp_bld_logic.h index d849d29e95d..00a8c750196 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_logic.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_logic.h @@ -79,4 +79,9 @@ lp_build_select_aos(struct lp_build_context *bld, LLVMValueRef lp_build_alloca(struct lp_build_context *bld); + +LLVMValueRef +lp_build_andc(struct lp_build_context *bld, LLVMValueRef a, LLVMValueRef b); + + #endif /* !LP_BLD_LOGIC_H */ -- cgit v1.2.3 From 227824ac6999a8925b90f093b08a6284d33a7dad Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 17 Mar 2010 15:09:35 -0600 Subject: llvmpipe: remove incorrect depth test check --- src/gallium/drivers/llvmpipe/lp_state_fs.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs.c b/src/gallium/drivers/llvmpipe/lp_state_fs.c index a4030269704..b38e0f393dc 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_fs.c +++ b/src/gallium/drivers/llvmpipe/lp_state_fs.c @@ -138,7 +138,7 @@ generate_pos0(LLVMBuilderRef builder, /** - * Generate the depth test. + * Generate the depth /stencil test code. */ static void generate_depth_stencil(LLVMBuilderRef builder, @@ -152,9 +152,6 @@ generate_depth_stencil(LLVMBuilderRef builder, const struct util_format_description *format_desc; struct lp_type dst_type; - if(!key->depth.enabled) - return; - format_desc = util_format_description(key->zsbuf_format); assert(format_desc); -- cgit v1.2.3 From fecd4cde501e8b0b5d057a9cc9d2e3af8d853d9e Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 17 Mar 2010 16:24:12 -0600 Subject: gallivm/llvmpipe: basic stencil testing works Most stencil demos look OK (modulo some unrelated rendering glitches). Only single-sided stencil test works at this point. There are probably some bugs to be found... --- src/gallium/auxiliary/gallivm/lp_bld_depth.c | 164 +++++++++++++++++++++++---- src/gallium/drivers/llvmpipe/lp_jit.h | 2 +- 2 files changed, 140 insertions(+), 26 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/auxiliary/gallivm/lp_bld_depth.c b/src/gallium/auxiliary/gallivm/lp_bld_depth.c index 0cbe42c9e5a..e4500e5aef1 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_depth.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_depth.c @@ -80,8 +80,8 @@ static LLVMValueRef lp_build_stencil_test(struct lp_build_context *bld, const struct pipe_stencil_state *stencil, - LLVMValueRef stencilVals, - LLVMValueRef stencilRef) + LLVMValueRef stencilRef, + LLVMValueRef stencilVals) { const unsigned stencilMax = 255; /* XXX fix */ struct lp_type type = bld->type; @@ -97,8 +97,7 @@ lp_build_stencil_test(struct lp_build_context *bld, stencilVals = LLVMBuildAnd(bld->builder, stencilVals, valuemask, ""); } - res = lp_build_compare(bld->builder, bld->type, stencil->func, - stencilVals, stencilRef); + res = lp_build_cmp(bld, stencil->func, stencilVals, stencilRef); return res; } @@ -111,10 +110,11 @@ lp_build_stencil_test(struct lp_build_context *bld, */ static LLVMValueRef lp_build_stencil_op(struct lp_build_context *bld, + const struct pipe_stencil_state *stencil, unsigned stencil_op, LLVMValueRef stencilRef, - const struct pipe_stencil_state *stencil, - LLVMValueRef stencilVals) + LLVMValueRef stencilVals, + LLVMValueRef mask) { const unsigned stencilMax = 255; /* XXX fix */ @@ -125,24 +125,33 @@ lp_build_stencil_op(struct lp_build_context *bld, switch (stencil_op) { case PIPE_STENCIL_OP_KEEP: res = stencilVals; + /* we can return early for this case */ + return res; case PIPE_STENCIL_OP_ZERO: res = bld->zero; + break; case PIPE_STENCIL_OP_REPLACE: - res = lp_build_broadcast_scalar(bld, stencilRef); + res = stencilRef; + break; case PIPE_STENCIL_OP_INCR: res = lp_build_add(bld, stencilVals, bld->one); res = lp_build_min(bld, res, max); + break; case PIPE_STENCIL_OP_DECR: res = lp_build_sub(bld, stencilVals, bld->one); res = lp_build_max(bld, res, bld->zero); + break; case PIPE_STENCIL_OP_INCR_WRAP: res = lp_build_add(bld, stencilVals, bld->one); res = LLVMBuildAnd(bld->builder, res, max, ""); + break; case PIPE_STENCIL_OP_DECR_WRAP: res = lp_build_sub(bld, stencilVals, bld->one); res = LLVMBuildAnd(bld->builder, res, max, ""); + break; case PIPE_STENCIL_OP_INVERT: res = LLVMBuildNot(bld->builder, stencilVals, ""); + break; default: assert(0 && "bad stencil op mode"); res = NULL; @@ -157,6 +166,9 @@ lp_build_stencil_op(struct lp_build_context *bld, res = LLVMBuildOr(bld->builder, t1, t2, "t1_or_t2"); } + /* only the update the vector elements enabled by 'mask' */ + res = lp_build_select(bld, mask, res, stencilVals); + return res; } @@ -201,6 +213,27 @@ lp_depth_type(const struct util_format_description *format_desc, } +static LLVMValueRef +lp_build_get_stencil_ref(struct lp_build_context *bld, + struct lp_type type, LLVMValueRef stencil_refs_ptr) +{ + LLVMValueRef indexes[2], ptr, ref, ref_vec; + + /* load 0th element of the array */ + indexes[0] = indexes[1] = LLVMConstInt(LLVMInt32Type(), 0, 0); + ptr = LLVMBuildGEP(bld->builder, stencil_refs_ptr, indexes, 2, ""); + ref = LLVMBuildLoad(bld->builder, ptr, ""); + + /* convert int8 value to i32 */ + ref = LLVMBuildZExt(bld->builder, ref, LLVMIntType(type.width), ""); + + /* make scalar into vector */ + ref_vec = lp_build_broadcast_scalar(bld, ref); + + return ref_vec; +} + + /** * Generate code for performing depth and/or stencil tests. * We operate on a vector of values (typically a 2x2 quad). @@ -224,12 +257,11 @@ lp_build_depth_stencil_test(LLVMBuilderRef builder, { struct lp_build_context bld; unsigned z_swizzle, s_swizzle; - LLVMValueRef zs_dst; - LLVMValueRef z_bitmask = NULL; - LLVMValueRef z_pass; - - (void) lp_build_stencil_test; - (void) lp_build_stencil_op; + LLVMValueRef zs_dst, z_dst = NULL; + LLVMValueRef stencil_vals = NULL; + LLVMValueRef z_bitmask = NULL, s_bitmask = NULL; + LLVMValueRef z_pass = NULL, s_pass_mask = NULL; + LLVMValueRef orig_mask = mask->value; assert(depth->enabled || stencil[0].enabled); @@ -262,15 +294,16 @@ lp_build_depth_stencil_test(LLVMBuilderRef builder, /* Setup build context */ lp_build_context_init(&bld, builder, type); + /* Load current z/stencil value from z/stencil buffer */ zs_dst = LLVMBuildLoad(builder, zs_dst_ptr, ""); - lp_build_name(zs_dst, "zsbuf"); + lp_build_name(zs_dst, "zsbufval"); /* Align the source depth bits with the destination's, and mask out any * stencil or padding bits from both */ if(format_desc->channel[z_swizzle].size == format_desc->block.bits) { assert(z_swizzle == 0); - /* nothing to do */ + z_dst = zs_dst; } else { /* shift/mask bits to right-justify the Z bits */ @@ -295,28 +328,109 @@ lp_build_depth_stencil_test(LLVMBuilderRef builder, z_bitmask = lp_build_const_int_vec(type, mask_left ^ mask_right); } + s_bitmask = LLVMBuildNot(builder, z_bitmask, ""); + + stencil_vals = LLVMBuildAnd(builder, zs_dst, s_bitmask, ""); + if(padding_left) z_src = LLVMBuildLShr(builder, z_src, lp_build_const_int_vec(type, padding_left), ""); if(padding_right) z_src = LLVMBuildAnd(builder, z_src, z_bitmask, ""); if(padding_left || padding_right) - zs_dst = LLVMBuildAnd(builder, zs_dst, z_bitmask, ""); + z_dst = LLVMBuildAnd(builder, zs_dst, z_bitmask, ""); + else + z_dst = zs_dst; } - lp_build_name(zs_dst, "zsbuf.z"); + lp_build_name(z_dst, "zsbuf.z"); + + /* + printf("build depth %d stencil %d\n", + depth->enabled, + stencil[0].enabled); + */ + + if (stencil[0].enabled) { + /* Incoming stencil_refs is ptr to int8[2]. Get/convert to int32[4]. */ + stencil_refs = lp_build_get_stencil_ref(&bld, type, stencil_refs); - /* compare src Z to dst Z, returning 'pass' mask */ - z_pass = lp_build_cmp(&bld, depth->func, z_src, zs_dst); - lp_build_mask_update(mask, z_pass); + s_pass_mask = lp_build_stencil_test(&bld, stencil, + stencil_refs, stencil_vals); - if (depth->writemask) { - if(z_bitmask) - z_bitmask = LLVMBuildAnd(builder, mask->value, z_bitmask, ""); + /* apply stencil-fail operator */ + { + LLVMValueRef s_fail_mask = lp_build_andc(&bld, orig_mask, s_pass_mask); + stencil_vals = lp_build_stencil_op(&bld, stencil, stencil[0].fail_op, + stencil_refs, stencil_vals, + s_fail_mask); + } + } + + if (depth->enabled) { + /* compare src Z to dst Z, returning 'pass' mask */ + z_pass = lp_build_cmp(&bld, depth->func, z_src, z_dst); + + if (!stencil[0].enabled) { + /* We can potentially skip all remaining operations here, but only + * if stencil is disabled because we still need to update the stencil + * buffer values. Don't need to update Z buffer values. + */ + lp_build_mask_update(mask, z_pass); + } + + if (depth->writemask) { + if(z_bitmask) + z_bitmask = LLVMBuildAnd(builder, mask->value, z_bitmask, ""); + else + z_bitmask = mask->value; + + z_dst = lp_build_select(&bld, z_bitmask, z_src, z_dst); + } + + if (stencil[0].enabled) { + /* update stencil buffer values according to z pass/fail result */ + LLVMValueRef z_fail_mask, z_pass_mask; + + /* apply Z-fail operator */ + z_fail_mask = lp_build_andc(&bld, orig_mask, z_pass); + stencil_vals = lp_build_stencil_op(&bld, stencil, stencil[0].zfail_op, + stencil_refs, stencil_vals, + z_fail_mask); + + /* apply Z-pass operator */ + z_pass_mask = LLVMBuildAnd(bld.builder, orig_mask, z_pass, ""); + stencil_vals = lp_build_stencil_op(&bld, stencil, stencil[0].zpass_op, + stencil_refs, stencil_vals, + z_pass_mask); + } + } + else { + /* No depth test: apply Z-pass operator to stencil buffer values which + * passed the stencil test. + */ + s_pass_mask = LLVMBuildAnd(bld.builder, orig_mask, s_pass_mask, ""); + stencil_vals = lp_build_stencil_op(&bld, stencil, stencil[0].zpass_op, + stencil_refs, stencil_vals, s_pass_mask); + } + + /* Finally, merge/store the z/stencil values */ + if ((depth->enabled && depth->writemask) || + (stencil[0].enabled && stencil[0].writemask)) { + + if (z_dst && stencil_vals) + zs_dst = LLVMBuildOr(bld.builder, z_dst, stencil_vals, ""); + else if (z_dst) + zs_dst = z_dst; else - z_bitmask = mask->value; + zs_dst = stencil_vals; - zs_dst = lp_build_select(&bld, z_bitmask, z_src, zs_dst); LLVMBuildStore(builder, zs_dst, zs_dst_ptr); } + + if (s_pass_mask) + lp_build_mask_update(mask, s_pass_mask); + + if (depth->enabled && stencil[0].enabled) + lp_build_mask_update(mask, z_pass); } diff --git a/src/gallium/drivers/llvmpipe/lp_jit.h b/src/gallium/drivers/llvmpipe/lp_jit.h index 843345c62d0..63e05c5d5e1 100644 --- a/src/gallium/drivers/llvmpipe/lp_jit.h +++ b/src/gallium/drivers/llvmpipe/lp_jit.h @@ -121,7 +121,7 @@ enum { lp_build_struct_get(_builder, _ptr, LP_JIT_CTX_ALPHA_REF, "alpha_ref_value") #define lp_jit_context_stencil_ref_values(_builder, _ptr) \ - lp_build_struct_get(_builder, _ptr, LP_JIT_CTX_STENCIL_REF, "stencil_ref") + lp_build_struct_get_ptr(_builder, _ptr, LP_JIT_CTX_STENCIL_REF, "stencil_ref") #define lp_jit_context_scissor_xmin_value(_builder, _ptr) \ lp_build_struct_get(_builder, _ptr, LP_JIT_CTX_SCISSOR_XMIN, "scissor_xmin") -- cgit v1.2.3 From 6dd4054ca544952393f74eee1b37406404d7d823 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 17 Mar 2010 16:33:29 -0600 Subject: cell: be more conservative in cell_is_format_supported() This fixes a regression from commit a84575cdc0c8193b2c7858734e2ec6b1ec4511b2 which changed the depth/stencil format we were trying to use. --- src/gallium/drivers/cell/ppu/cell_screen.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/cell/ppu/cell_screen.c b/src/gallium/drivers/cell/ppu/cell_screen.c index a43f8638dcd..eada62181af 100644 --- a/src/gallium/drivers/cell/ppu/cell_screen.c +++ b/src/gallium/drivers/cell/ppu/cell_screen.c @@ -134,12 +134,16 @@ cell_is_format_supported( struct pipe_screen *screen, unsigned tex_usage, unsigned geom_flags ) { - /* cell supports most formats, XXX for now anyway */ - if (format == PIPE_FORMAT_DXT5_RGBA || - format == PIPE_FORMAT_A8B8G8R8_SRGB) - return FALSE; - else + /* only a few formats are known to work at this time */ + switch (format) { + case PIPE_FORMAT_Z24S8_UNORM: + case PIPE_FORMAT_Z24X8_UNORM: + case PIPE_FORMAT_B8G8R8A8_UNORM: + case PIPE_FORMAT_I8_UNORM: return TRUE; + default: + return FALSE; + } } -- cgit v1.2.3 From 05a980ac2a6b74af0436c1bb15c986a8160ec2eb Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 17 Mar 2010 17:39:49 -0600 Subject: cell: return 1 for PIPE_CAP_BLEND_EQUATION_SEPARATE With this feature, we get OpenGL version 2.0 and the progs/glsl/ demos run as-is. --- src/gallium/drivers/cell/ppu/cell_screen.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/gallium') diff --git a/src/gallium/drivers/cell/ppu/cell_screen.c b/src/gallium/drivers/cell/ppu/cell_screen.c index eada62181af..7957e0149d7 100644 --- a/src/gallium/drivers/cell/ppu/cell_screen.c +++ b/src/gallium/drivers/cell/ppu/cell_screen.c @@ -95,6 +95,8 @@ cell_get_param(struct pipe_screen *screen, int param) case PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT: case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER: return 0; + case PIPE_CAP_BLEND_EQUATION_SEPARATE: + return 1; default: return 0; } -- cgit v1.2.3 From ca69249f25e0cb89dbfc3d98b92e7386a3029efa Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Tue, 16 Mar 2010 09:47:18 +0800 Subject: st/dri: Move DRI1 bits in dri_screen.c to dri1.c. --- src/gallium/state_trackers/dri/Makefile | 3 +- src/gallium/state_trackers/dri/SConscript | 1 + src/gallium/state_trackers/dri/dri1.c | 117 ++++++++++++++++++++++++++ src/gallium/state_trackers/dri/dri1.h | 43 ++++++++++ src/gallium/state_trackers/dri/dri_context.c | 1 + src/gallium/state_trackers/dri/dri_drawable.c | 1 + src/gallium/state_trackers/dri/dri_drawable.h | 1 + src/gallium/state_trackers/dri/dri_screen.c | 79 +---------------- src/gallium/state_trackers/dri/dri_screen.h | 9 +- 9 files changed, 173 insertions(+), 82 deletions(-) create mode 100644 src/gallium/state_trackers/dri/dri1.c create mode 100644 src/gallium/state_trackers/dri/dri1.h (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/dri/Makefile b/src/gallium/state_trackers/dri/Makefile index ef8f19709ab..24244417b97 100644 --- a/src/gallium/state_trackers/dri/Makefile +++ b/src/gallium/state_trackers/dri/Makefile @@ -15,7 +15,8 @@ C_SOURCES = \ dri_context.c \ dri_screen.c \ dri_drawable.c \ - dri_extensions.c + dri_extensions.c \ + dri1.c # $(TOP)/src/mesa/drivers/dri/common/utils.c \ $(TOP)/src/mesa/drivers/dri/common/vblank.c \ diff --git a/src/gallium/state_trackers/dri/SConscript b/src/gallium/state_trackers/dri/SConscript index ce2c2735974..6310fe06e43 100644 --- a/src/gallium/state_trackers/dri/SConscript +++ b/src/gallium/state_trackers/dri/SConscript @@ -18,6 +18,7 @@ if env['dri']: 'dri_drawable.c', 'dri_extensions.c', 'dri_screen.c', + 'dri1.c', ] ) Export('st_dri') diff --git a/src/gallium/state_trackers/dri/dri1.c b/src/gallium/state_trackers/dri/dri1.c new file mode 100644 index 00000000000..1222f42e237 --- /dev/null +++ b/src/gallium/state_trackers/dri/dri1.c @@ -0,0 +1,117 @@ +/************************************************************************** + * + * Copyright 2009, VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ +/* + * Author: Keith Whitwell + * Author: Jakob Bornecrantz + */ + +#include "util/u_memory.h" + +#include "dri_screen.h" +#include "dri_context.h" +#include "dri_drawable.h" +#include "dri1.h" + +static const __DRIextension *dri1_screen_extensions[] = { + &driReadDrawableExtension, + &driCopySubBufferExtension.base, + &driSwapControlExtension.base, + &driFrameTrackingExtension.base, + &driMediaStreamCounterExtension.base, + NULL +}; + +struct dri1_api *__dri1_api_hooks = NULL; + +static INLINE void +dri1_copy_version(struct dri1_api_version *dst, + const struct __DRIversionRec *src) +{ + dst->major = src->major; + dst->minor = src->minor; + dst->patch_level = src->patch; +} + +const __DRIconfig ** +dri1_init_screen(__DRIscreen * sPriv) +{ + struct dri_screen *screen; + const __DRIconfig **configs; + struct dri1_create_screen_arg arg; + + screen = CALLOC_STRUCT(dri_screen); + if (!screen) + return NULL; + + screen->api = drm_api_create(); + screen->sPriv = sPriv; + screen->fd = sPriv->fd; + screen->drmLock = (drmLock *) & sPriv->pSAREA->lock; + + sPriv->private = (void *)screen; + sPriv->extensions = dri1_screen_extensions; + + arg.base.mode = DRM_CREATE_DRI1; + arg.lf = &dri1_lf; + arg.ddx_info = sPriv->pDevPriv; + arg.ddx_info_size = sPriv->devPrivSize; + arg.sarea = sPriv->pSAREA; + dri1_copy_version(&arg.ddx_version, &sPriv->ddx_version); + dri1_copy_version(&arg.dri_version, &sPriv->dri_version); + dri1_copy_version(&arg.drm_version, &sPriv->drm_version); + arg.api = NULL; + + screen->pipe_screen = screen->api->create_screen(screen->api, screen->fd, &arg.base); + + if (!screen->pipe_screen || !arg.api) { + debug_printf("%s: failed to create dri1 screen\n", __FUNCTION__); + goto out_no_screen; + } + + __dri1_api_hooks = arg.api; + + screen->pipe_screen->flush_frontbuffer = dri1_flush_frontbuffer; + driParseOptionInfo(&screen->optionCache, + __driConfigOptions, __driNConfigOptions); + + /** + * FIXME: If the driver supports format conversion swapbuffer blits, we might + * want to support other color bit depths than the server is currently + * using. + */ + + configs = dri_fill_in_modes(screen, sPriv->fbBPP); + if (!configs) + goto out_no_configs; + + return configs; + out_no_configs: + screen->pipe_screen->destroy(screen->pipe_screen); + out_no_screen: + FREE(screen); + return NULL; +} diff --git a/src/gallium/state_trackers/dri/dri1.h b/src/gallium/state_trackers/dri/dri1.h new file mode 100644 index 00000000000..731b13cb06f --- /dev/null +++ b/src/gallium/state_trackers/dri/dri1.h @@ -0,0 +1,43 @@ +/************************************************************************** + * + * Copyright 2009, VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ +/* + * Author: Keith Whitwell + * Author: Jakob Bornecrantz + */ + +#ifndef DRI1_H +#define DRI1_H + +#include "state_tracker/dri1_api.h" +#include "dri_util.h" + +extern struct dri1_api *__dri1_api_hooks; + +const __DRIconfig ** +dri1_init_screen(__DRIscreen * sPriv); + +#endif /* DRI1_H */ diff --git a/src/gallium/state_trackers/dri/dri_context.c b/src/gallium/state_trackers/dri/dri_context.c index f772ba5d16b..a5ed0006dc9 100644 --- a/src/gallium/state_trackers/dri/dri_context.c +++ b/src/gallium/state_trackers/dri/dri_context.c @@ -38,6 +38,7 @@ #include "pipe/p_context.h" #include "dri_context.h" +#include "dri1.h" #include "util/u_memory.h" diff --git a/src/gallium/state_trackers/dri/dri_drawable.c b/src/gallium/state_trackers/dri/dri_drawable.c index c400725c7f2..83b1a29681b 100644 --- a/src/gallium/state_trackers/dri/dri_drawable.c +++ b/src/gallium/state_trackers/dri/dri_drawable.c @@ -32,6 +32,7 @@ #include "dri_screen.h" #include "dri_context.h" #include "dri_drawable.h" +#include "dri1.h" #include "pipe/p_context.h" #include "pipe/p_screen.h" diff --git a/src/gallium/state_trackers/dri/dri_drawable.h b/src/gallium/state_trackers/dri/dri_drawable.h index 8bc59cb4c3d..80bd2f5bdf0 100644 --- a/src/gallium/state_trackers/dri/dri_drawable.h +++ b/src/gallium/state_trackers/dri/dri_drawable.h @@ -29,6 +29,7 @@ #define DRI_DRAWABLE_H #include "pipe/p_compiler.h" +#include "pipe/p_format.h" struct pipe_surface; struct pipe_fence_handle; diff --git a/src/gallium/state_trackers/dri/dri_screen.c b/src/gallium/state_trackers/dri/dri_screen.c index 7ccad8f5dd6..8a586d637fc 100644 --- a/src/gallium/state_trackers/dri/dri_screen.c +++ b/src/gallium/state_trackers/dri/dri_screen.c @@ -36,6 +36,7 @@ #include "dri_screen.h" #include "dri_context.h" #include "dri_drawable.h" +#include "dri1.h" #include "pipe/p_screen.h" #include "pipe/p_format.h" @@ -53,7 +54,7 @@ PUBLIC const char __driConfigOptions[] = DRI_CONF_ALLOW_LARGE_TEXTURES(1) DRI_CONF_SECTION_END DRI_CONF_END; - const uint __driNConfigOptions = 3; +const uint __driNConfigOptions = 3; static const __DRItexBufferExtension dri2TexBufferExtension = { { __DRI_TEX_BUFFER, __DRI_TEX_BUFFER_VERSION }, @@ -83,9 +84,7 @@ static const __DRI2flushExtension dri2FlushExtension = { NULL }; -struct dri1_api *__dri1_api_hooks = NULL; - -static const __DRIconfig ** +const __DRIconfig ** dri_fill_in_modes(struct dri_screen *screen, unsigned pixel_bits) { @@ -240,75 +239,6 @@ dri_get_swap_info(__DRIdrawable * dPriv, __DRIswapInfo * sInfo) return 0; } -static INLINE void -dri_copy_version(struct dri1_api_version *dst, - const struct __DRIversionRec *src) -{ - dst->major = src->major; - dst->minor = src->minor; - dst->patch_level = src->patch; -} - -static const __DRIconfig ** -dri_init_screen(__DRIscreen * sPriv) -{ - struct dri_screen *screen; - const __DRIconfig **configs; - struct dri1_create_screen_arg arg; - - screen = CALLOC_STRUCT(dri_screen); - if (!screen) - return NULL; - - screen->api = drm_api_create(); - screen->sPriv = sPriv; - screen->fd = sPriv->fd; - screen->drmLock = (drmLock *) & sPriv->pSAREA->lock; - - sPriv->private = (void *)screen; - sPriv->extensions = dri_screen_extensions; - - arg.base.mode = DRM_CREATE_DRI1; - arg.lf = &dri1_lf; - arg.ddx_info = sPriv->pDevPriv; - arg.ddx_info_size = sPriv->devPrivSize; - arg.sarea = sPriv->pSAREA; - dri_copy_version(&arg.ddx_version, &sPriv->ddx_version); - dri_copy_version(&arg.dri_version, &sPriv->dri_version); - dri_copy_version(&arg.drm_version, &sPriv->drm_version); - arg.api = NULL; - - screen->pipe_screen = screen->api->create_screen(screen->api, screen->fd, &arg.base); - - if (!screen->pipe_screen || !arg.api) { - debug_printf("%s: failed to create dri1 screen\n", __FUNCTION__); - goto out_no_screen; - } - - __dri1_api_hooks = arg.api; - - screen->pipe_screen->flush_frontbuffer = dri1_flush_frontbuffer; - driParseOptionInfo(&screen->optionCache, - __driConfigOptions, __driNConfigOptions); - - /** - * FIXME: If the driver supports format conversion swapbuffer blits, we might - * want to support other color bit depths than the server is currently - * using. - */ - - configs = dri_fill_in_modes(screen, sPriv->fbBPP); - if (!configs) - goto out_no_configs; - - return configs; - out_no_configs: - screen->pipe_screen->destroy(screen->pipe_screen); - out_no_screen: - FREE(screen); - return NULL; -} - /** * This is the driver specific part of the createNewScreen entry point. * @@ -375,7 +305,6 @@ dri_destroy_screen(__DRIscreen * sPriv) } PUBLIC const struct __DriverAPIRec driDriverAPI = { - .InitScreen = dri_init_screen, .DestroyScreen = dri_destroy_screen, .CreateContext = dri_create_context, .DestroyContext = dri_destroy_context, @@ -388,7 +317,7 @@ PUBLIC const struct __DriverAPIRec driDriverAPI = { .GetDrawableMSC = driDrawableGetMSC32, .WaitForMSC = driWaitForMSC32, .CopySubBuffer = dri_copy_sub_buffer, - .InitScreen = dri_init_screen, + .InitScreen = dri1_init_screen, .InitScreen2 = dri_init_screen2, }; diff --git a/src/gallium/state_trackers/dri/dri_screen.h b/src/gallium/state_trackers/dri/dri_screen.h index 75a0ee4250e..31301356923 100644 --- a/src/gallium/state_trackers/dri/dri_screen.h +++ b/src/gallium/state_trackers/dri/dri_screen.h @@ -37,8 +37,6 @@ #include "pipe/p_compiler.h" -#include "state_tracker/dri1_api.h" - struct dri_screen { /* dri */ @@ -69,11 +67,10 @@ dri_screen(__DRIscreen * sPriv) return (struct dri_screen *)sPriv->private; } -/*********************************************************************** - * dri_screen.c - */ +extern const uint __driNConfigOptions; -extern struct dri1_api *__dri1_api_hooks; +const __DRIconfig ** +dri_fill_in_modes(struct dri_screen *screen, unsigned pixel_bits); #endif -- cgit v1.2.3 From a437bc50f2f8ff6e91fdf4dc9758b35cff35645a Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Tue, 16 Mar 2010 10:25:50 +0800 Subject: st/dri: Move DRI1 bits in dri_drawable.c to dri1.c. --- src/gallium/state_trackers/dri/dri1.c | 314 ++++++++++++++++++++++++++ src/gallium/state_trackers/dri/dri1.h | 16 ++ src/gallium/state_trackers/dri/dri_drawable.c | 306 +------------------------ src/gallium/state_trackers/dri/dri_drawable.h | 12 - src/gallium/state_trackers/dri/dri_screen.c | 7 +- 5 files changed, 336 insertions(+), 319 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/dri/dri1.c b/src/gallium/state_trackers/dri/dri1.c index 1222f42e237..2d809459ca2 100644 --- a/src/gallium/state_trackers/dri/dri1.c +++ b/src/gallium/state_trackers/dri/dri1.c @@ -30,12 +30,326 @@ */ #include "util/u_memory.h" +#include "util/u_rect.h" +#include "pipe/p_context.h" +#include "state_tracker/st_context.h" +#include "state_tracker/st_public.h" #include "dri_screen.h" #include "dri_context.h" #include "dri_drawable.h" #include "dri1.h" +static struct pipe_fence_handle * +dri_swap_fences_pop_front(struct dri_drawable *draw) +{ + struct pipe_screen *screen = dri_screen(draw->sPriv)->pipe_screen; + struct pipe_fence_handle *fence = NULL; + + if (draw->cur_fences >= draw->desired_fences) { + screen->fence_reference(screen, &fence, draw->swap_fences[draw->tail]); + screen->fence_reference(screen, &draw->swap_fences[draw->tail++], NULL); + --draw->cur_fences; + draw->tail &= DRI_SWAP_FENCES_MASK; + } + return fence; +} + +static void +dri_swap_fences_push_back(struct dri_drawable *draw, + struct pipe_fence_handle *fence) +{ + struct pipe_screen *screen = dri_screen(draw->sPriv)->pipe_screen; + + if (!fence) + return; + + if (draw->cur_fences < DRI_SWAP_FENCES_MAX) { + draw->cur_fences++; + screen->fence_reference(screen, &draw->swap_fences[draw->head++], + fence); + draw->head &= DRI_SWAP_FENCES_MASK; + } +} + +void +dri1_swap_fences_clear(struct dri_drawable *drawable) +{ + struct pipe_screen *screen = dri_screen(drawable->sPriv)->pipe_screen; + struct pipe_fence_handle *fence; + + while (drawable->cur_fences) { + fence = dri_swap_fences_pop_front(drawable); + screen->fence_reference(screen, &fence, NULL); + } +} + +static void +dri1_update_drawables_locked(struct dri_context *ctx, + __DRIdrawable * driDrawPriv, + __DRIdrawable * driReadPriv) +{ + if (ctx->stLostLock) { + ctx->stLostLock = FALSE; + if (driDrawPriv == driReadPriv) + DRI_VALIDATE_DRAWABLE_INFO(ctx->sPriv, driDrawPriv); + else + DRI_VALIDATE_TWO_DRAWABLES_INFO(ctx->sPriv, driDrawPriv, + driReadPriv); + } +} + +/** + * This ensures all contexts which bind to a drawable pick up the + * drawable change and signal new buffer state. + * Calling st_resize_framebuffer for each context may seem like overkill, + * but no new buffers will actually be allocated if the dimensions don't + * change. + */ + +static void +dri1_propagate_drawable_change(struct dri_context *ctx) +{ + __DRIdrawable *dPriv = ctx->dPriv; + __DRIdrawable *rPriv = ctx->rPriv; + boolean flushed = FALSE; + + if (dPriv && ctx->d_stamp != dPriv->lastStamp) { + + st_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); + flushed = TRUE; + ctx->d_stamp = dPriv->lastStamp; + st_resize_framebuffer(dri_drawable(dPriv)->stfb, dPriv->w, dPriv->h); + + } + + if (rPriv && dPriv != rPriv && ctx->r_stamp != rPriv->lastStamp) { + + if (!flushed) + st_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); + ctx->r_stamp = rPriv->lastStamp; + st_resize_framebuffer(dri_drawable(rPriv)->stfb, rPriv->w, rPriv->h); + + } else if (rPriv && dPriv == rPriv) { + + ctx->r_stamp = ctx->d_stamp; + + } +} + +void +dri1_update_drawables(struct dri_context *ctx, + struct dri_drawable *draw, struct dri_drawable *read) +{ + dri_lock(ctx); + dri1_update_drawables_locked(ctx, draw->dPriv, read->dPriv); + dri_unlock(ctx); + + dri1_propagate_drawable_change(ctx); +} + +static INLINE boolean +dri1_intersect_src_bbox(struct drm_clip_rect *dst, + int dst_x, + int dst_y, + const struct drm_clip_rect *src, + const struct drm_clip_rect *bbox) +{ + int xy1; + int xy2; + + xy1 = ((int)src->x1 > (int)bbox->x1 + dst_x) ? src->x1 : + (int)bbox->x1 + dst_x; + xy2 = ((int)src->x2 < (int)bbox->x2 + dst_x) ? src->x2 : + (int)bbox->x2 + dst_x; + if (xy1 >= xy2 || xy1 < 0) + return FALSE; + + dst->x1 = xy1; + dst->x2 = xy2; + + xy1 = ((int)src->y1 > (int)bbox->y1 + dst_y) ? src->y1 : + (int)bbox->y1 + dst_y; + xy2 = ((int)src->y2 < (int)bbox->y2 + dst_y) ? src->y2 : + (int)bbox->y2 + dst_y; + if (xy1 >= xy2 || xy1 < 0) + return FALSE; + + dst->y1 = xy1; + dst->y2 = xy2; + return TRUE; +} + +static void +dri1_swap_copy(struct dri_context *ctx, + struct pipe_surface *dst, + struct pipe_surface *src, + __DRIdrawable * dPriv, const struct drm_clip_rect *bbox) +{ + struct pipe_context *pipe = ctx->pipe; + struct drm_clip_rect clip; + struct drm_clip_rect *cur; + int i; + + cur = dPriv->pClipRects; + + for (i = 0; i < dPriv->numClipRects; ++i) { + if (dri1_intersect_src_bbox(&clip, dPriv->x, dPriv->y, cur++, bbox)) { + if (pipe->surface_copy) { + pipe->surface_copy(pipe, dst, clip.x1, clip.y1, + src, + (int)clip.x1 - dPriv->x, + (int)clip.y1 - dPriv->y, + clip.x2 - clip.x1, clip.y2 - clip.y1); + } else { + util_surface_copy(pipe, FALSE, dst, clip.x1, clip.y1, + src, + (int)clip.x1 - dPriv->x, + (int)clip.y1 - dPriv->y, + clip.x2 - clip.x1, clip.y2 - clip.y1); + } + } + } +} + +static void +dri1_copy_to_front(struct dri_context *ctx, + struct pipe_surface *surf, + __DRIdrawable * dPriv, + const struct drm_clip_rect *sub_box, + struct pipe_fence_handle **fence) +{ + struct pipe_context *pipe = ctx->pipe; + boolean save_lost_lock; + uint cur_w; + uint cur_h; + struct drm_clip_rect bbox; + boolean visible = TRUE; + + *fence = NULL; + + dri_lock(ctx); + save_lost_lock = ctx->stLostLock; + dri1_update_drawables_locked(ctx, dPriv, dPriv); + st_get_framebuffer_dimensions(dri_drawable(dPriv)->stfb, &cur_w, &cur_h); + + bbox.x1 = 0; + bbox.x2 = cur_w; + bbox.y1 = 0; + bbox.y2 = cur_h; + + if (sub_box) + visible = dri1_intersect_src_bbox(&bbox, 0, 0, &bbox, sub_box); + + if (visible && __dri1_api_hooks->present_locked) { + + __dri1_api_hooks->present_locked(pipe, + surf, + dPriv->pClipRects, + dPriv->numClipRects, + dPriv->x, dPriv->y, &bbox, fence); + + } else if (visible && __dri1_api_hooks->front_srf_locked) { + + struct pipe_surface *front = __dri1_api_hooks->front_srf_locked(pipe); + + if (front) + dri1_swap_copy(ctx, front, surf, dPriv, &bbox); + + st_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, fence); + } + + ctx->stLostLock = save_lost_lock; + + /** + * FIXME: Revisit this: Update drawables on copy_sub_buffer ? + */ + + if (!sub_box) + dri1_update_drawables_locked(ctx, ctx->dPriv, ctx->rPriv); + + dri_unlock(ctx); + dri1_propagate_drawable_change(ctx); +} + +void +dri1_flush_frontbuffer(struct pipe_screen *screen, + struct pipe_surface *surf, void *context_private) +{ + struct dri_context *ctx = (struct dri_context *)context_private; + struct pipe_fence_handle *dummy_fence; + + dri1_copy_to_front(ctx, surf, ctx->dPriv, NULL, &dummy_fence); + screen->fence_reference(screen, &dummy_fence, NULL); + + /** + * FIXME: Do we need swap throttling here? + */ +} + +void +dri1_swap_buffers(__DRIdrawable * dPriv) +{ + struct dri_context *ctx; + struct pipe_surface *back_surf; + struct dri_drawable *draw = dri_drawable(dPriv); + struct pipe_screen *screen = dri_screen(draw->sPriv)->pipe_screen; + struct pipe_fence_handle *fence; + struct st_context *st = st_get_current(); + + assert(__dri1_api_hooks != NULL); + + if (!st) + return; /* For now */ + + ctx = (struct dri_context *)st->pipe->priv; + + st_get_framebuffer_surface(draw->stfb, ST_SURFACE_BACK_LEFT, &back_surf); + if (back_surf) { + st_notify_swapbuffers(draw->stfb); + st_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); + fence = dri_swap_fences_pop_front(draw); + if (fence) { + (void)screen->fence_finish(screen, fence, 0); + screen->fence_reference(screen, &fence, NULL); + } + dri1_copy_to_front(ctx, back_surf, dPriv, NULL, &fence); + dri_swap_fences_push_back(draw, fence); + screen->fence_reference(screen, &fence, NULL); + } +} + +void +dri1_copy_sub_buffer(__DRIdrawable * dPriv, int x, int y, int w, int h) +{ + struct pipe_screen *screen = dri_screen(dPriv->driScreenPriv)->pipe_screen; + struct drm_clip_rect sub_bbox; + struct dri_context *ctx; + struct pipe_surface *back_surf; + struct dri_drawable *draw = dri_drawable(dPriv); + struct pipe_fence_handle *dummy_fence; + struct st_context *st = st_get_current(); + + assert(__dri1_api_hooks != NULL); + + if (!st) + return; + + ctx = (struct dri_context *)st->pipe->priv; + + sub_bbox.x1 = x; + sub_bbox.x2 = x + w; + sub_bbox.y1 = y; + sub_bbox.y2 = y + h; + + st_get_framebuffer_surface(draw->stfb, ST_SURFACE_BACK_LEFT, &back_surf); + if (back_surf) { + st_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); + dri1_copy_to_front(ctx, back_surf, dPriv, &sub_bbox, &dummy_fence); + screen->fence_reference(screen, &dummy_fence, NULL); + } +} + static const __DRIextension *dri1_screen_extensions[] = { &driReadDrawableExtension, &driCopySubBufferExtension.base, diff --git a/src/gallium/state_trackers/dri/dri1.h b/src/gallium/state_trackers/dri/dri1.h index 731b13cb06f..b2304af7e1a 100644 --- a/src/gallium/state_trackers/dri/dri1.h +++ b/src/gallium/state_trackers/dri/dri1.h @@ -40,4 +40,20 @@ extern struct dri1_api *__dri1_api_hooks; const __DRIconfig ** dri1_init_screen(__DRIscreen * sPriv); +void +dri1_update_drawables(struct dri_context *ctx, + struct dri_drawable *draw, struct dri_drawable *read); + +void +dri1_flush_frontbuffer(struct pipe_screen *screen, + struct pipe_surface *surf, void *context_private); + +void dri1_swap_buffers(__DRIdrawable * dPriv); + +void +dri1_copy_sub_buffer(__DRIdrawable * dPriv, int x, int y, int w, int h); + +void +dri1_swap_fences_clear(struct dri_drawable *drawable); + #endif /* DRI1_H */ diff --git a/src/gallium/state_trackers/dri/dri_drawable.c b/src/gallium/state_trackers/dri/dri_drawable.c index 83b1a29681b..6c4de71c89f 100644 --- a/src/gallium/state_trackers/dri/dri_drawable.c +++ b/src/gallium/state_trackers/dri/dri_drawable.c @@ -448,319 +448,17 @@ fail: return GL_FALSE; } -static struct pipe_fence_handle * -dri_swap_fences_pop_front(struct dri_drawable *draw) -{ - struct pipe_screen *screen = dri_screen(draw->sPriv)->pipe_screen; - struct pipe_fence_handle *fence = NULL; - - if (draw->cur_fences >= draw->desired_fences) { - screen->fence_reference(screen, &fence, draw->swap_fences[draw->tail]); - screen->fence_reference(screen, &draw->swap_fences[draw->tail++], NULL); - --draw->cur_fences; - draw->tail &= DRI_SWAP_FENCES_MASK; - } - return fence; -} - -static void -dri_swap_fences_push_back(struct dri_drawable *draw, - struct pipe_fence_handle *fence) -{ - struct pipe_screen *screen = dri_screen(draw->sPriv)->pipe_screen; - - if (!fence) - return; - - if (draw->cur_fences < DRI_SWAP_FENCES_MAX) { - draw->cur_fences++; - screen->fence_reference(screen, &draw->swap_fences[draw->head++], - fence); - draw->head &= DRI_SWAP_FENCES_MASK; - } -} - void dri_destroy_buffer(__DRIdrawable * dPriv) { struct dri_drawable *drawable = dri_drawable(dPriv); - struct pipe_fence_handle *fence; - struct pipe_screen *screen = dri_screen(drawable->sPriv)->pipe_screen; st_unreference_framebuffer(drawable->stfb); drawable->desired_fences = 0; - while (drawable->cur_fences) { - fence = dri_swap_fences_pop_front(drawable); - screen->fence_reference(screen, &fence, NULL); - } - - FREE(drawable); -} - -static void -dri1_update_drawables_locked(struct dri_context *ctx, - __DRIdrawable * driDrawPriv, - __DRIdrawable * driReadPriv) -{ - if (ctx->stLostLock) { - ctx->stLostLock = FALSE; - if (driDrawPriv == driReadPriv) - DRI_VALIDATE_DRAWABLE_INFO(ctx->sPriv, driDrawPriv); - else - DRI_VALIDATE_TWO_DRAWABLES_INFO(ctx->sPriv, driDrawPriv, - driReadPriv); - } -} - -/** - * This ensures all contexts which bind to a drawable pick up the - * drawable change and signal new buffer state. - * Calling st_resize_framebuffer for each context may seem like overkill, - * but no new buffers will actually be allocated if the dimensions don't - * change. - */ - -static void -dri1_propagate_drawable_change(struct dri_context *ctx) -{ - __DRIdrawable *dPriv = ctx->dPriv; - __DRIdrawable *rPriv = ctx->rPriv; - boolean flushed = FALSE; - - if (dPriv && ctx->d_stamp != dPriv->lastStamp) { - - st_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); - flushed = TRUE; - ctx->d_stamp = dPriv->lastStamp; - st_resize_framebuffer(dri_drawable(dPriv)->stfb, dPriv->w, dPriv->h); - - } - - if (rPriv && dPriv != rPriv && ctx->r_stamp != rPriv->lastStamp) { - - if (!flushed) - st_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); - ctx->r_stamp = rPriv->lastStamp; - st_resize_framebuffer(dri_drawable(rPriv)->stfb, rPriv->w, rPriv->h); - - } else if (rPriv && dPriv == rPriv) { - - ctx->r_stamp = ctx->d_stamp; - - } -} - -void -dri1_update_drawables(struct dri_context *ctx, - struct dri_drawable *draw, struct dri_drawable *read) -{ - dri_lock(ctx); - dri1_update_drawables_locked(ctx, draw->dPriv, read->dPriv); - dri_unlock(ctx); - - dri1_propagate_drawable_change(ctx); -} - -static INLINE boolean -dri1_intersect_src_bbox(struct drm_clip_rect *dst, - int dst_x, - int dst_y, - const struct drm_clip_rect *src, - const struct drm_clip_rect *bbox) -{ - int xy1; - int xy2; - - xy1 = ((int)src->x1 > (int)bbox->x1 + dst_x) ? src->x1 : - (int)bbox->x1 + dst_x; - xy2 = ((int)src->x2 < (int)bbox->x2 + dst_x) ? src->x2 : - (int)bbox->x2 + dst_x; - if (xy1 >= xy2 || xy1 < 0) - return FALSE; - - dst->x1 = xy1; - dst->x2 = xy2; - - xy1 = ((int)src->y1 > (int)bbox->y1 + dst_y) ? src->y1 : - (int)bbox->y1 + dst_y; - xy2 = ((int)src->y2 < (int)bbox->y2 + dst_y) ? src->y2 : - (int)bbox->y2 + dst_y; - if (xy1 >= xy2 || xy1 < 0) - return FALSE; - - dst->y1 = xy1; - dst->y2 = xy2; - return TRUE; -} - -static void -dri1_swap_copy(struct dri_context *ctx, - struct pipe_surface *dst, - struct pipe_surface *src, - __DRIdrawable * dPriv, const struct drm_clip_rect *bbox) -{ - struct pipe_context *pipe = ctx->pipe; - struct drm_clip_rect clip; - struct drm_clip_rect *cur; - int i; - cur = dPriv->pClipRects; + dri1_swap_fences_clear(drawable); - for (i = 0; i < dPriv->numClipRects; ++i) { - if (dri1_intersect_src_bbox(&clip, dPriv->x, dPriv->y, cur++, bbox)) { - if (pipe->surface_copy) { - pipe->surface_copy(pipe, dst, clip.x1, clip.y1, - src, - (int)clip.x1 - dPriv->x, - (int)clip.y1 - dPriv->y, - clip.x2 - clip.x1, clip.y2 - clip.y1); - } else { - util_surface_copy(pipe, FALSE, dst, clip.x1, clip.y1, - src, - (int)clip.x1 - dPriv->x, - (int)clip.y1 - dPriv->y, - clip.x2 - clip.x1, clip.y2 - clip.y1); - } - } - } -} - -static void -dri1_copy_to_front(struct dri_context *ctx, - struct pipe_surface *surf, - __DRIdrawable * dPriv, - const struct drm_clip_rect *sub_box, - struct pipe_fence_handle **fence) -{ - struct pipe_context *pipe = ctx->pipe; - boolean save_lost_lock; - uint cur_w; - uint cur_h; - struct drm_clip_rect bbox; - boolean visible = TRUE; - - *fence = NULL; - - dri_lock(ctx); - save_lost_lock = ctx->stLostLock; - dri1_update_drawables_locked(ctx, dPriv, dPriv); - st_get_framebuffer_dimensions(dri_drawable(dPriv)->stfb, &cur_w, &cur_h); - - bbox.x1 = 0; - bbox.x2 = cur_w; - bbox.y1 = 0; - bbox.y2 = cur_h; - - if (sub_box) - visible = dri1_intersect_src_bbox(&bbox, 0, 0, &bbox, sub_box); - - if (visible && __dri1_api_hooks->present_locked) { - - __dri1_api_hooks->present_locked(pipe, - surf, - dPriv->pClipRects, - dPriv->numClipRects, - dPriv->x, dPriv->y, &bbox, fence); - - } else if (visible && __dri1_api_hooks->front_srf_locked) { - - struct pipe_surface *front = __dri1_api_hooks->front_srf_locked(pipe); - - if (front) - dri1_swap_copy(ctx, front, surf, dPriv, &bbox); - - st_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, fence); - } - - ctx->stLostLock = save_lost_lock; - - /** - * FIXME: Revisit this: Update drawables on copy_sub_buffer ? - */ - - if (!sub_box) - dri1_update_drawables_locked(ctx, ctx->dPriv, ctx->rPriv); - - dri_unlock(ctx); - dri1_propagate_drawable_change(ctx); -} - -void -dri1_flush_frontbuffer(struct pipe_screen *screen, - struct pipe_surface *surf, void *context_private) -{ - struct dri_context *ctx = (struct dri_context *)context_private; - struct pipe_fence_handle *dummy_fence; - - dri1_copy_to_front(ctx, surf, ctx->dPriv, NULL, &dummy_fence); - screen->fence_reference(screen, &dummy_fence, NULL); - - /** - * FIXME: Do we need swap throttling here? - */ -} - -void -dri_swap_buffers(__DRIdrawable * dPriv) -{ - struct dri_context *ctx; - struct pipe_surface *back_surf; - struct dri_drawable *draw = dri_drawable(dPriv); - struct pipe_screen *screen = dri_screen(draw->sPriv)->pipe_screen; - struct pipe_fence_handle *fence; - struct st_context *st = st_get_current(); - - assert(__dri1_api_hooks != NULL); - - if (!st) - return; /* For now */ - - ctx = (struct dri_context *)st->pipe->priv; - - st_get_framebuffer_surface(draw->stfb, ST_SURFACE_BACK_LEFT, &back_surf); - if (back_surf) { - st_notify_swapbuffers(draw->stfb); - st_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); - fence = dri_swap_fences_pop_front(draw); - if (fence) { - (void)screen->fence_finish(screen, fence, 0); - screen->fence_reference(screen, &fence, NULL); - } - dri1_copy_to_front(ctx, back_surf, dPriv, NULL, &fence); - dri_swap_fences_push_back(draw, fence); - screen->fence_reference(screen, &fence, NULL); - } -} - -void -dri_copy_sub_buffer(__DRIdrawable * dPriv, int x, int y, int w, int h) -{ - struct pipe_screen *screen = dri_screen(dPriv->driScreenPriv)->pipe_screen; - struct drm_clip_rect sub_bbox; - struct dri_context *ctx; - struct pipe_surface *back_surf; - struct dri_drawable *draw = dri_drawable(dPriv); - struct pipe_fence_handle *dummy_fence; - struct st_context *st = st_get_current(); - - assert(__dri1_api_hooks != NULL); - - if (!st) - return; - - ctx = (struct dri_context *)st->pipe->priv; - - sub_bbox.x1 = x; - sub_bbox.x2 = x + w; - sub_bbox.y1 = y; - sub_bbox.y2 = y + h; - - st_get_framebuffer_surface(draw->stfb, ST_SURFACE_BACK_LEFT, &back_surf); - if (back_surf) { - st_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); - dri1_copy_to_front(ctx, back_surf, dPriv, &sub_bbox, &dummy_fence); - screen->fence_reference(screen, &dummy_fence, NULL); - } + FREE(drawable); } /* vim: set sw=3 ts=8 sts=3 expandtab: */ diff --git a/src/gallium/state_trackers/dri/dri_drawable.h b/src/gallium/state_trackers/dri/dri_drawable.h index 80bd2f5bdf0..48d24e959c0 100644 --- a/src/gallium/state_trackers/dri/dri_drawable.h +++ b/src/gallium/state_trackers/dri/dri_drawable.h @@ -88,11 +88,6 @@ void dri_flush_frontbuffer(struct pipe_screen *screen, struct pipe_surface *surf, void *context_private); -void dri_swap_buffers(__DRIdrawable * dPriv); - -void -dri_copy_sub_buffer(__DRIdrawable * dPriv, int x, int y, int w, int h); - void dri_get_buffers(__DRIdrawable * dPriv); void dri_destroy_buffer(__DRIdrawable * dPriv); @@ -103,13 +98,6 @@ void dri2_set_tex_buffer2(__DRIcontext *pDRICtx, GLint target, void dri2_set_tex_buffer(__DRIcontext *pDRICtx, GLint target, __DRIdrawable *dPriv); -void -dri1_update_drawables(struct dri_context *ctx, - struct dri_drawable *draw, struct dri_drawable *read); - -void -dri1_flush_frontbuffer(struct pipe_screen *screen, - struct pipe_surface *surf, void *context_private); #endif /* vim: set sw=3 ts=8 sts=3 expandtab: */ diff --git a/src/gallium/state_trackers/dri/dri_screen.c b/src/gallium/state_trackers/dri/dri_screen.c index 8a586d637fc..b6cd92d0f85 100644 --- a/src/gallium/state_trackers/dri/dri_screen.c +++ b/src/gallium/state_trackers/dri/dri_screen.c @@ -310,15 +310,16 @@ PUBLIC const struct __DriverAPIRec driDriverAPI = { .DestroyContext = dri_destroy_context, .CreateBuffer = dri_create_buffer, .DestroyBuffer = dri_destroy_buffer, - .SwapBuffers = dri_swap_buffers, .MakeCurrent = dri_make_current, .UnbindContext = dri_unbind_context, .GetSwapInfo = dri_get_swap_info, .GetDrawableMSC = driDrawableGetMSC32, .WaitForMSC = driWaitForMSC32, - .CopySubBuffer = dri_copy_sub_buffer, - .InitScreen = dri1_init_screen, .InitScreen2 = dri_init_screen2, + + .InitScreen = dri1_init_screen, + .SwapBuffers = dri1_swap_buffers, + .CopySubBuffer = dri1_copy_sub_buffer, }; /* This is the table of extensions that the loader will dlsym() for. */ -- cgit v1.2.3 From 61631a89a3268925c89934c77ed7c2482eaa1fd1 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Tue, 16 Mar 2010 10:31:40 +0800 Subject: st/dri: Move DRI1 bits in dri_context.c to dri1.c. --- src/gallium/state_trackers/dri/dri1.c | 68 ++++++++++++++++++++++++++-- src/gallium/state_trackers/dri/dri_context.c | 38 ---------------- src/gallium/state_trackers/dri/dri_context.h | 24 ---------- 3 files changed, 64 insertions(+), 66 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/dri/dri1.c b/src/gallium/state_trackers/dri/dri1.c index 2d809459ca2..a4284f6fe7a 100644 --- a/src/gallium/state_trackers/dri/dri1.c +++ b/src/gallium/state_trackers/dri/dri1.c @@ -40,6 +40,28 @@ #include "dri_drawable.h" #include "dri1.h" +static INLINE void +dri1_lock(struct dri_context *ctx) +{ + drm_context_t hw_context = ctx->cPriv->hHWContext; + char ret = 0; + + DRM_CAS(ctx->lock, hw_context, DRM_LOCK_HELD | hw_context, ret); + if (ret) { + drmGetLock(ctx->sPriv->fd, hw_context, 0); + ctx->stLostLock = TRUE; + ctx->wsLostLock = TRUE; + } + ctx->isLocked = TRUE; +} + +static INLINE void +dri1_unlock(struct dri_context *ctx) +{ + ctx->isLocked = FALSE; + DRM_UNLOCK(ctx->sPriv->fd, ctx->lock, ctx->cPriv->hHWContext); +} + static struct pipe_fence_handle * dri_swap_fences_pop_front(struct dri_drawable *draw) { @@ -141,9 +163,9 @@ void dri1_update_drawables(struct dri_context *ctx, struct dri_drawable *draw, struct dri_drawable *read) { - dri_lock(ctx); + dri1_lock(ctx); dri1_update_drawables_locked(ctx, draw->dPriv, read->dPriv); - dri_unlock(ctx); + dri1_unlock(ctx); dri1_propagate_drawable_change(ctx); } @@ -228,7 +250,7 @@ dri1_copy_to_front(struct dri_context *ctx, *fence = NULL; - dri_lock(ctx); + dri1_lock(ctx); save_lost_lock = ctx->stLostLock; dri1_update_drawables_locked(ctx, dPriv, dPriv); st_get_framebuffer_dimensions(dri_drawable(dPriv)->stfb, &cur_w, &cur_h); @@ -268,7 +290,7 @@ dri1_copy_to_front(struct dri_context *ctx, if (!sub_box) dri1_update_drawables_locked(ctx, ctx->dPriv, ctx->rPriv); - dri_unlock(ctx); + dri1_unlock(ctx); dri1_propagate_drawable_change(ctx); } @@ -350,6 +372,44 @@ dri1_copy_sub_buffer(__DRIdrawable * dPriv, int x, int y, int w, int h) } } +static void +st_dri_lock(struct pipe_context *pipe) +{ + dri1_lock((struct dri_context *)pipe->priv); +} + +static void +st_dri_unlock(struct pipe_context *pipe) +{ + dri1_unlock((struct dri_context *)pipe->priv); +} + +static boolean +st_dri_is_locked(struct pipe_context *pipe) +{ + return ((struct dri_context *)pipe->priv)->isLocked; +} + +static boolean +st_dri_lost_lock(struct pipe_context *pipe) +{ + return ((struct dri_context *)pipe->priv)->wsLostLock; +} + +static void +st_dri_clear_lost_lock(struct pipe_context *pipe) +{ + ((struct dri_context *)pipe->priv)->wsLostLock = FALSE; +} + +static struct dri1_api_lock_funcs dri1_lf = { + .lock = st_dri_lock, + .unlock = st_dri_unlock, + .is_locked = st_dri_is_locked, + .is_lock_lost = st_dri_lost_lock, + .clear_lost_lock = st_dri_clear_lost_lock +}; + static const __DRIextension *dri1_screen_extensions[] = { &driReadDrawableExtension, &driCopySubBufferExtension.base, diff --git a/src/gallium/state_trackers/dri/dri_context.c b/src/gallium/state_trackers/dri/dri_context.c index a5ed0006dc9..58f2b17585d 100644 --- a/src/gallium/state_trackers/dri/dri_context.c +++ b/src/gallium/state_trackers/dri/dri_context.c @@ -182,42 +182,4 @@ dri_make_current(__DRIcontext * cPriv, return GL_TRUE; } -static void -st_dri_lock(struct pipe_context *pipe) -{ - dri_lock((struct dri_context *)pipe->priv); -} - -static void -st_dri_unlock(struct pipe_context *pipe) -{ - dri_unlock((struct dri_context *)pipe->priv); -} - -static boolean -st_dri_is_locked(struct pipe_context *pipe) -{ - return ((struct dri_context *)pipe->priv)->isLocked; -} - -static boolean -st_dri_lost_lock(struct pipe_context *pipe) -{ - return ((struct dri_context *)pipe->priv)->wsLostLock; -} - -static void -st_dri_clear_lost_lock(struct pipe_context *pipe) -{ - ((struct dri_context *)pipe->priv)->wsLostLock = FALSE; -} - -struct dri1_api_lock_funcs dri1_lf = { - .lock = st_dri_lock, - .unlock = st_dri_unlock, - .is_locked = st_dri_is_locked, - .is_lock_lost = st_dri_lost_lock, - .clear_lost_lock = st_dri_clear_lost_lock -}; - /* vim: set sw=3 ts=8 sts=3 expandtab: */ diff --git a/src/gallium/state_trackers/dri/dri_context.h b/src/gallium/state_trackers/dri/dri_context.h index 13f497462f7..f0700b9aaff 100644 --- a/src/gallium/state_trackers/dri/dri_context.h +++ b/src/gallium/state_trackers/dri/dri_context.h @@ -72,33 +72,9 @@ dri_context(__DRIcontext * driContextPriv) return (struct dri_context *)driContextPriv->driverPrivate; } -static INLINE void -dri_lock(struct dri_context *ctx) -{ - drm_context_t hw_context = ctx->cPriv->hHWContext; - char ret = 0; - - DRM_CAS(ctx->lock, hw_context, DRM_LOCK_HELD | hw_context, ret); - if (ret) { - drmGetLock(ctx->sPriv->fd, hw_context, 0); - ctx->stLostLock = TRUE; - ctx->wsLostLock = TRUE; - } - ctx->isLocked = TRUE; -} - -static INLINE void -dri_unlock(struct dri_context *ctx) -{ - ctx->isLocked = FALSE; - DRM_UNLOCK(ctx->sPriv->fd, ctx->lock, ctx->cPriv->hHWContext); -} - /*********************************************************************** * dri_context.c */ -extern struct dri1_api_lock_funcs dri1_lf; - void dri_destroy_context(__DRIcontext * driContextPriv); boolean dri_unbind_context(__DRIcontext * driContextPriv); -- cgit v1.2.3 From 903b90926c7aebb7f48f3c0fdbe90cd22dd5b662 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Tue, 16 Mar 2010 10:55:40 +0800 Subject: st/dri: Headers and public symbols clean up. Remove unused headers and stop marking driDriverAPI as PUBLIC. --- src/gallium/state_trackers/dri/dri1.c | 1 + src/gallium/state_trackers/dri/dri1.h | 3 ++- src/gallium/state_trackers/dri/dri_context.c | 8 ++------ src/gallium/state_trackers/dri/dri_drawable.c | 7 ++----- src/gallium/state_trackers/dri/dri_screen.c | 3 +-- 5 files changed, 8 insertions(+), 14 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/dri/dri1.c b/src/gallium/state_trackers/dri/dri1.c index a4284f6fe7a..543891f813b 100644 --- a/src/gallium/state_trackers/dri/dri1.c +++ b/src/gallium/state_trackers/dri/dri1.c @@ -34,6 +34,7 @@ #include "pipe/p_context.h" #include "state_tracker/st_context.h" #include "state_tracker/st_public.h" +#include "state_tracker/dri1_api.h" #include "dri_screen.h" #include "dri_context.h" diff --git a/src/gallium/state_trackers/dri/dri1.h b/src/gallium/state_trackers/dri/dri1.h index b2304af7e1a..e525ce64c3f 100644 --- a/src/gallium/state_trackers/dri/dri1.h +++ b/src/gallium/state_trackers/dri/dri1.h @@ -32,7 +32,8 @@ #ifndef DRI1_H #define DRI1_H -#include "state_tracker/dri1_api.h" +#include "dri_context.h" +#include "dri_drawable.h" #include "dri_util.h" extern struct dri1_api *__dri1_api_hooks; diff --git a/src/gallium/state_trackers/dri/dri_context.c b/src/gallium/state_trackers/dri/dri_context.c index 58f2b17585d..8e74d3b9bf1 100644 --- a/src/gallium/state_trackers/dri/dri_context.c +++ b/src/gallium/state_trackers/dri/dri_context.c @@ -30,16 +30,12 @@ */ #include "dri_screen.h" - #include "dri_drawable.h" -#include "state_tracker/drm_api.h" -#include "state_tracker/dri1_api.h" -#include "state_tracker/st_public.h" -#include "pipe/p_context.h" - #include "dri_context.h" #include "dri1.h" +#include "state_tracker/st_public.h" +#include "pipe/p_context.h" #include "util/u_memory.h" GLboolean diff --git a/src/gallium/state_trackers/dri/dri_drawable.c b/src/gallium/state_trackers/dri/dri_drawable.c index 6c4de71c89f..9238f942999 100644 --- a/src/gallium/state_trackers/dri/dri_drawable.c +++ b/src/gallium/state_trackers/dri/dri_drawable.c @@ -34,19 +34,16 @@ #include "dri_drawable.h" #include "dri1.h" -#include "pipe/p_context.h" -#include "pipe/p_screen.h" #include "main/mtypes.h" #include "main/renderbuffer.h" -#include "state_tracker/drm_api.h" -#include "state_tracker/dri1_api.h" #include "state_tracker/st_context.h" #include "state_tracker/st_public.h" #include "state_tracker/st_cb_fbo.h" +#include "state_tracker/drm_api.h" +#include "pipe/p_screen.h" #include "util/u_format.h" #include "util/u_memory.h" -#include "util/u_rect.h" #include "util/u_inlines.h" static struct pipe_surface * diff --git a/src/gallium/state_trackers/dri/dri_screen.c b/src/gallium/state_trackers/dri/dri_screen.c index b6cd92d0f85..cffe3b33b2f 100644 --- a/src/gallium/state_trackers/dri/dri_screen.c +++ b/src/gallium/state_trackers/dri/dri_screen.c @@ -41,7 +41,6 @@ #include "pipe/p_screen.h" #include "pipe/p_format.h" #include "state_tracker/drm_api.h" -#include "state_tracker/dri1_api.h" #include "util/u_debug.h" @@ -304,7 +303,7 @@ dri_destroy_screen(__DRIscreen * sPriv) sPriv->private = NULL; } -PUBLIC const struct __DriverAPIRec driDriverAPI = { +const struct __DriverAPIRec driDriverAPI = { .DestroyScreen = dri_destroy_screen, .CreateContext = dri_create_context, .DestroyContext = dri_destroy_context, -- cgit v1.2.3 From 5ff21634f3074122ed8b8e4019c8092e31be0335 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Mon, 8 Mar 2010 19:25:32 +0800 Subject: st/dri: Implement st_api.h callbacks. This commit adds dri_st_api.c that implements st_api.h callbacks. A following commit will switch st/dri from st_public.h to st_api.h. --- src/gallium/state_trackers/dri/Makefile | 1 + src/gallium/state_trackers/dri/SConscript | 1 + src/gallium/state_trackers/dri/dri_drawable.h | 6 + src/gallium/state_trackers/dri/dri_st_api.c | 442 ++++++++++++++++++++++++++ src/gallium/state_trackers/dri/dri_st_api.h | 55 ++++ 5 files changed, 505 insertions(+) create mode 100644 src/gallium/state_trackers/dri/dri_st_api.c create mode 100644 src/gallium/state_trackers/dri/dri_st_api.h (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/dri/Makefile b/src/gallium/state_trackers/dri/Makefile index 24244417b97..f5af8aa3a67 100644 --- a/src/gallium/state_trackers/dri/Makefile +++ b/src/gallium/state_trackers/dri/Makefile @@ -16,6 +16,7 @@ C_SOURCES = \ dri_screen.c \ dri_drawable.c \ dri_extensions.c \ + dri_st_api.c \ dri1.c # $(TOP)/src/mesa/drivers/dri/common/utils.c \ diff --git a/src/gallium/state_trackers/dri/SConscript b/src/gallium/state_trackers/dri/SConscript index 6310fe06e43..7c67ceecd80 100644 --- a/src/gallium/state_trackers/dri/SConscript +++ b/src/gallium/state_trackers/dri/SConscript @@ -18,6 +18,7 @@ if env['dri']: 'dri_drawable.c', 'dri_extensions.c', 'dri_screen.c', + 'dri_st_api.c', 'dri1.c', ] ) diff --git a/src/gallium/state_trackers/dri/dri_drawable.h b/src/gallium/state_trackers/dri/dri_drawable.h index 48d24e959c0..ea66c483a1e 100644 --- a/src/gallium/state_trackers/dri/dri_drawable.h +++ b/src/gallium/state_trackers/dri/dri_drawable.h @@ -30,6 +30,7 @@ #include "pipe/p_compiler.h" #include "pipe/p_format.h" +#include "state_tracker/st_api.h" struct pipe_surface; struct pipe_fence_handle; @@ -57,6 +58,11 @@ struct dri_drawable /* gallium */ struct st_framebuffer *stfb; + struct st_visual stvis; + + struct pipe_texture *textures[ST_ATTACHMENT_COUNT]; + unsigned int texture_mask, texture_stamp; + struct pipe_fence_handle *swap_fences[DRI_SWAP_FENCES_MAX]; unsigned int head; unsigned int tail; diff --git a/src/gallium/state_trackers/dri/dri_st_api.c b/src/gallium/state_trackers/dri/dri_st_api.c new file mode 100644 index 00000000000..379515152e8 --- /dev/null +++ b/src/gallium/state_trackers/dri/dri_st_api.c @@ -0,0 +1,442 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu + */ + +#include "util/u_memory.h" +#include "util/u_inlines.h" +#include "util/u_format.h" +#include "util/u_debug.h" +#include "state_tracker/drm_api.h" +#include "state_tracker/st_manager.h" /* for st_manager_create_api */ + +#include "dri_screen.h" +#include "dri_context.h" +#include "dri_drawable.h" +#include "dri_st_api.h" +#include "dri1.h" + +static struct { + int32_t refcnt; + struct st_api *stapi; +} dri_st_api; + +/** + * Get the format of an attachment. + */ +static INLINE enum pipe_format +dri_drawable_get_format(struct dri_drawable *drawable, + enum st_attachment_type statt) +{ + enum pipe_format format; + + switch (statt) { + case ST_ATTACHMENT_FRONT_LEFT: + case ST_ATTACHMENT_BACK_LEFT: + case ST_ATTACHMENT_FRONT_RIGHT: + case ST_ATTACHMENT_BACK_RIGHT: + format = drawable->stvis.color_format; + break; + case ST_ATTACHMENT_DEPTH_STENCIL: + format = drawable->stvis.depth_stencil_format; + break; + default: + format = PIPE_FORMAT_NONE; + break; + } + + return format; +} + +/** + * Process __DRIbuffer and convert them into pipe_textures. + */ +static void +dri_drawable_process_buffers(struct dri_drawable *drawable, + __DRIbuffer *buffers, unsigned count) +{ + struct dri_screen *screen = dri_screen(drawable->sPriv); + __DRIdrawable *dri_drawable = drawable->dPriv; + struct pipe_texture templ; + struct winsys_handle whandle; + boolean have_depth = FALSE; + unsigned i; + + if (drawable->old_num == count && + drawable->old_w == dri_drawable->w && + drawable->old_h == dri_drawable->h && + memcmp(drawable->old, buffers, sizeof(__DRIbuffer) * count) == 0) + return; + + for (i = 0; i < ST_ATTACHMENT_COUNT; i++) + pipe_texture_reference(&drawable->textures[i], NULL); + + memset(&templ, 0, sizeof(templ)); + templ.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET; + templ.target = PIPE_TEXTURE_2D; + templ.last_level = 0; + templ.width0 = dri_drawable->w; + templ.height0 = dri_drawable->h; + templ.depth0 = 1; + + memset(&whandle, 0, sizeof(whandle)); + + for (i = 0; i < count; i++) { + __DRIbuffer *buf = &buffers[i]; + enum st_attachment_type statt; + enum pipe_format format; + + switch (buf->attachment) { + case __DRI_BUFFER_FRONT_LEFT: + if (!screen->auto_fake_front) { + statt = ST_ATTACHMENT_INVALID; + break; + } + /* fallthrough */ + case __DRI_BUFFER_FAKE_FRONT_LEFT: + statt = ST_ATTACHMENT_FRONT_LEFT; + break; + case __DRI_BUFFER_BACK_LEFT: + statt = ST_ATTACHMENT_BACK_LEFT; + break; + case __DRI_BUFFER_DEPTH: + case __DRI_BUFFER_DEPTH_STENCIL: + case __DRI_BUFFER_STENCIL: + statt = ST_ATTACHMENT_DEPTH_STENCIL; + /* use only the first depth/stencil buffer */ + if (have_depth) + statt = ST_ATTACHMENT_INVALID; + else + have_depth = TRUE; + break; + default: + statt = ST_ATTACHMENT_INVALID; + break; + } + + format = dri_drawable_get_format(drawable, statt); + if (statt == ST_ATTACHMENT_INVALID || format == PIPE_FORMAT_NONE) + continue; + + templ.format = format; + whandle.handle = buf->name; + whandle.stride = buf->pitch; + + drawable->textures[statt] = + screen->pipe_screen->texture_from_handle(screen->pipe_screen, + &templ, &whandle); + } + + drawable->old_num = count; + drawable->old_w = dri_drawable->w; + drawable->old_h = dri_drawable->h; + memcpy(drawable->old, buffers, sizeof(__DRIbuffer) * count); +} + +/** + * Retrieve __DRIbuffer from the DRI loader. + */ +static __DRIbuffer * +dri_drawable_get_buffers(struct dri_drawable *drawable, + const enum st_attachment_type *statts, + unsigned *count) +{ + __DRIdrawable *dri_drawable = drawable->dPriv; + struct __DRIdri2LoaderExtensionRec *loader = drawable->sPriv->dri2.loader; + boolean with_format; + __DRIbuffer *buffers; + int num_buffers; + unsigned attachments[8]; + unsigned num_attachments, i; + + assert(loader); + with_format = (loader->base.version > 2 && loader->getBuffersWithFormat); + + num_attachments = 0; + for (i = 0; i < *count; i++) { + enum pipe_format format; + int att; + + format = dri_drawable_get_format(drawable, statts[i]); + if (format == PIPE_FORMAT_NONE) + continue; + + switch (statts[i]) { + case ST_ATTACHMENT_FRONT_LEFT: + att = __DRI_BUFFER_FRONT_LEFT; + break; + case ST_ATTACHMENT_BACK_LEFT: + att = __DRI_BUFFER_BACK_LEFT; + break; + case ST_ATTACHMENT_FRONT_RIGHT: + att = __DRI_BUFFER_FRONT_RIGHT; + break; + case ST_ATTACHMENT_BACK_RIGHT: + att = __DRI_BUFFER_BACK_RIGHT; + break; + case ST_ATTACHMENT_DEPTH_STENCIL: + att = __DRI_BUFFER_DEPTH_STENCIL; + break; + default: + att = -1; + break; + } + + if (att >= 0) { + attachments[num_attachments++] = att; + if (with_format) { + attachments[num_attachments++] = + util_format_get_blocksizebits(format); + } + } + } + + if (with_format) { + num_attachments /= 2; + buffers = loader->getBuffersWithFormat(dri_drawable, + &dri_drawable->w, &dri_drawable->h, + attachments, num_attachments, + &num_buffers, dri_drawable->loaderPrivate); + } + else { + buffers = loader->getBuffers(dri_drawable, + &dri_drawable->w, &dri_drawable->h, + attachments, num_attachments, + &num_buffers, dri_drawable->loaderPrivate); + } + + if (buffers) { + /* set one cliprect to cover the whole dri_drawable */ + dri_drawable->x = 0; + dri_drawable->y = 0; + dri_drawable->backX = 0; + dri_drawable->backY = 0; + dri_drawable->numClipRects = 1; + dri_drawable->pClipRects[0].x1 = 0; + dri_drawable->pClipRects[0].y1 = 0; + dri_drawable->pClipRects[0].x2 = dri_drawable->w; + dri_drawable->pClipRects[0].y2 = dri_drawable->h; + dri_drawable->numBackClipRects = 1; + dri_drawable->pBackClipRects[0].x1 = 0; + dri_drawable->pBackClipRects[0].y1 = 0; + dri_drawable->pBackClipRects[0].x2 = dri_drawable->w; + dri_drawable->pBackClipRects[0].y2 = dri_drawable->h; + + *count = num_buffers; + } + + return buffers; +} + +static boolean +dri_st_framebuffer_validate(struct st_framebuffer_iface *stfbi, + const enum st_attachment_type *statts, + unsigned count, + struct pipe_texture **out) +{ + struct dri_drawable *drawable = + (struct dri_drawable *) stfbi->st_manager_private; + unsigned statt_mask, i; + + statt_mask = 0x0; + for (i = 0; i < count; i++) + statt_mask |= (1 << statts[i]); + + /* + * dPriv->pStamp is the server stamp. It should be accessed with a lock, at + * least for DRI1. dPriv->lastStamp is the client stamp. It has the value + * of the server stamp when last checked. + * + * This function updates the textures and records the stamp of the textures. + */ + if (drawable->texture_stamp != drawable->dPriv->lastStamp || + (statt_mask & ~drawable->texture_mask)) { + if (__dri1_api_hooks) { + /* TODO */ + return FALSE; + } + else { + __DRIbuffer *buffers; + unsigned num_buffers = count; + + buffers = dri_drawable_get_buffers(drawable, statts, &num_buffers); + dri_drawable_process_buffers(drawable, buffers, num_buffers); + } + + drawable->texture_stamp = drawable->dPriv->lastStamp; + drawable->texture_mask = statt_mask; + } + + if (!out) + return TRUE; + + for (i = 0; i < count; i++) { + out[i] = NULL; + pipe_texture_reference(&out[i], drawable->textures[statts[i]]); + } + + return TRUE; +} + +static boolean +dri_st_framebuffer_flush_front(struct st_framebuffer_iface *stfbi, + enum st_attachment_type statt) +{ + struct dri_drawable *drawable = + (struct dri_drawable *) stfbi->st_manager_private; + struct __DRIdri2LoaderExtensionRec *loader = + drawable->sPriv->dri2.loader; + + /* TODO */ + if (__dri1_api_hooks) + return FALSE; + + if (statt == ST_ATTACHMENT_FRONT_LEFT && loader->flushFrontBuffer) { + loader->flushFrontBuffer(drawable->dPriv, + drawable->dPriv->loaderPrivate); + } + + return TRUE; +} + +/** + * Create a framebuffer from the given drawable. + */ +struct st_framebuffer_iface * +dri_create_st_framebuffer(struct dri_drawable *drawable) +{ + struct st_framebuffer_iface *stfbi; + + stfbi = CALLOC_STRUCT(st_framebuffer_iface); + if (stfbi) { + stfbi->visual = &drawable->stvis; + stfbi->flush_front = dri_st_framebuffer_flush_front; + stfbi->validate = dri_st_framebuffer_validate; + stfbi->st_manager_private = (void *) drawable; + } + + return stfbi; +} + +/** + * Destroy a framebuffer. + */ +void +dri_destroy_st_framebuffer(struct st_framebuffer_iface *stfbi) +{ + FREE(stfbi); +} + +/** + * Return the texture at an attachment. Allocate the texture if it does not + * exist. + */ +struct pipe_texture * +dri_get_st_framebuffer_texture(struct st_framebuffer_iface *stfbi, + enum st_attachment_type statt) +{ + struct dri_drawable *drawable = + (struct dri_drawable *) stfbi->st_manager_private; + + if (!(drawable->texture_mask & (1 << statt))) { + enum st_attachment_type statts[ST_ATTACHMENT_COUNT]; + unsigned i, count = 0; + + /* make sure DRI2 does not destroy existing buffers */ + for (i = 0; i < ST_ATTACHMENT_COUNT; i++) { + if (drawable->texture_mask & (1 << i)) { + statts[count++] = i; + } + } + statts[count++] = statt; + + drawable->texture_stamp = drawable->dPriv->lastStamp - 1; + dri_st_framebuffer_validate(stfbi, statts, count, NULL); + } + + return drawable->textures[statt]; +} + +/** + * Add a reference to the st_api of the state tracker. + */ +static void +_dri_get_st_api(void) +{ + p_atomic_inc(&dri_st_api.refcnt); + if (p_atomic_read(&dri_st_api.refcnt) == 1) + dri_st_api.stapi = st_manager_create_api(); +} + +/** + * Remove a reference to the st_api of the state tracker. + */ +static void +_dri_put_st_api(void) +{ + struct st_api *stapi = dri_st_api.stapi; + + if (p_atomic_dec_zero(&dri_st_api.refcnt)) { + stapi->destroy(dri_st_api.stapi); + dri_st_api.stapi = NULL; + } +} + +/** + * Create a state tracker manager from the given screen. + */ +struct st_manager * +dri_create_st_manager(struct dri_screen *screen) +{ + struct st_manager *smapi; + + smapi = CALLOC_STRUCT(st_manager); + if (smapi) { + smapi->screen = screen->pipe_screen; + _dri_get_st_api(); + } + + return smapi; +} + +/** + * Destroy a state tracker manager. + */ +void +dri_destroy_st_manager(struct st_manager *smapi) +{ + _dri_put_st_api(); + FREE(smapi); +} + +/** + * Return the st_api of OpenGL state tracker. + */ +struct st_api * +dri_get_st_api(void) +{ + assert(dri_st_api.stapi); + return dri_st_api.stapi; +} diff --git a/src/gallium/state_trackers/dri/dri_st_api.h b/src/gallium/state_trackers/dri/dri_st_api.h new file mode 100644 index 00000000000..7cf522e4690 --- /dev/null +++ b/src/gallium/state_trackers/dri/dri_st_api.h @@ -0,0 +1,55 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu + */ + +#ifndef _DRI_ST_API_H_ +#define _DRI_ST_API_H_ + +#include "state_tracker/st_api.h" + +struct dri_screen; +struct dri_drawable; + +struct st_api * +dri_get_st_api(void); + +struct st_manager * +dri_create_st_manager(struct dri_screen *screen); + +void +dri_destroy_st_manager(struct st_manager *smapi); + +struct st_framebuffer_iface * +dri_create_st_framebuffer(struct dri_drawable *drawable); + +void +dri_destroy_st_framebuffer(struct st_framebuffer_iface *stfbi); + +struct pipe_texture * +dri_get_st_framebuffer_texture(struct st_framebuffer_iface *stfbi, + enum st_attachment_type statt); + +#endif /* _DRI_ST_API_H_ */ -- cgit v1.2.3 From bd1ce874728c06d08a1f9881f51edbdd2f1c9db0 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Mon, 8 Mar 2010 22:19:48 +0800 Subject: st/dri: Switch from st_public.h to st_api.h. This is tested with demos found in progs/demos. However, only the DRI2 path is tested. --- src/gallium/state_trackers/dri/dri1.c | 281 ++++++++++++------ src/gallium/state_trackers/dri/dri1.h | 11 +- src/gallium/state_trackers/dri/dri_context.c | 82 +++-- src/gallium/state_trackers/dri/dri_context.h | 9 +- src/gallium/state_trackers/dri/dri_drawable.c | 378 ++---------------------- src/gallium/state_trackers/dri/dri_drawable.h | 24 +- src/gallium/state_trackers/dri/dri_extensions.c | 4 +- src/gallium/state_trackers/dri/dri_screen.c | 137 +++++++-- src/gallium/state_trackers/dri/dri_screen.h | 12 + src/gallium/state_trackers/dri/dri_st_api.c | 13 +- 10 files changed, 393 insertions(+), 558 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/dri/dri1.c b/src/gallium/state_trackers/dri/dri1.c index 543891f813b..41dba82d528 100644 --- a/src/gallium/state_trackers/dri/dri1.c +++ b/src/gallium/state_trackers/dri/dri1.c @@ -29,16 +29,18 @@ * Author: Jakob Bornecrantz */ +/* XXX DRI1 is untested after the switch to st_api.h */ + #include "util/u_memory.h" #include "util/u_rect.h" +#include "util/u_inlines.h" #include "pipe/p_context.h" -#include "state_tracker/st_context.h" -#include "state_tracker/st_public.h" #include "state_tracker/dri1_api.h" #include "dri_screen.h" #include "dri_context.h" #include "dri_drawable.h" +#include "dri_st_api.h" #include "dri1.h" static INLINE void @@ -125,52 +127,29 @@ dri1_update_drawables_locked(struct dri_context *ctx, /** * This ensures all contexts which bind to a drawable pick up the * drawable change and signal new buffer state. - * Calling st_resize_framebuffer for each context may seem like overkill, - * but no new buffers will actually be allocated if the dimensions don't - * change. */ - static void dri1_propagate_drawable_change(struct dri_context *ctx) { __DRIdrawable *dPriv = ctx->dPriv; __DRIdrawable *rPriv = ctx->rPriv; + struct dri_drawable *draw = dri_drawable(dPriv); + struct dri_drawable *read = dri_drawable(rPriv); boolean flushed = FALSE; - if (dPriv && ctx->d_stamp != dPriv->lastStamp) { - - st_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); + if (dPriv && draw->texture_stamp != dPriv->lastStamp) { + ctx->st->flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); flushed = TRUE; - ctx->d_stamp = dPriv->lastStamp; - st_resize_framebuffer(dri_drawable(dPriv)->stfb, dPriv->w, dPriv->h); - + ctx->st->notify_invalid_framebuffer(ctx->st, draw->stfb); } - if (rPriv && dPriv != rPriv && ctx->r_stamp != rPriv->lastStamp) { - + if (rPriv && dPriv != rPriv && read->texture_stamp != rPriv->lastStamp) { if (!flushed) - st_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); - ctx->r_stamp = rPriv->lastStamp; - st_resize_framebuffer(dri_drawable(rPriv)->stfb, rPriv->w, rPriv->h); - - } else if (rPriv && dPriv == rPriv) { - - ctx->r_stamp = ctx->d_stamp; - + ctx->st->flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); + ctx->st->notify_invalid_framebuffer(ctx->st, read->stfb); } } -void -dri1_update_drawables(struct dri_context *ctx, - struct dri_drawable *draw, struct dri_drawable *read) -{ - dri1_lock(ctx); - dri1_update_drawables_locked(ctx, draw->dPriv, read->dPriv); - dri1_unlock(ctx); - - dri1_propagate_drawable_change(ctx); -} - static INLINE boolean dri1_intersect_src_bbox(struct drm_clip_rect *dst, int dst_x, @@ -204,12 +183,11 @@ dri1_intersect_src_bbox(struct drm_clip_rect *dst, } static void -dri1_swap_copy(struct dri_context *ctx, +dri1_swap_copy(struct pipe_context *pipe, struct pipe_surface *dst, struct pipe_surface *src, __DRIdrawable * dPriv, const struct drm_clip_rect *bbox) { - struct pipe_context *pipe = ctx->pipe; struct drm_clip_rect clip; struct drm_clip_rect *cur; int i; @@ -235,52 +213,96 @@ dri1_swap_copy(struct dri_context *ctx, } } +static struct pipe_surface * +dri1_get_pipe_surface(struct dri_drawable *drawable, struct pipe_texture *ptex) +{ + struct pipe_screen *pipe_screen = dri_screen(drawable->sPriv)->pipe_screen; + struct pipe_surface *psurf = drawable->dri1_surface; + + if (!psurf || psurf->texture != ptex) { + pipe_surface_reference(&drawable->dri1_surface, NULL); + + drawable->dri1_surface = pipe_screen->get_tex_surface(pipe_screen, + ptex, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_READ); + + psurf = drawable->dri1_surface; + } + + return psurf; +} + +static struct pipe_context * +dri1_get_pipe_context(struct dri_drawable *drawable) +{ + struct dri_screen *screen = dri_screen(drawable->sPriv); + struct pipe_context *pipe = screen->dri1_pipe; + + if (!pipe) { + screen->dri1_pipe = + screen->pipe_screen->context_create(screen->pipe_screen, NULL); + pipe = screen->dri1_pipe; + } + + return pipe; +} + static void -dri1_copy_to_front(struct dri_context *ctx, - struct pipe_surface *surf, - __DRIdrawable * dPriv, - const struct drm_clip_rect *sub_box, - struct pipe_fence_handle **fence) +dri1_present_texture_locked(__DRIdrawable * dPriv, + struct pipe_texture *ptex, + const struct drm_clip_rect *sub_box, + struct pipe_fence_handle **fence) { - struct pipe_context *pipe = ctx->pipe; - boolean save_lost_lock; - uint cur_w; - uint cur_h; + struct dri_drawable *drawable = dri_drawable(dPriv); + struct pipe_context *pipe; + struct pipe_surface *psurf; struct drm_clip_rect bbox; boolean visible = TRUE; *fence = NULL; - dri1_lock(ctx); - save_lost_lock = ctx->stLostLock; - dri1_update_drawables_locked(ctx, dPriv, dPriv); - st_get_framebuffer_dimensions(dri_drawable(dPriv)->stfb, &cur_w, &cur_h); - bbox.x1 = 0; - bbox.x2 = cur_w; + bbox.x2 = ptex->width0; bbox.y1 = 0; - bbox.y2 = cur_h; + bbox.y2 = ptex->height0; if (sub_box) visible = dri1_intersect_src_bbox(&bbox, 0, 0, &bbox, sub_box); + if (!visible) + return; - if (visible && __dri1_api_hooks->present_locked) { - - __dri1_api_hooks->present_locked(pipe, - surf, - dPriv->pClipRects, - dPriv->numClipRects, - dPriv->x, dPriv->y, &bbox, fence); - - } else if (visible && __dri1_api_hooks->front_srf_locked) { + pipe = dri1_get_pipe_context(drawable); + psurf = dri1_get_pipe_surface(drawable, ptex); + if (!pipe || !psurf) + return; + if (__dri1_api_hooks->present_locked) { + __dri1_api_hooks->present_locked(pipe, psurf, + dPriv->pClipRects, dPriv->numClipRects, + dPriv->x, dPriv->y, &bbox, fence); + } else if (__dri1_api_hooks->front_srf_locked) { struct pipe_surface *front = __dri1_api_hooks->front_srf_locked(pipe); if (front) - dri1_swap_copy(ctx, front, surf, dPriv, &bbox); + dri1_swap_copy(pipe, front, psurf, dPriv, &bbox); - st_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, fence); + pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, fence); } +} + +static void +dri1_copy_to_front(struct dri_context *ctx, + struct pipe_texture *ptex, + __DRIdrawable * dPriv, + const struct drm_clip_rect *sub_box, + struct pipe_fence_handle **fence) +{ + boolean save_lost_lock; + + dri1_lock(ctx); + save_lost_lock = ctx->stLostLock; + dri1_update_drawables_locked(ctx, dPriv, dPriv); + + dri1_present_texture_locked(dPriv, ptex, sub_box, fence); ctx->stLostLock = save_lost_lock; @@ -296,14 +318,23 @@ dri1_copy_to_front(struct dri_context *ctx, } void -dri1_flush_frontbuffer(struct pipe_screen *screen, - struct pipe_surface *surf, void *context_private) +dri1_flush_frontbuffer(struct dri_drawable *drawable, + struct pipe_texture *ptex) { - struct dri_context *ctx = (struct dri_context *)context_private; + struct st_api *stapi = dri_get_st_api(); + struct dri_screen *screen = dri_screen(drawable->sPriv); + struct pipe_screen *pipe_screen = screen->pipe_screen; + struct dri_context *ctx; struct pipe_fence_handle *dummy_fence; + struct st_context_iface *st = stapi->get_current(stapi); - dri1_copy_to_front(ctx, surf, ctx->dPriv, NULL, &dummy_fence); - screen->fence_reference(screen, &dummy_fence, NULL); + if (!st) + return; + + ctx = (struct dri_context *) st->st_manager_private; + + dri1_copy_to_front(ctx, ptex, ctx->dPriv, NULL, &dummy_fence); + pipe_screen->fence_reference(pipe_screen, &dummy_fence, NULL); /** * FIXME: Do we need swap throttling here? @@ -313,66 +344,127 @@ dri1_flush_frontbuffer(struct pipe_screen *screen, void dri1_swap_buffers(__DRIdrawable * dPriv) { - struct dri_context *ctx; - struct pipe_surface *back_surf; + struct dri_context *ctx = dri_get_current(); struct dri_drawable *draw = dri_drawable(dPriv); - struct pipe_screen *screen = dri_screen(draw->sPriv)->pipe_screen; + struct dri_screen *screen = dri_screen(draw->sPriv); + struct pipe_screen *pipe_screen = screen->pipe_screen; struct pipe_fence_handle *fence; - struct st_context *st = st_get_current(); + struct pipe_texture *ptex; assert(__dri1_api_hooks != NULL); - if (!st) + if (!ctx) return; /* For now */ - ctx = (struct dri_context *)st->pipe->priv; - - st_get_framebuffer_surface(draw->stfb, ST_SURFACE_BACK_LEFT, &back_surf); - if (back_surf) { - st_notify_swapbuffers(draw->stfb); - st_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); + ptex = draw->textures[ST_ATTACHMENT_BACK_LEFT]; + if (ptex) { + ctx->st->flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); fence = dri_swap_fences_pop_front(draw); if (fence) { - (void)screen->fence_finish(screen, fence, 0); - screen->fence_reference(screen, &fence, NULL); + (void)pipe_screen->fence_finish(pipe_screen, fence, 0); + pipe_screen->fence_reference(pipe_screen, &fence, NULL); } - dri1_copy_to_front(ctx, back_surf, dPriv, NULL, &fence); + dri1_copy_to_front(ctx, ptex, dPriv, NULL, &fence); dri_swap_fences_push_back(draw, fence); - screen->fence_reference(screen, &fence, NULL); + pipe_screen->fence_reference(pipe_screen, &fence, NULL); } } void dri1_copy_sub_buffer(__DRIdrawable * dPriv, int x, int y, int w, int h) { - struct pipe_screen *screen = dri_screen(dPriv->driScreenPriv)->pipe_screen; + struct dri_context *ctx = dri_get_current(); + struct dri_screen *screen = dri_screen(dPriv->driScreenPriv); + struct pipe_screen *pipe_screen = screen->pipe_screen; struct drm_clip_rect sub_bbox; - struct dri_context *ctx; - struct pipe_surface *back_surf; struct dri_drawable *draw = dri_drawable(dPriv); struct pipe_fence_handle *dummy_fence; - struct st_context *st = st_get_current(); + struct pipe_texture *ptex; assert(__dri1_api_hooks != NULL); - if (!st) + if (!ctx) return; - ctx = (struct dri_context *)st->pipe->priv; - sub_bbox.x1 = x; sub_bbox.x2 = x + w; sub_bbox.y1 = y; sub_bbox.y2 = y + h; - st_get_framebuffer_surface(draw->stfb, ST_SURFACE_BACK_LEFT, &back_surf); - if (back_surf) { - st_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); - dri1_copy_to_front(ctx, back_surf, dPriv, &sub_bbox, &dummy_fence); - screen->fence_reference(screen, &dummy_fence, NULL); + ptex = draw->textures[ST_ATTACHMENT_BACK_LEFT]; + if (ptex) { + ctx->st->flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); + dri1_copy_to_front(ctx, ptex, dPriv, &sub_bbox, &dummy_fence); + pipe_screen->fence_reference(pipe_screen, &dummy_fence, NULL); } } +void +dri1_allocate_textures(struct dri_drawable *drawable, + unsigned width, unsigned height, + unsigned mask) +{ + struct dri_screen *screen = dri_screen(drawable->sPriv); + struct pipe_texture templ; + int i; + + /* remove outdated textures */ + if (drawable->old_w != width || drawable->old_h != height) { + for (i = 0; i < ST_ATTACHMENT_COUNT; i++) + pipe_texture_reference(&drawable->textures[i], NULL); + } + + memset(&templ, 0, sizeof(templ)); + templ.target = PIPE_TEXTURE_2D; + templ.width0 = width; + templ.height0 = height; + templ.depth0 = 1; + templ.last_level = 0; + + for (i = 0; i < ST_ATTACHMENT_COUNT; i++) { + enum pipe_format format; + unsigned tex_usage; + + /* the texture already exists or not requested */ + if (drawable->textures[i] || !(mask & (1 << i))) { + /* remember the texture */ + if (drawable->textures[i]) + mask |= (1 << i); + continue; + } + + switch (i) { + case ST_ATTACHMENT_FRONT_LEFT: + case ST_ATTACHMENT_BACK_LEFT: + case ST_ATTACHMENT_FRONT_RIGHT: + case ST_ATTACHMENT_BACK_RIGHT: + format = drawable->stvis.color_format; + tex_usage = PIPE_TEXTURE_USAGE_DISPLAY_TARGET | + PIPE_TEXTURE_USAGE_RENDER_TARGET; + break; + case ST_ATTACHMENT_DEPTH_STENCIL: + format = drawable->stvis.depth_stencil_format; + tex_usage = PIPE_TEXTURE_USAGE_DEPTH_STENCIL; + break; + default: + format = PIPE_FORMAT_NONE; + break; + } + + if (templ.format != PIPE_FORMAT_NONE) { + templ.format = format; + templ.tex_usage = tex_usage; + + drawable->textures[i] = + screen->pipe_screen->texture_create(screen->pipe_screen, &templ); + } + } + + drawable->old_w = width; + drawable->old_h = height; + drawable->texture_mask = mask; +} + static void st_dri_lock(struct pipe_context *pipe) { @@ -469,7 +561,6 @@ dri1_init_screen(__DRIscreen * sPriv) __dri1_api_hooks = arg.api; - screen->pipe_screen->flush_frontbuffer = dri1_flush_frontbuffer; driParseOptionInfo(&screen->optionCache, __driConfigOptions, __driNConfigOptions); diff --git a/src/gallium/state_trackers/dri/dri1.h b/src/gallium/state_trackers/dri/dri1.h index e525ce64c3f..e83571e57be 100644 --- a/src/gallium/state_trackers/dri/dri1.h +++ b/src/gallium/state_trackers/dri/dri1.h @@ -34,6 +34,8 @@ #include "dri_context.h" #include "dri_drawable.h" + +#include "state_tracker/st_api.h" #include "dri_util.h" extern struct dri1_api *__dri1_api_hooks; @@ -42,12 +44,13 @@ const __DRIconfig ** dri1_init_screen(__DRIscreen * sPriv); void -dri1_update_drawables(struct dri_context *ctx, - struct dri_drawable *draw, struct dri_drawable *read); +dri1_flush_frontbuffer(struct dri_drawable *drawable, + struct pipe_texture *ptex); void -dri1_flush_frontbuffer(struct pipe_screen *screen, - struct pipe_surface *surf, void *context_private); +dri1_allocate_textures(struct dri_drawable *drawable, + unsigned width, unsigned height, + unsigned mask); void dri1_swap_buffers(__DRIdrawable * dPriv); diff --git a/src/gallium/state_trackers/dri/dri_context.c b/src/gallium/state_trackers/dri/dri_context.c index 8e74d3b9bf1..c1848b026cd 100644 --- a/src/gallium/state_trackers/dri/dri_context.c +++ b/src/gallium/state_trackers/dri/dri_context.c @@ -32,9 +32,9 @@ #include "dri_screen.h" #include "dri_drawable.h" #include "dri_context.h" +#include "dri_st_api.h" #include "dri1.h" -#include "state_tracker/st_public.h" #include "pipe/p_context.h" #include "util/u_memory.h" @@ -42,10 +42,12 @@ GLboolean dri_create_context(const __GLcontextModes * visual, __DRIcontext * cPriv, void *sharedContextPrivate) { + struct st_api *stapi = dri_get_st_api(); __DRIscreen *sPriv = cPriv->driScreenPriv; struct dri_screen *screen = dri_screen(sPriv); struct dri_context *ctx = NULL; - struct st_context *st_share = NULL; + struct st_context_iface *st_share = NULL; + struct st_visual stvis; if (sharedContextPrivate) { st_share = ((struct dri_context *)sharedContextPrivate)->st; @@ -59,21 +61,15 @@ dri_create_context(const __GLcontextModes * visual, ctx->cPriv = cPriv; ctx->sPriv = sPriv; ctx->lock = screen->drmLock; - ctx->d_stamp = -1; - ctx->r_stamp = -1; driParseConfigFiles(&ctx->optionCache, &screen->optionCache, sPriv->myNum, "dri"); - ctx->pipe = screen->pipe_screen->context_create( screen->pipe_screen, - ctx ); - - if (ctx->pipe == NULL) - goto fail; - - ctx->st = st_create_context(ctx->pipe, visual, st_share); + dri_fill_st_visual(&stvis, screen, visual); + ctx->st = stapi->create_context(stapi, screen->smapi, &stvis, st_share); if (ctx->st == NULL) goto fail; + ctx->st->st_manager_private = (void *) ctx; dri_init_extensions(ctx); @@ -81,10 +77,7 @@ dri_create_context(const __GLcontextModes * visual, fail: if (ctx && ctx->st) - st_destroy_context(ctx->st); - - if (ctx && ctx->pipe) - ctx->pipe->destroy(ctx->pipe); + ctx->st->destroy(ctx->st); FREE(ctx); return FALSE; @@ -106,11 +99,8 @@ dri_destroy_context(__DRIcontext * cPriv) * to avoid having to add code elsewhere to cope with flushing a * partially destroyed context. */ - st_flush(ctx->st, 0, NULL); - - /* Also frees ctx->pipe? - */ - st_destroy_context(ctx->st); + ctx->st->flush(ctx->st, 0, NULL); + ctx->st->destroy(ctx->st); FREE(ctx); } @@ -118,14 +108,16 @@ dri_destroy_context(__DRIcontext * cPriv) GLboolean dri_unbind_context(__DRIcontext * cPriv) { + struct st_api *stapi = dri_get_st_api(); + if (cPriv) { struct dri_context *ctx = dri_context(cPriv); if (--ctx->bind_count == 0) { - if (ctx->st && ctx->st == st_get_current()) { - st_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); - st_make_current(NULL, NULL, NULL, NULL); - } + if (ctx->st == stapi->get_current(stapi)) { + ctx->st->flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); + stapi->make_current(stapi, NULL, NULL, NULL); + } } } @@ -137,45 +129,47 @@ dri_make_current(__DRIcontext * cPriv, __DRIdrawable * driDrawPriv, __DRIdrawable * driReadPriv) { + struct st_api *stapi = dri_get_st_api(); + if (cPriv) { struct dri_context *ctx = dri_context(cPriv); struct dri_drawable *draw = dri_drawable(driDrawPriv); struct dri_drawable *read = dri_drawable(driReadPriv); - struct st_context *old_st = st_get_current(); + struct st_context_iface *old_st; + old_st = stapi->get_current(stapi); if (old_st && old_st != ctx->st) - st_flush(old_st, PIPE_FLUSH_RENDER_CACHE, NULL); + ctx->st->flush(old_st, PIPE_FLUSH_RENDER_CACHE, NULL); ++ctx->bind_count; if (ctx->dPriv != driDrawPriv) { ctx->dPriv = driDrawPriv; - ctx->d_stamp = driDrawPriv->lastStamp - 1; + draw->texture_stamp = driDrawPriv->lastStamp - 1; } if (ctx->rPriv != driReadPriv) { ctx->rPriv = driReadPriv; - ctx->r_stamp = driReadPriv->lastStamp - 1; + draw->texture_stamp = driReadPriv->lastStamp - 1; } - /* DRI co-state tracker currently overrides flush_frontbuffer. - * When this is fixed, will need to pass the drawable in the - * fourth parameter here so that when Mesa calls - * flush_frontbuffer directly (in front-buffer rendering), it - * will have access to the drawable argument: - */ - st_make_current(ctx->st, draw->stfb, read->stfb, ctx); - - if (__dri1_api_hooks) { - dri1_update_drawables(ctx, draw, read); - } else { - dri_update_buffer(ctx->pipe->screen, - ctx->pipe->priv); - } - } else { - st_make_current(NULL, NULL, NULL, NULL); + stapi->make_current(stapi, ctx->st, draw->stfb, read->stfb); + } + else { + stapi->make_current(stapi, NULL, NULL, NULL); } return GL_TRUE; } +struct dri_context * +dri_get_current(void) +{ + struct st_api *stapi = dri_get_st_api(); + struct st_context_iface *st; + + st = stapi->get_current(stapi); + + return (struct dri_context *) (st) ? st->st_manager_private : NULL; +} + /* vim: set sw=3 ts=8 sts=3 expandtab: */ diff --git a/src/gallium/state_trackers/dri/dri_context.h b/src/gallium/state_trackers/dri/dri_context.h index f0700b9aaff..845b420cf89 100644 --- a/src/gallium/state_trackers/dri/dri_context.h +++ b/src/gallium/state_trackers/dri/dri_context.h @@ -51,9 +51,6 @@ struct dri_context driOptionCache optionCache; - unsigned int d_stamp; - unsigned int r_stamp; - drmLock *lock; boolean isLocked; boolean stLostLock; @@ -62,8 +59,7 @@ struct dri_context unsigned int bind_count; /* gallium */ - struct st_context *st; - struct pipe_context *pipe; + struct st_context_iface *st; }; static INLINE struct dri_context * @@ -84,6 +80,9 @@ dri_make_current(__DRIcontext * driContextPriv, __DRIdrawable * driDrawPriv, __DRIdrawable * driReadPriv); +struct dri_context * +dri_get_current(void); + boolean dri_create_context(const __GLcontextModes * visual, __DRIcontext * driContextPriv, diff --git a/src/gallium/state_trackers/dri/dri_drawable.c b/src/gallium/state_trackers/dri/dri_drawable.c index 9238f942999..930387f8a67 100644 --- a/src/gallium/state_trackers/dri/dri_drawable.c +++ b/src/gallium/state_trackers/dri/dri_drawable.c @@ -32,249 +32,30 @@ #include "dri_screen.h" #include "dri_context.h" #include "dri_drawable.h" +#include "dri_st_api.h" #include "dri1.h" -#include "main/mtypes.h" -#include "main/renderbuffer.h" -#include "state_tracker/st_context.h" -#include "state_tracker/st_public.h" -#include "state_tracker/st_cb_fbo.h" -#include "state_tracker/drm_api.h" - #include "pipe/p_screen.h" #include "util/u_format.h" #include "util/u_memory.h" #include "util/u_inlines.h" -static struct pipe_surface * -dri_surface_from_handle(struct drm_api *api, - struct pipe_screen *screen, - unsigned handle, - enum pipe_format format, - unsigned width, unsigned height, unsigned pitch) -{ - struct pipe_surface *surface = NULL; - struct pipe_texture *texture = NULL; - struct pipe_texture templat; - struct winsys_handle whandle; - - memset(&templat, 0, sizeof(templat)); - templat.tex_usage |= PIPE_TEXTURE_USAGE_RENDER_TARGET; - templat.target = PIPE_TEXTURE_2D; - templat.last_level = 0; - templat.depth0 = 1; - templat.format = format; - templat.width0 = width; - templat.height0 = height; - - memset(&whandle, 0, sizeof(whandle)); - whandle.handle = handle; - whandle.stride = pitch; - - texture = screen->texture_from_handle(screen, &templat, &whandle); - - if (!texture) { - debug_printf("%s: Failed to blanket the buffer with a texture\n", __func__); - return NULL; - } - - surface = screen->get_tex_surface(screen, texture, 0, 0, 0, - PIPE_BUFFER_USAGE_GPU_READ | - PIPE_BUFFER_USAGE_GPU_WRITE); - - /* we don't need the texture from this point on */ - pipe_texture_reference(&texture, NULL); - return surface; -} - -/** - * Pixmaps have will have the same name of fake front and front. - */ -static boolean -dri2_check_if_pixmap(__DRIbuffer *buffers, int count) -{ - boolean found = FALSE; - boolean is_pixmap = FALSE; - unsigned name; - int i; - - for (i = 0; i < count; i++) { - switch (buffers[i].attachment) { - case __DRI_BUFFER_FRONT_LEFT: - case __DRI_BUFFER_FAKE_FRONT_LEFT: - if (found) { - is_pixmap = buffers[i].name == name; - } else { - name = buffers[i].name; - found = TRUE; - } - default: - continue; - } - } - - return is_pixmap; -} - -/** - * This will be called a drawable is known to have been resized. - */ -void -dri_get_buffers(__DRIdrawable * dPriv) -{ - - struct dri_drawable *drawable = dri_drawable(dPriv); - struct pipe_surface *surface = NULL; - struct dri_screen *st_screen = dri_screen(drawable->sPriv); - struct pipe_screen *screen = st_screen->pipe_screen; - __DRIbuffer *buffers = NULL; - __DRIscreen *dri_screen = drawable->sPriv; - __DRIdrawable *dri_drawable = drawable->dPriv; - struct drm_api *api = st_screen->api; - boolean have_depth = FALSE; - int i, count; - - if ((dri_screen->dri2.loader - && (dri_screen->dri2.loader->base.version > 2) - && (dri_screen->dri2.loader->getBuffersWithFormat != NULL))) { - buffers = (*dri_screen->dri2.loader->getBuffersWithFormat) - (dri_drawable, &dri_drawable->w, &dri_drawable->h, - drawable->attachments, drawable->num_attachments, - &count, dri_drawable->loaderPrivate); - } else { - assert(dri_screen->dri2.loader); - buffers = (*dri_screen->dri2.loader->getBuffers) (dri_drawable, - &dri_drawable->w, - &dri_drawable->h, - drawable->attachments, - drawable-> - num_attachments, &count, - dri_drawable-> - loaderPrivate); - } - - if (buffers == NULL) { - return; - } - - /* set one cliprect to cover the whole dri_drawable */ - dri_drawable->x = 0; - dri_drawable->y = 0; - dri_drawable->backX = 0; - dri_drawable->backY = 0; - dri_drawable->numClipRects = 1; - dri_drawable->pClipRects[0].x1 = 0; - dri_drawable->pClipRects[0].y1 = 0; - dri_drawable->pClipRects[0].x2 = dri_drawable->w; - dri_drawable->pClipRects[0].y2 = dri_drawable->h; - dri_drawable->numBackClipRects = 1; - dri_drawable->pBackClipRects[0].x1 = 0; - dri_drawable->pBackClipRects[0].y1 = 0; - dri_drawable->pBackClipRects[0].x2 = dri_drawable->w; - dri_drawable->pBackClipRects[0].y2 = dri_drawable->h; - - if (drawable->old_num == count && - drawable->old_w == dri_drawable->w && - drawable->old_h == dri_drawable->h && - memcmp(drawable->old, buffers, sizeof(__DRIbuffer) * count) == 0) { - return; - } else { - drawable->old_num = count; - drawable->old_w = dri_drawable->w; - drawable->old_h = dri_drawable->h; - memcpy(drawable->old, buffers, sizeof(__DRIbuffer) * count); - } - - drawable->is_pixmap = dri2_check_if_pixmap(buffers, count); - - for (i = 0; i < count; i++) { - enum pipe_format format = 0; - int index = 0; - - switch (buffers[i].attachment) { - case __DRI_BUFFER_FRONT_LEFT: - if (!st_screen->auto_fake_front) - continue; - /* fallthrough */ - case __DRI_BUFFER_FAKE_FRONT_LEFT: - index = ST_SURFACE_FRONT_LEFT; - format = drawable->color_format; - break; - case __DRI_BUFFER_BACK_LEFT: - index = ST_SURFACE_BACK_LEFT; - format = drawable->color_format; - break; - case __DRI_BUFFER_DEPTH: - case __DRI_BUFFER_DEPTH_STENCIL: - case __DRI_BUFFER_STENCIL: - index = ST_SURFACE_DEPTH; - format = drawable->depth_stencil_format; - break; - case __DRI_BUFFER_ACCUM: - default: - assert(0); - } - - if (index == ST_SURFACE_DEPTH) { - if (have_depth) - continue; - else - have_depth = TRUE; - } - - surface = dri_surface_from_handle(api, - screen, - buffers[i].name, - format, - dri_drawable->w, - dri_drawable->h, buffers[i].pitch); - - switch (buffers[i].attachment) { - case __DRI_BUFFER_FRONT_LEFT: - case __DRI_BUFFER_FAKE_FRONT_LEFT: - case __DRI_BUFFER_BACK_LEFT: - drawable->color_format = surface->format; - break; - case __DRI_BUFFER_DEPTH: - case __DRI_BUFFER_DEPTH_STENCIL: - case __DRI_BUFFER_STENCIL: - drawable->depth_stencil_format = surface->format; - break; - case __DRI_BUFFER_ACCUM: - default: - assert(0); - } - - st_set_framebuffer_surface(drawable->stfb, index, surface); - pipe_surface_reference(&surface, NULL); - } - /* this needed, or else the state tracker fails to pick the new buffers */ - st_resize_framebuffer(drawable->stfb, dri_drawable->w, dri_drawable->h); -} - /** * These are used for GLX_EXT_texture_from_pixmap */ void dri2_set_tex_buffer2(__DRIcontext *pDRICtx, GLint target, GLint format, __DRIdrawable *dPriv) { + struct dri_context *ctx = dri_context(pDRICtx); struct dri_drawable *drawable = dri_drawable(dPriv); - struct pipe_surface *ps; + struct pipe_texture *pt = + dri_get_st_framebuffer_texture(drawable->stfb, ST_ATTACHMENT_FRONT_LEFT); - if (!drawable->stfb->Base.Attachment[BUFFER_FRONT_LEFT].Renderbuffer) { - struct gl_renderbuffer *rb = - st_new_renderbuffer_fb(drawable->color_format, 0 /*XXX*/, FALSE); - _mesa_add_renderbuffer(&drawable->stfb->Base, BUFFER_FRONT_LEFT, rb); + if (pt) { + ctx->st->teximage(ctx->st, + (target == GL_TEXTURE_2D) ? ST_TEXTURE_2D : ST_TEXTURE_RECT, + 0, drawable->stvis.color_format, pt, FALSE); } - - dri_get_buffers(drawable->dPriv); - st_get_framebuffer_surface(drawable->stfb, ST_SURFACE_FRONT_LEFT, &ps); - - if (!ps) - return; - - st_bind_texture_surface(ps, target == GL_TEXTURE_2D ? ST_TEXTURE_2D : - ST_TEXTURE_RECT, 0, drawable->color_format); } void dri2_set_tex_buffer(__DRIcontext *pDRICtx, GLint target, @@ -283,53 +64,6 @@ void dri2_set_tex_buffer(__DRIcontext *pDRICtx, GLint target, dri2_set_tex_buffer2(pDRICtx, target, __DRI_TEXTURE_FORMAT_RGBA, dPriv); } -void -dri_update_buffer(struct pipe_screen *screen, void *context_private) -{ - struct dri_context *ctx = (struct dri_context *)context_private; - - if (ctx->d_stamp == *ctx->dPriv->pStamp && - ctx->r_stamp == *ctx->rPriv->pStamp) - return; - - ctx->d_stamp = *ctx->dPriv->pStamp; - ctx->r_stamp = *ctx->rPriv->pStamp; - - /* Ask the X server for new renderbuffers. */ - dri_get_buffers(ctx->dPriv); - if (ctx->dPriv != ctx->rPriv) - dri_get_buffers(ctx->rPriv); - -} - -void -dri_flush_frontbuffer(struct pipe_screen *screen, - struct pipe_surface *surf, void *context_private) -{ - struct dri_context *ctx = (struct dri_context *)context_private; - struct dri_drawable *drawable = dri_drawable(ctx->dPriv); - __DRIdrawable *dri_drawable = ctx->dPriv; - __DRIscreen *dri_screen = ctx->sPriv; - - /* XXX Does this function get called with DRI1? */ - - if (ctx->dPriv == NULL) { - debug_printf("%s: no drawable bound to context\n", __func__); - return; - } - -#if 0 - /* TODO if rendering to pixmaps is slow enable this code. */ - if (drawable->is_pixmap) - return; -#else - (void)drawable; -#endif - - (*dri_screen->dri2.loader->flushFrontBuffer)(dri_drawable, - dri_drawable->loaderPrivate); -} - /** * This is called when we need to set up GL rendering to a new X window. */ @@ -340,7 +74,6 @@ dri_create_buffer(__DRIscreen * sPriv, { struct dri_screen *screen = sPriv->private; struct dri_drawable *drawable = NULL; - int i; if (isPixmap) goto fail; /* not implemented */ @@ -349,45 +82,8 @@ dri_create_buffer(__DRIscreen * sPriv, if (drawable == NULL) goto fail; - if (visual->redBits == 8) { - if (visual->alphaBits == 8) - drawable->color_format = PIPE_FORMAT_B8G8R8A8_UNORM; - else - drawable->color_format = PIPE_FORMAT_B8G8R8X8_UNORM; - } else { - drawable->color_format = PIPE_FORMAT_B5G6R5_UNORM; - } - - switch(visual->depthBits) { - default: - case 0: - drawable->depth_stencil_format = PIPE_FORMAT_NONE; - break; - case 16: - drawable->depth_stencil_format = PIPE_FORMAT_Z16_UNORM; - break; - case 24: - if (visual->stencilBits == 0) { - drawable->depth_stencil_format = (screen->d_depth_bits_last) ? - PIPE_FORMAT_Z24X8_UNORM: - PIPE_FORMAT_X8Z24_UNORM; - } else { - drawable->depth_stencil_format = (screen->sd_depth_bits_last) ? - PIPE_FORMAT_Z24S8_UNORM: - PIPE_FORMAT_S8Z24_UNORM; - } - break; - case 32: - drawable->depth_stencil_format = PIPE_FORMAT_Z32_UNORM; - break; - } - - drawable->stfb = st_create_framebuffer(visual, - drawable->color_format, - drawable->depth_stencil_format, - drawable->depth_stencil_format, - dPriv->w, - dPriv->h, (void *)drawable); + dri_fill_st_visual(&drawable->stvis, screen, visual); + drawable->stfb = dri_create_st_framebuffer(drawable); if (drawable->stfb == NULL) goto fail; @@ -395,48 +91,6 @@ dri_create_buffer(__DRIscreen * sPriv, drawable->dPriv = dPriv; dPriv->driverPrivate = (void *)drawable; - /* setup dri2 buffers information */ - /* TODO incase of double buffer visual, delay fake creation */ - i = 0; - if (sPriv->dri2.loader - && (sPriv->dri2.loader->base.version > 2) - && (sPriv->dri2.loader->getBuffersWithFormat != NULL)) { - drawable->attachments[i++] = __DRI_BUFFER_FRONT_LEFT; - drawable->attachments[i++] = visual->rgbBits; - if (!screen->auto_fake_front) { - drawable->attachments[i++] = __DRI_BUFFER_FAKE_FRONT_LEFT; - drawable->attachments[i++] = visual->rgbBits; - } - if (visual->doubleBufferMode) { - drawable->attachments[i++] = __DRI_BUFFER_BACK_LEFT; - drawable->attachments[i++] = visual->rgbBits; - } - if (visual->depthBits && visual->stencilBits) { - drawable->attachments[i++] = __DRI_BUFFER_DEPTH_STENCIL; - drawable->attachments[i++] = visual->depthBits + visual->stencilBits; - } else if (visual->depthBits) { - drawable->attachments[i++] = __DRI_BUFFER_DEPTH; - drawable->attachments[i++] = visual->depthBits; - } else if (visual->stencilBits) { - drawable->attachments[i++] = __DRI_BUFFER_STENCIL; - drawable->attachments[i++] = visual->stencilBits; - } - drawable->num_attachments = i / 2; - } else { - drawable->attachments[i++] = __DRI_BUFFER_FRONT_LEFT; - if (!screen->auto_fake_front) - drawable->attachments[i++] = __DRI_BUFFER_FAKE_FRONT_LEFT; - if (visual->doubleBufferMode) - drawable->attachments[i++] = __DRI_BUFFER_BACK_LEFT; - if (visual->depthBits && visual->stencilBits) - drawable->attachments[i++] = __DRI_BUFFER_DEPTH_STENCIL; - else if (visual->depthBits) - drawable->attachments[i++] = __DRI_BUFFER_DEPTH; - else if (visual->stencilBits) - drawable->attachments[i++] = __DRI_BUFFER_STENCIL; - drawable->num_attachments = i; - } - drawable->desired_fences = 2; return GL_TRUE; @@ -449,12 +103,18 @@ void dri_destroy_buffer(__DRIdrawable * dPriv) { struct dri_drawable *drawable = dri_drawable(dPriv); - - st_unreference_framebuffer(drawable->stfb); - drawable->desired_fences = 0; + int i; dri1_swap_fences_clear(drawable); + pipe_surface_reference(&drawable->dri1_surface, NULL); + for (i = 0; i < ST_ATTACHMENT_COUNT; i++) + pipe_texture_reference(&drawable->textures[i], NULL); + + dri_destroy_st_framebuffer(drawable->stfb); + + drawable->desired_fences = 0; + FREE(drawable); } diff --git a/src/gallium/state_trackers/dri/dri_drawable.h b/src/gallium/state_trackers/dri/dri_drawable.h index ea66c483a1e..7f687b65f23 100644 --- a/src/gallium/state_trackers/dri/dri_drawable.h +++ b/src/gallium/state_trackers/dri/dri_drawable.h @@ -46,20 +46,15 @@ struct dri_drawable __DRIdrawable *dPriv; __DRIscreen *sPriv; - unsigned attachments[8]; - unsigned num_attachments; - - boolean is_pixmap; + /* gallium */ + struct st_framebuffer_iface *stfb; + struct st_visual stvis; __DRIbuffer old[8]; unsigned old_num; unsigned old_w; unsigned old_h; - /* gallium */ - struct st_framebuffer *stfb; - struct st_visual stvis; - struct pipe_texture *textures[ST_ATTACHMENT_COUNT]; unsigned int texture_mask, texture_stamp; @@ -69,8 +64,8 @@ struct dri_drawable unsigned int desired_fences; unsigned int cur_fences; - enum pipe_format color_format; - enum pipe_format depth_stencil_format; + /* used only by DRI1 */ + struct pipe_surface *dri1_surface; }; static INLINE struct dri_drawable * @@ -87,15 +82,6 @@ dri_create_buffer(__DRIscreen * sPriv, __DRIdrawable * dPriv, const __GLcontextModes * visual, boolean isPixmap); -void -dri_update_buffer(struct pipe_screen *screen, void *context_private); - -void -dri_flush_frontbuffer(struct pipe_screen *screen, - struct pipe_surface *surf, void *context_private); - -void dri_get_buffers(__DRIdrawable * dPriv); - void dri_destroy_buffer(__DRIdrawable * dPriv); void dri2_set_tex_buffer2(__DRIcontext *pDRICtx, GLint target, diff --git a/src/gallium/state_trackers/dri/dri_extensions.c b/src/gallium/state_trackers/dri/dri_extensions.c index 800677a2d1e..df458e1eb0f 100644 --- a/src/gallium/state_trackers/dri/dri_extensions.c +++ b/src/gallium/state_trackers/dri/dri_extensions.c @@ -38,9 +38,11 @@ void dri_init_extensions(struct dri_context *ctx) { + struct st_context *st = (struct st_context *) ctx->st; + /* New extensions should be added in mesa/state_tracker/st_extensions.c * and not in this file. */ - driInitExtensions(ctx->st->ctx, NULL, GL_FALSE); + driInitExtensions(st->ctx, NULL, GL_FALSE); } /* vim: set sw=3 ts=8 sts=3 expandtab: */ diff --git a/src/gallium/state_trackers/dri/dri_screen.c b/src/gallium/state_trackers/dri/dri_screen.c index cffe3b33b2f..17b9f1c5faf 100644 --- a/src/gallium/state_trackers/dri/dri_screen.c +++ b/src/gallium/state_trackers/dri/dri_screen.c @@ -36,8 +36,10 @@ #include "dri_screen.h" #include "dri_context.h" #include "dri_drawable.h" +#include "dri_st_api.h" #include "dri1.h" +#include "util/u_inlines.h" #include "pipe/p_screen.h" #include "pipe/p_format.h" #include "state_tracker/drm_api.h" @@ -66,10 +68,23 @@ dri2_flush_drawable(__DRIdrawable *draw) { } +static void +dri2_invalidate_drawable(__DRIdrawable *dPriv) +{ + struct dri_drawable *drawable = dri_drawable(dPriv); + struct dri_context *ctx = dri_context(dPriv->driContextPriv); + + dri2InvalidateDrawable(dPriv); + drawable->dPriv->lastStamp = *drawable->dPriv->pStamp; + + if (ctx) + ctx->st->notify_invalid_framebuffer(ctx->st, drawable->stfb); +} + static const __DRI2flushExtension dri2FlushExtension = { { __DRI2_FLUSH, __DRI2_FLUSH_VERSION }, dri2_flush_drawable, - dri2InvalidateDrawable, + dri2_invalidate_drawable, }; static const __DRIextension *dri_screen_extensions[] = { @@ -226,6 +241,68 @@ dri_fill_in_modes(struct dri_screen *screen, return (const __DRIconfig **)configs; } +/** + * Roughly the converse of dri_fill_in_modes. + */ +void +dri_fill_st_visual(struct st_visual *stvis, struct dri_screen *screen, + const __GLcontextModes *mode) +{ + memset(stvis, 0, sizeof(*stvis)); + + stvis->samples = mode->samples; + stvis->render_buffer = ST_ATTACHMENT_INVALID; + + if (mode->redBits == 8) { + if (mode->alphaBits == 8) + stvis->color_format = PIPE_FORMAT_B8G8R8A8_UNORM; + else + stvis->color_format = PIPE_FORMAT_B8G8R8X8_UNORM; + } else { + stvis->color_format = PIPE_FORMAT_B5G6R5_UNORM; + } + + switch (mode->depthBits) { + default: + case 0: + stvis->depth_stencil_format = PIPE_FORMAT_NONE; + break; + case 16: + stvis->depth_stencil_format = PIPE_FORMAT_Z16_UNORM; + break; + case 24: + if (mode->stencilBits == 0) { + stvis->depth_stencil_format = (screen->d_depth_bits_last) ? + PIPE_FORMAT_Z24X8_UNORM: + PIPE_FORMAT_X8Z24_UNORM; + } else { + stvis->depth_stencil_format = (screen->sd_depth_bits_last) ? + PIPE_FORMAT_Z24S8_UNORM: + PIPE_FORMAT_S8Z24_UNORM; + } + break; + case 32: + stvis->depth_stencil_format = PIPE_FORMAT_Z32_UNORM; + break; + } + + stvis->accum_format = (mode->haveAccumBuffer) ? + PIPE_FORMAT_R16G16B16A16_SNORM : PIPE_FORMAT_NONE; + + stvis->buffer_mask |= ST_ATTACHMENT_FRONT_LEFT_MASK; + if (mode->doubleBufferMode) + stvis->buffer_mask |= ST_ATTACHMENT_BACK_LEFT_MASK; + if (mode->stereoMode) { + stvis->buffer_mask |= ST_ATTACHMENT_FRONT_RIGHT_MASK; + if (mode->doubleBufferMode) + stvis->buffer_mask |= ST_ATTACHMENT_BACK_RIGHT_MASK; + } + + if (mode->haveDepthBuffer || mode->haveStencilBuffer) + stvis->buffer_mask |= ST_ATTACHMENT_DEPTH_STENCIL_MASK; + /* let the state tracker allocate the accum buffer */ +} + /** * Get information about previous buffer swaps. */ @@ -238,6 +315,33 @@ dri_get_swap_info(__DRIdrawable * dPriv, __DRIswapInfo * sInfo) return 0; } +static void +dri_destroy_screen(__DRIscreen * sPriv) +{ + struct dri_screen *screen = dri_screen(sPriv); + int i; + + if (screen->dri1_pipe) + screen->dri1_pipe->destroy(screen->dri1_pipe); + + if (screen->smapi) + dri_destroy_st_manager(screen->smapi); + if (screen->pipe_screen) + screen->pipe_screen->destroy(screen->pipe_screen); + + for (i = 0; i < (1 << screen->optionCache.tableSize); ++i) { + FREE(screen->optionCache.info[i].name); + FREE(screen->optionCache.info[i].ranges); + } + + FREE(screen->optionCache.info); + FREE(screen->optionCache.values); + + FREE(screen); + sPriv->private = NULL; + sPriv->extensions = NULL; +} + /** * This is the driver specific part of the createNewScreen entry point. * @@ -253,7 +357,7 @@ dri_init_screen2(__DRIscreen * sPriv) screen = CALLOC_STRUCT(dri_screen); if (!screen) - goto fail; + return NULL; screen->api = drm_api_create(); screen->sPriv = sPriv; @@ -268,9 +372,9 @@ dri_init_screen2(__DRIscreen * sPriv) goto fail; } - /* We need to hook in here */ - screen->pipe_screen->update_buffer = dri_update_buffer; - screen->pipe_screen->flush_frontbuffer = dri_flush_frontbuffer; + screen->smapi = dri_create_st_manager(screen); + if (!screen->smapi) + goto fail; driParseOptionInfo(&screen->optionCache, __driConfigOptions, __driNConfigOptions); @@ -279,30 +383,11 @@ dri_init_screen2(__DRIscreen * sPriv) dri2_ext->getBuffersWithFormat != NULL; return dri_fill_in_modes(screen, 32); - fail: +fail: + dri_destroy_screen(sPriv); return NULL; } -static void -dri_destroy_screen(__DRIscreen * sPriv) -{ - struct dri_screen *screen = dri_screen(sPriv); - int i; - - screen->pipe_screen->destroy(screen->pipe_screen); - - for (i = 0; i < (1 << screen->optionCache.tableSize); ++i) { - FREE(screen->optionCache.info[i].name); - FREE(screen->optionCache.info[i].ranges); - } - - FREE(screen->optionCache.info); - FREE(screen->optionCache.values); - - FREE(screen); - sPriv->private = NULL; -} - const struct __DriverAPIRec driDriverAPI = { .DestroyScreen = dri_destroy_screen, .CreateContext = dri_create_context, diff --git a/src/gallium/state_trackers/dri/dri_screen.h b/src/gallium/state_trackers/dri/dri_screen.h index 31301356923..e9944e0f63e 100644 --- a/src/gallium/state_trackers/dri/dri_screen.h +++ b/src/gallium/state_trackers/dri/dri_screen.h @@ -36,6 +36,9 @@ #include "xmlconfig.h" #include "pipe/p_compiler.h" +#include "pipe/p_context.h" +#include "pipe/p_state.h" +#include "state_tracker/st_api.h" struct dri_screen { @@ -58,6 +61,11 @@ struct dri_screen boolean d_depth_bits_last; boolean sd_depth_bits_last; boolean auto_fake_front; + + struct st_manager *smapi; + + /* used only by DRI1 */ + struct pipe_context *dri1_pipe; }; /** cast wrapper */ @@ -72,6 +80,10 @@ extern const uint __driNConfigOptions; const __DRIconfig ** dri_fill_in_modes(struct dri_screen *screen, unsigned pixel_bits); +void +dri_fill_st_visual(struct st_visual *stvis, struct dri_screen *screen, + const __GLcontextModes *mode); + #endif /* vim: set sw=3 ts=8 sts=3 expandtab: */ diff --git a/src/gallium/state_trackers/dri/dri_st_api.c b/src/gallium/state_trackers/dri/dri_st_api.c index 379515152e8..2cde01967d8 100644 --- a/src/gallium/state_trackers/dri/dri_st_api.c +++ b/src/gallium/state_trackers/dri/dri_st_api.c @@ -274,8 +274,8 @@ dri_st_framebuffer_validate(struct st_framebuffer_iface *stfbi, if (drawable->texture_stamp != drawable->dPriv->lastStamp || (statt_mask & ~drawable->texture_mask)) { if (__dri1_api_hooks) { - /* TODO */ - return FALSE; + dri1_allocate_textures(drawable, + drawable->dPriv->w, drawable->dPriv->h, statt_mask); } else { __DRIbuffer *buffers; @@ -309,9 +309,12 @@ dri_st_framebuffer_flush_front(struct st_framebuffer_iface *stfbi, struct __DRIdri2LoaderExtensionRec *loader = drawable->sPriv->dri2.loader; - /* TODO */ - if (__dri1_api_hooks) - return FALSE; + if (__dri1_api_hooks) { + struct pipe_texture *ptex = drawable->textures[statt]; + if (ptex) + dri1_flush_frontbuffer(drawable, ptex); + return TRUE; + } if (statt == ST_ATTACHMENT_FRONT_LEFT && loader->flushFrontBuffer) { loader->flushFrontBuffer(drawable->dPriv, -- cgit v1.2.3 From 9d48a621d2a0e55a76a2cfd0aea3b773e907ed50 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Thu, 18 Mar 2010 10:24:10 +0000 Subject: llvmpipe: Fix crashes when there is no depth buffer bound. --- src/gallium/drivers/llvmpipe/lp_state_fs.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/gallium') diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs.c b/src/gallium/drivers/llvmpipe/lp_state_fs.c index b38e0f393dc..2cecf7e0974 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_fs.c +++ b/src/gallium/drivers/llvmpipe/lp_state_fs.c @@ -152,6 +152,9 @@ generate_depth_stencil(LLVMBuilderRef builder, const struct util_format_description *format_desc; struct lp_type dst_type; + if (!key->depth.enabled && !key->stencil[0].enabled && !key->stencil[1].enabled) + return; + format_desc = util_format_description(key->zsbuf_format); assert(format_desc); -- cgit v1.2.3 From a1e7aeecc25cedbd54e43afa72a1a2926ae51a32 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Thu, 18 Mar 2010 09:30:13 -0600 Subject: llvmpipe: set opaque = FALSE if stencil enabled Fixes occasional bad tiles seen in some demos like progs/demos/reflect.c --- src/gallium/drivers/llvmpipe/lp_state_fs.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/gallium') diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs.c b/src/gallium/drivers/llvmpipe/lp_state_fs.c index 2cecf7e0974..921c51fbe84 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_fs.c +++ b/src/gallium/drivers/llvmpipe/lp_state_fs.c @@ -1169,6 +1169,7 @@ llvmpipe_update_fs(struct llvmpipe_context *lp) opaque = !key.blend.logicop_enable && !key.blend.rt[0].blend_enable && key.blend.rt[0].colormask == 0xf && + !key.stencil[0].enabled && !key.alpha.enabled && !key.depth.enabled && !key.scissor && -- cgit v1.2.3 From ecf85c7d750478e433e640897bb25a18069f14de Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Thu, 18 Mar 2010 11:18:01 -0600 Subject: gallivm: checkpoint WIP two-sided stencil test --- src/gallium/auxiliary/gallivm/lp_bld_depth.c | 221 +++++++++++++++++++++++---- 1 file changed, 191 insertions(+), 30 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/auxiliary/gallivm/lp_bld_depth.c b/src/gallium/auxiliary/gallivm/lp_bld_depth.c index e4500e5aef1..49de5c94a3c 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_depth.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_depth.c @@ -52,7 +52,14 @@ * Z31 Z32 Z41 Z42 Z33 Z34 Z43 Z44 ... * ... ... ... ... ... ... ... ... ... * - * FIXME: Code generate stencil test + * + * Stencil test: + * Two-sided stencil test is supported but probably not as efficient as + * it could be. Currently, we use if/then/else constructs to do the + * operations for front vs. back-facing polygons. We could probably do + * both the front and back arithmetic then use a Select() instruction to + * choose the result depending on polyon orientation. We'd have to + * measure performance both ways and see which is better. * * @author Jose Fonseca */ @@ -70,18 +77,28 @@ #include "lp_bld_swizzle.h" +/** Used to select fields from pipe_stencil_state */ +enum stencil_op { + S_FAIL_OP, + Z_FAIL_OP, + Z_PASS_OP +}; + + /** - * Do the stencil test comparison (compare fb Z values against ref value. - * \param stencilVals vector of stencil values from framebuffer + * Do the stencil test comparison (compare FB stencil values against ref value). + * This will be used twice when generating two-sided stencil code. + * \param stencil the front/back stencil state * \param stencilRef the stencil reference value, replicated as a vector - * \return mask of pass/fail values + * \param stencilVals vector of stencil values from framebuffer + * \return vector mask of pass/fail values (~0 or 0) */ static LLVMValueRef -lp_build_stencil_test(struct lp_build_context *bld, - const struct pipe_stencil_state *stencil, - LLVMValueRef stencilRef, - LLVMValueRef stencilVals) +lp_build_stencil_test_single(struct lp_build_context *bld, + const struct pipe_stencil_state *stencil, + LLVMValueRef stencilRef, + LLVMValueRef stencilVals) { const unsigned stencilMax = 255; /* XXX fix */ struct lp_type type = bld->type; @@ -103,24 +120,100 @@ lp_build_stencil_test(struct lp_build_context *bld, } +/** + * Do the one or two-sided stencil test comparison. + * \sa lp_build_stencil_test_single + * \param face an integer indicating front (+) or back (-) facing polygon. + * If NULL, assume front-facing. + */ +static LLVMValueRef +lp_build_stencil_test(struct lp_build_context *bld, + const struct pipe_stencil_state stencil[2], + LLVMValueRef stencilRefs[2], + LLVMValueRef stencilVals, + LLVMValueRef face) +{ + LLVMValueRef res; + + assert(stencil[0].enabled); + + if (stencil[1].enabled && face) { + /* do two-sided test */ + struct lp_build_flow_context *flow_ctx; + struct lp_build_if_state if_ctx; + LLVMValueRef front_facing; + LLVMValueRef zero = LLVMConstReal(LLVMFloatType(), 0.0); + LLVMValueRef result = NULL; + + flow_ctx = lp_build_flow_create(bld->builder); + lp_build_flow_scope_begin(flow_ctx); + + lp_build_flow_scope_declare(flow_ctx, &result); + + /* front_facing = face > 0.0 */ + front_facing = lp_build_cmp(bld, PIPE_FUNC_GREATER, face, zero); + + lp_build_if(&if_ctx, flow_ctx, bld->builder, front_facing); + { + result = lp_build_stencil_test_single(bld, &stencil[0], + stencilRefs[0], stencilVals); + } + lp_build_else(&if_ctx); + { + result = lp_build_stencil_test_single(bld, &stencil[1], + stencilRefs[1], stencilVals); + } + lp_build_endif(&if_ctx); + + lp_build_flow_scope_end(flow_ctx); + lp_build_flow_destroy(flow_ctx); + + res = result; + } + else { + /* do single-side test */ + res = lp_build_stencil_test_single(bld, &stencil[0], + stencilRefs[0], stencilVals); + } + + return res; +} + + /** * Apply the stencil operator (add/sub/keep/etc) to the given vector * of stencil values. * \return new stencil values vector */ static LLVMValueRef -lp_build_stencil_op(struct lp_build_context *bld, - const struct pipe_stencil_state *stencil, - unsigned stencil_op, - LLVMValueRef stencilRef, - LLVMValueRef stencilVals, - LLVMValueRef mask) +lp_build_stencil_op_single(struct lp_build_context *bld, + const struct pipe_stencil_state *stencil, + enum stencil_op op, + LLVMValueRef stencilRef, + LLVMValueRef stencilVals, + LLVMValueRef mask) { const unsigned stencilMax = 255; /* XXX fix */ struct lp_type type = bld->type; LLVMValueRef res; LLVMValueRef max = lp_build_const_int_vec(type, stencilMax); + unsigned stencil_op; + + switch (op) { + case S_FAIL_OP: + stencil_op = stencil->fail_op; + break; + case Z_FAIL_OP: + stencil_op = stencil->zfail_op; + break; + case Z_PASS_OP: + stencil_op = stencil->zpass_op; + break; + default: + assert(0 && "Invalid stencil_op mode"); + stencil_op = PIPE_STENCIL_OP_KEEP; + } switch (stencil_op) { case PIPE_STENCIL_OP_KEEP: @@ -173,6 +266,63 @@ lp_build_stencil_op(struct lp_build_context *bld, } +/** + * Do the one or two-sided stencil test op/update. + */ +static LLVMValueRef +lp_build_stencil_op(struct lp_build_context *bld, + const struct pipe_stencil_state stencil[2], + enum stencil_op op, + LLVMValueRef stencilRefs[2], + LLVMValueRef stencilVals, + LLVMValueRef mask, + LLVMValueRef face) + +{ + assert(stencil[0].enabled); + + if (stencil[1].enabled && face) { + /* do two-sided op */ + struct lp_build_flow_context *flow_ctx; + struct lp_build_if_state if_ctx; + LLVMValueRef front_facing; + LLVMValueRef zero = LLVMConstReal(LLVMFloatType(), 0.0); + LLVMValueRef result = NULL; + + flow_ctx = lp_build_flow_create(bld->builder); + lp_build_flow_scope_begin(flow_ctx); + + lp_build_flow_scope_declare(flow_ctx, &result); + + /* front_facing = face > 0.0 */ + front_facing = lp_build_cmp(bld, PIPE_FUNC_GREATER, face, zero); + + lp_build_if(&if_ctx, flow_ctx, bld->builder, front_facing); + { + result = lp_build_stencil_op_single(bld, &stencil[0], op, + stencilRefs[0], stencilVals, mask); + } + lp_build_else(&if_ctx); + { + result = lp_build_stencil_op_single(bld, &stencil[1], op, + stencilRefs[1], stencilVals, mask); + } + lp_build_endif(&if_ctx); + + lp_build_flow_scope_end(flow_ctx); + lp_build_flow_destroy(flow_ctx); + + return result; + } + else { + /* do single-sided op */ + return lp_build_stencil_op_single(bld, &stencil[0], op, + stencilRefs[0], stencilVals, mask); + } +} + + + /** * Return a type appropriate for depth/stencil testing. */ @@ -213,14 +363,19 @@ lp_depth_type(const struct util_format_description *format_desc, } +/** Get front/back-face stencil ref value */ static LLVMValueRef lp_build_get_stencil_ref(struct lp_build_context *bld, - struct lp_type type, LLVMValueRef stencil_refs_ptr) + struct lp_type type, LLVMValueRef stencil_refs_ptr, + unsigned face_index) { LLVMValueRef indexes[2], ptr, ref, ref_vec; - /* load 0th element of the array */ - indexes[0] = indexes[1] = LLVMConstInt(LLVMInt32Type(), 0, 0); + assert(face_index < 2); + + /* load [face_index] element of the array */ + indexes[0] = LLVMConstInt(LLVMInt32Type(), 0, 0); + indexes[1] = LLVMConstInt(LLVMInt32Type(), face_index, 0); ptr = LLVMBuildGEP(bld->builder, stencil_refs_ptr, indexes, 2, ""); ref = LLVMBuildLoad(bld->builder, ptr, ""); @@ -251,17 +406,19 @@ lp_build_depth_stencil_test(LLVMBuilderRef builder, struct lp_type type, const struct util_format_description *format_desc, struct lp_build_mask_context *mask, - LLVMValueRef stencil_refs, + LLVMValueRef stencil_refs_ptr, LLVMValueRef z_src, LLVMValueRef zs_dst_ptr) { struct lp_build_context bld; unsigned z_swizzle, s_swizzle; + LLVMValueRef stencil_refs[2]; LLVMValueRef zs_dst, z_dst = NULL; LLVMValueRef stencil_vals = NULL; LLVMValueRef z_bitmask = NULL, s_bitmask = NULL; LLVMValueRef z_pass = NULL, s_pass_mask = NULL; LLVMValueRef orig_mask = mask->value; + LLVMValueRef face = NULL; assert(depth->enabled || stencil[0].enabled); @@ -345,25 +502,29 @@ lp_build_depth_stencil_test(LLVMBuilderRef builder, lp_build_name(z_dst, "zsbuf.z"); - /* + printf("build depth %d stencil %d\n", depth->enabled, stencil[0].enabled); - */ + if (stencil[0].enabled) { /* Incoming stencil_refs is ptr to int8[2]. Get/convert to int32[4]. */ - stencil_refs = lp_build_get_stencil_ref(&bld, type, stencil_refs); + stencil_refs[0] = lp_build_get_stencil_ref(&bld, type, stencil_refs_ptr, 0); + + if (stencil[1].enabled) + stencil_refs[1] = + lp_build_get_stencil_ref(&bld, type, stencil_refs_ptr, 1); s_pass_mask = lp_build_stencil_test(&bld, stencil, - stencil_refs, stencil_vals); + stencil_refs, stencil_vals, face); /* apply stencil-fail operator */ { LLVMValueRef s_fail_mask = lp_build_andc(&bld, orig_mask, s_pass_mask); - stencil_vals = lp_build_stencil_op(&bld, stencil, stencil[0].fail_op, + stencil_vals = lp_build_stencil_op(&bld, stencil, S_FAIL_OP, stencil_refs, stencil_vals, - s_fail_mask); + s_fail_mask, face); } } @@ -394,15 +555,15 @@ lp_build_depth_stencil_test(LLVMBuilderRef builder, /* apply Z-fail operator */ z_fail_mask = lp_build_andc(&bld, orig_mask, z_pass); - stencil_vals = lp_build_stencil_op(&bld, stencil, stencil[0].zfail_op, + stencil_vals = lp_build_stencil_op(&bld, stencil, Z_FAIL_OP, stencil_refs, stencil_vals, - z_fail_mask); + z_fail_mask, face); /* apply Z-pass operator */ z_pass_mask = LLVMBuildAnd(bld.builder, orig_mask, z_pass, ""); - stencil_vals = lp_build_stencil_op(&bld, stencil, stencil[0].zpass_op, + stencil_vals = lp_build_stencil_op(&bld, stencil, Z_PASS_OP, stencil_refs, stencil_vals, - z_pass_mask); + z_pass_mask, face); } } else { @@ -410,8 +571,8 @@ lp_build_depth_stencil_test(LLVMBuilderRef builder, * passed the stencil test. */ s_pass_mask = LLVMBuildAnd(bld.builder, orig_mask, s_pass_mask, ""); - stencil_vals = lp_build_stencil_op(&bld, stencil, stencil[0].zpass_op, - stencil_refs, stencil_vals, s_pass_mask); + stencil_vals = lp_build_stencil_op(&bld, stencil, Z_PASS_OP, stencil_refs, + stencil_vals, s_pass_mask, face); } /* Finally, merge/store the z/stencil values */ -- cgit v1.2.3 From 521c61ff017ab15b829abbe9a98b179136a36009 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Thu, 18 Mar 2010 11:31:38 -0600 Subject: gallivm/llvmpipe: simplify front/back stencil ref value handling Instead of passing an array, just pass two scalar values. --- src/gallium/auxiliary/gallivm/lp_bld_depth.c | 41 ++++------------------------ src/gallium/auxiliary/gallivm/lp_bld_depth.h | 2 +- src/gallium/drivers/llvmpipe/lp_jit.c | 10 +++++-- src/gallium/drivers/llvmpipe/lp_jit.h | 12 +++++--- src/gallium/drivers/llvmpipe/lp_setup.c | 8 +++--- src/gallium/drivers/llvmpipe/lp_state_fs.c | 7 +++-- 6 files changed, 30 insertions(+), 50 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/auxiliary/gallivm/lp_bld_depth.c b/src/gallium/auxiliary/gallivm/lp_bld_depth.c index 49de5c94a3c..c253764e603 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_depth.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_depth.c @@ -363,32 +363,6 @@ lp_depth_type(const struct util_format_description *format_desc, } -/** Get front/back-face stencil ref value */ -static LLVMValueRef -lp_build_get_stencil_ref(struct lp_build_context *bld, - struct lp_type type, LLVMValueRef stencil_refs_ptr, - unsigned face_index) -{ - LLVMValueRef indexes[2], ptr, ref, ref_vec; - - assert(face_index < 2); - - /* load [face_index] element of the array */ - indexes[0] = LLVMConstInt(LLVMInt32Type(), 0, 0); - indexes[1] = LLVMConstInt(LLVMInt32Type(), face_index, 0); - ptr = LLVMBuildGEP(bld->builder, stencil_refs_ptr, indexes, 2, ""); - ref = LLVMBuildLoad(bld->builder, ptr, ""); - - /* convert int8 value to i32 */ - ref = LLVMBuildZExt(bld->builder, ref, LLVMIntType(type.width), ""); - - /* make scalar into vector */ - ref_vec = lp_build_broadcast_scalar(bld, ref); - - return ref_vec; -} - - /** * Generate code for performing depth and/or stencil tests. * We operate on a vector of values (typically a 2x2 quad). @@ -406,13 +380,12 @@ lp_build_depth_stencil_test(LLVMBuilderRef builder, struct lp_type type, const struct util_format_description *format_desc, struct lp_build_mask_context *mask, - LLVMValueRef stencil_refs_ptr, + LLVMValueRef stencil_refs[2], LLVMValueRef z_src, LLVMValueRef zs_dst_ptr) { struct lp_build_context bld; unsigned z_swizzle, s_swizzle; - LLVMValueRef stencil_refs[2]; LLVMValueRef zs_dst, z_dst = NULL; LLVMValueRef stencil_vals = NULL; LLVMValueRef z_bitmask = NULL, s_bitmask = NULL; @@ -502,19 +475,17 @@ lp_build_depth_stencil_test(LLVMBuilderRef builder, lp_build_name(z_dst, "zsbuf.z"); - + /* printf("build depth %d stencil %d\n", depth->enabled, stencil[0].enabled); - + */ if (stencil[0].enabled) { - /* Incoming stencil_refs is ptr to int8[2]. Get/convert to int32[4]. */ - stencil_refs[0] = lp_build_get_stencil_ref(&bld, type, stencil_refs_ptr, 0); + /* convert scalar stencil refs into vectors */ + stencil_refs[0] = lp_build_broadcast_scalar(&bld, stencil_refs[0]); + stencil_refs[1] = lp_build_broadcast_scalar(&bld, stencil_refs[1]); - if (stencil[1].enabled) - stencil_refs[1] = - lp_build_get_stencil_ref(&bld, type, stencil_refs_ptr, 1); s_pass_mask = lp_build_stencil_test(&bld, stencil, stencil_refs, stencil_vals, face); diff --git a/src/gallium/auxiliary/gallivm/lp_bld_depth.h b/src/gallium/auxiliary/gallivm/lp_bld_depth.h index eedc1e419b5..5708ced9839 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_depth.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_depth.h @@ -57,7 +57,7 @@ lp_build_depth_stencil_test(LLVMBuilderRef builder, struct lp_type type, const struct util_format_description *format_desc, struct lp_build_mask_context *mask, - LLVMValueRef stencil_refs, + LLVMValueRef stencil_refs[2], LLVMValueRef zs_src, LLVMValueRef zs_dst_ptr); diff --git a/src/gallium/drivers/llvmpipe/lp_jit.c b/src/gallium/drivers/llvmpipe/lp_jit.c index 1eee9212e6f..927e472ff26 100644 --- a/src/gallium/drivers/llvmpipe/lp_jit.c +++ b/src/gallium/drivers/llvmpipe/lp_jit.c @@ -96,7 +96,8 @@ lp_jit_init_globals(struct llvmpipe_screen *screen) elem_types[LP_JIT_CTX_CONSTANTS] = LLVMPointerType(LLVMFloatType(), 0); elem_types[LP_JIT_CTX_ALPHA_REF] = LLVMFloatType(); - elem_types[LP_JIT_CTX_STENCIL_REF] = LLVMArrayType(LLVMInt8Type(), 2); + elem_types[LP_JIT_CTX_STENCIL_REF_FRONT] = LLVMInt32Type(); + elem_types[LP_JIT_CTX_STENCIL_REF_BACK] = LLVMInt32Type(); elem_types[LP_JIT_CTX_SCISSOR_XMIN] = LLVMFloatType(); elem_types[LP_JIT_CTX_SCISSOR_YMIN] = LLVMFloatType(); elem_types[LP_JIT_CTX_SCISSOR_XMAX] = LLVMFloatType(); @@ -113,9 +114,12 @@ lp_jit_init_globals(struct llvmpipe_screen *screen) LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, alpha_ref_value, screen->target, context_type, LP_JIT_CTX_ALPHA_REF); - LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, stencil_ref, + LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, stencil_ref_front, screen->target, context_type, - LP_JIT_CTX_STENCIL_REF); + LP_JIT_CTX_STENCIL_REF_FRONT); + LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, stencil_ref_back, + screen->target, context_type, + LP_JIT_CTX_STENCIL_REF_BACK); LP_CHECK_MEMBER_OFFSET(struct lp_jit_context, scissor_xmin, screen->target, context_type, LP_JIT_CTX_SCISSOR_XMIN); diff --git a/src/gallium/drivers/llvmpipe/lp_jit.h b/src/gallium/drivers/llvmpipe/lp_jit.h index 63e05c5d5e1..bbd0c9610de 100644 --- a/src/gallium/drivers/llvmpipe/lp_jit.h +++ b/src/gallium/drivers/llvmpipe/lp_jit.h @@ -84,7 +84,7 @@ struct lp_jit_context float alpha_ref_value; - uint8_t stencil_ref[2]; + uint32_t stencil_ref_front, stencil_ref_back; /** floats, not ints */ float scissor_xmin, scissor_ymin, scissor_xmax, scissor_ymax; @@ -103,7 +103,8 @@ struct lp_jit_context enum { LP_JIT_CTX_CONSTANTS = 0, LP_JIT_CTX_ALPHA_REF, - LP_JIT_CTX_STENCIL_REF, + LP_JIT_CTX_STENCIL_REF_FRONT, + LP_JIT_CTX_STENCIL_REF_BACK, LP_JIT_CTX_SCISSOR_XMIN, LP_JIT_CTX_SCISSOR_YMIN, LP_JIT_CTX_SCISSOR_XMAX, @@ -120,8 +121,11 @@ enum { #define lp_jit_context_alpha_ref_value(_builder, _ptr) \ lp_build_struct_get(_builder, _ptr, LP_JIT_CTX_ALPHA_REF, "alpha_ref_value") -#define lp_jit_context_stencil_ref_values(_builder, _ptr) \ - lp_build_struct_get_ptr(_builder, _ptr, LP_JIT_CTX_STENCIL_REF, "stencil_ref") +#define lp_jit_context_stencil_ref_front_value(_builder, _ptr) \ + lp_build_struct_get(_builder, _ptr, LP_JIT_CTX_STENCIL_REF_FRONT, "stencil_ref_front") + +#define lp_jit_context_stencil_ref_back_value(_builder, _ptr) \ + lp_build_struct_get(_builder, _ptr, LP_JIT_CTX_STENCIL_REF_BACK, "stencil_ref_back") #define lp_jit_context_scissor_xmin_value(_builder, _ptr) \ lp_build_struct_get(_builder, _ptr, LP_JIT_CTX_SCISSOR_XMIN, "scissor_xmin") diff --git a/src/gallium/drivers/llvmpipe/lp_setup.c b/src/gallium/drivers/llvmpipe/lp_setup.c index bcc9d1fc1a4..fbb0d6f8a60 100644 --- a/src/gallium/drivers/llvmpipe/lp_setup.c +++ b/src/gallium/drivers/llvmpipe/lp_setup.c @@ -407,10 +407,10 @@ lp_setup_set_stencil_ref_values( struct lp_setup_context *setup, { LP_DBG(DEBUG_SETUP, "%s %d %d\n", __FUNCTION__, refs[0], refs[1]); - if (setup->fs.current.jit_context.stencil_ref[0] != refs[0] || - setup->fs.current.jit_context.stencil_ref[1] != refs[1]) { - setup->fs.current.jit_context.stencil_ref[0] = refs[0]; - setup->fs.current.jit_context.stencil_ref[1] = refs[1]; + if (setup->fs.current.jit_context.stencil_ref_front != refs[0] || + setup->fs.current.jit_context.stencil_ref_back != refs[1]) { + setup->fs.current.jit_context.stencil_ref_front = refs[0]; + setup->fs.current.jit_context.stencil_ref_back = refs[1]; setup->dirty |= LP_SETUP_NEW_FS; } } diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs.c b/src/gallium/drivers/llvmpipe/lp_state_fs.c index 921c51fbe84..0f96654a673 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_fs.c +++ b/src/gallium/drivers/llvmpipe/lp_state_fs.c @@ -145,7 +145,7 @@ generate_depth_stencil(LLVMBuilderRef builder, const struct lp_fragment_shader_variant_key *key, struct lp_type src_type, struct lp_build_mask_context *mask, - LLVMValueRef stencil_refs, + LLVMValueRef stencil_refs[2], LLVMValueRef src, LLVMValueRef dst_ptr) { @@ -408,7 +408,7 @@ generate_fs(struct llvmpipe_context *lp, LLVMValueRef consts_ptr; LLVMValueRef outputs[PIPE_MAX_SHADER_OUTPUTS][NUM_CHANNELS]; LLVMValueRef z = interp->pos[2]; - LLVMValueRef stencil_refs; + LLVMValueRef stencil_refs[2]; struct lp_build_flow_context *flow; struct lp_build_mask_context mask; boolean early_depth_stencil_test; @@ -418,7 +418,8 @@ generate_fs(struct llvmpipe_context *lp, assert(i < 4); - stencil_refs = lp_jit_context_stencil_ref_values(builder, context_ptr); + stencil_refs[0] = lp_jit_context_stencil_ref_front_value(builder, context_ptr); + stencil_refs[1] = lp_jit_context_stencil_ref_back_value(builder, context_ptr); elem_type = lp_build_elem_type(type); vec_type = lp_build_vec_type(type); -- cgit v1.2.3 From 94abc4b51e134bee1ace2b57400e35c295bda6f8 Mon Sep 17 00:00:00 2001 From: Alan Hourihane Date: Thu, 18 Mar 2010 18:01:05 +0000 Subject: Add format B5G5R5X1 --- src/gallium/auxiliary/util/u_format.csv | 1 + src/gallium/auxiliary/util/u_format_tests.c | 7 ++++ src/gallium/auxiliary/util/u_gen_mipmap.c | 1 + src/gallium/auxiliary/util/u_pack_color.h | 19 ++++++++++ src/gallium/auxiliary/util/u_tile.c | 55 +++++++++++++++++++++++++++++ src/gallium/include/pipe/p_format.h | 1 + 6 files changed, 84 insertions(+) (limited to 'src/gallium') diff --git a/src/gallium/auxiliary/util/u_format.csv b/src/gallium/auxiliary/util/u_format.csv index 96a0fa65507..11243e73492 100644 --- a/src/gallium/auxiliary/util/u_format.csv +++ b/src/gallium/auxiliary/util/u_format.csv @@ -63,6 +63,7 @@ PIPE_FORMAT_A8R8G8B8_UNORM , plain, 1, 1, un8 , un8 , un8 , un8 , yzwx, r PIPE_FORMAT_X8R8G8B8_UNORM , plain, 1, 1, un8 , un8 , un8 , un8 , yzw1, rgb PIPE_FORMAT_A8B8G8R8_UNORM , plain, 1, 1, un8 , un8 , un8 , un8 , wzyx, rgb PIPE_FORMAT_X8B8G8R8_UNORM , plain, 1, 1, un8 , un8 , un8 , un8 , wzy1, rgb +PIPE_FORMAT_B5G5R5X1_UNORM , plain, 1, 1, un5 , un5 , un5 , un1 , zyx1, rgb PIPE_FORMAT_B5G5R5A1_UNORM , plain, 1, 1, un5 , un5 , un5 , un1 , zyxw, rgb PIPE_FORMAT_B4G4R4A4_UNORM , plain, 1, 1, un4 , un4 , un4 , un4 , zyxw, rgb PIPE_FORMAT_B5G6R5_UNORM , plain, 1, 1, un5 , un6 , un5 , , zyx1, rgb diff --git a/src/gallium/auxiliary/util/u_format_tests.c b/src/gallium/auxiliary/util/u_format_tests.c index 182a4740448..9d6debcd8c7 100644 --- a/src/gallium/auxiliary/util/u_format_tests.c +++ b/src/gallium/auxiliary/util/u_format_tests.c @@ -120,6 +120,13 @@ util_format_test_cases[] = * 16-bit rendertarget formats */ + {PIPE_FORMAT_B5G5R5X1_UNORM, PACKED_1x16(0x7fff), PACKED_1x16(0x0000), {0.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_B5G5R5X1_UNORM, PACKED_1x16(0x7fff), PACKED_1x16(0x001f), {0.0, 0.0, 1.0, 0.0}}, + {PIPE_FORMAT_B5G5R5X1_UNORM, PACKED_1x16(0x7fff), PACKED_1x16(0x03e0), {0.0, 1.0, 0.0, 0.0}}, + {PIPE_FORMAT_B5G5R5X1_UNORM, PACKED_1x16(0x7fff), PACKED_1x16(0x7c00), {1.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_B5G5R5X1_UNORM, PACKED_1x16(0x7fff), PACKED_1x16(0x8000), {0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_B5G5R5X1_UNORM, PACKED_1x16(0x7fff), PACKED_1x16(0xffff), {1.0, 1.0, 1.0, 1.0}}, + {PIPE_FORMAT_B5G5R5A1_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x0000), {0.0, 0.0, 0.0, 0.0}}, {PIPE_FORMAT_B5G5R5A1_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x001f), {0.0, 0.0, 1.0, 0.0}}, {PIPE_FORMAT_B5G5R5A1_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x03e0), {0.0, 1.0, 0.0, 0.0}}, diff --git a/src/gallium/auxiliary/util/u_gen_mipmap.c b/src/gallium/auxiliary/util/u_gen_mipmap.c index 61d64cff6d4..509d38754f5 100644 --- a/src/gallium/auxiliary/util/u_gen_mipmap.c +++ b/src/gallium/auxiliary/util/u_gen_mipmap.c @@ -938,6 +938,7 @@ format_to_type_comps(enum pipe_format pformat, *datatype = DTYPE_UBYTE; *comps = 4; return; + case PIPE_FORMAT_B5G5R5X1_UNORM: case PIPE_FORMAT_B5G5R5A1_UNORM: *datatype = DTYPE_USHORT_1_5_5_5_REV; *comps = 4; diff --git a/src/gallium/auxiliary/util/u_pack_color.h b/src/gallium/auxiliary/util/u_pack_color.h index 50f1b1670b6..c5fd7a6783e 100644 --- a/src/gallium/auxiliary/util/u_pack_color.h +++ b/src/gallium/auxiliary/util/u_pack_color.h @@ -92,6 +92,11 @@ util_pack_color_ub(ubyte r, ubyte g, ubyte b, ubyte a, uc->us = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | (b >> 3); } return; + case PIPE_FORMAT_B5G5R5X1_UNORM: + { + uc->us = ((0x80) << 8) | ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | (b >> 3); + } + return; case PIPE_FORMAT_B5G5R5A1_UNORM: { uc->us = ((a & 0x80) << 8) | ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | (b >> 3); @@ -216,6 +221,15 @@ util_unpack_color_ub(enum pipe_format format, union util_color *uc, *a = (ubyte) 0xff; } return; + case PIPE_FORMAT_B5G5R5X1_UNORM: + { + ushort p = uc->us; + *r = (ubyte) (((p >> 7) & 0xf8) | ((p >> 12) & 0x7)); + *g = (ubyte) (((p >> 2) & 0xf8) | ((p >> 7) & 0x7)); + *b = (ubyte) (((p << 3) & 0xf8) | ((p >> 2) & 0x7)); + *a = (ubyte) 0xff; + } + return; case PIPE_FORMAT_B5G5R5A1_UNORM: { ushort p = uc->us; @@ -361,6 +375,11 @@ util_pack_color(const float rgba[4], enum pipe_format format, union util_color * uc->us = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | (b >> 3); } return; + case PIPE_FORMAT_B5G5R5X1_UNORM: + { + uc->us = ((0x80) << 8) | ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | (b >> 3); + } + return; case PIPE_FORMAT_B5G5R5A1_UNORM: { uc->us = ((a & 0x80) << 8) | ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | (b >> 3); diff --git a/src/gallium/auxiliary/util/u_tile.c b/src/gallium/auxiliary/util/u_tile.c index 82e44192aaf..09b2382733d 100644 --- a/src/gallium/auxiliary/util/u_tile.c +++ b/src/gallium/auxiliary/util/u_tile.c @@ -295,6 +295,55 @@ r8g8b8a8_put_tile_rgba(unsigned *dst, } +/*** PIPE_FORMAT_B5G5R5X1_UNORM ***/ + +static void +x1r5g5b5_get_tile_rgba(const ushort *src, + unsigned w, unsigned h, + float *p, + unsigned dst_stride) +{ + unsigned i, j; + + for (i = 0; i < h; i++) { + float *pRow = p; + for (j = 0; j < w; j++, pRow += 4) { + const ushort pixel = *src++; + pRow[0] = ((pixel >> 10) & 0x1f) * (1.0f / 31.0f); + pRow[1] = ((pixel >> 5) & 0x1f) * (1.0f / 31.0f); + pRow[2] = ((pixel ) & 0x1f) * (1.0f / 31.0f); + pRow[3] = 1.0f; + } + p += dst_stride; + } +} + + +static void +x1r5g5b5_put_tile_rgba(ushort *dst, + unsigned w, unsigned h, + const float *p, + unsigned src_stride) +{ + unsigned i, j; + + for (i = 0; i < h; i++) { + const float *pRow = p; + for (j = 0; j < w; j++, pRow += 4) { + unsigned r, g, b; + r = float_to_ubyte(pRow[0]); + g = float_to_ubyte(pRow[1]); + b = float_to_ubyte(pRow[2]); + r = r >> 3; /* 5 bits */ + g = g >> 3; /* 5 bits */ + b = b >> 3; /* 5 bits */ + *dst++ = (1 << 15) | (r << 10) | (g << 5) | b; + } + p += src_stride; + } +} + + /*** PIPE_FORMAT_B5G5R5A1_UNORM ***/ static void @@ -1174,6 +1223,9 @@ pipe_tile_raw_to_rgba(enum pipe_format format, case PIPE_FORMAT_A8B8G8R8_UNORM: r8g8b8a8_get_tile_rgba((unsigned *) src, w, h, dst, dst_stride); break; + case PIPE_FORMAT_B5G5R5X1_UNORM: + x1r5g5b5_get_tile_rgba((ushort *) src, w, h, dst, dst_stride); + break; case PIPE_FORMAT_B5G5R5A1_UNORM: a1r5g5b5_get_tile_rgba((ushort *) src, w, h, dst, dst_stride); break; @@ -1368,6 +1420,9 @@ pipe_put_tile_rgba(struct pipe_context *pipe, case PIPE_FORMAT_A8B8G8R8_UNORM: r8g8b8a8_put_tile_rgba((unsigned *) packed, w, h, p, src_stride); break; + case PIPE_FORMAT_B5G5R5X1_UNORM: + x1r5g5b5_put_tile_rgba((ushort *) packed, w, h, p, src_stride); + break; case PIPE_FORMAT_B5G5R5A1_UNORM: a1r5g5b5_put_tile_rgba((ushort *) packed, w, h, p, src_stride); break; diff --git a/src/gallium/include/pipe/p_format.h b/src/gallium/include/pipe/p_format.h index cbf3273ec8d..ba2985f4491 100644 --- a/src/gallium/include/pipe/p_format.h +++ b/src/gallium/include/pipe/p_format.h @@ -157,6 +157,7 @@ enum pipe_format { PIPE_FORMAT_DXT5_SRGBA = 109, PIPE_FORMAT_A8B8G8R8_UNORM = 110, + PIPE_FORMAT_B5G5R5X1_UNORM = 111, PIPE_FORMAT_COUNT }; -- cgit v1.2.3 From d219b8a022a6fdaa0106c6e160b594c359f85185 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Thu, 18 Mar 2010 12:04:50 -0600 Subject: llvmpipe: defines for RAST_WHOLE, RAST_EDGE_TEST --- src/gallium/drivers/llvmpipe/lp_jit.h | 5 ++++ src/gallium/drivers/llvmpipe/lp_rast.c | 38 ++++++++++++++++-------------- src/gallium/drivers/llvmpipe/lp_state_fs.c | 4 ++-- 3 files changed, 27 insertions(+), 20 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/llvmpipe/lp_jit.h b/src/gallium/drivers/llvmpipe/lp_jit.h index bbd0c9610de..690b4393079 100644 --- a/src/gallium/drivers/llvmpipe/lp_jit.h +++ b/src/gallium/drivers/llvmpipe/lp_jit.h @@ -146,6 +146,11 @@ enum { lp_build_struct_get_ptr(_builder, _ptr, LP_JIT_CONTEXT_TEXTURES, "textures") +/** Indexes into jit_function[] array */ +#define RAST_WHOLE 0 +#define RAST_EDGE_TEST 1 + + typedef void (*lp_jit_frag_func)(const struct lp_jit_context *context, uint32_t x, diff --git a/src/gallium/drivers/llvmpipe/lp_rast.c b/src/gallium/drivers/llvmpipe/lp_rast.c index 81ea11a16b6..30b43cce19b 100644 --- a/src/gallium/drivers/llvmpipe/lp_rast.c +++ b/src/gallium/drivers/llvmpipe/lp_rast.c @@ -312,15 +312,15 @@ lp_rast_shade_tile(struct lp_rasterizer_task *task, depth = lp_rast_depth_pointer(rast, tile_x + x, tile_y + y); /* run shader */ - state->jit_function[0]( &state->jit_context, - tile_x + x, tile_y + y, - inputs->a0, - inputs->dadx, - inputs->dady, - color, - depth, - INT_MIN, INT_MIN, INT_MIN, - NULL, NULL, NULL ); + state->jit_function[RAST_WHOLE]( &state->jit_context, + tile_x + x, tile_y + y, + inputs->a0, + inputs->dadx, + inputs->dady, + color, + depth, + INT_MIN, INT_MIN, INT_MIN, + NULL, NULL, NULL ); } } } @@ -375,15 +375,17 @@ void lp_rast_shade_quads( struct lp_rasterizer_task *task, assert(lp_check_alignment(inputs->step[2], 16)); /* run shader */ - state->jit_function[1]( &state->jit_context, - x, y, - inputs->a0, - inputs->dadx, - inputs->dady, - color, - depth, - c1, c2, c3, - inputs->step[0], inputs->step[1], inputs->step[2]); + state->jit_function[RAST_EDGE_TEST]( &state->jit_context, + x, y, + inputs->a0, + inputs->dadx, + inputs->dady, + color, + depth, + c1, c2, c3, + inputs->step[0], + inputs->step[1], + inputs->step[2]); } diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs.c b/src/gallium/drivers/llvmpipe/lp_state_fs.c index 0f96654a673..5f70d52b6cc 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_fs.c +++ b/src/gallium/drivers/llvmpipe/lp_state_fs.c @@ -1178,7 +1178,7 @@ llvmpipe_update_fs(struct llvmpipe_context *lp) ? TRUE : FALSE; lp_setup_set_fs_functions(lp->setup, - shader->current->jit_function[0], - shader->current->jit_function[1], + shader->current->jit_function[RAST_WHOLE], + shader->current->jit_function[RAST_EDGE_TEST], opaque); } -- cgit v1.2.3 From 22e6dc387039e79f6d1435ae8b7422a6514d5d10 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Thu, 18 Mar 2010 13:02:53 -0600 Subject: gallivm/llvmpipe: added lp_rast_shader_inputs::facing and pass through The triangle rasterizer sets this field to indicate front/back-facing. It gets passed into the generated fragment code as another parameter. Used now for stencil front/back selection but will also be used for fragment shaders in general (see TGSI_SEMANTIC_FACE). With this commit two-sided stenciling mostly works but there's still a bug or two... --- src/gallium/auxiliary/gallivm/lp_bld_depth.c | 22 ++++++---- src/gallium/auxiliary/gallivm/lp_bld_depth.h | 3 +- src/gallium/drivers/llvmpipe/lp_jit.h | 1 + src/gallium/drivers/llvmpipe/lp_rast.c | 2 + src/gallium/drivers/llvmpipe/lp_rast.h | 2 + src/gallium/drivers/llvmpipe/lp_rast_priv.h | 1 + src/gallium/drivers/llvmpipe/lp_setup_tri.c | 2 + src/gallium/drivers/llvmpipe/lp_state_fs.c | 61 ++++++++++++++++------------ 8 files changed, 57 insertions(+), 37 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/auxiliary/gallivm/lp_bld_depth.c b/src/gallium/auxiliary/gallivm/lp_bld_depth.c index c253764e603..e1558dca0e7 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_depth.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_depth.c @@ -143,7 +143,7 @@ lp_build_stencil_test(struct lp_build_context *bld, struct lp_build_if_state if_ctx; LLVMValueRef front_facing; LLVMValueRef zero = LLVMConstReal(LLVMFloatType(), 0.0); - LLVMValueRef result = NULL; + LLVMValueRef result = bld->undef; flow_ctx = lp_build_flow_create(bld->builder); lp_build_flow_scope_begin(flow_ctx); @@ -151,7 +151,7 @@ lp_build_stencil_test(struct lp_build_context *bld, lp_build_flow_scope_declare(flow_ctx, &result); /* front_facing = face > 0.0 */ - front_facing = lp_build_cmp(bld, PIPE_FUNC_GREATER, face, zero); + front_facing = LLVMBuildFCmp(bld->builder, LLVMRealUGT, face, zero, ""); lp_build_if(&if_ctx, flow_ctx, bld->builder, front_facing); { @@ -287,7 +287,7 @@ lp_build_stencil_op(struct lp_build_context *bld, struct lp_build_if_state if_ctx; LLVMValueRef front_facing; LLVMValueRef zero = LLVMConstReal(LLVMFloatType(), 0.0); - LLVMValueRef result = NULL; + LLVMValueRef result = bld->undef; flow_ctx = lp_build_flow_create(bld->builder); lp_build_flow_scope_begin(flow_ctx); @@ -295,7 +295,7 @@ lp_build_stencil_op(struct lp_build_context *bld, lp_build_flow_scope_declare(flow_ctx, &result); /* front_facing = face > 0.0 */ - front_facing = lp_build_cmp(bld, PIPE_FUNC_GREATER, face, zero); + front_facing = LLVMBuildFCmp(bld->builder, LLVMRealUGT, face, zero, ""); lp_build_if(&if_ctx, flow_ctx, bld->builder, front_facing); { @@ -367,11 +367,15 @@ lp_depth_type(const struct util_format_description *format_desc, * Generate code for performing depth and/or stencil tests. * We operate on a vector of values (typically a 2x2 quad). * + * \param depth the depth test state + * \param stencil the front/back stencil state * \param type the data type of the fragment depth/stencil values * \param format_desc description of the depth/stencil surface - * \param mask the alive/dead pixel mask for the quad - * \param src the incoming depth/stencil values (a 2x2 quad) - * \param dst_ptr the outgoing/updated depth/stencil values + * \param mask the alive/dead pixel mask for the quad (vector) + * \param stencil_refs the front/back stencil ref values (scalar) + * \param z_src the incoming depth/stencil values (a 2x2 quad) + * \param zs_dst_ptr pointer to depth/stencil values in framebuffer + * \param facing contains float value indicating front/back facing polygon */ void lp_build_depth_stencil_test(LLVMBuilderRef builder, @@ -382,7 +386,8 @@ lp_build_depth_stencil_test(LLVMBuilderRef builder, struct lp_build_mask_context *mask, LLVMValueRef stencil_refs[2], LLVMValueRef z_src, - LLVMValueRef zs_dst_ptr) + LLVMValueRef zs_dst_ptr, + LLVMValueRef face) { struct lp_build_context bld; unsigned z_swizzle, s_swizzle; @@ -391,7 +396,6 @@ lp_build_depth_stencil_test(LLVMBuilderRef builder, LLVMValueRef z_bitmask = NULL, s_bitmask = NULL; LLVMValueRef z_pass = NULL, s_pass_mask = NULL; LLVMValueRef orig_mask = mask->value; - LLVMValueRef face = NULL; assert(depth->enabled || stencil[0].enabled); diff --git a/src/gallium/auxiliary/gallivm/lp_bld_depth.h b/src/gallium/auxiliary/gallivm/lp_bld_depth.h index 5708ced9839..27dd46b625d 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_depth.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_depth.h @@ -59,7 +59,8 @@ lp_build_depth_stencil_test(LLVMBuilderRef builder, struct lp_build_mask_context *mask, LLVMValueRef stencil_refs[2], LLVMValueRef zs_src, - LLVMValueRef zs_dst_ptr); + LLVMValueRef zs_dst_ptr, + LLVMValueRef facing); #endif /* !LP_BLD_DEPTH_H */ diff --git a/src/gallium/drivers/llvmpipe/lp_jit.h b/src/gallium/drivers/llvmpipe/lp_jit.h index 690b4393079..4930ff02e6b 100644 --- a/src/gallium/drivers/llvmpipe/lp_jit.h +++ b/src/gallium/drivers/llvmpipe/lp_jit.h @@ -155,6 +155,7 @@ typedef void (*lp_jit_frag_func)(const struct lp_jit_context *context, uint32_t x, uint32_t y, + float facing, const void *a0, const void *dadx, const void *dady, diff --git a/src/gallium/drivers/llvmpipe/lp_rast.c b/src/gallium/drivers/llvmpipe/lp_rast.c index 30b43cce19b..3a51800c40d 100644 --- a/src/gallium/drivers/llvmpipe/lp_rast.c +++ b/src/gallium/drivers/llvmpipe/lp_rast.c @@ -314,6 +314,7 @@ lp_rast_shade_tile(struct lp_rasterizer_task *task, /* run shader */ state->jit_function[RAST_WHOLE]( &state->jit_context, tile_x + x, tile_y + y, + inputs->facing, inputs->a0, inputs->dadx, inputs->dady, @@ -377,6 +378,7 @@ void lp_rast_shade_quads( struct lp_rasterizer_task *task, /* run shader */ state->jit_function[RAST_EDGE_TEST]( &state->jit_context, x, y, + inputs->facing, inputs->a0, inputs->dadx, inputs->dady, diff --git a/src/gallium/drivers/llvmpipe/lp_rast.h b/src/gallium/drivers/llvmpipe/lp_rast.h index 303f6e3f7e4..ae838f3fbef 100644 --- a/src/gallium/drivers/llvmpipe/lp_rast.h +++ b/src/gallium/drivers/llvmpipe/lp_rast.h @@ -82,6 +82,8 @@ struct lp_rast_state { * These pointers point into the bin data buffer. */ struct lp_rast_shader_inputs { + float facing; /** Positive for front-facing, negative for back-facing */ + float (*a0)[4]; float (*dadx)[4]; float (*dady)[4]; diff --git a/src/gallium/drivers/llvmpipe/lp_rast_priv.h b/src/gallium/drivers/llvmpipe/lp_rast_priv.h index 39bf2c25879..6ee9bcaae3a 100644 --- a/src/gallium/drivers/llvmpipe/lp_rast_priv.h +++ b/src/gallium/drivers/llvmpipe/lp_rast_priv.h @@ -195,6 +195,7 @@ lp_rast_shade_quads_all( struct lp_rasterizer_task *task, /* run shader */ state->jit_function[0]( &state->jit_context, x, y, + inputs->facing, inputs->a0, inputs->dadx, inputs->dady, diff --git a/src/gallium/drivers/llvmpipe/lp_setup_tri.c b/src/gallium/drivers/llvmpipe/lp_setup_tri.c index ac6264dc73e..ce689d3d568 100644 --- a/src/gallium/drivers/llvmpipe/lp_setup_tri.c +++ b/src/gallium/drivers/llvmpipe/lp_setup_tri.c @@ -361,6 +361,8 @@ do_triangle_ccw(struct lp_setup_context *setup, */ setup_tri_coefficients( setup, tri, oneoverarea, v1, v2, v3, frontfacing ); + tri->inputs.facing = frontfacing ? 1.0F : -1.0F; + /* half-edge constants, will be interated over the whole render target. */ tri->c1 = tri->dy12 * x1 - tri->dx12 * y1; diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs.c b/src/gallium/drivers/llvmpipe/lp_state_fs.c index 5f70d52b6cc..7bbf348e0b8 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_fs.c +++ b/src/gallium/drivers/llvmpipe/lp_state_fs.c @@ -147,7 +147,8 @@ generate_depth_stencil(LLVMBuilderRef builder, struct lp_build_mask_context *mask, LLVMValueRef stencil_refs[2], LLVMValueRef src, - LLVMValueRef dst_ptr) + LLVMValueRef dst_ptr, + LLVMValueRef facing) { const struct util_format_description *format_desc; struct lp_type dst_type; @@ -193,7 +194,8 @@ generate_depth_stencil(LLVMBuilderRef builder, mask, stencil_refs, src, - dst_ptr); + dst_ptr, + facing); } @@ -393,6 +395,7 @@ generate_fs(struct llvmpipe_context *lp, LLVMValueRef *pmask, LLVMValueRef (*color)[4], LLVMValueRef depth_ptr, + LLVMValueRef facing, unsigned do_tri_test, LLVMValueRef c0, LLVMValueRef c1, @@ -469,7 +472,7 @@ generate_fs(struct llvmpipe_context *lp, if (early_depth_stencil_test) generate_depth_stencil(builder, key, type, &mask, - stencil_refs, z, depth_ptr); + stencil_refs, z, depth_ptr, facing); lp_build_tgsi_soa(builder, tokens, type, &mask, consts_ptr, interp->pos, interp->inputs, @@ -516,7 +519,7 @@ generate_fs(struct llvmpipe_context *lp, if (!early_depth_stencil_test) generate_depth_stencil(builder, key, type, &mask, - stencil_refs, z, depth_ptr); + stencil_refs, z, depth_ptr, facing); lp_build_mask_end(&mask); @@ -627,7 +630,7 @@ generate_fragment(struct llvmpipe_context *lp, LLVMTypeRef fs_int_vec_type; LLVMTypeRef blend_vec_type; LLVMTypeRef blend_int_vec_type; - LLVMTypeRef arg_types[14]; + LLVMTypeRef arg_types[15]; LLVMTypeRef func_type; LLVMTypeRef int32_vec4_type = lp_build_int32_vec4_type(); LLVMValueRef context_ptr; @@ -650,6 +653,7 @@ generate_fragment(struct llvmpipe_context *lp, LLVMValueRef blend_mask; LLVMValueRef blend_in_color[NUM_CHANNELS]; LLVMValueRef function; + LLVMValueRef facing; unsigned num_fs; unsigned i; unsigned chan; @@ -689,20 +693,21 @@ generate_fragment(struct llvmpipe_context *lp, arg_types[0] = screen->context_ptr_type; /* context */ arg_types[1] = LLVMInt32Type(); /* x */ arg_types[2] = LLVMInt32Type(); /* y */ - arg_types[3] = LLVMPointerType(fs_elem_type, 0); /* a0 */ - arg_types[4] = LLVMPointerType(fs_elem_type, 0); /* dadx */ - arg_types[5] = LLVMPointerType(fs_elem_type, 0); /* dady */ - arg_types[6] = LLVMPointerType(LLVMPointerType(blend_vec_type, 0), 0); /* color */ - arg_types[7] = LLVMPointerType(fs_int_vec_type, 0); /* depth */ - arg_types[8] = LLVMInt32Type(); /* c0 */ - arg_types[9] = LLVMInt32Type(); /* c1 */ - arg_types[10] = LLVMInt32Type(); /* c2 */ + arg_types[3] = LLVMFloatType(); /* facing */ + arg_types[4] = LLVMPointerType(fs_elem_type, 0); /* a0 */ + arg_types[5] = LLVMPointerType(fs_elem_type, 0); /* dadx */ + arg_types[6] = LLVMPointerType(fs_elem_type, 0); /* dady */ + arg_types[7] = LLVMPointerType(LLVMPointerType(blend_vec_type, 0), 0); /* color */ + arg_types[8] = LLVMPointerType(fs_int_vec_type, 0); /* depth */ + arg_types[9] = LLVMInt32Type(); /* c0 */ + arg_types[10] = LLVMInt32Type(); /* c1 */ + arg_types[11] = LLVMInt32Type(); /* c2 */ /* Note: the step arrays are built as int32[16] but we interpret * them here as int32_vec4[4]. */ - arg_types[11] = LLVMPointerType(int32_vec4_type, 0);/* step0 */ - arg_types[12] = LLVMPointerType(int32_vec4_type, 0);/* step1 */ - arg_types[13] = LLVMPointerType(int32_vec4_type, 0);/* step2 */ + arg_types[12] = LLVMPointerType(int32_vec4_type, 0);/* step0 */ + arg_types[13] = LLVMPointerType(int32_vec4_type, 0);/* step1 */ + arg_types[14] = LLVMPointerType(int32_vec4_type, 0);/* step2 */ func_type = LLVMFunctionType(LLVMVoidType(), arg_types, Elements(arg_types), 0); @@ -722,17 +727,18 @@ generate_fragment(struct llvmpipe_context *lp, context_ptr = LLVMGetParam(function, 0); x = LLVMGetParam(function, 1); y = LLVMGetParam(function, 2); - a0_ptr = LLVMGetParam(function, 3); - dadx_ptr = LLVMGetParam(function, 4); - dady_ptr = LLVMGetParam(function, 5); - color_ptr_ptr = LLVMGetParam(function, 6); - depth_ptr = LLVMGetParam(function, 7); - c0 = LLVMGetParam(function, 8); - c1 = LLVMGetParam(function, 9); - c2 = LLVMGetParam(function, 10); - step0_ptr = LLVMGetParam(function, 11); - step1_ptr = LLVMGetParam(function, 12); - step2_ptr = LLVMGetParam(function, 13); + facing = LLVMGetParam(function, 3); + a0_ptr = LLVMGetParam(function, 4); + dadx_ptr = LLVMGetParam(function, 5); + dady_ptr = LLVMGetParam(function, 6); + color_ptr_ptr = LLVMGetParam(function, 7); + depth_ptr = LLVMGetParam(function, 8); + c0 = LLVMGetParam(function, 9); + c1 = LLVMGetParam(function, 10); + c2 = LLVMGetParam(function, 11); + step0_ptr = LLVMGetParam(function, 12); + step1_ptr = LLVMGetParam(function, 13); + step2_ptr = LLVMGetParam(function, 14); lp_build_name(context_ptr, "context"); lp_build_name(x, "x"); @@ -791,6 +797,7 @@ generate_fragment(struct llvmpipe_context *lp, &fs_mask[i], /* output */ out_color, depth_ptr_i, + facing, do_tri_test, c0, c1, c2, step0_ptr, step1_ptr, step2_ptr); -- cgit v1.2.3 From 66b6676d141463b8229e62be6249efd1cb6873a8 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Thu, 18 Mar 2010 15:02:13 -0600 Subject: gallivm: fix broken INCR/DECR stencil modes We were mistakenly using the wrong data type for stencil values before. --- src/gallium/auxiliary/gallivm/lp_bld_depth.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/auxiliary/gallivm/lp_bld_depth.c b/src/gallium/auxiliary/gallivm/lp_bld_depth.c index e1558dca0e7..0841aa8ef86 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_depth.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_depth.c @@ -104,6 +104,8 @@ lp_build_stencil_test_single(struct lp_build_context *bld, struct lp_type type = bld->type; LLVMValueRef res; + assert(type.sign); + assert(stencil->enabled); if (stencil->valuemask != stencilMax) { @@ -200,6 +202,8 @@ lp_build_stencil_op_single(struct lp_build_context *bld, LLVMValueRef max = lp_build_const_int_vec(type, stencilMax); unsigned stencil_op; + assert(type.sign); + switch (op) { case S_FAIL_OP: stencil_op = stencil->fail_op; @@ -244,6 +248,7 @@ lp_build_stencil_op_single(struct lp_build_context *bld, break; case PIPE_STENCIL_OP_INVERT: res = LLVMBuildNot(bld->builder, stencilVals, ""); + res = LLVMBuildAnd(bld->builder, res, max, ""); break; default: assert(0 && "bad stencil op mode"); @@ -390,6 +395,8 @@ lp_build_depth_stencil_test(LLVMBuilderRef builder, LLVMValueRef face) { struct lp_build_context bld; + struct lp_build_context sbld; + struct lp_type s_type; unsigned z_swizzle, s_swizzle; LLVMValueRef zs_dst, z_dst = NULL; LLVMValueRef stencil_vals = NULL; @@ -425,9 +432,13 @@ lp_build_depth_stencil_test(LLVMBuilderRef builder, assert(type.norm); } - /* Setup build context */ + /* Setup build context for Z vals */ lp_build_context_init(&bld, builder, type); + /* Setup build context for stencil vals */ + s_type = lp_type_int_vec(type.width); + lp_build_context_init(&sbld, builder, s_type); + /* Load current z/stencil value from z/stencil buffer */ zs_dst = LLVMBuildLoad(builder, zs_dst_ptr, ""); @@ -491,13 +502,13 @@ lp_build_depth_stencil_test(LLVMBuilderRef builder, stencil_refs[1] = lp_build_broadcast_scalar(&bld, stencil_refs[1]); - s_pass_mask = lp_build_stencil_test(&bld, stencil, + s_pass_mask = lp_build_stencil_test(&sbld, stencil, stencil_refs, stencil_vals, face); /* apply stencil-fail operator */ { LLVMValueRef s_fail_mask = lp_build_andc(&bld, orig_mask, s_pass_mask); - stencil_vals = lp_build_stencil_op(&bld, stencil, S_FAIL_OP, + stencil_vals = lp_build_stencil_op(&sbld, stencil, S_FAIL_OP, stencil_refs, stencil_vals, s_fail_mask, face); } @@ -530,13 +541,13 @@ lp_build_depth_stencil_test(LLVMBuilderRef builder, /* apply Z-fail operator */ z_fail_mask = lp_build_andc(&bld, orig_mask, z_pass); - stencil_vals = lp_build_stencil_op(&bld, stencil, Z_FAIL_OP, + stencil_vals = lp_build_stencil_op(&sbld, stencil, Z_FAIL_OP, stencil_refs, stencil_vals, z_fail_mask, face); /* apply Z-pass operator */ z_pass_mask = LLVMBuildAnd(bld.builder, orig_mask, z_pass, ""); - stencil_vals = lp_build_stencil_op(&bld, stencil, Z_PASS_OP, + stencil_vals = lp_build_stencil_op(&sbld, stencil, Z_PASS_OP, stencil_refs, stencil_vals, z_pass_mask, face); } @@ -546,7 +557,7 @@ lp_build_depth_stencil_test(LLVMBuilderRef builder, * passed the stencil test. */ s_pass_mask = LLVMBuildAnd(bld.builder, orig_mask, s_pass_mask, ""); - stencil_vals = lp_build_stencil_op(&bld, stencil, Z_PASS_OP, stencil_refs, + stencil_vals = lp_build_stencil_op(&sbld, stencil, Z_PASS_OP, stencil_refs, stencil_vals, s_pass_mask, face); } -- cgit v1.2.3 From 8df65e98998b4c104db30cbba8a38be7eb2a9acd Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Thu, 18 Mar 2010 17:27:39 -0600 Subject: gallivm: support PIPE_FORMAT_Z24S8_UNORM in depth/stencil code --- src/gallium/auxiliary/gallivm/lp_bld_depth.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/auxiliary/gallivm/lp_bld_depth.c b/src/gallium/auxiliary/gallivm/lp_bld_depth.c index 0841aa8ef86..5b5ae7b5ea8 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_depth.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_depth.c @@ -400,7 +400,7 @@ lp_build_depth_stencil_test(LLVMBuilderRef builder, unsigned z_swizzle, s_swizzle; LLVMValueRef zs_dst, z_dst = NULL; LLVMValueRef stencil_vals = NULL; - LLVMValueRef z_bitmask = NULL, s_bitmask = NULL; + LLVMValueRef z_bitmask = NULL, s_bitmask = NULL, s_shift = NULL; LLVMValueRef z_pass = NULL, s_pass_mask = NULL; LLVMValueRef orig_mask = mask->value; @@ -416,6 +416,11 @@ lp_build_depth_stencil_test(LLVMBuilderRef builder, assert(z_swizzle != UTIL_FORMAT_SWIZZLE_NONE || s_swizzle != UTIL_FORMAT_SWIZZLE_NONE); + if (stencil[0].enabled) { + assert(format_desc->format == PIPE_FORMAT_Z24S8_UNORM || + format_desc->format == PIPE_FORMAT_S8Z24_UNORM); + } + /* Sanity checking */ assert(z_swizzle < 4); assert(format_desc->block.bits == type.width); @@ -473,9 +478,16 @@ lp_build_depth_stencil_test(LLVMBuilderRef builder, z_bitmask = lp_build_const_int_vec(type, mask_left ^ mask_right); } - s_bitmask = LLVMBuildNot(builder, z_bitmask, ""); + /* If PIPE_FORMAT_Z24S8, we'll shift zs >> 24 to position stencil_vals */ + if (format_desc->format == PIPE_FORMAT_Z24S8_UNORM) + s_shift = lp_build_const_int_vec(type, 24); + else + s_shift = lp_build_const_int_vec(type, 0); + + s_bitmask = lp_build_const_int_vec(s_type, 0xff); - stencil_vals = LLVMBuildAnd(builder, zs_dst, s_bitmask, ""); + stencil_vals = LLVMBuildLShr(builder, zs_dst, s_shift, ""); + stencil_vals = LLVMBuildAnd(builder, stencil_vals, s_bitmask, ""); if(padding_left) z_src = LLVMBuildLShr(builder, z_src, @@ -561,6 +573,9 @@ lp_build_depth_stencil_test(LLVMBuilderRef builder, stencil_vals, s_pass_mask, face); } + if (stencil_vals) + stencil_vals = LLVMBuildShl(bld.builder, stencil_vals, s_shift, ""); + /* Finally, merge/store the z/stencil values */ if ((depth->enabled && depth->writemask) || (stencil[0].enabled && stencil[0].writemask)) { -- cgit v1.2.3 From cba6430524198a1bdcdeada03cbe946a454f3935 Mon Sep 17 00:00:00 2001 From: Marek Olšák Date: Thu, 24 Dec 2009 21:29:41 +0100 Subject: r300g: add generating texture coordinates for point sprites (WIP) --- src/gallium/drivers/r300/r300_context.c | 2 ++ src/gallium/drivers/r300/r300_context.h | 13 +++++++++ src/gallium/drivers/r300/r300_emit.c | 6 +++++ src/gallium/drivers/r300/r300_state.c | 35 ++++++++++++++++++++++++- src/gallium/drivers/r300/r300_state_derived.c | 5 +++- src/gallium/drivers/r300/r300_state_invariant.c | 13 ++------- 6 files changed, 61 insertions(+), 13 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/r300/r300_context.c b/src/gallium/drivers/r300/r300_context.c index d994a46ccfe..210e31e69c7 100644 --- a/src/gallium/drivers/r300/r300_context.c +++ b/src/gallium/drivers/r300/r300_context.c @@ -202,6 +202,8 @@ struct pipe_context* r300_create_context(struct pipe_screen* screen, r300_setup_atoms(r300); + r300->sprite_coord_index = -1; + /* Open up the OQ BO. */ r300->oqbo = screen->buffer_create(screen, 4096, PIPE_BUFFER_USAGE_VERTEX, 4096); diff --git a/src/gallium/drivers/r300/r300_context.h b/src/gallium/drivers/r300/r300_context.h index 0c8fb6860eb..edebeab86fd 100644 --- a/src/gallium/drivers/r300/r300_context.h +++ b/src/gallium/drivers/r300/r300_context.h @@ -98,6 +98,16 @@ struct r300_rs_state { uint32_t line_stipple_value; /* R300_GA_LINE_STIPPLE_VALUE: 0x4260 */ uint32_t color_control; /* R300_GA_COLOR_CONTROL: 0x4278 */ uint32_t polygon_mode; /* R300_GA_POLY_MODE: 0x4288 */ + + /* Specifies top of Raster pipe specific enable controls, + * i.e. texture coordinates stuffing for points, lines, triangles */ + uint32_t stuffing_enable; /* R300_GB_ENABLE: 0x4008 */ + + /* Point sprites texture coordinates, 0: lower left, 1: upper right */ + float point_texcoord_left; /* R300_GA_POINT_S0: 0x4200 */ + float point_texcoord_bottom; /* R300_GA_POINT_T0: 0x4204 */ + float point_texcoord_right; /* R300_GA_POINT_S1: 0x4208 */ + float point_texcoord_top; /* R300_GA_POINT_T1: 0x420c */ }; struct r300_rs_block { @@ -390,6 +400,9 @@ struct r300_context { uint32_t zbuffer_bpp; /* Whether scissor is enabled. */ boolean scissor_enabled; + /* Point sprites texcoord index, -1 = unused. */ + int sprite_coord_index; + /* upload managers */ struct u_upload_mgr *upload_vb; struct u_upload_mgr *upload_ib; diff --git a/src/gallium/drivers/r300/r300_emit.c b/src/gallium/drivers/r300/r300_emit.c index 3ad0e561bc1..5522fb306db 100644 --- a/src/gallium/drivers/r300/r300_emit.c +++ b/src/gallium/drivers/r300/r300_emit.c @@ -616,6 +616,12 @@ void r300_emit_rs_state(struct r300_context* r300, unsigned size, void* state) OUT_CS_REG(R300_GA_LINE_STIPPLE_CONFIG, rs->line_stipple_config); OUT_CS_REG(R300_GA_LINE_STIPPLE_VALUE, rs->line_stipple_value); OUT_CS_REG(R300_GA_POLY_MODE, rs->polygon_mode); + OUT_CS_REG(R300_GB_ENABLE, rs->stuffing_enable); + OUT_CS_REG_SEQ(R300_GA_POINT_S0, 4); + OUT_CS_32F(rs->point_texcoord_left); + OUT_CS_32F(rs->point_texcoord_bottom); + OUT_CS_32F(rs->point_texcoord_right); + OUT_CS_32F(rs->point_texcoord_top); END_CS; } diff --git a/src/gallium/drivers/r300/r300_state.c b/src/gallium/drivers/r300/r300_state.c index d7d654dc315..db7844eef0e 100644 --- a/src/gallium/drivers/r300/r300_state.c +++ b/src/gallium/drivers/r300/r300_state.c @@ -715,6 +715,7 @@ static void* r300_create_rs_state(struct pipe_context* pipe, { struct r300_screen* r300screen = r300_screen(pipe->screen); struct r300_rs_state* rs = CALLOC_STRUCT(r300_rs_state); + unsigned coord_index; /* Copy rasterizer state for Draw. */ rs->rs = *state; @@ -807,6 +808,32 @@ static void* r300_create_rs_state(struct pipe_context* pipe, rs->color_control = R300_SHADE_MODEL_SMOOTH; } + /* Point sprites */ + if (state->sprite_coord_enable) { + coord_index = ffs(state->sprite_coord_enable)-1; + + SCREEN_DBG(r300screen, DBG_DRAW, + "r300: point sprite: shader coord=%d\n", coord_index); + + rs->stuffing_enable = + R300_GB_POINT_STUFF_ENABLE | + R300_GB_TEX_ST << (R300_GB_TEX0_SOURCE_SHIFT + (coord_index*2)); + + rs->point_texcoord_left = 0.0f; + rs->point_texcoord_right = 1.0f; + + switch (state->sprite_coord_mode) { + case PIPE_SPRITE_COORD_UPPER_LEFT: + rs->point_texcoord_top = 0.0f; + rs->point_texcoord_bottom = 1.0f; + break; + case PIPE_SPRITE_COORD_LOWER_LEFT: + rs->point_texcoord_top = 1.0f; + rs->point_texcoord_bottom = 0.0f; + break; + } + } + return (void*)rs; } @@ -816,6 +843,7 @@ static void r300_bind_rs_state(struct pipe_context* pipe, void* state) struct r300_context* r300 = r300_context(pipe); struct r300_rs_state* rs = (struct r300_rs_state*)state; boolean scissor_was_enabled = r300->scissor_enabled; + int last_sprite_coord_index = r300->sprite_coord_index; if (r300->draw) { draw_flush(r300->draw); @@ -825,17 +853,22 @@ static void r300_bind_rs_state(struct pipe_context* pipe, void* state) if (rs) { r300->polygon_offset_enabled = rs->rs.offset_cw || rs->rs.offset_ccw; r300->scissor_enabled = rs->rs.scissor; + r300->sprite_coord_index = ffs(rs->rs.sprite_coord_enable)-1; } else { r300->polygon_offset_enabled = FALSE; r300->scissor_enabled = FALSE; + r300->sprite_coord_index = -1; } UPDATE_STATE(state, r300->rs_state); - r300->rs_state.size = 17 + (r300->polygon_offset_enabled ? 5 : 0); + r300->rs_state.size = 24 + (r300->polygon_offset_enabled ? 5 : 0); if (scissor_was_enabled != r300->scissor_enabled) { r300->scissor_state.dirty = TRUE; } + if (last_sprite_coord_index != r300->sprite_coord_index) { + r300->rs_block_state.dirty = TRUE; + } } /* Free rasterizer state. */ diff --git a/src/gallium/drivers/r300/r300_state_derived.c b/src/gallium/drivers/r300/r300_state_derived.c index 7947ec6641d..74663bda514 100644 --- a/src/gallium/drivers/r300/r300_state_derived.c +++ b/src/gallium/drivers/r300/r300_state_derived.c @@ -178,7 +178,8 @@ static void r300_update_rs_block(struct r300_context* r300, /* Rasterize texture coordinates. */ for (i = 0; i < ATTR_GENERIC_COUNT; i++) { - if (vs_outputs->generic[i] != ATTR_UNUSED) { + if (vs_outputs->generic[i] != ATTR_UNUSED || + r300->sprite_coord_index == i) { /* Always rasterize if it's written by the VS, * otherwise it locks up. */ rX00_rs_tex(&rs, tex_count, tex_count, FALSE); @@ -186,6 +187,8 @@ static void r300_update_rs_block(struct r300_context* r300, /* Write it to the FS input register if it's used by the FS. */ if (fs_inputs->generic[i] != ATTR_UNUSED) { rX00_rs_tex_write(&rs, tex_count, fp_offset); + if (r300->sprite_coord_index == i) + debug_printf("r300: SpriteCoord (generic index %i) is being written to reg %i\n", i, fp_offset); fp_offset++; } tex_count++; diff --git a/src/gallium/drivers/r300/r300_state_invariant.c b/src/gallium/drivers/r300/r300_state_invariant.c index 4a2c68269b1..2d9a63d29a4 100644 --- a/src/gallium/drivers/r300/r300_state_invariant.c +++ b/src/gallium/drivers/r300/r300_state_invariant.c @@ -44,13 +44,9 @@ void r300_emit_invariant_state(struct r300_context* r300, struct r300_capabilities* caps = r300_screen(r300->context.screen)->caps; CS_LOCALS(r300); - BEGIN_CS(14 + (caps->has_tcl ? 2: 0)); + BEGIN_CS(12 + (caps->has_tcl ? 2: 0)); /*** Graphics Backend (GB) ***/ - /* Various GB enables */ - OUT_CS_REG(R300_GB_ENABLE, R300_GB_POINT_STUFF_ENABLE | - R300_GB_LINE_STUFF_ENABLE | - R300_GB_TRIANGLE_STUFF_ENABLE); /* Subpixel multisampling for AA * These are commented out because glisse's CS checker doesn't like them. * I presume these will be re-enabled later. @@ -78,7 +74,7 @@ void r300_emit_invariant_state(struct r300_context* r300, END_CS; /* XXX unsorted stuff from surface_fill */ - BEGIN_CS(44 + (caps->has_tcl ? 7 : 0) + + BEGIN_CS(40 + (caps->has_tcl ? 7 : 0) + (caps->family >= CHIP_FAMILY_RV350 ? 4 : 0)); if (caps->has_tcl) { @@ -90,11 +86,6 @@ void r300_emit_invariant_state(struct r300_context* r300, OUT_CS_32F(1.0); OUT_CS_32F(1.0); } - /* XXX point tex stuffing */ - OUT_CS_REG_SEQ(R300_GA_POINT_S0, 1); - OUT_CS_32F(0.0); - OUT_CS_REG_SEQ(R300_GA_POINT_S1, 1); - OUT_CS_32F(1.0); /* XXX line tex stuffing */ OUT_CS_REG_SEQ(R300_GA_LINE_S0, 1); OUT_CS_32F(0.0); -- cgit v1.2.3 From 0c81739528fd8f240176bb120c90c712f9606718 Mon Sep 17 00:00:00 2001 From: Marek Olšák Date: Thu, 18 Mar 2010 20:58:04 +0100 Subject: r300g: mark SRGB colorbuffers as unsupported I can't find the register bits for SRGB-aware blending and it's not even exposed by fglrx so it's most probably not supported by hw. --- src/gallium/drivers/r300/r300_texture.c | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/r300/r300_texture.c b/src/gallium/drivers/r300/r300_texture.c index 7c7656068bb..09067aab3bf 100644 --- a/src/gallium/drivers/r300/r300_texture.c +++ b/src/gallium/drivers/r300/r300_texture.c @@ -302,7 +302,6 @@ static uint32_t r300_translate_colorformat(enum pipe_format format) case PIPE_FORMAT_A8_UNORM: case PIPE_FORMAT_I8_UNORM: case PIPE_FORMAT_L8_UNORM: - case PIPE_FORMAT_L8_SRGB: case PIPE_FORMAT_R8_UNORM: case PIPE_FORMAT_R8_SNORM: return R300_COLOR_FORMAT_I8; @@ -317,18 +316,12 @@ static uint32_t r300_translate_colorformat(enum pipe_format format) /* 32-bit buffers. */ case PIPE_FORMAT_B8G8R8A8_UNORM: - case PIPE_FORMAT_B8G8R8A8_SRGB: case PIPE_FORMAT_B8G8R8X8_UNORM: - case PIPE_FORMAT_B8G8R8X8_SRGB: case PIPE_FORMAT_A8R8G8B8_UNORM: - case PIPE_FORMAT_A8R8G8B8_SRGB: case PIPE_FORMAT_X8R8G8B8_UNORM: - case PIPE_FORMAT_X8R8G8B8_SRGB: case PIPE_FORMAT_A8B8G8R8_UNORM: case PIPE_FORMAT_R8G8B8A8_SNORM: - case PIPE_FORMAT_A8B8G8R8_SRGB: case PIPE_FORMAT_X8B8G8R8_UNORM: - case PIPE_FORMAT_X8B8G8R8_SRGB: case PIPE_FORMAT_R8SG8SB8UX8U_NORM: return R300_COLOR_FORMAT_ARGB8888; case PIPE_FORMAT_R10G10B10A2_UNORM: @@ -393,12 +386,7 @@ static uint32_t r300_translate_out_fmt(enum pipe_format format) desc = util_format_description(format); /* Specifies how the shader output is written to the fog unit. */ - if (desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB) { - /* The gamma correction causes precision loss so we need - * higher precision to maintain reasonable quality. - * It has nothing to do with the colorbuffer format. */ - modifier |= R300_US_OUT_FMT_C4_10_GAMMA; - } else if (desc->channel[0].type == UTIL_FORMAT_TYPE_FLOAT) { + if (desc->channel[0].type == UTIL_FORMAT_TYPE_FLOAT) { if (desc->channel[0].size == 32) { modifier |= R300_US_OUT_FMT_C4_32_FP; } else { @@ -428,7 +416,6 @@ static uint32_t r300_translate_out_fmt(enum pipe_format format) return modifier | R300_C2_SEL_A; case PIPE_FORMAT_I8_UNORM: case PIPE_FORMAT_L8_UNORM: - case PIPE_FORMAT_L8_SRGB: case PIPE_FORMAT_R8_UNORM: case PIPE_FORMAT_R8_SNORM: return modifier | R300_C2_SEL_R; @@ -438,18 +425,14 @@ static uint32_t r300_translate_out_fmt(enum pipe_format format) case PIPE_FORMAT_B5G5R5A1_UNORM: case PIPE_FORMAT_B4G4R4A4_UNORM: case PIPE_FORMAT_B8G8R8A8_UNORM: - case PIPE_FORMAT_B8G8R8A8_SRGB: case PIPE_FORMAT_B8G8R8X8_UNORM: - case PIPE_FORMAT_B8G8R8X8_SRGB: return modifier | R300_C0_SEL_B | R300_C1_SEL_G | R300_C2_SEL_R | R300_C3_SEL_A; /* BGRA 32-bit outputs. */ case PIPE_FORMAT_A8R8G8B8_UNORM: - case PIPE_FORMAT_A8R8G8B8_SRGB: case PIPE_FORMAT_X8R8G8B8_UNORM: - case PIPE_FORMAT_X8R8G8B8_SRGB: return modifier | R300_C0_SEL_A | R300_C1_SEL_R | R300_C2_SEL_G | R300_C3_SEL_B; @@ -457,9 +440,7 @@ static uint32_t r300_translate_out_fmt(enum pipe_format format) /* RGBA 32-bit outputs. */ case PIPE_FORMAT_A8B8G8R8_UNORM: case PIPE_FORMAT_R8G8B8A8_SNORM: - case PIPE_FORMAT_A8B8G8R8_SRGB: case PIPE_FORMAT_X8B8G8R8_UNORM: - case PIPE_FORMAT_X8B8G8R8_SRGB: return modifier | R300_C0_SEL_A | R300_C1_SEL_B | R300_C2_SEL_G | R300_C3_SEL_R; -- cgit v1.2.3 From f6e987ce7839d66edb88403d2c9ac1b28db2832b Mon Sep 17 00:00:00 2001 From: Marek Olšák Date: Thu, 18 Mar 2010 21:18:36 +0100 Subject: r300g: add PIPE_FORMAT_B5G5R5X1_UNORM colorbuffer support, cleanups --- src/gallium/drivers/r300/r300_texture.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/r300/r300_texture.c b/src/gallium/drivers/r300/r300_texture.c index 09067aab3bf..cb53619fe5e 100644 --- a/src/gallium/drivers/r300/r300_texture.c +++ b/src/gallium/drivers/r300/r300_texture.c @@ -310,6 +310,7 @@ static uint32_t r300_translate_colorformat(enum pipe_format format) case PIPE_FORMAT_B5G6R5_UNORM: return R300_COLOR_FORMAT_RGB565; case PIPE_FORMAT_B5G5R5A1_UNORM: + case PIPE_FORMAT_B5G5R5X1_UNORM: return R300_COLOR_FORMAT_ARGB1555; case PIPE_FORMAT_B4G4R4A4_UNORM: return R300_COLOR_FORMAT_ARGB4444; @@ -420,9 +421,10 @@ static uint32_t r300_translate_out_fmt(enum pipe_format format) case PIPE_FORMAT_R8_SNORM: return modifier | R300_C2_SEL_R; - /* ARGB 32-bit outputs. */ + /* BGRA outputs. */ case PIPE_FORMAT_B5G6R5_UNORM: case PIPE_FORMAT_B5G5R5A1_UNORM: + case PIPE_FORMAT_B5G5R5X1_UNORM: case PIPE_FORMAT_B4G4R4A4_UNORM: case PIPE_FORMAT_B8G8R8A8_UNORM: case PIPE_FORMAT_B8G8R8X8_UNORM: @@ -430,25 +432,24 @@ static uint32_t r300_translate_out_fmt(enum pipe_format format) R300_C0_SEL_B | R300_C1_SEL_G | R300_C2_SEL_R | R300_C3_SEL_A; - /* BGRA 32-bit outputs. */ + /* ARGB outputs. */ case PIPE_FORMAT_A8R8G8B8_UNORM: case PIPE_FORMAT_X8R8G8B8_UNORM: return modifier | R300_C0_SEL_A | R300_C1_SEL_R | R300_C2_SEL_G | R300_C3_SEL_B; - /* RGBA 32-bit outputs. */ + /* ABGR outputs. */ case PIPE_FORMAT_A8B8G8R8_UNORM: - case PIPE_FORMAT_R8G8B8A8_SNORM: case PIPE_FORMAT_X8B8G8R8_UNORM: return modifier | R300_C0_SEL_A | R300_C1_SEL_B | R300_C2_SEL_G | R300_C3_SEL_R; - /* ABGR 32-bit outputs. */ + /* RGBA outputs. */ + case PIPE_FORMAT_R8G8B8A8_SNORM: case PIPE_FORMAT_R8SG8SB8UX8U_NORM: case PIPE_FORMAT_R10G10B10A2_UNORM: - /* RGBA high precision outputs (same swizzles as ABGR low precision) */ case PIPE_FORMAT_R16G16B16A16_UNORM: case PIPE_FORMAT_R16G16B16A16_SNORM: //case PIPE_FORMAT_R16G16B16A16_FLOAT: /* not in pipe_format */ -- cgit v1.2.3 From afae0891949b72a2ede2a3b6a01d4d6bcf4ceae0 Mon Sep 17 00:00:00 2001 From: Marek Olšák Date: Fri, 19 Mar 2010 01:13:57 +0100 Subject: r300g: fix breakage after the gallium-sampler-view merge --- src/gallium/drivers/r300/r300_emit.c | 6 ++++-- src/gallium/drivers/r300/r300_state.c | 12 ++++++++---- src/gallium/drivers/r300/r300_state_derived.c | 13 ++++++++++--- 3 files changed, 22 insertions(+), 9 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/r300/r300_emit.c b/src/gallium/drivers/r300/r300_emit.c index 5522fb306db..c897df628d2 100644 --- a/src/gallium/drivers/r300/r300_emit.c +++ b/src/gallium/drivers/r300/r300_emit.c @@ -1050,9 +1050,11 @@ validate: } /* ...textures... */ for (i = 0; i < texstate->count; i++) { - tex = (struct r300_texture*)texstate->fragment_sampler_views[i]->texture; - if (!tex || !texstate->sampler_states[i]) + if (!(texstate->tx_enable & (1 << i))) { continue; + } + + tex = (struct r300_texture*)texstate->fragment_sampler_views[i]->texture; if (!r300_add_texture(r300->rws, tex, RADEON_GEM_DOMAIN_GTT | RADEON_GEM_DOMAIN_VRAM, 0)) { r300->context.flush(&r300->context, 0, NULL); diff --git a/src/gallium/drivers/r300/r300_state.c b/src/gallium/drivers/r300/r300_state.c index db7844eef0e..bdfe74ed2a0 100644 --- a/src/gallium/drivers/r300/r300_state.c +++ b/src/gallium/drivers/r300/r300_state.c @@ -973,6 +973,7 @@ static void r300_set_fragment_sampler_views(struct pipe_context* pipe, struct r300_context* r300 = r300_context(pipe); struct r300_textures_state* state = (struct r300_textures_state*)r300->textures_state.state; + struct r300_texture *texture; unsigned i; boolean is_r500 = r300_screen(r300->context.screen)->caps->is_r500; boolean dirty_tex = FALSE; @@ -984,15 +985,18 @@ static void r300_set_fragment_sampler_views(struct pipe_context* pipe, for (i = 0; i < count; i++) { if (state->fragment_sampler_views[i] != views[i]) { - struct r300_texture *texture; - pipe_sampler_view_reference(&state->fragment_sampler_views[i], views[i]); - dirty_tex = TRUE; - texture = (struct r300_texture *)views[i]->texture; + if (!views[i]) { + continue; + } + + /* A new sampler view (= texture)... */ + dirty_tex = TRUE; /* R300-specific - set the texrect factor in the fragment shader */ + texture = (struct r300_texture *)views[i]->texture; if (!is_r500 && texture->is_npot) { /* XXX It would be nice to re-emit just 1 constant, * XXX not all of them */ diff --git a/src/gallium/drivers/r300/r300_state_derived.c b/src/gallium/drivers/r300/r300_state_derived.c index 74663bda514..85947353ee9 100644 --- a/src/gallium/drivers/r300/r300_state_derived.c +++ b/src/gallium/drivers/r300/r300_state_derived.c @@ -335,20 +335,25 @@ static void r300_merge_textures_and_samplers(struct r300_context* r300) (struct r300_textures_state*)r300->textures_state.state; struct r300_texture_sampler_state *texstate; struct r300_sampler_state *sampler; + struct pipe_sampler_view *view; struct r300_texture *tex; unsigned min_level, max_level, i, size; unsigned count = MIN2(state->texture_count, state->sampler_count); state->tx_enable = 0; + state->count = 0; size = 2; for (i = 0; i < count; i++) { if (state->fragment_sampler_views[i] && state->sampler_states[i]) { state->tx_enable |= 1 << i; - tex = (struct r300_texture *)state->fragment_sampler_views[i]->texture; + view = state->fragment_sampler_views[i]; + tex = (struct r300_texture *)view->texture; sampler = state->sampler_states[i]; + assert(view->format == tex->tex.format); + texstate = &state->regs[i]; memcpy(texstate->format, &tex->state, sizeof(uint32_t)*3); texstate->filter[0] = sampler->filter0; @@ -370,8 +375,10 @@ static void r300_merge_textures_and_samplers(struct r300_context* r300) } else { /* determine min/max levels */ /* the MAX_MIP level is the largest (finest) one */ - max_level = MIN2(sampler->max_lod, tex->tex.last_level); - min_level = MIN2(sampler->min_lod, max_level); + max_level = MIN3(sampler->max_lod, tex->tex.last_level, + view->last_level); + min_level = MIN2(MAX2(sampler->min_lod, view->first_level), + max_level); texstate->format[0] |= R300_TX_NUM_LEVELS(max_level); texstate->filter[0] |= R300_TX_MAX_MIP_LEVEL(min_level); } -- cgit v1.2.3 From 12a40dda394bd14e31c679551bc5abc8b601fdbf Mon Sep 17 00:00:00 2001 From: Marek Olšák Date: Fri, 19 Mar 2010 04:46:15 +0100 Subject: r300g: lod min/max clamping should be relative to the base level --- src/gallium/drivers/r300/r300_state_derived.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/r300/r300_state_derived.c b/src/gallium/drivers/r300/r300_state_derived.c index 85947353ee9..8178d55dc9a 100644 --- a/src/gallium/drivers/r300/r300_state_derived.c +++ b/src/gallium/drivers/r300/r300_state_derived.c @@ -375,9 +375,9 @@ static void r300_merge_textures_and_samplers(struct r300_context* r300) } else { /* determine min/max levels */ /* the MAX_MIP level is the largest (finest) one */ - max_level = MIN3(sampler->max_lod, tex->tex.last_level, - view->last_level); - min_level = MIN2(MAX2(sampler->min_lod, view->first_level), + max_level = MIN3(sampler->max_lod + view->first_level, + tex->tex.last_level, view->last_level); + min_level = MIN2(sampler->min_lod + view->first_level, max_level); texstate->format[0] |= R300_TX_NUM_LEVELS(max_level); texstate->filter[0] |= R300_TX_MAX_MIP_LEVEL(min_level); -- cgit v1.2.3 From 8e1768cfd32a4fa47dd5d4e8f5434fafc3b31201 Mon Sep 17 00:00:00 2001 From: Corbin Simpson Date: Fri, 19 Mar 2010 00:07:55 -0700 Subject: gallium/docs: Fix a couple ReST errors. --- src/gallium/docs/source/context.rst | 1 + src/gallium/docs/source/cso/velems.rst | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'src/gallium') diff --git a/src/gallium/docs/source/context.rst b/src/gallium/docs/source/context.rst index 1f022570dbb..e7a693251ef 100644 --- a/src/gallium/docs/source/context.rst +++ b/src/gallium/docs/source/context.rst @@ -50,6 +50,7 @@ Non-CSO State These pieces of state are too small, variable, and/or trivial to have CSO objects. They all follow simple, one-method binding calls, e.g. ``set_blend_color``. + * ``set_stencil_ref`` sets the stencil front and back reference values which are used as comparison values in stencil test. * ``set_blend_color`` diff --git a/src/gallium/docs/source/cso/velems.rst b/src/gallium/docs/source/cso/velems.rst index 8e758fae103..92cde014fb8 100644 --- a/src/gallium/docs/source/cso/velems.rst +++ b/src/gallium/docs/source/cso/velems.rst @@ -1,4 +1,4 @@ -.. _vertex,elements +.. _vertexelements: Vertex Elements =============== -- cgit v1.2.3 From 980da4aed28eca5770323e4fa55b2fd2670261cf Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Fri, 19 Mar 2010 09:08:33 +0100 Subject: gallium/docs: Clarify sampler view descriptions. --- src/gallium/docs/source/context.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/docs/source/context.rst b/src/gallium/docs/source/context.rst index e7a693251ef..2b0941010b0 100644 --- a/src/gallium/docs/source/context.rst +++ b/src/gallium/docs/source/context.rst @@ -74,11 +74,11 @@ is being cast to another format. Casting can be done only between compatible formats, that is formats that have matching component order and sizes. Swizzle fields specify they way in which fetched texel components are placed -in the result register. For example, swizzle_r specifies what is going to be -placed in destination register x (AKA r). +in the result register. For example, ``swizzle_r`` specifies what is going to be +placed in first component of result register. -first_level and last_level fields of sampler view template specify the LOD -range the texture is going to be constrained to. +The ``first_level`` and ``last_level`` fields of sampler view template specify +the LOD range the texture is going to be constrained to. * ``set_fragment_sampler_views`` binds an array of sampler views to fragment shader stage. Every binding point acquires a reference @@ -89,7 +89,7 @@ range the texture is going to be constrained to. shader stage. Every binding point acquires a reference to a respective sampler view and releases a reference to the previous sampler view. -* ``create_sampler_view`` creates a new sampler view. texture is associated +* ``create_sampler_view`` creates a new sampler view. ``texture`` is associated with the sampler view which results in sampler view holding a reference to the texture. Format specified in template must be compatible with texture format. -- cgit v1.2.3 From 8221a0e7f7eeff2c8201afcf4f5b46fc36dc8606 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Fri, 19 Mar 2010 07:36:50 -0600 Subject: es: added -I$(TOP)/include path --- src/gallium/state_trackers/es/Makefile | 1 + 1 file changed, 1 insertion(+) (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/es/Makefile b/src/gallium/state_trackers/es/Makefile index e33685d2471..089d4411675 100644 --- a/src/gallium/state_trackers/es/Makefile +++ b/src/gallium/state_trackers/es/Makefile @@ -38,6 +38,7 @@ SYS_LIBS = -lm -pthread INCLUDE_DIRS = \ + -I$(TOP)/include \ -I$(TOP)/src/mesa \ -I$(TOP)/src/gallium/include -- cgit v1.2.3 From e5f0384ad06359aa1b9dc1b4bc6f475f7a119af2 Mon Sep 17 00:00:00 2001 From: Roland Scheidegger Date: Fri, 19 Mar 2010 16:29:22 +0100 Subject: st/vega: fix up vega state tracker to use cso changes use cso fragment sampler views instead of sampler textures. since we don't really change views, try to store sampler views instead of the textures to avoid having to recreate views most of the time. --- src/gallium/state_trackers/vega/api_filters.c | 73 ++++++++++++++++++--------- src/gallium/state_trackers/vega/image.c | 37 +++++++++----- src/gallium/state_trackers/vega/image.h | 4 +- src/gallium/state_trackers/vega/mask.c | 66 ++++++++++++++---------- src/gallium/state_trackers/vega/mask.h | 2 +- src/gallium/state_trackers/vega/paint.c | 62 +++++++++++++++-------- src/gallium/state_trackers/vega/paint.h | 2 +- src/gallium/state_trackers/vega/renderer.c | 37 +++++++++----- src/gallium/state_trackers/vega/renderer.h | 3 +- src/gallium/state_trackers/vega/shader.c | 34 ++++++------- src/gallium/state_trackers/vega/vg_context.c | 16 ++++-- src/gallium/state_trackers/vega/vg_context.h | 5 +- src/gallium/state_trackers/vega/vg_tracker.c | 58 ++++++++++++++------- 13 files changed, 253 insertions(+), 146 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/vega/api_filters.c b/src/gallium/state_trackers/vega/api_filters.c index 18e2cc1f250..a643f38624f 100644 --- a/src/gallium/state_trackers/vega/api_filters.c +++ b/src/gallium/state_trackers/vega/api_filters.c @@ -40,6 +40,7 @@ #include "util/u_format.h" #include "util/u_memory.h" +#include "util/u_sampler.h" #include "asm_filters.h" @@ -53,7 +54,7 @@ struct filter_info { const void *const_buffer; VGint const_buffer_len; VGTilingMode tiling_mode; - struct pipe_texture *extra_texture; + struct pipe_sampler_view *extra_texture_view; }; static INLINE struct pipe_texture *create_texture_1d(struct vg_context *ctx, @@ -91,13 +92,35 @@ static INLINE struct pipe_texture *create_texture_1d(struct vg_context *ctx, return tex; } +static INLINE struct pipe_sampler_view *create_texture_1d_view(struct vg_context *ctx, + const VGuint *color_data, + const VGint color_data_len) +{ + struct pipe_context *pipe = ctx->pipe; + struct pipe_texture *texture; + struct pipe_sampler_view view_templ; + struct pipe_sampler_view *view; + + texture = create_texture_1d(ctx, color_data, color_data_len); + + if (!texture) + return NULL; + + u_sampler_view_default_template(&view_templ, texture, texture->format); + view = pipe->create_sampler_view(pipe, texture, &view_templ); + /* want the texture to go away if the view is freed */ + pipe_texture_reference(&texture, NULL); + + return view; +} + static INLINE struct pipe_surface * setup_framebuffer(struct vg_image *dst) { struct vg_context *ctx = vg_current_context(); struct pipe_context *pipe = ctx->pipe; struct pipe_framebuffer_state fb; struct pipe_surface *dst_surf = pipe->screen->get_tex_surface( - pipe->screen, dst->texture, 0, 0, 0, + pipe->screen, dst->sampler_view->texture, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE); /* drawing dest */ @@ -168,7 +191,7 @@ static void setup_constant_buffer(struct vg_context *ctx, const void *buffer, static void setup_samplers(struct vg_context *ctx, struct filter_info *info) { struct pipe_sampler_state *samplers[PIPE_MAX_SAMPLERS]; - struct pipe_texture *textures[PIPE_MAX_SAMPLERS]; + struct pipe_sampler_view *sampler_views[PIPE_MAX_SAMPLERS]; struct pipe_sampler_state sampler[3]; int num_samplers = 0; int num_textures = 0; @@ -177,10 +200,10 @@ static void setup_samplers(struct vg_context *ctx, struct filter_info *info) samplers[1] = NULL; samplers[2] = NULL; samplers[3] = NULL; - textures[0] = NULL; - textures[1] = NULL; - textures[2] = NULL; - textures[3] = NULL; + sampler_views[0] = NULL; + sampler_views[1] = NULL; + sampler_views[2] = NULL; + sampler_views[3] = NULL; memset(&sampler[0], 0, sizeof(struct pipe_sampler_state)); sampler[0].wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE; @@ -215,21 +238,21 @@ static void setup_samplers(struct vg_context *ctx, struct filter_info *info) } samplers[0] = &sampler[0]; - textures[0] = info->src->texture; + sampler_views[0] = info->src->sampler_view; ++num_samplers; ++num_textures; - if (info->extra_texture) { + if (info->extra_texture_view) { memcpy(&sampler[1], &sampler[0], sizeof(struct pipe_sampler_state)); samplers[1] = &sampler[1]; - textures[1] = info->extra_texture; + sampler_views[1] = info->extra_texture_view; ++num_samplers; ++num_textures; } cso_set_samplers(ctx->cso_context, num_samplers, (const struct pipe_sampler_state **)samplers); - cso_set_sampler_textures(ctx->cso_context, num_textures, textures); + cso_set_fragment_sampler_views(ctx->cso_context, num_textures, sampler_views); } static struct vg_shader * setup_color_matrix(struct vg_context *ctx, void *user_data) @@ -308,7 +331,7 @@ static void execute_filter(struct vg_context *ctx, cso_save_viewport(ctx->cso_context); cso_save_blend(ctx->cso_context); cso_save_samplers(ctx->cso_context); - cso_save_sampler_textures(ctx->cso_context); + cso_save_fragment_sampler_views(ctx->cso_context); dst_surf = setup_framebuffer(info->dst); setup_viewport(info->dst); @@ -318,7 +341,7 @@ static void execute_filter(struct vg_context *ctx, setup_samplers(ctx, info); renderer_draw_texture(ctx->renderer, - info->src->texture, + info->src->sampler_view->texture, info->dst->x, info->dst->y, info->dst->x + info->dst->width, info->dst->y + info->dst->height, @@ -331,7 +354,7 @@ static void execute_filter(struct vg_context *ctx, cso_restore_viewport(ctx->cso_context); cso_restore_blend(ctx->cso_context); cso_restore_samplers(ctx->cso_context); - cso_restore_sampler_textures(ctx->cso_context); + cso_restore_fragment_sampler_views(ctx->cso_context); vg_shader_destroy(ctx, shader); @@ -369,7 +392,7 @@ void vgColorMatrix(VGImage dst, VGImage src, info.const_buffer = matrix; info.const_buffer_len = 20 * sizeof(VGfloat); info.tiling_mode = VG_TILE_PAD; - info.extra_texture = 0; + info.extra_texture_view = NULL; execute_filter(ctx, &info); } @@ -479,7 +502,7 @@ void vgConvolve(VGImage dst, VGImage src, info.const_buffer = buffer; info.const_buffer_len = buffer_len * sizeof(VGfloat); info.tiling_mode = tilingMode; - info.extra_texture = 0; + info.extra_texture_view = NULL; execute_filter(ctx, &info); free(buffer); @@ -669,7 +692,7 @@ void vgGaussianBlur(VGImage dst, VGImage src, info.const_buffer = buffer; info.const_buffer_len = buffer_len * sizeof(VGfloat); info.tiling_mode = tilingMode; - info.extra_texture = 0; + info.extra_texture_view = NULL; execute_filter(ctx, &info); free(buffer); @@ -688,7 +711,7 @@ void vgLookup(VGImage dst, VGImage src, struct vg_image *d, *s; VGuint color_data[256]; VGint i; - struct pipe_texture *lut_texture; + struct pipe_sampler_view *lut_texture_view; VGfloat buffer[4]; struct filter_info info; @@ -714,7 +737,7 @@ void vgLookup(VGImage dst, VGImage src, color_data[i] = blueLUT[i] << 24 | greenLUT[i] << 16 | redLUT[i] << 8 | alphaLUT[i]; } - lut_texture = create_texture_1d(ctx, color_data, 255); + lut_texture_view = create_texture_1d_view(ctx, color_data, 255); buffer[0] = 0.f; buffer[1] = 0.f; @@ -728,11 +751,11 @@ void vgLookup(VGImage dst, VGImage src, info.const_buffer = buffer; info.const_buffer_len = 4 * sizeof(VGfloat); info.tiling_mode = VG_TILE_PAD; - info.extra_texture = lut_texture; + info.extra_texture_view = lut_texture_view; execute_filter(ctx, &info); - pipe_texture_reference(&lut_texture, NULL); + pipe_sampler_view_reference(&lut_texture_view, NULL); } void vgLookupSingle(VGImage dst, VGImage src, @@ -743,7 +766,7 @@ void vgLookupSingle(VGImage dst, VGImage src, { struct vg_context *ctx = vg_current_context(); struct vg_image *d, *s; - struct pipe_texture *lut_texture; + struct pipe_sampler_view *lut_texture_view; VGfloat buffer[4]; struct filter_info info; VGuint color_data[256]; @@ -783,7 +806,7 @@ void vgLookupSingle(VGImage dst, VGImage src, color_data[i] = blue << 24 | green << 16 | red << 8 | alpha; } - lut_texture = create_texture_1d(ctx, color_data, 256); + lut_texture_view = create_texture_1d_view(ctx, color_data, 256); buffer[0] = 0.f; buffer[1] = 0.f; @@ -797,9 +820,9 @@ void vgLookupSingle(VGImage dst, VGImage src, info.const_buffer = buffer; info.const_buffer_len = 4 * sizeof(VGfloat); info.tiling_mode = VG_TILE_PAD; - info.extra_texture = lut_texture; + info.extra_texture_view = lut_texture_view; execute_filter(ctx, &info); - pipe_texture_reference(&lut_texture, NULL); + pipe_sampler_view_reference(&lut_texture_view, NULL); } diff --git a/src/gallium/state_trackers/vega/image.c b/src/gallium/state_trackers/vega/image.c index a71579cd264..c3268a84a60 100644 --- a/src/gallium/state_trackers/vega/image.c +++ b/src/gallium/state_trackers/vega/image.c @@ -43,6 +43,7 @@ #include "util/u_tile.h" #include "util/u_memory.h" #include "util/u_math.h" +#include "util/u_sampler.h" static enum pipe_format vg_format_to_pipe(VGImageFormat format) { @@ -81,7 +82,7 @@ static INLINE void vg_sync_size(VGfloat *src_loc, VGfloat *dst_loc) static void vg_copy_texture(struct vg_context *ctx, struct pipe_texture *dst, VGint dx, VGint dy, - struct pipe_texture *src, VGint sx, VGint sy, + struct pipe_sampler_view *src, VGint sx, VGint sy, VGint width, VGint height) { VGfloat dst_loc[4], src_loc[4]; @@ -103,8 +104,8 @@ static void vg_copy_texture(struct vg_context *ctx, src_loc[3] = height; src_bounds[0] = 0.f; src_bounds[1] = 0.f; - src_bounds[2] = src->width0; - src_bounds[3] = src->height0; + src_bounds[2] = src->texture->width0; + src_bounds[3] = src->texture->height0; vg_bound_rect(src_loc, src_bounds, src_shift); vg_bound_rect(dst_loc, dst_bounds, dst_shift); @@ -218,7 +219,7 @@ void vg_copy_surface(struct vg_context *ctx, static struct pipe_texture *image_texture(struct vg_image *img) { - struct pipe_texture *tex = img->texture; + struct pipe_texture *tex = img->sampler_view->texture; return tex; } @@ -247,9 +248,12 @@ struct vg_image * image_create(VGImageFormat format, VGint width, VGint height) { struct vg_context *ctx = vg_current_context(); + struct pipe_context *pipe = ctx->pipe; struct vg_image *image = CALLOC_STRUCT(vg_image); enum pipe_format pformat = vg_format_to_pipe(format); struct pipe_texture pt, *newtex; + struct pipe_sampler_view view_templ; + struct pipe_sampler_view *view; struct pipe_screen *screen = ctx->pipe->screen; vg_init_object(&image->base, ctx, VG_OBJECT_IMAGE); @@ -281,7 +285,12 @@ struct vg_image * image_create(VGImageFormat format, debug_assert(newtex); - image->texture = newtex; + u_sampler_view_default_template(&view_templ, newtex, newtex->format); + view = pipe->create_sampler_view(pipe, newtex, &view_templ); + /* want the texture to go away if the view is freed */ + pipe_texture_reference(&newtex, NULL); + + image->sampler_view = view; vg_context_add_object(ctx, VG_OBJECT_IMAGE, image); @@ -345,7 +354,7 @@ void image_destroy(struct vg_image *img) array_destroy(img->children_array); } - pipe_texture_reference(&img->texture, NULL); + pipe_sampler_view_reference(&img->sampler_view, NULL); free(img); } @@ -444,7 +453,7 @@ void image_get_sub_data(struct vg_image * image, { struct pipe_transfer *transfer = pipe->get_tex_transfer(pipe, - image->texture, 0, 0, 0, + image->sampler_view->texture, 0, 0, 0, PIPE_TRANSFER_READ, 0, 0, image->x + image->width, @@ -478,9 +487,9 @@ struct vg_image * image_child_image(struct vg_image *parent, image->width = width; image->height = height; image->parent = parent; - image->texture = 0; - pipe_texture_reference(&image->texture, - parent->texture); + image->sampler_view = NULL; + pipe_sampler_view_reference(&image->sampler_view, + parent->sampler_view); image->sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE; image->sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE; @@ -514,8 +523,8 @@ void image_copy(struct vg_image *dst, VGint dx, VGint dy, } /* make sure rendering has completed */ ctx->pipe->flush(ctx->pipe, PIPE_FLUSH_RENDER_CACHE, NULL); - vg_copy_texture(ctx, dst->texture, dst->x + dx, dst->y + dy, - src->texture, src->x + sx, src->y + sy, width, height); + vg_copy_texture(ctx, dst->sampler_view->texture, dst->x + dx, dst->y + dy, + src->sampler_view, src->x + sx, src->y + sy, width, height); } void image_draw(struct vg_image *img) @@ -624,12 +633,12 @@ VGboolean vg_image_overlaps(struct vg_image *dst, } VGint image_bind_samplers(struct vg_image *img, struct pipe_sampler_state **samplers, - struct pipe_texture **textures) + struct pipe_sampler_view **sampler_views) { img->sampler.min_img_filter = image_sampler_filter(img->base.ctx); img->sampler.mag_img_filter = image_sampler_filter(img->base.ctx); samplers[3] = &img->sampler; - textures[3] = img->texture; + sampler_views[3] = img->sampler_view; return 1; } diff --git a/src/gallium/state_trackers/vega/image.h b/src/gallium/state_trackers/vega/image.h index 78e17cffa64..805b35fab9f 100644 --- a/src/gallium/state_trackers/vega/image.h +++ b/src/gallium/state_trackers/vega/image.h @@ -43,7 +43,7 @@ struct vg_image { struct vg_image *parent; - struct pipe_texture *texture; + struct pipe_sampler_view *sampler_view; struct pipe_sampler_state sampler; struct array *children_array; @@ -89,7 +89,7 @@ void image_get_pixels(struct vg_image *dst, VGint dx, VGint dy, VGint width, VGint height); VGint image_bind_samplers(struct vg_image *dst, struct pipe_sampler_state **samplers, - struct pipe_texture **textures); + struct pipe_sampler_view **sampler_views); VGboolean vg_image_overlaps(struct vg_image *dst, struct vg_image *src); diff --git a/src/gallium/state_trackers/vega/mask.c b/src/gallium/state_trackers/vega/mask.c index 839dc19a3b8..316ea7a9c95 100644 --- a/src/gallium/state_trackers/vega/mask.c +++ b/src/gallium/state_trackers/vega/mask.c @@ -45,7 +45,7 @@ struct vg_mask_layer { VGint width; VGint height; - struct pipe_texture *texture; + struct pipe_sampler_view *sampler_view; }; static INLINE struct pipe_surface * @@ -54,7 +54,7 @@ alpha_mask_surface(struct vg_context *ctx, int usage) struct pipe_screen *screen = ctx->pipe->screen; struct st_framebuffer *stfb = ctx->draw_buffer; return screen->get_tex_surface(screen, - stfb->alpha_mask, + stfb->alpha_mask_view->texture, 0, 0, 0, usage); } @@ -284,35 +284,33 @@ static void setup_mask_operation(VGMaskOperation operation) cso_set_fragment_shader_handle(ctx->cso_context, shader); } -static void setup_mask_samplers(struct pipe_texture *umask) +static void setup_mask_samplers(struct pipe_sampler_view *umask) { struct vg_context *ctx = vg_current_context(); struct pipe_sampler_state *samplers[PIPE_MAX_SAMPLERS]; - struct pipe_texture *textures[PIPE_MAX_SAMPLERS]; + struct pipe_sampler_view *sampler_views[PIPE_MAX_SAMPLERS]; struct st_framebuffer *fb_buffers = ctx->draw_buffer; - struct pipe_texture *uprev = NULL; + struct pipe_sampler_view *uprev = NULL; struct pipe_sampler_state sampler; - uprev = fb_buffers->blend_texture; + uprev = fb_buffers->blend_texture_view; sampler = ctx->mask.sampler; sampler.normalized_coords = 1; samplers[0] = NULL; samplers[1] = NULL; - samplers[2] = NULL; - textures[0] = NULL; - textures[1] = NULL; - textures[2] = NULL; + sampler_views[0] = NULL; + sampler_views[1] = NULL; samplers[0] = &sampler; samplers[1] = &ctx->mask.sampler; - textures[0] = umask; - textures[1] = uprev; + sampler_views[0] = umask; + sampler_views[1] = uprev; cso_set_samplers(ctx->cso_context, 2, (const struct pipe_sampler_state **)samplers); - cso_set_sampler_textures(ctx->cso_context, 2, textures); + cso_set_fragment_sampler_views(ctx->cso_context, 2, sampler_views); } @@ -411,12 +409,13 @@ static void surface_fill(struct pipe_surface *surf, } -static void mask_using_texture(struct pipe_texture *texture, +static void mask_using_texture(struct pipe_sampler_view *sampler_view, VGMaskOperation operation, VGint x, VGint y, VGint width, VGint height) { struct vg_context *ctx = vg_current_context(); + struct pipe_texture *texture = sampler_view->texture; struct pipe_surface *surface = alpha_mask_surface(ctx, PIPE_BUFFER_USAGE_GPU_WRITE); VGint offsets[4], loc[4]; @@ -439,13 +438,13 @@ static void mask_using_texture(struct pipe_texture *texture, vg_prepare_blend_surface_from_mask(ctx); cso_save_samplers(ctx->cso_context); - cso_save_sampler_textures(ctx->cso_context); + cso_save_fragment_sampler_views(ctx->cso_context); cso_save_framebuffer(ctx->cso_context); cso_save_blend(ctx->cso_context); cso_save_fragment_shader(ctx->cso_context); cso_save_viewport(ctx->cso_context); - setup_mask_samplers(texture); + setup_mask_samplers(sampler_view); setup_mask_blend(); setup_mask_operation(operation); setup_mask_framebuffer(surface, surface->width, surface->height); @@ -463,7 +462,7 @@ static void mask_using_texture(struct pipe_texture *texture, cso_restore_framebuffer(ctx->cso_context); cso_restore_fragment_shader(ctx->cso_context); cso_restore_samplers(ctx->cso_context); - cso_restore_sampler_textures(ctx->cso_context); + cso_restore_fragment_sampler_views(ctx->cso_context); cso_restore_viewport(ctx->cso_context); pipe_surface_reference(&surface, NULL); @@ -484,7 +483,11 @@ struct vg_mask_layer * mask_layer_create(VGint width, VGint height) { struct pipe_texture pt; + struct pipe_context *pipe = ctx->pipe; struct pipe_screen *screen = ctx->pipe->screen; + struct pipe_sampler_view view_templ; + struct pipe_sampler_view *view = NULL; + struct pipe_texture *texture; memset(&pt, 0, sizeof(pt)); pt.target = PIPE_TEXTURE_2D; @@ -496,7 +499,14 @@ struct vg_mask_layer * mask_layer_create(VGint width, VGint height) pt.tex_usage = PIPE_TEXTURE_USAGE_SAMPLER; pt.compressed = 0; - mask->texture = screen->texture_create(screen, &pt); + texture = screen->texture_create(screen, &pt); + + if (texture) { + u_sampler_view_default_template(&view_templ, texture, texture->format); + view = pipe->create_sampler_view(pipe, texture, &view_templ); + } + pipe_texture_reference(&texture, NULL); + mask->sampler_view = view; } vg_context_add_object(ctx, VG_OBJECT_MASK, mask); @@ -525,7 +535,7 @@ void mask_layer_fill(struct vg_mask_layer *layer, alpha_color[3] = value; surface = ctx->pipe->screen->get_tex_surface( - ctx->pipe->screen, layer->texture, + ctx->pipe->screen, layer->sampler_view->texture, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE); @@ -545,10 +555,10 @@ void mask_copy(struct vg_mask_layer *layer, struct st_framebuffer *fb_buffers = ctx->draw_buffer; renderer_copy_texture(ctx->renderer, - layer->texture, + layer->sampler_view, sx, sy, sx + width, sy + height, - fb_buffers->alpha_mask, + fb_buffers->alpha_mask_view->texture, dx, dy, dx + width, dy + height); } @@ -562,7 +572,7 @@ static void mask_layer_render_to(struct vg_mask_layer *layer, struct pipe_screen *screen = ctx->pipe->screen; struct pipe_surface *surface; - surface = screen->get_tex_surface(screen, layer->texture, 0, 0, 0, + surface = screen->get_tex_surface(screen, layer->sampler_view->texture, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE); cso_save_framebuffer(ctx->cso_context); @@ -604,8 +614,8 @@ void mask_render_to(struct path *path, struct vg_mask_layer *temp_layer; VGint width, height; - width = fb_buffers->alpha_mask->width0; - height = fb_buffers->alpha_mask->width0; + width = fb_buffers->alpha_mask_view->texture->width0; + height = fb_buffers->alpha_mask_view->texture->width0; temp_layer = mask_layer_create(width, height); @@ -622,7 +632,7 @@ void mask_using_layer(struct vg_mask_layer *layer, VGint x, VGint y, VGint width, VGint height) { - mask_using_texture(layer->texture, operation, + mask_using_texture(layer->sampler_view, operation, x, y, width, height); } @@ -644,7 +654,7 @@ void mask_using_image(struct vg_image *image, VGint x, VGint y, VGint width, VGint height) { - mask_using_texture(image->texture, operation, + mask_using_texture(image->sampler_view, operation, x, y, width, height); } @@ -672,7 +682,7 @@ void mask_fill(VGint x, VGint y, VGint width, VGint height, } VGint mask_bind_samplers(struct pipe_sampler_state **samplers, - struct pipe_texture **textures) + struct pipe_sampler_view **sampler_views) { struct vg_context *ctx = vg_current_context(); @@ -680,7 +690,7 @@ VGint mask_bind_samplers(struct pipe_sampler_state **samplers, struct st_framebuffer *fb_buffers = ctx->draw_buffer; samplers[1] = &ctx->mask.sampler; - textures[1] = fb_buffers->alpha_mask; + sampler_views[1] = fb_buffers->alpha_mask_view; return 1; } else return 0; diff --git a/src/gallium/state_trackers/vega/mask.h b/src/gallium/state_trackers/vega/mask.h index 5eaaede0e3a..4feacbefda8 100644 --- a/src/gallium/state_trackers/vega/mask.h +++ b/src/gallium/state_trackers/vega/mask.h @@ -63,6 +63,6 @@ void mask_fill(VGint x, VGint y, VGfloat value); VGint mask_bind_samplers(struct pipe_sampler_state **samplers, - struct pipe_texture **textures); + struct pipe_sampler_view **sampler_views); #endif diff --git a/src/gallium/state_trackers/vega/paint.c b/src/gallium/state_trackers/vega/paint.c index dc56b8c5f3b..508e1863a57 100644 --- a/src/gallium/state_trackers/vega/paint.c +++ b/src/gallium/state_trackers/vega/paint.c @@ -37,6 +37,7 @@ #include "util/u_format.h" #include "util/u_memory.h" #include "util/u_math.h" +#include "util/u_sampler.h" #include "cso_cache/cso_context.h" @@ -61,7 +62,7 @@ struct vg_paint { VGfloat vals[5]; VGint valsi[5]; } radial; - struct pipe_texture *texture; + struct pipe_sampler_view *sampler_view; struct pipe_sampler_state sampler; VGfloat *ramp_stops; @@ -72,7 +73,7 @@ struct vg_paint { } gradient; struct { - struct pipe_texture *texture; + struct pipe_sampler_view *sampler_view; VGTilingMode tiling_mode; struct pipe_sampler_state sampler; } pattern; @@ -173,6 +174,26 @@ static INLINE struct pipe_texture *create_gradient_texture(struct vg_paint *p) return tex; } +static INLINE struct pipe_sampler_view *create_gradient_sampler_view(struct vg_paint *p) +{ + struct pipe_context *pipe = p->base.ctx->pipe; + struct pipe_texture *texture; + struct pipe_sampler_view view_templ; + struct pipe_sampler_view *view; + + texture = create_gradient_texture(p); + + if (!texture) + return NULL; + + u_sampler_view_default_template(&view_templ, texture, texture->format); + view = pipe->create_sampler_view(pipe, texture, &view_templ); + /* want the texture to go away if the view is freed */ + pipe_texture_reference(&texture, NULL); + + return view; +} + struct vg_paint * paint_create(struct vg_context *ctx) { struct vg_paint *paint = CALLOC_STRUCT(vg_paint); @@ -207,8 +228,9 @@ struct vg_paint * paint_create(struct vg_context *ctx) void paint_destroy(struct vg_paint *paint) { struct vg_context *ctx = paint->base.ctx; - if (paint->pattern.texture) - pipe_texture_reference(&paint->pattern.texture, NULL); + pipe_sampler_view_reference(&paint->gradient.sampler_view, NULL); + if (paint->pattern.sampler_view) + pipe_sampler_view_reference(&paint->pattern.sampler_view, NULL); if (ctx) vg_context_remove_object(ctx, VG_OBJECT_PAINT, paint); @@ -329,8 +351,8 @@ static INLINE void paint_pattern_buffer(struct vg_paint *paint, void *buffer) map[4] = 0.f; map[5] = 1.f; - map[6] = paint->pattern.texture->width0; - map[7] = paint->pattern.texture->height0; + map[6] = paint->pattern.sampler_view->texture->width0; + map[7] = paint->pattern.sampler_view->texture->height0; { struct matrix mat; memcpy(&mat, &ctx->state.vg.fill_paint_to_user_matrix, @@ -394,12 +416,12 @@ void paint_set_ramp_stops(struct vg_paint *paint, const VGfloat *stops, create_gradient_data(stops, num / 5, paint->gradient.color_data, 1024); - if (paint->gradient.texture) { - pipe_texture_reference(&paint->gradient.texture, NULL); - paint->gradient.texture = 0; + if (paint->gradient.sampler_view) { + pipe_sampler_view_reference(&paint->gradient.sampler_view, NULL); + paint->gradient.sampler_view = NULL; } - paint->gradient.texture = create_gradient_texture(paint); + paint->gradient.sampler_view = create_gradient_sampler_view(paint); } void paint_set_colori(struct vg_paint *p, @@ -459,12 +481,12 @@ void paint_set_radial_gradient(struct vg_paint *paint, void paint_set_pattern(struct vg_paint *paint, struct vg_image *img) { - if (paint->pattern.texture) - pipe_texture_reference(&paint->pattern.texture, NULL); + if (paint->pattern.sampler_view) + pipe_sampler_view_reference(&paint->pattern.sampler_view, NULL); - paint->pattern.texture = 0; - pipe_texture_reference(&paint->pattern.texture, - img->texture); + paint->pattern.sampler_view = NULL; + pipe_sampler_view_reference(&paint->pattern.sampler_view, + img->sampler_view); } void paint_set_pattern_tiling(struct vg_paint *paint, @@ -611,18 +633,18 @@ VGTilingMode paint_pattern_tiling(struct vg_paint *paint) } VGint paint_bind_samplers(struct vg_paint *paint, struct pipe_sampler_state **samplers, - struct pipe_texture **textures) + struct pipe_sampler_view **sampler_views) { struct vg_context *ctx = vg_current_context(); switch(paint->type) { case VG_PAINT_TYPE_LINEAR_GRADIENT: case VG_PAINT_TYPE_RADIAL_GRADIENT: { - if (paint->gradient.texture) { + if (paint->gradient.sampler_view) { paint->gradient.sampler.min_img_filter = image_sampler_filter(ctx); paint->gradient.sampler.mag_img_filter = image_sampler_filter(ctx); samplers[0] = &paint->gradient.sampler; - textures[0] = paint->gradient.texture; + sampler_views[0] = paint->gradient.sampler_view; return 1; } } @@ -634,7 +656,7 @@ VGint paint_bind_samplers(struct vg_paint *paint, struct pipe_sampler_state **sa paint->pattern.sampler.min_img_filter = image_sampler_filter(ctx); paint->pattern.sampler.mag_img_filter = image_sampler_filter(ctx); samplers[0] = &paint->pattern.sampler; - textures[0] = paint->pattern.texture; + sampler_views[0] = paint->pattern.sampler_view; return 1; } break; @@ -647,7 +669,7 @@ VGint paint_bind_samplers(struct vg_paint *paint, struct pipe_sampler_state **sa void paint_resolve_type(struct vg_paint *paint) { if (paint->type == VG_PAINT_TYPE_PATTERN && - !paint->pattern.texture) { + !paint->pattern.sampler_view) { paint->type = VG_PAINT_TYPE_COLOR; } } diff --git a/src/gallium/state_trackers/vega/paint.h b/src/gallium/state_trackers/vega/paint.h index 999b5c167ca..9ea67c4b1e6 100644 --- a/src/gallium/state_trackers/vega/paint.h +++ b/src/gallium/state_trackers/vega/paint.h @@ -108,7 +108,7 @@ VGboolean paint_color_ramp_premultiplied(struct vg_paint *paint); VGint paint_bind_samplers(struct vg_paint *paint, struct pipe_sampler_state **samplers, - struct pipe_texture **textures); + struct pipe_sampler_view **sampler_views); VGint paint_constant_buffer_size(struct vg_paint *paint); void paint_fill_constant_buffer(struct vg_paint *paint, diff --git a/src/gallium/state_trackers/vega/renderer.c b/src/gallium/state_trackers/vega/renderer.c index 47e8b470a11..2bb4c8bc756 100644 --- a/src/gallium/state_trackers/vega/renderer.c +++ b/src/gallium/state_trackers/vega/renderer.c @@ -39,6 +39,7 @@ #include "util/u_simple_shaders.h" #include "util/u_memory.h" #include "util/u_rect.h" +#include "util/u_sampler.h" #include "cso_cache/cso_context.h" @@ -263,7 +264,7 @@ void renderer_draw_texture(struct renderer *r, } void renderer_copy_texture(struct renderer *ctx, - struct pipe_texture *src, + struct pipe_sampler_view *src, VGfloat sx1, VGfloat sy1, VGfloat sx2, VGfloat sy2, struct pipe_texture *dst, @@ -272,6 +273,7 @@ void renderer_copy_texture(struct renderer *ctx, { struct pipe_context *pipe = ctx->pipe; struct pipe_screen *screen = pipe->screen; + struct pipe_texture *tex = src->texture; struct pipe_buffer *buf; struct pipe_surface *dst_surf = screen->get_tex_surface( screen, dst, 0, 0, 0, @@ -279,8 +281,8 @@ void renderer_copy_texture(struct renderer *ctx, struct pipe_framebuffer_state fb; float s0, t0, s1, t1; - assert(src->width0 != 0); - assert(src->height0 != 0); + assert(tex->width0 != 0); + assert(tex->height0 != 0); assert(dst->width0 != 0); assert(dst->height0 != 0); @@ -290,10 +292,10 @@ void renderer_copy_texture(struct renderer *ctx, #endif #if 1 - s0 = sx1 / src->width0; - s1 = sx2 / src->width0; - t0 = sy1 / src->height0; - t1 = sy2 / src->height0; + s0 = sx1 / tex->width0; + s1 = sx2 / tex->width0; + t0 = sy1 / tex->height0; + t1 = sy2 / tex->height0; #else s0 = 0; s1 = 1; @@ -307,7 +309,7 @@ void renderer_copy_texture(struct renderer *ctx, /* save state (restored below) */ cso_save_blend(ctx->cso); cso_save_samplers(ctx->cso); - cso_save_sampler_textures(ctx->cso); + cso_save_fragment_sampler_views(ctx->cso); cso_save_framebuffer(ctx->cso); cso_save_fragment_shader(ctx->cso); cso_save_vertex_shader(ctx->cso); @@ -345,7 +347,7 @@ void renderer_copy_texture(struct renderer *ctx, vg_set_viewport(ctx->owner, VEGA_Y0_TOP); /* texture */ - cso_set_sampler_textures(ctx->cso, 1, &src); + cso_set_fragment_sampler_views(ctx->cso, 1, &src); /* shaders */ cso_set_vertex_shader_handle(ctx->cso, vg_texture_vs(ctx->owner)); @@ -385,7 +387,7 @@ void renderer_copy_texture(struct renderer *ctx, /* restore state we changed */ cso_restore_blend(ctx->cso); cso_restore_samplers(ctx->cso); - cso_restore_sampler_textures(ctx->cso); + cso_restore_fragment_sampler_views(ctx->cso); cso_restore_framebuffer(ctx->cso); cso_restore_vertex_shader(ctx->cso); cso_restore_fragment_shader(ctx->cso); @@ -406,6 +408,8 @@ void renderer_copy_surface(struct renderer *ctx, struct pipe_context *pipe = ctx->pipe; struct pipe_screen *screen = pipe->screen; struct pipe_buffer *buf; + struct pipe_sampler_view view_templ; + struct pipe_sampler_view *view; struct pipe_texture texTemp, *tex; struct pipe_surface *texSurf; struct pipe_framebuffer_state fb; @@ -457,6 +461,12 @@ void renderer_copy_surface(struct renderer *ctx, if (!tex) return; + u_sampler_view_default_template(&view_templ, tex, tex->format); + view = pipe->create_sampler_view(pipe, tex, &view_templ); + + if (!view) + return; + texSurf = screen->get_tex_surface(screen, tex, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE); @@ -479,7 +489,7 @@ void renderer_copy_surface(struct renderer *ctx, /* save state (restored below) */ cso_save_blend(ctx->cso); cso_save_samplers(ctx->cso); - cso_save_sampler_textures(ctx->cso); + cso_save_fragment_sampler_views(ctx->cso); cso_save_framebuffer(ctx->cso); cso_save_fragment_shader(ctx->cso); cso_save_vertex_shader(ctx->cso); @@ -515,7 +525,7 @@ void renderer_copy_surface(struct renderer *ctx, } /* texture */ - cso_set_sampler_textures(ctx->cso, 1, &tex); + cso_set_fragment_sampler_views(ctx->cso, 1, &view); /* shaders */ cso_set_fragment_shader_handle(ctx->cso, ctx->fs); @@ -552,13 +562,14 @@ void renderer_copy_surface(struct renderer *ctx, /* restore state we changed */ cso_restore_blend(ctx->cso); cso_restore_samplers(ctx->cso); - cso_restore_sampler_textures(ctx->cso); + cso_restore_fragment_sampler_views(ctx->cso); cso_restore_framebuffer(ctx->cso); cso_restore_fragment_shader(ctx->cso); cso_restore_vertex_shader(ctx->cso); cso_restore_viewport(ctx->cso); pipe_texture_reference(&tex, NULL); + pipe_sampler_view_reference(&view, NULL); } void renderer_texture_quad(struct renderer *r, diff --git a/src/gallium/state_trackers/vega/renderer.h b/src/gallium/state_trackers/vega/renderer.h index 990cd32c313..03366f13614 100644 --- a/src/gallium/state_trackers/vega/renderer.h +++ b/src/gallium/state_trackers/vega/renderer.h @@ -33,6 +33,7 @@ struct renderer; struct vg_context; struct pipe_texture; +struct pipe_sampler_view; struct pipe_surface; struct renderer *renderer_create(struct vg_context *owner); @@ -57,7 +58,7 @@ void renderer_texture_quad(struct renderer *, VGfloat x3, VGfloat y3, VGfloat x4, VGfloat y4); void renderer_copy_texture(struct renderer *r, - struct pipe_texture *src, + struct pipe_sampler_view *src, VGfloat sx1, VGfloat sy1, VGfloat sx2, VGfloat sy2, struct pipe_texture *dst, diff --git a/src/gallium/state_trackers/vega/shader.c b/src/gallium/state_trackers/vega/shader.c index 0e71a507bff..f2ec24c57ff 100644 --- a/src/gallium/state_trackers/vega/shader.c +++ b/src/gallium/state_trackers/vega/shader.c @@ -119,7 +119,7 @@ static void setup_constant_buffer(struct shader *shader) static VGint blend_bind_samplers(struct vg_context *ctx, struct pipe_sampler_state **samplers, - struct pipe_texture **textures) + struct pipe_sampler_view **sampler_views) { VGBlendMode bmode = ctx->state.vg.blend_mode; @@ -132,15 +132,15 @@ static VGint blend_bind_samplers(struct vg_context *ctx, vg_prepare_blend_surface(ctx); samplers[2] = &ctx->blend_sampler; - textures[2] = stfb->blend_texture; + sampler_views[2] = stfb->blend_texture_view; - if (!samplers[0] || !textures[0]) { + if (!samplers[0] || !sampler_views[0]) { samplers[0] = samplers[2]; - textures[0] = textures[2]; + sampler_views[0] = sampler_views[2]; } - if (!samplers[1] || !textures[1]) { + if (!samplers[1] || !sampler_views[1]) { samplers[1] = samplers[0]; - textures[1] = textures[0]; + sampler_views[1] = sampler_views[0]; } return 1; @@ -151,7 +151,7 @@ static VGint blend_bind_samplers(struct vg_context *ctx, static void setup_samplers(struct shader *shader) { struct pipe_sampler_state *samplers[PIPE_MAX_SAMPLERS]; - struct pipe_texture *textures[PIPE_MAX_SAMPLERS]; + struct pipe_sampler_view *sampler_views[PIPE_MAX_SAMPLERS]; struct vg_context *ctx = shader->context; /* a little wonky: we use the num as a boolean that just says * whether any sampler/textures have been set. the actual numbering @@ -167,20 +167,20 @@ static void setup_samplers(struct shader *shader) samplers[1] = NULL; samplers[2] = NULL; samplers[3] = NULL; - textures[0] = NULL; - textures[1] = NULL; - textures[2] = NULL; - textures[3] = NULL; - - num += paint_bind_samplers(shader->paint, samplers, textures); - num += mask_bind_samplers(samplers, textures); - num += blend_bind_samplers(ctx, samplers, textures); + sampler_views[0] = NULL; + sampler_views[1] = NULL; + sampler_views[2] = NULL; + sampler_views[3] = NULL; + + num += paint_bind_samplers(shader->paint, samplers, sampler_views); + num += mask_bind_samplers(samplers, sampler_views); + num += blend_bind_samplers(ctx, samplers, sampler_views); if (shader->drawing_image && shader->image) - num += image_bind_samplers(shader->image, samplers, textures); + num += image_bind_samplers(shader->image, samplers, sampler_views); if (num) { cso_set_samplers(ctx->cso_context, 4, (const struct pipe_sampler_state **)samplers); - cso_set_sampler_textures(ctx->cso_context, 4, textures); + cso_set_fragment_sampler_views(ctx->cso_context, 4, sampler_views); } } diff --git a/src/gallium/state_trackers/vega/vg_context.c b/src/gallium/state_trackers/vega/vg_context.c index 7769112a31e..11ebbbe5444 100644 --- a/src/gallium/state_trackers/vega/vg_context.c +++ b/src/gallium/state_trackers/vega/vg_context.c @@ -43,6 +43,7 @@ #include "util/u_simple_shaders.h" #include "util/u_memory.h" #include "util/u_blit.h" +#include "util/u_sampler.h" struct vg_context *_vg_context = 0; @@ -436,19 +437,24 @@ void vg_prepare_blend_surface(struct vg_context *ctx) { struct pipe_surface *dest_surface = NULL; struct pipe_context *pipe = ctx->pipe; + struct pipe_sampler_view *view; + struct pipe_sampler_view view_templ; struct st_framebuffer *stfb = ctx->draw_buffer; struct st_renderbuffer *strb = stfb->strb; /* first finish all pending rendering */ vgFinish(); + u_sampler_view_default_template(&view_templ, strb->texture, strb->texture->format); + view = pipe->create_sampler_view(pipe, strb->texture, &view_templ); + dest_surface = pipe->screen->get_tex_surface(pipe->screen, - stfb->blend_texture, + stfb->blend_texture_view->texture, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE); /* flip it, because we want to use it as a sampler */ util_blit_pixels_tex(ctx->blit, - strb->texture, + view, 0, strb->height, strb->width, 0, dest_surface, @@ -461,6 +467,8 @@ void vg_prepare_blend_surface(struct vg_context *ctx) /* make sure it's complete */ vgFinish(); + + pipe_sampler_view_reference(&view, NULL); } @@ -477,13 +485,13 @@ void vg_prepare_blend_surface_from_mask(struct vg_context *ctx) vgFinish(); dest_surface = pipe->screen->get_tex_surface(pipe->screen, - stfb->blend_texture, + stfb->blend_texture_view->texture, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE); /* flip it, because we want to use it as a sampler */ util_blit_pixels_tex(ctx->blit, - stfb->alpha_mask, + stfb->alpha_mask_view, 0, strb->height, strb->width, 0, dest_surface, diff --git a/src/gallium/state_trackers/vega/vg_context.h b/src/gallium/state_trackers/vega/vg_context.h index 17c7d2ad1c5..c9e36d7d767 100644 --- a/src/gallium/state_trackers/vega/vg_context.h +++ b/src/gallium/state_trackers/vega/vg_context.h @@ -55,9 +55,10 @@ struct st_framebuffer { struct st_renderbuffer *strb; struct st_renderbuffer *dsrb; - struct pipe_texture *alpha_mask; + struct pipe_sampler_view *alpha_mask_view; + + struct pipe_sampler_view *blend_texture_view; - struct pipe_texture *blend_texture; struct st_framebuffer_iface *iface; enum st_attachment_type strb_att; diff --git a/src/gallium/state_trackers/vega/vg_tracker.c b/src/gallium/state_trackers/vega/vg_tracker.c index ea5c2ce41f6..f438e34087e 100644 --- a/src/gallium/state_trackers/vega/vg_tracker.c +++ b/src/gallium/state_trackers/vega/vg_tracker.c @@ -32,6 +32,7 @@ #include "util/u_inlines.h" #include "pipe/p_screen.h" #include "util/u_format.h" +#include "util/u_sampler.h" #include "util/u_memory.h" #include "util/u_math.h" #include "util/u_rect.h" @@ -41,7 +42,7 @@ PUBLIC const int st_api_OpenVG = 1; static struct pipe_texture * create_texture(struct pipe_context *pipe, enum pipe_format format, - VGint width, VGint height) + VGint width, VGint height) { struct pipe_texture templ; @@ -71,6 +72,27 @@ create_texture(struct pipe_context *pipe, enum pipe_format format, return pipe->screen->texture_create(pipe->screen, &templ); } +static struct pipe_sampler_view * +create_tex_and_view(struct pipe_context *pipe, enum pipe_format format, + VGint width, VGint height) +{ + struct pipe_texture *texture; + struct pipe_sampler_view view_templ; + struct pipe_sampler_view *view; + + texture = create_texture(pipe, format, width, height); + + if (!texture) + return NULL; + + u_sampler_view_default_template(&view_templ, texture, texture->format); + view = pipe->create_sampler_view(pipe, texture, &view_templ); + /* want the texture to go away if the view is freed */ + pipe_texture_reference(&texture, NULL); + + return view; +} + /** * Allocate a renderbuffer for a an on-screen window (not a user-created * renderbuffer). The window system code determines the format. @@ -115,8 +137,8 @@ st_renderbuffer_alloc_storage(struct vg_context * ctx, surface_usage = (PIPE_BUFFER_USAGE_GPU_READ | PIPE_BUFFER_USAGE_GPU_WRITE); - strb->texture = create_texture(pipe, strb->format, - width, height); + strb->texture = create_texture(pipe, strb->format, width, height); + if (!strb->texture) return FALSE; @@ -191,7 +213,7 @@ struct st_framebuffer * st_create_framebuffer(const void *visual, /*### currently we always allocate it but it's possible it's not necessary if EGL_ALPHA_MASK_SIZE was 0 */ - stfb->alpha_mask = 0; + stfb->alpha_mask_view = NULL; stfb->width = width; stfb->height = height; @@ -206,19 +228,19 @@ static void setup_new_alpha_mask(struct vg_context *ctx, uint width, uint height) { struct pipe_context *pipe = ctx->pipe; - struct pipe_texture *old_texture = stfb->alpha_mask; + struct pipe_sampler_view *old_sampler_view = stfb->alpha_mask_view; /* we use PIPE_FORMAT_B8G8R8A8_UNORM because we want to render to this texture and use it as a sampler, so while this wastes some space it makes both of those a lot simpler */ - stfb->alpha_mask = - create_texture(pipe, PIPE_FORMAT_B8G8R8A8_UNORM, width, height); + stfb->alpha_mask_view = + create_tex_and_view(pipe, PIPE_FORMAT_B8G8R8A8_UNORM, width, height); - if (!stfb->alpha_mask) { - if (old_texture) - pipe_texture_reference(&old_texture, NULL); + if (!stfb->alpha_mask_view) { + if (old_sampler_view) + pipe_sampler_view_reference(&old_sampler_view, NULL); return; } @@ -228,15 +250,15 @@ static void setup_new_alpha_mask(struct vg_context *ctx, mask_fill(0, 0, width, height, 1.f); /* if we had an old surface copy it over */ - if (old_texture) { + if (old_sampler_view) { struct pipe_surface *surface = pipe->screen->get_tex_surface( pipe->screen, - stfb->alpha_mask, + stfb->alpha_mask_view->texture, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE); struct pipe_surface *old_surface = pipe->screen->get_tex_surface( pipe->screen, - old_texture, + old_sampler_view->texture, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_READ); if (pipe->surface_copy) { @@ -264,8 +286,8 @@ static void setup_new_alpha_mask(struct vg_context *ctx, /* Free the old texture */ - if (old_texture) - pipe_texture_reference(&old_texture, NULL); + if (old_sampler_view) + pipe_sampler_view_reference(&old_sampler_view, NULL); } void st_resize_framebuffer(struct st_framebuffer *stfb, @@ -326,9 +348,9 @@ void st_resize_framebuffer(struct st_framebuffer *stfb, setup_new_alpha_mask(ctx, stfb, width, height); - pipe_texture_reference( &stfb->blend_texture, NULL ); - stfb->blend_texture = create_texture(ctx->pipe, PIPE_FORMAT_B8G8R8A8_UNORM, - width, height); + pipe_sampler_view_reference( &stfb->blend_texture_view, NULL ); + stfb->blend_texture_view = create_tex_and_view(ctx->pipe, PIPE_FORMAT_B8G8R8A8_UNORM, + width, height); } void st_set_framebuffer_surface(struct st_framebuffer *stfb, -- cgit v1.2.3 From 3b9555094d128052bdaf9957fe9062b35f7f5392 Mon Sep 17 00:00:00 2001 From: Roland Scheidegger Date: Fri, 19 Mar 2010 16:30:47 +0100 Subject: cso: remove cso_set/save/restore_sampler_textures no longer used after all statetrackers have been converted. --- src/gallium/auxiliary/cso_cache/cso_context.c | 68 --------------------------- src/gallium/auxiliary/cso_cache/cso_context.h | 8 ---- 2 files changed, 76 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/auxiliary/cso_cache/cso_context.c b/src/gallium/auxiliary/cso_cache/cso_context.c index 4ed9e09c529..d6f8dd34bfa 100644 --- a/src/gallium/auxiliary/cso_cache/cso_context.c +++ b/src/gallium/auxiliary/cso_cache/cso_context.c @@ -618,74 +618,6 @@ cso_restore_vertex_samplers(struct cso_context *ctx) } -enum pipe_error cso_set_sampler_textures( struct cso_context *ctx, - uint count, - struct pipe_texture **textures ) -{ - uint i; - - ctx->nr_fragment_sampler_views = count; - - for (i = 0; i < count; i++) { - struct pipe_sampler_view templ, *view; - - u_sampler_view_default_template(&templ, - textures[i], - textures[i]->format); - - view = ctx->pipe->create_sampler_view(ctx->pipe, - textures[i], - &templ); - - pipe_sampler_view_reference(&ctx->fragment_sampler_views[i], view); - } - for ( ; i < PIPE_MAX_SAMPLERS; i++) { - pipe_sampler_view_reference(&ctx->fragment_sampler_views[i], NULL); - } - - ctx->pipe->set_fragment_sampler_views(ctx->pipe, - count, - ctx->fragment_sampler_views); - - return PIPE_OK; -} - -void cso_save_sampler_textures( struct cso_context *ctx ) -{ - uint i; - - ctx->nr_fragment_sampler_views_saved = ctx->nr_fragment_sampler_views; - for (i = 0; i < ctx->nr_fragment_sampler_views; i++) { - assert(!ctx->fragment_sampler_views_saved[i]); - - pipe_sampler_view_reference(&ctx->fragment_sampler_views_saved[i], - ctx->fragment_sampler_views[i]); - } -} - -void cso_restore_sampler_textures( struct cso_context *ctx ) -{ - uint i; - - ctx->nr_fragment_sampler_views = ctx->nr_fragment_sampler_views_saved; - - for (i = 0; i < ctx->nr_fragment_sampler_views; i++) { - pipe_sampler_view_reference(&ctx->fragment_sampler_views[i], NULL); - ctx->fragment_sampler_views[i] = ctx->fragment_sampler_views_saved[i]; - ctx->fragment_sampler_views_saved[i] = NULL; - } - for ( ; i < PIPE_MAX_SAMPLERS; i++) { - pipe_sampler_view_reference(&ctx->fragment_sampler_views[i], NULL); - } - - ctx->pipe->set_fragment_sampler_views(ctx->pipe, - ctx->nr_fragment_sampler_views, - ctx->fragment_sampler_views); - - ctx->nr_fragment_sampler_views_saved = 0; -} - - enum pipe_error cso_set_depth_stencil_alpha(struct cso_context *ctx, const struct pipe_depth_stencil_alpha_state *templ) { diff --git a/src/gallium/auxiliary/cso_cache/cso_context.h b/src/gallium/auxiliary/cso_cache/cso_context.h index a24077e009c..d6bcb1fe8f7 100644 --- a/src/gallium/auxiliary/cso_cache/cso_context.h +++ b/src/gallium/auxiliary/cso_cache/cso_context.h @@ -103,14 +103,6 @@ void cso_single_vertex_sampler_done(struct cso_context *cso); - -enum pipe_error cso_set_sampler_textures( struct cso_context *cso, - uint count, - struct pipe_texture **textures ); -void cso_save_sampler_textures( struct cso_context *cso ); -void cso_restore_sampler_textures( struct cso_context *cso ); - - enum pipe_error cso_set_vertex_elements(struct cso_context *ctx, unsigned count, const struct pipe_vertex_element *states); -- cgit v1.2.3 From 05c03c6a1bcfb8ad77d3025f166f02ddaa741aa2 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Fri, 19 Mar 2010 10:02:16 -0600 Subject: gallivm: simplify and clean-up Z/stencil bit mask/shift code Refactor the code into two helper functions which compute the bit mask and shift terms for Z and stencil. Plus add a bunch of new comments to explain everything. --- src/gallium/auxiliary/gallivm/lp_bld_depth.c | 247 +++++++++++++++++---------- 1 file changed, 160 insertions(+), 87 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/auxiliary/gallivm/lp_bld_depth.c b/src/gallium/auxiliary/gallivm/lp_bld_depth.c index 5b5ae7b5ea8..4ce1a27a061 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_depth.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_depth.c @@ -368,6 +368,83 @@ lp_depth_type(const struct util_format_description *format_desc, } +/** + * Compute bitmask and bit shift to apply to the incoming fragment Z values + * and the Z buffer values needed before doing the Z comparison. + * + * Note that we leave the Z bits in the position that we find them + * in the Z buffer (typically 0xffffff00 or 0x00ffffff). That lets us + * get by with fewer bit twiddling steps. + */ +static boolean +get_z_shift_and_mask(const struct util_format_description *format_desc, + unsigned *shift, unsigned *mask) +{ + const unsigned total_bits = format_desc->block.bits; + unsigned z_swizzle; + int chan; + unsigned padding_left, padding_right; + + assert(format_desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS); + assert(format_desc->block.width == 1); + assert(format_desc->block.height == 1); + + z_swizzle = format_desc->swizzle[0]; + + if (z_swizzle == UTIL_FORMAT_SWIZZLE_NONE) + return FALSE; + + padding_right = 0; + for (chan = 0; chan < z_swizzle; ++chan) + padding_right += format_desc->channel[chan].size; + + padding_left = + total_bits - (padding_right + format_desc->channel[z_swizzle].size); + + if (padding_left || padding_right) { + unsigned long long mask_left = (1ULL << (total_bits - padding_left)) - 1; + unsigned long long mask_right = (1ULL << (padding_right)) - 1; + *mask = mask_left ^ mask_right; + } + else { + *mask = 0xffffffff; + } + + *shift = padding_left; + + return TRUE; +} + + +/** + * Compute bitmask and bit shift to apply to the framebuffer pixel values + * to put the stencil bits in the least significant position. + * (i.e. 0x000000ff) + */ +static boolean +get_s_shift_and_mask(const struct util_format_description *format_desc, + unsigned *shift, unsigned *mask) +{ + unsigned s_swizzle; + int chan, sz; + + s_swizzle = format_desc->swizzle[1]; + + if (s_swizzle == UTIL_FORMAT_SWIZZLE_NONE) + return FALSE; + + *shift = 0; + for (chan = 0; chan < s_swizzle; chan++) + *shift += format_desc->channel[chan].size; + + sz = format_desc->channel[s_swizzle].size; + *mask = (1U << sz) - 1U; + + return TRUE; +} + + + /** * Generate code for performing depth and/or stencil tests. * We operate on a vector of values (typically a 2x2 quad). @@ -397,46 +474,51 @@ lp_build_depth_stencil_test(LLVMBuilderRef builder, struct lp_build_context bld; struct lp_build_context sbld; struct lp_type s_type; - unsigned z_swizzle, s_swizzle; LLVMValueRef zs_dst, z_dst = NULL; LLVMValueRef stencil_vals = NULL; - LLVMValueRef z_bitmask = NULL, s_bitmask = NULL, s_shift = NULL; + LLVMValueRef z_bitmask = NULL, stencil_shift = NULL; LLVMValueRef z_pass = NULL, s_pass_mask = NULL; LLVMValueRef orig_mask = mask->value; - assert(depth->enabled || stencil[0].enabled); + /* Sanity checking */ + { + const unsigned z_swizzle = format_desc->swizzle[0]; + const unsigned s_swizzle = format_desc->swizzle[1]; - assert(format_desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS); - assert(format_desc->block.width == 1); - assert(format_desc->block.height == 1); + assert(z_swizzle != UTIL_FORMAT_SWIZZLE_NONE || + s_swizzle != UTIL_FORMAT_SWIZZLE_NONE); - z_swizzle = format_desc->swizzle[0]; - s_swizzle = format_desc->swizzle[1]; + assert(depth->enabled || stencil[0].enabled); - assert(z_swizzle != UTIL_FORMAT_SWIZZLE_NONE || - s_swizzle != UTIL_FORMAT_SWIZZLE_NONE); + assert(format_desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS); + assert(format_desc->block.width == 1); + assert(format_desc->block.height == 1); - if (stencil[0].enabled) { - assert(format_desc->format == PIPE_FORMAT_Z24S8_UNORM || - format_desc->format == PIPE_FORMAT_S8Z24_UNORM); - } + if (stencil[0].enabled) { + assert(format_desc->format == PIPE_FORMAT_Z24S8_UNORM || + format_desc->format == PIPE_FORMAT_S8Z24_UNORM); + } - /* Sanity checking */ - assert(z_swizzle < 4); - assert(format_desc->block.bits == type.width); - if(type.floating) { - assert(z_swizzle == 0); - assert(format_desc->channel[z_swizzle].type == UTIL_FORMAT_TYPE_FLOAT); - assert(format_desc->channel[z_swizzle].size == format_desc->block.bits); - } - else { - assert(format_desc->channel[z_swizzle].type == UTIL_FORMAT_TYPE_UNSIGNED); - assert(format_desc->channel[z_swizzle].normalized); - assert(!type.fixed); - assert(!type.sign); - assert(type.norm); + assert(z_swizzle < 4); + assert(format_desc->block.bits == type.width); + if (type.floating) { + assert(z_swizzle == 0); + assert(format_desc->channel[z_swizzle].type == + UTIL_FORMAT_TYPE_FLOAT); + assert(format_desc->channel[z_swizzle].size == + format_desc->block.bits); + } + else { + assert(format_desc->channel[z_swizzle].type == + UTIL_FORMAT_TYPE_UNSIGNED); + assert(format_desc->channel[z_swizzle].normalized); + assert(!type.fixed); + assert(!type.sign); + assert(type.norm); + } } + /* Setup build context for Z vals */ lp_build_context_init(&bld, builder, type); @@ -449,71 +531,57 @@ lp_build_depth_stencil_test(LLVMBuilderRef builder, lp_build_name(zs_dst, "zsbufval"); - /* Align the source depth bits with the destination's, and mask out any - * stencil or padding bits from both */ - if(format_desc->channel[z_swizzle].size == format_desc->block.bits) { - assert(z_swizzle == 0); - z_dst = zs_dst; - } - else { - /* shift/mask bits to right-justify the Z bits */ - unsigned padding_left; - unsigned padding_right; - unsigned chan; - - assert(format_desc->layout == UTIL_FORMAT_LAYOUT_PLAIN); - assert(format_desc->channel[z_swizzle].type == UTIL_FORMAT_TYPE_UNSIGNED); - assert(format_desc->channel[z_swizzle].size <= format_desc->block.bits); - assert(format_desc->channel[z_swizzle].normalized); - - padding_right = 0; - for(chan = 0; chan < z_swizzle; ++chan) - padding_right += format_desc->channel[chan].size; - padding_left = format_desc->block.bits - - (padding_right + format_desc->channel[z_swizzle].size); - - if(padding_left || padding_right) { - const unsigned long long mask_left = (1ULL << (format_desc->block.bits - padding_left)) - 1; - const unsigned long long mask_right = (1ULL << (padding_right)) - 1; - z_bitmask = lp_build_const_int_vec(type, mask_left ^ mask_right); - } - /* If PIPE_FORMAT_Z24S8, we'll shift zs >> 24 to position stencil_vals */ - if (format_desc->format == PIPE_FORMAT_Z24S8_UNORM) - s_shift = lp_build_const_int_vec(type, 24); - else - s_shift = lp_build_const_int_vec(type, 0); - - s_bitmask = lp_build_const_int_vec(s_type, 0xff); - - stencil_vals = LLVMBuildLShr(builder, zs_dst, s_shift, ""); - stencil_vals = LLVMBuildAnd(builder, stencil_vals, s_bitmask, ""); + /* Compute and apply the Z/stencil bitmasks and shifts. + */ + { + unsigned z_shift, z_mask; + unsigned s_shift, s_mask; + + if (get_z_shift_and_mask(format_desc, &z_shift, &z_mask)) { + if (z_shift) { + LLVMValueRef shift = lp_build_const_int_vec(type, z_shift); + z_src = LLVMBuildLShr(builder, z_src, shift, ""); + } + + if (z_mask != 0xffffffff) { + LLVMValueRef mask = lp_build_const_int_vec(type, z_mask); + z_src = LLVMBuildAnd(builder, z_src, mask, ""); + z_dst = LLVMBuildAnd(builder, zs_dst, mask, ""); + z_bitmask = mask; /* used below */ + } + else { + z_dst = zs_dst; + } + + lp_build_name(z_dst, "zsbuf.z"); + } - if(padding_left) - z_src = LLVMBuildLShr(builder, z_src, - lp_build_const_int_vec(type, padding_left), ""); - if(padding_right) - z_src = LLVMBuildAnd(builder, z_src, z_bitmask, ""); - if(padding_left || padding_right) - z_dst = LLVMBuildAnd(builder, zs_dst, z_bitmask, ""); - else - z_dst = zs_dst; + if (get_s_shift_and_mask(format_desc, &s_shift, &s_mask)) { + if (s_shift) { + LLVMValueRef shift = lp_build_const_int_vec(type, s_shift); + stencil_vals = LLVMBuildLShr(builder, zs_dst, shift, ""); + stencil_shift = shift; /* used below */ + } + else { + stencil_vals = zs_dst; + } + + if (s_mask != 0xffffffff) { + LLVMValueRef mask = lp_build_const_int_vec(type, s_mask); + stencil_vals = LLVMBuildAnd(builder, stencil_vals, mask, ""); + } + + lp_build_name(stencil_vals, "stencil"); + } } - lp_build_name(z_dst, "zsbuf.z"); - - /* - printf("build depth %d stencil %d\n", - depth->enabled, - stencil[0].enabled); - */ if (stencil[0].enabled) { /* convert scalar stencil refs into vectors */ stencil_refs[0] = lp_build_broadcast_scalar(&bld, stencil_refs[0]); stencil_refs[1] = lp_build_broadcast_scalar(&bld, stencil_refs[1]); - s_pass_mask = lp_build_stencil_test(&sbld, stencil, stencil_refs, stencil_vals, face); @@ -569,12 +637,17 @@ lp_build_depth_stencil_test(LLVMBuilderRef builder, * passed the stencil test. */ s_pass_mask = LLVMBuildAnd(bld.builder, orig_mask, s_pass_mask, ""); - stencil_vals = lp_build_stencil_op(&sbld, stencil, Z_PASS_OP, stencil_refs, - stencil_vals, s_pass_mask, face); + stencil_vals = lp_build_stencil_op(&sbld, stencil, Z_PASS_OP, + stencil_refs, stencil_vals, + s_pass_mask, face); } - if (stencil_vals) - stencil_vals = LLVMBuildShl(bld.builder, stencil_vals, s_shift, ""); + /* The Z bits are already in the right place but we may need to shift the + * stencil bits before ORing Z with Stencil to make the final pixel value. + */ + if (stencil_vals && stencil_shift) + stencil_vals = LLVMBuildShl(bld.builder, stencil_vals, + stencil_shift, ""); /* Finally, merge/store the z/stencil values */ if ((depth->enabled && depth->writemask) || -- cgit v1.2.3 From 7e6e049bb769012ef93d373d8a95a727120d2bc7 Mon Sep 17 00:00:00 2001 From: Marek Olšák Date: Tue, 9 Mar 2010 02:10:36 +0100 Subject: r300g: remove hacks from translate_vertex_data_swizzle Fixing RGBA 4ub vertex colors. --- src/gallium/drivers/r300/r300_state_inlines.h | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/r300/r300_state_inlines.h b/src/gallium/drivers/r300/r300_state_inlines.h index 2f3a56e1fbc..af7827820cc 100644 --- a/src/gallium/drivers/r300/r300_state_inlines.h +++ b/src/gallium/drivers/r300/r300_state_inlines.h @@ -453,7 +453,6 @@ r300_translate_vertex_data_type(enum pipe_format format) { static INLINE uint16_t r300_translate_vertex_data_swizzle(enum pipe_format format) { const struct util_format_description *desc = util_format_description(format); - unsigned swizzle[4], i; assert(format); @@ -463,25 +462,10 @@ r300_translate_vertex_data_swizzle(enum pipe_format format) { return 0; } - /* Swizzles for 8bits formats are in the reversed order, not sure why. */ - if (desc->channel[0].size == 8) { - for (i = 0; i < 4; i++) { - if (desc->swizzle[i] <= 3) { - swizzle[i] = 3 - desc->swizzle[i]; - } else { - swizzle[i] = desc->swizzle[i]; - } - } - } else { - for (i = 0; i < 4; i++) { - swizzle[i] = desc->swizzle[i]; - } - } - - return ((swizzle[0] << R300_SWIZZLE_SELECT_X_SHIFT) | - (swizzle[1] << R300_SWIZZLE_SELECT_Y_SHIFT) | - (swizzle[2] << R300_SWIZZLE_SELECT_Z_SHIFT) | - (swizzle[3] << R300_SWIZZLE_SELECT_W_SHIFT) | + return ((desc->swizzle[0] << R300_SWIZZLE_SELECT_X_SHIFT) | + (desc->swizzle[1] << R300_SWIZZLE_SELECT_Y_SHIFT) | + (desc->swizzle[2] << R300_SWIZZLE_SELECT_Z_SHIFT) | + (desc->swizzle[3] << R300_SWIZZLE_SELECT_W_SHIFT) | (0xf << R300_WRITE_ENA_SHIFT)); } -- cgit v1.2.3 From 92827cd4511fabcaeb8abfdd11122e04502d5944 Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Fri, 19 Mar 2010 02:38:10 +0200 Subject: st/dri: fix bug in allocate_textures --- src/gallium/state_trackers/dri/dri1.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/dri/dri1.c b/src/gallium/state_trackers/dri/dri1.c index 41dba82d528..240bc69efd5 100644 --- a/src/gallium/state_trackers/dri/dri1.c +++ b/src/gallium/state_trackers/dri/dri1.c @@ -451,7 +451,7 @@ dri1_allocate_textures(struct dri_drawable *drawable, break; } - if (templ.format != PIPE_FORMAT_NONE) { + if (format != PIPE_FORMAT_NONE) { templ.format = format; templ.tex_usage = tex_usage; -- cgit v1.2.3 From fe5f070ef94219f12196bff6cb3274756ea03660 Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Fri, 19 Mar 2010 19:16:21 +0000 Subject: st/dri: fix bug in make_current --- src/gallium/state_trackers/dri/dri_context.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/dri/dri_context.c b/src/gallium/state_trackers/dri/dri_context.c index c1848b026cd..54568a8b220 100644 --- a/src/gallium/state_trackers/dri/dri_context.c +++ b/src/gallium/state_trackers/dri/dri_context.c @@ -149,7 +149,7 @@ dri_make_current(__DRIcontext * cPriv, } if (ctx->rPriv != driReadPriv) { ctx->rPriv = driReadPriv; - draw->texture_stamp = driReadPriv->lastStamp - 1; + read->texture_stamp = driReadPriv->lastStamp - 1; } stapi->make_current(stapi, ctx->st, draw->stfb, read->stfb); -- cgit v1.2.3 From 03f1896304da481bd054779a025a4509f7ea59af Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Sun, 21 Mar 2010 06:32:48 +1000 Subject: r300g: add buffer/texture referenced checks. I've no idea about the comments that were in there, just pass this down to the winsys. Signed-off-by: Dave Airlie --- src/gallium/drivers/r300/r300_context.c | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/r300/r300_context.c b/src/gallium/drivers/r300/r300_context.c index 210e31e69c7..a55d2db039f 100644 --- a/src/gallium/drivers/r300/r300_context.c +++ b/src/gallium/drivers/r300/r300_context.c @@ -72,29 +72,23 @@ static void r300_destroy_context(struct pipe_context* context) } static unsigned int -r300_is_texture_referenced(struct pipe_context *pipe, +r300_is_texture_referenced(struct pipe_context *context, struct pipe_texture *texture, unsigned face, unsigned level) { - return 0; + struct r300_context* r300 = r300_context(context); + struct r300_texture* tex = (struct r300_texture*)texture; + + return r300->rws->is_buffer_referenced(r300->rws, tex->buffer); } static unsigned int -r300_is_buffer_referenced(struct pipe_context *pipe, +r300_is_buffer_referenced(struct pipe_context *context, struct pipe_buffer *buf) { - /* This only checks to see whether actual hardware buffers are - * referenced. Since we use managed BOs and transfers, it's actually not - * possible for pipe_buffers to ever reference the actual hardware, so - * buffers are never referenced. - */ - - /* XXX: that doesn't make sense given that - * r300_is_texture_referenced is implemented on top of this - * function and hardware can certainly refer to textures - * directly... - */ - return 0; + struct r300_context* r300 = r300_context(context); + + return r300_buffer_is_referenced(r300, buf); } static void r300_flush_cb(void *data) -- cgit v1.2.3 From c2d17dce27d412012a3a45bbde954fb9374d5db9 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Sun, 21 Mar 2010 06:34:11 +1000 Subject: r300g: winsys fix tiling change flushes. If we change the tiling on a buffer we need to flush it, the old radeon_buffer.c code had this but it crossed streams when I ported to radeon_drm_buffer.c and I missed it. Should fix some piglit regressions. Signed-off-by: Dave Airlie --- src/gallium/winsys/drm/radeon/core/radeon_drm_buffer.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/winsys/drm/radeon/core/radeon_drm_buffer.c b/src/gallium/winsys/drm/radeon/core/radeon_drm_buffer.c index cc56a2bb8fd..73472aabc5e 100644 --- a/src/gallium/winsys/drm/radeon/core/radeon_drm_buffer.c +++ b/src/gallium/winsys/drm/radeon/core/radeon_drm_buffer.c @@ -306,13 +306,21 @@ boolean radeon_drm_bufmgr_get_handle(struct pb_buffer *_buf, void radeon_drm_bufmgr_set_tiling(struct pb_buffer *_buf, boolean microtiled, boolean macrotiled, uint32_t pitch) { struct radeon_drm_buffer *buf = get_drm_buffer(_buf); - uint32_t flags = 0; - + uint32_t flags = 0, old_flags, old_pitch; if (microtiled) flags |= RADEON_BO_FLAGS_MICRO_TILE; if (macrotiled) flags |= RADEON_BO_FLAGS_MACRO_TILE; + radeon_bo_get_tiling(buf->bo, &old_flags, &old_pitch); + + if (flags != old_flags || pitch != old_pitch) { + /* Tiling determines how DRM treats the buffer data. + * We must flush CS when changing it if the buffer is referenced. */ + if (radeon_bo_is_referenced_by_cs(buf->bo, buf->mgr->rws->cs)) { + buf->mgr->rws->flush_cb(buf->mgr->rws->flush_data); + } + } radeon_bo_set_tiling(buf->bo, flags, pitch); } -- cgit v1.2.3 From 20dedcca3ca5bfeaaa275bec8a14ca8c69615f6a Mon Sep 17 00:00:00 2001 From: Corbin Simpson Date: Sat, 20 Mar 2010 16:14:20 -0700 Subject: radeong: Test the BO ptr for NULL instead of using a bool. Slight memory savings, but more importantly also avoids a potential NULL dereference. --- src/gallium/winsys/drm/radeon/core/radeon_drm_buffer.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/winsys/drm/radeon/core/radeon_drm_buffer.c b/src/gallium/winsys/drm/radeon/core/radeon_drm_buffer.c index 73472aabc5e..2f7456e12dd 100644 --- a/src/gallium/winsys/drm/radeon/core/radeon_drm_buffer.c +++ b/src/gallium/winsys/drm/radeon/core/radeon_drm_buffer.c @@ -23,7 +23,6 @@ struct radeon_drm_buffer { boolean flinked; uint32_t flink; - boolean mapped; struct radeon_drm_buffer *next, *prev; }; @@ -56,10 +55,10 @@ radeon_drm_buffer_destroy(struct pb_buffer *_buf) { struct radeon_drm_buffer *buf = radeon_drm_buffer(_buf); - if (buf->mapped) { + if (buf->bo->ptr != NULL) { remove_from_list(buf); radeon_bo_unmap(buf->bo); - buf->mapped = false; + buf->bo->ptr = NULL; } radeon_bo_unref(buf->bo); @@ -73,7 +72,7 @@ radeon_drm_buffer_map(struct pb_buffer *_buf, struct radeon_drm_buffer *buf = radeon_drm_buffer(_buf); int write; - if (buf->mapped) + if (buf->bo->ptr != NULL) return buf->bo->ptr; if (flags & PIPE_BUFFER_USAGE_DONTBLOCK) { @@ -95,7 +94,6 @@ radeon_drm_buffer_map(struct pb_buffer *_buf, if (radeon_bo_map(buf->bo, write)) { return NULL; } - buf->mapped = true; insert_at_tail(&buf->mgr->buffer_map_list, buf); return buf->bo->ptr; } @@ -365,12 +363,10 @@ void radeon_drm_bufmgr_flush_maps(struct pb_manager *_mgr) struct radeon_drm_buffer *rpb, *t_rpb; foreach_s(rpb, t_rpb, &mgr->buffer_map_list) { - rpb->mapped = 0; radeon_bo_unmap(rpb->bo); + rpb->bo->ptr = NULL; remove_from_list(rpb); } make_empty_list(&mgr->buffer_map_list); - - } -- cgit v1.2.3 From 7c8221b46008cd4f217d3ddab59dcc4c488a54b3 Mon Sep 17 00:00:00 2001 From: Corbin Simpson Date: Sat, 20 Mar 2010 16:15:36 -0700 Subject: radeong: Use TRUE and FALSE. --- src/gallium/winsys/drm/radeon/core/radeon_drm_buffer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/winsys/drm/radeon/core/radeon_drm_buffer.c b/src/gallium/winsys/drm/radeon/core/radeon_drm_buffer.c index 2f7456e12dd..2472b6bf952 100644 --- a/src/gallium/winsys/drm/radeon/core/radeon_drm_buffer.c +++ b/src/gallium/winsys/drm/radeon/core/radeon_drm_buffer.c @@ -287,7 +287,7 @@ boolean radeon_drm_bufmgr_get_handle(struct pb_buffer *_buf, retval = ioctl(fd, DRM_IOCTL_GEM_FLINK, &flink); if (retval) { - return false; + return FALSE; } buf->flinked = TRUE; @@ -329,7 +329,7 @@ boolean radeon_drm_bufmgr_add_buffer(struct pb_buffer *_buf, struct radeon_drm_buffer *buf = get_drm_buffer(_buf); radeon_cs_space_add_persistent_bo(buf->mgr->rws->cs, buf->bo, rd, wd); - return true; + return TRUE; } void radeon_drm_bufmgr_write_reloc(struct pb_buffer *_buf, -- cgit v1.2.3 From 4711aa089ec7af70bb9118ad8d7830e475805297 Mon Sep 17 00:00:00 2001 From: Corbin Simpson Date: Sat, 20 Mar 2010 17:16:46 -0700 Subject: r300g: Correctly hax max_index on pipe_vertex_buffers. Still not happy with this, but at least things seem to work. --- src/gallium/drivers/r300/r300_render.c | 2 +- src/gallium/drivers/r300/r300_state.c | 38 ++++++++++++++++++++++++---------- 2 files changed, 28 insertions(+), 12 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/r300/r300_render.c b/src/gallium/drivers/r300/r300_render.c index 47100c83b0b..40c1a420428 100644 --- a/src/gallium/drivers/r300/r300_render.c +++ b/src/gallium/drivers/r300/r300_render.c @@ -307,7 +307,7 @@ static void r300_emit_draw_elements(struct r300_context *r300, assert((start * indexSize) % 4 == 0); assert(count < (1 << 24)); - maxIndex = MIN3(maxIndex, r300->vertex_buffer_max_index, count - minIndex); + maxIndex = MIN2(maxIndex, r300->vertex_buffer_max_index); DBG(r300, DBG_DRAW, "r300: Indexbuf of %u indices, min %u max %u\n", count, minIndex, maxIndex); diff --git a/src/gallium/drivers/r300/r300_state.c b/src/gallium/drivers/r300/r300_state.c index bdfe74ed2a0..6328374e301 100644 --- a/src/gallium/drivers/r300/r300_state.c +++ b/src/gallium/drivers/r300/r300_state.c @@ -1109,26 +1109,42 @@ static void r300_set_vertex_buffers(struct pipe_context* pipe, const struct pipe_vertex_buffer* buffers) { struct r300_context* r300 = r300_context(pipe); - int i; - unsigned max_index = (1 << 24) - 1; - boolean any_user_buffer = false; + struct pipe_vertex_buffer *vbo; + unsigned i, max_index = (1 << 24) - 1; + boolean any_user_buffer = FALSE; if (count == r300->vertex_buffer_count && - memcmp(r300->vertex_buffer, buffers, count * sizeof(buffers[0])) == 0) + memcmp(r300->vertex_buffer, buffers, + sizeof(struct pipe_vertex_buffer) * count) == 0) { return; + } for (i = 0; i < count; i++) { - pipe_buffer_reference(&r300->vertex_buffer[i].buffer, buffers[i].buffer); - if (r300_buffer_is_user_buffer(buffers[i].buffer)) - any_user_buffer = true; - max_index = MIN2(buffers[i].max_index, max_index); + /* Why, yes, I AM casting away constness. How did you know? */ + vbo = (struct pipe_vertex_buffer*)&buffers[i]; + + /* Reference our buffer. */ + pipe_buffer_reference(&r300->vertex_buffer[i].buffer, vbo->buffer); + if (r300_buffer_is_user_buffer(vbo->buffer)) { + any_user_buffer = TRUE; + } + + if (vbo->max_index == ~0) { + /* Bogus value from broken state tracker; hax it. */ + vbo->max_index = + (vbo->buffer->size - vbo->buffer_offset) / vbo->stride; + } + + max_index = MIN2(vbo->max_index, max_index); } - for ( ; i < r300->vertex_buffer_count; i++) - pipe_buffer_reference(&r300->vertex_buffer[i].buffer, NULL); + for (; i < r300->vertex_buffer_count; i++) { + /* Dereference any old buffers. */ + pipe_buffer_reference(&r300->vertex_buffer[i].buffer, NULL); + } memcpy(r300->vertex_buffer, buffers, - sizeof(struct pipe_vertex_buffer) * count); + sizeof(struct pipe_vertex_buffer) * count); r300->vertex_buffer_count = count; r300->vertex_buffer_max_index = max_index; -- cgit v1.2.3 From 44cfc4ad740bfc89fc30e19fde4dcc130c605d02 Mon Sep 17 00:00:00 2001 From: Corbin Simpson Date: Sat, 20 Mar 2010 17:18:22 -0700 Subject: r300g: Bump immediate limits. Seems like a decent idea, especially since the big barrier now is getting the VBOs back from the VRAM boundary. --- src/gallium/drivers/r300/r300_render.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/r300/r300_render.c b/src/gallium/drivers/r300/r300_render.c index 40c1a420428..ff93a16a107 100644 --- a/src/gallium/drivers/r300/r300_render.c +++ b/src/gallium/drivers/r300/r300_render.c @@ -141,7 +141,7 @@ static boolean immd_is_good_idea(struct r300_context *r300, unsigned vertex_element_count = r300->velems->count; unsigned i, vbi; - if (count > 4) { + if (count > 10) { return FALSE; } @@ -155,8 +155,7 @@ static boolean immd_is_good_idea(struct r300_context *r300, if (!checked[vbi]) { vbuf = &r300->vertex_buffer[vbi]; - if (r300_buffer_is_referenced(r300, - vbuf->buffer)) { + if (r300_buffer_is_referenced(r300, vbuf->buffer)) { /* It's a very bad idea to map it... */ return FALSE; } -- cgit v1.2.3 From 951d89ae3a01b2d7f482b95da0a6d647c6855a68 Mon Sep 17 00:00:00 2001 From: Marek Olšák Date: Sat, 20 Mar 2010 21:26:19 +0100 Subject: r300g: skip null vertex buffers --- src/gallium/drivers/r300/r300_state.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/r300/r300_state.c b/src/gallium/drivers/r300/r300_state.c index 6328374e301..7ab76bfb8d3 100644 --- a/src/gallium/drivers/r300/r300_state.c +++ b/src/gallium/drivers/r300/r300_state.c @@ -1039,7 +1039,6 @@ r300_create_sampler_view(struct pipe_context *pipe, return view; } - static void r300_sampler_view_destroy(struct pipe_context *pipe, struct pipe_sampler_view *view) @@ -1125,6 +1124,12 @@ static void r300_set_vertex_buffers(struct pipe_context* pipe, /* Reference our buffer. */ pipe_buffer_reference(&r300->vertex_buffer[i].buffer, vbo->buffer); + + /* Skip NULL buffers */ + if (!buffers[i].buffer) { + continue; + } + if (r300_buffer_is_user_buffer(vbo->buffer)) { any_user_buffer = TRUE; } -- cgit v1.2.3 From 04de5f4b8bf68a4594ed7fef8348bcf068701ac8 Mon Sep 17 00:00:00 2001 From: Marek Olšák Date: Sat, 20 Mar 2010 22:14:59 +0100 Subject: r300g: split the vertex buffer alignment validation --- src/gallium/drivers/r300/r300_state.c | 51 ++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 22 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/r300/r300_state.c b/src/gallium/drivers/r300/r300_state.c index 7ab76bfb8d3..f396b42e950 100644 --- a/src/gallium/drivers/r300/r300_state.c +++ b/src/gallium/drivers/r300/r300_state.c @@ -1118,6 +1118,20 @@ static void r300_set_vertex_buffers(struct pipe_context* pipe, return; } + /* Check if the stride is aligned to the size of DWORD. */ + for (i = 0; i < count; i++) { + if (buffers[i].buffer) { + if (buffers[i].stride % 4 != 0) { + // XXX Shouldn't we align the buffer? + fprintf(stderr, "r300_set_vertex_buffers: " + "Unaligned buffer stride %i isn't supported.\n", + buffers[i].stride); + assert(0); + abort(); + } + } + } + for (i = 0; i < count; i++) { /* Why, yes, I AM casting away constness. How did you know? */ vbo = (struct pipe_vertex_buffer*)&buffers[i]; @@ -1161,22 +1175,6 @@ static void r300_set_vertex_buffers(struct pipe_context* pipe, } } -static boolean r300_validate_aos(struct r300_context *r300) -{ - struct pipe_vertex_buffer *vbuf = r300->vertex_buffer; - struct pipe_vertex_element *velem = r300->velems->velem; - int i; - - /* Check if formats and strides are aligned to the size of DWORD. */ - for (i = 0; i < r300->velems->count; i++) { - if (vbuf[velem[i].vertex_buffer_index].stride % 4 != 0 || - util_format_get_blocksize(velem[i].src_format) % 4 != 0) { - return FALSE; - } - } - return TRUE; -} - static void r300_draw_emit_attrib(struct r300_context* r300, enum attrib_emit emit, enum interp_mode interp, @@ -1346,6 +1344,7 @@ static void* r300_create_vertex_elements_state(struct pipe_context* pipe, struct r300_context *r300 = r300_context(pipe); struct r300_screen* r300screen = r300_screen(pipe->screen); struct r300_vertex_element_state *velems; + unsigned i, size; assert(count <= PIPE_MAX_ATTRIBS); velems = CALLOC_STRUCT(r300_vertex_element_state); @@ -1354,6 +1353,20 @@ static void* r300_create_vertex_elements_state(struct pipe_context* pipe, memcpy(velems->velem, attribs, sizeof(struct pipe_vertex_element) * count); if (r300screen->caps->has_tcl) { + /* Check if the format is aligned to the size of DWORD. */ + for (i = 0; i < count; i++) { + size = util_format_get_blocksize(attribs[i].src_format); + + if (size % 4 != 0) { + /* XXX Shouldn't we align the format? */ + fprintf(stderr, "r300_create_vertex_elements_state: " + "Unaligned format %s:%i isn't supported\n", + util_format_name(attribs[i].src_format), size); + assert(0); + abort(); + } + } + r300_vertex_psc(velems); } else { memset(&r300->vertex_info, 0, sizeof(struct vertex_info)); @@ -1382,12 +1395,6 @@ static void r300_bind_vertex_elements_state(struct pipe_context *pipe, draw_set_vertex_elements(r300->draw, velems->count, velems->velem); } - if (!r300_validate_aos(r300)) { - /* XXX We should fallback using draw. */ - assert(0); - abort(); - } - UPDATE_STATE(&velems->vertex_stream, r300->vertex_stream_state); r300->vertex_stream_state.size = (1 + velems->vertex_stream.count) * 2; } -- cgit v1.2.3 From 53ca4f8401f2fc552636d69f7d0dcfd7621769e3 Mon Sep 17 00:00:00 2001 From: Marek Olšák Date: Sun, 21 Mar 2010 04:39:33 +0100 Subject: r300g: fix misaligned generated offset for ubyte vertex indices --- src/gallium/drivers/r300/r300_render.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/r300/r300_render.c b/src/gallium/drivers/r300/r300_render.c index ff93a16a107..afd871ae302 100644 --- a/src/gallium/drivers/r300/r300_render.c +++ b/src/gallium/drivers/r300/r300_render.c @@ -353,6 +353,7 @@ static void r300_emit_draw_elements(struct r300_context *r300, static void r300_shorten_ubyte_elts(struct r300_context* r300, struct pipe_buffer** elts, + unsigned start, unsigned count) { struct pipe_screen* screen = r300->context.screen; @@ -370,6 +371,8 @@ static void r300_shorten_ubyte_elts(struct r300_context* r300, in_map = pipe_buffer_map(screen, *elts, PIPE_BUFFER_USAGE_CPU_READ); out_map = pipe_buffer_map(screen, new_elts, PIPE_BUFFER_USAGE_CPU_WRITE); + in_map += start; + for (i = 0; i < count; i++) { *out_map = (unsigned short)*in_map; in_map++; @@ -407,8 +410,9 @@ void r300_draw_range_elements(struct pipe_context* pipe, } if (indexSize == 1) { - r300_shorten_ubyte_elts(r300, &indexBuffer, count); + r300_shorten_ubyte_elts(r300, &indexBuffer, start, count); indexSize = 2; + start = 0; } r300_update_derived_state(r300); -- cgit v1.2.3 From 162bc831c93bf8632b25c11f116a1405b93a1704 Mon Sep 17 00:00:00 2001 From: Marek Olšák Date: Sun, 21 Mar 2010 04:49:35 +0100 Subject: r300g: align misaligned ushort vertex indices --- src/gallium/drivers/r300/r300_render.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/r300/r300_render.c b/src/gallium/drivers/r300/r300_render.c index afd871ae302..2fed263a7a9 100644 --- a/src/gallium/drivers/r300/r300_render.c +++ b/src/gallium/drivers/r300/r300_render.c @@ -303,7 +303,6 @@ static void r300_emit_draw_elements(struct r300_context *r300, #endif CS_LOCALS(r300); - assert((start * indexSize) % 4 == 0); assert(count < (1 << 24)); maxIndex = MIN2(maxIndex, r300->vertex_buffer_max_index); @@ -385,6 +384,32 @@ static void r300_shorten_ubyte_elts(struct r300_context* r300, *elts = new_elts; } +static void r300_align_ushort_elts(struct r300_context *r300, + struct pipe_buffer **elts, + unsigned start, unsigned count) +{ + struct pipe_screen* screen = r300->context.screen; + struct pipe_buffer* new_elts; + unsigned short *in_map; + unsigned short *out_map; + + new_elts = screen->buffer_create(screen, 32, + PIPE_BUFFER_USAGE_INDEX | + PIPE_BUFFER_USAGE_CPU_WRITE | + PIPE_BUFFER_USAGE_GPU_READ, + 2 * count); + + in_map = pipe_buffer_map(screen, *elts, PIPE_BUFFER_USAGE_CPU_READ); + out_map = pipe_buffer_map(screen, new_elts, PIPE_BUFFER_USAGE_CPU_WRITE); + + memcpy(out_map, in_map+start, 2 * count); + + pipe_buffer_unmap(screen, *elts); + pipe_buffer_unmap(screen, new_elts); + + *elts = new_elts; +} + /* This is the fast-path drawing & emission for HW TCL. */ void r300_draw_range_elements(struct pipe_context* pipe, struct pipe_buffer* indexBuffer, @@ -413,6 +438,9 @@ void r300_draw_range_elements(struct pipe_context* pipe, r300_shorten_ubyte_elts(r300, &indexBuffer, start, count); indexSize = 2; start = 0; + } else if (indexSize == 2 && start % 2 != 0) { + r300_align_ushort_elts(r300, &indexBuffer, start, count); + start = 0; } r300_update_derived_state(r300); -- cgit v1.2.3 From 0dab3189e1d100a9a2487f7aff45589b423c386c Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Sun, 21 Mar 2010 18:23:22 +1000 Subject: gallium: cached bufmgr add map busy check Suggested by Jose on the list, probably not perfect but will let me get past this for now, testing with a fenced bufmgr on top of this, was slower, Also this doesn't let you do the busy early exit optimisation either from what I can see. Signed-off-by: Dave Airlie --- src/gallium/auxiliary/pipebuffer/pb_bufmgr_cache.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/gallium') diff --git a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_cache.c b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_cache.c index 86f9266c95f..0f2ae05daed 100644 --- a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_cache.c +++ b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_cache.c @@ -227,6 +227,8 @@ pb_cache_is_buffer_compat(struct pb_cache_buffer *buf, pb_size size, const struct pb_desc *desc) { + void *map; + if(buf->base.base.size < size) return FALSE; @@ -239,6 +241,13 @@ pb_cache_is_buffer_compat(struct pb_cache_buffer *buf, if(!pb_check_usage(desc->usage, buf->base.base.usage)) return FALSE; + + map = pb_map(buf->buffer, PIPE_BUFFER_USAGE_DONTBLOCK); + if (!map) { + return FALSE; + } + + pb_unmap(buf->buffer); return TRUE; } -- cgit v1.2.3 From ff1c7baad241dd722341023806e00a07606de206 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Sun, 21 Mar 2010 18:25:31 +1000 Subject: r300g: add bufmgr cached for vertex/index buffers. This adds the cached bufmgr for vertex/index buffers on top of the kernel manager. Signed-off-by: Dave Airlie --- src/gallium/winsys/drm/radeon/core/radeon_drm_buffer.c | 9 ++++++--- src/gallium/winsys/drm/radeon/core/radeon_r300.c | 11 ++++++++++- src/gallium/winsys/drm/radeon/core/radeon_winsys.h | 2 ++ 3 files changed, 18 insertions(+), 4 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/winsys/drm/radeon/core/radeon_drm_buffer.c b/src/gallium/winsys/drm/radeon/core/radeon_drm_buffer.c index 2472b6bf952..1d29b0b727a 100644 --- a/src/gallium/winsys/drm/radeon/core/radeon_drm_buffer.c +++ b/src/gallium/winsys/drm/radeon/core/radeon_drm_buffer.c @@ -72,17 +72,20 @@ radeon_drm_buffer_map(struct pb_buffer *_buf, struct radeon_drm_buffer *buf = radeon_drm_buffer(_buf); int write; + if (flags & PIPE_BUFFER_USAGE_DONTBLOCK) { + if (radeon_bo_is_referenced_by_cs(buf->bo, buf->mgr->rws->cs)) + return NULL; + } + if (buf->bo->ptr != NULL) return buf->bo->ptr; - + if (flags & PIPE_BUFFER_USAGE_DONTBLOCK) { uint32_t domain; - if (radeon_bo_is_busy(buf->bo, &domain)) return NULL; } - if (radeon_bo_is_referenced_by_cs(buf->bo, buf->mgr->rws->cs)) { buf->mgr->rws->flush_cb(buf->mgr->rws->flush_data); } diff --git a/src/gallium/winsys/drm/radeon/core/radeon_r300.c b/src/gallium/winsys/drm/radeon/core/radeon_r300.c index 5b82a776a81..62d66d31dc1 100644 --- a/src/gallium/winsys/drm/radeon/core/radeon_r300.c +++ b/src/gallium/winsys/drm/radeon/core/radeon_r300.c @@ -44,6 +44,9 @@ radeon_r300_winsys_buffer_create(struct r300_winsys_screen *rws, if (usage & PIPE_BUFFER_USAGE_CONSTANT) provider = ws->mman; + else if ((usage & PIPE_BUFFER_USAGE_VERTEX) || + (usage & PIPE_BUFFER_USAGE_INDEX)) + provider = ws->cman; else provider = ws->kman; buffer = provider->create_buffer(provider, size, &desc); @@ -260,6 +263,7 @@ radeon_winsys_destroy(struct r300_winsys_screen *rws) struct radeon_libdrm_winsys *ws = (struct radeon_libdrm_winsys *)rws; radeon_cs_destroy(ws->cs); + ws->cman->destroy(ws->cman); ws->kman->destroy(ws->kman); ws->mman->destroy(ws->mman); @@ -281,6 +285,10 @@ radeon_setup_winsys(int fd, struct radeon_libdrm_winsys* ws) if (!ws->kman) goto fail; + ws->cman = pb_cache_manager_create(ws->kman, 100000); + if (!ws->cman) + goto fail; + ws->mman = pb_malloc_bufmgr_create(); if (!ws->mman) goto fail; @@ -325,7 +333,8 @@ fail: if (ws->bom) radeon_bo_manager_gem_dtor(ws->bom); - + if (ws->cman) + ws->cman->destroy(ws->cman); if (ws->kman) ws->kman->destroy(ws->kman); if (ws->mman) diff --git a/src/gallium/winsys/drm/radeon/core/radeon_winsys.h b/src/gallium/winsys/drm/radeon/core/radeon_winsys.h index 16cc701ad6f..ad7b976abd2 100644 --- a/src/gallium/winsys/drm/radeon/core/radeon_winsys.h +++ b/src/gallium/winsys/drm/radeon/core/radeon_winsys.h @@ -38,6 +38,8 @@ struct radeon_libdrm_winsys { struct pb_manager *kman; + struct pb_manager *cman; + struct pb_manager *mman; /* PCI ID */ -- cgit v1.2.3 From bb324182fc7cd9cfaa62ee44bdd9287f1ed2ac7a Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Sun, 21 Mar 2010 19:36:15 +1000 Subject: r300g: fix occlusion query hangs. Okay need to revist the whole OQ stuff anyways, glean test asserts which is never good. I'm liking the cached bufmgr restrictions less and less, I think I'll probably play with the fence and/or busy stuff ASAP and try and clean it up. Signed-off-by: Dave Airlie --- src/gallium/drivers/r300/r300_context.c | 2 +- src/gallium/winsys/drm/radeon/core/radeon_drm_buffer.c | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/r300/r300_context.c b/src/gallium/drivers/r300/r300_context.c index a55d2db039f..60b441176d9 100644 --- a/src/gallium/drivers/r300/r300_context.c +++ b/src/gallium/drivers/r300/r300_context.c @@ -200,7 +200,7 @@ struct pipe_context* r300_create_context(struct pipe_screen* screen, /* Open up the OQ BO. */ r300->oqbo = screen->buffer_create(screen, 4096, - PIPE_BUFFER_USAGE_VERTEX, 4096); + PIPE_BUFFER_USAGE_PIXEL, 4096); make_empty_list(&r300->query_list); r300_init_flush_functions(r300); diff --git a/src/gallium/winsys/drm/radeon/core/radeon_drm_buffer.c b/src/gallium/winsys/drm/radeon/core/radeon_drm_buffer.c index 1d29b0b727a..a8a7c45a96f 100644 --- a/src/gallium/winsys/drm/radeon/core/radeon_drm_buffer.c +++ b/src/gallium/winsys/drm/radeon/core/radeon_drm_buffer.c @@ -73,8 +73,10 @@ radeon_drm_buffer_map(struct pb_buffer *_buf, int write; if (flags & PIPE_BUFFER_USAGE_DONTBLOCK) { - if (radeon_bo_is_referenced_by_cs(buf->bo, buf->mgr->rws->cs)) - return NULL; + if ((_buf->base.usage & PIPE_BUFFER_USAGE_VERTEX) || + (_buf->base.usage & PIPE_BUFFER_USAGE_INDEX)) + if (radeon_bo_is_referenced_by_cs(buf->bo, buf->mgr->rws->cs)) + return NULL; } if (buf->bo->ptr != NULL) -- cgit v1.2.3 From 9ec29e31919e85f9230867f43841c0e74be930d3 Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Fri, 19 Mar 2010 02:38:10 +0200 Subject: Makefile.template: respect LIBRARY_DEFINES in mkdep --- src/gallium/Makefile.template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/gallium') diff --git a/src/gallium/Makefile.template b/src/gallium/Makefile.template index 91a9b54b362..7606a947e22 100644 --- a/src/gallium/Makefile.template +++ b/src/gallium/Makefile.template @@ -34,7 +34,7 @@ lib$(LIBNAME).a: $(OBJECTS) $(EXTRA_OBJECTS) Makefile $(TOP)/src/gallium/Makefil depend: $(C_SOURCES) $(CPP_SOURCES) $(ASM_SOURCES) $(SYMLINKS) $(GENERATED_SOURCES) rm -f depend touch depend - $(MKDEP) $(MKDEP_OPTIONS) $(INCLUDES) $(C_SOURCES) $(CPP_SOURCES) $(ASM_SOURCES) $(GENERATED_SOURCES) 2> /dev/null + $(MKDEP) $(MKDEP_OPTIONS) $(INCLUDES) $(LIBRARY_DEFINES) $(C_SOURCES) $(CPP_SOURCES) $(ASM_SOURCES) $(GENERATED_SOURCES) 2> /dev/null # Emacs tags tags: -- cgit v1.2.3 From 016c5c953f05bc8f20cc48d352e1013dd71a98a2 Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Fri, 19 Mar 2010 02:38:11 +0200 Subject: drm/sw: llvmpipe texture_from_handle Not sure, but judging by softpipe, this hook was forgotten. --- src/gallium/drivers/llvmpipe/lp_texture.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/gallium') diff --git a/src/gallium/drivers/llvmpipe/lp_texture.c b/src/gallium/drivers/llvmpipe/lp_texture.c index 93ad789c35d..8137f29af52 100644 --- a/src/gallium/drivers/llvmpipe/lp_texture.c +++ b/src/gallium/drivers/llvmpipe/lp_texture.c @@ -464,6 +464,7 @@ llvmpipe_init_screen_texture_funcs(struct pipe_screen *screen) { screen->texture_create = llvmpipe_texture_create; screen->texture_destroy = llvmpipe_texture_destroy; + screen->texture_from_handle = llvmpipe_texture_from_handle; screen->texture_get_handle = llvmpipe_texture_get_handle; screen->get_tex_surface = llvmpipe_get_tex_surface; -- cgit v1.2.3 From 97a694e2211dc804090f282d8e096c028f29579f Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Fri, 19 Mar 2010 02:38:11 +0200 Subject: drm/sw: does not need sw_winsys --- src/gallium/winsys/drm/sw/sw_drm_api.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/gallium') diff --git a/src/gallium/winsys/drm/sw/sw_drm_api.c b/src/gallium/winsys/drm/sw/sw_drm_api.c index 0fd2163913e..9c5933c73af 100644 --- a/src/gallium/winsys/drm/sw/sw_drm_api.c +++ b/src/gallium/winsys/drm/sw/sw_drm_api.c @@ -40,7 +40,6 @@ struct sw_drm_api { struct drm_api base; struct drm_api *api; - struct sw_winsys *sw; }; static INLINE struct sw_drm_api * -- cgit v1.2.3 From c28f5f98d6d57d3dd74fc6c1205a36ed584d1c93 Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Fri, 19 Mar 2010 02:38:11 +0200 Subject: dri1_api: need not include drm.h --- src/gallium/include/state_tracker/dri1_api.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/gallium') diff --git a/src/gallium/include/state_tracker/dri1_api.h b/src/gallium/include/state_tracker/dri1_api.h index b173ba3683d..27b7a28c467 100644 --- a/src/gallium/include/state_tracker/dri1_api.h +++ b/src/gallium/include/state_tracker/dri1_api.h @@ -7,7 +7,7 @@ #include "state_tracker/drm_api.h" -#include +struct drm_clip_rect; struct pipe_screen; struct pipe_winsys; -- cgit v1.2.3 From f87a5f6499f51f651c2a9f2d4682875b22926905 Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Fri, 19 Mar 2010 02:38:11 +0200 Subject: gallium: add soft screen helper --- src/gallium/auxiliary/target-helpers/soft_screen.c | 73 ++++++++++++++++++++++ src/gallium/auxiliary/target-helpers/soft_screen.h | 12 ++++ src/gallium/targets/libgl-xlib/Makefile | 1 + src/gallium/targets/libgl-xlib/soft_screen.c | 1 + src/gallium/targets/libgl-xlib/xlib.c | 34 +--------- src/gallium/winsys/drm/sw/Makefile | 3 +- src/gallium/winsys/drm/sw/soft_screen.c | 1 + src/gallium/winsys/drm/sw/sw_drm_api.c | 32 ++++++++-- 8 files changed, 120 insertions(+), 37 deletions(-) create mode 100644 src/gallium/auxiliary/target-helpers/soft_screen.c create mode 100644 src/gallium/auxiliary/target-helpers/soft_screen.h create mode 120000 src/gallium/targets/libgl-xlib/soft_screen.c create mode 120000 src/gallium/winsys/drm/sw/soft_screen.c (limited to 'src/gallium') diff --git a/src/gallium/auxiliary/target-helpers/soft_screen.c b/src/gallium/auxiliary/target-helpers/soft_screen.c new file mode 100644 index 00000000000..00d386ee1de --- /dev/null +++ b/src/gallium/auxiliary/target-helpers/soft_screen.c @@ -0,0 +1,73 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * + **************************************************************************/ + +#include "target-helpers/soft_screen.h" +#include "softpipe/sp_public.h" +#include "llvmpipe/lp_public.h" +#include "cell/ppu/cell_public.h" +#include "util/u_debug.h" + +/** + * Choose and create a software renderer screen. + */ +struct pipe_screen * +gallium_soft_create_screen( struct sw_winsys *winsys ) +{ + const char *default_driver = NULL; + const char *driver = NULL; + struct pipe_screen *screen = NULL; + +#if defined(GALLIUM_CELL) + default_driver = "cell"; +#elif defined(GALLIUM_LLVMPIPE) + default_driver = "llvmpipe"; +#elif defined(GALLIUM_SOFTPIPE) + default_driver = "softpipe"; +#else + default_driver = ""; +#endif + + driver = debug_get_option("GALLIUM_DRIVER", default_driver); + +#if defined(GALLIUM_CELL) + if (screen == NULL && strcmp(driver, "cell") == 0) + screen = cell_create_screen( winsys ); +#endif + +#if defined(GALLIUM_LLVMPIPE) + if (screen == NULL && strcmp(driver, "llvmpipe") == 0) + screen = llvmpipe_create_screen( winsys ); +#endif + +#if defined(GALLIUM_SOFTPIPE) + if (screen == NULL) + screen = softpipe_create_screen( winsys ); +#endif + + return screen; +} diff --git a/src/gallium/auxiliary/target-helpers/soft_screen.h b/src/gallium/auxiliary/target-helpers/soft_screen.h new file mode 100644 index 00000000000..5c1012644aa --- /dev/null +++ b/src/gallium/auxiliary/target-helpers/soft_screen.h @@ -0,0 +1,12 @@ +#ifndef SOFT_SCREEN_HELPER_H +#define SOFT_SCREEN_HELPER_H + +#include "pipe/p_compiler.h" + +struct pipe_screen; +struct sw_winsys; + +struct pipe_screen * +gallium_soft_create_screen( struct sw_winsys *winsys ); + +#endif diff --git a/src/gallium/targets/libgl-xlib/Makefile b/src/gallium/targets/libgl-xlib/Makefile index 5a4e035c2eb..2c44a62102e 100644 --- a/src/gallium/targets/libgl-xlib/Makefile +++ b/src/gallium/targets/libgl-xlib/Makefile @@ -27,6 +27,7 @@ DEFINES += \ #-DGALLIUM_CELL will be defined by the config */ XLIB_TARGET_SOURCES = \ + soft_screen.c \ xlib.c diff --git a/src/gallium/targets/libgl-xlib/soft_screen.c b/src/gallium/targets/libgl-xlib/soft_screen.c new file mode 120000 index 00000000000..d6d878f3658 --- /dev/null +++ b/src/gallium/targets/libgl-xlib/soft_screen.c @@ -0,0 +1 @@ +../../auxiliary/target-helpers/soft_screen.c \ No newline at end of file diff --git a/src/gallium/targets/libgl-xlib/xlib.c b/src/gallium/targets/libgl-xlib/xlib.c index 48e79fe4f3b..e7862212106 100644 --- a/src/gallium/targets/libgl-xlib/xlib.c +++ b/src/gallium/targets/libgl-xlib/xlib.c @@ -36,6 +36,7 @@ #include "softpipe/sp_public.h" #include "llvmpipe/lp_public.h" #include "cell/ppu/cell_public.h" +#include "target-helpers/soft_screen.h" #include "target-helpers/wrap_screen.h" #include "xm_public.h" @@ -63,8 +64,6 @@ PUBLIC const struct st_module st_module_OpenGL = { static struct pipe_screen * swrast_xlib_create_screen( Display *display ) { - const char *default_driver; - const char *driver; struct sw_winsys *winsys; struct pipe_screen *screen = NULL; @@ -75,36 +74,7 @@ swrast_xlib_create_screen( Display *display ) if (winsys == NULL) return NULL; -#if defined(GALLIUM_CELL) - default_driver = "cell"; -#elif defined(GALLIUM_LLVMPIPE) - default_driver = "llvmpipe"; -#elif defined(GALLIUM_SOFTPIPE) - default_driver = "softpipe"; -#else - default_driver = ""; -#endif - - driver = debug_get_option("GALLIUM_DRIVER", default_driver); - - /* Create a software rasterizer on top of that winsys: - */ -#if defined(GALLIUM_CELL) - if (screen == NULL && - strcmp(driver, "cell") == 0) - screen = cell_create_screen( winsys ); -#endif - -#if defined(GALLIUM_LLVMPIPE) - if (screen == NULL && - strcmp(driver, "llvmpipe") == 0) - screen = llvmpipe_create_screen( winsys ); -#endif - -#if defined(GALLIUM_SOFTPIPE) - if (screen == NULL) - screen = softpipe_create_screen( winsys ); -#endif + screen = gallium_soft_create_screen( winsys ); if (screen == NULL) goto fail; diff --git a/src/gallium/winsys/drm/sw/Makefile b/src/gallium/winsys/drm/sw/Makefile index 5f3c3ec325d..12b20cbd454 100644 --- a/src/gallium/winsys/drm/sw/Makefile +++ b/src/gallium/winsys/drm/sw/Makefile @@ -4,11 +4,12 @@ include $(TOP)/configs/current LIBNAME = swdrm C_SOURCES = \ + soft_screen.c \ wrapper_sw_winsys.c \ sw_drm_api.c LIBRARY_INCLUDES = -LIBRARY_DEFINES = +LIBRARY_DEFINES = -DGALLIUM_SOFTPIPE include ../../../Makefile.template diff --git a/src/gallium/winsys/drm/sw/soft_screen.c b/src/gallium/winsys/drm/sw/soft_screen.c new file mode 120000 index 00000000000..423597ba31f --- /dev/null +++ b/src/gallium/winsys/drm/sw/soft_screen.c @@ -0,0 +1 @@ +../../../auxiliary/target-helpers/soft_screen.c \ No newline at end of file diff --git a/src/gallium/winsys/drm/sw/sw_drm_api.c b/src/gallium/winsys/drm/sw/sw_drm_api.c index 9c5933c73af..ed3ce146eb1 100644 --- a/src/gallium/winsys/drm/sw/sw_drm_api.c +++ b/src/gallium/winsys/drm/sw/sw_drm_api.c @@ -24,8 +24,11 @@ **********************************************************/ +#include "pipe/p_screen.h" #include "util/u_memory.h" -#include "softpipe/sp_public.h" +#include "target-helpers/soft_screen.h" + +#include "state_tracker/sw_winsys.h" #include "state_tracker/drm_api.h" #include "wrapper_sw_winsys.h" #include "sw_drm_api.h" @@ -60,14 +63,35 @@ sw_drm_create_screen(struct drm_api *_api, int drmFD, { struct sw_drm_api *swapi = sw_drm_api(_api); struct drm_api *api = swapi->api; - struct sw_winsys *sww; - struct pipe_screen *screen; + struct sw_winsys *sww = NULL; + struct pipe_screen *screen = NULL; + struct pipe_screen *soft_screen = NULL; screen = api->create_screen(api, drmFD, arg); + if (screen == NULL) + goto fail; sww = wrapper_sw_winsys_warp_pipe_screen(screen); + if (sww == NULL) + goto fail; + + soft_screen = gallium_soft_create_screen(sww); + if (soft_screen == NULL) + goto fail; + + return soft_screen; + +fail: + if (soft_screen) + soft_screen->destroy(soft_screen); + + if (sww) + sww->destroy(sww); + + if (screen) + screen->destroy(screen); - return softpipe_create_screen(sww); + return NULL; } static void -- cgit v1.2.3 From 272bbbffb0138024564cbf8410a30ea9e25eb179 Mon Sep 17 00:00:00 2001 From: Christoph Bumiller Date: Sun, 21 Mar 2010 13:17:02 +0100 Subject: nv50: get rid of the static_init stateobj Relocations of per-screen buffers are now emitted directly, and include the necessary method to get changes in constbuf addresses committed to the hw. It should also be a bit cheaper than the way stateobjs emit relocation markers, use a little less pushbuf space. --- src/gallium/drivers/nv50/nv50_screen.c | 276 +++++++++++++------------ src/gallium/drivers/nv50/nv50_screen.h | 4 +- src/gallium/drivers/nv50/nv50_state_validate.c | 2 +- 3 files changed, 142 insertions(+), 140 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/nv50/nv50_screen.c b/src/gallium/drivers/nv50/nv50_screen.c index d7f5863fb71..8fab06c55da 100644 --- a/src/gallium/drivers/nv50/nv50_screen.c +++ b/src/gallium/drivers/nv50/nv50_screen.c @@ -190,8 +190,6 @@ nv50_screen_destroy(struct pipe_screen *pscreen) nouveau_bo_ref(NULL, &screen->tic); if (screen->tsc) nouveau_bo_ref(NULL, &screen->tsc); - if (screen->static_init) - so_ref(NULL, &screen->static_init); nouveau_notifier_free(&screen->sync); nouveau_grobj_free(&screen->tesla); @@ -204,16 +202,65 @@ nv50_screen_destroy(struct pipe_screen *pscreen) FREE(screen); } +#define BGN_RELOC(ch, bo, gr, m, n, fl) \ + OUT_RELOC(ch, bo, (n << 18) | (gr->subc << 13) | m, fl, 0, 0) + +void +nv50_screen_relocs(struct nv50_screen *screen) +{ + struct nouveau_channel *chan = screen->base.channel; + struct nouveau_grobj *tesla = screen->tesla; + unsigned i; + const unsigned rl = NOUVEAU_BO_VRAM | NOUVEAU_BO_RD | NOUVEAU_BO_DUMMY; + + MARK_RING (chan, 28, 26); + + /* cause grobj autobind */ + BEGIN_RING(chan, tesla, 0x0100, 1); + OUT_RING (chan, 0); + + BGN_RELOC (chan, screen->tic, tesla, NV50TCL_TIC_ADDRESS_HIGH, 2, rl); + OUT_RELOCh(chan, screen->tic, 0, rl); + OUT_RELOCl(chan, screen->tic, 0, rl); + + BGN_RELOC (chan, screen->tsc, tesla, NV50TCL_TSC_ADDRESS_HIGH, 2, rl); + OUT_RELOCh(chan, screen->tsc, 0, rl); + OUT_RELOCl(chan, screen->tsc, 0, rl); + + BGN_RELOC (chan, screen->constbuf_misc[0], + tesla, NV50TCL_CB_DEF_ADDRESS_HIGH, 3, rl); + OUT_RELOCh(chan, screen->constbuf_misc[0], 0, rl); + OUT_RELOCl(chan, screen->constbuf_misc[0], 0, rl); + OUT_RELOC (chan, screen->constbuf_misc[0], + (NV50_CB_PMISC << 16) | 0x0200, rl, 0, 0); + + BGN_RELOC (chan, screen->constbuf_misc[0], + tesla, NV50TCL_CB_DEF_ADDRESS_HIGH, 3, rl); + OUT_RELOCh(chan, screen->constbuf_misc[0], 0x200, rl); + OUT_RELOCl(chan, screen->constbuf_misc[0], 0x200, rl); + OUT_RELOC (chan, screen->constbuf_misc[0], + (NV50_CB_AUX << 16) | 0x0200, rl, 0, 0); + + for (i = 0; i < 3; ++i) { + BGN_RELOC (chan, screen->constbuf_parm[i], + tesla, NV50TCL_CB_DEF_ADDRESS_HIGH, 3, rl); + OUT_RELOCh(chan, screen->constbuf_parm[i], 0, rl); + OUT_RELOCl(chan, screen->constbuf_parm[i], 0, rl); + OUT_RELOC (chan, screen->constbuf_parm[i], + ((NV50_CB_PVP + i) << 16) | 0x0800, rl, 0, 0); + } +} + struct pipe_screen * nv50_screen_create(struct pipe_winsys *ws, struct nouveau_device *dev) { struct nv50_screen *screen = CALLOC_STRUCT(nv50_screen); struct nouveau_channel *chan; struct pipe_screen *pscreen; - struct nouveau_stateobj *so; unsigned chipset = dev->chipset; unsigned tesla_class = 0; int ret, i; + const unsigned rl = NOUVEAU_BO_VRAM | NOUVEAU_BO_RD; if (!screen) return NULL; @@ -296,64 +343,58 @@ nv50_screen_create(struct pipe_winsys *ws, struct nouveau_device *dev) } /* Static M2MF init */ - so = so_new(1, 3, 0); - so_method(so, screen->m2mf, NV04_MEMORY_TO_MEMORY_FORMAT_DMA_NOTIFY, 3); - so_data (so, screen->sync->handle); - so_data (so, chan->vram->handle); - so_data (so, chan->vram->handle); - so_emit(chan, so); - so_ref (NULL, &so); + BEGIN_RING(chan, screen->m2mf, + NV04_MEMORY_TO_MEMORY_FORMAT_DMA_NOTIFY, 3); + OUT_RING (chan, screen->sync->handle); + OUT_RING (chan, chan->vram->handle); + OUT_RING (chan, chan->vram->handle); /* Static 2D init */ - so = so_new(4, 7, 0); - so_method(so, screen->eng2d, NV50_2D_DMA_NOTIFY, 4); - so_data (so, screen->sync->handle); - so_data (so, chan->vram->handle); - so_data (so, chan->vram->handle); - so_data (so, chan->vram->handle); - so_method(so, screen->eng2d, NV50_2D_OPERATION, 1); - so_data (so, NV50_2D_OPERATION_SRCCOPY); - so_method(so, screen->eng2d, NV50_2D_CLIP_ENABLE, 1); - so_data (so, 0); - so_method(so, screen->eng2d, 0x0888, 1); - so_data (so, 1); - so_emit(chan, so); - so_ref(NULL, &so); + BEGIN_RING(chan, screen->eng2d, NV50_2D_DMA_NOTIFY, 4); + OUT_RING (chan, screen->sync->handle); + OUT_RING (chan, chan->vram->handle); + OUT_RING (chan, chan->vram->handle); + OUT_RING (chan, chan->vram->handle); + BEGIN_RING(chan, screen->eng2d, NV50_2D_OPERATION, 1); + OUT_RING (chan, NV50_2D_OPERATION_SRCCOPY); + BEGIN_RING(chan, screen->eng2d, NV50_2D_CLIP_ENABLE, 1); + OUT_RING (chan, 0); + BEGIN_RING(chan, screen->eng2d, 0x0888, 1); + OUT_RING (chan, 1); /* Static tesla init */ - so = so_new(47, 95, 24); - - so_method(so, screen->tesla, NV50TCL_COND_MODE, 1); - so_data (so, NV50TCL_COND_MODE_ALWAYS); - so_method(so, screen->tesla, NV50TCL_DMA_NOTIFY, 1); - so_data (so, screen->sync->handle); - so_method(so, screen->tesla, NV50TCL_DMA_ZETA, 11); + BEGIN_RING(chan, screen->tesla, NV50TCL_COND_MODE, 1); + OUT_RING (chan, NV50TCL_COND_MODE_ALWAYS); + BEGIN_RING(chan, screen->tesla, NV50TCL_DMA_NOTIFY, 1); + OUT_RING (chan, screen->sync->handle); + BEGIN_RING(chan, screen->tesla, NV50TCL_DMA_ZETA, 11); for (i = 0; i < 11; i++) - so_data(so, chan->vram->handle); - so_method(so, screen->tesla, NV50TCL_DMA_COLOR(0), - NV50TCL_DMA_COLOR__SIZE); + OUT_RING (chan, chan->vram->handle); + BEGIN_RING(chan, screen->tesla, + NV50TCL_DMA_COLOR(0), NV50TCL_DMA_COLOR__SIZE); for (i = 0; i < NV50TCL_DMA_COLOR__SIZE; i++) - so_data(so, chan->vram->handle); - so_method(so, screen->tesla, NV50TCL_RT_CONTROL, 1); - so_data (so, 1); + OUT_RING (chan, chan->vram->handle); + + BEGIN_RING(chan, screen->tesla, NV50TCL_RT_CONTROL, 1); + OUT_RING (chan, 1); /* activate all 32 lanes (threads) in a warp */ - so_method(so, screen->tesla, NV50TCL_WARP_HALVES, 1); - so_data (so, 0x2); - so_method(so, screen->tesla, 0x1400, 1); - so_data (so, 0xf); + BEGIN_RING(chan, screen->tesla, NV50TCL_WARP_HALVES, 1); + OUT_RING (chan, 2); + BEGIN_RING(chan, screen->tesla, 0x1400, 1); + OUT_RING (chan, 0xf); /* max TIC (bits 4:8) & TSC (ignored) bindings, per program type */ for (i = 0; i < 3; ++i) { - so_method(so, screen->tesla, NV50TCL_TEX_LIMITS(i), 1); - so_data (so, 0x54); + BEGIN_RING(chan, screen->tesla, NV50TCL_TEX_LIMITS(i), 1); + OUT_RING (chan, 0x54); } /* origin is top left (set to 1 for bottom left) */ - so_method(so, screen->tesla, NV50TCL_Y_ORIGIN_BOTTOM, 1); - so_data (so, 0); - so_method(so, screen->tesla, NV50TCL_VP_REG_ALLOC_RESULT, 1); - so_data (so, 8); + BEGIN_RING(chan, screen->tesla, NV50TCL_Y_ORIGIN_BOTTOM, 1); + OUT_RING (chan, 0); + BEGIN_RING(chan, screen->tesla, NV50TCL_VP_REG_ALLOC_RESULT, 1); + OUT_RING (chan, 8); /* constant buffers for immediates and VP/FP parameters */ ret = nouveau_bo_new(dev, NOUVEAU_BO_VRAM, 0, (32 * 4) * 4, @@ -362,6 +403,14 @@ nv50_screen_create(struct pipe_winsys *ws, struct nouveau_device *dev) nv50_screen_destroy(pscreen); return NULL; } + BEGIN_RING(chan, screen->tesla, NV50TCL_CB_DEF_ADDRESS_HIGH, 3); + OUT_RELOCh(chan, screen->constbuf_misc[0], 0, rl); + OUT_RELOCl(chan, screen->constbuf_misc[0], 0, rl); + OUT_RING (chan, (NV50_CB_PMISC << 16) | 0x0200); + BEGIN_RING(chan, screen->tesla, NV50TCL_CB_DEF_ADDRESS_HIGH, 3); + OUT_RELOCh(chan, screen->constbuf_misc[0], 0x200, rl); + OUT_RELOCl(chan, screen->constbuf_misc[0], 0x200, rl); + OUT_RING (chan, (NV50_CB_AUX << 16) | 0x0200); for (i = 0; i < 3; i++) { ret = nouveau_bo_new(dev, NOUVEAU_BO_VRAM, 0, (256 * 4) * 4, @@ -370,6 +419,10 @@ nv50_screen_create(struct pipe_winsys *ws, struct nouveau_device *dev) nv50_screen_destroy(pscreen); return NULL; } + BEGIN_RING(chan, screen->tesla, NV50TCL_CB_DEF_ADDRESS_HIGH, 3); + OUT_RELOCh(chan, screen->constbuf_parm[i], 0, rl); + OUT_RELOCl(chan, screen->constbuf_parm[i], 0, rl); + OUT_RING (chan, ((NV50_CB_PVP + i) << 16) | 0x0800); } if (nouveau_resource_init(&screen->immd_heap[0], 0, 128) || @@ -381,80 +434,16 @@ nv50_screen_create(struct pipe_winsys *ws, struct nouveau_device *dev) return NULL; } - /* - // map constant buffers: - // B = buffer ID (maybe more than 1 byte) - // N = CB index used in shader instruction - // P = program type (0 = VP, 2 = GP, 3 = FP) - so_method(so, screen->tesla, NV50TCL_SET_PROGRAM_CB, 1); - so_data (so, 0x000BBNP1); - */ - - so_method(so, screen->tesla, NV50TCL_CB_DEF_ADDRESS_HIGH, 3); - so_reloc (so, screen->constbuf_misc[0], 0, NOUVEAU_BO_VRAM | - NOUVEAU_BO_RD | NOUVEAU_BO_HIGH, 0, 0); - so_reloc (so, screen->constbuf_misc[0], 0, NOUVEAU_BO_VRAM | - NOUVEAU_BO_RD | NOUVEAU_BO_LOW, 0, 0); - so_data (so, (NV50_CB_PMISC << 16) | 0x00000200); - so_method(so, screen->tesla, NV50TCL_SET_PROGRAM_CB, 1); - so_data (so, 0x00000001 | (NV50_CB_PMISC << 12)); - so_method(so, screen->tesla, NV50TCL_SET_PROGRAM_CB, 1); - so_data (so, 0x00000021 | (NV50_CB_PMISC << 12)); - so_method(so, screen->tesla, NV50TCL_SET_PROGRAM_CB, 1); - so_data (so, 0x00000031 | (NV50_CB_PMISC << 12)); - - /* bind auxiliary constbuf to immediate data bo */ - so_method(so, screen->tesla, NV50TCL_CB_DEF_ADDRESS_HIGH, 3); - so_reloc (so, screen->constbuf_misc[0], (128 * 4) * 4, - NOUVEAU_BO_VRAM | NOUVEAU_BO_RD | NOUVEAU_BO_HIGH, 0, 0); - so_reloc (so, screen->constbuf_misc[0], (128 * 4) * 4, - NOUVEAU_BO_VRAM | NOUVEAU_BO_RD | NOUVEAU_BO_LOW, 0, 0); - so_data (so, (NV50_CB_AUX << 16) | 0x00000200); - so_method(so, screen->tesla, NV50TCL_SET_PROGRAM_CB, 1); - so_data (so, 0x00000201 | (NV50_CB_AUX << 12)); - so_method(so, screen->tesla, NV50TCL_SET_PROGRAM_CB, 1); - so_data (so, 0x00000221 | (NV50_CB_AUX << 12)); - - so_method(so, screen->tesla, NV50TCL_CB_DEF_ADDRESS_HIGH, 3); - so_reloc (so, screen->constbuf_parm[PIPE_SHADER_VERTEX], 0, - NOUVEAU_BO_VRAM | NOUVEAU_BO_RD | NOUVEAU_BO_HIGH, 0, 0); - so_reloc (so, screen->constbuf_parm[PIPE_SHADER_VERTEX], 0, - NOUVEAU_BO_VRAM | NOUVEAU_BO_RD | NOUVEAU_BO_LOW, 0, 0); - so_data (so, (NV50_CB_PVP << 16) | 0x00000800); - so_method(so, screen->tesla, NV50TCL_SET_PROGRAM_CB, 1); - so_data (so, 0x00000101 | (NV50_CB_PVP << 12)); - - so_method(so, screen->tesla, NV50TCL_CB_DEF_ADDRESS_HIGH, 3); - so_reloc (so, screen->constbuf_parm[PIPE_SHADER_GEOMETRY], 0, - NOUVEAU_BO_VRAM | NOUVEAU_BO_RD | NOUVEAU_BO_HIGH, 0, 0); - so_reloc (so, screen->constbuf_parm[PIPE_SHADER_GEOMETRY], 0, - NOUVEAU_BO_VRAM | NOUVEAU_BO_RD | NOUVEAU_BO_LOW, 0, 0); - so_data (so, (NV50_CB_PGP << 16) | 0x00000800); - so_method(so, screen->tesla, NV50TCL_SET_PROGRAM_CB, 1); - so_data (so, 0x00000121 | (NV50_CB_PGP << 12)); - - so_method(so, screen->tesla, NV50TCL_CB_DEF_ADDRESS_HIGH, 3); - so_reloc (so, screen->constbuf_parm[PIPE_SHADER_FRAGMENT], 0, - NOUVEAU_BO_VRAM | NOUVEAU_BO_RD | NOUVEAU_BO_HIGH, 0, 0); - so_reloc (so, screen->constbuf_parm[PIPE_SHADER_FRAGMENT], 0, - NOUVEAU_BO_VRAM | NOUVEAU_BO_RD | NOUVEAU_BO_LOW, 0, 0); - so_data (so, (NV50_CB_PFP << 16) | 0x00000800); - so_method(so, screen->tesla, NV50TCL_SET_PROGRAM_CB, 1); - so_data (so, 0x00000131 | (NV50_CB_PFP << 12)); - ret = nouveau_bo_new(dev, NOUVEAU_BO_VRAM, 0, 3 * 32 * (8 * 4), &screen->tic); if (ret) { nv50_screen_destroy(pscreen); return NULL; } - - so_method(so, screen->tesla, NV50TCL_TIC_ADDRESS_HIGH, 3); - so_reloc (so, screen->tic, 0, NOUVEAU_BO_VRAM | - NOUVEAU_BO_RD | NOUVEAU_BO_HIGH, 0, 0); - so_reloc (so, screen->tic, 0, NOUVEAU_BO_VRAM | - NOUVEAU_BO_RD | NOUVEAU_BO_LOW, 0, 0); - so_data (so, 3 * 32 - 1); + BEGIN_RING(chan, screen->tesla, NV50TCL_TIC_ADDRESS_HIGH, 3); + OUT_RELOCh(chan, screen->tic, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_RD); + OUT_RELOCl(chan, screen->tic, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_RD); + OUT_RING (chan, 3 * 32 - 1); ret = nouveau_bo_new(dev, NOUVEAU_BO_VRAM, 0, 3 * 32 * (8 * 4), &screen->tsc); @@ -462,37 +451,50 @@ nv50_screen_create(struct pipe_winsys *ws, struct nouveau_device *dev) nv50_screen_destroy(pscreen); return NULL; } - - so_method(so, screen->tesla, NV50TCL_TSC_ADDRESS_HIGH, 3); - so_reloc (so, screen->tsc, 0, NOUVEAU_BO_VRAM | - NOUVEAU_BO_RD | NOUVEAU_BO_HIGH, 0, 0); - so_reloc (so, screen->tsc, 0, NOUVEAU_BO_VRAM | - NOUVEAU_BO_RD | NOUVEAU_BO_LOW, 0, 0); - so_data (so, 0x00000000); /* ignored if TSC_LINKED (0x1234) = 1 */ - + BEGIN_RING(chan, screen->tesla, NV50TCL_TSC_ADDRESS_HIGH, 3); + OUT_RELOCh(chan, screen->tsc, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_RD); + OUT_RELOCl(chan, screen->tsc, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_RD); + OUT_RING (chan, 0); /* ignored if TSC_LINKED (0x1234) == 1 */ + + /* map constant buffers: + * B = buffer ID (maybe more than 1 byte) + * N = CB index used in shader instruction + * P = program type (0 = VP, 2 = GP, 3 = FP) + * SET_PROGRAM_CB = 0x000BBNP1 + */ + BEGIN_RING_NI(chan, screen->tesla, NV50TCL_SET_PROGRAM_CB, 8); + /* bind immediate buffer */ + OUT_RING (chan, 0x001 | (NV50_CB_PMISC << 12)); + OUT_RING (chan, 0x021 | (NV50_CB_PMISC << 12)); + OUT_RING (chan, 0x031 | (NV50_CB_PMISC << 12)); + /* bind auxiliary constbuf to immediate data bo */ + OUT_RING (chan, 0x201 | (NV50_CB_AUX << 12)); + OUT_RING (chan, 0x221 | (NV50_CB_AUX << 12)); + /* bind parameter buffers */ + OUT_RING (chan, 0x101 | (NV50_CB_PVP << 12)); + OUT_RING (chan, 0x121 | (NV50_CB_PGP << 12)); + OUT_RING (chan, 0x131 | (NV50_CB_PFP << 12)); /* Vertex array limits - max them out */ for (i = 0; i < 16; i++) { - so_method(so, screen->tesla, NV50TCL_VERTEX_ARRAY_LIMIT_HIGH(i), 2); - so_data (so, 0x000000ff); - so_data (so, 0xffffffff); + BEGIN_RING(chan, screen->tesla, + NV50TCL_VERTEX_ARRAY_LIMIT_HIGH(i), 2); + OUT_RING (chan, 0x000000ff); + OUT_RING (chan, 0xffffffff); } - so_method(so, screen->tesla, NV50TCL_DEPTH_RANGE_NEAR(0), 2); - so_data (so, fui(0.0)); - so_data (so, fui(1.0)); + BEGIN_RING(chan, screen->tesla, NV50TCL_DEPTH_RANGE_NEAR(0), 2); + OUT_RINGf (chan, 0.0f); + OUT_RINGf (chan, 1.0f); /* no dynamic combination of TIC & TSC entries => only BIND_TIC used */ - so_method(so, screen->tesla, NV50TCL_LINKED_TSC, 1); - so_data (so, 1); + BEGIN_RING(chan, screen->tesla, NV50TCL_LINKED_TSC, 1); + OUT_RING (chan, 1); - so_method(so, screen->tesla, NV50TCL_EDGEFLAG_ENABLE, 1); - so_data (so, 1); /* default edgeflag to TRUE */ + BEGIN_RING(chan, screen->tesla, NV50TCL_EDGEFLAG_ENABLE, 1); + OUT_RING (chan, 1); /* default edgeflag to TRUE */ - so_emit(chan, so); - so_ref (so, &screen->static_init); - so_ref (NULL, &so); - nouveau_pushbuf_flush(chan, 0); + FIRE_RING (chan); screen->force_push = debug_get_bool_option("NV50_ALWAYS_PUSH", FALSE); return pscreen; diff --git a/src/gallium/drivers/nv50/nv50_screen.h b/src/gallium/drivers/nv50/nv50_screen.h index ec19ea655b1..15bd4eed399 100644 --- a/src/gallium/drivers/nv50/nv50_screen.h +++ b/src/gallium/drivers/nv50/nv50_screen.h @@ -27,8 +27,6 @@ struct nv50_screen { struct nouveau_bo *tic; struct nouveau_bo *tsc; - struct nouveau_stateobj *static_init; - boolean force_push; }; @@ -38,4 +36,6 @@ nv50_screen(struct pipe_screen *screen) return (struct nv50_screen *)screen; } +extern void nv50_screen_relocs(struct nv50_screen *); + #endif diff --git a/src/gallium/drivers/nv50/nv50_state_validate.c b/src/gallium/drivers/nv50/nv50_state_validate.c index 63d73b5ce83..b7e355283c8 100644 --- a/src/gallium/drivers/nv50/nv50_state_validate.c +++ b/src/gallium/drivers/nv50/nv50_state_validate.c @@ -435,7 +435,7 @@ nv50_state_validate(struct nv50_context *nv50, unsigned wait_dwords) so_emit_reloc_markers(chan, nv50->state.hw[3]); /* vp */ so_emit_reloc_markers(chan, nv50->state.hw[4]); /* fp */ so_emit_reloc_markers(chan, nv50->state.hw[17]); /* vb */ - so_emit_reloc_markers(chan, nv50->screen->static_init); + nv50_screen_relocs(nv50->screen); /* No idea.. */ BEGIN_RING(chan, tesla, 0x142c, 1); -- cgit v1.2.3 From 1afda5303d2eaf9581fa7c9eec872a0022ff35b5 Mon Sep 17 00:00:00 2001 From: Christoph Bumiller Date: Sun, 21 Mar 2010 12:26:08 +0100 Subject: nv50: don't validate arrays on clear The vertex elements and buffers might not be valid anymore. --- src/gallium/drivers/nv50/nv50_clear.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/gallium') diff --git a/src/gallium/drivers/nv50/nv50_clear.c b/src/gallium/drivers/nv50/nv50_clear.c index 8afc95c9fc6..5447904e9ca 100644 --- a/src/gallium/drivers/nv50/nv50_clear.c +++ b/src/gallium/drivers/nv50/nv50_clear.c @@ -35,7 +35,10 @@ nv50_clear(struct pipe_context *pipe, unsigned buffers, struct nouveau_grobj *tesla = nv50->screen->tesla; struct pipe_framebuffer_state *fb = &nv50->framebuffer; unsigned mode = 0, i; + const unsigned dirty = nv50->dirty; + /* don't need NEW_BLEND, NV50TCL_COLOR_MASK doesn't affect CLEAR_BUFFERS */ + nv50->dirty &= NV50_NEW_FRAMEBUFFER | NV50_NEW_SCISSOR; if (!nv50_state_validate(nv50, 64)) return; @@ -64,5 +67,6 @@ nv50_clear(struct pipe_context *pipe, unsigned buffers, BEGIN_RING(chan, tesla, NV50TCL_CLEAR_BUFFERS, 1); OUT_RING (chan, (i << 6) | 0x3c); } + nv50->dirty = dirty; } -- cgit v1.2.3 From 5d524cce9c4fcc18ed977801d59ba7bb911020db Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Sun, 21 Mar 2010 15:01:36 +0200 Subject: drm/sw: just s/softpipe_create_screen/gallium_soft_create_screen/ This partially reverts commit f87a5f6499f51f651c2a9f2d4682875b22926905. --- src/gallium/winsys/drm/sw/sw_drm_api.c | 30 ++++-------------------------- 1 file changed, 4 insertions(+), 26 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/winsys/drm/sw/sw_drm_api.c b/src/gallium/winsys/drm/sw/sw_drm_api.c index ed3ce146eb1..fa16600fe6a 100644 --- a/src/gallium/winsys/drm/sw/sw_drm_api.c +++ b/src/gallium/winsys/drm/sw/sw_drm_api.c @@ -24,11 +24,9 @@ **********************************************************/ -#include "pipe/p_screen.h" #include "util/u_memory.h" #include "target-helpers/soft_screen.h" -#include "state_tracker/sw_winsys.h" #include "state_tracker/drm_api.h" #include "wrapper_sw_winsys.h" #include "sw_drm_api.h" @@ -43,6 +41,7 @@ struct sw_drm_api { struct drm_api base; struct drm_api *api; + struct sw_winsys *sw; }; static INLINE struct sw_drm_api * @@ -63,35 +62,14 @@ sw_drm_create_screen(struct drm_api *_api, int drmFD, { struct sw_drm_api *swapi = sw_drm_api(_api); struct drm_api *api = swapi->api; - struct sw_winsys *sww = NULL; - struct pipe_screen *screen = NULL; - struct pipe_screen *soft_screen = NULL; + struct sw_winsys *sww; + struct pipe_screen *screen; screen = api->create_screen(api, drmFD, arg); - if (screen == NULL) - goto fail; sww = wrapper_sw_winsys_warp_pipe_screen(screen); - if (sww == NULL) - goto fail; - soft_screen = gallium_soft_create_screen(sww); - if (soft_screen == NULL) - goto fail; - - return soft_screen; - -fail: - if (soft_screen) - soft_screen->destroy(soft_screen); - - if (sww) - sww->destroy(sww); - - if (screen) - screen->destroy(screen); - - return NULL; + return gallium_soft_create_screen(sww); } static void -- cgit v1.2.3 From f7273f2a2741b34ee4d31b0c734bcb3de92098c1 Mon Sep 17 00:00:00 2001 From: Christoph Bumiller Date: Sun, 21 Mar 2010 14:05:20 +0100 Subject: nv50: report driver as GLSL capable There's still no hint of optimization in the shaders, but we support conditionals, loops and even integer opcodes so it isn't that big a lie. --- src/gallium/drivers/nv50/nv50_screen.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/nv50/nv50_screen.c b/src/gallium/drivers/nv50/nv50_screen.c index 8fab06c55da..1a4606d9e25 100644 --- a/src/gallium/drivers/nv50/nv50_screen.c +++ b/src/gallium/drivers/nv50/nv50_screen.c @@ -109,7 +109,7 @@ nv50_screen_get_param(struct pipe_screen *pscreen, int param) case PIPE_CAP_TWO_SIDED_STENCIL: return 1; case PIPE_CAP_GLSL: - return 0; + return 1; case PIPE_CAP_ANISOTROPIC_FILTER: return 1; case PIPE_CAP_POINT_SPRITE: -- cgit v1.2.3 From 59629b413a7e3e3ba4b4213eb3ba4b65bdf3f9fb Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Sun, 21 Mar 2010 15:32:50 +0200 Subject: Revert "Makefile.template: respect LIBRARY_DEFINES in mkdep" This reverts commit 9ec29e31919e85f9230867f43841c0e74be930d3. --- src/gallium/Makefile.template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/gallium') diff --git a/src/gallium/Makefile.template b/src/gallium/Makefile.template index 7606a947e22..91a9b54b362 100644 --- a/src/gallium/Makefile.template +++ b/src/gallium/Makefile.template @@ -34,7 +34,7 @@ lib$(LIBNAME).a: $(OBJECTS) $(EXTRA_OBJECTS) Makefile $(TOP)/src/gallium/Makefil depend: $(C_SOURCES) $(CPP_SOURCES) $(ASM_SOURCES) $(SYMLINKS) $(GENERATED_SOURCES) rm -f depend touch depend - $(MKDEP) $(MKDEP_OPTIONS) $(INCLUDES) $(LIBRARY_DEFINES) $(C_SOURCES) $(CPP_SOURCES) $(ASM_SOURCES) $(GENERATED_SOURCES) 2> /dev/null + $(MKDEP) $(MKDEP_OPTIONS) $(INCLUDES) $(C_SOURCES) $(CPP_SOURCES) $(ASM_SOURCES) $(GENERATED_SOURCES) 2> /dev/null # Emacs tags tags: -- cgit v1.2.3 From 29ec05164838f13d9535271796a50fa213d07912 Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Sun, 21 Mar 2010 19:20:15 +0200 Subject: fix scons build --- src/gallium/targets/libgl-xlib/SConscript | 1 + 1 file changed, 1 insertion(+) (limited to 'src/gallium') diff --git a/src/gallium/targets/libgl-xlib/SConscript b/src/gallium/targets/libgl-xlib/SConscript index efa7e797d1f..4de463e743e 100644 --- a/src/gallium/targets/libgl-xlib/SConscript +++ b/src/gallium/targets/libgl-xlib/SConscript @@ -40,6 +40,7 @@ env.Prepend(LIBS = [ ]) sources = [ + 'soft_screen.c', 'xlib.c', ] -- cgit v1.2.3 From 63aa8a39c4e7ee996afc87404474cce570ac3729 Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Sun, 21 Mar 2010 19:32:40 +0200 Subject: Revert "fix scons build" This reverts commit 29ec05164838f13d9535271796a50fa213d07912. --- src/gallium/targets/libgl-xlib/SConscript | 1 - 1 file changed, 1 deletion(-) (limited to 'src/gallium') diff --git a/src/gallium/targets/libgl-xlib/SConscript b/src/gallium/targets/libgl-xlib/SConscript index 4de463e743e..efa7e797d1f 100644 --- a/src/gallium/targets/libgl-xlib/SConscript +++ b/src/gallium/targets/libgl-xlib/SConscript @@ -40,7 +40,6 @@ env.Prepend(LIBS = [ ]) sources = [ - 'soft_screen.c', 'xlib.c', ] -- cgit v1.2.3 From f9c0cbd1ad0c5948ea577edb5c76b0c45976a285 Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Sun, 21 Mar 2010 19:33:09 +0200 Subject: Revert "drm/sw: just s/softpipe_create_screen/gallium_soft_create_screen/" This reverts commit 5d524cce9c4fcc18ed977801d59ba7bb911020db. --- src/gallium/winsys/drm/sw/sw_drm_api.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/winsys/drm/sw/sw_drm_api.c b/src/gallium/winsys/drm/sw/sw_drm_api.c index fa16600fe6a..ed3ce146eb1 100644 --- a/src/gallium/winsys/drm/sw/sw_drm_api.c +++ b/src/gallium/winsys/drm/sw/sw_drm_api.c @@ -24,9 +24,11 @@ **********************************************************/ +#include "pipe/p_screen.h" #include "util/u_memory.h" #include "target-helpers/soft_screen.h" +#include "state_tracker/sw_winsys.h" #include "state_tracker/drm_api.h" #include "wrapper_sw_winsys.h" #include "sw_drm_api.h" @@ -41,7 +43,6 @@ struct sw_drm_api { struct drm_api base; struct drm_api *api; - struct sw_winsys *sw; }; static INLINE struct sw_drm_api * @@ -62,14 +63,35 @@ sw_drm_create_screen(struct drm_api *_api, int drmFD, { struct sw_drm_api *swapi = sw_drm_api(_api); struct drm_api *api = swapi->api; - struct sw_winsys *sww; - struct pipe_screen *screen; + struct sw_winsys *sww = NULL; + struct pipe_screen *screen = NULL; + struct pipe_screen *soft_screen = NULL; screen = api->create_screen(api, drmFD, arg); + if (screen == NULL) + goto fail; sww = wrapper_sw_winsys_warp_pipe_screen(screen); + if (sww == NULL) + goto fail; - return gallium_soft_create_screen(sww); + soft_screen = gallium_soft_create_screen(sww); + if (soft_screen == NULL) + goto fail; + + return soft_screen; + +fail: + if (soft_screen) + soft_screen->destroy(soft_screen); + + if (sww) + sww->destroy(sww); + + if (screen) + screen->destroy(screen); + + return NULL; } static void -- cgit v1.2.3 From 15c7fa460b93039a1676cc08a218101f92681190 Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Sun, 21 Mar 2010 19:33:17 +0200 Subject: Revert "gallium: add soft screen helper" This reverts commit f87a5f6499f51f651c2a9f2d4682875b22926905. --- src/gallium/auxiliary/target-helpers/soft_screen.c | 73 ---------------------- src/gallium/auxiliary/target-helpers/soft_screen.h | 12 ---- src/gallium/targets/libgl-xlib/Makefile | 1 - src/gallium/targets/libgl-xlib/soft_screen.c | 1 - src/gallium/targets/libgl-xlib/xlib.c | 34 +++++++++- src/gallium/winsys/drm/sw/Makefile | 3 +- src/gallium/winsys/drm/sw/soft_screen.c | 1 - src/gallium/winsys/drm/sw/sw_drm_api.c | 32 ++-------- 8 files changed, 37 insertions(+), 120 deletions(-) delete mode 100644 src/gallium/auxiliary/target-helpers/soft_screen.c delete mode 100644 src/gallium/auxiliary/target-helpers/soft_screen.h delete mode 120000 src/gallium/targets/libgl-xlib/soft_screen.c delete mode 120000 src/gallium/winsys/drm/sw/soft_screen.c (limited to 'src/gallium') diff --git a/src/gallium/auxiliary/target-helpers/soft_screen.c b/src/gallium/auxiliary/target-helpers/soft_screen.c deleted file mode 100644 index 00d386ee1de..00000000000 --- a/src/gallium/auxiliary/target-helpers/soft_screen.c +++ /dev/null @@ -1,73 +0,0 @@ -/************************************************************************** - * - * Copyright 2010 VMware, Inc. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL - * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE - * USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * - **************************************************************************/ - -#include "target-helpers/soft_screen.h" -#include "softpipe/sp_public.h" -#include "llvmpipe/lp_public.h" -#include "cell/ppu/cell_public.h" -#include "util/u_debug.h" - -/** - * Choose and create a software renderer screen. - */ -struct pipe_screen * -gallium_soft_create_screen( struct sw_winsys *winsys ) -{ - const char *default_driver = NULL; - const char *driver = NULL; - struct pipe_screen *screen = NULL; - -#if defined(GALLIUM_CELL) - default_driver = "cell"; -#elif defined(GALLIUM_LLVMPIPE) - default_driver = "llvmpipe"; -#elif defined(GALLIUM_SOFTPIPE) - default_driver = "softpipe"; -#else - default_driver = ""; -#endif - - driver = debug_get_option("GALLIUM_DRIVER", default_driver); - -#if defined(GALLIUM_CELL) - if (screen == NULL && strcmp(driver, "cell") == 0) - screen = cell_create_screen( winsys ); -#endif - -#if defined(GALLIUM_LLVMPIPE) - if (screen == NULL && strcmp(driver, "llvmpipe") == 0) - screen = llvmpipe_create_screen( winsys ); -#endif - -#if defined(GALLIUM_SOFTPIPE) - if (screen == NULL) - screen = softpipe_create_screen( winsys ); -#endif - - return screen; -} diff --git a/src/gallium/auxiliary/target-helpers/soft_screen.h b/src/gallium/auxiliary/target-helpers/soft_screen.h deleted file mode 100644 index 5c1012644aa..00000000000 --- a/src/gallium/auxiliary/target-helpers/soft_screen.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef SOFT_SCREEN_HELPER_H -#define SOFT_SCREEN_HELPER_H - -#include "pipe/p_compiler.h" - -struct pipe_screen; -struct sw_winsys; - -struct pipe_screen * -gallium_soft_create_screen( struct sw_winsys *winsys ); - -#endif diff --git a/src/gallium/targets/libgl-xlib/Makefile b/src/gallium/targets/libgl-xlib/Makefile index 2c44a62102e..5a4e035c2eb 100644 --- a/src/gallium/targets/libgl-xlib/Makefile +++ b/src/gallium/targets/libgl-xlib/Makefile @@ -27,7 +27,6 @@ DEFINES += \ #-DGALLIUM_CELL will be defined by the config */ XLIB_TARGET_SOURCES = \ - soft_screen.c \ xlib.c diff --git a/src/gallium/targets/libgl-xlib/soft_screen.c b/src/gallium/targets/libgl-xlib/soft_screen.c deleted file mode 120000 index d6d878f3658..00000000000 --- a/src/gallium/targets/libgl-xlib/soft_screen.c +++ /dev/null @@ -1 +0,0 @@ -../../auxiliary/target-helpers/soft_screen.c \ No newline at end of file diff --git a/src/gallium/targets/libgl-xlib/xlib.c b/src/gallium/targets/libgl-xlib/xlib.c index e7862212106..48e79fe4f3b 100644 --- a/src/gallium/targets/libgl-xlib/xlib.c +++ b/src/gallium/targets/libgl-xlib/xlib.c @@ -36,7 +36,6 @@ #include "softpipe/sp_public.h" #include "llvmpipe/lp_public.h" #include "cell/ppu/cell_public.h" -#include "target-helpers/soft_screen.h" #include "target-helpers/wrap_screen.h" #include "xm_public.h" @@ -64,6 +63,8 @@ PUBLIC const struct st_module st_module_OpenGL = { static struct pipe_screen * swrast_xlib_create_screen( Display *display ) { + const char *default_driver; + const char *driver; struct sw_winsys *winsys; struct pipe_screen *screen = NULL; @@ -74,7 +75,36 @@ swrast_xlib_create_screen( Display *display ) if (winsys == NULL) return NULL; - screen = gallium_soft_create_screen( winsys ); +#if defined(GALLIUM_CELL) + default_driver = "cell"; +#elif defined(GALLIUM_LLVMPIPE) + default_driver = "llvmpipe"; +#elif defined(GALLIUM_SOFTPIPE) + default_driver = "softpipe"; +#else + default_driver = ""; +#endif + + driver = debug_get_option("GALLIUM_DRIVER", default_driver); + + /* Create a software rasterizer on top of that winsys: + */ +#if defined(GALLIUM_CELL) + if (screen == NULL && + strcmp(driver, "cell") == 0) + screen = cell_create_screen( winsys ); +#endif + +#if defined(GALLIUM_LLVMPIPE) + if (screen == NULL && + strcmp(driver, "llvmpipe") == 0) + screen = llvmpipe_create_screen( winsys ); +#endif + +#if defined(GALLIUM_SOFTPIPE) + if (screen == NULL) + screen = softpipe_create_screen( winsys ); +#endif if (screen == NULL) goto fail; diff --git a/src/gallium/winsys/drm/sw/Makefile b/src/gallium/winsys/drm/sw/Makefile index 12b20cbd454..5f3c3ec325d 100644 --- a/src/gallium/winsys/drm/sw/Makefile +++ b/src/gallium/winsys/drm/sw/Makefile @@ -4,12 +4,11 @@ include $(TOP)/configs/current LIBNAME = swdrm C_SOURCES = \ - soft_screen.c \ wrapper_sw_winsys.c \ sw_drm_api.c LIBRARY_INCLUDES = -LIBRARY_DEFINES = -DGALLIUM_SOFTPIPE +LIBRARY_DEFINES = include ../../../Makefile.template diff --git a/src/gallium/winsys/drm/sw/soft_screen.c b/src/gallium/winsys/drm/sw/soft_screen.c deleted file mode 120000 index 423597ba31f..00000000000 --- a/src/gallium/winsys/drm/sw/soft_screen.c +++ /dev/null @@ -1 +0,0 @@ -../../../auxiliary/target-helpers/soft_screen.c \ No newline at end of file diff --git a/src/gallium/winsys/drm/sw/sw_drm_api.c b/src/gallium/winsys/drm/sw/sw_drm_api.c index ed3ce146eb1..9c5933c73af 100644 --- a/src/gallium/winsys/drm/sw/sw_drm_api.c +++ b/src/gallium/winsys/drm/sw/sw_drm_api.c @@ -24,11 +24,8 @@ **********************************************************/ -#include "pipe/p_screen.h" #include "util/u_memory.h" -#include "target-helpers/soft_screen.h" - -#include "state_tracker/sw_winsys.h" +#include "softpipe/sp_public.h" #include "state_tracker/drm_api.h" #include "wrapper_sw_winsys.h" #include "sw_drm_api.h" @@ -63,35 +60,14 @@ sw_drm_create_screen(struct drm_api *_api, int drmFD, { struct sw_drm_api *swapi = sw_drm_api(_api); struct drm_api *api = swapi->api; - struct sw_winsys *sww = NULL; - struct pipe_screen *screen = NULL; - struct pipe_screen *soft_screen = NULL; + struct sw_winsys *sww; + struct pipe_screen *screen; screen = api->create_screen(api, drmFD, arg); - if (screen == NULL) - goto fail; sww = wrapper_sw_winsys_warp_pipe_screen(screen); - if (sww == NULL) - goto fail; - - soft_screen = gallium_soft_create_screen(sww); - if (soft_screen == NULL) - goto fail; - - return soft_screen; - -fail: - if (soft_screen) - soft_screen->destroy(soft_screen); - - if (sww) - sww->destroy(sww); - - if (screen) - screen->destroy(screen); - return NULL; + return softpipe_create_screen(sww); } static void -- cgit v1.2.3 From a0ce95576463cedb817ad3b262c82eb06eec9b9e Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Sun, 21 Mar 2010 19:36:28 +0200 Subject: Revert "drm/sw: does not need sw_winsys" This reverts commit 97a694e2211dc804090f282d8e096c028f29579f. --- src/gallium/winsys/drm/sw/sw_drm_api.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/gallium') diff --git a/src/gallium/winsys/drm/sw/sw_drm_api.c b/src/gallium/winsys/drm/sw/sw_drm_api.c index 9c5933c73af..0fd2163913e 100644 --- a/src/gallium/winsys/drm/sw/sw_drm_api.c +++ b/src/gallium/winsys/drm/sw/sw_drm_api.c @@ -40,6 +40,7 @@ struct sw_drm_api { struct drm_api base; struct drm_api *api; + struct sw_winsys *sw; }; static INLINE struct sw_drm_api * -- cgit v1.2.3 From bc5778e2023543e5049ab41398aa28fb0709f5f2 Mon Sep 17 00:00:00 2001 From: Marek Olšák Date: Sun, 21 Mar 2010 21:22:21 +0100 Subject: r300g: remove unused code --- src/gallium/drivers/r300/r300_screen.h | 2 - src/gallium/drivers/r300/r300_screen_buffer.c | 2 +- src/gallium/drivers/r300/r300_winsys.h | 2 - src/gallium/winsys/drm/radeon/core/radeon_buffer.c | 388 --------------------- src/gallium/winsys/drm/radeon/core/radeon_buffer.h | 2 - 5 files changed, 1 insertion(+), 395 deletions(-) delete mode 100644 src/gallium/winsys/drm/radeon/core/radeon_buffer.c (limited to 'src/gallium') diff --git a/src/gallium/drivers/r300/r300_screen.h b/src/gallium/drivers/r300/r300_screen.h index 1ccc0bfb7a5..c31f39e6917 100644 --- a/src/gallium/drivers/r300/r300_screen.h +++ b/src/gallium/drivers/r300/r300_screen.h @@ -30,8 +30,6 @@ #define R300_TEXTURE_USAGE_TRANSFER PIPE_TEXTURE_USAGE_CUSTOM -struct radeon_winsys; - struct r300_screen { /* Parent class */ struct pipe_screen screen; diff --git a/src/gallium/drivers/r300/r300_screen_buffer.c b/src/gallium/drivers/r300/r300_screen_buffer.c index b97d0d76a4a..a1cd48ee730 100644 --- a/src/gallium/drivers/r300/r300_screen_buffer.c +++ b/src/gallium/drivers/r300/r300_screen_buffer.c @@ -237,7 +237,7 @@ r300_buffer_map_range(struct pipe_screen *screen, } } just_map: - map = rws->buffer_map(rws, rbuf->buf, usage | R300_USAGE_FLAG_DONT_SYNC); + map = rws->buffer_map(rws, rbuf->buf, usage); return map; } diff --git a/src/gallium/drivers/r300/r300_winsys.h b/src/gallium/drivers/r300/r300_winsys.h index e5183a8239c..1e6d43bea31 100644 --- a/src/gallium/drivers/r300/r300_winsys.h +++ b/src/gallium/drivers/r300/r300_winsys.h @@ -49,8 +49,6 @@ enum r300_value_id { R300_VID_Z_PIPES, }; -#define R300_USAGE_FLAG_DONT_SYNC (1 << 17) - struct r300_winsys_screen { void (*destroy)(struct r300_winsys_screen *ws); diff --git a/src/gallium/winsys/drm/radeon/core/radeon_buffer.c b/src/gallium/winsys/drm/radeon/core/radeon_buffer.c deleted file mode 100644 index 25b58b2926c..00000000000 --- a/src/gallium/winsys/drm/radeon/core/radeon_buffer.c +++ /dev/null @@ -1,388 +0,0 @@ -/* - * Copyright © 2008 Jérôme Glisse - * 2009 Corbin Simpson - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS - * AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE - * USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - */ -/* - * Authors: - * Jérôme Glisse - * Corbin Simpson - */ - -#include "radeon_buffer.h" -#include "radeon_drm.h" - -#include "util/u_format.h" -#include "util/u_math.h" -#include "util/u_memory.h" - -#include "radeon_bo_gem.h" -#include - -struct radeon_vl_context -{ - Display *display; - int screen; - Drawable drawable; -}; - -static const char *radeon_get_name(struct pipe_winsys *ws) -{ - return "Radeon/GEM+KMS"; -} - -static uint32_t radeon_domain_from_usage(unsigned usage) -{ - uint32_t domain = 0; - - if (usage & PIPE_BUFFER_USAGE_GPU_WRITE) { - domain |= RADEON_GEM_DOMAIN_VRAM; - } - if (usage & PIPE_BUFFER_USAGE_PIXEL) { - domain |= RADEON_GEM_DOMAIN_VRAM; - } - if (usage & PIPE_BUFFER_USAGE_VERTEX) { - domain |= RADEON_GEM_DOMAIN_GTT; - } - if (usage & PIPE_BUFFER_USAGE_INDEX) { - domain |= RADEON_GEM_DOMAIN_GTT; - } - - return domain; -} - -static struct pipe_buffer *radeon_buffer_create(struct pipe_winsys *ws, - unsigned alignment, - unsigned usage, - unsigned size) -{ - struct radeon_winsys *radeon_ws = (struct radeon_winsys *)ws; - struct radeon_pipe_buffer *radeon_buffer; - struct pb_desc desc; - uint32_t domain; - - radeon_buffer = CALLOC_STRUCT(radeon_pipe_buffer); - if (radeon_buffer == NULL) { - return NULL; - } - - pipe_reference_init(&radeon_buffer->base.reference, 1); - radeon_buffer->base.alignment = alignment; - radeon_buffer->base.usage = usage; - radeon_buffer->base.size = size; - - if (usage & PIPE_BUFFER_USAGE_CONSTANT && is_r3xx(radeon_ws->pci_id)) { - /* Don't bother allocating a BO, as it'll never get to the card. */ - desc.alignment = alignment; - desc.usage = usage; - radeon_buffer->pb = pb_malloc_buffer_create(size, &desc); - return &radeon_buffer->base; - } - - domain = radeon_domain_from_usage(usage); - - radeon_buffer->bo = radeon_bo_open(radeon_ws->priv->bom, 0, size, - alignment, domain, 0); - if (radeon_buffer->bo == NULL) { - FREE(radeon_buffer); - return NULL; - } - return &radeon_buffer->base; -} - -static struct pipe_buffer *radeon_buffer_user_create(struct pipe_winsys *ws, - void *ptr, - unsigned bytes) -{ - struct radeon_pipe_buffer *radeon_buffer; - - radeon_buffer = - (struct radeon_pipe_buffer*)radeon_buffer_create(ws, 0, 0, bytes); - if (radeon_buffer == NULL) { - return NULL; - } - radeon_bo_map(radeon_buffer->bo, 1); - memcpy(radeon_buffer->bo->ptr, ptr, bytes); - radeon_bo_unmap(radeon_buffer->bo); - return &radeon_buffer->base; -} - -static struct pipe_buffer *radeon_surface_buffer_create(struct pipe_winsys *ws, - unsigned width, - unsigned height, - enum pipe_format format, - unsigned usage, - unsigned tex_usage, - unsigned *stride) -{ - /* Radeons enjoy things in multiples of 32. */ - /* XXX this can be 32 when POT */ - const unsigned alignment = 64; - unsigned nblocksy, size; - - nblocksy = util_format_get_nblocksy(format, height); - *stride = align(util_format_get_stride(format, width), alignment); - size = *stride * nblocksy; - - return radeon_buffer_create(ws, 64, usage, size); -} - -static void radeon_buffer_del(struct pipe_buffer *buffer) -{ - struct radeon_pipe_buffer *radeon_buffer = - (struct radeon_pipe_buffer*)buffer; - - if (radeon_buffer->pb) { - pipe_reference_init(&radeon_buffer->pb->base.reference, 0); - pb_destroy(radeon_buffer->pb); - } - - if (radeon_buffer->bo) { - radeon_bo_unref(radeon_buffer->bo); - } - - FREE(radeon_buffer); -} - -static void *radeon_buffer_map(struct pipe_winsys *ws, - struct pipe_buffer *buffer, - unsigned flags) -{ - struct radeon_winsys_priv *priv = ((struct radeon_winsys *)ws)->priv; - struct radeon_pipe_buffer *radeon_buffer = - (struct radeon_pipe_buffer*)buffer; - int write = 0; - - if (radeon_buffer->pb) { - return pb_map(radeon_buffer->pb, flags); - } - - if (flags & PIPE_BUFFER_USAGE_DONTBLOCK) { - uint32_t domain; - - if (radeon_bo_is_busy(radeon_buffer->bo, &domain)) - return NULL; - } - - if (radeon_bo_is_referenced_by_cs(radeon_buffer->bo, priv->cs)) { - priv->flush_cb(priv->flush_data); - } - - if (flags & PIPE_BUFFER_USAGE_CPU_WRITE) { - write = 1; - } - - if (radeon_bo_map(radeon_buffer->bo, write)) { - return NULL; - } - - return radeon_buffer->bo->ptr; -} - -static void radeon_buffer_unmap(struct pipe_winsys *ws, - struct pipe_buffer *buffer) -{ - struct radeon_pipe_buffer *radeon_buffer = - (struct radeon_pipe_buffer*)buffer; - - if (radeon_buffer->pb) { - pb_unmap(radeon_buffer->pb); - } else { - radeon_bo_unmap(radeon_buffer->bo); - } -} - -static boolean radeon_is_buffer_referenced(struct radeon_winsys *ws, - struct pipe_buffer *buffer) -{ - struct radeon_pipe_buffer *radeon_buffer = - (struct radeon_pipe_buffer*)buffer; - uint32_t domain; - - /* Referenced by CS or HW. */ - return radeon_bo_is_referenced_by_cs(radeon_buffer->bo, ws->priv->cs) || - radeon_bo_is_busy(radeon_buffer->bo, &domain); -} - -static void radeon_buffer_set_tiling(struct radeon_winsys *ws, - struct pipe_buffer *buffer, - uint32_t pitch, - boolean microtiled, - boolean macrotiled) -{ - struct radeon_winsys_priv *priv = ((struct radeon_winsys *)ws)->priv; - struct radeon_pipe_buffer *radeon_buffer = - (struct radeon_pipe_buffer*)buffer; - uint32_t flags = 0, old_flags, old_pitch; - - if (microtiled) { - flags |= RADEON_BO_FLAGS_MICRO_TILE; - } - if (macrotiled) { - flags |= RADEON_BO_FLAGS_MACRO_TILE; - } - - radeon_bo_get_tiling(radeon_buffer->bo, &old_flags, &old_pitch); - - if (flags != old_flags || pitch != old_pitch) { - /* Tiling determines how DRM treats the buffer data. - * We must flush CS when changing it if the buffer is referenced. */ - if (radeon_bo_is_referenced_by_cs(radeon_buffer->bo, priv->cs)) { - priv->flush_cb(priv->flush_data); - } - - radeon_bo_set_tiling(radeon_buffer->bo, flags, pitch); - } -} - -static void radeon_fence_reference(struct pipe_winsys *ws, - struct pipe_fence_handle **ptr, - struct pipe_fence_handle *pfence) -{ -} - -static int radeon_fence_signalled(struct pipe_winsys *ws, - struct pipe_fence_handle *pfence, - unsigned flag) -{ - return 1; -} - -static int radeon_fence_finish(struct pipe_winsys *ws, - struct pipe_fence_handle *pfence, - unsigned flag) -{ - return 0; -} - -/* Create a buffer from a handle. */ -static struct pipe_buffer* radeon_buffer_from_handle(struct radeon_winsys *radeon_ws, - struct pipe_screen *screen, - struct winsys_handle *whandle, - unsigned *stride) -{ - struct radeon_bo_manager* bom = radeon_ws->priv->bom; - struct radeon_pipe_buffer* radeon_buffer; - struct radeon_bo* bo = NULL; - - bo = radeon_bo_open(bom, whandle->handle, 0, 0, 0, 0); - if (bo == NULL) { - return NULL; - } - - radeon_buffer = CALLOC_STRUCT(radeon_pipe_buffer); - if (radeon_buffer == NULL) { - radeon_bo_unref(bo); - return NULL; - } - - pipe_reference_init(&radeon_buffer->base.reference, 1); - radeon_buffer->base.screen = screen; - radeon_buffer->base.usage = PIPE_BUFFER_USAGE_PIXEL; - radeon_buffer->bo = bo; - - *stride = whandle->stride; - - return &radeon_buffer->base; -} - -static boolean radeon_buffer_get_handle(struct radeon_winsys *radeon_ws, - struct pipe_buffer *buffer, - unsigned stride, - struct winsys_handle *whandle) -{ - int retval, fd; - struct drm_gem_flink flink; - struct radeon_pipe_buffer* radeon_buffer; - - radeon_buffer = (struct radeon_pipe_buffer*)buffer; - - - if (whandle->type == DRM_API_HANDLE_TYPE_SHARED) { - if (!radeon_buffer->flinked) { - fd = radeon_ws->priv->fd; - - flink.handle = radeon_buffer->bo->handle; - - retval = ioctl(fd, DRM_IOCTL_GEM_FLINK, &flink); - if (retval) { - debug_printf("radeon: DRM_IOCTL_GEM_FLINK failed, error %d\n", - retval); - return FALSE; - } - - radeon_buffer->flink = flink.name; - radeon_buffer->flinked = TRUE; - } - - whandle->handle = radeon_buffer->flink; - } else if (whandle->type == DRM_API_HANDLE_TYPE_KMS) { - whandle->handle = ((struct radeon_pipe_buffer*)buffer)->bo->handle; - } - whandle->stride = stride; - - return TRUE; -} - -struct radeon_winsys* radeon_pipe_winsys(int fd) -{ - struct radeon_winsys* radeon_ws; - - radeon_ws = CALLOC_STRUCT(radeon_winsys); - if (radeon_ws == NULL) { - return NULL; - } - - radeon_ws->priv = CALLOC_STRUCT(radeon_winsys_priv); - if (radeon_ws->priv == NULL) { - FREE(radeon_ws); - return NULL; - } - - radeon_ws->priv->fd = fd; - radeon_ws->priv->bom = radeon_bo_manager_gem_ctor(fd); - - radeon_ws->base.flush_frontbuffer = NULL; /* overriden by co-state tracker */ - - radeon_ws->base.buffer_create = radeon_buffer_create; - radeon_ws->base.user_buffer_create = radeon_buffer_user_create; - radeon_ws->base.surface_buffer_create = radeon_surface_buffer_create; - radeon_ws->base.buffer_map = radeon_buffer_map; - radeon_ws->base.buffer_unmap = radeon_buffer_unmap; - radeon_ws->base.buffer_destroy = radeon_buffer_del; - - radeon_ws->base.fence_reference = radeon_fence_reference; - radeon_ws->base.fence_signalled = radeon_fence_signalled; - radeon_ws->base.fence_finish = radeon_fence_finish; - - radeon_ws->base.get_name = radeon_get_name; - - radeon_ws->buffer_set_tiling = radeon_buffer_set_tiling; - radeon_ws->buffer_from_handle = radeon_buffer_from_handle; - radeon_ws->buffer_get_handle = radeon_buffer_get_handle; - - radeon_ws->is_buffer_referenced = radeon_is_buffer_referenced; - - return radeon_ws; -} diff --git a/src/gallium/winsys/drm/radeon/core/radeon_buffer.h b/src/gallium/winsys/drm/radeon/core/radeon_buffer.h index e1fcfcfccaa..3d14c861dfa 100644 --- a/src/gallium/winsys/drm/radeon/core/radeon_buffer.h +++ b/src/gallium/winsys/drm/radeon/core/radeon_buffer.h @@ -69,8 +69,6 @@ void radeon_drm_bufmgr_write_reloc(struct pb_buffer *_buf, uint32_t rd, uint32_t wd, uint32_t flags); -struct radeon_libdrm_winsys* radeon_pipe_winsys(int fd); - struct pb_buffer *radeon_drm_bufmgr_create_buffer_from_handle(struct pb_manager *_mgr, uint32_t handle); -- cgit v1.2.3 From d0d3abd360a0d98302841e62ab9acdebea2ca8c2 Mon Sep 17 00:00:00 2001 From: Marek Olšák Date: Sun, 21 Mar 2010 21:34:18 +0100 Subject: r300g: put common defines into one file --- src/gallium/drivers/r300/r300_context.h | 16 +---------- src/gallium/drivers/r300/r300_defines.h | 47 +++++++++++++++++++++++++++++++++ src/gallium/drivers/r300/r300_render.c | 7 ++--- src/gallium/drivers/r300/r300_screen.h | 2 -- src/gallium/drivers/r300/r300_winsys.h | 2 ++ 5 files changed, 52 insertions(+), 22 deletions(-) create mode 100644 src/gallium/drivers/r300/r300_defines.h (limited to 'src/gallium') diff --git a/src/gallium/drivers/r300/r300_context.h b/src/gallium/drivers/r300/r300_context.h index edebeab86fd..4bb385238ed 100644 --- a/src/gallium/drivers/r300/r300_context.h +++ b/src/gallium/drivers/r300/r300_context.h @@ -30,6 +30,7 @@ #include "pipe/p_context.h" #include "util/u_inlines.h" +#include "r300_defines.h" #include "r300_screen.h" struct u_upload_mgr; @@ -135,8 +136,6 @@ struct r300_texture_format_state { uint32_t format2; /* R300_TX_FORMAT2: 0x4500 */ }; -#define R300_MAX_TEXTURE_LEVELS 13 - struct r300_texture_fb_state { /* Colorbuffer. */ uint32_t colorpitch[R300_MAX_TEXTURE_LEVELS]; /* R300_RB3D_COLORPITCH[0-3]*/ @@ -195,12 +194,6 @@ struct r300_ztop_state { uint32_t z_buffer_top; /* R300_ZB_ZTOP: 0x4f14 */ }; -#define R300_NEW_FRAGMENT_SHADER 0x00000020 -#define R300_NEW_FRAGMENT_SHADER_CONSTANTS 0x00000040 -#define R300_NEW_VERTEX_SHADER_CONSTANTS 0x10000000 -#define R300_NEW_QUERY 0x40000000 -#define R300_NEW_KITCHEN_SINK 0x7fffffff - /* The next several objects are not pure Radeon state; they inherit from * various Gallium classes. */ @@ -238,12 +231,6 @@ struct r300_query { struct r300_query* next; }; -enum r300_buffer_tiling { - R300_BUFFER_LINEAR = 0, - R300_BUFFER_TILED, - R300_BUFFER_SQUARETILED -}; - struct r300_texture { /* Parent class */ struct pipe_texture tex; @@ -444,4 +431,3 @@ static INLINE void CTX_DBG(struct r300_context * ctx, unsigned flags, #define DBG CTX_DBG #endif /* R300_CONTEXT_H */ - diff --git a/src/gallium/drivers/r300/r300_defines.h b/src/gallium/drivers/r300/r300_defines.h new file mode 100644 index 00000000000..2e04876de92 --- /dev/null +++ b/src/gallium/drivers/r300/r300_defines.h @@ -0,0 +1,47 @@ +/* + * Copyright 2010 Marek Olšák + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * on the rights to use, copy, modify, merge, publish, distribute, sub + * license, and/or sell copies of the Software, and to permit persons to whom + * the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. */ + +#ifndef R300_DEFINES_H +#define R300_DEFINES_H + +#include "pipe/p_defines.h" + +#define R300_MAX_TEXTURE_LEVELS 13 +#define R300_MAX_DRAW_VBO_SIZE (1024 * 1024) + +#define R300_TEXTURE_USAGE_TRANSFER PIPE_TEXTURE_USAGE_CUSTOM + +/* Non-atom dirty state flags. */ +#define R300_NEW_FRAGMENT_SHADER 0x00000020 +#define R300_NEW_FRAGMENT_SHADER_CONSTANTS 0x00000040 +#define R300_NEW_VERTEX_SHADER_CONSTANTS 0x10000000 +#define R300_NEW_QUERY 0x40000000 +#define R300_NEW_KITCHEN_SINK 0x7fffffff + +/* Tiling flags. */ +enum r300_buffer_tiling { + R300_BUFFER_LINEAR = 0, + R300_BUFFER_TILED, + R300_BUFFER_SQUARETILED +}; + +#endif diff --git a/src/gallium/drivers/r300/r300_render.c b/src/gallium/drivers/r300/r300_render.c index 2fed263a7a9..93bf388776c 100644 --- a/src/gallium/drivers/r300/r300_render.c +++ b/src/gallium/drivers/r300/r300_render.c @@ -41,9 +41,6 @@ #include "r300_render.h" #include "r300_state_derived.h" -/* r300_render: Vertex and index buffer primitive emission. */ -#define R300_MAX_VBO_SIZE (1024 * 1024) - /* XXX The DRM rejects VAP_ALT_NUM_VERTICES.. */ //#define ENABLE_ALT_NUM_VERTS @@ -689,9 +686,9 @@ static boolean r300_render_allocate_vertices(struct vbuf_render* render, r300render->vbo = pipe_buffer_create(screen, 64, PIPE_BUFFER_USAGE_VERTEX, - R300_MAX_VBO_SIZE); + R300_MAX_DRAW_VBO_SIZE); r300render->vbo_offset = 0; - r300render->vbo_size = R300_MAX_VBO_SIZE; + r300render->vbo_size = R300_MAX_DRAW_VBO_SIZE; } r300render->vertex_size = vertex_size; diff --git a/src/gallium/drivers/r300/r300_screen.h b/src/gallium/drivers/r300/r300_screen.h index c31f39e6917..a055159c93b 100644 --- a/src/gallium/drivers/r300/r300_screen.h +++ b/src/gallium/drivers/r300/r300_screen.h @@ -28,8 +28,6 @@ #include "r300_chipset.h" -#define R300_TEXTURE_USAGE_TRANSFER PIPE_TEXTURE_USAGE_CUSTOM - struct r300_screen { /* Parent class */ struct pipe_screen screen; diff --git a/src/gallium/drivers/r300/r300_winsys.h b/src/gallium/drivers/r300/r300_winsys.h index 1e6d43bea31..cd03355ab3e 100644 --- a/src/gallium/drivers/r300/r300_winsys.h +++ b/src/gallium/drivers/r300/r300_winsys.h @@ -30,6 +30,8 @@ #include "pipe/p_defines.h" #include "pipe/p_state.h" +#include "r300_defines.h" + struct r300_winsys_screen; /* Creates a new r300 screen. */ -- cgit v1.2.3 From 33d2349119ada410dbfbaa667fc7aef8b60d1a6f Mon Sep 17 00:00:00 2001 From: Marek Olšák Date: Sun, 21 Mar 2010 21:34:57 +0100 Subject: r300g: cleanup tiling flags propagation --- src/gallium/drivers/r300/r300_state.c | 16 ++++++++-------- src/gallium/drivers/r300/r300_texture.c | 4 ++-- src/gallium/drivers/r300/r300_winsys.h | 4 ++-- src/gallium/winsys/drm/radeon/core/radeon_buffer.h | 5 ++++- src/gallium/winsys/drm/radeon/core/radeon_drm_buffer.c | 9 ++++++--- src/gallium/winsys/drm/radeon/core/radeon_r300.c | 4 ++-- 6 files changed, 24 insertions(+), 18 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/r300/r300_state.c b/src/gallium/drivers/r300/r300_state.c index f396b42e950..397369015a5 100644 --- a/src/gallium/drivers/r300/r300_state.c +++ b/src/gallium/drivers/r300/r300_state.c @@ -528,8 +528,8 @@ static void r300_fb_update_tiling_flags(struct r300_context *r300, if (tex) { r300->rws->buffer_set_tiling(r300->rws, tex->buffer, tex->pitch[0], - tex->microtile != 0, - tex->macrotile != 0); + tex->microtile, + tex->macrotile); } } if (old_state->zsbuf && @@ -540,8 +540,8 @@ static void r300_fb_update_tiling_flags(struct r300_context *r300, if (tex) { r300->rws->buffer_set_tiling(r300->rws, tex->buffer, tex->pitch[0], - tex->microtile != 0, - tex->macrotile != 0); + tex->microtile, + tex->macrotile); } } @@ -552,8 +552,8 @@ static void r300_fb_update_tiling_flags(struct r300_context *r300, r300->rws->buffer_set_tiling(r300->rws, tex->buffer, tex->pitch[level], - tex->microtile != 0, - tex->mip_macrotile[level] != 0); + tex->microtile, + tex->mip_macrotile[level]); } if (new_state->zsbuf) { tex = (struct r300_texture*)new_state->zsbuf->texture; @@ -561,8 +561,8 @@ static void r300_fb_update_tiling_flags(struct r300_context *r300, r300->rws->buffer_set_tiling(r300->rws, tex->buffer, tex->pitch[level], - tex->microtile != 0, - tex->mip_macrotile[level] != 0); + tex->microtile, + tex->mip_macrotile[level]); } } diff --git a/src/gallium/drivers/r300/r300_texture.c b/src/gallium/drivers/r300/r300_texture.c index cb53619fe5e..2fa656067fa 100644 --- a/src/gallium/drivers/r300/r300_texture.c +++ b/src/gallium/drivers/r300/r300_texture.c @@ -777,8 +777,8 @@ static struct pipe_texture* r300_texture_create(struct pipe_screen* screen, tex->size); rws->buffer_set_tiling(rws, tex->buffer, tex->pitch[0], - tex->microtile != R300_BUFFER_LINEAR, - tex->macrotile != R300_BUFFER_LINEAR); + tex->microtile, + tex->macrotile); if (!tex->buffer) { FREE(tex); diff --git a/src/gallium/drivers/r300/r300_winsys.h b/src/gallium/drivers/r300/r300_winsys.h index cd03355ab3e..93f9dd7cfac 100644 --- a/src/gallium/drivers/r300/r300_winsys.h +++ b/src/gallium/drivers/r300/r300_winsys.h @@ -148,8 +148,8 @@ struct r300_winsys_screen { void (*buffer_set_tiling)(struct r300_winsys_screen *winsys, struct r300_winsys_buffer *buffer, uint32_t pitch, - boolean microtiled, - boolean macrotiled); + enum r300_buffer_tiling microtiled, + enum r300_buffer_tiling macrotiled); uint32_t (*get_value)(struct r300_winsys_screen *winsys, enum r300_value_id vid); diff --git a/src/gallium/winsys/drm/radeon/core/radeon_buffer.h b/src/gallium/winsys/drm/radeon/core/radeon_buffer.h index 3d14c861dfa..218a3763018 100644 --- a/src/gallium/winsys/drm/radeon/core/radeon_buffer.h +++ b/src/gallium/winsys/drm/radeon/core/radeon_buffer.h @@ -72,7 +72,10 @@ void radeon_drm_bufmgr_write_reloc(struct pb_buffer *_buf, struct pb_buffer *radeon_drm_bufmgr_create_buffer_from_handle(struct pb_manager *_mgr, uint32_t handle); -void radeon_drm_bufmgr_set_tiling(struct pb_buffer *_buf, boolean microtiled, boolean macrotiled, uint32_t pitch); +void radeon_drm_bufmgr_set_tiling(struct pb_buffer *_buf, + enum r300_buffer_tiling microtiled, + enum r300_buffer_tiling macrotiled, + uint32_t pitch); void radeon_drm_bufmgr_flush_maps(struct pb_manager *_mgr); diff --git a/src/gallium/winsys/drm/radeon/core/radeon_drm_buffer.c b/src/gallium/winsys/drm/radeon/core/radeon_drm_buffer.c index a8a7c45a96f..0a86acc2284 100644 --- a/src/gallium/winsys/drm/radeon/core/radeon_drm_buffer.c +++ b/src/gallium/winsys/drm/radeon/core/radeon_drm_buffer.c @@ -306,13 +306,16 @@ boolean radeon_drm_bufmgr_get_handle(struct pb_buffer *_buf, } -void radeon_drm_bufmgr_set_tiling(struct pb_buffer *_buf, boolean microtiled, boolean macrotiled, uint32_t pitch) +void radeon_drm_bufmgr_set_tiling(struct pb_buffer *_buf, + enum r300_buffer_tiling microtiled, + enum r300_buffer_tiling macrotiled, + uint32_t pitch) { struct radeon_drm_buffer *buf = get_drm_buffer(_buf); uint32_t flags = 0, old_flags, old_pitch; - if (microtiled) + if (microtiled == R300_BUFFER_TILED) flags |= RADEON_BO_FLAGS_MICRO_TILE; - if (macrotiled) + if (macrotiled == R300_BUFFER_TILED) flags |= RADEON_BO_FLAGS_MACRO_TILE; radeon_bo_get_tiling(buf->bo, &old_flags, &old_pitch); diff --git a/src/gallium/winsys/drm/radeon/core/radeon_r300.c b/src/gallium/winsys/drm/radeon/core/radeon_r300.c index 62d66d31dc1..0c0fee1586c 100644 --- a/src/gallium/winsys/drm/radeon/core/radeon_r300.c +++ b/src/gallium/winsys/drm/radeon/core/radeon_r300.c @@ -65,8 +65,8 @@ static void radeon_r300_winsys_buffer_destroy(struct r300_winsys_buffer *buf) static void radeon_r300_winsys_buffer_set_tiling(struct r300_winsys_screen *rws, struct r300_winsys_buffer *buf, uint32_t pitch, - boolean microtiled, - boolean macrotiled) + enum r300_buffer_tiling microtiled, + enum r300_buffer_tiling macrotiled) { struct pb_buffer *_buf = radeon_pb_buffer(buf); radeon_drm_bufmgr_set_tiling(_buf, microtiled, macrotiled, pitch); -- cgit v1.2.3 From 12dc4971735a8703c298d35eb21e3d1a2e053217 Mon Sep 17 00:00:00 2001 From: Marek Olšák Date: Sun, 14 Feb 2010 17:43:32 +0100 Subject: r300g: add and enable square microtiling It requires DRM 2.1.0 (e.g. kernel 2.6.34) and is disabled on older ones. Finally, the texture tiling implementation is now complete. Uff. --- src/gallium/drivers/r300/r300_texture.c | 11 ++++++----- src/gallium/drivers/r300/r300_winsys.h | 1 + src/gallium/winsys/drm/radeon/core/radeon_drm.c | 4 ++++ src/gallium/winsys/drm/radeon/core/radeon_drm_buffer.c | 6 ++++-- src/gallium/winsys/drm/radeon/core/radeon_r300.c | 2 ++ src/gallium/winsys/drm/radeon/core/radeon_winsys.h | 3 +++ 6 files changed, 20 insertions(+), 7 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/r300/r300_texture.c b/src/gallium/drivers/r300/r300_texture.c index 2fa656067fa..fe2ba60b9c9 100644 --- a/src/gallium/drivers/r300/r300_texture.c +++ b/src/gallium/drivers/r300/r300_texture.c @@ -715,6 +715,7 @@ static void r300_setup_flags(struct r300_texture* tex) static void r300_setup_tiling(struct pipe_screen *screen, struct r300_texture *tex) { + struct r300_winsys_screen *rws = (struct r300_winsys_screen *)screen->winsys; enum pipe_format format = tex->tex.format; boolean rv350_mode = r300_screen(screen)->caps->family >= CHIP_FAMILY_RV350; @@ -734,12 +735,12 @@ static void r300_setup_tiling(struct pipe_screen *screen, tex->microtile = R300_BUFFER_TILED; break; - /* XXX Square-tiling doesn't work with kernel older than 2.6.34, - * XXX need to check the DRM version */ - /*case 2: + case 2: case 8: - tex->microtile = R300_BUFFER_SQUARETILED; - break;*/ + if (rws->get_value(rws, R300_VID_SQUARE_TILING_SUPPORT)) { + tex->microtile = R300_BUFFER_SQUARETILED; + } + break; } /* Set macrotiling. */ diff --git a/src/gallium/drivers/r300/r300_winsys.h b/src/gallium/drivers/r300/r300_winsys.h index 93f9dd7cfac..acfa5dbeb9c 100644 --- a/src/gallium/drivers/r300/r300_winsys.h +++ b/src/gallium/drivers/r300/r300_winsys.h @@ -49,6 +49,7 @@ enum r300_value_id { R300_VID_PCI_ID, R300_VID_GB_PIPES, R300_VID_Z_PIPES, + R300_VID_SQUARE_TILING_SUPPORT }; struct r300_winsys_screen { diff --git a/src/gallium/winsys/drm/radeon/core/radeon_drm.c b/src/gallium/winsys/drm/radeon/core/radeon_drm.c index d70173e805d..7aa9c5425d6 100644 --- a/src/gallium/winsys/drm/radeon/core/radeon_drm.c +++ b/src/gallium/winsys/drm/radeon/core/radeon_drm.c @@ -93,6 +93,10 @@ static void do_ioctls(int fd, struct radeon_libdrm_winsys* winsys) exit(1); } + // Supported since 2.1.0. + winsys->squaretiling = version->version_major > 2 || + version->version_minor >= 1; + info.request = RADEON_INFO_DEVICE_ID; retval = drmCommandWriteRead(fd, DRM_RADEON_INFO, &info, sizeof(info)); if (retval) { diff --git a/src/gallium/winsys/drm/radeon/core/radeon_drm_buffer.c b/src/gallium/winsys/drm/radeon/core/radeon_drm_buffer.c index 0a86acc2284..e36bad7ea8c 100644 --- a/src/gallium/winsys/drm/radeon/core/radeon_drm_buffer.c +++ b/src/gallium/winsys/drm/radeon/core/radeon_drm_buffer.c @@ -314,9 +314,11 @@ void radeon_drm_bufmgr_set_tiling(struct pb_buffer *_buf, struct radeon_drm_buffer *buf = get_drm_buffer(_buf); uint32_t flags = 0, old_flags, old_pitch; if (microtiled == R300_BUFFER_TILED) - flags |= RADEON_BO_FLAGS_MICRO_TILE; + flags |= RADEON_BO_FLAGS_MICRO_TILE; + else if (microtiled == R300_BUFFER_SQUARETILED) + flags |= RADEON_BO_FLAGS_MICRO_TILE_SQUARE; if (macrotiled == R300_BUFFER_TILED) - flags |= RADEON_BO_FLAGS_MACRO_TILE; + flags |= RADEON_BO_FLAGS_MACRO_TILE; radeon_bo_get_tiling(buf->bo, &old_flags, &old_pitch); diff --git a/src/gallium/winsys/drm/radeon/core/radeon_r300.c b/src/gallium/winsys/drm/radeon/core/radeon_r300.c index 0c0fee1586c..38fcf889c8b 100644 --- a/src/gallium/winsys/drm/radeon/core/radeon_r300.c +++ b/src/gallium/winsys/drm/radeon/core/radeon_r300.c @@ -253,6 +253,8 @@ static uint32_t radeon_get_value(struct r300_winsys_screen *rws, return ws->gb_pipes; case R300_VID_Z_PIPES: return ws->z_pipes; + case R300_VID_SQUARE_TILING_SUPPORT: + return ws->squaretiling; } return 0; } diff --git a/src/gallium/winsys/drm/radeon/core/radeon_winsys.h b/src/gallium/winsys/drm/radeon/core/radeon_winsys.h index ad7b976abd2..4260dbaad72 100644 --- a/src/gallium/winsys/drm/radeon/core/radeon_winsys.h +++ b/src/gallium/winsys/drm/radeon/core/radeon_winsys.h @@ -57,6 +57,9 @@ struct radeon_libdrm_winsys { /* VRAM size. */ uint32_t vram_size; + /* Square tiling support. */ + boolean squaretiling; + /* DRM FD */ int fd; -- cgit v1.2.3 From 7733bac66c071a64cf12930b16b808b3450f853b Mon Sep 17 00:00:00 2001 From: Marek Olšák Date: Sun, 21 Mar 2010 21:47:41 +0100 Subject: r300g: accelerate blitting for all 64-bit texture formats --- src/gallium/drivers/r300/r300_blit.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/gallium') diff --git a/src/gallium/drivers/r300/r300_blit.c b/src/gallium/drivers/r300/r300_blit.c index f99f9dffaa5..bcdf950df9c 100644 --- a/src/gallium/drivers/r300/r300_blit.c +++ b/src/gallium/drivers/r300/r300_blit.c @@ -149,6 +149,9 @@ void r300_surface_copy(struct pipe_context* pipe, case 4: new_format = PIPE_FORMAT_B8G8R8A8_UNORM; break; + case 8: + new_format = PIPE_FORMAT_R16G16B16A16_UNORM; + break; default: debug_printf("r300: surface_copy: Unhandled format: %s. Falling back to software.\n" "r300: surface_copy: Software fallback doesn't work for tiled textures.\n", -- cgit v1.2.3 From 8bf9842fac00369b5cd3a82fb4d87db0e31848b8 Mon Sep 17 00:00:00 2001 From: Marek Olšák Date: Sun, 21 Mar 2010 22:05:27 +0100 Subject: r300g: fix scons build --- src/gallium/drivers/r300/r300_context.c | 4 ++-- src/gallium/drivers/r300/r300_cs.h | 3 +-- src/gallium/drivers/r300/r300_screen.c | 4 +--- src/gallium/drivers/r300/r300_state.c | 3 +-- src/gallium/drivers/r300/r300_texture.c | 3 +-- 5 files changed, 6 insertions(+), 11 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/r300/r300_context.c b/src/gallium/drivers/r300/r300_context.c index 60b441176d9..2bec946fe89 100644 --- a/src/gallium/drivers/r300/r300_context.c +++ b/src/gallium/drivers/r300/r300_context.c @@ -33,11 +33,11 @@ #include "r300_query.h" #include "r300_render.h" #include "r300_screen.h" +#include "r300_screen_buffer.h" #include "r300_state_invariant.h" #include "r300_texture.h" #include "r300_transfer.h" - -#include "radeon_winsys.h" +#include "r300_winsys.h" static void r300_destroy_context(struct pipe_context* context) { diff --git a/src/gallium/drivers/r300/r300_cs.h b/src/gallium/drivers/r300/r300_cs.h index ad07efbffdb..456b2ec7b92 100644 --- a/src/gallium/drivers/r300/r300_cs.h +++ b/src/gallium/drivers/r300/r300_cs.h @@ -26,8 +26,7 @@ #include "util/u_math.h" #include "r300_reg.h" - -#include "radeon_winsys.h" +#include "r300_winsys.h" /* Yes, I know macros are ugly. However, they are much prettier than the code * that they neatly hide away, and don't have the cost of function setup,so diff --git a/src/gallium/drivers/r300/r300_screen.c b/src/gallium/drivers/r300/r300_screen.c index 3e31688f8e8..bcb8b20f736 100644 --- a/src/gallium/drivers/r300/r300_screen.c +++ b/src/gallium/drivers/r300/r300_screen.c @@ -26,10 +26,8 @@ #include "r300_context.h" #include "r300_texture.h" - -#include "radeon_winsys.h" - #include "r300_screen_buffer.h" +#include "r300_winsys.h" /* Return the identifier behind whom the brave coders responsible for this * amalgamation of code, sweat, and duct tape, routinely obscure their names. diff --git a/src/gallium/drivers/r300/r300_state.c b/src/gallium/drivers/r300/r300_state.c index 397369015a5..31e32114b60 100644 --- a/src/gallium/drivers/r300/r300_state.c +++ b/src/gallium/drivers/r300/r300_state.c @@ -38,8 +38,7 @@ #include "r300_state_inlines.h" #include "r300_fs.h" #include "r300_vs.h" - -#include "radeon_winsys.h" +#include "r300_winsys.h" /* r300_state: Functions used to intialize state context by translating * Gallium state objects into semi-native r300 state objects. */ diff --git a/src/gallium/drivers/r300/r300_texture.c b/src/gallium/drivers/r300/r300_texture.c index fe2ba60b9c9..eaefd9d7d4e 100644 --- a/src/gallium/drivers/r300/r300_texture.c +++ b/src/gallium/drivers/r300/r300_texture.c @@ -31,8 +31,7 @@ #include "r300_texture.h" #include "r300_screen.h" #include "r300_state_inlines.h" - -#include "radeon_winsys.h" +#include "r300_winsys.h" #define TILE_WIDTH 0 #define TILE_HEIGHT 1 -- cgit v1.2.3 From 9fc6c8b831e5b43ae86ece6a531fc892f6f66356 Mon Sep 17 00:00:00 2001 From: Marek Olšák Date: Sun, 21 Mar 2010 22:17:14 +0100 Subject: r300g: disable tiling for YUV formats --- src/gallium/drivers/r300/r300_texture.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/r300/r300_texture.c b/src/gallium/drivers/r300/r300_texture.c index eaefd9d7d4e..1b796257e4f 100644 --- a/src/gallium/drivers/r300/r300_texture.c +++ b/src/gallium/drivers/r300/r300_texture.c @@ -45,6 +45,18 @@ static const unsigned microblock_table[5][3][2] = { {{ 2, 1}, {0, 0}, {0, 0}} /* 128 bits per pixel */ }; +/* Return true for non-compressed and non-YUV formats. */ +static boolean r300_format_is_plain(enum pipe_format format) +{ + const struct util_format_description *desc = util_format_description(format); + + if (!format) { + return FALSE; + } + + return desc->layout == UTIL_FORMAT_LAYOUT_PLAIN; +} + /* Translate a pipe_format into a useful texture format for sampling. * * Some special formats are translated directly using R300_EASY_TX_FORMAT, @@ -639,7 +651,7 @@ unsigned r300_texture_get_stride(struct r300_screen* screen, width = u_minify(tex->tex.width0, level); - if (!util_format_is_compressed(tex->tex.format)) { + if (r300_format_is_plain(tex->tex.format)) { tile_width = r300_texture_get_tile_size(tex, TILE_WIDTH, tex->mip_macrotile[level]); width = align(width, tile_width); @@ -657,7 +669,7 @@ static unsigned r300_texture_get_nblocksy(struct r300_texture* tex, height = u_minify(tex->tex.height0, level); - if (!util_format_is_compressed(tex->tex.format)) { + if (r300_format_is_plain(tex->tex.format)) { tile_height = r300_texture_get_tile_size(tex, TILE_HEIGHT, tex->mip_macrotile[level]); height = align(height, tile_height); @@ -718,7 +730,7 @@ static void r300_setup_tiling(struct pipe_screen *screen, enum pipe_format format = tex->tex.format; boolean rv350_mode = r300_screen(screen)->caps->family >= CHIP_FAMILY_RV350; - if (util_format_is_compressed(format)) { + if (!r300_format_is_plain(format)) { return; } -- cgit v1.2.3 From 4e3b950c70721b826c712636d37197dd5a76b910 Mon Sep 17 00:00:00 2001 From: Luca Barbieri Date: Mon, 22 Mar 2010 18:36:16 +0100 Subject: nvfx: fix sampler views support The code was half converted, resulting in texturing being totally broken. --- src/gallium/drivers/nvfx/nv30_fragtex.c | 2 +- src/gallium/drivers/nvfx/nv40_fragtex.c | 2 +- src/gallium/drivers/nvfx/nvfx_context.h | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/nvfx/nv30_fragtex.c b/src/gallium/drivers/nvfx/nv30_fragtex.c index 2b56f454921..54e47574c4d 100644 --- a/src/gallium/drivers/nvfx/nv30_fragtex.c +++ b/src/gallium/drivers/nvfx/nv30_fragtex.c @@ -91,7 +91,7 @@ struct nouveau_stateobj * nv30_fragtex_build(struct nvfx_context *nvfx, int unit) { struct nvfx_sampler_state *ps = nvfx->tex_sampler[unit]; - struct nvfx_miptree *nv30mt = nvfx->tex_miptree[unit]; + struct nvfx_miptree *nv30mt = (struct nvfx_miptree *)nvfx->fragment_sampler_views[unit]->texture; struct pipe_texture *pt = &nv30mt->base; struct nouveau_bo *bo = nouveau_bo(nv30mt->buffer); struct nv30_texture_format *tf; diff --git a/src/gallium/drivers/nvfx/nv40_fragtex.c b/src/gallium/drivers/nvfx/nv40_fragtex.c index 5889b5e40d5..05506e28099 100644 --- a/src/gallium/drivers/nvfx/nv40_fragtex.c +++ b/src/gallium/drivers/nvfx/nv40_fragtex.c @@ -109,7 +109,7 @@ struct nouveau_stateobj * nv40_fragtex_build(struct nvfx_context *nvfx, int unit) { struct nvfx_sampler_state *ps = nvfx->tex_sampler[unit]; - struct nvfx_miptree *nv40mt = nvfx->tex_miptree[unit]; + struct nvfx_miptree *nv40mt = (struct nvfx_miptree *)nvfx->fragment_sampler_views[unit]->texture; struct nouveau_bo *bo = nouveau_bo(nv40mt->buffer); struct pipe_texture *pt = &nv40mt->base; struct nv40_texture_format *tf; diff --git a/src/gallium/drivers/nvfx/nvfx_context.h b/src/gallium/drivers/nvfx/nvfx_context.h index 001b19eedf0..ab7225cf6c3 100644 --- a/src/gallium/drivers/nvfx/nvfx_context.h +++ b/src/gallium/drivers/nvfx/nvfx_context.h @@ -158,7 +158,6 @@ struct nvfx_context { struct pipe_buffer *idxbuf; unsigned idxbuf_format; struct nvfx_sampler_state *tex_sampler[PIPE_MAX_SAMPLERS]; - struct nvfx_miptree *tex_miptree[PIPE_MAX_SAMPLERS]; struct pipe_sampler_view *fragment_sampler_views[PIPE_MAX_SAMPLERS]; unsigned nr_samplers; unsigned nr_textures; -- cgit v1.2.3 From 45d1dc26072ea83ee10cf1c8907cfdf5df51928e Mon Sep 17 00:00:00 2001 From: Vinson Lee Date: Mon, 22 Mar 2010 11:34:18 -0700 Subject: cso: Remove unnecessary header. --- src/gallium/auxiliary/cso_cache/cso_context.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/gallium') diff --git a/src/gallium/auxiliary/cso_cache/cso_context.c b/src/gallium/auxiliary/cso_cache/cso_context.c index d6f8dd34bfa..6fd4bd36428 100644 --- a/src/gallium/auxiliary/cso_cache/cso_context.c +++ b/src/gallium/auxiliary/cso_cache/cso_context.c @@ -39,7 +39,6 @@ #include "util/u_inlines.h" #include "util/u_math.h" #include "util/u_memory.h" -#include "util/u_sampler.h" #include "tgsi/tgsi_parse.h" #include "cso_cache/cso_context.h" -- cgit v1.2.3 From ef2664da6c4db1b52ef351641e3ee949b87f9c7b Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 22 Mar 2010 15:55:43 -0600 Subject: st/glx: fix depth/stencil format selection code This fixes a pretty big performance regression caused by commit 3475e88442c16fb2b50b903fe246b3ebe49da226. When the user does not request a stencil buffer it's important that we don't use a depth/stencil format (or at least make it our last choice). If the user calls glClear(GL_DEPTH_BUFFER_BIT) when we have a combined depth/stencil buffer, that causes us to hit the clear_with_quad() path which can be much, much slower than calling pipe_context::clear(). Also, try to use a shallower depth format before a deeper one. --- src/gallium/state_trackers/glx/xlib/xm_api.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/glx/xlib/xm_api.c b/src/gallium/state_trackers/glx/xlib/xm_api.c index 62a2bfcfa07..8dd54206af2 100644 --- a/src/gallium/state_trackers/glx/xlib/xm_api.c +++ b/src/gallium/state_trackers/glx/xlib/xm_api.c @@ -309,8 +309,9 @@ choose_pixel_format(XMesaVisual v) return 0; } + /** - * Choose a depth/stencil format that is "better" than the given depth and + * Choose a depth/stencil format that satisfies the given depth and * stencil sizes. */ static enum pipe_format @@ -324,16 +325,20 @@ choose_depth_stencil_format(XMesaDisplay xmdpy, int depth, int stencil) int count, i; count = 0; + + if (depth <= 16 && stencil == 0) { + formats[count++] = PIPE_FORMAT_Z16_UNORM; + } + if (depth <= 24 && stencil == 0) { + formats[count++] = PIPE_FORMAT_X8Z24_UNORM; + formats[count++] = PIPE_FORMAT_Z24X8_UNORM; + } if (depth <= 24 && stencil <= 8) { formats[count++] = PIPE_FORMAT_S8Z24_UNORM; formats[count++] = PIPE_FORMAT_Z24S8_UNORM; } - - if (!stencil) { - if (depth <= 16) - formats[count++] = PIPE_FORMAT_Z16_UNORM; - if (depth <= 32) - formats[count++] = PIPE_FORMAT_Z32_UNORM; + if (depth <= 32 && stencil == 0) { + formats[count++] = PIPE_FORMAT_Z32_UNORM; } fmt = PIPE_FORMAT_NONE; -- cgit v1.2.3 From ca49a72a55895f8fefb090405a79918cbaa805ee Mon Sep 17 00:00:00 2001 From: Corbin Simpson Date: Mon, 22 Mar 2010 03:10:19 -0700 Subject: r300g: Cleanup a few old warnings. Those paths aren't important anymore, and a debugging warning won't stop a hardlock anyway. --- src/gallium/drivers/r300/r300_emit.c | 33 +++++++++------------------------ 1 file changed, 9 insertions(+), 24 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/r300/r300_emit.c b/src/gallium/drivers/r300/r300_emit.c index c897df628d2..796e3eca5bf 100644 --- a/src/gallium/drivers/r300/r300_emit.c +++ b/src/gallium/drivers/r300/r300_emit.c @@ -146,10 +146,8 @@ static const float * get_shader_constant( struct rc_constant * constant, struct r300_constant_buffer * externals) { - struct r300_viewport_state* viewport = - (struct r300_viewport_state*)r300->viewport_state.state; - struct r300_textures_state* texstate = - (struct r300_textures_state*)r300->textures_state.state; + struct r300_viewport_state* viewport = r300->viewport_state.state; + struct r300_textures_state* texstate = r300->textures_state.state; static float vec[4] = { 0.0, 0.0, 0.0, 1.0 }; struct pipe_texture *tex; @@ -900,12 +898,6 @@ void r300_emit_vs_state(struct r300_context* r300, unsigned size, void* state) CS_LOCALS(r300); - if (!r300screen->caps->has_tcl) { - debug_printf("r300: Implementation error: emit_vs_state called," - " but has_tcl is FALSE!\n"); - return; - } - BEGIN_CS(size); /* R300_VAP_PVS_CODE_CNTL_0 * R300_VAP_PVS_CONST_CNTL @@ -935,28 +927,19 @@ void r300_emit_vs_state(struct r300_context* r300, unsigned size, void* state) void r300_emit_vs_constant_buffer(struct r300_context* r300, struct rc_constant_list* constants) { - int i; struct r300_screen* r300screen = r300_screen(r300->context.screen); + unsigned i; CS_LOCALS(r300); - if (!r300screen->caps->has_tcl) { - debug_printf("r300: Implementation error: emit_vs_constant_buffer called," - " but has_tcl is FALSE!\n"); - return; - } - - if (constants->Count == 0) - return; - BEGIN_CS(constants->Count * 4 + 3); OUT_CS_REG(R300_VAP_PVS_VECTOR_INDX_REG, (r300screen->caps->is_r500 ? R500_PVS_CONST_START : R300_PVS_CONST_START)); OUT_CS_ONE_REG(R300_VAP_PVS_UPLOAD_DATA, constants->Count * 4); for (i = 0; i < constants->Count; i++) { - const float * data = get_shader_constant(r300, - &constants->Constants[i], - &r300->shader_constants[PIPE_SHADER_VERTEX]); + const float *data = get_shader_constant(r300, + &constants->Constants[i], + &r300->shader_constants[PIPE_SHADER_VERTEX]); OUT_CS_32F(data[0]); OUT_CS_32F(data[1]); OUT_CS_32F(data[2]); @@ -1167,7 +1150,9 @@ void r300_emit_dirty_state(struct r300_context* r300) if (r300->dirty_state & R300_NEW_VERTEX_SHADER_CONSTANTS) { struct r300_vertex_shader* vs = r300->vs_state.state; - r300_emit_vs_constant_buffer(r300, &vs->code.constants); + if (vs->code.constants.Count) { + r300_emit_vs_constant_buffer(r300, &vs->code.constants); + } r300->dirty_state &= ~R300_NEW_VERTEX_SHADER_CONSTANTS; } -- cgit v1.2.3 From ed61faec7ea307ff22738b4fcc96933f910e4145 Mon Sep 17 00:00:00 2001 From: Corbin Simpson Date: Mon, 22 Mar 2010 18:11:40 -0700 Subject: radeong: Always initialize this variable. May or may not be responsible for slight increases in ipers FPS. --- src/gallium/winsys/drm/radeon/core/radeon_drm_buffer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/winsys/drm/radeon/core/radeon_drm_buffer.c b/src/gallium/winsys/drm/radeon/core/radeon_drm_buffer.c index e36bad7ea8c..ec45abf4676 100644 --- a/src/gallium/winsys/drm/radeon/core/radeon_drm_buffer.c +++ b/src/gallium/winsys/drm/radeon/core/radeon_drm_buffer.c @@ -70,7 +70,7 @@ radeon_drm_buffer_map(struct pb_buffer *_buf, unsigned flags) { struct radeon_drm_buffer *buf = radeon_drm_buffer(_buf); - int write; + int write = 0; if (flags & PIPE_BUFFER_USAGE_DONTBLOCK) { if ((_buf->base.usage & PIPE_BUFFER_USAGE_VERTEX) || @@ -365,7 +365,7 @@ boolean radeon_drm_bufmgr_is_buffer_referenced(struct pb_buffer *_buf) return (radeon_bo_is_referenced_by_cs(buf->bo, buf->mgr->rws->cs) || radeon_bo_is_busy(buf->bo, &domain)); } - + void radeon_drm_bufmgr_flush_maps(struct pb_manager *_mgr) { -- cgit v1.2.3 From d5b2cecb03e8985aae589f1a8118e60eb693452a Mon Sep 17 00:00:00 2001 From: Corbin Simpson Date: Mon, 22 Mar 2010 18:12:16 -0700 Subject: gallium/docs: Cleanup and clarify point ras info. ...This state's interdependent? Really? Needs moar cleanup. --- src/gallium/docs/source/cso/rasterizer.rst | 76 +++++++++++++++++------------- 1 file changed, 44 insertions(+), 32 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/docs/source/cso/rasterizer.rst b/src/gallium/docs/source/cso/rasterizer.rst index ccd9136a2eb..e8dc82964fa 100644 --- a/src/gallium/docs/source/cso/rasterizer.rst +++ b/src/gallium/docs/source/cso/rasterizer.rst @@ -7,7 +7,7 @@ The rasterizer state controls the rendering of points, lines and triangles. Attributes include polygon culling state, line width, line stipple, multisample state, scissoring and flat/smooth shading. -Members +Shading ------- flatshade @@ -46,6 +46,49 @@ There are several important exceptions to the specification of this rule. second vertex, not the first. This permits each segment of the fan to have a different color. +Points +------ + +sprite_coord_enable +^^^^^^^^^^^^^^^^^^^ + +Specifies if a texture unit has its texture coordinates replaced or not. This +is a packed bitfield containing the enable for all texcoords -- if all bits +are zero, point sprites are effectively disabled. If any bit is set, then +point_smooth and point_quad_rasterization are ignored; point smoothing is +disabled and points are always rasterized as quads. If enabled, the four +vertices of the resulting quad will be assigned texture coordinates, +according to sprite_coord_mode. + +sprite_coord_mode +^^^^^^^^^^^^^^^^^ + +Specifies how the value for each shader output should be computed when drawing +point sprites. For PIPE_SPRITE_COORD_LOWER_LEFT, the lower-left vertex will +have coordinates (0,0,0,1). For PIPE_SPRITE_COORD_UPPER_LEFT, the upper-left +vertex will have coordinates (0,0,0,1). +This state is used by :ref:`Draw` to generate texcoords. + +.. note:: + + When geometry shaders are available, a special geometry shader could be + used instead of this functionality, to convert incoming points into quads + with the proper texture coordinates. + +point_quad_rasterization +^^^^^^^^^^^^^^^^^^^^^^^^ + +Determines if points should be rasterized as quads or points. Certain APIs, +like Direct3D, always use quad rasterization for points, regardless of +whether point sprites are enabled or not. If this state is enabled, point +smoothing and antialiasing are disabled, and sprite coordinates are not +generated. + +.. note:: + + Some renderers always internally translate points into quads; this state + still affects those renderers by overriding other rasterization state. + Other Members ^^^^^^^^^^^^^ @@ -107,37 +150,6 @@ point_size_per_vertex Whether vertices have a point size element. point_size The size of points, if not specified per-vertex. -sprite_coord_enable - Specifies if a coord has its texture coordinates replaced or not. This - is a packed bitfield containing the enable for all coords - if all are 0 - point sprites are effectively disabled, though points may still be - rendered slightly different according to point_quad_rasterization. - If any coord is non-zero, point_smooth should be disabled, and - point_quad_rasterization enabled. - If enabled, the four vertices of the resulting quad will be assigned - texture coordinates, according to sprite_coord_mode. -sprite_coord_mode - Specifies how the value for each shader output should be computed when - drawing sprites, for each coord which has sprite_coord_enable set. - For PIPE_SPRITE_COORD_LOWER_LEFT, the lower left vertex will have - coordinate (0,0,0,1). - For PIPE_SPRITE_COORD_UPPER_LEFT, the upper-left vertex will have - coordinate (0,0,0,1). - This state is needed by :ref:`Draw` because that's where each - point vertex is converted into four quad vertices. There's no other - place to emit the new vertex texture coordinates which are required for - sprite rendering. - Note that when geometry shaders are available, this state could be - removed. A special geometry shader defined by the state tracker could - convert the incoming points into quads with the proper texture coords. -point_quad_rasterization - This determines if points should be rasterized as quads or points. - d3d always uses quad rasterization for points, regardless if point sprites - are enabled or not, but OGL has different rules. If point_quad_rasterization - is set, point_smooth should be disabled, and points will be rendered as - squares even if multisample is enabled. - sprite_coord_enable should be zero if point_quad_rasterization is not - enabled. scissor Whether the scissor test is enabled. -- cgit v1.2.3 From 2a3accbc00c565e6641f926d6d3761249540fdea Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Mon, 22 Mar 2010 13:35:20 +1000 Subject: r300g: fix glean occlusion query test --- src/gallium/drivers/r300/r300_query.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/gallium') diff --git a/src/gallium/drivers/r300/r300_query.c b/src/gallium/drivers/r300/r300_query.c index ca00b043c51..9822e6b48dd 100644 --- a/src/gallium/drivers/r300/r300_query.c +++ b/src/gallium/drivers/r300/r300_query.c @@ -97,8 +97,10 @@ static void r300_end_query(struct pipe_context* pipe, struct pipe_query* query) { struct r300_context* r300 = r300_context(pipe); + struct r300_query* q = (struct r300_query*)query; r300_emit_query_end(r300); + q->begin_emitted = false; r300->query_current = NULL; } -- cgit v1.2.3 From 1f25eca311715f5ebceaee50ba4d68c3c9ea79a6 Mon Sep 17 00:00:00 2001 From: Marek Olšák Date: Tue, 23 Mar 2010 13:33:16 +0100 Subject: radeong: fix build issue with libdrm < 2.4.19 --- src/gallium/winsys/drm/radeon/core/radeon_drm.c | 3 +++ src/gallium/winsys/drm/radeon/core/radeon_drm_buffer.c | 3 +++ 2 files changed, 6 insertions(+) (limited to 'src/gallium') diff --git a/src/gallium/winsys/drm/radeon/core/radeon_drm.c b/src/gallium/winsys/drm/radeon/core/radeon_drm.c index 7aa9c5425d6..3dfcc5aef07 100644 --- a/src/gallium/winsys/drm/radeon/core/radeon_drm.c +++ b/src/gallium/winsys/drm/radeon/core/radeon_drm.c @@ -93,9 +93,12 @@ static void do_ioctls(int fd, struct radeon_libdrm_winsys* winsys) exit(1); } +/* XXX Remove this ifdef when libdrm version 2.4.19 becomes mandatory. */ +#ifdef RADEON_BO_FLAGS_MICRO_TILE_SQUARE // Supported since 2.1.0. winsys->squaretiling = version->version_major > 2 || version->version_minor >= 1; +#endif info.request = RADEON_INFO_DEVICE_ID; retval = drmCommandWriteRead(fd, DRM_RADEON_INFO, &info, sizeof(info)); diff --git a/src/gallium/winsys/drm/radeon/core/radeon_drm_buffer.c b/src/gallium/winsys/drm/radeon/core/radeon_drm_buffer.c index ec45abf4676..66f61322457 100644 --- a/src/gallium/winsys/drm/radeon/core/radeon_drm_buffer.c +++ b/src/gallium/winsys/drm/radeon/core/radeon_drm_buffer.c @@ -315,8 +315,11 @@ void radeon_drm_bufmgr_set_tiling(struct pb_buffer *_buf, uint32_t flags = 0, old_flags, old_pitch; if (microtiled == R300_BUFFER_TILED) flags |= RADEON_BO_FLAGS_MICRO_TILE; +/* XXX Remove this ifdef when libdrm version 2.4.19 becomes mandatory. */ +#ifdef RADEON_BO_FLAGS_MICRO_TILE_SQUARE else if (microtiled == R300_BUFFER_SQUARETILED) flags |= RADEON_BO_FLAGS_MICRO_TILE_SQUARE; +#endif if (macrotiled == R300_BUFFER_TILED) flags |= RADEON_BO_FLAGS_MACRO_TILE; -- cgit v1.2.3 From 3e17a5b047124c46ee45dbd1848127c67e0d62f3 Mon Sep 17 00:00:00 2001 From: Luca Barbieri Date: Mon, 15 Mar 2010 18:36:27 +0100 Subject: dri: test whether the built drivers have unresolved symbols This is a different approach to solving this problem that the patch I previously posted, and unlike that, should not cause any problems. Right now undefined symbols in DRI drivers will still allow the build to succeed. As a result, people modifying drivers they cannot test risk creating unloadable drivers with no easy way of automatically avoiding it. For instance, the modifications to nv50 for context transfers caused such an issue recently. Unfortunately, just adding -Wl,--no-undefined doesn't work, because the DRI drivers depend on glapi symbols, but do not depend on libGL.so.1 Adding -lGL is not the correct solution since DRI drivers are not loaded just by libGL, but also by X and possibly by other clients. So, this patch simply tries to build an executable linked to the DRI driver and to libGL. If the DRI driver contains any undefined symbols not satisfied by its dependencies or by libGL, this will fail. This solution does not alter the built drivers, and does not significantly slow down the build process. All classic DRI drivers as well as all the Gallium drivers with configure options compiled successfully with this change. Thanks to Xavier Chantry and Michel Daenzer for helping with this. Signed-off-by: Luca Barbieri Acked-by: Brian Paul --- src/gallium/winsys/drm/Makefile.template | 7 +++++-- src/mesa/drivers/dri/Makefile.template | 7 +++++-- src/mesa/drivers/dri/common/dri_test.c | 10 ++++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 src/mesa/drivers/dri/common/dri_test.c (limited to 'src/gallium') diff --git a/src/gallium/winsys/drm/Makefile.template b/src/gallium/winsys/drm/Makefile.template index f4cc0def471..9f984f1090c 100644 --- a/src/gallium/winsys/drm/Makefile.template +++ b/src/gallium/winsys/drm/Makefile.template @@ -64,11 +64,14 @@ SHARED_INCLUDES = \ default: depend symlinks $(TOP)/$(LIB_DIR)/gallium/$(LIBNAME) $(LIBNAME): $(OBJECTS) $(MESA_MODULES) $(PIPE_DRIVERS) Makefile \ - $(TOP)/src/mesa/drivers/dri/Makefile.template - $(MKLIB) -o $@ -noprefix -linker '$(CC)' -ldflags '$(LDFLAGS)' \ + $(TOP)/src/mesa/drivers/dri/Makefile.template $(TOP)/src/mesa/drivers/dri/common/dri_test.o + $(MKLIB) -o $@.tmp -noprefix -linker '$(CC)' -ldflags '$(LDFLAGS)' \ $(OBJECTS) $(PIPE_DRIVERS) \ -Wl,--start-group $(MESA_MODULES) -Wl,--end-group \ $(DRI_LIB_DEPS) $(DRIVER_EXTRAS) + $(CC) -o $@.test $(TOP)/src/mesa/drivers/dri/common/dri_test.o $@.tmp -L$(TOP)/lib -lGL + @rm -f $@.test + mv $@.tmp $@ $(TOP)/$(LIB_DIR)/gallium: mkdir -p $@ diff --git a/src/mesa/drivers/dri/Makefile.template b/src/mesa/drivers/dri/Makefile.template index a0c25d26cdf..2b7634bbf6c 100644 --- a/src/mesa/drivers/dri/Makefile.template +++ b/src/mesa/drivers/dri/Makefile.template @@ -51,9 +51,12 @@ lib: symlinks subdirs depend @$(MAKE) $(LIBNAME) $(TOP)/$(LIB_DIR)/$(LIBNAME) $(LIBNAME): $(OBJECTS) $(MESA_MODULES) $(EXTRA_MODULES) Makefile \ - $(TOP)/src/mesa/drivers/dri/Makefile.template - $(MKLIB) -o $@ -noprefix -linker '$(CC)' -ldflags '$(LDFLAGS)' \ + $(TOP)/src/mesa/drivers/dri/Makefile.template $(TOP)/src/mesa/drivers/dri/common/dri_test.o + $(MKLIB) -o $@.tmp -noprefix -linker '$(CC)' -ldflags '$(LDFLAGS)' \ $(OBJECTS) $(MESA_MODULES) $(EXTRA_MODULES) $(DRI_LIB_DEPS) + $(CC) -o $@.test $(TOP)/src/mesa/drivers/dri/common/dri_test.o $@.tmp -L$(TOP)/lib -lGL + @rm -f $@.test + mv $@.tmp $@ $(TOP)/$(LIB_DIR)/$(LIBNAME): $(LIBNAME) diff --git a/src/mesa/drivers/dri/common/dri_test.c b/src/mesa/drivers/dri/common/dri_test.c new file mode 100644 index 00000000000..cf59b2b7378 --- /dev/null +++ b/src/mesa/drivers/dri/common/dri_test.c @@ -0,0 +1,10 @@ +/* This is just supposed to make sure we get a reference to + the driver entry symbol that the compiler doesn't optimize away */ + +extern char __driDriverExtensions[]; + +int main(int argc, char** argv) +{ + void* p = __driDriverExtensions; + return (int)(unsigned long)p; +} -- cgit v1.2.3 From c652ad907f0715a0c23476ebd48ab722c96a5064 Mon Sep 17 00:00:00 2001 From: Luca Barbieri Date: Wed, 17 Mar 2010 15:44:45 +0100 Subject: nvfx: fix/workaround nv3x hwtnl issues This patch re-emits the viewport state on framebuffer or rasterizer change. This seems to be necessary on nv3x, but the reason is not fully understood. It is quite likely that this isn't really the correct fix, but seems to work, and makes nv3x much better. --- src/gallium/drivers/nvfx/nvfx_state_viewport.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/nvfx/nvfx_state_viewport.c b/src/gallium/drivers/nvfx/nvfx_state_viewport.c index 82e0e9220b0..ec730e3a9e9 100644 --- a/src/gallium/drivers/nvfx/nvfx_state_viewport.c +++ b/src/gallium/drivers/nvfx/nvfx_state_viewport.c @@ -1,15 +1,16 @@ #include "nvfx_context.h" +/* Having this depend on FB and RAST looks wrong, but it seems + necessary to make this work on nv3x + TODO: find the right fix +*/ + static boolean nvfx_state_viewport_validate(struct nvfx_context *nvfx) { struct pipe_viewport_state *vpt = &nvfx->viewport; struct nouveau_stateobj *so; - if (nvfx->state.hw[NVFX_STATE_VIEWPORT] && - !(nvfx->dirty & NVFX_NEW_VIEWPORT)) - return FALSE; - so = so_new(2, 9, 0); so_method(so, nvfx->screen->eng3d, NV34TCL_VIEWPORT_TRANSLATE_X, 8); @@ -45,7 +46,7 @@ nvfx_state_viewport_validate(struct nvfx_context *nvfx) struct nvfx_state_entry nvfx_state_viewport = { .validate = nvfx_state_viewport_validate, .dirty = { - .pipe = NVFX_NEW_VIEWPORT, + .pipe = NVFX_NEW_VIEWPORT | NVFX_NEW_FB | NVFX_NEW_RAST, .hw = NVFX_STATE_VIEWPORT } }; -- cgit v1.2.3 From a6cc9cf38d6e01d39b34f17a51c42e2d4962c0c9 Mon Sep 17 00:00:00 2001 From: Luca Barbieri Date: Wed, 17 Mar 2010 20:31:56 +0100 Subject: nvfx: stop incessantly spewing debug messages on the terminal Currently we are continuously spewing messages about these variables since we call debug_get_bool_option everytime we want to check their value. This is annoying, slows things down due to terminal rerendering and obscures useful messages. This patch only calls debug_get_bool_option once and caches the result in a static variable. --- src/gallium/drivers/nvfx/nvfx_miptree.c | 5 ++++- src/gallium/drivers/nvfx/nvfx_transfer.c | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/nvfx/nvfx_miptree.c b/src/gallium/drivers/nvfx/nvfx_miptree.c index 0f5ed61aab7..9de25175e78 100644 --- a/src/gallium/drivers/nvfx/nvfx_miptree.c +++ b/src/gallium/drivers/nvfx/nvfx_miptree.c @@ -67,6 +67,9 @@ nvfx_miptree_create(struct pipe_screen *pscreen, const struct pipe_texture *pt) struct nvfx_miptree *mt; unsigned buf_usage = PIPE_BUFFER_USAGE_PIXEL | NOUVEAU_BUFFER_USAGE_TEXTURE; + static int no_swizzle = -1; + if(no_swizzle < 0) + no_swizzle = debug_get_bool_option("NOUVEAU_NO_SWIZZLE", FALSE); mt = MALLOC(sizeof(struct nvfx_miptree)); if (!mt) @@ -106,7 +109,7 @@ nvfx_miptree_create(struct pipe_screen *pscreen, const struct pipe_texture *pt) case PIPE_FORMAT_B8G8R8X8_UNORM: case PIPE_FORMAT_R16_SNORM: { - if (debug_get_bool_option("NOUVEAU_NO_SWIZZLE", FALSE)) + if (no_swizzle) mt->base.tex_usage |= NOUVEAU_TEXTURE_USAGE_LINEAR; break; } diff --git a/src/gallium/drivers/nvfx/nvfx_transfer.c b/src/gallium/drivers/nvfx/nvfx_transfer.c index 409b354d582..c81b44a789b 100644 --- a/src/gallium/drivers/nvfx/nvfx_transfer.c +++ b/src/gallium/drivers/nvfx/nvfx_transfer.c @@ -42,6 +42,9 @@ nvfx_transfer_new(struct pipe_context *pcontext, struct pipe_texture *pt, struct nvfx_miptree *mt = (struct nvfx_miptree *)pt; struct nvfx_transfer *tx; struct pipe_texture tx_tex_template, *tx_tex; + static int no_transfer = -1; + if(no_transfer < 0) + no_transfer = debug_get_bool_option("NOUVEAU_NO_TRANSFER", TRUE/*XXX:FALSE*/); tx = CALLOC_STRUCT(nvfx_transfer); if (!tx) @@ -59,8 +62,7 @@ nvfx_transfer_new(struct pipe_context *pcontext, struct pipe_texture *pt, tx->base.zslice = zslice; /* Direct access to texture */ - if ((pt->tex_usage & PIPE_TEXTURE_USAGE_DYNAMIC || - debug_get_bool_option("NOUVEAU_NO_TRANSFER", TRUE/*XXX:FALSE*/)) && + if ((pt->tex_usage & PIPE_TEXTURE_USAGE_DYNAMIC || no_transfer) && pt->tex_usage & NOUVEAU_TEXTURE_USAGE_LINEAR) { tx->direct = true; -- cgit v1.2.3 From e14d812e158a667ffb096a99e2510da326155670 Mon Sep 17 00:00:00 2001 From: Luca Barbieri Date: Wed, 17 Mar 2010 22:31:29 +0100 Subject: nvfx: fix coding style in nvfx_transfer.c --- src/gallium/drivers/nvfx/nvfx_transfer.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/nvfx/nvfx_transfer.c b/src/gallium/drivers/nvfx/nvfx_transfer.c index c81b44a789b..1c250e9fe44 100644 --- a/src/gallium/drivers/nvfx/nvfx_transfer.c +++ b/src/gallium/drivers/nvfx/nvfx_transfer.c @@ -33,12 +33,12 @@ nvfx_compatible_transfer_tex(struct pipe_texture *pt, unsigned width, unsigned h } static struct pipe_transfer * -nvfx_transfer_new(struct pipe_context *pcontext, struct pipe_texture *pt, +nvfx_transfer_new(struct pipe_context *pipe, struct pipe_texture *pt, unsigned face, unsigned level, unsigned zslice, enum pipe_transfer_usage usage, unsigned x, unsigned y, unsigned w, unsigned h) { - struct pipe_screen *pscreen = pcontext->screen; + struct pipe_screen *pscreen = pipe->screen; struct nvfx_miptree *mt = (struct nvfx_miptree *)pt; struct nvfx_transfer *tx; struct pipe_texture tx_tex_template, *tx_tex; @@ -120,13 +120,13 @@ nvfx_transfer_new(struct pipe_context *pcontext, struct pipe_texture *pt, } static void -nvfx_transfer_del(struct pipe_context *pcontext, +nvfx_transfer_del(struct pipe_context *pipe, struct pipe_transfer *ptx) { struct nvfx_transfer *tx = (struct nvfx_transfer *)ptx; if (!tx->direct && (ptx->usage & PIPE_TRANSFER_WRITE)) { - struct pipe_screen *pscreen = pcontext->screen; + struct pipe_screen *pscreen = pipe->screen; struct nvfx_screen *nvscreen = nvfx_screen(pscreen); struct pipe_surface *dst; @@ -149,9 +149,9 @@ nvfx_transfer_del(struct pipe_context *pcontext, } static void * -nvfx_transfer_map(struct pipe_context *pcontext, struct pipe_transfer *ptx) +nvfx_transfer_map(struct pipe_context *pipe, struct pipe_transfer *ptx) { - struct pipe_screen *pscreen = pcontext->screen; + struct pipe_screen *pscreen = pipe->screen; struct nvfx_transfer *tx = (struct nvfx_transfer *)ptx; struct nv04_surface *ns = (struct nv04_surface *)tx->surface; struct nvfx_miptree *mt = (struct nvfx_miptree *)tx->surface->texture; @@ -165,9 +165,9 @@ nvfx_transfer_map(struct pipe_context *pcontext, struct pipe_transfer *ptx) } static void -nvfx_transfer_unmap(struct pipe_context *pcontext, struct pipe_transfer *ptx) +nvfx_transfer_unmap(struct pipe_context *pipe, struct pipe_transfer *ptx) { - struct pipe_screen *pscreen = pcontext->screen; + struct pipe_screen *pscreen = pipe->screen; struct nvfx_transfer *tx = (struct nvfx_transfer *)ptx; struct nvfx_miptree *mt = (struct nvfx_miptree *)tx->surface->texture; -- cgit v1.2.3 From 83f4c444f4e630fe2bfd17ad750f3f17ceff13f6 Mon Sep 17 00:00:00 2001 From: Luca Barbieri Date: Sun, 17 Jan 2010 22:27:53 +0100 Subject: nvfx: don't crash on empty fragment program --- src/gallium/drivers/nvfx/nvfx_fragprog.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/nvfx/nvfx_fragprog.c b/src/gallium/drivers/nvfx/nvfx_fragprog.c index 76351430f44..b9c91cec8ce 100644 --- a/src/gallium/drivers/nvfx/nvfx_fragprog.c +++ b/src/gallium/drivers/nvfx/nvfx_fragprog.c @@ -803,7 +803,8 @@ nvfx_fragprog_translate(struct nvfx_context *nvfx, fp->fp_control |= fpc->num_regs << NV40TCL_FP_CONTROL_TEMP_COUNT_SHIFT; /* Terminate final instruction */ - fp->insn[fpc->inst_offset] |= 0x00000001; + if(fp->insn) + fp->insn[fpc->inst_offset] |= 0x00000001; /* Append NOP + END instruction, may or may not be necessary. */ fpc->inst_offset = fp->insn_len; -- cgit v1.2.3 From 4ceeb1307a018f426784620d3376f9f1ea07e53b Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Tue, 23 Mar 2010 08:58:09 -0600 Subject: st/glx: better format selection in xmesa_choose_z_stencil_format() This is a back-port of commit ef2664da6c4db1b52ef351641e3ee949b87f9c7b from master. --- src/gallium/state_trackers/glx/xlib/xm_api.c | 41 ++++++++++++++++------------ 1 file changed, 24 insertions(+), 17 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/glx/xlib/xm_api.c b/src/gallium/state_trackers/glx/xlib/xm_api.c index 217bdeff75e..e8524a21c21 100644 --- a/src/gallium/state_trackers/glx/xlib/xm_api.c +++ b/src/gallium/state_trackers/glx/xlib/xm_api.c @@ -324,7 +324,7 @@ choose_pixel_format(XMesaVisual v) * at least matches the given depthBits and stencilBits. */ static void -xmesa_choose_z_stencil_format(int depthBits, int stencilBits, +xmesa_choose_z_stencil_format(int depth, int stencil, enum pipe_format *depthFormat, enum pipe_format *stencilFormat) { @@ -332,20 +332,28 @@ xmesa_choose_z_stencil_format(int depthBits, int stencilBits, const unsigned tex_usage = PIPE_TEXTURE_USAGE_DEPTH_STENCIL; const unsigned geom_flags = (PIPE_TEXTURE_GEOM_NON_SQUARE | PIPE_TEXTURE_GEOM_NON_POWER_OF_TWO); - static enum pipe_format formats[] = { - PIPE_FORMAT_S8Z24_UNORM, - PIPE_FORMAT_Z24S8_UNORM, - PIPE_FORMAT_Z16_UNORM, - PIPE_FORMAT_Z32_UNORM - }; - int i; + enum pipe_format formats[8]; + int count, i; - assert(screen); + count = 0; - *depthFormat = *stencilFormat = PIPE_FORMAT_NONE; + if (depth <= 16 && stencil == 0) { + formats[count++] = PIPE_FORMAT_Z16_UNORM; + } + if (depth <= 24 && stencil == 0) { + formats[count++] = PIPE_FORMAT_X8Z24_UNORM; + formats[count++] = PIPE_FORMAT_Z24X8_UNORM; + } + if (depth <= 24 && stencil <= 8) { + formats[count++] = PIPE_FORMAT_S8Z24_UNORM; + formats[count++] = PIPE_FORMAT_Z24S8_UNORM; + } + if (depth <= 32 && stencil == 0) { + formats[count++] = PIPE_FORMAT_Z32_UNORM; + } - /* search for supported format */ - for (i = 0; i < Elements(formats); i++) { + *depthFormat = PIPE_FORMAT_NONE; + for (i = 0; i < count; i++) { if (screen->is_format_supported(screen, formats[i], target, tex_usage, geom_flags)) { *depthFormat = formats[i]; @@ -353,13 +361,12 @@ xmesa_choose_z_stencil_format(int depthBits, int stencilBits, } } - if (stencilBits) { + if (stencil) { *stencilFormat = *depthFormat; } - - /* XXX we should check that he chosen format has at least as many bits - * as what was requested. - */ + else { + *stencilFormat = PIPE_FORMAT_NONE; + } } -- cgit v1.2.3 From fc1ba0423ac31cff14346dbc888255fb5fd7d1b2 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Tue, 23 Mar 2010 09:00:19 -0600 Subject: softpipe: add special cases for all Z compare modes for 16-bit Z buffer We had fast paths for PIPE_FUNC_LESS and LEQUAL before. To satisfy OpenGL invariance rules, all depth compare modes should produce the same fragment Z values. Fixes progs/demos/singlebuffer.c --- src/gallium/drivers/softpipe/sp_quad_depth_test.c | 221 +++++---------------- .../drivers/softpipe/sp_quad_depth_test_tmp.h | 147 ++++++++++++++ 2 files changed, 195 insertions(+), 173 deletions(-) create mode 100644 src/gallium/drivers/softpipe/sp_quad_depth_test_tmp.h (limited to 'src/gallium') diff --git a/src/gallium/drivers/softpipe/sp_quad_depth_test.c b/src/gallium/drivers/softpipe/sp_quad_depth_test.c index 4815a0d49f1..5854cee1be0 100644 --- a/src/gallium/drivers/softpipe/sp_quad_depth_test.c +++ b/src/gallium/drivers/softpipe/sp_quad_depth_test.c @@ -730,169 +730,36 @@ depth_test_quads_fallback(struct quad_stage *qs, /** - * Special-case Z testing for 16-bit Zbuffer, PIPE_FUNC_LESS and - * Z buffer writes enabled. - * - * NOTE: there's no guarantee that the quads are sequentially side by - * side. The fragment shader may have culled some quads, etc. Sliver - * triangles may generate non-sequential quads. + * Special-case Z testing for 16-bit Zbuffer and Z buffer writes enabled. */ -static void -depth_interp_z16_less_write(struct quad_stage *qs, - struct quad_header *quads[], - unsigned nr) -{ - unsigned i, pass = 0; - const unsigned ix = quads[0]->input.x0; - const unsigned iy = quads[0]->input.y0; - const float fx = (float) ix; - const float fy = (float) iy; - const float dzdx = quads[0]->posCoef->dadx[2]; - const float dzdy = quads[0]->posCoef->dady[2]; - const float z0 = quads[0]->posCoef->a0[2] + dzdx * fx + dzdy * fy; - struct softpipe_cached_tile *tile; - ushort (*depth16)[TILE_SIZE]; - ushort init_idepth[4], idepth[4], depth_step; - const float scale = 65535.0; - - /* compute scaled depth of the four pixels in first quad */ - init_idepth[0] = (ushort)((z0) * scale); - init_idepth[1] = (ushort)((z0 + dzdx) * scale); - init_idepth[2] = (ushort)((z0 + dzdy) * scale); - init_idepth[3] = (ushort)((z0 + dzdx + dzdy) * scale); - - depth_step = (ushort)(dzdx * scale); - - tile = sp_get_cached_tile(qs->softpipe->zsbuf_cache, ix, iy); - - for (i = 0; i < nr; i++) { - const unsigned outmask = quads[i]->inout.mask; - const int dx = quads[i]->input.x0 - ix; - unsigned mask = 0; - - /* compute depth for this quad */ - idepth[0] = init_idepth[0] + dx * depth_step; - idepth[1] = init_idepth[1] + dx * depth_step; - idepth[2] = init_idepth[2] + dx * depth_step; - idepth[3] = init_idepth[3] + dx * depth_step; - - depth16 = (ushort (*)[TILE_SIZE]) - &tile->data.depth16[iy % TILE_SIZE][(ix + dx)% TILE_SIZE]; - - if ((outmask & 1) && idepth[0] < depth16[0][0]) { - depth16[0][0] = idepth[0]; - mask |= (1 << 0); - } - - if ((outmask & 2) && idepth[1] < depth16[0][1]) { - depth16[0][1] = idepth[1]; - mask |= (1 << 1); - } - - if ((outmask & 4) && idepth[2] < depth16[1][0]) { - depth16[1][0] = idepth[2]; - mask |= (1 << 2); - } - - if ((outmask & 8) && idepth[3] < depth16[1][1]) { - depth16[1][1] = idepth[3]; - mask |= (1 << 3); - } - - quads[i]->inout.mask = mask; - if (quads[i]->inout.mask) - quads[pass++] = quads[i]; - } - - if (pass) - qs->next->run(qs->next, quads, pass); - -} - - -/** - * Special-case Z testing for 16-bit Zbuffer, PIPE_FUNC_LEQUAL and - * Z buffer writes enabled. - * - * NOTE: there's no guarantee that the quads are sequentially side by - * side. The fragment shader may have culled some quads, etc. Sliver - * triangles may generate non-sequential quads. - */ -static void -depth_interp_z16_lequal_write(struct quad_stage *qs, - struct quad_header *quads[], - unsigned nr) -{ - unsigned i, pass = 0; - const unsigned ix = quads[0]->input.x0; - const unsigned iy = quads[0]->input.y0; - const float fx = (float) ix; - const float fy = (float) iy; - const float dzdx = quads[0]->posCoef->dadx[2]; - const float dzdy = quads[0]->posCoef->dady[2]; - const float z0 = quads[0]->posCoef->a0[2] + dzdx * fx + dzdy * fy; - struct softpipe_cached_tile *tile; - ushort (*depth16)[TILE_SIZE]; - ushort init_idepth[4], idepth[4], depth_step; - const float scale = 65535.0; - - /* compute scaled depth of the four pixels in first quad */ - init_idepth[0] = (ushort)((z0) * scale); - init_idepth[1] = (ushort)((z0 + dzdx) * scale); - init_idepth[2] = (ushort)((z0 + dzdy) * scale); - init_idepth[3] = (ushort)((z0 + dzdx + dzdy) * scale); - - depth_step = (ushort)(dzdx * scale); - - tile = sp_get_cached_tile(qs->softpipe->zsbuf_cache, ix, iy); - - for (i = 0; i < nr; i++) { - const unsigned outmask = quads[i]->inout.mask; - const int dx = quads[i]->input.x0 - ix; - unsigned mask = 0; - - /* compute depth for this quad */ - idepth[0] = init_idepth[0] + dx * depth_step; - idepth[1] = init_idepth[1] + dx * depth_step; - idepth[2] = init_idepth[2] + dx * depth_step; - idepth[3] = init_idepth[3] + dx * depth_step; - - depth16 = (ushort (*)[TILE_SIZE]) - &tile->data.depth16[iy % TILE_SIZE][(ix + dx)% TILE_SIZE]; - if ((outmask & 1) && idepth[0] <= depth16[0][0]) { - depth16[0][0] = idepth[0]; - mask |= (1 << 0); - } - - if ((outmask & 2) && idepth[1] <= depth16[0][1]) { - depth16[0][1] = idepth[1]; - mask |= (1 << 1); - } +#define NAME depth_interp_z16_less_write +#define OPERATOR < +#include "sp_quad_depth_test_tmp.h" - if ((outmask & 4) && idepth[2] <= depth16[1][0]) { - depth16[1][0] = idepth[2]; - mask |= (1 << 2); - } +#define NAME depth_interp_z16_equal_write +#define OPERATOR == +#include "sp_quad_depth_test_tmp.h" - if ((outmask & 8) && idepth[3] <= depth16[1][1]) { - depth16[1][1] = idepth[3]; - mask |= (1 << 3); - } +#define NAME depth_interp_z16_lequal_write +#define OPERATOR <= +#include "sp_quad_depth_test_tmp.h" - depth16 = (ushort (*)[TILE_SIZE]) &depth16[0][2]; +#define NAME depth_interp_z16_greater_write +#define OPERATOR > +#include "sp_quad_depth_test_tmp.h" - quads[i]->inout.mask = mask; - if (quads[i]->inout.mask) - quads[pass++] = quads[i]; - } - - if (pass) - qs->next->run(qs->next, quads, pass); - -} +#define NAME depth_interp_z16_notequal_write +#define OPERATOR != +#include "sp_quad_depth_test_tmp.h" +#define NAME depth_interp_z16_gequal_write +#define OPERATOR >= +#include "sp_quad_depth_test_tmp.h" +#define NAME depth_interp_z16_always_write +#define ALWAYS 1 +#include "sp_quad_depth_test_tmp.h" @@ -926,6 +793,10 @@ choose_depth_test(struct quad_stage *qs, boolean occlusion = qs->softpipe->active_query_count; + /* default */ + qs->run = depth_test_quads_fallback; + + /* look for special cases */ if (!alpha && !depth && !stencil) { @@ -938,36 +809,40 @@ choose_depth_test(struct quad_stage *qs, !occlusion && !stencil) { - switch (depthfunc) { - case PIPE_FUNC_LESS: - switch (qs->softpipe->framebuffer.zsbuf->format) { - case PIPE_FORMAT_Z16_UNORM: + if (qs->softpipe->framebuffer.zsbuf->format == PIPE_FORMAT_Z16_UNORM) { + switch (depthfunc) { + case PIPE_FUNC_NEVER: + qs->run = depth_test_quads_fallback; + break; + case PIPE_FUNC_LESS: qs->run = depth_interp_z16_less_write; break; - default: - qs->run = depth_test_quads_fallback; + case PIPE_FUNC_EQUAL: + qs->run = depth_interp_z16_equal_write; break; - } - break; - case PIPE_FUNC_LEQUAL: - switch (qs->softpipe->framebuffer.zsbuf->format) { - case PIPE_FORMAT_Z16_UNORM: + case PIPE_FUNC_LEQUAL: qs->run = depth_interp_z16_lequal_write; break; + case PIPE_FUNC_GREATER: + qs->run = depth_interp_z16_greater_write; + break; + case PIPE_FUNC_NOTEQUAL: + qs->run = depth_interp_z16_notequal_write; + break; + case PIPE_FUNC_GEQUAL: + qs->run = depth_interp_z16_gequal_write; + break; + case PIPE_FUNC_ALWAYS: + qs->run = depth_interp_z16_always_write; + break; default: qs->run = depth_test_quads_fallback; break; } - break; - default: - qs->run = depth_test_quads_fallback; } } - else { - qs->run = depth_test_quads_fallback; - } - + /* next quad/fragment stage */ qs->run( qs, quads, nr ); } diff --git a/src/gallium/drivers/softpipe/sp_quad_depth_test_tmp.h b/src/gallium/drivers/softpipe/sp_quad_depth_test_tmp.h new file mode 100644 index 00000000000..25af415c256 --- /dev/null +++ b/src/gallium/drivers/softpipe/sp_quad_depth_test_tmp.h @@ -0,0 +1,147 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +/* + * Template for generating Z test functions + * Only PIPE_FORMAT_Z16_UNORM supported at this time. + */ + + +#ifndef NAME +#error "NAME is not defined!" +#endif + +#if !defined(OPERATOR) && !defined(ALWAYS) +#error "neither OPERATOR nor ALWAYS is defined!" +#endif + + +/* + * NOTE: there's no guarantee that the quads are sequentially side by + * side. The fragment shader may have culled some quads, etc. Sliver + * triangles may generate non-sequential quads. + */ +static void +NAME(struct quad_stage *qs, + struct quad_header *quads[], + unsigned nr) +{ + unsigned i, pass = 0; + const unsigned ix = quads[0]->input.x0; + const unsigned iy = quads[0]->input.y0; + const float fx = (float) ix; + const float fy = (float) iy; + const float dzdx = quads[0]->posCoef->dadx[2]; + const float dzdy = quads[0]->posCoef->dady[2]; + const float z0 = quads[0]->posCoef->a0[2] + dzdx * fx + dzdy * fy; + struct softpipe_cached_tile *tile; + ushort (*depth16)[TILE_SIZE]; + ushort init_idepth[4], idepth[4], depth_step; + const float scale = 65535.0; + + /* compute scaled depth of the four pixels in first quad */ + init_idepth[0] = (ushort)((z0) * scale); + init_idepth[1] = (ushort)((z0 + dzdx) * scale); + init_idepth[2] = (ushort)((z0 + dzdy) * scale); + init_idepth[3] = (ushort)((z0 + dzdx + dzdy) * scale); + + depth_step = (ushort)(dzdx * scale); + + tile = sp_get_cached_tile(qs->softpipe->zsbuf_cache, ix, iy); + + for (i = 0; i < nr; i++) { + const unsigned outmask = quads[i]->inout.mask; + const int dx = quads[i]->input.x0 - ix; + unsigned mask = 0; + + /* compute depth for this quad */ + idepth[0] = init_idepth[0] + dx * depth_step; + idepth[1] = init_idepth[1] + dx * depth_step; + idepth[2] = init_idepth[2] + dx * depth_step; + idepth[3] = init_idepth[3] + dx * depth_step; + + depth16 = (ushort (*)[TILE_SIZE]) + &tile->data.depth16[iy % TILE_SIZE][(ix + dx)% TILE_SIZE]; + +#ifdef ALWAYS + if (outmask & 1) { + depth16[0][0] = idepth[0]; + mask |= (1 << 0); + } + + if (outmask & 2) { + depth16[0][1] = idepth[1]; + mask |= (1 << 1); + } + + if (outmask & 4) { + depth16[1][0] = idepth[2]; + mask |= (1 << 2); + } + + if (outmask & 8) { + depth16[1][1] = idepth[3]; + mask |= (1 << 3); + } +#else + /* Note: OPERATOR appears here: */ + if ((outmask & 1) && (idepth[0] OPERATOR depth16[0][0])) { + depth16[0][0] = idepth[0]; + mask |= (1 << 0); + } + + if ((outmask & 2) && (idepth[1] OPERATOR depth16[0][1])) { + depth16[0][1] = idepth[1]; + mask |= (1 << 1); + } + + if ((outmask & 4) && (idepth[2] OPERATOR depth16[1][0])) { + depth16[1][0] = idepth[2]; + mask |= (1 << 2); + } + + if ((outmask & 8) && (idepth[3] OPERATOR depth16[1][1])) { + depth16[1][1] = idepth[3]; + mask |= (1 << 3); + } +#endif + + depth16 = (ushort (*)[TILE_SIZE]) &depth16[0][2]; + + quads[i]->inout.mask = mask; + if (quads[i]->inout.mask) + quads[pass++] = quads[i]; + } + + if (pass) + qs->next->run(qs->next, quads, pass); +} + + +#undef NAME +#undef OPERATOR +#undef ALWAYS -- cgit v1.2.3 From ff54af530bc17429eda73a761dd6b73e3ec0d6ef Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Tue, 23 Mar 2010 09:08:35 -0600 Subject: softpipe: comments, re-formatting, etc --- src/gallium/drivers/softpipe/sp_quad_depth_test.c | 38 ++++++++++++++--------- 1 file changed, 24 insertions(+), 14 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/softpipe/sp_quad_depth_test.c b/src/gallium/drivers/softpipe/sp_quad_depth_test.c index 5854cee1be0..17cd5b82072 100644 --- a/src/gallium/drivers/softpipe/sp_quad_depth_test.c +++ b/src/gallium/drivers/softpipe/sp_quad_depth_test.c @@ -1,6 +1,7 @@ /************************************************************************** * * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * Copyright 2010 VMware, Inc. * All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a @@ -18,7 +19,7 @@ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * IN NO EVENT SHALL THE AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -26,7 +27,7 @@ **************************************************************************/ /** - * \brief Quad depth testing + * \brief Quad depth / stencil testing */ #include "pipe/p_defines.h" @@ -96,7 +97,9 @@ get_depth_stencil_values( struct depth_data *data, } } -/* If the shader has not been run, interpolate the depth values + +/** + * If the shader has not been run, interpolate the depth values * ourselves. */ static void @@ -115,6 +118,9 @@ interpolate_quad_depth( struct quad_header *quad ) } +/** + * Compute the depth_data::qzzzz[] values from the float fragment Z values. + */ static void convert_quad_depth( struct depth_data *data, const struct quad_header *quad ) @@ -173,6 +179,9 @@ convert_quad_depth( struct depth_data *data, +/** + * Write data->bzzzz[] values and data->stencilVals into the Z/stencil buffer. + */ static void write_depth_stencil_values( struct depth_data *data, struct quad_header *quad ) @@ -225,7 +234,6 @@ write_depth_stencil_values( struct depth_data *data, - /** Only 8-bit stencil supported */ #define STENCIL_MAX 0xff @@ -408,12 +416,11 @@ apply_stencil_op(struct depth_data *data, -/* +/** * To increase efficiency, we should probably have multiple versions * of this function that are specifically for Z16, Z32 and FP Z buffers. * Try to effectively do that with codegen... */ - static boolean depth_test_quad(struct quad_stage *qs, struct depth_data *data, @@ -523,7 +530,6 @@ depth_stencil_test_quad(struct quad_stage *qs, wrtMask = softpipe->depth_stencil->stencil[face].writemask; valMask = softpipe->depth_stencil->stencil[face].valuemask; - /* do the stencil test first */ { unsigned passMask, failMask; @@ -563,7 +569,7 @@ depth_stencil_test_quad(struct quad_stage *qs, #define ALPHATEST( FUNC, COMP ) \ - static int \ + static int \ alpha_test_quads_##FUNC( struct quad_stage *qs, \ struct quad_header *quads[], \ unsigned nr ) \ @@ -629,6 +635,7 @@ alpha_test_quads(struct quad_stage *qs, } } + static unsigned mask_count[16] = { 0, /* 0x0 */ @@ -665,6 +672,9 @@ get_depth_bits(struct quad_stage *qs) +/** + * General depth/stencil test function. Used when there's no fast-path. + */ static void depth_test_quads_fallback(struct quad_stage *qs, struct quad_header *quads[], @@ -712,7 +722,6 @@ depth_test_quads_fallback(struct quad_stage *qs, write_depth_stencil_values(&data, quads[i]); } - quads[pass++] = quads[i]; } @@ -848,22 +857,23 @@ choose_depth_test(struct quad_stage *qs, - - -static void depth_test_begin(struct quad_stage *qs) +static void +depth_test_begin(struct quad_stage *qs) { qs->run = choose_depth_test; qs->next->begin(qs->next); } -static void depth_test_destroy(struct quad_stage *qs) +static void +depth_test_destroy(struct quad_stage *qs) { FREE( qs ); } -struct quad_stage *sp_quad_depth_test_stage( struct softpipe_context *softpipe ) +struct quad_stage * +sp_quad_depth_test_stage(struct softpipe_context *softpipe) { struct quad_stage *stage = CALLOC_STRUCT(quad_stage); -- cgit v1.2.3 From fff86eb0aab506fdfe3e956587d453c52ab07730 Mon Sep 17 00:00:00 2001 From: Luca Barbieri Date: Tue, 23 Mar 2010 17:55:38 +0100 Subject: dri: use mv -f instead of mv to ensure no prompting occurs Using just mv may cause prompts on some systems/configurations. --- src/gallium/winsys/drm/Makefile.template | 2 +- src/mesa/drivers/dri/Makefile.template | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/winsys/drm/Makefile.template b/src/gallium/winsys/drm/Makefile.template index 9f984f1090c..7146e112d04 100644 --- a/src/gallium/winsys/drm/Makefile.template +++ b/src/gallium/winsys/drm/Makefile.template @@ -71,7 +71,7 @@ $(LIBNAME): $(OBJECTS) $(MESA_MODULES) $(PIPE_DRIVERS) Makefile \ $(DRI_LIB_DEPS) $(DRIVER_EXTRAS) $(CC) -o $@.test $(TOP)/src/mesa/drivers/dri/common/dri_test.o $@.tmp -L$(TOP)/lib -lGL @rm -f $@.test - mv $@.tmp $@ + mv -f $@.tmp $@ $(TOP)/$(LIB_DIR)/gallium: mkdir -p $@ diff --git a/src/mesa/drivers/dri/Makefile.template b/src/mesa/drivers/dri/Makefile.template index 2b7634bbf6c..15682b76ff1 100644 --- a/src/mesa/drivers/dri/Makefile.template +++ b/src/mesa/drivers/dri/Makefile.template @@ -56,7 +56,7 @@ $(LIBNAME): $(OBJECTS) $(MESA_MODULES) $(EXTRA_MODULES) Makefile \ $(OBJECTS) $(MESA_MODULES) $(EXTRA_MODULES) $(DRI_LIB_DEPS) $(CC) -o $@.test $(TOP)/src/mesa/drivers/dri/common/dri_test.o $@.tmp -L$(TOP)/lib -lGL @rm -f $@.test - mv $@.tmp $@ + mv -f $@.tmp $@ $(TOP)/$(LIB_DIR)/$(LIBNAME): $(LIBNAME) -- cgit v1.2.3 From 208f5bf3cd8555f5b896c3e9d60c26f1bdb8683c Mon Sep 17 00:00:00 2001 From: Luca Barbieri Date: Tue, 23 Mar 2010 16:34:51 +0100 Subject: nvfx: delay allocation of buffers in GART/VRAM to validation time Currently we allocate buffers in GART or VRAM at creation time. However, when using swtnl, this results in reads from uncached memory, which drastically impair performance. So, for now, cause nouveau_screen.c to not pass any placement flags to buffer creation, so that the buffers are moved later. Previously libdrm itself did this, but was changed to not to do it. This may introduce an extra copy in normal usage, but this currently does not seem to introduce significant performance degradation. This will be revisited when pipebuffer is integrated. Note that for AGP systems, properly solving this may be complex since currently there is no fast way of reading from GART/VRAM. We will probably need to try mapping AGP as writethrough and, in addition, make buffer creation more aware of future buffer usage. --- src/gallium/drivers/nvfx/nvfx_screen.c | 6 ++---- src/gallium/drivers/nvfx/nvfx_vbo.c | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/nvfx/nvfx_screen.c b/src/gallium/drivers/nvfx/nvfx_screen.c index 8138715cc7d..6cbd8b23e1f 100644 --- a/src/gallium/drivers/nvfx/nvfx_screen.c +++ b/src/gallium/drivers/nvfx/nvfx_screen.c @@ -68,11 +68,9 @@ nvfx_screen_get_param(struct pipe_screen *pscreen, int param) case PIPE_CAP_BLEND_EQUATION_SEPARATE: return !!screen->is_nv4x; case NOUVEAU_CAP_HW_VTXBUF: - /* TODO: this is almost surely wrong */ - return !!screen->is_nv4x; + return 0; case NOUVEAU_CAP_HW_IDXBUF: - /* TODO: this is also almost surely wrong */ - return screen->is_nv4x && screen->eng3d->grclass == NV40TCL; + return 0; case PIPE_CAP_MAX_COMBINED_SAMPLERS: return 16; case PIPE_CAP_INDEP_BLEND_ENABLE: diff --git a/src/gallium/drivers/nvfx/nvfx_vbo.c b/src/gallium/drivers/nvfx/nvfx_vbo.c index 257087f8f63..db47acb9502 100644 --- a/src/gallium/drivers/nvfx/nvfx_vbo.c +++ b/src/gallium/drivers/nvfx/nvfx_vbo.c @@ -495,7 +495,7 @@ nvfx_vbo_validate(struct nvfx_context *nvfx) struct nouveau_grobj *eng3d = nvfx->screen->eng3d; struct pipe_buffer *ib = nvfx->idxbuf; unsigned ib_format = nvfx->idxbuf_format; - unsigned vb_flags = NOUVEAU_BO_VRAM | NOUVEAU_BO_GART | NOUVEAU_BO_RD; + unsigned vb_flags = NOUVEAU_BO_GART | NOUVEAU_BO_RD; int hw; vtxbuf = so_new(3, 17, 18); -- cgit v1.2.3 From 3428a305150e98c8002e0fb339f5667c5533c0d1 Mon Sep 17 00:00:00 2001 From: Luca Barbieri Date: Mon, 11 Jan 2010 03:13:42 +0100 Subject: nvfx: add NOUVEAU_VTXIDX_IN_VRAM variable to put vertex/index buffers in VRAM On some systems, putting vertex and index buffers in VRAM instead of GART memory eliminates massive graphics corruption which is otherwise present, due to unclear causes. This patch adds an environment variable that does that, along with helpful messages. It turns it on by default on G7x, as it is what I am seeing corruption on and some other reports also seemed to pinpoint these cards. --- src/gallium/drivers/nvfx/nvfx_screen.c | 31 +++++++++++++++++++++++++++++++ src/gallium/drivers/nvfx/nvfx_screen.h | 1 + src/gallium/drivers/nvfx/nvfx_vbo.c | 2 +- 3 files changed, 33 insertions(+), 1 deletion(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/nvfx/nvfx_screen.c b/src/gallium/drivers/nvfx/nvfx_screen.c index 6cbd8b23e1f..f7f39218944 100644 --- a/src/gallium/drivers/nvfx/nvfx_screen.c +++ b/src/gallium/drivers/nvfx/nvfx_screen.c @@ -293,6 +293,36 @@ static void nv40_screen_init(struct nvfx_screen *screen, struct nouveau_stateobj so_data (so, 0x00000001); } +static void +nvfx_screen_init_buffer_functions(struct nvfx_screen* screen) +{ + int vram_hack_default = 0; + int vram_hack; + // TODO: this is a bit of a guess; also add other cards that may need this hack. + // It may also depend on the specific card or the AGP/PCIe chipset. + if(screen->base.device->chipset == 0x47 /* G70 */ + || screen->base.device->chipset == 0x49 /* G71 */ + || screen->base.device->chipset == 0x46 /* G72 */ + ) + vram_hack_default = 1; + vram_hack = debug_get_bool_option("NOUVEAU_VTXIDX_IN_VRAM", vram_hack_default); + +#ifdef DEBUG + if(!vram_hack) + { + fprintf(stderr, "Some systems may experience graphics corruption due to randomly misplaced vertices.\n" + "If this is happening, export NOUVEAU_VTXIDX_IN_VRAM=1 may reduce or eliminate the problem\n"); + } + else + { + fprintf(stderr, "A performance reducing hack is being used to help avoid graphics corruption.\n" + "You can try export NOUVEAU_VTXIDX_IN_VRAM=0 to disable it.\n"); + } +#endif + + screen->vertex_buffer_flags = vram_hack ? NOUVEAU_BO_VRAM : NOUVEAU_BO_GART; +} + struct pipe_screen * nvfx_screen_create(struct pipe_winsys *ws, struct nouveau_device *dev) { @@ -350,6 +380,7 @@ nvfx_screen_create(struct pipe_winsys *ws, struct nouveau_device *dev) return NULL; } + nvfx_screen_init_buffer_functions(screen); nvfx_screen_init_miptree_functions(pscreen); ret = nouveau_grobj_alloc(chan, 0xbeef3097, eng3d_class, &screen->eng3d); diff --git a/src/gallium/drivers/nvfx/nvfx_screen.h b/src/gallium/drivers/nvfx/nvfx_screen.h index c0b4b9899dd..baa848c47aa 100644 --- a/src/gallium/drivers/nvfx/nvfx_screen.h +++ b/src/gallium/drivers/nvfx/nvfx_screen.h @@ -12,6 +12,7 @@ struct nvfx_screen { struct nvfx_context *cur_ctx; unsigned is_nv4x; /* either 0 or ~0 */ + int vertex_buffer_flags; /* HW graphics objects */ struct nv04_surface_2d *eng2d; diff --git a/src/gallium/drivers/nvfx/nvfx_vbo.c b/src/gallium/drivers/nvfx/nvfx_vbo.c index db47acb9502..c26536b0e77 100644 --- a/src/gallium/drivers/nvfx/nvfx_vbo.c +++ b/src/gallium/drivers/nvfx/nvfx_vbo.c @@ -495,7 +495,7 @@ nvfx_vbo_validate(struct nvfx_context *nvfx) struct nouveau_grobj *eng3d = nvfx->screen->eng3d; struct pipe_buffer *ib = nvfx->idxbuf; unsigned ib_format = nvfx->idxbuf_format; - unsigned vb_flags = NOUVEAU_BO_GART | NOUVEAU_BO_RD; + unsigned vb_flags = nvfx->screen->vertex_buffer_flags | NOUVEAU_BO_RD; int hw; vtxbuf = so_new(3, 17, 18); -- cgit v1.2.3 From ba5a53edd12fac24c176e714560b1f9ec255bbdb Mon Sep 17 00:00:00 2001 From: Kristian Høgsberg Date: Tue, 23 Mar 2010 15:47:49 -0400 Subject: dri: Add $(DRI_LIB_DEPS) when linking the test binary This will make sure we pick up libdrm_$(chipset).so from the right place. --- src/gallium/winsys/drm/Makefile.template | 2 +- src/mesa/drivers/dri/Makefile.template | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/winsys/drm/Makefile.template b/src/gallium/winsys/drm/Makefile.template index 7146e112d04..8c16094688c 100644 --- a/src/gallium/winsys/drm/Makefile.template +++ b/src/gallium/winsys/drm/Makefile.template @@ -69,7 +69,7 @@ $(LIBNAME): $(OBJECTS) $(MESA_MODULES) $(PIPE_DRIVERS) Makefile \ $(OBJECTS) $(PIPE_DRIVERS) \ -Wl,--start-group $(MESA_MODULES) -Wl,--end-group \ $(DRI_LIB_DEPS) $(DRIVER_EXTRAS) - $(CC) -o $@.test $(TOP)/src/mesa/drivers/dri/common/dri_test.o $@.tmp -L$(TOP)/lib -lGL + $(CC) -o $@.test $(TOP)/src/mesa/drivers/dri/common/dri_test.o $@.tmp $(DRI_LIB_DEPS) -L$(TOP)/lib -lGL @rm -f $@.test mv -f $@.tmp $@ diff --git a/src/mesa/drivers/dri/Makefile.template b/src/mesa/drivers/dri/Makefile.template index 15682b76ff1..cd800e5e017 100644 --- a/src/mesa/drivers/dri/Makefile.template +++ b/src/mesa/drivers/dri/Makefile.template @@ -54,7 +54,7 @@ $(LIBNAME): $(OBJECTS) $(MESA_MODULES) $(EXTRA_MODULES) Makefile \ $(TOP)/src/mesa/drivers/dri/Makefile.template $(TOP)/src/mesa/drivers/dri/common/dri_test.o $(MKLIB) -o $@.tmp -noprefix -linker '$(CC)' -ldflags '$(LDFLAGS)' \ $(OBJECTS) $(MESA_MODULES) $(EXTRA_MODULES) $(DRI_LIB_DEPS) - $(CC) -o $@.test $(TOP)/src/mesa/drivers/dri/common/dri_test.o $@.tmp -L$(TOP)/lib -lGL + $(CC) -o $@.test $(TOP)/src/mesa/drivers/dri/common/dri_test.o $@.tmp $(DRI_LIB_DEPS) -L$(TOP)/lib -lGL @rm -f $@.test mv -f $@.tmp $@ -- cgit v1.2.3 From e725ef171b5a4d5425461f237d9ccab223806913 Mon Sep 17 00:00:00 2001 From: Dan Nicholson Date: Mon, 15 Mar 2010 20:53:56 -0700 Subject: Change libX11 variables to not conflict with AC_PATH_XTRA The variable X_LIBS from AC_PATH_XTRA contains only the -L searchdir parameter and not the -lX11 to link to Xlib. Use X11 prefixed build vars for linking with Xlib to avoid the conflict. Signed-off-by: Dan Nicholson --- configs/autoconf.in | 4 ++-- configure.ac | 6 +++++- progs/egl/Makefile | 6 +++--- progs/xdemos/Makefile | 2 +- src/gallium/state_trackers/glx/xlib/Makefile | 2 +- src/gallium/winsys/xlib/Makefile | 2 +- 6 files changed, 13 insertions(+), 9 deletions(-) (limited to 'src/gallium') diff --git a/configs/autoconf.in b/configs/autoconf.in index f50fb7dd093..66c1ee48e87 100644 --- a/configs/autoconf.in +++ b/configs/autoconf.in @@ -24,8 +24,8 @@ RADEON_CFLAGS = @RADEON_CFLAGS@ RADEON_LDFLAGS = @RADEON_LDFLAGS@ INTEL_LIBS = @INTEL_LIBS@ INTEL_CFLAGS = @INTEL_CFLAGS@ -X_LIBS = @X_LIBS@ -X_CFLAGS = @X_CFLAGS@ +X11_LIBS = @X11_LIBS@ +X11_CFLAGS = @X11_CFLAGS@ # Assembler MESA_ASM_SOURCES = @MESA_ASM_SOURCES@ diff --git a/configure.ac b/configure.ac index 0f51097ef62..26960e85ea4 100644 --- a/configure.ac +++ b/configure.ac @@ -548,9 +548,13 @@ else fi dnl Use the autoconf macro if no pkg-config files if test "$x11_pkgconfig" = yes; then - PKG_CHECK_MODULES([X], [x11]) + PKG_CHECK_MODULES([X11], [x11]) else AC_PATH_XTRA + test -z "$X11_CFLAGS" && X11_CFLAGS="$X_CFLAGS" + test -z "$X11_LIBS" && X11_LIBS="$X_LIBS -lX11" + AC_SUBST([X11_CFLAGS]) + AC_SUBST([X11_LIBS]) fi dnl Try to tell the user that the --x-* options are only used when diff --git a/progs/egl/Makefile b/progs/egl/Makefile index 5f51104fed6..8dfcb4eabcb 100644 --- a/progs/egl/Makefile +++ b/progs/egl/Makefile @@ -57,13 +57,13 @@ peglgears: peglgears.o $(HEADERS) $(LIB_DEP) $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) $(LIBDRM_LIB) -lm xeglgears: xeglgears.o $(HEADERS) $(LIB_DEP) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lm $(X_LIBS) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lm $(X11_LIBS) xeglthreads: xeglthreads.o $(HEADERS) $(LIB_DEP) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lm $(X_LIBS) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lm $(X11_LIBS) xegl_tri: xegl_tri.o $(HEADERS) $(LIB_DEP) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lm $(X_LIBS) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) -lm $(X11_LIBS) clean: -rm -f *.o *~ diff --git a/progs/xdemos/Makefile b/progs/xdemos/Makefile index f81aafe00f6..660c540657a 100644 --- a/progs/xdemos/Makefile +++ b/progs/xdemos/Makefile @@ -9,7 +9,7 @@ INCDIR = $(TOP)/include LIB_DEP = $(TOP)/$(LIB_DIR)/$(GL_LIB_NAME) # Add X11 and pthread libs to satisfy GNU gold. -APP_LIB_DEPS += $(X_LIBS) -lpthread +APP_LIB_DEPS += $(X11_LIBS) -lpthread LIBS = -L$(TOP)/$(LIB_DIR) -l$(GL_LIB) $(APP_LIB_DEPS) diff --git a/src/gallium/state_trackers/glx/xlib/Makefile b/src/gallium/state_trackers/glx/xlib/Makefile index 582e72bb463..35509fd708b 100644 --- a/src/gallium/state_trackers/glx/xlib/Makefile +++ b/src/gallium/state_trackers/glx/xlib/Makefile @@ -6,7 +6,7 @@ LIBNAME = xlib LIBRARY_INCLUDES = \ -I$(TOP)/include \ -I$(TOP)/src/mesa \ - $(X_CFLAGS) + $(X11_CFLAGS) C_SOURCES = \ glx_api.c \ diff --git a/src/gallium/winsys/xlib/Makefile b/src/gallium/winsys/xlib/Makefile index 18357a41127..83d53c59542 100644 --- a/src/gallium/winsys/xlib/Makefile +++ b/src/gallium/winsys/xlib/Makefile @@ -7,7 +7,7 @@ LIBRARY_INCLUDES = \ -I$(TOP)/src/gallium/include \ -I$(TOP)/src/gallium/drivers \ -I$(TOP)/src/gallium/auxiliary \ - $(X_CFLAGS) + $(X11_CFLAGS) C_SOURCES = \ xlib_sw_winsys.c -- cgit v1.2.3 From 7e246e6aa63979d53731a591f4caee3651c1d96b Mon Sep 17 00:00:00 2001 From: Luca Barbieri Date: Tue, 23 Mar 2010 21:10:07 +0100 Subject: dri: make unresolved symbol test link work even without a libGL.so Currently the test link uses -lGL to define the glapi symbols. This makes it impossible to build DRI drivers on systems without Mesa installed and without building the libGL from the Mesa tree first. Some automated build systems trigger this problem. This commit removes -lGL and instead adds a dummy implementation of glapi to dri_test.c This, along with Kristian's commit, should fix all known regressions due to the addition of unresolved symbol checking. --- src/gallium/winsys/drm/Makefile.template | 2 +- src/mesa/drivers/dri/Makefile.template | 2 +- src/mesa/drivers/dri/common/dri_test.c | 68 ++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 2 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/winsys/drm/Makefile.template b/src/gallium/winsys/drm/Makefile.template index 8c16094688c..6d9b81aa249 100644 --- a/src/gallium/winsys/drm/Makefile.template +++ b/src/gallium/winsys/drm/Makefile.template @@ -69,7 +69,7 @@ $(LIBNAME): $(OBJECTS) $(MESA_MODULES) $(PIPE_DRIVERS) Makefile \ $(OBJECTS) $(PIPE_DRIVERS) \ -Wl,--start-group $(MESA_MODULES) -Wl,--end-group \ $(DRI_LIB_DEPS) $(DRIVER_EXTRAS) - $(CC) -o $@.test $(TOP)/src/mesa/drivers/dri/common/dri_test.o $@.tmp $(DRI_LIB_DEPS) -L$(TOP)/lib -lGL + $(CC) -o $@.test $(TOP)/src/mesa/drivers/dri/common/dri_test.o $@.tmp $(DRI_LIB_DEPS) @rm -f $@.test mv -f $@.tmp $@ diff --git a/src/mesa/drivers/dri/Makefile.template b/src/mesa/drivers/dri/Makefile.template index cd800e5e017..f19cc039b22 100644 --- a/src/mesa/drivers/dri/Makefile.template +++ b/src/mesa/drivers/dri/Makefile.template @@ -54,7 +54,7 @@ $(LIBNAME): $(OBJECTS) $(MESA_MODULES) $(EXTRA_MODULES) Makefile \ $(TOP)/src/mesa/drivers/dri/Makefile.template $(TOP)/src/mesa/drivers/dri/common/dri_test.o $(MKLIB) -o $@.tmp -noprefix -linker '$(CC)' -ldflags '$(LDFLAGS)' \ $(OBJECTS) $(MESA_MODULES) $(EXTRA_MODULES) $(DRI_LIB_DEPS) - $(CC) -o $@.test $(TOP)/src/mesa/drivers/dri/common/dri_test.o $@.tmp $(DRI_LIB_DEPS) -L$(TOP)/lib -lGL + $(CC) -o $@.test $(TOP)/src/mesa/drivers/dri/common/dri_test.o $@.tmp $(DRI_LIB_DEPS) @rm -f $@.test mv -f $@.tmp $@ diff --git a/src/mesa/drivers/dri/common/dri_test.c b/src/mesa/drivers/dri/common/dri_test.c index cf59b2b7378..f55ec6d52be 100644 --- a/src/mesa/drivers/dri/common/dri_test.c +++ b/src/mesa/drivers/dri/common/dri_test.c @@ -1,8 +1,76 @@ +#include "main/glheader.h" +#include "main/compiler.h" +#include "glapi/glapi.h" + /* This is just supposed to make sure we get a reference to the driver entry symbol that the compiler doesn't optimize away */ extern char __driDriverExtensions[]; +/* provide glapi symbols */ + +#if defined(GLX_USE_TLS) + +PUBLIC __thread struct _glapi_table * _glapi_tls_Dispatch + __attribute__((tls_model("initial-exec"))); + +PUBLIC __thread void * _glapi_tls_Context + __attribute__((tls_model("initial-exec"))); + +#endif + +PUBLIC const struct _glapi_table *_glapi_Dispatch; +PUBLIC const void *_glapi_Context; + +PUBLIC void +_glapi_check_multithread(void) +{} + +PUBLIC void +_glapi_set_context(void *context) +{} + +PUBLIC void * +_glapi_get_context(void) +{ + return 0; +} + +PUBLIC void +_glapi_set_dispatch(struct _glapi_table *dispatch) +{} + +PUBLIC struct _glapi_table * +_glapi_get_dispatch(void) +{ + return 0; +} + +PUBLIC int +_glapi_add_dispatch( const char * const * function_names, + const char * parameter_signature ) +{ + return 0; +} + +PUBLIC GLint +_glapi_get_proc_offset(const char *funcName) +{ + return 0; +} + +PUBLIC _glapi_proc +_glapi_get_proc_address(const char *funcName) +{ + return 0; +} + +PUBLIC GLuint +_glapi_get_dispatch_table_size(void) +{ + return 0; +} + int main(int argc, char** argv) { void* p = __driDriverExtensions; -- cgit v1.2.3 From 8ba47561dd45e1cd737992544545d7fa0f61918b Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Tue, 23 Mar 2010 17:22:43 -0600 Subject: st/glx: add support for multiple displays This is a quick & dirty solution, but it works. See comments in the code for other ideas. Fixes regressions/breakage seen in progs/xdemos/glxheads, etc. from commit 6632915e957149c153a3f793c400a532b4995b18. --- src/gallium/state_trackers/glx/xlib/xm_api.c | 30 ++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/glx/xlib/xm_api.c b/src/gallium/state_trackers/glx/xlib/xm_api.c index 8dd54206af2..3022d45157a 100644 --- a/src/gallium/state_trackers/glx/xlib/xm_api.c +++ b/src/gallium/state_trackers/glx/xlib/xm_api.c @@ -78,17 +78,39 @@ void xmesa_set_driver( const struct xm_driver *templ ) stapi = driver.create_st_api(); } + +/* + * XXX replace this with a linked list, or better yet, try to attach the + * gallium/mesa extra bits to the X Display object with XAddExtension(). + */ +#define MAX_DISPLAYS 10 +static struct xmesa_display Displays[MAX_DISPLAYS]; +static int NumDisplays = 0; + + static XMesaDisplay xmesa_init_display( Display *display ) { pipe_static_mutex(init_mutex); - static struct xmesa_display xm_display; XMesaDisplay xmdpy; - + int i; + pipe_mutex_lock(init_mutex); - /* TODO support for multiple displays */ - xmdpy = &xm_display; + /* Look for XMesaDisplay which corresponds to 'display' */ + for (i = 0; i < NumDisplays; i++) { + if (Displays[i].display == display) { + /* Found it */ + pipe_mutex_unlock(init_mutex); + return &Displays[i]; + } + } + + /* Create new XMesaDisplay */ + + assert(NumDisplays < MAX_DISPLAYS); + xmdpy = &Displays[NumDisplays]; + NumDisplays++; if (!xmdpy->display && display) { xmdpy->display = display; -- cgit v1.2.3 From 41d2ebf2020311eb032882d9b0bd1efe916f1feb Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Tue, 16 Mar 2010 13:44:32 +0000 Subject: gallium: Remove GALLIUM_WINSYS_DRM_DIRS --- configs/autoconf.in | 1 - configs/default | 3 +-- configs/linux-dri | 3 +-- configs/linux-opengl-es | 3 +-- configure.ac | 25 +++++++++++++++---------- src/gallium/winsys/drm/Makefile | 12 ------------ 6 files changed, 18 insertions(+), 29 deletions(-) delete mode 100644 src/gallium/winsys/drm/Makefile (limited to 'src/gallium') diff --git a/configs/autoconf.in b/configs/autoconf.in index 66c1ee48e87..b6cc9b3b73e 100644 --- a/configs/autoconf.in +++ b/configs/autoconf.in @@ -76,7 +76,6 @@ GALLIUM_DIRS = @GALLIUM_DIRS@ GALLIUM_DRIVERS_DIRS = @GALLIUM_DRIVERS_DIRS@ GALLIUM_WINSYS_DIRS = @GALLIUM_WINSYS_DIRS@ GALLIUM_TARGET_DIRS = @GALLIUM_TARGET_DIRS@ -GALLIUM_WINSYS_DRM_DIRS = @GALLIUM_WINSYS_DRM_DIRS@ GALLIUM_STATE_TRACKERS_DIRS = @GALLIUM_STATE_TRACKERS_DIRS@ GALLIUM_AUXILIARIES = $(TOP)/src/gallium/auxiliary/libgallium.a GALLIUM_DRIVERS = $(foreach DIR,$(GALLIUM_DRIVERS_DIRS),$(TOP)/src/gallium/drivers/$(DIR)/lib$(DIR).a) diff --git a/configs/default b/configs/default index 8fbf8dd219a..03feed973a2 100644 --- a/configs/default +++ b/configs/default @@ -100,9 +100,8 @@ GALLIUM_DIRS = auxiliary drivers state_trackers GALLIUM_AUXILIARIES = $(TOP)/src/gallium/auxiliary/libgallium.a GALLIUM_DRIVERS_DIRS = softpipe failover svga i915 i965 r300 trace identity GALLIUM_DRIVERS = $(foreach DIR,$(GALLIUM_DRIVERS_DIRS),$(TOP)/src/gallium/drivers/$(DIR)/lib$(DIR).a) -GALLIUM_WINSYS_DIRS = null xlib drm +GALLIUM_WINSYS_DIRS = null xlib drm/swrast GALLIUM_TARGET_DIRS = libgl-xlib -GALLIUM_WINSYS_DRM_DIRS = swrast GALLIUM_STATE_TRACKERS_DIRS = glx vega # native displays EGL should support diff --git a/configs/linux-dri b/configs/linux-dri index d362fd8b377..e10021d7994 100644 --- a/configs/linux-dri +++ b/configs/linux-dri @@ -58,9 +58,8 @@ PROGRAM_DIRS := egl $(PROGRAM_DIRS) EGL_DRIVERS_DIRS = glx DRIVER_DIRS = dri -GALLIUM_WINSYS_DIRS = null xlib drm +GALLIUM_WINSYS_DIRS = null xlib drm/vmware drm/intel drm/i965 GALLIUM_TARGET_DIRS = -GALLIUM_WINSYS_DRM_DIRS = vmware intel i965 GALLIUM_STATE_TRACKERS_DIRS = egl DRI_DIRS = i810 i915 i965 mach64 mga r128 r200 r300 radeon \ diff --git a/configs/linux-opengl-es b/configs/linux-opengl-es index 76054aad14e..ddcb717f836 100644 --- a/configs/linux-opengl-es +++ b/configs/linux-opengl-es @@ -24,5 +24,4 @@ GALLIUM_STATE_TRACKERS_DIRS = es # build egl_x11_{swrast,i915}.so GALLIUM_DRIVERS_DIRS += trace i915 GALLIUM_STATE_TRACKERS_DIRS += egl -GALLIUM_WINSYS_DIRS += drm -GALLIUM_WINSYS_DRM_DIRS += intel swrast +GALLIUM_WINSYS_DIRS += drm/intel drm/swrast diff --git a/configure.ac b/configure.ac index 26960e85ea4..aab16b6ea8a 100644 --- a/configure.ac +++ b/configure.ac @@ -461,8 +461,7 @@ SRC_DIRS="glew" GLU_DIRS="sgi" GALLIUM_DIRS="auxiliary drivers state_trackers" GALLIUM_TARGET_DIRS="" -GALLIUM_WINSYS_DIRS="" -GALLIUM_WINSYS_DRM_DIRS="" +GALLIUM_WINSYS_DIRS="null" GALLIUM_DRIVERS_DIRS="softpipe failover trace identity" GALLIUM_STATE_TRACKERS_DIRS="" @@ -475,7 +474,7 @@ xlib) dri) SRC_DIRS="$SRC_DIRS glx" DRIVER_DIRS="dri" - GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS xlib drm" + GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS xlib drm/sw" ;; osmesa) DRIVER_DIRS="osmesa" @@ -487,7 +486,6 @@ AC_SUBST([DRIVER_DIRS]) AC_SUBST([GALLIUM_DIRS]) AC_SUBST([GALLIUM_TARGET_DIRS]) AC_SUBST([GALLIUM_WINSYS_DIRS]) -AC_SUBST([GALLIUM_WINSYS_DRM_DIRS]) AC_SUBST([GALLIUM_DRIVERS_DIRS]) AC_SUBST([GALLIUM_STATE_TRACKERS_DIRS]) @@ -1318,7 +1316,9 @@ AC_ARG_ENABLE([gallium-svga], [enable_gallium_svga="$enableval"], [enable_gallium_svga=auto]) if test "x$enable_gallium_svga" = xyes; then - GALLIUM_WINSYS_DRM_DIRS="$GALLIUM_WINSYS_DRM_DIRS vmware" + if test "x$mesa_driver" = xdri; then + GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS drm/vmware" + fi GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS svga" elif test "x$enable_gallium_svga" = xauto; then GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS svga" @@ -1333,7 +1333,9 @@ AC_ARG_ENABLE([gallium-intel], [enable_gallium_intel="$enableval"], [enable_gallium_intel=auto]) if test "x$enable_gallium_intel" = xyes; then - GALLIUM_WINSYS_DRM_DIRS="$GALLIUM_WINSYS_DRM_DIRS intel i965" + if test "x$mesa_driver" = xdri; then + GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS drm/intel drm/i965" + fi GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS i915 i965" elif test "x$enable_gallium_intel" = xauto; then GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS i915 i965" @@ -1348,7 +1350,9 @@ AC_ARG_ENABLE([gallium-radeon], [enable_gallium_radeon="$enableval"], [enable_gallium_radeon=auto]) if test "x$enable_gallium_radeon" = xyes; then - GALLIUM_WINSYS_DRM_DIRS="$GALLIUM_WINSYS_DRM_DIRS radeon" + if test "x$mesa_driver" = xdri; then + GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS drm/radeon" + fi GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS r300" elif test "x$enable_gallium_radeon" = xauto; then GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS r300" @@ -1363,7 +1367,9 @@ AC_ARG_ENABLE([gallium-nouveau], [enable_gallium_nouveau="$enableval"], [enable_gallium_nouveau=no]) if test "x$enable_gallium_nouveau" = xyes; then - GALLIUM_WINSYS_DRM_DIRS="$GALLIUM_WINSYS_DRM_DIRS nouveau" + if test "x$mesa_driver" = xdri; then + GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS drm/nouveau" + fi GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS nouveau nvfx nv50" fi @@ -1376,7 +1382,7 @@ AC_ARG_ENABLE([gallium-swrast], [enable_gallium_swrast="$enableval"], [enable_gallium_swrast=auto]) if test "x$enable_gallium_swrast" = xyes; then - GALLIUM_WINSYS_DRM_DIRS="$GALLIUM_WINSYS_DRM_DIRS swrast" + GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS drm/swrast" fi dnl prepend CORE_DIRS to SRC_DIRS @@ -1434,7 +1440,6 @@ if echo "$SRC_DIRS" | grep 'gallium' >/dev/null 2>&1; then echo " Gallium dirs: $GALLIUM_DIRS" echo " Target dirs: $GALLIUM_TARGET_DIRS" echo " Winsys dirs: $GALLIUM_WINSYS_DIRS" - echo " Winsys drm dirs:$GALLIUM_WINSYS_DRM_DIRS" echo " Driver dirs: $GALLIUM_DRIVERS_DIRS" echo " Trackers dirs: $GALLIUM_STATE_TRACKERS_DIRS" else diff --git a/src/gallium/winsys/drm/Makefile b/src/gallium/winsys/drm/Makefile deleted file mode 100644 index a998aff931d..00000000000 --- a/src/gallium/winsys/drm/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -# src/gallium/winsys/Makefile -TOP = ../../../.. -include $(TOP)/configs/current - -SUBDIRS = sw $(GALLIUM_WINSYS_DRM_DIRS) - -default install clean: - @for dir in $(SUBDIRS) ; do \ - if [ -d $$dir ] ; then \ - (cd $$dir && $(MAKE) $@) || exit 1; \ - fi \ - done -- cgit v1.2.3 From be38b32531cc974ff8a33e4504d4169150be4d55 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Tue, 23 Mar 2010 13:23:26 +0000 Subject: gallium: Move dri drivers to targets Attached output from git commit: rename src/gallium/{winsys/drm/Makefile.template => targets/Makefile.dri} (100%) rename src/gallium/{winsys/drm/intel/dri => targets/dri-i915}/Makefile (75%) rename src/gallium/{winsys/drm/intel/dri => targets/dri-i915}/SConscript (100%) rename src/gallium/{winsys/drm/i965/dri => targets/dri-i965}/Makefile (76%) rename src/gallium/{winsys/drm/i965/dri => targets/dri-i965}/SConscript (100%) rename src/gallium/{winsys/drm/nouveau/dri => targets/dri-nouveau}/Makefile (86%) rename src/gallium/{winsys/drm/radeon/dri => targets/dri-radeong}/Makefile (85%) rename src/gallium/{winsys/drm/radeon/dri => targets/dri-radeong}/SConscript (100%) rename src/gallium/{winsys/drm/vmware/dri => targets/dri-vmwgfx}/Makefile (85%) rename src/gallium/{winsys/drm/vmware/dri => targets/dri-vmwgfx}/SConscript (100%) --- configure.ac | 6 +- src/gallium/targets/Makefile.dri | 105 +++++++++++++++++++++++++++ src/gallium/targets/dri-i915/Makefile | 22 ++++++ src/gallium/targets/dri-i915/SConscript | 21 ++++++ src/gallium/targets/dri-i965/Makefile | 23 ++++++ src/gallium/targets/dri-i965/SConscript | 19 +++++ src/gallium/targets/dri-nouveau/Makefile | 21 ++++++ src/gallium/targets/dri-radeong/Makefile | 21 ++++++ src/gallium/targets/dri-radeong/SConscript | 17 +++++ src/gallium/targets/dri-vmwgfx/Makefile | 17 +++++ src/gallium/targets/dri-vmwgfx/SConscript | 63 ++++++++++++++++ src/gallium/winsys/drm/Makefile.template | 105 --------------------------- src/gallium/winsys/drm/i965/SConscript | 4 - src/gallium/winsys/drm/i965/dri/Makefile | 27 ------- src/gallium/winsys/drm/i965/dri/SConscript | 19 ----- src/gallium/winsys/drm/intel/SConscript | 4 - src/gallium/winsys/drm/intel/dri/Makefile | 26 ------- src/gallium/winsys/drm/intel/dri/SConscript | 21 ------ src/gallium/winsys/drm/nouveau/dri/Makefile | 23 ------ src/gallium/winsys/drm/radeon/SConscript | 4 - src/gallium/winsys/drm/radeon/dri/Makefile | 24 ------ src/gallium/winsys/drm/radeon/dri/SConscript | 17 ----- src/gallium/winsys/drm/vmware/SConscript | 4 - src/gallium/winsys/drm/vmware/dri/Makefile | 18 ----- src/gallium/winsys/drm/vmware/dri/SConscript | 63 ---------------- 25 files changed, 334 insertions(+), 360 deletions(-) create mode 100644 src/gallium/targets/Makefile.dri create mode 100644 src/gallium/targets/dri-i915/Makefile create mode 100644 src/gallium/targets/dri-i915/SConscript create mode 100644 src/gallium/targets/dri-i965/Makefile create mode 100644 src/gallium/targets/dri-i965/SConscript create mode 100644 src/gallium/targets/dri-nouveau/Makefile create mode 100644 src/gallium/targets/dri-radeong/Makefile create mode 100644 src/gallium/targets/dri-radeong/SConscript create mode 100644 src/gallium/targets/dri-vmwgfx/Makefile create mode 100644 src/gallium/targets/dri-vmwgfx/SConscript delete mode 100644 src/gallium/winsys/drm/Makefile.template delete mode 100644 src/gallium/winsys/drm/i965/dri/Makefile delete mode 100644 src/gallium/winsys/drm/i965/dri/SConscript delete mode 100644 src/gallium/winsys/drm/intel/dri/Makefile delete mode 100644 src/gallium/winsys/drm/intel/dri/SConscript delete mode 100644 src/gallium/winsys/drm/nouveau/dri/Makefile delete mode 100644 src/gallium/winsys/drm/radeon/dri/Makefile delete mode 100644 src/gallium/winsys/drm/radeon/dri/SConscript delete mode 100644 src/gallium/winsys/drm/vmware/dri/Makefile delete mode 100644 src/gallium/winsys/drm/vmware/dri/SConscript (limited to 'src/gallium') diff --git a/configure.ac b/configure.ac index aab16b6ea8a..51b480ff972 100644 --- a/configure.ac +++ b/configure.ac @@ -1180,7 +1180,7 @@ AC_ARG_ENABLE([gallium], [enable_gallium="$enableval"], [enable_gallium=yes]) if test "x$enable_gallium" = xyes; then - SRC_DIRS="$SRC_DIRS gallium gallium/winsys" + SRC_DIRS="$SRC_DIRS gallium gallium/winsys gallium/targets" fi dnl @@ -1318,6 +1318,7 @@ AC_ARG_ENABLE([gallium-svga], if test "x$enable_gallium_svga" = xyes; then if test "x$mesa_driver" = xdri; then GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS drm/vmware" + GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS dri-vmwgfx" fi GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS svga" elif test "x$enable_gallium_svga" = xauto; then @@ -1335,6 +1336,7 @@ AC_ARG_ENABLE([gallium-intel], if test "x$enable_gallium_intel" = xyes; then if test "x$mesa_driver" = xdri; then GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS drm/intel drm/i965" + GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS dri-i915 dri-i965" fi GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS i915 i965" elif test "x$enable_gallium_intel" = xauto; then @@ -1352,6 +1354,7 @@ AC_ARG_ENABLE([gallium-radeon], if test "x$enable_gallium_radeon" = xyes; then if test "x$mesa_driver" = xdri; then GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS drm/radeon" + GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS dri-radeong" fi GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS r300" elif test "x$enable_gallium_radeon" = xauto; then @@ -1369,6 +1372,7 @@ AC_ARG_ENABLE([gallium-nouveau], if test "x$enable_gallium_nouveau" = xyes; then if test "x$mesa_driver" = xdri; then GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS drm/nouveau" + GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS dri-nouveau" fi GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS nouveau nvfx nv50" fi diff --git a/src/gallium/targets/Makefile.dri b/src/gallium/targets/Makefile.dri new file mode 100644 index 00000000000..6d9b81aa249 --- /dev/null +++ b/src/gallium/targets/Makefile.dri @@ -0,0 +1,105 @@ +# -*-makefile-*- + +MESA_MODULES = \ + $(TOP)/src/mesa/libmesagallium.a \ + $(GALLIUM_AUXILIARIES) + +COMMON_GALLIUM_SOURCES = \ + $(TOP)/src/mesa/drivers/dri/common/utils.c \ + $(TOP)/src/mesa/drivers/dri/common/vblank.c \ + $(TOP)/src/mesa/drivers/dri/common/dri_util.c \ + $(TOP)/src/mesa/drivers/dri/common/xmlconfig.c + +COMMON_SOURCES = $(COMMON_GALLIUM_SOURCES) \ + $(TOP)/src/mesa/drivers/common/driverfuncs.c \ + $(TOP)/src/mesa/drivers/dri/common/texmem.c \ + $(TOP)/src/mesa/drivers/dri/common/drirenderbuffer.c + +COMMON_BM_SOURCES = \ + $(TOP)/src/mesa/drivers/dri/common/dri_bufmgr.c \ + $(TOP)/src/mesa/drivers/dri/common/dri_drmpool.c + +INCLUDES = $(SHARED_INCLUDES) $(EXPAT_INCLUDES) + +OBJECTS = \ + $(C_SOURCES:.c=.o) \ + $(ASM_SOURCES:.S=.o) + + +### Include directories +SHARED_INCLUDES = \ + -I. \ + -I$(TOP)/src/mesa/drivers/dri/common \ + -Iserver \ + -I$(TOP)/include \ + -I$(TOP)/include/GL/internal \ + -I$(TOP)/src/gallium/include \ + -I$(TOP)/src/gallium/auxiliary \ + -I$(TOP)/src/gallium/drivers \ + -I$(TOP)/src/gallium/winsys/common \ + -I$(TOP)/src/mesa \ + -I$(TOP)/src/mesa/main \ + -I$(TOP)/src/mesa/glapi \ + -I$(TOP)/src/mesa/math \ + -I$(TOP)/src/mesa/transform \ + -I$(TOP)/src/mesa/shader \ + -I$(TOP)/src/mesa/swrast \ + -I$(TOP)/src/mesa/swrast_setup \ + -I$(TOP)/src/egl/main \ + -I$(TOP)/src/egl/drivers/dri \ + $(LIBDRM_CFLAGS) + + +##### RULES ##### + +.c.o: + $(CC) -c $(INCLUDES) $(CFLAGS) $(DRIVER_DEFINES) $< -o $@ + +.S.o: + $(CC) -c $(INCLUDES) $(CFLAGS) $(DRIVER_DEFINES) $< -o $@ + + +##### TARGETS ##### + +default: depend symlinks $(TOP)/$(LIB_DIR)/gallium/$(LIBNAME) + +$(LIBNAME): $(OBJECTS) $(MESA_MODULES) $(PIPE_DRIVERS) Makefile \ + $(TOP)/src/mesa/drivers/dri/Makefile.template $(TOP)/src/mesa/drivers/dri/common/dri_test.o + $(MKLIB) -o $@.tmp -noprefix -linker '$(CC)' -ldflags '$(LDFLAGS)' \ + $(OBJECTS) $(PIPE_DRIVERS) \ + -Wl,--start-group $(MESA_MODULES) -Wl,--end-group \ + $(DRI_LIB_DEPS) $(DRIVER_EXTRAS) + $(CC) -o $@.test $(TOP)/src/mesa/drivers/dri/common/dri_test.o $@.tmp $(DRI_LIB_DEPS) + @rm -f $@.test + mv -f $@.tmp $@ + +$(TOP)/$(LIB_DIR)/gallium: + mkdir -p $@ + +$(TOP)/$(LIB_DIR)/gallium/$(LIBNAME): $(LIBNAME) $(TOP)/$(LIB_DIR)/gallium + $(INSTALL) $(LIBNAME) $(TOP)/$(LIB_DIR)/gallium + +depend: $(C_SOURCES) $(ASM_SOURCES) $(SYMLINKS) + rm -f depend + touch depend + $(MKDEP) $(MKDEP_OPTIONS) $(DRIVER_DEFINES) $(INCLUDES) $(C_SOURCES) \ + $(ASM_SOURCES) 2> /dev/null + + +# Emacs tags +tags: + etags `find . -name \*.[ch]` `find ../include` + + +# Remove .o and backup files +clean: + -rm -f *.o */*.o *~ *.so *~ server/*.o $(SYMLINKS) + -rm -f depend depend.bak + + +install: $(LIBNAME) + $(INSTALL) -d $(DESTDIR)$(DRI_DRIVER_INSTALL_DIR) + $(MINSTALL) -m 755 $(LIBNAME) $(DESTDIR)$(DRI_DRIVER_INSTALL_DIR) + + +include depend diff --git a/src/gallium/targets/dri-i915/Makefile b/src/gallium/targets/dri-i915/Makefile new file mode 100644 index 00000000000..33eaae624f2 --- /dev/null +++ b/src/gallium/targets/dri-i915/Makefile @@ -0,0 +1,22 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +LIBNAME = i915_dri.so + +PIPE_DRIVERS = \ + $(TOP)/src/gallium/state_trackers/dri/libdridrm.a \ + $(TOP)/src/gallium/winsys/drm/intel/gem/libinteldrm.a \ + $(TOP)/src/gallium/drivers/trace/libtrace.a \ + $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ + $(TOP)/src/gallium/drivers/identity/libidentity.a \ + $(TOP)/src/gallium/drivers/i915/libi915.a + +C_SOURCES = \ + $(COMMON_GALLIUM_SOURCES) \ + $(DRIVER_SOURCES) + +include ../Makefile.dri + +DRI_LIB_DEPS += -ldrm_intel + +symlinks: diff --git a/src/gallium/targets/dri-i915/SConscript b/src/gallium/targets/dri-i915/SConscript new file mode 100644 index 00000000000..0df841d8798 --- /dev/null +++ b/src/gallium/targets/dri-i915/SConscript @@ -0,0 +1,21 @@ +Import('*') + +env = drienv.Clone() + +env.ParseConfig('pkg-config --cflags --libs libdrm_intel') + +env.Prepend(LIBS = [ + st_dri, + inteldrm, + i915, + trace, + mesa, + glsl, + gallium +]) + +env.LoadableModule( + target ='i915_dri.so', + source = COMMON_GALLIUM_SOURCES, + SHLIBPREFIX = '', +) diff --git a/src/gallium/targets/dri-i965/Makefile b/src/gallium/targets/dri-i965/Makefile new file mode 100644 index 00000000000..e17775a842a --- /dev/null +++ b/src/gallium/targets/dri-i965/Makefile @@ -0,0 +1,23 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +LIBNAME = i965_dri.so + +PIPE_DRIVERS = \ + $(TOP)/src/gallium/state_trackers/dri/libdridrm.a \ + $(TOP)/src/gallium/winsys/drm/i965/gem/libi965drm.a \ + $(TOP)/src/gallium/drivers/trace/libtrace.a \ + $(TOP)/src/gallium/winsys/drm/sw/libswdrm.a \ + $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ + $(TOP)/src/gallium/drivers/identity/libidentity.a \ + $(TOP)/src/gallium/drivers/i965/libi965.a + +C_SOURCES = \ + $(COMMON_GALLIUM_SOURCES) \ + $(DRIVER_SOURCES) + +include ../Makefile.dri + +DRI_LIB_DEPS += -ldrm_intel + +symlinks: diff --git a/src/gallium/targets/dri-i965/SConscript b/src/gallium/targets/dri-i965/SConscript new file mode 100644 index 00000000000..a99533fd245 --- /dev/null +++ b/src/gallium/targets/dri-i965/SConscript @@ -0,0 +1,19 @@ +Import('*') + +env = drienv.Clone() + +env.ParseConfig('pkg-config --cflags --libs libdrm_intel') + +drivers = [ + st_dri, + i965drm, + i965, + trace, +] + +env.LoadableModule( + target ='i965_dri.so', + source = COMMON_GALLIUM_SOURCES, + LIBS = drivers + mesa + gallium + env['LIBS'], + SHLIBPREFIX = '', +) diff --git a/src/gallium/targets/dri-nouveau/Makefile b/src/gallium/targets/dri-nouveau/Makefile new file mode 100644 index 00000000000..680bad79177 --- /dev/null +++ b/src/gallium/targets/dri-nouveau/Makefile @@ -0,0 +1,21 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +LIBNAME = nouveau_dri.so + +PIPE_DRIVERS = \ + $(TOP)/src/gallium/state_trackers/dri/libdridrm.a \ + $(TOP)/src/gallium/winsys/drm/nouveau/drm/libnouveaudrm.a \ + $(TOP)/src/gallium/drivers/nvfx/libnvfx.a \ + $(TOP)/src/gallium/drivers/nv50/libnv50.a \ + $(TOP)/src/gallium/drivers/nouveau/libnouveau.a + +C_SOURCES = \ + $(COMMON_GALLIUM_SOURCES) \ + $(DRIVER_SOURCES) + +include ../Makefile.dri + +DRI_LIB_DEPS += $(shell pkg-config libdrm_nouveau --libs) + +symlinks: diff --git a/src/gallium/targets/dri-radeong/Makefile b/src/gallium/targets/dri-radeong/Makefile new file mode 100644 index 00000000000..c6d8c524694 --- /dev/null +++ b/src/gallium/targets/dri-radeong/Makefile @@ -0,0 +1,21 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +LIBNAME = radeong_dri.so + +PIPE_DRIVERS = \ + $(TOP)/src/gallium/state_trackers/dri/libdridrm.a \ + $(TOP)/src/gallium/winsys/drm/radeon/core/libradeonwinsys.a \ + $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ + $(TOP)/src/gallium/drivers/trace/libtrace.a \ + $(TOP)/src/gallium/drivers/r300/libr300.a + +C_SOURCES = \ + $(COMMON_GALLIUM_SOURCES) \ + $(DRIVER_SOURCES) + +include ../Makefile.dri + +DRI_LIB_DEPS += -ldrm_radeon + +symlinks: diff --git a/src/gallium/targets/dri-radeong/SConscript b/src/gallium/targets/dri-radeong/SConscript new file mode 100644 index 00000000000..c4989d1b595 --- /dev/null +++ b/src/gallium/targets/dri-radeong/SConscript @@ -0,0 +1,17 @@ +Import('*') + +env = drienv.Clone() + +env.ParseConfig('pkg-config --cflags --libs libdrm_radeon') + +drivers = [ + trace, + softpipe, + r300 +] + +env.SharedLibrary( + target ='radeon_dri.so', + source = COMMON_GALLIUM_SOURCES, + LIBS = st_dri + radeonwinsys + mesa + drivers + gallium + env['LIBS'], +) diff --git a/src/gallium/targets/dri-vmwgfx/Makefile b/src/gallium/targets/dri-vmwgfx/Makefile new file mode 100644 index 00000000000..1d2ddfe548f --- /dev/null +++ b/src/gallium/targets/dri-vmwgfx/Makefile @@ -0,0 +1,17 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +LIBNAME = vmwgfx_dri.so + +PIPE_DRIVERS = \ + $(TOP)/src/gallium/state_trackers/dri/libdridrm.a \ + $(TOP)/src/gallium/winsys/drm/vmware/core/libsvgadrm.a \ + $(TOP)/src/gallium/drivers/trace/libtrace.a \ + $(TOP)/src/gallium/drivers/svga/libsvga.a + +C_SOURCES = \ + $(COMMON_GALLIUM_SOURCES) + +include ../Makefile.dri + +symlinks: diff --git a/src/gallium/targets/dri-vmwgfx/SConscript b/src/gallium/targets/dri-vmwgfx/SConscript new file mode 100644 index 00000000000..d26d0cd7483 --- /dev/null +++ b/src/gallium/targets/dri-vmwgfx/SConscript @@ -0,0 +1,63 @@ +import os +import os.path + +Import('*') + +if env['platform'] == 'linux': + + if env['dri']: + env = env.Clone() + + sources = [ + '#/src/mesa/drivers/dri/common/utils.c', + '#/src/mesa/drivers/dri/common/vblank.c', + '#/src/mesa/drivers/dri/common/dri_util.c', + '#/src/mesa/drivers/dri/common/xmlconfig.c', + ] + + + env.ParseConfig('pkg-config --cflags --libs libdrm') + + env.Prepend(CPPPATH = [ + '#/src/mesa/state_tracker', + '#/src/mesa/drivers/dri/common', + '#/src/mesa/main', + '#/src/mesa/glapi', + '#/src/mesa', + '#/include', + '#/src/gallium/drivers/svga', + '#/src/gallium/drivers/svga/include', + ]) + + env.Append(CPPDEFINES = [ + 'HAVE_STDINT_H', + 'HAVE_SYS_TYPES_H', + ]) + + env.Append(CFLAGS = [ + '-std=gnu99', + '-D_FILE_OFFSET_BITS=64', + ]) + + env.Prepend(LIBPATH = [ + ]) + + env.Prepend(LIBS = [ + trace, + st_dri, + svgadrm, + svga, + mesa, + glsl, + gallium, + ]) + + # TODO: write a wrapper function http://www.scons.org/wiki/WrapperFunctions + env.LoadableModule( + target ='vmwgfx_dri.so', + source = sources, + LIBS = env['LIBS'], + SHLIBPREFIX = '', + ) + + diff --git a/src/gallium/winsys/drm/Makefile.template b/src/gallium/winsys/drm/Makefile.template deleted file mode 100644 index 6d9b81aa249..00000000000 --- a/src/gallium/winsys/drm/Makefile.template +++ /dev/null @@ -1,105 +0,0 @@ -# -*-makefile-*- - -MESA_MODULES = \ - $(TOP)/src/mesa/libmesagallium.a \ - $(GALLIUM_AUXILIARIES) - -COMMON_GALLIUM_SOURCES = \ - $(TOP)/src/mesa/drivers/dri/common/utils.c \ - $(TOP)/src/mesa/drivers/dri/common/vblank.c \ - $(TOP)/src/mesa/drivers/dri/common/dri_util.c \ - $(TOP)/src/mesa/drivers/dri/common/xmlconfig.c - -COMMON_SOURCES = $(COMMON_GALLIUM_SOURCES) \ - $(TOP)/src/mesa/drivers/common/driverfuncs.c \ - $(TOP)/src/mesa/drivers/dri/common/texmem.c \ - $(TOP)/src/mesa/drivers/dri/common/drirenderbuffer.c - -COMMON_BM_SOURCES = \ - $(TOP)/src/mesa/drivers/dri/common/dri_bufmgr.c \ - $(TOP)/src/mesa/drivers/dri/common/dri_drmpool.c - -INCLUDES = $(SHARED_INCLUDES) $(EXPAT_INCLUDES) - -OBJECTS = \ - $(C_SOURCES:.c=.o) \ - $(ASM_SOURCES:.S=.o) - - -### Include directories -SHARED_INCLUDES = \ - -I. \ - -I$(TOP)/src/mesa/drivers/dri/common \ - -Iserver \ - -I$(TOP)/include \ - -I$(TOP)/include/GL/internal \ - -I$(TOP)/src/gallium/include \ - -I$(TOP)/src/gallium/auxiliary \ - -I$(TOP)/src/gallium/drivers \ - -I$(TOP)/src/gallium/winsys/common \ - -I$(TOP)/src/mesa \ - -I$(TOP)/src/mesa/main \ - -I$(TOP)/src/mesa/glapi \ - -I$(TOP)/src/mesa/math \ - -I$(TOP)/src/mesa/transform \ - -I$(TOP)/src/mesa/shader \ - -I$(TOP)/src/mesa/swrast \ - -I$(TOP)/src/mesa/swrast_setup \ - -I$(TOP)/src/egl/main \ - -I$(TOP)/src/egl/drivers/dri \ - $(LIBDRM_CFLAGS) - - -##### RULES ##### - -.c.o: - $(CC) -c $(INCLUDES) $(CFLAGS) $(DRIVER_DEFINES) $< -o $@ - -.S.o: - $(CC) -c $(INCLUDES) $(CFLAGS) $(DRIVER_DEFINES) $< -o $@ - - -##### TARGETS ##### - -default: depend symlinks $(TOP)/$(LIB_DIR)/gallium/$(LIBNAME) - -$(LIBNAME): $(OBJECTS) $(MESA_MODULES) $(PIPE_DRIVERS) Makefile \ - $(TOP)/src/mesa/drivers/dri/Makefile.template $(TOP)/src/mesa/drivers/dri/common/dri_test.o - $(MKLIB) -o $@.tmp -noprefix -linker '$(CC)' -ldflags '$(LDFLAGS)' \ - $(OBJECTS) $(PIPE_DRIVERS) \ - -Wl,--start-group $(MESA_MODULES) -Wl,--end-group \ - $(DRI_LIB_DEPS) $(DRIVER_EXTRAS) - $(CC) -o $@.test $(TOP)/src/mesa/drivers/dri/common/dri_test.o $@.tmp $(DRI_LIB_DEPS) - @rm -f $@.test - mv -f $@.tmp $@ - -$(TOP)/$(LIB_DIR)/gallium: - mkdir -p $@ - -$(TOP)/$(LIB_DIR)/gallium/$(LIBNAME): $(LIBNAME) $(TOP)/$(LIB_DIR)/gallium - $(INSTALL) $(LIBNAME) $(TOP)/$(LIB_DIR)/gallium - -depend: $(C_SOURCES) $(ASM_SOURCES) $(SYMLINKS) - rm -f depend - touch depend - $(MKDEP) $(MKDEP_OPTIONS) $(DRIVER_DEFINES) $(INCLUDES) $(C_SOURCES) \ - $(ASM_SOURCES) 2> /dev/null - - -# Emacs tags -tags: - etags `find . -name \*.[ch]` `find ../include` - - -# Remove .o and backup files -clean: - -rm -f *.o */*.o *~ *.so *~ server/*.o $(SYMLINKS) - -rm -f depend depend.bak - - -install: $(LIBNAME) - $(INSTALL) -d $(DESTDIR)$(DRI_DRIVER_INSTALL_DIR) - $(MINSTALL) -m 755 $(LIBNAME) $(DESTDIR)$(DRI_DRIVER_INSTALL_DIR) - - -include depend diff --git a/src/gallium/winsys/drm/i965/SConscript b/src/gallium/winsys/drm/i965/SConscript index 50d7b75ed68..fdf57eedb94 100644 --- a/src/gallium/winsys/drm/i965/SConscript +++ b/src/gallium/winsys/drm/i965/SConscript @@ -1,7 +1,3 @@ Import('*') SConscript(['gem/SConscript',]) - -if 'mesa' in env['statetrackers']: - - SConscript(['dri/SConscript']) diff --git a/src/gallium/winsys/drm/i965/dri/Makefile b/src/gallium/winsys/drm/i965/dri/Makefile deleted file mode 100644 index 56690769fc7..00000000000 --- a/src/gallium/winsys/drm/i965/dri/Makefile +++ /dev/null @@ -1,27 +0,0 @@ -TOP = ../../../../../.. -include $(TOP)/configs/current - -LIBNAME = i965_dri.so - -PIPE_DRIVERS = \ - $(TOP)/src/gallium/state_trackers/dri/libdridrm.a \ - $(TOP)/src/gallium/winsys/drm/i965/gem/libi965drm.a \ - $(TOP)/src/gallium/drivers/trace/libtrace.a \ - $(TOP)/src/gallium/winsys/drm/sw/libswdrm.a \ - $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ - $(TOP)/src/gallium/drivers/identity/libidentity.a \ - $(TOP)/src/gallium/drivers/i965/libi965.a - - -DRIVER_SOURCES = - -C_SOURCES = \ - $(COMMON_GALLIUM_SOURCES) \ - $(DRIVER_SOURCES) - -include ../../Makefile.template - -DRI_LIB_DEPS += -ldrm_intel - -symlinks: $(TOP)/$(LIB_DIR)/gallium - @rm -f $(TOP)/$(LIB_DIR)/gallium/i965_dri.so diff --git a/src/gallium/winsys/drm/i965/dri/SConscript b/src/gallium/winsys/drm/i965/dri/SConscript deleted file mode 100644 index a99533fd245..00000000000 --- a/src/gallium/winsys/drm/i965/dri/SConscript +++ /dev/null @@ -1,19 +0,0 @@ -Import('*') - -env = drienv.Clone() - -env.ParseConfig('pkg-config --cflags --libs libdrm_intel') - -drivers = [ - st_dri, - i965drm, - i965, - trace, -] - -env.LoadableModule( - target ='i965_dri.so', - source = COMMON_GALLIUM_SOURCES, - LIBS = drivers + mesa + gallium + env['LIBS'], - SHLIBPREFIX = '', -) diff --git a/src/gallium/winsys/drm/intel/SConscript b/src/gallium/winsys/drm/intel/SConscript index 50d7b75ed68..fdf57eedb94 100644 --- a/src/gallium/winsys/drm/intel/SConscript +++ b/src/gallium/winsys/drm/intel/SConscript @@ -1,7 +1,3 @@ Import('*') SConscript(['gem/SConscript',]) - -if 'mesa' in env['statetrackers']: - - SConscript(['dri/SConscript']) diff --git a/src/gallium/winsys/drm/intel/dri/Makefile b/src/gallium/winsys/drm/intel/dri/Makefile deleted file mode 100644 index 26aae4122eb..00000000000 --- a/src/gallium/winsys/drm/intel/dri/Makefile +++ /dev/null @@ -1,26 +0,0 @@ -TOP = ../../../../../.. -include $(TOP)/configs/current - -LIBNAME = i915_dri.so - -PIPE_DRIVERS = \ - $(TOP)/src/gallium/state_trackers/dri/libdridrm.a \ - $(TOP)/src/gallium/winsys/drm/intel/gem/libinteldrm.a \ - $(TOP)/src/gallium/drivers/trace/libtrace.a \ - $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ - $(TOP)/src/gallium/drivers/identity/libidentity.a \ - $(TOP)/src/gallium/drivers/i915/libi915.a - - -DRIVER_SOURCES = - -C_SOURCES = \ - $(COMMON_GALLIUM_SOURCES) \ - $(DRIVER_SOURCES) - -include ../../Makefile.template - -DRI_LIB_DEPS += -ldrm_intel - -symlinks: $(TOP)/$(LIB_DIR)/gallium - @rm -f $(TOP)/$(LIB_DIR)/gallium/i965_dri.so diff --git a/src/gallium/winsys/drm/intel/dri/SConscript b/src/gallium/winsys/drm/intel/dri/SConscript deleted file mode 100644 index 0df841d8798..00000000000 --- a/src/gallium/winsys/drm/intel/dri/SConscript +++ /dev/null @@ -1,21 +0,0 @@ -Import('*') - -env = drienv.Clone() - -env.ParseConfig('pkg-config --cflags --libs libdrm_intel') - -env.Prepend(LIBS = [ - st_dri, - inteldrm, - i915, - trace, - mesa, - glsl, - gallium -]) - -env.LoadableModule( - target ='i915_dri.so', - source = COMMON_GALLIUM_SOURCES, - SHLIBPREFIX = '', -) diff --git a/src/gallium/winsys/drm/nouveau/dri/Makefile b/src/gallium/winsys/drm/nouveau/dri/Makefile deleted file mode 100644 index 50ac3f203e5..00000000000 --- a/src/gallium/winsys/drm/nouveau/dri/Makefile +++ /dev/null @@ -1,23 +0,0 @@ -TOP = ../../../../../.. -include $(TOP)/configs/current - -LIBNAME = nouveau_dri.so - -PIPE_DRIVERS = \ - $(TOP)/src/gallium/state_trackers/dri/libdridrm.a \ - $(TOP)/src/gallium/winsys/drm/nouveau/drm/libnouveaudrm.a \ - $(TOP)/src/gallium/drivers/nvfx/libnvfx.a \ - $(TOP)/src/gallium/drivers/nv50/libnv50.a \ - $(TOP)/src/gallium/drivers/nouveau/libnouveau.a - -DRIVER_SOURCES = - -C_SOURCES = \ - $(COMMON_GALLIUM_SOURCES) \ - $(DRIVER_SOURCES) - -include ../../Makefile.template - -DRI_LIB_DEPS += $(shell pkg-config libdrm_nouveau --libs) - -symlinks: diff --git a/src/gallium/winsys/drm/radeon/SConscript b/src/gallium/winsys/drm/radeon/SConscript index b2dfd504d42..eff87e7d010 100644 --- a/src/gallium/winsys/drm/radeon/SConscript +++ b/src/gallium/winsys/drm/radeon/SConscript @@ -1,7 +1,3 @@ Import('*') SConscript(['core/SConscript',]) - -if 'mesa' in env['statetrackers']: - - SConscript(['dri/SConscript']) diff --git a/src/gallium/winsys/drm/radeon/dri/Makefile b/src/gallium/winsys/drm/radeon/dri/Makefile deleted file mode 100644 index d75f7dd6da7..00000000000 --- a/src/gallium/winsys/drm/radeon/dri/Makefile +++ /dev/null @@ -1,24 +0,0 @@ - -TOP = ../../../../../.. -include $(TOP)/configs/current - -LIBNAME = radeong_dri.so - -PIPE_DRIVERS = \ - $(TOP)/src/gallium/state_trackers/dri/libdridrm.a \ - $(TOP)/src/gallium/winsys/drm/radeon/core/libradeonwinsys.a \ - $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ - $(TOP)/src/gallium/drivers/trace/libtrace.a \ - $(TOP)/src/gallium/drivers/r300/libr300.a - -C_SOURCES = \ - $(COMMON_GALLIUM_SOURCES) \ - $(DRIVER_SOURCES) - -ASM_SOURCES = - -include ../../Makefile.template - -DRI_LIB_DEPS += -ldrm_radeon - -symlinks: diff --git a/src/gallium/winsys/drm/radeon/dri/SConscript b/src/gallium/winsys/drm/radeon/dri/SConscript deleted file mode 100644 index c4989d1b595..00000000000 --- a/src/gallium/winsys/drm/radeon/dri/SConscript +++ /dev/null @@ -1,17 +0,0 @@ -Import('*') - -env = drienv.Clone() - -env.ParseConfig('pkg-config --cflags --libs libdrm_radeon') - -drivers = [ - trace, - softpipe, - r300 -] - -env.SharedLibrary( - target ='radeon_dri.so', - source = COMMON_GALLIUM_SOURCES, - LIBS = st_dri + radeonwinsys + mesa + drivers + gallium + env['LIBS'], -) diff --git a/src/gallium/winsys/drm/vmware/SConscript b/src/gallium/winsys/drm/vmware/SConscript index 06e6d5be9ca..e4da31a6933 100644 --- a/src/gallium/winsys/drm/vmware/SConscript +++ b/src/gallium/winsys/drm/vmware/SConscript @@ -2,10 +2,6 @@ Import('*') SConscript(['core/SConscript',]) -if 'mesa' in env['statetrackers']: - - SConscript(['dri/SConscript']) - if 'xorg' in env['statetrackers']: SConscript(['xorg/SConscript']) diff --git a/src/gallium/winsys/drm/vmware/dri/Makefile b/src/gallium/winsys/drm/vmware/dri/Makefile deleted file mode 100644 index 8a39e23da6d..00000000000 --- a/src/gallium/winsys/drm/vmware/dri/Makefile +++ /dev/null @@ -1,18 +0,0 @@ - -TOP = ../../../../../.. -include $(TOP)/configs/current - -LIBNAME = vmwgfx_dri.so - -PIPE_DRIVERS = \ - $(TOP)/src/gallium/state_trackers/dri/libdridrm.a \ - $(TOP)/src/gallium/winsys/drm/vmware/core/libsvgadrm.a \ - $(TOP)/src/gallium/drivers/trace/libtrace.a \ - $(TOP)/src/gallium/drivers/svga/libsvga.a - -C_SOURCES = \ - $(COMMON_GALLIUM_SOURCES) - -include ../../Makefile.template - -symlinks: diff --git a/src/gallium/winsys/drm/vmware/dri/SConscript b/src/gallium/winsys/drm/vmware/dri/SConscript deleted file mode 100644 index d26d0cd7483..00000000000 --- a/src/gallium/winsys/drm/vmware/dri/SConscript +++ /dev/null @@ -1,63 +0,0 @@ -import os -import os.path - -Import('*') - -if env['platform'] == 'linux': - - if env['dri']: - env = env.Clone() - - sources = [ - '#/src/mesa/drivers/dri/common/utils.c', - '#/src/mesa/drivers/dri/common/vblank.c', - '#/src/mesa/drivers/dri/common/dri_util.c', - '#/src/mesa/drivers/dri/common/xmlconfig.c', - ] - - - env.ParseConfig('pkg-config --cflags --libs libdrm') - - env.Prepend(CPPPATH = [ - '#/src/mesa/state_tracker', - '#/src/mesa/drivers/dri/common', - '#/src/mesa/main', - '#/src/mesa/glapi', - '#/src/mesa', - '#/include', - '#/src/gallium/drivers/svga', - '#/src/gallium/drivers/svga/include', - ]) - - env.Append(CPPDEFINES = [ - 'HAVE_STDINT_H', - 'HAVE_SYS_TYPES_H', - ]) - - env.Append(CFLAGS = [ - '-std=gnu99', - '-D_FILE_OFFSET_BITS=64', - ]) - - env.Prepend(LIBPATH = [ - ]) - - env.Prepend(LIBS = [ - trace, - st_dri, - svgadrm, - svga, - mesa, - glsl, - gallium, - ]) - - # TODO: write a wrapper function http://www.scons.org/wiki/WrapperFunctions - env.LoadableModule( - target ='vmwgfx_dri.so', - source = sources, - LIBS = env['LIBS'], - SHLIBPREFIX = '', - ) - - -- cgit v1.2.3 From f5ba2cdeb902993b993187a958aad89c5ac79d6b Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Wed, 24 Mar 2010 10:58:45 +0100 Subject: gallium: Move egl drivers to targets Atteched output from git commit: rename src/gallium/{winsys/drm => targets}/Makefile.egl (100%) rename src/gallium/{winsys/drm/intel/egl => targets/egl-i915}/Makefile (86%) rename src/gallium/{winsys/drm/i965/egl => targets/egl-i915}/dummy.c (100%) rename src/gallium/{winsys/drm/i965/egl => targets/egl-i965}/Makefile (86%) rename src/gallium/{winsys/drm/intel/egl => targets/egl-i965}/dummy.c (100%) rename src/gallium/{winsys/drm/nouveau/egl => targets/egl-nouveau}/Makefile (88%) rename src/gallium/{winsys/drm/nouveau/egl => targets/egl-nouveau}/dummy.c (100%) rename src/gallium/{winsys/drm/radeon/egl => targets/egl-radeon}/Makefile (87%) rename src/gallium/{winsys/drm/radeon/egl => targets/egl-radeon}/dummy.c (100%) create mode 100644 src/gallium/targets/egl-swrast/Makefile create mode 100644 src/gallium/targets/egl-swrast/swrast_glue.c rename src/gallium/{winsys/drm/vmware/egl => targets/egl-vmwgfx}/Makefile (86%) rename src/gallium/{winsys/drm/swrast/egl => targets/egl-vmwgfx}/dummy.c (100%) delete mode 100644 src/gallium/winsys/drm/swrast/Makefile delete mode 100644 src/gallium/winsys/drm/swrast/core/Makefile delete mode 100644 src/gallium/winsys/drm/swrast/core/swrast_drm_api.c delete mode 100644 src/gallium/winsys/drm/swrast/egl/Makefile delete mode 100644 src/gallium/winsys/drm/vmware/egl/dummy.c --- configs/default | 2 +- configs/linux-dri | 2 +- configs/linux-opengl-es | 3 +- configure.ac | 23 +++++++- src/gallium/targets/Makefile.egl | 64 ++++++++++++++++++++++ src/gallium/targets/egl-i915/Makefile | 14 +++++ src/gallium/targets/egl-i915/dummy.c | 3 + src/gallium/targets/egl-i965/Makefile | 14 +++++ src/gallium/targets/egl-i965/dummy.c | 3 + src/gallium/targets/egl-nouveau/Makefile | 15 +++++ src/gallium/targets/egl-nouveau/dummy.c | 3 + src/gallium/targets/egl-radeon/Makefile | 14 +++++ src/gallium/targets/egl-radeon/dummy.c | 3 + src/gallium/targets/egl-swrast/Makefile | 12 ++++ src/gallium/targets/egl-swrast/swrast_glue.c | 17 ++++++ src/gallium/targets/egl-vmwgfx/Makefile | 14 +++++ src/gallium/targets/egl-vmwgfx/dummy.c | 3 + src/gallium/winsys/drm/Makefile.egl | 64 ---------------------- src/gallium/winsys/drm/i965/egl/Makefile | 14 ----- src/gallium/winsys/drm/i965/egl/dummy.c | 3 - src/gallium/winsys/drm/intel/egl/Makefile | 14 ----- src/gallium/winsys/drm/intel/egl/dummy.c | 3 - src/gallium/winsys/drm/nouveau/egl/Makefile | 15 ----- src/gallium/winsys/drm/nouveau/egl/dummy.c | 3 - src/gallium/winsys/drm/radeon/egl/Makefile | 14 ----- src/gallium/winsys/drm/radeon/egl/dummy.c | 3 - src/gallium/winsys/drm/swrast/Makefile | 12 ---- src/gallium/winsys/drm/swrast/core/Makefile | 10 ---- .../winsys/drm/swrast/core/swrast_drm_api.c | 13 ----- src/gallium/winsys/drm/swrast/egl/Makefile | 12 ---- src/gallium/winsys/drm/swrast/egl/dummy.c | 3 - src/gallium/winsys/drm/vmware/egl/Makefile | 14 ----- src/gallium/winsys/drm/vmware/egl/dummy.c | 3 - 33 files changed, 204 insertions(+), 205 deletions(-) create mode 100644 src/gallium/targets/Makefile.egl create mode 100644 src/gallium/targets/egl-i915/Makefile create mode 100644 src/gallium/targets/egl-i915/dummy.c create mode 100644 src/gallium/targets/egl-i965/Makefile create mode 100644 src/gallium/targets/egl-i965/dummy.c create mode 100644 src/gallium/targets/egl-nouveau/Makefile create mode 100644 src/gallium/targets/egl-nouveau/dummy.c create mode 100644 src/gallium/targets/egl-radeon/Makefile create mode 100644 src/gallium/targets/egl-radeon/dummy.c create mode 100644 src/gallium/targets/egl-swrast/Makefile create mode 100644 src/gallium/targets/egl-swrast/swrast_glue.c create mode 100644 src/gallium/targets/egl-vmwgfx/Makefile create mode 100644 src/gallium/targets/egl-vmwgfx/dummy.c delete mode 100644 src/gallium/winsys/drm/Makefile.egl delete mode 100644 src/gallium/winsys/drm/i965/egl/Makefile delete mode 100644 src/gallium/winsys/drm/i965/egl/dummy.c delete mode 100644 src/gallium/winsys/drm/intel/egl/Makefile delete mode 100644 src/gallium/winsys/drm/intel/egl/dummy.c delete mode 100644 src/gallium/winsys/drm/nouveau/egl/Makefile delete mode 100644 src/gallium/winsys/drm/nouveau/egl/dummy.c delete mode 100644 src/gallium/winsys/drm/radeon/egl/Makefile delete mode 100644 src/gallium/winsys/drm/radeon/egl/dummy.c delete mode 100644 src/gallium/winsys/drm/swrast/Makefile delete mode 100644 src/gallium/winsys/drm/swrast/core/Makefile delete mode 100644 src/gallium/winsys/drm/swrast/core/swrast_drm_api.c delete mode 100644 src/gallium/winsys/drm/swrast/egl/Makefile delete mode 100644 src/gallium/winsys/drm/swrast/egl/dummy.c delete mode 100644 src/gallium/winsys/drm/vmware/egl/Makefile delete mode 100644 src/gallium/winsys/drm/vmware/egl/dummy.c (limited to 'src/gallium') diff --git a/configs/default b/configs/default index 03feed973a2..65e9847bd20 100644 --- a/configs/default +++ b/configs/default @@ -100,7 +100,7 @@ GALLIUM_DIRS = auxiliary drivers state_trackers GALLIUM_AUXILIARIES = $(TOP)/src/gallium/auxiliary/libgallium.a GALLIUM_DRIVERS_DIRS = softpipe failover svga i915 i965 r300 trace identity GALLIUM_DRIVERS = $(foreach DIR,$(GALLIUM_DRIVERS_DIRS),$(TOP)/src/gallium/drivers/$(DIR)/lib$(DIR).a) -GALLIUM_WINSYS_DIRS = null xlib drm/swrast +GALLIUM_WINSYS_DIRS = null xlib GALLIUM_TARGET_DIRS = libgl-xlib GALLIUM_STATE_TRACKERS_DIRS = glx vega diff --git a/configs/linux-dri b/configs/linux-dri index e10021d7994..b11daeda7c2 100644 --- a/configs/linux-dri +++ b/configs/linux-dri @@ -59,7 +59,7 @@ EGL_DRIVERS_DIRS = glx DRIVER_DIRS = dri GALLIUM_WINSYS_DIRS = null xlib drm/vmware drm/intel drm/i965 -GALLIUM_TARGET_DIRS = +GALLIUM_TARGET_DIRS = egl-swrast GALLIUM_STATE_TRACKERS_DIRS = egl DRI_DIRS = i810 i915 i965 mach64 mga r128 r200 r300 radeon \ diff --git a/configs/linux-opengl-es b/configs/linux-opengl-es index ddcb717f836..32fe40fb848 100644 --- a/configs/linux-opengl-es +++ b/configs/linux-opengl-es @@ -24,4 +24,5 @@ GALLIUM_STATE_TRACKERS_DIRS = es # build egl_x11_{swrast,i915}.so GALLIUM_DRIVERS_DIRS += trace i915 GALLIUM_STATE_TRACKERS_DIRS += egl -GALLIUM_WINSYS_DIRS += drm/intel drm/swrast +GALLIUM_WINSYS_DIRS += drm/intel +GALLIUM_TARGET_DIRS += egl-swrast egl-i915 diff --git a/configure.ac b/configure.ac index 51b480ff972..dccff6f7cc4 100644 --- a/configure.ac +++ b/configure.ac @@ -1320,6 +1320,9 @@ if test "x$enable_gallium_svga" = xyes; then GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS drm/vmware" GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS dri-vmwgfx" fi + if test "x$enable_egl" = xyes; then + GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS egl-vmwgfx" + fi GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS svga" elif test "x$enable_gallium_svga" = xauto; then GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS svga" @@ -1338,6 +1341,9 @@ if test "x$enable_gallium_intel" = xyes; then GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS drm/intel drm/i965" GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS dri-i915 dri-i965" fi + if test "x$enable_egl" = xyes; then + GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS egl-i915 egl-i965" + fi GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS i915 i965" elif test "x$enable_gallium_intel" = xauto; then GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS i915 i965" @@ -1356,6 +1362,9 @@ if test "x$enable_gallium_radeon" = xyes; then GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS drm/radeon" GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS dri-radeong" fi + if test "x$enable_egl" = xyes; then + GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS egl-radeon" + fi GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS r300" elif test "x$enable_gallium_radeon" = xauto; then GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS r300" @@ -1374,6 +1383,9 @@ if test "x$enable_gallium_nouveau" = xyes; then GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS drm/nouveau" GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS dri-nouveau" fi + if test "x$enable_egl" = xyes; then + GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS egl-nouveau" + fi GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS nouveau nvfx nv50" fi @@ -1382,11 +1394,18 @@ dnl Gallium swrast configuration dnl AC_ARG_ENABLE([gallium-swrast], [AS_HELP_STRING([--enable-gallium-swrast], - [build gallium swrast @<:@default=disabled@:>@])], + [build gallium swrast @<:@default=auto@:>@])], [enable_gallium_swrast="$enableval"], [enable_gallium_swrast=auto]) if test "x$enable_gallium_swrast" = xyes; then - GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS drm/swrast" + if test "x$enable_egl" != xyes; then + AC_MSG_ERROR([EGL needs to be enabled for egl-swrast target]) + fi + GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS egl-swrast" +elif test "x$enable_gallium_swrast" = xauto; then + if test "x$enable_egl" = xyes; then + GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS egl-swrast" + fi fi dnl prepend CORE_DIRS to SRC_DIRS diff --git a/src/gallium/targets/Makefile.egl b/src/gallium/targets/Makefile.egl new file mode 100644 index 00000000000..bc5dd3a53b8 --- /dev/null +++ b/src/gallium/targets/Makefile.egl @@ -0,0 +1,64 @@ +# src/gallium/winsys/drm/Makefile.egl + +# The driver Makefile should define +# +# EGL_DRIVER_NAME, the name of the driver +# EGL_DRIVER_SOURCES, the sources of the driver +# EGL_DRIVER_LIBS, extra libraries needed by the driver +# EGL_DRIVER_PIPES, the pipe drivers of the driver +# +# before including this file. + +EGL_DRIVER_OBJECTS = $(EGL_DRIVER_SOURCES:.c=.o) + +common_LIBS = -ldrm -lm -ldl + +x11_ST = $(TOP)/src/gallium/state_trackers/egl/libeglx11.a \ + $(TOP)/src/gallium/winsys/xlib/libws_xlib.a +x11_LIBS = $(common_LIBS) -lX11 -lXext -lXfixes + +kms_ST = $(TOP)/src/gallium/state_trackers/egl/libeglkms.a +kms_LIBS = $(common_LIBS) + +##### RULES ##### + +.c.o: + $(CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) $< -o $@ + + +##### TARGETS ##### + +EGL_DISPLAY_DRIVERS = $(foreach dpy, $(EGL_DISPLAYS), egl_$(dpy)_$(EGL_DRIVER_NAME).so) + +EGL_DISPLAY_LIBS = $(foreach drv, $(EGL_DISPLAY_DRIVERS), $(TOP)/$(LIB_DIR)/$(drv)) + +default: $(EGL_DISPLAY_LIBS) + +$(EGL_DISPLAY_LIBS): $(TOP)/$(LIB_DIR)/%.so: %.so + $(INSTALL) $< $(TOP)/$(LIB_DIR) + +define mklib-egl +$(MKLIB) -o $@ -noprefix -linker '$(CC)' -ldflags '$(LDFLAGS)' \ + $(MKLIB_OPTIONS) $(EGL_DRIVER_OBJECTS) \ + -Wl,--start-group $($(1)_ST) $(EGL_DRIVER_PIPES) \ + $(GALLIUM_AUXILIARIES) -Wl,--end-group \ + $($(1)_LIBS) $(EGL_DRIVER_LIBS) +endef + +egl_x11_$(EGL_DRIVER_NAME).so: $(EGL_DRIVER_OBJECTS) $(x11_ST) $(EGL_DRIVER_PIPES) $(GALLIUM_AUXILIARIES) Makefile + $(call mklib-egl,x11) + +egl_kms_$(EGL_DRIVER_NAME).so: $(EGL_DRIVER_OBJECTS) $(kms_ST) $(EGL_DRIVER_PIPES) $(GALLIUM_AUXILIARIES) Makefile + $(call mklib-egl,kms) + +clean: + -rm -f $(EGL_DRIVER_OBJECTS) + -rm -f $(EGL_DISPLAY_DRIVERS) + +install: $(EGL_DISPLAY_LIBS) + $(INSTALL) -d $(DESTDIR)$(EGL_DRIVER_INSTALL_DIR) + for lib in $(EGL_DISPLAY_LIBS); do \ + $(MINSTALL) -m 755 "$$lib" $(DESTDIR)$(EGL_DRIVER_INSTALL_DIR); \ + done + +depend: diff --git a/src/gallium/targets/egl-i915/Makefile b/src/gallium/targets/egl-i915/Makefile new file mode 100644 index 00000000000..596dd092f75 --- /dev/null +++ b/src/gallium/targets/egl-i915/Makefile @@ -0,0 +1,14 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +EGL_DRIVER_NAME = i915 +EGL_DRIVER_SOURCES = dummy.c +EGL_DRIVER_LIBS = -ldrm_intel + +EGL_DRIVER_PIPES = \ + $(TOP)/src/gallium/winsys/drm/intel/gem/libinteldrm.a \ + $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ + $(TOP)/src/gallium/drivers/trace/libtrace.a \ + $(TOP)/src/gallium/drivers/i915/libi915.a + +include ../Makefile.egl diff --git a/src/gallium/targets/egl-i915/dummy.c b/src/gallium/targets/egl-i915/dummy.c new file mode 100644 index 00000000000..3181d0ba7e8 --- /dev/null +++ b/src/gallium/targets/egl-i915/dummy.c @@ -0,0 +1,3 @@ +/* A poor man's --whole-archive for EGL drivers */ +void *_eglMain(void *); +void *_eglWholeArchive = (void *) _eglMain; diff --git a/src/gallium/targets/egl-i965/Makefile b/src/gallium/targets/egl-i965/Makefile new file mode 100644 index 00000000000..e4c1a88f4c6 --- /dev/null +++ b/src/gallium/targets/egl-i965/Makefile @@ -0,0 +1,14 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +EGL_DRIVER_NAME = i965 +EGL_DRIVER_SOURCES = dummy.c +EGL_DRIVER_LIBS = -ldrm_intel + +EGL_DRIVER_PIPES = \ + $(TOP)/src/gallium/winsys/drm/i965/gem/libi965drm.a \ + $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ + $(TOP)/src/gallium/drivers/trace/libtrace.a \ + $(TOP)/src/gallium/drivers/i965/libi965.a + +include ../Makefile.egl diff --git a/src/gallium/targets/egl-i965/dummy.c b/src/gallium/targets/egl-i965/dummy.c new file mode 100644 index 00000000000..3181d0ba7e8 --- /dev/null +++ b/src/gallium/targets/egl-i965/dummy.c @@ -0,0 +1,3 @@ +/* A poor man's --whole-archive for EGL drivers */ +void *_eglMain(void *); +void *_eglWholeArchive = (void *) _eglMain; diff --git a/src/gallium/targets/egl-nouveau/Makefile b/src/gallium/targets/egl-nouveau/Makefile new file mode 100644 index 00000000000..46fcdf5e4b0 --- /dev/null +++ b/src/gallium/targets/egl-nouveau/Makefile @@ -0,0 +1,15 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +EGL_DRIVER_NAME = nouveau +EGL_DRIVER_SOURCES = dummy.c +EGL_DRIVER_LIBS = -ldrm_nouveau + +EGL_DRIVER_PIPES = \ + $(TOP)/src/gallium/winsys/drm/nouveau/drm/libnouveaudrm.a \ + $(TOP)/src/gallium/drivers/nvfx/libnvfx.a \ + $(TOP)/src/gallium/drivers/nv50/libnv50.a \ + $(TOP)/src/gallium/drivers/nouveau/libnouveau.a \ + $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a + +include ../Makefile.egl diff --git a/src/gallium/targets/egl-nouveau/dummy.c b/src/gallium/targets/egl-nouveau/dummy.c new file mode 100644 index 00000000000..3181d0ba7e8 --- /dev/null +++ b/src/gallium/targets/egl-nouveau/dummy.c @@ -0,0 +1,3 @@ +/* A poor man's --whole-archive for EGL drivers */ +void *_eglMain(void *); +void *_eglWholeArchive = (void *) _eglMain; diff --git a/src/gallium/targets/egl-radeon/Makefile b/src/gallium/targets/egl-radeon/Makefile new file mode 100644 index 00000000000..56818365dda --- /dev/null +++ b/src/gallium/targets/egl-radeon/Makefile @@ -0,0 +1,14 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +EGL_DRIVER_NAME = radeon +EGL_DRIVER_SOURCES = dummy.c +EGL_DRIVER_LIBS = -ldrm_radeon + +EGL_DRIVER_PIPES = \ + $(TOP)/src/gallium/winsys/drm/radeon/core/libradeonwinsys.a \ + $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ + $(TOP)/src/gallium/drivers/trace/libtrace.a \ + $(TOP)/src/gallium/drivers/r300/libr300.a + +include ../Makefile.egl diff --git a/src/gallium/targets/egl-radeon/dummy.c b/src/gallium/targets/egl-radeon/dummy.c new file mode 100644 index 00000000000..3181d0ba7e8 --- /dev/null +++ b/src/gallium/targets/egl-radeon/dummy.c @@ -0,0 +1,3 @@ +/* A poor man's --whole-archive for EGL drivers */ +void *_eglMain(void *); +void *_eglWholeArchive = (void *) _eglMain; diff --git a/src/gallium/targets/egl-swrast/Makefile b/src/gallium/targets/egl-swrast/Makefile new file mode 100644 index 00000000000..937343defe5 --- /dev/null +++ b/src/gallium/targets/egl-swrast/Makefile @@ -0,0 +1,12 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +# Do propperly +CFLAGS+="-I$(TOP)/src/gallium/include" + +EGL_DRIVER_NAME = swrast +EGL_DRIVER_SOURCES = swrast_glue.c +EGL_DRIVER_LIBS = +EGL_DRIVER_PIPES = $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a + +include ../Makefile.egl diff --git a/src/gallium/targets/egl-swrast/swrast_glue.c b/src/gallium/targets/egl-swrast/swrast_glue.c new file mode 100644 index 00000000000..9db8089a666 --- /dev/null +++ b/src/gallium/targets/egl-swrast/swrast_glue.c @@ -0,0 +1,17 @@ +#include "state_tracker/drm_api.h" + +static struct drm_api swrast_drm_api = +{ + .name = "swrast", +}; + +struct drm_api * +drm_api_create() +{ + (void) swrast_drm_api; + return NULL; +} + +/* A poor man's --whole-archive for EGL drivers */ +void *_eglMain(void *); +void *_eglWholeArchive = (void *) _eglMain; diff --git a/src/gallium/targets/egl-vmwgfx/Makefile b/src/gallium/targets/egl-vmwgfx/Makefile new file mode 100644 index 00000000000..007158a6408 --- /dev/null +++ b/src/gallium/targets/egl-vmwgfx/Makefile @@ -0,0 +1,14 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +EGL_DRIVER_NAME = vmwgfx +EGL_DRIVER_SOURCES = dummy.c +EGL_DRIVER_LIBS = + +EGL_DRIVER_PIPES = \ + $(TOP)/src/gallium/winsys/drm/vmware/core/libsvgadrm.a \ + $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ + $(TOP)/src/gallium/drivers/trace/libtrace.a \ + $(TOP)/src/gallium/drivers/svga/libsvga.a + +include ../Makefile.egl diff --git a/src/gallium/targets/egl-vmwgfx/dummy.c b/src/gallium/targets/egl-vmwgfx/dummy.c new file mode 100644 index 00000000000..3181d0ba7e8 --- /dev/null +++ b/src/gallium/targets/egl-vmwgfx/dummy.c @@ -0,0 +1,3 @@ +/* A poor man's --whole-archive for EGL drivers */ +void *_eglMain(void *); +void *_eglWholeArchive = (void *) _eglMain; diff --git a/src/gallium/winsys/drm/Makefile.egl b/src/gallium/winsys/drm/Makefile.egl deleted file mode 100644 index bc5dd3a53b8..00000000000 --- a/src/gallium/winsys/drm/Makefile.egl +++ /dev/null @@ -1,64 +0,0 @@ -# src/gallium/winsys/drm/Makefile.egl - -# The driver Makefile should define -# -# EGL_DRIVER_NAME, the name of the driver -# EGL_DRIVER_SOURCES, the sources of the driver -# EGL_DRIVER_LIBS, extra libraries needed by the driver -# EGL_DRIVER_PIPES, the pipe drivers of the driver -# -# before including this file. - -EGL_DRIVER_OBJECTS = $(EGL_DRIVER_SOURCES:.c=.o) - -common_LIBS = -ldrm -lm -ldl - -x11_ST = $(TOP)/src/gallium/state_trackers/egl/libeglx11.a \ - $(TOP)/src/gallium/winsys/xlib/libws_xlib.a -x11_LIBS = $(common_LIBS) -lX11 -lXext -lXfixes - -kms_ST = $(TOP)/src/gallium/state_trackers/egl/libeglkms.a -kms_LIBS = $(common_LIBS) - -##### RULES ##### - -.c.o: - $(CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) $< -o $@ - - -##### TARGETS ##### - -EGL_DISPLAY_DRIVERS = $(foreach dpy, $(EGL_DISPLAYS), egl_$(dpy)_$(EGL_DRIVER_NAME).so) - -EGL_DISPLAY_LIBS = $(foreach drv, $(EGL_DISPLAY_DRIVERS), $(TOP)/$(LIB_DIR)/$(drv)) - -default: $(EGL_DISPLAY_LIBS) - -$(EGL_DISPLAY_LIBS): $(TOP)/$(LIB_DIR)/%.so: %.so - $(INSTALL) $< $(TOP)/$(LIB_DIR) - -define mklib-egl -$(MKLIB) -o $@ -noprefix -linker '$(CC)' -ldflags '$(LDFLAGS)' \ - $(MKLIB_OPTIONS) $(EGL_DRIVER_OBJECTS) \ - -Wl,--start-group $($(1)_ST) $(EGL_DRIVER_PIPES) \ - $(GALLIUM_AUXILIARIES) -Wl,--end-group \ - $($(1)_LIBS) $(EGL_DRIVER_LIBS) -endef - -egl_x11_$(EGL_DRIVER_NAME).so: $(EGL_DRIVER_OBJECTS) $(x11_ST) $(EGL_DRIVER_PIPES) $(GALLIUM_AUXILIARIES) Makefile - $(call mklib-egl,x11) - -egl_kms_$(EGL_DRIVER_NAME).so: $(EGL_DRIVER_OBJECTS) $(kms_ST) $(EGL_DRIVER_PIPES) $(GALLIUM_AUXILIARIES) Makefile - $(call mklib-egl,kms) - -clean: - -rm -f $(EGL_DRIVER_OBJECTS) - -rm -f $(EGL_DISPLAY_DRIVERS) - -install: $(EGL_DISPLAY_LIBS) - $(INSTALL) -d $(DESTDIR)$(EGL_DRIVER_INSTALL_DIR) - for lib in $(EGL_DISPLAY_LIBS); do \ - $(MINSTALL) -m 755 "$$lib" $(DESTDIR)$(EGL_DRIVER_INSTALL_DIR); \ - done - -depend: diff --git a/src/gallium/winsys/drm/i965/egl/Makefile b/src/gallium/winsys/drm/i965/egl/Makefile deleted file mode 100644 index 1c132582005..00000000000 --- a/src/gallium/winsys/drm/i965/egl/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -TOP = ../../../../../.. -include $(TOP)/configs/current - -EGL_DRIVER_NAME = i965 -EGL_DRIVER_SOURCES = dummy.c -EGL_DRIVER_LIBS = -ldrm_intel - -EGL_DRIVER_PIPES = \ - $(TOP)/src/gallium/winsys/drm/i965/gem/libi965drm.a \ - $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ - $(TOP)/src/gallium/drivers/trace/libtrace.a \ - $(TOP)/src/gallium/drivers/i965/libi965.a - -include ../../Makefile.egl diff --git a/src/gallium/winsys/drm/i965/egl/dummy.c b/src/gallium/winsys/drm/i965/egl/dummy.c deleted file mode 100644 index 3181d0ba7e8..00000000000 --- a/src/gallium/winsys/drm/i965/egl/dummy.c +++ /dev/null @@ -1,3 +0,0 @@ -/* A poor man's --whole-archive for EGL drivers */ -void *_eglMain(void *); -void *_eglWholeArchive = (void *) _eglMain; diff --git a/src/gallium/winsys/drm/intel/egl/Makefile b/src/gallium/winsys/drm/intel/egl/Makefile deleted file mode 100644 index 60d675ca73d..00000000000 --- a/src/gallium/winsys/drm/intel/egl/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -TOP = ../../../../../.. -include $(TOP)/configs/current - -EGL_DRIVER_NAME = i915 -EGL_DRIVER_SOURCES = dummy.c -EGL_DRIVER_LIBS = -ldrm_intel - -EGL_DRIVER_PIPES = \ - $(TOP)/src/gallium/winsys/drm/intel/gem/libinteldrm.a \ - $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ - $(TOP)/src/gallium/drivers/trace/libtrace.a \ - $(TOP)/src/gallium/drivers/i915/libi915.a - -include ../../Makefile.egl diff --git a/src/gallium/winsys/drm/intel/egl/dummy.c b/src/gallium/winsys/drm/intel/egl/dummy.c deleted file mode 100644 index 3181d0ba7e8..00000000000 --- a/src/gallium/winsys/drm/intel/egl/dummy.c +++ /dev/null @@ -1,3 +0,0 @@ -/* A poor man's --whole-archive for EGL drivers */ -void *_eglMain(void *); -void *_eglWholeArchive = (void *) _eglMain; diff --git a/src/gallium/winsys/drm/nouveau/egl/Makefile b/src/gallium/winsys/drm/nouveau/egl/Makefile deleted file mode 100644 index 47d11276155..00000000000 --- a/src/gallium/winsys/drm/nouveau/egl/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -TOP = ../../../../../.. -include $(TOP)/configs/current - -EGL_DRIVER_NAME = nouveau -EGL_DRIVER_SOURCES = dummy.c -EGL_DRIVER_LIBS = -ldrm_nouveau - -EGL_DRIVER_PIPES = \ - $(TOP)/src/gallium/winsys/drm/nouveau/drm/libnouveaudrm.a \ - $(TOP)/src/gallium/drivers/nvfx/libnvfx.a \ - $(TOP)/src/gallium/drivers/nv50/libnv50.a \ - $(TOP)/src/gallium/drivers/nouveau/libnouveau.a \ - $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a - -include ../../Makefile.egl diff --git a/src/gallium/winsys/drm/nouveau/egl/dummy.c b/src/gallium/winsys/drm/nouveau/egl/dummy.c deleted file mode 100644 index 3181d0ba7e8..00000000000 --- a/src/gallium/winsys/drm/nouveau/egl/dummy.c +++ /dev/null @@ -1,3 +0,0 @@ -/* A poor man's --whole-archive for EGL drivers */ -void *_eglMain(void *); -void *_eglWholeArchive = (void *) _eglMain; diff --git a/src/gallium/winsys/drm/radeon/egl/Makefile b/src/gallium/winsys/drm/radeon/egl/Makefile deleted file mode 100644 index cd4f9b20f06..00000000000 --- a/src/gallium/winsys/drm/radeon/egl/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -TOP = ../../../../../.. -include $(TOP)/configs/current - -EGL_DRIVER_NAME = radeon -EGL_DRIVER_SOURCES = dummy.c -EGL_DRIVER_LIBS = -ldrm_radeon - -EGL_DRIVER_PIPES = \ - $(TOP)/src/gallium/winsys/drm/radeon/core/libradeonwinsys.a \ - $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ - $(TOP)/src/gallium/drivers/trace/libtrace.a \ - $(TOP)/src/gallium/drivers/r300/libr300.a - -include ../../Makefile.egl diff --git a/src/gallium/winsys/drm/radeon/egl/dummy.c b/src/gallium/winsys/drm/radeon/egl/dummy.c deleted file mode 100644 index 3181d0ba7e8..00000000000 --- a/src/gallium/winsys/drm/radeon/egl/dummy.c +++ /dev/null @@ -1,3 +0,0 @@ -/* A poor man's --whole-archive for EGL drivers */ -void *_eglMain(void *); -void *_eglWholeArchive = (void *) _eglMain; diff --git a/src/gallium/winsys/drm/swrast/Makefile b/src/gallium/winsys/drm/swrast/Makefile deleted file mode 100644 index 363b89584f2..00000000000 --- a/src/gallium/winsys/drm/swrast/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -# src/gallium/winsys/drm/swrast/Makefile -TOP = ../../../../.. -include $(TOP)/configs/current - -SUBDIRS = core $(GALLIUM_STATE_TRACKERS_DIRS) - -default install clean: - @for dir in $(SUBDIRS) ; do \ - if [ -d $$dir ] ; then \ - (cd $$dir && $(MAKE) $@) || exit 1; \ - fi \ - done diff --git a/src/gallium/winsys/drm/swrast/core/Makefile b/src/gallium/winsys/drm/swrast/core/Makefile deleted file mode 100644 index 93931ae22b9..00000000000 --- a/src/gallium/winsys/drm/swrast/core/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -# src/gallium/winsys/drm/swrast/core/Makefile - -TOP = ../../../../../.. -include $(TOP)/configs/current - -LIBNAME = swrastdrm - -C_SOURCES = swrast_drm_api.c - -include ../../../../Makefile.template diff --git a/src/gallium/winsys/drm/swrast/core/swrast_drm_api.c b/src/gallium/winsys/drm/swrast/core/swrast_drm_api.c deleted file mode 100644 index 8c9f80e2c15..00000000000 --- a/src/gallium/winsys/drm/swrast/core/swrast_drm_api.c +++ /dev/null @@ -1,13 +0,0 @@ -#include "state_tracker/drm_api.h" - -static struct drm_api swrast_drm_api = -{ - .name = "swrast", -}; - -struct drm_api * -drm_api_create() -{ - (void) swrast_drm_api; - return NULL; -} diff --git a/src/gallium/winsys/drm/swrast/egl/Makefile b/src/gallium/winsys/drm/swrast/egl/Makefile deleted file mode 100644 index 26fe2d2805a..00000000000 --- a/src/gallium/winsys/drm/swrast/egl/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -TOP = ../../../../../.. -include $(TOP)/configs/current - -EGL_DRIVER_NAME = swrast -EGL_DRIVER_SOURCES = dummy.c -EGL_DRIVER_LIBS = - -EGL_DRIVER_PIPES = \ - $(TOP)/src/gallium/winsys/drm/swrast/core/libswrastdrm.a \ - $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a - -include ../../Makefile.egl diff --git a/src/gallium/winsys/drm/swrast/egl/dummy.c b/src/gallium/winsys/drm/swrast/egl/dummy.c deleted file mode 100644 index 3181d0ba7e8..00000000000 --- a/src/gallium/winsys/drm/swrast/egl/dummy.c +++ /dev/null @@ -1,3 +0,0 @@ -/* A poor man's --whole-archive for EGL drivers */ -void *_eglMain(void *); -void *_eglWholeArchive = (void *) _eglMain; diff --git a/src/gallium/winsys/drm/vmware/egl/Makefile b/src/gallium/winsys/drm/vmware/egl/Makefile deleted file mode 100644 index a3e73131c35..00000000000 --- a/src/gallium/winsys/drm/vmware/egl/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -TOP = ../../../../../.. -include $(TOP)/configs/current - -EGL_DRIVER_NAME = vmwgfx -EGL_DRIVER_SOURCES = dummy.c -EGL_DRIVER_LIBS = - -EGL_DRIVER_PIPES = \ - $(TOP)/src/gallium/winsys/drm/vmware/core/libsvgadrm.a \ - $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ - $(TOP)/src/gallium/drivers/trace/libtrace.a \ - $(TOP)/src/gallium/drivers/svga/libsvga.a - -include ../../Makefile.egl diff --git a/src/gallium/winsys/drm/vmware/egl/dummy.c b/src/gallium/winsys/drm/vmware/egl/dummy.c deleted file mode 100644 index 3181d0ba7e8..00000000000 --- a/src/gallium/winsys/drm/vmware/egl/dummy.c +++ /dev/null @@ -1,3 +0,0 @@ -/* A poor man's --whole-archive for EGL drivers */ -void *_eglMain(void *); -void *_eglWholeArchive = (void *) _eglMain; -- cgit v1.2.3 From 43218a45a4cdbe2bc92867dc143f4b0e5fe9ca8d Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Wed, 24 Mar 2010 11:45:30 +0100 Subject: gallium: Move xorg drivers to targets Attached output from git commit: rename src/gallium/{winsys/drm/intel/xorg => targets/xorg-i915}/Makefile (95%) rename src/gallium/{winsys/drm/intel/xorg => targets/xorg-i915}/intel_xorg.c (98%) rename src/gallium/{winsys/drm/i965/xorg => targets/xorg-i965}/Makefile (78%) rename src/gallium/{winsys/drm/i965/xorg => targets/xorg-i965}/intel_xorg.c (98%) rename src/gallium/{winsys/drm/nouveau/xorg => targets/xorg-nouveau}/Makefile (96%) rename src/gallium/{winsys/drm/nouveau/xorg => targets/xorg-nouveau}/nouveau_xorg.c (98%) rename src/gallium/{winsys/drm/radeon/xorg => targets/xorg-radeon}/Makefile (73%) rename src/gallium/{winsys/drm/radeon/xorg => targets/xorg-radeon}/radeon_xorg.c (98%) rename src/gallium/{winsys/drm/vmware/xorg => targets/xorg-vmwgfx}/Makefile (97%) rename src/gallium/{winsys/drm/vmware/xorg => targets/xorg-vmwgfx}/SConscript (100%) rename src/gallium/{winsys/drm/vmware/xorg => targets/xorg-vmwgfx}/vmw_driver.h (100%) rename src/gallium/{winsys/drm/vmware/xorg => targets/xorg-vmwgfx}/vmw_hook.h (100%) rename src/gallium/{winsys/drm/vmware/xorg => targets/xorg-vmwgfx}/vmw_ioctl.c (99%) rename src/gallium/{winsys/drm/vmware/xorg => targets/xorg-vmwgfx}/vmw_screen.c (100%) rename src/gallium/{winsys/drm/vmware/xorg => targets/xorg-vmwgfx}/vmw_video.c (99%) rename src/gallium/{winsys/drm/vmware/xorg => targets/xorg-vmwgfx}/vmw_xorg.c (100%) --- configure.ac | 12 + src/gallium/targets/xorg-i915/Makefile | 57 ++ src/gallium/targets/xorg-i915/intel_xorg.c | 147 +++ src/gallium/targets/xorg-i965/Makefile | 48 + src/gallium/targets/xorg-i965/intel_xorg.c | 147 +++ src/gallium/targets/xorg-nouveau/Makefile | 56 + src/gallium/targets/xorg-nouveau/nouveau_xorg.c | 149 +++ src/gallium/targets/xorg-radeon/Makefile | 48 + src/gallium/targets/xorg-radeon/radeon_xorg.c | 148 +++ src/gallium/targets/xorg-vmwgfx/Makefile | 70 ++ src/gallium/targets/xorg-vmwgfx/SConscript | 57 ++ src/gallium/targets/xorg-vmwgfx/vmw_driver.h | 103 ++ src/gallium/targets/xorg-vmwgfx/vmw_hook.h | 39 + src/gallium/targets/xorg-vmwgfx/vmw_ioctl.c | 242 +++++ src/gallium/targets/xorg-vmwgfx/vmw_screen.c | 178 ++++ src/gallium/targets/xorg-vmwgfx/vmw_video.c | 1072 ++++++++++++++++++++ src/gallium/targets/xorg-vmwgfx/vmw_xorg.c | 191 ++++ src/gallium/winsys/drm/i965/xorg/Makefile | 54 - src/gallium/winsys/drm/i965/xorg/intel_xorg.c | 147 --- src/gallium/winsys/drm/intel/xorg/Makefile | 57 -- src/gallium/winsys/drm/intel/xorg/intel_xorg.c | 147 --- src/gallium/winsys/drm/nouveau/xorg/Makefile | 57 -- src/gallium/winsys/drm/nouveau/xorg/nouveau_xorg.c | 149 --- src/gallium/winsys/drm/radeon/xorg/Makefile | 54 - src/gallium/winsys/drm/radeon/xorg/radeon_xorg.c | 148 --- src/gallium/winsys/drm/vmware/SConscript | 4 - src/gallium/winsys/drm/vmware/xorg/Makefile | 71 -- src/gallium/winsys/drm/vmware/xorg/SConscript | 57 -- src/gallium/winsys/drm/vmware/xorg/vmw_driver.h | 103 -- src/gallium/winsys/drm/vmware/xorg/vmw_hook.h | 39 - src/gallium/winsys/drm/vmware/xorg/vmw_ioctl.c | 242 ----- src/gallium/winsys/drm/vmware/xorg/vmw_screen.c | 178 ---- src/gallium/winsys/drm/vmware/xorg/vmw_video.c | 1072 -------------------- src/gallium/winsys/drm/vmware/xorg/vmw_xorg.c | 191 ---- 34 files changed, 2764 insertions(+), 2770 deletions(-) create mode 100644 src/gallium/targets/xorg-i915/Makefile create mode 100644 src/gallium/targets/xorg-i915/intel_xorg.c create mode 100644 src/gallium/targets/xorg-i965/Makefile create mode 100644 src/gallium/targets/xorg-i965/intel_xorg.c create mode 100644 src/gallium/targets/xorg-nouveau/Makefile create mode 100644 src/gallium/targets/xorg-nouveau/nouveau_xorg.c create mode 100644 src/gallium/targets/xorg-radeon/Makefile create mode 100644 src/gallium/targets/xorg-radeon/radeon_xorg.c create mode 100644 src/gallium/targets/xorg-vmwgfx/Makefile create mode 100644 src/gallium/targets/xorg-vmwgfx/SConscript create mode 100644 src/gallium/targets/xorg-vmwgfx/vmw_driver.h create mode 100644 src/gallium/targets/xorg-vmwgfx/vmw_hook.h create mode 100644 src/gallium/targets/xorg-vmwgfx/vmw_ioctl.c create mode 100644 src/gallium/targets/xorg-vmwgfx/vmw_screen.c create mode 100644 src/gallium/targets/xorg-vmwgfx/vmw_video.c create mode 100644 src/gallium/targets/xorg-vmwgfx/vmw_xorg.c delete mode 100644 src/gallium/winsys/drm/i965/xorg/Makefile delete mode 100644 src/gallium/winsys/drm/i965/xorg/intel_xorg.c delete mode 100644 src/gallium/winsys/drm/intel/xorg/Makefile delete mode 100644 src/gallium/winsys/drm/intel/xorg/intel_xorg.c delete mode 100644 src/gallium/winsys/drm/nouveau/xorg/Makefile delete mode 100644 src/gallium/winsys/drm/nouveau/xorg/nouveau_xorg.c delete mode 100644 src/gallium/winsys/drm/radeon/xorg/Makefile delete mode 100644 src/gallium/winsys/drm/radeon/xorg/radeon_xorg.c delete mode 100644 src/gallium/winsys/drm/vmware/xorg/Makefile delete mode 100644 src/gallium/winsys/drm/vmware/xorg/SConscript delete mode 100644 src/gallium/winsys/drm/vmware/xorg/vmw_driver.h delete mode 100644 src/gallium/winsys/drm/vmware/xorg/vmw_hook.h delete mode 100644 src/gallium/winsys/drm/vmware/xorg/vmw_ioctl.c delete mode 100644 src/gallium/winsys/drm/vmware/xorg/vmw_screen.c delete mode 100644 src/gallium/winsys/drm/vmware/xorg/vmw_video.c delete mode 100644 src/gallium/winsys/drm/vmware/xorg/vmw_xorg.c (limited to 'src/gallium') diff --git a/configure.ac b/configure.ac index dccff6f7cc4..c8f78dc74e8 100644 --- a/configure.ac +++ b/configure.ac @@ -1323,6 +1323,9 @@ if test "x$enable_gallium_svga" = xyes; then if test "x$enable_egl" = xyes; then GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS egl-vmwgfx" fi + if test "x$HAVE_XORG" = xyes; then + GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS xorg-vmwgfx" + fi GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS svga" elif test "x$enable_gallium_svga" = xauto; then GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS svga" @@ -1344,6 +1347,9 @@ if test "x$enable_gallium_intel" = xyes; then if test "x$enable_egl" = xyes; then GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS egl-i915 egl-i965" fi + if test "x$HAVE_XORG" = xyes; then + GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS xorg-i915 xorg-i965" + fi GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS i915 i965" elif test "x$enable_gallium_intel" = xauto; then GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS i915 i965" @@ -1365,6 +1371,9 @@ if test "x$enable_gallium_radeon" = xyes; then if test "x$enable_egl" = xyes; then GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS egl-radeon" fi + if test "x$HAVE_XORG" = xyes; then + GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS xorg-radeon" + fi GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS r300" elif test "x$enable_gallium_radeon" = xauto; then GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS r300" @@ -1386,6 +1395,9 @@ if test "x$enable_gallium_nouveau" = xyes; then if test "x$enable_egl" = xyes; then GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS egl-nouveau" fi + if test "x$HAVE_XORG" = xyes; then + GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS xorg-nouveau" + fi GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS nouveau nvfx nv50" fi diff --git a/src/gallium/targets/xorg-i915/Makefile b/src/gallium/targets/xorg-i915/Makefile new file mode 100644 index 00000000000..4442147e83f --- /dev/null +++ b/src/gallium/targets/xorg-i915/Makefile @@ -0,0 +1,57 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +TARGET = modesetting_drv.so +CFILES = $(wildcard ./*.c) +OBJECTS = $(patsubst ./%.c,./%.o,$(CFILES)) + +INCLUDES = \ + $(shell pkg-config --cflags-only-I pixman-1 xorg-server libdrm xproto) \ + -I$(TOP)/src/gallium/winsys/drm/intel/gem \ + -I$(TOP)/src/gallium/include \ + -I$(TOP)/src/gallium/drivers \ + -I$(TOP)/src/gallium/auxiliary \ + -I$(TOP)/src/mesa \ + -I$(TOP)/include \ + -I$(TOP)/src/egl/main + +LIBS = \ + $(TOP)/src/gallium/state_trackers/xorg/libxorgtracker.a \ + $(TOP)/src/gallium/winsys/drm/intel/gem/libinteldrm.a \ + $(TOP)/src/gallium/drivers/i915/libi915.a \ + $(TOP)/src/gallium/drivers/trace/libtrace.a \ + $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ + $(GALLIUM_AUXILIARIES) + +DRIVER_DEFINES = \ + -DHAVE_CONFIG_H + + +############################################# + + + +all default: $(TARGET) + +$(TARGET): $(OBJECTS) Makefile $(TOP)/src/gallium/state_trackers/xorg/libxorgtracker.a $(LIBS) + $(TOP)/bin/mklib -noprefix -o $@ \ + $(OBJECTS) $(LIBS) $(shell pkg-config --libs libdrm) -ldrm_intel + +clean: + rm -rf $(OBJECTS) $(TARGET) + +install: + $(INSTALL) -d $(DESTDIR)/$(XORG_DRIVER_INSTALL_DIR) + $(MINSTALL) -m 755 $(TARGET) $(DESTDIR)/$(XORG_DRIVER_INSTALL_DIR) + + +############################################## + + +.c.o: + $(CC) -c $(CFLAGS) $(INCLUDES) $(DRIVER_DEFINES) $< -o $@ + + +############################################## + +.PHONY = all clean install diff --git a/src/gallium/targets/xorg-i915/intel_xorg.c b/src/gallium/targets/xorg-i915/intel_xorg.c new file mode 100644 index 00000000000..08f3b088636 --- /dev/null +++ b/src/gallium/targets/xorg-i915/intel_xorg.c @@ -0,0 +1,147 @@ +/* + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * + * Author: Alan Hourihane + * Author: Jakob Bornecrantz + * + */ + +#include "../../state_trackers/xorg/xorg_winsys.h" + +static void intel_xorg_identify(int flags); +static Bool intel_xorg_pci_probe(DriverPtr driver, + int entity_num, + struct pci_device *device, + intptr_t match_data); + +static const struct pci_id_match intel_xorg_device_match[] = { + {0x8086, PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, 0, 0, 0}, + {0, 0, 0}, +}; + +static SymTabRec intel_xorg_chipsets[] = { + {PCI_MATCH_ANY, "Intel Graphics Device"}, + {-1, NULL} +}; + +static PciChipsets intel_xorg_pci_devices[] = { + {PCI_MATCH_ANY, PCI_MATCH_ANY, NULL}, + {-1, -1, NULL} +}; + +static XF86ModuleVersionInfo intel_xorg_version = { + "modesetting", + MODULEVENDORSTRING, + MODINFOSTRING1, + MODINFOSTRING2, + XORG_VERSION_CURRENT, + 0, 1, 0, /* major, minor, patch */ + ABI_CLASS_VIDEODRV, + ABI_VIDEODRV_VERSION, + MOD_CLASS_VIDEODRV, + {0, 0, 0, 0} +}; + +/* + * Xorg driver exported structures + */ + +_X_EXPORT DriverRec modesetting = { + 1, + "modesetting", + intel_xorg_identify, + NULL, + xorg_tracker_available_options, + NULL, + 0, + NULL, + intel_xorg_device_match, + intel_xorg_pci_probe +}; + +static MODULESETUPPROTO(intel_xorg_setup); + +_X_EXPORT XF86ModuleData modesettingModuleData = { + &intel_xorg_version, + intel_xorg_setup, + NULL +}; + +/* + * Xorg driver functions + */ + +static pointer +intel_xorg_setup(pointer module, pointer opts, int *errmaj, int *errmin) +{ + static Bool setupDone = 0; + + /* This module should be loaded only once, but check to be sure. + */ + if (!setupDone) { + setupDone = 1; + xf86AddDriver(&modesetting, module, HaveDriverFuncs); + + /* + * The return value must be non-NULL on success even though there + * is no TearDownProc. + */ + return (pointer) 1; + } else { + if (errmaj) + *errmaj = LDR_ONCEONLY; + return NULL; + } +} + +static void +intel_xorg_identify(int flags) +{ + xf86PrintChipsets("modesetting", "Driver for Modesetting Kernel Drivers", + intel_xorg_chipsets); +} + +static Bool +intel_xorg_pci_probe(DriverPtr driver, + int entity_num, struct pci_device *device, intptr_t match_data) +{ + ScrnInfoPtr scrn = NULL; + EntityInfoPtr entity; + + scrn = xf86ConfigPciEntity(scrn, 0, entity_num, intel_xorg_pci_devices, + NULL, NULL, NULL, NULL, NULL); + if (scrn != NULL) { + scrn->driverVersion = 1; + scrn->driverName = "i915"; + scrn->name = "modesetting"; + scrn->Probe = NULL; + + entity = xf86GetEntityInfo(entity_num); + + /* Use all the functions from the xorg tracker */ + xorg_tracker_set_functions(scrn); + } + return scrn != NULL; +} diff --git a/src/gallium/targets/xorg-i965/Makefile b/src/gallium/targets/xorg-i965/Makefile new file mode 100644 index 00000000000..8d6a741e5d1 --- /dev/null +++ b/src/gallium/targets/xorg-i965/Makefile @@ -0,0 +1,48 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +TARGET = i965g_drv.so +CFILES = $(wildcard ./*.c) +OBJECTS = $(patsubst ./%.c,./%.o,$(CFILES)) + +CFLAGS = -DHAVE_CONFIG_H \ + -g -Wall -Wimplicit-function-declaration -fPIC \ + $(shell pkg-config --cflags pixman-1 xorg-server libdrm xproto) \ + -I$(TOP)/src/gallium/include \ + -I$(TOP)/src/gallium/drivers \ + -I$(TOP)/src/gallium/auxiliary \ + -I$(TOP)/src/mesa \ + -I$(TOP)/include \ + -I$(TOP)/src/egl/main + +LIBS = \ + $(TOP)/src/gallium/state_trackers/xorg/libxorgtracker.a \ + $(TOP)/src/gallium/winsys/drm/i965/gem/libi965drm.a \ + $(TOP)/src/gallium/drivers/i965/libi965.a \ + $(TOP)/src/gallium/drivers/trace/libtrace.a \ + $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ + $(GALLIUM_AUXILIARIES) + +TARGET_STAGING = $(TOP)/$(LIB_DIR)/gallium/$(TARGET) +############################################# + +all default: $(TARGET) $(TARGET_STAGING) + +$(TARGET): $(OBJECTS) Makefile $(TOP)/src/gallium/state_trackers/xorg/libxorgtracker.a $(LIBS) + $(TOP)/bin/mklib -noprefix -o $@ \ + $(OBJECTS) $(LIBS) $(shell pkg-config --libs libdrm) -ldrm_intel + +$(TOP)/$(LIB_DIR)/gallium: + mkdir -p $@ + +$(TARGET_STAGING): $(TARGET) $(TOP)/$(LIB_DIR)/gallium + $(INSTALL) $(TARGET) $(TOP)/$(LIB_DIR)/gallium + +clean: + rm -rf $(OBJECTS) $(TARGET) + +install: + $(INSTALL) -d $(DESTDIR)/$(XORG_DRIVER_INSTALL_DIR) + $(MINSTALL) -m 755 $(TARGET) $(DESTDIR)/$(XORG_DRIVER_INSTALL_DIR) + +.PHONY = all clean install diff --git a/src/gallium/targets/xorg-i965/intel_xorg.c b/src/gallium/targets/xorg-i965/intel_xorg.c new file mode 100644 index 00000000000..f4608f0eb41 --- /dev/null +++ b/src/gallium/targets/xorg-i965/intel_xorg.c @@ -0,0 +1,147 @@ +/* + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * + * Author: Alan Hourihane + * Author: Jakob Bornecrantz + * + */ + +#include "../../state_trackers/xorg/xorg_winsys.h" + +static void intel_xorg_identify(int flags); +static Bool intel_xorg_pci_probe(DriverPtr driver, + int entity_num, + struct pci_device *device, + intptr_t match_data); + +static const struct pci_id_match intel_xorg_device_match[] = { + {0x8086, PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, 0, 0, 0}, + {0, 0, 0}, +}; + +static SymTabRec intel_xorg_chipsets[] = { + {PCI_MATCH_ANY, "Intel Graphics Device"}, + {-1, NULL} +}; + +static PciChipsets intel_xorg_pci_devices[] = { + {PCI_MATCH_ANY, PCI_MATCH_ANY, NULL}, + {-1, -1, NULL} +}; + +static XF86ModuleVersionInfo intel_xorg_version = { + "modesetting", + MODULEVENDORSTRING, + MODINFOSTRING1, + MODINFOSTRING2, + XORG_VERSION_CURRENT, + 0, 1, 0, /* major, minor, patch */ + ABI_CLASS_VIDEODRV, + ABI_VIDEODRV_VERSION, + MOD_CLASS_VIDEODRV, + {0, 0, 0, 0} +}; + +/* + * Xorg driver exported structures + */ + +_X_EXPORT DriverRec modesetting = { + 1, + "modesetting", + intel_xorg_identify, + NULL, + xorg_tracker_available_options, + NULL, + 0, + NULL, + intel_xorg_device_match, + intel_xorg_pci_probe +}; + +static MODULESETUPPROTO(intel_xorg_setup); + +_X_EXPORT XF86ModuleData modesettingModuleData = { + &intel_xorg_version, + intel_xorg_setup, + NULL +}; + +/* + * Xorg driver functions + */ + +static pointer +intel_xorg_setup(pointer module, pointer opts, int *errmaj, int *errmin) +{ + static Bool setupDone = 0; + + /* This module should be loaded only once, but check to be sure. + */ + if (!setupDone) { + setupDone = 1; + xf86AddDriver(&modesetting, module, HaveDriverFuncs); + + /* + * The return value must be non-NULL on success even though there + * is no TearDownProc. + */ + return (pointer) 1; + } else { + if (errmaj) + *errmaj = LDR_ONCEONLY; + return NULL; + } +} + +static void +intel_xorg_identify(int flags) +{ + xf86PrintChipsets("modesetting", "Driver for Modesetting Kernel Drivers", + intel_xorg_chipsets); +} + +static Bool +intel_xorg_pci_probe(DriverPtr driver, + int entity_num, struct pci_device *device, intptr_t match_data) +{ + ScrnInfoPtr scrn = NULL; + EntityInfoPtr entity; + + scrn = xf86ConfigPciEntity(scrn, 0, entity_num, intel_xorg_pci_devices, + NULL, NULL, NULL, NULL, NULL); + if (scrn != NULL) { + scrn->driverVersion = 1; + scrn->driverName = "i965"; + scrn->name = "modesetting"; + scrn->Probe = NULL; + + entity = xf86GetEntityInfo(entity_num); + + /* Use all the functions from the xorg tracker */ + xorg_tracker_set_functions(scrn); + } + return scrn != NULL; +} diff --git a/src/gallium/targets/xorg-nouveau/Makefile b/src/gallium/targets/xorg-nouveau/Makefile new file mode 100644 index 00000000000..d41de0b3110 --- /dev/null +++ b/src/gallium/targets/xorg-nouveau/Makefile @@ -0,0 +1,56 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +TARGET = modesetting_drv.so +CFILES = $(wildcard ./*.c) +OBJECTS = $(patsubst ./%.c,./%.o,$(CFILES)) + +INCLUDES = \ + $(shell pkg-config --cflags-only-I pixman-1 xorg-server libdrm xproto) \ + -I$(TOP)/src/gallium/include \ + -I$(TOP)/src/gallium/drivers \ + -I$(TOP)/src/gallium/auxiliary \ + -I$(TOP)/src/mesa \ + -I$(TOP)/include \ + -I$(TOP)/src/egl/main + +LIBS = \ + $(TOP)/src/gallium/state_trackers/xorg/libxorgtracker.a \ + $(TOP)/src/gallium/winsys/drm/nouveau/drm/libnouveaudrm.a \ + $(TOP)/src/gallium/drivers/nvfx/libnvfx.a \ + $(TOP)/src/gallium/drivers/nv50/libnv50.a \ + $(TOP)/src/gallium/drivers/nouveau/libnouveau.a \ + $(GALLIUM_AUXILIARIES) + +DRIVER_DEFINES = \ + -DHAVE_CONFIG_H + + +############################################# + + + +all default: $(TARGET) + +$(TARGET): $(OBJECTS) Makefile $(TOP)/src/gallium/state_trackers/xorg/libxorgtracker.a $(LIBS) + $(TOP)/bin/mklib -noprefix -o $@ \ + $(OBJECTS) $(LIBS) $(shell pkg-config --libs libdrm) -ldrm_nouveau + +clean: + rm -rf $(OBJECTS) $(TARGET) + +install: + $(INSTALL) -d $(DESTDIR)/$(XORG_DRIVER_INSTALL_DIR) + $(MINSTALL) -m 755 $(TARGET) $(DESTDIR)/$(XORG_DRIVER_INSTALL_DIR) + + +############################################## + + +.c.o: + $(CC) -c $(CFLAGS) $(INCLUDES) $(DRIVER_DEFINES) $< -o $@ + + +############################################## + +.PHONY = all clean install diff --git a/src/gallium/targets/xorg-nouveau/nouveau_xorg.c b/src/gallium/targets/xorg-nouveau/nouveau_xorg.c new file mode 100644 index 00000000000..699af09029f --- /dev/null +++ b/src/gallium/targets/xorg-nouveau/nouveau_xorg.c @@ -0,0 +1,149 @@ +/* + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * + * Author: Alan Hourihane + * Author: Jakob Bornecrantz + * + */ + +#include "../../state_trackers/xorg/xorg_winsys.h" + +static void nouveau_xorg_identify(int flags); +static Bool nouveau_xorg_pci_probe(DriverPtr driver, int entity_num, + struct pci_device *device, + intptr_t match_data); + +static const struct pci_id_match nouveau_xorg_device_match[] = { + { 0x10de, PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, + 0x00030000, 0x00ffffff, 0 }, + { 0x12d2, PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, + 0x00030000, 0x00ffffff, 0 }, + {0, 0, 0}, +}; + +static SymTabRec nouveau_xorg_chipsets[] = { + {PCI_MATCH_ANY, "NVIDIA Graphics Device"}, + {-1, NULL} +}; + +static PciChipsets nouveau_xorg_pci_devices[] = { + {PCI_MATCH_ANY, PCI_MATCH_ANY, NULL}, + {-1, -1, NULL} +}; + +static XF86ModuleVersionInfo nouveau_xorg_version = { + "modesetting", + MODULEVENDORSTRING, + MODINFOSTRING1, + MODINFOSTRING2, + XORG_VERSION_CURRENT, + 0, 1, 0, /* major, minor, patch */ + ABI_CLASS_VIDEODRV, + ABI_VIDEODRV_VERSION, + MOD_CLASS_VIDEODRV, + {0, 0, 0, 0} +}; + +/* + * Xorg driver exported structures + */ + +_X_EXPORT DriverRec modesetting = { + 1, + "modesetting", + nouveau_xorg_identify, + NULL, + xorg_tracker_available_options, + NULL, + 0, + NULL, + nouveau_xorg_device_match, + nouveau_xorg_pci_probe +}; + +static MODULESETUPPROTO(nouveau_xorg_setup); + +_X_EXPORT XF86ModuleData modesettingModuleData = { + &nouveau_xorg_version, + nouveau_xorg_setup, + NULL +}; + +/* + * Xorg driver functions + */ + +static pointer +nouveau_xorg_setup(pointer module, pointer opts, int *errmaj, int *errmin) +{ + static Bool setupDone = 0; + + /* This module should be loaded only once, but check to be sure. + */ + if (!setupDone) { + setupDone = 1; + xf86AddDriver(&modesetting, module, HaveDriverFuncs); + + /* + * The return value must be non-NULL on success even though there + * is no TearDownProc. + */ + return (pointer) 1; + } else { + if (errmaj) + *errmaj = LDR_ONCEONLY; + return NULL; + } +} + +static void +nouveau_xorg_identify(int flags) +{ + xf86PrintChipsets("modesetting", "Driver for Modesetting Kernel Drivers", + nouveau_xorg_chipsets); +} + +static Bool +nouveau_xorg_pci_probe(DriverPtr driver, + int entity_num, struct pci_device *device, intptr_t match_data) +{ + ScrnInfoPtr scrn = NULL; + EntityInfoPtr entity; + + scrn = xf86ConfigPciEntity(scrn, 0, entity_num, nouveau_xorg_pci_devices, + NULL, NULL, NULL, NULL, NULL); + if (scrn != NULL) { + scrn->driverVersion = 1; + scrn->driverName = "i915"; + scrn->name = "modesetting"; + scrn->Probe = NULL; + + entity = xf86GetEntityInfo(entity_num); + + /* Use all the functions from the xorg tracker */ + xorg_tracker_set_functions(scrn); + } + return scrn != NULL; +} diff --git a/src/gallium/targets/xorg-radeon/Makefile b/src/gallium/targets/xorg-radeon/Makefile new file mode 100644 index 00000000000..9618d30b4d6 --- /dev/null +++ b/src/gallium/targets/xorg-radeon/Makefile @@ -0,0 +1,48 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +TARGET = radeong_drv.so +CFILES = $(wildcard ./*.c) +OBJECTS = $(patsubst ./%.c,./%.o,$(CFILES)) + +CFLAGS = -DHAVE_CONFIG_H \ + -g -Wall -Wimplicit-function-declaration -fPIC \ + $(shell pkg-config --cflags pixman-1 xorg-server libdrm xproto) \ + -I$(TOP)/src/gallium/include \ + -I$(TOP)/src/gallium/drivers \ + -I$(TOP)/src/gallium/auxiliary \ + -I${TOP}/src/mesa \ + -I$(TOP)/include \ + -I$(TOP)/src/egl/main + +LIBS = \ + $(TOP)/src/gallium/state_trackers/xorg/libxorgtracker.a \ + $(TOP)/src/gallium/winsys/drm/radeon/core/libradeonwinsys.a \ + $(TOP)/src/gallium/drivers/r300/libr300.a \ + $(TOP)/src/gallium/drivers/trace/libtrace.a \ + $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ + $(GALLIUM_AUXILIARIES) + +TARGET_STAGING = $(TOP)/$(LIB_DIR)/gallium/$(TARGET) +############################################# + +all default: $(TARGET) $(TARGET_STAGING) + +$(TARGET): $(OBJECTS) Makefile $(TOP)/src/gallium/state_trackers/xorg/libxorgtracker.a $(LIBS) + $(TOP)/bin/mklib -noprefix -o $@ \ + $(OBJECTS) $(LIBS) $(shell pkg-config --libs libdrm) -ldrm_radeon + +$(TOP)/$(LIB_DIR)/gallium: + mkdir -p $@ + +$(TARGET_STAGING): $(TARGET) $(TOP)/$(LIB_DIR)/gallium + $(INSTALL) $(TARGET) $(TOP)/$(LIB_DIR)/gallium + +clean: + rm -rf $(OBJECTS) $(TARGET) + +install: + $(INSTALL) -d $(DESTDIR)/$(XORG_DRIVER_INSTALL_DIR) + $(MINSTALL) -m 755 $(TARGET) $(DESTDIR)/$(XORG_DRIVER_INSTALL_DIR) + +.PHONY = all clean install diff --git a/src/gallium/targets/xorg-radeon/radeon_xorg.c b/src/gallium/targets/xorg-radeon/radeon_xorg.c new file mode 100644 index 00000000000..0d6aa567229 --- /dev/null +++ b/src/gallium/targets/xorg-radeon/radeon_xorg.c @@ -0,0 +1,148 @@ +/* + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * + * Author: Alan Hourihane + * Author: Jakob Bornecrantz + * Author: Corbin Simpson + * + */ + +#include "../../state_trackers/xorg/xorg_winsys.h" + +static void radeon_xorg_identify(int flags); +static Bool radeon_xorg_pci_probe(DriverPtr driver, + int entity_num, + struct pci_device *device, + intptr_t match_data); + +static const struct pci_id_match radeon_xorg_device_match[] = { + {0x1002, PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, 0, 0, 0}, + {0, 0, 0}, +}; + +static SymTabRec radeon_xorg_chipsets[] = { + {PCI_MATCH_ANY, "ATI/AMD Radeon Graphics Chipset"}, + {-1, NULL} +}; + +static PciChipsets radeon_xorg_pci_devices[] = { + {PCI_MATCH_ANY, PCI_MATCH_ANY, NULL}, + {-1, -1, NULL} +}; + +static XF86ModuleVersionInfo radeon_xorg_version = { + "radeong", + MODULEVENDORSTRING, + MODINFOSTRING1, + MODINFOSTRING2, + XORG_VERSION_CURRENT, + 0, 1, 0, /* major, minor, patch */ + ABI_CLASS_VIDEODRV, + ABI_VIDEODRV_VERSION, + MOD_CLASS_VIDEODRV, + {0, 0, 0, 0} +}; + +/* + * Xorg driver exported structures + */ + +_X_EXPORT DriverRec radeong = { + 1, + "radeong", + radeon_xorg_identify, + NULL, + xorg_tracker_available_options, + NULL, + 0, + NULL, + radeon_xorg_device_match, + radeon_xorg_pci_probe +}; + +static MODULESETUPPROTO(radeon_xorg_setup); + +_X_EXPORT XF86ModuleData radeongModuleData = { + &radeon_xorg_version, + radeon_xorg_setup, + NULL +}; + +/* + * Xorg driver functions + */ + +static pointer +radeon_xorg_setup(pointer module, pointer opts, int *errmaj, int *errmin) +{ + static Bool setupDone = 0; + + /* This module should be loaded only once, but check to be sure. + */ + if (!setupDone) { + setupDone = 1; + xf86AddDriver(&radeong, module, HaveDriverFuncs); + + /* + * The return value must be non-NULL on success even though there + * is no TearDownProc. + */ + return (pointer) 1; + } else { + if (errmaj) + *errmaj = LDR_ONCEONLY; + return NULL; + } +} + +static void +radeon_xorg_identify(int flags) +{ + xf86PrintChipsets("radeong", "Driver for Radeon Gallium with KMS", + radeon_xorg_chipsets); +} + +static Bool +radeon_xorg_pci_probe(DriverPtr driver, + int entity_num, struct pci_device *device, intptr_t match_data) +{ + ScrnInfoPtr scrn = NULL; + EntityInfoPtr entity; + + scrn = xf86ConfigPciEntity(scrn, 0, entity_num, radeon_xorg_pci_devices, + NULL, NULL, NULL, NULL, NULL); + if (scrn != NULL) { + scrn->driverVersion = 1; + scrn->driverName = "radeong"; + scrn->name = "radeong"; + scrn->Probe = NULL; + + entity = xf86GetEntityInfo(entity_num); + + /* Use all the functions from the xorg tracker */ + xorg_tracker_set_functions(scrn); + } + return scrn != NULL; +} diff --git a/src/gallium/targets/xorg-vmwgfx/Makefile b/src/gallium/targets/xorg-vmwgfx/Makefile new file mode 100644 index 00000000000..3691b883588 --- /dev/null +++ b/src/gallium/targets/xorg-vmwgfx/Makefile @@ -0,0 +1,70 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +TARGET = vmwgfx_drv.so + +CFILES = \ + vmw_xorg.c \ + vmw_video.c \ + vmw_ioctl.c \ + vmw_screen.c + +OBJECTS = $(patsubst %.c,%.o,$(CFILES)) + +INCLUDES = \ + $(shell pkg-config --cflags-only-I pixman-1 xorg-server libdrm xproto) \ + -I$(TOP)/src/gallium/include \ + -I$(TOP)/src/gallium/drivers \ + -I$(TOP)/src/gallium/auxiliary \ + -I$(TOP)/src/gallium + +LIBS = \ + $(TOP)/src/gallium/state_trackers/xorg/libxorgtracker.a \ + $(TOP)/src/gallium/winsys/drm/vmware/core/libsvgadrm.a \ + $(TOP)/src/gallium/drivers/trace/libtrace.a \ + $(TOP)/src/gallium/drivers/svga/libsvga.a \ + $(GALLIUM_AUXILIARIES) + +LINKS = \ + $(shell pkg-config --libs --silence-errors libkms) \ + $(shell pkg-config --libs libdrm) + +DRIVER_DEFINES = \ + -std=gnu99 \ + -DHAVE_CONFIG_H + +TARGET_STAGING = $(TOP)/$(LIB_DIR)/gallium/$(TARGET) + +############################################# + + + +all default: $(TARGET) $(TARGET_STAGING) + +$(TARGET): $(OBJECTS) Makefile $(LIBS) + $(MKLIB) -noprefix -o $@ $(OBJECTS) $(LIBS) $(LINKS) + +$(TOP)/$(LIB_DIR)/gallium: + mkdir -p $@ + +$(TARGET_STAGING): $(TARGET) $(TOP)/$(LIB_DIR)/gallium + $(INSTALL) $(TARGET) $(TOP)/$(LIB_DIR)/gallium + +clean: + rm -rf $(OBJECTS) $(TARGET) + +install: + $(INSTALL) -d $(DESTDIR)/$(XORG_DRIVER_INSTALL_DIR) + $(MINSTALL) -m 755 $(TARGET) $(DESTDIR)/$(XORG_DRIVER_INSTALL_DIR) + + +############################################## + + +.c.o: + $(CC) -c $(CFLAGS) $(INCLUDES) $(DRIVER_DEFINES) $< -o $@ + + +############################################## + +.PHONY = all clean install diff --git a/src/gallium/targets/xorg-vmwgfx/SConscript b/src/gallium/targets/xorg-vmwgfx/SConscript new file mode 100644 index 00000000000..1e5d8ff7fed --- /dev/null +++ b/src/gallium/targets/xorg-vmwgfx/SConscript @@ -0,0 +1,57 @@ +import os.path + +Import('*') + +if env['platform'] == 'linux': + + env = env.Clone() + + env.ParseConfig('pkg-config --cflags --libs libdrm xorg-server') + + env.Prepend(CPPPATH = [ + '#/include', + '#/src/gallium', + '#/src/mesa', + '#/src/gallium/drivers/svga', + '#/src/gallium/drivers/svga/include', + ]) + + env.Append(CPPDEFINES = [ + ]) + + if env['gcc']: + env.Append(CPPDEFINES = [ + 'HAVE_STDINT_H', + 'HAVE_SYS_TYPES_H', + ]) + + env.Append(CFLAGS = [ + '-std=gnu99', + '-D_FILE_OFFSET_BITS=64', + ]) + + env.Prepend(LIBPATH = [ + ]) + + env.Prepend(LIBS = [ + trace, + st_xorg, + svgadrm, + svga, + gallium, + ]) + + sources = [ + 'vmw_ioctl.c', + 'vmw_screen.c', + 'vmw_video.c', + 'vmw_xorg.c', + ] + + # TODO: write a wrapper function http://www.scons.org/wiki/WrapperFunctions + env.LoadableModule( + target ='vmwgfx_drv.so', + source = sources, + LIBS = env['LIBS'], + SHLIBPREFIX = '', + ) diff --git a/src/gallium/targets/xorg-vmwgfx/vmw_driver.h b/src/gallium/targets/xorg-vmwgfx/vmw_driver.h new file mode 100644 index 00000000000..ba754b51e47 --- /dev/null +++ b/src/gallium/targets/xorg-vmwgfx/vmw_driver.h @@ -0,0 +1,103 @@ +/********************************************************** + * Copyright 2009 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + **********************************************************/ + +/** + * @file + * Contains the shared resources for VMware Xorg driver + * that sits ontop of the Xorg State Traker. + * + * It is initialized in vmw_screen.c. + * + * @author Jakob Bornecrantz + */ + +#ifndef VMW_DRIVER_H_ +#define VMW_DRIVER_H_ + +#include "state_trackers/xorg/xorg_tracker.h" + +struct vmw_dma_buffer; + +struct vmw_customizer +{ + CustomizerRec base; + ScrnInfoPtr pScrn; + + int fd; + + void *cursor_priv; + + /* vmw_video.c */ + void *video_priv; +}; + +static INLINE struct vmw_customizer * +vmw_customizer(CustomizerPtr cust) +{ + return cust ? (struct vmw_customizer *) cust : NULL; +} + + +/*********************************************************************** + * vmw_video.c + */ + +Bool vmw_video_init(struct vmw_customizer *vmw); + +Bool vmw_video_close(struct vmw_customizer *vmw); + +void vmw_video_stop_all(struct vmw_customizer *vmw); + + +/*********************************************************************** + * vmw_ioctl.c + */ + +int vmw_ioctl_cursor_bypass(struct vmw_customizer *vmw, int xhot, int yhot); + +struct vmw_dma_buffer * vmw_ioctl_buffer_create(struct vmw_customizer *vmw, + uint32_t size, + unsigned *handle); + +void * vmw_ioctl_buffer_map(struct vmw_customizer *vmw, + struct vmw_dma_buffer *buf); + +void vmw_ioctl_buffer_unmap(struct vmw_customizer *vmw, + struct vmw_dma_buffer *buf); + +void vmw_ioctl_buffer_destroy(struct vmw_customizer *vmw, + struct vmw_dma_buffer *buf); + +int vmw_ioctl_supports_streams(struct vmw_customizer *vmw); + +int vmw_ioctl_num_streams(struct vmw_customizer *vmw, + uint32_t *ntot, uint32_t *nfree); + +int vmw_ioctl_unref_stream(struct vmw_customizer *vmw, uint32_t stream_id); + +int vmw_ioctl_claim_stream(struct vmw_customizer *vmw, uint32_t *out); + + +#endif diff --git a/src/gallium/targets/xorg-vmwgfx/vmw_hook.h b/src/gallium/targets/xorg-vmwgfx/vmw_hook.h new file mode 100644 index 00000000000..224a2d92996 --- /dev/null +++ b/src/gallium/targets/xorg-vmwgfx/vmw_hook.h @@ -0,0 +1,39 @@ +/********************************************************** + * Copyright 2009 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + **********************************************************/ + +#ifndef VMW_HOOK_H_ +#define VMW_HOOK_H_ + +#include "state_trackers/xorg/xorg_winsys.h" + + +/*********************************************************************** + * vmw_screen.c + */ + +void vmw_screen_set_functions(ScrnInfoPtr pScrn); + + +#endif diff --git a/src/gallium/targets/xorg-vmwgfx/vmw_ioctl.c b/src/gallium/targets/xorg-vmwgfx/vmw_ioctl.c new file mode 100644 index 00000000000..fe9c0393e23 --- /dev/null +++ b/src/gallium/targets/xorg-vmwgfx/vmw_ioctl.c @@ -0,0 +1,242 @@ +/********************************************************** + * Copyright 2009 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + **********************************************************/ + +/** + * @file + * Contains the functions for creating dma buffers by calling + * the kernel via driver specific ioctls. + * + * @author Jakob Bornecrantz + */ + +#ifndef HAVE_STDINT_H +#define HAVE_STDINT_H 1 +#endif +#define _FILE_OFFSET_BITS 64 + +#include +#include +#include + +#include +#include "xf86drm.h" +#include "../../winsys/drm/vmware/core/vmwgfx_drm.h" + +#include "vmw_driver.h" +#include "util/u_debug.h" + +struct vmw_dma_buffer +{ + void *data; + unsigned handle; + uint64_t map_handle; + unsigned map_count; + uint32_t size; +}; + +static int +vmw_ioctl_get_param(struct vmw_customizer *vmw, uint32_t param, uint64_t *out) +{ + struct drm_vmw_getparam_arg gp_arg; + int ret; + + memset(&gp_arg, 0, sizeof(gp_arg)); + gp_arg.param = param; + ret = drmCommandWriteRead(vmw->fd, DRM_VMW_GET_PARAM, + &gp_arg, sizeof(gp_arg)); + + if (ret == 0) { + *out = gp_arg.value; + } + + return ret; +} + +int +vmw_ioctl_supports_streams(struct vmw_customizer *vmw) +{ + uint64_t value; + int ret; + + ret = vmw_ioctl_get_param(vmw, DRM_VMW_PARAM_NUM_STREAMS, &value); + if (ret) + return ret; + + return value ? 0 : -ENOSYS; +} + +int +vmw_ioctl_num_streams(struct vmw_customizer *vmw, + uint32_t *ntot, uint32_t *nfree) +{ + uint64_t v1, v2; + int ret; + + ret = vmw_ioctl_get_param(vmw, DRM_VMW_PARAM_NUM_STREAMS, &v1); + if (ret) + return ret; + + ret = vmw_ioctl_get_param(vmw, DRM_VMW_PARAM_NUM_FREE_STREAMS, &v2); + if (ret) + return ret; + + *ntot = (uint32_t)v1; + *nfree = (uint32_t)v2; + + return 0; +} + +int +vmw_ioctl_claim_stream(struct vmw_customizer *vmw, uint32_t *out) +{ + struct drm_vmw_stream_arg s_arg; + int ret; + + ret = drmCommandRead(vmw->fd, DRM_VMW_CLAIM_STREAM, + &s_arg, sizeof(s_arg)); + + if (ret) + return -1; + + *out = s_arg.stream_id; + return 0; +} + +int +vmw_ioctl_unref_stream(struct vmw_customizer *vmw, uint32_t stream_id) +{ + struct drm_vmw_stream_arg s_arg; + int ret; + + memset(&s_arg, 0, sizeof(s_arg)); + s_arg.stream_id = stream_id; + + ret = drmCommandRead(vmw->fd, DRM_VMW_CLAIM_STREAM, + &s_arg, sizeof(s_arg)); + + return 0; +} + +int +vmw_ioctl_cursor_bypass(struct vmw_customizer *vmw, int xhot, int yhot) +{ + struct drm_vmw_cursor_bypass_arg arg; + int ret; + + memset(&arg, 0, sizeof(arg)); + arg.flags = DRM_VMW_CURSOR_BYPASS_ALL; + arg.xhot = xhot; + arg.yhot = yhot; + + ret = drmCommandWrite(vmw->fd, DRM_VMW_CURSOR_BYPASS, + &arg, sizeof(arg)); + + return ret; +} + +struct vmw_dma_buffer * +vmw_ioctl_buffer_create(struct vmw_customizer *vmw, uint32_t size, unsigned *handle) +{ + struct vmw_dma_buffer *buf; + union drm_vmw_alloc_dmabuf_arg arg; + struct drm_vmw_alloc_dmabuf_req *req = &arg.req; + struct drm_vmw_dmabuf_rep *rep = &arg.rep; + int ret; + + buf = xcalloc(1, sizeof(*buf)); + if (!buf) + goto err; + + memset(&arg, 0, sizeof(arg)); + req->size = size; + do { + ret = drmCommandWriteRead(vmw->fd, DRM_VMW_ALLOC_DMABUF, &arg, sizeof(arg)); + } while (ret == -ERESTART); + + if (ret) { + debug_printf("IOCTL failed %d: %s\n", ret, strerror(-ret)); + goto err_free; + } + + + buf->data = NULL; + buf->handle = rep->handle; + buf->map_handle = rep->map_handle; + buf->map_count = 0; + buf->size = size; + + *handle = rep->handle; + + return buf; + +err_free: + xfree(buf); +err: + return NULL; +} + +void +vmw_ioctl_buffer_destroy(struct vmw_customizer *vmw, struct vmw_dma_buffer *buf) +{ + struct drm_vmw_unref_dmabuf_arg arg; + + if (buf->data) { + munmap(buf->data, buf->size); + buf->data = NULL; + } + + memset(&arg, 0, sizeof(arg)); + arg.handle = buf->handle; + drmCommandWrite(vmw->fd, DRM_VMW_UNREF_DMABUF, &arg, sizeof(arg)); + + xfree(buf); +} + +void * +vmw_ioctl_buffer_map(struct vmw_customizer *vmw, struct vmw_dma_buffer *buf) +{ + void *map; + + if (buf->data == NULL) { + map = mmap(NULL, buf->size, PROT_READ | PROT_WRITE, MAP_SHARED, + vmw->fd, buf->map_handle); + if (map == MAP_FAILED) { + debug_printf("%s: Map failed.\n", __FUNCTION__); + return NULL; + } + + buf->data = map; + } + + ++buf->map_count; + + return buf->data; +} + +void +vmw_ioctl_buffer_unmap(struct vmw_customizer *vmw, struct vmw_dma_buffer *buf) +{ + --buf->map_count; +} diff --git a/src/gallium/targets/xorg-vmwgfx/vmw_screen.c b/src/gallium/targets/xorg-vmwgfx/vmw_screen.c new file mode 100644 index 00000000000..f43f91e5c0d --- /dev/null +++ b/src/gallium/targets/xorg-vmwgfx/vmw_screen.c @@ -0,0 +1,178 @@ +/********************************************************** + * Copyright 2009 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + **********************************************************/ + +/** + * @file + * Contains the init code for the VMware Xorg driver. + * + * @author Jakob Bornecrantz + */ + +#include "vmw_hook.h" +#include "vmw_driver.h" + +#include "cursorstr.h" + +/* modified version of crtc functions */ +xf86CrtcFuncsRec vmw_screen_crtc_funcs; + +static void +vmw_screen_cursor_load_argb(xf86CrtcPtr crtc, CARD32 *image) +{ + struct vmw_customizer *vmw = + vmw_customizer(xorg_customizer(crtc->scrn)); + xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(crtc->scrn); + xf86CrtcFuncsPtr funcs = vmw->cursor_priv; + CursorPtr c = config->cursor; + + /* Run the ioctl before uploading the image */ + vmw_ioctl_cursor_bypass(vmw, c->bits->xhot, c->bits->yhot); + + funcs->load_cursor_argb(crtc, image); +} + +static void +vmw_screen_cursor_init(struct vmw_customizer *vmw) +{ + ScrnInfoPtr pScrn = vmw->pScrn; + xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); + int i; + + /* XXX assume that all crtc's have the same function struct */ + + /* Save old struct need to call the old functions as well */ + vmw->cursor_priv = (void*)(config->crtc[0]->funcs); + memcpy(&vmw_screen_crtc_funcs, vmw->cursor_priv, sizeof(xf86CrtcFuncsRec)); + vmw_screen_crtc_funcs.load_cursor_argb = vmw_screen_cursor_load_argb; + + for (i = 0; i < config->num_crtc; i++) + config->crtc[i]->funcs = &vmw_screen_crtc_funcs; +} + +static void +vmw_screen_cursor_close(struct vmw_customizer *vmw) +{ + xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(vmw->pScrn); + int i; + + vmw_ioctl_cursor_bypass(vmw, 0, 0); + + for (i = 0; i < config->num_crtc; i++) + config->crtc[i]->funcs = vmw->cursor_priv; +} + +static Bool +vmw_screen_init(CustomizerPtr cust, int fd) +{ + struct vmw_customizer *vmw = vmw_customizer(cust); + + vmw->fd = fd; + vmw_screen_cursor_init(vmw); + + /* if gallium is used then we don't need to do anything more. */ + if (xorg_has_gallium(vmw->pScrn)) + return TRUE; + + vmw_video_init(vmw); + + return TRUE; +} + +static Bool +vmw_screen_close(CustomizerPtr cust) +{ + struct vmw_customizer *vmw = vmw_customizer(cust); + + if (!vmw) + return TRUE; + + vmw_screen_cursor_close(vmw); + + vmw_video_close(vmw); + + return TRUE; +} + +static Bool +vmw_screen_enter_vt(CustomizerPtr cust) +{ + debug_printf("%s: enter\n", __func__); + + return TRUE; +} + +static Bool +vmw_screen_leave_vt(CustomizerPtr cust) +{ + struct vmw_customizer *vmw = vmw_customizer(cust); + + debug_printf("%s: enter\n", __func__); + + vmw_video_stop_all(vmw); + + return TRUE; +} + +/* + * Functions for setting up hooks into the xorg state tracker + */ + +static Bool (*vmw_screen_pre_init_saved)(ScrnInfoPtr pScrn, int flags) = NULL; + +static Bool +vmw_screen_pre_init(ScrnInfoPtr pScrn, int flags) +{ + struct vmw_customizer *vmw; + CustomizerPtr cust; + + vmw = xnfcalloc(1, sizeof(*vmw)); + if (!vmw) + return FALSE; + + cust = &vmw->base; + + cust->winsys_screen_init = vmw_screen_init; + cust->winsys_screen_close = vmw_screen_close; + cust->winsys_enter_vt = vmw_screen_enter_vt; + cust->winsys_leave_vt = vmw_screen_leave_vt; + vmw->pScrn = pScrn; + + pScrn->driverPrivate = cust; + + pScrn->PreInit = vmw_screen_pre_init_saved; + if (!pScrn->PreInit(pScrn, flags)) + return FALSE; + + return TRUE; +} + +void +vmw_screen_set_functions(ScrnInfoPtr pScrn) +{ + assert(!vmw_screen_pre_init_saved); + + vmw_screen_pre_init_saved = pScrn->PreInit; + pScrn->PreInit = vmw_screen_pre_init; +} diff --git a/src/gallium/targets/xorg-vmwgfx/vmw_video.c b/src/gallium/targets/xorg-vmwgfx/vmw_video.c new file mode 100644 index 00000000000..7909999edfb --- /dev/null +++ b/src/gallium/targets/xorg-vmwgfx/vmw_video.c @@ -0,0 +1,1072 @@ +/* + * Copyright 2007 by VMware, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of the copyright holder(s) + * and author(s) shall not be used in advertising or otherwise to promote + * the sale, use or other dealings in this Software without prior written + * authorization from the copyright holder(s) and author(s). + */ + +/* + * vmwarevideo.c -- + * + * Xv extension support. + * See http://www.xfree86.org/current/DESIGN16.html + * + */ + + +#include "xf86xv.h" +#include "fourcc.h" + +#include "pipe/p_compiler.h" +/* + * We can't incude svga_types.h due to conflicting types for Bool. + */ +typedef int64_t int64; +typedef uint64_t uint64; + +typedef int32_t int32; +typedef uint32_t uint32; + +typedef int16_t int16; +typedef uint16_t uint16; + +typedef int8_t int8; +typedef uint8_t uint8; + +#include "svga/include/svga_reg.h" +#include "svga/include/svga_escape.h" +#include "svga/include/svga_overlay.h" + +#include "vmw_driver.h" + +#include + +#include "xf86drm.h" +#include "../../winsys/drm/vmware/core/vmwgfx_drm.h" + +#define MAKE_ATOM(a) MakeAtom(a, sizeof(a) - 1, TRUE) + +/* + * Number of videos that can be played simultaneously + */ +#define VMWARE_VID_NUM_PORTS 1 + +/* + * Using a dark shade as the default colorKey + */ +#define VMWARE_VIDEO_COLORKEY 0x100701 + +/* + * Maximum dimensions + */ +#define VMWARE_VID_MAX_WIDTH 2048 +#define VMWARE_VID_MAX_HEIGHT 2048 + +#define VMWARE_VID_NUM_ENCODINGS 1 +static XF86VideoEncodingRec vmwareVideoEncodings[] = +{ + { + 0, + "XV_IMAGE", + VMWARE_VID_MAX_WIDTH, VMWARE_VID_MAX_HEIGHT, + {1, 1} + } +}; + +#define VMWARE_VID_NUM_FORMATS 2 +static XF86VideoFormatRec vmwareVideoFormats[] = +{ + { 16, TrueColor}, + { 24, TrueColor} +}; + +#define VMWARE_VID_NUM_IMAGES 3 +static XF86ImageRec vmwareVideoImages[] = +{ + XVIMAGE_YV12, + XVIMAGE_YUY2, + XVIMAGE_UYVY +}; + +#define VMWARE_VID_NUM_ATTRIBUTES 2 +static XF86AttributeRec vmwareVideoAttributes[] = +{ + { + XvGettable | XvSettable, + 0x000000, + 0xffffff, + "XV_COLORKEY" + }, + { + XvGettable | XvSettable, + 0, + 1, + "XV_AUTOPAINT_COLORKEY" + } +}; + +/* + * Video frames are stored in a circular list of buffers. + * Must be power or two, See vmw_video_port_play. + */ +#define VMWARE_VID_NUM_BUFFERS 1 + +/* + * Defines the structure used to hold and pass video data to the host + */ +struct vmw_video_buffer +{ + unsigned handle; + int size; + void *data; + void *extra_data; + struct vmw_dma_buffer *buf; +}; + + +/** + * Structure representing a single video stream, aka port. + * + * Ports maps one to one to a SVGA stream. Port is just + * what Xv calls a SVGA stream. + */ +struct vmw_video_port +{ + /* + * Function prototype same as XvPutImage. + * + * This is either set to vmw_video_port_init or vmw_video_port_play. + * At init this function is set to port_init. In port_init we set it + * to port_play and call it, after initializing the struct. + */ + int (*play)(ScrnInfoPtr, struct vmw_video_port *, + short, short, short, short, short, + short, short, short, int, unsigned char*, + short, short, RegionPtr); + + /* values to go into the SVGAOverlayUnit */ + uint32 streamId; + uint32 colorKey; + uint32 flags; + + /* round robin of buffers */ + unsigned currBuf; + struct vmw_video_buffer bufs[VMWARE_VID_NUM_BUFFERS]; + + /* properties that applies to all buffers */ + int size; + int pitches[3]; + int offsets[3]; + + /* things for X */ + RegionRec clipBoxes; + Bool isAutoPaintColorkey; +}; + + +/** + * Structure holding all the infromation for video. + */ +struct vmw_video_private +{ + int fd; + + /** ports */ + struct vmw_video_port port[VMWARE_VID_NUM_PORTS]; + + /** Used to store port pointers pointers */ + DevUnion port_ptr[VMWARE_VID_NUM_PORTS]; +}; + + +/* + * Callback functions exported to Xv, prefixed with vmw_xv_*. + */ +static int vmw_xv_put_image(ScrnInfoPtr pScrn, short src_x, short src_y, + short drw_x, short drw_y, short src_w, short src_h, + short drw_w, short drw_h, int image, + unsigned char *buf, short width, short height, + Bool sync, RegionPtr clipBoxes, pointer data, + DrawablePtr dst); +static void vmw_xv_stop_video(ScrnInfoPtr pScrn, pointer data, Bool Cleanup); +static int vmw_xv_query_image_attributes(ScrnInfoPtr pScrn, int format, + unsigned short *width, + unsigned short *height, int *pitches, + int *offsets); +static int vmw_xv_set_port_attribute(ScrnInfoPtr pScrn, Atom attribute, + INT32 value, pointer data); +static int vmw_xv_get_port_attribute(ScrnInfoPtr pScrn, Atom attribute, + INT32 *value, pointer data); +static void vmw_xv_query_best_size(ScrnInfoPtr pScrn, Bool motion, + short vid_w, short vid_h, short drw_w, + short drw_h, unsigned int *p_w, + unsigned int *p_h, pointer data); + + +/* + * Local functions. + */ +static XF86VideoAdaptorPtr vmw_video_init_adaptor(ScrnInfoPtr pScrn, struct vmw_customizer *vmw); + +static int vmw_video_port_init(ScrnInfoPtr pScrn, + struct vmw_video_port *port, + short src_x, short src_y, short drw_x, + short drw_y, short src_w, short src_h, + short drw_w, short drw_h, int format, + unsigned char *buf, short width, + short height, RegionPtr clipBoxes); +static int vmw_video_port_play(ScrnInfoPtr pScrn, struct vmw_video_port *port, + short src_x, short src_y, short drw_x, + short drw_y, short src_w, short src_h, + short drw_w, short drw_h, int format, + unsigned char *buf, short width, + short height, RegionPtr clipBoxes); +static void vmw_video_port_cleanup(ScrnInfoPtr pScrn, struct vmw_video_port *port); + +static int vmw_video_buffer_alloc(struct vmw_customizer *vmw, int size, + struct vmw_video_buffer *out); +static int vmw_video_buffer_free(struct vmw_customizer *vmw, + struct vmw_video_buffer *out); + + +/* + *----------------------------------------------------------------------------- + * + * vmw_video_init -- + * + * Initializes Xv support. + * + * Results: + * TRUE on success, FALSE on error. + * + * Side effects: + * Xv support is initialized. Memory is allocated for all supported + * video streams. + * + *----------------------------------------------------------------------------- + */ + +Bool +vmw_video_init(struct vmw_customizer *vmw) +{ + ScrnInfoPtr pScrn = vmw->pScrn; + ScreenPtr pScreen = pScrn->pScreen; + XF86VideoAdaptorPtr *overlayAdaptors, *newAdaptors = NULL; + XF86VideoAdaptorPtr newAdaptor = NULL; + int numAdaptors; + unsigned int ntot, nfree; + + debug_printf("%s: enter\n", __func__); + + if (vmw_ioctl_num_streams(vmw, &ntot, &nfree) != 0) { + debug_printf("No stream ioctl support\n"); + return FALSE; + } + + if (nfree == 0) { + debug_printf("No free streams\n"); + return FALSE; + } + + numAdaptors = xf86XVListGenericAdaptors(pScrn, &overlayAdaptors); + + newAdaptor = vmw_video_init_adaptor(pScrn, vmw); + if (!newAdaptor) { + debug_printf("Failed to initialize Xv extension\n"); + return FALSE; + } + + if (!numAdaptors) { + numAdaptors = 1; + overlayAdaptors = &newAdaptor; + } else { + newAdaptors = xalloc((numAdaptors + 1) * + sizeof(XF86VideoAdaptorPtr*)); + if (!newAdaptors) { + xf86XVFreeVideoAdaptorRec(newAdaptor); + return FALSE; + } + + memcpy(newAdaptors, overlayAdaptors, + numAdaptors * sizeof(XF86VideoAdaptorPtr)); + newAdaptors[numAdaptors++] = newAdaptor; + overlayAdaptors = newAdaptors; + } + + if (!xf86XVScreenInit(pScreen, overlayAdaptors, numAdaptors)) { + debug_printf("Failed to initialize Xv extension\n"); + xf86XVFreeVideoAdaptorRec(newAdaptor); + return FALSE; + } + + if (newAdaptors) { + xfree(newAdaptors); + } + + debug_printf("Initialized VMware Xv extension successfully\n"); + + return TRUE; +} + + +/* + *----------------------------------------------------------------------------- + * + * vmw_video_close -- + * + * Unitializes video. + * + * Results: + * TRUE. + * + * Side effects: + * vmw->video_priv = NULL + * + *----------------------------------------------------------------------------- + */ + +Bool +vmw_video_close(struct vmw_customizer *vmw) +{ + ScrnInfoPtr pScrn = vmw->pScrn; + struct vmw_video_private *video; + int i; + + debug_printf("%s: enter\n", __func__); + + video = vmw->video_priv; + if (!video) + return TRUE; + + for (i = 0; i < VMWARE_VID_NUM_PORTS; ++i) { + /* make sure the port is stoped as well */ + vmw_xv_stop_video(pScrn, &video->port[i], TRUE); + vmw_ioctl_unref_stream(vmw, video->port[i].streamId); + } + + /* XXX: I'm sure this function is missing code for turning off Xv */ + + free(vmw->video_priv); + vmw->video_priv = NULL; + + return TRUE; +} + + +/* + *----------------------------------------------------------------------------- + * + * vmw_video_stop_all -- + * + * Stop all video streams from playing. + * + * Results: + * None. + * + * Side effects: + * All buffers are freed. + * + *----------------------------------------------------------------------------- + */ + +void vmw_video_stop_all(struct vmw_customizer *vmw) +{ + ScrnInfoPtr pScrn = vmw->pScrn; + struct vmw_video_private *video = vmw->video_priv; + int i; + + debug_printf("%s: enter\n", __func__); + + if (!video) + return; + + for (i = 0; i < VMWARE_VID_NUM_PORTS; ++i) { + vmw_xv_stop_video(pScrn, &video->port[i], TRUE); + } +} + + +/* + *----------------------------------------------------------------------------- + * + * vmw_video_init_adaptor -- + * + * Initializes a XF86VideoAdaptor structure with the capabilities and + * functions supported by this video driver. + * + * Results: + * On success initialized XF86VideoAdaptor struct or NULL on error + * + * Side effects: + * None. + * + *----------------------------------------------------------------------------- + */ + +static XF86VideoAdaptorPtr +vmw_video_init_adaptor(ScrnInfoPtr pScrn, struct vmw_customizer *vmw) +{ + XF86VideoAdaptorPtr adaptor; + struct vmw_video_private *video; + int i; + + debug_printf("%s: enter \n", __func__); + + adaptor = xf86XVAllocateVideoAdaptorRec(pScrn); + if (!adaptor) { + debug_printf("Not enough memory\n"); + return NULL; + } + + video = xcalloc(1, sizeof(*video)); + if (!video) { + debug_printf("Not enough memory.\n"); + xf86XVFreeVideoAdaptorRec(adaptor); + return NULL; + } + + vmw->video_priv = video; + + adaptor->type = XvInputMask | XvImageMask | XvWindowMask; + adaptor->flags = VIDEO_OVERLAID_IMAGES | VIDEO_CLIP_TO_VIEWPORT; + adaptor->name = "VMware Video Engine"; + adaptor->nEncodings = VMWARE_VID_NUM_ENCODINGS; + adaptor->pEncodings = vmwareVideoEncodings; + adaptor->nFormats = VMWARE_VID_NUM_FORMATS; + adaptor->pFormats = vmwareVideoFormats; + adaptor->nPorts = VMWARE_VID_NUM_PORTS; + adaptor->pPortPrivates = video->port_ptr; + + for (i = 0; i < VMWARE_VID_NUM_PORTS; ++i) { + vmw_ioctl_claim_stream(vmw, &video->port[i].streamId); + video->port[i].play = vmw_video_port_init; + video->port[i].flags = SVGA_VIDEO_FLAG_COLORKEY; + video->port[i].colorKey = VMWARE_VIDEO_COLORKEY; + video->port[i].isAutoPaintColorkey = TRUE; + adaptor->pPortPrivates[i].ptr = &video->port[i]; + } + + adaptor->nAttributes = VMWARE_VID_NUM_ATTRIBUTES; + adaptor->pAttributes = vmwareVideoAttributes; + + adaptor->nImages = VMWARE_VID_NUM_IMAGES; + adaptor->pImages = vmwareVideoImages; + + adaptor->PutVideo = NULL; + adaptor->PutStill = NULL; + adaptor->GetVideo = NULL; + adaptor->GetStill = NULL; + adaptor->StopVideo = vmw_xv_stop_video; + adaptor->SetPortAttribute = vmw_xv_set_port_attribute; + adaptor->GetPortAttribute = vmw_xv_get_port_attribute; + adaptor->QueryBestSize = vmw_xv_query_best_size; + adaptor->PutImage = vmw_xv_put_image; + adaptor->QueryImageAttributes = vmw_xv_query_image_attributes; + + debug_printf("%s: done %p\n", __func__, adaptor); + + return adaptor; +} + + +/* + *----------------------------------------------------------------------------- + * + * vmw_video_port_init -- + * + * Initializes a video stream in response to the first PutImage() on a + * video stream. The process goes as follows: + * - Figure out characteristics according to format + * - Allocate offscreen memory + * - Pass on video to Play() functions + * + * Results: + * Success or XvBadAlloc on failure. + * + * Side effects: + * Video stream is initialized and its first frame sent to the host + * (done by VideoPlay() function called at the end) + * + *----------------------------------------------------------------------------- + */ + +static int +vmw_video_port_init(ScrnInfoPtr pScrn, struct vmw_video_port *port, + short src_x, short src_y, short drw_x, + short drw_y, short src_w, short src_h, + short drw_w, short drw_h, int format, + unsigned char *buf, short width, + short height, RegionPtr clipBoxes) +{ + struct vmw_customizer *vmw = vmw_customizer(xorg_customizer(pScrn)); + unsigned short w, h; + int i, ret; + + debug_printf("\t%s: id %d, format %d\n", __func__, port->streamId, format); + + w = width; + h = height; + /* init all the format attributes, used for buffers */ + port->size = vmw_xv_query_image_attributes(pScrn, format, &w, &h, + port->pitches, port->offsets); + + if (port->size == -1) + return XvBadAlloc; + + port->play = vmw_video_port_play; + + for (i = 0; i < VMWARE_VID_NUM_BUFFERS; ++i) { + ret = vmw_video_buffer_alloc(vmw, port->size, &port->bufs[i]); + if (ret != Success) + break; + } + + /* Free all allocated buffers on failure */ + if (ret != Success) { + for (--i; i >= 0; --i) { + vmw_video_buffer_free(vmw, &port->bufs[i]); + } + return ret; + } + + port->currBuf = 0; + + REGION_COPY(pScrn->pScreen, &port->clipBoxes, clipBoxes); + + if (port->isAutoPaintColorkey) + xf86XVFillKeyHelper(pScrn->pScreen, port->colorKey, clipBoxes); + + return port->play(pScrn, port, src_x, src_y, drw_x, drw_y, src_w, src_h, + drw_w, drw_h, format, buf, width, height, clipBoxes); +} + + +/* + *----------------------------------------------------------------------------- + * + * vmw_video_port_play -- + * + * Sends all the attributes associated with the video frame using the + * FIFO ESCAPE mechanism to the host. + * + * Results: + * Always returns Success. + * + * Side effects: + * None. + * + *----------------------------------------------------------------------------- + */ + +static int +vmw_video_port_play(ScrnInfoPtr pScrn, struct vmw_video_port *port, + short src_x, short src_y, short drw_x, + short drw_y, short src_w, short src_h, + short drw_w, short drw_h, int format, + unsigned char *buf, short width, + short height, RegionPtr clipBoxes) +{ + struct vmw_customizer *vmw = vmw_customizer(xorg_customizer(pScrn)); + struct drm_vmw_control_stream_arg arg; + unsigned short w, h; + int size; + int ret; + + debug_printf("\t%s: enter\n", __func__); + + w = width; + h = height; + + /* we don't update the ports size */ + size = vmw_xv_query_image_attributes(pScrn, format, &w, &h, + port->pitches, port->offsets); + + if (size > port->size) { + debug_printf("\t%s: Increase in size of Xv video frame streamId:%d.\n", + __func__, port->streamId); + vmw_xv_stop_video(pScrn, port, TRUE); + return port->play(pScrn, port, src_x, src_y, drw_x, drw_y, src_w, + src_h, drw_w, drw_h, format, buf, width, height, + clipBoxes); + } + + memcpy(port->bufs[port->currBuf].data, buf, port->size); + + memset(&arg, 0, sizeof(arg)); + + arg.stream_id = port->streamId; + arg.enabled = TRUE; + arg.flags = port->flags; + arg.color_key = port->colorKey; + arg.handle = port->bufs[port->currBuf].handle; + arg.format = format; + arg.size = port->size; + arg.width = w; + arg.height = h; + arg.src.x = src_x; + arg.src.y = src_y; + arg.src.w = src_w; + arg.src.h = src_h; + arg.dst.x = drw_x; + arg.dst.y = drw_y; + arg.dst.w = drw_w; + arg.dst.h = drw_h; + arg.pitch[0] = port->pitches[0]; + arg.pitch[1] = port->pitches[1]; + arg.pitch[2] = port->pitches[2]; + arg.offset = 0; + + /* + * Update the clipList and paint the colorkey, if required. + */ + if (!REGION_EQUAL(pScrn->pScreen, &port->clipBoxes, clipBoxes)) { + REGION_COPY(pScrn->pScreen, &port->clipBoxes, clipBoxes); + if (port->isAutoPaintColorkey) { + xf86XVFillKeyHelper(pScrn->pScreen, port->colorKey, clipBoxes); + } + } + + ret = drmCommandWrite(vmw->fd, DRM_VMW_CONTROL_STREAM, &arg, sizeof(arg)); + if (ret) { + vmw_video_port_cleanup(pScrn, port); + return XvBadAlloc; + } + + if (++(port->currBuf) >= VMWARE_VID_NUM_BUFFERS) + port->currBuf = 0; + + return Success; +} + + +/* + *----------------------------------------------------------------------------- + * + * vmw_video_port_cleanup -- + * + * Frees up all resources (if any) taken by a video stream. + * + * Results: + * None. + * + * Side effects: + * Same as above. + * + *----------------------------------------------------------------------------- + */ + +static void +vmw_video_port_cleanup(ScrnInfoPtr pScrn, struct vmw_video_port *port) +{ + struct vmw_customizer *vmw = vmw_customizer(xorg_customizer(pScrn)); + uint32 id, colorKey, flags; + Bool isAutoPaintColorkey; + int i; + + debug_printf("\t%s: enter\n", __func__); + + for (i = 0; i < VMWARE_VID_NUM_BUFFERS; i++) { + vmw_video_buffer_free(vmw, &port->bufs[i]); + } + + /* + * reset stream for next video + */ + id = port->streamId; + colorKey = port->colorKey; + flags = port->flags; + isAutoPaintColorkey = port->isAutoPaintColorkey; + + memset(port, 0, sizeof(*port)); + + port->streamId = id; + port->play = vmw_video_port_init; + port->colorKey = colorKey; + port->flags = flags; + port->isAutoPaintColorkey = isAutoPaintColorkey; +} + + +/* + *----------------------------------------------------------------------------- + * + * vmw_video_buffer_alloc -- + * + * Allocates and map a kernel buffer to be used as data storage. + * + * Results: + * XvBadAlloc on failure, otherwise Success. + * + * Side effects: + * Calls into the kernel, sets members of out. + * + *----------------------------------------------------------------------------- + */ + +static int +vmw_video_buffer_alloc(struct vmw_customizer *vmw, int size, + struct vmw_video_buffer *out) +{ + out->buf = vmw_ioctl_buffer_create(vmw, size, &out->handle); + if (!out->buf) + return XvBadAlloc; + + out->data = vmw_ioctl_buffer_map(vmw, out->buf); + if (!out->data) { + vmw_ioctl_buffer_destroy(vmw, out->buf); + + out->handle = 0; + out->buf = NULL; + + return XvBadAlloc; + } + + out->size = size; + out->extra_data = xcalloc(1, size); + + debug_printf("\t\t%s: allocated buffer %p of size %i\n", __func__, out, size); + + return Success; +} + + +/* + *----------------------------------------------------------------------------- + * + * vmw_video_buffer_free -- + * + * Frees and unmaps an allocated kernel buffer. + * + * Results: + * Success. + * + * Side effects: + * Calls into the kernel, sets members of out to 0. + * + *----------------------------------------------------------------------------- + */ + +static int +vmw_video_buffer_free(struct vmw_customizer *vmw, + struct vmw_video_buffer *out) +{ + if (out->size == 0) + return Success; + + xfree(out->extra_data); + vmw_ioctl_buffer_unmap(vmw, out->buf); + vmw_ioctl_buffer_destroy(vmw, out->buf); + + out->buf = NULL; + out->data = NULL; + out->handle = 0; + out->size = 0; + + debug_printf("\t\t%s: freed buffer %p\n", __func__, out); + + return Success; +} + + +/* + *----------------------------------------------------------------------------- + * + * vmw_xv_put_image -- + * + * Main video playback function. It copies the passed data which is in + * the specified format (e.g. FOURCC_YV12) into the overlay. + * + * If sync is TRUE the driver should not return from this + * function until it is through reading the data from buf. + * + * Results: + * Success or XvBadAlloc on failure + * + * Side effects: + * Video port will be played(initialized if 1st frame) on success + * or will fail on error. + * + *----------------------------------------------------------------------------- + */ + +static int +vmw_xv_put_image(ScrnInfoPtr pScrn, short src_x, short src_y, + short drw_x, short drw_y, short src_w, short src_h, + short drw_w, short drw_h, int format, + unsigned char *buf, short width, short height, + Bool sync, RegionPtr clipBoxes, pointer data, + DrawablePtr dst) +{ + struct vmw_customizer *vmw = vmw_customizer(xorg_customizer(pScrn)); + struct vmw_video_port *port = data; + + debug_printf("%s: enter (%u, %u) (%ux%u) (%u, %u) (%ux%u) (%ux%u)\n", __func__, + src_x, src_y, src_w, src_h, + drw_x, drw_y, drw_w, drw_h, + width, height); + + if (!vmw->video_priv) + return XvBadAlloc; + + return port->play(pScrn, port, src_x, src_y, drw_x, drw_y, src_w, src_h, + drw_w, drw_h, format, buf, width, height, clipBoxes); +} + + +/* + *----------------------------------------------------------------------------- + * + * vmw_xv_stop_video -- + * + * Called when we should stop playing video for a particular stream. If + * Cleanup is FALSE, the "stop" operation is only temporary, and thus we + * don't do anything. If Cleanup is TRUE we kill the video port by + * sending a message to the host and freeing up the stream. + * + * Results: + * None. + * + * Side effects: + * See above. + * + *----------------------------------------------------------------------------- + */ + +static void +vmw_xv_stop_video(ScrnInfoPtr pScrn, pointer data, Bool cleanup) +{ + struct vmw_customizer *vmw = vmw_customizer(xorg_customizer(pScrn)); + struct vmw_video_port *port = data; + struct drm_vmw_control_stream_arg arg; + int ret; + + debug_printf("%s: cleanup is %s\n", __func__, cleanup ? "TRUE" : "FALSE"); + + if (!vmw->video_priv) + return; + + if (!cleanup) + return; + + + memset(&arg, 0, sizeof(arg)); + arg.stream_id = port->streamId; + arg.enabled = FALSE; + + ret = drmCommandWrite(vmw->fd, DRM_VMW_CONTROL_STREAM, &arg, sizeof(arg)); + assert(ret == 0); + + vmw_video_port_cleanup(pScrn, port); +} + + +/* + *----------------------------------------------------------------------------- + * + * vmw_xv_query_image_attributes -- + * + * From the spec: This function is called to let the driver specify how data + * for a particular image of size width by height should be stored. + * Sometimes only the size and corrected width and height are needed. In + * that case pitches and offsets are NULL. + * + * Results: + * The size of the memory required for the image, or -1 on error. + * + * Side effects: + * None. + * + *----------------------------------------------------------------------------- + */ + +static int +vmw_xv_query_image_attributes(ScrnInfoPtr pScrn, int format, + unsigned short *width, unsigned short *height, + int *pitches, int *offsets) +{ + INT32 size, tmp; + + if (*width > VMWARE_VID_MAX_WIDTH) { + *width = VMWARE_VID_MAX_WIDTH; + } + if (*height > VMWARE_VID_MAX_HEIGHT) { + *height = VMWARE_VID_MAX_HEIGHT; + } + + *width = (*width + 1) & ~1; + if (offsets != NULL) { + offsets[0] = 0; + } + + switch (format) { + case FOURCC_YV12: + *height = (*height + 1) & ~1; + size = (*width + 3) & ~3; + if (pitches) { + pitches[0] = size; + } + size *= *height; + if (offsets) { + offsets[1] = size; + } + tmp = ((*width >> 1) + 3) & ~3; + if (pitches) { + pitches[1] = pitches[2] = tmp; + } + tmp *= (*height >> 1); + size += tmp; + if (offsets) { + offsets[2] = size; + } + size += tmp; + break; + case FOURCC_UYVY: + case FOURCC_YUY2: + size = *width * 2; + if (pitches) { + pitches[0] = size; + } + size *= *height; + break; + default: + debug_printf("Query for invalid video format %d\n", format); + return -1; + } + return size; +} + + +/* + *----------------------------------------------------------------------------- + * + * vmw_xv_set_port_attribute -- + * + * From the spec: A port may have particular attributes such as colorKey, hue, + * saturation, brightness or contrast. Xv clients set these + * attribute values by sending attribute strings (Atoms) to the server. + * + * Results: + * Success if the attribute exists and XvBadAlloc otherwise. + * + * Side effects: + * The respective attribute gets the new value. + * + *----------------------------------------------------------------------------- + */ + +static int +vmw_xv_set_port_attribute(ScrnInfoPtr pScrn, Atom attribute, + INT32 value, pointer data) +{ + struct vmw_video_port *port = data; + Atom xvColorKey = MAKE_ATOM("XV_COLORKEY"); + Atom xvAutoPaint = MAKE_ATOM("XV_AUTOPAINT_COLORKEY"); + + if (attribute == xvColorKey) { + debug_printf("%s: Set colorkey:0x%x\n", __func__, (unsigned)value); + port->colorKey = value; + } else if (attribute == xvAutoPaint) { + debug_printf("%s: Set autoPaint: %s\n", __func__, value? "TRUE": "FALSE"); + port->isAutoPaintColorkey = value; + } else { + return XvBadAlloc; + } + + return Success; +} + + +/* + *----------------------------------------------------------------------------- + * + * vmw_xv_get_port_attribute -- + * + * From the spec: A port may have particular attributes such as hue, + * saturation, brightness or contrast. Xv clients get these + * attribute values by sending attribute strings (Atoms) to the server + * + * Results: + * Success if the attribute exists and XvBadAlloc otherwise. + * + * Side effects: + * "value" contains the requested attribute on success. + * + *----------------------------------------------------------------------------- + */ + +static int +vmw_xv_get_port_attribute(ScrnInfoPtr pScrn, Atom attribute, + INT32 *value, pointer data) +{ + struct vmw_video_port *port = data; + Atom xvColorKey = MAKE_ATOM("XV_COLORKEY"); + Atom xvAutoPaint = MAKE_ATOM("XV_AUTOPAINT_COLORKEY"); + + if (attribute == xvColorKey) { + *value = port->colorKey; + } else if (attribute == xvAutoPaint) { + *value = port->isAutoPaintColorkey; + } else { + return XvBadAlloc; + } + + return Success; +} + + +/* + *----------------------------------------------------------------------------- + * + * vmw_xv_query_best_size -- + * + * From the spec: QueryBestSize provides the client with a way to query what + * the destination dimensions would end up being if they were to request + * that an area vid_w by vid_h from the video stream be scaled to rectangle + * of drw_w by drw_h on the screen. Since it is not expected that all + * hardware will be able to get the target dimensions exactly, it is + * important that the driver provide this function. + * + * This function seems to never be called, but to be on the safe side + * we apply the same logic that QueryImageAttributes has for width + * and height. + * + * Results: + * None. + * + * Side effects: + * None. + * + *----------------------------------------------------------------------------- + */ + +static void +vmw_xv_query_best_size(ScrnInfoPtr pScrn, Bool motion, + short vid_w, short vid_h, short drw_w, + short drw_h, unsigned int *p_w, + unsigned int *p_h, pointer data) +{ + *p_w = (drw_w + 1) & ~1; + *p_h = drw_h; + + return; +} diff --git a/src/gallium/targets/xorg-vmwgfx/vmw_xorg.c b/src/gallium/targets/xorg-vmwgfx/vmw_xorg.c new file mode 100644 index 00000000000..87aad25b24f --- /dev/null +++ b/src/gallium/targets/xorg-vmwgfx/vmw_xorg.c @@ -0,0 +1,191 @@ +/********************************************************** + * Copyright 2008-2009 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + **********************************************************/ + +/** + * @file + * Glue file for Xorg State Tracker. + * + * @author Alan Hourihane + * @author Jakob Bornecrantz + */ + +#include "vmw_hook.h" + + +/* + * Defines and modinfo + */ + +#define VMWGFX_DRIVER_NAME "vmwgfx" + +#define VMW_STRING_INNER(s) #s +#define VMW_STRING(str) VMW_STRING_INNER(str) + +#define VMWGFX_VERSION_MAJOR 11 +#define VMWGFX_VERSION_MINOR 0 +#define VMWGFX_VERSION_PATCH 0 +#define VMWGFX_VERSION_STRING_MAJOR VMW_STRING(VMWGFX_VERSION_MAJOR) +#define VMWGFX_VERSION_STRING_MINOR VMW_STRING(VMWGFX_VERSION_MINOR) +#define VMWGFX_VERSION_STRING_PATCH VMW_STRING(VMWGFX_VERSION_PATCH) + +#define VMWGFX_DRIVER_VERSION \ + (VMWGFX_VERSION_MAJOR * 65536 + VMWGFX_VERSION_MINOR * 256 + VMWGFX_VERSION_PATCH) +#define VMWGFX_DRIVER_VERSION_STRING \ + VMWGFX_VERSION_STRING_MAJOR "." VMWGFX_VERSION_STRING_MINOR \ + "." VMWGFX_VERSION_STRING_PATCH + +/* + * Standard four digit version string expected by VMware Tools installer. + * As the driver's version is only {major, minor, patchlevel}, simply append an + * extra zero for the fourth digit. + */ +#ifdef __GNUC__ +_X_EXPORT const char vmwgfx_drv_modinfo[] __attribute__((section(".modinfo"),unused)) = + "version=" VMWGFX_DRIVER_VERSION_STRING ".0"; +#endif + +static void vmw_xorg_identify(int flags); +_X_EXPORT Bool vmw_xorg_pci_probe(DriverPtr driver, + int entity_num, + struct pci_device *device, + intptr_t match_data); + + +/* + * Tables + */ + +static const struct pci_id_match vmw_xorg_device_match[] = { + {0x15ad, PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0}, +}; + +static SymTabRec vmw_xorg_chipsets[] = { + {PCI_MATCH_ANY, "VMware SVGA Device"}, + {-1, NULL} +}; + +static PciChipsets vmw_xorg_pci_devices[] = { + {PCI_MATCH_ANY, PCI_MATCH_ANY, NULL}, + {-1, -1, NULL} +}; + +static XF86ModuleVersionInfo vmw_xorg_version = { + VMWGFX_DRIVER_NAME, + MODULEVENDORSTRING, + MODINFOSTRING1, + MODINFOSTRING2, + XORG_VERSION_CURRENT, + VMWGFX_VERSION_MAJOR, VMWGFX_VERSION_MINOR, VMWGFX_VERSION_PATCH, + ABI_CLASS_VIDEODRV, + ABI_VIDEODRV_VERSION, + MOD_CLASS_VIDEODRV, + {0, 0, 0, 0} +}; + +/* + * Xorg driver exported structures + */ + +_X_EXPORT DriverRec vmwgfx = { + 1, + VMWGFX_DRIVER_NAME, + vmw_xorg_identify, + NULL, + xorg_tracker_available_options, + NULL, + 0, + NULL, + vmw_xorg_device_match, + vmw_xorg_pci_probe +}; + +static MODULESETUPPROTO(vmw_xorg_setup); + +_X_EXPORT XF86ModuleData vmwgfxModuleData = { + &vmw_xorg_version, + vmw_xorg_setup, + NULL +}; + + +/* + * Xorg driver functions + */ + +static pointer +vmw_xorg_setup(pointer module, pointer opts, int *errmaj, int *errmin) +{ + static Bool setupDone = 0; + + /* This module should be loaded only once, but check to be sure. + */ + if (!setupDone) { + setupDone = 1; + xf86AddDriver(&vmwgfx, module, HaveDriverFuncs); + + /* + * The return value must be non-NULL on success even though there + * is no TearDownProc. + */ + return (pointer) 1; + } else { + if (errmaj) + *errmaj = LDR_ONCEONLY; + return NULL; + } +} + +static void +vmw_xorg_identify(int flags) +{ + xf86PrintChipsets("vmwgfx", "Driver for VMware SVGA device", + vmw_xorg_chipsets); +} + +_X_EXPORT Bool +vmw_xorg_pci_probe(DriverPtr driver, + int entity_num, struct pci_device *device, intptr_t match_data) +{ + ScrnInfoPtr scrn = NULL; + EntityInfoPtr entity; + + scrn = xf86ConfigPciEntity(scrn, 0, entity_num, vmw_xorg_pci_devices, + NULL, NULL, NULL, NULL, NULL); + if (scrn != NULL) { + scrn->driverVersion = 1; + scrn->driverName = "vmwgfx"; + scrn->name = "vmwgfx"; + scrn->Probe = NULL; + + entity = xf86GetEntityInfo(entity_num); + + /* Use all the functions from the xorg tracker */ + xorg_tracker_set_functions(scrn); + + vmw_screen_set_functions(scrn); + } + return scrn != NULL; +} diff --git a/src/gallium/winsys/drm/i965/xorg/Makefile b/src/gallium/winsys/drm/i965/xorg/Makefile deleted file mode 100644 index c25726b0bb1..00000000000 --- a/src/gallium/winsys/drm/i965/xorg/Makefile +++ /dev/null @@ -1,54 +0,0 @@ -TOP = ../../../../../.. - - -GALLIUMDIR = $(TOP)/src/gallium - -TARGET = i965g_drv.so - -CFILES = $(wildcard ./*.c) - -include ${TOP}/configs/current - -OBJECTS = $(patsubst ./%.c,./%.o,$(CFILES)) - -CFLAGS = -DHAVE_CONFIG_H \ - -g -Wall -Wimplicit-function-declaration -fPIC \ - $(shell pkg-config --cflags pixman-1 xorg-server libdrm xproto) \ - -I${GALLIUMDIR}/include \ - -I${GALLIUMDIR}/drivers \ - -I${GALLIUMDIR}/auxiliary \ - -I${TOP}/src/mesa \ - -I$(TOP)/include \ - -I$(TOP)/src/egl/main - -LIBS = \ - $(TOP)/src/gallium/state_trackers/xorg/libxorgtracker.a \ - $(TOP)/src/gallium/winsys/drm/i965/gem/libi965drm.a \ - $(TOP)/src/gallium/drivers/i965/libi965.a \ - $(TOP)/src/gallium/drivers/trace/libtrace.a \ - $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ - $(GALLIUM_AUXILIARIES) - -TARGET_STAGING = $(TOP)/$(LIB_DIR)/gallium/$(TARGET) -############################################# - -all default: $(TARGET) $(TARGET_STAGING) - -$(TARGET): $(OBJECTS) Makefile $(GALLIUMDIR)/state_trackers/xorg/libxorgtracker.a $(LIBS) - $(TOP)/bin/mklib -noprefix -o $@ \ - $(OBJECTS) $(LIBS) $(shell pkg-config --libs libdrm) -ldrm_intel - -$(TOP)/$(LIB_DIR)/gallium: - mkdir -p $@ - -$(TARGET_STAGING): $(TARGET) $(TOP)/$(LIB_DIR)/gallium - $(INSTALL) $(TARGET) $(TOP)/$(LIB_DIR)/gallium - -clean: - rm -rf $(OBJECTS) $(TARGET) - -install: - $(INSTALL) -d $(DESTDIR)/$(XORG_DRIVER_INSTALL_DIR) - $(MINSTALL) -m 755 $(TARGET) $(DESTDIR)/$(XORG_DRIVER_INSTALL_DIR) - -.PHONY = all clean install diff --git a/src/gallium/winsys/drm/i965/xorg/intel_xorg.c b/src/gallium/winsys/drm/i965/xorg/intel_xorg.c deleted file mode 100644 index ac691cb76b3..00000000000 --- a/src/gallium/winsys/drm/i965/xorg/intel_xorg.c +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * - * Author: Alan Hourihane - * Author: Jakob Bornecrantz - * - */ - -#include "../../../../state_trackers/xorg/xorg_winsys.h" - -static void intel_xorg_identify(int flags); -static Bool intel_xorg_pci_probe(DriverPtr driver, - int entity_num, - struct pci_device *device, - intptr_t match_data); - -static const struct pci_id_match intel_xorg_device_match[] = { - {0x8086, PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, 0, 0, 0}, - {0, 0, 0}, -}; - -static SymTabRec intel_xorg_chipsets[] = { - {PCI_MATCH_ANY, "Intel Graphics Device"}, - {-1, NULL} -}; - -static PciChipsets intel_xorg_pci_devices[] = { - {PCI_MATCH_ANY, PCI_MATCH_ANY, NULL}, - {-1, -1, NULL} -}; - -static XF86ModuleVersionInfo intel_xorg_version = { - "modesetting", - MODULEVENDORSTRING, - MODINFOSTRING1, - MODINFOSTRING2, - XORG_VERSION_CURRENT, - 0, 1, 0, /* major, minor, patch */ - ABI_CLASS_VIDEODRV, - ABI_VIDEODRV_VERSION, - MOD_CLASS_VIDEODRV, - {0, 0, 0, 0} -}; - -/* - * Xorg driver exported structures - */ - -_X_EXPORT DriverRec modesetting = { - 1, - "modesetting", - intel_xorg_identify, - NULL, - xorg_tracker_available_options, - NULL, - 0, - NULL, - intel_xorg_device_match, - intel_xorg_pci_probe -}; - -static MODULESETUPPROTO(intel_xorg_setup); - -_X_EXPORT XF86ModuleData modesettingModuleData = { - &intel_xorg_version, - intel_xorg_setup, - NULL -}; - -/* - * Xorg driver functions - */ - -static pointer -intel_xorg_setup(pointer module, pointer opts, int *errmaj, int *errmin) -{ - static Bool setupDone = 0; - - /* This module should be loaded only once, but check to be sure. - */ - if (!setupDone) { - setupDone = 1; - xf86AddDriver(&modesetting, module, HaveDriverFuncs); - - /* - * The return value must be non-NULL on success even though there - * is no TearDownProc. - */ - return (pointer) 1; - } else { - if (errmaj) - *errmaj = LDR_ONCEONLY; - return NULL; - } -} - -static void -intel_xorg_identify(int flags) -{ - xf86PrintChipsets("modesetting", "Driver for Modesetting Kernel Drivers", - intel_xorg_chipsets); -} - -static Bool -intel_xorg_pci_probe(DriverPtr driver, - int entity_num, struct pci_device *device, intptr_t match_data) -{ - ScrnInfoPtr scrn = NULL; - EntityInfoPtr entity; - - scrn = xf86ConfigPciEntity(scrn, 0, entity_num, intel_xorg_pci_devices, - NULL, NULL, NULL, NULL, NULL); - if (scrn != NULL) { - scrn->driverVersion = 1; - scrn->driverName = "i965"; - scrn->name = "modesetting"; - scrn->Probe = NULL; - - entity = xf86GetEntityInfo(entity_num); - - /* Use all the functions from the xorg tracker */ - xorg_tracker_set_functions(scrn); - } - return scrn != NULL; -} diff --git a/src/gallium/winsys/drm/intel/xorg/Makefile b/src/gallium/winsys/drm/intel/xorg/Makefile deleted file mode 100644 index 14c2462524b..00000000000 --- a/src/gallium/winsys/drm/intel/xorg/Makefile +++ /dev/null @@ -1,57 +0,0 @@ -TARGET = modesetting_drv.so -CFILES = $(wildcard ./*.c) -OBJECTS = $(patsubst ./%.c,./%.o,$(CFILES)) -TOP = ../../../../../.. - -include $(TOP)/configs/current - -INCLUDES = \ - $(shell pkg-config --cflags-only-I pixman-1 xorg-server libdrm xproto) \ - -I../gem \ - -I$(TOP)/src/gallium/include \ - -I$(TOP)/src/gallium/drivers \ - -I$(TOP)/src/gallium/auxiliary \ - -I$(TOP)/src/mesa \ - -I$(TOP)/include \ - -I$(TOP)/src/egl/main - -LIBS = \ - $(TOP)/src/gallium/state_trackers/xorg/libxorgtracker.a \ - $(TOP)/src/gallium/winsys/drm/intel/gem/libinteldrm.a \ - $(TOP)/src/gallium/drivers/i915/libi915.a \ - $(TOP)/src/gallium/drivers/trace/libtrace.a \ - $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ - $(GALLIUM_AUXILIARIES) - -DRIVER_DEFINES = \ - -DHAVE_CONFIG_H - - -############################################# - - - -all default: $(TARGET) - -$(TARGET): $(OBJECTS) Makefile $(TOP)/src/gallium/state_trackers/xorg/libxorgtracker.a $(LIBS) - $(TOP)/bin/mklib -noprefix -o $@ \ - $(OBJECTS) $(LIBS) $(shell pkg-config --libs libdrm) -ldrm_intel - -clean: - rm -rf $(OBJECTS) $(TARGET) - -install: - $(INSTALL) -d $(DESTDIR)/$(XORG_DRIVER_INSTALL_DIR) - $(MINSTALL) -m 755 $(TARGET) $(DESTDIR)/$(XORG_DRIVER_INSTALL_DIR) - - -############################################## - - -.c.o: - $(CC) -c $(CFLAGS) $(INCLUDES) $(DRIVER_DEFINES) $< -o $@ - - -############################################## - -.PHONY = all clean install diff --git a/src/gallium/winsys/drm/intel/xorg/intel_xorg.c b/src/gallium/winsys/drm/intel/xorg/intel_xorg.c deleted file mode 100644 index 369dc356cf8..00000000000 --- a/src/gallium/winsys/drm/intel/xorg/intel_xorg.c +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * - * Author: Alan Hourihane - * Author: Jakob Bornecrantz - * - */ - -#include "../../../../state_trackers/xorg/xorg_winsys.h" - -static void intel_xorg_identify(int flags); -static Bool intel_xorg_pci_probe(DriverPtr driver, - int entity_num, - struct pci_device *device, - intptr_t match_data); - -static const struct pci_id_match intel_xorg_device_match[] = { - {0x8086, PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, 0, 0, 0}, - {0, 0, 0}, -}; - -static SymTabRec intel_xorg_chipsets[] = { - {PCI_MATCH_ANY, "Intel Graphics Device"}, - {-1, NULL} -}; - -static PciChipsets intel_xorg_pci_devices[] = { - {PCI_MATCH_ANY, PCI_MATCH_ANY, NULL}, - {-1, -1, NULL} -}; - -static XF86ModuleVersionInfo intel_xorg_version = { - "modesetting", - MODULEVENDORSTRING, - MODINFOSTRING1, - MODINFOSTRING2, - XORG_VERSION_CURRENT, - 0, 1, 0, /* major, minor, patch */ - ABI_CLASS_VIDEODRV, - ABI_VIDEODRV_VERSION, - MOD_CLASS_VIDEODRV, - {0, 0, 0, 0} -}; - -/* - * Xorg driver exported structures - */ - -_X_EXPORT DriverRec modesetting = { - 1, - "modesetting", - intel_xorg_identify, - NULL, - xorg_tracker_available_options, - NULL, - 0, - NULL, - intel_xorg_device_match, - intel_xorg_pci_probe -}; - -static MODULESETUPPROTO(intel_xorg_setup); - -_X_EXPORT XF86ModuleData modesettingModuleData = { - &intel_xorg_version, - intel_xorg_setup, - NULL -}; - -/* - * Xorg driver functions - */ - -static pointer -intel_xorg_setup(pointer module, pointer opts, int *errmaj, int *errmin) -{ - static Bool setupDone = 0; - - /* This module should be loaded only once, but check to be sure. - */ - if (!setupDone) { - setupDone = 1; - xf86AddDriver(&modesetting, module, HaveDriverFuncs); - - /* - * The return value must be non-NULL on success even though there - * is no TearDownProc. - */ - return (pointer) 1; - } else { - if (errmaj) - *errmaj = LDR_ONCEONLY; - return NULL; - } -} - -static void -intel_xorg_identify(int flags) -{ - xf86PrintChipsets("modesetting", "Driver for Modesetting Kernel Drivers", - intel_xorg_chipsets); -} - -static Bool -intel_xorg_pci_probe(DriverPtr driver, - int entity_num, struct pci_device *device, intptr_t match_data) -{ - ScrnInfoPtr scrn = NULL; - EntityInfoPtr entity; - - scrn = xf86ConfigPciEntity(scrn, 0, entity_num, intel_xorg_pci_devices, - NULL, NULL, NULL, NULL, NULL); - if (scrn != NULL) { - scrn->driverVersion = 1; - scrn->driverName = "i915"; - scrn->name = "modesetting"; - scrn->Probe = NULL; - - entity = xf86GetEntityInfo(entity_num); - - /* Use all the functions from the xorg tracker */ - xorg_tracker_set_functions(scrn); - } - return scrn != NULL; -} diff --git a/src/gallium/winsys/drm/nouveau/xorg/Makefile b/src/gallium/winsys/drm/nouveau/xorg/Makefile deleted file mode 100644 index f7f6fe17dd6..00000000000 --- a/src/gallium/winsys/drm/nouveau/xorg/Makefile +++ /dev/null @@ -1,57 +0,0 @@ -TARGET = modesetting_drv.so -CFILES = $(wildcard ./*.c) -OBJECTS = $(patsubst ./%.c,./%.o,$(CFILES)) -TOP = ../../../../../.. - -include $(TOP)/configs/current - -INCLUDES = \ - $(shell pkg-config --cflags-only-I pixman-1 xorg-server libdrm xproto) \ - -I../gem \ - -I$(TOP)/src/gallium/include \ - -I$(TOP)/src/gallium/drivers \ - -I$(TOP)/src/gallium/auxiliary \ - -I$(TOP)/src/mesa \ - -I$(TOP)/include \ - -I$(TOP)/src/egl/main - -LIBS = \ - $(TOP)/src/gallium/state_trackers/xorg/libxorgtracker.a \ - $(TOP)/src/gallium/winsys/drm/nouveau/drm/libnouveaudrm.a \ - $(TOP)/src/gallium/drivers/nvfx/libnvfx.a \ - $(TOP)/src/gallium/drivers/nv50/libnv50.a \ - $(TOP)/src/gallium/drivers/nouveau/libnouveau.a \ - $(GALLIUM_AUXILIARIES) - -DRIVER_DEFINES = \ - -DHAVE_CONFIG_H - - -############################################# - - - -all default: $(TARGET) - -$(TARGET): $(OBJECTS) Makefile $(TOP)/src/gallium/state_trackers/xorg/libxorgtracker.a $(LIBS) - $(TOP)/bin/mklib -noprefix -o $@ \ - $(OBJECTS) $(LIBS) $(shell pkg-config --libs libdrm) -ldrm_nouveau - -clean: - rm -rf $(OBJECTS) $(TARGET) - -install: - $(INSTALL) -d $(DESTDIR)/$(XORG_DRIVER_INSTALL_DIR) - $(MINSTALL) -m 755 $(TARGET) $(DESTDIR)/$(XORG_DRIVER_INSTALL_DIR) - - -############################################## - - -.c.o: - $(CC) -c $(CFLAGS) $(INCLUDES) $(DRIVER_DEFINES) $< -o $@ - - -############################################## - -.PHONY = all clean install diff --git a/src/gallium/winsys/drm/nouveau/xorg/nouveau_xorg.c b/src/gallium/winsys/drm/nouveau/xorg/nouveau_xorg.c deleted file mode 100644 index a669b3080aa..00000000000 --- a/src/gallium/winsys/drm/nouveau/xorg/nouveau_xorg.c +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * - * Author: Alan Hourihane - * Author: Jakob Bornecrantz - * - */ - -#include "../../../../state_trackers/xorg/xorg_winsys.h" - -static void nouveau_xorg_identify(int flags); -static Bool nouveau_xorg_pci_probe(DriverPtr driver, int entity_num, - struct pci_device *device, - intptr_t match_data); - -static const struct pci_id_match nouveau_xorg_device_match[] = { - { 0x10de, PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, - 0x00030000, 0x00ffffff, 0 }, - { 0x12d2, PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, - 0x00030000, 0x00ffffff, 0 }, - {0, 0, 0}, -}; - -static SymTabRec nouveau_xorg_chipsets[] = { - {PCI_MATCH_ANY, "NVIDIA Graphics Device"}, - {-1, NULL} -}; - -static PciChipsets nouveau_xorg_pci_devices[] = { - {PCI_MATCH_ANY, PCI_MATCH_ANY, NULL}, - {-1, -1, NULL} -}; - -static XF86ModuleVersionInfo nouveau_xorg_version = { - "modesetting", - MODULEVENDORSTRING, - MODINFOSTRING1, - MODINFOSTRING2, - XORG_VERSION_CURRENT, - 0, 1, 0, /* major, minor, patch */ - ABI_CLASS_VIDEODRV, - ABI_VIDEODRV_VERSION, - MOD_CLASS_VIDEODRV, - {0, 0, 0, 0} -}; - -/* - * Xorg driver exported structures - */ - -_X_EXPORT DriverRec modesetting = { - 1, - "modesetting", - nouveau_xorg_identify, - NULL, - xorg_tracker_available_options, - NULL, - 0, - NULL, - nouveau_xorg_device_match, - nouveau_xorg_pci_probe -}; - -static MODULESETUPPROTO(nouveau_xorg_setup); - -_X_EXPORT XF86ModuleData modesettingModuleData = { - &nouveau_xorg_version, - nouveau_xorg_setup, - NULL -}; - -/* - * Xorg driver functions - */ - -static pointer -nouveau_xorg_setup(pointer module, pointer opts, int *errmaj, int *errmin) -{ - static Bool setupDone = 0; - - /* This module should be loaded only once, but check to be sure. - */ - if (!setupDone) { - setupDone = 1; - xf86AddDriver(&modesetting, module, HaveDriverFuncs); - - /* - * The return value must be non-NULL on success even though there - * is no TearDownProc. - */ - return (pointer) 1; - } else { - if (errmaj) - *errmaj = LDR_ONCEONLY; - return NULL; - } -} - -static void -nouveau_xorg_identify(int flags) -{ - xf86PrintChipsets("modesetting", "Driver for Modesetting Kernel Drivers", - nouveau_xorg_chipsets); -} - -static Bool -nouveau_xorg_pci_probe(DriverPtr driver, - int entity_num, struct pci_device *device, intptr_t match_data) -{ - ScrnInfoPtr scrn = NULL; - EntityInfoPtr entity; - - scrn = xf86ConfigPciEntity(scrn, 0, entity_num, nouveau_xorg_pci_devices, - NULL, NULL, NULL, NULL, NULL); - if (scrn != NULL) { - scrn->driverVersion = 1; - scrn->driverName = "i915"; - scrn->name = "modesetting"; - scrn->Probe = NULL; - - entity = xf86GetEntityInfo(entity_num); - - /* Use all the functions from the xorg tracker */ - xorg_tracker_set_functions(scrn); - } - return scrn != NULL; -} diff --git a/src/gallium/winsys/drm/radeon/xorg/Makefile b/src/gallium/winsys/drm/radeon/xorg/Makefile deleted file mode 100644 index 0eb1b3988f3..00000000000 --- a/src/gallium/winsys/drm/radeon/xorg/Makefile +++ /dev/null @@ -1,54 +0,0 @@ -TOP = ../../../../../.. - - -GALLIUMDIR = $(TOP)/src/gallium - -TARGET = radeong_drv.so - -CFILES = $(wildcard ./*.c) - -include ${TOP}/configs/current - -OBJECTS = $(patsubst ./%.c,./%.o,$(CFILES)) - -CFLAGS = -DHAVE_CONFIG_H \ - -g -Wall -Wimplicit-function-declaration -fPIC \ - $(shell pkg-config --cflags pixman-1 xorg-server libdrm xproto) \ - -I${GALLIUMDIR}/include \ - -I${GALLIUMDIR}/drivers \ - -I${GALLIUMDIR}/auxiliary \ - -I${TOP}/src/mesa \ - -I$(TOP)/include \ - -I$(TOP)/src/egl/main - -LIBS = \ - $(GALLIUMDIR)/state_trackers/xorg/libxorgtracker.a \ - $(GALLIUMDIR)/winsys/drm/radeon/core/libradeonwinsys.a \ - $(TOP)/src/gallium/drivers/r300/libr300.a \ - $(TOP)/src/gallium/drivers/trace/libtrace.a \ - $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ - $(GALLIUM_AUXILIARIES) - -TARGET_STAGING = $(TOP)/$(LIB_DIR)/gallium/$(TARGET) -############################################# - -all default: $(TARGET) $(TARGET_STAGING) - -$(TARGET): $(OBJECTS) Makefile $(GALLIUMDIR)/state_trackers/xorg/libxorgtracker.a $(LIBS) - $(TOP)/bin/mklib -noprefix -o $@ \ - $(OBJECTS) $(LIBS) $(shell pkg-config --libs libdrm) -ldrm_radeon - -$(TOP)/$(LIB_DIR)/gallium: - mkdir -p $@ - -$(TARGET_STAGING): $(TARGET) $(TOP)/$(LIB_DIR)/gallium - $(INSTALL) $(TARGET) $(TOP)/$(LIB_DIR)/gallium - -clean: - rm -rf $(OBJECTS) $(TARGET) - -install: - $(INSTALL) -d $(DESTDIR)/$(XORG_DRIVER_INSTALL_DIR) - $(MINSTALL) -m 755 $(TARGET) $(DESTDIR)/$(XORG_DRIVER_INSTALL_DIR) - -.PHONY = all clean install diff --git a/src/gallium/winsys/drm/radeon/xorg/radeon_xorg.c b/src/gallium/winsys/drm/radeon/xorg/radeon_xorg.c deleted file mode 100644 index bb76cc03499..00000000000 --- a/src/gallium/winsys/drm/radeon/xorg/radeon_xorg.c +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * - * Author: Alan Hourihane - * Author: Jakob Bornecrantz - * Author: Corbin Simpson - * - */ - -#include "../../../../state_trackers/xorg/xorg_winsys.h" - -static void radeon_xorg_identify(int flags); -static Bool radeon_xorg_pci_probe(DriverPtr driver, - int entity_num, - struct pci_device *device, - intptr_t match_data); - -static const struct pci_id_match radeon_xorg_device_match[] = { - {0x1002, PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, 0, 0, 0}, - {0, 0, 0}, -}; - -static SymTabRec radeon_xorg_chipsets[] = { - {PCI_MATCH_ANY, "ATI/AMD Radeon Graphics Chipset"}, - {-1, NULL} -}; - -static PciChipsets radeon_xorg_pci_devices[] = { - {PCI_MATCH_ANY, PCI_MATCH_ANY, NULL}, - {-1, -1, NULL} -}; - -static XF86ModuleVersionInfo radeon_xorg_version = { - "radeong", - MODULEVENDORSTRING, - MODINFOSTRING1, - MODINFOSTRING2, - XORG_VERSION_CURRENT, - 0, 1, 0, /* major, minor, patch */ - ABI_CLASS_VIDEODRV, - ABI_VIDEODRV_VERSION, - MOD_CLASS_VIDEODRV, - {0, 0, 0, 0} -}; - -/* - * Xorg driver exported structures - */ - -_X_EXPORT DriverRec radeong = { - 1, - "radeong", - radeon_xorg_identify, - NULL, - xorg_tracker_available_options, - NULL, - 0, - NULL, - radeon_xorg_device_match, - radeon_xorg_pci_probe -}; - -static MODULESETUPPROTO(radeon_xorg_setup); - -_X_EXPORT XF86ModuleData radeongModuleData = { - &radeon_xorg_version, - radeon_xorg_setup, - NULL -}; - -/* - * Xorg driver functions - */ - -static pointer -radeon_xorg_setup(pointer module, pointer opts, int *errmaj, int *errmin) -{ - static Bool setupDone = 0; - - /* This module should be loaded only once, but check to be sure. - */ - if (!setupDone) { - setupDone = 1; - xf86AddDriver(&radeong, module, HaveDriverFuncs); - - /* - * The return value must be non-NULL on success even though there - * is no TearDownProc. - */ - return (pointer) 1; - } else { - if (errmaj) - *errmaj = LDR_ONCEONLY; - return NULL; - } -} - -static void -radeon_xorg_identify(int flags) -{ - xf86PrintChipsets("radeong", "Driver for Radeon Gallium with KMS", - radeon_xorg_chipsets); -} - -static Bool -radeon_xorg_pci_probe(DriverPtr driver, - int entity_num, struct pci_device *device, intptr_t match_data) -{ - ScrnInfoPtr scrn = NULL; - EntityInfoPtr entity; - - scrn = xf86ConfigPciEntity(scrn, 0, entity_num, radeon_xorg_pci_devices, - NULL, NULL, NULL, NULL, NULL); - if (scrn != NULL) { - scrn->driverVersion = 1; - scrn->driverName = "radeong"; - scrn->name = "radeong"; - scrn->Probe = NULL; - - entity = xf86GetEntityInfo(entity_num); - - /* Use all the functions from the xorg tracker */ - xorg_tracker_set_functions(scrn); - } - return scrn != NULL; -} diff --git a/src/gallium/winsys/drm/vmware/SConscript b/src/gallium/winsys/drm/vmware/SConscript index e4da31a6933..eff87e7d010 100644 --- a/src/gallium/winsys/drm/vmware/SConscript +++ b/src/gallium/winsys/drm/vmware/SConscript @@ -1,7 +1,3 @@ Import('*') SConscript(['core/SConscript',]) - -if 'xorg' in env['statetrackers']: - - SConscript(['xorg/SConscript']) diff --git a/src/gallium/winsys/drm/vmware/xorg/Makefile b/src/gallium/winsys/drm/vmware/xorg/Makefile deleted file mode 100644 index 49e28ae17f5..00000000000 --- a/src/gallium/winsys/drm/vmware/xorg/Makefile +++ /dev/null @@ -1,71 +0,0 @@ -TOP = ../../../../../.. - -include $(TOP)/configs/current - -TARGET = vmwgfx_drv.so - -CFILES = \ - vmw_xorg.c \ - vmw_video.c \ - vmw_ioctl.c \ - vmw_screen.c - -OBJECTS = $(patsubst %.c,%.o,$(CFILES)) - -INCLUDES = \ - $(shell pkg-config --cflags-only-I pixman-1 xorg-server libdrm xproto) \ - -I$(TOP)/src/gallium/include \ - -I$(TOP)/src/gallium/drivers \ - -I$(TOP)/src/gallium/auxiliary \ - -I$(TOP)/src/gallium - -LIBS = \ - $(TOP)/src/gallium/state_trackers/xorg/libxorgtracker.a \ - $(TOP)/src/gallium/winsys/drm/vmware/core/libsvgadrm.a \ - $(TOP)/src/gallium/drivers/trace/libtrace.a \ - $(TOP)/src/gallium/drivers/svga/libsvga.a \ - $(GALLIUM_AUXILIARIES) - -LINKS = \ - $(shell pkg-config --libs --silence-errors libkms) \ - $(shell pkg-config --libs libdrm) - -DRIVER_DEFINES = \ - -std=gnu99 \ - -DHAVE_CONFIG_H - -TARGET_STAGING = $(TOP)/$(LIB_DIR)/gallium/$(TARGET) - -############################################# - - - -all default: $(TARGET) $(TARGET_STAGING) - -$(TARGET): $(OBJECTS) Makefile $(LIBS) - $(MKLIB) -noprefix -o $@ $(OBJECTS) $(LIBS) $(LINKS) - -$(TOP)/$(LIB_DIR)/gallium: - mkdir -p $@ - -$(TARGET_STAGING): $(TARGET) $(TOP)/$(LIB_DIR)/gallium - $(INSTALL) $(TARGET) $(TOP)/$(LIB_DIR)/gallium - -clean: - rm -rf $(OBJECTS) $(TARGET) - -install: - $(INSTALL) -d $(DESTDIR)/$(XORG_DRIVER_INSTALL_DIR) - $(MINSTALL) -m 755 $(TARGET) $(DESTDIR)/$(XORG_DRIVER_INSTALL_DIR) - - -############################################## - - -.c.o: - $(CC) -c $(CFLAGS) $(INCLUDES) $(DRIVER_DEFINES) $< -o $@ - - -############################################## - -.PHONY = all clean install diff --git a/src/gallium/winsys/drm/vmware/xorg/SConscript b/src/gallium/winsys/drm/vmware/xorg/SConscript deleted file mode 100644 index 1e5d8ff7fed..00000000000 --- a/src/gallium/winsys/drm/vmware/xorg/SConscript +++ /dev/null @@ -1,57 +0,0 @@ -import os.path - -Import('*') - -if env['platform'] == 'linux': - - env = env.Clone() - - env.ParseConfig('pkg-config --cflags --libs libdrm xorg-server') - - env.Prepend(CPPPATH = [ - '#/include', - '#/src/gallium', - '#/src/mesa', - '#/src/gallium/drivers/svga', - '#/src/gallium/drivers/svga/include', - ]) - - env.Append(CPPDEFINES = [ - ]) - - if env['gcc']: - env.Append(CPPDEFINES = [ - 'HAVE_STDINT_H', - 'HAVE_SYS_TYPES_H', - ]) - - env.Append(CFLAGS = [ - '-std=gnu99', - '-D_FILE_OFFSET_BITS=64', - ]) - - env.Prepend(LIBPATH = [ - ]) - - env.Prepend(LIBS = [ - trace, - st_xorg, - svgadrm, - svga, - gallium, - ]) - - sources = [ - 'vmw_ioctl.c', - 'vmw_screen.c', - 'vmw_video.c', - 'vmw_xorg.c', - ] - - # TODO: write a wrapper function http://www.scons.org/wiki/WrapperFunctions - env.LoadableModule( - target ='vmwgfx_drv.so', - source = sources, - LIBS = env['LIBS'], - SHLIBPREFIX = '', - ) diff --git a/src/gallium/winsys/drm/vmware/xorg/vmw_driver.h b/src/gallium/winsys/drm/vmware/xorg/vmw_driver.h deleted file mode 100644 index ba754b51e47..00000000000 --- a/src/gallium/winsys/drm/vmware/xorg/vmw_driver.h +++ /dev/null @@ -1,103 +0,0 @@ -/********************************************************** - * Copyright 2009 VMware, Inc. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - **********************************************************/ - -/** - * @file - * Contains the shared resources for VMware Xorg driver - * that sits ontop of the Xorg State Traker. - * - * It is initialized in vmw_screen.c. - * - * @author Jakob Bornecrantz - */ - -#ifndef VMW_DRIVER_H_ -#define VMW_DRIVER_H_ - -#include "state_trackers/xorg/xorg_tracker.h" - -struct vmw_dma_buffer; - -struct vmw_customizer -{ - CustomizerRec base; - ScrnInfoPtr pScrn; - - int fd; - - void *cursor_priv; - - /* vmw_video.c */ - void *video_priv; -}; - -static INLINE struct vmw_customizer * -vmw_customizer(CustomizerPtr cust) -{ - return cust ? (struct vmw_customizer *) cust : NULL; -} - - -/*********************************************************************** - * vmw_video.c - */ - -Bool vmw_video_init(struct vmw_customizer *vmw); - -Bool vmw_video_close(struct vmw_customizer *vmw); - -void vmw_video_stop_all(struct vmw_customizer *vmw); - - -/*********************************************************************** - * vmw_ioctl.c - */ - -int vmw_ioctl_cursor_bypass(struct vmw_customizer *vmw, int xhot, int yhot); - -struct vmw_dma_buffer * vmw_ioctl_buffer_create(struct vmw_customizer *vmw, - uint32_t size, - unsigned *handle); - -void * vmw_ioctl_buffer_map(struct vmw_customizer *vmw, - struct vmw_dma_buffer *buf); - -void vmw_ioctl_buffer_unmap(struct vmw_customizer *vmw, - struct vmw_dma_buffer *buf); - -void vmw_ioctl_buffer_destroy(struct vmw_customizer *vmw, - struct vmw_dma_buffer *buf); - -int vmw_ioctl_supports_streams(struct vmw_customizer *vmw); - -int vmw_ioctl_num_streams(struct vmw_customizer *vmw, - uint32_t *ntot, uint32_t *nfree); - -int vmw_ioctl_unref_stream(struct vmw_customizer *vmw, uint32_t stream_id); - -int vmw_ioctl_claim_stream(struct vmw_customizer *vmw, uint32_t *out); - - -#endif diff --git a/src/gallium/winsys/drm/vmware/xorg/vmw_hook.h b/src/gallium/winsys/drm/vmware/xorg/vmw_hook.h deleted file mode 100644 index 224a2d92996..00000000000 --- a/src/gallium/winsys/drm/vmware/xorg/vmw_hook.h +++ /dev/null @@ -1,39 +0,0 @@ -/********************************************************** - * Copyright 2009 VMware, Inc. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - **********************************************************/ - -#ifndef VMW_HOOK_H_ -#define VMW_HOOK_H_ - -#include "state_trackers/xorg/xorg_winsys.h" - - -/*********************************************************************** - * vmw_screen.c - */ - -void vmw_screen_set_functions(ScrnInfoPtr pScrn); - - -#endif diff --git a/src/gallium/winsys/drm/vmware/xorg/vmw_ioctl.c b/src/gallium/winsys/drm/vmware/xorg/vmw_ioctl.c deleted file mode 100644 index 521578ab35d..00000000000 --- a/src/gallium/winsys/drm/vmware/xorg/vmw_ioctl.c +++ /dev/null @@ -1,242 +0,0 @@ -/********************************************************** - * Copyright 2009 VMware, Inc. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - **********************************************************/ - -/** - * @file - * Contains the functions for creating dma buffers by calling - * the kernel via driver specific ioctls. - * - * @author Jakob Bornecrantz - */ - -#ifndef HAVE_STDINT_H -#define HAVE_STDINT_H 1 -#endif -#define _FILE_OFFSET_BITS 64 - -#include -#include -#include - -#include -#include "xf86drm.h" -#include "../core/vmwgfx_drm.h" - -#include "vmw_driver.h" -#include "util/u_debug.h" - -struct vmw_dma_buffer -{ - void *data; - unsigned handle; - uint64_t map_handle; - unsigned map_count; - uint32_t size; -}; - -static int -vmw_ioctl_get_param(struct vmw_customizer *vmw, uint32_t param, uint64_t *out) -{ - struct drm_vmw_getparam_arg gp_arg; - int ret; - - memset(&gp_arg, 0, sizeof(gp_arg)); - gp_arg.param = param; - ret = drmCommandWriteRead(vmw->fd, DRM_VMW_GET_PARAM, - &gp_arg, sizeof(gp_arg)); - - if (ret == 0) { - *out = gp_arg.value; - } - - return ret; -} - -int -vmw_ioctl_supports_streams(struct vmw_customizer *vmw) -{ - uint64_t value; - int ret; - - ret = vmw_ioctl_get_param(vmw, DRM_VMW_PARAM_NUM_STREAMS, &value); - if (ret) - return ret; - - return value ? 0 : -ENOSYS; -} - -int -vmw_ioctl_num_streams(struct vmw_customizer *vmw, - uint32_t *ntot, uint32_t *nfree) -{ - uint64_t v1, v2; - int ret; - - ret = vmw_ioctl_get_param(vmw, DRM_VMW_PARAM_NUM_STREAMS, &v1); - if (ret) - return ret; - - ret = vmw_ioctl_get_param(vmw, DRM_VMW_PARAM_NUM_FREE_STREAMS, &v2); - if (ret) - return ret; - - *ntot = (uint32_t)v1; - *nfree = (uint32_t)v2; - - return 0; -} - -int -vmw_ioctl_claim_stream(struct vmw_customizer *vmw, uint32_t *out) -{ - struct drm_vmw_stream_arg s_arg; - int ret; - - ret = drmCommandRead(vmw->fd, DRM_VMW_CLAIM_STREAM, - &s_arg, sizeof(s_arg)); - - if (ret) - return -1; - - *out = s_arg.stream_id; - return 0; -} - -int -vmw_ioctl_unref_stream(struct vmw_customizer *vmw, uint32_t stream_id) -{ - struct drm_vmw_stream_arg s_arg; - int ret; - - memset(&s_arg, 0, sizeof(s_arg)); - s_arg.stream_id = stream_id; - - ret = drmCommandRead(vmw->fd, DRM_VMW_CLAIM_STREAM, - &s_arg, sizeof(s_arg)); - - return 0; -} - -int -vmw_ioctl_cursor_bypass(struct vmw_customizer *vmw, int xhot, int yhot) -{ - struct drm_vmw_cursor_bypass_arg arg; - int ret; - - memset(&arg, 0, sizeof(arg)); - arg.flags = DRM_VMW_CURSOR_BYPASS_ALL; - arg.xhot = xhot; - arg.yhot = yhot; - - ret = drmCommandWrite(vmw->fd, DRM_VMW_CURSOR_BYPASS, - &arg, sizeof(arg)); - - return ret; -} - -struct vmw_dma_buffer * -vmw_ioctl_buffer_create(struct vmw_customizer *vmw, uint32_t size, unsigned *handle) -{ - struct vmw_dma_buffer *buf; - union drm_vmw_alloc_dmabuf_arg arg; - struct drm_vmw_alloc_dmabuf_req *req = &arg.req; - struct drm_vmw_dmabuf_rep *rep = &arg.rep; - int ret; - - buf = xcalloc(1, sizeof(*buf)); - if (!buf) - goto err; - - memset(&arg, 0, sizeof(arg)); - req->size = size; - do { - ret = drmCommandWriteRead(vmw->fd, DRM_VMW_ALLOC_DMABUF, &arg, sizeof(arg)); - } while (ret == -ERESTART); - - if (ret) { - debug_printf("IOCTL failed %d: %s\n", ret, strerror(-ret)); - goto err_free; - } - - - buf->data = NULL; - buf->handle = rep->handle; - buf->map_handle = rep->map_handle; - buf->map_count = 0; - buf->size = size; - - *handle = rep->handle; - - return buf; - -err_free: - xfree(buf); -err: - return NULL; -} - -void -vmw_ioctl_buffer_destroy(struct vmw_customizer *vmw, struct vmw_dma_buffer *buf) -{ - struct drm_vmw_unref_dmabuf_arg arg; - - if (buf->data) { - munmap(buf->data, buf->size); - buf->data = NULL; - } - - memset(&arg, 0, sizeof(arg)); - arg.handle = buf->handle; - drmCommandWrite(vmw->fd, DRM_VMW_UNREF_DMABUF, &arg, sizeof(arg)); - - xfree(buf); -} - -void * -vmw_ioctl_buffer_map(struct vmw_customizer *vmw, struct vmw_dma_buffer *buf) -{ - void *map; - - if (buf->data == NULL) { - map = mmap(NULL, buf->size, PROT_READ | PROT_WRITE, MAP_SHARED, - vmw->fd, buf->map_handle); - if (map == MAP_FAILED) { - debug_printf("%s: Map failed.\n", __FUNCTION__); - return NULL; - } - - buf->data = map; - } - - ++buf->map_count; - - return buf->data; -} - -void -vmw_ioctl_buffer_unmap(struct vmw_customizer *vmw, struct vmw_dma_buffer *buf) -{ - --buf->map_count; -} diff --git a/src/gallium/winsys/drm/vmware/xorg/vmw_screen.c b/src/gallium/winsys/drm/vmware/xorg/vmw_screen.c deleted file mode 100644 index f43f91e5c0d..00000000000 --- a/src/gallium/winsys/drm/vmware/xorg/vmw_screen.c +++ /dev/null @@ -1,178 +0,0 @@ -/********************************************************** - * Copyright 2009 VMware, Inc. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - **********************************************************/ - -/** - * @file - * Contains the init code for the VMware Xorg driver. - * - * @author Jakob Bornecrantz - */ - -#include "vmw_hook.h" -#include "vmw_driver.h" - -#include "cursorstr.h" - -/* modified version of crtc functions */ -xf86CrtcFuncsRec vmw_screen_crtc_funcs; - -static void -vmw_screen_cursor_load_argb(xf86CrtcPtr crtc, CARD32 *image) -{ - struct vmw_customizer *vmw = - vmw_customizer(xorg_customizer(crtc->scrn)); - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(crtc->scrn); - xf86CrtcFuncsPtr funcs = vmw->cursor_priv; - CursorPtr c = config->cursor; - - /* Run the ioctl before uploading the image */ - vmw_ioctl_cursor_bypass(vmw, c->bits->xhot, c->bits->yhot); - - funcs->load_cursor_argb(crtc, image); -} - -static void -vmw_screen_cursor_init(struct vmw_customizer *vmw) -{ - ScrnInfoPtr pScrn = vmw->pScrn; - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); - int i; - - /* XXX assume that all crtc's have the same function struct */ - - /* Save old struct need to call the old functions as well */ - vmw->cursor_priv = (void*)(config->crtc[0]->funcs); - memcpy(&vmw_screen_crtc_funcs, vmw->cursor_priv, sizeof(xf86CrtcFuncsRec)); - vmw_screen_crtc_funcs.load_cursor_argb = vmw_screen_cursor_load_argb; - - for (i = 0; i < config->num_crtc; i++) - config->crtc[i]->funcs = &vmw_screen_crtc_funcs; -} - -static void -vmw_screen_cursor_close(struct vmw_customizer *vmw) -{ - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(vmw->pScrn); - int i; - - vmw_ioctl_cursor_bypass(vmw, 0, 0); - - for (i = 0; i < config->num_crtc; i++) - config->crtc[i]->funcs = vmw->cursor_priv; -} - -static Bool -vmw_screen_init(CustomizerPtr cust, int fd) -{ - struct vmw_customizer *vmw = vmw_customizer(cust); - - vmw->fd = fd; - vmw_screen_cursor_init(vmw); - - /* if gallium is used then we don't need to do anything more. */ - if (xorg_has_gallium(vmw->pScrn)) - return TRUE; - - vmw_video_init(vmw); - - return TRUE; -} - -static Bool -vmw_screen_close(CustomizerPtr cust) -{ - struct vmw_customizer *vmw = vmw_customizer(cust); - - if (!vmw) - return TRUE; - - vmw_screen_cursor_close(vmw); - - vmw_video_close(vmw); - - return TRUE; -} - -static Bool -vmw_screen_enter_vt(CustomizerPtr cust) -{ - debug_printf("%s: enter\n", __func__); - - return TRUE; -} - -static Bool -vmw_screen_leave_vt(CustomizerPtr cust) -{ - struct vmw_customizer *vmw = vmw_customizer(cust); - - debug_printf("%s: enter\n", __func__); - - vmw_video_stop_all(vmw); - - return TRUE; -} - -/* - * Functions for setting up hooks into the xorg state tracker - */ - -static Bool (*vmw_screen_pre_init_saved)(ScrnInfoPtr pScrn, int flags) = NULL; - -static Bool -vmw_screen_pre_init(ScrnInfoPtr pScrn, int flags) -{ - struct vmw_customizer *vmw; - CustomizerPtr cust; - - vmw = xnfcalloc(1, sizeof(*vmw)); - if (!vmw) - return FALSE; - - cust = &vmw->base; - - cust->winsys_screen_init = vmw_screen_init; - cust->winsys_screen_close = vmw_screen_close; - cust->winsys_enter_vt = vmw_screen_enter_vt; - cust->winsys_leave_vt = vmw_screen_leave_vt; - vmw->pScrn = pScrn; - - pScrn->driverPrivate = cust; - - pScrn->PreInit = vmw_screen_pre_init_saved; - if (!pScrn->PreInit(pScrn, flags)) - return FALSE; - - return TRUE; -} - -void -vmw_screen_set_functions(ScrnInfoPtr pScrn) -{ - assert(!vmw_screen_pre_init_saved); - - vmw_screen_pre_init_saved = pScrn->PreInit; - pScrn->PreInit = vmw_screen_pre_init; -} diff --git a/src/gallium/winsys/drm/vmware/xorg/vmw_video.c b/src/gallium/winsys/drm/vmware/xorg/vmw_video.c deleted file mode 100644 index de28f06a475..00000000000 --- a/src/gallium/winsys/drm/vmware/xorg/vmw_video.c +++ /dev/null @@ -1,1072 +0,0 @@ -/* - * Copyright 2007 by VMware, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - * - * Except as contained in this notice, the name of the copyright holder(s) - * and author(s) shall not be used in advertising or otherwise to promote - * the sale, use or other dealings in this Software without prior written - * authorization from the copyright holder(s) and author(s). - */ - -/* - * vmwarevideo.c -- - * - * Xv extension support. - * See http://www.xfree86.org/current/DESIGN16.html - * - */ - - -#include "xf86xv.h" -#include "fourcc.h" - -#include "pipe/p_compiler.h" -/* - * We can't incude svga_types.h due to conflicting types for Bool. - */ -typedef int64_t int64; -typedef uint64_t uint64; - -typedef int32_t int32; -typedef uint32_t uint32; - -typedef int16_t int16; -typedef uint16_t uint16; - -typedef int8_t int8; -typedef uint8_t uint8; - -#include "svga/include/svga_reg.h" -#include "svga/include/svga_escape.h" -#include "svga/include/svga_overlay.h" - -#include "vmw_driver.h" - -#include - -#include "xf86drm.h" -#include "../core/vmwgfx_drm.h" - -#define MAKE_ATOM(a) MakeAtom(a, sizeof(a) - 1, TRUE) - -/* - * Number of videos that can be played simultaneously - */ -#define VMWARE_VID_NUM_PORTS 1 - -/* - * Using a dark shade as the default colorKey - */ -#define VMWARE_VIDEO_COLORKEY 0x100701 - -/* - * Maximum dimensions - */ -#define VMWARE_VID_MAX_WIDTH 2048 -#define VMWARE_VID_MAX_HEIGHT 2048 - -#define VMWARE_VID_NUM_ENCODINGS 1 -static XF86VideoEncodingRec vmwareVideoEncodings[] = -{ - { - 0, - "XV_IMAGE", - VMWARE_VID_MAX_WIDTH, VMWARE_VID_MAX_HEIGHT, - {1, 1} - } -}; - -#define VMWARE_VID_NUM_FORMATS 2 -static XF86VideoFormatRec vmwareVideoFormats[] = -{ - { 16, TrueColor}, - { 24, TrueColor} -}; - -#define VMWARE_VID_NUM_IMAGES 3 -static XF86ImageRec vmwareVideoImages[] = -{ - XVIMAGE_YV12, - XVIMAGE_YUY2, - XVIMAGE_UYVY -}; - -#define VMWARE_VID_NUM_ATTRIBUTES 2 -static XF86AttributeRec vmwareVideoAttributes[] = -{ - { - XvGettable | XvSettable, - 0x000000, - 0xffffff, - "XV_COLORKEY" - }, - { - XvGettable | XvSettable, - 0, - 1, - "XV_AUTOPAINT_COLORKEY" - } -}; - -/* - * Video frames are stored in a circular list of buffers. - * Must be power or two, See vmw_video_port_play. - */ -#define VMWARE_VID_NUM_BUFFERS 1 - -/* - * Defines the structure used to hold and pass video data to the host - */ -struct vmw_video_buffer -{ - unsigned handle; - int size; - void *data; - void *extra_data; - struct vmw_dma_buffer *buf; -}; - - -/** - * Structure representing a single video stream, aka port. - * - * Ports maps one to one to a SVGA stream. Port is just - * what Xv calls a SVGA stream. - */ -struct vmw_video_port -{ - /* - * Function prototype same as XvPutImage. - * - * This is either set to vmw_video_port_init or vmw_video_port_play. - * At init this function is set to port_init. In port_init we set it - * to port_play and call it, after initializing the struct. - */ - int (*play)(ScrnInfoPtr, struct vmw_video_port *, - short, short, short, short, short, - short, short, short, int, unsigned char*, - short, short, RegionPtr); - - /* values to go into the SVGAOverlayUnit */ - uint32 streamId; - uint32 colorKey; - uint32 flags; - - /* round robin of buffers */ - unsigned currBuf; - struct vmw_video_buffer bufs[VMWARE_VID_NUM_BUFFERS]; - - /* properties that applies to all buffers */ - int size; - int pitches[3]; - int offsets[3]; - - /* things for X */ - RegionRec clipBoxes; - Bool isAutoPaintColorkey; -}; - - -/** - * Structure holding all the infromation for video. - */ -struct vmw_video_private -{ - int fd; - - /** ports */ - struct vmw_video_port port[VMWARE_VID_NUM_PORTS]; - - /** Used to store port pointers pointers */ - DevUnion port_ptr[VMWARE_VID_NUM_PORTS]; -}; - - -/* - * Callback functions exported to Xv, prefixed with vmw_xv_*. - */ -static int vmw_xv_put_image(ScrnInfoPtr pScrn, short src_x, short src_y, - short drw_x, short drw_y, short src_w, short src_h, - short drw_w, short drw_h, int image, - unsigned char *buf, short width, short height, - Bool sync, RegionPtr clipBoxes, pointer data, - DrawablePtr dst); -static void vmw_xv_stop_video(ScrnInfoPtr pScrn, pointer data, Bool Cleanup); -static int vmw_xv_query_image_attributes(ScrnInfoPtr pScrn, int format, - unsigned short *width, - unsigned short *height, int *pitches, - int *offsets); -static int vmw_xv_set_port_attribute(ScrnInfoPtr pScrn, Atom attribute, - INT32 value, pointer data); -static int vmw_xv_get_port_attribute(ScrnInfoPtr pScrn, Atom attribute, - INT32 *value, pointer data); -static void vmw_xv_query_best_size(ScrnInfoPtr pScrn, Bool motion, - short vid_w, short vid_h, short drw_w, - short drw_h, unsigned int *p_w, - unsigned int *p_h, pointer data); - - -/* - * Local functions. - */ -static XF86VideoAdaptorPtr vmw_video_init_adaptor(ScrnInfoPtr pScrn, struct vmw_customizer *vmw); - -static int vmw_video_port_init(ScrnInfoPtr pScrn, - struct vmw_video_port *port, - short src_x, short src_y, short drw_x, - short drw_y, short src_w, short src_h, - short drw_w, short drw_h, int format, - unsigned char *buf, short width, - short height, RegionPtr clipBoxes); -static int vmw_video_port_play(ScrnInfoPtr pScrn, struct vmw_video_port *port, - short src_x, short src_y, short drw_x, - short drw_y, short src_w, short src_h, - short drw_w, short drw_h, int format, - unsigned char *buf, short width, - short height, RegionPtr clipBoxes); -static void vmw_video_port_cleanup(ScrnInfoPtr pScrn, struct vmw_video_port *port); - -static int vmw_video_buffer_alloc(struct vmw_customizer *vmw, int size, - struct vmw_video_buffer *out); -static int vmw_video_buffer_free(struct vmw_customizer *vmw, - struct vmw_video_buffer *out); - - -/* - *----------------------------------------------------------------------------- - * - * vmw_video_init -- - * - * Initializes Xv support. - * - * Results: - * TRUE on success, FALSE on error. - * - * Side effects: - * Xv support is initialized. Memory is allocated for all supported - * video streams. - * - *----------------------------------------------------------------------------- - */ - -Bool -vmw_video_init(struct vmw_customizer *vmw) -{ - ScrnInfoPtr pScrn = vmw->pScrn; - ScreenPtr pScreen = pScrn->pScreen; - XF86VideoAdaptorPtr *overlayAdaptors, *newAdaptors = NULL; - XF86VideoAdaptorPtr newAdaptor = NULL; - int numAdaptors; - unsigned int ntot, nfree; - - debug_printf("%s: enter\n", __func__); - - if (vmw_ioctl_num_streams(vmw, &ntot, &nfree) != 0) { - debug_printf("No stream ioctl support\n"); - return FALSE; - } - - if (nfree == 0) { - debug_printf("No free streams\n"); - return FALSE; - } - - numAdaptors = xf86XVListGenericAdaptors(pScrn, &overlayAdaptors); - - newAdaptor = vmw_video_init_adaptor(pScrn, vmw); - if (!newAdaptor) { - debug_printf("Failed to initialize Xv extension\n"); - return FALSE; - } - - if (!numAdaptors) { - numAdaptors = 1; - overlayAdaptors = &newAdaptor; - } else { - newAdaptors = xalloc((numAdaptors + 1) * - sizeof(XF86VideoAdaptorPtr*)); - if (!newAdaptors) { - xf86XVFreeVideoAdaptorRec(newAdaptor); - return FALSE; - } - - memcpy(newAdaptors, overlayAdaptors, - numAdaptors * sizeof(XF86VideoAdaptorPtr)); - newAdaptors[numAdaptors++] = newAdaptor; - overlayAdaptors = newAdaptors; - } - - if (!xf86XVScreenInit(pScreen, overlayAdaptors, numAdaptors)) { - debug_printf("Failed to initialize Xv extension\n"); - xf86XVFreeVideoAdaptorRec(newAdaptor); - return FALSE; - } - - if (newAdaptors) { - xfree(newAdaptors); - } - - debug_printf("Initialized VMware Xv extension successfully\n"); - - return TRUE; -} - - -/* - *----------------------------------------------------------------------------- - * - * vmw_video_close -- - * - * Unitializes video. - * - * Results: - * TRUE. - * - * Side effects: - * vmw->video_priv = NULL - * - *----------------------------------------------------------------------------- - */ - -Bool -vmw_video_close(struct vmw_customizer *vmw) -{ - ScrnInfoPtr pScrn = vmw->pScrn; - struct vmw_video_private *video; - int i; - - debug_printf("%s: enter\n", __func__); - - video = vmw->video_priv; - if (!video) - return TRUE; - - for (i = 0; i < VMWARE_VID_NUM_PORTS; ++i) { - /* make sure the port is stoped as well */ - vmw_xv_stop_video(pScrn, &video->port[i], TRUE); - vmw_ioctl_unref_stream(vmw, video->port[i].streamId); - } - - /* XXX: I'm sure this function is missing code for turning off Xv */ - - free(vmw->video_priv); - vmw->video_priv = NULL; - - return TRUE; -} - - -/* - *----------------------------------------------------------------------------- - * - * vmw_video_stop_all -- - * - * Stop all video streams from playing. - * - * Results: - * None. - * - * Side effects: - * All buffers are freed. - * - *----------------------------------------------------------------------------- - */ - -void vmw_video_stop_all(struct vmw_customizer *vmw) -{ - ScrnInfoPtr pScrn = vmw->pScrn; - struct vmw_video_private *video = vmw->video_priv; - int i; - - debug_printf("%s: enter\n", __func__); - - if (!video) - return; - - for (i = 0; i < VMWARE_VID_NUM_PORTS; ++i) { - vmw_xv_stop_video(pScrn, &video->port[i], TRUE); - } -} - - -/* - *----------------------------------------------------------------------------- - * - * vmw_video_init_adaptor -- - * - * Initializes a XF86VideoAdaptor structure with the capabilities and - * functions supported by this video driver. - * - * Results: - * On success initialized XF86VideoAdaptor struct or NULL on error - * - * Side effects: - * None. - * - *----------------------------------------------------------------------------- - */ - -static XF86VideoAdaptorPtr -vmw_video_init_adaptor(ScrnInfoPtr pScrn, struct vmw_customizer *vmw) -{ - XF86VideoAdaptorPtr adaptor; - struct vmw_video_private *video; - int i; - - debug_printf("%s: enter \n", __func__); - - adaptor = xf86XVAllocateVideoAdaptorRec(pScrn); - if (!adaptor) { - debug_printf("Not enough memory\n"); - return NULL; - } - - video = xcalloc(1, sizeof(*video)); - if (!video) { - debug_printf("Not enough memory.\n"); - xf86XVFreeVideoAdaptorRec(adaptor); - return NULL; - } - - vmw->video_priv = video; - - adaptor->type = XvInputMask | XvImageMask | XvWindowMask; - adaptor->flags = VIDEO_OVERLAID_IMAGES | VIDEO_CLIP_TO_VIEWPORT; - adaptor->name = "VMware Video Engine"; - adaptor->nEncodings = VMWARE_VID_NUM_ENCODINGS; - adaptor->pEncodings = vmwareVideoEncodings; - adaptor->nFormats = VMWARE_VID_NUM_FORMATS; - adaptor->pFormats = vmwareVideoFormats; - adaptor->nPorts = VMWARE_VID_NUM_PORTS; - adaptor->pPortPrivates = video->port_ptr; - - for (i = 0; i < VMWARE_VID_NUM_PORTS; ++i) { - vmw_ioctl_claim_stream(vmw, &video->port[i].streamId); - video->port[i].play = vmw_video_port_init; - video->port[i].flags = SVGA_VIDEO_FLAG_COLORKEY; - video->port[i].colorKey = VMWARE_VIDEO_COLORKEY; - video->port[i].isAutoPaintColorkey = TRUE; - adaptor->pPortPrivates[i].ptr = &video->port[i]; - } - - adaptor->nAttributes = VMWARE_VID_NUM_ATTRIBUTES; - adaptor->pAttributes = vmwareVideoAttributes; - - adaptor->nImages = VMWARE_VID_NUM_IMAGES; - adaptor->pImages = vmwareVideoImages; - - adaptor->PutVideo = NULL; - adaptor->PutStill = NULL; - adaptor->GetVideo = NULL; - adaptor->GetStill = NULL; - adaptor->StopVideo = vmw_xv_stop_video; - adaptor->SetPortAttribute = vmw_xv_set_port_attribute; - adaptor->GetPortAttribute = vmw_xv_get_port_attribute; - adaptor->QueryBestSize = vmw_xv_query_best_size; - adaptor->PutImage = vmw_xv_put_image; - adaptor->QueryImageAttributes = vmw_xv_query_image_attributes; - - debug_printf("%s: done %p\n", __func__, adaptor); - - return adaptor; -} - - -/* - *----------------------------------------------------------------------------- - * - * vmw_video_port_init -- - * - * Initializes a video stream in response to the first PutImage() on a - * video stream. The process goes as follows: - * - Figure out characteristics according to format - * - Allocate offscreen memory - * - Pass on video to Play() functions - * - * Results: - * Success or XvBadAlloc on failure. - * - * Side effects: - * Video stream is initialized and its first frame sent to the host - * (done by VideoPlay() function called at the end) - * - *----------------------------------------------------------------------------- - */ - -static int -vmw_video_port_init(ScrnInfoPtr pScrn, struct vmw_video_port *port, - short src_x, short src_y, short drw_x, - short drw_y, short src_w, short src_h, - short drw_w, short drw_h, int format, - unsigned char *buf, short width, - short height, RegionPtr clipBoxes) -{ - struct vmw_customizer *vmw = vmw_customizer(xorg_customizer(pScrn)); - unsigned short w, h; - int i, ret; - - debug_printf("\t%s: id %d, format %d\n", __func__, port->streamId, format); - - w = width; - h = height; - /* init all the format attributes, used for buffers */ - port->size = vmw_xv_query_image_attributes(pScrn, format, &w, &h, - port->pitches, port->offsets); - - if (port->size == -1) - return XvBadAlloc; - - port->play = vmw_video_port_play; - - for (i = 0; i < VMWARE_VID_NUM_BUFFERS; ++i) { - ret = vmw_video_buffer_alloc(vmw, port->size, &port->bufs[i]); - if (ret != Success) - break; - } - - /* Free all allocated buffers on failure */ - if (ret != Success) { - for (--i; i >= 0; --i) { - vmw_video_buffer_free(vmw, &port->bufs[i]); - } - return ret; - } - - port->currBuf = 0; - - REGION_COPY(pScrn->pScreen, &port->clipBoxes, clipBoxes); - - if (port->isAutoPaintColorkey) - xf86XVFillKeyHelper(pScrn->pScreen, port->colorKey, clipBoxes); - - return port->play(pScrn, port, src_x, src_y, drw_x, drw_y, src_w, src_h, - drw_w, drw_h, format, buf, width, height, clipBoxes); -} - - -/* - *----------------------------------------------------------------------------- - * - * vmw_video_port_play -- - * - * Sends all the attributes associated with the video frame using the - * FIFO ESCAPE mechanism to the host. - * - * Results: - * Always returns Success. - * - * Side effects: - * None. - * - *----------------------------------------------------------------------------- - */ - -static int -vmw_video_port_play(ScrnInfoPtr pScrn, struct vmw_video_port *port, - short src_x, short src_y, short drw_x, - short drw_y, short src_w, short src_h, - short drw_w, short drw_h, int format, - unsigned char *buf, short width, - short height, RegionPtr clipBoxes) -{ - struct vmw_customizer *vmw = vmw_customizer(xorg_customizer(pScrn)); - struct drm_vmw_control_stream_arg arg; - unsigned short w, h; - int size; - int ret; - - debug_printf("\t%s: enter\n", __func__); - - w = width; - h = height; - - /* we don't update the ports size */ - size = vmw_xv_query_image_attributes(pScrn, format, &w, &h, - port->pitches, port->offsets); - - if (size > port->size) { - debug_printf("\t%s: Increase in size of Xv video frame streamId:%d.\n", - __func__, port->streamId); - vmw_xv_stop_video(pScrn, port, TRUE); - return port->play(pScrn, port, src_x, src_y, drw_x, drw_y, src_w, - src_h, drw_w, drw_h, format, buf, width, height, - clipBoxes); - } - - memcpy(port->bufs[port->currBuf].data, buf, port->size); - - memset(&arg, 0, sizeof(arg)); - - arg.stream_id = port->streamId; - arg.enabled = TRUE; - arg.flags = port->flags; - arg.color_key = port->colorKey; - arg.handle = port->bufs[port->currBuf].handle; - arg.format = format; - arg.size = port->size; - arg.width = w; - arg.height = h; - arg.src.x = src_x; - arg.src.y = src_y; - arg.src.w = src_w; - arg.src.h = src_h; - arg.dst.x = drw_x; - arg.dst.y = drw_y; - arg.dst.w = drw_w; - arg.dst.h = drw_h; - arg.pitch[0] = port->pitches[0]; - arg.pitch[1] = port->pitches[1]; - arg.pitch[2] = port->pitches[2]; - arg.offset = 0; - - /* - * Update the clipList and paint the colorkey, if required. - */ - if (!REGION_EQUAL(pScrn->pScreen, &port->clipBoxes, clipBoxes)) { - REGION_COPY(pScrn->pScreen, &port->clipBoxes, clipBoxes); - if (port->isAutoPaintColorkey) { - xf86XVFillKeyHelper(pScrn->pScreen, port->colorKey, clipBoxes); - } - } - - ret = drmCommandWrite(vmw->fd, DRM_VMW_CONTROL_STREAM, &arg, sizeof(arg)); - if (ret) { - vmw_video_port_cleanup(pScrn, port); - return XvBadAlloc; - } - - if (++(port->currBuf) >= VMWARE_VID_NUM_BUFFERS) - port->currBuf = 0; - - return Success; -} - - -/* - *----------------------------------------------------------------------------- - * - * vmw_video_port_cleanup -- - * - * Frees up all resources (if any) taken by a video stream. - * - * Results: - * None. - * - * Side effects: - * Same as above. - * - *----------------------------------------------------------------------------- - */ - -static void -vmw_video_port_cleanup(ScrnInfoPtr pScrn, struct vmw_video_port *port) -{ - struct vmw_customizer *vmw = vmw_customizer(xorg_customizer(pScrn)); - uint32 id, colorKey, flags; - Bool isAutoPaintColorkey; - int i; - - debug_printf("\t%s: enter\n", __func__); - - for (i = 0; i < VMWARE_VID_NUM_BUFFERS; i++) { - vmw_video_buffer_free(vmw, &port->bufs[i]); - } - - /* - * reset stream for next video - */ - id = port->streamId; - colorKey = port->colorKey; - flags = port->flags; - isAutoPaintColorkey = port->isAutoPaintColorkey; - - memset(port, 0, sizeof(*port)); - - port->streamId = id; - port->play = vmw_video_port_init; - port->colorKey = colorKey; - port->flags = flags; - port->isAutoPaintColorkey = isAutoPaintColorkey; -} - - -/* - *----------------------------------------------------------------------------- - * - * vmw_video_buffer_alloc -- - * - * Allocates and map a kernel buffer to be used as data storage. - * - * Results: - * XvBadAlloc on failure, otherwise Success. - * - * Side effects: - * Calls into the kernel, sets members of out. - * - *----------------------------------------------------------------------------- - */ - -static int -vmw_video_buffer_alloc(struct vmw_customizer *vmw, int size, - struct vmw_video_buffer *out) -{ - out->buf = vmw_ioctl_buffer_create(vmw, size, &out->handle); - if (!out->buf) - return XvBadAlloc; - - out->data = vmw_ioctl_buffer_map(vmw, out->buf); - if (!out->data) { - vmw_ioctl_buffer_destroy(vmw, out->buf); - - out->handle = 0; - out->buf = NULL; - - return XvBadAlloc; - } - - out->size = size; - out->extra_data = xcalloc(1, size); - - debug_printf("\t\t%s: allocated buffer %p of size %i\n", __func__, out, size); - - return Success; -} - - -/* - *----------------------------------------------------------------------------- - * - * vmw_video_buffer_free -- - * - * Frees and unmaps an allocated kernel buffer. - * - * Results: - * Success. - * - * Side effects: - * Calls into the kernel, sets members of out to 0. - * - *----------------------------------------------------------------------------- - */ - -static int -vmw_video_buffer_free(struct vmw_customizer *vmw, - struct vmw_video_buffer *out) -{ - if (out->size == 0) - return Success; - - xfree(out->extra_data); - vmw_ioctl_buffer_unmap(vmw, out->buf); - vmw_ioctl_buffer_destroy(vmw, out->buf); - - out->buf = NULL; - out->data = NULL; - out->handle = 0; - out->size = 0; - - debug_printf("\t\t%s: freed buffer %p\n", __func__, out); - - return Success; -} - - -/* - *----------------------------------------------------------------------------- - * - * vmw_xv_put_image -- - * - * Main video playback function. It copies the passed data which is in - * the specified format (e.g. FOURCC_YV12) into the overlay. - * - * If sync is TRUE the driver should not return from this - * function until it is through reading the data from buf. - * - * Results: - * Success or XvBadAlloc on failure - * - * Side effects: - * Video port will be played(initialized if 1st frame) on success - * or will fail on error. - * - *----------------------------------------------------------------------------- - */ - -static int -vmw_xv_put_image(ScrnInfoPtr pScrn, short src_x, short src_y, - short drw_x, short drw_y, short src_w, short src_h, - short drw_w, short drw_h, int format, - unsigned char *buf, short width, short height, - Bool sync, RegionPtr clipBoxes, pointer data, - DrawablePtr dst) -{ - struct vmw_customizer *vmw = vmw_customizer(xorg_customizer(pScrn)); - struct vmw_video_port *port = data; - - debug_printf("%s: enter (%u, %u) (%ux%u) (%u, %u) (%ux%u) (%ux%u)\n", __func__, - src_x, src_y, src_w, src_h, - drw_x, drw_y, drw_w, drw_h, - width, height); - - if (!vmw->video_priv) - return XvBadAlloc; - - return port->play(pScrn, port, src_x, src_y, drw_x, drw_y, src_w, src_h, - drw_w, drw_h, format, buf, width, height, clipBoxes); -} - - -/* - *----------------------------------------------------------------------------- - * - * vmw_xv_stop_video -- - * - * Called when we should stop playing video for a particular stream. If - * Cleanup is FALSE, the "stop" operation is only temporary, and thus we - * don't do anything. If Cleanup is TRUE we kill the video port by - * sending a message to the host and freeing up the stream. - * - * Results: - * None. - * - * Side effects: - * See above. - * - *----------------------------------------------------------------------------- - */ - -static void -vmw_xv_stop_video(ScrnInfoPtr pScrn, pointer data, Bool cleanup) -{ - struct vmw_customizer *vmw = vmw_customizer(xorg_customizer(pScrn)); - struct vmw_video_port *port = data; - struct drm_vmw_control_stream_arg arg; - int ret; - - debug_printf("%s: cleanup is %s\n", __func__, cleanup ? "TRUE" : "FALSE"); - - if (!vmw->video_priv) - return; - - if (!cleanup) - return; - - - memset(&arg, 0, sizeof(arg)); - arg.stream_id = port->streamId; - arg.enabled = FALSE; - - ret = drmCommandWrite(vmw->fd, DRM_VMW_CONTROL_STREAM, &arg, sizeof(arg)); - assert(ret == 0); - - vmw_video_port_cleanup(pScrn, port); -} - - -/* - *----------------------------------------------------------------------------- - * - * vmw_xv_query_image_attributes -- - * - * From the spec: This function is called to let the driver specify how data - * for a particular image of size width by height should be stored. - * Sometimes only the size and corrected width and height are needed. In - * that case pitches and offsets are NULL. - * - * Results: - * The size of the memory required for the image, or -1 on error. - * - * Side effects: - * None. - * - *----------------------------------------------------------------------------- - */ - -static int -vmw_xv_query_image_attributes(ScrnInfoPtr pScrn, int format, - unsigned short *width, unsigned short *height, - int *pitches, int *offsets) -{ - INT32 size, tmp; - - if (*width > VMWARE_VID_MAX_WIDTH) { - *width = VMWARE_VID_MAX_WIDTH; - } - if (*height > VMWARE_VID_MAX_HEIGHT) { - *height = VMWARE_VID_MAX_HEIGHT; - } - - *width = (*width + 1) & ~1; - if (offsets != NULL) { - offsets[0] = 0; - } - - switch (format) { - case FOURCC_YV12: - *height = (*height + 1) & ~1; - size = (*width + 3) & ~3; - if (pitches) { - pitches[0] = size; - } - size *= *height; - if (offsets) { - offsets[1] = size; - } - tmp = ((*width >> 1) + 3) & ~3; - if (pitches) { - pitches[1] = pitches[2] = tmp; - } - tmp *= (*height >> 1); - size += tmp; - if (offsets) { - offsets[2] = size; - } - size += tmp; - break; - case FOURCC_UYVY: - case FOURCC_YUY2: - size = *width * 2; - if (pitches) { - pitches[0] = size; - } - size *= *height; - break; - default: - debug_printf("Query for invalid video format %d\n", format); - return -1; - } - return size; -} - - -/* - *----------------------------------------------------------------------------- - * - * vmw_xv_set_port_attribute -- - * - * From the spec: A port may have particular attributes such as colorKey, hue, - * saturation, brightness or contrast. Xv clients set these - * attribute values by sending attribute strings (Atoms) to the server. - * - * Results: - * Success if the attribute exists and XvBadAlloc otherwise. - * - * Side effects: - * The respective attribute gets the new value. - * - *----------------------------------------------------------------------------- - */ - -static int -vmw_xv_set_port_attribute(ScrnInfoPtr pScrn, Atom attribute, - INT32 value, pointer data) -{ - struct vmw_video_port *port = data; - Atom xvColorKey = MAKE_ATOM("XV_COLORKEY"); - Atom xvAutoPaint = MAKE_ATOM("XV_AUTOPAINT_COLORKEY"); - - if (attribute == xvColorKey) { - debug_printf("%s: Set colorkey:0x%x\n", __func__, (unsigned)value); - port->colorKey = value; - } else if (attribute == xvAutoPaint) { - debug_printf("%s: Set autoPaint: %s\n", __func__, value? "TRUE": "FALSE"); - port->isAutoPaintColorkey = value; - } else { - return XvBadAlloc; - } - - return Success; -} - - -/* - *----------------------------------------------------------------------------- - * - * vmw_xv_get_port_attribute -- - * - * From the spec: A port may have particular attributes such as hue, - * saturation, brightness or contrast. Xv clients get these - * attribute values by sending attribute strings (Atoms) to the server - * - * Results: - * Success if the attribute exists and XvBadAlloc otherwise. - * - * Side effects: - * "value" contains the requested attribute on success. - * - *----------------------------------------------------------------------------- - */ - -static int -vmw_xv_get_port_attribute(ScrnInfoPtr pScrn, Atom attribute, - INT32 *value, pointer data) -{ - struct vmw_video_port *port = data; - Atom xvColorKey = MAKE_ATOM("XV_COLORKEY"); - Atom xvAutoPaint = MAKE_ATOM("XV_AUTOPAINT_COLORKEY"); - - if (attribute == xvColorKey) { - *value = port->colorKey; - } else if (attribute == xvAutoPaint) { - *value = port->isAutoPaintColorkey; - } else { - return XvBadAlloc; - } - - return Success; -} - - -/* - *----------------------------------------------------------------------------- - * - * vmw_xv_query_best_size -- - * - * From the spec: QueryBestSize provides the client with a way to query what - * the destination dimensions would end up being if they were to request - * that an area vid_w by vid_h from the video stream be scaled to rectangle - * of drw_w by drw_h on the screen. Since it is not expected that all - * hardware will be able to get the target dimensions exactly, it is - * important that the driver provide this function. - * - * This function seems to never be called, but to be on the safe side - * we apply the same logic that QueryImageAttributes has for width - * and height. - * - * Results: - * None. - * - * Side effects: - * None. - * - *----------------------------------------------------------------------------- - */ - -static void -vmw_xv_query_best_size(ScrnInfoPtr pScrn, Bool motion, - short vid_w, short vid_h, short drw_w, - short drw_h, unsigned int *p_w, - unsigned int *p_h, pointer data) -{ - *p_w = (drw_w + 1) & ~1; - *p_h = drw_h; - - return; -} diff --git a/src/gallium/winsys/drm/vmware/xorg/vmw_xorg.c b/src/gallium/winsys/drm/vmware/xorg/vmw_xorg.c deleted file mode 100644 index 87aad25b24f..00000000000 --- a/src/gallium/winsys/drm/vmware/xorg/vmw_xorg.c +++ /dev/null @@ -1,191 +0,0 @@ -/********************************************************** - * Copyright 2008-2009 VMware, Inc. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - **********************************************************/ - -/** - * @file - * Glue file for Xorg State Tracker. - * - * @author Alan Hourihane - * @author Jakob Bornecrantz - */ - -#include "vmw_hook.h" - - -/* - * Defines and modinfo - */ - -#define VMWGFX_DRIVER_NAME "vmwgfx" - -#define VMW_STRING_INNER(s) #s -#define VMW_STRING(str) VMW_STRING_INNER(str) - -#define VMWGFX_VERSION_MAJOR 11 -#define VMWGFX_VERSION_MINOR 0 -#define VMWGFX_VERSION_PATCH 0 -#define VMWGFX_VERSION_STRING_MAJOR VMW_STRING(VMWGFX_VERSION_MAJOR) -#define VMWGFX_VERSION_STRING_MINOR VMW_STRING(VMWGFX_VERSION_MINOR) -#define VMWGFX_VERSION_STRING_PATCH VMW_STRING(VMWGFX_VERSION_PATCH) - -#define VMWGFX_DRIVER_VERSION \ - (VMWGFX_VERSION_MAJOR * 65536 + VMWGFX_VERSION_MINOR * 256 + VMWGFX_VERSION_PATCH) -#define VMWGFX_DRIVER_VERSION_STRING \ - VMWGFX_VERSION_STRING_MAJOR "." VMWGFX_VERSION_STRING_MINOR \ - "." VMWGFX_VERSION_STRING_PATCH - -/* - * Standard four digit version string expected by VMware Tools installer. - * As the driver's version is only {major, minor, patchlevel}, simply append an - * extra zero for the fourth digit. - */ -#ifdef __GNUC__ -_X_EXPORT const char vmwgfx_drv_modinfo[] __attribute__((section(".modinfo"),unused)) = - "version=" VMWGFX_DRIVER_VERSION_STRING ".0"; -#endif - -static void vmw_xorg_identify(int flags); -_X_EXPORT Bool vmw_xorg_pci_probe(DriverPtr driver, - int entity_num, - struct pci_device *device, - intptr_t match_data); - - -/* - * Tables - */ - -static const struct pci_id_match vmw_xorg_device_match[] = { - {0x15ad, PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, 0, 0, 0}, - {0, 0, 0, 0, 0, 0, 0}, -}; - -static SymTabRec vmw_xorg_chipsets[] = { - {PCI_MATCH_ANY, "VMware SVGA Device"}, - {-1, NULL} -}; - -static PciChipsets vmw_xorg_pci_devices[] = { - {PCI_MATCH_ANY, PCI_MATCH_ANY, NULL}, - {-1, -1, NULL} -}; - -static XF86ModuleVersionInfo vmw_xorg_version = { - VMWGFX_DRIVER_NAME, - MODULEVENDORSTRING, - MODINFOSTRING1, - MODINFOSTRING2, - XORG_VERSION_CURRENT, - VMWGFX_VERSION_MAJOR, VMWGFX_VERSION_MINOR, VMWGFX_VERSION_PATCH, - ABI_CLASS_VIDEODRV, - ABI_VIDEODRV_VERSION, - MOD_CLASS_VIDEODRV, - {0, 0, 0, 0} -}; - -/* - * Xorg driver exported structures - */ - -_X_EXPORT DriverRec vmwgfx = { - 1, - VMWGFX_DRIVER_NAME, - vmw_xorg_identify, - NULL, - xorg_tracker_available_options, - NULL, - 0, - NULL, - vmw_xorg_device_match, - vmw_xorg_pci_probe -}; - -static MODULESETUPPROTO(vmw_xorg_setup); - -_X_EXPORT XF86ModuleData vmwgfxModuleData = { - &vmw_xorg_version, - vmw_xorg_setup, - NULL -}; - - -/* - * Xorg driver functions - */ - -static pointer -vmw_xorg_setup(pointer module, pointer opts, int *errmaj, int *errmin) -{ - static Bool setupDone = 0; - - /* This module should be loaded only once, but check to be sure. - */ - if (!setupDone) { - setupDone = 1; - xf86AddDriver(&vmwgfx, module, HaveDriverFuncs); - - /* - * The return value must be non-NULL on success even though there - * is no TearDownProc. - */ - return (pointer) 1; - } else { - if (errmaj) - *errmaj = LDR_ONCEONLY; - return NULL; - } -} - -static void -vmw_xorg_identify(int flags) -{ - xf86PrintChipsets("vmwgfx", "Driver for VMware SVGA device", - vmw_xorg_chipsets); -} - -_X_EXPORT Bool -vmw_xorg_pci_probe(DriverPtr driver, - int entity_num, struct pci_device *device, intptr_t match_data) -{ - ScrnInfoPtr scrn = NULL; - EntityInfoPtr entity; - - scrn = xf86ConfigPciEntity(scrn, 0, entity_num, vmw_xorg_pci_devices, - NULL, NULL, NULL, NULL, NULL); - if (scrn != NULL) { - scrn->driverVersion = 1; - scrn->driverName = "vmwgfx"; - scrn->name = "vmwgfx"; - scrn->Probe = NULL; - - entity = xf86GetEntityInfo(entity_num); - - /* Use all the functions from the xorg tracker */ - xorg_tracker_set_functions(scrn); - - vmw_screen_set_functions(scrn); - } - return scrn != NULL; -} -- cgit v1.2.3 From c9f98673c5b6830cd1f41c0c53a9e5e299d47464 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Tue, 16 Mar 2010 13:54:18 +0000 Subject: gallium: Reorg winsys directories Attached output from commit. delete mode 100644 src/gallium/winsys/drm/SConscript delete mode 100644 src/gallium/winsys/drm/i965/SConscript delete mode 100644 src/gallium/winsys/drm/intel/Makefile delete mode 100644 src/gallium/winsys/drm/intel/SConscript delete mode 100644 src/gallium/winsys/drm/nouveau/Makefile delete mode 100644 src/gallium/winsys/drm/radeon/Makefile delete mode 100644 src/gallium/winsys/drm/radeon/SConscript delete mode 100644 src/gallium/winsys/drm/vmware/Makefile delete mode 100644 src/gallium/winsys/drm/vmware/SConscript rename src/gallium/winsys/{drm/intel/gem => i915/drm}/Makefile (82%) rename src/gallium/winsys/{drm/intel/gem => i915/drm}/SConscript (100%) rename src/gallium/winsys/{drm/intel/gem => i915/drm}/intel_drm_api.c (100%) rename src/gallium/winsys/{drm/intel/gem => i915/drm}/intel_drm_batchbuffer.c (100%) rename src/gallium/winsys/{drm/intel/gem => i915/drm}/intel_drm_buffer.c (100%) rename src/gallium/winsys/{drm/intel/gem => i915/drm}/intel_drm_fence.c (100%) rename src/gallium/winsys/{drm/intel/gem => i915/drm}/intel_drm_winsys.h (100%) rename src/gallium/winsys/{drm/i965/gem => i965/drm}/Makefile (78%) rename src/gallium/winsys/{drm/i965/gem => i965/drm}/SConscript (100%) rename src/gallium/winsys/{drm/i965/gem => i965/drm}/i965_drm_api.c (98%) rename src/gallium/winsys/{drm/i965/gem => i965/drm}/i965_drm_buffer.c (100%) rename src/gallium/winsys/{drm/i965/gem => i965/drm}/i965_drm_winsys.h (100%) rename src/gallium/winsys/{drm => }/i965/xlib/Makefile (97%) rename src/gallium/winsys/{drm => }/i965/xlib/xlib_i965.c (100%) rename src/gallium/winsys/{drm => }/nouveau/drm/Makefile (79%) rename src/gallium/winsys/{drm => }/nouveau/drm/nouveau_dri.h (100%) rename src/gallium/winsys/{drm => }/nouveau/drm/nouveau_drm_api.c (100%) rename src/gallium/winsys/{drm => }/nouveau/drm/nouveau_drm_api.h (100%) rename src/gallium/winsys/{drm/radeon/core => radeon/drm}/Makefile (79%) rename src/gallium/winsys/{drm/radeon/core => radeon/drm}/SConscript (100%) rename src/gallium/winsys/{drm/radeon/core => radeon/drm}/radeon_buffer.h (100%) rename src/gallium/winsys/{drm/radeon/core => radeon/drm}/radeon_drm.c (100%) rename src/gallium/winsys/{drm/radeon/core => radeon/drm}/radeon_drm.h (100%) rename src/gallium/winsys/{drm/radeon/core => radeon/drm}/radeon_drm_buffer.c (100%) rename src/gallium/winsys/{drm/radeon/core => radeon/drm}/radeon_r300.c (100%) rename src/gallium/winsys/{drm/radeon/core => radeon/drm}/radeon_r300.h (100%) rename src/gallium/winsys/{drm/radeon/core => radeon/drm}/radeon_winsys.h (100%) rename src/gallium/winsys/{drm/vmware/core => svga/drm}/Makefile (63%) rename src/gallium/winsys/{drm/vmware/core => svga/drm}/SConscript (100%) rename src/gallium/winsys/{drm/vmware/core => svga/drm}/vmw_buffer.c (100%) rename src/gallium/winsys/{drm/vmware/core => svga/drm}/vmw_buffer.h (100%) rename src/gallium/winsys/{drm/vmware/core => svga/drm}/vmw_context.c (100%) rename src/gallium/winsys/{drm/vmware/core => svga/drm}/vmw_context.h (100%) rename src/gallium/winsys/{drm/vmware/core => svga/drm}/vmw_fence.c (100%) rename src/gallium/winsys/{drm/vmware/core => svga/drm}/vmw_fence.h (100%) rename src/gallium/winsys/{drm/vmware/core => svga/drm}/vmw_screen.c (100%) rename src/gallium/winsys/{drm/vmware/core => svga/drm}/vmw_screen.h (100%) rename src/gallium/winsys/{drm/vmware/core => svga/drm}/vmw_screen_dri.c (100%) rename src/gallium/winsys/{drm/vmware/core => svga/drm}/vmw_screen_ioctl.c (100%) rename src/gallium/winsys/{drm/vmware/core => svga/drm}/vmw_screen_pools.c (100%) rename src/gallium/winsys/{drm/vmware/core => svga/drm}/vmw_screen_svga.c (100%) rename src/gallium/winsys/{drm/vmware/core => svga/drm}/vmw_surface.c (100%) rename src/gallium/winsys/{drm/vmware/core => svga/drm}/vmw_surface.h (100%) rename src/gallium/winsys/{drm/vmware/core => svga/drm}/vmwgfx_drm.h (100%) rename src/gallium/winsys/{drm/i965 => sw}/Makefile (61%) copy src/gallium/winsys/{drm/sw => sw/drm}/Makefile (73%) rename src/gallium/winsys/{drm/sw => sw/drm}/sw_drm_api.c (98%) rename src/gallium/winsys/{drm/sw => sw/drm}/sw_drm_api.h (100%) rename src/gallium/winsys/{ => sw}/gdi/SConscript (100%) rename src/gallium/winsys/{ => sw}/gdi/gdi_sw_winsys.c (100%) rename src/gallium/winsys/{ => sw}/gdi/gdi_sw_winsys.h (100%) rename src/gallium/winsys/{ => sw}/null/Makefile (78%) rename src/gallium/winsys/{ => sw}/null/SConscript (100%) rename src/gallium/winsys/{ => sw}/null/null_sw_winsys.c (100%) rename src/gallium/winsys/{ => sw}/null/null_sw_winsys.h (100%) rename src/gallium/winsys/{drm/sw => sw/wrapper}/Makefile (65%) rename src/gallium/winsys/{drm/sw => sw/wrapper}/wrapper_sw_winsys.c (100%) rename src/gallium/winsys/{drm/sw => sw/wrapper}/wrapper_sw_winsys.h (100%) rename src/gallium/winsys/{ => sw}/xlib/Makefile (79%) rename src/gallium/winsys/{ => sw}/xlib/SConscript (100%) rename src/gallium/winsys/{ => sw}/xlib/xlib_sw_winsys.c (100%) --- configs/default | 2 +- configs/linux-dri | 2 +- configure.ac | 14 +- src/gallium/SConscript | 2 +- src/gallium/targets/Makefile.egl | 2 +- src/gallium/targets/dri-i915/Makefile | 2 +- src/gallium/targets/dri-i965/Makefile | 5 +- src/gallium/targets/dri-nouveau/Makefile | 2 +- src/gallium/targets/dri-radeong/Makefile | 2 +- src/gallium/targets/dri-vmwgfx/Makefile | 2 +- src/gallium/targets/egl-i915/Makefile | 2 +- src/gallium/targets/egl-i965/Makefile | 2 +- src/gallium/targets/egl-nouveau/Makefile | 2 +- src/gallium/targets/egl-radeon/Makefile | 2 +- src/gallium/targets/egl-vmwgfx/Makefile | 2 +- src/gallium/targets/xorg-i915/Makefile | 2 +- src/gallium/targets/xorg-i965/Makefile | 2 +- src/gallium/targets/xorg-nouveau/Makefile | 2 +- src/gallium/targets/xorg-radeon/Makefile | 2 +- src/gallium/targets/xorg-vmwgfx/Makefile | 2 +- src/gallium/targets/xorg-vmwgfx/vmw_ioctl.c | 2 +- src/gallium/targets/xorg-vmwgfx/vmw_video.c | 2 +- src/gallium/winsys/SConscript | 9 +- src/gallium/winsys/drm/SConscript | 69 --- src/gallium/winsys/drm/i965/Makefile | 12 - src/gallium/winsys/drm/i965/SConscript | 3 - src/gallium/winsys/drm/i965/gem/Makefile | 14 - src/gallium/winsys/drm/i965/gem/SConscript | 15 - src/gallium/winsys/drm/i965/gem/i965_drm_api.c | 122 ----- src/gallium/winsys/drm/i965/gem/i965_drm_buffer.c | 503 ------------------- src/gallium/winsys/drm/i965/gem/i965_drm_winsys.h | 64 --- src/gallium/winsys/drm/i965/xlib/Makefile | 97 ---- src/gallium/winsys/drm/i965/xlib/xlib_i965.c | 503 ------------------- src/gallium/winsys/drm/intel/Makefile | 12 - src/gallium/winsys/drm/intel/SConscript | 3 - src/gallium/winsys/drm/intel/gem/Makefile | 16 - src/gallium/winsys/drm/intel/gem/SConscript | 17 - src/gallium/winsys/drm/intel/gem/intel_drm_api.c | 109 ----- .../winsys/drm/intel/gem/intel_drm_batchbuffer.c | 244 --------- .../winsys/drm/intel/gem/intel_drm_buffer.c | 217 -------- src/gallium/winsys/drm/intel/gem/intel_drm_fence.c | 83 ---- .../winsys/drm/intel/gem/intel_drm_winsys.h | 77 --- src/gallium/winsys/drm/nouveau/Makefile | 12 - src/gallium/winsys/drm/nouveau/drm/Makefile | 11 - src/gallium/winsys/drm/nouveau/drm/nouveau_dri.h | 28 -- .../winsys/drm/nouveau/drm/nouveau_drm_api.c | 157 ------ .../winsys/drm/nouveau/drm/nouveau_drm_api.h | 31 -- src/gallium/winsys/drm/radeon/Makefile | 12 - src/gallium/winsys/drm/radeon/SConscript | 3 - src/gallium/winsys/drm/radeon/core/Makefile | 17 - src/gallium/winsys/drm/radeon/core/SConscript | 18 - src/gallium/winsys/drm/radeon/core/radeon_buffer.h | 86 ---- src/gallium/winsys/drm/radeon/core/radeon_drm.c | 200 -------- src/gallium/winsys/drm/radeon/core/radeon_drm.h | 66 --- .../winsys/drm/radeon/core/radeon_drm_buffer.c | 385 --------------- src/gallium/winsys/drm/radeon/core/radeon_r300.c | 348 ------------- src/gallium/winsys/drm/radeon/core/radeon_r300.h | 30 -- src/gallium/winsys/drm/radeon/core/radeon_winsys.h | 86 ---- src/gallium/winsys/drm/sw/Makefile | 14 - src/gallium/winsys/drm/sw/sw_drm_api.c | 97 ---- src/gallium/winsys/drm/sw/sw_drm_api.h | 34 -- src/gallium/winsys/drm/sw/wrapper_sw_winsys.c | 282 ----------- src/gallium/winsys/drm/sw/wrapper_sw_winsys.h | 35 -- src/gallium/winsys/drm/vmware/Makefile | 12 - src/gallium/winsys/drm/vmware/SConscript | 3 - src/gallium/winsys/drm/vmware/core/Makefile | 35 -- src/gallium/winsys/drm/vmware/core/SConscript | 39 -- src/gallium/winsys/drm/vmware/core/vmw_buffer.c | 274 ----------- src/gallium/winsys/drm/vmware/core/vmw_buffer.h | 65 --- src/gallium/winsys/drm/vmware/core/vmw_context.c | 382 --------------- src/gallium/winsys/drm/vmware/core/vmw_context.h | 56 --- src/gallium/winsys/drm/vmware/core/vmw_fence.c | 108 ---- src/gallium/winsys/drm/vmware/core/vmw_fence.h | 59 --- src/gallium/winsys/drm/vmware/core/vmw_screen.c | 77 --- src/gallium/winsys/drm/vmware/core/vmw_screen.h | 140 ------ .../winsys/drm/vmware/core/vmw_screen_dri.c | 373 -------------- .../winsys/drm/vmware/core/vmw_screen_ioctl.c | 529 -------------------- .../winsys/drm/vmware/core/vmw_screen_pools.c | 97 ---- .../winsys/drm/vmware/core/vmw_screen_svga.c | 295 ----------- src/gallium/winsys/drm/vmware/core/vmw_surface.c | 61 --- src/gallium/winsys/drm/vmware/core/vmw_surface.h | 79 --- src/gallium/winsys/drm/vmware/core/vmwgfx_drm.h | 545 --------------------- src/gallium/winsys/gdi/SConscript | 23 - src/gallium/winsys/gdi/gdi_sw_winsys.c | 247 ---------- src/gallium/winsys/gdi/gdi_sw_winsys.h | 16 - src/gallium/winsys/i915/drm/Makefile | 16 + src/gallium/winsys/i915/drm/SConscript | 17 + src/gallium/winsys/i915/drm/intel_drm_api.c | 109 +++++ .../winsys/i915/drm/intel_drm_batchbuffer.c | 244 +++++++++ src/gallium/winsys/i915/drm/intel_drm_buffer.c | 217 ++++++++ src/gallium/winsys/i915/drm/intel_drm_fence.c | 83 ++++ src/gallium/winsys/i915/drm/intel_drm_winsys.h | 77 +++ src/gallium/winsys/i965/drm/Makefile | 14 + src/gallium/winsys/i965/drm/SConscript | 15 + src/gallium/winsys/i965/drm/i965_drm_api.c | 122 +++++ src/gallium/winsys/i965/drm/i965_drm_buffer.c | 503 +++++++++++++++++++ src/gallium/winsys/i965/drm/i965_drm_winsys.h | 64 +++ src/gallium/winsys/i965/xlib/Makefile | 97 ++++ src/gallium/winsys/i965/xlib/xlib_i965.c | 503 +++++++++++++++++++ src/gallium/winsys/nouveau/drm/Makefile | 11 + src/gallium/winsys/nouveau/drm/nouveau_dri.h | 28 ++ src/gallium/winsys/nouveau/drm/nouveau_drm_api.c | 157 ++++++ src/gallium/winsys/nouveau/drm/nouveau_drm_api.h | 31 ++ src/gallium/winsys/null/Makefile | 16 - src/gallium/winsys/null/SConscript | 21 - src/gallium/winsys/null/null_sw_winsys.c | 148 ------ src/gallium/winsys/null/null_sw_winsys.h | 40 -- src/gallium/winsys/radeon/drm/Makefile | 17 + src/gallium/winsys/radeon/drm/SConscript | 18 + src/gallium/winsys/radeon/drm/radeon_buffer.h | 86 ++++ src/gallium/winsys/radeon/drm/radeon_drm.c | 200 ++++++++ src/gallium/winsys/radeon/drm/radeon_drm.h | 66 +++ src/gallium/winsys/radeon/drm/radeon_drm_buffer.c | 385 +++++++++++++++ src/gallium/winsys/radeon/drm/radeon_r300.c | 348 +++++++++++++ src/gallium/winsys/radeon/drm/radeon_r300.h | 30 ++ src/gallium/winsys/radeon/drm/radeon_winsys.h | 86 ++++ src/gallium/winsys/svga/drm/Makefile | 27 + src/gallium/winsys/svga/drm/SConscript | 39 ++ src/gallium/winsys/svga/drm/vmw_buffer.c | 274 +++++++++++ src/gallium/winsys/svga/drm/vmw_buffer.h | 65 +++ src/gallium/winsys/svga/drm/vmw_context.c | 382 +++++++++++++++ src/gallium/winsys/svga/drm/vmw_context.h | 56 +++ src/gallium/winsys/svga/drm/vmw_fence.c | 108 ++++ src/gallium/winsys/svga/drm/vmw_fence.h | 59 +++ src/gallium/winsys/svga/drm/vmw_screen.c | 77 +++ src/gallium/winsys/svga/drm/vmw_screen.h | 140 ++++++ src/gallium/winsys/svga/drm/vmw_screen_dri.c | 373 ++++++++++++++ src/gallium/winsys/svga/drm/vmw_screen_ioctl.c | 529 ++++++++++++++++++++ src/gallium/winsys/svga/drm/vmw_screen_pools.c | 97 ++++ src/gallium/winsys/svga/drm/vmw_screen_svga.c | 295 +++++++++++ src/gallium/winsys/svga/drm/vmw_surface.c | 61 +++ src/gallium/winsys/svga/drm/vmw_surface.h | 79 +++ src/gallium/winsys/svga/drm/vmwgfx_drm.h | 545 +++++++++++++++++++++ src/gallium/winsys/sw/Makefile | 12 + src/gallium/winsys/sw/drm/Makefile | 12 + src/gallium/winsys/sw/drm/sw_drm_api.c | 97 ++++ src/gallium/winsys/sw/drm/sw_drm_api.h | 34 ++ src/gallium/winsys/sw/gdi/SConscript | 23 + src/gallium/winsys/sw/gdi/gdi_sw_winsys.c | 247 ++++++++++ src/gallium/winsys/sw/gdi/gdi_sw_winsys.h | 16 + src/gallium/winsys/sw/null/Makefile | 16 + src/gallium/winsys/sw/null/SConscript | 21 + src/gallium/winsys/sw/null/null_sw_winsys.c | 148 ++++++ src/gallium/winsys/sw/null/null_sw_winsys.h | 40 ++ src/gallium/winsys/sw/wrapper/Makefile | 12 + src/gallium/winsys/sw/wrapper/wrapper_sw_winsys.c | 282 +++++++++++ src/gallium/winsys/sw/wrapper/wrapper_sw_winsys.h | 35 ++ src/gallium/winsys/sw/xlib/Makefile | 17 + src/gallium/winsys/sw/xlib/SConscript | 23 + src/gallium/winsys/sw/xlib/xlib_sw_winsys.c | 464 ++++++++++++++++++ src/gallium/winsys/xlib/Makefile | 17 - src/gallium/winsys/xlib/SConscript | 23 - src/gallium/winsys/xlib/xlib_sw_winsys.c | 464 ------------------ 153 files changed, 8281 insertions(+), 8412 deletions(-) delete mode 100644 src/gallium/winsys/drm/SConscript delete mode 100644 src/gallium/winsys/drm/i965/Makefile delete mode 100644 src/gallium/winsys/drm/i965/SConscript delete mode 100644 src/gallium/winsys/drm/i965/gem/Makefile delete mode 100644 src/gallium/winsys/drm/i965/gem/SConscript delete mode 100644 src/gallium/winsys/drm/i965/gem/i965_drm_api.c delete mode 100644 src/gallium/winsys/drm/i965/gem/i965_drm_buffer.c delete mode 100644 src/gallium/winsys/drm/i965/gem/i965_drm_winsys.h delete mode 100644 src/gallium/winsys/drm/i965/xlib/Makefile delete mode 100644 src/gallium/winsys/drm/i965/xlib/xlib_i965.c delete mode 100644 src/gallium/winsys/drm/intel/Makefile delete mode 100644 src/gallium/winsys/drm/intel/SConscript delete mode 100644 src/gallium/winsys/drm/intel/gem/Makefile delete mode 100644 src/gallium/winsys/drm/intel/gem/SConscript delete mode 100644 src/gallium/winsys/drm/intel/gem/intel_drm_api.c delete mode 100644 src/gallium/winsys/drm/intel/gem/intel_drm_batchbuffer.c delete mode 100644 src/gallium/winsys/drm/intel/gem/intel_drm_buffer.c delete mode 100644 src/gallium/winsys/drm/intel/gem/intel_drm_fence.c delete mode 100644 src/gallium/winsys/drm/intel/gem/intel_drm_winsys.h delete mode 100644 src/gallium/winsys/drm/nouveau/Makefile delete mode 100644 src/gallium/winsys/drm/nouveau/drm/Makefile delete mode 100644 src/gallium/winsys/drm/nouveau/drm/nouveau_dri.h delete mode 100644 src/gallium/winsys/drm/nouveau/drm/nouveau_drm_api.c delete mode 100644 src/gallium/winsys/drm/nouveau/drm/nouveau_drm_api.h delete mode 100644 src/gallium/winsys/drm/radeon/Makefile delete mode 100644 src/gallium/winsys/drm/radeon/SConscript delete mode 100644 src/gallium/winsys/drm/radeon/core/Makefile delete mode 100644 src/gallium/winsys/drm/radeon/core/SConscript delete mode 100644 src/gallium/winsys/drm/radeon/core/radeon_buffer.h delete mode 100644 src/gallium/winsys/drm/radeon/core/radeon_drm.c delete mode 100644 src/gallium/winsys/drm/radeon/core/radeon_drm.h delete mode 100644 src/gallium/winsys/drm/radeon/core/radeon_drm_buffer.c delete mode 100644 src/gallium/winsys/drm/radeon/core/radeon_r300.c delete mode 100644 src/gallium/winsys/drm/radeon/core/radeon_r300.h delete mode 100644 src/gallium/winsys/drm/radeon/core/radeon_winsys.h delete mode 100644 src/gallium/winsys/drm/sw/Makefile delete mode 100644 src/gallium/winsys/drm/sw/sw_drm_api.c delete mode 100644 src/gallium/winsys/drm/sw/sw_drm_api.h delete mode 100644 src/gallium/winsys/drm/sw/wrapper_sw_winsys.c delete mode 100644 src/gallium/winsys/drm/sw/wrapper_sw_winsys.h delete mode 100644 src/gallium/winsys/drm/vmware/Makefile delete mode 100644 src/gallium/winsys/drm/vmware/SConscript delete mode 100644 src/gallium/winsys/drm/vmware/core/Makefile delete mode 100644 src/gallium/winsys/drm/vmware/core/SConscript delete mode 100644 src/gallium/winsys/drm/vmware/core/vmw_buffer.c delete mode 100644 src/gallium/winsys/drm/vmware/core/vmw_buffer.h delete mode 100644 src/gallium/winsys/drm/vmware/core/vmw_context.c delete mode 100644 src/gallium/winsys/drm/vmware/core/vmw_context.h delete mode 100644 src/gallium/winsys/drm/vmware/core/vmw_fence.c delete mode 100644 src/gallium/winsys/drm/vmware/core/vmw_fence.h delete mode 100644 src/gallium/winsys/drm/vmware/core/vmw_screen.c delete mode 100644 src/gallium/winsys/drm/vmware/core/vmw_screen.h delete mode 100644 src/gallium/winsys/drm/vmware/core/vmw_screen_dri.c delete mode 100644 src/gallium/winsys/drm/vmware/core/vmw_screen_ioctl.c delete mode 100644 src/gallium/winsys/drm/vmware/core/vmw_screen_pools.c delete mode 100644 src/gallium/winsys/drm/vmware/core/vmw_screen_svga.c delete mode 100644 src/gallium/winsys/drm/vmware/core/vmw_surface.c delete mode 100644 src/gallium/winsys/drm/vmware/core/vmw_surface.h delete mode 100644 src/gallium/winsys/drm/vmware/core/vmwgfx_drm.h delete mode 100644 src/gallium/winsys/gdi/SConscript delete mode 100644 src/gallium/winsys/gdi/gdi_sw_winsys.c delete mode 100644 src/gallium/winsys/gdi/gdi_sw_winsys.h create mode 100644 src/gallium/winsys/i915/drm/Makefile create mode 100644 src/gallium/winsys/i915/drm/SConscript create mode 100644 src/gallium/winsys/i915/drm/intel_drm_api.c create mode 100644 src/gallium/winsys/i915/drm/intel_drm_batchbuffer.c create mode 100644 src/gallium/winsys/i915/drm/intel_drm_buffer.c create mode 100644 src/gallium/winsys/i915/drm/intel_drm_fence.c create mode 100644 src/gallium/winsys/i915/drm/intel_drm_winsys.h create mode 100644 src/gallium/winsys/i965/drm/Makefile create mode 100644 src/gallium/winsys/i965/drm/SConscript create mode 100644 src/gallium/winsys/i965/drm/i965_drm_api.c create mode 100644 src/gallium/winsys/i965/drm/i965_drm_buffer.c create mode 100644 src/gallium/winsys/i965/drm/i965_drm_winsys.h create mode 100644 src/gallium/winsys/i965/xlib/Makefile create mode 100644 src/gallium/winsys/i965/xlib/xlib_i965.c create mode 100644 src/gallium/winsys/nouveau/drm/Makefile create mode 100644 src/gallium/winsys/nouveau/drm/nouveau_dri.h create mode 100644 src/gallium/winsys/nouveau/drm/nouveau_drm_api.c create mode 100644 src/gallium/winsys/nouveau/drm/nouveau_drm_api.h delete mode 100644 src/gallium/winsys/null/Makefile delete mode 100644 src/gallium/winsys/null/SConscript delete mode 100644 src/gallium/winsys/null/null_sw_winsys.c delete mode 100644 src/gallium/winsys/null/null_sw_winsys.h create mode 100644 src/gallium/winsys/radeon/drm/Makefile create mode 100644 src/gallium/winsys/radeon/drm/SConscript create mode 100644 src/gallium/winsys/radeon/drm/radeon_buffer.h create mode 100644 src/gallium/winsys/radeon/drm/radeon_drm.c create mode 100644 src/gallium/winsys/radeon/drm/radeon_drm.h create mode 100644 src/gallium/winsys/radeon/drm/radeon_drm_buffer.c create mode 100644 src/gallium/winsys/radeon/drm/radeon_r300.c create mode 100644 src/gallium/winsys/radeon/drm/radeon_r300.h create mode 100644 src/gallium/winsys/radeon/drm/radeon_winsys.h create mode 100644 src/gallium/winsys/svga/drm/Makefile create mode 100644 src/gallium/winsys/svga/drm/SConscript create mode 100644 src/gallium/winsys/svga/drm/vmw_buffer.c create mode 100644 src/gallium/winsys/svga/drm/vmw_buffer.h create mode 100644 src/gallium/winsys/svga/drm/vmw_context.c create mode 100644 src/gallium/winsys/svga/drm/vmw_context.h create mode 100644 src/gallium/winsys/svga/drm/vmw_fence.c create mode 100644 src/gallium/winsys/svga/drm/vmw_fence.h create mode 100644 src/gallium/winsys/svga/drm/vmw_screen.c create mode 100644 src/gallium/winsys/svga/drm/vmw_screen.h create mode 100644 src/gallium/winsys/svga/drm/vmw_screen_dri.c create mode 100644 src/gallium/winsys/svga/drm/vmw_screen_ioctl.c create mode 100644 src/gallium/winsys/svga/drm/vmw_screen_pools.c create mode 100644 src/gallium/winsys/svga/drm/vmw_screen_svga.c create mode 100644 src/gallium/winsys/svga/drm/vmw_surface.c create mode 100644 src/gallium/winsys/svga/drm/vmw_surface.h create mode 100644 src/gallium/winsys/svga/drm/vmwgfx_drm.h create mode 100644 src/gallium/winsys/sw/Makefile create mode 100644 src/gallium/winsys/sw/drm/Makefile create mode 100644 src/gallium/winsys/sw/drm/sw_drm_api.c create mode 100644 src/gallium/winsys/sw/drm/sw_drm_api.h create mode 100644 src/gallium/winsys/sw/gdi/SConscript create mode 100644 src/gallium/winsys/sw/gdi/gdi_sw_winsys.c create mode 100644 src/gallium/winsys/sw/gdi/gdi_sw_winsys.h create mode 100644 src/gallium/winsys/sw/null/Makefile create mode 100644 src/gallium/winsys/sw/null/SConscript create mode 100644 src/gallium/winsys/sw/null/null_sw_winsys.c create mode 100644 src/gallium/winsys/sw/null/null_sw_winsys.h create mode 100644 src/gallium/winsys/sw/wrapper/Makefile create mode 100644 src/gallium/winsys/sw/wrapper/wrapper_sw_winsys.c create mode 100644 src/gallium/winsys/sw/wrapper/wrapper_sw_winsys.h create mode 100644 src/gallium/winsys/sw/xlib/Makefile create mode 100644 src/gallium/winsys/sw/xlib/SConscript create mode 100644 src/gallium/winsys/sw/xlib/xlib_sw_winsys.c delete mode 100644 src/gallium/winsys/xlib/Makefile delete mode 100644 src/gallium/winsys/xlib/SConscript delete mode 100644 src/gallium/winsys/xlib/xlib_sw_winsys.c (limited to 'src/gallium') diff --git a/configs/default b/configs/default index 65e9847bd20..77a9898775c 100644 --- a/configs/default +++ b/configs/default @@ -100,7 +100,7 @@ GALLIUM_DIRS = auxiliary drivers state_trackers GALLIUM_AUXILIARIES = $(TOP)/src/gallium/auxiliary/libgallium.a GALLIUM_DRIVERS_DIRS = softpipe failover svga i915 i965 r300 trace identity GALLIUM_DRIVERS = $(foreach DIR,$(GALLIUM_DRIVERS_DIRS),$(TOP)/src/gallium/drivers/$(DIR)/lib$(DIR).a) -GALLIUM_WINSYS_DIRS = null xlib +GALLIUM_WINSYS_DIRS = sw sw/xlib GALLIUM_TARGET_DIRS = libgl-xlib GALLIUM_STATE_TRACKERS_DIRS = glx vega diff --git a/configs/linux-dri b/configs/linux-dri index b11daeda7c2..e21a3e95943 100644 --- a/configs/linux-dri +++ b/configs/linux-dri @@ -58,7 +58,7 @@ PROGRAM_DIRS := egl $(PROGRAM_DIRS) EGL_DRIVERS_DIRS = glx DRIVER_DIRS = dri -GALLIUM_WINSYS_DIRS = null xlib drm/vmware drm/intel drm/i965 +GALLIUM_WINSYS_DIRS = sw sw/xlib drm/vmware drm/intel drm/i965 GALLIUM_TARGET_DIRS = egl-swrast GALLIUM_STATE_TRACKERS_DIRS = egl diff --git a/configure.ac b/configure.ac index c8f78dc74e8..edf2363a717 100644 --- a/configure.ac +++ b/configure.ac @@ -461,20 +461,20 @@ SRC_DIRS="glew" GLU_DIRS="sgi" GALLIUM_DIRS="auxiliary drivers state_trackers" GALLIUM_TARGET_DIRS="" -GALLIUM_WINSYS_DIRS="null" +GALLIUM_WINSYS_DIRS="sw" GALLIUM_DRIVERS_DIRS="softpipe failover trace identity" GALLIUM_STATE_TRACKERS_DIRS="" case "$mesa_driver" in xlib) DRIVER_DIRS="x11" - GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS xlib" + GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS sw/xlib" GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS libgl-xlib" ;; dri) SRC_DIRS="$SRC_DIRS glx" DRIVER_DIRS="dri" - GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS xlib drm/sw" + GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS sw/xlib sw/drm" ;; osmesa) DRIVER_DIRS="osmesa" @@ -1317,7 +1317,7 @@ AC_ARG_ENABLE([gallium-svga], [enable_gallium_svga=auto]) if test "x$enable_gallium_svga" = xyes; then if test "x$mesa_driver" = xdri; then - GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS drm/vmware" + GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS svga/drm" GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS dri-vmwgfx" fi if test "x$enable_egl" = xyes; then @@ -1341,7 +1341,7 @@ AC_ARG_ENABLE([gallium-intel], [enable_gallium_intel=auto]) if test "x$enable_gallium_intel" = xyes; then if test "x$mesa_driver" = xdri; then - GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS drm/intel drm/i965" + GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS i915/drm i965/drm" GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS dri-i915 dri-i965" fi if test "x$enable_egl" = xyes; then @@ -1365,7 +1365,7 @@ AC_ARG_ENABLE([gallium-radeon], [enable_gallium_radeon=auto]) if test "x$enable_gallium_radeon" = xyes; then if test "x$mesa_driver" = xdri; then - GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS drm/radeon" + GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS radeon/drm" GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS dri-radeong" fi if test "x$enable_egl" = xyes; then @@ -1389,7 +1389,7 @@ AC_ARG_ENABLE([gallium-nouveau], [enable_gallium_nouveau=no]) if test "x$enable_gallium_nouveau" = xyes; then if test "x$mesa_driver" = xdri; then - GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS drm/nouveau" + GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS nouveau/drm" GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS dri-nouveau" fi if test "x$enable_egl" = xyes; then diff --git a/src/gallium/SConscript b/src/gallium/SConscript index c833d83e65b..b8c04f72379 100644 --- a/src/gallium/SConscript +++ b/src/gallium/SConscript @@ -8,7 +8,7 @@ for driver in env['drivers']: SConscript(os.path.join('drivers', driver, 'SConscript')) # Needed by some state trackers -SConscript('winsys/null/SConscript') +SConscript('winsys/sw/null/SConscript') SConscript('state_trackers/python/SConscript') if platform != 'embedded': diff --git a/src/gallium/targets/Makefile.egl b/src/gallium/targets/Makefile.egl index bc5dd3a53b8..30fced7e3c8 100644 --- a/src/gallium/targets/Makefile.egl +++ b/src/gallium/targets/Makefile.egl @@ -14,7 +14,7 @@ EGL_DRIVER_OBJECTS = $(EGL_DRIVER_SOURCES:.c=.o) common_LIBS = -ldrm -lm -ldl x11_ST = $(TOP)/src/gallium/state_trackers/egl/libeglx11.a \ - $(TOP)/src/gallium/winsys/xlib/libws_xlib.a + $(TOP)/src/gallium/winsys/sw/xlib/libws_xlib.a x11_LIBS = $(common_LIBS) -lX11 -lXext -lXfixes kms_ST = $(TOP)/src/gallium/state_trackers/egl/libeglkms.a diff --git a/src/gallium/targets/dri-i915/Makefile b/src/gallium/targets/dri-i915/Makefile index 33eaae624f2..facbcb1803a 100644 --- a/src/gallium/targets/dri-i915/Makefile +++ b/src/gallium/targets/dri-i915/Makefile @@ -5,7 +5,7 @@ LIBNAME = i915_dri.so PIPE_DRIVERS = \ $(TOP)/src/gallium/state_trackers/dri/libdridrm.a \ - $(TOP)/src/gallium/winsys/drm/intel/gem/libinteldrm.a \ + $(TOP)/src/gallium/winsys/i915/drm/libinteldrm.a \ $(TOP)/src/gallium/drivers/trace/libtrace.a \ $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ $(TOP)/src/gallium/drivers/identity/libidentity.a \ diff --git a/src/gallium/targets/dri-i965/Makefile b/src/gallium/targets/dri-i965/Makefile index e17775a842a..c622bbcaf65 100644 --- a/src/gallium/targets/dri-i965/Makefile +++ b/src/gallium/targets/dri-i965/Makefile @@ -5,9 +5,10 @@ LIBNAME = i965_dri.so PIPE_DRIVERS = \ $(TOP)/src/gallium/state_trackers/dri/libdridrm.a \ - $(TOP)/src/gallium/winsys/drm/i965/gem/libi965drm.a \ + $(TOP)/src/gallium/winsys/i965/drm/libi965drm.a \ $(TOP)/src/gallium/drivers/trace/libtrace.a \ - $(TOP)/src/gallium/winsys/drm/sw/libswdrm.a \ + $(TOP)/src/gallium/winsys/sw/drm/libswdrm.a \ + $(TOP)/src/gallium/winsys/sw/wrapper/libwsw.a \ $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ $(TOP)/src/gallium/drivers/identity/libidentity.a \ $(TOP)/src/gallium/drivers/i965/libi965.a diff --git a/src/gallium/targets/dri-nouveau/Makefile b/src/gallium/targets/dri-nouveau/Makefile index 680bad79177..9ba5e18ba70 100644 --- a/src/gallium/targets/dri-nouveau/Makefile +++ b/src/gallium/targets/dri-nouveau/Makefile @@ -5,7 +5,7 @@ LIBNAME = nouveau_dri.so PIPE_DRIVERS = \ $(TOP)/src/gallium/state_trackers/dri/libdridrm.a \ - $(TOP)/src/gallium/winsys/drm/nouveau/drm/libnouveaudrm.a \ + $(TOP)/src/gallium/winsys/nouveau/drm/libnouveaudrm.a \ $(TOP)/src/gallium/drivers/nvfx/libnvfx.a \ $(TOP)/src/gallium/drivers/nv50/libnv50.a \ $(TOP)/src/gallium/drivers/nouveau/libnouveau.a diff --git a/src/gallium/targets/dri-radeong/Makefile b/src/gallium/targets/dri-radeong/Makefile index c6d8c524694..ce25559e946 100644 --- a/src/gallium/targets/dri-radeong/Makefile +++ b/src/gallium/targets/dri-radeong/Makefile @@ -5,7 +5,7 @@ LIBNAME = radeong_dri.so PIPE_DRIVERS = \ $(TOP)/src/gallium/state_trackers/dri/libdridrm.a \ - $(TOP)/src/gallium/winsys/drm/radeon/core/libradeonwinsys.a \ + $(TOP)/src/gallium/winsys/radeon/drm/libradeonwinsys.a \ $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ $(TOP)/src/gallium/drivers/trace/libtrace.a \ $(TOP)/src/gallium/drivers/r300/libr300.a diff --git a/src/gallium/targets/dri-vmwgfx/Makefile b/src/gallium/targets/dri-vmwgfx/Makefile index 1d2ddfe548f..32edc46a3d9 100644 --- a/src/gallium/targets/dri-vmwgfx/Makefile +++ b/src/gallium/targets/dri-vmwgfx/Makefile @@ -5,7 +5,7 @@ LIBNAME = vmwgfx_dri.so PIPE_DRIVERS = \ $(TOP)/src/gallium/state_trackers/dri/libdridrm.a \ - $(TOP)/src/gallium/winsys/drm/vmware/core/libsvgadrm.a \ + $(TOP)/src/gallium/winsys/svga/drm/libsvgadrm.a \ $(TOP)/src/gallium/drivers/trace/libtrace.a \ $(TOP)/src/gallium/drivers/svga/libsvga.a diff --git a/src/gallium/targets/egl-i915/Makefile b/src/gallium/targets/egl-i915/Makefile index 596dd092f75..6c2fc14d70f 100644 --- a/src/gallium/targets/egl-i915/Makefile +++ b/src/gallium/targets/egl-i915/Makefile @@ -6,7 +6,7 @@ EGL_DRIVER_SOURCES = dummy.c EGL_DRIVER_LIBS = -ldrm_intel EGL_DRIVER_PIPES = \ - $(TOP)/src/gallium/winsys/drm/intel/gem/libinteldrm.a \ + $(TOP)/src/gallium/winsys/i915/drm/libinteldrm.a \ $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ $(TOP)/src/gallium/drivers/trace/libtrace.a \ $(TOP)/src/gallium/drivers/i915/libi915.a diff --git a/src/gallium/targets/egl-i965/Makefile b/src/gallium/targets/egl-i965/Makefile index e4c1a88f4c6..dfb3cc45a7d 100644 --- a/src/gallium/targets/egl-i965/Makefile +++ b/src/gallium/targets/egl-i965/Makefile @@ -6,7 +6,7 @@ EGL_DRIVER_SOURCES = dummy.c EGL_DRIVER_LIBS = -ldrm_intel EGL_DRIVER_PIPES = \ - $(TOP)/src/gallium/winsys/drm/i965/gem/libi965drm.a \ + $(TOP)/src/gallium/winsys/i965/drm/libi965drm.a \ $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ $(TOP)/src/gallium/drivers/trace/libtrace.a \ $(TOP)/src/gallium/drivers/i965/libi965.a diff --git a/src/gallium/targets/egl-nouveau/Makefile b/src/gallium/targets/egl-nouveau/Makefile index 46fcdf5e4b0..3da93790f25 100644 --- a/src/gallium/targets/egl-nouveau/Makefile +++ b/src/gallium/targets/egl-nouveau/Makefile @@ -6,7 +6,7 @@ EGL_DRIVER_SOURCES = dummy.c EGL_DRIVER_LIBS = -ldrm_nouveau EGL_DRIVER_PIPES = \ - $(TOP)/src/gallium/winsys/drm/nouveau/drm/libnouveaudrm.a \ + $(TOP)/src/gallium/winsys/nouveau/drm/libnouveaudrm.a \ $(TOP)/src/gallium/drivers/nvfx/libnvfx.a \ $(TOP)/src/gallium/drivers/nv50/libnv50.a \ $(TOP)/src/gallium/drivers/nouveau/libnouveau.a \ diff --git a/src/gallium/targets/egl-radeon/Makefile b/src/gallium/targets/egl-radeon/Makefile index 56818365dda..f55d84de810 100644 --- a/src/gallium/targets/egl-radeon/Makefile +++ b/src/gallium/targets/egl-radeon/Makefile @@ -6,7 +6,7 @@ EGL_DRIVER_SOURCES = dummy.c EGL_DRIVER_LIBS = -ldrm_radeon EGL_DRIVER_PIPES = \ - $(TOP)/src/gallium/winsys/drm/radeon/core/libradeonwinsys.a \ + $(TOP)/src/gallium/winsys/radeon/drm/libradeonwinsys.a \ $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ $(TOP)/src/gallium/drivers/trace/libtrace.a \ $(TOP)/src/gallium/drivers/r300/libr300.a diff --git a/src/gallium/targets/egl-vmwgfx/Makefile b/src/gallium/targets/egl-vmwgfx/Makefile index 007158a6408..6db12e03a75 100644 --- a/src/gallium/targets/egl-vmwgfx/Makefile +++ b/src/gallium/targets/egl-vmwgfx/Makefile @@ -6,7 +6,7 @@ EGL_DRIVER_SOURCES = dummy.c EGL_DRIVER_LIBS = EGL_DRIVER_PIPES = \ - $(TOP)/src/gallium/winsys/drm/vmware/core/libsvgadrm.a \ + $(TOP)/src/gallium/winsys/svga/drm/libsvgadrm.a \ $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ $(TOP)/src/gallium/drivers/trace/libtrace.a \ $(TOP)/src/gallium/drivers/svga/libsvga.a diff --git a/src/gallium/targets/xorg-i915/Makefile b/src/gallium/targets/xorg-i915/Makefile index 4442147e83f..e2cffcd70b3 100644 --- a/src/gallium/targets/xorg-i915/Makefile +++ b/src/gallium/targets/xorg-i915/Makefile @@ -17,7 +17,7 @@ INCLUDES = \ LIBS = \ $(TOP)/src/gallium/state_trackers/xorg/libxorgtracker.a \ - $(TOP)/src/gallium/winsys/drm/intel/gem/libinteldrm.a \ + $(TOP)/src/gallium/winsys/i915/drm/libinteldrm.a \ $(TOP)/src/gallium/drivers/i915/libi915.a \ $(TOP)/src/gallium/drivers/trace/libtrace.a \ $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ diff --git a/src/gallium/targets/xorg-i965/Makefile b/src/gallium/targets/xorg-i965/Makefile index 8d6a741e5d1..104a1434a84 100644 --- a/src/gallium/targets/xorg-i965/Makefile +++ b/src/gallium/targets/xorg-i965/Makefile @@ -17,7 +17,7 @@ CFLAGS = -DHAVE_CONFIG_H \ LIBS = \ $(TOP)/src/gallium/state_trackers/xorg/libxorgtracker.a \ - $(TOP)/src/gallium/winsys/drm/i965/gem/libi965drm.a \ + $(TOP)/src/gallium/winsys/i965/drm/libi965drm.a \ $(TOP)/src/gallium/drivers/i965/libi965.a \ $(TOP)/src/gallium/drivers/trace/libtrace.a \ $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ diff --git a/src/gallium/targets/xorg-nouveau/Makefile b/src/gallium/targets/xorg-nouveau/Makefile index d41de0b3110..b514b570007 100644 --- a/src/gallium/targets/xorg-nouveau/Makefile +++ b/src/gallium/targets/xorg-nouveau/Makefile @@ -16,7 +16,7 @@ INCLUDES = \ LIBS = \ $(TOP)/src/gallium/state_trackers/xorg/libxorgtracker.a \ - $(TOP)/src/gallium/winsys/drm/nouveau/drm/libnouveaudrm.a \ + $(TOP)/src/gallium/winsys/nouveau/drm/libnouveaudrm.a \ $(TOP)/src/gallium/drivers/nvfx/libnvfx.a \ $(TOP)/src/gallium/drivers/nv50/libnv50.a \ $(TOP)/src/gallium/drivers/nouveau/libnouveau.a \ diff --git a/src/gallium/targets/xorg-radeon/Makefile b/src/gallium/targets/xorg-radeon/Makefile index 9618d30b4d6..cd32914c0d3 100644 --- a/src/gallium/targets/xorg-radeon/Makefile +++ b/src/gallium/targets/xorg-radeon/Makefile @@ -17,7 +17,7 @@ CFLAGS = -DHAVE_CONFIG_H \ LIBS = \ $(TOP)/src/gallium/state_trackers/xorg/libxorgtracker.a \ - $(TOP)/src/gallium/winsys/drm/radeon/core/libradeonwinsys.a \ + $(TOP)/src/gallium/winsys/radeon/drm/libradeonwinsys.a \ $(TOP)/src/gallium/drivers/r300/libr300.a \ $(TOP)/src/gallium/drivers/trace/libtrace.a \ $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ diff --git a/src/gallium/targets/xorg-vmwgfx/Makefile b/src/gallium/targets/xorg-vmwgfx/Makefile index 3691b883588..12bc307ef9b 100644 --- a/src/gallium/targets/xorg-vmwgfx/Makefile +++ b/src/gallium/targets/xorg-vmwgfx/Makefile @@ -20,7 +20,7 @@ INCLUDES = \ LIBS = \ $(TOP)/src/gallium/state_trackers/xorg/libxorgtracker.a \ - $(TOP)/src/gallium/winsys/drm/vmware/core/libsvgadrm.a \ + $(TOP)/src/gallium/winsys/svga/drm/libsvgadrm.a \ $(TOP)/src/gallium/drivers/trace/libtrace.a \ $(TOP)/src/gallium/drivers/svga/libsvga.a \ $(GALLIUM_AUXILIARIES) diff --git a/src/gallium/targets/xorg-vmwgfx/vmw_ioctl.c b/src/gallium/targets/xorg-vmwgfx/vmw_ioctl.c index fe9c0393e23..96ee4ff82b4 100644 --- a/src/gallium/targets/xorg-vmwgfx/vmw_ioctl.c +++ b/src/gallium/targets/xorg-vmwgfx/vmw_ioctl.c @@ -42,7 +42,7 @@ #include #include "xf86drm.h" -#include "../../winsys/drm/vmware/core/vmwgfx_drm.h" +#include "../../winsys/svga/drm/vmwgfx_drm.h" #include "vmw_driver.h" #include "util/u_debug.h" diff --git a/src/gallium/targets/xorg-vmwgfx/vmw_video.c b/src/gallium/targets/xorg-vmwgfx/vmw_video.c index 7909999edfb..eced60d0ec1 100644 --- a/src/gallium/targets/xorg-vmwgfx/vmw_video.c +++ b/src/gallium/targets/xorg-vmwgfx/vmw_video.c @@ -62,7 +62,7 @@ typedef uint8_t uint8; #include #include "xf86drm.h" -#include "../../winsys/drm/vmware/core/vmwgfx_drm.h" +#include "../../winsys/svga/drm/vmwgfx_drm.h" #define MAKE_ATOM(a) MakeAtom(a, sizeof(a) - 1, TRUE) diff --git a/src/gallium/winsys/SConscript b/src/gallium/winsys/SConscript index 30c3378dfff..97ea82ea761 100644 --- a/src/gallium/winsys/SConscript +++ b/src/gallium/winsys/SConscript @@ -1,16 +1,11 @@ Import('*') -if env['dri']: - SConscript([ - 'drm/SConscript', - ]) - if 'xlib' in env['winsys']: SConscript([ - 'xlib/SConscript', + 'sw/xlib/SConscript', ]) if 'gdi' in env['winsys']: SConscript([ - 'gdi/SConscript', + 'sw/gdi/SConscript', ]) diff --git a/src/gallium/winsys/drm/SConscript b/src/gallium/winsys/drm/SConscript deleted file mode 100644 index 66b73a8bf93..00000000000 --- a/src/gallium/winsys/drm/SConscript +++ /dev/null @@ -1,69 +0,0 @@ -Import('*') - -if env['dri']: - - drienv = env.Clone() - - drienv.Replace(CPPPATH = [ - '#src/mesa/drivers/dri/common', - '#include', - '#include/GL/internal', - '#src/gallium/include', - '#src/gallium/auxiliary', - '#src/gallium/drivers', - '#src/mesa', - '#src/mesa/main', - '#src/mesa/glapi', - '#src/mesa/math', - '#src/mesa/transform', - '#src/mesa/shader', - '#src/mesa/swrast', - '#src/mesa/swrast_setup', - '#src/egl/main', - '#src/egl/drivers/dri', - ]) - - drienv.ParseConfig('pkg-config --cflags --libs libdrm') - - COMMON_GALLIUM_SOURCES = [ - '#src/mesa/drivers/dri/common/utils.c', - '#src/mesa/drivers/dri/common/vblank.c', - '#src/mesa/drivers/dri/common/dri_util.c', - '#src/mesa/drivers/dri/common/xmlconfig.c', - ] - - COMMON_BM_SOURCES = [ - '#src/mesa/drivers/dri/common/dri_bufmgr.c', - '#src/mesa/drivers/dri/common/dri_drmpool.c', - ] - - Export([ - 'drienv', - 'COMMON_GALLIUM_SOURCES', - 'COMMON_BM_SOURCES', - ]) - - # TODO: Installation - #install: $(LIBNAME) - # $(INSTALL) -d $(DRI_DRIVER_INSTALL_DIR) - # $(INSTALL) -m 755 $(LIBNAME) $(DRI_DRIVER_INSTALL_DIR) - - if 'vmware' in env['winsys']: - SConscript([ - 'vmware/SConscript', - ]) - - if 'intel' in env['winsys']: - SConscript([ - 'intel/SConscript', - ]) - - if 'i965' in env['winsys']: - SConscript([ - 'i965/SConscript', - ]) - - if 'radeon' in env['winsys']: - SConscript([ - 'radeon/SConscript', - ]) diff --git a/src/gallium/winsys/drm/i965/Makefile b/src/gallium/winsys/drm/i965/Makefile deleted file mode 100644 index d8feef6824a..00000000000 --- a/src/gallium/winsys/drm/i965/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -# src/gallium/winsys/drm/intel/Makefile -TOP = ../../../../.. -include $(TOP)/configs/current - -SUBDIRS = gem $(GALLIUM_STATE_TRACKERS_DIRS) - -default install clean: - @for dir in $(SUBDIRS) ; do \ - if [ -d $$dir ] ; then \ - (cd $$dir && $(MAKE) $@) || exit 1; \ - fi \ - done diff --git a/src/gallium/winsys/drm/i965/SConscript b/src/gallium/winsys/drm/i965/SConscript deleted file mode 100644 index fdf57eedb94..00000000000 --- a/src/gallium/winsys/drm/i965/SConscript +++ /dev/null @@ -1,3 +0,0 @@ -Import('*') - -SConscript(['gem/SConscript',]) diff --git a/src/gallium/winsys/drm/i965/gem/Makefile b/src/gallium/winsys/drm/i965/gem/Makefile deleted file mode 100644 index 6a7497b6be3..00000000000 --- a/src/gallium/winsys/drm/i965/gem/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -TOP = ../../../../../.. -include $(TOP)/configs/current - -LIBNAME = i965drm - -C_SOURCES = \ - i965_drm_buffer.c \ - i965_drm_api.c - -LIBRARY_INCLUDES = $(shell pkg-config libdrm --cflags-only-I) - -LIBRARY_DEFINES = $(shell pkg-config libdrm --cflags-only-other) - -include ../../../../Makefile.template diff --git a/src/gallium/winsys/drm/i965/gem/SConscript b/src/gallium/winsys/drm/i965/gem/SConscript deleted file mode 100644 index 6256ec6eaf0..00000000000 --- a/src/gallium/winsys/drm/i965/gem/SConscript +++ /dev/null @@ -1,15 +0,0 @@ -Import('*') - -env = drienv.Clone() - -i965drm_sources = [ - 'i965_drm_api.c', - 'i965_drm_buffer.c', -] - -i965drm = env.ConvenienceLibrary( - target ='i965drm', - source = i965drm_sources, -) - -Export('i965drm') diff --git a/src/gallium/winsys/drm/i965/gem/i965_drm_api.c b/src/gallium/winsys/drm/i965/gem/i965_drm_api.c deleted file mode 100644 index c644eedcb31..00000000000 --- a/src/gallium/winsys/drm/i965/gem/i965_drm_api.c +++ /dev/null @@ -1,122 +0,0 @@ - -#include -#include "state_tracker/drm_api.h" - -#include "i965_drm_winsys.h" -#include "util/u_memory.h" - -#include "i965/brw_context.h" /* XXX: shouldn't be doing this */ -#include "i965/brw_screen.h" /* XXX: shouldn't be doing this */ - -#include "trace/tr_drm.h" - -#include "../../sw/sw_drm_api.h" - -/* - * Helper functions - */ - - -static void -i965_libdrm_get_device_id(unsigned int *device_id) -{ - char path[512]; - FILE *file; - void *shutup_gcc; - - /* - * FIXME: Fix this up to use a drm ioctl or whatever. - */ - - snprintf(path, sizeof(path), "/sys/class/drm/card0/device/device"); - file = fopen(path, "r"); - if (!file) { - return; - } - - shutup_gcc = fgets(path, sizeof(path), file); - sscanf(path, "%x", device_id); - fclose(file); -} - -static void -i965_libdrm_winsys_destroy(struct brw_winsys_screen *iws) -{ - struct i965_libdrm_winsys *idws = i965_libdrm_winsys(iws); - - if (BRW_DUMP) - debug_printf("%s\n", __FUNCTION__); - - drm_intel_bufmgr_destroy(idws->gem); - - FREE(idws); -} - -static struct pipe_screen * -i965_libdrm_create_screen(struct drm_api *api, int drmFD, - struct drm_create_screen_arg *arg) -{ - struct i965_libdrm_winsys *idws; - unsigned int deviceID; - - debug_printf("%s\n", __FUNCTION__); - - if (arg != NULL) { - switch(arg->mode) { - case DRM_CREATE_NORMAL: - break; - default: - return NULL; - } - } - - idws = CALLOC_STRUCT(i965_libdrm_winsys); - if (!idws) - return NULL; - - i965_libdrm_get_device_id(&deviceID); - - i965_libdrm_winsys_init_buffer_functions(idws); - - idws->fd = drmFD; - idws->id = deviceID; - - idws->base.destroy = i965_libdrm_winsys_destroy; - - idws->gem = drm_intel_bufmgr_gem_init(idws->fd, BRW_BATCH_SIZE); - drm_intel_bufmgr_gem_enable_reuse(idws->gem); - - idws->send_cmd = !debug_get_bool_option("BRW_NO_HW", FALSE); - - return brw_create_screen(&idws->base, deviceID); -} - - -static void -destroy(struct drm_api *api) -{ - if (BRW_DUMP) - debug_printf("%s\n", __FUNCTION__); - -} - -struct drm_api i965_libdrm_api = -{ - .name = "i965", - .create_screen = i965_libdrm_create_screen, - .destroy = destroy, -}; - -struct drm_api * -drm_api_create() -{ - struct drm_api *api = NULL; - - if (api == NULL && debug_get_bool_option("BRW_SOFTPIPE", FALSE)) - api = sw_drm_api_create(&i965_libdrm_api); - - if (api == NULL) - api = &i965_libdrm_api; - - return trace_drm_create(api); -} diff --git a/src/gallium/winsys/drm/i965/gem/i965_drm_buffer.c b/src/gallium/winsys/drm/i965/gem/i965_drm_buffer.c deleted file mode 100644 index 33a17496b2b..00000000000 --- a/src/gallium/winsys/drm/i965/gem/i965_drm_buffer.c +++ /dev/null @@ -1,503 +0,0 @@ - -#include "state_tracker/drm_api.h" -#include "i965_drm_winsys.h" -#include "util/u_memory.h" -#include "util/u_inlines.h" - -#include "i915_drm.h" -#include "intel_bufmgr.h" - - - -const char *names[BRW_BUFFER_TYPE_MAX] = { - "TEXTURE", - "SCANOUT", - "VERTEX", - "CURBE", - "QUERY", - "SHADER_CONSTANTS", - "WM_SCRATCH", - "BATCH", - "GENERAL_STATE", - "SURFACE_STATE", - "PIXEL", - "GENERIC", -}; - -const char *usages[BRW_USAGE_MAX] = { - "STATE", - "QUERY_RESULT", - "RENDER_TARGET", - "DEPTH_BUFFER", - "BLIT_SOURCE", - "BLIT_DEST", - "SAMPLER", - "VERTEX", - "SCRATCH" -}; - - -const char *data_types[BRW_DATA_MAX] = -{ - "GS: CC_VP", - "GS: CC_UNIT", - "GS: WM_PROG", - "GS: SAMPLER_DEFAULT_COLOR", - "GS: SAMPLER", - "GS: WM_UNIT", - "GS: SF_PROG", - "GS: SF_VP", - "GS: SF_UNIT", - "GS: VS_UNIT", - "GS: VS_PROG", - "GS: GS_UNIT", - "GS: GS_PROG", - "GS: CLIP_VP", - "GS: CLIP_UNIT", - "GS: CLIP_PROG", - "SS: SURFACE", - "SS: SURF_BIND", - "CONSTANT DATA", - "BATCH DATA", - "(untyped)" -}; - -static enum pipe_error -i965_libdrm_bo_alloc(struct brw_winsys_screen *sws, - enum brw_buffer_type type, - unsigned size, - unsigned alignment, - struct brw_winsys_buffer **bo_out) -{ - struct i965_libdrm_winsys *idws = i965_libdrm_winsys(sws); - struct i965_libdrm_buffer *buf; - - if (BRW_DUMP) - debug_printf("%s type %s sz %d align %d\n", - __FUNCTION__, names[type], size, alignment ); - - buf = CALLOC_STRUCT(i965_libdrm_buffer); - if (!buf) - return PIPE_ERROR_OUT_OF_MEMORY; - - switch (type) { - case BRW_BUFFER_TYPE_TEXTURE: -/* case BRW_BUFFER_TYPE_SCANOUT:*/ - case BRW_BUFFER_TYPE_VERTEX: - case BRW_BUFFER_TYPE_CURBE: - case BRW_BUFFER_TYPE_QUERY: - case BRW_BUFFER_TYPE_SHADER_CONSTANTS: - case BRW_BUFFER_TYPE_SHADER_SCRATCH: - case BRW_BUFFER_TYPE_BATCH: - case BRW_BUFFER_TYPE_GENERAL_STATE: - case BRW_BUFFER_TYPE_SURFACE_STATE: - case BRW_BUFFER_TYPE_PIXEL: - case BRW_BUFFER_TYPE_GENERIC: - break; - case BRW_BUFFER_TYPE_SCANOUT: - buf->map_gtt = TRUE; - break; - default: - assert(0); - break; - } - - buf->bo = drm_intel_bo_alloc(idws->gem, - names[type], - size, - alignment); - - if (!buf->bo) - goto err; - - pipe_reference_init(&buf->base.reference, 1); - buf->base.size = size; - buf->base.sws = sws; - - *bo_out = &buf->base; - return PIPE_OK; - -err: - assert(0); - FREE(buf); - return PIPE_ERROR_OUT_OF_MEMORY; -} - -static enum pipe_error -i965_libdrm_bo_from_handle(struct brw_winsys_screen *sws, - struct winsys_handle *whandle, - unsigned *stride, - unsigned *tile, - struct brw_winsys_buffer **bo_out) -{ - struct i965_libdrm_winsys *idws = i965_libdrm_winsys(sws); - struct i965_libdrm_buffer *buf = CALLOC_STRUCT(i965_libdrm_buffer); - uint32_t swizzle = 0; - - if (BRW_DUMP) - debug_printf("%s\n", __FUNCTION__); - - if (!buf) - return PIPE_ERROR_OUT_OF_MEMORY; - - pipe_reference_init(&buf->base.reference, 1); - buf->bo = drm_intel_bo_gem_create_from_name(idws->gem, "FROM_HANDLE", whandle->handle); - buf->base.size = buf->bo->size; - buf->base.sws = &idws->base; - buf->flinked = TRUE; - buf->flink = whandle->handle; - - - if (!buf->bo) - goto err; - - drm_intel_bo_get_tiling(buf->bo, &buf->tiling, &swizzle); - if (buf->tiling != 0) - buf->map_gtt = TRUE; - - *tile = buf->tiling; - *stride = whandle->stride; - - *bo_out = &buf->base; - return PIPE_OK; - -err: - FREE(buf); - return PIPE_ERROR_OUT_OF_MEMORY; -} - -static enum pipe_error -i965_libdrm_bo_get_handle(struct brw_winsys_buffer *buffer, - struct winsys_handle *whandle, - unsigned stride) -{ - struct i965_libdrm_buffer *buf = i965_libdrm_buffer(buffer); - - if (BRW_DUMP) - debug_printf("%s\n", __FUNCTION__); - - if (whandle->type == DRM_API_HANDLE_TYPE_SHARED) { - if (!buf->flinked) { - if (drm_intel_bo_flink(buf->bo, &buf->flink)) - return PIPE_ERROR_BAD_INPUT; - buf->flinked = TRUE; - } - - whandle->handle = buf->flink; - } else if (whandle->type == DRM_API_HANDLE_TYPE_KMS) { - whandle->handle = buf->bo->handle; - } else { - assert(!"unknown usage"); - return PIPE_ERROR_BAD_INPUT; - } - - whandle->stride = stride; - return PIPE_OK; -} - -static void -i965_libdrm_bo_destroy(struct brw_winsys_buffer *buffer) -{ - struct i965_libdrm_buffer *buf = i965_libdrm_buffer(buffer); - - if (BRW_DUMP) - debug_printf("%s\n", __FUNCTION__); - - drm_intel_bo_unreference(buf->bo); - FREE(buffer); -} - -static enum pipe_error -i965_libdrm_bo_emit_reloc(struct brw_winsys_buffer *buffer, - enum brw_buffer_usage usage, - unsigned delta, - unsigned offset, - struct brw_winsys_buffer *buffer2) -{ - struct i965_libdrm_buffer *buf = i965_libdrm_buffer(buffer); - struct i965_libdrm_buffer *buf2 = i965_libdrm_buffer(buffer2); - int read, write; - int ret; - - if (BRW_DUMP) - debug_printf("%s buf %p offset %x delta %x buf2 %p/%s/%s\n", - __FUNCTION__, (void *)buffer, - offset, delta, - (void *)buffer2, names[buf2->data_type], usages[usage]); - - switch (usage) { - case BRW_USAGE_STATE: - read = I915_GEM_DOMAIN_INSTRUCTION; - write = 0; - break; - case BRW_USAGE_QUERY_RESULT: - read = I915_GEM_DOMAIN_INSTRUCTION; - write = I915_GEM_DOMAIN_INSTRUCTION; - break; - case BRW_USAGE_RENDER_TARGET: - read = I915_GEM_DOMAIN_RENDER; - write = 0; - break; - case BRW_USAGE_DEPTH_BUFFER: - read = I915_GEM_DOMAIN_RENDER; - write = I915_GEM_DOMAIN_RENDER; - break; - case BRW_USAGE_BLIT_SOURCE: - read = 0; - write = I915_GEM_DOMAIN_RENDER; - break; - case BRW_USAGE_BLIT_DEST: - read = I915_GEM_DOMAIN_RENDER; - write = I915_GEM_DOMAIN_RENDER; - break; - case BRW_USAGE_SAMPLER: - read = I915_GEM_DOMAIN_SAMPLER; - write = 0; - break; - case BRW_USAGE_VERTEX: - read = I915_GEM_DOMAIN_VERTEX; - write = 0; - break; - case BRW_USAGE_SCRATCH: - read = 0; - write = 0; - break; - default: - assert(0); - return -1; - } - - /* Needed?? - ((uint32_t *)buf->bo->virtual)[offset/4] = (delta + - buf2->bo->offset); - */ - - ret = dri_bo_emit_reloc( buf->bo, read, write, delta, offset, buf2->bo ); - if (ret) - return -1; - - return 0; -} - -static enum pipe_error -i965_libdrm_bo_exec(struct brw_winsys_buffer *buffer, - unsigned bytes_used) -{ - struct i965_libdrm_buffer *buf = i965_libdrm_buffer(buffer); - struct i965_libdrm_winsys *idws = i965_libdrm_winsys(buffer->sws); - int ret; - - if (BRW_DUMP) - debug_printf("execute buffer %p, bytes %d\n", (void *)buffer, bytes_used); - - if (idws->send_cmd) { - ret = dri_bo_exec(buf->bo, bytes_used, NULL, 0, 0); - if (ret) - return PIPE_ERROR; - } - - return PIPE_OK; -} - -static enum pipe_error -i965_libdrm_bo_subdata(struct brw_winsys_buffer *buffer, - enum brw_buffer_data_type data_type, - size_t offset, - size_t size, - const void *data, - const struct brw_winsys_reloc *reloc, - unsigned nr_reloc) -{ - struct i965_libdrm_buffer *buf = i965_libdrm_buffer(buffer); - struct i965_libdrm_winsys *idws = i965_libdrm_winsys(buffer->sws); - int ret, i; - - (void)data_type; - - if (BRW_DUMP) - debug_printf("%s buf %p off %d sz %d %s relocs: %d\n", - __FUNCTION__, - (void *)buffer, offset, size, - data_types[data_type], - nr_reloc); - - if (BRW_DUMP) - brw_dump_data( idws->id, - data_type, - buf->bo->offset + offset, - data, size ); - - /* XXX: use bo_map_gtt/memcpy/unmap_gtt under some circumstances??? - */ - ret = drm_intel_bo_subdata(buf->bo, offset, size, (void*)data); - if (ret) - return PIPE_ERROR; - - for (i = 0; i < nr_reloc; i++) { - i965_libdrm_bo_emit_reloc(buffer, reloc[i].usage, reloc[i].delta, - reloc[i].offset, reloc[i].bo); - } - - return PIPE_OK; -} - -static boolean -i965_libdrm_bo_is_busy(struct brw_winsys_buffer *buffer) -{ - struct i965_libdrm_buffer *buf = i965_libdrm_buffer(buffer); - boolean ret; - - if (BRW_DUMP) - debug_printf("%s %p\n", __FUNCTION__, (void *)buffer); - - ret = drm_intel_bo_busy(buf->bo); - - if (BRW_DUMP) - debug_printf(" --> %d\n", ret); - - return ret; -} - -static boolean -i965_libdrm_bo_references(struct brw_winsys_buffer *a, - struct brw_winsys_buffer *b) -{ - struct i965_libdrm_buffer *bufa = i965_libdrm_buffer(a); - struct i965_libdrm_buffer *bufb = i965_libdrm_buffer(b); - boolean ret; - - if (BRW_DUMP) - debug_printf("%s %p %p\n", __FUNCTION__, (void *)a, (void *)b); - - ret = drm_intel_bo_references(bufa->bo, bufb->bo); - - if (BRW_DUMP) - debug_printf(" --> %d\n", ret); - - return ret; -} - -/* XXX: couldn't this be handled by returning true/false on - * bo_emit_reloc? - */ -static enum pipe_error -i965_libdrm_check_aperture_space(struct brw_winsys_screen *iws, - struct brw_winsys_buffer **buffers, - unsigned count) -{ - static drm_intel_bo *bos[128]; - int i; - int ret; - - if (BRW_DUMP) - debug_printf("%s\n", __FUNCTION__); - - if (count > Elements(bos)) { - assert(0); - return FALSE; - } - - for (i = 0; i < count; i++) - bos[i] = i965_libdrm_buffer(buffers[i])->bo; - - /* XXX: converting from ??? to pipe_error: - */ - ret = dri_bufmgr_check_aperture_space(bos, count); - - if (BRW_DUMP) - debug_printf(" --> %d (ok == %d)\n", ret, PIPE_OK); - - return ret; -} - -static void * -i965_libdrm_bo_map(struct brw_winsys_buffer *buffer, - enum brw_buffer_data_type data_type, - unsigned offset, - unsigned length, - boolean write, - boolean discard, - boolean flush_explicit) -{ - struct i965_libdrm_buffer *buf = i965_libdrm_buffer(buffer); - int ret; - - - if (BRW_DUMP) - debug_printf("%s %p %s %s\n", __FUNCTION__, (void *)buffer, - write ? "read/write" : "read", - write ? data_types[data_type] : ""); - - if (!buf->map_count) { - if (buf->map_gtt) { - ret = drm_intel_gem_bo_map_gtt(buf->bo); - if (ret) - return NULL; - } - else { - ret = drm_intel_bo_map(buf->bo, write); - if (ret) - return NULL; - } - } - - buf->data_type = data_type; - buf->map_count++; - return buf->bo->virtual; -} - -static void -i965_libdrm_bo_flush_range(struct brw_winsys_buffer *buffer, - unsigned offset, - unsigned length) -{ - struct i965_libdrm_buffer *buf = i965_libdrm_buffer(buffer); - struct i965_libdrm_winsys *idws = i965_libdrm_winsys(buffer->sws); - - if (BRW_DUMP) - debug_printf("%s %s offset %d len %d\n", __FUNCTION__, - data_types[buf->data_type], - offset, length); - - if (BRW_DUMP) - brw_dump_data( idws->id, - buf->data_type, - buf->bo->offset + offset, - buf->bo->virtual + offset, - length ); -} - -static void -i965_libdrm_bo_unmap(struct brw_winsys_buffer *buffer) -{ - struct i965_libdrm_buffer *buf = i965_libdrm_buffer(buffer); - - if (BRW_DUMP) - debug_printf("%s\n", __FUNCTION__); - - if (--buf->map_count > 0) - return; - - if (buf->map_gtt) - drm_intel_gem_bo_unmap_gtt(buf->bo); - else - drm_intel_bo_unmap(buf->bo); -} - -void -i965_libdrm_winsys_init_buffer_functions(struct i965_libdrm_winsys *idws) -{ - idws->base.bo_alloc = i965_libdrm_bo_alloc; - idws->base.bo_from_handle = i965_libdrm_bo_from_handle; - idws->base.bo_get_handle = i965_libdrm_bo_get_handle; - idws->base.bo_destroy = i965_libdrm_bo_destroy; - idws->base.bo_emit_reloc = i965_libdrm_bo_emit_reloc; - idws->base.bo_exec = i965_libdrm_bo_exec; - idws->base.bo_subdata = i965_libdrm_bo_subdata; - idws->base.bo_is_busy = i965_libdrm_bo_is_busy; - idws->base.bo_references = i965_libdrm_bo_references; - idws->base.check_aperture_space = i965_libdrm_check_aperture_space; - idws->base.bo_map = i965_libdrm_bo_map; - idws->base.bo_flush_range = i965_libdrm_bo_flush_range; - idws->base.bo_unmap = i965_libdrm_bo_unmap; -} diff --git a/src/gallium/winsys/drm/i965/gem/i965_drm_winsys.h b/src/gallium/winsys/drm/i965/gem/i965_drm_winsys.h deleted file mode 100644 index c6a7d4a8c51..00000000000 --- a/src/gallium/winsys/drm/i965/gem/i965_drm_winsys.h +++ /dev/null @@ -1,64 +0,0 @@ - -#ifndef INTEL_DRM_WINSYS_H -#define INTEL_DRM_WINSYS_H - -#include "i965/brw_winsys.h" - -#include "drm.h" -#include "intel_bufmgr.h" - - - -/* - * Winsys - */ - - -struct i965_libdrm_winsys -{ - struct brw_winsys_screen base; - drm_intel_bufmgr *gem; - - boolean send_cmd; - - int fd; /**< Drm file discriptor */ - - unsigned id; -}; - -static INLINE struct i965_libdrm_winsys * -i965_libdrm_winsys(struct brw_winsys_screen *iws) -{ - return (struct i965_libdrm_winsys *)iws; -} - -struct i965_libdrm_winsys *i965_libdrm_winsys_create(int fd, unsigned pci_id); - -void i965_libdrm_winsys_init_buffer_functions(struct i965_libdrm_winsys *idws); - - -/* Buffer. - */ -struct i965_libdrm_buffer { - struct brw_winsys_buffer base; - - drm_intel_bo *bo; - - void *ptr; - unsigned map_count; - unsigned data_type; /* valid while mapped */ - unsigned tiling; - - boolean map_gtt; - boolean flinked; - unsigned flink; -}; - -static INLINE struct i965_libdrm_buffer * -i965_libdrm_buffer(struct brw_winsys_buffer *buffer) -{ - return (struct i965_libdrm_buffer *)buffer; -} - - -#endif diff --git a/src/gallium/winsys/drm/i965/xlib/Makefile b/src/gallium/winsys/drm/i965/xlib/Makefile deleted file mode 100644 index 0efa0ca6f9a..00000000000 --- a/src/gallium/winsys/drm/i965/xlib/Makefile +++ /dev/null @@ -1,97 +0,0 @@ -# src/gallium/winsys/xlib/Makefile - -# This makefile produces a "stand-alone" libGL.so which is based on -# Xlib (no DRI HW acceleration) - - -TOP = ../../../../../.. -include $(TOP)/configs/current - - -GL_MAJOR = 1 -GL_MINOR = 5 -GL_TINY = 0$(MESA_MAJOR)0$(MESA_MINOR)0$(MESA_TINY) - - -INCLUDE_DIRS = \ - -I$(TOP)/include \ - -I$(TOP)/src/mesa \ - -I$(TOP)/src/mesa/main \ - -I$(TOP)/src/gallium/include \ - -I$(TOP)/src/gallium/drivers \ - -I$(TOP)/src/gallium/drivers/i965 \ - -I$(TOP)/src/gallium/drivers/i965/include \ - -I$(TOP)/src/gallium/state_trackers/glx/xlib \ - -I$(TOP)/src/gallium/auxiliary \ - -I/usr/include/drm - -XLIB_WINSYS_SOURCES = \ - xlib_i965.c \ - - - -XLIB_WINSYS_OBJECTS = $(XLIB_WINSYS_SOURCES:.c=.o) - - - -LIBS = \ - $(TOP)/src/gallium/drivers/i965/libi965.a \ - $(TOP)/src/gallium/drivers/trace/libtrace.a \ - $(TOP)/src/gallium/state_trackers/glx/xlib/libxlib.a \ - $(TOP)/src/mesa/libglapi.a \ - $(TOP)/src/mesa/libmesagallium.a \ - $(GALLIUM_AUXILIARIES) - -# $(TOP)/src/gallium/drivers/i965/lib/libi9xx.a \ - -.SUFFIXES : .cpp - -.c.o: - $(CC) -c $(INCLUDE_DIRS) $(DEFINES) $(CFLAGS) $< -o $@ - -.cpp.o: - $(CXX) -c $(INCLUDE_DIRS) $(DEFINES) $(CXXFLAGS) $< -o $@ - - - -default: $(TOP)/$(LIB_DIR)/gallium $(TOP)/$(LIB_DIR)/gallium/$(GL_LIB_NAME) - -$(TOP)/$(LIB_DIR)/gallium: - @ mkdir -p $(TOP)/$(LIB_DIR)/gallium - -# Make the libGL.so library -$(TOP)/$(LIB_DIR)/gallium/$(GL_LIB_NAME): $(XLIB_WINSYS_OBJECTS) $(LIBS) Makefile - $(TOP)/bin/mklib -o $(GL_LIB) \ - -linker "$(CC)" \ - -major $(GL_MAJOR) -minor $(GL_MINOR) -patch $(GL_TINY) \ - -install $(TOP)/$(LIB_DIR)/gallium \ - $(MKLIB_OPTIONS) $(XLIB_WINSYS_OBJECTS) \ - -Wl,--start-group $(LIBS) -Wl,--end-group $(GL_LIB_DEPS) - - -depend: $(XLIB_WINSYS_SOURCES) - @ echo "running $(MKDEP)" - @ rm -f depend # workaround oops on gutsy?!? - @ touch depend - $(MKDEP) $(MKDEP_OPTIONS) $(DEFINES) $(INCLUDE_DIRS) $(XLIB_WINSYS_SOURCES) \ - > /dev/null 2>/dev/null - - -install: default - $(INSTALL) -d $(INSTALL_DIR)/include/GL - $(INSTALL) -d $(INSTALL_DIR)/$(LIB_DIR) - $(INSTALL) -m 644 $(TOP)/include/GL/*.h $(INSTALL_DIR)/include/GL - @if [ -e $(TOP)/$(LIB_DIR)/$(GL_LIB_NAME) ]; then \ - $(MINSTALL) $(TOP)/$(LIB_DIR)/libGL* $(INSTALL_DIR)/$(LIB_DIR); \ - fi - - -# Emacs tags -tags: - etags `find . -name \*.[ch]` $(TOP)/include/GL/*.h - -clean: - -rm -f *.o - - -include depend diff --git a/src/gallium/winsys/drm/i965/xlib/xlib_i965.c b/src/gallium/winsys/drm/i965/xlib/xlib_i965.c deleted file mode 100644 index 063e9f600b9..00000000000 --- a/src/gallium/winsys/drm/i965/xlib/xlib_i965.c +++ /dev/null @@ -1,503 +0,0 @@ -/************************************************************************** - * - * Copyright 2007 Tungsten Graphics, Inc., Bismarck, ND., USA - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL - * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE - * USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * - **************************************************************************/ - -/* - * Authors: - * Keith Whitwell - * Brian Paul - */ - - -#include "util/u_memory.h" -#include "util/u_math.h" -#include "pipe/p_error.h" -#include "pipe/p_context.h" - -#include "xm_public.h" - -#include "i965/brw_winsys.h" -#include "i965/brw_screen.h" -#include "i965/brw_reg.h" -#include "i965/brw_structs_dump.h" - -#define MAX_VRAM (128*1024*1024) - - - -extern int brw_disasm (FILE *file, - const struct brw_instruction *inst, - unsigned count ); - -extern int intel_decode(const uint32_t *data, - int count, - uint32_t hw_offset, - uint32_t devid); - -struct xlib_brw_buffer -{ - struct brw_winsys_buffer base; - char *virtual; - unsigned offset; - unsigned type; - int map_count; - boolean modified; -}; - - -/** - * Subclass of brw_winsys_screen for Xlib winsys - */ -struct xlib_brw_winsys -{ - struct brw_winsys_screen base; - struct brw_chipset chipset; - - unsigned size; - unsigned used; -}; - -static struct xlib_brw_winsys * -xlib_brw_winsys( struct brw_winsys_screen *screen ) -{ - return (struct xlib_brw_winsys *)screen; -} - - -static struct xlib_brw_buffer * -xlib_brw_buffer( struct brw_winsys_buffer *buffer ) -{ - return (struct xlib_brw_buffer *)buffer; -} - - - -const char *names[BRW_BUFFER_TYPE_MAX] = { - "TEXTURE", - "SCANOUT", - "VERTEX", - "CURBE", - "QUERY", - "SHADER_CONSTANTS", - "WM_SCRATCH", - "BATCH", - "GENERAL_STATE", - "SURFACE_STATE", - "PIXEL", - "GENERIC", -}; - -const char *usages[BRW_USAGE_MAX] = { - "STATE", - "QUERY_RESULT", - "RENDER_TARGET", - "DEPTH_BUFFER", - "BLIT_SOURCE", - "BLIT_DEST", - "SAMPLER", - "VERTEX", - "SCRATCH" -}; - - -const char *data_types[BRW_DATA_MAX] = -{ - "GS: CC_VP", - "GS: CC_UNIT", - "GS: WM_PROG", - "GS: SAMPLER_DEFAULT_COLOR", - "GS: SAMPLER", - "GS: WM_UNIT", - "GS: SF_PROG", - "GS: SF_VP", - "GS: SF_UNIT", - "GS: VS_UNIT", - "GS: VS_PROG", - "GS: GS_UNIT", - "GS: GS_PROG", - "GS: CLIP_VP", - "GS: CLIP_UNIT", - "GS: CLIP_PROG", - "SS: SURFACE", - "SS: SURF_BIND", - "CONSTANT DATA", - "BATCH DATA", - "(untyped)" -}; - - -static enum pipe_error -xlib_brw_bo_alloc( struct brw_winsys_screen *sws, - enum brw_buffer_type type, - unsigned size, - unsigned alignment, - struct brw_winsys_buffer **bo_out ) -{ - struct xlib_brw_winsys *xbw = xlib_brw_winsys(sws); - struct xlib_brw_buffer *buf; - - if (BRW_DEBUG & DEBUG_WINSYS) - debug_printf("%s type %s sz %d align %d\n", - __FUNCTION__, names[type], size, alignment ); - - buf = CALLOC_STRUCT(xlib_brw_buffer); - if (!buf) - return PIPE_ERROR_OUT_OF_MEMORY; - - pipe_reference_init(&buf->base.reference, 1); - - buf->offset = align(xbw->used, alignment); - buf->type = type; - buf->virtual = MALLOC(size); - buf->base.size = size; - buf->base.sws = sws; - - xbw->used = align(xbw->used, alignment) + size; - if (xbw->used > MAX_VRAM) - goto err; - - /* XXX: possibly rentrant call to bo_destroy: - */ - bo_reference(bo_out, &buf->base); - return PIPE_OK; - -err: - assert(0); - FREE(buf->virtual); - FREE(buf); - return PIPE_ERROR_OUT_OF_MEMORY; -} - -static void -xlib_brw_bo_destroy( struct brw_winsys_buffer *buffer ) -{ - struct xlib_brw_buffer *buf = xlib_brw_buffer(buffer); - - FREE(buf); -} - -static int -xlib_brw_bo_emit_reloc( struct brw_winsys_buffer *buffer, - enum brw_buffer_usage usage, - unsigned delta, - unsigned offset, - struct brw_winsys_buffer *buffer2) -{ - struct xlib_brw_buffer *buf = xlib_brw_buffer(buffer); - struct xlib_brw_buffer *buf2 = xlib_brw_buffer(buffer2); - - if (BRW_DEBUG & DEBUG_WINSYS) - debug_printf("%s buf %p offset %x val %x + %x buf2 %p/%s/%s\n", - __FUNCTION__, (void *)buffer, offset, - buf2->offset, delta, - (void *)buffer2, names[buf2->type], usages[usage]); - - *(uint32_t *)(buf->virtual + offset) = buf2->offset + delta; - - return 0; -} - -static int -xlib_brw_bo_exec( struct brw_winsys_buffer *buffer, - unsigned bytes_used ) -{ - if (BRW_DEBUG & DEBUG_WINSYS) - debug_printf("execute buffer %p, bytes %d\n", (void *)buffer, bytes_used); - - return 0; -} - - - - -static int -xlib_brw_bo_subdata(struct brw_winsys_buffer *buffer, - enum brw_buffer_data_type data_type, - size_t offset, - size_t size, - const void *data, - const struct brw_winsys_reloc *reloc, - unsigned nr_relocs) -{ - struct xlib_brw_buffer *buf = xlib_brw_buffer(buffer); - struct xlib_brw_winsys *xbw = xlib_brw_winsys(buffer->sws); - unsigned i; - - if (BRW_DEBUG & DEBUG_WINSYS) - debug_printf("%s buf %p off %d sz %d %s relocs: %d\n", - __FUNCTION__, - (void *)buffer, offset, size, - data_types[data_type], - nr_relocs); - - assert(buf->base.size >= offset + size); - memcpy(buf->virtual + offset, data, size); - - /* Apply the relocations: - */ - for (i = 0; i < nr_relocs; i++) { - if (BRW_DEBUG & DEBUG_WINSYS) - debug_printf("\treloc[%d] usage %s off %d value %x+%x\n", - i, usages[reloc[i].usage], reloc[i].offset, - xlib_brw_buffer(reloc[i].bo)->offset, reloc[i].delta); - - *(unsigned *)(buf->virtual + offset + reloc[i].offset) = - xlib_brw_buffer(reloc[i].bo)->offset + reloc[i].delta; - } - - if (BRW_DUMP) - brw_dump_data( xbw->chipset.pci_id, - data_type, - buf->offset + offset, - buf->virtual + offset, size ); - - - return 0; -} - - -static boolean -xlib_brw_bo_is_busy(struct brw_winsys_buffer *buffer) -{ - if (BRW_DEBUG & DEBUG_WINSYS) - debug_printf("%s %p\n", __FUNCTION__, (void *)buffer); - return TRUE; -} - -static boolean -xlib_brw_bo_references(struct brw_winsys_buffer *a, - struct brw_winsys_buffer *b) -{ - if (BRW_DEBUG & DEBUG_WINSYS) - debug_printf("%s %p %p\n", __FUNCTION__, (void *)a, (void *)b); - return TRUE; -} - -static enum pipe_error -xlib_brw_check_aperture_space( struct brw_winsys_screen *iws, - struct brw_winsys_buffer **buffers, - unsigned count ) -{ - unsigned tot_size = 0; - unsigned i; - - for (i = 0; i < count; i++) - tot_size += buffers[i]->size; - - if (BRW_DEBUG & DEBUG_WINSYS) - debug_printf("%s %d bufs, tot_size: %d kb\n", - __FUNCTION__, count, - (tot_size + 1023) / 1024); - - return PIPE_OK; -} - -static void * -xlib_brw_bo_map(struct brw_winsys_buffer *buffer, - enum brw_buffer_data_type data_type, - unsigned offset, - unsigned length, - boolean write, - boolean discard, - boolean explicit) -{ - struct xlib_brw_buffer *buf = xlib_brw_buffer(buffer); - - if (BRW_DEBUG & DEBUG_WINSYS) - debug_printf("%s %p %s %s\n", __FUNCTION__, (void *)buffer, - write ? "read/write" : "read", - write ? data_types[data_type] : ""); - - if (write) - buf->modified = 1; - - buf->map_count++; - return buf->virtual; -} - - -static void -xlib_brw_bo_flush_range( struct brw_winsys_buffer *buffer, - unsigned offset, - unsigned length ) -{ -} - - -static void -xlib_brw_bo_unmap(struct brw_winsys_buffer *buffer) -{ - struct xlib_brw_buffer *buf = xlib_brw_buffer(buffer); - - if (BRW_DEBUG & DEBUG_WINSYS) - debug_printf("%s %p\n", __FUNCTION__, (void *)buffer); - - --buf->map_count; - assert(buf->map_count >= 0); - - if (buf->map_count == 0 && - buf->modified) { - - buf->modified = 0; - - /* Consider dumping new buffer contents here, using the - * flush-range info to minimize verbosity. - */ - } -} - - -static void -xlib_brw_bo_wait_idle( struct brw_winsys_buffer *buffer ) -{ -} - - -static void -xlib_brw_winsys_destroy( struct brw_winsys_screen *sws ) -{ - struct xlib_brw_winsys *xbw = xlib_brw_winsys(sws); - - FREE(xbw); -} - -static struct brw_winsys_screen * -xlib_create_brw_winsys_screen( void ) -{ - struct xlib_brw_winsys *ws; - - ws = CALLOC_STRUCT(xlib_brw_winsys); - if (!ws) - return NULL; - - ws->used = 0; - - ws->base.destroy = xlib_brw_winsys_destroy; - ws->base.bo_alloc = xlib_brw_bo_alloc; - ws->base.bo_destroy = xlib_brw_bo_destroy; - ws->base.bo_emit_reloc = xlib_brw_bo_emit_reloc; - ws->base.bo_exec = xlib_brw_bo_exec; - ws->base.bo_subdata = xlib_brw_bo_subdata; - ws->base.bo_is_busy = xlib_brw_bo_is_busy; - ws->base.bo_references = xlib_brw_bo_references; - ws->base.check_aperture_space = xlib_brw_check_aperture_space; - ws->base.bo_map = xlib_brw_bo_map; - ws->base.bo_flush_range = xlib_brw_bo_flush_range; - ws->base.bo_unmap = xlib_brw_bo_unmap; - ws->base.bo_wait_idle = xlib_brw_bo_wait_idle; - - return &ws->base; -} - - -/*********************************************************************** - * Implementation of Xlib co-state-tracker's winsys interface - */ - -static void -xlib_i965_display_surface(struct xmesa_buffer *xm_buffer, - struct pipe_surface *surf) -{ - struct brw_surface *surface = brw_surface(surf); - struct xlib_brw_buffer *bo = xlib_brw_buffer(surface->bo); - - if (BRW_DEBUG & DEBUG_WINSYS) - debug_printf("%s offset %x+%x sz %dx%d\n", __FUNCTION__, - bo->offset, - surface->draw_offset, - surf->width, - surf->height); -} - -static void -xlib_i965_flush_frontbuffer(struct pipe_screen *screen, - struct pipe_surface *surf, - void *context_private) -{ - xlib_i965_display_surface(NULL, surf); -} - - -static struct pipe_screen * -xlib_create_i965_screen( void ) -{ - struct brw_winsys_screen *winsys; - struct pipe_screen *screen; - - winsys = xlib_create_brw_winsys_screen(); - if (winsys == NULL) - return NULL; - - screen = brw_create_screen(winsys, PCI_CHIP_GM45_GM); - if (screen == NULL) - goto fail; - - xlib_brw_winsys(winsys)->chipset = brw_screen(screen)->chipset; - - screen->flush_frontbuffer = xlib_i965_flush_frontbuffer; - return screen; - -fail: - if (winsys) - winsys->destroy( winsys ); - - return NULL; -} - - - - - -struct xm_driver xlib_i965_driver = -{ - .create_pipe_screen = xlib_create_i965_screen, - .display_surface = xlib_i965_display_surface -}; - - -/* Register this driver at library load: - */ -static void _init( void ) __attribute__((constructor)); -static void _init( void ) -{ - xmesa_set_driver( &xlib_i965_driver ); -} - - - -/*********************************************************************** - * - * Butt-ugly hack to convince the linker not to throw away public GL - * symbols (they are all referenced from getprocaddress, I guess). - */ -extern void (*linker_foo(const unsigned char *procName))(); -extern void (*glXGetProcAddress(const unsigned char *procName))(); - -extern void (*linker_foo(const unsigned char *procName))() -{ - return glXGetProcAddress(procName); -} diff --git a/src/gallium/winsys/drm/intel/Makefile b/src/gallium/winsys/drm/intel/Makefile deleted file mode 100644 index d8feef6824a..00000000000 --- a/src/gallium/winsys/drm/intel/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -# src/gallium/winsys/drm/intel/Makefile -TOP = ../../../../.. -include $(TOP)/configs/current - -SUBDIRS = gem $(GALLIUM_STATE_TRACKERS_DIRS) - -default install clean: - @for dir in $(SUBDIRS) ; do \ - if [ -d $$dir ] ; then \ - (cd $$dir && $(MAKE) $@) || exit 1; \ - fi \ - done diff --git a/src/gallium/winsys/drm/intel/SConscript b/src/gallium/winsys/drm/intel/SConscript deleted file mode 100644 index fdf57eedb94..00000000000 --- a/src/gallium/winsys/drm/intel/SConscript +++ /dev/null @@ -1,3 +0,0 @@ -Import('*') - -SConscript(['gem/SConscript',]) diff --git a/src/gallium/winsys/drm/intel/gem/Makefile b/src/gallium/winsys/drm/intel/gem/Makefile deleted file mode 100644 index 0d6d4e37dbd..00000000000 --- a/src/gallium/winsys/drm/intel/gem/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -TOP = ../../../../../.. -include $(TOP)/configs/current - -LIBNAME = inteldrm - -C_SOURCES = \ - intel_drm_batchbuffer.c \ - intel_drm_buffer.c \ - intel_drm_fence.c \ - intel_drm_api.c - -LIBRARY_INCLUDES = $(shell pkg-config libdrm --cflags-only-I) - -LIBRARY_DEFINES = $(shell pkg-config libdrm --cflags-only-other) - -include ../../../../Makefile.template diff --git a/src/gallium/winsys/drm/intel/gem/SConscript b/src/gallium/winsys/drm/intel/gem/SConscript deleted file mode 100644 index 26717f391fa..00000000000 --- a/src/gallium/winsys/drm/intel/gem/SConscript +++ /dev/null @@ -1,17 +0,0 @@ -Import('*') - -env = drienv.Clone() - -inteldrm_sources = [ - 'intel_drm_api.c', - 'intel_drm_batchbuffer.c', - 'intel_drm_buffer.c', - 'intel_drm_fence.c', -] - -inteldrm = env.ConvenienceLibrary( - target ='inteldrm', - source = inteldrm_sources, -) - -Export('inteldrm') diff --git a/src/gallium/winsys/drm/intel/gem/intel_drm_api.c b/src/gallium/winsys/drm/intel/gem/intel_drm_api.c deleted file mode 100644 index e3b980a832b..00000000000 --- a/src/gallium/winsys/drm/intel/gem/intel_drm_api.c +++ /dev/null @@ -1,109 +0,0 @@ -#include - -#include "state_tracker/drm_api.h" - -#include "intel_drm_winsys.h" -#include "util/u_memory.h" - -#include "i915/i915_context.h" -#include "i915/i915_screen.h" - -#include "trace/tr_drm.h" - -/* - * Helper functions - */ - - -static void -intel_drm_get_device_id(unsigned int *device_id) -{ - char path[512]; - FILE *file; - void *shutup_gcc; - - /* - * FIXME: Fix this up to use a drm ioctl or whatever. - */ - - snprintf(path, sizeof(path), "/sys/class/drm/card0/device/device"); - file = fopen(path, "r"); - if (!file) { - return; - } - - shutup_gcc = fgets(path, sizeof(path), file); - (void) shutup_gcc; - sscanf(path, "%x", device_id); - fclose(file); -} - -static void -intel_drm_winsys_destroy(struct intel_winsys *iws) -{ - struct intel_drm_winsys *idws = intel_drm_winsys(iws); - - drm_intel_bufmgr_destroy(idws->pools.gem); - - FREE(idws); -} - -static struct pipe_screen * -intel_drm_create_screen(struct drm_api *api, int drmFD, - struct drm_create_screen_arg *arg) -{ - struct intel_drm_winsys *idws; - unsigned int deviceID; - - if (arg != NULL) { - switch(arg->mode) { - case DRM_CREATE_NORMAL: - break; - default: - return NULL; - } - } - - idws = CALLOC_STRUCT(intel_drm_winsys); - if (!idws) - return NULL; - - intel_drm_get_device_id(&deviceID); - - intel_drm_winsys_init_batchbuffer_functions(idws); - intel_drm_winsys_init_buffer_functions(idws); - intel_drm_winsys_init_fence_functions(idws); - - idws->fd = drmFD; - idws->id = deviceID; - idws->max_batch_size = 16 * 4096; - - idws->base.destroy = intel_drm_winsys_destroy; - - idws->pools.gem = drm_intel_bufmgr_gem_init(idws->fd, idws->max_batch_size); - drm_intel_bufmgr_gem_enable_reuse(idws->pools.gem); - - idws->dump_cmd = debug_get_bool_option("INTEL_DUMP_CMD", FALSE); - - return i915_create_screen(&idws->base, deviceID); -} - -static void -destroy(struct drm_api *api) -{ - -} - -struct drm_api intel_drm_api = -{ - .name = "i915", - .driver_name = "i915", - .create_screen = intel_drm_create_screen, - .destroy = destroy, -}; - -struct drm_api * -drm_api_create() -{ - return trace_drm_create(&intel_drm_api); -} diff --git a/src/gallium/winsys/drm/intel/gem/intel_drm_batchbuffer.c b/src/gallium/winsys/drm/intel/gem/intel_drm_batchbuffer.c deleted file mode 100644 index 5b4dafc8e41..00000000000 --- a/src/gallium/winsys/drm/intel/gem/intel_drm_batchbuffer.c +++ /dev/null @@ -1,244 +0,0 @@ - -#include "intel_drm_winsys.h" -#include "util/u_memory.h" - -#include "i915_drm.h" - -#define BATCH_RESERVED 16 - -#define INTEL_DEFAULT_RELOCS 100 -#define INTEL_MAX_RELOCS 400 - -#define INTEL_BATCH_NO_CLIPRECTS 0x1 -#define INTEL_BATCH_CLIPRECTS 0x2 - -#undef INTEL_RUN_SYNC -#undef INTEL_MAP_BATCHBUFFER -#undef INTEL_MAP_GTT -#define INTEL_ALWAYS_FLUSH - -struct intel_drm_batchbuffer -{ - struct intel_batchbuffer base; - - size_t actual_size; - - drm_intel_bo *bo; -}; - -static INLINE struct intel_drm_batchbuffer * -intel_drm_batchbuffer(struct intel_batchbuffer *batch) -{ - return (struct intel_drm_batchbuffer *)batch; -} - -static void -intel_drm_batchbuffer_reset(struct intel_drm_batchbuffer *batch) -{ - struct intel_drm_winsys *idws = intel_drm_winsys(batch->base.iws); - int ret; - - if (batch->bo) - drm_intel_bo_unreference(batch->bo); - batch->bo = drm_intel_bo_alloc(idws->pools.gem, - "gallium3d_batchbuffer", - batch->actual_size, - 4096); - -#ifdef INTEL_MAP_BATCHBUFFER -#ifdef INTEL_MAP_GTT - ret = drm_intel_gem_bo_map_gtt(batch->bo); -#else - ret = drm_intel_bo_map(batch->bo, TRUE); -#endif - assert(ret == 0); - batch->base.map = batch->bo->virtual; -#else - (void)ret; -#endif - - memset(batch->base.map, 0, batch->actual_size); - batch->base.ptr = batch->base.map; - batch->base.size = batch->actual_size - BATCH_RESERVED; - batch->base.relocs = 0; -} - -static struct intel_batchbuffer * -intel_drm_batchbuffer_create(struct intel_winsys *iws) -{ - struct intel_drm_winsys *idws = intel_drm_winsys(iws); - struct intel_drm_batchbuffer *batch = CALLOC_STRUCT(intel_drm_batchbuffer); - - batch->actual_size = idws->max_batch_size; - -#ifdef INTEL_MAP_BATCHBUFFER - batch->base.map = NULL; -#else - batch->base.map = MALLOC(batch->actual_size); -#endif - batch->base.ptr = NULL; - batch->base.size = 0; - - batch->base.relocs = 0; - batch->base.max_relocs = 300;/*INTEL_DEFAULT_RELOCS;*/ - - batch->base.iws = iws; - - intel_drm_batchbuffer_reset(batch); - - return &batch->base; -} - -static int -intel_drm_batchbuffer_reloc(struct intel_batchbuffer *ibatch, - struct intel_buffer *buffer, - enum intel_buffer_usage usage, - unsigned pre_add) -{ - struct intel_drm_batchbuffer *batch = intel_drm_batchbuffer(ibatch); - unsigned write_domain = 0; - unsigned read_domain = 0; - unsigned offset; - int ret = 0; - - assert(batch->base.relocs < batch->base.max_relocs); - - if (usage == INTEL_USAGE_SAMPLER) { - write_domain = 0; - read_domain = I915_GEM_DOMAIN_SAMPLER; - - } else if (usage == INTEL_USAGE_RENDER) { - write_domain = I915_GEM_DOMAIN_RENDER; - read_domain = I915_GEM_DOMAIN_RENDER; - - } else if (usage == INTEL_USAGE_2D_TARGET) { - write_domain = I915_GEM_DOMAIN_RENDER; - read_domain = I915_GEM_DOMAIN_RENDER; - - } else if (usage == INTEL_USAGE_2D_SOURCE) { - write_domain = 0; - read_domain = I915_GEM_DOMAIN_RENDER; - - } else if (usage == INTEL_USAGE_VERTEX) { - write_domain = 0; - read_domain = I915_GEM_DOMAIN_VERTEX; - - } else { - assert(0); - return -1; - } - - offset = (unsigned)(batch->base.ptr - batch->base.map); - - ret = drm_intel_bo_emit_reloc(batch->bo, offset, - intel_bo(buffer), pre_add, - read_domain, - write_domain); - - ((uint32_t*)batch->base.ptr)[0] = intel_bo(buffer)->offset + pre_add; - batch->base.ptr += 4; - - if (!ret) - batch->base.relocs++; - - return ret; -} - -static void -intel_drm_batchbuffer_flush(struct intel_batchbuffer *ibatch, - struct pipe_fence_handle **fence) -{ - struct intel_drm_batchbuffer *batch = intel_drm_batchbuffer(ibatch); - unsigned used = 0; - int ret = 0; - int i; - - assert(intel_batchbuffer_space(ibatch) >= 0); - - used = batch->base.ptr - batch->base.map; - assert((used & 3) == 0); - - -#ifdef INTEL_ALWAYS_FLUSH - /* MI_FLUSH | FLUSH_MAP_CACHE */ - intel_batchbuffer_dword(ibatch, (0x4<<23)|(1<<0)); - used += 4; -#endif - - if ((used & 4) == 0) { - /* MI_NOOP */ - intel_batchbuffer_dword(ibatch, 0); - } - /* MI_BATCH_BUFFER_END */ - intel_batchbuffer_dword(ibatch, (0xA<<23)); - - used = batch->base.ptr - batch->base.map; - assert((used & 4) == 0); - -#ifdef INTEL_MAP_BATCHBUFFER -#ifdef INTEL_MAP_GTT - drm_intel_gem_bo_unmap_gtt(batch->bo); -#else - drm_intel_bo_unmap(batch->bo); -#endif -#else - drm_intel_bo_subdata(batch->bo, 0, used, batch->base.map); -#endif - - /* Do the sending to HW */ - ret = drm_intel_bo_exec(batch->bo, used, NULL, 0, 0); - assert(ret == 0); - - if (intel_drm_winsys(ibatch->iws)->dump_cmd) { - unsigned *ptr; - drm_intel_bo_map(batch->bo, FALSE); - ptr = (unsigned*)batch->bo->virtual; - - debug_printf("%s:\n", __func__); - for (i = 0; i < used / 4; i++, ptr++) { - debug_printf("\t%08x: %08x\n", i*4, *ptr); - } - - drm_intel_bo_unmap(batch->bo); - } else { -#ifdef INTEL_RUN_SYNC - drm_intel_bo_map(batch->bo, FALSE); - drm_intel_bo_unmap(batch->bo); -#endif - } - - if (fence) { - ibatch->iws->fence_reference(ibatch->iws, fence, NULL); - -#ifdef INTEL_RUN_SYNC - /* we run synced to GPU so just pass null */ - (*fence) = intel_drm_fence_create(NULL); -#else - (*fence) = intel_drm_fence_create(batch->bo); -#endif - } - - intel_drm_batchbuffer_reset(batch); -} - -static void -intel_drm_batchbuffer_destroy(struct intel_batchbuffer *ibatch) -{ - struct intel_drm_batchbuffer *batch = intel_drm_batchbuffer(ibatch); - - if (batch->bo) - drm_intel_bo_unreference(batch->bo); - -#ifndef INTEL_MAP_BATCHBUFFER - FREE(batch->base.map); -#endif - FREE(batch); -} - -void intel_drm_winsys_init_batchbuffer_functions(struct intel_drm_winsys *idws) -{ - idws->base.batchbuffer_create = intel_drm_batchbuffer_create; - idws->base.batchbuffer_reloc = intel_drm_batchbuffer_reloc; - idws->base.batchbuffer_flush = intel_drm_batchbuffer_flush; - idws->base.batchbuffer_destroy = intel_drm_batchbuffer_destroy; -} diff --git a/src/gallium/winsys/drm/intel/gem/intel_drm_buffer.c b/src/gallium/winsys/drm/intel/gem/intel_drm_buffer.c deleted file mode 100644 index cb4f92a3b17..00000000000 --- a/src/gallium/winsys/drm/intel/gem/intel_drm_buffer.c +++ /dev/null @@ -1,217 +0,0 @@ - -#include "state_tracker/drm_api.h" -#include "intel_drm_winsys.h" -#include "util/u_memory.h" - -#include "i915_drm.h" - -static struct intel_buffer * -intel_drm_buffer_create(struct intel_winsys *iws, - unsigned size, unsigned alignment, - enum intel_buffer_type type) -{ - struct intel_drm_buffer *buf = CALLOC_STRUCT(intel_drm_buffer); - struct intel_drm_winsys *idws = intel_drm_winsys(iws); - drm_intel_bufmgr *pool; - char *name; - - if (!buf) - return NULL; - - buf->magic = 0xDEAD1337; - buf->flinked = FALSE; - buf->flink = 0; - buf->map_gtt = FALSE; - - if (type == INTEL_NEW_TEXTURE) { - name = "gallium3d_texture"; - pool = idws->pools.gem; - } else if (type == INTEL_NEW_VERTEX) { - name = "gallium3d_vertex"; - pool = idws->pools.gem; - buf->map_gtt = TRUE; - } else if (type == INTEL_NEW_SCANOUT) { - name = "gallium3d_scanout"; - pool = idws->pools.gem; - buf->map_gtt = TRUE; - } else { - assert(0); - name = "gallium3d_unknown"; - pool = idws->pools.gem; - } - - buf->bo = drm_intel_bo_alloc(pool, name, size, alignment); - - if (!buf->bo) - goto err; - - return (struct intel_buffer *)buf; - -err: - assert(0); - FREE(buf); - return NULL; -} - -static struct intel_buffer * -intel_drm_buffer_from_handle(struct intel_winsys *iws, - struct winsys_handle *whandle, - unsigned *stride) -{ - struct intel_drm_winsys *idws = intel_drm_winsys(iws); - struct intel_drm_buffer *buf = CALLOC_STRUCT(intel_drm_buffer); - uint32_t tile = 0, swizzle = 0; - - if (!buf) - return NULL; - - buf->magic = 0xDEAD1337; - buf->bo = drm_intel_bo_gem_create_from_name(idws->pools.gem, "gallium3d_from_handle", whandle->handle); - buf->flinked = TRUE; - buf->flink = whandle->handle; - - if (!buf->bo) - goto err; - - drm_intel_bo_get_tiling(buf->bo, &tile, &swizzle); - if (tile != INTEL_TILE_NONE) - buf->map_gtt = TRUE; - - *stride = whandle->stride; - - return (struct intel_buffer *)buf; - -err: - FREE(buf); - return NULL; -} - -static boolean -intel_drm_buffer_get_handle(struct intel_winsys *iws, - struct intel_buffer *buffer, - struct winsys_handle *whandle, - unsigned stride) -{ - struct intel_drm_buffer *buf = intel_drm_buffer(buffer); - - if (whandle->type == DRM_API_HANDLE_TYPE_SHARED) { - if (!buf->flinked) { - if (drm_intel_bo_flink(buf->bo, &buf->flink)) - return FALSE; - buf->flinked = TRUE; - } - - whandle->handle = buf->flink; - } else if (whandle->type == DRM_API_HANDLE_TYPE_KMS) { - whandle->handle = buf->bo->handle; - } else { - assert(!"unknown usage"); - return FALSE; - } - - whandle->stride = stride; - return TRUE; -} - -static int -intel_drm_buffer_set_fence_reg(struct intel_winsys *iws, - struct intel_buffer *buffer, - unsigned stride, - enum intel_buffer_tile tile) -{ - struct intel_drm_buffer *buf = intel_drm_buffer(buffer); - assert(I915_TILING_NONE == INTEL_TILE_NONE); - assert(I915_TILING_X == INTEL_TILE_X); - assert(I915_TILING_Y == INTEL_TILE_Y); - - if (tile != INTEL_TILE_NONE) { - assert(buf->map_count == 0); - buf->map_gtt = TRUE; - } - - return drm_intel_bo_set_tiling(buf->bo, &tile, stride); -} - -static void * -intel_drm_buffer_map(struct intel_winsys *iws, - struct intel_buffer *buffer, - boolean write) -{ - struct intel_drm_buffer *buf = intel_drm_buffer(buffer); - drm_intel_bo *bo = intel_bo(buffer); - int ret = 0; - - assert(bo); - - if (buf->map_count) - goto out; - - if (buf->map_gtt) - ret = drm_intel_gem_bo_map_gtt(bo); - else - ret = drm_intel_bo_map(bo, write); - - buf->ptr = bo->virtual; - - assert(ret == 0); -out: - if (ret) - return NULL; - - buf->map_count++; - return buf->ptr; -} - -static void -intel_drm_buffer_unmap(struct intel_winsys *iws, - struct intel_buffer *buffer) -{ - struct intel_drm_buffer *buf = intel_drm_buffer(buffer); - - if (--buf->map_count) - return; - - if (buf->map_gtt) - drm_intel_gem_bo_unmap_gtt(intel_bo(buffer)); - else - drm_intel_bo_unmap(intel_bo(buffer)); -} - -static int -intel_drm_buffer_write(struct intel_winsys *iws, - struct intel_buffer *buffer, - size_t offset, - size_t size, - const void *data) -{ - struct intel_drm_buffer *buf = intel_drm_buffer(buffer); - - return drm_intel_bo_subdata(buf->bo, offset, size, (void*)data); -} - -static void -intel_drm_buffer_destroy(struct intel_winsys *iws, - struct intel_buffer *buffer) -{ - drm_intel_bo_unreference(intel_bo(buffer)); - -#ifdef DEBUG - intel_drm_buffer(buffer)->magic = 0; - intel_drm_buffer(buffer)->bo = NULL; -#endif - - FREE(buffer); -} - -void -intel_drm_winsys_init_buffer_functions(struct intel_drm_winsys *idws) -{ - idws->base.buffer_create = intel_drm_buffer_create; - idws->base.buffer_from_handle = intel_drm_buffer_from_handle; - idws->base.buffer_get_handle = intel_drm_buffer_get_handle; - idws->base.buffer_set_fence_reg = intel_drm_buffer_set_fence_reg; - idws->base.buffer_map = intel_drm_buffer_map; - idws->base.buffer_unmap = intel_drm_buffer_unmap; - idws->base.buffer_write = intel_drm_buffer_write; - idws->base.buffer_destroy = intel_drm_buffer_destroy; -} diff --git a/src/gallium/winsys/drm/intel/gem/intel_drm_fence.c b/src/gallium/winsys/drm/intel/gem/intel_drm_fence.c deleted file mode 100644 index 102faedfeae..00000000000 --- a/src/gallium/winsys/drm/intel/gem/intel_drm_fence.c +++ /dev/null @@ -1,83 +0,0 @@ - -#include "intel_drm_winsys.h" -#include "util/u_memory.h" -#include "util/u_atomic.h" -#include "util/u_inlines.h" - -/** - * Because gem does not have fence's we have to create our own fences. - * - * They work by keeping the batchbuffer around and checking if that has - * been idled. If bo is NULL fence has expired. - */ -struct intel_drm_fence -{ - struct pipe_reference reference; - drm_intel_bo *bo; -}; - - -struct pipe_fence_handle * -intel_drm_fence_create(drm_intel_bo *bo) -{ - struct intel_drm_fence *fence = CALLOC_STRUCT(intel_drm_fence); - - pipe_reference_init(&fence->reference, 1); - /* bo is null if fence already expired */ - if (bo) { - drm_intel_bo_reference(bo); - fence->bo = bo; - } - - return (struct pipe_fence_handle *)fence; -} - -static void -intel_drm_fence_reference(struct intel_winsys *iws, - struct pipe_fence_handle **ptr, - struct pipe_fence_handle *fence) -{ - struct intel_drm_fence *old = (struct intel_drm_fence *)*ptr; - struct intel_drm_fence *f = (struct intel_drm_fence *)fence; - - if (pipe_reference(&((struct intel_drm_fence *)(*ptr))->reference, &f->reference)) { - if (old->bo) - drm_intel_bo_unreference(old->bo); - FREE(old); - } - *ptr = fence; -} - -static int -intel_drm_fence_signalled(struct intel_winsys *iws, - struct pipe_fence_handle *fence) -{ - assert(0); - - return 0; -} - -static int -intel_drm_fence_finish(struct intel_winsys *iws, - struct pipe_fence_handle *fence) -{ - struct intel_drm_fence *f = (struct intel_drm_fence *)fence; - - /* fence already expired */ - if (!f->bo) - return 0; - - drm_intel_bo_wait_rendering(f->bo); - drm_intel_bo_unreference(f->bo); - f->bo = NULL; - - return 0; -} - -void -intel_drm_winsys_init_fence_functions(struct intel_drm_winsys *idws) -{ - idws->base.fence_reference = intel_drm_fence_reference; - idws->base.fence_signalled = intel_drm_fence_signalled; - idws->base.fence_finish = intel_drm_fence_finish; -} diff --git a/src/gallium/winsys/drm/intel/gem/intel_drm_winsys.h b/src/gallium/winsys/drm/intel/gem/intel_drm_winsys.h deleted file mode 100644 index 9786ee93650..00000000000 --- a/src/gallium/winsys/drm/intel/gem/intel_drm_winsys.h +++ /dev/null @@ -1,77 +0,0 @@ - -#ifndef INTEL_DRM_WINSYS_H -#define INTEL_DRM_WINSYS_H - -#include "i915/intel_batchbuffer.h" - -#include "drm.h" -#include "intel_bufmgr.h" - - -/* - * Winsys - */ - - -struct intel_drm_winsys -{ - struct intel_winsys base; - - boolean dump_cmd; - - int fd; /**< Drm file discriptor */ - - unsigned id; - - size_t max_batch_size; - - struct { - drm_intel_bufmgr *gem; - } pools; -}; - -static INLINE struct intel_drm_winsys * -intel_drm_winsys(struct intel_winsys *iws) -{ - return (struct intel_drm_winsys *)iws; -} - -struct intel_drm_winsys * intel_drm_winsys_create(int fd, unsigned pci_id); -struct pipe_fence_handle * intel_drm_fence_create(drm_intel_bo *bo); - -void intel_drm_winsys_init_batchbuffer_functions(struct intel_drm_winsys *idws); -void intel_drm_winsys_init_buffer_functions(struct intel_drm_winsys *idws); -void intel_drm_winsys_init_fence_functions(struct intel_drm_winsys *idws); - - -/* - * Buffer - */ - - -struct intel_drm_buffer { - unsigned magic; - - drm_intel_bo *bo; - - void *ptr; - unsigned map_count; - boolean map_gtt; - - boolean flinked; - unsigned flink; -}; - -static INLINE struct intel_drm_buffer * -intel_drm_buffer(struct intel_buffer *buffer) -{ - return (struct intel_drm_buffer *)buffer; -} - -static INLINE drm_intel_bo * -intel_bo(struct intel_buffer *buffer) -{ - return intel_drm_buffer(buffer)->bo; -} - -#endif diff --git a/src/gallium/winsys/drm/nouveau/Makefile b/src/gallium/winsys/drm/nouveau/Makefile deleted file mode 100644 index 6c9cbef26df..00000000000 --- a/src/gallium/winsys/drm/nouveau/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -# src/gallium/winsys/drm/nouveau/Makefile -TOP = ../../../../.. -include $(TOP)/configs/current - -SUBDIRS = drm $(GALLIUM_STATE_TRACKERS_DIRS) - -default install clean: - @for dir in $(SUBDIRS) ; do \ - if [ -d $$dir ] ; then \ - (cd $$dir && $(MAKE) $@) || exit 1; \ - fi \ - done diff --git a/src/gallium/winsys/drm/nouveau/drm/Makefile b/src/gallium/winsys/drm/nouveau/drm/Makefile deleted file mode 100644 index 54c3b26c755..00000000000 --- a/src/gallium/winsys/drm/nouveau/drm/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -TOP = ../../../../../.. -include $(TOP)/configs/current - -LIBNAME = nouveaudrm - -C_SOURCES = nouveau_drm_api.c - -LIBRARY_INCLUDES = $(shell pkg-config libdrm libdrm_nouveau --cflags-only-I) -LIBRARY_DEFINES = $(shell pkg-config libdrm libdrm_nouveau --cflags-only-other) - -include ../../../../Makefile.template diff --git a/src/gallium/winsys/drm/nouveau/drm/nouveau_dri.h b/src/gallium/winsys/drm/nouveau/drm/nouveau_dri.h deleted file mode 100644 index 1207c2d609c..00000000000 --- a/src/gallium/winsys/drm/nouveau/drm/nouveau_dri.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef _NOUVEAU_DRI_ -#define _NOUVEAU_DRI_ - -#include "xf86drm.h" -#include "drm.h" -#include "nouveau_drm.h" - -struct nouveau_dri { - uint32_t device_id; /**< \brief PCI device ID */ - uint32_t width; /**< \brief width in pixels of display */ - uint32_t height; /**< \brief height in scanlines of display */ - uint32_t depth; /**< \brief depth of display (8, 15, 16, 24) */ - uint32_t bpp; /**< \brief bit depth of display (8, 16, 24, 32) */ - - uint32_t bus_type; /**< \brief ths bus type */ - uint32_t bus_mode; /**< \brief bus mode (used for AGP, maybe also for PCI-E ?) */ - - uint32_t front_offset; /**< \brief front buffer offset */ - uint32_t front_pitch; /**< \brief front buffer pitch */ - uint32_t back_offset; /**< \brief private back buffer offset */ - uint32_t back_pitch; /**< \brief private back buffer pitch */ - uint32_t depth_offset; /**< \brief private depth buffer offset */ - uint32_t depth_pitch; /**< \brief private depth buffer pitch */ - -}; - -#endif - diff --git a/src/gallium/winsys/drm/nouveau/drm/nouveau_drm_api.c b/src/gallium/winsys/drm/nouveau/drm/nouveau_drm_api.c deleted file mode 100644 index 716d4bacd3b..00000000000 --- a/src/gallium/winsys/drm/nouveau/drm/nouveau_drm_api.c +++ /dev/null @@ -1,157 +0,0 @@ -#include "pipe/p_context.h" -#include "pipe/p_state.h" -#include "util/u_format.h" -#include "util/u_memory.h" -#include "util/u_inlines.h" - -#include "nouveau_drm_api.h" - -#include "nouveau_drmif.h" -#include "nouveau_channel.h" -#include "nouveau_bo.h" - -#include "nouveau/nouveau_winsys.h" -#include "nouveau/nouveau_screen.h" - -static struct pipe_surface * -dri_surface_from_handle(struct drm_api *api, struct pipe_screen *pscreen, - unsigned handle, enum pipe_format format, - unsigned width, unsigned height, unsigned pitch) -{ - struct pipe_surface *ps = NULL; - struct pipe_texture *pt = NULL; - struct pipe_texture tmpl; - struct winsys_handle whandle; - - memset(&tmpl, 0, sizeof(tmpl)); - tmpl.tex_usage = PIPE_TEXTURE_USAGE_SCANOUT; - tmpl.target = PIPE_TEXTURE_2D; - tmpl.last_level = 0; - tmpl.depth0 = 1; - tmpl.format = format; - tmpl.width0 = width; - tmpl.height0 = height; - - memset(&whandle, 0, sizeof(whandle)); - whandle.stride = pitch; - whandle.handle = handle; - - pt = pscreen->texture_from_handle(pscreen, &tmpl, &whandle); - if (!pt) - return NULL; - - ps = pscreen->get_tex_surface(pscreen, pt, 0, 0, 0, - PIPE_BUFFER_USAGE_GPU_READ | - PIPE_BUFFER_USAGE_GPU_WRITE); - - /* we don't need the texture from this point on */ - pipe_texture_reference(&pt, NULL); - return ps; -} - -static struct pipe_surface * -nouveau_dri1_front_surface(struct pipe_context *pipe) -{ - return nouveau_winsys_screen(pipe->screen)->front; -} - -static struct dri1_api nouveau_dri1_api = { - nouveau_dri1_front_surface, -}; - -static void -nouveau_drm_destroy_winsys(struct pipe_winsys *s) -{ - struct nouveau_winsys *nv_winsys = nouveau_winsys(s); - struct nouveau_screen *nv_screen= nouveau_screen(nv_winsys->pscreen); - nouveau_device_close(&nv_screen->device); - FREE(nv_winsys); -} - -static struct pipe_screen * -nouveau_drm_create_screen(struct drm_api *api, int fd, - struct drm_create_screen_arg *arg) -{ - struct dri1_create_screen_arg *dri1 = (void *)arg; - struct nouveau_winsys *nvws; - struct pipe_winsys *ws; - struct nouveau_device *dev = NULL; - struct pipe_screen *(*init)(struct pipe_winsys *, - struct nouveau_device *); - int ret; - - ret = nouveau_device_open_existing(&dev, 0, fd, 0); - if (ret) - return NULL; - - switch (dev->chipset & 0xf0) { - case 0x30: - case 0x40: - case 0x60: - init = nvfx_screen_create; - break; - case 0x50: - case 0x80: - case 0x90: - case 0xa0: - init = nv50_screen_create; - break; - default: - debug_printf("%s: unknown chipset nv%02x\n", __func__, - dev->chipset); - return NULL; - } - - nvws = CALLOC_STRUCT(nouveau_winsys); - if (!nvws) { - nouveau_device_close(&dev); - return NULL; - } - ws = &nvws->base; - ws->destroy = nouveau_drm_destroy_winsys; - - nvws->pscreen = init(ws, dev); - if (!nvws->pscreen) { - ws->destroy(ws); - return NULL; - } - - if (arg && arg->mode == DRM_CREATE_DRI1) { - struct nouveau_dri *nvdri = dri1->ddx_info; - enum pipe_format format; - - if (nvdri->bpp == 16) - format = PIPE_FORMAT_B5G6R5_UNORM; - else - format = PIPE_FORMAT_B8G8R8A8_UNORM; - - nvws->front = dri_surface_from_handle(api, nvws->pscreen, - nvdri->front_offset, - format, nvdri->width, - nvdri->height, - nvdri->front_pitch * - (nvdri->bpp / 8)); - if (!nvws->front) { - debug_printf("%s: error referencing front buffer\n", - __func__); - ws->destroy(ws); - return NULL; - } - - dri1->api = &nouveau_dri1_api; - } - - return nvws->pscreen; -} - -struct drm_api drm_api_hooks = { - .name = "nouveau", - .driver_name = "nouveau", - .create_screen = nouveau_drm_create_screen, -}; - -struct drm_api * -drm_api_create() { - return &drm_api_hooks; -} - diff --git a/src/gallium/winsys/drm/nouveau/drm/nouveau_drm_api.h b/src/gallium/winsys/drm/nouveau/drm/nouveau_drm_api.h deleted file mode 100644 index a91aad7df8e..00000000000 --- a/src/gallium/winsys/drm/nouveau/drm/nouveau_drm_api.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef __NOUVEAU_DRM_API_H__ -#define __NOUVEAU_DRM_API_H__ - -#include "state_tracker/drm_api.h" -#include "state_tracker/dri1_api.h" - -#include "util/u_simple_screen.h" - -#include "nouveau_dri.h" - -struct nouveau_winsys { - struct pipe_winsys base; - - struct pipe_screen *pscreen; - - struct pipe_surface *front; -}; - -static INLINE struct nouveau_winsys * -nouveau_winsys(struct pipe_winsys *ws) -{ - return (struct nouveau_winsys *)ws; -} - -static INLINE struct nouveau_winsys * -nouveau_winsys_screen(struct pipe_screen *pscreen) -{ - return nouveau_winsys(pscreen->winsys); -} - -#endif diff --git a/src/gallium/winsys/drm/radeon/Makefile b/src/gallium/winsys/drm/radeon/Makefile deleted file mode 100644 index bacdf3de28a..00000000000 --- a/src/gallium/winsys/drm/radeon/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -# src/gallium/winsys/drm/radeon/Makefile -TOP = ../../../../.. -include $(TOP)/configs/current - -SUBDIRS = core $(GALLIUM_STATE_TRACKERS_DIRS) - -default install clean: - @for dir in $(SUBDIRS) ; do \ - if [ -d $$dir ] ; then \ - (cd $$dir && $(MAKE) $@) || exit 1; \ - fi \ - done diff --git a/src/gallium/winsys/drm/radeon/SConscript b/src/gallium/winsys/drm/radeon/SConscript deleted file mode 100644 index eff87e7d010..00000000000 --- a/src/gallium/winsys/drm/radeon/SConscript +++ /dev/null @@ -1,3 +0,0 @@ -Import('*') - -SConscript(['core/SConscript',]) diff --git a/src/gallium/winsys/drm/radeon/core/Makefile b/src/gallium/winsys/drm/radeon/core/Makefile deleted file mode 100644 index 13bbbf730d6..00000000000 --- a/src/gallium/winsys/drm/radeon/core/Makefile +++ /dev/null @@ -1,17 +0,0 @@ - -TOP = ../../../../../.. -include $(TOP)/configs/current - -LIBNAME = radeonwinsys - -C_SOURCES = \ - radeon_drm_buffer.c \ - radeon_drm.c \ - radeon_r300.c - -LIBRARY_INCLUDES = -I$(TOP)/src/gallium/drivers/r300 \ - $(shell pkg-config libdrm --cflags-only-I) - -include ../../../../Makefile.template - -symlinks: diff --git a/src/gallium/winsys/drm/radeon/core/SConscript b/src/gallium/winsys/drm/radeon/core/SConscript deleted file mode 100644 index f4e9c397bdf..00000000000 --- a/src/gallium/winsys/drm/radeon/core/SConscript +++ /dev/null @@ -1,18 +0,0 @@ -Import('*') - -env = drienv.Clone() - -radeon_sources = [ - 'radeon_buffer.c', - 'radeon_drm.c', - 'radeon_r300.c', -] - -env.Append(CPPPATH = '#/src/gallium/drivers/r300') - -radeonwinsys = env.ConvenienceLibrary( - target ='radeonwinsys', - source = radeon_sources, -) - -Export('radeonwinsys') diff --git a/src/gallium/winsys/drm/radeon/core/radeon_buffer.h b/src/gallium/winsys/drm/radeon/core/radeon_buffer.h deleted file mode 100644 index 218a3763018..00000000000 --- a/src/gallium/winsys/drm/radeon/core/radeon_buffer.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright © 2008 Jérôme Glisse - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS - * AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE - * USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - */ -/* - * Authors: - * Jérôme Glisse - */ -#ifndef RADEON_BUFFER_H -#define RADEON_BUFFER_H - -#include - -#include "pipe/p_defines.h" -#include "util/u_inlines.h" - -#include "pipebuffer/pb_buffer.h" -#include "pipebuffer/pb_bufmgr.h" - -#include "radeon_bo.h" -#include "radeon_cs.h" - -#include "radeon_winsys.h" - - -#define RADEON_MAX_BOS 24 - -static INLINE struct pb_buffer * -radeon_pb_buffer(struct r300_winsys_buffer *buffer) -{ - return (struct pb_buffer *)buffer; -} - -static INLINE struct r300_winsys_buffer * -radeon_libdrm_winsys_buffer(struct pb_buffer *buffer) -{ - return (struct r300_winsys_buffer *)buffer; -} - -struct pb_manager * -radeon_drm_bufmgr_create(struct radeon_libdrm_winsys *rws); - -boolean radeon_drm_bufmgr_add_buffer(struct pb_buffer *_buf, - uint32_t rd, uint32_t wd); - - -void radeon_drm_bufmgr_write_reloc(struct pb_buffer *_buf, - uint32_t rd, uint32_t wd, - uint32_t flags); - -struct pb_buffer *radeon_drm_bufmgr_create_buffer_from_handle(struct pb_manager *_mgr, - uint32_t handle); - -void radeon_drm_bufmgr_set_tiling(struct pb_buffer *_buf, - enum r300_buffer_tiling microtiled, - enum r300_buffer_tiling macrotiled, - uint32_t pitch); - -void radeon_drm_bufmgr_flush_maps(struct pb_manager *_mgr); - -boolean radeon_drm_bufmgr_get_handle(struct pb_buffer *_buf, - struct winsys_handle *whandle); - -boolean radeon_drm_bufmgr_is_buffer_referenced(struct pb_buffer *_buf); -#endif diff --git a/src/gallium/winsys/drm/radeon/core/radeon_drm.c b/src/gallium/winsys/drm/radeon/core/radeon_drm.c deleted file mode 100644 index 3dfcc5aef07..00000000000 --- a/src/gallium/winsys/drm/radeon/core/radeon_drm.c +++ /dev/null @@ -1,200 +0,0 @@ -/* - * Copyright © 2009 Corbin Simpson - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS - * AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE - * USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - */ -/* - * Authors: - * Corbin Simpson - * Joakim Sindholt - */ - -#include "radeon_drm.h" -#include "radeon_r300.h" -#include "radeon_buffer.h" - -#include "r300_winsys.h" -#include "trace/tr_drm.h" - -#include "util/u_memory.h" - -#include "xf86drm.h" -#include - -static struct radeon_libdrm_winsys * -radeon_winsys_create(int fd) -{ - struct radeon_libdrm_winsys *rws; - - rws = CALLOC_STRUCT(radeon_libdrm_winsys); - if (rws == NULL) { - return NULL; - } - - rws->fd = fd; - return rws; -} - -/* Helper function to do the ioctls needed for setup and init. */ -static void do_ioctls(int fd, struct radeon_libdrm_winsys* winsys) -{ - struct drm_radeon_gem_info gem_info = {0}; - struct drm_radeon_info info = {0}; - int target = 0; - int retval; - drmVersionPtr version; - - info.value = (unsigned long)⌖ - - /* We do things in a specific order here. - * - * DRM version first. We need to be sure we're running on a KMS chipset. - * This is also for some features. - * - * Then, the PCI ID. This is essential and should return usable numbers - * for all Radeons. If this fails, we probably got handed an FD for some - * non-Radeon card. - * - * The GB and Z pipe requests should always succeed, but they might not - * return sensical values for all chipsets, but that's alright because - * the pipe drivers already know that. - * - * The GEM info is actually bogus on the kernel side, as well as our side - * (see radeon_gem_info_ioctl in radeon_gem.c) but that's alright because - * we don't actually use the info for anything yet. */ - - version = drmGetVersion(fd); - if (version->version_major != 2) { - fprintf(stderr, "%s: DRM version is %d.%d.%d but this driver is " - "only compatible with 2.x.x\n", __FUNCTION__, - version->version_major, version->version_minor, - version->version_patchlevel); - drmFreeVersion(version); - exit(1); - } - -/* XXX Remove this ifdef when libdrm version 2.4.19 becomes mandatory. */ -#ifdef RADEON_BO_FLAGS_MICRO_TILE_SQUARE - // Supported since 2.1.0. - winsys->squaretiling = version->version_major > 2 || - version->version_minor >= 1; -#endif - - info.request = RADEON_INFO_DEVICE_ID; - retval = drmCommandWriteRead(fd, DRM_RADEON_INFO, &info, sizeof(info)); - if (retval) { - fprintf(stderr, "%s: Failed to get PCI ID, " - "error number %d\n", __FUNCTION__, retval); - exit(1); - } - winsys->pci_id = target; - - info.request = RADEON_INFO_NUM_GB_PIPES; - retval = drmCommandWriteRead(fd, DRM_RADEON_INFO, &info, sizeof(info)); - if (retval) { - fprintf(stderr, "%s: Failed to get GB pipe count, " - "error number %d\n", __FUNCTION__, retval); - exit(1); - } - winsys->gb_pipes = target; - - info.request = RADEON_INFO_NUM_Z_PIPES; - retval = drmCommandWriteRead(fd, DRM_RADEON_INFO, &info, sizeof(info)); - if (retval) { - fprintf(stderr, "%s: Failed to get Z pipe count, " - "error number %d\n", __FUNCTION__, retval); - exit(1); - } - winsys->z_pipes = target; - - retval = drmCommandWriteRead(fd, DRM_RADEON_GEM_INFO, - &gem_info, sizeof(gem_info)); - if (retval) { - fprintf(stderr, "%s: Failed to get MM info, error number %d\n", - __FUNCTION__, retval); - exit(1); - } - winsys->gart_size = gem_info.gart_size; - winsys->vram_size = gem_info.vram_size; - - debug_printf("radeon: Successfully grabbed chipset info from kernel!\n" - "radeon: DRM version: %d.%d.%d ID: 0x%04x GB: %d Z: %d\n" - "radeon: GART size: %d MB VRAM size: %d MB\n", - version->version_major, version->version_minor, - version->version_patchlevel, winsys->pci_id, - winsys->gb_pipes, winsys->z_pipes, - winsys->gart_size / 1024 / 1024, - winsys->vram_size / 1024 / 1024); - - drmFreeVersion(version); -} - -/* Create a pipe_screen. */ -struct pipe_screen* radeon_create_screen(struct drm_api* api, - int drmFB, - struct drm_create_screen_arg *arg) -{ - struct radeon_libdrm_winsys* rws; - boolean ret; - - rws = radeon_winsys_create(drmFB); - if (!rws) - return NULL; - - do_ioctls(drmFB, rws); - - /* The state tracker can organize a softpipe fallback if no hw - * driver is found. - */ - if (is_r3xx(rws->pci_id)) { - ret = radeon_setup_winsys(drmFB, rws); - if (ret == FALSE) - goto fail; - return r300_create_screen(&rws->base); - } - -fail: - FREE(rws); - return NULL; -} - -static void radeon_drm_api_destroy(struct drm_api *api) -{ - return; -} - -struct drm_api drm_api_hooks = { - .name = "radeon", - .driver_name = "radeon", - .create_screen = radeon_create_screen, - .destroy = radeon_drm_api_destroy, -}; - -struct drm_api* drm_api_create() -{ -#ifdef DEBUG - return trace_drm_create(&drm_api_hooks); -#else - return &drm_api_hooks; -#endif -} diff --git a/src/gallium/winsys/drm/radeon/core/radeon_drm.h b/src/gallium/winsys/drm/radeon/core/radeon_drm.h deleted file mode 100644 index 2dc077c0521..00000000000 --- a/src/gallium/winsys/drm/radeon/core/radeon_drm.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright © 2009 Corbin Simpson - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS - * AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE - * USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - */ -/* - * Authors: - * Corbin Simpson - */ -#ifndef RADEON_DRM_H -#define RADEON_DRM_H - -#include "state_tracker/drm_api.h" - - -struct pipe_screen* radeon_create_screen(struct drm_api* api, - int drmFB, - struct drm_create_screen_arg *arg); - -boolean radeon_buffer_from_texture(struct drm_api* api, - struct pipe_screen* screen, - struct pipe_texture* texture, - struct pipe_buffer** buffer, - unsigned* stride); - -boolean radeon_handle_from_buffer(struct drm_api* api, - struct pipe_screen* screen, - struct pipe_buffer* buffer, - unsigned* handle); - -boolean radeon_global_handle_from_buffer(struct drm_api* api, - struct pipe_screen* screen, - struct pipe_buffer* buffer, - unsigned* handle); - -void radeon_destroy_drm_api(struct drm_api* api); - -/* Guess at whether this chipset should use r300g. - * - * I believe that this check is valid, but I haven't been exhaustive. */ -static INLINE boolean is_r3xx(int pciid) -{ - return (pciid > 0x3150) && (pciid < 0x796f); -} - -#endif diff --git a/src/gallium/winsys/drm/radeon/core/radeon_drm_buffer.c b/src/gallium/winsys/drm/radeon/core/radeon_drm_buffer.c deleted file mode 100644 index 66f61322457..00000000000 --- a/src/gallium/winsys/drm/radeon/core/radeon_drm_buffer.c +++ /dev/null @@ -1,385 +0,0 @@ - -#include -#include "radeon_drm.h" -#include "radeon_bo_gem.h" -#include "radeon_cs_gem.h" -#include "radeon_buffer.h" - -#include "util/u_inlines.h" -#include "util/u_memory.h" -#include "util/u_simple_list.h" -#include "pipebuffer/pb_buffer.h" -#include "pipebuffer/pb_bufmgr.h" - -#include "radeon_winsys.h" -struct radeon_drm_bufmgr; - -struct radeon_drm_buffer { - struct pb_buffer base; - struct radeon_drm_bufmgr *mgr; - - struct radeon_bo *bo; - - boolean flinked; - uint32_t flink; - - struct radeon_drm_buffer *next, *prev; -}; - -extern const struct pb_vtbl radeon_drm_buffer_vtbl; - - -static INLINE struct radeon_drm_buffer * -radeon_drm_buffer(struct pb_buffer *buf) -{ - assert(buf); - assert(buf->vtbl == &radeon_drm_buffer_vtbl); - return (struct radeon_drm_buffer *)buf; -} - -struct radeon_drm_bufmgr { - struct pb_manager base; - struct radeon_libdrm_winsys *rws; - struct radeon_drm_buffer buffer_map_list; -}; - -static INLINE struct radeon_drm_bufmgr * -radeon_drm_bufmgr(struct pb_manager *mgr) -{ - assert(mgr); - return (struct radeon_drm_bufmgr *)mgr; -} - -static void -radeon_drm_buffer_destroy(struct pb_buffer *_buf) -{ - struct radeon_drm_buffer *buf = radeon_drm_buffer(_buf); - - if (buf->bo->ptr != NULL) { - remove_from_list(buf); - radeon_bo_unmap(buf->bo); - buf->bo->ptr = NULL; - } - radeon_bo_unref(buf->bo); - - FREE(buf); -} - -static void * -radeon_drm_buffer_map(struct pb_buffer *_buf, - unsigned flags) -{ - struct radeon_drm_buffer *buf = radeon_drm_buffer(_buf); - int write = 0; - - if (flags & PIPE_BUFFER_USAGE_DONTBLOCK) { - if ((_buf->base.usage & PIPE_BUFFER_USAGE_VERTEX) || - (_buf->base.usage & PIPE_BUFFER_USAGE_INDEX)) - if (radeon_bo_is_referenced_by_cs(buf->bo, buf->mgr->rws->cs)) - return NULL; - } - - if (buf->bo->ptr != NULL) - return buf->bo->ptr; - - if (flags & PIPE_BUFFER_USAGE_DONTBLOCK) { - uint32_t domain; - if (radeon_bo_is_busy(buf->bo, &domain)) - return NULL; - } - - if (radeon_bo_is_referenced_by_cs(buf->bo, buf->mgr->rws->cs)) { - buf->mgr->rws->flush_cb(buf->mgr->rws->flush_data); - } - - if (flags & PIPE_BUFFER_USAGE_CPU_WRITE) { - write = 1; - } - - if (radeon_bo_map(buf->bo, write)) { - return NULL; - } - insert_at_tail(&buf->mgr->buffer_map_list, buf); - return buf->bo->ptr; -} - -static void -radeon_drm_buffer_unmap(struct pb_buffer *_buf) -{ - (void)_buf; -} - -static void -radeon_drm_buffer_get_base_buffer(struct pb_buffer *buf, - struct pb_buffer **base_buf, - unsigned *offset) -{ - *base_buf = buf; - *offset = 0; -} - - -static enum pipe_error -radeon_drm_buffer_validate(struct pb_buffer *_buf, - struct pb_validate *vl, - unsigned flags) -{ - /* Always pinned */ - return PIPE_OK; -} - -static void -radeon_drm_buffer_fence(struct pb_buffer *buf, - struct pipe_fence_handle *fence) -{ -} - -const struct pb_vtbl radeon_drm_buffer_vtbl = { - radeon_drm_buffer_destroy, - radeon_drm_buffer_map, - radeon_drm_buffer_unmap, - radeon_drm_buffer_validate, - radeon_drm_buffer_fence, - radeon_drm_buffer_get_base_buffer, -}; - - -static uint32_t radeon_domain_from_usage(unsigned usage) -{ - uint32_t domain = 0; - - if (usage & PIPE_BUFFER_USAGE_GPU_WRITE) { - domain |= RADEON_GEM_DOMAIN_VRAM; - } - if (usage & PIPE_BUFFER_USAGE_PIXEL) { - domain |= RADEON_GEM_DOMAIN_VRAM; - } - if (usage & PIPE_BUFFER_USAGE_VERTEX) { - domain |= RADEON_GEM_DOMAIN_GTT; - } - if (usage & PIPE_BUFFER_USAGE_INDEX) { - domain |= RADEON_GEM_DOMAIN_GTT; - } - - return domain; -} - -struct pb_buffer *radeon_drm_bufmgr_create_buffer_from_handle(struct pb_manager *_mgr, - uint32_t handle) -{ - struct radeon_drm_bufmgr *mgr = radeon_drm_bufmgr(_mgr); - struct radeon_libdrm_winsys *rws = mgr->rws; - struct radeon_drm_buffer *buf; - struct radeon_bo *bo; - - bo = radeon_bo_open(rws->bom, handle, 0, - 0, 0, 0); - if (bo == NULL) - return NULL; - - buf = CALLOC_STRUCT(radeon_drm_buffer); - if (!buf) { - radeon_bo_unref(bo); - return NULL; - } - - make_empty_list(buf); - - pipe_reference_init(&buf->base.base.reference, 1); - buf->base.base.alignment = 0; - buf->base.base.usage = PIPE_BUFFER_USAGE_PIXEL; - buf->base.base.size = 0; - buf->base.vtbl = &radeon_drm_buffer_vtbl; - buf->mgr = mgr; - - buf->bo = bo; - - return &buf->base; -} - -static struct pb_buffer * -radeon_drm_bufmgr_create_buffer(struct pb_manager *_mgr, - pb_size size, - const struct pb_desc *desc) -{ - struct radeon_drm_bufmgr *mgr = radeon_drm_bufmgr(_mgr); - struct radeon_libdrm_winsys *rws = mgr->rws; - struct radeon_drm_buffer *buf; - uint32_t domain; - - buf = CALLOC_STRUCT(radeon_drm_buffer); - if (!buf) - goto error1; - - pipe_reference_init(&buf->base.base.reference, 1); - buf->base.base.alignment = desc->alignment; - buf->base.base.usage = desc->usage; - buf->base.base.size = size; - buf->base.vtbl = &radeon_drm_buffer_vtbl; - buf->mgr = mgr; - - make_empty_list(buf); - domain = radeon_domain_from_usage(desc->usage); - buf->bo = radeon_bo_open(rws->bom, 0, size, - desc->alignment, domain, 0); - if (buf->bo == NULL) - goto error2; - - return &buf->base; - - error2: - FREE(buf); - error1: - return NULL; -} - -static void -radeon_drm_bufmgr_flush(struct pb_manager *mgr) -{ - /* NOP */ -} - -static void -radeon_drm_bufmgr_destroy(struct pb_manager *_mgr) -{ - struct radeon_drm_bufmgr *mgr = radeon_drm_bufmgr(_mgr); - FREE(mgr); -} - -struct pb_manager * -radeon_drm_bufmgr_create(struct radeon_libdrm_winsys *rws) -{ - struct radeon_drm_bufmgr *mgr; - - mgr = CALLOC_STRUCT(radeon_drm_bufmgr); - if (!mgr) - return NULL; - - mgr->base.destroy = radeon_drm_bufmgr_destroy; - mgr->base.create_buffer = radeon_drm_bufmgr_create_buffer; - mgr->base.flush = radeon_drm_bufmgr_flush; - - mgr->rws = rws; - make_empty_list(&mgr->buffer_map_list); - return &mgr->base; -} - -static struct radeon_drm_buffer *get_drm_buffer(struct pb_buffer *_buf) -{ - struct radeon_drm_buffer *buf; - if (_buf->vtbl == &radeon_drm_buffer_vtbl) { - buf = radeon_drm_buffer(_buf); - } else { - struct pb_buffer *base_buf; - pb_size offset; - pb_get_base_buffer(_buf, &base_buf, &offset); - - buf = radeon_drm_buffer(base_buf); - } - return buf; -} - -boolean radeon_drm_bufmgr_get_handle(struct pb_buffer *_buf, - struct winsys_handle *whandle) -{ - int retval, fd; - struct drm_gem_flink flink; - struct radeon_drm_buffer *buf = get_drm_buffer(_buf); - if (whandle->type == DRM_API_HANDLE_TYPE_SHARED) { - if (!buf->flinked) { - fd = buf->mgr->rws->fd; - flink.handle = buf->bo->handle; - - retval = ioctl(fd, DRM_IOCTL_GEM_FLINK, &flink); - if (retval) { - return FALSE; - } - - buf->flinked = TRUE; - buf->flink = flink.name; - } - whandle->handle = buf->flink; - } else if (whandle->type == DRM_API_HANDLE_TYPE_KMS) { - whandle->handle = buf->bo->handle; - } - return TRUE; -} - - -void radeon_drm_bufmgr_set_tiling(struct pb_buffer *_buf, - enum r300_buffer_tiling microtiled, - enum r300_buffer_tiling macrotiled, - uint32_t pitch) -{ - struct radeon_drm_buffer *buf = get_drm_buffer(_buf); - uint32_t flags = 0, old_flags, old_pitch; - if (microtiled == R300_BUFFER_TILED) - flags |= RADEON_BO_FLAGS_MICRO_TILE; -/* XXX Remove this ifdef when libdrm version 2.4.19 becomes mandatory. */ -#ifdef RADEON_BO_FLAGS_MICRO_TILE_SQUARE - else if (microtiled == R300_BUFFER_SQUARETILED) - flags |= RADEON_BO_FLAGS_MICRO_TILE_SQUARE; -#endif - if (macrotiled == R300_BUFFER_TILED) - flags |= RADEON_BO_FLAGS_MACRO_TILE; - - radeon_bo_get_tiling(buf->bo, &old_flags, &old_pitch); - - if (flags != old_flags || pitch != old_pitch) { - /* Tiling determines how DRM treats the buffer data. - * We must flush CS when changing it if the buffer is referenced. */ - if (radeon_bo_is_referenced_by_cs(buf->bo, buf->mgr->rws->cs)) { - buf->mgr->rws->flush_cb(buf->mgr->rws->flush_data); - } - } - radeon_bo_set_tiling(buf->bo, flags, pitch); - -} - -boolean radeon_drm_bufmgr_add_buffer(struct pb_buffer *_buf, - uint32_t rd, uint32_t wd) -{ - struct radeon_drm_buffer *buf = get_drm_buffer(_buf); - radeon_cs_space_add_persistent_bo(buf->mgr->rws->cs, buf->bo, - rd, wd); - return TRUE; -} - -void radeon_drm_bufmgr_write_reloc(struct pb_buffer *_buf, - uint32_t rd, uint32_t wd, - uint32_t flags) -{ - struct radeon_drm_buffer *buf = get_drm_buffer(_buf); - int retval; - - retval = radeon_cs_write_reloc(buf->mgr->rws->cs, - buf->bo, rd, wd, flags); - if (retval) { - debug_printf("radeon: Relocation of %p (%d, %d, %d) failed!\n", - buf, rd, wd, flags); - } -} - -boolean radeon_drm_bufmgr_is_buffer_referenced(struct pb_buffer *_buf) -{ - struct radeon_drm_buffer *buf = get_drm_buffer(_buf); - uint32_t domain; - - return (radeon_bo_is_referenced_by_cs(buf->bo, buf->mgr->rws->cs) || - radeon_bo_is_busy(buf->bo, &domain)); -} - - -void radeon_drm_bufmgr_flush_maps(struct pb_manager *_mgr) -{ - struct radeon_drm_bufmgr *mgr = radeon_drm_bufmgr(_mgr); - struct radeon_drm_buffer *rpb, *t_rpb; - - foreach_s(rpb, t_rpb, &mgr->buffer_map_list) { - radeon_bo_unmap(rpb->bo); - rpb->bo->ptr = NULL; - remove_from_list(rpb); - } - - make_empty_list(&mgr->buffer_map_list); -} diff --git a/src/gallium/winsys/drm/radeon/core/radeon_r300.c b/src/gallium/winsys/drm/radeon/core/radeon_r300.c deleted file mode 100644 index 38fcf889c8b..00000000000 --- a/src/gallium/winsys/drm/radeon/core/radeon_r300.c +++ /dev/null @@ -1,348 +0,0 @@ -/* - * Copyright 2008 Corbin Simpson - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * on the rights to use, copy, modify, merge, publish, distribute, sub - * license, and/or sell copies of the Software, and to permit persons to whom - * the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL - * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE - * USE OR OTHER DEALINGS IN THE SOFTWARE. */ - -#include "radeon_r300.h" -#include "radeon_buffer.h" - -#include "radeon_bo_gem.h" -#include "radeon_cs_gem.h" -#include "state_tracker/drm_api.h" - -static struct r300_winsys_buffer * -radeon_r300_winsys_buffer_create(struct r300_winsys_screen *rws, - unsigned alignment, - unsigned usage, - unsigned size) -{ - struct radeon_libdrm_winsys *ws = radeon_winsys_screen(rws); - struct pb_desc desc; - struct pb_manager *provider; - struct pb_buffer *buffer; - - memset(&desc, 0, sizeof(desc)); - desc.alignment = alignment; - desc.usage = usage; - - if (usage & PIPE_BUFFER_USAGE_CONSTANT) - provider = ws->mman; - else if ((usage & PIPE_BUFFER_USAGE_VERTEX) || - (usage & PIPE_BUFFER_USAGE_INDEX)) - provider = ws->cman; - else - provider = ws->kman; - buffer = provider->create_buffer(provider, size, &desc); - if (!buffer) - return NULL; - - return radeon_libdrm_winsys_buffer(buffer); -} - -static void radeon_r300_winsys_buffer_destroy(struct r300_winsys_buffer *buf) -{ - struct pb_buffer *_buf = radeon_pb_buffer(buf); - - pb_destroy(_buf); -} -static void radeon_r300_winsys_buffer_set_tiling(struct r300_winsys_screen *rws, - struct r300_winsys_buffer *buf, - uint32_t pitch, - enum r300_buffer_tiling microtiled, - enum r300_buffer_tiling macrotiled) -{ - struct pb_buffer *_buf = radeon_pb_buffer(buf); - radeon_drm_bufmgr_set_tiling(_buf, microtiled, macrotiled, pitch); -} - -static void *radeon_r300_winsys_buffer_map(struct r300_winsys_screen *ws, - struct r300_winsys_buffer *buf, - unsigned usage) -{ - struct pb_buffer *_buf = radeon_pb_buffer(buf); - - return pb_map(_buf, usage); -} - -static void radeon_r300_winsys_buffer_unmap(struct r300_winsys_screen *ws, - struct r300_winsys_buffer *buf) -{ - struct pb_buffer *_buf = radeon_pb_buffer(buf); - - pb_unmap(_buf); -} - -static void radeon_r300_winsys_buffer_reference(struct r300_winsys_screen *rws, - struct r300_winsys_buffer **pdst, - struct r300_winsys_buffer *src) -{ - struct pb_buffer *_src = radeon_pb_buffer(src); - struct pb_buffer *_dst = radeon_pb_buffer(*pdst); - - pb_reference(&_dst, _src); - - *pdst = radeon_libdrm_winsys_buffer(_dst); -} - -static boolean radeon_r300_winsys_is_buffer_referenced(struct r300_winsys_screen *rws, - struct r300_winsys_buffer *buf) -{ - struct pb_buffer *_buf = radeon_pb_buffer(buf); - - return radeon_drm_bufmgr_is_buffer_referenced(_buf); -} - -static struct r300_winsys_buffer *radeon_r300_winsys_buffer_from_handle(struct r300_winsys_screen *rws, - struct pipe_screen *screen, - struct winsys_handle *whandle, - unsigned *stride) -{ - struct radeon_libdrm_winsys *ws = radeon_winsys_screen(rws); - struct pb_buffer *_buf; - - _buf = radeon_drm_bufmgr_create_buffer_from_handle(ws->kman, whandle->handle); - *stride = whandle->stride; - return radeon_libdrm_winsys_buffer(_buf); -} - -static boolean radeon_r300_winsys_buffer_get_handle(struct r300_winsys_screen *rws, - struct r300_winsys_buffer *buffer, - unsigned stride, - struct winsys_handle *whandle) -{ - struct pb_buffer *_buf = radeon_pb_buffer(buffer); - boolean ret; - ret = radeon_drm_bufmgr_get_handle(_buf, whandle); - if (ret) - whandle->stride = stride; - return ret; -} - -static void radeon_set_flush_cb(struct r300_winsys_screen *rws, - void (*flush_cb)(void *), - void *data) -{ - struct radeon_libdrm_winsys *ws = radeon_winsys_screen(rws); - ws->flush_cb = flush_cb; - ws->flush_data = data; - radeon_cs_space_set_flush(ws->cs, flush_cb, data); -} - -static boolean radeon_add_buffer(struct r300_winsys_screen *rws, - struct r300_winsys_buffer *buf, - uint32_t rd, - uint32_t wd) -{ - struct pb_buffer *_buf = radeon_pb_buffer(buf); - - return radeon_drm_bufmgr_add_buffer(_buf, rd, wd); -} - -static boolean radeon_validate(struct r300_winsys_screen *rws) -{ - struct radeon_libdrm_winsys *ws = radeon_winsys_screen(rws); - if (radeon_cs_space_check(ws->cs) < 0) { - return FALSE; - } - - /* Things are fine, we can proceed as normal. */ - return TRUE; -} - -static boolean radeon_check_cs(struct r300_winsys_screen *rws, int size) -{ - struct radeon_libdrm_winsys *ws = radeon_winsys_screen(rws); - struct radeon_cs *cs = ws->cs; - - return radeon_validate(rws) && cs->cdw + size <= cs->ndw; -} - -static void radeon_begin_cs(struct r300_winsys_screen *rws, - int size, - const char* file, - const char* function, - int line) -{ - struct radeon_libdrm_winsys *ws = radeon_winsys_screen(rws); - radeon_cs_begin(ws->cs, size, file, function, line); -} - -static void radeon_write_cs_dword(struct r300_winsys_screen *rws, - uint32_t dword) -{ - struct radeon_libdrm_winsys *ws = radeon_winsys_screen(rws); - radeon_cs_write_dword(ws->cs, dword); -} - -static void radeon_write_cs_reloc(struct r300_winsys_screen *rws, - struct r300_winsys_buffer *buf, - uint32_t rd, - uint32_t wd, - uint32_t flags) -{ - struct pb_buffer *_buf = radeon_pb_buffer(buf); - radeon_drm_bufmgr_write_reloc(_buf, rd, wd, flags); -} - -static void radeon_reset_bos(struct r300_winsys_screen *rws) -{ - struct radeon_libdrm_winsys *ws = radeon_winsys_screen(rws); - radeon_cs_space_reset_bos(ws->cs); -} - -static void radeon_end_cs(struct r300_winsys_screen *rws, - const char* file, - const char* function, - int line) -{ - struct radeon_libdrm_winsys *ws = radeon_winsys_screen(rws); - radeon_cs_end(ws->cs, file, function, line); -} - -static void radeon_flush_cs(struct r300_winsys_screen *rws) -{ - struct radeon_libdrm_winsys *ws = radeon_winsys_screen(rws); - int retval; - - /* Don't flush a zero-sized CS. */ - if (!ws->cs->cdw) { - return; - } - - radeon_drm_bufmgr_flush_maps(ws->kman); - /* Emit the CS. */ - retval = radeon_cs_emit(ws->cs); - if (retval) { - debug_printf("radeon: Bad CS, dumping...\n"); - radeon_cs_print(ws->cs, stderr); - } - - /* Reset CS. - * Someday, when we care about performance, we should really find a way - * to rotate between two or three CS objects so that the GPU can be - * spinning through one CS while another one is being filled. */ - radeon_cs_erase(ws->cs); -} - -static uint32_t radeon_get_value(struct r300_winsys_screen *rws, - enum r300_value_id id) -{ - struct radeon_libdrm_winsys *ws = (struct radeon_libdrm_winsys *)rws; - - switch(id) { - case R300_VID_PCI_ID: - return ws->pci_id; - case R300_VID_GB_PIPES: - return ws->gb_pipes; - case R300_VID_Z_PIPES: - return ws->z_pipes; - case R300_VID_SQUARE_TILING_SUPPORT: - return ws->squaretiling; - } - return 0; -} - -static void -radeon_winsys_destroy(struct r300_winsys_screen *rws) -{ - struct radeon_libdrm_winsys *ws = (struct radeon_libdrm_winsys *)rws; - radeon_cs_destroy(ws->cs); - - ws->cman->destroy(ws->cman); - ws->kman->destroy(ws->kman); - ws->mman->destroy(ws->mman); - - radeon_bo_manager_gem_dtor(ws->bom); - radeon_cs_manager_gem_dtor(ws->csm); -} - -boolean -radeon_setup_winsys(int fd, struct radeon_libdrm_winsys* ws) -{ - - ws->csm = radeon_cs_manager_gem_ctor(fd); - if (!ws->csm) - goto fail; - ws->bom = radeon_bo_manager_gem_ctor(fd); - if (!ws->bom) - goto fail; - ws->kman = radeon_drm_bufmgr_create(ws); - if (!ws->kman) - goto fail; - - ws->cman = pb_cache_manager_create(ws->kman, 100000); - if (!ws->cman) - goto fail; - - ws->mman = pb_malloc_bufmgr_create(); - if (!ws->mman) - goto fail; - - /* Size limit on IBs is 64 kibibytes. */ - ws->cs = radeon_cs_create(ws->csm, 1024 * 64 / 4); - if (!ws->cs) - goto fail; - radeon_cs_set_limit(ws->cs, - RADEON_GEM_DOMAIN_GTT, ws->gart_size); - radeon_cs_set_limit(ws->cs, - RADEON_GEM_DOMAIN_VRAM, ws->vram_size); - - ws->base.add_buffer = radeon_add_buffer; - ws->base.validate = radeon_validate; - ws->base.destroy = radeon_winsys_destroy; - ws->base.check_cs = radeon_check_cs; - ws->base.begin_cs = radeon_begin_cs; - ws->base.write_cs_dword = radeon_write_cs_dword; - ws->base.write_cs_reloc = radeon_write_cs_reloc; - ws->base.end_cs = radeon_end_cs; - ws->base.flush_cs = radeon_flush_cs; - ws->base.reset_bos = radeon_reset_bos; - ws->base.set_flush_cb = radeon_set_flush_cb; - ws->base.get_value = radeon_get_value; - - ws->base.buffer_create = radeon_r300_winsys_buffer_create; - ws->base.buffer_destroy = radeon_r300_winsys_buffer_destroy; - ws->base.buffer_set_tiling = radeon_r300_winsys_buffer_set_tiling; - ws->base.buffer_map = radeon_r300_winsys_buffer_map; - ws->base.buffer_unmap = radeon_r300_winsys_buffer_unmap; - ws->base.buffer_reference = radeon_r300_winsys_buffer_reference; - ws->base.buffer_from_handle = radeon_r300_winsys_buffer_from_handle; - ws->base.buffer_get_handle = radeon_r300_winsys_buffer_get_handle; - ws->base.is_buffer_referenced = radeon_r300_winsys_is_buffer_referenced; - return TRUE; - -fail: - if (ws->csm) - radeon_cs_manager_gem_dtor(ws->csm); - - if (ws->bom) - radeon_bo_manager_gem_dtor(ws->bom); - - if (ws->cman) - ws->cman->destroy(ws->cman); - if (ws->kman) - ws->kman->destroy(ws->kman); - if (ws->mman) - ws->mman->destroy(ws->mman); - - if (ws->cs) - radeon_cs_destroy(ws->cs); - return FALSE; -} diff --git a/src/gallium/winsys/drm/radeon/core/radeon_r300.h b/src/gallium/winsys/drm/radeon/core/radeon_r300.h deleted file mode 100644 index 2703464ad8f..00000000000 --- a/src/gallium/winsys/drm/radeon/core/radeon_r300.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2008 Corbin Simpson - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * on the rights to use, copy, modify, merge, publish, distribute, sub - * license, and/or sell copies of the Software, and to permit persons to whom - * the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL - * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE - * USE OR OTHER DEALINGS IN THE SOFTWARE. */ - -#ifndef RADEON_R300_H -#define RADEON_R300_H - -#include "radeon_winsys.h" - -boolean radeon_setup_winsys(int fd, struct radeon_libdrm_winsys* winsys); - -#endif /* RADEON_R300_H */ diff --git a/src/gallium/winsys/drm/radeon/core/radeon_winsys.h b/src/gallium/winsys/drm/radeon/core/radeon_winsys.h deleted file mode 100644 index 4260dbaad72..00000000000 --- a/src/gallium/winsys/drm/radeon/core/radeon_winsys.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright © 2009 Corbin Simpson - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS - * AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE - * USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - */ -/* - * Authors: - * Corbin Simpson - */ -#ifndef RADEON_WINSYS_H -#define RADEON_WINSYS_H - -#include "r300_winsys.h" - -struct radeon_libdrm_winsys { - /* Parent class. */ - struct r300_winsys_screen base; - - struct pb_manager *kman; - - struct pb_manager *cman; - - struct pb_manager *mman; - - /* PCI ID */ - uint32_t pci_id; - - /* GB pipe count */ - uint32_t gb_pipes; - - /* Z pipe count (rv530 only) */ - uint32_t z_pipes; - - /* GART size. */ - uint32_t gart_size; - - /* VRAM size. */ - uint32_t vram_size; - - /* Square tiling support. */ - boolean squaretiling; - - /* DRM FD */ - int fd; - - /* Radeon BO manager. */ - struct radeon_bo_manager *bom; - - /* Radeon CS manager. */ - struct radeon_cs_manager *csm; - - /* Current CS. */ - struct radeon_cs *cs; - - /* Flush CB */ - void (*flush_cb)(void *); - void *flush_data; -}; - -static INLINE struct radeon_libdrm_winsys * -radeon_winsys_screen(struct r300_winsys_screen *base) -{ - return (struct radeon_libdrm_winsys *)base; -} - -#endif diff --git a/src/gallium/winsys/drm/sw/Makefile b/src/gallium/winsys/drm/sw/Makefile deleted file mode 100644 index 5f3c3ec325d..00000000000 --- a/src/gallium/winsys/drm/sw/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -TOP = ../../../../.. -include $(TOP)/configs/current - -LIBNAME = swdrm - -C_SOURCES = \ - wrapper_sw_winsys.c \ - sw_drm_api.c - -LIBRARY_INCLUDES = - -LIBRARY_DEFINES = - -include ../../../Makefile.template diff --git a/src/gallium/winsys/drm/sw/sw_drm_api.c b/src/gallium/winsys/drm/sw/sw_drm_api.c deleted file mode 100644 index 0fd2163913e..00000000000 --- a/src/gallium/winsys/drm/sw/sw_drm_api.c +++ /dev/null @@ -1,97 +0,0 @@ -/********************************************************** - * Copyright 2010 VMware, Inc. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - **********************************************************/ - - -#include "util/u_memory.h" -#include "softpipe/sp_public.h" -#include "state_tracker/drm_api.h" -#include "wrapper_sw_winsys.h" -#include "sw_drm_api.h" - - -/* - * Defines - */ - - -struct sw_drm_api -{ - struct drm_api base; - struct drm_api *api; - struct sw_winsys *sw; -}; - -static INLINE struct sw_drm_api * -sw_drm_api(struct drm_api *api) -{ - return (struct sw_drm_api *)api; -} - - -/* - * Exported functions - */ - - -static struct pipe_screen * -sw_drm_create_screen(struct drm_api *_api, int drmFD, - struct drm_create_screen_arg *arg) -{ - struct sw_drm_api *swapi = sw_drm_api(_api); - struct drm_api *api = swapi->api; - struct sw_winsys *sww; - struct pipe_screen *screen; - - screen = api->create_screen(api, drmFD, arg); - - sww = wrapper_sw_winsys_warp_pipe_screen(screen); - - return softpipe_create_screen(sww); -} - -static void -sw_drm_destroy(struct drm_api *api) -{ - struct sw_drm_api *swapi = sw_drm_api(api); - if (swapi->api->destroy) - swapi->api->destroy(swapi->api); - - FREE(swapi); -} - -struct drm_api * -sw_drm_api_create(struct drm_api *api) -{ - struct sw_drm_api *swapi = CALLOC_STRUCT(sw_drm_api); - - swapi->base.name = "sw"; - swapi->base.driver_name = api->driver_name; - swapi->base.create_screen = sw_drm_create_screen; - swapi->base.destroy = sw_drm_destroy; - - swapi->api = api; - - return &swapi->base; -} diff --git a/src/gallium/winsys/drm/sw/sw_drm_api.h b/src/gallium/winsys/drm/sw/sw_drm_api.h deleted file mode 100644 index ce90a04ae0c..00000000000 --- a/src/gallium/winsys/drm/sw/sw_drm_api.h +++ /dev/null @@ -1,34 +0,0 @@ -/********************************************************** - * Copyright 2010 VMware, Inc. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - **********************************************************/ - - -#ifndef SW_DRM_API_H -#define SW_DRM_API_H - -struct drm_api; - -struct drm_api * sw_drm_api_create(struct drm_api *api); - -#endif diff --git a/src/gallium/winsys/drm/sw/wrapper_sw_winsys.c b/src/gallium/winsys/drm/sw/wrapper_sw_winsys.c deleted file mode 100644 index 459b1c1e2a3..00000000000 --- a/src/gallium/winsys/drm/sw/wrapper_sw_winsys.c +++ /dev/null @@ -1,282 +0,0 @@ -/********************************************************** - * Copyright 2010 VMware, Inc. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - **********************************************************/ - - -#include "wrapper_sw_winsys.h" - -#include "pipe/p_format.h" -#include "pipe/p_state.h" - -#include "state_tracker/sw_winsys.h" - -#include "util/u_memory.h" -#include "util/u_inlines.h" - -/* - * This code wraps a pipe_screen and exposes a sw_winsys interface for use - * with software resterizers. This code is used by the DRM based winsys to - * allow access to the drm driver. - * - * We must borrow the whole stack because only the pipe screen knows how - * to decode the content of a buffer. Or how to create a buffer that - * can still be used by drivers using real hardware (as the case is - * with software st/xorg but hw st/dri). - * - * We also need a pipe context for the transfers. - */ - -struct wrapper_sw_winsys -{ - struct sw_winsys base; - struct pipe_screen *screen; - struct pipe_context *pipe; -}; - -struct wrapper_sw_displaytarget -{ - struct wrapper_sw_winsys *winsys; - struct pipe_texture *tex; - struct pipe_transfer *transfer; - - unsigned width; - unsigned height; - unsigned map_count; - unsigned stride; /**< because we give stride at create */ - void *ptr; -}; - -static INLINE struct wrapper_sw_winsys * -wrapper_sw_winsys(struct sw_winsys *ws) -{ - return (struct wrapper_sw_winsys *)ws; -} - -static INLINE struct wrapper_sw_displaytarget * -wrapper_sw_displaytarget(struct sw_displaytarget *dt) -{ - return (struct wrapper_sw_displaytarget *)dt; -} - - -/* - * Functions - */ - - -static boolean -wsw_dt_get_stride(struct wrapper_sw_displaytarget *wdt, unsigned *stride) -{ - struct pipe_context *pipe = wdt->winsys->pipe; - struct pipe_texture *tex = wdt->tex; - struct pipe_transfer *tr; - - tr = pipe->get_tex_transfer(pipe, tex, 0, 0, 0, - PIPE_TRANSFER_READ_WRITE, - 0, 0, wdt->width, wdt->height); - if (!tr) - return FALSE; - - *stride = tr->stride; - wdt->stride = tr->stride; - - pipe->tex_transfer_destroy(pipe, tr); - - return TRUE; -} - -static struct sw_displaytarget * -wsw_dt_wrap_texture(struct wrapper_sw_winsys *wsw, - struct pipe_texture *tex, unsigned *stride) -{ - struct wrapper_sw_displaytarget *wdt = CALLOC_STRUCT(wrapper_sw_displaytarget); - if (!wdt) - goto err_unref; - - wdt->tex = tex; - wdt->winsys = wsw; - - if (!wsw_dt_get_stride(wdt, stride)) - goto err_free; - - return (struct sw_displaytarget *)wdt; - -err_free: - FREE(wdt); -err_unref: - pipe_texture_reference(&tex, NULL); - return NULL; -} - -static struct sw_displaytarget * -wsw_dt_create(struct sw_winsys *ws, - unsigned tex_usage, - enum pipe_format format, - unsigned width, unsigned height, - unsigned alignment, - unsigned *stride) -{ - struct wrapper_sw_winsys *wsw = wrapper_sw_winsys(ws); - struct pipe_texture templ; - struct pipe_texture *tex; - - /* - * XXX Why don't we just get the template. - */ - memset(&templ, 0, sizeof(templ)); - templ.width0 = width; - templ.height0 = height; - templ.format = format; - templ.tex_usage = tex_usage; - - /* XXX alignment: we can't do anything about this */ - - tex = wsw->screen->texture_create(wsw->screen, &templ); - if (!tex) - return NULL; - - return wsw_dt_wrap_texture(wsw, tex, stride); -} - -static struct sw_displaytarget * -wsw_dt_from_handle(struct sw_winsys *ws, - const struct pipe_texture *templ, - struct winsys_handle *whandle, - unsigned *stride) -{ - struct wrapper_sw_winsys *wsw = wrapper_sw_winsys(ws); - struct pipe_texture *tex; - - tex = wsw->screen->texture_from_handle(wsw->screen, templ, whandle); - if (!tex) - return NULL; - - return wsw_dt_wrap_texture(wsw, tex, stride); -} - -static void * -wsw_dt_map(struct sw_winsys *ws, - struct sw_displaytarget *dt, - unsigned flags) -{ - struct wrapper_sw_displaytarget *wdt = wrapper_sw_displaytarget(dt); - struct pipe_context *pipe = wdt->winsys->pipe; - struct pipe_texture *tex = wdt->tex; - struct pipe_transfer *tr; - void *ptr; - - if (!wdt->map_count) { - - assert(!wdt->transfer); - - tr = pipe->get_tex_transfer(pipe, tex, 0, 0, 0, - PIPE_TRANSFER_READ_WRITE, - 0, 0, wdt->width, wdt->height); - if (!tr) - return NULL; - - ptr = pipe->transfer_map(pipe, tr); - if (!ptr) - goto err; - - wdt->transfer = tr; - wdt->ptr = ptr; - - /* XXX Handle this case */ - assert(tr->stride == wdt->stride); - } - - wdt->map_count++; - - return wdt->ptr; - -err: - pipe->tex_transfer_destroy(pipe, tr); - return NULL; -} - -static void -wsw_dt_unmap(struct sw_winsys *ws, - struct sw_displaytarget *dt) -{ - struct wrapper_sw_displaytarget *wdt = wrapper_sw_displaytarget(dt); - struct pipe_context *pipe = wdt->winsys->pipe; - - assert(wdt->transfer); - - wdt->map_count--; - - if (wdt->map_count) - return; - - pipe->transfer_unmap(pipe, wdt->transfer); - pipe->tex_transfer_destroy(pipe, wdt->transfer); - wdt->transfer = NULL; -} - -static void -wsw_dt_destroy(struct sw_winsys *ws, - struct sw_displaytarget *dt) -{ - struct wrapper_sw_displaytarget *wdt = wrapper_sw_displaytarget(dt); - - pipe_texture_reference(&wdt->tex, NULL); - - FREE(wdt); -} - -static void -wsw_destroy(struct sw_winsys *ws) -{ - struct wrapper_sw_winsys *wsw = wrapper_sw_winsys(ws); - - wsw->pipe->destroy(wsw->pipe); - wsw->screen->destroy(wsw->screen); - - FREE(wsw); -} - -struct sw_winsys * -wrapper_sw_winsys_warp_pipe_screen(struct pipe_screen *screen) -{ - struct wrapper_sw_winsys *wsw = CALLOC_STRUCT(wrapper_sw_winsys); - - wsw->base.displaytarget_create = wsw_dt_create; - wsw->base.displaytarget_from_handle = wsw_dt_from_handle; - wsw->base.displaytarget_map = wsw_dt_map; - wsw->base.displaytarget_unmap = wsw_dt_unmap; - wsw->base.displaytarget_destroy = wsw_dt_destroy; - wsw->base.destroy = wsw_destroy; - - wsw->screen = screen; - wsw->pipe = screen->context_create(screen, NULL); - if (!wsw->pipe) - goto err; - - return &wsw->base; - -err: - FREE(wsw); - return NULL; -} diff --git a/src/gallium/winsys/drm/sw/wrapper_sw_winsys.h b/src/gallium/winsys/drm/sw/wrapper_sw_winsys.h deleted file mode 100644 index b5c25a3c50f..00000000000 --- a/src/gallium/winsys/drm/sw/wrapper_sw_winsys.h +++ /dev/null @@ -1,35 +0,0 @@ -/********************************************************** - * Copyright 2010 VMware, Inc. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - **********************************************************/ - - -#ifndef WRAPPER_SW_WINSYS -#define WRAPPER_SW_WINSYS - -struct sw_winsys; -struct pipe_screen; - -struct sw_winsys *wrapper_sw_winsys_warp_pipe_screen(struct pipe_screen *screen); - -#endif diff --git a/src/gallium/winsys/drm/vmware/Makefile b/src/gallium/winsys/drm/vmware/Makefile deleted file mode 100644 index 2ae6dead5c1..00000000000 --- a/src/gallium/winsys/drm/vmware/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -# src/gallium/winsys/drm/vmware/Makefile -TOP = ../../../../.. -include $(TOP)/configs/current - -SUBDIRS = core $(GALLIUM_STATE_TRACKERS_DIRS) - -default install clean: - @for dir in $(SUBDIRS) ; do \ - if [ -d $$dir ] ; then \ - (cd $$dir && $(MAKE) $@) || exit 1; \ - fi \ - done diff --git a/src/gallium/winsys/drm/vmware/SConscript b/src/gallium/winsys/drm/vmware/SConscript deleted file mode 100644 index eff87e7d010..00000000000 --- a/src/gallium/winsys/drm/vmware/SConscript +++ /dev/null @@ -1,3 +0,0 @@ -Import('*') - -SConscript(['core/SConscript',]) diff --git a/src/gallium/winsys/drm/vmware/core/Makefile b/src/gallium/winsys/drm/vmware/core/Makefile deleted file mode 100644 index a52957c1a5b..00000000000 --- a/src/gallium/winsys/drm/vmware/core/Makefile +++ /dev/null @@ -1,35 +0,0 @@ -TOP = ../../../../../.. -include $(TOP)/configs/current - -LIBNAME = svgadrm - -C_SOURCES = \ - vmw_buffer.c \ - vmw_context.c \ - vmw_fence.c \ - vmw_screen.c \ - vmw_screen_dri.c \ - vmw_screen_ioctl.c \ - vmw_screen_pools.c \ - vmw_screen_svga.c \ - vmw_surface.c - -LIBRARY_INCLUDES = \ - -I$(TOP)/src/gallium/drivers/svga \ - -I$(TOP)/src/gallium/drivers/svga/include \ - -I$(GALLIUM)/src/mesa/drivers/dri/common \ - -I$(GALLIUM)/include \ - -I$(GALLIUM)/include/GL/internal \ - -I$(GALLIUM)/src/mesa \ - -I$(GALLIUM)/src/mesa/main \ - -I$(GALLIUM)/src/mesa/glapi \ - -I$(GALLIUM)/src/egl/main \ - -I$(GALLIUM)/src/egl/drivers/dri \ - $(shell pkg-config libdrm --cflags-only-I) - -LIBRARY_DEFINES = \ - -std=gnu99 -fvisibility=hidden \ - -DHAVE_STDINT_H -D_FILE_OFFSET_BITS=64 \ - $(shell pkg-config libdrm --cflags-only-other) - -include ../../../../Makefile.template diff --git a/src/gallium/winsys/drm/vmware/core/SConscript b/src/gallium/winsys/drm/vmware/core/SConscript deleted file mode 100644 index edaf9458bee..00000000000 --- a/src/gallium/winsys/drm/vmware/core/SConscript +++ /dev/null @@ -1,39 +0,0 @@ -Import('*') - -env = env.Clone() - -if env['gcc']: - env.Append(CCFLAGS = ['-fvisibility=hidden']) - env.Append(CPPDEFINES = [ - 'HAVE_STDINT_H', - 'HAVE_SYS_TYPES_H', - '-D_FILE_OFFSET_BITS=64', - ]) - -env.Prepend(CPPPATH = [ - 'include', - '#/src/gallium/drivers/svga', - '#/src/gallium/drivers/svga/include', -]) - -env.Append(CPPDEFINES = [ -]) - -sources = [ - 'vmw_buffer.c', - 'vmw_context.c', - 'vmw_fence.c', - 'vmw_screen.c', - 'vmw_screen_dri.c', - 'vmw_screen_ioctl.c', - 'vmw_screen_pools.c', - 'vmw_screen_svga.c', - 'vmw_surface.c', -] - -svgadrm = env.ConvenienceLibrary( - target = 'svgadrm', - source = sources, -) - -Export('svgadrm') diff --git a/src/gallium/winsys/drm/vmware/core/vmw_buffer.c b/src/gallium/winsys/drm/vmware/core/vmw_buffer.c deleted file mode 100644 index eca174a6c56..00000000000 --- a/src/gallium/winsys/drm/vmware/core/vmw_buffer.c +++ /dev/null @@ -1,274 +0,0 @@ -/********************************************************** - * Copyright 2009 VMware, Inc. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - **********************************************************/ - -/** - * @file - * SVGA buffer manager for Guest Memory Regions (GMRs). - * - * GMRs are used for pixel and vertex data upload/download to/from the virtual - * SVGA hardware. There is a limited number of GMRs available, and - * creating/destroying them is also a slow operation so we must suballocate - * them. - * - * This file implements a pipebuffer library's buffer manager, so that we can - * use pipepbuffer's suballocation, fencing, and debugging facilities with GMRs. - * - * @author Jose Fonseca - */ - - -#include "svga_cmd.h" - -#include "util/u_inlines.h" -#include "util/u_memory.h" -#include "pipebuffer/pb_buffer.h" -#include "pipebuffer/pb_bufmgr.h" - -#include "svga_winsys.h" - -#include "vmw_screen.h" -#include "vmw_buffer.h" - - -struct vmw_gmr_bufmgr; - - -struct vmw_gmr_buffer -{ - struct pb_buffer base; - - struct vmw_gmr_bufmgr *mgr; - - struct vmw_region *region; - void *map; - -#ifdef DEBUG - struct pipe_fence_handle *last_fence; -#endif -}; - - -extern const struct pb_vtbl vmw_gmr_buffer_vtbl; - - -static INLINE struct vmw_gmr_buffer * -vmw_gmr_buffer(struct pb_buffer *buf) -{ - assert(buf); - assert(buf->vtbl == &vmw_gmr_buffer_vtbl); - return (struct vmw_gmr_buffer *)buf; -} - - -struct vmw_gmr_bufmgr -{ - struct pb_manager base; - - struct vmw_winsys_screen *vws; -}; - - -static INLINE struct vmw_gmr_bufmgr * -vmw_gmr_bufmgr(struct pb_manager *mgr) -{ - assert(mgr); - return (struct vmw_gmr_bufmgr *)mgr; -} - - -static void -vmw_gmr_buffer_destroy(struct pb_buffer *_buf) -{ - struct vmw_gmr_buffer *buf = vmw_gmr_buffer(_buf); - -#ifdef DEBUG - if(buf->last_fence) { - struct svga_winsys_screen *sws = &buf->mgr->vws->base; - assert(sws->fence_signalled(sws, buf->last_fence, 0) == 0); - } -#endif - - vmw_ioctl_region_unmap(buf->region); - - vmw_ioctl_region_destroy(buf->region); - - FREE(buf); -} - - -static void * -vmw_gmr_buffer_map(struct pb_buffer *_buf, - unsigned flags) -{ - struct vmw_gmr_buffer *buf = vmw_gmr_buffer(_buf); - return buf->map; -} - - -static void -vmw_gmr_buffer_unmap(struct pb_buffer *_buf) -{ - /* Do nothing */ - (void)_buf; -} - - -static void -vmw_gmr_buffer_get_base_buffer(struct pb_buffer *buf, - struct pb_buffer **base_buf, - unsigned *offset) -{ - *base_buf = buf; - *offset = 0; -} - - -static enum pipe_error -vmw_gmr_buffer_validate( struct pb_buffer *_buf, - struct pb_validate *vl, - unsigned flags ) -{ - /* Always pinned */ - return PIPE_OK; -} - - -static void -vmw_gmr_buffer_fence( struct pb_buffer *_buf, - struct pipe_fence_handle *fence ) -{ - /* We don't need to do anything, as the pipebuffer library - * will take care of delaying the destruction of fenced buffers */ -#ifdef DEBUG - struct vmw_gmr_buffer *buf = vmw_gmr_buffer(_buf); - if(fence) - buf->last_fence = fence; -#endif -} - - -const struct pb_vtbl vmw_gmr_buffer_vtbl = { - vmw_gmr_buffer_destroy, - vmw_gmr_buffer_map, - vmw_gmr_buffer_unmap, - vmw_gmr_buffer_validate, - vmw_gmr_buffer_fence, - vmw_gmr_buffer_get_base_buffer -}; - - -static struct pb_buffer * -vmw_gmr_bufmgr_create_buffer(struct pb_manager *_mgr, - pb_size size, - const struct pb_desc *desc) -{ - struct vmw_gmr_bufmgr *mgr = vmw_gmr_bufmgr(_mgr); - struct vmw_winsys_screen *vws = mgr->vws; - struct vmw_gmr_buffer *buf; - - buf = CALLOC_STRUCT(vmw_gmr_buffer); - if(!buf) - goto error1; - - pipe_reference_init(&buf->base.base.reference, 1); - buf->base.base.alignment = desc->alignment; - buf->base.base.usage = desc->usage; - buf->base.base.size = size; - buf->base.vtbl = &vmw_gmr_buffer_vtbl; - buf->mgr = mgr; - - buf->region = vmw_ioctl_region_create(vws, size); - if(!buf->region) - goto error2; - - buf->map = vmw_ioctl_region_map(buf->region); - if(!buf->map) - goto error3; - - return &buf->base; - -error3: - vmw_ioctl_region_destroy(buf->region); -error2: - FREE(buf); -error1: - return NULL; -} - - -static void -vmw_gmr_bufmgr_flush(struct pb_manager *mgr) -{ - /* No-op */ -} - - -static void -vmw_gmr_bufmgr_destroy(struct pb_manager *_mgr) -{ - struct vmw_gmr_bufmgr *mgr = vmw_gmr_bufmgr(_mgr); - FREE(mgr); -} - - -struct pb_manager * -vmw_gmr_bufmgr_create(struct vmw_winsys_screen *vws) -{ - struct vmw_gmr_bufmgr *mgr; - - mgr = CALLOC_STRUCT(vmw_gmr_bufmgr); - if(!mgr) - return NULL; - - mgr->base.destroy = vmw_gmr_bufmgr_destroy; - mgr->base.create_buffer = vmw_gmr_bufmgr_create_buffer; - mgr->base.flush = vmw_gmr_bufmgr_flush; - - mgr->vws = vws; - - return &mgr->base; -} - - -boolean -vmw_gmr_bufmgr_region_ptr(struct pb_buffer *buf, - struct SVGAGuestPtr *ptr) -{ - struct pb_buffer *base_buf; - unsigned offset = 0; - struct vmw_gmr_buffer *gmr_buf; - - pb_get_base_buffer( buf, &base_buf, &offset ); - - gmr_buf = vmw_gmr_buffer(base_buf); - if(!gmr_buf) - return FALSE; - - *ptr = vmw_ioctl_region_ptr(gmr_buf->region); - - ptr->offset += offset; - - return TRUE; -} diff --git a/src/gallium/winsys/drm/vmware/core/vmw_buffer.h b/src/gallium/winsys/drm/vmware/core/vmw_buffer.h deleted file mode 100644 index 41fb4476da5..00000000000 --- a/src/gallium/winsys/drm/vmware/core/vmw_buffer.h +++ /dev/null @@ -1,65 +0,0 @@ -/********************************************************** - * Copyright 2009 VMware, Inc. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - **********************************************************/ - - -#ifndef VMW_BUFFER_H_ -#define VMW_BUFFER_H_ - -#include -#include "pipe/p_compiler.h" - -struct SVGAGuestPtr; -struct pb_buffer; -struct pb_manager; -struct svga_winsys_buffer; -struct svga_winsys_surface; -struct vmw_winsys_screen; - - -static INLINE struct pb_buffer * -vmw_pb_buffer(struct svga_winsys_buffer *buffer) -{ - assert(buffer); - return (struct pb_buffer *)buffer; -} - - -static INLINE struct svga_winsys_buffer * -vmw_svga_winsys_buffer(struct pb_buffer *buffer) -{ - assert(buffer); - return (struct svga_winsys_buffer *)buffer; -} - - -struct pb_manager * -vmw_gmr_bufmgr_create(struct vmw_winsys_screen *vws); - -boolean -vmw_gmr_bufmgr_region_ptr(struct pb_buffer *buf, - struct SVGAGuestPtr *ptr); - - -#endif /* VMW_BUFFER_H_ */ diff --git a/src/gallium/winsys/drm/vmware/core/vmw_context.c b/src/gallium/winsys/drm/vmware/core/vmw_context.c deleted file mode 100644 index 90ffc4868f7..00000000000 --- a/src/gallium/winsys/drm/vmware/core/vmw_context.c +++ /dev/null @@ -1,382 +0,0 @@ -/********************************************************** - * Copyright 2009 VMware, Inc. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - **********************************************************/ - - -#include "svga_cmd.h" - -#include "util/u_debug.h" -#include "util/u_memory.h" -#include "util/u_debug_stack.h" -#include "pipebuffer/pb_buffer.h" -#include "pipebuffer/pb_validate.h" - -#include "svga_winsys.h" -#include "vmw_context.h" -#include "vmw_screen.h" -#include "vmw_buffer.h" -#include "vmw_surface.h" -#include "vmw_fence.h" - -#define VMW_COMMAND_SIZE (64*1024) -#define VMW_SURFACE_RELOCS (1024) -#define VMW_REGION_RELOCS (512) - -#define VMW_MUST_FLUSH_STACK 8 - -struct vmw_region_relocation -{ - struct SVGAGuestPtr *where; - struct pb_buffer *buffer; - /* TODO: put offset info inside where */ - uint32 offset; -}; - -struct vmw_svga_winsys_context -{ - struct svga_winsys_context base; - - struct vmw_winsys_screen *vws; - -#ifdef DEBUG - boolean must_flush; - struct debug_stack_frame must_flush_stack[VMW_MUST_FLUSH_STACK]; -#endif - - struct { - uint8_t buffer[VMW_COMMAND_SIZE]; - uint32_t size; - uint32_t used; - uint32_t reserved; - } command; - - struct { - struct vmw_svga_winsys_surface *handles[VMW_SURFACE_RELOCS]; - uint32_t size; - uint32_t used; - uint32_t staged; - uint32_t reserved; - } surface; - - struct { - struct vmw_region_relocation relocs[VMW_REGION_RELOCS]; - uint32_t size; - uint32_t used; - uint32_t staged; - uint32_t reserved; - } region; - - struct pb_validate *validate; - - uint32_t last_fence; - - /** - * The amount of GMR that is referred by the commands currently batched - * in the context. - */ - uint32_t seen_regions; - - /** - * Whether this context should fail to reserve more commands, not because it - * ran out of command space, but because a substantial ammount of GMR was - * referred. - */ - boolean preemptive_flush; -}; - - -static INLINE struct vmw_svga_winsys_context * -vmw_svga_winsys_context(struct svga_winsys_context *swc) -{ - assert(swc); - return (struct vmw_svga_winsys_context *)swc; -} - - -static enum pipe_error -vmw_swc_flush(struct svga_winsys_context *swc, - struct pipe_fence_handle **pfence) -{ - struct vmw_svga_winsys_context *vswc = vmw_svga_winsys_context(swc); - struct pipe_fence_handle *fence = NULL; - unsigned i; - enum pipe_error ret; - - ret = pb_validate_validate(vswc->validate); - assert(ret == PIPE_OK); - if(ret == PIPE_OK) { - - /* Apply relocations */ - for(i = 0; i < vswc->region.used; ++i) { - struct vmw_region_relocation *reloc = &vswc->region.relocs[i]; - struct SVGAGuestPtr ptr; - - if(!vmw_gmr_bufmgr_region_ptr(reloc->buffer, &ptr)) - assert(0); - - ptr.offset += reloc->offset; - - *reloc->where = ptr; - } - - if (vswc->command.used) - vmw_ioctl_command(vswc->vws, - vswc->command.buffer, - vswc->command.used, - &vswc->last_fence); - - fence = vmw_pipe_fence(vswc->last_fence); - - pb_validate_fence(vswc->validate, fence); - } - - vswc->command.used = 0; - vswc->command.reserved = 0; - - for(i = 0; i < vswc->surface.used + vswc->surface.staged; ++i) { - struct vmw_svga_winsys_surface *vsurf = - vswc->surface.handles[i]; - p_atomic_dec(&vsurf->validated); - vmw_svga_winsys_surface_reference(&vswc->surface.handles[i], NULL); - } - - vswc->surface.used = 0; - vswc->surface.reserved = 0; - - for(i = 0; i < vswc->region.used + vswc->region.staged; ++i) { - pb_reference(&vswc->region.relocs[i].buffer, NULL); - } - - vswc->region.used = 0; - vswc->region.reserved = 0; - -#ifdef DEBUG - vswc->must_flush = FALSE; -#endif - vswc->preemptive_flush = FALSE; - vswc->seen_regions = 0; - - if(pfence) - *pfence = fence; - - return ret; -} - - -static void * -vmw_swc_reserve(struct svga_winsys_context *swc, - uint32_t nr_bytes, uint32_t nr_relocs ) -{ - struct vmw_svga_winsys_context *vswc = vmw_svga_winsys_context(swc); - -#ifdef DEBUG - /* Check if somebody forgot to check the previous failure */ - if(vswc->must_flush) { - debug_printf("Forgot to flush:\n"); - debug_backtrace_dump(vswc->must_flush_stack, VMW_MUST_FLUSH_STACK); - assert(!vswc->must_flush); - } -#endif - - assert(nr_bytes <= vswc->command.size); - if(nr_bytes > vswc->command.size) - return NULL; - - if(vswc->preemptive_flush || - vswc->command.used + nr_bytes > vswc->command.size || - vswc->surface.used + nr_relocs > vswc->surface.size || - vswc->region.used + nr_relocs > vswc->region.size) { -#ifdef DEBUG - vswc->must_flush = TRUE; - debug_backtrace_capture(vswc->must_flush_stack, 1, - VMW_MUST_FLUSH_STACK); -#endif - return NULL; - } - - assert(vswc->command.used + nr_bytes <= vswc->command.size); - assert(vswc->surface.used + nr_relocs <= vswc->surface.size); - assert(vswc->region.used + nr_relocs <= vswc->region.size); - - vswc->command.reserved = nr_bytes; - vswc->surface.reserved = nr_relocs; - vswc->surface.staged = 0; - vswc->region.reserved = nr_relocs; - vswc->region.staged = 0; - - return vswc->command.buffer + vswc->command.used; -} - - -static void -vmw_swc_surface_relocation(struct svga_winsys_context *swc, - uint32 *where, - struct svga_winsys_surface *surface, - unsigned flags) -{ - struct vmw_svga_winsys_context *vswc = vmw_svga_winsys_context(swc); - struct vmw_svga_winsys_surface *vsurf; - - if(!surface) { - *where = SVGA3D_INVALID_ID; - return; - } - - assert(vswc->surface.staged < vswc->surface.reserved); - - vsurf = vmw_svga_winsys_surface(surface); - - *where = vsurf->sid; - - vmw_svga_winsys_surface_reference(&vswc->surface.handles[vswc->surface.used + vswc->surface.staged], vsurf); - p_atomic_inc(&vsurf->validated); - ++vswc->surface.staged; -} - - -static void -vmw_swc_region_relocation(struct svga_winsys_context *swc, - struct SVGAGuestPtr *where, - struct svga_winsys_buffer *buffer, - uint32 offset, - unsigned flags) -{ - struct vmw_svga_winsys_context *vswc = vmw_svga_winsys_context(swc); - struct vmw_region_relocation *reloc; - enum pipe_error ret; - - assert(vswc->region.staged < vswc->region.reserved); - - reloc = &vswc->region.relocs[vswc->region.used + vswc->region.staged]; - reloc->where = where; - pb_reference(&reloc->buffer, vmw_pb_buffer(buffer)); - reloc->offset = offset; - - ++vswc->region.staged; - - ret = pb_validate_add_buffer(vswc->validate, reloc->buffer, flags); - /* TODO: Update pipebuffer to reserve buffers and not fail here */ - assert(ret == PIPE_OK); - - /* - * Flush preemptively the FIFO commands to keep the GMR working set within - * the GMR pool size. - * - * This is necessary for applications like SPECviewperf that generate huge - * amounts of immediate vertex data, so that we don't pile up too much of - * that vertex data neither in the guest nor in the host. - * - * Note that in the current implementation if a region is referred twice in - * a command stream, it will be accounted twice. We could detect repeated - * regions and count only once, but there is no incentive to do that, since - * regions are typically short-lived; always referred in a single command; - * and at the worst we just flush the commands a bit sooner, which for the - * SVGA virtual device it's not a performance issue since flushing commands - * to the FIFO won't cause flushing in the host. - */ - vswc->seen_regions += reloc->buffer->base.size; - if(vswc->seen_regions >= VMW_GMR_POOL_SIZE/2) - vswc->preemptive_flush = TRUE; -} - - -static void -vmw_swc_commit(struct svga_winsys_context *swc) -{ - struct vmw_svga_winsys_context *vswc = vmw_svga_winsys_context(swc); - - assert(vswc->command.reserved); - assert(vswc->command.used + vswc->command.reserved <= vswc->command.size); - vswc->command.used += vswc->command.reserved; - vswc->command.reserved = 0; - - assert(vswc->surface.staged <= vswc->surface.reserved); - assert(vswc->surface.used + vswc->surface.staged <= vswc->surface.size); - vswc->surface.used += vswc->surface.staged; - vswc->surface.staged = 0; - vswc->surface.reserved = 0; - - assert(vswc->region.staged <= vswc->region.reserved); - assert(vswc->region.used + vswc->region.staged <= vswc->region.size); - vswc->region.used += vswc->region.staged; - vswc->region.staged = 0; - vswc->region.reserved = 0; -} - - -static void -vmw_swc_destroy(struct svga_winsys_context *swc) -{ - struct vmw_svga_winsys_context *vswc = vmw_svga_winsys_context(swc); - unsigned i; - - for(i = 0; i < vswc->region.used; ++i) { - pb_reference(&vswc->region.relocs[i].buffer, NULL); - } - - for(i = 0; i < vswc->surface.used; ++i) { - p_atomic_dec(&vswc->surface.handles[i]->validated); - vmw_svga_winsys_surface_reference(&vswc->surface.handles[i], NULL); - } - pb_validate_destroy(vswc->validate); - vmw_ioctl_context_destroy(vswc->vws, swc->cid); - FREE(vswc); -} - - -struct svga_winsys_context * -vmw_svga_winsys_context_create(struct svga_winsys_screen *sws) -{ - struct vmw_winsys_screen *vws = vmw_winsys_screen(sws); - struct vmw_svga_winsys_context *vswc; - - vswc = CALLOC_STRUCT(vmw_svga_winsys_context); - if(!vswc) - return NULL; - - vswc->base.destroy = vmw_swc_destroy; - vswc->base.reserve = vmw_swc_reserve; - vswc->base.surface_relocation = vmw_swc_surface_relocation; - vswc->base.region_relocation = vmw_swc_region_relocation; - vswc->base.commit = vmw_swc_commit; - vswc->base.flush = vmw_swc_flush; - - vswc->base.cid = vmw_ioctl_context_create(vws); - - vswc->vws = vws; - - vswc->command.size = VMW_COMMAND_SIZE; - vswc->surface.size = VMW_SURFACE_RELOCS; - vswc->region.size = VMW_REGION_RELOCS; - - vswc->validate = pb_validate_create(); - if(!vswc->validate) { - FREE(vswc); - return NULL; - } - - return &vswc->base; -} - - diff --git a/src/gallium/winsys/drm/vmware/core/vmw_context.h b/src/gallium/winsys/drm/vmware/core/vmw_context.h deleted file mode 100644 index d4884d24e99..00000000000 --- a/src/gallium/winsys/drm/vmware/core/vmw_context.h +++ /dev/null @@ -1,56 +0,0 @@ -/********************************************************** - * Copyright 2009 VMware, Inc. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - **********************************************************/ - -/** - * @author Jose Fonseca - */ - - -#ifndef VMW_CONTEXT_H_ -#define VMW_CONTEXT_H_ - -#include "pipe/p_compiler.h" - -struct svga_winsys_screen; -struct svga_winsys_context; -struct pipe_context; -struct pipe_screen; - -#define VMW_DEBUG 0 - -#if VMW_DEBUG -#define vmw_printf debug_printf -#define VMW_FUNC debug_printf("%s\n", __FUNCTION__) -#else -#define VMW_FUNC -#define vmw_printf(...) -#endif - - -struct svga_winsys_context * -vmw_svga_winsys_context_create(struct svga_winsys_screen *sws); - - -#endif /* VMW_CONTEXT_H_ */ diff --git a/src/gallium/winsys/drm/vmware/core/vmw_fence.c b/src/gallium/winsys/drm/vmware/core/vmw_fence.c deleted file mode 100644 index 873dd51166c..00000000000 --- a/src/gallium/winsys/drm/vmware/core/vmw_fence.c +++ /dev/null @@ -1,108 +0,0 @@ -/********************************************************** - * Copyright 2009 VMware, Inc. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - **********************************************************/ - - -#include "util/u_memory.h" -#include "pipebuffer/pb_buffer_fenced.h" - -#include "vmw_screen.h" -#include "vmw_fence.h" - - - -struct vmw_fence_ops -{ - struct pb_fence_ops base; - - struct vmw_winsys_screen *vws; -}; - - -static INLINE struct vmw_fence_ops * -vmw_fence_ops(struct pb_fence_ops *ops) -{ - assert(ops); - return (struct vmw_fence_ops *)ops; -} - - -static void -vmw_fence_ops_fence_reference(struct pb_fence_ops *ops, - struct pipe_fence_handle **ptr, - struct pipe_fence_handle *fence) -{ - *ptr = fence; -} - - -static int -vmw_fence_ops_fence_signalled(struct pb_fence_ops *ops, - struct pipe_fence_handle *fence, - unsigned flag) -{ - struct vmw_winsys_screen *vws = vmw_fence_ops(ops)->vws; - (void)flag; - return vmw_ioctl_fence_signalled(vws, vmw_fence(fence)); -} - - -static int -vmw_fence_ops_fence_finish(struct pb_fence_ops *ops, - struct pipe_fence_handle *fence, - unsigned flag) -{ - struct vmw_winsys_screen *vws = vmw_fence_ops(ops)->vws; - (void)flag; - return vmw_ioctl_fence_finish(vws, vmw_fence(fence)); -} - - -static void -vmw_fence_ops_destroy(struct pb_fence_ops *ops) -{ - FREE(ops); -} - - -struct pb_fence_ops * -vmw_fence_ops_create(struct vmw_winsys_screen *vws) -{ - struct vmw_fence_ops *ops; - - ops = CALLOC_STRUCT(vmw_fence_ops); - if(!ops) - return NULL; - - ops->base.destroy = &vmw_fence_ops_destroy; - ops->base.fence_reference = &vmw_fence_ops_fence_reference; - ops->base.fence_signalled = &vmw_fence_ops_fence_signalled; - ops->base.fence_finish = &vmw_fence_ops_fence_finish; - - ops->vws = vws; - - return &ops->base; -} - - diff --git a/src/gallium/winsys/drm/vmware/core/vmw_fence.h b/src/gallium/winsys/drm/vmware/core/vmw_fence.h deleted file mode 100644 index 5357b4f61de..00000000000 --- a/src/gallium/winsys/drm/vmware/core/vmw_fence.h +++ /dev/null @@ -1,59 +0,0 @@ -/********************************************************** - * Copyright 2009 VMware, Inc. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - **********************************************************/ - - -#ifndef VMW_FENCE_H_ -#define VMW_FENCE_H_ - - -#include "pipe/p_compiler.h" - - -struct pipe_fence_handle; -struct pb_fence_ops; -struct vmw_winsys_screen; - - -/** Cast from a pipe_fence_handle pointer into a SVGA fence */ -static INLINE uint32_t -vmw_fence( struct pipe_fence_handle *fence ) -{ - return (uint32_t)(uintptr_t)fence; -} - - -/** Cast from a SVGA fence number to pipe_fence_handle pointer */ -static INLINE struct pipe_fence_handle * -vmw_pipe_fence( uint32_t fence ) -{ - return (struct pipe_fence_handle *)(uintptr_t)fence; -} - - -struct pb_fence_ops * -vmw_fence_ops_create(struct vmw_winsys_screen *vws); - - -#endif /* VMW_FENCE_H_ */ diff --git a/src/gallium/winsys/drm/vmware/core/vmw_screen.c b/src/gallium/winsys/drm/vmware/core/vmw_screen.c deleted file mode 100644 index 6cc9b382932..00000000000 --- a/src/gallium/winsys/drm/vmware/core/vmw_screen.c +++ /dev/null @@ -1,77 +0,0 @@ -/********************************************************** - * Copyright 2009 VMware, Inc. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - **********************************************************/ - - -#include "vmw_screen.h" - -#include "vmw_context.h" - -#include "util/u_memory.h" -#include "pipe/p_compiler.h" - - -/* Called from vmw_drm_create_screen(), creates and initializes the - * vmw_winsys_screen structure, which is the main entity in this - * module. - */ -struct vmw_winsys_screen * -vmw_winsys_create( int fd, boolean use_old_scanout_flag ) -{ - struct vmw_winsys_screen *vws = CALLOC_STRUCT(vmw_winsys_screen); - if (!vws) - goto out_no_vws; - - vws->ioctl.drm_fd = fd; - vws->use_old_scanout_flag = use_old_scanout_flag; - debug_printf("%s: use_old_scanout_flag == %s\n", __FUNCTION__, - use_old_scanout_flag ? "true" : "false"); - - if (!vmw_ioctl_init(vws)) - goto out_no_ioctl; - - if(!vmw_pools_init(vws)) - goto out_no_pools; - - if (!vmw_winsys_screen_init_svga(vws)) - goto out_no_svga; - - return vws; -out_no_svga: - vmw_pools_cleanup(vws); -out_no_pools: - vmw_ioctl_cleanup(vws); -out_no_ioctl: - FREE(vws); -out_no_vws: - return NULL; -} - -void -vmw_winsys_destroy(struct vmw_winsys_screen *vws) -{ - vmw_pools_cleanup(vws); - vmw_ioctl_cleanup(vws); - FREE(vws); -} diff --git a/src/gallium/winsys/drm/vmware/core/vmw_screen.h b/src/gallium/winsys/drm/vmware/core/vmw_screen.h deleted file mode 100644 index d3f2c2c7f56..00000000000 --- a/src/gallium/winsys/drm/vmware/core/vmw_screen.h +++ /dev/null @@ -1,140 +0,0 @@ -/********************************************************** - * Copyright 2009 VMware, Inc. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - **********************************************************/ - -/** - * @file - * Common definitions for the VMware SVGA winsys. - * - * @author Jose Fonseca - */ - - -#ifndef VMW_SCREEN_H_ -#define VMW_SCREEN_H_ - - -#include "pipe/p_compiler.h" -#include "pipe/p_state.h" - -#include "svga_winsys.h" - - -#define VMW_GMR_POOL_SIZE (16*1024*1024) - - -struct pb_manager; -struct vmw_region; - - -struct vmw_winsys_screen -{ - struct svga_winsys_screen base; - - boolean use_old_scanout_flag; - - struct { - volatile uint32_t *fifo_map; - uint64_t last_fence; - int drm_fd; - } ioctl; - - struct { - struct pb_manager *gmr; - struct pb_manager *gmr_mm; - struct pb_manager *gmr_fenced; - } pools; -}; - - -static INLINE struct vmw_winsys_screen * -vmw_winsys_screen(struct svga_winsys_screen *base) -{ - return (struct vmw_winsys_screen *)base; -} - -/* */ -uint32 -vmw_ioctl_context_create(struct vmw_winsys_screen *vws); - -void -vmw_ioctl_context_destroy(struct vmw_winsys_screen *vws, - uint32 cid); - -uint32 -vmw_ioctl_surface_create(struct vmw_winsys_screen *vws, - SVGA3dSurfaceFlags flags, - SVGA3dSurfaceFormat format, - SVGA3dSize size, - uint32 numFaces, - uint32 numMipLevels); - -void -vmw_ioctl_surface_destroy(struct vmw_winsys_screen *vws, - uint32 sid); - -void -vmw_ioctl_command(struct vmw_winsys_screen *vws, - void *commands, - uint32_t size, - uint32_t *fence); - -struct vmw_region * -vmw_ioctl_region_create(struct vmw_winsys_screen *vws, uint32_t size); - -void -vmw_ioctl_region_destroy(struct vmw_region *region); - -struct SVGAGuestPtr -vmw_ioctl_region_ptr(struct vmw_region *region); - -void * -vmw_ioctl_region_map(struct vmw_region *region); -void -vmw_ioctl_region_unmap(struct vmw_region *region); - - -int -vmw_ioctl_fence_finish(struct vmw_winsys_screen *vws, - uint32_t fence); - -int -vmw_ioctl_fence_signalled(struct vmw_winsys_screen *vws, - uint32_t fence); - - -/* Initialize parts of vmw_winsys_screen at startup: - */ -boolean vmw_ioctl_init(struct vmw_winsys_screen *vws); -boolean vmw_pools_init(struct vmw_winsys_screen *vws); -boolean vmw_winsys_screen_init_svga(struct vmw_winsys_screen *vws); - -void vmw_ioctl_cleanup(struct vmw_winsys_screen *vws); -void vmw_pools_cleanup(struct vmw_winsys_screen *vws); - -struct vmw_winsys_screen *vmw_winsys_create(int fd, boolean use_old_scanout_flag); -void vmw_winsys_destroy(struct vmw_winsys_screen *sws); - - -#endif /* VMW_SCREEN_H_ */ diff --git a/src/gallium/winsys/drm/vmware/core/vmw_screen_dri.c b/src/gallium/winsys/drm/vmware/core/vmw_screen_dri.c deleted file mode 100644 index 657544dcb21..00000000000 --- a/src/gallium/winsys/drm/vmware/core/vmw_screen_dri.c +++ /dev/null @@ -1,373 +0,0 @@ -/********************************************************** - * Copyright 2009 VMware, Inc. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - **********************************************************/ - - -#include "pipe/p_compiler.h" -#include "util/u_inlines.h" -#include "util/u_memory.h" -#include "util/u_format.h" -#include "vmw_screen.h" - -#include "trace/tr_drm.h" - -#include "vmw_screen.h" -#include "vmw_surface.h" -#include "vmw_fence.h" -#include "vmw_context.h" - -#include -#include -#include -#include - -#include - -static struct svga_winsys_surface * -vmw_drm_surface_from_handle(struct svga_winsys_screen *sws, - struct winsys_handle *whandle, - SVGA3dSurfaceFormat *format); -static boolean -vmw_drm_surface_get_handle(struct svga_winsys_screen *sws, - struct svga_winsys_surface *surface, - unsigned stride, - struct winsys_handle *whandle); - -static struct dri1_api dri1_api_hooks; -static struct dri1_api_version ddx_required = { 0, 1, 0 }; -static struct dri1_api_version ddx_compat = { 0, 0, 0 }; -static struct dri1_api_version dri_required = { 4, 0, 0 }; -static struct dri1_api_version dri_compat = { 4, 0, 0 }; -static struct dri1_api_version drm_required = { 1, 0, 0 }; -static struct dri1_api_version drm_compat = { 1, 0, 0 }; -static struct dri1_api_version drm_scanout = { 0, 9, 0 }; - -static boolean -vmw_dri1_check_version(const struct dri1_api_version *cur, - const struct dri1_api_version *required, - const struct dri1_api_version *compat, - const char component[]) -{ - if (cur->major > required->major && cur->major <= compat->major) - return TRUE; - if (cur->major == required->major && cur->minor >= required->minor) - return TRUE; - - fprintf(stderr, "%s version failure.\n", component); - fprintf(stderr, "%s version is %d.%d.%d and this driver can only work\n" - "with versions %d.%d.x through %d.x.x.\n", - component, - cur->major, - cur->minor, - cur->patch_level, required->major, required->minor, compat->major); - return FALSE; -} - -/* This is actually the entrypoint to the entire driver, called by the - * libGL (or EGL, or ...) code via the drm_api_hooks table at the - * bottom of the file. - */ -static struct pipe_screen * -vmw_drm_create_screen(struct drm_api *drm_api, - int fd, - struct drm_create_screen_arg *arg) -{ - struct vmw_winsys_screen *vws; - struct pipe_screen *screen; - struct dri1_create_screen_arg *dri1; - boolean use_old_scanout_flag = FALSE; - - if (!arg || arg->mode == DRM_CREATE_NORMAL) { - struct dri1_api_version drm_ver; - drmVersionPtr ver; - - ver = drmGetVersion(fd); - if (ver == NULL) - return NULL; - - drm_ver.major = ver->version_major; - drm_ver.minor = ver->version_minor; - drm_ver.patch_level = 0; /* ??? */ - - drmFreeVersion(ver); - if (!vmw_dri1_check_version(&drm_ver, &drm_required, - &drm_compat, "vmwgfx drm driver")) - return NULL; - - if (!vmw_dri1_check_version(&drm_ver, &drm_scanout, - &drm_compat, "use old scanout field (not a error)")) - use_old_scanout_flag = TRUE; - } - - if (arg != NULL) { - switch (arg->mode) { - case DRM_CREATE_NORMAL: - break; - case DRM_CREATE_DRI1: - dri1 = (struct dri1_create_screen_arg *)arg; - if (!vmw_dri1_check_version(&dri1->ddx_version, &ddx_required, - &ddx_compat, "ddx - driver api")) - return NULL; - if (!vmw_dri1_check_version(&dri1->dri_version, &dri_required, - &dri_compat, "dri info")) - return NULL; - if (!vmw_dri1_check_version(&dri1->drm_version, &drm_required, - &drm_compat, "vmwgfx drm driver")) - return NULL; - if (!vmw_dri1_check_version(&dri1->drm_version, &drm_scanout, - &drm_compat, "use old scanout field (not a error)")) - use_old_scanout_flag = TRUE; - dri1->api = &dri1_api_hooks; -#if 0 - break; -#else - assert(!"No dri 1 support for now\n"); - return NULL; -#endif - default: - return NULL; - } - } - - vws = vmw_winsys_create( fd, use_old_scanout_flag ); - if (!vws) - goto out_no_vws; - - /* XXX do this properly */ - vws->base.surface_from_handle = vmw_drm_surface_from_handle; - vws->base.surface_get_handle = vmw_drm_surface_get_handle; - - screen = svga_screen_create( &vws->base ); - if (!screen) - goto out_no_screen; - - return screen; - - /* Failure cases: - */ -out_no_screen: - vmw_winsys_destroy( vws ); - -out_no_vws: - return NULL; -} - -static INLINE boolean -vmw_dri1_intersect_src_bbox(struct drm_clip_rect *dst, - int dst_x, - int dst_y, - const struct drm_clip_rect *src, - const struct drm_clip_rect *bbox) -{ - int xy1; - int xy2; - - xy1 = ((int)src->x1 > (int)bbox->x1 + dst_x) ? src->x1 : - (int)bbox->x1 + dst_x; - xy2 = ((int)src->x2 < (int)bbox->x2 + dst_x) ? src->x2 : - (int)bbox->x2 + dst_x; - if (xy1 >= xy2 || xy1 < 0) - return FALSE; - - dst->x1 = xy1; - dst->x2 = xy2; - - xy1 = ((int)src->y1 > (int)bbox->y1 + dst_y) ? src->y1 : - (int)bbox->y1 + dst_y; - xy2 = ((int)src->y2 < (int)bbox->y2 + dst_y) ? src->y2 : - (int)bbox->y2 + dst_y; - if (xy1 >= xy2 || xy1 < 0) - return FALSE; - - dst->y1 = xy1; - dst->y2 = xy2; - return TRUE; -} - -/** - * No fancy get-surface-from-sarea stuff here. - * Just use the present blit. - */ - -static void -vmw_dri1_present_locked(struct pipe_context *locked_pipe, - struct pipe_surface *surf, - const struct drm_clip_rect *rect, - unsigned int num_clip, - int x_draw, int y_draw, - const struct drm_clip_rect *bbox, - struct pipe_fence_handle **p_fence) -{ -#if 0 - struct svga_winsys_surface *srf = - svga_screen_texture_get_winsys_surface(surf->texture); - struct vmw_svga_winsys_surface *vsrf = vmw_svga_winsys_surface(srf); - struct vmw_winsys_screen *vws = - vmw_winsys_screen(svga_winsys_screen(locked_pipe->screen)); - struct drm_clip_rect clip; - int i; - struct - { - SVGA3dCmdHeader header; - SVGA3dCmdPresent body; - SVGA3dCopyRect rect; - } cmd; - boolean visible = FALSE; - uint32_t fence_seq = 0; - - VMW_FUNC; - cmd.header.id = SVGA_3D_CMD_PRESENT; - cmd.header.size = sizeof cmd.body + sizeof cmd.rect; - cmd.body.sid = vsrf->sid; - - for (i = 0; i < num_clip; ++i) { - if (!vmw_dri1_intersect_src_bbox(&clip, x_draw, y_draw, rect++, bbox)) - continue; - - cmd.rect.x = clip.x1; - cmd.rect.y = clip.y1; - cmd.rect.w = clip.x2 - clip.x1; - cmd.rect.h = clip.y2 - clip.y1; - cmd.rect.srcx = (int)clip.x1 - x_draw; - cmd.rect.srcy = (int)clip.y1 - y_draw; - - vmw_printf("%s: Clip %d x %d y %d w %d h %d srcx %d srcy %d\n", - __FUNCTION__, - i, - cmd.rect.x, - cmd.rect.y, - cmd.rect.w, cmd.rect.h, cmd.rect.srcx, cmd.rect.srcy); - - vmw_ioctl_command(vws, &cmd, sizeof cmd.header + cmd.header.size, - &fence_seq); - visible = TRUE; - } - - *p_fence = (visible) ? vmw_pipe_fence(fence_seq) : NULL; - vmw_svga_winsys_surface_reference(&vsrf, NULL); -#else - assert(!"No dri 1 support for now\n"); -#endif -} - -static struct svga_winsys_surface * -vmw_drm_surface_from_handle(struct svga_winsys_screen *sws, - struct winsys_handle *whandle, - SVGA3dSurfaceFormat *format) -{ - struct vmw_svga_winsys_surface *vsrf; - struct svga_winsys_surface *ssrf; - struct vmw_winsys_screen *vws = vmw_winsys_screen(sws); - union drm_vmw_surface_reference_arg arg; - struct drm_vmw_surface_arg *req = &arg.req; - struct drm_vmw_surface_create_req *rep = &arg.rep; - int ret; - int i; - - /** - * The vmware device specific handle is the hardware SID. - * FIXME: We probably want to move this to the ioctl implementations. - */ - - memset(&arg, 0, sizeof(arg)); - req->sid = whandle->handle; - - ret = drmCommandWriteRead(vws->ioctl.drm_fd, DRM_VMW_REF_SURFACE, - &arg, sizeof(arg)); - - if (ret) { - fprintf(stderr, "Failed referencing shared surface. SID %d.\n" - "Error %d (%s).\n", - whandle->handle, ret, strerror(-ret)); - return NULL; - } - - if (rep->mip_levels[0] != 1) { - fprintf(stderr, "Incorrect number of mipmap levels on shared surface." - " SID %d, levels %d\n", - whandle->handle, rep->mip_levels[0]); - goto out_mip; - } - - for (i=1; i < DRM_VMW_MAX_SURFACE_FACES; ++i) { - if (rep->mip_levels[i] != 0) { - fprintf(stderr, "Incorrect number of faces levels on shared surface." - " SID %d, face %d present.\n", - whandle->handle, i); - goto out_mip; - } - } - - vsrf = CALLOC_STRUCT(vmw_svga_winsys_surface); - if (!vsrf) - goto out_mip; - - pipe_reference_init(&vsrf->refcnt, 1); - p_atomic_set(&vsrf->validated, 0); - vsrf->screen = vws; - vsrf->sid = whandle->handle; - ssrf = svga_winsys_surface(vsrf); - *format = rep->format; - - return ssrf; - -out_mip: - vmw_ioctl_surface_destroy(vws, whandle->handle); - return NULL; -} - -static boolean -vmw_drm_surface_get_handle(struct svga_winsys_screen *sws, - struct svga_winsys_surface *surface, - unsigned stride, - struct winsys_handle *whandle) -{ - struct vmw_svga_winsys_surface *vsrf; - - if (!surface) - return FALSE; - - vsrf = vmw_svga_winsys_surface(surface); - whandle->handle = vsrf->sid; - whandle->stride = stride; - - return TRUE; -} - - -static struct dri1_api dri1_api_hooks = { - .front_srf_locked = NULL, - .present_locked = vmw_dri1_present_locked -}; - -static struct drm_api vmw_drm_api_hooks = { - .name = "vmwgfx", - .driver_name = "vmwgfx", - .create_screen = vmw_drm_create_screen, -}; - -struct drm_api* drm_api_create() -{ - return trace_drm_create(&vmw_drm_api_hooks); -} diff --git a/src/gallium/winsys/drm/vmware/core/vmw_screen_ioctl.c b/src/gallium/winsys/drm/vmware/core/vmw_screen_ioctl.c deleted file mode 100644 index 5d81fa8c4a6..00000000000 --- a/src/gallium/winsys/drm/vmware/core/vmw_screen_ioctl.c +++ /dev/null @@ -1,529 +0,0 @@ -/********************************************************** - * Copyright 2009 VMware, Inc. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - **********************************************************/ - -/** - * @file - * - * Wrappers for DRM ioctl functionlaity used by the rest of the vmw - * drm winsys. - * - * Based on svgaicd_escape.c - */ - - -#include "svga_cmd.h" -#include "util/u_memory.h" -#include "util/u_math.h" -#include "svgadump/svga_dump.h" -#include "vmw_screen.h" -#include "vmw_context.h" -#include "xf86drm.h" -#include "vmwgfx_drm.h" - -#include -#include -#include - -struct vmw_region -{ - SVGAGuestPtr ptr; - uint32_t handle; - uint64_t map_handle; - void *data; - uint32_t map_count; - int drm_fd; - uint32_t size; -}; - -/* XXX: This isn't a real hardware flag, but just a hack for kernel to - * know about primary surfaces. In newer versions of the kernel - * interface the driver uses a special field. - */ -#define SVGA3D_SURFACE_HINT_SCANOUT (1 << 9) - -static void -vmw_check_last_cmd(struct vmw_winsys_screen *vws) -{ - static uint32_t buffer[16384]; - struct drm_vmw_fifo_debug_arg arg; - int ret; - - return; - memset(&arg, 0, sizeof(arg)); - arg.debug_buffer = (unsigned long)buffer; - arg.debug_buffer_size = 65536; - - ret = drmCommandWriteRead(vws->ioctl.drm_fd, DRM_VMW_FIFO_DEBUG, - &arg, sizeof(arg)); - - if (ret) { - debug_printf("%s Ioctl error: \"%s\".\n", __FUNCTION__, strerror(-ret)); - return; - } - - if (arg.did_not_fit) { - debug_printf("%s Command did not fit completely.\n", __FUNCTION__); - } - - svga_dump_commands(buffer, arg.used_size); -} - -static void -vmw_ioctl_fifo_unmap(struct vmw_winsys_screen *vws, void *mapping) -{ - VMW_FUNC; - (void)munmap(mapping, getpagesize()); -} - - -static void * -vmw_ioctl_fifo_map(struct vmw_winsys_screen *vws, - uint32_t fifo_offset ) -{ - void *map; - - VMW_FUNC; - - map = mmap(NULL, getpagesize(), PROT_READ, MAP_SHARED, - vws->ioctl.drm_fd, fifo_offset); - - if (map == MAP_FAILED) { - debug_printf("Map failed %s\n", strerror(errno)); - return NULL; - } - - vmw_printf("Fifo (min) is 0x%08x\n", ((uint32_t *) map)[SVGA_FIFO_MIN]); - - return map; -} - -uint32 -vmw_ioctl_context_create(struct vmw_winsys_screen *vws) -{ - struct drm_vmw_context_arg c_arg; - int ret; - - VMW_FUNC; - - ret = drmCommandRead(vws->ioctl.drm_fd, DRM_VMW_CREATE_CONTEXT, - &c_arg, sizeof(c_arg)); - - if (ret) - return -1; - - vmw_check_last_cmd(vws); - vmw_printf("Context id is %d\n", c_arg.cid); - - return c_arg.cid; -} - -void -vmw_ioctl_context_destroy(struct vmw_winsys_screen *vws, uint32 cid) -{ - struct drm_vmw_context_arg c_arg; - - VMW_FUNC; - - memset(&c_arg, 0, sizeof(c_arg)); - c_arg.cid = cid; - - (void)drmCommandWrite(vws->ioctl.drm_fd, DRM_VMW_UNREF_CONTEXT, - &c_arg, sizeof(c_arg)); - - vmw_check_last_cmd(vws); -} - -uint32 -vmw_ioctl_surface_create(struct vmw_winsys_screen *vws, - SVGA3dSurfaceFlags flags, - SVGA3dSurfaceFormat format, - SVGA3dSize size, - uint32_t numFaces, uint32_t numMipLevels) -{ - union drm_vmw_surface_create_arg s_arg; - struct drm_vmw_surface_create_req *req = &s_arg.req; - struct drm_vmw_surface_arg *rep = &s_arg.rep; - struct drm_vmw_size sizes[DRM_VMW_MAX_SURFACE_FACES* - DRM_VMW_MAX_MIP_LEVELS]; - struct drm_vmw_size *cur_size; - uint32_t iFace; - uint32_t iMipLevel; - int ret; - - vmw_printf("%s flags %d format %d\n", __FUNCTION__, flags, format); - - memset(&s_arg, 0, sizeof(s_arg)); - if (vws->use_old_scanout_flag && - (flags & SVGA3D_SURFACE_HINT_SCANOUT)) { - req->flags = (uint32_t) flags; - req->scanout = false; - } else if (flags & SVGA3D_SURFACE_HINT_SCANOUT) { - req->flags = (uint32_t) (flags & ~SVGA3D_SURFACE_HINT_SCANOUT); - req->scanout = true; - } else { - req->flags = (uint32_t) flags; - req->scanout = false; - } - req->format = (uint32_t) format; - req->shareable = 1; - - assert(numFaces * numMipLevels < DRM_VMW_MAX_SURFACE_FACES* - DRM_VMW_MAX_MIP_LEVELS); - cur_size = sizes; - for (iFace = 0; iFace < numFaces; ++iFace) { - SVGA3dSize mipSize = size; - - req->mip_levels[iFace] = numMipLevels; - for (iMipLevel = 0; iMipLevel < numMipLevels; ++iMipLevel) { - cur_size->width = mipSize.width; - cur_size->height = mipSize.height; - cur_size->depth = mipSize.depth; - mipSize.width = MAX2(mipSize.width >> 1, 1); - mipSize.height = MAX2(mipSize.height >> 1, 1); - mipSize.depth = MAX2(mipSize.depth >> 1, 1); - cur_size++; - } - } - for (iFace = numFaces; iFace < SVGA3D_MAX_SURFACE_FACES; ++iFace) { - req->mip_levels[iFace] = 0; - } - - req->size_addr = (unsigned long)&sizes; - - ret = drmCommandWriteRead(vws->ioctl.drm_fd, DRM_VMW_CREATE_SURFACE, - &s_arg, sizeof(s_arg)); - - if (ret) - return -1; - - vmw_printf("Surface id is %d\n", rep->sid); - vmw_check_last_cmd(vws); - - return rep->sid; -} - -void -vmw_ioctl_surface_destroy(struct vmw_winsys_screen *vws, uint32 sid) -{ - struct drm_vmw_surface_arg s_arg; - - VMW_FUNC; - - memset(&s_arg, 0, sizeof(s_arg)); - s_arg.sid = sid; - - (void)drmCommandWrite(vws->ioctl.drm_fd, DRM_VMW_UNREF_SURFACE, - &s_arg, sizeof(s_arg)); - vmw_check_last_cmd(vws); - -} - -void -vmw_ioctl_command(struct vmw_winsys_screen *vws, void *commands, uint32_t size, - uint32_t * pfence) -{ - struct drm_vmw_execbuf_arg arg; - struct drm_vmw_fence_rep rep; - int ret; - -#ifdef DEBUG - { - static boolean firsttime = TRUE; - static boolean debug = FALSE; - static boolean skip = FALSE; - if (firsttime) { - debug = debug_get_bool_option("SVGA_DUMP_CMD", FALSE); - skip = debug_get_bool_option("SVGA_SKIP_CMD", FALSE); - } - if (debug) { - VMW_FUNC; - svga_dump_commands(commands, size); - } - firsttime = FALSE; - if (skip) { - size = 0; - } - } -#endif - - memset(&arg, 0, sizeof(arg)); - memset(&rep, 0, sizeof(rep)); - - rep.error = -EFAULT; - arg.fence_rep = (unsigned long)&rep; - arg.commands = (unsigned long)commands; - arg.command_size = size; - - do { - ret = drmCommandWrite(vws->ioctl.drm_fd, DRM_VMW_EXECBUF, &arg, sizeof(arg)); - } while(ret == -ERESTART); - if (ret) { - debug_printf("%s error %s.\n", __FUNCTION__, strerror(-ret)); - } - if (rep.error) { - - /* - * Kernel has synced and put the last fence sequence in the FIFO - * register. - */ - - if (rep.error == -EFAULT) - rep.fence_seq = vws->ioctl.fifo_map[SVGA_FIFO_FENCE]; - - debug_printf("%s Fence error %s.\n", __FUNCTION__, - strerror(-rep.error)); - } - - vws->ioctl.last_fence = rep.fence_seq; - - if (pfence) - *pfence = rep.fence_seq; - vmw_check_last_cmd(vws); - -} - - -struct vmw_region * -vmw_ioctl_region_create(struct vmw_winsys_screen *vws, uint32_t size) -{ - struct vmw_region *region; - union drm_vmw_alloc_dmabuf_arg arg; - struct drm_vmw_alloc_dmabuf_req *req = &arg.req; - struct drm_vmw_dmabuf_rep *rep = &arg.rep; - int ret; - - vmw_printf("%s: size = %u\n", __FUNCTION__, size); - - region = CALLOC_STRUCT(vmw_region); - if (!region) - goto out_err1; - - memset(&arg, 0, sizeof(arg)); - req->size = size; - do { - ret = drmCommandWriteRead(vws->ioctl.drm_fd, DRM_VMW_ALLOC_DMABUF, &arg, - sizeof(arg)); - } while (ret == -ERESTART); - - if (ret) { - debug_printf("IOCTL failed %d: %s\n", ret, strerror(-ret)); - goto out_err1; - } - - region->ptr.gmrId = rep->cur_gmr_id; - region->ptr.offset = rep->cur_gmr_offset; - region->data = NULL; - region->handle = rep->handle; - region->map_handle = rep->map_handle; - region->map_count = 0; - region->size = size; - region->drm_fd = vws->ioctl.drm_fd; - - vmw_printf(" gmrId = %u, offset = %u\n", - region->ptr.gmrId, region->ptr.offset); - - return region; - - out_err1: - FREE(region); - return NULL; -} - -void -vmw_ioctl_region_destroy(struct vmw_region *region) -{ - struct drm_vmw_unref_dmabuf_arg arg; - - vmw_printf("%s: gmrId = %u, offset = %u\n", __FUNCTION__, - region->ptr.gmrId, region->ptr.offset); - - if (region->data) { - munmap(region->data, region->size); - region->data = NULL; - } - - memset(&arg, 0, sizeof(arg)); - arg.handle = region->handle; - drmCommandWrite(region->drm_fd, DRM_VMW_UNREF_DMABUF, &arg, sizeof(arg)); - - FREE(region); -} - -SVGAGuestPtr -vmw_ioctl_region_ptr(struct vmw_region *region) -{ - return region->ptr; -} - -void * -vmw_ioctl_region_map(struct vmw_region *region) -{ - void *map; - - vmw_printf("%s: gmrId = %u, offset = %u\n", __FUNCTION__, - region->ptr.gmrId, region->ptr.offset); - - if (region->data == NULL) { - map = mmap(NULL, region->size, PROT_READ | PROT_WRITE, MAP_SHARED, - region->drm_fd, region->map_handle); - if (map == MAP_FAILED) { - debug_printf("%s: Map failed.\n", __FUNCTION__); - return NULL; - } - - region->data = map; - } - - ++region->map_count; - - return region->data; -} - -void -vmw_ioctl_region_unmap(struct vmw_region *region) -{ - vmw_printf("%s: gmrId = %u, offset = %u\n", __FUNCTION__, - region->ptr.gmrId, region->ptr.offset); - --region->map_count; -} - - -int -vmw_ioctl_fence_signalled(struct vmw_winsys_screen *vws, - uint32_t fence) -{ - uint32_t expected; - uint32_t current; - - assert(fence); - if(!fence) - return 0; - - expected = fence; - current = vws->ioctl.fifo_map[SVGA_FIFO_FENCE]; - - if ((int32)(current - expected) >= 0) - return 0; /* fence passed */ - else - return -1; -} - - -static void -vmw_ioctl_sync(struct vmw_winsys_screen *vws, - uint32_t fence) -{ - uint32_t cur_fence; - struct drm_vmw_fence_wait_arg arg; - int ret; - - vmw_printf("%s: fence = %lu\n", __FUNCTION__, - (unsigned long)fence); - - cur_fence = vws->ioctl.fifo_map[SVGA_FIFO_FENCE]; - vmw_printf("%s: Fence id read is 0x%08x\n", __FUNCTION__, - (unsigned int)cur_fence); - - if ((cur_fence - fence) < (1 << 24)) - return; - - memset(&arg, 0, sizeof(arg)); - arg.sequence = fence; - - do { - ret = drmCommandWriteRead(vws->ioctl.drm_fd, DRM_VMW_FENCE_WAIT, &arg, - sizeof(arg)); - } while (ret == -ERESTART); -} - - -int -vmw_ioctl_fence_finish(struct vmw_winsys_screen *vws, - uint32_t fence) -{ - assert(fence); - - if(fence) { - if(vmw_ioctl_fence_signalled(vws, fence) != 0) { - vmw_ioctl_sync(vws, fence); - } - } - - return 0; -} - - -boolean -vmw_ioctl_init(struct vmw_winsys_screen *vws) -{ - struct drm_vmw_getparam_arg gp_arg; - int ret; - - VMW_FUNC; - - memset(&gp_arg, 0, sizeof(gp_arg)); - gp_arg.param = DRM_VMW_PARAM_3D; - ret = drmCommandWriteRead(vws->ioctl.drm_fd, DRM_VMW_GET_PARAM, - &gp_arg, sizeof(gp_arg)); - if (ret || gp_arg.value == 0) { - debug_printf("No 3D enabled (%i, %s)\n", ret, strerror(-ret)); - goto out_err1; - } - - memset(&gp_arg, 0, sizeof(gp_arg)); - gp_arg.param = DRM_VMW_PARAM_FIFO_OFFSET; - ret = drmCommandWriteRead(vws->ioctl.drm_fd, DRM_VMW_GET_PARAM, - &gp_arg, sizeof(gp_arg)); - - if (ret) { - debug_printf("GET_PARAM on %d returned %d: %s\n", - vws->ioctl.drm_fd, ret, strerror(-ret)); - goto out_err1; - } - - vmw_printf("Offset to map is 0x%08llx\n", - (unsigned long long)gp_arg.value); - - vws->ioctl.fifo_map = vmw_ioctl_fifo_map(vws, gp_arg.value); - if (vws->ioctl.fifo_map == NULL) - goto out_err1; - - vmw_printf("%s OK\n", __FUNCTION__); - return TRUE; - - out_err1: - debug_printf("%s Failed\n", __FUNCTION__); - return FALSE; -} - - - -void -vmw_ioctl_cleanup(struct vmw_winsys_screen *vws) -{ - VMW_FUNC; - - vmw_ioctl_fifo_unmap(vws, (void *)vws->ioctl.fifo_map); -} diff --git a/src/gallium/winsys/drm/vmware/core/vmw_screen_pools.c b/src/gallium/winsys/drm/vmware/core/vmw_screen_pools.c deleted file mode 100644 index b9823d78575..00000000000 --- a/src/gallium/winsys/drm/vmware/core/vmw_screen_pools.c +++ /dev/null @@ -1,97 +0,0 @@ -/********************************************************** - * Copyright 2009 VMware, Inc. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - **********************************************************/ - - -#include "vmw_screen.h" - -#include "vmw_buffer.h" -#include "vmw_fence.h" - -#include "pipebuffer/pb_buffer.h" -#include "pipebuffer/pb_bufmgr.h" - -void -vmw_pools_cleanup(struct vmw_winsys_screen *vws) -{ - if(vws->pools.gmr_fenced) - vws->pools.gmr_fenced->destroy(vws->pools.gmr_fenced); - - /* gmr_mm pool is already destroyed above */ - - if(vws->pools.gmr) - vws->pools.gmr->destroy(vws->pools.gmr); -} - - -boolean -vmw_pools_init(struct vmw_winsys_screen *vws) -{ - vws->pools.gmr = vmw_gmr_bufmgr_create(vws); - if(!vws->pools.gmr) - goto error; - - vws->pools.gmr_mm = mm_bufmgr_create(vws->pools.gmr, - VMW_GMR_POOL_SIZE, - 12 /* 4096 alignment */); - if(!vws->pools.gmr_mm) - goto error; - - /* - * GMR buffers are typically shortlived, but it's possible that at a given - * instance a buffer is mapped. So to avoid stalling we tell pipebuffer to - * forbid creation of buffers beyond half the GMR pool size, - * - * XXX: It is unclear weather we want to limit the total amount of temporary - * malloc memory used to backup unvalidated GMR buffers. On one hand it is - * preferrable to fail an allocation than exhausting the guest memory with - * temporary data, but on the other hand it is possible that a stupid - * application creates large vertex buffers and does not use them for a long - * time -- since the svga pipe driver only emits the DMA uploads when a - * buffer is used for drawing this would effectively disabling swapping GMR - * buffers to memory. So far, the preemptively flush already seems to keep - * total allocated memory within relatively small numbers, so we don't - * limit. - */ - vws->pools.gmr_fenced = fenced_bufmgr_create( - vws->pools.gmr_mm, - vmw_fence_ops_create(vws), - VMW_GMR_POOL_SIZE/2, - ~0); - -#ifdef DEBUG - vws->pools.gmr_fenced = pb_debug_manager_create(vws->pools.gmr_fenced, - 4096, - 4096); -#endif - if(!vws->pools.gmr_fenced) - goto error; - - return TRUE; - -error: - vmw_pools_cleanup(vws); - return FALSE; -} - diff --git a/src/gallium/winsys/drm/vmware/core/vmw_screen_svga.c b/src/gallium/winsys/drm/vmware/core/vmw_screen_svga.c deleted file mode 100644 index 2b4e80f0039..00000000000 --- a/src/gallium/winsys/drm/vmware/core/vmw_screen_svga.c +++ /dev/null @@ -1,295 +0,0 @@ -/********************************************************** - * Copyright 2009 VMware, Inc. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - **********************************************************/ - -/** - * @file - * This file implements the SVGA interface into this winsys, defined - * in drivers/svga/svga_winsys.h. - * - * @author Keith Whitwell - * @author Jose Fonseca - */ - - -#include "svga_cmd.h" -#include "svga3d_caps.h" - -#include "util/u_inlines.h" -#include "util/u_math.h" -#include "util/u_memory.h" -#include "pipebuffer/pb_buffer.h" -#include "pipebuffer/pb_bufmgr.h" -#include "svga_winsys.h" -#include "vmw_context.h" -#include "vmw_screen.h" -#include "vmw_surface.h" -#include "vmw_buffer.h" -#include "vmw_fence.h" - - -static struct svga_winsys_buffer * -vmw_svga_winsys_buffer_create(struct svga_winsys_screen *sws, - unsigned alignment, - unsigned usage, - unsigned size) -{ - struct vmw_winsys_screen *vws = vmw_winsys_screen(sws); - struct pb_desc desc; - struct pb_manager *provider; - struct pb_buffer *buffer; - - memset(&desc, 0, sizeof desc); - desc.alignment = alignment; - desc.usage = usage; - - provider = vws->pools.gmr_fenced; - - assert(provider); - buffer = provider->create_buffer(provider, size, &desc); - if(!buffer) - return NULL; - - return vmw_svga_winsys_buffer(buffer); -} - - -static void * -vmw_svga_winsys_buffer_map(struct svga_winsys_screen *sws, - struct svga_winsys_buffer *buf, - unsigned flags) -{ - (void)sws; - return pb_map(vmw_pb_buffer(buf), flags); -} - - -static void -vmw_svga_winsys_buffer_unmap(struct svga_winsys_screen *sws, - struct svga_winsys_buffer *buf) -{ - (void)sws; - pb_unmap(vmw_pb_buffer(buf)); -} - - -static void -vmw_svga_winsys_buffer_destroy(struct svga_winsys_screen *sws, - struct svga_winsys_buffer *buf) -{ - struct pb_buffer *pbuf = vmw_pb_buffer(buf); - (void)sws; - pb_reference(&pbuf, NULL); -} - - -static void -vmw_svga_winsys_fence_reference(struct svga_winsys_screen *sws, - struct pipe_fence_handle **pdst, - struct pipe_fence_handle *src) -{ - (void)sws; - *pdst = src; -} - - -static int -vmw_svga_winsys_fence_signalled(struct svga_winsys_screen *sws, - struct pipe_fence_handle *fence, - unsigned flag) -{ - struct vmw_winsys_screen *vws = vmw_winsys_screen(sws); - (void)flag; - return vmw_ioctl_fence_signalled(vws, vmw_fence(fence)); -} - - -static int -vmw_svga_winsys_fence_finish(struct svga_winsys_screen *sws, - struct pipe_fence_handle *fence, - unsigned flag) -{ - struct vmw_winsys_screen *vws = vmw_winsys_screen(sws); - (void)flag; - return vmw_ioctl_fence_finish(vws, vmw_fence(fence)); -} - - - -static struct svga_winsys_surface * -vmw_svga_winsys_surface_create(struct svga_winsys_screen *sws, - SVGA3dSurfaceFlags flags, - SVGA3dSurfaceFormat format, - SVGA3dSize size, - uint32 numFaces, - uint32 numMipLevels) -{ - struct vmw_winsys_screen *vws = vmw_winsys_screen(sws); - struct vmw_svga_winsys_surface *surface; - - surface = CALLOC_STRUCT(vmw_svga_winsys_surface); - if(!surface) - goto no_surface; - - pipe_reference_init(&surface->refcnt, 1); - p_atomic_set(&surface->validated, 0); - surface->screen = vws; - surface->sid = vmw_ioctl_surface_create(vws, - flags, format, size, - numFaces, numMipLevels); - if(surface->sid == SVGA3D_INVALID_ID) - goto no_sid; - - return svga_winsys_surface(surface); - -no_sid: - FREE(surface); -no_surface: - return NULL; -} - - -static boolean -vmw_svga_winsys_surface_is_flushed(struct svga_winsys_screen *sws, - struct svga_winsys_surface *surface) -{ - struct vmw_svga_winsys_surface *vsurf = vmw_svga_winsys_surface(surface); - return (p_atomic_read(&vsurf->validated) == 0); -} - - -static void -vmw_svga_winsys_surface_ref(struct svga_winsys_screen *sws, - struct svga_winsys_surface **pDst, - struct svga_winsys_surface *src) -{ - struct vmw_svga_winsys_surface *d_vsurf = vmw_svga_winsys_surface(*pDst); - struct vmw_svga_winsys_surface *s_vsurf = vmw_svga_winsys_surface(src); - - vmw_svga_winsys_surface_reference(&d_vsurf, s_vsurf); - *pDst = svga_winsys_surface(d_vsurf); -} - - -static void -vmw_svga_winsys_destroy(struct svga_winsys_screen *sws) -{ - struct vmw_winsys_screen *vws = vmw_winsys_screen(sws); - - vmw_winsys_destroy(vws); -} - - -static boolean -vmw_svga_winsys_get_cap(struct svga_winsys_screen *sws, - SVGA3dDevCapIndex index, - SVGA3dDevCapResult *result) -{ - struct vmw_winsys_screen *vws = vmw_winsys_screen(sws); - const uint32 *capsBlock; - const SVGA3dCapsRecord *capsRecord = NULL; - uint32 offset; - const SVGA3dCapPair *capArray; - int numCaps, first, last; - - if(!vws->ioctl.fifo_map) - return FALSE; - - if(vws->ioctl.fifo_map[SVGA_FIFO_3D_HWVERSION] < SVGA3D_HWVERSION_WS6_B1) - return FALSE; - - /* - * Search linearly through the caps block records for the specified type. - */ - capsBlock = (const uint32 *)&vws->ioctl.fifo_map[SVGA_FIFO_3D_CAPS]; - for (offset = 0; capsBlock[offset] != 0; offset += capsBlock[offset]) { - const SVGA3dCapsRecord *record; - assert(offset < SVGA_FIFO_3D_CAPS_SIZE); - record = (const SVGA3dCapsRecord *) (capsBlock + offset); - if ((record->header.type >= SVGA3DCAPS_RECORD_DEVCAPS_MIN) && - (record->header.type <= SVGA3DCAPS_RECORD_DEVCAPS_MAX) && - (!capsRecord || (record->header.type > capsRecord->header.type))) { - capsRecord = record; - } - } - - if(!capsRecord) - return FALSE; - - /* - * Calculate the number of caps from the size of the record. - */ - capArray = (const SVGA3dCapPair *) capsRecord->data; - numCaps = (int) ((capsRecord->header.length * sizeof(uint32) - - sizeof capsRecord->header) / (2 * sizeof(uint32))); - - /* - * Binary-search for the cap with the specified index. - */ - for (first = 0, last = numCaps - 1; first <= last; ) { - int mid = (first + last) / 2; - - if ((SVGA3dDevCapIndex) capArray[mid][0] == index) { - /* - * Found it. - */ - result->u = capArray[mid][1]; - return TRUE; - } - - /* - * Divide and conquer. - */ - if ((SVGA3dDevCapIndex) capArray[mid][0] > index) { - last = mid - 1; - } else { - first = mid + 1; - } - } - - return FALSE; -} - - -boolean -vmw_winsys_screen_init_svga(struct vmw_winsys_screen *vws) -{ - vws->base.destroy = vmw_svga_winsys_destroy; - vws->base.get_cap = vmw_svga_winsys_get_cap; - vws->base.context_create = vmw_svga_winsys_context_create; - vws->base.surface_create = vmw_svga_winsys_surface_create; - vws->base.surface_is_flushed = vmw_svga_winsys_surface_is_flushed; - vws->base.surface_reference = vmw_svga_winsys_surface_ref; - vws->base.buffer_create = vmw_svga_winsys_buffer_create; - vws->base.buffer_map = vmw_svga_winsys_buffer_map; - vws->base.buffer_unmap = vmw_svga_winsys_buffer_unmap; - vws->base.buffer_destroy = vmw_svga_winsys_buffer_destroy; - vws->base.fence_reference = vmw_svga_winsys_fence_reference; - vws->base.fence_signalled = vmw_svga_winsys_fence_signalled; - vws->base.fence_finish = vmw_svga_winsys_fence_finish; - - return TRUE; -} - - diff --git a/src/gallium/winsys/drm/vmware/core/vmw_surface.c b/src/gallium/winsys/drm/vmware/core/vmw_surface.c deleted file mode 100644 index 5f1b9ad5770..00000000000 --- a/src/gallium/winsys/drm/vmware/core/vmw_surface.c +++ /dev/null @@ -1,61 +0,0 @@ -/********************************************************** - * Copyright 2009 VMware, Inc. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - **********************************************************/ - - -#include "svga_cmd.h" -#include "util/u_debug.h" -#include "util/u_memory.h" - -#include "vmw_surface.h" -#include "vmw_screen.h" - -void -vmw_svga_winsys_surface_reference(struct vmw_svga_winsys_surface **pdst, - struct vmw_svga_winsys_surface *src) -{ - struct pipe_reference *src_ref; - struct pipe_reference *dst_ref; - struct vmw_svga_winsys_surface *dst; - - if(pdst == NULL || *pdst == src) - return; - - dst = *pdst; - - src_ref = src ? &src->refcnt : NULL; - dst_ref = dst ? &dst->refcnt : NULL; - - if (pipe_reference(dst_ref, src_ref)) { - vmw_ioctl_surface_destroy(dst->screen, dst->sid); -#ifdef DEBUG - /* to detect dangling pointers */ - assert(p_atomic_read(&dst->validated) == 0); - dst->sid = SVGA3D_INVALID_ID; -#endif - FREE(dst); - } - - *pdst = src; -} diff --git a/src/gallium/winsys/drm/vmware/core/vmw_surface.h b/src/gallium/winsys/drm/vmware/core/vmw_surface.h deleted file mode 100644 index 3d61595c288..00000000000 --- a/src/gallium/winsys/drm/vmware/core/vmw_surface.h +++ /dev/null @@ -1,79 +0,0 @@ -/********************************************************** - * Copyright 2009 VMware, Inc. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - **********************************************************/ - -/** - * @file - * Surfaces for VMware SVGA winsys. - * - * @author Jose Fonseca - */ - - -#ifndef VMW_SURFACE_H_ -#define VMW_SURFACE_H_ - - -#include "pipe/p_compiler.h" -#include "util/u_atomic.h" -#include "util/u_inlines.h" - -#define VMW_MAX_PRESENTS 3 - - - -struct vmw_svga_winsys_surface -{ - int32_t validated; /* atomic */ - struct pipe_reference refcnt; - - struct vmw_winsys_screen *screen; - uint32_t sid; - - /* FIXME: make this thread safe */ - unsigned next_present_no; - uint32_t present_fences[VMW_MAX_PRESENTS]; -}; - - -static INLINE struct svga_winsys_surface * -svga_winsys_surface(struct vmw_svga_winsys_surface *surf) -{ - assert(!surf || surf->sid != SVGA3D_INVALID_ID); - return (struct svga_winsys_surface *)surf; -} - - -static INLINE struct vmw_svga_winsys_surface * -vmw_svga_winsys_surface(struct svga_winsys_surface *surf) -{ - return (struct vmw_svga_winsys_surface *)surf; -} - - -void -vmw_svga_winsys_surface_reference(struct vmw_svga_winsys_surface **pdst, - struct vmw_svga_winsys_surface *src); - -#endif /* VMW_SURFACE_H_ */ diff --git a/src/gallium/winsys/drm/vmware/core/vmwgfx_drm.h b/src/gallium/winsys/drm/vmware/core/vmwgfx_drm.h deleted file mode 100644 index 47914bdb711..00000000000 --- a/src/gallium/winsys/drm/vmware/core/vmwgfx_drm.h +++ /dev/null @@ -1,545 +0,0 @@ -/************************************************************************** - * - * Copyright © 2009 VMware, Inc., Palo Alto, CA., USA - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL - * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE - * USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -#ifndef __VMWGFX_DRM_H__ -#define __VMWGFX_DRM_H__ - -#define DRM_VMW_MAX_SURFACE_FACES 6 -#define DRM_VMW_MAX_MIP_LEVELS 24 - -#define DRM_VMW_EXT_NAME_LEN 128 - -#define DRM_VMW_GET_PARAM 0 -#define DRM_VMW_ALLOC_DMABUF 1 -#define DRM_VMW_UNREF_DMABUF 2 -#define DRM_VMW_CURSOR_BYPASS 3 -/* guarded by DRM_VMW_PARAM_NUM_STREAMS != 0*/ -#define DRM_VMW_CONTROL_STREAM 4 -#define DRM_VMW_CLAIM_STREAM 5 -#define DRM_VMW_UNREF_STREAM 6 -/* guarded by DRM_VMW_PARAM_3D == 1 */ -#define DRM_VMW_CREATE_CONTEXT 7 -#define DRM_VMW_UNREF_CONTEXT 8 -#define DRM_VMW_CREATE_SURFACE 9 -#define DRM_VMW_UNREF_SURFACE 10 -#define DRM_VMW_REF_SURFACE 11 -#define DRM_VMW_EXECBUF 12 -#define DRM_VMW_FIFO_DEBUG 13 -#define DRM_VMW_FENCE_WAIT 14 - - -/*************************************************************************/ -/** - * DRM_VMW_GET_PARAM - get device information. - * - * DRM_VMW_PARAM_FIFO_OFFSET: - * Offset to use to map the first page of the FIFO read-only. - * The fifo is mapped using the mmap() system call on the drm device. - * - * DRM_VMW_PARAM_OVERLAY_IOCTL: - * Does the driver support the overlay ioctl. - */ - -#define DRM_VMW_PARAM_NUM_STREAMS 0 -#define DRM_VMW_PARAM_NUM_FREE_STREAMS 1 -#define DRM_VMW_PARAM_3D 2 -#define DRM_VMW_PARAM_FIFO_OFFSET 3 -#define DRM_VMW_PARAM_HW_CAPS 4 -#define DRM_VMW_PARAM_FIFO_CAPS 5 - -/** - * struct drm_vmw_getparam_arg - * - * @value: Returned value. //Out - * @param: Parameter to query. //In. - * - * Argument to the DRM_VMW_GET_PARAM Ioctl. - */ - -struct drm_vmw_getparam_arg { - uint64_t value; - uint32_t param; - uint32_t pad64; -}; - -/*************************************************************************/ -/** - * DRM_VMW_CREATE_CONTEXT - Create a host context. - * - * Allocates a device unique context id, and queues a create context command - * for the host. Does not wait for host completion. - */ - -/** - * struct drm_vmw_context_arg - * - * @cid: Device unique context ID. - * - * Output argument to the DRM_VMW_CREATE_CONTEXT Ioctl. - * Input argument to the DRM_VMW_UNREF_CONTEXT Ioctl. - */ - -struct drm_vmw_context_arg { - int32_t cid; - uint32_t pad64; -}; - -/*************************************************************************/ -/** - * DRM_VMW_UNREF_CONTEXT - Create a host context. - * - * Frees a global context id, and queues a destroy host command for the host. - * Does not wait for host completion. The context ID can be used directly - * in the command stream and shows up as the same context ID on the host. - */ - -/*************************************************************************/ -/** - * DRM_VMW_CREATE_SURFACE - Create a host suface. - * - * Allocates a device unique surface id, and queues a create surface command - * for the host. Does not wait for host completion. The surface ID can be - * used directly in the command stream and shows up as the same surface - * ID on the host. - */ - -/** - * struct drm_wmv_surface_create_req - * - * @flags: Surface flags as understood by the host. - * @format: Surface format as understood by the host. - * @mip_levels: Number of mip levels for each face. - * An unused face should have 0 encoded. - * @size_addr: Address of a user-space array of sruct drm_vmw_size - * cast to an uint64_t for 32-64 bit compatibility. - * The size of the array should equal the total number of mipmap levels. - * @shareable: Boolean whether other clients (as identified by file descriptors) - * may reference this surface. - * @scanout: Boolean whether the surface is intended to be used as a - * scanout. - * - * Input data to the DRM_VMW_CREATE_SURFACE Ioctl. - * Output data from the DRM_VMW_REF_SURFACE Ioctl. - */ - -struct drm_vmw_surface_create_req { - uint32_t flags; - uint32_t format; - uint32_t mip_levels[DRM_VMW_MAX_SURFACE_FACES]; - uint64_t size_addr; - int32_t shareable; - int32_t scanout; -}; - -/** - * struct drm_wmv_surface_arg - * - * @sid: Surface id of created surface or surface to destroy or reference. - * - * Output data from the DRM_VMW_CREATE_SURFACE Ioctl. - * Input argument to the DRM_VMW_UNREF_SURFACE Ioctl. - * Input argument to the DRM_VMW_REF_SURFACE Ioctl. - */ - -struct drm_vmw_surface_arg { - int32_t sid; - uint32_t pad64; -}; - -/** - * struct drm_vmw_size ioctl. - * - * @width - mip level width - * @height - mip level height - * @depth - mip level depth - * - * Description of a mip level. - * Input data to the DRM_WMW_CREATE_SURFACE Ioctl. - */ - -struct drm_vmw_size { - uint32_t width; - uint32_t height; - uint32_t depth; - uint32_t pad64; -}; - -/** - * union drm_vmw_surface_create_arg - * - * @rep: Output data as described above. - * @req: Input data as described above. - * - * Argument to the DRM_VMW_CREATE_SURFACE Ioctl. - */ - -union drm_vmw_surface_create_arg { - struct drm_vmw_surface_arg rep; - struct drm_vmw_surface_create_req req; -}; - -/*************************************************************************/ -/** - * DRM_VMW_REF_SURFACE - Reference a host surface. - * - * Puts a reference on a host surface with a give sid, as previously - * returned by the DRM_VMW_CREATE_SURFACE ioctl. - * A reference will make sure the surface isn't destroyed while we hold - * it and will allow the calling client to use the surface ID in the command - * stream. - * - * On successful return, the Ioctl returns the surface information given - * in the DRM_VMW_CREATE_SURFACE ioctl. - */ - -/** - * union drm_vmw_surface_reference_arg - * - * @rep: Output data as described above. - * @req: Input data as described above. - * - * Argument to the DRM_VMW_REF_SURFACE Ioctl. - */ - -union drm_vmw_surface_reference_arg { - struct drm_vmw_surface_create_req rep; - struct drm_vmw_surface_arg req; -}; - -/*************************************************************************/ -/** - * DRM_VMW_UNREF_SURFACE - Unreference a host surface. - * - * Clear a reference previously put on a host surface. - * When all references are gone, including the one implicitly placed - * on creation, - * a destroy surface command will be queued for the host. - * Does not wait for completion. - */ - -/*************************************************************************/ -/** - * DRM_VMW_EXECBUF - * - * Submit a command buffer for execution on the host, and return a - * fence sequence that when signaled, indicates that the command buffer has - * executed. - */ - -/** - * struct drm_vmw_execbuf_arg - * - * @commands: User-space address of a command buffer cast to an uint64_t. - * @command-size: Size in bytes of the command buffer. - * @throttle-us: Sleep until software is less than @throttle_us - * microseconds ahead of hardware. The driver may round this value - * to the nearest kernel tick. - * @fence_rep: User-space address of a struct drm_vmw_fence_rep cast to an - * uint64_t. - * @version: Allows expanding the execbuf ioctl parameters without breaking - * backwards compatibility, since user-space will always tell the kernel - * which version it uses. - * @flags: Execbuf flags. None currently. - * - * Argument to the DRM_VMW_EXECBUF Ioctl. - */ - -#define DRM_VMW_EXECBUF_VERSION 0 - -struct drm_vmw_execbuf_arg { - uint64_t commands; - uint32_t command_size; - uint32_t throttle_us; - uint64_t fence_rep; - uint32_t version; - uint32_t flags; -}; - -/** - * struct drm_vmw_fence_rep - * - * @fence_seq: Fence sequence associated with a command submission. - * @error: This member should've been set to -EFAULT on submission. - * The following actions should be take on completion: - * error == -EFAULT: Fence communication failed. The host is synchronized. - * Use the last fence id read from the FIFO fence register. - * error != 0 && error != -EFAULT: - * Fence submission failed. The host is synchronized. Use the fence_seq member. - * error == 0: All is OK, The host may not be synchronized. - * Use the fence_seq member. - * - * Input / Output data to the DRM_VMW_EXECBUF Ioctl. - */ - -struct drm_vmw_fence_rep { - uint64_t fence_seq; - int32_t error; - uint32_t pad64; -}; - -/*************************************************************************/ -/** - * DRM_VMW_ALLOC_DMABUF - * - * Allocate a DMA buffer that is visible also to the host. - * NOTE: The buffer is - * identified by a handle and an offset, which are private to the guest, but - * useable in the command stream. The guest kernel may translate these - * and patch up the command stream accordingly. In the future, the offset may - * be zero at all times, or it may disappear from the interface before it is - * fixed. - * - * The DMA buffer may stay user-space mapped in the guest at all times, - * and is thus suitable for sub-allocation. - * - * DMA buffers are mapped using the mmap() syscall on the drm device. - */ - -/** - * struct drm_vmw_alloc_dmabuf_req - * - * @size: Required minimum size of the buffer. - * - * Input data to the DRM_VMW_ALLOC_DMABUF Ioctl. - */ - -struct drm_vmw_alloc_dmabuf_req { - uint32_t size; - uint32_t pad64; -}; - -/** - * struct drm_vmw_dmabuf_rep - * - * @map_handle: Offset to use in the mmap() call used to map the buffer. - * @handle: Handle unique to this buffer. Used for unreferencing. - * @cur_gmr_id: GMR id to use in the command stream when this buffer is - * referenced. See not above. - * @cur_gmr_offset: Offset to use in the command stream when this buffer is - * referenced. See note above. - * - * Output data from the DRM_VMW_ALLOC_DMABUF Ioctl. - */ - -struct drm_vmw_dmabuf_rep { - uint64_t map_handle; - uint32_t handle; - uint32_t cur_gmr_id; - uint32_t cur_gmr_offset; - uint32_t pad64; -}; - -/** - * union drm_vmw_dmabuf_arg - * - * @req: Input data as described above. - * @rep: Output data as described above. - * - * Argument to the DRM_VMW_ALLOC_DMABUF Ioctl. - */ - -union drm_vmw_alloc_dmabuf_arg { - struct drm_vmw_alloc_dmabuf_req req; - struct drm_vmw_dmabuf_rep rep; -}; - -/*************************************************************************/ -/** - * DRM_VMW_UNREF_DMABUF - Free a DMA buffer. - * - */ - -/** - * struct drm_vmw_unref_dmabuf_arg - * - * @handle: Handle indicating what buffer to free. Obtained from the - * DRM_VMW_ALLOC_DMABUF Ioctl. - * - * Argument to the DRM_VMW_UNREF_DMABUF Ioctl. - */ - -struct drm_vmw_unref_dmabuf_arg { - uint32_t handle; - uint32_t pad64; -}; - -/*************************************************************************/ -/** - * DRM_VMW_FIFO_DEBUG - Get last FIFO submission. - * - * This IOCTL copies the last FIFO submission directly out of the FIFO buffer. - */ - -/** - * struct drm_vmw_fifo_debug_arg - * - * @debug_buffer: User space address of a debug_buffer cast to an uint64_t //In - * @debug_buffer_size: Size in bytes of debug buffer //In - * @used_size: Number of bytes copied to the buffer // Out - * @did_not_fit: Boolean indicating that the fifo contents did not fit. //Out - * - * Argument to the DRM_VMW_FIFO_DEBUG Ioctl. - */ - -struct drm_vmw_fifo_debug_arg { - uint64_t debug_buffer; - uint32_t debug_buffer_size; - uint32_t used_size; - int32_t did_not_fit; - uint32_t pad64; -}; - -struct drm_vmw_fence_wait_arg { - uint64_t sequence; - uint64_t kernel_cookie; - int32_t cookie_valid; - int32_t pad64; -}; - -/*************************************************************************/ -/** - * DRM_VMW_CONTROL_STREAM - Control overlays, aka streams. - * - * This IOCTL controls the overlay units of the svga device. - * The SVGA overlay units does not work like regular hardware units in - * that they do not automaticaly read back the contents of the given dma - * buffer. But instead only read back for each call to this ioctl, and - * at any point between this call being made and a following call that - * either changes the buffer or disables the stream. - */ - -/** - * struct drm_vmw_rect - * - * Defines a rectangle. Used in the overlay ioctl to define - * source and destination rectangle. - */ - -struct drm_vmw_rect { - int32_t x; - int32_t y; - uint32_t w; - uint32_t h; -}; - -/** - * struct drm_vmw_control_stream_arg - * - * @stream_id: Stearm to control - * @enabled: If false all following arguments are ignored. - * @handle: Handle to buffer for getting data from. - * @format: Format of the overlay as understood by the host. - * @width: Width of the overlay. - * @height: Height of the overlay. - * @size: Size of the overlay in bytes. - * @pitch: Array of pitches, the two last are only used for YUV12 formats. - * @offset: Offset from start of dma buffer to overlay. - * @src: Source rect, must be within the defined area above. - * @dst: Destination rect, x and y may be negative. - * - * Argument to the DRM_VMW_CONTROL_STREAM Ioctl. - */ - -struct drm_vmw_control_stream_arg { - uint32_t stream_id; - uint32_t enabled; - - uint32_t flags; - uint32_t color_key; - - uint32_t handle; - uint32_t offset; - int32_t format; - uint32_t size; - uint32_t width; - uint32_t height; - uint32_t pitch[3]; - - uint32_t pad64; - struct drm_vmw_rect src; - struct drm_vmw_rect dst; -}; - -/*************************************************************************/ -/** - * DRM_VMW_CURSOR_BYPASS - Give extra information about cursor bypass. - * - */ - -#define DRM_VMW_CURSOR_BYPASS_ALL (1 << 0) -#define DRM_VMW_CURSOR_BYPASS_FLAGS (1) - -/** - * struct drm_vmw_cursor_bypass_arg - * - * @flags: Flags. - * @crtc_id: Crtc id, only used if DMR_CURSOR_BYPASS_ALL isn't passed. - * @xpos: X position of cursor. - * @ypos: Y position of cursor. - * @xhot: X hotspot. - * @yhot: Y hotspot. - * - * Argument to the DRM_VMW_CURSOR_BYPASS Ioctl. - */ - -struct drm_vmw_cursor_bypass_arg { - uint32_t flags; - uint32_t crtc_id; - int32_t xpos; - int32_t ypos; - int32_t xhot; - int32_t yhot; -}; - -/*************************************************************************/ -/** - * DRM_VMW_CLAIM_STREAM - Claim a single stream. - */ - -/** - * struct drm_vmw_context_arg - * - * @stream_id: Device unique context ID. - * - * Output argument to the DRM_VMW_CREATE_CONTEXT Ioctl. - * Input argument to the DRM_VMW_UNREF_CONTEXT Ioctl. - */ - -struct drm_vmw_stream_arg { - uint32_t stream_id; - uint32_t pad64; -}; - -/*************************************************************************/ -/** - * DRM_VMW_UNREF_STREAM - Unclaim a stream. - * - * Return a single stream that was claimed by this process. Also makes - * sure that the stream has been stopped. - */ - -#endif diff --git a/src/gallium/winsys/gdi/SConscript b/src/gallium/winsys/gdi/SConscript deleted file mode 100644 index 1267fc6eea4..00000000000 --- a/src/gallium/winsys/gdi/SConscript +++ /dev/null @@ -1,23 +0,0 @@ -####################################################################### -# SConscript for xlib winsys - - -Import('*') - -if env['platform'] == 'windows': - - env = env.Clone() - - env.Append(CPPPATH = [ - '#/src/gallium/include', - '#/src/gallium/auxiliary', - '#/src/gallium/drivers', - ]) - - ws_gdi = env.ConvenienceLibrary( - target = 'ws_gdi', - source = [ - 'gdi_sw_winsys.c', - ] - ) - Export('ws_gdi') diff --git a/src/gallium/winsys/gdi/gdi_sw_winsys.c b/src/gallium/winsys/gdi/gdi_sw_winsys.c deleted file mode 100644 index 4dba4b577b8..00000000000 --- a/src/gallium/winsys/gdi/gdi_sw_winsys.c +++ /dev/null @@ -1,247 +0,0 @@ -/************************************************************************** - * - * Copyright 2009 VMware, Inc. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL - * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE - * USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * - **************************************************************************/ - -/** - * @file - * GDI software rasterizer support. - * - * @author Jose Fonseca - */ - - -#include - -#include "pipe/p_format.h" -#include "pipe/p_context.h" -#include "util/u_inlines.h" -#include "util/u_format.h" -#include "util/u_math.h" -#include "util/u_memory.h" -#include "state_tracker/sw_winsys.h" -#include "gdi_sw_winsys.h" - - -struct gdi_sw_displaytarget -{ - enum pipe_format format; - unsigned width; - unsigned height; - unsigned stride; - - unsigned size; - - void *data; - - BITMAPINFO bmi; -}; - - -/** Cast wrapper */ -static INLINE struct gdi_sw_displaytarget * -gdi_sw_displaytarget( struct sw_displaytarget *buf ) -{ - return (struct gdi_sw_displaytarget *)buf; -} - - -static boolean -gdi_sw_is_displaytarget_format_supported( struct sw_winsys *ws, - unsigned tex_usage, - enum pipe_format format ) -{ - switch(format) { - case PIPE_FORMAT_B8G8R8X8_UNORM: - case PIPE_FORMAT_B8G8R8A8_UNORM: - return TRUE; - - /* TODO: Support other formats possible with BMPs, as described in - * http://msdn.microsoft.com/en-us/library/dd183376(VS.85).aspx */ - - default: - return FALSE; - } -} - - -static void * -gdi_sw_displaytarget_map(struct sw_winsys *ws, - struct sw_displaytarget *dt, - unsigned flags ) -{ - struct gdi_sw_displaytarget *gdt = gdi_sw_displaytarget(dt); - - return gdt->data; -} - - -static void -gdi_sw_displaytarget_unmap(struct sw_winsys *ws, - struct sw_displaytarget *dt ) -{ - -} - - -static void -gdi_sw_displaytarget_destroy(struct sw_winsys *winsys, - struct sw_displaytarget *dt) -{ - struct gdi_sw_displaytarget *gdt = gdi_sw_displaytarget(dt); - - align_free(gdt->data); - FREE(gdt); -} - - -static struct sw_displaytarget * -gdi_sw_displaytarget_create(struct sw_winsys *winsys, - unsigned tex_usage, - enum pipe_format format, - unsigned width, unsigned height, - unsigned alignment, - unsigned *stride) -{ - struct gdi_sw_displaytarget *gdt; - unsigned cpp; - unsigned bpp; - - gdt = CALLOC_STRUCT(gdi_sw_displaytarget); - if(!gdt) - goto no_gdt; - - gdt->format = format; - gdt->width = width; - gdt->height = height; - - bpp = util_format_get_blocksizebits(format); - cpp = util_format_get_blocksize(format); - - gdt->stride = align(width * cpp, alignment); - gdt->size = gdt->stride * height; - - gdt->data = align_malloc(gdt->size, alignment); - if(!gdt->data) - goto no_data; - - gdt->bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); - gdt->bmi.bmiHeader.biWidth = gdt->stride / cpp; - gdt->bmi.bmiHeader.biHeight= -(long)height; - gdt->bmi.bmiHeader.biPlanes = 1; - gdt->bmi.bmiHeader.biBitCount = bpp; - gdt->bmi.bmiHeader.biCompression = BI_RGB; - gdt->bmi.bmiHeader.biSizeImage = 0; - gdt->bmi.bmiHeader.biXPelsPerMeter = 0; - gdt->bmi.bmiHeader.biYPelsPerMeter = 0; - gdt->bmi.bmiHeader.biClrUsed = 0; - gdt->bmi.bmiHeader.biClrImportant = 0; - - *stride = gdt->stride; - return (struct sw_displaytarget *)gdt; - -no_data: - FREE(gdt); -no_gdt: - return NULL; -} - - -static struct sw_displaytarget * -gdi_sw_displaytarget_from_handle(struct sw_winsys *winsys, - const struct pipe_texture *templet, - struct winsys_handle *whandle, - unsigned *stride) -{ - assert(0); - return NULL; -} - - -static boolean -gdi_sw_displaytarget_get_handle(struct sw_winsys *winsys, - struct sw_displaytarget *dt, - struct winsys_handle *whandle) -{ - assert(0); - return FALSE; -} - - -void -gdi_sw_display( struct sw_winsys *winsys, - struct sw_displaytarget *dt, - HDC hDC ) -{ - struct gdi_sw_displaytarget *gdt = gdi_sw_displaytarget(dt); - - StretchDIBits(hDC, - 0, 0, gdt->width, gdt->height, - 0, 0, gdt->width, gdt->height, - gdt->data, &gdt->bmi, 0, SRCCOPY); -} - -static void -gdi_sw_displaytarget_display(struct sw_winsys *winsys, - struct sw_displaytarget *dt, - void *context_private) -{ - /* nasty: - */ - HDC hDC = (HDC)context_private; - - gdi_sw_display(winsys, dt, hDC); -} - - -static void -gdi_sw_destroy(struct sw_winsys *winsys) -{ - FREE(winsys); -} - -struct sw_winsys * -gdi_create_sw_winsys(void) -{ - static struct sw_winsys *winsys; - - winsys = CALLOC_STRUCT(sw_winsys); - if(!winsys) - return NULL; - - winsys->destroy = gdi_sw_destroy; - winsys->is_displaytarget_format_supported = gdi_sw_is_displaytarget_format_supported; - winsys->displaytarget_create = gdi_sw_displaytarget_create; - winsys->displaytarget_from_handle = gdi_sw_displaytarget_from_handle; - winsys->displaytarget_get_handle = gdi_sw_displaytarget_get_handle; - winsys->displaytarget_map = gdi_sw_displaytarget_map; - winsys->displaytarget_unmap = gdi_sw_displaytarget_unmap; - winsys->displaytarget_display = gdi_sw_displaytarget_display; - winsys->displaytarget_destroy = gdi_sw_displaytarget_destroy; - - return winsys; -} - diff --git a/src/gallium/winsys/gdi/gdi_sw_winsys.h b/src/gallium/winsys/gdi/gdi_sw_winsys.h deleted file mode 100644 index 4bbcb47848b..00000000000 --- a/src/gallium/winsys/gdi/gdi_sw_winsys.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef GDI_SW_WINSYS_H -#define GDI_SW_WINSYS_H - -#include - -#include "pipe/p_compiler.h" -#include "state_tracker/sw_winsys.h" - -void gdi_sw_display( struct sw_winsys *winsys, - struct sw_displaytarget *dt, - HDC hDC ); - -struct sw_winsys * -gdi_create_sw_winsys(void); - -#endif diff --git a/src/gallium/winsys/i915/drm/Makefile b/src/gallium/winsys/i915/drm/Makefile new file mode 100644 index 00000000000..4aac3309aa7 --- /dev/null +++ b/src/gallium/winsys/i915/drm/Makefile @@ -0,0 +1,16 @@ +TOP = ../../../../.. +include $(TOP)/configs/current + +LIBNAME = inteldrm + +C_SOURCES = \ + intel_drm_batchbuffer.c \ + intel_drm_buffer.c \ + intel_drm_fence.c \ + intel_drm_api.c + +LIBRARY_INCLUDES = $(shell pkg-config libdrm --cflags-only-I) + +LIBRARY_DEFINES = $(shell pkg-config libdrm --cflags-only-other) + +include ../../../Makefile.template diff --git a/src/gallium/winsys/i915/drm/SConscript b/src/gallium/winsys/i915/drm/SConscript new file mode 100644 index 00000000000..26717f391fa --- /dev/null +++ b/src/gallium/winsys/i915/drm/SConscript @@ -0,0 +1,17 @@ +Import('*') + +env = drienv.Clone() + +inteldrm_sources = [ + 'intel_drm_api.c', + 'intel_drm_batchbuffer.c', + 'intel_drm_buffer.c', + 'intel_drm_fence.c', +] + +inteldrm = env.ConvenienceLibrary( + target ='inteldrm', + source = inteldrm_sources, +) + +Export('inteldrm') diff --git a/src/gallium/winsys/i915/drm/intel_drm_api.c b/src/gallium/winsys/i915/drm/intel_drm_api.c new file mode 100644 index 00000000000..e3b980a832b --- /dev/null +++ b/src/gallium/winsys/i915/drm/intel_drm_api.c @@ -0,0 +1,109 @@ +#include + +#include "state_tracker/drm_api.h" + +#include "intel_drm_winsys.h" +#include "util/u_memory.h" + +#include "i915/i915_context.h" +#include "i915/i915_screen.h" + +#include "trace/tr_drm.h" + +/* + * Helper functions + */ + + +static void +intel_drm_get_device_id(unsigned int *device_id) +{ + char path[512]; + FILE *file; + void *shutup_gcc; + + /* + * FIXME: Fix this up to use a drm ioctl or whatever. + */ + + snprintf(path, sizeof(path), "/sys/class/drm/card0/device/device"); + file = fopen(path, "r"); + if (!file) { + return; + } + + shutup_gcc = fgets(path, sizeof(path), file); + (void) shutup_gcc; + sscanf(path, "%x", device_id); + fclose(file); +} + +static void +intel_drm_winsys_destroy(struct intel_winsys *iws) +{ + struct intel_drm_winsys *idws = intel_drm_winsys(iws); + + drm_intel_bufmgr_destroy(idws->pools.gem); + + FREE(idws); +} + +static struct pipe_screen * +intel_drm_create_screen(struct drm_api *api, int drmFD, + struct drm_create_screen_arg *arg) +{ + struct intel_drm_winsys *idws; + unsigned int deviceID; + + if (arg != NULL) { + switch(arg->mode) { + case DRM_CREATE_NORMAL: + break; + default: + return NULL; + } + } + + idws = CALLOC_STRUCT(intel_drm_winsys); + if (!idws) + return NULL; + + intel_drm_get_device_id(&deviceID); + + intel_drm_winsys_init_batchbuffer_functions(idws); + intel_drm_winsys_init_buffer_functions(idws); + intel_drm_winsys_init_fence_functions(idws); + + idws->fd = drmFD; + idws->id = deviceID; + idws->max_batch_size = 16 * 4096; + + idws->base.destroy = intel_drm_winsys_destroy; + + idws->pools.gem = drm_intel_bufmgr_gem_init(idws->fd, idws->max_batch_size); + drm_intel_bufmgr_gem_enable_reuse(idws->pools.gem); + + idws->dump_cmd = debug_get_bool_option("INTEL_DUMP_CMD", FALSE); + + return i915_create_screen(&idws->base, deviceID); +} + +static void +destroy(struct drm_api *api) +{ + +} + +struct drm_api intel_drm_api = +{ + .name = "i915", + .driver_name = "i915", + .create_screen = intel_drm_create_screen, + .destroy = destroy, +}; + +struct drm_api * +drm_api_create() +{ + return trace_drm_create(&intel_drm_api); +} diff --git a/src/gallium/winsys/i915/drm/intel_drm_batchbuffer.c b/src/gallium/winsys/i915/drm/intel_drm_batchbuffer.c new file mode 100644 index 00000000000..5b4dafc8e41 --- /dev/null +++ b/src/gallium/winsys/i915/drm/intel_drm_batchbuffer.c @@ -0,0 +1,244 @@ + +#include "intel_drm_winsys.h" +#include "util/u_memory.h" + +#include "i915_drm.h" + +#define BATCH_RESERVED 16 + +#define INTEL_DEFAULT_RELOCS 100 +#define INTEL_MAX_RELOCS 400 + +#define INTEL_BATCH_NO_CLIPRECTS 0x1 +#define INTEL_BATCH_CLIPRECTS 0x2 + +#undef INTEL_RUN_SYNC +#undef INTEL_MAP_BATCHBUFFER +#undef INTEL_MAP_GTT +#define INTEL_ALWAYS_FLUSH + +struct intel_drm_batchbuffer +{ + struct intel_batchbuffer base; + + size_t actual_size; + + drm_intel_bo *bo; +}; + +static INLINE struct intel_drm_batchbuffer * +intel_drm_batchbuffer(struct intel_batchbuffer *batch) +{ + return (struct intel_drm_batchbuffer *)batch; +} + +static void +intel_drm_batchbuffer_reset(struct intel_drm_batchbuffer *batch) +{ + struct intel_drm_winsys *idws = intel_drm_winsys(batch->base.iws); + int ret; + + if (batch->bo) + drm_intel_bo_unreference(batch->bo); + batch->bo = drm_intel_bo_alloc(idws->pools.gem, + "gallium3d_batchbuffer", + batch->actual_size, + 4096); + +#ifdef INTEL_MAP_BATCHBUFFER +#ifdef INTEL_MAP_GTT + ret = drm_intel_gem_bo_map_gtt(batch->bo); +#else + ret = drm_intel_bo_map(batch->bo, TRUE); +#endif + assert(ret == 0); + batch->base.map = batch->bo->virtual; +#else + (void)ret; +#endif + + memset(batch->base.map, 0, batch->actual_size); + batch->base.ptr = batch->base.map; + batch->base.size = batch->actual_size - BATCH_RESERVED; + batch->base.relocs = 0; +} + +static struct intel_batchbuffer * +intel_drm_batchbuffer_create(struct intel_winsys *iws) +{ + struct intel_drm_winsys *idws = intel_drm_winsys(iws); + struct intel_drm_batchbuffer *batch = CALLOC_STRUCT(intel_drm_batchbuffer); + + batch->actual_size = idws->max_batch_size; + +#ifdef INTEL_MAP_BATCHBUFFER + batch->base.map = NULL; +#else + batch->base.map = MALLOC(batch->actual_size); +#endif + batch->base.ptr = NULL; + batch->base.size = 0; + + batch->base.relocs = 0; + batch->base.max_relocs = 300;/*INTEL_DEFAULT_RELOCS;*/ + + batch->base.iws = iws; + + intel_drm_batchbuffer_reset(batch); + + return &batch->base; +} + +static int +intel_drm_batchbuffer_reloc(struct intel_batchbuffer *ibatch, + struct intel_buffer *buffer, + enum intel_buffer_usage usage, + unsigned pre_add) +{ + struct intel_drm_batchbuffer *batch = intel_drm_batchbuffer(ibatch); + unsigned write_domain = 0; + unsigned read_domain = 0; + unsigned offset; + int ret = 0; + + assert(batch->base.relocs < batch->base.max_relocs); + + if (usage == INTEL_USAGE_SAMPLER) { + write_domain = 0; + read_domain = I915_GEM_DOMAIN_SAMPLER; + + } else if (usage == INTEL_USAGE_RENDER) { + write_domain = I915_GEM_DOMAIN_RENDER; + read_domain = I915_GEM_DOMAIN_RENDER; + + } else if (usage == INTEL_USAGE_2D_TARGET) { + write_domain = I915_GEM_DOMAIN_RENDER; + read_domain = I915_GEM_DOMAIN_RENDER; + + } else if (usage == INTEL_USAGE_2D_SOURCE) { + write_domain = 0; + read_domain = I915_GEM_DOMAIN_RENDER; + + } else if (usage == INTEL_USAGE_VERTEX) { + write_domain = 0; + read_domain = I915_GEM_DOMAIN_VERTEX; + + } else { + assert(0); + return -1; + } + + offset = (unsigned)(batch->base.ptr - batch->base.map); + + ret = drm_intel_bo_emit_reloc(batch->bo, offset, + intel_bo(buffer), pre_add, + read_domain, + write_domain); + + ((uint32_t*)batch->base.ptr)[0] = intel_bo(buffer)->offset + pre_add; + batch->base.ptr += 4; + + if (!ret) + batch->base.relocs++; + + return ret; +} + +static void +intel_drm_batchbuffer_flush(struct intel_batchbuffer *ibatch, + struct pipe_fence_handle **fence) +{ + struct intel_drm_batchbuffer *batch = intel_drm_batchbuffer(ibatch); + unsigned used = 0; + int ret = 0; + int i; + + assert(intel_batchbuffer_space(ibatch) >= 0); + + used = batch->base.ptr - batch->base.map; + assert((used & 3) == 0); + + +#ifdef INTEL_ALWAYS_FLUSH + /* MI_FLUSH | FLUSH_MAP_CACHE */ + intel_batchbuffer_dword(ibatch, (0x4<<23)|(1<<0)); + used += 4; +#endif + + if ((used & 4) == 0) { + /* MI_NOOP */ + intel_batchbuffer_dword(ibatch, 0); + } + /* MI_BATCH_BUFFER_END */ + intel_batchbuffer_dword(ibatch, (0xA<<23)); + + used = batch->base.ptr - batch->base.map; + assert((used & 4) == 0); + +#ifdef INTEL_MAP_BATCHBUFFER +#ifdef INTEL_MAP_GTT + drm_intel_gem_bo_unmap_gtt(batch->bo); +#else + drm_intel_bo_unmap(batch->bo); +#endif +#else + drm_intel_bo_subdata(batch->bo, 0, used, batch->base.map); +#endif + + /* Do the sending to HW */ + ret = drm_intel_bo_exec(batch->bo, used, NULL, 0, 0); + assert(ret == 0); + + if (intel_drm_winsys(ibatch->iws)->dump_cmd) { + unsigned *ptr; + drm_intel_bo_map(batch->bo, FALSE); + ptr = (unsigned*)batch->bo->virtual; + + debug_printf("%s:\n", __func__); + for (i = 0; i < used / 4; i++, ptr++) { + debug_printf("\t%08x: %08x\n", i*4, *ptr); + } + + drm_intel_bo_unmap(batch->bo); + } else { +#ifdef INTEL_RUN_SYNC + drm_intel_bo_map(batch->bo, FALSE); + drm_intel_bo_unmap(batch->bo); +#endif + } + + if (fence) { + ibatch->iws->fence_reference(ibatch->iws, fence, NULL); + +#ifdef INTEL_RUN_SYNC + /* we run synced to GPU so just pass null */ + (*fence) = intel_drm_fence_create(NULL); +#else + (*fence) = intel_drm_fence_create(batch->bo); +#endif + } + + intel_drm_batchbuffer_reset(batch); +} + +static void +intel_drm_batchbuffer_destroy(struct intel_batchbuffer *ibatch) +{ + struct intel_drm_batchbuffer *batch = intel_drm_batchbuffer(ibatch); + + if (batch->bo) + drm_intel_bo_unreference(batch->bo); + +#ifndef INTEL_MAP_BATCHBUFFER + FREE(batch->base.map); +#endif + FREE(batch); +} + +void intel_drm_winsys_init_batchbuffer_functions(struct intel_drm_winsys *idws) +{ + idws->base.batchbuffer_create = intel_drm_batchbuffer_create; + idws->base.batchbuffer_reloc = intel_drm_batchbuffer_reloc; + idws->base.batchbuffer_flush = intel_drm_batchbuffer_flush; + idws->base.batchbuffer_destroy = intel_drm_batchbuffer_destroy; +} diff --git a/src/gallium/winsys/i915/drm/intel_drm_buffer.c b/src/gallium/winsys/i915/drm/intel_drm_buffer.c new file mode 100644 index 00000000000..cb4f92a3b17 --- /dev/null +++ b/src/gallium/winsys/i915/drm/intel_drm_buffer.c @@ -0,0 +1,217 @@ + +#include "state_tracker/drm_api.h" +#include "intel_drm_winsys.h" +#include "util/u_memory.h" + +#include "i915_drm.h" + +static struct intel_buffer * +intel_drm_buffer_create(struct intel_winsys *iws, + unsigned size, unsigned alignment, + enum intel_buffer_type type) +{ + struct intel_drm_buffer *buf = CALLOC_STRUCT(intel_drm_buffer); + struct intel_drm_winsys *idws = intel_drm_winsys(iws); + drm_intel_bufmgr *pool; + char *name; + + if (!buf) + return NULL; + + buf->magic = 0xDEAD1337; + buf->flinked = FALSE; + buf->flink = 0; + buf->map_gtt = FALSE; + + if (type == INTEL_NEW_TEXTURE) { + name = "gallium3d_texture"; + pool = idws->pools.gem; + } else if (type == INTEL_NEW_VERTEX) { + name = "gallium3d_vertex"; + pool = idws->pools.gem; + buf->map_gtt = TRUE; + } else if (type == INTEL_NEW_SCANOUT) { + name = "gallium3d_scanout"; + pool = idws->pools.gem; + buf->map_gtt = TRUE; + } else { + assert(0); + name = "gallium3d_unknown"; + pool = idws->pools.gem; + } + + buf->bo = drm_intel_bo_alloc(pool, name, size, alignment); + + if (!buf->bo) + goto err; + + return (struct intel_buffer *)buf; + +err: + assert(0); + FREE(buf); + return NULL; +} + +static struct intel_buffer * +intel_drm_buffer_from_handle(struct intel_winsys *iws, + struct winsys_handle *whandle, + unsigned *stride) +{ + struct intel_drm_winsys *idws = intel_drm_winsys(iws); + struct intel_drm_buffer *buf = CALLOC_STRUCT(intel_drm_buffer); + uint32_t tile = 0, swizzle = 0; + + if (!buf) + return NULL; + + buf->magic = 0xDEAD1337; + buf->bo = drm_intel_bo_gem_create_from_name(idws->pools.gem, "gallium3d_from_handle", whandle->handle); + buf->flinked = TRUE; + buf->flink = whandle->handle; + + if (!buf->bo) + goto err; + + drm_intel_bo_get_tiling(buf->bo, &tile, &swizzle); + if (tile != INTEL_TILE_NONE) + buf->map_gtt = TRUE; + + *stride = whandle->stride; + + return (struct intel_buffer *)buf; + +err: + FREE(buf); + return NULL; +} + +static boolean +intel_drm_buffer_get_handle(struct intel_winsys *iws, + struct intel_buffer *buffer, + struct winsys_handle *whandle, + unsigned stride) +{ + struct intel_drm_buffer *buf = intel_drm_buffer(buffer); + + if (whandle->type == DRM_API_HANDLE_TYPE_SHARED) { + if (!buf->flinked) { + if (drm_intel_bo_flink(buf->bo, &buf->flink)) + return FALSE; + buf->flinked = TRUE; + } + + whandle->handle = buf->flink; + } else if (whandle->type == DRM_API_HANDLE_TYPE_KMS) { + whandle->handle = buf->bo->handle; + } else { + assert(!"unknown usage"); + return FALSE; + } + + whandle->stride = stride; + return TRUE; +} + +static int +intel_drm_buffer_set_fence_reg(struct intel_winsys *iws, + struct intel_buffer *buffer, + unsigned stride, + enum intel_buffer_tile tile) +{ + struct intel_drm_buffer *buf = intel_drm_buffer(buffer); + assert(I915_TILING_NONE == INTEL_TILE_NONE); + assert(I915_TILING_X == INTEL_TILE_X); + assert(I915_TILING_Y == INTEL_TILE_Y); + + if (tile != INTEL_TILE_NONE) { + assert(buf->map_count == 0); + buf->map_gtt = TRUE; + } + + return drm_intel_bo_set_tiling(buf->bo, &tile, stride); +} + +static void * +intel_drm_buffer_map(struct intel_winsys *iws, + struct intel_buffer *buffer, + boolean write) +{ + struct intel_drm_buffer *buf = intel_drm_buffer(buffer); + drm_intel_bo *bo = intel_bo(buffer); + int ret = 0; + + assert(bo); + + if (buf->map_count) + goto out; + + if (buf->map_gtt) + ret = drm_intel_gem_bo_map_gtt(bo); + else + ret = drm_intel_bo_map(bo, write); + + buf->ptr = bo->virtual; + + assert(ret == 0); +out: + if (ret) + return NULL; + + buf->map_count++; + return buf->ptr; +} + +static void +intel_drm_buffer_unmap(struct intel_winsys *iws, + struct intel_buffer *buffer) +{ + struct intel_drm_buffer *buf = intel_drm_buffer(buffer); + + if (--buf->map_count) + return; + + if (buf->map_gtt) + drm_intel_gem_bo_unmap_gtt(intel_bo(buffer)); + else + drm_intel_bo_unmap(intel_bo(buffer)); +} + +static int +intel_drm_buffer_write(struct intel_winsys *iws, + struct intel_buffer *buffer, + size_t offset, + size_t size, + const void *data) +{ + struct intel_drm_buffer *buf = intel_drm_buffer(buffer); + + return drm_intel_bo_subdata(buf->bo, offset, size, (void*)data); +} + +static void +intel_drm_buffer_destroy(struct intel_winsys *iws, + struct intel_buffer *buffer) +{ + drm_intel_bo_unreference(intel_bo(buffer)); + +#ifdef DEBUG + intel_drm_buffer(buffer)->magic = 0; + intel_drm_buffer(buffer)->bo = NULL; +#endif + + FREE(buffer); +} + +void +intel_drm_winsys_init_buffer_functions(struct intel_drm_winsys *idws) +{ + idws->base.buffer_create = intel_drm_buffer_create; + idws->base.buffer_from_handle = intel_drm_buffer_from_handle; + idws->base.buffer_get_handle = intel_drm_buffer_get_handle; + idws->base.buffer_set_fence_reg = intel_drm_buffer_set_fence_reg; + idws->base.buffer_map = intel_drm_buffer_map; + idws->base.buffer_unmap = intel_drm_buffer_unmap; + idws->base.buffer_write = intel_drm_buffer_write; + idws->base.buffer_destroy = intel_drm_buffer_destroy; +} diff --git a/src/gallium/winsys/i915/drm/intel_drm_fence.c b/src/gallium/winsys/i915/drm/intel_drm_fence.c new file mode 100644 index 00000000000..102faedfeae --- /dev/null +++ b/src/gallium/winsys/i915/drm/intel_drm_fence.c @@ -0,0 +1,83 @@ + +#include "intel_drm_winsys.h" +#include "util/u_memory.h" +#include "util/u_atomic.h" +#include "util/u_inlines.h" + +/** + * Because gem does not have fence's we have to create our own fences. + * + * They work by keeping the batchbuffer around and checking if that has + * been idled. If bo is NULL fence has expired. + */ +struct intel_drm_fence +{ + struct pipe_reference reference; + drm_intel_bo *bo; +}; + + +struct pipe_fence_handle * +intel_drm_fence_create(drm_intel_bo *bo) +{ + struct intel_drm_fence *fence = CALLOC_STRUCT(intel_drm_fence); + + pipe_reference_init(&fence->reference, 1); + /* bo is null if fence already expired */ + if (bo) { + drm_intel_bo_reference(bo); + fence->bo = bo; + } + + return (struct pipe_fence_handle *)fence; +} + +static void +intel_drm_fence_reference(struct intel_winsys *iws, + struct pipe_fence_handle **ptr, + struct pipe_fence_handle *fence) +{ + struct intel_drm_fence *old = (struct intel_drm_fence *)*ptr; + struct intel_drm_fence *f = (struct intel_drm_fence *)fence; + + if (pipe_reference(&((struct intel_drm_fence *)(*ptr))->reference, &f->reference)) { + if (old->bo) + drm_intel_bo_unreference(old->bo); + FREE(old); + } + *ptr = fence; +} + +static int +intel_drm_fence_signalled(struct intel_winsys *iws, + struct pipe_fence_handle *fence) +{ + assert(0); + + return 0; +} + +static int +intel_drm_fence_finish(struct intel_winsys *iws, + struct pipe_fence_handle *fence) +{ + struct intel_drm_fence *f = (struct intel_drm_fence *)fence; + + /* fence already expired */ + if (!f->bo) + return 0; + + drm_intel_bo_wait_rendering(f->bo); + drm_intel_bo_unreference(f->bo); + f->bo = NULL; + + return 0; +} + +void +intel_drm_winsys_init_fence_functions(struct intel_drm_winsys *idws) +{ + idws->base.fence_reference = intel_drm_fence_reference; + idws->base.fence_signalled = intel_drm_fence_signalled; + idws->base.fence_finish = intel_drm_fence_finish; +} diff --git a/src/gallium/winsys/i915/drm/intel_drm_winsys.h b/src/gallium/winsys/i915/drm/intel_drm_winsys.h new file mode 100644 index 00000000000..9786ee93650 --- /dev/null +++ b/src/gallium/winsys/i915/drm/intel_drm_winsys.h @@ -0,0 +1,77 @@ + +#ifndef INTEL_DRM_WINSYS_H +#define INTEL_DRM_WINSYS_H + +#include "i915/intel_batchbuffer.h" + +#include "drm.h" +#include "intel_bufmgr.h" + + +/* + * Winsys + */ + + +struct intel_drm_winsys +{ + struct intel_winsys base; + + boolean dump_cmd; + + int fd; /**< Drm file discriptor */ + + unsigned id; + + size_t max_batch_size; + + struct { + drm_intel_bufmgr *gem; + } pools; +}; + +static INLINE struct intel_drm_winsys * +intel_drm_winsys(struct intel_winsys *iws) +{ + return (struct intel_drm_winsys *)iws; +} + +struct intel_drm_winsys * intel_drm_winsys_create(int fd, unsigned pci_id); +struct pipe_fence_handle * intel_drm_fence_create(drm_intel_bo *bo); + +void intel_drm_winsys_init_batchbuffer_functions(struct intel_drm_winsys *idws); +void intel_drm_winsys_init_buffer_functions(struct intel_drm_winsys *idws); +void intel_drm_winsys_init_fence_functions(struct intel_drm_winsys *idws); + + +/* + * Buffer + */ + + +struct intel_drm_buffer { + unsigned magic; + + drm_intel_bo *bo; + + void *ptr; + unsigned map_count; + boolean map_gtt; + + boolean flinked; + unsigned flink; +}; + +static INLINE struct intel_drm_buffer * +intel_drm_buffer(struct intel_buffer *buffer) +{ + return (struct intel_drm_buffer *)buffer; +} + +static INLINE drm_intel_bo * +intel_bo(struct intel_buffer *buffer) +{ + return intel_drm_buffer(buffer)->bo; +} + +#endif diff --git a/src/gallium/winsys/i965/drm/Makefile b/src/gallium/winsys/i965/drm/Makefile new file mode 100644 index 00000000000..bbb71e25d84 --- /dev/null +++ b/src/gallium/winsys/i965/drm/Makefile @@ -0,0 +1,14 @@ +TOP = ../../../../.. +include $(TOP)/configs/current + +LIBNAME = i965drm + +C_SOURCES = \ + i965_drm_buffer.c \ + i965_drm_api.c + +LIBRARY_INCLUDES = $(shell pkg-config libdrm --cflags-only-I) + +LIBRARY_DEFINES = $(shell pkg-config libdrm --cflags-only-other) + +include ../../../Makefile.template diff --git a/src/gallium/winsys/i965/drm/SConscript b/src/gallium/winsys/i965/drm/SConscript new file mode 100644 index 00000000000..6256ec6eaf0 --- /dev/null +++ b/src/gallium/winsys/i965/drm/SConscript @@ -0,0 +1,15 @@ +Import('*') + +env = drienv.Clone() + +i965drm_sources = [ + 'i965_drm_api.c', + 'i965_drm_buffer.c', +] + +i965drm = env.ConvenienceLibrary( + target ='i965drm', + source = i965drm_sources, +) + +Export('i965drm') diff --git a/src/gallium/winsys/i965/drm/i965_drm_api.c b/src/gallium/winsys/i965/drm/i965_drm_api.c new file mode 100644 index 00000000000..9072a186384 --- /dev/null +++ b/src/gallium/winsys/i965/drm/i965_drm_api.c @@ -0,0 +1,122 @@ + +#include +#include "state_tracker/drm_api.h" + +#include "i965_drm_winsys.h" +#include "util/u_memory.h" + +#include "i965/brw_context.h" /* XXX: shouldn't be doing this */ +#include "i965/brw_screen.h" /* XXX: shouldn't be doing this */ + +#include "trace/tr_drm.h" + +#include "../../sw/drm/sw_drm_api.h" + +/* + * Helper functions + */ + + +static void +i965_libdrm_get_device_id(unsigned int *device_id) +{ + char path[512]; + FILE *file; + void *shutup_gcc; + + /* + * FIXME: Fix this up to use a drm ioctl or whatever. + */ + + snprintf(path, sizeof(path), "/sys/class/drm/card0/device/device"); + file = fopen(path, "r"); + if (!file) { + return; + } + + shutup_gcc = fgets(path, sizeof(path), file); + sscanf(path, "%x", device_id); + fclose(file); +} + +static void +i965_libdrm_winsys_destroy(struct brw_winsys_screen *iws) +{ + struct i965_libdrm_winsys *idws = i965_libdrm_winsys(iws); + + if (BRW_DUMP) + debug_printf("%s\n", __FUNCTION__); + + drm_intel_bufmgr_destroy(idws->gem); + + FREE(idws); +} + +static struct pipe_screen * +i965_libdrm_create_screen(struct drm_api *api, int drmFD, + struct drm_create_screen_arg *arg) +{ + struct i965_libdrm_winsys *idws; + unsigned int deviceID; + + debug_printf("%s\n", __FUNCTION__); + + if (arg != NULL) { + switch(arg->mode) { + case DRM_CREATE_NORMAL: + break; + default: + return NULL; + } + } + + idws = CALLOC_STRUCT(i965_libdrm_winsys); + if (!idws) + return NULL; + + i965_libdrm_get_device_id(&deviceID); + + i965_libdrm_winsys_init_buffer_functions(idws); + + idws->fd = drmFD; + idws->id = deviceID; + + idws->base.destroy = i965_libdrm_winsys_destroy; + + idws->gem = drm_intel_bufmgr_gem_init(idws->fd, BRW_BATCH_SIZE); + drm_intel_bufmgr_gem_enable_reuse(idws->gem); + + idws->send_cmd = !debug_get_bool_option("BRW_NO_HW", FALSE); + + return brw_create_screen(&idws->base, deviceID); +} + + +static void +destroy(struct drm_api *api) +{ + if (BRW_DUMP) + debug_printf("%s\n", __FUNCTION__); + +} + +struct drm_api i965_libdrm_api = +{ + .name = "i965", + .create_screen = i965_libdrm_create_screen, + .destroy = destroy, +}; + +struct drm_api * +drm_api_create() +{ + struct drm_api *api = NULL; + + if (api == NULL && debug_get_bool_option("BRW_SOFTPIPE", FALSE)) + api = sw_drm_api_create(&i965_libdrm_api); + + if (api == NULL) + api = &i965_libdrm_api; + + return trace_drm_create(api); +} diff --git a/src/gallium/winsys/i965/drm/i965_drm_buffer.c b/src/gallium/winsys/i965/drm/i965_drm_buffer.c new file mode 100644 index 00000000000..33a17496b2b --- /dev/null +++ b/src/gallium/winsys/i965/drm/i965_drm_buffer.c @@ -0,0 +1,503 @@ + +#include "state_tracker/drm_api.h" +#include "i965_drm_winsys.h" +#include "util/u_memory.h" +#include "util/u_inlines.h" + +#include "i915_drm.h" +#include "intel_bufmgr.h" + + + +const char *names[BRW_BUFFER_TYPE_MAX] = { + "TEXTURE", + "SCANOUT", + "VERTEX", + "CURBE", + "QUERY", + "SHADER_CONSTANTS", + "WM_SCRATCH", + "BATCH", + "GENERAL_STATE", + "SURFACE_STATE", + "PIXEL", + "GENERIC", +}; + +const char *usages[BRW_USAGE_MAX] = { + "STATE", + "QUERY_RESULT", + "RENDER_TARGET", + "DEPTH_BUFFER", + "BLIT_SOURCE", + "BLIT_DEST", + "SAMPLER", + "VERTEX", + "SCRATCH" +}; + + +const char *data_types[BRW_DATA_MAX] = +{ + "GS: CC_VP", + "GS: CC_UNIT", + "GS: WM_PROG", + "GS: SAMPLER_DEFAULT_COLOR", + "GS: SAMPLER", + "GS: WM_UNIT", + "GS: SF_PROG", + "GS: SF_VP", + "GS: SF_UNIT", + "GS: VS_UNIT", + "GS: VS_PROG", + "GS: GS_UNIT", + "GS: GS_PROG", + "GS: CLIP_VP", + "GS: CLIP_UNIT", + "GS: CLIP_PROG", + "SS: SURFACE", + "SS: SURF_BIND", + "CONSTANT DATA", + "BATCH DATA", + "(untyped)" +}; + +static enum pipe_error +i965_libdrm_bo_alloc(struct brw_winsys_screen *sws, + enum brw_buffer_type type, + unsigned size, + unsigned alignment, + struct brw_winsys_buffer **bo_out) +{ + struct i965_libdrm_winsys *idws = i965_libdrm_winsys(sws); + struct i965_libdrm_buffer *buf; + + if (BRW_DUMP) + debug_printf("%s type %s sz %d align %d\n", + __FUNCTION__, names[type], size, alignment ); + + buf = CALLOC_STRUCT(i965_libdrm_buffer); + if (!buf) + return PIPE_ERROR_OUT_OF_MEMORY; + + switch (type) { + case BRW_BUFFER_TYPE_TEXTURE: +/* case BRW_BUFFER_TYPE_SCANOUT:*/ + case BRW_BUFFER_TYPE_VERTEX: + case BRW_BUFFER_TYPE_CURBE: + case BRW_BUFFER_TYPE_QUERY: + case BRW_BUFFER_TYPE_SHADER_CONSTANTS: + case BRW_BUFFER_TYPE_SHADER_SCRATCH: + case BRW_BUFFER_TYPE_BATCH: + case BRW_BUFFER_TYPE_GENERAL_STATE: + case BRW_BUFFER_TYPE_SURFACE_STATE: + case BRW_BUFFER_TYPE_PIXEL: + case BRW_BUFFER_TYPE_GENERIC: + break; + case BRW_BUFFER_TYPE_SCANOUT: + buf->map_gtt = TRUE; + break; + default: + assert(0); + break; + } + + buf->bo = drm_intel_bo_alloc(idws->gem, + names[type], + size, + alignment); + + if (!buf->bo) + goto err; + + pipe_reference_init(&buf->base.reference, 1); + buf->base.size = size; + buf->base.sws = sws; + + *bo_out = &buf->base; + return PIPE_OK; + +err: + assert(0); + FREE(buf); + return PIPE_ERROR_OUT_OF_MEMORY; +} + +static enum pipe_error +i965_libdrm_bo_from_handle(struct brw_winsys_screen *sws, + struct winsys_handle *whandle, + unsigned *stride, + unsigned *tile, + struct brw_winsys_buffer **bo_out) +{ + struct i965_libdrm_winsys *idws = i965_libdrm_winsys(sws); + struct i965_libdrm_buffer *buf = CALLOC_STRUCT(i965_libdrm_buffer); + uint32_t swizzle = 0; + + if (BRW_DUMP) + debug_printf("%s\n", __FUNCTION__); + + if (!buf) + return PIPE_ERROR_OUT_OF_MEMORY; + + pipe_reference_init(&buf->base.reference, 1); + buf->bo = drm_intel_bo_gem_create_from_name(idws->gem, "FROM_HANDLE", whandle->handle); + buf->base.size = buf->bo->size; + buf->base.sws = &idws->base; + buf->flinked = TRUE; + buf->flink = whandle->handle; + + + if (!buf->bo) + goto err; + + drm_intel_bo_get_tiling(buf->bo, &buf->tiling, &swizzle); + if (buf->tiling != 0) + buf->map_gtt = TRUE; + + *tile = buf->tiling; + *stride = whandle->stride; + + *bo_out = &buf->base; + return PIPE_OK; + +err: + FREE(buf); + return PIPE_ERROR_OUT_OF_MEMORY; +} + +static enum pipe_error +i965_libdrm_bo_get_handle(struct brw_winsys_buffer *buffer, + struct winsys_handle *whandle, + unsigned stride) +{ + struct i965_libdrm_buffer *buf = i965_libdrm_buffer(buffer); + + if (BRW_DUMP) + debug_printf("%s\n", __FUNCTION__); + + if (whandle->type == DRM_API_HANDLE_TYPE_SHARED) { + if (!buf->flinked) { + if (drm_intel_bo_flink(buf->bo, &buf->flink)) + return PIPE_ERROR_BAD_INPUT; + buf->flinked = TRUE; + } + + whandle->handle = buf->flink; + } else if (whandle->type == DRM_API_HANDLE_TYPE_KMS) { + whandle->handle = buf->bo->handle; + } else { + assert(!"unknown usage"); + return PIPE_ERROR_BAD_INPUT; + } + + whandle->stride = stride; + return PIPE_OK; +} + +static void +i965_libdrm_bo_destroy(struct brw_winsys_buffer *buffer) +{ + struct i965_libdrm_buffer *buf = i965_libdrm_buffer(buffer); + + if (BRW_DUMP) + debug_printf("%s\n", __FUNCTION__); + + drm_intel_bo_unreference(buf->bo); + FREE(buffer); +} + +static enum pipe_error +i965_libdrm_bo_emit_reloc(struct brw_winsys_buffer *buffer, + enum brw_buffer_usage usage, + unsigned delta, + unsigned offset, + struct brw_winsys_buffer *buffer2) +{ + struct i965_libdrm_buffer *buf = i965_libdrm_buffer(buffer); + struct i965_libdrm_buffer *buf2 = i965_libdrm_buffer(buffer2); + int read, write; + int ret; + + if (BRW_DUMP) + debug_printf("%s buf %p offset %x delta %x buf2 %p/%s/%s\n", + __FUNCTION__, (void *)buffer, + offset, delta, + (void *)buffer2, names[buf2->data_type], usages[usage]); + + switch (usage) { + case BRW_USAGE_STATE: + read = I915_GEM_DOMAIN_INSTRUCTION; + write = 0; + break; + case BRW_USAGE_QUERY_RESULT: + read = I915_GEM_DOMAIN_INSTRUCTION; + write = I915_GEM_DOMAIN_INSTRUCTION; + break; + case BRW_USAGE_RENDER_TARGET: + read = I915_GEM_DOMAIN_RENDER; + write = 0; + break; + case BRW_USAGE_DEPTH_BUFFER: + read = I915_GEM_DOMAIN_RENDER; + write = I915_GEM_DOMAIN_RENDER; + break; + case BRW_USAGE_BLIT_SOURCE: + read = 0; + write = I915_GEM_DOMAIN_RENDER; + break; + case BRW_USAGE_BLIT_DEST: + read = I915_GEM_DOMAIN_RENDER; + write = I915_GEM_DOMAIN_RENDER; + break; + case BRW_USAGE_SAMPLER: + read = I915_GEM_DOMAIN_SAMPLER; + write = 0; + break; + case BRW_USAGE_VERTEX: + read = I915_GEM_DOMAIN_VERTEX; + write = 0; + break; + case BRW_USAGE_SCRATCH: + read = 0; + write = 0; + break; + default: + assert(0); + return -1; + } + + /* Needed?? + ((uint32_t *)buf->bo->virtual)[offset/4] = (delta + + buf2->bo->offset); + */ + + ret = dri_bo_emit_reloc( buf->bo, read, write, delta, offset, buf2->bo ); + if (ret) + return -1; + + return 0; +} + +static enum pipe_error +i965_libdrm_bo_exec(struct brw_winsys_buffer *buffer, + unsigned bytes_used) +{ + struct i965_libdrm_buffer *buf = i965_libdrm_buffer(buffer); + struct i965_libdrm_winsys *idws = i965_libdrm_winsys(buffer->sws); + int ret; + + if (BRW_DUMP) + debug_printf("execute buffer %p, bytes %d\n", (void *)buffer, bytes_used); + + if (idws->send_cmd) { + ret = dri_bo_exec(buf->bo, bytes_used, NULL, 0, 0); + if (ret) + return PIPE_ERROR; + } + + return PIPE_OK; +} + +static enum pipe_error +i965_libdrm_bo_subdata(struct brw_winsys_buffer *buffer, + enum brw_buffer_data_type data_type, + size_t offset, + size_t size, + const void *data, + const struct brw_winsys_reloc *reloc, + unsigned nr_reloc) +{ + struct i965_libdrm_buffer *buf = i965_libdrm_buffer(buffer); + struct i965_libdrm_winsys *idws = i965_libdrm_winsys(buffer->sws); + int ret, i; + + (void)data_type; + + if (BRW_DUMP) + debug_printf("%s buf %p off %d sz %d %s relocs: %d\n", + __FUNCTION__, + (void *)buffer, offset, size, + data_types[data_type], + nr_reloc); + + if (BRW_DUMP) + brw_dump_data( idws->id, + data_type, + buf->bo->offset + offset, + data, size ); + + /* XXX: use bo_map_gtt/memcpy/unmap_gtt under some circumstances??? + */ + ret = drm_intel_bo_subdata(buf->bo, offset, size, (void*)data); + if (ret) + return PIPE_ERROR; + + for (i = 0; i < nr_reloc; i++) { + i965_libdrm_bo_emit_reloc(buffer, reloc[i].usage, reloc[i].delta, + reloc[i].offset, reloc[i].bo); + } + + return PIPE_OK; +} + +static boolean +i965_libdrm_bo_is_busy(struct brw_winsys_buffer *buffer) +{ + struct i965_libdrm_buffer *buf = i965_libdrm_buffer(buffer); + boolean ret; + + if (BRW_DUMP) + debug_printf("%s %p\n", __FUNCTION__, (void *)buffer); + + ret = drm_intel_bo_busy(buf->bo); + + if (BRW_DUMP) + debug_printf(" --> %d\n", ret); + + return ret; +} + +static boolean +i965_libdrm_bo_references(struct brw_winsys_buffer *a, + struct brw_winsys_buffer *b) +{ + struct i965_libdrm_buffer *bufa = i965_libdrm_buffer(a); + struct i965_libdrm_buffer *bufb = i965_libdrm_buffer(b); + boolean ret; + + if (BRW_DUMP) + debug_printf("%s %p %p\n", __FUNCTION__, (void *)a, (void *)b); + + ret = drm_intel_bo_references(bufa->bo, bufb->bo); + + if (BRW_DUMP) + debug_printf(" --> %d\n", ret); + + return ret; +} + +/* XXX: couldn't this be handled by returning true/false on + * bo_emit_reloc? + */ +static enum pipe_error +i965_libdrm_check_aperture_space(struct brw_winsys_screen *iws, + struct brw_winsys_buffer **buffers, + unsigned count) +{ + static drm_intel_bo *bos[128]; + int i; + int ret; + + if (BRW_DUMP) + debug_printf("%s\n", __FUNCTION__); + + if (count > Elements(bos)) { + assert(0); + return FALSE; + } + + for (i = 0; i < count; i++) + bos[i] = i965_libdrm_buffer(buffers[i])->bo; + + /* XXX: converting from ??? to pipe_error: + */ + ret = dri_bufmgr_check_aperture_space(bos, count); + + if (BRW_DUMP) + debug_printf(" --> %d (ok == %d)\n", ret, PIPE_OK); + + return ret; +} + +static void * +i965_libdrm_bo_map(struct brw_winsys_buffer *buffer, + enum brw_buffer_data_type data_type, + unsigned offset, + unsigned length, + boolean write, + boolean discard, + boolean flush_explicit) +{ + struct i965_libdrm_buffer *buf = i965_libdrm_buffer(buffer); + int ret; + + + if (BRW_DUMP) + debug_printf("%s %p %s %s\n", __FUNCTION__, (void *)buffer, + write ? "read/write" : "read", + write ? data_types[data_type] : ""); + + if (!buf->map_count) { + if (buf->map_gtt) { + ret = drm_intel_gem_bo_map_gtt(buf->bo); + if (ret) + return NULL; + } + else { + ret = drm_intel_bo_map(buf->bo, write); + if (ret) + return NULL; + } + } + + buf->data_type = data_type; + buf->map_count++; + return buf->bo->virtual; +} + +static void +i965_libdrm_bo_flush_range(struct brw_winsys_buffer *buffer, + unsigned offset, + unsigned length) +{ + struct i965_libdrm_buffer *buf = i965_libdrm_buffer(buffer); + struct i965_libdrm_winsys *idws = i965_libdrm_winsys(buffer->sws); + + if (BRW_DUMP) + debug_printf("%s %s offset %d len %d\n", __FUNCTION__, + data_types[buf->data_type], + offset, length); + + if (BRW_DUMP) + brw_dump_data( idws->id, + buf->data_type, + buf->bo->offset + offset, + buf->bo->virtual + offset, + length ); +} + +static void +i965_libdrm_bo_unmap(struct brw_winsys_buffer *buffer) +{ + struct i965_libdrm_buffer *buf = i965_libdrm_buffer(buffer); + + if (BRW_DUMP) + debug_printf("%s\n", __FUNCTION__); + + if (--buf->map_count > 0) + return; + + if (buf->map_gtt) + drm_intel_gem_bo_unmap_gtt(buf->bo); + else + drm_intel_bo_unmap(buf->bo); +} + +void +i965_libdrm_winsys_init_buffer_functions(struct i965_libdrm_winsys *idws) +{ + idws->base.bo_alloc = i965_libdrm_bo_alloc; + idws->base.bo_from_handle = i965_libdrm_bo_from_handle; + idws->base.bo_get_handle = i965_libdrm_bo_get_handle; + idws->base.bo_destroy = i965_libdrm_bo_destroy; + idws->base.bo_emit_reloc = i965_libdrm_bo_emit_reloc; + idws->base.bo_exec = i965_libdrm_bo_exec; + idws->base.bo_subdata = i965_libdrm_bo_subdata; + idws->base.bo_is_busy = i965_libdrm_bo_is_busy; + idws->base.bo_references = i965_libdrm_bo_references; + idws->base.check_aperture_space = i965_libdrm_check_aperture_space; + idws->base.bo_map = i965_libdrm_bo_map; + idws->base.bo_flush_range = i965_libdrm_bo_flush_range; + idws->base.bo_unmap = i965_libdrm_bo_unmap; +} diff --git a/src/gallium/winsys/i965/drm/i965_drm_winsys.h b/src/gallium/winsys/i965/drm/i965_drm_winsys.h new file mode 100644 index 00000000000..c6a7d4a8c51 --- /dev/null +++ b/src/gallium/winsys/i965/drm/i965_drm_winsys.h @@ -0,0 +1,64 @@ + +#ifndef INTEL_DRM_WINSYS_H +#define INTEL_DRM_WINSYS_H + +#include "i965/brw_winsys.h" + +#include "drm.h" +#include "intel_bufmgr.h" + + + +/* + * Winsys + */ + + +struct i965_libdrm_winsys +{ + struct brw_winsys_screen base; + drm_intel_bufmgr *gem; + + boolean send_cmd; + + int fd; /**< Drm file discriptor */ + + unsigned id; +}; + +static INLINE struct i965_libdrm_winsys * +i965_libdrm_winsys(struct brw_winsys_screen *iws) +{ + return (struct i965_libdrm_winsys *)iws; +} + +struct i965_libdrm_winsys *i965_libdrm_winsys_create(int fd, unsigned pci_id); + +void i965_libdrm_winsys_init_buffer_functions(struct i965_libdrm_winsys *idws); + + +/* Buffer. + */ +struct i965_libdrm_buffer { + struct brw_winsys_buffer base; + + drm_intel_bo *bo; + + void *ptr; + unsigned map_count; + unsigned data_type; /* valid while mapped */ + unsigned tiling; + + boolean map_gtt; + boolean flinked; + unsigned flink; +}; + +static INLINE struct i965_libdrm_buffer * +i965_libdrm_buffer(struct brw_winsys_buffer *buffer) +{ + return (struct i965_libdrm_buffer *)buffer; +} + + +#endif diff --git a/src/gallium/winsys/i965/xlib/Makefile b/src/gallium/winsys/i965/xlib/Makefile new file mode 100644 index 00000000000..3730db6997e --- /dev/null +++ b/src/gallium/winsys/i965/xlib/Makefile @@ -0,0 +1,97 @@ +# src/gallium/winsys/i965/xlib/Makefile + +# This makefile produces a "stand-alone" libGL.so which is based on +# Xlib (no DRI HW acceleration) + + +TOP = ../../../../.. +include $(TOP)/configs/current + + +GL_MAJOR = 1 +GL_MINOR = 5 +GL_TINY = 0$(MESA_MAJOR)0$(MESA_MINOR)0$(MESA_TINY) + + +INCLUDE_DIRS = \ + -I$(TOP)/include \ + -I$(TOP)/src/mesa \ + -I$(TOP)/src/mesa/main \ + -I$(TOP)/src/gallium/include \ + -I$(TOP)/src/gallium/drivers \ + -I$(TOP)/src/gallium/drivers/i965 \ + -I$(TOP)/src/gallium/drivers/i965/include \ + -I$(TOP)/src/gallium/state_trackers/glx/xlib \ + -I$(TOP)/src/gallium/auxiliary \ + -I/usr/include/drm + +XLIB_WINSYS_SOURCES = \ + xlib_i965.c \ + + + +XLIB_WINSYS_OBJECTS = $(XLIB_WINSYS_SOURCES:.c=.o) + + + +LIBS = \ + $(TOP)/src/gallium/drivers/i965/libi965.a \ + $(TOP)/src/gallium/drivers/trace/libtrace.a \ + $(TOP)/src/gallium/state_trackers/glx/xlib/libxlib.a \ + $(TOP)/src/mesa/libglapi.a \ + $(TOP)/src/mesa/libmesagallium.a \ + $(GALLIUM_AUXILIARIES) + +# $(TOP)/src/gallium/drivers/i965/lib/libi9xx.a \ + +.SUFFIXES : .cpp + +.c.o: + $(CC) -c $(INCLUDE_DIRS) $(DEFINES) $(CFLAGS) $< -o $@ + +.cpp.o: + $(CXX) -c $(INCLUDE_DIRS) $(DEFINES) $(CXXFLAGS) $< -o $@ + + + +default: $(TOP)/$(LIB_DIR)/gallium $(TOP)/$(LIB_DIR)/gallium/$(GL_LIB_NAME) + +$(TOP)/$(LIB_DIR)/gallium: + @ mkdir -p $(TOP)/$(LIB_DIR)/gallium + +# Make the libGL.so library +$(TOP)/$(LIB_DIR)/gallium/$(GL_LIB_NAME): $(XLIB_WINSYS_OBJECTS) $(LIBS) Makefile + $(TOP)/bin/mklib -o $(GL_LIB) \ + -linker "$(CC)" \ + -major $(GL_MAJOR) -minor $(GL_MINOR) -patch $(GL_TINY) \ + -install $(TOP)/$(LIB_DIR)/gallium \ + $(MKLIB_OPTIONS) $(XLIB_WINSYS_OBJECTS) \ + -Wl,--start-group $(LIBS) -Wl,--end-group $(GL_LIB_DEPS) + + +depend: $(XLIB_WINSYS_SOURCES) + @ echo "running $(MKDEP)" + @ rm -f depend # workaround oops on gutsy?!? + @ touch depend + $(MKDEP) $(MKDEP_OPTIONS) $(DEFINES) $(INCLUDE_DIRS) $(XLIB_WINSYS_SOURCES) \ + > /dev/null 2>/dev/null + + +install: default + $(INSTALL) -d $(INSTALL_DIR)/include/GL + $(INSTALL) -d $(INSTALL_DIR)/$(LIB_DIR) + $(INSTALL) -m 644 $(TOP)/include/GL/*.h $(INSTALL_DIR)/include/GL + @if [ -e $(TOP)/$(LIB_DIR)/$(GL_LIB_NAME) ]; then \ + $(MINSTALL) $(TOP)/$(LIB_DIR)/libGL* $(INSTALL_DIR)/$(LIB_DIR); \ + fi + + +# Emacs tags +tags: + etags `find . -name \*.[ch]` $(TOP)/include/GL/*.h + +clean: + -rm -f *.o + + +include depend diff --git a/src/gallium/winsys/i965/xlib/xlib_i965.c b/src/gallium/winsys/i965/xlib/xlib_i965.c new file mode 100644 index 00000000000..063e9f600b9 --- /dev/null +++ b/src/gallium/winsys/i965/xlib/xlib_i965.c @@ -0,0 +1,503 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Bismarck, ND., USA + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * + **************************************************************************/ + +/* + * Authors: + * Keith Whitwell + * Brian Paul + */ + + +#include "util/u_memory.h" +#include "util/u_math.h" +#include "pipe/p_error.h" +#include "pipe/p_context.h" + +#include "xm_public.h" + +#include "i965/brw_winsys.h" +#include "i965/brw_screen.h" +#include "i965/brw_reg.h" +#include "i965/brw_structs_dump.h" + +#define MAX_VRAM (128*1024*1024) + + + +extern int brw_disasm (FILE *file, + const struct brw_instruction *inst, + unsigned count ); + +extern int intel_decode(const uint32_t *data, + int count, + uint32_t hw_offset, + uint32_t devid); + +struct xlib_brw_buffer +{ + struct brw_winsys_buffer base; + char *virtual; + unsigned offset; + unsigned type; + int map_count; + boolean modified; +}; + + +/** + * Subclass of brw_winsys_screen for Xlib winsys + */ +struct xlib_brw_winsys +{ + struct brw_winsys_screen base; + struct brw_chipset chipset; + + unsigned size; + unsigned used; +}; + +static struct xlib_brw_winsys * +xlib_brw_winsys( struct brw_winsys_screen *screen ) +{ + return (struct xlib_brw_winsys *)screen; +} + + +static struct xlib_brw_buffer * +xlib_brw_buffer( struct brw_winsys_buffer *buffer ) +{ + return (struct xlib_brw_buffer *)buffer; +} + + + +const char *names[BRW_BUFFER_TYPE_MAX] = { + "TEXTURE", + "SCANOUT", + "VERTEX", + "CURBE", + "QUERY", + "SHADER_CONSTANTS", + "WM_SCRATCH", + "BATCH", + "GENERAL_STATE", + "SURFACE_STATE", + "PIXEL", + "GENERIC", +}; + +const char *usages[BRW_USAGE_MAX] = { + "STATE", + "QUERY_RESULT", + "RENDER_TARGET", + "DEPTH_BUFFER", + "BLIT_SOURCE", + "BLIT_DEST", + "SAMPLER", + "VERTEX", + "SCRATCH" +}; + + +const char *data_types[BRW_DATA_MAX] = +{ + "GS: CC_VP", + "GS: CC_UNIT", + "GS: WM_PROG", + "GS: SAMPLER_DEFAULT_COLOR", + "GS: SAMPLER", + "GS: WM_UNIT", + "GS: SF_PROG", + "GS: SF_VP", + "GS: SF_UNIT", + "GS: VS_UNIT", + "GS: VS_PROG", + "GS: GS_UNIT", + "GS: GS_PROG", + "GS: CLIP_VP", + "GS: CLIP_UNIT", + "GS: CLIP_PROG", + "SS: SURFACE", + "SS: SURF_BIND", + "CONSTANT DATA", + "BATCH DATA", + "(untyped)" +}; + + +static enum pipe_error +xlib_brw_bo_alloc( struct brw_winsys_screen *sws, + enum brw_buffer_type type, + unsigned size, + unsigned alignment, + struct brw_winsys_buffer **bo_out ) +{ + struct xlib_brw_winsys *xbw = xlib_brw_winsys(sws); + struct xlib_brw_buffer *buf; + + if (BRW_DEBUG & DEBUG_WINSYS) + debug_printf("%s type %s sz %d align %d\n", + __FUNCTION__, names[type], size, alignment ); + + buf = CALLOC_STRUCT(xlib_brw_buffer); + if (!buf) + return PIPE_ERROR_OUT_OF_MEMORY; + + pipe_reference_init(&buf->base.reference, 1); + + buf->offset = align(xbw->used, alignment); + buf->type = type; + buf->virtual = MALLOC(size); + buf->base.size = size; + buf->base.sws = sws; + + xbw->used = align(xbw->used, alignment) + size; + if (xbw->used > MAX_VRAM) + goto err; + + /* XXX: possibly rentrant call to bo_destroy: + */ + bo_reference(bo_out, &buf->base); + return PIPE_OK; + +err: + assert(0); + FREE(buf->virtual); + FREE(buf); + return PIPE_ERROR_OUT_OF_MEMORY; +} + +static void +xlib_brw_bo_destroy( struct brw_winsys_buffer *buffer ) +{ + struct xlib_brw_buffer *buf = xlib_brw_buffer(buffer); + + FREE(buf); +} + +static int +xlib_brw_bo_emit_reloc( struct brw_winsys_buffer *buffer, + enum brw_buffer_usage usage, + unsigned delta, + unsigned offset, + struct brw_winsys_buffer *buffer2) +{ + struct xlib_brw_buffer *buf = xlib_brw_buffer(buffer); + struct xlib_brw_buffer *buf2 = xlib_brw_buffer(buffer2); + + if (BRW_DEBUG & DEBUG_WINSYS) + debug_printf("%s buf %p offset %x val %x + %x buf2 %p/%s/%s\n", + __FUNCTION__, (void *)buffer, offset, + buf2->offset, delta, + (void *)buffer2, names[buf2->type], usages[usage]); + + *(uint32_t *)(buf->virtual + offset) = buf2->offset + delta; + + return 0; +} + +static int +xlib_brw_bo_exec( struct brw_winsys_buffer *buffer, + unsigned bytes_used ) +{ + if (BRW_DEBUG & DEBUG_WINSYS) + debug_printf("execute buffer %p, bytes %d\n", (void *)buffer, bytes_used); + + return 0; +} + + + + +static int +xlib_brw_bo_subdata(struct brw_winsys_buffer *buffer, + enum brw_buffer_data_type data_type, + size_t offset, + size_t size, + const void *data, + const struct brw_winsys_reloc *reloc, + unsigned nr_relocs) +{ + struct xlib_brw_buffer *buf = xlib_brw_buffer(buffer); + struct xlib_brw_winsys *xbw = xlib_brw_winsys(buffer->sws); + unsigned i; + + if (BRW_DEBUG & DEBUG_WINSYS) + debug_printf("%s buf %p off %d sz %d %s relocs: %d\n", + __FUNCTION__, + (void *)buffer, offset, size, + data_types[data_type], + nr_relocs); + + assert(buf->base.size >= offset + size); + memcpy(buf->virtual + offset, data, size); + + /* Apply the relocations: + */ + for (i = 0; i < nr_relocs; i++) { + if (BRW_DEBUG & DEBUG_WINSYS) + debug_printf("\treloc[%d] usage %s off %d value %x+%x\n", + i, usages[reloc[i].usage], reloc[i].offset, + xlib_brw_buffer(reloc[i].bo)->offset, reloc[i].delta); + + *(unsigned *)(buf->virtual + offset + reloc[i].offset) = + xlib_brw_buffer(reloc[i].bo)->offset + reloc[i].delta; + } + + if (BRW_DUMP) + brw_dump_data( xbw->chipset.pci_id, + data_type, + buf->offset + offset, + buf->virtual + offset, size ); + + + return 0; +} + + +static boolean +xlib_brw_bo_is_busy(struct brw_winsys_buffer *buffer) +{ + if (BRW_DEBUG & DEBUG_WINSYS) + debug_printf("%s %p\n", __FUNCTION__, (void *)buffer); + return TRUE; +} + +static boolean +xlib_brw_bo_references(struct brw_winsys_buffer *a, + struct brw_winsys_buffer *b) +{ + if (BRW_DEBUG & DEBUG_WINSYS) + debug_printf("%s %p %p\n", __FUNCTION__, (void *)a, (void *)b); + return TRUE; +} + +static enum pipe_error +xlib_brw_check_aperture_space( struct brw_winsys_screen *iws, + struct brw_winsys_buffer **buffers, + unsigned count ) +{ + unsigned tot_size = 0; + unsigned i; + + for (i = 0; i < count; i++) + tot_size += buffers[i]->size; + + if (BRW_DEBUG & DEBUG_WINSYS) + debug_printf("%s %d bufs, tot_size: %d kb\n", + __FUNCTION__, count, + (tot_size + 1023) / 1024); + + return PIPE_OK; +} + +static void * +xlib_brw_bo_map(struct brw_winsys_buffer *buffer, + enum brw_buffer_data_type data_type, + unsigned offset, + unsigned length, + boolean write, + boolean discard, + boolean explicit) +{ + struct xlib_brw_buffer *buf = xlib_brw_buffer(buffer); + + if (BRW_DEBUG & DEBUG_WINSYS) + debug_printf("%s %p %s %s\n", __FUNCTION__, (void *)buffer, + write ? "read/write" : "read", + write ? data_types[data_type] : ""); + + if (write) + buf->modified = 1; + + buf->map_count++; + return buf->virtual; +} + + +static void +xlib_brw_bo_flush_range( struct brw_winsys_buffer *buffer, + unsigned offset, + unsigned length ) +{ +} + + +static void +xlib_brw_bo_unmap(struct brw_winsys_buffer *buffer) +{ + struct xlib_brw_buffer *buf = xlib_brw_buffer(buffer); + + if (BRW_DEBUG & DEBUG_WINSYS) + debug_printf("%s %p\n", __FUNCTION__, (void *)buffer); + + --buf->map_count; + assert(buf->map_count >= 0); + + if (buf->map_count == 0 && + buf->modified) { + + buf->modified = 0; + + /* Consider dumping new buffer contents here, using the + * flush-range info to minimize verbosity. + */ + } +} + + +static void +xlib_brw_bo_wait_idle( struct brw_winsys_buffer *buffer ) +{ +} + + +static void +xlib_brw_winsys_destroy( struct brw_winsys_screen *sws ) +{ + struct xlib_brw_winsys *xbw = xlib_brw_winsys(sws); + + FREE(xbw); +} + +static struct brw_winsys_screen * +xlib_create_brw_winsys_screen( void ) +{ + struct xlib_brw_winsys *ws; + + ws = CALLOC_STRUCT(xlib_brw_winsys); + if (!ws) + return NULL; + + ws->used = 0; + + ws->base.destroy = xlib_brw_winsys_destroy; + ws->base.bo_alloc = xlib_brw_bo_alloc; + ws->base.bo_destroy = xlib_brw_bo_destroy; + ws->base.bo_emit_reloc = xlib_brw_bo_emit_reloc; + ws->base.bo_exec = xlib_brw_bo_exec; + ws->base.bo_subdata = xlib_brw_bo_subdata; + ws->base.bo_is_busy = xlib_brw_bo_is_busy; + ws->base.bo_references = xlib_brw_bo_references; + ws->base.check_aperture_space = xlib_brw_check_aperture_space; + ws->base.bo_map = xlib_brw_bo_map; + ws->base.bo_flush_range = xlib_brw_bo_flush_range; + ws->base.bo_unmap = xlib_brw_bo_unmap; + ws->base.bo_wait_idle = xlib_brw_bo_wait_idle; + + return &ws->base; +} + + +/*********************************************************************** + * Implementation of Xlib co-state-tracker's winsys interface + */ + +static void +xlib_i965_display_surface(struct xmesa_buffer *xm_buffer, + struct pipe_surface *surf) +{ + struct brw_surface *surface = brw_surface(surf); + struct xlib_brw_buffer *bo = xlib_brw_buffer(surface->bo); + + if (BRW_DEBUG & DEBUG_WINSYS) + debug_printf("%s offset %x+%x sz %dx%d\n", __FUNCTION__, + bo->offset, + surface->draw_offset, + surf->width, + surf->height); +} + +static void +xlib_i965_flush_frontbuffer(struct pipe_screen *screen, + struct pipe_surface *surf, + void *context_private) +{ + xlib_i965_display_surface(NULL, surf); +} + + +static struct pipe_screen * +xlib_create_i965_screen( void ) +{ + struct brw_winsys_screen *winsys; + struct pipe_screen *screen; + + winsys = xlib_create_brw_winsys_screen(); + if (winsys == NULL) + return NULL; + + screen = brw_create_screen(winsys, PCI_CHIP_GM45_GM); + if (screen == NULL) + goto fail; + + xlib_brw_winsys(winsys)->chipset = brw_screen(screen)->chipset; + + screen->flush_frontbuffer = xlib_i965_flush_frontbuffer; + return screen; + +fail: + if (winsys) + winsys->destroy( winsys ); + + return NULL; +} + + + + + +struct xm_driver xlib_i965_driver = +{ + .create_pipe_screen = xlib_create_i965_screen, + .display_surface = xlib_i965_display_surface +}; + + +/* Register this driver at library load: + */ +static void _init( void ) __attribute__((constructor)); +static void _init( void ) +{ + xmesa_set_driver( &xlib_i965_driver ); +} + + + +/*********************************************************************** + * + * Butt-ugly hack to convince the linker not to throw away public GL + * symbols (they are all referenced from getprocaddress, I guess). + */ +extern void (*linker_foo(const unsigned char *procName))(); +extern void (*glXGetProcAddress(const unsigned char *procName))(); + +extern void (*linker_foo(const unsigned char *procName))() +{ + return glXGetProcAddress(procName); +} diff --git a/src/gallium/winsys/nouveau/drm/Makefile b/src/gallium/winsys/nouveau/drm/Makefile new file mode 100644 index 00000000000..71029858f75 --- /dev/null +++ b/src/gallium/winsys/nouveau/drm/Makefile @@ -0,0 +1,11 @@ +TOP = ../../../../.. +include $(TOP)/configs/current + +LIBNAME = nouveaudrm + +C_SOURCES = nouveau_drm_api.c + +LIBRARY_INCLUDES = $(shell pkg-config libdrm libdrm_nouveau --cflags-only-I) +LIBRARY_DEFINES = $(shell pkg-config libdrm libdrm_nouveau --cflags-only-other) + +include ../../../Makefile.template diff --git a/src/gallium/winsys/nouveau/drm/nouveau_dri.h b/src/gallium/winsys/nouveau/drm/nouveau_dri.h new file mode 100644 index 00000000000..1207c2d609c --- /dev/null +++ b/src/gallium/winsys/nouveau/drm/nouveau_dri.h @@ -0,0 +1,28 @@ +#ifndef _NOUVEAU_DRI_ +#define _NOUVEAU_DRI_ + +#include "xf86drm.h" +#include "drm.h" +#include "nouveau_drm.h" + +struct nouveau_dri { + uint32_t device_id; /**< \brief PCI device ID */ + uint32_t width; /**< \brief width in pixels of display */ + uint32_t height; /**< \brief height in scanlines of display */ + uint32_t depth; /**< \brief depth of display (8, 15, 16, 24) */ + uint32_t bpp; /**< \brief bit depth of display (8, 16, 24, 32) */ + + uint32_t bus_type; /**< \brief ths bus type */ + uint32_t bus_mode; /**< \brief bus mode (used for AGP, maybe also for PCI-E ?) */ + + uint32_t front_offset; /**< \brief front buffer offset */ + uint32_t front_pitch; /**< \brief front buffer pitch */ + uint32_t back_offset; /**< \brief private back buffer offset */ + uint32_t back_pitch; /**< \brief private back buffer pitch */ + uint32_t depth_offset; /**< \brief private depth buffer offset */ + uint32_t depth_pitch; /**< \brief private depth buffer pitch */ + +}; + +#endif + diff --git a/src/gallium/winsys/nouveau/drm/nouveau_drm_api.c b/src/gallium/winsys/nouveau/drm/nouveau_drm_api.c new file mode 100644 index 00000000000..716d4bacd3b --- /dev/null +++ b/src/gallium/winsys/nouveau/drm/nouveau_drm_api.c @@ -0,0 +1,157 @@ +#include "pipe/p_context.h" +#include "pipe/p_state.h" +#include "util/u_format.h" +#include "util/u_memory.h" +#include "util/u_inlines.h" + +#include "nouveau_drm_api.h" + +#include "nouveau_drmif.h" +#include "nouveau_channel.h" +#include "nouveau_bo.h" + +#include "nouveau/nouveau_winsys.h" +#include "nouveau/nouveau_screen.h" + +static struct pipe_surface * +dri_surface_from_handle(struct drm_api *api, struct pipe_screen *pscreen, + unsigned handle, enum pipe_format format, + unsigned width, unsigned height, unsigned pitch) +{ + struct pipe_surface *ps = NULL; + struct pipe_texture *pt = NULL; + struct pipe_texture tmpl; + struct winsys_handle whandle; + + memset(&tmpl, 0, sizeof(tmpl)); + tmpl.tex_usage = PIPE_TEXTURE_USAGE_SCANOUT; + tmpl.target = PIPE_TEXTURE_2D; + tmpl.last_level = 0; + tmpl.depth0 = 1; + tmpl.format = format; + tmpl.width0 = width; + tmpl.height0 = height; + + memset(&whandle, 0, sizeof(whandle)); + whandle.stride = pitch; + whandle.handle = handle; + + pt = pscreen->texture_from_handle(pscreen, &tmpl, &whandle); + if (!pt) + return NULL; + + ps = pscreen->get_tex_surface(pscreen, pt, 0, 0, 0, + PIPE_BUFFER_USAGE_GPU_READ | + PIPE_BUFFER_USAGE_GPU_WRITE); + + /* we don't need the texture from this point on */ + pipe_texture_reference(&pt, NULL); + return ps; +} + +static struct pipe_surface * +nouveau_dri1_front_surface(struct pipe_context *pipe) +{ + return nouveau_winsys_screen(pipe->screen)->front; +} + +static struct dri1_api nouveau_dri1_api = { + nouveau_dri1_front_surface, +}; + +static void +nouveau_drm_destroy_winsys(struct pipe_winsys *s) +{ + struct nouveau_winsys *nv_winsys = nouveau_winsys(s); + struct nouveau_screen *nv_screen= nouveau_screen(nv_winsys->pscreen); + nouveau_device_close(&nv_screen->device); + FREE(nv_winsys); +} + +static struct pipe_screen * +nouveau_drm_create_screen(struct drm_api *api, int fd, + struct drm_create_screen_arg *arg) +{ + struct dri1_create_screen_arg *dri1 = (void *)arg; + struct nouveau_winsys *nvws; + struct pipe_winsys *ws; + struct nouveau_device *dev = NULL; + struct pipe_screen *(*init)(struct pipe_winsys *, + struct nouveau_device *); + int ret; + + ret = nouveau_device_open_existing(&dev, 0, fd, 0); + if (ret) + return NULL; + + switch (dev->chipset & 0xf0) { + case 0x30: + case 0x40: + case 0x60: + init = nvfx_screen_create; + break; + case 0x50: + case 0x80: + case 0x90: + case 0xa0: + init = nv50_screen_create; + break; + default: + debug_printf("%s: unknown chipset nv%02x\n", __func__, + dev->chipset); + return NULL; + } + + nvws = CALLOC_STRUCT(nouveau_winsys); + if (!nvws) { + nouveau_device_close(&dev); + return NULL; + } + ws = &nvws->base; + ws->destroy = nouveau_drm_destroy_winsys; + + nvws->pscreen = init(ws, dev); + if (!nvws->pscreen) { + ws->destroy(ws); + return NULL; + } + + if (arg && arg->mode == DRM_CREATE_DRI1) { + struct nouveau_dri *nvdri = dri1->ddx_info; + enum pipe_format format; + + if (nvdri->bpp == 16) + format = PIPE_FORMAT_B5G6R5_UNORM; + else + format = PIPE_FORMAT_B8G8R8A8_UNORM; + + nvws->front = dri_surface_from_handle(api, nvws->pscreen, + nvdri->front_offset, + format, nvdri->width, + nvdri->height, + nvdri->front_pitch * + (nvdri->bpp / 8)); + if (!nvws->front) { + debug_printf("%s: error referencing front buffer\n", + __func__); + ws->destroy(ws); + return NULL; + } + + dri1->api = &nouveau_dri1_api; + } + + return nvws->pscreen; +} + +struct drm_api drm_api_hooks = { + .name = "nouveau", + .driver_name = "nouveau", + .create_screen = nouveau_drm_create_screen, +}; + +struct drm_api * +drm_api_create() { + return &drm_api_hooks; +} + diff --git a/src/gallium/winsys/nouveau/drm/nouveau_drm_api.h b/src/gallium/winsys/nouveau/drm/nouveau_drm_api.h new file mode 100644 index 00000000000..a91aad7df8e --- /dev/null +++ b/src/gallium/winsys/nouveau/drm/nouveau_drm_api.h @@ -0,0 +1,31 @@ +#ifndef __NOUVEAU_DRM_API_H__ +#define __NOUVEAU_DRM_API_H__ + +#include "state_tracker/drm_api.h" +#include "state_tracker/dri1_api.h" + +#include "util/u_simple_screen.h" + +#include "nouveau_dri.h" + +struct nouveau_winsys { + struct pipe_winsys base; + + struct pipe_screen *pscreen; + + struct pipe_surface *front; +}; + +static INLINE struct nouveau_winsys * +nouveau_winsys(struct pipe_winsys *ws) +{ + return (struct nouveau_winsys *)ws; +} + +static INLINE struct nouveau_winsys * +nouveau_winsys_screen(struct pipe_screen *pscreen) +{ + return nouveau_winsys(pscreen->winsys); +} + +#endif diff --git a/src/gallium/winsys/null/Makefile b/src/gallium/winsys/null/Makefile deleted file mode 100644 index 3a3fb75ab36..00000000000 --- a/src/gallium/winsys/null/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -TOP = ../../../.. -include $(TOP)/configs/current - -LIBNAME = ws_null - -LIBRARY_INCLUDES = \ - -I$(TOP)/src/gallium/include \ - -I$(TOP)/src/gallium/drivers \ - -I$(TOP)/src/gallium/auxiliary - -C_SOURCES = \ - null_sw_winsys.c - -include ../../Makefile.template - - diff --git a/src/gallium/winsys/null/SConscript b/src/gallium/winsys/null/SConscript deleted file mode 100644 index 21837dc60c2..00000000000 --- a/src/gallium/winsys/null/SConscript +++ /dev/null @@ -1,21 +0,0 @@ -####################################################################### -# SConscript for xlib winsys - - -Import('*') - -env = env.Clone() - -env.Append(CPPPATH = [ - '#/src/gallium/include', - '#/src/gallium/auxiliary', - '#/src/gallium/drivers', -]) - -ws_null = env.ConvenienceLibrary( - target = 'ws_null', - source = [ - 'null_sw_winsys.c', - ] -) -Export('ws_null') diff --git a/src/gallium/winsys/null/null_sw_winsys.c b/src/gallium/winsys/null/null_sw_winsys.c deleted file mode 100644 index 5027e57b303..00000000000 --- a/src/gallium/winsys/null/null_sw_winsys.c +++ /dev/null @@ -1,148 +0,0 @@ -/************************************************************************** - * - * Copyright 2010 VMware, Inc. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL - * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE - * USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - **************************************************************************/ - -/** - * @file - * Null software rasterizer winsys. - * - * There is no present support. Framebuffer data needs to be obtained via - * transfers. - * - * @author Jose Fonseca - */ - - -#include "pipe/p_format.h" -#include "util/u_memory.h" -#include "state_tracker/sw_winsys.h" -#include "null_sw_winsys.h" - - -static boolean -null_sw_is_displaytarget_format_supported(struct sw_winsys *ws, - unsigned tex_usage, - enum pipe_format format ) -{ - return FALSE; -} - - -static void * -null_sw_displaytarget_map(struct sw_winsys *ws, - struct sw_displaytarget *dt, - unsigned flags ) -{ - assert(0); - return NULL; -} - - -static void -null_sw_displaytarget_unmap(struct sw_winsys *ws, - struct sw_displaytarget *dt ) -{ - assert(0); -} - - -static void -null_sw_displaytarget_destroy(struct sw_winsys *winsys, - struct sw_displaytarget *dt) -{ - assert(0); -} - - -static struct sw_displaytarget * -null_sw_displaytarget_create(struct sw_winsys *winsys, - unsigned tex_usage, - enum pipe_format format, - unsigned width, unsigned height, - unsigned alignment, - unsigned *stride) -{ - return NULL; -} - - -static struct sw_displaytarget * -null_sw_displaytarget_from_handle(struct sw_winsys *winsys, - const struct pipe_texture *templet, - struct winsys_handle *whandle, - unsigned *stride) -{ - return NULL; -} - - -static boolean -null_sw_displaytarget_get_handle(struct sw_winsys *winsys, - struct sw_displaytarget *dt, - struct winsys_handle *whandle) -{ - assert(0); - return FALSE; -} - - -static void -null_sw_displaytarget_display(struct sw_winsys *winsys, - struct sw_displaytarget *dt, - void *context_private) -{ - assert(0); -} - - -static void -null_sw_destroy(struct sw_winsys *winsys) -{ - FREE(winsys); -} - - -struct sw_winsys * -null_sw_create(void) -{ - static struct sw_winsys *winsys; - - winsys = CALLOC_STRUCT(sw_winsys); - if (!winsys) - return NULL; - - winsys->destroy = null_sw_destroy; - winsys->is_displaytarget_format_supported = null_sw_is_displaytarget_format_supported; - winsys->displaytarget_create = null_sw_displaytarget_create; - winsys->displaytarget_from_handle = null_sw_displaytarget_from_handle; - winsys->displaytarget_get_handle = null_sw_displaytarget_get_handle; - winsys->displaytarget_map = null_sw_displaytarget_map; - winsys->displaytarget_unmap = null_sw_displaytarget_unmap; - winsys->displaytarget_display = null_sw_displaytarget_display; - winsys->displaytarget_destroy = null_sw_displaytarget_destroy; - - return winsys; -} diff --git a/src/gallium/winsys/null/null_sw_winsys.h b/src/gallium/winsys/null/null_sw_winsys.h deleted file mode 100644 index 1986186febe..00000000000 --- a/src/gallium/winsys/null/null_sw_winsys.h +++ /dev/null @@ -1,40 +0,0 @@ -/************************************************************************** - * - * Copyright 2010 VMware, Inc. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL - * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE - * USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - **************************************************************************/ - - -#ifndef NULL_SW_WINSYS_H_ -#define NULL_SW_WINSYS_H_ - - -struct sw_winsys; - - -struct sw_winsys * -null_sw_create(void); - - -#endif /* NULL_SW_WINSYS_H_ */ diff --git a/src/gallium/winsys/radeon/drm/Makefile b/src/gallium/winsys/radeon/drm/Makefile new file mode 100644 index 00000000000..7f69e392735 --- /dev/null +++ b/src/gallium/winsys/radeon/drm/Makefile @@ -0,0 +1,17 @@ + +TOP = ../../../../.. +include $(TOP)/configs/current + +LIBNAME = radeonwinsys + +C_SOURCES = \ + radeon_drm_buffer.c \ + radeon_drm.c \ + radeon_r300.c + +LIBRARY_INCLUDES = -I$(TOP)/src/gallium/drivers/r300 \ + $(shell pkg-config libdrm --cflags-only-I) + +include ../../../Makefile.template + +symlinks: diff --git a/src/gallium/winsys/radeon/drm/SConscript b/src/gallium/winsys/radeon/drm/SConscript new file mode 100644 index 00000000000..f4e9c397bdf --- /dev/null +++ b/src/gallium/winsys/radeon/drm/SConscript @@ -0,0 +1,18 @@ +Import('*') + +env = drienv.Clone() + +radeon_sources = [ + 'radeon_buffer.c', + 'radeon_drm.c', + 'radeon_r300.c', +] + +env.Append(CPPPATH = '#/src/gallium/drivers/r300') + +radeonwinsys = env.ConvenienceLibrary( + target ='radeonwinsys', + source = radeon_sources, +) + +Export('radeonwinsys') diff --git a/src/gallium/winsys/radeon/drm/radeon_buffer.h b/src/gallium/winsys/radeon/drm/radeon_buffer.h new file mode 100644 index 00000000000..218a3763018 --- /dev/null +++ b/src/gallium/winsys/radeon/drm/radeon_buffer.h @@ -0,0 +1,86 @@ +/* + * Copyright © 2008 Jérôme Glisse + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS + * AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + */ +/* + * Authors: + * Jérôme Glisse + */ +#ifndef RADEON_BUFFER_H +#define RADEON_BUFFER_H + +#include + +#include "pipe/p_defines.h" +#include "util/u_inlines.h" + +#include "pipebuffer/pb_buffer.h" +#include "pipebuffer/pb_bufmgr.h" + +#include "radeon_bo.h" +#include "radeon_cs.h" + +#include "radeon_winsys.h" + + +#define RADEON_MAX_BOS 24 + +static INLINE struct pb_buffer * +radeon_pb_buffer(struct r300_winsys_buffer *buffer) +{ + return (struct pb_buffer *)buffer; +} + +static INLINE struct r300_winsys_buffer * +radeon_libdrm_winsys_buffer(struct pb_buffer *buffer) +{ + return (struct r300_winsys_buffer *)buffer; +} + +struct pb_manager * +radeon_drm_bufmgr_create(struct radeon_libdrm_winsys *rws); + +boolean radeon_drm_bufmgr_add_buffer(struct pb_buffer *_buf, + uint32_t rd, uint32_t wd); + + +void radeon_drm_bufmgr_write_reloc(struct pb_buffer *_buf, + uint32_t rd, uint32_t wd, + uint32_t flags); + +struct pb_buffer *radeon_drm_bufmgr_create_buffer_from_handle(struct pb_manager *_mgr, + uint32_t handle); + +void radeon_drm_bufmgr_set_tiling(struct pb_buffer *_buf, + enum r300_buffer_tiling microtiled, + enum r300_buffer_tiling macrotiled, + uint32_t pitch); + +void radeon_drm_bufmgr_flush_maps(struct pb_manager *_mgr); + +boolean radeon_drm_bufmgr_get_handle(struct pb_buffer *_buf, + struct winsys_handle *whandle); + +boolean radeon_drm_bufmgr_is_buffer_referenced(struct pb_buffer *_buf); +#endif diff --git a/src/gallium/winsys/radeon/drm/radeon_drm.c b/src/gallium/winsys/radeon/drm/radeon_drm.c new file mode 100644 index 00000000000..3dfcc5aef07 --- /dev/null +++ b/src/gallium/winsys/radeon/drm/radeon_drm.c @@ -0,0 +1,200 @@ +/* + * Copyright © 2009 Corbin Simpson + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS + * AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + */ +/* + * Authors: + * Corbin Simpson + * Joakim Sindholt + */ + +#include "radeon_drm.h" +#include "radeon_r300.h" +#include "radeon_buffer.h" + +#include "r300_winsys.h" +#include "trace/tr_drm.h" + +#include "util/u_memory.h" + +#include "xf86drm.h" +#include + +static struct radeon_libdrm_winsys * +radeon_winsys_create(int fd) +{ + struct radeon_libdrm_winsys *rws; + + rws = CALLOC_STRUCT(radeon_libdrm_winsys); + if (rws == NULL) { + return NULL; + } + + rws->fd = fd; + return rws; +} + +/* Helper function to do the ioctls needed for setup and init. */ +static void do_ioctls(int fd, struct radeon_libdrm_winsys* winsys) +{ + struct drm_radeon_gem_info gem_info = {0}; + struct drm_radeon_info info = {0}; + int target = 0; + int retval; + drmVersionPtr version; + + info.value = (unsigned long)⌖ + + /* We do things in a specific order here. + * + * DRM version first. We need to be sure we're running on a KMS chipset. + * This is also for some features. + * + * Then, the PCI ID. This is essential and should return usable numbers + * for all Radeons. If this fails, we probably got handed an FD for some + * non-Radeon card. + * + * The GB and Z pipe requests should always succeed, but they might not + * return sensical values for all chipsets, but that's alright because + * the pipe drivers already know that. + * + * The GEM info is actually bogus on the kernel side, as well as our side + * (see radeon_gem_info_ioctl in radeon_gem.c) but that's alright because + * we don't actually use the info for anything yet. */ + + version = drmGetVersion(fd); + if (version->version_major != 2) { + fprintf(stderr, "%s: DRM version is %d.%d.%d but this driver is " + "only compatible with 2.x.x\n", __FUNCTION__, + version->version_major, version->version_minor, + version->version_patchlevel); + drmFreeVersion(version); + exit(1); + } + +/* XXX Remove this ifdef when libdrm version 2.4.19 becomes mandatory. */ +#ifdef RADEON_BO_FLAGS_MICRO_TILE_SQUARE + // Supported since 2.1.0. + winsys->squaretiling = version->version_major > 2 || + version->version_minor >= 1; +#endif + + info.request = RADEON_INFO_DEVICE_ID; + retval = drmCommandWriteRead(fd, DRM_RADEON_INFO, &info, sizeof(info)); + if (retval) { + fprintf(stderr, "%s: Failed to get PCI ID, " + "error number %d\n", __FUNCTION__, retval); + exit(1); + } + winsys->pci_id = target; + + info.request = RADEON_INFO_NUM_GB_PIPES; + retval = drmCommandWriteRead(fd, DRM_RADEON_INFO, &info, sizeof(info)); + if (retval) { + fprintf(stderr, "%s: Failed to get GB pipe count, " + "error number %d\n", __FUNCTION__, retval); + exit(1); + } + winsys->gb_pipes = target; + + info.request = RADEON_INFO_NUM_Z_PIPES; + retval = drmCommandWriteRead(fd, DRM_RADEON_INFO, &info, sizeof(info)); + if (retval) { + fprintf(stderr, "%s: Failed to get Z pipe count, " + "error number %d\n", __FUNCTION__, retval); + exit(1); + } + winsys->z_pipes = target; + + retval = drmCommandWriteRead(fd, DRM_RADEON_GEM_INFO, + &gem_info, sizeof(gem_info)); + if (retval) { + fprintf(stderr, "%s: Failed to get MM info, error number %d\n", + __FUNCTION__, retval); + exit(1); + } + winsys->gart_size = gem_info.gart_size; + winsys->vram_size = gem_info.vram_size; + + debug_printf("radeon: Successfully grabbed chipset info from kernel!\n" + "radeon: DRM version: %d.%d.%d ID: 0x%04x GB: %d Z: %d\n" + "radeon: GART size: %d MB VRAM size: %d MB\n", + version->version_major, version->version_minor, + version->version_patchlevel, winsys->pci_id, + winsys->gb_pipes, winsys->z_pipes, + winsys->gart_size / 1024 / 1024, + winsys->vram_size / 1024 / 1024); + + drmFreeVersion(version); +} + +/* Create a pipe_screen. */ +struct pipe_screen* radeon_create_screen(struct drm_api* api, + int drmFB, + struct drm_create_screen_arg *arg) +{ + struct radeon_libdrm_winsys* rws; + boolean ret; + + rws = radeon_winsys_create(drmFB); + if (!rws) + return NULL; + + do_ioctls(drmFB, rws); + + /* The state tracker can organize a softpipe fallback if no hw + * driver is found. + */ + if (is_r3xx(rws->pci_id)) { + ret = radeon_setup_winsys(drmFB, rws); + if (ret == FALSE) + goto fail; + return r300_create_screen(&rws->base); + } + +fail: + FREE(rws); + return NULL; +} + +static void radeon_drm_api_destroy(struct drm_api *api) +{ + return; +} + +struct drm_api drm_api_hooks = { + .name = "radeon", + .driver_name = "radeon", + .create_screen = radeon_create_screen, + .destroy = radeon_drm_api_destroy, +}; + +struct drm_api* drm_api_create() +{ +#ifdef DEBUG + return trace_drm_create(&drm_api_hooks); +#else + return &drm_api_hooks; +#endif +} diff --git a/src/gallium/winsys/radeon/drm/radeon_drm.h b/src/gallium/winsys/radeon/drm/radeon_drm.h new file mode 100644 index 00000000000..2dc077c0521 --- /dev/null +++ b/src/gallium/winsys/radeon/drm/radeon_drm.h @@ -0,0 +1,66 @@ +/* + * Copyright © 2009 Corbin Simpson + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS + * AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + */ +/* + * Authors: + * Corbin Simpson + */ +#ifndef RADEON_DRM_H +#define RADEON_DRM_H + +#include "state_tracker/drm_api.h" + + +struct pipe_screen* radeon_create_screen(struct drm_api* api, + int drmFB, + struct drm_create_screen_arg *arg); + +boolean radeon_buffer_from_texture(struct drm_api* api, + struct pipe_screen* screen, + struct pipe_texture* texture, + struct pipe_buffer** buffer, + unsigned* stride); + +boolean radeon_handle_from_buffer(struct drm_api* api, + struct pipe_screen* screen, + struct pipe_buffer* buffer, + unsigned* handle); + +boolean radeon_global_handle_from_buffer(struct drm_api* api, + struct pipe_screen* screen, + struct pipe_buffer* buffer, + unsigned* handle); + +void radeon_destroy_drm_api(struct drm_api* api); + +/* Guess at whether this chipset should use r300g. + * + * I believe that this check is valid, but I haven't been exhaustive. */ +static INLINE boolean is_r3xx(int pciid) +{ + return (pciid > 0x3150) && (pciid < 0x796f); +} + +#endif diff --git a/src/gallium/winsys/radeon/drm/radeon_drm_buffer.c b/src/gallium/winsys/radeon/drm/radeon_drm_buffer.c new file mode 100644 index 00000000000..66f61322457 --- /dev/null +++ b/src/gallium/winsys/radeon/drm/radeon_drm_buffer.c @@ -0,0 +1,385 @@ + +#include +#include "radeon_drm.h" +#include "radeon_bo_gem.h" +#include "radeon_cs_gem.h" +#include "radeon_buffer.h" + +#include "util/u_inlines.h" +#include "util/u_memory.h" +#include "util/u_simple_list.h" +#include "pipebuffer/pb_buffer.h" +#include "pipebuffer/pb_bufmgr.h" + +#include "radeon_winsys.h" +struct radeon_drm_bufmgr; + +struct radeon_drm_buffer { + struct pb_buffer base; + struct radeon_drm_bufmgr *mgr; + + struct radeon_bo *bo; + + boolean flinked; + uint32_t flink; + + struct radeon_drm_buffer *next, *prev; +}; + +extern const struct pb_vtbl radeon_drm_buffer_vtbl; + + +static INLINE struct radeon_drm_buffer * +radeon_drm_buffer(struct pb_buffer *buf) +{ + assert(buf); + assert(buf->vtbl == &radeon_drm_buffer_vtbl); + return (struct radeon_drm_buffer *)buf; +} + +struct radeon_drm_bufmgr { + struct pb_manager base; + struct radeon_libdrm_winsys *rws; + struct radeon_drm_buffer buffer_map_list; +}; + +static INLINE struct radeon_drm_bufmgr * +radeon_drm_bufmgr(struct pb_manager *mgr) +{ + assert(mgr); + return (struct radeon_drm_bufmgr *)mgr; +} + +static void +radeon_drm_buffer_destroy(struct pb_buffer *_buf) +{ + struct radeon_drm_buffer *buf = radeon_drm_buffer(_buf); + + if (buf->bo->ptr != NULL) { + remove_from_list(buf); + radeon_bo_unmap(buf->bo); + buf->bo->ptr = NULL; + } + radeon_bo_unref(buf->bo); + + FREE(buf); +} + +static void * +radeon_drm_buffer_map(struct pb_buffer *_buf, + unsigned flags) +{ + struct radeon_drm_buffer *buf = radeon_drm_buffer(_buf); + int write = 0; + + if (flags & PIPE_BUFFER_USAGE_DONTBLOCK) { + if ((_buf->base.usage & PIPE_BUFFER_USAGE_VERTEX) || + (_buf->base.usage & PIPE_BUFFER_USAGE_INDEX)) + if (radeon_bo_is_referenced_by_cs(buf->bo, buf->mgr->rws->cs)) + return NULL; + } + + if (buf->bo->ptr != NULL) + return buf->bo->ptr; + + if (flags & PIPE_BUFFER_USAGE_DONTBLOCK) { + uint32_t domain; + if (radeon_bo_is_busy(buf->bo, &domain)) + return NULL; + } + + if (radeon_bo_is_referenced_by_cs(buf->bo, buf->mgr->rws->cs)) { + buf->mgr->rws->flush_cb(buf->mgr->rws->flush_data); + } + + if (flags & PIPE_BUFFER_USAGE_CPU_WRITE) { + write = 1; + } + + if (radeon_bo_map(buf->bo, write)) { + return NULL; + } + insert_at_tail(&buf->mgr->buffer_map_list, buf); + return buf->bo->ptr; +} + +static void +radeon_drm_buffer_unmap(struct pb_buffer *_buf) +{ + (void)_buf; +} + +static void +radeon_drm_buffer_get_base_buffer(struct pb_buffer *buf, + struct pb_buffer **base_buf, + unsigned *offset) +{ + *base_buf = buf; + *offset = 0; +} + + +static enum pipe_error +radeon_drm_buffer_validate(struct pb_buffer *_buf, + struct pb_validate *vl, + unsigned flags) +{ + /* Always pinned */ + return PIPE_OK; +} + +static void +radeon_drm_buffer_fence(struct pb_buffer *buf, + struct pipe_fence_handle *fence) +{ +} + +const struct pb_vtbl radeon_drm_buffer_vtbl = { + radeon_drm_buffer_destroy, + radeon_drm_buffer_map, + radeon_drm_buffer_unmap, + radeon_drm_buffer_validate, + radeon_drm_buffer_fence, + radeon_drm_buffer_get_base_buffer, +}; + + +static uint32_t radeon_domain_from_usage(unsigned usage) +{ + uint32_t domain = 0; + + if (usage & PIPE_BUFFER_USAGE_GPU_WRITE) { + domain |= RADEON_GEM_DOMAIN_VRAM; + } + if (usage & PIPE_BUFFER_USAGE_PIXEL) { + domain |= RADEON_GEM_DOMAIN_VRAM; + } + if (usage & PIPE_BUFFER_USAGE_VERTEX) { + domain |= RADEON_GEM_DOMAIN_GTT; + } + if (usage & PIPE_BUFFER_USAGE_INDEX) { + domain |= RADEON_GEM_DOMAIN_GTT; + } + + return domain; +} + +struct pb_buffer *radeon_drm_bufmgr_create_buffer_from_handle(struct pb_manager *_mgr, + uint32_t handle) +{ + struct radeon_drm_bufmgr *mgr = radeon_drm_bufmgr(_mgr); + struct radeon_libdrm_winsys *rws = mgr->rws; + struct radeon_drm_buffer *buf; + struct radeon_bo *bo; + + bo = radeon_bo_open(rws->bom, handle, 0, + 0, 0, 0); + if (bo == NULL) + return NULL; + + buf = CALLOC_STRUCT(radeon_drm_buffer); + if (!buf) { + radeon_bo_unref(bo); + return NULL; + } + + make_empty_list(buf); + + pipe_reference_init(&buf->base.base.reference, 1); + buf->base.base.alignment = 0; + buf->base.base.usage = PIPE_BUFFER_USAGE_PIXEL; + buf->base.base.size = 0; + buf->base.vtbl = &radeon_drm_buffer_vtbl; + buf->mgr = mgr; + + buf->bo = bo; + + return &buf->base; +} + +static struct pb_buffer * +radeon_drm_bufmgr_create_buffer(struct pb_manager *_mgr, + pb_size size, + const struct pb_desc *desc) +{ + struct radeon_drm_bufmgr *mgr = radeon_drm_bufmgr(_mgr); + struct radeon_libdrm_winsys *rws = mgr->rws; + struct radeon_drm_buffer *buf; + uint32_t domain; + + buf = CALLOC_STRUCT(radeon_drm_buffer); + if (!buf) + goto error1; + + pipe_reference_init(&buf->base.base.reference, 1); + buf->base.base.alignment = desc->alignment; + buf->base.base.usage = desc->usage; + buf->base.base.size = size; + buf->base.vtbl = &radeon_drm_buffer_vtbl; + buf->mgr = mgr; + + make_empty_list(buf); + domain = radeon_domain_from_usage(desc->usage); + buf->bo = radeon_bo_open(rws->bom, 0, size, + desc->alignment, domain, 0); + if (buf->bo == NULL) + goto error2; + + return &buf->base; + + error2: + FREE(buf); + error1: + return NULL; +} + +static void +radeon_drm_bufmgr_flush(struct pb_manager *mgr) +{ + /* NOP */ +} + +static void +radeon_drm_bufmgr_destroy(struct pb_manager *_mgr) +{ + struct radeon_drm_bufmgr *mgr = radeon_drm_bufmgr(_mgr); + FREE(mgr); +} + +struct pb_manager * +radeon_drm_bufmgr_create(struct radeon_libdrm_winsys *rws) +{ + struct radeon_drm_bufmgr *mgr; + + mgr = CALLOC_STRUCT(radeon_drm_bufmgr); + if (!mgr) + return NULL; + + mgr->base.destroy = radeon_drm_bufmgr_destroy; + mgr->base.create_buffer = radeon_drm_bufmgr_create_buffer; + mgr->base.flush = radeon_drm_bufmgr_flush; + + mgr->rws = rws; + make_empty_list(&mgr->buffer_map_list); + return &mgr->base; +} + +static struct radeon_drm_buffer *get_drm_buffer(struct pb_buffer *_buf) +{ + struct radeon_drm_buffer *buf; + if (_buf->vtbl == &radeon_drm_buffer_vtbl) { + buf = radeon_drm_buffer(_buf); + } else { + struct pb_buffer *base_buf; + pb_size offset; + pb_get_base_buffer(_buf, &base_buf, &offset); + + buf = radeon_drm_buffer(base_buf); + } + return buf; +} + +boolean radeon_drm_bufmgr_get_handle(struct pb_buffer *_buf, + struct winsys_handle *whandle) +{ + int retval, fd; + struct drm_gem_flink flink; + struct radeon_drm_buffer *buf = get_drm_buffer(_buf); + if (whandle->type == DRM_API_HANDLE_TYPE_SHARED) { + if (!buf->flinked) { + fd = buf->mgr->rws->fd; + flink.handle = buf->bo->handle; + + retval = ioctl(fd, DRM_IOCTL_GEM_FLINK, &flink); + if (retval) { + return FALSE; + } + + buf->flinked = TRUE; + buf->flink = flink.name; + } + whandle->handle = buf->flink; + } else if (whandle->type == DRM_API_HANDLE_TYPE_KMS) { + whandle->handle = buf->bo->handle; + } + return TRUE; +} + + +void radeon_drm_bufmgr_set_tiling(struct pb_buffer *_buf, + enum r300_buffer_tiling microtiled, + enum r300_buffer_tiling macrotiled, + uint32_t pitch) +{ + struct radeon_drm_buffer *buf = get_drm_buffer(_buf); + uint32_t flags = 0, old_flags, old_pitch; + if (microtiled == R300_BUFFER_TILED) + flags |= RADEON_BO_FLAGS_MICRO_TILE; +/* XXX Remove this ifdef when libdrm version 2.4.19 becomes mandatory. */ +#ifdef RADEON_BO_FLAGS_MICRO_TILE_SQUARE + else if (microtiled == R300_BUFFER_SQUARETILED) + flags |= RADEON_BO_FLAGS_MICRO_TILE_SQUARE; +#endif + if (macrotiled == R300_BUFFER_TILED) + flags |= RADEON_BO_FLAGS_MACRO_TILE; + + radeon_bo_get_tiling(buf->bo, &old_flags, &old_pitch); + + if (flags != old_flags || pitch != old_pitch) { + /* Tiling determines how DRM treats the buffer data. + * We must flush CS when changing it if the buffer is referenced. */ + if (radeon_bo_is_referenced_by_cs(buf->bo, buf->mgr->rws->cs)) { + buf->mgr->rws->flush_cb(buf->mgr->rws->flush_data); + } + } + radeon_bo_set_tiling(buf->bo, flags, pitch); + +} + +boolean radeon_drm_bufmgr_add_buffer(struct pb_buffer *_buf, + uint32_t rd, uint32_t wd) +{ + struct radeon_drm_buffer *buf = get_drm_buffer(_buf); + radeon_cs_space_add_persistent_bo(buf->mgr->rws->cs, buf->bo, + rd, wd); + return TRUE; +} + +void radeon_drm_bufmgr_write_reloc(struct pb_buffer *_buf, + uint32_t rd, uint32_t wd, + uint32_t flags) +{ + struct radeon_drm_buffer *buf = get_drm_buffer(_buf); + int retval; + + retval = radeon_cs_write_reloc(buf->mgr->rws->cs, + buf->bo, rd, wd, flags); + if (retval) { + debug_printf("radeon: Relocation of %p (%d, %d, %d) failed!\n", + buf, rd, wd, flags); + } +} + +boolean radeon_drm_bufmgr_is_buffer_referenced(struct pb_buffer *_buf) +{ + struct radeon_drm_buffer *buf = get_drm_buffer(_buf); + uint32_t domain; + + return (radeon_bo_is_referenced_by_cs(buf->bo, buf->mgr->rws->cs) || + radeon_bo_is_busy(buf->bo, &domain)); +} + + +void radeon_drm_bufmgr_flush_maps(struct pb_manager *_mgr) +{ + struct radeon_drm_bufmgr *mgr = radeon_drm_bufmgr(_mgr); + struct radeon_drm_buffer *rpb, *t_rpb; + + foreach_s(rpb, t_rpb, &mgr->buffer_map_list) { + radeon_bo_unmap(rpb->bo); + rpb->bo->ptr = NULL; + remove_from_list(rpb); + } + + make_empty_list(&mgr->buffer_map_list); +} diff --git a/src/gallium/winsys/radeon/drm/radeon_r300.c b/src/gallium/winsys/radeon/drm/radeon_r300.c new file mode 100644 index 00000000000..38fcf889c8b --- /dev/null +++ b/src/gallium/winsys/radeon/drm/radeon_r300.c @@ -0,0 +1,348 @@ +/* + * Copyright 2008 Corbin Simpson + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * on the rights to use, copy, modify, merge, publish, distribute, sub + * license, and/or sell copies of the Software, and to permit persons to whom + * the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. */ + +#include "radeon_r300.h" +#include "radeon_buffer.h" + +#include "radeon_bo_gem.h" +#include "radeon_cs_gem.h" +#include "state_tracker/drm_api.h" + +static struct r300_winsys_buffer * +radeon_r300_winsys_buffer_create(struct r300_winsys_screen *rws, + unsigned alignment, + unsigned usage, + unsigned size) +{ + struct radeon_libdrm_winsys *ws = radeon_winsys_screen(rws); + struct pb_desc desc; + struct pb_manager *provider; + struct pb_buffer *buffer; + + memset(&desc, 0, sizeof(desc)); + desc.alignment = alignment; + desc.usage = usage; + + if (usage & PIPE_BUFFER_USAGE_CONSTANT) + provider = ws->mman; + else if ((usage & PIPE_BUFFER_USAGE_VERTEX) || + (usage & PIPE_BUFFER_USAGE_INDEX)) + provider = ws->cman; + else + provider = ws->kman; + buffer = provider->create_buffer(provider, size, &desc); + if (!buffer) + return NULL; + + return radeon_libdrm_winsys_buffer(buffer); +} + +static void radeon_r300_winsys_buffer_destroy(struct r300_winsys_buffer *buf) +{ + struct pb_buffer *_buf = radeon_pb_buffer(buf); + + pb_destroy(_buf); +} +static void radeon_r300_winsys_buffer_set_tiling(struct r300_winsys_screen *rws, + struct r300_winsys_buffer *buf, + uint32_t pitch, + enum r300_buffer_tiling microtiled, + enum r300_buffer_tiling macrotiled) +{ + struct pb_buffer *_buf = radeon_pb_buffer(buf); + radeon_drm_bufmgr_set_tiling(_buf, microtiled, macrotiled, pitch); +} + +static void *radeon_r300_winsys_buffer_map(struct r300_winsys_screen *ws, + struct r300_winsys_buffer *buf, + unsigned usage) +{ + struct pb_buffer *_buf = radeon_pb_buffer(buf); + + return pb_map(_buf, usage); +} + +static void radeon_r300_winsys_buffer_unmap(struct r300_winsys_screen *ws, + struct r300_winsys_buffer *buf) +{ + struct pb_buffer *_buf = radeon_pb_buffer(buf); + + pb_unmap(_buf); +} + +static void radeon_r300_winsys_buffer_reference(struct r300_winsys_screen *rws, + struct r300_winsys_buffer **pdst, + struct r300_winsys_buffer *src) +{ + struct pb_buffer *_src = radeon_pb_buffer(src); + struct pb_buffer *_dst = radeon_pb_buffer(*pdst); + + pb_reference(&_dst, _src); + + *pdst = radeon_libdrm_winsys_buffer(_dst); +} + +static boolean radeon_r300_winsys_is_buffer_referenced(struct r300_winsys_screen *rws, + struct r300_winsys_buffer *buf) +{ + struct pb_buffer *_buf = radeon_pb_buffer(buf); + + return radeon_drm_bufmgr_is_buffer_referenced(_buf); +} + +static struct r300_winsys_buffer *radeon_r300_winsys_buffer_from_handle(struct r300_winsys_screen *rws, + struct pipe_screen *screen, + struct winsys_handle *whandle, + unsigned *stride) +{ + struct radeon_libdrm_winsys *ws = radeon_winsys_screen(rws); + struct pb_buffer *_buf; + + _buf = radeon_drm_bufmgr_create_buffer_from_handle(ws->kman, whandle->handle); + *stride = whandle->stride; + return radeon_libdrm_winsys_buffer(_buf); +} + +static boolean radeon_r300_winsys_buffer_get_handle(struct r300_winsys_screen *rws, + struct r300_winsys_buffer *buffer, + unsigned stride, + struct winsys_handle *whandle) +{ + struct pb_buffer *_buf = radeon_pb_buffer(buffer); + boolean ret; + ret = radeon_drm_bufmgr_get_handle(_buf, whandle); + if (ret) + whandle->stride = stride; + return ret; +} + +static void radeon_set_flush_cb(struct r300_winsys_screen *rws, + void (*flush_cb)(void *), + void *data) +{ + struct radeon_libdrm_winsys *ws = radeon_winsys_screen(rws); + ws->flush_cb = flush_cb; + ws->flush_data = data; + radeon_cs_space_set_flush(ws->cs, flush_cb, data); +} + +static boolean radeon_add_buffer(struct r300_winsys_screen *rws, + struct r300_winsys_buffer *buf, + uint32_t rd, + uint32_t wd) +{ + struct pb_buffer *_buf = radeon_pb_buffer(buf); + + return radeon_drm_bufmgr_add_buffer(_buf, rd, wd); +} + +static boolean radeon_validate(struct r300_winsys_screen *rws) +{ + struct radeon_libdrm_winsys *ws = radeon_winsys_screen(rws); + if (radeon_cs_space_check(ws->cs) < 0) { + return FALSE; + } + + /* Things are fine, we can proceed as normal. */ + return TRUE; +} + +static boolean radeon_check_cs(struct r300_winsys_screen *rws, int size) +{ + struct radeon_libdrm_winsys *ws = radeon_winsys_screen(rws); + struct radeon_cs *cs = ws->cs; + + return radeon_validate(rws) && cs->cdw + size <= cs->ndw; +} + +static void radeon_begin_cs(struct r300_winsys_screen *rws, + int size, + const char* file, + const char* function, + int line) +{ + struct radeon_libdrm_winsys *ws = radeon_winsys_screen(rws); + radeon_cs_begin(ws->cs, size, file, function, line); +} + +static void radeon_write_cs_dword(struct r300_winsys_screen *rws, + uint32_t dword) +{ + struct radeon_libdrm_winsys *ws = radeon_winsys_screen(rws); + radeon_cs_write_dword(ws->cs, dword); +} + +static void radeon_write_cs_reloc(struct r300_winsys_screen *rws, + struct r300_winsys_buffer *buf, + uint32_t rd, + uint32_t wd, + uint32_t flags) +{ + struct pb_buffer *_buf = radeon_pb_buffer(buf); + radeon_drm_bufmgr_write_reloc(_buf, rd, wd, flags); +} + +static void radeon_reset_bos(struct r300_winsys_screen *rws) +{ + struct radeon_libdrm_winsys *ws = radeon_winsys_screen(rws); + radeon_cs_space_reset_bos(ws->cs); +} + +static void radeon_end_cs(struct r300_winsys_screen *rws, + const char* file, + const char* function, + int line) +{ + struct radeon_libdrm_winsys *ws = radeon_winsys_screen(rws); + radeon_cs_end(ws->cs, file, function, line); +} + +static void radeon_flush_cs(struct r300_winsys_screen *rws) +{ + struct radeon_libdrm_winsys *ws = radeon_winsys_screen(rws); + int retval; + + /* Don't flush a zero-sized CS. */ + if (!ws->cs->cdw) { + return; + } + + radeon_drm_bufmgr_flush_maps(ws->kman); + /* Emit the CS. */ + retval = radeon_cs_emit(ws->cs); + if (retval) { + debug_printf("radeon: Bad CS, dumping...\n"); + radeon_cs_print(ws->cs, stderr); + } + + /* Reset CS. + * Someday, when we care about performance, we should really find a way + * to rotate between two or three CS objects so that the GPU can be + * spinning through one CS while another one is being filled. */ + radeon_cs_erase(ws->cs); +} + +static uint32_t radeon_get_value(struct r300_winsys_screen *rws, + enum r300_value_id id) +{ + struct radeon_libdrm_winsys *ws = (struct radeon_libdrm_winsys *)rws; + + switch(id) { + case R300_VID_PCI_ID: + return ws->pci_id; + case R300_VID_GB_PIPES: + return ws->gb_pipes; + case R300_VID_Z_PIPES: + return ws->z_pipes; + case R300_VID_SQUARE_TILING_SUPPORT: + return ws->squaretiling; + } + return 0; +} + +static void +radeon_winsys_destroy(struct r300_winsys_screen *rws) +{ + struct radeon_libdrm_winsys *ws = (struct radeon_libdrm_winsys *)rws; + radeon_cs_destroy(ws->cs); + + ws->cman->destroy(ws->cman); + ws->kman->destroy(ws->kman); + ws->mman->destroy(ws->mman); + + radeon_bo_manager_gem_dtor(ws->bom); + radeon_cs_manager_gem_dtor(ws->csm); +} + +boolean +radeon_setup_winsys(int fd, struct radeon_libdrm_winsys* ws) +{ + + ws->csm = radeon_cs_manager_gem_ctor(fd); + if (!ws->csm) + goto fail; + ws->bom = radeon_bo_manager_gem_ctor(fd); + if (!ws->bom) + goto fail; + ws->kman = radeon_drm_bufmgr_create(ws); + if (!ws->kman) + goto fail; + + ws->cman = pb_cache_manager_create(ws->kman, 100000); + if (!ws->cman) + goto fail; + + ws->mman = pb_malloc_bufmgr_create(); + if (!ws->mman) + goto fail; + + /* Size limit on IBs is 64 kibibytes. */ + ws->cs = radeon_cs_create(ws->csm, 1024 * 64 / 4); + if (!ws->cs) + goto fail; + radeon_cs_set_limit(ws->cs, + RADEON_GEM_DOMAIN_GTT, ws->gart_size); + radeon_cs_set_limit(ws->cs, + RADEON_GEM_DOMAIN_VRAM, ws->vram_size); + + ws->base.add_buffer = radeon_add_buffer; + ws->base.validate = radeon_validate; + ws->base.destroy = radeon_winsys_destroy; + ws->base.check_cs = radeon_check_cs; + ws->base.begin_cs = radeon_begin_cs; + ws->base.write_cs_dword = radeon_write_cs_dword; + ws->base.write_cs_reloc = radeon_write_cs_reloc; + ws->base.end_cs = radeon_end_cs; + ws->base.flush_cs = radeon_flush_cs; + ws->base.reset_bos = radeon_reset_bos; + ws->base.set_flush_cb = radeon_set_flush_cb; + ws->base.get_value = radeon_get_value; + + ws->base.buffer_create = radeon_r300_winsys_buffer_create; + ws->base.buffer_destroy = radeon_r300_winsys_buffer_destroy; + ws->base.buffer_set_tiling = radeon_r300_winsys_buffer_set_tiling; + ws->base.buffer_map = radeon_r300_winsys_buffer_map; + ws->base.buffer_unmap = radeon_r300_winsys_buffer_unmap; + ws->base.buffer_reference = radeon_r300_winsys_buffer_reference; + ws->base.buffer_from_handle = radeon_r300_winsys_buffer_from_handle; + ws->base.buffer_get_handle = radeon_r300_winsys_buffer_get_handle; + ws->base.is_buffer_referenced = radeon_r300_winsys_is_buffer_referenced; + return TRUE; + +fail: + if (ws->csm) + radeon_cs_manager_gem_dtor(ws->csm); + + if (ws->bom) + radeon_bo_manager_gem_dtor(ws->bom); + + if (ws->cman) + ws->cman->destroy(ws->cman); + if (ws->kman) + ws->kman->destroy(ws->kman); + if (ws->mman) + ws->mman->destroy(ws->mman); + + if (ws->cs) + radeon_cs_destroy(ws->cs); + return FALSE; +} diff --git a/src/gallium/winsys/radeon/drm/radeon_r300.h b/src/gallium/winsys/radeon/drm/radeon_r300.h new file mode 100644 index 00000000000..2703464ad8f --- /dev/null +++ b/src/gallium/winsys/radeon/drm/radeon_r300.h @@ -0,0 +1,30 @@ +/* + * Copyright 2008 Corbin Simpson + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * on the rights to use, copy, modify, merge, publish, distribute, sub + * license, and/or sell copies of the Software, and to permit persons to whom + * the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. */ + +#ifndef RADEON_R300_H +#define RADEON_R300_H + +#include "radeon_winsys.h" + +boolean radeon_setup_winsys(int fd, struct radeon_libdrm_winsys* winsys); + +#endif /* RADEON_R300_H */ diff --git a/src/gallium/winsys/radeon/drm/radeon_winsys.h b/src/gallium/winsys/radeon/drm/radeon_winsys.h new file mode 100644 index 00000000000..4260dbaad72 --- /dev/null +++ b/src/gallium/winsys/radeon/drm/radeon_winsys.h @@ -0,0 +1,86 @@ +/* + * Copyright © 2009 Corbin Simpson + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS, AUTHORS + * AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + */ +/* + * Authors: + * Corbin Simpson + */ +#ifndef RADEON_WINSYS_H +#define RADEON_WINSYS_H + +#include "r300_winsys.h" + +struct radeon_libdrm_winsys { + /* Parent class. */ + struct r300_winsys_screen base; + + struct pb_manager *kman; + + struct pb_manager *cman; + + struct pb_manager *mman; + + /* PCI ID */ + uint32_t pci_id; + + /* GB pipe count */ + uint32_t gb_pipes; + + /* Z pipe count (rv530 only) */ + uint32_t z_pipes; + + /* GART size. */ + uint32_t gart_size; + + /* VRAM size. */ + uint32_t vram_size; + + /* Square tiling support. */ + boolean squaretiling; + + /* DRM FD */ + int fd; + + /* Radeon BO manager. */ + struct radeon_bo_manager *bom; + + /* Radeon CS manager. */ + struct radeon_cs_manager *csm; + + /* Current CS. */ + struct radeon_cs *cs; + + /* Flush CB */ + void (*flush_cb)(void *); + void *flush_data; +}; + +static INLINE struct radeon_libdrm_winsys * +radeon_winsys_screen(struct r300_winsys_screen *base) +{ + return (struct radeon_libdrm_winsys *)base; +} + +#endif diff --git a/src/gallium/winsys/svga/drm/Makefile b/src/gallium/winsys/svga/drm/Makefile new file mode 100644 index 00000000000..c2f59e01b0d --- /dev/null +++ b/src/gallium/winsys/svga/drm/Makefile @@ -0,0 +1,27 @@ +TOP = ../../../../.. +include $(TOP)/configs/current + +LIBNAME = svgadrm + +C_SOURCES = \ + vmw_buffer.c \ + vmw_context.c \ + vmw_fence.c \ + vmw_screen.c \ + vmw_screen_dri.c \ + vmw_screen_ioctl.c \ + vmw_screen_pools.c \ + vmw_screen_svga.c \ + vmw_surface.c + +LIBRARY_INCLUDES = \ + -I$(TOP)/src/gallium/drivers/svga \ + -I$(TOP)/src/gallium/drivers/svga/include \ + $(shell pkg-config libdrm --cflags-only-I) + +LIBRARY_DEFINES = \ + -std=gnu99 -fvisibility=hidden \ + -DHAVE_STDINT_H -D_FILE_OFFSET_BITS=64 \ + $(shell pkg-config libdrm --cflags-only-other) + +include ../../../Makefile.template diff --git a/src/gallium/winsys/svga/drm/SConscript b/src/gallium/winsys/svga/drm/SConscript new file mode 100644 index 00000000000..edaf9458bee --- /dev/null +++ b/src/gallium/winsys/svga/drm/SConscript @@ -0,0 +1,39 @@ +Import('*') + +env = env.Clone() + +if env['gcc']: + env.Append(CCFLAGS = ['-fvisibility=hidden']) + env.Append(CPPDEFINES = [ + 'HAVE_STDINT_H', + 'HAVE_SYS_TYPES_H', + '-D_FILE_OFFSET_BITS=64', + ]) + +env.Prepend(CPPPATH = [ + 'include', + '#/src/gallium/drivers/svga', + '#/src/gallium/drivers/svga/include', +]) + +env.Append(CPPDEFINES = [ +]) + +sources = [ + 'vmw_buffer.c', + 'vmw_context.c', + 'vmw_fence.c', + 'vmw_screen.c', + 'vmw_screen_dri.c', + 'vmw_screen_ioctl.c', + 'vmw_screen_pools.c', + 'vmw_screen_svga.c', + 'vmw_surface.c', +] + +svgadrm = env.ConvenienceLibrary( + target = 'svgadrm', + source = sources, +) + +Export('svgadrm') diff --git a/src/gallium/winsys/svga/drm/vmw_buffer.c b/src/gallium/winsys/svga/drm/vmw_buffer.c new file mode 100644 index 00000000000..eca174a6c56 --- /dev/null +++ b/src/gallium/winsys/svga/drm/vmw_buffer.c @@ -0,0 +1,274 @@ +/********************************************************** + * Copyright 2009 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + **********************************************************/ + +/** + * @file + * SVGA buffer manager for Guest Memory Regions (GMRs). + * + * GMRs are used for pixel and vertex data upload/download to/from the virtual + * SVGA hardware. There is a limited number of GMRs available, and + * creating/destroying them is also a slow operation so we must suballocate + * them. + * + * This file implements a pipebuffer library's buffer manager, so that we can + * use pipepbuffer's suballocation, fencing, and debugging facilities with GMRs. + * + * @author Jose Fonseca + */ + + +#include "svga_cmd.h" + +#include "util/u_inlines.h" +#include "util/u_memory.h" +#include "pipebuffer/pb_buffer.h" +#include "pipebuffer/pb_bufmgr.h" + +#include "svga_winsys.h" + +#include "vmw_screen.h" +#include "vmw_buffer.h" + + +struct vmw_gmr_bufmgr; + + +struct vmw_gmr_buffer +{ + struct pb_buffer base; + + struct vmw_gmr_bufmgr *mgr; + + struct vmw_region *region; + void *map; + +#ifdef DEBUG + struct pipe_fence_handle *last_fence; +#endif +}; + + +extern const struct pb_vtbl vmw_gmr_buffer_vtbl; + + +static INLINE struct vmw_gmr_buffer * +vmw_gmr_buffer(struct pb_buffer *buf) +{ + assert(buf); + assert(buf->vtbl == &vmw_gmr_buffer_vtbl); + return (struct vmw_gmr_buffer *)buf; +} + + +struct vmw_gmr_bufmgr +{ + struct pb_manager base; + + struct vmw_winsys_screen *vws; +}; + + +static INLINE struct vmw_gmr_bufmgr * +vmw_gmr_bufmgr(struct pb_manager *mgr) +{ + assert(mgr); + return (struct vmw_gmr_bufmgr *)mgr; +} + + +static void +vmw_gmr_buffer_destroy(struct pb_buffer *_buf) +{ + struct vmw_gmr_buffer *buf = vmw_gmr_buffer(_buf); + +#ifdef DEBUG + if(buf->last_fence) { + struct svga_winsys_screen *sws = &buf->mgr->vws->base; + assert(sws->fence_signalled(sws, buf->last_fence, 0) == 0); + } +#endif + + vmw_ioctl_region_unmap(buf->region); + + vmw_ioctl_region_destroy(buf->region); + + FREE(buf); +} + + +static void * +vmw_gmr_buffer_map(struct pb_buffer *_buf, + unsigned flags) +{ + struct vmw_gmr_buffer *buf = vmw_gmr_buffer(_buf); + return buf->map; +} + + +static void +vmw_gmr_buffer_unmap(struct pb_buffer *_buf) +{ + /* Do nothing */ + (void)_buf; +} + + +static void +vmw_gmr_buffer_get_base_buffer(struct pb_buffer *buf, + struct pb_buffer **base_buf, + unsigned *offset) +{ + *base_buf = buf; + *offset = 0; +} + + +static enum pipe_error +vmw_gmr_buffer_validate( struct pb_buffer *_buf, + struct pb_validate *vl, + unsigned flags ) +{ + /* Always pinned */ + return PIPE_OK; +} + + +static void +vmw_gmr_buffer_fence( struct pb_buffer *_buf, + struct pipe_fence_handle *fence ) +{ + /* We don't need to do anything, as the pipebuffer library + * will take care of delaying the destruction of fenced buffers */ +#ifdef DEBUG + struct vmw_gmr_buffer *buf = vmw_gmr_buffer(_buf); + if(fence) + buf->last_fence = fence; +#endif +} + + +const struct pb_vtbl vmw_gmr_buffer_vtbl = { + vmw_gmr_buffer_destroy, + vmw_gmr_buffer_map, + vmw_gmr_buffer_unmap, + vmw_gmr_buffer_validate, + vmw_gmr_buffer_fence, + vmw_gmr_buffer_get_base_buffer +}; + + +static struct pb_buffer * +vmw_gmr_bufmgr_create_buffer(struct pb_manager *_mgr, + pb_size size, + const struct pb_desc *desc) +{ + struct vmw_gmr_bufmgr *mgr = vmw_gmr_bufmgr(_mgr); + struct vmw_winsys_screen *vws = mgr->vws; + struct vmw_gmr_buffer *buf; + + buf = CALLOC_STRUCT(vmw_gmr_buffer); + if(!buf) + goto error1; + + pipe_reference_init(&buf->base.base.reference, 1); + buf->base.base.alignment = desc->alignment; + buf->base.base.usage = desc->usage; + buf->base.base.size = size; + buf->base.vtbl = &vmw_gmr_buffer_vtbl; + buf->mgr = mgr; + + buf->region = vmw_ioctl_region_create(vws, size); + if(!buf->region) + goto error2; + + buf->map = vmw_ioctl_region_map(buf->region); + if(!buf->map) + goto error3; + + return &buf->base; + +error3: + vmw_ioctl_region_destroy(buf->region); +error2: + FREE(buf); +error1: + return NULL; +} + + +static void +vmw_gmr_bufmgr_flush(struct pb_manager *mgr) +{ + /* No-op */ +} + + +static void +vmw_gmr_bufmgr_destroy(struct pb_manager *_mgr) +{ + struct vmw_gmr_bufmgr *mgr = vmw_gmr_bufmgr(_mgr); + FREE(mgr); +} + + +struct pb_manager * +vmw_gmr_bufmgr_create(struct vmw_winsys_screen *vws) +{ + struct vmw_gmr_bufmgr *mgr; + + mgr = CALLOC_STRUCT(vmw_gmr_bufmgr); + if(!mgr) + return NULL; + + mgr->base.destroy = vmw_gmr_bufmgr_destroy; + mgr->base.create_buffer = vmw_gmr_bufmgr_create_buffer; + mgr->base.flush = vmw_gmr_bufmgr_flush; + + mgr->vws = vws; + + return &mgr->base; +} + + +boolean +vmw_gmr_bufmgr_region_ptr(struct pb_buffer *buf, + struct SVGAGuestPtr *ptr) +{ + struct pb_buffer *base_buf; + unsigned offset = 0; + struct vmw_gmr_buffer *gmr_buf; + + pb_get_base_buffer( buf, &base_buf, &offset ); + + gmr_buf = vmw_gmr_buffer(base_buf); + if(!gmr_buf) + return FALSE; + + *ptr = vmw_ioctl_region_ptr(gmr_buf->region); + + ptr->offset += offset; + + return TRUE; +} diff --git a/src/gallium/winsys/svga/drm/vmw_buffer.h b/src/gallium/winsys/svga/drm/vmw_buffer.h new file mode 100644 index 00000000000..41fb4476da5 --- /dev/null +++ b/src/gallium/winsys/svga/drm/vmw_buffer.h @@ -0,0 +1,65 @@ +/********************************************************** + * Copyright 2009 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + **********************************************************/ + + +#ifndef VMW_BUFFER_H_ +#define VMW_BUFFER_H_ + +#include +#include "pipe/p_compiler.h" + +struct SVGAGuestPtr; +struct pb_buffer; +struct pb_manager; +struct svga_winsys_buffer; +struct svga_winsys_surface; +struct vmw_winsys_screen; + + +static INLINE struct pb_buffer * +vmw_pb_buffer(struct svga_winsys_buffer *buffer) +{ + assert(buffer); + return (struct pb_buffer *)buffer; +} + + +static INLINE struct svga_winsys_buffer * +vmw_svga_winsys_buffer(struct pb_buffer *buffer) +{ + assert(buffer); + return (struct svga_winsys_buffer *)buffer; +} + + +struct pb_manager * +vmw_gmr_bufmgr_create(struct vmw_winsys_screen *vws); + +boolean +vmw_gmr_bufmgr_region_ptr(struct pb_buffer *buf, + struct SVGAGuestPtr *ptr); + + +#endif /* VMW_BUFFER_H_ */ diff --git a/src/gallium/winsys/svga/drm/vmw_context.c b/src/gallium/winsys/svga/drm/vmw_context.c new file mode 100644 index 00000000000..90ffc4868f7 --- /dev/null +++ b/src/gallium/winsys/svga/drm/vmw_context.c @@ -0,0 +1,382 @@ +/********************************************************** + * Copyright 2009 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + **********************************************************/ + + +#include "svga_cmd.h" + +#include "util/u_debug.h" +#include "util/u_memory.h" +#include "util/u_debug_stack.h" +#include "pipebuffer/pb_buffer.h" +#include "pipebuffer/pb_validate.h" + +#include "svga_winsys.h" +#include "vmw_context.h" +#include "vmw_screen.h" +#include "vmw_buffer.h" +#include "vmw_surface.h" +#include "vmw_fence.h" + +#define VMW_COMMAND_SIZE (64*1024) +#define VMW_SURFACE_RELOCS (1024) +#define VMW_REGION_RELOCS (512) + +#define VMW_MUST_FLUSH_STACK 8 + +struct vmw_region_relocation +{ + struct SVGAGuestPtr *where; + struct pb_buffer *buffer; + /* TODO: put offset info inside where */ + uint32 offset; +}; + +struct vmw_svga_winsys_context +{ + struct svga_winsys_context base; + + struct vmw_winsys_screen *vws; + +#ifdef DEBUG + boolean must_flush; + struct debug_stack_frame must_flush_stack[VMW_MUST_FLUSH_STACK]; +#endif + + struct { + uint8_t buffer[VMW_COMMAND_SIZE]; + uint32_t size; + uint32_t used; + uint32_t reserved; + } command; + + struct { + struct vmw_svga_winsys_surface *handles[VMW_SURFACE_RELOCS]; + uint32_t size; + uint32_t used; + uint32_t staged; + uint32_t reserved; + } surface; + + struct { + struct vmw_region_relocation relocs[VMW_REGION_RELOCS]; + uint32_t size; + uint32_t used; + uint32_t staged; + uint32_t reserved; + } region; + + struct pb_validate *validate; + + uint32_t last_fence; + + /** + * The amount of GMR that is referred by the commands currently batched + * in the context. + */ + uint32_t seen_regions; + + /** + * Whether this context should fail to reserve more commands, not because it + * ran out of command space, but because a substantial ammount of GMR was + * referred. + */ + boolean preemptive_flush; +}; + + +static INLINE struct vmw_svga_winsys_context * +vmw_svga_winsys_context(struct svga_winsys_context *swc) +{ + assert(swc); + return (struct vmw_svga_winsys_context *)swc; +} + + +static enum pipe_error +vmw_swc_flush(struct svga_winsys_context *swc, + struct pipe_fence_handle **pfence) +{ + struct vmw_svga_winsys_context *vswc = vmw_svga_winsys_context(swc); + struct pipe_fence_handle *fence = NULL; + unsigned i; + enum pipe_error ret; + + ret = pb_validate_validate(vswc->validate); + assert(ret == PIPE_OK); + if(ret == PIPE_OK) { + + /* Apply relocations */ + for(i = 0; i < vswc->region.used; ++i) { + struct vmw_region_relocation *reloc = &vswc->region.relocs[i]; + struct SVGAGuestPtr ptr; + + if(!vmw_gmr_bufmgr_region_ptr(reloc->buffer, &ptr)) + assert(0); + + ptr.offset += reloc->offset; + + *reloc->where = ptr; + } + + if (vswc->command.used) + vmw_ioctl_command(vswc->vws, + vswc->command.buffer, + vswc->command.used, + &vswc->last_fence); + + fence = vmw_pipe_fence(vswc->last_fence); + + pb_validate_fence(vswc->validate, fence); + } + + vswc->command.used = 0; + vswc->command.reserved = 0; + + for(i = 0; i < vswc->surface.used + vswc->surface.staged; ++i) { + struct vmw_svga_winsys_surface *vsurf = + vswc->surface.handles[i]; + p_atomic_dec(&vsurf->validated); + vmw_svga_winsys_surface_reference(&vswc->surface.handles[i], NULL); + } + + vswc->surface.used = 0; + vswc->surface.reserved = 0; + + for(i = 0; i < vswc->region.used + vswc->region.staged; ++i) { + pb_reference(&vswc->region.relocs[i].buffer, NULL); + } + + vswc->region.used = 0; + vswc->region.reserved = 0; + +#ifdef DEBUG + vswc->must_flush = FALSE; +#endif + vswc->preemptive_flush = FALSE; + vswc->seen_regions = 0; + + if(pfence) + *pfence = fence; + + return ret; +} + + +static void * +vmw_swc_reserve(struct svga_winsys_context *swc, + uint32_t nr_bytes, uint32_t nr_relocs ) +{ + struct vmw_svga_winsys_context *vswc = vmw_svga_winsys_context(swc); + +#ifdef DEBUG + /* Check if somebody forgot to check the previous failure */ + if(vswc->must_flush) { + debug_printf("Forgot to flush:\n"); + debug_backtrace_dump(vswc->must_flush_stack, VMW_MUST_FLUSH_STACK); + assert(!vswc->must_flush); + } +#endif + + assert(nr_bytes <= vswc->command.size); + if(nr_bytes > vswc->command.size) + return NULL; + + if(vswc->preemptive_flush || + vswc->command.used + nr_bytes > vswc->command.size || + vswc->surface.used + nr_relocs > vswc->surface.size || + vswc->region.used + nr_relocs > vswc->region.size) { +#ifdef DEBUG + vswc->must_flush = TRUE; + debug_backtrace_capture(vswc->must_flush_stack, 1, + VMW_MUST_FLUSH_STACK); +#endif + return NULL; + } + + assert(vswc->command.used + nr_bytes <= vswc->command.size); + assert(vswc->surface.used + nr_relocs <= vswc->surface.size); + assert(vswc->region.used + nr_relocs <= vswc->region.size); + + vswc->command.reserved = nr_bytes; + vswc->surface.reserved = nr_relocs; + vswc->surface.staged = 0; + vswc->region.reserved = nr_relocs; + vswc->region.staged = 0; + + return vswc->command.buffer + vswc->command.used; +} + + +static void +vmw_swc_surface_relocation(struct svga_winsys_context *swc, + uint32 *where, + struct svga_winsys_surface *surface, + unsigned flags) +{ + struct vmw_svga_winsys_context *vswc = vmw_svga_winsys_context(swc); + struct vmw_svga_winsys_surface *vsurf; + + if(!surface) { + *where = SVGA3D_INVALID_ID; + return; + } + + assert(vswc->surface.staged < vswc->surface.reserved); + + vsurf = vmw_svga_winsys_surface(surface); + + *where = vsurf->sid; + + vmw_svga_winsys_surface_reference(&vswc->surface.handles[vswc->surface.used + vswc->surface.staged], vsurf); + p_atomic_inc(&vsurf->validated); + ++vswc->surface.staged; +} + + +static void +vmw_swc_region_relocation(struct svga_winsys_context *swc, + struct SVGAGuestPtr *where, + struct svga_winsys_buffer *buffer, + uint32 offset, + unsigned flags) +{ + struct vmw_svga_winsys_context *vswc = vmw_svga_winsys_context(swc); + struct vmw_region_relocation *reloc; + enum pipe_error ret; + + assert(vswc->region.staged < vswc->region.reserved); + + reloc = &vswc->region.relocs[vswc->region.used + vswc->region.staged]; + reloc->where = where; + pb_reference(&reloc->buffer, vmw_pb_buffer(buffer)); + reloc->offset = offset; + + ++vswc->region.staged; + + ret = pb_validate_add_buffer(vswc->validate, reloc->buffer, flags); + /* TODO: Update pipebuffer to reserve buffers and not fail here */ + assert(ret == PIPE_OK); + + /* + * Flush preemptively the FIFO commands to keep the GMR working set within + * the GMR pool size. + * + * This is necessary for applications like SPECviewperf that generate huge + * amounts of immediate vertex data, so that we don't pile up too much of + * that vertex data neither in the guest nor in the host. + * + * Note that in the current implementation if a region is referred twice in + * a command stream, it will be accounted twice. We could detect repeated + * regions and count only once, but there is no incentive to do that, since + * regions are typically short-lived; always referred in a single command; + * and at the worst we just flush the commands a bit sooner, which for the + * SVGA virtual device it's not a performance issue since flushing commands + * to the FIFO won't cause flushing in the host. + */ + vswc->seen_regions += reloc->buffer->base.size; + if(vswc->seen_regions >= VMW_GMR_POOL_SIZE/2) + vswc->preemptive_flush = TRUE; +} + + +static void +vmw_swc_commit(struct svga_winsys_context *swc) +{ + struct vmw_svga_winsys_context *vswc = vmw_svga_winsys_context(swc); + + assert(vswc->command.reserved); + assert(vswc->command.used + vswc->command.reserved <= vswc->command.size); + vswc->command.used += vswc->command.reserved; + vswc->command.reserved = 0; + + assert(vswc->surface.staged <= vswc->surface.reserved); + assert(vswc->surface.used + vswc->surface.staged <= vswc->surface.size); + vswc->surface.used += vswc->surface.staged; + vswc->surface.staged = 0; + vswc->surface.reserved = 0; + + assert(vswc->region.staged <= vswc->region.reserved); + assert(vswc->region.used + vswc->region.staged <= vswc->region.size); + vswc->region.used += vswc->region.staged; + vswc->region.staged = 0; + vswc->region.reserved = 0; +} + + +static void +vmw_swc_destroy(struct svga_winsys_context *swc) +{ + struct vmw_svga_winsys_context *vswc = vmw_svga_winsys_context(swc); + unsigned i; + + for(i = 0; i < vswc->region.used; ++i) { + pb_reference(&vswc->region.relocs[i].buffer, NULL); + } + + for(i = 0; i < vswc->surface.used; ++i) { + p_atomic_dec(&vswc->surface.handles[i]->validated); + vmw_svga_winsys_surface_reference(&vswc->surface.handles[i], NULL); + } + pb_validate_destroy(vswc->validate); + vmw_ioctl_context_destroy(vswc->vws, swc->cid); + FREE(vswc); +} + + +struct svga_winsys_context * +vmw_svga_winsys_context_create(struct svga_winsys_screen *sws) +{ + struct vmw_winsys_screen *vws = vmw_winsys_screen(sws); + struct vmw_svga_winsys_context *vswc; + + vswc = CALLOC_STRUCT(vmw_svga_winsys_context); + if(!vswc) + return NULL; + + vswc->base.destroy = vmw_swc_destroy; + vswc->base.reserve = vmw_swc_reserve; + vswc->base.surface_relocation = vmw_swc_surface_relocation; + vswc->base.region_relocation = vmw_swc_region_relocation; + vswc->base.commit = vmw_swc_commit; + vswc->base.flush = vmw_swc_flush; + + vswc->base.cid = vmw_ioctl_context_create(vws); + + vswc->vws = vws; + + vswc->command.size = VMW_COMMAND_SIZE; + vswc->surface.size = VMW_SURFACE_RELOCS; + vswc->region.size = VMW_REGION_RELOCS; + + vswc->validate = pb_validate_create(); + if(!vswc->validate) { + FREE(vswc); + return NULL; + } + + return &vswc->base; +} + + diff --git a/src/gallium/winsys/svga/drm/vmw_context.h b/src/gallium/winsys/svga/drm/vmw_context.h new file mode 100644 index 00000000000..d4884d24e99 --- /dev/null +++ b/src/gallium/winsys/svga/drm/vmw_context.h @@ -0,0 +1,56 @@ +/********************************************************** + * Copyright 2009 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + **********************************************************/ + +/** + * @author Jose Fonseca + */ + + +#ifndef VMW_CONTEXT_H_ +#define VMW_CONTEXT_H_ + +#include "pipe/p_compiler.h" + +struct svga_winsys_screen; +struct svga_winsys_context; +struct pipe_context; +struct pipe_screen; + +#define VMW_DEBUG 0 + +#if VMW_DEBUG +#define vmw_printf debug_printf +#define VMW_FUNC debug_printf("%s\n", __FUNCTION__) +#else +#define VMW_FUNC +#define vmw_printf(...) +#endif + + +struct svga_winsys_context * +vmw_svga_winsys_context_create(struct svga_winsys_screen *sws); + + +#endif /* VMW_CONTEXT_H_ */ diff --git a/src/gallium/winsys/svga/drm/vmw_fence.c b/src/gallium/winsys/svga/drm/vmw_fence.c new file mode 100644 index 00000000000..873dd51166c --- /dev/null +++ b/src/gallium/winsys/svga/drm/vmw_fence.c @@ -0,0 +1,108 @@ +/********************************************************** + * Copyright 2009 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + **********************************************************/ + + +#include "util/u_memory.h" +#include "pipebuffer/pb_buffer_fenced.h" + +#include "vmw_screen.h" +#include "vmw_fence.h" + + + +struct vmw_fence_ops +{ + struct pb_fence_ops base; + + struct vmw_winsys_screen *vws; +}; + + +static INLINE struct vmw_fence_ops * +vmw_fence_ops(struct pb_fence_ops *ops) +{ + assert(ops); + return (struct vmw_fence_ops *)ops; +} + + +static void +vmw_fence_ops_fence_reference(struct pb_fence_ops *ops, + struct pipe_fence_handle **ptr, + struct pipe_fence_handle *fence) +{ + *ptr = fence; +} + + +static int +vmw_fence_ops_fence_signalled(struct pb_fence_ops *ops, + struct pipe_fence_handle *fence, + unsigned flag) +{ + struct vmw_winsys_screen *vws = vmw_fence_ops(ops)->vws; + (void)flag; + return vmw_ioctl_fence_signalled(vws, vmw_fence(fence)); +} + + +static int +vmw_fence_ops_fence_finish(struct pb_fence_ops *ops, + struct pipe_fence_handle *fence, + unsigned flag) +{ + struct vmw_winsys_screen *vws = vmw_fence_ops(ops)->vws; + (void)flag; + return vmw_ioctl_fence_finish(vws, vmw_fence(fence)); +} + + +static void +vmw_fence_ops_destroy(struct pb_fence_ops *ops) +{ + FREE(ops); +} + + +struct pb_fence_ops * +vmw_fence_ops_create(struct vmw_winsys_screen *vws) +{ + struct vmw_fence_ops *ops; + + ops = CALLOC_STRUCT(vmw_fence_ops); + if(!ops) + return NULL; + + ops->base.destroy = &vmw_fence_ops_destroy; + ops->base.fence_reference = &vmw_fence_ops_fence_reference; + ops->base.fence_signalled = &vmw_fence_ops_fence_signalled; + ops->base.fence_finish = &vmw_fence_ops_fence_finish; + + ops->vws = vws; + + return &ops->base; +} + + diff --git a/src/gallium/winsys/svga/drm/vmw_fence.h b/src/gallium/winsys/svga/drm/vmw_fence.h new file mode 100644 index 00000000000..5357b4f61de --- /dev/null +++ b/src/gallium/winsys/svga/drm/vmw_fence.h @@ -0,0 +1,59 @@ +/********************************************************** + * Copyright 2009 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + **********************************************************/ + + +#ifndef VMW_FENCE_H_ +#define VMW_FENCE_H_ + + +#include "pipe/p_compiler.h" + + +struct pipe_fence_handle; +struct pb_fence_ops; +struct vmw_winsys_screen; + + +/** Cast from a pipe_fence_handle pointer into a SVGA fence */ +static INLINE uint32_t +vmw_fence( struct pipe_fence_handle *fence ) +{ + return (uint32_t)(uintptr_t)fence; +} + + +/** Cast from a SVGA fence number to pipe_fence_handle pointer */ +static INLINE struct pipe_fence_handle * +vmw_pipe_fence( uint32_t fence ) +{ + return (struct pipe_fence_handle *)(uintptr_t)fence; +} + + +struct pb_fence_ops * +vmw_fence_ops_create(struct vmw_winsys_screen *vws); + + +#endif /* VMW_FENCE_H_ */ diff --git a/src/gallium/winsys/svga/drm/vmw_screen.c b/src/gallium/winsys/svga/drm/vmw_screen.c new file mode 100644 index 00000000000..6cc9b382932 --- /dev/null +++ b/src/gallium/winsys/svga/drm/vmw_screen.c @@ -0,0 +1,77 @@ +/********************************************************** + * Copyright 2009 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + **********************************************************/ + + +#include "vmw_screen.h" + +#include "vmw_context.h" + +#include "util/u_memory.h" +#include "pipe/p_compiler.h" + + +/* Called from vmw_drm_create_screen(), creates and initializes the + * vmw_winsys_screen structure, which is the main entity in this + * module. + */ +struct vmw_winsys_screen * +vmw_winsys_create( int fd, boolean use_old_scanout_flag ) +{ + struct vmw_winsys_screen *vws = CALLOC_STRUCT(vmw_winsys_screen); + if (!vws) + goto out_no_vws; + + vws->ioctl.drm_fd = fd; + vws->use_old_scanout_flag = use_old_scanout_flag; + debug_printf("%s: use_old_scanout_flag == %s\n", __FUNCTION__, + use_old_scanout_flag ? "true" : "false"); + + if (!vmw_ioctl_init(vws)) + goto out_no_ioctl; + + if(!vmw_pools_init(vws)) + goto out_no_pools; + + if (!vmw_winsys_screen_init_svga(vws)) + goto out_no_svga; + + return vws; +out_no_svga: + vmw_pools_cleanup(vws); +out_no_pools: + vmw_ioctl_cleanup(vws); +out_no_ioctl: + FREE(vws); +out_no_vws: + return NULL; +} + +void +vmw_winsys_destroy(struct vmw_winsys_screen *vws) +{ + vmw_pools_cleanup(vws); + vmw_ioctl_cleanup(vws); + FREE(vws); +} diff --git a/src/gallium/winsys/svga/drm/vmw_screen.h b/src/gallium/winsys/svga/drm/vmw_screen.h new file mode 100644 index 00000000000..d3f2c2c7f56 --- /dev/null +++ b/src/gallium/winsys/svga/drm/vmw_screen.h @@ -0,0 +1,140 @@ +/********************************************************** + * Copyright 2009 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + **********************************************************/ + +/** + * @file + * Common definitions for the VMware SVGA winsys. + * + * @author Jose Fonseca + */ + + +#ifndef VMW_SCREEN_H_ +#define VMW_SCREEN_H_ + + +#include "pipe/p_compiler.h" +#include "pipe/p_state.h" + +#include "svga_winsys.h" + + +#define VMW_GMR_POOL_SIZE (16*1024*1024) + + +struct pb_manager; +struct vmw_region; + + +struct vmw_winsys_screen +{ + struct svga_winsys_screen base; + + boolean use_old_scanout_flag; + + struct { + volatile uint32_t *fifo_map; + uint64_t last_fence; + int drm_fd; + } ioctl; + + struct { + struct pb_manager *gmr; + struct pb_manager *gmr_mm; + struct pb_manager *gmr_fenced; + } pools; +}; + + +static INLINE struct vmw_winsys_screen * +vmw_winsys_screen(struct svga_winsys_screen *base) +{ + return (struct vmw_winsys_screen *)base; +} + +/* */ +uint32 +vmw_ioctl_context_create(struct vmw_winsys_screen *vws); + +void +vmw_ioctl_context_destroy(struct vmw_winsys_screen *vws, + uint32 cid); + +uint32 +vmw_ioctl_surface_create(struct vmw_winsys_screen *vws, + SVGA3dSurfaceFlags flags, + SVGA3dSurfaceFormat format, + SVGA3dSize size, + uint32 numFaces, + uint32 numMipLevels); + +void +vmw_ioctl_surface_destroy(struct vmw_winsys_screen *vws, + uint32 sid); + +void +vmw_ioctl_command(struct vmw_winsys_screen *vws, + void *commands, + uint32_t size, + uint32_t *fence); + +struct vmw_region * +vmw_ioctl_region_create(struct vmw_winsys_screen *vws, uint32_t size); + +void +vmw_ioctl_region_destroy(struct vmw_region *region); + +struct SVGAGuestPtr +vmw_ioctl_region_ptr(struct vmw_region *region); + +void * +vmw_ioctl_region_map(struct vmw_region *region); +void +vmw_ioctl_region_unmap(struct vmw_region *region); + + +int +vmw_ioctl_fence_finish(struct vmw_winsys_screen *vws, + uint32_t fence); + +int +vmw_ioctl_fence_signalled(struct vmw_winsys_screen *vws, + uint32_t fence); + + +/* Initialize parts of vmw_winsys_screen at startup: + */ +boolean vmw_ioctl_init(struct vmw_winsys_screen *vws); +boolean vmw_pools_init(struct vmw_winsys_screen *vws); +boolean vmw_winsys_screen_init_svga(struct vmw_winsys_screen *vws); + +void vmw_ioctl_cleanup(struct vmw_winsys_screen *vws); +void vmw_pools_cleanup(struct vmw_winsys_screen *vws); + +struct vmw_winsys_screen *vmw_winsys_create(int fd, boolean use_old_scanout_flag); +void vmw_winsys_destroy(struct vmw_winsys_screen *sws); + + +#endif /* VMW_SCREEN_H_ */ diff --git a/src/gallium/winsys/svga/drm/vmw_screen_dri.c b/src/gallium/winsys/svga/drm/vmw_screen_dri.c new file mode 100644 index 00000000000..657544dcb21 --- /dev/null +++ b/src/gallium/winsys/svga/drm/vmw_screen_dri.c @@ -0,0 +1,373 @@ +/********************************************************** + * Copyright 2009 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + **********************************************************/ + + +#include "pipe/p_compiler.h" +#include "util/u_inlines.h" +#include "util/u_memory.h" +#include "util/u_format.h" +#include "vmw_screen.h" + +#include "trace/tr_drm.h" + +#include "vmw_screen.h" +#include "vmw_surface.h" +#include "vmw_fence.h" +#include "vmw_context.h" + +#include +#include +#include +#include + +#include + +static struct svga_winsys_surface * +vmw_drm_surface_from_handle(struct svga_winsys_screen *sws, + struct winsys_handle *whandle, + SVGA3dSurfaceFormat *format); +static boolean +vmw_drm_surface_get_handle(struct svga_winsys_screen *sws, + struct svga_winsys_surface *surface, + unsigned stride, + struct winsys_handle *whandle); + +static struct dri1_api dri1_api_hooks; +static struct dri1_api_version ddx_required = { 0, 1, 0 }; +static struct dri1_api_version ddx_compat = { 0, 0, 0 }; +static struct dri1_api_version dri_required = { 4, 0, 0 }; +static struct dri1_api_version dri_compat = { 4, 0, 0 }; +static struct dri1_api_version drm_required = { 1, 0, 0 }; +static struct dri1_api_version drm_compat = { 1, 0, 0 }; +static struct dri1_api_version drm_scanout = { 0, 9, 0 }; + +static boolean +vmw_dri1_check_version(const struct dri1_api_version *cur, + const struct dri1_api_version *required, + const struct dri1_api_version *compat, + const char component[]) +{ + if (cur->major > required->major && cur->major <= compat->major) + return TRUE; + if (cur->major == required->major && cur->minor >= required->minor) + return TRUE; + + fprintf(stderr, "%s version failure.\n", component); + fprintf(stderr, "%s version is %d.%d.%d and this driver can only work\n" + "with versions %d.%d.x through %d.x.x.\n", + component, + cur->major, + cur->minor, + cur->patch_level, required->major, required->minor, compat->major); + return FALSE; +} + +/* This is actually the entrypoint to the entire driver, called by the + * libGL (or EGL, or ...) code via the drm_api_hooks table at the + * bottom of the file. + */ +static struct pipe_screen * +vmw_drm_create_screen(struct drm_api *drm_api, + int fd, + struct drm_create_screen_arg *arg) +{ + struct vmw_winsys_screen *vws; + struct pipe_screen *screen; + struct dri1_create_screen_arg *dri1; + boolean use_old_scanout_flag = FALSE; + + if (!arg || arg->mode == DRM_CREATE_NORMAL) { + struct dri1_api_version drm_ver; + drmVersionPtr ver; + + ver = drmGetVersion(fd); + if (ver == NULL) + return NULL; + + drm_ver.major = ver->version_major; + drm_ver.minor = ver->version_minor; + drm_ver.patch_level = 0; /* ??? */ + + drmFreeVersion(ver); + if (!vmw_dri1_check_version(&drm_ver, &drm_required, + &drm_compat, "vmwgfx drm driver")) + return NULL; + + if (!vmw_dri1_check_version(&drm_ver, &drm_scanout, + &drm_compat, "use old scanout field (not a error)")) + use_old_scanout_flag = TRUE; + } + + if (arg != NULL) { + switch (arg->mode) { + case DRM_CREATE_NORMAL: + break; + case DRM_CREATE_DRI1: + dri1 = (struct dri1_create_screen_arg *)arg; + if (!vmw_dri1_check_version(&dri1->ddx_version, &ddx_required, + &ddx_compat, "ddx - driver api")) + return NULL; + if (!vmw_dri1_check_version(&dri1->dri_version, &dri_required, + &dri_compat, "dri info")) + return NULL; + if (!vmw_dri1_check_version(&dri1->drm_version, &drm_required, + &drm_compat, "vmwgfx drm driver")) + return NULL; + if (!vmw_dri1_check_version(&dri1->drm_version, &drm_scanout, + &drm_compat, "use old scanout field (not a error)")) + use_old_scanout_flag = TRUE; + dri1->api = &dri1_api_hooks; +#if 0 + break; +#else + assert(!"No dri 1 support for now\n"); + return NULL; +#endif + default: + return NULL; + } + } + + vws = vmw_winsys_create( fd, use_old_scanout_flag ); + if (!vws) + goto out_no_vws; + + /* XXX do this properly */ + vws->base.surface_from_handle = vmw_drm_surface_from_handle; + vws->base.surface_get_handle = vmw_drm_surface_get_handle; + + screen = svga_screen_create( &vws->base ); + if (!screen) + goto out_no_screen; + + return screen; + + /* Failure cases: + */ +out_no_screen: + vmw_winsys_destroy( vws ); + +out_no_vws: + return NULL; +} + +static INLINE boolean +vmw_dri1_intersect_src_bbox(struct drm_clip_rect *dst, + int dst_x, + int dst_y, + const struct drm_clip_rect *src, + const struct drm_clip_rect *bbox) +{ + int xy1; + int xy2; + + xy1 = ((int)src->x1 > (int)bbox->x1 + dst_x) ? src->x1 : + (int)bbox->x1 + dst_x; + xy2 = ((int)src->x2 < (int)bbox->x2 + dst_x) ? src->x2 : + (int)bbox->x2 + dst_x; + if (xy1 >= xy2 || xy1 < 0) + return FALSE; + + dst->x1 = xy1; + dst->x2 = xy2; + + xy1 = ((int)src->y1 > (int)bbox->y1 + dst_y) ? src->y1 : + (int)bbox->y1 + dst_y; + xy2 = ((int)src->y2 < (int)bbox->y2 + dst_y) ? src->y2 : + (int)bbox->y2 + dst_y; + if (xy1 >= xy2 || xy1 < 0) + return FALSE; + + dst->y1 = xy1; + dst->y2 = xy2; + return TRUE; +} + +/** + * No fancy get-surface-from-sarea stuff here. + * Just use the present blit. + */ + +static void +vmw_dri1_present_locked(struct pipe_context *locked_pipe, + struct pipe_surface *surf, + const struct drm_clip_rect *rect, + unsigned int num_clip, + int x_draw, int y_draw, + const struct drm_clip_rect *bbox, + struct pipe_fence_handle **p_fence) +{ +#if 0 + struct svga_winsys_surface *srf = + svga_screen_texture_get_winsys_surface(surf->texture); + struct vmw_svga_winsys_surface *vsrf = vmw_svga_winsys_surface(srf); + struct vmw_winsys_screen *vws = + vmw_winsys_screen(svga_winsys_screen(locked_pipe->screen)); + struct drm_clip_rect clip; + int i; + struct + { + SVGA3dCmdHeader header; + SVGA3dCmdPresent body; + SVGA3dCopyRect rect; + } cmd; + boolean visible = FALSE; + uint32_t fence_seq = 0; + + VMW_FUNC; + cmd.header.id = SVGA_3D_CMD_PRESENT; + cmd.header.size = sizeof cmd.body + sizeof cmd.rect; + cmd.body.sid = vsrf->sid; + + for (i = 0; i < num_clip; ++i) { + if (!vmw_dri1_intersect_src_bbox(&clip, x_draw, y_draw, rect++, bbox)) + continue; + + cmd.rect.x = clip.x1; + cmd.rect.y = clip.y1; + cmd.rect.w = clip.x2 - clip.x1; + cmd.rect.h = clip.y2 - clip.y1; + cmd.rect.srcx = (int)clip.x1 - x_draw; + cmd.rect.srcy = (int)clip.y1 - y_draw; + + vmw_printf("%s: Clip %d x %d y %d w %d h %d srcx %d srcy %d\n", + __FUNCTION__, + i, + cmd.rect.x, + cmd.rect.y, + cmd.rect.w, cmd.rect.h, cmd.rect.srcx, cmd.rect.srcy); + + vmw_ioctl_command(vws, &cmd, sizeof cmd.header + cmd.header.size, + &fence_seq); + visible = TRUE; + } + + *p_fence = (visible) ? vmw_pipe_fence(fence_seq) : NULL; + vmw_svga_winsys_surface_reference(&vsrf, NULL); +#else + assert(!"No dri 1 support for now\n"); +#endif +} + +static struct svga_winsys_surface * +vmw_drm_surface_from_handle(struct svga_winsys_screen *sws, + struct winsys_handle *whandle, + SVGA3dSurfaceFormat *format) +{ + struct vmw_svga_winsys_surface *vsrf; + struct svga_winsys_surface *ssrf; + struct vmw_winsys_screen *vws = vmw_winsys_screen(sws); + union drm_vmw_surface_reference_arg arg; + struct drm_vmw_surface_arg *req = &arg.req; + struct drm_vmw_surface_create_req *rep = &arg.rep; + int ret; + int i; + + /** + * The vmware device specific handle is the hardware SID. + * FIXME: We probably want to move this to the ioctl implementations. + */ + + memset(&arg, 0, sizeof(arg)); + req->sid = whandle->handle; + + ret = drmCommandWriteRead(vws->ioctl.drm_fd, DRM_VMW_REF_SURFACE, + &arg, sizeof(arg)); + + if (ret) { + fprintf(stderr, "Failed referencing shared surface. SID %d.\n" + "Error %d (%s).\n", + whandle->handle, ret, strerror(-ret)); + return NULL; + } + + if (rep->mip_levels[0] != 1) { + fprintf(stderr, "Incorrect number of mipmap levels on shared surface." + " SID %d, levels %d\n", + whandle->handle, rep->mip_levels[0]); + goto out_mip; + } + + for (i=1; i < DRM_VMW_MAX_SURFACE_FACES; ++i) { + if (rep->mip_levels[i] != 0) { + fprintf(stderr, "Incorrect number of faces levels on shared surface." + " SID %d, face %d present.\n", + whandle->handle, i); + goto out_mip; + } + } + + vsrf = CALLOC_STRUCT(vmw_svga_winsys_surface); + if (!vsrf) + goto out_mip; + + pipe_reference_init(&vsrf->refcnt, 1); + p_atomic_set(&vsrf->validated, 0); + vsrf->screen = vws; + vsrf->sid = whandle->handle; + ssrf = svga_winsys_surface(vsrf); + *format = rep->format; + + return ssrf; + +out_mip: + vmw_ioctl_surface_destroy(vws, whandle->handle); + return NULL; +} + +static boolean +vmw_drm_surface_get_handle(struct svga_winsys_screen *sws, + struct svga_winsys_surface *surface, + unsigned stride, + struct winsys_handle *whandle) +{ + struct vmw_svga_winsys_surface *vsrf; + + if (!surface) + return FALSE; + + vsrf = vmw_svga_winsys_surface(surface); + whandle->handle = vsrf->sid; + whandle->stride = stride; + + return TRUE; +} + + +static struct dri1_api dri1_api_hooks = { + .front_srf_locked = NULL, + .present_locked = vmw_dri1_present_locked +}; + +static struct drm_api vmw_drm_api_hooks = { + .name = "vmwgfx", + .driver_name = "vmwgfx", + .create_screen = vmw_drm_create_screen, +}; + +struct drm_api* drm_api_create() +{ + return trace_drm_create(&vmw_drm_api_hooks); +} diff --git a/src/gallium/winsys/svga/drm/vmw_screen_ioctl.c b/src/gallium/winsys/svga/drm/vmw_screen_ioctl.c new file mode 100644 index 00000000000..5d81fa8c4a6 --- /dev/null +++ b/src/gallium/winsys/svga/drm/vmw_screen_ioctl.c @@ -0,0 +1,529 @@ +/********************************************************** + * Copyright 2009 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + **********************************************************/ + +/** + * @file + * + * Wrappers for DRM ioctl functionlaity used by the rest of the vmw + * drm winsys. + * + * Based on svgaicd_escape.c + */ + + +#include "svga_cmd.h" +#include "util/u_memory.h" +#include "util/u_math.h" +#include "svgadump/svga_dump.h" +#include "vmw_screen.h" +#include "vmw_context.h" +#include "xf86drm.h" +#include "vmwgfx_drm.h" + +#include +#include +#include + +struct vmw_region +{ + SVGAGuestPtr ptr; + uint32_t handle; + uint64_t map_handle; + void *data; + uint32_t map_count; + int drm_fd; + uint32_t size; +}; + +/* XXX: This isn't a real hardware flag, but just a hack for kernel to + * know about primary surfaces. In newer versions of the kernel + * interface the driver uses a special field. + */ +#define SVGA3D_SURFACE_HINT_SCANOUT (1 << 9) + +static void +vmw_check_last_cmd(struct vmw_winsys_screen *vws) +{ + static uint32_t buffer[16384]; + struct drm_vmw_fifo_debug_arg arg; + int ret; + + return; + memset(&arg, 0, sizeof(arg)); + arg.debug_buffer = (unsigned long)buffer; + arg.debug_buffer_size = 65536; + + ret = drmCommandWriteRead(vws->ioctl.drm_fd, DRM_VMW_FIFO_DEBUG, + &arg, sizeof(arg)); + + if (ret) { + debug_printf("%s Ioctl error: \"%s\".\n", __FUNCTION__, strerror(-ret)); + return; + } + + if (arg.did_not_fit) { + debug_printf("%s Command did not fit completely.\n", __FUNCTION__); + } + + svga_dump_commands(buffer, arg.used_size); +} + +static void +vmw_ioctl_fifo_unmap(struct vmw_winsys_screen *vws, void *mapping) +{ + VMW_FUNC; + (void)munmap(mapping, getpagesize()); +} + + +static void * +vmw_ioctl_fifo_map(struct vmw_winsys_screen *vws, + uint32_t fifo_offset ) +{ + void *map; + + VMW_FUNC; + + map = mmap(NULL, getpagesize(), PROT_READ, MAP_SHARED, + vws->ioctl.drm_fd, fifo_offset); + + if (map == MAP_FAILED) { + debug_printf("Map failed %s\n", strerror(errno)); + return NULL; + } + + vmw_printf("Fifo (min) is 0x%08x\n", ((uint32_t *) map)[SVGA_FIFO_MIN]); + + return map; +} + +uint32 +vmw_ioctl_context_create(struct vmw_winsys_screen *vws) +{ + struct drm_vmw_context_arg c_arg; + int ret; + + VMW_FUNC; + + ret = drmCommandRead(vws->ioctl.drm_fd, DRM_VMW_CREATE_CONTEXT, + &c_arg, sizeof(c_arg)); + + if (ret) + return -1; + + vmw_check_last_cmd(vws); + vmw_printf("Context id is %d\n", c_arg.cid); + + return c_arg.cid; +} + +void +vmw_ioctl_context_destroy(struct vmw_winsys_screen *vws, uint32 cid) +{ + struct drm_vmw_context_arg c_arg; + + VMW_FUNC; + + memset(&c_arg, 0, sizeof(c_arg)); + c_arg.cid = cid; + + (void)drmCommandWrite(vws->ioctl.drm_fd, DRM_VMW_UNREF_CONTEXT, + &c_arg, sizeof(c_arg)); + + vmw_check_last_cmd(vws); +} + +uint32 +vmw_ioctl_surface_create(struct vmw_winsys_screen *vws, + SVGA3dSurfaceFlags flags, + SVGA3dSurfaceFormat format, + SVGA3dSize size, + uint32_t numFaces, uint32_t numMipLevels) +{ + union drm_vmw_surface_create_arg s_arg; + struct drm_vmw_surface_create_req *req = &s_arg.req; + struct drm_vmw_surface_arg *rep = &s_arg.rep; + struct drm_vmw_size sizes[DRM_VMW_MAX_SURFACE_FACES* + DRM_VMW_MAX_MIP_LEVELS]; + struct drm_vmw_size *cur_size; + uint32_t iFace; + uint32_t iMipLevel; + int ret; + + vmw_printf("%s flags %d format %d\n", __FUNCTION__, flags, format); + + memset(&s_arg, 0, sizeof(s_arg)); + if (vws->use_old_scanout_flag && + (flags & SVGA3D_SURFACE_HINT_SCANOUT)) { + req->flags = (uint32_t) flags; + req->scanout = false; + } else if (flags & SVGA3D_SURFACE_HINT_SCANOUT) { + req->flags = (uint32_t) (flags & ~SVGA3D_SURFACE_HINT_SCANOUT); + req->scanout = true; + } else { + req->flags = (uint32_t) flags; + req->scanout = false; + } + req->format = (uint32_t) format; + req->shareable = 1; + + assert(numFaces * numMipLevels < DRM_VMW_MAX_SURFACE_FACES* + DRM_VMW_MAX_MIP_LEVELS); + cur_size = sizes; + for (iFace = 0; iFace < numFaces; ++iFace) { + SVGA3dSize mipSize = size; + + req->mip_levels[iFace] = numMipLevels; + for (iMipLevel = 0; iMipLevel < numMipLevels; ++iMipLevel) { + cur_size->width = mipSize.width; + cur_size->height = mipSize.height; + cur_size->depth = mipSize.depth; + mipSize.width = MAX2(mipSize.width >> 1, 1); + mipSize.height = MAX2(mipSize.height >> 1, 1); + mipSize.depth = MAX2(mipSize.depth >> 1, 1); + cur_size++; + } + } + for (iFace = numFaces; iFace < SVGA3D_MAX_SURFACE_FACES; ++iFace) { + req->mip_levels[iFace] = 0; + } + + req->size_addr = (unsigned long)&sizes; + + ret = drmCommandWriteRead(vws->ioctl.drm_fd, DRM_VMW_CREATE_SURFACE, + &s_arg, sizeof(s_arg)); + + if (ret) + return -1; + + vmw_printf("Surface id is %d\n", rep->sid); + vmw_check_last_cmd(vws); + + return rep->sid; +} + +void +vmw_ioctl_surface_destroy(struct vmw_winsys_screen *vws, uint32 sid) +{ + struct drm_vmw_surface_arg s_arg; + + VMW_FUNC; + + memset(&s_arg, 0, sizeof(s_arg)); + s_arg.sid = sid; + + (void)drmCommandWrite(vws->ioctl.drm_fd, DRM_VMW_UNREF_SURFACE, + &s_arg, sizeof(s_arg)); + vmw_check_last_cmd(vws); + +} + +void +vmw_ioctl_command(struct vmw_winsys_screen *vws, void *commands, uint32_t size, + uint32_t * pfence) +{ + struct drm_vmw_execbuf_arg arg; + struct drm_vmw_fence_rep rep; + int ret; + +#ifdef DEBUG + { + static boolean firsttime = TRUE; + static boolean debug = FALSE; + static boolean skip = FALSE; + if (firsttime) { + debug = debug_get_bool_option("SVGA_DUMP_CMD", FALSE); + skip = debug_get_bool_option("SVGA_SKIP_CMD", FALSE); + } + if (debug) { + VMW_FUNC; + svga_dump_commands(commands, size); + } + firsttime = FALSE; + if (skip) { + size = 0; + } + } +#endif + + memset(&arg, 0, sizeof(arg)); + memset(&rep, 0, sizeof(rep)); + + rep.error = -EFAULT; + arg.fence_rep = (unsigned long)&rep; + arg.commands = (unsigned long)commands; + arg.command_size = size; + + do { + ret = drmCommandWrite(vws->ioctl.drm_fd, DRM_VMW_EXECBUF, &arg, sizeof(arg)); + } while(ret == -ERESTART); + if (ret) { + debug_printf("%s error %s.\n", __FUNCTION__, strerror(-ret)); + } + if (rep.error) { + + /* + * Kernel has synced and put the last fence sequence in the FIFO + * register. + */ + + if (rep.error == -EFAULT) + rep.fence_seq = vws->ioctl.fifo_map[SVGA_FIFO_FENCE]; + + debug_printf("%s Fence error %s.\n", __FUNCTION__, + strerror(-rep.error)); + } + + vws->ioctl.last_fence = rep.fence_seq; + + if (pfence) + *pfence = rep.fence_seq; + vmw_check_last_cmd(vws); + +} + + +struct vmw_region * +vmw_ioctl_region_create(struct vmw_winsys_screen *vws, uint32_t size) +{ + struct vmw_region *region; + union drm_vmw_alloc_dmabuf_arg arg; + struct drm_vmw_alloc_dmabuf_req *req = &arg.req; + struct drm_vmw_dmabuf_rep *rep = &arg.rep; + int ret; + + vmw_printf("%s: size = %u\n", __FUNCTION__, size); + + region = CALLOC_STRUCT(vmw_region); + if (!region) + goto out_err1; + + memset(&arg, 0, sizeof(arg)); + req->size = size; + do { + ret = drmCommandWriteRead(vws->ioctl.drm_fd, DRM_VMW_ALLOC_DMABUF, &arg, + sizeof(arg)); + } while (ret == -ERESTART); + + if (ret) { + debug_printf("IOCTL failed %d: %s\n", ret, strerror(-ret)); + goto out_err1; + } + + region->ptr.gmrId = rep->cur_gmr_id; + region->ptr.offset = rep->cur_gmr_offset; + region->data = NULL; + region->handle = rep->handle; + region->map_handle = rep->map_handle; + region->map_count = 0; + region->size = size; + region->drm_fd = vws->ioctl.drm_fd; + + vmw_printf(" gmrId = %u, offset = %u\n", + region->ptr.gmrId, region->ptr.offset); + + return region; + + out_err1: + FREE(region); + return NULL; +} + +void +vmw_ioctl_region_destroy(struct vmw_region *region) +{ + struct drm_vmw_unref_dmabuf_arg arg; + + vmw_printf("%s: gmrId = %u, offset = %u\n", __FUNCTION__, + region->ptr.gmrId, region->ptr.offset); + + if (region->data) { + munmap(region->data, region->size); + region->data = NULL; + } + + memset(&arg, 0, sizeof(arg)); + arg.handle = region->handle; + drmCommandWrite(region->drm_fd, DRM_VMW_UNREF_DMABUF, &arg, sizeof(arg)); + + FREE(region); +} + +SVGAGuestPtr +vmw_ioctl_region_ptr(struct vmw_region *region) +{ + return region->ptr; +} + +void * +vmw_ioctl_region_map(struct vmw_region *region) +{ + void *map; + + vmw_printf("%s: gmrId = %u, offset = %u\n", __FUNCTION__, + region->ptr.gmrId, region->ptr.offset); + + if (region->data == NULL) { + map = mmap(NULL, region->size, PROT_READ | PROT_WRITE, MAP_SHARED, + region->drm_fd, region->map_handle); + if (map == MAP_FAILED) { + debug_printf("%s: Map failed.\n", __FUNCTION__); + return NULL; + } + + region->data = map; + } + + ++region->map_count; + + return region->data; +} + +void +vmw_ioctl_region_unmap(struct vmw_region *region) +{ + vmw_printf("%s: gmrId = %u, offset = %u\n", __FUNCTION__, + region->ptr.gmrId, region->ptr.offset); + --region->map_count; +} + + +int +vmw_ioctl_fence_signalled(struct vmw_winsys_screen *vws, + uint32_t fence) +{ + uint32_t expected; + uint32_t current; + + assert(fence); + if(!fence) + return 0; + + expected = fence; + current = vws->ioctl.fifo_map[SVGA_FIFO_FENCE]; + + if ((int32)(current - expected) >= 0) + return 0; /* fence passed */ + else + return -1; +} + + +static void +vmw_ioctl_sync(struct vmw_winsys_screen *vws, + uint32_t fence) +{ + uint32_t cur_fence; + struct drm_vmw_fence_wait_arg arg; + int ret; + + vmw_printf("%s: fence = %lu\n", __FUNCTION__, + (unsigned long)fence); + + cur_fence = vws->ioctl.fifo_map[SVGA_FIFO_FENCE]; + vmw_printf("%s: Fence id read is 0x%08x\n", __FUNCTION__, + (unsigned int)cur_fence); + + if ((cur_fence - fence) < (1 << 24)) + return; + + memset(&arg, 0, sizeof(arg)); + arg.sequence = fence; + + do { + ret = drmCommandWriteRead(vws->ioctl.drm_fd, DRM_VMW_FENCE_WAIT, &arg, + sizeof(arg)); + } while (ret == -ERESTART); +} + + +int +vmw_ioctl_fence_finish(struct vmw_winsys_screen *vws, + uint32_t fence) +{ + assert(fence); + + if(fence) { + if(vmw_ioctl_fence_signalled(vws, fence) != 0) { + vmw_ioctl_sync(vws, fence); + } + } + + return 0; +} + + +boolean +vmw_ioctl_init(struct vmw_winsys_screen *vws) +{ + struct drm_vmw_getparam_arg gp_arg; + int ret; + + VMW_FUNC; + + memset(&gp_arg, 0, sizeof(gp_arg)); + gp_arg.param = DRM_VMW_PARAM_3D; + ret = drmCommandWriteRead(vws->ioctl.drm_fd, DRM_VMW_GET_PARAM, + &gp_arg, sizeof(gp_arg)); + if (ret || gp_arg.value == 0) { + debug_printf("No 3D enabled (%i, %s)\n", ret, strerror(-ret)); + goto out_err1; + } + + memset(&gp_arg, 0, sizeof(gp_arg)); + gp_arg.param = DRM_VMW_PARAM_FIFO_OFFSET; + ret = drmCommandWriteRead(vws->ioctl.drm_fd, DRM_VMW_GET_PARAM, + &gp_arg, sizeof(gp_arg)); + + if (ret) { + debug_printf("GET_PARAM on %d returned %d: %s\n", + vws->ioctl.drm_fd, ret, strerror(-ret)); + goto out_err1; + } + + vmw_printf("Offset to map is 0x%08llx\n", + (unsigned long long)gp_arg.value); + + vws->ioctl.fifo_map = vmw_ioctl_fifo_map(vws, gp_arg.value); + if (vws->ioctl.fifo_map == NULL) + goto out_err1; + + vmw_printf("%s OK\n", __FUNCTION__); + return TRUE; + + out_err1: + debug_printf("%s Failed\n", __FUNCTION__); + return FALSE; +} + + + +void +vmw_ioctl_cleanup(struct vmw_winsys_screen *vws) +{ + VMW_FUNC; + + vmw_ioctl_fifo_unmap(vws, (void *)vws->ioctl.fifo_map); +} diff --git a/src/gallium/winsys/svga/drm/vmw_screen_pools.c b/src/gallium/winsys/svga/drm/vmw_screen_pools.c new file mode 100644 index 00000000000..b9823d78575 --- /dev/null +++ b/src/gallium/winsys/svga/drm/vmw_screen_pools.c @@ -0,0 +1,97 @@ +/********************************************************** + * Copyright 2009 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + **********************************************************/ + + +#include "vmw_screen.h" + +#include "vmw_buffer.h" +#include "vmw_fence.h" + +#include "pipebuffer/pb_buffer.h" +#include "pipebuffer/pb_bufmgr.h" + +void +vmw_pools_cleanup(struct vmw_winsys_screen *vws) +{ + if(vws->pools.gmr_fenced) + vws->pools.gmr_fenced->destroy(vws->pools.gmr_fenced); + + /* gmr_mm pool is already destroyed above */ + + if(vws->pools.gmr) + vws->pools.gmr->destroy(vws->pools.gmr); +} + + +boolean +vmw_pools_init(struct vmw_winsys_screen *vws) +{ + vws->pools.gmr = vmw_gmr_bufmgr_create(vws); + if(!vws->pools.gmr) + goto error; + + vws->pools.gmr_mm = mm_bufmgr_create(vws->pools.gmr, + VMW_GMR_POOL_SIZE, + 12 /* 4096 alignment */); + if(!vws->pools.gmr_mm) + goto error; + + /* + * GMR buffers are typically shortlived, but it's possible that at a given + * instance a buffer is mapped. So to avoid stalling we tell pipebuffer to + * forbid creation of buffers beyond half the GMR pool size, + * + * XXX: It is unclear weather we want to limit the total amount of temporary + * malloc memory used to backup unvalidated GMR buffers. On one hand it is + * preferrable to fail an allocation than exhausting the guest memory with + * temporary data, but on the other hand it is possible that a stupid + * application creates large vertex buffers and does not use them for a long + * time -- since the svga pipe driver only emits the DMA uploads when a + * buffer is used for drawing this would effectively disabling swapping GMR + * buffers to memory. So far, the preemptively flush already seems to keep + * total allocated memory within relatively small numbers, so we don't + * limit. + */ + vws->pools.gmr_fenced = fenced_bufmgr_create( + vws->pools.gmr_mm, + vmw_fence_ops_create(vws), + VMW_GMR_POOL_SIZE/2, + ~0); + +#ifdef DEBUG + vws->pools.gmr_fenced = pb_debug_manager_create(vws->pools.gmr_fenced, + 4096, + 4096); +#endif + if(!vws->pools.gmr_fenced) + goto error; + + return TRUE; + +error: + vmw_pools_cleanup(vws); + return FALSE; +} + diff --git a/src/gallium/winsys/svga/drm/vmw_screen_svga.c b/src/gallium/winsys/svga/drm/vmw_screen_svga.c new file mode 100644 index 00000000000..2b4e80f0039 --- /dev/null +++ b/src/gallium/winsys/svga/drm/vmw_screen_svga.c @@ -0,0 +1,295 @@ +/********************************************************** + * Copyright 2009 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + **********************************************************/ + +/** + * @file + * This file implements the SVGA interface into this winsys, defined + * in drivers/svga/svga_winsys.h. + * + * @author Keith Whitwell + * @author Jose Fonseca + */ + + +#include "svga_cmd.h" +#include "svga3d_caps.h" + +#include "util/u_inlines.h" +#include "util/u_math.h" +#include "util/u_memory.h" +#include "pipebuffer/pb_buffer.h" +#include "pipebuffer/pb_bufmgr.h" +#include "svga_winsys.h" +#include "vmw_context.h" +#include "vmw_screen.h" +#include "vmw_surface.h" +#include "vmw_buffer.h" +#include "vmw_fence.h" + + +static struct svga_winsys_buffer * +vmw_svga_winsys_buffer_create(struct svga_winsys_screen *sws, + unsigned alignment, + unsigned usage, + unsigned size) +{ + struct vmw_winsys_screen *vws = vmw_winsys_screen(sws); + struct pb_desc desc; + struct pb_manager *provider; + struct pb_buffer *buffer; + + memset(&desc, 0, sizeof desc); + desc.alignment = alignment; + desc.usage = usage; + + provider = vws->pools.gmr_fenced; + + assert(provider); + buffer = provider->create_buffer(provider, size, &desc); + if(!buffer) + return NULL; + + return vmw_svga_winsys_buffer(buffer); +} + + +static void * +vmw_svga_winsys_buffer_map(struct svga_winsys_screen *sws, + struct svga_winsys_buffer *buf, + unsigned flags) +{ + (void)sws; + return pb_map(vmw_pb_buffer(buf), flags); +} + + +static void +vmw_svga_winsys_buffer_unmap(struct svga_winsys_screen *sws, + struct svga_winsys_buffer *buf) +{ + (void)sws; + pb_unmap(vmw_pb_buffer(buf)); +} + + +static void +vmw_svga_winsys_buffer_destroy(struct svga_winsys_screen *sws, + struct svga_winsys_buffer *buf) +{ + struct pb_buffer *pbuf = vmw_pb_buffer(buf); + (void)sws; + pb_reference(&pbuf, NULL); +} + + +static void +vmw_svga_winsys_fence_reference(struct svga_winsys_screen *sws, + struct pipe_fence_handle **pdst, + struct pipe_fence_handle *src) +{ + (void)sws; + *pdst = src; +} + + +static int +vmw_svga_winsys_fence_signalled(struct svga_winsys_screen *sws, + struct pipe_fence_handle *fence, + unsigned flag) +{ + struct vmw_winsys_screen *vws = vmw_winsys_screen(sws); + (void)flag; + return vmw_ioctl_fence_signalled(vws, vmw_fence(fence)); +} + + +static int +vmw_svga_winsys_fence_finish(struct svga_winsys_screen *sws, + struct pipe_fence_handle *fence, + unsigned flag) +{ + struct vmw_winsys_screen *vws = vmw_winsys_screen(sws); + (void)flag; + return vmw_ioctl_fence_finish(vws, vmw_fence(fence)); +} + + + +static struct svga_winsys_surface * +vmw_svga_winsys_surface_create(struct svga_winsys_screen *sws, + SVGA3dSurfaceFlags flags, + SVGA3dSurfaceFormat format, + SVGA3dSize size, + uint32 numFaces, + uint32 numMipLevels) +{ + struct vmw_winsys_screen *vws = vmw_winsys_screen(sws); + struct vmw_svga_winsys_surface *surface; + + surface = CALLOC_STRUCT(vmw_svga_winsys_surface); + if(!surface) + goto no_surface; + + pipe_reference_init(&surface->refcnt, 1); + p_atomic_set(&surface->validated, 0); + surface->screen = vws; + surface->sid = vmw_ioctl_surface_create(vws, + flags, format, size, + numFaces, numMipLevels); + if(surface->sid == SVGA3D_INVALID_ID) + goto no_sid; + + return svga_winsys_surface(surface); + +no_sid: + FREE(surface); +no_surface: + return NULL; +} + + +static boolean +vmw_svga_winsys_surface_is_flushed(struct svga_winsys_screen *sws, + struct svga_winsys_surface *surface) +{ + struct vmw_svga_winsys_surface *vsurf = vmw_svga_winsys_surface(surface); + return (p_atomic_read(&vsurf->validated) == 0); +} + + +static void +vmw_svga_winsys_surface_ref(struct svga_winsys_screen *sws, + struct svga_winsys_surface **pDst, + struct svga_winsys_surface *src) +{ + struct vmw_svga_winsys_surface *d_vsurf = vmw_svga_winsys_surface(*pDst); + struct vmw_svga_winsys_surface *s_vsurf = vmw_svga_winsys_surface(src); + + vmw_svga_winsys_surface_reference(&d_vsurf, s_vsurf); + *pDst = svga_winsys_surface(d_vsurf); +} + + +static void +vmw_svga_winsys_destroy(struct svga_winsys_screen *sws) +{ + struct vmw_winsys_screen *vws = vmw_winsys_screen(sws); + + vmw_winsys_destroy(vws); +} + + +static boolean +vmw_svga_winsys_get_cap(struct svga_winsys_screen *sws, + SVGA3dDevCapIndex index, + SVGA3dDevCapResult *result) +{ + struct vmw_winsys_screen *vws = vmw_winsys_screen(sws); + const uint32 *capsBlock; + const SVGA3dCapsRecord *capsRecord = NULL; + uint32 offset; + const SVGA3dCapPair *capArray; + int numCaps, first, last; + + if(!vws->ioctl.fifo_map) + return FALSE; + + if(vws->ioctl.fifo_map[SVGA_FIFO_3D_HWVERSION] < SVGA3D_HWVERSION_WS6_B1) + return FALSE; + + /* + * Search linearly through the caps block records for the specified type. + */ + capsBlock = (const uint32 *)&vws->ioctl.fifo_map[SVGA_FIFO_3D_CAPS]; + for (offset = 0; capsBlock[offset] != 0; offset += capsBlock[offset]) { + const SVGA3dCapsRecord *record; + assert(offset < SVGA_FIFO_3D_CAPS_SIZE); + record = (const SVGA3dCapsRecord *) (capsBlock + offset); + if ((record->header.type >= SVGA3DCAPS_RECORD_DEVCAPS_MIN) && + (record->header.type <= SVGA3DCAPS_RECORD_DEVCAPS_MAX) && + (!capsRecord || (record->header.type > capsRecord->header.type))) { + capsRecord = record; + } + } + + if(!capsRecord) + return FALSE; + + /* + * Calculate the number of caps from the size of the record. + */ + capArray = (const SVGA3dCapPair *) capsRecord->data; + numCaps = (int) ((capsRecord->header.length * sizeof(uint32) - + sizeof capsRecord->header) / (2 * sizeof(uint32))); + + /* + * Binary-search for the cap with the specified index. + */ + for (first = 0, last = numCaps - 1; first <= last; ) { + int mid = (first + last) / 2; + + if ((SVGA3dDevCapIndex) capArray[mid][0] == index) { + /* + * Found it. + */ + result->u = capArray[mid][1]; + return TRUE; + } + + /* + * Divide and conquer. + */ + if ((SVGA3dDevCapIndex) capArray[mid][0] > index) { + last = mid - 1; + } else { + first = mid + 1; + } + } + + return FALSE; +} + + +boolean +vmw_winsys_screen_init_svga(struct vmw_winsys_screen *vws) +{ + vws->base.destroy = vmw_svga_winsys_destroy; + vws->base.get_cap = vmw_svga_winsys_get_cap; + vws->base.context_create = vmw_svga_winsys_context_create; + vws->base.surface_create = vmw_svga_winsys_surface_create; + vws->base.surface_is_flushed = vmw_svga_winsys_surface_is_flushed; + vws->base.surface_reference = vmw_svga_winsys_surface_ref; + vws->base.buffer_create = vmw_svga_winsys_buffer_create; + vws->base.buffer_map = vmw_svga_winsys_buffer_map; + vws->base.buffer_unmap = vmw_svga_winsys_buffer_unmap; + vws->base.buffer_destroy = vmw_svga_winsys_buffer_destroy; + vws->base.fence_reference = vmw_svga_winsys_fence_reference; + vws->base.fence_signalled = vmw_svga_winsys_fence_signalled; + vws->base.fence_finish = vmw_svga_winsys_fence_finish; + + return TRUE; +} + + diff --git a/src/gallium/winsys/svga/drm/vmw_surface.c b/src/gallium/winsys/svga/drm/vmw_surface.c new file mode 100644 index 00000000000..5f1b9ad5770 --- /dev/null +++ b/src/gallium/winsys/svga/drm/vmw_surface.c @@ -0,0 +1,61 @@ +/********************************************************** + * Copyright 2009 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + **********************************************************/ + + +#include "svga_cmd.h" +#include "util/u_debug.h" +#include "util/u_memory.h" + +#include "vmw_surface.h" +#include "vmw_screen.h" + +void +vmw_svga_winsys_surface_reference(struct vmw_svga_winsys_surface **pdst, + struct vmw_svga_winsys_surface *src) +{ + struct pipe_reference *src_ref; + struct pipe_reference *dst_ref; + struct vmw_svga_winsys_surface *dst; + + if(pdst == NULL || *pdst == src) + return; + + dst = *pdst; + + src_ref = src ? &src->refcnt : NULL; + dst_ref = dst ? &dst->refcnt : NULL; + + if (pipe_reference(dst_ref, src_ref)) { + vmw_ioctl_surface_destroy(dst->screen, dst->sid); +#ifdef DEBUG + /* to detect dangling pointers */ + assert(p_atomic_read(&dst->validated) == 0); + dst->sid = SVGA3D_INVALID_ID; +#endif + FREE(dst); + } + + *pdst = src; +} diff --git a/src/gallium/winsys/svga/drm/vmw_surface.h b/src/gallium/winsys/svga/drm/vmw_surface.h new file mode 100644 index 00000000000..3d61595c288 --- /dev/null +++ b/src/gallium/winsys/svga/drm/vmw_surface.h @@ -0,0 +1,79 @@ +/********************************************************** + * Copyright 2009 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + **********************************************************/ + +/** + * @file + * Surfaces for VMware SVGA winsys. + * + * @author Jose Fonseca + */ + + +#ifndef VMW_SURFACE_H_ +#define VMW_SURFACE_H_ + + +#include "pipe/p_compiler.h" +#include "util/u_atomic.h" +#include "util/u_inlines.h" + +#define VMW_MAX_PRESENTS 3 + + + +struct vmw_svga_winsys_surface +{ + int32_t validated; /* atomic */ + struct pipe_reference refcnt; + + struct vmw_winsys_screen *screen; + uint32_t sid; + + /* FIXME: make this thread safe */ + unsigned next_present_no; + uint32_t present_fences[VMW_MAX_PRESENTS]; +}; + + +static INLINE struct svga_winsys_surface * +svga_winsys_surface(struct vmw_svga_winsys_surface *surf) +{ + assert(!surf || surf->sid != SVGA3D_INVALID_ID); + return (struct svga_winsys_surface *)surf; +} + + +static INLINE struct vmw_svga_winsys_surface * +vmw_svga_winsys_surface(struct svga_winsys_surface *surf) +{ + return (struct vmw_svga_winsys_surface *)surf; +} + + +void +vmw_svga_winsys_surface_reference(struct vmw_svga_winsys_surface **pdst, + struct vmw_svga_winsys_surface *src); + +#endif /* VMW_SURFACE_H_ */ diff --git a/src/gallium/winsys/svga/drm/vmwgfx_drm.h b/src/gallium/winsys/svga/drm/vmwgfx_drm.h new file mode 100644 index 00000000000..47914bdb711 --- /dev/null +++ b/src/gallium/winsys/svga/drm/vmwgfx_drm.h @@ -0,0 +1,545 @@ +/************************************************************************** + * + * Copyright © 2009 VMware, Inc., Palo Alto, CA., USA + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef __VMWGFX_DRM_H__ +#define __VMWGFX_DRM_H__ + +#define DRM_VMW_MAX_SURFACE_FACES 6 +#define DRM_VMW_MAX_MIP_LEVELS 24 + +#define DRM_VMW_EXT_NAME_LEN 128 + +#define DRM_VMW_GET_PARAM 0 +#define DRM_VMW_ALLOC_DMABUF 1 +#define DRM_VMW_UNREF_DMABUF 2 +#define DRM_VMW_CURSOR_BYPASS 3 +/* guarded by DRM_VMW_PARAM_NUM_STREAMS != 0*/ +#define DRM_VMW_CONTROL_STREAM 4 +#define DRM_VMW_CLAIM_STREAM 5 +#define DRM_VMW_UNREF_STREAM 6 +/* guarded by DRM_VMW_PARAM_3D == 1 */ +#define DRM_VMW_CREATE_CONTEXT 7 +#define DRM_VMW_UNREF_CONTEXT 8 +#define DRM_VMW_CREATE_SURFACE 9 +#define DRM_VMW_UNREF_SURFACE 10 +#define DRM_VMW_REF_SURFACE 11 +#define DRM_VMW_EXECBUF 12 +#define DRM_VMW_FIFO_DEBUG 13 +#define DRM_VMW_FENCE_WAIT 14 + + +/*************************************************************************/ +/** + * DRM_VMW_GET_PARAM - get device information. + * + * DRM_VMW_PARAM_FIFO_OFFSET: + * Offset to use to map the first page of the FIFO read-only. + * The fifo is mapped using the mmap() system call on the drm device. + * + * DRM_VMW_PARAM_OVERLAY_IOCTL: + * Does the driver support the overlay ioctl. + */ + +#define DRM_VMW_PARAM_NUM_STREAMS 0 +#define DRM_VMW_PARAM_NUM_FREE_STREAMS 1 +#define DRM_VMW_PARAM_3D 2 +#define DRM_VMW_PARAM_FIFO_OFFSET 3 +#define DRM_VMW_PARAM_HW_CAPS 4 +#define DRM_VMW_PARAM_FIFO_CAPS 5 + +/** + * struct drm_vmw_getparam_arg + * + * @value: Returned value. //Out + * @param: Parameter to query. //In. + * + * Argument to the DRM_VMW_GET_PARAM Ioctl. + */ + +struct drm_vmw_getparam_arg { + uint64_t value; + uint32_t param; + uint32_t pad64; +}; + +/*************************************************************************/ +/** + * DRM_VMW_CREATE_CONTEXT - Create a host context. + * + * Allocates a device unique context id, and queues a create context command + * for the host. Does not wait for host completion. + */ + +/** + * struct drm_vmw_context_arg + * + * @cid: Device unique context ID. + * + * Output argument to the DRM_VMW_CREATE_CONTEXT Ioctl. + * Input argument to the DRM_VMW_UNREF_CONTEXT Ioctl. + */ + +struct drm_vmw_context_arg { + int32_t cid; + uint32_t pad64; +}; + +/*************************************************************************/ +/** + * DRM_VMW_UNREF_CONTEXT - Create a host context. + * + * Frees a global context id, and queues a destroy host command for the host. + * Does not wait for host completion. The context ID can be used directly + * in the command stream and shows up as the same context ID on the host. + */ + +/*************************************************************************/ +/** + * DRM_VMW_CREATE_SURFACE - Create a host suface. + * + * Allocates a device unique surface id, and queues a create surface command + * for the host. Does not wait for host completion. The surface ID can be + * used directly in the command stream and shows up as the same surface + * ID on the host. + */ + +/** + * struct drm_wmv_surface_create_req + * + * @flags: Surface flags as understood by the host. + * @format: Surface format as understood by the host. + * @mip_levels: Number of mip levels for each face. + * An unused face should have 0 encoded. + * @size_addr: Address of a user-space array of sruct drm_vmw_size + * cast to an uint64_t for 32-64 bit compatibility. + * The size of the array should equal the total number of mipmap levels. + * @shareable: Boolean whether other clients (as identified by file descriptors) + * may reference this surface. + * @scanout: Boolean whether the surface is intended to be used as a + * scanout. + * + * Input data to the DRM_VMW_CREATE_SURFACE Ioctl. + * Output data from the DRM_VMW_REF_SURFACE Ioctl. + */ + +struct drm_vmw_surface_create_req { + uint32_t flags; + uint32_t format; + uint32_t mip_levels[DRM_VMW_MAX_SURFACE_FACES]; + uint64_t size_addr; + int32_t shareable; + int32_t scanout; +}; + +/** + * struct drm_wmv_surface_arg + * + * @sid: Surface id of created surface or surface to destroy or reference. + * + * Output data from the DRM_VMW_CREATE_SURFACE Ioctl. + * Input argument to the DRM_VMW_UNREF_SURFACE Ioctl. + * Input argument to the DRM_VMW_REF_SURFACE Ioctl. + */ + +struct drm_vmw_surface_arg { + int32_t sid; + uint32_t pad64; +}; + +/** + * struct drm_vmw_size ioctl. + * + * @width - mip level width + * @height - mip level height + * @depth - mip level depth + * + * Description of a mip level. + * Input data to the DRM_WMW_CREATE_SURFACE Ioctl. + */ + +struct drm_vmw_size { + uint32_t width; + uint32_t height; + uint32_t depth; + uint32_t pad64; +}; + +/** + * union drm_vmw_surface_create_arg + * + * @rep: Output data as described above. + * @req: Input data as described above. + * + * Argument to the DRM_VMW_CREATE_SURFACE Ioctl. + */ + +union drm_vmw_surface_create_arg { + struct drm_vmw_surface_arg rep; + struct drm_vmw_surface_create_req req; +}; + +/*************************************************************************/ +/** + * DRM_VMW_REF_SURFACE - Reference a host surface. + * + * Puts a reference on a host surface with a give sid, as previously + * returned by the DRM_VMW_CREATE_SURFACE ioctl. + * A reference will make sure the surface isn't destroyed while we hold + * it and will allow the calling client to use the surface ID in the command + * stream. + * + * On successful return, the Ioctl returns the surface information given + * in the DRM_VMW_CREATE_SURFACE ioctl. + */ + +/** + * union drm_vmw_surface_reference_arg + * + * @rep: Output data as described above. + * @req: Input data as described above. + * + * Argument to the DRM_VMW_REF_SURFACE Ioctl. + */ + +union drm_vmw_surface_reference_arg { + struct drm_vmw_surface_create_req rep; + struct drm_vmw_surface_arg req; +}; + +/*************************************************************************/ +/** + * DRM_VMW_UNREF_SURFACE - Unreference a host surface. + * + * Clear a reference previously put on a host surface. + * When all references are gone, including the one implicitly placed + * on creation, + * a destroy surface command will be queued for the host. + * Does not wait for completion. + */ + +/*************************************************************************/ +/** + * DRM_VMW_EXECBUF + * + * Submit a command buffer for execution on the host, and return a + * fence sequence that when signaled, indicates that the command buffer has + * executed. + */ + +/** + * struct drm_vmw_execbuf_arg + * + * @commands: User-space address of a command buffer cast to an uint64_t. + * @command-size: Size in bytes of the command buffer. + * @throttle-us: Sleep until software is less than @throttle_us + * microseconds ahead of hardware. The driver may round this value + * to the nearest kernel tick. + * @fence_rep: User-space address of a struct drm_vmw_fence_rep cast to an + * uint64_t. + * @version: Allows expanding the execbuf ioctl parameters without breaking + * backwards compatibility, since user-space will always tell the kernel + * which version it uses. + * @flags: Execbuf flags. None currently. + * + * Argument to the DRM_VMW_EXECBUF Ioctl. + */ + +#define DRM_VMW_EXECBUF_VERSION 0 + +struct drm_vmw_execbuf_arg { + uint64_t commands; + uint32_t command_size; + uint32_t throttle_us; + uint64_t fence_rep; + uint32_t version; + uint32_t flags; +}; + +/** + * struct drm_vmw_fence_rep + * + * @fence_seq: Fence sequence associated with a command submission. + * @error: This member should've been set to -EFAULT on submission. + * The following actions should be take on completion: + * error == -EFAULT: Fence communication failed. The host is synchronized. + * Use the last fence id read from the FIFO fence register. + * error != 0 && error != -EFAULT: + * Fence submission failed. The host is synchronized. Use the fence_seq member. + * error == 0: All is OK, The host may not be synchronized. + * Use the fence_seq member. + * + * Input / Output data to the DRM_VMW_EXECBUF Ioctl. + */ + +struct drm_vmw_fence_rep { + uint64_t fence_seq; + int32_t error; + uint32_t pad64; +}; + +/*************************************************************************/ +/** + * DRM_VMW_ALLOC_DMABUF + * + * Allocate a DMA buffer that is visible also to the host. + * NOTE: The buffer is + * identified by a handle and an offset, which are private to the guest, but + * useable in the command stream. The guest kernel may translate these + * and patch up the command stream accordingly. In the future, the offset may + * be zero at all times, or it may disappear from the interface before it is + * fixed. + * + * The DMA buffer may stay user-space mapped in the guest at all times, + * and is thus suitable for sub-allocation. + * + * DMA buffers are mapped using the mmap() syscall on the drm device. + */ + +/** + * struct drm_vmw_alloc_dmabuf_req + * + * @size: Required minimum size of the buffer. + * + * Input data to the DRM_VMW_ALLOC_DMABUF Ioctl. + */ + +struct drm_vmw_alloc_dmabuf_req { + uint32_t size; + uint32_t pad64; +}; + +/** + * struct drm_vmw_dmabuf_rep + * + * @map_handle: Offset to use in the mmap() call used to map the buffer. + * @handle: Handle unique to this buffer. Used for unreferencing. + * @cur_gmr_id: GMR id to use in the command stream when this buffer is + * referenced. See not above. + * @cur_gmr_offset: Offset to use in the command stream when this buffer is + * referenced. See note above. + * + * Output data from the DRM_VMW_ALLOC_DMABUF Ioctl. + */ + +struct drm_vmw_dmabuf_rep { + uint64_t map_handle; + uint32_t handle; + uint32_t cur_gmr_id; + uint32_t cur_gmr_offset; + uint32_t pad64; +}; + +/** + * union drm_vmw_dmabuf_arg + * + * @req: Input data as described above. + * @rep: Output data as described above. + * + * Argument to the DRM_VMW_ALLOC_DMABUF Ioctl. + */ + +union drm_vmw_alloc_dmabuf_arg { + struct drm_vmw_alloc_dmabuf_req req; + struct drm_vmw_dmabuf_rep rep; +}; + +/*************************************************************************/ +/** + * DRM_VMW_UNREF_DMABUF - Free a DMA buffer. + * + */ + +/** + * struct drm_vmw_unref_dmabuf_arg + * + * @handle: Handle indicating what buffer to free. Obtained from the + * DRM_VMW_ALLOC_DMABUF Ioctl. + * + * Argument to the DRM_VMW_UNREF_DMABUF Ioctl. + */ + +struct drm_vmw_unref_dmabuf_arg { + uint32_t handle; + uint32_t pad64; +}; + +/*************************************************************************/ +/** + * DRM_VMW_FIFO_DEBUG - Get last FIFO submission. + * + * This IOCTL copies the last FIFO submission directly out of the FIFO buffer. + */ + +/** + * struct drm_vmw_fifo_debug_arg + * + * @debug_buffer: User space address of a debug_buffer cast to an uint64_t //In + * @debug_buffer_size: Size in bytes of debug buffer //In + * @used_size: Number of bytes copied to the buffer // Out + * @did_not_fit: Boolean indicating that the fifo contents did not fit. //Out + * + * Argument to the DRM_VMW_FIFO_DEBUG Ioctl. + */ + +struct drm_vmw_fifo_debug_arg { + uint64_t debug_buffer; + uint32_t debug_buffer_size; + uint32_t used_size; + int32_t did_not_fit; + uint32_t pad64; +}; + +struct drm_vmw_fence_wait_arg { + uint64_t sequence; + uint64_t kernel_cookie; + int32_t cookie_valid; + int32_t pad64; +}; + +/*************************************************************************/ +/** + * DRM_VMW_CONTROL_STREAM - Control overlays, aka streams. + * + * This IOCTL controls the overlay units of the svga device. + * The SVGA overlay units does not work like regular hardware units in + * that they do not automaticaly read back the contents of the given dma + * buffer. But instead only read back for each call to this ioctl, and + * at any point between this call being made and a following call that + * either changes the buffer or disables the stream. + */ + +/** + * struct drm_vmw_rect + * + * Defines a rectangle. Used in the overlay ioctl to define + * source and destination rectangle. + */ + +struct drm_vmw_rect { + int32_t x; + int32_t y; + uint32_t w; + uint32_t h; +}; + +/** + * struct drm_vmw_control_stream_arg + * + * @stream_id: Stearm to control + * @enabled: If false all following arguments are ignored. + * @handle: Handle to buffer for getting data from. + * @format: Format of the overlay as understood by the host. + * @width: Width of the overlay. + * @height: Height of the overlay. + * @size: Size of the overlay in bytes. + * @pitch: Array of pitches, the two last are only used for YUV12 formats. + * @offset: Offset from start of dma buffer to overlay. + * @src: Source rect, must be within the defined area above. + * @dst: Destination rect, x and y may be negative. + * + * Argument to the DRM_VMW_CONTROL_STREAM Ioctl. + */ + +struct drm_vmw_control_stream_arg { + uint32_t stream_id; + uint32_t enabled; + + uint32_t flags; + uint32_t color_key; + + uint32_t handle; + uint32_t offset; + int32_t format; + uint32_t size; + uint32_t width; + uint32_t height; + uint32_t pitch[3]; + + uint32_t pad64; + struct drm_vmw_rect src; + struct drm_vmw_rect dst; +}; + +/*************************************************************************/ +/** + * DRM_VMW_CURSOR_BYPASS - Give extra information about cursor bypass. + * + */ + +#define DRM_VMW_CURSOR_BYPASS_ALL (1 << 0) +#define DRM_VMW_CURSOR_BYPASS_FLAGS (1) + +/** + * struct drm_vmw_cursor_bypass_arg + * + * @flags: Flags. + * @crtc_id: Crtc id, only used if DMR_CURSOR_BYPASS_ALL isn't passed. + * @xpos: X position of cursor. + * @ypos: Y position of cursor. + * @xhot: X hotspot. + * @yhot: Y hotspot. + * + * Argument to the DRM_VMW_CURSOR_BYPASS Ioctl. + */ + +struct drm_vmw_cursor_bypass_arg { + uint32_t flags; + uint32_t crtc_id; + int32_t xpos; + int32_t ypos; + int32_t xhot; + int32_t yhot; +}; + +/*************************************************************************/ +/** + * DRM_VMW_CLAIM_STREAM - Claim a single stream. + */ + +/** + * struct drm_vmw_context_arg + * + * @stream_id: Device unique context ID. + * + * Output argument to the DRM_VMW_CREATE_CONTEXT Ioctl. + * Input argument to the DRM_VMW_UNREF_CONTEXT Ioctl. + */ + +struct drm_vmw_stream_arg { + uint32_t stream_id; + uint32_t pad64; +}; + +/*************************************************************************/ +/** + * DRM_VMW_UNREF_STREAM - Unclaim a stream. + * + * Return a single stream that was claimed by this process. Also makes + * sure that the stream has been stopped. + */ + +#endif diff --git a/src/gallium/winsys/sw/Makefile b/src/gallium/winsys/sw/Makefile new file mode 100644 index 00000000000..e9182ea5b1b --- /dev/null +++ b/src/gallium/winsys/sw/Makefile @@ -0,0 +1,12 @@ +# src/gallium/winsys/sw/Makefile +TOP = ../../../.. +include $(TOP)/configs/current + +SUBDIRS = null wrapper + +default install clean: + @for dir in $(SUBDIRS) ; do \ + if [ -d $$dir ] ; then \ + (cd $$dir && $(MAKE) $@) || exit 1; \ + fi \ + done diff --git a/src/gallium/winsys/sw/drm/Makefile b/src/gallium/winsys/sw/drm/Makefile new file mode 100644 index 00000000000..79664536aa0 --- /dev/null +++ b/src/gallium/winsys/sw/drm/Makefile @@ -0,0 +1,12 @@ +TOP = ../../../../.. +include $(TOP)/configs/current + +LIBNAME = swdrm + +C_SOURCES = sw_drm_api.c + +LIBRARY_INCLUDES = + +LIBRARY_DEFINES = + +include ../../../Makefile.template diff --git a/src/gallium/winsys/sw/drm/sw_drm_api.c b/src/gallium/winsys/sw/drm/sw_drm_api.c new file mode 100644 index 00000000000..eb81d26a593 --- /dev/null +++ b/src/gallium/winsys/sw/drm/sw_drm_api.c @@ -0,0 +1,97 @@ +/********************************************************** + * Copyright 2010 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + **********************************************************/ + + +#include "util/u_memory.h" +#include "softpipe/sp_public.h" +#include "state_tracker/drm_api.h" +#include "../../sw/wrapper/wrapper_sw_winsys.h" +#include "sw_drm_api.h" + + +/* + * Defines + */ + + +struct sw_drm_api +{ + struct drm_api base; + struct drm_api *api; + struct sw_winsys *sw; +}; + +static INLINE struct sw_drm_api * +sw_drm_api(struct drm_api *api) +{ + return (struct sw_drm_api *)api; +} + + +/* + * Exported functions + */ + + +static struct pipe_screen * +sw_drm_create_screen(struct drm_api *_api, int drmFD, + struct drm_create_screen_arg *arg) +{ + struct sw_drm_api *swapi = sw_drm_api(_api); + struct drm_api *api = swapi->api; + struct sw_winsys *sww; + struct pipe_screen *screen; + + screen = api->create_screen(api, drmFD, arg); + + sww = wrapper_sw_winsys_warp_pipe_screen(screen); + + return softpipe_create_screen(sww); +} + +static void +sw_drm_destroy(struct drm_api *api) +{ + struct sw_drm_api *swapi = sw_drm_api(api); + if (swapi->api->destroy) + swapi->api->destroy(swapi->api); + + FREE(swapi); +} + +struct drm_api * +sw_drm_api_create(struct drm_api *api) +{ + struct sw_drm_api *swapi = CALLOC_STRUCT(sw_drm_api); + + swapi->base.name = "sw"; + swapi->base.driver_name = api->driver_name; + swapi->base.create_screen = sw_drm_create_screen; + swapi->base.destroy = sw_drm_destroy; + + swapi->api = api; + + return &swapi->base; +} diff --git a/src/gallium/winsys/sw/drm/sw_drm_api.h b/src/gallium/winsys/sw/drm/sw_drm_api.h new file mode 100644 index 00000000000..ce90a04ae0c --- /dev/null +++ b/src/gallium/winsys/sw/drm/sw_drm_api.h @@ -0,0 +1,34 @@ +/********************************************************** + * Copyright 2010 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + **********************************************************/ + + +#ifndef SW_DRM_API_H +#define SW_DRM_API_H + +struct drm_api; + +struct drm_api * sw_drm_api_create(struct drm_api *api); + +#endif diff --git a/src/gallium/winsys/sw/gdi/SConscript b/src/gallium/winsys/sw/gdi/SConscript new file mode 100644 index 00000000000..1267fc6eea4 --- /dev/null +++ b/src/gallium/winsys/sw/gdi/SConscript @@ -0,0 +1,23 @@ +####################################################################### +# SConscript for xlib winsys + + +Import('*') + +if env['platform'] == 'windows': + + env = env.Clone() + + env.Append(CPPPATH = [ + '#/src/gallium/include', + '#/src/gallium/auxiliary', + '#/src/gallium/drivers', + ]) + + ws_gdi = env.ConvenienceLibrary( + target = 'ws_gdi', + source = [ + 'gdi_sw_winsys.c', + ] + ) + Export('ws_gdi') diff --git a/src/gallium/winsys/sw/gdi/gdi_sw_winsys.c b/src/gallium/winsys/sw/gdi/gdi_sw_winsys.c new file mode 100644 index 00000000000..4dba4b577b8 --- /dev/null +++ b/src/gallium/winsys/sw/gdi/gdi_sw_winsys.c @@ -0,0 +1,247 @@ +/************************************************************************** + * + * Copyright 2009 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * + **************************************************************************/ + +/** + * @file + * GDI software rasterizer support. + * + * @author Jose Fonseca + */ + + +#include + +#include "pipe/p_format.h" +#include "pipe/p_context.h" +#include "util/u_inlines.h" +#include "util/u_format.h" +#include "util/u_math.h" +#include "util/u_memory.h" +#include "state_tracker/sw_winsys.h" +#include "gdi_sw_winsys.h" + + +struct gdi_sw_displaytarget +{ + enum pipe_format format; + unsigned width; + unsigned height; + unsigned stride; + + unsigned size; + + void *data; + + BITMAPINFO bmi; +}; + + +/** Cast wrapper */ +static INLINE struct gdi_sw_displaytarget * +gdi_sw_displaytarget( struct sw_displaytarget *buf ) +{ + return (struct gdi_sw_displaytarget *)buf; +} + + +static boolean +gdi_sw_is_displaytarget_format_supported( struct sw_winsys *ws, + unsigned tex_usage, + enum pipe_format format ) +{ + switch(format) { + case PIPE_FORMAT_B8G8R8X8_UNORM: + case PIPE_FORMAT_B8G8R8A8_UNORM: + return TRUE; + + /* TODO: Support other formats possible with BMPs, as described in + * http://msdn.microsoft.com/en-us/library/dd183376(VS.85).aspx */ + + default: + return FALSE; + } +} + + +static void * +gdi_sw_displaytarget_map(struct sw_winsys *ws, + struct sw_displaytarget *dt, + unsigned flags ) +{ + struct gdi_sw_displaytarget *gdt = gdi_sw_displaytarget(dt); + + return gdt->data; +} + + +static void +gdi_sw_displaytarget_unmap(struct sw_winsys *ws, + struct sw_displaytarget *dt ) +{ + +} + + +static void +gdi_sw_displaytarget_destroy(struct sw_winsys *winsys, + struct sw_displaytarget *dt) +{ + struct gdi_sw_displaytarget *gdt = gdi_sw_displaytarget(dt); + + align_free(gdt->data); + FREE(gdt); +} + + +static struct sw_displaytarget * +gdi_sw_displaytarget_create(struct sw_winsys *winsys, + unsigned tex_usage, + enum pipe_format format, + unsigned width, unsigned height, + unsigned alignment, + unsigned *stride) +{ + struct gdi_sw_displaytarget *gdt; + unsigned cpp; + unsigned bpp; + + gdt = CALLOC_STRUCT(gdi_sw_displaytarget); + if(!gdt) + goto no_gdt; + + gdt->format = format; + gdt->width = width; + gdt->height = height; + + bpp = util_format_get_blocksizebits(format); + cpp = util_format_get_blocksize(format); + + gdt->stride = align(width * cpp, alignment); + gdt->size = gdt->stride * height; + + gdt->data = align_malloc(gdt->size, alignment); + if(!gdt->data) + goto no_data; + + gdt->bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); + gdt->bmi.bmiHeader.biWidth = gdt->stride / cpp; + gdt->bmi.bmiHeader.biHeight= -(long)height; + gdt->bmi.bmiHeader.biPlanes = 1; + gdt->bmi.bmiHeader.biBitCount = bpp; + gdt->bmi.bmiHeader.biCompression = BI_RGB; + gdt->bmi.bmiHeader.biSizeImage = 0; + gdt->bmi.bmiHeader.biXPelsPerMeter = 0; + gdt->bmi.bmiHeader.biYPelsPerMeter = 0; + gdt->bmi.bmiHeader.biClrUsed = 0; + gdt->bmi.bmiHeader.biClrImportant = 0; + + *stride = gdt->stride; + return (struct sw_displaytarget *)gdt; + +no_data: + FREE(gdt); +no_gdt: + return NULL; +} + + +static struct sw_displaytarget * +gdi_sw_displaytarget_from_handle(struct sw_winsys *winsys, + const struct pipe_texture *templet, + struct winsys_handle *whandle, + unsigned *stride) +{ + assert(0); + return NULL; +} + + +static boolean +gdi_sw_displaytarget_get_handle(struct sw_winsys *winsys, + struct sw_displaytarget *dt, + struct winsys_handle *whandle) +{ + assert(0); + return FALSE; +} + + +void +gdi_sw_display( struct sw_winsys *winsys, + struct sw_displaytarget *dt, + HDC hDC ) +{ + struct gdi_sw_displaytarget *gdt = gdi_sw_displaytarget(dt); + + StretchDIBits(hDC, + 0, 0, gdt->width, gdt->height, + 0, 0, gdt->width, gdt->height, + gdt->data, &gdt->bmi, 0, SRCCOPY); +} + +static void +gdi_sw_displaytarget_display(struct sw_winsys *winsys, + struct sw_displaytarget *dt, + void *context_private) +{ + /* nasty: + */ + HDC hDC = (HDC)context_private; + + gdi_sw_display(winsys, dt, hDC); +} + + +static void +gdi_sw_destroy(struct sw_winsys *winsys) +{ + FREE(winsys); +} + +struct sw_winsys * +gdi_create_sw_winsys(void) +{ + static struct sw_winsys *winsys; + + winsys = CALLOC_STRUCT(sw_winsys); + if(!winsys) + return NULL; + + winsys->destroy = gdi_sw_destroy; + winsys->is_displaytarget_format_supported = gdi_sw_is_displaytarget_format_supported; + winsys->displaytarget_create = gdi_sw_displaytarget_create; + winsys->displaytarget_from_handle = gdi_sw_displaytarget_from_handle; + winsys->displaytarget_get_handle = gdi_sw_displaytarget_get_handle; + winsys->displaytarget_map = gdi_sw_displaytarget_map; + winsys->displaytarget_unmap = gdi_sw_displaytarget_unmap; + winsys->displaytarget_display = gdi_sw_displaytarget_display; + winsys->displaytarget_destroy = gdi_sw_displaytarget_destroy; + + return winsys; +} + diff --git a/src/gallium/winsys/sw/gdi/gdi_sw_winsys.h b/src/gallium/winsys/sw/gdi/gdi_sw_winsys.h new file mode 100644 index 00000000000..4bbcb47848b --- /dev/null +++ b/src/gallium/winsys/sw/gdi/gdi_sw_winsys.h @@ -0,0 +1,16 @@ +#ifndef GDI_SW_WINSYS_H +#define GDI_SW_WINSYS_H + +#include + +#include "pipe/p_compiler.h" +#include "state_tracker/sw_winsys.h" + +void gdi_sw_display( struct sw_winsys *winsys, + struct sw_displaytarget *dt, + HDC hDC ); + +struct sw_winsys * +gdi_create_sw_winsys(void); + +#endif diff --git a/src/gallium/winsys/sw/null/Makefile b/src/gallium/winsys/sw/null/Makefile new file mode 100644 index 00000000000..b1882b582e9 --- /dev/null +++ b/src/gallium/winsys/sw/null/Makefile @@ -0,0 +1,16 @@ +TOP = ../../../../.. +include $(TOP)/configs/current + +LIBNAME = ws_null + +LIBRARY_INCLUDES = \ + -I$(TOP)/src/gallium/include \ + -I$(TOP)/src/gallium/drivers \ + -I$(TOP)/src/gallium/auxiliary + +C_SOURCES = \ + null_sw_winsys.c + +include ../../../Makefile.template + + diff --git a/src/gallium/winsys/sw/null/SConscript b/src/gallium/winsys/sw/null/SConscript new file mode 100644 index 00000000000..21837dc60c2 --- /dev/null +++ b/src/gallium/winsys/sw/null/SConscript @@ -0,0 +1,21 @@ +####################################################################### +# SConscript for xlib winsys + + +Import('*') + +env = env.Clone() + +env.Append(CPPPATH = [ + '#/src/gallium/include', + '#/src/gallium/auxiliary', + '#/src/gallium/drivers', +]) + +ws_null = env.ConvenienceLibrary( + target = 'ws_null', + source = [ + 'null_sw_winsys.c', + ] +) +Export('ws_null') diff --git a/src/gallium/winsys/sw/null/null_sw_winsys.c b/src/gallium/winsys/sw/null/null_sw_winsys.c new file mode 100644 index 00000000000..5027e57b303 --- /dev/null +++ b/src/gallium/winsys/sw/null/null_sw_winsys.c @@ -0,0 +1,148 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + **************************************************************************/ + +/** + * @file + * Null software rasterizer winsys. + * + * There is no present support. Framebuffer data needs to be obtained via + * transfers. + * + * @author Jose Fonseca + */ + + +#include "pipe/p_format.h" +#include "util/u_memory.h" +#include "state_tracker/sw_winsys.h" +#include "null_sw_winsys.h" + + +static boolean +null_sw_is_displaytarget_format_supported(struct sw_winsys *ws, + unsigned tex_usage, + enum pipe_format format ) +{ + return FALSE; +} + + +static void * +null_sw_displaytarget_map(struct sw_winsys *ws, + struct sw_displaytarget *dt, + unsigned flags ) +{ + assert(0); + return NULL; +} + + +static void +null_sw_displaytarget_unmap(struct sw_winsys *ws, + struct sw_displaytarget *dt ) +{ + assert(0); +} + + +static void +null_sw_displaytarget_destroy(struct sw_winsys *winsys, + struct sw_displaytarget *dt) +{ + assert(0); +} + + +static struct sw_displaytarget * +null_sw_displaytarget_create(struct sw_winsys *winsys, + unsigned tex_usage, + enum pipe_format format, + unsigned width, unsigned height, + unsigned alignment, + unsigned *stride) +{ + return NULL; +} + + +static struct sw_displaytarget * +null_sw_displaytarget_from_handle(struct sw_winsys *winsys, + const struct pipe_texture *templet, + struct winsys_handle *whandle, + unsigned *stride) +{ + return NULL; +} + + +static boolean +null_sw_displaytarget_get_handle(struct sw_winsys *winsys, + struct sw_displaytarget *dt, + struct winsys_handle *whandle) +{ + assert(0); + return FALSE; +} + + +static void +null_sw_displaytarget_display(struct sw_winsys *winsys, + struct sw_displaytarget *dt, + void *context_private) +{ + assert(0); +} + + +static void +null_sw_destroy(struct sw_winsys *winsys) +{ + FREE(winsys); +} + + +struct sw_winsys * +null_sw_create(void) +{ + static struct sw_winsys *winsys; + + winsys = CALLOC_STRUCT(sw_winsys); + if (!winsys) + return NULL; + + winsys->destroy = null_sw_destroy; + winsys->is_displaytarget_format_supported = null_sw_is_displaytarget_format_supported; + winsys->displaytarget_create = null_sw_displaytarget_create; + winsys->displaytarget_from_handle = null_sw_displaytarget_from_handle; + winsys->displaytarget_get_handle = null_sw_displaytarget_get_handle; + winsys->displaytarget_map = null_sw_displaytarget_map; + winsys->displaytarget_unmap = null_sw_displaytarget_unmap; + winsys->displaytarget_display = null_sw_displaytarget_display; + winsys->displaytarget_destroy = null_sw_displaytarget_destroy; + + return winsys; +} diff --git a/src/gallium/winsys/sw/null/null_sw_winsys.h b/src/gallium/winsys/sw/null/null_sw_winsys.h new file mode 100644 index 00000000000..1986186febe --- /dev/null +++ b/src/gallium/winsys/sw/null/null_sw_winsys.h @@ -0,0 +1,40 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + **************************************************************************/ + + +#ifndef NULL_SW_WINSYS_H_ +#define NULL_SW_WINSYS_H_ + + +struct sw_winsys; + + +struct sw_winsys * +null_sw_create(void); + + +#endif /* NULL_SW_WINSYS_H_ */ diff --git a/src/gallium/winsys/sw/wrapper/Makefile b/src/gallium/winsys/sw/wrapper/Makefile new file mode 100644 index 00000000000..4771fbcf700 --- /dev/null +++ b/src/gallium/winsys/sw/wrapper/Makefile @@ -0,0 +1,12 @@ +TOP = ../../../../.. +include $(TOP)/configs/current + +LIBNAME = wsw + +C_SOURCES = wrapper_sw_winsys.c + +LIBRARY_INCLUDES = + +LIBRARY_DEFINES = + +include ../../../Makefile.template diff --git a/src/gallium/winsys/sw/wrapper/wrapper_sw_winsys.c b/src/gallium/winsys/sw/wrapper/wrapper_sw_winsys.c new file mode 100644 index 00000000000..459b1c1e2a3 --- /dev/null +++ b/src/gallium/winsys/sw/wrapper/wrapper_sw_winsys.c @@ -0,0 +1,282 @@ +/********************************************************** + * Copyright 2010 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + **********************************************************/ + + +#include "wrapper_sw_winsys.h" + +#include "pipe/p_format.h" +#include "pipe/p_state.h" + +#include "state_tracker/sw_winsys.h" + +#include "util/u_memory.h" +#include "util/u_inlines.h" + +/* + * This code wraps a pipe_screen and exposes a sw_winsys interface for use + * with software resterizers. This code is used by the DRM based winsys to + * allow access to the drm driver. + * + * We must borrow the whole stack because only the pipe screen knows how + * to decode the content of a buffer. Or how to create a buffer that + * can still be used by drivers using real hardware (as the case is + * with software st/xorg but hw st/dri). + * + * We also need a pipe context for the transfers. + */ + +struct wrapper_sw_winsys +{ + struct sw_winsys base; + struct pipe_screen *screen; + struct pipe_context *pipe; +}; + +struct wrapper_sw_displaytarget +{ + struct wrapper_sw_winsys *winsys; + struct pipe_texture *tex; + struct pipe_transfer *transfer; + + unsigned width; + unsigned height; + unsigned map_count; + unsigned stride; /**< because we give stride at create */ + void *ptr; +}; + +static INLINE struct wrapper_sw_winsys * +wrapper_sw_winsys(struct sw_winsys *ws) +{ + return (struct wrapper_sw_winsys *)ws; +} + +static INLINE struct wrapper_sw_displaytarget * +wrapper_sw_displaytarget(struct sw_displaytarget *dt) +{ + return (struct wrapper_sw_displaytarget *)dt; +} + + +/* + * Functions + */ + + +static boolean +wsw_dt_get_stride(struct wrapper_sw_displaytarget *wdt, unsigned *stride) +{ + struct pipe_context *pipe = wdt->winsys->pipe; + struct pipe_texture *tex = wdt->tex; + struct pipe_transfer *tr; + + tr = pipe->get_tex_transfer(pipe, tex, 0, 0, 0, + PIPE_TRANSFER_READ_WRITE, + 0, 0, wdt->width, wdt->height); + if (!tr) + return FALSE; + + *stride = tr->stride; + wdt->stride = tr->stride; + + pipe->tex_transfer_destroy(pipe, tr); + + return TRUE; +} + +static struct sw_displaytarget * +wsw_dt_wrap_texture(struct wrapper_sw_winsys *wsw, + struct pipe_texture *tex, unsigned *stride) +{ + struct wrapper_sw_displaytarget *wdt = CALLOC_STRUCT(wrapper_sw_displaytarget); + if (!wdt) + goto err_unref; + + wdt->tex = tex; + wdt->winsys = wsw; + + if (!wsw_dt_get_stride(wdt, stride)) + goto err_free; + + return (struct sw_displaytarget *)wdt; + +err_free: + FREE(wdt); +err_unref: + pipe_texture_reference(&tex, NULL); + return NULL; +} + +static struct sw_displaytarget * +wsw_dt_create(struct sw_winsys *ws, + unsigned tex_usage, + enum pipe_format format, + unsigned width, unsigned height, + unsigned alignment, + unsigned *stride) +{ + struct wrapper_sw_winsys *wsw = wrapper_sw_winsys(ws); + struct pipe_texture templ; + struct pipe_texture *tex; + + /* + * XXX Why don't we just get the template. + */ + memset(&templ, 0, sizeof(templ)); + templ.width0 = width; + templ.height0 = height; + templ.format = format; + templ.tex_usage = tex_usage; + + /* XXX alignment: we can't do anything about this */ + + tex = wsw->screen->texture_create(wsw->screen, &templ); + if (!tex) + return NULL; + + return wsw_dt_wrap_texture(wsw, tex, stride); +} + +static struct sw_displaytarget * +wsw_dt_from_handle(struct sw_winsys *ws, + const struct pipe_texture *templ, + struct winsys_handle *whandle, + unsigned *stride) +{ + struct wrapper_sw_winsys *wsw = wrapper_sw_winsys(ws); + struct pipe_texture *tex; + + tex = wsw->screen->texture_from_handle(wsw->screen, templ, whandle); + if (!tex) + return NULL; + + return wsw_dt_wrap_texture(wsw, tex, stride); +} + +static void * +wsw_dt_map(struct sw_winsys *ws, + struct sw_displaytarget *dt, + unsigned flags) +{ + struct wrapper_sw_displaytarget *wdt = wrapper_sw_displaytarget(dt); + struct pipe_context *pipe = wdt->winsys->pipe; + struct pipe_texture *tex = wdt->tex; + struct pipe_transfer *tr; + void *ptr; + + if (!wdt->map_count) { + + assert(!wdt->transfer); + + tr = pipe->get_tex_transfer(pipe, tex, 0, 0, 0, + PIPE_TRANSFER_READ_WRITE, + 0, 0, wdt->width, wdt->height); + if (!tr) + return NULL; + + ptr = pipe->transfer_map(pipe, tr); + if (!ptr) + goto err; + + wdt->transfer = tr; + wdt->ptr = ptr; + + /* XXX Handle this case */ + assert(tr->stride == wdt->stride); + } + + wdt->map_count++; + + return wdt->ptr; + +err: + pipe->tex_transfer_destroy(pipe, tr); + return NULL; +} + +static void +wsw_dt_unmap(struct sw_winsys *ws, + struct sw_displaytarget *dt) +{ + struct wrapper_sw_displaytarget *wdt = wrapper_sw_displaytarget(dt); + struct pipe_context *pipe = wdt->winsys->pipe; + + assert(wdt->transfer); + + wdt->map_count--; + + if (wdt->map_count) + return; + + pipe->transfer_unmap(pipe, wdt->transfer); + pipe->tex_transfer_destroy(pipe, wdt->transfer); + wdt->transfer = NULL; +} + +static void +wsw_dt_destroy(struct sw_winsys *ws, + struct sw_displaytarget *dt) +{ + struct wrapper_sw_displaytarget *wdt = wrapper_sw_displaytarget(dt); + + pipe_texture_reference(&wdt->tex, NULL); + + FREE(wdt); +} + +static void +wsw_destroy(struct sw_winsys *ws) +{ + struct wrapper_sw_winsys *wsw = wrapper_sw_winsys(ws); + + wsw->pipe->destroy(wsw->pipe); + wsw->screen->destroy(wsw->screen); + + FREE(wsw); +} + +struct sw_winsys * +wrapper_sw_winsys_warp_pipe_screen(struct pipe_screen *screen) +{ + struct wrapper_sw_winsys *wsw = CALLOC_STRUCT(wrapper_sw_winsys); + + wsw->base.displaytarget_create = wsw_dt_create; + wsw->base.displaytarget_from_handle = wsw_dt_from_handle; + wsw->base.displaytarget_map = wsw_dt_map; + wsw->base.displaytarget_unmap = wsw_dt_unmap; + wsw->base.displaytarget_destroy = wsw_dt_destroy; + wsw->base.destroy = wsw_destroy; + + wsw->screen = screen; + wsw->pipe = screen->context_create(screen, NULL); + if (!wsw->pipe) + goto err; + + return &wsw->base; + +err: + FREE(wsw); + return NULL; +} diff --git a/src/gallium/winsys/sw/wrapper/wrapper_sw_winsys.h b/src/gallium/winsys/sw/wrapper/wrapper_sw_winsys.h new file mode 100644 index 00000000000..b5c25a3c50f --- /dev/null +++ b/src/gallium/winsys/sw/wrapper/wrapper_sw_winsys.h @@ -0,0 +1,35 @@ +/********************************************************** + * Copyright 2010 VMware, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + **********************************************************/ + + +#ifndef WRAPPER_SW_WINSYS +#define WRAPPER_SW_WINSYS + +struct sw_winsys; +struct pipe_screen; + +struct sw_winsys *wrapper_sw_winsys_warp_pipe_screen(struct pipe_screen *screen); + +#endif diff --git a/src/gallium/winsys/sw/xlib/Makefile b/src/gallium/winsys/sw/xlib/Makefile new file mode 100644 index 00000000000..c6693899281 --- /dev/null +++ b/src/gallium/winsys/sw/xlib/Makefile @@ -0,0 +1,17 @@ +TOP = ../../../../.. +include $(TOP)/configs/current + +LIBNAME = ws_xlib + +LIBRARY_INCLUDES = \ + -I$(TOP)/src/gallium/include \ + -I$(TOP)/src/gallium/drivers \ + -I$(TOP)/src/gallium/auxiliary \ + $(X11_CFLAGS) + +C_SOURCES = \ + xlib_sw_winsys.c + +include ../../../Makefile.template + + diff --git a/src/gallium/winsys/sw/xlib/SConscript b/src/gallium/winsys/sw/xlib/SConscript new file mode 100644 index 00000000000..2af6153b4c7 --- /dev/null +++ b/src/gallium/winsys/sw/xlib/SConscript @@ -0,0 +1,23 @@ +####################################################################### +# SConscript for xlib winsys + + +Import('*') + +if env['platform'] == 'linux': + + env = env.Clone() + + env.Append(CPPPATH = [ + '#/src/gallium/include', + '#/src/gallium/auxiliary', + '#/src/gallium/drivers', + ]) + + ws_xlib = env.ConvenienceLibrary( + target = 'ws_xlib', + source = [ + 'xlib_sw_winsys.c', + ] + ) + Export('ws_xlib') diff --git a/src/gallium/winsys/sw/xlib/xlib_sw_winsys.c b/src/gallium/winsys/sw/xlib/xlib_sw_winsys.c new file mode 100644 index 00000000000..54789d7a87c --- /dev/null +++ b/src/gallium/winsys/sw/xlib/xlib_sw_winsys.c @@ -0,0 +1,464 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Bismarck, ND., USA + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * + **************************************************************************/ + +/* + * Authors: + * Keith Whitwell + * Brian Paul + */ + +#include "pipe/p_format.h" +#include "pipe/p_context.h" +#include "util/u_inlines.h" +#include "util/u_format.h" +#include "util/u_math.h" +#include "util/u_memory.h" + +#include "state_tracker/xlib_sw_winsys.h" + +#include +#include +#include +#include +#include +#include + +/** + * Subclass of pipe_buffer for Xlib winsys. + * Low-level OS/window system memory buffer + */ +struct xm_displaytarget +{ + enum pipe_format format; + unsigned width; + unsigned height; + unsigned stride; + + void *data; + void *mapped; + + Display *display; + Visual *visual; + XImage *tempImage; + GC gc; + + /* This is the last drawable that this display target was presented + * against. May need to recreate gc, tempImage when this changes?? + */ + Drawable drawable; + + XShmSegmentInfo shminfo; + int shm; +}; + + +/** + * Subclass of sw_winsys for Xlib winsys + */ +struct xlib_sw_winsys +{ + struct sw_winsys base; + + + + Display *display; +}; + + + +/** Cast wrapper */ +static INLINE struct xm_displaytarget * +xm_displaytarget( struct sw_displaytarget *dt ) +{ + return (struct xm_displaytarget *)dt; +} + + +/** + * X Shared Memory Image extension code + */ + +static volatile int mesaXErrorFlag = 0; + +/** + * Catches potential Xlib errors. + */ +static int +mesaHandleXError(Display *dpy, XErrorEvent *event) +{ + (void) dpy; + (void) event; + mesaXErrorFlag = 1; + return 0; +} + + +static char *alloc_shm(struct xm_displaytarget *buf, unsigned size) +{ + XShmSegmentInfo *const shminfo = & buf->shminfo; + + shminfo->shmid = shmget(IPC_PRIVATE, size, IPC_CREAT|0777); + if (shminfo->shmid < 0) { + return NULL; + } + + shminfo->shmaddr = (char *) shmat(shminfo->shmid, 0, 0); + if (shminfo->shmaddr == (char *) -1) { + shmctl(shminfo->shmid, IPC_RMID, 0); + return NULL; + } + + shminfo->readOnly = False; + return shminfo->shmaddr; +} + + +/** + * Allocate a shared memory XImage back buffer for the given XMesaBuffer. + */ +static void +alloc_shm_ximage(struct xm_displaytarget *xm_dt, + struct xlib_drawable *xmb, + unsigned width, unsigned height) +{ + /* + * We have to do a _lot_ of error checking here to be sure we can + * really use the XSHM extension. It seems different servers trigger + * errors at different points if the extension won't work. Therefore + * we have to be very careful... + */ + int (*old_handler)(Display *, XErrorEvent *); + + xm_dt->tempImage = XShmCreateImage(xm_dt->display, + xmb->visual, + xmb->depth, + ZPixmap, + NULL, + &xm_dt->shminfo, + width, height); + if (xm_dt->tempImage == NULL) { + xm_dt->shm = 0; + return; + } + + + mesaXErrorFlag = 0; + old_handler = XSetErrorHandler(mesaHandleXError); + /* This may trigger the X protocol error we're ready to catch: */ + XShmAttach(xm_dt->display, &xm_dt->shminfo); + XSync(xm_dt->display, False); + + if (mesaXErrorFlag) { + /* we are on a remote display, this error is normal, don't print it */ + XFlush(xm_dt->display); + mesaXErrorFlag = 0; + XDestroyImage(xm_dt->tempImage); + xm_dt->tempImage = NULL; + xm_dt->shm = 0; + (void) XSetErrorHandler(old_handler); + return; + } + + xm_dt->shm = 1; +} + + +static void +alloc_ximage(struct xm_displaytarget *xm_dt, + struct xlib_drawable *xmb, + unsigned width, unsigned height) +{ + if (xm_dt->shm) { + alloc_shm_ximage(xm_dt, xmb, width, height); + return; + } + + xm_dt->tempImage = XCreateImage(xm_dt->display, + xmb->visual, + xmb->depth, + ZPixmap, 0, + NULL, width, height, + 8, 0); +} + +static boolean +xm_is_displaytarget_format_supported( struct sw_winsys *ws, + unsigned tex_usage, + enum pipe_format format ) +{ + /* TODO: check visuals or other sensible thing here */ + return TRUE; +} + + +static void * +xm_displaytarget_map(struct sw_winsys *ws, + struct sw_displaytarget *dt, + unsigned flags) +{ + struct xm_displaytarget *xm_dt = xm_displaytarget(dt); + xm_dt->mapped = xm_dt->data; + return xm_dt->mapped; +} + +static void +xm_displaytarget_unmap(struct sw_winsys *ws, + struct sw_displaytarget *dt) +{ + struct xm_displaytarget *xm_dt = xm_displaytarget(dt); + xm_dt->mapped = NULL; +} + +static void +xm_displaytarget_destroy(struct sw_winsys *ws, + struct sw_displaytarget *dt) +{ + struct xm_displaytarget *xm_dt = xm_displaytarget(dt); + + if (xm_dt->data) { + if (xm_dt->shminfo.shmid >= 0) { + shmdt(xm_dt->shminfo.shmaddr); + shmctl(xm_dt->shminfo.shmid, IPC_RMID, 0); + + xm_dt->shminfo.shmid = -1; + xm_dt->shminfo.shmaddr = (char *) -1; + } + else { + FREE(xm_dt->data); + } + } + + if (xm_dt->tempImage) + XDestroyImage(xm_dt->tempImage); + + if (xm_dt->gc) + XFreeGC(xm_dt->display, xm_dt->gc); + + FREE(xm_dt); +} + + +/** + * Display/copy the image in the surface into the X window specified + * by the XMesaBuffer. + */ +static void +xlib_sw_display(struct xlib_drawable *xlib_drawable, + struct sw_displaytarget *dt) +{ + static boolean no_swap = 0; + static boolean firsttime = 1; + struct xm_displaytarget *xm_dt = xm_displaytarget(dt); + Display *display = xm_dt->display; + XImage *ximage; + + if (firsttime) { + no_swap = getenv("SP_NO_RAST") != NULL; + firsttime = 0; + } + + if (no_swap) + return; + + if (xm_dt->drawable != xlib_drawable->drawable) { + if (xm_dt->gc) { + XFreeGC( display, xm_dt->gc ); + xm_dt->gc = NULL; + } + + if (xm_dt->tempImage) { + XDestroyImage( xm_dt->tempImage ); + xm_dt->tempImage = NULL; + } + + xm_dt->drawable = xlib_drawable->drawable; + } + + if (xm_dt->tempImage == NULL) { + assert(util_format_get_blockwidth(xm_dt->format) == 1); + assert(util_format_get_blockheight(xm_dt->format) == 1); + alloc_ximage(xm_dt, xlib_drawable, + xm_dt->stride / util_format_get_blocksize(xm_dt->format), + xm_dt->height); + if (!xm_dt->tempImage) + return; + } + + if (xm_dt->gc == NULL) { + xm_dt->gc = XCreateGC( display, xlib_drawable->drawable, 0, NULL ); + XSetFunction( display, xm_dt->gc, GXcopy ); + } + + if (xm_dt->shm) + { + ximage = xm_dt->tempImage; + ximage->data = xm_dt->data; + + /* _debug_printf("XSHM\n"); */ + XShmPutImage(xm_dt->display, xlib_drawable->drawable, xm_dt->gc, + ximage, 0, 0, 0, 0, xm_dt->width, xm_dt->height, False); + } + else { + /* display image in Window */ + ximage = xm_dt->tempImage; + ximage->data = xm_dt->data; + + /* check that the XImage has been previously initialized */ + assert(ximage->format); + assert(ximage->bitmap_unit); + + /* update XImage's fields */ + ximage->width = xm_dt->width; + ximage->height = xm_dt->height; + ximage->bytes_per_line = xm_dt->stride; + + /* _debug_printf("XPUT\n"); */ + XPutImage(xm_dt->display, xlib_drawable->drawable, xm_dt->gc, + ximage, 0, 0, 0, 0, xm_dt->width, xm_dt->height); + } +} + +/** + * Display/copy the image in the surface into the X window specified + * by the XMesaBuffer. + */ +static void +xm_displaytarget_display(struct sw_winsys *ws, + struct sw_displaytarget *dt, + void *context_private) +{ + struct xlib_drawable *xlib_drawable = (struct xlib_drawable *)context_private; + xlib_sw_display(xlib_drawable, dt); +} + + +static struct sw_displaytarget * +xm_displaytarget_create(struct sw_winsys *winsys, + unsigned tex_usage, + enum pipe_format format, + unsigned width, unsigned height, + unsigned alignment, + unsigned *stride) +{ + struct xm_displaytarget *xm_dt; + unsigned nblocksy, size; + + xm_dt = CALLOC_STRUCT(xm_displaytarget); + if(!xm_dt) + goto no_xm_dt; + + xm_dt->display = ((struct xlib_sw_winsys *)winsys)->display; + xm_dt->format = format; + xm_dt->width = width; + xm_dt->height = height; + + nblocksy = util_format_get_nblocksy(format, height); + xm_dt->stride = align(util_format_get_stride(format, width), alignment); + size = xm_dt->stride * nblocksy; + + if (!debug_get_bool_option("XLIB_NO_SHM", FALSE)) + { + xm_dt->shminfo.shmid = -1; + xm_dt->shminfo.shmaddr = (char *) -1; + xm_dt->shm = TRUE; + + xm_dt->data = alloc_shm(xm_dt, size); + if(!xm_dt->data) + goto no_data; + } + + if(!xm_dt->data) { + xm_dt->data = align_malloc(size, alignment); + if(!xm_dt->data) + goto no_data; + } + + *stride = xm_dt->stride; + return (struct sw_displaytarget *)xm_dt; + +no_data: + FREE(xm_dt); +no_xm_dt: + return NULL; +} + + +static struct sw_displaytarget * +xm_displaytarget_from_handle(struct sw_winsys *winsys, + const struct pipe_texture *templet, + struct winsys_handle *whandle, + unsigned *stride) +{ + assert(0); + return NULL; +} + + +static boolean +xm_displaytarget_get_handle(struct sw_winsys *winsys, + struct sw_displaytarget *dt, + struct winsys_handle *whandle) +{ + assert(0); + return FALSE; +} + + +static void +xm_destroy( struct sw_winsys *ws ) +{ + FREE(ws); +} + + +struct sw_winsys * +xlib_create_sw_winsys( Display *display ) +{ + struct xlib_sw_winsys *ws; + + ws = CALLOC_STRUCT(xlib_sw_winsys); + if (!ws) + return NULL; + + ws->display = display; + ws->base.destroy = xm_destroy; + + ws->base.is_displaytarget_format_supported = xm_is_displaytarget_format_supported; + + ws->base.displaytarget_create = xm_displaytarget_create; + ws->base.displaytarget_from_handle = xm_displaytarget_from_handle; + ws->base.displaytarget_get_handle = xm_displaytarget_get_handle; + ws->base.displaytarget_map = xm_displaytarget_map; + ws->base.displaytarget_unmap = xm_displaytarget_unmap; + ws->base.displaytarget_destroy = xm_displaytarget_destroy; + + ws->base.displaytarget_display = xm_displaytarget_display; + + return &ws->base; +} + diff --git a/src/gallium/winsys/xlib/Makefile b/src/gallium/winsys/xlib/Makefile deleted file mode 100644 index 83d53c59542..00000000000 --- a/src/gallium/winsys/xlib/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -TOP = ../../../.. -include $(TOP)/configs/current - -LIBNAME = ws_xlib - -LIBRARY_INCLUDES = \ - -I$(TOP)/src/gallium/include \ - -I$(TOP)/src/gallium/drivers \ - -I$(TOP)/src/gallium/auxiliary \ - $(X11_CFLAGS) - -C_SOURCES = \ - xlib_sw_winsys.c - -include ../../Makefile.template - - diff --git a/src/gallium/winsys/xlib/SConscript b/src/gallium/winsys/xlib/SConscript deleted file mode 100644 index 2af6153b4c7..00000000000 --- a/src/gallium/winsys/xlib/SConscript +++ /dev/null @@ -1,23 +0,0 @@ -####################################################################### -# SConscript for xlib winsys - - -Import('*') - -if env['platform'] == 'linux': - - env = env.Clone() - - env.Append(CPPPATH = [ - '#/src/gallium/include', - '#/src/gallium/auxiliary', - '#/src/gallium/drivers', - ]) - - ws_xlib = env.ConvenienceLibrary( - target = 'ws_xlib', - source = [ - 'xlib_sw_winsys.c', - ] - ) - Export('ws_xlib') diff --git a/src/gallium/winsys/xlib/xlib_sw_winsys.c b/src/gallium/winsys/xlib/xlib_sw_winsys.c deleted file mode 100644 index 54789d7a87c..00000000000 --- a/src/gallium/winsys/xlib/xlib_sw_winsys.c +++ /dev/null @@ -1,464 +0,0 @@ -/************************************************************************** - * - * Copyright 2007 Tungsten Graphics, Inc., Bismarck, ND., USA - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL - * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE - * USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * - **************************************************************************/ - -/* - * Authors: - * Keith Whitwell - * Brian Paul - */ - -#include "pipe/p_format.h" -#include "pipe/p_context.h" -#include "util/u_inlines.h" -#include "util/u_format.h" -#include "util/u_math.h" -#include "util/u_memory.h" - -#include "state_tracker/xlib_sw_winsys.h" - -#include -#include -#include -#include -#include -#include - -/** - * Subclass of pipe_buffer for Xlib winsys. - * Low-level OS/window system memory buffer - */ -struct xm_displaytarget -{ - enum pipe_format format; - unsigned width; - unsigned height; - unsigned stride; - - void *data; - void *mapped; - - Display *display; - Visual *visual; - XImage *tempImage; - GC gc; - - /* This is the last drawable that this display target was presented - * against. May need to recreate gc, tempImage when this changes?? - */ - Drawable drawable; - - XShmSegmentInfo shminfo; - int shm; -}; - - -/** - * Subclass of sw_winsys for Xlib winsys - */ -struct xlib_sw_winsys -{ - struct sw_winsys base; - - - - Display *display; -}; - - - -/** Cast wrapper */ -static INLINE struct xm_displaytarget * -xm_displaytarget( struct sw_displaytarget *dt ) -{ - return (struct xm_displaytarget *)dt; -} - - -/** - * X Shared Memory Image extension code - */ - -static volatile int mesaXErrorFlag = 0; - -/** - * Catches potential Xlib errors. - */ -static int -mesaHandleXError(Display *dpy, XErrorEvent *event) -{ - (void) dpy; - (void) event; - mesaXErrorFlag = 1; - return 0; -} - - -static char *alloc_shm(struct xm_displaytarget *buf, unsigned size) -{ - XShmSegmentInfo *const shminfo = & buf->shminfo; - - shminfo->shmid = shmget(IPC_PRIVATE, size, IPC_CREAT|0777); - if (shminfo->shmid < 0) { - return NULL; - } - - shminfo->shmaddr = (char *) shmat(shminfo->shmid, 0, 0); - if (shminfo->shmaddr == (char *) -1) { - shmctl(shminfo->shmid, IPC_RMID, 0); - return NULL; - } - - shminfo->readOnly = False; - return shminfo->shmaddr; -} - - -/** - * Allocate a shared memory XImage back buffer for the given XMesaBuffer. - */ -static void -alloc_shm_ximage(struct xm_displaytarget *xm_dt, - struct xlib_drawable *xmb, - unsigned width, unsigned height) -{ - /* - * We have to do a _lot_ of error checking here to be sure we can - * really use the XSHM extension. It seems different servers trigger - * errors at different points if the extension won't work. Therefore - * we have to be very careful... - */ - int (*old_handler)(Display *, XErrorEvent *); - - xm_dt->tempImage = XShmCreateImage(xm_dt->display, - xmb->visual, - xmb->depth, - ZPixmap, - NULL, - &xm_dt->shminfo, - width, height); - if (xm_dt->tempImage == NULL) { - xm_dt->shm = 0; - return; - } - - - mesaXErrorFlag = 0; - old_handler = XSetErrorHandler(mesaHandleXError); - /* This may trigger the X protocol error we're ready to catch: */ - XShmAttach(xm_dt->display, &xm_dt->shminfo); - XSync(xm_dt->display, False); - - if (mesaXErrorFlag) { - /* we are on a remote display, this error is normal, don't print it */ - XFlush(xm_dt->display); - mesaXErrorFlag = 0; - XDestroyImage(xm_dt->tempImage); - xm_dt->tempImage = NULL; - xm_dt->shm = 0; - (void) XSetErrorHandler(old_handler); - return; - } - - xm_dt->shm = 1; -} - - -static void -alloc_ximage(struct xm_displaytarget *xm_dt, - struct xlib_drawable *xmb, - unsigned width, unsigned height) -{ - if (xm_dt->shm) { - alloc_shm_ximage(xm_dt, xmb, width, height); - return; - } - - xm_dt->tempImage = XCreateImage(xm_dt->display, - xmb->visual, - xmb->depth, - ZPixmap, 0, - NULL, width, height, - 8, 0); -} - -static boolean -xm_is_displaytarget_format_supported( struct sw_winsys *ws, - unsigned tex_usage, - enum pipe_format format ) -{ - /* TODO: check visuals or other sensible thing here */ - return TRUE; -} - - -static void * -xm_displaytarget_map(struct sw_winsys *ws, - struct sw_displaytarget *dt, - unsigned flags) -{ - struct xm_displaytarget *xm_dt = xm_displaytarget(dt); - xm_dt->mapped = xm_dt->data; - return xm_dt->mapped; -} - -static void -xm_displaytarget_unmap(struct sw_winsys *ws, - struct sw_displaytarget *dt) -{ - struct xm_displaytarget *xm_dt = xm_displaytarget(dt); - xm_dt->mapped = NULL; -} - -static void -xm_displaytarget_destroy(struct sw_winsys *ws, - struct sw_displaytarget *dt) -{ - struct xm_displaytarget *xm_dt = xm_displaytarget(dt); - - if (xm_dt->data) { - if (xm_dt->shminfo.shmid >= 0) { - shmdt(xm_dt->shminfo.shmaddr); - shmctl(xm_dt->shminfo.shmid, IPC_RMID, 0); - - xm_dt->shminfo.shmid = -1; - xm_dt->shminfo.shmaddr = (char *) -1; - } - else { - FREE(xm_dt->data); - } - } - - if (xm_dt->tempImage) - XDestroyImage(xm_dt->tempImage); - - if (xm_dt->gc) - XFreeGC(xm_dt->display, xm_dt->gc); - - FREE(xm_dt); -} - - -/** - * Display/copy the image in the surface into the X window specified - * by the XMesaBuffer. - */ -static void -xlib_sw_display(struct xlib_drawable *xlib_drawable, - struct sw_displaytarget *dt) -{ - static boolean no_swap = 0; - static boolean firsttime = 1; - struct xm_displaytarget *xm_dt = xm_displaytarget(dt); - Display *display = xm_dt->display; - XImage *ximage; - - if (firsttime) { - no_swap = getenv("SP_NO_RAST") != NULL; - firsttime = 0; - } - - if (no_swap) - return; - - if (xm_dt->drawable != xlib_drawable->drawable) { - if (xm_dt->gc) { - XFreeGC( display, xm_dt->gc ); - xm_dt->gc = NULL; - } - - if (xm_dt->tempImage) { - XDestroyImage( xm_dt->tempImage ); - xm_dt->tempImage = NULL; - } - - xm_dt->drawable = xlib_drawable->drawable; - } - - if (xm_dt->tempImage == NULL) { - assert(util_format_get_blockwidth(xm_dt->format) == 1); - assert(util_format_get_blockheight(xm_dt->format) == 1); - alloc_ximage(xm_dt, xlib_drawable, - xm_dt->stride / util_format_get_blocksize(xm_dt->format), - xm_dt->height); - if (!xm_dt->tempImage) - return; - } - - if (xm_dt->gc == NULL) { - xm_dt->gc = XCreateGC( display, xlib_drawable->drawable, 0, NULL ); - XSetFunction( display, xm_dt->gc, GXcopy ); - } - - if (xm_dt->shm) - { - ximage = xm_dt->tempImage; - ximage->data = xm_dt->data; - - /* _debug_printf("XSHM\n"); */ - XShmPutImage(xm_dt->display, xlib_drawable->drawable, xm_dt->gc, - ximage, 0, 0, 0, 0, xm_dt->width, xm_dt->height, False); - } - else { - /* display image in Window */ - ximage = xm_dt->tempImage; - ximage->data = xm_dt->data; - - /* check that the XImage has been previously initialized */ - assert(ximage->format); - assert(ximage->bitmap_unit); - - /* update XImage's fields */ - ximage->width = xm_dt->width; - ximage->height = xm_dt->height; - ximage->bytes_per_line = xm_dt->stride; - - /* _debug_printf("XPUT\n"); */ - XPutImage(xm_dt->display, xlib_drawable->drawable, xm_dt->gc, - ximage, 0, 0, 0, 0, xm_dt->width, xm_dt->height); - } -} - -/** - * Display/copy the image in the surface into the X window specified - * by the XMesaBuffer. - */ -static void -xm_displaytarget_display(struct sw_winsys *ws, - struct sw_displaytarget *dt, - void *context_private) -{ - struct xlib_drawable *xlib_drawable = (struct xlib_drawable *)context_private; - xlib_sw_display(xlib_drawable, dt); -} - - -static struct sw_displaytarget * -xm_displaytarget_create(struct sw_winsys *winsys, - unsigned tex_usage, - enum pipe_format format, - unsigned width, unsigned height, - unsigned alignment, - unsigned *stride) -{ - struct xm_displaytarget *xm_dt; - unsigned nblocksy, size; - - xm_dt = CALLOC_STRUCT(xm_displaytarget); - if(!xm_dt) - goto no_xm_dt; - - xm_dt->display = ((struct xlib_sw_winsys *)winsys)->display; - xm_dt->format = format; - xm_dt->width = width; - xm_dt->height = height; - - nblocksy = util_format_get_nblocksy(format, height); - xm_dt->stride = align(util_format_get_stride(format, width), alignment); - size = xm_dt->stride * nblocksy; - - if (!debug_get_bool_option("XLIB_NO_SHM", FALSE)) - { - xm_dt->shminfo.shmid = -1; - xm_dt->shminfo.shmaddr = (char *) -1; - xm_dt->shm = TRUE; - - xm_dt->data = alloc_shm(xm_dt, size); - if(!xm_dt->data) - goto no_data; - } - - if(!xm_dt->data) { - xm_dt->data = align_malloc(size, alignment); - if(!xm_dt->data) - goto no_data; - } - - *stride = xm_dt->stride; - return (struct sw_displaytarget *)xm_dt; - -no_data: - FREE(xm_dt); -no_xm_dt: - return NULL; -} - - -static struct sw_displaytarget * -xm_displaytarget_from_handle(struct sw_winsys *winsys, - const struct pipe_texture *templet, - struct winsys_handle *whandle, - unsigned *stride) -{ - assert(0); - return NULL; -} - - -static boolean -xm_displaytarget_get_handle(struct sw_winsys *winsys, - struct sw_displaytarget *dt, - struct winsys_handle *whandle) -{ - assert(0); - return FALSE; -} - - -static void -xm_destroy( struct sw_winsys *ws ) -{ - FREE(ws); -} - - -struct sw_winsys * -xlib_create_sw_winsys( Display *display ) -{ - struct xlib_sw_winsys *ws; - - ws = CALLOC_STRUCT(xlib_sw_winsys); - if (!ws) - return NULL; - - ws->display = display; - ws->base.destroy = xm_destroy; - - ws->base.is_displaytarget_format_supported = xm_is_displaytarget_format_supported; - - ws->base.displaytarget_create = xm_displaytarget_create; - ws->base.displaytarget_from_handle = xm_displaytarget_from_handle; - ws->base.displaytarget_get_handle = xm_displaytarget_get_handle; - ws->base.displaytarget_map = xm_displaytarget_map; - ws->base.displaytarget_unmap = xm_displaytarget_unmap; - ws->base.displaytarget_destroy = xm_displaytarget_destroy; - - ws->base.displaytarget_display = xm_displaytarget_display; - - return &ws->base; -} - -- cgit v1.2.3 From 42a1bcc22f0ed84faa51dafe9e61703e02e93eba Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Wed, 24 Mar 2010 18:09:19 +0100 Subject: radeong: Fix scons build --- src/gallium/winsys/radeon/drm/SConscript | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/gallium') diff --git a/src/gallium/winsys/radeon/drm/SConscript b/src/gallium/winsys/radeon/drm/SConscript index f4e9c397bdf..19e895f10b9 100644 --- a/src/gallium/winsys/radeon/drm/SConscript +++ b/src/gallium/winsys/radeon/drm/SConscript @@ -3,7 +3,7 @@ Import('*') env = drienv.Clone() radeon_sources = [ - 'radeon_buffer.c', + 'radeon_drm_buffer.c', 'radeon_drm.c', 'radeon_r300.c', ] -- cgit v1.2.3 From 738850e52260a76ffee57e22193b21126d6d39a1 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Wed, 24 Mar 2010 18:42:35 +0100 Subject: gallium: Make scons build dri/xorg drivers again --- src/gallium/targets/SConscript | 68 ++++++++++++++++++++++++++++ src/gallium/targets/dri-vmwgfx/SConscript | 75 +++++++------------------------ src/gallium/winsys/SConscript | 21 +++++++++ src/gallium/winsys/i915/drm/SConscript | 2 +- src/gallium/winsys/i965/drm/SConscript | 2 +- src/gallium/winsys/radeon/drm/SConscript | 2 +- 6 files changed, 108 insertions(+), 62 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/targets/SConscript b/src/gallium/targets/SConscript index df62fc65fb7..38645646883 100644 --- a/src/gallium/targets/SConscript +++ b/src/gallium/targets/SConscript @@ -14,3 +14,71 @@ if 'gdi' in env['winsys']: SConscript([ 'libgl-gdi/SConscript', ]) + +if env['dri']: + drienv = env.Clone() + + drienv.Replace(CPPPATH = [ + '#src/mesa/drivers/dri/common', + '#include', + '#include/GL/internal', + '#src/gallium/include', + '#src/gallium/auxiliary', + '#src/gallium/drivers', + '#src/mesa', + '#src/mesa/main', + '#src/mesa/glapi', + '#src/mesa/math', + '#src/mesa/transform', + '#src/mesa/shader', + '#src/mesa/swrast', + '#src/mesa/swrast_setup', + '#src/egl/main', + '#src/egl/drivers/dri', + ]) + + drienv.ParseConfig('pkg-config --cflags --libs libdrm') + + COMMON_GALLIUM_SOURCES = [ + '#src/mesa/drivers/dri/common/utils.c', + '#src/mesa/drivers/dri/common/vblank.c', + '#src/mesa/drivers/dri/common/dri_util.c', + '#src/mesa/drivers/dri/common/xmlconfig.c', + ] + + COMMON_BM_SOURCES = [ + '#src/mesa/drivers/dri/common/dri_bufmgr.c', + '#src/mesa/drivers/dri/common/dri_drmpool.c', + ] + + Export([ + 'drienv', + 'COMMON_GALLIUM_SOURCES', + 'COMMON_BM_SOURCES', + ]) + + if 'vmware' in env['winsys']: + SConscript([ + 'dri-vmwgfx/SConscript', + ]) + + if 'intel' in env['winsys']: + SConscript([ + 'dri-i915/SConscript', + ]) + + if 'i965' in env['winsys']: + SConscript([ + 'dri-i965/SConscript', + ]) + + if 'radeon' in env['winsys']: + SConscript([ + 'dri-radeong/SConscript', + ]) + +if 'xorg' in env['statetrackers']: + if 'vmware' in env['winsys']: + SConscript([ + 'xorg-vmwgfx/SConscript', + ]) diff --git a/src/gallium/targets/dri-vmwgfx/SConscript b/src/gallium/targets/dri-vmwgfx/SConscript index d26d0cd7483..4437916c293 100644 --- a/src/gallium/targets/dri-vmwgfx/SConscript +++ b/src/gallium/targets/dri-vmwgfx/SConscript @@ -1,63 +1,20 @@ -import os -import os.path - Import('*') -if env['platform'] == 'linux': - - if env['dri']: - env = env.Clone() - - sources = [ - '#/src/mesa/drivers/dri/common/utils.c', - '#/src/mesa/drivers/dri/common/vblank.c', - '#/src/mesa/drivers/dri/common/dri_util.c', - '#/src/mesa/drivers/dri/common/xmlconfig.c', - ] - - - env.ParseConfig('pkg-config --cflags --libs libdrm') - - env.Prepend(CPPPATH = [ - '#/src/mesa/state_tracker', - '#/src/mesa/drivers/dri/common', - '#/src/mesa/main', - '#/src/mesa/glapi', - '#/src/mesa', - '#/include', - '#/src/gallium/drivers/svga', - '#/src/gallium/drivers/svga/include', - ]) - - env.Append(CPPDEFINES = [ - 'HAVE_STDINT_H', - 'HAVE_SYS_TYPES_H', - ]) +env = drienv.Clone() - env.Append(CFLAGS = [ - '-std=gnu99', - '-D_FILE_OFFSET_BITS=64', - ]) - - env.Prepend(LIBPATH = [ - ]) - - env.Prepend(LIBS = [ - trace, - st_dri, - svgadrm, - svga, - mesa, - glsl, - gallium, - ]) - - # TODO: write a wrapper function http://www.scons.org/wiki/WrapperFunctions - env.LoadableModule( - target ='vmwgfx_dri.so', - source = sources, - LIBS = env['LIBS'], - SHLIBPREFIX = '', - ) - +drivers = [ + trace, + st_dri, + svgadrm, + svga, + mesa, + glsl, + gallium, +] +env.LoadableModule( + target ='vmwgfx_dri.so', + source = COMMON_GALLIUM_SOURCES, + LIBS = drivers + mesa + gallium + env['LIBS'], + SHLIBPREFIX = '', +) diff --git a/src/gallium/winsys/SConscript b/src/gallium/winsys/SConscript index 97ea82ea761..90ca693eb68 100644 --- a/src/gallium/winsys/SConscript +++ b/src/gallium/winsys/SConscript @@ -9,3 +9,24 @@ if 'gdi' in env['winsys']: SConscript([ 'sw/gdi/SConscript', ]) + +if env['dri']: + if 'vmware' in env['winsys']: + SConscript([ + 'svga/drm/SConscript', + ]) + + if 'intel' in env['winsys']: + SConscript([ + 'i915/drm/SConscript', + ]) + + if 'i965' in env['winsys']: + SConscript([ + 'i965/drm/SConscript', + ]) + + if 'radeon' in env['winsys']: + SConscript([ + 'radeon/drm/SConscript', + ]) diff --git a/src/gallium/winsys/i915/drm/SConscript b/src/gallium/winsys/i915/drm/SConscript index 26717f391fa..b47b8add837 100644 --- a/src/gallium/winsys/i915/drm/SConscript +++ b/src/gallium/winsys/i915/drm/SConscript @@ -1,6 +1,6 @@ Import('*') -env = drienv.Clone() +env = env.Clone() inteldrm_sources = [ 'intel_drm_api.c', diff --git a/src/gallium/winsys/i965/drm/SConscript b/src/gallium/winsys/i965/drm/SConscript index 6256ec6eaf0..150ab19a33e 100644 --- a/src/gallium/winsys/i965/drm/SConscript +++ b/src/gallium/winsys/i965/drm/SConscript @@ -1,6 +1,6 @@ Import('*') -env = drienv.Clone() +env = env.Clone() i965drm_sources = [ 'i965_drm_api.c', diff --git a/src/gallium/winsys/radeon/drm/SConscript b/src/gallium/winsys/radeon/drm/SConscript index 19e895f10b9..fab42929514 100644 --- a/src/gallium/winsys/radeon/drm/SConscript +++ b/src/gallium/winsys/radeon/drm/SConscript @@ -1,6 +1,6 @@ Import('*') -env = drienv.Clone() +env = env.Clone() radeon_sources = [ 'radeon_drm_buffer.c', -- cgit v1.2.3 From f5ae5b5396ce93d138d6fde5d79e999175dfd63f Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Wed, 24 Mar 2010 19:16:29 +0100 Subject: gallium: Add warnings incase pipe drivers are not built in targets --- src/gallium/targets/dri-i915/SConscript | 4 ++++ src/gallium/targets/dri-i965/SConscript | 4 ++++ src/gallium/targets/dri-radeong/SConscript | 4 ++++ src/gallium/targets/dri-vmwgfx/SConscript | 4 ++++ src/gallium/targets/xorg-vmwgfx/SConscript | 4 ++++ 5 files changed, 20 insertions(+) (limited to 'src/gallium') diff --git a/src/gallium/targets/dri-i915/SConscript b/src/gallium/targets/dri-i915/SConscript index 0df841d8798..8d4ecefbe1b 100644 --- a/src/gallium/targets/dri-i915/SConscript +++ b/src/gallium/targets/dri-i915/SConscript @@ -1,5 +1,9 @@ Import('*') +if not 'i915' in env['drivers']: + print 'warning: i915 pipe driver not built skipping i915_dri.so' + Return() + env = drienv.Clone() env.ParseConfig('pkg-config --cflags --libs libdrm_intel') diff --git a/src/gallium/targets/dri-i965/SConscript b/src/gallium/targets/dri-i965/SConscript index a99533fd245..3b37d8e1af4 100644 --- a/src/gallium/targets/dri-i965/SConscript +++ b/src/gallium/targets/dri-i965/SConscript @@ -1,5 +1,9 @@ Import('*') +if not 'i965' in env['drivers']: + print 'warning: i965 pipe driver not built skipping i965_dri.so' + Return() + env = drienv.Clone() env.ParseConfig('pkg-config --cflags --libs libdrm_intel') diff --git a/src/gallium/targets/dri-radeong/SConscript b/src/gallium/targets/dri-radeong/SConscript index c4989d1b595..bb3b5b9304b 100644 --- a/src/gallium/targets/dri-radeong/SConscript +++ b/src/gallium/targets/dri-radeong/SConscript @@ -1,5 +1,9 @@ Import('*') +if not 'r300' in env['drivers']: + print 'warning: r300 pipe driver not built skipping radeong_dri.so' + Return() + env = drienv.Clone() env.ParseConfig('pkg-config --cflags --libs libdrm_radeon') diff --git a/src/gallium/targets/dri-vmwgfx/SConscript b/src/gallium/targets/dri-vmwgfx/SConscript index 4437916c293..7d248e8a9ce 100644 --- a/src/gallium/targets/dri-vmwgfx/SConscript +++ b/src/gallium/targets/dri-vmwgfx/SConscript @@ -1,5 +1,9 @@ Import('*') +if not 'svga' in env['drivers']: + print 'warning: svga pipe driver not built skipping vmwgfx_dri.so' + Return() + env = drienv.Clone() drivers = [ diff --git a/src/gallium/targets/xorg-vmwgfx/SConscript b/src/gallium/targets/xorg-vmwgfx/SConscript index 1e5d8ff7fed..b63ab99e050 100644 --- a/src/gallium/targets/xorg-vmwgfx/SConscript +++ b/src/gallium/targets/xorg-vmwgfx/SConscript @@ -2,6 +2,10 @@ import os.path Import('*') +if not 'svga' in env['drivers']: + print 'warning: svga pipe driver not built skipping vmwgfx_drv.so' + Return() + if env['platform'] == 'linux': env = env.Clone() -- cgit v1.2.3 From 2ad8692aad0f4ad49643d5f697a036afccdeb9f0 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 24 Mar 2010 16:27:31 -0600 Subject: llvmpipe: fix texture reference counting bug We weren't saving the per-scene texture references at the right point. Fixes piglit cubemap segfault. The segfault resulted from referencing texture memory which was prematurely freed because of a missed reference count. Fixes fd.o bug 27276. --- src/gallium/drivers/llvmpipe/lp_setup.c | 27 +++++++++++++++++++------ src/gallium/drivers/llvmpipe/lp_setup_context.h | 1 + 2 files changed, 22 insertions(+), 6 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/llvmpipe/lp_setup.c b/src/gallium/drivers/llvmpipe/lp_setup.c index fbb0d6f8a60..76a8b87a309 100644 --- a/src/gallium/drivers/llvmpipe/lp_setup.c +++ b/src/gallium/drivers/llvmpipe/lp_setup.c @@ -489,6 +489,12 @@ lp_setup_set_fragment_sampler_views(struct lp_setup_context *setup, jit_tex->height = tex->height0; jit_tex->depth = tex->depth0; jit_tex->last_level = tex->last_level; + + /* We're referencing the texture's internal data, so save a + * reference to it. + */ + pipe_texture_reference(&setup->fs.current_tex[i], tex); + if (!lp_tex->dt) { /* regular texture - setup array of mipmap level pointers */ int j; @@ -511,12 +517,6 @@ lp_setup_set_fragment_sampler_views(struct lp_setup_context *setup, jit_tex->row_stride[0] = lp_tex->stride[0]; assert(jit_tex->data[0]); } - - /* the scene references this texture */ - { - struct lp_scene *scene = lp_setup_get_current_scene(setup); - lp_scene_texture_reference(scene, tex); - } } } @@ -651,6 +651,7 @@ lp_setup_update_state( struct lp_setup_context *setup ) * the new, current state. So allocate a new lp_rast_state object * and append it to the bin's setup data buffer. */ + uint i; struct lp_rast_state *stored = (struct lp_rast_state *) lp_scene_alloc(scene, sizeof *stored); if(stored) { @@ -664,6 +665,14 @@ lp_setup_update_state( struct lp_setup_context *setup ) lp_rast_set_state, lp_rast_arg_state(setup->fs.stored) ); } + + /* The scene now references the textures in the rasterization + * state record. Note that now. + */ + for (i = 0; i < Elements(setup->fs.current_tex); i++) { + if (setup->fs.current_tex[i]) + lp_scene_texture_reference(scene, setup->fs.current_tex[i]); + } } } @@ -679,8 +688,14 @@ lp_setup_update_state( struct lp_setup_context *setup ) void lp_setup_destroy( struct lp_setup_context *setup ) { + uint i; + reset_context( setup ); + for (i = 0; i < Elements(setup->fs.current_tex); i++) { + pipe_texture_reference(&setup->fs.current_tex[i], NULL); + } + pipe_buffer_reference(&setup->constants.current, NULL); /* free the scenes in the 'empty' queue */ diff --git a/src/gallium/drivers/llvmpipe/lp_setup_context.h b/src/gallium/drivers/llvmpipe/lp_setup_context.h index 464fb369840..ca0dafab627 100644 --- a/src/gallium/drivers/llvmpipe/lp_setup_context.h +++ b/src/gallium/drivers/llvmpipe/lp_setup_context.h @@ -111,6 +111,7 @@ struct lp_setup_context const struct lp_rast_state *stored; /**< what's in the scene */ struct lp_rast_state current; /**< currently set state */ + struct pipe_texture *current_tex[PIPE_MAX_SAMPLERS]; } fs; /** fragment shader constants */ -- cgit v1.2.3 From 372011bc892481e61c273a12d9601fd6008751ea Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Thu, 25 Mar 2010 00:27:46 +0100 Subject: st/dri: Fix for X server 1.6.0 (DRI2 version 1) --- src/gallium/state_trackers/dri/dri_st_api.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/dri/dri_st_api.c b/src/gallium/state_trackers/dri/dri_st_api.c index 2cde01967d8..263c1e19a70 100644 --- a/src/gallium/state_trackers/dri/dri_st_api.c +++ b/src/gallium/state_trackers/dri/dri_st_api.c @@ -168,13 +168,18 @@ dri_drawable_get_buffers(struct dri_drawable *drawable, boolean with_format; __DRIbuffer *buffers; int num_buffers; - unsigned attachments[8]; + unsigned attachments[10]; unsigned num_attachments, i; assert(loader); with_format = (loader->base.version > 2 && loader->getBuffersWithFormat); num_attachments = 0; + + /* for Xserver 1.6.0 (DRI2 version 1) we always need to ask for the front */ + if (!with_format) + attachments[num_attachments++] = __DRI_BUFFER_FRONT_LEFT; + for (i = 0; i < *count; i++) { enum pipe_format format; int att; @@ -185,6 +190,9 @@ dri_drawable_get_buffers(struct dri_drawable *drawable, switch (statts[i]) { case ST_ATTACHMENT_FRONT_LEFT: + /* already added */ + if (!with_format) + continue; att = __DRI_BUFFER_FRONT_LEFT; break; case ST_ATTACHMENT_BACK_LEFT: -- cgit v1.2.3 From b4b4ac668116d974522df2ce56e30b74ecdfef77 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Thu, 25 Mar 2010 00:41:21 +0100 Subject: i915g: Correct and add supperted texture formats --- src/gallium/drivers/i915/i915_screen.c | 6 +++++- src/gallium/drivers/i915/i915_state_sampler.c | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/i915/i915_screen.c b/src/gallium/drivers/i915/i915_screen.c index e5bf4a20bd0..48a39edad20 100644 --- a/src/gallium/drivers/i915/i915_screen.c +++ b/src/gallium/drivers/i915/i915_screen.c @@ -165,8 +165,12 @@ i915_is_format_supported(struct pipe_screen *screen, unsigned geom_flags) { static const enum pipe_format tex_supported[] = { - PIPE_FORMAT_A8B8G8R8_UNORM, PIPE_FORMAT_B8G8R8A8_UNORM, + PIPE_FORMAT_B8G8R8X8_UNORM, + PIPE_FORMAT_R8G8B8A8_UNORM, +#if 0 + PIPE_FORMAT_R8G8B8X8_UNORM, +#endif PIPE_FORMAT_B5G6R5_UNORM, PIPE_FORMAT_L8_UNORM, PIPE_FORMAT_A8_UNORM, diff --git a/src/gallium/drivers/i915/i915_state_sampler.c b/src/gallium/drivers/i915/i915_state_sampler.c index d6da8225490..4c326561cb9 100644 --- a/src/gallium/drivers/i915/i915_state_sampler.c +++ b/src/gallium/drivers/i915/i915_state_sampler.c @@ -192,6 +192,14 @@ translate_texture_format(enum pipe_format pipeFormat) return MAPSURF_16BIT | MT_16BIT_ARGB4444; case PIPE_FORMAT_B8G8R8A8_UNORM: return MAPSURF_32BIT | MT_32BIT_ARGB8888; + case PIPE_FORMAT_B8G8R8X8_UNORM: + return MAPSURF_32BIT | MT_32BIT_XRGB8888; + case PIPE_FORMAT_R8G8B8A8_UNORM: + return MAPSURF_32BIT | MT_32BIT_ABGR8888; +#if 0 + case PIPE_FORMAT_R8G8B8X8_UNORM: + return MAPSURF_32BIT | MT_32BIT_XBGR8888; +#endif case PIPE_FORMAT_YUYV: return (MAPSURF_422 | MT_422_YCRCB_NORMAL); case PIPE_FORMAT_UYVY: -- cgit v1.2.3 From 331729c8c877fd8ddde0a83cbe0fcdd5df4b1f1f Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 24 Mar 2010 19:30:27 -0600 Subject: llvmpipe: added lp_fence_signal() --- src/gallium/drivers/llvmpipe/lp_fence.c | 16 ++++++++++++++++ src/gallium/drivers/llvmpipe/lp_fence.h | 4 ++++ 2 files changed, 20 insertions(+) (limited to 'src/gallium') diff --git a/src/gallium/drivers/llvmpipe/lp_fence.c b/src/gallium/drivers/llvmpipe/lp_fence.c index 525c117f316..00dc3eab6b1 100644 --- a/src/gallium/drivers/llvmpipe/lp_fence.c +++ b/src/gallium/drivers/llvmpipe/lp_fence.c @@ -29,6 +29,7 @@ #include "pipe/p_screen.h" #include "util/u_memory.h" #include "util/u_inlines.h" +#include "lp_debug.h" #include "lp_fence.h" @@ -99,6 +100,21 @@ llvmpipe_fence_finish(struct pipe_screen *screen, } +void +lp_fence_signal(struct lp_fence *fence) +{ + pipe_mutex_lock(fence->mutex); + + fence->count++; + assert(fence->count <= fence->rank); + + LP_DBG(DEBUG_RAST, "%s count=%u rank=%u\n", __FUNCTION__, + fence->count, fence->rank); + + pipe_condvar_signal(fence->signalled); + + pipe_mutex_unlock(fence->mutex); +} void diff --git a/src/gallium/drivers/llvmpipe/lp_fence.h b/src/gallium/drivers/llvmpipe/lp_fence.h index c90e6de423b..d9270f5784a 100644 --- a/src/gallium/drivers/llvmpipe/lp_fence.h +++ b/src/gallium/drivers/llvmpipe/lp_fence.h @@ -53,6 +53,10 @@ struct lp_fence * lp_fence_create(unsigned rank); +void +lp_fence_signal(struct lp_fence *fence); + + void llvmpipe_init_screen_fence_funcs(struct pipe_screen *screen); -- cgit v1.2.3 From d7ddb589f49bfd3683650846d9b95835d0abd7ba Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 24 Mar 2010 19:28:41 -0600 Subject: llvmpipe: call lp_fence_signal() --- src/gallium/drivers/llvmpipe/lp_rast.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/llvmpipe/lp_rast.c b/src/gallium/drivers/llvmpipe/lp_rast.c index 3a51800c40d..cd9919ca909 100644 --- a/src/gallium/drivers/llvmpipe/lp_rast.c +++ b/src/gallium/drivers/llvmpipe/lp_rast.c @@ -491,18 +491,7 @@ lp_rast_fence(struct lp_rasterizer_task *task, const union lp_rast_cmd_arg arg) { struct lp_fence *fence = arg.fence; - - pipe_mutex_lock( fence->mutex ); - - fence->count++; - assert(fence->count <= fence->rank); - - LP_DBG(DEBUG_RAST, "%s count=%u rank=%u\n", __FUNCTION__, - fence->count, fence->rank); - - pipe_condvar_signal( fence->signalled ); - - pipe_mutex_unlock( fence->mutex ); + lp_fence_signal(fence); } -- cgit v1.2.3 From a9063cad0f0190ff88cd20fbad5aa87bf1a943f6 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 24 Mar 2010 20:49:12 -0600 Subject: llvmpipe: optimize the lp_setup_fence() function Avoid emitting fences when not needed. Speeds up glReadPixels quite a bit when reading image row by row. --- src/gallium/drivers/llvmpipe/lp_setup.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/llvmpipe/lp_setup.c b/src/gallium/drivers/llvmpipe/lp_setup.c index 76a8b87a309..4eeb98621f6 100644 --- a/src/gallium/drivers/llvmpipe/lp_setup.c +++ b/src/gallium/drivers/llvmpipe/lp_setup.c @@ -318,16 +318,30 @@ lp_setup_fence( struct lp_setup_context *setup ) { struct lp_scene *scene = lp_setup_get_current_scene(setup); const unsigned rank = lp_scene_get_num_bins( scene ); /* xxx */ - struct lp_fence *fence = lp_fence_create(rank); + struct lp_fence *fence; LP_DBG(DEBUG_SETUP, "%s rank %u\n", __FUNCTION__, rank); - set_scene_state( setup, SETUP_ACTIVE ); + if (setup->state == SETUP_FLUSHED) { + /* We're in a flushed state so there's nothing in the bins. + * No need to wait on a fence. + */ + fence = NULL; + } + else { + /* There's material in the bins. Emit the fence into the bins. + * When the rasterizer(s) find the fence, they'll signal on it. + */ + fence = lp_fence_create(rank); + + set_scene_state( setup, SETUP_ACTIVE ); - /* insert the fence into all command bins */ - lp_scene_bin_everywhere( scene, - lp_rast_fence, - lp_rast_arg_fence(fence) ); + /* insert the fence into all command bins */ + lp_scene_bin_everywhere( scene, + lp_rast_fence, + lp_rast_arg_fence(fence) ); + + } return (struct pipe_fence_handle *) fence; } -- cgit v1.2.3 From 9a5241758231b2dd5ae757645158fa33051f5507 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 24 Mar 2010 20:40:31 -0600 Subject: llvmpipe: fix up some questionable fence code Jose should probably review this since he wrote the original code. --- src/gallium/drivers/llvmpipe/lp_flush.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/llvmpipe/lp_flush.c b/src/gallium/drivers/llvmpipe/lp_flush.c index 636d72a9bb8..782669a1e77 100644 --- a/src/gallium/drivers/llvmpipe/lp_flush.c +++ b/src/gallium/drivers/llvmpipe/lp_flush.c @@ -111,7 +111,6 @@ llvmpipe_flush_texture(struct pipe_context *pipe, boolean cpu_access, boolean do_not_flush) { - struct pipe_fence_handle *last_fence = NULL; unsigned referenced; referenced = pipe->is_texture_referenced(pipe, texture, face, level); @@ -142,7 +141,7 @@ llvmpipe_flush_texture(struct pipe_context *pipe, pipe->flush(pipe, flush_flags, &fence); - if (last_fence) { + if (fence) { pipe->screen->fence_finish(pipe->screen, fence, 0); pipe->screen->fence_reference(pipe->screen, &fence, NULL); } -- cgit v1.2.3 From 8b12c58ce41f33108431213725d5d9b9aac8912c Mon Sep 17 00:00:00 2001 From: Vinson Lee Date: Thu, 25 Mar 2010 00:20:05 -0700 Subject: r300g: Remove unnecessary header. --- src/gallium/drivers/r300/r300_context.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/r300/r300_context.c b/src/gallium/drivers/r300/r300_context.c index 2bec946fe89..4433dcff21a 100644 --- a/src/gallium/drivers/r300/r300_context.c +++ b/src/gallium/drivers/r300/r300_context.c @@ -35,7 +35,6 @@ #include "r300_screen.h" #include "r300_screen_buffer.h" #include "r300_state_invariant.h" -#include "r300_texture.h" #include "r300_transfer.h" #include "r300_winsys.h" -- cgit v1.2.3 From 0d0220fedc7a8d490162f7385d19b2d0ab3fb8d9 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Thu, 25 Mar 2010 14:42:40 +0100 Subject: gallium: Fix libgl-xlib path to sw xlib winsys --- src/gallium/targets/libgl-xlib/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/gallium') diff --git a/src/gallium/targets/libgl-xlib/Makefile b/src/gallium/targets/libgl-xlib/Makefile index 5a4e035c2eb..6cd00cad458 100644 --- a/src/gallium/targets/libgl-xlib/Makefile +++ b/src/gallium/targets/libgl-xlib/Makefile @@ -38,7 +38,7 @@ XLIB_TARGET_OBJECTS = $(XLIB_TARGET_SOURCES:.c=.o) LIBS = \ $(GALLIUM_DRIVERS) \ $(TOP)/src/gallium/state_trackers/glx/xlib/libxlib.a \ - $(TOP)/src/gallium/winsys/xlib/libws_xlib.a \ + $(TOP)/src/gallium/winsys/sw/xlib/libws_xlib.a \ $(TOP)/src/gallium/drivers/trace/libtrace.a \ $(TOP)/src/gallium/drivers/identity/libidentity.a \ $(TOP)/src/mesa/libglapi.a \ -- cgit v1.2.3 From 204c88014b8c3cfd7bd84928bbc77489ebd98399 Mon Sep 17 00:00:00 2001 From: Joakim Sindholt Date: Thu, 25 Mar 2010 15:51:23 +0100 Subject: r300g/radeong: fix scons build --- src/gallium/drivers/r300/SConscript | 1 + src/gallium/targets/dri-radeong/SConscript | 8 ++------ 2 files changed, 3 insertions(+), 6 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/r300/SConscript b/src/gallium/drivers/r300/SConscript index 27b2e309932..221878c1c0c 100644 --- a/src/gallium/drivers/r300/SConscript +++ b/src/gallium/drivers/r300/SConscript @@ -24,6 +24,7 @@ r300 = env.ConvenienceLibrary( 'r300_query.c', 'r300_render.c', 'r300_screen.c', + 'r300_screen_buffer.c', 'r300_state.c', 'r300_state_derived.c', 'r300_state_invariant.c', diff --git a/src/gallium/targets/dri-radeong/SConscript b/src/gallium/targets/dri-radeong/SConscript index bb3b5b9304b..239d29ace18 100644 --- a/src/gallium/targets/dri-radeong/SConscript +++ b/src/gallium/targets/dri-radeong/SConscript @@ -8,14 +8,10 @@ env = drienv.Clone() env.ParseConfig('pkg-config --cflags --libs libdrm_radeon') -drivers = [ - trace, - softpipe, - r300 -] +drivers = r300 + trace + softpipe env.SharedLibrary( target ='radeon_dri.so', source = COMMON_GALLIUM_SOURCES, - LIBS = st_dri + radeonwinsys + mesa + drivers + gallium + env['LIBS'], + LIBS = st_dri + radeonwinsys + mesa + glsl + drivers + gallium + env['LIBS'], ) -- cgit v1.2.3 From d7f78065acb09769195a58303ce3e9a401bf7a43 Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Thu, 25 Mar 2010 17:01:51 +0200 Subject: st/dri: add inline for dri2 check done in multiple places --- src/gallium/state_trackers/dri/dri_screen.c | 9 ++------- src/gallium/state_trackers/dri/dri_screen.h | 10 ++++++++++ src/gallium/state_trackers/dri/dri_st_api.c | 2 +- 3 files changed, 13 insertions(+), 8 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/dri/dri_screen.c b/src/gallium/state_trackers/dri/dri_screen.c index 17b9f1c5faf..733d71f9959 100644 --- a/src/gallium/state_trackers/dri/dri_screen.c +++ b/src/gallium/state_trackers/dri/dri_screen.c @@ -148,9 +148,7 @@ dri_fill_in_modes(struct dri_screen *screen, PIPE_TEXTURE_USAGE_RENDER_TARGET, 0); /* We can only get a 16 or 32 bit depth buffer with getBuffersWithFormat */ - if (screen->sPriv->dri2.loader && - (screen->sPriv->dri2.loader->base.version > 2) && - (screen->sPriv->dri2.loader->getBuffersWithFormat != NULL)) { + if (dri_with_format(screen->sPriv)) { pf_z16 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_Z16_UNORM, PIPE_TEXTURE_2D, PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0); @@ -352,8 +350,6 @@ dri_init_screen2(__DRIscreen * sPriv) { struct dri_screen *screen; struct drm_create_screen_arg arg; - const __DRIdri2LoaderExtension *dri2_ext = - sPriv->dri2.loader; screen = CALLOC_STRUCT(dri_screen); if (!screen) @@ -379,8 +375,7 @@ dri_init_screen2(__DRIscreen * sPriv) driParseOptionInfo(&screen->optionCache, __driConfigOptions, __driNConfigOptions); - screen->auto_fake_front = dri2_ext->base.version >= 3 && - dri2_ext->getBuffersWithFormat != NULL; + screen->auto_fake_front = dri_with_format(sPriv); return dri_fill_in_modes(screen, 32); fail: diff --git a/src/gallium/state_trackers/dri/dri_screen.h b/src/gallium/state_trackers/dri/dri_screen.h index e9944e0f63e..3b805c539f9 100644 --- a/src/gallium/state_trackers/dri/dri_screen.h +++ b/src/gallium/state_trackers/dri/dri_screen.h @@ -75,6 +75,16 @@ dri_screen(__DRIscreen * sPriv) return (struct dri_screen *)sPriv->private; } +static INLINE boolean +dri_with_format(__DRIscreen * sPriv) +{ + const __DRIdri2LoaderExtension *loader = sPriv->dri2.loader; + + return loader + && (loader->base.version >= 3) + && (loader->getBuffersWithFormat != NULL); +} + extern const uint __driNConfigOptions; const __DRIconfig ** diff --git a/src/gallium/state_trackers/dri/dri_st_api.c b/src/gallium/state_trackers/dri/dri_st_api.c index 263c1e19a70..67ab89e7aa8 100644 --- a/src/gallium/state_trackers/dri/dri_st_api.c +++ b/src/gallium/state_trackers/dri/dri_st_api.c @@ -172,7 +172,7 @@ dri_drawable_get_buffers(struct dri_drawable *drawable, unsigned num_attachments, i; assert(loader); - with_format = (loader->base.version > 2 && loader->getBuffersWithFormat); + with_format = dri_with_format(drawable->sPriv); num_attachments = 0; -- cgit v1.2.3 From c049d58a229125ce7ad61c645902eb2638e87194 Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Thu, 25 Mar 2010 17:01:52 +0200 Subject: st/dri: minor cosmetic for screen - put extensions above init_screen - split out destroy_option_cache --- src/gallium/state_trackers/dri/dri_screen.c | 47 +++++++++++++++++------------ 1 file changed, 27 insertions(+), 20 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/dri/dri_screen.c b/src/gallium/state_trackers/dri/dri_screen.c index 733d71f9959..cb650122668 100644 --- a/src/gallium/state_trackers/dri/dri_screen.c +++ b/src/gallium/state_trackers/dri/dri_screen.c @@ -51,7 +51,7 @@ PUBLIC const char __driConfigOptions[] = DRI_CONF_FTHROTTLE_MODE(DRI_CONF_FTHROTTLE_IRQS) DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_DEF_INTERVAL_0) DRI_CONF_SECTION_END DRI_CONF_SECTION_QUALITY - /*DRI_CONF_FORCE_S3TC_ENABLE(false) */ +/* DRI_CONF_FORCE_S3TC_ENABLE(false) */ DRI_CONF_ALLOW_LARGE_TEXTURES(1) DRI_CONF_SECTION_END DRI_CONF_END; @@ -87,17 +87,6 @@ static const __DRI2flushExtension dri2FlushExtension = { dri2_invalidate_drawable, }; - static const __DRIextension *dri_screen_extensions[] = { - &driReadDrawableExtension, - &driCopySubBufferExtension.base, - &driSwapControlExtension.base, - &driFrameTrackingExtension.base, - &driMediaStreamCounterExtension.base, - &dri2TexBufferExtension.base, - &dri2FlushExtension.base, - NULL - }; - const __DRIconfig ** dri_fill_in_modes(struct dri_screen *screen, unsigned pixel_bits) @@ -313,11 +302,24 @@ dri_get_swap_info(__DRIdrawable * dPriv, __DRIswapInfo * sInfo) return 0; } +static void +dri_destroy_option_cache(struct dri_screen * screen) +{ + int i; + + for (i = 0; i < (1 << screen->optionCache.tableSize); ++i) { + FREE(screen->optionCache.info[i].name); + FREE(screen->optionCache.info[i].ranges); + } + + FREE(screen->optionCache.info); + FREE(screen->optionCache.values); +} + static void dri_destroy_screen(__DRIscreen * sPriv) { struct dri_screen *screen = dri_screen(sPriv); - int i; if (screen->dri1_pipe) screen->dri1_pipe->destroy(screen->dri1_pipe); @@ -327,19 +329,24 @@ dri_destroy_screen(__DRIscreen * sPriv) if (screen->pipe_screen) screen->pipe_screen->destroy(screen->pipe_screen); - for (i = 0; i < (1 << screen->optionCache.tableSize); ++i) { - FREE(screen->optionCache.info[i].name); - FREE(screen->optionCache.info[i].ranges); - } - - FREE(screen->optionCache.info); - FREE(screen->optionCache.values); + dri_destroy_option_cache(screen); FREE(screen); sPriv->private = NULL; sPriv->extensions = NULL; } +static const __DRIextension *dri_screen_extensions[] = { + &driReadDrawableExtension, + &driCopySubBufferExtension.base, + &driSwapControlExtension.base, + &driFrameTrackingExtension.base, + &driMediaStreamCounterExtension.base, + &dri2TexBufferExtension.base, + &dri2FlushExtension.base, + NULL +}; + /** * This is the driver specific part of the createNewScreen entry point. * -- cgit v1.2.3 From 03c4573ecaeedc8439ebbdfe90f7873fcd9706a1 Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Thu, 25 Mar 2010 17:01:52 +0200 Subject: st/dri: minor cosmetic for buffers --- src/gallium/state_trackers/dri/dri_st_api.c | 31 ++++++++++++++++------------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/dri/dri_st_api.c b/src/gallium/state_trackers/dri/dri_st_api.c index 67ab89e7aa8..e721e55459d 100644 --- a/src/gallium/state_trackers/dri/dri_st_api.c +++ b/src/gallium/state_trackers/dri/dri_st_api.c @@ -110,27 +110,29 @@ dri_drawable_process_buffers(struct dri_drawable *drawable, switch (buf->attachment) { case __DRI_BUFFER_FRONT_LEFT: - if (!screen->auto_fake_front) { + if (!screen->auto_fake_front) { statt = ST_ATTACHMENT_INVALID; break; } - /* fallthrough */ + /* fallthrough */ case __DRI_BUFFER_FAKE_FRONT_LEFT: statt = ST_ATTACHMENT_FRONT_LEFT; - break; + break; case __DRI_BUFFER_BACK_LEFT: statt = ST_ATTACHMENT_BACK_LEFT; - break; + break; case __DRI_BUFFER_DEPTH: case __DRI_BUFFER_DEPTH_STENCIL: case __DRI_BUFFER_STENCIL: - statt = ST_ATTACHMENT_DEPTH_STENCIL; /* use only the first depth/stencil buffer */ - if (have_depth) - statt = ST_ATTACHMENT_INVALID; - else + if (!have_depth) { have_depth = TRUE; - break; + statt = ST_ATTACHMENT_DEPTH_STENCIL; + } + else { + statt = ST_ATTACHMENT_INVALID; + } + break; default: statt = ST_ATTACHMENT_INVALID; break; @@ -143,7 +145,7 @@ dri_drawable_process_buffers(struct dri_drawable *drawable, templ.format = format; whandle.handle = buf->name; whandle.stride = buf->pitch; - + drawable->textures[statt] = screen->pipe_screen->texture_from_handle(screen->pipe_screen, &templ, &whandle); @@ -182,7 +184,7 @@ dri_drawable_get_buffers(struct dri_drawable *drawable, for (i = 0; i < *count; i++) { enum pipe_format format; - int att; + int att, bpp; format = dri_drawable_get_format(drawable, statts[i]); if (format == PIPE_FORMAT_NONE) @@ -212,11 +214,12 @@ dri_drawable_get_buffers(struct dri_drawable *drawable, break; } + bpp = util_format_get_blocksizebits(format); + if (att >= 0) { attachments[num_attachments++] = att; if (with_format) { - attachments[num_attachments++] = - util_format_get_blocksizebits(format); + attachments[num_attachments++] = bpp; } } } @@ -258,7 +261,7 @@ dri_drawable_get_buffers(struct dri_drawable *drawable, return buffers; } -static boolean +static boolean dri_st_framebuffer_validate(struct st_framebuffer_iface *stfbi, const enum st_attachment_type *statts, unsigned count, -- cgit v1.2.3 From 24056e76637c9d79d996c6bc060576907bd9b2aa Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Thu, 25 Mar 2010 17:01:52 +0200 Subject: st/dri: flush_frontbuffer, allocate_textures for dri1 * ptex is get by flush_frontbuffer, similar to swap_buffers * comment for allocate_textures * texture_mask is managed at the st_fb level --- src/gallium/state_trackers/dri/dri1.c | 46 ++++++++++++++++++----------- src/gallium/state_trackers/dri/dri1.h | 3 +- src/gallium/state_trackers/dri/dri_st_api.c | 13 ++++---- 3 files changed, 37 insertions(+), 25 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/dri/dri1.c b/src/gallium/state_trackers/dri/dri1.c index 240bc69efd5..9108d41bd94 100644 --- a/src/gallium/state_trackers/dri/dri1.c +++ b/src/gallium/state_trackers/dri/dri1.c @@ -318,23 +318,23 @@ dri1_copy_to_front(struct dri_context *ctx, } void -dri1_flush_frontbuffer(struct dri_drawable *drawable, - struct pipe_texture *ptex) +dri1_flush_frontbuffer(struct dri_drawable *draw, + enum st_attachment_type statt) { - struct st_api *stapi = dri_get_st_api(); - struct dri_screen *screen = dri_screen(drawable->sPriv); + struct dri_context *ctx = dri_get_current(); + struct dri_screen *screen = dri_screen(draw->sPriv); struct pipe_screen *pipe_screen = screen->pipe_screen; - struct dri_context *ctx; struct pipe_fence_handle *dummy_fence; - struct st_context_iface *st = stapi->get_current(stapi); - - if (!st) - return; + struct pipe_texture *ptex; - ctx = (struct dri_context *) st->st_manager_private; + if (!ctx) + return; /* For now */ - dri1_copy_to_front(ctx, ptex, ctx->dPriv, NULL, &dummy_fence); - pipe_screen->fence_reference(pipe_screen, &dummy_fence, NULL); + ptex = draw->textures[statt]; + if (ptex) { + dri1_copy_to_front(ctx, ptex, ctx->dPriv, NULL, &dummy_fence); + pipe_screen->fence_reference(pipe_screen, &dummy_fence, NULL); + } /** * FIXME: Do we need swap throttling here? @@ -399,17 +399,31 @@ dri1_copy_sub_buffer(__DRIdrawable * dPriv, int x, int y, int w, int h) } } +/** + * Allocate framebuffer attachments. + * + * During fixed-size operation, the function keeps allocating new attachments + * as they are requested. Unused attachments are not removed, not until the + * framebuffer is resized or destroyed. + */ void dri1_allocate_textures(struct dri_drawable *drawable, - unsigned width, unsigned height, unsigned mask) { struct dri_screen *screen = dri_screen(drawable->sPriv); struct pipe_texture templ; + unsigned width, height; + boolean resized; int i; + width = drawable->dPriv->w; + height = drawable->dPriv->h; + + resized = (drawable->old_w != width || + drawable->old_h != height); + /* remove outdated textures */ - if (drawable->old_w != width || drawable->old_h != height) { + if (resized) { for (i = 0; i < ST_ATTACHMENT_COUNT; i++) pipe_texture_reference(&drawable->textures[i], NULL); } @@ -427,9 +441,6 @@ dri1_allocate_textures(struct dri_drawable *drawable, /* the texture already exists or not requested */ if (drawable->textures[i] || !(mask & (1 << i))) { - /* remember the texture */ - if (drawable->textures[i]) - mask |= (1 << i); continue; } @@ -462,7 +473,6 @@ dri1_allocate_textures(struct dri_drawable *drawable, drawable->old_w = width; drawable->old_h = height; - drawable->texture_mask = mask; } static void diff --git a/src/gallium/state_trackers/dri/dri1.h b/src/gallium/state_trackers/dri/dri1.h index e83571e57be..f1004281b54 100644 --- a/src/gallium/state_trackers/dri/dri1.h +++ b/src/gallium/state_trackers/dri/dri1.h @@ -45,11 +45,10 @@ dri1_init_screen(__DRIscreen * sPriv); void dri1_flush_frontbuffer(struct dri_drawable *drawable, - struct pipe_texture *ptex); + enum st_attachment_type statt); void dri1_allocate_textures(struct dri_drawable *drawable, - unsigned width, unsigned height, unsigned mask); void dri1_swap_buffers(__DRIdrawable * dPriv); diff --git a/src/gallium/state_trackers/dri/dri_st_api.c b/src/gallium/state_trackers/dri/dri_st_api.c index e721e55459d..2cdfd257b01 100644 --- a/src/gallium/state_trackers/dri/dri_st_api.c +++ b/src/gallium/state_trackers/dri/dri_st_api.c @@ -285,8 +285,7 @@ dri_st_framebuffer_validate(struct st_framebuffer_iface *stfbi, if (drawable->texture_stamp != drawable->dPriv->lastStamp || (statt_mask & ~drawable->texture_mask)) { if (__dri1_api_hooks) { - dri1_allocate_textures(drawable, - drawable->dPriv->w, drawable->dPriv->h, statt_mask); + dri1_allocate_textures(drawable, statt_mask); } else { __DRIbuffer *buffers; @@ -296,6 +295,12 @@ dri_st_framebuffer_validate(struct st_framebuffer_iface *stfbi, dri_drawable_process_buffers(drawable, buffers, num_buffers); } + /* add existing textures */ + for (i = 0; i < ST_ATTACHMENT_COUNT; i++) { + if (drawable->textures[i]) + statt_mask |= (1 << i); + } + drawable->texture_stamp = drawable->dPriv->lastStamp; drawable->texture_mask = statt_mask; } @@ -321,9 +326,7 @@ dri_st_framebuffer_flush_front(struct st_framebuffer_iface *stfbi, drawable->sPriv->dri2.loader; if (__dri1_api_hooks) { - struct pipe_texture *ptex = drawable->textures[statt]; - if (ptex) - dri1_flush_frontbuffer(drawable, ptex); + dri1_flush_frontbuffer(drawable, statt); return TRUE; } -- cgit v1.2.3 From a21c30308db206467a54394b1ddda444861ee9b6 Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Thu, 25 Mar 2010 17:01:52 +0200 Subject: st/dri: flush_frontbuffer, allocate_textures for dri2 dri_st_framebuffer functions just forward to dri1/dri2 functions. --- src/gallium/state_trackers/dri/dri_st_api.c | 57 ++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 17 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/dri/dri_st_api.c b/src/gallium/state_trackers/dri/dri_st_api.c index 2cdfd257b01..84c94cb06db 100644 --- a/src/gallium/state_trackers/dri/dri_st_api.c +++ b/src/gallium/state_trackers/dri/dri_st_api.c @@ -261,6 +261,18 @@ dri_drawable_get_buffers(struct dri_drawable *drawable, return buffers; } +static void +dri_allocate_textures(struct dri_drawable *drawable, + const enum st_attachment_type *statts, + unsigned count) +{ + __DRIbuffer *buffers; + unsigned num_buffers = count; + + buffers = dri_drawable_get_buffers(drawable, statts, &num_buffers); + dri_drawable_process_buffers(drawable, buffers, num_buffers); +} + static boolean dri_st_framebuffer_validate(struct st_framebuffer_iface *stfbi, const enum st_attachment_type *statts, @@ -269,30 +281,31 @@ dri_st_framebuffer_validate(struct st_framebuffer_iface *stfbi, { struct dri_drawable *drawable = (struct dri_drawable *) stfbi->st_manager_private; - unsigned statt_mask, i; + unsigned statt_mask, new_mask; + boolean new_stamp; + int i; statt_mask = 0x0; for (i = 0; i < count; i++) statt_mask |= (1 << statts[i]); + /* record newly allocated textures */ + new_mask = (statt_mask & ~drawable->texture_mask); + /* * dPriv->pStamp is the server stamp. It should be accessed with a lock, at * least for DRI1. dPriv->lastStamp is the client stamp. It has the value * of the server stamp when last checked. - * - * This function updates the textures and records the stamp of the textures. */ - if (drawable->texture_stamp != drawable->dPriv->lastStamp || - (statt_mask & ~drawable->texture_mask)) { + new_stamp = (drawable->texture_stamp != drawable->dPriv->lastStamp); + + if (new_stamp || new_mask) { + if (__dri1_api_hooks) { dri1_allocate_textures(drawable, statt_mask); } else { - __DRIbuffer *buffers; - unsigned num_buffers = count; - - buffers = dri_drawable_get_buffers(drawable, statts, &num_buffers); - dri_drawable_process_buffers(drawable, buffers, num_buffers); + dri_allocate_textures(drawable, statts, count); } /* add existing textures */ @@ -316,23 +329,33 @@ dri_st_framebuffer_validate(struct st_framebuffer_iface *stfbi, return TRUE; } +static void +dri_flush_frontbuffer(struct dri_drawable *drawable, + enum st_attachment_type statt) +{ + __DRIdrawable *dri_drawable = drawable->dPriv; + struct __DRIdri2LoaderExtensionRec *loader = drawable->sPriv->dri2.loader; + + if (loader->flushFrontBuffer == NULL) + return; + + if (statt == ST_ATTACHMENT_FRONT_LEFT) { + loader->flushFrontBuffer(dri_drawable, dri_drawable->loaderPrivate); + } +} + static boolean dri_st_framebuffer_flush_front(struct st_framebuffer_iface *stfbi, enum st_attachment_type statt) { struct dri_drawable *drawable = (struct dri_drawable *) stfbi->st_manager_private; - struct __DRIdri2LoaderExtensionRec *loader = - drawable->sPriv->dri2.loader; if (__dri1_api_hooks) { dri1_flush_frontbuffer(drawable, statt); - return TRUE; } - - if (statt == ST_ATTACHMENT_FRONT_LEFT && loader->flushFrontBuffer) { - loader->flushFrontBuffer(drawable->dPriv, - drawable->dPriv->loaderPrivate); + else { + dri_flush_frontbuffer(drawable, statt); } return TRUE; -- cgit v1.2.3 From 96c152b4b066f6e3583821ad44ec8a527ab55e05 Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Thu, 25 Mar 2010 17:01:52 +0200 Subject: st/dri: make get_texture into validate_att This is a wrapper around dri_st_framebuffer_validate for a single attachment. Also, call validate through hook to make it more generic. --- src/gallium/state_trackers/dri/dri_drawable.c | 7 ++++-- src/gallium/state_trackers/dri/dri_st_api.c | 36 +++++++++++++-------------- src/gallium/state_trackers/dri/dri_st_api.h | 6 ++--- 3 files changed, 26 insertions(+), 23 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/dri/dri_drawable.c b/src/gallium/state_trackers/dri/dri_drawable.c index 930387f8a67..4e2300d78fd 100644 --- a/src/gallium/state_trackers/dri/dri_drawable.c +++ b/src/gallium/state_trackers/dri/dri_drawable.c @@ -48,8 +48,11 @@ void dri2_set_tex_buffer2(__DRIcontext *pDRICtx, GLint target, { struct dri_context *ctx = dri_context(pDRICtx); struct dri_drawable *drawable = dri_drawable(dPriv); - struct pipe_texture *pt = - dri_get_st_framebuffer_texture(drawable->stfb, ST_ATTACHMENT_FRONT_LEFT); + struct pipe_texture *pt; + + dri_st_framebuffer_validate_att(drawable->stfb, ST_ATTACHMENT_FRONT_LEFT); + + pt = drawable->textures[ST_ATTACHMENT_FRONT_LEFT]; if (pt) { ctx->st->teximage(ctx->st, diff --git a/src/gallium/state_trackers/dri/dri_st_api.c b/src/gallium/state_trackers/dri/dri_st_api.c index 84c94cb06db..c067cee66cf 100644 --- a/src/gallium/state_trackers/dri/dri_st_api.c +++ b/src/gallium/state_trackers/dri/dri_st_api.c @@ -390,33 +390,33 @@ dri_destroy_st_framebuffer(struct st_framebuffer_iface *stfbi) } /** - * Return the texture at an attachment. Allocate the texture if it does not + * Validate the texture at an attachment. Allocate the texture if it does not * exist. */ -struct pipe_texture * -dri_get_st_framebuffer_texture(struct st_framebuffer_iface *stfbi, - enum st_attachment_type statt) +void +dri_st_framebuffer_validate_att(struct st_framebuffer_iface *stfbi, + enum st_attachment_type statt) { struct dri_drawable *drawable = (struct dri_drawable *) stfbi->st_manager_private; - - if (!(drawable->texture_mask & (1 << statt))) { - enum st_attachment_type statts[ST_ATTACHMENT_COUNT]; - unsigned i, count = 0; + enum st_attachment_type statts[ST_ATTACHMENT_COUNT]; + unsigned i, count = 0; - /* make sure DRI2 does not destroy existing buffers */ - for (i = 0; i < ST_ATTACHMENT_COUNT; i++) { - if (drawable->texture_mask & (1 << i)) { - statts[count++] = i; - } - } - statts[count++] = statt; + /* check if buffer already exists */ + if (drawable->texture_mask & (1 << statt)) + return; - drawable->texture_stamp = drawable->dPriv->lastStamp - 1; - dri_st_framebuffer_validate(stfbi, statts, count, NULL); + /* make sure DRI2 does not destroy existing buffers */ + for (i = 0; i < ST_ATTACHMENT_COUNT; i++) { + if (drawable->texture_mask & (1 << i)) { + statts[count++] = i; + } } + statts[count++] = statt; + + drawable->texture_stamp = drawable->dPriv->lastStamp - 1; - return drawable->textures[statt]; + stfbi->validate(stfbi, statts, count, NULL); } /** diff --git a/src/gallium/state_trackers/dri/dri_st_api.h b/src/gallium/state_trackers/dri/dri_st_api.h index 7cf522e4690..99a217bfa79 100644 --- a/src/gallium/state_trackers/dri/dri_st_api.h +++ b/src/gallium/state_trackers/dri/dri_st_api.h @@ -48,8 +48,8 @@ dri_create_st_framebuffer(struct dri_drawable *drawable); void dri_destroy_st_framebuffer(struct st_framebuffer_iface *stfbi); -struct pipe_texture * -dri_get_st_framebuffer_texture(struct st_framebuffer_iface *stfbi, - enum st_attachment_type statt); +void +dri_st_framebuffer_validate_att(struct st_framebuffer_iface *stfbi, + enum st_attachment_type statt); #endif /* _DRI_ST_API_H_ */ -- cgit v1.2.3 From 6a7bd8eb95e7d304725b09272dc9c40a337182e1 Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Thu, 25 Mar 2010 17:01:53 +0200 Subject: st/dri: split out DRI2 code --- src/gallium/state_trackers/dri/Makefile | 3 +- src/gallium/state_trackers/dri/SConscript | 1 + src/gallium/state_trackers/dri/dri2.c | 413 ++++++++++++++++++++++++++ src/gallium/state_trackers/dri/dri2.h | 46 +++ src/gallium/state_trackers/dri/dri_drawable.c | 27 -- src/gallium/state_trackers/dri/dri_drawable.h | 6 - src/gallium/state_trackers/dri/dri_screen.c | 87 +----- src/gallium/state_trackers/dri/dri_screen.h | 3 + src/gallium/state_trackers/dri/dri_st_api.c | 260 +--------------- 9 files changed, 476 insertions(+), 370 deletions(-) create mode 100644 src/gallium/state_trackers/dri/dri2.c create mode 100644 src/gallium/state_trackers/dri/dri2.h (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/dri/Makefile b/src/gallium/state_trackers/dri/Makefile index f5af8aa3a67..6d95a277f82 100644 --- a/src/gallium/state_trackers/dri/Makefile +++ b/src/gallium/state_trackers/dri/Makefile @@ -17,7 +17,8 @@ C_SOURCES = \ dri_drawable.c \ dri_extensions.c \ dri_st_api.c \ - dri1.c + dri1.c \ + dri2.c # $(TOP)/src/mesa/drivers/dri/common/utils.c \ $(TOP)/src/mesa/drivers/dri/common/vblank.c \ diff --git a/src/gallium/state_trackers/dri/SConscript b/src/gallium/state_trackers/dri/SConscript index 7c67ceecd80..d6dc126723d 100644 --- a/src/gallium/state_trackers/dri/SConscript +++ b/src/gallium/state_trackers/dri/SConscript @@ -20,6 +20,7 @@ if env['dri']: 'dri_screen.c', 'dri_st_api.c', 'dri1.c', + 'dri2.c', ] ) Export('st_dri') diff --git a/src/gallium/state_trackers/dri/dri2.c b/src/gallium/state_trackers/dri/dri2.c new file mode 100644 index 00000000000..2c6a0621ae7 --- /dev/null +++ b/src/gallium/state_trackers/dri/dri2.c @@ -0,0 +1,413 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright 2009, VMware, Inc. + * All Rights Reserved. + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * Authors: + * Keith Whitwell + * Jakob Bornecrantz + * Chia-I Wu + */ + +#include "util/u_memory.h" +#include "util/u_inlines.h" +#include "util/u_format.h" +#include "util/u_debug.h" +#include "state_tracker/drm_api.h" + +#include "dri_screen.h" +#include "dri_context.h" +#include "dri_drawable.h" +#include "dri_st_api.h" +#include "dri2.h" + +/** + * DRI2 flush extension. + */ +static void +dri2_flush_drawable(__DRIdrawable *draw) +{ +} + +static void +dri2_invalidate_drawable(__DRIdrawable *dPriv) +{ + struct dri_drawable *drawable = dri_drawable(dPriv); + struct dri_context *ctx = dri_context(dPriv->driContextPriv); + + dri2InvalidateDrawable(dPriv); + drawable->dPriv->lastStamp = *drawable->dPriv->pStamp; + + if (ctx) + ctx->st->notify_invalid_framebuffer(ctx->st, drawable->stfb); +} + +static const __DRI2flushExtension dri2FlushExtension = { + { __DRI2_FLUSH, __DRI2_FLUSH_VERSION }, + dri2_flush_drawable, + dri2_invalidate_drawable, +}; + +/** + * These are used for GLX_EXT_texture_from_pixmap + */ +static void +dri2_set_tex_buffer2(__DRIcontext *pDRICtx, GLint target, + GLint format, __DRIdrawable *dPriv) +{ + struct dri_context *ctx = dri_context(pDRICtx); + struct dri_drawable *drawable = dri_drawable(dPriv); + struct pipe_texture *pt; + + dri_st_framebuffer_validate_att(drawable->stfb, ST_ATTACHMENT_FRONT_LEFT); + + pt = drawable->textures[ST_ATTACHMENT_FRONT_LEFT]; + + if (pt) { + ctx->st->teximage(ctx->st, + (target == GL_TEXTURE_2D) ? ST_TEXTURE_2D : ST_TEXTURE_RECT, + 0, drawable->stvis.color_format, pt, FALSE); + } +} + +static void +dri2_set_tex_buffer(__DRIcontext *pDRICtx, GLint target, + __DRIdrawable *dPriv) +{ + dri2_set_tex_buffer2(pDRICtx, target, __DRI_TEXTURE_FORMAT_RGBA, dPriv); +} + +static const __DRItexBufferExtension dri2TexBufferExtension = { + { __DRI_TEX_BUFFER, __DRI_TEX_BUFFER_VERSION }, + dri2_set_tex_buffer, + dri2_set_tex_buffer2, +}; + +/** + * Get the format of an attachment. + */ +static INLINE enum pipe_format +dri_drawable_get_format(struct dri_drawable *drawable, + enum st_attachment_type statt) +{ + enum pipe_format format; + + switch (statt) { + case ST_ATTACHMENT_FRONT_LEFT: + case ST_ATTACHMENT_BACK_LEFT: + case ST_ATTACHMENT_FRONT_RIGHT: + case ST_ATTACHMENT_BACK_RIGHT: + format = drawable->stvis.color_format; + break; + case ST_ATTACHMENT_DEPTH_STENCIL: + format = drawable->stvis.depth_stencil_format; + break; + default: + format = PIPE_FORMAT_NONE; + break; + } + + return format; +} + +/** + * Retrieve __DRIbuffer from the DRI loader. + */ +static __DRIbuffer * +dri_drawable_get_buffers(struct dri_drawable *drawable, + const enum st_attachment_type *statts, + unsigned *count) +{ + __DRIdrawable *dri_drawable = drawable->dPriv; + struct __DRIdri2LoaderExtensionRec *loader = drawable->sPriv->dri2.loader; + boolean with_format; + __DRIbuffer *buffers; + int num_buffers; + unsigned attachments[10]; + unsigned num_attachments, i; + + assert(loader); + with_format = dri_with_format(drawable->sPriv); + + num_attachments = 0; + + /* for Xserver 1.6.0 (DRI2 version 1) we always need to ask for the front */ + if (!with_format) + attachments[num_attachments++] = __DRI_BUFFER_FRONT_LEFT; + + for (i = 0; i < *count; i++) { + enum pipe_format format; + int att, bpp; + + format = dri_drawable_get_format(drawable, statts[i]); + if (format == PIPE_FORMAT_NONE) + continue; + + switch (statts[i]) { + case ST_ATTACHMENT_FRONT_LEFT: + /* already added */ + if (!with_format) + continue; + att = __DRI_BUFFER_FRONT_LEFT; + break; + case ST_ATTACHMENT_BACK_LEFT: + att = __DRI_BUFFER_BACK_LEFT; + break; + case ST_ATTACHMENT_FRONT_RIGHT: + att = __DRI_BUFFER_FRONT_RIGHT; + break; + case ST_ATTACHMENT_BACK_RIGHT: + att = __DRI_BUFFER_BACK_RIGHT; + break; + case ST_ATTACHMENT_DEPTH_STENCIL: + att = __DRI_BUFFER_DEPTH_STENCIL; + break; + default: + att = -1; + break; + } + + bpp = util_format_get_blocksizebits(format); + + if (att >= 0) { + attachments[num_attachments++] = att; + if (with_format) { + attachments[num_attachments++] = bpp; + } + } + } + + if (with_format) { + num_attachments /= 2; + buffers = loader->getBuffersWithFormat(dri_drawable, + &dri_drawable->w, &dri_drawable->h, + attachments, num_attachments, + &num_buffers, dri_drawable->loaderPrivate); + } + else { + buffers = loader->getBuffers(dri_drawable, + &dri_drawable->w, &dri_drawable->h, + attachments, num_attachments, + &num_buffers, dri_drawable->loaderPrivate); + } + + if (buffers) { + /* set one cliprect to cover the whole dri_drawable */ + dri_drawable->x = 0; + dri_drawable->y = 0; + dri_drawable->backX = 0; + dri_drawable->backY = 0; + dri_drawable->numClipRects = 1; + dri_drawable->pClipRects[0].x1 = 0; + dri_drawable->pClipRects[0].y1 = 0; + dri_drawable->pClipRects[0].x2 = dri_drawable->w; + dri_drawable->pClipRects[0].y2 = dri_drawable->h; + dri_drawable->numBackClipRects = 1; + dri_drawable->pBackClipRects[0].x1 = 0; + dri_drawable->pBackClipRects[0].y1 = 0; + dri_drawable->pBackClipRects[0].x2 = dri_drawable->w; + dri_drawable->pBackClipRects[0].y2 = dri_drawable->h; + + *count = num_buffers; + } + + return buffers; +} + +/** + * Process __DRIbuffer and convert them into pipe_textures. + */ +static void +dri_drawable_process_buffers(struct dri_drawable *drawable, + __DRIbuffer *buffers, unsigned count) +{ + struct dri_screen *screen = dri_screen(drawable->sPriv); + __DRIdrawable *dri_drawable = drawable->dPriv; + struct pipe_texture templ; + struct winsys_handle whandle; + boolean have_depth = FALSE; + unsigned i; + + if (drawable->old_num == count && + drawable->old_w == dri_drawable->w && + drawable->old_h == dri_drawable->h && + memcmp(drawable->old, buffers, sizeof(__DRIbuffer) * count) == 0) + return; + + for (i = 0; i < ST_ATTACHMENT_COUNT; i++) + pipe_texture_reference(&drawable->textures[i], NULL); + + memset(&templ, 0, sizeof(templ)); + templ.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET; + templ.target = PIPE_TEXTURE_2D; + templ.last_level = 0; + templ.width0 = dri_drawable->w; + templ.height0 = dri_drawable->h; + templ.depth0 = 1; + + memset(&whandle, 0, sizeof(whandle)); + + for (i = 0; i < count; i++) { + __DRIbuffer *buf = &buffers[i]; + enum st_attachment_type statt; + enum pipe_format format; + + switch (buf->attachment) { + case __DRI_BUFFER_FRONT_LEFT: + if (!screen->auto_fake_front) { + statt = ST_ATTACHMENT_INVALID; + break; + } + /* fallthrough */ + case __DRI_BUFFER_FAKE_FRONT_LEFT: + statt = ST_ATTACHMENT_FRONT_LEFT; + break; + case __DRI_BUFFER_BACK_LEFT: + statt = ST_ATTACHMENT_BACK_LEFT; + break; + case __DRI_BUFFER_DEPTH: + case __DRI_BUFFER_DEPTH_STENCIL: + case __DRI_BUFFER_STENCIL: + /* use only the first depth/stencil buffer */ + if (!have_depth) { + have_depth = TRUE; + statt = ST_ATTACHMENT_DEPTH_STENCIL; + } + else { + statt = ST_ATTACHMENT_INVALID; + } + break; + default: + statt = ST_ATTACHMENT_INVALID; + break; + } + + format = dri_drawable_get_format(drawable, statt); + if (statt == ST_ATTACHMENT_INVALID || format == PIPE_FORMAT_NONE) + continue; + + templ.format = format; + whandle.handle = buf->name; + whandle.stride = buf->pitch; + + drawable->textures[statt] = + screen->pipe_screen->texture_from_handle(screen->pipe_screen, + &templ, &whandle); + } + + drawable->old_num = count; + drawable->old_w = dri_drawable->w; + drawable->old_h = dri_drawable->h; + memcpy(drawable->old, buffers, sizeof(__DRIbuffer) * count); +} + +/* + * Backend functions for st_framebuffer interface. + */ + +void +dri_allocate_textures(struct dri_drawable *drawable, + const enum st_attachment_type *statts, + unsigned count) +{ + __DRIbuffer *buffers; + unsigned num_buffers = count; + + buffers = dri_drawable_get_buffers(drawable, statts, &num_buffers); + dri_drawable_process_buffers(drawable, buffers, num_buffers); +} + +void +dri_flush_frontbuffer(struct dri_drawable *drawable, + enum st_attachment_type statt) +{ + __DRIdrawable *dri_drawable = drawable->dPriv; + struct __DRIdri2LoaderExtensionRec *loader = drawable->sPriv->dri2.loader; + + if (loader->flushFrontBuffer == NULL) + return; + + if (statt == ST_ATTACHMENT_FRONT_LEFT) { + loader->flushFrontBuffer(dri_drawable, dri_drawable->loaderPrivate); + } +} + +/* + * Backend function init_screen. + */ + +static const __DRIextension *dri_screen_extensions[] = { + &driReadDrawableExtension, + &driCopySubBufferExtension.base, + &driSwapControlExtension.base, + &driFrameTrackingExtension.base, + &driMediaStreamCounterExtension.base, + &dri2TexBufferExtension.base, + &dri2FlushExtension.base, + NULL +}; + +/** + * This is the driver specific part of the createNewScreen entry point. + * + * Returns the __GLcontextModes supported by this driver. + */ +const __DRIconfig ** +dri_init_screen2(__DRIscreen * sPriv) +{ + struct dri_screen *screen; + struct drm_create_screen_arg arg; + + screen = CALLOC_STRUCT(dri_screen); + if (!screen) + return NULL; + + screen->api = drm_api_create(); + screen->sPriv = sPriv; + screen->fd = sPriv->fd; + sPriv->private = (void *)screen; + sPriv->extensions = dri_screen_extensions; + arg.mode = DRM_CREATE_NORMAL; + + screen->pipe_screen = screen->api->create_screen(screen->api, screen->fd, &arg); + if (!screen->pipe_screen) { + debug_printf("%s: failed to create pipe_screen\n", __FUNCTION__); + goto fail; + } + + screen->smapi = dri_create_st_manager(screen); + if (!screen->smapi) + goto fail; + + driParseOptionInfo(&screen->optionCache, + __driConfigOptions, __driNConfigOptions); + + screen->auto_fake_front = dri_with_format(sPriv); + + return dri_fill_in_modes(screen, 32); +fail: + dri_destroy_screen(sPriv); + return NULL; +} + +/* vim: set sw=3 ts=8 sts=3 expandtab: */ diff --git a/src/gallium/state_trackers/dri/dri2.h b/src/gallium/state_trackers/dri/dri2.h new file mode 100644 index 00000000000..06abccc405f --- /dev/null +++ b/src/gallium/state_trackers/dri/dri2.h @@ -0,0 +1,46 @@ +/************************************************************************** + * + * Copyright 2009, VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef DRI2_H +#define DRI2_H + +#include "dri_drawable.h" +#include "dri_util.h" + +const __DRIconfig ** +dri_init_screen2(__DRIscreen * sPriv); + +void +dri_flush_frontbuffer(struct dri_drawable *drawable, + enum st_attachment_type statt); + +void +dri_allocate_textures(struct dri_drawable *drawable, + const enum st_attachment_type *statts, + unsigned count); + +#endif /* DRI2_H */ diff --git a/src/gallium/state_trackers/dri/dri_drawable.c b/src/gallium/state_trackers/dri/dri_drawable.c index 4e2300d78fd..9b0ae8b27a9 100644 --- a/src/gallium/state_trackers/dri/dri_drawable.c +++ b/src/gallium/state_trackers/dri/dri_drawable.c @@ -40,33 +40,6 @@ #include "util/u_memory.h" #include "util/u_inlines.h" -/** - * These are used for GLX_EXT_texture_from_pixmap - */ -void dri2_set_tex_buffer2(__DRIcontext *pDRICtx, GLint target, - GLint format, __DRIdrawable *dPriv) -{ - struct dri_context *ctx = dri_context(pDRICtx); - struct dri_drawable *drawable = dri_drawable(dPriv); - struct pipe_texture *pt; - - dri_st_framebuffer_validate_att(drawable->stfb, ST_ATTACHMENT_FRONT_LEFT); - - pt = drawable->textures[ST_ATTACHMENT_FRONT_LEFT]; - - if (pt) { - ctx->st->teximage(ctx->st, - (target == GL_TEXTURE_2D) ? ST_TEXTURE_2D : ST_TEXTURE_RECT, - 0, drawable->stvis.color_format, pt, FALSE); - } -} - -void dri2_set_tex_buffer(__DRIcontext *pDRICtx, GLint target, - __DRIdrawable *dPriv) -{ - dri2_set_tex_buffer2(pDRICtx, target, __DRI_TEXTURE_FORMAT_RGBA, dPriv); -} - /** * This is called when we need to set up GL rendering to a new X window. */ diff --git a/src/gallium/state_trackers/dri/dri_drawable.h b/src/gallium/state_trackers/dri/dri_drawable.h index 7f687b65f23..98abeb9ec05 100644 --- a/src/gallium/state_trackers/dri/dri_drawable.h +++ b/src/gallium/state_trackers/dri/dri_drawable.h @@ -84,12 +84,6 @@ dri_create_buffer(__DRIscreen * sPriv, void dri_destroy_buffer(__DRIdrawable * dPriv); -void dri2_set_tex_buffer2(__DRIcontext *pDRICtx, GLint target, - GLint glx_texture_format, __DRIdrawable *dPriv); - -void dri2_set_tex_buffer(__DRIcontext *pDRICtx, GLint target, - __DRIdrawable *dPriv); - #endif /* vim: set sw=3 ts=8 sts=3 expandtab: */ diff --git a/src/gallium/state_trackers/dri/dri_screen.c b/src/gallium/state_trackers/dri/dri_screen.c index cb650122668..6aef2d57002 100644 --- a/src/gallium/state_trackers/dri/dri_screen.c +++ b/src/gallium/state_trackers/dri/dri_screen.c @@ -38,6 +38,7 @@ #include "dri_drawable.h" #include "dri_st_api.h" #include "dri1.h" +#include "dri2.h" #include "util/u_inlines.h" #include "pipe/p_screen.h" @@ -57,36 +58,6 @@ PUBLIC const char __driConfigOptions[] = const uint __driNConfigOptions = 3; -static const __DRItexBufferExtension dri2TexBufferExtension = { - { __DRI_TEX_BUFFER, __DRI_TEX_BUFFER_VERSION }, - dri2_set_tex_buffer, - dri2_set_tex_buffer2, -}; - -static void -dri2_flush_drawable(__DRIdrawable *draw) -{ -} - -static void -dri2_invalidate_drawable(__DRIdrawable *dPriv) -{ - struct dri_drawable *drawable = dri_drawable(dPriv); - struct dri_context *ctx = dri_context(dPriv->driContextPriv); - - dri2InvalidateDrawable(dPriv); - drawable->dPriv->lastStamp = *drawable->dPriv->pStamp; - - if (ctx) - ctx->st->notify_invalid_framebuffer(ctx->st, drawable->stfb); -} - -static const __DRI2flushExtension dri2FlushExtension = { - { __DRI2_FLUSH, __DRI2_FLUSH_VERSION }, - dri2_flush_drawable, - dri2_invalidate_drawable, -}; - const __DRIconfig ** dri_fill_in_modes(struct dri_screen *screen, unsigned pixel_bits) @@ -316,7 +287,7 @@ dri_destroy_option_cache(struct dri_screen * screen) FREE(screen->optionCache.values); } -static void +void dri_destroy_screen(__DRIscreen * sPriv) { struct dri_screen *screen = dri_screen(sPriv); @@ -336,60 +307,6 @@ dri_destroy_screen(__DRIscreen * sPriv) sPriv->extensions = NULL; } -static const __DRIextension *dri_screen_extensions[] = { - &driReadDrawableExtension, - &driCopySubBufferExtension.base, - &driSwapControlExtension.base, - &driFrameTrackingExtension.base, - &driMediaStreamCounterExtension.base, - &dri2TexBufferExtension.base, - &dri2FlushExtension.base, - NULL -}; - -/** - * This is the driver specific part of the createNewScreen entry point. - * - * Returns the __GLcontextModes supported by this driver. - */ -static const __DRIconfig ** -dri_init_screen2(__DRIscreen * sPriv) -{ - struct dri_screen *screen; - struct drm_create_screen_arg arg; - - screen = CALLOC_STRUCT(dri_screen); - if (!screen) - return NULL; - - screen->api = drm_api_create(); - screen->sPriv = sPriv; - screen->fd = sPriv->fd; - sPriv->private = (void *)screen; - sPriv->extensions = dri_screen_extensions; - arg.mode = DRM_CREATE_NORMAL; - - screen->pipe_screen = screen->api->create_screen(screen->api, screen->fd, &arg); - if (!screen->pipe_screen) { - debug_printf("%s: failed to create pipe_screen\n", __FUNCTION__); - goto fail; - } - - screen->smapi = dri_create_st_manager(screen); - if (!screen->smapi) - goto fail; - - driParseOptionInfo(&screen->optionCache, - __driConfigOptions, __driNConfigOptions); - - screen->auto_fake_front = dri_with_format(sPriv); - - return dri_fill_in_modes(screen, 32); -fail: - dri_destroy_screen(sPriv); - return NULL; -} - const struct __DriverAPIRec driDriverAPI = { .DestroyScreen = dri_destroy_screen, .CreateContext = dri_create_context, diff --git a/src/gallium/state_trackers/dri/dri_screen.h b/src/gallium/state_trackers/dri/dri_screen.h index 3b805c539f9..2b0444603a0 100644 --- a/src/gallium/state_trackers/dri/dri_screen.h +++ b/src/gallium/state_trackers/dri/dri_screen.h @@ -94,6 +94,9 @@ void dri_fill_st_visual(struct st_visual *stvis, struct dri_screen *screen, const __GLcontextModes *mode); +void +dri_destroy_screen(__DRIscreen * sPriv); + #endif /* vim: set sw=3 ts=8 sts=3 expandtab: */ diff --git a/src/gallium/state_trackers/dri/dri_st_api.c b/src/gallium/state_trackers/dri/dri_st_api.c index c067cee66cf..88cc410a9f9 100644 --- a/src/gallium/state_trackers/dri/dri_st_api.c +++ b/src/gallium/state_trackers/dri/dri_st_api.c @@ -29,7 +29,6 @@ #include "util/u_inlines.h" #include "util/u_format.h" #include "util/u_debug.h" -#include "state_tracker/drm_api.h" #include "state_tracker/st_manager.h" /* for st_manager_create_api */ #include "dri_screen.h" @@ -37,241 +36,7 @@ #include "dri_drawable.h" #include "dri_st_api.h" #include "dri1.h" - -static struct { - int32_t refcnt; - struct st_api *stapi; -} dri_st_api; - -/** - * Get the format of an attachment. - */ -static INLINE enum pipe_format -dri_drawable_get_format(struct dri_drawable *drawable, - enum st_attachment_type statt) -{ - enum pipe_format format; - - switch (statt) { - case ST_ATTACHMENT_FRONT_LEFT: - case ST_ATTACHMENT_BACK_LEFT: - case ST_ATTACHMENT_FRONT_RIGHT: - case ST_ATTACHMENT_BACK_RIGHT: - format = drawable->stvis.color_format; - break; - case ST_ATTACHMENT_DEPTH_STENCIL: - format = drawable->stvis.depth_stencil_format; - break; - default: - format = PIPE_FORMAT_NONE; - break; - } - - return format; -} - -/** - * Process __DRIbuffer and convert them into pipe_textures. - */ -static void -dri_drawable_process_buffers(struct dri_drawable *drawable, - __DRIbuffer *buffers, unsigned count) -{ - struct dri_screen *screen = dri_screen(drawable->sPriv); - __DRIdrawable *dri_drawable = drawable->dPriv; - struct pipe_texture templ; - struct winsys_handle whandle; - boolean have_depth = FALSE; - unsigned i; - - if (drawable->old_num == count && - drawable->old_w == dri_drawable->w && - drawable->old_h == dri_drawable->h && - memcmp(drawable->old, buffers, sizeof(__DRIbuffer) * count) == 0) - return; - - for (i = 0; i < ST_ATTACHMENT_COUNT; i++) - pipe_texture_reference(&drawable->textures[i], NULL); - - memset(&templ, 0, sizeof(templ)); - templ.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET; - templ.target = PIPE_TEXTURE_2D; - templ.last_level = 0; - templ.width0 = dri_drawable->w; - templ.height0 = dri_drawable->h; - templ.depth0 = 1; - - memset(&whandle, 0, sizeof(whandle)); - - for (i = 0; i < count; i++) { - __DRIbuffer *buf = &buffers[i]; - enum st_attachment_type statt; - enum pipe_format format; - - switch (buf->attachment) { - case __DRI_BUFFER_FRONT_LEFT: - if (!screen->auto_fake_front) { - statt = ST_ATTACHMENT_INVALID; - break; - } - /* fallthrough */ - case __DRI_BUFFER_FAKE_FRONT_LEFT: - statt = ST_ATTACHMENT_FRONT_LEFT; - break; - case __DRI_BUFFER_BACK_LEFT: - statt = ST_ATTACHMENT_BACK_LEFT; - break; - case __DRI_BUFFER_DEPTH: - case __DRI_BUFFER_DEPTH_STENCIL: - case __DRI_BUFFER_STENCIL: - /* use only the first depth/stencil buffer */ - if (!have_depth) { - have_depth = TRUE; - statt = ST_ATTACHMENT_DEPTH_STENCIL; - } - else { - statt = ST_ATTACHMENT_INVALID; - } - break; - default: - statt = ST_ATTACHMENT_INVALID; - break; - } - - format = dri_drawable_get_format(drawable, statt); - if (statt == ST_ATTACHMENT_INVALID || format == PIPE_FORMAT_NONE) - continue; - - templ.format = format; - whandle.handle = buf->name; - whandle.stride = buf->pitch; - - drawable->textures[statt] = - screen->pipe_screen->texture_from_handle(screen->pipe_screen, - &templ, &whandle); - } - - drawable->old_num = count; - drawable->old_w = dri_drawable->w; - drawable->old_h = dri_drawable->h; - memcpy(drawable->old, buffers, sizeof(__DRIbuffer) * count); -} - -/** - * Retrieve __DRIbuffer from the DRI loader. - */ -static __DRIbuffer * -dri_drawable_get_buffers(struct dri_drawable *drawable, - const enum st_attachment_type *statts, - unsigned *count) -{ - __DRIdrawable *dri_drawable = drawable->dPriv; - struct __DRIdri2LoaderExtensionRec *loader = drawable->sPriv->dri2.loader; - boolean with_format; - __DRIbuffer *buffers; - int num_buffers; - unsigned attachments[10]; - unsigned num_attachments, i; - - assert(loader); - with_format = dri_with_format(drawable->sPriv); - - num_attachments = 0; - - /* for Xserver 1.6.0 (DRI2 version 1) we always need to ask for the front */ - if (!with_format) - attachments[num_attachments++] = __DRI_BUFFER_FRONT_LEFT; - - for (i = 0; i < *count; i++) { - enum pipe_format format; - int att, bpp; - - format = dri_drawable_get_format(drawable, statts[i]); - if (format == PIPE_FORMAT_NONE) - continue; - - switch (statts[i]) { - case ST_ATTACHMENT_FRONT_LEFT: - /* already added */ - if (!with_format) - continue; - att = __DRI_BUFFER_FRONT_LEFT; - break; - case ST_ATTACHMENT_BACK_LEFT: - att = __DRI_BUFFER_BACK_LEFT; - break; - case ST_ATTACHMENT_FRONT_RIGHT: - att = __DRI_BUFFER_FRONT_RIGHT; - break; - case ST_ATTACHMENT_BACK_RIGHT: - att = __DRI_BUFFER_BACK_RIGHT; - break; - case ST_ATTACHMENT_DEPTH_STENCIL: - att = __DRI_BUFFER_DEPTH_STENCIL; - break; - default: - att = -1; - break; - } - - bpp = util_format_get_blocksizebits(format); - - if (att >= 0) { - attachments[num_attachments++] = att; - if (with_format) { - attachments[num_attachments++] = bpp; - } - } - } - - if (with_format) { - num_attachments /= 2; - buffers = loader->getBuffersWithFormat(dri_drawable, - &dri_drawable->w, &dri_drawable->h, - attachments, num_attachments, - &num_buffers, dri_drawable->loaderPrivate); - } - else { - buffers = loader->getBuffers(dri_drawable, - &dri_drawable->w, &dri_drawable->h, - attachments, num_attachments, - &num_buffers, dri_drawable->loaderPrivate); - } - - if (buffers) { - /* set one cliprect to cover the whole dri_drawable */ - dri_drawable->x = 0; - dri_drawable->y = 0; - dri_drawable->backX = 0; - dri_drawable->backY = 0; - dri_drawable->numClipRects = 1; - dri_drawable->pClipRects[0].x1 = 0; - dri_drawable->pClipRects[0].y1 = 0; - dri_drawable->pClipRects[0].x2 = dri_drawable->w; - dri_drawable->pClipRects[0].y2 = dri_drawable->h; - dri_drawable->numBackClipRects = 1; - dri_drawable->pBackClipRects[0].x1 = 0; - dri_drawable->pBackClipRects[0].y1 = 0; - dri_drawable->pBackClipRects[0].x2 = dri_drawable->w; - dri_drawable->pBackClipRects[0].y2 = dri_drawable->h; - - *count = num_buffers; - } - - return buffers; -} - -static void -dri_allocate_textures(struct dri_drawable *drawable, - const enum st_attachment_type *statts, - unsigned count) -{ - __DRIbuffer *buffers; - unsigned num_buffers = count; - - buffers = dri_drawable_get_buffers(drawable, statts, &num_buffers); - dri_drawable_process_buffers(drawable, buffers, num_buffers); -} +#include "dri2.h" static boolean dri_st_framebuffer_validate(struct st_framebuffer_iface *stfbi, @@ -329,21 +94,6 @@ dri_st_framebuffer_validate(struct st_framebuffer_iface *stfbi, return TRUE; } -static void -dri_flush_frontbuffer(struct dri_drawable *drawable, - enum st_attachment_type statt) -{ - __DRIdrawable *dri_drawable = drawable->dPriv; - struct __DRIdri2LoaderExtensionRec *loader = drawable->sPriv->dri2.loader; - - if (loader->flushFrontBuffer == NULL) - return; - - if (statt == ST_ATTACHMENT_FRONT_LEFT) { - loader->flushFrontBuffer(dri_drawable, dri_drawable->loaderPrivate); - } -} - static boolean dri_st_framebuffer_flush_front(struct st_framebuffer_iface *stfbi, enum st_attachment_type statt) @@ -419,6 +169,14 @@ dri_st_framebuffer_validate_att(struct st_framebuffer_iface *stfbi, stfbi->validate(stfbi, statts, count, NULL); } +/** + * Reference counted st_api. + */ +static struct { + int32_t refcnt; + struct st_api *stapi; +} dri_st_api; + /** * Add a reference to the st_api of the state tracker. */ -- cgit v1.2.3 From 4ce16e13ce5ca89943b86a8e8cdb5354892a13a6 Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Thu, 25 Mar 2010 17:01:53 +0200 Subject: st/dri: export DRI1 surface / pipe They will be used by DRISW. Also, add destroy functions. --- src/gallium/state_trackers/dri/Makefile | 1 + src/gallium/state_trackers/dri/SConscript | 1 + src/gallium/state_trackers/dri/dri1.c | 93 +++---------------- src/gallium/state_trackers/dri/dri1.h | 3 - src/gallium/state_trackers/dri/dri1_helper.c | 129 ++++++++++++++++++++++++++ src/gallium/state_trackers/dri/dri1_helper.h | 61 ++++++++++++ src/gallium/state_trackers/dri/dri_drawable.c | 7 +- src/gallium/state_trackers/dri/dri_screen.c | 5 +- src/gallium/state_trackers/dri/dri_st_api.c | 8 ++ 9 files changed, 218 insertions(+), 90 deletions(-) create mode 100644 src/gallium/state_trackers/dri/dri1_helper.c create mode 100644 src/gallium/state_trackers/dri/dri1_helper.h (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/dri/Makefile b/src/gallium/state_trackers/dri/Makefile index 6d95a277f82..f1a54e80b61 100644 --- a/src/gallium/state_trackers/dri/Makefile +++ b/src/gallium/state_trackers/dri/Makefile @@ -17,6 +17,7 @@ C_SOURCES = \ dri_drawable.c \ dri_extensions.c \ dri_st_api.c \ + dri1_helper.c \ dri1.c \ dri2.c diff --git a/src/gallium/state_trackers/dri/SConscript b/src/gallium/state_trackers/dri/SConscript index d6dc126723d..2ca9f420683 100644 --- a/src/gallium/state_trackers/dri/SConscript +++ b/src/gallium/state_trackers/dri/SConscript @@ -19,6 +19,7 @@ if env['dri']: 'dri_extensions.c', 'dri_screen.c', 'dri_st_api.c', + 'dri1_helper.c', 'dri1.c', 'dri2.c', ] diff --git a/src/gallium/state_trackers/dri/dri1.c b/src/gallium/state_trackers/dri/dri1.c index 9108d41bd94..98bdb2936a1 100644 --- a/src/gallium/state_trackers/dri/dri1.c +++ b/src/gallium/state_trackers/dri/dri1.c @@ -41,6 +41,7 @@ #include "dri_context.h" #include "dri_drawable.h" #include "dri_st_api.h" +#include "dri1_helper.h" #include "dri1.h" static INLINE void @@ -65,50 +66,6 @@ dri1_unlock(struct dri_context *ctx) DRM_UNLOCK(ctx->sPriv->fd, ctx->lock, ctx->cPriv->hHWContext); } -static struct pipe_fence_handle * -dri_swap_fences_pop_front(struct dri_drawable *draw) -{ - struct pipe_screen *screen = dri_screen(draw->sPriv)->pipe_screen; - struct pipe_fence_handle *fence = NULL; - - if (draw->cur_fences >= draw->desired_fences) { - screen->fence_reference(screen, &fence, draw->swap_fences[draw->tail]); - screen->fence_reference(screen, &draw->swap_fences[draw->tail++], NULL); - --draw->cur_fences; - draw->tail &= DRI_SWAP_FENCES_MASK; - } - return fence; -} - -static void -dri_swap_fences_push_back(struct dri_drawable *draw, - struct pipe_fence_handle *fence) -{ - struct pipe_screen *screen = dri_screen(draw->sPriv)->pipe_screen; - - if (!fence) - return; - - if (draw->cur_fences < DRI_SWAP_FENCES_MAX) { - draw->cur_fences++; - screen->fence_reference(screen, &draw->swap_fences[draw->head++], - fence); - draw->head &= DRI_SWAP_FENCES_MASK; - } -} - -void -dri1_swap_fences_clear(struct dri_drawable *drawable) -{ - struct pipe_screen *screen = dri_screen(drawable->sPriv)->pipe_screen; - struct pipe_fence_handle *fence; - - while (drawable->cur_fences) { - fence = dri_swap_fences_pop_front(drawable); - screen->fence_reference(screen, &fence, NULL); - } -} - static void dri1_update_drawables_locked(struct dri_context *ctx, __DRIdrawable * driDrawPriv, @@ -213,39 +170,6 @@ dri1_swap_copy(struct pipe_context *pipe, } } -static struct pipe_surface * -dri1_get_pipe_surface(struct dri_drawable *drawable, struct pipe_texture *ptex) -{ - struct pipe_screen *pipe_screen = dri_screen(drawable->sPriv)->pipe_screen; - struct pipe_surface *psurf = drawable->dri1_surface; - - if (!psurf || psurf->texture != ptex) { - pipe_surface_reference(&drawable->dri1_surface, NULL); - - drawable->dri1_surface = pipe_screen->get_tex_surface(pipe_screen, - ptex, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_READ); - - psurf = drawable->dri1_surface; - } - - return psurf; -} - -static struct pipe_context * -dri1_get_pipe_context(struct dri_drawable *drawable) -{ - struct dri_screen *screen = dri_screen(drawable->sPriv); - struct pipe_context *pipe = screen->dri1_pipe; - - if (!pipe) { - screen->dri1_pipe = - screen->pipe_screen->context_create(screen->pipe_screen, NULL); - pipe = screen->dri1_pipe; - } - - return pipe; -} - static void dri1_present_texture_locked(__DRIdrawable * dPriv, struct pipe_texture *ptex, @@ -253,6 +177,7 @@ dri1_present_texture_locked(__DRIdrawable * dPriv, struct pipe_fence_handle **fence) { struct dri_drawable *drawable = dri_drawable(dPriv); + struct dri_screen *screen = dri_screen(drawable->sPriv); struct pipe_context *pipe; struct pipe_surface *psurf; struct drm_clip_rect bbox; @@ -270,7 +195,7 @@ dri1_present_texture_locked(__DRIdrawable * dPriv, if (!visible) return; - pipe = dri1_get_pipe_context(drawable); + pipe = dri1_get_pipe_context(screen); psurf = dri1_get_pipe_surface(drawable, ptex); if (!pipe || !psurf) return; @@ -317,6 +242,10 @@ dri1_copy_to_front(struct dri_context *ctx, dri1_propagate_drawable_change(ctx); } +/* + * Backend functions for st_framebuffer interface and swap_buffers. + */ + void dri1_flush_frontbuffer(struct dri_drawable *draw, enum st_attachment_type statt) @@ -359,13 +288,13 @@ dri1_swap_buffers(__DRIdrawable * dPriv) ptex = draw->textures[ST_ATTACHMENT_BACK_LEFT]; if (ptex) { ctx->st->flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); - fence = dri_swap_fences_pop_front(draw); + fence = dri1_swap_fences_pop_front(draw); if (fence) { (void)pipe_screen->fence_finish(pipe_screen, fence, 0); pipe_screen->fence_reference(pipe_screen, &fence, NULL); } dri1_copy_to_front(ctx, ptex, dPriv, NULL, &fence); - dri_swap_fences_push_back(draw, fence); + dri1_swap_fences_push_back(draw, fence); pipe_screen->fence_reference(pipe_screen, &fence, NULL); } } @@ -513,6 +442,10 @@ static struct dri1_api_lock_funcs dri1_lf = { .clear_lost_lock = st_dri_clear_lost_lock }; +/* + * Backend function for init_screen. + */ + static const __DRIextension *dri1_screen_extensions[] = { &driReadDrawableExtension, &driCopySubBufferExtension.base, diff --git a/src/gallium/state_trackers/dri/dri1.h b/src/gallium/state_trackers/dri/dri1.h index f1004281b54..cced505ea97 100644 --- a/src/gallium/state_trackers/dri/dri1.h +++ b/src/gallium/state_trackers/dri/dri1.h @@ -56,7 +56,4 @@ void dri1_swap_buffers(__DRIdrawable * dPriv); void dri1_copy_sub_buffer(__DRIdrawable * dPriv, int x, int y, int w, int h); -void -dri1_swap_fences_clear(struct dri_drawable *drawable); - #endif /* DRI1_H */ diff --git a/src/gallium/state_trackers/dri/dri1_helper.c b/src/gallium/state_trackers/dri/dri1_helper.c new file mode 100644 index 00000000000..7eeb868d422 --- /dev/null +++ b/src/gallium/state_trackers/dri/dri1_helper.c @@ -0,0 +1,129 @@ +/************************************************************************** + * + * Copyright 2009, VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ +/* + * Management of pipe objects (surface / pipe / fences) used by DRI1 and DRISW. + * + * Author: Keith Whitwell + * Author: Jakob Bornecrantz + */ + +#include "util/u_inlines.h" +#include "pipe/p_context.h" + +#include "dri_screen.h" +#include "dri_context.h" +#include "dri_drawable.h" +#include "dri1_helper.h" + +struct pipe_fence_handle * +dri1_swap_fences_pop_front(struct dri_drawable *draw) +{ + struct pipe_screen *screen = dri_screen(draw->sPriv)->pipe_screen; + struct pipe_fence_handle *fence = NULL; + + if (draw->cur_fences >= draw->desired_fences) { + screen->fence_reference(screen, &fence, draw->swap_fences[draw->tail]); + screen->fence_reference(screen, &draw->swap_fences[draw->tail++], NULL); + --draw->cur_fences; + draw->tail &= DRI_SWAP_FENCES_MASK; + } + return fence; +} + +void +dri1_swap_fences_push_back(struct dri_drawable *draw, + struct pipe_fence_handle *fence) +{ + struct pipe_screen *screen = dri_screen(draw->sPriv)->pipe_screen; + + if (!fence) + return; + + if (draw->cur_fences < DRI_SWAP_FENCES_MAX) { + draw->cur_fences++; + screen->fence_reference(screen, &draw->swap_fences[draw->head++], + fence); + draw->head &= DRI_SWAP_FENCES_MASK; + } +} + +void +dri1_swap_fences_clear(struct dri_drawable *drawable) +{ + struct pipe_screen *screen = dri_screen(drawable->sPriv)->pipe_screen; + struct pipe_fence_handle *fence; + + while (drawable->cur_fences) { + fence = dri1_swap_fences_pop_front(drawable); + screen->fence_reference(screen, &fence, NULL); + } +} + +struct pipe_surface * +dri1_get_pipe_surface(struct dri_drawable *drawable, struct pipe_texture *ptex) +{ + struct pipe_screen *pipe_screen = dri_screen(drawable->sPriv)->pipe_screen; + struct pipe_surface *psurf = drawable->dri1_surface; + + if (!psurf || psurf->texture != ptex) { + pipe_surface_reference(&drawable->dri1_surface, NULL); + + drawable->dri1_surface = pipe_screen->get_tex_surface(pipe_screen, + ptex, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_READ); + + psurf = drawable->dri1_surface; + } + + return psurf; +} + +void +dri1_destroy_pipe_surface(struct dri_drawable *drawable) +{ + pipe_surface_reference(&drawable->dri1_surface, NULL); +} + +struct pipe_context * +dri1_get_pipe_context(struct dri_screen *screen) +{ + struct pipe_context *pipe = screen->dri1_pipe; + + if (!pipe) { + screen->dri1_pipe = + screen->pipe_screen->context_create(screen->pipe_screen, NULL); + pipe = screen->dri1_pipe; + } + + return pipe; +} + +void +dri1_destroy_pipe_context(struct dri_screen *screen) +{ + if (screen->dri1_pipe) + screen->dri1_pipe->destroy(screen->dri1_pipe); +} diff --git a/src/gallium/state_trackers/dri/dri1_helper.h b/src/gallium/state_trackers/dri/dri1_helper.h new file mode 100644 index 00000000000..3254b7ff872 --- /dev/null +++ b/src/gallium/state_trackers/dri/dri1_helper.h @@ -0,0 +1,61 @@ +/************************************************************************** + * + * Copyright 2009, VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ +/* + * Author: Keith Whitwell + * Author: Jakob Bornecrantz + */ + +#ifndef DRI1_HELPER_H +#define DRI1_HELPER_H + +#include "dri_screen.h" +#include "dri_context.h" +#include "dri_drawable.h" + +struct pipe_fence_handle * +dri1_swap_fences_pop_front(struct dri_drawable *draw); + +void +dri1_swap_fences_push_back(struct dri_drawable *draw, + struct pipe_fence_handle *fence); + +void +dri1_swap_fences_clear(struct dri_drawable *drawable); + +struct pipe_surface * +dri1_get_pipe_surface(struct dri_drawable *drawable, struct pipe_texture *ptex); + +void +dri1_destroy_pipe_surface(struct dri_drawable *drawable); + +struct pipe_context * +dri1_get_pipe_context(struct dri_screen *screen); + +void +dri1_destroy_pipe_context(struct dri_screen *screen); + +#endif /* DRI1_HELPER_H */ diff --git a/src/gallium/state_trackers/dri/dri_drawable.c b/src/gallium/state_trackers/dri/dri_drawable.c index 9b0ae8b27a9..75b4cc56289 100644 --- a/src/gallium/state_trackers/dri/dri_drawable.c +++ b/src/gallium/state_trackers/dri/dri_drawable.c @@ -33,7 +33,7 @@ #include "dri_context.h" #include "dri_drawable.h" #include "dri_st_api.h" -#include "dri1.h" +#include "dri1_helper.h" #include "pipe/p_screen.h" #include "util/u_format.h" @@ -79,13 +79,10 @@ void dri_destroy_buffer(__DRIdrawable * dPriv) { struct dri_drawable *drawable = dri_drawable(dPriv); - int i; dri1_swap_fences_clear(drawable); - pipe_surface_reference(&drawable->dri1_surface, NULL); - for (i = 0; i < ST_ATTACHMENT_COUNT; i++) - pipe_texture_reference(&drawable->textures[i], NULL); + dri1_destroy_pipe_surface(drawable); dri_destroy_st_framebuffer(drawable->stfb); diff --git a/src/gallium/state_trackers/dri/dri_screen.c b/src/gallium/state_trackers/dri/dri_screen.c index 6aef2d57002..1d808f0f7f9 100644 --- a/src/gallium/state_trackers/dri/dri_screen.c +++ b/src/gallium/state_trackers/dri/dri_screen.c @@ -37,6 +37,7 @@ #include "dri_context.h" #include "dri_drawable.h" #include "dri_st_api.h" +#include "dri1_helper.h" #include "dri1.h" #include "dri2.h" @@ -292,11 +293,11 @@ dri_destroy_screen(__DRIscreen * sPriv) { struct dri_screen *screen = dri_screen(sPriv); - if (screen->dri1_pipe) - screen->dri1_pipe->destroy(screen->dri1_pipe); + dri1_destroy_pipe_context(screen); if (screen->smapi) dri_destroy_st_manager(screen->smapi); + if (screen->pipe_screen) screen->pipe_screen->destroy(screen->pipe_screen); diff --git a/src/gallium/state_trackers/dri/dri_st_api.c b/src/gallium/state_trackers/dri/dri_st_api.c index 88cc410a9f9..3592a782229 100644 --- a/src/gallium/state_trackers/dri/dri_st_api.c +++ b/src/gallium/state_trackers/dri/dri_st_api.c @@ -35,6 +35,7 @@ #include "dri_context.h" #include "dri_drawable.h" #include "dri_st_api.h" +#include "dri1_helper.h" #include "dri1.h" #include "dri2.h" @@ -136,6 +137,13 @@ dri_create_st_framebuffer(struct dri_drawable *drawable) void dri_destroy_st_framebuffer(struct st_framebuffer_iface *stfbi) { + struct dri_drawable *drawable = + (struct dri_drawable *) stfbi->st_manager_private; + int i; + + for (i = 0; i < ST_ATTACHMENT_COUNT; i++) + pipe_texture_reference(&drawable->textures[i], NULL); + FREE(stfbi); } -- cgit v1.2.3 From 1bed0eb98e00ed9ea7431f19ab3bed8860864264 Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Thu, 25 Mar 2010 17:01:53 +0200 Subject: st/dri: add dri_wrapper.h --- src/gallium/state_trackers/dri/dri1.h | 2 +- src/gallium/state_trackers/dri/dri2.h | 2 +- src/gallium/state_trackers/dri/dri_context.c | 1 - src/gallium/state_trackers/dri/dri_context.h | 3 +-- src/gallium/state_trackers/dri/dri_screen.h | 2 +- src/gallium/state_trackers/dri/dri_wrapper.h | 10 ++++++++++ 6 files changed, 14 insertions(+), 6 deletions(-) create mode 100644 src/gallium/state_trackers/dri/dri_wrapper.h (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/dri/dri1.h b/src/gallium/state_trackers/dri/dri1.h index cced505ea97..f7441f98abc 100644 --- a/src/gallium/state_trackers/dri/dri1.h +++ b/src/gallium/state_trackers/dri/dri1.h @@ -36,7 +36,7 @@ #include "dri_drawable.h" #include "state_tracker/st_api.h" -#include "dri_util.h" +#include "dri_wrapper.h" extern struct dri1_api *__dri1_api_hooks; diff --git a/src/gallium/state_trackers/dri/dri2.h b/src/gallium/state_trackers/dri/dri2.h index 06abccc405f..e1afcf8ca8d 100644 --- a/src/gallium/state_trackers/dri/dri2.h +++ b/src/gallium/state_trackers/dri/dri2.h @@ -29,7 +29,7 @@ #define DRI2_H #include "dri_drawable.h" -#include "dri_util.h" +#include "dri_wrapper.h" const __DRIconfig ** dri_init_screen2(__DRIscreen * sPriv); diff --git a/src/gallium/state_trackers/dri/dri_context.c b/src/gallium/state_trackers/dri/dri_context.c index 54568a8b220..34d9a932ead 100644 --- a/src/gallium/state_trackers/dri/dri_context.c +++ b/src/gallium/state_trackers/dri/dri_context.c @@ -33,7 +33,6 @@ #include "dri_drawable.h" #include "dri_context.h" #include "dri_st_api.h" -#include "dri1.h" #include "pipe/p_context.h" #include "util/u_memory.h" diff --git a/src/gallium/state_trackers/dri/dri_context.h b/src/gallium/state_trackers/dri/dri_context.h index 845b420cf89..24d3d0368a4 100644 --- a/src/gallium/state_trackers/dri/dri_context.h +++ b/src/gallium/state_trackers/dri/dri_context.h @@ -33,8 +33,7 @@ #define DRI_CONTEXT_H #include "pipe/p_compiler.h" -#include "drm.h" -#include "dri_util.h" +#include "dri_wrapper.h" struct pipe_context; struct pipe_fence; diff --git a/src/gallium/state_trackers/dri/dri_screen.h b/src/gallium/state_trackers/dri/dri_screen.h index 2b0444603a0..639d48661e2 100644 --- a/src/gallium/state_trackers/dri/dri_screen.h +++ b/src/gallium/state_trackers/dri/dri_screen.h @@ -32,7 +32,7 @@ #ifndef DRI_SCREEN_H #define DRI_SCREEN_H -#include "dri_util.h" +#include "dri_wrapper.h" #include "xmlconfig.h" #include "pipe/p_compiler.h" diff --git a/src/gallium/state_trackers/dri/dri_wrapper.h b/src/gallium/state_trackers/dri/dri_wrapper.h new file mode 100644 index 00000000000..141ba02706a --- /dev/null +++ b/src/gallium/state_trackers/dri/dri_wrapper.h @@ -0,0 +1,10 @@ +#ifndef DRI_WRAPPER_H +#define DRI_WRAPPER_H + +#ifndef __NOT_HAVE_DRM_H +#include "dri_util.h" +#else +#include "drisw_util.h" +#endif + +#endif -- cgit v1.2.3 From 5b75e12f9165c890fd14b22983d6289be8f20abc Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Thu, 25 Mar 2010 17:01:53 +0200 Subject: st/dri: add drisw --- src/gallium/include/state_tracker/drm_api.h | 1 + src/gallium/state_trackers/dri/dri_screen.c | 33 ++++ src/gallium/state_trackers/dri/dri_screen.h | 12 ++ src/gallium/state_trackers/dri/dri_st_api.c | 12 ++ src/gallium/state_trackers/dri/drisw.c | 288 ++++++++++++++++++++++++++++ src/gallium/state_trackers/dri/drisw.h | 54 ++++++ 6 files changed, 400 insertions(+) create mode 100644 src/gallium/state_trackers/dri/drisw.c create mode 100644 src/gallium/state_trackers/dri/drisw.h (limited to 'src/gallium') diff --git a/src/gallium/include/state_tracker/drm_api.h b/src/gallium/include/state_tracker/drm_api.h index fe7ef253ef0..9780cf250b8 100644 --- a/src/gallium/include/state_tracker/drm_api.h +++ b/src/gallium/include/state_tracker/drm_api.h @@ -13,6 +13,7 @@ struct pipe_texture; enum drm_create_screen_mode { DRM_CREATE_NORMAL = 0, DRM_CREATE_DRI1, + DRM_CREATE_DRISW, DRM_CREATE_DRIVER = 1024, DRM_CREATE_MAX }; diff --git a/src/gallium/state_trackers/dri/dri_screen.c b/src/gallium/state_trackers/dri/dri_screen.c index 1d808f0f7f9..ae311641042 100644 --- a/src/gallium/state_trackers/dri/dri_screen.c +++ b/src/gallium/state_trackers/dri/dri_screen.c @@ -30,7 +30,9 @@ */ #include "utils.h" +#ifndef __NOT_HAVE_DRM_H #include "vblank.h" +#endif #include "xmlpool.h" #include "dri_screen.h" @@ -40,6 +42,7 @@ #include "dri1_helper.h" #include "dri1.h" #include "dri2.h" +#include "drisw.h" #include "util/u_inlines.h" #include "pipe/p_screen.h" @@ -262,6 +265,8 @@ dri_fill_st_visual(struct st_visual *stvis, struct dri_screen *screen, /* let the state tracker allocate the accum buffer */ } +#ifndef __NOT_HAVE_DRM_H + /** * Get information about previous buffer swaps. */ @@ -274,6 +279,8 @@ dri_get_swap_info(__DRIdrawable * dPriv, __DRIswapInfo * sInfo) return 0; } +#endif + static void dri_destroy_option_cache(struct dri_screen * screen) { @@ -308,6 +315,8 @@ dri_destroy_screen(__DRIscreen * sPriv) sPriv->extensions = NULL; } +#ifndef __NOT_HAVE_DRM_H + const struct __DriverAPIRec driDriverAPI = { .DestroyScreen = dri_destroy_screen, .CreateContext = dri_create_context, @@ -334,4 +343,28 @@ PUBLIC const __DRIextension *__driDriverExtensions[] = { NULL }; +#else + +const struct __DriverAPIRec driDriverAPI = { + .DestroyScreen = dri_destroy_screen, + .CreateContext = dri_create_context, + .DestroyContext = dri_destroy_context, + .CreateBuffer = dri_create_buffer, + .DestroyBuffer = dri_destroy_buffer, + .MakeCurrent = dri_make_current, + .UnbindContext = dri_unbind_context, + + .InitScreen = drisw_init_screen, + .SwapBuffers = drisw_swap_buffers, +}; + +/* This is the table of extensions that the loader will dlsym() for. */ +PUBLIC const __DRIextension *__driDriverExtensions[] = { + &driCoreExtension.base, + &driSWRastExtension.base, + NULL +}; + +#endif + /* vim: set sw=3 ts=8 sts=3 expandtab: */ diff --git a/src/gallium/state_trackers/dri/dri_screen.h b/src/gallium/state_trackers/dri/dri_screen.h index 639d48661e2..4f59db37cfa 100644 --- a/src/gallium/state_trackers/dri/dri_screen.h +++ b/src/gallium/state_trackers/dri/dri_screen.h @@ -75,6 +75,8 @@ dri_screen(__DRIscreen * sPriv) return (struct dri_screen *)sPriv->private; } +#ifndef __NOT_HAVE_DRM_H + static INLINE boolean dri_with_format(__DRIscreen * sPriv) { @@ -85,6 +87,16 @@ dri_with_format(__DRIscreen * sPriv) && (loader->getBuffersWithFormat != NULL); } +#else + +static INLINE boolean +dri_with_format(__DRIscreen * sPriv) +{ + return TRUE; +} + +#endif + extern const uint __driNConfigOptions; const __DRIconfig ** diff --git a/src/gallium/state_trackers/dri/dri_st_api.c b/src/gallium/state_trackers/dri/dri_st_api.c index 3592a782229..2b98c487c84 100644 --- a/src/gallium/state_trackers/dri/dri_st_api.c +++ b/src/gallium/state_trackers/dri/dri_st_api.c @@ -38,6 +38,7 @@ #include "dri1_helper.h" #include "dri1.h" #include "dri2.h" +#include "drisw.h" static boolean dri_st_framebuffer_validate(struct st_framebuffer_iface *stfbi, @@ -67,12 +68,19 @@ dri_st_framebuffer_validate(struct st_framebuffer_iface *stfbi, if (new_stamp || new_mask) { +#ifndef __NOT_HAVE_DRM_H if (__dri1_api_hooks) { dri1_allocate_textures(drawable, statt_mask); } else { dri_allocate_textures(drawable, statts, count); } +#else + if (new_stamp) + drisw_update_drawable_info(drawable->dPriv); + + drisw_allocate_textures(drawable, statt_mask); +#endif /* add existing textures */ for (i = 0; i < ST_ATTACHMENT_COUNT; i++) { @@ -102,12 +110,16 @@ dri_st_framebuffer_flush_front(struct st_framebuffer_iface *stfbi, struct dri_drawable *drawable = (struct dri_drawable *) stfbi->st_manager_private; +#ifndef __NOT_HAVE_DRM_H if (__dri1_api_hooks) { dri1_flush_frontbuffer(drawable, statt); } else { dri_flush_frontbuffer(drawable, statt); } +#else + drisw_flush_frontbuffer(drawable, statt); +#endif return TRUE; } diff --git a/src/gallium/state_trackers/dri/drisw.c b/src/gallium/state_trackers/dri/drisw.c new file mode 100644 index 00000000000..b3d65df8815 --- /dev/null +++ b/src/gallium/state_trackers/dri/drisw.c @@ -0,0 +1,288 @@ +/************************************************************************** + * + * Copyright 2009, VMware, Inc. + * All Rights Reserved. + * Copyright 2010 George Sapountzis + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#include "util/u_memory.h" +#include "util/u_inlines.h" +#include "pipe/p_context.h" +#include "state_tracker/drm_api.h" + +#include "dri_screen.h" +#include "dri_context.h" +#include "dri_drawable.h" +#include "dri_st_api.h" +#include "dri1_helper.h" +#include "drisw.h" + + +static INLINE void +get_drawable_info(__DRIdrawable *dPriv, int *w, int *h) +{ + __DRIscreen *sPriv = dPriv->driScreenPriv; + const __DRIswrastLoaderExtension *loader = sPriv->swrast_loader; + int x, y; + + loader->getDrawableInfo(dPriv, + &x, &y, w, h, + dPriv->loaderPrivate); +} + +static INLINE void +put_image(__DRIdrawable *dPriv, void *data) +{ + __DRIscreen *sPriv = dPriv->driScreenPriv; + const __DRIswrastLoaderExtension *loader = sPriv->swrast_loader; + + loader->putImage(dPriv, __DRI_SWRAST_IMAGE_OP_SWAP, + 0, 0, dPriv->w, dPriv->h, + data, dPriv->loaderPrivate); +} + +void +drisw_update_drawable_info(__DRIdrawable *dPriv) +{ + get_drawable_info(dPriv, &dPriv->w, &dPriv->h); +} + +static INLINE void +drisw_present_texture(__DRIdrawable *dPriv, + struct pipe_texture *ptex) +{ + struct dri_drawable *drawable = dri_drawable(dPriv); + struct dri_screen *screen = dri_screen(drawable->sPriv); + struct pipe_context *pipe; + struct pipe_surface *psurf; + struct pipe_transfer *ptrans; + void *pmap; + + pipe = dri1_get_pipe_context(screen); + psurf = dri1_get_pipe_surface(drawable, ptex); + if (!pipe || !psurf) + return; + + ptrans = pipe->get_tex_transfer(pipe, ptex, 0, 0, 0, + PIPE_TRANSFER_READ, + 0, 0, dPriv->w, dPriv->h); + + pmap = pipe->transfer_map(pipe, ptrans); + + assert(pmap); + + put_image(dPriv, pmap); + + pipe->transfer_unmap(pipe, ptrans); + + pipe->tex_transfer_destroy(pipe, ptrans); +} + +static INLINE void +drisw_invalidate_drawable(__DRIdrawable *dPriv) +{ + struct dri_context *ctx = dri_get_current(); + struct dri_drawable *drawable = dri_drawable(dPriv); + + drawable->texture_stamp = dPriv->lastStamp - 1; + + /* check if swapping currently bound buffer */ + if (ctx && ctx->dPriv == dPriv) + ctx->st->notify_invalid_framebuffer(ctx->st, drawable->stfb); +} + +static INLINE void +drisw_copy_to_front(__DRIdrawable * dPriv, + struct pipe_texture *ptex) +{ + drisw_present_texture(dPriv, ptex); + + drisw_invalidate_drawable(dPriv); +} + +/* + * Backend functions for st_framebuffer interface and swap_buffers. + */ + +void +drisw_flush_frontbuffer(struct dri_drawable *drawable, + enum st_attachment_type statt) +{ + struct dri_context *ctx = dri_get_current(); + struct pipe_texture *ptex; + + if (!ctx) + return; + + ptex = drawable->textures[statt]; + + if (ptex) { + drisw_copy_to_front(ctx->dPriv, ptex); + } +} + +void +drisw_swap_buffers(__DRIdrawable *dPriv) +{ + struct dri_context *ctx = dri_get_current(); + struct dri_drawable *drawable = dri_drawable(dPriv); + struct pipe_texture *ptex; + + if (!ctx) + return; + + ptex = drawable->textures[ST_ATTACHMENT_BACK_LEFT]; + + if (ptex) { + ctx->st->flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); + + drisw_copy_to_front(dPriv, ptex); + } +} + +/** + * Allocate framebuffer attachments. + * + * During fixed-size operation, the function keeps allocating new attachments + * as they are requested. Unused attachments are not removed, not until the + * framebuffer is resized or destroyed. + * + * It should be possible for DRI1 and DRISW to share this function, but it + * seems a better seperation and safer for each DRI version to provide its own + * function. + */ +void +drisw_allocate_textures(struct dri_drawable *drawable, + unsigned mask) +{ + struct dri_screen *screen = dri_screen(drawable->sPriv); + struct pipe_texture templ; + unsigned width, height; + boolean resized; + int i; + + width = drawable->dPriv->w; + height = drawable->dPriv->h; + + resized = (drawable->old_w != width || + drawable->old_h != height); + + /* remove outdated textures */ + if (resized) { + for (i = 0; i < ST_ATTACHMENT_COUNT; i++) + pipe_texture_reference(&drawable->textures[i], NULL); + } + + memset(&templ, 0, sizeof(templ)); + templ.target = PIPE_TEXTURE_2D; + templ.width0 = width; + templ.height0 = height; + templ.depth0 = 1; + templ.last_level = 0; + + for (i = 0; i < ST_ATTACHMENT_COUNT; i++) { + enum pipe_format format; + unsigned tex_usage; + + /* the texture already exists or not requested */ + if (drawable->textures[i] || !(mask & (1 << i))) { + continue; + } + + switch (i) { + case ST_ATTACHMENT_FRONT_LEFT: + case ST_ATTACHMENT_BACK_LEFT: + case ST_ATTACHMENT_FRONT_RIGHT: + case ST_ATTACHMENT_BACK_RIGHT: + format = drawable->stvis.color_format; + tex_usage = PIPE_TEXTURE_USAGE_DISPLAY_TARGET | + PIPE_TEXTURE_USAGE_RENDER_TARGET; + break; + case ST_ATTACHMENT_DEPTH_STENCIL: + format = drawable->stvis.depth_stencil_format; + tex_usage = PIPE_TEXTURE_USAGE_DEPTH_STENCIL; + break; + default: + format = PIPE_FORMAT_NONE; + break; + } + + if (format != PIPE_FORMAT_NONE) { + templ.format = format; + templ.tex_usage = tex_usage; + + drawable->textures[i] = + screen->pipe_screen->texture_create(screen->pipe_screen, &templ); + } + } + + drawable->old_w = width; + drawable->old_h = height; +} + +/* + * Backend function for init_screen. + */ + +static const __DRIextension *drisw_screen_extensions[] = { + NULL +}; + +const __DRIconfig ** +drisw_init_screen(__DRIscreen * sPriv) +{ + struct dri_screen *screen; + struct drm_create_screen_arg arg; + + screen = CALLOC_STRUCT(dri_screen); + if (!screen) + return NULL; + + screen->api = drm_api_create(); + screen->sPriv = sPriv; + screen->fd = -1; + sPriv->private = (void *)screen; + sPriv->extensions = drisw_screen_extensions; + arg.mode = DRM_CREATE_DRISW; + + screen->pipe_screen = screen->api->create_screen(screen->api, -1, &arg); + if (!screen->pipe_screen) { + debug_printf("%s: failed to create pipe_screen\n", __FUNCTION__); + goto fail; + } + + screen->smapi = dri_create_st_manager(screen); + if (!screen->smapi) + goto fail; + + driParseOptionInfo(&screen->optionCache, + __driConfigOptions, __driNConfigOptions); + + return dri_fill_in_modes(screen, 32); +fail: + dri_destroy_screen(sPriv); + return NULL; +} + +/* vim: set sw=3 ts=8 sts=3 expandtab: */ diff --git a/src/gallium/state_trackers/dri/drisw.h b/src/gallium/state_trackers/dri/drisw.h new file mode 100644 index 00000000000..2c0d5610fac --- /dev/null +++ b/src/gallium/state_trackers/dri/drisw.h @@ -0,0 +1,54 @@ +/************************************************************************** + * + * Copyright 2009, VMware, Inc. + * All Rights Reserved. + * Copyright 2010 George Sapountzis + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef DRISW_H +#define DRISW_H + +#include "dri_context.h" +#include "dri_drawable.h" + +#include "state_tracker/st_api.h" +#include "dri_wrapper.h" + +const __DRIconfig ** +drisw_init_screen(__DRIscreen * sPriv); + +void +drisw_update_drawable_info(__DRIdrawable *dPriv); + +void +drisw_flush_frontbuffer(struct dri_drawable *drawable, + enum st_attachment_type statt); + +void +drisw_allocate_textures(struct dri_drawable *drawable, + unsigned mask); + +void drisw_swap_buffers(__DRIdrawable * dPriv); + +#endif /* DRISW_H */ -- cgit v1.2.3 From 992e9572bdbc1f3d5243ca8eecbd6a372721a62b Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Thu, 25 Mar 2010 17:01:53 +0200 Subject: swrastg_dri: add state_tracker --- configure.ac | 2 +- src/gallium/state_trackers/drisw/Makefile | 26 +++++++++++++++++++++++ src/gallium/state_trackers/drisw/dri1_helper.c | 1 + src/gallium/state_trackers/drisw/dri_context.c | 1 + src/gallium/state_trackers/drisw/dri_drawable.c | 1 + src/gallium/state_trackers/drisw/dri_extensions.c | 1 + src/gallium/state_trackers/drisw/dri_screen.c | 1 + src/gallium/state_trackers/drisw/dri_st_api.c | 1 + src/gallium/state_trackers/drisw/drisw.c | 1 + 9 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/gallium/state_trackers/drisw/Makefile create mode 120000 src/gallium/state_trackers/drisw/dri1_helper.c create mode 120000 src/gallium/state_trackers/drisw/dri_context.c create mode 120000 src/gallium/state_trackers/drisw/dri_drawable.c create mode 120000 src/gallium/state_trackers/drisw/dri_extensions.c create mode 120000 src/gallium/state_trackers/drisw/dri_screen.c create mode 120000 src/gallium/state_trackers/drisw/dri_st_api.c create mode 120000 src/gallium/state_trackers/drisw/drisw.c (limited to 'src/gallium') diff --git a/configure.ac b/configure.ac index edf2363a717..1b9500b8b5a 100644 --- a/configure.ac +++ b/configure.ac @@ -1204,7 +1204,7 @@ yes) GALLIUM_STATE_TRACKERS_DIRS=glx ;; dri) - GALLIUM_STATE_TRACKERS_DIRS="dri" + GALLIUM_STATE_TRACKERS_DIRS="dri drisw" if test "x$enable_egl" = xyes; then GALLIUM_STATE_TRACKERS_DIRS="$GALLIUM_STATE_TRACKERS_DIRS egl" fi diff --git a/src/gallium/state_trackers/drisw/Makefile b/src/gallium/state_trackers/drisw/Makefile new file mode 100644 index 00000000000..dec9a39edec --- /dev/null +++ b/src/gallium/state_trackers/drisw/Makefile @@ -0,0 +1,26 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +LIBNAME = drisw + +LIBRARY_DEFINES = -D__NOT_HAVE_DRM_H + +LIBRARY_INCLUDES = \ + -I../dri \ + -I$(TOP)/include \ + -I$(TOP)/src/mesa \ + -I$(TOP)/src/mesa/drivers/dri/common \ + -I$(TOP)/src/mesa/main \ + -D__NOT_HAVE_DRM_H + + +C_SOURCES = \ + dri_context.c \ + dri_screen.c \ + dri_drawable.c \ + dri_extensions.c \ + dri_st_api.c \ + dri1_helper.c \ + drisw.c + +include ../../Makefile.template diff --git a/src/gallium/state_trackers/drisw/dri1_helper.c b/src/gallium/state_trackers/drisw/dri1_helper.c new file mode 120000 index 00000000000..e704e382e05 --- /dev/null +++ b/src/gallium/state_trackers/drisw/dri1_helper.c @@ -0,0 +1 @@ +../dri/dri1_helper.c \ No newline at end of file diff --git a/src/gallium/state_trackers/drisw/dri_context.c b/src/gallium/state_trackers/drisw/dri_context.c new file mode 120000 index 00000000000..e4e879dc867 --- /dev/null +++ b/src/gallium/state_trackers/drisw/dri_context.c @@ -0,0 +1 @@ +../dri/dri_context.c \ No newline at end of file diff --git a/src/gallium/state_trackers/drisw/dri_drawable.c b/src/gallium/state_trackers/drisw/dri_drawable.c new file mode 120000 index 00000000000..d7f65c85d20 --- /dev/null +++ b/src/gallium/state_trackers/drisw/dri_drawable.c @@ -0,0 +1 @@ +../dri/dri_drawable.c \ No newline at end of file diff --git a/src/gallium/state_trackers/drisw/dri_extensions.c b/src/gallium/state_trackers/drisw/dri_extensions.c new file mode 120000 index 00000000000..60ecde9547d --- /dev/null +++ b/src/gallium/state_trackers/drisw/dri_extensions.c @@ -0,0 +1 @@ +../dri/dri_extensions.c \ No newline at end of file diff --git a/src/gallium/state_trackers/drisw/dri_screen.c b/src/gallium/state_trackers/drisw/dri_screen.c new file mode 120000 index 00000000000..f22c562c84f --- /dev/null +++ b/src/gallium/state_trackers/drisw/dri_screen.c @@ -0,0 +1 @@ +../dri/dri_screen.c \ No newline at end of file diff --git a/src/gallium/state_trackers/drisw/dri_st_api.c b/src/gallium/state_trackers/drisw/dri_st_api.c new file mode 120000 index 00000000000..eac8ec66905 --- /dev/null +++ b/src/gallium/state_trackers/drisw/dri_st_api.c @@ -0,0 +1 @@ +../dri/dri_st_api.c \ No newline at end of file diff --git a/src/gallium/state_trackers/drisw/drisw.c b/src/gallium/state_trackers/drisw/drisw.c new file mode 120000 index 00000000000..258a79021ef --- /dev/null +++ b/src/gallium/state_trackers/drisw/drisw.c @@ -0,0 +1 @@ +../dri/drisw.c \ No newline at end of file -- cgit v1.2.3 From 007e0e3ef90d73f232c463e353da13378ffcef63 Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Thu, 25 Mar 2010 17:01:54 +0200 Subject: swrastg_dri: add winsys and target --- src/gallium/targets/dri-swrast/Makefile | 30 ++++ src/gallium/targets/dri-swrast/swrast_drm_api.c | 93 +++++++++++ src/gallium/winsys/sw/dri/Makefile | 13 ++ src/gallium/winsys/sw/dri/dri_sw_winsys.c | 197 ++++++++++++++++++++++++ src/gallium/winsys/sw/dri/dri_sw_winsys.h | 36 +++++ 5 files changed, 369 insertions(+) create mode 100644 src/gallium/targets/dri-swrast/Makefile create mode 100644 src/gallium/targets/dri-swrast/swrast_drm_api.c create mode 100644 src/gallium/winsys/sw/dri/Makefile create mode 100644 src/gallium/winsys/sw/dri/dri_sw_winsys.c create mode 100644 src/gallium/winsys/sw/dri/dri_sw_winsys.h (limited to 'src/gallium') diff --git a/src/gallium/targets/dri-swrast/Makefile b/src/gallium/targets/dri-swrast/Makefile new file mode 100644 index 00000000000..57a9e02a4bb --- /dev/null +++ b/src/gallium/targets/dri-swrast/Makefile @@ -0,0 +1,30 @@ +TOP = ../../../.. +include $(TOP)/configs/current + +LIBNAME = swrastg_dri.so + +DRIVER_DEFINES = -D__NOT_HAVE_DRM_H + +PIPE_DRIVERS = \ + $(TOP)/src/gallium/state_trackers/drisw/libdrisw.a \ + $(TOP)/src/gallium/winsys/sw/dri/libswdri.a \ + $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a + +SWRAST_COMMON_GALLIUM_SOURCES = \ + $(TOP)/src/mesa/drivers/dri/common/utils.c \ + $(TOP)/src/mesa/drivers/dri/common/drisw_util.c \ + $(TOP)/src/mesa/drivers/dri/common/xmlconfig.c + +C_SOURCES = \ + swrast_drm_api.c \ + $(SWRAST_COMMON_GALLIUM_SOURCES) \ + $(DRIVER_SOURCES) + +ASM_SOURCES = + +include ../Makefile.dri + +INCLUDES += \ + -I$(TOP)/src/gallium/winsys/sw/dri + +symlinks: diff --git a/src/gallium/targets/dri-swrast/swrast_drm_api.c b/src/gallium/targets/dri-swrast/swrast_drm_api.c new file mode 100644 index 00000000000..211836d784f --- /dev/null +++ b/src/gallium/targets/dri-swrast/swrast_drm_api.c @@ -0,0 +1,93 @@ +/************************************************************************** + * + * Copyright 2009, VMware, Inc. + * All Rights Reserved. + * Copyright 2010 George Sapountzis + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#include "pipe/p_compiler.h" +#include "util/u_memory.h" + +#include "softpipe/sp_public.h" +#include "state_tracker/drm_api.h" +#include "state_tracker/sw_winsys.h" +#include "dri_sw_winsys.h" + +static struct pipe_screen * +swrast_create_screen(struct drm_api *api, + int drmFD, + struct drm_create_screen_arg *arg) +{ + struct sw_winsys *winsys = NULL; + struct pipe_screen *screen = NULL; + + (void) drmFD; + + if (arg != NULL) { + switch(arg->mode) { + case DRM_CREATE_DRISW: + break; + default: + return NULL; + } + } + + winsys = dri_create_sw_winsys(); + if (winsys == NULL) + return NULL; + + screen = softpipe_create_screen( winsys ); + if (screen == NULL) + goto fail; + + return screen; + +fail: + if (winsys) + winsys->destroy( winsys ); + + return NULL; +} + +static void +swrast_drm_api_destroy(struct drm_api *api) +{ + return; +} + +static struct drm_api swrast_drm_api = +{ + .name = "swrast", + .driver_name = "swrast", + .create_screen = swrast_create_screen, + .destroy = swrast_drm_api_destroy, +}; + +struct drm_api * +drm_api_create() +{ + return &swrast_drm_api; +} + +/* vim: set sw=3 ts=8 sts=3 expandtab: */ diff --git a/src/gallium/winsys/sw/dri/Makefile b/src/gallium/winsys/sw/dri/Makefile new file mode 100644 index 00000000000..a3fca6be885 --- /dev/null +++ b/src/gallium/winsys/sw/dri/Makefile @@ -0,0 +1,13 @@ +TOP = ../../../../.. +include $(TOP)/configs/current + +LIBNAME = swdri + +LIBRARY_INCLUDES = + +LIBRARY_DEFINES = + +C_SOURCES = \ + dri_sw_winsys.c + +include ../../../Makefile.template diff --git a/src/gallium/winsys/sw/dri/dri_sw_winsys.c b/src/gallium/winsys/sw/dri/dri_sw_winsys.c new file mode 100644 index 00000000000..abf92b86b04 --- /dev/null +++ b/src/gallium/winsys/sw/dri/dri_sw_winsys.c @@ -0,0 +1,197 @@ +/************************************************************************** + * + * Copyright 2009, VMware, Inc. + * All Rights Reserved. + * Copyright 2010 George Sapountzis + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#include "pipe/p_compiler.h" +#include "pipe/p_format.h" +#include "util/u_inlines.h" +#include "util/u_format.h" +#include "util/u_math.h" +#include "util/u_memory.h" + +#include "state_tracker/sw_winsys.h" +#include "dri_sw_winsys.h" + + +struct xm_displaytarget +{ + void *data; + void *mapped; +}; + + +/** Cast wrapper */ +static INLINE struct xm_displaytarget * +xm_displaytarget( struct sw_displaytarget *dt ) +{ + return (struct xm_displaytarget *)dt; +} + + +/* pipe_screen::is_format_supported */ +static boolean +xm_is_displaytarget_format_supported( struct sw_winsys *ws, + unsigned tex_usage, + enum pipe_format format ) +{ + /* TODO: check visuals or other sensible thing here */ + return TRUE; +} + +/* pipe_screen::texture_create DISPLAY_TARGET / SCANOUT / SHARED */ +static struct sw_displaytarget * +xm_displaytarget_create(struct sw_winsys *winsys, + unsigned tex_usage, + enum pipe_format format, + unsigned width, unsigned height, + unsigned alignment, + unsigned *stride) +{ + struct xm_displaytarget *xm_dt; + unsigned nblocksy, size, xm_stride; + + xm_dt = CALLOC_STRUCT(xm_displaytarget); + if(!xm_dt) + goto no_xm_dt; + + nblocksy = util_format_get_nblocksy(format, height); + xm_stride = align(util_format_get_stride(format, width), alignment); + size = xm_stride * nblocksy; + + xm_dt->data = align_malloc(size, alignment); + if(!xm_dt->data) + goto no_data; + + *stride = xm_stride; + return (struct sw_displaytarget *)xm_dt; + +no_data: + FREE(xm_dt); +no_xm_dt: + return NULL; +} + +/* pipe_screen::texture_destroy */ +static void +xm_displaytarget_destroy(struct sw_winsys *ws, + struct sw_displaytarget *dt) +{ + struct xm_displaytarget *xm_dt = xm_displaytarget(dt); + + if (xm_dt->data) { + FREE(xm_dt->data); + } + + FREE(xm_dt); +} + +/* pipe_context::transfer_map */ +static void * +xm_displaytarget_map(struct sw_winsys *ws, + struct sw_displaytarget *dt, + unsigned flags) +{ + struct xm_displaytarget *xm_dt = xm_displaytarget(dt); + xm_dt->mapped = xm_dt->data; + return xm_dt->mapped; +} + +/* pipe_context::transfer_unmap */ +static void +xm_displaytarget_unmap(struct sw_winsys *ws, + struct sw_displaytarget *dt) +{ + struct xm_displaytarget *xm_dt = xm_displaytarget(dt); + xm_dt->mapped = NULL; +} + +/* pipe_screen::texture_from_handle */ +static struct sw_displaytarget * +xm_displaytarget_from_handle(struct sw_winsys *winsys, + const struct pipe_texture *templ, + struct winsys_handle *whandle, + unsigned *stride) +{ + assert(0); + return NULL; +} + +/* pipe_screen::texture_get_handle */ +static boolean +xm_displaytarget_get_handle(struct sw_winsys *winsys, + struct sw_displaytarget *dt, + struct winsys_handle *whandle) +{ + assert(0); + return FALSE; +} + +/* pipe_screen::flush_frontbuffer */ +static void +xm_displaytarget_display(struct sw_winsys *ws, + struct sw_displaytarget *dt, + void *context_private) +{ + assert(0); +} + + +static void +dri_destroy_sw_winsys(struct sw_winsys *winsys) +{ + FREE(winsys); +} + +struct sw_winsys * +dri_create_sw_winsys(void) +{ + struct sw_winsys *ws; + + ws = CALLOC_STRUCT(sw_winsys); + if (!ws) + return NULL; + + ws->destroy = dri_destroy_sw_winsys; + + ws->is_displaytarget_format_supported = xm_is_displaytarget_format_supported; + + /* screen texture functions */ + ws->displaytarget_create = xm_displaytarget_create; + ws->displaytarget_destroy = xm_displaytarget_destroy; + ws->displaytarget_from_handle = xm_displaytarget_from_handle; + ws->displaytarget_get_handle = xm_displaytarget_get_handle; + + /* texture functions */ + ws->displaytarget_map = xm_displaytarget_map; + ws->displaytarget_unmap = xm_displaytarget_unmap; + + ws->displaytarget_display = xm_displaytarget_display; + + return ws; +} + +/* vim: set sw=3 ts=8 sts=3 expandtab: */ diff --git a/src/gallium/winsys/sw/dri/dri_sw_winsys.h b/src/gallium/winsys/sw/dri/dri_sw_winsys.h new file mode 100644 index 00000000000..c2382a68d78 --- /dev/null +++ b/src/gallium/winsys/sw/dri/dri_sw_winsys.h @@ -0,0 +1,36 @@ +/************************************************************************** + * + * Copyright 2009, VMware, Inc. + * All Rights Reserved. + * Copyright 2010 George Sapountzis + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef DRI_SW_WINSYS +#define DRI_SW_WINSYS + +struct sw_winsys; + +struct sw_winsys *dri_create_sw_winsys(void); + +#endif -- cgit v1.2.3 From bb289a8a7019cc0b40121e91fe5cd404a76b1fb5 Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Thu, 25 Mar 2010 17:01:54 +0200 Subject: swrastg_dri: hack for loader hardcoded stride --- src/gallium/winsys/sw/dri/dri_sw_winsys.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/winsys/sw/dri/dri_sw_winsys.c b/src/gallium/winsys/sw/dri/dri_sw_winsys.c index abf92b86b04..5549e152ee8 100644 --- a/src/gallium/winsys/sw/dri/dri_sw_winsys.c +++ b/src/gallium/winsys/sw/dri/dri_sw_winsys.c @@ -62,6 +62,14 @@ xm_is_displaytarget_format_supported( struct sw_winsys *ws, return TRUE; } +static INLINE int +bytes_per_line(unsigned stride, unsigned mul) +{ + unsigned mask = mul - 1; + + return ((stride * 8 + mask) & ~mask) / 8; +} + /* pipe_screen::texture_create DISPLAY_TARGET / SCANOUT / SHARED */ static struct sw_displaytarget * xm_displaytarget_create(struct sw_winsys *winsys, @@ -72,21 +80,35 @@ xm_displaytarget_create(struct sw_winsys *winsys, unsigned *stride) { struct xm_displaytarget *xm_dt; - unsigned nblocksy, size, xm_stride; + unsigned nblocksy, size, xm_stride, loader_stride, format_stride; xm_dt = CALLOC_STRUCT(xm_displaytarget); if(!xm_dt) goto no_xm_dt; + format_stride = util_format_get_stride(format, width); + xm_stride = align(format_stride, alignment); + loader_stride = bytes_per_line(format_stride, 32); + nblocksy = util_format_get_nblocksy(format, height); - xm_stride = align(util_format_get_stride(format, width), alignment); size = xm_stride * nblocksy; +#ifdef DEBUG + debug_printf("swrast format stride: %8d\n", format_stride); + debug_printf("swrast pipe stride : %8d\n", xm_stride); + debug_printf("swrast loader stride: %8d\n", loader_stride); +#endif + + /* + * Allocate with the aligned stride required by the pipe but set the stride + * to the one hardcoded in the loaders XXX + */ + xm_dt->data = align_malloc(size, alignment); if(!xm_dt->data) goto no_data; - *stride = xm_stride; + *stride = loader_stride; return (struct sw_displaytarget *)xm_dt; no_data: -- cgit v1.2.3 From 1570e30b487018f056af4d0b5ca83a889f9ce721 Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Thu, 25 Mar 2010 17:01:54 +0200 Subject: st/dri: add TODO list for DRISW --- src/gallium/state_trackers/dri/drisw.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/dri/drisw.c b/src/gallium/state_trackers/dri/drisw.c index b3d65df8815..73bc45d9060 100644 --- a/src/gallium/state_trackers/dri/drisw.c +++ b/src/gallium/state_trackers/dri/drisw.c @@ -26,6 +26,36 @@ * **************************************************************************/ +/* TODO: + * + * stride: + * + * The driver and the loaders (libGL, xserver/glx) compute the stride from the + * width independently. winsys has a workaround that works for softpipe but may + * explode for other drivers or platforms, rendering- or performance-wise. + * Solving this issue properly requires extending the DRISW loader extension, + * in order to make the stride available to the putImage callback. + * + * drisw_api: + * + * Define drisw_api similarly to dri_api and use it to call the loader. This is + * predicated on support for calling the loader from the winsys, which has to + * grow for DRI2 as well. + * + * xshm: + * + * Allow the loaders to use the XSHM extension. It probably requires callbacks + * for createImage/destroyImage similar to DRI2 getBuffers. Probably not worth + * it, given the scope of DRISW, unless it falls naturally from properly + * solving the above two issues. + * + * swrast_create_screen: + * + * Allow for any software renderer to be used. Factor out the code from + * targets/libgl-xlib/xlib.c, put it in targets/common or winsys/sw/common and + * use it in all software targets. + */ + #include "util/u_memory.h" #include "util/u_inlines.h" #include "pipe/p_context.h" -- cgit v1.2.3 From 8f47f5320f1a8d4750152f7783cf72073d0979bd Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Thu, 25 Mar 2010 17:54:41 +0100 Subject: st/dri: Add dri2 prefix for all dri2.c functions --- src/gallium/state_trackers/dri/dri2.c | 34 ++++++++++++++--------------- src/gallium/state_trackers/dri/dri2.h | 10 ++++----- src/gallium/state_trackers/dri/dri_screen.c | 2 +- src/gallium/state_trackers/dri/dri_st_api.c | 4 ++-- 4 files changed, 25 insertions(+), 25 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/dri/dri2.c b/src/gallium/state_trackers/dri/dri2.c index 2c6a0621ae7..108b18e9d3c 100644 --- a/src/gallium/state_trackers/dri/dri2.c +++ b/src/gallium/state_trackers/dri/dri2.c @@ -107,8 +107,8 @@ static const __DRItexBufferExtension dri2TexBufferExtension = { * Get the format of an attachment. */ static INLINE enum pipe_format -dri_drawable_get_format(struct dri_drawable *drawable, - enum st_attachment_type statt) +dri2_drawable_get_format(struct dri_drawable *drawable, + enum st_attachment_type statt) { enum pipe_format format; @@ -134,9 +134,9 @@ dri_drawable_get_format(struct dri_drawable *drawable, * Retrieve __DRIbuffer from the DRI loader. */ static __DRIbuffer * -dri_drawable_get_buffers(struct dri_drawable *drawable, - const enum st_attachment_type *statts, - unsigned *count) +dri2_drawable_get_buffers(struct dri_drawable *drawable, + const enum st_attachment_type *statts, + unsigned *count) { __DRIdrawable *dri_drawable = drawable->dPriv; struct __DRIdri2LoaderExtensionRec *loader = drawable->sPriv->dri2.loader; @@ -159,7 +159,7 @@ dri_drawable_get_buffers(struct dri_drawable *drawable, enum pipe_format format; int att, bpp; - format = dri_drawable_get_format(drawable, statts[i]); + format = dri2_drawable_get_format(drawable, statts[i]); if (format == PIPE_FORMAT_NONE) continue; @@ -238,8 +238,8 @@ dri_drawable_get_buffers(struct dri_drawable *drawable, * Process __DRIbuffer and convert them into pipe_textures. */ static void -dri_drawable_process_buffers(struct dri_drawable *drawable, - __DRIbuffer *buffers, unsigned count) +dri2_drawable_process_buffers(struct dri_drawable *drawable, + __DRIbuffer *buffers, unsigned count) { struct dri_screen *screen = dri_screen(drawable->sPriv); __DRIdrawable *dri_drawable = drawable->dPriv; @@ -302,7 +302,7 @@ dri_drawable_process_buffers(struct dri_drawable *drawable, break; } - format = dri_drawable_get_format(drawable, statt); + format = dri2_drawable_get_format(drawable, statt); if (statt == ST_ATTACHMENT_INVALID || format == PIPE_FORMAT_NONE) continue; @@ -326,20 +326,20 @@ dri_drawable_process_buffers(struct dri_drawable *drawable, */ void -dri_allocate_textures(struct dri_drawable *drawable, - const enum st_attachment_type *statts, - unsigned count) +dri2_allocate_textures(struct dri_drawable *drawable, + const enum st_attachment_type *statts, + unsigned count) { __DRIbuffer *buffers; unsigned num_buffers = count; - buffers = dri_drawable_get_buffers(drawable, statts, &num_buffers); - dri_drawable_process_buffers(drawable, buffers, num_buffers); + buffers = dri2_drawable_get_buffers(drawable, statts, &num_buffers); + dri2_drawable_process_buffers(drawable, buffers, num_buffers); } void -dri_flush_frontbuffer(struct dri_drawable *drawable, - enum st_attachment_type statt) +dri2_flush_frontbuffer(struct dri_drawable *drawable, + enum st_attachment_type statt) { __DRIdrawable *dri_drawable = drawable->dPriv; struct __DRIdri2LoaderExtensionRec *loader = drawable->sPriv->dri2.loader; @@ -373,7 +373,7 @@ static const __DRIextension *dri_screen_extensions[] = { * Returns the __GLcontextModes supported by this driver. */ const __DRIconfig ** -dri_init_screen2(__DRIscreen * sPriv) +dri2_init_screen(__DRIscreen * sPriv) { struct dri_screen *screen; struct drm_create_screen_arg arg; diff --git a/src/gallium/state_trackers/dri/dri2.h b/src/gallium/state_trackers/dri/dri2.h index e1afcf8ca8d..379963431fb 100644 --- a/src/gallium/state_trackers/dri/dri2.h +++ b/src/gallium/state_trackers/dri/dri2.h @@ -32,15 +32,15 @@ #include "dri_wrapper.h" const __DRIconfig ** -dri_init_screen2(__DRIscreen * sPriv); +dri2_init_screen(__DRIscreen * sPriv); void -dri_flush_frontbuffer(struct dri_drawable *drawable, +dri2_flush_frontbuffer(struct dri_drawable *drawable, enum st_attachment_type statt); void -dri_allocate_textures(struct dri_drawable *drawable, - const enum st_attachment_type *statts, - unsigned count); +dri2_allocate_textures(struct dri_drawable *drawable, + const enum st_attachment_type *statts, + unsigned count); #endif /* DRI2_H */ diff --git a/src/gallium/state_trackers/dri/dri_screen.c b/src/gallium/state_trackers/dri/dri_screen.c index ae311641042..3029d337878 100644 --- a/src/gallium/state_trackers/dri/dri_screen.c +++ b/src/gallium/state_trackers/dri/dri_screen.c @@ -328,7 +328,7 @@ const struct __DriverAPIRec driDriverAPI = { .GetSwapInfo = dri_get_swap_info, .GetDrawableMSC = driDrawableGetMSC32, .WaitForMSC = driWaitForMSC32, - .InitScreen2 = dri_init_screen2, + .InitScreen2 = dri2_init_screen, .InitScreen = dri1_init_screen, .SwapBuffers = dri1_swap_buffers, diff --git a/src/gallium/state_trackers/dri/dri_st_api.c b/src/gallium/state_trackers/dri/dri_st_api.c index 2b98c487c84..31d2c582aa0 100644 --- a/src/gallium/state_trackers/dri/dri_st_api.c +++ b/src/gallium/state_trackers/dri/dri_st_api.c @@ -73,7 +73,7 @@ dri_st_framebuffer_validate(struct st_framebuffer_iface *stfbi, dri1_allocate_textures(drawable, statt_mask); } else { - dri_allocate_textures(drawable, statts, count); + dri2_allocate_textures(drawable, statts, count); } #else if (new_stamp) @@ -115,7 +115,7 @@ dri_st_framebuffer_flush_front(struct st_framebuffer_iface *stfbi, dri1_flush_frontbuffer(drawable, statt); } else { - dri_flush_frontbuffer(drawable, statt); + dri2_flush_frontbuffer(drawable, statt); } #else drisw_flush_frontbuffer(drawable, statt); -- cgit v1.2.3 From 9eaadfeaa54d15fc3eb90d4137795ace4f920b2f Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Thu, 25 Mar 2010 18:28:31 +0100 Subject: st/dri: Don't include sw vs drm dri headers --- src/gallium/state_trackers/dri/dri_screen.c | 3 +++ src/gallium/state_trackers/dri/dri_st_api.c | 3 +++ 2 files changed, 6 insertions(+) (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/dri/dri_screen.c b/src/gallium/state_trackers/dri/dri_screen.c index 3029d337878..598a07bb646 100644 --- a/src/gallium/state_trackers/dri/dri_screen.c +++ b/src/gallium/state_trackers/dri/dri_screen.c @@ -40,9 +40,12 @@ #include "dri_drawable.h" #include "dri_st_api.h" #include "dri1_helper.h" +#ifndef __NOT_HAVE_DRM_H #include "dri1.h" #include "dri2.h" +#else #include "drisw.h" +#endif #include "util/u_inlines.h" #include "pipe/p_screen.h" diff --git a/src/gallium/state_trackers/dri/dri_st_api.c b/src/gallium/state_trackers/dri/dri_st_api.c index 31d2c582aa0..40b24b18e9f 100644 --- a/src/gallium/state_trackers/dri/dri_st_api.c +++ b/src/gallium/state_trackers/dri/dri_st_api.c @@ -36,9 +36,12 @@ #include "dri_drawable.h" #include "dri_st_api.h" #include "dri1_helper.h" +#ifndef __NOT_HAVE_DRM_H #include "dri1.h" #include "dri2.h" +#else #include "drisw.h" +#endif static boolean dri_st_framebuffer_validate(struct st_framebuffer_iface *stfbi, -- cgit v1.2.3 From 67e377bda6431b613836fdc04680a49b75e4b751 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Thu, 25 Mar 2010 16:04:40 -0600 Subject: llvmpipe: disable an assertion We shouldn't try to clear a non-existant z/stencil buffer, so there's probably a bug elsewhere. Disable the assertion for now to allow things to at least run. --- src/gallium/drivers/llvmpipe/lp_rast.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/llvmpipe/lp_rast.c b/src/gallium/drivers/llvmpipe/lp_rast.c index cd9919ca909..8352f175598 100644 --- a/src/gallium/drivers/llvmpipe/lp_rast.c +++ b/src/gallium/drivers/llvmpipe/lp_rast.c @@ -189,7 +189,7 @@ lp_rast_clear_zstencil(struct lp_rasterizer_task *task, LP_DBG(DEBUG_RAST, "%s 0x%x\n", __FUNCTION__, arg.clear_zstencil); - assert(rast->zsbuf.map); + /*assert(rast->zsbuf.map);*/ if (!rast->zsbuf.map) return; -- cgit v1.2.3 From 8814bb652aa0deee7fa34c0746ba9dc63163b88d Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Thu, 25 Mar 2010 16:06:07 -0600 Subject: Revert "llvmpipe: optimize the lp_setup_fence() function" This reverts commit a9063cad0f0190ff88cd20fbad5aa87bf1a943f6. Not too surprisingly, this change caused some regressions. Revert it for the time being. See fd.o bug 27320. --- src/gallium/drivers/llvmpipe/lp_setup.c | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/llvmpipe/lp_setup.c b/src/gallium/drivers/llvmpipe/lp_setup.c index 4eeb98621f6..76a8b87a309 100644 --- a/src/gallium/drivers/llvmpipe/lp_setup.c +++ b/src/gallium/drivers/llvmpipe/lp_setup.c @@ -318,30 +318,16 @@ lp_setup_fence( struct lp_setup_context *setup ) { struct lp_scene *scene = lp_setup_get_current_scene(setup); const unsigned rank = lp_scene_get_num_bins( scene ); /* xxx */ - struct lp_fence *fence; + struct lp_fence *fence = lp_fence_create(rank); LP_DBG(DEBUG_SETUP, "%s rank %u\n", __FUNCTION__, rank); - if (setup->state == SETUP_FLUSHED) { - /* We're in a flushed state so there's nothing in the bins. - * No need to wait on a fence. - */ - fence = NULL; - } - else { - /* There's material in the bins. Emit the fence into the bins. - * When the rasterizer(s) find the fence, they'll signal on it. - */ - fence = lp_fence_create(rank); - - set_scene_state( setup, SETUP_ACTIVE ); - - /* insert the fence into all command bins */ - lp_scene_bin_everywhere( scene, - lp_rast_fence, - lp_rast_arg_fence(fence) ); + set_scene_state( setup, SETUP_ACTIVE ); - } + /* insert the fence into all command bins */ + lp_scene_bin_everywhere( scene, + lp_rast_fence, + lp_rast_arg_fence(fence) ); return (struct pipe_fence_handle *) fence; } -- cgit v1.2.3 From 5b1fc14627ae37c5def70e2d5fe28bf7a4becee6 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Thu, 25 Mar 2010 18:29:51 +0100 Subject: st/dri: Reshuffle files and make it obvious which files are shared In short: git mv ../drisw/Makefile dri/sw git mv drisw.[c|h] sw git mv dri2.[c|h] dri1.[c|h] Makefile drm git rm ../drisw ln -s drm/* ln -s sw/* --- configure.ac | 11 +- src/gallium/state_trackers/dri/Makefile | 36 +- src/gallium/state_trackers/dri/SConscript | 28 +- src/gallium/state_trackers/dri/dri1.c | 526 --------------------- src/gallium/state_trackers/dri/dri1.h | 59 --- src/gallium/state_trackers/dri/dri2.c | 413 ---------------- src/gallium/state_trackers/dri/dri2.h | 46 -- src/gallium/state_trackers/dri/drisw.c | 318 ------------- src/gallium/state_trackers/dri/drisw.h | 54 --- src/gallium/state_trackers/dri/drm/Makefile | 33 ++ src/gallium/state_trackers/dri/drm/SConscript | 28 ++ src/gallium/state_trackers/dri/drm/dri1.c | 526 +++++++++++++++++++++ src/gallium/state_trackers/dri/drm/dri1.h | 59 +++ src/gallium/state_trackers/dri/drm/dri1_helper.c | 1 + src/gallium/state_trackers/dri/drm/dri2.c | 413 ++++++++++++++++ src/gallium/state_trackers/dri/drm/dri2.h | 46 ++ src/gallium/state_trackers/dri/drm/dri_context.c | 1 + src/gallium/state_trackers/dri/drm/dri_drawable.c | 1 + .../state_trackers/dri/drm/dri_extensions.c | 1 + src/gallium/state_trackers/dri/drm/dri_screen.c | 1 + src/gallium/state_trackers/dri/drm/dri_st_api.c | 1 + src/gallium/state_trackers/dri/sw/Makefile | 27 ++ src/gallium/state_trackers/dri/sw/dri1_helper.c | 1 + src/gallium/state_trackers/dri/sw/dri_context.c | 1 + src/gallium/state_trackers/dri/sw/dri_drawable.c | 1 + src/gallium/state_trackers/dri/sw/dri_extensions.c | 1 + src/gallium/state_trackers/dri/sw/dri_screen.c | 1 + src/gallium/state_trackers/dri/sw/dri_st_api.c | 1 + src/gallium/state_trackers/dri/sw/drisw.c | 318 +++++++++++++ src/gallium/state_trackers/dri/sw/drisw.h | 54 +++ src/gallium/state_trackers/drisw/Makefile | 26 - src/gallium/state_trackers/drisw/dri1_helper.c | 1 - src/gallium/state_trackers/drisw/dri_context.c | 1 - src/gallium/state_trackers/drisw/dri_drawable.c | 1 - src/gallium/state_trackers/drisw/dri_extensions.c | 1 - src/gallium/state_trackers/drisw/dri_screen.c | 1 - src/gallium/state_trackers/drisw/dri_st_api.c | 1 - src/gallium/state_trackers/drisw/drisw.c | 1 - src/gallium/targets/dri-i915/Makefile | 2 +- src/gallium/targets/dri-i965/Makefile | 2 +- src/gallium/targets/dri-nouveau/Makefile | 2 +- src/gallium/targets/dri-radeong/Makefile | 2 +- src/gallium/targets/dri-swrast/Makefile | 2 +- src/gallium/targets/dri-vmwgfx/Makefile | 2 +- 44 files changed, 1535 insertions(+), 1517 deletions(-) delete mode 100644 src/gallium/state_trackers/dri/dri1.c delete mode 100644 src/gallium/state_trackers/dri/dri1.h delete mode 100644 src/gallium/state_trackers/dri/dri2.c delete mode 100644 src/gallium/state_trackers/dri/dri2.h delete mode 100644 src/gallium/state_trackers/dri/drisw.c delete mode 100644 src/gallium/state_trackers/dri/drisw.h create mode 100644 src/gallium/state_trackers/dri/drm/Makefile create mode 100644 src/gallium/state_trackers/dri/drm/SConscript create mode 100644 src/gallium/state_trackers/dri/drm/dri1.c create mode 100644 src/gallium/state_trackers/dri/drm/dri1.h create mode 120000 src/gallium/state_trackers/dri/drm/dri1_helper.c create mode 100644 src/gallium/state_trackers/dri/drm/dri2.c create mode 100644 src/gallium/state_trackers/dri/drm/dri2.h create mode 120000 src/gallium/state_trackers/dri/drm/dri_context.c create mode 120000 src/gallium/state_trackers/dri/drm/dri_drawable.c create mode 120000 src/gallium/state_trackers/dri/drm/dri_extensions.c create mode 120000 src/gallium/state_trackers/dri/drm/dri_screen.c create mode 120000 src/gallium/state_trackers/dri/drm/dri_st_api.c create mode 100644 src/gallium/state_trackers/dri/sw/Makefile create mode 120000 src/gallium/state_trackers/dri/sw/dri1_helper.c create mode 120000 src/gallium/state_trackers/dri/sw/dri_context.c create mode 120000 src/gallium/state_trackers/dri/sw/dri_drawable.c create mode 120000 src/gallium/state_trackers/dri/sw/dri_extensions.c create mode 120000 src/gallium/state_trackers/dri/sw/dri_screen.c create mode 120000 src/gallium/state_trackers/dri/sw/dri_st_api.c create mode 100644 src/gallium/state_trackers/dri/sw/drisw.c create mode 100644 src/gallium/state_trackers/dri/sw/drisw.h delete mode 100644 src/gallium/state_trackers/drisw/Makefile delete mode 120000 src/gallium/state_trackers/drisw/dri1_helper.c delete mode 120000 src/gallium/state_trackers/drisw/dri_context.c delete mode 120000 src/gallium/state_trackers/drisw/dri_drawable.c delete mode 120000 src/gallium/state_trackers/drisw/dri_extensions.c delete mode 120000 src/gallium/state_trackers/drisw/dri_screen.c delete mode 120000 src/gallium/state_trackers/drisw/dri_st_api.c delete mode 120000 src/gallium/state_trackers/drisw/drisw.c (limited to 'src/gallium') diff --git a/configure.ac b/configure.ac index d6d952d7a58..caa2cf65766 100644 --- a/configure.ac +++ b/configure.ac @@ -1204,9 +1204,8 @@ yes) GALLIUM_STATE_TRACKERS_DIRS=glx ;; dri) - GALLIUM_STATE_TRACKERS_DIRS="dri drisw" + GALLIUM_STATE_TRACKERS_DIRS="dri" HAVE_ST_DRI="yes" - HAVE_ST_DRISW="yes" if test "x$enable_egl" = xyes; then GALLIUM_STATE_TRACKERS_DIRS="$GALLIUM_STATE_TRACKERS_DIRS egl" HAVE_ST_EGL="yes" @@ -1232,12 +1231,6 @@ yes) fi HAVE_ST_DRI="yes" ;; - drisw) - if test "x$mesa_driver" != xdri; then - AC_MSG_ERROR([cannot build drisw state tracker without mesa driver set to dri]) - fi - HAVE_ST_DRISW="yes" - ;; egl) if test "x$enable_egl" != xyes; then AC_MSG_ERROR([cannot build egl state tracker without EGL library]) @@ -1409,7 +1402,7 @@ AC_ARG_ENABLE([gallium-swrast], [enable_gallium_swrast="$enableval"], [enable_gallium_swrast=auto]) if test "x$enable_gallium_swrast" = xyes || test "x$enable_gallium_swrast" = xauto; then - if test "x$HAVE_ST_DRISW" = xyes; then + if test "x$HAVE_ST_DRI" = xyes; then GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS dri-swrast" fi if test "x$HAVE_ST_EGL" = xyes; then diff --git a/src/gallium/state_trackers/dri/Makefile b/src/gallium/state_trackers/dri/Makefile index f1a54e80b61..72e70577b3d 100644 --- a/src/gallium/state_trackers/dri/Makefile +++ b/src/gallium/state_trackers/dri/Makefile @@ -1,32 +1,12 @@ +# src/gallium/state_trackers/dri/Makefile TOP = ../../../.. include $(TOP)/configs/current -LIBNAME = dridrm +SUBDIRS = drm sw -LIBRARY_INCLUDES = \ - -I$(TOP)/include \ - -I$(TOP)/src/mesa \ - -I$(TOP)/src/mesa/drivers/dri/common \ - -I$(TOP)/src/mesa/main \ - $(shell pkg-config --cflags-only-I libdrm) - - -C_SOURCES = \ - dri_context.c \ - dri_screen.c \ - dri_drawable.c \ - dri_extensions.c \ - dri_st_api.c \ - dri1_helper.c \ - dri1.c \ - dri2.c - -# $(TOP)/src/mesa/drivers/dri/common/utils.c \ - $(TOP)/src/mesa/drivers/dri/common/vblank.c \ - $(TOP)/src/mesa/drivers/dri/common/dri_util.c \ - $(TOP)/src/mesa/drivers/dri/common/xmlconfig.c \ - $(TOP)/src/mesa/drivers/common/driverfuncs.c \ - $(TOP)/src/mesa/drivers/dri/common/texmem.c \ - $(TOP)/src/mesa/drivers/dri/common/drirenderbuffer.c - -include ../../Makefile.template +default install clean: + @for dir in $(SUBDIRS) ; do \ + if [ -d $$dir ] ; then \ + (cd $$dir && $(MAKE) $@) || exit 1; \ + fi \ + done diff --git a/src/gallium/state_trackers/dri/SConscript b/src/gallium/state_trackers/dri/SConscript index 2ca9f420683..b4a276cf29d 100644 --- a/src/gallium/state_trackers/dri/SConscript +++ b/src/gallium/state_trackers/dri/SConscript @@ -1,27 +1,5 @@ -####################################################################### -# SConscript for dri state_tracker - Import('*') -if env['dri']: - - env = env.Clone() - - env.Append(CPPPATH = [ - '#/src/mesa', - '#/src/mesa/drivers/dri/common', - ]) - - st_dri = env.ConvenienceLibrary( - target = 'st_dri', - source = [ 'dri_context.c', - 'dri_drawable.c', - 'dri_extensions.c', - 'dri_screen.c', - 'dri_st_api.c', - 'dri1_helper.c', - 'dri1.c', - 'dri2.c', - ] - ) - Export('st_dri') +SConscript([ + 'drm/SConscript', +]) diff --git a/src/gallium/state_trackers/dri/dri1.c b/src/gallium/state_trackers/dri/dri1.c deleted file mode 100644 index 98bdb2936a1..00000000000 --- a/src/gallium/state_trackers/dri/dri1.c +++ /dev/null @@ -1,526 +0,0 @@ -/************************************************************************** - * - * Copyright 2009, VMware, Inc. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ -/* - * Author: Keith Whitwell - * Author: Jakob Bornecrantz - */ - -/* XXX DRI1 is untested after the switch to st_api.h */ - -#include "util/u_memory.h" -#include "util/u_rect.h" -#include "util/u_inlines.h" -#include "pipe/p_context.h" -#include "state_tracker/dri1_api.h" - -#include "dri_screen.h" -#include "dri_context.h" -#include "dri_drawable.h" -#include "dri_st_api.h" -#include "dri1_helper.h" -#include "dri1.h" - -static INLINE void -dri1_lock(struct dri_context *ctx) -{ - drm_context_t hw_context = ctx->cPriv->hHWContext; - char ret = 0; - - DRM_CAS(ctx->lock, hw_context, DRM_LOCK_HELD | hw_context, ret); - if (ret) { - drmGetLock(ctx->sPriv->fd, hw_context, 0); - ctx->stLostLock = TRUE; - ctx->wsLostLock = TRUE; - } - ctx->isLocked = TRUE; -} - -static INLINE void -dri1_unlock(struct dri_context *ctx) -{ - ctx->isLocked = FALSE; - DRM_UNLOCK(ctx->sPriv->fd, ctx->lock, ctx->cPriv->hHWContext); -} - -static void -dri1_update_drawables_locked(struct dri_context *ctx, - __DRIdrawable * driDrawPriv, - __DRIdrawable * driReadPriv) -{ - if (ctx->stLostLock) { - ctx->stLostLock = FALSE; - if (driDrawPriv == driReadPriv) - DRI_VALIDATE_DRAWABLE_INFO(ctx->sPriv, driDrawPriv); - else - DRI_VALIDATE_TWO_DRAWABLES_INFO(ctx->sPriv, driDrawPriv, - driReadPriv); - } -} - -/** - * This ensures all contexts which bind to a drawable pick up the - * drawable change and signal new buffer state. - */ -static void -dri1_propagate_drawable_change(struct dri_context *ctx) -{ - __DRIdrawable *dPriv = ctx->dPriv; - __DRIdrawable *rPriv = ctx->rPriv; - struct dri_drawable *draw = dri_drawable(dPriv); - struct dri_drawable *read = dri_drawable(rPriv); - boolean flushed = FALSE; - - if (dPriv && draw->texture_stamp != dPriv->lastStamp) { - ctx->st->flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); - flushed = TRUE; - ctx->st->notify_invalid_framebuffer(ctx->st, draw->stfb); - } - - if (rPriv && dPriv != rPriv && read->texture_stamp != rPriv->lastStamp) { - if (!flushed) - ctx->st->flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); - ctx->st->notify_invalid_framebuffer(ctx->st, read->stfb); - } -} - -static INLINE boolean -dri1_intersect_src_bbox(struct drm_clip_rect *dst, - int dst_x, - int dst_y, - const struct drm_clip_rect *src, - const struct drm_clip_rect *bbox) -{ - int xy1; - int xy2; - - xy1 = ((int)src->x1 > (int)bbox->x1 + dst_x) ? src->x1 : - (int)bbox->x1 + dst_x; - xy2 = ((int)src->x2 < (int)bbox->x2 + dst_x) ? src->x2 : - (int)bbox->x2 + dst_x; - if (xy1 >= xy2 || xy1 < 0) - return FALSE; - - dst->x1 = xy1; - dst->x2 = xy2; - - xy1 = ((int)src->y1 > (int)bbox->y1 + dst_y) ? src->y1 : - (int)bbox->y1 + dst_y; - xy2 = ((int)src->y2 < (int)bbox->y2 + dst_y) ? src->y2 : - (int)bbox->y2 + dst_y; - if (xy1 >= xy2 || xy1 < 0) - return FALSE; - - dst->y1 = xy1; - dst->y2 = xy2; - return TRUE; -} - -static void -dri1_swap_copy(struct pipe_context *pipe, - struct pipe_surface *dst, - struct pipe_surface *src, - __DRIdrawable * dPriv, const struct drm_clip_rect *bbox) -{ - struct drm_clip_rect clip; - struct drm_clip_rect *cur; - int i; - - cur = dPriv->pClipRects; - - for (i = 0; i < dPriv->numClipRects; ++i) { - if (dri1_intersect_src_bbox(&clip, dPriv->x, dPriv->y, cur++, bbox)) { - if (pipe->surface_copy) { - pipe->surface_copy(pipe, dst, clip.x1, clip.y1, - src, - (int)clip.x1 - dPriv->x, - (int)clip.y1 - dPriv->y, - clip.x2 - clip.x1, clip.y2 - clip.y1); - } else { - util_surface_copy(pipe, FALSE, dst, clip.x1, clip.y1, - src, - (int)clip.x1 - dPriv->x, - (int)clip.y1 - dPriv->y, - clip.x2 - clip.x1, clip.y2 - clip.y1); - } - } - } -} - -static void -dri1_present_texture_locked(__DRIdrawable * dPriv, - struct pipe_texture *ptex, - const struct drm_clip_rect *sub_box, - struct pipe_fence_handle **fence) -{ - struct dri_drawable *drawable = dri_drawable(dPriv); - struct dri_screen *screen = dri_screen(drawable->sPriv); - struct pipe_context *pipe; - struct pipe_surface *psurf; - struct drm_clip_rect bbox; - boolean visible = TRUE; - - *fence = NULL; - - bbox.x1 = 0; - bbox.x2 = ptex->width0; - bbox.y1 = 0; - bbox.y2 = ptex->height0; - - if (sub_box) - visible = dri1_intersect_src_bbox(&bbox, 0, 0, &bbox, sub_box); - if (!visible) - return; - - pipe = dri1_get_pipe_context(screen); - psurf = dri1_get_pipe_surface(drawable, ptex); - if (!pipe || !psurf) - return; - - if (__dri1_api_hooks->present_locked) { - __dri1_api_hooks->present_locked(pipe, psurf, - dPriv->pClipRects, dPriv->numClipRects, - dPriv->x, dPriv->y, &bbox, fence); - } else if (__dri1_api_hooks->front_srf_locked) { - struct pipe_surface *front = __dri1_api_hooks->front_srf_locked(pipe); - - if (front) - dri1_swap_copy(pipe, front, psurf, dPriv, &bbox); - - pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, fence); - } -} - -static void -dri1_copy_to_front(struct dri_context *ctx, - struct pipe_texture *ptex, - __DRIdrawable * dPriv, - const struct drm_clip_rect *sub_box, - struct pipe_fence_handle **fence) -{ - boolean save_lost_lock; - - dri1_lock(ctx); - save_lost_lock = ctx->stLostLock; - dri1_update_drawables_locked(ctx, dPriv, dPriv); - - dri1_present_texture_locked(dPriv, ptex, sub_box, fence); - - ctx->stLostLock = save_lost_lock; - - /** - * FIXME: Revisit this: Update drawables on copy_sub_buffer ? - */ - - if (!sub_box) - dri1_update_drawables_locked(ctx, ctx->dPriv, ctx->rPriv); - - dri1_unlock(ctx); - dri1_propagate_drawable_change(ctx); -} - -/* - * Backend functions for st_framebuffer interface and swap_buffers. - */ - -void -dri1_flush_frontbuffer(struct dri_drawable *draw, - enum st_attachment_type statt) -{ - struct dri_context *ctx = dri_get_current(); - struct dri_screen *screen = dri_screen(draw->sPriv); - struct pipe_screen *pipe_screen = screen->pipe_screen; - struct pipe_fence_handle *dummy_fence; - struct pipe_texture *ptex; - - if (!ctx) - return; /* For now */ - - ptex = draw->textures[statt]; - if (ptex) { - dri1_copy_to_front(ctx, ptex, ctx->dPriv, NULL, &dummy_fence); - pipe_screen->fence_reference(pipe_screen, &dummy_fence, NULL); - } - - /** - * FIXME: Do we need swap throttling here? - */ -} - -void -dri1_swap_buffers(__DRIdrawable * dPriv) -{ - struct dri_context *ctx = dri_get_current(); - struct dri_drawable *draw = dri_drawable(dPriv); - struct dri_screen *screen = dri_screen(draw->sPriv); - struct pipe_screen *pipe_screen = screen->pipe_screen; - struct pipe_fence_handle *fence; - struct pipe_texture *ptex; - - assert(__dri1_api_hooks != NULL); - - if (!ctx) - return; /* For now */ - - ptex = draw->textures[ST_ATTACHMENT_BACK_LEFT]; - if (ptex) { - ctx->st->flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); - fence = dri1_swap_fences_pop_front(draw); - if (fence) { - (void)pipe_screen->fence_finish(pipe_screen, fence, 0); - pipe_screen->fence_reference(pipe_screen, &fence, NULL); - } - dri1_copy_to_front(ctx, ptex, dPriv, NULL, &fence); - dri1_swap_fences_push_back(draw, fence); - pipe_screen->fence_reference(pipe_screen, &fence, NULL); - } -} - -void -dri1_copy_sub_buffer(__DRIdrawable * dPriv, int x, int y, int w, int h) -{ - struct dri_context *ctx = dri_get_current(); - struct dri_screen *screen = dri_screen(dPriv->driScreenPriv); - struct pipe_screen *pipe_screen = screen->pipe_screen; - struct drm_clip_rect sub_bbox; - struct dri_drawable *draw = dri_drawable(dPriv); - struct pipe_fence_handle *dummy_fence; - struct pipe_texture *ptex; - - assert(__dri1_api_hooks != NULL); - - if (!ctx) - return; - - sub_bbox.x1 = x; - sub_bbox.x2 = x + w; - sub_bbox.y1 = y; - sub_bbox.y2 = y + h; - - ptex = draw->textures[ST_ATTACHMENT_BACK_LEFT]; - if (ptex) { - ctx->st->flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); - dri1_copy_to_front(ctx, ptex, dPriv, &sub_bbox, &dummy_fence); - pipe_screen->fence_reference(pipe_screen, &dummy_fence, NULL); - } -} - -/** - * Allocate framebuffer attachments. - * - * During fixed-size operation, the function keeps allocating new attachments - * as they are requested. Unused attachments are not removed, not until the - * framebuffer is resized or destroyed. - */ -void -dri1_allocate_textures(struct dri_drawable *drawable, - unsigned mask) -{ - struct dri_screen *screen = dri_screen(drawable->sPriv); - struct pipe_texture templ; - unsigned width, height; - boolean resized; - int i; - - width = drawable->dPriv->w; - height = drawable->dPriv->h; - - resized = (drawable->old_w != width || - drawable->old_h != height); - - /* remove outdated textures */ - if (resized) { - for (i = 0; i < ST_ATTACHMENT_COUNT; i++) - pipe_texture_reference(&drawable->textures[i], NULL); - } - - memset(&templ, 0, sizeof(templ)); - templ.target = PIPE_TEXTURE_2D; - templ.width0 = width; - templ.height0 = height; - templ.depth0 = 1; - templ.last_level = 0; - - for (i = 0; i < ST_ATTACHMENT_COUNT; i++) { - enum pipe_format format; - unsigned tex_usage; - - /* the texture already exists or not requested */ - if (drawable->textures[i] || !(mask & (1 << i))) { - continue; - } - - switch (i) { - case ST_ATTACHMENT_FRONT_LEFT: - case ST_ATTACHMENT_BACK_LEFT: - case ST_ATTACHMENT_FRONT_RIGHT: - case ST_ATTACHMENT_BACK_RIGHT: - format = drawable->stvis.color_format; - tex_usage = PIPE_TEXTURE_USAGE_DISPLAY_TARGET | - PIPE_TEXTURE_USAGE_RENDER_TARGET; - break; - case ST_ATTACHMENT_DEPTH_STENCIL: - format = drawable->stvis.depth_stencil_format; - tex_usage = PIPE_TEXTURE_USAGE_DEPTH_STENCIL; - break; - default: - format = PIPE_FORMAT_NONE; - break; - } - - if (format != PIPE_FORMAT_NONE) { - templ.format = format; - templ.tex_usage = tex_usage; - - drawable->textures[i] = - screen->pipe_screen->texture_create(screen->pipe_screen, &templ); - } - } - - drawable->old_w = width; - drawable->old_h = height; -} - -static void -st_dri_lock(struct pipe_context *pipe) -{ - dri1_lock((struct dri_context *)pipe->priv); -} - -static void -st_dri_unlock(struct pipe_context *pipe) -{ - dri1_unlock((struct dri_context *)pipe->priv); -} - -static boolean -st_dri_is_locked(struct pipe_context *pipe) -{ - return ((struct dri_context *)pipe->priv)->isLocked; -} - -static boolean -st_dri_lost_lock(struct pipe_context *pipe) -{ - return ((struct dri_context *)pipe->priv)->wsLostLock; -} - -static void -st_dri_clear_lost_lock(struct pipe_context *pipe) -{ - ((struct dri_context *)pipe->priv)->wsLostLock = FALSE; -} - -static struct dri1_api_lock_funcs dri1_lf = { - .lock = st_dri_lock, - .unlock = st_dri_unlock, - .is_locked = st_dri_is_locked, - .is_lock_lost = st_dri_lost_lock, - .clear_lost_lock = st_dri_clear_lost_lock -}; - -/* - * Backend function for init_screen. - */ - -static const __DRIextension *dri1_screen_extensions[] = { - &driReadDrawableExtension, - &driCopySubBufferExtension.base, - &driSwapControlExtension.base, - &driFrameTrackingExtension.base, - &driMediaStreamCounterExtension.base, - NULL -}; - -struct dri1_api *__dri1_api_hooks = NULL; - -static INLINE void -dri1_copy_version(struct dri1_api_version *dst, - const struct __DRIversionRec *src) -{ - dst->major = src->major; - dst->minor = src->minor; - dst->patch_level = src->patch; -} - -const __DRIconfig ** -dri1_init_screen(__DRIscreen * sPriv) -{ - struct dri_screen *screen; - const __DRIconfig **configs; - struct dri1_create_screen_arg arg; - - screen = CALLOC_STRUCT(dri_screen); - if (!screen) - return NULL; - - screen->api = drm_api_create(); - screen->sPriv = sPriv; - screen->fd = sPriv->fd; - screen->drmLock = (drmLock *) & sPriv->pSAREA->lock; - - sPriv->private = (void *)screen; - sPriv->extensions = dri1_screen_extensions; - - arg.base.mode = DRM_CREATE_DRI1; - arg.lf = &dri1_lf; - arg.ddx_info = sPriv->pDevPriv; - arg.ddx_info_size = sPriv->devPrivSize; - arg.sarea = sPriv->pSAREA; - dri1_copy_version(&arg.ddx_version, &sPriv->ddx_version); - dri1_copy_version(&arg.dri_version, &sPriv->dri_version); - dri1_copy_version(&arg.drm_version, &sPriv->drm_version); - arg.api = NULL; - - screen->pipe_screen = screen->api->create_screen(screen->api, screen->fd, &arg.base); - - if (!screen->pipe_screen || !arg.api) { - debug_printf("%s: failed to create dri1 screen\n", __FUNCTION__); - goto out_no_screen; - } - - __dri1_api_hooks = arg.api; - - driParseOptionInfo(&screen->optionCache, - __driConfigOptions, __driNConfigOptions); - - /** - * FIXME: If the driver supports format conversion swapbuffer blits, we might - * want to support other color bit depths than the server is currently - * using. - */ - - configs = dri_fill_in_modes(screen, sPriv->fbBPP); - if (!configs) - goto out_no_configs; - - return configs; - out_no_configs: - screen->pipe_screen->destroy(screen->pipe_screen); - out_no_screen: - FREE(screen); - return NULL; -} diff --git a/src/gallium/state_trackers/dri/dri1.h b/src/gallium/state_trackers/dri/dri1.h deleted file mode 100644 index f7441f98abc..00000000000 --- a/src/gallium/state_trackers/dri/dri1.h +++ /dev/null @@ -1,59 +0,0 @@ -/************************************************************************** - * - * Copyright 2009, VMware, Inc. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ -/* - * Author: Keith Whitwell - * Author: Jakob Bornecrantz - */ - -#ifndef DRI1_H -#define DRI1_H - -#include "dri_context.h" -#include "dri_drawable.h" - -#include "state_tracker/st_api.h" -#include "dri_wrapper.h" - -extern struct dri1_api *__dri1_api_hooks; - -const __DRIconfig ** -dri1_init_screen(__DRIscreen * sPriv); - -void -dri1_flush_frontbuffer(struct dri_drawable *drawable, - enum st_attachment_type statt); - -void -dri1_allocate_textures(struct dri_drawable *drawable, - unsigned mask); - -void dri1_swap_buffers(__DRIdrawable * dPriv); - -void -dri1_copy_sub_buffer(__DRIdrawable * dPriv, int x, int y, int w, int h); - -#endif /* DRI1_H */ diff --git a/src/gallium/state_trackers/dri/dri2.c b/src/gallium/state_trackers/dri/dri2.c deleted file mode 100644 index 108b18e9d3c..00000000000 --- a/src/gallium/state_trackers/dri/dri2.c +++ /dev/null @@ -1,413 +0,0 @@ -/* - * Mesa 3-D graphics library - * Version: 7.9 - * - * Copyright 2009, VMware, Inc. - * All Rights Reserved. - * Copyright (C) 2010 LunarG Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * Authors: - * Keith Whitwell - * Jakob Bornecrantz - * Chia-I Wu - */ - -#include "util/u_memory.h" -#include "util/u_inlines.h" -#include "util/u_format.h" -#include "util/u_debug.h" -#include "state_tracker/drm_api.h" - -#include "dri_screen.h" -#include "dri_context.h" -#include "dri_drawable.h" -#include "dri_st_api.h" -#include "dri2.h" - -/** - * DRI2 flush extension. - */ -static void -dri2_flush_drawable(__DRIdrawable *draw) -{ -} - -static void -dri2_invalidate_drawable(__DRIdrawable *dPriv) -{ - struct dri_drawable *drawable = dri_drawable(dPriv); - struct dri_context *ctx = dri_context(dPriv->driContextPriv); - - dri2InvalidateDrawable(dPriv); - drawable->dPriv->lastStamp = *drawable->dPriv->pStamp; - - if (ctx) - ctx->st->notify_invalid_framebuffer(ctx->st, drawable->stfb); -} - -static const __DRI2flushExtension dri2FlushExtension = { - { __DRI2_FLUSH, __DRI2_FLUSH_VERSION }, - dri2_flush_drawable, - dri2_invalidate_drawable, -}; - -/** - * These are used for GLX_EXT_texture_from_pixmap - */ -static void -dri2_set_tex_buffer2(__DRIcontext *pDRICtx, GLint target, - GLint format, __DRIdrawable *dPriv) -{ - struct dri_context *ctx = dri_context(pDRICtx); - struct dri_drawable *drawable = dri_drawable(dPriv); - struct pipe_texture *pt; - - dri_st_framebuffer_validate_att(drawable->stfb, ST_ATTACHMENT_FRONT_LEFT); - - pt = drawable->textures[ST_ATTACHMENT_FRONT_LEFT]; - - if (pt) { - ctx->st->teximage(ctx->st, - (target == GL_TEXTURE_2D) ? ST_TEXTURE_2D : ST_TEXTURE_RECT, - 0, drawable->stvis.color_format, pt, FALSE); - } -} - -static void -dri2_set_tex_buffer(__DRIcontext *pDRICtx, GLint target, - __DRIdrawable *dPriv) -{ - dri2_set_tex_buffer2(pDRICtx, target, __DRI_TEXTURE_FORMAT_RGBA, dPriv); -} - -static const __DRItexBufferExtension dri2TexBufferExtension = { - { __DRI_TEX_BUFFER, __DRI_TEX_BUFFER_VERSION }, - dri2_set_tex_buffer, - dri2_set_tex_buffer2, -}; - -/** - * Get the format of an attachment. - */ -static INLINE enum pipe_format -dri2_drawable_get_format(struct dri_drawable *drawable, - enum st_attachment_type statt) -{ - enum pipe_format format; - - switch (statt) { - case ST_ATTACHMENT_FRONT_LEFT: - case ST_ATTACHMENT_BACK_LEFT: - case ST_ATTACHMENT_FRONT_RIGHT: - case ST_ATTACHMENT_BACK_RIGHT: - format = drawable->stvis.color_format; - break; - case ST_ATTACHMENT_DEPTH_STENCIL: - format = drawable->stvis.depth_stencil_format; - break; - default: - format = PIPE_FORMAT_NONE; - break; - } - - return format; -} - -/** - * Retrieve __DRIbuffer from the DRI loader. - */ -static __DRIbuffer * -dri2_drawable_get_buffers(struct dri_drawable *drawable, - const enum st_attachment_type *statts, - unsigned *count) -{ - __DRIdrawable *dri_drawable = drawable->dPriv; - struct __DRIdri2LoaderExtensionRec *loader = drawable->sPriv->dri2.loader; - boolean with_format; - __DRIbuffer *buffers; - int num_buffers; - unsigned attachments[10]; - unsigned num_attachments, i; - - assert(loader); - with_format = dri_with_format(drawable->sPriv); - - num_attachments = 0; - - /* for Xserver 1.6.0 (DRI2 version 1) we always need to ask for the front */ - if (!with_format) - attachments[num_attachments++] = __DRI_BUFFER_FRONT_LEFT; - - for (i = 0; i < *count; i++) { - enum pipe_format format; - int att, bpp; - - format = dri2_drawable_get_format(drawable, statts[i]); - if (format == PIPE_FORMAT_NONE) - continue; - - switch (statts[i]) { - case ST_ATTACHMENT_FRONT_LEFT: - /* already added */ - if (!with_format) - continue; - att = __DRI_BUFFER_FRONT_LEFT; - break; - case ST_ATTACHMENT_BACK_LEFT: - att = __DRI_BUFFER_BACK_LEFT; - break; - case ST_ATTACHMENT_FRONT_RIGHT: - att = __DRI_BUFFER_FRONT_RIGHT; - break; - case ST_ATTACHMENT_BACK_RIGHT: - att = __DRI_BUFFER_BACK_RIGHT; - break; - case ST_ATTACHMENT_DEPTH_STENCIL: - att = __DRI_BUFFER_DEPTH_STENCIL; - break; - default: - att = -1; - break; - } - - bpp = util_format_get_blocksizebits(format); - - if (att >= 0) { - attachments[num_attachments++] = att; - if (with_format) { - attachments[num_attachments++] = bpp; - } - } - } - - if (with_format) { - num_attachments /= 2; - buffers = loader->getBuffersWithFormat(dri_drawable, - &dri_drawable->w, &dri_drawable->h, - attachments, num_attachments, - &num_buffers, dri_drawable->loaderPrivate); - } - else { - buffers = loader->getBuffers(dri_drawable, - &dri_drawable->w, &dri_drawable->h, - attachments, num_attachments, - &num_buffers, dri_drawable->loaderPrivate); - } - - if (buffers) { - /* set one cliprect to cover the whole dri_drawable */ - dri_drawable->x = 0; - dri_drawable->y = 0; - dri_drawable->backX = 0; - dri_drawable->backY = 0; - dri_drawable->numClipRects = 1; - dri_drawable->pClipRects[0].x1 = 0; - dri_drawable->pClipRects[0].y1 = 0; - dri_drawable->pClipRects[0].x2 = dri_drawable->w; - dri_drawable->pClipRects[0].y2 = dri_drawable->h; - dri_drawable->numBackClipRects = 1; - dri_drawable->pBackClipRects[0].x1 = 0; - dri_drawable->pBackClipRects[0].y1 = 0; - dri_drawable->pBackClipRects[0].x2 = dri_drawable->w; - dri_drawable->pBackClipRects[0].y2 = dri_drawable->h; - - *count = num_buffers; - } - - return buffers; -} - -/** - * Process __DRIbuffer and convert them into pipe_textures. - */ -static void -dri2_drawable_process_buffers(struct dri_drawable *drawable, - __DRIbuffer *buffers, unsigned count) -{ - struct dri_screen *screen = dri_screen(drawable->sPriv); - __DRIdrawable *dri_drawable = drawable->dPriv; - struct pipe_texture templ; - struct winsys_handle whandle; - boolean have_depth = FALSE; - unsigned i; - - if (drawable->old_num == count && - drawable->old_w == dri_drawable->w && - drawable->old_h == dri_drawable->h && - memcmp(drawable->old, buffers, sizeof(__DRIbuffer) * count) == 0) - return; - - for (i = 0; i < ST_ATTACHMENT_COUNT; i++) - pipe_texture_reference(&drawable->textures[i], NULL); - - memset(&templ, 0, sizeof(templ)); - templ.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET; - templ.target = PIPE_TEXTURE_2D; - templ.last_level = 0; - templ.width0 = dri_drawable->w; - templ.height0 = dri_drawable->h; - templ.depth0 = 1; - - memset(&whandle, 0, sizeof(whandle)); - - for (i = 0; i < count; i++) { - __DRIbuffer *buf = &buffers[i]; - enum st_attachment_type statt; - enum pipe_format format; - - switch (buf->attachment) { - case __DRI_BUFFER_FRONT_LEFT: - if (!screen->auto_fake_front) { - statt = ST_ATTACHMENT_INVALID; - break; - } - /* fallthrough */ - case __DRI_BUFFER_FAKE_FRONT_LEFT: - statt = ST_ATTACHMENT_FRONT_LEFT; - break; - case __DRI_BUFFER_BACK_LEFT: - statt = ST_ATTACHMENT_BACK_LEFT; - break; - case __DRI_BUFFER_DEPTH: - case __DRI_BUFFER_DEPTH_STENCIL: - case __DRI_BUFFER_STENCIL: - /* use only the first depth/stencil buffer */ - if (!have_depth) { - have_depth = TRUE; - statt = ST_ATTACHMENT_DEPTH_STENCIL; - } - else { - statt = ST_ATTACHMENT_INVALID; - } - break; - default: - statt = ST_ATTACHMENT_INVALID; - break; - } - - format = dri2_drawable_get_format(drawable, statt); - if (statt == ST_ATTACHMENT_INVALID || format == PIPE_FORMAT_NONE) - continue; - - templ.format = format; - whandle.handle = buf->name; - whandle.stride = buf->pitch; - - drawable->textures[statt] = - screen->pipe_screen->texture_from_handle(screen->pipe_screen, - &templ, &whandle); - } - - drawable->old_num = count; - drawable->old_w = dri_drawable->w; - drawable->old_h = dri_drawable->h; - memcpy(drawable->old, buffers, sizeof(__DRIbuffer) * count); -} - -/* - * Backend functions for st_framebuffer interface. - */ - -void -dri2_allocate_textures(struct dri_drawable *drawable, - const enum st_attachment_type *statts, - unsigned count) -{ - __DRIbuffer *buffers; - unsigned num_buffers = count; - - buffers = dri2_drawable_get_buffers(drawable, statts, &num_buffers); - dri2_drawable_process_buffers(drawable, buffers, num_buffers); -} - -void -dri2_flush_frontbuffer(struct dri_drawable *drawable, - enum st_attachment_type statt) -{ - __DRIdrawable *dri_drawable = drawable->dPriv; - struct __DRIdri2LoaderExtensionRec *loader = drawable->sPriv->dri2.loader; - - if (loader->flushFrontBuffer == NULL) - return; - - if (statt == ST_ATTACHMENT_FRONT_LEFT) { - loader->flushFrontBuffer(dri_drawable, dri_drawable->loaderPrivate); - } -} - -/* - * Backend function init_screen. - */ - -static const __DRIextension *dri_screen_extensions[] = { - &driReadDrawableExtension, - &driCopySubBufferExtension.base, - &driSwapControlExtension.base, - &driFrameTrackingExtension.base, - &driMediaStreamCounterExtension.base, - &dri2TexBufferExtension.base, - &dri2FlushExtension.base, - NULL -}; - -/** - * This is the driver specific part of the createNewScreen entry point. - * - * Returns the __GLcontextModes supported by this driver. - */ -const __DRIconfig ** -dri2_init_screen(__DRIscreen * sPriv) -{ - struct dri_screen *screen; - struct drm_create_screen_arg arg; - - screen = CALLOC_STRUCT(dri_screen); - if (!screen) - return NULL; - - screen->api = drm_api_create(); - screen->sPriv = sPriv; - screen->fd = sPriv->fd; - sPriv->private = (void *)screen; - sPriv->extensions = dri_screen_extensions; - arg.mode = DRM_CREATE_NORMAL; - - screen->pipe_screen = screen->api->create_screen(screen->api, screen->fd, &arg); - if (!screen->pipe_screen) { - debug_printf("%s: failed to create pipe_screen\n", __FUNCTION__); - goto fail; - } - - screen->smapi = dri_create_st_manager(screen); - if (!screen->smapi) - goto fail; - - driParseOptionInfo(&screen->optionCache, - __driConfigOptions, __driNConfigOptions); - - screen->auto_fake_front = dri_with_format(sPriv); - - return dri_fill_in_modes(screen, 32); -fail: - dri_destroy_screen(sPriv); - return NULL; -} - -/* vim: set sw=3 ts=8 sts=3 expandtab: */ diff --git a/src/gallium/state_trackers/dri/dri2.h b/src/gallium/state_trackers/dri/dri2.h deleted file mode 100644 index 379963431fb..00000000000 --- a/src/gallium/state_trackers/dri/dri2.h +++ /dev/null @@ -1,46 +0,0 @@ -/************************************************************************** - * - * Copyright 2009, VMware, Inc. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -#ifndef DRI2_H -#define DRI2_H - -#include "dri_drawable.h" -#include "dri_wrapper.h" - -const __DRIconfig ** -dri2_init_screen(__DRIscreen * sPriv); - -void -dri2_flush_frontbuffer(struct dri_drawable *drawable, - enum st_attachment_type statt); - -void -dri2_allocate_textures(struct dri_drawable *drawable, - const enum st_attachment_type *statts, - unsigned count); - -#endif /* DRI2_H */ diff --git a/src/gallium/state_trackers/dri/drisw.c b/src/gallium/state_trackers/dri/drisw.c deleted file mode 100644 index 73bc45d9060..00000000000 --- a/src/gallium/state_trackers/dri/drisw.c +++ /dev/null @@ -1,318 +0,0 @@ -/************************************************************************** - * - * Copyright 2009, VMware, Inc. - * All Rights Reserved. - * Copyright 2010 George Sapountzis - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -/* TODO: - * - * stride: - * - * The driver and the loaders (libGL, xserver/glx) compute the stride from the - * width independently. winsys has a workaround that works for softpipe but may - * explode for other drivers or platforms, rendering- or performance-wise. - * Solving this issue properly requires extending the DRISW loader extension, - * in order to make the stride available to the putImage callback. - * - * drisw_api: - * - * Define drisw_api similarly to dri_api and use it to call the loader. This is - * predicated on support for calling the loader from the winsys, which has to - * grow for DRI2 as well. - * - * xshm: - * - * Allow the loaders to use the XSHM extension. It probably requires callbacks - * for createImage/destroyImage similar to DRI2 getBuffers. Probably not worth - * it, given the scope of DRISW, unless it falls naturally from properly - * solving the above two issues. - * - * swrast_create_screen: - * - * Allow for any software renderer to be used. Factor out the code from - * targets/libgl-xlib/xlib.c, put it in targets/common or winsys/sw/common and - * use it in all software targets. - */ - -#include "util/u_memory.h" -#include "util/u_inlines.h" -#include "pipe/p_context.h" -#include "state_tracker/drm_api.h" - -#include "dri_screen.h" -#include "dri_context.h" -#include "dri_drawable.h" -#include "dri_st_api.h" -#include "dri1_helper.h" -#include "drisw.h" - - -static INLINE void -get_drawable_info(__DRIdrawable *dPriv, int *w, int *h) -{ - __DRIscreen *sPriv = dPriv->driScreenPriv; - const __DRIswrastLoaderExtension *loader = sPriv->swrast_loader; - int x, y; - - loader->getDrawableInfo(dPriv, - &x, &y, w, h, - dPriv->loaderPrivate); -} - -static INLINE void -put_image(__DRIdrawable *dPriv, void *data) -{ - __DRIscreen *sPriv = dPriv->driScreenPriv; - const __DRIswrastLoaderExtension *loader = sPriv->swrast_loader; - - loader->putImage(dPriv, __DRI_SWRAST_IMAGE_OP_SWAP, - 0, 0, dPriv->w, dPriv->h, - data, dPriv->loaderPrivate); -} - -void -drisw_update_drawable_info(__DRIdrawable *dPriv) -{ - get_drawable_info(dPriv, &dPriv->w, &dPriv->h); -} - -static INLINE void -drisw_present_texture(__DRIdrawable *dPriv, - struct pipe_texture *ptex) -{ - struct dri_drawable *drawable = dri_drawable(dPriv); - struct dri_screen *screen = dri_screen(drawable->sPriv); - struct pipe_context *pipe; - struct pipe_surface *psurf; - struct pipe_transfer *ptrans; - void *pmap; - - pipe = dri1_get_pipe_context(screen); - psurf = dri1_get_pipe_surface(drawable, ptex); - if (!pipe || !psurf) - return; - - ptrans = pipe->get_tex_transfer(pipe, ptex, 0, 0, 0, - PIPE_TRANSFER_READ, - 0, 0, dPriv->w, dPriv->h); - - pmap = pipe->transfer_map(pipe, ptrans); - - assert(pmap); - - put_image(dPriv, pmap); - - pipe->transfer_unmap(pipe, ptrans); - - pipe->tex_transfer_destroy(pipe, ptrans); -} - -static INLINE void -drisw_invalidate_drawable(__DRIdrawable *dPriv) -{ - struct dri_context *ctx = dri_get_current(); - struct dri_drawable *drawable = dri_drawable(dPriv); - - drawable->texture_stamp = dPriv->lastStamp - 1; - - /* check if swapping currently bound buffer */ - if (ctx && ctx->dPriv == dPriv) - ctx->st->notify_invalid_framebuffer(ctx->st, drawable->stfb); -} - -static INLINE void -drisw_copy_to_front(__DRIdrawable * dPriv, - struct pipe_texture *ptex) -{ - drisw_present_texture(dPriv, ptex); - - drisw_invalidate_drawable(dPriv); -} - -/* - * Backend functions for st_framebuffer interface and swap_buffers. - */ - -void -drisw_flush_frontbuffer(struct dri_drawable *drawable, - enum st_attachment_type statt) -{ - struct dri_context *ctx = dri_get_current(); - struct pipe_texture *ptex; - - if (!ctx) - return; - - ptex = drawable->textures[statt]; - - if (ptex) { - drisw_copy_to_front(ctx->dPriv, ptex); - } -} - -void -drisw_swap_buffers(__DRIdrawable *dPriv) -{ - struct dri_context *ctx = dri_get_current(); - struct dri_drawable *drawable = dri_drawable(dPriv); - struct pipe_texture *ptex; - - if (!ctx) - return; - - ptex = drawable->textures[ST_ATTACHMENT_BACK_LEFT]; - - if (ptex) { - ctx->st->flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); - - drisw_copy_to_front(dPriv, ptex); - } -} - -/** - * Allocate framebuffer attachments. - * - * During fixed-size operation, the function keeps allocating new attachments - * as they are requested. Unused attachments are not removed, not until the - * framebuffer is resized or destroyed. - * - * It should be possible for DRI1 and DRISW to share this function, but it - * seems a better seperation and safer for each DRI version to provide its own - * function. - */ -void -drisw_allocate_textures(struct dri_drawable *drawable, - unsigned mask) -{ - struct dri_screen *screen = dri_screen(drawable->sPriv); - struct pipe_texture templ; - unsigned width, height; - boolean resized; - int i; - - width = drawable->dPriv->w; - height = drawable->dPriv->h; - - resized = (drawable->old_w != width || - drawable->old_h != height); - - /* remove outdated textures */ - if (resized) { - for (i = 0; i < ST_ATTACHMENT_COUNT; i++) - pipe_texture_reference(&drawable->textures[i], NULL); - } - - memset(&templ, 0, sizeof(templ)); - templ.target = PIPE_TEXTURE_2D; - templ.width0 = width; - templ.height0 = height; - templ.depth0 = 1; - templ.last_level = 0; - - for (i = 0; i < ST_ATTACHMENT_COUNT; i++) { - enum pipe_format format; - unsigned tex_usage; - - /* the texture already exists or not requested */ - if (drawable->textures[i] || !(mask & (1 << i))) { - continue; - } - - switch (i) { - case ST_ATTACHMENT_FRONT_LEFT: - case ST_ATTACHMENT_BACK_LEFT: - case ST_ATTACHMENT_FRONT_RIGHT: - case ST_ATTACHMENT_BACK_RIGHT: - format = drawable->stvis.color_format; - tex_usage = PIPE_TEXTURE_USAGE_DISPLAY_TARGET | - PIPE_TEXTURE_USAGE_RENDER_TARGET; - break; - case ST_ATTACHMENT_DEPTH_STENCIL: - format = drawable->stvis.depth_stencil_format; - tex_usage = PIPE_TEXTURE_USAGE_DEPTH_STENCIL; - break; - default: - format = PIPE_FORMAT_NONE; - break; - } - - if (format != PIPE_FORMAT_NONE) { - templ.format = format; - templ.tex_usage = tex_usage; - - drawable->textures[i] = - screen->pipe_screen->texture_create(screen->pipe_screen, &templ); - } - } - - drawable->old_w = width; - drawable->old_h = height; -} - -/* - * Backend function for init_screen. - */ - -static const __DRIextension *drisw_screen_extensions[] = { - NULL -}; - -const __DRIconfig ** -drisw_init_screen(__DRIscreen * sPriv) -{ - struct dri_screen *screen; - struct drm_create_screen_arg arg; - - screen = CALLOC_STRUCT(dri_screen); - if (!screen) - return NULL; - - screen->api = drm_api_create(); - screen->sPriv = sPriv; - screen->fd = -1; - sPriv->private = (void *)screen; - sPriv->extensions = drisw_screen_extensions; - arg.mode = DRM_CREATE_DRISW; - - screen->pipe_screen = screen->api->create_screen(screen->api, -1, &arg); - if (!screen->pipe_screen) { - debug_printf("%s: failed to create pipe_screen\n", __FUNCTION__); - goto fail; - } - - screen->smapi = dri_create_st_manager(screen); - if (!screen->smapi) - goto fail; - - driParseOptionInfo(&screen->optionCache, - __driConfigOptions, __driNConfigOptions); - - return dri_fill_in_modes(screen, 32); -fail: - dri_destroy_screen(sPriv); - return NULL; -} - -/* vim: set sw=3 ts=8 sts=3 expandtab: */ diff --git a/src/gallium/state_trackers/dri/drisw.h b/src/gallium/state_trackers/dri/drisw.h deleted file mode 100644 index 2c0d5610fac..00000000000 --- a/src/gallium/state_trackers/dri/drisw.h +++ /dev/null @@ -1,54 +0,0 @@ -/************************************************************************** - * - * Copyright 2009, VMware, Inc. - * All Rights Reserved. - * Copyright 2010 George Sapountzis - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -#ifndef DRISW_H -#define DRISW_H - -#include "dri_context.h" -#include "dri_drawable.h" - -#include "state_tracker/st_api.h" -#include "dri_wrapper.h" - -const __DRIconfig ** -drisw_init_screen(__DRIscreen * sPriv); - -void -drisw_update_drawable_info(__DRIdrawable *dPriv); - -void -drisw_flush_frontbuffer(struct dri_drawable *drawable, - enum st_attachment_type statt); - -void -drisw_allocate_textures(struct dri_drawable *drawable, - unsigned mask); - -void drisw_swap_buffers(__DRIdrawable * dPriv); - -#endif /* DRISW_H */ diff --git a/src/gallium/state_trackers/dri/drm/Makefile b/src/gallium/state_trackers/dri/drm/Makefile new file mode 100644 index 00000000000..c43bfee8b8f --- /dev/null +++ b/src/gallium/state_trackers/dri/drm/Makefile @@ -0,0 +1,33 @@ +TOP = ../../../../.. +include $(TOP)/configs/current + +LIBNAME = dridrm + +LIBRARY_INCLUDES = \ + -I$(TOP)/include \ + -I$(TOP)/src/mesa \ + -I$(TOP)/src/gallium/state_trackers/dri \ + -I$(TOP)/src/mesa/drivers/dri/common \ + -I$(TOP)/src/mesa/main \ + $(shell pkg-config --cflags-only-I libdrm) + + +C_SOURCES = \ + dri_context.c \ + dri_screen.c \ + dri_drawable.c \ + dri_extensions.c \ + dri_st_api.c \ + dri1_helper.c \ + dri1.c \ + dri2.c + +# $(TOP)/src/mesa/drivers/dri/common/utils.c \ + $(TOP)/src/mesa/drivers/dri/common/vblank.c \ + $(TOP)/src/mesa/drivers/dri/common/dri_util.c \ + $(TOP)/src/mesa/drivers/dri/common/xmlconfig.c \ + $(TOP)/src/mesa/drivers/common/driverfuncs.c \ + $(TOP)/src/mesa/drivers/dri/common/texmem.c \ + $(TOP)/src/mesa/drivers/dri/common/drirenderbuffer.c + +include ../../../Makefile.template diff --git a/src/gallium/state_trackers/dri/drm/SConscript b/src/gallium/state_trackers/dri/drm/SConscript new file mode 100644 index 00000000000..a9c359c2e89 --- /dev/null +++ b/src/gallium/state_trackers/dri/drm/SConscript @@ -0,0 +1,28 @@ +####################################################################### +# SConscript for dri state_tracker + +Import('*') + +if env['dri']: + + env = env.Clone() + + env.Append(CPPPATH = [ + '#/src/mesa', + '#/src/gallium/state_trackers/dri', + '#/src/mesa/drivers/dri/common', + ]) + + st_dri = env.ConvenienceLibrary( + target = 'st_dri', + source = [ 'dri_context.c', + 'dri_drawable.c', + 'dri_extensions.c', + 'dri_screen.c', + 'dri_st_api.c', + 'dri1_helper.c', + 'dri1.c', + 'dri2.c', + ] + ) + Export('st_dri') diff --git a/src/gallium/state_trackers/dri/drm/dri1.c b/src/gallium/state_trackers/dri/drm/dri1.c new file mode 100644 index 00000000000..98bdb2936a1 --- /dev/null +++ b/src/gallium/state_trackers/dri/drm/dri1.c @@ -0,0 +1,526 @@ +/************************************************************************** + * + * Copyright 2009, VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ +/* + * Author: Keith Whitwell + * Author: Jakob Bornecrantz + */ + +/* XXX DRI1 is untested after the switch to st_api.h */ + +#include "util/u_memory.h" +#include "util/u_rect.h" +#include "util/u_inlines.h" +#include "pipe/p_context.h" +#include "state_tracker/dri1_api.h" + +#include "dri_screen.h" +#include "dri_context.h" +#include "dri_drawable.h" +#include "dri_st_api.h" +#include "dri1_helper.h" +#include "dri1.h" + +static INLINE void +dri1_lock(struct dri_context *ctx) +{ + drm_context_t hw_context = ctx->cPriv->hHWContext; + char ret = 0; + + DRM_CAS(ctx->lock, hw_context, DRM_LOCK_HELD | hw_context, ret); + if (ret) { + drmGetLock(ctx->sPriv->fd, hw_context, 0); + ctx->stLostLock = TRUE; + ctx->wsLostLock = TRUE; + } + ctx->isLocked = TRUE; +} + +static INLINE void +dri1_unlock(struct dri_context *ctx) +{ + ctx->isLocked = FALSE; + DRM_UNLOCK(ctx->sPriv->fd, ctx->lock, ctx->cPriv->hHWContext); +} + +static void +dri1_update_drawables_locked(struct dri_context *ctx, + __DRIdrawable * driDrawPriv, + __DRIdrawable * driReadPriv) +{ + if (ctx->stLostLock) { + ctx->stLostLock = FALSE; + if (driDrawPriv == driReadPriv) + DRI_VALIDATE_DRAWABLE_INFO(ctx->sPriv, driDrawPriv); + else + DRI_VALIDATE_TWO_DRAWABLES_INFO(ctx->sPriv, driDrawPriv, + driReadPriv); + } +} + +/** + * This ensures all contexts which bind to a drawable pick up the + * drawable change and signal new buffer state. + */ +static void +dri1_propagate_drawable_change(struct dri_context *ctx) +{ + __DRIdrawable *dPriv = ctx->dPriv; + __DRIdrawable *rPriv = ctx->rPriv; + struct dri_drawable *draw = dri_drawable(dPriv); + struct dri_drawable *read = dri_drawable(rPriv); + boolean flushed = FALSE; + + if (dPriv && draw->texture_stamp != dPriv->lastStamp) { + ctx->st->flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); + flushed = TRUE; + ctx->st->notify_invalid_framebuffer(ctx->st, draw->stfb); + } + + if (rPriv && dPriv != rPriv && read->texture_stamp != rPriv->lastStamp) { + if (!flushed) + ctx->st->flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); + ctx->st->notify_invalid_framebuffer(ctx->st, read->stfb); + } +} + +static INLINE boolean +dri1_intersect_src_bbox(struct drm_clip_rect *dst, + int dst_x, + int dst_y, + const struct drm_clip_rect *src, + const struct drm_clip_rect *bbox) +{ + int xy1; + int xy2; + + xy1 = ((int)src->x1 > (int)bbox->x1 + dst_x) ? src->x1 : + (int)bbox->x1 + dst_x; + xy2 = ((int)src->x2 < (int)bbox->x2 + dst_x) ? src->x2 : + (int)bbox->x2 + dst_x; + if (xy1 >= xy2 || xy1 < 0) + return FALSE; + + dst->x1 = xy1; + dst->x2 = xy2; + + xy1 = ((int)src->y1 > (int)bbox->y1 + dst_y) ? src->y1 : + (int)bbox->y1 + dst_y; + xy2 = ((int)src->y2 < (int)bbox->y2 + dst_y) ? src->y2 : + (int)bbox->y2 + dst_y; + if (xy1 >= xy2 || xy1 < 0) + return FALSE; + + dst->y1 = xy1; + dst->y2 = xy2; + return TRUE; +} + +static void +dri1_swap_copy(struct pipe_context *pipe, + struct pipe_surface *dst, + struct pipe_surface *src, + __DRIdrawable * dPriv, const struct drm_clip_rect *bbox) +{ + struct drm_clip_rect clip; + struct drm_clip_rect *cur; + int i; + + cur = dPriv->pClipRects; + + for (i = 0; i < dPriv->numClipRects; ++i) { + if (dri1_intersect_src_bbox(&clip, dPriv->x, dPriv->y, cur++, bbox)) { + if (pipe->surface_copy) { + pipe->surface_copy(pipe, dst, clip.x1, clip.y1, + src, + (int)clip.x1 - dPriv->x, + (int)clip.y1 - dPriv->y, + clip.x2 - clip.x1, clip.y2 - clip.y1); + } else { + util_surface_copy(pipe, FALSE, dst, clip.x1, clip.y1, + src, + (int)clip.x1 - dPriv->x, + (int)clip.y1 - dPriv->y, + clip.x2 - clip.x1, clip.y2 - clip.y1); + } + } + } +} + +static void +dri1_present_texture_locked(__DRIdrawable * dPriv, + struct pipe_texture *ptex, + const struct drm_clip_rect *sub_box, + struct pipe_fence_handle **fence) +{ + struct dri_drawable *drawable = dri_drawable(dPriv); + struct dri_screen *screen = dri_screen(drawable->sPriv); + struct pipe_context *pipe; + struct pipe_surface *psurf; + struct drm_clip_rect bbox; + boolean visible = TRUE; + + *fence = NULL; + + bbox.x1 = 0; + bbox.x2 = ptex->width0; + bbox.y1 = 0; + bbox.y2 = ptex->height0; + + if (sub_box) + visible = dri1_intersect_src_bbox(&bbox, 0, 0, &bbox, sub_box); + if (!visible) + return; + + pipe = dri1_get_pipe_context(screen); + psurf = dri1_get_pipe_surface(drawable, ptex); + if (!pipe || !psurf) + return; + + if (__dri1_api_hooks->present_locked) { + __dri1_api_hooks->present_locked(pipe, psurf, + dPriv->pClipRects, dPriv->numClipRects, + dPriv->x, dPriv->y, &bbox, fence); + } else if (__dri1_api_hooks->front_srf_locked) { + struct pipe_surface *front = __dri1_api_hooks->front_srf_locked(pipe); + + if (front) + dri1_swap_copy(pipe, front, psurf, dPriv, &bbox); + + pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, fence); + } +} + +static void +dri1_copy_to_front(struct dri_context *ctx, + struct pipe_texture *ptex, + __DRIdrawable * dPriv, + const struct drm_clip_rect *sub_box, + struct pipe_fence_handle **fence) +{ + boolean save_lost_lock; + + dri1_lock(ctx); + save_lost_lock = ctx->stLostLock; + dri1_update_drawables_locked(ctx, dPriv, dPriv); + + dri1_present_texture_locked(dPriv, ptex, sub_box, fence); + + ctx->stLostLock = save_lost_lock; + + /** + * FIXME: Revisit this: Update drawables on copy_sub_buffer ? + */ + + if (!sub_box) + dri1_update_drawables_locked(ctx, ctx->dPriv, ctx->rPriv); + + dri1_unlock(ctx); + dri1_propagate_drawable_change(ctx); +} + +/* + * Backend functions for st_framebuffer interface and swap_buffers. + */ + +void +dri1_flush_frontbuffer(struct dri_drawable *draw, + enum st_attachment_type statt) +{ + struct dri_context *ctx = dri_get_current(); + struct dri_screen *screen = dri_screen(draw->sPriv); + struct pipe_screen *pipe_screen = screen->pipe_screen; + struct pipe_fence_handle *dummy_fence; + struct pipe_texture *ptex; + + if (!ctx) + return; /* For now */ + + ptex = draw->textures[statt]; + if (ptex) { + dri1_copy_to_front(ctx, ptex, ctx->dPriv, NULL, &dummy_fence); + pipe_screen->fence_reference(pipe_screen, &dummy_fence, NULL); + } + + /** + * FIXME: Do we need swap throttling here? + */ +} + +void +dri1_swap_buffers(__DRIdrawable * dPriv) +{ + struct dri_context *ctx = dri_get_current(); + struct dri_drawable *draw = dri_drawable(dPriv); + struct dri_screen *screen = dri_screen(draw->sPriv); + struct pipe_screen *pipe_screen = screen->pipe_screen; + struct pipe_fence_handle *fence; + struct pipe_texture *ptex; + + assert(__dri1_api_hooks != NULL); + + if (!ctx) + return; /* For now */ + + ptex = draw->textures[ST_ATTACHMENT_BACK_LEFT]; + if (ptex) { + ctx->st->flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); + fence = dri1_swap_fences_pop_front(draw); + if (fence) { + (void)pipe_screen->fence_finish(pipe_screen, fence, 0); + pipe_screen->fence_reference(pipe_screen, &fence, NULL); + } + dri1_copy_to_front(ctx, ptex, dPriv, NULL, &fence); + dri1_swap_fences_push_back(draw, fence); + pipe_screen->fence_reference(pipe_screen, &fence, NULL); + } +} + +void +dri1_copy_sub_buffer(__DRIdrawable * dPriv, int x, int y, int w, int h) +{ + struct dri_context *ctx = dri_get_current(); + struct dri_screen *screen = dri_screen(dPriv->driScreenPriv); + struct pipe_screen *pipe_screen = screen->pipe_screen; + struct drm_clip_rect sub_bbox; + struct dri_drawable *draw = dri_drawable(dPriv); + struct pipe_fence_handle *dummy_fence; + struct pipe_texture *ptex; + + assert(__dri1_api_hooks != NULL); + + if (!ctx) + return; + + sub_bbox.x1 = x; + sub_bbox.x2 = x + w; + sub_bbox.y1 = y; + sub_bbox.y2 = y + h; + + ptex = draw->textures[ST_ATTACHMENT_BACK_LEFT]; + if (ptex) { + ctx->st->flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); + dri1_copy_to_front(ctx, ptex, dPriv, &sub_bbox, &dummy_fence); + pipe_screen->fence_reference(pipe_screen, &dummy_fence, NULL); + } +} + +/** + * Allocate framebuffer attachments. + * + * During fixed-size operation, the function keeps allocating new attachments + * as they are requested. Unused attachments are not removed, not until the + * framebuffer is resized or destroyed. + */ +void +dri1_allocate_textures(struct dri_drawable *drawable, + unsigned mask) +{ + struct dri_screen *screen = dri_screen(drawable->sPriv); + struct pipe_texture templ; + unsigned width, height; + boolean resized; + int i; + + width = drawable->dPriv->w; + height = drawable->dPriv->h; + + resized = (drawable->old_w != width || + drawable->old_h != height); + + /* remove outdated textures */ + if (resized) { + for (i = 0; i < ST_ATTACHMENT_COUNT; i++) + pipe_texture_reference(&drawable->textures[i], NULL); + } + + memset(&templ, 0, sizeof(templ)); + templ.target = PIPE_TEXTURE_2D; + templ.width0 = width; + templ.height0 = height; + templ.depth0 = 1; + templ.last_level = 0; + + for (i = 0; i < ST_ATTACHMENT_COUNT; i++) { + enum pipe_format format; + unsigned tex_usage; + + /* the texture already exists or not requested */ + if (drawable->textures[i] || !(mask & (1 << i))) { + continue; + } + + switch (i) { + case ST_ATTACHMENT_FRONT_LEFT: + case ST_ATTACHMENT_BACK_LEFT: + case ST_ATTACHMENT_FRONT_RIGHT: + case ST_ATTACHMENT_BACK_RIGHT: + format = drawable->stvis.color_format; + tex_usage = PIPE_TEXTURE_USAGE_DISPLAY_TARGET | + PIPE_TEXTURE_USAGE_RENDER_TARGET; + break; + case ST_ATTACHMENT_DEPTH_STENCIL: + format = drawable->stvis.depth_stencil_format; + tex_usage = PIPE_TEXTURE_USAGE_DEPTH_STENCIL; + break; + default: + format = PIPE_FORMAT_NONE; + break; + } + + if (format != PIPE_FORMAT_NONE) { + templ.format = format; + templ.tex_usage = tex_usage; + + drawable->textures[i] = + screen->pipe_screen->texture_create(screen->pipe_screen, &templ); + } + } + + drawable->old_w = width; + drawable->old_h = height; +} + +static void +st_dri_lock(struct pipe_context *pipe) +{ + dri1_lock((struct dri_context *)pipe->priv); +} + +static void +st_dri_unlock(struct pipe_context *pipe) +{ + dri1_unlock((struct dri_context *)pipe->priv); +} + +static boolean +st_dri_is_locked(struct pipe_context *pipe) +{ + return ((struct dri_context *)pipe->priv)->isLocked; +} + +static boolean +st_dri_lost_lock(struct pipe_context *pipe) +{ + return ((struct dri_context *)pipe->priv)->wsLostLock; +} + +static void +st_dri_clear_lost_lock(struct pipe_context *pipe) +{ + ((struct dri_context *)pipe->priv)->wsLostLock = FALSE; +} + +static struct dri1_api_lock_funcs dri1_lf = { + .lock = st_dri_lock, + .unlock = st_dri_unlock, + .is_locked = st_dri_is_locked, + .is_lock_lost = st_dri_lost_lock, + .clear_lost_lock = st_dri_clear_lost_lock +}; + +/* + * Backend function for init_screen. + */ + +static const __DRIextension *dri1_screen_extensions[] = { + &driReadDrawableExtension, + &driCopySubBufferExtension.base, + &driSwapControlExtension.base, + &driFrameTrackingExtension.base, + &driMediaStreamCounterExtension.base, + NULL +}; + +struct dri1_api *__dri1_api_hooks = NULL; + +static INLINE void +dri1_copy_version(struct dri1_api_version *dst, + const struct __DRIversionRec *src) +{ + dst->major = src->major; + dst->minor = src->minor; + dst->patch_level = src->patch; +} + +const __DRIconfig ** +dri1_init_screen(__DRIscreen * sPriv) +{ + struct dri_screen *screen; + const __DRIconfig **configs; + struct dri1_create_screen_arg arg; + + screen = CALLOC_STRUCT(dri_screen); + if (!screen) + return NULL; + + screen->api = drm_api_create(); + screen->sPriv = sPriv; + screen->fd = sPriv->fd; + screen->drmLock = (drmLock *) & sPriv->pSAREA->lock; + + sPriv->private = (void *)screen; + sPriv->extensions = dri1_screen_extensions; + + arg.base.mode = DRM_CREATE_DRI1; + arg.lf = &dri1_lf; + arg.ddx_info = sPriv->pDevPriv; + arg.ddx_info_size = sPriv->devPrivSize; + arg.sarea = sPriv->pSAREA; + dri1_copy_version(&arg.ddx_version, &sPriv->ddx_version); + dri1_copy_version(&arg.dri_version, &sPriv->dri_version); + dri1_copy_version(&arg.drm_version, &sPriv->drm_version); + arg.api = NULL; + + screen->pipe_screen = screen->api->create_screen(screen->api, screen->fd, &arg.base); + + if (!screen->pipe_screen || !arg.api) { + debug_printf("%s: failed to create dri1 screen\n", __FUNCTION__); + goto out_no_screen; + } + + __dri1_api_hooks = arg.api; + + driParseOptionInfo(&screen->optionCache, + __driConfigOptions, __driNConfigOptions); + + /** + * FIXME: If the driver supports format conversion swapbuffer blits, we might + * want to support other color bit depths than the server is currently + * using. + */ + + configs = dri_fill_in_modes(screen, sPriv->fbBPP); + if (!configs) + goto out_no_configs; + + return configs; + out_no_configs: + screen->pipe_screen->destroy(screen->pipe_screen); + out_no_screen: + FREE(screen); + return NULL; +} diff --git a/src/gallium/state_trackers/dri/drm/dri1.h b/src/gallium/state_trackers/dri/drm/dri1.h new file mode 100644 index 00000000000..f7441f98abc --- /dev/null +++ b/src/gallium/state_trackers/dri/drm/dri1.h @@ -0,0 +1,59 @@ +/************************************************************************** + * + * Copyright 2009, VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ +/* + * Author: Keith Whitwell + * Author: Jakob Bornecrantz + */ + +#ifndef DRI1_H +#define DRI1_H + +#include "dri_context.h" +#include "dri_drawable.h" + +#include "state_tracker/st_api.h" +#include "dri_wrapper.h" + +extern struct dri1_api *__dri1_api_hooks; + +const __DRIconfig ** +dri1_init_screen(__DRIscreen * sPriv); + +void +dri1_flush_frontbuffer(struct dri_drawable *drawable, + enum st_attachment_type statt); + +void +dri1_allocate_textures(struct dri_drawable *drawable, + unsigned mask); + +void dri1_swap_buffers(__DRIdrawable * dPriv); + +void +dri1_copy_sub_buffer(__DRIdrawable * dPriv, int x, int y, int w, int h); + +#endif /* DRI1_H */ diff --git a/src/gallium/state_trackers/dri/drm/dri1_helper.c b/src/gallium/state_trackers/dri/drm/dri1_helper.c new file mode 120000 index 00000000000..7006a8d882f --- /dev/null +++ b/src/gallium/state_trackers/dri/drm/dri1_helper.c @@ -0,0 +1 @@ +../dri1_helper.c \ No newline at end of file diff --git a/src/gallium/state_trackers/dri/drm/dri2.c b/src/gallium/state_trackers/dri/drm/dri2.c new file mode 100644 index 00000000000..108b18e9d3c --- /dev/null +++ b/src/gallium/state_trackers/dri/drm/dri2.c @@ -0,0 +1,413 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright 2009, VMware, Inc. + * All Rights Reserved. + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * Authors: + * Keith Whitwell + * Jakob Bornecrantz + * Chia-I Wu + */ + +#include "util/u_memory.h" +#include "util/u_inlines.h" +#include "util/u_format.h" +#include "util/u_debug.h" +#include "state_tracker/drm_api.h" + +#include "dri_screen.h" +#include "dri_context.h" +#include "dri_drawable.h" +#include "dri_st_api.h" +#include "dri2.h" + +/** + * DRI2 flush extension. + */ +static void +dri2_flush_drawable(__DRIdrawable *draw) +{ +} + +static void +dri2_invalidate_drawable(__DRIdrawable *dPriv) +{ + struct dri_drawable *drawable = dri_drawable(dPriv); + struct dri_context *ctx = dri_context(dPriv->driContextPriv); + + dri2InvalidateDrawable(dPriv); + drawable->dPriv->lastStamp = *drawable->dPriv->pStamp; + + if (ctx) + ctx->st->notify_invalid_framebuffer(ctx->st, drawable->stfb); +} + +static const __DRI2flushExtension dri2FlushExtension = { + { __DRI2_FLUSH, __DRI2_FLUSH_VERSION }, + dri2_flush_drawable, + dri2_invalidate_drawable, +}; + +/** + * These are used for GLX_EXT_texture_from_pixmap + */ +static void +dri2_set_tex_buffer2(__DRIcontext *pDRICtx, GLint target, + GLint format, __DRIdrawable *dPriv) +{ + struct dri_context *ctx = dri_context(pDRICtx); + struct dri_drawable *drawable = dri_drawable(dPriv); + struct pipe_texture *pt; + + dri_st_framebuffer_validate_att(drawable->stfb, ST_ATTACHMENT_FRONT_LEFT); + + pt = drawable->textures[ST_ATTACHMENT_FRONT_LEFT]; + + if (pt) { + ctx->st->teximage(ctx->st, + (target == GL_TEXTURE_2D) ? ST_TEXTURE_2D : ST_TEXTURE_RECT, + 0, drawable->stvis.color_format, pt, FALSE); + } +} + +static void +dri2_set_tex_buffer(__DRIcontext *pDRICtx, GLint target, + __DRIdrawable *dPriv) +{ + dri2_set_tex_buffer2(pDRICtx, target, __DRI_TEXTURE_FORMAT_RGBA, dPriv); +} + +static const __DRItexBufferExtension dri2TexBufferExtension = { + { __DRI_TEX_BUFFER, __DRI_TEX_BUFFER_VERSION }, + dri2_set_tex_buffer, + dri2_set_tex_buffer2, +}; + +/** + * Get the format of an attachment. + */ +static INLINE enum pipe_format +dri2_drawable_get_format(struct dri_drawable *drawable, + enum st_attachment_type statt) +{ + enum pipe_format format; + + switch (statt) { + case ST_ATTACHMENT_FRONT_LEFT: + case ST_ATTACHMENT_BACK_LEFT: + case ST_ATTACHMENT_FRONT_RIGHT: + case ST_ATTACHMENT_BACK_RIGHT: + format = drawable->stvis.color_format; + break; + case ST_ATTACHMENT_DEPTH_STENCIL: + format = drawable->stvis.depth_stencil_format; + break; + default: + format = PIPE_FORMAT_NONE; + break; + } + + return format; +} + +/** + * Retrieve __DRIbuffer from the DRI loader. + */ +static __DRIbuffer * +dri2_drawable_get_buffers(struct dri_drawable *drawable, + const enum st_attachment_type *statts, + unsigned *count) +{ + __DRIdrawable *dri_drawable = drawable->dPriv; + struct __DRIdri2LoaderExtensionRec *loader = drawable->sPriv->dri2.loader; + boolean with_format; + __DRIbuffer *buffers; + int num_buffers; + unsigned attachments[10]; + unsigned num_attachments, i; + + assert(loader); + with_format = dri_with_format(drawable->sPriv); + + num_attachments = 0; + + /* for Xserver 1.6.0 (DRI2 version 1) we always need to ask for the front */ + if (!with_format) + attachments[num_attachments++] = __DRI_BUFFER_FRONT_LEFT; + + for (i = 0; i < *count; i++) { + enum pipe_format format; + int att, bpp; + + format = dri2_drawable_get_format(drawable, statts[i]); + if (format == PIPE_FORMAT_NONE) + continue; + + switch (statts[i]) { + case ST_ATTACHMENT_FRONT_LEFT: + /* already added */ + if (!with_format) + continue; + att = __DRI_BUFFER_FRONT_LEFT; + break; + case ST_ATTACHMENT_BACK_LEFT: + att = __DRI_BUFFER_BACK_LEFT; + break; + case ST_ATTACHMENT_FRONT_RIGHT: + att = __DRI_BUFFER_FRONT_RIGHT; + break; + case ST_ATTACHMENT_BACK_RIGHT: + att = __DRI_BUFFER_BACK_RIGHT; + break; + case ST_ATTACHMENT_DEPTH_STENCIL: + att = __DRI_BUFFER_DEPTH_STENCIL; + break; + default: + att = -1; + break; + } + + bpp = util_format_get_blocksizebits(format); + + if (att >= 0) { + attachments[num_attachments++] = att; + if (with_format) { + attachments[num_attachments++] = bpp; + } + } + } + + if (with_format) { + num_attachments /= 2; + buffers = loader->getBuffersWithFormat(dri_drawable, + &dri_drawable->w, &dri_drawable->h, + attachments, num_attachments, + &num_buffers, dri_drawable->loaderPrivate); + } + else { + buffers = loader->getBuffers(dri_drawable, + &dri_drawable->w, &dri_drawable->h, + attachments, num_attachments, + &num_buffers, dri_drawable->loaderPrivate); + } + + if (buffers) { + /* set one cliprect to cover the whole dri_drawable */ + dri_drawable->x = 0; + dri_drawable->y = 0; + dri_drawable->backX = 0; + dri_drawable->backY = 0; + dri_drawable->numClipRects = 1; + dri_drawable->pClipRects[0].x1 = 0; + dri_drawable->pClipRects[0].y1 = 0; + dri_drawable->pClipRects[0].x2 = dri_drawable->w; + dri_drawable->pClipRects[0].y2 = dri_drawable->h; + dri_drawable->numBackClipRects = 1; + dri_drawable->pBackClipRects[0].x1 = 0; + dri_drawable->pBackClipRects[0].y1 = 0; + dri_drawable->pBackClipRects[0].x2 = dri_drawable->w; + dri_drawable->pBackClipRects[0].y2 = dri_drawable->h; + + *count = num_buffers; + } + + return buffers; +} + +/** + * Process __DRIbuffer and convert them into pipe_textures. + */ +static void +dri2_drawable_process_buffers(struct dri_drawable *drawable, + __DRIbuffer *buffers, unsigned count) +{ + struct dri_screen *screen = dri_screen(drawable->sPriv); + __DRIdrawable *dri_drawable = drawable->dPriv; + struct pipe_texture templ; + struct winsys_handle whandle; + boolean have_depth = FALSE; + unsigned i; + + if (drawable->old_num == count && + drawable->old_w == dri_drawable->w && + drawable->old_h == dri_drawable->h && + memcmp(drawable->old, buffers, sizeof(__DRIbuffer) * count) == 0) + return; + + for (i = 0; i < ST_ATTACHMENT_COUNT; i++) + pipe_texture_reference(&drawable->textures[i], NULL); + + memset(&templ, 0, sizeof(templ)); + templ.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET; + templ.target = PIPE_TEXTURE_2D; + templ.last_level = 0; + templ.width0 = dri_drawable->w; + templ.height0 = dri_drawable->h; + templ.depth0 = 1; + + memset(&whandle, 0, sizeof(whandle)); + + for (i = 0; i < count; i++) { + __DRIbuffer *buf = &buffers[i]; + enum st_attachment_type statt; + enum pipe_format format; + + switch (buf->attachment) { + case __DRI_BUFFER_FRONT_LEFT: + if (!screen->auto_fake_front) { + statt = ST_ATTACHMENT_INVALID; + break; + } + /* fallthrough */ + case __DRI_BUFFER_FAKE_FRONT_LEFT: + statt = ST_ATTACHMENT_FRONT_LEFT; + break; + case __DRI_BUFFER_BACK_LEFT: + statt = ST_ATTACHMENT_BACK_LEFT; + break; + case __DRI_BUFFER_DEPTH: + case __DRI_BUFFER_DEPTH_STENCIL: + case __DRI_BUFFER_STENCIL: + /* use only the first depth/stencil buffer */ + if (!have_depth) { + have_depth = TRUE; + statt = ST_ATTACHMENT_DEPTH_STENCIL; + } + else { + statt = ST_ATTACHMENT_INVALID; + } + break; + default: + statt = ST_ATTACHMENT_INVALID; + break; + } + + format = dri2_drawable_get_format(drawable, statt); + if (statt == ST_ATTACHMENT_INVALID || format == PIPE_FORMAT_NONE) + continue; + + templ.format = format; + whandle.handle = buf->name; + whandle.stride = buf->pitch; + + drawable->textures[statt] = + screen->pipe_screen->texture_from_handle(screen->pipe_screen, + &templ, &whandle); + } + + drawable->old_num = count; + drawable->old_w = dri_drawable->w; + drawable->old_h = dri_drawable->h; + memcpy(drawable->old, buffers, sizeof(__DRIbuffer) * count); +} + +/* + * Backend functions for st_framebuffer interface. + */ + +void +dri2_allocate_textures(struct dri_drawable *drawable, + const enum st_attachment_type *statts, + unsigned count) +{ + __DRIbuffer *buffers; + unsigned num_buffers = count; + + buffers = dri2_drawable_get_buffers(drawable, statts, &num_buffers); + dri2_drawable_process_buffers(drawable, buffers, num_buffers); +} + +void +dri2_flush_frontbuffer(struct dri_drawable *drawable, + enum st_attachment_type statt) +{ + __DRIdrawable *dri_drawable = drawable->dPriv; + struct __DRIdri2LoaderExtensionRec *loader = drawable->sPriv->dri2.loader; + + if (loader->flushFrontBuffer == NULL) + return; + + if (statt == ST_ATTACHMENT_FRONT_LEFT) { + loader->flushFrontBuffer(dri_drawable, dri_drawable->loaderPrivate); + } +} + +/* + * Backend function init_screen. + */ + +static const __DRIextension *dri_screen_extensions[] = { + &driReadDrawableExtension, + &driCopySubBufferExtension.base, + &driSwapControlExtension.base, + &driFrameTrackingExtension.base, + &driMediaStreamCounterExtension.base, + &dri2TexBufferExtension.base, + &dri2FlushExtension.base, + NULL +}; + +/** + * This is the driver specific part of the createNewScreen entry point. + * + * Returns the __GLcontextModes supported by this driver. + */ +const __DRIconfig ** +dri2_init_screen(__DRIscreen * sPriv) +{ + struct dri_screen *screen; + struct drm_create_screen_arg arg; + + screen = CALLOC_STRUCT(dri_screen); + if (!screen) + return NULL; + + screen->api = drm_api_create(); + screen->sPriv = sPriv; + screen->fd = sPriv->fd; + sPriv->private = (void *)screen; + sPriv->extensions = dri_screen_extensions; + arg.mode = DRM_CREATE_NORMAL; + + screen->pipe_screen = screen->api->create_screen(screen->api, screen->fd, &arg); + if (!screen->pipe_screen) { + debug_printf("%s: failed to create pipe_screen\n", __FUNCTION__); + goto fail; + } + + screen->smapi = dri_create_st_manager(screen); + if (!screen->smapi) + goto fail; + + driParseOptionInfo(&screen->optionCache, + __driConfigOptions, __driNConfigOptions); + + screen->auto_fake_front = dri_with_format(sPriv); + + return dri_fill_in_modes(screen, 32); +fail: + dri_destroy_screen(sPriv); + return NULL; +} + +/* vim: set sw=3 ts=8 sts=3 expandtab: */ diff --git a/src/gallium/state_trackers/dri/drm/dri2.h b/src/gallium/state_trackers/dri/drm/dri2.h new file mode 100644 index 00000000000..379963431fb --- /dev/null +++ b/src/gallium/state_trackers/dri/drm/dri2.h @@ -0,0 +1,46 @@ +/************************************************************************** + * + * Copyright 2009, VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef DRI2_H +#define DRI2_H + +#include "dri_drawable.h" +#include "dri_wrapper.h" + +const __DRIconfig ** +dri2_init_screen(__DRIscreen * sPriv); + +void +dri2_flush_frontbuffer(struct dri_drawable *drawable, + enum st_attachment_type statt); + +void +dri2_allocate_textures(struct dri_drawable *drawable, + const enum st_attachment_type *statts, + unsigned count); + +#endif /* DRI2_H */ diff --git a/src/gallium/state_trackers/dri/drm/dri_context.c b/src/gallium/state_trackers/dri/drm/dri_context.c new file mode 120000 index 00000000000..989ef4438a1 --- /dev/null +++ b/src/gallium/state_trackers/dri/drm/dri_context.c @@ -0,0 +1 @@ +../dri_context.c \ No newline at end of file diff --git a/src/gallium/state_trackers/dri/drm/dri_drawable.c b/src/gallium/state_trackers/dri/drm/dri_drawable.c new file mode 120000 index 00000000000..422c4c1d740 --- /dev/null +++ b/src/gallium/state_trackers/dri/drm/dri_drawable.c @@ -0,0 +1 @@ +../dri_drawable.c \ No newline at end of file diff --git a/src/gallium/state_trackers/dri/drm/dri_extensions.c b/src/gallium/state_trackers/dri/drm/dri_extensions.c new file mode 120000 index 00000000000..b793f06747d --- /dev/null +++ b/src/gallium/state_trackers/dri/drm/dri_extensions.c @@ -0,0 +1 @@ +../dri_extensions.c \ No newline at end of file diff --git a/src/gallium/state_trackers/dri/drm/dri_screen.c b/src/gallium/state_trackers/dri/drm/dri_screen.c new file mode 120000 index 00000000000..938f4c3bdc7 --- /dev/null +++ b/src/gallium/state_trackers/dri/drm/dri_screen.c @@ -0,0 +1 @@ +../dri_screen.c \ No newline at end of file diff --git a/src/gallium/state_trackers/dri/drm/dri_st_api.c b/src/gallium/state_trackers/dri/drm/dri_st_api.c new file mode 120000 index 00000000000..9ae88230ddc --- /dev/null +++ b/src/gallium/state_trackers/dri/drm/dri_st_api.c @@ -0,0 +1 @@ +../dri_st_api.c \ No newline at end of file diff --git a/src/gallium/state_trackers/dri/sw/Makefile b/src/gallium/state_trackers/dri/sw/Makefile new file mode 100644 index 00000000000..35e31e6466a --- /dev/null +++ b/src/gallium/state_trackers/dri/sw/Makefile @@ -0,0 +1,27 @@ +TOP = ../../../../.. +include $(TOP)/configs/current + +LIBNAME = drisw + +LIBRARY_DEFINES = -D__NOT_HAVE_DRM_H + +LIBRARY_INCLUDES = \ + -I../dri \ + -I$(TOP)/include \ + -I$(TOP)/src/mesa \ + -I$(TOP)/src/gallium/state_trackers/dri \ + -I$(TOP)/src/mesa/drivers/dri/common \ + -I$(TOP)/src/mesa/main \ + -D__NOT_HAVE_DRM_H + + +C_SOURCES = \ + dri_context.c \ + dri_screen.c \ + dri_drawable.c \ + dri_extensions.c \ + dri_st_api.c \ + dri1_helper.c \ + drisw.c + +include ../../../Makefile.template diff --git a/src/gallium/state_trackers/dri/sw/dri1_helper.c b/src/gallium/state_trackers/dri/sw/dri1_helper.c new file mode 120000 index 00000000000..7006a8d882f --- /dev/null +++ b/src/gallium/state_trackers/dri/sw/dri1_helper.c @@ -0,0 +1 @@ +../dri1_helper.c \ No newline at end of file diff --git a/src/gallium/state_trackers/dri/sw/dri_context.c b/src/gallium/state_trackers/dri/sw/dri_context.c new file mode 120000 index 00000000000..989ef4438a1 --- /dev/null +++ b/src/gallium/state_trackers/dri/sw/dri_context.c @@ -0,0 +1 @@ +../dri_context.c \ No newline at end of file diff --git a/src/gallium/state_trackers/dri/sw/dri_drawable.c b/src/gallium/state_trackers/dri/sw/dri_drawable.c new file mode 120000 index 00000000000..422c4c1d740 --- /dev/null +++ b/src/gallium/state_trackers/dri/sw/dri_drawable.c @@ -0,0 +1 @@ +../dri_drawable.c \ No newline at end of file diff --git a/src/gallium/state_trackers/dri/sw/dri_extensions.c b/src/gallium/state_trackers/dri/sw/dri_extensions.c new file mode 120000 index 00000000000..b793f06747d --- /dev/null +++ b/src/gallium/state_trackers/dri/sw/dri_extensions.c @@ -0,0 +1 @@ +../dri_extensions.c \ No newline at end of file diff --git a/src/gallium/state_trackers/dri/sw/dri_screen.c b/src/gallium/state_trackers/dri/sw/dri_screen.c new file mode 120000 index 00000000000..938f4c3bdc7 --- /dev/null +++ b/src/gallium/state_trackers/dri/sw/dri_screen.c @@ -0,0 +1 @@ +../dri_screen.c \ No newline at end of file diff --git a/src/gallium/state_trackers/dri/sw/dri_st_api.c b/src/gallium/state_trackers/dri/sw/dri_st_api.c new file mode 120000 index 00000000000..9ae88230ddc --- /dev/null +++ b/src/gallium/state_trackers/dri/sw/dri_st_api.c @@ -0,0 +1 @@ +../dri_st_api.c \ No newline at end of file diff --git a/src/gallium/state_trackers/dri/sw/drisw.c b/src/gallium/state_trackers/dri/sw/drisw.c new file mode 100644 index 00000000000..73bc45d9060 --- /dev/null +++ b/src/gallium/state_trackers/dri/sw/drisw.c @@ -0,0 +1,318 @@ +/************************************************************************** + * + * Copyright 2009, VMware, Inc. + * All Rights Reserved. + * Copyright 2010 George Sapountzis + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* TODO: + * + * stride: + * + * The driver and the loaders (libGL, xserver/glx) compute the stride from the + * width independently. winsys has a workaround that works for softpipe but may + * explode for other drivers or platforms, rendering- or performance-wise. + * Solving this issue properly requires extending the DRISW loader extension, + * in order to make the stride available to the putImage callback. + * + * drisw_api: + * + * Define drisw_api similarly to dri_api and use it to call the loader. This is + * predicated on support for calling the loader from the winsys, which has to + * grow for DRI2 as well. + * + * xshm: + * + * Allow the loaders to use the XSHM extension. It probably requires callbacks + * for createImage/destroyImage similar to DRI2 getBuffers. Probably not worth + * it, given the scope of DRISW, unless it falls naturally from properly + * solving the above two issues. + * + * swrast_create_screen: + * + * Allow for any software renderer to be used. Factor out the code from + * targets/libgl-xlib/xlib.c, put it in targets/common or winsys/sw/common and + * use it in all software targets. + */ + +#include "util/u_memory.h" +#include "util/u_inlines.h" +#include "pipe/p_context.h" +#include "state_tracker/drm_api.h" + +#include "dri_screen.h" +#include "dri_context.h" +#include "dri_drawable.h" +#include "dri_st_api.h" +#include "dri1_helper.h" +#include "drisw.h" + + +static INLINE void +get_drawable_info(__DRIdrawable *dPriv, int *w, int *h) +{ + __DRIscreen *sPriv = dPriv->driScreenPriv; + const __DRIswrastLoaderExtension *loader = sPriv->swrast_loader; + int x, y; + + loader->getDrawableInfo(dPriv, + &x, &y, w, h, + dPriv->loaderPrivate); +} + +static INLINE void +put_image(__DRIdrawable *dPriv, void *data) +{ + __DRIscreen *sPriv = dPriv->driScreenPriv; + const __DRIswrastLoaderExtension *loader = sPriv->swrast_loader; + + loader->putImage(dPriv, __DRI_SWRAST_IMAGE_OP_SWAP, + 0, 0, dPriv->w, dPriv->h, + data, dPriv->loaderPrivate); +} + +void +drisw_update_drawable_info(__DRIdrawable *dPriv) +{ + get_drawable_info(dPriv, &dPriv->w, &dPriv->h); +} + +static INLINE void +drisw_present_texture(__DRIdrawable *dPriv, + struct pipe_texture *ptex) +{ + struct dri_drawable *drawable = dri_drawable(dPriv); + struct dri_screen *screen = dri_screen(drawable->sPriv); + struct pipe_context *pipe; + struct pipe_surface *psurf; + struct pipe_transfer *ptrans; + void *pmap; + + pipe = dri1_get_pipe_context(screen); + psurf = dri1_get_pipe_surface(drawable, ptex); + if (!pipe || !psurf) + return; + + ptrans = pipe->get_tex_transfer(pipe, ptex, 0, 0, 0, + PIPE_TRANSFER_READ, + 0, 0, dPriv->w, dPriv->h); + + pmap = pipe->transfer_map(pipe, ptrans); + + assert(pmap); + + put_image(dPriv, pmap); + + pipe->transfer_unmap(pipe, ptrans); + + pipe->tex_transfer_destroy(pipe, ptrans); +} + +static INLINE void +drisw_invalidate_drawable(__DRIdrawable *dPriv) +{ + struct dri_context *ctx = dri_get_current(); + struct dri_drawable *drawable = dri_drawable(dPriv); + + drawable->texture_stamp = dPriv->lastStamp - 1; + + /* check if swapping currently bound buffer */ + if (ctx && ctx->dPriv == dPriv) + ctx->st->notify_invalid_framebuffer(ctx->st, drawable->stfb); +} + +static INLINE void +drisw_copy_to_front(__DRIdrawable * dPriv, + struct pipe_texture *ptex) +{ + drisw_present_texture(dPriv, ptex); + + drisw_invalidate_drawable(dPriv); +} + +/* + * Backend functions for st_framebuffer interface and swap_buffers. + */ + +void +drisw_flush_frontbuffer(struct dri_drawable *drawable, + enum st_attachment_type statt) +{ + struct dri_context *ctx = dri_get_current(); + struct pipe_texture *ptex; + + if (!ctx) + return; + + ptex = drawable->textures[statt]; + + if (ptex) { + drisw_copy_to_front(ctx->dPriv, ptex); + } +} + +void +drisw_swap_buffers(__DRIdrawable *dPriv) +{ + struct dri_context *ctx = dri_get_current(); + struct dri_drawable *drawable = dri_drawable(dPriv); + struct pipe_texture *ptex; + + if (!ctx) + return; + + ptex = drawable->textures[ST_ATTACHMENT_BACK_LEFT]; + + if (ptex) { + ctx->st->flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); + + drisw_copy_to_front(dPriv, ptex); + } +} + +/** + * Allocate framebuffer attachments. + * + * During fixed-size operation, the function keeps allocating new attachments + * as they are requested. Unused attachments are not removed, not until the + * framebuffer is resized or destroyed. + * + * It should be possible for DRI1 and DRISW to share this function, but it + * seems a better seperation and safer for each DRI version to provide its own + * function. + */ +void +drisw_allocate_textures(struct dri_drawable *drawable, + unsigned mask) +{ + struct dri_screen *screen = dri_screen(drawable->sPriv); + struct pipe_texture templ; + unsigned width, height; + boolean resized; + int i; + + width = drawable->dPriv->w; + height = drawable->dPriv->h; + + resized = (drawable->old_w != width || + drawable->old_h != height); + + /* remove outdated textures */ + if (resized) { + for (i = 0; i < ST_ATTACHMENT_COUNT; i++) + pipe_texture_reference(&drawable->textures[i], NULL); + } + + memset(&templ, 0, sizeof(templ)); + templ.target = PIPE_TEXTURE_2D; + templ.width0 = width; + templ.height0 = height; + templ.depth0 = 1; + templ.last_level = 0; + + for (i = 0; i < ST_ATTACHMENT_COUNT; i++) { + enum pipe_format format; + unsigned tex_usage; + + /* the texture already exists or not requested */ + if (drawable->textures[i] || !(mask & (1 << i))) { + continue; + } + + switch (i) { + case ST_ATTACHMENT_FRONT_LEFT: + case ST_ATTACHMENT_BACK_LEFT: + case ST_ATTACHMENT_FRONT_RIGHT: + case ST_ATTACHMENT_BACK_RIGHT: + format = drawable->stvis.color_format; + tex_usage = PIPE_TEXTURE_USAGE_DISPLAY_TARGET | + PIPE_TEXTURE_USAGE_RENDER_TARGET; + break; + case ST_ATTACHMENT_DEPTH_STENCIL: + format = drawable->stvis.depth_stencil_format; + tex_usage = PIPE_TEXTURE_USAGE_DEPTH_STENCIL; + break; + default: + format = PIPE_FORMAT_NONE; + break; + } + + if (format != PIPE_FORMAT_NONE) { + templ.format = format; + templ.tex_usage = tex_usage; + + drawable->textures[i] = + screen->pipe_screen->texture_create(screen->pipe_screen, &templ); + } + } + + drawable->old_w = width; + drawable->old_h = height; +} + +/* + * Backend function for init_screen. + */ + +static const __DRIextension *drisw_screen_extensions[] = { + NULL +}; + +const __DRIconfig ** +drisw_init_screen(__DRIscreen * sPriv) +{ + struct dri_screen *screen; + struct drm_create_screen_arg arg; + + screen = CALLOC_STRUCT(dri_screen); + if (!screen) + return NULL; + + screen->api = drm_api_create(); + screen->sPriv = sPriv; + screen->fd = -1; + sPriv->private = (void *)screen; + sPriv->extensions = drisw_screen_extensions; + arg.mode = DRM_CREATE_DRISW; + + screen->pipe_screen = screen->api->create_screen(screen->api, -1, &arg); + if (!screen->pipe_screen) { + debug_printf("%s: failed to create pipe_screen\n", __FUNCTION__); + goto fail; + } + + screen->smapi = dri_create_st_manager(screen); + if (!screen->smapi) + goto fail; + + driParseOptionInfo(&screen->optionCache, + __driConfigOptions, __driNConfigOptions); + + return dri_fill_in_modes(screen, 32); +fail: + dri_destroy_screen(sPriv); + return NULL; +} + +/* vim: set sw=3 ts=8 sts=3 expandtab: */ diff --git a/src/gallium/state_trackers/dri/sw/drisw.h b/src/gallium/state_trackers/dri/sw/drisw.h new file mode 100644 index 00000000000..2c0d5610fac --- /dev/null +++ b/src/gallium/state_trackers/dri/sw/drisw.h @@ -0,0 +1,54 @@ +/************************************************************************** + * + * Copyright 2009, VMware, Inc. + * All Rights Reserved. + * Copyright 2010 George Sapountzis + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef DRISW_H +#define DRISW_H + +#include "dri_context.h" +#include "dri_drawable.h" + +#include "state_tracker/st_api.h" +#include "dri_wrapper.h" + +const __DRIconfig ** +drisw_init_screen(__DRIscreen * sPriv); + +void +drisw_update_drawable_info(__DRIdrawable *dPriv); + +void +drisw_flush_frontbuffer(struct dri_drawable *drawable, + enum st_attachment_type statt); + +void +drisw_allocate_textures(struct dri_drawable *drawable, + unsigned mask); + +void drisw_swap_buffers(__DRIdrawable * dPriv); + +#endif /* DRISW_H */ diff --git a/src/gallium/state_trackers/drisw/Makefile b/src/gallium/state_trackers/drisw/Makefile deleted file mode 100644 index dec9a39edec..00000000000 --- a/src/gallium/state_trackers/drisw/Makefile +++ /dev/null @@ -1,26 +0,0 @@ -TOP = ../../../.. -include $(TOP)/configs/current - -LIBNAME = drisw - -LIBRARY_DEFINES = -D__NOT_HAVE_DRM_H - -LIBRARY_INCLUDES = \ - -I../dri \ - -I$(TOP)/include \ - -I$(TOP)/src/mesa \ - -I$(TOP)/src/mesa/drivers/dri/common \ - -I$(TOP)/src/mesa/main \ - -D__NOT_HAVE_DRM_H - - -C_SOURCES = \ - dri_context.c \ - dri_screen.c \ - dri_drawable.c \ - dri_extensions.c \ - dri_st_api.c \ - dri1_helper.c \ - drisw.c - -include ../../Makefile.template diff --git a/src/gallium/state_trackers/drisw/dri1_helper.c b/src/gallium/state_trackers/drisw/dri1_helper.c deleted file mode 120000 index e704e382e05..00000000000 --- a/src/gallium/state_trackers/drisw/dri1_helper.c +++ /dev/null @@ -1 +0,0 @@ -../dri/dri1_helper.c \ No newline at end of file diff --git a/src/gallium/state_trackers/drisw/dri_context.c b/src/gallium/state_trackers/drisw/dri_context.c deleted file mode 120000 index e4e879dc867..00000000000 --- a/src/gallium/state_trackers/drisw/dri_context.c +++ /dev/null @@ -1 +0,0 @@ -../dri/dri_context.c \ No newline at end of file diff --git a/src/gallium/state_trackers/drisw/dri_drawable.c b/src/gallium/state_trackers/drisw/dri_drawable.c deleted file mode 120000 index d7f65c85d20..00000000000 --- a/src/gallium/state_trackers/drisw/dri_drawable.c +++ /dev/null @@ -1 +0,0 @@ -../dri/dri_drawable.c \ No newline at end of file diff --git a/src/gallium/state_trackers/drisw/dri_extensions.c b/src/gallium/state_trackers/drisw/dri_extensions.c deleted file mode 120000 index 60ecde9547d..00000000000 --- a/src/gallium/state_trackers/drisw/dri_extensions.c +++ /dev/null @@ -1 +0,0 @@ -../dri/dri_extensions.c \ No newline at end of file diff --git a/src/gallium/state_trackers/drisw/dri_screen.c b/src/gallium/state_trackers/drisw/dri_screen.c deleted file mode 120000 index f22c562c84f..00000000000 --- a/src/gallium/state_trackers/drisw/dri_screen.c +++ /dev/null @@ -1 +0,0 @@ -../dri/dri_screen.c \ No newline at end of file diff --git a/src/gallium/state_trackers/drisw/dri_st_api.c b/src/gallium/state_trackers/drisw/dri_st_api.c deleted file mode 120000 index eac8ec66905..00000000000 --- a/src/gallium/state_trackers/drisw/dri_st_api.c +++ /dev/null @@ -1 +0,0 @@ -../dri/dri_st_api.c \ No newline at end of file diff --git a/src/gallium/state_trackers/drisw/drisw.c b/src/gallium/state_trackers/drisw/drisw.c deleted file mode 120000 index 258a79021ef..00000000000 --- a/src/gallium/state_trackers/drisw/drisw.c +++ /dev/null @@ -1 +0,0 @@ -../dri/drisw.c \ No newline at end of file diff --git a/src/gallium/targets/dri-i915/Makefile b/src/gallium/targets/dri-i915/Makefile index facbcb1803a..822d4b57bbb 100644 --- a/src/gallium/targets/dri-i915/Makefile +++ b/src/gallium/targets/dri-i915/Makefile @@ -4,7 +4,7 @@ include $(TOP)/configs/current LIBNAME = i915_dri.so PIPE_DRIVERS = \ - $(TOP)/src/gallium/state_trackers/dri/libdridrm.a \ + $(TOP)/src/gallium/state_trackers/dri/drm/libdridrm.a \ $(TOP)/src/gallium/winsys/i915/drm/libinteldrm.a \ $(TOP)/src/gallium/drivers/trace/libtrace.a \ $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ diff --git a/src/gallium/targets/dri-i965/Makefile b/src/gallium/targets/dri-i965/Makefile index c622bbcaf65..e267ba3a023 100644 --- a/src/gallium/targets/dri-i965/Makefile +++ b/src/gallium/targets/dri-i965/Makefile @@ -4,7 +4,7 @@ include $(TOP)/configs/current LIBNAME = i965_dri.so PIPE_DRIVERS = \ - $(TOP)/src/gallium/state_trackers/dri/libdridrm.a \ + $(TOP)/src/gallium/state_trackers/dri/drm/libdridrm.a \ $(TOP)/src/gallium/winsys/i965/drm/libi965drm.a \ $(TOP)/src/gallium/drivers/trace/libtrace.a \ $(TOP)/src/gallium/winsys/sw/drm/libswdrm.a \ diff --git a/src/gallium/targets/dri-nouveau/Makefile b/src/gallium/targets/dri-nouveau/Makefile index 9ba5e18ba70..74d352c6a70 100644 --- a/src/gallium/targets/dri-nouveau/Makefile +++ b/src/gallium/targets/dri-nouveau/Makefile @@ -4,7 +4,7 @@ include $(TOP)/configs/current LIBNAME = nouveau_dri.so PIPE_DRIVERS = \ - $(TOP)/src/gallium/state_trackers/dri/libdridrm.a \ + $(TOP)/src/gallium/state_trackers/dri/drm/libdridrm.a \ $(TOP)/src/gallium/winsys/nouveau/drm/libnouveaudrm.a \ $(TOP)/src/gallium/drivers/nvfx/libnvfx.a \ $(TOP)/src/gallium/drivers/nv50/libnv50.a \ diff --git a/src/gallium/targets/dri-radeong/Makefile b/src/gallium/targets/dri-radeong/Makefile index ce25559e946..66dd392b68b 100644 --- a/src/gallium/targets/dri-radeong/Makefile +++ b/src/gallium/targets/dri-radeong/Makefile @@ -4,7 +4,7 @@ include $(TOP)/configs/current LIBNAME = radeong_dri.so PIPE_DRIVERS = \ - $(TOP)/src/gallium/state_trackers/dri/libdridrm.a \ + $(TOP)/src/gallium/state_trackers/dri/drm/libdridrm.a \ $(TOP)/src/gallium/winsys/radeon/drm/libradeonwinsys.a \ $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ $(TOP)/src/gallium/drivers/trace/libtrace.a \ diff --git a/src/gallium/targets/dri-swrast/Makefile b/src/gallium/targets/dri-swrast/Makefile index 57a9e02a4bb..3780da27550 100644 --- a/src/gallium/targets/dri-swrast/Makefile +++ b/src/gallium/targets/dri-swrast/Makefile @@ -6,7 +6,7 @@ LIBNAME = swrastg_dri.so DRIVER_DEFINES = -D__NOT_HAVE_DRM_H PIPE_DRIVERS = \ - $(TOP)/src/gallium/state_trackers/drisw/libdrisw.a \ + $(TOP)/src/gallium/state_trackers/dri/sw/libdrisw.a \ $(TOP)/src/gallium/winsys/sw/dri/libswdri.a \ $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a diff --git a/src/gallium/targets/dri-vmwgfx/Makefile b/src/gallium/targets/dri-vmwgfx/Makefile index 32edc46a3d9..4b002e828fa 100644 --- a/src/gallium/targets/dri-vmwgfx/Makefile +++ b/src/gallium/targets/dri-vmwgfx/Makefile @@ -4,7 +4,7 @@ include $(TOP)/configs/current LIBNAME = vmwgfx_dri.so PIPE_DRIVERS = \ - $(TOP)/src/gallium/state_trackers/dri/libdridrm.a \ + $(TOP)/src/gallium/state_trackers/dri/drm/libdridrm.a \ $(TOP)/src/gallium/winsys/svga/drm/libsvgadrm.a \ $(TOP)/src/gallium/drivers/trace/libtrace.a \ $(TOP)/src/gallium/drivers/svga/libsvga.a -- cgit v1.2.3 From 80672e84cf79ab12b7a4ff56567184d1c39baef3 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Thu, 25 Mar 2010 18:51:52 +0100 Subject: st/dri: Move common files to common directory 27 files changed, 15 insertions(+), 15 deletions(-) rename src/gallium/state_trackers/dri/{ => common}/dri1_helper.c (100%) rename src/gallium/state_trackers/dri/{ => common}/dri1_helper.h (100%) rename src/gallium/state_trackers/dri/{ => common}/dri_context.c (100%) rename src/gallium/state_trackers/dri/{ => common}/dri_context.h (100%) rename src/gallium/state_trackers/dri/{ => common}/dri_drawable.c (100%) rename src/gallium/state_trackers/dri/{ => common}/dri_drawable.h (100%) rename src/gallium/state_trackers/dri/{ => common}/dri_extensions.c (100%) rename src/gallium/state_trackers/dri/{ => common}/dri_screen.c (100%) rename src/gallium/state_trackers/dri/{ => common}/dri_screen.h (100%) rename src/gallium/state_trackers/dri/{ => common}/dri_st_api.c (100%) rename src/gallium/state_trackers/dri/{ => common}/dri_st_api.h (100%) rename src/gallium/state_trackers/dri/{ => common}/dri_wrapper.h (100%) --- .../state_trackers/dri/common/dri1_helper.c | 129 +++++++ .../state_trackers/dri/common/dri1_helper.h | 61 ++++ .../state_trackers/dri/common/dri_context.c | 174 ++++++++++ .../state_trackers/dri/common/dri_context.h | 97 ++++++ .../state_trackers/dri/common/dri_drawable.c | 94 ++++++ .../state_trackers/dri/common/dri_drawable.h | 89 +++++ .../state_trackers/dri/common/dri_extensions.c | 48 +++ src/gallium/state_trackers/dri/common/dri_screen.c | 373 +++++++++++++++++++++ src/gallium/state_trackers/dri/common/dri_screen.h | 114 +++++++ src/gallium/state_trackers/dri/common/dri_st_api.c | 263 +++++++++++++++ src/gallium/state_trackers/dri/common/dri_st_api.h | 55 +++ .../state_trackers/dri/common/dri_wrapper.h | 10 + src/gallium/state_trackers/dri/dri1_helper.c | 129 ------- src/gallium/state_trackers/dri/dri1_helper.h | 61 ---- src/gallium/state_trackers/dri/dri_context.c | 174 ---------- src/gallium/state_trackers/dri/dri_context.h | 97 ------ src/gallium/state_trackers/dri/dri_drawable.c | 94 ------ src/gallium/state_trackers/dri/dri_drawable.h | 89 ----- src/gallium/state_trackers/dri/dri_extensions.c | 48 --- src/gallium/state_trackers/dri/dri_screen.c | 373 --------------------- src/gallium/state_trackers/dri/dri_screen.h | 114 ------- src/gallium/state_trackers/dri/dri_st_api.c | 263 --------------- src/gallium/state_trackers/dri/dri_st_api.h | 55 --- src/gallium/state_trackers/dri/dri_wrapper.h | 10 - src/gallium/state_trackers/dri/drm/Makefile | 2 +- src/gallium/state_trackers/dri/drm/SConscript | 2 +- src/gallium/state_trackers/dri/drm/dri1_helper.c | 2 +- src/gallium/state_trackers/dri/drm/dri_context.c | 2 +- src/gallium/state_trackers/dri/drm/dri_drawable.c | 2 +- .../state_trackers/dri/drm/dri_extensions.c | 2 +- src/gallium/state_trackers/dri/drm/dri_screen.c | 2 +- src/gallium/state_trackers/dri/drm/dri_st_api.c | 2 +- src/gallium/state_trackers/dri/sw/Makefile | 2 +- src/gallium/state_trackers/dri/sw/dri1_helper.c | 2 +- src/gallium/state_trackers/dri/sw/dri_context.c | 2 +- src/gallium/state_trackers/dri/sw/dri_drawable.c | 2 +- src/gallium/state_trackers/dri/sw/dri_extensions.c | 2 +- src/gallium/state_trackers/dri/sw/dri_screen.c | 2 +- src/gallium/state_trackers/dri/sw/dri_st_api.c | 2 +- 39 files changed, 1522 insertions(+), 1522 deletions(-) create mode 100644 src/gallium/state_trackers/dri/common/dri1_helper.c create mode 100644 src/gallium/state_trackers/dri/common/dri1_helper.h create mode 100644 src/gallium/state_trackers/dri/common/dri_context.c create mode 100644 src/gallium/state_trackers/dri/common/dri_context.h create mode 100644 src/gallium/state_trackers/dri/common/dri_drawable.c create mode 100644 src/gallium/state_trackers/dri/common/dri_drawable.h create mode 100644 src/gallium/state_trackers/dri/common/dri_extensions.c create mode 100644 src/gallium/state_trackers/dri/common/dri_screen.c create mode 100644 src/gallium/state_trackers/dri/common/dri_screen.h create mode 100644 src/gallium/state_trackers/dri/common/dri_st_api.c create mode 100644 src/gallium/state_trackers/dri/common/dri_st_api.h create mode 100644 src/gallium/state_trackers/dri/common/dri_wrapper.h delete mode 100644 src/gallium/state_trackers/dri/dri1_helper.c delete mode 100644 src/gallium/state_trackers/dri/dri1_helper.h delete mode 100644 src/gallium/state_trackers/dri/dri_context.c delete mode 100644 src/gallium/state_trackers/dri/dri_context.h delete mode 100644 src/gallium/state_trackers/dri/dri_drawable.c delete mode 100644 src/gallium/state_trackers/dri/dri_drawable.h delete mode 100644 src/gallium/state_trackers/dri/dri_extensions.c delete mode 100644 src/gallium/state_trackers/dri/dri_screen.c delete mode 100644 src/gallium/state_trackers/dri/dri_screen.h delete mode 100644 src/gallium/state_trackers/dri/dri_st_api.c delete mode 100644 src/gallium/state_trackers/dri/dri_st_api.h delete mode 100644 src/gallium/state_trackers/dri/dri_wrapper.h (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/dri/common/dri1_helper.c b/src/gallium/state_trackers/dri/common/dri1_helper.c new file mode 100644 index 00000000000..7eeb868d422 --- /dev/null +++ b/src/gallium/state_trackers/dri/common/dri1_helper.c @@ -0,0 +1,129 @@ +/************************************************************************** + * + * Copyright 2009, VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ +/* + * Management of pipe objects (surface / pipe / fences) used by DRI1 and DRISW. + * + * Author: Keith Whitwell + * Author: Jakob Bornecrantz + */ + +#include "util/u_inlines.h" +#include "pipe/p_context.h" + +#include "dri_screen.h" +#include "dri_context.h" +#include "dri_drawable.h" +#include "dri1_helper.h" + +struct pipe_fence_handle * +dri1_swap_fences_pop_front(struct dri_drawable *draw) +{ + struct pipe_screen *screen = dri_screen(draw->sPriv)->pipe_screen; + struct pipe_fence_handle *fence = NULL; + + if (draw->cur_fences >= draw->desired_fences) { + screen->fence_reference(screen, &fence, draw->swap_fences[draw->tail]); + screen->fence_reference(screen, &draw->swap_fences[draw->tail++], NULL); + --draw->cur_fences; + draw->tail &= DRI_SWAP_FENCES_MASK; + } + return fence; +} + +void +dri1_swap_fences_push_back(struct dri_drawable *draw, + struct pipe_fence_handle *fence) +{ + struct pipe_screen *screen = dri_screen(draw->sPriv)->pipe_screen; + + if (!fence) + return; + + if (draw->cur_fences < DRI_SWAP_FENCES_MAX) { + draw->cur_fences++; + screen->fence_reference(screen, &draw->swap_fences[draw->head++], + fence); + draw->head &= DRI_SWAP_FENCES_MASK; + } +} + +void +dri1_swap_fences_clear(struct dri_drawable *drawable) +{ + struct pipe_screen *screen = dri_screen(drawable->sPriv)->pipe_screen; + struct pipe_fence_handle *fence; + + while (drawable->cur_fences) { + fence = dri1_swap_fences_pop_front(drawable); + screen->fence_reference(screen, &fence, NULL); + } +} + +struct pipe_surface * +dri1_get_pipe_surface(struct dri_drawable *drawable, struct pipe_texture *ptex) +{ + struct pipe_screen *pipe_screen = dri_screen(drawable->sPriv)->pipe_screen; + struct pipe_surface *psurf = drawable->dri1_surface; + + if (!psurf || psurf->texture != ptex) { + pipe_surface_reference(&drawable->dri1_surface, NULL); + + drawable->dri1_surface = pipe_screen->get_tex_surface(pipe_screen, + ptex, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_READ); + + psurf = drawable->dri1_surface; + } + + return psurf; +} + +void +dri1_destroy_pipe_surface(struct dri_drawable *drawable) +{ + pipe_surface_reference(&drawable->dri1_surface, NULL); +} + +struct pipe_context * +dri1_get_pipe_context(struct dri_screen *screen) +{ + struct pipe_context *pipe = screen->dri1_pipe; + + if (!pipe) { + screen->dri1_pipe = + screen->pipe_screen->context_create(screen->pipe_screen, NULL); + pipe = screen->dri1_pipe; + } + + return pipe; +} + +void +dri1_destroy_pipe_context(struct dri_screen *screen) +{ + if (screen->dri1_pipe) + screen->dri1_pipe->destroy(screen->dri1_pipe); +} diff --git a/src/gallium/state_trackers/dri/common/dri1_helper.h b/src/gallium/state_trackers/dri/common/dri1_helper.h new file mode 100644 index 00000000000..3254b7ff872 --- /dev/null +++ b/src/gallium/state_trackers/dri/common/dri1_helper.h @@ -0,0 +1,61 @@ +/************************************************************************** + * + * Copyright 2009, VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ +/* + * Author: Keith Whitwell + * Author: Jakob Bornecrantz + */ + +#ifndef DRI1_HELPER_H +#define DRI1_HELPER_H + +#include "dri_screen.h" +#include "dri_context.h" +#include "dri_drawable.h" + +struct pipe_fence_handle * +dri1_swap_fences_pop_front(struct dri_drawable *draw); + +void +dri1_swap_fences_push_back(struct dri_drawable *draw, + struct pipe_fence_handle *fence); + +void +dri1_swap_fences_clear(struct dri_drawable *drawable); + +struct pipe_surface * +dri1_get_pipe_surface(struct dri_drawable *drawable, struct pipe_texture *ptex); + +void +dri1_destroy_pipe_surface(struct dri_drawable *drawable); + +struct pipe_context * +dri1_get_pipe_context(struct dri_screen *screen); + +void +dri1_destroy_pipe_context(struct dri_screen *screen); + +#endif /* DRI1_HELPER_H */ diff --git a/src/gallium/state_trackers/dri/common/dri_context.c b/src/gallium/state_trackers/dri/common/dri_context.c new file mode 100644 index 00000000000..34d9a932ead --- /dev/null +++ b/src/gallium/state_trackers/dri/common/dri_context.c @@ -0,0 +1,174 @@ +/************************************************************************** + * + * Copyright 2009, VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ +/* + * Author: Keith Whitwell + * Author: Jakob Bornecrantz + */ + +#include "dri_screen.h" +#include "dri_drawable.h" +#include "dri_context.h" +#include "dri_st_api.h" + +#include "pipe/p_context.h" +#include "util/u_memory.h" + +GLboolean +dri_create_context(const __GLcontextModes * visual, + __DRIcontext * cPriv, void *sharedContextPrivate) +{ + struct st_api *stapi = dri_get_st_api(); + __DRIscreen *sPriv = cPriv->driScreenPriv; + struct dri_screen *screen = dri_screen(sPriv); + struct dri_context *ctx = NULL; + struct st_context_iface *st_share = NULL; + struct st_visual stvis; + + if (sharedContextPrivate) { + st_share = ((struct dri_context *)sharedContextPrivate)->st; + } + + ctx = CALLOC_STRUCT(dri_context); + if (ctx == NULL) + goto fail; + + cPriv->driverPrivate = ctx; + ctx->cPriv = cPriv; + ctx->sPriv = sPriv; + ctx->lock = screen->drmLock; + + driParseConfigFiles(&ctx->optionCache, + &screen->optionCache, sPriv->myNum, "dri"); + + dri_fill_st_visual(&stvis, screen, visual); + ctx->st = stapi->create_context(stapi, screen->smapi, &stvis, st_share); + if (ctx->st == NULL) + goto fail; + ctx->st->st_manager_private = (void *) ctx; + + dri_init_extensions(ctx); + + return GL_TRUE; + + fail: + if (ctx && ctx->st) + ctx->st->destroy(ctx->st); + + FREE(ctx); + return FALSE; +} + +void +dri_destroy_context(__DRIcontext * cPriv) +{ + struct dri_context *ctx = dri_context(cPriv); + + /* note: we are freeing values and nothing more because + * driParseConfigFiles allocated values only - the rest + * is owned by screen optionCache. + */ + FREE(ctx->optionCache.values); + + /* No particular reason to wait for command completion before + * destroying a context, but it is probably worthwhile flushing it + * to avoid having to add code elsewhere to cope with flushing a + * partially destroyed context. + */ + ctx->st->flush(ctx->st, 0, NULL); + ctx->st->destroy(ctx->st); + + FREE(ctx); +} + +GLboolean +dri_unbind_context(__DRIcontext * cPriv) +{ + struct st_api *stapi = dri_get_st_api(); + + if (cPriv) { + struct dri_context *ctx = dri_context(cPriv); + + if (--ctx->bind_count == 0) { + if (ctx->st == stapi->get_current(stapi)) { + ctx->st->flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); + stapi->make_current(stapi, NULL, NULL, NULL); + } + } + } + + return GL_TRUE; +} + +GLboolean +dri_make_current(__DRIcontext * cPriv, + __DRIdrawable * driDrawPriv, + __DRIdrawable * driReadPriv) +{ + struct st_api *stapi = dri_get_st_api(); + + if (cPriv) { + struct dri_context *ctx = dri_context(cPriv); + struct dri_drawable *draw = dri_drawable(driDrawPriv); + struct dri_drawable *read = dri_drawable(driReadPriv); + struct st_context_iface *old_st; + + old_st = stapi->get_current(stapi); + if (old_st && old_st != ctx->st) + ctx->st->flush(old_st, PIPE_FLUSH_RENDER_CACHE, NULL); + + ++ctx->bind_count; + + if (ctx->dPriv != driDrawPriv) { + ctx->dPriv = driDrawPriv; + draw->texture_stamp = driDrawPriv->lastStamp - 1; + } + if (ctx->rPriv != driReadPriv) { + ctx->rPriv = driReadPriv; + read->texture_stamp = driReadPriv->lastStamp - 1; + } + + stapi->make_current(stapi, ctx->st, draw->stfb, read->stfb); + } + else { + stapi->make_current(stapi, NULL, NULL, NULL); + } + + return GL_TRUE; +} + +struct dri_context * +dri_get_current(void) +{ + struct st_api *stapi = dri_get_st_api(); + struct st_context_iface *st; + + st = stapi->get_current(stapi); + + return (struct dri_context *) (st) ? st->st_manager_private : NULL; +} + +/* vim: set sw=3 ts=8 sts=3 expandtab: */ diff --git a/src/gallium/state_trackers/dri/common/dri_context.h b/src/gallium/state_trackers/dri/common/dri_context.h new file mode 100644 index 00000000000..24d3d0368a4 --- /dev/null +++ b/src/gallium/state_trackers/dri/common/dri_context.h @@ -0,0 +1,97 @@ +/************************************************************************** + * + * Copyright (C) 2009 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ +/* + * Author: Keith Whitwell + * Author: Jakob Bornecrantz + */ + +#ifndef DRI_CONTEXT_H +#define DRI_CONTEXT_H + +#include "pipe/p_compiler.h" +#include "dri_wrapper.h" + +struct pipe_context; +struct pipe_fence; +struct st_context; +struct dri_drawable; + +struct dri_context +{ + /* dri */ + __DRIscreen *sPriv; + __DRIcontext *cPriv; + __DRIdrawable *dPriv; + __DRIdrawable *rPriv; + + driOptionCache optionCache; + + drmLock *lock; + boolean isLocked; + boolean stLostLock; + boolean wsLostLock; + + unsigned int bind_count; + + /* gallium */ + struct st_context_iface *st; +}; + +static INLINE struct dri_context * +dri_context(__DRIcontext * driContextPriv) +{ + return (struct dri_context *)driContextPriv->driverPrivate; +} + +/*********************************************************************** + * dri_context.c + */ +void dri_destroy_context(__DRIcontext * driContextPriv); + +boolean dri_unbind_context(__DRIcontext * driContextPriv); + +boolean +dri_make_current(__DRIcontext * driContextPriv, + __DRIdrawable * driDrawPriv, + __DRIdrawable * driReadPriv); + +struct dri_context * +dri_get_current(void); + +boolean +dri_create_context(const __GLcontextModes * visual, + __DRIcontext * driContextPriv, + void *sharedContextPrivate); + +/*********************************************************************** + * dri_extensions.c + */ +void dri_init_extensions(struct dri_context *ctx); + +#endif + +/* vim: set sw=3 ts=8 sts=3 expandtab: */ diff --git a/src/gallium/state_trackers/dri/common/dri_drawable.c b/src/gallium/state_trackers/dri/common/dri_drawable.c new file mode 100644 index 00000000000..75b4cc56289 --- /dev/null +++ b/src/gallium/state_trackers/dri/common/dri_drawable.c @@ -0,0 +1,94 @@ +/************************************************************************** + * + * Copyright 2009, VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ +/* + * Author: Keith Whitwell + * Author: Jakob Bornecrantz + */ + +#include "dri_screen.h" +#include "dri_context.h" +#include "dri_drawable.h" +#include "dri_st_api.h" +#include "dri1_helper.h" + +#include "pipe/p_screen.h" +#include "util/u_format.h" +#include "util/u_memory.h" +#include "util/u_inlines.h" + +/** + * This is called when we need to set up GL rendering to a new X window. + */ +boolean +dri_create_buffer(__DRIscreen * sPriv, + __DRIdrawable * dPriv, + const __GLcontextModes * visual, boolean isPixmap) +{ + struct dri_screen *screen = sPriv->private; + struct dri_drawable *drawable = NULL; + + if (isPixmap) + goto fail; /* not implemented */ + + drawable = CALLOC_STRUCT(dri_drawable); + if (drawable == NULL) + goto fail; + + dri_fill_st_visual(&drawable->stvis, screen, visual); + drawable->stfb = dri_create_st_framebuffer(drawable); + if (drawable->stfb == NULL) + goto fail; + + drawable->sPriv = sPriv; + drawable->dPriv = dPriv; + dPriv->driverPrivate = (void *)drawable; + + drawable->desired_fences = 2; + + return GL_TRUE; +fail: + FREE(drawable); + return GL_FALSE; +} + +void +dri_destroy_buffer(__DRIdrawable * dPriv) +{ + struct dri_drawable *drawable = dri_drawable(dPriv); + + dri1_swap_fences_clear(drawable); + + dri1_destroy_pipe_surface(drawable); + + dri_destroy_st_framebuffer(drawable->stfb); + + drawable->desired_fences = 0; + + FREE(drawable); +} + +/* vim: set sw=3 ts=8 sts=3 expandtab: */ diff --git a/src/gallium/state_trackers/dri/common/dri_drawable.h b/src/gallium/state_trackers/dri/common/dri_drawable.h new file mode 100644 index 00000000000..98abeb9ec05 --- /dev/null +++ b/src/gallium/state_trackers/dri/common/dri_drawable.h @@ -0,0 +1,89 @@ +/************************************************************************** + * + * Copyright 2009, VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef DRI_DRAWABLE_H +#define DRI_DRAWABLE_H + +#include "pipe/p_compiler.h" +#include "pipe/p_format.h" +#include "state_tracker/st_api.h" + +struct pipe_surface; +struct pipe_fence_handle; +struct st_framebuffer; +struct dri_context; + +#define DRI_SWAP_FENCES_MAX 8 +#define DRI_SWAP_FENCES_MASK 7 + +struct dri_drawable +{ + /* dri */ + __DRIdrawable *dPriv; + __DRIscreen *sPriv; + + /* gallium */ + struct st_framebuffer_iface *stfb; + struct st_visual stvis; + + __DRIbuffer old[8]; + unsigned old_num; + unsigned old_w; + unsigned old_h; + + struct pipe_texture *textures[ST_ATTACHMENT_COUNT]; + unsigned int texture_mask, texture_stamp; + + struct pipe_fence_handle *swap_fences[DRI_SWAP_FENCES_MAX]; + unsigned int head; + unsigned int tail; + unsigned int desired_fences; + unsigned int cur_fences; + + /* used only by DRI1 */ + struct pipe_surface *dri1_surface; +}; + +static INLINE struct dri_drawable * +dri_drawable(__DRIdrawable * driDrawPriv) +{ + return (struct dri_drawable *)driDrawPriv->driverPrivate; +} + +/*********************************************************************** + * dri_drawable.c + */ +boolean +dri_create_buffer(__DRIscreen * sPriv, + __DRIdrawable * dPriv, + const __GLcontextModes * visual, boolean isPixmap); + +void dri_destroy_buffer(__DRIdrawable * dPriv); + +#endif + +/* vim: set sw=3 ts=8 sts=3 expandtab: */ diff --git a/src/gallium/state_trackers/dri/common/dri_extensions.c b/src/gallium/state_trackers/dri/common/dri_extensions.c new file mode 100644 index 00000000000..df458e1eb0f --- /dev/null +++ b/src/gallium/state_trackers/dri/common/dri_extensions.c @@ -0,0 +1,48 @@ +/************************************************************************** + * + * Copyright 2009, VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ +/* + * Author: Keith Whitwell + * Author: Jakob Bornecrantz + */ + +#include "dri_screen.h" +#include "dri_context.h" +#include "state_tracker/st_context.h" + +#include "utils.h" + +void +dri_init_extensions(struct dri_context *ctx) +{ + struct st_context *st = (struct st_context *) ctx->st; + + /* New extensions should be added in mesa/state_tracker/st_extensions.c + * and not in this file. */ + driInitExtensions(st->ctx, NULL, GL_FALSE); +} + +/* vim: set sw=3 ts=8 sts=3 expandtab: */ diff --git a/src/gallium/state_trackers/dri/common/dri_screen.c b/src/gallium/state_trackers/dri/common/dri_screen.c new file mode 100644 index 00000000000..598a07bb646 --- /dev/null +++ b/src/gallium/state_trackers/dri/common/dri_screen.c @@ -0,0 +1,373 @@ +/************************************************************************** + * + * Copyright 2009, VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ +/* + * Author: Keith Whitwell + * Author: Jakob Bornecrantz + */ + +#include "utils.h" +#ifndef __NOT_HAVE_DRM_H +#include "vblank.h" +#endif +#include "xmlpool.h" + +#include "dri_screen.h" +#include "dri_context.h" +#include "dri_drawable.h" +#include "dri_st_api.h" +#include "dri1_helper.h" +#ifndef __NOT_HAVE_DRM_H +#include "dri1.h" +#include "dri2.h" +#else +#include "drisw.h" +#endif + +#include "util/u_inlines.h" +#include "pipe/p_screen.h" +#include "pipe/p_format.h" +#include "state_tracker/drm_api.h" + +#include "util/u_debug.h" + +PUBLIC const char __driConfigOptions[] = + DRI_CONF_BEGIN DRI_CONF_SECTION_PERFORMANCE + DRI_CONF_FTHROTTLE_MODE(DRI_CONF_FTHROTTLE_IRQS) + DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_DEF_INTERVAL_0) + DRI_CONF_SECTION_END DRI_CONF_SECTION_QUALITY +/* DRI_CONF_FORCE_S3TC_ENABLE(false) */ + DRI_CONF_ALLOW_LARGE_TEXTURES(1) + DRI_CONF_SECTION_END DRI_CONF_END; + +const uint __driNConfigOptions = 3; + +const __DRIconfig ** +dri_fill_in_modes(struct dri_screen *screen, + unsigned pixel_bits) +{ + __DRIconfig **configs = NULL; + __DRIconfig **configs_r5g6b5 = NULL; + __DRIconfig **configs_a8r8g8b8 = NULL; + __DRIconfig **configs_x8r8g8b8 = NULL; + unsigned num_modes; + uint8_t depth_bits_array[5]; + uint8_t stencil_bits_array[5]; + uint8_t msaa_samples_array[2]; + unsigned depth_buffer_factor; + unsigned back_buffer_factor; + unsigned msaa_samples_factor; + struct pipe_screen *p_screen = screen->pipe_screen; + boolean pf_r5g6b5, pf_a8r8g8b8, pf_x8r8g8b8; + boolean pf_z16, pf_x8z24, pf_z24x8, pf_s8z24, pf_z24s8, pf_z32; + + static const GLenum back_buffer_modes[] = { + GLX_NONE, GLX_SWAP_UNDEFINED_OML, GLX_SWAP_COPY_OML + }; + + depth_bits_array[0] = 0; + stencil_bits_array[0] = 0; + depth_buffer_factor = 1; + + pf_x8z24 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_Z24X8_UNORM, + PIPE_TEXTURE_2D, + PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0); + pf_z24x8 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_X8Z24_UNORM, + PIPE_TEXTURE_2D, + PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0); + pf_s8z24 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_Z24S8_UNORM, + PIPE_TEXTURE_2D, + PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0); + pf_z24s8 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_S8Z24_UNORM, + PIPE_TEXTURE_2D, + PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0); + pf_a8r8g8b8 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_B8G8R8A8_UNORM, + PIPE_TEXTURE_2D, + PIPE_TEXTURE_USAGE_RENDER_TARGET, 0); + pf_x8r8g8b8 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_B8G8R8X8_UNORM, + PIPE_TEXTURE_2D, + PIPE_TEXTURE_USAGE_RENDER_TARGET, 0); + pf_r5g6b5 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_B5G6R5_UNORM, + PIPE_TEXTURE_2D, + PIPE_TEXTURE_USAGE_RENDER_TARGET, 0); + + /* We can only get a 16 or 32 bit depth buffer with getBuffersWithFormat */ + if (dri_with_format(screen->sPriv)) { + pf_z16 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_Z16_UNORM, + PIPE_TEXTURE_2D, + PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0); + pf_z32 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_Z32_UNORM, + PIPE_TEXTURE_2D, + PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0); + } else { + pf_z16 = FALSE; + pf_z32 = FALSE; + } + + if (pf_z16) { + depth_bits_array[depth_buffer_factor] = 16; + stencil_bits_array[depth_buffer_factor++] = 0; + } + if (pf_x8z24 || pf_z24x8) { + depth_bits_array[depth_buffer_factor] = 24; + stencil_bits_array[depth_buffer_factor++] = 0; + screen->d_depth_bits_last = pf_x8z24; + } + if (pf_s8z24 || pf_z24s8) { + depth_bits_array[depth_buffer_factor] = 24; + stencil_bits_array[depth_buffer_factor++] = 8; + screen->sd_depth_bits_last = pf_s8z24; + } + if (pf_z32) { + depth_bits_array[depth_buffer_factor] = 32; + stencil_bits_array[depth_buffer_factor++] = 0; + } + + msaa_samples_array[0] = 0; + msaa_samples_array[1] = 4; + back_buffer_factor = 3; + msaa_samples_factor = 2; + + num_modes = + depth_buffer_factor * back_buffer_factor * msaa_samples_factor * 4; + + if (pf_r5g6b5) + configs_r5g6b5 = driCreateConfigs(GL_RGB, GL_UNSIGNED_SHORT_5_6_5, + depth_bits_array, stencil_bits_array, + depth_buffer_factor, back_buffer_modes, + back_buffer_factor, + msaa_samples_array, msaa_samples_factor, + GL_TRUE); + + if (pf_a8r8g8b8) + configs_a8r8g8b8 = driCreateConfigs(GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, + depth_bits_array, + stencil_bits_array, + depth_buffer_factor, + back_buffer_modes, + back_buffer_factor, + msaa_samples_array, + msaa_samples_factor, + GL_TRUE); + + if (pf_x8r8g8b8) + configs_x8r8g8b8 = driCreateConfigs(GL_BGR, GL_UNSIGNED_INT_8_8_8_8_REV, + depth_bits_array, + stencil_bits_array, + depth_buffer_factor, + back_buffer_modes, + back_buffer_factor, + msaa_samples_array, + msaa_samples_factor, + GL_TRUE); + + if (pixel_bits == 16) { + configs = configs_r5g6b5; + if (configs_a8r8g8b8) + configs = configs ? driConcatConfigs(configs, configs_a8r8g8b8) : configs_a8r8g8b8; + if (configs_x8r8g8b8) + configs = configs ? driConcatConfigs(configs, configs_x8r8g8b8) : configs_x8r8g8b8; + } else { + configs = configs_a8r8g8b8; + if (configs_x8r8g8b8) + configs = configs ? driConcatConfigs(configs, configs_x8r8g8b8) : configs_x8r8g8b8; + if (configs_r5g6b5) + configs = configs ? driConcatConfigs(configs, configs_r5g6b5) : configs_r5g6b5; + } + + if (configs == NULL) { + debug_printf("%s: driCreateConfigs failed\n", __FUNCTION__); + return NULL; + } + + return (const __DRIconfig **)configs; +} + +/** + * Roughly the converse of dri_fill_in_modes. + */ +void +dri_fill_st_visual(struct st_visual *stvis, struct dri_screen *screen, + const __GLcontextModes *mode) +{ + memset(stvis, 0, sizeof(*stvis)); + + stvis->samples = mode->samples; + stvis->render_buffer = ST_ATTACHMENT_INVALID; + + if (mode->redBits == 8) { + if (mode->alphaBits == 8) + stvis->color_format = PIPE_FORMAT_B8G8R8A8_UNORM; + else + stvis->color_format = PIPE_FORMAT_B8G8R8X8_UNORM; + } else { + stvis->color_format = PIPE_FORMAT_B5G6R5_UNORM; + } + + switch (mode->depthBits) { + default: + case 0: + stvis->depth_stencil_format = PIPE_FORMAT_NONE; + break; + case 16: + stvis->depth_stencil_format = PIPE_FORMAT_Z16_UNORM; + break; + case 24: + if (mode->stencilBits == 0) { + stvis->depth_stencil_format = (screen->d_depth_bits_last) ? + PIPE_FORMAT_Z24X8_UNORM: + PIPE_FORMAT_X8Z24_UNORM; + } else { + stvis->depth_stencil_format = (screen->sd_depth_bits_last) ? + PIPE_FORMAT_Z24S8_UNORM: + PIPE_FORMAT_S8Z24_UNORM; + } + break; + case 32: + stvis->depth_stencil_format = PIPE_FORMAT_Z32_UNORM; + break; + } + + stvis->accum_format = (mode->haveAccumBuffer) ? + PIPE_FORMAT_R16G16B16A16_SNORM : PIPE_FORMAT_NONE; + + stvis->buffer_mask |= ST_ATTACHMENT_FRONT_LEFT_MASK; + if (mode->doubleBufferMode) + stvis->buffer_mask |= ST_ATTACHMENT_BACK_LEFT_MASK; + if (mode->stereoMode) { + stvis->buffer_mask |= ST_ATTACHMENT_FRONT_RIGHT_MASK; + if (mode->doubleBufferMode) + stvis->buffer_mask |= ST_ATTACHMENT_BACK_RIGHT_MASK; + } + + if (mode->haveDepthBuffer || mode->haveStencilBuffer) + stvis->buffer_mask |= ST_ATTACHMENT_DEPTH_STENCIL_MASK; + /* let the state tracker allocate the accum buffer */ +} + +#ifndef __NOT_HAVE_DRM_H + +/** + * Get information about previous buffer swaps. + */ +static int +dri_get_swap_info(__DRIdrawable * dPriv, __DRIswapInfo * sInfo) +{ + if (dPriv == NULL || dPriv->driverPrivate == NULL || sInfo == NULL) + return -1; + else + return 0; +} + +#endif + +static void +dri_destroy_option_cache(struct dri_screen * screen) +{ + int i; + + for (i = 0; i < (1 << screen->optionCache.tableSize); ++i) { + FREE(screen->optionCache.info[i].name); + FREE(screen->optionCache.info[i].ranges); + } + + FREE(screen->optionCache.info); + FREE(screen->optionCache.values); +} + +void +dri_destroy_screen(__DRIscreen * sPriv) +{ + struct dri_screen *screen = dri_screen(sPriv); + + dri1_destroy_pipe_context(screen); + + if (screen->smapi) + dri_destroy_st_manager(screen->smapi); + + if (screen->pipe_screen) + screen->pipe_screen->destroy(screen->pipe_screen); + + dri_destroy_option_cache(screen); + + FREE(screen); + sPriv->private = NULL; + sPriv->extensions = NULL; +} + +#ifndef __NOT_HAVE_DRM_H + +const struct __DriverAPIRec driDriverAPI = { + .DestroyScreen = dri_destroy_screen, + .CreateContext = dri_create_context, + .DestroyContext = dri_destroy_context, + .CreateBuffer = dri_create_buffer, + .DestroyBuffer = dri_destroy_buffer, + .MakeCurrent = dri_make_current, + .UnbindContext = dri_unbind_context, + .GetSwapInfo = dri_get_swap_info, + .GetDrawableMSC = driDrawableGetMSC32, + .WaitForMSC = driWaitForMSC32, + .InitScreen2 = dri2_init_screen, + + .InitScreen = dri1_init_screen, + .SwapBuffers = dri1_swap_buffers, + .CopySubBuffer = dri1_copy_sub_buffer, +}; + +/* This is the table of extensions that the loader will dlsym() for. */ +PUBLIC const __DRIextension *__driDriverExtensions[] = { + &driCoreExtension.base, + &driLegacyExtension.base, + &driDRI2Extension.base, + NULL +}; + +#else + +const struct __DriverAPIRec driDriverAPI = { + .DestroyScreen = dri_destroy_screen, + .CreateContext = dri_create_context, + .DestroyContext = dri_destroy_context, + .CreateBuffer = dri_create_buffer, + .DestroyBuffer = dri_destroy_buffer, + .MakeCurrent = dri_make_current, + .UnbindContext = dri_unbind_context, + + .InitScreen = drisw_init_screen, + .SwapBuffers = drisw_swap_buffers, +}; + +/* This is the table of extensions that the loader will dlsym() for. */ +PUBLIC const __DRIextension *__driDriverExtensions[] = { + &driCoreExtension.base, + &driSWRastExtension.base, + NULL +}; + +#endif + +/* vim: set sw=3 ts=8 sts=3 expandtab: */ diff --git a/src/gallium/state_trackers/dri/common/dri_screen.h b/src/gallium/state_trackers/dri/common/dri_screen.h new file mode 100644 index 00000000000..4f59db37cfa --- /dev/null +++ b/src/gallium/state_trackers/dri/common/dri_screen.h @@ -0,0 +1,114 @@ +/************************************************************************** + * + * Copyright 2009, VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ +/* + * Author: Keith Whitwell + * Author: Jakob Bornecrantz + */ + +#ifndef DRI_SCREEN_H +#define DRI_SCREEN_H + +#include "dri_wrapper.h" +#include "xmlconfig.h" + +#include "pipe/p_compiler.h" +#include "pipe/p_context.h" +#include "pipe/p_state.h" +#include "state_tracker/st_api.h" + +struct dri_screen +{ + /* dri */ + __DRIscreen *sPriv; + + /** + * Configuration cache with default values for all contexts + */ + driOptionCache optionCache; + + /* drm */ + int fd; + drmLock *drmLock; + + /* gallium */ + struct drm_api *api; + struct pipe_winsys *pipe_winsys; + struct pipe_screen *pipe_screen; + boolean d_depth_bits_last; + boolean sd_depth_bits_last; + boolean auto_fake_front; + + struct st_manager *smapi; + + /* used only by DRI1 */ + struct pipe_context *dri1_pipe; +}; + +/** cast wrapper */ +static INLINE struct dri_screen * +dri_screen(__DRIscreen * sPriv) +{ + return (struct dri_screen *)sPriv->private; +} + +#ifndef __NOT_HAVE_DRM_H + +static INLINE boolean +dri_with_format(__DRIscreen * sPriv) +{ + const __DRIdri2LoaderExtension *loader = sPriv->dri2.loader; + + return loader + && (loader->base.version >= 3) + && (loader->getBuffersWithFormat != NULL); +} + +#else + +static INLINE boolean +dri_with_format(__DRIscreen * sPriv) +{ + return TRUE; +} + +#endif + +extern const uint __driNConfigOptions; + +const __DRIconfig ** +dri_fill_in_modes(struct dri_screen *screen, unsigned pixel_bits); + +void +dri_fill_st_visual(struct st_visual *stvis, struct dri_screen *screen, + const __GLcontextModes *mode); + +void +dri_destroy_screen(__DRIscreen * sPriv); + +#endif + +/* vim: set sw=3 ts=8 sts=3 expandtab: */ diff --git a/src/gallium/state_trackers/dri/common/dri_st_api.c b/src/gallium/state_trackers/dri/common/dri_st_api.c new file mode 100644 index 00000000000..40b24b18e9f --- /dev/null +++ b/src/gallium/state_trackers/dri/common/dri_st_api.c @@ -0,0 +1,263 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu + */ + +#include "util/u_memory.h" +#include "util/u_inlines.h" +#include "util/u_format.h" +#include "util/u_debug.h" +#include "state_tracker/st_manager.h" /* for st_manager_create_api */ + +#include "dri_screen.h" +#include "dri_context.h" +#include "dri_drawable.h" +#include "dri_st_api.h" +#include "dri1_helper.h" +#ifndef __NOT_HAVE_DRM_H +#include "dri1.h" +#include "dri2.h" +#else +#include "drisw.h" +#endif + +static boolean +dri_st_framebuffer_validate(struct st_framebuffer_iface *stfbi, + const enum st_attachment_type *statts, + unsigned count, + struct pipe_texture **out) +{ + struct dri_drawable *drawable = + (struct dri_drawable *) stfbi->st_manager_private; + unsigned statt_mask, new_mask; + boolean new_stamp; + int i; + + statt_mask = 0x0; + for (i = 0; i < count; i++) + statt_mask |= (1 << statts[i]); + + /* record newly allocated textures */ + new_mask = (statt_mask & ~drawable->texture_mask); + + /* + * dPriv->pStamp is the server stamp. It should be accessed with a lock, at + * least for DRI1. dPriv->lastStamp is the client stamp. It has the value + * of the server stamp when last checked. + */ + new_stamp = (drawable->texture_stamp != drawable->dPriv->lastStamp); + + if (new_stamp || new_mask) { + +#ifndef __NOT_HAVE_DRM_H + if (__dri1_api_hooks) { + dri1_allocate_textures(drawable, statt_mask); + } + else { + dri2_allocate_textures(drawable, statts, count); + } +#else + if (new_stamp) + drisw_update_drawable_info(drawable->dPriv); + + drisw_allocate_textures(drawable, statt_mask); +#endif + + /* add existing textures */ + for (i = 0; i < ST_ATTACHMENT_COUNT; i++) { + if (drawable->textures[i]) + statt_mask |= (1 << i); + } + + drawable->texture_stamp = drawable->dPriv->lastStamp; + drawable->texture_mask = statt_mask; + } + + if (!out) + return TRUE; + + for (i = 0; i < count; i++) { + out[i] = NULL; + pipe_texture_reference(&out[i], drawable->textures[statts[i]]); + } + + return TRUE; +} + +static boolean +dri_st_framebuffer_flush_front(struct st_framebuffer_iface *stfbi, + enum st_attachment_type statt) +{ + struct dri_drawable *drawable = + (struct dri_drawable *) stfbi->st_manager_private; + +#ifndef __NOT_HAVE_DRM_H + if (__dri1_api_hooks) { + dri1_flush_frontbuffer(drawable, statt); + } + else { + dri2_flush_frontbuffer(drawable, statt); + } +#else + drisw_flush_frontbuffer(drawable, statt); +#endif + + return TRUE; +} + +/** + * Create a framebuffer from the given drawable. + */ +struct st_framebuffer_iface * +dri_create_st_framebuffer(struct dri_drawable *drawable) +{ + struct st_framebuffer_iface *stfbi; + + stfbi = CALLOC_STRUCT(st_framebuffer_iface); + if (stfbi) { + stfbi->visual = &drawable->stvis; + stfbi->flush_front = dri_st_framebuffer_flush_front; + stfbi->validate = dri_st_framebuffer_validate; + stfbi->st_manager_private = (void *) drawable; + } + + return stfbi; +} + +/** + * Destroy a framebuffer. + */ +void +dri_destroy_st_framebuffer(struct st_framebuffer_iface *stfbi) +{ + struct dri_drawable *drawable = + (struct dri_drawable *) stfbi->st_manager_private; + int i; + + for (i = 0; i < ST_ATTACHMENT_COUNT; i++) + pipe_texture_reference(&drawable->textures[i], NULL); + + FREE(stfbi); +} + +/** + * Validate the texture at an attachment. Allocate the texture if it does not + * exist. + */ +void +dri_st_framebuffer_validate_att(struct st_framebuffer_iface *stfbi, + enum st_attachment_type statt) +{ + struct dri_drawable *drawable = + (struct dri_drawable *) stfbi->st_manager_private; + enum st_attachment_type statts[ST_ATTACHMENT_COUNT]; + unsigned i, count = 0; + + /* check if buffer already exists */ + if (drawable->texture_mask & (1 << statt)) + return; + + /* make sure DRI2 does not destroy existing buffers */ + for (i = 0; i < ST_ATTACHMENT_COUNT; i++) { + if (drawable->texture_mask & (1 << i)) { + statts[count++] = i; + } + } + statts[count++] = statt; + + drawable->texture_stamp = drawable->dPriv->lastStamp - 1; + + stfbi->validate(stfbi, statts, count, NULL); +} + +/** + * Reference counted st_api. + */ +static struct { + int32_t refcnt; + struct st_api *stapi; +} dri_st_api; + +/** + * Add a reference to the st_api of the state tracker. + */ +static void +_dri_get_st_api(void) +{ + p_atomic_inc(&dri_st_api.refcnt); + if (p_atomic_read(&dri_st_api.refcnt) == 1) + dri_st_api.stapi = st_manager_create_api(); +} + +/** + * Remove a reference to the st_api of the state tracker. + */ +static void +_dri_put_st_api(void) +{ + struct st_api *stapi = dri_st_api.stapi; + + if (p_atomic_dec_zero(&dri_st_api.refcnt)) { + stapi->destroy(dri_st_api.stapi); + dri_st_api.stapi = NULL; + } +} + +/** + * Create a state tracker manager from the given screen. + */ +struct st_manager * +dri_create_st_manager(struct dri_screen *screen) +{ + struct st_manager *smapi; + + smapi = CALLOC_STRUCT(st_manager); + if (smapi) { + smapi->screen = screen->pipe_screen; + _dri_get_st_api(); + } + + return smapi; +} + +/** + * Destroy a state tracker manager. + */ +void +dri_destroy_st_manager(struct st_manager *smapi) +{ + _dri_put_st_api(); + FREE(smapi); +} + +/** + * Return the st_api of OpenGL state tracker. + */ +struct st_api * +dri_get_st_api(void) +{ + assert(dri_st_api.stapi); + return dri_st_api.stapi; +} diff --git a/src/gallium/state_trackers/dri/common/dri_st_api.h b/src/gallium/state_trackers/dri/common/dri_st_api.h new file mode 100644 index 00000000000..99a217bfa79 --- /dev/null +++ b/src/gallium/state_trackers/dri/common/dri_st_api.h @@ -0,0 +1,55 @@ +/* + * Mesa 3-D graphics library + * Version: 7.9 + * + * Copyright (C) 2010 LunarG Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * Authors: + * Chia-I Wu + */ + +#ifndef _DRI_ST_API_H_ +#define _DRI_ST_API_H_ + +#include "state_tracker/st_api.h" + +struct dri_screen; +struct dri_drawable; + +struct st_api * +dri_get_st_api(void); + +struct st_manager * +dri_create_st_manager(struct dri_screen *screen); + +void +dri_destroy_st_manager(struct st_manager *smapi); + +struct st_framebuffer_iface * +dri_create_st_framebuffer(struct dri_drawable *drawable); + +void +dri_destroy_st_framebuffer(struct st_framebuffer_iface *stfbi); + +void +dri_st_framebuffer_validate_att(struct st_framebuffer_iface *stfbi, + enum st_attachment_type statt); + +#endif /* _DRI_ST_API_H_ */ diff --git a/src/gallium/state_trackers/dri/common/dri_wrapper.h b/src/gallium/state_trackers/dri/common/dri_wrapper.h new file mode 100644 index 00000000000..141ba02706a --- /dev/null +++ b/src/gallium/state_trackers/dri/common/dri_wrapper.h @@ -0,0 +1,10 @@ +#ifndef DRI_WRAPPER_H +#define DRI_WRAPPER_H + +#ifndef __NOT_HAVE_DRM_H +#include "dri_util.h" +#else +#include "drisw_util.h" +#endif + +#endif diff --git a/src/gallium/state_trackers/dri/dri1_helper.c b/src/gallium/state_trackers/dri/dri1_helper.c deleted file mode 100644 index 7eeb868d422..00000000000 --- a/src/gallium/state_trackers/dri/dri1_helper.c +++ /dev/null @@ -1,129 +0,0 @@ -/************************************************************************** - * - * Copyright 2009, VMware, Inc. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ -/* - * Management of pipe objects (surface / pipe / fences) used by DRI1 and DRISW. - * - * Author: Keith Whitwell - * Author: Jakob Bornecrantz - */ - -#include "util/u_inlines.h" -#include "pipe/p_context.h" - -#include "dri_screen.h" -#include "dri_context.h" -#include "dri_drawable.h" -#include "dri1_helper.h" - -struct pipe_fence_handle * -dri1_swap_fences_pop_front(struct dri_drawable *draw) -{ - struct pipe_screen *screen = dri_screen(draw->sPriv)->pipe_screen; - struct pipe_fence_handle *fence = NULL; - - if (draw->cur_fences >= draw->desired_fences) { - screen->fence_reference(screen, &fence, draw->swap_fences[draw->tail]); - screen->fence_reference(screen, &draw->swap_fences[draw->tail++], NULL); - --draw->cur_fences; - draw->tail &= DRI_SWAP_FENCES_MASK; - } - return fence; -} - -void -dri1_swap_fences_push_back(struct dri_drawable *draw, - struct pipe_fence_handle *fence) -{ - struct pipe_screen *screen = dri_screen(draw->sPriv)->pipe_screen; - - if (!fence) - return; - - if (draw->cur_fences < DRI_SWAP_FENCES_MAX) { - draw->cur_fences++; - screen->fence_reference(screen, &draw->swap_fences[draw->head++], - fence); - draw->head &= DRI_SWAP_FENCES_MASK; - } -} - -void -dri1_swap_fences_clear(struct dri_drawable *drawable) -{ - struct pipe_screen *screen = dri_screen(drawable->sPriv)->pipe_screen; - struct pipe_fence_handle *fence; - - while (drawable->cur_fences) { - fence = dri1_swap_fences_pop_front(drawable); - screen->fence_reference(screen, &fence, NULL); - } -} - -struct pipe_surface * -dri1_get_pipe_surface(struct dri_drawable *drawable, struct pipe_texture *ptex) -{ - struct pipe_screen *pipe_screen = dri_screen(drawable->sPriv)->pipe_screen; - struct pipe_surface *psurf = drawable->dri1_surface; - - if (!psurf || psurf->texture != ptex) { - pipe_surface_reference(&drawable->dri1_surface, NULL); - - drawable->dri1_surface = pipe_screen->get_tex_surface(pipe_screen, - ptex, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_READ); - - psurf = drawable->dri1_surface; - } - - return psurf; -} - -void -dri1_destroy_pipe_surface(struct dri_drawable *drawable) -{ - pipe_surface_reference(&drawable->dri1_surface, NULL); -} - -struct pipe_context * -dri1_get_pipe_context(struct dri_screen *screen) -{ - struct pipe_context *pipe = screen->dri1_pipe; - - if (!pipe) { - screen->dri1_pipe = - screen->pipe_screen->context_create(screen->pipe_screen, NULL); - pipe = screen->dri1_pipe; - } - - return pipe; -} - -void -dri1_destroy_pipe_context(struct dri_screen *screen) -{ - if (screen->dri1_pipe) - screen->dri1_pipe->destroy(screen->dri1_pipe); -} diff --git a/src/gallium/state_trackers/dri/dri1_helper.h b/src/gallium/state_trackers/dri/dri1_helper.h deleted file mode 100644 index 3254b7ff872..00000000000 --- a/src/gallium/state_trackers/dri/dri1_helper.h +++ /dev/null @@ -1,61 +0,0 @@ -/************************************************************************** - * - * Copyright 2009, VMware, Inc. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ -/* - * Author: Keith Whitwell - * Author: Jakob Bornecrantz - */ - -#ifndef DRI1_HELPER_H -#define DRI1_HELPER_H - -#include "dri_screen.h" -#include "dri_context.h" -#include "dri_drawable.h" - -struct pipe_fence_handle * -dri1_swap_fences_pop_front(struct dri_drawable *draw); - -void -dri1_swap_fences_push_back(struct dri_drawable *draw, - struct pipe_fence_handle *fence); - -void -dri1_swap_fences_clear(struct dri_drawable *drawable); - -struct pipe_surface * -dri1_get_pipe_surface(struct dri_drawable *drawable, struct pipe_texture *ptex); - -void -dri1_destroy_pipe_surface(struct dri_drawable *drawable); - -struct pipe_context * -dri1_get_pipe_context(struct dri_screen *screen); - -void -dri1_destroy_pipe_context(struct dri_screen *screen); - -#endif /* DRI1_HELPER_H */ diff --git a/src/gallium/state_trackers/dri/dri_context.c b/src/gallium/state_trackers/dri/dri_context.c deleted file mode 100644 index 34d9a932ead..00000000000 --- a/src/gallium/state_trackers/dri/dri_context.c +++ /dev/null @@ -1,174 +0,0 @@ -/************************************************************************** - * - * Copyright 2009, VMware, Inc. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ -/* - * Author: Keith Whitwell - * Author: Jakob Bornecrantz - */ - -#include "dri_screen.h" -#include "dri_drawable.h" -#include "dri_context.h" -#include "dri_st_api.h" - -#include "pipe/p_context.h" -#include "util/u_memory.h" - -GLboolean -dri_create_context(const __GLcontextModes * visual, - __DRIcontext * cPriv, void *sharedContextPrivate) -{ - struct st_api *stapi = dri_get_st_api(); - __DRIscreen *sPriv = cPriv->driScreenPriv; - struct dri_screen *screen = dri_screen(sPriv); - struct dri_context *ctx = NULL; - struct st_context_iface *st_share = NULL; - struct st_visual stvis; - - if (sharedContextPrivate) { - st_share = ((struct dri_context *)sharedContextPrivate)->st; - } - - ctx = CALLOC_STRUCT(dri_context); - if (ctx == NULL) - goto fail; - - cPriv->driverPrivate = ctx; - ctx->cPriv = cPriv; - ctx->sPriv = sPriv; - ctx->lock = screen->drmLock; - - driParseConfigFiles(&ctx->optionCache, - &screen->optionCache, sPriv->myNum, "dri"); - - dri_fill_st_visual(&stvis, screen, visual); - ctx->st = stapi->create_context(stapi, screen->smapi, &stvis, st_share); - if (ctx->st == NULL) - goto fail; - ctx->st->st_manager_private = (void *) ctx; - - dri_init_extensions(ctx); - - return GL_TRUE; - - fail: - if (ctx && ctx->st) - ctx->st->destroy(ctx->st); - - FREE(ctx); - return FALSE; -} - -void -dri_destroy_context(__DRIcontext * cPriv) -{ - struct dri_context *ctx = dri_context(cPriv); - - /* note: we are freeing values and nothing more because - * driParseConfigFiles allocated values only - the rest - * is owned by screen optionCache. - */ - FREE(ctx->optionCache.values); - - /* No particular reason to wait for command completion before - * destroying a context, but it is probably worthwhile flushing it - * to avoid having to add code elsewhere to cope with flushing a - * partially destroyed context. - */ - ctx->st->flush(ctx->st, 0, NULL); - ctx->st->destroy(ctx->st); - - FREE(ctx); -} - -GLboolean -dri_unbind_context(__DRIcontext * cPriv) -{ - struct st_api *stapi = dri_get_st_api(); - - if (cPriv) { - struct dri_context *ctx = dri_context(cPriv); - - if (--ctx->bind_count == 0) { - if (ctx->st == stapi->get_current(stapi)) { - ctx->st->flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); - stapi->make_current(stapi, NULL, NULL, NULL); - } - } - } - - return GL_TRUE; -} - -GLboolean -dri_make_current(__DRIcontext * cPriv, - __DRIdrawable * driDrawPriv, - __DRIdrawable * driReadPriv) -{ - struct st_api *stapi = dri_get_st_api(); - - if (cPriv) { - struct dri_context *ctx = dri_context(cPriv); - struct dri_drawable *draw = dri_drawable(driDrawPriv); - struct dri_drawable *read = dri_drawable(driReadPriv); - struct st_context_iface *old_st; - - old_st = stapi->get_current(stapi); - if (old_st && old_st != ctx->st) - ctx->st->flush(old_st, PIPE_FLUSH_RENDER_CACHE, NULL); - - ++ctx->bind_count; - - if (ctx->dPriv != driDrawPriv) { - ctx->dPriv = driDrawPriv; - draw->texture_stamp = driDrawPriv->lastStamp - 1; - } - if (ctx->rPriv != driReadPriv) { - ctx->rPriv = driReadPriv; - read->texture_stamp = driReadPriv->lastStamp - 1; - } - - stapi->make_current(stapi, ctx->st, draw->stfb, read->stfb); - } - else { - stapi->make_current(stapi, NULL, NULL, NULL); - } - - return GL_TRUE; -} - -struct dri_context * -dri_get_current(void) -{ - struct st_api *stapi = dri_get_st_api(); - struct st_context_iface *st; - - st = stapi->get_current(stapi); - - return (struct dri_context *) (st) ? st->st_manager_private : NULL; -} - -/* vim: set sw=3 ts=8 sts=3 expandtab: */ diff --git a/src/gallium/state_trackers/dri/dri_context.h b/src/gallium/state_trackers/dri/dri_context.h deleted file mode 100644 index 24d3d0368a4..00000000000 --- a/src/gallium/state_trackers/dri/dri_context.h +++ /dev/null @@ -1,97 +0,0 @@ -/************************************************************************** - * - * Copyright (C) 2009 VMware, Inc. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ -/* - * Author: Keith Whitwell - * Author: Jakob Bornecrantz - */ - -#ifndef DRI_CONTEXT_H -#define DRI_CONTEXT_H - -#include "pipe/p_compiler.h" -#include "dri_wrapper.h" - -struct pipe_context; -struct pipe_fence; -struct st_context; -struct dri_drawable; - -struct dri_context -{ - /* dri */ - __DRIscreen *sPriv; - __DRIcontext *cPriv; - __DRIdrawable *dPriv; - __DRIdrawable *rPriv; - - driOptionCache optionCache; - - drmLock *lock; - boolean isLocked; - boolean stLostLock; - boolean wsLostLock; - - unsigned int bind_count; - - /* gallium */ - struct st_context_iface *st; -}; - -static INLINE struct dri_context * -dri_context(__DRIcontext * driContextPriv) -{ - return (struct dri_context *)driContextPriv->driverPrivate; -} - -/*********************************************************************** - * dri_context.c - */ -void dri_destroy_context(__DRIcontext * driContextPriv); - -boolean dri_unbind_context(__DRIcontext * driContextPriv); - -boolean -dri_make_current(__DRIcontext * driContextPriv, - __DRIdrawable * driDrawPriv, - __DRIdrawable * driReadPriv); - -struct dri_context * -dri_get_current(void); - -boolean -dri_create_context(const __GLcontextModes * visual, - __DRIcontext * driContextPriv, - void *sharedContextPrivate); - -/*********************************************************************** - * dri_extensions.c - */ -void dri_init_extensions(struct dri_context *ctx); - -#endif - -/* vim: set sw=3 ts=8 sts=3 expandtab: */ diff --git a/src/gallium/state_trackers/dri/dri_drawable.c b/src/gallium/state_trackers/dri/dri_drawable.c deleted file mode 100644 index 75b4cc56289..00000000000 --- a/src/gallium/state_trackers/dri/dri_drawable.c +++ /dev/null @@ -1,94 +0,0 @@ -/************************************************************************** - * - * Copyright 2009, VMware, Inc. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ -/* - * Author: Keith Whitwell - * Author: Jakob Bornecrantz - */ - -#include "dri_screen.h" -#include "dri_context.h" -#include "dri_drawable.h" -#include "dri_st_api.h" -#include "dri1_helper.h" - -#include "pipe/p_screen.h" -#include "util/u_format.h" -#include "util/u_memory.h" -#include "util/u_inlines.h" - -/** - * This is called when we need to set up GL rendering to a new X window. - */ -boolean -dri_create_buffer(__DRIscreen * sPriv, - __DRIdrawable * dPriv, - const __GLcontextModes * visual, boolean isPixmap) -{ - struct dri_screen *screen = sPriv->private; - struct dri_drawable *drawable = NULL; - - if (isPixmap) - goto fail; /* not implemented */ - - drawable = CALLOC_STRUCT(dri_drawable); - if (drawable == NULL) - goto fail; - - dri_fill_st_visual(&drawable->stvis, screen, visual); - drawable->stfb = dri_create_st_framebuffer(drawable); - if (drawable->stfb == NULL) - goto fail; - - drawable->sPriv = sPriv; - drawable->dPriv = dPriv; - dPriv->driverPrivate = (void *)drawable; - - drawable->desired_fences = 2; - - return GL_TRUE; -fail: - FREE(drawable); - return GL_FALSE; -} - -void -dri_destroy_buffer(__DRIdrawable * dPriv) -{ - struct dri_drawable *drawable = dri_drawable(dPriv); - - dri1_swap_fences_clear(drawable); - - dri1_destroy_pipe_surface(drawable); - - dri_destroy_st_framebuffer(drawable->stfb); - - drawable->desired_fences = 0; - - FREE(drawable); -} - -/* vim: set sw=3 ts=8 sts=3 expandtab: */ diff --git a/src/gallium/state_trackers/dri/dri_drawable.h b/src/gallium/state_trackers/dri/dri_drawable.h deleted file mode 100644 index 98abeb9ec05..00000000000 --- a/src/gallium/state_trackers/dri/dri_drawable.h +++ /dev/null @@ -1,89 +0,0 @@ -/************************************************************************** - * - * Copyright 2009, VMware, Inc. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -#ifndef DRI_DRAWABLE_H -#define DRI_DRAWABLE_H - -#include "pipe/p_compiler.h" -#include "pipe/p_format.h" -#include "state_tracker/st_api.h" - -struct pipe_surface; -struct pipe_fence_handle; -struct st_framebuffer; -struct dri_context; - -#define DRI_SWAP_FENCES_MAX 8 -#define DRI_SWAP_FENCES_MASK 7 - -struct dri_drawable -{ - /* dri */ - __DRIdrawable *dPriv; - __DRIscreen *sPriv; - - /* gallium */ - struct st_framebuffer_iface *stfb; - struct st_visual stvis; - - __DRIbuffer old[8]; - unsigned old_num; - unsigned old_w; - unsigned old_h; - - struct pipe_texture *textures[ST_ATTACHMENT_COUNT]; - unsigned int texture_mask, texture_stamp; - - struct pipe_fence_handle *swap_fences[DRI_SWAP_FENCES_MAX]; - unsigned int head; - unsigned int tail; - unsigned int desired_fences; - unsigned int cur_fences; - - /* used only by DRI1 */ - struct pipe_surface *dri1_surface; -}; - -static INLINE struct dri_drawable * -dri_drawable(__DRIdrawable * driDrawPriv) -{ - return (struct dri_drawable *)driDrawPriv->driverPrivate; -} - -/*********************************************************************** - * dri_drawable.c - */ -boolean -dri_create_buffer(__DRIscreen * sPriv, - __DRIdrawable * dPriv, - const __GLcontextModes * visual, boolean isPixmap); - -void dri_destroy_buffer(__DRIdrawable * dPriv); - -#endif - -/* vim: set sw=3 ts=8 sts=3 expandtab: */ diff --git a/src/gallium/state_trackers/dri/dri_extensions.c b/src/gallium/state_trackers/dri/dri_extensions.c deleted file mode 100644 index df458e1eb0f..00000000000 --- a/src/gallium/state_trackers/dri/dri_extensions.c +++ /dev/null @@ -1,48 +0,0 @@ -/************************************************************************** - * - * Copyright 2009, VMware, Inc. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ -/* - * Author: Keith Whitwell - * Author: Jakob Bornecrantz - */ - -#include "dri_screen.h" -#include "dri_context.h" -#include "state_tracker/st_context.h" - -#include "utils.h" - -void -dri_init_extensions(struct dri_context *ctx) -{ - struct st_context *st = (struct st_context *) ctx->st; - - /* New extensions should be added in mesa/state_tracker/st_extensions.c - * and not in this file. */ - driInitExtensions(st->ctx, NULL, GL_FALSE); -} - -/* vim: set sw=3 ts=8 sts=3 expandtab: */ diff --git a/src/gallium/state_trackers/dri/dri_screen.c b/src/gallium/state_trackers/dri/dri_screen.c deleted file mode 100644 index 598a07bb646..00000000000 --- a/src/gallium/state_trackers/dri/dri_screen.c +++ /dev/null @@ -1,373 +0,0 @@ -/************************************************************************** - * - * Copyright 2009, VMware, Inc. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ -/* - * Author: Keith Whitwell - * Author: Jakob Bornecrantz - */ - -#include "utils.h" -#ifndef __NOT_HAVE_DRM_H -#include "vblank.h" -#endif -#include "xmlpool.h" - -#include "dri_screen.h" -#include "dri_context.h" -#include "dri_drawable.h" -#include "dri_st_api.h" -#include "dri1_helper.h" -#ifndef __NOT_HAVE_DRM_H -#include "dri1.h" -#include "dri2.h" -#else -#include "drisw.h" -#endif - -#include "util/u_inlines.h" -#include "pipe/p_screen.h" -#include "pipe/p_format.h" -#include "state_tracker/drm_api.h" - -#include "util/u_debug.h" - -PUBLIC const char __driConfigOptions[] = - DRI_CONF_BEGIN DRI_CONF_SECTION_PERFORMANCE - DRI_CONF_FTHROTTLE_MODE(DRI_CONF_FTHROTTLE_IRQS) - DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_DEF_INTERVAL_0) - DRI_CONF_SECTION_END DRI_CONF_SECTION_QUALITY -/* DRI_CONF_FORCE_S3TC_ENABLE(false) */ - DRI_CONF_ALLOW_LARGE_TEXTURES(1) - DRI_CONF_SECTION_END DRI_CONF_END; - -const uint __driNConfigOptions = 3; - -const __DRIconfig ** -dri_fill_in_modes(struct dri_screen *screen, - unsigned pixel_bits) -{ - __DRIconfig **configs = NULL; - __DRIconfig **configs_r5g6b5 = NULL; - __DRIconfig **configs_a8r8g8b8 = NULL; - __DRIconfig **configs_x8r8g8b8 = NULL; - unsigned num_modes; - uint8_t depth_bits_array[5]; - uint8_t stencil_bits_array[5]; - uint8_t msaa_samples_array[2]; - unsigned depth_buffer_factor; - unsigned back_buffer_factor; - unsigned msaa_samples_factor; - struct pipe_screen *p_screen = screen->pipe_screen; - boolean pf_r5g6b5, pf_a8r8g8b8, pf_x8r8g8b8; - boolean pf_z16, pf_x8z24, pf_z24x8, pf_s8z24, pf_z24s8, pf_z32; - - static const GLenum back_buffer_modes[] = { - GLX_NONE, GLX_SWAP_UNDEFINED_OML, GLX_SWAP_COPY_OML - }; - - depth_bits_array[0] = 0; - stencil_bits_array[0] = 0; - depth_buffer_factor = 1; - - pf_x8z24 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_Z24X8_UNORM, - PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0); - pf_z24x8 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_X8Z24_UNORM, - PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0); - pf_s8z24 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_Z24S8_UNORM, - PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0); - pf_z24s8 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_S8Z24_UNORM, - PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0); - pf_a8r8g8b8 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_B8G8R8A8_UNORM, - PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_RENDER_TARGET, 0); - pf_x8r8g8b8 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_B8G8R8X8_UNORM, - PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_RENDER_TARGET, 0); - pf_r5g6b5 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_B5G6R5_UNORM, - PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_RENDER_TARGET, 0); - - /* We can only get a 16 or 32 bit depth buffer with getBuffersWithFormat */ - if (dri_with_format(screen->sPriv)) { - pf_z16 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_Z16_UNORM, - PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0); - pf_z32 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_Z32_UNORM, - PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0); - } else { - pf_z16 = FALSE; - pf_z32 = FALSE; - } - - if (pf_z16) { - depth_bits_array[depth_buffer_factor] = 16; - stencil_bits_array[depth_buffer_factor++] = 0; - } - if (pf_x8z24 || pf_z24x8) { - depth_bits_array[depth_buffer_factor] = 24; - stencil_bits_array[depth_buffer_factor++] = 0; - screen->d_depth_bits_last = pf_x8z24; - } - if (pf_s8z24 || pf_z24s8) { - depth_bits_array[depth_buffer_factor] = 24; - stencil_bits_array[depth_buffer_factor++] = 8; - screen->sd_depth_bits_last = pf_s8z24; - } - if (pf_z32) { - depth_bits_array[depth_buffer_factor] = 32; - stencil_bits_array[depth_buffer_factor++] = 0; - } - - msaa_samples_array[0] = 0; - msaa_samples_array[1] = 4; - back_buffer_factor = 3; - msaa_samples_factor = 2; - - num_modes = - depth_buffer_factor * back_buffer_factor * msaa_samples_factor * 4; - - if (pf_r5g6b5) - configs_r5g6b5 = driCreateConfigs(GL_RGB, GL_UNSIGNED_SHORT_5_6_5, - depth_bits_array, stencil_bits_array, - depth_buffer_factor, back_buffer_modes, - back_buffer_factor, - msaa_samples_array, msaa_samples_factor, - GL_TRUE); - - if (pf_a8r8g8b8) - configs_a8r8g8b8 = driCreateConfigs(GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, - depth_bits_array, - stencil_bits_array, - depth_buffer_factor, - back_buffer_modes, - back_buffer_factor, - msaa_samples_array, - msaa_samples_factor, - GL_TRUE); - - if (pf_x8r8g8b8) - configs_x8r8g8b8 = driCreateConfigs(GL_BGR, GL_UNSIGNED_INT_8_8_8_8_REV, - depth_bits_array, - stencil_bits_array, - depth_buffer_factor, - back_buffer_modes, - back_buffer_factor, - msaa_samples_array, - msaa_samples_factor, - GL_TRUE); - - if (pixel_bits == 16) { - configs = configs_r5g6b5; - if (configs_a8r8g8b8) - configs = configs ? driConcatConfigs(configs, configs_a8r8g8b8) : configs_a8r8g8b8; - if (configs_x8r8g8b8) - configs = configs ? driConcatConfigs(configs, configs_x8r8g8b8) : configs_x8r8g8b8; - } else { - configs = configs_a8r8g8b8; - if (configs_x8r8g8b8) - configs = configs ? driConcatConfigs(configs, configs_x8r8g8b8) : configs_x8r8g8b8; - if (configs_r5g6b5) - configs = configs ? driConcatConfigs(configs, configs_r5g6b5) : configs_r5g6b5; - } - - if (configs == NULL) { - debug_printf("%s: driCreateConfigs failed\n", __FUNCTION__); - return NULL; - } - - return (const __DRIconfig **)configs; -} - -/** - * Roughly the converse of dri_fill_in_modes. - */ -void -dri_fill_st_visual(struct st_visual *stvis, struct dri_screen *screen, - const __GLcontextModes *mode) -{ - memset(stvis, 0, sizeof(*stvis)); - - stvis->samples = mode->samples; - stvis->render_buffer = ST_ATTACHMENT_INVALID; - - if (mode->redBits == 8) { - if (mode->alphaBits == 8) - stvis->color_format = PIPE_FORMAT_B8G8R8A8_UNORM; - else - stvis->color_format = PIPE_FORMAT_B8G8R8X8_UNORM; - } else { - stvis->color_format = PIPE_FORMAT_B5G6R5_UNORM; - } - - switch (mode->depthBits) { - default: - case 0: - stvis->depth_stencil_format = PIPE_FORMAT_NONE; - break; - case 16: - stvis->depth_stencil_format = PIPE_FORMAT_Z16_UNORM; - break; - case 24: - if (mode->stencilBits == 0) { - stvis->depth_stencil_format = (screen->d_depth_bits_last) ? - PIPE_FORMAT_Z24X8_UNORM: - PIPE_FORMAT_X8Z24_UNORM; - } else { - stvis->depth_stencil_format = (screen->sd_depth_bits_last) ? - PIPE_FORMAT_Z24S8_UNORM: - PIPE_FORMAT_S8Z24_UNORM; - } - break; - case 32: - stvis->depth_stencil_format = PIPE_FORMAT_Z32_UNORM; - break; - } - - stvis->accum_format = (mode->haveAccumBuffer) ? - PIPE_FORMAT_R16G16B16A16_SNORM : PIPE_FORMAT_NONE; - - stvis->buffer_mask |= ST_ATTACHMENT_FRONT_LEFT_MASK; - if (mode->doubleBufferMode) - stvis->buffer_mask |= ST_ATTACHMENT_BACK_LEFT_MASK; - if (mode->stereoMode) { - stvis->buffer_mask |= ST_ATTACHMENT_FRONT_RIGHT_MASK; - if (mode->doubleBufferMode) - stvis->buffer_mask |= ST_ATTACHMENT_BACK_RIGHT_MASK; - } - - if (mode->haveDepthBuffer || mode->haveStencilBuffer) - stvis->buffer_mask |= ST_ATTACHMENT_DEPTH_STENCIL_MASK; - /* let the state tracker allocate the accum buffer */ -} - -#ifndef __NOT_HAVE_DRM_H - -/** - * Get information about previous buffer swaps. - */ -static int -dri_get_swap_info(__DRIdrawable * dPriv, __DRIswapInfo * sInfo) -{ - if (dPriv == NULL || dPriv->driverPrivate == NULL || sInfo == NULL) - return -1; - else - return 0; -} - -#endif - -static void -dri_destroy_option_cache(struct dri_screen * screen) -{ - int i; - - for (i = 0; i < (1 << screen->optionCache.tableSize); ++i) { - FREE(screen->optionCache.info[i].name); - FREE(screen->optionCache.info[i].ranges); - } - - FREE(screen->optionCache.info); - FREE(screen->optionCache.values); -} - -void -dri_destroy_screen(__DRIscreen * sPriv) -{ - struct dri_screen *screen = dri_screen(sPriv); - - dri1_destroy_pipe_context(screen); - - if (screen->smapi) - dri_destroy_st_manager(screen->smapi); - - if (screen->pipe_screen) - screen->pipe_screen->destroy(screen->pipe_screen); - - dri_destroy_option_cache(screen); - - FREE(screen); - sPriv->private = NULL; - sPriv->extensions = NULL; -} - -#ifndef __NOT_HAVE_DRM_H - -const struct __DriverAPIRec driDriverAPI = { - .DestroyScreen = dri_destroy_screen, - .CreateContext = dri_create_context, - .DestroyContext = dri_destroy_context, - .CreateBuffer = dri_create_buffer, - .DestroyBuffer = dri_destroy_buffer, - .MakeCurrent = dri_make_current, - .UnbindContext = dri_unbind_context, - .GetSwapInfo = dri_get_swap_info, - .GetDrawableMSC = driDrawableGetMSC32, - .WaitForMSC = driWaitForMSC32, - .InitScreen2 = dri2_init_screen, - - .InitScreen = dri1_init_screen, - .SwapBuffers = dri1_swap_buffers, - .CopySubBuffer = dri1_copy_sub_buffer, -}; - -/* This is the table of extensions that the loader will dlsym() for. */ -PUBLIC const __DRIextension *__driDriverExtensions[] = { - &driCoreExtension.base, - &driLegacyExtension.base, - &driDRI2Extension.base, - NULL -}; - -#else - -const struct __DriverAPIRec driDriverAPI = { - .DestroyScreen = dri_destroy_screen, - .CreateContext = dri_create_context, - .DestroyContext = dri_destroy_context, - .CreateBuffer = dri_create_buffer, - .DestroyBuffer = dri_destroy_buffer, - .MakeCurrent = dri_make_current, - .UnbindContext = dri_unbind_context, - - .InitScreen = drisw_init_screen, - .SwapBuffers = drisw_swap_buffers, -}; - -/* This is the table of extensions that the loader will dlsym() for. */ -PUBLIC const __DRIextension *__driDriverExtensions[] = { - &driCoreExtension.base, - &driSWRastExtension.base, - NULL -}; - -#endif - -/* vim: set sw=3 ts=8 sts=3 expandtab: */ diff --git a/src/gallium/state_trackers/dri/dri_screen.h b/src/gallium/state_trackers/dri/dri_screen.h deleted file mode 100644 index 4f59db37cfa..00000000000 --- a/src/gallium/state_trackers/dri/dri_screen.h +++ /dev/null @@ -1,114 +0,0 @@ -/************************************************************************** - * - * Copyright 2009, VMware, Inc. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ -/* - * Author: Keith Whitwell - * Author: Jakob Bornecrantz - */ - -#ifndef DRI_SCREEN_H -#define DRI_SCREEN_H - -#include "dri_wrapper.h" -#include "xmlconfig.h" - -#include "pipe/p_compiler.h" -#include "pipe/p_context.h" -#include "pipe/p_state.h" -#include "state_tracker/st_api.h" - -struct dri_screen -{ - /* dri */ - __DRIscreen *sPriv; - - /** - * Configuration cache with default values for all contexts - */ - driOptionCache optionCache; - - /* drm */ - int fd; - drmLock *drmLock; - - /* gallium */ - struct drm_api *api; - struct pipe_winsys *pipe_winsys; - struct pipe_screen *pipe_screen; - boolean d_depth_bits_last; - boolean sd_depth_bits_last; - boolean auto_fake_front; - - struct st_manager *smapi; - - /* used only by DRI1 */ - struct pipe_context *dri1_pipe; -}; - -/** cast wrapper */ -static INLINE struct dri_screen * -dri_screen(__DRIscreen * sPriv) -{ - return (struct dri_screen *)sPriv->private; -} - -#ifndef __NOT_HAVE_DRM_H - -static INLINE boolean -dri_with_format(__DRIscreen * sPriv) -{ - const __DRIdri2LoaderExtension *loader = sPriv->dri2.loader; - - return loader - && (loader->base.version >= 3) - && (loader->getBuffersWithFormat != NULL); -} - -#else - -static INLINE boolean -dri_with_format(__DRIscreen * sPriv) -{ - return TRUE; -} - -#endif - -extern const uint __driNConfigOptions; - -const __DRIconfig ** -dri_fill_in_modes(struct dri_screen *screen, unsigned pixel_bits); - -void -dri_fill_st_visual(struct st_visual *stvis, struct dri_screen *screen, - const __GLcontextModes *mode); - -void -dri_destroy_screen(__DRIscreen * sPriv); - -#endif - -/* vim: set sw=3 ts=8 sts=3 expandtab: */ diff --git a/src/gallium/state_trackers/dri/dri_st_api.c b/src/gallium/state_trackers/dri/dri_st_api.c deleted file mode 100644 index 40b24b18e9f..00000000000 --- a/src/gallium/state_trackers/dri/dri_st_api.c +++ /dev/null @@ -1,263 +0,0 @@ -/* - * Mesa 3-D graphics library - * Version: 7.9 - * - * Copyright (C) 2010 LunarG Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * Authors: - * Chia-I Wu - */ - -#include "util/u_memory.h" -#include "util/u_inlines.h" -#include "util/u_format.h" -#include "util/u_debug.h" -#include "state_tracker/st_manager.h" /* for st_manager_create_api */ - -#include "dri_screen.h" -#include "dri_context.h" -#include "dri_drawable.h" -#include "dri_st_api.h" -#include "dri1_helper.h" -#ifndef __NOT_HAVE_DRM_H -#include "dri1.h" -#include "dri2.h" -#else -#include "drisw.h" -#endif - -static boolean -dri_st_framebuffer_validate(struct st_framebuffer_iface *stfbi, - const enum st_attachment_type *statts, - unsigned count, - struct pipe_texture **out) -{ - struct dri_drawable *drawable = - (struct dri_drawable *) stfbi->st_manager_private; - unsigned statt_mask, new_mask; - boolean new_stamp; - int i; - - statt_mask = 0x0; - for (i = 0; i < count; i++) - statt_mask |= (1 << statts[i]); - - /* record newly allocated textures */ - new_mask = (statt_mask & ~drawable->texture_mask); - - /* - * dPriv->pStamp is the server stamp. It should be accessed with a lock, at - * least for DRI1. dPriv->lastStamp is the client stamp. It has the value - * of the server stamp when last checked. - */ - new_stamp = (drawable->texture_stamp != drawable->dPriv->lastStamp); - - if (new_stamp || new_mask) { - -#ifndef __NOT_HAVE_DRM_H - if (__dri1_api_hooks) { - dri1_allocate_textures(drawable, statt_mask); - } - else { - dri2_allocate_textures(drawable, statts, count); - } -#else - if (new_stamp) - drisw_update_drawable_info(drawable->dPriv); - - drisw_allocate_textures(drawable, statt_mask); -#endif - - /* add existing textures */ - for (i = 0; i < ST_ATTACHMENT_COUNT; i++) { - if (drawable->textures[i]) - statt_mask |= (1 << i); - } - - drawable->texture_stamp = drawable->dPriv->lastStamp; - drawable->texture_mask = statt_mask; - } - - if (!out) - return TRUE; - - for (i = 0; i < count; i++) { - out[i] = NULL; - pipe_texture_reference(&out[i], drawable->textures[statts[i]]); - } - - return TRUE; -} - -static boolean -dri_st_framebuffer_flush_front(struct st_framebuffer_iface *stfbi, - enum st_attachment_type statt) -{ - struct dri_drawable *drawable = - (struct dri_drawable *) stfbi->st_manager_private; - -#ifndef __NOT_HAVE_DRM_H - if (__dri1_api_hooks) { - dri1_flush_frontbuffer(drawable, statt); - } - else { - dri2_flush_frontbuffer(drawable, statt); - } -#else - drisw_flush_frontbuffer(drawable, statt); -#endif - - return TRUE; -} - -/** - * Create a framebuffer from the given drawable. - */ -struct st_framebuffer_iface * -dri_create_st_framebuffer(struct dri_drawable *drawable) -{ - struct st_framebuffer_iface *stfbi; - - stfbi = CALLOC_STRUCT(st_framebuffer_iface); - if (stfbi) { - stfbi->visual = &drawable->stvis; - stfbi->flush_front = dri_st_framebuffer_flush_front; - stfbi->validate = dri_st_framebuffer_validate; - stfbi->st_manager_private = (void *) drawable; - } - - return stfbi; -} - -/** - * Destroy a framebuffer. - */ -void -dri_destroy_st_framebuffer(struct st_framebuffer_iface *stfbi) -{ - struct dri_drawable *drawable = - (struct dri_drawable *) stfbi->st_manager_private; - int i; - - for (i = 0; i < ST_ATTACHMENT_COUNT; i++) - pipe_texture_reference(&drawable->textures[i], NULL); - - FREE(stfbi); -} - -/** - * Validate the texture at an attachment. Allocate the texture if it does not - * exist. - */ -void -dri_st_framebuffer_validate_att(struct st_framebuffer_iface *stfbi, - enum st_attachment_type statt) -{ - struct dri_drawable *drawable = - (struct dri_drawable *) stfbi->st_manager_private; - enum st_attachment_type statts[ST_ATTACHMENT_COUNT]; - unsigned i, count = 0; - - /* check if buffer already exists */ - if (drawable->texture_mask & (1 << statt)) - return; - - /* make sure DRI2 does not destroy existing buffers */ - for (i = 0; i < ST_ATTACHMENT_COUNT; i++) { - if (drawable->texture_mask & (1 << i)) { - statts[count++] = i; - } - } - statts[count++] = statt; - - drawable->texture_stamp = drawable->dPriv->lastStamp - 1; - - stfbi->validate(stfbi, statts, count, NULL); -} - -/** - * Reference counted st_api. - */ -static struct { - int32_t refcnt; - struct st_api *stapi; -} dri_st_api; - -/** - * Add a reference to the st_api of the state tracker. - */ -static void -_dri_get_st_api(void) -{ - p_atomic_inc(&dri_st_api.refcnt); - if (p_atomic_read(&dri_st_api.refcnt) == 1) - dri_st_api.stapi = st_manager_create_api(); -} - -/** - * Remove a reference to the st_api of the state tracker. - */ -static void -_dri_put_st_api(void) -{ - struct st_api *stapi = dri_st_api.stapi; - - if (p_atomic_dec_zero(&dri_st_api.refcnt)) { - stapi->destroy(dri_st_api.stapi); - dri_st_api.stapi = NULL; - } -} - -/** - * Create a state tracker manager from the given screen. - */ -struct st_manager * -dri_create_st_manager(struct dri_screen *screen) -{ - struct st_manager *smapi; - - smapi = CALLOC_STRUCT(st_manager); - if (smapi) { - smapi->screen = screen->pipe_screen; - _dri_get_st_api(); - } - - return smapi; -} - -/** - * Destroy a state tracker manager. - */ -void -dri_destroy_st_manager(struct st_manager *smapi) -{ - _dri_put_st_api(); - FREE(smapi); -} - -/** - * Return the st_api of OpenGL state tracker. - */ -struct st_api * -dri_get_st_api(void) -{ - assert(dri_st_api.stapi); - return dri_st_api.stapi; -} diff --git a/src/gallium/state_trackers/dri/dri_st_api.h b/src/gallium/state_trackers/dri/dri_st_api.h deleted file mode 100644 index 99a217bfa79..00000000000 --- a/src/gallium/state_trackers/dri/dri_st_api.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Mesa 3-D graphics library - * Version: 7.9 - * - * Copyright (C) 2010 LunarG Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * Authors: - * Chia-I Wu - */ - -#ifndef _DRI_ST_API_H_ -#define _DRI_ST_API_H_ - -#include "state_tracker/st_api.h" - -struct dri_screen; -struct dri_drawable; - -struct st_api * -dri_get_st_api(void); - -struct st_manager * -dri_create_st_manager(struct dri_screen *screen); - -void -dri_destroy_st_manager(struct st_manager *smapi); - -struct st_framebuffer_iface * -dri_create_st_framebuffer(struct dri_drawable *drawable); - -void -dri_destroy_st_framebuffer(struct st_framebuffer_iface *stfbi); - -void -dri_st_framebuffer_validate_att(struct st_framebuffer_iface *stfbi, - enum st_attachment_type statt); - -#endif /* _DRI_ST_API_H_ */ diff --git a/src/gallium/state_trackers/dri/dri_wrapper.h b/src/gallium/state_trackers/dri/dri_wrapper.h deleted file mode 100644 index 141ba02706a..00000000000 --- a/src/gallium/state_trackers/dri/dri_wrapper.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef DRI_WRAPPER_H -#define DRI_WRAPPER_H - -#ifndef __NOT_HAVE_DRM_H -#include "dri_util.h" -#else -#include "drisw_util.h" -#endif - -#endif diff --git a/src/gallium/state_trackers/dri/drm/Makefile b/src/gallium/state_trackers/dri/drm/Makefile index c43bfee8b8f..19a755b86f1 100644 --- a/src/gallium/state_trackers/dri/drm/Makefile +++ b/src/gallium/state_trackers/dri/drm/Makefile @@ -6,7 +6,7 @@ LIBNAME = dridrm LIBRARY_INCLUDES = \ -I$(TOP)/include \ -I$(TOP)/src/mesa \ - -I$(TOP)/src/gallium/state_trackers/dri \ + -I$(TOP)/src/gallium/state_trackers/dri/common \ -I$(TOP)/src/mesa/drivers/dri/common \ -I$(TOP)/src/mesa/main \ $(shell pkg-config --cflags-only-I libdrm) diff --git a/src/gallium/state_trackers/dri/drm/SConscript b/src/gallium/state_trackers/dri/drm/SConscript index a9c359c2e89..b974e298f36 100644 --- a/src/gallium/state_trackers/dri/drm/SConscript +++ b/src/gallium/state_trackers/dri/drm/SConscript @@ -9,7 +9,7 @@ if env['dri']: env.Append(CPPPATH = [ '#/src/mesa', - '#/src/gallium/state_trackers/dri', + '#/src/gallium/state_trackers/dri/common', '#/src/mesa/drivers/dri/common', ]) diff --git a/src/gallium/state_trackers/dri/drm/dri1_helper.c b/src/gallium/state_trackers/dri/drm/dri1_helper.c index 7006a8d882f..c45ebf5c102 120000 --- a/src/gallium/state_trackers/dri/drm/dri1_helper.c +++ b/src/gallium/state_trackers/dri/drm/dri1_helper.c @@ -1 +1 @@ -../dri1_helper.c \ No newline at end of file +../common/dri1_helper.c \ No newline at end of file diff --git a/src/gallium/state_trackers/dri/drm/dri_context.c b/src/gallium/state_trackers/dri/drm/dri_context.c index 989ef4438a1..5cfbbaeb068 120000 --- a/src/gallium/state_trackers/dri/drm/dri_context.c +++ b/src/gallium/state_trackers/dri/drm/dri_context.c @@ -1 +1 @@ -../dri_context.c \ No newline at end of file +../common/dri_context.c \ No newline at end of file diff --git a/src/gallium/state_trackers/dri/drm/dri_drawable.c b/src/gallium/state_trackers/dri/drm/dri_drawable.c index 422c4c1d740..0fc19be6ea6 120000 --- a/src/gallium/state_trackers/dri/drm/dri_drawable.c +++ b/src/gallium/state_trackers/dri/drm/dri_drawable.c @@ -1 +1 @@ -../dri_drawable.c \ No newline at end of file +../common/dri_drawable.c \ No newline at end of file diff --git a/src/gallium/state_trackers/dri/drm/dri_extensions.c b/src/gallium/state_trackers/dri/drm/dri_extensions.c index b793f06747d..e0d06dcdfa5 120000 --- a/src/gallium/state_trackers/dri/drm/dri_extensions.c +++ b/src/gallium/state_trackers/dri/drm/dri_extensions.c @@ -1 +1 @@ -../dri_extensions.c \ No newline at end of file +../common/dri_extensions.c \ No newline at end of file diff --git a/src/gallium/state_trackers/dri/drm/dri_screen.c b/src/gallium/state_trackers/dri/drm/dri_screen.c index 938f4c3bdc7..847f6515f25 120000 --- a/src/gallium/state_trackers/dri/drm/dri_screen.c +++ b/src/gallium/state_trackers/dri/drm/dri_screen.c @@ -1 +1 @@ -../dri_screen.c \ No newline at end of file +../common/dri_screen.c \ No newline at end of file diff --git a/src/gallium/state_trackers/dri/drm/dri_st_api.c b/src/gallium/state_trackers/dri/drm/dri_st_api.c index 9ae88230ddc..a8f6bd06b09 120000 --- a/src/gallium/state_trackers/dri/drm/dri_st_api.c +++ b/src/gallium/state_trackers/dri/drm/dri_st_api.c @@ -1 +1 @@ -../dri_st_api.c \ No newline at end of file +../common/dri_st_api.c \ No newline at end of file diff --git a/src/gallium/state_trackers/dri/sw/Makefile b/src/gallium/state_trackers/dri/sw/Makefile index 35e31e6466a..75e14fd26cb 100644 --- a/src/gallium/state_trackers/dri/sw/Makefile +++ b/src/gallium/state_trackers/dri/sw/Makefile @@ -9,7 +9,7 @@ LIBRARY_INCLUDES = \ -I../dri \ -I$(TOP)/include \ -I$(TOP)/src/mesa \ - -I$(TOP)/src/gallium/state_trackers/dri \ + -I$(TOP)/src/gallium/state_trackers/dri/common \ -I$(TOP)/src/mesa/drivers/dri/common \ -I$(TOP)/src/mesa/main \ -D__NOT_HAVE_DRM_H diff --git a/src/gallium/state_trackers/dri/sw/dri1_helper.c b/src/gallium/state_trackers/dri/sw/dri1_helper.c index 7006a8d882f..c45ebf5c102 120000 --- a/src/gallium/state_trackers/dri/sw/dri1_helper.c +++ b/src/gallium/state_trackers/dri/sw/dri1_helper.c @@ -1 +1 @@ -../dri1_helper.c \ No newline at end of file +../common/dri1_helper.c \ No newline at end of file diff --git a/src/gallium/state_trackers/dri/sw/dri_context.c b/src/gallium/state_trackers/dri/sw/dri_context.c index 989ef4438a1..5cfbbaeb068 120000 --- a/src/gallium/state_trackers/dri/sw/dri_context.c +++ b/src/gallium/state_trackers/dri/sw/dri_context.c @@ -1 +1 @@ -../dri_context.c \ No newline at end of file +../common/dri_context.c \ No newline at end of file diff --git a/src/gallium/state_trackers/dri/sw/dri_drawable.c b/src/gallium/state_trackers/dri/sw/dri_drawable.c index 422c4c1d740..0fc19be6ea6 120000 --- a/src/gallium/state_trackers/dri/sw/dri_drawable.c +++ b/src/gallium/state_trackers/dri/sw/dri_drawable.c @@ -1 +1 @@ -../dri_drawable.c \ No newline at end of file +../common/dri_drawable.c \ No newline at end of file diff --git a/src/gallium/state_trackers/dri/sw/dri_extensions.c b/src/gallium/state_trackers/dri/sw/dri_extensions.c index b793f06747d..e0d06dcdfa5 120000 --- a/src/gallium/state_trackers/dri/sw/dri_extensions.c +++ b/src/gallium/state_trackers/dri/sw/dri_extensions.c @@ -1 +1 @@ -../dri_extensions.c \ No newline at end of file +../common/dri_extensions.c \ No newline at end of file diff --git a/src/gallium/state_trackers/dri/sw/dri_screen.c b/src/gallium/state_trackers/dri/sw/dri_screen.c index 938f4c3bdc7..847f6515f25 120000 --- a/src/gallium/state_trackers/dri/sw/dri_screen.c +++ b/src/gallium/state_trackers/dri/sw/dri_screen.c @@ -1 +1 @@ -../dri_screen.c \ No newline at end of file +../common/dri_screen.c \ No newline at end of file diff --git a/src/gallium/state_trackers/dri/sw/dri_st_api.c b/src/gallium/state_trackers/dri/sw/dri_st_api.c index 9ae88230ddc..a8f6bd06b09 120000 --- a/src/gallium/state_trackers/dri/sw/dri_st_api.c +++ b/src/gallium/state_trackers/dri/sw/dri_st_api.c @@ -1 +1 @@ -../dri_st_api.c \ No newline at end of file +../common/dri_st_api.c \ No newline at end of file -- cgit v1.2.3 From bc88c95990f871a206a8fe93e7541f1f41841f7e Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Thu, 25 Mar 2010 19:19:00 +0100 Subject: i915g: Rename winsys prefix to i915_ from intel_ Since the winsys isn't shared with i965 and never will be --- SConstruct | 2 +- src/gallium/drivers/i915/i915_batch.h | 10 +- src/gallium/drivers/i915/i915_batchbuffer.h | 87 ++++++++ src/gallium/drivers/i915/i915_blit.c | 12 +- src/gallium/drivers/i915/i915_blit.h | 6 +- src/gallium/drivers/i915/i915_buffer.c | 4 +- src/gallium/drivers/i915/i915_context.h | 14 +- src/gallium/drivers/i915/i915_debug.c | 2 +- src/gallium/drivers/i915/i915_debug.h | 4 +- src/gallium/drivers/i915/i915_prim_vbuf.c | 16 +- src/gallium/drivers/i915/i915_screen.c | 4 +- src/gallium/drivers/i915/i915_screen.h | 4 +- src/gallium/drivers/i915/i915_state_emit.c | 10 +- src/gallium/drivers/i915/i915_state_immediate.c | 6 +- src/gallium/drivers/i915/i915_texture.c | 26 +-- src/gallium/drivers/i915/i915_winsys.h | 230 +++++++++++++++++++ src/gallium/drivers/i915/intel_batchbuffer.h | 87 -------- src/gallium/drivers/i915/intel_winsys.h | 227 ------------------- src/gallium/targets/SConscript | 2 +- src/gallium/targets/dri-i915/Makefile | 2 +- src/gallium/targets/dri-i915/SConscript | 2 +- src/gallium/targets/egl-i915/Makefile | 2 +- src/gallium/targets/xorg-i915/Makefile | 2 +- src/gallium/winsys/SConscript | 2 +- src/gallium/winsys/i915/drm/Makefile | 10 +- src/gallium/winsys/i915/drm/SConscript | 18 +- src/gallium/winsys/i915/drm/i915_drm_api.c | 109 +++++++++ src/gallium/winsys/i915/drm/i915_drm_batchbuffer.c | 244 +++++++++++++++++++++ src/gallium/winsys/i915/drm/i915_drm_buffer.c | 217 ++++++++++++++++++ src/gallium/winsys/i915/drm/i915_drm_fence.c | 83 +++++++ src/gallium/winsys/i915/drm/i915_drm_winsys.h | 77 +++++++ src/gallium/winsys/i915/drm/intel_drm_api.c | 109 --------- .../winsys/i915/drm/intel_drm_batchbuffer.c | 244 --------------------- src/gallium/winsys/i915/drm/intel_drm_buffer.c | 217 ------------------ src/gallium/winsys/i915/drm/intel_drm_fence.c | 83 ------- src/gallium/winsys/i915/drm/intel_drm_winsys.h | 77 ------- 36 files changed, 1127 insertions(+), 1124 deletions(-) create mode 100644 src/gallium/drivers/i915/i915_batchbuffer.h create mode 100644 src/gallium/drivers/i915/i915_winsys.h delete mode 100644 src/gallium/drivers/i915/intel_batchbuffer.h delete mode 100644 src/gallium/drivers/i915/intel_winsys.h create mode 100644 src/gallium/winsys/i915/drm/i915_drm_api.c create mode 100644 src/gallium/winsys/i915/drm/i915_drm_batchbuffer.c create mode 100644 src/gallium/winsys/i915/drm/i915_drm_buffer.c create mode 100644 src/gallium/winsys/i915/drm/i915_drm_fence.c create mode 100644 src/gallium/winsys/i915/drm/i915_drm_winsys.h delete mode 100644 src/gallium/winsys/i915/drm/intel_drm_api.c delete mode 100644 src/gallium/winsys/i915/drm/intel_drm_batchbuffer.c delete mode 100644 src/gallium/winsys/i915/drm/intel_drm_buffer.c delete mode 100644 src/gallium/winsys/i915/drm/intel_drm_fence.c delete mode 100644 src/gallium/winsys/i915/drm/intel_drm_winsys.h (limited to 'src/gallium') diff --git a/SConstruct b/SConstruct index 6ed44ddd067..2549a13fffa 100644 --- a/SConstruct +++ b/SConstruct @@ -52,7 +52,7 @@ opts.Add(ListVariable('statetrackers', 'state trackers to build', default_statet opts.Add(ListVariable('drivers', 'pipe drivers to build', default_drivers, ['softpipe', 'failover', 'svga', 'i915', 'i965', 'trace', 'r300', 'identity', 'llvmpipe'])) opts.Add(ListVariable('winsys', 'winsys drivers to build', default_winsys, - ['xlib', 'vmware', 'intel', 'i965', 'gdi', 'radeon'])) + ['xlib', 'vmware', 'i915', 'i965', 'gdi', 'radeon'])) opts.Add(EnumVariable('MSVS_VERSION', 'MS Visual C++ version', None, allowed_values=('7.1', '8.0', '9.0'))) diff --git a/src/gallium/drivers/i915/i915_batch.h b/src/gallium/drivers/i915/i915_batch.h index b813784723f..f0086695d16 100644 --- a/src/gallium/drivers/i915/i915_batch.h +++ b/src/gallium/drivers/i915/i915_batch.h @@ -28,19 +28,19 @@ #ifndef I915_BATCH_H #define I915_BATCH_H -#include "intel_batchbuffer.h" +#include "i915_batchbuffer.h" #define BEGIN_BATCH(dwords, relocs) \ - (intel_batchbuffer_check(i915->batch, dwords, relocs)) + (i915_winsys_batchbuffer_check(i915->batch, dwords, relocs)) #define OUT_BATCH(dword) \ - intel_batchbuffer_dword(i915->batch, dword) + i915_winsys_batchbuffer_dword(i915->batch, dword) #define OUT_RELOC(buf, usage, offset) \ - intel_batchbuffer_reloc(i915->batch, buf, usage, offset) + i915_winsys_batchbuffer_reloc(i915->batch, buf, usage, offset) #define FLUSH_BATCH(fence) do { \ - intel_batchbuffer_flush(i915->batch, fence); \ + i915_winsys_batchbuffer_flush(i915->batch, fence); \ i915->hardware_dirty = ~0; \ } while (0) diff --git a/src/gallium/drivers/i915/i915_batchbuffer.h b/src/gallium/drivers/i915/i915_batchbuffer.h new file mode 100644 index 00000000000..27ccaa6b1fa --- /dev/null +++ b/src/gallium/drivers/i915/i915_batchbuffer.h @@ -0,0 +1,87 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef I915_BATCHBUFFER_H +#define I915_BATCHBUFFER_H + +#include "i915_winsys.h" + +static INLINE boolean +i915_winsys_batchbuffer_check(struct i915_winsys_batchbuffer *batch, + size_t dwords, + size_t relocs) +{ + return dwords * 4 <= batch->size - (batch->ptr - batch->map) && + relocs <= (batch->max_relocs - batch->relocs); +} + +static INLINE size_t +i915_winsys_batchbuffer_space(struct i915_winsys_batchbuffer *batch) +{ + return batch->size - (batch->ptr - batch->map); +} + +static INLINE void +i915_winsys_batchbuffer_dword(struct i915_winsys_batchbuffer *batch, + unsigned dword) +{ + if (i915_winsys_batchbuffer_space(batch) < 4) + return; + + *(unsigned *)batch->ptr = dword; + batch->ptr += 4; +} + +static INLINE void +i915_winsys_batchbuffer_write(struct i915_winsys_batchbuffer *batch, + void *data, + size_t size) +{ + if (i915_winsys_batchbuffer_space(batch) < size) + return; + + memcpy(data, batch->ptr, size); + batch->ptr += size; +} + +static INLINE int +i915_winsys_batchbuffer_reloc(struct i915_winsys_batchbuffer *batch, + struct i915_winsys_buffer *buffer, + enum i915_winsys_buffer_usage usage, + size_t offset) +{ + return batch->iws->batchbuffer_reloc(batch, buffer, usage, offset); +} + +static INLINE void +i915_winsys_batchbuffer_flush(struct i915_winsys_batchbuffer *batch, + struct pipe_fence_handle **fence) +{ + batch->iws->batchbuffer_flush(batch, fence); +} + +#endif diff --git a/src/gallium/drivers/i915/i915_blit.c b/src/gallium/drivers/i915/i915_blit.c index 83dfc335288..533fa81219b 100644 --- a/src/gallium/drivers/i915/i915_blit.c +++ b/src/gallium/drivers/i915/i915_blit.c @@ -37,7 +37,7 @@ void i915_fill_blit(struct i915_context *i915, unsigned cpp, unsigned short dst_pitch, - struct intel_buffer *dst_buffer, + struct i915_winsys_buffer *dst_buffer, unsigned dst_offset, short x, short y, short w, short h, @@ -77,7 +77,7 @@ i915_fill_blit(struct i915_context *i915, OUT_BATCH(BR13); OUT_BATCH((y << 16) | x); OUT_BATCH(((y + h) << 16) | (x + w)); - OUT_RELOC(dst_buffer, INTEL_USAGE_2D_TARGET, dst_offset); + OUT_RELOC(dst_buffer, I915_USAGE_2D_TARGET, dst_offset); OUT_BATCH(color); FLUSH_BATCH(NULL); } @@ -87,10 +87,10 @@ i915_copy_blit(struct i915_context *i915, unsigned do_flip, unsigned cpp, unsigned short src_pitch, - struct intel_buffer *src_buffer, + struct i915_winsys_buffer *src_buffer, unsigned src_offset, unsigned short dst_pitch, - struct intel_buffer *dst_buffer, + struct i915_winsys_buffer *dst_buffer, unsigned dst_offset, short src_x, short src_y, short dst_x, short dst_y, @@ -143,9 +143,9 @@ i915_copy_blit(struct i915_context *i915, OUT_BATCH(BR13); OUT_BATCH((dst_y << 16) | dst_x); OUT_BATCH((dst_y2 << 16) | dst_x2); - OUT_RELOC(dst_buffer, INTEL_USAGE_2D_TARGET, dst_offset); + OUT_RELOC(dst_buffer, I915_USAGE_2D_TARGET, dst_offset); OUT_BATCH((src_y << 16) | src_x); OUT_BATCH(((int) src_pitch & 0xffff)); - OUT_RELOC(src_buffer, INTEL_USAGE_2D_SOURCE, src_offset); + OUT_RELOC(src_buffer, I915_USAGE_2D_SOURCE, src_offset); FLUSH_BATCH(NULL); } diff --git a/src/gallium/drivers/i915/i915_blit.h b/src/gallium/drivers/i915/i915_blit.h index 8ce3220cfd9..db576ed4c90 100644 --- a/src/gallium/drivers/i915/i915_blit.h +++ b/src/gallium/drivers/i915/i915_blit.h @@ -34,10 +34,10 @@ extern void i915_copy_blit(struct i915_context *i915, unsigned do_flip, unsigned cpp, unsigned short src_pitch, - struct intel_buffer *src_buffer, + struct i915_winsys_buffer *src_buffer, unsigned src_offset, unsigned short dst_pitch, - struct intel_buffer *dst_buffer, + struct i915_winsys_buffer *dst_buffer, unsigned dst_offset, short srcx, short srcy, short dstx, short dsty, @@ -46,7 +46,7 @@ extern void i915_copy_blit(struct i915_context *i915, extern void i915_fill_blit(struct i915_context *i915, unsigned cpp, unsigned short dst_pitch, - struct intel_buffer *dst_buffer, + struct i915_winsys_buffer *dst_buffer, unsigned dst_offset, short x, short y, short w, short h, unsigned color); diff --git a/src/gallium/drivers/i915/i915_buffer.c b/src/gallium/drivers/i915/i915_buffer.c index 0f76a59e93a..1247de320d4 100644 --- a/src/gallium/drivers/i915/i915_buffer.c +++ b/src/gallium/drivers/i915/i915_buffer.c @@ -28,13 +28,13 @@ #include "i915_screen.h" #include "i915_buffer.h" -struct intel_buffer; +struct i915_winsys_buffer; struct i915_buffer { struct pipe_buffer base; - struct intel_buffer *ibuf; /** hw buffer */ + struct i915_winsys_buffer *ibuf; /** hw buffer */ void *data; /**< user and malloc data */ boolean own; /**< we own the data incase of malloc */ diff --git a/src/gallium/drivers/i915/i915_context.h b/src/gallium/drivers/i915/i915_context.h index 5348f62ca74..8df4dce8653 100644 --- a/src/gallium/drivers/i915/i915_context.h +++ b/src/gallium/drivers/i915/i915_context.h @@ -38,9 +38,9 @@ #include "tgsi/tgsi_scan.h" -struct intel_winsys; -struct intel_buffer; -struct intel_batchbuffer; +struct i915_winsys; +struct i915_winsys_buffer; +struct i915_winsys_batchbuffer; #define I915_TEX_UNITS 8 @@ -219,14 +219,14 @@ struct i915_texture { /* The data is held here: */ - struct intel_buffer *buffer; + struct i915_winsys_buffer *buffer; }; struct i915_context { struct pipe_context base; - struct intel_winsys *iws; + struct i915_winsys *iws; struct draw_context *draw; @@ -257,10 +257,10 @@ struct i915_context unsigned num_fragment_sampler_views; unsigned num_vertex_buffers; - struct intel_batchbuffer *batch; + struct i915_winsys_batchbuffer *batch; /** Vertex buffer */ - struct intel_buffer *vbo; + struct i915_winsys_buffer *vbo; size_t vbo_offset; unsigned vbo_flushed; diff --git a/src/gallium/drivers/i915/i915_debug.c b/src/gallium/drivers/i915/i915_debug.c index 237654d26b2..663fac3055c 100644 --- a/src/gallium/drivers/i915/i915_debug.c +++ b/src/gallium/drivers/i915/i915_debug.c @@ -863,7 +863,7 @@ static boolean i915_debug_packet( struct debug_stream *stream ) void -i915_dump_batchbuffer( struct intel_batchbuffer *batch ) +i915_dump_batchbuffer( struct i915_winsys_batchbuffer *batch ) { struct debug_stream stream; unsigned *start = (unsigned*)batch->map; diff --git a/src/gallium/drivers/i915/i915_debug.h b/src/gallium/drivers/i915/i915_debug.h index 8f7484797de..67b8d9c2f63 100644 --- a/src/gallium/drivers/i915/i915_debug.h +++ b/src/gallium/drivers/i915/i915_debug.h @@ -104,9 +104,9 @@ I915_DBG( #endif -struct intel_batchbuffer; +struct i915_winsys_batchbuffer; -void i915_dump_batchbuffer( struct intel_batchbuffer *i915 ); +void i915_dump_batchbuffer( struct i915_winsys_batchbuffer *i915 ); void i915_debug_init( struct i915_context *i915 ); diff --git a/src/gallium/drivers/i915/i915_prim_vbuf.c b/src/gallium/drivers/i915/i915_prim_vbuf.c index cad4109ee6b..df9e68af4fc 100644 --- a/src/gallium/drivers/i915/i915_prim_vbuf.c +++ b/src/gallium/drivers/i915/i915_prim_vbuf.c @@ -76,7 +76,7 @@ struct i915_vbuf_render { unsigned fallback; /* Stuff for the vbo */ - struct intel_buffer *vbo; + struct i915_winsys_buffer *vbo; size_t vbo_size; /**< current size of allocated buffer */ size_t vbo_alloc_size; /**< minimum buffer size to allocate */ size_t vbo_offset; @@ -141,7 +141,7 @@ static void i915_vbuf_render_new_buf(struct i915_vbuf_render *i915_render, size_t size) { struct i915_context *i915 = i915_render->i915; - struct intel_winsys *iws = i915->iws; + struct i915_winsys *iws = i915->iws; if (i915_render->vbo) { #ifdef VBUF_USE_FIFO @@ -172,7 +172,7 @@ i915_vbuf_render_new_buf(struct i915_vbuf_render *i915_render, size_t size) if (i915_render->vbo_size != i915_render->pool_buffer_size) { i915_render->pool_not_used = TRUE; i915_render->vbo = iws->buffer_create(iws, i915_render->vbo_size, 64, - INTEL_NEW_VERTEX); + I915_NEW_VERTEX); } else { i915_render->pool_not_used = FALSE; @@ -185,7 +185,7 @@ i915_vbuf_render_new_buf(struct i915_vbuf_render *i915_render, size_t size) } #else i915_render->vbo = iws->buffer_create(iws, i915_render->vbo_size, - 64, INTEL_NEW_VERTEX); + 64, I915_NEW_VERTEX); #endif } @@ -225,7 +225,7 @@ i915_vbuf_render_map_vertices(struct vbuf_render *render) { struct i915_vbuf_render *i915_render = i915_vbuf_render(render); struct i915_context *i915 = i915_render->i915; - struct intel_winsys *iws = i915->iws; + struct i915_winsys *iws = i915->iws; if (i915->vbo_flushed) debug_printf("%s bad vbo flush occured stalling on hw\n", __FUNCTION__); @@ -246,7 +246,7 @@ i915_vbuf_render_unmap_vertices(struct vbuf_render *render, { struct i915_vbuf_render *i915_render = i915_vbuf_render(render); struct i915_context *i915 = i915_render->i915; - struct intel_winsys *iws = i915->iws; + struct i915_winsys *iws = i915->iws; i915_render->vbo_max_used = MAX2(i915_render->vbo_max_used, i915_render->vertex_size * (max_index + 1)); #ifdef VBUF_MAP_BUFFER @@ -621,7 +621,7 @@ static struct vbuf_render * i915_vbuf_render_create(struct i915_context *i915) { struct i915_vbuf_render *i915_render = CALLOC_STRUCT(i915_vbuf_render); - struct intel_winsys *iws = i915->iws; + struct i915_winsys *iws = i915->iws; int i; i915_render->i915 = i915; @@ -662,7 +662,7 @@ i915_vbuf_render_create(struct i915_context *i915) for (i = 0; i < 6; i++) u_fifo_add(i915_render->pool_fifo, iws->buffer_create(iws, i915_render->pool_buffer_size, 64, - INTEL_NEW_VERTEX)); + I915_NEW_VERTEX)); #else (void)i; (void)iws; diff --git a/src/gallium/drivers/i915/i915_screen.c b/src/gallium/drivers/i915/i915_screen.c index 48a39edad20..53ef6e50f6c 100644 --- a/src/gallium/drivers/i915/i915_screen.c +++ b/src/gallium/drivers/i915/i915_screen.c @@ -35,7 +35,7 @@ #include "i915_screen.h" #include "i915_buffer.h" #include "i915_texture.h" -#include "intel_winsys.h" +#include "i915_winsys.h" /* @@ -260,7 +260,7 @@ i915_destroy_screen(struct pipe_screen *screen) * Create a new i915_screen object */ struct pipe_screen * -i915_create_screen(struct intel_winsys *iws, uint pci_id) +i915_create_screen(struct i915_winsys *iws, uint pci_id) { struct i915_screen *is = CALLOC_STRUCT(i915_screen); diff --git a/src/gallium/drivers/i915/i915_screen.h b/src/gallium/drivers/i915/i915_screen.h index 5126485caa7..7f9e02fc0f6 100644 --- a/src/gallium/drivers/i915/i915_screen.h +++ b/src/gallium/drivers/i915/i915_screen.h @@ -32,7 +32,7 @@ #include "pipe/p_screen.h" -struct intel_winsys; +struct i915_winsys; /** @@ -42,7 +42,7 @@ struct i915_screen { struct pipe_screen base; - struct intel_winsys *iws; + struct i915_winsys *iws; boolean is_i945; uint pci_id; diff --git a/src/gallium/drivers/i915/i915_state_emit.c b/src/gallium/drivers/i915/i915_state_emit.c index d79c1ca0b2c..04a3924aaf7 100644 --- a/src/gallium/drivers/i915/i915_state_emit.c +++ b/src/gallium/drivers/i915/i915_state_emit.c @@ -182,7 +182,7 @@ i915_emit_hardware_state(struct i915_context *i915 ) if(i915->vbo) OUT_RELOC(i915->vbo, - INTEL_USAGE_VERTEX, + I915_USAGE_VERTEX, i915->current.immediate[I915_IMMEDIATE_S0]); else /* FIXME: we should not do this */ @@ -226,7 +226,7 @@ i915_emit_hardware_state(struct i915_context *i915 ) ctile); OUT_RELOC(tex->buffer, - INTEL_USAGE_RENDER, + I915_USAGE_RENDER, cbuf_surface->offset); } @@ -250,7 +250,7 @@ i915_emit_hardware_state(struct i915_context *i915 ) ztile); OUT_RELOC(tex->buffer, - INTEL_USAGE_RENDER, + I915_USAGE_RENDER, depth_surface->offset); } @@ -291,13 +291,13 @@ i915_emit_hardware_state(struct i915_context *i915 ) for (unit = 0; unit < I915_TEX_UNITS; unit++) { if (enabled & (1 << unit)) { struct i915_texture *texture = (struct i915_texture *)i915->fragment_sampler_views[unit]->texture; - struct intel_buffer *buf = texture->buffer; + struct i915_winsys_buffer *buf = texture->buffer; uint offset = 0; assert(buf); count++; - OUT_RELOC(buf, INTEL_USAGE_SAMPLER, offset); + OUT_RELOC(buf, I915_USAGE_SAMPLER, offset); OUT_BATCH(i915->current.texbuffer[unit][0]); /* MS3 */ OUT_BATCH(i915->current.texbuffer[unit][1]); /* MS4 */ } diff --git a/src/gallium/drivers/i915/i915_state_immediate.c b/src/gallium/drivers/i915/i915_state_immediate.c index d2c6f151434..8cec699285c 100644 --- a/src/gallium/drivers/i915/i915_state_immediate.c +++ b/src/gallium/drivers/i915/i915_state_immediate.c @@ -52,11 +52,11 @@ static void upload_S0S1(struct i915_context *i915) { unsigned LIS0, LIS1; - /* INTEL_NEW_VBO */ + /* I915_NEW_VBO */ /* TODO: re-use vertex buffers here? */ LIS0 = i915->vbo_offset; - /* INTEL_NEW_VERTEX_SIZE -- do this where the vertex size is calculated! + /* I915_NEW_VERTEX_SIZE -- do this where the vertex size is calculated! */ { unsigned vertex_size = i915->current.vertex_info.size; @@ -65,7 +65,7 @@ static void upload_S0S1(struct i915_context *i915) (vertex_size << 16)); } - /* INTEL_NEW_VBO */ + /* I915_NEW_VBO */ /* TODO: use a vertex generation number to track vbo changes */ if (1 || i915->current.immediate[I915_IMMEDIATE_S0] != LIS0 || diff --git a/src/gallium/drivers/i915/i915_texture.c b/src/gallium/drivers/i915/i915_texture.c index b252fb5330c..8c405c2443e 100644 --- a/src/gallium/drivers/i915/i915_texture.c +++ b/src/gallium/drivers/i915/i915_texture.c @@ -41,7 +41,7 @@ #include "i915_context.h" #include "i915_texture.h" #include "i915_screen.h" -#include "intel_winsys.h" +#include "i915_winsys.h" /* @@ -162,7 +162,7 @@ i915_scanout_layout(struct i915_texture *tex) if (pt->width0 >= 240) { tex->stride = power_of_two(util_format_get_stride(pt->format, pt->width0)); tex->total_nblocksy = align(util_format_get_nblocksy(pt->format, pt->height0), 8); - tex->hw_tiled = INTEL_TILE_X; + tex->hw_tiled = I915_TILE_X; } else if (pt->width0 == 64 && pt->height0 == 64) { tex->stride = power_of_two(util_format_get_stride(pt->format, pt->width0)); tex->total_nblocksy = align(util_format_get_nblocksy(pt->format, pt->height0), 8); @@ -200,7 +200,7 @@ i915_display_target_layout(struct i915_texture *tex) tex->stride = power_of_two(util_format_get_stride(pt->format, pt->width0)); tex->total_nblocksy = align(util_format_get_nblocksy(pt->format, pt->height0), 8); - tex->hw_tiled = INTEL_TILE_X; + tex->hw_tiled = I915_TILE_X; debug_printf("%s size: %d,%d,%d offset %d,%d (0x%x)\n", __FUNCTION__, pt->width0, pt->height0, util_format_get_blocksize(pt->format), @@ -617,7 +617,7 @@ i915_texture_create(struct pipe_screen *screen, const struct pipe_texture *templat) { struct i915_screen *is = i915_screen(screen); - struct intel_winsys *iws = is->iws; + struct i915_winsys *iws = is->iws; struct i915_texture *tex = CALLOC_STRUCT(i915_texture); size_t tex_size; unsigned buf_usage = 0; @@ -643,9 +643,9 @@ i915_texture_create(struct pipe_screen *screen, /* for scanouts and cursors, cursors arn't scanouts */ if (templat->tex_usage & PIPE_TEXTURE_USAGE_SCANOUT && templat->width0 != 64) - buf_usage = INTEL_NEW_SCANOUT; + buf_usage = I915_NEW_SCANOUT; else - buf_usage = INTEL_NEW_TEXTURE; + buf_usage = I915_NEW_TEXTURE; tex->buffer = iws->buffer_create(iws, tex_size, 64, buf_usage); if (!tex->buffer) @@ -653,7 +653,7 @@ i915_texture_create(struct pipe_screen *screen, /* setup any hw fences */ if (tex->hw_tiled) { - assert(tex->sw_tiled == INTEL_TILE_NONE); + assert(tex->sw_tiled == I915_TILE_NONE); iws->buffer_set_fence_reg(iws, tex->buffer, tex->stride, tex->hw_tiled); } @@ -679,8 +679,8 @@ i915_texture_from_handle(struct pipe_screen * screen, { struct i915_screen *is = i915_screen(screen); struct i915_texture *tex; - struct intel_winsys *iws = is->iws; - struct intel_buffer *buffer; + struct i915_winsys *iws = is->iws; + struct i915_winsys_buffer *buffer; unsigned stride; assert(screen); @@ -719,7 +719,7 @@ i915_texture_get_handle(struct pipe_screen * screen, { struct i915_screen *is = i915_screen(screen); struct i915_texture *tex = (struct i915_texture *)texture; - struct intel_winsys *iws = is->iws; + struct i915_winsys *iws = is->iws; return iws->buffer_get_handle(iws, tex->buffer, whandle, tex->stride); } @@ -729,7 +729,7 @@ static void i915_texture_destroy(struct pipe_texture *pt) { struct i915_texture *tex = (struct i915_texture *)pt; - struct intel_winsys *iws = i915_screen(pt->screen)->iws; + struct i915_winsys *iws = i915_screen(pt->screen)->iws; uint i; /* @@ -841,7 +841,7 @@ i915_transfer_map(struct pipe_context *pipe, struct pipe_transfer *transfer) { struct i915_texture *tex = (struct i915_texture *)transfer->texture; - struct intel_winsys *iws = i915_screen(tex->base.screen)->iws; + struct i915_winsys *iws = i915_screen(tex->base.screen)->iws; char *map; boolean write = FALSE; enum pipe_format format = tex->base.format; @@ -863,7 +863,7 @@ i915_transfer_unmap(struct pipe_context *pipe, struct pipe_transfer *transfer) { struct i915_texture *tex = (struct i915_texture *)transfer->texture; - struct intel_winsys *iws = i915_screen(tex->base.screen)->iws; + struct i915_winsys *iws = i915_screen(tex->base.screen)->iws; iws->buffer_unmap(iws, tex->buffer); } diff --git a/src/gallium/drivers/i915/i915_winsys.h b/src/gallium/drivers/i915/i915_winsys.h new file mode 100644 index 00000000000..246e95b00d6 --- /dev/null +++ b/src/gallium/drivers/i915/i915_winsys.h @@ -0,0 +1,230 @@ +/************************************************************************** + * + * Copyright © 2009 Jakob Bornecrantz + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef I915_WINSYS_H +#define I915_WINSYS_H + +#include "pipe/p_compiler.h" + +struct i915_winsys; +struct i915_winsys_buffer; +struct i915_winsys_batchbuffer; +struct pipe_texture; +struct pipe_fence_handle; +struct winsys_handle; + +enum i915_winsys_buffer_usage +{ + /* use on textures */ + I915_USAGE_RENDER = 0x01, + I915_USAGE_SAMPLER = 0x02, + I915_USAGE_2D_TARGET = 0x04, + I915_USAGE_2D_SOURCE = 0x08, + /* use on vertex */ + I915_USAGE_VERTEX = 0x10 +}; + +enum i915_winsys_buffer_type +{ + I915_NEW_TEXTURE, + I915_NEW_SCANOUT, /**< a texture used for scanning out from */ + I915_NEW_VERTEX +}; + +enum i915_winsys_buffer_tile +{ + I915_TILE_NONE, + I915_TILE_X, + I915_TILE_Y +}; + +struct i915_winsys_batchbuffer { + + struct i915_winsys *iws; + + /** + * Values exported to speed up the writing the batchbuffer, + * instead of having to go trough a accesor function for + * each dword written. + */ + /*{@*/ + uint8_t *map; + uint8_t *ptr; + size_t size; + + size_t relocs; + size_t max_relocs; + /*@}*/ +}; + +struct i915_winsys { + + /** + * Batchbuffer functions. + */ + /*@{*/ + /** + * Create a new batchbuffer. + */ + struct i915_winsys_batchbuffer * + (*batchbuffer_create)(struct i915_winsys *iws); + + /** + * Emit a relocation to a buffer. + * Target position in batchbuffer is the same as ptr. + * + * @batch + * @reloc buffer address to be inserted into target. + * @usage how is the hardware going to use the buffer. + * @offset add this to the reloc buffers address + * @target buffer where to write the address, null for batchbuffer. + */ + int (*batchbuffer_reloc)(struct i915_winsys_batchbuffer *batch, + struct i915_winsys_buffer *reloc, + enum i915_winsys_buffer_usage usage, + unsigned offset); + + /** + * Flush a bufferbatch. + */ + void (*batchbuffer_flush)(struct i915_winsys_batchbuffer *batch, + struct pipe_fence_handle **fence); + + /** + * Destroy a batchbuffer. + */ + void (*batchbuffer_destroy)(struct i915_winsys_batchbuffer *batch); + /*@}*/ + + + /** + * Buffer functions. + */ + /*@{*/ + /** + * Create a buffer. + */ + struct i915_winsys_buffer * + (*buffer_create)(struct i915_winsys *iws, + unsigned size, unsigned alignment, + enum i915_winsys_buffer_type type); + + /** + * Creates a buffer from a handle. + * Used to implement pipe_screen::texture_from_handle. + * Also provides the stride information needed for the + * texture via the stride argument. + */ + struct i915_winsys_buffer * + (*buffer_from_handle)(struct i915_winsys *iws, + struct winsys_handle *whandle, + unsigned *stride); + + /** + * Used to implement pipe_screen::texture_get_handle. + * The winsys might need the stride information. + */ + boolean (*buffer_get_handle)(struct i915_winsys *iws, + struct i915_winsys_buffer *buffer, + struct winsys_handle *whandle, + unsigned stride); + + /** + * Fence a buffer with a fence reg. + * Not to be confused with pipe_fence_handle. + */ + int (*buffer_set_fence_reg)(struct i915_winsys *iws, + struct i915_winsys_buffer *buffer, + unsigned stride, + enum i915_winsys_buffer_tile tile); + + /** + * Map a buffer. + */ + void *(*buffer_map)(struct i915_winsys *iws, + struct i915_winsys_buffer *buffer, + boolean write); + + /** + * Unmap a buffer. + */ + void (*buffer_unmap)(struct i915_winsys *iws, + struct i915_winsys_buffer *buffer); + + /** + * Write to a buffer. + * + * Arguments follows pipe_buffer_write. + */ + int (*buffer_write)(struct i915_winsys *iws, + struct i915_winsys_buffer *dst, + size_t offset, + size_t size, + const void *data); + + void (*buffer_destroy)(struct i915_winsys *iws, + struct i915_winsys_buffer *buffer); + /*@}*/ + + + /** + * Fence functions. + */ + /*@{*/ + /** + * Reference fence and set ptr to fence. + */ + void (*fence_reference)(struct i915_winsys *iws, + struct pipe_fence_handle **ptr, + struct pipe_fence_handle *fence); + + /** + * Check if a fence has finished. + */ + int (*fence_signalled)(struct i915_winsys *iws, + struct pipe_fence_handle *fence); + + /** + * Wait on a fence to finish. + */ + int (*fence_finish)(struct i915_winsys *iws, + struct pipe_fence_handle *fence); + /*@}*/ + + + /** + * Destroy the winsys. + */ + void (*destroy)(struct i915_winsys *iws); +}; + + +/** + * Create i915 pipe_screen. + */ +struct pipe_screen *i915_create_screen(struct i915_winsys *iws, unsigned pci_id); + + +#endif diff --git a/src/gallium/drivers/i915/intel_batchbuffer.h b/src/gallium/drivers/i915/intel_batchbuffer.h deleted file mode 100644 index db12dfd2ac2..00000000000 --- a/src/gallium/drivers/i915/intel_batchbuffer.h +++ /dev/null @@ -1,87 +0,0 @@ -/************************************************************************** - * - * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -#ifndef INTEL_BATCH_H -#define INTEL_BATCH_H - -#include "intel_winsys.h" - -static INLINE boolean -intel_batchbuffer_check(struct intel_batchbuffer *batch, - size_t dwords, - size_t relocs) -{ - return dwords * 4 <= batch->size - (batch->ptr - batch->map) && - relocs <= (batch->max_relocs - batch->relocs); -} - -static INLINE size_t -intel_batchbuffer_space(struct intel_batchbuffer *batch) -{ - return batch->size - (batch->ptr - batch->map); -} - -static INLINE void -intel_batchbuffer_dword(struct intel_batchbuffer *batch, - unsigned dword) -{ - if (intel_batchbuffer_space(batch) < 4) - return; - - *(unsigned *)batch->ptr = dword; - batch->ptr += 4; -} - -static INLINE void -intel_batchbuffer_write(struct intel_batchbuffer *batch, - void *data, - size_t size) -{ - if (intel_batchbuffer_space(batch) < size) - return; - - memcpy(data, batch->ptr, size); - batch->ptr += size; -} - -static INLINE int -intel_batchbuffer_reloc(struct intel_batchbuffer *batch, - struct intel_buffer *buffer, - enum intel_buffer_usage usage, - size_t offset) -{ - return batch->iws->batchbuffer_reloc(batch, buffer, usage, offset); -} - -static INLINE void -intel_batchbuffer_flush(struct intel_batchbuffer *batch, - struct pipe_fence_handle **fence) -{ - batch->iws->batchbuffer_flush(batch, fence); -} - -#endif diff --git a/src/gallium/drivers/i915/intel_winsys.h b/src/gallium/drivers/i915/intel_winsys.h deleted file mode 100644 index 00fd0c1efea..00000000000 --- a/src/gallium/drivers/i915/intel_winsys.h +++ /dev/null @@ -1,227 +0,0 @@ -/************************************************************************** - * - * Copyright © 2009 Jakob Bornecrantz - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -#ifndef INTEL_WINSYS_H -#define INTEL_WINSYS_H - -#include "pipe/p_compiler.h" - -struct intel_winsys; -struct intel_buffer; -struct intel_batchbuffer; -struct pipe_texture; -struct pipe_fence_handle; -struct winsys_handle; - -enum intel_buffer_usage -{ - /* use on textures */ - INTEL_USAGE_RENDER = 0x01, - INTEL_USAGE_SAMPLER = 0x02, - INTEL_USAGE_2D_TARGET = 0x04, - INTEL_USAGE_2D_SOURCE = 0x08, - /* use on vertex */ - INTEL_USAGE_VERTEX = 0x10 -}; - -enum intel_buffer_type -{ - INTEL_NEW_TEXTURE, - INTEL_NEW_SCANOUT, /**< a texture used for scanning out from */ - INTEL_NEW_VERTEX -}; - -enum intel_buffer_tile -{ - INTEL_TILE_NONE, - INTEL_TILE_X, - INTEL_TILE_Y -}; - -struct intel_batchbuffer { - - struct intel_winsys *iws; - - /** - * Values exported to speed up the writing the batchbuffer, - * instead of having to go trough a accesor function for - * each dword written. - */ - /*{@*/ - uint8_t *map; - uint8_t *ptr; - size_t size; - - size_t relocs; - size_t max_relocs; - /*@}*/ -}; - -struct intel_winsys { - - /** - * Batchbuffer functions. - */ - /*@{*/ - /** - * Create a new batchbuffer. - */ - struct intel_batchbuffer *(*batchbuffer_create)(struct intel_winsys *iws); - - /** - * Emit a relocation to a buffer. - * Target position in batchbuffer is the same as ptr. - * - * @batch - * @reloc buffer address to be inserted into target. - * @usage how is the hardware going to use the buffer. - * @offset add this to the reloc buffers address - * @target buffer where to write the address, null for batchbuffer. - */ - int (*batchbuffer_reloc)(struct intel_batchbuffer *batch, - struct intel_buffer *reloc, - enum intel_buffer_usage usage, - unsigned offset); - - /** - * Flush a bufferbatch. - */ - void (*batchbuffer_flush)(struct intel_batchbuffer *batch, - struct pipe_fence_handle **fence); - - /** - * Destroy a batchbuffer. - */ - void (*batchbuffer_destroy)(struct intel_batchbuffer *batch); - /*@}*/ - - - /** - * Buffer functions. - */ - /*@{*/ - /** - * Create a buffer. - */ - struct intel_buffer *(*buffer_create)(struct intel_winsys *iws, - unsigned size, unsigned alignment, - enum intel_buffer_type type); - - /** - * Creates a buffer from a handle. - * Used to implement pipe_screen::texture_from_handle. - * Also provides the stride information needed for the - * texture via the stride argument. - */ - struct intel_buffer *(*buffer_from_handle)(struct intel_winsys *iws, - struct winsys_handle *whandle, - unsigned *stride); - - /** - * Used to implement pipe_screen::texture_get_handle. - * The winsys might need the stride information. - */ - boolean (*buffer_get_handle)(struct intel_winsys *iws, - struct intel_buffer *buffer, - struct winsys_handle *whandle, - unsigned stride); - - /** - * Fence a buffer with a fence reg. - * Not to be confused with pipe_fence_handle. - */ - int (*buffer_set_fence_reg)(struct intel_winsys *iws, - struct intel_buffer *buffer, - unsigned stride, - enum intel_buffer_tile tile); - - /** - * Map a buffer. - */ - void *(*buffer_map)(struct intel_winsys *iws, - struct intel_buffer *buffer, - boolean write); - - /** - * Unmap a buffer. - */ - void (*buffer_unmap)(struct intel_winsys *iws, - struct intel_buffer *buffer); - - /** - * Write to a buffer. - * - * Arguments follows pipe_buffer_write. - */ - int (*buffer_write)(struct intel_winsys *iws, - struct intel_buffer *dst, - size_t offset, - size_t size, - const void *data); - - void (*buffer_destroy)(struct intel_winsys *iws, - struct intel_buffer *buffer); - /*@}*/ - - - /** - * Fence functions. - */ - /*@{*/ - /** - * Reference fence and set ptr to fence. - */ - void (*fence_reference)(struct intel_winsys *iws, - struct pipe_fence_handle **ptr, - struct pipe_fence_handle *fence); - - /** - * Check if a fence has finished. - */ - int (*fence_signalled)(struct intel_winsys *iws, - struct pipe_fence_handle *fence); - - /** - * Wait on a fence to finish. - */ - int (*fence_finish)(struct intel_winsys *iws, - struct pipe_fence_handle *fence); - /*@}*/ - - - /** - * Destroy the winsys. - */ - void (*destroy)(struct intel_winsys *iws); -}; - - -/** - * Create i915 pipe_screen. - */ -struct pipe_screen *i915_create_screen(struct intel_winsys *iws, unsigned pci_id); - - -#endif diff --git a/src/gallium/targets/SConscript b/src/gallium/targets/SConscript index 38645646883..a41496a5dd9 100644 --- a/src/gallium/targets/SConscript +++ b/src/gallium/targets/SConscript @@ -62,7 +62,7 @@ if env['dri']: 'dri-vmwgfx/SConscript', ]) - if 'intel' in env['winsys']: + if 'i915' in env['winsys']: SConscript([ 'dri-i915/SConscript', ]) diff --git a/src/gallium/targets/dri-i915/Makefile b/src/gallium/targets/dri-i915/Makefile index 822d4b57bbb..50a8e11e17c 100644 --- a/src/gallium/targets/dri-i915/Makefile +++ b/src/gallium/targets/dri-i915/Makefile @@ -5,7 +5,7 @@ LIBNAME = i915_dri.so PIPE_DRIVERS = \ $(TOP)/src/gallium/state_trackers/dri/drm/libdridrm.a \ - $(TOP)/src/gallium/winsys/i915/drm/libinteldrm.a \ + $(TOP)/src/gallium/winsys/i915/drm/libi915drm.a \ $(TOP)/src/gallium/drivers/trace/libtrace.a \ $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ $(TOP)/src/gallium/drivers/identity/libidentity.a \ diff --git a/src/gallium/targets/dri-i915/SConscript b/src/gallium/targets/dri-i915/SConscript index 8d4ecefbe1b..f6d1f934783 100644 --- a/src/gallium/targets/dri-i915/SConscript +++ b/src/gallium/targets/dri-i915/SConscript @@ -10,7 +10,7 @@ env.ParseConfig('pkg-config --cflags --libs libdrm_intel') env.Prepend(LIBS = [ st_dri, - inteldrm, + i915drm, i915, trace, mesa, diff --git a/src/gallium/targets/egl-i915/Makefile b/src/gallium/targets/egl-i915/Makefile index 6c2fc14d70f..efaf7b0bef9 100644 --- a/src/gallium/targets/egl-i915/Makefile +++ b/src/gallium/targets/egl-i915/Makefile @@ -6,7 +6,7 @@ EGL_DRIVER_SOURCES = dummy.c EGL_DRIVER_LIBS = -ldrm_intel EGL_DRIVER_PIPES = \ - $(TOP)/src/gallium/winsys/i915/drm/libinteldrm.a \ + $(TOP)/src/gallium/winsys/i915/drm/libi915drm.a \ $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ $(TOP)/src/gallium/drivers/trace/libtrace.a \ $(TOP)/src/gallium/drivers/i915/libi915.a diff --git a/src/gallium/targets/xorg-i915/Makefile b/src/gallium/targets/xorg-i915/Makefile index e2cffcd70b3..52a9e97b409 100644 --- a/src/gallium/targets/xorg-i915/Makefile +++ b/src/gallium/targets/xorg-i915/Makefile @@ -17,7 +17,7 @@ INCLUDES = \ LIBS = \ $(TOP)/src/gallium/state_trackers/xorg/libxorgtracker.a \ - $(TOP)/src/gallium/winsys/i915/drm/libinteldrm.a \ + $(TOP)/src/gallium/winsys/i915/drm/libi915drm.a \ $(TOP)/src/gallium/drivers/i915/libi915.a \ $(TOP)/src/gallium/drivers/trace/libtrace.a \ $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ diff --git a/src/gallium/winsys/SConscript b/src/gallium/winsys/SConscript index 90ca693eb68..3e7052c0e6f 100644 --- a/src/gallium/winsys/SConscript +++ b/src/gallium/winsys/SConscript @@ -16,7 +16,7 @@ if env['dri']: 'svga/drm/SConscript', ]) - if 'intel' in env['winsys']: + if 'i915' in env['winsys']: SConscript([ 'i915/drm/SConscript', ]) diff --git a/src/gallium/winsys/i915/drm/Makefile b/src/gallium/winsys/i915/drm/Makefile index 4aac3309aa7..a67b9e8a528 100644 --- a/src/gallium/winsys/i915/drm/Makefile +++ b/src/gallium/winsys/i915/drm/Makefile @@ -1,13 +1,13 @@ TOP = ../../../../.. include $(TOP)/configs/current -LIBNAME = inteldrm +LIBNAME = i915drm C_SOURCES = \ - intel_drm_batchbuffer.c \ - intel_drm_buffer.c \ - intel_drm_fence.c \ - intel_drm_api.c + i915_drm_batchbuffer.c \ + i915_drm_buffer.c \ + i915_drm_fence.c \ + i915_drm_api.c LIBRARY_INCLUDES = $(shell pkg-config libdrm --cflags-only-I) diff --git a/src/gallium/winsys/i915/drm/SConscript b/src/gallium/winsys/i915/drm/SConscript index b47b8add837..ba29ac72fe7 100644 --- a/src/gallium/winsys/i915/drm/SConscript +++ b/src/gallium/winsys/i915/drm/SConscript @@ -2,16 +2,16 @@ Import('*') env = env.Clone() -inteldrm_sources = [ - 'intel_drm_api.c', - 'intel_drm_batchbuffer.c', - 'intel_drm_buffer.c', - 'intel_drm_fence.c', +i915drm_sources = [ + 'i915_drm_api.c', + 'i915_drm_batchbuffer.c', + 'i915_drm_buffer.c', + 'i915_drm_fence.c', ] -inteldrm = env.ConvenienceLibrary( - target ='inteldrm', - source = inteldrm_sources, +i915drm = env.ConvenienceLibrary( + target ='i915drm', + source = i915drm_sources, ) -Export('inteldrm') +Export('i915drm') diff --git a/src/gallium/winsys/i915/drm/i915_drm_api.c b/src/gallium/winsys/i915/drm/i915_drm_api.c new file mode 100644 index 00000000000..6bb0aec1a67 --- /dev/null +++ b/src/gallium/winsys/i915/drm/i915_drm_api.c @@ -0,0 +1,109 @@ +#include + +#include "state_tracker/drm_api.h" + +#include "i915_drm_winsys.h" +#include "util/u_memory.h" + +#include "i915/i915_context.h" +#include "i915/i915_screen.h" + +#include "trace/tr_drm.h" + +/* + * Helper functions + */ + + +static void +i915_drm_get_device_id(unsigned int *device_id) +{ + char path[512]; + FILE *file; + void *shutup_gcc; + + /* + * FIXME: Fix this up to use a drm ioctl or whatever. + */ + + snprintf(path, sizeof(path), "/sys/class/drm/card0/device/device"); + file = fopen(path, "r"); + if (!file) { + return; + } + + shutup_gcc = fgets(path, sizeof(path), file); + (void) shutup_gcc; + sscanf(path, "%x", device_id); + fclose(file); +} + +static void +i915_drm_winsys_destroy(struct i915_winsys *iws) +{ + struct i915_drm_winsys *idws = i915_drm_winsys(iws); + + drm_intel_bufmgr_destroy(idws->pools.gem); + + FREE(idws); +} + +static struct pipe_screen * +i915_drm_create_screen(struct drm_api *api, int drmFD, + struct drm_create_screen_arg *arg) +{ + struct i915_drm_winsys *idws; + unsigned int deviceID; + + if (arg != NULL) { + switch(arg->mode) { + case DRM_CREATE_NORMAL: + break; + default: + return NULL; + } + } + + idws = CALLOC_STRUCT(i915_drm_winsys); + if (!idws) + return NULL; + + i915_drm_get_device_id(&deviceID); + + i915_drm_winsys_init_batchbuffer_functions(idws); + i915_drm_winsys_init_buffer_functions(idws); + i915_drm_winsys_init_fence_functions(idws); + + idws->fd = drmFD; + idws->id = deviceID; + idws->max_batch_size = 16 * 4096; + + idws->base.destroy = i915_drm_winsys_destroy; + + idws->pools.gem = drm_intel_bufmgr_gem_init(idws->fd, idws->max_batch_size); + drm_intel_bufmgr_gem_enable_reuse(idws->pools.gem); + + idws->dump_cmd = debug_get_bool_option("INTEL_DUMP_CMD", FALSE); + + return i915_create_screen(&idws->base, deviceID); +} + +static void +destroy(struct drm_api *api) +{ + +} + +struct drm_api intel_drm_api = +{ + .name = "i915", + .driver_name = "i915", + .create_screen = i915_drm_create_screen, + .destroy = destroy, +}; + +struct drm_api * +drm_api_create() +{ + return trace_drm_create(&intel_drm_api); +} diff --git a/src/gallium/winsys/i915/drm/i915_drm_batchbuffer.c b/src/gallium/winsys/i915/drm/i915_drm_batchbuffer.c new file mode 100644 index 00000000000..102f59dc541 --- /dev/null +++ b/src/gallium/winsys/i915/drm/i915_drm_batchbuffer.c @@ -0,0 +1,244 @@ + +#include "i915_drm_winsys.h" +#include "util/u_memory.h" + +#include "i915_drm.h" + +#define BATCH_RESERVED 16 + +#define INTEL_DEFAULT_RELOCS 100 +#define INTEL_MAX_RELOCS 400 + +#define INTEL_BATCH_NO_CLIPRECTS 0x1 +#define INTEL_BATCH_CLIPRECTS 0x2 + +#undef INTEL_RUN_SYNC +#undef INTEL_MAP_BATCHBUFFER +#undef INTEL_MAP_GTT +#define INTEL_ALWAYS_FLUSH + +struct i915_drm_batchbuffer +{ + struct i915_winsys_batchbuffer base; + + size_t actual_size; + + drm_intel_bo *bo; +}; + +static INLINE struct i915_drm_batchbuffer * +i915_drm_batchbuffer(struct i915_winsys_batchbuffer *batch) +{ + return (struct i915_drm_batchbuffer *)batch; +} + +static void +i915_drm_batchbuffer_reset(struct i915_drm_batchbuffer *batch) +{ + struct i915_drm_winsys *idws = i915_drm_winsys(batch->base.iws); + int ret; + + if (batch->bo) + drm_intel_bo_unreference(batch->bo); + batch->bo = drm_intel_bo_alloc(idws->pools.gem, + "gallium3d_batchbuffer", + batch->actual_size, + 4096); + +#ifdef INTEL_MAP_BATCHBUFFER +#ifdef INTEL_MAP_GTT + ret = drm_intel_gem_bo_map_gtt(batch->bo); +#else + ret = drm_intel_bo_map(batch->bo, TRUE); +#endif + assert(ret == 0); + batch->base.map = batch->bo->virtual; +#else + (void)ret; +#endif + + memset(batch->base.map, 0, batch->actual_size); + batch->base.ptr = batch->base.map; + batch->base.size = batch->actual_size - BATCH_RESERVED; + batch->base.relocs = 0; +} + +static struct i915_winsys_batchbuffer * +i915_drm_batchbuffer_create(struct i915_winsys *iws) +{ + struct i915_drm_winsys *idws = i915_drm_winsys(iws); + struct i915_drm_batchbuffer *batch = CALLOC_STRUCT(i915_drm_batchbuffer); + + batch->actual_size = idws->max_batch_size; + +#ifdef INTEL_MAP_BATCHBUFFER + batch->base.map = NULL; +#else + batch->base.map = MALLOC(batch->actual_size); +#endif + batch->base.ptr = NULL; + batch->base.size = 0; + + batch->base.relocs = 0; + batch->base.max_relocs = 300;/*INTEL_DEFAULT_RELOCS;*/ + + batch->base.iws = iws; + + i915_drm_batchbuffer_reset(batch); + + return &batch->base; +} + +static int +i915_drm_batchbuffer_reloc(struct i915_winsys_batchbuffer *ibatch, + struct i915_winsys_buffer *buffer, + enum i915_winsys_buffer_usage usage, + unsigned pre_add) +{ + struct i915_drm_batchbuffer *batch = i915_drm_batchbuffer(ibatch); + unsigned write_domain = 0; + unsigned read_domain = 0; + unsigned offset; + int ret = 0; + + assert(batch->base.relocs < batch->base.max_relocs); + + if (usage == I915_USAGE_SAMPLER) { + write_domain = 0; + read_domain = I915_GEM_DOMAIN_SAMPLER; + + } else if (usage == I915_USAGE_RENDER) { + write_domain = I915_GEM_DOMAIN_RENDER; + read_domain = I915_GEM_DOMAIN_RENDER; + + } else if (usage == I915_USAGE_2D_TARGET) { + write_domain = I915_GEM_DOMAIN_RENDER; + read_domain = I915_GEM_DOMAIN_RENDER; + + } else if (usage == I915_USAGE_2D_SOURCE) { + write_domain = 0; + read_domain = I915_GEM_DOMAIN_RENDER; + + } else if (usage == I915_USAGE_VERTEX) { + write_domain = 0; + read_domain = I915_GEM_DOMAIN_VERTEX; + + } else { + assert(0); + return -1; + } + + offset = (unsigned)(batch->base.ptr - batch->base.map); + + ret = drm_intel_bo_emit_reloc(batch->bo, offset, + intel_bo(buffer), pre_add, + read_domain, + write_domain); + + ((uint32_t*)batch->base.ptr)[0] = intel_bo(buffer)->offset + pre_add; + batch->base.ptr += 4; + + if (!ret) + batch->base.relocs++; + + return ret; +} + +static void +i915_drm_batchbuffer_flush(struct i915_winsys_batchbuffer *ibatch, + struct pipe_fence_handle **fence) +{ + struct i915_drm_batchbuffer *batch = i915_drm_batchbuffer(ibatch); + unsigned used = 0; + int ret = 0; + int i; + + assert(i915_winsys_batchbuffer_space(ibatch) >= 0); + + used = batch->base.ptr - batch->base.map; + assert((used & 3) == 0); + + +#ifdef INTEL_ALWAYS_FLUSH + /* MI_FLUSH | FLUSH_MAP_CACHE */ + i915_winsys_batchbuffer_dword(ibatch, (0x4<<23)|(1<<0)); + used += 4; +#endif + + if ((used & 4) == 0) { + /* MI_NOOP */ + i915_winsys_batchbuffer_dword(ibatch, 0); + } + /* MI_BATCH_BUFFER_END */ + i915_winsys_batchbuffer_dword(ibatch, (0xA<<23)); + + used = batch->base.ptr - batch->base.map; + assert((used & 4) == 0); + +#ifdef INTEL_MAP_BATCHBUFFER +#ifdef INTEL_MAP_GTT + drm_intel_gem_bo_unmap_gtt(batch->bo); +#else + drm_intel_bo_unmap(batch->bo); +#endif +#else + drm_intel_bo_subdata(batch->bo, 0, used, batch->base.map); +#endif + + /* Do the sending to HW */ + ret = drm_intel_bo_exec(batch->bo, used, NULL, 0, 0); + assert(ret == 0); + + if (i915_drm_winsys(ibatch->iws)->dump_cmd) { + unsigned *ptr; + drm_intel_bo_map(batch->bo, FALSE); + ptr = (unsigned*)batch->bo->virtual; + + debug_printf("%s:\n", __func__); + for (i = 0; i < used / 4; i++, ptr++) { + debug_printf("\t%08x: %08x\n", i*4, *ptr); + } + + drm_intel_bo_unmap(batch->bo); + } else { +#ifdef INTEL_RUN_SYNC + drm_intel_bo_map(batch->bo, FALSE); + drm_intel_bo_unmap(batch->bo); +#endif + } + + if (fence) { + ibatch->iws->fence_reference(ibatch->iws, fence, NULL); + +#ifdef INTEL_RUN_SYNC + /* we run synced to GPU so just pass null */ + (*fence) = i915_drm_fence_create(NULL); +#else + (*fence) = i915_drm_fence_create(batch->bo); +#endif + } + + i915_drm_batchbuffer_reset(batch); +} + +static void +i915_drm_batchbuffer_destroy(struct i915_winsys_batchbuffer *ibatch) +{ + struct i915_drm_batchbuffer *batch = i915_drm_batchbuffer(ibatch); + + if (batch->bo) + drm_intel_bo_unreference(batch->bo); + +#ifndef INTEL_MAP_BATCHBUFFER + FREE(batch->base.map); +#endif + FREE(batch); +} + +void i915_drm_winsys_init_batchbuffer_functions(struct i915_drm_winsys *idws) +{ + idws->base.batchbuffer_create = i915_drm_batchbuffer_create; + idws->base.batchbuffer_reloc = i915_drm_batchbuffer_reloc; + idws->base.batchbuffer_flush = i915_drm_batchbuffer_flush; + idws->base.batchbuffer_destroy = i915_drm_batchbuffer_destroy; +} diff --git a/src/gallium/winsys/i915/drm/i915_drm_buffer.c b/src/gallium/winsys/i915/drm/i915_drm_buffer.c new file mode 100644 index 00000000000..3bd85026b21 --- /dev/null +++ b/src/gallium/winsys/i915/drm/i915_drm_buffer.c @@ -0,0 +1,217 @@ + +#include "state_tracker/drm_api.h" +#include "i915_drm_winsys.h" +#include "util/u_memory.h" + +#include "i915_drm.h" + +static struct i915_winsys_buffer * +i915_drm_buffer_create(struct i915_winsys *iws, + unsigned size, unsigned alignment, + enum i915_winsys_buffer_type type) +{ + struct i915_drm_buffer *buf = CALLOC_STRUCT(i915_drm_buffer); + struct i915_drm_winsys *idws = i915_drm_winsys(iws); + drm_intel_bufmgr *pool; + char *name; + + if (!buf) + return NULL; + + buf->magic = 0xDEAD1337; + buf->flinked = FALSE; + buf->flink = 0; + buf->map_gtt = FALSE; + + if (type == I915_NEW_TEXTURE) { + name = "gallium3d_texture"; + pool = idws->pools.gem; + } else if (type == I915_NEW_VERTEX) { + name = "gallium3d_vertex"; + pool = idws->pools.gem; + buf->map_gtt = TRUE; + } else if (type == I915_NEW_SCANOUT) { + name = "gallium3d_scanout"; + pool = idws->pools.gem; + buf->map_gtt = TRUE; + } else { + assert(0); + name = "gallium3d_unknown"; + pool = idws->pools.gem; + } + + buf->bo = drm_intel_bo_alloc(pool, name, size, alignment); + + if (!buf->bo) + goto err; + + return (struct i915_winsys_buffer *)buf; + +err: + assert(0); + FREE(buf); + return NULL; +} + +static struct i915_winsys_buffer * +i915_drm_buffer_from_handle(struct i915_winsys *iws, + struct winsys_handle *whandle, + unsigned *stride) +{ + struct i915_drm_winsys *idws = i915_drm_winsys(iws); + struct i915_drm_buffer *buf = CALLOC_STRUCT(i915_drm_buffer); + uint32_t tile = 0, swizzle = 0; + + if (!buf) + return NULL; + + buf->magic = 0xDEAD1337; + buf->bo = drm_intel_bo_gem_create_from_name(idws->pools.gem, "gallium3d_from_handle", whandle->handle); + buf->flinked = TRUE; + buf->flink = whandle->handle; + + if (!buf->bo) + goto err; + + drm_intel_bo_get_tiling(buf->bo, &tile, &swizzle); + if (tile != I915_TILE_NONE) + buf->map_gtt = TRUE; + + *stride = whandle->stride; + + return (struct i915_winsys_buffer *)buf; + +err: + FREE(buf); + return NULL; +} + +static boolean +i915_drm_buffer_get_handle(struct i915_winsys *iws, + struct i915_winsys_buffer *buffer, + struct winsys_handle *whandle, + unsigned stride) +{ + struct i915_drm_buffer *buf = i915_drm_buffer(buffer); + + if (whandle->type == DRM_API_HANDLE_TYPE_SHARED) { + if (!buf->flinked) { + if (drm_intel_bo_flink(buf->bo, &buf->flink)) + return FALSE; + buf->flinked = TRUE; + } + + whandle->handle = buf->flink; + } else if (whandle->type == DRM_API_HANDLE_TYPE_KMS) { + whandle->handle = buf->bo->handle; + } else { + assert(!"unknown usage"); + return FALSE; + } + + whandle->stride = stride; + return TRUE; +} + +static int +i915_drm_buffer_set_fence_reg(struct i915_winsys *iws, + struct i915_winsys_buffer *buffer, + unsigned stride, + enum i915_winsys_buffer_tile tile) +{ + struct i915_drm_buffer *buf = i915_drm_buffer(buffer); + assert(I915_TILING_NONE == I915_TILE_NONE); + assert(I915_TILING_X == I915_TILE_X); + assert(I915_TILING_Y == I915_TILE_Y); + + if (tile != I915_TILE_NONE) { + assert(buf->map_count == 0); + buf->map_gtt = TRUE; + } + + return drm_intel_bo_set_tiling(buf->bo, &tile, stride); +} + +static void * +i915_drm_buffer_map(struct i915_winsys *iws, + struct i915_winsys_buffer *buffer, + boolean write) +{ + struct i915_drm_buffer *buf = i915_drm_buffer(buffer); + drm_intel_bo *bo = intel_bo(buffer); + int ret = 0; + + assert(bo); + + if (buf->map_count) + goto out; + + if (buf->map_gtt) + ret = drm_intel_gem_bo_map_gtt(bo); + else + ret = drm_intel_bo_map(bo, write); + + buf->ptr = bo->virtual; + + assert(ret == 0); +out: + if (ret) + return NULL; + + buf->map_count++; + return buf->ptr; +} + +static void +i915_drm_buffer_unmap(struct i915_winsys *iws, + struct i915_winsys_buffer *buffer) +{ + struct i915_drm_buffer *buf = i915_drm_buffer(buffer); + + if (--buf->map_count) + return; + + if (buf->map_gtt) + drm_intel_gem_bo_unmap_gtt(intel_bo(buffer)); + else + drm_intel_bo_unmap(intel_bo(buffer)); +} + +static int +i915_drm_buffer_write(struct i915_winsys *iws, + struct i915_winsys_buffer *buffer, + size_t offset, + size_t size, + const void *data) +{ + struct i915_drm_buffer *buf = i915_drm_buffer(buffer); + + return drm_intel_bo_subdata(buf->bo, offset, size, (void*)data); +} + +static void +i915_drm_buffer_destroy(struct i915_winsys *iws, + struct i915_winsys_buffer *buffer) +{ + drm_intel_bo_unreference(intel_bo(buffer)); + +#ifdef DEBUG + i915_drm_buffer(buffer)->magic = 0; + i915_drm_buffer(buffer)->bo = NULL; +#endif + + FREE(buffer); +} + +void +i915_drm_winsys_init_buffer_functions(struct i915_drm_winsys *idws) +{ + idws->base.buffer_create = i915_drm_buffer_create; + idws->base.buffer_from_handle = i915_drm_buffer_from_handle; + idws->base.buffer_get_handle = i915_drm_buffer_get_handle; + idws->base.buffer_set_fence_reg = i915_drm_buffer_set_fence_reg; + idws->base.buffer_map = i915_drm_buffer_map; + idws->base.buffer_unmap = i915_drm_buffer_unmap; + idws->base.buffer_write = i915_drm_buffer_write; + idws->base.buffer_destroy = i915_drm_buffer_destroy; +} diff --git a/src/gallium/winsys/i915/drm/i915_drm_fence.c b/src/gallium/winsys/i915/drm/i915_drm_fence.c new file mode 100644 index 00000000000..30ebf4835ea --- /dev/null +++ b/src/gallium/winsys/i915/drm/i915_drm_fence.c @@ -0,0 +1,83 @@ + +#include "i915_drm_winsys.h" +#include "util/u_memory.h" +#include "util/u_atomic.h" +#include "util/u_inlines.h" + +/** + * Because gem does not have fence's we have to create our own fences. + * + * They work by keeping the batchbuffer around and checking if that has + * been idled. If bo is NULL fence has expired. + */ +struct i915_drm_fence +{ + struct pipe_reference reference; + drm_intel_bo *bo; +}; + + +struct pipe_fence_handle * +i915_drm_fence_create(drm_intel_bo *bo) +{ + struct i915_drm_fence *fence = CALLOC_STRUCT(i915_drm_fence); + + pipe_reference_init(&fence->reference, 1); + /* bo is null if fence already expired */ + if (bo) { + drm_intel_bo_reference(bo); + fence->bo = bo; + } + + return (struct pipe_fence_handle *)fence; +} + +static void +i915_drm_fence_reference(struct i915_winsys *iws, + struct pipe_fence_handle **ptr, + struct pipe_fence_handle *fence) +{ + struct i915_drm_fence *old = (struct i915_drm_fence *)*ptr; + struct i915_drm_fence *f = (struct i915_drm_fence *)fence; + + if (pipe_reference(&((struct i915_drm_fence *)(*ptr))->reference, &f->reference)) { + if (old->bo) + drm_intel_bo_unreference(old->bo); + FREE(old); + } + *ptr = fence; +} + +static int +i915_drm_fence_signalled(struct i915_winsys *iws, + struct pipe_fence_handle *fence) +{ + assert(0); + + return 0; +} + +static int +i915_drm_fence_finish(struct i915_winsys *iws, + struct pipe_fence_handle *fence) +{ + struct i915_drm_fence *f = (struct i915_drm_fence *)fence; + + /* fence already expired */ + if (!f->bo) + return 0; + + drm_intel_bo_wait_rendering(f->bo); + drm_intel_bo_unreference(f->bo); + f->bo = NULL; + + return 0; +} + +void +i915_drm_winsys_init_fence_functions(struct i915_drm_winsys *idws) +{ + idws->base.fence_reference = i915_drm_fence_reference; + idws->base.fence_signalled = i915_drm_fence_signalled; + idws->base.fence_finish = i915_drm_fence_finish; +} diff --git a/src/gallium/winsys/i915/drm/i915_drm_winsys.h b/src/gallium/winsys/i915/drm/i915_drm_winsys.h new file mode 100644 index 00000000000..217c4a7eafb --- /dev/null +++ b/src/gallium/winsys/i915/drm/i915_drm_winsys.h @@ -0,0 +1,77 @@ + +#ifndef INTEL_DRM_WINSYS_H +#define INTEL_DRM_WINSYS_H + +#include "i915/i915_batchbuffer.h" + +#include "drm.h" +#include "intel_bufmgr.h" + + +/* + * Winsys + */ + + +struct i915_drm_winsys +{ + struct i915_winsys base; + + boolean dump_cmd; + + int fd; /**< Drm file discriptor */ + + unsigned id; + + size_t max_batch_size; + + struct { + drm_intel_bufmgr *gem; + } pools; +}; + +static INLINE struct i915_drm_winsys * +i915_drm_winsys(struct i915_winsys *iws) +{ + return (struct i915_drm_winsys *)iws; +} + +struct i915_drm_winsys * i915_drm_winsys_create(int fd, unsigned pci_id); +struct pipe_fence_handle * i915_drm_fence_create(drm_intel_bo *bo); + +void i915_drm_winsys_init_batchbuffer_functions(struct i915_drm_winsys *idws); +void i915_drm_winsys_init_buffer_functions(struct i915_drm_winsys *idws); +void i915_drm_winsys_init_fence_functions(struct i915_drm_winsys *idws); + + +/* + * Buffer + */ + + +struct i915_drm_buffer { + unsigned magic; + + drm_intel_bo *bo; + + void *ptr; + unsigned map_count; + boolean map_gtt; + + boolean flinked; + unsigned flink; +}; + +static INLINE struct i915_drm_buffer * +i915_drm_buffer(struct i915_winsys_buffer *buffer) +{ + return (struct i915_drm_buffer *)buffer; +} + +static INLINE drm_intel_bo * +intel_bo(struct i915_winsys_buffer *buffer) +{ + return i915_drm_buffer(buffer)->bo; +} + +#endif diff --git a/src/gallium/winsys/i915/drm/intel_drm_api.c b/src/gallium/winsys/i915/drm/intel_drm_api.c deleted file mode 100644 index e3b980a832b..00000000000 --- a/src/gallium/winsys/i915/drm/intel_drm_api.c +++ /dev/null @@ -1,109 +0,0 @@ -#include - -#include "state_tracker/drm_api.h" - -#include "intel_drm_winsys.h" -#include "util/u_memory.h" - -#include "i915/i915_context.h" -#include "i915/i915_screen.h" - -#include "trace/tr_drm.h" - -/* - * Helper functions - */ - - -static void -intel_drm_get_device_id(unsigned int *device_id) -{ - char path[512]; - FILE *file; - void *shutup_gcc; - - /* - * FIXME: Fix this up to use a drm ioctl or whatever. - */ - - snprintf(path, sizeof(path), "/sys/class/drm/card0/device/device"); - file = fopen(path, "r"); - if (!file) { - return; - } - - shutup_gcc = fgets(path, sizeof(path), file); - (void) shutup_gcc; - sscanf(path, "%x", device_id); - fclose(file); -} - -static void -intel_drm_winsys_destroy(struct intel_winsys *iws) -{ - struct intel_drm_winsys *idws = intel_drm_winsys(iws); - - drm_intel_bufmgr_destroy(idws->pools.gem); - - FREE(idws); -} - -static struct pipe_screen * -intel_drm_create_screen(struct drm_api *api, int drmFD, - struct drm_create_screen_arg *arg) -{ - struct intel_drm_winsys *idws; - unsigned int deviceID; - - if (arg != NULL) { - switch(arg->mode) { - case DRM_CREATE_NORMAL: - break; - default: - return NULL; - } - } - - idws = CALLOC_STRUCT(intel_drm_winsys); - if (!idws) - return NULL; - - intel_drm_get_device_id(&deviceID); - - intel_drm_winsys_init_batchbuffer_functions(idws); - intel_drm_winsys_init_buffer_functions(idws); - intel_drm_winsys_init_fence_functions(idws); - - idws->fd = drmFD; - idws->id = deviceID; - idws->max_batch_size = 16 * 4096; - - idws->base.destroy = intel_drm_winsys_destroy; - - idws->pools.gem = drm_intel_bufmgr_gem_init(idws->fd, idws->max_batch_size); - drm_intel_bufmgr_gem_enable_reuse(idws->pools.gem); - - idws->dump_cmd = debug_get_bool_option("INTEL_DUMP_CMD", FALSE); - - return i915_create_screen(&idws->base, deviceID); -} - -static void -destroy(struct drm_api *api) -{ - -} - -struct drm_api intel_drm_api = -{ - .name = "i915", - .driver_name = "i915", - .create_screen = intel_drm_create_screen, - .destroy = destroy, -}; - -struct drm_api * -drm_api_create() -{ - return trace_drm_create(&intel_drm_api); -} diff --git a/src/gallium/winsys/i915/drm/intel_drm_batchbuffer.c b/src/gallium/winsys/i915/drm/intel_drm_batchbuffer.c deleted file mode 100644 index 5b4dafc8e41..00000000000 --- a/src/gallium/winsys/i915/drm/intel_drm_batchbuffer.c +++ /dev/null @@ -1,244 +0,0 @@ - -#include "intel_drm_winsys.h" -#include "util/u_memory.h" - -#include "i915_drm.h" - -#define BATCH_RESERVED 16 - -#define INTEL_DEFAULT_RELOCS 100 -#define INTEL_MAX_RELOCS 400 - -#define INTEL_BATCH_NO_CLIPRECTS 0x1 -#define INTEL_BATCH_CLIPRECTS 0x2 - -#undef INTEL_RUN_SYNC -#undef INTEL_MAP_BATCHBUFFER -#undef INTEL_MAP_GTT -#define INTEL_ALWAYS_FLUSH - -struct intel_drm_batchbuffer -{ - struct intel_batchbuffer base; - - size_t actual_size; - - drm_intel_bo *bo; -}; - -static INLINE struct intel_drm_batchbuffer * -intel_drm_batchbuffer(struct intel_batchbuffer *batch) -{ - return (struct intel_drm_batchbuffer *)batch; -} - -static void -intel_drm_batchbuffer_reset(struct intel_drm_batchbuffer *batch) -{ - struct intel_drm_winsys *idws = intel_drm_winsys(batch->base.iws); - int ret; - - if (batch->bo) - drm_intel_bo_unreference(batch->bo); - batch->bo = drm_intel_bo_alloc(idws->pools.gem, - "gallium3d_batchbuffer", - batch->actual_size, - 4096); - -#ifdef INTEL_MAP_BATCHBUFFER -#ifdef INTEL_MAP_GTT - ret = drm_intel_gem_bo_map_gtt(batch->bo); -#else - ret = drm_intel_bo_map(batch->bo, TRUE); -#endif - assert(ret == 0); - batch->base.map = batch->bo->virtual; -#else - (void)ret; -#endif - - memset(batch->base.map, 0, batch->actual_size); - batch->base.ptr = batch->base.map; - batch->base.size = batch->actual_size - BATCH_RESERVED; - batch->base.relocs = 0; -} - -static struct intel_batchbuffer * -intel_drm_batchbuffer_create(struct intel_winsys *iws) -{ - struct intel_drm_winsys *idws = intel_drm_winsys(iws); - struct intel_drm_batchbuffer *batch = CALLOC_STRUCT(intel_drm_batchbuffer); - - batch->actual_size = idws->max_batch_size; - -#ifdef INTEL_MAP_BATCHBUFFER - batch->base.map = NULL; -#else - batch->base.map = MALLOC(batch->actual_size); -#endif - batch->base.ptr = NULL; - batch->base.size = 0; - - batch->base.relocs = 0; - batch->base.max_relocs = 300;/*INTEL_DEFAULT_RELOCS;*/ - - batch->base.iws = iws; - - intel_drm_batchbuffer_reset(batch); - - return &batch->base; -} - -static int -intel_drm_batchbuffer_reloc(struct intel_batchbuffer *ibatch, - struct intel_buffer *buffer, - enum intel_buffer_usage usage, - unsigned pre_add) -{ - struct intel_drm_batchbuffer *batch = intel_drm_batchbuffer(ibatch); - unsigned write_domain = 0; - unsigned read_domain = 0; - unsigned offset; - int ret = 0; - - assert(batch->base.relocs < batch->base.max_relocs); - - if (usage == INTEL_USAGE_SAMPLER) { - write_domain = 0; - read_domain = I915_GEM_DOMAIN_SAMPLER; - - } else if (usage == INTEL_USAGE_RENDER) { - write_domain = I915_GEM_DOMAIN_RENDER; - read_domain = I915_GEM_DOMAIN_RENDER; - - } else if (usage == INTEL_USAGE_2D_TARGET) { - write_domain = I915_GEM_DOMAIN_RENDER; - read_domain = I915_GEM_DOMAIN_RENDER; - - } else if (usage == INTEL_USAGE_2D_SOURCE) { - write_domain = 0; - read_domain = I915_GEM_DOMAIN_RENDER; - - } else if (usage == INTEL_USAGE_VERTEX) { - write_domain = 0; - read_domain = I915_GEM_DOMAIN_VERTEX; - - } else { - assert(0); - return -1; - } - - offset = (unsigned)(batch->base.ptr - batch->base.map); - - ret = drm_intel_bo_emit_reloc(batch->bo, offset, - intel_bo(buffer), pre_add, - read_domain, - write_domain); - - ((uint32_t*)batch->base.ptr)[0] = intel_bo(buffer)->offset + pre_add; - batch->base.ptr += 4; - - if (!ret) - batch->base.relocs++; - - return ret; -} - -static void -intel_drm_batchbuffer_flush(struct intel_batchbuffer *ibatch, - struct pipe_fence_handle **fence) -{ - struct intel_drm_batchbuffer *batch = intel_drm_batchbuffer(ibatch); - unsigned used = 0; - int ret = 0; - int i; - - assert(intel_batchbuffer_space(ibatch) >= 0); - - used = batch->base.ptr - batch->base.map; - assert((used & 3) == 0); - - -#ifdef INTEL_ALWAYS_FLUSH - /* MI_FLUSH | FLUSH_MAP_CACHE */ - intel_batchbuffer_dword(ibatch, (0x4<<23)|(1<<0)); - used += 4; -#endif - - if ((used & 4) == 0) { - /* MI_NOOP */ - intel_batchbuffer_dword(ibatch, 0); - } - /* MI_BATCH_BUFFER_END */ - intel_batchbuffer_dword(ibatch, (0xA<<23)); - - used = batch->base.ptr - batch->base.map; - assert((used & 4) == 0); - -#ifdef INTEL_MAP_BATCHBUFFER -#ifdef INTEL_MAP_GTT - drm_intel_gem_bo_unmap_gtt(batch->bo); -#else - drm_intel_bo_unmap(batch->bo); -#endif -#else - drm_intel_bo_subdata(batch->bo, 0, used, batch->base.map); -#endif - - /* Do the sending to HW */ - ret = drm_intel_bo_exec(batch->bo, used, NULL, 0, 0); - assert(ret == 0); - - if (intel_drm_winsys(ibatch->iws)->dump_cmd) { - unsigned *ptr; - drm_intel_bo_map(batch->bo, FALSE); - ptr = (unsigned*)batch->bo->virtual; - - debug_printf("%s:\n", __func__); - for (i = 0; i < used / 4; i++, ptr++) { - debug_printf("\t%08x: %08x\n", i*4, *ptr); - } - - drm_intel_bo_unmap(batch->bo); - } else { -#ifdef INTEL_RUN_SYNC - drm_intel_bo_map(batch->bo, FALSE); - drm_intel_bo_unmap(batch->bo); -#endif - } - - if (fence) { - ibatch->iws->fence_reference(ibatch->iws, fence, NULL); - -#ifdef INTEL_RUN_SYNC - /* we run synced to GPU so just pass null */ - (*fence) = intel_drm_fence_create(NULL); -#else - (*fence) = intel_drm_fence_create(batch->bo); -#endif - } - - intel_drm_batchbuffer_reset(batch); -} - -static void -intel_drm_batchbuffer_destroy(struct intel_batchbuffer *ibatch) -{ - struct intel_drm_batchbuffer *batch = intel_drm_batchbuffer(ibatch); - - if (batch->bo) - drm_intel_bo_unreference(batch->bo); - -#ifndef INTEL_MAP_BATCHBUFFER - FREE(batch->base.map); -#endif - FREE(batch); -} - -void intel_drm_winsys_init_batchbuffer_functions(struct intel_drm_winsys *idws) -{ - idws->base.batchbuffer_create = intel_drm_batchbuffer_create; - idws->base.batchbuffer_reloc = intel_drm_batchbuffer_reloc; - idws->base.batchbuffer_flush = intel_drm_batchbuffer_flush; - idws->base.batchbuffer_destroy = intel_drm_batchbuffer_destroy; -} diff --git a/src/gallium/winsys/i915/drm/intel_drm_buffer.c b/src/gallium/winsys/i915/drm/intel_drm_buffer.c deleted file mode 100644 index cb4f92a3b17..00000000000 --- a/src/gallium/winsys/i915/drm/intel_drm_buffer.c +++ /dev/null @@ -1,217 +0,0 @@ - -#include "state_tracker/drm_api.h" -#include "intel_drm_winsys.h" -#include "util/u_memory.h" - -#include "i915_drm.h" - -static struct intel_buffer * -intel_drm_buffer_create(struct intel_winsys *iws, - unsigned size, unsigned alignment, - enum intel_buffer_type type) -{ - struct intel_drm_buffer *buf = CALLOC_STRUCT(intel_drm_buffer); - struct intel_drm_winsys *idws = intel_drm_winsys(iws); - drm_intel_bufmgr *pool; - char *name; - - if (!buf) - return NULL; - - buf->magic = 0xDEAD1337; - buf->flinked = FALSE; - buf->flink = 0; - buf->map_gtt = FALSE; - - if (type == INTEL_NEW_TEXTURE) { - name = "gallium3d_texture"; - pool = idws->pools.gem; - } else if (type == INTEL_NEW_VERTEX) { - name = "gallium3d_vertex"; - pool = idws->pools.gem; - buf->map_gtt = TRUE; - } else if (type == INTEL_NEW_SCANOUT) { - name = "gallium3d_scanout"; - pool = idws->pools.gem; - buf->map_gtt = TRUE; - } else { - assert(0); - name = "gallium3d_unknown"; - pool = idws->pools.gem; - } - - buf->bo = drm_intel_bo_alloc(pool, name, size, alignment); - - if (!buf->bo) - goto err; - - return (struct intel_buffer *)buf; - -err: - assert(0); - FREE(buf); - return NULL; -} - -static struct intel_buffer * -intel_drm_buffer_from_handle(struct intel_winsys *iws, - struct winsys_handle *whandle, - unsigned *stride) -{ - struct intel_drm_winsys *idws = intel_drm_winsys(iws); - struct intel_drm_buffer *buf = CALLOC_STRUCT(intel_drm_buffer); - uint32_t tile = 0, swizzle = 0; - - if (!buf) - return NULL; - - buf->magic = 0xDEAD1337; - buf->bo = drm_intel_bo_gem_create_from_name(idws->pools.gem, "gallium3d_from_handle", whandle->handle); - buf->flinked = TRUE; - buf->flink = whandle->handle; - - if (!buf->bo) - goto err; - - drm_intel_bo_get_tiling(buf->bo, &tile, &swizzle); - if (tile != INTEL_TILE_NONE) - buf->map_gtt = TRUE; - - *stride = whandle->stride; - - return (struct intel_buffer *)buf; - -err: - FREE(buf); - return NULL; -} - -static boolean -intel_drm_buffer_get_handle(struct intel_winsys *iws, - struct intel_buffer *buffer, - struct winsys_handle *whandle, - unsigned stride) -{ - struct intel_drm_buffer *buf = intel_drm_buffer(buffer); - - if (whandle->type == DRM_API_HANDLE_TYPE_SHARED) { - if (!buf->flinked) { - if (drm_intel_bo_flink(buf->bo, &buf->flink)) - return FALSE; - buf->flinked = TRUE; - } - - whandle->handle = buf->flink; - } else if (whandle->type == DRM_API_HANDLE_TYPE_KMS) { - whandle->handle = buf->bo->handle; - } else { - assert(!"unknown usage"); - return FALSE; - } - - whandle->stride = stride; - return TRUE; -} - -static int -intel_drm_buffer_set_fence_reg(struct intel_winsys *iws, - struct intel_buffer *buffer, - unsigned stride, - enum intel_buffer_tile tile) -{ - struct intel_drm_buffer *buf = intel_drm_buffer(buffer); - assert(I915_TILING_NONE == INTEL_TILE_NONE); - assert(I915_TILING_X == INTEL_TILE_X); - assert(I915_TILING_Y == INTEL_TILE_Y); - - if (tile != INTEL_TILE_NONE) { - assert(buf->map_count == 0); - buf->map_gtt = TRUE; - } - - return drm_intel_bo_set_tiling(buf->bo, &tile, stride); -} - -static void * -intel_drm_buffer_map(struct intel_winsys *iws, - struct intel_buffer *buffer, - boolean write) -{ - struct intel_drm_buffer *buf = intel_drm_buffer(buffer); - drm_intel_bo *bo = intel_bo(buffer); - int ret = 0; - - assert(bo); - - if (buf->map_count) - goto out; - - if (buf->map_gtt) - ret = drm_intel_gem_bo_map_gtt(bo); - else - ret = drm_intel_bo_map(bo, write); - - buf->ptr = bo->virtual; - - assert(ret == 0); -out: - if (ret) - return NULL; - - buf->map_count++; - return buf->ptr; -} - -static void -intel_drm_buffer_unmap(struct intel_winsys *iws, - struct intel_buffer *buffer) -{ - struct intel_drm_buffer *buf = intel_drm_buffer(buffer); - - if (--buf->map_count) - return; - - if (buf->map_gtt) - drm_intel_gem_bo_unmap_gtt(intel_bo(buffer)); - else - drm_intel_bo_unmap(intel_bo(buffer)); -} - -static int -intel_drm_buffer_write(struct intel_winsys *iws, - struct intel_buffer *buffer, - size_t offset, - size_t size, - const void *data) -{ - struct intel_drm_buffer *buf = intel_drm_buffer(buffer); - - return drm_intel_bo_subdata(buf->bo, offset, size, (void*)data); -} - -static void -intel_drm_buffer_destroy(struct intel_winsys *iws, - struct intel_buffer *buffer) -{ - drm_intel_bo_unreference(intel_bo(buffer)); - -#ifdef DEBUG - intel_drm_buffer(buffer)->magic = 0; - intel_drm_buffer(buffer)->bo = NULL; -#endif - - FREE(buffer); -} - -void -intel_drm_winsys_init_buffer_functions(struct intel_drm_winsys *idws) -{ - idws->base.buffer_create = intel_drm_buffer_create; - idws->base.buffer_from_handle = intel_drm_buffer_from_handle; - idws->base.buffer_get_handle = intel_drm_buffer_get_handle; - idws->base.buffer_set_fence_reg = intel_drm_buffer_set_fence_reg; - idws->base.buffer_map = intel_drm_buffer_map; - idws->base.buffer_unmap = intel_drm_buffer_unmap; - idws->base.buffer_write = intel_drm_buffer_write; - idws->base.buffer_destroy = intel_drm_buffer_destroy; -} diff --git a/src/gallium/winsys/i915/drm/intel_drm_fence.c b/src/gallium/winsys/i915/drm/intel_drm_fence.c deleted file mode 100644 index 102faedfeae..00000000000 --- a/src/gallium/winsys/i915/drm/intel_drm_fence.c +++ /dev/null @@ -1,83 +0,0 @@ - -#include "intel_drm_winsys.h" -#include "util/u_memory.h" -#include "util/u_atomic.h" -#include "util/u_inlines.h" - -/** - * Because gem does not have fence's we have to create our own fences. - * - * They work by keeping the batchbuffer around and checking if that has - * been idled. If bo is NULL fence has expired. - */ -struct intel_drm_fence -{ - struct pipe_reference reference; - drm_intel_bo *bo; -}; - - -struct pipe_fence_handle * -intel_drm_fence_create(drm_intel_bo *bo) -{ - struct intel_drm_fence *fence = CALLOC_STRUCT(intel_drm_fence); - - pipe_reference_init(&fence->reference, 1); - /* bo is null if fence already expired */ - if (bo) { - drm_intel_bo_reference(bo); - fence->bo = bo; - } - - return (struct pipe_fence_handle *)fence; -} - -static void -intel_drm_fence_reference(struct intel_winsys *iws, - struct pipe_fence_handle **ptr, - struct pipe_fence_handle *fence) -{ - struct intel_drm_fence *old = (struct intel_drm_fence *)*ptr; - struct intel_drm_fence *f = (struct intel_drm_fence *)fence; - - if (pipe_reference(&((struct intel_drm_fence *)(*ptr))->reference, &f->reference)) { - if (old->bo) - drm_intel_bo_unreference(old->bo); - FREE(old); - } - *ptr = fence; -} - -static int -intel_drm_fence_signalled(struct intel_winsys *iws, - struct pipe_fence_handle *fence) -{ - assert(0); - - return 0; -} - -static int -intel_drm_fence_finish(struct intel_winsys *iws, - struct pipe_fence_handle *fence) -{ - struct intel_drm_fence *f = (struct intel_drm_fence *)fence; - - /* fence already expired */ - if (!f->bo) - return 0; - - drm_intel_bo_wait_rendering(f->bo); - drm_intel_bo_unreference(f->bo); - f->bo = NULL; - - return 0; -} - -void -intel_drm_winsys_init_fence_functions(struct intel_drm_winsys *idws) -{ - idws->base.fence_reference = intel_drm_fence_reference; - idws->base.fence_signalled = intel_drm_fence_signalled; - idws->base.fence_finish = intel_drm_fence_finish; -} diff --git a/src/gallium/winsys/i915/drm/intel_drm_winsys.h b/src/gallium/winsys/i915/drm/intel_drm_winsys.h deleted file mode 100644 index 9786ee93650..00000000000 --- a/src/gallium/winsys/i915/drm/intel_drm_winsys.h +++ /dev/null @@ -1,77 +0,0 @@ - -#ifndef INTEL_DRM_WINSYS_H -#define INTEL_DRM_WINSYS_H - -#include "i915/intel_batchbuffer.h" - -#include "drm.h" -#include "intel_bufmgr.h" - - -/* - * Winsys - */ - - -struct intel_drm_winsys -{ - struct intel_winsys base; - - boolean dump_cmd; - - int fd; /**< Drm file discriptor */ - - unsigned id; - - size_t max_batch_size; - - struct { - drm_intel_bufmgr *gem; - } pools; -}; - -static INLINE struct intel_drm_winsys * -intel_drm_winsys(struct intel_winsys *iws) -{ - return (struct intel_drm_winsys *)iws; -} - -struct intel_drm_winsys * intel_drm_winsys_create(int fd, unsigned pci_id); -struct pipe_fence_handle * intel_drm_fence_create(drm_intel_bo *bo); - -void intel_drm_winsys_init_batchbuffer_functions(struct intel_drm_winsys *idws); -void intel_drm_winsys_init_buffer_functions(struct intel_drm_winsys *idws); -void intel_drm_winsys_init_fence_functions(struct intel_drm_winsys *idws); - - -/* - * Buffer - */ - - -struct intel_drm_buffer { - unsigned magic; - - drm_intel_bo *bo; - - void *ptr; - unsigned map_count; - boolean map_gtt; - - boolean flinked; - unsigned flink; -}; - -static INLINE struct intel_drm_buffer * -intel_drm_buffer(struct intel_buffer *buffer) -{ - return (struct intel_drm_buffer *)buffer; -} - -static INLINE drm_intel_bo * -intel_bo(struct intel_buffer *buffer) -{ - return intel_drm_buffer(buffer)->bo; -} - -#endif -- cgit v1.2.3 From 84a8347b9f6ef0c1b2519e9bd5fef2ce3c85afb7 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Thu, 25 Mar 2010 00:18:30 +0100 Subject: draw: Use translate function instead of switch cases --- src/gallium/auxiliary/draw/draw_pipe_vbuf.c | 37 ++++---------------- src/gallium/auxiliary/draw/draw_pt_emit.c | 37 ++++---------------- src/gallium/auxiliary/draw/draw_pt_fetch_emit.c | 39 ++++------------------ .../auxiliary/draw/draw_pt_fetch_shade_emit.c | 29 +++------------- src/gallium/auxiliary/draw/draw_vertex.c | 30 ++++------------- src/gallium/auxiliary/draw/draw_vertex.h | 28 ++++++++++++++-- 6 files changed, 56 insertions(+), 144 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/auxiliary/draw/draw_pipe_vbuf.c b/src/gallium/auxiliary/draw/draw_pipe_vbuf.c index 27099579618..1c7db0005a9 100644 --- a/src/gallium/auxiliary/draw/draw_pipe_vbuf.c +++ b/src/gallium/auxiliary/draw/draw_pipe_vbuf.c @@ -238,38 +238,15 @@ vbuf_start_prim( struct vbuf_stage *vbuf, uint prim ) unsigned output_format; unsigned src_offset = (vbuf->vinfo->attrib[i].src_index * 4 * sizeof(float) ); - switch (vbuf->vinfo->attrib[i].emit) { - case EMIT_4F: - output_format = PIPE_FORMAT_R32G32B32A32_FLOAT; - emit_sz = 4 * sizeof(float); - break; - case EMIT_3F: - output_format = PIPE_FORMAT_R32G32B32_FLOAT; - emit_sz = 3 * sizeof(float); - break; - case EMIT_2F: - output_format = PIPE_FORMAT_R32G32_FLOAT; - emit_sz = 2 * sizeof(float); - break; - case EMIT_1F: - output_format = PIPE_FORMAT_R32_FLOAT; - emit_sz = 1 * sizeof(float); - break; - case EMIT_1F_PSIZE: - output_format = PIPE_FORMAT_R32_FLOAT; - emit_sz = 1 * sizeof(float); + output_format = draw_translate_vinfo_format(vbuf->vinfo->attrib[i].emit); + emit_sz = draw_translate_vinfo_size(vbuf->vinfo->attrib[i].emit); + + /* doesn't handle EMIT_OMIT */ + assert(emit_sz != 0); + + if (vbuf->vinfo->attrib[i].emit == EMIT_1F_PSIZE) { src_buffer = 1; src_offset = 0; - break; - case EMIT_4UB: - output_format = PIPE_FORMAT_A8R8G8B8_UNORM; - emit_sz = 4 * sizeof(ubyte); - break; - default: - assert(0); - output_format = PIPE_FORMAT_NONE; - emit_sz = 0; - break; } hw_key.element[i].type = TRANSLATE_ELEMENT_NORMAL; diff --git a/src/gallium/auxiliary/draw/draw_pt_emit.c b/src/gallium/auxiliary/draw/draw_pt_emit.c index ae357b51226..a7917f54b04 100644 --- a/src/gallium/auxiliary/draw/draw_pt_emit.c +++ b/src/gallium/auxiliary/draw/draw_pt_emit.c @@ -86,40 +86,15 @@ void draw_pt_emit_prepare( struct pt_emit *emit, unsigned output_format; unsigned src_offset = (vinfo->attrib[i].src_index * 4 * sizeof(float) ); + output_format = draw_translate_vinfo_format(vinfo->attrib[i].emit); + emit_sz = draw_translate_vinfo_size(vinfo->attrib[i].emit); - - switch (vinfo->attrib[i].emit) { - case EMIT_4F: - output_format = PIPE_FORMAT_R32G32B32A32_FLOAT; - emit_sz = 4 * sizeof(float); - break; - case EMIT_3F: - output_format = PIPE_FORMAT_R32G32B32_FLOAT; - emit_sz = 3 * sizeof(float); - break; - case EMIT_2F: - output_format = PIPE_FORMAT_R32G32_FLOAT; - emit_sz = 2 * sizeof(float); - break; - case EMIT_1F: - output_format = PIPE_FORMAT_R32_FLOAT; - emit_sz = 1 * sizeof(float); - break; - case EMIT_1F_PSIZE: - output_format = PIPE_FORMAT_R32_FLOAT; - emit_sz = 1 * sizeof(float); + /* doesn't handle EMIT_OMIT */ + assert(emit_sz != 0); + + if (vinfo->attrib[i].emit == EMIT_1F_PSIZE) { src_buffer = 1; src_offset = 0; - break; - case EMIT_4UB: - output_format = PIPE_FORMAT_A8R8G8B8_UNORM; - emit_sz = 4 * sizeof(ubyte); - break; - default: - assert(0); - output_format = PIPE_FORMAT_NONE; - emit_sz = 0; - break; } hw_key.element[i].type = TRANSLATE_ELEMENT_NORMAL; diff --git a/src/gallium/auxiliary/draw/draw_pt_fetch_emit.c b/src/gallium/auxiliary/draw/draw_pt_fetch_emit.c index 2a604470e9a..1994ddf2bcc 100644 --- a/src/gallium/auxiliary/draw/draw_pt_fetch_emit.c +++ b/src/gallium/auxiliary/draw/draw_pt_fetch_emit.c @@ -129,41 +129,16 @@ static void fetch_emit_prepare( struct draw_pt_middle_end *middle, unsigned input_offset = src->src_offset; unsigned output_format; - switch (vinfo->attrib[i].emit) { - case EMIT_4UB: - output_format = PIPE_FORMAT_R8G8B8A8_UNORM; - emit_sz = 4 * sizeof(unsigned char); - break; - case EMIT_4F: - output_format = PIPE_FORMAT_R32G32B32A32_FLOAT; - emit_sz = 4 * sizeof(float); - break; - case EMIT_3F: - output_format = PIPE_FORMAT_R32G32B32_FLOAT; - emit_sz = 3 * sizeof(float); - break; - case EMIT_2F: - output_format = PIPE_FORMAT_R32G32_FLOAT; - emit_sz = 2 * sizeof(float); - break; - case EMIT_1F: - output_format = PIPE_FORMAT_R32_FLOAT; - emit_sz = 1 * sizeof(float); - break; - case EMIT_1F_PSIZE: + output_format = draw_translate_vinfo_format(vinfo->attrib[i].emit); + emit_sz = draw_translate_vinfo_size(vinfo->attrib[i].emit); + + if (vinfo->attrib[i].emit == EMIT_OMIT) + continue; + + if (vinfo->attrib[i].emit == EMIT_1F_PSIZE) { input_format = PIPE_FORMAT_R32_FLOAT; input_buffer = draw->pt.nr_vertex_buffers; input_offset = 0; - output_format = PIPE_FORMAT_R32_FLOAT; - emit_sz = 1 * sizeof(float); - break; - case EMIT_OMIT: - continue; - default: - assert(0); - output_format = PIPE_FORMAT_NONE; - emit_sz = 0; - continue; } key.element[i].type = TRANSLATE_ELEMENT_NORMAL; diff --git a/src/gallium/auxiliary/draw/draw_pt_fetch_shade_emit.c b/src/gallium/auxiliary/draw/draw_pt_fetch_shade_emit.c index 1aecb510777..389e2b105e5 100644 --- a/src/gallium/auxiliary/draw/draw_pt_fetch_shade_emit.c +++ b/src/gallium/auxiliary/draw/draw_pt_fetch_shade_emit.c @@ -130,31 +130,10 @@ static void fse_prepare( struct draw_pt_middle_end *middle, unsigned dst_offset = 0; for (i = 0; i < vinfo->num_attribs; i++) { - unsigned emit_sz = 0; - - switch (vinfo->attrib[i].emit) { - case EMIT_4F: - emit_sz = 4 * sizeof(float); - break; - case EMIT_3F: - emit_sz = 3 * sizeof(float); - break; - case EMIT_2F: - emit_sz = 2 * sizeof(float); - break; - case EMIT_1F: - emit_sz = 1 * sizeof(float); - break; - case EMIT_1F_PSIZE: - emit_sz = 1 * sizeof(float); - break; - case EMIT_4UB: - emit_sz = 4 * sizeof(ubyte); - break; - default: - assert(0); - break; - } + unsigned emit_sz = draw_translate_vinfo_size(vinfo->attrib[i].emit); + + /* doesn't handle EMIT_OMIT */ + assert(emit_sz != 0); /* The elements in the key correspond to vertex shader output * numbers, not to positions in the hw vertex description -- diff --git a/src/gallium/auxiliary/draw/draw_vertex.c b/src/gallium/auxiliary/draw/draw_vertex.c index 3214213e445..18921ad7179 100644 --- a/src/gallium/auxiliary/draw/draw_vertex.c +++ b/src/gallium/auxiliary/draw/draw_vertex.c @@ -48,30 +48,12 @@ draw_compute_vertex_size(struct vertex_info *vinfo) uint i; vinfo->size = 0; - for (i = 0; i < vinfo->num_attribs; i++) { - switch (vinfo->attrib[i].emit) { - case EMIT_OMIT: - break; - case EMIT_4UB: - /* fall-through */ - case EMIT_1F_PSIZE: - /* fall-through */ - case EMIT_1F: - vinfo->size += 1; - break; - case EMIT_2F: - vinfo->size += 2; - break; - case EMIT_3F: - vinfo->size += 3; - break; - case EMIT_4F: - vinfo->size += 4; - break; - default: - assert(0); - } - } + for (i = 0; i < vinfo->num_attribs; i++) + vinfo->size += draw_translate_vinfo_size(vinfo->attrib[i].emit); + + assert(vinfo->size % 4 == 0); + /* in dwords */ + vinfo->size /= 4; } diff --git a/src/gallium/auxiliary/draw/draw_vertex.h b/src/gallium/auxiliary/draw/draw_vertex.h index 8c3c7befbc7..24c5a48b2ef 100644 --- a/src/gallium/auxiliary/draw/draw_vertex.h +++ b/src/gallium/auxiliary/draw/draw_vertex.h @@ -141,9 +141,11 @@ void draw_dump_emitted_vertex(const struct vertex_info *vinfo, const uint8_t *data); -static INLINE unsigned draw_translate_vinfo_format(unsigned format ) +static INLINE unsigned draw_translate_vinfo_format(enum attrib_emit emit) { - switch (format) { + switch (emit) { + case EMIT_OMIT: + return PIPE_FORMAT_NONE; case EMIT_1F: case EMIT_1F_PSIZE: return PIPE_FORMAT_R32_FLOAT; @@ -156,9 +158,31 @@ static INLINE unsigned draw_translate_vinfo_format(unsigned format ) case EMIT_4UB: return PIPE_FORMAT_R8G8B8A8_UNORM; default: + assert(!"unexpected format"); return PIPE_FORMAT_NONE; } } +static INLINE unsigned draw_translate_vinfo_size(enum attrib_emit emit) +{ + switch (emit) { + case EMIT_OMIT: + return 0; + case EMIT_1F: + case EMIT_1F_PSIZE: + return 1 * sizeof(float); + case EMIT_2F: + return 2 * sizeof(float); + case EMIT_3F: + return 3 * sizeof(float); + case EMIT_4F: + return 4 * sizeof(float); + case EMIT_4UB: + return 4 * sizeof(unsigned char); + default: + assert(!"unexpected format"); + return 0; + } +} #endif /* DRAW_VERTEX_H */ -- cgit v1.2.3 From fe306e7ea5e789adc955653d9be8cd7f8af47264 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Thu, 25 Mar 2010 13:45:42 +0100 Subject: draw: Add EMIT_4UB_BGRA format Needed for i915g, also fixed swizzle in draw_vs_aos_io. --- src/gallium/auxiliary/draw/draw_vertex.c | 7 +++++++ src/gallium/auxiliary/draw/draw_vertex.h | 7 ++++++- src/gallium/auxiliary/draw/draw_vs_aos_io.c | 12 +++++------- src/gallium/drivers/i915/i915_prim_emit.c | 7 +++++++ src/gallium/drivers/i915/i915_state_derived.c | 4 ++-- src/gallium/drivers/nvfx/nvfx_draw.c | 6 ++++++ 6 files changed, 33 insertions(+), 10 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/auxiliary/draw/draw_vertex.c b/src/gallium/auxiliary/draw/draw_vertex.c index 18921ad7179..a4f5e882c0a 100644 --- a/src/gallium/auxiliary/draw/draw_vertex.c +++ b/src/gallium/auxiliary/draw/draw_vertex.c @@ -102,6 +102,13 @@ draw_dump_emitted_vertex(const struct vertex_info *vinfo, const uint8_t *data) debug_printf("%u ", *data++); debug_printf("%u ", *data++); break; + case EMIT_4UB_BGRA: + debug_printf("EMIT_4UB_BGRA:\t"); + debug_printf("%u ", *data++); + debug_printf("%u ", *data++); + debug_printf("%u ", *data++); + debug_printf("%u ", *data++); + break; default: assert(0); } diff --git a/src/gallium/auxiliary/draw/draw_vertex.h b/src/gallium/auxiliary/draw/draw_vertex.h index 24c5a48b2ef..ca272371267 100644 --- a/src/gallium/auxiliary/draw/draw_vertex.h +++ b/src/gallium/auxiliary/draw/draw_vertex.h @@ -54,7 +54,8 @@ enum attrib_emit { EMIT_2F, EMIT_3F, EMIT_4F, - EMIT_4UB /**< XXX may need variations for RGBA vs BGRA, etc */ + EMIT_4UB, /**< is RGBA like the rest */ + EMIT_4UB_BGRA }; @@ -157,6 +158,8 @@ static INLINE unsigned draw_translate_vinfo_format(enum attrib_emit emit) return PIPE_FORMAT_R32G32B32A32_FLOAT; case EMIT_4UB: return PIPE_FORMAT_R8G8B8A8_UNORM; + case EMIT_4UB_BGRA: + return PIPE_FORMAT_B8G8R8A8_UNORM; default: assert(!"unexpected format"); return PIPE_FORMAT_NONE; @@ -179,6 +182,8 @@ static INLINE unsigned draw_translate_vinfo_size(enum attrib_emit emit) return 4 * sizeof(float); case EMIT_4UB: return 4 * sizeof(unsigned char); + case EMIT_4UB_BGRA: + return 4 * sizeof(unsigned char); default: assert(!"unexpected format"); return 0; diff --git a/src/gallium/auxiliary/draw/draw_vs_aos_io.c b/src/gallium/auxiliary/draw/draw_vs_aos_io.c index ece1ddde0cb..8f8bbe7cb88 100644 --- a/src/gallium/auxiliary/draw/draw_vs_aos_io.c +++ b/src/gallium/auxiliary/draw/draw_vs_aos_io.c @@ -401,13 +401,11 @@ static boolean emit_output( struct aos_compilation *cp, emit_store_R32G32B32A32(cp, ptr, dataXMM); break; case EMIT_4UB: - if (1) { - emit_swizzle(cp, dataXMM, dataXMM, SHUF(Z,Y,X,W)); - emit_store_R8G8B8A8_UNORM(cp, ptr, dataXMM); - } - else { - emit_store_R8G8B8A8_UNORM(cp, ptr, dataXMM); - } + emit_store_R8G8B8A8_UNORM(cp, ptr, dataXMM); + break; + case EMIT_4UB_BGRA: + emit_swizzle(cp, dataXMM, dataXMM, SHUF(Z,Y,X,W)); + emit_store_R8G8B8A8_UNORM(cp, ptr, dataXMM); break; default: AOS_ERROR(cp, "unhandled output format"); diff --git a/src/gallium/drivers/i915/i915_prim_emit.c b/src/gallium/drivers/i915/i915_prim_emit.c index d9a5c40ab97..dd997e2cf48 100644 --- a/src/gallium/drivers/i915/i915_prim_emit.c +++ b/src/gallium/drivers/i915/i915_prim_emit.c @@ -102,6 +102,13 @@ emit_hw_vertex( struct i915_context *i915, count += 4; break; case EMIT_4UB: + OUT_BATCH( pack_ub4(float_to_ubyte( attrib[0] ), + float_to_ubyte( attrib[1] ), + float_to_ubyte( attrib[2] ), + float_to_ubyte( attrib[3] )) ); + count += 1; + break; + case EMIT_4UB_BGRA: OUT_BATCH( pack_ub4(float_to_ubyte( attrib[2] ), float_to_ubyte( attrib[1] ), float_to_ubyte( attrib[0] ), diff --git a/src/gallium/drivers/i915/i915_state_derived.c b/src/gallium/drivers/i915/i915_state_derived.c index 0eb1e3f91a4..4da46772b5d 100644 --- a/src/gallium/drivers/i915/i915_state_derived.c +++ b/src/gallium/drivers/i915/i915_state_derived.c @@ -101,14 +101,14 @@ static void calculate_vertex_layout( struct i915_context *i915 ) /* primary color */ if (colors[0]) { src = draw_find_shader_output(i915->draw, TGSI_SEMANTIC_COLOR, 0); - draw_emit_vertex_attr(&vinfo, EMIT_4UB, colorInterp, src); + draw_emit_vertex_attr(&vinfo, EMIT_4UB_BGRA, colorInterp, src); vinfo.hwfmt[0] |= S4_VFMT_COLOR; } /* secondary color */ if (colors[1]) { src = draw_find_shader_output(i915->draw, TGSI_SEMANTIC_COLOR, 1); - draw_emit_vertex_attr(&vinfo, EMIT_4UB, colorInterp, src); + draw_emit_vertex_attr(&vinfo, EMIT_4UB_BGRA, colorInterp, src); vinfo.hwfmt[0] |= S4_VFMT_SPEC_FOG; } diff --git a/src/gallium/drivers/nvfx/nvfx_draw.c b/src/gallium/drivers/nvfx/nvfx_draw.c index 5379b29efd1..68e50a36479 100644 --- a/src/gallium/drivers/nvfx/nvfx_draw.c +++ b/src/gallium/drivers/nvfx/nvfx_draw.c @@ -79,6 +79,12 @@ nvfx_render_vertex(struct nvfx_context *nvfx, const struct vertex_header *v) float_to_ubyte(v->data[idx][1]), float_to_ubyte(v->data[idx][2]), float_to_ubyte(v->data[idx][3]))); + case EMIT_4UB_BGRA: + BEGIN_RING(chan, eng3d, NV34TCL_VTX_ATTR_4UB(hw), 1); + OUT_RING (chan, pack_ub4(float_to_ubyte(v->data[idx][2]), + float_to_ubyte(v->data[idx][1]), + float_to_ubyte(v->data[idx][0]), + float_to_ubyte(v->data[idx][3]))); break; default: assert(0); -- cgit v1.2.3 From 8edf085c77c84c8b09762dab0dfd31fac51fe65d Mon Sep 17 00:00:00 2001 From: Vinson Lee Date: Thu, 25 Mar 2010 22:40:03 -0700 Subject: identity: Remove unnecessary header. --- src/gallium/drivers/identity/id_drm.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/identity/id_drm.c b/src/gallium/drivers/identity/id_drm.c index 936ccc444a8..26920fed08d 100644 --- a/src/gallium/drivers/identity/id_drm.c +++ b/src/gallium/drivers/identity/id_drm.c @@ -31,7 +31,6 @@ #include "id_drm.h" #include "id_screen.h" #include "id_public.h" -#include "id_screen.h" #include "id_objects.h" struct identity_drm_api -- cgit v1.2.3 From b1e3e03d6703970e3dd8d751735af665ebd48589 Mon Sep 17 00:00:00 2001 From: Vinson Lee Date: Thu, 25 Mar 2010 22:51:08 -0700 Subject: rtasm: Fix typos in comments. --- src/gallium/auxiliary/rtasm/rtasm_x86sse.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/auxiliary/rtasm/rtasm_x86sse.h b/src/gallium/auxiliary/rtasm/rtasm_x86sse.h index f7612d416a0..319b836ffb1 100644 --- a/src/gallium/auxiliary/rtasm/rtasm_x86sse.h +++ b/src/gallium/auxiliary/rtasm/rtasm_x86sse.h @@ -102,7 +102,7 @@ enum sse_cc { #define cc_Z cc_E #define cc_NZ cc_NE -/* Begin/end/retreive function creation: +/* Begin/end/retrieve function creation: */ @@ -311,8 +311,8 @@ void x87_fucom( struct x86_function *p, struct x86_reg arg ); -/* Retreive a reference to one of the function arguments, taking into - * account any push/pop activity. Note - doesn't track explict +/* Retrieve a reference to one of the function arguments, taking into + * account any push/pop activity. Note - doesn't track explicit * manipulation of ESP by other instructions. */ struct x86_reg x86_fn_arg( struct x86_function *p, unsigned arg ); -- cgit v1.2.3 From 1f19aba1ea461db7bbd10d05244eb12dfc31a046 Mon Sep 17 00:00:00 2001 From: Christoph Bumiller Date: Fri, 26 Mar 2010 11:13:01 +0100 Subject: nv50: fix FACE semantic check in FP input slot assignments Fixes for instance noise with material shaders in FlightGear. --- src/gallium/drivers/nv50/nv50_program.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/nv50/nv50_program.c b/src/gallium/drivers/nv50/nv50_program.c index c857816b31a..d7e06c93272 100644 --- a/src/gallium/drivers/nv50/nv50_program.c +++ b/src/gallium/drivers/nv50/nv50_program.c @@ -3762,7 +3762,7 @@ nv50_program_tx_prep(struct nv50_pc *pc) p->cfg.in[n].hw = rid = aid; i = p->cfg.in[n].id; - if (p->info.input_semantic_name[n] == + if (p->info.input_semantic_name[i] == TGSI_SEMANTIC_FACE) { load_frontfacing(pc, &pc->attr[i * 4]); continue; -- cgit v1.2.3 From 38c7a01b6c220ad04c5754602673ad3cf36ad508 Mon Sep 17 00:00:00 2001 From: Corbin Simpson Date: Fri, 26 Mar 2010 04:15:53 -0700 Subject: Revert "r300g: add generating texture coordinates for point sprites (WIP)" This reverts commit cba6430524198a1bdcdeada03cbe946a454f3935. Breaks celestia with a hardlock. :T We really need to sit down and study texture stuffing further. --- src/gallium/drivers/r300/r300_context.c | 2 -- src/gallium/drivers/r300/r300_context.h | 13 --------- src/gallium/drivers/r300/r300_emit.c | 6 ----- src/gallium/drivers/r300/r300_state.c | 35 +------------------------ src/gallium/drivers/r300/r300_state_derived.c | 5 +--- src/gallium/drivers/r300/r300_state_invariant.c | 13 +++++++-- 6 files changed, 13 insertions(+), 61 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/r300/r300_context.c b/src/gallium/drivers/r300/r300_context.c index 4433dcff21a..4b470b2c6af 100644 --- a/src/gallium/drivers/r300/r300_context.c +++ b/src/gallium/drivers/r300/r300_context.c @@ -195,8 +195,6 @@ struct pipe_context* r300_create_context(struct pipe_screen* screen, r300_setup_atoms(r300); - r300->sprite_coord_index = -1; - /* Open up the OQ BO. */ r300->oqbo = screen->buffer_create(screen, 4096, PIPE_BUFFER_USAGE_PIXEL, 4096); diff --git a/src/gallium/drivers/r300/r300_context.h b/src/gallium/drivers/r300/r300_context.h index 4bb385238ed..eb9178a2656 100644 --- a/src/gallium/drivers/r300/r300_context.h +++ b/src/gallium/drivers/r300/r300_context.h @@ -99,16 +99,6 @@ struct r300_rs_state { uint32_t line_stipple_value; /* R300_GA_LINE_STIPPLE_VALUE: 0x4260 */ uint32_t color_control; /* R300_GA_COLOR_CONTROL: 0x4278 */ uint32_t polygon_mode; /* R300_GA_POLY_MODE: 0x4288 */ - - /* Specifies top of Raster pipe specific enable controls, - * i.e. texture coordinates stuffing for points, lines, triangles */ - uint32_t stuffing_enable; /* R300_GB_ENABLE: 0x4008 */ - - /* Point sprites texture coordinates, 0: lower left, 1: upper right */ - float point_texcoord_left; /* R300_GA_POINT_S0: 0x4200 */ - float point_texcoord_bottom; /* R300_GA_POINT_T0: 0x4204 */ - float point_texcoord_right; /* R300_GA_POINT_S1: 0x4208 */ - float point_texcoord_top; /* R300_GA_POINT_T1: 0x420c */ }; struct r300_rs_block { @@ -387,9 +377,6 @@ struct r300_context { uint32_t zbuffer_bpp; /* Whether scissor is enabled. */ boolean scissor_enabled; - /* Point sprites texcoord index, -1 = unused. */ - int sprite_coord_index; - /* upload managers */ struct u_upload_mgr *upload_vb; struct u_upload_mgr *upload_ib; diff --git a/src/gallium/drivers/r300/r300_emit.c b/src/gallium/drivers/r300/r300_emit.c index 796e3eca5bf..92266ba669d 100644 --- a/src/gallium/drivers/r300/r300_emit.c +++ b/src/gallium/drivers/r300/r300_emit.c @@ -614,12 +614,6 @@ void r300_emit_rs_state(struct r300_context* r300, unsigned size, void* state) OUT_CS_REG(R300_GA_LINE_STIPPLE_CONFIG, rs->line_stipple_config); OUT_CS_REG(R300_GA_LINE_STIPPLE_VALUE, rs->line_stipple_value); OUT_CS_REG(R300_GA_POLY_MODE, rs->polygon_mode); - OUT_CS_REG(R300_GB_ENABLE, rs->stuffing_enable); - OUT_CS_REG_SEQ(R300_GA_POINT_S0, 4); - OUT_CS_32F(rs->point_texcoord_left); - OUT_CS_32F(rs->point_texcoord_bottom); - OUT_CS_32F(rs->point_texcoord_right); - OUT_CS_32F(rs->point_texcoord_top); END_CS; } diff --git a/src/gallium/drivers/r300/r300_state.c b/src/gallium/drivers/r300/r300_state.c index 31e32114b60..8e9285419c3 100644 --- a/src/gallium/drivers/r300/r300_state.c +++ b/src/gallium/drivers/r300/r300_state.c @@ -714,7 +714,6 @@ static void* r300_create_rs_state(struct pipe_context* pipe, { struct r300_screen* r300screen = r300_screen(pipe->screen); struct r300_rs_state* rs = CALLOC_STRUCT(r300_rs_state); - unsigned coord_index; /* Copy rasterizer state for Draw. */ rs->rs = *state; @@ -807,32 +806,6 @@ static void* r300_create_rs_state(struct pipe_context* pipe, rs->color_control = R300_SHADE_MODEL_SMOOTH; } - /* Point sprites */ - if (state->sprite_coord_enable) { - coord_index = ffs(state->sprite_coord_enable)-1; - - SCREEN_DBG(r300screen, DBG_DRAW, - "r300: point sprite: shader coord=%d\n", coord_index); - - rs->stuffing_enable = - R300_GB_POINT_STUFF_ENABLE | - R300_GB_TEX_ST << (R300_GB_TEX0_SOURCE_SHIFT + (coord_index*2)); - - rs->point_texcoord_left = 0.0f; - rs->point_texcoord_right = 1.0f; - - switch (state->sprite_coord_mode) { - case PIPE_SPRITE_COORD_UPPER_LEFT: - rs->point_texcoord_top = 0.0f; - rs->point_texcoord_bottom = 1.0f; - break; - case PIPE_SPRITE_COORD_LOWER_LEFT: - rs->point_texcoord_top = 1.0f; - rs->point_texcoord_bottom = 0.0f; - break; - } - } - return (void*)rs; } @@ -842,7 +815,6 @@ static void r300_bind_rs_state(struct pipe_context* pipe, void* state) struct r300_context* r300 = r300_context(pipe); struct r300_rs_state* rs = (struct r300_rs_state*)state; boolean scissor_was_enabled = r300->scissor_enabled; - int last_sprite_coord_index = r300->sprite_coord_index; if (r300->draw) { draw_flush(r300->draw); @@ -852,22 +824,17 @@ static void r300_bind_rs_state(struct pipe_context* pipe, void* state) if (rs) { r300->polygon_offset_enabled = rs->rs.offset_cw || rs->rs.offset_ccw; r300->scissor_enabled = rs->rs.scissor; - r300->sprite_coord_index = ffs(rs->rs.sprite_coord_enable)-1; } else { r300->polygon_offset_enabled = FALSE; r300->scissor_enabled = FALSE; - r300->sprite_coord_index = -1; } UPDATE_STATE(state, r300->rs_state); - r300->rs_state.size = 24 + (r300->polygon_offset_enabled ? 5 : 0); + r300->rs_state.size = 17 + (r300->polygon_offset_enabled ? 5 : 0); if (scissor_was_enabled != r300->scissor_enabled) { r300->scissor_state.dirty = TRUE; } - if (last_sprite_coord_index != r300->sprite_coord_index) { - r300->rs_block_state.dirty = TRUE; - } } /* Free rasterizer state. */ diff --git a/src/gallium/drivers/r300/r300_state_derived.c b/src/gallium/drivers/r300/r300_state_derived.c index 8178d55dc9a..3560b6e427f 100644 --- a/src/gallium/drivers/r300/r300_state_derived.c +++ b/src/gallium/drivers/r300/r300_state_derived.c @@ -178,8 +178,7 @@ static void r300_update_rs_block(struct r300_context* r300, /* Rasterize texture coordinates. */ for (i = 0; i < ATTR_GENERIC_COUNT; i++) { - if (vs_outputs->generic[i] != ATTR_UNUSED || - r300->sprite_coord_index == i) { + if (vs_outputs->generic[i] != ATTR_UNUSED) { /* Always rasterize if it's written by the VS, * otherwise it locks up. */ rX00_rs_tex(&rs, tex_count, tex_count, FALSE); @@ -187,8 +186,6 @@ static void r300_update_rs_block(struct r300_context* r300, /* Write it to the FS input register if it's used by the FS. */ if (fs_inputs->generic[i] != ATTR_UNUSED) { rX00_rs_tex_write(&rs, tex_count, fp_offset); - if (r300->sprite_coord_index == i) - debug_printf("r300: SpriteCoord (generic index %i) is being written to reg %i\n", i, fp_offset); fp_offset++; } tex_count++; diff --git a/src/gallium/drivers/r300/r300_state_invariant.c b/src/gallium/drivers/r300/r300_state_invariant.c index 2d9a63d29a4..4a2c68269b1 100644 --- a/src/gallium/drivers/r300/r300_state_invariant.c +++ b/src/gallium/drivers/r300/r300_state_invariant.c @@ -44,9 +44,13 @@ void r300_emit_invariant_state(struct r300_context* r300, struct r300_capabilities* caps = r300_screen(r300->context.screen)->caps; CS_LOCALS(r300); - BEGIN_CS(12 + (caps->has_tcl ? 2: 0)); + BEGIN_CS(14 + (caps->has_tcl ? 2: 0)); /*** Graphics Backend (GB) ***/ + /* Various GB enables */ + OUT_CS_REG(R300_GB_ENABLE, R300_GB_POINT_STUFF_ENABLE | + R300_GB_LINE_STUFF_ENABLE | + R300_GB_TRIANGLE_STUFF_ENABLE); /* Subpixel multisampling for AA * These are commented out because glisse's CS checker doesn't like them. * I presume these will be re-enabled later. @@ -74,7 +78,7 @@ void r300_emit_invariant_state(struct r300_context* r300, END_CS; /* XXX unsorted stuff from surface_fill */ - BEGIN_CS(40 + (caps->has_tcl ? 7 : 0) + + BEGIN_CS(44 + (caps->has_tcl ? 7 : 0) + (caps->family >= CHIP_FAMILY_RV350 ? 4 : 0)); if (caps->has_tcl) { @@ -86,6 +90,11 @@ void r300_emit_invariant_state(struct r300_context* r300, OUT_CS_32F(1.0); OUT_CS_32F(1.0); } + /* XXX point tex stuffing */ + OUT_CS_REG_SEQ(R300_GA_POINT_S0, 1); + OUT_CS_32F(0.0); + OUT_CS_REG_SEQ(R300_GA_POINT_S1, 1); + OUT_CS_32F(1.0); /* XXX line tex stuffing */ OUT_CS_REG_SEQ(R300_GA_LINE_S0, 1); OUT_CS_32F(0.0); -- cgit v1.2.3 From fb70f456fce6b9cca9330e1c1e174153e532693e Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Fri, 26 Mar 2010 14:32:56 +0100 Subject: svga/drm: Fix build under scons --- src/gallium/winsys/svga/drm/vmw_screen_dri.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/gallium') diff --git a/src/gallium/winsys/svga/drm/vmw_screen_dri.c b/src/gallium/winsys/svga/drm/vmw_screen_dri.c index 657544dcb21..e8ebe9ac893 100644 --- a/src/gallium/winsys/svga/drm/vmw_screen_dri.c +++ b/src/gallium/winsys/svga/drm/vmw_screen_dri.c @@ -39,7 +39,7 @@ #include #include -#include +#include "vmwgfx_drm.h" #include #include -- cgit v1.2.3 From 711529153c797b4169fd5bbba79b370a2f38a0e9 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Fri, 26 Mar 2010 14:19:48 +0100 Subject: gallium: Fix DRI driver build warnings under scons When building more then one dri driver we would get warnings because we where defining the same build target multiple times. Also move all the dri scons targets related code into its own file. --- src/gallium/targets/SConscript | 66 +------------------------ src/gallium/targets/SConscript.dri | 79 ++++++++++++++++++++++++++++++ src/gallium/targets/dri-i915/SConscript | 7 +-- src/gallium/targets/dri-i915/dummy.c | 0 src/gallium/targets/dri-i965/SConscript | 13 +++-- src/gallium/targets/dri-i965/dummy.c | 0 src/gallium/targets/dri-radeong/SConscript | 15 ++++-- src/gallium/targets/dri-radeong/dummy.c | 0 src/gallium/targets/dri-vmwgfx/SConscript | 24 ++++----- src/gallium/targets/dri-vmwgfx/dummy.c | 0 10 files changed, 117 insertions(+), 87 deletions(-) create mode 100644 src/gallium/targets/SConscript.dri create mode 100644 src/gallium/targets/dri-i915/dummy.c create mode 100644 src/gallium/targets/dri-i965/dummy.c create mode 100644 src/gallium/targets/dri-radeong/dummy.c create mode 100644 src/gallium/targets/dri-vmwgfx/dummy.c (limited to 'src/gallium') diff --git a/src/gallium/targets/SConscript b/src/gallium/targets/SConscript index a41496a5dd9..747e64508f7 100644 --- a/src/gallium/targets/SConscript +++ b/src/gallium/targets/SConscript @@ -1,9 +1,4 @@ Import('*') - -#if env['dri']: -# SConscript([ -# 'drm/SConscript', -# ]) if 'xlib' in env['winsys']: SConscript([ @@ -16,67 +11,10 @@ if 'gdi' in env['winsys']: ]) if env['dri']: - drienv = env.Clone() - - drienv.Replace(CPPPATH = [ - '#src/mesa/drivers/dri/common', - '#include', - '#include/GL/internal', - '#src/gallium/include', - '#src/gallium/auxiliary', - '#src/gallium/drivers', - '#src/mesa', - '#src/mesa/main', - '#src/mesa/glapi', - '#src/mesa/math', - '#src/mesa/transform', - '#src/mesa/shader', - '#src/mesa/swrast', - '#src/mesa/swrast_setup', - '#src/egl/main', - '#src/egl/drivers/dri', - ]) - - drienv.ParseConfig('pkg-config --cflags --libs libdrm') - - COMMON_GALLIUM_SOURCES = [ - '#src/mesa/drivers/dri/common/utils.c', - '#src/mesa/drivers/dri/common/vblank.c', - '#src/mesa/drivers/dri/common/dri_util.c', - '#src/mesa/drivers/dri/common/xmlconfig.c', - ] - - COMMON_BM_SOURCES = [ - '#src/mesa/drivers/dri/common/dri_bufmgr.c', - '#src/mesa/drivers/dri/common/dri_drmpool.c', - ] - - Export([ - 'drienv', - 'COMMON_GALLIUM_SOURCES', - 'COMMON_BM_SOURCES', + SConscript([ + 'SConscript.dri' ]) - if 'vmware' in env['winsys']: - SConscript([ - 'dri-vmwgfx/SConscript', - ]) - - if 'i915' in env['winsys']: - SConscript([ - 'dri-i915/SConscript', - ]) - - if 'i965' in env['winsys']: - SConscript([ - 'dri-i965/SConscript', - ]) - - if 'radeon' in env['winsys']: - SConscript([ - 'dri-radeong/SConscript', - ]) - if 'xorg' in env['statetrackers']: if 'vmware' in env['winsys']: SConscript([ diff --git a/src/gallium/targets/SConscript.dri b/src/gallium/targets/SConscript.dri new file mode 100644 index 00000000000..62192405807 --- /dev/null +++ b/src/gallium/targets/SConscript.dri @@ -0,0 +1,79 @@ +################################### +# SConcscript file for dri targets + +Import('*') + +drienv = env.Clone() + +drienv.Replace(CPPPATH = [ + '#src/mesa/drivers/dri/common', + '#include', + '#include/GL/internal', + '#src/gallium/include', + '#src/gallium/auxiliary', + '#src/gallium/drivers', + '#src/mesa', + '#src/mesa/main', + '#src/mesa/glapi', + '#src/mesa/math', + '#src/mesa/transform', + '#src/mesa/shader', + '#src/mesa/swrast', + '#src/mesa/swrast_setup', + '#src/egl/main', + '#src/egl/drivers/dri', +]) + +drienv.ParseConfig('pkg-config --cflags --libs libdrm') + +dri_common_utils = drienv.SharedObject( + target = 'utils.o', + source = '#src/mesa/drivers/dri/common/utils.c' +) + +dri_common_xmlconfig = drienv.SharedObject( + target = 'xmlconfig.o', + source = '#src/mesa/drivers/dri/common/xmlconfig.c' +) + +dri_common_vblank = drienv.SharedObject( + target = 'vblank.o', + source = '#src/mesa/drivers/dri/common/vblank.c' +) + +dri_common_dri_util = drienv.SharedObject( + target = 'dri_util.o', + source = '#src/mesa/drivers/dri/common/dri_util.c' +) + +COMMON_DRI_DRM_OBJECTS = [ + dri_common_utils, + dri_common_xmlconfig, + dri_common_vblank, + dri_common_dri_util, +] + +Export([ + 'drienv', + 'COMMON_DRI_DRM_OBJECTS', +]) + +if 'vmware' in env['winsys']: + SConscript([ + 'dri-vmwgfx/SConscript', + ]) + +if 'i915' in env['winsys']: + SConscript([ + 'dri-i915/SConscript', + ]) + +if 'i965' in env['winsys']: + SConscript([ + 'dri-i965/SConscript', + ]) + +if 'radeon' in env['winsys']: + SConscript([ + 'dri-radeong/SConscript', + ]) diff --git a/src/gallium/targets/dri-i915/SConscript b/src/gallium/targets/dri-i915/SConscript index f6d1f934783..2fcc8028f12 100644 --- a/src/gallium/targets/dri-i915/SConscript +++ b/src/gallium/targets/dri-i915/SConscript @@ -15,11 +15,12 @@ env.Prepend(LIBS = [ trace, mesa, glsl, - gallium + gallium, + COMMON_DRI_DRM_OBJECTS ]) env.LoadableModule( - target ='i915_dri.so', - source = COMMON_GALLIUM_SOURCES, + target = 'i915_dri.so', + source = 'dummy.c', SHLIBPREFIX = '', ) diff --git a/src/gallium/targets/dri-i915/dummy.c b/src/gallium/targets/dri-i915/dummy.c new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/gallium/targets/dri-i965/SConscript b/src/gallium/targets/dri-i965/SConscript index 3b37d8e1af4..eb9e6cd172a 100644 --- a/src/gallium/targets/dri-i965/SConscript +++ b/src/gallium/targets/dri-i965/SConscript @@ -8,16 +8,19 @@ env = drienv.Clone() env.ParseConfig('pkg-config --cflags --libs libdrm_intel') -drivers = [ +env.Prepend(LIBS = [ st_dri, i965drm, i965, trace, -] + mesa, + glsl, + gallium, + COMMON_DRI_DRM_OBJECTS +]) env.LoadableModule( - target ='i965_dri.so', - source = COMMON_GALLIUM_SOURCES, - LIBS = drivers + mesa + gallium + env['LIBS'], + target = 'i965_dri.so', + source = 'dummy.c', SHLIBPREFIX = '', ) diff --git a/src/gallium/targets/dri-i965/dummy.c b/src/gallium/targets/dri-i965/dummy.c new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/gallium/targets/dri-radeong/SConscript b/src/gallium/targets/dri-radeong/SConscript index 239d29ace18..d926c272889 100644 --- a/src/gallium/targets/dri-radeong/SConscript +++ b/src/gallium/targets/dri-radeong/SConscript @@ -8,10 +8,19 @@ env = drienv.Clone() env.ParseConfig('pkg-config --cflags --libs libdrm_radeon') -drivers = r300 + trace + softpipe +env.Prepend(LIBS = [ + st_dri, + radeonwinsys, + r300, + trace, + mesa, + glsl, + gallium, + COMMON_DRI_DRM_OBJECTS +]) env.SharedLibrary( target ='radeon_dri.so', - source = COMMON_GALLIUM_SOURCES, - LIBS = st_dri + radeonwinsys + mesa + glsl + drivers + gallium + env['LIBS'], + source = 'dummy.c', + SHLIBPREFIX = '', ) diff --git a/src/gallium/targets/dri-radeong/dummy.c b/src/gallium/targets/dri-radeong/dummy.c new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/gallium/targets/dri-vmwgfx/SConscript b/src/gallium/targets/dri-vmwgfx/SConscript index 7d248e8a9ce..6a1f8827bc3 100644 --- a/src/gallium/targets/dri-vmwgfx/SConscript +++ b/src/gallium/targets/dri-vmwgfx/SConscript @@ -6,19 +6,19 @@ if not 'svga' in env['drivers']: env = drienv.Clone() -drivers = [ - trace, - st_dri, - svgadrm, - svga, - mesa, - glsl, - gallium, -] +env.Prepend(LIBS = [ + st_dri, + svgadrm, + svga, + trace, + mesa, + glsl, + gallium, + COMMON_DRI_DRM_OBJECTS +]) env.LoadableModule( - target ='vmwgfx_dri.so', - source = COMMON_GALLIUM_SOURCES, - LIBS = drivers + mesa + gallium + env['LIBS'], + target = 'vmwgfx_dri.so', + source = 'dummy.c', SHLIBPREFIX = '', ) diff --git a/src/gallium/targets/dri-vmwgfx/dummy.c b/src/gallium/targets/dri-vmwgfx/dummy.c new file mode 100644 index 00000000000..e69de29bb2d -- cgit v1.2.3 From 7f91f2efb5b92a9ad8506c54643142f40f286d5c Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Fri, 26 Mar 2010 14:45:36 +0100 Subject: swrastg: Build with scons --- src/gallium/state_trackers/dri/SConscript | 1 + src/gallium/state_trackers/dri/sw/SConscript | 29 +++++++++++++++++++++++++ src/gallium/targets/SConscript.dri | 17 +++++++++++++++ src/gallium/targets/dri-swrast/SConscript | 32 ++++++++++++++++++++++++++++ src/gallium/winsys/SConscript | 4 ++++ src/gallium/winsys/sw/dri/SConscript | 23 ++++++++++++++++++++ 6 files changed, 106 insertions(+) create mode 100644 src/gallium/state_trackers/dri/sw/SConscript create mode 100644 src/gallium/targets/dri-swrast/SConscript create mode 100644 src/gallium/winsys/sw/dri/SConscript (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/dri/SConscript b/src/gallium/state_trackers/dri/SConscript index b4a276cf29d..aba60fb8c5b 100644 --- a/src/gallium/state_trackers/dri/SConscript +++ b/src/gallium/state_trackers/dri/SConscript @@ -1,5 +1,6 @@ Import('*') SConscript([ + 'sw/SConscript', 'drm/SConscript', ]) diff --git a/src/gallium/state_trackers/dri/sw/SConscript b/src/gallium/state_trackers/dri/sw/SConscript new file mode 100644 index 00000000000..0614b8f521f --- /dev/null +++ b/src/gallium/state_trackers/dri/sw/SConscript @@ -0,0 +1,29 @@ +####################################################################### +# SConscript for dri state_tracker + +Import('*') + +if env['dri']: + + env = env.Clone() + + env.Append(CPPPATH = [ + '#/src/mesa', + '#/src/gallium/state_trackers/dri/common', + '#/src/mesa/drivers/dri/common', + ]) + + env.Append(CPPDEFINES = [('__NOT_HAVE_DRM_H', '1')]) + + st_drisw = env.ConvenienceLibrary( + target = 'st_drisw', + source = [ 'dri_context.c', + 'dri_drawable.c', + 'dri_extensions.c', + 'dri_screen.c', + 'dri_st_api.c', + 'dri1_helper.c', + 'drisw.c', + ] + ) + Export('st_drisw') diff --git a/src/gallium/targets/SConscript.dri b/src/gallium/targets/SConscript.dri index 62192405807..210af13720a 100644 --- a/src/gallium/targets/SConscript.dri +++ b/src/gallium/targets/SConscript.dri @@ -46,6 +46,18 @@ dri_common_dri_util = drienv.SharedObject( source = '#src/mesa/drivers/dri/common/dri_util.c' ) +dri_common_drisw_util = drienv.SharedObject( + target = 'drisw_util.o', + source = '#src/mesa/drivers/dri/common/drisw_util.c' +) + + +COMMON_DRI_SW_OBJECTS = [ + dri_common_utils, + dri_common_xmlconfig, + dri_common_drisw_util, +] + COMMON_DRI_DRM_OBJECTS = [ dri_common_utils, dri_common_xmlconfig, @@ -55,9 +67,14 @@ COMMON_DRI_DRM_OBJECTS = [ Export([ 'drienv', + 'COMMON_DRI_SW_OBJECTS', 'COMMON_DRI_DRM_OBJECTS', ]) +SConscript([ + 'dri-swrast/SConscript', +]) + if 'vmware' in env['winsys']: SConscript([ 'dri-vmwgfx/SConscript', diff --git a/src/gallium/targets/dri-swrast/SConscript b/src/gallium/targets/dri-swrast/SConscript new file mode 100644 index 00000000000..e9f742c43ce --- /dev/null +++ b/src/gallium/targets/dri-swrast/SConscript @@ -0,0 +1,32 @@ +Import('*') + +if not 'softpipe' in env['drivers']: + print 'warning: softpipe driver not built skipping swrastg_dri.so' + Return() + +env = drienv.Clone() + +env.Append(CPPPATH = [ + '#/src/gallium/winsys/sw/dri', +]) + +env.Prepend(LIBS = [ + st_drisw, + ws_dri, + softpipe, + trace, + mesa, + glsl, + gallium, + COMMON_DRI_SW_OBJECTS +]) + +swrastg_sources = [ + 'swrast_drm_api.c' +] + +env.LoadableModule( + target ='swrastg_dri.so', + source = swrastg_sources, + SHLIBPREFIX = '', +) diff --git a/src/gallium/winsys/SConscript b/src/gallium/winsys/SConscript index 3e7052c0e6f..2013ee97c1c 100644 --- a/src/gallium/winsys/SConscript +++ b/src/gallium/winsys/SConscript @@ -11,6 +11,10 @@ if 'gdi' in env['winsys']: ]) if env['dri']: + SConscript([ + 'sw/dri/SConscript', + ]) + if 'vmware' in env['winsys']: SConscript([ 'svga/drm/SConscript', diff --git a/src/gallium/winsys/sw/dri/SConscript b/src/gallium/winsys/sw/dri/SConscript new file mode 100644 index 00000000000..b255d725f95 --- /dev/null +++ b/src/gallium/winsys/sw/dri/SConscript @@ -0,0 +1,23 @@ +####################################################################### +# SConscript for xlib winsys + + +Import('*') + +if env['platform'] == 'linux': + + env = env.Clone() + + env.Append(CPPPATH = [ + '#/src/gallium/include', + '#/src/gallium/auxiliary', + '#/src/gallium/drivers', + ]) + + ws_dri = env.ConvenienceLibrary( + target = 'ws_dri', + source = [ + 'dri_sw_winsys.c', + ] + ) + Export('ws_dri') -- cgit v1.2.3 From e57405e8d516c09b890c6f1c3bd8fe7780417c95 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Fri, 26 Mar 2010 14:47:20 +0100 Subject: swrastg: Use llvmpipe if built but only on scons --- src/gallium/targets/dri-swrast/Makefile | 2 +- src/gallium/targets/dri-swrast/SConscript | 16 +++++++++++++--- src/gallium/targets/dri-swrast/swrast_drm_api.c | 25 ++++++++++++++++++++----- 3 files changed, 34 insertions(+), 9 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/targets/dri-swrast/Makefile b/src/gallium/targets/dri-swrast/Makefile index 3780da27550..fcfd690e438 100644 --- a/src/gallium/targets/dri-swrast/Makefile +++ b/src/gallium/targets/dri-swrast/Makefile @@ -3,7 +3,7 @@ include $(TOP)/configs/current LIBNAME = swrastg_dri.so -DRIVER_DEFINES = -D__NOT_HAVE_DRM_H +DRIVER_DEFINES = -D__NOT_HAVE_DRM_H -DGALLIUM_SOFTPIPE PIPE_DRIVERS = \ $(TOP)/src/gallium/state_trackers/dri/sw/libdrisw.a \ diff --git a/src/gallium/targets/dri-swrast/SConscript b/src/gallium/targets/dri-swrast/SConscript index e9f742c43ce..94ff99a0a90 100644 --- a/src/gallium/targets/dri-swrast/SConscript +++ b/src/gallium/targets/dri-swrast/SConscript @@ -1,7 +1,7 @@ Import('*') -if not 'softpipe' in env['drivers']: - print 'warning: softpipe driver not built skipping swrastg_dri.so' +if not set(('softpipe', 'llvmpipe')).intersection(env['drivers']): + print 'warning: no supported pipe driver: skipping build of swrastg_dri.so' Return() env = drienv.Clone() @@ -13,7 +13,6 @@ env.Append(CPPPATH = [ env.Prepend(LIBS = [ st_drisw, ws_dri, - softpipe, trace, mesa, glsl, @@ -21,6 +20,17 @@ env.Prepend(LIBS = [ COMMON_DRI_SW_OBJECTS ]) +if 'softpipe' in env['drivers']: + env.Append(CPPDEFINES = 'GALLIUM_SOFTPIPE') + env.Prepend(LIBS = [softpipe]) + +if 'llvmpipe' in env['drivers']: + env.Tool('llvm') + if 'LLVM_VERSION' in env: + env.Append(CPPDEFINES = 'GALLIUM_LLVMPIPE') + env.Tool('udis86') + env.Prepend(LIBS = [llvmpipe]) + swrastg_sources = [ 'swrast_drm_api.c' ] diff --git a/src/gallium/targets/dri-swrast/swrast_drm_api.c b/src/gallium/targets/dri-swrast/swrast_drm_api.c index 211836d784f..224651603d1 100644 --- a/src/gallium/targets/dri-swrast/swrast_drm_api.c +++ b/src/gallium/targets/dri-swrast/swrast_drm_api.c @@ -28,12 +28,18 @@ #include "pipe/p_compiler.h" #include "util/u_memory.h" - -#include "softpipe/sp_public.h" #include "state_tracker/drm_api.h" #include "state_tracker/sw_winsys.h" #include "dri_sw_winsys.h" +#ifdef GALLIUM_SOFTPIPE +#include "softpipe/sp_public.h" +#endif + +#ifdef GALLIUM_LLVMPIPE +#include "llvmpipe/lp_public.h" +#endif + static struct pipe_screen * swrast_create_screen(struct drm_api *api, int drmFD, @@ -57,15 +63,24 @@ swrast_create_screen(struct drm_api *api, if (winsys == NULL) return NULL; - screen = softpipe_create_screen( winsys ); - if (screen == NULL) +#ifdef GALLIUM_LLVMPIPE + if (!screen) + screen = llvmpipe_create_screen(winsys); +#endif + +#ifdef GALLIUM_SOFTPIPE + if (!screen) + screen = softpipe_create_screen(winsys); +#endif + + if (!screen) goto fail; return screen; fail: if (winsys) - winsys->destroy( winsys ); + winsys->destroy(winsys); return NULL; } -- cgit v1.2.3 From 4b722bf9fde668dff1c2b55b34eb3f86c78f43fb Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Fri, 26 Mar 2010 18:44:39 +0200 Subject: st/dri: fold dri_extensions.c into dri_context.c --- .../state_trackers/dri/common/dri_context.c | 14 ++++++- .../state_trackers/dri/common/dri_context.h | 5 --- .../state_trackers/dri/common/dri_extensions.c | 48 ---------------------- src/gallium/state_trackers/dri/drm/Makefile | 1 - .../state_trackers/dri/drm/dri_extensions.c | 1 - src/gallium/state_trackers/dri/sw/Makefile | 1 - src/gallium/state_trackers/dri/sw/dri_extensions.c | 1 - 7 files changed, 13 insertions(+), 58 deletions(-) delete mode 100644 src/gallium/state_trackers/dri/common/dri_extensions.c delete mode 120000 src/gallium/state_trackers/dri/drm/dri_extensions.c delete mode 120000 src/gallium/state_trackers/dri/sw/dri_extensions.c (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/dri/common/dri_context.c b/src/gallium/state_trackers/dri/common/dri_context.c index 34d9a932ead..f14f4130bf4 100644 --- a/src/gallium/state_trackers/dri/common/dri_context.c +++ b/src/gallium/state_trackers/dri/common/dri_context.c @@ -29,13 +29,25 @@ * Author: Jakob Bornecrantz */ +#include "utils.h" + #include "dri_screen.h" #include "dri_drawable.h" #include "dri_context.h" #include "dri_st_api.h" #include "pipe/p_context.h" -#include "util/u_memory.h" +#include "state_tracker/st_context.h" + +static void +dri_init_extensions(struct dri_context *ctx) +{ + struct st_context *st = (struct st_context *) ctx->st; + + /* New extensions should be added in mesa/state_tracker/st_extensions.c + * and not in this file. */ + driInitExtensions(st->ctx, NULL, GL_FALSE); +} GLboolean dri_create_context(const __GLcontextModes * visual, diff --git a/src/gallium/state_trackers/dri/common/dri_context.h b/src/gallium/state_trackers/dri/common/dri_context.h index 24d3d0368a4..594618874a4 100644 --- a/src/gallium/state_trackers/dri/common/dri_context.h +++ b/src/gallium/state_trackers/dri/common/dri_context.h @@ -87,11 +87,6 @@ dri_create_context(const __GLcontextModes * visual, __DRIcontext * driContextPriv, void *sharedContextPrivate); -/*********************************************************************** - * dri_extensions.c - */ -void dri_init_extensions(struct dri_context *ctx); - #endif /* vim: set sw=3 ts=8 sts=3 expandtab: */ diff --git a/src/gallium/state_trackers/dri/common/dri_extensions.c b/src/gallium/state_trackers/dri/common/dri_extensions.c deleted file mode 100644 index df458e1eb0f..00000000000 --- a/src/gallium/state_trackers/dri/common/dri_extensions.c +++ /dev/null @@ -1,48 +0,0 @@ -/************************************************************************** - * - * Copyright 2009, VMware, Inc. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ -/* - * Author: Keith Whitwell - * Author: Jakob Bornecrantz - */ - -#include "dri_screen.h" -#include "dri_context.h" -#include "state_tracker/st_context.h" - -#include "utils.h" - -void -dri_init_extensions(struct dri_context *ctx) -{ - struct st_context *st = (struct st_context *) ctx->st; - - /* New extensions should be added in mesa/state_tracker/st_extensions.c - * and not in this file. */ - driInitExtensions(st->ctx, NULL, GL_FALSE); -} - -/* vim: set sw=3 ts=8 sts=3 expandtab: */ diff --git a/src/gallium/state_trackers/dri/drm/Makefile b/src/gallium/state_trackers/dri/drm/Makefile index 19a755b86f1..7a236da0c0f 100644 --- a/src/gallium/state_trackers/dri/drm/Makefile +++ b/src/gallium/state_trackers/dri/drm/Makefile @@ -16,7 +16,6 @@ C_SOURCES = \ dri_context.c \ dri_screen.c \ dri_drawable.c \ - dri_extensions.c \ dri_st_api.c \ dri1_helper.c \ dri1.c \ diff --git a/src/gallium/state_trackers/dri/drm/dri_extensions.c b/src/gallium/state_trackers/dri/drm/dri_extensions.c deleted file mode 120000 index e0d06dcdfa5..00000000000 --- a/src/gallium/state_trackers/dri/drm/dri_extensions.c +++ /dev/null @@ -1 +0,0 @@ -../common/dri_extensions.c \ No newline at end of file diff --git a/src/gallium/state_trackers/dri/sw/Makefile b/src/gallium/state_trackers/dri/sw/Makefile index 75e14fd26cb..18d7aabd9f0 100644 --- a/src/gallium/state_trackers/dri/sw/Makefile +++ b/src/gallium/state_trackers/dri/sw/Makefile @@ -19,7 +19,6 @@ C_SOURCES = \ dri_context.c \ dri_screen.c \ dri_drawable.c \ - dri_extensions.c \ dri_st_api.c \ dri1_helper.c \ drisw.c diff --git a/src/gallium/state_trackers/dri/sw/dri_extensions.c b/src/gallium/state_trackers/dri/sw/dri_extensions.c deleted file mode 120000 index e0d06dcdfa5..00000000000 --- a/src/gallium/state_trackers/dri/sw/dri_extensions.c +++ /dev/null @@ -1 +0,0 @@ -../common/dri_extensions.c \ No newline at end of file -- cgit v1.2.3 From 1fbfc22d8560c9d900832147f504ff64c64358de Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Fri, 26 Mar 2010 18:44:39 +0200 Subject: st/dri mv __driDriverExtensions to drisw.c and dri2.c --- src/gallium/state_trackers/dri/common/dri_screen.c | 15 --------------- src/gallium/state_trackers/dri/drm/dri2.c | 8 ++++++++ src/gallium/state_trackers/dri/sw/drisw.c | 7 +++++++ 3 files changed, 15 insertions(+), 15 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/dri/common/dri_screen.c b/src/gallium/state_trackers/dri/common/dri_screen.c index 598a07bb646..53053a74c4c 100644 --- a/src/gallium/state_trackers/dri/common/dri_screen.c +++ b/src/gallium/state_trackers/dri/common/dri_screen.c @@ -338,14 +338,6 @@ const struct __DriverAPIRec driDriverAPI = { .CopySubBuffer = dri1_copy_sub_buffer, }; -/* This is the table of extensions that the loader will dlsym() for. */ -PUBLIC const __DRIextension *__driDriverExtensions[] = { - &driCoreExtension.base, - &driLegacyExtension.base, - &driDRI2Extension.base, - NULL -}; - #else const struct __DriverAPIRec driDriverAPI = { @@ -361,13 +353,6 @@ const struct __DriverAPIRec driDriverAPI = { .SwapBuffers = drisw_swap_buffers, }; -/* This is the table of extensions that the loader will dlsym() for. */ -PUBLIC const __DRIextension *__driDriverExtensions[] = { - &driCoreExtension.base, - &driSWRastExtension.base, - NULL -}; - #endif /* vim: set sw=3 ts=8 sts=3 expandtab: */ diff --git a/src/gallium/state_trackers/dri/drm/dri2.c b/src/gallium/state_trackers/dri/drm/dri2.c index 108b18e9d3c..854801d1ea1 100644 --- a/src/gallium/state_trackers/dri/drm/dri2.c +++ b/src/gallium/state_trackers/dri/drm/dri2.c @@ -410,4 +410,12 @@ fail: return NULL; } +/* This is the table of extensions that the loader will dlsym() for. */ +PUBLIC const __DRIextension *__driDriverExtensions[] = { + &driCoreExtension.base, + &driLegacyExtension.base, + &driDRI2Extension.base, + NULL +}; + /* vim: set sw=3 ts=8 sts=3 expandtab: */ diff --git a/src/gallium/state_trackers/dri/sw/drisw.c b/src/gallium/state_trackers/dri/sw/drisw.c index 73bc45d9060..d7c6577818f 100644 --- a/src/gallium/state_trackers/dri/sw/drisw.c +++ b/src/gallium/state_trackers/dri/sw/drisw.c @@ -315,4 +315,11 @@ fail: return NULL; } +/* This is the table of extensions that the loader will dlsym() for. */ +PUBLIC const __DRIextension *__driDriverExtensions[] = { + &driCoreExtension.base, + &driSWRastExtension.base, + NULL +}; + /* vim: set sw=3 ts=8 sts=3 expandtab: */ -- cgit v1.2.3 From 5b07257fdbb5a93f432b8eaf3a41f39b26bdb1f3 Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Fri, 26 Mar 2010 18:44:39 +0200 Subject: st/dri: factor out common init_screen code --- src/gallium/state_trackers/dri/common/dri_screen.c | 38 ++++++++++++++++++---- src/gallium/state_trackers/dri/common/dri_screen.h | 13 ++++---- src/gallium/state_trackers/dri/drm/dri1.c | 30 +++++++---------- src/gallium/state_trackers/dri/drm/dri2.c | 21 +++++------- src/gallium/state_trackers/dri/sw/drisw.c | 21 +++++------- 5 files changed, 67 insertions(+), 56 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/dri/common/dri_screen.c b/src/gallium/state_trackers/dri/common/dri_screen.c index 53053a74c4c..cbd7563938e 100644 --- a/src/gallium/state_trackers/dri/common/dri_screen.c +++ b/src/gallium/state_trackers/dri/common/dri_screen.c @@ -50,7 +50,6 @@ #include "util/u_inlines.h" #include "pipe/p_screen.h" #include "pipe/p_format.h" -#include "state_tracker/drm_api.h" #include "util/u_debug.h" @@ -63,9 +62,9 @@ PUBLIC const char __driConfigOptions[] = DRI_CONF_ALLOW_LARGE_TEXTURES(1) DRI_CONF_SECTION_END DRI_CONF_END; -const uint __driNConfigOptions = 3; +static const uint __driNConfigOptions = 3; -const __DRIconfig ** +static const __DRIconfig ** dri_fill_in_modes(struct dri_screen *screen, unsigned pixel_bits) { @@ -299,10 +298,8 @@ dri_destroy_option_cache(struct dri_screen * screen) } void -dri_destroy_screen(__DRIscreen * sPriv) +dri_destroy_screen_helper(struct dri_screen * screen) { - struct dri_screen *screen = dri_screen(sPriv); - dri1_destroy_pipe_context(screen); if (screen->smapi) @@ -312,12 +309,41 @@ dri_destroy_screen(__DRIscreen * sPriv) screen->pipe_screen->destroy(screen->pipe_screen); dri_destroy_option_cache(screen); +} + +static void +dri_destroy_screen(__DRIscreen * sPriv) +{ + struct dri_screen *screen = dri_screen(sPriv); + + dri_destroy_screen_helper(screen); FREE(screen); sPriv->private = NULL; sPriv->extensions = NULL; } +const __DRIconfig ** +dri_init_screen_helper(struct dri_screen *screen, + struct drm_create_screen_arg *arg, + unsigned pixel_bits) +{ + screen->pipe_screen = screen->api->create_screen(screen->api, screen->fd, arg); + if (!screen->pipe_screen) { + debug_printf("%s: failed to create pipe_screen\n", __FUNCTION__); + return NULL; + } + + screen->smapi = dri_create_st_manager(screen); + if (!screen->smapi) + return NULL; + + driParseOptionInfo(&screen->optionCache, + __driConfigOptions, __driNConfigOptions); + + return dri_fill_in_modes(screen, pixel_bits); +} + #ifndef __NOT_HAVE_DRM_H const struct __DriverAPIRec driDriverAPI = { diff --git a/src/gallium/state_trackers/dri/common/dri_screen.h b/src/gallium/state_trackers/dri/common/dri_screen.h index 4f59db37cfa..e77bce17ae9 100644 --- a/src/gallium/state_trackers/dri/common/dri_screen.h +++ b/src/gallium/state_trackers/dri/common/dri_screen.h @@ -39,6 +39,7 @@ #include "pipe/p_context.h" #include "pipe/p_state.h" #include "state_tracker/st_api.h" +#include "state_tracker/drm_api.h" struct dri_screen { @@ -97,17 +98,17 @@ dri_with_format(__DRIscreen * sPriv) #endif -extern const uint __driNConfigOptions; - -const __DRIconfig ** -dri_fill_in_modes(struct dri_screen *screen, unsigned pixel_bits); - void dri_fill_st_visual(struct st_visual *stvis, struct dri_screen *screen, const __GLcontextModes *mode); +const __DRIconfig ** +dri_init_screen_helper(struct dri_screen *screen, + struct drm_create_screen_arg *arg, + unsigned pixel_bits); + void -dri_destroy_screen(__DRIscreen * sPriv); +dri_destroy_screen_helper(struct dri_screen * screen); #endif diff --git a/src/gallium/state_trackers/dri/drm/dri1.c b/src/gallium/state_trackers/dri/drm/dri1.c index 98bdb2936a1..aad098bb301 100644 --- a/src/gallium/state_trackers/dri/drm/dri1.c +++ b/src/gallium/state_trackers/dri/drm/dri1.c @@ -469,8 +469,8 @@ dri1_copy_version(struct dri1_api_version *dst, const __DRIconfig ** dri1_init_screen(__DRIscreen * sPriv) { - struct dri_screen *screen; const __DRIconfig **configs; + struct dri_screen *screen; struct dri1_create_screen_arg arg; screen = CALLOC_STRUCT(dri_screen); @@ -495,32 +495,26 @@ dri1_init_screen(__DRIscreen * sPriv) dri1_copy_version(&arg.drm_version, &sPriv->drm_version); arg.api = NULL; - screen->pipe_screen = screen->api->create_screen(screen->api, screen->fd, &arg.base); - - if (!screen->pipe_screen || !arg.api) { - debug_printf("%s: failed to create dri1 screen\n", __FUNCTION__); - goto out_no_screen; - } - - __dri1_api_hooks = arg.api; - - driParseOptionInfo(&screen->optionCache, - __driConfigOptions, __driNConfigOptions); - /** * FIXME: If the driver supports format conversion swapbuffer blits, we might * want to support other color bit depths than the server is currently * using. */ - configs = dri_fill_in_modes(screen, sPriv->fbBPP); + configs = dri_init_screen_helper(screen, &arg.base, sPriv->fbBPP); if (!configs) - goto out_no_configs; + goto fail; + + if (!arg.api) { + debug_printf("%s: failed to create dri1 screen\n", __FUNCTION__); + goto fail; + } + + __dri1_api_hooks = arg.api; return configs; - out_no_configs: - screen->pipe_screen->destroy(screen->pipe_screen); - out_no_screen: +fail: + dri_destroy_screen_helper(screen); FREE(screen); return NULL; } diff --git a/src/gallium/state_trackers/dri/drm/dri2.c b/src/gallium/state_trackers/dri/drm/dri2.c index 854801d1ea1..c632f0fe4f3 100644 --- a/src/gallium/state_trackers/dri/drm/dri2.c +++ b/src/gallium/state_trackers/dri/drm/dri2.c @@ -375,6 +375,7 @@ static const __DRIextension *dri_screen_extensions[] = { const __DRIconfig ** dri2_init_screen(__DRIscreen * sPriv) { + const __DRIconfig **configs; struct dri_screen *screen; struct drm_create_screen_arg arg; @@ -385,28 +386,22 @@ dri2_init_screen(__DRIscreen * sPriv) screen->api = drm_api_create(); screen->sPriv = sPriv; screen->fd = sPriv->fd; + sPriv->private = (void *)screen; sPriv->extensions = dri_screen_extensions; - arg.mode = DRM_CREATE_NORMAL; - screen->pipe_screen = screen->api->create_screen(screen->api, screen->fd, &arg); - if (!screen->pipe_screen) { - debug_printf("%s: failed to create pipe_screen\n", __FUNCTION__); - goto fail; - } + arg.mode = DRM_CREATE_NORMAL; - screen->smapi = dri_create_st_manager(screen); - if (!screen->smapi) + configs = dri_init_screen_helper(screen, &arg, 32); + if (!configs) goto fail; - driParseOptionInfo(&screen->optionCache, - __driConfigOptions, __driNConfigOptions); - screen->auto_fake_front = dri_with_format(sPriv); - return dri_fill_in_modes(screen, 32); + return configs; fail: - dri_destroy_screen(sPriv); + dri_destroy_screen_helper(screen); + FREE(screen); return NULL; } diff --git a/src/gallium/state_trackers/dri/sw/drisw.c b/src/gallium/state_trackers/dri/sw/drisw.c index d7c6577818f..8999ae530f2 100644 --- a/src/gallium/state_trackers/dri/sw/drisw.c +++ b/src/gallium/state_trackers/dri/sw/drisw.c @@ -282,6 +282,7 @@ static const __DRIextension *drisw_screen_extensions[] = { const __DRIconfig ** drisw_init_screen(__DRIscreen * sPriv) { + const __DRIconfig **configs; struct dri_screen *screen; struct drm_create_screen_arg arg; @@ -292,26 +293,20 @@ drisw_init_screen(__DRIscreen * sPriv) screen->api = drm_api_create(); screen->sPriv = sPriv; screen->fd = -1; + sPriv->private = (void *)screen; sPriv->extensions = drisw_screen_extensions; - arg.mode = DRM_CREATE_DRISW; - screen->pipe_screen = screen->api->create_screen(screen->api, -1, &arg); - if (!screen->pipe_screen) { - debug_printf("%s: failed to create pipe_screen\n", __FUNCTION__); - goto fail; - } + arg.mode = DRM_CREATE_DRISW; - screen->smapi = dri_create_st_manager(screen); - if (!screen->smapi) + configs = dri_init_screen_helper(screen, &arg, 32); + if (!configs) goto fail; - driParseOptionInfo(&screen->optionCache, - __driConfigOptions, __driNConfigOptions); - - return dri_fill_in_modes(screen, 32); + return configs; fail: - dri_destroy_screen(sPriv); + dri_destroy_screen_helper(screen); + FREE(screen); return NULL; } -- cgit v1.2.3 From fc35d203c70a89b723e5ebeff1918e7607d67a79 Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Fri, 26 Mar 2010 18:44:39 +0200 Subject: st/dri: add comment about the ifdef in dri_screen.c --- src/gallium/state_trackers/dri/common/dri_screen.c | 23 ++++++++++------------ 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/dri/common/dri_screen.c b/src/gallium/state_trackers/dri/common/dri_screen.c index cbd7563938e..821c1dea626 100644 --- a/src/gallium/state_trackers/dri/common/dri_screen.c +++ b/src/gallium/state_trackers/dri/common/dri_screen.c @@ -344,8 +344,11 @@ dri_init_screen_helper(struct dri_screen *screen, return dri_fill_in_modes(screen, pixel_bits); } -#ifndef __NOT_HAVE_DRM_H - +/** + * DRI driver virtual function table. + * + * DRI versions differ in their implementation of init_screen and swap_buffers. + */ const struct __DriverAPIRec driDriverAPI = { .DestroyScreen = dri_destroy_screen, .CreateContext = dri_create_context, @@ -354,6 +357,9 @@ const struct __DriverAPIRec driDriverAPI = { .DestroyBuffer = dri_destroy_buffer, .MakeCurrent = dri_make_current, .UnbindContext = dri_unbind_context, + +#ifndef __NOT_HAVE_DRM_H + .GetSwapInfo = dri_get_swap_info, .GetDrawableMSC = driDrawableGetMSC32, .WaitForMSC = driWaitForMSC32, @@ -362,23 +368,14 @@ const struct __DriverAPIRec driDriverAPI = { .InitScreen = dri1_init_screen, .SwapBuffers = dri1_swap_buffers, .CopySubBuffer = dri1_copy_sub_buffer, -}; #else -const struct __DriverAPIRec driDriverAPI = { - .DestroyScreen = dri_destroy_screen, - .CreateContext = dri_create_context, - .DestroyContext = dri_destroy_context, - .CreateBuffer = dri_create_buffer, - .DestroyBuffer = dri_destroy_buffer, - .MakeCurrent = dri_make_current, - .UnbindContext = dri_unbind_context, - .InitScreen = drisw_init_screen, .SwapBuffers = drisw_swap_buffers, -}; #endif +}; + /* vim: set sw=3 ts=8 sts=3 expandtab: */ -- cgit v1.2.3 From 3ae082f00cad3f2323a3747fe3b6f02b8f8c5285 Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Fri, 26 Mar 2010 18:44:40 +0200 Subject: swrastg: allow for any of the software rasterizers. This function should be put in targets/common or winsys/sw/common and shared with targers/libgl-xlib and winsys/sw/drm. For targets/common, you get layering violations in the build system unless all of drm_api's are moved under targets. --- src/gallium/state_trackers/dri/sw/drisw.c | 6 --- src/gallium/targets/dri-swrast/swrast_drm_api.c | 70 ++++++++++++++++++++----- src/gallium/targets/libgl-xlib/xlib.c | 64 ++++++++++++++-------- 3 files changed, 98 insertions(+), 42 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/dri/sw/drisw.c b/src/gallium/state_trackers/dri/sw/drisw.c index 8999ae530f2..745941d5501 100644 --- a/src/gallium/state_trackers/dri/sw/drisw.c +++ b/src/gallium/state_trackers/dri/sw/drisw.c @@ -48,12 +48,6 @@ * for createImage/destroyImage similar to DRI2 getBuffers. Probably not worth * it, given the scope of DRISW, unless it falls naturally from properly * solving the above two issues. - * - * swrast_create_screen: - * - * Allow for any software renderer to be used. Factor out the code from - * targets/libgl-xlib/xlib.c, put it in targets/common or winsys/sw/common and - * use it in all software targets. */ #include "util/u_memory.h" diff --git a/src/gallium/targets/dri-swrast/swrast_drm_api.c b/src/gallium/targets/dri-swrast/swrast_drm_api.c index 224651603d1..1fdfcccf883 100644 --- a/src/gallium/targets/dri-swrast/swrast_drm_api.c +++ b/src/gallium/targets/dri-swrast/swrast_drm_api.c @@ -32,6 +32,16 @@ #include "state_tracker/sw_winsys.h" #include "dri_sw_winsys.h" +/* Copied from targets/libgl-xlib. + * + * TODO: + * This function should be put in targets/common or winsys/sw/common and shared + * with targets/libgl-xlib and winsys/sw/drm. + * + * For targets/common, you get layering violations in the build system unless + * all of drm_api's are moved under targets. + */ + #ifdef GALLIUM_SOFTPIPE #include "softpipe/sp_public.h" #endif @@ -40,10 +50,51 @@ #include "llvmpipe/lp_public.h" #endif +#ifdef GALLIUM_CELL +#include "cell/ppu/cell_public.h" +#endif + static struct pipe_screen * -swrast_create_screen(struct drm_api *api, - int drmFD, - struct drm_create_screen_arg *arg) +swrast_create_screen(struct sw_winsys *winsys) +{ + const char *default_driver; + const char *driver; + struct pipe_screen *screen = NULL; + +#if defined(GALLIUM_CELL) + default_driver = "cell"; +#elif defined(GALLIUM_LLVMPIPE) + default_driver = "llvmpipe"; +#elif defined(GALLIUM_SOFTPIPE) + default_driver = "softpipe"; +#else + default_driver = ""; +#endif + + driver = debug_get_option("GALLIUM_DRIVER", default_driver); + +#if defined(GALLIUM_CELL) + if (screen == NULL && strcmp(driver, "cell") == 0) + screen = cell_create_screen( winsys ); +#endif + +#if defined(GALLIUM_LLVMPIPE) + if (screen == NULL && strcmp(driver, "llvmpipe") == 0) + screen = llvmpipe_create_screen( winsys ); +#endif + +#if defined(GALLIUM_SOFTPIPE) + if (screen == NULL) + screen = softpipe_create_screen( winsys ); +#endif + + return screen; +} + +static struct pipe_screen * +swrast_drm_create_screen(struct drm_api *api, + int drmFD, + struct drm_create_screen_arg *arg) { struct sw_winsys *winsys = NULL; struct pipe_screen *screen = NULL; @@ -63,16 +114,7 @@ swrast_create_screen(struct drm_api *api, if (winsys == NULL) return NULL; -#ifdef GALLIUM_LLVMPIPE - if (!screen) - screen = llvmpipe_create_screen(winsys); -#endif - -#ifdef GALLIUM_SOFTPIPE - if (!screen) - screen = softpipe_create_screen(winsys); -#endif - + screen = swrast_create_screen(winsys); if (!screen) goto fail; @@ -95,7 +137,7 @@ static struct drm_api swrast_drm_api = { .name = "swrast", .driver_name = "swrast", - .create_screen = swrast_create_screen, + .create_screen = swrast_drm_create_screen, .destroy = swrast_drm_api_destroy, }; diff --git a/src/gallium/targets/libgl-xlib/xlib.c b/src/gallium/targets/libgl-xlib/xlib.c index 48e79fe4f3b..4a8366280d8 100644 --- a/src/gallium/targets/libgl-xlib/xlib.c +++ b/src/gallium/targets/libgl-xlib/xlib.c @@ -31,12 +31,9 @@ * Keith Whitwell */ #include "pipe/p_compiler.h" -#include "state_tracker/xlib_sw_winsys.h" #include "util/u_debug.h" -#include "softpipe/sp_public.h" -#include "llvmpipe/lp_public.h" -#include "cell/ppu/cell_public.h" #include "target-helpers/wrap_screen.h" +#include "state_tracker/xlib_sw_winsys.h" #include "xm_public.h" #include "state_tracker/st_manager.h" @@ -49,9 +46,8 @@ PUBLIC const struct st_module st_module_OpenGL = { .create_api = st_manager_create_api }; -/* Helper function to build a subset of a driver stack consisting of - * one of the software rasterizers (cell, llvmpipe, softpipe) and the - * xlib winsys. +/* Helper function to choose and instantiate one of the software rasterizers: + * cell, llvmpipe, softpipe. * * This function could be shared, but currently causes headaches for * the build systems, particularly scons if we try. Long term, want @@ -60,21 +56,26 @@ PUBLIC const struct st_module st_module_OpenGL = { * things that are painful for it now are likely to be painful for * other build systems in the future. */ + +#ifdef GALLIUM_SOFTPIPE +#include "softpipe/sp_public.h" +#endif + +#ifdef GALLIUM_LLVMPIPE +#include "llvmpipe/lp_public.h" +#endif + +#ifdef GALLIUM_CELL +#include "cell/ppu/cell_public.h" +#endif + static struct pipe_screen * -swrast_xlib_create_screen( Display *display ) +swrast_create_screen(struct sw_winsys *winsys) { const char *default_driver; const char *driver; - struct sw_winsys *winsys; struct pipe_screen *screen = NULL; - /* Create the underlying winsys, which performs presents to Xlib - * drawables: - */ - winsys = xlib_create_sw_winsys( display ); - if (winsys == NULL) - return NULL; - #if defined(GALLIUM_CELL) default_driver = "cell"; #elif defined(GALLIUM_LLVMPIPE) @@ -87,17 +88,13 @@ swrast_xlib_create_screen( Display *display ) driver = debug_get_option("GALLIUM_DRIVER", default_driver); - /* Create a software rasterizer on top of that winsys: - */ #if defined(GALLIUM_CELL) - if (screen == NULL && - strcmp(driver, "cell") == 0) + if (screen == NULL && strcmp(driver, "cell") == 0) screen = cell_create_screen( winsys ); #endif #if defined(GALLIUM_LLVMPIPE) - if (screen == NULL && - strcmp(driver, "llvmpipe") == 0) + if (screen == NULL && strcmp(driver, "llvmpipe") == 0) screen = llvmpipe_create_screen( winsys ); #endif @@ -106,6 +103,29 @@ swrast_xlib_create_screen( Display *display ) screen = softpipe_create_screen( winsys ); #endif + return screen; +} + +/* Helper function to build a subset of a driver stack consisting of + * one of the software rasterizers (cell, llvmpipe, softpipe) and the + * xlib winsys. + */ +static struct pipe_screen * +swrast_xlib_create_screen( Display *display ) +{ + struct sw_winsys *winsys; + struct pipe_screen *screen = NULL; + + /* Create the underlying winsys, which performs presents to Xlib + * drawables: + */ + winsys = xlib_create_sw_winsys( display ); + if (winsys == NULL) + return NULL; + + /* Create a software rasterizer on top of that winsys: + */ + screen = swrast_create_screen( winsys ); if (screen == NULL) goto fail; -- cgit v1.2.3 From e9a25089f92e0cce6f72ba5e1a6c2036825290d5 Mon Sep 17 00:00:00 2001 From: Vinson Lee Date: Fri, 26 Mar 2010 14:59:06 -0700 Subject: rtasm: Silence gnu_printf format warnings. --- src/gallium/auxiliary/rtasm/rtasm_x86sse.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/gallium') diff --git a/src/gallium/auxiliary/rtasm/rtasm_x86sse.c b/src/gallium/auxiliary/rtasm/rtasm_x86sse.c index f675427d987..7595214bdf2 100644 --- a/src/gallium/auxiliary/rtasm/rtasm_x86sse.c +++ b/src/gallium/auxiliary/rtasm/rtasm_x86sse.c @@ -87,7 +87,7 @@ void x86_print_reg( struct x86_reg reg ) foo++; \ if (*foo) \ foo++; \ - debug_printf( "\n% 4x% 15s ", p->csr - p->store, foo ); \ + debug_printf( "\n%4x %14s ", p->csr - p->store, foo ); \ } while (0) #define DUMP_I( I ) do { \ -- cgit v1.2.3 From 8260e9a8217bf003f490b17cbd9df93bf0cc6675 Mon Sep 17 00:00:00 2001 From: Chris Li Date: Wed, 24 Feb 2010 17:43:38 -0800 Subject: gallium/llvmpipe: add PROGS target/rule to Makefile.template So other directory can share it. Also remove the libllvmpipe.a dependency from test programs. It is not needed any more. Signed-Off-By: Christopher Li --- src/gallium/Makefile.template | 7 +++++-- src/gallium/drivers/llvmpipe/Makefile | 14 ++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/Makefile.template b/src/gallium/Makefile.template index 91a9b54b362..b5a9938c740 100644 --- a/src/gallium/Makefile.template +++ b/src/gallium/Makefile.template @@ -26,7 +26,7 @@ INCLUDES = \ ##### TARGETS ##### -default: depend lib$(LIBNAME).a +default: depend lib$(LIBNAME).a $(PROGS) lib$(LIBNAME).a: $(OBJECTS) $(EXTRA_OBJECTS) Makefile $(TOP)/src/gallium/Makefile.template $(MKLIB) -o $(LIBNAME) -static $(OBJECTS) $(EXTRA_OBJECTS) @@ -36,13 +36,16 @@ depend: $(C_SOURCES) $(CPP_SOURCES) $(ASM_SOURCES) $(SYMLINKS) $(GENERATED_SOURC touch depend $(MKDEP) $(MKDEP_OPTIONS) $(INCLUDES) $(C_SOURCES) $(CPP_SOURCES) $(ASM_SOURCES) $(GENERATED_SOURCES) 2> /dev/null +$(PROGS): % : %.o + $(LD) $(filter %.o,$^) -o $@ -Wl,--start-group $(LIBS) -Wl,--end-group + # Emacs tags tags: etags `find . -name \*.[ch]` `find $(TOP)/src/gallium/include -name \*.h` # Remove .o and backup files clean: - rm -f $(OBJECTS) $(GENERATED_SOURCES) lib$(LIBNAME).a depend depend.bak + rm -f $(OBJECTS) $(GENERATED_SOURCES) $(PROGS) lib$(LIBNAME).a depend depend.bak # Dummy target install: diff --git a/src/gallium/drivers/llvmpipe/Makefile b/src/gallium/drivers/llvmpipe/Makefile index 89c06ea3ad7..74d728ddb39 100644 --- a/src/gallium/drivers/llvmpipe/Makefile +++ b/src/gallium/drivers/llvmpipe/Makefile @@ -42,6 +42,10 @@ C_SOURCES = \ CPP_SOURCES = \ +PROGS := lp_test_format \ + lp_test_blend \ + lp_test_conv + include ../../Makefile.template @@ -49,13 +53,7 @@ lp_tile_soa.c: lp_tile_soa.py ../../auxiliary/util/u_format_parse.py ../../auxil python lp_tile_soa.py ../../auxiliary/util/u_format.csv > $@ -testprogs := lp_test_format \ - lp_test_blend \ - lp_test_conv - -LIBS += $(GL_LIB_DEPS) -L. -lllvmpipe -L../../auxiliary/ -lgallium +LIBS += $(GL_LIB_DEPS) -L../../auxiliary/ -lgallium -#$(testprogs): lp_test_% : lp_test_%.o lp_test_main.o libllvmpipe.a -# $(LD) $(filter %.o,$^) -o $@ -Wl,--start-group $(LIBS) -Wl,--end-group +$(PROGS): lp_test_main.o -#default: $(testprogs) -- cgit v1.2.3 From 03832881325348871db1dad613bdcf8f4265a240 Mon Sep 17 00:00:00 2001 From: Vinson Lee Date: Fri, 26 Mar 2010 17:56:13 -0700 Subject: st/dri: Fix SCons build. This was missed in commit 4b722bf9fde668dff1c2b55b34eb3f86c78f43fb. dri_extensions.c was removed from Makefile but not from SConscript. --- src/gallium/state_trackers/dri/drm/SConscript | 1 - src/gallium/state_trackers/dri/sw/SConscript | 1 - 2 files changed, 2 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/dri/drm/SConscript b/src/gallium/state_trackers/dri/drm/SConscript index b974e298f36..b9726ee3113 100644 --- a/src/gallium/state_trackers/dri/drm/SConscript +++ b/src/gallium/state_trackers/dri/drm/SConscript @@ -17,7 +17,6 @@ if env['dri']: target = 'st_dri', source = [ 'dri_context.c', 'dri_drawable.c', - 'dri_extensions.c', 'dri_screen.c', 'dri_st_api.c', 'dri1_helper.c', diff --git a/src/gallium/state_trackers/dri/sw/SConscript b/src/gallium/state_trackers/dri/sw/SConscript index 0614b8f521f..c97124c8310 100644 --- a/src/gallium/state_trackers/dri/sw/SConscript +++ b/src/gallium/state_trackers/dri/sw/SConscript @@ -19,7 +19,6 @@ if env['dri']: target = 'st_drisw', source = [ 'dri_context.c', 'dri_drawable.c', - 'dri_extensions.c', 'dri_screen.c', 'dri_st_api.c', 'dri1_helper.c', -- cgit v1.2.3 From 95030062857cf8d370a0125ddf3ffc71b70c8104 Mon Sep 17 00:00:00 2001 From: Vinson Lee Date: Fri, 26 Mar 2010 18:58:44 -0700 Subject: gallium: Fix Windows SCons build. --- src/gallium/targets/libgl-gdi/SConscript | 1 + 1 file changed, 1 insertion(+) (limited to 'src/gallium') diff --git a/src/gallium/targets/libgl-gdi/SConscript b/src/gallium/targets/libgl-gdi/SConscript index 57704440ce7..21b4eb2abee 100644 --- a/src/gallium/targets/libgl-gdi/SConscript +++ b/src/gallium/targets/libgl-gdi/SConscript @@ -9,6 +9,7 @@ if env['platform'] == 'windows': env.Append(CPPPATH = [ '#src/gallium/state_trackers/wgl', + '#src/gallium/winsys/sw', ]) env.Append(LIBS = [ -- cgit v1.2.3 From 42f14a76a6e689abcc84de0aecd6f1d302020a79 Mon Sep 17 00:00:00 2001 From: Vinson Lee Date: Fri, 26 Mar 2010 23:54:16 -0700 Subject: r300g: Remove unnecessary header. --- src/gallium/drivers/r300/r300_emit.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/r300/r300_emit.c b/src/gallium/drivers/r300/r300_emit.c index 92266ba669d..c8d98997b12 100644 --- a/src/gallium/drivers/r300/r300_emit.c +++ b/src/gallium/drivers/r300/r300_emit.c @@ -33,7 +33,6 @@ #include "r300_fs.h" #include "r300_screen.h" #include "r300_screen_buffer.h" -#include "r300_state_inlines.h" #include "r300_vs.h" void r300_emit_blend_state(struct r300_context* r300, -- cgit v1.2.3 From c8844c5549dec7e9c47ab49d6e229980f62da74d Mon Sep 17 00:00:00 2001 From: Corbin Simpson Date: Sat, 27 Mar 2010 01:07:39 -0700 Subject: r300g: Make SWTCL clear work again. Kind of surprised that this was as little as it took. Worrying. --- src/gallium/drivers/r300/r300_state.c | 128 ------------------------- src/gallium/drivers/r300/r300_state_derived.c | 132 ++++++++++++++++++++++++++ 2 files changed, 132 insertions(+), 128 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/r300/r300_state.c b/src/gallium/drivers/r300/r300_state.c index 8e9285419c3..1fc9f39e273 100644 --- a/src/gallium/drivers/r300/r300_state.c +++ b/src/gallium/drivers/r300/r300_state.c @@ -1141,72 +1141,6 @@ static void r300_set_vertex_buffers(struct pipe_context* pipe, } } -static void r300_draw_emit_attrib(struct r300_context* r300, - enum attrib_emit emit, - enum interp_mode interp, - int index) -{ - struct r300_vertex_shader* vs = r300->vs_state.state; - struct tgsi_shader_info* info = &vs->info; - int output; - - output = draw_find_shader_output(r300->draw, - info->output_semantic_name[index], - info->output_semantic_index[index]); - draw_emit_vertex_attr(&r300->vertex_info, emit, interp, output); -} - -static void r300_draw_emit_all_attribs(struct r300_context* r300) -{ - struct r300_vertex_shader* vs = r300->vs_state.state; - struct r300_shader_semantics* vs_outputs = &vs->outputs; - int i, gen_count; - - /* Position. */ - if (vs_outputs->pos != ATTR_UNUSED) { - r300_draw_emit_attrib(r300, EMIT_4F, INTERP_PERSPECTIVE, - vs_outputs->pos); - } else { - assert(0); - } - - /* Point size. */ - if (vs_outputs->psize != ATTR_UNUSED) { - r300_draw_emit_attrib(r300, EMIT_1F_PSIZE, INTERP_POS, - vs_outputs->psize); - } - - /* Colors. */ - for (i = 0; i < ATTR_COLOR_COUNT; i++) { - if (vs_outputs->color[i] != ATTR_UNUSED) { - r300_draw_emit_attrib(r300, EMIT_4F, INTERP_LINEAR, - vs_outputs->color[i]); - } - } - - /* XXX Back-face colors. */ - - /* Texture coordinates. */ - gen_count = 0; - for (i = 0; i < ATTR_GENERIC_COUNT; i++) { - if (vs_outputs->generic[i] != ATTR_UNUSED) { - r300_draw_emit_attrib(r300, EMIT_4F, INTERP_PERSPECTIVE, - vs_outputs->generic[i]); - gen_count++; - } - } - - /* Fog coordinates. */ - if (vs_outputs->fog != ATTR_UNUSED) { - r300_draw_emit_attrib(r300, EMIT_4F, INTERP_PERSPECTIVE, - vs_outputs->fog); - gen_count++; - } - - /* XXX magic */ - assert(gen_count <= 8); -} - /* Update the PSC tables. */ static void r300_vertex_psc(struct r300_vertex_element_state *velems) { @@ -1246,63 +1180,6 @@ static void r300_vertex_psc(struct r300_vertex_element_state *velems) vstream->count = (i >> 1) + 1; } -/* Update the PSC tables for SW TCL, using Draw. */ -static void r300_swtcl_vertex_psc(struct r300_context *r300, - struct r300_vertex_element_state *velems) -{ - struct r300_vertex_stream_state *vstream = &velems->vertex_stream; - struct r300_vertex_shader* vs = r300->vs_state.state; - struct vertex_info* vinfo = &r300->vertex_info; - uint16_t type, swizzle; - enum pipe_format format; - unsigned i, attrib_count; - int* vs_output_tab = vs->stream_loc_notcl; - - /* For each Draw attribute, route it to the fragment shader according - * to the vs_output_tab. */ - attrib_count = vinfo->num_attribs; - DBG(r300, DBG_DRAW, "r300: attrib count: %d\n", attrib_count); - for (i = 0; i < attrib_count; i++) { - DBG(r300, DBG_DRAW, "r300: attrib: offset %d, interp %d, size %d," - " vs_output_tab %d\n", vinfo->attrib[i].src_index, - vinfo->attrib[i].interp_mode, vinfo->attrib[i].emit, - vs_output_tab[i]); - } - - for (i = 0; i < attrib_count; i++) { - /* Make sure we have a proper destination for our attribute. */ - assert(vs_output_tab[i] != -1); - - format = draw_translate_vinfo_format(vinfo->attrib[i].emit); - - /* Obtain the type of data in this attribute. */ - type = r300_translate_vertex_data_type(format) | - vs_output_tab[i] << R300_DST_VEC_LOC_SHIFT; - - /* Obtain the swizzle for this attribute. Note that the default - * swizzle in the hardware is not XYZW! */ - swizzle = r300_translate_vertex_data_swizzle(format); - - /* Add the attribute to the PSC table. */ - if (i & 1) { - vstream->vap_prog_stream_cntl[i >> 1] |= type << 16; - vstream->vap_prog_stream_cntl_ext[i >> 1] |= swizzle << 16; - } else { - vstream->vap_prog_stream_cntl[i >> 1] |= type; - vstream->vap_prog_stream_cntl_ext[i >> 1] |= swizzle; - } - } - - /* Set the last vector in the PSC. */ - if (i) { - i -= 1; - } - vstream->vap_prog_stream_cntl[i >> 1] |= - (R300_LAST_VEC << (i & 1 ? 16 : 0)); - - vstream->count = (i >> 1) + 1; -} - static void* r300_create_vertex_elements_state(struct pipe_context* pipe, unsigned count, const struct pipe_vertex_element* attribs) @@ -1334,11 +1211,6 @@ static void* r300_create_vertex_elements_state(struct pipe_context* pipe, } r300_vertex_psc(velems); - } else { - memset(&r300->vertex_info, 0, sizeof(struct vertex_info)); - r300_draw_emit_all_attribs(r300); - draw_compute_vertex_size(&r300->vertex_info); - r300_swtcl_vertex_psc(r300, velems); } } return velems; diff --git a/src/gallium/drivers/r300/r300_state_derived.c b/src/gallium/drivers/r300/r300_state_derived.c index 3560b6e427f..bc5431c802d 100644 --- a/src/gallium/drivers/r300/r300_state_derived.c +++ b/src/gallium/drivers/r300/r300_state_derived.c @@ -37,6 +37,131 @@ /* r300_state_derived: Various bits of state which are dependent upon * currently bound CSO data. */ +static void r300_draw_emit_attrib(struct r300_context* r300, + enum attrib_emit emit, + enum interp_mode interp, + int index) +{ + struct r300_vertex_shader* vs = r300->vs_state.state; + struct tgsi_shader_info* info = &vs->info; + int output; + + output = draw_find_shader_output(r300->draw, + info->output_semantic_name[index], + info->output_semantic_index[index]); + draw_emit_vertex_attr(&r300->vertex_info, emit, interp, output); +} + +static void r300_draw_emit_all_attribs(struct r300_context* r300) +{ + struct r300_vertex_shader* vs = r300->vs_state.state; + struct r300_shader_semantics* vs_outputs = &vs->outputs; + int i, gen_count; + + /* Position. */ + if (vs_outputs->pos != ATTR_UNUSED) { + r300_draw_emit_attrib(r300, EMIT_4F, INTERP_PERSPECTIVE, + vs_outputs->pos); + } else { + assert(0); + } + + /* Point size. */ + if (vs_outputs->psize != ATTR_UNUSED) { + r300_draw_emit_attrib(r300, EMIT_1F_PSIZE, INTERP_POS, + vs_outputs->psize); + } + + /* Colors. */ + for (i = 0; i < ATTR_COLOR_COUNT; i++) { + if (vs_outputs->color[i] != ATTR_UNUSED) { + r300_draw_emit_attrib(r300, EMIT_4F, INTERP_LINEAR, + vs_outputs->color[i]); + } + } + + /* XXX Back-face colors. */ + + /* Texture coordinates. */ + gen_count = 0; + for (i = 0; i < ATTR_GENERIC_COUNT; i++) { + if (vs_outputs->generic[i] != ATTR_UNUSED) { + r300_draw_emit_attrib(r300, EMIT_4F, INTERP_PERSPECTIVE, + vs_outputs->generic[i]); + gen_count++; + } + } + + /* Fog coordinates. */ + if (vs_outputs->fog != ATTR_UNUSED) { + r300_draw_emit_attrib(r300, EMIT_4F, INTERP_PERSPECTIVE, + vs_outputs->fog); + gen_count++; + } + + /* XXX magic */ + assert(gen_count <= 8); +} + +/* Update the PSC tables for SW TCL, using Draw. */ +static void r300_swtcl_vertex_psc(struct r300_context *r300) +{ + struct r300_vertex_stream_state *vstream = r300->vertex_stream_state.state; + struct r300_vertex_shader* vs = r300->vs_state.state; + struct vertex_info* vinfo = &r300->vertex_info; + uint16_t type, swizzle; + enum pipe_format format; + unsigned i, attrib_count; + int* vs_output_tab = vs->stream_loc_notcl; + + /* XXX hax */ + memset(vstream, 0, sizeof(struct r300_vertex_stream_state)); + + /* For each Draw attribute, route it to the fragment shader according + * to the vs_output_tab. */ + attrib_count = vinfo->num_attribs; + DBG(r300, DBG_DRAW, "r300: attrib count: %d\n", attrib_count); + for (i = 0; i < attrib_count; i++) { + DBG(r300, DBG_DRAW, "r300: attrib: offset %d, interp %d, size %d," + " vs_output_tab %d\n", vinfo->attrib[i].src_index, + vinfo->attrib[i].interp_mode, vinfo->attrib[i].emit, + vs_output_tab[i]); + + /* Make sure we have a proper destination for our attribute. */ + assert(vs_output_tab[i] != -1); + + format = draw_translate_vinfo_format(vinfo->attrib[i].emit); + + /* Obtain the type of data in this attribute. */ + type = r300_translate_vertex_data_type(format) | + vs_output_tab[i] << R300_DST_VEC_LOC_SHIFT; + + /* Obtain the swizzle for this attribute. Note that the default + * swizzle in the hardware is not XYZW! */ + swizzle = r300_translate_vertex_data_swizzle(format); + + /* Add the attribute to the PSC table. */ + if (i & 1) { + vstream->vap_prog_stream_cntl[i >> 1] |= type << 16; + vstream->vap_prog_stream_cntl_ext[i >> 1] |= swizzle << 16; + } else { + vstream->vap_prog_stream_cntl[i >> 1] |= type; + vstream->vap_prog_stream_cntl_ext[i >> 1] |= swizzle; + } + } + + /* Set the last vector in the PSC. */ + if (i) { + i -= 1; + } + vstream->vap_prog_stream_cntl[i >> 1] |= + (R300_LAST_VEC << (i & 1 ? 16 : 0)); + + vstream->count = (i >> 1) + 1; + r300->vertex_stream_state.dirty = TRUE; + r300->vertex_stream_state.size = (1 + vstream->count) * 2; +} + static void r300_rs_col(struct r300_rs_block* rs, int id, int ptr, boolean swizzle_0001) { @@ -400,5 +525,12 @@ void r300_update_derived_state(struct r300_context* r300) r300_merge_textures_and_samplers(r300); } + if (r300->draw) { + memset(&r300->vertex_info, 0, sizeof(struct vertex_info)); + r300_draw_emit_all_attribs(r300); + draw_compute_vertex_size(&r300->vertex_info); + r300_swtcl_vertex_psc(r300); + } + r300_update_ztop(r300); } -- cgit v1.2.3 From a43618fdc4e046f946d5f0de6dd8a421b66e9498 Mon Sep 17 00:00:00 2001 From: Mathias Fröhlich Date: Sat, 27 Mar 2010 13:40:38 +0100 Subject: r300g: fix macrotiling for non-square textures MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit FDO bug #27338. Signed-off-by: Marek Olšák --- src/gallium/drivers/r300/r300_texture.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/r300/r300_texture.c b/src/gallium/drivers/r300/r300_texture.c index 1b796257e4f..7c86bdb4bdc 100644 --- a/src/gallium/drivers/r300/r300_texture.c +++ b/src/gallium/drivers/r300/r300_texture.c @@ -692,7 +692,8 @@ static void r300_setup_miptree(struct r300_screen* screen, /* Let's see if this miplevel can be macrotiled. */ tex->mip_macrotile[i] = (tex->macrotile == R300_BUFFER_TILED && - r300_texture_macro_switch(tex, i, rv350_mode, TILE_WIDTH)) ? + r300_texture_macro_switch(tex, i, rv350_mode, TILE_WIDTH) && + r300_texture_macro_switch(tex, i, rv350_mode, TILE_HEIGHT)) ? R300_BUFFER_TILED : R300_BUFFER_LINEAR; stride = r300_texture_get_stride(screen, tex, i); -- cgit v1.2.3 From 077570c12b01bafb71c145225e6e08f26b6f8f96 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Sat, 27 Mar 2010 22:25:26 +0800 Subject: st/egl: Fix missing symbols. ximage backend calls gallium_wrap_screen, which requires libidentity.a and libtrace.a. There are also some missing symbols in i965 due to the use of sw wrapper. --- src/gallium/targets/Makefile.egl | 8 +++++++- src/gallium/targets/egl-i915/Makefile | 1 - src/gallium/targets/egl-i965/Makefile | 6 ++++-- src/gallium/targets/egl-nouveau/Makefile | 3 +-- src/gallium/targets/egl-radeon/Makefile | 1 - src/gallium/targets/egl-swrast/Makefile | 2 +- src/gallium/targets/egl-vmwgfx/Makefile | 1 - 7 files changed, 13 insertions(+), 9 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/targets/Makefile.egl b/src/gallium/targets/Makefile.egl index 30fced7e3c8..9265e2eb7bc 100644 --- a/src/gallium/targets/Makefile.egl +++ b/src/gallium/targets/Makefile.egl @@ -13,8 +13,14 @@ EGL_DRIVER_OBJECTS = $(EGL_DRIVER_SOURCES:.c=.o) common_LIBS = -ldrm -lm -ldl +# ximage backend calls gallium_wrap_screen, which requires libidentity.a and +# libtrace.a x11_ST = $(TOP)/src/gallium/state_trackers/egl/libeglx11.a \ - $(TOP)/src/gallium/winsys/sw/xlib/libws_xlib.a + $(TOP)/src/gallium/winsys/sw/xlib/libws_xlib.a \ + $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ + $(TOP)/src/gallium/drivers/identity/libidentity.a \ + $(TOP)/src/gallium/drivers/trace/libtrace.a + x11_LIBS = $(common_LIBS) -lX11 -lXext -lXfixes kms_ST = $(TOP)/src/gallium/state_trackers/egl/libeglkms.a diff --git a/src/gallium/targets/egl-i915/Makefile b/src/gallium/targets/egl-i915/Makefile index efaf7b0bef9..02258fb69a4 100644 --- a/src/gallium/targets/egl-i915/Makefile +++ b/src/gallium/targets/egl-i915/Makefile @@ -7,7 +7,6 @@ EGL_DRIVER_LIBS = -ldrm_intel EGL_DRIVER_PIPES = \ $(TOP)/src/gallium/winsys/i915/drm/libi915drm.a \ - $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ $(TOP)/src/gallium/drivers/trace/libtrace.a \ $(TOP)/src/gallium/drivers/i915/libi915.a diff --git a/src/gallium/targets/egl-i965/Makefile b/src/gallium/targets/egl-i965/Makefile index dfb3cc45a7d..fad56ef5554 100644 --- a/src/gallium/targets/egl-i965/Makefile +++ b/src/gallium/targets/egl-i965/Makefile @@ -7,8 +7,10 @@ EGL_DRIVER_LIBS = -ldrm_intel EGL_DRIVER_PIPES = \ $(TOP)/src/gallium/winsys/i965/drm/libi965drm.a \ - $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ $(TOP)/src/gallium/drivers/trace/libtrace.a \ - $(TOP)/src/gallium/drivers/i965/libi965.a + $(TOP)/src/gallium/drivers/i965/libi965.a \ + $(TOP)/src/gallium/winsys/sw/drm/libswdrm.a \ + $(TOP)/src/gallium/winsys/sw/wrapper/libwsw.a \ + $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a include ../Makefile.egl diff --git a/src/gallium/targets/egl-nouveau/Makefile b/src/gallium/targets/egl-nouveau/Makefile index 3da93790f25..e3fa8937e83 100644 --- a/src/gallium/targets/egl-nouveau/Makefile +++ b/src/gallium/targets/egl-nouveau/Makefile @@ -9,7 +9,6 @@ EGL_DRIVER_PIPES = \ $(TOP)/src/gallium/winsys/nouveau/drm/libnouveaudrm.a \ $(TOP)/src/gallium/drivers/nvfx/libnvfx.a \ $(TOP)/src/gallium/drivers/nv50/libnv50.a \ - $(TOP)/src/gallium/drivers/nouveau/libnouveau.a \ - $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a + $(TOP)/src/gallium/drivers/nouveau/libnouveau.a include ../Makefile.egl diff --git a/src/gallium/targets/egl-radeon/Makefile b/src/gallium/targets/egl-radeon/Makefile index f55d84de810..8daadb59791 100644 --- a/src/gallium/targets/egl-radeon/Makefile +++ b/src/gallium/targets/egl-radeon/Makefile @@ -7,7 +7,6 @@ EGL_DRIVER_LIBS = -ldrm_radeon EGL_DRIVER_PIPES = \ $(TOP)/src/gallium/winsys/radeon/drm/libradeonwinsys.a \ - $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ $(TOP)/src/gallium/drivers/trace/libtrace.a \ $(TOP)/src/gallium/drivers/r300/libr300.a diff --git a/src/gallium/targets/egl-swrast/Makefile b/src/gallium/targets/egl-swrast/Makefile index 937343defe5..7d4f5054983 100644 --- a/src/gallium/targets/egl-swrast/Makefile +++ b/src/gallium/targets/egl-swrast/Makefile @@ -7,6 +7,6 @@ CFLAGS+="-I$(TOP)/src/gallium/include" EGL_DRIVER_NAME = swrast EGL_DRIVER_SOURCES = swrast_glue.c EGL_DRIVER_LIBS = -EGL_DRIVER_PIPES = $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a +EGL_DRIVER_PIPES = include ../Makefile.egl diff --git a/src/gallium/targets/egl-vmwgfx/Makefile b/src/gallium/targets/egl-vmwgfx/Makefile index 6db12e03a75..5f9385f42b0 100644 --- a/src/gallium/targets/egl-vmwgfx/Makefile +++ b/src/gallium/targets/egl-vmwgfx/Makefile @@ -7,7 +7,6 @@ EGL_DRIVER_LIBS = EGL_DRIVER_PIPES = \ $(TOP)/src/gallium/winsys/svga/drm/libsvgadrm.a \ - $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ $(TOP)/src/gallium/drivers/trace/libtrace.a \ $(TOP)/src/gallium/drivers/svga/libsvga.a -- cgit v1.2.3 From 02ee7c29502966dffa44243bfc8c20c15907b880 Mon Sep 17 00:00:00 2001 From: Vinson Lee Date: Sat, 27 Mar 2010 10:07:14 -0700 Subject: identity: Add id_drm.c to SCons build. This was missed in commit f7cbaae13d67c55abe81ac230de37f564365099f. --- src/gallium/drivers/identity/SConscript | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/identity/SConscript b/src/gallium/drivers/identity/SConscript index 7f079dd0a8b..2a68891c284 100644 --- a/src/gallium/drivers/identity/SConscript +++ b/src/gallium/drivers/identity/SConscript @@ -5,9 +5,10 @@ env = env.Clone() identity = env.ConvenienceLibrary( target = 'identity', source = [ - 'id_screen.c', 'id_context.c', + 'id_drm.c', 'id_objects.c', + 'id_screen.c', ]) Export('identity') -- cgit v1.2.3 From f4e561ce127cf484d7c76c29b8cd026c9ad5cebc Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Sat, 27 Mar 2010 20:32:52 +0200 Subject: drisw: make stride issue profound --- include/GL/internal/dri_interface.h | 12 ++-- src/gallium/state_trackers/dri/sw/drisw.c | 10 ++-- src/gallium/winsys/sw/dri/dri_sw_winsys.c | 6 +- src/glx/drisw_glx.c | 92 ++++++++++++++++++++----------- src/mesa/drivers/dri/swrast/swrast.c | 18 ++++-- src/mesa/drivers/dri/swrast/swrast_priv.h | 8 --- 6 files changed, 88 insertions(+), 58 deletions(-) (limited to 'src/gallium') diff --git a/include/GL/internal/dri_interface.h b/include/GL/internal/dri_interface.h index aa56eb45d79..fa9b7c4bf21 100644 --- a/include/GL/internal/dri_interface.h +++ b/include/GL/internal/dri_interface.h @@ -416,15 +416,15 @@ struct __DRIswrastLoaderExtensionRec { * Put image to drawable */ void (*putImage)(__DRIdrawable *drawable, int op, - int x, int y, int width, int height, char *data, - void *loaderPrivate); + int x, int y, int width, int height, + char *data, void *loaderPrivate); /** - * Get image from drawable + * Get image from readable */ - void (*getImage)(__DRIdrawable *drawable, - int x, int y, int width, int height, char *data, - void *loaderPrivate); + void (*getImage)(__DRIdrawable *readable, + int x, int y, int width, int height, + char *data, void *loaderPrivate); }; /** diff --git a/src/gallium/state_trackers/dri/sw/drisw.c b/src/gallium/state_trackers/dri/sw/drisw.c index 745941d5501..a75fdf17899 100644 --- a/src/gallium/state_trackers/dri/sw/drisw.c +++ b/src/gallium/state_trackers/dri/sw/drisw.c @@ -38,16 +38,16 @@ * * drisw_api: * - * Define drisw_api similarly to dri_api and use it to call the loader. This is - * predicated on support for calling the loader from the winsys, which has to - * grow for DRI2 as well. + * Define drisw_api similarly to dri1_api and use it to call the loader. This + * is predicated on support for calling the loader from the winsys, which has + * to grow for DRI2 as well. * - * xshm: + * xshm / texture_from_pixmap / EGLImage: * * Allow the loaders to use the XSHM extension. It probably requires callbacks * for createImage/destroyImage similar to DRI2 getBuffers. Probably not worth * it, given the scope of DRISW, unless it falls naturally from properly - * solving the above two issues. + * solving the other issues. */ #include "util/u_memory.h" diff --git a/src/gallium/winsys/sw/dri/dri_sw_winsys.c b/src/gallium/winsys/sw/dri/dri_sw_winsys.c index 5549e152ee8..9e8c31282d4 100644 --- a/src/gallium/winsys/sw/dri/dri_sw_winsys.c +++ b/src/gallium/winsys/sw/dri/dri_sw_winsys.c @@ -63,11 +63,11 @@ xm_is_displaytarget_format_supported( struct sw_winsys *ws, } static INLINE int -bytes_per_line(unsigned stride, unsigned mul) +bytes_per_line(unsigned pitch_bits, unsigned mul) { unsigned mask = mul - 1; - return ((stride * 8 + mask) & ~mask) / 8; + return ((pitch_bits + mask) & ~mask) / 8; } /* pipe_screen::texture_create DISPLAY_TARGET / SCANOUT / SHARED */ @@ -88,7 +88,7 @@ xm_displaytarget_create(struct sw_winsys *winsys, format_stride = util_format_get_stride(format, width); xm_stride = align(format_stride, alignment); - loader_stride = bytes_per_line(format_stride, 32); + loader_stride = bytes_per_line(format_stride * 8, 32); nblocksy = util_format_get_nblocksy(format, height); size = xm_stride * nblocksy; diff --git a/src/glx/drisw_glx.c b/src/glx/drisw_glx.c index 99f8f2cbf06..ca85ae3a313 100644 --- a/src/glx/drisw_glx.c +++ b/src/glx/drisw_glx.c @@ -53,7 +53,6 @@ struct __GLXDRIdrawablePrivateRec XVisualInfo *visinfo; XImage *ximage; - int bpp; }; /** @@ -90,13 +89,10 @@ XCreateDrawable(__GLXDRIdrawablePrivate * pdp, pdp->visinfo->depth, ZPixmap, 0, /* format, offset */ NULL, /* data */ - 0, 0, /* size */ - 32, /* bitmap_pad */ + 0, 0, /* width, height */ + 8, /* bitmap_pad */ 0); /* bytes_per_line */ - /* get the true number of bits per pixel */ - pdp->bpp = pdp->ximage->bits_per_pixel; - return True; } @@ -112,7 +108,8 @@ XDestroyDrawable(__GLXDRIdrawablePrivate * pdp, Display * dpy, XID drawable) static void swrastGetDrawableInfo(__DRIdrawable * draw, - int *x, int *y, int *w, int *h, void *loaderPrivate) + int *x, int *y, int *w, int *h, + void *loaderPrivate) { __GLXDRIdrawablePrivate *pdp = loaderPrivate; __GLXDRIdrawable *pdraw = &(pdp->base); @@ -121,26 +118,20 @@ swrastGetDrawableInfo(__DRIdrawable * draw, Window root; Status stat; - unsigned int bw, depth; + unsigned uw, uh, bw, depth; drawable = pdraw->xDrawable; stat = XGetGeometry(dpy, drawable, &root, - x, y, (unsigned int *) w, (unsigned int *) h, - &bw, &depth); -} - -static inline int -bytes_per_line(int w, int bpp, unsigned mul) -{ - unsigned mask = mul - 1; - - return ((w * bpp + mask) & ~mask) / 8; + x, y, &uw, &uh, &bw, &depth); + *w = uw; + *h = uh; } static void -swrastPutImage(__DRIdrawable * draw, int op, - int x, int y, int w, int h, char *data, void *loaderPrivate) +swrastPutImage2(__DRIdrawable * draw, int op, + int x, int y, int w, int h, + char *data, int pitch, void *loaderPrivate) { __GLXDRIdrawablePrivate *pdp = loaderPrivate; __GLXDRIdrawable *pdraw = &(pdp->base); @@ -166,7 +157,7 @@ swrastPutImage(__DRIdrawable * draw, int op, ximage->data = data; ximage->width = w; ximage->height = h; - ximage->bytes_per_line = bytes_per_line(w, pdp->bpp, 32); + ximage->bytes_per_line = pitch; XPutImage(dpy, drawable, gc, ximage, 0, 0, x, y, w, h); @@ -174,28 +165,67 @@ swrastPutImage(__DRIdrawable * draw, int op, } static void -swrastGetImage(__DRIdrawable * draw, - int x, int y, int w, int h, char *data, void *loaderPrivate) +swrastGetImage2(__DRIdrawable * read, + int x, int y, int w, int h, + char *data, int pitch, void *loaderPrivate) { - __GLXDRIdrawablePrivate *pdp = loaderPrivate; - __GLXDRIdrawable *pdraw = &(pdp->base); - Display *dpy = pdraw->psc->dpy; - Drawable drawable; + __GLXDRIdrawablePrivate *prp = loaderPrivate; + __GLXDRIdrawable *pread = &(prp->base); + Display *dpy = pread->psc->dpy; + Drawable readable; XImage *ximage; - drawable = pdraw->xDrawable; + readable = pread->xDrawable; - ximage = pdp->ximage; + ximage = prp->ximage; ximage->data = data; ximage->width = w; ximage->height = h; - ximage->bytes_per_line = bytes_per_line(w, pdp->bpp, 32); + ximage->bytes_per_line = pitch; - XGetSubImage(dpy, drawable, x, y, w, h, ~0L, ZPixmap, ximage, 0, 0); + XGetSubImage(dpy, readable, x, y, w, h, ~0L, ZPixmap, ximage, 0, 0); ximage->data = NULL; } +static inline int +bytes_per_line(unsigned pitch_bits, unsigned mul) +{ + unsigned mask = mul - 1; + + return ((pitch_bits + mask) & ~mask) / 8; +} + +static void +swrastPutImage(__DRIdrawable * draw, int op, + int x, int y, int w, int h, + char *data, void *loaderPrivate) +{ + __GLXDRIdrawablePrivate *pdp = loaderPrivate; + int bpp, pitch; + + bpp = pdp->ximage->bits_per_pixel; + + pitch = bytes_per_line(w * bpp, 32); + + swrastPutImage2(draw, op, x, y, w, h, data, pitch, loaderPrivate); +} + +static void +swrastGetImage(__DRIdrawable * read, + int x, int y, int w, int h, + char *data, void *loaderPrivate) +{ + __GLXDRIdrawablePrivate *prp = loaderPrivate; + int bpp, pitch; + + bpp = prp->ximage->bits_per_pixel; + + pitch = bytes_per_line(w * bpp, 32); + + swrastGetImage2(read, x, y, w, h, data, pitch, loaderPrivate); +} + static const __DRIswrastLoaderExtension swrastLoaderExtension = { {__DRI_SWRAST_LOADER, __DRI_SWRAST_LOADER_VERSION}, swrastGetDrawableInfo, diff --git a/src/mesa/drivers/dri/swrast/swrast.c b/src/mesa/drivers/dri/swrast/swrast.c index e9ca99a86f0..e8df26f3d06 100644 --- a/src/mesa/drivers/dri/swrast/swrast.c +++ b/src/mesa/drivers/dri/swrast/swrast.c @@ -206,12 +206,19 @@ swrast_delete_renderbuffer(struct gl_renderbuffer *rb) free(rb); } +static INLINE int +bytes_per_line(unsigned pitch_bits, unsigned mul) +{ + unsigned mask = mul - 1; + + return ((pitch_bits + mask) & ~mask) / 8; +} + static GLboolean swrast_alloc_front_storage(GLcontext *ctx, struct gl_renderbuffer *rb, GLenum internalFormat, GLuint width, GLuint height) { struct swrast_renderbuffer *xrb = swrast_renderbuffer(rb); - unsigned mask = PITCH_ALIGN_BITS - 1; TRACE; @@ -219,8 +226,7 @@ swrast_alloc_front_storage(GLcontext *ctx, struct gl_renderbuffer *rb, rb->Width = width; rb->Height = height; - /* always pad to PITCH_ALIGN_BITS */ - xrb->pitch = ((width * xrb->bpp + mask) & ~mask) / 8; + xrb->pitch = bytes_per_line(width * xrb->bpp, 32); return GL_TRUE; } @@ -394,8 +400,10 @@ dri_swap_buffers(__DRIdrawable * dPriv) fb = &drawable->Base; - frontrb = swrast_renderbuffer(fb->Attachment[BUFFER_FRONT_LEFT].Renderbuffer); - backrb = swrast_renderbuffer(fb->Attachment[BUFFER_BACK_LEFT].Renderbuffer); + frontrb = + swrast_renderbuffer(fb->Attachment[BUFFER_FRONT_LEFT].Renderbuffer); + backrb = + swrast_renderbuffer(fb->Attachment[BUFFER_BACK_LEFT].Renderbuffer); /* check for signle-buffered */ if (backrb == NULL) diff --git a/src/mesa/drivers/dri/swrast/swrast_priv.h b/src/mesa/drivers/dri/swrast/swrast_priv.h index 007642be95f..6679061a983 100644 --- a/src/mesa/drivers/dri/swrast/swrast_priv.h +++ b/src/mesa/drivers/dri/swrast/swrast_priv.h @@ -124,14 +124,6 @@ swrast_renderbuffer(struct gl_renderbuffer *rb) #define PF_R3G3B2 3 /**< 8bpp TrueColor: 3-R, 3-G, 2-B bits */ #define PF_X8R8G8B8 4 /**< 32bpp TrueColor: 8-R, 8-G, 8-B bits */ -/** - * Renderbuffer pitch alignment (in bits). - * - * The xorg loader requires padding images to 32 bits. However, this should - * become a screen/drawable parameter XXX - */ -#define PITCH_ALIGN_BITS 32 - /* swrast_span.c */ -- cgit v1.2.3 From 3bfa23317c6b1b52ec637a03a0b623228ffc95ef Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Sat, 27 Mar 2010 21:35:25 +0200 Subject: drisw: add comment to libGL about stride --- src/gallium/winsys/sw/dri/dri_sw_winsys.c | 1 + src/glx/drisw_glx.c | 10 +++++++++- src/mesa/drivers/dri/swrast/swrast.c | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) (limited to 'src/gallium') diff --git a/src/gallium/winsys/sw/dri/dri_sw_winsys.c b/src/gallium/winsys/sw/dri/dri_sw_winsys.c index 9e8c31282d4..ee8ec91bc52 100644 --- a/src/gallium/winsys/sw/dri/dri_sw_winsys.c +++ b/src/gallium/winsys/sw/dri/dri_sw_winsys.c @@ -62,6 +62,7 @@ xm_is_displaytarget_format_supported( struct sw_winsys *ws, return TRUE; } +/* see bytes_per_line in libGL */ static INLINE int bytes_per_line(unsigned pitch_bits, unsigned mul) { diff --git a/src/glx/drisw_glx.c b/src/glx/drisw_glx.c index ca85ae3a313..5a47e4a097f 100644 --- a/src/glx/drisw_glx.c +++ b/src/glx/drisw_glx.c @@ -90,7 +90,7 @@ XCreateDrawable(__GLXDRIdrawablePrivate * pdp, ZPixmap, 0, /* format, offset */ NULL, /* data */ 0, 0, /* width, height */ - 8, /* bitmap_pad */ + 32, /* bitmap_pad */ 0); /* bytes_per_line */ return True; @@ -188,6 +188,14 @@ swrastGetImage2(__DRIdrawable * read, ximage->data = NULL; } +/** + * Renderbuffer pitch alignment (in bits). + * + * This should be chosen by the driver and the loader (libGL, xserver/glx) + * should use the driver provided pitch. I had a comment that the xserver + * requires padding images to 32 bits. Is this a hard requirement or can it use + * the driver pitch without extra copies ? XXX + */ static inline int bytes_per_line(unsigned pitch_bits, unsigned mul) { diff --git a/src/mesa/drivers/dri/swrast/swrast.c b/src/mesa/drivers/dri/swrast/swrast.c index e8df26f3d06..8b68281fab0 100644 --- a/src/mesa/drivers/dri/swrast/swrast.c +++ b/src/mesa/drivers/dri/swrast/swrast.c @@ -206,6 +206,7 @@ swrast_delete_renderbuffer(struct gl_renderbuffer *rb) free(rb); } +/* see bytes_per_line in libGL */ static INLINE int bytes_per_line(unsigned pitch_bits, unsigned mul) { -- cgit v1.2.3 From 1b5b04de75f73f0c622429a412f584a368a0803f Mon Sep 17 00:00:00 2001 From: Vinson Lee Date: Sat, 27 Mar 2010 10:07:14 -0700 Subject: identity: Add id_drm.c to SCons build. This was missed in commit f7cbaae13d67c55abe81ac230de37f564365099f. (cherry picked from commit 02ee7c29502966dffa44243bfc8c20c15907b880) --- src/gallium/drivers/identity/SConscript | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/identity/SConscript b/src/gallium/drivers/identity/SConscript index 7f079dd0a8b..2a68891c284 100644 --- a/src/gallium/drivers/identity/SConscript +++ b/src/gallium/drivers/identity/SConscript @@ -5,9 +5,10 @@ env = env.Clone() identity = env.ConvenienceLibrary( target = 'identity', source = [ - 'id_screen.c', 'id_context.c', + 'id_drm.c', 'id_objects.c', + 'id_screen.c', ]) Export('identity') -- cgit v1.2.3 From 1bf67a3b3f220493484fa675b00cb6bf257a0a81 Mon Sep 17 00:00:00 2001 From: Vinson Lee Date: Sat, 27 Mar 2010 14:25:03 -0700 Subject: i965g: Add brw_winsys_debug.c to SCons build. --- src/gallium/drivers/i965/SConscript | 1 + 1 file changed, 1 insertion(+) (limited to 'src/gallium') diff --git a/src/gallium/drivers/i965/SConscript b/src/gallium/drivers/i965/SConscript index 9c2faaf4b49..d900ea25968 100644 --- a/src/gallium/drivers/i965/SConscript +++ b/src/gallium/drivers/i965/SConscript @@ -58,6 +58,7 @@ i965 = env.ConvenienceLibrary( 'brw_vs_emit.c', 'brw_vs_state.c', 'brw_vs_surface_state.c', + 'brw_winsys_debug.c', 'brw_wm.c', # 'brw_wm_constant_buffer.c', 'brw_wm_debug.c', -- cgit v1.2.3 From 4b8d3480764daf45cbbc03d76cd8b7c81937f532 Mon Sep 17 00:00:00 2001 From: Marek Olšák Date: Sat, 27 Mar 2010 22:25:13 +0100 Subject: r300g: print errors even on non-debug builds We really need to get these into bug reports. --- src/gallium/drivers/r300/r300_chipset.c | 7 ++--- src/gallium/drivers/r300/r300_debug.c | 12 ++++++--- src/gallium/drivers/r300/r300_emit.c | 12 ++++----- src/gallium/drivers/r300/r300_fs.c | 5 ++-- src/gallium/drivers/r300/r300_query.c | 6 +++-- src/gallium/drivers/r300/r300_screen.c | 6 ++--- src/gallium/drivers/r300/r300_state.c | 7 +++-- src/gallium/drivers/r300/r300_state_inlines.h | 38 ++++++++++++++------------- src/gallium/drivers/r300/r300_tgsi_to_rc.c | 3 ++- src/gallium/drivers/r300/r300_vs.c | 2 +- 10 files changed, 53 insertions(+), 45 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/r300/r300_chipset.c b/src/gallium/drivers/r300/r300_chipset.c index 92de297ef1d..41719862635 100644 --- a/src/gallium/drivers/r300/r300_chipset.c +++ b/src/gallium/drivers/r300/r300_chipset.c @@ -24,6 +24,8 @@ #include "util/u_debug.h" +#include + /* r300_chipset: A file all to itself for deducing the various properties of * Radeons. */ @@ -365,8 +367,7 @@ void r300_parse_chipset(struct r300_capabilities* caps) break; default: - debug_printf("r300: Warning: Unknown chipset 0x%x\n", - caps->pci_id); - break; + fprintf(stderr, "r300: Warning: Unknown chipset 0x%x\n", + caps->pci_id); } } diff --git a/src/gallium/drivers/r300/r300_debug.c b/src/gallium/drivers/r300/r300_debug.c index d6177577c8d..016e8d66061 100644 --- a/src/gallium/drivers/r300/r300_debug.c +++ b/src/gallium/drivers/r300/r300_debug.c @@ -22,6 +22,7 @@ #include "r300_context.h" +#include struct debug_option { const char * name; @@ -69,7 +70,7 @@ void r300_init_debug(struct r300_screen * screen) } if (!opt->name) { - debug_printf("Unknown debug option: %s\n", options); + fprintf(stderr, "Unknown debug option: %s\n", options); printhint = TRUE; } @@ -81,10 +82,13 @@ void r300_init_debug(struct r300_screen * screen) } if (printhint || screen->debug & DBG_HELP) { - debug_printf("You can enable debug output by setting the RADEON_DEBUG environment variable\n" - "to a comma-separated list of debug options. Available options are:\n"); + fprintf(stderr, "You can enable debug output by setting " + "the RADEON_DEBUG environment variable\n" + "to a comma-separated list of debug options. " + "Available options are:\n"); + for(opt = debug_options; opt->name; ++opt) { - debug_printf(" %s: %s\n", opt->name, opt->description); + fprintf(stderr, " %s: %s\n", opt->name, opt->description); } } } diff --git a/src/gallium/drivers/r300/r300_emit.c b/src/gallium/drivers/r300/r300_emit.c index c8d98997b12..15bcf8907f3 100644 --- a/src/gallium/drivers/r300/r300_emit.c +++ b/src/gallium/drivers/r300/r300_emit.c @@ -186,13 +186,13 @@ static const float * get_shader_constant( break; default: - debug_printf("r300: Implementation error: " + fprintf(stderr, "r300: Implementation error: " "Unknown RC_CONSTANT type %d\n", constant->u.State[0]); } break; default: - debug_printf("r300: Implementation error: " + fprintf(stderr, "r300: Implementation error: " "Unhandled constant type %d\n", constant->Type); } @@ -514,9 +514,9 @@ static void r300_emit_query_finish(struct r300_context *r300, 0, RADEON_GEM_DOMAIN_GTT, 0); break; default: - debug_printf("r300: Implementation error: Chipset reports %d" + fprintf(stderr, "r300: Implementation error: Chipset reports %d" " pixel pipes!\n", caps->num_frag_pipes); - assert(0); + abort(); } /* And, finally, reset it to normal... */ @@ -1077,8 +1077,8 @@ validate: r300->context.flush(&r300->context, 0, NULL); if (invalid) { /* Well, hell. */ - debug_printf("r300: Stuck in validation loop, gonna quit now."); - exit(1); + fprintf(stderr, "r300: Stuck in validation loop, gonna quit now.\n"); + abort(); } invalid = TRUE; goto validate; diff --git a/src/gallium/drivers/r300/r300_fs.c b/src/gallium/drivers/r300/r300_fs.c index 9e71e61c303..e23fef8c9f7 100644 --- a/src/gallium/drivers/r300/r300_fs.c +++ b/src/gallium/drivers/r300/r300_fs.c @@ -204,9 +204,8 @@ static void r300_translate_fragment_shader( r3xx_compile_fragment_program(&compiler); if (compiler.Base.Error) { /* XXX failover maybe? */ - DBG(r300, DBG_FP, "r300: Error compiling fragment program: %s\n", - compiler.Base.ErrorMsg); - assert(0); + fprintf(stderr, "r300 FP: Compiler Error:\n%s", + compiler.Base.ErrorMsg); abort(); } diff --git a/src/gallium/drivers/r300/r300_query.c b/src/gallium/drivers/r300/r300_query.c index 9822e6b48dd..f8b52d593d5 100644 --- a/src/gallium/drivers/r300/r300_query.c +++ b/src/gallium/drivers/r300/r300_query.c @@ -30,6 +30,8 @@ #include "r300_query.h" #include "r300_reg.h" +#include + static struct pipe_query *r300_create_query(struct pipe_context *pipe, unsigned query_type) { @@ -137,8 +139,8 @@ static boolean r300_get_query_result(struct pipe_context* pipe, if (*map == ~0U) { /* Looks like our results aren't ready yet. */ if (wait) { - debug_printf("r300: Despite waiting, OQ results haven't" - " come in yet.\n"); + fprintf(stderr, "r300: Despite waiting, OQ results haven't " + "come in yet.\n"); } temp = ~0U; break; diff --git a/src/gallium/drivers/r300/r300_screen.c b/src/gallium/drivers/r300/r300_screen.c index bcb8b20f736..e46f836dd2c 100644 --- a/src/gallium/drivers/r300/r300_screen.c +++ b/src/gallium/drivers/r300/r300_screen.c @@ -164,7 +164,7 @@ static int r300_get_param(struct pipe_screen* pscreen, int param) case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER: return 0; default: - debug_printf("r300: Implementation error: Bad param %d\n", + fprintf(stderr, "r300: Implementation error: Bad param %d\n", param); return 0; } @@ -193,7 +193,7 @@ static float r300_get_paramf(struct pipe_screen* pscreen, int param) case PIPE_CAP_MAX_TEXTURE_LOD_BIAS: return 16.0f; default: - debug_printf("r300: Implementation error: Bad paramf %d\n", + fprintf(stderr, "r300: Implementation error: Bad paramf %d\n", param); return 0.0f; } @@ -212,7 +212,7 @@ static boolean r300_is_format_supported(struct pipe_screen* screen, boolean is_color2101010 = format == PIPE_FORMAT_R10G10B10A2_UNORM; if (target >= PIPE_MAX_TEXTURE_TYPES) { - debug_printf("r300: Implementation error: Received bogus texture " + fprintf(stderr, "r300: Implementation error: Received bogus texture " "target %d in %s\n", target, __FUNCTION__); return FALSE; } diff --git a/src/gallium/drivers/r300/r300_state.c b/src/gallium/drivers/r300/r300_state.c index 1fc9f39e273..b7b5e1ef03b 100644 --- a/src/gallium/drivers/r300/r300_state.c +++ b/src/gallium/drivers/r300/r300_state.c @@ -575,9 +575,8 @@ static void unsigned max_width, max_height; uint32_t zbuffer_bpp = 0; - if (state->nr_cbufs > 4) { - debug_printf("r300: Implementation error: Too many MRTs in %s, " + fprintf(stderr, "r300: Implementation error: Too many MRTs in %s, " "refusing to bind framebuffer state!\n", __FUNCTION__); return; } @@ -591,7 +590,7 @@ static void } if (state->width > max_width || state->height > max_height) { - debug_printf("r300: Implementation error: Render targets are too " + fprintf(stderr, "r300: Implementation error: Render targets are too " "big in %s, refusing to bind framebuffer state!\n", __FUNCTION__); return; } @@ -1353,7 +1352,7 @@ static void r300_set_constant_buffer(struct pipe_context *pipe, /* XXX Subtract immediates and RC_STATE_* variables. */ if (buf->size > (sizeof(float) * 4 * max_size)) { - debug_printf("r300: Max size of the constant buffer is " + fprintf(stderr, "r300: Max size of the constant buffer is " "%i*4 floats.\n", max_size); abort(); } diff --git a/src/gallium/drivers/r300/r300_state_inlines.h b/src/gallium/drivers/r300/r300_state_inlines.h index 8485d4f8f94..02d09c008c8 100644 --- a/src/gallium/drivers/r300/r300_state_inlines.h +++ b/src/gallium/drivers/r300/r300_state_inlines.h @@ -32,6 +32,8 @@ #include "r300_reg.h" +#include + /* Some maths. These should probably find their way to u_math, if needed. */ static INLINE int pack_float_16_6x(float f) { @@ -54,7 +56,7 @@ static INLINE uint32_t r300_translate_blend_function(int blend_func) case PIPE_BLEND_MAX: return R300_COMB_FCN_MAX; default: - debug_printf("r300: Unknown blend function %d\n", blend_func); + fprintf(stderr, "r300: Unknown blend function %d\n", blend_func); assert(0); break; } @@ -100,13 +102,13 @@ static INLINE uint32_t r300_translate_blend_factor(int blend_fact) case PIPE_BLENDFACTOR_SRC1_ALPHA: case PIPE_BLENDFACTOR_INV_SRC1_COLOR: case PIPE_BLENDFACTOR_INV_SRC1_ALPHA: - debug_printf("r300: Implementation error: " + fprintf(stderr, "r300: Implementation error: " "Bad blend factor %d not supported!\n", blend_fact); assert(0); break; default: - debug_printf("r300: Unknown blend factor %d\n", blend_fact); + fprintf(stderr, "r300: Unknown blend factor %d\n", blend_fact); assert(0); break; } @@ -135,7 +137,7 @@ static INLINE uint32_t r300_translate_depth_stencil_function(int zs_func) case PIPE_FUNC_ALWAYS: return R300_ZS_ALWAYS; default: - debug_printf("r300: Unknown depth/stencil function %d\n", + fprintf(stderr, "r300: Unknown depth/stencil function %d\n", zs_func); assert(0); break; @@ -163,7 +165,7 @@ static INLINE uint32_t r300_translate_stencil_op(int s_op) case PIPE_STENCIL_OP_INVERT: return R300_ZS_INVERT; default: - debug_printf("r300: Unknown stencil op %d", s_op); + fprintf(stderr, "r300: Unknown stencil op %d", s_op); assert(0); break; } @@ -190,7 +192,7 @@ static INLINE uint32_t r300_translate_alpha_function(int alpha_func) case PIPE_FUNC_ALWAYS: return R300_FG_ALPHA_FUNC_ALWAYS; default: - debug_printf("r300: Unknown alpha function %d", alpha_func); + fprintf(stderr, "r300: Unknown alpha function %d", alpha_func); assert(0); break; } @@ -209,7 +211,7 @@ r300_translate_polygon_mode_front(unsigned mode) { return R300_GA_POLY_MODE_FRONT_PTYPE_POINT; default: - debug_printf("r300: Bad polygon mode %i in %s\n", mode, + fprintf(stderr, "r300: Bad polygon mode %i in %s\n", mode, __FUNCTION__); return R300_GA_POLY_MODE_FRONT_PTYPE_TRI; } @@ -227,7 +229,7 @@ r300_translate_polygon_mode_back(unsigned mode) { return R300_GA_POLY_MODE_BACK_PTYPE_POINT; default: - debug_printf("r300: Bad polygon mode %i in %s\n", mode, + fprintf(stderr, "r300: Bad polygon mode %i in %s\n", mode, __FUNCTION__); return R300_GA_POLY_MODE_BACK_PTYPE_TRI; } @@ -255,7 +257,7 @@ static INLINE uint32_t r300_translate_wrap(int wrap) case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER: return R300_TX_CLAMP_TO_EDGE | R300_TX_MIRRORED; default: - debug_printf("r300: Unknown texture wrap %d", wrap); + fprintf(stderr, "r300: Unknown texture wrap %d", wrap); assert(0); return 0; } @@ -276,7 +278,7 @@ static INLINE uint32_t r300_translate_tex_filters(int min, int mag, int mip, retval |= R300_TX_MIN_FILTER_LINEAR; break; default: - debug_printf("r300: Unknown texture filter %d\n", min); + fprintf(stderr, "r300: Unknown texture filter %d\n", min); assert(0); break; } @@ -288,7 +290,7 @@ static INLINE uint32_t r300_translate_tex_filters(int min, int mag, int mip, retval |= R300_TX_MAG_FILTER_LINEAR; break; default: - debug_printf("r300: Unknown texture filter %d\n", mag); + fprintf(stderr, "r300: Unknown texture filter %d\n", mag); assert(0); break; } @@ -304,7 +306,7 @@ static INLINE uint32_t r300_translate_tex_filters(int min, int mag, int mip, retval |= R300_TX_MIN_FILTER_MIP_LINEAR; break; default: - debug_printf("r300: Unknown texture filter %d\n", mip); + fprintf(stderr, "r300: Unknown texture filter %d\n", mip); assert(0); break; } @@ -370,7 +372,7 @@ r300_translate_vertex_data_type(enum pipe_format format) { desc = util_format_description(format); if (desc->layout != UTIL_FORMAT_LAYOUT_PLAIN) { - debug_printf("r300: Bad format %s in %s:%d\n", util_format_name(format), + fprintf(stderr, "r300: Bad format %s in %s:%d\n", util_format_name(format), __FUNCTION__, __LINE__); assert(0); } @@ -391,7 +393,7 @@ r300_translate_vertex_data_type(enum pipe_format format) { result = R300_DATA_TYPE_FLOAT_1 + (components - 1); break; default: - debug_printf("r300: Bad format %s in %s:%d\n", + fprintf(stderr, "r300: Bad format %s in %s:%d\n", util_format_name(format), __FUNCTION__, __LINE__); assert(0); } @@ -412,15 +414,15 @@ r300_translate_vertex_data_type(enum pipe_format format) { } break; default: - debug_printf("r300: Bad format %s in %s:%d\n", + fprintf(stderr, "r300: Bad format %s in %s:%d\n", util_format_name(format), __FUNCTION__, __LINE__); - debug_printf("r300: util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_RGB, 0) == %d\n", + fprintf(stderr, "r300: util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_RGB, 0) == %d\n", util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_RGB, 0)); assert(0); } break; default: - debug_printf("r300: Bad format %s in %s:%d\n", + fprintf(stderr, "r300: Bad format %s in %s:%d\n", util_format_name(format), __FUNCTION__, __LINE__); assert(0); } @@ -442,7 +444,7 @@ r300_translate_vertex_data_swizzle(enum pipe_format format) { assert(format); if (desc->layout != UTIL_FORMAT_LAYOUT_PLAIN) { - debug_printf("r300: Bad format %s in %s:%d\n", + fprintf(stderr, "r300: Bad format %s in %s:%d\n", util_format_name(format), __FUNCTION__, __LINE__); return 0; } diff --git a/src/gallium/drivers/r300/r300_tgsi_to_rc.c b/src/gallium/drivers/r300/r300_tgsi_to_rc.c index aff4ddd4e23..1c90cc92a96 100644 --- a/src/gallium/drivers/r300/r300_tgsi_to_rc.c +++ b/src/gallium/drivers/r300/r300_tgsi_to_rc.c @@ -25,6 +25,7 @@ #include "radeon_compiler.h" #include "radeon_program.h" +#include "tgsi/tgsi_info.h" #include "tgsi/tgsi_parse.h" #include "tgsi/tgsi_scan.h" #include "tgsi/tgsi_util.h" @@ -145,7 +146,7 @@ static unsigned translate_opcode(unsigned opcode) case TGSI_OPCODE_KIL: return RC_OPCODE_KIL; } - debug_printf("r300: Unknown TGSI/RC opcode: %i\n", opcode); + fprintf(stderr, "r300: Unknown TGSI/RC opcode: %s\n", tgsi_get_opcode_name(opcode)); return RC_OPCODE_ILLEGAL_OPCODE; } diff --git a/src/gallium/drivers/r300/r300_vs.c b/src/gallium/drivers/r300/r300_vs.c index bd6b95dccba..d5690caa68e 100644 --- a/src/gallium/drivers/r300/r300_vs.c +++ b/src/gallium/drivers/r300/r300_vs.c @@ -299,7 +299,7 @@ void r300_translate_vertex_shader(struct r300_context* r300, r3xx_compile_vertex_program(&compiler); if (compiler.Base.Error) { /* XXX We should fallback using Draw. */ - fprintf(stderr, "r300 VP: Compiler error\n"); + fprintf(stderr, "r300 VP: Compiler error:\n%s", compiler.Base.ErrorMsg); abort(); } -- cgit v1.2.3 From feb8d995939bd52e880defc1ea95ccb68f5aaa0c Mon Sep 17 00:00:00 2001 From: Marek Olšák Date: Sat, 27 Mar 2010 22:39:54 +0100 Subject: r300g: disable cliprects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Thanks to Nicolai Hähnle for explaining this register! --- src/gallium/drivers/r300/r300_state_invariant.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/r300/r300_state_invariant.c b/src/gallium/drivers/r300/r300_state_invariant.c index 4a2c68269b1..88ae75bb816 100644 --- a/src/gallium/drivers/r300/r300_state_invariant.c +++ b/src/gallium/drivers/r300/r300_state_invariant.c @@ -127,7 +127,7 @@ void r300_emit_invariant_state(struct r300_context* r300, OUT_CS_REG(R300_ZB_HIZ_PITCH, 0x00000000); /* XXX */ - OUT_CS_REG(R300_SC_CLIP_RULE, 0xaaaa); + OUT_CS_REG(R300_SC_CLIP_RULE, 0xFFFF); END_CS; } -- cgit v1.2.3 From 4a16d325eb79d8c9da22df58aae4490bd79edaba Mon Sep 17 00:00:00 2001 From: Marek Olšák Date: Sun, 28 Mar 2010 00:07:45 +0100 Subject: r300g: handle TGSI_OPCODE_RET as END --- src/gallium/drivers/r300/r300_tgsi_to_rc.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/r300/r300_tgsi_to_rc.c b/src/gallium/drivers/r300/r300_tgsi_to_rc.c index 1c90cc92a96..3f88a2b82b9 100644 --- a/src/gallium/drivers/r300/r300_tgsi_to_rc.c +++ b/src/gallium/drivers/r300/r300_tgsi_to_rc.c @@ -273,9 +273,6 @@ static void transform_instruction(struct tgsi_to_rc * ttr, struct tgsi_full_inst struct rc_instruction * dst; int i; - if (src->Instruction.Opcode == TGSI_OPCODE_END) - return; - dst = rc_insert_new_instruction(ttr->compiler, ttr->compiler->Program.Instructions.Prev); dst->U.I.Opcode = translate_opcode(src->Instruction.Opcode); dst->U.I.SaturateMode = translate_saturate(src->Instruction.Saturate); @@ -334,6 +331,7 @@ static void handle_immediate(struct tgsi_to_rc * ttr, void r300_tgsi_to_rc(struct tgsi_to_rc * ttr, const struct tgsi_token * tokens) { + struct tgsi_full_instruction *inst; struct tgsi_parse_context parser; unsigned imm_index = 0; int i; @@ -368,7 +366,15 @@ void r300_tgsi_to_rc(struct tgsi_to_rc * ttr, imm_index++; break; case TGSI_TOKEN_TYPE_INSTRUCTION: - transform_instruction(ttr, &parser.FullToken.FullInstruction); + inst = &parser.FullToken.FullInstruction; + /* This hack with the RET opcode woudn't work with + * conditionals. */ + if (inst->Instruction.Opcode == TGSI_OPCODE_END || + inst->Instruction.Opcode == TGSI_OPCODE_RET) { + break; + } + + transform_instruction(ttr, inst); break; } } -- cgit v1.2.3 From d142e8f9d33da797e67706f7246af2694eed6d38 Mon Sep 17 00:00:00 2001 From: Luca Barbieri Date: Sat, 27 Mar 2010 23:41:15 +0100 Subject: gallium/docs: add comparison between Gallium and Direct3D 11 DDI interfaces Feel free to check it and improve it if necessary. --- src/gallium/docs/d3d11ddi.txt | 492 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 492 insertions(+) create mode 100644 src/gallium/docs/d3d11ddi.txt (limited to 'src/gallium') diff --git a/src/gallium/docs/d3d11ddi.txt b/src/gallium/docs/d3d11ddi.txt new file mode 100644 index 00000000000..8aba4fde118 --- /dev/null +++ b/src/gallium/docs/d3d11ddi.txt @@ -0,0 +1,492 @@ +This document compares the D3D10/D3D11 device driver interface with Gallium. +It is written from the perspective of a developer implementing a D3D10/D3D11 driver as a Gallium state tracker. + +Note that naming and other cosmetic differences are not noted, since they don't really matter and would severely clutter the document. +Gallium/OpenGL terminology is used in preference to D3D terminology. + +NOTE: this document tries to be complete but most likely isn't fully complete and also not fully correct: please submit patches if you spot anything incorrect + +Also note that this is specifically for the DirectX 10/11 Windows Vista/7 DDI interfaces. +DirectX 9 has both user-mode (for Vista) and kernel mode (pre-Vista) interfaces, but they are significantly different from Gallium due to the presence of a lot of fixed function functionality. + +The user-visible DirectX 10/11 interfaces are distinct from the kernel DDI, but they match very closely. + +* Accessing Microsoft documentation + +See http://msdn.microsoft.com/en-us/library/dd445501.aspx ("D3D11DDI_DEVICEFUNCS") for D3D documentation. + +Also see download.microsoft.com/download/f/2/d/.../Direct3D10_web.pdf for an introduction to Direct3D 10 and the rationale for its design. + +The Windows Driver Kit contains the actual headers, as well as shader bytecode documentation; + +To get the headers from Linux, run the following, in a dedicated directory: +wget http://download.microsoft.com/download/4/A/2/4A25C7D5-EFBE-4182-B6A9-AE6850409A78/GRMWDK_EN_7600_1.ISO +sudo mount -o loop GRMWDK_EN_7600_1.ISO /mnt/tmp +cabextract -x /mnt/tmp/wdk/headers_cab001.cab +rename 's/^_(.*)_[0-9]*$/$1/' * +sudo umount /mnt/tmp + +d3d10umddi.h contains the DDI interface analyzed in this document: note that it is much easier to read this online on MSDN. +d3d{10,11}TokenizedProgramFormat.hpp contains the shader bytecode definitions: this is not available on MSDN. +d3d9types.h contains DX9 shader bytecode, and DX9 types +d3dumddi.h contains the DirectX 9 DDI interface + +* Glossary + +BC1: DXT1 +BC2: DXT3 +BC3: DXT5 +BC5: RGTC +BC6H: BPTC float +BC7: BPTC +CS = compute shader: OpenCL-like shader +DS = domain shader: tessellation evaluation shader +HS = hull shader: tessellation control shader +IA = input assembler: primitive assembly +Input layout: vertex elements +OM = output merger: blender +PS = pixel shader: fragment shader +Primitive topology: primitive type +Resource: buffer or texture +Shader resource (view): sampler view +SO = stream out: transform feedback +Unordered access view: view supporting random read/write access (usually from compute shaders) + +* Legend + +-: features D3D11 has and Gallium lacks ++: features Gallium has and D3D11 lacks +!: differences between D3D11 and Gallium +*: possible improvements to Gallium +>: references to comparisons of special enumerations +#: comment + +* Gallium functions with no direct D3D10/D3D11 equivalent + +clear + + Gallium supports clearing both render targets and depth/stencil with a single call + +draw_range_elements + + Gallium supports indexed draw with explicit range + +fence_signalled +fence_finish + + D3D10/D3D11 don't appear to support explicit fencing; queries can often substitute though, and flushing is supported + +set_clip_state + + Gallium supports fixed function user clip planes, D3D10/D3D11 only support using the vertex shader for them + +set_polygon_stipple + + Gallium supports polygon stipple + +surface_fill + + Gallium supports subrectangle fills of surfaces, D3D10 only supports full clears of views + +* DirectX 10/11 DDI functions and Gallium equivalents + +AbandonCommandList (D3D11 only) + - Gallium does not support deferred contexts + +CalcPrivateBlendStateSize +CalcPrivateDepthStencilStateSize +CalcPrivateDepthStencilViewSize +CalcPrivateElementLayoutSize +CalcPrivateGeometryShaderWithStreamOutput +CalcPrivateOpenedResourceSize +CalcPrivateQuerySize +CalcPrivateRasterizerStateSize +CalcPrivateRenderTargetViewSize +CalcPrivateResourceSize +CalcPrivateSamplerSize +CalcPrivateShaderResourceViewSize +CalcPrivateShaderSize +CalcDeferredContextHandleSize (D3D11 only) +CalcPrivateCommandListSize (D3D11 only) +CalcPrivateDeferredContextSize (D3D11 only) +CalcPrivateTessellationShaderSize (D3D11 only) +CalcPrivateUnorderedAccessViewSize (D3D11 only) + ! D3D11 allocates private objects itself, using the size computed here + * Gallium could do something similar to be able to put the private data inline into state tracker objects: this would allow them to fit in the same cacheline and improve performance + +CheckDeferredContextHandleSizes (D3D11 only) + - Gallium does not support deferred contexts + +CheckFormatSupport -> screen->is_format_supported + ! Gallium passes usages to this function, D3D11 returns them + - Gallium does not differentiate between blendable and non-blendable render targets + - Gallium lacks multisampled-texture and multisampled-render-target usages + +CheckMultisampleQualityLevels + * could merge this with is_format_supported + - Gallium lacks multisampling support + +CommandListExecute (D3D11 only) + - Gallium does not support command lists + +CopyStructureCount (D3D11 only) + - Gallium does not support unordered access views (views that can be written to arbitrarily from compute shaders) + +ClearDepthStencilView -> clear +ClearRenderTargetView -> clear + # D3D11 is not totally clear about whether this applies to any view or only a "currently-bound view" + + Gallium allows to clear both depth/stencil and render target(s) in a single operation + + Gallium supports double-precision depth values (but not rgba values!) + * May want to also support double-precision rgba or use "float" for "depth" + +ClearUnorderedAccessViewFloat (D3D11 only) +ClearUnorderedAccessViewUint (D3D11 only) + - Gallium does not support unordered access views (views that can be written to arbitrarily from compute shaders) + +CreateBlendState (extended in D3D10.1) -> create_blend_state + # D3D10 does not support per-RT blending, only D3D10.1 does + - Gallium lacks alpha-to-coverage + + Gallium supports logic ops + + Gallium supports dithering + + Gallium supports using the broadcast alpha component of the blend constant color + +CreateCommandList (D3D11 only) + - Gallium does not support command lists + +CreateComputeShader (D3D11 only) + - Gallium does not support compute shaders + +CreateDeferredContext (D3D11 only) + - Gallium does not support deferred contexts + +CreateDomainShader (D3D11 only) + - Gallium does not support domain shaders + +CreateHullShader (D3D11 only) + - Gallium does not support hull shaders + +CreateUnorderedAccessView (D3D11 only) + - Gallium does not support unordered access views + +CreateDepthStencilState -> create_depth_stencil_alpha_state + ! D3D11 has both a global stencil enable, and front/back enables; Gallium has only front/back enables + + Gallium has per-face writemask/valuemasks, D3D11 uses the same value for back and front + + Gallium supports the alpha test, which D3D11 lacks + +CreateDepthStencilView -> get_tex_surface +CreateRenderTargetView -> get_tex_surface + ! Gallium merges depthstencil and rendertarget views into pipe_surface, which also doubles as a 2D surface abstraction + - lack of texture array support + - lack of render-to-buffer support + + Gallium supports using 3D texture zslices as a depth/stencil buffer (in theory) + +CreateElementLayout -> create_vertex_elements_state + ! D3D11 allows sparse vertex elements (via InputRegister); in Gallium they must be specified sequentially + ! D3D11 has an extra flag (InputSlotClass) that is the same as instance_divisor == 0 + +CreateGeometryShader -> create_gs_state +CreateGeometryShaderWithStreamOutput -> create_gs_state +CreatePixelShader -> create_fs_state +CreateVertexShader -> create_vs_state + > bytecode is different (see D3d10tokenizedprogramformat.hpp) + ! D3D11 describes input/outputs separately from bytecode; Gallium has the tgsi_scan.c module to extract it from TGSI + @ TODO: look into DirectX 10/11 semantics specification and bytecode + +CheckCounter +CheckCounterInfo +CreateQuery -> create_query + - Gallium only supports occlusion, primitives generated and primitives emitted queries + ! D3D11 implements fences with "event" queries + * TIMESTAMP could be implemented as an additional fields for other queries: some cards have hardware support for exactly this + * OCCLUSIONPREDICATE is required for the OpenGL v2 occlusion query functionality + * others are performance counters, we may want them but they are not critical + +CreateRasterizerState + - Gallium lacks clamping of polygon offset depth biases + - Gallium lacks support to disable depth clipping + - Gallium lacks multisampling + + Gallium, like OpenGL, supports PIPE_POLYGON_MODE_POINT + + Gallium, like OpenGL, supports per-face polygon fill modes + + Gallium, like OpenGL, supports culling everything + + Gallium, like OpenGL, supports two-side lighting; D3D11 only has the facing attribute + + Gallium, like OpenGL, supports per-fill-mode polygon offset enables + + Gallium, like OpenGL, supports polygon smoothing + + Gallium, like OpenGL, supports polygon stipple + + Gallium, like OpenGL, supports point smoothing + + Gallium, like OpenGL, supports point sprites + + Gallium supports specifying point quad rasterization + + Gallium, like OpenGL, supports per-point point size + + Gallium, like OpenGL, supports line smoothing + + Gallium, like OpenGL, supports line stipple + + Gallium supports line last pixel rule specification + + Gallium, like OpenGL, supports provoking vertex convention + + Gallium supports D3D9 rasterization rules + + Gallium supports fixed line width + + Gallium supports fixed point size + +CreateResource -> texture_create or buffer_create + ! D3D11 passes the dimensions of all mipmap levels to the create call, while Gallium has an implicit floor(x/2) rule + # Note that hardware often has the implicit rule, so the D3D11 interface seems to make little sense + # Also, the D3D11 API does not allow the user to specify mipmap sizes, so this really seems a dubious decision on Microsoft's part + - D3D11 supports specifying initial data to write in the resource + - Gallium lacks support for stream output buffer usage + - Gallium does not support unordered access buffers + ! D3D11 specifies mapping flags (i.e. read/write/discard);:it's unclear what they are used for here + - D3D11 supports odd things in the D3D10_DDI_RESOURCE_MISC_FLAG enum (D3D10_DDI_RESOURCE_MISC_DISCARD_ON_PRESENT, D3D11_DDI_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, D3D11_DDI_RESOURCE_MISC_BUFFER_STRUCTURED) + - Gallium does not support indirect draw call parameter buffers + - Gallium lacks multisampling + - Gallium lacks array textures + ! D3D11 supports specifying hardware modes and other stuff here for scanout resources + + Gallium allows specifying minimum buffer alignment + ! D3D11 implements cube maps as 2D array textures + +CreateSampler + - D3D11 supports a monochrome convolution filter for "text filtering" + + Gallium supports non-normalized coordinates + + Gallium supports CLAMP, MIRROR_CLAMP and MIRROR_CLAMP_TO_BORDER + + Gallium supports setting min/max/mip filters and anisotropy independently + +CreateShaderResourceView (extended in D3D10.1) -> create_sampler_view + - Gallium lacks sampler views over buffers + - Gallium lacks texture arrays, and cube map views over texture arrays + + Gallium supports specifying a swizzle + ! D3D11 implements "cube views" as views into a 2D array texture + +CsSetConstantBuffers (D3D11 only) +CsSetSamplers (D3D11 only) +CsSetShader (D3D11 only) +CsSetShaderResources (D3D11 only) +CsSetShaderWithIfaces (D3D11 only) +CsSetUnorderedAccessViews (D3D11 only) + - Gallium does not support compute shaders + +DestroyBlendState +DestroyCommandList (D3D11 only) +DestroyDepthStencilState +DestroyDepthStencilView +DestroyDevice +DestroyElementLayout +DestroyQuery +DestroyRasterizerState +DestroyRenderTargetView +DestroyResource +DestroySampler +DestroyShader +DestroyShaderResourceView +DestroyUnorderedAccessView (D3D11 only) + # these are trivial + +Dispatch (D3D11 only) + - Gallium does not support compute shaders + +DispatchIndirect (D3D11 only) + - Gallium does not support compute shaders + +Draw -> draw_arrays + ! D3D11 sets primitive modes separately with IaSetTopology: it's not obvious which is better + +DrawAuto + - Gallium lacks stream out and DrawAuto + +DrawIndexed -> draw_elements + ! D3D11 sets primitive modes separately with IaSetTopology: it's not obvious which is better + * may want to add a separate set_index_buffer + - Gallium lacks base vertex for indexed draw calls + + D3D11 lacks draw_range_elements functionality, which is required for OpenGL + +DrawIndexedInstanced -> draw_elements_instanced + ! D3D11 sets primitive modes separately with IaSetTopology: it's not obvious which is better + * may want to add a separate set_index_buffer + - Gallium lacks base vertex for indexed draw calls + +DrawIndexedInstancedIndirect (D3D11 only) -> call draw_elements_instanced multiple times in software + # this allows to use an hardware buffer to specify the parameters for multiple draw_elements_instanced calls + - Gallium does not support draw call parameter buffers and indirect draw + +DrawInstanced -> draw_arrays_instanced + ! D3D11 sets primitive modes separately with IaSetTopology: it's not obvious which is better + +DrawInstancedIndirect (D3D11 only) -> call draw_arrays_instanced multiple times in software + # this allows to use an hardware buffer to specify the parameters for multiple draw_arrays_instanced calls + - Gallium does not support draw call parameter buffers and indirect draws + +DsSetConstantBuffers (D3D11 only) +DsSetSamplers (D3D11 only) +DsSetShader (D3D11 only) +DsSetShaderResources (D3D11 only) +DsSetShaderWithIfaces (D3D11 only) + - Gallium does not support domain shaders + +Flush -> flush + ! Gallium supports fencing and several kinds of flushing here, D3D11 just has a dumb glFlush-like function + +GenMips + - Gallium lacks a mipmap generation interface, and does this manually with the 3D engine + * it may be useful to add a mipmap generation interface, since the hardware (especially older cards) may have a better way than using the 3D engine + +GsSetConstantBuffers -> for(i = StartBuffer; i < NumBuffers; ++i) set_constant_buffer(PIPE_SHADER_GEOMETRY, i, phBuffers[i]) + +GsSetSamplers + - Gallium does not support sampling in geometry shaders + +GsSetShader -> bind_gs_state + +GsSetShaderWithIfaces (D3D11 only) + - Gallium does not support shader interfaces + +GsSetShaderResources + - Gallium does not support sampling in geometry shaders + +HsSetConstantBuffers (D3D11 only) +HsSetSamplers (D3D11 only) +HsSetShader (D3D11 only) +HsSetShaderResources (D3D11 only) +HsSetShaderWithIfaces (D3D11 only) + - Gallium does not support hull shaders + +IaSetIndexBuffer + ! Gallium passes this to the draw_elements or draw_elements_instanced calls + + Gallium supports 8-bit indices + ! the D3D11 interface allows index-size-unaligned byte offsets into index buffers; it's not clear whether they actually work + +IaSetInputLayout -> bind_vertex_elements_state + +IaSetTopology + ! Gallium passes the topology = primitive type to the draw calls + * may want to add an interface for this + - Gallium lacks support for DirectX 11 tessellated primitives + + Gallium supports line loops, triangle fans, quads, quad strips and polygons + +IaSetVertexBuffers -> set_vertex_buffers + + Gallium allows to specify a max_index here + - Gallium only allows setting all vertex buffers at once, while D3D11 supports setting a subset + +OpenResource -> texture_from_handle + +PsSetConstantBuffers -> for(i = StartBuffer; i < NumBuffers; ++i) set_constant_buffer(PIPE_SHADER_FRAGMENT, i, phBuffers[i]) + [*] may want to split into fragment/vertex-specific versions + +PsSetSamplers -> bind_fragment_sampler_states + [*] may want to allow binding subsets instead of all at once + +PsSetShader -> bind_fs_state + +PsSetShaderWithIfaces (D3D11 only) + - Gallium does not support shader interfaces + +PsSetShaderResources -> set_fragment_sampler_views + [*] may want to allow binding subsets instead of all at once + +QueryBegin -> begin_query + +QueryEnd -> end_query + +QueryGetData -> get_query_result + - D3D11 supports reading an arbitrary data chunk for query results, Gallium only supports reading a 64-bit integer + + D3D11 doesn't seem to support actually waiting for the query result (?!) + - D3D11 supports optionally not flushing command buffers here and instead returning DXGI_DDI_ERR_WASSTILLDRAWING + +RecycleCommandList (D3D11 only) +RecycleCreateCommandList (D3D11 only) +RecycleDestroyCommandList (D3D11 only) + - Gallium does not support command lists + +RecycleCreateDeferredContext (D3D11 only) + - Gallium does not support deferred contexts + +RelocateDeviceFuncs + - Gallium does not support moving pipe_context, while D3D11 seems to, using this + +ResetPrimitiveID (D3D10.1+ only, #ifdef D3D10PSGP) + # used to do vertex processing on the GPU on Intel G45 chipsets when it is faster this way (see www.intel.com/Assets/PDF/whitepaper/322931.pdf) + # presumably this resets the primitive id system value + - Gallium does not support vertex pipeline bypass anymore + +ResourceCopy +ResourceCopyRegion +ResourceConvert (D3D10.1+ only) +ResourceConvertRegion (D3D10.1+ only) + -> surface_copy + - Gallium does not support hardware buffer copies + - Gallium does not support copying 3D texture subregions in a single call + +ResourceIsStagingBusy -> is_texture_referenced, is_buffer_referenced + - Gallium does not support checking reference for a whole texture, but only a specific surface + +ResourceReadAfterWriteHazard + ! Gallium specifies hides this, except for the render and texture caches + +ResourceResolveSubresource + - Gallium does not support multisample sample resolution + +ResourceMap +ResourceUnmap +DynamicConstantBufferMapDiscard +DynamicConstantBufferUnmap +DynamicIABufferMapDiscard +DynamicIABufferMapNoOverwrite +DynamicIABufferUnmap +DynamicResourceMapDiscard +DynamicResourceUnmap +StagingResourceMap +StagingResourceUnmap + -> buffer_map / buffer_unmap + -> transfer functions + ! Gallium and D3D have different semantics for transfers + * D3D separates vertex/index buffers from constant buffers + ! D3D separates some buffer flags into specialized calls + +ResourceUpdateSubresourceUP -> transfer functionality, transfer_inline_write in gallium-resources +DefaultConstantBufferUpdateSubresourceUP -> transfer functionality, transfer_inline_write in gallium-resources + +SetBlendState -> bind_blend_state and set_blend_color + ! D3D11 fuses bind_blend_state and set_blend_color in a single function + - Gallium lacks the sample mask + +SetDepthStencilState -> bind_depth_stencil_alpha_state and set_stencil_ref + ! D3D11 fuses bind_depth_stencil_alpha_state and set_stencil_ref in a single function + +SetPredication -> render_condition + # here both D3D11 and Gallium seem very limited (hardware is too, probably though) + # ideally, we should support nested conditional rendering, as well as more complex tests (checking for an arbitrary range, after an AND with arbitrary mask ) + # of couse, hardware support is probably as limited as OpenGL/D3D11 + + Gallium, like NV_conditional_render, supports by-region and wait flags + - D3D11 supports predication conditional on being equal any value (along with occlusion predicates); Gallium only supports on non-zero + +SetRasterizerState -> bind_rasterizer_state + +SetRenderTargets (extended in D3D11) -> set_framebuffer_state + ! Gallium passed a width/height here, D3D11 does not + ! Gallium lacks ClearTargets (but this is redundant and the driver can trivially compute this if desired) + - Gallium does not support unordered access views + - Gallium does not support geometry shader selection of texture array image / 3D texture zslice + +SetResourceMinLOD (D3D11 only) + - Gallium does not support min lod directly on textures + +SetScissorRects + - Gallium lacks support for multiple geometry-shader-selectable scissor rectangles D3D11 has + +SetTextFilterSize + - Gallium lacks support for text filters + +SetVertexPipelineOutput (D3D10.1+ only) + # used to do vertex processing on the GPU on Intel G45 chipsets when it is faster this way (see www.intel.com/Assets/PDF/whitepaper/322931.pdf) + - Gallium does not support vertex pipeline bypass anymore + +SetViewports + - Gallium lacks support for multiple geometry-shader-selectable viewports D3D11 has + +ShaderResourceViewReadAfterWriteHazard -> flush(PIPE_FLUSH_RENDER_CACHE) + - Gallium does not support specifying this per-render-target/view + +SoSetTargets + - Gallium does not support stream out + +VsSetConstantBuffers -> for(i = StartBuffer; i < NumBuffers; ++i) set_constant_buffer(PIPE_SHADER_VERTEX, i, phBuffers[i]) + [*] may want to split into fragment/vertex-specific versions + +VsSetSamplers -> bind_vertex_sampler_states + [*] may want to allow binding subsets instead of all at once + +VsSetShader -> bind_vs_state + +VsSetShaderWithIfaces (D3D11 only) + - Gallium does not support shader interfaces + +VsSetShaderResources -> set_fragment_sampler_views + [*] may want to allow binding subsets instead of all at once -- cgit v1.2.3 From add226ea44d26db80fc8868ac422a2daf782003c Mon Sep 17 00:00:00 2001 From: Luca Barbieri Date: Sun, 28 Mar 2010 16:41:54 +0200 Subject: gallium/docs: fix formatting mistakes in d3d11ddi.txt --- src/gallium/docs/d3d11ddi.txt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/docs/d3d11ddi.txt b/src/gallium/docs/d3d11ddi.txt index 8aba4fde118..0baf2682871 100644 --- a/src/gallium/docs/d3d11ddi.txt +++ b/src/gallium/docs/d3d11ddi.txt @@ -15,9 +15,9 @@ The user-visible DirectX 10/11 interfaces are distinct from the kernel DDI, but See http://msdn.microsoft.com/en-us/library/dd445501.aspx ("D3D11DDI_DEVICEFUNCS") for D3D documentation. -Also see download.microsoft.com/download/f/2/d/.../Direct3D10_web.pdf for an introduction to Direct3D 10 and the rationale for its design. +Also see http://download.microsoft.com/download/f/2/d/f2d5ee2c-b7ba-4cd0-9686-b6508b5479a1/direct3d10_web.pdf ("The Direct3D 10 System" by David Blythe) for an introduction to Direct3D 10 and the rationale for its design. -The Windows Driver Kit contains the actual headers, as well as shader bytecode documentation; +The Windows Driver Kit contains the actual headers, as well as shader bytecode documentation. To get the headers from Linux, run the following, in a dedicated directory: wget http://download.microsoft.com/download/4/A/2/4A25C7D5-EFBE-4182-B6A9-AE6850409A78/GRMWDK_EN_7600_1.ISO @@ -358,10 +358,10 @@ IaSetVertexBuffers -> set_vertex_buffers OpenResource -> texture_from_handle PsSetConstantBuffers -> for(i = StartBuffer; i < NumBuffers; ++i) set_constant_buffer(PIPE_SHADER_FRAGMENT, i, phBuffers[i]) - [*] may want to split into fragment/vertex-specific versions + * may want to split into fragment/vertex-specific versions PsSetSamplers -> bind_fragment_sampler_states - [*] may want to allow binding subsets instead of all at once + * may want to allow binding subsets instead of all at once PsSetShader -> bind_fs_state @@ -369,7 +369,7 @@ PsSetShaderWithIfaces (D3D11 only) - Gallium does not support shader interfaces PsSetShaderResources -> set_fragment_sampler_views - [*] may want to allow binding subsets instead of all at once + * may want to allow binding subsets instead of all at once QueryBegin -> begin_query @@ -478,10 +478,10 @@ SoSetTargets - Gallium does not support stream out VsSetConstantBuffers -> for(i = StartBuffer; i < NumBuffers; ++i) set_constant_buffer(PIPE_SHADER_VERTEX, i, phBuffers[i]) - [*] may want to split into fragment/vertex-specific versions + * may want to split into fragment/vertex-specific versions VsSetSamplers -> bind_vertex_sampler_states - [*] may want to allow binding subsets instead of all at once + * may want to allow binding subsets instead of all at once VsSetShader -> bind_vs_state @@ -489,4 +489,4 @@ VsSetShaderWithIfaces (D3D11 only) - Gallium does not support shader interfaces VsSetShaderResources -> set_fragment_sampler_views - [*] may want to allow binding subsets instead of all at once + * may want to allow binding subsets instead of all at once -- cgit v1.2.3 From c42fe8cd278fdff831f557bbfcbfde16bd38a65d Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Sun, 28 Mar 2010 17:00:46 +0100 Subject: util: Update MSDN links. --- src/gallium/auxiliary/util/u_format.csv | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/auxiliary/util/u_format.csv b/src/gallium/auxiliary/util/u_format.csv index 11243e73492..d2a925141b1 100644 --- a/src/gallium/auxiliary/util/u_format.csv +++ b/src/gallium/auxiliary/util/u_format.csv @@ -47,9 +47,9 @@ # - color space: rgb, yub, sz # # See also: -# - http://msdn.microsoft.com/en-us/library/ee416489.aspx (D3D9) -# - http://msdn.microsoft.com/en-us/library/ee415668.aspx (D3D9 -> D3D10) -# - http://msdn.microsoft.com/en-us/library/ee418116.aspx (D3D10) +# - http://msdn.microsoft.com/en-us/library/bb172558.aspx (D3D9) +# - http://msdn.microsoft.com/en-us/library/bb205073.aspx#mapping_texture_formats (D3D9 -> D3D10) +# - http://msdn.microsoft.com/en-us/library/bb173059.aspx (D3D10) # # Note that GL doesn't really specify the layout of internal formats. See # OpenGL 2.1 specification, Table 3.16, on the "Correspondence of sized -- cgit v1.2.3 From a24fc90703f62d286031cb2ee8f625ef728243fd Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Sun, 28 Mar 2010 19:30:03 +0300 Subject: drisw: probably better hack for stride and some comments --- src/gallium/state_trackers/dri/sw/drisw.c | 19 +++++- src/gallium/targets/dri-swrast/swrast_drm_api.c | 4 +- src/gallium/winsys/sw/dri/dri_sw_winsys.c | 25 +------ src/glx/drisw_glx.c | 89 +++++++++---------------- 4 files changed, 50 insertions(+), 87 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/dri/sw/drisw.c b/src/gallium/state_trackers/dri/sw/drisw.c index a75fdf17899..b7eba63bcb9 100644 --- a/src/gallium/state_trackers/dri/sw/drisw.c +++ b/src/gallium/state_trackers/dri/sw/drisw.c @@ -48,8 +48,13 @@ * for createImage/destroyImage similar to DRI2 getBuffers. Probably not worth * it, given the scope of DRISW, unless it falls naturally from properly * solving the other issues. + * + * fences: + * + * No fences are used, are they needed for llvmpipe / cell ? */ +#include "util/u_format.h" #include "util/u_memory.h" #include "util/u_inlines.h" #include "pipe/p_context.h" @@ -75,14 +80,19 @@ get_drawable_info(__DRIdrawable *dPriv, int *w, int *h) dPriv->loaderPrivate); } +/* + * Set the width to 'stride / cpp'. PutImage seems to correctly clip the width + * to the actual width of the dst drawable. Even if this is not specified but + * an implementation detail, it is the correct thing to do, so rely on it. XXX + */ static INLINE void -put_image(__DRIdrawable *dPriv, void *data) +put_image(__DRIdrawable *dPriv, void *data, unsigned width) { __DRIscreen *sPriv = dPriv->driScreenPriv; const __DRIswrastLoaderExtension *loader = sPriv->swrast_loader; loader->putImage(dPriv, __DRI_SWRAST_IMAGE_OP_SWAP, - 0, 0, dPriv->w, dPriv->h, + 0, 0, width, dPriv->h, data, dPriv->loaderPrivate); } @@ -102,6 +112,7 @@ drisw_present_texture(__DRIdrawable *dPriv, struct pipe_surface *psurf; struct pipe_transfer *ptrans; void *pmap; + unsigned width; pipe = dri1_get_pipe_context(screen); psurf = dri1_get_pipe_surface(drawable, ptex); @@ -112,11 +123,13 @@ drisw_present_texture(__DRIdrawable *dPriv, PIPE_TRANSFER_READ, 0, 0, dPriv->w, dPriv->h); + width = ptrans->stride / util_format_get_blocksize(ptex->format); + pmap = pipe->transfer_map(pipe, ptrans); assert(pmap); - put_image(dPriv, pmap); + put_image(dPriv, pmap, width); pipe->transfer_unmap(pipe, ptrans); diff --git a/src/gallium/targets/dri-swrast/swrast_drm_api.c b/src/gallium/targets/dri-swrast/swrast_drm_api.c index 1fdfcccf883..1f24d7650d7 100644 --- a/src/gallium/targets/dri-swrast/swrast_drm_api.c +++ b/src/gallium/targets/dri-swrast/swrast_drm_api.c @@ -38,8 +38,8 @@ * This function should be put in targets/common or winsys/sw/common and shared * with targets/libgl-xlib and winsys/sw/drm. * - * For targets/common, you get layering violations in the build system unless - * all of drm_api's are moved under targets. + * For targets/common, you get layering violations unless all of drm_api's are + * moved under targets. */ #ifdef GALLIUM_SOFTPIPE diff --git a/src/gallium/winsys/sw/dri/dri_sw_winsys.c b/src/gallium/winsys/sw/dri/dri_sw_winsys.c index ee8ec91bc52..1c1e5612d28 100644 --- a/src/gallium/winsys/sw/dri/dri_sw_winsys.c +++ b/src/gallium/winsys/sw/dri/dri_sw_winsys.c @@ -62,15 +62,6 @@ xm_is_displaytarget_format_supported( struct sw_winsys *ws, return TRUE; } -/* see bytes_per_line in libGL */ -static INLINE int -bytes_per_line(unsigned pitch_bits, unsigned mul) -{ - unsigned mask = mul - 1; - - return ((pitch_bits + mask) & ~mask) / 8; -} - /* pipe_screen::texture_create DISPLAY_TARGET / SCANOUT / SHARED */ static struct sw_displaytarget * xm_displaytarget_create(struct sw_winsys *winsys, @@ -81,7 +72,7 @@ xm_displaytarget_create(struct sw_winsys *winsys, unsigned *stride) { struct xm_displaytarget *xm_dt; - unsigned nblocksy, size, xm_stride, loader_stride, format_stride; + unsigned nblocksy, size, xm_stride, format_stride; xm_dt = CALLOC_STRUCT(xm_displaytarget); if(!xm_dt) @@ -89,27 +80,15 @@ xm_displaytarget_create(struct sw_winsys *winsys, format_stride = util_format_get_stride(format, width); xm_stride = align(format_stride, alignment); - loader_stride = bytes_per_line(format_stride * 8, 32); nblocksy = util_format_get_nblocksy(format, height); size = xm_stride * nblocksy; -#ifdef DEBUG - debug_printf("swrast format stride: %8d\n", format_stride); - debug_printf("swrast pipe stride : %8d\n", xm_stride); - debug_printf("swrast loader stride: %8d\n", loader_stride); -#endif - - /* - * Allocate with the aligned stride required by the pipe but set the stride - * to the one hardcoded in the loaders XXX - */ - xm_dt->data = align_malloc(size, alignment); if(!xm_dt->data) goto no_data; - *stride = loader_stride; + *stride = xm_stride; return (struct sw_displaytarget *)xm_dt; no_data: diff --git a/src/glx/drisw_glx.c b/src/glx/drisw_glx.c index b5615239465..786faff81c1 100644 --- a/src/glx/drisw_glx.c +++ b/src/glx/drisw_glx.c @@ -129,10 +129,32 @@ swrastGetDrawableInfo(__DRIdrawable * draw, *h = uh; } +/** + * Align renderbuffer pitch. + * + * This should be chosen by the driver and the loader (libGL, xserver/glx) + * should use the driver provided pitch. + * + * It seems that the xorg loader (that is the xserver loading swrast_dri for + * indirect rendering, not client-side libGL) requires that the pitch is + * exactly the image width padded to 32 bits. XXX + * + * The above restriction can probably be overcome by using ScratchPixmap and + * CopyArea in the xserver, similar to ShmPutImage, and setting the width of + * the scratch pixmap to 'pitch / cpp'. + */ +static inline int +bytes_per_line(unsigned pitch_bits, unsigned mul) +{ + unsigned mask = mul - 1; + + return ((pitch_bits + mask) & ~mask) / 8; +} + static void -swrastPutImage2(__DRIdrawable * draw, int op, - int x, int y, int w, int h, - char *data, int pitch, void *loaderPrivate) +swrastPutImage(__DRIdrawable * draw, int op, + int x, int y, int w, int h, + char *data, void *loaderPrivate) { __GLXDRIdrawablePrivate *pdp = loaderPrivate; __GLXDRIdrawable *pdraw = &(pdp->base); @@ -158,7 +180,7 @@ swrastPutImage2(__DRIdrawable * draw, int op, ximage->data = data; ximage->width = w; ximage->height = h; - ximage->bytes_per_line = pitch; + ximage->bytes_per_line = bytes_per_line(w * ximage->bits_per_pixel, 32); XPutImage(dpy, drawable, gc, ximage, 0, 0, x, y, w, h); @@ -166,9 +188,9 @@ swrastPutImage2(__DRIdrawable * draw, int op, } static void -swrastGetImage2(__DRIdrawable * read, - int x, int y, int w, int h, - char *data, int pitch, void *loaderPrivate) +swrastGetImage(__DRIdrawable * read, + int x, int y, int w, int h, + char *data, void *loaderPrivate) { __GLXDRIdrawablePrivate *prp = loaderPrivate; __GLXDRIdrawable *pread = &(prp->base); @@ -182,64 +204,13 @@ swrastGetImage2(__DRIdrawable * read, ximage->data = data; ximage->width = w; ximage->height = h; - ximage->bytes_per_line = pitch; + ximage->bytes_per_line = bytes_per_line(w * ximage->bits_per_pixel, 32); XGetSubImage(dpy, readable, x, y, w, h, ~0L, ZPixmap, ximage, 0, 0); ximage->data = NULL; } -/** - * Align renderbuffer pitch. - * - * This should be chosen by the driver and the loader (libGL, xserver/glx) - * should use the driver provided pitch. - * - * It seems that the xorg loader (that is the xserver loading swrast_dri for - * indirect rendering, not client-side libGL) requires that the pitch is - * exactly the image width padded to 32 bits. XXX - * - * Is this a hard requirement that requires extra copies for different pitches - * or can the xorg loader use the driver pitch without extra copies ? - */ -static inline int -bytes_per_line(unsigned pitch_bits, unsigned mul) -{ - unsigned mask = mul - 1; - - return ((pitch_bits + mask) & ~mask) / 8; -} - -static void -swrastPutImage(__DRIdrawable * draw, int op, - int x, int y, int w, int h, - char *data, void *loaderPrivate) -{ - __GLXDRIdrawablePrivate *pdp = loaderPrivate; - int bpp, pitch; - - bpp = pdp->ximage->bits_per_pixel; - - pitch = bytes_per_line(w * bpp, 32); - - swrastPutImage2(draw, op, x, y, w, h, data, pitch, loaderPrivate); -} - -static void -swrastGetImage(__DRIdrawable * read, - int x, int y, int w, int h, - char *data, void *loaderPrivate) -{ - __GLXDRIdrawablePrivate *prp = loaderPrivate; - int bpp, pitch; - - bpp = prp->ximage->bits_per_pixel; - - pitch = bytes_per_line(w * bpp, 32); - - swrastGetImage2(read, x, y, w, h, data, pitch, loaderPrivate); -} - static const __DRIswrastLoaderExtension swrastLoaderExtension = { {__DRI_SWRAST_LOADER, __DRI_SWRAST_LOADER_VERSION}, swrastGetDrawableInfo, -- cgit v1.2.3 From 42ab3f6fd2a019e63bf66cc59c5afb8cb6a53741 Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Fri, 26 Mar 2010 17:19:45 -0700 Subject: st/python: updates for recent interface changes Still problems at runtime with vertex elements, etc. Building still disabled. --- src/gallium/state_trackers/python/p_texture.i | 86 +++++++++++----------- src/gallium/state_trackers/python/st_device.c | 22 +++--- src/gallium/state_trackers/python/st_sample.c | 5 +- .../state_trackers/python/st_softpipe_winsys.c | 2 +- 4 files changed, 58 insertions(+), 57 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/python/p_texture.i b/src/gallium/state_trackers/python/p_texture.i index 761587dc533..2dd9e5050ea 100644 --- a/src/gallium/state_trackers/python/p_texture.i +++ b/src/gallium/state_trackers/python/p_texture.i @@ -125,10 +125,10 @@ struct st_surface } %cstring_output_allocate_size(char **STRING, int *LENGTH, free(*$1)); - void get_tile_raw(unsigned x, unsigned y, unsigned w, unsigned h, char **STRING, int *LENGTH) + void get_tile_raw(struct st_context *ctx, unsigned x, unsigned y, unsigned w, unsigned h, char **STRING, int *LENGTH) { struct pipe_texture *texture = $self->texture; - struct pipe_screen *screen = texture->screen; + struct pipe_context *pipe = ctx->pipe; struct pipe_transfer *transfer; unsigned stride; @@ -138,7 +138,7 @@ struct st_surface if(!*STRING) return; - transfer = screen->get_tex_transfer(screen, + transfer = pipe->get_tex_transfer(pipe, $self->texture, $self->face, $self->level, @@ -146,16 +146,16 @@ struct st_surface PIPE_TRANSFER_READ, x, y, w, h); if(transfer) { - pipe_get_tile_raw(transfer, 0, 0, w, h, *STRING, stride); - screen->tex_transfer_destroy(transfer); + pipe_get_tile_raw(pipe, transfer, 0, 0, w, h, *STRING, stride); + pipe->tex_transfer_destroy(pipe, transfer); } } %cstring_input_binary(const char *STRING, unsigned LENGTH); - void put_tile_raw(unsigned x, unsigned y, unsigned w, unsigned h, const char *STRING, unsigned LENGTH, unsigned stride = 0) + void put_tile_raw(struct st_context *ctx, unsigned x, unsigned y, unsigned w, unsigned h, const char *STRING, unsigned LENGTH, unsigned stride = 0) { struct pipe_texture *texture = $self->texture; - struct pipe_screen *screen = texture->screen; + struct pipe_context *pipe = ctx->pipe; struct pipe_transfer *transfer; if(stride == 0) @@ -164,7 +164,7 @@ struct st_surface if(LENGTH < util_format_get_nblocksy(texture->format, h) * stride) SWIG_exception(SWIG_ValueError, "offset must be smaller than buffer size"); - transfer = screen->get_tex_transfer(screen, + transfer = pipe->get_tex_transfer(pipe, $self->texture, $self->face, $self->level, @@ -174,19 +174,18 @@ struct st_surface if(!transfer) SWIG_exception(SWIG_MemoryError, "couldn't initiate transfer"); - pipe_put_tile_raw(transfer, 0, 0, w, h, STRING, stride); - screen->tex_transfer_destroy(transfer); + pipe_put_tile_raw(pipe, transfer, 0, 0, w, h, STRING, stride); + pipe->tex_transfer_destroy(pipe, transfer); fail: return; } - void - get_tile_rgba(unsigned x, unsigned y, unsigned w, unsigned h, float *rgba) + void get_tile_rgba(struct st_context *ctx, unsigned x, unsigned y, unsigned w, unsigned h, float *rgba) { - struct pipe_screen *screen = $self->texture->screen; + struct pipe_context *pipe = ctx->pipe; struct pipe_transfer *transfer; - transfer = screen->get_tex_transfer(screen, + transfer = pipe->get_tex_transfer(pipe, $self->texture, $self->face, $self->level, @@ -194,17 +193,17 @@ struct st_surface PIPE_TRANSFER_READ, x, y, w, h); if(transfer) { - pipe_get_tile_rgba(transfer, 0, 0, w, h, rgba); - screen->tex_transfer_destroy(transfer); + pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba); + pipe->tex_transfer_destroy(pipe, transfer); } } void - put_tile_rgba(unsigned x, unsigned y, unsigned w, unsigned h, const float *rgba) + put_tile_rgba(struct st_context *ctx, unsigned x, unsigned y, unsigned w, unsigned h, const float *rgba) { - struct pipe_screen *screen = $self->texture->screen; + struct pipe_context *pipe = ctx->pipe; struct pipe_transfer *transfer; - transfer = screen->get_tex_transfer(screen, + transfer = pipe->get_tex_transfer(pipe, $self->texture, $self->face, $self->level, @@ -212,16 +211,16 @@ struct st_surface PIPE_TRANSFER_WRITE, x, y, w, h); if(transfer) { - pipe_put_tile_rgba(transfer, 0, 0, w, h, rgba); - screen->tex_transfer_destroy(transfer); + pipe_put_tile_rgba(pipe, transfer, 0, 0, w, h, rgba); + pipe->tex_transfer_destroy(pipe, transfer); } } %cstring_output_allocate_size(char **STRING, int *LENGTH, free(*$1)); void - get_tile_rgba8(unsigned x, unsigned y, unsigned w, unsigned h, char **STRING, int *LENGTH) + get_tile_rgba8(struct st_context *ctx, unsigned x, unsigned y, unsigned w, unsigned h, char **STRING, int *LENGTH) { - struct pipe_screen *screen = $self->texture->screen; + struct pipe_context *pipe = ctx->pipe; struct pipe_transfer *transfer; float *rgba; unsigned char *rgba8; @@ -244,7 +243,7 @@ struct st_surface rgba8 = (unsigned char *) *STRING; - transfer = screen->get_tex_transfer(screen, + transfer = pipe->get_tex_transfer(pipe, $self->texture, $self->face, $self->level, @@ -253,24 +252,23 @@ struct st_surface x, y, w, h); if(transfer) { - pipe_get_tile_rgba(transfer, 0, 0, w, h, rgba); + pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba); for(j = 0; j < h; ++j) { for(i = 0; i < w; ++i) for(k = 0; k <4; ++k) rgba8[j*w*4 + i*4 + k] = float_to_ubyte(rgba[j*w*4 + i*4 + k]); } - screen->tex_transfer_destroy(transfer); + pipe->tex_transfer_destroy(pipe, transfer); } free(rgba); } - void - get_tile_z(unsigned x, unsigned y, unsigned w, unsigned h, unsigned *z) + void get_tile_z(struct st_context *ctx, unsigned x, unsigned y, unsigned w, unsigned h, unsigned *z) { - struct pipe_screen *screen = $self->texture->screen; + struct pipe_context *pipe = ctx->pipe; struct pipe_transfer *transfer; - transfer = screen->get_tex_transfer(screen, + transfer = pipe->get_tex_transfer(pipe, $self->texture, $self->face, $self->level, @@ -278,17 +276,16 @@ struct st_surface PIPE_TRANSFER_READ, x, y, w, h); if(transfer) { - pipe_get_tile_z(transfer, 0, 0, w, h, z); - screen->tex_transfer_destroy(transfer); + pipe_get_tile_z(pipe, transfer, 0, 0, w, h, z); + pipe->tex_transfer_destroy(pipe, transfer); } } - void - put_tile_z(unsigned x, unsigned y, unsigned w, unsigned h, const unsigned *z) + void put_tile_z(struct st_context *ctx, unsigned x, unsigned y, unsigned w, unsigned h, const unsigned *z) { - struct pipe_screen *screen = $self->texture->screen; + struct pipe_context *pipe = ctx->pipe; struct pipe_transfer *transfer; - transfer = screen->get_tex_transfer(screen, + transfer = pipe->get_tex_transfer(pipe, $self->texture, $self->face, $self->level, @@ -296,20 +293,21 @@ struct st_surface PIPE_TRANSFER_WRITE, x, y, w, h); if(transfer) { - pipe_put_tile_z(transfer, 0, 0, w, h, z); - screen->tex_transfer_destroy(transfer); + pipe_put_tile_z(pipe, transfer, 0, 0, w, h, z); + pipe->tex_transfer_destroy(pipe, transfer); } } +/* void sample_rgba(float *rgba) { st_sample_surface($self, rgba); } +*/ - unsigned - compare_tile_rgba(unsigned x, unsigned y, unsigned w, unsigned h, const float *rgba, float tol = 0.0) + unsigned compare_tile_rgba(struct st_context *ctx, unsigned x, unsigned y, unsigned w, unsigned h, const float *rgba, float tol = 0.0) { - struct pipe_screen *screen = $self->texture->screen; + struct pipe_context *pipe = ctx->pipe; struct pipe_transfer *transfer; float *rgba2; const float *p1; @@ -320,7 +318,7 @@ struct st_surface if(!rgba2) return ~0; - transfer = screen->get_tex_transfer(screen, + transfer = pipe->get_tex_transfer(pipe, $self->texture, $self->face, $self->level, @@ -332,8 +330,8 @@ struct st_surface return ~0; } - pipe_get_tile_rgba(transfer, 0, 0, w, h, rgba2); - screen->tex_transfer_destroy(transfer); + pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba2); + pipe->tex_transfer_destroy(pipe, transfer); p1 = rgba; p2 = rgba2; diff --git a/src/gallium/state_trackers/python/st_device.c b/src/gallium/state_trackers/python/st_device.c index 0d87c705e75..44d65e3fc1e 100644 --- a/src/gallium/state_trackers/python/st_device.c +++ b/src/gallium/state_trackers/python/st_device.c @@ -31,6 +31,7 @@ #include "pipe/p_shader_tokens.h" #include "util/u_inlines.h" #include "cso_cache/cso_context.h" +#include "util/u_inlines.h" #include "util/u_math.h" #include "util/u_memory.h" #include "util/u_sampler.h" @@ -228,6 +229,7 @@ st_context_create(struct st_device *st_dev) /* default textures */ { + struct pipe_context *pipe = st_ctx->pipe; struct pipe_screen *screen = st_dev->screen; struct pipe_texture templat; struct pipe_transfer *transfer; @@ -245,21 +247,21 @@ st_context_create(struct st_device *st_dev) st_ctx->default_texture = screen->texture_create( screen, &templat ); if(st_ctx->default_texture) { - transfer = screen->get_tex_transfer(screen, - st_ctx->default_texture, - 0, 0, 0, - PIPE_TRANSFER_WRITE, - 0, 0, - st_ctx->default_texture->width0, - st_ctx->default_texture->height0); + transfer = pipe->get_tex_transfer(pipe, + st_ctx->default_texture, + 0, 0, 0, + PIPE_TRANSFER_WRITE, + 0, 0, + st_ctx->default_texture->width0, + st_ctx->default_texture->height0); if (transfer) { uint32_t *map; - map = (uint32_t *) screen->transfer_map(screen, transfer); + map = (uint32_t *) pipe->transfer_map(pipe, transfer); if(map) { *map = 0x00000000; - screen->transfer_unmap(screen, transfer); + pipe->transfer_unmap(pipe, transfer); } - screen->tex_transfer_destroy(transfer); + pipe->tex_transfer_destroy(pipe, transfer); } } diff --git a/src/gallium/state_trackers/python/st_sample.c b/src/gallium/state_trackers/python/st_sample.c index e1808153461..f9622533fbc 100644 --- a/src/gallium/state_trackers/python/st_sample.c +++ b/src/gallium/state_trackers/python/st_sample.c @@ -521,7 +521,7 @@ st_sample_pixel_block(enum pipe_format format, } } - +#if 0 void st_sample_surface(struct st_surface *surface, float *rgba) { @@ -533,7 +533,7 @@ st_sample_surface(struct st_surface *surface, float *rgba) struct pipe_transfer *transfer; void *raw; - transfer = screen->get_tex_transfer(screen, + transfer = pipe->get_tex_transfer(pipe, surface->texture, surface->face, surface->level, @@ -572,3 +572,4 @@ st_sample_surface(struct st_surface *surface, float *rgba) screen->tex_transfer_destroy(transfer); } +#endif diff --git a/src/gallium/state_trackers/python/st_softpipe_winsys.c b/src/gallium/state_trackers/python/st_softpipe_winsys.c index 985374190c3..0a332aaa9f1 100644 --- a/src/gallium/state_trackers/python/st_softpipe_winsys.c +++ b/src/gallium/state_trackers/python/st_softpipe_winsys.c @@ -30,7 +30,7 @@ #include "softpipe/sp_public.h" #include "llvmpipe/lp_public.h" #include "state_tracker/sw_winsys.h" -#include "null/null_sw_winsys.h" +#include "sw/null/null_sw_winsys.h" #include "st_winsys.h" -- cgit v1.2.3 From f97f46f269666b289f9af977e238ccda9b483c44 Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Sun, 28 Mar 2010 09:30:55 -0700 Subject: aux/tgsi: fix some minor glitches in string routines Not sure why we are open-coding these rather than using standard library functions. --- src/gallium/auxiliary/tgsi/tgsi_text.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/auxiliary/tgsi/tgsi_text.c b/src/gallium/auxiliary/tgsi/tgsi_text.c index f918151daaa..0b468a9184e 100644 --- a/src/gallium/auxiliary/tgsi/tgsi_text.c +++ b/src/gallium/auxiliary/tgsi/tgsi_text.c @@ -55,7 +55,7 @@ static boolean is_digit_alpha_underscore( const char *cur ) return is_digit( cur ) || is_alpha_underscore( cur ); } -static boolean uprcase( char c ) +static char uprcase( char c ) { if (c >= 'a' && c <= 'z') return c += 'A' - 'a'; @@ -76,7 +76,7 @@ streq_nocase_uprcase(const char *str1, str1++; str2++; } - return TRUE; + return *str1 == 0 && *str2 == 0; } static boolean str_match_no_case( const char **pcur, const char *str ) -- cgit v1.2.3 From db5c2235d1accc2adcf1746aec2342bfa67237ba Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Sun, 28 Mar 2010 09:53:58 -0700 Subject: gallium: new raw gallium interface to support standalone tests Provides basic window system integration behind a simple interface, allowing tests to be written without dependency on either the driver or window system. With a lot of work, could turn into something like glut for gallium. --- SConstruct | 2 +- progs/SConscript | 1 + progs/gallium/raw/SConscript | 17 +++ progs/gallium/raw/clear.c | 85 ++++++++++++++ src/gallium/drivers/sw/Makefile | 10 ++ src/gallium/drivers/sw/SConscript | 42 +++++++ src/gallium/drivers/sw/sw.c | 59 ++++++++++ src/gallium/drivers/sw/sw_public.h | 13 +++ src/gallium/include/state_tracker/graw.h | 36 ++++++ src/gallium/targets/SConscript | 5 + src/gallium/targets/graw-xlib/SConscript | 57 ++++++++++ src/gallium/targets/graw-xlib/graw.h | 36 ++++++ src/gallium/targets/graw-xlib/graw_xlib.c | 181 ++++++++++++++++++++++++++++++ 13 files changed, 543 insertions(+), 1 deletion(-) create mode 100644 progs/gallium/raw/SConscript create mode 100644 progs/gallium/raw/clear.c create mode 100644 src/gallium/drivers/sw/Makefile create mode 100644 src/gallium/drivers/sw/SConscript create mode 100644 src/gallium/drivers/sw/sw.c create mode 100644 src/gallium/drivers/sw/sw_public.h create mode 100644 src/gallium/include/state_tracker/graw.h create mode 100644 src/gallium/targets/graw-xlib/SConscript create mode 100644 src/gallium/targets/graw-xlib/graw.h create mode 100644 src/gallium/targets/graw-xlib/graw_xlib.c (limited to 'src/gallium') diff --git a/SConstruct b/SConstruct index 2549a13fffa..5d44b6efde6 100644 --- a/SConstruct +++ b/SConstruct @@ -52,7 +52,7 @@ opts.Add(ListVariable('statetrackers', 'state trackers to build', default_statet opts.Add(ListVariable('drivers', 'pipe drivers to build', default_drivers, ['softpipe', 'failover', 'svga', 'i915', 'i965', 'trace', 'r300', 'identity', 'llvmpipe'])) opts.Add(ListVariable('winsys', 'winsys drivers to build', default_winsys, - ['xlib', 'vmware', 'i915', 'i965', 'gdi', 'radeon'])) + ['xlib', 'vmware', 'i915', 'i965', 'gdi', 'radeon', 'graw-xlib'])) opts.Add(EnumVariable('MSVS_VERSION', 'MS Visual C++ version', None, allowed_values=('7.1', '8.0', '9.0'))) diff --git a/progs/SConscript b/progs/SConscript index aa6640cf7a6..20be60972d2 100644 --- a/progs/SConscript +++ b/progs/SConscript @@ -56,4 +56,5 @@ SConscript([ 'wgl/SConscript', 'perf/SConscript', 'gallium/unit/SConscript', + 'gallium/raw/SConscript', ]) diff --git a/progs/gallium/raw/SConscript b/progs/gallium/raw/SConscript new file mode 100644 index 00000000000..073b97951e7 --- /dev/null +++ b/progs/gallium/raw/SConscript @@ -0,0 +1,17 @@ +Import('*') + +env = env.Clone() + +env.Prepend(LIBPATH = [graw.dir]) +env.Prepend(LIBS = [graw.name]) + +progs = [ + 'clear' +] + +for prog in progs: + env.Program( + target = prog, + source = prog + '.c', + ) + diff --git a/progs/gallium/raw/clear.c b/progs/gallium/raw/clear.c new file mode 100644 index 00000000000..e46d135224d --- /dev/null +++ b/progs/gallium/raw/clear.c @@ -0,0 +1,85 @@ +/* Display a cleared blue window. This demo has no dependencies on + * any utility code, just the graw interface and gallium. + */ + +#include "state_tracker/graw.h" +#include "pipe/p_screen.h" +#include "pipe/p_context.h" +#include "pipe/p_state.h" +#include "pipe/p_defines.h" +#include /* for sleep() */ + +enum pipe_format formats[] = { + PIPE_FORMAT_R8G8B8A8_UNORM, + PIPE_FORMAT_B8G8R8A8_UNORM, + PIPE_FORMAT_NONE +}; + +static const int WIDTH = 300; +static const int HEIGHT = 300; + +int main( int argc, char *argv[] ) +{ + struct pipe_screen *screen; + struct pipe_context *pipe; + struct pipe_surface *surf; + struct pipe_framebuffer_state fb; + struct pipe_texture *tex, templat; + void *window = NULL; + float clear_color[4] = {1,0,1,1}; + int i; + + screen = graw_init(); + if (screen == NULL) + exit(1); + + for (i = 0; + window == NULL && formats[i] != PIPE_FORMAT_NONE; + i++) { + + window = graw_create_window(0,0,300,300, formats[i]); + } + + if (window == NULL) + exit(2); + + pipe = screen->context_create(screen, NULL); + if (pipe == NULL) + exit(3); + + templat.target = PIPE_TEXTURE_2D; + templat.format = formats[i]; + templat.width0 = WIDTH; + templat.height0 = HEIGHT; + templat.depth0 = 1; + templat.last_level = 0; + templat.nr_samples = 1; + templat.tex_usage = (PIPE_TEXTURE_USAGE_RENDER_TARGET | + PIPE_TEXTURE_USAGE_DISPLAY_TARGET); + + tex = screen->texture_create(screen, + &templat); + if (tex == NULL) + exit(4); + + surf = screen->get_tex_surface(screen, tex, 0, 0, 0, + PIPE_TEXTURE_USAGE_RENDER_TARGET | + PIPE_TEXTURE_USAGE_DISPLAY_TARGET); + if (surf == NULL) + exit(5); + + memset(&fb, 0, sizeof fb); + fb.nr_cbufs = 1; + fb.width = WIDTH; + fb.height = HEIGHT; + fb.cbufs[0] = surf; + + pipe->set_framebuffer_state(pipe, &fb); + pipe->clear(pipe, PIPE_CLEAR_COLOR, clear_color, 0, 0); + pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL); + + screen->flush_frontbuffer(screen, surf, window); + + sleep(100); + return 0; +} diff --git a/src/gallium/drivers/sw/Makefile b/src/gallium/drivers/sw/Makefile new file mode 100644 index 00000000000..2713a62ee9f --- /dev/null +++ b/src/gallium/drivers/sw/Makefile @@ -0,0 +1,10 @@ +# Meta-driver which combines whichever software rasterizers have been +# built into a single convenience library. + +TOP = ../../../.. +include $(TOP)/configs/current + +C_SOURCES = \ + sw.c + +include ../../Makefile.template diff --git a/src/gallium/drivers/sw/SConscript b/src/gallium/drivers/sw/SConscript new file mode 100644 index 00000000000..6fbbdf3cc46 --- /dev/null +++ b/src/gallium/drivers/sw/SConscript @@ -0,0 +1,42 @@ +####################################################################### +# SConscript for swrast convenience library +# +# This is a meta-driver which consists of any and all of the software +# rasterizers into a single driver. A software rasterizer is defined +# as any driver which takes an sw_winsys pointer as the only argument +# to create_screen. +# +# XXX: unfortunately users of this driver still need to link in any +# extra libraries needed for the particular driver (eg llvm for +# llvmpipe). Not sure how to get around this. + +Import('*') + +if not set(('softpipe', 'llvmpipe', 'cell')).intersection(env['drivers']): + print 'warning: no supported pipe driver: skipping build of sw meta-driver' + Return() + +env = env.Clone() + +if 'softpipe' in env['drivers']: + env.Append(CPPDEFINES = 'GALLIUM_SOFTPIPE') + env.Prepend(LIBS = [softpipe]) + +if 'llvmpipe' in env['drivers']: + env.Tool('llvm') + if 'LLVM_VERSION' in env: + env.Append(CPPDEFINES = 'GALLIUM_LLVMPIPE') + env.Tool('udis86') + env.Prepend(LIBS = [llvmpipe]) + +if 'cell' in env['drivers']: + env.Append(CPPDEFINES = 'GALLIUM_CELL') + env.Prepend(LIBS = [cell]) + +sw = env.ConvenienceLibrary( + target = 'sw', + source = [ + 'sw.c', + ] + ) + Export('sw') diff --git a/src/gallium/drivers/sw/sw.c b/src/gallium/drivers/sw/sw.c new file mode 100644 index 00000000000..9f156df45f5 --- /dev/null +++ b/src/gallium/drivers/sw/sw.c @@ -0,0 +1,59 @@ +#include "pipe/p_compiler.h" +#include "util/u_debug.h" +#include "target-helpers/wrap_screen.h" +#include "sw_public.h" +#include "state_tracker/sw_winsys.h" + + +/* Helper function to choose and instantiate one of the software rasterizers: + * cell, llvmpipe, softpipe. + */ + +#ifdef GALLIUM_SOFTPIPE +#include "softpipe/sp_public.h" +#endif + +#ifdef GALLIUM_LLVMPIPE +#include "llvmpipe/lp_public.h" +#endif + +#ifdef GALLIUM_CELL +#include "cell/ppu/cell_public.h" +#endif + +struct pipe_screen * +swrast_create_screen(struct sw_winsys *winsys) +{ + const char *default_driver; + const char *driver; + struct pipe_screen *screen = NULL; + +#if defined(GALLIUM_CELL) + default_driver = "cell"; +#elif defined(GALLIUM_LLVMPIPE) + default_driver = "llvmpipe"; +#elif defined(GALLIUM_SOFTPIPE) + default_driver = "softpipe"; +#else + default_driver = ""; +#endif + + driver = debug_get_option("GALLIUM_DRIVER", default_driver); + +#if defined(GALLIUM_CELL) + if (screen == NULL && strcmp(driver, "cell") == 0) + screen = cell_create_screen( winsys ); +#endif + +#if defined(GALLIUM_LLVMPIPE) + if (screen == NULL && strcmp(driver, "llvmpipe") == 0) + screen = llvmpipe_create_screen( winsys ); +#endif + +#if defined(GALLIUM_SOFTPIPE) + if (screen == NULL) + screen = softpipe_create_screen( winsys ); +#endif + + return screen; +} diff --git a/src/gallium/drivers/sw/sw_public.h b/src/gallium/drivers/sw/sw_public.h new file mode 100644 index 00000000000..7085c5c85a0 --- /dev/null +++ b/src/gallium/drivers/sw/sw_public.h @@ -0,0 +1,13 @@ +#ifndef SW_PUBLIC_H +#define SW_PUBLIC_H + +/* A convenience library, primarily to isolate the logic required to + * figure out which if any software rasterizers have been built and + * select between them. + */ +struct sw_winsys; + +struct pipe_screen * +swrast_create_screen(struct sw_winsys *winsys); + +#endif diff --git a/src/gallium/include/state_tracker/graw.h b/src/gallium/include/state_tracker/graw.h new file mode 100644 index 00000000000..a58e18e4739 --- /dev/null +++ b/src/gallium/include/state_tracker/graw.h @@ -0,0 +1,36 @@ +#ifndef GALLIUM_RAW_H +#define GALLIUM_RAW_H + +/* This is an API for exercising gallium functionality in a + * platform-neutral fashion. Whatever platform integration is + * necessary to implement this interface is orchestrated by the + * individual target building this entity. + * + * For instance, the graw-xlib target includes code to implent these + * interfaces on top of the X window system. + * + * Programs using this interface may additionally benefit from some of + * the utilities currently in the libgallium.a library, especially + * those for parsing text representations of TGSI shaders. + */ + +#include "pipe/p_format.h" + +struct pipe_screen; + +struct pipe_screen *graw_init( void ); + +/* Returns a handle to be used with flush_frontbuffer()/present(). + * + * Query format support with screen::is_format_supported and usage + * XXX. + */ +void *graw_create_window( int x, + int y, + unsigned width, + unsigned height, + enum pipe_format format ); + +void graw_destroy_window( void *handle ); + +#endif diff --git a/src/gallium/targets/SConscript b/src/gallium/targets/SConscript index 747e64508f7..1292d4f6193 100644 --- a/src/gallium/targets/SConscript +++ b/src/gallium/targets/SConscript @@ -10,6 +10,11 @@ if 'gdi' in env['winsys']: 'libgl-gdi/SConscript', ]) +if 'graw-xlib' in env['winsys']: + SConscript([ + 'graw-xlib/SConscript', + ]) + if env['dri']: SConscript([ 'SConscript.dri' diff --git a/src/gallium/targets/graw-xlib/SConscript b/src/gallium/targets/graw-xlib/SConscript new file mode 100644 index 00000000000..24cea92f907 --- /dev/null +++ b/src/gallium/targets/graw-xlib/SConscript @@ -0,0 +1,57 @@ +####################################################################### +# SConscript for xlib winsys + +Import('*') + +if env['platform'] != 'linux': + Return() + +if not set(('softpipe', 'llvmpipe', 'cell')).intersection(env['drivers']): + print 'warning: no supported pipe driver: skipping build of xlib libGL.so' + Return() + +env = env.Clone() + +env.Prepend(LIBS = [ + ws_xlib, + trace, + identity, +# gallium, +]) + +env.Append(CPPPATH = [ + '#src/gallium/drivers', +]) + + +sources = [ + 'graw_xlib.c', +] + +if 'softpipe' in env['drivers']: + env.Append(CPPDEFINES = 'GALLIUM_SOFTPIPE') + env.Prepend(LIBS = [softpipe]) + +if 'llvmpipe' in env['drivers']: + env.Tool('llvm') + if 'LLVM_VERSION' in env: + env.Append(CPPDEFINES = 'GALLIUM_LLVMPIPE') + env.Tool('udis86') + env.Prepend(LIBS = [llvmpipe]) + +# Need this for trace, identity drivers referenced by +# gallium_wrap_screen(). +# +env.Prepend(LIBS = [gallium]) + +# TODO: write a wrapper function http://www.scons.org/wiki/WrapperFunctions +graw = env.SharedLibrary( + target ='graw', + source = sources, +) + +env.InstallSharedLibrary(graw, version=(1, 0)) + +graw = env.FindIxes(graw, 'SHLIBPREFIX', 'SHLIBSUFFIX') + +Export('graw') diff --git a/src/gallium/targets/graw-xlib/graw.h b/src/gallium/targets/graw-xlib/graw.h new file mode 100644 index 00000000000..a58e18e4739 --- /dev/null +++ b/src/gallium/targets/graw-xlib/graw.h @@ -0,0 +1,36 @@ +#ifndef GALLIUM_RAW_H +#define GALLIUM_RAW_H + +/* This is an API for exercising gallium functionality in a + * platform-neutral fashion. Whatever platform integration is + * necessary to implement this interface is orchestrated by the + * individual target building this entity. + * + * For instance, the graw-xlib target includes code to implent these + * interfaces on top of the X window system. + * + * Programs using this interface may additionally benefit from some of + * the utilities currently in the libgallium.a library, especially + * those for parsing text representations of TGSI shaders. + */ + +#include "pipe/p_format.h" + +struct pipe_screen; + +struct pipe_screen *graw_init( void ); + +/* Returns a handle to be used with flush_frontbuffer()/present(). + * + * Query format support with screen::is_format_supported and usage + * XXX. + */ +void *graw_create_window( int x, + int y, + unsigned width, + unsigned height, + enum pipe_format format ); + +void graw_destroy_window( void *handle ); + +#endif diff --git a/src/gallium/targets/graw-xlib/graw_xlib.c b/src/gallium/targets/graw-xlib/graw_xlib.c new file mode 100644 index 00000000000..fb8ef9d78b6 --- /dev/null +++ b/src/gallium/targets/graw-xlib/graw_xlib.c @@ -0,0 +1,181 @@ +#include "pipe/p_compiler.h" +#include "util/u_debug.h" +#include "util/u_memory.h" +#include "target-helpers/wrap_screen.h" +#include "state_tracker/xlib_sw_winsys.h" + +#ifdef GALLIUM_SOFTPIPE +#include "softpipe/sp_public.h" +#endif + +#ifdef GALLIUM_LLVMPIPE +#include "llvmpipe/lp_public.h" +#endif + +/* Haven't figured out a decent way to build the helper code yet - + * #include it here temporarily. + */ +#include "sw/sw_public.h" +#include "sw/sw.c" + +#include "graw.h" + +#include +#include +#include +#include + +static struct { + Display *display; +} graw; + + +struct pipe_screen * +graw_init( void ) +{ + const char *default_driver; + const char *driver; + struct pipe_screen *screen = NULL; + struct sw_winsys *winsys = NULL; + + graw.display = XOpenDisplay(NULL); + if (graw.display == NULL) + return NULL; + + /* Create the underlying winsys, which performs presents to Xlib + * drawables: + */ + winsys = xlib_create_sw_winsys( graw.display ); + if (winsys == NULL) + return NULL; + +#if defined(GALLIUM_LLVMPIPE) + default_driver = "llvmpipe"; +#elif defined(GALLIUM_SOFTPIPE) + default_driver = "softpipe"; +#else + default_driver = ""; +#endif + + driver = debug_get_option("GALLIUM_DRIVER", default_driver); + +#if defined(GALLIUM_LLVMPIPE) + if (screen == NULL && strcmp(driver, "llvmpipe") == 0) + screen = llvmpipe_create_screen( winsys ); +#endif + +#if defined(GALLIUM_SOFTPIPE) + if (screen == NULL) + screen = softpipe_create_screen( winsys ); +#endif + + /* Inject any wrapping layers we want to here: + */ + return gallium_wrap_screen( screen ); +} + + + + + +void * +graw_create_window( int x, + int y, + unsigned width, + unsigned height, + enum pipe_format format ) +{ + struct xlib_drawable *handle = NULL; + XSetWindowAttributes attr; + Window root; + Window win = 0; + XVisualInfo templat, *visinfo = NULL; + unsigned mask; + int n; + int scrnum; + + + scrnum = DefaultScreen( graw.display ); + root = RootWindow( graw.display, scrnum ); + + + if (format != PIPE_FORMAT_R8G8B8A8_UNORM) + goto fail; + + if (graw.display == NULL) + goto fail; + + handle = CALLOC_STRUCT(xlib_drawable); + if (handle == NULL) + goto fail; + + + mask = VisualScreenMask | VisualDepthMask | VisualClassMask; + templat.screen = DefaultScreen(graw.display); + templat.depth = 32; + templat.class = TrueColor; + + visinfo = XGetVisualInfo(graw.display, mask, &templat, &n); + if (!visinfo) { + printf("Error: couldn't get an RGB, Double-buffered visual\n"); + exit(1); + } + + /* window attributes */ + attr.background_pixel = 0; + attr.border_pixel = 0; + attr.colormap = XCreateColormap( graw.display, root, visinfo->visual, AllocNone); + attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask; + /* XXX this is a bad way to get a borderless window! */ + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; + + win = XCreateWindow( graw.display, root, x, y, width, height, + 0, visinfo->depth, InputOutput, + visinfo->visual, mask, &attr ); + + + /* set hints and properties */ + { + char *name = NULL; + XSizeHints sizehints; + sizehints.x = x; + sizehints.y = y; + sizehints.width = width; + sizehints.height = height; + sizehints.flags = USSize | USPosition; + XSetNormalHints(graw.display, win, &sizehints); + XSetStandardProperties(graw.display, win, name, name, + None, (char **)NULL, 0, &sizehints); + } + + XFree(visinfo); + XMapWindow(graw.display, win); + while (1) { + XEvent e; + XNextEvent( graw.display, &e ); + if (e.type == MapNotify && e.xmap.window == win) { + break; + } + } + + handle->visual = visinfo->visual; + handle->drawable = (Drawable)win; + handle->depth = visinfo->depth; + return (void *)handle; + +fail: + FREE(handle); + XFree(visinfo); + + if (win) + XDestroyWindow(graw.display, win); + + return NULL; +} + + +void +graw_destroy_window( void *xlib_drawable ) +{ +} + -- cgit v1.2.3 From d0d73a38dab49d762dfbe596b66634d5d187501a Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Sun, 28 Mar 2010 10:39:46 -0700 Subject: ws/xlib: Call XFlush after PutImage Want to see the results. --- src/gallium/winsys/sw/xlib/xlib_sw_winsys.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/gallium') diff --git a/src/gallium/winsys/sw/xlib/xlib_sw_winsys.c b/src/gallium/winsys/sw/xlib/xlib_sw_winsys.c index 54789d7a87c..ad843b7def6 100644 --- a/src/gallium/winsys/sw/xlib/xlib_sw_winsys.c +++ b/src/gallium/winsys/sw/xlib/xlib_sw_winsys.c @@ -341,6 +341,8 @@ xlib_sw_display(struct xlib_drawable *xlib_drawable, XPutImage(xm_dt->display, xlib_drawable->drawable, xm_dt->gc, ximage, 0, 0, 0, 0, xm_dt->width, xm_dt->height); } + + XFlush(xm_dt->display); } /** -- cgit v1.2.3 From 1c2912ee7a47170bbaa8a71d4af729d0caf17f04 Mon Sep 17 00:00:00 2001 From: Marek Olšák Date: Sun, 28 Mar 2010 18:38:30 +0200 Subject: r300g: print configurable debugging info on non-debug builds --- src/gallium/drivers/r300/r300_context.h | 2 +- src/gallium/drivers/r300/r300_screen.h | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/r300/r300_context.h b/src/gallium/drivers/r300/r300_context.h index eb9178a2656..0a82484e89d 100644 --- a/src/gallium/drivers/r300/r300_context.h +++ b/src/gallium/drivers/r300/r300_context.h @@ -409,7 +409,7 @@ static INLINE void CTX_DBG(struct r300_context * ctx, unsigned flags, if (CTX_DBG_ON(ctx, flags)) { va_list va; va_start(va, fmt); - debug_vprintf(fmt, va); + vfprintf(stderr, fmt, va); va_end(va); } } diff --git a/src/gallium/drivers/r300/r300_screen.h b/src/gallium/drivers/r300/r300_screen.h index a055159c93b..1cf8b7452d7 100644 --- a/src/gallium/drivers/r300/r300_screen.h +++ b/src/gallium/drivers/r300/r300_screen.h @@ -28,6 +28,8 @@ #include "r300_chipset.h" +#include + struct r300_screen { /* Parent class */ struct pipe_screen screen; @@ -80,7 +82,7 @@ static INLINE void SCREEN_DBG(struct r300_screen * screen, unsigned flags, if (SCREEN_DBG_ON(screen, flags)) { va_list va; va_start(va, fmt); - debug_vprintf(fmt, va); + vfprintf(stderr, fmt, va); va_end(va); } } -- cgit v1.2.3 From 37877b192e4f9e753f5e837520090206b342a6ea Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Tue, 23 Mar 2010 16:21:03 +0100 Subject: softpipe: Map GS constants, too. --- src/gallium/drivers/softpipe/sp_state_fs.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/softpipe/sp_state_fs.c b/src/gallium/drivers/softpipe/sp_state_fs.c index 2b089c28316..d6f3229bed7 100644 --- a/src/gallium/drivers/softpipe/sp_state_fs.c +++ b/src/gallium/drivers/softpipe/sp_state_fs.c @@ -181,9 +181,8 @@ softpipe_set_constant_buffer(struct pipe_context *pipe, /* note: reference counting */ pipe_buffer_reference(&softpipe->constants[shader][index], constants); - if(shader == PIPE_SHADER_VERTEX) { - draw_set_mapped_constant_buffer(softpipe->draw, PIPE_SHADER_VERTEX, index, - data, size); + if (shader == PIPE_SHADER_VERTEX || shader == PIPE_SHADER_GEOMETRY) { + draw_set_mapped_constant_buffer(softpipe->draw, shader, index, data, size); } softpipe->mapped_constants[shader][index] = data; -- cgit v1.2.3 From b9ad95d3ee9178dce9320d28b20d23d97370f7bd Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Mon, 29 Mar 2010 17:29:27 +0100 Subject: util: Distinguish between the different compression formats. In particular, all current uses of util_format_is_compressed() actually mean s3tc. --- src/gallium/auxiliary/util/u_format.csv | 20 ++++++++++++-------- src/gallium/auxiliary/util/u_format.h | 20 ++++++++++++++------ 2 files changed, 26 insertions(+), 14 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/auxiliary/util/u_format.csv b/src/gallium/auxiliary/util/u_format.csv index d2a925141b1..d819bbbde1c 100644 --- a/src/gallium/auxiliary/util/u_format.csv +++ b/src/gallium/auxiliary/util/u_format.csv @@ -110,14 +110,18 @@ PIPE_FORMAT_UYVY , subsampled, 2, 1, x32 , , , , xyz PIPE_FORMAT_YUYV , subsampled, 2, 1, x32 , , , , xyz1, yuv # Compressed formats -PIPE_FORMAT_DXT1_RGB , compressed, 4, 4, x64 , , , , xyz1, rgb -PIPE_FORMAT_DXT1_RGBA , compressed, 4, 4, x64 , , , , xyzw, rgb -PIPE_FORMAT_DXT3_RGBA , compressed, 4, 4, x128, , , , xyzw, rgb -PIPE_FORMAT_DXT5_RGBA , compressed, 4, 4, x128, , , , xyzw, rgb -PIPE_FORMAT_DXT1_SRGB , compressed, 4, 4, x64 , , , , xyz1, srgb -PIPE_FORMAT_DXT1_SRGBA , compressed, 4, 4, x64 , , , , xyzw, srgb -PIPE_FORMAT_DXT3_SRGBA , compressed, 4, 4, x128, , , , xyzw, srgb -PIPE_FORMAT_DXT5_SRGBA , compressed, 4, 4, x128, , , , xyzw, srgb +# - http://en.wikipedia.org/wiki/S3_Texture_Compression +# - http://www.opengl.org/registry/specs/EXT/texture_compression_s3tc.txt +# - http://www.opengl.org/registry/specs/ARB/texture_compression_rgtc.txt +# - http://msdn.microsoft.com/en-us/library/bb694531.aspx +PIPE_FORMAT_DXT1_RGB , s3tc, 4, 4, x64 , , , , xyz1, rgb +PIPE_FORMAT_DXT1_RGBA , s3tc, 4, 4, x64 , , , , xyzw, rgb +PIPE_FORMAT_DXT3_RGBA , s3tc, 4, 4, x128, , , , xyzw, rgb +PIPE_FORMAT_DXT5_RGBA , s3tc, 4, 4, x128, , , , xyzw, rgb +PIPE_FORMAT_DXT1_SRGB , s3tc, 4, 4, x64 , , , , xyz1, srgb +PIPE_FORMAT_DXT1_SRGBA , s3tc, 4, 4, x64 , , , , xyzw, srgb +PIPE_FORMAT_DXT3_SRGBA , s3tc, 4, 4, x128, , , , xyzw, srgb +PIPE_FORMAT_DXT5_SRGBA , s3tc, 4, 4, x128, , , , xyzw, srgb # Straightforward D3D10-like formats (also used for # vertex buffer element description) diff --git a/src/gallium/auxiliary/util/u_format.h b/src/gallium/auxiliary/util/u_format.h index c08fdcafcc8..98d4b98ebb5 100644 --- a/src/gallium/auxiliary/util/u_format.h +++ b/src/gallium/auxiliary/util/u_format.h @@ -56,15 +56,23 @@ enum util_format_layout { * * This is for formats like YV12 where there is less than one sample per * pixel. - * - * XXX: This could actually b */ UTIL_FORMAT_LAYOUT_SUBSAMPLED = 3, /** - * An unspecified compression algorithm. + * S3 Texture Compression formats. + */ + UTIL_FORMAT_LAYOUT_S3TC = 4, + + /** + * Red-Green Texture Compression formats. + */ + UTIL_FORMAT_LAYOUT_RGTC = 5, + + /** + * Everything else that doesn't fit in any of the above layouts. */ - UTIL_FORMAT_LAYOUT_COMPRESSED = 4 + UTIL_FORMAT_LAYOUT_OTHER = 6 }; @@ -210,7 +218,7 @@ util_format_name(enum pipe_format format) } static INLINE boolean -util_format_is_compressed(enum pipe_format format) +util_format_is_s3tc(enum pipe_format format) { const struct util_format_description *desc = util_format_description(format); @@ -219,7 +227,7 @@ util_format_is_compressed(enum pipe_format format) return FALSE; } - return desc->layout == UTIL_FORMAT_LAYOUT_COMPRESSED ? TRUE : FALSE; + return desc->layout == UTIL_FORMAT_LAYOUT_S3TC ? TRUE : FALSE; } static INLINE boolean -- cgit v1.2.3 From 28cf5e1191077e063fe2a81d9d35934b71d001e2 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Mon, 29 Mar 2010 17:30:09 +0100 Subject: r300: UTIL_FORMAT_LAYOUT_COMPRESSED -> UTIL_FORMAT_LAYOUT_S3TC. --- src/gallium/drivers/r300/r300_texture.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/r300/r300_texture.c b/src/gallium/drivers/r300/r300_texture.c index 7c86bdb4bdc..22ccadfe3dd 100644 --- a/src/gallium/drivers/r300/r300_texture.c +++ b/src/gallium/drivers/r300/r300_texture.c @@ -159,7 +159,7 @@ static uint32_t r300_translate_texformat(enum pipe_format format) } /* Compressed formats. */ - if (desc->layout == UTIL_FORMAT_LAYOUT_COMPRESSED) { + if (desc->layout == UTIL_FORMAT_LAYOUT_S3TC) { switch (format) { case PIPE_FORMAT_DXT1_RGB: case PIPE_FORMAT_DXT1_RGBA: -- cgit v1.2.3 From bade76191a3a429176694b3d7fd4f68409359735 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Mon, 29 Mar 2010 17:30:35 +0100 Subject: svga: util_format_is_compressed() -> util_format_is_s3tc(). --- src/gallium/drivers/svga/svga_screen_texture.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/svga/svga_screen_texture.c b/src/gallium/drivers/svga/svga_screen_texture.c index 4a058eda885..70d3a8a46ae 100644 --- a/src/gallium/drivers/svga/svga_screen_texture.c +++ b/src/gallium/drivers/svga/svga_screen_texture.c @@ -330,7 +330,7 @@ svga_texture_create(struct pipe_screen *screen, */ #if 0 if((templat->tex_usage & PIPE_TEXTURE_USAGE_RENDER_TARGET) && - !util_format_is_compressed(templat->format)) + !util_format_is_s3tc(templat->format)) tex->key.flags |= SVGA3D_SURFACE_HINT_RENDERTARGET; #endif @@ -969,7 +969,7 @@ svga_get_tex_sampler_view(struct pipe_context *pipe, struct pipe_texture *pt, if (min_lod == 0 && max_lod >= pt->last_level) view = FALSE; - if (util_format_is_compressed(pt->format) && view) { + if (util_format_is_s3tc(pt->format) && view) { format = svga_translate_format_render(pt->format); } -- cgit v1.2.3 From f3cb08f3dd81bc6479e8aa926fb74e73bb83cb6f Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Mon, 29 Mar 2010 17:31:16 +0100 Subject: i965g: util_format_is_compressed() -> util_format_is_s3tc(). --- src/gallium/drivers/i965/brw_screen_texture.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/i965/brw_screen_texture.c b/src/gallium/drivers/i965/brw_screen_texture.c index cadcb7cee2a..f9f17bdabac 100644 --- a/src/gallium/drivers/i965/brw_screen_texture.c +++ b/src/gallium/drivers/i965/brw_screen_texture.c @@ -206,7 +206,7 @@ static struct pipe_texture *brw_texture_create( struct pipe_screen *screen, /* XXX: compressed textures need special treatment here */ tex->cpp = util_format_get_blocksize(tex->base.format); - tex->compressed = util_format_is_compressed(tex->base.format); + tex->compressed = util_format_is_s3tc(tex->base.format); make_empty_list(&tex->views[0]); make_empty_list(&tex->views[1]); @@ -321,7 +321,7 @@ brw_texture_from_handle(struct pipe_screen *screen, templ->depth0 != 1) return NULL; - if (util_format_is_compressed(templ->format)) + if (util_format_is_s3tc(templ->format)) return NULL; tex = CALLOC_STRUCT(brw_texture); -- cgit v1.2.3 From 588dd187c45490368354f340f5175d2c4d7cbd3c Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Mon, 29 Mar 2010 17:52:10 +0100 Subject: Revert "python: Temporarily disable python state tracker until transfers are done by contexts" This reverts commit 50a778661930ec7aa875a9c5235e9910143ec700. --- src/gallium/state_trackers/python/SConscript | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/python/SConscript b/src/gallium/state_trackers/python/SConscript index d0d141fd249..781f54bf2b9 100644 --- a/src/gallium/state_trackers/python/SConscript +++ b/src/gallium/state_trackers/python/SConscript @@ -3,8 +3,7 @@ import os.path Import('*') -if 'python' in env['statetrackers'] and 0: - # FIXME: Disable python state tracker until transfers are done by contexts +if 'python' in env['statetrackers']: env = env.Clone() -- cgit v1.2.3 From 6cc5fbd76b8994da8174c39f8eacb6605f4aa3b2 Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Mon, 29 Mar 2010 21:06:53 +0300 Subject: ws/sw/dri: s/xm/dri_sw/ --- src/gallium/winsys/sw/dri/dri_sw_winsys.c | 147 +++++++++++++++--------------- 1 file changed, 74 insertions(+), 73 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/winsys/sw/dri/dri_sw_winsys.c b/src/gallium/winsys/sw/dri/dri_sw_winsys.c index 1c1e5612d28..fb4722fc75f 100644 --- a/src/gallium/winsys/sw/dri/dri_sw_winsys.c +++ b/src/gallium/winsys/sw/dri/dri_sw_winsys.c @@ -37,126 +37,127 @@ #include "dri_sw_winsys.h" -struct xm_displaytarget +struct dri_sw_displaytarget { void *data; void *mapped; }; +struct dri_sw_winsys +{ + struct sw_winsys base; +}; -/** Cast wrapper */ -static INLINE struct xm_displaytarget * -xm_displaytarget( struct sw_displaytarget *dt ) +static INLINE struct dri_sw_displaytarget * +dri_sw_displaytarget( struct sw_displaytarget *dt ) { - return (struct xm_displaytarget *)dt; + return (struct dri_sw_displaytarget *)dt; +} + +static INLINE struct dri_sw_winsys * +dri_sw_winsys( struct sw_winsys *ws ) +{ + return (struct dri_sw_winsys *)ws; } -/* pipe_screen::is_format_supported */ static boolean -xm_is_displaytarget_format_supported( struct sw_winsys *ws, - unsigned tex_usage, - enum pipe_format format ) +dri_sw_is_displaytarget_format_supported( struct sw_winsys *ws, + unsigned tex_usage, + enum pipe_format format ) { /* TODO: check visuals or other sensible thing here */ return TRUE; } -/* pipe_screen::texture_create DISPLAY_TARGET / SCANOUT / SHARED */ static struct sw_displaytarget * -xm_displaytarget_create(struct sw_winsys *winsys, - unsigned tex_usage, - enum pipe_format format, - unsigned width, unsigned height, - unsigned alignment, - unsigned *stride) +dri_sw_displaytarget_create(struct sw_winsys *winsys, + unsigned tex_usage, + enum pipe_format format, + unsigned width, unsigned height, + unsigned alignment, + unsigned *stride) { - struct xm_displaytarget *xm_dt; - unsigned nblocksy, size, xm_stride, format_stride; + struct dri_sw_displaytarget *dri_sw_dt; + unsigned nblocksy, size, dri_sw_stride, format_stride; - xm_dt = CALLOC_STRUCT(xm_displaytarget); - if(!xm_dt) - goto no_xm_dt; + dri_sw_dt = CALLOC_STRUCT(dri_sw_displaytarget); + if(!dri_sw_dt) + goto no_dt; format_stride = util_format_get_stride(format, width); - xm_stride = align(format_stride, alignment); + dri_sw_stride = align(format_stride, alignment); nblocksy = util_format_get_nblocksy(format, height); - size = xm_stride * nblocksy; + size = dri_sw_stride * nblocksy; - xm_dt->data = align_malloc(size, alignment); - if(!xm_dt->data) + dri_sw_dt->data = align_malloc(size, alignment); + if(!dri_sw_dt->data) goto no_data; - *stride = xm_stride; - return (struct sw_displaytarget *)xm_dt; + *stride = dri_sw_stride; + return (struct sw_displaytarget *)dri_sw_dt; no_data: - FREE(xm_dt); -no_xm_dt: + FREE(dri_sw_dt); +no_dt: return NULL; } -/* pipe_screen::texture_destroy */ static void -xm_displaytarget_destroy(struct sw_winsys *ws, - struct sw_displaytarget *dt) +dri_sw_displaytarget_destroy(struct sw_winsys *ws, + struct sw_displaytarget *dt) { - struct xm_displaytarget *xm_dt = xm_displaytarget(dt); + struct dri_sw_displaytarget *dri_sw_dt = dri_sw_displaytarget(dt); - if (xm_dt->data) { - FREE(xm_dt->data); + if (dri_sw_dt->data) { + FREE(dri_sw_dt->data); } - FREE(xm_dt); + FREE(dri_sw_dt); } -/* pipe_context::transfer_map */ static void * -xm_displaytarget_map(struct sw_winsys *ws, - struct sw_displaytarget *dt, - unsigned flags) +dri_sw_displaytarget_map(struct sw_winsys *ws, + struct sw_displaytarget *dt, + unsigned flags) { - struct xm_displaytarget *xm_dt = xm_displaytarget(dt); - xm_dt->mapped = xm_dt->data; - return xm_dt->mapped; + struct dri_sw_displaytarget *dri_sw_dt = dri_sw_displaytarget(dt); + dri_sw_dt->mapped = dri_sw_dt->data; + return dri_sw_dt->mapped; } -/* pipe_context::transfer_unmap */ static void -xm_displaytarget_unmap(struct sw_winsys *ws, - struct sw_displaytarget *dt) +dri_sw_displaytarget_unmap(struct sw_winsys *ws, + struct sw_displaytarget *dt) { - struct xm_displaytarget *xm_dt = xm_displaytarget(dt); - xm_dt->mapped = NULL; + struct dri_sw_displaytarget *dri_sw_dt = dri_sw_displaytarget(dt); + dri_sw_dt->mapped = NULL; } -/* pipe_screen::texture_from_handle */ static struct sw_displaytarget * -xm_displaytarget_from_handle(struct sw_winsys *winsys, - const struct pipe_texture *templ, - struct winsys_handle *whandle, - unsigned *stride) +dri_sw_displaytarget_from_handle(struct sw_winsys *winsys, + const struct pipe_texture *templ, + struct winsys_handle *whandle, + unsigned *stride) { assert(0); return NULL; } -/* pipe_screen::texture_get_handle */ static boolean -xm_displaytarget_get_handle(struct sw_winsys *winsys, - struct sw_displaytarget *dt, - struct winsys_handle *whandle) +dri_sw_displaytarget_get_handle(struct sw_winsys *winsys, + struct sw_displaytarget *dt, + struct winsys_handle *whandle) { assert(0); return FALSE; } -/* pipe_screen::flush_frontbuffer */ static void -xm_displaytarget_display(struct sw_winsys *ws, - struct sw_displaytarget *dt, - void *context_private) +dri_sw_displaytarget_display(struct sw_winsys *ws, + struct sw_displaytarget *dt, + void *context_private) { assert(0); } @@ -171,29 +172,29 @@ dri_destroy_sw_winsys(struct sw_winsys *winsys) struct sw_winsys * dri_create_sw_winsys(void) { - struct sw_winsys *ws; + struct dri_sw_winsys *ws; - ws = CALLOC_STRUCT(sw_winsys); + ws = CALLOC_STRUCT(dri_sw_winsys); if (!ws) return NULL; - ws->destroy = dri_destroy_sw_winsys; + ws->base.destroy = dri_destroy_sw_winsys; - ws->is_displaytarget_format_supported = xm_is_displaytarget_format_supported; + ws->base.is_displaytarget_format_supported = dri_sw_is_displaytarget_format_supported; /* screen texture functions */ - ws->displaytarget_create = xm_displaytarget_create; - ws->displaytarget_destroy = xm_displaytarget_destroy; - ws->displaytarget_from_handle = xm_displaytarget_from_handle; - ws->displaytarget_get_handle = xm_displaytarget_get_handle; + ws->base.displaytarget_create = dri_sw_displaytarget_create; + ws->base.displaytarget_destroy = dri_sw_displaytarget_destroy; + ws->base.displaytarget_from_handle = dri_sw_displaytarget_from_handle; + ws->base.displaytarget_get_handle = dri_sw_displaytarget_get_handle; /* texture functions */ - ws->displaytarget_map = xm_displaytarget_map; - ws->displaytarget_unmap = xm_displaytarget_unmap; + ws->base.displaytarget_map = dri_sw_displaytarget_map; + ws->base.displaytarget_unmap = dri_sw_displaytarget_unmap; - ws->displaytarget_display = xm_displaytarget_display; + ws->base.displaytarget_display = dri_sw_displaytarget_display; - return ws; + return &ws->base; } /* vim: set sw=3 ts=8 sts=3 expandtab: */ -- cgit v1.2.3 From 625e024b186829f199458679921916971a5b00cb Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Mon, 29 Mar 2010 21:06:54 +0300 Subject: st/dri/sw: add drisw_api similarly to dri1_api I am pretty sure that this is in gallium spirit, so commit. Thanks to Chia-I for suggesting this. --- src/gallium/include/state_tracker/dri1_api.h | 8 +- src/gallium/include/state_tracker/drisw_api.h | 35 ++++++++ src/gallium/state_trackers/dri/common/dri_st_api.c | 2 +- src/gallium/state_trackers/dri/drm/dri1.c | 30 +++---- src/gallium/state_trackers/dri/sw/drisw.c | 100 ++++++++------------- src/gallium/state_trackers/dri/sw/drisw.h | 2 +- src/gallium/targets/dri-swrast/swrast_drm_api.c | 17 ++-- src/gallium/targets/libgl-xlib/xlib.c | 8 ++ src/gallium/winsys/sw/dri/dri_sw_winsys.c | 37 ++++++-- src/gallium/winsys/sw/dri/dri_sw_winsys.h | 4 +- 10 files changed, 141 insertions(+), 102 deletions(-) create mode 100644 src/gallium/include/state_tracker/drisw_api.h (limited to 'src/gallium') diff --git a/src/gallium/include/state_tracker/dri1_api.h b/src/gallium/include/state_tracker/dri1_api.h index 27b7a28c467..bb1cd6d1d82 100644 --- a/src/gallium/include/state_tracker/dri1_api.h +++ b/src/gallium/include/state_tracker/dri1_api.h @@ -7,14 +7,14 @@ #include "state_tracker/drm_api.h" -struct drm_clip_rect; - struct pipe_screen; struct pipe_winsys; struct pipe_buffer; struct pipe_context; struct pipe_texture; +struct drm_clip_rect; + struct dri1_api_version { int major; @@ -31,8 +31,8 @@ struct dri1_api_lock_funcs { void (*lock) (struct pipe_context * pipe); void (*unlock) (struct pipe_context * locked_pipe); - boolean(*is_locked) (struct pipe_context * locked_pipe); - boolean(*is_lock_lost) (struct pipe_context * locked_pipe); + boolean(*is_locked) (struct pipe_context * locked_pipe); + boolean(*is_lock_lost) (struct pipe_context * locked_pipe); void (*clear_lost_lock) (struct pipe_context * locked_pipe); }; diff --git a/src/gallium/include/state_tracker/drisw_api.h b/src/gallium/include/state_tracker/drisw_api.h new file mode 100644 index 00000000000..c6adebb4ec5 --- /dev/null +++ b/src/gallium/include/state_tracker/drisw_api.h @@ -0,0 +1,35 @@ +#ifndef _DRISW_API_H_ +#define _DRISW_API_H_ + +#include "pipe/p_compiler.h" +#include "pipe/p_screen.h" +#include "pipe/p_format.h" + +#include "state_tracker/drm_api.h" + +struct pipe_screen; +struct pipe_winsys; +struct pipe_buffer; +struct pipe_context; +struct pipe_texture; + +struct dri_drawable; + +/** + * This callback struct is intended for the winsys to call the loader. + */ + +struct drisw_loader_funcs +{ + void (*put_image) (struct dri_drawable *dri_drawable, + void *data, unsigned width, unsigned height); +}; + +struct drisw_create_screen_arg +{ + struct drm_create_screen_arg base; + + struct drisw_loader_funcs *lf; +}; + +#endif diff --git a/src/gallium/state_trackers/dri/common/dri_st_api.c b/src/gallium/state_trackers/dri/common/dri_st_api.c index 40b24b18e9f..7ba7ec383d8 100644 --- a/src/gallium/state_trackers/dri/common/dri_st_api.c +++ b/src/gallium/state_trackers/dri/common/dri_st_api.c @@ -80,7 +80,7 @@ dri_st_framebuffer_validate(struct st_framebuffer_iface *stfbi, } #else if (new_stamp) - drisw_update_drawable_info(drawable->dPriv); + drisw_update_drawable_info(drawable); drisw_allocate_textures(drawable, statt_mask); #endif diff --git a/src/gallium/state_trackers/dri/drm/dri1.c b/src/gallium/state_trackers/dri/drm/dri1.c index aad098bb301..9b5842ba2bf 100644 --- a/src/gallium/state_trackers/dri/drm/dri1.c +++ b/src/gallium/state_trackers/dri/drm/dri1.c @@ -404,6 +404,19 @@ dri1_allocate_textures(struct dri_drawable *drawable, drawable->old_h = height; } +/* + * Backend function for init_screen. + */ + +static const __DRIextension *dri1_screen_extensions[] = { + &driReadDrawableExtension, + &driCopySubBufferExtension.base, + &driSwapControlExtension.base, + &driFrameTrackingExtension.base, + &driMediaStreamCounterExtension.base, + NULL +}; + static void st_dri_lock(struct pipe_context *pipe) { @@ -442,21 +455,6 @@ static struct dri1_api_lock_funcs dri1_lf = { .clear_lost_lock = st_dri_clear_lost_lock }; -/* - * Backend function for init_screen. - */ - -static const __DRIextension *dri1_screen_extensions[] = { - &driReadDrawableExtension, - &driCopySubBufferExtension.base, - &driSwapControlExtension.base, - &driFrameTrackingExtension.base, - &driMediaStreamCounterExtension.base, - NULL -}; - -struct dri1_api *__dri1_api_hooks = NULL; - static INLINE void dri1_copy_version(struct dri1_api_version *dst, const struct __DRIversionRec *src) @@ -466,6 +464,8 @@ dri1_copy_version(struct dri1_api_version *dst, dst->patch_level = src->patch; } +struct dri1_api *__dri1_api_hooks = NULL; + const __DRIconfig ** dri1_init_screen(__DRIscreen * sPriv) { diff --git a/src/gallium/state_trackers/dri/sw/drisw.c b/src/gallium/state_trackers/dri/sw/drisw.c index b7eba63bcb9..b8256710972 100644 --- a/src/gallium/state_trackers/dri/sw/drisw.c +++ b/src/gallium/state_trackers/dri/sw/drisw.c @@ -27,38 +27,18 @@ **************************************************************************/ /* TODO: - * - * stride: - * - * The driver and the loaders (libGL, xserver/glx) compute the stride from the - * width independently. winsys has a workaround that works for softpipe but may - * explode for other drivers or platforms, rendering- or performance-wise. - * Solving this issue properly requires extending the DRISW loader extension, - * in order to make the stride available to the putImage callback. - * - * drisw_api: - * - * Define drisw_api similarly to dri1_api and use it to call the loader. This - * is predicated on support for calling the loader from the winsys, which has - * to grow for DRI2 as well. * * xshm / texture_from_pixmap / EGLImage: * * Allow the loaders to use the XSHM extension. It probably requires callbacks - * for createImage/destroyImage similar to DRI2 getBuffers. Probably not worth - * it, given the scope of DRISW, unless it falls naturally from properly - * solving the other issues. - * - * fences: - * - * No fences are used, are they needed for llvmpipe / cell ? + * for createImage/destroyImage similar to DRI2 getBuffers. */ #include "util/u_format.h" #include "util/u_memory.h" #include "util/u_inlines.h" #include "pipe/p_context.h" -#include "state_tracker/drm_api.h" +#include "state_tracker/drisw_api.h" #include "dri_screen.h" #include "dri_context.h" @@ -80,60 +60,47 @@ get_drawable_info(__DRIdrawable *dPriv, int *w, int *h) dPriv->loaderPrivate); } -/* - * Set the width to 'stride / cpp'. PutImage seems to correctly clip the width - * to the actual width of the dst drawable. Even if this is not specified but - * an implementation detail, it is the correct thing to do, so rely on it. XXX - */ static INLINE void -put_image(__DRIdrawable *dPriv, void *data, unsigned width) +put_image(__DRIdrawable *dPriv, void *data, unsigned width, unsigned height) { __DRIscreen *sPriv = dPriv->driScreenPriv; const __DRIswrastLoaderExtension *loader = sPriv->swrast_loader; loader->putImage(dPriv, __DRI_SWRAST_IMAGE_OP_SWAP, - 0, 0, width, dPriv->h, + 0, 0, width, height, data, dPriv->loaderPrivate); } void -drisw_update_drawable_info(__DRIdrawable *dPriv) +drisw_update_drawable_info(struct dri_drawable *drawable) { + __DRIdrawable *dPriv = drawable->dPriv; + get_drawable_info(dPriv, &dPriv->w, &dPriv->h); } +static void +drisw_put_image(struct dri_drawable *drawable, + void *data, unsigned width, unsigned height) +{ + __DRIdrawable *dPriv = drawable->dPriv; + + put_image(dPriv, data, width, height); +} + static INLINE void drisw_present_texture(__DRIdrawable *dPriv, struct pipe_texture *ptex) { struct dri_drawable *drawable = dri_drawable(dPriv); struct dri_screen *screen = dri_screen(drawable->sPriv); - struct pipe_context *pipe; struct pipe_surface *psurf; - struct pipe_transfer *ptrans; - void *pmap; - unsigned width; - pipe = dri1_get_pipe_context(screen); psurf = dri1_get_pipe_surface(drawable, ptex); - if (!pipe || !psurf) + if (!psurf) return; - ptrans = pipe->get_tex_transfer(pipe, ptex, 0, 0, 0, - PIPE_TRANSFER_READ, - 0, 0, dPriv->w, dPriv->h); - - width = ptrans->stride / util_format_get_blocksize(ptex->format); - - pmap = pipe->transfer_map(pipe, ptrans); - - assert(pmap); - - put_image(dPriv, pmap, width); - - pipe->transfer_unmap(pipe, ptrans); - - pipe->tex_transfer_destroy(pipe, ptrans); + screen->pipe_screen->flush_frontbuffer(screen->pipe_screen, psurf, drawable); } static INLINE void @@ -163,38 +130,38 @@ drisw_copy_to_front(__DRIdrawable * dPriv, */ void -drisw_flush_frontbuffer(struct dri_drawable *drawable, - enum st_attachment_type statt) +drisw_swap_buffers(__DRIdrawable *dPriv) { struct dri_context *ctx = dri_get_current(); + struct dri_drawable *drawable = dri_drawable(dPriv); struct pipe_texture *ptex; if (!ctx) return; - ptex = drawable->textures[statt]; + ptex = drawable->textures[ST_ATTACHMENT_BACK_LEFT]; if (ptex) { - drisw_copy_to_front(ctx->dPriv, ptex); + ctx->st->flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); + + drisw_copy_to_front(dPriv, ptex); } } void -drisw_swap_buffers(__DRIdrawable *dPriv) +drisw_flush_frontbuffer(struct dri_drawable *drawable, + enum st_attachment_type statt) { struct dri_context *ctx = dri_get_current(); - struct dri_drawable *drawable = dri_drawable(dPriv); struct pipe_texture *ptex; if (!ctx) return; - ptex = drawable->textures[ST_ATTACHMENT_BACK_LEFT]; + ptex = drawable->textures[statt]; if (ptex) { - ctx->st->flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); - - drisw_copy_to_front(dPriv, ptex); + drisw_copy_to_front(ctx->dPriv, ptex); } } @@ -286,12 +253,16 @@ static const __DRIextension *drisw_screen_extensions[] = { NULL }; +static struct drisw_loader_funcs drisw_lf = { + .put_image = drisw_put_image +}; + const __DRIconfig ** drisw_init_screen(__DRIscreen * sPriv) { const __DRIconfig **configs; struct dri_screen *screen; - struct drm_create_screen_arg arg; + struct drisw_create_screen_arg arg; screen = CALLOC_STRUCT(dri_screen); if (!screen) @@ -304,9 +275,10 @@ drisw_init_screen(__DRIscreen * sPriv) sPriv->private = (void *)screen; sPriv->extensions = drisw_screen_extensions; - arg.mode = DRM_CREATE_DRISW; + arg.base.mode = DRM_CREATE_DRISW; + arg.lf = &drisw_lf; - configs = dri_init_screen_helper(screen, &arg, 32); + configs = dri_init_screen_helper(screen, &arg.base, 32); if (!configs) goto fail; diff --git a/src/gallium/state_trackers/dri/sw/drisw.h b/src/gallium/state_trackers/dri/sw/drisw.h index 2c0d5610fac..c0c874f7326 100644 --- a/src/gallium/state_trackers/dri/sw/drisw.h +++ b/src/gallium/state_trackers/dri/sw/drisw.h @@ -39,7 +39,7 @@ const __DRIconfig ** drisw_init_screen(__DRIscreen * sPriv); void -drisw_update_drawable_info(__DRIdrawable *dPriv); +drisw_update_drawable_info(struct dri_drawable *drawable); void drisw_flush_frontbuffer(struct dri_drawable *drawable, diff --git a/src/gallium/targets/dri-swrast/swrast_drm_api.c b/src/gallium/targets/dri-swrast/swrast_drm_api.c index 1f24d7650d7..63b935bb07b 100644 --- a/src/gallium/targets/dri-swrast/swrast_drm_api.c +++ b/src/gallium/targets/dri-swrast/swrast_drm_api.c @@ -32,15 +32,7 @@ #include "state_tracker/sw_winsys.h" #include "dri_sw_winsys.h" -/* Copied from targets/libgl-xlib. - * - * TODO: - * This function should be put in targets/common or winsys/sw/common and shared - * with targets/libgl-xlib and winsys/sw/drm. - * - * For targets/common, you get layering violations unless all of drm_api's are - * moved under targets. - */ +/* Copied from targets/libgl-xlib */ #ifdef GALLIUM_SOFTPIPE #include "softpipe/sp_public.h" @@ -98,19 +90,24 @@ swrast_drm_create_screen(struct drm_api *api, { struct sw_winsys *winsys = NULL; struct pipe_screen *screen = NULL; + struct drisw_create_screen_arg *drisw; (void) drmFD; if (arg != NULL) { switch(arg->mode) { case DRM_CREATE_DRISW: + drisw = (struct drisw_create_screen_arg *)arg; break; default: return NULL; } } + else { + return NULL; + } - winsys = dri_create_sw_winsys(); + winsys = dri_create_sw_winsys(drisw->lf); if (winsys == NULL) return NULL; diff --git a/src/gallium/targets/libgl-xlib/xlib.c b/src/gallium/targets/libgl-xlib/xlib.c index 4a8366280d8..48e5bdff429 100644 --- a/src/gallium/targets/libgl-xlib/xlib.c +++ b/src/gallium/targets/libgl-xlib/xlib.c @@ -55,6 +55,14 @@ PUBLIC const struct st_module st_module_OpenGL = { * GALLIUM_CELL, etc. Scons already eliminates those #defines, so * things that are painful for it now are likely to be painful for * other build systems in the future. + * + * Copies (full or partial): + * targets/libgl-xlib + * targets/graw-xlib + * targets/dri-swrast + * winsys/sw/drm + * drivers/sw + * */ #ifdef GALLIUM_SOFTPIPE diff --git a/src/gallium/winsys/sw/dri/dri_sw_winsys.c b/src/gallium/winsys/sw/dri/dri_sw_winsys.c index fb4722fc75f..870c6afc124 100644 --- a/src/gallium/winsys/sw/dri/dri_sw_winsys.c +++ b/src/gallium/winsys/sw/dri/dri_sw_winsys.c @@ -39,6 +39,11 @@ struct dri_sw_displaytarget { + enum pipe_format format; + unsigned width; + unsigned height; + unsigned stride; + void *data; void *mapped; }; @@ -46,6 +51,8 @@ struct dri_sw_displaytarget struct dri_sw_winsys { struct sw_winsys base; + + struct drisw_loader_funcs *lf; }; static INLINE struct dri_sw_displaytarget * @@ -79,23 +86,27 @@ dri_sw_displaytarget_create(struct sw_winsys *winsys, unsigned *stride) { struct dri_sw_displaytarget *dri_sw_dt; - unsigned nblocksy, size, dri_sw_stride, format_stride; + unsigned nblocksy, size, format_stride; dri_sw_dt = CALLOC_STRUCT(dri_sw_displaytarget); if(!dri_sw_dt) goto no_dt; + dri_sw_dt->format = format; + dri_sw_dt->width = width; + dri_sw_dt->height = height; + format_stride = util_format_get_stride(format, width); - dri_sw_stride = align(format_stride, alignment); + dri_sw_dt->stride = align(format_stride, alignment); nblocksy = util_format_get_nblocksy(format, height); - size = dri_sw_stride * nblocksy; + size = dri_sw_dt->stride * nblocksy; dri_sw_dt->data = align_malloc(size, alignment); if(!dri_sw_dt->data) goto no_data; - *stride = dri_sw_stride; + *stride = dri_sw_dt->stride; return (struct sw_displaytarget *)dri_sw_dt; no_data: @@ -159,7 +170,20 @@ dri_sw_displaytarget_display(struct sw_winsys *ws, struct sw_displaytarget *dt, void *context_private) { - assert(0); + struct dri_sw_winsys *dri_sw_ws = dri_sw_winsys(ws); + struct dri_sw_displaytarget *dri_sw_dt = dri_sw_displaytarget(dt); + struct dri_drawable *dri_drawable = (struct dri_drawable *)context_private; + unsigned width, height; + + /* Set the width to 'stride / cpp'. + * + * PutImage correctly clips to the width of the dst drawable. + */ + width = dri_sw_dt->stride / util_format_get_blocksize(dri_sw_dt->format); + + height = dri_sw_dt->height; + + dri_sw_ws->lf->put_image(dri_drawable, dri_sw_dt->data, width, height); } @@ -170,7 +194,7 @@ dri_destroy_sw_winsys(struct sw_winsys *winsys) } struct sw_winsys * -dri_create_sw_winsys(void) +dri_create_sw_winsys(struct drisw_loader_funcs *lf) { struct dri_sw_winsys *ws; @@ -178,6 +202,7 @@ dri_create_sw_winsys(void) if (!ws) return NULL; + ws->lf = lf; ws->base.destroy = dri_destroy_sw_winsys; ws->base.is_displaytarget_format_supported = dri_sw_is_displaytarget_format_supported; diff --git a/src/gallium/winsys/sw/dri/dri_sw_winsys.h b/src/gallium/winsys/sw/dri/dri_sw_winsys.h index c2382a68d78..329ac06a05b 100644 --- a/src/gallium/winsys/sw/dri/dri_sw_winsys.h +++ b/src/gallium/winsys/sw/dri/dri_sw_winsys.h @@ -29,8 +29,10 @@ #ifndef DRI_SW_WINSYS #define DRI_SW_WINSYS +#include "state_tracker/drisw_api.h" + struct sw_winsys; -struct sw_winsys *dri_create_sw_winsys(void); +struct sw_winsys *dri_create_sw_winsys(struct drisw_loader_funcs *lf); #endif -- cgit v1.2.3 From 012fabca722494162c244a367913562b8cfa4677 Mon Sep 17 00:00:00 2001 From: Zack Rusin Date: Mon, 29 Mar 2010 16:17:17 -0400 Subject: gallivm: make sure that the alloca's are the very first thing in the function otherwise mem2reg can't put them in registers --- src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'src/gallium') diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c index f160be878f8..95cd6a0ecf3 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c @@ -651,6 +651,19 @@ emit_declaration( unsigned first = decl->Range.First; unsigned last = decl->Range.Last; unsigned idx, i; + LLVMBasicBlockRef current_block = + LLVMGetInsertBlock(bld->base.builder); + LLVMBasicBlockRef first_block = + LLVMGetEntryBasicBlock( + LLVMGetBasicBlockParent(current_block)); + LLVMValueRef first_inst = + LLVMGetFirstInstruction(first_block); + + /* we want alloca's to be the first instruction + * in the function so we need to rewind the builder + * to the very beginning */ + LLVMPositionBuilderBefore(bld->base.builder, + first_inst); for (idx = first; idx <= last; ++idx) { boolean ok; @@ -673,10 +686,15 @@ emit_declaration( ok = TRUE; } - if (!ok) + if (!ok) { + LLVMPositionBuilderAtEnd(bld->base.builder, + current_block); return FALSE; + } } + LLVMPositionBuilderAtEnd(bld->base.builder, + current_block); return TRUE; } -- cgit v1.2.3 From 69492c3aca8361b903a7daaa697c0660faa22b04 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Mon, 29 Mar 2010 21:09:21 +0100 Subject: st/python: Move surface read/write methods to context. --- src/gallium/state_trackers/python/p_context.i | 249 +++++++++++++++++++++++++- src/gallium/state_trackers/python/p_texture.i | 226 ----------------------- src/gallium/state_trackers/python/st_sample.c | 30 ++-- src/gallium/state_trackers/python/st_sample.h | 7 +- 4 files changed, 267 insertions(+), 245 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/python/p_context.i b/src/gallium/state_trackers/python/p_context.i index df700bc663c..a8e164a072b 100644 --- a/src/gallium/state_trackers/python/p_context.i +++ b/src/gallium/state_trackers/python/p_context.i @@ -362,10 +362,253 @@ error1: pipe_surface_reference(&_dst, NULL); } - void clear(unsigned buffers, const float *rgba, double depth = 0.0f, - unsigned stencil = 0) + %cstring_output_allocate_size(char **STRING, int *LENGTH, free(*$1)); + void + surface_read_raw(struct st_surface *surface, + unsigned x, unsigned y, unsigned w, unsigned h, + char **STRING, int *LENGTH) + { + struct pipe_texture *texture = surface->texture; + struct pipe_context *pipe = $self->pipe; + struct pipe_transfer *transfer; + unsigned stride; + + stride = util_format_get_stride(texture->format, w); + *LENGTH = util_format_get_nblocksy(texture->format, h) * stride; + *STRING = (char *) malloc(*LENGTH); + if(!*STRING) + return; + + transfer = pipe->get_tex_transfer(pipe, + surface->texture, + surface->face, + surface->level, + surface->zslice, + PIPE_TRANSFER_READ, + x, y, w, h); + if(transfer) { + pipe_get_tile_raw(pipe, transfer, 0, 0, w, h, *STRING, stride); + pipe->tex_transfer_destroy(pipe, transfer); + } + } + + %cstring_input_binary(const char *STRING, unsigned LENGTH); + void + surface_write_raw(struct st_surface *surface, + unsigned x, unsigned y, unsigned w, unsigned h, + const char *STRING, unsigned LENGTH, unsigned stride = 0) { - $self->pipe->clear($self->pipe, buffers, rgba, depth, stencil); + struct pipe_texture *texture = surface->texture; + struct pipe_context *pipe = $self->pipe; + struct pipe_transfer *transfer; + + if(stride == 0) + stride = util_format_get_stride(texture->format, w); + + if(LENGTH < util_format_get_nblocksy(texture->format, h) * stride) + SWIG_exception(SWIG_ValueError, "offset must be smaller than buffer size"); + + transfer = pipe->get_tex_transfer(pipe, + surface->texture, + surface->face, + surface->level, + surface->zslice, + PIPE_TRANSFER_WRITE, + x, y, w, h); + if(!transfer) + SWIG_exception(SWIG_MemoryError, "couldn't initiate transfer"); + + pipe_put_tile_raw(pipe, transfer, 0, 0, w, h, STRING, stride); + pipe->tex_transfer_destroy(pipe, transfer); + + fail: + return; + } + + void + surface_read_rgba(struct st_surface *surface, + unsigned x, unsigned y, unsigned w, unsigned h, + float *rgba) + { + struct pipe_context *pipe = $self->pipe; + struct pipe_transfer *transfer; + transfer = pipe->get_tex_transfer(pipe, + surface->texture, + surface->face, + surface->level, + surface->zslice, + PIPE_TRANSFER_READ, + x, y, w, h); + if(transfer) { + pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba); + pipe->tex_transfer_destroy(pipe, transfer); + } + } + + void + surface_write_rgba(struct st_surface *surface, + unsigned x, unsigned y, unsigned w, unsigned h, + const float *rgba) + { + struct pipe_context *pipe = $self->pipe; + struct pipe_transfer *transfer; + transfer = pipe->get_tex_transfer(pipe, + surface->texture, + surface->face, + surface->level, + surface->zslice, + PIPE_TRANSFER_WRITE, + x, y, w, h); + if(transfer) { + pipe_put_tile_rgba(pipe, transfer, 0, 0, w, h, rgba); + pipe->tex_transfer_destroy(pipe, transfer); + } + } + + %cstring_output_allocate_size(char **STRING, int *LENGTH, free(*$1)); + void + surface_read_rgba8(struct st_surface *surface, + unsigned x, unsigned y, unsigned w, unsigned h, + char **STRING, int *LENGTH) + { + struct pipe_context *pipe = $self->pipe; + struct pipe_transfer *transfer; + float *rgba; + unsigned char *rgba8; + unsigned i, j, k; + + *LENGTH = 0; + *STRING = NULL; + + if (!surface) + return; + + *LENGTH = h*w*4; + *STRING = (char *) malloc(*LENGTH); + if(!*STRING) + return; + + rgba = malloc(h*w*4*sizeof(float)); + if(!rgba) + return; + + rgba8 = (unsigned char *) *STRING; + + transfer = pipe->get_tex_transfer(pipe, + surface->texture, + surface->face, + surface->level, + surface->zslice, + PIPE_TRANSFER_READ, + x, y, + w, h); + if(transfer) { + pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba); + for(j = 0; j < h; ++j) { + for(i = 0; i < w; ++i) + for(k = 0; k <4; ++k) + rgba8[j*w*4 + i*4 + k] = float_to_ubyte(rgba[j*w*4 + i*4 + k]); + } + pipe->tex_transfer_destroy(pipe, transfer); + } + + free(rgba); + } + + void + surface_read_z(struct st_surface *surface, + unsigned x, unsigned y, unsigned w, unsigned h, + unsigned *z) + { + struct pipe_context *pipe = $self->pipe; + struct pipe_transfer *transfer; + transfer = pipe->get_tex_transfer(pipe, + surface->texture, + surface->face, + surface->level, + surface->zslice, + PIPE_TRANSFER_READ, + x, y, w, h); + if(transfer) { + pipe_get_tile_z(pipe, transfer, 0, 0, w, h, z); + pipe->tex_transfer_destroy(pipe, transfer); + } + } + + void + surface_write_z(struct st_surface *surface, + unsigned x, unsigned y, unsigned w, unsigned h, + const unsigned *z) + { + struct pipe_context *pipe = $self->pipe; + struct pipe_transfer *transfer; + transfer = pipe->get_tex_transfer(pipe, + surface->texture, + surface->face, + surface->level, + surface->zslice, + PIPE_TRANSFER_WRITE, + x, y, w, h); + if(transfer) { + pipe_put_tile_z(pipe, transfer, 0, 0, w, h, z); + pipe->tex_transfer_destroy(pipe, transfer); + } + } + + void + surface_sample_rgba(struct st_surface *surface, + float *rgba) + { + st_sample_surface($self->pipe, surface, rgba); + } + + unsigned + surface_compare_rgba(struct st_surface *surface, + unsigned x, unsigned y, unsigned w, unsigned h, + const float *rgba, float tol = 0.0) + { + struct pipe_context *pipe = $self->pipe; + struct pipe_transfer *transfer; + float *rgba2; + const float *p1; + const float *p2; + unsigned i, j, n; + + rgba2 = MALLOC(h*w*4*sizeof(float)); + if(!rgba2) + return ~0; + + transfer = pipe->get_tex_transfer(pipe, + surface->texture, + surface->face, + surface->level, + surface->zslice, + PIPE_TRANSFER_READ, + x, y, w, h); + if(!transfer) { + FREE(rgba2); + return ~0; + } + + pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba2); + pipe->tex_transfer_destroy(pipe, transfer); + + p1 = rgba; + p2 = rgba2; + n = 0; + for(i = h*w; i; --i) { + unsigned differs = 0; + for(j = 4; j; --j) { + float delta = *p2++ - *p1++; + if (delta < -tol || delta > tol) + differs = 1; + } + n += differs; + } + + FREE(rgba2); + + return n; } }; diff --git a/src/gallium/state_trackers/python/p_texture.i b/src/gallium/state_trackers/python/p_texture.i index 2dd9e5050ea..923a6285289 100644 --- a/src/gallium/state_trackers/python/p_texture.i +++ b/src/gallium/state_trackers/python/p_texture.i @@ -124,232 +124,6 @@ struct st_surface FREE($self); } - %cstring_output_allocate_size(char **STRING, int *LENGTH, free(*$1)); - void get_tile_raw(struct st_context *ctx, unsigned x, unsigned y, unsigned w, unsigned h, char **STRING, int *LENGTH) - { - struct pipe_texture *texture = $self->texture; - struct pipe_context *pipe = ctx->pipe; - struct pipe_transfer *transfer; - unsigned stride; - - stride = util_format_get_stride(texture->format, w); - *LENGTH = util_format_get_nblocksy(texture->format, h) * stride; - *STRING = (char *) malloc(*LENGTH); - if(!*STRING) - return; - - transfer = pipe->get_tex_transfer(pipe, - $self->texture, - $self->face, - $self->level, - $self->zslice, - PIPE_TRANSFER_READ, - x, y, w, h); - if(transfer) { - pipe_get_tile_raw(pipe, transfer, 0, 0, w, h, *STRING, stride); - pipe->tex_transfer_destroy(pipe, transfer); - } - } - - %cstring_input_binary(const char *STRING, unsigned LENGTH); - void put_tile_raw(struct st_context *ctx, unsigned x, unsigned y, unsigned w, unsigned h, const char *STRING, unsigned LENGTH, unsigned stride = 0) - { - struct pipe_texture *texture = $self->texture; - struct pipe_context *pipe = ctx->pipe; - struct pipe_transfer *transfer; - - if(stride == 0) - stride = util_format_get_stride(texture->format, w); - - if(LENGTH < util_format_get_nblocksy(texture->format, h) * stride) - SWIG_exception(SWIG_ValueError, "offset must be smaller than buffer size"); - - transfer = pipe->get_tex_transfer(pipe, - $self->texture, - $self->face, - $self->level, - $self->zslice, - PIPE_TRANSFER_WRITE, - x, y, w, h); - if(!transfer) - SWIG_exception(SWIG_MemoryError, "couldn't initiate transfer"); - - pipe_put_tile_raw(pipe, transfer, 0, 0, w, h, STRING, stride); - pipe->tex_transfer_destroy(pipe, transfer); - - fail: - return; - } - - void get_tile_rgba(struct st_context *ctx, unsigned x, unsigned y, unsigned w, unsigned h, float *rgba) - { - struct pipe_context *pipe = ctx->pipe; - struct pipe_transfer *transfer; - transfer = pipe->get_tex_transfer(pipe, - $self->texture, - $self->face, - $self->level, - $self->zslice, - PIPE_TRANSFER_READ, - x, y, w, h); - if(transfer) { - pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba); - pipe->tex_transfer_destroy(pipe, transfer); - } - } - - void - put_tile_rgba(struct st_context *ctx, unsigned x, unsigned y, unsigned w, unsigned h, const float *rgba) - { - struct pipe_context *pipe = ctx->pipe; - struct pipe_transfer *transfer; - transfer = pipe->get_tex_transfer(pipe, - $self->texture, - $self->face, - $self->level, - $self->zslice, - PIPE_TRANSFER_WRITE, - x, y, w, h); - if(transfer) { - pipe_put_tile_rgba(pipe, transfer, 0, 0, w, h, rgba); - pipe->tex_transfer_destroy(pipe, transfer); - } - } - - %cstring_output_allocate_size(char **STRING, int *LENGTH, free(*$1)); - void - get_tile_rgba8(struct st_context *ctx, unsigned x, unsigned y, unsigned w, unsigned h, char **STRING, int *LENGTH) - { - struct pipe_context *pipe = ctx->pipe; - struct pipe_transfer *transfer; - float *rgba; - unsigned char *rgba8; - unsigned i, j, k; - - *LENGTH = 0; - *STRING = NULL; - - if (!$self) - return; - - *LENGTH = h*w*4; - *STRING = (char *) malloc(*LENGTH); - if(!*STRING) - return; - - rgba = malloc(h*w*4*sizeof(float)); - if(!rgba) - return; - - rgba8 = (unsigned char *) *STRING; - - transfer = pipe->get_tex_transfer(pipe, - $self->texture, - $self->face, - $self->level, - $self->zslice, - PIPE_TRANSFER_READ, - x, y, - w, h); - if(transfer) { - pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba); - for(j = 0; j < h; ++j) { - for(i = 0; i < w; ++i) - for(k = 0; k <4; ++k) - rgba8[j*w*4 + i*4 + k] = float_to_ubyte(rgba[j*w*4 + i*4 + k]); - } - pipe->tex_transfer_destroy(pipe, transfer); - } - - free(rgba); - } - - void get_tile_z(struct st_context *ctx, unsigned x, unsigned y, unsigned w, unsigned h, unsigned *z) - { - struct pipe_context *pipe = ctx->pipe; - struct pipe_transfer *transfer; - transfer = pipe->get_tex_transfer(pipe, - $self->texture, - $self->face, - $self->level, - $self->zslice, - PIPE_TRANSFER_READ, - x, y, w, h); - if(transfer) { - pipe_get_tile_z(pipe, transfer, 0, 0, w, h, z); - pipe->tex_transfer_destroy(pipe, transfer); - } - } - - void put_tile_z(struct st_context *ctx, unsigned x, unsigned y, unsigned w, unsigned h, const unsigned *z) - { - struct pipe_context *pipe = ctx->pipe; - struct pipe_transfer *transfer; - transfer = pipe->get_tex_transfer(pipe, - $self->texture, - $self->face, - $self->level, - $self->zslice, - PIPE_TRANSFER_WRITE, - x, y, w, h); - if(transfer) { - pipe_put_tile_z(pipe, transfer, 0, 0, w, h, z); - pipe->tex_transfer_destroy(pipe, transfer); - } - } - -/* - void - sample_rgba(float *rgba) { - st_sample_surface($self, rgba); - } -*/ - - unsigned compare_tile_rgba(struct st_context *ctx, unsigned x, unsigned y, unsigned w, unsigned h, const float *rgba, float tol = 0.0) - { - struct pipe_context *pipe = ctx->pipe; - struct pipe_transfer *transfer; - float *rgba2; - const float *p1; - const float *p2; - unsigned i, j, n; - - rgba2 = MALLOC(h*w*4*sizeof(float)); - if(!rgba2) - return ~0; - - transfer = pipe->get_tex_transfer(pipe, - $self->texture, - $self->face, - $self->level, - $self->zslice, - PIPE_TRANSFER_READ, - x, y, w, h); - if(!transfer) { - FREE(rgba2); - return ~0; - } - - pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba2); - pipe->tex_transfer_destroy(pipe, transfer); - - p1 = rgba; - p2 = rgba2; - n = 0; - for(i = h*w; i; --i) { - unsigned differs = 0; - for(j = 4; j; --j) { - float delta = *p2++ - *p1++; - if (delta < -tol || delta > tol) - differs = 1; - } - n += differs; - } - - FREE(rgba2); - - return n; - } }; diff --git a/src/gallium/state_trackers/python/st_sample.c b/src/gallium/state_trackers/python/st_sample.c index f9622533fbc..e2c1e060174 100644 --- a/src/gallium/state_trackers/python/st_sample.c +++ b/src/gallium/state_trackers/python/st_sample.c @@ -521,12 +521,13 @@ st_sample_pixel_block(enum pipe_format format, } } -#if 0 + void -st_sample_surface(struct st_surface *surface, float *rgba) +st_sample_surface(struct pipe_context *pipe, + struct st_surface *surface, + float *rgba) { struct pipe_texture *texture = surface->texture; - struct pipe_screen *screen = texture->screen; unsigned width = u_minify(texture->width0, surface->level); unsigned height = u_minify(texture->height0, surface->level); uint rgba_stride = width * 4; @@ -534,18 +535,18 @@ st_sample_surface(struct st_surface *surface, float *rgba) void *raw; transfer = pipe->get_tex_transfer(pipe, - surface->texture, - surface->face, - surface->level, - surface->zslice, - PIPE_TRANSFER_WRITE, - 0, 0, - width, - height); + surface->texture, + surface->face, + surface->level, + surface->zslice, + PIPE_TRANSFER_WRITE, + 0, 0, + width, + height); if (!transfer) return; - raw = screen->transfer_map(screen, transfer); + raw = pipe->transfer_map(pipe, transfer); if (raw) { enum pipe_format format = texture->format; uint x, y; @@ -567,9 +568,8 @@ st_sample_surface(struct st_surface *surface, float *rgba) } } - screen->transfer_unmap(screen, transfer); + pipe->transfer_unmap(pipe, transfer); } - screen->tex_transfer_destroy(transfer); + pipe->tex_transfer_destroy(pipe, transfer); } -#endif diff --git a/src/gallium/state_trackers/python/st_sample.h b/src/gallium/state_trackers/python/st_sample.h index 888114d3021..6fb8417add8 100644 --- a/src/gallium/state_trackers/python/st_sample.h +++ b/src/gallium/state_trackers/python/st_sample.h @@ -32,6 +32,9 @@ #include "pipe/p_format.h" +struct pipe_context; +struct st_surface; + void st_sample_pixel_block(enum pipe_format format, @@ -40,7 +43,9 @@ st_sample_pixel_block(enum pipe_format format, unsigned w, unsigned h); void -st_sample_surface(struct st_surface *surface, float *rgba); +st_sample_surface(struct pipe_context *pipe, + struct st_surface *surface, + float *rgba); #endif /* ST_SAMPLE_H_ */ -- cgit v1.2.3 From d0e7aa25a9258aaf0bf9b22c1e75eda1515a69f7 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Mon, 29 Mar 2010 21:09:37 +0100 Subject: st/python: Update for util_draw_vertex_buffer changes. --- src/gallium/state_trackers/python/p_context.i | 38 ++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/python/p_context.i b/src/gallium/state_trackers/python/p_context.i index a8e164a072b..bccaeead015 100644 --- a/src/gallium/state_trackers/python/p_context.i +++ b/src/gallium/state_trackers/python/p_context.i @@ -280,8 +280,11 @@ struct st_context { struct pipe_context *pipe = $self->pipe; struct pipe_screen *screen = pipe->screen; struct pipe_buffer *vbuf; + struct pipe_vertex_element velements[PIPE_MAX_ATTRIBS]; + struct pipe_vertex_buffer vbuffer; float *map; unsigned size; + unsigned i; size = num_verts * num_attribs * 4 * sizeof(float); @@ -297,15 +300,44 @@ struct st_context { goto error2; memcpy(map, vertices, size); pipe_buffer_unmap(screen, vbuf); - - util_draw_vertex_buffer(pipe, vbuf, 0, prim, num_verts, num_attribs); - + + cso_save_vertex_elements($self->cso); + + /* tell pipe about the vertex attributes */ + for (i = 0; i < num_attribs; i++) { + velements[i].src_offset = i * 4 * sizeof(float); + velements[i].instance_divisor = 0; + velements[i].vertex_buffer_index = 0; + velements[i].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + } + cso_set_vertex_elements($self->cso, num_attribs, velements); + + /* tell pipe about the vertex buffer */ + memset(&vbuffer, 0, sizeof(vbuffer)); + vbuffer.buffer = vbuf; + vbuffer.stride = num_attribs * 4 * sizeof(float); /* vertex size */ + vbuffer.buffer_offset = 0; + vbuffer.max_index = num_verts - 1; + pipe->set_vertex_buffers(pipe, 1, &vbuffer); + + /* draw */ + pipe->draw_arrays(pipe, prim, 0, num_verts); + + cso_restore_vertex_elements($self->cso); + error2: pipe_buffer_reference(&vbuf, NULL); error1: ; } + void + clear(unsigned buffers, const float *rgba, double depth = 0.0f, + unsigned stencil = 0) + { + $self->pipe->clear($self->pipe, buffers, rgba, depth, stencil); + } + void flush(unsigned flags = 0) { struct pipe_fence_handle *fence = NULL; -- cgit v1.2.3 From 3b1a8d9d5ba286da568b4176ed533a7dde60ad18 Mon Sep 17 00:00:00 2001 From: Chris Li Date: Fri, 26 Mar 2010 10:23:03 -0700 Subject: gallivm: added lp_bld_printf() function --- src/gallium/auxiliary/Makefile | 1 + src/gallium/auxiliary/SConscript | 1 + src/gallium/auxiliary/gallivm/lp_bld_printf.c | 109 ++++++++++++++++++++++++++ src/gallium/auxiliary/gallivm/lp_bld_printf.h | 39 +++++++++ 4 files changed, 150 insertions(+) create mode 100644 src/gallium/auxiliary/gallivm/lp_bld_printf.c create mode 100644 src/gallium/auxiliary/gallivm/lp_bld_printf.h (limited to 'src/gallium') diff --git a/src/gallium/auxiliary/Makefile b/src/gallium/auxiliary/Makefile index e1c3bc43a24..452eceb7f4f 100644 --- a/src/gallium/auxiliary/Makefile +++ b/src/gallium/auxiliary/Makefile @@ -155,6 +155,7 @@ GALLIVM_SOURCES = \ gallivm/lp_bld_intr.c \ gallivm/lp_bld_logic.c \ gallivm/lp_bld_pack.c \ + gallivm/lp_bld_printf.c \ gallivm/lp_bld_sample.c \ gallivm/lp_bld_sample_soa.c \ gallivm/lp_bld_struct.c \ diff --git a/src/gallium/auxiliary/SConscript b/src/gallium/auxiliary/SConscript index 65e1dc8a58d..0a23da47b2a 100644 --- a/src/gallium/auxiliary/SConscript +++ b/src/gallium/auxiliary/SConscript @@ -200,6 +200,7 @@ if drawllvm: 'gallivm/lp_bld_logic.c', 'gallivm/lp_bld_init.cpp', 'gallivm/lp_bld_pack.c', + 'gallivm/lp_bld_printf.c', 'gallivm/lp_bld_sample.c', 'gallivm/lp_bld_sample_soa.c', 'gallivm/lp_bld_struct.c', diff --git a/src/gallium/auxiliary/gallivm/lp_bld_printf.c b/src/gallium/auxiliary/gallivm/lp_bld_printf.c new file mode 100644 index 00000000000..ae4d400af39 --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_printf.c @@ -0,0 +1,109 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#include + +#include "lp_bld_printf.h" + + +static int +lp_get_printf_arg_count(const char *fmt) +{ + int count =0; + const char *p = fmt; + int c; + + while ((c = *p++)) { + if (c != '%') + continue; + switch (*p) { + case '\0': + continue; + case '%': + p++; + continue; + case '.': + if (p[1] == '*' && p[2] == 's') { + count += 2; + p += 3; + continue; + } + default: + count ++; + } + } + return count; +} + +LLVMValueRef +lp_build_const_string_variable(LLVMModuleRef module, const char *str, int len) +{ + LLVMValueRef string = LLVMAddGlobal(module, LLVMArrayType(LLVMInt8Type(), len + 1), ""); + LLVMSetGlobalConstant(string, TRUE); + LLVMSetLinkage(string, LLVMInternalLinkage); + LLVMSetInitializer(string, LLVMConstString(str, len + 1, TRUE)); + return string; +} + + +/** + * lp_build_printf. + * + * Build printf call in LLVM IR. The output goes to stdout. + * The additional variable arguments need to have type + * LLVMValueRef. + */ +LLVMValueRef +lp_build_printf(LLVMBuilderRef builder, const char *fmt, ...) +{ + va_list arglist; + int i = 0; + int argcount = lp_get_printf_arg_count(fmt); + LLVMModuleRef module = LLVMGetGlobalParent(LLVMGetBasicBlockParent(LLVMGetInsertBlock(builder))); + LLVMValueRef params[argcount + 1]; + LLVMValueRef fmtarg = lp_build_const_string_variable(module, fmt, strlen(fmt) + 1); + LLVMValueRef int0 = LLVMConstInt(LLVMInt32Type(), 0, 0); + LLVMValueRef index[2]; + LLVMValueRef func_printf = LLVMGetNamedFunction(module, "printf"); + + index[0] = index[1] = int0; + + if (!func_printf) { + LLVMTypeRef printf_type = LLVMFunctionType(LLVMIntType(32), NULL, 0, 1); + func_printf = LLVMAddFunction(module, "printf", printf_type); + } + + params[0] = LLVMBuildGEP(builder, fmtarg, index, 2, ""); + + va_start(arglist, fmt); + for (i = 1; i <= argcount; i++) + params[i] = va_arg(arglist, LLVMValueRef); + va_end(arglist); + + return LLVMBuildCall(builder, func_printf, params, argcount + 1, ""); +} + diff --git a/src/gallium/auxiliary/gallivm/lp_bld_printf.h b/src/gallium/auxiliary/gallivm/lp_bld_printf.h new file mode 100644 index 00000000000..83bd8f1d557 --- /dev/null +++ b/src/gallium/auxiliary/gallivm/lp_bld_printf.h @@ -0,0 +1,39 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef LP_BLD_PRINTF_H +#define LP_BLD_PRINTF_H + + +#include "pipe/p_compiler.h" +#include "lp_bld.h" + +LLVMValueRef lp_build_const_string_variable(LLVMModuleRef module, const char *str, int len); +LLVMValueRef lp_build_printf(LLVMBuilderRef builder, const char *fmt, ...); + +#endif + -- cgit v1.2.3 From 5fa09846618ed702493f054a1d4b0ec2a28fbbd0 Mon Sep 17 00:00:00 2001 From: Chris Li Date: Fri, 26 Mar 2010 10:24:34 -0700 Subject: Add test case for lp_bld_printf() --- src/gallium/drivers/llvmpipe/Makefile | 3 +- src/gallium/drivers/llvmpipe/lp_test_printf.c | 162 ++++++++++++++++++++++++++ 2 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 src/gallium/drivers/llvmpipe/lp_test_printf.c (limited to 'src/gallium') diff --git a/src/gallium/drivers/llvmpipe/Makefile b/src/gallium/drivers/llvmpipe/Makefile index 74d728ddb39..b37c6754c08 100644 --- a/src/gallium/drivers/llvmpipe/Makefile +++ b/src/gallium/drivers/llvmpipe/Makefile @@ -44,7 +44,8 @@ CPP_SOURCES = \ PROGS := lp_test_format \ lp_test_blend \ - lp_test_conv + lp_test_conv \ + lp_test_printf include ../../Makefile.template diff --git a/src/gallium/drivers/llvmpipe/lp_test_printf.c b/src/gallium/drivers/llvmpipe/lp_test_printf.c new file mode 100644 index 00000000000..e5e5925012a --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_test_printf.c @@ -0,0 +1,162 @@ +/************************************************************************** + * + * Copyright 2010 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + + +#include +#include + +#include "gallivm/lp_bld.h" +#include "gallivm/lp_bld_printf.h" + +#include +#include +#include +#include + +#include "lp_test.h" + + +struct printf_test_case { +}; + +void +write_tsv_header(FILE *fp) +{ + fprintf(fp, + "result\t" + "format\n"); + + fflush(fp); +} + + + +typedef void (*test_printf_t)(int i); + +static LLVMValueRef +add_printf_test(LLVMModuleRef module) +{ + LLVMTypeRef args[1] = { LLVMIntType(32) }; + LLVMValueRef func = LLVMAddFunction(module, "test_printf", LLVMFunctionType(LLVMVoidType(), args, 1, 0)); + LLVMBuilderRef builder = LLVMCreateBuilder(); + LLVMBasicBlockRef block = LLVMAppendBasicBlock(func, "entry"); + + LLVMSetFunctionCallConv(func, LLVMCCallConv); + + LLVMPositionBuilderAtEnd(builder, block); + lp_build_printf(builder, "hello, world\n"); + lp_build_printf(builder, "print 5 6: %d %d\n", LLVMConstInt(LLVMInt32Type(), 5, 0), + LLVMConstInt(LLVMInt32Type(), 6, 0)); + LLVMBuildRetVoid(builder); + LLVMDisposeBuilder(builder); + return func; +} + + +PIPE_ALIGN_STACK +static boolean +test_printf(unsigned verbose, FILE *fp, const struct printf_test_case *testcase) +{ + LLVMModuleRef module = NULL; + LLVMValueRef test = NULL; + LLVMExecutionEngineRef engine = NULL; + LLVMModuleProviderRef provider = NULL; + LLVMPassManagerRef pass = NULL; + char *error = NULL; + test_printf_t test_printf; + float unpacked[4]; + unsigned packed; + boolean success = TRUE; + + module = LLVMModuleCreateWithName("test"); + + test = add_printf_test(module); + + if(LLVMVerifyModule(module, LLVMPrintMessageAction, &error)) { + LLVMDumpModule(module); + abort(); + } + LLVMDisposeMessage(error); + + provider = LLVMCreateModuleProviderForExistingModule(module); + if (LLVMCreateJITCompiler(&engine, provider, 1, &error)) { + fprintf(stderr, "%s\n", error); + LLVMDisposeMessage(error); + abort(); + } + +#if 0 + pass = LLVMCreatePassManager(); + LLVMAddTargetData(LLVMGetExecutionEngineTargetData(engine), pass); + /* These are the passes currently listed in llvm-c/Transforms/Scalar.h, + * but there are more on SVN. */ + LLVMAddConstantPropagationPass(pass); + LLVMAddInstructionCombiningPass(pass); + LLVMAddPromoteMemoryToRegisterPass(pass); + LLVMAddGVNPass(pass); + LLVMAddCFGSimplificationPass(pass); + LLVMRunPassManager(pass, module); +#else + (void)pass; +#endif + + test_printf = (test_printf_t)LLVMGetPointerToGlobal(engine, test); + + memset(unpacked, 0, sizeof unpacked); + packed = 0; + + + // LLVMDumpModule(module); + + test_printf(0); + + LLVMFreeMachineCodeForFunction(engine, test); + + LLVMDisposeExecutionEngine(engine); + if(pass) + LLVMDisposePassManager(pass); + + return success; +} + + +boolean +test_all(unsigned verbose, FILE *fp) +{ + bool success = TRUE; + + test_printf(verbose, fp, NULL); + + return success; +} + + +boolean +test_some(unsigned verbose, FILE *fp, unsigned long n) +{ + return test_all(verbose, fp); +} -- cgit v1.2.3 From 8c6f71e01e40075156c8b83f2c5e15ab73e66036 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 29 Mar 2010 18:13:31 -0600 Subject: gallivm: use constant size array, added assertion check --- src/gallium/auxiliary/gallivm/lp_bld_printf.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/gallium') diff --git a/src/gallium/auxiliary/gallivm/lp_bld_printf.c b/src/gallium/auxiliary/gallivm/lp_bld_printf.c index ae4d400af39..78c9ec778b6 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_printf.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_printf.c @@ -27,6 +27,8 @@ #include +#include "util/u_debug.h" +#include "util/u_memory.h" #include "lp_bld_printf.h" @@ -84,12 +86,14 @@ lp_build_printf(LLVMBuilderRef builder, const char *fmt, ...) int i = 0; int argcount = lp_get_printf_arg_count(fmt); LLVMModuleRef module = LLVMGetGlobalParent(LLVMGetBasicBlockParent(LLVMGetInsertBlock(builder))); - LLVMValueRef params[argcount + 1]; + LLVMValueRef params[50]; LLVMValueRef fmtarg = lp_build_const_string_variable(module, fmt, strlen(fmt) + 1); LLVMValueRef int0 = LLVMConstInt(LLVMInt32Type(), 0, 0); LLVMValueRef index[2]; LLVMValueRef func_printf = LLVMGetNamedFunction(module, "printf"); + assert(Elements(params) >= argcount + 1); + index[0] = index[1] = int0; if (!func_printf) { -- cgit v1.2.3 From c1a392ac4c6a7da4026653de556c2c7698f86860 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Tue, 30 Mar 2010 09:17:20 +0800 Subject: st/glx: Remove a wrong assertion in choose_pixel_format. There are X visuals that Gallium or the code does not support. We could not assert the color format to be supported. Return PIPE_FORMAT_NONE in such cases and let the caller handle it. --- src/gallium/state_trackers/glx/xlib/glx_api.c | 4 ++++ src/gallium/state_trackers/glx/xlib/xm_api.c | 9 +++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/glx/xlib/glx_api.c b/src/gallium/state_trackers/glx/xlib/glx_api.c index 4930cd6cd50..eb8d6a19333 100644 --- a/src/gallium/state_trackers/glx/xlib/glx_api.c +++ b/src/gallium/state_trackers/glx/xlib/glx_api.c @@ -1758,6 +1758,10 @@ glXGetFBConfigs( Display *dpy, int screen, int *nelements ) } for (i = 0; i < *nelements; i++) { results[i] = create_glx_visual(dpy, visuals + i); + if (!results[i]) { + *nelements = i; + break; + } } return (GLXFBConfig *) results; } diff --git a/src/gallium/state_trackers/glx/xlib/xm_api.c b/src/gallium/state_trackers/glx/xlib/xm_api.c index 3022d45157a..fd03d3c46a4 100644 --- a/src/gallium/state_trackers/glx/xlib/xm_api.c +++ b/src/gallium/state_trackers/glx/xlib/xm_api.c @@ -327,8 +327,7 @@ choose_pixel_format(XMesaVisual v) return PIPE_FORMAT_B5G6R5_UNORM; } - assert(0); - return 0; + return PIPE_FORMAT_NONE; } @@ -737,6 +736,12 @@ XMesaVisual XMesaCreateVisual( Display *display, } v->stvis.color_format = choose_pixel_format(v); + if (v->stvis.color_format == PIPE_FORMAT_NONE) { + FREE(v->visinfo); + FREE(v); + return NULL; + } + v->stvis.depth_stencil_format = choose_depth_stencil_format(xmdpy, depth_size, stencil_size); -- cgit v1.2.3 From 587c5ef01fad962bcfb087232d0925a8eec86953 Mon Sep 17 00:00:00 2001 From: Corbin Simpson Date: Mon, 29 Mar 2010 15:10:18 -0700 Subject: r300g: Bind constantbuf to Draw immediately, don't wait for render. Doesn't hurt, and reduces code duplication. --- src/gallium/drivers/r300/r300_render.c | 14 -------------- src/gallium/drivers/r300/r300_state.c | 8 ++++++-- 2 files changed, 6 insertions(+), 16 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/r300/r300_render.c b/src/gallium/drivers/r300/r300_render.c index 93bf388776c..1fb7eac2b34 100644 --- a/src/gallium/drivers/r300/r300_render.c +++ b/src/gallium/drivers/r300/r300_render.c @@ -569,13 +569,6 @@ void r300_swtcl_draw_arrays(struct pipe_context* pipe, draw_set_mapped_element_buffer(r300->draw, 0, NULL); - draw_set_mapped_constant_buffer(r300->draw, - PIPE_SHADER_VERTEX, - 0, - r300->shader_constants[PIPE_SHADER_VERTEX].constants, - r300->shader_constants[PIPE_SHADER_VERTEX].count * - (sizeof(float) * 4)); - draw_arrays(r300->draw, mode, start, count); for (i = 0; i < r300->vertex_buffer_count; i++) { @@ -614,13 +607,6 @@ void r300_swtcl_draw_range_elements(struct pipe_context* pipe, draw_set_mapped_element_buffer_range(r300->draw, indexSize, minIndex, maxIndex, indices); - draw_set_mapped_constant_buffer(r300->draw, - PIPE_SHADER_VERTEX, - 0, - r300->shader_constants[PIPE_SHADER_VERTEX].constants, - r300->shader_constants[PIPE_SHADER_VERTEX].count * - (sizeof(float) * 4)); - draw_arrays(r300->draw, mode, start, count); for (i = 0; i < r300->vertex_buffer_count; i++) { diff --git a/src/gallium/drivers/r300/r300_state.c b/src/gallium/drivers/r300/r300_state.c index b7b5e1ef03b..ace71d657ef 100644 --- a/src/gallium/drivers/r300/r300_state.c +++ b/src/gallium/drivers/r300/r300_state.c @@ -1365,10 +1365,14 @@ static void r300_set_constant_buffer(struct pipe_context *pipe, if (r300screen->caps->has_tcl) { r300->dirty_state |= R300_NEW_VERTEX_SHADER_CONSTANTS; r300->pvs_flush.dirty = TRUE; + } else if (r300->draw) { + draw_set_mapped_constant_buffer(r300->draw, PIPE_SHADER_VERTEX, + 0, r300->shader_constants[PIPE_SHADER_VERTEX].constants, + buf->size); } - } - else if (shader == PIPE_SHADER_FRAGMENT) + } else if (shader == PIPE_SHADER_FRAGMENT) { r300->dirty_state |= R300_NEW_FRAGMENT_SHADER_CONSTANTS; + } } void r300_init_state_functions(struct r300_context* r300) -- cgit v1.2.3 From 9dc51ad4f7bb9bbaba247da90dc50f2098dd5e64 Mon Sep 17 00:00:00 2001 From: Vinson Lee Date: Mon, 29 Mar 2010 22:11:37 -0700 Subject: r300g: Remove unnecessary header. --- src/gallium/drivers/r300/r300_tgsi_to_rc.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/r300/r300_tgsi_to_rc.c b/src/gallium/drivers/r300/r300_tgsi_to_rc.c index 3f88a2b82b9..3b3802ee2b2 100644 --- a/src/gallium/drivers/r300/r300_tgsi_to_rc.c +++ b/src/gallium/drivers/r300/r300_tgsi_to_rc.c @@ -30,8 +30,6 @@ #include "tgsi/tgsi_scan.h" #include "tgsi/tgsi_util.h" -#include "util/u_debug.h" - static unsigned translate_opcode(unsigned opcode) { switch(opcode) { -- cgit v1.2.3 From ba43b74967d91d592f085943b60c522b88916495 Mon Sep 17 00:00:00 2001 From: Vinson Lee Date: Mon, 29 Mar 2010 22:19:28 -0700 Subject: r300g: Remove unused variable. --- src/gallium/drivers/r300/r300_state.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/gallium') diff --git a/src/gallium/drivers/r300/r300_state.c b/src/gallium/drivers/r300/r300_state.c index ace71d657ef..39e05583dd4 100644 --- a/src/gallium/drivers/r300/r300_state.c +++ b/src/gallium/drivers/r300/r300_state.c @@ -1183,7 +1183,6 @@ static void* r300_create_vertex_elements_state(struct pipe_context* pipe, unsigned count, const struct pipe_vertex_element* attribs) { - struct r300_context *r300 = r300_context(pipe); struct r300_screen* r300screen = r300_screen(pipe->screen); struct r300_vertex_element_state *velems; unsigned i, size; -- cgit v1.2.3 From f2c55566ee271f34a42587f9def105c99ec06faf Mon Sep 17 00:00:00 2001 From: Vinson Lee Date: Mon, 29 Mar 2010 22:54:35 -0700 Subject: swrastg: Silence unused value warning. --- src/gallium/targets/dri-swrast/swrast_drm_api.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/targets/dri-swrast/swrast_drm_api.c b/src/gallium/targets/dri-swrast/swrast_drm_api.c index 63b935bb07b..99c25543a76 100644 --- a/src/gallium/targets/dri-swrast/swrast_drm_api.c +++ b/src/gallium/targets/dri-swrast/swrast_drm_api.c @@ -68,16 +68,16 @@ swrast_create_screen(struct sw_winsys *winsys) #if defined(GALLIUM_CELL) if (screen == NULL && strcmp(driver, "cell") == 0) screen = cell_create_screen( winsys ); -#endif - -#if defined(GALLIUM_LLVMPIPE) +#elif defined(GALLIUM_LLVMPIPE) if (screen == NULL && strcmp(driver, "llvmpipe") == 0) screen = llvmpipe_create_screen( winsys ); -#endif - -#if defined(GALLIUM_SOFTPIPE) +#elif defined(GALLIUM_SOFTPIPE) if (screen == NULL) screen = softpipe_create_screen( winsys ); + + (void) driver; +#else + (void) driver; #endif return screen; -- cgit v1.2.3 From 49289007c1fb7609a1c37aeb2daeeb96a47b8438 Mon Sep 17 00:00:00 2001 From: Vinson Lee Date: Mon, 29 Mar 2010 23:11:26 -0700 Subject: drisw: Remove unnecessary header. --- src/gallium/state_trackers/dri/sw/drisw.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/dri/sw/drisw.c b/src/gallium/state_trackers/dri/sw/drisw.c index b8256710972..42fa789aaf7 100644 --- a/src/gallium/state_trackers/dri/sw/drisw.c +++ b/src/gallium/state_trackers/dri/sw/drisw.c @@ -43,7 +43,6 @@ #include "dri_screen.h" #include "dri_context.h" #include "dri_drawable.h" -#include "dri_st_api.h" #include "dri1_helper.h" #include "drisw.h" -- cgit v1.2.3 From aa1a79036003c2aeaae24877da66e9b46a059cad Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Tue, 30 Mar 2010 15:41:31 +0800 Subject: st/dri: Fix a memory leak in dri1_init_screen. Free the returned configs upon errors. --- src/gallium/state_trackers/dri/drm/dri1.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/gallium') diff --git a/src/gallium/state_trackers/dri/drm/dri1.c b/src/gallium/state_trackers/dri/drm/dri1.c index 9b5842ba2bf..cca7cd8f0c3 100644 --- a/src/gallium/state_trackers/dri/drm/dri1.c +++ b/src/gallium/state_trackers/dri/drm/dri1.c @@ -514,6 +514,8 @@ dri1_init_screen(__DRIscreen * sPriv) return configs; fail: + if (configs) + FREE(configs); dri_destroy_screen_helper(screen); FREE(screen); return NULL; -- cgit v1.2.3 From dc886ba1391d7d890bd1f5532bc14553e883a418 Mon Sep 17 00:00:00 2001 From: Zack Rusin Date: Tue, 30 Mar 2010 08:55:17 -0400 Subject: gallivm: cleanup the code (found by coverity) the condition can't be false, declerations are ok even if we don't emit any. --- src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c index 95cd6a0ecf3..8901e656aed 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c @@ -666,30 +666,20 @@ emit_declaration( first_inst); for (idx = first; idx <= last; ++idx) { - boolean ok; - switch (decl->Declaration.File) { case TGSI_FILE_TEMPORARY: for (i = 0; i < NUM_CHANNELS; i++) bld->temps[idx][i] = lp_build_alloca(&bld->base); - ok = TRUE; break; case TGSI_FILE_OUTPUT: for (i = 0; i < NUM_CHANNELS; i++) bld->outputs[idx][i] = lp_build_alloca(&bld->base); - ok = TRUE; break; default: /* don't need to declare other vars */ - ok = TRUE; - } - - if (!ok) { - LLVMPositionBuilderAtEnd(bld->base.builder, - current_block); - return FALSE; + break; } } -- cgit v1.2.3