summaryrefslogtreecommitdiffstats
path: root/src/renderdoc.zig
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2021-03-09 17:40:29 +0000
committers-ol <s-ol@users.noreply.github.com>2021-03-09 17:40:29 +0000
commit40c7bc1f0f58d3e19d9b4d610454745cfbb005aa (patch)
tree709c7e99854d92988ca5d296afd539559a13761c /src/renderdoc.zig
parentintial commit (diff)
downloadopenxPriments-40c7bc1f0f58d3e19d9b4d610454745cfbb005aa.tar.gz
openxPriments-40c7bc1f0f58d3e19d9b4d610454745cfbb005aa.zip
Vulkan wip
Diffstat (limited to 'src/renderdoc.zig')
-rw-r--r--src/renderdoc.zig77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/renderdoc.zig b/src/renderdoc.zig
new file mode 100644
index 0000000..48cbb16
--- /dev/null
+++ b/src/renderdoc.zig
@@ -0,0 +1,77 @@
+const std = @import("std");
+const c = @cImport({
+ @cInclude("renderdoc_app.h");
+ @cInclude("dlfcn.h");
+});
+
+fn fix_fields(comptime T: type) type {
+ const TypeId = std.builtin.TypeId;
+ var ti = @typeInfo(T);
+
+ const num_fields = ti.Struct.fields.len;
+ var fields = [_]TypeId.StructField{undefined} ** num_fields;
+ for (ti.Struct.fields) |field, i| {
+ var field_ti = @typeInfo(field.field_type);
+
+ switch (field_ti) {
+ .Optional => |opt| {
+ fields[i] = TypeId.StructField{
+ .name = field.name,
+ .field_type = opt.child,
+ .default_value = @as(opt.child, fields[i].default_value),
+ .is_comptime = field.is_comptime,
+ .alignment = field.alignment,
+ };
+ },
+ else => {
+ fields[i] = field;
+ }
+ }
+ }
+
+ ti.Struct.fields = fields[0..];
+ return @Type(.{
+ .Struct = .{
+ .layout = .Extern,
+ .fields = fields,
+ .decls = [_]TypeId.Declaration{},
+ .is_tuple = false,
+ },
+ });
+}
+
+const API = struct {
+ StartFrameCapture: fn (c.RENDERDOC_DevicePointer, c.RENDERDOC_WindowHandle) callconv(.C) void,
+ EndFrameCapture: fn (c.RENDERDOC_DevicePointer, c.RENDERDOC_WindowHandle) callconv(.C) u32,
+};
+
+pub var api: ?API = null;
+
+extern fn RENDERDOC_GetAPI(c.RENDERDOC_Version, [*c]?*c_void) callconv(.C) c_int;
+
+pub fn load_api() !void {
+ var tmp_api: ?*c.RENDERDOC_API_1_1_2 = null;
+ if (RENDERDOC_GetAPI(.eRENDERDOC_API_Version_1_1_2, @ptrCast([*c]?*c_void, &tmp_api)) != 1) {
+ return error.Unknown;
+ }
+
+ if (tmp_api) |_api| {
+ var local_api : API = undefined;
+ var have_all: bool = true;
+ if (_api.StartFrameCapture) |fp| {
+ local_api.StartFrameCapture = fp;
+ } else {
+ return error.NoStart;
+ }
+
+ if (_api.EndFrameCapture) |fp| {
+ local_api.EndFrameCapture = fp;
+ } else {
+ return error.NoEnd;
+ }
+
+ api = local_api;
+ } else {
+ return error.ApiEmpty;
+ }
+}