r600g: add support for signed normalized frame buffers
[mesa.git] / src / gallium / drivers / r600 / r600_state.c
index df2c05ea1390bd7a24735f1e40d254ac198d8426..fa011612aebdb3ddbf4cd00a91ad6760e84999be 100644 (file)
@@ -324,20 +324,6 @@ static void *r600_create_blend_state(struct pipe_context *ctx,
        return rstate;
 }
 
-static void r600_bind_blend_state(struct pipe_context *ctx, void *state)
-{
-       struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx;
-       struct r600_pipe_blend *blend = (struct r600_pipe_blend *)state;
-       struct r600_pipe_state *rstate;
-
-       if (state == NULL)
-               return;
-       rstate = &blend->rstate;
-       rctx->states[rstate->id] = rstate;
-       rctx->cb_target_mask = blend->cb_target_mask;
-       r600_context_pipe_state_set(&rctx->ctx, rstate);
-}
-
 static void *r600_create_dsa_state(struct pipe_context *ctx,
                                   const struct pipe_depth_stencil_alpha_state *state)
 {
@@ -448,7 +434,7 @@ static void *r600_create_rs_state(struct pipe_context *ctx,
        rstate->id = R600_PIPE_STATE_RASTERIZER;
        if (state->flatshade_first)
                prov_vtx = 0;
-       tmp = 0x00000001;
+       tmp = S_0286D4_FLAT_SHADE_ENA(1);
        if (state->sprite_coord_enable) {
                tmp |= S_0286D4_PNT_SPRITE_ENA(1) |
                        S_0286D4_PNT_SPRITE_OVRD_X(2) |
@@ -483,12 +469,17 @@ static void *r600_create_rs_state(struct pipe_context *ctx,
        r600_pipe_state_add_reg(rstate, R_028A00_PA_SU_POINT_SIZE, S_028A00_HEIGHT(tmp) | S_028A00_WIDTH(tmp), 0xFFFFFFFF, NULL);
        r600_pipe_state_add_reg(rstate, R_028A04_PA_SU_POINT_MINMAX, 0x80000000, 0xFFFFFFFF, NULL);
 
-       tmp = (unsigned)(state->line_width * 8.0);
+       tmp = (unsigned)state->line_width * 8;
        r600_pipe_state_add_reg(rstate, R_028A08_PA_SU_LINE_CNTL, S_028A08_WIDTH(tmp), 0xFFFFFFFF, NULL);
 
        r600_pipe_state_add_reg(rstate, R_028A0C_PA_SC_LINE_STIPPLE, 0x00000005, 0xFFFFFFFF, NULL);
        r600_pipe_state_add_reg(rstate, R_028A48_PA_SC_MPASS_PS_CNTL, 0x00000000, 0xFFFFFFFF, NULL);
        r600_pipe_state_add_reg(rstate, R_028C00_PA_SC_LINE_CNTL, 0x00000400, 0xFFFFFFFF, NULL);
+        
+       r600_pipe_state_add_reg(rstate, R_028C08_PA_SU_VTX_CNTL,
+                               S_028C08_PIX_CENTER_HALF(state->gl_rasterization_rules),
+                               0xFFFFFFFF, NULL);
+
        r600_pipe_state_add_reg(rstate, R_028C0C_PA_CL_GB_VERT_CLIP_ADJ, 0x3F800000, 0xFFFFFFFF, NULL);
        r600_pipe_state_add_reg(rstate, R_028C10_PA_CL_GB_VERT_DISC_ADJ, 0x3F800000, 0xFFFFFFFF, NULL);
        r600_pipe_state_add_reg(rstate, R_028C14_PA_CL_GB_HORZ_CLIP_ADJ, 0x3F800000, 0xFFFFFFFF, NULL);
@@ -499,36 +490,6 @@ static void *r600_create_rs_state(struct pipe_context *ctx,
        return rstate;
 }
 
-static void r600_bind_rs_state(struct pipe_context *ctx, void *state)
-{
-       struct r600_pipe_rasterizer *rs = (struct r600_pipe_rasterizer *)state;
-       struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx;
-
-       if (state == NULL)
-               return;
-
-       rctx->flatshade = rs->flatshade;
-       rctx->sprite_coord_enable = rs->sprite_coord_enable;
-       rctx->rasterizer = rs;
-
-       rctx->states[rs->rstate.id] = &rs->rstate;
-       r600_context_pipe_state_set(&rctx->ctx, &rs->rstate);
-}
-
-static void r600_delete_rs_state(struct pipe_context *ctx, void *state)
-{
-       struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx;
-       struct r600_pipe_rasterizer *rs = (struct r600_pipe_rasterizer *)state;
-
-       if (rctx->rasterizer == rs) {
-               rctx->rasterizer = NULL;
-       }
-       if (rctx->states[rs->rstate.id] == &rs->rstate) {
-               rctx->states[rs->rstate.id] = NULL;
-       }
-       free(rs);
-}
-
 static void *r600_create_sampler_state(struct pipe_context *ctx,
                                        const struct pipe_sampler_state *state)
 {
@@ -565,16 +526,6 @@ static void *r600_create_sampler_state(struct pipe_context *ctx,
        return rstate;
 }
 
-
-static void r600_sampler_view_destroy(struct pipe_context *ctx,
-                                     struct pipe_sampler_view *state)
-{
-       struct r600_pipe_sampler_view *resource = (struct r600_pipe_sampler_view *)state;
-
-       pipe_resource_reference(&state->texture, NULL);
-       FREE(resource);
-}
-
 static struct pipe_sampler_view *r600_create_sampler_view(struct pipe_context *ctx,
                                                        struct pipe_resource *texture,
                                                        const struct pipe_sampler_view *state)
@@ -705,17 +656,6 @@ static void r600_set_ps_sampler_view(struct pipe_context *ctx, unsigned count,
        rctx->ps_samplers.n_views = count;
 }
 
-static void r600_bind_state(struct pipe_context *ctx, void *state)
-{
-       struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx;
-       struct r600_pipe_state *rstate = (struct r600_pipe_state *)state;
-
-       if (state == NULL)
-               return;
-       rctx->states[rstate->id] = rstate;
-       r600_context_pipe_state_set(&rctx->ctx, rstate);
-}
-
 static void r600_bind_ps_sampler(struct pipe_context *ctx, unsigned count, void **states)
 {
        struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx;
@@ -739,31 +679,6 @@ static void r600_bind_vs_sampler(struct pipe_context *ctx, unsigned count, void
        }
 }
 
-static void r600_delete_state(struct pipe_context *ctx, void *state)
-{
-       struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx;
-       struct r600_pipe_state *rstate = (struct r600_pipe_state *)state;
-
-       if (rctx->states[rstate->id] == rstate) {
-               rctx->states[rstate->id] = NULL;
-       }
-       for (int i = 0; i < rstate->nregs; i++) {
-               r600_bo_reference(rctx->radeon, &rstate->regs[i].bo, NULL);
-       }
-       free(rstate);
-}
-
-static void r600_delete_vertex_element(struct pipe_context *ctx, void *state)
-{
-       struct r600_vertex_element *v = (struct r600_vertex_element*)state;
-
-       if (v == NULL)
-               return;
-       if (--v->refcount)
-               return;
-       free(v);
-}
-
 static void r600_set_clip_state(struct pipe_context *ctx,
                                const struct pipe_clip_state *state)
 {
@@ -799,19 +714,6 @@ static void r600_set_clip_state(struct pipe_context *ctx,
        r600_context_pipe_state_set(&rctx->ctx, rstate);
 }
 
-static void r600_bind_vertex_elements(struct pipe_context *ctx, void *state)
-{
-       struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx;
-       struct r600_vertex_element *v = (struct r600_vertex_element*)state;
-
-       r600_delete_vertex_element(ctx, rctx->vertex_elements);
-       rctx->vertex_elements = v;
-       if (v) {
-               v->refcount++;
-//             rctx->vs_rebuild = TRUE;
-       }
-}
-
 static void r600_set_polygon_stipple(struct pipe_context *ctx,
                                         const struct pipe_poly_stipple *state)
 {
@@ -942,6 +844,17 @@ static void r600_cb(struct r600_pipe_context *rctx, struct r600_pipe_state *rsta
        desc = util_format_description(rtex->resource.base.b.format);
        if (desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB)
                ntype = V_0280A0_NUMBER_SRGB;
+        else if (desc->layout == UTIL_FORMAT_LAYOUT_PLAIN) {
+               switch(desc->channel[0].type) {
+               case UTIL_FORMAT_TYPE_UNSIGNED:
+                       ntype = V_0280A0_NUMBER_UNORM;
+                       break;
+
+               case UTIL_FORMAT_TYPE_SIGNED:
+                       ntype = V_0280A0_NUMBER_SNORM;
+                       break;
+               }
+       }
 
        format = r600_translate_colorformat(rtex->resource.base.b.format);
        swap = r600_translate_colorswap(rtex->resource.base.b.format);
@@ -1121,6 +1034,13 @@ static void r600_set_constant_buffer(struct pipe_context *ctx, uint shader, uint
        struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx;
        struct r600_resource *rbuffer = (struct r600_resource*)buffer;
 
+       /* Note that the state tracker can unbind constant buffers by
+        * passing NULL here.
+        */
+       if (buffer == NULL) {
+               return;
+       }
+
        switch (shader) {
        case PIPE_SHADER_VERTEX:
                rctx->vs_const_buffer.nregs = 0;
@@ -1150,59 +1070,6 @@ static void r600_set_constant_buffer(struct pipe_context *ctx, uint shader, uint
        }
 }
 
-static void *r600_create_shader_state(struct pipe_context *ctx,
-                                       const struct pipe_shader_state *state)
-{
-       struct r600_pipe_shader *shader =  CALLOC_STRUCT(r600_pipe_shader);
-       int r;
-
-       r =  r600_pipe_shader_create(ctx, shader, state->tokens);
-       if (r) {
-               return NULL;
-       }
-       return shader;
-}
-
-static void r600_bind_ps_shader(struct pipe_context *ctx, void *state)
-{
-       struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx;
-
-       /* TODO delete old shader */
-       rctx->ps_shader = (struct r600_pipe_shader *)state;
-}
-
-static void r600_bind_vs_shader(struct pipe_context *ctx, void *state)
-{
-       struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx;
-
-       /* TODO delete old shader */
-       rctx->vs_shader = (struct r600_pipe_shader *)state;
-}
-
-static void r600_delete_ps_shader(struct pipe_context *ctx, void *state)
-{
-       struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx;
-       struct r600_pipe_shader *shader = (struct r600_pipe_shader *)state;
-
-       if (rctx->ps_shader == shader) {
-               rctx->ps_shader = NULL;
-       }
-       /* TODO proper delete */
-       free(shader);
-}
-
-static void r600_delete_vs_shader(struct pipe_context *ctx, void *state)
-{
-       struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx;
-       struct r600_pipe_shader *shader = (struct r600_pipe_shader *)state;
-
-       if (rctx->vs_shader == shader) {
-               rctx->vs_shader = NULL;
-       }
-       /* TODO proper delete */
-       free(shader);
-}
-
 void r600_init_state_functions(struct r600_pipe_context *rctx)
 {
        rctx->context.create_blend_state = r600_create_blend_state;