fixing descriptor sets managment
This commit is contained in:
@@ -17,10 +17,10 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: https://codeberg.org/mlugg/setup-zig@v2
|
|
||||||
- uses: actions/setup-node@v6
|
|
||||||
with:
|
with:
|
||||||
node-version: 24
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- uses: https://codeberg.org/mlugg/setup-zig@v2
|
||||||
|
|
||||||
- name: Building
|
- name: Building
|
||||||
run: zig build -Dno-example=true
|
run: zig build -Dno-example=true
|
||||||
@@ -28,10 +28,16 @@ jobs:
|
|||||||
- name: Generating docs
|
- name: Generating docs
|
||||||
run: zig build docs -Dno-example=true
|
run: zig build docs -Dno-example=true
|
||||||
|
|
||||||
- name: Publish to Cloudflare Pages
|
- name: Deploying docs
|
||||||
uses: cloudflare/wrangler-action@v3
|
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
|
||||||
|
uses: milanmk/actions-file-deployer@master
|
||||||
with:
|
with:
|
||||||
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
remote-protocol: sftp
|
||||||
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
remote-host: ${{ secrets.SFTP_HOST_DOCS }}
|
||||||
command: pages deploy zig-out/docs --project-name=spirv-interpreter-docs
|
remote-user: ${{ secrets.SFTP_USER_DOCS }}
|
||||||
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
|
remote-password: ${{ secrets.SFTP_PASSWORD_DOCS }}
|
||||||
|
remote-port: 6969
|
||||||
|
local-path: "./zig-out/docs"
|
||||||
|
remote-path: "/www"
|
||||||
|
sync: full
|
||||||
|
|
||||||
|
|||||||
+28
-8
@@ -9,8 +9,6 @@ const SpvByte = spv.SpvByte;
|
|||||||
const SpvWord = spv.SpvWord;
|
const SpvWord = spv.SpvWord;
|
||||||
const SpvBool = spv.SpvBool;
|
const SpvBool = spv.SpvBool;
|
||||||
|
|
||||||
const SpvBinding = spv.SpvBinding;
|
|
||||||
|
|
||||||
const Result = @import("Result.zig");
|
const Result = @import("Result.zig");
|
||||||
const Runtime = @import("Runtime.zig");
|
const Runtime = @import("Runtime.zig");
|
||||||
const Value = @import("Value.zig").Value;
|
const Value = @import("Value.zig").Value;
|
||||||
@@ -30,6 +28,12 @@ const SpvEntryPoint = struct {
|
|||||||
globals: []SpvWord,
|
globals: []SpvWord,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const BindingEntry = struct {
|
||||||
|
set: SpvWord,
|
||||||
|
binding: SpvWord,
|
||||||
|
result: SpvWord,
|
||||||
|
};
|
||||||
|
|
||||||
pub const ModuleError = error{
|
pub const ModuleError = error{
|
||||||
InvalidSpirV,
|
InvalidSpirV,
|
||||||
InvalidMagic,
|
InvalidMagic,
|
||||||
@@ -73,7 +77,7 @@ geometry_output: SpvWord,
|
|||||||
|
|
||||||
input_locations: [lib.SPIRV_MAX_INPUT_LOCATIONS]SpvWord,
|
input_locations: [lib.SPIRV_MAX_INPUT_LOCATIONS]SpvWord,
|
||||||
output_locations: [lib.SPIRV_MAX_OUTPUT_LOCATIONS]SpvWord,
|
output_locations: [lib.SPIRV_MAX_OUTPUT_LOCATIONS]SpvWord,
|
||||||
bindings: [lib.SPIRV_MAX_SET][lib.SPIRV_MAX_SET_BINDINGS]SpvWord,
|
bindings: std.ArrayList(BindingEntry),
|
||||||
builtins: std.EnumMap(spv.SpvBuiltIn, SpvWord),
|
builtins: std.EnumMap(spv.SpvBuiltIn, SpvWord),
|
||||||
|
|
||||||
pub fn init(allocator: std.mem.Allocator, source: []const SpvWord, options: ModuleOptions) ModuleError!Self {
|
pub fn init(allocator: std.mem.Allocator, source: []const SpvWord, options: ModuleOptions) ModuleError!Self {
|
||||||
@@ -82,12 +86,14 @@ pub fn init(allocator: std.mem.Allocator, source: []const SpvWord, options: Modu
|
|||||||
.code = allocator.dupe(SpvWord, source) catch return ModuleError.OutOfMemory,
|
.code = allocator.dupe(SpvWord, source) catch return ModuleError.OutOfMemory,
|
||||||
.extensions = std.ArrayList([]const u8).empty,
|
.extensions = std.ArrayList([]const u8).empty,
|
||||||
.entry_points = std.ArrayList(SpvEntryPoint).empty,
|
.entry_points = std.ArrayList(SpvEntryPoint).empty,
|
||||||
|
.bindings = std.ArrayList(BindingEntry).empty,
|
||||||
.capabilities = std.EnumSet(spv.SpvCapability).initEmpty(),
|
.capabilities = std.EnumSet(spv.SpvCapability).initEmpty(),
|
||||||
.local_size_x = 1,
|
.local_size_x = 1,
|
||||||
.local_size_y = 1,
|
.local_size_y = 1,
|
||||||
.local_size_z = 1,
|
.local_size_z = 1,
|
||||||
});
|
});
|
||||||
errdefer allocator.free(self.code);
|
errdefer allocator.free(self.code);
|
||||||
|
errdefer self.bindings.deinit(allocator);
|
||||||
|
|
||||||
op.initRuntimeDispatcher();
|
op.initRuntimeDispatcher();
|
||||||
|
|
||||||
@@ -125,7 +131,7 @@ pub fn init(allocator: std.mem.Allocator, source: []const SpvWord, options: Modu
|
|||||||
_ = self.it.skip(); // Skip schema
|
_ = self.it.skip(); // Skip schema
|
||||||
|
|
||||||
try self.pass(allocator); // Setup pass
|
try self.pass(allocator); // Setup pass
|
||||||
try self.applyDecorations();
|
try self.applyDecorations(allocator);
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
@@ -256,13 +262,13 @@ fn applyStructMemberInterfaceDecorations(self: *Self, storage_class: spv.SpvStor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn applyDecorations(self: *Self) ModuleError!void {
|
fn applyDecorations(self: *Self, allocator: std.mem.Allocator) ModuleError!void {
|
||||||
for (self.results, 0..) |result, id| {
|
for (self.results, 0..) |result, id| {
|
||||||
if (result.variant == null)
|
if (result.variant == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
var set: ?usize = null;
|
var set: ?SpvWord = null;
|
||||||
var binding: ?usize = null;
|
var binding: ?SpvWord = null;
|
||||||
|
|
||||||
for (result.decorations.items) |decoration| {
|
for (result.decorations.items) |decoration| {
|
||||||
if (result.variant) |*variant| switch (variant.*) {
|
if (result.variant) |*variant| switch (variant.*) {
|
||||||
@@ -320,11 +326,24 @@ fn applyDecorations(self: *Self) ModuleError!void {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (set != null and binding != null) {
|
if (set != null and binding != null) {
|
||||||
self.bindings[set.?][binding.?] = @intCast(id);
|
self.bindings.append(allocator, .{
|
||||||
|
.set = set.?,
|
||||||
|
.binding = binding.?,
|
||||||
|
.result = @intCast(id),
|
||||||
|
}) catch return ModuleError.OutOfMemory;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn getBindingResult(self: *const Self, set: SpvWord, binding: SpvWord) ?SpvWord {
|
||||||
|
for (self.bindings.items) |entry| {
|
||||||
|
if (entry.set == set and entry.binding == binding) {
|
||||||
|
return entry.result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn deinit(self: *Self, allocator: std.mem.Allocator) void {
|
pub fn deinit(self: *Self, allocator: std.mem.Allocator) void {
|
||||||
allocator.free(self.code);
|
allocator.free(self.code);
|
||||||
for (self.entry_points.items) |entry| {
|
for (self.entry_points.items) |entry| {
|
||||||
@@ -337,6 +356,7 @@ pub fn deinit(self: *Self, allocator: std.mem.Allocator) void {
|
|||||||
allocator.free(ext);
|
allocator.free(ext);
|
||||||
}
|
}
|
||||||
self.extensions.deinit(allocator);
|
self.extensions.deinit(allocator);
|
||||||
|
self.bindings.deinit(allocator);
|
||||||
|
|
||||||
for (self.results) |*result| {
|
for (self.results) |*result| {
|
||||||
result.deinit(allocator);
|
result.deinit(allocator);
|
||||||
|
|||||||
+16
-17
@@ -246,7 +246,9 @@ pub fn continueEntryPoint(self: *Self, allocator: std.mem.Allocator) RuntimeErro
|
|||||||
fn pass(self: *Self, allocator: std.mem.Allocator, op_set: ?std.EnumSet(spv.SpvOp)) RuntimeError!void {
|
fn pass(self: *Self, allocator: std.mem.Allocator, op_set: ?std.EnumSet(spv.SpvOp)) RuntimeError!void {
|
||||||
self.it.did_jump = false; // To reset function jump
|
self.it.did_jump = false; // To reset function jump
|
||||||
while (self.it.nextOrNull()) |opcode_data| {
|
while (self.it.nextOrNull()) |opcode_data| {
|
||||||
const word_count = ((opcode_data & (~spv.SpvOpCodeMask)) >> spv.SpvWordCountShift) - 1;
|
const word_count_with_header = (opcode_data & (~spv.SpvOpCodeMask)) >> spv.SpvWordCountShift;
|
||||||
|
if (word_count_with_header == 0) return RuntimeError.InvalidSpirV;
|
||||||
|
const word_count = word_count_with_header - 1;
|
||||||
const opcode = (opcode_data & spv.SpvOpCodeMask);
|
const opcode = (opcode_data & spv.SpvOpCodeMask);
|
||||||
|
|
||||||
if (op_set) |set| {
|
if (op_set) |set| {
|
||||||
@@ -282,22 +284,19 @@ pub fn populatePushConstants(self: *Self, blob: []const u8) RuntimeError!void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn writeDescriptorSet(self: *const Self, input: []const u8, set: SpvWord, binding: SpvWord, descriptor_index: SpvWord) RuntimeError!void {
|
pub fn writeDescriptorSet(self: *const Self, input: []const u8, set: SpvWord, binding: SpvWord, descriptor_index: SpvWord) RuntimeError!void {
|
||||||
if (set < lib.SPIRV_MAX_SET and binding < lib.SPIRV_MAX_SET_BINDINGS) {
|
const result = self.mod.getBindingResult(set, binding) orelse return RuntimeError.NotFound;
|
||||||
const value = &(self.results[self.mod.bindings[set][binding]].variant orelse return).Variable.value;
|
const value = &(self.results[result].variant orelse return).Variable.value;
|
||||||
switch (value.*) {
|
switch (value.*) {
|
||||||
.Array => |arr| {
|
.Array => |arr| {
|
||||||
if (descriptor_index >= arr.values.len)
|
if (descriptor_index >= arr.values.len)
|
||||||
return RuntimeError.NotFound;
|
return RuntimeError.NotFound;
|
||||||
_ = try arr.values[descriptor_index].write(input);
|
_ = try arr.values[descriptor_index].write(input);
|
||||||
},
|
},
|
||||||
else => {
|
else => {
|
||||||
if (descriptor_index != 0)
|
if (descriptor_index != 0)
|
||||||
return RuntimeError.NotFound;
|
return RuntimeError.NotFound;
|
||||||
_ = try value.write(input);
|
_ = try value.write(input);
|
||||||
},
|
},
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return RuntimeError.NotFound;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+9
-2
@@ -113,7 +113,9 @@ pub const Value = union(Type) {
|
|||||||
type_word: SpvWord,
|
type_word: SpvWord,
|
||||||
driver_image: *anyopaque,
|
driver_image: *anyopaque,
|
||||||
},
|
},
|
||||||
Sampler: struct {},
|
Sampler: struct {
|
||||||
|
driver_sampler: *anyopaque,
|
||||||
|
},
|
||||||
SampledImage: struct {
|
SampledImage: struct {
|
||||||
type_word: SpvWord,
|
type_word: SpvWord,
|
||||||
driver_image: *anyopaque,
|
driver_image: *anyopaque,
|
||||||
@@ -255,7 +257,11 @@ pub const Value = union(Type) {
|
|||||||
.driver_image = undefined,
|
.driver_image = undefined,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
.Sampler => RuntimeError.ToDo,
|
.Sampler => .{
|
||||||
|
.Sampler = .{
|
||||||
|
.driver_sampler = undefined,
|
||||||
|
},
|
||||||
|
},
|
||||||
.SampledImage => .{
|
.SampledImage => .{
|
||||||
.SampledImage = .{
|
.SampledImage = .{
|
||||||
.type_word = target_type,
|
.type_word = target_type,
|
||||||
@@ -487,6 +493,7 @@ pub const Value = union(Type) {
|
|||||||
},
|
},
|
||||||
.RuntimeArray => |*arr| arr.data = @constCast(input[0..]),
|
.RuntimeArray => |*arr| arr.data = @constCast(input[0..]),
|
||||||
.Image => |*img| img.driver_image = @ptrFromInt(std.mem.bytesToValue(usize, input[0..])),
|
.Image => |*img| img.driver_image = @ptrFromInt(std.mem.bytesToValue(usize, input[0..])),
|
||||||
|
.Sampler => |*sampler| sampler.driver_sampler = @ptrFromInt(std.mem.bytesToValue(usize, input[0..])),
|
||||||
.SampledImage => |*img| {
|
.SampledImage => |*img| {
|
||||||
img.driver_image = @ptrFromInt(std.mem.bytesToValue(usize, input[0..]));
|
img.driver_image = @ptrFromInt(std.mem.bytesToValue(usize, input[0..]));
|
||||||
img.driver_sampler = @ptrFromInt(std.mem.bytesToValue(usize, input[@sizeOf(usize)..]));
|
img.driver_sampler = @ptrFromInt(std.mem.bytesToValue(usize, input[@sizeOf(usize)..]));
|
||||||
|
|||||||
+42
-1
@@ -217,6 +217,7 @@ pub const SetupDispatcher = block: {
|
|||||||
.SMulExtended = autoSetupConstant,
|
.SMulExtended = autoSetupConstant,
|
||||||
.SNegate = autoSetupConstant,
|
.SNegate = autoSetupConstant,
|
||||||
.SRem = autoSetupConstant,
|
.SRem = autoSetupConstant,
|
||||||
|
.SampledImage = autoSetupConstant,
|
||||||
.SatConvertSToU = autoSetupConstant,
|
.SatConvertSToU = autoSetupConstant,
|
||||||
.SatConvertUToS = autoSetupConstant,
|
.SatConvertUToS = autoSetupConstant,
|
||||||
.Select = autoSetupConstant,
|
.Select = autoSetupConstant,
|
||||||
@@ -229,6 +230,7 @@ pub const SetupDispatcher = block: {
|
|||||||
.TypeFloat = opTypeFloat,
|
.TypeFloat = opTypeFloat,
|
||||||
.TypeFunction = opTypeFunction,
|
.TypeFunction = opTypeFunction,
|
||||||
.TypeImage = opTypeImage,
|
.TypeImage = opTypeImage,
|
||||||
|
.TypeSampler = opTypeSampler,
|
||||||
.TypeSampledImage = opTypeSampledImage,
|
.TypeSampledImage = opTypeSampledImage,
|
||||||
.TypeInt = opTypeInt,
|
.TypeInt = opTypeInt,
|
||||||
.TypeMatrix = opTypeMatrix,
|
.TypeMatrix = opTypeMatrix,
|
||||||
@@ -334,6 +336,7 @@ pub fn initRuntimeDispatcher() void {
|
|||||||
runtime_dispatcher[@intFromEnum(spv.SpvOp.ImageSampleImplicitLod)] = ImageEngine(.SampleImplicitLod).op;
|
runtime_dispatcher[@intFromEnum(spv.SpvOp.ImageSampleImplicitLod)] = ImageEngine(.SampleImplicitLod).op;
|
||||||
runtime_dispatcher[@intFromEnum(spv.SpvOp.ImageTexelPointer)] = opImageTexelPointer;
|
runtime_dispatcher[@intFromEnum(spv.SpvOp.ImageTexelPointer)] = opImageTexelPointer;
|
||||||
runtime_dispatcher[@intFromEnum(spv.SpvOp.ImageWrite)] = ImageEngine(.Write).op;
|
runtime_dispatcher[@intFromEnum(spv.SpvOp.ImageWrite)] = ImageEngine(.Write).op;
|
||||||
|
runtime_dispatcher[@intFromEnum(spv.SpvOp.SampledImage)] = opSampledImage;
|
||||||
runtime_dispatcher[@intFromEnum(spv.SpvOp.InBoundsAccessChain)] = opAccessChain;
|
runtime_dispatcher[@intFromEnum(spv.SpvOp.InBoundsAccessChain)] = opAccessChain;
|
||||||
runtime_dispatcher[@intFromEnum(spv.SpvOp.IsFinite)] = CondEngine(.Float, .IsNan).op;
|
runtime_dispatcher[@intFromEnum(spv.SpvOp.IsFinite)] = CondEngine(.Float, .IsNan).op;
|
||||||
runtime_dispatcher[@intFromEnum(spv.SpvOp.IsInf)] = CondEngine(.Float, .IsInf).op;
|
runtime_dispatcher[@intFromEnum(spv.SpvOp.IsInf)] = CondEngine(.Float, .IsInf).op;
|
||||||
@@ -1134,6 +1137,14 @@ fn ImageEngine(comptime Op: ImageOp) type {
|
|||||||
|
|
||||||
fn readSampleCoordLane(coord: *const Value, lane_index: usize) RuntimeError!f32 {
|
fn readSampleCoordLane(coord: *const Value, lane_index: usize) RuntimeError!f32 {
|
||||||
return switch (coord.*) {
|
return switch (coord.*) {
|
||||||
|
.Float => |f| {
|
||||||
|
if (lane_index != 0) return RuntimeError.OutOfBounds;
|
||||||
|
return f.value.float32;
|
||||||
|
},
|
||||||
|
.Int => |i| {
|
||||||
|
if (lane_index != 0) return RuntimeError.OutOfBounds;
|
||||||
|
return if (i.is_signed) @floatFromInt(i.value.sint32) else @floatFromInt(i.value.uint32);
|
||||||
|
},
|
||||||
.Vector => |lanes| {
|
.Vector => |lanes| {
|
||||||
if (lane_index >= lanes.len) return RuntimeError.OutOfBounds;
|
if (lane_index >= lanes.len) return RuntimeError.OutOfBounds;
|
||||||
return readSampleCoordLane(&lanes[lane_index], 0);
|
return readSampleCoordLane(&lanes[lane_index], 0);
|
||||||
@@ -3790,6 +3801,36 @@ fn opTypeSampledImage(_: std.mem.Allocator, _: SpvWord, rt: *Runtime) RuntimeErr
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn opTypeSampler(_: std.mem.Allocator, _: SpvWord, rt: *Runtime) RuntimeError!void {
|
||||||
|
const id = try rt.it.next();
|
||||||
|
rt.results[id].variant = .{
|
||||||
|
.Type = .{
|
||||||
|
.Sampler = .{},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
fn opSampledImage(_: std.mem.Allocator, _: SpvWord, rt: *Runtime) RuntimeError!void {
|
||||||
|
const type_word = try rt.it.next();
|
||||||
|
const dst = try rt.results[try rt.it.next()].getValue();
|
||||||
|
const image = try rt.results[try rt.it.next()].getValue();
|
||||||
|
const sampler = try rt.results[try rt.it.next()].getValue();
|
||||||
|
|
||||||
|
dst.* = .{
|
||||||
|
.SampledImage = .{
|
||||||
|
.type_word = type_word,
|
||||||
|
.driver_image = switch (image.*) {
|
||||||
|
.Image => |img| img.driver_image,
|
||||||
|
else => return RuntimeError.InvalidSpirV,
|
||||||
|
},
|
||||||
|
.driver_sampler = switch (sampler.*) {
|
||||||
|
.Sampler => |s| s.driver_sampler,
|
||||||
|
else => return RuntimeError.InvalidSpirV,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
fn opTypeInt(_: std.mem.Allocator, _: SpvWord, rt: *Runtime) RuntimeError!void {
|
fn opTypeInt(_: std.mem.Allocator, _: SpvWord, rt: *Runtime) RuntimeError!void {
|
||||||
const id = try rt.it.next();
|
const id = try rt.it.next();
|
||||||
rt.results[id].variant = .{
|
rt.results[id].variant = .{
|
||||||
@@ -3979,7 +4020,7 @@ fn opVariable(allocator: std.mem.Allocator, word_count: SpvWord, rt: *Runtime) R
|
|||||||
.storage_class = storage_class,
|
.storage_class = storage_class,
|
||||||
.type_word = resolved_word,
|
.type_word = resolved_word,
|
||||||
.type = resolved_type,
|
.type = resolved_type,
|
||||||
.value = try Value.init(allocator, rt.results, resolved_word, is_externally_visible),
|
.value = try Value.init(allocator, rt.results, resolved_word, is_externally_visible and resolved_type != .Array),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user