// TILE LIGHTING SYSTEM. See d3dx.ini
// Generated by Microsoft (R) HLSL Shader Compiler 9.30.9200.20546
//
//   using 3Dmigoto v1.3.14 on Fri Mar 22 21:06:45 2019
//
//
// Buffer Definitions:
//
// cbuffer cbLightAccParam
// {
//
//   float4x4 g_InvProjMatrix;          // Offset:    0 Size:    64
//   float4x3 g_ViewMatrix;             // Offset:   64 Size:    48 [unused]
//   float4 g_ScreenSize;               // Offset:  112 Size:    16
//   float4x4 g_CameraMatrix;           // Offset:  128 Size:    64 [unused]
//   float4 g_specPowerParam;           // Offset:  192 Size:    16 [unused]
//   float4x4 g_ProjMatrix;             // Offset:  208 Size:    64
//   uint g_lightCount;                 // Offset:  272 Size:     4
//   bool g_visualizeLightCount;        // Offset:  276 Size:     4 [unused]
//   uint g_spotLightCount;             // Offset:  280 Size:     4
//   uint g_lineLightCount;             // Offset:  284 Size:     4 [unused]
//   float g_frustumNear;               // Offset:  288 Size:     4
//   float g_frustumFar;                // Offset:  292 Size:     4
//   float g_frustumSliceScale;         // Offset:  296 Size:     4
//   float g_frustumSliceBias;          // Offset:  300 Size:     4
//   uint4 g_lightTileSize;             // Offset:  304 Size:    16
//   float g_ssrDepthThreshold;         // Offset:  320 Size:     4 [unused]
//   float g_ssrDepthFadeRangeRecp;     // Offset:  324 Size:     4 [unused]
//   float g_ssrFresnelThreshold;       // Offset:  328 Size:     4 [unused]
//   float g_ssrDisplayMipScale;        // Offset:  332 Size:     4 [unused]
//   float g_ssrDisplayMipOffset;       // Offset:  336 Size:     4 [unused]
//   float g_ssrReserved1;              // Offset:  340 Size:     4 [unused]
//   float2 g_ssrReserved2;             // Offset:  344 Size:     8 [unused]
//   bool g_isNeoOrScorpio;             // Offset:  352 Size:     4 [unused]
//   uint2 g_emissiveCMaskInfo;         // Offset:  360 Size:     8 [unused]
//
// }
//
// Resource bind info for g_LightBuffer
// {
//
//   struct PointLight
//   {
//
//       float4 PositionAndRadius;      // Offset:    0
//       float4 DiffColor;              // Offset:   16
//       float4 SpecColor;              // Offset:   32
//       float4 TransLightParam;        // Offset:   48
//       float LightType;               // Offset:   64
//       float3 Pad;                    // Offset:   68
//       float4 ProjParam;              // Offset:   80
//       float4 ShadowCenterPos;        // Offset:   96
//       float4 ViewportScaleOffset[6]; // Offset:  112
//
//   } $Element;                        // Offset:    0 Size:   208
//
// }
//
// Resource bind info for g_SpotLightBuffer
// {
//
//   struct SpotLight
//   {
//
//       float4 PositionAndRange;       // Offset:    0
//       float4 DiffColor;              // Offset:   16
//       float4 SpecColor;              // Offset:   32
//       float3 TransLightParam;        // Offset:   48
//       float ShadingMode;             // Offset:   60
//       float4x4 ViewToLightSpaceMatrix;// Offset:   64
//       float LightType;               // Offset:  128
//       float MinDist;                 // Offset:  132
//       float MaxDist;                 // Offset:  136
//       float Pad;                     // Offset:  140
//       float4 CullPositionAndRange;   // Offset:  144
//       float4 ShadowParam;            // Offset:  160
//       float4 ViewportScaleOffset;    // Offset:  176
//
//   } $Element;                        // Offset:    0 Size:   192
//
// }
//
// Resource bind info for g_wLightIndices
// {
//
//   uint $Element;                     // Offset:    0 Size:     4
//
// }
//
// Resource bind info for g_lightLookup
// {
//
//   uint3 $Element;                    // Offset:    0 Size:    12
//
// }
//
// Resource bind info for g_workData
// {
//
//   struct WorkData
//   {
//
//       uint numLights;                // Offset:    0
//
//   } $Element;                        // Offset:    0 Size:     4
//
// }
//
//
// Resource Bindings:
//
// Name                                 Type  Format         Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// g_DepthTexture                    texture  float4          2d    1        1
// g_LightBuffer                     texture  struct         r/o   19        1
// g_SpotLightBuffer                 texture  struct         r/o   20        1
// g_wLightIndices                       UAV  struct         r/w    0        1
// g_lightLookup                         UAV  struct         r/w    1        1
// g_workData                            UAV  struct         r/w    2        1
// cbLightAccParam                   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[20], immediateIndexed
dcl_resource_texture2d (float,float,float,float) t1
dcl_resource_structured t19, 208
dcl_resource_structured t20, 192
dcl_uav_structured u0, 4
dcl_uav_structured u1, 12
dcl_uav_structured u2, 4
dcl_input vThreadGroupID.xy
dcl_input vThreadIDInGroup.xy
dcl_input vThreadID.xy
dcl_temps 7
dcl_tgsm_raw g0, 4
dcl_tgsm_raw g1, 4
dcl_tgsm_structured g2, 4, 512
dcl_tgsm_structured g3, 4, 512
dcl_tgsm_raw g4, 4
dcl_tgsm_raw g5, 4
dcl_tgsm_raw g6, 4
dcl_tgsm_raw g7, 4
dcl_tgsm_raw g8, 4
dcl_thread_group 16, 16, 1
imad r0.x, vThreadIDInGroup.y, l(16), vThreadIDInGroup.x
imul null, r0.yz, vThreadID.xxyx, cb0[19].yyyy
mov r1.zw, l(0,0,0,0)
mov r2.w, l(1.000000)
mov r3.xy, l(340282346638528860000000000000000000000.000000,0,0,0)
mov r4.y, l(0)
loop
  uge r0.w, r4.y, cb0[19].y
  breakc_nz r0.w
  mov r3.zw, r3.xxxy
  mov r4.x, l(0)
  loop
    uge r0.w, r4.x, cb0[19].y
    breakc_nz r0.w
    imad r1.xy, cb0[19].yyyy, vThreadID.xyxx, r4.xyxx
    utof r4.zw, r1.xxxy
    add r4.zw, r4.zzzw, l(0.000000, 0.000000, 0.500000, 0.500000)
    mul r4.zw, r4.zzzw, cb0[7].zzzw
    mad r2.xy, r4.zwzz, l(2.000000, -2.000000, 0.000000, 0.000000), l(-1.000000, 1.000000, 0.000000, 0.000000)
    ld_indexable(texture2d)(float,float,float,float) r2.z, r1.xyzw, t1.yzxw
    dp4 r0.w, r2.xyzw, cb0[2].xyzw
    dp4 r1.x, r2.xyzw, cb0[3].xyzw
    div r0.w, r0.w, r1.x
    min r3.z, r0.w, r3.z
    max r3.w, r0.w, r3.w
    iadd r4.x, r4.x, l(1)
  endloop
  mov r3.xy, r3.zwzz
  iadd r4.y, r4.y, l(1)
endloop
if_z r0.x
  store_raw g8.x, l(0), l(0)
  store_raw g4.x, l(0), l(0)
  store_raw g5.x, l(0), l(0)
  store_raw g6.x, l(0), l(0)
  store_raw g7.x, l(0), l(0)
  store_raw g0.x, l(0), l(340282346638528860000000000000000000000.000000)
  store_raw g1.x, l(0), l(0)
endif
sync_g_t
atomic_umin g0, l(0), r3.x
atomic_umax g1, l(0), r3.y
sync_g_t
ld_raw r0.w, l(0), g0.xxxx
ld_raw r1.y, l(0), g1.xxxx
ishl r1.z, cb0[19].x, l(1)
utof r1.z, r1.z
rcp r1.z, r1.z
mul r2.xy, r1.zzzz, cb0[7].xyxx
utof r2.zw, vThreadGroupID.xxxy
mad r3.zw, cb0[7].xxxy, r1.zzzz, -r2.zzzw
mul r3.y, r2.x, cb0[13].x
mul r3.x, r2.y, -cb0[14].y
add r2.xyzw, -r3.yzxw, l(0.000000, 1.000000, 0.000000, 1.000000)
add r3.xyzw, r3.yzxw, l(0.000000, 1.000000, 0.000000, 1.000000)
mov r4.w, -r0.w
dp2 r1.z, r2.xyxx, r2.xyxx
sqrt r1.z, r1.z
rcp r1.z, r1.z
mul r1.zw, r1.zzzz, r2.xxxy
dp2 r2.x, r3.xyxx, r3.xyxx
sqrt r2.x, r2.x
rcp r2.x, r2.x
mul r2.xy, r2.xxxx, r3.xyxx
dp2 r3.x, r2.zwzz, r2.zwzz
sqrt r3.x, r3.x
rcp r3.x, r3.x
mul r2.zw, r2.zzzw, r3.xxxx
dp2 r3.x, r3.zwzz, r3.zwzz
sqrt r3.x, r3.x
rcp r3.x, r3.x
mul r3.xy, r3.xxxx, r3.zwzz
mov r3.z, r0.x
loop
  uge r3.w, r3.z, cb0[17].x
  breakc_nz r3.w
  ld_structured_indexable(structured_buffer, stride=208)(mixed,mixed,mixed,mixed) r4.xyz, r3.z, l(0), t19.xyzx
  ld_structured_indexable(structured_buffer, stride=208)(mixed,mixed,mixed,mixed) r5.xy, r3.z, l(60), t19.xyxx
  dp2 r3.w, r1.zwzz, r4.xzxx
  ge r3.w, r3.w, -r5.x
  dp2 r4.x, r2.xyxx, r4.xzxx
  ge r4.x, r4.x, -r5.x
  and r3.w, r3.w, r4.x
  dp2 r4.x, r2.zwzz, r4.yzyy
  ge r4.x, r4.x, -r5.x
  and r3.w, r3.w, r4.x
  dp2 r4.x, r3.xyxx, r4.yzyy
  ge r4.x, r4.x, -r5.x
  and r3.w, r3.w, r4.x
  //if_nz r3.w
    add r3.w, r4.z, -r5.x
    add r4.x, r4.z, r5.x
    add r3.w, r3.w, -cb0[18].x
    log r3.w, r3.w
    add r3.w, r3.w, -cb0[18].w
    div r3.w, r3.w, cb0[18].z
    max r3.w, r3.w, l(0.000000)
    min r3.w, r3.w, l(14.000000)
    ftou r3.w, r3.w
    add r4.x, r4.x, -cb0[18].x
    log r4.x, r4.x
    add r4.x, r4.x, -cb0[18].w
    div r4.x, r4.x, cb0[18].z
    max r4.x, r4.x, l(0.000000)
    min r4.x, r4.x, l(14.000000)
    ftou r4.x, r4.x
    ishl r4.y, l(1), r3.w
    mov r5.z, l(0)
    mov r5.w, r4.y
    mov r6.x, r3.w
    loop
      ult r6.y, r4.x, r6.x
      breakc_nz r6.y
      or r5.z, r5.w, r5.z
      ishl r5.w, r5.w, l(1)
      iadd r6.x, r6.x, l(1)
    endloop
    dp2 r3.w, l(1.000000, 1.000000, 0.000000, 0.000000), r4.zwzz
    mov r1.x, r4.z
    dp2 r1.x, l(-1.000000, 1.000000, 0.000000, 0.000000), r1.xyxx
    ge r3.w, r3.w, -r5.x
    ge r1.x, r1.x, -r5.x
    and r1.x, r1.x, r3.w
    eq r3.w, r5.y, l(0.000000)
    and r1.x, r1.x, r3.w
    or r3.w, r5.z, l(0x00008000)
    movc r1.x, r1.x, r3.w, r5.z
    if_nz r1.x
      imm_atomic_iadd r6.x, g4, l(0), l(1)
      and r3.w, r1.x, l(0x00008000)
      if_nz r3.w
        atomic_iadd g6, l(0), l(1)
      endif
      ishl r1.x, r1.x, l(16)
      or r1.x, r3.z, r1.x
      store_structured g2.x, r6.x, l(0), r1.x
    endif
  //endif
  iadd r3.z, r3.z, l(256)
endloop
mov r1.x, r0.x
loop
  uge r3.z, r1.x, cb0[17].z
  breakc_nz r3.z
  ld_structured_indexable(structured_buffer, stride=192)(mixed,mixed,mixed,mixed) r4.xyzw, r1.x, l(144), t20.xyzw
  dp2 r3.z, r1.zwzz, r4.xzxx
  dp2 r3.w, r2.xyxx, r4.xzxx
  ge r3.zw, r3.zzzw, -r4.wwww
  and r3.z, r3.w, r3.z
  dp2 r3.w, r2.zwzz, r4.yzyy
  ge r3.w, r3.w, -r4.w
  and r3.z, r3.w, r3.z
  dp2 r3.w, r3.xyxx, r4.yzyy
  ge r3.w, r3.w, -r4.w
  and r3.z, r3.w, r3.z
  if_nz r3.z
    ld_structured_indexable(structured_buffer, stride=192)(mixed,mixed,mixed,mixed) r4.xyz, r1.x, l(128), t20.xyzx
    ge r3.z, r4.z, cb0[18].x
    ge r3.w, cb0[18].y, r4.y
    and r3.z, r3.w, r3.z
    and r3.w, r3.z, l(0x00007fff)
    ge r4.z, r4.z, r0.w
    ge r4.y, r1.y, r4.y
    and r4.y, r4.y, r4.z
    eq r4.x, r4.x, l(0.000000)
    and r4.x, r4.x, r4.y
    bfi r3.z, l(15), l(0), r3.z, l(0x00008000)
    movc r3.z, r4.x, r3.z, r3.w
    if_nz r3.z
      imm_atomic_iadd r4.x, g5, l(0), l(1)
      and r3.w, r3.z, l(0x00008000)
      if_nz r3.w
        atomic_iadd g7, l(0), l(1)
      endif
      ishl r3.z, r3.z, l(16)
      or r3.z, r1.x, r3.z
      store_structured g3.x, r4.x, l(0), r3.z
    endif
  endif
  iadd r1.x, r1.x, l(256)
endloop
sync_g_t
if_z r0.x
  ld_raw r0.w, l(0), g4.xxxx
  ld_raw r1.x, l(0), g5.xxxx
  iadd r0.w, r0.w, r1.x
  imm_atomic_iadd r1.x, u2, l(0, 0, 0, 0), r0.w
  store_raw g8.x, l(0), r1.x
endif
sync_g_t
if_z r0.x
  utof r0.w, cb0[19].x
  add r1.x, r0.w, cb0[7].x
  add r1.x, r1.x, l(-1.000000)
  div r0.w, r1.x, r0.w
  ftou r0.w, r0.w
  udiv r0.yz, null, r0.yyzy, cb0[19].xxxx
  utof r0.yzw, r0.yyzw
  mad r0.y, r0.z, r0.w, r0.y
  ftou r0.y, r0.y
  ld_raw r1.x, l(0), g8.xxxx
  ld_raw r0.z, l(0), g5.xxxx
  ishl r0.z, r0.z, l(16)
  ld_raw r0.w, l(0), g4.xxxx
  or r1.y, r0.w, r0.z
  ld_raw r0.z, l(0), g7.xxxx
  ishl r0.z, r0.z, l(16)
  ld_raw r0.w, l(0), g6.xxxx
  or r1.z, r0.w, r0.z
  store_structured u1.xyz, r0.y, l(0), r1.xyzx
endif
ld_raw r0.y, l(0), g8.xxxx
ld_raw r0.z, l(0), g4.xxxx
mov r0.w, r0.x
loop
  uge r1.x, r0.w, r0.z
  breakc_nz r1.x
  iadd r1.x, r0.w, r0.y
  ld_structured r1.y, r0.w, l(0), g2.xxxx
  store_structured u0.x, r1.x, l(0), r1.y
  iadd r0.w, r0.w, l(256)
endloop
ld_raw r0.z, l(0), g4.xxxx
iadd r0.y, r0.z, r0.y
ld_raw r0.z, l(0), g5.xxxx
mov r0.w, r0.x
loop
  uge r1.x, r0.w, r0.z
  breakc_nz r1.x
  iadd r1.x, r0.w, r0.y
  ld_structured r1.y, r0.w, l(0), g3.xxxx
  store_structured u0.x, r1.x, l(0), r1.y
  iadd r0.w, r0.w, l(256)
endloop
ret
// Approximately 235 instruction slots used

