Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spirv: miscellaneous stuff #22889

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2,097 changes: 79 additions & 2,018 deletions lib/std/Target/spirv.zig

Large diffs are not rendered by default.

44 changes: 21 additions & 23 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,21 +80,17 @@ 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 " ++ &[_]u8{'0' + loc}
:
: [ptr] "" (ptr),
);
}

/// 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 descriptor_set: u32, comptime bind: u32) void {
asm volatile ("OpDecorate %ptr DescriptorSet " ++ &[_]u8{'0' + descriptor_set} ++
"OpDecorate %ptr Binding " ++ &[_]u8{'0' + bind}
:
: [ptr] "" (ptr),
);
Comment on lines +91 to 96
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this should work

Suggested change
pub fn binding(comptime ptr: anytype, comptime descriptor_set: u32, comptime bind: u32) void {
asm volatile ("OpDecorate %ptr DescriptorSet " ++ &[_]u8{'0' + descriptor_set} ++
"OpDecorate %ptr Binding " ++ &[_]u8{'0' + bind}
:
: [ptr] "" (ptr),
);
pub fn binding(comptime ptr: anytype, comptime descriptor_set: u32, comptime bind: u32) void {
asm volatile (
\\OpDecorate %ptr DescriptorSet $set
\\OpDecorate %ptr Binding $bind
:
: [ptr] "" (ptr),
[set] "c" (set),
[bind] "c" (bind),
);

this $constant syntax was added a while ago I think

Expand Down Expand Up @@ -141,8 +136,7 @@ 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 {}" ++ &[_]u8{'0' + @intFromEnum(mode)}
:
: [entry_point] "" (entry_point),
);
Expand All @@ -151,12 +145,14 @@ pub fn depthMode(comptime entry_point: anytype, comptime mode: DepthMode) void {
/// 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 " ++ &[_]u8{
'0' + size[0],
' ',
'0' + size[1],
' ',
'0' + size[2],
' ',
}
:
: [entry_point] "" (entry_point),
);
Expand All @@ -165,12 +161,14 @@ pub fn workgroupSize(comptime entry_point: anytype, comptime size: @Vector(3, u3
/// 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 {} {} {}" ++ &.{
'0' + size[0],
' ',
'0' + size[1],
' ',
'0' + size[2],
' ',
}
:
: [entry_point] "" (entry_point),
);
Expand Down
Loading
Loading