mirror of
https://github.com/yuzu-mirror/yuzu.git
synced 2024-09-07 23:39:07 +01:00
glsl: Fix integer conversions, implement clamp CC
This commit is contained in:
parent
21797efa54
commit
86d4a05cec
2 changed files with 36 additions and 27 deletions
|
@ -30,12 +30,12 @@ void EmitConvertS32F16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::I
|
|||
|
||||
void EmitConvertS32F32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
ctx.AddS32("{}=int({});", inst, value);
|
||||
ctx.AddS32("{}=int(float({}));", inst, value);
|
||||
}
|
||||
|
||||
void EmitConvertS32F64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
ctx.AddS32("{}=int({});", inst, value);
|
||||
ctx.AddS32("{}=int(double({}));", inst, value);
|
||||
}
|
||||
|
||||
void EmitConvertS64F16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
|
@ -45,12 +45,12 @@ void EmitConvertS64F16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::I
|
|||
|
||||
void EmitConvertS64F32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
ctx.AddS64("{}=int64_t(double({}));", inst, value);
|
||||
ctx.AddS64("{}=int64_t(double(float({})));", inst, value);
|
||||
}
|
||||
|
||||
void EmitConvertS64F64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
ctx.AddS64("{}=int64_t({});", inst, value);
|
||||
ctx.AddS64("{}=int64_t(double({}));", inst, value);
|
||||
}
|
||||
|
||||
void EmitConvertU16F16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
|
@ -75,12 +75,12 @@ void EmitConvertU32F16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::I
|
|||
|
||||
void EmitConvertU32F32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
ctx.AddU32("{}=uint({});", inst, value);
|
||||
ctx.AddU32("{}=uint(float({}));", inst, value);
|
||||
}
|
||||
|
||||
void EmitConvertU32F64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
ctx.AddU32("{}=uint({});", inst, value);
|
||||
ctx.AddU32("{}=uint(double({}));", inst, value);
|
||||
}
|
||||
|
||||
void EmitConvertU64F16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
|
@ -90,22 +90,22 @@ void EmitConvertU64F16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::I
|
|||
|
||||
void EmitConvertU64F32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
ctx.AddU64("{}=uint64_t(double({}));", inst, value);
|
||||
ctx.AddU64("{}=uint64_t(float({}));", inst, value);
|
||||
}
|
||||
|
||||
void EmitConvertU64F64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
ctx.AddU64("{}=uint64_t({});", inst, value);
|
||||
ctx.AddU64("{}=uint64_t(double({}));", inst, value);
|
||||
}
|
||||
|
||||
void EmitConvertU64U32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
ctx.AddU64("{}=uint64_t({});", inst, value);
|
||||
ctx.AddU64("{}=uint64_t(uint({}));", inst, value);
|
||||
}
|
||||
|
||||
void EmitConvertU32U64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
ctx.AddU32("{}=uint({});", inst, value);
|
||||
ctx.AddU32("{}=uint(uint64_t({}));", inst, value);
|
||||
}
|
||||
|
||||
void EmitConvertF16F32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
|
@ -120,12 +120,12 @@ void EmitConvertF32F16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::I
|
|||
|
||||
void EmitConvertF32F64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
ctx.AddF32("{}=float({});", inst, value);
|
||||
ctx.AddF32("{}=float(double({}));", inst, value);
|
||||
}
|
||||
|
||||
void EmitConvertF64F32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
ctx.AddF64("{}=double({});", inst, value);
|
||||
ctx.AddF64("{}=double(float({}));", inst, value);
|
||||
}
|
||||
|
||||
void EmitConvertF16S8([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
|
@ -180,12 +180,12 @@ void EmitConvertF32S16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::I
|
|||
|
||||
void EmitConvertF32S32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
ctx.AddF32("{}=float({});", inst, value);
|
||||
ctx.AddF32("{}=float(int({}));", inst, value);
|
||||
}
|
||||
|
||||
void EmitConvertF32S64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
ctx.AddF32("{}=float({});", inst, value);
|
||||
ctx.AddF32("{}=float(double(int64_t({})));", inst, value);
|
||||
}
|
||||
|
||||
void EmitConvertF32U8([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
|
@ -195,17 +195,17 @@ void EmitConvertF32U8([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::In
|
|||
|
||||
void EmitConvertF32U16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
ctx.AddF32("{}=float({});", inst, value);
|
||||
ctx.AddF32("{}=float(uint({}));", inst, value);
|
||||
}
|
||||
|
||||
void EmitConvertF32U32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
ctx.AddF32("{}=float({});", inst, value);
|
||||
ctx.AddF32("{}=float(uint({}));", inst, value);
|
||||
}
|
||||
|
||||
void EmitConvertF32U64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
ctx.AddF32("{}=float({});", inst, value);
|
||||
ctx.AddF32("{}=float(double(uint64_t({})));", inst, value);
|
||||
}
|
||||
|
||||
void EmitConvertF64S8([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
|
@ -220,12 +220,12 @@ void EmitConvertF64S16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::I
|
|||
|
||||
void EmitConvertF64S32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
ctx.AddF64("{}=double({});", inst, value);
|
||||
ctx.AddF64("{}=double(int({}));", inst, value);
|
||||
}
|
||||
|
||||
void EmitConvertF64S64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
ctx.AddF64("{}=double({});", inst, value);
|
||||
ctx.AddF64("{}=double(int64_t({}));", inst, value);
|
||||
}
|
||||
|
||||
void EmitConvertF64U8([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
|
@ -240,12 +240,12 @@ void EmitConvertF64U16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::I
|
|||
|
||||
void EmitConvertF64U32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
ctx.AddF64("{}=double({});", inst, value);
|
||||
ctx.AddF64("{}=double(uint({}));", inst, value);
|
||||
}
|
||||
|
||||
void EmitConvertF64U64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view value) {
|
||||
ctx.AddF64("{}=double({});", inst, value);
|
||||
ctx.AddF64("{}=double(uint64_t({}));", inst, value);
|
||||
}
|
||||
|
||||
} // namespace Shader::Backend::GLSL
|
||||
|
|
|
@ -72,11 +72,11 @@ void EmitINeg64(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
|||
}
|
||||
|
||||
void EmitIAbs32(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU32("{}=abs({});", inst, value);
|
||||
ctx.AddU32("{}=abs(int({}));", inst, value);
|
||||
}
|
||||
|
||||
void EmitIAbs64(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
|
||||
ctx.AddU64("{}=abs({});", inst, value);
|
||||
ctx.AddU64("{}=abs(int64_t({}));", inst, value);
|
||||
}
|
||||
|
||||
void EmitShiftLeftLogical32(EmitContext& ctx, IR::Inst& inst, std::string_view base,
|
||||
|
@ -128,13 +128,16 @@ void EmitBitFieldInsert(EmitContext& ctx, IR::Inst& inst, std::string_view base,
|
|||
|
||||
void EmitBitFieldSExtract(EmitContext& ctx, IR::Inst& inst, std::string_view base,
|
||||
std::string_view offset, std::string_view count) {
|
||||
ctx.AddU32("{}=bitfieldExtract(int({}), int({}), int({}));", inst, base, offset, count);
|
||||
const auto result{ctx.reg_alloc.Define(inst, Type::U32)};
|
||||
ctx.Add("{}=uint(bitfieldExtract(int({}),int({}),int({})));", result, base, offset, count);
|
||||
SetZeroFlag(ctx, inst, result);
|
||||
SetSignFlag(ctx, inst, result);
|
||||
}
|
||||
|
||||
void EmitBitFieldUExtract(EmitContext& ctx, IR::Inst& inst, std::string_view base,
|
||||
std::string_view offset, std::string_view count) {
|
||||
const auto result{ctx.reg_alloc.Define(inst, Type::U32)};
|
||||
ctx.Add("{}=bitfieldExtract({},int({}),int({}));", result, base, offset, count);
|
||||
ctx.Add("{}=uint(bitfieldExtract(uint({}),int({}),int({})));", result, base, offset, count);
|
||||
SetZeroFlag(ctx, inst, result);
|
||||
SetSignFlag(ctx, inst, result);
|
||||
}
|
||||
|
@ -179,12 +182,18 @@ void EmitUMax32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::strin
|
|||
|
||||
void EmitSClamp32(EmitContext& ctx, IR::Inst& inst, std::string_view value, std::string_view min,
|
||||
std::string_view max) {
|
||||
ctx.AddU32("{}=clamp(int({}), int({}), int({}));", inst, value, min, max);
|
||||
const auto result{ctx.reg_alloc.Define(inst, Type::U32)};
|
||||
ctx.Add("{}=clamp(int({}), int({}), int({}));", result, value, min, max);
|
||||
SetZeroFlag(ctx, inst, result);
|
||||
SetSignFlag(ctx, inst, result);
|
||||
}
|
||||
|
||||
void EmitUClamp32(EmitContext& ctx, IR::Inst& inst, std::string_view value, std::string_view min,
|
||||
std::string_view max) {
|
||||
ctx.AddU32("{}=clamp(uint({}), uint({}), uint({}));", inst, value, min, max);
|
||||
const auto result{ctx.reg_alloc.Define(inst, Type::U32)};
|
||||
ctx.Add("{}=clamp(uint({}), uint({}), uint({}));", result, value, min, max);
|
||||
SetZeroFlag(ctx, inst, result);
|
||||
SetSignFlag(ctx, inst, result);
|
||||
}
|
||||
|
||||
void EmitSLessThan(EmitContext& ctx, IR::Inst& inst, std::string_view lhs, std::string_view rhs) {
|
||||
|
|
Loading…
Reference in a new issue