2022-11-10 17:58:55 +08:00
|
|
|
/*
|
2025-03-19 21:56:18 +08:00
|
|
|
* Copyright (C) 2022-2025 Intel Corporation
|
2022-11-10 17:58:55 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "shared/source/command_stream/linear_stream.h"
|
|
|
|
#include "shared/source/helpers/register_offsets.h"
|
|
|
|
#include "shared/source/helpers/string.h"
|
|
|
|
|
2025-03-19 21:56:18 +08:00
|
|
|
#include <array>
|
|
|
|
#include <tuple>
|
|
|
|
|
2022-11-10 17:58:55 +08:00
|
|
|
namespace NEO {
|
2023-11-30 18:36:43 +08:00
|
|
|
template <typename GfxFamily, size_t aluCount>
|
2022-11-10 17:58:55 +08:00
|
|
|
class EncodeAluHelper {
|
|
|
|
public:
|
|
|
|
using MI_MATH_ALU_INST_INLINE = typename GfxFamily::MI_MATH_ALU_INST_INLINE;
|
|
|
|
using MI_MATH = typename GfxFamily::MI_MATH;
|
|
|
|
|
2025-03-19 21:56:18 +08:00
|
|
|
using OperandTupleT = std::tuple<AluRegisters, AluRegisters, AluRegisters>;
|
|
|
|
using OperandArrayT = std::array<OperandTupleT, aluCount>;
|
|
|
|
|
|
|
|
constexpr EncodeAluHelper() {
|
2022-11-10 17:58:55 +08:00
|
|
|
aluOps.miMath.DW0.BitField.InstructionType = MI_MATH::COMMAND_TYPE_MI_COMMAND;
|
|
|
|
aluOps.miMath.DW0.BitField.InstructionOpcode = MI_MATH::MI_COMMAND_OPCODE_MI_MATH;
|
2023-11-30 18:36:43 +08:00
|
|
|
aluOps.miMath.DW0.BitField.DwordLength = aluCount - 1;
|
2022-11-10 17:58:55 +08:00
|
|
|
}
|
|
|
|
|
2025-03-19 21:56:18 +08:00
|
|
|
consteval EncodeAluHelper(OperandArrayT inputParams) : EncodeAluHelper() {
|
|
|
|
for (auto ¶m : inputParams) {
|
|
|
|
auto &[opcode, operand1, operand2] = param;
|
|
|
|
if (opcode == AluRegisters::opcodeNone) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
setNextAlu(opcode, operand1, operand2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-28 00:21:40 +08:00
|
|
|
void setMocs([[maybe_unused]] uint32_t mocs) {
|
|
|
|
if constexpr (GfxFamily::isUsingMiMathMocs) {
|
|
|
|
aluOps.miMath.DW0.BitField.MemoryObjectControlState = mocs;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-03-19 21:56:18 +08:00
|
|
|
constexpr void setNextAlu(AluRegisters opcode) {
|
2023-12-19 15:40:17 +08:00
|
|
|
setNextAlu(opcode, AluRegisters::opcodeNone, AluRegisters::opcodeNone);
|
2022-11-10 17:58:55 +08:00
|
|
|
}
|
|
|
|
|
2025-03-19 21:56:18 +08:00
|
|
|
constexpr void setNextAlu(AluRegisters opcode, AluRegisters operand1, AluRegisters operand2) {
|
2022-11-10 17:58:55 +08:00
|
|
|
aluOps.aliInst[aluIndex].DW0.BitField.ALUOpcode = static_cast<uint32_t>(opcode);
|
|
|
|
aluOps.aliInst[aluIndex].DW0.BitField.Operand1 = static_cast<uint32_t>(operand1);
|
|
|
|
aluOps.aliInst[aluIndex].DW0.BitField.Operand2 = static_cast<uint32_t>(operand2);
|
|
|
|
|
|
|
|
aluIndex++;
|
|
|
|
}
|
2025-03-19 21:56:18 +08:00
|
|
|
void copyToCmdStream(LinearStream &cmdStream) const {
|
2023-11-30 18:36:43 +08:00
|
|
|
UNRECOVERABLE_IF(aluIndex != aluCount);
|
2022-11-10 17:58:55 +08:00
|
|
|
|
|
|
|
auto cmds = cmdStream.getSpace(sizeof(AluOps));
|
|
|
|
memcpy_s(cmds, sizeof(AluOps), &aluOps, sizeof(AluOps));
|
|
|
|
}
|
|
|
|
|
|
|
|
static constexpr size_t getCmdsSize() {
|
2023-11-30 18:36:43 +08:00
|
|
|
return (sizeof(MI_MATH) + (aluCount * sizeof(MI_MATH_ALU_INST_INLINE)));
|
2022-11-10 17:58:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
struct alignas(1) AluOps {
|
|
|
|
MI_MATH miMath = {};
|
2023-11-30 18:36:43 +08:00
|
|
|
MI_MATH_ALU_INST_INLINE aliInst[aluCount];
|
2022-11-10 17:58:55 +08:00
|
|
|
} aluOps;
|
|
|
|
|
|
|
|
size_t aluIndex = 0;
|
|
|
|
|
|
|
|
static_assert(sizeof(AluOps) == getCmdsSize(), "This structure is consumed by GPU and must follow specific restrictions for padding and size");
|
|
|
|
};
|
2023-11-30 18:36:43 +08:00
|
|
|
} // namespace NEO
|