1 /*
2  * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
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  *      Jerome Glisse
25  */
26 #ifndef R600_H
27 #define R600_H
28 
29 #include "../../winsys/radeon/drm/radeon_winsys.h"
30 #include "util/u_double_list.h"
31 #include "util/u_transfer.h"
32 
33 #include "radeonsi_resource.h"
34 
35 #define R600_ERR(fmt, args...) \
36 	fprintf(stderr, "EE %s:%d %s - "fmt, __FILE__, __LINE__, __func__, ##args)
37 
38 struct winsys_handle;
39 
40 enum radeon_family {
41 	CHIP_UNKNOWN,
42 	CHIP_CAYMAN,
43 	CHIP_TAHITI,
44 	CHIP_PITCAIRN,
45 	CHIP_VERDE,
46 	CHIP_LAST,
47 };
48 
49 enum chip_class {
50 	CAYMAN,
51 	TAHITI,
52 };
53 
54 struct r600_tiling_info {
55 	unsigned num_channels;
56 	unsigned num_banks;
57 	unsigned group_bytes;
58 };
59 
60 /* R600/R700 STATES */
61 struct r600_query {
62 	union {
63 		uint64_t			u64;
64 		boolean				b;
65 		struct pipe_query_data_so_statistics so;
66 	} result;
67 	/* The kind of query */
68 	unsigned				type;
69 	/* Offset of the first result for current query */
70 	unsigned				results_start;
71 	/* Offset of the next free result after current query data */
72 	unsigned				results_end;
73 	/* Size of the result in memory for both begin_query and end_query,
74 	 * this can be one or two numbers, or it could even be a size of a structure. */
75 	unsigned				result_size;
76 	/* The buffer where query results are stored. It's used as a ring,
77 	 * data blocks for current query are stored sequentially from
78 	 * results_start to results_end, with wrapping on the buffer end */
79 	struct si_resource			*buffer;
80 	/* The number of dwords for begin_query or end_query. */
81 	unsigned				num_cs_dw;
82 	/* linked list of queries */
83 	struct list_head			list;
84 };
85 
86 struct r600_so_target {
87 	struct pipe_stream_output_target b;
88 
89 	/* The buffer where BUFFER_FILLED_SIZE is stored. */
90 	struct si_resource	*filled_size;
91 	unsigned		stride;
92 	unsigned		so_index;
93 };
94 
95 #define R600_CONTEXT_DST_CACHES_DIRTY	(1 << 1)
96 #define R600_CONTEXT_CHECK_EVENT_FLUSH	(1 << 2)
97 
98 struct r600_context;
99 struct r600_screen;
100 
101 void si_get_backend_mask(struct r600_context *ctx);
102 void si_context_flush(struct r600_context *ctx, unsigned flags);
103 
104 struct r600_query *r600_context_query_create(struct r600_context *ctx, unsigned query_type);
105 void r600_context_query_destroy(struct r600_context *ctx, struct r600_query *query);
106 boolean r600_context_query_result(struct r600_context *ctx,
107 				struct r600_query *query,
108 				boolean wait, void *vresult);
109 void r600_query_begin(struct r600_context *ctx, struct r600_query *query);
110 void r600_query_end(struct r600_context *ctx, struct r600_query *query);
111 void r600_context_queries_suspend(struct r600_context *ctx);
112 void r600_context_queries_resume(struct r600_context *ctx);
113 void r600_query_predication(struct r600_context *ctx, struct r600_query *query, int operation,
114 			    int flag_wait);
115 void si_context_emit_fence(struct r600_context *ctx, struct si_resource *fence,
116                            unsigned offset, unsigned value);
117 
118 void r600_context_draw_opaque_count(struct r600_context *ctx, struct r600_so_target *t);
119 void si_need_cs_space(struct r600_context *ctx, unsigned num_dw, boolean count_draw_in);
120 
121 int si_context_init(struct r600_context *ctx);
122 
123 #endif
124