<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/either-i-m-stupid-or-it-s-broken--ary7wkkqt" -->

---
title: Either I'm stupid or it's broken... | daily.dev
description: A live-coding stream follows the process of GPU-accelerating a hand-written SVG renderer originally built for a Wayland compositor's taskbar icons, using Zig's...
canonical: https://daily.dev/posts/either-i-m-stupid-or-it-s-broken--ary7wkkqt
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Either I'm stupid or it's broken... | daily.dev
og:description: A live-coding stream follows the process of GPU-accelerating a hand-written SVG renderer originally built for a Wayland compositor's taskbar icons, using Zig's...
og:url: https://daily.dev/posts/either-i-m-stupid-or-it-s-broken--ary7wkkqt
og:image: https://api.daily.dev/og/posts/ARY7wkKqt.png
og:image:alt: Either I'm stupid or it's broken...
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Either I'm stupid or it's broken...

**[sphaerophoria](https://daily.dev/sources/sphaerophoria)** · 126 min read · 2 upvotes · 0 comments

## Summary

A live-coding stream follows the process of GPU-accelerating a hand-written SVG renderer originally built for a Wayland compositor's taskbar icons, using Zig's work-in-progress SPIR-V backend. The session works through porting CPU scanline-crossing logic to the GPU, hitting a wall because SPIR-V's logical pointers don't support Zig's union types the way CPU code does. After weighing options (avoiding unions, forcing physical pointers, manual byte packing, or hoping the compiler resolves struct-like unions), the streamer settles on manually packing segment data into a fixed-size float array struct. The rest of the stream is spent debugging a two-pass compute shader pipeline (winding number calculation), chasing bugs from wrong buffer offsets, missing dispatch calls, insufficient memory barriers, and struct layout mismatches between CPU and GPU code, ending mid-debug with inconsistent output data still unexplained.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.youtube.com/watch?v=MALaovMBnh0>

## Questions this post answers

### Why doesn't Zig's SPIR-V backend support unions?

SPIR-V uses logical pointers rather than real physical memory addresses, so there is no underlying memory to cast when implementing a union the way you would in C. Since the GPU execution model just links variable references together as labels instead of guaranteeing a shared memory layout, a bucket-of-storage-plus-bitcast approach used for unions on CPU cannot work, forcing manual struct-based packing instead.

_Developers hitting GPU codegen limitations in Zig can find similar low-level debugging accounts on daily.dev._

### How can I manually replace a union with a struct in Zig when targeting SPIR-V for GPU compute?

Define a struct containing an enum tag for the variant kind plus a fixed-size float array large enough to hold the largest variant's data, then write separate init and accessor functions for each variant that read and write specific offsets into that array. For a segment type storing lines, quadratic beziers, cubic beziers, and arcs, eight 32-bit floats of storage was enough to cover every case.

_Anyone porting CPU data structures to GPU shaders can track these packing workarounds on daily.dev._

### Why would data written to a GPU storage buffer from a compute shader appear missing or zeroed when read back on the CPU?

One cause is a struct field declared as a byte array (U8) on the CPU side getting code-generated by the SPIR-V backend as an array of U32s instead, so writes end up masked and aligned to 4-byte boundaries with an ampersand-255 mask, which silently corrupts or zeros out adjacent bytes near the end of the buffer rather than writing the intended packed bytes.

_Developers chasing GPU buffer readback bugs can follow real debugging sessions like this on daily.dev._

## Similar posts on daily.dev

- [Graphics Programming weekly - Issue 461 - November 1st, 2026](https://daily.dev/posts/graphics-programming-weekly---issue-461---november-1st-2026-kwlnglixx) · Jendrik Illner · 0 upvotes · 0 comments

---

Tags: [#gpu](https://daily.dev/tags/gpu), [#svg](https://daily.dev/tags/svg), [#zig](https://daily.dev/tags/zig)

[View this post on daily.dev](https://daily.dev/posts/either-i-m-stupid-or-it-s-broken--ary7wkkqt)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Either I'm stupid or it's broken...","url":"https://daily.dev/posts/either-i-m-stupid-or-it-s-broken--ary7wkkqt","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/either-i-m-stupid-or-it-s-broken--ary7wkkqt"},"datePublished":"2026-08-29T00:14:19.467Z","dateModified":"2026-10-15T02:22:47.657Z","description":"A live-coding stream follows the process of GPU-accelerating a hand-written SVG renderer originally built for a Wayland compositor's taskbar icons, using Zig's...","image":"https://i.ytimg.com/vi/MALaovMBnh0/sddefault.jpg","thumbnailUrl":"https://i.ytimg.com/vi/MALaovMBnh0/sddefault.jpg","isAccessibleForFree":true,"articleSection":"sphaerophoria","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"sphaerophoria","logo":"https://media.daily.dev/image/upload/s--dgPUg2T7--/f_auto/v1728806109/logos/sphaerophoria","url":"https://daily.dev/sources/sphaerophoria"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/either-i-m-stupid-or-it-s-broken--ary7wkkqt","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":2},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"gpu,svg,zig","timeRequired":"PT126M","video":{"@type":"VideoObject","name":"Either I'm stupid or it's broken...","description":"A live-coding stream follows the process of GPU-accelerating a hand-written SVG renderer originally built for a Wayland compositor's taskbar icons, using Zig's...","thumbnailUrl":"https://i.ytimg.com/vi/MALaovMBnh0/sddefault.jpg","uploadDate":"2026-08-29T00:14:19.467Z","duration":"PT126M","url":"https://api.daily.dev/r/ARY7wkKqt","embedUrl":"https://www.youtube.com/embed/MALaovMBnh0"}}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"sphaerophoria","item":"https://daily.dev/sources/sphaerophoria"},{"@type":"ListItem","position":3,"name":"Either I'm stupid or it's broken..."}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/either-i-m-stupid-or-it-s-broken--ary7wkkqt#faq","mainEntity":[{"@type":"Question","name":"Why doesn't Zig's SPIR-V backend support unions?","acceptedAnswer":{"@type":"Answer","text":"SPIR-V uses logical pointers rather than real physical memory addresses, so there is no underlying memory to cast when implementing a union the way you would in C. Since the GPU execution model just links variable references together as labels instead of guaranteeing a shared memory layout, a bucket-of-storage-plus-bitcast approach used for unions on CPU cannot work, forcing manual struct-based packing instead. Developers hitting GPU codegen limitations in Zig can find similar low-level debugging accounts on daily.dev."}},{"@type":"Question","name":"How can I manually replace a union with a struct in Zig when targeting SPIR-V for GPU compute?","acceptedAnswer":{"@type":"Answer","text":"Define a struct containing an enum tag for the variant kind plus a fixed-size float array large enough to hold the largest variant's data, then write separate init and accessor functions for each variant that read and write specific offsets into that array. For a segment type storing lines, quadratic beziers, cubic beziers, and arcs, eight 32-bit floats of storage was enough to cover every case. Anyone porting CPU data structures to GPU shaders can track these packing workarounds on daily.dev."}},{"@type":"Question","name":"Why would data written to a GPU storage buffer from a compute shader appear missing or zeroed when read back on the CPU?","acceptedAnswer":{"@type":"Answer","text":"One cause is a struct field declared as a byte array (U8) on the CPU side getting code-generated by the SPIR-V backend as an array of U32s instead, so writes end up masked and aligned to 4-byte boundaries with an ampersand-255 mask, which silently corrupts or zeros out adjacent bytes near the end of the buffer rather than writing the intended packed bytes. Developers chasing GPU buffer readback bugs can follow real debugging sessions like this on daily.dev."}}]}
```

