Created
July 18, 2020 02:19
-
-
Save awygle/6ab2e89adafec1ce320bc3e9d715ae0b to your computer and use it in GitHub Desktop.
compute shader glsl dump
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#version 450 | |
layout(local_size_x = 1024) in; | |
layout(set = 0, binding = 0) buffer Buffer0 { | |
uint[16] state_in; | |
}; | |
layout(set = 0, binding = 1) buffer Buffer1 { | |
uint x_offset; | |
}; | |
layout(set = 0, binding = 2) buffer Buffer2 { | |
uint y_offset; | |
}; | |
layout(set = 0, binding = 3) buffer Buffer3 { | |
uint[1] finished; | |
}; | |
layout(set = 0, binding = 4) buffer Buffer4 { | |
uint[2] result; | |
}; | |
uint magic = 0x95DACFDC; | |
uint target_hi = 33208; | |
uint target_lo = 3022916510; | |
uint seed = 16191; | |
uint csum(uint op1, uint op2, uint op3) { | |
uint hi; | |
uint lo; | |
if (op2 == 0) { | |
op2 = op3; | |
} | |
umulExtended(op1, op2, hi, lo); | |
if (hi - lo == 0) { | |
return lo; | |
} | |
return hi - lo; | |
} | |
uint[16] round(uint[16] state, uint data_last, uint data, uint data_next, uint loop_count) { | |
state[0] += csum(uint(0x3EF - loop_count), data, loop_count); | |
state[1] = csum(state[1], data, loop_count); | |
state[2] ^= data; | |
state[3] += csum(data + 5, 0x6c078965, loop_count); | |
if (data_last < data) { | |
state[9] = csum(state[9], data, loop_count); | |
} | |
else { | |
state[9] += data; | |
} | |
state[4] += ((data << (0x20 - (data_last & 0x1f))) | (data >> (data_last & 0x1f))); | |
state[7] = csum(state[7], ((data >> (0x20 - (data_last & 0x1f))) | (data << (data_last & 0x1f))), loop_count); | |
if (data < state[6]) { | |
state[6] = (data + loop_count) ^ (state[3] + state[6]); | |
} | |
else { | |
state[6] = (state[4] + data) ^ state[6]; | |
} | |
state[5] += (data >> (0x20 - (data_last >> 27))) | (data << (data_last >> 27)); | |
state[8] = csum(state[8], (data << (0x20 - (data_last >> 27))) | (data >> (data_last >> 27)), loop_count); | |
if (loop_count == 0x3F0) return state; | |
uint tmp1 = csum(state[15], (data >> (0x20 - (data_last >> 27))) | (data << (data_last >> 27)), loop_count); | |
state[15] = csum(tmp1, (data_next << (data >> 27)) | (data_next >> (0x20 - (data >> 27))), loop_count); | |
uint tmp2 = ((data << (0x20 - (data_last & 0x1f))) | (data >> (data_last & 0x1f))); | |
uint tmp3 = csum(state[14], tmp2, loop_count); | |
uint tmp4 = csum(tmp3, (data_next >> (data & 0x1f)) | (data_next << (0x20 - (data & 0x1f))), loop_count); | |
state[14] = tmp4; | |
state[13] += ((data >> (data & 0x1f)) | (data << (0x20 - (data & 0x1f)))) + ((data_next >> (data_next & 0x1f)) | (data_next << (0x20 - (data_next & 0x1f)))); | |
state[10] = csum(state[10] + data, data_next, loop_count); | |
state[11] = csum(state[11] ^ data, data_next, loop_count); | |
state[12] += (state[8] ^ data); | |
return state; | |
} | |
uint[2] finalize(uint[16] state) { | |
uint buf[4]; | |
for (int i = 0; i < 4; i++) { | |
buf[i] = state[0]; | |
} | |
for (uint i = 0; i < 16; i++) { | |
uint data = state[i]; | |
uint shift = data & 0x1f; | |
uint data_shifted_left = data << (32 - shift); | |
uint data_shifted_right = data >> shift; | |
uint tmp = buf[0] + (data_shifted_right | data_shifted_left); | |
buf[0] = tmp; | |
if (data < tmp) { | |
buf[1] += data; | |
} | |
else { | |
buf[1] = csum(buf[1], data, i); | |
} | |
tmp = (data & 0x02) >> 1; | |
uint tmp2 = data & 0x01; | |
if (tmp == tmp2) { | |
buf[2] += data; | |
} | |
else { | |
buf[2] = csum(buf[2], data, i); | |
} | |
if (tmp2 == 1) { | |
buf[3] ^= data; | |
} | |
else { | |
buf[3] = csum(buf[3], data, i); | |
} | |
} | |
uint res[2]; | |
res[1] = csum(buf[0], buf[1], 16) & 0xFFFF; | |
res[0] = buf[3] ^ buf[2]; | |
return res; | |
} | |
uint[2] crunch(uint[16] state_in, uint hi, uint lo) { | |
uint state[16]; | |
for (int i = 0; i < 16; i++) { | |
state[i] = state_in[i]; | |
} | |
uint data_last = 0; | |
uint data = hi; | |
uint data_next = lo; | |
uint loop_count = 1007; | |
state = round(state, data_last, data, data_next, loop_count); | |
data_last = data; | |
data = data_next; | |
data_next = 0; | |
loop_count = 1008; | |
state = round(state, data_last, data, data_next, loop_count); | |
return finalize(state); | |
} | |
void main() { | |
uint y = y_offset; | |
uint x = x_offset + gl_GlobalInvocationID.x; | |
uint local_result[2] = crunch(state_in, y, x); | |
if (local_result[1] == target_hi && local_result[0] == target_lo) { | |
if (atomicOr(finished[0], 1) == 0) { | |
result[0] = x; | |
result[1] = y; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment