From 5c68b7961ab0e1914cdec24e4483a50b2a0abdbd Mon Sep 17 00:00:00 2001 From: Tom Stellard Date: Sat, 23 Apr 2011 21:27:34 -0700 Subject: [PATCH] r300/compiler: Limit instructions to 3 source selects Some presubtract conversions where generating more than 3 source selects. https://bugs.freedesktop.org/show_bug.cgi?id=36527 --- .../dri/r300/compiler/radeon_compiler_util.c | 95 +++++++++++++++----- 1 files changed, 73 insertions(+), 22 deletions(-) diff --git a/src/mesa/drivers/dri/r300/compiler/radeon_compiler_util.c b/src/mesa/drivers/dri/r300/compiler/radeon_compiler_util.c index 15ec441..97ace55 100644 --- a/src/mesa/drivers/dri/r300/compiler/radeon_compiler_util.c +++ b/src/mesa/drivers/dri/r300/compiler/radeon_compiler_util.c @@ -200,12 +200,35 @@ unsigned int rc_source_type_mask(unsigned int mask) return ret; } +struct src_select { + rc_register_file File; + int Index; + unsigned int SrcType; +}; + struct can_use_presub_data { - struct rc_src_register RemoveSrcs[3]; - unsigned int RGBCount; - unsigned int AlphaCount; + struct src_select Selects[5]; + unsigned int SelectCount; }; +static void can_use_presub_data_add_select( + struct can_use_presub_data * data, + rc_register_file file, + unsigned int index, + unsigned int src_type) +{ + struct src_select * select; + + select = &data->Selects[data->SelectCount++]; + select->File = file; + select->Index = index; + select->SrcType = src_type; +} + +/** + * This callback function counts the number of sources in inst that are + * different from the sources in can_use_presub_data->RemoveSrcs. + */ static void can_use_presub_read_cb( void * userdata, struct rc_instruction * inst, @@ -214,25 +237,12 @@ static void can_use_presub_read_cb( unsigned int mask) { struct can_use_presub_data * d = userdata; - unsigned int src_type = rc_source_type_mask(mask); - unsigned int i; if (file == RC_FILE_NONE) return; - for(i = 0; i < 3; i++) { - if (d->RemoveSrcs[i].File == file - && d->RemoveSrcs[i].Index == index) { - src_type &= - ~rc_source_type_swz(d->RemoveSrcs[i].Swizzle); - } - } - - if (src_type & RC_SOURCE_RGB) - d->RGBCount++; - - if (src_type & RC_SOURCE_ALPHA) - d->AlphaCount++; + can_use_presub_data_add_select(d, file, index, + rc_source_type_mask(mask)); } unsigned int rc_inst_can_use_presub( @@ -245,8 +255,10 @@ unsigned int rc_inst_can_use_presub( { struct can_use_presub_data d; unsigned int num_presub_srcs; + unsigned int i; const struct rc_opcode_info * info = rc_get_opcode_info(inst->U.I.Opcode); + int rgb_count = 0, alpha_count = 0; if (presub_op == RC_PRESUB_NONE) { return 1; @@ -266,15 +278,54 @@ unsigned int rc_inst_can_use_presub( } memset(&d, 0, sizeof(d)); - d.RemoveSrcs[0] = replace_reg; - d.RemoveSrcs[1] = presub_src0; - d.RemoveSrcs[2] = presub_src1; rc_for_all_reads_mask(inst, can_use_presub_read_cb, &d); num_presub_srcs = rc_presubtract_src_reg_count(presub_op); - if (d.RGBCount + num_presub_srcs > 3 || d.AlphaCount + num_presub_srcs > 3) { + can_use_presub_data_add_select(&d, + presub_src0.File, + presub_src0.Index, + rc_source_type_swz(presub_src0.Swizzle)); + + if (num_presub_srcs > 1) { + can_use_presub_data_add_select(&d, + presub_src1.File, + presub_src1.Index, + rc_source_type_swz(presub_src1.Swizzle)); + } + + /* One of the source selects will be replaced by the presub source, + * so we start the count at -1 to compensate for this. */ + if (rc_source_type_swz(replace_reg.Swizzle) & RC_SOURCE_RGB) { + rgb_count = -1; + } + + if (rc_source_type_swz(replace_reg.Swizzle) & RC_SOURCE_ALPHA) { + alpha_count = -1; + } + + /* Count the number of source selects for Alpha and RGB. If we + * encouter two source selects then we can ignore the first one. */ + for (i = 0; i < d.SelectCount; i++) { + unsigned int j; + unsigned int src_type = d.Selects[i].SrcType; + for (j = i + 1; j < d.SelectCount; j++) { + if (d.Selects[i].File == d.Selects[j].File + && d.Selects[i].Index == d.Selects[j].Index) { + src_type &= ~d.Selects[j].SrcType; + } + } + if (src_type & RC_SOURCE_RGB) { + rgb_count++; + } + + if (src_type & RC_SOURCE_ALPHA) { + alpha_count++; + } + } + + if (rgb_count > 3 || alpha_count > 3) { return 0; } -- 1.7.3.4