authorgravatar for alichraghi@proton.meAli Chraghi <alichraghi@proton.me> 2025-02-13 16:14:17+03:30
committergravatar for alichraghi@proton.meAli Chraghi <alichraghi@proton.me> 2025-02-18 18:07:31+03:30
log7bbeac7f175f5b2aff27aea9c9f64d531150aa80
treecdcba358c04513d772c3baedffde035e56e549c3
parent0779e847f79851419dfeb39595b1817ce72ea9fa
signaturelock-open Commit is signed but in an unrecognized format.

std.gpu: stop using `comptimePrint`


1 files changed, 20 insertions(+), 28 deletions(-)

lib/std/gpu.zig+20-28
......@@ -1,5 +1,4 @@
11const std = @import("std.zig");
2const 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.
8382pub 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.
93pub 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
92pub 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.
113112pub 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.
143139pub 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.
153149pub 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.
167161pub 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}