diff options
| author | 2021-05-28 16:32:01 -0400 | |
|---|---|---|
| committer | 2021-07-22 21:51:36 -0400 | |
| commit | 86d4a05cec42becd60ad68205ca7f190e3fcbed9 (patch) | |
| tree | 2c4373972c4ceebeb480d464c2a3497efed272a7 /src | |
| parent | glsl: Implement IADD CC (diff) | |
| download | yuzu-86d4a05cec42becd60ad68205ca7f190e3fcbed9.tar.gz yuzu-86d4a05cec42becd60ad68205ca7f190e3fcbed9.tar.xz yuzu-86d4a05cec42becd60ad68205ca7f190e3fcbed9.zip | |
glsl: Fix integer conversions, implement clamp CC
Diffstat (limited to 'src')
| -rw-r--r-- | src/shader_recompiler/backend/glsl/emit_glsl_convert.cpp | 42 | ||||
| -rw-r--r-- | src/shader_recompiler/backend/glsl/emit_glsl_integer.cpp | 21 |
2 files changed, 36 insertions, 27 deletions
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_convert.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_convert.cpp index c27965ef0..fa1b02af1 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_convert.cpp +++ b/src/shader_recompiler/backend/glsl/emit_glsl_convert.cpp | |||
| @@ -30,12 +30,12 @@ void EmitConvertS32F16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::I | |||
| 30 | 30 | ||
| 31 | void EmitConvertS32F32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | 31 | void EmitConvertS32F32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, |
| 32 | [[maybe_unused]] std::string_view value) { | 32 | [[maybe_unused]] std::string_view value) { |
| 33 | ctx.AddS32("{}=int({});", inst, value); | 33 | ctx.AddS32("{}=int(float({}));", inst, value); |
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | void EmitConvertS32F64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | 36 | void EmitConvertS32F64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, |
| 37 | [[maybe_unused]] std::string_view value) { | 37 | [[maybe_unused]] std::string_view value) { |
| 38 | ctx.AddS32("{}=int({});", inst, value); | 38 | ctx.AddS32("{}=int(double({}));", inst, value); |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | void EmitConvertS64F16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | 41 | 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 | |||
| 45 | 45 | ||
| 46 | void EmitConvertS64F32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | 46 | void EmitConvertS64F32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, |
| 47 | [[maybe_unused]] std::string_view value) { | 47 | [[maybe_unused]] std::string_view value) { |
| 48 | ctx.AddS64("{}=int64_t(double({}));", inst, value); | 48 | ctx.AddS64("{}=int64_t(double(float({})));", inst, value); |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | void EmitConvertS64F64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | 51 | void EmitConvertS64F64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, |
| 52 | [[maybe_unused]] std::string_view value) { | 52 | [[maybe_unused]] std::string_view value) { |
| 53 | ctx.AddS64("{}=int64_t({});", inst, value); | 53 | ctx.AddS64("{}=int64_t(double({}));", inst, value); |
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | void EmitConvertU16F16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | 56 | 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 | |||
| 75 | 75 | ||
| 76 | void EmitConvertU32F32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | 76 | void EmitConvertU32F32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, |
| 77 | [[maybe_unused]] std::string_view value) { | 77 | [[maybe_unused]] std::string_view value) { |
| 78 | ctx.AddU32("{}=uint({});", inst, value); | 78 | ctx.AddU32("{}=uint(float({}));", inst, value); |
| 79 | } | 79 | } |
| 80 | 80 | ||
| 81 | void EmitConvertU32F64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | 81 | void EmitConvertU32F64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, |
| 82 | [[maybe_unused]] std::string_view value) { | 82 | [[maybe_unused]] std::string_view value) { |
| 83 | ctx.AddU32("{}=uint({});", inst, value); | 83 | ctx.AddU32("{}=uint(double({}));", inst, value); |
| 84 | } | 84 | } |
| 85 | 85 | ||
| 86 | void EmitConvertU64F16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | 86 | 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 | |||
| 90 | 90 | ||
| 91 | void EmitConvertU64F32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | 91 | void EmitConvertU64F32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, |
| 92 | [[maybe_unused]] std::string_view value) { | 92 | [[maybe_unused]] std::string_view value) { |
| 93 | ctx.AddU64("{}=uint64_t(double({}));", inst, value); | 93 | ctx.AddU64("{}=uint64_t(float({}));", inst, value); |
| 94 | } | 94 | } |
| 95 | 95 | ||
| 96 | void EmitConvertU64F64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | 96 | void EmitConvertU64F64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, |
| 97 | [[maybe_unused]] std::string_view value) { | 97 | [[maybe_unused]] std::string_view value) { |
| 98 | ctx.AddU64("{}=uint64_t({});", inst, value); | 98 | ctx.AddU64("{}=uint64_t(double({}));", inst, value); |
| 99 | } | 99 | } |
| 100 | 100 | ||
| 101 | void EmitConvertU64U32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | 101 | void EmitConvertU64U32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, |
| 102 | [[maybe_unused]] std::string_view value) { | 102 | [[maybe_unused]] std::string_view value) { |
| 103 | ctx.AddU64("{}=uint64_t({});", inst, value); | 103 | ctx.AddU64("{}=uint64_t(uint({}));", inst, value); |
| 104 | } | 104 | } |
| 105 | 105 | ||
| 106 | void EmitConvertU32U64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | 106 | void EmitConvertU32U64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, |
| 107 | [[maybe_unused]] std::string_view value) { | 107 | [[maybe_unused]] std::string_view value) { |
| 108 | ctx.AddU32("{}=uint({});", inst, value); | 108 | ctx.AddU32("{}=uint(uint64_t({}));", inst, value); |
| 109 | } | 109 | } |
| 110 | 110 | ||
| 111 | void EmitConvertF16F32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | 111 | 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 | |||
| 120 | 120 | ||
| 121 | void EmitConvertF32F64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | 121 | void EmitConvertF32F64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, |
| 122 | [[maybe_unused]] std::string_view value) { | 122 | [[maybe_unused]] std::string_view value) { |
| 123 | ctx.AddF32("{}=float({});", inst, value); | 123 | ctx.AddF32("{}=float(double({}));", inst, value); |
| 124 | } | 124 | } |
| 125 | 125 | ||
| 126 | void EmitConvertF64F32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | 126 | void EmitConvertF64F32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, |
| 127 | [[maybe_unused]] std::string_view value) { | 127 | [[maybe_unused]] std::string_view value) { |
| 128 | ctx.AddF64("{}=double({});", inst, value); | 128 | ctx.AddF64("{}=double(float({}));", inst, value); |
| 129 | } | 129 | } |
| 130 | 130 | ||
| 131 | void EmitConvertF16S8([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | 131 | 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 | |||
| 180 | 180 | ||
| 181 | void EmitConvertF32S32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | 181 | void EmitConvertF32S32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, |
| 182 | [[maybe_unused]] std::string_view value) { | 182 | [[maybe_unused]] std::string_view value) { |
| 183 | ctx.AddF32("{}=float({});", inst, value); | 183 | ctx.AddF32("{}=float(int({}));", inst, value); |
| 184 | } | 184 | } |
| 185 | 185 | ||
| 186 | void EmitConvertF32S64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | 186 | void EmitConvertF32S64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, |
| 187 | [[maybe_unused]] std::string_view value) { | 187 | [[maybe_unused]] std::string_view value) { |
| 188 | ctx.AddF32("{}=float({});", inst, value); | 188 | ctx.AddF32("{}=float(double(int64_t({})));", inst, value); |
| 189 | } | 189 | } |
| 190 | 190 | ||
| 191 | void EmitConvertF32U8([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | 191 | 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 | |||
| 195 | 195 | ||
| 196 | void EmitConvertF32U16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | 196 | void EmitConvertF32U16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, |
| 197 | [[maybe_unused]] std::string_view value) { | 197 | [[maybe_unused]] std::string_view value) { |
| 198 | ctx.AddF32("{}=float({});", inst, value); | 198 | ctx.AddF32("{}=float(uint({}));", inst, value); |
| 199 | } | 199 | } |
| 200 | 200 | ||
| 201 | void EmitConvertF32U32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | 201 | void EmitConvertF32U32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, |
| 202 | [[maybe_unused]] std::string_view value) { | 202 | [[maybe_unused]] std::string_view value) { |
| 203 | ctx.AddF32("{}=float({});", inst, value); | 203 | ctx.AddF32("{}=float(uint({}));", inst, value); |
| 204 | } | 204 | } |
| 205 | 205 | ||
| 206 | void EmitConvertF32U64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | 206 | void EmitConvertF32U64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, |
| 207 | [[maybe_unused]] std::string_view value) { | 207 | [[maybe_unused]] std::string_view value) { |
| 208 | ctx.AddF32("{}=float({});", inst, value); | 208 | ctx.AddF32("{}=float(double(uint64_t({})));", inst, value); |
| 209 | } | 209 | } |
| 210 | 210 | ||
| 211 | void EmitConvertF64S8([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | 211 | 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 | |||
| 220 | 220 | ||
| 221 | void EmitConvertF64S32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | 221 | void EmitConvertF64S32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, |
| 222 | [[maybe_unused]] std::string_view value) { | 222 | [[maybe_unused]] std::string_view value) { |
| 223 | ctx.AddF64("{}=double({});", inst, value); | 223 | ctx.AddF64("{}=double(int({}));", inst, value); |
| 224 | } | 224 | } |
| 225 | 225 | ||
| 226 | void EmitConvertF64S64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | 226 | void EmitConvertF64S64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, |
| 227 | [[maybe_unused]] std::string_view value) { | 227 | [[maybe_unused]] std::string_view value) { |
| 228 | ctx.AddF64("{}=double({});", inst, value); | 228 | ctx.AddF64("{}=double(int64_t({}));", inst, value); |
| 229 | } | 229 | } |
| 230 | 230 | ||
| 231 | void EmitConvertF64U8([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | 231 | 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 | |||
| 240 | 240 | ||
| 241 | void EmitConvertF64U32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | 241 | void EmitConvertF64U32([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, |
| 242 | [[maybe_unused]] std::string_view value) { | 242 | [[maybe_unused]] std::string_view value) { |
| 243 | ctx.AddF64("{}=double({});", inst, value); | 243 | ctx.AddF64("{}=double(uint({}));", inst, value); |
| 244 | } | 244 | } |
| 245 | 245 | ||
| 246 | void EmitConvertF64U64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | 246 | void EmitConvertF64U64([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, |
| 247 | [[maybe_unused]] std::string_view value) { | 247 | [[maybe_unused]] std::string_view value) { |
| 248 | ctx.AddF64("{}=double({});", inst, value); | 248 | ctx.AddF64("{}=double(uint64_t({}));", inst, value); |
| 249 | } | 249 | } |
| 250 | 250 | ||
| 251 | } // namespace Shader::Backend::GLSL | 251 | } // namespace Shader::Backend::GLSL |
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_integer.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_integer.cpp index 6ff0f9248..34f880f1b 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_integer.cpp +++ b/src/shader_recompiler/backend/glsl/emit_glsl_integer.cpp | |||
| @@ -72,11 +72,11 @@ void EmitINeg64(EmitContext& ctx, IR::Inst& inst, std::string_view value) { | |||
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | void EmitIAbs32(EmitContext& ctx, IR::Inst& inst, std::string_view value) { | 74 | void EmitIAbs32(EmitContext& ctx, IR::Inst& inst, std::string_view value) { |
| 75 | ctx.AddU32("{}=abs({});", inst, value); | 75 | ctx.AddU32("{}=abs(int({}));", inst, value); |
| 76 | } | 76 | } |
| 77 | 77 | ||
| 78 | void EmitIAbs64(EmitContext& ctx, IR::Inst& inst, std::string_view value) { | 78 | void EmitIAbs64(EmitContext& ctx, IR::Inst& inst, std::string_view value) { |
| 79 | ctx.AddU64("{}=abs({});", inst, value); | 79 | ctx.AddU64("{}=abs(int64_t({}));", inst, value); |
| 80 | } | 80 | } |
| 81 | 81 | ||
| 82 | void EmitShiftLeftLogical32(EmitContext& ctx, IR::Inst& inst, std::string_view base, | 82 | 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, | |||
| 128 | 128 | ||
| 129 | void EmitBitFieldSExtract(EmitContext& ctx, IR::Inst& inst, std::string_view base, | 129 | void EmitBitFieldSExtract(EmitContext& ctx, IR::Inst& inst, std::string_view base, |
| 130 | std::string_view offset, std::string_view count) { | 130 | std::string_view offset, std::string_view count) { |
| 131 | ctx.AddU32("{}=bitfieldExtract(int({}), int({}), int({}));", inst, base, offset, count); | 131 | const auto result{ctx.reg_alloc.Define(inst, Type::U32)}; |
| 132 | ctx.Add("{}=uint(bitfieldExtract(int({}),int({}),int({})));", result, base, offset, count); | ||
| 133 | SetZeroFlag(ctx, inst, result); | ||
| 134 | SetSignFlag(ctx, inst, result); | ||
| 132 | } | 135 | } |
| 133 | 136 | ||
| 134 | void EmitBitFieldUExtract(EmitContext& ctx, IR::Inst& inst, std::string_view base, | 137 | void EmitBitFieldUExtract(EmitContext& ctx, IR::Inst& inst, std::string_view base, |
| 135 | std::string_view offset, std::string_view count) { | 138 | std::string_view offset, std::string_view count) { |
| 136 | const auto result{ctx.reg_alloc.Define(inst, Type::U32)}; | 139 | const auto result{ctx.reg_alloc.Define(inst, Type::U32)}; |
| 137 | ctx.Add("{}=bitfieldExtract({},int({}),int({}));", result, base, offset, count); | 140 | ctx.Add("{}=uint(bitfieldExtract(uint({}),int({}),int({})));", result, base, offset, count); |
| 138 | SetZeroFlag(ctx, inst, result); | 141 | SetZeroFlag(ctx, inst, result); |
| 139 | SetSignFlag(ctx, inst, result); | 142 | SetSignFlag(ctx, inst, result); |
| 140 | } | 143 | } |
| @@ -179,12 +182,18 @@ void EmitUMax32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::strin | |||
| 179 | 182 | ||
| 180 | void EmitSClamp32(EmitContext& ctx, IR::Inst& inst, std::string_view value, std::string_view min, | 183 | void EmitSClamp32(EmitContext& ctx, IR::Inst& inst, std::string_view value, std::string_view min, |
| 181 | std::string_view max) { | 184 | std::string_view max) { |
| 182 | ctx.AddU32("{}=clamp(int({}), int({}), int({}));", inst, value, min, max); | 185 | const auto result{ctx.reg_alloc.Define(inst, Type::U32)}; |
| 186 | ctx.Add("{}=clamp(int({}), int({}), int({}));", result, value, min, max); | ||
| 187 | SetZeroFlag(ctx, inst, result); | ||
| 188 | SetSignFlag(ctx, inst, result); | ||
| 183 | } | 189 | } |
| 184 | 190 | ||
| 185 | void EmitUClamp32(EmitContext& ctx, IR::Inst& inst, std::string_view value, std::string_view min, | 191 | void EmitUClamp32(EmitContext& ctx, IR::Inst& inst, std::string_view value, std::string_view min, |
| 186 | std::string_view max) { | 192 | std::string_view max) { |
| 187 | ctx.AddU32("{}=clamp(uint({}), uint({}), uint({}));", inst, value, min, max); | 193 | const auto result{ctx.reg_alloc.Define(inst, Type::U32)}; |
| 194 | ctx.Add("{}=clamp(uint({}), uint({}), uint({}));", result, value, min, max); | ||
| 195 | SetZeroFlag(ctx, inst, result); | ||
| 196 | SetSignFlag(ctx, inst, result); | ||
| 188 | } | 197 | } |
| 189 | 198 | ||
| 190 | void EmitSLessThan(EmitContext& ctx, IR::Inst& inst, std::string_view lhs, std::string_view rhs) { | 199 | void EmitSLessThan(EmitContext& ctx, IR::Inst& inst, std::string_view lhs, std::string_view rhs) { |