summaryrefslogtreecommitdiffstats
path: root/src/shader_recompiler/frontend
diff options
context:
space:
mode:
authorFernandoS27 <fsahmkow27@gmail.com>2021-04-04 06:47:14 +0200
committerameerj <52414509+ameerj@users.noreply.github.com>2021-07-23 03:51:26 +0200
commit1d51803169f72f79e19995072fb9e8a371dbdcbf (patch)
treeeb668d924985e4b0bd599a695a0a2eee30fd0090 /src/shader_recompiler/frontend
parentshader: Implement AL2P (diff)
downloadyuzu-1d51803169f72f79e19995072fb9e8a371dbdcbf.tar
yuzu-1d51803169f72f79e19995072fb9e8a371dbdcbf.tar.gz
yuzu-1d51803169f72f79e19995072fb9e8a371dbdcbf.tar.bz2
yuzu-1d51803169f72f79e19995072fb9e8a371dbdcbf.tar.lz
yuzu-1d51803169f72f79e19995072fb9e8a371dbdcbf.tar.xz
yuzu-1d51803169f72f79e19995072fb9e8a371dbdcbf.tar.zst
yuzu-1d51803169f72f79e19995072fb9e8a371dbdcbf.zip
Diffstat (limited to 'src/shader_recompiler/frontend')
-rw-r--r--src/shader_recompiler/frontend/ir/ir_emitter.cpp8
-rw-r--r--src/shader_recompiler/frontend/ir/ir_emitter.h3
-rw-r--r--src/shader_recompiler/frontend/maxwell/program.cpp2
-rw-r--r--src/shader_recompiler/frontend/maxwell/translate/impl/load_store_attribute.cpp38
4 files changed, 37 insertions, 14 deletions
diff --git a/src/shader_recompiler/frontend/ir/ir_emitter.cpp b/src/shader_recompiler/frontend/ir/ir_emitter.cpp
index ed1e0dd3b..e4e9b260c 100644
--- a/src/shader_recompiler/frontend/ir/ir_emitter.cpp
+++ b/src/shader_recompiler/frontend/ir/ir_emitter.cpp
@@ -307,6 +307,14 @@ void IREmitter::SetAttribute(IR::Attribute attribute, const F32& value) {
Inst(Opcode::SetAttribute, attribute, value);
}
+F32 IREmitter::GetAttributeIndexed(IR::U32 phys_address) {
+ return Inst<F32>(Opcode::GetAttributeIndexed, phys_address);
+}
+
+void IREmitter::SetAttributeIndexed(IR::U32 phys_address, const F32& value) {
+ Inst(Opcode::SetAttributeIndexed, phys_address, value);
+}
+
void IREmitter::SetFragColor(u32 index, u32 component, const F32& value) {
Inst(Opcode::SetFragColor, Imm32(index), Imm32(component), value);
}
diff --git a/src/shader_recompiler/frontend/ir/ir_emitter.h b/src/shader_recompiler/frontend/ir/ir_emitter.h
index 42756af43..afa8bd924 100644
--- a/src/shader_recompiler/frontend/ir/ir_emitter.h
+++ b/src/shader_recompiler/frontend/ir/ir_emitter.h
@@ -76,6 +76,9 @@ public:
[[nodiscard]] F32 GetAttribute(IR::Attribute attribute);
void SetAttribute(IR::Attribute attribute, const F32& value);
+ [[nodiscard]] F32 GetAttributeIndexed(IR::U32 phys_address);
+ void SetAttributeIndexed(IR::U32 phys_address, const F32& value);
+
void SetFragColor(u32 index, u32 component, const F32& value);
void SetFragDepth(const F32& value);
diff --git a/src/shader_recompiler/frontend/maxwell/program.cpp b/src/shader_recompiler/frontend/maxwell/program.cpp
index 58caa35a1..aaf2a74a7 100644
--- a/src/shader_recompiler/frontend/maxwell/program.cpp
+++ b/src/shader_recompiler/frontend/maxwell/program.cpp
@@ -87,7 +87,7 @@ IR::Program TranslateProgram(ObjectPool<IR::Inst>& inst_pool, ObjectPool<IR::Blo
Optimization::DeadCodeEliminationPass(program);
Optimization::IdentityRemovalPass(program);
Optimization::VerificationPass(program);
- Optimization::CollectShaderInfoPass(program);
+ Optimization::CollectShaderInfoPass(env, program);
CollectInterpolationInfo(env, program);
return program;
}
diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/load_store_attribute.cpp b/src/shader_recompiler/frontend/maxwell/translate/impl/load_store_attribute.cpp
index 54bc1e34c..0d248c020 100644
--- a/src/shader_recompiler/frontend/maxwell/translate/impl/load_store_attribute.cpp
+++ b/src/shader_recompiler/frontend/maxwell/translate/impl/load_store_attribute.cpp
@@ -31,7 +31,7 @@ enum class SampleMode : u64 {
Offset,
};
-int NumElements(Size size) {
+u32 NumElements(Size size) {
switch (size) {
case Size::B32:
return 1;
@@ -65,15 +65,21 @@ void TranslatorVisitor::ALD(u64 insn) {
if (ald.patch != 0) {
throw NotImplementedException("P");
}
- if (ald.index_reg != IR::Reg::RZ) {
- throw NotImplementedException("Indexed");
- }
const u64 offset{ald.absolute_offset.Value()};
if (offset % 4 != 0) {
throw NotImplementedException("Unaligned absolute offset {}", offset);
}
- const int num_elements{NumElements(ald.size)};
- for (int element = 0; element < num_elements; ++element) {
+ const u32 num_elements{NumElements(ald.size)};
+ if (ald.index_reg != IR::Reg::RZ) {
+ const IR::U32 index_value = X(ald.index_reg);
+ for (u32 element = 0; element < num_elements; ++element) {
+ const IR::U32 final_offset =
+ element == 0 ? index_value : IR::U32{ir.IAdd(index_value, ir.Imm32(element * 4U))};
+ F(ald.dest_reg + element, ir.GetAttributeIndexed(final_offset));
+ }
+ return;
+ }
+ for (u32 element = 0; element < num_elements; ++element) {
F(ald.dest_reg + element, ir.GetAttribute(IR::Attribute{offset / 4 + element}));
}
}
@@ -103,8 +109,17 @@ void TranslatorVisitor::AST(u64 insn) {
if (offset % 4 != 0) {
throw NotImplementedException("Unaligned absolute offset {}", offset);
}
- const int num_elements{NumElements(ast.size)};
- for (int element = 0; element < num_elements; ++element) {
+ const u32 num_elements{NumElements(ast.size)};
+ if (ast.index_reg != IR::Reg::RZ) {
+ const IR::U32 index_value = X(ast.index_reg);
+ for (u32 element = 0; element < num_elements; ++element) {
+ const IR::U32 final_offset =
+ element == 0 ? index_value : IR::U32{ir.IAdd(index_value, ir.Imm32(element * 4U))};
+ ir.SetAttributeIndexed(final_offset, F(ast.src_reg + element));
+ }
+ return;
+ }
+ for (u32 element = 0; element < num_elements; ++element) {
ir.SetAttribute(IR::Attribute{offset / 4 + element}, F(ast.src_reg + element));
}
}
@@ -134,12 +149,9 @@ void TranslatorVisitor::IPA(u64 insn) {
// gl_FragColor = colors[idx];
// }
const bool is_indexed{ipa.idx != 0 && ipa.index_reg != IR::Reg::RZ};
- if (is_indexed) {
- throw NotImplementedException("IDX");
- }
-
const IR::Attribute attribute{ipa.attribute};
- IR::F32 value{ir.GetAttribute(attribute)};
+ IR::F32 value{is_indexed ? ir.GetAttributeIndexed(X(ipa.index_reg))
+ : ir.GetAttribute(attribute)};
if (IR::IsGeneric(attribute)) {
const ProgramHeader& sph{env.SPH()};
const u32 attr_index{IR::GenericAttributeIndex(attribute)};