Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
2992db0
refactor(api): update api to better suit compute applications
JohnSmoit Jul 23, 2025
060ca1a
chore(helpers): make helpers its own module to be imported by each sa…
JohnSmoit Jul 23, 2025
21b817e
feat(compute): begin implementing a compute-shader demonstration via …
JohnSmoit Jul 23, 2025
dcb1274
fix(graphics_pipeline): fixed issue when specifying no vertex inputs
JohnSmoit Jul 25, 2025
4e9d465
chore(framebuffer): update framebuffer initialization to be parametar…
JohnSmoit Jul 25, 2025
a4514e4
refactor(shader): refactor shader modules to use updated rshc with sh…
JohnSmoit Jul 25, 2025
0105ada
Revert "chore(framebuffer): update framebuffer initialization to be p…
JohnSmoit Jul 25, 2025
02e606e
chore(framebuffer): update framebuffer initailization to be parameter…
JohnSmoit Jul 25, 2025
04a04f5
feat(slime): complete render quad's graphics pipeline
JohnSmoit Jul 25, 2025
571b21d
feat(api): tweaks to api to streamline vulkan object initialization
JohnSmoit Jul 26, 2025
1a7a15c
feat(sample): compute sample now displays a fullscreen quad (will be …
JohnSmoit Jul 26, 2025
4e705c3
feat(sample): added uniforms to the slime sample
JohnSmoit Jul 26, 2025
0ac2ce5
feat(sample): implement hello compute with storage image reading/writing
JohnSmoit Jul 29, 2025
9d579b3
feat(vulkan): update images and buffers to support storage usage
JohnSmoit Jul 29, 2025
19f5b2f
feat(misc): update math types and utilities to support an additional …
JohnSmoit Jul 29, 2025
ed17fbb
feat(sample): slime sample now has complete compute initialization
JohnSmoit Aug 1, 2025
af499dc
feat(vulkan): updated layout transitions and switched from EnumMap to…
JohnSmoit Aug 1, 2025
c7a363b
feat(vulkan): update various types to handle multiple use images acro…
JohnSmoit Aug 3, 2025
32360e7
feat(sample): added a working compute shader dispatch test cycle
JohnSmoit Aug 3, 2025
4110112
feat(sample): compute-generated image now dispays on the window surface
JohnSmoit Aug 6, 2025
d044542
feat(vulkan): updated sampler descriptor to take actual vk.Sampler ha…
JohnSmoit Aug 6, 2025
ee97baa
refactor 'slime' sample to 'basic compute drawing'
JohnSmoit Aug 6, 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
13 changes: 12 additions & 1 deletion build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const SampleEntry = struct {
};
var sample_files = [_]SampleEntry{
.{ .name = "basic_planes", .path = "basic_planes.zig" },
.{ .name = "basic_compute", .path = "basic_compute.zig" },
.{ .name = "compute_drawing", .path = "compute_drawing/main.zig" },
.{ .name = "test_sample", .path = "test_sample.zig" },
};

Expand All @@ -103,6 +103,16 @@ fn populateSampleModules(
deps: Dependencies,
opts: BuildOpts,
) void {
const sample_commons = b.createModule(.{
.root_source_file = b.path("samples/common/helpers.zig"),
.optimize = opts.optimize,
.target = opts.target,
});

sample_commons.addImport("ray", lib_mod);
sample_commons.addImport("glfw", deps.glfw);
sample_commons.addImport("vulkan", deps.vulkan);

for (&sample_files) |*f| {
const sample_mod = b.createModule(.{
.root_source_file = b.path(b.pathJoin(&.{
Expand All @@ -116,6 +126,7 @@ fn populateSampleModules(
sample_mod.addImport("ray", lib_mod);
sample_mod.addImport("glfw", deps.glfw);
sample_mod.addImport("vulkan", deps.vulkan);
sample_mod.addImport("helpers", sample_commons);

const sample_exe = b.addExecutable(.{
.name = f.name,
Expand Down
4 changes: 2 additions & 2 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
.hash = "N-V-__8AAOlnwQD_q2VUB2dZD64hwX7kJ2w9knrChBKgJHe0",
},
.RshLang = .{
.url = "git+https://github.com/JohnSmoit/ray-eater-shaders.git#a5c9c1240b9bbcdaab1536d909c22facf548ab7a",
.hash = "RshLang-0.0.0-4EjkCyFmAADvzF5CNrhKYg2-gA09u8Q10ZlJAHbbCwoI",
.url = "git+https://github.com/JohnSmoit/ray-eater-shaders.git#621811032c0d385a1c49d5f655e2498a1de72ab9",
.hash = "RshLang-0.0.0-4EjkC1twAACu3mtJTUJzOjluiAhJQzA5rDEGfYHgaMnD",
},
},
.paths = .{
Expand Down
132 changes: 0 additions & 132 deletions samples/basic_compute.zig

This file was deleted.

2 changes: 1 addition & 1 deletion samples/basic_planes.zig
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const ray = @import("ray");
const math = ray.math;
const api = ray.api;

const helpers = @import("common/helpers.zig");
const helpers = @import("helpers");
const util = ray.util;

const span = util.span;
Expand Down
18 changes: 18 additions & 0 deletions samples/common/helpers.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,18 @@ const vk = @import("vulkan");

const glfw = @import("glfw");

const ray = @import("ray");

const ShaderModule = ray.api.ShaderModule;
const Stage = ShaderModule.Stage;
const Context = ray.Context;

const Allocator = std.mem.Allocator;

const Window = glfw.Window;

pub const RenderQuad = @import("render_quad.zig");

pub fn makeBasicWindow(w: u32, h: u32, name: []const u8) !Window {
glfw.init() catch |err| {
std.debug.print("Failed to initialize GLFW\n", .{});
Expand Down Expand Up @@ -38,3 +48,11 @@ pub fn windowExtent(win: *const Window) vk.Extent2D {
.height = dims.height,
};
}

pub fn initSampleShader(ctx: *const Context, allocator: Allocator, path: []const u8, stage: Stage) !ShaderModule {
const base: []const u8 = "samples/";
const final_path = try std.mem.concat(allocator, u8, &.{base, path});
defer allocator.free(final_path);

return ShaderModule.fromSourceFile(ctx, allocator, final_path, stage);
}
132 changes: 132 additions & 0 deletions samples/common/render_quad.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
const std = @import("std");
const ray = @import("ray");
const api = ray.api;

const Allocator = std.mem.Allocator;

const Self = @This();

const Context = ray.Context;

const Descriptor = api.Descriptor;
const GraphicsPipeline = api.GraphicsPipeline;
const FixedFunctionState = api.FixedFunctionState;
const ShaderModule = api.ShaderModule;
const RenderPass = api.RenderPass;
const CommandBuffer = api.CommandBuffer;
const DeviceHandler = api.DeviceHandler;
const FrameBuffer = api.FrameBuffer;

const Swapchain = api.Swapchain;

pipeline: GraphicsPipeline = undefined,
renderpass: RenderPass = undefined,
dev: *const DeviceHandler = undefined,
swapchain: *const Swapchain = undefined,
desc: ?*const Descriptor = null,

const hardcoded_vert_src: []const u8 =
\\ #version 450
\\ vec2 verts[4] = vec2[](
\\ vec2(-1.0, -1.0),
\\ vec2( 1.0, -1.0),
\\ vec2( 1.0, 1.0),
\\ vec2(-1.0, 1.0)
\\ );
\\ vec2 uvs[4] = vec2[](
\\ vec2(0.0, 0.0),
\\ vec2(1.0, 0.0),
\\ vec2(1.0, 1.0),
\\ vec2(0.0, 1.0)
\\);
\\ uint ind[6] = uint[](
\\ 0, 1, 2, 0, 2, 3
\\);
\\ layout(location = 0) out vec2 texCoord;
\\
\\ void main() {
\\ uint index = ind[gl_VertexIndex];
\\ gl_Position = vec4(verts[index], 0.0, 1.0);
\\ texCoord = uvs[index];
\\ }
;

pub const Config = struct {
// null if fragment shader has no referenced data
// fragment descriptors are also combined with vertex descriptors
frag_descriptors: ?*const Descriptor = null,
frag_shader: *const ShaderModule,
swapchain: *const Swapchain,
};

pub fn initSelf(self: *Self, ctx: *const Context, allocator: Allocator, config: Config) !void {
const vert_shader = try ShaderModule.initFromSrc(
ctx,
allocator,
hardcoded_vert_src,
.Vertex,
);
defer vert_shader.deinit();

const shaders: []const ShaderModule = &.{
vert_shader,
config.frag_shader.*,
};

var fixed_functions_config = FixedFunctionState{};
fixed_functions_config.init_self(ctx, &.{
.dynamic_states = &.{
.viewport,
.scissor,
},
.viewport = .{ .Swapchain = config.swapchain },
.descriptors = if (config.frag_descriptors) |fd| &.{
fd.h_desc_layout,
} else &.{},
});
defer fixed_functions_config.deinit();

self.renderpass = try api.RenderPass.initAlloc(ctx, allocator, &.{.{
.attachment = .{
.initial_layout = .undefined,
.final_layout = .present_src_khr,
.format = .r8g8b8a8_srgb,

.load_op = .clear,
.store_op = .store,

.stencil_load_op = .dont_care,
.stencil_store_op = .dont_care,
.samples = .{ .@"1_bit" = true },
},
.tipo = .Color,
}});

self.pipeline = try GraphicsPipeline.init(ctx, .{
.fixed_functions = &fixed_functions_config,
.renderpass = &self.renderpass,
.shader_stages = shaders,
}, allocator);

self.dev = ctx.env(.dev);
self.swapchain = config.swapchain;
self.desc = config.frag_descriptors;
}

pub fn drawOneShot(self: *const Self, cmd_buf: *const CommandBuffer, framebuffer: *const FrameBuffer) void {
self.pipeline.bind(cmd_buf);
const image_index = self.swapchain.image_index;
self.renderpass.begin(cmd_buf, framebuffer, image_index);

if (self.desc) |d| {
d.bind(cmd_buf, self.pipeline.h_pipeline_layout, .{});
}

self.dev.draw(cmd_buf, 6, 1, 0, 0);
self.renderpass.end(cmd_buf);
}

pub fn deinit(self: *Self) void {
self.pipeline.deinit();
self.renderpass.deinit();
}
Loading
Loading