fix redefination of descriptoSetLayout
parent
2f5fd63dd9
commit
7558e92ab3
|
@ -12,7 +12,7 @@ set(KTX_SOURCES
|
||||||
|
|
||||||
add_library(base STATIC ${BASE_SRC} ${KTX_SOURCES})
|
add_library(base STATIC ${BASE_SRC} ${KTX_SOURCES})
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
target_link_libraries(base ${Vulkan_LIBRARY} ${WINLIBS})
|
target_link_libraries(base ${Vulkan_LIBRARY})
|
||||||
else(WIN32)
|
else(WIN32)
|
||||||
target_link_libraries(base ${Vulkan_LIBRARY} ${XCB_LIBRARIES} ${WAYLAND_CLIENT_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
|
target_link_libraries(base ${Vulkan_LIBRARY} ${XCB_LIBRARIES} ${WAYLAND_CLIENT_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
|
||||||
endif(WIN32)
|
endif(WIN32)
|
|
@ -1,4 +1,4 @@
|
||||||
|
#pragma once
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,230 +0,0 @@
|
||||||
/*
|
|
||||||
* Vulkan Example base class
|
|
||||||
*
|
|
||||||
* Copyright (C) 2016 by Sascha Willems - www.saschawillems.de
|
|
||||||
*
|
|
||||||
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
#pragma comment(linker, "/subsystem:windows")
|
|
||||||
#include <windows.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <io.h>
|
|
||||||
#elif defined(VK_USE_PLATFORM_ANDROID_KHR)
|
|
||||||
#include <android/native_activity.h>
|
|
||||||
#include <android/asset_manager.h>
|
|
||||||
#include <android_native_app_glue.h>
|
|
||||||
#include <sys/system_properties.h>
|
|
||||||
#include "VulkanAndroid.h"
|
|
||||||
#elif defined(VK_USE_PLATFORM_WAYLAND_KHR)
|
|
||||||
#include <wayland-client.h>
|
|
||||||
#elif defined(_DIRECT2DISPLAY)
|
|
||||||
//
|
|
||||||
#elif defined(VK_USE_PLATFORM_XCB_KHR)
|
|
||||||
#include <xcb/xcb.h>
|
|
||||||
#elif defined(VK_USE_PLATFORM_MACOS_MVK)
|
|
||||||
#include <Cocoa/Cocoa.h>
|
|
||||||
#include <Carbon/Carbon.h>
|
|
||||||
#include <QuartzCore/CAMetalLayer.h>
|
|
||||||
#include <CoreVideo/CVDisplayLink.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <chrono>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
|
|
||||||
#define GLM_FORCE_RADIANS
|
|
||||||
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
|
|
||||||
#define GLM_ENABLE_EXPERIMENTAL
|
|
||||||
#include <glm/glm.hpp>
|
|
||||||
#include <string>
|
|
||||||
#include <sstream>
|
|
||||||
#include <array>
|
|
||||||
#include <numeric>
|
|
||||||
|
|
||||||
#include "vulkan/vulkan.h"
|
|
||||||
|
|
||||||
#include "VulkanTools.h"
|
|
||||||
#include "camera.hpp"
|
|
||||||
#include "keycodes.hpp"
|
|
||||||
|
|
||||||
#include "VulkanDevice.hpp"
|
|
||||||
#include "VulkanSwapChain.hpp"
|
|
||||||
|
|
||||||
#include "imgui/imgui.h"
|
|
||||||
|
|
||||||
class VulkanExampleBase
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
float fpsTimer = 0.0f;
|
|
||||||
uint32_t frameCounter = 0;
|
|
||||||
uint32_t destWidth;
|
|
||||||
uint32_t destHeight;
|
|
||||||
bool resizing = false;
|
|
||||||
void handleMouseMove(int32_t x, int32_t y);
|
|
||||||
PFN_vkCreateDebugReportCallbackEXT vkCreateDebugReportCallback;
|
|
||||||
PFN_vkDestroyDebugReportCallbackEXT vkDestroyDebugReportCallback;
|
|
||||||
VkDebugReportCallbackEXT debugReportCallback;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
VkInstance instance;
|
|
||||||
VkPhysicalDevice physicalDevice;
|
|
||||||
VkPhysicalDeviceProperties deviceProperties;
|
|
||||||
VkPhysicalDeviceFeatures deviceFeatures;
|
|
||||||
VkPhysicalDeviceMemoryProperties deviceMemoryProperties;
|
|
||||||
VkDevice device;
|
|
||||||
vks::VulkanDevice *vulkanDevice;
|
|
||||||
VkQueue queue;
|
|
||||||
VkFormat depthFormat;
|
|
||||||
VkCommandPool cmdPool;
|
|
||||||
VkRenderPass renderPass;
|
|
||||||
std::vector<VkFramebuffer>frameBuffers;
|
|
||||||
uint32_t currentBuffer = 0;
|
|
||||||
VkDescriptorPool descriptorPool;
|
|
||||||
VkPipelineCache pipelineCache;
|
|
||||||
VulkanSwapChain swapChain;
|
|
||||||
std::string title = "Vulkan Example";
|
|
||||||
std::string name = "vulkanExample";
|
|
||||||
void windowResize();
|
|
||||||
public:
|
|
||||||
|
|
||||||
uint32_t selectedPhysicalDeviceIndex = 0;
|
|
||||||
bool prepared = false;
|
|
||||||
|
|
||||||
Camera camera;
|
|
||||||
|
|
||||||
bool paused = false;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct DepthStencil {
|
|
||||||
VkImage image;
|
|
||||||
VkDeviceMemory mem;
|
|
||||||
VkImageView view;
|
|
||||||
} depthStencil;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// OS specific
|
|
||||||
#if defined(_WIN32)
|
|
||||||
HWND window;
|
|
||||||
HINSTANCE windowInstance;
|
|
||||||
#elif defined(VK_USE_PLATFORM_ANDROID_KHR)
|
|
||||||
// true if application has focused, false if moved to background
|
|
||||||
bool focused = false;
|
|
||||||
std::string androidProduct;
|
|
||||||
struct TouchPoint {
|
|
||||||
int32_t id;
|
|
||||||
float x;
|
|
||||||
float y;
|
|
||||||
bool down = false;
|
|
||||||
};
|
|
||||||
float pinchDist = 0.0f;
|
|
||||||
std::array<TouchPoint, 2> touchPoints;
|
|
||||||
#elif defined(VK_USE_PLATFORM_WAYLAND_KHR)
|
|
||||||
wl_display *display = nullptr;
|
|
||||||
wl_registry *registry = nullptr;
|
|
||||||
wl_compositor *compositor = nullptr;
|
|
||||||
wl_shell *shell = nullptr;
|
|
||||||
wl_seat *seat = nullptr;
|
|
||||||
wl_pointer *pointer = nullptr;
|
|
||||||
wl_keyboard *keyboard = nullptr;
|
|
||||||
wl_surface *surface = nullptr;
|
|
||||||
wl_shell_surface *shell_surface = nullptr;
|
|
||||||
bool quit = false;
|
|
||||||
|
|
||||||
#elif defined(_DIRECT2DISPLAY)
|
|
||||||
bool quit = false;
|
|
||||||
#elif defined(VK_USE_PLATFORM_XCB_KHR)
|
|
||||||
bool quit = false;
|
|
||||||
xcb_connection_t *connection;
|
|
||||||
xcb_screen_t *screen;
|
|
||||||
xcb_window_t window;
|
|
||||||
xcb_intern_atom_reply_t *atom_wm_delete_window;
|
|
||||||
#elif defined(VK_USE_PLATFORM_MACOS_MVK)
|
|
||||||
NSWindow* window;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(_WIN32)
|
|
||||||
HWND setupWindow(HINSTANCE hinstance, WNDPROC wndproc);
|
|
||||||
void handleMessages(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
|
||||||
#elif defined(VK_USE_PLATFORM_ANDROID_KHR)
|
|
||||||
static int32_t handleAppInput(struct android_app* app, AInputEvent* event);
|
|
||||||
static void handleAppCommand(android_app* app, int32_t cmd);
|
|
||||||
#elif defined(VK_USE_PLATFORM_WAYLAND_KHR)
|
|
||||||
wl_shell_surface *setupWindow();
|
|
||||||
void initWaylandConnection();
|
|
||||||
static void registryGlobalCb(void *data, struct wl_registry *registry,
|
|
||||||
uint32_t name, const char *interface, uint32_t version);
|
|
||||||
void registryGlobal(struct wl_registry *registry, uint32_t name,
|
|
||||||
const char *interface, uint32_t version);
|
|
||||||
static void registryGlobalRemoveCb(void *data, struct wl_registry *registry,
|
|
||||||
uint32_t name);
|
|
||||||
static void seatCapabilitiesCb(void *data, wl_seat *seat, uint32_t caps);
|
|
||||||
void seatCapabilities(wl_seat *seat, uint32_t caps);
|
|
||||||
static void pointerEnterCb(void *data, struct wl_pointer *pointer,
|
|
||||||
uint32_t serial, struct wl_surface *surface, wl_fixed_t sx,
|
|
||||||
wl_fixed_t sy);
|
|
||||||
static void pointerLeaveCb(void *data, struct wl_pointer *pointer,
|
|
||||||
uint32_t serial, struct wl_surface *surface);
|
|
||||||
static void pointerMotionCb(void *data, struct wl_pointer *pointer,
|
|
||||||
uint32_t time, wl_fixed_t sx, wl_fixed_t sy);
|
|
||||||
void pointerMotion(struct wl_pointer *pointer,
|
|
||||||
uint32_t time, wl_fixed_t sx, wl_fixed_t sy);
|
|
||||||
static void pointerButtonCb(void *data, struct wl_pointer *wl_pointer,
|
|
||||||
uint32_t serial, uint32_t time, uint32_t button, uint32_t state);
|
|
||||||
void pointerButton(struct wl_pointer *wl_pointer,
|
|
||||||
uint32_t serial, uint32_t time, uint32_t button, uint32_t state);
|
|
||||||
static void pointerAxisCb(void *data, struct wl_pointer *wl_pointer,
|
|
||||||
uint32_t time, uint32_t axis, wl_fixed_t value);
|
|
||||||
void pointerAxis(struct wl_pointer *wl_pointer,
|
|
||||||
uint32_t time, uint32_t axis, wl_fixed_t value);
|
|
||||||
static void keyboardKeymapCb(void *data, struct wl_keyboard *keyboard,
|
|
||||||
uint32_t format, int fd, uint32_t size);
|
|
||||||
static void keyboardEnterCb(void *data, struct wl_keyboard *keyboard,
|
|
||||||
uint32_t serial, struct wl_surface *surface, struct wl_array *keys);
|
|
||||||
static void keyboardLeaveCb(void *data, struct wl_keyboard *keyboard,
|
|
||||||
uint32_t serial, struct wl_surface *surface);
|
|
||||||
static void keyboardKeyCb(void *data, struct wl_keyboard *keyboard,
|
|
||||||
uint32_t serial, uint32_t time, uint32_t key, uint32_t state);
|
|
||||||
void keyboardKey(struct wl_keyboard *keyboard,
|
|
||||||
uint32_t serial, uint32_t time, uint32_t key, uint32_t state);
|
|
||||||
static void keyboardModifiersCb(void *data, struct wl_keyboard *keyboard,
|
|
||||||
uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched,
|
|
||||||
uint32_t mods_locked, uint32_t group);
|
|
||||||
|
|
||||||
#elif defined(_DIRECT2DISPLAY)
|
|
||||||
//
|
|
||||||
#elif defined(VK_USE_PLATFORM_XCB_KHR)
|
|
||||||
xcb_window_t setupWindow();
|
|
||||||
void initxcbConnection();
|
|
||||||
void handleEvent(const xcb_generic_event_t *event);
|
|
||||||
#elif defined(VK_USE_PLATFORM_MACOS_MVK)
|
|
||||||
NSWindow* setupWindow();
|
|
||||||
void mouseDragged(float x, float y);
|
|
||||||
void windowWillResize(float x, float y);
|
|
||||||
void windowDidResize();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
VulkanExampleBase();
|
|
||||||
virtual ~VulkanExampleBase();
|
|
||||||
|
|
||||||
void initVulkan();
|
|
||||||
|
|
||||||
virtual VkResult createInstance(bool enableValidation);
|
|
||||||
virtual void render() = 0;
|
|
||||||
virtual void windowResized();
|
|
||||||
virtual void setupFrameBuffer();
|
|
||||||
virtual void prepare();
|
|
||||||
virtual void fileDropped(std::string filename);
|
|
||||||
|
|
||||||
void initSwapchain();
|
|
||||||
void setupSwapChain();
|
|
||||||
|
|
||||||
void renderLoop();
|
|
||||||
void renderFrame();
|
|
||||||
};
|
|
|
@ -10,14 +10,8 @@ namespace PBR
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Material();
|
Material();
|
||||||
~Material()
|
~Material();
|
||||||
{
|
|
||||||
textures.environmentCube.destroy();
|
|
||||||
textures.irradianceCube.destroy();
|
|
||||||
textures.prefilteredCube.destroy();
|
|
||||||
textures.lutBrdf.destroy();
|
|
||||||
textures.empty.destroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
struct PushConstBlockMaterial {
|
struct PushConstBlockMaterial {
|
||||||
glm::vec4 baseColorFactor;
|
glm::vec4 baseColorFactor;
|
||||||
|
@ -103,5 +97,10 @@ namespace PBR
|
||||||
|
|
||||||
Material::~Material()
|
Material::~Material()
|
||||||
{
|
{
|
||||||
|
textures.environmentCube.destroy();
|
||||||
|
textures.irradianceCube.destroy();
|
||||||
|
textures.prefilteredCube.destroy();
|
||||||
|
textures.lutBrdf.destroy();
|
||||||
|
textures.empty.destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -105,26 +105,12 @@ void PlumageRender::renderMain::render()
|
||||||
renderGUI.updateUIOverlay();
|
renderGUI.updateUIOverlay();
|
||||||
}
|
}
|
||||||
|
|
||||||
//加入写到文件的函数
|
|
||||||
//swapChainImage = swapChain.images[frameIndex];
|
|
||||||
//outputImageSequeue(swapChainImage,filePath.imageSequenceFilePath);
|
|
||||||
|
|
||||||
|
|
||||||
uint32_t imageIndex;
|
uint32_t imageIndex;
|
||||||
|
|
||||||
VK_CHECK_RESULT(vkWaitForFences(VulkanBackend::VulkanFoundation::device, 1, &vkFoundation.waitFences[frameIndex], VK_TRUE, UINT64_MAX));
|
|
||||||
VkResult result = vkAcquireNextImageKHR(VulkanBackend::VulkanFoundation::device, VulkanBackend::VulkanFoundation::swapChain, UINT64_MAX, vkFoundation.renderCompleteSemaphores[frameIndex], VK_NULL_HANDLE, &imageIndex);
|
|
||||||
|
|
||||||
if (result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR || framebufferResized)
|
VK_CHECK_RESULT(vkWaitForFences(VulkanBackend::VulkanFoundation::device, 1, &vkFoundation.waitFences[frameIndex], VK_TRUE, UINT64_MAX));
|
||||||
{
|
|
||||||
framebufferResized = false;
|
framebufferResized = vkFoundation.acqureNextSwapchainImage(framebufferResized, imageIndex, frameIndex);
|
||||||
vkFoundation.recreateSwapChain();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else if (result != VK_SUCCESS && result != VK_SUBOPTIMAL_KHR)
|
|
||||||
{
|
|
||||||
throw std::runtime_error("failed to acquire swap chain image in drawFrame");
|
|
||||||
}
|
|
||||||
|
|
||||||
VK_CHECK_RESULT(vkResetFences(VulkanBackend::VulkanFoundation::device, 1, &vkFoundation.waitFences[frameIndex]));
|
VK_CHECK_RESULT(vkResetFences(VulkanBackend::VulkanFoundation::device, 1, &vkFoundation.waitFences[frameIndex]));
|
||||||
renderOutput.outputImageSequence();
|
renderOutput.outputImageSequence();
|
||||||
|
@ -137,44 +123,9 @@ void PlumageRender::renderMain::render()
|
||||||
memcpy(currentUB.params.mapped, &PBR::Material::shaderData, sizeof(PBR::Material::shaderData));
|
memcpy(currentUB.params.mapped, &PBR::Material::shaderData, sizeof(PBR::Material::shaderData));
|
||||||
memcpy(currentUB.skybox.mapped, &vkFoundation.shaderDataSkybox, sizeof(vkFoundation.shaderDataSkybox));
|
memcpy(currentUB.skybox.mapped, &vkFoundation.shaderDataSkybox, sizeof(vkFoundation.shaderDataSkybox));
|
||||||
|
|
||||||
const VkPipelineStageFlags waitDstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
vkFoundation.submitToGraphicQueue(frameIndex, currentBuffer);
|
||||||
VkSubmitInfo submitInfo{};
|
|
||||||
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
|
|
||||||
submitInfo.pWaitDstStageMask = &waitDstStageMask;
|
|
||||||
submitInfo.pWaitSemaphores = &vkFoundation.presentCompleteSemaphores[frameIndex];
|
|
||||||
submitInfo.waitSemaphoreCount = 1;
|
|
||||||
submitInfo.pSignalSemaphores = &vkFoundation.renderCompleteSemaphores[frameIndex];
|
|
||||||
submitInfo.signalSemaphoreCount = 1;
|
|
||||||
submitInfo.pCommandBuffers = &vkFoundation.commandbuffers[currentBuffer];
|
|
||||||
submitInfo.commandBufferCount = 1;
|
|
||||||
VK_CHECK_RESULT(vkQueueSubmit(vkFoundation.graphicQueue, 1, &submitInfo, vkFoundation.waitFences[frameIndex]));
|
|
||||||
|
|
||||||
//显示队列
|
vkFoundation.imageToQueuePresent(frameIndex, imageIndex, framebufferResized);
|
||||||
|
|
||||||
VkSemaphore signalSemaphores[] = { vkFoundation.renderCompleteSemaphores[frameIndex] };
|
|
||||||
|
|
||||||
VkPresentInfoKHR presentInfo{};
|
|
||||||
presentInfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
|
|
||||||
|
|
||||||
presentInfo.waitSemaphoreCount = 1;
|
|
||||||
presentInfo.pWaitSemaphores = signalSemaphores;
|
|
||||||
|
|
||||||
VkSwapchainKHR swapChains[] = { vkFoundation.swapChain };
|
|
||||||
presentInfo.swapchainCount = 1;
|
|
||||||
presentInfo.pSwapchains = swapChains;
|
|
||||||
presentInfo.pImageIndices = &imageIndex;
|
|
||||||
presentInfo.pResults = nullptr;
|
|
||||||
|
|
||||||
result = vkQueuePresentKHR(vkFoundation.presentQueue, &presentInfo);
|
|
||||||
if (result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR)
|
|
||||||
{
|
|
||||||
framebufferResized = false;
|
|
||||||
vkFoundation.recreateSwapChain();
|
|
||||||
}
|
|
||||||
else if (result != VK_SUCCESS)
|
|
||||||
{
|
|
||||||
throw std::runtime_error("failed to present swap chain image in drawFrame");
|
|
||||||
}
|
|
||||||
|
|
||||||
frameIndex += 1;
|
frameIndex += 1;
|
||||||
frameIndex %= PlumageRender::Setter::settings.MaxFrameInFlight;
|
frameIndex %= PlumageRender::Setter::settings.MaxFrameInFlight;
|
||||||
|
@ -206,15 +157,43 @@ void PlumageRender::renderMain::render()
|
||||||
|
|
||||||
void PlumageRender::renderMain::renderLoop(GLFWwindow* window)
|
void PlumageRender::renderMain::renderLoop(GLFWwindow* window)
|
||||||
{
|
{
|
||||||
while (!glfwWindowShouldClose(window))
|
if (PlumageRender::Setter::settings.headless)
|
||||||
{
|
{
|
||||||
glfwPollEvents();
|
uint32_t frameRange = PlumageRender::Setter::settings.endFrameIndex - PlumageRender::Setter::settings.startFrameCount;
|
||||||
render();
|
for (size_t i = 0; i < frameRange; i++)
|
||||||
|
{
|
||||||
|
drawFrame();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
while (!glfwWindowShouldClose(window))
|
||||||
|
{
|
||||||
|
glfwPollEvents();
|
||||||
|
drawFrame();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vkDeviceWaitIdle(VulkanBackend::VulkanFoundation::device);
|
vkDeviceWaitIdle(VulkanBackend::VulkanFoundation::device);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PlumageRender::renderMain::drawFrame()
|
||||||
|
{
|
||||||
|
auto tStart = std::chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
|
render();
|
||||||
|
|
||||||
|
frameCounter++;
|
||||||
|
auto tEnd = std::chrono::high_resolution_clock::now();
|
||||||
|
auto tDiff = std::chrono::duration<double, std::milli>(tEnd - tStart).count();
|
||||||
|
frameTimer = (float)tDiff / 1000.0f;
|
||||||
|
camera.update(frameTimer);
|
||||||
|
fpsTimer += (float)tDiff;
|
||||||
|
if (fpsTimer > 1000.0f) {
|
||||||
|
lastFPS = static_cast<uint32_t>((float)frameCounter * (1000.0f / fpsTimer));
|
||||||
|
fpsTimer = 0.0f;
|
||||||
|
frameCounter = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
|
||||||
#include <vulkan/vulkan.h>
|
#include <vulkan/vulkan.h>
|
||||||
#include "VulkanExampleBase.h"
|
|
||||||
#include "glTFModel.h"
|
#include "glTFModel.h"
|
||||||
#include "GLFW/glfw3.h"
|
#include "GLFW/glfw3.h"
|
||||||
#include <VulkanTexture.hpp>
|
#include <VulkanTexture.hpp>
|
||||||
|
@ -26,7 +26,7 @@
|
||||||
#include <VulkanUtils.hpp>
|
#include <VulkanUtils.hpp>
|
||||||
#include "renderSetter.h"
|
#include "renderSetter.h"
|
||||||
#include "vulkanFoundation.h"
|
#include "vulkanFoundation.h"
|
||||||
#include "camera.hpp"
|
|
||||||
|
|
||||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||||
#include "stb_image_write.h"
|
#include "stb_image_write.h"
|
||||||
|
@ -43,7 +43,6 @@ namespace PlumageRender
|
||||||
GLFWwindow* window;
|
GLFWwindow* window;
|
||||||
|
|
||||||
|
|
||||||
static Camera camera;
|
|
||||||
|
|
||||||
struct Models
|
struct Models
|
||||||
{
|
{
|
||||||
|
@ -62,6 +61,7 @@ namespace PlumageRender
|
||||||
glm::vec3 modelPos = glm::vec3(0.0f);
|
glm::vec3 modelPos = glm::vec3(0.0f);
|
||||||
|
|
||||||
uint32_t frameIndex = 0;
|
uint32_t frameIndex = 0;
|
||||||
|
uint32_t frameCounter = 0;
|
||||||
|
|
||||||
//VkImage swapChainImage;
|
//VkImage swapChainImage;
|
||||||
|
|
||||||
|
@ -75,20 +75,15 @@ namespace PlumageRender
|
||||||
|
|
||||||
|
|
||||||
uint32_t lastFPS = 0;
|
uint32_t lastFPS = 0;
|
||||||
static const float frameTimer = 1.0f;
|
float frameTimer = 1.0f;
|
||||||
|
float fpsTimer = 0.0f;
|
||||||
static int32_t animationIndex;
|
static int32_t animationIndex;
|
||||||
float animationTimer = 0.0f;
|
float animationTimer = 0.0f;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
renderMain();
|
renderMain();
|
||||||
~renderMain()
|
~renderMain();
|
||||||
{
|
|
||||||
models.scene.destroy(VulkanBackend::VulkanFoundation::device);
|
|
||||||
models.skybox.destroy(VulkanBackend::VulkanFoundation::device);
|
|
||||||
|
|
||||||
|
|
||||||
delete gui;
|
|
||||||
}
|
|
||||||
|
|
||||||
void initWindow(int width, int height);
|
void initWindow(int width, int height);
|
||||||
static void framebufferResizeCallback(GLFWwindow* window, int width, int height);
|
static void framebufferResizeCallback(GLFWwindow* window, int width, int height);
|
||||||
|
@ -100,6 +95,7 @@ namespace PlumageRender
|
||||||
|
|
||||||
virtual void render();
|
virtual void render();
|
||||||
void renderLoop(GLFWwindow* window);
|
void renderLoop(GLFWwindow* window);
|
||||||
|
void drawFrame();
|
||||||
private:
|
private:
|
||||||
|
|
||||||
PlumageRender::RenderInput renderInput;
|
PlumageRender::RenderInput renderInput;
|
||||||
|
@ -118,6 +114,20 @@ namespace PlumageRender
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
renderMain::renderMain()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
renderMain::~renderMain()
|
||||||
|
{
|
||||||
|
models.scene.destroy(VulkanBackend::VulkanFoundation::device);
|
||||||
|
models.skybox.destroy(VulkanBackend::VulkanFoundation::device);
|
||||||
|
|
||||||
|
|
||||||
|
delete gui;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -83,6 +83,10 @@ void PlumageRender::RenderOutput::writeImageToFile(std::string filePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Source for the copy is the last rendered swapchain image
|
// Source for the copy is the last rendered swapchain image
|
||||||
|
if (PlumageRender::Setter::settings.headless)
|
||||||
|
{
|
||||||
|
VkImage srcImage = VulkanBackend::VulkanFoundation::colorAttachment.image;
|
||||||
|
}
|
||||||
VkImage srcImage = VulkanBackend::VulkanFoundation::swapChainImages[PlumageRender::renderMain::currentBuffer];
|
VkImage srcImage = VulkanBackend::VulkanFoundation::swapChainImages[PlumageRender::renderMain::currentBuffer];
|
||||||
|
|
||||||
// Create the linear tiled destination image to copy to and to read the memory from
|
// Create the linear tiled destination image to copy to and to read the memory from
|
||||||
|
@ -128,18 +132,22 @@ void PlumageRender::RenderOutput::writeImageToFile(std::string filePath)
|
||||||
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||||
VkImageSubresourceRange{ VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 });
|
VkImageSubresourceRange{ VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 });
|
||||||
|
|
||||||
// Transition swapchain image from present to transfer source layout
|
if (!PlumageRender::Setter::settings.headless)
|
||||||
vks::tools::insertImageMemoryBarrier(
|
{
|
||||||
copyCmd,
|
// Transition swapchain image from present to transfer source layout
|
||||||
srcImage,
|
vks::tools::insertImageMemoryBarrier(
|
||||||
VK_ACCESS_MEMORY_READ_BIT,
|
copyCmd,
|
||||||
VK_ACCESS_TRANSFER_READ_BIT,
|
srcImage,
|
||||||
//VK_IMAGE_LAYOUT_UNDEFINED,
|
VK_ACCESS_MEMORY_READ_BIT,
|
||||||
VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
|
VK_ACCESS_TRANSFER_READ_BIT,
|
||||||
VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
|
//VK_IMAGE_LAYOUT_UNDEFINED,
|
||||||
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
|
||||||
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
|
||||||
VkImageSubresourceRange{ VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 });
|
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||||
|
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||||
|
VkImageSubresourceRange{ VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 });
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// If source and destination support blit we'll blit as this also does automatic format conversion (e.g. from BGR to RGB)
|
// If source and destination support blit we'll blit as this also does automatic format conversion (e.g. from BGR to RGB)
|
||||||
if (supportsBlit)
|
if (supportsBlit)
|
||||||
|
|
|
@ -178,12 +178,12 @@ void PlumageRender::PlumageGUI::updateUIOverlay()
|
||||||
if (gui->vertexBuffer.buffer) {
|
if (gui->vertexBuffer.buffer) {
|
||||||
gui->vertexBuffer.destroy();
|
gui->vertexBuffer.destroy();
|
||||||
}
|
}
|
||||||
gui->vertexBuffer.create(PlumageRender::renderMain::vkFoundation.vulkanDevice, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, vertexBufferSize);
|
gui->vertexBuffer.create(VulkanBackend::VulkanFoundation::vulkanDevice, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, vertexBufferSize);
|
||||||
gui->vertexBuffer.count = imDrawData->TotalVtxCount;
|
gui->vertexBuffer.count = imDrawData->TotalVtxCount;
|
||||||
if (gui->indexBuffer.buffer) {
|
if (gui->indexBuffer.buffer) {
|
||||||
gui->indexBuffer.destroy();
|
gui->indexBuffer.destroy();
|
||||||
}
|
}
|
||||||
gui->indexBuffer.create(PlumageRender::renderMain::vkFoundation.vulkanDevice, VK_BUFFER_USAGE_INDEX_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, indexBufferSize);
|
gui->indexBuffer.create(VulkanBackend::VulkanFoundation::vulkanDevice, VK_BUFFER_USAGE_INDEX_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, indexBufferSize);
|
||||||
gui->indexBuffer.count = imDrawData->TotalIdxCount;
|
gui->indexBuffer.count = imDrawData->TotalIdxCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,12 +209,12 @@ void PlumageRender::PlumageGUI::updateUIOverlay()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (updateCBs) {
|
if (updateCBs) {
|
||||||
vkDeviceWaitIdle(PlumageRender::renderMain::vkFoundation.device);
|
vkDeviceWaitIdle(VulkanBackend::VulkanFoundation::device);
|
||||||
PlumageRender::renderMain::vkFoundation.createCommandBuffer();
|
vkFoundation.createCommandBuffer();
|
||||||
vkDeviceWaitIdle(PlumageRender::renderMain::vkFoundation.device);
|
vkDeviceWaitIdle(VulkanBackend::VulkanFoundation::device);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (updateShaderParams) {
|
if (updateShaderParams) {
|
||||||
PlumageRender::renderMain::vkFoundation.createCommandBuffer();
|
vkFoundation.createCommandBuffer();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
#include "ui.hpp"
|
#include "ui.hpp"
|
||||||
#include "VulkanDevice.hpp"
|
#include "VulkanDevice.hpp"
|
||||||
|
#include "vulkanFoundation.h"
|
||||||
#include "renderSetter.h"
|
#include "renderSetter.h"
|
||||||
#include "renderIO.h"
|
#include "renderIO.h"
|
||||||
#include "render.h"
|
#include "render.h"
|
||||||
|
@ -27,6 +27,7 @@ namespace PlumageRender
|
||||||
static DebugView debugView;
|
static DebugView debugView;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1047,6 +1047,13 @@ bool VulkanBackend::VulkanFoundation::hasStencilComponent(VkFormat format)
|
||||||
|
|
||||||
|
|
||||||
void VulkanBackend::VulkanFoundation::createDescriptorSetLayout()
|
void VulkanBackend::VulkanFoundation::createDescriptorSetLayout()
|
||||||
|
{
|
||||||
|
createSceneDescriptorSetLayout();
|
||||||
|
createMaterialDescriptorSetLayout();
|
||||||
|
createNodeDescriptorSetLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
void VulkanBackend::VulkanFoundation::createSceneDescriptorSetLayout()
|
||||||
{
|
{
|
||||||
// scene,场景的资源描述符
|
// scene,场景的资源描述符
|
||||||
std::vector<VkDescriptorSetLayoutBinding> setLayoutBindings = {
|
std::vector<VkDescriptorSetLayoutBinding> setLayoutBindings = {
|
||||||
|
@ -1061,7 +1068,10 @@ void VulkanBackend::VulkanFoundation::createDescriptorSetLayout()
|
||||||
descriptorSetLayoutCI.pBindings = setLayoutBindings.data();
|
descriptorSetLayoutCI.pBindings = setLayoutBindings.data();
|
||||||
descriptorSetLayoutCI.bindingCount = static_cast<uint32_t>(setLayoutBindings.size());
|
descriptorSetLayoutCI.bindingCount = static_cast<uint32_t>(setLayoutBindings.size());
|
||||||
VK_CHECK_RESULT(vkCreateDescriptorSetLayout(device, &descriptorSetLayoutCI, nullptr, &descriptorSetLayouts.scene));
|
VK_CHECK_RESULT(vkCreateDescriptorSetLayout(device, &descriptorSetLayoutCI, nullptr, &descriptorSetLayouts.scene));
|
||||||
|
}
|
||||||
|
|
||||||
|
void VulkanBackend::VulkanFoundation::createMaterialDescriptorSetLayout()
|
||||||
|
{
|
||||||
// 材质或材质采样器的资源描述符
|
// 材质或材质采样器的资源描述符
|
||||||
std::vector<VkDescriptorSetLayoutBinding> setLayoutBindings = {
|
std::vector<VkDescriptorSetLayoutBinding> setLayoutBindings = {
|
||||||
{ 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr },
|
{ 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr },
|
||||||
|
@ -1075,7 +1085,10 @@ void VulkanBackend::VulkanFoundation::createDescriptorSetLayout()
|
||||||
descriptorSetLayoutCI.pBindings = setLayoutBindings.data();
|
descriptorSetLayoutCI.pBindings = setLayoutBindings.data();
|
||||||
descriptorSetLayoutCI.bindingCount = static_cast<uint32_t>(setLayoutBindings.size());
|
descriptorSetLayoutCI.bindingCount = static_cast<uint32_t>(setLayoutBindings.size());
|
||||||
VK_CHECK_RESULT(vkCreateDescriptorSetLayout(device, &descriptorSetLayoutCI, nullptr, &descriptorSetLayouts.material));
|
VK_CHECK_RESULT(vkCreateDescriptorSetLayout(device, &descriptorSetLayoutCI, nullptr, &descriptorSetLayouts.material));
|
||||||
|
}
|
||||||
|
|
||||||
|
void VulkanBackend::VulkanFoundation::createNodeDescriptorSetLayout()
|
||||||
|
{
|
||||||
// 模型结点或矩阵的资源描述符
|
// 模型结点或矩阵的资源描述符
|
||||||
std::vector<VkDescriptorSetLayoutBinding> setLayoutBindings = {
|
std::vector<VkDescriptorSetLayoutBinding> setLayoutBindings = {
|
||||||
{ 0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1, VK_SHADER_STAGE_VERTEX_BIT, nullptr },
|
{ 0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1, VK_SHADER_STAGE_VERTEX_BIT, nullptr },
|
||||||
|
@ -1775,7 +1788,7 @@ void VulkanBackend::VulkanFoundation::createCommandBuffer()
|
||||||
// User interface
|
// User interface
|
||||||
if (!PlumageRender::Setter::settings.headless)
|
if (!PlumageRender::Setter::settings.headless)
|
||||||
{
|
{
|
||||||
gui->draw(currentCB);
|
plumageGui.gui->draw(currentCB);
|
||||||
}
|
}
|
||||||
|
|
||||||
vkCmdEndRenderPass(currentCB);
|
vkCmdEndRenderPass(currentCB);
|
||||||
|
@ -1889,6 +1902,80 @@ void VulkanBackend::VulkanFoundation::createFenceAndSemaphore()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VulkanBackend::VulkanFoundation::DestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT debugMessenger, const VkAllocationCallbacks* pAllocator)
|
||||||
|
{
|
||||||
|
auto func = (PFN_vkDestroyDebugUtilsMessengerEXT)vkGetInstanceProcAddr(instance, "vkDestroyDebugUtilsMessengerEXT");
|
||||||
|
|
||||||
|
if (func != nullptr)
|
||||||
|
{
|
||||||
|
func(instance, debugMessenger, pAllocator);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool VulkanBackend::VulkanFoundation::acqureNextSwapchainImage(bool framebuffeerResized,uint32_t imageIndex,uint32_t frameIndex)
|
||||||
|
{
|
||||||
|
VkResult result = vkAcquireNextImageKHR(device, swapChain, UINT64_MAX, renderCompleteSemaphores[frameIndex], VK_NULL_HANDLE, &imageIndex);
|
||||||
|
|
||||||
|
if (result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR || framebuffeerResized)
|
||||||
|
{
|
||||||
|
framebuffeerResized = false;
|
||||||
|
recreateSwapChain();
|
||||||
|
return framebuffeerResized;
|
||||||
|
}
|
||||||
|
else if (result != VK_SUCCESS && result != VK_SUBOPTIMAL_KHR)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("failed to acquire swap chain image in drawFrame");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void VulkanBackend::VulkanFoundation::submitToGraphicQueue(uint32_t frameIndex, uint32_t currentBuffer)
|
||||||
|
{
|
||||||
|
const VkPipelineStageFlags waitDstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
||||||
|
VkSubmitInfo submitInfo{};
|
||||||
|
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
|
||||||
|
submitInfo.pWaitDstStageMask = &waitDstStageMask;
|
||||||
|
submitInfo.pWaitSemaphores = &presentCompleteSemaphores[frameIndex];
|
||||||
|
submitInfo.waitSemaphoreCount = 1;
|
||||||
|
submitInfo.pSignalSemaphores = &renderCompleteSemaphores[frameIndex];
|
||||||
|
submitInfo.signalSemaphoreCount = 1;
|
||||||
|
submitInfo.pCommandBuffers = &commandbuffers[currentBuffer];
|
||||||
|
submitInfo.commandBufferCount = 1;
|
||||||
|
VK_CHECK_RESULT(vkQueueSubmit(graphicQueue, 1, &submitInfo, waitFences[frameIndex]));
|
||||||
|
}
|
||||||
|
|
||||||
|
void VulkanBackend::VulkanFoundation::imageToQueuePresent(uint32_t frameIndex,uint32_t imageIndex,bool framebufferResized)
|
||||||
|
{
|
||||||
|
//显示队列
|
||||||
|
VkSemaphore signalSemaphores[] = { renderCompleteSemaphores[frameIndex] };
|
||||||
|
|
||||||
|
VkPresentInfoKHR presentInfo{};
|
||||||
|
presentInfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
|
||||||
|
|
||||||
|
presentInfo.waitSemaphoreCount = 1;
|
||||||
|
presentInfo.pWaitSemaphores = signalSemaphores;
|
||||||
|
|
||||||
|
VkSwapchainKHR swapChains[] = { swapChain };
|
||||||
|
presentInfo.swapchainCount = 1;
|
||||||
|
presentInfo.pSwapchains = swapChains;
|
||||||
|
presentInfo.pImageIndices = &imageIndex;
|
||||||
|
presentInfo.pResults = nullptr;
|
||||||
|
|
||||||
|
VkResult result = vkQueuePresentKHR(presentQueue, &presentInfo);
|
||||||
|
if (result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR)
|
||||||
|
{
|
||||||
|
framebufferResized = false;
|
||||||
|
recreateSwapChain();
|
||||||
|
}
|
||||||
|
else if (result != VK_SUCCESS)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("failed to present swap chain image in drawFrame");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void VulkanBackend::VulkanFoundation::updateShaderData()
|
void VulkanBackend::VulkanFoundation::updateShaderData()
|
||||||
{
|
{
|
||||||
PBR::Material::shaderData.lightDir = glm::vec4(
|
PBR::Material::shaderData.lightDir = glm::vec4(
|
||||||
|
|
|
@ -13,8 +13,9 @@
|
||||||
#include "VulkanUtils.hpp"
|
#include "VulkanUtils.hpp"
|
||||||
#include "PBR.h"
|
#include "PBR.h"
|
||||||
#include "VulkanDevice.hpp"
|
#include "VulkanDevice.hpp"
|
||||||
#include <camera.hpp>
|
|
||||||
#include "renderUI.h"
|
#include "renderUI.h"
|
||||||
|
#include <camera.hpp>
|
||||||
|
|
||||||
|
|
||||||
namespace VulkanBackend
|
namespace VulkanBackend
|
||||||
{
|
{
|
||||||
|
@ -24,12 +25,37 @@ namespace VulkanBackend
|
||||||
VulkanFoundation();
|
VulkanFoundation();
|
||||||
~VulkanFoundation()
|
~VulkanFoundation()
|
||||||
{
|
{
|
||||||
|
// Clean up Vulkan resources
|
||||||
|
cleanupSwapChain();
|
||||||
|
vkDestroyDescriptorPool(device, descriptorPool, nullptr);
|
||||||
|
vkDestroyRenderPass(device, renderPass, nullptr);
|
||||||
|
for (uint32_t i = 0; i < framebuffers.size(); i++) {
|
||||||
|
vkDestroyFramebuffer(device, framebuffers[i], nullptr);
|
||||||
|
}
|
||||||
|
vkDestroyImageView(device, colorAttachment.view, nullptr);
|
||||||
|
vkDestroyImage(device, colorAttachment.image, nullptr);
|
||||||
|
vkFreeMemory(device, colorAttachment.memory, nullptr);
|
||||||
|
vkDestroyImageView(device, depthAttachment.view, nullptr);
|
||||||
|
vkDestroyImage(device, depthAttachment.image, nullptr);
|
||||||
|
vkFreeMemory(device, depthAttachment.memory, nullptr);
|
||||||
|
|
||||||
|
if (PlumageRender::Setter::settings.multiSampling) {
|
||||||
|
vkDestroyImage(device, multisampleTarget.colorAttachment.image, nullptr);
|
||||||
|
vkDestroyImageView(device, multisampleTarget.colorAttachment.view, nullptr);
|
||||||
|
vkFreeMemory(device, multisampleTarget.colorAttachment.memory, nullptr);
|
||||||
|
vkDestroyImage(device, multisampleTarget.depthAttachment.image, nullptr);
|
||||||
|
vkDestroyImageView(device, multisampleTarget.depthAttachment.view, nullptr);
|
||||||
|
vkFreeMemory(device, multisampleTarget.depthAttachment.memory, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Clean up used Vulkan resources
|
// Clean up used Vulkan resources
|
||||||
// Note : Inherited destructor cleans up resources stored in base class
|
// Note : Inherited destructor cleans up resources stored in base class
|
||||||
vkDestroyPipeline(device, pipelines.skybox, nullptr);
|
vkDestroyPipeline(device, pipelines.skybox, nullptr);
|
||||||
vkDestroyPipeline(device, pipelines.pbr, nullptr);
|
vkDestroyPipeline(device, pipelines.pbr, nullptr);
|
||||||
vkDestroyPipeline(device, pipelines.pbrAlphaBlend, nullptr);
|
vkDestroyPipeline(device, pipelines.pbrAlphaBlend, nullptr);
|
||||||
|
vkDestroyPipelineCache(device, pipelineCache, nullptr);
|
||||||
|
vkDestroyCommandPool(device, commandPool, nullptr);
|
||||||
vkDestroyPipelineLayout(device, pipelineLayout, nullptr);
|
vkDestroyPipelineLayout(device, pipelineLayout, nullptr);
|
||||||
vkDestroyDescriptorSetLayout(device, descriptorSetLayouts.scene, nullptr);
|
vkDestroyDescriptorSetLayout(device, descriptorSetLayouts.scene, nullptr);
|
||||||
vkDestroyDescriptorSetLayout(device, descriptorSetLayouts.material, nullptr);
|
vkDestroyDescriptorSetLayout(device, descriptorSetLayouts.material, nullptr);
|
||||||
|
@ -51,6 +77,11 @@ namespace VulkanBackend
|
||||||
for (auto semaphore : presentCompleteSemaphores) {
|
for (auto semaphore : presentCompleteSemaphores) {
|
||||||
vkDestroySemaphore(device, semaphore, nullptr);
|
vkDestroySemaphore(device, semaphore, nullptr);
|
||||||
}
|
}
|
||||||
|
delete vulkanDevice;
|
||||||
|
if (PlumageRender::Setter::settings.validation) {
|
||||||
|
DestroyDebugUtilsMessengerEXT(instance, debugMessenger, nullptr);
|
||||||
|
}
|
||||||
|
vkDestroyInstance(instance, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<const char*> validationLayers = {
|
const std::vector<const char*> validationLayers = {
|
||||||
|
@ -72,7 +103,14 @@ namespace VulkanBackend
|
||||||
|
|
||||||
static VkQueue graphicQueue;
|
static VkQueue graphicQueue;
|
||||||
|
|
||||||
|
struct FrameBufferAttachment
|
||||||
|
{
|
||||||
|
VkImage image;
|
||||||
|
VkDeviceMemory memory;
|
||||||
|
VkImageView view;
|
||||||
|
}depthAttachment;
|
||||||
|
|
||||||
|
static FrameBufferAttachment colorAttachment;
|
||||||
|
|
||||||
static VkPipelineCache pipelineCache;
|
static VkPipelineCache pipelineCache;
|
||||||
|
|
||||||
|
@ -120,9 +158,15 @@ namespace VulkanBackend
|
||||||
|
|
||||||
void recreateSwapChain();
|
void recreateSwapChain();
|
||||||
|
|
||||||
|
bool acqureNextSwapchainImage(bool framebuffeerResized, uint32_t imageIndex, uint32_t frameIndex);
|
||||||
|
|
||||||
|
void submitToGraphicQueue(uint32_t frameIndex, uint32_t currentBuffer);
|
||||||
|
|
||||||
|
void imageToQueuePresent(uint32_t frameIndex, uint32_t imageIndex, bool framebufferResized);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
PlumageRender::PlumageGUI plumageGui;
|
||||||
|
|
||||||
VkInstance instance;
|
VkInstance instance;
|
||||||
|
|
||||||
|
@ -178,12 +222,7 @@ namespace VulkanBackend
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct FrameBufferAttachment
|
|
||||||
{
|
|
||||||
VkImage image;
|
|
||||||
VkDeviceMemory memory;
|
|
||||||
VkImageView view;
|
|
||||||
}colorAttachment,depthAttachment;
|
|
||||||
|
|
||||||
struct MultisampleTarget {
|
struct MultisampleTarget {
|
||||||
FrameBufferAttachment colorAttachment;
|
FrameBufferAttachment colorAttachment;
|
||||||
|
@ -255,6 +294,7 @@ namespace VulkanBackend
|
||||||
const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData,
|
const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData,
|
||||||
void* pUserData);
|
void* pUserData);
|
||||||
VkResult CreateDebugUtilsMessengerEXT(VkInstance instance, const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDebugUtilsMessengerEXT* pDebugMessenger);
|
VkResult CreateDebugUtilsMessengerEXT(VkInstance instance, const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDebugUtilsMessengerEXT* pDebugMessenger);
|
||||||
|
void DestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT debugMessenger, const VkAllocationCallbacks* pAllocator);
|
||||||
|
|
||||||
// 通过检查队列、交换链、扩展支持,选择合适的显卡
|
// 通过检查队列、交换链、扩展支持,选择合适的显卡
|
||||||
void pickPhysicalDevice();
|
void pickPhysicalDevice();
|
||||||
|
@ -284,6 +324,9 @@ namespace VulkanBackend
|
||||||
|
|
||||||
// 创建资源描述符层级,用于访问绑定的资源
|
// 创建资源描述符层级,用于访问绑定的资源
|
||||||
void createDescriptorSetLayout();
|
void createDescriptorSetLayout();
|
||||||
|
void createSceneDescriptorSetLayout();
|
||||||
|
void createMaterialDescriptorSetLayout();
|
||||||
|
void createNodeDescriptorSetLayout();
|
||||||
|
|
||||||
// 创建管线缓存
|
// 创建管线缓存
|
||||||
void createPipelineCache();
|
void createPipelineCache();
|
||||||
|
@ -325,6 +368,7 @@ namespace VulkanBackend
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
VulkanFoundation::VulkanFoundation()
|
VulkanFoundation::VulkanFoundation()
|
||||||
|
|
Loading…
Reference in New Issue