r300g: implement fragment color clamping in the shader
authorMarek Olšák <maraeo@gmail.com>
Sat, 12 Mar 2011 05:11:18 +0000 (06:11 +0100)
committerMarek Olšák <maraeo@gmail.com>
Sat, 12 Mar 2011 06:56:33 +0000 (07:56 +0100)
This finishes the implementation of the fragment color clamp control
for ARB_color_buffer_float. I don't wanna keep this stuff in a branch...

src/gallium/drivers/r300/r300_context.h
src/gallium/drivers/r300/r300_fs.c
src/gallium/drivers/r300/r300_state.c
src/mesa/drivers/dri/r300/compiler/r3xx_fragprog.c
src/mesa/drivers/dri/r300/compiler/radeon_code.h

index 76ea5ee2517ee1f788a9af2a50b53ad867fc297f..162470871039b4ae1f853770cadde3bd567c6535 100644 (file)
@@ -65,6 +65,8 @@ struct r300_aa_state {
 };
 
 struct r300_blend_state {
+    struct pipe_blend_state state;
+
     uint32_t cb[8];
     uint32_t cb_no_readwrite[8];
 };
index cec7473009a6e03f359b7e5457c4c3ceeefa71ae..4c502fefb3fce365c3c50b0a668ff45074e4def9 100644 (file)
@@ -149,6 +149,8 @@ static void get_external_state(
     unsigned i;
     unsigned char *swizzle;
 
+    state->frag_clamp = 0;
+
     for (i = 0; i < texstate->sampler_state_count; i++) {
         struct r300_sampler_state *s = texstate->sampler_states[i];
         struct r300_sampler_view *v = texstate->sampler_views[i];
index 49c2b883504988c3b9d096931acf47ffc5d2a7ed..f0830e13f046e7b707c39c8cd3a89d70f693bb61 100644 (file)
@@ -195,6 +195,8 @@ static void* r300_create_blend_state(struct pipe_context* pipe,
     boolean clamp = TRUE;
     CB_LOCALS;
 
+    blend->state = *state;
+
     if (state->rt[0].blend_enable)
     {
         unsigned eqRGB = state->rt[0].rgb_func;
@@ -377,6 +379,10 @@ static void r300_bind_blend_state(struct pipe_context* pipe,
     struct r300_context* r300 = r300_context(pipe);
 
     UPDATE_STATE(state, r300->blend_state);
+
+    if (r300->fs.state && r300_pick_fragment_shader(r300)) {
+        r300_mark_fs_code_dirty(r300);
+    }
 }
 
 /* Free blend state. */
index 1616306afbd4c6b29e0b7099f2596443213e64ed..9286733635fcc5c44ba13da355fc148e2502f7b4 100644 (file)
@@ -78,12 +78,32 @@ static void rc_rewrite_depth_out(struct radeon_compiler *cc, void *user)
        }
 }
 
+static int radeon_saturate_output(
+               struct radeon_compiler * c,
+               struct rc_instruction * inst,
+               void* data)
+{
+       const struct rc_opcode_info *info = rc_get_opcode_info(inst->U.I.Opcode);
+
+       if (!info->HasDstReg || inst->U.I.DstReg.File != RC_FILE_OUTPUT)
+               return 0;
+
+       inst->U.I.SaturateMode = RC_SATURATE_ZERO_ONE;
+       return 1;
+}
+
 void r3xx_compile_fragment_program(struct r300_fragment_program_compiler* c)
 {
        int is_r500 = c->Base.is_r500;
        int opt = !c->Base.disable_optimizations;
+       int sat_out = c->state.frag_clamp;
 
        /* Lists of instruction transformations. */
+       struct radeon_program_transformation saturate_output[] = {
+               { &radeon_saturate_output, c },
+               { 0, 0 }
+       };
+
        struct radeon_program_transformation rewrite_tex[] = {
                { &radeonTransformTEX, c },
                { 0, 0 }
@@ -113,6 +133,7 @@ void r3xx_compile_fragment_program(struct r300_fragment_program_compiler* c)
                {"unroll loops",                1, is_r500,     rc_unroll_loops,                NULL},
                {"transform loops",             1, !is_r500,    rc_transform_loops,             NULL},
                {"emulate branches",            1, !is_r500,    rc_emulate_branches,            NULL},
+               {"saturate output writes",      1, sat_out,     rc_local_transform,             saturate_output},
                {"transform TEX",               1, 1,           rc_local_transform,             rewrite_tex},
                {"native rewrite",              1, is_r500,     rc_local_transform,             native_rewrite_r500},
                {"native rewrite",              1, !is_r500,    rc_local_transform,             native_rewrite_r300},
index d14516689472308eb848e5b67fc436356fe630b6..35360aa70f07033368568552bcb4fa0a9be574e2 100644 (file)
@@ -173,6 +173,8 @@ struct r300_fragment_program_external_state {
                 * RC_STATE_R300_TEXSCALE_FACTOR. */
                unsigned clamp_and_scale_before_fetch : 1;
        } unit[16];
+
+       unsigned frag_clamp:1;
 };