Broken shader example in the guide
edusporto opened this issue · comments
Reproducing the behavior
The PR HigherOrderCO/HVM#379 broke one of the examples in the guide, namely:
Lines 748 to 772 in c3b1a36
It's also one of Bend's automated tests:
Bend/tests/golden_tests/run_file/guide_shader_dummy.bend
Lines 1 to 23 in c3b1a36
This is because demo_shader
is now marked as unsafe since it contains a DUP (it duplicates i
), and render
tries to duplicate it by running it in every step of its recursion.
We could fix this by inlining demo_shader
.
System Settings
MacBook Air M2
Additional context
No response
I'm not a fan of this solution, but it does work:
# given a shader, returns a square image
def render(depth):
bend d = 0, i = 0:
when d < depth:
# create more pixels
pixel = (fork(d+1, i*2+0), fork(d+1, i*2+1))
else:
width = depth / 2
# calculate the color of the pixel
bend i = i % width, y = i / width:
# for this demo, it just busy loops
when i < 10:
color = fork(i + 1, y)
else:
color = 0x000001
pixel = color
return pixel
# renders a 256x256 image using demo_shader
def main:
return render(5)
Any other ideas? @developedby @imaqtkatt
you can just
# given a shader, returns a square image
def render(depth):
bend d = 0, i = 0:
when d < depth:
color = (fork(d+1, i*2+0), fork(d+1, i*2+1))
else:
width = depth / 2
color = demo_shader(i % width, i / width)
return color
# given a position, returns a color
# for this demo, it just busy loops
def demo_shader(x, y):
bend i = 0:
when i < 100000:
color = fork(i + 1)
else:
color = 0x000001
return color
Oh 🤦 that's much easier