r600g: only set depth bit for hw accessible depth buffers.
[mesa.git] / src / gallium / drivers / r600 / evergreen_state.c
index 08f9f753afe69e44dbce0a9161acf4c3f50c6281..c64b93bd4fcfdf5c0b1bcfd836c85b6ed44ed49e 100644 (file)
@@ -103,7 +103,7 @@ static void *evergreen_create_blend_state(struct pipe_context *ctx,
        }
        blend->cb_target_mask = target_mask;
        r600_pipe_state_add_reg(rstate, R_028808_CB_COLOR_CONTROL,
-                               color_control, 0xFFFFFFFF, NULL);
+                               color_control, 0xFFFFFFFD, NULL);
        r600_pipe_state_add_reg(rstate, R_028C3C_PA_SC_AA_MASK, 0xFFFFFFFF, 0xFFFFFFFF, NULL);
 
        for (int i = 0; i < 8; i++) {
@@ -351,7 +351,7 @@ static struct pipe_sampler_view *evergreen_create_sampler_view(struct pipe_conte
        struct r600_resource *rbuffer;
        unsigned format;
        uint32_t word4 = 0, yuv_format = 0, pitch = 0;
-       unsigned char swizzle[4];
+       unsigned char swizzle[4], array_mode = 0, tile_type = 0;
        struct r600_bo *bo[2];
 
        if (resource == NULL)
@@ -380,28 +380,31 @@ static struct pipe_sampler_view *evergreen_create_sampler_view(struct pipe_conte
        if (desc == NULL) {
                R600_ERR("unknow format %d\n", state->format);
        }
-       tmp = (struct r600_resource_texture*)texture;
+       tmp = (struct r600_resource_texture *)texture;
+       if (tmp->depth && tmp->tile_type == 1) {
+               r600_texture_depth_flush(ctx, texture);
+               tmp = tmp->flushed_depth_texture;
+       }
        rbuffer = &tmp->resource;
        bo[0] = rbuffer->bo;
        bo[1] = rbuffer->bo;
-       /* FIXME depth texture decompression */
-       if (tmp->depth) {
-               r600_texture_depth_flush(ctx, texture);
-               tmp = (struct r600_resource_texture*)texture;
-               rbuffer = &tmp->flushed_depth_texture->resource;
-               bo[0] = rbuffer->bo;
-               bo[1] = rbuffer->bo;
-       }
+
        pitch = align(tmp->pitch_in_pixels[0], 8);
+       if (tmp->tiled) {
+               array_mode = tmp->array_mode[0];
+               tile_type = tmp->tile_type;
+       }
 
        /* FIXME properly handle first level != 0 */
        r600_pipe_state_add_reg(rstate, R_030000_RESOURCE0_WORD0,
                                S_030000_DIM(r600_tex_dim(texture->target)) |
                                S_030000_PITCH((pitch / 8) - 1) |
+                               S_030000_NON_DISP_TILING_ORDER(tile_type) |
                                S_030000_TEX_WIDTH(texture->width0 - 1), 0xFFFFFFFF, NULL);
        r600_pipe_state_add_reg(rstate, R_030004_RESOURCE0_WORD1,
                                S_030004_TEX_HEIGHT(texture->height0 - 1) |
-                               S_030004_TEX_DEPTH(texture->depth0 - 1),
+                               S_030004_TEX_DEPTH(texture->depth0 - 1) |
+                               S_030004_ARRAY_MODE(array_mode),
                                0xFFFFFFFF, NULL);
        r600_pipe_state_add_reg(rstate, R_030008_RESOURCE0_WORD2,
                                (tmp->offset[0] + r600_bo_offset(bo[0])) >> 8, 0xFFFFFFFF, bo[0]);
@@ -638,6 +641,7 @@ static void evergreen_cb(struct r600_pipe_context *rctx, struct r600_pipe_state
        unsigned color_info;
        unsigned format, swap, ntype;
        unsigned offset;
+       unsigned tile_type;
        const struct util_format_description *desc;
        struct r600_bo *bo[3];
 
@@ -662,11 +666,17 @@ static void evergreen_cb(struct r600_pipe_context *rctx, struct r600_pipe_state
        swap = r600_translate_colorswap(rtex->resource.base.b.format);
        color_info = S_028C70_FORMAT(format) |
                S_028C70_COMP_SWAP(swap) |
+               S_028C70_ARRAY_MODE(rtex->array_mode[level]) |
                S_028C70_BLEND_CLAMP(1) |
                S_028C70_NUMBER_TYPE(ntype);
        if (desc->colorspace != UTIL_FORMAT_COLORSPACE_ZS)
                color_info |= S_028C70_SOURCE_FORMAT(1);
 
+       if (rtex->tiled) {
+               tile_type = rtex->tile_type;
+       } else /* workaround for linear buffers */
+               tile_type = 1;
+
        /* FIXME handle enabling of CB beyond BASE8 which has different offset */
        r600_pipe_state_add_reg(rstate,
                                R_028C60_CB_COLOR0_BASE + cb * 0x3C,
@@ -690,7 +700,7 @@ static void evergreen_cb(struct r600_pipe_context *rctx, struct r600_pipe_state
                                0x00000000, 0xFFFFFFFF, NULL);
        r600_pipe_state_add_reg(rstate,
                                R_028C74_CB_COLOR0_ATTRIB + cb * 0x3C,
-                               S_028C74_NON_DISP_TILING_ORDER(1),
+                               S_028C74_NON_DISP_TILING_ORDER(tile_type),
                                0xFFFFFFFF, bo[0]);
 }
 
@@ -711,10 +721,7 @@ static void evergreen_db(struct r600_pipe_context *rctx, struct r600_pipe_state
 
        surf = (struct r600_surface *)state->zsbuf;
        rtex = (struct r600_resource_texture*)state->zsbuf->texture;
-       rtex->tiled = 1;
-       rtex->array_mode[level] = 2;
        rtex->tile_type = 1;
-       rtex->depth = 1;
        rbuffer = &rtex->resource;
 
        /* XXX quite sure for dx10+ hw don't need any offset hacks */
@@ -837,54 +844,6 @@ static void evergreen_set_framebuffer_state(struct pipe_context *ctx,
        }
 }
 
-static void evergreen_set_constant_buffer(struct pipe_context *ctx, uint shader, uint index,
-                                       struct pipe_resource *buffer)
-{
-       struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx;
-       struct r600_resource_buffer *rbuffer = r600_buffer(buffer);
-       uint32_t offset;
-
-       /* Note that the state tracker can unbind constant buffers by
-        * passing NULL here.
-        */
-       if (buffer == NULL) {
-               return;
-       }
-
-       r600_upload_const_buffer(rctx, &rbuffer, &offset);
-
-       switch (shader) {
-       case PIPE_SHADER_VERTEX:
-               rctx->vs_const_buffer.nregs = 0;
-               r600_pipe_state_add_reg(&rctx->vs_const_buffer,
-                                       R_028180_ALU_CONST_BUFFER_SIZE_VS_0,
-                                       ALIGN_DIVUP(buffer->width0 >> 4, 16),
-                                       0xFFFFFFFF, NULL);
-               r600_pipe_state_add_reg(&rctx->vs_const_buffer,
-                                       R_028980_ALU_CONST_CACHE_VS_0,
-                                       (r600_bo_offset(rbuffer->r.bo) + offset) >> 8, 0xFFFFFFFF, rbuffer->r.bo);
-               r600_context_pipe_state_set(&rctx->ctx, &rctx->vs_const_buffer);
-               break;
-       case PIPE_SHADER_FRAGMENT:
-               rctx->ps_const_buffer.nregs = 0;
-               r600_pipe_state_add_reg(&rctx->ps_const_buffer,
-                                       R_028140_ALU_CONST_BUFFER_SIZE_PS_0,
-                                       ALIGN_DIVUP(buffer->width0 >> 4, 16),
-                                       0xFFFFFFFF, NULL);
-               r600_pipe_state_add_reg(&rctx->ps_const_buffer,
-                                       R_028940_ALU_CONST_CACHE_PS_0,
-                                       (r600_bo_offset(rbuffer->r.bo) + offset) >> 8, 0xFFFFFFFF, rbuffer->r.bo);
-               r600_context_pipe_state_set(&rctx->ctx, &rctx->ps_const_buffer);
-               break;
-       default:
-               R600_ERR("unsupported %d\n", shader);
-               return;
-       }
-
-       if (!rbuffer->user_buffer)
-               pipe_resource_reference((struct pipe_resource**)&rbuffer, NULL);
-}
-
 void evergreen_init_state_functions(struct r600_pipe_context *rctx)
 {
        rctx->context.create_blend_state = evergreen_create_blend_state;
@@ -912,7 +871,7 @@ void evergreen_init_state_functions(struct r600_pipe_context *rctx)
        rctx->context.delete_vs_state = r600_delete_vs_shader;
        rctx->context.set_blend_color = evergreen_set_blend_color;
        rctx->context.set_clip_state = evergreen_set_clip_state;
-       rctx->context.set_constant_buffer = evergreen_set_constant_buffer;
+       rctx->context.set_constant_buffer = r600_set_constant_buffer;
        rctx->context.set_fragment_sampler_views = evergreen_set_ps_sampler_view;
        rctx->context.set_framebuffer_state = evergreen_set_framebuffer_state;
        rctx->context.set_polygon_stipple = evergreen_set_polygon_stipple;