Skip to content

Commit

Permalink
Merge pull request #22889 from alichraghi/ali_spv
Browse files Browse the repository at this point in the history
spirv: miscellaneous stuff
  • Loading branch information
Snektron authored Feb 18, 2025
2 parents 0779e84 + 7872082 commit 4720a79
Show file tree
Hide file tree
Showing 11 changed files with 530 additions and 2,850 deletions.
2,097 changes: 79 additions & 2,018 deletions lib/std/Target/spirv.zig

Large diffs are not rendered by default.

48 changes: 20 additions & 28 deletions lib/std/gpu.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const std = @import("std.zig");
const comptimePrint = std.fmt.comptimePrint;

/// Will make `ptr` contain the location of the current invocation within the
/// global workgroup. Each component is equal to the index of the local workgroup
Expand Down Expand Up @@ -81,23 +80,23 @@ pub fn fragmentDepth(comptime ptr: *addrspace(.output) f32) void {
/// Forms the main linkage for `input` and `output` address spaces.
/// `ptr` must be a reference to variable or struct field.
pub fn location(comptime ptr: anytype, comptime loc: u32) void {
const code = comptimePrint("OpDecorate %ptr Location {}", .{loc});
asm volatile (code
asm volatile ("OpDecorate %ptr Location $loc"
:
: [ptr] "" (ptr),
[loc] "c" (loc),
);
}

/// Forms the main linkage for `input` and `output` address spaces.
/// `ptr` must be a reference to variable or struct field.
pub fn binding(comptime ptr: anytype, comptime group: u32, comptime bind: u32) void {
const code = comptimePrint(
\\OpDecorate %ptr DescriptorSet {}
\\OpDecorate %ptr Binding {}
, .{ group, bind });
asm volatile (code
pub fn binding(comptime ptr: anytype, comptime set: u32, comptime bind: u32) void {
asm volatile (
\\OpDecorate %ptr DescriptorSet $set
\\OpDecorate %ptr Binding $bind
:
: [ptr] "" (ptr),
[set] "c" (set),
[bind] "c" (bind),
);
}

Expand All @@ -111,13 +110,10 @@ pub const Origin = enum(u32) {
/// The coordinates appear to originate in the specified `origin`.
/// Only valid with the `Fragment` calling convention.
pub fn fragmentOrigin(comptime entry_point: anytype, comptime origin: Origin) void {
const origin_enum = switch (origin) {
.upper_left => .OriginUpperLeft,
.lower_left => .OriginLowerLeft,
};
asm volatile ("OpExecutionMode %entry_point " ++ @tagName(origin_enum)
asm volatile ("OpExecutionMode %entry_point $origin"
:
: [entry_point] "" (entry_point),
[origin] "c" (@intFromEnum(origin)),
);
}

Expand All @@ -141,37 +137,33 @@ pub const DepthMode = enum(u32) {

/// Only valid with the `Fragment` calling convention.
pub fn depthMode(comptime entry_point: anytype, comptime mode: DepthMode) void {
const code = comptimePrint("OpExecutionMode %entry_point {}", .{@intFromEnum(mode)});
asm volatile (code
asm volatile ("OpExecutionMode %entry_point $mode"
:
: [entry_point] "" (entry_point),
[mode] "c" (mode),
);
}

/// Indicates the workgroup size in the `x`, `y`, and `z` dimensions.
/// Only valid with the `GLCompute` or `Kernel` calling conventions.
pub fn workgroupSize(comptime entry_point: anytype, comptime size: @Vector(3, u32)) void {
const code = comptimePrint("OpExecutionMode %entry_point LocalSize {} {} {}", .{
size[0],
size[1],
size[2],
});
asm volatile (code
asm volatile ("OpExecutionMode %entry_point LocalSize %x %y %z"
:
: [entry_point] "" (entry_point),
[x] "c" (size[0]),
[y] "c" (size[1]),
[z] "c" (size[2]),
);
}

/// A hint to the client, which indicates the workgroup size in the `x`, `y`, and `z` dimensions.
/// Only valid with the `GLCompute` or `Kernel` calling conventions.
pub fn workgroupSizeHint(comptime entry_point: anytype, comptime size: @Vector(3, u32)) void {
const code = comptimePrint("OpExecutionMode %entry_point LocalSizeHint {} {} {}", .{
size[0],
size[1],
size[2],
});
asm volatile (code
asm volatile ("OpExecutionMode %entry_point LocalSizeHint %x %y %z"
:
: [entry_point] "" (entry_point),
[x] "c" (size[0]),
[y] "c" (size[1]),
[z] "c" (size[2]),
);
}
Loading

0 comments on commit 4720a79

Please sign in to comment.