1
0
Fork 0
forked from vv/efemra

first set of nearly-compiling stuff. time to fix compile for real

This commit is contained in:
Vivianne 2022-07-08 17:56:30 -07:00
parent 28d6f4be15
commit b9b7f21ef0
6 changed files with 116 additions and 21 deletions

View file

@ -98,10 +98,7 @@ pub fn build(b: *std.build.Builder) void {
res.addShader("triangle_frag", "src/shaders/triangle.frag");
exe.addPackage(res.package);
exe.addPackage(pkgs.vma);
build_vma.linkVma(exe, gen.output_file.getPath(), mode, target);
exe.addPackage(pkgs.imgui);
build_imgui.link(exe);
exe.install();

View file

@ -8,7 +8,7 @@ const Memory = @import("memory.zig").Memory;
const Framebuffer = @import("framebuffer.zig").Framebuffer;
const Swapchain = @import("Swapchain.zig");
const Context = @import("Context.zig");
const MainPass = @import("main_pass.zig").MainPass;
//const MainPass = @import("main_pass.zig").MainPass;
const Command = @import("Command.zig");
instance: Instance,
@ -19,12 +19,12 @@ framebuffer: Framebuffer,
swapchain: Swapchain,
context: Context,
// sampler: Sampler, TODO
// texTable: TexTable, TODO
// tex_table: TexTable, TODO
// bindings: Bindings, TODO
// targets: Targets, TODO
// meshSys: MeshSys, TODO
// imSys: ImSys, TODO
mainPass: MainPass,
// mesh_sys: MeshSys, TODO
// im_sys: ImSys, TODO
//main_pass: MainPass,
const Self = @This();
@ -47,7 +47,7 @@ pub fn init() !Self {
// try self.targets.init();
// try self.meshSys.init();
// try self.imSys.init();
try self.mainPass.init();
//try self.main_pass.init();
return self;
}
@ -69,14 +69,14 @@ pub fn update(self: Self) bool {
// setup phase
{
self.mainPass.setup();
//self.main_pass.setup();
// TODO textable update
Command.flush();
// TODO bindings update
}
// execute phase
self.mainPass.execute();
//self.main_pass.execute();
// present phase
self.swapchain.submit(Command.get());
@ -93,7 +93,7 @@ pub fn deinit(self: Self) void {
// TODO: delete lightmap pack
self.mainPass.deinit();
//self.main_pass.deinit();
// self.imSys.deinit();
// self.meshSys.deinit();

View file

@ -2,7 +2,7 @@ const std = @import("std");
const vk = @import("vulkan");
const vkd = @import("device.zig").DeviceDispatch;
const Image = @import("image.zig").Image;
const renderpass = @import("renderpass.zig");
const renderpass = @import("render_pass.zig");
const Device = @import("device.zig").Device;
// TODO memory

View file

@ -89,17 +89,17 @@ pub const Instance = struct {
defer allocator.free(list);
_ = try self.vki.enumerateInstanceLayerProperties(&count, list.ptr);
const hashMap = std.StringArrayHashMap(void).init(allocator);
try hashMap.ensureTotalCapacity(count);
const hash_map = std.StringArrayHashMap(void).init(allocator);
try hash_map.ensureTotalCapacity(count);
// TODO log
std.debug.print("{} available instance layers", .{count});
for (list) |layer| {
std.debug.print("{s}", layer.layer_name);
hashMap.putAssumeCapacity(layer);
hash_map.putAssumeCapacity(layer);
}
return hashMap;
return hash_map;
}
fn getLayers(avail_layers: *std.StringArrayHashMap) !std.ArrayList([*:0]const u8) {
@ -122,17 +122,17 @@ pub const Instance = struct {
defer allocator.free(list);
_ = try self.vki.enumerateInstanceExtensionProperties(&count, list.ptr);
const hashMap = std.StringArrayHashMap(void).init(allocator);
try hashMap.ensureTotalCapacity(count);
const hash_map = std.StringArrayHashMap(void).init(allocator);
try hash_map.ensureTotalCapacity(count);
// TODO log
std.debug.print("{} available instance extensions", count);
for (list) |ext| {
std.debug.print("{s}", ext.extension_name);
hashMap.putAssumeCapacity(ext);
hash_map.putAssumeCapacity(ext);
}
return hashMap;
return hash_map;
}
fn getExtensions(avail_exts: *std.StringArrayHashMap) !std.ArrayList([][*:0]const u8) {

View file

@ -0,0 +1,5 @@
const vk = @import("vulkan");
pub fn init() !void {}
pub fn deinit() !void {}

View file

@ -0,0 +1,93 @@
const std = @import("std");
const vk = @import("vulkan");
const profiler = @import("/common/profiler.zig");
const Device = @import("device.zig").Device;
const vkd = @import("device.zig").DeviceDispatch;
const allocator: std.mem.Allocator = undefined;
const Description = struct {};
const s_cache = std.HashMap(Description, vk.RenderPass).init(allocator);
const pm_get = profiler.ProfileMark.init("renderpass.get");
pub fn get(desc: *const Description) !vk.RenderPass {
try pm_get.begin();
defer pm_get.end();
const result = try s_cache.getOrPut(desc);
if (result.found_existing) {
return result.value_ptr;
}
const attachments = [8]vk.AttachmentDescription{};
const refs = [attachments.len]vk.AttachmentReference{};
var attachment_count = 0;
var ref_count = 0;
const format0 = desc.attachments[0].format;
const zero_is_depth = format0 >= .d16_unorm and format0 <= .d32_sfloat_s8_uint;
for (desc.attachments) |dst_attachment, i| {
attachments[i].load_op = .dont_care;
attachments[i].store_op = .dont_care;
const src = &desc.attachments[i];
if (src.format != .@"undefined") {
std.debug.assert(attachment_count < attachments.len);
const dst = &dst_attachment;
dst.format = src.format;
dst.initial_layout = src.layout;
dst.samples = .@"1_bit";
dst.stencil_load_op = .dont_care;
dst.stencil_store_op = .dont_care;
dst.load_op = src.load;
dst.store_op = src.store;
refs[attachment_count].attachment = attachment_count;
refs[attachment_count].layout = src.layout;
if (dst.load_op != .dont_care or dst.store_op != .dont_care) {
std.debug.assert(ref_count < refs.len);
refs[attachment_count].attachment = attachment_count;
refs[attachment_count].layout = src.layout;
}
attachment_count += 1;
}
}
std.debug.assert(attachment_count <= attachments.len);
std.debug.assert(attachment_count <= refs.len);
const color_ref_count = if (zero_is_depth) attachment_count - 1 else attachment_count;
const depth_ref_count = if (zero_is_depth) 1 else 0;
const handle = try new(attachment_count, attachments, 1, &.{
.pipeline_bind_point = .graphics,
.color_attachment_count = color_ref_count,
.p_color_attachments = if (color_ref_count) &refs[depth_ref_count] else null,
.p_depth_stencil_attachment = if (depth_ref_count) &refs[0] else null,
}, 1, &.{
.src_subpass = .external,
.dst_subpass = 0,
.src_stage_mask = desc.src_stage_mask,
.dst_stage_mask = desc.dest_stage_mask,
.src_access_mask = desc.src_access_mask,
.dst_access_mask = desc.dst_access_mask,
});
result.value_ptr.* = handle;
}
fn new(device: *Device, attachment_count: i32, p_attachments: *const vk.AttachmentDescription, subpass_count: i32, p_subpasses: *const vk.SubpassDescription, dependency_count: i32, p_dependencies: *const vk.SubpassDependency) !vk.RenderPass {
const handle: vk.RenderPass = undefined;
try vkd.createRenderPass(device.dev, &.{
.s_type = .render_pass_create_info,
.attachment_count = attachment_count,
.p_attachments = p_attachments,
.subpass_count = subpass_count,
.p_subpasses = p_subpasses,
.dependency_count = dependency_count,
.p_dependencies = p_dependencies,
}, null, &handle);
return handle;
}