r600g,radeonsi: consolidate create_surface and surface_destroy
[mesa.git] / src / gallium / drivers / r600 / r600_state_common.c
index d1410260cc50c0ae6839087ee78d85e33291f656..1ca2c90794aa9e3a6670e3c5eb59ea05749f3b70 100644 (file)
@@ -334,9 +334,9 @@ static void r600_bind_rs_state(struct pipe_context *ctx, void *state)
 
        /* Workaround for a missing scissor enable on r600. */
        if (rctx->b.chip_class == R600 &&
-           rs->scissor_enable != rctx->scissor.enable) {
-               rctx->scissor.enable = rs->scissor_enable;
-               rctx->scissor.atom.dirty = true;
+           rs->scissor_enable != rctx->scissor[0].enable) {
+               rctx->scissor[0].enable = rs->scissor_enable;
+               rctx->scissor[0].atom.dirty = true;
        }
 
        /* Re-emit PA_SC_LINE_STIPPLE. */
@@ -657,17 +657,22 @@ static void r600_set_viewport_states(struct pipe_context *ctx,
                                      const struct pipe_viewport_state *state)
 {
        struct r600_context *rctx = (struct r600_context *)ctx;
+       int i;
 
-       rctx->viewport.state = *state;
-       rctx->viewport.atom.dirty = true;
+       for (i = start_slot; i < start_slot + num_viewports; i++) {
+               rctx->viewport[i].state = state[i - start_slot];
+               rctx->viewport[i].atom.dirty = true;
+       }
 }
 
 void r600_emit_viewport_state(struct r600_context *rctx, struct r600_atom *atom)
 {
        struct radeon_winsys_cs *cs = rctx->b.rings.gfx.cs;
-       struct pipe_viewport_state *state = &rctx->viewport.state;
+       struct r600_viewport_state *rstate = (struct r600_viewport_state *)atom;
+       struct pipe_viewport_state *state = &rstate->state;
+       int offset = rstate->idx * 6 * 4;
 
-       r600_write_context_reg_seq(cs, R_02843C_PA_CL_VPORT_XSCALE_0, 6);
+       r600_write_context_reg_seq(cs, R_02843C_PA_CL_VPORT_XSCALE_0 + offset, 6);
        radeon_emit(cs, fui(state->scale[0]));     /* R_02843C_PA_CL_VPORT_XSCALE_0  */
        radeon_emit(cs, fui(state->translate[0])); /* R_028440_PA_CL_VPORT_XOFFSET_0 */
        radeon_emit(cs, fui(state->scale[1]));     /* R_028444_PA_CL_VPORT_YSCALE_0  */
@@ -931,7 +936,7 @@ static void r600_set_constant_buffer(struct pipe_context *ctx, uint shader, uint
                        }
 
                        for (i = 0; i < size / 4; ++i) {
-                               tmpPtr[i] = util_bswap32(((uint32_t *)ptr)[i]);
+                               tmpPtr[i] = util_cpu_to_le32(((uint32_t *)ptr)[i]);
                        }
 
                        u_upload_data(rctx->b.uploader, 0, size, tmpPtr, &cb->buffer_offset, &cb->buffer);
@@ -1109,14 +1114,14 @@ static void update_gs_block_state(struct r600_context *rctx, unsigned enable)
                        unsigned size = 0x1C000;
                        rctx->gs_rings.esgs_ring.buffer =
                                        pipe_buffer_create(rctx->b.b.screen, PIPE_BIND_CUSTOM,
-                                                       PIPE_USAGE_STATIC, size);
+                                                       PIPE_USAGE_DEFAULT, size);
                        rctx->gs_rings.esgs_ring.buffer_size = size;
 
                        size = 0x4000000;
 
                        rctx->gs_rings.gsvs_ring.buffer =
                                        pipe_buffer_create(rctx->b.b.screen, PIPE_BIND_CUSTOM,
-                                                       PIPE_USAGE_STATIC, size);
+                                                       PIPE_USAGE_DEFAULT, size);
                        rctx->gs_rings.gsvs_ring.buffer_size = size;
                }
 
@@ -1722,48 +1727,6 @@ void r600_emit_shader(struct r600_context *rctx, struct r600_atom *a)
        radeon_emit(cs, r600_context_bo_reloc(&rctx->b, &rctx->b.rings.gfx, shader->bo, RADEON_USAGE_READ));
 }
 
-struct pipe_surface *r600_create_surface_custom(struct pipe_context *pipe,
-                                               struct pipe_resource *texture,
-                                               const struct pipe_surface *templ,
-                                               unsigned width, unsigned height)
-{
-       struct r600_surface *surface = CALLOC_STRUCT(r600_surface);
-
-        assert(templ->u.tex.first_layer <= util_max_layer(texture, templ->u.tex.level));
-        assert(templ->u.tex.last_layer <= util_max_layer(texture, templ->u.tex.level));
-       if (surface == NULL)
-               return NULL;
-       pipe_reference_init(&surface->base.reference, 1);
-       pipe_resource_reference(&surface->base.texture, texture);
-       surface->base.context = pipe;
-       surface->base.format = templ->format;
-       surface->base.width = width;
-       surface->base.height = height;
-       surface->base.u = templ->u;
-       return &surface->base;
-}
-
-static struct pipe_surface *r600_create_surface(struct pipe_context *pipe,
-                                               struct pipe_resource *tex,
-                                               const struct pipe_surface *templ)
-{
-       unsigned level = templ->u.tex.level;
-
-       return r600_create_surface_custom(pipe, tex, templ,
-                                          u_minify(tex->width0, level),
-                                         u_minify(tex->height0, level));
-}
-
-static void r600_surface_destroy(struct pipe_context *pipe,
-                                struct pipe_surface *surface)
-{
-       struct r600_surface *surf = (struct r600_surface*)surface;
-       pipe_resource_reference((struct pipe_resource**)&surf->cb_buffer_fmask, NULL);
-       pipe_resource_reference((struct pipe_resource**)&surf->cb_buffer_cmask, NULL);
-       pipe_resource_reference(&surface->texture, NULL);
-       FREE(surface);
-}
-
 unsigned r600_get_swizzle_combined(const unsigned char *swizzle_format,
                                   const unsigned char *swizzle_view,
                                   boolean vtx)
@@ -2179,8 +2142,8 @@ static void r600_invalidate_buffer(struct pipe_context *ctx, struct pipe_resourc
        pb_reference(&rbuffer->buf, NULL);
 
        /* Create a new one in the same pipe_resource. */
-       r600_init_resource(&rctx->screen->b, rbuffer, rbuffer->b.b.width0, alignment,
-                          TRUE, rbuffer->b.b.usage);
+       r600_init_resource(&rctx->screen->b, rbuffer, rbuffer->b.b.width0,
+                          alignment, TRUE);
 
        /* We changed the buffer, now we need to bind it where the old one was bound. */
        /* Vertex buffers. */
@@ -2275,8 +2238,6 @@ void r600_init_common_state_functions(struct r600_context *rctx)
        rctx->b.b.sampler_view_destroy = r600_sampler_view_destroy;
        rctx->b.b.texture_barrier = r600_texture_barrier;
        rctx->b.b.set_stream_output_targets = r600_set_streamout_targets;
-       rctx->b.b.create_surface = r600_create_surface;
-       rctx->b.b.surface_destroy = r600_surface_destroy;
        rctx->b.b.draw_vbo = r600_draw_vbo;
        rctx->b.invalidate_buffer = r600_invalidate_buffer;
        rctx->b.set_occlusion_query_state = r600_set_occlusion_query_state;