[DXBC] ALU scalar ops to new codegen

This commit is contained in:
Triang3l 2020-05-10 20:57:33 +03:00
parent ef37cbb955
commit 814990f686
3 changed files with 358 additions and 1050 deletions

View File

@ -1092,6 +1092,7 @@ class DxbcShaderTranslator : public ShaderTranslator {
kEndLoop = 22,
kEndSwitch = 23,
kEq = 24,
kExp = 25,
kFrc = 26,
kFToI = 27,
kFToU = 28,
@ -1107,6 +1108,7 @@ class DxbcShaderTranslator : public ShaderTranslator {
kIShL = 41,
kIToF = 43,
kLabel = 44,
kLog = 47,
kLoop = 48,
kLT = 49,
kMAd = 50,
@ -1123,7 +1125,10 @@ class DxbcShaderTranslator : public ShaderTranslator {
kRoundNE = 64,
kRoundNI = 65,
kRoundZ = 67,
kRSq = 68,
kSqRt = 75,
kSwitch = 76,
kSinCos = 77,
kULT = 79,
kUGE = 80,
kUMul = 81,
@ -1216,6 +1221,19 @@ class DxbcShaderTranslator : public ShaderTranslator {
src3.Write(shader_code_, (src_are_integer & 0b1000) != 0, dest_write_mask);
++stat_.instruction_count;
}
void DxbcEmitAluOp(DxbcOpcode opcode, uint32_t src_are_integer,
const DxbcDest& dest0, const DxbcDest& dest1,
const DxbcSrc& src, bool saturate = false) {
uint32_t dest_write_mask = dest0.GetMask() | dest1.GetMask();
uint32_t operands_length =
dest0.GetLength() + dest1.GetLength() + src.GetLength(dest_write_mask);
shader_code_.reserve(shader_code_.size() + 1 + operands_length);
shader_code_.push_back(DxbcOpcodeToken(opcode, operands_length, saturate));
dest0.Write(shader_code_);
dest1.Write(shader_code_);
src.Write(shader_code_, (src_are_integer & 0b1) != 0, dest_write_mask);
++stat_.instruction_count;
}
void DxbcEmitAluOp(DxbcOpcode opcode, uint32_t src_are_integer,
const DxbcDest& dest0, const DxbcDest& dest1,
const DxbcSrc& src0, const DxbcSrc& src1,
@ -1355,6 +1373,11 @@ class DxbcShaderTranslator : public ShaderTranslator {
DxbcEmitAluOp(DxbcOpcode::kEq, 0b00, dest, src0, src1);
++stat_.float_instruction_count;
}
void DxbcOpExp(const DxbcDest& dest, const DxbcSrc& src,
bool saturate = false) {
DxbcEmitAluOp(DxbcOpcode::kExp, 0b0, dest, src, saturate);
++stat_.float_instruction_count;
}
void DxbcOpFrc(const DxbcDest& dest, const DxbcSrc& src,
bool saturate = false) {
DxbcEmitAluOp(DxbcOpcode::kFrc, 0b0, dest, src, saturate);
@ -1431,6 +1454,11 @@ class DxbcShaderTranslator : public ShaderTranslator {
label.Write(shader_code_, true, 0b0000);
// Doesn't count towards stat_.instruction_count.
}
void DxbcOpLog(const DxbcDest& dest, const DxbcSrc& src,
bool saturate = false) {
DxbcEmitAluOp(DxbcOpcode::kLog, 0b0, dest, src, saturate);
++stat_.float_instruction_count;
}
void DxbcOpLoop() {
shader_code_.push_back(DxbcOpcodeToken(DxbcOpcode::kLoop, 0));
++stat_.instruction_count;
@ -1516,10 +1544,25 @@ class DxbcShaderTranslator : public ShaderTranslator {
DxbcEmitAluOp(DxbcOpcode::kRoundZ, 0b0, dest, src, saturate);
++stat_.float_instruction_count;
}
void DxbcOpRSq(const DxbcDest& dest, const DxbcSrc& src,
bool saturate = false) {
DxbcEmitAluOp(DxbcOpcode::kRSq, 0b0, dest, src, saturate);
++stat_.float_instruction_count;
}
void DxbcOpSqRt(const DxbcDest& dest, const DxbcSrc& src,
bool saturate = false) {
DxbcEmitAluOp(DxbcOpcode::kSqRt, 0b0, dest, src, saturate);
++stat_.float_instruction_count;
}
void DxbcOpSwitch(const DxbcSrc& src) {
DxbcEmitFlowOp(DxbcOpcode::kSwitch, src);
++stat_.dynamic_flow_control_count;
}
void DxbcOpSinCos(const DxbcDest& dest_sin, const DxbcDest& dest_cos,
const DxbcSrc& src, bool saturate = false) {
DxbcEmitAluOp(DxbcOpcode::kSinCos, 0b0, dest_sin, dest_cos, src, saturate);
++stat_.float_instruction_count;
}
void DxbcOpULT(const DxbcDest& dest, const DxbcSrc& src0,
const DxbcSrc& src1) {
DxbcEmitAluOp(DxbcOpcode::kULT, 0b11, dest, src0, src1);
@ -2206,7 +2249,7 @@ class DxbcShaderTranslator : public ShaderTranslator {
void ProcessVectorAluOperation(const ParsedAluInstruction& instr,
uint32_t& result_swizzle,
bool& predicate_written);
bool ProcessScalarAluOperation(const ParsedAluInstruction& instr,
void ProcessScalarAluOperation(const ParsedAluInstruction& instr,
bool& predicate_written);
// Appends a string to a DWORD stream, returns the DWORD-aligned length.

File diff suppressed because it is too large Load Diff

View File

@ -810,16 +810,14 @@ enum class AluScalarOpcode : uint32_t {
// Floating-Point Maximum with Copy To Integer in AR
// maxas dest, src0.ab
// movas/MOVAs dest, src0.aa
// int result = (int)floor(src0.a + 0.5);
// a0 = clamp(result, -256, 255);
// a0 = (int)clamp(floor(src0.a + 0.5), -256.0, 255.0);
// dest.xyzw = src0.a >= src0.b ? src0.a : src0.b;
kMaxAs = 23,
// Floating-Point Maximum with Copy Truncated To Integer in AR
// maxasf dest, src0.ab
// movasf/MOVA_FLOORs dest, src0.aa
// int result = (int)floor(src0.a);
// a0 = clamp(result, -256, 255);
// a0 = (int)clamp(floor(src0.a), -256.0, 255.0);
// dest.xyzw = src0.a >= src0.b ? src0.a : src0.b;
kMaxAsf = 24,