mirror of
https://git.triforceproject.com/triforce/source
synced 2026-11-19 16:20:01 -04:00
Triforce v0.2.0
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
55
gpu/vk/shaders/wb_diff.comp
Normal file
55
gpu/vk/shaders/wb_diff.comp
Normal file
@@ -0,0 +1,55 @@
|
||||
#version 460
|
||||
// (hookshot) The write-back's diff (vk_memory.cpp, "the write-back's diff"): a mirror's run copied back to guest memory where it
|
||||
// differs from the shadow (the pool's copy of what guest memory holds), the shadow kept the same. One workgroup a chunk of a
|
||||
// run (64 KB at most), from a table the CPU wrote. A chunk of 16-byte vectors goes a subgroup's span at a time, written whole
|
||||
// when any of its vectors differs (whole lines over PCIe: word by word it went at ~1 GB/s); a chunk's odd words one by one.
|
||||
// glslangValidator -V --target-env vulkan1.3 --vn WB_DIFF_COMP_SPV -o wb_diff_comp_spv.h wb_diff.comp
|
||||
#extension GL_EXT_buffer_reference : require
|
||||
#extension GL_EXT_buffer_reference_uvec2 : require
|
||||
#extension GL_KHR_shader_subgroup_vote : require
|
||||
layout(local_size_x = 256) in;
|
||||
layout(buffer_reference, std430, buffer_reference_align = 4) buffer Words { uint w[]; };
|
||||
layout(buffer_reference, std430, buffer_reference_align = 16) buffer Vecs { uvec4 v[]; };
|
||||
struct Chunk {
|
||||
uvec2 mirror; // (device addresses: the chunk's first byte in the mirror, the shadow and the guest memory's buffer)
|
||||
uvec2 shadow;
|
||||
uvec2 guest;
|
||||
uint count; // (16-byte vectors, or words)
|
||||
uint vecs; // (1: vectors, the three addresses 16-byte aligned; 0: words)
|
||||
};
|
||||
layout(buffer_reference, std430, buffer_reference_align = 8) readonly buffer Table { Chunk c[]; };
|
||||
layout(push_constant) uniform P {
|
||||
Table table;
|
||||
uint count;
|
||||
} pc;
|
||||
void main() {
|
||||
const uint ci = gl_WorkGroupID.x + gl_WorkGroupID.y * 65535u;
|
||||
if (ci >= pc.count) return;
|
||||
const Chunk c = pc.table.c[ci];
|
||||
if (c.vecs != 0u) {
|
||||
Vecs m = Vecs(c.mirror), s = Vecs(c.shadow), g = Vecs(c.guest);
|
||||
const uint n = (c.count + 255u) & ~255u; // (every invocation through the loop alike: the vote takes them all)
|
||||
for (uint i = gl_LocalInvocationID.x; i < n; i += 256u) {
|
||||
const bool in_run = i < c.count;
|
||||
uvec4 v = uvec4(0u);
|
||||
bool differs = false;
|
||||
if (in_run) {
|
||||
v = m.v[i];
|
||||
differs = any(notEqual(v, s.v[i]));
|
||||
}
|
||||
if (subgroupAny(differs) && in_run) {
|
||||
g.v[i] = v;
|
||||
s.v[i] = v;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Words m = Words(c.mirror), s = Words(c.shadow), g = Words(c.guest);
|
||||
for (uint i = gl_LocalInvocationID.x; i < c.count; i += 256u) {
|
||||
const uint v = m.w[i];
|
||||
if (v != s.w[i]) {
|
||||
g.w[i] = v;
|
||||
s.w[i] = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user