"""The SPIR-V of DLSS's reactive mask pass (vk_dlaa.c, mask_pass) as runtime/dlaa_mask_spv.h, assembled here like tools/make_mvobj_fs.py. tools/build_shaders.py writes the header from HEADER when the game is built; run on its own, this script writes it too. The shader, as GLSL: #version 450 layout(local_size_x = 8, local_size_y = 8) in; layout(binding = 0) uniform sampler2D before; // the light target when the transparents start layout(binding = 1) uniform sampler2D after; // the light target when DLSS runs layout(binding = 2, r8) uniform writeonly image2D mask; layout(push_constant) uniform P { vec4 p; }; // render size xy, threshold z, gain w void main() { vec2 g = vec2(gl_GlobalInvocationID.xy); if (g.x < p.x && g.y < p.y) { ivec2 c = ivec2(gl_GlobalInvocationID.xy); vec3 b = texelFetch(before, c, 0).rgb, a = texelFetch(after, c, 0).rgb; vec3 d = abs(a - b); float dm = max(max(d.r, d.g), d.b); float m = max(max(max(a.r, a.g), a.b), max(max(b.r, b.g), b.b)); float r = dm / max(m, 1e-4); imageStore(mask, c, vec4(clamp((r - p.z) * p.w, 0.0, 1.0))); } } The mask is the share of a pixel's colour the transparents changed (particles, smoke, sparks: what has no motion vectors of its own), 0 where nothing was drawn over the solid scene. python tools/make_dlaa_mask.py """ import struct from pathlib import Path ROOT = Path(__file__).resolve().parent.parent OUT = ROOT / 'runtime' / 'dlaa_mask_spv.h' SECTIONS = ('cap', 'ext', 'mem', 'entry', 'exec', 'dec', 'types', 'func') class Asm: def __init__(self): self.next = 1 self.sections = {k: [] for k in SECTIONS} def id(self): self.next += 1 return self.next - 1 def op(self, sec, code, *words): self.sections[sec].append([(len(words) + 1) << 16 | code, *words]) def words(self): out = [0x07230203, 0x00010000, 0, self.next, 0] for sec in SECTIONS: for ins in self.sections[sec]: out.extend(ins) return out def string(s): b = s.encode() + b'\0' b += b'\0' * (-len(b) % 4) return list(struct.unpack('<%dI' % (len(b) // 4), b)) def f32(x): return struct.unpack('\n' 'static const uint32_t dlaa_mask_spv[] = {\n ' + ',\n '.join(lines) + '\n};\n') if __name__ == '__main__': OUT.write_text(HEADER, newline='\n') print(f'{OUT}: {len(w)} words')