diff options
author | Christian König <[email protected]> | 2011-03-05 15:46:56 +0100 |
---|---|---|
committer | Christian König <[email protected]> | 2011-03-05 15:46:56 +0100 |
commit | 199034a3cc46e09e7a325690ac5b2b097e90249f (patch) | |
tree | 7977b528517d926d04d7fa990b27b09c653ba087 /src/gallium/drivers/r300 | |
parent | 54f11a27a1ec28fcf9734f4454dee870bc0113f8 (diff) | |
parent | 533bf171d4c926e4ab6fcd0d51396b195b9e024f (diff) |
Merge remote branch 'origin/master' into pipe-video
Diffstat (limited to 'src/gallium/drivers/r300')
-rw-r--r-- | src/gallium/drivers/r300/r300_context.c | 5 | ||||
-rw-r--r-- | src/gallium/drivers/r300/r300_context.h | 22 | ||||
-rw-r--r-- | src/gallium/drivers/r300/r300_emit.c | 10 | ||||
-rw-r--r-- | src/gallium/drivers/r300/r300_state.c | 109 | ||||
-rw-r--r-- | src/gallium/drivers/r300/r300_state_inlines.h | 31 |
5 files changed, 140 insertions, 37 deletions
diff --git a/src/gallium/drivers/r300/r300_context.c b/src/gallium/drivers/r300/r300_context.c index 166d965aa5b..b8db6fb6c12 100644 --- a/src/gallium/drivers/r300/r300_context.c +++ b/src/gallium/drivers/r300/r300_context.c @@ -194,14 +194,14 @@ static boolean r300_setup_atoms(struct r300_context* r300) /* ZB (unpipelined), SC. */ R300_INIT_ATOM(ztop_state, 2); /* ZB, FG. */ - R300_INIT_ATOM(dsa_state, is_r500 ? 8 : 6); + R300_INIT_ATOM(dsa_state, is_r500 ? (drm_2_6_0 ? 10 : 8) : 6); /* RB3D. */ R300_INIT_ATOM(blend_state, 8); R300_INIT_ATOM(blend_color_state, is_r500 ? 3 : 2); /* SC. */ R300_INIT_ATOM(scissor_state, 3); /* GB, FG, GA, SU, SC, RB3D. */ - R300_INIT_ATOM(invariant_state, 18 + (is_rv350 ? 4 : 0) + (is_r500 ? 4 : 0)); + R300_INIT_ATOM(invariant_state, 16 + (is_rv350 ? 4 : 0) + (is_r500 ? 4 : 0)); /* VAP. */ R300_INIT_ATOM(viewport_state, 9); R300_INIT_ATOM(pvs_flush, 2); @@ -349,7 +349,6 @@ static void r300_init_states(struct pipe_context *pipe) BEGIN_CB(invariant->cb, r300->invariant_state.size); OUT_CB_REG(R300_GB_SELECT, 0); OUT_CB_REG(R300_FG_FOG_BLEND, 0); - OUT_CB_REG(R300_GA_ROUND_MODE, 1); OUT_CB_REG(R300_GA_OFFSET, 0); OUT_CB_REG(R300_SU_TEX_WRAP, 0); OUT_CB_REG(R300_SU_DEPTH_SCALE, 0x4B7FFFFF); diff --git a/src/gallium/drivers/r300/r300_context.h b/src/gallium/drivers/r300/r300_context.h index 6f2aab69ab1..58e1094e339 100644 --- a/src/gallium/drivers/r300/r300_context.h +++ b/src/gallium/drivers/r300/r300_context.h @@ -70,6 +70,7 @@ struct r300_blend_state { }; struct r300_blend_color_state { + struct pipe_blend_color state; uint32_t cb[3]; }; @@ -91,9 +92,24 @@ struct r300_dsa_state { uint32_t stencil_ref_mask; /* R300_ZB_STENCILREFMASK: 0x4f08 */ uint32_t cb_reg; uint32_t stencil_ref_bf; /* R500_ZB_STENCILREFMASK_BF: 0x4fd4 */ + uint32_t cb_reg1; + uint32_t alpha_value; /* R500_FG_ALPHA_VALUE: 0x4be0 */ + + /* The same, but for FP16 alpha test. */ + uint32_t cb_begin_fp16; + uint32_t alpha_function_fp16; /* R300_FG_ALPHA_FUNC: 0x4bd4 */ + uint32_t cb_reg_seq_fp16; + uint32_t z_buffer_control_fp16; /* R300_ZB_CNTL: 0x4f00 */ + uint32_t z_stencil_control_fp16; /* R300_ZB_ZSTENCILCNTL: 0x4f04 */ + uint32_t stencil_ref_mask_fp16; /* R300_ZB_STENCILREFMASK: 0x4f08 */ + uint32_t cb_reg_fp16; + uint32_t stencil_ref_bf_fp16; /* R500_ZB_STENCILREFMASK_BF: 0x4fd4 */ + uint32_t cb_reg1_fp16; + uint32_t alpha_value_fp16; /* R500_FG_ALPHA_VALUE: 0x4be0 */ /* The second command buffer disables zbuffer reads and writes. */ - uint32_t cb_no_readwrite[8]; + uint32_t cb_zb_no_readwrite[10]; + uint32_t cb_fp16_zb_no_readwrite[10]; /* Whether a two-sided stencil is enabled. */ boolean two_sided; @@ -120,7 +136,7 @@ struct r300_gpu_flush { uint32_t cb_flush_clean[6]; }; -#define RS_STATE_MAIN_SIZE 23 +#define RS_STATE_MAIN_SIZE 25 struct r300_rs_state { /* Original rasterizer state. */ @@ -219,7 +235,7 @@ struct r300_vertex_stream_state { }; struct r300_invariant_state { - uint32_t cb[26]; + uint32_t cb[24]; }; struct r300_vap_invariant_state { diff --git a/src/gallium/drivers/r300/r300_emit.c b/src/gallium/drivers/r300/r300_emit.c index 24c82a3efd2..e3945b72d7a 100644 --- a/src/gallium/drivers/r300/r300_emit.c +++ b/src/gallium/drivers/r300/r300_emit.c @@ -77,9 +77,15 @@ void r300_emit_dsa_state(struct r300_context* r300, unsigned size, void* state) CS_LOCALS(r300); if (fb->zsbuf) { - WRITE_CS_TABLE(&dsa->cb_begin, size); + if (fb->nr_cbufs && fb->cbufs[0]->format == PIPE_FORMAT_R16G16B16A16_FLOAT) + WRITE_CS_TABLE(&dsa->cb_begin_fp16, size); + else + WRITE_CS_TABLE(&dsa->cb_begin, size); } else { - WRITE_CS_TABLE(dsa->cb_no_readwrite, size); + if (fb->nr_cbufs && fb->cbufs[0]->format == PIPE_FORMAT_R16G16B16A16_FLOAT) + WRITE_CS_TABLE(dsa->cb_fp16_zb_no_readwrite, size); + else + WRITE_CS_TABLE(dsa->cb_zb_no_readwrite, size); } } diff --git a/src/gallium/drivers/r300/r300_state.c b/src/gallium/drivers/r300/r300_state.c index b810f4081c8..2b0c8750554 100644 --- a/src/gallium/drivers/r300/r300_state.c +++ b/src/gallium/drivers/r300/r300_state.c @@ -24,6 +24,7 @@ #include "draw/draw_context.h" #include "util/u_framebuffer.h" +#include "util/u_half.h" #include "util/u_math.h" #include "util/u_mm.h" #include "util/u_memory.h" @@ -191,6 +192,7 @@ static void* r300_create_blend_state(struct pipe_context* pipe, uint32_t color_channel_mask = 0; /* R300_RB3D_COLOR_CHANNEL_MASK: 0x4e0c */ uint32_t rop = 0; /* R300_RB3D_ROPCNTL: 0x4e18 */ uint32_t dither = 0; /* R300_RB3D_DITHER_CTL: 0x4e50 */ + boolean clamp = TRUE; CB_LOCALS; if (state->rt[0].blend_enable) @@ -206,7 +208,7 @@ static void* r300_create_blend_state(struct pipe_context* pipe, /* despite the name, ALPHA_BLEND_ENABLE has nothing to do with alpha, * this is just the crappy D3D naming */ blend_control = R300_ALPHA_BLEND_ENABLE | - r300_translate_blend_function(eqRGB) | + r300_translate_blend_function(eqRGB, clamp) | ( r300_translate_blend_factor(srcRGB) << R300_SRC_BLEND_SHIFT) | ( r300_translate_blend_factor(dstRGB) << R300_DST_BLEND_SHIFT); @@ -267,7 +269,8 @@ static void* r300_create_blend_state(struct pipe_context* pipe, * * Equations other than ADD are rarely used and therefore won't be * optimized. */ - if ((eqRGB == PIPE_BLEND_ADD || eqRGB == PIPE_BLEND_REVERSE_SUBTRACT) && + if (clamp && + (eqRGB == PIPE_BLEND_ADD || eqRGB == PIPE_BLEND_REVERSE_SUBTRACT) && (eqA == PIPE_BLEND_ADD || eqA == PIPE_BLEND_REVERSE_SUBTRACT)) { /* ADD: X+Y * REVERSE_SUBTRACT: Y-X @@ -306,7 +309,7 @@ static void* r300_create_blend_state(struct pipe_context* pipe, if (srcA != srcRGB || dstA != dstRGB || eqA != eqRGB) { blend_control |= R300_SEPARATE_ALPHA_ENABLE; alpha_blend_control = - r300_translate_blend_function(eqA) | + r300_translate_blend_function(eqA, clamp) | (r300_translate_blend_factor(srcA) << R300_SRC_BLEND_SHIFT) | (r300_translate_blend_factor(dstA) << R300_DST_BLEND_SHIFT); } @@ -395,22 +398,64 @@ static void r300_set_blend_color(struct pipe_context* pipe, const struct pipe_blend_color* color) { struct r300_context* r300 = r300_context(pipe); - struct r300_blend_color_state* state = + struct pipe_framebuffer_state *fb = r300->fb_state.state; + struct r300_blend_color_state *state = (struct r300_blend_color_state*)r300->blend_color_state.state; + struct pipe_blend_color c; + enum pipe_format format = fb->nr_cbufs ? fb->cbufs[0]->format : 0; CB_LOCALS; + state->state = *color; /* Save it, so that we can reuse it in set_fb_state */ + c = *color; + + /* The blend color is dependent on the colorbuffer format. */ + if (fb->nr_cbufs) { + switch (format) { + case PIPE_FORMAT_R8_UNORM: + case PIPE_FORMAT_L8_UNORM: + case PIPE_FORMAT_I8_UNORM: + c.color[1] = c.color[0]; + break; + + case PIPE_FORMAT_A8_UNORM: + c.color[1] = c.color[3]; + break; + + case PIPE_FORMAT_R8G8_UNORM: + c.color[2] = c.color[1]; + break; + + case PIPE_FORMAT_L8A8_UNORM: + c.color[2] = c.color[3]; + break; + + default:; + } + } + if (r300->screen->caps.is_r500) { - /* XXX if FP16 blending is enabled, we should use the FP16 format */ BEGIN_CB(state->cb, 3); OUT_CB_REG_SEQ(R500_RB3D_CONSTANT_COLOR_AR, 2); - OUT_CB(float_to_fixed10(color->color[0]) | - (float_to_fixed10(color->color[3]) << 16)); - OUT_CB(float_to_fixed10(color->color[2]) | - (float_to_fixed10(color->color[1]) << 16)); + + switch (format) { + case PIPE_FORMAT_R16G16B16A16_FLOAT: + OUT_CB(util_float_to_half(c.color[2]) | + (util_float_to_half(c.color[3]) << 16)); + OUT_CB(util_float_to_half(c.color[0]) | + (util_float_to_half(c.color[1]) << 16)); + break; + + default: + OUT_CB(float_to_fixed10(c.color[0]) | + (float_to_fixed10(c.color[3]) << 16)); + OUT_CB(float_to_fixed10(c.color[2]) | + (float_to_fixed10(c.color[1]) << 16)); + } + END_CB; } else { union util_color uc; - util_pack_color(color->color, PIPE_FORMAT_B8G8R8A8_UNORM, &uc); + util_pack_color(c.color, PIPE_FORMAT_B8G8R8A8_UNORM, &uc); BEGIN_CB(state->cb, 2); OUT_CB_REG(R300_RB3D_BLEND_COLOR, uc.ui); @@ -537,29 +582,54 @@ static void* r300_translate_alpha_function(state->alpha.func) | R300_FG_ALPHA_FUNC_ENABLE; - /* We could use 10bit alpha ref but who needs that? */ dsa->alpha_function |= float_to_ubyte(state->alpha.ref_value); + dsa->alpha_value = util_float_to_half(state->alpha.ref_value); - if (caps->is_r500) + if (caps->is_r500) { + dsa->alpha_function_fp16 = dsa->alpha_function | + R500_FG_ALPHA_FUNC_FP16_ENABLE; dsa->alpha_function |= R500_FG_ALPHA_FUNC_8BIT; + } } - BEGIN_CB(&dsa->cb_begin, 8); + BEGIN_CB(&dsa->cb_begin, 10); OUT_CB_REG(R300_FG_ALPHA_FUNC, dsa->alpha_function); OUT_CB_REG_SEQ(R300_ZB_CNTL, 3); OUT_CB(dsa->z_buffer_control); OUT_CB(dsa->z_stencil_control); OUT_CB(dsa->stencil_ref_mask); OUT_CB_REG(R500_ZB_STENCILREFMASK_BF, dsa->stencil_ref_bf); + OUT_CB_REG(R500_FG_ALPHA_VALUE, dsa->alpha_value); + END_CB; + + BEGIN_CB(&dsa->cb_begin_fp16, 10); + OUT_CB_REG(R300_FG_ALPHA_FUNC, dsa->alpha_function_fp16); + OUT_CB_REG_SEQ(R300_ZB_CNTL, 3); + OUT_CB(dsa->z_buffer_control); + OUT_CB(dsa->z_stencil_control); + OUT_CB(dsa->stencil_ref_mask); + OUT_CB_REG(R500_ZB_STENCILREFMASK_BF, dsa->stencil_ref_bf); + OUT_CB_REG(R500_FG_ALPHA_VALUE, dsa->alpha_value); END_CB; - BEGIN_CB(dsa->cb_no_readwrite, 8); + BEGIN_CB(dsa->cb_zb_no_readwrite, 10); OUT_CB_REG(R300_FG_ALPHA_FUNC, dsa->alpha_function); OUT_CB_REG_SEQ(R300_ZB_CNTL, 3); OUT_CB(0); OUT_CB(0); OUT_CB(0); OUT_CB_REG(R500_ZB_STENCILREFMASK_BF, 0); + OUT_CB_REG(R500_FG_ALPHA_VALUE, dsa->alpha_value); + END_CB; + + BEGIN_CB(dsa->cb_fp16_zb_no_readwrite, 10); + OUT_CB_REG(R300_FG_ALPHA_FUNC, dsa->alpha_function_fp16); + OUT_CB_REG_SEQ(R300_ZB_CNTL, 3); + OUT_CB(0); + OUT_CB(0); + OUT_CB(0); + OUT_CB_REG(R500_ZB_STENCILREFMASK_BF, 0); + OUT_CB_REG(R500_FG_ALPHA_VALUE, dsa->alpha_value); END_CB; return (void*)dsa; @@ -686,6 +756,8 @@ void r300_mark_fb_state_dirty(struct r300_context *r300, /* What is marked as dirty depends on the enum r300_fb_state_change. */ if (change == R300_CHANGED_FB_STATE) { r300_mark_atom_dirty(r300, &r300->aa_state); + r300_mark_atom_dirty(r300, &r300->dsa_state); /* for AlphaRef */ + r300_set_blend_color(&r300->context, r300->blend_color_state.state); } if (change == R300_CHANGED_FB_STATE || @@ -944,12 +1016,14 @@ static void* r300_create_rs_state(struct pipe_context* pipe, uint32_t line_stipple_value; /* R300_GA_LINE_STIPPLE_VALUE: 0x4260 */ uint32_t polygon_mode; /* R300_GA_POLY_MODE: 0x4288 */ uint32_t clip_rule; /* R300_SC_CLIP_RULE: 0x43D0 */ + uint32_t round_mode; /* R300_GA_ROUND_MODE: 0x428c */ /* Point sprites texture coordinates, 0: lower left, 1: upper right */ float point_texcoord_left = 0; /* R300_GA_POINT_S0: 0x4200 */ float point_texcoord_bottom = 0;/* R300_GA_POINT_T0: 0x4204 */ float point_texcoord_right = 1; /* R300_GA_POINT_S1: 0x4208 */ float point_texcoord_top = 0; /* R300_GA_POINT_T1: 0x420c */ + boolean vclamp = TRUE; CB_LOCALS; /* Copy rasterizer state. */ @@ -1072,6 +1146,12 @@ static void* r300_create_rs_state(struct pipe_context* pipe, } } + /* Vertex color clamping. FP20 means no clamping. */ + round_mode = + R300_GA_ROUND_MODE_GEOMETRY_ROUND_NEAREST | + (!vclamp ? (R300_GA_ROUND_MODE_RGB_CLAMP_FP20 | + R300_GA_ROUND_MODE_ALPHA_CLAMP_FP20) : 0); + /* Build the main command buffer. */ BEGIN_CB(rs->cb_main, RS_STATE_MAIN_SIZE); OUT_CB_REG(R300_VAP_CNTL_STATUS, vap_control_status); @@ -1086,6 +1166,7 @@ static void* r300_create_rs_state(struct pipe_context* pipe, OUT_CB_REG(R300_GA_LINE_STIPPLE_CONFIG, line_stipple_config); OUT_CB_REG(R300_GA_LINE_STIPPLE_VALUE, line_stipple_value); OUT_CB_REG(R300_GA_POLY_MODE, polygon_mode); + OUT_CB_REG(R300_GA_ROUND_MODE, round_mode); OUT_CB_REG(R300_SC_CLIP_RULE, clip_rule); OUT_CB_REG_SEQ(R300_GA_POINT_S0, 4); OUT_CB_32F(point_texcoord_left); diff --git a/src/gallium/drivers/r300/r300_state_inlines.h b/src/gallium/drivers/r300/r300_state_inlines.h index 06da04c7ad7..54dae1acd98 100644 --- a/src/gallium/drivers/r300/r300_state_inlines.h +++ b/src/gallium/drivers/r300/r300_state_inlines.h @@ -38,23 +38,24 @@ static INLINE int pack_float_16_6x(float f) { /* Blend state. */ -static INLINE uint32_t r300_translate_blend_function(int blend_func) +static INLINE uint32_t r300_translate_blend_function(int blend_func, + boolean clamp) { switch (blend_func) { - case PIPE_BLEND_ADD: - return R300_COMB_FCN_ADD_CLAMP; - case PIPE_BLEND_SUBTRACT: - return R300_COMB_FCN_SUB_CLAMP; - case PIPE_BLEND_REVERSE_SUBTRACT: - return R300_COMB_FCN_RSUB_CLAMP; - case PIPE_BLEND_MIN: - return R300_COMB_FCN_MIN; - case PIPE_BLEND_MAX: - return R300_COMB_FCN_MAX; - default: - fprintf(stderr, "r300: Unknown blend function %d\n", blend_func); - assert(0); - break; + case PIPE_BLEND_ADD: + return clamp ? R300_COMB_FCN_ADD_CLAMP : R300_COMB_FCN_ADD_NOCLAMP; + case PIPE_BLEND_SUBTRACT: + return clamp ? R300_COMB_FCN_SUB_CLAMP : R300_COMB_FCN_SUB_NOCLAMP; + case PIPE_BLEND_REVERSE_SUBTRACT: + return clamp ? R300_COMB_FCN_RSUB_CLAMP : R300_COMB_FCN_RSUB_NOCLAMP; + case PIPE_BLEND_MIN: + return R300_COMB_FCN_MIN; + case PIPE_BLEND_MAX: + return R300_COMB_FCN_MAX; + default: + fprintf(stderr, "r300: Unknown blend function %d\n", blend_func); + assert(0); + break; } return 0; } |