implementing imulextend and umulextend
This commit is contained in:
@@ -77,7 +77,7 @@ pub fn createCompute(device: *base.Device, allocator: std.mem.Allocator, cache:
|
||||
soft_module.ref();
|
||||
shader.module = soft_module;
|
||||
|
||||
const runtimes = runtimes_allocator.alloc(spv.Runtime, runtimes_count) catch return VkError.OutOfHostMemory;
|
||||
const runtimes = runtimes_allocator.alloc(spv.Runtime, runtimes_count) catch return VkError.OutOfDeviceMemory;
|
||||
|
||||
for (runtimes) |*runtime| {
|
||||
runtime.* = spv.Runtime.init(
|
||||
@@ -97,18 +97,22 @@ pub fn createCompute(device: *base.Device, allocator: std.mem.Allocator, cache:
|
||||
if (specialization.p_map_entries) |map| {
|
||||
const data: []const u8 = @as([*]const u8, @ptrCast(@alignCast(specialization.p_data)))[0..specialization.data_size];
|
||||
for (map[0..], 0..specialization.map_entry_count) |entry, _| {
|
||||
runtime.addSpecializationInfo(runtimes_allocator, .{
|
||||
.id = @intCast(entry.constant_id),
|
||||
.offset = @intCast(entry.offset),
|
||||
.size = @intCast(entry.size),
|
||||
}, data) catch return VkError.OutOfHostMemory;
|
||||
runtime.addSpecializationInfo(
|
||||
runtimes_allocator,
|
||||
.{
|
||||
.id = @intCast(entry.constant_id),
|
||||
.offset = @intCast(entry.offset),
|
||||
.size = @intCast(entry.size),
|
||||
},
|
||||
data,
|
||||
) catch return VkError.OutOfDeviceMemory;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
shader.runtimes = runtimes;
|
||||
shader.entry = runtimes_allocator.dupe(u8, std.mem.span(info.stage.p_name)) catch return VkError.OutOfHostMemory;
|
||||
shader.entry = runtimes_allocator.dupe(u8, std.mem.span(info.stage.p_name)) catch return VkError.OutOfDeviceMemory;
|
||||
|
||||
std.log.scoped(.ComputePipeline).debug("Created {d} runtimes for compute stage", .{runtimes_count});
|
||||
break :blk shader;
|
||||
@@ -224,6 +228,10 @@ pub fn createGraphics(device: *base.Device, allocator: std.mem.Allocator, cache:
|
||||
|
||||
pub fn destroy(interface: *Interface, allocator: std.mem.Allocator) void {
|
||||
const self: *Self = @alignCast(@fieldParentPtr("interface", interface));
|
||||
var it = self.stages.iterator();
|
||||
while (it.next()) |entry| {
|
||||
entry.value.module.unref(allocator);
|
||||
}
|
||||
self.runtimes_allocator.deinit();
|
||||
allocator.destroy(self);
|
||||
}
|
||||
|
||||
@@ -7,11 +7,14 @@ const lib = @import("lib.zig");
|
||||
const VkError = base.VkError;
|
||||
const Device = base.Device;
|
||||
|
||||
const SoftDevice = @import("SoftDevice.zig");
|
||||
|
||||
const Self = @This();
|
||||
pub const Interface = base.ShaderModule;
|
||||
|
||||
interface: Interface,
|
||||
module: spv.Module,
|
||||
module_allocator: std.heap.ArenaAllocator,
|
||||
|
||||
/// Pipelines need SPIR-V module reference so shader module may not
|
||||
/// be destroy on call to `vkDestroyShaderModule`
|
||||
@@ -23,6 +26,13 @@ pub fn create(device: *base.Device, allocator: std.mem.Allocator, info: *const v
|
||||
|
||||
var interface = try Interface.init(device, allocator, info);
|
||||
|
||||
const soft_device: *SoftDevice = @alignCast(@fieldParentPtr("interface", device));
|
||||
const device_allocator = soft_device.device_allocator.allocator();
|
||||
|
||||
var module_allocator_arena: std.heap.ArenaAllocator = .init(device_allocator);
|
||||
errdefer module_allocator_arena.deinit();
|
||||
const module_allocator = module_allocator_arena.allocator();
|
||||
|
||||
interface.vtable = &.{
|
||||
.destroy = destroy,
|
||||
};
|
||||
@@ -31,7 +41,7 @@ pub fn create(device: *base.Device, allocator: std.mem.Allocator, info: *const v
|
||||
|
||||
self.* = .{
|
||||
.interface = interface,
|
||||
.module = spv.Module.init(allocator, code, .{
|
||||
.module = spv.Module.init(module_allocator, code, .{
|
||||
.use_simd_vectors_specializations = base.config.shaders_simd,
|
||||
}) catch |err| switch (err) {
|
||||
spv.Module.ModuleError.OutOfMemory => return VkError.OutOfHostMemory,
|
||||
@@ -43,6 +53,7 @@ pub fn create(device: *base.Device, allocator: std.mem.Allocator, info: *const v
|
||||
return VkError.ValidationFailed;
|
||||
},
|
||||
},
|
||||
.module_allocator = module_allocator_arena,
|
||||
.ref_count = std.atomic.Value(usize).init(1),
|
||||
};
|
||||
return self;
|
||||
@@ -53,16 +64,16 @@ pub fn destroy(interface: *Interface, allocator: std.mem.Allocator) void {
|
||||
self.unref(allocator);
|
||||
}
|
||||
|
||||
pub inline fn drop(self: *Self, allocator: std.mem.Allocator) void {
|
||||
self.module.deinit(allocator);
|
||||
pub fn drop(self: *Self, allocator: std.mem.Allocator) void {
|
||||
self.module_allocator.deinit();
|
||||
allocator.destroy(self);
|
||||
}
|
||||
|
||||
pub inline fn ref(self: *Self) void {
|
||||
pub fn ref(self: *Self) void {
|
||||
_ = self.ref_count.fetchAdd(1, .monotonic);
|
||||
}
|
||||
|
||||
pub inline fn unref(self: *Self, allocator: std.mem.Allocator) void {
|
||||
pub fn unref(self: *Self, allocator: std.mem.Allocator) void {
|
||||
if (self.ref_count.fetchSub(1, .release) == 1) {
|
||||
self.drop(allocator);
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ pub fn draw(self: *Self, vertex_count: usize, instance_count: usize, first_verte
|
||||
const allocator = arena.allocator();
|
||||
|
||||
const timer = std.Io.Timestamp.now(io, .real);
|
||||
defer if (comptime base.config.logs) {
|
||||
defer if (comptime base.config.logs != .none) {
|
||||
const duration = timer.untilNow(io, .real);
|
||||
const ms = duration.toMicroseconds();
|
||||
std.log.scoped(.SoftwareRenderer).debug("Drawcall stats:\n> Took {d}us\n> Allocated {d} KB", .{ ms, @divTrunc(arena.queryCapacity(), 1000) });
|
||||
|
||||
Reference in New Issue
Block a user