From 6581203fb618daec26c8c9e7c2958a4c0148f4ad Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Fri, 17 Dec 2010 18:41:46 +1000 Subject: [PATCH] gallium/r300g: fix frag color writing attempt 2 this uses a tgsi property. --- src/gallium/auxiliary/tgsi/tgsi_text.c | 3 + src/gallium/auxiliary/tgsi/tgsi_ureg.c | 16 +++++++- src/gallium/auxiliary/tgsi/tgsi_ureg.h | 4 ++ src/gallium/drivers/r300/r300_fs.c | 42 ++++++++++++++++--- src/gallium/drivers/r300/r300_tgsi_to_rc.c | 30 +++++++------- src/gallium/include/pipe/p_shader_tokens.h | 3 +- src/mesa/drivers/dri/r300/compiler/r3xx_fragprog.c | 1 + src/mesa/drivers/dri/r300/compiler/radeon_code.h | 1 + src/mesa/state_tracker/st_program.c | 5 ++ 9 files changed, 82 insertions(+), 23 deletions(-) diff --git a/src/gallium/auxiliary/tgsi/tgsi_text.c b/src/gallium/auxiliary/tgsi/tgsi_text.c index 9a38c37..cdf94fe 100644 --- a/src/gallium/auxiliary/tgsi/tgsi_text.c +++ b/src/gallium/auxiliary/tgsi/tgsi_text.c @@ -1265,6 +1265,7 @@ static const char *property_names[] = "GS_MAX_OUTPUT_VERTICES", "FS_COORD_ORIGIN", "FS_COORD_PIXEL_CENTER" + "FS_WRITE_ALL" }; static const char *primitive_names[] = @@ -1398,6 +1399,8 @@ static boolean parse_property( struct translate_ctx *ctx ) return FALSE; } break; + case TGSI_PROPERTY_FS_WRITE_ALL: + break; default: if (!parse_uint(&ctx->cur, &values[0] )) { report_error( ctx, "Expected unsigned integer as property!" ); diff --git a/src/gallium/auxiliary/tgsi/tgsi_ureg.c b/src/gallium/auxiliary/tgsi/tgsi_ureg.c index 7d13a17..be4567d 100644 --- a/src/gallium/auxiliary/tgsi/tgsi_ureg.c +++ b/src/gallium/auxiliary/tgsi/tgsi_ureg.c @@ -148,6 +148,7 @@ struct ureg_program unsigned property_gs_max_vertices; unsigned char property_fs_coord_origin; /* = TGSI_FS_COORD_ORIGIN_* */ unsigned char property_fs_coord_pixel_center; /* = TGSI_FS_COORD_PIXEL_CENTER_* */ + unsigned char property_fs_write_all; /* = TGSI_FS_WRITE_ALL * */ unsigned nr_addrs; unsigned nr_preds; @@ -284,7 +285,12 @@ ureg_property_fs_coord_pixel_center(struct ureg_program *ureg, ureg->property_fs_coord_pixel_center = fs_coord_pixel_center; } - +void +ureg_property_fs_write_all(struct ureg_program *ureg, + unsigned fs_write_all) +{ + ureg->property_fs_write_all = fs_write_all; +} struct ureg_src ureg_DECL_fs_input_cyl_centroid(struct ureg_program *ureg, @@ -1278,6 +1284,14 @@ static void emit_decls( struct ureg_program *ureg ) ureg->property_fs_coord_pixel_center); } + if (ureg->property_fs_write_all) { + assert(ureg->processor == TGSI_PROCESSOR_FRAGMENT); + + emit_property(ureg, + TGSI_PROPERTY_FS_WRITE_ALL, + ureg->property_fs_write_all); + } + if (ureg->processor == TGSI_PROCESSOR_VERTEX) { for (i = 0; i < UREG_MAX_INPUT; i++) { if (ureg->vs_inputs[i/32] & (1 << (i%32))) { diff --git a/src/gallium/auxiliary/tgsi/tgsi_ureg.h b/src/gallium/auxiliary/tgsi/tgsi_ureg.h index acc4632..8259b60 100644 --- a/src/gallium/auxiliary/tgsi/tgsi_ureg.h +++ b/src/gallium/auxiliary/tgsi/tgsi_ureg.h @@ -153,6 +153,10 @@ void ureg_property_fs_coord_pixel_center(struct ureg_program *ureg, unsigned fs_coord_pixel_center); +void +ureg_property_fs_write_all(struct ureg_program *ureg, + unsigned fs_write_all); + /*********************************************************************** * Build shader declarations: */ diff --git a/src/gallium/drivers/r300/r300_fs.c b/src/gallium/drivers/r300/r300_fs.c index 2936c34..b05b00f 100644 --- a/src/gallium/drivers/r300/r300_fs.c +++ b/src/gallium/drivers/r300/r300_fs.c @@ -85,16 +85,19 @@ void r300_shader_read_fs_inputs(struct tgsi_shader_info* info, } static void find_output_registers(struct r300_fragment_program_compiler * compiler, - struct r300_fragment_shader_code *shader) + struct r300_fragment_shader_code *shader, bool write_all) { unsigned i, colorbuf_count = 0; + unsigned max = shader->info.num_outputs; + if (write_all && compiler->state.num_color_outputs > 1) + max = shader->info.num_outputs + compiler->state.num_color_outputs - 1; /* Mark the outputs as not present initially */ - compiler->OutputColor[0] = shader->info.num_outputs; - compiler->OutputColor[1] = shader->info.num_outputs; - compiler->OutputColor[2] = shader->info.num_outputs; - compiler->OutputColor[3] = shader->info.num_outputs; - compiler->OutputDepth = shader->info.num_outputs; + compiler->OutputColor[0] = max; + compiler->OutputColor[1] = max; + compiler->OutputColor[2] = max; + compiler->OutputColor[3] = max; + compiler->OutputDepth = max; /* Now see where they really are. */ for(i = 0; i < shader->info.num_outputs; ++i) { @@ -108,6 +111,14 @@ static void find_output_registers(struct r300_fragment_program_compiler * compil break; } } + + if (write_all && colorbuf_count == 1 && colorbuf_count != compiler->state.num_color_outputs) { + fprintf(stderr,"extra outputs %d\n", compiler->state.num_color_outputs-1); + for (i = 1; i < compiler->state.num_color_outputs; i++) { + compiler->OutputColor[colorbuf_count] = i; + colorbuf_count++; + } + } } static void allocate_hardware_inputs( @@ -148,6 +159,9 @@ static void get_external_state( struct r300_textures_state *texstate = r300->textures_state.state; unsigned i; unsigned char *swizzle; + struct pipe_framebuffer_state *fb_state = r300->fb_state.state; + + state->num_color_outputs = fb_state->nr_cbufs; for (i = 0; i < texstate->sampler_state_count; i++) { struct r300_sampler_state *s = texstate->sampler_states[i]; @@ -368,6 +382,7 @@ static void r300_translate_fragment_shader( struct tgsi_to_rc ttr; int wpos, face; unsigned i; + bool write_all = false; tgsi_scan_shader(tokens, &shader->info); r300_shader_read_fs_inputs(&shader->info, &shader->inputs); @@ -393,7 +408,13 @@ static void r300_translate_fragment_shader( compiler.AllocateHwInputs = &allocate_hardware_inputs; compiler.UserData = &shader->inputs; - find_output_registers(&compiler, shader); + for (i = 0; i < shader->info.num_properties; i++) { + if (shader->info.properties[i].name == TGSI_PROPERTY_FS_WRITE_ALL) { + write_all = true; + } + } + + find_output_registers(&compiler, shader, write_all); if (compiler.Base.Debug & RC_DBG_LOG) { DBG(r300, DBG_FP, "r300: Initial fragment program\n"); @@ -428,6 +449,13 @@ static void r300_translate_fragment_shader( rc_transform_fragment_face(&compiler.Base, face); } + if (write_all == true && compiler.state.num_color_outputs > 1) { + rc_move_output(&compiler.Base, 0, compiler.OutputColor[0], 0xf); + for (i = 1; i < compiler.state.num_color_outputs; i++) { + rc_copy_output(&compiler.Base, 0, compiler.OutputColor[i]); + } + } + /* Invoke the compiler */ r3xx_compile_fragment_program(&compiler); diff --git a/src/gallium/drivers/r300/r300_tgsi_to_rc.c b/src/gallium/drivers/r300/r300_tgsi_to_rc.c index 15a3239..12b6d31 100644 --- a/src/gallium/drivers/r300/r300_tgsi_to_rc.c +++ b/src/gallium/drivers/r300/r300_tgsi_to_rc.c @@ -355,20 +355,22 @@ void r300_tgsi_to_rc(struct tgsi_to_rc * ttr, tgsi_parse_token(&parser); switch (parser.FullToken.Token.Type) { - case TGSI_TOKEN_TYPE_DECLARATION: - break; - case TGSI_TOKEN_TYPE_IMMEDIATE: - handle_immediate(ttr, &parser.FullToken.FullImmediate, imm_index); - imm_index++; - break; - case TGSI_TOKEN_TYPE_INSTRUCTION: - inst = &parser.FullToken.FullInstruction; - if (inst->Instruction.Opcode == TGSI_OPCODE_END) { - break; - } - - transform_instruction(ttr, inst); - break; + case TGSI_TOKEN_TYPE_PROPERTY: + fprintf(stderr,"property\n"); + break; + case TGSI_TOKEN_TYPE_DECLARATION: + break; + case TGSI_TOKEN_TYPE_IMMEDIATE: + handle_immediate(ttr, &parser.FullToken.FullImmediate, imm_index); + imm_index++; + break; + case TGSI_TOKEN_TYPE_INSTRUCTION: + inst = &parser.FullToken.FullInstruction; + if (inst->Instruction.Opcode == TGSI_OPCODE_END) { + break; + } + transform_instruction(ttr, inst); + break; } } diff --git a/src/gallium/include/pipe/p_shader_tokens.h b/src/gallium/include/pipe/p_shader_tokens.h index ba433b2..d0f96c3 100644 --- a/src/gallium/include/pipe/p_shader_tokens.h +++ b/src/gallium/include/pipe/p_shader_tokens.h @@ -177,7 +177,8 @@ union tgsi_immediate_data #define TGSI_PROPERTY_GS_MAX_OUTPUT_VERTICES 2 #define TGSI_PROPERTY_FS_COORD_ORIGIN 3 #define TGSI_PROPERTY_FS_COORD_PIXEL_CENTER 4 -#define TGSI_PROPERTY_COUNT 5 +#define TGSI_PROPERTY_FS_WRITE_ALL 5 +#define TGSI_PROPERTY_COUNT 6 struct tgsi_property { unsigned Type : 4; /**< TGSI_TOKEN_TYPE_PROPERTY */ diff --git a/src/mesa/drivers/dri/r300/compiler/r3xx_fragprog.c b/src/mesa/drivers/dri/r300/compiler/r3xx_fragprog.c index e0d349b..9b08455 100644 --- a/src/mesa/drivers/dri/r300/compiler/r3xx_fragprog.c +++ b/src/mesa/drivers/dri/r300/compiler/r3xx_fragprog.c @@ -103,6 +103,7 @@ void r3xx_compile_fragment_program(struct r300_fragment_program_compiler* c) { 0, 0 } }; + fprintf(stderr,"num color buffers %d\n", c->state.num_color_outputs); /* List of compiler passes. */ struct radeon_compiler_pass fs_list[] = { /* NAME DUMP PREDICATE FUNCTION PARAM */ diff --git a/src/mesa/drivers/dri/r300/compiler/radeon_code.h b/src/mesa/drivers/dri/r300/compiler/radeon_code.h index b69e816..890b5ce 100644 --- a/src/mesa/drivers/dri/r300/compiler/radeon_code.h +++ b/src/mesa/drivers/dri/r300/compiler/radeon_code.h @@ -170,6 +170,7 @@ struct r300_fragment_program_external_state { * RC_STATE_R300_TEXSCALE_FACTOR. */ unsigned clamp_and_scale_before_fetch : 1; } unit[16]; + int num_color_outputs; }; diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c index cfdc96b..ba67695 100644 --- a/src/mesa/state_tracker/st_program.c +++ b/src/mesa/state_tracker/st_program.c @@ -444,6 +444,7 @@ st_translate_fragment_program(struct st_context *st, enum pipe_error error; const GLbitfield inputsRead = stfp->Base.Base.InputsRead; struct ureg_program *ureg; + GLboolean write_all = GL_FALSE; ubyte input_semantic_name[PIPE_MAX_SHADER_INPUTS]; ubyte input_semantic_index[PIPE_MAX_SHADER_INPUTS]; @@ -568,6 +569,8 @@ st_translate_fragment_program(struct st_context *st, /* handled above */ assert(0); break; + case FRAG_RESULT_COLOR: + write_all = GL_TRUE; /* fallthrough */ default: assert(attr == FRAG_RESULT_COLOR || (FRAG_RESULT_DATA0 <= attr && attr < FRAG_RESULT_MAX)); @@ -592,6 +595,8 @@ st_translate_fragment_program(struct st_context *st, _mesa_print_program_parameters(st->ctx, &stfp->Base.Base); debug_printf("\n"); } + if (write_all == GL_TRUE) + ureg_property_fs_write_all(ureg, 1); error = st_translate_mesa_program(st->ctx, TGSI_PROCESSOR_FRAGMENT, -- 1.7.2.3