r600.h revision d116fe51c1aee3453290ac30ffe993bc131c53f7
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 <assert.h> 30#include <stdint.h> 31#include <stdio.h> 32#include <util/u_double_list.h> 33#include <pipe/p_compiler.h> 34 35#define RADEON_CTX_MAX_PM4 (64 * 1024 / 4) 36 37#define R600_ERR(fmt, args...) \ 38 fprintf(stderr, "EE %s:%d %s - "fmt, __FILE__, __LINE__, __func__, ##args) 39 40typedef uint64_t u64; 41typedef uint32_t u32; 42typedef uint16_t u16; 43typedef uint8_t u8; 44 45struct radeon; 46struct winsys_handle; 47 48enum radeon_family { 49 CHIP_UNKNOWN, 50 CHIP_R100, 51 CHIP_RV100, 52 CHIP_RS100, 53 CHIP_RV200, 54 CHIP_RS200, 55 CHIP_R200, 56 CHIP_RV250, 57 CHIP_RS300, 58 CHIP_RV280, 59 CHIP_R300, 60 CHIP_R350, 61 CHIP_RV350, 62 CHIP_RV380, 63 CHIP_R420, 64 CHIP_R423, 65 CHIP_RV410, 66 CHIP_RS400, 67 CHIP_RS480, 68 CHIP_RS600, 69 CHIP_RS690, 70 CHIP_RS740, 71 CHIP_RV515, 72 CHIP_R520, 73 CHIP_RV530, 74 CHIP_RV560, 75 CHIP_RV570, 76 CHIP_R580, 77 CHIP_R600, 78 CHIP_RV610, 79 CHIP_RV630, 80 CHIP_RV670, 81 CHIP_RV620, 82 CHIP_RV635, 83 CHIP_RS780, 84 CHIP_RS880, 85 CHIP_RV770, 86 CHIP_RV730, 87 CHIP_RV710, 88 CHIP_RV740, 89 CHIP_CEDAR, 90 CHIP_REDWOOD, 91 CHIP_JUNIPER, 92 CHIP_CYPRESS, 93 CHIP_HEMLOCK, 94 CHIP_PALM, 95 CHIP_BARTS, 96 CHIP_TURKS, 97 CHIP_CAICOS, 98 CHIP_LAST, 99}; 100 101enum chip_class { 102 R600, 103 R700, 104 EVERGREEN, 105}; 106 107struct r600_tiling_info { 108 unsigned num_channels; 109 unsigned num_banks; 110 unsigned group_bytes; 111}; 112 113enum radeon_family r600_get_family(struct radeon *rw); 114enum chip_class r600_get_family_class(struct radeon *radeon); 115struct r600_tiling_info *r600_get_tiling_info(struct radeon *radeon); 116unsigned r600_get_clock_crystal_freq(struct radeon *radeon); 117unsigned r600_get_minor_version(struct radeon *radeon); 118unsigned r600_get_num_backends(struct radeon *radeon); 119 120/* r600_bo.c */ 121struct r600_bo; 122struct r600_bo *r600_bo(struct radeon *radeon, 123 unsigned size, unsigned alignment, 124 unsigned binding, unsigned usage); 125struct r600_bo *r600_bo_handle(struct radeon *radeon, 126 unsigned handle, unsigned *array_mode); 127void *r600_bo_map(struct radeon *radeon, struct r600_bo *bo, unsigned usage, void *ctx); 128void r600_bo_unmap(struct radeon *radeon, struct r600_bo *bo); 129void r600_bo_reference(struct radeon *radeon, struct r600_bo **dst, 130 struct r600_bo *src); 131boolean r600_bo_get_winsys_handle(struct radeon *radeon, struct r600_bo *pb_bo, 132 unsigned stride, struct winsys_handle *whandle); 133static INLINE unsigned r600_bo_offset(struct r600_bo *bo) 134{ 135 return 0; 136} 137 138 139/* R600/R700 STATES */ 140#define R600_GROUP_MAX 16 141#define R600_BLOCK_MAX_BO 32 142#define R600_BLOCK_MAX_REG 128 143 144struct r600_pipe_reg { 145 u32 offset; 146 u32 mask; 147 u32 value; 148 struct r600_bo *bo; 149}; 150 151struct r600_pipe_state { 152 unsigned id; 153 unsigned nregs; 154 struct r600_pipe_reg regs[R600_BLOCK_MAX_REG]; 155}; 156 157static inline void r600_pipe_state_add_reg(struct r600_pipe_state *state, 158 u32 offset, u32 value, u32 mask, 159 struct r600_bo *bo) 160{ 161 state->regs[state->nregs].offset = offset; 162 state->regs[state->nregs].value = value; 163 state->regs[state->nregs].mask = mask; 164 state->regs[state->nregs].bo = bo; 165 state->nregs++; 166 assert(state->nregs < R600_BLOCK_MAX_REG); 167} 168 169#define R600_BLOCK_STATUS_ENABLED (1 << 0) 170#define R600_BLOCK_STATUS_DIRTY (1 << 1) 171 172struct r600_block_reloc { 173 struct r600_bo *bo; 174 unsigned flush_flags; 175 unsigned flush_mask; 176 unsigned bo_pm4_index; 177}; 178 179struct r600_block { 180 struct list_head list; 181 unsigned status; 182 unsigned flags; 183 unsigned start_offset; 184 unsigned pm4_ndwords; 185 unsigned pm4_flush_ndwords; 186 unsigned nbo; 187 u16 nreg; 188 u16 nreg_dirty; 189 u32 *reg; 190 u32 pm4[R600_BLOCK_MAX_REG]; 191 unsigned pm4_bo_index[R600_BLOCK_MAX_REG]; 192 struct r600_block_reloc reloc[R600_BLOCK_MAX_BO]; 193}; 194 195struct r600_range { 196 unsigned start_offset; 197 unsigned end_offset; 198 struct r600_block **blocks; 199}; 200 201/* 202 * relocation 203 */ 204#pragma pack(1) 205struct r600_reloc { 206 uint32_t handle; 207 uint32_t read_domain; 208 uint32_t write_domain; 209 uint32_t flags; 210}; 211#pragma pack() 212 213/* 214 * query 215 */ 216struct r600_query { 217 u64 result; 218 /* The kind of query. Currently only OQ is supported. */ 219 unsigned type; 220 /* How many results have been written, in dwords. It's incremented 221 * after end_query and flush. */ 222 unsigned num_results; 223 /* if we've flushed the query */ 224 unsigned state; 225 /* The buffer where query results are stored. */ 226 struct r600_bo *buffer; 227 unsigned buffer_size; 228 /* linked list of queries */ 229 struct list_head list; 230}; 231 232#define R600_QUERY_STATE_STARTED (1 << 0) 233#define R600_QUERY_STATE_ENDED (1 << 1) 234#define R600_QUERY_STATE_SUSPENDED (1 << 2) 235 236#define R600_CONTEXT_DRAW_PENDING (1 << 0) 237#define R600_CONTEXT_DST_CACHES_DIRTY (1 << 1) 238#define R600_CONTEXT_CHECK_EVENT_FLUSH (1 << 2) 239 240struct r600_context { 241 struct radeon *radeon; 242 unsigned hash_size; 243 unsigned hash_shift; 244 struct r600_range range[256]; 245 unsigned nblocks; 246 struct r600_block **blocks; 247 struct list_head dirty; 248 unsigned pm4_ndwords; 249 unsigned pm4_cdwords; 250 unsigned pm4_dirty_cdwords; 251 unsigned ctx_pm4_ndwords; 252 unsigned nreloc; 253 unsigned creloc; 254 struct r600_reloc *reloc; 255 struct radeon_bo **bo; 256 u32 *pm4; 257 struct list_head query_list; 258 unsigned num_query_running; 259 struct list_head fenced_bo; 260 unsigned max_db; /* for OQ */ 261 unsigned num_dest_buffers; 262 unsigned flags; 263 boolean predicate_drawing; 264}; 265 266struct r600_draw { 267 u32 vgt_num_indices; 268 u32 vgt_num_instances; 269 u32 vgt_index_type; 270 u32 vgt_draw_initiator; 271 u32 indices_bo_offset; 272 struct r600_bo *indices; 273}; 274 275int r600_context_init(struct r600_context *ctx, struct radeon *radeon); 276void r600_context_fini(struct r600_context *ctx); 277void r600_context_pipe_state_set(struct r600_context *ctx, struct r600_pipe_state *state); 278void r600_context_pipe_state_set_ps_resource(struct r600_context *ctx, struct r600_pipe_state *state, unsigned rid); 279void r600_context_pipe_state_set_vs_resource(struct r600_context *ctx, struct r600_pipe_state *state, unsigned rid); 280void r600_context_pipe_state_set_fs_resource(struct r600_context *ctx, struct r600_pipe_state *state, unsigned rid); 281void r600_context_pipe_state_set_ps_sampler(struct r600_context *ctx, struct r600_pipe_state *state, unsigned id); 282void r600_context_pipe_state_set_vs_sampler(struct r600_context *ctx, struct r600_pipe_state *state, unsigned id); 283void r600_context_flush(struct r600_context *ctx); 284void r600_context_dump_bof(struct r600_context *ctx, const char *file); 285void r600_context_draw(struct r600_context *ctx, const struct r600_draw *draw); 286 287struct r600_query *r600_context_query_create(struct r600_context *ctx, unsigned query_type); 288void r600_context_query_destroy(struct r600_context *ctx, struct r600_query *query); 289boolean r600_context_query_result(struct r600_context *ctx, 290 struct r600_query *query, 291 boolean wait, void *vresult); 292void r600_query_begin(struct r600_context *ctx, struct r600_query *query); 293void r600_query_end(struct r600_context *ctx, struct r600_query *query); 294void r600_context_queries_suspend(struct r600_context *ctx); 295void r600_context_queries_resume(struct r600_context *ctx); 296void r600_query_predication(struct r600_context *ctx, struct r600_query *query, int operation, 297 int flag_wait); 298void r600_context_emit_fence(struct r600_context *ctx, struct r600_bo *fence, 299 unsigned offset, unsigned value); 300void r600_context_flush_all(struct r600_context *ctx, unsigned flush_flags); 301void r600_context_flush_dest_caches(struct r600_context *ctx); 302 303int evergreen_context_init(struct r600_context *ctx, struct radeon *radeon); 304void evergreen_context_draw(struct r600_context *ctx, const struct r600_draw *draw); 305void evergreen_context_flush_dest_caches(struct r600_context *ctx); 306void evergreen_context_pipe_state_set_ps_resource(struct r600_context *ctx, struct r600_pipe_state *state, unsigned rid); 307void evergreen_context_pipe_state_set_vs_resource(struct r600_context *ctx, struct r600_pipe_state *state, unsigned rid); 308void evergreen_context_pipe_state_set_fs_resource(struct r600_context *ctx, struct r600_pipe_state *state, unsigned rid); 309void evergreen_context_pipe_state_set_ps_sampler(struct r600_context *ctx, struct r600_pipe_state *state, unsigned id); 310void evergreen_context_pipe_state_set_vs_sampler(struct r600_context *ctx, struct r600_pipe_state *state, unsigned id); 311 312struct radeon *radeon_decref(struct radeon *radeon); 313 314#endif 315