1848b8605Smrg/* 2848b8605Smrg * Copyright (C) 2012 Rob Clark <robclark@freedesktop.org> 3848b8605Smrg * 4848b8605Smrg * Permission is hereby granted, free of charge, to any person obtaining a 5848b8605Smrg * copy of this software and associated documentation files (the "Software"), 6848b8605Smrg * to deal in the Software without restriction, including without limitation 7848b8605Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8848b8605Smrg * and/or sell copies of the Software, and to permit persons to whom the 9848b8605Smrg * Software is furnished to do so, subject to the following conditions: 10848b8605Smrg * 11848b8605Smrg * The above copyright notice and this permission notice (including the next 12848b8605Smrg * paragraph) shall be included in all copies or substantial portions of the 13848b8605Smrg * Software. 14848b8605Smrg * 15848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16848b8605Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17848b8605Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18848b8605Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19848b8605Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20848b8605Smrg * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21848b8605Smrg * SOFTWARE. 22848b8605Smrg * 23848b8605Smrg * Authors: 24848b8605Smrg * Rob Clark <robclark@freedesktop.org> 25848b8605Smrg */ 26848b8605Smrg 27848b8605Smrg#ifndef FREEDRENO_UTIL_H_ 28848b8605Smrg#define FREEDRENO_UTIL_H_ 29848b8605Smrg 30b8e80941Smrg#include "drm/freedreno_drmif.h" 31b8e80941Smrg#include "drm/freedreno_ringbuffer.h" 32848b8605Smrg 33848b8605Smrg#include "pipe/p_format.h" 34848b8605Smrg#include "pipe/p_state.h" 35848b8605Smrg#include "util/u_debug.h" 36848b8605Smrg#include "util/u_math.h" 37848b8605Smrg#include "util/u_half.h" 38848b8605Smrg#include "util/u_dynarray.h" 39848b8605Smrg#include "util/u_pack_color.h" 40848b8605Smrg 41b8e80941Smrg#include "disasm.h" 42848b8605Smrg#include "adreno_common.xml.h" 43848b8605Smrg#include "adreno_pm4.xml.h" 44848b8605Smrg 45848b8605Smrgenum adreno_rb_depth_format fd_pipe2depth(enum pipe_format format); 46848b8605Smrgenum pc_di_index_size fd_pipe2index(enum pipe_format format); 47b8e80941Smrgenum pipe_format fd_gmem_restore_format(enum pipe_format format); 48848b8605Smrgenum adreno_rb_blend_factor fd_blend_factor(unsigned factor); 49848b8605Smrgenum adreno_pa_su_sc_draw fd_polygon_mode(unsigned mode); 50848b8605Smrgenum adreno_stencil_op fd_stencil_op(unsigned op); 51848b8605Smrg 52848b8605Smrg#define A3XX_MAX_MIP_LEVELS 14 53848b8605Smrg/* TBD if it is same on a2xx, but for now: */ 54848b8605Smrg#define MAX_MIP_LEVELS A3XX_MAX_MIP_LEVELS 55848b8605Smrg 56b8e80941Smrg#define A2XX_MAX_RENDER_TARGETS 1 57b8e80941Smrg#define A3XX_MAX_RENDER_TARGETS 4 58b8e80941Smrg#define A4XX_MAX_RENDER_TARGETS 8 59b8e80941Smrg#define A5XX_MAX_RENDER_TARGETS 8 60b8e80941Smrg#define A6XX_MAX_RENDER_TARGETS 8 61b8e80941Smrg 62b8e80941Smrg#define MAX_RENDER_TARGETS A6XX_MAX_RENDER_TARGETS 63b8e80941Smrg 64848b8605Smrg#define FD_DBG_MSGS 0x0001 65848b8605Smrg#define FD_DBG_DISASM 0x0002 66848b8605Smrg#define FD_DBG_DCLEAR 0x0004 67b8e80941Smrg#define FD_DBG_DDRAW 0x0008 68b8e80941Smrg#define FD_DBG_NOSCIS 0x0010 69848b8605Smrg#define FD_DBG_DIRECT 0x0020 70b8e80941Smrg#define FD_DBG_NOBYPASS 0x0040 71848b8605Smrg#define FD_DBG_FRAGHALF 0x0080 72848b8605Smrg#define FD_DBG_NOBIN 0x0100 73b8e80941Smrg/* unused 0x0200 */ 74b8e80941Smrg#define FD_DBG_GLSL120 0x0400 75b8e80941Smrg#define FD_DBG_SHADERDB 0x0800 76b8e80941Smrg#define FD_DBG_FLUSH 0x1000 77b8e80941Smrg#define FD_DBG_DEQP 0x2000 78b8e80941Smrg#define FD_DBG_INORDER 0x4000 79b8e80941Smrg#define FD_DBG_BSTAT 0x8000 80b8e80941Smrg#define FD_DBG_NOGROW 0x10000 81b8e80941Smrg#define FD_DBG_LRZ 0x20000 82b8e80941Smrg#define FD_DBG_NOINDR 0x40000 83b8e80941Smrg#define FD_DBG_NOBLIT 0x80000 84b8e80941Smrg#define FD_DBG_HIPRIO 0x100000 85b8e80941Smrg#define FD_DBG_TTILE 0x200000 86b8e80941Smrg#define FD_DBG_PERFC 0x400000 87b8e80941Smrg#define FD_DBG_SOFTPIN 0x800000 88b8e80941Smrg#define FD_DBG_UBWC 0x1000000 89848b8605Smrgextern int fd_mesa_debug; 90848b8605Smrgextern bool fd_binning_enabled; 91848b8605Smrg 92848b8605Smrg#define DBG(fmt, ...) \ 93848b8605Smrg do { if (fd_mesa_debug & FD_DBG_MSGS) \ 94848b8605Smrg debug_printf("%s:%d: "fmt "\n", \ 95848b8605Smrg __FUNCTION__, __LINE__, ##__VA_ARGS__); } while (0) 96848b8605Smrg 97848b8605Smrg/* for conditionally setting boolean flag(s): */ 98848b8605Smrg#define COND(bool, val) ((bool) ? (val) : 0) 99848b8605Smrg 100848b8605Smrg#define CP_REG(reg) ((0x4 << 16) | ((unsigned int)((reg) - (0x2000)))) 101848b8605Smrg 102848b8605Smrgstatic inline uint32_t DRAW(enum pc_di_primtype prim_type, 103848b8605Smrg enum pc_di_src_sel source_select, enum pc_di_index_size index_size, 104b8e80941Smrg enum pc_di_vis_cull_mode vis_cull_mode, 105b8e80941Smrg uint8_t instances) 106848b8605Smrg{ 107848b8605Smrg return (prim_type << 0) | 108848b8605Smrg (source_select << 6) | 109848b8605Smrg ((index_size & 1) << 11) | 110848b8605Smrg ((index_size >> 1) << 13) | 111848b8605Smrg (vis_cull_mode << 9) | 112b8e80941Smrg (1 << 14) | 113b8e80941Smrg (instances << 24); 114b8e80941Smrg} 115b8e80941Smrg 116b8e80941Smrgstatic inline uint32_t DRAW_A20X(enum pc_di_primtype prim_type, 117b8e80941Smrg enum pc_di_face_cull_sel faceness_cull_select, 118b8e80941Smrg enum pc_di_src_sel source_select, enum pc_di_index_size index_size, 119b8e80941Smrg bool pre_fetch_cull_enable, 120b8e80941Smrg bool grp_cull_enable, 121b8e80941Smrg uint16_t count) 122b8e80941Smrg{ 123b8e80941Smrg return (prim_type << 0) | 124b8e80941Smrg (source_select << 6) | 125b8e80941Smrg (faceness_cull_select << 8) | 126b8e80941Smrg ((index_size & 1) << 11) | 127b8e80941Smrg ((index_size >> 1) << 13) | 128b8e80941Smrg (pre_fetch_cull_enable << 14) | 129b8e80941Smrg (grp_cull_enable << 15) | 130b8e80941Smrg (count << 16); 131848b8605Smrg} 132848b8605Smrg 133848b8605Smrg/* for tracking cmdstream positions that need to be patched: */ 134848b8605Smrgstruct fd_cs_patch { 135848b8605Smrg uint32_t *cs; 136848b8605Smrg uint32_t val; 137848b8605Smrg}; 138848b8605Smrg#define fd_patch_num_elements(buf) ((buf)->size / sizeof(struct fd_cs_patch)) 139848b8605Smrg#define fd_patch_element(buf, i) util_dynarray_element(buf, struct fd_cs_patch, i) 140848b8605Smrg 141848b8605Smrgstatic inline enum pipe_format 142848b8605Smrgpipe_surface_format(struct pipe_surface *psurf) 143848b8605Smrg{ 144848b8605Smrg if (!psurf) 145848b8605Smrg return PIPE_FORMAT_NONE; 146848b8605Smrg return psurf->format; 147848b8605Smrg} 148848b8605Smrg 149b8e80941Smrgstatic inline bool 150b8e80941Smrgfd_surface_half_precision(const struct pipe_surface *psurf) 151b8e80941Smrg{ 152b8e80941Smrg enum pipe_format format; 153b8e80941Smrg 154b8e80941Smrg if (!psurf) 155b8e80941Smrg return true; 156b8e80941Smrg 157b8e80941Smrg format = psurf->format; 158b8e80941Smrg 159b8e80941Smrg /* colors are provided in consts, which go through cov.f32f16, which will 160b8e80941Smrg * break these values 161b8e80941Smrg */ 162b8e80941Smrg if (util_format_is_pure_integer(format)) 163b8e80941Smrg return false; 164b8e80941Smrg 165b8e80941Smrg /* avoid losing precision on 32-bit float formats */ 166b8e80941Smrg if (util_format_is_float(format) && 167b8e80941Smrg util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_RGB, 0) == 32) 168b8e80941Smrg return false; 169b8e80941Smrg 170b8e80941Smrg return true; 171b8e80941Smrg} 172b8e80941Smrg 173b8e80941Smrgstatic inline unsigned 174b8e80941Smrgfd_sampler_first_level(const struct pipe_sampler_view *view) 175b8e80941Smrg{ 176b8e80941Smrg if (view->target == PIPE_BUFFER) 177b8e80941Smrg return 0; 178b8e80941Smrg return view->u.tex.first_level; 179b8e80941Smrg} 180b8e80941Smrg 181b8e80941Smrgstatic inline unsigned 182b8e80941Smrgfd_sampler_last_level(const struct pipe_sampler_view *view) 183b8e80941Smrg{ 184b8e80941Smrg if (view->target == PIPE_BUFFER) 185b8e80941Smrg return 0; 186b8e80941Smrg return view->u.tex.last_level; 187b8e80941Smrg} 188b8e80941Smrg 189b8e80941Smrgstatic inline bool 190b8e80941Smrgfd_half_precision(struct pipe_framebuffer_state *pfb) 191b8e80941Smrg{ 192b8e80941Smrg unsigned i; 193b8e80941Smrg 194b8e80941Smrg for (i = 0; i < pfb->nr_cbufs; i++) 195b8e80941Smrg if (!fd_surface_half_precision(pfb->cbufs[i])) 196b8e80941Smrg return false; 197b8e80941Smrg 198b8e80941Smrg return true; 199b8e80941Smrg} 200b8e80941Smrg 201b8e80941Smrg/* Note sure if this is same on all gens, but seems to be same on the later 202b8e80941Smrg * gen's 203b8e80941Smrg */ 204b8e80941Smrgstatic inline unsigned 205b8e80941Smrgfd_calc_guardband(unsigned x) 206b8e80941Smrg{ 207b8e80941Smrg float l = log2(x); 208b8e80941Smrg if (l <= 8) 209b8e80941Smrg return 511; 210b8e80941Smrg return 511 - ((l - 8) * 65); 211b8e80941Smrg} 212b8e80941Smrg 213848b8605Smrg#define LOG_DWORDS 0 214848b8605Smrg 215848b8605Smrgstatic inline void emit_marker(struct fd_ringbuffer *ring, int scratch_idx); 216848b8605Smrg 217848b8605Smrgstatic inline void 218848b8605SmrgOUT_RING(struct fd_ringbuffer *ring, uint32_t data) 219848b8605Smrg{ 220848b8605Smrg if (LOG_DWORDS) { 221848b8605Smrg DBG("ring[%p]: OUT_RING %04x: %08x", ring, 222b8e80941Smrg (uint32_t)(ring->cur - ring->start), data); 223848b8605Smrg } 224b8e80941Smrg fd_ringbuffer_emit(ring, data); 225848b8605Smrg} 226848b8605Smrg 227848b8605Smrg/* like OUT_RING() but appends a cmdstream patch point to 'buf' */ 228848b8605Smrgstatic inline void 229848b8605SmrgOUT_RINGP(struct fd_ringbuffer *ring, uint32_t data, 230848b8605Smrg struct util_dynarray *buf) 231848b8605Smrg{ 232848b8605Smrg if (LOG_DWORDS) { 233848b8605Smrg DBG("ring[%p]: OUT_RINGP %04x: %08x", ring, 234b8e80941Smrg (uint32_t)(ring->cur - ring->start), data); 235848b8605Smrg } 236848b8605Smrg util_dynarray_append(buf, struct fd_cs_patch, ((struct fd_cs_patch){ 237848b8605Smrg .cs = ring->cur++, 238848b8605Smrg .val = data, 239848b8605Smrg })); 240848b8605Smrg} 241848b8605Smrg 242b8e80941Smrg/* 243b8e80941Smrg * NOTE: OUT_RELOC*() is 2 dwords (64b) on a5xx+ 244b8e80941Smrg */ 245b8e80941Smrg 246848b8605Smrgstatic inline void 247b8e80941Smrg__out_reloc(struct fd_ringbuffer *ring, struct fd_bo *bo, 248b8e80941Smrg uint32_t offset, uint64_t or, int32_t shift, uint32_t flags) 249848b8605Smrg{ 250848b8605Smrg if (LOG_DWORDS) { 251848b8605Smrg DBG("ring[%p]: OUT_RELOC %04x: %p+%u << %d", ring, 252b8e80941Smrg (uint32_t)(ring->cur - ring->start), bo, offset, shift); 253848b8605Smrg } 254b8e80941Smrg debug_assert(offset < fd_bo_size(bo)); 255848b8605Smrg fd_ringbuffer_reloc(ring, &(struct fd_reloc){ 256848b8605Smrg .bo = bo, 257b8e80941Smrg .flags = flags, 258848b8605Smrg .offset = offset, 259848b8605Smrg .or = or, 260848b8605Smrg .shift = shift, 261b8e80941Smrg .orhi = or >> 32, 262848b8605Smrg }); 263848b8605Smrg} 264848b8605Smrg 265b8e80941Smrgstatic inline void 266b8e80941SmrgOUT_RELOC(struct fd_ringbuffer *ring, struct fd_bo *bo, 267b8e80941Smrg uint32_t offset, uint64_t or, int32_t shift) 268b8e80941Smrg{ 269b8e80941Smrg __out_reloc(ring, bo, offset, or, shift, FD_RELOC_READ); 270b8e80941Smrg} 271b8e80941Smrg 272848b8605Smrgstatic inline void 273848b8605SmrgOUT_RELOCW(struct fd_ringbuffer *ring, struct fd_bo *bo, 274b8e80941Smrg uint32_t offset, uint64_t or, int32_t shift) 275848b8605Smrg{ 276b8e80941Smrg __out_reloc(ring, bo, offset, or, shift, FD_RELOC_READ | FD_RELOC_WRITE); 277b8e80941Smrg} 278b8e80941Smrg 279b8e80941Smrgstatic inline void 280b8e80941SmrgOUT_RELOCD(struct fd_ringbuffer *ring, struct fd_bo *bo, 281b8e80941Smrg uint32_t offset, uint64_t or, int32_t shift) 282b8e80941Smrg{ 283b8e80941Smrg __out_reloc(ring, bo, offset, or, shift, FD_RELOC_READ | FD_RELOC_DUMP); 284b8e80941Smrg} 285b8e80941Smrg 286b8e80941Smrgstatic inline void 287b8e80941SmrgOUT_RB(struct fd_ringbuffer *ring, struct fd_ringbuffer *target) 288b8e80941Smrg{ 289b8e80941Smrg fd_ringbuffer_emit_reloc_ring_full(ring, target, 0); 290848b8605Smrg} 291848b8605Smrg 292848b8605Smrgstatic inline void BEGIN_RING(struct fd_ringbuffer *ring, uint32_t ndwords) 293848b8605Smrg{ 294b8e80941Smrg if (ring->cur + ndwords > ring->end) 295b8e80941Smrg fd_ringbuffer_grow(ring, ndwords); 296848b8605Smrg} 297848b8605Smrg 298848b8605Smrgstatic inline void 299848b8605SmrgOUT_PKT0(struct fd_ringbuffer *ring, uint16_t regindx, uint16_t cnt) 300848b8605Smrg{ 301848b8605Smrg BEGIN_RING(ring, cnt+1); 302848b8605Smrg OUT_RING(ring, CP_TYPE0_PKT | ((cnt-1) << 16) | (regindx & 0x7FFF)); 303848b8605Smrg} 304848b8605Smrg 305b8e80941Smrgstatic inline void 306b8e80941SmrgOUT_PKT2(struct fd_ringbuffer *ring) 307b8e80941Smrg{ 308b8e80941Smrg BEGIN_RING(ring, 1); 309b8e80941Smrg OUT_RING(ring, CP_TYPE2_PKT); 310b8e80941Smrg} 311b8e80941Smrg 312848b8605Smrgstatic inline void 313848b8605SmrgOUT_PKT3(struct fd_ringbuffer *ring, uint8_t opcode, uint16_t cnt) 314848b8605Smrg{ 315848b8605Smrg BEGIN_RING(ring, cnt+1); 316848b8605Smrg OUT_RING(ring, CP_TYPE3_PKT | ((cnt-1) << 16) | ((opcode & 0xFF) << 8)); 317848b8605Smrg} 318848b8605Smrg 319b8e80941Smrg/* 320b8e80941Smrg * Starting with a5xx, pkt4/pkt7 are used instead of pkt0/pkt3 321b8e80941Smrg */ 322b8e80941Smrg 323b8e80941Smrgstatic inline unsigned 324b8e80941Smrg_odd_parity_bit(unsigned val) 325b8e80941Smrg{ 326b8e80941Smrg /* See: http://graphics.stanford.edu/~seander/bithacks.html#ParityParallel 327b8e80941Smrg * note that we want odd parity so 0x6996 is inverted. 328b8e80941Smrg */ 329b8e80941Smrg val ^= val >> 16; 330b8e80941Smrg val ^= val >> 8; 331b8e80941Smrg val ^= val >> 4; 332b8e80941Smrg val &= 0xf; 333b8e80941Smrg return (~0x6996 >> val) & 1; 334b8e80941Smrg} 335b8e80941Smrg 336b8e80941Smrgstatic inline void 337b8e80941SmrgOUT_PKT4(struct fd_ringbuffer *ring, uint16_t regindx, uint16_t cnt) 338b8e80941Smrg{ 339b8e80941Smrg BEGIN_RING(ring, cnt+1); 340b8e80941Smrg OUT_RING(ring, CP_TYPE4_PKT | cnt | 341b8e80941Smrg (_odd_parity_bit(cnt) << 7) | 342b8e80941Smrg ((regindx & 0x3ffff) << 8) | 343b8e80941Smrg ((_odd_parity_bit(regindx) << 27))); 344b8e80941Smrg} 345b8e80941Smrg 346b8e80941Smrgstatic inline void 347b8e80941SmrgOUT_PKT7(struct fd_ringbuffer *ring, uint8_t opcode, uint16_t cnt) 348b8e80941Smrg{ 349b8e80941Smrg BEGIN_RING(ring, cnt+1); 350b8e80941Smrg OUT_RING(ring, CP_TYPE7_PKT | cnt | 351b8e80941Smrg (_odd_parity_bit(cnt) << 15) | 352b8e80941Smrg ((opcode & 0x7f) << 16) | 353b8e80941Smrg ((_odd_parity_bit(opcode) << 23))); 354b8e80941Smrg} 355b8e80941Smrg 356848b8605Smrgstatic inline void 357848b8605SmrgOUT_WFI(struct fd_ringbuffer *ring) 358848b8605Smrg{ 359848b8605Smrg OUT_PKT3(ring, CP_WAIT_FOR_IDLE, 1); 360848b8605Smrg OUT_RING(ring, 0x00000000); 361848b8605Smrg} 362848b8605Smrg 363848b8605Smrgstatic inline void 364b8e80941SmrgOUT_WFI5(struct fd_ringbuffer *ring) 365848b8605Smrg{ 366b8e80941Smrg OUT_PKT7(ring, CP_WAIT_FOR_IDLE, 0); 367b8e80941Smrg} 368848b8605Smrg 369b8e80941Smrgstatic inline void 370b8e80941Smrg__OUT_IB(struct fd_ringbuffer *ring, bool prefetch, struct fd_ringbuffer *target) 371b8e80941Smrg{ 372b8e80941Smrg if (target->cur == target->start) 373b8e80941Smrg return; 374b8e80941Smrg 375b8e80941Smrg unsigned count = fd_ringbuffer_cmd_count(target); 376848b8605Smrg 377848b8605Smrg /* for debug after a lock up, write a unique counter value 378848b8605Smrg * to scratch6 for each IB, to make it easier to match up 379848b8605Smrg * register dumps to cmdstream. The combination of IB and 380848b8605Smrg * DRAW (scratch7) is enough to "triangulate" the particular 381848b8605Smrg * draw that caused lockup. 382848b8605Smrg */ 383848b8605Smrg emit_marker(ring, 6); 384848b8605Smrg 385b8e80941Smrg for (unsigned i = 0; i < count; i++) { 386b8e80941Smrg uint32_t dwords; 387b8e80941Smrg OUT_PKT3(ring, prefetch ? CP_INDIRECT_BUFFER_PFE : CP_INDIRECT_BUFFER_PFD, 2); 388b8e80941Smrg dwords = fd_ringbuffer_emit_reloc_ring_full(ring, target, i) / 4; 389b8e80941Smrg assert(dwords > 0); 390b8e80941Smrg OUT_RING(ring, dwords); 391b8e80941Smrg OUT_PKT2(ring); 392b8e80941Smrg } 393848b8605Smrg 394848b8605Smrg emit_marker(ring, 6); 395848b8605Smrg} 396848b8605Smrg 397b8e80941Smrgstatic inline void 398b8e80941Smrg__OUT_IB5(struct fd_ringbuffer *ring, struct fd_ringbuffer *target) 399b8e80941Smrg{ 400b8e80941Smrg if (target->cur == target->start) 401b8e80941Smrg return; 402b8e80941Smrg 403b8e80941Smrg unsigned count = fd_ringbuffer_cmd_count(target); 404b8e80941Smrg 405b8e80941Smrg for (unsigned i = 0; i < count; i++) { 406b8e80941Smrg uint32_t dwords; 407b8e80941Smrg OUT_PKT7(ring, CP_INDIRECT_BUFFER, 3); 408b8e80941Smrg dwords = fd_ringbuffer_emit_reloc_ring_full(ring, target, i) / 4; 409b8e80941Smrg assert(dwords > 0); 410b8e80941Smrg OUT_RING(ring, dwords); 411b8e80941Smrg } 412b8e80941Smrg} 413b8e80941Smrg 414848b8605Smrg/* CP_SCRATCH_REG4 is used to hold base address for query results: */ 415b8e80941Smrg// XXX annoyingly scratch regs move on a5xx.. and additionally different 416b8e80941Smrg// packet types.. so freedreno_query_hw is going to need a bit of 417b8e80941Smrg// rework.. 418848b8605Smrg#define HW_QUERY_BASE_REG REG_AXXX_CP_SCRATCH_REG4 419848b8605Smrg 420848b8605Smrgstatic inline void 421848b8605Smrgemit_marker(struct fd_ringbuffer *ring, int scratch_idx) 422848b8605Smrg{ 423848b8605Smrg extern unsigned marker_cnt; 424848b8605Smrg unsigned reg = REG_AXXX_CP_SCRATCH_REG0 + scratch_idx; 425848b8605Smrg assert(reg != HW_QUERY_BASE_REG); 426848b8605Smrg if (reg == HW_QUERY_BASE_REG) 427848b8605Smrg return; 428848b8605Smrg OUT_PKT0(ring, reg, 1); 429848b8605Smrg OUT_RING(ring, ++marker_cnt); 430848b8605Smrg} 431848b8605Smrg 432848b8605Smrgstatic inline uint32_t 433848b8605Smrgpack_rgba(enum pipe_format format, const float *rgba) 434848b8605Smrg{ 435848b8605Smrg union util_color uc; 436848b8605Smrg util_pack_color(rgba, format, &uc); 437848b8605Smrg return uc.ui[0]; 438848b8605Smrg} 439848b8605Smrg 440b8e80941Smrg/* 441b8e80941Smrg * swap - swap value of @a and @b 442b8e80941Smrg */ 443b8e80941Smrg#define swap(a, b) \ 444b8e80941Smrg do { __typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0) 445b8e80941Smrg 446b8e80941Smrg#define foreach_bit(b, mask) \ 447b8e80941Smrg for (uint32_t _m = (mask); _m && ({(b) = u_bit_scan(&_m); 1;});) 448b8e80941Smrg 449b8e80941Smrg 450b8e80941Smrg#define BIT(bit) (1u << bit) 451b8e80941Smrg 452b8e80941Smrg/* 453b8e80941Smrg * a3xx+ helpers: 454b8e80941Smrg */ 455b8e80941Smrg 456b8e80941Smrgstatic inline enum a3xx_msaa_samples 457b8e80941Smrgfd_msaa_samples(unsigned samples) 458b8e80941Smrg{ 459b8e80941Smrg switch (samples) { 460b8e80941Smrg default: 461b8e80941Smrg debug_assert(0); 462b8e80941Smrg case 0: 463b8e80941Smrg case 1: return MSAA_ONE; 464b8e80941Smrg case 2: return MSAA_TWO; 465b8e80941Smrg case 4: return MSAA_FOUR; 466b8e80941Smrg case 8: return MSAA_EIGHT; 467b8e80941Smrg } 468b8e80941Smrg} 469b8e80941Smrg 470b8e80941Smrg/* 471b8e80941Smrg * a4xx+ helpers: 472b8e80941Smrg */ 473b8e80941Smrg 474b8e80941Smrgstatic inline enum a4xx_state_block 475b8e80941Smrgfd4_stage2shadersb(gl_shader_stage type) 476b8e80941Smrg{ 477b8e80941Smrg switch (type) { 478b8e80941Smrg case MESA_SHADER_VERTEX: 479b8e80941Smrg return SB4_VS_SHADER; 480b8e80941Smrg case MESA_SHADER_FRAGMENT: 481b8e80941Smrg return SB4_FS_SHADER; 482b8e80941Smrg case MESA_SHADER_COMPUTE: 483b8e80941Smrg case MESA_SHADER_KERNEL: 484b8e80941Smrg return SB4_CS_SHADER; 485b8e80941Smrg default: 486b8e80941Smrg unreachable("bad shader type"); 487b8e80941Smrg return ~0; 488b8e80941Smrg } 489b8e80941Smrg} 490b8e80941Smrg 491848b8605Smrg#endif /* FREEDRENO_UTIL_H_ */ 492