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 @@...@@ -1,5 +1,4 @@
1const std = @import("std.zig");1const std = @import("std.zig");
2const comptimePrint = std.fmt.comptimePrint;
32
4/// Will make `ptr` contain the location of the current invocation within the3/// Will make `ptr` contain the location of the current invocation within the
5/// global workgroup. Each component is equal to the index of the local workgroup4/// 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 {...@@ -81,23 +80,23 @@ pub fn fragmentDepth(comptime ptr: *addrspace(.output) f32) void {
81/// Forms the main linkage for `input` and `output` address spaces.80/// Forms the main linkage for `input` and `output` address spaces.
82/// `ptr` must be a reference to variable or struct field.81/// `ptr` must be a reference to variable or struct field.
83pub fn location(comptime ptr: anytype, comptime loc: u32) void {82pub fn location(comptime ptr: anytype, comptime loc: u32) void {
84 const code = comptimePrint("OpDecorate %ptr Location {}", .{loc});83 asm volatile ("OpDecorate %ptr Location $loc"
85 asm volatile (code
86 :84 :
87 : [ptr] "" (ptr),85 : [ptr] "" (ptr),
86 [loc] "c" (loc),
88 );87 );
89}88}
9089
91/// Forms the main linkage for `input` and `output` address spaces.90/// Forms the main linkage for `input` and `output` address spaces.
92/// `ptr` must be a reference to variable or struct field.91/// `ptr` must be a reference to variable or struct field.
93pub fn binding(comptime ptr: anytype, comptime group: u32, comptime bind: u32) void {92pub fn binding(comptime ptr: anytype, comptime set: u32, comptime bind: u32) void {
94 const code = comptimePrint(93 asm volatile (
95 \\OpDecorate %ptr DescriptorSet {}94 \\OpDecorate %ptr DescriptorSet $set
96 \\OpDecorate %ptr Binding {}95 \\OpDecorate %ptr Binding $bind
97 , .{ group, bind });
98 asm volatile (code
99 :96 :
100 : [ptr] "" (ptr),97 : [ptr] "" (ptr),
98 [set] "c" (set),
99 [bind] "c" (bind),
101 );100 );
102}101}
103102
...@@ -111,13 +110,10 @@ pub const Origin = enum(u32) {...@@ -111,13 +110,10 @@ pub const Origin = enum(u32) {
111/// The coordinates appear to originate in the specified `origin`.110/// The coordinates appear to originate in the specified `origin`.
112/// Only valid with the `Fragment` calling convention.111/// Only valid with the `Fragment` calling convention.
113pub fn fragmentOrigin(comptime entry_point: anytype, comptime origin: Origin) void {112pub fn fragmentOrigin(comptime entry_point: anytype, comptime origin: Origin) void {
114 const origin_enum = switch (origin) {113 asm volatile ("OpExecutionMode %entry_point $origin"
115 .upper_left => .OriginUpperLeft,
116 .lower_left => .OriginLowerLeft,
117 };
118 asm volatile ("OpExecutionMode %entry_point " ++ @tagName(origin_enum)
119 :114 :
120 : [entry_point] "" (entry_point),115 : [entry_point] "" (entry_point),
116 [origin] "c" (@intFromEnum(origin)),
121 );117 );
122}118}
123119
...@@ -141,37 +137,33 @@ pub const DepthMode = enum(u32) {...@@ -141,37 +137,33 @@ pub const DepthMode = enum(u32) {
141137
142/// Only valid with the `Fragment` calling convention.138/// Only valid with the `Fragment` calling convention.
143pub fn depthMode(comptime entry_point: anytype, comptime mode: DepthMode) void {139pub fn depthMode(comptime entry_point: anytype, comptime mode: DepthMode) void {
144 const code = comptimePrint("OpExecutionMode %entry_point {}", .{@intFromEnum(mode)});140 asm volatile ("OpExecutionMode %entry_point $mode"
145 asm volatile (code
146 :141 :
147 : [entry_point] "" (entry_point),142 : [entry_point] "" (entry_point),
143 [mode] "c" (mode),
148 );144 );
149}145}
150146
151/// Indicates the workgroup size in the `x`, `y`, and `z` dimensions.147/// Indicates the workgroup size in the `x`, `y`, and `z` dimensions.
152/// Only valid with the `GLCompute` or `Kernel` calling conventions.148/// Only valid with the `GLCompute` or `Kernel` calling conventions.
153pub fn workgroupSize(comptime entry_point: anytype, comptime size: @Vector(3, u32)) void {149pub fn workgroupSize(comptime entry_point: anytype, comptime size: @Vector(3, u32)) void {
154 const code = comptimePrint("OpExecutionMode %entry_point LocalSize {} {} {}", .{150 asm volatile ("OpExecutionMode %entry_point LocalSize %x %y %z"
155 size[0],
156 size[1],
157 size[2],
158 });
159 asm volatile (code
160 :151 :
161 : [entry_point] "" (entry_point),152 : [entry_point] "" (entry_point),
153 [x] "c" (size[0]),
154 [y] "c" (size[1]),
155 [z] "c" (size[2]),
162 );156 );
163}157}
164158
165/// A hint to the client, which indicates the workgroup size in the `x`, `y`, and `z` dimensions.159/// A hint to the client, which indicates the workgroup size in the `x`, `y`, and `z` dimensions.
166/// Only valid with the `GLCompute` or `Kernel` calling conventions.160/// Only valid with the `GLCompute` or `Kernel` calling conventions.
167pub fn workgroupSizeHint(comptime entry_point: anytype, comptime size: @Vector(3, u32)) void {161pub fn workgroupSizeHint(comptime entry_point: anytype, comptime size: @Vector(3, u32)) void {
168 const code = comptimePrint("OpExecutionMode %entry_point LocalSizeHint {} {} {}", .{162 asm volatile ("OpExecutionMode %entry_point LocalSizeHint %x %y %z"
169 size[0],
170 size[1],
171 size[2],
172 });
173 asm volatile (code
174 :163 :
175 : [entry_point] "" (entry_point),164 : [entry_point] "" (entry_point),
165 [x] "c" (size[0]),
166 [y] "c" (size[1]),
167 [z] "c" (size[2]),
176 );168 );
177}169}