Skip to content
This repository was archived by the owner on Dec 1, 2025. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
ba5713c
Shadercross WIP
Gota7 Aug 23, 2025
2ed71cc
Finish Wrapping SDL Shadercross
Gota7 Aug 24, 2025
a1605fc
GPU Examples WIP
Gota7 Aug 31, 2025
da9b9ef
Clear Screen GPU Example
Gota7 Aug 31, 2025
0077141
Add Multi Window Example
Gota7 Aug 31, 2025
2742eae
Basic Triangle WIP
Gota7 Sep 1, 2025
201c33f
Temporarily Remove Reflect Call
Gota7 Sep 1, 2025
7bf31f5
Zig & GLSL Shaders Work
Gota7 Sep 2, 2025
24ae192
Remove I64 From SPIRV
Gota7 Sep 3, 2025
005f119
Finish Basic Triangle
Gota7 Sep 5, 2025
0de0ac8
Finish Basic Vertex Buffer Example
Gota7 Sep 5, 2025
fbb2d57
Finish Cull Mode Example
Gota7 Sep 5, 2025
364ff21
Add GPU Examples README
Gota7 Sep 5, 2025
9575231
Basic Stencil Example Finished
Gota7 Sep 6, 2025
b09e19e
Add Instanced Index Example
Gota7 Sep 6, 2025
2ccde41
Add Textured Quad Example
Gota7 Sep 6, 2025
32001bb
Add Animated Textured Quad Example
Gota7 Sep 7, 2025
59448d5
Add Clear 3d Slice Example
Gota7 Sep 7, 2025
4f5e09b
Add Basic Compute Example
Gota7 Sep 7, 2025
77b86aa
Compute Uniform WIP
Gota7 Sep 9, 2025
e2bab84
Compute Uniforms Example
Gota7 Sep 10, 2025
3cdb8b6
Tone Mapping WIP
Gota7 Sep 24, 2025
9a2152d
Draw Indirect Example
Gota7 Sep 24, 2025
af3cf84
Add Compute Sampler Example
Gota7 Sep 24, 2025
d80f848
Add Copy And Readback Example
Gota7 Sep 27, 2025
a65286d
Add Copy Consistency Example
Gota7 Sep 27, 2025
7e64b93
Add Texture 2d Array Example
Gota7 Sep 27, 2025
1f6dd1f
Add Triangle MSAA Example
Gota7 Sep 27, 2025
657cdf0
Add Cubemap Example
Gota7 Sep 28, 2025
165ae35
Add Window Resize Example
Gota7 Sep 28, 2025
404a2e2
Add Blit 2d Array & Blit Cube Examples
Gota7 Sep 28, 2025
10ef9dd
Add Blit Mirror Example
Gota7 Sep 28, 2025
bc3e945
Add Generate Mipmaps Example
Gota7 Sep 28, 2025
1f66e1d
Add Latency Example
Gota7 Sep 29, 2025
dd47ff8
Add Depth Sampler Example
Gota7 Oct 4, 2025
250ce72
Zig Compute Kernels Work
Gota7 Oct 4, 2025
ac9868b
Compute Sprite Batch Example WIP
Gota7 Oct 5, 2025
7a17a86
Make Zig GPU Inline Assembly Common
Gota7 Oct 15, 2025
54fa5b3
GPU Template WIP
Gota7 Oct 23, 2025
fe302f7
Template WIP
Gota7 Oct 25, 2025
cb1720a
GPU Progress
Gota7 Oct 26, 2025
37fb037
GPU Reflection Progress
Gota7 Oct 26, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ jobs:
run: zig build examples
- name: Build Examples Windows
run: zig build examples -Dtarget=x86_64-windows
gpu_examples:
name: Build GPU Examples
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: mlugg/setup-zig@v2
with:
version: ${{ env.ZIG_VERSION }}
- name: Build GPU Examples Linux
run: cd gpu_examples && zig build examples
- name: Build GPU Examples Windows
run: cd gpu_examples && zig build examples -Dtarget=x86_64-windows
template:
name: Build Template
runs-on: ubuntu-latest
Expand Down
57 changes: 57 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ pub fn build(b: *std.Build) !void {
extension_options.addOption(bool, "image", ext_image);
const ext_net = b.option(bool, "ext_net", "Enable SDL_net extension") orelse false;
extension_options.addOption(bool, "net", ext_net);
const ext_shadercross = b.option(bool, "ext_shadercross", "Enable SDL_shadercross extension") orelse false;
extension_options.addOption(bool, "shadercross", ext_shadercross);
const ext_ttf = b.option(bool, "ext_ttf", "Enable SDL_ttf extension") orelse false;
extension_options.addOption(bool, "ttf", ext_ttf);

Expand All @@ -131,10 +133,12 @@ pub fn build(b: *std.Build) !void {
\\{s}
\\{s}
\\{s}
\\{s}
, .{
if (!sdl3_main) "#define SDL_MAIN_NOIMPL\n" else "",
if (ext_image) "#include <SDL3_image/SDL_image.h>\n" else "",
if (ext_net) "#include <SDL3_net/SDL_net.h>\n" else "",
if (ext_shadercross) "#include <SDL3_shadercross/SDL_shadercross.h>\n" else "",
if (ext_ttf) "#include <SDL3_ttf/SDL_ttf.h>\n#include <SDL3_ttf/SDL_textengine.h>\n" else "",
});

Expand Down Expand Up @@ -192,6 +196,9 @@ pub fn build(b: *std.Build) !void {
.target = target,
}, sdl_system_include_path);
}
if (ext_shadercross) {
setupSdlShadercross(b, sdl3, translate_c, sdl_dep_lib, c_sdl_preferred_linkage, cfg);
}

_ = setupDocs(b, sdl3);
_ = setupTest(b, cfg, extension_options, options, c_module);
Expand All @@ -200,6 +207,56 @@ pub fn build(b: *std.Build) !void {
_ = try runExample(b, sdl3, cfg, example_options);
}

// Most of this is copied from https://github.com/Beyley/SDL_shadercross_zig/blob/master/build.zig.
pub fn setupSdlShadercross(
b: *std.Build,
sdl3: *std.Build.Module,
translate_c: *std.Build.Step.TranslateC,
sdl_dep_lib: *std.Build.Step.Compile,
linkage: std.builtin.LinkMode,
cfg: Config,
) void {
const upstream = b.lazyDependency("sdl_shadercross", .{}) orelse return;

const target = cfg.target;
const lib = b.addLibrary(.{
.name = "SDL3_shadercross",
.version = .{ .major = 3, .minor = 0, .patch = 0 },
.linkage = linkage,
.root_module = b.createModule(.{
.target = target,
.optimize = cfg.optimize,
.link_libc = true,
}),
});
lib.root_module.linkLibrary(sdl_dep_lib);

translate_c.addIncludePath(upstream.path("include"));
lib.root_module.addIncludePath(upstream.path("include"));
lib.root_module.addIncludePath(upstream.path("src"));

lib.root_module.addCSourceFiles(.{
.root = upstream.path("src"),
.files = &.{
"SDL_shadercross.c",
},
});

lib.installHeadersDirectory(upstream.path("include"), "", .{});

const spirv_headers = b.dependency("spirv_headers", .{});
const spirv_cross = b.dependency("spirv_cross", .{
.target = target,
.optimize = .ReleaseFast, // There is a C bug in spirv-cross upstream! Ignore undefined behavior for now.
.spv_cross_reflect = true,
.spv_cross_cpp = false,
});
lib.linkLibrary(spirv_cross.artifact("spirv-cross-c"));
lib.addIncludePath(spirv_headers.path("include/spirv/1.2/"));

sdl3.linkLibrary(lib);
}

pub fn setupDocs(b: *std.Build, sdl3: *std.Build.Module) *std.Build.Step {
const sdl3_lib = b.addLibrary(.{
.root_module = sdl3,
Expand Down
24 changes: 18 additions & 6 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
.version = "0.1.5",
.minimum_zig_version = "0.15.1",
.dependencies = .{
.freetype = .{
.url = "git+https://github.com/allyourcodebase/freetype.git#9d847affbd224cf6a7303ad6d98715e3675ef78c",
.hash = "freetype-2.13.3-C3-WdeyJAAD9z8BeYYQ8N3gNlPI9NvHRxg5039S5vhz7",
},
.harfbuzz = .{
.url = "git+https://github.com/allyourcodebase/harfbuzz#6bb522d22cee0ce1d1446bd59fa5b0417f25303e",
.hash = "harfbuzz-8.5.0-Ip1VAqCZAADRh-K2AVujG0N3VAal-AKwkZrvlYOaloyB",
},
.sdl = .{
.url = "git+https://github.com/castholm/SDL.git?ref=v0.3.1%2B3.2.24#1d4b8dcc03bd216712b55318b4ad2402b5511490",
.hash = "sdl-0.3.1+3.2.24-7uIn9L9AfwFQf90JcTh3Slw__ZA8SEomk6fQI9F8ItY0",
Expand All @@ -17,18 +25,22 @@
.hash = "N-V-__8AAK74BwCyuisw6wdXWDDg8sXuHJd_tPk1VKxLTUBK",
.lazy = true,
},
.sdl_shadercross = .{
.url = "git+https://github.com/libsdl-org/SDL_shadercross#392d12afc1ef084c5cd656307180027399b7a54e",
.hash = "N-V-__8AAH9GBgCySY9rt5VJj3A-OGl0Z05BPZ9PgS5Pt1zm",
},
.sdl_ttf = .{
.url = "git+https://github.com/libsdl-org/SDL_ttf#release-3.2.2",
.hash = "N-V-__8AAF2JgAA_Y5Qzm3b226N8y7ivM-qFVpCo9NkbfO8Y",
.lazy = true,
},
.harfbuzz = .{
.url = "git+https://github.com/allyourcodebase/harfbuzz#6bb522d22cee0ce1d1446bd59fa5b0417f25303e",
.hash = "harfbuzz-8.5.0-Ip1VAqCZAADRh-K2AVujG0N3VAal-AKwkZrvlYOaloyB",
.spirv_cross = .{
.url = "git+https://github.com/Gota7/spirv_cross-zig#75cfd40f81f63a678d70d7e3de021edd944eb553",
.hash = "spirv_cross-0.0.0-bzNVZC4YAADQdsxyfpxC9Iw8xxietH7xoEQxbHY43bmo",
},
.freetype = .{
.url = "git+https://github.com/allyourcodebase/freetype.git#9d847affbd224cf6a7303ad6d98715e3675ef78c",
.hash = "freetype-2.13.3-C3-WdeyJAAD9z8BeYYQ8N3gNlPI9NvHRxg5039S5vhz7",
.spirv_headers = .{
.url = "git+https://github.com/KhronosGroup/SPIRV-Headers#1bfd27101e4578d0284061bdf8f09fb4755c7c2d",
.hash = "N-V-__8AADq1MQCCoUh-qOkYXGvqKFClPzdiedYrsGFYzTV9",
},
},
.paths = .{
Expand Down
40 changes: 40 additions & 0 deletions gpu_examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# SDL3 GPU Examples
Zig examples of using SDL3's GPU subsystem along with shadercross to run all provided shader formats on the target. SDL shadercross bridges the platform shader format gap such that the shaders "just work" everywhere.

## Build System
You can use `zig build examples` to build all of the example executables, and `zig build run -Dexample=example-zig-file-here` (Ex: `-Dexample=basic-triangle`) to run a particular example. You may also specify the shader format to use with `-Dshader_format`. Note that the default format is `zig`. You are free to use the build system as a reference for building your own project's, taking the shader format you like most.

Zig shaders use `spirv-opt` on the system to optimize the result of SPIR-V as zig does not optimize SPIR-V iirc? Also, you may not compile zig shaders on a Windows system at the moment [due to this issue](https://github.com/ziglang/zig/issues/23883). There is nothing stopping you from cross-compiling for a Windows system, but doing dev from a Windows environment would be unfun.

GLSL shaders use `glslang` on the system in order to compile GLSL into SPIR-V binaries.

HLSL shaders are compiled at runtime using SDL shadercross. Note that nothing is stopping you from pre-compiling HLSL into SPIR-V using `glslang` if runtime flexibility is not needed.

## Shader Formats
Each shader format has its own ups and downs.

### Zig
Pros:
* It's zig
* Tooling already installed with the compiler

Cons:
* Inline assembly required for more complex tasks
* External tool required at compile time to maximize performance
* No runtime recompilation support

### Compiled GLSL/HLSL
Pros:
* Normal shading language

Cons:
* Requires `glslang` or other shader compiler at build time
* No runtime recompilation support

### Runtime HLSL
Pros:
* Runtime recompilation support
* Normal shading language

Cons:
* Requires additional less-flexible dependencies for SDL shadercross
Loading
Loading