From 9b213c871a080472660eff271c72a3fcc5d3f578 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Christian=20K=C3=B6nig?= Date: Fri, 20 Jul 2012 11:46:01 +0200 Subject: [PATCH] radeonsi: move everything else into the new handling MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- src/gallium/drivers/radeonsi/Makefile.sources | 1 - .../drivers/radeonsi/evergreen_state.c | 98 --------- .../drivers/radeonsi/r600_state_common.c | 157 -------------- src/gallium/drivers/radeonsi/radeonsi_pipe.c | 2 +- src/gallium/drivers/radeonsi/radeonsi_pipe.h | 32 --- src/gallium/drivers/radeonsi/si_state.c | 197 ++++++++++++++++++ src/gallium/drivers/radeonsi/si_state.h | 1 + 7 files changed, 199 insertions(+), 289 deletions(-) delete mode 100644 src/gallium/drivers/radeonsi/evergreen_state.c diff --git a/src/gallium/drivers/radeonsi/Makefile.sources b/src/gallium/drivers/radeonsi/Makefile.sources index b5c193b6585..8e27b6c7050 100644 --- a/src/gallium/drivers/radeonsi/Makefile.sources +++ b/src/gallium/drivers/radeonsi/Makefile.sources @@ -8,7 +8,6 @@ C_SOURCES := \ radeonsi_shader.c \ r600_texture.c \ evergreen_hw_context.c \ - evergreen_state.c \ r600_translate.c \ r600_state_common.c \ radeonsi_pm4.c \ diff --git a/src/gallium/drivers/radeonsi/evergreen_state.c b/src/gallium/drivers/radeonsi/evergreen_state.c deleted file mode 100644 index f3627538c5f..00000000000 --- a/src/gallium/drivers/radeonsi/evergreen_state.c +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright 2010 Jerome Glisse - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * on the rights to use, copy, modify, merge, publish, distribute, sub - * license, and/or sell copies of the Software, and to permit persons to whom - * the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL - * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE - * USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -/* TODO: - * - fix mask for depth control & cull for query - */ -#include -#include -#include "pipe/p_defines.h" -#include "pipe/p_state.h" -#include "pipe/p_context.h" -#include "tgsi/tgsi_scan.h" -#include "tgsi/tgsi_parse.h" -#include "tgsi/tgsi_util.h" -#include "util/u_blitter.h" -#include "util/u_double_list.h" -#include "util/u_transfer.h" -#include "util/u_surface.h" -#include "util/u_pack_color.h" -#include "util/u_memory.h" -#include "util/u_inlines.h" -#include "util/u_framebuffer.h" -#include "pipebuffer/pb_buffer.h" -#include "r600.h" -#include "sid.h" -#include "r600_resource.h" -#include "radeonsi_pipe.h" -#include "si_state.h" - -#if 0 -static uint32_t r600_translate_stencil_op(int s_op) -{ - switch (s_op) { - case PIPE_STENCIL_OP_KEEP: - return V_028800_STENCIL_KEEP; - case PIPE_STENCIL_OP_ZERO: - return V_028800_STENCIL_ZERO; - case PIPE_STENCIL_OP_REPLACE: - return V_028800_STENCIL_REPLACE; - case PIPE_STENCIL_OP_INCR: - return V_028800_STENCIL_INCR; - case PIPE_STENCIL_OP_DECR: - return V_028800_STENCIL_DECR; - case PIPE_STENCIL_OP_INCR_WRAP: - return V_028800_STENCIL_INCR_WRAP; - case PIPE_STENCIL_OP_DECR_WRAP: - return V_028800_STENCIL_DECR_WRAP; - case PIPE_STENCIL_OP_INVERT: - return V_028800_STENCIL_INVERT; - default: - R600_ERR("Unknown stencil op %d", s_op); - assert(0); - break; - } - return 0; -} -#endif - -static void evergreen_set_polygon_stipple(struct pipe_context *ctx, - const struct pipe_poly_stipple *state) -{ -} - -void cayman_init_state_functions(struct r600_context *rctx) -{ - si_init_state_functions(rctx); - rctx->context.create_vertex_elements_state = si_create_vertex_elements; - rctx->context.bind_vertex_elements_state = r600_bind_vertex_elements; - rctx->context.delete_vertex_elements_state = r600_delete_vertex_element; - rctx->context.set_polygon_stipple = evergreen_set_polygon_stipple; - rctx->context.set_vertex_buffers = r600_set_vertex_buffers; - rctx->context.set_index_buffer = r600_set_index_buffer; - rctx->context.sampler_view_destroy = r600_sampler_view_destroy; - rctx->context.texture_barrier = r600_texture_barrier; - rctx->context.create_stream_output_target = r600_create_so_target; - rctx->context.stream_output_target_destroy = r600_so_target_destroy; - rctx->context.set_stream_output_targets = r600_set_so_targets; -} diff --git a/src/gallium/drivers/radeonsi/r600_state_common.c b/src/gallium/drivers/radeonsi/r600_state_common.c index d54ffc56f09..04a592f29ed 100644 --- a/src/gallium/drivers/radeonsi/r600_state_common.c +++ b/src/gallium/drivers/radeonsi/r600_state_common.c @@ -84,163 +84,6 @@ unsigned r600_get_cb_flush_flags(struct r600_context *rctx) return flags; } -void r600_texture_barrier(struct pipe_context *ctx) -{ - struct r600_context *rctx = (struct r600_context *)ctx; - - rctx->atom_surface_sync.flush_flags |= S_0085F0_TC_ACTION_ENA(1) | r600_get_cb_flush_flags(rctx); - r600_atom_dirty(rctx, &rctx->atom_surface_sync.atom); -} - -/* common state between evergreen and r600 */ -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); -} - -void r600_delete_state(struct pipe_context *ctx, void *state) -{ - struct r600_context *rctx = (struct r600_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++) { - pipe_resource_reference((struct pipe_resource**)&rstate->regs[i].bo, NULL); - } - free(rstate); -} - -void r600_bind_vertex_elements(struct pipe_context *ctx, void *state) -{ - struct r600_context *rctx = (struct r600_context *)ctx; - struct si_vertex_element *v = (struct r600_vertex_element*)state; - - rctx->vertex_elements = v; - if (v) { - r600_inval_shader_cache(rctx); - } -} - -void r600_delete_vertex_element(struct pipe_context *ctx, void *state) -{ - struct r600_context *rctx = (struct r600_context *)ctx; - struct r600_vertex_element *v = (struct r600_vertex_element*)state; - - if (rctx->vertex_elements == state) - rctx->vertex_elements = NULL; - FREE(state); -} - - -void r600_set_index_buffer(struct pipe_context *ctx, - const struct pipe_index_buffer *ib) -{ - struct r600_context *rctx = (struct r600_context *)ctx; - - if (ib) { - pipe_resource_reference(&rctx->index_buffer.buffer, ib->buffer); - memcpy(&rctx->index_buffer, ib, sizeof(*ib)); - } else { - pipe_resource_reference(&rctx->index_buffer.buffer, NULL); - } -} - -void r600_set_vertex_buffers(struct pipe_context *ctx, unsigned count, - const struct pipe_vertex_buffer *buffers) -{ - struct r600_context *rctx = (struct r600_context *)ctx; - - util_copy_vertex_buffers(rctx->vertex_buffer, &rctx->nr_vertex_buffers, buffers, count); -} - -void *si_create_vertex_elements(struct pipe_context *ctx, - unsigned count, - const struct pipe_vertex_element *elements) -{ - struct r600_context *rctx = (struct r600_context *)ctx; - struct si_vertex_element *v = CALLOC_STRUCT(si_vertex_element); - - assert(count < 32); - if (!v) - return NULL; - - v->count = count; - memcpy(v->elements, elements, sizeof(struct pipe_vertex_element) * count); - - return v; -} - -struct pipe_stream_output_target * -r600_create_so_target(struct pipe_context *ctx, - struct pipe_resource *buffer, - unsigned buffer_offset, - unsigned buffer_size) -{ - struct r600_context *rctx = (struct r600_context *)ctx; - struct r600_so_target *t; - void *ptr; - - t = CALLOC_STRUCT(r600_so_target); - if (!t) { - return NULL; - } - - t->b.reference.count = 1; - t->b.context = ctx; - pipe_resource_reference(&t->b.buffer, buffer); - t->b.buffer_offset = buffer_offset; - t->b.buffer_size = buffer_size; - - t->filled_size = (struct r600_resource*) - pipe_buffer_create(ctx->screen, PIPE_BIND_CUSTOM, PIPE_USAGE_STATIC, 4); - ptr = rctx->ws->buffer_map(t->filled_size->cs_buf, rctx->cs, PIPE_TRANSFER_WRITE); - memset(ptr, 0, t->filled_size->buf->size); - rctx->ws->buffer_unmap(t->filled_size->cs_buf); - - return &t->b; -} - -void r600_so_target_destroy(struct pipe_context *ctx, - struct pipe_stream_output_target *target) -{ - struct r600_so_target *t = (struct r600_so_target*)target; - pipe_resource_reference(&t->b.buffer, NULL); - pipe_resource_reference((struct pipe_resource**)&t->filled_size, NULL); - FREE(t); -} - -void r600_set_so_targets(struct pipe_context *ctx, - unsigned num_targets, - struct pipe_stream_output_target **targets, - unsigned append_bitmask) -{ - struct r600_context *rctx = (struct r600_context *)ctx; - unsigned i; - - /* Stop streamout. */ - if (rctx->num_so_targets) { - r600_context_streamout_end(rctx); - } - - /* Set the new targets. */ - for (i = 0; i < num_targets; i++) { - pipe_so_target_reference((struct pipe_stream_output_target**)&rctx->so_targets[i], targets[i]); - } - for (; i < rctx->num_so_targets; i++) { - pipe_so_target_reference((struct pipe_stream_output_target**)&rctx->so_targets[i], NULL); - } - - rctx->num_so_targets = num_targets; - rctx->streamout_start = num_targets != 0; - rctx->streamout_append_bitmask = append_bitmask; -} - void _r600_pipe_state_add_reg(struct r600_context *ctx, struct r600_pipe_state *state, uint32_t offset, uint32_t value, diff --git a/src/gallium/drivers/radeonsi/radeonsi_pipe.c b/src/gallium/drivers/radeonsi/radeonsi_pipe.c index e13d9bd69ed..d3547467ef9 100644 --- a/src/gallium/drivers/radeonsi/radeonsi_pipe.c +++ b/src/gallium/drivers/radeonsi/radeonsi_pipe.c @@ -221,7 +221,7 @@ static struct pipe_context *r600_create_context(struct pipe_screen *screen, void switch (rctx->chip_class) { case TAHITI: - cayman_init_state_functions(rctx); + si_init_state_functions(rctx); if (si_context_init(rctx)) { r600_destroy_context(&rctx->context); return NULL; diff --git a/src/gallium/drivers/radeonsi/radeonsi_pipe.h b/src/gallium/drivers/radeonsi/radeonsi_pipe.h index 0521c9b31be..ff68b50fe81 100644 --- a/src/gallium/drivers/radeonsi/radeonsi_pipe.h +++ b/src/gallium/drivers/radeonsi/radeonsi_pipe.h @@ -250,9 +250,6 @@ static INLINE void r600_atom_dirty(struct r600_context *rctx, struct r600_atom * } } -/* evergreen_state.c */ -void cayman_init_state_functions(struct r600_context *rctx); - /* r600_blit.c */ void r600_init_blit_functions(struct r600_context *rctx); void r600_blit_uncompress_depth(struct pipe_context *ctx, struct r600_resource_texture *texture); @@ -298,35 +295,6 @@ void r600_translate_index_buffer(struct r600_context *r600, /* r600_state_common.c */ void r600_init_common_atoms(struct r600_context *rctx); unsigned r600_get_cb_flush_flags(struct r600_context *rctx); -void r600_texture_barrier(struct pipe_context *ctx); -void r600_set_index_buffer(struct pipe_context *ctx, - const struct pipe_index_buffer *ib); -void r600_set_vertex_buffers(struct pipe_context *ctx, unsigned count, - const struct pipe_vertex_buffer *buffers); -void *si_create_vertex_elements(struct pipe_context *ctx, - unsigned count, - const struct pipe_vertex_element *elements); -void r600_delete_vertex_element(struct pipe_context *ctx, void *state); -void r600_bind_dsa_state(struct pipe_context *ctx, void *state); -void r600_sampler_view_destroy(struct pipe_context *ctx, - struct pipe_sampler_view *state); -void r600_delete_state(struct pipe_context *ctx, void *state); -void r600_bind_vertex_elements(struct pipe_context *ctx, void *state); -void r600_bind_ps_shader(struct pipe_context *ctx, void *state); -void r600_bind_vs_shader(struct pipe_context *ctx, void *state); -void r600_delete_ps_shader(struct pipe_context *ctx, void *state); -void r600_delete_vs_shader(struct pipe_context *ctx, void *state); -struct pipe_stream_output_target * -r600_create_so_target(struct pipe_context *ctx, - struct pipe_resource *buffer, - unsigned buffer_offset, - unsigned buffer_size); -void r600_so_target_destroy(struct pipe_context *ctx, - struct pipe_stream_output_target *target); -void r600_set_so_targets(struct pipe_context *ctx, - unsigned num_targets, - struct pipe_stream_output_target **targets, - unsigned append_bitmask); /* * common helpers diff --git a/src/gallium/drivers/radeonsi/si_state.c b/src/gallium/drivers/radeonsi/si_state.c index 978c1948c18..79665d68845 100644 --- a/src/gallium/drivers/radeonsi/si_state.c +++ b/src/gallium/drivers/radeonsi/si_state.c @@ -1839,6 +1839,15 @@ static struct pipe_sampler_view *si_create_sampler_view(struct pipe_context *ctx return &view->base; } +static void si_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 void *si_create_sampler_state(struct pipe_context *ctx, const struct pipe_sampler_state *state) { @@ -2062,6 +2071,180 @@ static void si_set_constant_buffer(struct pipe_context *ctx, uint shader, uint i pipe_resource_reference((struct pipe_resource**)&rbuffer, NULL); } +/* + * Vertex elements & buffers + */ + +static void *si_create_vertex_elements(struct pipe_context *ctx, + unsigned count, + const struct pipe_vertex_element *elements) +{ + struct si_vertex_element *v = CALLOC_STRUCT(si_vertex_element); + + assert(count < 32); + if (!v) + return NULL; + + v->count = count; + memcpy(v->elements, elements, sizeof(struct pipe_vertex_element) * count); + + return v; +} + +static void si_bind_vertex_elements(struct pipe_context *ctx, void *state) +{ + struct r600_context *rctx = (struct r600_context *)ctx; + struct si_vertex_element *v = (struct si_vertex_element*)state; + + rctx->vertex_elements = v; +} + +static void si_delete_vertex_element(struct pipe_context *ctx, void *state) +{ + struct r600_context *rctx = (struct r600_context *)ctx; + + if (rctx->vertex_elements == state) + rctx->vertex_elements = NULL; + FREE(state); +} + +static void si_set_vertex_buffers(struct pipe_context *ctx, unsigned count, + const struct pipe_vertex_buffer *buffers) +{ + struct r600_context *rctx = (struct r600_context *)ctx; + + util_copy_vertex_buffers(rctx->vertex_buffer, &rctx->nr_vertex_buffers, buffers, count); +} + +static void si_set_index_buffer(struct pipe_context *ctx, + const struct pipe_index_buffer *ib) +{ + struct r600_context *rctx = (struct r600_context *)ctx; + + if (ib) { + pipe_resource_reference(&rctx->index_buffer.buffer, ib->buffer); + memcpy(&rctx->index_buffer, ib, sizeof(*ib)); + } else { + pipe_resource_reference(&rctx->index_buffer.buffer, NULL); + } +} + +/* + * Stream out + */ + +static struct pipe_stream_output_target * +si_create_so_target(struct pipe_context *ctx, + struct pipe_resource *buffer, + unsigned buffer_offset, + unsigned buffer_size) +{ + struct r600_context *rctx = (struct r600_context *)ctx; + struct r600_so_target *t; + void *ptr; + + t = CALLOC_STRUCT(r600_so_target); + if (!t) { + return NULL; + } + + t->b.reference.count = 1; + t->b.context = ctx; + pipe_resource_reference(&t->b.buffer, buffer); + t->b.buffer_offset = buffer_offset; + t->b.buffer_size = buffer_size; + + t->filled_size = (struct r600_resource*) + pipe_buffer_create(ctx->screen, PIPE_BIND_CUSTOM, PIPE_USAGE_STATIC, 4); + ptr = rctx->ws->buffer_map(t->filled_size->cs_buf, rctx->cs, PIPE_TRANSFER_WRITE); + memset(ptr, 0, t->filled_size->buf->size); + rctx->ws->buffer_unmap(t->filled_size->cs_buf); + + return &t->b; +} + +static void si_so_target_destroy(struct pipe_context *ctx, + struct pipe_stream_output_target *target) +{ + struct r600_so_target *t = (struct r600_so_target*)target; + pipe_resource_reference(&t->b.buffer, NULL); + pipe_resource_reference((struct pipe_resource**)&t->filled_size, NULL); + FREE(t); +} + +static void si_set_so_targets(struct pipe_context *ctx, + unsigned num_targets, + struct pipe_stream_output_target **targets, + unsigned append_bitmask) +{ + struct r600_context *rctx = (struct r600_context *)ctx; + unsigned i; + + /* Stop streamout. */ + if (rctx->num_so_targets) { + r600_context_streamout_end(rctx); + } + + /* Set the new targets. */ + for (i = 0; i < num_targets; i++) { + pipe_so_target_reference((struct pipe_stream_output_target**)&rctx->so_targets[i], targets[i]); + } + for (; i < rctx->num_so_targets; i++) { + pipe_so_target_reference((struct pipe_stream_output_target**)&rctx->so_targets[i], NULL); + } + + rctx->num_so_targets = num_targets; + rctx->streamout_start = num_targets != 0; + rctx->streamout_append_bitmask = append_bitmask; +} + +/* + * Misc + */ +#if 0 +static uint32_t r600_translate_stencil_op(int s_op) +{ + switch (s_op) { + case PIPE_STENCIL_OP_KEEP: + return V_028800_STENCIL_KEEP; + case PIPE_STENCIL_OP_ZERO: + return V_028800_STENCIL_ZERO; + case PIPE_STENCIL_OP_REPLACE: + return V_028800_STENCIL_REPLACE; + case PIPE_STENCIL_OP_INCR: + return V_028800_STENCIL_INCR; + case PIPE_STENCIL_OP_DECR: + return V_028800_STENCIL_DECR; + case PIPE_STENCIL_OP_INCR_WRAP: + return V_028800_STENCIL_INCR_WRAP; + case PIPE_STENCIL_OP_DECR_WRAP: + return V_028800_STENCIL_DECR_WRAP; + case PIPE_STENCIL_OP_INVERT: + return V_028800_STENCIL_INVERT; + default: + R600_ERR("Unknown stencil op %d", s_op); + assert(0); + break; + } + return 0; +} +#endif + +static void si_set_polygon_stipple(struct pipe_context *ctx, + const struct pipe_poly_stipple *state) +{ +} + +static void si_texture_barrier(struct pipe_context *ctx) +{ + struct r600_context *rctx = (struct r600_context *)ctx; + struct si_pm4_state *pm4 = CALLOC_STRUCT(si_pm4_state); + + si_pm4_inval_texture_cache(pm4); + si_pm4_inval_fb_cache(pm4, rctx->framebuffer.nr_cbufs); + si_pm4_set_state(rctx, texture_barrier, pm4); +} + void si_init_state_functions(struct r600_context *rctx) { rctx->context.create_blend_state = si_create_blend_state; @@ -2100,11 +2283,25 @@ void si_init_state_functions(struct r600_context *rctx) rctx->context.create_sampler_view = si_create_sampler_view; rctx->context.set_vertex_sampler_views = si_set_vs_sampler_view; rctx->context.set_fragment_sampler_views = si_set_ps_sampler_view; + rctx->context.sampler_view_destroy = si_sampler_view_destroy; rctx->context.set_sample_mask = si_set_sample_mask; rctx->context.set_constant_buffer = si_set_constant_buffer; + rctx->context.create_vertex_elements_state = si_create_vertex_elements; + rctx->context.bind_vertex_elements_state = si_bind_vertex_elements; + rctx->context.delete_vertex_elements_state = si_delete_vertex_element; + rctx->context.set_vertex_buffers = si_set_vertex_buffers; + rctx->context.set_index_buffer = si_set_index_buffer; + + rctx->context.create_stream_output_target = si_create_so_target; + rctx->context.stream_output_target_destroy = si_so_target_destroy; + rctx->context.set_stream_output_targets = si_set_so_targets; + + rctx->context.texture_barrier = si_texture_barrier; + rctx->context.set_polygon_stipple = si_set_polygon_stipple; + rctx->context.draw_vbo = si_draw_vbo; } diff --git a/src/gallium/drivers/radeonsi/si_state.h b/src/gallium/drivers/radeonsi/si_state.h index e94797c63bc..771de125e93 100644 --- a/src/gallium/drivers/radeonsi/si_state.h +++ b/src/gallium/drivers/radeonsi/si_state.h @@ -123,6 +123,7 @@ union si_state { struct si_pm4_state *ps_const; struct si_pm4_state *spi; struct si_pm4_state *vertex_buffers; + struct si_pm4_state *texture_barrier; struct si_pm4_state *draw_info; } named; struct si_pm4_state *array[0]; -- 2.30.2