1/* 2 * Cayman shaders 3 * 4 * Copyright (C) 2011 Advanced Micro Devices, Inc. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the "Software"), 8 * to deal in the Software without restriction, including without limitation 9 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 * and/or sell copies of the Software, and to permit persons to whom the 11 * Software is furnished to do so, subject to the following conditions: 12 * 13 * The above copyright notice and this permission notice shall be included 14 * in all copies or substantial portions of the Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 20 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 */ 23 24/* 25 * Shader macros 26 */ 27 28#ifndef __SHADER_H__ 29#define __SHADER_H__ 30 31#include "radeon.h" 32 33/* Oder of instructions: All CF, All ALU, All Tex/Vtx fetches */ 34 35 36// CF insts 37// addr 38#define ADDR(x) (x) 39// jumptable 40#define JUMPTABLE_SEL(x) (x) 41// pc 42#define POP_COUNT(x) (x) 43// const 44#define CF_CONST(x) (x) 45// cond 46#define COND(x) (x) // SQ_COND_* 47// count 48#define I_COUNT(x) ((x) ? ((x) - 1) : 0) 49// vpm 50#define VALID_PIXEL_MODE(x) (x) 51// cf inst 52#define CF_INST(x) (x) // SQ_CF_INST_* 53// wqm 54#define WHOLE_QUAD_MODE(x) (x) 55// barrier 56#define BARRIER(x) (x) 57//kb0 58#define KCACHE_BANK0(x) (x) 59//kb1 60#define KCACHE_BANK1(x) (x) 61// km0/1 62#define KCACHE_MODE0(x) (x) 63#define KCACHE_MODE1(x) (x) // SQ_CF_KCACHE_* 64// 65#define KCACHE_ADDR0(x) (x) 66#define KCACHE_ADDR1(x) (x) 67 68#define ALT_CONST(x) (x) 69 70#define ARRAY_BASE(x) (x) 71// export pixel 72#define CF_PIXEL_MRT0 0 73#define CF_PIXEL_MRT1 1 74#define CF_PIXEL_MRT2 2 75#define CF_PIXEL_MRT3 3 76#define CF_PIXEL_MRT4 4 77#define CF_PIXEL_MRT5 5 78#define CF_PIXEL_MRT6 6 79#define CF_PIXEL_MRT7 7 80// computed Z 81#define CF_COMPUTED_Z 61 82// export pos 83#define CF_POS0 60 84#define CF_POS1 61 85#define CF_POS2 62 86#define CF_POS3 63 87// export param 88// 0...31 89#define TYPE(x) (x) // SQ_EXPORT_* 90#define RW_GPR(x) (x) 91#define RW_REL(x) (x) 92#define ABSOLUTE 0 93#define RELATIVE 1 94#define INDEX_GPR(x) (x) 95#define ELEM_SIZE(x) (x ? (x - 1) : 0) 96#define BURST_COUNT(x) (x ? (x - 1) : 0) 97#define MARK(x) (x) 98 99// swiz 100#define SRC_SEL_X(x) (x) // SQ_SEL_* each 101#define SRC_SEL_Y(x) (x) 102#define SRC_SEL_Z(x) (x) 103#define SRC_SEL_W(x) (x) 104 105#define CF_DWORD0(addr, jmptbl) cpu_to_le32(((addr) | ((jmptbl) << 24))) 106#define CF_DWORD1(pc, cf_const, cond, count, vpm, cf_inst, b) \ 107 cpu_to_le32((((pc) << 0) | ((cf_const) << 3) | ((cond) << 8) | ((count) << 10) | \ 108 ((vpm) << 20) | ((cf_inst) << 22) | ((b) << 31))) 109 110#define CF_ALU_DWORD0(addr, kb0, kb1, km0) cpu_to_le32((((addr) << 0) | ((kb0) << 22) | ((kb1) << 26) | ((km0) << 30))) 111#define CF_ALU_DWORD1(km1, kcache_addr0, kcache_addr1, count, alt_const, cf_inst, wqm, b) \ 112 cpu_to_le32((((km1) << 0) | ((kcache_addr0) << 2) | ((kcache_addr1) << 10) | \ 113 ((count) << 18) | ((alt_const) << 25) | ((cf_inst) << 26) | ((wqm) << 30) | ((b) << 31))) 114 115#define CF_ALLOC_IMP_EXP_DWORD0(array_base, type, rw_gpr, rr, index_gpr, es) \ 116 cpu_to_le32((((array_base) << 0) | ((type) << 13) | ((rw_gpr) << 15) | ((rr) << 22) | \ 117 ((index_gpr) << 23) | ((es) << 30))) 118#define CF_ALLOC_IMP_EXP_DWORD1_SWIZ(sel_x, sel_y, sel_z, sel_w, bc, vpm, cf_inst, m, b) \ 119 cpu_to_le32((((sel_x) << 0) | ((sel_y) << 3) | ((sel_z) << 6) | ((sel_w) << 9) | \ 120 ((bc) << 16) | ((vpm) << 20) | ((cf_inst) << 22) | ((m) << 30) | ((b) << 31))) 121 122// ALU clause insts 123#define SRC0_SEL(x) (x) 124#define SRC1_SEL(x) (x) 125#define SRC2_SEL(x) (x) 126// src[0-2]_sel 127// 0-127 GPR 128// 128-159 kcache constants bank 0 129// 160-191 kcache constants bank 1 130// 192-255 inline const values 131// 256-287 kcache constants bank 2 132// 288-319 kcache constants bank 3 133// 219-255 special SQ_ALU_SRC_* (0, 1, etc.) 134// 488-520 src param space 135#define ALU_SRC_GPR_BASE 0 136#define ALU_SRC_KCACHE0_BASE 128 137#define ALU_SRC_KCACHE1_BASE 160 138#define ALU_SRC_INLINE_K_BASE 192 139#define ALU_SRC_KCACHE2_BASE 256 140#define ALU_SRC_KCACHE3_BASE 288 141#define ALU_SRC_PARAM_BASE 448 142 143#define SRC0_REL(x) (x) 144#define SRC1_REL(x) (x) 145#define SRC2_REL(x) (x) 146// elem 147#define SRC0_ELEM(x) (x) 148#define SRC1_ELEM(x) (x) 149#define SRC2_ELEM(x) (x) 150#define ELEM_X 0 151#define ELEM_Y 1 152#define ELEM_Z 2 153#define ELEM_W 3 154// neg 155#define SRC0_NEG(x) (x) 156#define SRC1_NEG(x) (x) 157#define SRC2_NEG(x) (x) 158// im 159#define INDEX_MODE(x) (x) // SQ_INDEX_* 160// ps 161#define PRED_SEL(x) (x) // SQ_PRED_SEL_* 162// last 163#define LAST(x) (x) 164// abs 165#define SRC0_ABS(x) (x) 166#define SRC1_ABS(x) (x) 167// uem 168#define UPDATE_EXECUTE_MASK(x) (x) 169// up 170#define UPDATE_PRED(x) (x) 171// wm 172#define WRITE_MASK(x) (x) 173// omod 174#define OMOD(x) (x) // SQ_ALU_OMOD_* 175// alu inst 176#define ALU_INST(x) (x) // SQ_ALU_INST_* 177//bs 178#define BANK_SWIZZLE(x) (x) // SQ_ALU_VEC_* 179#define DST_GPR(x) (x) 180#define DST_REL(x) (x) 181#define DST_ELEM(x) (x) 182#define CLAMP(x) (x) 183 184#define ALU_DWORD0(src0_sel, s0r, s0e, s0n, src1_sel, s1r, s1e, s1n, im, ps, last) \ 185 cpu_to_le32((((src0_sel) << 0) | ((s0r) << 9) | ((s0e) << 10) | ((s0n) << 12) | \ 186 ((src1_sel) << 13) | ((s1r) << 22) | ((s1e) << 23) | ((s1n) << 25) | \ 187 ((im) << 26) | ((ps) << 29) | ((last) << 31))) 188 189#define ALU_DWORD1_OP2(s0a, s1a, uem, up, wm, omod, alu_inst, bs, dst_gpr, dr, de, clamp) \ 190 cpu_to_le32((((s0a) << 0) | ((s1a) << 1) | ((uem) << 2) | ((up) << 3) | ((wm) << 4) | \ 191 ((omod) << 5) | ((alu_inst) << 7) | ((bs) << 18) | ((dst_gpr) << 21) | \ 192 ((dr) << 28) | ((de) << 29) | ((clamp) << 31))) 193 194#define ALU_DWORD1_OP3(src2_sel, s2r, s2e, s2n, alu_inst, bs, dst_gpr, dr, de, clamp) \ 195 cpu_to_le32((((src2_sel) << 0) | ((s2r) << 9) | ((s2e) << 10) | ((s2n) << 12) | \ 196 ((alu_inst) << 13) | ((bs) << 18) | ((dst_gpr) << 21) | ((dr) << 28) | \ 197 ((de) << 29) | ((clamp) << 31))) 198 199// VTX clause insts 200// vxt insts 201#define VTX_INST(x) (x) // SQ_VTX_INST_* 202 203// fetch type 204#define FETCH_TYPE(x) (x) // SQ_VTX_FETCH_* 205 206#define FETCH_WHOLE_QUAD(x) (x) 207#define BUFFER_ID(x) (x) 208#define SRC_GPR(x) (x) 209#define SRC_REL(x) (x) 210 211#define STRUCTURED_READ(x) (x) 212#define LDS_REQ(x) (x) 213#define COALESCED_READ(x) (x) 214 215#define DST_SEL_X(x) (x) 216#define DST_SEL_Y(x) (x) 217#define DST_SEL_Z(x) (x) 218#define DST_SEL_W(x) (x) 219#define USE_CONST_FIELDS(x) (x) 220#define DATA_FORMAT(x) (x) 221// num format 222#define NUM_FORMAT_ALL(x) (x) // SQ_NUM_FORMAT_* 223// format comp 224#define FORMAT_COMP_ALL(x) (x) // SQ_FORMAT_COMP_* 225// sma 226#define SRF_MODE_ALL(x) (x) 227#define SRF_MODE_ZERO_CLAMP_MINUS_ONE 0 228#define SRF_MODE_NO_ZERO 1 229#define OFFSET(x) (x) 230// endian swap 231#define ENDIAN_SWAP(x) (x) // SQ_ENDIAN_* 232#define CONST_BUF_NO_STRIDE(x) (x) 233#define BUFFER_INDEX_MODE(x) (x) 234 235#define VTX_DWORD0(vtx_inst, ft, fwq, buffer_id, src_gpr, sr, ssx, ssy, str, ldsr, cr) \ 236 cpu_to_le32((((vtx_inst) << 0) | ((ft) << 5) | ((fwq) << 7) | ((buffer_id) << 8) | \ 237 ((src_gpr) << 16) | ((sr) << 23) | ((ssx) << 24) | ((ssy) << 26) | \ 238 ((str) << 28) | ((ldsr) << 30) | ((cr) << 31))) 239#define VTX_DWORD1_GPR(dst_gpr, dr, dsx, dsy, dsz, dsw, ucf, data_format, nfa, fca, sma) \ 240 cpu_to_le32((((dst_gpr) << 0) | ((dr) << 7) | ((dsx) << 9) | ((dsy) << 12) | ((dsz) << 15) | ((dsw) << 18) | \ 241 ((ucf) << 21) | ((data_format) << 22) | ((nfa) << 28) | ((fca) << 30) | ((sma) << 31))) 242#define VTX_DWORD2(offset, es, cbns, alt_const, bim) \ 243 cpu_to_le32((((offset) << 0) | ((es) << 16) | ((cbns) << 18) | ((alt_const) << 20) | ((bim) << 21))) 244#define VTX_DWORD_PAD cpu_to_le32(0x00000000) 245 246// TEX clause insts 247// tex insts 248#define TEX_INST(x) (x) // SQ_TEX_INST_* 249#define INST_MOD(x) (x) 250#define FETCH_WHOLE_QUAD(x) (x) 251#define RESOURCE_ID(x) (x) 252#define RESOURCE_INDEX_MODE(x) (x) 253#define SAMPLER_INDEX_MODE(x) (x) 254 255#define LOD_BIAS(x) (x) 256//ct 257#define COORD_TYPE_X(x) (x) 258#define COORD_TYPE_Y(x) (x) 259#define COORD_TYPE_Z(x) (x) 260#define COORD_TYPE_W(x) (x) 261#define TEX_UNNORMALIZED 0 262#define TEX_NORMALIZED 1 263#define OFFSET_X(x) (((int)(x) * 2) & 0x1f) /* 4:1-bits 2's-complement fixed-point: [-8.0..7.5] */ 264#define OFFSET_Y(x) (((int)(x) * 2) & 0x1f) 265#define OFFSET_Z(x) (((int)(x) * 2) & 0x1f) 266#define SAMPLER_ID(x) (x) 267 268#define TEX_DWORD0(tex_inst, im, fwq, resource_id, src_gpr, sr, ac, rim, sim) \ 269 cpu_to_le32((((tex_inst) << 0) | ((im) << 5) | ((fwq) << 7) | ((resource_id) << 8) | \ 270 ((src_gpr) << 16) | ((sr) << 23) | ((ac) << 24) | ((rim) << 25) | ((sim) << 27))) 271#define TEX_DWORD1(dst_gpr, dr, dsx, dsy, dsz, dsw, lod_bias, ctx, cty, ctz, ctw) \ 272 cpu_to_le32((((dst_gpr) << 0) | ((dr) << 7) | ((dsx) << 9) | ((dsy) << 12) | ((dsz) << 15) | ((dsw) << 18) | \ 273 ((lod_bias) << 21) | ((ctx) << 28) | ((cty) << 29) | ((ctz) << 30) | ((ctw) << 31))) 274#define TEX_DWORD2(offset_x, offset_y, offset_z, sampler_id, ssx, ssy, ssz, ssw) \ 275 cpu_to_le32((((offset_x) << 0) | ((offset_y) << 5) | ((offset_z) << 10) | ((sampler_id) << 15) | \ 276 ((ssx) << 20) | ((ssy) << 23) | ((ssz) << 26) | ((ssw) << 29))) 277#define TEX_DWORD_PAD cpu_to_le32(0x00000000) 278 279#endif 280