1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright © 2019 Intel Corporation 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 10bf215546Sopenharmony_ci * 11bf215546Sopenharmony_ci * The above copyright notice and this permission notice shall be included 12bf215546Sopenharmony_ci * in all copies or substantial portions of the Software. 13bf215546Sopenharmony_ci * 14bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20bf215546Sopenharmony_ci * DEALINGS IN THE SOFTWARE. 21bf215546Sopenharmony_ci */ 22bf215546Sopenharmony_ci 23bf215546Sopenharmony_ci/** 24bf215546Sopenharmony_ci * Macro and function definitions needed in order to use genxml. 25bf215546Sopenharmony_ci * 26bf215546Sopenharmony_ci * This should only be included in sources compiled per-generation. 27bf215546Sopenharmony_ci */ 28bf215546Sopenharmony_ci 29bf215546Sopenharmony_ci#include "iris_batch.h" 30bf215546Sopenharmony_ci 31bf215546Sopenharmony_ci#define __gen_address_type struct iris_address 32bf215546Sopenharmony_ci#define __gen_user_data struct iris_batch 33bf215546Sopenharmony_ci#define __gen_combine_address iris_combine_address 34bf215546Sopenharmony_ci 35bf215546Sopenharmony_cistatic inline void * 36bf215546Sopenharmony_ci__gen_get_batch_dwords(struct iris_batch *batch, unsigned dwords) 37bf215546Sopenharmony_ci{ 38bf215546Sopenharmony_ci return iris_get_command_space(batch, dwords * sizeof(uint32_t)); 39bf215546Sopenharmony_ci} 40bf215546Sopenharmony_ci 41bf215546Sopenharmony_cistatic inline struct iris_address 42bf215546Sopenharmony_ci__gen_address_offset(struct iris_address addr, uint64_t offset) 43bf215546Sopenharmony_ci{ 44bf215546Sopenharmony_ci addr.offset += offset; 45bf215546Sopenharmony_ci return addr; 46bf215546Sopenharmony_ci} 47bf215546Sopenharmony_ci 48bf215546Sopenharmony_cistatic uint64_t 49bf215546Sopenharmony_ci__gen_combine_address(struct iris_batch *batch, void *location, 50bf215546Sopenharmony_ci struct iris_address addr, uint32_t delta) 51bf215546Sopenharmony_ci{ 52bf215546Sopenharmony_ci uint64_t result = addr.offset + delta; 53bf215546Sopenharmony_ci 54bf215546Sopenharmony_ci if (addr.bo) { 55bf215546Sopenharmony_ci iris_use_pinned_bo(batch, addr.bo, 56bf215546Sopenharmony_ci !iris_domain_is_read_only(addr.access), addr.access); 57bf215546Sopenharmony_ci /* Assume this is a general address, not relative to a base. */ 58bf215546Sopenharmony_ci result += addr.bo->address; 59bf215546Sopenharmony_ci } 60bf215546Sopenharmony_ci 61bf215546Sopenharmony_ci return result; 62bf215546Sopenharmony_ci} 63bf215546Sopenharmony_ci 64bf215546Sopenharmony_cistatic inline struct iris_address 65bf215546Sopenharmony_ci__gen_get_batch_address(struct iris_batch *batch, void *location) 66bf215546Sopenharmony_ci{ 67bf215546Sopenharmony_ci unreachable("Not supported by iris"); 68bf215546Sopenharmony_ci} 69bf215546Sopenharmony_ci 70bf215546Sopenharmony_ci#define __gen_address_type struct iris_address 71bf215546Sopenharmony_ci#define __gen_user_data struct iris_batch 72bf215546Sopenharmony_ci 73bf215546Sopenharmony_ci#define __genxml_cmd_length(cmd) cmd ## _length 74bf215546Sopenharmony_ci#define __genxml_cmd_length_bias(cmd) cmd ## _length_bias 75bf215546Sopenharmony_ci#define __genxml_cmd_header(cmd) cmd ## _header 76bf215546Sopenharmony_ci#define __genxml_cmd_pack(cmd) cmd ## _pack 77bf215546Sopenharmony_ci#define __genxml_reg_num(cmd) cmd ## _num 78bf215546Sopenharmony_ci 79bf215546Sopenharmony_ci#include "genxml/genX_pack.h" 80bf215546Sopenharmony_ci#include "genxml/gen_macros.h" 81bf215546Sopenharmony_ci#include "genxml/genX_bits.h" 82bf215546Sopenharmony_ci 83bf215546Sopenharmony_ci/* CS_GPR(15) is reserved for combining conditional rendering predicates 84bf215546Sopenharmony_ci * with GL_ARB_indirect_parameters draw number predicates. 85bf215546Sopenharmony_ci */ 86bf215546Sopenharmony_ci#define MI_BUILDER_NUM_ALLOC_GPRS 15 87bf215546Sopenharmony_ci#include "common/mi_builder.h" 88bf215546Sopenharmony_ci 89bf215546Sopenharmony_ci#define _iris_pack_command(batch, cmd, dst, name) \ 90bf215546Sopenharmony_ci for (struct cmd name = { __genxml_cmd_header(cmd) }, \ 91bf215546Sopenharmony_ci *_dst = (void *)(dst); __builtin_expect(_dst != NULL, 1); \ 92bf215546Sopenharmony_ci ({ __genxml_cmd_pack(cmd)(batch, (void *)_dst, &name); \ 93bf215546Sopenharmony_ci _dst = NULL; \ 94bf215546Sopenharmony_ci })) 95bf215546Sopenharmony_ci 96bf215546Sopenharmony_ci#define iris_pack_command(cmd, dst, name) \ 97bf215546Sopenharmony_ci _iris_pack_command(NULL, cmd, dst, name) 98bf215546Sopenharmony_ci 99bf215546Sopenharmony_ci#define _iris_pack_state(batch, cmd, dst, name) \ 100bf215546Sopenharmony_ci for (struct cmd name = {}, \ 101bf215546Sopenharmony_ci *_dst = (void *)(dst); __builtin_expect(_dst != NULL, 1); \ 102bf215546Sopenharmony_ci __genxml_cmd_pack(cmd)(batch, (void *)_dst, &name), \ 103bf215546Sopenharmony_ci _dst = NULL) 104bf215546Sopenharmony_ci 105bf215546Sopenharmony_ci#define iris_pack_state(cmd, dst, name) \ 106bf215546Sopenharmony_ci _iris_pack_state(NULL, cmd, dst, name) 107bf215546Sopenharmony_ci 108bf215546Sopenharmony_ci#define iris_emit_cmd(batch, cmd, name) \ 109bf215546Sopenharmony_ci _iris_pack_command(batch, cmd, __gen_get_batch_dwords(batch, __genxml_cmd_length(cmd)), name) 110bf215546Sopenharmony_ci 111bf215546Sopenharmony_ci#define iris_emit_merge(batch, dwords0, dwords1, num_dwords) \ 112bf215546Sopenharmony_ci do { \ 113bf215546Sopenharmony_ci uint32_t *dw = __gen_get_batch_dwords(batch, num_dwords); \ 114bf215546Sopenharmony_ci for (uint32_t i = 0; i < num_dwords; i++) \ 115bf215546Sopenharmony_ci dw[i] = (dwords0)[i] | (dwords1)[i]; \ 116bf215546Sopenharmony_ci VG(VALGRIND_CHECK_MEM_IS_DEFINED(dw, num_dwords)); \ 117bf215546Sopenharmony_ci } while (0) 118bf215546Sopenharmony_ci 119bf215546Sopenharmony_ci#define iris_emit_reg(batch, reg, name) \ 120bf215546Sopenharmony_ci for (struct reg name = {}, *_cont = (struct reg *)1; _cont != NULL; \ 121bf215546Sopenharmony_ci ({ \ 122bf215546Sopenharmony_ci uint32_t _dw[__genxml_cmd_length(reg)]; \ 123bf215546Sopenharmony_ci __genxml_cmd_pack(reg)(NULL, _dw, &name); \ 124bf215546Sopenharmony_ci for (unsigned i = 0; i < __genxml_cmd_length(reg); i++) { \ 125bf215546Sopenharmony_ci iris_emit_cmd(batch, GENX(MI_LOAD_REGISTER_IMM), lri) { \ 126bf215546Sopenharmony_ci lri.RegisterOffset = __genxml_reg_num(reg); \ 127bf215546Sopenharmony_ci lri.DataDWord = _dw[i]; \ 128bf215546Sopenharmony_ci } \ 129bf215546Sopenharmony_ci } \ 130bf215546Sopenharmony_ci _cont = NULL; \ 131bf215546Sopenharmony_ci })) 132bf215546Sopenharmony_ci 133bf215546Sopenharmony_ci 134bf215546Sopenharmony_ci/** 135bf215546Sopenharmony_ci * iris_address constructor helpers: 136bf215546Sopenharmony_ci * 137bf215546Sopenharmony_ci * When using these to construct a CSO, pass NULL for \p bo, and manually 138bf215546Sopenharmony_ci * pin the BO later. Otherwise, genxml's address handling will add the 139bf215546Sopenharmony_ci * BO to the current batch's validation list at CSO creation time, rather 140bf215546Sopenharmony_ci * than at draw time as desired. 141bf215546Sopenharmony_ci */ 142bf215546Sopenharmony_ci 143bf215546Sopenharmony_ciUNUSED static struct iris_address 144bf215546Sopenharmony_ciro_bo(struct iris_bo *bo, uint64_t offset) 145bf215546Sopenharmony_ci{ 146bf215546Sopenharmony_ci return (struct iris_address) { .bo = bo, .offset = offset, 147bf215546Sopenharmony_ci .access = IRIS_DOMAIN_OTHER_READ }; 148bf215546Sopenharmony_ci} 149bf215546Sopenharmony_ci 150bf215546Sopenharmony_ciUNUSED static struct iris_address 151bf215546Sopenharmony_cirw_bo(struct iris_bo *bo, uint64_t offset, enum iris_domain access) 152bf215546Sopenharmony_ci{ 153bf215546Sopenharmony_ci return (struct iris_address) { .bo = bo, .offset = offset, 154bf215546Sopenharmony_ci .access = access }; 155bf215546Sopenharmony_ci} 156