2 * Copyright 2013 Advanced Micro Devices, Inc.
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 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
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
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 NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * Authors: Marek Olšák <maraeo@gmail.com>
28 * This file contains common screen and context structures and functions
29 * for r600g and radeonsi.
32 #ifndef R600_PIPE_COMMON_H
33 #define R600_PIPE_COMMON_H
35 #include "../../winsys/radeon/drm/radeon_winsys.h"
37 #include "util/u_range.h"
38 #include "util/u_suballoc.h"
39 #include "util/u_transfer.h"
41 #define R600_RESOURCE_FLAG_TRANSFER (PIPE_RESOURCE_FLAG_DRV_PRIV << 0)
42 #define R600_RESOURCE_FLAG_FLUSHED_DEPTH (PIPE_RESOURCE_FLAG_DRV_PRIV << 1)
43 #define R600_RESOURCE_FLAG_FORCE_TILING (PIPE_RESOURCE_FLAG_DRV_PRIV << 2)
46 #define R600_CONTEXT_INV_VERTEX_CACHE (1 << 0)
47 #define R600_CONTEXT_INV_TEX_CACHE (1 << 1)
48 #define R600_CONTEXT_INV_CONST_CACHE (1 << 2)
49 #define R600_CONTEXT_INV_SHADER_CACHE (1 << 3)
50 /* read-write caches */
51 #define R600_CONTEXT_STREAMOUT_FLUSH (1 << 8)
52 #define R600_CONTEXT_FLUSH_AND_INV (1 << 9)
53 #define R600_CONTEXT_FLUSH_AND_INV_CB_META (1 << 10)
54 #define R600_CONTEXT_FLUSH_AND_INV_DB_META (1 << 11)
55 #define R600_CONTEXT_FLUSH_AND_INV_DB (1 << 12)
56 #define R600_CONTEXT_FLUSH_AND_INV_CB (1 << 13)
57 /* engine synchronization */
58 #define R600_CONTEXT_PS_PARTIAL_FLUSH (1 << 16)
59 #define R600_CONTEXT_WAIT_3D_IDLE (1 << 17)
60 #define R600_CONTEXT_WAIT_CP_DMA_IDLE (1 << 18)
64 #define DBG_TEX_DEPTH (1 << 0)
65 #define DBG_COMPUTE (1 << 1)
66 #define DBG_VM (1 << 2)
67 #define DBG_TRACE_CS (1 << 3)
69 #define DBG_FS (1 << 8)
70 #define DBG_VS (1 << 9)
71 #define DBG_GS (1 << 10)
72 #define DBG_PS (1 << 11)
73 #define DBG_CS (1 << 12)
74 /* The maximum allowed bit is 15. */
76 struct r600_common_context
;
78 struct r600_resource
{
82 struct pb_buffer
*buf
;
83 struct radeon_winsys_cs_handle
*cs_buf
;
86 enum radeon_bo_domain domains
;
88 /* The buffer range which is initialized (with a write transfer,
89 * streamout, DMA, or as a random access target). The rest of
90 * the buffer is considered invalid and can be mapped unsynchronized.
92 * This allows unsychronized mapping of a buffer range which hasn't
93 * been used yet. It's for applications which forget to use
94 * the unsynchronized map flag and expect the driver to figure it out.
96 struct util_range valid_buffer_range
;
99 struct r600_transfer
{
100 struct pipe_transfer transfer
;
101 struct r600_resource
*staging
;
105 struct r600_fmask_info
{
110 unsigned bank_height
;
111 unsigned slice_tile_max
;
112 unsigned tile_mode_index
;
115 struct r600_cmask_info
{
119 unsigned slice_tile_max
;
122 struct r600_texture
{
123 struct r600_resource resource
;
126 unsigned pitch_override
;
128 unsigned dirty_level_mask
; /* each bit says if that mipmap is compressed */
129 struct r600_texture
*flushed_depth_texture
;
130 boolean is_flushing_texture
;
131 struct radeon_surface surface
;
133 /* Colorbuffer compression and fast clear. */
134 struct r600_fmask_info fmask
;
135 struct r600_cmask_info cmask
;
137 struct r600_resource
*htile
;
138 float depth_clear
; /* use htile only for first level */
140 struct r600_resource
*cmask_buffer
;
141 unsigned color_clear_value
[2];
143 bool non_disp_tiling
; /* R600-Cayman only */
144 unsigned mipmap_shift
;
147 struct r600_tiling_info
{
148 unsigned num_channels
;
150 unsigned group_bytes
;
153 struct r600_common_screen
{
154 struct pipe_screen b
;
155 struct radeon_winsys
*ws
;
156 enum radeon_family family
;
157 enum chip_class chip_class
;
158 struct radeon_info info
;
159 struct r600_tiling_info tiling_info
;
160 unsigned debug_flags
;
162 /* Auxiliary context. Mainly used to initialize resources.
163 * It must be locked prior to using and flushed before unlocking. */
164 struct pipe_context
*aux_context
;
165 pipe_mutex aux_context_lock
;
168 /* This encapsulates a state or an operation which can emitted into the GPU
171 void (*emit
)(struct r600_common_context
*ctx
, struct r600_atom
*state
);
176 struct r600_so_target
{
177 struct pipe_stream_output_target b
;
179 /* The buffer where BUFFER_FILLED_SIZE is stored. */
180 struct r600_resource
*buf_filled_size
;
181 unsigned buf_filled_size_offset
;
183 unsigned stride_in_dw
;
186 struct r600_streamout
{
187 struct r600_atom begin_atom
;
189 unsigned num_dw_for_end
;
191 unsigned enabled_mask
;
192 unsigned num_targets
;
193 struct r600_so_target
*targets
[PIPE_MAX_SO_BUFFERS
];
195 unsigned append_bitmask
;
198 /* External state which comes from the vertex shader,
199 * it must be set explicitly when binding a shader. */
200 unsigned *stride_in_dw
;
204 struct radeon_winsys_cs
*cs
;
206 void (*flush
)(void *ctx
, unsigned flags
);
210 struct r600_ring gfx
;
211 struct r600_ring dma
;
214 struct r600_common_context
{
215 struct pipe_context b
; /* base class */
217 struct radeon_winsys
*ws
;
218 enum radeon_family family
;
219 enum chip_class chip_class
;
220 struct r600_rings rings
;
222 struct u_suballocator
*allocator_so_filled_size
;
224 /* Current unaccounted memory usage. */
229 struct r600_streamout streamout
;
231 /* Additional context states. */
232 unsigned flags
; /* flush flags */
234 /* Copy one resource to another using async DMA.
235 * False is returned if the copy couldn't be done. */
236 boolean (*dma_copy
)(struct pipe_context
*ctx
,
237 struct pipe_resource
*dst
,
239 unsigned dst_x
, unsigned dst_y
, unsigned dst_z
,
240 struct pipe_resource
*src
,
242 const struct pipe_box
*src_box
);
244 void (*clear_buffer
)(struct pipe_context
*ctx
, struct pipe_resource
*dst
,
245 unsigned offset
, unsigned size
, unsigned value
);
248 /* r600_common_pipe.c */
249 bool r600_common_screen_init(struct r600_common_screen
*rscreen
,
250 struct radeon_winsys
*ws
);
251 void r600_common_screen_cleanup(struct r600_common_screen
*rscreen
);
252 bool r600_common_context_init(struct r600_common_context
*rctx
,
253 struct r600_common_screen
*rscreen
);
254 void r600_common_context_cleanup(struct r600_common_context
*rctx
);
255 void r600_context_add_resource_size(struct pipe_context
*ctx
, struct pipe_resource
*r
);
256 bool r600_can_dump_shader(struct r600_common_screen
*rscreen
,
257 const struct tgsi_token
*tokens
);
258 void r600_screen_clear_buffer(struct r600_common_screen
*rscreen
, struct pipe_resource
*dst
,
259 unsigned offset
, unsigned size
, unsigned value
);
260 boolean
r600_rings_is_buffer_referenced(struct r600_common_context
*ctx
,
261 struct radeon_winsys_cs_handle
*buf
,
262 enum radeon_bo_usage usage
);
263 void *r600_buffer_map_sync_with_rings(struct r600_common_context
*ctx
,
264 struct r600_resource
*resource
,
267 /* r600_streamout.c */
268 void r600_streamout_buffers_dirty(struct r600_common_context
*rctx
);
269 void r600_set_streamout_targets(struct pipe_context
*ctx
,
270 unsigned num_targets
,
271 struct pipe_stream_output_target
**targets
,
272 unsigned append_bitmask
);
273 void r600_emit_streamout_end(struct r600_common_context
*rctx
);
274 void r600_streamout_init(struct r600_common_context
*rctx
);
276 /* Inline helpers. */
278 static INLINE
struct r600_resource
*r600_resource(struct pipe_resource
*r
)
280 return (struct r600_resource
*)r
;
284 r600_resource_reference(struct r600_resource
**ptr
, struct r600_resource
*res
)
286 pipe_resource_reference((struct pipe_resource
**)ptr
,
287 (struct pipe_resource
*)res
);