Compare commits

...
3 Commits
Author SHA1 Message Date
Dynamitos 7af42b9bad I dont know anymore 2026-04-06 20:35:02 +02:00
Dynamitos ace1554020 Fixing glfw package breaking changes 2026-04-06 17:29:55 +02:00
Dynamitos 87390db80d Adding more Window validation 2026-04-06 14:28:58 +02:00
8 changed files with 74 additions and 61 deletions
+10 -19
View File
@@ -59,7 +59,12 @@ target_include_directories(Engine PRIVATE src/Engine)
target_link_libraries(Engine PUBLIC Vulkan::Vulkan)
target_link_libraries(Engine PUBLIC GPUOpen::VulkanMemoryAllocator)
if(NOT APPLE)
target_link_libraries(Engine PUBLIC slang::slang-glslang)
# slang-glslang is a MODULE library (plugin) - copy it instead of linking
add_custom_command(TARGET Engine POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:slang::slang-glslang>
$<TARGET_FILE_DIR:Engine>
)
endif()
target_link_libraries(Engine PUBLIC EnTT::EnTT)
target_link_libraries(Engine PUBLIC glfw)
@@ -121,31 +126,17 @@ if(APPLE)
target_compile_options(Engine PUBLIC -Wno-gnu-anonymous-struct -Wno-nested-anon-types)
target_compile_options(Editor PUBLIC -Wno-gnu-anonymous-struct -Wno-nested-anon-types)
endif()
target_compile_options(Engine PUBLIC "$<$<CONFIG:DEBUG>:-DENABLE_VALIDATION>")
target_compile_options(Engine PUBLIC "$<$<CONFIG:DEBUG>:-DSEELE_DEBUG>")
add_subdirectory(src/)
#add_subdirectory(tests/)
if(WIN32)
add_custom_target(dll_copy ALL
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_RUNTIME_DLLS:Engine> $<TARGET_FILE_DIR:Editor>
COMMAND_EXPAND_LISTS
DEPENDS Editor)
elseif(APPLE)
add_custom_target(dll_copy ALL
COMMAND ${CMAKE_COMMAND} -E true
COMMAND_EXPAND_LISTS
DEPENDS Editor)
else()
add_custom_target(dll_copy ALL
COMMAND ${CMAKE_COMMAND} -E true)
add_custom_command(TARGET Engine POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_RUNTIME_DLLS:Engine> $<TARGET_FILE_DIR:Editor>)
endif()
add_custom_target(SeeleEngine ALL
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/res $<TARGET_FILE_DIR:Engine>
COMMAND_EXPAND_LISTS
DEPENDS Editor dll_copy)
add_custom_command(TARGET Engine POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/res $<TARGET_FILE_DIR:Engine>)
install(
TARGETS
-2
View File
@@ -1,2 +0,0 @@
(?<enum>[A-Z_]*) = [0-9]*,
case SE_${enum}:\nreturn VK_${enum};
-4
View File
@@ -1,4 +0,0 @@
// Hint files help the Visual Studio IDE interpret Visual C++ identifiers
// such as names of functions and macros.
// For more information see https://go.microsoft.com/fwlink/?linkid=865984
#define DECLARE_REF(x)
+1 -1
View File
@@ -4,7 +4,7 @@
#include "MinimalEngine.h"
#include "RenderTarget.h"
#include "Resources.h"
#define ENABLE_VALIDATION
namespace Seele {
namespace Gfx {
+25 -23
View File
@@ -17,6 +17,8 @@
#include "Shader.h"
#include "Window.h"
#include <GLFW/glfw3.h>
#include <GLFW/glfw3native.h>
#include <vulkan/vulkan_wayland.h>
#include <cstring>
#include <vulkan/vulkan_core.h>
@@ -142,9 +144,7 @@ Graphics::~Graphics() {
void Graphics::init(GraphicsInitializer initInfo) {
initInstance(initInfo);
#ifdef ENABLE_VALIDATION
setupDebugCallback();
#endif
pickPhysicalDevice();
createDevice(initInfo);
VmaAllocatorCreateInfo createInfo = {
@@ -667,6 +667,19 @@ Array<const char*> Graphics::getRequiredExtensions() {
unsigned int glfwExtensionCount = 0;
const char** glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount);
if (glfwExtensions == nullptr || glfwExtensionCount == 0) {
const char* glfwError = nullptr;
glfwGetError(&glfwError);
std::string message = "GLFW did not report required Vulkan instance extensions";
if (glfwError != nullptr) {
message += ": ";
message += glfwError;
}
extensions.add(VK_KHR_SURFACE_EXTENSION_NAME);
extensions.add(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
std::cerr << "Warning: " << message << ". Falling back to a default set of extensions." << std::endl;
}
for (unsigned int i = 0; i < glfwExtensionCount; i++) {
extensions.add(glfwExtensions[i]);
}
@@ -677,8 +690,16 @@ Array<const char*> Graphics::getRequiredExtensions() {
}
void Graphics::initInstance(GraphicsInitializer initInfo) {
glfwInit();
assert(glfwVulkanSupported());
#if defined(GLFW_WAYLAND_LIBDECOR) && defined(GLFW_WAYLAND_DISABLE_LIBDECOR)
// Work around libdecor runtime regressions on some Wayland stacks.
glfwInitHint(GLFW_WAYLAND_LIBDECOR, GLFW_WAYLAND_DISABLE_LIBDECOR);
#endif
if (!glfwInit()) {
throw std::runtime_error("Failed to initialize GLFW");
}
if (!glfwVulkanSupported()) {
throw std::runtime_error("GLFW: Vulkan not supported");
}
VkApplicationInfo appInfo = {
.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
.pNext = nullptr,
@@ -697,25 +718,6 @@ void Graphics::initInstance(GraphicsInitializer initInfo) {
extensions.add("VK_KHR_portability_enumeration");
#endif
Array<const char*> layers = initInfo.layers;
#ifdef ENABLE_VALIDATION
bool hasValidationLayer = false;
uint32 layerCount = 0;
vkEnumerateInstanceLayerProperties(&layerCount, nullptr);
Array<VkLayerProperties> availableLayers(layerCount);
vkEnumerateInstanceLayerProperties(&layerCount, availableLayers.data());
for (const auto& layer : availableLayers) {
if (std::strcmp(layer.layerName, "VK_LAYER_KHRONOS_validation") == 0) {
hasValidationLayer = true;
break;
}
}
if (hasValidationLayer) {
layers.add("VK_LAYER_KHRONOS_validation");
std::cerr << "Enabled Vulkan validation layer: VK_LAYER_KHRONOS_validation" << std::endl;
} else {
std::cerr << "ENABLE_VALIDATION is set, but VK_LAYER_KHRONOS_validation is unavailable on this system." << std::endl;
}
#endif
VkInstanceCreateInfo info = {
.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
.pNext = nullptr,
-2
View File
@@ -1,8 +1,6 @@
#include "Resources.h"
#include "Command.h"
#include "Enums.h"
#include "Graphics.h"
#include "Window.h"
using namespace Seele;
using namespace Seele::Vulkan;
+32 -5
View File
@@ -4,10 +4,12 @@
#include "Graphics.h"
#include "Resources.h"
#include <GLFW/glfw3.h>
#include <sstream>
using namespace Seele;
using namespace Seele::Vulkan;
double currentFrameDelta = 0;
double Gfx::getCurrentFrameDelta() { return currentFrameDelta; }
@@ -60,7 +62,18 @@ Window::Window(PGraphics graphics, const WindowCreateInfo& createInfo)
glfwGetMonitorContentScale(glfwGetPrimaryMonitor(), &contentScaleX, &contentScaleY);
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
GLFWwindow* handle = glfwCreateWindow(createInfo.width / contentScaleX, createInfo.height / contentScaleY, createInfo.title, nullptr, nullptr);
if (handle == nullptr) {
const char* glfwError = nullptr;
glfwGetError(&glfwError);
std::string message = "Failed to create GLFW window";
if (glfwError != nullptr) {
message += ": ";
message += glfwError;
}
throw std::runtime_error(message);
}
windowHandle = handle;
glfwSetWindowUserPointer(handle, this);
@@ -73,7 +86,17 @@ Window::Window(PGraphics graphics, const WindowCreateInfo& createInfo)
glfwSetFramebufferSizeCallback(handle, &glfwFramebufferResizeCallback);
// glfwSetWindowSizeCallback(handle, &glfwResizeCallback);
glfwCreateWindowSurface(instance, handle, nullptr, &surface);
VkResult surfaceResult = glfwCreateWindowSurface(instance, handle, nullptr, &surface);
if (surfaceResult != VK_SUCCESS || surface == VK_NULL_HANDLE) {
const char* glfwError = nullptr;
glfwGetError(&glfwError);
std::ostringstream oss;
oss << "Failed to create Vulkan surface via GLFW (VkResult=" << surfaceResult << ")";
if (glfwError != nullptr) {
oss << ": " << glfwError;
}
throw std::runtime_error(oss.str());
}
querySurface();
chooseSwapSurfaceFormat();
@@ -104,6 +127,9 @@ void Window::beginFrame() {
imageAvailableFences[currentSemaphoreIndex]->getHandle(), &currentImageIndex));
imageAvailableSemaphores[currentSemaphoreIndex]->encodeSignal();
imageAvailableFences[currentSemaphoreIndex]->submit();
// The image was reacquired, so the previous presentation using this image's
// renderDone semaphore has completed and it can be safely reused
renderingDoneSemaphores[currentImageIndex]->resolveSignal();
graphics->getGraphicsCommands()->getCommands()->waitForSemaphore(VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
imageAvailableSemaphores[currentSemaphoreIndex]);
static double start = glfwGetTime();
@@ -117,9 +143,9 @@ void Window::endFrame() {
swapChainTextures[currentImageIndex]->changeLayout(Gfx::SE_IMAGE_LAYOUT_PRESENT_SRC_KHR, Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, Gfx::SE_ACCESS_MEMORY_READ_BIT,
Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
renderingDoneSemaphores[currentSemaphoreIndex]->rotateSemaphore();
graphics->getGraphicsCommands()->submitCommands(renderingDoneSemaphores[currentSemaphoreIndex]);
VkSemaphore renderDoneHandle = renderingDoneSemaphores[currentSemaphoreIndex]->getHandle();
renderingDoneSemaphores[currentImageIndex]->rotateSemaphore();
graphics->getGraphicsCommands()->submitCommands(renderingDoneSemaphores[currentImageIndex]);
VkSemaphore renderDoneHandle = renderingDoneSemaphores[currentImageIndex]->getHandle();
VkPresentInfoKHR presentInfo = {
.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR,
.pNext = nullptr,
@@ -137,7 +163,7 @@ void Window::endFrame() {
} else {
VK_CHECK(r);
}
renderingDoneSemaphores[currentSemaphoreIndex]->resolveSignal();
renderingDoneSemaphores[currentImageIndex]->encodeSignal();
currentSemaphoreIndex = (currentSemaphoreIndex + 1) % Gfx::numFramesBuffered;
currentFrameIndex = currentSemaphoreIndex;
// graphics->waitDeviceIdle();
@@ -249,6 +275,7 @@ void Window::chooseSwapExtent() {
}
void Window::createSwapChain() {
graphics->waitDeviceIdle();
uint32 imageCount = Gfx::numFramesBuffered;
VkSwapchainCreateInfoKHR createInfo = {
.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR,
+6 -5
View File
@@ -1,9 +1,5 @@
{
"dependencies": [
{
"name": "vulkan"
},
"vulkan-loader",
{
"name": "vulkan-memory-allocator"
},
@@ -11,7 +7,12 @@
"stb",
"entt",
"freetype",
"glfw3",
{
"name": "glfw3",
"features": [
"wayland"
]
},
"glm",
"ktx",
"nlohmann-json",