Merge pull request #344 from bunnei/shader-decompiler-p2
Shader decompiler changes part 2
This commit is contained in:
		@@ -4,6 +4,7 @@
 | 
			
		||||
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include <cstring>
 | 
			
		||||
#include <map>
 | 
			
		||||
#include <string>
 | 
			
		||||
#include "common/bit_field.h"
 | 
			
		||||
@@ -12,14 +13,10 @@ namespace Tegra {
 | 
			
		||||
namespace Shader {
 | 
			
		||||
 | 
			
		||||
struct Register {
 | 
			
		||||
    Register() = default;
 | 
			
		||||
    constexpr Register() = default;
 | 
			
		||||
 | 
			
		||||
    constexpr Register(u64 value) : value(value) {}
 | 
			
		||||
 | 
			
		||||
    constexpr u64 GetIndex() const {
 | 
			
		||||
        return value;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    constexpr operator u64() const {
 | 
			
		||||
        return value;
 | 
			
		||||
    }
 | 
			
		||||
@@ -43,13 +40,13 @@ struct Register {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    u64 value;
 | 
			
		||||
    u64 value{};
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
union Attribute {
 | 
			
		||||
    Attribute() = default;
 | 
			
		||||
 | 
			
		||||
    constexpr Attribute(u64 value) : value(value) {}
 | 
			
		||||
    constexpr explicit Attribute(u64 value) : value(value) {}
 | 
			
		||||
 | 
			
		||||
    enum class Index : u64 {
 | 
			
		||||
        Position = 7,
 | 
			
		||||
@@ -68,7 +65,20 @@ union Attribute {
 | 
			
		||||
    } fmt28;
 | 
			
		||||
 | 
			
		||||
    BitField<39, 8, u64> reg;
 | 
			
		||||
    u64 value;
 | 
			
		||||
    u64 value{};
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
union Sampler {
 | 
			
		||||
    Sampler() = default;
 | 
			
		||||
 | 
			
		||||
    constexpr explicit Sampler(u64 value) : value(value) {}
 | 
			
		||||
 | 
			
		||||
    enum class Index : u64 {
 | 
			
		||||
        Sampler_0 = 8,
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    BitField<36, 13, Index> index;
 | 
			
		||||
    u64 value{};
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
union Uniform {
 | 
			
		||||
@@ -238,7 +248,7 @@ union OpCode {
 | 
			
		||||
    BitField<55, 9, Id> op3;
 | 
			
		||||
    BitField<52, 12, Id> op4;
 | 
			
		||||
    BitField<51, 13, Id> op5;
 | 
			
		||||
    u64 value;
 | 
			
		||||
    u64 value{};
 | 
			
		||||
};
 | 
			
		||||
static_assert(sizeof(OpCode) == 0x8, "Incorrect structure size");
 | 
			
		||||
 | 
			
		||||
@@ -280,6 +290,7 @@ enum class SubOp : u64 {
 | 
			
		||||
    Lg2 = 0x3,
 | 
			
		||||
    Rcp = 0x4,
 | 
			
		||||
    Rsq = 0x5,
 | 
			
		||||
    Min = 0x8,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
union Instruction {
 | 
			
		||||
@@ -295,15 +306,25 @@ union Instruction {
 | 
			
		||||
    BitField<20, 8, Register> gpr20;
 | 
			
		||||
    BitField<20, 7, SubOp> sub_op;
 | 
			
		||||
    BitField<28, 8, Register> gpr28;
 | 
			
		||||
    BitField<36, 13, u64> imm36;
 | 
			
		||||
    BitField<39, 8, Register> gpr39;
 | 
			
		||||
 | 
			
		||||
    union {
 | 
			
		||||
        BitField<20, 19, u64> imm20;
 | 
			
		||||
        BitField<45, 1, u64> negate_b;
 | 
			
		||||
        BitField<46, 1, u64> abs_a;
 | 
			
		||||
        BitField<48, 1, u64> negate_a;
 | 
			
		||||
        BitField<49, 1, u64> abs_b;
 | 
			
		||||
        BitField<50, 1, u64> abs_d;
 | 
			
		||||
        BitField<56, 1, u64> negate_imm;
 | 
			
		||||
 | 
			
		||||
        float GetImm20() const {
 | 
			
		||||
            float result{};
 | 
			
		||||
            u32 imm{static_cast<u32>(imm20)};
 | 
			
		||||
            imm <<= 12;
 | 
			
		||||
            imm |= negate_imm ? 0x80000000 : 0;
 | 
			
		||||
            std::memcpy(&result, &imm, sizeof(imm));
 | 
			
		||||
            return result;
 | 
			
		||||
        }
 | 
			
		||||
    } alu;
 | 
			
		||||
 | 
			
		||||
    union {
 | 
			
		||||
@@ -311,11 +332,13 @@ union Instruction {
 | 
			
		||||
        BitField<49, 1, u64> negate_c;
 | 
			
		||||
    } ffma;
 | 
			
		||||
 | 
			
		||||
    BitField<61, 1, u64> is_b_imm;
 | 
			
		||||
    BitField<60, 1, u64> is_b_gpr;
 | 
			
		||||
    BitField<59, 1, u64> is_c_gpr;
 | 
			
		||||
 | 
			
		||||
    Attribute attribute;
 | 
			
		||||
    Uniform uniform;
 | 
			
		||||
    Sampler sampler;
 | 
			
		||||
 | 
			
		||||
    u64 hex;
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user