Skip to content

Commit 4720a79

Browse files
authored
Merge pull request #22889 from alichraghi/ali_spv
spirv: miscellaneous stuff
2 parents 0779e84 + 7872082 commit 4720a79

File tree

11 files changed

+530
-2850
lines changed

11 files changed

+530
-2850
lines changed

lib/std/Target/spirv.zig

Lines changed: 79 additions & 2018 deletions
Large diffs are not rendered by default.

lib/std/gpu.zig

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const std = @import("std.zig");
2-
const comptimePrint = std.fmt.comptimePrint;
32

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

9190
/// Forms the main linkage for `input` and `output` address spaces.
9291
/// `ptr` must be a reference to variable or struct field.
93-
pub fn binding(comptime ptr: anytype, comptime group: u32, comptime bind: u32) void {
94-
const code = comptimePrint(
95-
\\OpDecorate %ptr DescriptorSet {}
96-
\\OpDecorate %ptr Binding {}
97-
, .{ group, bind });
98-
asm volatile (code
92+
pub fn binding(comptime ptr: anytype, comptime set: u32, comptime bind: u32) void {
93+
asm volatile (
94+
\\OpDecorate %ptr DescriptorSet $set
95+
\\OpDecorate %ptr Binding $bind
9996
:
10097
: [ptr] "" (ptr),
98+
[set] "c" (set),
99+
[bind] "c" (bind),
101100
);
102101
}
103102

@@ -111,13 +110,10 @@ pub const Origin = enum(u32) {
111110
/// The coordinates appear to originate in the specified `origin`.
112111
/// Only valid with the `Fragment` calling convention.
113112
pub fn fragmentOrigin(comptime entry_point: anytype, comptime origin: Origin) void {
114-
const origin_enum = switch (origin) {
115-
.upper_left => .OriginUpperLeft,
116-
.lower_left => .OriginLowerLeft,
117-
};
118-
asm volatile ("OpExecutionMode %entry_point " ++ @tagName(origin_enum)
113+
asm volatile ("OpExecutionMode %entry_point $origin"
119114
:
120115
: [entry_point] "" (entry_point),
116+
[origin] "c" (@intFromEnum(origin)),
121117
);
122118
}
123119

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

142138
/// Only valid with the `Fragment` calling convention.
143139
pub fn depthMode(comptime entry_point: anytype, comptime mode: DepthMode) void {
144-
const code = comptimePrint("OpExecutionMode %entry_point {}", .{@intFromEnum(mode)});
145-
asm volatile (code
140+
asm volatile ("OpExecutionMode %entry_point $mode"
146141
:
147142
: [entry_point] "" (entry_point),
143+
[mode] "c" (mode),
148144
);
149145
}
150146

151147
/// Indicates the workgroup size in the `x`, `y`, and `z` dimensions.
152148
/// Only valid with the `GLCompute` or `Kernel` calling conventions.
153149
pub fn workgroupSize(comptime entry_point: anytype, comptime size: @Vector(3, u32)) void {
154-
const code = comptimePrint("OpExecutionMode %entry_point LocalSize {} {} {}", .{
155-
size[0],
156-
size[1],
157-
size[2],
158-
});
159-
asm volatile (code
150+
asm volatile ("OpExecutionMode %entry_point LocalSize %x %y %z"
160151
:
161152
: [entry_point] "" (entry_point),
153+
[x] "c" (size[0]),
154+
[y] "c" (size[1]),
155+
[z] "c" (size[2]),
162156
);
163157
}
164158

165159
/// A hint to the client, which indicates the workgroup size in the `x`, `y`, and `z` dimensions.
166160
/// Only valid with the `GLCompute` or `Kernel` calling conventions.
167161
pub fn workgroupSizeHint(comptime entry_point: anytype, comptime size: @Vector(3, u32)) void {
168-
const code = comptimePrint("OpExecutionMode %entry_point LocalSizeHint {} {} {}", .{
169-
size[0],
170-
size[1],
171-
size[2],
172-
});
173-
asm volatile (code
162+
asm volatile ("OpExecutionMode %entry_point LocalSizeHint %x %y %z"
174163
:
175164
: [entry_point] "" (entry_point),
165+
[x] "c" (size[0]),
166+
[y] "c" (size[1]),
167+
[z] "c" (size[2]),
176168
);
177169
}

0 commit comments

Comments
 (0)