Skip to content
Open
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 @@ -74,3 +74,4 @@ compile_commands.json

.DS_Store
Oxylus.xcodeproj
vsxmake2026
5 changes: 5 additions & 0 deletions Oxylus/include/Render/Renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ class Renderer {
auto init(this Renderer& self) -> std::expected<void, std::string>;
auto deinit(this Renderer& self) -> std::expected<void, std::string>;

auto new_frame(this Renderer& self) -> void;

auto new_instance(Scene& scene) -> std::unique_ptr<RendererInstance>;

private:
Expand All @@ -156,7 +158,10 @@ class Renderer {
bool initalized = false;

Texture sky_transmittance_lut_view;
vuk::Value<vuk::ImageAttachment> acquired_sky_transmittance_lut_view;
Texture sky_multiscatter_lut_view;
vuk::Value<vuk::ImageAttachment> acquired_sky_multiscatter_lut_view;
Texture hilbert_noise_lut;
vuk::Value<vuk::ImageAttachment> acquired_hilbert_noise_lut;
};
} // namespace ox
2 changes: 2 additions & 0 deletions Oxylus/include/Render/RendererInstance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ class RendererInstance {
auto update_vbgtao_info(this RendererInstance&) -> void;

private:
bool update_ran_this_frame = false; // Sanity Check

SharedResources shared_resources = {};
std::vector<RenderStageCallback> stage_callbacks;
std::vector<std::vector<usize>> before_callbacks;
Expand Down
3 changes: 2 additions & 1 deletion Oxylus/include/Scene/Scene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Scene {
flecs::world world;
ComponentDB component_db = {};

f32 physics_interval = 1.f / 60.f; // used only on initalization
f32 physics_interval = 1.f / 60.f; // used only on initialization

std::vector<GPU::TransformID> dirty_transforms = {};
SlotMap<GPU::Transforms, GPU::TransformID> transforms = {};
Expand All @@ -64,6 +64,7 @@ class Scene {
std::vector<GPU::Material> gpu_materials = {};

bool meshes_dirty = false;
bool force_material_update = true;
u32 mesh_instance_count = 0;
u32 max_meshlet_instance_count = 0;

Expand Down
6 changes: 1 addition & 5 deletions Oxylus/include/Scripting/LuaImGuiBindings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2506,8 +2506,6 @@ inline void init_enums(sol::state* lua) {
ImGuiTreeNodeFlags_Selected,
"Framed",
ImGuiTreeNodeFlags_Framed,
"AllowItemOverlap",
ImGuiTreeNodeFlags_AllowItemOverlap,
"NoTreePushOnOpen",
ImGuiTreeNodeFlags_NoTreePushOnOpen,
"NoAutoOpenOnLog",
Expand Down Expand Up @@ -2545,9 +2543,7 @@ inline void init_enums(sol::state* lua) {
"AllowDoubleClick",
ImGuiSelectableFlags_AllowDoubleClick,
"Disabled",
ImGuiSelectableFlags_Disabled,
"AllowItemOverlap",
ImGuiSelectableFlags_AllowItemOverlap);
ImGuiSelectableFlags_Disabled);
#pragma endregion Selectable Flags

#pragma region Popup Flags
Expand Down
1 change: 1 addition & 0 deletions Oxylus/include/UI/PayloadData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ struct PayloadData {
auto size() const -> usize { return sizeof(PayloadData); }

auto get_str() const -> std::string { return std::string(str); }
auto get_path() const -> std::filesystem::path { return std::filesystem::path(str); }

static auto from_payload(const ImGuiPayload* payload) -> const PayloadData* {
return reinterpret_cast<const PayloadData*>(payload->Data);
Expand Down
12 changes: 12 additions & 0 deletions Oxylus/src/Render/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,4 +411,16 @@ auto Renderer::deinit(this Renderer& self) -> std::expected<void, std::string> {

return {};
}

auto Renderer::new_frame(this Renderer& self) -> void {
self.acquired_sky_transmittance_lut_view = self.sky_transmittance_lut_view.acquire(
"sky_transmittance_lut",
vuk::Access::eComputeSampled
);
self.acquired_sky_multiscatter_lut_view = self.sky_multiscatter_lut_view.acquire(
"sky_multiscatter_lut",
vuk::Access::eComputeSampled
);
self.acquired_hilbert_noise_lut = self.hilbert_noise_lut.acquire("hilbert noise", vuk::eComputeSampled);
}
} // namespace ox
30 changes: 15 additions & 15 deletions Oxylus/src/Render/RendererInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,9 @@ auto RendererInstance::render(
) -> vuk::Value<vuk::ImageAttachment> {
ZoneScoped;

OX_ASSERT(self.update_ran_this_frame);
self.update_ran_this_frame = false;

OX_DEFER(&) {
self.clear_stages();
self.shared_resources.clear();
Expand Down Expand Up @@ -467,13 +470,13 @@ auto RendererInstance::render(
std::move(self.prepared_frame.spot_lights_buffer)
);

if (static_cast<bool>(RendererCVar::cvar_bloom_enable.get()))
if (RendererCVar::cvar_bloom_enable.as_bool())
self.gpu_scene_flags |= GPU::SceneFlags::HasBloom;
if (static_cast<bool>(RendererCVar::cvar_fxaa_enable.get()))
if (RendererCVar::cvar_fxaa_enable.as_bool())
self.gpu_scene_flags |= GPU::SceneFlags::HasFXAA;
if (static_cast<bool>(RendererCVar::cvar_vbgtao_enable.get()))
if (RendererCVar::cvar_vbgtao_enable.as_bool())
self.gpu_scene_flags |= GPU::SceneFlags::HasGTAO;
if (static_cast<bool>(RendererCVar::cvar_contact_shadows.get()))
if (RendererCVar::cvar_contact_shadows.as_bool())
self.gpu_scene_flags |= GPU::SceneFlags::HasContactShadows;

const auto debug_view = static_cast<GPU::DebugView>(RendererCVar::cvar_debug_view.get());
Expand Down Expand Up @@ -519,14 +522,6 @@ auto RendererInstance::render(
);
hiz_attachment = vuk::clear_image(std::move(hiz_attachment), vuk::DepthZero);

auto sky_transmittance_lut_attachment = self.renderer.sky_transmittance_lut_view.acquire(
"sky_transmittance_lut",
vuk::Access::eComputeSampled
);
auto sky_multiscatter_lut_attachment = self.renderer.sky_multiscatter_lut_view.acquire(
"sky_multiscatter_lut",
vuk::Access::eComputeSampled
);
auto sky_view_lut_attachment = vuk::declare_ia(
"sky_view_lut",
{.image_type = vuk::ImageType::e2D,
Expand All @@ -553,7 +548,7 @@ auto RendererInstance::render(
sky_aerial_perspective_attachment.same_format_as(sky_view_lut_attachment);
sky_aerial_perspective_attachment = vuk::clear_image(std::move(sky_aerial_perspective_attachment), vuk::Black<f32>);

auto hilbert_noise_lut_attachment = self.renderer.hilbert_noise_lut.acquire("hilbert noise", vuk::eComputeSampled);
auto hilbert_noise_lut_attachment = self.renderer.acquired_hilbert_noise_lut;

auto visbuffer_attachment = vuk::declare_ia(
"visbuffer",
Expand Down Expand Up @@ -815,10 +810,13 @@ auto RendererInstance::render(
);
}

auto sky_transmittance_lut_attachment = self.renderer.acquired_sky_transmittance_lut_view;
auto sky_multiscatter_lut_attachment = self.renderer.acquired_sky_multiscatter_lut_view;

if (scene_has_atmosphere && scene_has_directional_light) {
auto atmos_context = AtmosphereContext{
.sky_transmittance_lut_attachment = std::move(sky_transmittance_lut_attachment),
.sky_multiscatter_lut_attachment = std::move(sky_multiscatter_lut_attachment),
.sky_transmittance_lut_attachment = sky_transmittance_lut_attachment,
.sky_multiscatter_lut_attachment = sky_multiscatter_lut_attachment,
.sky_view_lut_attachment = std::move(sky_view_lut_attachment),
.sky_aerial_perspective_lut_attachment = std::move(sky_aerial_perspective_attachment),
};
Expand Down Expand Up @@ -1029,6 +1027,8 @@ auto RendererInstance::render(
auto RendererInstance::update(this RendererInstance& self, RendererInstanceUpdateInfo& info) -> void {
ZoneScoped;

self.update_ran_this_frame = true;

auto& asset_man = App::mod<AssetManager>();
auto& vk_context = *self.renderer.vk_context;

Expand Down
6 changes: 5 additions & 1 deletion Oxylus/src/Render/Vulkan/VkContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <vuk/runtime/vk/Query.hpp>

#include "Core/App.hpp"
#include "Render/Renderer.hpp"
#include "Render/RendererConfig.hpp"
#include "Render/Window.hpp"
#include "Utils/Profiler.hpp"
Expand Down Expand Up @@ -369,7 +370,7 @@ auto VkContext::create_context(this VkContext& self, const Window& window, bool
.create_persistent_descriptor_set(1, bindless_set_info, bindless_set_binding_flags);

auto& event_system = App::get_event_system();
auto sub_result = event_system.subscribe<WindowResizeEvent>([&self](const WindowResizeEvent& e){
auto sub_result = event_system.subscribe<WindowResizeEvent>([&self](const WindowResizeEvent& e) {
self.handle_resize(e.width, e.height);
});
if (!sub_result.has_value()) {
Expand Down Expand Up @@ -488,6 +489,9 @@ auto VkContext::new_frame(this VkContext& self) -> vuk::Value<vuk::ImageAttachme

self.swapchain_extent = glm::vec2(acquired_image->extent.width, acquired_image->extent.height);

if (App::has_mod<Renderer>())
App::mod<Renderer>().new_frame();

return acquired_image;
}

Expand Down
8 changes: 5 additions & 3 deletions Oxylus/src/Scene/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -656,9 +656,6 @@ auto Scene::init(this Scene& self, const std::string& name) -> void {
};
material->uv_offset = material->uv_offset + glm::vec2{uv_size.x * frame_x, uv_size.y * frame_y};
});

auto& asset_man = App::mod<AssetManager>();
asset_man.set_all_materials_dirty();
}

auto Scene::physics_init(this Scene& self) -> void {
Expand Down Expand Up @@ -825,6 +822,11 @@ auto Scene::runtime_update(this Scene& self, const Timestep& delta_time) -> void
return texture->get_view_index();
};

if (self.force_material_update) {
asset_man.set_all_materials_dirty();
self.force_material_update = false;
}

auto dirty_material_ids = asset_man.get_dirty_material_ids();
auto dirty_material_indices = std::vector<u32>();
for (const auto dirty_id : dirty_material_ids) {
Expand Down
2 changes: 0 additions & 2 deletions Oxylus/src/Scripting/LuaApplicationBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ sol::object lua_subscribe_helper(EventSystem& system, sol::function callback) {
sub_ptr->unsubscribe();
};

OX_LOG_INFO("Subscribed to event from lua");

return sol::make_object(lua, LuaScopedSubscription(std::move(unsub_func)));
}

Expand Down
2 changes: 1 addition & 1 deletion Oxylus/src/UI/AssetManagerViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ auto AssetManagerViewer::render(const char* id, bool* visible, AssetType default
);
UI::center_next_window(ImGuiCond_Appearing);
if (ImGui::Begin(id, visible, ImGuiWindowFlags_NoCollapse)) {
constexpr ImGuiTreeNodeFlags TREE_FLAGS = ImGuiTreeNodeFlags_SpanAvailWidth | ImGuiTreeNodeFlags_AllowItemOverlap |
constexpr ImGuiTreeNodeFlags TREE_FLAGS = ImGuiTreeNodeFlags_SpanAvailWidth | ImGuiTreeNodeFlags_AllowOverlap |
ImGuiTreeNodeFlags_Framed | ImGuiTreeNodeFlags_FramePadding |
ImGuiTreeNodeFlags_DefaultOpen;
constexpr i32 TABLE_COLUMNS_COUNT = 5;
Expand Down
14 changes: 8 additions & 6 deletions Oxylus/src/UI/ImGuiRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ vuk::Value<vuk::ImageAttachment> ImGuiRenderer::end_frame(VkContext& context, vu
}

auto texture_id = this->add_image(*font_texture);
OX_ASSERT(texture_id > 0);
texture->SetTexID(texture_id);
#else
auto acquired = false;
Expand Down Expand Up @@ -362,13 +363,14 @@ vuk::Value<vuk::ImageAttachment> ImGuiRenderer::end_frame(VkContext& context, vu
scissor.extent.height = static_cast<uint32_t>(clip_rect.w - clip_rect.y);
command_buffer.set_scissor(0, scissor);

command_buffer.bind_sampler(
0, 0, {.magFilter = vuk::Filter::eLinear, .minFilter = vuk::Filter::eLinear});
// NOTE: Dear ImGui assumes id 0 for textures means they are invalid textures.
// So we use indices for textures starting from 1 thus this -1 is required.
const auto index = im_cmd->GetTexID();
const auto& image = sis[index];
command_buffer.bind_image(0, 1, image);
const auto& image = sis[index - 1];

command_buffer.draw_indexed(im_cmd->ElemCount,
command_buffer.bind_image(0, 1, image)
.bind_sampler(0, 0, {.magFilter = vuk::Filter::eLinear, .minFilter = vuk::Filter::eLinear})
.draw_indexed(im_cmd->ElemCount,
1,
im_cmd->IdxOffset + global_idx_offset,
im_cmd->VtxOffset + global_vtx_offset,
Expand All @@ -389,7 +391,7 @@ vuk::Value<vuk::ImageAttachment> ImGuiRenderer::end_frame(VkContext& context, vu

ImTextureID ImGuiRenderer::add_image(vuk::Value<vuk::ImageAttachment>&& attachment) {
rendering_images.emplace_back(std::move(attachment));
return rendering_images.size() - 1;
return rendering_images.size();
}

ImTextureID ImGuiRenderer::add_image(const Texture& texture) {
Expand Down
Loading