summaryrefslogtreecommitdiffstats
path: root/src/shader_recompiler/frontend
diff options
context:
space:
mode:
authorFernandoS27 <fsahmkow27@gmail.com>2021-03-30 08:41:21 +0200
committerameerj <52414509+ameerj@users.noreply.github.com>2021-07-23 03:51:25 +0200
commit4d0d29fc2092bf02e102b8bac9cfa1b509274901 (patch)
tree97fbee1b64a0e5d8189cac30e8dd0a1a72a8ec4a /src/shader_recompiler/frontend
parentshader: Always pass a lod for TexelFetch (diff)
downloadyuzu-4d0d29fc2092bf02e102b8bac9cfa1b509274901.tar
yuzu-4d0d29fc2092bf02e102b8bac9cfa1b509274901.tar.gz
yuzu-4d0d29fc2092bf02e102b8bac9cfa1b509274901.tar.bz2
yuzu-4d0d29fc2092bf02e102b8bac9cfa1b509274901.tar.lz
yuzu-4d0d29fc2092bf02e102b8bac9cfa1b509274901.tar.xz
yuzu-4d0d29fc2092bf02e102b8bac9cfa1b509274901.tar.zst
yuzu-4d0d29fc2092bf02e102b8bac9cfa1b509274901.zip
Diffstat (limited to 'src/shader_recompiler/frontend')
-rw-r--r--src/shader_recompiler/frontend/maxwell/translate/impl/texture_gradient.cpp34
-rw-r--r--src/shader_recompiler/frontend/maxwell/translate/impl/texture_load.cpp10
-rw-r--r--src/shader_recompiler/frontend/maxwell/translate/impl/texture_mipmap_level.cpp26
3 files changed, 33 insertions, 37 deletions
diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/texture_gradient.cpp b/src/shader_recompiler/frontend/maxwell/translate/impl/texture_gradient.cpp
index 00768e167..c66468a48 100644
--- a/src/shader_recompiler/frontend/maxwell/translate/impl/texture_gradient.cpp
+++ b/src/shader_recompiler/frontend/maxwell/translate/impl/texture_gradient.cpp
@@ -47,7 +47,7 @@ Shader::TextureType GetType(TextureType type, bool dc) {
IR::Value MakeOffset(TranslatorVisitor& v, IR::Reg reg, bool has_lod_clamp) {
const IR::U32 value{v.X(reg)};
- const u32 base = has_lod_clamp ? 12 : 16;
+ const u32 base{has_lod_clamp ? 12U : 16U};
return v.ir.CompositeConstruct(
v.ir.BitFieldExtract(value, v.ir.Imm32(base), v.ir.Imm32(4), true),
v.ir.BitFieldExtract(value, v.ir.Imm32(base + 4), v.ir.Imm32(4), true));
@@ -74,20 +74,21 @@ void Impl(TranslatorVisitor& v, u64 insn, bool is_bindless) {
}
IR::Value coords;
- u32 num_derivates;
- IR::Reg base_reg = txd.coord_reg;
+ u32 num_derivates{};
+ IR::Reg base_reg{txd.coord_reg};
IR::Reg last_reg;
IR::Value handle;
- if (!is_bindless) {
- handle = v.ir.Imm32(static_cast<u32>(txd.cbuf_offset.Value() * 4));
- } else {
+ if (is_bindless) {
handle = v.X(base_reg++);
+ } else {
+ handle = v.ir.Imm32(static_cast<u32>(txd.cbuf_offset.Value() * 4));
}
const auto read_array{[&]() -> IR::F32 {
- return v.ir.ConvertUToF(32, 16,
- v.ir.BitFieldExtract(v.X(last_reg), v.ir.Imm32(0),
- v.ir.Imm32(has_lod_clamp ? 12 : 16)));
+ const IR::U32 base{v.ir.Imm32(0)};
+ const IR::U32 count{v.ir.Imm32(has_lod_clamp ? 12 : 16)};
+ const IR::U32 array_index{v.ir.BitFieldExtract(v.X(last_reg), base, count)};
+ return v.ir.ConvertUToF(32, 16, array_index);
}};
switch (txd.type) {
case TextureType::_1D: {
@@ -141,19 +142,20 @@ void Impl(TranslatorVisitor& v, u64 insn, bool is_bindless) {
IR::F32 lod_clamp;
if (has_lod_clamp) {
- const IR::F32 conv4_8fixp_f = v.ir.Imm32(Common::BitCast<f32>(0x3b800000U));
- const IR::F32 tmp = v.ir.ConvertUToF(
- 32, 16, v.ir.BitFieldExtract(v.X(last_reg), v.ir.Imm32(20), v.ir.Imm32(12)));
- lod_clamp = v.ir.FPMul(tmp, conv4_8fixp_f);
+ // Lod Clamp is a Fixed Point 4.8, we need to transform it to float.
+ // to convert a fixed point, float(value) / float(1 << fixed_point)
+ // in this case the fixed_point is 8.
+ const IR::F32 conv4_8fixp_f{v.ir.Imm32(static_cast<f32>(1U << 8))};
+ const IR::F32 fixp_lc{v.ir.ConvertUToF(
+ 32, 16, v.ir.BitFieldExtract(v.X(last_reg), v.ir.Imm32(20), v.ir.Imm32(12)))};
+ lod_clamp = v.ir.FPMul(fixp_lc, conv4_8fixp_f);
}
IR::TextureInstInfo info{};
info.type.Assign(GetType(txd.type, false));
info.num_derivates.Assign(num_derivates);
info.has_lod_clamp.Assign(has_lod_clamp ? 1 : 0);
- const IR::Value sample{[&]() -> IR::Value {
- return v.ir.ImageGradient(handle, coords, derivates, offset, lod_clamp, info);
- }()};
+ const IR::Value sample{v.ir.ImageGradient(handle, coords, derivates, offset, lod_clamp, info)};
IR::Reg dest_reg{txd.dest_reg};
for (size_t element = 0; element < 4; ++element) {
diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/texture_load.cpp b/src/shader_recompiler/frontend/maxwell/translate/impl/texture_load.cpp
index df38f87a3..987b7ec34 100644
--- a/src/shader_recompiler/frontend/maxwell/translate/impl/texture_load.cpp
+++ b/src/shader_recompiler/frontend/maxwell/translate/impl/texture_load.cpp
@@ -117,10 +117,10 @@ void Impl(TranslatorVisitor& v, u64 insn, bool is_bindless) {
IR::Value offset;
IR::U32 lod;
IR::U32 multisample;
- if (!is_bindless) {
- handle = v.ir.Imm32(static_cast<u32>(tld.cbuf_offset.Value() * 4));
- } else {
+ if (is_bindless) {
handle = v.X(meta_reg++);
+ } else {
+ handle = v.ir.Imm32(static_cast<u32>(tld.cbuf_offset.Value() * 4));
}
if (tld.lod != 0) {
lod = v.X(meta_reg++);
@@ -138,9 +138,7 @@ void Impl(TranslatorVisitor& v, u64 insn, bool is_bindless) {
}
IR::TextureInstInfo info{};
info.type.Assign(GetType(tld.type, false));
- const IR::Value sample{[&]() -> IR::Value {
- return v.ir.ImageFetch(handle, coords, offset, lod, multisample, info);
- }()};
+ const IR::Value sample{v.ir.ImageFetch(handle, coords, offset, lod, multisample, info)};
IR::Reg dest_reg{tld.dest_reg};
for (size_t element = 0; element < 4; ++element) {
diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/texture_mipmap_level.cpp b/src/shader_recompiler/frontend/maxwell/translate/impl/texture_mipmap_level.cpp
index ee13ede30..b6efc04f0 100644
--- a/src/shader_recompiler/frontend/maxwell/translate/impl/texture_mipmap_level.cpp
+++ b/src/shader_recompiler/frontend/maxwell/translate/impl/texture_mipmap_level.cpp
@@ -81,39 +81,35 @@ void Impl(TranslatorVisitor& v, u64 insn, bool is_bindless) {
BitField<36, 13, u64> cbuf_offset;
} const tmml{insn};
- if ((tmml.mask & 0xC) != 0) {
+ if ((tmml.mask & 0b1100) != 0) {
throw NotImplementedException("TMML BA results are not implmented");
}
- IR::F32 transform_constant = v.ir.Imm32(256.0f);
+ IR::F32 transform_constant{v.ir.Imm32(256.0f)};
const IR::Value coords{MakeCoords(v, tmml.coord_reg, tmml.type)};
IR::U32 handle;
IR::Reg meta_reg{tmml.meta_reg};
- if (!is_bindless) {
- handle = v.ir.Imm32(static_cast<u32>(tmml.cbuf_offset.Value() * 4));
- } else {
+ if (is_bindless) {
handle = v.X(meta_reg++);
+ } else {
+ handle = v.ir.Imm32(static_cast<u32>(tmml.cbuf_offset.Value() * 4));
}
IR::TextureInstInfo info{};
info.type.Assign(GetType(tmml.type, false));
- const IR::Value sample{
- [&]() -> IR::Value { return v.ir.ImageQueryLod(handle, coords, info); }()};
+ const IR::Value sample{v.ir.ImageQueryLod(handle, coords, info)};
- const IR::FpControl fp_control{
- .no_contraction{false},
- .rounding{IR::FpRounding::RP},
- .fmz_mode{IR::FmzMode::FTZ},
- };
IR::Reg dest_reg{tmml.dest_reg};
for (size_t element = 0; element < 4; ++element) {
if (((tmml.mask >> element) & 1) == 0) {
continue;
}
- IR::F32 value = IR::F32{v.ir.CompositeExtract(sample, element)};
- v.F(dest_reg,
- element < 2 ? IR::F32{v.ir.FPMul(value, transform_constant, fp_control)} : value);
+ IR::F32 value{v.ir.CompositeExtract(sample, element)};
+ if (element < 2) {
+ value = v.ir.FPMul(value, transform_constant);
+ }
+ v.F(dest_reg, value);
++dest_reg;
}
}