|
| 1 | +/* |
| 2 | + * Copyright (C) 2025 Intel Corporation |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: MIT |
| 5 | + * |
| 6 | + */ |
| 7 | + |
| 8 | +#pragma once |
| 9 | + |
| 10 | +#include "level_zero/ze_stypes.h" |
| 11 | +#include <level_zero/ze_api.h> |
| 12 | + |
| 13 | +/////////////////////////////////////////////////////////////////////////////// |
| 14 | +/// @brief Label handle. |
| 15 | +typedef struct _zex_label_handle_t *zex_label_handle_t; |
| 16 | + |
| 17 | +/////////////////////////////////////////////////////////////////////////////// |
| 18 | +/// @brief Label descriptor. |
| 19 | +typedef struct _zex_label_desc_t { |
| 20 | + ze_structure_type_ext_t stype = ZEX_STRUCTURE_TYPE_LABEL_DESCRIPTOR; ///< [in] type of this structure |
| 21 | + const void *pNext = nullptr; ///< [in][optional] pointer to extension-specific structure |
| 22 | + |
| 23 | + const char *name; ///< [in][optional] null-terminated name of the label |
| 24 | + uint32_t alignment; ///< [in][optional] minimum alignment of the label |
| 25 | +} zex_label_desc_t; |
| 26 | + |
| 27 | +/////////////////////////////////////////////////////////////////////////////// |
| 28 | +/// @brief Operand flags |
| 29 | +typedef uint32_t zex_operand_flags_t; |
| 30 | +typedef enum _zex_operand_flag_t { |
| 31 | + ZEX_OPERAND_FLAG_USES_VARIABLE = ZE_BIT(0), // variable is being used - passed via memory |
| 32 | + ZEX_OPERAND_FLAG_JUMP_ON_CLEAR = ZE_BIT(1) // jump on '0', instead of default '1' |
| 33 | +} zex_operand_flag_t; |
| 34 | + |
| 35 | +/////////////////////////////////////////////////////////////////////////////// |
| 36 | +/// @brief Operand descriptor. |
| 37 | +typedef struct _zex_operand_desc_t { |
| 38 | + ze_structure_type_ext_t stype = ZEX_STRUCTURE_TYPE_OPERAND_DESCRIPTOR; ///< [in] type of this structure |
| 39 | + const void *pNext = nullptr; ///< [in][optional] pointer to extension-specific structure |
| 40 | + |
| 41 | + void *memory; // if memory is NULL then offset is interpreted as MMIO |
| 42 | + // if flag ZEX_OPERAND_FLAG_USES_VARIABLE is set memory is interpreted as variable |
| 43 | + size_t offset; // offset within memory or register MMIO |
| 44 | + uint32_t size; // operand size - dword |
| 45 | + zex_operand_flags_t flags; // flags |
| 46 | +} zex_operand_desc_t; |
| 47 | + |
| 48 | +#if defined(__cplusplus) |
| 49 | +extern "C" { |
| 50 | +#endif |
| 51 | +/////////////////////////////////////////////////////////////////////////////// |
| 52 | +/// @brief Creates/returns label based on name provided in |
| 53 | +/// label descriptor. |
| 54 | +/// |
| 55 | +/// @details |
| 56 | +/// - When label with the name provided in label descriptor does not |
| 57 | +/// exist new label is created. |
| 58 | +/// - If label with provided name exists it's returned. |
| 59 | +/// - Label at creation is undefined (points to nothing). |
| 60 | +/// |
| 61 | +/// @returns |
| 62 | +/// - ZE_RESULT_SUCCESS |
| 63 | +/// - ZE_RESULT_ERROR_INVALID_ARGUMENT |
| 64 | +/// + nullptr == hCommandList |
| 65 | +/// + nullptr == pLabelDesc |
| 66 | +/// + nullptr == phLabel |
| 67 | +/// + pLabelDesc->alignment & (pLabelDesc->alignment - 1) != 0 |
| 68 | +/// - ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY |
| 69 | +/// + bad_alloc |
| 70 | +ze_result_t ZE_APICALL |
| 71 | +zexCommandListGetLabel( |
| 72 | + ze_command_list_handle_t hCommandList, ///< [in] handle of command list |
| 73 | + const zex_label_desc_t *pLabelDesc, ///< [in] pointer to label descriptor |
| 74 | + zex_label_handle_t *phLabel ///< [out] pointer to handle of label |
| 75 | +); |
| 76 | + |
| 77 | +/////////////////////////////////////////////////////////////////////////////// |
| 78 | +/// @brief Sets label to point to current location in command list. |
| 79 | +/// |
| 80 | +/// @details |
| 81 | +/// - Sets label address to current location. |
| 82 | +/// - All previous jumps to this label are patched with label's address. |
| 83 | +/// - Future jumps to this label will be patched with label's address. |
| 84 | +/// - Label can be set only once. |
| 85 | +/// - Label must be located in the same command list, as it was created |
| 86 | +/// |
| 87 | +/// @returns |
| 88 | +/// - ZE_RESULT_SUCCESS |
| 89 | +/// - ZE_RESULT_ERROR_INVALID_ARGUMENT |
| 90 | +/// + nullptr == hCommandList |
| 91 | +/// + nullptr == hLabel |
| 92 | +/// - ZE_RESULT_ERROR_UNSUPPORTED_FEATURE |
| 93 | +/// + variable already set |
| 94 | +/// - ZE_RESULT_ERROR_UNSUPPORTED_ALIGNMENT |
| 95 | +/// + label's address is not aligned to it's alignment |
| 96 | +ze_result_t ZE_APICALL |
| 97 | +zexCommandListSetLabel( |
| 98 | + ze_command_list_handle_t hCommandList, ///< [in] handle of command list |
| 99 | + zex_label_handle_t hLabel ///< [in] handle of label |
| 100 | +); |
| 101 | + |
| 102 | +/////////////////////////////////////////////////////////////////////////////// |
| 103 | +/// @brief Appends jump to label predicated by condition. |
| 104 | +/// |
| 105 | +/// @details |
| 106 | +/// If condition is present: |
| 107 | +/// If condition->memory is present: |
| 108 | +/// If ZEX_OPERAND_FLAG_USES_VARIABLE flag is set: |
| 109 | +/// - Append MI_LOAD_REGISTER_MEM |
| 110 | +/// reg = PREDICATE_RESULT_2 |
| 111 | +/// memAddr = gpu address of buffer variable |
| 112 | +/// Else: |
| 113 | +/// - Append MI_LOAD_REGISTER_MEM |
| 114 | +/// reg = PREDICATE_RESULT_2 |
| 115 | +/// memAddr = pCondition->memory + pCondition->offset |
| 116 | +/// Else: |
| 117 | +/// - Append MI_LOAD_REGISTER_REG |
| 118 | +/// regDst = PREDICATE_RESULT_2 |
| 119 | +/// regSrc = pCondition->offset (need to pass MMIO) |
| 120 | +/// |
| 121 | +/// If ZEX_OPERAND_FLAG_JUMP_ON_CLEAR flag is set: // jumps when '0' |
| 122 | +/// - Append MI_SET_PREDICATE(ENABLE_ON_SET) |
| 123 | +/// Else: // jumps when '1' |
| 124 | +/// - Append MI_SET_PREDICATE(ENABLE_ON_CLEAR) |
| 125 | +/// |
| 126 | +/// - Append MI_BATCH_BUFFER_START |
| 127 | +/// predicationEnabled = condition is present |
| 128 | +/// jumpAddress = label's address |
| 129 | +/// - Append MI_SET_PREDICATE(DISABLE) - after BB_START |
| 130 | +/// - Append MI_SET_PREDICATE(DISABLE) - at label's address |
| 131 | +/// |
| 132 | +/// @returns |
| 133 | +/// - ZE_RESULT_SUCCESS |
| 134 | +/// - ZE_RESULT_ERROR_INVALID_ARGUMENT |
| 135 | +/// + nullptr == hCommandList |
| 136 | +/// + nullptr == hLabel |
| 137 | +ze_result_t ZE_APICALL |
| 138 | +zexCommandListAppendJump( |
| 139 | + ze_command_list_handle_t hCommandList, ///< [in] handle of command list |
| 140 | + zex_label_handle_t hLabel, ///< [in] handle of label |
| 141 | + zex_operand_desc_t *pCondition ///< [in][opt] pointer to operand |
| 142 | +); |
| 143 | + |
| 144 | +typedef ze_result_t(ZE_APICALL *zex_pfnCommandListGetLabelCb_t)( |
| 145 | + ze_command_list_handle_t hCommandList, |
| 146 | + const zex_label_desc_t *pLabelDesc, |
| 147 | + zex_label_handle_t *phLabel); |
| 148 | + |
| 149 | +typedef ze_result_t(ZE_APICALL *zex_pfnCommandListSetLabelCb_t)( |
| 150 | + ze_command_list_handle_t hCommandList, |
| 151 | + zex_label_handle_t hLabel); |
| 152 | + |
| 153 | +typedef ze_result_t(ZE_APICALL *zex_pfnCommandListAppendJumpCb_t)( |
| 154 | + ze_command_list_handle_t hCommandList, |
| 155 | + zex_label_handle_t hLabel, |
| 156 | + zex_operand_desc_t *pCondition); |
| 157 | + |
| 158 | +#if defined(__cplusplus) |
| 159 | +} // extern "C" |
| 160 | +#endif |
0 commit comments