Skip to content

Instantly share code, notes, and snippets.

@Subv
Created June 26, 2015 22:29
Show Gist options
  • Select an option

  • Save Subv/5475d034c1e2d5565b63 to your computer and use it in GitHub Desktop.

Select an option

Save Subv/5475d034c1e2d5565b63 to your computer and use it in GitHub Desktop.
Nihstro patch
diff --git a/include/nihstro/shader_bytecode.h b/include/nihstro/shader_bytecode.h
index 4b609eb..5686c6c 100644
--- a/include/nihstro/shader_bytecode.h
+++ b/include/nihstro/shader_bytecode.h
@@ -380,8 +380,7 @@ struct OpCode {
}
const Info& GetInfo() const {
- static const OpCode::Info unknown_instruction = { OpCode::Type::Unknown, 0, "UNK" };
- static const OpCode::Info dummy = { OpCode::Type::Unknown, 0, "DMY" };
+ #define unknown_instruction { OpCode::Type::Unknown, 0, "UNK" }
static const OpCode::Info info_table[] = {
{ OpCode::Type::Arithmetic, OpCode::Info::TwoArguments, "add" },
{ OpCode::Type::Arithmetic, OpCode::Info::TwoArguments, "dp3" },
@@ -430,18 +429,26 @@ struct OpCode {
{ OpCode::Type::Conditional, OpCode::Info::JMPC, "jmpc" },
{ OpCode::Type::Conditional, OpCode::Info::JMPU, "jmpu" },
{ OpCode::Type::Arithmetic, OpCode::Info::Compare, "cmp" },
- dummy,
+ { OpCode::Type::Arithmetic, OpCode::Info::Compare, "cmp" },
+ { OpCode::Type::MultiplyAdd, OpCode::Info::SrcInversed, "madi" },
+ { OpCode::Type::MultiplyAdd, OpCode::Info::SrcInversed, "madi" },
+ { OpCode::Type::MultiplyAdd, OpCode::Info::SrcInversed, "madi" },
+ { OpCode::Type::MultiplyAdd, OpCode::Info::SrcInversed, "madi" },
+ { OpCode::Type::MultiplyAdd, OpCode::Info::SrcInversed, "madi" },
+ { OpCode::Type::MultiplyAdd, OpCode::Info::SrcInversed, "madi" },
{ OpCode::Type::MultiplyAdd, OpCode::Info::SrcInversed, "madi" },
- dummy,
- dummy,
- dummy,
- dummy,
- dummy,
- dummy,
- dummy,
+ { OpCode::Type::MultiplyAdd, OpCode::Info::SrcInversed, "madi" },
+ { OpCode::Type::MultiplyAdd, 0, "mad" },
+ { OpCode::Type::MultiplyAdd, 0, "mad" },
+ { OpCode::Type::MultiplyAdd, 0, "mad" },
+ { OpCode::Type::MultiplyAdd, 0, "mad" },
+ { OpCode::Type::MultiplyAdd, 0, "mad" },
+ { OpCode::Type::MultiplyAdd, 0, "mad" },
+ { OpCode::Type::MultiplyAdd, 0, "mad" },
{ OpCode::Type::MultiplyAdd, 0, "mad" }
};
- return info_table[(int)EffectiveOpCode()];
+ #undef unknown_instruction
+ return info_table[value];
}
operator Id() const {
@@ -613,7 +620,7 @@ union Instruction {
return src2i;
}
}
-
+
const SourceRegister GetSrc3(bool is_inverted) const {
if (!is_inverted) {
return src3;
@@ -627,7 +634,7 @@ union Instruction {
BitField<0x05, 0x5, SourceRegister> src3;
BitField<0x0a, 0x7, SourceRegister> src2;
BitField<0x11, 0x7, SourceRegister> src1;
-
+
BitField<0x05, 0x7, SourceRegister> src3i;
BitField<0x0c, 0x5, SourceRegister> src2i;
@@ -653,24 +660,15 @@ union SwizzlePattern {
};
Selector GetSelectorSrc1(int comp) const {
- Selector selectors[] = {
- src1_selector_0, src1_selector_1, src1_selector_2, src1_selector_3
- };
- return selectors[comp];
+ return static_cast<Selector>((hex >> (11 - (2 * comp))) & 0x3);
}
Selector GetSelectorSrc2(int comp) const {
- Selector selectors[] = {
- src2_selector_0, src2_selector_1, src2_selector_2, src2_selector_3
- };
- return selectors[comp];
+ return static_cast<Selector>((hex >> (20 - (2 * comp))) & 0x3);
}
Selector GetSelectorSrc3(int comp) const {
- Selector selectors[] = {
- src3_selector_0, src3_selector_1, src3_selector_2, src3_selector_3
- };
- return selectors[comp];
+ return static_cast<Selector>((hex >> (29 - (2 * comp))) & 0x3);
}
void SetSelectorSrc1(int comp, Selector value) {
@@ -714,9 +712,6 @@ union SwizzlePattern {
}
bool DestComponentEnabled(unsigned int i) const {
- if (i >= 4)
- throw std::out_of_range("index needs to be smaller than 4");
-
return (dest_mask & (0x8 >> i));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment