// ---- Created with 3Dmigoto v1.2.35 on Tue Apr 26 22:30:56 2016

cbuffer ccbSceneParam : register(b0)
{
  float4 m_ElapsedTime : packoffset(c0);
  float4 m_CameraNearFar : packoffset(c1);
  float4 m_ParentMove : packoffset(c2);
  float4 m_ParentRot : packoffset(c3);
  float4 m_ParentScale : packoffset(c4);
  float4 m_ParentColor : packoffset(c5);
  int4 m_TexNumInfo : packoffset(c6);
  int4 m_EmitInfo : packoffset(c7);
  float4 m_MoveInterpolateWeight : packoffset(c8);
  float4 m_WanderingVisionResetTime : packoffset(c9);
  float4 m_WanderingVisionEmitInfo : packoffset(c10);
  float4 m_WanderingVisionVelocity : packoffset(c11);
  float4 m_WanderingVisionAddVelocity : packoffset(c12);
  float4 m_WanderingVisionInitScale : packoffset(c13);
  float4 m_WanderingVisionScaleVelocity : packoffset(c14);
  float4 m_WanderingVisionScaleAddVelocity : packoffset(c15);
  float4 m_WanderingVisionColor : packoffset(c16);
  int4 m_WanderingVisionCloneParam : packoffset(c17);
  float4 m_WanderingVisionForceRate : packoffset(c18);
  float4 m_WanderingVisionLongevity : packoffset(c19);
  float4 m_WanderingVisionEdgeParam : packoffset(c20);
  float4 m_WanderingVisionNormalVelocity : packoffset(c21);
  float4 m_WanderingVisionInitRotation : packoffset(c22);
  float4 m_WanderingVisionRotationVelocity : packoffset(c23);
  float4 m_WanderingVisionRotationAddVelocity : packoffset(c24);
  float4 m_WanderingVisionNoiseVelocityMin : packoffset(c25);
  float4 m_WanderingVisionNoiseVelocityMax : packoffset(c26);
  float4 m_WanderingVisionNoiseAddVelocityMin : packoffset(c27);
  float4 m_WanderingVisionNoiseAddVelocityMax : packoffset(c28);
  float4 m_WanderingVisionNoiseRotMin : packoffset(c29);
  float4 m_WanderingVisionNoiseRotMax : packoffset(c30);
  float4 m_WanderingVisionNoiseRotVelocityMin : packoffset(c31);
  float4 m_WanderingVisionNoiseRotVelocityMax : packoffset(c32);
  float4 m_WanderingVisionNoiseRotAddVelocityMin : packoffset(c33);
  float4 m_WanderingVisionNoiseRotAddVelocityMax : packoffset(c34);
  float4 m_WanderingVisionNoiseInitScaleMin : packoffset(c35);
  float4 m_WanderingVisionNoiseInitScaleMax : packoffset(c36);
  float4 m_WanderingVisionNoiseScaleVelocityMin : packoffset(c37);
  float4 m_WanderingVisionNoiseScaleVelocityMax : packoffset(c38);
  float4 m_WanderingVisionNoiseScaleAddVelocityMin : packoffset(c39);
  float4 m_WanderingVisionNoiseScaleAddVelocityMax : packoffset(c40);
  float4 m_WanderingVisionNoiseColorMin : packoffset(c41);
  float4 m_WanderingVisionNoiseColorMax : packoffset(c42);
  float4 m_vDepthComputeParam : packoffset(c43);
  int4 m_vDepthTexParam : packoffset(c44);
  int4 m_YurayuraParam : packoffset(c45);
  int4 m_HitParam : packoffset(c46);
  float4 m_UvCropInfo : packoffset(c47);
  float4 m_ParentWeight : packoffset(c48);
  int4 m_KeyBlendParam : packoffset(c49);
  float4x4 m_CameraMatrix : packoffset(c50);
  float4x4 m_ViewMatrix : packoffset(c54);
  float4x4 m_ProjMatrix : packoffset(c58);
  float4x4 m_ViewProjMatrix : packoffset(c62);
  float4 m_ForceUnevenness : packoffset(c66);
  int4 m_TraceInfo : packoffset(c67);
  float4 m_TraceParam : packoffset(c68);
}

Buffer<uint4> rSortCounter : register(t0);
StructuredBuffer<rBufferMax> rBufferMax : register(t1);
StructuredBuffer<rSortParticleIn> rSortParticleIn : register(t2);


// 3Dmigoto declarations
#define cmp -
Texture1D<float4> IniParams : register(t120);
Texture2D<float4> StereoParams : register(t125);


void main()
{
// Needs manual fix for instruction: 
// unknown dcl_: dcl_resource_structured t1, 4 
// Needs manual fix for instruction: 
// unknown dcl_: dcl_resource_structured t2, 336 
// Needs manual fix for instruction: 
// unknown dcl_: dcl_uav_structured u0, 4
// Needs manual fix for instruction: 
// unknown dcl_: dcl_uav_structured u1, 4
  float4 r0,r1;
  uint4 bitmask, uiDest;
  float4 fDest;

// Needs manual fix for instruction: 
// unknown dcl_: dcl_thread_group 64, 1, 1
// Known bad code for instruction (needs manual fix):
ld_structured_indexable(structured_buffer, stride=4)(mixed,mixed,mixed,mixed) r0.x, l(0), l(0), t1.xxxx
r0.x = rSortCounter[]..swiz;
  r0.y = rSortCounter.Load(float4(0,0,0,0)).x;
  r1.w = 1;
  r0.z = vThreadIDInGroupFlattened.x;
  while (true) {
    r0.w = cmp((uint)r0.z >= (uint)r0.x);
    if (r0.w != 0) break;
    [r0.z].0 = u0.x;
    r0.w = cmp((uint)r0.z < (uint)r0.y);
  // Known bad code for instruction (needs manual fix):
    ld_structured_indexable(structured_buffer, stride=336)(mixed,mixed,mixed,mixed) r1.xyz, r0.z, l(0), t2.xyzx
  r1.x = rSortCounter[]..swiz;
  r1.y = rSortCounter[]..swiz;
  r1.z = rSortCounter[]..swiz;
    r1.x = dot(r1.xyzw, m_ViewMatrix._m02_m12_m22_m32);
    r0.w = r0.w ? r1.x : -10000000;
    [r0.z].0 = u1.x;
    r0.z = (int)r0.z + 64;
  }
  return;
}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Original ASM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.30.9200.20546
//
//
// Buffer Definitions: 
//
// cbuffer ccbSceneParam
// {
//
//   float4 m_ElapsedTime;              // Offset:    0 Size:    16 [unused]
//   float4 m_CameraNearFar;            // Offset:   16 Size:    16 [unused]
//   float4 m_ParentMove;               // Offset:   32 Size:    16 [unused]
//   float4 m_ParentRot;                // Offset:   48 Size:    16 [unused]
//   float4 m_ParentScale;              // Offset:   64 Size:    16 [unused]
//   float4 m_ParentColor;              // Offset:   80 Size:    16 [unused]
//   int4 m_TexNumInfo;                 // Offset:   96 Size:    16 [unused]
//   int4 m_EmitInfo;                   // Offset:  112 Size:    16 [unused]
//   float4 m_MoveInterpolateWeight;    // Offset:  128 Size:    16 [unused]
//   float4 m_WanderingVisionResetTime; // Offset:  144 Size:    16 [unused]
//   float4 m_WanderingVisionEmitInfo;  // Offset:  160 Size:    16 [unused]
//   float4 m_WanderingVisionVelocity;  // Offset:  176 Size:    16 [unused]
//   float4 m_WanderingVisionAddVelocity;// Offset:  192 Size:    16 [unused]
//   float4 m_WanderingVisionInitScale; // Offset:  208 Size:    16 [unused]
//   float4 m_WanderingVisionScaleVelocity;// Offset:  224 Size:    16 [unused]
//   float4 m_WanderingVisionScaleAddVelocity;// Offset:  240 Size:    16 [unused]
//   float4 m_WanderingVisionColor;     // Offset:  256 Size:    16 [unused]
//   int4 m_WanderingVisionCloneParam;  // Offset:  272 Size:    16 [unused]
//   float4 m_WanderingVisionForceRate; // Offset:  288 Size:    16 [unused]
//   float4 m_WanderingVisionLongevity; // Offset:  304 Size:    16 [unused]
//   float4 m_WanderingVisionEdgeParam; // Offset:  320 Size:    16 [unused]
//   float4 m_WanderingVisionNormalVelocity;// Offset:  336 Size:    16 [unused]
//   float4 m_WanderingVisionInitRotation;// Offset:  352 Size:    16 [unused]
//   float4 m_WanderingVisionRotationVelocity;// Offset:  368 Size:    16 [unused]
//   float4 m_WanderingVisionRotationAddVelocity;// Offset:  384 Size:    16 [unused]
//   float4 m_WanderingVisionNoiseVelocityMin;// Offset:  400 Size:    16 [unused]
//   float4 m_WanderingVisionNoiseVelocityMax;// Offset:  416 Size:    16 [unused]
//   float4 m_WanderingVisionNoiseAddVelocityMin;// Offset:  432 Size:    16 [unused]
//   float4 m_WanderingVisionNoiseAddVelocityMax;// Offset:  448 Size:    16 [unused]
//   float4 m_WanderingVisionNoiseRotMin;// Offset:  464 Size:    16 [unused]
//   float4 m_WanderingVisionNoiseRotMax;// Offset:  480 Size:    16 [unused]
//   float4 m_WanderingVisionNoiseRotVelocityMin;// Offset:  496 Size:    16 [unused]
//   float4 m_WanderingVisionNoiseRotVelocityMax;// Offset:  512 Size:    16 [unused]
//   float4 m_WanderingVisionNoiseRotAddVelocityMin;// Offset:  528 Size:    16 [unused]
//   float4 m_WanderingVisionNoiseRotAddVelocityMax;// Offset:  544 Size:    16 [unused]
//   float4 m_WanderingVisionNoiseInitScaleMin;// Offset:  560 Size:    16 [unused]
//   float4 m_WanderingVisionNoiseInitScaleMax;// Offset:  576 Size:    16 [unused]
//   float4 m_WanderingVisionNoiseScaleVelocityMin;// Offset:  592 Size:    16 [unused]
//   float4 m_WanderingVisionNoiseScaleVelocityMax;// Offset:  608 Size:    16 [unused]
//   float4 m_WanderingVisionNoiseScaleAddVelocityMin;// Offset:  624 Size:    16 [unused]
//   float4 m_WanderingVisionNoiseScaleAddVelocityMax;// Offset:  640 Size:    16 [unused]
//   float4 m_WanderingVisionNoiseColorMin;// Offset:  656 Size:    16 [unused]
//   float4 m_WanderingVisionNoiseColorMax;// Offset:  672 Size:    16 [unused]
//   float4 m_vDepthComputeParam;       // Offset:  688 Size:    16 [unused]
//   int4 m_vDepthTexParam;             // Offset:  704 Size:    16 [unused]
//   int4 m_YurayuraParam;              // Offset:  720 Size:    16 [unused]
//   int4 m_HitParam;                   // Offset:  736 Size:    16 [unused]
//   float4 m_UvCropInfo;               // Offset:  752 Size:    16 [unused]
//   float4 m_ParentWeight;             // Offset:  768 Size:    16 [unused]
//   int4 m_KeyBlendParam;              // Offset:  784 Size:    16 [unused]
//   float4x4 m_CameraMatrix;           // Offset:  800 Size:    64 [unused]
//   float4x4 m_ViewMatrix;             // Offset:  864 Size:    64
//   float4x4 m_ProjMatrix;             // Offset:  928 Size:    64 [unused]
//   float4x4 m_ViewProjMatrix;         // Offset:  992 Size:    64 [unused]
//   float4 m_ForceUnevenness;          // Offset: 1056 Size:    16 [unused]
//   int4 m_TraceInfo;                  // Offset: 1072 Size:    16 [unused]
//   float4 m_TraceParam;               // Offset: 1088 Size:    16 [unused]
//
// }
//
// Resource bind info for rBufferMax
// {
//
//   uint $Element;                     // Offset:    0 Size:     4
//
// }
//
// Resource bind info for rSortParticleIn
// {
//
//   struct GXSparkParticleVS
//   {
//       
//       float4 NodePos[12];            // Offset:    0
//       float4 FowardNodePos;          // Offset:  192
//       float4 vVelocity;              // Offset:  208
//       float4 vMoveDir;               // Offset:  224
//       float4 Longevity;              // Offset:  240
//       uint2 WeightColor;             // Offset:  256
//       uint2 MoveBaseVelNoise;        // Offset:  264
//       uint2 ColorBaseNoise;          // Offset:  272
//       uint2 ForceVelocity;           // Offset:  280
//       float4 TraceParam;             // Offset:  288
//       float4 TraceOption;            // Offset:  304
//       float4 vReboundingVelocity;    // Offset:  320
//
//   } $Element;                        // Offset:    0 Size:   336
//
// }
//
// Resource bind info for rwSortingBuffer
// {
//
//   uint $Element;                     // Offset:    0 Size:     4
//
// }
//
// Resource bind info for rwViewZBuffer
// {
//
//   float $Element;                    // Offset:    0 Size:     4
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// rSortCounter                      texture   uint4         buf    0        1
// rBufferMax                        texture  struct         r/o    1        1
// rSortParticleIn                   texture  struct         r/o    2        1
// rwSortingBuffer                       UAV  struct         r/w    0        1
// rwViewZBuffer                         UAV  struct         r/w    1        1
// ccbSceneParam                     cbuffer      NA          NA    0        1
//
//
//
// Input signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// no Input
//
// Output signature:
//
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// no Output
cs_5_0
dcl_globalFlags refactoringAllowed
dcl_constantbuffer cb0[57], immediateIndexed
dcl_resource_buffer (uint,uint,uint,uint) t0
dcl_resource_structured t1, 4 
dcl_resource_structured t2, 336 
dcl_uav_structured u0, 4
dcl_uav_structured u1, 4
dcl_input vThreadIDInGroupFlattened
dcl_temps 2
dcl_thread_group 64, 1, 1
ld_structured_indexable(structured_buffer, stride=4)(mixed,mixed,mixed,mixed) r0.x, l(0), l(0), t1.xxxx
ld_indexable(buffer)(uint,uint,uint,uint) r0.y, l(0, 0, 0, 0), t0.yxzw
mov r1.w, l(1.000000)
mov r0.z, vThreadIDInGroupFlattened.x
loop 
  uge r0.w, r0.z, r0.x
  breakc_nz r0.w
  store_structured u0.x, r0.z, l(0), r0.z
  ult r0.w, r0.z, r0.y
  ld_structured_indexable(structured_buffer, stride=336)(mixed,mixed,mixed,mixed) r1.xyz, r0.z, l(0), t2.xyzx
  dp4 r1.x, r1.xyzw, cb0[56].xyzw
  movc r0.w, r0.w, r1.x, l(-10000000.000000)
  store_structured u1.x, r0.z, l(0), r0.w
  iadd r0.z, r0.z, l(64)
endloop 
ret 
// Approximately 16 instruction slots used

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
