Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ out/
compile_commands.json
.luarc.json
.notes/
xmake-requires.lock
8 changes: 4 additions & 4 deletions Lorr/Editor/EditorModule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ bool EditorModule::update(this EditorModule &self, f64 delta_time) {
}
}

self.render(swapchain_attachment->format, swapchain_attachment->extent);
self.render(window.swap_chain.value());

self.frame_profiler.measure(&device, delta_time);

Expand Down Expand Up @@ -509,7 +509,7 @@ static auto draw_profiler(EditorModule &self) -> void {
ImGui::End();
}

auto EditorModule::render(this EditorModule &self, vuk::Format format, vuk::Extent3D extent) -> bool {
auto EditorModule::render(this EditorModule &self, vuk::Swapchain &swap_chain) -> bool {
ZoneScoped;

auto *viewport = ImGui::GetMainViewport();
Expand Down Expand Up @@ -550,7 +550,7 @@ auto EditorModule::render(this EditorModule &self, vuk::Format format, vuk::Exte
ImGui::End();

for (auto &window : self.windows) {
window->do_render(format, extent);
window->do_render(swap_chain);
}

if (!self.active_project) {
Expand Down Expand Up @@ -620,7 +620,7 @@ bool ImGui::drag_vec(i32 id, void *data, usize components, ImGuiDataType data_ty
}

ImGui::PushID(static_cast<i32>(i));
value_changed |= ImGui::DragScalar("", data_type, data, 0.01f);
value_changed |= ImGui::DragScalar("", data_type, data, 0.1f);
ImGui::PopItemWidth();
ImGui::PopID();

Expand Down
2 changes: 1 addition & 1 deletion Lorr/Editor/EditorModule.hh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct EditorModule {

auto init(this EditorModule &) -> bool;
auto update(this EditorModule &, f64 delta_time) -> bool;
auto render(this EditorModule &, vuk::Format format, vuk::Extent3D extent) -> bool;
auto render(this EditorModule &, vuk::Swapchain &swap_chain) -> bool;
auto destroy(this EditorModule &) -> void;

template<typename T>
Expand Down
4 changes: 2 additions & 2 deletions Lorr/Editor/Window/AssetBrowserWindow.hh
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ struct AssetBrowserWindow : IWindow {
auto find_directory(this AssetBrowserWindow &, const fs::path &path) -> AssetDirectory *;

void render(this AssetBrowserWindow &);
void do_render(vuk::Format, vuk::Extent3D) override {
void do_render(vuk::Swapchain &) override {
render();
}
};
} // namespace lr
} // namespace led
4 changes: 2 additions & 2 deletions Lorr/Editor/Window/ConsoleWindow.hh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ struct ConsoleWindow : IWindow {
ConsoleWindow(std::string name_, bool open_ = true);

void render(this ConsoleWindow &);
void do_render(vuk::Format, vuk::Extent3D) override {
void do_render(vuk::Swapchain &) override {
render();
}
};
} // namespace lr
} // namespace led
4 changes: 2 additions & 2 deletions Lorr/Editor/Window/IWindow.hh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <imgui_internal.h>
#include <imgui_stdlib.h>

#include "Engine/Graphics/VulkanTypes.hh"
#include <vuk/runtime/vk/VkSwapchain.hpp>

namespace led {
struct IWindow {
Expand All @@ -14,7 +14,7 @@ struct IWindow {
IWindow(std::string name_, bool open_ = true): name(std::move(name_)), open(open_) {};

virtual ~IWindow() = default;
virtual auto do_render(vuk::Format format, vuk::Extent3D extent) -> void = 0;
virtual auto do_render(vuk::Swapchain &swap_chain) -> void = 0;
};

} // namespace lr
4 changes: 2 additions & 2 deletions Lorr/Editor/Window/InspectorWindow.hh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ struct InspectorWindow : IWindow {
InspectorWindow(std::string name_, bool open_ = true);

auto render(this InspectorWindow &) -> void;
void do_render(vuk::Format, vuk::Extent3D) override {
void do_render(vuk::Swapchain &) override {
render();
}
};
} // namespace lr
} // namespace led
4 changes: 2 additions & 2 deletions Lorr/Editor/Window/SceneBrowserWindow.hh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ struct SceneBrowserWindow : IWindow {
SceneBrowserWindow(std::string name_, bool open_ = true);

void render(this SceneBrowserWindow &);
void do_render(vuk::Format, vuk::Extent3D) override {
void do_render(vuk::Swapchain &) override {
render();
}
};
} // namespace lr
} // namespace led
12 changes: 7 additions & 5 deletions Lorr/Editor/Window/ViewportWindow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ static auto draw_tools(ViewportWindow &self) -> void {
}
}

static auto draw_viewport(ViewportWindow &self, vuk::Format format, vuk::Extent3D) -> void {
static auto draw_viewport(ViewportWindow &self, vuk::Swapchain &swap_chain) -> void {
auto &asset_man = lr::App::mod<lr::AssetManager>();
auto &editor = lr::App::mod<EditorModule>();
auto &scene_renderer = lr::App::mod<lr::SceneRenderer>();
Expand Down Expand Up @@ -242,13 +242,14 @@ static auto draw_viewport(ViewportWindow &self, vuk::Format format, vuk::Extent3
self.editor_camera.update(delta_time, target_velocity);
}

auto prepared_frame = active_scene->prepare_frame(scene_renderer, self.editor_camera); // NOLINT(cppcoreguidelines-slicing)
auto prepared_frame =
active_scene->prepare_frame(scene_renderer, swap_chain.images.size(), self.editor_camera); // NOLINT(cppcoreguidelines-slicing)

auto viewport_attachment_info = vuk::ImageAttachment{
.image_type = vuk::ImageType::e2D,
.usage = vuk::ImageUsageFlagBits::eSampled | vuk::ImageUsageFlagBits::eColorAttachment,
.extent = { .width = static_cast<u32>(window_size.x), .height = static_cast<u32>(window_size.y), .depth = 1 },
.format = format,
.format = swap_chain.images[0].format,
.sample_count = vuk::Samples::e1,
.view_type = vuk::ImageViewType::e2D,
.level_count = 1,
Expand All @@ -257,6 +258,7 @@ static auto draw_viewport(ViewportWindow &self, vuk::Format format, vuk::Extent3
auto viewport_attachment = vuk::declare_ia("viewport", viewport_attachment_info);
auto scene_render_info = lr::SceneRenderInfo{
.delta_time = delta_time,
.image_index = swap_chain.image_index,
.cull_flags = active_scene->get_cull_flags(),
.picking_texel = requested_texel_transform,
};
Expand Down Expand Up @@ -347,14 +349,14 @@ ViewportWindow::ViewportWindow(std::string name_, bool open_) : IWindow(std::mov
this->gizmo_op = ImGuizmo::TRANSLATE;
}

auto ViewportWindow::render(this ViewportWindow &self, vuk::Format format, vuk::Extent3D extent) -> void {
auto ViewportWindow::render(this ViewportWindow &self, vuk::Swapchain &swap_chain) -> void {
auto &editor = lr::App::mod<EditorModule>();
const auto should_render = editor.active_project && editor.active_project->active_scene_uuid;

ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0, 0.0));
if (ImGui::Begin(self.name.data())) {
if (should_render) {
draw_viewport(self, format, extent);
draw_viewport(self, swap_chain);
draw_tools(self);
}

Expand Down
8 changes: 4 additions & 4 deletions Lorr/Editor/Window/ViewportWindow.hh
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ struct ViewportWindow : IWindow {

ViewportWindow(std::string name_, bool open_ = true);

auto render(this ViewportWindow &, vuk::Format format, vuk::Extent3D extent) -> void;
void do_render(vuk::Format format, vuk::Extent3D extent) override {
render(format, extent);
auto render(this ViewportWindow &, vuk::Swapchain &swap_chain) -> void;
void do_render(vuk::Swapchain &swap_chain) override {
render(swap_chain);
}
};
} // namespace lr
} // namespace led
6 changes: 3 additions & 3 deletions Lorr/Engine/Asset/Asset.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1109,11 +1109,11 @@ auto AssetManager::load_texture(this AssetManager &self, const UUID &uuid, const
.addr_v = vuk::SamplerAddressMode::eRepeat,
.addr_w = vuk::SamplerAddressMode::eRepeat,
.compare_op = vuk::CompareOp::eNever,
.max_anisotropy = 8.0f,
.max_anisotropy = 1.0f,
.mip_lod_bias = 0.0f,
.min_lod = 0.0f,
.max_lod = static_cast<f32>(mip_level_count - 1),
.use_anisotropy = true,
.max_lod = 1000.0f,
.use_anisotropy = false,
};
auto sampler = Sampler::create(device, sampler_info).value();

Expand Down
3 changes: 2 additions & 1 deletion Lorr/Engine/Graphics/Slang/Compiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ auto SlangCompiler::new_session(const SlangSessionInfo &info) -> ls::option<Slan
{ .name = slang::CompilerOptionName::Capability, .value = { .kind = slang::CompilerOptionValueKind::String, .stringValue0 = "vk_mem_model" } },
{ .name = slang::CompilerOptionName::Capability, .value = { .kind = slang::CompilerOptionValueKind::String, .stringValue0 = "spvGroupNonUniformBallot" } },
{ .name = slang::CompilerOptionName::Capability, .value = { .kind = slang::CompilerOptionValueKind::String, .stringValue0 = "spvGroupNonUniformShuffle" } },
{ .name = slang::CompilerOptionName::Capability, .value = { .kind = slang::CompilerOptionValueKind::String, .stringValue0 = "spvImageGatherExtended" } },
//{ .name = slang::CompilerOptionName::DumpIntermediates, .value = { .kind = slang::CompilerOptionValueKind::Int, .intValue0 = 1 } },
//{ .name = slang::CompilerOptionName::EmitSeparateDebug, .value = { .kind = slang::CompilerOptionValueKind::Int, .intValue0 = 1 } },
};
Expand All @@ -357,7 +358,7 @@ auto SlangCompiler::new_session(const SlangSessionInfo &info) -> ls::option<Slan
.format = SLANG_SPIRV,
.profile = impl->global_session->findProfile("spirv_1_5"),
.flags = SLANG_TARGET_FLAG_GENERATE_SPIRV_DIRECTLY,
.floatingPointMode = SLANG_FLOATING_POINT_MODE_FAST,
//.floatingPointMode = SLANG_FLOATING_POINT_MODE_FAST,
.lineDirectiveMode = SLANG_LINE_DIRECTIVE_MODE_STANDARD,
.forceGLSLScalarBufferLayout = true,
.compilerOptionEntries = entries,
Expand Down
5 changes: 4 additions & 1 deletion Lorr/Engine/Graphics/Vulkan/Device.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ auto Device::init(this Device &self) -> bool {
instance_extensions.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
instance_extensions.push_back("VK_KHR_xcb_surface");
instance_extensions.push_back("VK_KHR_xlib_surface");
// instance_extensions.push_back("VK_KHR_wayland_surface");
instance_extensions.push_back("VK_KHR_wayland_surface");
#endif
#if LS_DEBUG
instance_extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
Expand Down Expand Up @@ -138,6 +138,7 @@ auto Device::init(this Device &self) -> bool {
vk12_features.vulkanMemoryModel = true;
vk12_features.vulkanMemoryModelDeviceScope = true;
vk12_features.storageBuffer8BitAccess = true;
vk12_features.uniformAndStorageBuffer8BitAccess = true;
vk12_features.scalarBlockLayout = true;
vk12_features.shaderInt8 = true;
vk12_features.shaderSubgroupExtendedTypes = true;
Expand All @@ -154,8 +155,10 @@ auto Device::init(this Device &self) -> bool {
vk10_features.features.vertexPipelineStoresAndAtomics = true;
vk10_features.features.fragmentStoresAndAtomics = true;
vk10_features.features.shaderInt64 = true;
vk10_features.features.shaderInt16 = true;
vk10_features.features.multiDrawIndirect = true;
vk10_features.features.samplerAnisotropy = true;
vk10_features.features.shaderImageGatherExtended = true;

VkPhysicalDeviceMaintenance8FeaturesKHR maintenance_8_features = {};
maintenance_8_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_8_FEATURES_KHR;
Expand Down
24 changes: 13 additions & 11 deletions Lorr/Engine/Resources/shaders/cull.slang
Original file line number Diff line number Diff line change
Expand Up @@ -88,23 +88,25 @@ public func test_frustum(in f32x4x4 mvp, in f32x3 aabb_center, in f32x3 aabb_ext
public func test_occlusion(
in ScreenAabb screen_aabb,
in Image2D<f32> hiz_image,
in Sampler hiz_sampler,
in constexpr bool ceiling
in Sampler hiz_sampler
) -> bool {
var hiz_size = u32x2(0.0);
var width: u32;
var height: u32;
var hiz_levels = 0;
hiz_image.GetDimensions(0, hiz_size.x, hiz_size.y, hiz_levels);
hiz_image.GetDimensions(0, width, height, hiz_levels);
let hiz_size = f32x2(width, height);

let min_uv = screen_aabb.min.xy;
let max_uv = screen_aabb.max.xy;
let min_texel = u32x2(max(min_uv * f32x2(hiz_size), 0.0));
let max_texel = u32x2(min(max_uv * f32x2(hiz_size), hiz_size - 1.0));
let min_uv = screen_aabb.min.xy * hiz_size;
let max_uv = screen_aabb.max.xy * hiz_size;
let min_texel = u32x2(max(min_uv, 0.0));
let max_texel = u32x2(min(max_uv, hiz_size - 1.0));

let size = max_texel - min_texel;
let max_size = max(size.x, size.y);
let mip = max(floor(log2(max_size)) - 1.0, 0.0);
var mip = max(floor(log2(max_size)), 0);

var uv = (min_uv + max_uv) * 0.5;
let uv = ((f32x2(min_texel) + f32x2(max_texel)) * 0.5f) / hiz_size;
let d = hiz_image.SampleLevel(hiz_sampler, uv, mip);
return screen_aabb.max.z < d;
constexpr static let EPSILON = 1e-7;
return screen_aabb.max.z <= d - EPSILON;
}
11 changes: 6 additions & 5 deletions Lorr/Engine/Resources/shaders/passes/cull_meshlets.slang
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ import debug_drawer;
[[shader("compute")]]
[[numthreads(CULLING_MESHLET_COUNT, 1, 1)]]
func cs_main(
uint3 thread_id : SV_DispatchThreadID,
uint group_thread_id : SV_GroupThreadID,
uint global_thread_id : SV_DispatchThreadID,
uniform CullFlags cull_flags
) -> void {
let meshlet_instance_count = visible_meshlet_instances_count[2];
let meshlet_instance_index = thread_id.x;
let meshlet_instance_index = global_thread_id;
if (meshlet_instance_index >= meshlet_instance_count) {
return;
}
Expand Down Expand Up @@ -61,7 +62,7 @@ func cs_main(

if (LATE && visible && cull_occlusion) {
if (let screen_aabb = project_aabb(mvp, camera.near_clip, bounds.aabb_center, bounds.aabb_extent)) {
visible = !test_occlusion(screen_aabb, hiz_image, hiz_sampler, false);
visible = !test_occlusion(screen_aabb, hiz_image, hiz_sampler);
#ifdef DEBUG_DRAW
if (visible) {
let ndc_aabb_max = screen_aabb.max.xy * 2.0 - 1.0;
Expand Down Expand Up @@ -94,9 +95,9 @@ func cs_main(

if (LATE) {
if (visible) {
__atomic_or(meshlet_instance_visibility_mask[mask_index], visibility_bit, MemoryOrder::AcquireRelease);
__atomic_or(meshlet_instance_visibility_mask[mask_index], visibility_bit, MemoryOrder::Relaxed);
} else {
__atomic_and(meshlet_instance_visibility_mask[mask_index], ~visibility_bit, MemoryOrder::AcquireRelease);
__atomic_and(meshlet_instance_visibility_mask[mask_index], ~visibility_bit, MemoryOrder::Relaxed);
}
}
}
16 changes: 12 additions & 4 deletions Lorr/Engine/Resources/shaders/passes/cull_triangles.slang
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import passes.visbuffer;
groupshared u32 base_index_shared;
groupshared u32 triangles_passed_shared;
groupshared mat4 model_view_proj_shared;
groupshared u32 meshlet_triangle_count_shared;

// https://github.com/GPUOpen-Effects/GeometryFX/blob/master/amd_geometryfx/src/Shaders/AMD_GeometryFX_Filtering.hlsl
// Parameters: vertices in UV space, viewport extent
Expand Down Expand Up @@ -123,12 +124,15 @@ func cs_main(
let meshlet_instance_index = visible_meshlet_instances_indices[visible_meshlet_instance_index];
let meshlet_instance = meshlet_instances[meshlet_instance_index];
let mesh_instance = mesh_instances[meshlet_instance.mesh_instance_index];
let mesh = meshes[mesh_instance.mesh_index];
let mesh_lod = mesh.lods[mesh_instance.lod_index];
let meshlet = mesh_lod.meshlets[meshlet_instance.meshlet_index];

if (local_index == 0) {
triangles_passed_shared = 0;

let mesh = meshes[mesh_instance.mesh_index];
let mesh_lod = mesh.lods[mesh_instance.lod_index];
let meshlet = mesh_lod.meshlets[meshlet_instance.meshlet_index];
meshlet_triangle_count_shared = meshlet.triangle_count;

let transform = transforms[mesh_instance.transform_index];
model_view_proj_shared = mul(camera.projection_view_mat, transform.world);
}
Expand All @@ -137,7 +141,11 @@ func cs_main(

var triangle_passed = false;
var active_triangle_index = 0;
if (local_index < meshlet.triangle_count) {
if (local_index < meshlet_triangle_count_shared) {
let mesh = meshes[mesh_instance.mesh_index];
let mesh_lod = mesh.lods[mesh_instance.lod_index];
let meshlet = mesh_lod.meshlets[meshlet_instance.meshlet_index];

let indices = meshlet.indices(mesh_lod, local_index);
let positions = meshlet.positions(mesh, indices);
triangle_passed = test_triangle(positions, camera.resolution, cull_flags, local_index);
Expand Down
Loading
Loading