From 79e22369582f6aebe18a5864067135368084fb83 Mon Sep 17 00:00:00 2001
From: Philip Rebohle <philip.rebohle@tu-dortmund.de>
Date: Sun, 22 Oct 2017 23:13:29 +0200
Subject: [PATCH] [dxbc] Some more decoding stuff

---
 src/dxbc/dxbc_compiler.cpp |   2 +-
 src/dxbc/dxbc_compiler.h   |   2 -
 src/dxbc/dxbc_decoder.h    |  42 +++++++++++
 src/dxbc/dxbc_enums.h      | 140 ++++++++++++++++++++++++++++++++-----
 4 files changed, 165 insertions(+), 21 deletions(-)

diff --git a/src/dxbc/dxbc_compiler.cpp b/src/dxbc/dxbc_compiler.cpp
index 9868db30c..805e1e59e 100644
--- a/src/dxbc/dxbc_compiler.cpp
+++ b/src/dxbc/dxbc_compiler.cpp
@@ -17,7 +17,7 @@ namespace dxvk {
   
   
   bool DxbcCompiler::processInstruction(DxbcInstruction ins) {
-    return false;
+    
   }
   
   
diff --git a/src/dxbc/dxbc_compiler.h b/src/dxbc/dxbc_compiler.h
index fabb53a2c..70b5fba22 100644
--- a/src/dxbc/dxbc_compiler.h
+++ b/src/dxbc/dxbc_compiler.h
@@ -59,8 +59,6 @@ namespace dxvk {
     
     uint32_t m_entryPointId = 0;
     
-    bool handleDcl(DxbcInstruction ins);
-    
     void declareCapabilities();
     void declareMemoryModel();
     
diff --git a/src/dxbc/dxbc_decoder.h b/src/dxbc/dxbc_decoder.h
index f6554be81..ef6cb83d0 100644
--- a/src/dxbc/dxbc_decoder.h
+++ b/src/dxbc/dxbc_decoder.h
@@ -89,6 +89,15 @@ namespace dxvk {
     DxbcOpcodeTokenExt(uint32_t token)
     : m_token(token) { }
     
+    /**
+     * \brief Extended opcode
+     * \returns Extended opcode
+     */
+    DxbcExtOpcode opcode() const {
+      return static_cast<DxbcExtOpcode>(
+        bit::extract(m_token, 0, 5));
+    }
+    
     /**
      * \brief Control info
      * 
@@ -312,6 +321,39 @@ namespace dxvk {
   };
   
   
+  struct DxbcInstructionSampleControls {
+    int32_t uoffset;
+    int32_t voffset;
+    int32_t woffset;
+  };
+  
+  
+  struct DxbcInstructionResourceDim {
+    DxbcResourceDim dim;
+  };
+  
+  
+  struct DxbcInstructionResourceRet {
+    DxbcResourceReturnType x;
+    DxbcResourceReturnType y;
+    DxbcResourceReturnType z;
+    DxbcResourceReturnType w;
+  };
+  
+  
+  union DxbcInstructionModifierInfo {
+    DxbcInstructionSampleControls sampleControls;
+    DxbcInstructionResourceDim    resourceDim;
+    DxbcInstructionResourceRet    resourceRet;
+  };
+  
+  
+  struct DxbcInstructionModifier {
+    DxbcExtOpcode               code;
+    DxbcInstructionModifierInfo info;
+  };
+  
+  
   /**
    * \brief Instruction decoder
    * 
diff --git a/src/dxbc/dxbc_enums.h b/src/dxbc/dxbc_enums.h
index 944fd7feb..6d41be1ea 100644
--- a/src/dxbc/dxbc_enums.h
+++ b/src/dxbc/dxbc_enums.h
@@ -218,19 +218,23 @@ namespace dxvk {
   };
   
   
-  enum class DxbcOperandNumComponents : uint32_t {
-    Component0 = 0,
-    Component1 = 1,
-    Component4 = 2,
+  /**
+   * \brief Extended opcode
+   */
+  enum class DxbcExtOpcode : uint32_t {
+    Empty                                = 0,
+    SampleControls                       = 1,
+    ResourceDim                          = 2,
+    ResourceReturnType                   = 3,
   };
   
   
-  enum class DxbcOperandComponentSelectionMode : uint32_t {
-    Mask    = 0,
-    Swizzle = 1,
-    Select1 = 2,
-  };
-  
+  /**
+   * \brief Operand type
+   * 
+   * Selects the 'register file' from which
+   * to retrieve an operand's value.
+   */
   enum class DxbcOperandType : uint32_t {
     Temp                    = 0,
     Input                   = 1,
@@ -275,22 +279,122 @@ namespace dxvk {
     CycleCounter            = 40,
   };
   
+  
+  /**
+   * \brief Number of components
+   * 
+   * Used by operands to determine whether the
+   * operand has one, four or zero components.
+   */
+  enum class DxbcOperandNumComponents : uint32_t {
+    Component0 = 0,
+    Component1 = 1,
+    Component4 = 2,
+  };
+  
+  
+  /**
+   * \brief Component selection mode
+   * 
+   * When an operand has four components, the
+   * component selection mode deterines which
+   * components are used for the operation.
+   */
+  enum class DxbcOperandComponentSelectionMode : uint32_t {
+    Mask    = 0,
+    Swizzle = 1,
+    Select1 = 2,
+  };
+  
+  
+  /**
+   * \brief Component name
+   * Used for component selection.
+   */
   enum class DxbcOperandComponentName : uint32_t {
-    X = 0, R = 0, Y = 1, G = 1,
-    Z = 2, B = 2, W = 3, A = 3,
+    X = 0, Y = 1, Z = 2, W = 3,
   };
   
   
+  /**
+   * \brief Index representation
+   * 
+   * Determines how an operand
+   * register index is stored.
+   */
   enum class DxbcOperandIndexRepresentation : uint32_t {
-    Imm32         = 0,
-    Imm64         = 1,
-    Relative      = 2,
-    Imm32Relative = 3,
-    Imm64Relative = 3,
+    Imm32             = 0,
+    Imm64             = 1,
+    Relative          = 2,
+    Imm32Relative     = 3,
+    Imm64Relative     = 4,
   };
   
+  
+  /**
+   * \brief Extended operand type
+   */
   enum class DxbcOperandExt : uint32_t {
-    OperandModifier = 1,
+    OperandModifier   = 1,
+  };
+  
+  
+  /**
+   * \brief Resource dimension
+   * The type of a resource.
+   */
+  enum class DxbcResourceDim : uint32_t {
+    Unknown           = 0,
+    Buffer            = 1,
+    Texture1D         = 2,
+    Texture2D         = 3,
+    Texture2DMs       = 4,
+    Texture3D         = 5,
+    TextureCube       = 6,
+    Texture1DArr      = 7,
+    Texture2DArr      = 8,
+    Texture2DMsArr    = 9,
+    TextureCubeArr    = 10,
+    RawBuffer         = 11,
+    StructuredBuffer  = 12,
+  };
+  
+  
+  /**
+   * \brief Resource return type
+   * Data type for resource read ops.
+   */
+  enum class DxbcResourceReturnType : uint32_t {
+    Unorm             = 1,
+    Snorm             = 2,
+    Sint              = 3,
+    Uint              = 4,
+    Float             = 5,
+    Mixed             = 6,  /// ?
+    Double            = 7,
+    Continued         = 8,  /// ?
+    Unused            = 9,  /// ?
+  };
+  
+  
+  /**
+   * \brief Register component type
+   * Data type of a register component.
+   */
+  enum class DxbcRegisterComponentType : uint32_t {
+    Unknown           = 0,
+    Uint32            = 1,
+    Sint32            = 2,
+    Float32           = 3,
+  };
+  
+  
+  /**
+   * \brief Instruction return type
+   */
+  enum class DxbcInstructionReturnType : uint32_t {
+    Float             = 0,
+    Uint              = 1,
   };
   
 }
\ No newline at end of file