summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian König <deathsimple@vodafone.de>2012-07-17 14:09:03 +0200
committerChristian König <deathsimple@vodafone.de>2012-07-24 12:29:29 +0200
commitbf7302a6e1f3aed4518498e90e8261a2b1f6afd7 (patch)
treec5c2f8c204eef583c4b27d722097700a6e95dfab
parent27382c0f7ba2ae826531ba4c254741b2a9df1882 (diff)
radeonsi: rework state handling v2
Add a complete new state handling for SI. v2: fix spelling error Signed-off-by: Christian König <deathsimple@vodafone.de>
-rw-r--r--src/gallium/drivers/radeonsi/Makefile.sources4
-rw-r--r--src/gallium/drivers/radeonsi/r600_hw_context.c2
-rw-r--r--src/gallium/drivers/radeonsi/r600_state_common.c3
-rw-r--r--src/gallium/drivers/radeonsi/radeonsi_pipe.h6
-rw-r--r--src/gallium/drivers/radeonsi/radeonsi_pm4.c175
-rw-r--r--src/gallium/drivers/radeonsi/radeonsi_pm4.h76
-rw-r--r--src/gallium/drivers/radeonsi/si_state.c28
-rw-r--r--src/gallium/drivers/radeonsi/si_state.h65
8 files changed, 358 insertions, 1 deletions
diff --git a/src/gallium/drivers/radeonsi/Makefile.sources b/src/gallium/drivers/radeonsi/Makefile.sources
index 394cfe93e07..8aeea8d574f 100644
--- a/src/gallium/drivers/radeonsi/Makefile.sources
+++ b/src/gallium/drivers/radeonsi/Makefile.sources
@@ -10,4 +10,6 @@ C_SOURCES := \
10 evergreen_hw_context.c \ 10 evergreen_hw_context.c \
11 evergreen_state.c \ 11 evergreen_state.c \
12 r600_translate.c \ 12 r600_translate.c \
13 r600_state_common.c 13 r600_state_common.c \
14 radeonsi_pm4.c \
15 si_state.c
diff --git a/src/gallium/drivers/radeonsi/r600_hw_context.c b/src/gallium/drivers/radeonsi/r600_hw_context.c
index 9422adc2e42..858bd16fdda 100644
--- a/src/gallium/drivers/radeonsi/r600_hw_context.c
+++ b/src/gallium/drivers/radeonsi/r600_hw_context.c
@@ -24,6 +24,7 @@
24 * Jerome Glisse 24 * Jerome Glisse
25 */ 25 */
26#include "r600_hw_context_priv.h" 26#include "r600_hw_context_priv.h"
27#include "radeonsi_pm4.h"
27#include "radeonsi_pipe.h" 28#include "radeonsi_pipe.h"
28#include "sid.h" 29#include "sid.h"
29#include "util/u_memory.h" 30#include "util/u_memory.h"
@@ -563,6 +564,7 @@ void r600_context_flush(struct r600_context *ctx, unsigned flags)
563 ctx->pm4_dirty_cdwords += enable_block->pm4_ndwords; 564 ctx->pm4_dirty_cdwords += enable_block->pm4_ndwords;
564 enable_block->nreg_dirty = enable_block->nreg; 565 enable_block->nreg_dirty = enable_block->nreg;
565 } 566 }
567 si_pm4_reset_emitted(ctx);
566} 568}
567 569
568void r600_context_emit_fence(struct r600_context *ctx, struct r600_resource *fence_bo, unsigned offset, unsigned value) 570void r600_context_emit_fence(struct r600_context *ctx, struct r600_resource *fence_bo, unsigned offset, unsigned value)
diff --git a/src/gallium/drivers/radeonsi/r600_state_common.c b/src/gallium/drivers/radeonsi/r600_state_common.c
index b63027e9c38..18ba7a8e2b6 100644
--- a/src/gallium/drivers/radeonsi/r600_state_common.c
+++ b/src/gallium/drivers/radeonsi/r600_state_common.c
@@ -801,6 +801,8 @@ void r600_draw_vbo(struct pipe_context *ctx, const struct pipe_draw_info *dinfo)
801 rdraw.db_render_control = dsa->db_render_control; 801 rdraw.db_render_control = dsa->db_render_control;
802 802
803 /* Emit states. */ 803 /* Emit states. */
804 rctx->pm4_dirty_cdwords += si_pm4_dirty_dw(rctx);
805
804 r600_need_cs_space(rctx, 0, TRUE); 806 r600_need_cs_space(rctx, 0, TRUE);
805 807
806 LIST_FOR_EACH_ENTRY_SAFE(state, next_state, &rctx->dirty_states, head) { 808 LIST_FOR_EACH_ENTRY_SAFE(state, next_state, &rctx->dirty_states, head) {
@@ -809,6 +811,7 @@ void r600_draw_vbo(struct pipe_context *ctx, const struct pipe_draw_info *dinfo)
809 LIST_FOR_EACH_ENTRY_SAFE(dirty_block, next_block, &rctx->dirty,list) { 811 LIST_FOR_EACH_ENTRY_SAFE(dirty_block, next_block, &rctx->dirty,list) {
810 r600_context_block_emit_dirty(rctx, dirty_block); 812 r600_context_block_emit_dirty(rctx, dirty_block);
811 } 813 }
814 si_pm4_emit_dirty(rctx);
812 rctx->pm4_dirty_cdwords = 0; 815 rctx->pm4_dirty_cdwords = 0;
813 816
814 /* Enable stream out if needed. */ 817 /* Enable stream out if needed. */
diff --git a/src/gallium/drivers/radeonsi/radeonsi_pipe.h b/src/gallium/drivers/radeonsi/radeonsi_pipe.h
index 6ba1017e16d..733afd9b4f0 100644
--- a/src/gallium/drivers/radeonsi/radeonsi_pipe.h
+++ b/src/gallium/drivers/radeonsi/radeonsi_pipe.h
@@ -36,6 +36,8 @@
36#include "util/u_slab.h" 36#include "util/u_slab.h"
37#include "r600.h" 37#include "r600.h"
38#include "radeonsi_public.h" 38#include "radeonsi_public.h"
39#include "radeonsi_pm4.h"
40#include "si_state.h"
39#include "r600_resource.h" 41#include "r600_resource.h"
40#include "sid.h" 42#include "sid.h"
41 43
@@ -320,6 +322,10 @@ struct r600_context {
320 struct pipe_index_buffer index_buffer; 322 struct pipe_index_buffer index_buffer;
321 struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS]; 323 struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS];
322 unsigned nr_vertex_buffers; 324 unsigned nr_vertex_buffers;
325
326 /* SI state handling */
327 union si_state queued;
328 union si_state emitted;
323}; 329};
324 330
325static INLINE void r600_emit_atom(struct r600_context *rctx, struct r600_atom *atom) 331static INLINE void r600_emit_atom(struct r600_context *rctx, struct r600_atom *atom)
diff --git a/src/gallium/drivers/radeonsi/radeonsi_pm4.c b/src/gallium/drivers/radeonsi/radeonsi_pm4.c
new file mode 100644
index 00000000000..488e1ccfd34
--- /dev/null
+++ b/src/gallium/drivers/radeonsi/radeonsi_pm4.c
@@ -0,0 +1,175 @@
1/*
2 * Copyright 2012 Advanced Micro Devices, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
22 *
23 * Authors:
24 * Christian König <christian.koenig@amd.com>
25 */
26
27#include "util/u_memory.h"
28#include "radeonsi_pipe.h"
29#include "radeonsi_pm4.h"
30#include "sid.h"
31#include "r600_hw_context_priv.h"
32
33#define NUMBER_OF_STATES (sizeof(union si_state) / sizeof(struct si_pm4_state *))
34
35void si_pm4_set_reg(struct si_pm4_state *state, unsigned reg, uint32_t val)
36{
37 unsigned opcode, count;
38
39 if (reg >= SI_CONFIG_REG_OFFSET && reg <= SI_CONFIG_REG_END) {
40 opcode = PKT3_SET_CONFIG_REG;
41 reg -= SI_CONFIG_REG_OFFSET;
42
43 } else if (reg >= SI_SH_REG_OFFSET && reg <= SI_SH_REG_END) {
44 opcode = PKT3_SET_SH_REG;
45 reg -= SI_SH_REG_OFFSET;
46
47 } else if (reg >= SI_CONTEXT_REG_OFFSET && reg <= SI_CONTEXT_REG_END) {
48 opcode = PKT3_SET_CONTEXT_REG;
49 reg -= SI_CONTEXT_REG_OFFSET;
50 } else {
51 R600_ERR("Invalid register offset %08x!\n", reg);
52 return;
53 }
54
55 reg >>= 2;
56
57 if (opcode != state->last_opcode || reg != (state->last_reg + 1)) {
58 state->last_opcode = opcode;
59 state->last_pm4 = state->ndw++;
60 state->pm4[state->ndw++] = reg;
61 }
62
63 state->last_reg = reg;
64 count = state->ndw - state->last_pm4 - 1;
65 state->pm4[state->last_pm4] = PKT3(opcode, count, 0);
66 state->pm4[state->ndw++] = val;
67
68 assert(state->ndw <= SI_PM4_MAX_DW);
69}
70
71void si_pm4_add_bo(struct si_pm4_state *state,
72 struct r600_resource *bo,
73 enum radeon_bo_usage usage)
74{
75 unsigned idx = state->nbo++;
76 assert(idx < SI_PM4_MAX_BO);
77
78 pipe_resource_reference((struct pipe_resource**)&state->bo[idx],
79 (struct pipe_resource*)bo);
80 state->bo_usage[idx] = usage;
81}
82
83void si_pm4_inval_shader_cache(struct si_pm4_state *state)
84{
85 state->cp_coher_cntl |= S_0085F0_SH_ICACHE_ACTION_ENA(1);
86 state->cp_coher_cntl |= S_0085F0_SH_KCACHE_ACTION_ENA(1);
87}
88
89void si_pm4_inval_texture_cache(struct si_pm4_state *state)
90{
91 state->cp_coher_cntl |= S_0085F0_TC_ACTION_ENA(1);
92}
93
94void si_pm4_inval_vertex_cache(struct si_pm4_state *state)
95{
96 /* Some GPUs don't have the vertex cache and must use the texture cache instead. */
97 state->cp_coher_cntl |= S_0085F0_TC_ACTION_ENA(1);
98}
99
100void si_pm4_inval_fb_cache(struct si_pm4_state *state, unsigned nr_cbufs)
101{
102 state->cp_coher_cntl |= S_0085F0_CB_ACTION_ENA(1);
103 state->cp_coher_cntl |= ((1 << nr_cbufs) - 1) << S_0085F0_CB0_DEST_BASE_ENA_SHIFT;
104}
105
106void si_pm4_inval_zsbuf_cache(struct si_pm4_state *state)
107{
108 state->cp_coher_cntl |= S_0085F0_DB_ACTION_ENA(1) | S_0085F0_DB_DEST_BASE_ENA(1);
109}
110
111void si_pm4_free_state(struct r600_context *rctx,
112 struct si_pm4_state *state,
113 unsigned idx)
114{
115 if (state == NULL)
116 return;
117
118 if (rctx->emitted.array[idx] == state) {
119 rctx->emitted.array[idx] = NULL;
120 }
121
122 for (int i = 0; i < state->nbo; ++i) {
123 pipe_resource_reference((struct pipe_resource**)&state->bo[idx],
124 NULL);
125 }
126 FREE(state);
127}
128
129unsigned si_pm4_dirty_dw(struct r600_context *rctx)
130{
131 unsigned count = 0;
132 uint32_t cp_coher_cntl = 0;
133
134 for (int i = 0; i < NUMBER_OF_STATES; ++i) {
135 struct si_pm4_state *state = rctx->queued.array[i];
136
137 if (!state || rctx->emitted.array[i] == state)
138 continue;
139
140 count += state->ndw;
141 cp_coher_cntl |= state->cp_coher_cntl;
142 }
143
144 //TODO
145 rctx->atom_surface_sync.flush_flags |= cp_coher_cntl;
146 r600_atom_dirty(rctx, &rctx->atom_surface_sync.atom);
147 return count;
148}
149
150void si_pm4_emit_dirty(struct r600_context *rctx)
151{
152 struct radeon_winsys_cs *cs = rctx->cs;
153
154 for (int i = 0; i < NUMBER_OF_STATES; ++i) {
155 struct si_pm4_state *state = rctx->queued.array[i];
156
157 if (!state || rctx->emitted.array[i] == state)
158 continue;
159
160 for (int j = 0; j < state->nbo; ++j) {
161 r600_context_bo_reloc(rctx, state->bo[j],
162 state->bo_usage[j]);
163 }
164
165 memcpy(&cs->buf[cs->cdw], state->pm4, state->ndw * 4);
166 cs->cdw += state->ndw;
167
168 rctx->emitted.array[i] = state;
169 }
170}
171
172void si_pm4_reset_emitted(struct r600_context *rctx)
173{
174 memset(&rctx->emitted, 0, sizeof(rctx->emitted));
175}
diff --git a/src/gallium/drivers/radeonsi/radeonsi_pm4.h b/src/gallium/drivers/radeonsi/radeonsi_pm4.h
new file mode 100644
index 00000000000..e6148b4c20c
--- /dev/null
+++ b/src/gallium/drivers/radeonsi/radeonsi_pm4.h
@@ -0,0 +1,76 @@
1/*
2 * Copyright 2012 Advanced Micro Devices, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
22 *
23 * Authors:
24 * Christian König <christian.koenig@amd.com>
25 */
26
27#ifndef RADEONSI_PM4_H
28#define RADEONSI_PM4_H
29
30#include "../../winsys/radeon/drm/radeon_winsys.h"
31
32#define SI_PM4_MAX_DW 128
33#define SI_PM4_MAX_BO 32
34
35// forward defines
36struct r600_context;
37
38struct si_pm4_state
39{
40 /* PKT3_SET_*_REG handling */
41 unsigned last_opcode;
42 unsigned last_reg;
43 unsigned last_pm4;
44
45 /* flush flags for SURFACE_SYNC */
46 uint32_t cp_coher_cntl;
47
48 /* commands for the DE */
49 unsigned ndw;
50 uint32_t pm4[SI_PM4_MAX_DW];
51
52 /* BO's referenced by this state */
53 unsigned nbo;
54 struct r600_resource *bo[SI_PM4_MAX_BO];
55 enum radeon_bo_usage bo_usage[SI_PM4_MAX_BO];
56};
57
58void si_pm4_set_reg(struct si_pm4_state *state, unsigned reg, uint32_t val);
59void si_pm4_add_bo(struct si_pm4_state *state,
60 struct r600_resource *bo,
61 enum radeon_bo_usage usage);
62
63void si_pm4_inval_shader_cache(struct si_pm4_state *state);
64void si_pm4_inval_texture_cache(struct si_pm4_state *state);
65void si_pm4_inval_vertex_cache(struct si_pm4_state *state);
66void si_pm4_inval_fb_cache(struct si_pm4_state *state, unsigned nr_cbufs);
67void si_pm4_inval_zsbuf_cache(struct si_pm4_state *state);
68
69void si_pm4_free_state(struct r600_context *rctx,
70 struct si_pm4_state *state,
71 unsigned idx);
72unsigned si_pm4_dirty_dw(struct r600_context *rctx);
73void si_pm4_emit_dirty(struct r600_context *rctx);
74void si_pm4_reset_emitted(struct r600_context *rctx);
75
76#endif
diff --git a/src/gallium/drivers/radeonsi/si_state.c b/src/gallium/drivers/radeonsi/si_state.c
new file mode 100644
index 00000000000..843403b6deb
--- /dev/null
+++ b/src/gallium/drivers/radeonsi/si_state.c
@@ -0,0 +1,28 @@
1/*
2 * Copyright 2012 Advanced Micro Devices, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
22 *
23 * Authors:
24 * Christian König <christian.koenig@amd.com>
25 *
26 */
27
28#include "si_state.h"
diff --git a/src/gallium/drivers/radeonsi/si_state.h b/src/gallium/drivers/radeonsi/si_state.h
new file mode 100644
index 00000000000..697c8721359
--- /dev/null
+++ b/src/gallium/drivers/radeonsi/si_state.h
@@ -0,0 +1,65 @@
1/*
2 * Copyright 2012 Advanced Micro Devices, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
22 *
23 * Authors:
24 * Christian König <christian.koenig@amd.com>
25 */
26
27#ifndef SI_STATE_H
28#define SI_STATE_H
29
30#include "radeonsi_pm4.h"
31
32union si_state {
33 struct {
34 } named;
35 struct si_pm4_state *array[0];
36};
37
38#define si_pm4_block_idx(member) \
39 (offsetof(union si_state, named.member) / sizeof(struct si_pm4_state *))
40
41#define si_pm4_bind_state(rctx, member, value) \
42 do { \
43 (rctx)->queued.named.member = (value); \
44 } while(0);
45
46#define si_pm4_delete_state(rctx, member, value) \
47 do { \
48 if ((rctx)->queued.named.member == (value)) { \
49 (rctx)->queued.named.member = NULL; \
50 } \
51 si_pm4_free_state(rctx, (struct si_pm4_state *)(value), \
52 si_pm4_block_idx(member)); \
53 } while(0);
54
55#define si_pm4_set_state(rctx, member, value) \
56 do { \
57 if ((rctx)->queued.named.member != (value)) { \
58 si_pm4_free_state(rctx, \
59 (struct si_pm4_state *)(rctx)->queued.named.member, \
60 si_pm4_block_idx(member)); \
61 (rctx)->queued.named.member = (value); \
62 } \
63 } while(0);
64
65#endif