yuzu-emu
/
yuzu-mainline
Archived
1
0
Fork 0

glsl: Implement more Integer ops

This commit is contained in:
ameerj 2021-05-21 21:37:13 -04:00
parent 266a3d60e3
commit ef7bd53f18
3 changed files with 72 additions and 119 deletions

View File

@ -210,8 +210,8 @@ void EmitSelectU64(EmitContext& ctx, std::string_view cond, std::string_view tru
std::string_view false_value); std::string_view false_value);
void EmitSelectF16(EmitContext& ctx, std::string_view cond, std::string_view true_value, void EmitSelectF16(EmitContext& ctx, std::string_view cond, std::string_view true_value,
std::string_view false_value); std::string_view false_value);
void EmitSelectF32(EmitContext& ctx, std::string_view cond, std::string_view true_value, void EmitSelectF32(EmitContext& ctx, IR::Inst& inst, std::string_view cond,
std::string_view false_value); std::string_view true_value, std::string_view false_value);
void EmitSelectF64(EmitContext& ctx, std::string_view cond, std::string_view true_value, void EmitSelectF64(EmitContext& ctx, std::string_view cond, std::string_view true_value,
std::string_view false_value); std::string_view false_value);
void EmitBitCastU16F16(EmitContext& ctx); void EmitBitCastU16F16(EmitContext& ctx);

View File

@ -10,136 +10,108 @@
#include "shader_recompiler/profile.h" #include "shader_recompiler/profile.h"
namespace Shader::Backend::GLSL { namespace Shader::Backend::GLSL {
void EmitIAdd32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, void EmitIAdd32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
[[maybe_unused]] std::string_view a, [[maybe_unused]] std::string_view b) {
ctx.AddU32("{}={}+{};", inst, a, b); ctx.AddU32("{}={}+{};", inst, a, b);
} }
void EmitIAdd64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, void EmitIAdd64(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
[[maybe_unused]] std::string_view a, [[maybe_unused]] std::string_view b) { ctx.AddU64("{}={}+{};", inst, a, b);
throw NotImplementedException("GLSL Instruction");
} }
void EmitISub32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, void EmitISub32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
[[maybe_unused]] std::string_view a, [[maybe_unused]] std::string_view b) {
ctx.AddU32("{}={}-{};", inst, a, b); ctx.AddU32("{}={}-{};", inst, a, b);
} }
void EmitISub64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, void EmitISub64(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
[[maybe_unused]] std::string_view a, [[maybe_unused]] std::string_view b) { ctx.AddU64("{}={}-{};", inst, a, b);
throw NotImplementedException("GLSL Instruction");
} }
void EmitIMul32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, void EmitIMul32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
[[maybe_unused]] std::string_view a, [[maybe_unused]] std::string_view b) { ctx.AddU32("{}={}*{};", inst, a, b);
throw NotImplementedException("GLSL Instruction");
} }
void EmitINeg32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, void EmitINeg32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
[[maybe_unused]] std::string_view value) {
ctx.AddU32("{}=-{};", inst, value); ctx.AddU32("{}=-{};", inst, value);
} }
void EmitINeg64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, void EmitINeg64(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
[[maybe_unused]] std::string_view value) { ctx.AddU64("{}=-{};", inst, value);
throw NotImplementedException("GLSL Instruction");
} }
void EmitIAbs32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, void EmitIAbs32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
[[maybe_unused]] std::string_view value) {
ctx.AddU32("{}=abs({});", inst, value); ctx.AddU32("{}=abs({});", inst, value);
} }
void EmitIAbs64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, void EmitIAbs64(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
[[maybe_unused]] std::string_view value) { ctx.AddU64("{}=abs({});", inst, value);
throw NotImplementedException("GLSL Instruction");
} }
void EmitShiftLeftLogical32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, void EmitShiftLeftLogical32(EmitContext& ctx, IR::Inst& inst, std::string_view base,
[[maybe_unused]] std::string_view base, std::string_view shift) {
[[maybe_unused]] std::string_view shift) {
ctx.AddU32("{}={}<<{};", inst, base, shift); ctx.AddU32("{}={}<<{};", inst, base, shift);
} }
void EmitShiftLeftLogical64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, void EmitShiftLeftLogical64(EmitContext& ctx, IR::Inst& inst, std::string_view base,
[[maybe_unused]] std::string_view base, std::string_view shift) {
[[maybe_unused]] std::string_view shift) {
ctx.AddU64("{}={}<<{};", inst, base, shift); ctx.AddU64("{}={}<<{};", inst, base, shift);
} }
void EmitShiftRightLogical32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, void EmitShiftRightLogical32(EmitContext& ctx, IR::Inst& inst, std::string_view base,
[[maybe_unused]] std::string_view base, std::string_view shift) {
[[maybe_unused]] std::string_view shift) {
ctx.AddU32("{}={}>>{};", inst, base, shift); ctx.AddU32("{}={}>>{};", inst, base, shift);
} }
void EmitShiftRightLogical64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, void EmitShiftRightLogical64(EmitContext& ctx, IR::Inst& inst, std::string_view base,
[[maybe_unused]] std::string_view base, std::string_view shift) {
[[maybe_unused]] std::string_view shift) {
ctx.AddU64("{}={}>>{};", inst, base, shift); ctx.AddU64("{}={}>>{};", inst, base, shift);
} }
void EmitShiftRightArithmetic32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, void EmitShiftRightArithmetic32(EmitContext& ctx, IR::Inst& inst, std::string_view base,
[[maybe_unused]] std::string_view base, std::string_view shift) {
[[maybe_unused]] std::string_view shift) {
ctx.AddS32("{}=int({})>>{};", inst, base, shift); ctx.AddS32("{}=int({})>>{};", inst, base, shift);
} }
void EmitShiftRightArithmetic64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, void EmitShiftRightArithmetic64(EmitContext& ctx, IR::Inst& inst, std::string_view base,
[[maybe_unused]] std::string_view base, std::string_view shift) {
[[maybe_unused]] std::string_view shift) {
ctx.AddU64("{}=int64_t({})>>{};", inst, base, shift); ctx.AddU64("{}=int64_t({})>>{};", inst, base, shift);
} }
void EmitBitwiseAnd32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, void EmitBitwiseAnd32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
[[maybe_unused]] std::string_view a, [[maybe_unused]] std::string_view b) {
ctx.AddU32("{}={}&{};", inst, a, b); ctx.AddU32("{}={}&{};", inst, a, b);
} }
void EmitBitwiseOr32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, void EmitBitwiseOr32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
[[maybe_unused]] std::string_view a, [[maybe_unused]] std::string_view b) {
ctx.AddU32("{}={}|{};", inst, a, b); ctx.AddU32("{}={}|{};", inst, a, b);
} }
void EmitBitwiseXor32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, void EmitBitwiseXor32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
[[maybe_unused]] std::string_view a, [[maybe_unused]] std::string_view b) {
ctx.AddU32("{}={}^{};", inst, a, b); ctx.AddU32("{}={}^{};", inst, a, b);
} }
void EmitBitFieldInsert([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, void EmitBitFieldInsert(EmitContext& ctx, IR::Inst& inst, std::string_view base,
[[maybe_unused]] std::string_view base, std::string_view insert, std::string_view offset, std::string_view count) {
[[maybe_unused]] std::string_view insert,
[[maybe_unused]] std::string_view offset,
[[maybe_unused]] std::string_view count) {
ctx.AddU32("{}=bitfieldInsert({}, {}, int({}), int({}));", inst, base, insert, offset, count); ctx.AddU32("{}=bitfieldInsert({}, {}, int({}), int({}));", inst, base, insert, offset, count);
} }
void EmitBitFieldSExtract([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, void EmitBitFieldSExtract(EmitContext& ctx, IR::Inst& inst, std::string_view base,
[[maybe_unused]] std::string_view base, std::string_view offset, std::string_view count) {
[[maybe_unused]] std::string_view offset,
[[maybe_unused]] std::string_view count) {
ctx.AddU32("{}=bitfieldExtract(int({}), int({}), int({}));", inst, base, offset, count); ctx.AddU32("{}=bitfieldExtract(int({}), int({}), int({}));", inst, base, offset, count);
} }
void EmitBitFieldUExtract([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, void EmitBitFieldUExtract(EmitContext& ctx, IR::Inst& inst, std::string_view base,
[[maybe_unused]] std::string_view base, std::string_view offset, std::string_view count) {
[[maybe_unused]] std::string_view offset,
[[maybe_unused]] std::string_view count) {
ctx.AddU32("{}=bitfieldExtract({}, int({}), int({}));", inst, base, offset, count); ctx.AddU32("{}=bitfieldExtract({}, int({}), int({}));", inst, base, offset, count);
} }
void EmitBitReverse32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, void EmitBitReverse32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
[[maybe_unused]] std::string_view value) {
ctx.AddU32("{}=bitfieldReverse({});", inst, value); ctx.AddU32("{}=bitfieldReverse({});", inst, value);
} }
void EmitBitCount32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, void EmitBitCount32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
[[maybe_unused]] std::string_view value) { ctx.AddU32("{}=bitCount({});", inst, value);
throw NotImplementedException("GLSL Instruction");
} }
void EmitBitwiseNot32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, void EmitBitwiseNot32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
[[maybe_unused]] std::string_view value) {
ctx.AddU32("{}=~{};", inst, value); ctx.AddU32("{}=~{};", inst, value);
} }
@ -153,91 +125,75 @@ void EmitFindUMsb32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst
throw NotImplementedException("GLSL Instruction"); throw NotImplementedException("GLSL Instruction");
} }
void EmitSMin32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, void EmitSMin32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
[[maybe_unused]] std::string_view a, [[maybe_unused]] std::string_view b) {
ctx.AddU32("{}=min(int({}), int({}));", inst, a, b); ctx.AddU32("{}=min(int({}), int({}));", inst, a, b);
} }
void EmitUMin32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, void EmitUMin32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
[[maybe_unused]] std::string_view a, [[maybe_unused]] std::string_view b) {
ctx.AddU32("{}=min(uint({}), uint({}));", inst, a, b); ctx.AddU32("{}=min(uint({}), uint({}));", inst, a, b);
} }
void EmitSMax32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, void EmitSMax32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
[[maybe_unused]] std::string_view a, [[maybe_unused]] std::string_view b) {
ctx.AddU32("{}=max(int({}), int({}));", inst, a, b); ctx.AddU32("{}=max(int({}), int({}));", inst, a, b);
} }
void EmitUMax32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, void EmitUMax32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
[[maybe_unused]] std::string_view a, [[maybe_unused]] std::string_view b) {
ctx.AddU32("{}=max(uint({}), uint({}));", inst, a, b); ctx.AddU32("{}=max(uint({}), uint({}));", inst, a, b);
} }
void EmitSClamp32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, void EmitSClamp32(EmitContext& ctx, IR::Inst& inst, std::string_view value, std::string_view min,
[[maybe_unused]] std::string_view value, [[maybe_unused]] std::string_view min, std::string_view max) {
[[maybe_unused]] std::string_view max) { ctx.AddU32("{}=clamp(int({}), int({}), int({}));", inst, value, min, max);
throw NotImplementedException("GLSL Instruction");
} }
void EmitUClamp32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, void EmitUClamp32(EmitContext& ctx, IR::Inst& inst, std::string_view value, std::string_view min,
[[maybe_unused]] std::string_view value, [[maybe_unused]] std::string_view min, std::string_view max) {
[[maybe_unused]] std::string_view max) { ctx.AddU32("{}=clamp(uint({}), uint({}), uint({}));", inst, value, min, max);
throw NotImplementedException("GLSL Instruction");
} }
void EmitSLessThan([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, void EmitSLessThan(EmitContext& ctx, IR::Inst& inst, std::string_view lhs, std::string_view rhs) {
[[maybe_unused]] std::string_view lhs, [[maybe_unused]] std::string_view rhs) {
ctx.AddU1("{}=int({})<int({});", inst, lhs, rhs); ctx.AddU1("{}=int({})<int({});", inst, lhs, rhs);
} }
void EmitULessThan([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, void EmitULessThan(EmitContext& ctx, IR::Inst& inst, std::string_view lhs, std::string_view rhs) {
[[maybe_unused]] std::string_view lhs, [[maybe_unused]] std::string_view rhs) {
ctx.AddU1("{}=uint({})<uint({)};", inst, lhs, rhs); ctx.AddU1("{}=uint({})<uint({)};", inst, lhs, rhs);
} }
void EmitIEqual([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, void EmitIEqual(EmitContext& ctx, IR::Inst& inst, std::string_view lhs, std::string_view rhs) {
[[maybe_unused]] std::string_view lhs, [[maybe_unused]] std::string_view rhs) {
ctx.AddU1("{}={}=={};", inst, lhs, rhs); ctx.AddU1("{}={}=={};", inst, lhs, rhs);
} }
void EmitSLessThanEqual([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, void EmitSLessThanEqual(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
[[maybe_unused]] std::string_view lhs, std::string_view rhs) {
[[maybe_unused]] std::string_view rhs) {
ctx.AddU1("{}=int({})<=int({});", inst, lhs, rhs); ctx.AddU1("{}=int({})<=int({});", inst, lhs, rhs);
} }
void EmitULessThanEqual([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, void EmitULessThanEqual(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
[[maybe_unused]] std::string_view lhs, std::string_view rhs) {
[[maybe_unused]] std::string_view rhs) {
ctx.AddU1("{}=uint({})<=uint({});", inst, lhs, rhs); ctx.AddU1("{}=uint({})<=uint({});", inst, lhs, rhs);
} }
void EmitSGreaterThan([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, void EmitSGreaterThan(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
[[maybe_unused]] std::string_view lhs, std::string_view rhs) {
[[maybe_unused]] std::string_view rhs) {
ctx.AddU1("{}=int({})>int({});", inst, lhs, rhs); ctx.AddU1("{}=int({})>int({});", inst, lhs, rhs);
} }
void EmitUGreaterThan([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, void EmitUGreaterThan(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
[[maybe_unused]] std::string_view lhs, std::string_view rhs) {
[[maybe_unused]] std::string_view rhs) {
ctx.AddU1("{}=uint({})>uint({});", inst, lhs, rhs); ctx.AddU1("{}=uint({})>uint({});", inst, lhs, rhs);
} }
void EmitINotEqual([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, void EmitINotEqual(EmitContext& ctx, IR::Inst& inst, std::string_view lhs, std::string_view rhs) {
[[maybe_unused]] std::string_view lhs, [[maybe_unused]] std::string_view rhs) {
ctx.AddU1("{}={}!={};", inst, lhs, rhs); ctx.AddU1("{}={}!={};", inst, lhs, rhs);
} }
void EmitSGreaterThanEqual([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, void EmitSGreaterThanEqual(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
[[maybe_unused]] std::string_view lhs, std::string_view rhs) {
[[maybe_unused]] std::string_view rhs) {
ctx.AddU1("{}=int({})>=int({});", inst, lhs, rhs); ctx.AddU1("{}=int({})>=int({});", inst, lhs, rhs);
} }
void EmitUGreaterThanEqual([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, void EmitUGreaterThanEqual(EmitContext& ctx, IR::Inst& inst, std::string_view lhs,
[[maybe_unused]] std::string_view lhs, std::string_view rhs) {
[[maybe_unused]] std::string_view rhs) {
ctx.AddU1("{}=uint({})>=uint({});", inst, lhs, rhs); ctx.AddU1("{}=uint({})>=uint({});", inst, lhs, rhs);
} }
} // namespace Shader::Backend::GLSL } // namespace Shader::Backend::GLSL

View File

@ -28,10 +28,8 @@ void EmitSelectU16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::stri
throw NotImplementedException("GLSL Instruction"); throw NotImplementedException("GLSL Instruction");
} }
void EmitSelectU32([[maybe_unused]] EmitContext& ctx, IR::Inst& inst, void EmitSelectU32(EmitContext& ctx, IR::Inst& inst, std::string_view cond,
[[maybe_unused]] std::string_view cond, std::string_view true_value, std::string_view false_value) {
[[maybe_unused]] std::string_view true_value,
[[maybe_unused]] std::string_view false_value) {
ctx.AddU32("{}={}?{}:{};", inst, cond, true_value, false_value); ctx.AddU32("{}={}?{}:{};", inst, cond, true_value, false_value);
} }
@ -47,10 +45,9 @@ void EmitSelectF16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::stri
throw NotImplementedException("GLSL Instruction"); throw NotImplementedException("GLSL Instruction");
} }
void EmitSelectF32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view cond, void EmitSelectF32(EmitContext& ctx, IR::Inst& inst, std::string_view cond,
[[maybe_unused]] std::string_view true_value, std::string_view true_value, std::string_view false_value) {
[[maybe_unused]] std::string_view false_value) { ctx.AddF32("{}={}?{}:{};", inst, cond, true_value, false_value);
throw NotImplementedException("GLSL Instruction");
} }
void EmitSelectF64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view cond, void EmitSelectF64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view cond,