"""Pin original RGB-only HDR stores and current source-space GPU comparisons."""
from pathlib import Path
import hashlib
import json
import struct
def sha(data):
return hashlib.sha256(data).hexdigest()
root = Path('artifacts/galaxy-query-research')
effects = root / 'power-outer-sources/effects'
application_path = root / 'power-outer-sources/material-slots/original-blend-application.json'
application = json.loads(application_path.read_text())
rows = []
for material, shader, rgb, alpha in [
('sectorline_nodepth', 'ps_StarMapLine_Forward0_0_Win64_SM50', 'instanceRGB * HDRWrite', 'distanceFade * sampledAlpha * instanceAlpha'),
('spectralclassvismode_nodepth', 'ps_BackgroundStars_Forward0_0_Win64_SM50', 'clamp(maskGlow * instanceRGB, 0, 100) * HDRWrite', 'instanceAlpha'),
('traderoute', 'ps_RouteInstances_Forward0_0_Win64_SM50', 'atlas0.rgb*atlas0.a * atlas1.rgb*atlas1.a * trail.rgb * instanceRGB * HDRWrite', 'instanceAlpha'),
('traderoutehotspot', 'ps_RouteHotspotInstances_Forward0_0_Win64_SM50', 'atlas0.rgb*atlas0.a * atlas1.rgb*atlas1.a * instanceRGB * HDRWrite', 'instanceAlpha'),
('simplebillboardglow', 'ps_GalaxyMapSimpleBillboard_Forward_1_Win64_SM50', 'sampledRed * instanceAlpha * linearInstanceRGB * HDRWrite', 'zero'),
]:
state = next(r for r in application['materials'] if r['material'] == material and r['resolved'])
archive_path = Path(state['archiveSource'])
archive = archive_path.read_bytes()
if sha(archive) != state['archiveSha256']:
raise ValueError('Pinned effects changed')
first_marker = archive.index(b'\0\1voMrtP', state['effectArchiveOffset'] + 8)
first_size, relocations = struct.unpack_from('<2I', archive, first_marker + 8)
second_marker = archive.index(b'\0\1voMrtP', first_marker + 16 + first_size + relocations * 4)
second_size = struct.unpack_from('<I', archive, second_marker + 8)[0]
second = archive[second_marker + 16:second_marker + 16 + second_size]
if sha(second) != state['secondObjectSha256']:
raise ValueError('Frozen variable reflection changed')
pointer, count = struct.unpack_from('<2Q', second, 0x48)
fields = {}
for index in range(count):
record = second[pointer + index * 32:pointer + index * 32 + 32]
name_pointer = struct.unpack_from('<Q', record)[0]
name = second[name_pointer:second.index(0, name_pointer)].decode('ascii')
if name in ('gHDRScalingWrite', 'gHDRScalingRead', 'gCameraPos'):
encoded = struct.unpack_from('<H', record, 10)[0]
fields[name] = dict(bank=encoded & 3, byteOffset=(encoded >> 1) & 0x7FFC, descriptorRaw=record.hex())
shared_start = fields['gCameraPos']['byteOffset'] - 275 * 16
if shared_start != 272 or fields['gHDRScalingWrite']['byteOffset'] - shared_start != 90 * 16 + 4:
raise ValueError('Original GPU HDR Write/CameraPos anchor changed')
folder = effects if material not in ('traderoute', 'traderoutehotspot') else root / 'current-trade/effects'
text_path, blob_path = folder / (shader + '.txt'), folder / (shader + '.dxbc')
text, blob = text_path.read_text(), blob_path.read_bytes()
if blob not in archive or 'mul o0.xyz, ' not in text or 'cb1[90].yyyy' not in text:
raise ValueError('Original pixel program/source HDR store changed')
if alpha == 'instanceAlpha' and 'mov o0.w, v' not in text:
raise ValueError('Original source alpha is not retained')
if alpha == 'zero' and 'mov o0.w, l(0)' not in text:
raise ValueError('Original additive alpha changed')
rows.append(dict(material=material, passNames=state['passes'], shader=shader,
sourceArchive=str(archive_path), sourceArchiveSha256=state['archiveSha256'],
bytecode=str(blob_path), bytecodeSha256=sha(blob), assembly=str(text_path), assemblySha256=sha(text.encode()),
reflection=fields, sharedGpuBufferDataStart=shared_start, actualPixelRegister='cb1[90].y',
rgbEquation=rgb, alphaEquation=alpha, originalBlend=state['d3d11']))
production = ['XFEEDToolBox/Assets/GalaxyMap.hlsl', 'XFEEDToolBox/Rendering/GalaxyGridGraphics.cs',
'XFEEDToolBox/Rendering/GalaxyTradeGraphics.cs']
probes = [Path('artifacts/galaxy-stellar-shader-validation/report.json'),
Path('artifacts/galaxy-grid-shader-validation/report.json')]
stellar = json.loads(probes[0].read_text())
grid = json.loads(probes[1].read_text())
if len(stellar['hdr']) != 2 or any(r['maximumRgbVectorDifference'] > .003 or r['sdrPremultiplicationAdapterApplied'] for r in stellar['hdr']):
raise ValueError('Current stellar source comparison is not the original unassociated output')
grid_hdr = next(row for row in grid if row.get('hdrStorage'))
if grid_hdr['rgbError'] > 1e-5 or grid_hdr['alphaError'] > 1e-5:
raise ValueError('Current grid HDR Write scales source alpha')
output = dict(gameProcessAccess=False, gameCalls=0, materialBlendProof=str(application_path),
materialBlendProofSha256=sha(application_path.read_bytes()), sources=rows,
sourceOutput=dict(buffer='b8', value='float4(HDRWrite, originalSourceEnabled, 0, 0)',
binding='BindOriginalSourceOutput(float hdrWrite=1, bool applySourceAlphaBlend=true)',
defaultProbeWrite=1, productionWrite=1 / 256, alphaScaled=False),
production=[dict(path=path, sha256=sha(Path(path).read_bytes())) for path in production],
comparisons=[dict(path=str(path), sha256=sha(path.read_bytes())) for path in probes],
toolAdapters=['PSOverview RGB-only scene storage', 'PSGalacticZones RGB-only scene storage',
'PSNebulaComposite RGB-only scene storage'],
limits=['Original sampled source outputs and material blend do not certify final output/exposure/LUT/bloom',
'Tool nebula/zone/overview calculations remain explicit adaptations',
'Live shared state and cell/frame fade remain separate from default source-space probes'],
fullOutputRestored=False)
target = root / 'current-trade/source-hdr-output.json'
target.write_text(json.dumps(output, indent=2) + '\n', encoding='utf-8')
print(json.dumps(dict(path=str(target), sources=len(rows), stellarCases=2, gridRgbError=grid_hdr['rgbError'], gridAlphaError=grid_hdr['alphaError'])))
"""Pin original RGB-only HDR stores and current source-space GPU comparisons."""
from pathlib import Path
import hashlib
import json
import struct
def sha(data):
return hashlib.sha256(data).hexdigest()
root = Path('artifacts/galaxy-query-research')
effects = root / 'power-outer-sources/effects'
application_path = root / 'power-outer-sources/material-slots/original-blend-application.json'
application = json.loads(application_path.read_text())
rows = []
for material, shader, rgb, alpha in [
('sectorline_nodepth', 'ps_StarMapLine_Forward0_0_Win64_SM50', 'instanceRGB * HDRWrite', 'distanceFade * sampledAlpha * instanceAlpha'),
('spectralclassvismode_nodepth', 'ps_BackgroundStars_Forward0_0_Win64_SM50', 'clamp(maskGlow * instanceRGB, 0, 100) * HDRWrite', 'instanceAlpha'),
('traderoute', 'ps_RouteInstances_Forward0_0_Win64_SM50', 'atlas0.rgb*atlas0.a * atlas1.rgb*atlas1.a * trail.rgb * instanceRGB * HDRWrite', 'instanceAlpha'),
('traderoutehotspot', 'ps_RouteHotspotInstances_Forward0_0_Win64_SM50', 'atlas0.rgb*atlas0.a * atlas1.rgb*atlas1.a * instanceRGB * HDRWrite', 'instanceAlpha'),
('simplebillboardglow', 'ps_GalaxyMapSimpleBillboard_Forward_1_Win64_SM50', 'sampledRed * instanceAlpha * linearInstanceRGB * HDRWrite', 'zero'),
]:
state = next(r for r in application['materials'] if r['material'] == material and r['resolved'])
archive_path = Path(state['archiveSource'])
archive = archive_path.read_bytes()
if sha(archive) != state['archiveSha256']:
raise ValueError('Pinned effects changed')
first_marker = archive.index(b'\0\1voMrtP', state['effectArchiveOffset'] + 8)
first_size, relocations = struct.unpack_from('<2I', archive, first_marker + 8)
second_marker = archive.index(b'\0\1voMrtP', first_marker + 16 + first_size + relocations * 4)
second_size = struct.unpack_from('<I', archive, second_marker + 8)[0]
second = archive[second_marker + 16:second_marker + 16 + second_size]
if sha(second) != state['secondObjectSha256']:
raise ValueError('Frozen variable reflection changed')
pointer, count = struct.unpack_from('<2Q', second, 0x48)
fields = {}
for index in range(count):
record = second[pointer + index * 32:pointer + index * 32 + 32]
name_pointer = struct.unpack_from('<Q', record)[0]
name = second[name_pointer:second.index(0, name_pointer)].decode('ascii')
if name in ('gHDRScalingWrite', 'gHDRScalingRead', 'gCameraPos'):
encoded = struct.unpack_from('<H', record, 10)[0]
fields[name] = dict(bank=encoded & 3, byteOffset=(encoded >> 1) & 0x7FFC, descriptorRaw=record.hex())
shared_start = fields['gCameraPos']['byteOffset'] - 275 * 16
if shared_start != 272 or fields['gHDRScalingWrite']['byteOffset'] - shared_start != 90 * 16 + 4:
raise ValueError('Original GPU HDR Write/CameraPos anchor changed')
folder = effects if material not in ('traderoute', 'traderoutehotspot') else root / 'current-trade/effects'
text_path, blob_path = folder / (shader + '.txt'), folder / (shader + '.dxbc')
text, blob = text_path.read_text(), blob_path.read_bytes()
if blob not in archive or 'mul o0.xyz, ' not in text or 'cb1[90].yyyy' not in text:
raise ValueError('Original pixel program/source HDR store changed')
if alpha == 'instanceAlpha' and 'mov o0.w, v' not in text:
raise ValueError('Original source alpha is not retained')
if alpha == 'zero' and 'mov o0.w, l(0)' not in text:
raise ValueError('Original additive alpha changed')
rows.append(dict(material=material, passNames=state['passes'], shader=shader,
sourceArchive=str(archive_path), sourceArchiveSha256=state['archiveSha256'],
bytecode=str(blob_path), bytecodeSha256=sha(blob), assembly=str(text_path), assemblySha256=sha(text.encode()),
reflection=fields, sharedGpuBufferDataStart=shared_start, actualPixelRegister='cb1[90].y',
rgbEquation=rgb, alphaEquation=alpha, originalBlend=state['d3d11']))
production = ['XFEEDToolBox/Assets/GalaxyMap.hlsl', 'XFEEDToolBox/Rendering/GalaxyGridGraphics.cs',
'XFEEDToolBox/Rendering/GalaxyTradeGraphics.cs']
probes = [Path('artifacts/galaxy-stellar-shader-validation/report.json'),
Path('artifacts/galaxy-grid-shader-validation/report.json')]
stellar = json.loads(probes[0].read_text())
grid = json.loads(probes[1].read_text())
if len(stellar['hdr']) != 2 or any(r['maximumRgbVectorDifference'] > .003 or r['sdrPremultiplicationAdapterApplied'] for r in stellar['hdr']):
raise ValueError('Current stellar source comparison is not the original unassociated output')
grid_hdr = next(row for row in grid if row.get('hdrStorage'))
if grid_hdr['rgbError'] > 1e-5 or grid_hdr['alphaError'] > 1e-5:
raise ValueError('Current grid HDR Write scales source alpha')
output = dict(gameProcessAccess=False, gameCalls=0, materialBlendProof=str(application_path),
materialBlendProofSha256=sha(application_path.read_bytes()), sources=rows,
sourceOutput=dict(buffer='b8', value='float4(HDRWrite, originalSourceEnabled, 0, 0)',
binding='BindOriginalSourceOutput(float hdrWrite=1, bool applySourceAlphaBlend=true)',
defaultProbeWrite=1, productionWrite=1 / 256, alphaScaled=False),
production=[dict(path=path, sha256=sha(Path(path).read_bytes())) for path in production],
comparisons=[dict(path=str(path), sha256=sha(path.read_bytes())) for path in probes],
toolAdapters=['PSOverview RGB-only scene storage', 'PSGalacticZones RGB-only scene storage',
'PSNebulaComposite RGB-only scene storage'],
limits=['Original sampled source outputs and material blend do not certify final output/exposure/LUT/bloom',
'Tool nebula/zone/overview calculations remain explicit adaptations',
'Live shared state and cell/frame fade remain separate from default source-space probes'],
fullOutputRestored=False)
target = root / 'current-trade/source-hdr-output.json'
target.write_text(json.dumps(output, indent=2) + '\n', encoding='utf-8')
print(json.dumps(dict(path=str(target), sources=len(rows), stellarCases=2, gridRgbError=grid_hdr['rgbError'], gridAlphaError=grid_hdr['alphaError'])))