72 Cores an an RX 480 in Python
import sys, numpy as np
from OpenGL.GL import *
from OpenGL.GLUT import *
from OpenGL.GL.shaders import compileProgram, compileShader
import math
# ---------------- Shader Sources ----------------
VERTEX_SRC = """
#version 330
layout (location = 0) in vec2 pos;
out vec2 texCoord;
void main() {
texCoord = (pos + 1.0) * 0.5;
gl_Position = vec4(pos, 0.0, 1.0);
}
"""
FRAGMENT_SRC = """
#version 330
in vec2 texCoord;
out vec4 fragColor;
uniform sampler2D latticeTex; // 32×72 lattice
uniform sampler2D historyTex; // scrolling history
uniform float cycle;
uniform float omegaTime; // analog Ω overlay
// Threshold function
float binarize(float x) {
return x > 0.5 ? 1.0 : 0.0;
}
void main() {
int x = int(texCoord.x * 32.0); // lattice slot
int y = int(texCoord.y * 72.0); // lattice instance
// fetch current slot state
float val = texelFetch(latticeTex, ivec2(x, y), 0).r;
// --- HDGL toy update ---
float phi = 1.6180339887;
float r_dim = 0.3 + 0.01 * float(y); // per-instance recursion bias
float omega = 0.5 + 0.5*sin(omegaTime); // analog Ω oscillation
float new_val = val + r_dim * 0.5 + omega * 0.25;
float slot = binarize(mod(new_val + float((int(cycle)+x+y)%2), 2.0));
fragColor = vec4(slot, slot, slot, 1.0);
}
"""
# ---------------- Globals ----------------
window = None
shader = None
vao = None
lattice_tex = None
history_tex = None
cycle = 0.0
omega_time = 0.0
# ---------------- OpenGL Init ----------------
def init_gl():
global shader, vao, lattice_tex, history_tex
shader = compileProgram(
compileShader(VERTEX_SRC, GL_VERTEX_SHADER),
compileShader(FRAGMENT_SRC, GL_FRAGMENT_SHADER)
)
# Fullscreen quad
verts = np.array([-1,-1, 1,-1, -1,1, 1,-1, 1,1, -1,1], dtype=np.float32)
vao = glGenVertexArrays(1)
glBindVertexArray(vao)
vbo = glGenBuffers(1)
glBindBuffer(GL_ARRAY_BUFFER, vbo)
glBufferData(GL_ARRAY_BUFFER, verts.nbytes, verts, GL_STATIC_DRAW)
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, None)
glEnableVertexAttribArray(0)
# Lattice state texture: 32 slots × 72 instances
init_lattice = np.zeros((72,32), dtype=np.float32)
for i in range(72):
init_lattice[i,0] = 1.0 # seed one active slot per instance
lattice_tex = glGenTextures(1)
glBindTexture(GL_TEXTURE_2D, lattice_tex)
glTexImage2D(GL_TEXTURE_2D, 0, GL_R32F, 32, 72, 0, GL_RED, GL_FLOAT, init_lattice)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
# History texture (same width, arbitrary height 100 cycles)
history_tex = glGenTextures(1)
glBindTexture(GL_TEXTURE_2D, history_tex)
glTexImage2D(GL_TEXTURE_2D, 0, GL_R32F, 32, 100, 0, GL_RED, GL_FLOAT, None)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
# ---------------- Display ----------------
def display():
global cycle, omega_time
glClear(GL_COLOR_BUFFER_BIT)
glUseProgram(shader)
glUniform1i(glGetUniformLocation(shader, "latticeTex"), 0)
glUniform1i(glGetUniformLocation(shader, "historyTex"), 1)
glUniform1f(glGetUniformLocation(shader, "cycle"), cycle)
glUniform1f(glGetUniformLocation(shader, "omegaTime"), omega_time)
glActiveTexture(GL_TEXTURE0)
glBindTexture(GL_TEXTURE_2D, lattice_tex)
glActiveTexture(GL_TEXTURE1)
glBindTexture(GL_TEXTURE_2D, history_tex)
glBindVertexArray(vao)
glDrawArrays(GL_TRIANGLES, 0, 6)
glutSwapBuffers()
cycle += 1
omega_time += 0.05 # smooth Ω oscillation
def idle():
glutPostRedisplay()
# ---------------- Main ----------------
def main():
global window
glutInit(sys.argv)
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE)
glutInitWindowSize(1280, 720)
window = glutCreateWindow(b"HDGL GPU Lattice w/ Ω Clock")
init_gl()
glutDisplayFunc(display)
glutIdleFunc(idle)
glutMainLoop()
if __name__ == "__main__":
main()
over 2,000 threads on RX 480
import sys, numpy as np
from OpenGL.GL import *
from OpenGL.GLUT import *
from OpenGL.GL.shaders import compileProgram, compileShader
# ---------- Shaders ----------
VERTEX_SRC = """
#version 330
layout(location = 0) in vec2 pos;
out vec2 texCoord;
void main() {
texCoord = (pos + 1.0) * 0.5;
gl_Position = vec4(pos,0,1);
}
"""
FRAGMENT_SRC = """
#version 330
in vec2 texCoord;
out vec4 fragColor;
uniform sampler2D latticeTex;
uniform float cycle;
uniform float omegaTime;
uniform float phiPowers[72]; // Precomputed 1/(phi^7)^n
uniform float threshold;
float phi = 1.6180339887;
float hdgl_slot(float val, float r_dim, float omega, int x, int y){
float idx0 = float(x % 4 == 0 ? 1 : 0);
float resonance = 0.1 * sin(float(cycle)*0.05 + float(y)) * idx0;
float wave = 0.3 * float(x%3==0) -0.3 * float(x%3==2);
float omega_inst = phiPowers[y % 72];
float rec = r_dim*val*0.5 + 0.25*sin(float(cycle)*r_dim + float(x));
float new_val = val + omega_inst + resonance + wave + rec + omega*0.05;
return new_val > threshold ? 1.0 : 0.0;
}
void main(){
int x = int(texCoord.x * 32.0);
int y = int(texCoord.y * 2304.0); // test lattice height
float val = texelFetch(latticeTex, ivec2(x,y), 0).r;
float r_dim = 0.3 + 0.01*float(y);
float new_val = hdgl_slot(val, r_dim, sin(omegaTime), x, y);
fragColor = vec4(new_val, sin(omegaTime), 0.0, 1.0);
}
"""
# ---------- Globals ----------
window = None
shader = None
vao = None
fbo = [0,0]
tex = [0,0]
current = 0
cycle = 0.0
omega_time = 0.0
# --------- FIXED PHI POWERS ----------
# Precompute Ω tension safely: 1/(phi^7)^n
phi = 1.6180339887
phi_powers = np.array([1.0 / pow(phi, 7*(i+1)) for i in range(72)], dtype=np.float32)
threshold = np.sqrt(phi)
# ---------- OpenGL Init ----------
def init_gl():
global shader, vao, fbo, tex
shader = compileProgram(compileShader(VERTEX_SRC, GL_VERTEX_SHADER),
compileShader(FRAGMENT_SRC, GL_FRAGMENT_SHADER))
# Fullscreen quad
verts = np.array([-1,-1,1,-1,-1,1,1,-1,1,1,-1,1],dtype=np.float32)
vao = glGenVertexArrays(1)
glBindVertexArray(vao)
vbo = glGenBuffers(1)
glBindBuffer(GL_ARRAY_BUFFER, vbo)
glBufferData(GL_ARRAY_BUFFER, verts.nbytes, verts, GL_STATIC_DRAW)
glVertexAttribPointer(0,2,GL_FLOAT,GL_FALSE,0,None)
glEnableVertexAttribArray(0)
# Ping-pong FBOs
fbo[0], fbo[1] = glGenFramebuffers(2)
tex[0], tex[1] = glGenTextures(2)
for i in range(2):
glBindTexture(GL_TEXTURE_2D, tex[i])
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA32F,32,2304,0,GL_RGBA,GL_FLOAT,None)
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST)
glBindFramebuffer(GL_FRAMEBUFFER,fbo[i])
glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,tex[i],0)
# Seed first lattice
init_lattice = np.zeros((2304,32,4),dtype=np.float32)
init_lattice[:,0,0] = 1.0
glBindTexture(GL_TEXTURE_2D,tex[0])
glTexSubImage2D(GL_TEXTURE_2D,0,0,0,32,2304,GL_RGBA,GL_FLOAT,init_lattice)
glBindFramebuffer(GL_FRAMEBUFFER,0)
# ---------- Display ----------
def display():
global cycle, omega_time, current
next_idx = 1-current
glBindFramebuffer(GL_FRAMEBUFFER,fbo[next_idx])
glViewport(0,0,32,2304)
glClear(GL_COLOR_BUFFER_BIT)
glUseProgram(shader)
glUniform1i(glGetUniformLocation(shader,"latticeTex"),0)
glUniform1f(glGetUniformLocation(shader,"cycle"),cycle)
glUniform1f(glGetUniformLocation(shader,"omegaTime"),omega_time)
glUniform1fv(glGetUniformLocation(shader,"phiPowers"),72,phi_powers)
glUniform1f(glGetUniformLocation(shader,"threshold"),threshold)
glActiveTexture(GL_TEXTURE0)
glBindTexture(GL_TEXTURE_2D, tex[current])
glBindVertexArray(vao)
glDrawArrays(GL_TRIANGLES,0,6)
glBindFramebuffer(GL_FRAMEBUFFER,0)
glViewport(0,0,1280,720)
glBindTexture(GL_TEXTURE_2D, tex[next_idx])
glDrawArrays(GL_TRIANGLES,0,6)
glutSwapBuffers()
cycle +=1
omega_time +=0.05
current = next_idx
def idle():
glutPostRedisplay()
def main():
global window
glutInit(sys.argv)
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE)
glutInitWindowSize(1280,720)
window = glutCreateWindow(b"HDGL Max-Scale GPU Lattice + Ω Clock")
init_gl()
glutDisplayFunc(display)
glutIdleFunc(idle)
glutMainLoop()
if __name__=="__main__":
main()
The specs say I can handle 15M instances. How about just 150k instances for starters? Anyone?
import sys, numpy as np
from OpenGL.GL import *
from OpenGL.GLUT import *
from OpenGL.GL.shaders import compileProgram, compileShader
# ---------- Shaders ----------
VERTEX_SRC = """
#version 330
layout(location = 0) in vec2 pos;
out vec2 texCoord;
void main() {
texCoord = (pos + 1.0) * 0.5;
gl_Position = vec4(pos,0,1);
}
"""
FRAGMENT_SRC = """
#version 330
in vec2 texCoord;
out vec4 fragColor;
uniform sampler2D latticeTex;
uniform float cycle;
uniform float omegaTime;
uniform float phiPowers[72];
uniform float threshold;
uniform int latticeHeight;
uniform int yOffset;
float hdgl_slot(float val, float r_dim, float omega, int x, int y){
float resonance = (x % 4 == 0 ? 0.1 * sin(float(cycle)*0.05 + float(y)) : 0.0);
float wave = (x % 3 == 0 ? 0.3 : (x % 3 == 1 ? 0.0 : -0.3));
float omega_inst = phiPowers[y % 72];
float rec = r_dim*val*0.5 + 0.25*sin(float(cycle)*r_dim + float(x));
float new_val = val + omega_inst + resonance + wave + rec + omega*0.05;
return new_val > threshold ? 1.0 : 0.0;
}
void main(){
int x = int(texCoord.x * 32.0);
int y = int(texCoord.y * float(latticeHeight)) + yOffset;
float val = texelFetch(latticeTex, ivec2(x,y - yOffset), 0).r;
float r_dim = 0.3 + 0.01*float(y);
float new_val = hdgl_slot(val, r_dim, sin(omegaTime), x, y);
fragColor = vec4(new_val, sin(omegaTime), 0.0, 1.0);
}
"""
# ---------- Globals ----------
window = None
shader = None
vao = None
textures = []
fbos = []
current = 0
cycle = 0.0
omega_time = 0.0
# ---------- Lattice parameters ----------
lattice_width = 32
num_instances = 150_000 # Reduced from 15M for stability
max_tex_height = 2048 # Safe texture height
sub_tile_height = 256 # Smaller sub-tile per frame
threshold = np.sqrt(1.6180339887)
phi = 1.6180339887
phi_powers = np.array([1.0 / pow(phi, 7*(i+1)) for i in range(72)], dtype=np.float32)
# ---------- Tile division ----------
tile_count = (num_instances + max_tex_height - 1) // max_tex_height
tile_heights = [min(max_tex_height, num_instances - i*max_tex_height) for i in range(tile_count)]
# ---------- OpenGL Init ----------
def init_gl():
global shader, vao, textures, fbos
shader = compileProgram(compileShader(VERTEX_SRC, GL_VERTEX_SHADER),
compileShader(FRAGMENT_SRC, GL_FRAGMENT_SHADER))
verts = np.array([-1,-1,1,-1,-1,1,1,-1,1,1,-1,1], dtype=np.float32)
vao = glGenVertexArrays(1)
glBindVertexArray(vao)
vbo = glGenBuffers(1)
glBindBuffer(GL_ARRAY_BUFFER, vbo)
glBufferData(GL_ARRAY_BUFFER, verts.nbytes, verts, GL_STATIC_DRAW)
glVertexAttribPointer(0,2,GL_FLOAT,GL_FALSE,0,None)
glEnableVertexAttribArray(0)
for t, th in enumerate(tile_heights):
tex_pair = glGenTextures(2)
fbo_pair = glGenFramebuffers(2)
for i in range(2):
glBindTexture(GL_TEXTURE_2D, tex_pair[i])
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, lattice_width, th, 0, GL_RGBA, GL_FLOAT, None)
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST)
glBindFramebuffer(GL_FRAMEBUFFER, fbo_pair[i])
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex_pair[i],0)
textures.append(tex_pair)
fbos.append(fbo_pair)
# Initialize lattice with zeros
for start in range(0, th, sub_tile_height):
end = min(start + sub_tile_height, th) # <- use th directly
init_chunk = np.zeros((end-start, lattice_width, 4), dtype=np.float32)
glBindTexture(GL_TEXTURE_2D, tex_pair[0])
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, start, lattice_width, end-start, GL_RGBA, GL_FLOAT, init_chunk)
glBindFramebuffer(GL_FRAMEBUFFER,0)
# ---------- Display ----------
def display():
global cycle, omega_time, current
next_idx = 1-current
for t, th in enumerate(tile_heights):
for y_start in range(0, th, sub_tile_height):
h = min(sub_tile_height, th - y_start)
glBindFramebuffer(GL_FRAMEBUFFER, fbos[t][next_idx])
glViewport(0,0,lattice_width,h)
glUseProgram(shader)
glUniform1i(glGetUniformLocation(shader,"latticeTex"),0)
glUniform1f(glGetUniformLocation(shader,"cycle"),cycle)
glUniform1f(glGetUniformLocation(shader,"omegaTime"),omega_time)
glUniform1fv(glGetUniformLocation(shader,"phiPowers"),72,phi_powers)
glUniform1f(glGetUniformLocation(shader,"threshold"),threshold)
glUniform1i(glGetUniformLocation(shader,"latticeHeight"), h)
glUniform1i(glGetUniformLocation(shader,"yOffset"), y_start)
glActiveTexture(GL_TEXTURE0)
glBindTexture(GL_TEXTURE_2D, textures[t][current])
glBindVertexArray(vao)
glDrawArrays(GL_TRIANGLES,0,6)
glBindFramebuffer(GL_FRAMEBUFFER,0)
glViewport(0,0,1280,720)
for t, th in enumerate(tile_heights):
glBindTexture(GL_TEXTURE_2D, textures[t][next_idx])
glDrawArrays(GL_TRIANGLES,0,6)
glutSwapBuffers()
cycle += 1
omega_time += 0.05
current = next_idx
def idle():
glutPostRedisplay()
def main():
glutInit(sys.argv)
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE)
glutInitWindowSize(1280,720)
glutCreateWindow(b"HDGL 150k Instance GPU Lattice + PHI Clock")
init_gl()
glutDisplayFunc(display)
glutIdleFunc(idle)
glutMainLoop()
if __name__=="__main__":
main()
How about progressive scaling up to 500k instances? Anyone up for that? You can change the number, which was recommended to me as 15 Million, but that crashed me out so that’s why we test specific to our card.
import sys, time
import numpy as np
from OpenGL.GL import *
from OpenGL.GLUT import *
from OpenGL.GL.shaders import compileProgram, compileShader
# ---------- Shaders ----------
VERTEX_SRC = """
#version 330
layout(location = 0) in vec2 pos;
out vec2 texCoord;
void main(){
texCoord = (pos + 1.0)*0.5;
gl_Position = vec4(pos,0,1);
}
"""
FRAGMENT_SRC = """
#version 330
in vec2 texCoord;
out vec4 fragColor;
uniform sampler2D latticeTex;
uniform float cycle;
uniform float omegaTime;
uniform float phiPowers[72];
uniform float threshold;
uniform int latticeHeight;
uniform int yOffset;
float hdgl_slot(float val, float r_dim, float omega, int x, int y){
float resonance = (x % 4 == 0 ? 0.1 * sin(cycle*0.05 + float(y)) : 0.0);
float wave = (x % 3 == 0 ? 0.3 : (x % 3 == 1 ? 0.0 : -0.3));
float omega_inst = phiPowers[y % 72];
float rec = r_dim*val*0.5 + 0.25*sin(cycle*r_dim + float(x));
float new_val = val + omega_inst + resonance + wave + rec + omega*0.05;
return new_val > threshold ? 1.0 : 0.0;
}
void main(){
int x = int(texCoord.x * 32.0);
int y = int(texCoord.y * float(latticeHeight)) + yOffset;
float val = texelFetch(latticeTex, ivec2(x,y - yOffset), 0).r;
float r_dim = 0.3 + 0.01*float(y);
float new_val = hdgl_slot(val, r_dim, sin(omegaTime), x, y);
fragColor = vec4(new_val, sin(omegaTime), 0.0, 1.0);
}
"""
# ---------- Globals ----------
window = None
shader = None
vao = None
textures = []
fbos = []
current = 0
cycle = 0.0
omega_time = 0.0
# ---------- Lattice parameters ----------
lattice_width = 32
num_instances_base = 50_000 # Starting instances
num_instances_max = 500_000 # Max scaling
instance_step = 10_000
scale_interval = 2.0 # Seconds between steps
sub_tile_height = 256
max_tex_height = 2048
threshold = np.sqrt(1.6180339887)
phi = 1.6180339887
phi_powers = np.array([1.0 / pow(phi, 7*(i+1)) for i in range(72)], dtype=np.float32)
tile_heights = []
tile_count = 0
last_scale_time = time.time()
# ---------- OpenGL Init ----------
def init_gl():
global shader, vao, textures, fbos, tile_heights, tile_count
shader = compileProgram(compileShader(VERTEX_SRC, GL_VERTEX_SHADER),
compileShader(FRAGMENT_SRC, GL_FRAGMENT_SHADER))
verts = np.array([-1,-1,1,-1,-1,1,1,-1,1,1,-1,1], dtype=np.float32)
vao = glGenVertexArrays(1)
glBindVertexArray(vao)
vbo = glGenBuffers(1)
glBindBuffer(GL_ARRAY_BUFFER, vbo)
glBufferData(GL_ARRAY_BUFFER, verts.nbytes, verts, GL_STATIC_DRAW)
glVertexAttribPointer(0,2,GL_FLOAT,GL_FALSE,0,None)
glEnableVertexAttribArray(0)
# Initialize lattice
reinit_lattice(num_instances_base)
# ---------- Lattice reinit ----------
def reinit_lattice(new_num_instances):
global textures, fbos, tile_heights, tile_count
# Clean old resources
for tex_pair in textures:
glDeleteTextures(tex_pair)
for fbo_pair in fbos:
glDeleteFramebuffers(2, fbo_pair)
textures.clear()
fbos.clear()
tile_count = (new_num_instances + max_tex_height - 1) // max_tex_height
tile_heights = [min(max_tex_height, new_num_instances - i*max_tex_height) for i in range(tile_count)]
for t, th in enumerate(tile_heights):
tex_pair = glGenTextures(2)
fbo_pair = glGenFramebuffers(2)
for i in range(2):
glBindTexture(GL_TEXTURE_2D, tex_pair[i])
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, lattice_width, th, 0, GL_RGBA, GL_FLOAT, None)
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST)
glBindFramebuffer(GL_FRAMEBUFFER, fbo_pair[i])
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex_pair[i],0)
textures.append(tex_pair)
fbos.append(fbo_pair)
for start in range(0, th, sub_tile_height):
end = min(start + sub_tile_height, th)
init_chunk = np.zeros((end-start, lattice_width,4), dtype=np.float32)
glBindTexture(GL_TEXTURE_2D, tex_pair[0])
glTexSubImage2D(GL_TEXTURE_2D,0,0,start,lattice_width,end-start,GL_RGBA,GL_FLOAT,init_chunk)
glBindFramebuffer(GL_FRAMEBUFFER,0)
# ---------- Display ----------
def display():
global cycle, omega_time, current
next_idx = 1-current
for t, th in enumerate(tile_heights):
for y_start in range(0, th, sub_tile_height):
h = min(sub_tile_height, th - y_start)
glBindFramebuffer(GL_FRAMEBUFFER, fbos[t][next_idx])
glViewport(0,0,lattice_width,h)
glUseProgram(shader)
glUniform1i(glGetUniformLocation(shader,"latticeTex"),0)
glUniform1f(glGetUniformLocation(shader,"cycle"),cycle)
glUniform1f(glGetUniformLocation(shader,"omegaTime"),omega_time)
glUniform1fv(glGetUniformLocation(shader,"phiPowers"),72,phi_powers)
glUniform1f(glGetUniformLocation(shader,"threshold"),threshold)
glUniform1i(glGetUniformLocation(shader,"latticeHeight"), h)
glUniform1i(glGetUniformLocation(shader,"yOffset"), y_start)
glActiveTexture(GL_TEXTURE0)
glBindTexture(GL_TEXTURE_2D, textures[t][current])
glBindVertexArray(vao)
glDrawArrays(GL_TRIANGLES,0,6)
glBindFramebuffer(GL_FRAMEBUFFER,0)
glViewport(0,0,1280,720)
for t, th in enumerate(tile_heights):
glBindTexture(GL_TEXTURE_2D, textures[t][next_idx])
glDrawArrays(GL_TRIANGLES,0,6)
glutSwapBuffers()
cycle += 1
omega_time += 0.05
current = next_idx
# ---------- Idle ----------
def idle():
global num_instances_base, last_scale_time
glutPostRedisplay()
now = time.time()
if now - last_scale_time > scale_interval and num_instances_base < num_instances_max:
num_instances_base += instance_step
last_scale_time = now
print(f"[Scaling] Increasing instances to {num_instances_base}")
reinit_lattice(num_instances_base)
# ---------- Main ----------
def main():
glutInit(sys.argv)
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE)
glutInitWindowSize(1280,720)
glutCreateWindow(b"HDGL Progressive GPU Lattice + PHI Clock")
init_gl()
glutDisplayFunc(display)
glutIdleFunc(idle)
glutMainLoop()
if __name__=="__main__":
main()
AUTO-RAMP TO THAT SWEET SPOT. SWEETNESS.
import sys, time
import numpy as np
from OpenGL.GL import *
from OpenGL.GLUT import *
from OpenGL.GL.shaders import compileProgram, compileShader
# Optional GPU utilities
try:
import GPUtil
except ImportError:
GPUtil = None
print("[GPU] GPUtil not installed. Using safe fallback for VRAM.")
# ---------- Shaders ----------
VERTEX_SRC = """
#version 330
layout(location = 0) in vec2 pos;
out vec2 texCoord;
void main(){
texCoord = (pos + 1.0)*0.5;
gl_Position = vec4(pos,0,1);
}
"""
FRAGMENT_SRC = """
#version 330
in vec2 texCoord;
out vec4 fragColor;
uniform sampler2D latticeTex;
uniform float cycle;
uniform float omegaTime;
uniform float phiPowers[72];
uniform float threshold;
uniform int latticeHeight;
uniform int yOffset;
float hdgl_slot(float val, float r_dim, float omega, int x, int y){
float resonance = (x % 4 == 0 ? 0.1 * sin(cycle*0.05 + float(y)) : 0.0);
float wave = (x % 3 == 0 ? 0.3 : (x % 3 == 1 ? 0.0 : -0.3));
float omega_inst = phiPowers[y % 72];
float rec = r_dim*val*0.5 + 0.25*sin(cycle*r_dim + float(x));
float new_val = val + omega_inst + resonance + wave + rec + omega*0.05;
return new_val > threshold ? 1.0 : 0.0;
}
void main(){
int x = int(texCoord.x * 32.0);
int y = int(texCoord.y * float(latticeHeight)) + yOffset;
float val = texelFetch(latticeTex, ivec2(x,y - yOffset), 0).r;
float r_dim = 0.3 + 0.01*float(y);
float new_val = hdgl_slot(val, r_dim, sin(omegaTime), x, y);
fragColor = vec4(new_val, sin(omegaTime), 0.0, 1.0);
}
"""
# ---------- Globals ----------
window = None
shader = None
vao = None
textures = []
fbos = []
current = 0
cycle = 0.0
omega_time = 0.0
# ---------- Lattice params ----------
lattice_width = 32
num_instances_base = 50_000
scale_interval = 2.0
sub_tile_height = 256
max_tex_height = 2048
threshold = np.sqrt(1.6180339887)
phi = 1.6180339887
phi_powers = np.array([1.0 / pow(phi, 7*(i+1)) for i in range(72)], dtype=np.float32)
tile_heights = []
tile_count = 0
last_scale_time = time.time()
frame_times = []
# ---------- GPU Detection with fallback ----------
def compute_max_instances(lattice_width, bytes_per_pixel=16):
if GPUtil:
gpus = GPUtil.getGPUs()
if gpus:
gpu = gpus[0]
free_vram = gpu.memoryFree * 1024**2
instance_bytes = lattice_width * 4 * 4
max_instances = int(free_vram * 0.9 / instance_bytes)
print(f"[GPU] Free VRAM: {gpu.memoryFree} MB, Max safe instances: {max_instances}")
return max_instances
print("[GPU] No GPU detected or GPUtil failed. Using safe fallback for max instances.")
return 50_000
num_instances_max = compute_max_instances(lattice_width)
# ---------- OpenGL Init ----------
def init_gl():
global shader, vao, textures, fbos, tile_heights, tile_count
shader = compileProgram(compileShader(VERTEX_SRC, GL_VERTEX_SHADER),
compileShader(FRAGMENT_SRC, GL_FRAGMENT_SHADER))
verts = np.array([-1,-1,1,-1,-1,1,1,-1,1,1,-1,1], dtype=np.float32)
vao = glGenVertexArrays(1)
glBindVertexArray(vao)
vbo = glGenBuffers(1)
glBindBuffer(GL_ARRAY_BUFFER, vbo)
glBufferData(GL_ARRAY_BUFFER, verts.nbytes, verts, GL_STATIC_DRAW)
glVertexAttribPointer(0,2,GL_FLOAT,GL_FALSE,0,None)
glEnableVertexAttribArray(0)
reinit_lattice(num_instances_base)
# ---------- Lattice reinit ----------
def reinit_lattice(new_num_instances):
global textures, fbos, tile_heights, tile_count
for tex_pair in textures:
glDeleteTextures(tex_pair)
for fbo_pair in fbos:
glDeleteFramebuffers(2, fbo_pair)
textures.clear()
fbos.clear()
tile_count = (new_num_instances + max_tex_height - 1) // max_tex_height
tile_heights[:] = [min(max_tex_height, new_num_instances - i*max_tex_height) for i in range(tile_count)]
for t, th in enumerate(tile_heights):
tex_pair = glGenTextures(2)
fbo_pair = glGenFramebuffers(2)
for i in range(2):
glBindTexture(GL_TEXTURE_2D, tex_pair[i])
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, lattice_width, th, 0, GL_RGBA, GL_FLOAT, None)
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST)
glBindFramebuffer(GL_FRAMEBUFFER, fbo_pair[i])
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex_pair[i],0)
textures.append(tex_pair)
fbos.append(fbo_pair)
for start in range(0, th, sub_tile_height):
end = min(start + sub_tile_height, th)
init_chunk = np.zeros((end-start, lattice_width,4), dtype=np.float32)
glBindTexture(GL_TEXTURE_2D, tex_pair[0])
glTexSubImage2D(GL_TEXTURE_2D,0,0,start,lattice_width,end-start,GL_RGBA,GL_FLOAT,init_chunk)
glBindFramebuffer(GL_FRAMEBUFFER,0)
# ---------- Display ----------
def display():
global cycle, omega_time, current
next_idx = 1-current
for t, th in enumerate(tile_heights):
for y_start in range(0, th, sub_tile_height):
h = min(sub_tile_height, th - y_start)
glBindFramebuffer(GL_FRAMEBUFFER, fbos[t][next_idx])
glViewport(0,0,lattice_width,h)
glUseProgram(shader)
glUniform1i(glGetUniformLocation(shader,"latticeTex"),0)
glUniform1f(glGetUniformLocation(shader,"cycle"),cycle)
glUniform1f(glGetUniformLocation(shader,"omegaTime"),omega_time)
glUniform1fv(glGetUniformLocation(shader,"phiPowers"),72,phi_powers)
glUniform1f(glGetUniformLocation(shader,"threshold"),threshold)
glUniform1i(glGetUniformLocation(shader,"latticeHeight"), h)
glUniform1i(glGetUniformLocation(shader,"yOffset"), y_start)
glActiveTexture(GL_TEXTURE0)
glBindTexture(GL_TEXTURE_2D, textures[t][current])
glBindVertexArray(vao)
glDrawArrays(GL_TRIANGLES,0,6)
glBindFramebuffer(GL_FRAMEBUFFER,0)
glViewport(0,0,1280,720)
for t, th in enumerate(tile_heights):
glBindTexture(GL_TEXTURE_2D, textures[t][next_idx])
glDrawArrays(GL_TRIANGLES,0,6)
glutSwapBuffers()
start = time.time()
cycle += 1
omega_time += 0.05
current = next_idx
frame_times.append(time.time()-start)
if len(frame_times) > 100: frame_times.pop(0)
# ---------- Idle ----------
def idle():
global num_instances_base, last_scale_time
glutPostRedisplay()
now = time.time()
if now - last_scale_time > scale_interval and num_instances_base < num_instances_max:
gpu_headroom = 1.0
if GPUtil:
gpus = GPUtil.getGPUs()
if gpus:
gpu_headroom = max(0.1, 1.0 - gpus[0].load)
step = int(max(1_000, (1.0 - num_instances_base/num_instances_max) * 50_000 * gpu_headroom))
num_instances_base += step
if num_instances_base > num_instances_max:
num_instances_base = num_instances_max
last_scale_time = now
print(f"[Scaling] Instances: {num_instances_base}, Step: {step}, GPU headroom: {gpu_headroom:.2f}")
reinit_lattice(num_instances_base)
if frame_times:
avg = sum(frame_times)/len(frame_times)
print(f"[Perf] Avg frame: {avg*1000:.2f} ms")
# ---------- Main ----------
def main():
glutInit(sys.argv)
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE)
glutInitWindowSize(1280,720)
glutCreateWindow(b"HDGL Full GPU Saturation + Ω Clock")
init_gl()
glutDisplayFunc(display)
glutIdleFunc(idle)
glutMainLoop()
if __name__=="__main__":
main()