Files
larp/shaders/replace/02737aba304c298a.compute.hlsl

415 lines
21 KiB
HLSL

// 02737aba304c298a, compute: ComputeClosestDepth. Per thread eight rays from a record's position (or a point
// offset along its frame) along directions spread around its normal; the thread stores the largest t of the rays
// that hit a back face where more than 6 of the 8 did, else 0.
//
// The layer's translation of the console program without a table entry, its walk left in, turned into HLSL
// (dxil-spirv, then SPIRV-Cross) with its bindings restored as the
// translation makes them (README "Bindings": heap views through ResourceDescriptorHeap typed as the translation's
// handles, with this host's view heap clamps, null slot 999999; user data b0 space0, 12 dwords; [WaveSize(32)]
// [numthreads(32, 1, 1)]), with these changes. Every other name is a number of the decompile. Offsets below are of the
// console code's listing.
//
// - Site 1 (`// site 1`): the walk of the console's structure (32-bit form: the top level walked by the whole
// wave, node test 0x450, the bottom level per lane, node test 0xb08; E 0x3f8, X 0xfc0), with the root load
// before it (header +48, 0x374, and its test 0x39c, which skips the walk as a miss), is one host ray query
// of structure view 0, t248 space1 (02737aba304c298a.compute.views: the table at root parameter 1, dword 0,
// the console's s_load_dwordx4 s[16:19] at 0x98), with the ray the code holds at E: origin v24, v23, v22,
// direction v37, v36, v35 (= v20, v21, v19, 0x3dc-0x3e4), t max v25 = min(1, the record's half at 0x368),
// t min v26 (the record's +104 low half, 0x3c4; the walk's test t >= v26 at 0xda4).
// Flags RAY_FLAG_CULL_NON_OPAQUE (0x80): the cull multiplier at 0xa78 is 0 (no face culled), and only a
// triangle the instance flags (0xa6c) and the triangle's opaque bit (0xd44, 0xd54) make opaque is tested
// (0xd7c); a commit does not end the walk (closest hit). Mask 0xd5 (instance +48 & 0xd5000000, 0x644).
// The ray is traced where it is valid (no NaN among origin and direction, t min <= t max), as the
// translator's substitution does; elsewhere a miss.
// What the code after X reads of what the walk wrote, and what it became:
// - v28, the committed triangle's pointer (0 at E): 1 on a hit, 0 on a miss. Read only as `== 0` (0xfc4).
// - v25, the walk's t max that each commit shortens: CommittedRayT() on a hit, else its value at E.
// - v18, the hit kind (0xfe front, 0xff back, from the denominator's sign xor the instance's
// counter-clockwise bit, 0xdc0-0xde0): 0xfe where CommittedTriangleFrontFace() (whose front face holds
// the instance's winding), else 0xff, on a hit; its value at E on a miss (each ray enters with the
// previous ray's, 0 before the first). Read as `== 0xfe` (0xfe0): a front face does not count.
// - v33, the walk's node-test count (0 at E): 0. The console stops the bottom level past 0xfffe (0xedc), and
// the code after X counts a ray that committed nothing and whose count passed 0xfffe as it counts a
// back-face hit (0xfc4: v28 == 0 and v33 > 0xfffe; its t max at E enters the max). A host query has no
// iteration cap and gives the closest opaque hit of the whole structure, so no ray is counted for the cap;
// a ray the console capped counts here only if its closest hit is a back face. The cap is the console walk's bound on node
// tests of the console's tree (the constant 0xfffe), a property of that walk and not of the scene; the host
// structure is another tree and its traversal is not counted.
// The other registers the walk wrote are read after X only by the walk of the next ray; the query does not
// read them.
// - The walk's group-shared stack (_46) and its lane-stack registers go with the walk; the program reads no title
// memory by address: memory_pages (t254) and memory_faults (u253) are not declared (README "Ray tracing": they
// stay bound), and no memory_copy_* read is left.
// - The stores are the translation's: one dword per thread to the view at slot 1 +0x20 (0x1000-0x1010).
//
// Not established: how often the console's cap of 0xfffe node tests is reached for this pass's rays (it would
// show as rays counted there and not here).
#include "view_heap_layout.hlsli"
static bool _3734;
static uint _3772;
static int _3866;
ByteAddressBuffer table_lists : register(t252, space1);
ByteAddressBuffer view_shifts : register(t253, space1);
cbuffer _40_42 : register(b0, space0)
{
float4 _42_m0[3] : packoffset(c0);
};
// The host top level of structure view 0 (the table at root parameter 1, dword 0; site 1).
RaytracingAccelerationStructure scene0 : register(t248, space1);
Buffer<float4> heap_Buffer_float4(uint i) { Buffer<float4> r = ResourceDescriptorHeap[i]; return r; }
ByteAddressBuffer heap_ByteAddressBuffer(uint i) { ByteAddressBuffer r = ResourceDescriptorHeap[i]; return r; }
RWByteAddressBuffer heap_RWByteAddressBuffer(uint i) { RWByteAddressBuffer r = ResourceDescriptorHeap[i]; return r; }
static uint3 gl_WorkGroupID;
static uint gl_LocalInvocationIndex;
struct SPIRV_Cross_Input
{
uint3 gl_WorkGroupID : SV_GroupID;
uint gl_LocalInvocationIndex : SV_GroupIndex;
};
uint spvPackHalf2x16(float2 value)
{
uint2 Packed = f32tof16(value);
return Packed.x | (Packed.y << 16);
}
float2 spvUnpackHalf2x16(uint value)
{
return f16tof32(uint2(value & 0xffff, value >> 16));
}
void comp_main()
{
uint4 _59 = asuint(_42_m0[1u]);
uint _64 = WaveReadLaneFirst(gl_LocalInvocationIndex);
uint _73 = _59.x;
uint _81 = min((((_73 + 864u) >> 5u) << 2u), 2147483584u);
uint _88 = asuint(asfloat(table_lists.Load<uint>((_81 >> 2u) * 4 + 0)));
uint _89 = min(_88, NULL_SLOT);
uint _101 = asuint(asfloat(view_shifts.Load<uint>((min((min(_88, 2097151u) << 2u), 2147483584u) >> 2u) * 4 + 0)));
uint _103 = ((gl_WorkGroupID.x + _59.z) << 5u) + (((_64 & 4294967264u) + WaveGetLaneIndex()) % 32u);
uint _108 = _103 * 512u;
uint _109 = _108 + 20u;
uint _111 = _109 + _101;
uint _116 = min(((_111 < _101) ? _109 : _111), 2147483584u) >> 2u;
float2 _125 = asfloat(uint2(heap_ByteAddressBuffer(_89).Load<uint>(_116 * 4 + 0), heap_ByteAddressBuffer(_89).Load<uint>((_116 + 1u) * 4 + 0)));
uint _127 = asuint(_125.x);
uint _129 = asuint(_125.y);
uint _138 = _59.w;
uint4 _141 = asuint(_42_m0[2u]);
uint _142 = _141.x;
uint _143 = _141.y;
uint _3475;
uint _3476;
if ((1073741824u > _129) ? false : (!(1073741824u == (3221225472u & _129))))
{
_3475 = 0u;
_3476 = 0u;
}
else
{
uint _148 = asuint(asfloat(table_lists.Load<uint>((_81 >> 2u) * 4 + 0)));
uint _156 = asuint(asfloat(view_shifts.Load<uint>((min((min(_148, 2097151u) << 2u), 2147483584u) >> 2u) * 4 + 0)));
uint _157 = _108 + _156;
uint _160 = min(_148, NULL_SLOT);
uint _163 = min(((_157 < _156) ? _108 : _157), 2147483584u) >> 2u;
float4 _176 = asfloat(uint4(heap_ByteAddressBuffer(_160).Load<uint>(_163 * 4 + 0), heap_ByteAddressBuffer(_160).Load<uint>((_163 + 1u) * 4 + 0), heap_ByteAddressBuffer(_160).Load<uint>((_163 + 2u) * 4 + 0), heap_ByteAddressBuffer(_160).Load<uint>((_163 + 3u) * 4 + 0)));
float _177 = _176.x;
uint _178 = asuint(_177);
float _179 = _176.y;
uint _180 = asuint(_179);
float _181 = _176.z;
uint _182 = asuint(_181);
uint _185 = _108 + 32u;
uint _186 = _185 + _156;
uint _190 = min(((_186 < _156) ? _185 : _186), 2147483584u) >> 2u;
float2 _197 = asfloat(uint2(heap_ByteAddressBuffer(_160).Load<uint>(_190 * 4 + 0), heap_ByteAddressBuffer(_160).Load<uint>((_190 + 1u) * 4 + 0)));
uint _199 = asuint(_197.x);
uint _202 = _108 + 44u;
uint _204 = _202 + _156;
float2 _215 = spvUnpackHalf2x16(_127 >> 16u);
float _216 = _215.x;
uint _223 = min((((_73 + 1312u) >> 5u) << 2u), 2147483584u);
float2 _224 = spvUnpackHalf2x16(_127);
float _225 = _224.x;
float2 _227 = spvUnpackHalf2x16(_129);
float _228 = _227.x;
float _230 = rsqrt(mad(_228, _228, mad(_225, _225, mad(_216, _216, 0.0f))));
float _231 = mad(_230, _225, 0.0f);
float _232 = mad(_230, _216, 0.0f);
float _233 = mad(_230, _228, 0.0f);
float2 _237 = spvUnpackHalf2x16((asuint(_176.w) >> 16u) & 65535u);
float _238 = _237.x;
uint _239 = asuint(_238);
float2 _241 = spvUnpackHalf2x16(_199 >> 16u);
float _242 = _241.x;
float2 _245 = spvUnpackHalf2x16(asuint(asfloat(heap_ByteAddressBuffer(_160).Load<uint>((min(((_204 < _156) ? _202 : _204), 2147483584u) >> 2u) * 4 + 0))) & 65535u);
float _246 = _245.x;
float2 _247 = spvUnpackHalf2x16(_199);
float _248 = _247.x;
float2 _250 = spvUnpackHalf2x16(asuint(_197.y));
float _251 = _250.x;
float _253 = rsqrt(mad(_251, _251, mad(_248, _248, mad(_242, _242, 0.0f))));
float _254 = mad(_253, _248, 0.0f);
float _255 = mad(_253, _251, 0.0f);
float _256 = mad(_253, _242, 0.0f);
precise float _257 = _254 * _232;
bool _258 = _254 == 0.0f;
bool _259 = _232 == 0.0f;
precise float _262 = _255 * _231;
bool _263 = _255 == 0.0f;
bool _264 = _231 == 0.0f;
precise float _267 = _256 * _233;
bool _268 = _256 == 0.0f;
bool _269 = _233 == 0.0f;
precise float _272 = (-0.0f) - ((_258 || _259) ? 0.0f : _257);
float _274 = mad(_256, _231, _272);
precise float _275 = (-0.0f) - ((_263 || _264) ? 0.0f : _262);
float _276 = mad(_254, _233, _275);
precise float _277 = (-0.0f) - ((_268 || _269) ? 0.0f : _267);
float _278 = mad(_255, _232, _277);
uint _292;
uint _288;
uint _290;
uint _294;
uint _3453;
uint _3454;
uint _3455;
bool _3725;
uint _3743;
uint _3745;
uint _279 = 0u;
uint _281 = 0u;
uint _283 = 0u;
uint _285 = 0u;
uint _287 = 0u;
uint _289 = 0u;
uint _291 = 0u;
uint _293 = 0u;
uint _325;
uint _344;
uint _364;
precise float _374;
uint _375;
float _393;
uint _394;
float _397;
uint _398;
bool _399;
for (;;)
{
uint _295 = _108 + 104u;
uint _301 = asuint(asfloat(table_lists.Load<uint>((_81 >> 2u) * 4 + 0)));
uint _309 = asuint(asfloat(view_shifts.Load<uint>((min((min(_301, 2097151u) << 2u), 2147483584u) >> 2u) * 4 + 0)));
uint _310 = _295 + _309;
uint _313 = min(_301, NULL_SLOT);
uint _316 = min(((_310 < _309) ? _295 : _310), 2147483584u) >> 2u;
float2 _323 = asfloat(uint2(heap_ByteAddressBuffer(_313).Load<uint>(_316 * 4 + 0), heap_ByteAddressBuffer(_313).Load<uint>((_316 + 1u) * 4 + 0)));
_325 = asuint(_323.x);
uint _330 = _108 + 24u;
uint _332 = _330 + _309;
_344 = 3221225472u & asuint(asfloat(heap_ByteAddressBuffer(_313).Load<uint>((min(((_332 < _309) ? _330 : _332), 2147483584u) >> 2u) * 4 + 0)));
bool _345 = 0u != ((asuint(_323.y) >> 22u) & 1u);
_364 = asuint(heap_Buffer_float4(min(asuint(asfloat(table_lists.Load<uint>((_223 >> 2u) * 4 + 0))), NULL_SLOT)).Load(min((((_345 ? 1664u : 0u) | (_281 << 14u)) | (_345 ? 5u : 0u)), 134217727u)).x);
precise float _372 = 0.5f + float((_364 >> 8u) & 255u);
_374 = 0.5f + float(_364 & 255u);
_375 = asuint(_374);
precise float _376 = 0.00390625f * _372;
precise float _381 = (-0.0f) - trunc((_372 == 0.0f) ? 0.0f : _376);
float _382 = mad(0.00390625f, _372, _381);
precise float _384 = _382 - round(_382);
float _386 = (_382 == 0.0f) ? _382 : _384;
precise float _387 = _386 * 6.283185482025146484375f;
float _390 = abs(_386);
_393 = (_390 == 0.25f) ? 0.0f : cos(_387);
_394 = asuint(_393);
_397 = (_390 == 0.5f) ? 0.0f : sin(_387);
_398 = asuint(_397);
_399 = 1073741824u == _344;
uint _570;
uint _571;
uint _572;
uint _573;
uint _574;
uint _575;
if (_399)
{
uint _400 = _108 + 40u;
uint _406 = asuint(asfloat(table_lists.Load<uint>((_81 >> 2u) * 4 + 0)));
uint _414 = asuint(asfloat(view_shifts.Load<uint>((min((min(_406, 2097151u) << 2u), 2147483584u) >> 2u) * 4 + 0)));
uint _415 = _400 + _414;
uint _418 = min(_406, NULL_SLOT);
precise float _426 = 0.00390625f * _374;
precise float _435 = 0.5f + float((_364 >> 16u) & 255u);
float _438 = mad(spvUnpackHalf2x16(asuint(asfloat(heap_ByteAddressBuffer(_418).Load<uint>((min(((_415 < _414) ? _400 : _415), 2147483584u) >> 2u) * 4 + 0)))).x, (_374 == 0.0f) ? 0.0f : _426, mad(-0.00390625f, _374, 1.0f));
precise float _442 = (-0.0f) - _438;
precise float _444 = _438 * _231;
bool _445 = _438 == 0.0f;
precise float _448 = _438 * _233;
precise float _451 = 0.5f + float((_364 >> 24u) & 255u);
uint _452 = asuint(_451);
float _453 = sqrt(mad(_442, _438, 1.0f));
precise float _454 = _393 * _453;
bool _456 = _453 == 0.0f;
float _458 = ((_393 == 0.0f) || _456) ? 0.0f : _454;
precise float _459 = _438 * _232;
precise float _462 = _397 * _453;
float _465 = ((_397 == 0.0f) || _456) ? 0.0f : _462;
float _466 = mad(0.0078125f, _435, -1.0f);
uint _469 = asuint(_466);
float _470 = mad(0.0078125f, _451, -1.0f);
bool _483 = abs(_466) > abs(_470);
precise float _484 = 1.0f / _466;
float _487 = asfloat(_483 ? asuint(_484) : _452);
precise float _488 = _470 * _487;
uint _494 = _483 ? asuint(((_470 == 0.0f) || (_487 == 0.0f)) ? 0.0f : _488) : asuint(_470);
float _495 = asfloat(_494);
precise float _496 = 0.785398185253143310546875f * _495;
uint _501 = _483 ? asuint((_495 == 0.0f) ? 0.0f : _496) : _452;
bool _502 = !_483;
precise float _503 = 1.0f / _495;
float _506 = asfloat(_502 ? asuint(_503) : _501);
precise float _507 = _466 * _506;
float _521 = asfloat(_502 ? asuint(mad(asfloat(_502 ? asuint(((_466 == 0.0f) || (_506 == 0.0f)) ? 0.0f : _507) : _469), -0.785398185253143310546875f, 1.57079637050628662109375f)) : _501);
precise float _522 = 0.15915493667125701904296875f * _521;
precise float _527 = (-0.0f) - trunc((_521 == 0.0f) ? 0.0f : _522);
float _528 = mad(_521, 0.15915493667125701904296875f, _527);
precise float _530 = _528 - round(_528);
float _532 = (_528 == 0.0f) ? _528 : _530;
precise float _533 = _532 * 6.283185482025146484375f;
float _535 = abs(_532);
float _537 = (_535 == 0.25f) ? 0.0f : cos(_533);
float _540 = (_535 == 0.5f) ? 0.0f : sin(_533);
float _541 = asfloat(_502 ? _494 : _469);
precise float _542 = _537 * _541;
bool _544 = _541 == 0.0f;
float _546 = ((_537 == 0.0f) || _544) ? 0.0f : _542;
precise float _547 = _540 * _541;
float _550 = ((_540 == 0.0f) || _544) ? 0.0f : _547;
precise float _551 = _546 * _254;
bool _552 = _546 == 0.0f;
precise float _555 = _546 * _256;
precise float _558 = _546 * _255;
_570 = asuint(mad(_465, _255, mad(_458, _274, (_445 || _269) ? 0.0f : _448)));
_571 = asuint(mad(_465, _254, mad(_458, _278, (_445 || _264) ? 0.0f : _444)));
_572 = asuint(mad(_465, _256, mad(_458, _276, (_445 || _259) ? 0.0f : _459)));
_573 = asuint(mad(mad(_550, _274, (_552 || _263) ? 0.0f : _558), _246, _181));
_574 = asuint(mad(mad(_550, _276, (_552 || _268) ? 0.0f : _555), _246, _179));
_575 = asuint(mad(mad(_550, _278, (_552 || _258) ? 0.0f : _551), _246, _177));
}
else
{
_570 = _375;
_571 = _364;
_572 = _394;
_573 = _398;
_574 = _344;
_575 = _291;
}
bool _576 = !_399;
uint _581 = _576 ? asuint(mad(-0.0078125f, asfloat(_570), 1.0f)) : _570;
_292 = _576 ? _178 : _575;
float _582 = asfloat(_581);
precise float _583 = (-0.0f) - _582;
uint _586 = _576 ? asuint(mad(_583, _582, 1.0f)) : _571;
float _599 = asfloat(_572);
float _600 = asfloat(_576 ? asuint(sqrt(asfloat(_576 ? asuint(((_586 & 2147483647u) == 0u) ? 0.0f : max(0.0f, asfloat(_586))) : _571))) : _574);
precise float _601 = _599 * _600;
bool _603 = _600 == 0.0f;
uint _607 = _576 ? asuint(((_599 == 0.0f) || _603) ? 0.0f : _601) : _571;
float _608 = asfloat(_573);
precise float _609 = _608 * _600;
uint _614 = _576 ? asuint(((_608 == 0.0f) || _603) ? 0.0f : _609) : _572;
uint _615 = _576 ? _182 : _573;
uint _616 = _576 ? _180 : _574;
uint _632 = 1065353216u | _239;
uint _638 = asuint(((_632 & 2147483647u) == 0u) ? asfloat(_632) : min(1.0f, _238));
// site 1 (console E 0x3f8, X 0xfc0): structure view 0, flags RAY_FLAG_CULL_NON_OPAQUE, mask 0xd5,
// t min v26 (the record's +104 low half), t max v25 (_638); origin v24, v23, v22; direction v37, v36, v35.
float2 _686 = spvUnpackHalf2x16(_325 & 65535u);
float _687 = _686.x;
float3 site1_origin = float3(asfloat(_292), asfloat(_616), asfloat(_615));
float3 site1_direction = float3(asfloat(_607), asfloat(_614), asfloat(_581));
float site1_tmax = asfloat(_638);
bool site1_hit = false;
float site1_t = 0.0f;
bool site1_front = false;
if ((_687 <= site1_tmax) && !any(isnan(site1_origin)) && !any(isnan(site1_direction)))
{
RayDesc site1_ray = {site1_origin, _687, site1_direction, site1_tmax};
RayQuery<RAY_FLAG_CULL_NON_OPAQUE> site1_q;
site1_q.TraceRayInline(scene0, 128u, 213u, site1_ray);
while (site1_q.Proceed())
{
}
site1_hit = site1_q.CommittedStatus() == COMMITTED_TRIANGLE_HIT;
site1_t = site1_q.CommittedRayT();
site1_front = site1_q.CommittedTriangleFrontFace();
}
// v28 (committed triangle), v25 (t), v18 (hit kind, its value at E on a miss), v33 (count: 0).
_288 = _287;
_290 = site1_hit ? (site1_front ? 254u : 255u) : _289;
_3453 = site1_hit ? asuint(site1_t) : _638;
_3454 = site1_hit ? 1u : 0u;
_3455 = 0u;
_294 = _293;
uint _282 = _281 + 1u;
bool _3469 = 254u == _290;
bool _3472 = (0u == _3454) ? ((65535u > _3455) || _3469) : _3469;
uint _286 = _3472 ? _285 : (1u + _285);
uint _284 = _3472 ? _283 : asuint((((_3453 | _283) & 2147483647u) == 0u) ? asfloat(_3453 & _283) : max(asfloat(_3453), asfloat(_283)));
uint _280 = _279 + 1u;
if ((_282 == 8u) || (_280 >= 4096u))
{
_3725 = false;
_3743 = _284;
_3745 = _286;
break;
}
else
{
_279 = _280;
_281 = _282;
_283 = _284;
_285 = _286;
_287 = _288;
_289 = _290;
_291 = _292;
_293 = _294;
continue;
}
}
if (_3725)
{
return;
}
_3475 = _3743;
_3476 = _3745;
}
uint _3482 = (_103 * 8u) + 4u;
uint _3487 = asuint(asfloat(table_lists.Load<uint>((min((((_59.y + 32u) >> 5u) << 2u), 2147483584u) >> 2u) * 4 + 0)));
uint _3495 = asuint(asfloat(view_shifts.Load<uint>((min((min(_3487, 2097151u) << 2u), 2147483584u) >> 2u) * 4 + 0)));
uint _3496 = _3482 + _3495;
uint _3499 = min(_3487, NULL_SLOT);
heap_RWByteAddressBuffer(_3499).Store<uint>((min(((_3496 < _3495) ? _3482 : _3496), 2147483584u) >> 2u) * 4 + 0, (6.0f < float(_3476)) ? _3475 : 0u);
}
[WaveSize(32)]
[numthreads(32, 1, 1)]
void main(SPIRV_Cross_Input stage_input)
{
gl_WorkGroupID = stage_input.gl_WorkGroupID;
gl_LocalInvocationIndex = stage_input.gl_LocalInvocationIndex;
comp_main();
}