Path: blob/21.2-virgl/src/gallium/drivers/crocus/crocus_genx_macros.h
4570 views
/*1* Copyright © 2019 Intel Corporation2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice shall be included11* in all copies or substantial portions of the Software.12*13* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS14* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,15* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL16* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER17* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING18* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER19* DEALINGS IN THE SOFTWARE.20*/2122/**23* Macro and function definitions needed in order to use genxml.24*25* This should only be included in sources compiled per-generation.26*/2728#include "crocus_batch.h"2930#include "genxml/gen_macros.h"3132#define __gen_address_type struct crocus_address33#define __gen_user_data struct crocus_batch34#define __gen_combine_address crocus_combine_address3536static inline void *37__gen_get_batch_dwords(struct crocus_batch *batch, unsigned dwords)38{39return crocus_get_command_space(batch, dwords * sizeof(uint32_t));40}4142static inline struct crocus_address43__gen_address_offset(struct crocus_address addr, uint64_t offset)44{45addr.offset += offset;46return addr;47}4849static uint64_t50__gen_combine_address(struct crocus_batch *batch, void *location,51struct crocus_address addr, uint32_t delta)52{53uint32_t offset = (char *)location - (char *)batch->command.map;5455if (addr.bo == NULL) {56return addr.offset + delta;57} else {58if (GFX_VER < 6 && crocus_ptr_in_state_buffer(batch, location)) {59offset = (char *) location - (char *) batch->state.map;60return crocus_state_reloc(batch, offset, addr.bo,61addr.offset + delta,62addr.reloc_flags);63}6465assert(!crocus_ptr_in_state_buffer(batch, location));6667offset = (char *) location - (char *) batch->command.map;68return crocus_command_reloc(batch, offset, addr.bo,69addr.offset + delta,70addr.reloc_flags);71}72}7374#define __gen_address_type struct crocus_address75#define __gen_user_data struct crocus_batch7677#define __genxml_cmd_length(cmd) cmd ## _length78#define __genxml_cmd_length_bias(cmd) cmd ## _length_bias79#define __genxml_cmd_header(cmd) cmd ## _header80#define __genxml_cmd_pack(cmd) cmd ## _pack81#define __genxml_reg_num(cmd) cmd ## _num8283#include "genxml/genX_pack.h"84#include "genxml/gen_macros.h"85#include "genxml/genX_bits.h"8687/* CS_GPR(15) is reserved for combining conditional rendering predicates88* with GL_ARB_indirect_parameters draw number predicates.89*/90#define MI_BUILDER_NUM_ALLOC_GPRS 1591#include "common/mi_builder.h"9293#define _crocus_pack_command(batch, cmd, dst, name) \94for (struct cmd name = { __genxml_cmd_header(cmd) }, \95*_dst = (void *)(dst); __builtin_expect(_dst != NULL, 1); \96({ __genxml_cmd_pack(cmd)(batch, (void *)_dst, &name); \97_dst = NULL; \98}))99100#define crocus_pack_command(cmd, dst, name) \101_crocus_pack_command(NULL, cmd, dst, name)102103#define _crocus_pack_state(batch, cmd, dst, name) \104for (struct cmd name = {}, \105*_dst = (void *)(dst); __builtin_expect(_dst != NULL, 1); \106__genxml_cmd_pack(cmd)(batch, (void *)_dst, &name), \107_dst = NULL)108109#define crocus_pack_state(cmd, dst, name) \110_crocus_pack_state(NULL, cmd, dst, name)111112#define crocus_emit_cmd(batch, cmd, name) \113_crocus_pack_command(batch, cmd, __gen_get_batch_dwords(batch, __genxml_cmd_length(cmd)), name)114115#define crocus_emit_merge(batch, dwords0, dwords1, num_dwords) \116do { \117uint32_t *dw = __gen_get_batch_dwords(batch, num_dwords); \118for (uint32_t i = 0; i < num_dwords; i++) \119dw[i] = (dwords0)[i] | (dwords1)[i]; \120VG(VALGRIND_CHECK_MEM_IS_DEFINED(dw, num_dwords)); \121} while (0)122123#define crocus_emit_reg(batch, reg, name) \124for (struct reg name = {}, *_cont = (struct reg *)1; _cont != NULL; \125({ \126uint32_t _dw[__genxml_cmd_length(reg)]; \127__genxml_cmd_pack(reg)(NULL, _dw, &name); \128for (unsigned i = 0; i < __genxml_cmd_length(reg); i++) { \129crocus_emit_cmd(batch, GENX(MI_LOAD_REGISTER_IMM), lri) { \130lri.RegisterOffset = __genxml_reg_num(reg); \131lri.DataDWord = _dw[i]; \132} \133} \134_cont = NULL; \135}))136137138/**139* crocus_address constructor helpers:140*141* When using these to construct a CSO, pass NULL for \p bo, and manually142* pin the BO later. Otherwise, genxml's address handling will add the143* BO to the current batch's validation list at CSO creation time, rather144* than at draw time as desired.145*/146147UNUSED static struct crocus_address148ro_bo(struct crocus_bo *bo, uint64_t offset)149{150return (struct crocus_address) { .bo = bo, .offset = offset, .reloc_flags = RELOC_32BIT };151}152153UNUSED static struct crocus_address154rw_bo(struct crocus_bo *bo, uint64_t offset)155{156return (struct crocus_address) { .bo = bo, .offset = offset, .reloc_flags = RELOC_32BIT | RELOC_WRITE };157}158159UNUSED static struct crocus_address160ggtt_bo(struct crocus_bo *bo, uint64_t offset)161{162return (struct crocus_address) { .bo = bo, .offset = offset, .reloc_flags = RELOC_WRITE | RELOC_NEEDS_GGTT };163}164165166