working on spirv debug
This commit is contained in:
@@ -36,6 +36,7 @@
|
|||||||
.SPIRV_Interpreter = .{
|
.SPIRV_Interpreter = .{
|
||||||
.url = "git+https://git.kbz8.me/kbz_8/SPIRV-Interpreter#e21d26d9975b96a222b70648ceeea9e473e9657f",
|
.url = "git+https://git.kbz8.me/kbz_8/SPIRV-Interpreter#e21d26d9975b96a222b70648ceeea9e473e9657f",
|
||||||
.hash = "SPIRV_Interpreter-0.0.1-ajmpn2tAAwCBI0oWa3VKlYX3MEM0OxN4iXQ-PwO6_Vhx",
|
.hash = "SPIRV_Interpreter-0.0.1-ajmpn2tAAwCBI0oWa3VKlYX3MEM0OxN4iXQ-PwO6_Vhx",
|
||||||
|
//.path = "../SPIRV-Interpreter",
|
||||||
},
|
},
|
||||||
.cpuinfo = .{
|
.cpuinfo = .{
|
||||||
.url = "git+https://github.com/Kbz-8/cpuinfo#4883954cfcec3f6c9ca9c4aaddfc26107e08726f",
|
.url = "git+https://github.com/Kbz-8/cpuinfo#4883954cfcec3f6c9ca9c4aaddfc26107e08726f",
|
||||||
|
|||||||
@@ -23,11 +23,13 @@ pub fn create(device: *base.Device, allocator: std.mem.Allocator, info: *const v
|
|||||||
.destroy = destroy,
|
.destroy = destroy,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const code = info.p_code[0..@divExact(info.code_size, 4)];
|
||||||
|
|
||||||
self.* = .{
|
self.* = .{
|
||||||
.interface = interface,
|
.interface = interface,
|
||||||
.module = spv.Module.init(
|
.module = spv.Module.init(
|
||||||
allocator,
|
allocator,
|
||||||
info.p_code[0..@divExact(info.code_size, 4)],
|
code,
|
||||||
.{
|
.{
|
||||||
.use_simd_vectors_specializations = !std.process.hasEnvVarConstant(lib.NO_SHADER_SIMD_ENV_NAME),
|
.use_simd_vectors_specializations = !std.process.hasEnvVarConstant(lib.NO_SHADER_SIMD_ENV_NAME),
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -25,16 +25,11 @@ pub fn initCompute(device: *Device, allocator: std.mem.Allocator, cache: ?*Pipel
|
|||||||
_ = allocator;
|
_ = allocator;
|
||||||
_ = cache;
|
_ = cache;
|
||||||
|
|
||||||
var stages: vk.ShaderStageFlags = .{};
|
|
||||||
for (info.p_stages[0..info.stage_count]) |stage| {
|
|
||||||
stages = stages.merge(stage orelse continue);
|
|
||||||
}
|
|
||||||
|
|
||||||
return .{
|
return .{
|
||||||
.owner = device,
|
.owner = device,
|
||||||
.vtable = undefined,
|
.vtable = undefined,
|
||||||
.bind_point = .compute,
|
.bind_point = .compute,
|
||||||
.stages = stages,
|
.stages = info.stage.stage,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,8 +38,10 @@ pub fn initGraphics(device: *Device, allocator: std.mem.Allocator, cache: ?*Pipe
|
|||||||
_ = cache;
|
_ = cache;
|
||||||
|
|
||||||
var stages: vk.ShaderStageFlags = .{};
|
var stages: vk.ShaderStageFlags = .{};
|
||||||
for (info.p_stages[0..info.stage_count]) |stage| {
|
if (info.p_stages) |p_stages| {
|
||||||
stages = stages.merge(stage orelse continue);
|
for (p_stages[0..info.stage_count]) |stage| {
|
||||||
|
stages = stages.merge(stage.stage);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return .{
|
return .{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const vk = @import("vulkan");
|
const vk = @import("vulkan");
|
||||||
|
const lib = @import("lib.zig");
|
||||||
|
|
||||||
const NonDispatchable = @import("NonDispatchable.zig");
|
const NonDispatchable = @import("NonDispatchable.zig");
|
||||||
|
|
||||||
@@ -19,8 +20,12 @@ pub const VTable = struct {
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub fn init(device: *Device, allocator: std.mem.Allocator, info: *const vk.ShaderModuleCreateInfo) VkError!Self {
|
pub fn init(device: *Device, allocator: std.mem.Allocator, info: *const vk.ShaderModuleCreateInfo) VkError!Self {
|
||||||
_ = allocator;
|
if (std.process.hasEnvVarConstant(lib.DRIVER_LOG_SPIRV_ENV_NAME)) {
|
||||||
_ = info;
|
logShaderModule(allocator, info) catch |e| {
|
||||||
|
std.log.scoped(.ShaderModule).err("Failed to disassemble SPIR-V module to readable text: {s}", .{@errorName(e)});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
return .{
|
return .{
|
||||||
.owner = device,
|
.owner = device,
|
||||||
.vtable = undefined,
|
.vtable = undefined,
|
||||||
@@ -30,3 +35,35 @@ pub fn init(device: *Device, allocator: std.mem.Allocator, info: *const vk.Shade
|
|||||||
pub inline fn destroy(self: *Self, allocator: std.mem.Allocator) void {
|
pub inline fn destroy(self: *Self, allocator: std.mem.Allocator) void {
|
||||||
self.vtable.destroy(self, allocator);
|
self.vtable.destroy(self, allocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn logShaderModule(allocator: std.mem.Allocator, info: *const vk.ShaderModuleCreateInfo) !void {
|
||||||
|
std.log.scoped(.ShaderModule).info("Logging SPIR-V module", .{});
|
||||||
|
|
||||||
|
var process = std.process.Child.init(&[_][]const u8{ "spirv-dis", "--no-color", "/home/kbz8/Documents/Code/Zig/SPIRV-Interpreter/example/shader.spv" }, allocator);
|
||||||
|
|
||||||
|
process.stdout_behavior = .Pipe;
|
||||||
|
process.stderr_behavior = .Pipe;
|
||||||
|
process.stdin_behavior = .Pipe;
|
||||||
|
|
||||||
|
var stdout: std.ArrayList(u8) = .empty;
|
||||||
|
defer stdout.deinit(allocator);
|
||||||
|
var stderr: std.ArrayList(u8) = .empty;
|
||||||
|
defer stderr.deinit(allocator);
|
||||||
|
|
||||||
|
try process.spawn();
|
||||||
|
errdefer {
|
||||||
|
_ = process.kill() catch {};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (process.stdin) |stdin| {
|
||||||
|
_ = try stdin.write(@ptrCast(@alignCast(info.p_code[0..@divExact(info.code_size, 4)])));
|
||||||
|
}
|
||||||
|
try process.collectOutput(allocator, &stdout, &stderr, 1024 * 1024);
|
||||||
|
_ = try process.wait();
|
||||||
|
|
||||||
|
if (stderr.items.len != 0) {
|
||||||
|
std.log.scoped(.ShaderModule).err("Failed to disassemble SPIR-V module to readable text.\nError:\n{s}", .{stderr.items});
|
||||||
|
} else if (stdout.items.len != 0) {
|
||||||
|
std.log.scoped(.ShaderModule).info("{s}\n{d}", .{ stdout.items, stdout.items.len });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -50,6 +50,8 @@ pub const VULKAN_VENDOR_ID = @typeInfo(vk.VendorId).@"enum".fields[@typeInfo(vk.
|
|||||||
pub const DRIVER_DEBUG_ALLOCATOR_ENV_NAME = "STROLL_DEBUG_ALLOCATOR";
|
pub const DRIVER_DEBUG_ALLOCATOR_ENV_NAME = "STROLL_DEBUG_ALLOCATOR";
|
||||||
pub const DRIVER_LOGS_ENV_NAME = "STROLL_LOGS_LEVEL";
|
pub const DRIVER_LOGS_ENV_NAME = "STROLL_LOGS_LEVEL";
|
||||||
|
|
||||||
|
pub const DRIVER_LOG_SPIRV_ENV_NAME = "STROLL_LOG_SPIRV";
|
||||||
|
|
||||||
/// Default driver name
|
/// Default driver name
|
||||||
pub const DRIVER_NAME = "Unnamed Stroll Driver";
|
pub const DRIVER_NAME = "Unnamed Stroll Driver";
|
||||||
/// Default Vulkan version
|
/// Default Vulkan version
|
||||||
|
|||||||
Reference in New Issue
Block a user