2022-07-17 12:54:29 +00:00
|
|
|
const std = @import("std");
|
|
|
|
const vk = @import("vulkan");
|
|
|
|
|
2022-07-21 09:10:07 +00:00
|
|
|
const resources = @import("resources");
|
|
|
|
|
2022-07-17 12:54:29 +00:00
|
|
|
const ProfileMark = @import("../../common/profiler.zig").ProfileMark;
|
2022-07-21 09:10:07 +00:00
|
|
|
const settings = @import("settings.zig");
|
2022-07-17 12:54:29 +00:00
|
|
|
const Device = @import("device.zig").Device;
|
|
|
|
const Command = @import("Command.zig");
|
|
|
|
const Swapchain = @import("swapchain.zig").Swapchain;
|
|
|
|
const Image = @import("image.zig").Image;
|
2022-07-21 09:10:07 +00:00
|
|
|
const Buffer = @import("Buffer.zig");
|
2022-07-17 12:56:18 +00:00
|
|
|
const Camera = @import("../Camera.zig");
|
2022-07-21 09:10:07 +00:00
|
|
|
const shaders = @import("shaders.zig");
|
2022-07-17 12:54:29 +00:00
|
|
|
const Pass = @import("Pass.zig");
|
|
|
|
const framebuffer = @import("framebuffer.zig");
|
2022-07-18 10:14:55 +00:00
|
|
|
const Targets = @import("Targets.zig");
|
2022-07-17 12:54:29 +00:00
|
|
|
const RenderPass = @import("RenderPass.zig");
|
2022-07-21 09:10:07 +00:00
|
|
|
const Bindings = @import("Bindings.zig");
|
2022-07-23 10:00:45 +00:00
|
|
|
const Entities = @import("../Entities.zig");
|
|
|
|
const Texture = @import("../textures.zig").Texture;
|
2022-07-17 12:54:29 +00:00
|
|
|
|
2022-07-21 09:10:07 +00:00
|
|
|
const vec = @import("../../math/vec.zig");
|
2022-07-23 10:00:45 +00:00
|
|
|
const mat = @import("../../math/mat.zig");
|
2022-07-21 09:10:07 +00:00
|
|
|
const Vec2f = vec.Vec2f;
|
|
|
|
const Vec4f = vec.Vec4f;
|
|
|
|
const Vec4i = vec.Vec4i;
|
|
|
|
const Vec2u = vec.Vec2u;
|
|
|
|
const Vec4u = vec.Vec4u;
|
2022-07-23 10:00:45 +00:00
|
|
|
const Mat4f = mat.Mat4f;
|
2022-07-17 12:54:29 +00:00
|
|
|
|
2022-07-18 10:14:55 +00:00
|
|
|
pub fn init(device: *const Device, swapchain: *Swapchain) !void {
|
2022-07-17 12:54:29 +00:00
|
|
|
errdefer {
|
2022-07-18 10:14:55 +00:00
|
|
|
std.debug.print("Failed to init MainPass", .{});
|
2022-07-20 05:41:34 +00:00
|
|
|
deinit(device);
|
2022-07-17 12:54:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// try ScreenBlit.init()
|
2022-07-18 10:14:55 +00:00
|
|
|
try DepthPass.init(device, swapchain);
|
2022-07-21 09:10:07 +00:00
|
|
|
try OpaquePass.init(device, swapchain);
|
2022-07-17 12:54:29 +00:00
|
|
|
// try Exposure.init();
|
|
|
|
// try UIPass.init();
|
|
|
|
}
|
|
|
|
|
2022-07-20 05:41:34 +00:00
|
|
|
pub fn deinit(device: *const Device) void {
|
2022-07-17 12:54:29 +00:00
|
|
|
// ScreenBlit.deinit()
|
2022-07-20 05:41:34 +00:00
|
|
|
DepthPass.deinit(device);
|
2022-07-21 09:10:07 +00:00
|
|
|
OpaquePass.deinit(device);
|
2022-07-17 12:54:29 +00:00
|
|
|
// Exposure.deinit();
|
|
|
|
// UIPass.deinit();
|
|
|
|
}
|
|
|
|
|
|
|
|
const pm_setup = ProfileMark.init("MainPass.setup");
|
2022-07-22 08:30:43 +00:00
|
|
|
pub fn setup(device: *const Device, swapchain: *const Swapchain) !void {
|
2022-07-17 12:54:29 +00:00
|
|
|
pm_setup.begin();
|
|
|
|
defer pm_setup.end();
|
|
|
|
|
|
|
|
DepthPass.setup();
|
2022-07-22 08:30:43 +00:00
|
|
|
try OpaquePass.setup(device, swapchain);
|
2022-07-17 12:54:29 +00:00
|
|
|
// Exposure.setup();
|
|
|
|
// UIPass.setup();
|
|
|
|
}
|
|
|
|
|
|
|
|
const pm_execute = ProfileMark.init("MainPass.execute");
|
2022-07-18 10:14:55 +00:00
|
|
|
pub fn execute(device: *const Device, swapchain: *Swapchain) !void {
|
2022-07-17 12:54:29 +00:00
|
|
|
pm_execute.begin();
|
|
|
|
defer pm_execute.end();
|
|
|
|
|
|
|
|
// todo: pt_trace convar check
|
2022-07-18 10:14:55 +00:00
|
|
|
try DepthPass.execute(device, swapchain);
|
2022-07-22 09:40:36 +00:00
|
|
|
try OpaquePass.execute(device, swapchain);
|
2022-07-17 12:54:29 +00:00
|
|
|
|
|
|
|
// Exposure.execute();
|
|
|
|
// UIPass.execute();
|
|
|
|
}
|
|
|
|
|
|
|
|
const DepthPass = struct {
|
2022-07-21 09:10:07 +00:00
|
|
|
const PushConstants = packed struct {
|
2022-07-23 10:00:45 +00:00
|
|
|
local_to_clip: Mat4f,
|
2022-07-21 09:10:07 +00:00
|
|
|
};
|
|
|
|
|
2022-07-17 12:54:29 +00:00
|
|
|
var s_render_pass: vk.RenderPass = undefined;
|
|
|
|
var s_pass: Pass = undefined;
|
|
|
|
|
2022-07-18 10:14:55 +00:00
|
|
|
pub fn init(device: *const Device, swapchain: *Swapchain) !void {
|
2022-07-20 05:41:34 +00:00
|
|
|
errdefer DepthPass.deinit(device);
|
2022-07-17 12:54:29 +00:00
|
|
|
|
2022-07-18 10:50:19 +00:00
|
|
|
const depth_buffer = Targets.getDepthBuffer(swapchain);
|
2022-07-17 12:54:29 +00:00
|
|
|
|
|
|
|
var info = RenderPass.Description{
|
2022-07-22 09:40:36 +00:00
|
|
|
.src_stage_mask = .{ .fragment_shader_bit = true },
|
|
|
|
.src_access_mask = .{ .shader_read_bit = true },
|
|
|
|
.dst_stage_mask = .{ .color_attachment_output_bit = true },
|
|
|
|
.dst_access_mask = .{ .color_attachment_write_bit = true },
|
2022-07-17 12:54:29 +00:00
|
|
|
};
|
2022-07-22 09:40:36 +00:00
|
|
|
|
2022-07-17 12:54:29 +00:00
|
|
|
info.attachments[0] = .{
|
|
|
|
.format = depth_buffer.format,
|
|
|
|
.layout = .depth_stencil_attachment_optimal,
|
2022-07-18 10:14:55 +00:00
|
|
|
.load = .clear,
|
|
|
|
.store = .store,
|
2022-07-17 12:54:29 +00:00
|
|
|
};
|
2022-07-18 10:14:55 +00:00
|
|
|
s_render_pass = try RenderPass.get(device, info);
|
2022-07-17 12:54:29 +00:00
|
|
|
|
2022-07-18 10:14:55 +00:00
|
|
|
var vert_bindings = [_]vk.VertexInputBindingDescription{
|
2022-07-17 12:54:29 +00:00
|
|
|
.{
|
|
|
|
.binding = 0,
|
2022-07-19 10:40:15 +00:00
|
|
|
.stride = @sizeOf(Vec2f),
|
2022-07-17 12:54:29 +00:00
|
|
|
.input_rate = .vertex,
|
|
|
|
},
|
|
|
|
};
|
2022-07-18 10:14:55 +00:00
|
|
|
var vert_attributes = [_]vk.VertexInputAttributeDescription{
|
2022-07-17 12:54:29 +00:00
|
|
|
.{
|
|
|
|
.binding = 0,
|
|
|
|
.format = .r32g32b32a32_sfloat,
|
|
|
|
.location = 0,
|
2022-07-18 10:14:55 +00:00
|
|
|
.offset = 0,
|
2022-07-17 12:54:29 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2022-07-21 09:10:07 +00:00
|
|
|
var sh: [2]vk.PipelineShaderStageCreateInfo = undefined;
|
|
|
|
sh[0] = try shaders.createModule(device, .{ .vertex_bit = true }, &resources.DepthOnly_vert, "VSMain");
|
|
|
|
defer shaders.deinitModule(device, sh[0].module);
|
|
|
|
sh[1] = try shaders.createModule(device, .{ .fragment_bit = true }, &resources.DepthOnly_frag, "PSMain");
|
|
|
|
defer shaders.deinitModule(device, sh[1].module);
|
|
|
|
|
|
|
|
const desc = Pass.Description{
|
2022-07-17 12:54:29 +00:00
|
|
|
.push_constant_bytes = @sizeOf(PushConstants),
|
2022-07-21 09:10:07 +00:00
|
|
|
.shaders = &sh,
|
2022-07-17 12:54:29 +00:00
|
|
|
.render_pass = s_render_pass,
|
2022-07-20 05:41:34 +00:00
|
|
|
.subpass = null,
|
2022-07-17 12:54:29 +00:00
|
|
|
.vert_layout = .{
|
2022-07-18 10:14:55 +00:00
|
|
|
.bindings = &vert_bindings,
|
|
|
|
.attributes = &vert_attributes,
|
2022-07-17 12:54:29 +00:00
|
|
|
},
|
|
|
|
.fixed_funcs = .{
|
2022-07-18 10:14:55 +00:00
|
|
|
.viewport = swapchain.getViewport(),
|
|
|
|
.scissor = swapchain.getRect(),
|
2022-07-17 12:54:29 +00:00
|
|
|
.topology = .triangle_list,
|
|
|
|
.polygon_mode = .fill,
|
|
|
|
.front_face = .counter_clockwise,
|
2022-07-18 10:14:55 +00:00
|
|
|
.cull_mode = .{ .back_bit = true },
|
2022-07-17 12:54:29 +00:00
|
|
|
.depth_compare_op = .less,
|
|
|
|
.scissor_on = false,
|
|
|
|
.depth_clamp = false,
|
|
|
|
.depth_test_enable = true,
|
|
|
|
.depth_write_enable = true,
|
|
|
|
},
|
2022-07-18 10:14:55 +00:00
|
|
|
};
|
2022-07-21 09:10:07 +00:00
|
|
|
|
|
|
|
try s_pass.init(device, &desc);
|
2022-07-17 12:54:29 +00:00
|
|
|
}
|
|
|
|
|
2022-07-20 05:41:34 +00:00
|
|
|
pub fn deinit(device: *const Device) void {
|
|
|
|
s_pass.deinit(device);
|
2022-07-17 12:54:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn setup() void {}
|
|
|
|
|
|
|
|
const pm_depth_execute = ProfileMark.init("DepthPass.execute");
|
2022-07-18 10:14:55 +00:00
|
|
|
pub fn execute(device: *const Device, swapchain: *Swapchain) !void {
|
2022-07-17 12:54:29 +00:00
|
|
|
pm_depth_execute.begin();
|
|
|
|
defer pm_depth_execute.end();
|
|
|
|
|
|
|
|
const camera = Camera.get();
|
2022-07-18 10:14:55 +00:00
|
|
|
const world_to_clip = camera.getWorldToClip(swapchain.getAspect());
|
2022-07-17 12:54:29 +00:00
|
|
|
|
2022-07-18 10:50:19 +00:00
|
|
|
const attachments = &[_]*Image{Targets.getDepthBuffer(swapchain)};
|
2022-07-17 12:54:29 +00:00
|
|
|
const rect = vk.Rect2D{
|
|
|
|
.offset = std.mem.zeroes(vk.Offset2D),
|
|
|
|
.extent = .{
|
|
|
|
.width = attachments[0].width,
|
|
|
|
.height = attachments[0].height,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2022-07-18 10:14:55 +00:00
|
|
|
const fbuf = try framebuffer.getOrAdd(device, attachments, rect.extent.width, rect.extent.height);
|
2022-07-17 12:54:29 +00:00
|
|
|
const cmd = try Command.Buffer.get(.graphics, device);
|
|
|
|
|
2022-07-18 10:14:55 +00:00
|
|
|
_ = try Image.State.depthAttachWrite(device, cmd, attachments[0]);
|
2022-07-17 12:54:29 +00:00
|
|
|
|
2022-07-18 10:14:55 +00:00
|
|
|
cmd.defaultViewport(device, swapchain);
|
|
|
|
cmd.bindPass(device, swapchain, &s_pass);
|
|
|
|
cmd.beginRenderPass(device, s_render_pass, fbuf, rect, &.{
|
2022-07-17 12:54:29 +00:00
|
|
|
.{
|
|
|
|
.depth_stencil = .{ .depth = 1.0, .stencil = 0.0 },
|
|
|
|
},
|
|
|
|
});
|
|
|
|
defer cmd.endRenderPass(device);
|
|
|
|
|
|
|
|
// TODO: draw entities/meshes
|
|
|
|
|
|
|
|
cmd.pushConstants(device, &s_pass, &PushConstants{ .local_to_clip = world_to_clip });
|
|
|
|
|
|
|
|
// TODO: imSys_drawDepth()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-07-18 10:14:55 +00:00
|
|
|
const OpaquePass = struct {
|
2022-07-21 09:10:07 +00:00
|
|
|
const Globals = packed struct {
|
2022-07-23 10:00:45 +00:00
|
|
|
g_WorldToClip: Mat4f,
|
2022-07-21 09:10:07 +00:00
|
|
|
g_Eye: Vec4f,
|
|
|
|
|
|
|
|
g_HdrEnabled: f32,
|
|
|
|
g_Whitepoint: f32,
|
|
|
|
g_DisplayNits: f32,
|
|
|
|
g_UiNits: f32,
|
|
|
|
|
|
|
|
g_RenderSize: Vec2u,
|
|
|
|
g_DisplaySize: Vec2u,
|
|
|
|
};
|
|
|
|
|
|
|
|
const PushConstants = packed struct {
|
2022-07-23 10:00:45 +00:00
|
|
|
kLocalToWorld: Mat4f,
|
|
|
|
kIMc0: Vec4f, // components of inverse matrix
|
2022-07-21 09:10:07 +00:00
|
|
|
kIMc1: Vec4f,
|
|
|
|
kIMc2: Vec4f,
|
|
|
|
kTexInds: Vec4u,
|
|
|
|
};
|
2022-07-18 10:14:55 +00:00
|
|
|
|
2022-07-21 09:10:07 +00:00
|
|
|
var s_render_pass: vk.RenderPass = undefined;
|
|
|
|
var s_pass: Pass = undefined;
|
|
|
|
var s_per_camera_buffer: Buffer.Set = undefined;
|
2022-07-18 10:14:55 +00:00
|
|
|
|
2022-07-21 09:10:07 +00:00
|
|
|
pub fn init(device: *const Device, swapchain: *Swapchain) !void {
|
|
|
|
errdefer OpaquePass.deinit(device);
|
|
|
|
|
|
|
|
const scene_buffer = Targets.getSceneBuffer(swapchain);
|
|
|
|
const depth_buffer = Targets.getDepthBuffer(swapchain);
|
2022-07-22 09:40:36 +00:00
|
|
|
|
2022-07-21 09:10:07 +00:00
|
|
|
var info = RenderPass.Description{
|
2022-07-22 09:40:36 +00:00
|
|
|
.src_stage_mask = .{ .fragment_shader_bit = true },
|
|
|
|
.dst_stage_mask = .{ .color_attachment_output_bit = true },
|
|
|
|
.src_access_mask = .{ .shader_read_bit = true },
|
|
|
|
.dst_access_mask = .{ .color_attachment_write_bit = true },
|
2022-07-21 09:10:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
info.attachments[0] = .{
|
|
|
|
.format = depth_buffer.format,
|
|
|
|
.layout = .depth_stencil_attachment_optimal,
|
|
|
|
.load = .load,
|
|
|
|
.store = .dont_care,
|
|
|
|
};
|
|
|
|
info.attachments[1] = .{
|
|
|
|
.format = scene_buffer.format,
|
|
|
|
.layout = .color_attachment_optimal,
|
|
|
|
.load = .clear,
|
|
|
|
.store = .store,
|
|
|
|
};
|
|
|
|
s_render_pass = try RenderPass.get(device, info);
|
|
|
|
|
2022-07-21 09:34:28 +00:00
|
|
|
try s_per_camera_buffer.init(device, @sizeOf(Globals), .{ .uniform_buffer_bit = true }, .cpuToGpu);
|
|
|
|
errdefer s_per_camera_buffer.release(device);
|
2022-07-21 09:10:07 +00:00
|
|
|
|
|
|
|
var sh: [2]vk.PipelineShaderStageCreateInfo = undefined;
|
|
|
|
sh[0] = try shaders.createModule(device, .{ .vertex_bit = true }, &resources.brush_vert, "VSMain");
|
|
|
|
defer shaders.deinitModule(device, sh[0].module);
|
|
|
|
sh[1] = try shaders.createModule(device, .{ .fragment_bit = true }, &resources.brush_frag, "PSMain");
|
|
|
|
defer shaders.deinitModule(device, sh[1].module);
|
|
|
|
|
|
|
|
// TODO: probably a few ways to make this more elegant using comptime?
|
|
|
|
const vert_bindings = [_]vk.VertexInputBindingDescription{
|
|
|
|
// positionWs
|
|
|
|
.{
|
|
|
|
.binding = 0,
|
|
|
|
.stride = @sizeOf(Vec4f),
|
|
|
|
.input_rate = .vertex,
|
|
|
|
},
|
|
|
|
// normalWS and lightmap index
|
|
|
|
.{
|
|
|
|
.binding = 1,
|
|
|
|
.stride = @sizeOf(Vec4f),
|
|
|
|
.input_rate = .vertex,
|
|
|
|
},
|
|
|
|
// uv0 and uv1
|
|
|
|
.{
|
|
|
|
.binding = 2,
|
|
|
|
.stride = @sizeOf(Vec4f),
|
|
|
|
.input_rate = .vertex,
|
|
|
|
},
|
|
|
|
// texture indices
|
|
|
|
.{
|
|
|
|
.binding = 3,
|
|
|
|
.stride = @sizeOf(Vec4i),
|
|
|
|
.input_rate = .vertex,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const vert_attributes = [_]vk.VertexInputAttributeDescription{
|
|
|
|
// positionOS
|
|
|
|
.{
|
|
|
|
.binding = 0,
|
|
|
|
.location = 0,
|
|
|
|
.format = .r32g32b32a32_sfloat,
|
|
|
|
.offset = 0,
|
|
|
|
},
|
|
|
|
// normalOS and lightmap index
|
|
|
|
.{
|
|
|
|
.binding = 1,
|
|
|
|
.location = 1,
|
|
|
|
.format = .r32g32b32a32_sfloat,
|
|
|
|
.offset = 0,
|
|
|
|
},
|
|
|
|
// uv0 and uv1
|
|
|
|
.{
|
|
|
|
.binding = 2,
|
|
|
|
.location = 2,
|
|
|
|
.format = .r32g32b32a32_sfloat,
|
|
|
|
.offset = 0,
|
|
|
|
},
|
|
|
|
// texture indices
|
|
|
|
.{
|
|
|
|
.binding = 3,
|
|
|
|
.location = 3,
|
2022-07-22 08:30:43 +00:00
|
|
|
.format = .r32g32b32a32_uint,
|
2022-07-21 09:10:07 +00:00
|
|
|
.offset = 0,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
var desc = Pass.Description{
|
|
|
|
.push_constant_bytes = @sizeOf(PushConstants),
|
|
|
|
.shaders = &sh,
|
|
|
|
.render_pass = s_render_pass,
|
|
|
|
.subpass = 0,
|
|
|
|
.vert_layout = .{
|
|
|
|
.bindings = &vert_bindings,
|
|
|
|
.attributes = &vert_attributes,
|
|
|
|
},
|
|
|
|
.fixed_funcs = .{
|
|
|
|
.viewport = swapchain.getViewport(),
|
|
|
|
.scissor = swapchain.getRect(),
|
|
|
|
.topology = .triangle_list,
|
|
|
|
.polygon_mode = .fill,
|
|
|
|
.front_face = .counter_clockwise,
|
|
|
|
.cull_mode = .{ .back_bit = true },
|
|
|
|
.depth_compare_op = .equal,
|
|
|
|
.scissor_on = false,
|
|
|
|
.depth_clamp = false,
|
|
|
|
.depth_test_enable = true,
|
|
|
|
.depth_write_enable = false,
|
2022-07-22 08:30:43 +00:00
|
|
|
.attachments = &[_]Pass.BlendState{
|
|
|
|
.{
|
|
|
|
.color_write_mask = .{ .r_bit = true, .g_bit = true, .b_bit = true, .a_bit = true },
|
|
|
|
.blend_enable = true,
|
|
|
|
.color_blend_op = .add,
|
|
|
|
.alpha_blend_op = .add,
|
|
|
|
},
|
|
|
|
},
|
2022-07-21 09:10:07 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
try s_pass.init(device, &desc);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn deinit(device: *const Device) void {
|
|
|
|
s_pass.deinit(device);
|
2022-07-21 09:34:28 +00:00
|
|
|
s_per_camera_buffer.release(device);
|
2022-07-21 09:10:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const pm_opaque_setup = ProfileMark.init("OpaquePass.setup");
|
2022-07-22 08:30:43 +00:00
|
|
|
pub fn setup(device: *const Device, swapchain: *const Swapchain) !void {
|
2022-07-21 09:10:07 +00:00
|
|
|
pm_opaque_setup.begin();
|
|
|
|
defer pm_opaque_setup.end();
|
|
|
|
|
|
|
|
// TODO: move this into some parameter provider standalone file, says kara
|
|
|
|
{
|
|
|
|
const camera = Camera.get();
|
2022-07-22 08:30:43 +00:00
|
|
|
const globals = Globals{
|
2022-07-21 09:10:07 +00:00
|
|
|
.g_WorldToClip = camera.getWorldToClip(Targets.getRenderAspect()),
|
|
|
|
.g_Eye = camera.position,
|
2022-07-22 08:30:43 +00:00
|
|
|
.g_HdrEnabled = 0, // TODO getHdrEnabled
|
2022-07-21 09:10:07 +00:00
|
|
|
.g_Whitepoint = 0, // TODO getWhitepoint
|
|
|
|
.g_DisplayNits = 0, // TODO getDisplayNitsMax
|
|
|
|
.g_UiNits = 0, // TODO getUiNits
|
|
|
|
.g_RenderSize = .{
|
|
|
|
.x = Targets.getRenderWidth(),
|
|
|
|
.y = Targets.getRenderHeight(),
|
|
|
|
},
|
|
|
|
.g_DisplaySize = .{
|
|
|
|
.x = Targets.getDisplayWidth(swapchain),
|
|
|
|
.y = Targets.getDisplayHeight(swapchain),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2022-07-22 08:30:43 +00:00
|
|
|
try s_per_camera_buffer.write(device, swapchain, @ptrCast([*]const u8, &globals)[0..@sizeOf(Globals)]);
|
2022-07-21 09:10:07 +00:00
|
|
|
}
|
|
|
|
|
2022-07-21 09:34:28 +00:00
|
|
|
Bindings.bindBuffer(settings.Bid.Globals.id, .uniform_buffer, s_per_camera_buffer.current(swapchain));
|
2022-07-21 09:10:07 +00:00
|
|
|
}
|
2022-07-18 10:14:55 +00:00
|
|
|
|
2022-07-22 09:40:36 +00:00
|
|
|
const pm_opaque_execute = ProfileMark.init("OpaquePass.execute");
|
|
|
|
pub fn execute(device: *const Device, swapchain: *Swapchain) !void {
|
|
|
|
pm_opaque_execute.begin();
|
|
|
|
defer pm_opaque_execute.end();
|
|
|
|
|
|
|
|
var attachments = [_]*Image{
|
|
|
|
Targets.getDepthBuffer(swapchain),
|
|
|
|
Targets.getSceneBuffer(swapchain),
|
|
|
|
};
|
|
|
|
const rect = vk.Rect2D{
|
|
|
|
.extent = .{
|
|
|
|
.width = attachments[0].width,
|
|
|
|
.height = attachments[0].height,
|
|
|
|
},
|
|
|
|
.offset = std.mem.zeroes(vk.Offset2D),
|
|
|
|
};
|
|
|
|
const fbuf = try framebuffer.getOrAdd(device, &attachments, rect.extent.width, rect.extent.height);
|
|
|
|
const cmdbuf = try Command.Buffer.get(.graphics, device);
|
|
|
|
|
|
|
|
_ = try Image.State.depthAttachWrite(device, cmdbuf, attachments[0]);
|
|
|
|
_ = try Image.State.colorAttachWrite(device, cmdbuf, attachments[1]);
|
|
|
|
// textable fragsampleall
|
|
|
|
|
|
|
|
cmdbuf.defaultViewport(device, swapchain);
|
|
|
|
cmdbuf.bindPass(device, swapchain, &s_pass);
|
|
|
|
const clear_values = [_]vk.ClearValue{
|
|
|
|
.{
|
|
|
|
.depth_stencil = .{ .depth = 1, .stencil = 0 },
|
|
|
|
},
|
|
|
|
.{
|
|
|
|
.color = .{ .float_32 = .{ 0, 0, 0, 1 } },
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
cmdbuf.beginRenderPass(device, s_render_pass, fbuf, rect, &clear_values);
|
|
|
|
defer cmdbuf.endRenderPass(device);
|
|
|
|
|
2022-07-23 10:00:45 +00:00
|
|
|
const ents = Entities.get();
|
|
|
|
for (ents.meshes.items) |mesh, i| {
|
2022-07-26 10:00:39 +00:00
|
|
|
const mAlbedo = Texture.get(ents.materials.items[i].albedo);
|
|
|
|
const mRome = Texture.get(ents.materials.items[i].rome);
|
|
|
|
const mNormal = Texture.get(ents.materials.items[i].normal);
|
2022-07-23 10:00:45 +00:00
|
|
|
|
|
|
|
const pc = PushConstants{
|
2022-07-26 10:00:39 +00:00
|
|
|
.kLocalToWorld = ents.matrices.items[i],
|
|
|
|
.kIMc0 = ents.inv_matrices.items[i].c0,
|
|
|
|
.kIMc1 = ents.inv_matrices.items[i].c1,
|
|
|
|
.kIMc2 = ents.inv_matrices.items[i].c2,
|
2022-07-23 10:00:45 +00:00
|
|
|
.kTexInds = .{
|
2022-07-26 10:00:39 +00:00
|
|
|
.x = if (mAlbedo) |albedo| albedo.slot.index else 0,
|
|
|
|
.y = if (mRome) |rome| rome.slot.index else 0,
|
|
|
|
.z = if (mNormal) |normal| normal.slot.index else 0,
|
2022-07-23 10:00:45 +00:00
|
|
|
.w = 0,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
cmdbuf.pushConstants(device, &s_pass, &pc);
|
|
|
|
cmdbuf.drawMesh(mesh.id);
|
|
|
|
}
|
2022-07-22 09:40:36 +00:00
|
|
|
|
|
|
|
const pc = PushConstants{
|
2022-07-23 10:00:45 +00:00
|
|
|
.kLocalToWorld = Mat4f.id,
|
2022-07-22 09:40:36 +00:00
|
|
|
.kIMc0 = Vec4f{ .x = 1, .y = 0, .z = 0, .w = 0 },
|
|
|
|
.kIMc1 = Vec4f{ .x = 0, .y = 1, .z = 0, .w = 0 },
|
|
|
|
.kIMc2 = Vec4f{ .x = 0, .y = 0, .z = 1, .w = 0 },
|
|
|
|
.kTexInds = Vec4u{},
|
|
|
|
};
|
|
|
|
|
|
|
|
cmdbuf.pushConstants(device, &s_pass, &pc);
|
|
|
|
}
|
2022-07-18 10:14:55 +00:00
|
|
|
};
|