Skip to content

Commit

Permalink
spirv: remove Int/Float Capabilites for vulkan target
Browse files Browse the repository at this point in the history
  • Loading branch information
alichraghi committed Apr 9, 2024
1 parent b519b93 commit d765c08
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 28 deletions.
15 changes: 13 additions & 2 deletions lib/std/gpu.zig
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ pub fn vertexIndex(comptime ptr: *addrspace(.input) u32) void {
);
}

/// Will make `ptr` contain the index of the instance that is
/// being processed by the current vertex shader invocation.
/// `ptr` must be a reference to variable or struct field.
pub fn instanceIndex(comptime ptr: *addrspace(.input) u32) void {
asm volatile (
\\OpDecorate %ptr BuiltIn InstanceIndex
:
: [ptr] "" (ptr),
);
}

/// Output fragment depth from a `Fragment` entrypoint
/// `ptr` must be a reference to variable or struct field.
pub fn fragmentCoord(comptime ptr: *addrspace(.input) @Vector(4, f32)) void {
Expand Down Expand Up @@ -132,11 +143,11 @@ pub fn location(comptime ptr: anytype, comptime loc: u32) void {

/// 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 {
pub fn binding(comptime ptr: anytype, comptime descriptor_set: u32, comptime bind: u32) void {
const code = comptimePrint(
\\OpDecorate %ptr DescriptorSet {}
\\OpDecorate %ptr Binding {}
, .{ group, bind });
, .{ descriptor_set, bind });
asm volatile (code
:
: [ptr] "" (ptr),
Expand Down
7 changes: 6 additions & 1 deletion src/codegen/spirv.zig
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,11 @@ const DeclGen = struct {
}
}

// TODO: Temporary hack for vulkan shaders
if (target.os.tag == .vulkan) {
return 32;
}

return null;
}

Expand Down Expand Up @@ -1303,11 +1308,11 @@ const DeclGen = struct {
return self.todo("Implement {s} composite int type of {} bits", .{ @tagName(signedness), bits });
};

// Kernel only supports unsigned ints.
if (self.getTarget().os.tag == .vulkan) {
return self.spv.intType(signedness, backing_bits);
}

// Kernel only supports unsigned ints.
return self.spv.intType(.unsigned, backing_bits);
}

Expand Down
2 changes: 1 addition & 1 deletion src/link/SpirV.zig
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ fn writeCapabilities(spv: *SpvModule, target: std.Target) !void {
const caps: []const spec.Capability = switch (target.os.tag) {
.opencl => &.{ .Kernel, .Addresses, .Int8, .Int16, .Int64, .Float64, .Float16, .Vector16, .GenericPointer },
.glsl450 => &.{.Shader},
.vulkan => &.{ .Shader, .Int8, .Int16, .Int64, .Float16, .Float64 },
.vulkan => &.{.Shader},
else => unreachable, // TODO
};

Expand Down
35 changes: 11 additions & 24 deletions src/link/SpirV/BinaryModule.zig
Original file line number Diff line number Diff line change
Expand Up @@ -337,30 +337,17 @@ pub const Parser = struct {
) !usize {
var offset = start_offset;
for (operands) |operand| {
offset = try self.parseOperandResultIds(binary, inst, operand, offset, offsets);
}
return offset;
}

fn parseOperandResultIds(
self: *Parser,
binary: BinaryModule,
inst: Instruction,
operand: spec.Operand,
start_offset: usize,
offsets: *std.ArrayList(u16),
) !usize {
var offset = start_offset;
switch (operand.quantifier) {
.variadic => while (offset < inst.operands.len) {
offset = try self.parseOperandKindResultIds(binary, inst, operand.kind, offset, offsets);
},
.optional => if (offset < inst.operands.len) {
offset = try self.parseOperandKindResultIds(binary, inst, operand.kind, offset, offsets);
},
.required => {
offset = try self.parseOperandKindResultIds(binary, inst, operand.kind, offset, offsets);
},
switch (operand.quantifier) {
.variadic => while (offset < inst.operands.len) {
offset = try self.parseOperandKindResultIds(binary, inst, operand.kind, offset, offsets);
},
.optional => if (offset < inst.operands.len) {
offset = try self.parseOperandKindResultIds(binary, inst, operand.kind, offset, offsets);
},
.required => {
offset = try self.parseOperandKindResultIds(binary, inst, operand.kind, offset, offsets);
},
}
}
return offset;
}
Expand Down

0 comments on commit d765c08

Please sign in to comment.