Skip to content

Commit afa7793

Browse files
committed
spirv: basic shader support
1 parent 7634a11 commit afa7793

File tree

9 files changed

+220
-115
lines changed

9 files changed

+220
-115
lines changed

lib/std/Target.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,6 +1221,7 @@ pub const Cpu = struct {
12211221
.fs, .gs, .ss => arch == .x86_64 or arch == .x86,
12221222
.global, .constant, .local, .shared => is_gpu,
12231223
.param => is_nvptx,
1224+
.input, .output, .uniform => is_spirv,
12241225
// TODO this should also check how many flash banks the cpu has
12251226
.flash, .flash1, .flash2, .flash3, .flash4, .flash5 => arch == .avr,
12261227
};
@@ -2353,7 +2354,7 @@ pub fn c_type_bit_size(target: Target, c_type: CType) u16 {
23532354
.longdouble => return 128,
23542355
},
23552356

2356-
.opencl => switch (c_type) {
2357+
.opencl, .vulkan => switch (c_type) {
23572358
.char => return 8,
23582359
.short, .ushort => return 16,
23592360
.int, .uint, .float => return 32,
@@ -2386,7 +2387,6 @@ pub fn c_type_bit_size(target: Target, c_type: CType) u16 {
23862387
.hermit,
23872388
.hurd,
23882389
.glsl450,
2389-
.vulkan,
23902390
.driverkit,
23912391
.shadermodel,
23922392
.liteos,

lib/std/builtin.zig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ pub const CallingConvention = enum(u8) {
205205
Win64,
206206
/// AMD GPU, NVPTX, or SPIR-V kernel
207207
Kernel,
208+
// Vulkan-only
209+
Fragment,
210+
Vertex,
208211
};
209212

210213
/// This data structure is used by the Zig language code generation and
@@ -222,6 +225,9 @@ pub const AddressSpace = enum(u5) {
222225
param,
223226
shared,
224227
local,
228+
input,
229+
output,
230+
uniform,
225231

226232
// AVR address spaces.
227233
flash,

src/Sema.zig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9741,6 +9741,10 @@ fn finishFunc(
97419741
.nvptx, .nvptx64, .amdgcn, .spirv32, .spirv64 => null,
97429742
else => "nvptx, amdgcn and SPIR-V",
97439743
},
9744+
.Fragment, .Vertex => switch (arch) {
9745+
.spirv32, .spirv64 => null,
9746+
else => "SPIR-V",
9747+
},
97449748
})) |allowed_platform| {
97459749
return sema.fail(block, cc_src, "callconv '{s}' is only available on {s}, not {s}", .{
97469750
@tagName(cc_resolved),
@@ -37917,6 +37921,7 @@ pub fn analyzeAddressSpace(
3791737921
.gs, .fs, .ss => (arch == .x86 or arch == .x86_64) and ctx == .pointer,
3791837922
// TODO: check that .shared and .local are left uninitialized
3791937923
.param => is_nv,
37924+
.input, .output, .uniform => is_spirv,
3792037925
.global, .shared, .local => is_gpu,
3792137926
.constant => is_gpu and (ctx == .constant),
3792237927
// TODO this should also check how many flash banks the cpu has

src/codegen/llvm.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10848,6 +10848,7 @@ fn toLlvmCallConv(cc: std.builtin.CallingConvention, target: std.Target) Builder
1084810848
.amdgcn => .amdgpu_kernel,
1084910849
else => unreachable,
1085010850
},
10851+
.Vertex, .Fragment => unreachable,
1085110852
};
1085210853
}
1085310854

0 commit comments

Comments
 (0)