Fixed March objects to reload on every change, and forced swapchain recreation on resize due to an issue on linux. Additonally, fixed printf errors

This commit is contained in:
tyromaniac 2025-03-31 13:00:33 -04:00
parent f3fa22c3c5
commit 8dbff0ec75
11 changed files with 131 additions and 14 deletions

View File

@ -6,7 +6,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(WIN32)
set(CMAKE_CXX_FLAGS "-D_DEBUG")
else()
set(CMAKE_CXX_FLAGS "-D_DEBUG -Wall -D_GLIBCXX_DEBUG -fsanitize=address")
set(CMAKE_CXX_FLAGS "-D_DEBUG -Wall -D_GLIBCXX_DEBUG -g -fsanitize=address")
endif()
project(Pleascach)

View File

@ -363,6 +363,10 @@ void Renderer::draw() {
auto sz = win.getDimensions();
/* re-upload objects if out-of-sync */
if(uniform_buffer->data_copy.n_objects != objects.size())
shader_buffer->upload(objects);
uniform_buffer->upload(UniformData{
.cam_pos = cam.pos,
.time = time,
@ -372,6 +376,8 @@ void Renderer::draw() {
.rad = rad,
});
command_buffer->bind(*pipeline);
command_buffer->command_buffer.setViewport(0, viewport);
command_buffer->command_buffer.setScissor(0, scissor);

View File

@ -45,7 +45,7 @@ struct ShaderBuffer {
}
inline void upload(const std::vector<Object>& scene) {
buffer->upload(reinterpret_cast<const uint8_t*>(scene.data()));
buffer->upload(reinterpret_cast<const uint8_t*>(scene.data()), scene.size() * sizeof(Object));
}
~ShaderBuffer() {

View File

@ -11,5 +11,6 @@ UniformBuffer::UniformBuffer(vk::PhysicalDevice phys_dev, vk::Device dev) {
}
void UniformBuffer::upload(const UniformData& data) {
data_copy = data;
buffer->upload(reinterpret_cast<const uint8_t*>(&data), sizeof(UniformData));
}

View File

@ -38,6 +38,7 @@ struct UniformBuffer {
UniformBuffer(vk::PhysicalDevice phys_dev, vk::Device dev);
std::unique_ptr<Buffer> buffer;
UniformData data_copy { 0.0 };
void upload(const UniformData& data);

View File

@ -35,9 +35,6 @@ static void scene_write(csys::String fname) {
March::writeFile(fname.m_String, __ren->objects, __ren->scene_map);
}
static void add_sphere() {
}
UI::UI(Renderer* ren) : ren(ren) {
__ren = ren;
@ -113,7 +110,7 @@ UI::UI(Renderer* ren) : ren(ren) {
auto& io = ImGui::GetIO();
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
console = std::make_unique<ImGuiConsole>("developer console");
console = new ImGuiConsole("developer console");
console->System().RegisterCommand("pause", "Pauses or unpauses the engine", [this]() {
this->ren->paused = !this->ren->paused;
console->System().Log(csys::ItemType::eINFO) << "Paused: " << (this->ren->paused ? "True" : "False") << csys::endl;
@ -219,7 +216,6 @@ void UI::render(vk::CommandBuffer cmd) {
}
UI::~UI() {
console.reset();
// dev.destroyDescriptorPool(desc_pool);
ImGui_ImplVulkan_Shutdown();

View File

@ -21,7 +21,7 @@ struct UI {
UI(Renderer* ren);
std::unique_ptr<ImGuiConsole> console;
ImGuiConsole* console;
void newFrame();
void render(vk::CommandBuffer cmd);

61
flake.lock generated Normal file
View File

@ -0,0 +1,61 @@
{
"nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1731533236,
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1743315132,
"narHash": "sha256-6hl6L/tRnwubHcA4pfUUtk542wn2Om+D4UnDhlDW9BE=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "52faf482a3889b7619003c0daec593a1912fddc1",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

31
flake.nix Normal file
View File

@ -0,0 +1,31 @@
{
description = "Flake for Vulkan and GLSLC Project";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
in {
devShells.default = pkgs.mkShell {
buildInputs = [
pkgs.git
pkgs.cmake
pkgs.vulkan-loader
pkgs.vulkan-headers
pkgs.vulkan-tools
pkgs.vulkan-validation-layers
pkgs.shaderc
pkgs.glfw3
];
shellHook = ''
echo "Vulkan development environment loaded."
'';
};
}
);
}

View File

@ -33,9 +33,8 @@ int main(int argc, char* argv[]) {
switch (event.tag) {
case InputEvent::Tag::eRESIZE:
Log::info("Event Processed: Resized to %dx%d\n", event.resize.width, event.resize.height);
/* no need to have a resize() function in the renderer, b/c swapchain images will be
* automatically marked out-of-date, and recreation will be triggered in our code
*/
ren.swapchain->recreate();
/* but still block while waiting for window to be opened again */
if (event.resize.height == 0 || event.resize.width == 0) {
int h = event.resize.height;

View File

@ -33,10 +33,32 @@ namespace Log {
level_txt = "[DEBUG] ";
break;
}
std::fprintf(stderr, level_txt);
std::fputs(level_txt, stderr);
std::fprintf(stderr, fmt.c_str(), args...);
}
static void print(MessageLevelBit level, const std::string& str) {
if (!(log_mask & level))
return;
/* appearently C++ doesn't have designated array indices :( */
const char* level_txt = "[UNKNOWN] ";
switch (level) {
case eERROR:
level_txt = "[ERROR] ";
break;
case eINFO:
level_txt = "[INFO] ";
break;
case eDEBUG:
level_txt = "[DEBUG] ";
break;
}
std::fputs(level_txt, stderr);
std::fprintf(stderr, "%s", str.c_str());
}
template<typename ...Args>
static void error(const std::string& fmt, Args... args) {
print(MessageLevelBit::eERROR, fmt, args...);