<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/index-a-slice-challenge-impossible-zgb4oqwka" -->

---
title: Index a slice challenge... IMPOSSIBLE | daily.dev
description: A live coding session exploring a bug in the Zig SPIR-V code generation backend. The developer is working on a Wayland compositor that renders SVGs on the GPU...
canonical: https://daily.dev/posts/index-a-slice-challenge-impossible-zgb4oqwka
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Index a slice challenge... IMPOSSIBLE | daily.dev
og:description: A live coding session exploring a bug in the Zig SPIR-V code generation backend. The developer is working on a Wayland compositor that renders SVGs on the GPU...
og:url: https://daily.dev/posts/index-a-slice-challenge-impossible-zgb4oqwka
og:image: https://api.daily.dev/og/posts/Zgb4OQwkA.png
og:image:alt: Index a slice challenge... IMPOSSIBLE
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.

# Index a slice challenge... IMPOSSIBLE

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

## Summary

A live coding session exploring a bug in the Zig SPIR-V code generation backend. The developer is working on a Wayland compositor that renders SVGs on the GPU using OpenGL with SPIR-V shaders. The core problem: SPIR-V's function storage class doesn't support runtime pointer arithmetic, so slice indexing generates invalid SPIR-V. The session investigates two potential fixes — resolving slices at compile time in semantic analysis (sema), or tracking array-to-pointer operations at the codegen level. The developer digs through Zig's compiler internals (AIR, intern pool, sema.zig) to understand how slices and arrays differ in the generated IR, ultimately leaning toward a sema-level fix that converts compile-time-known slice accesses into array accesses.

## Full article

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

## Questions this post answers

### Why does indexing a Zig slice fail when targeting SPIR-V but indexing an array works fine?

SPIR-V does not allow runtime pointer indexing into function-space storage the way normal pointers work; values there are references rather than real pointers you can offset. Arrays can be indexed because SPIR-V provides a dedicated array-access mechanism, but slices, which are represented as a pointer plus length, cannot be turned into an arbitrary offsettable pointer, so slice indexing generates invalid SPIR-V while equivalent array indexing generates valid code.

_Developers hitting GPU backend limits with Zig can compare notes on SPIR-V codegen quirks via daily.dev._

### How can I check if generated SPIR-V bytecode is valid?

Khronos, the organization behind the SPIR-V specification, provides a validation tool called spirv-val (spv val) that checks whether generated SPIR-V binaries conform to the spec, such as flagging invalid attempts to extract a raw pointer to a value from an array in disallowed storage classes. Disassembly tools like spirv-dis can also be used alongside it to inspect the actual generated instructions.

_Anyone debugging GPU shader compilation can find SPIR-V tooling tips like this through daily.dev._

## Similar posts on daily.dev

- [ZigCool](https://daily.dev/posts/zigcool-w6vkx2tr6) · Hacker News · 4 upvotes · 0 comments

---

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

[View this post on daily.dev](https://daily.dev/posts/index-a-slice-challenge-impossible-zgb4oqwka)

```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":"Index a slice challenge... IMPOSSIBLE","url":"https://daily.dev/posts/index-a-slice-challenge-impossible-zgb4oqwka","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/index-a-slice-challenge-impossible-zgb4oqwka"},"datePublished":"2026-07-14T23:20:28.476Z","dateModified":"2026-10-14T02:32:42.239Z","description":"A live coding session exploring a bug in the Zig SPIR-V code generation backend. The developer is working on a Wayland compositor that renders SVGs on the GPU...","image":"https://i.ytimg.com/vi/0kftNxGU51g/sddefault.jpg","thumbnailUrl":"https://i.ytimg.com/vi/0kftNxGU51g/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/index-a-slice-challenge-impossible-zgb4oqwka","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":6},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"gpu,opengl,zig","timeRequired":"PT138M","video":{"@type":"VideoObject","name":"Index a slice challenge... IMPOSSIBLE","description":"A live coding session exploring a bug in the Zig SPIR-V code generation backend. The developer is working on a Wayland compositor that renders SVGs on the GPU...","thumbnailUrl":"https://i.ytimg.com/vi/0kftNxGU51g/sddefault.jpg","uploadDate":"2026-07-14T23:20:28.476Z","duration":"PT138M","url":"https://api.daily.dev/r/Zgb4OQwkA","embedUrl":"https://www.youtube.com/embed/0kftNxGU51g"}}
{"@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":"Index a slice challenge... IMPOSSIBLE"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/index-a-slice-challenge-impossible-zgb4oqwka#faq","mainEntity":[{"@type":"Question","name":"Why does indexing a Zig slice fail when targeting SPIR-V but indexing an array works fine?","acceptedAnswer":{"@type":"Answer","text":"SPIR-V does not allow runtime pointer indexing into function-space storage the way normal pointers work; values there are references rather than real pointers you can offset. Arrays can be indexed because SPIR-V provides a dedicated array-access mechanism, but slices, which are represented as a pointer plus length, cannot be turned into an arbitrary offsettable pointer, so slice indexing generates invalid SPIR-V while equivalent array indexing generates valid code. Developers hitting GPU backend limits with Zig can compare notes on SPIR-V codegen quirks via daily.dev."}},{"@type":"Question","name":"How can I check if generated SPIR-V bytecode is valid?","acceptedAnswer":{"@type":"Answer","text":"Khronos, the organization behind the SPIR-V specification, provides a validation tool called spirv-val (spv val) that checks whether generated SPIR-V binaries conform to the spec, such as flagging invalid attempts to extract a raw pointer to a value from an array in disallowed storage classes. Disassembly tools like spirv-dis can also be used alongside it to inspect the actual generated instructions. Anyone debugging GPU shader compilation can find SPIR-V tooling tips like this through daily.dev."}}]}
```

