renderpass
This commit is contained in:
parent
755ae866e9
commit
5cd703df01
@ -1,30 +1,31 @@
|
||||
#include "graph.h"
|
||||
namespace render {
|
||||
Graph::~Graph()
|
||||
{
|
||||
|
||||
render::Graph::~Graph()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
render::Graph::Graph(renderapi::Backend* backend, renderapi::Target* target)
|
||||
Graph::Graph(renderapi::Backend* backend, renderapi::Target* target)
|
||||
:mBackend(backend)
|
||||
{
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void render::Graph::Recreate(bool recursive)
|
||||
{
|
||||
void Graph::Recreate(bool recursive)
|
||||
{
|
||||
Destroy(recursive);
|
||||
if (!recursive) return;
|
||||
mBackend->Recreate();
|
||||
}
|
||||
}
|
||||
|
||||
void render::Graph::Destroy(bool recursive)
|
||||
{
|
||||
void Graph::Destroy(bool recursive)
|
||||
{
|
||||
if (!recursive) return;
|
||||
mBackend->Destroy();
|
||||
}
|
||||
}
|
||||
|
||||
void render::Graph::Draw(Object* scene)
|
||||
{
|
||||
void Graph::Draw(Object* scene)
|
||||
{
|
||||
//auto worker = mBackend->Worker(0);
|
||||
}
|
||||
}
|
||||
|
||||
22
engine/src/engine/render/pass/forwardpass.cpp
Normal file
22
engine/src/engine/render/pass/forwardpass.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
#include "forwardpass.h"
|
||||
#include "engine/vulkanapi/renderpass/renderpass.h"
|
||||
namespace vulkanapi {
|
||||
ForwardPass::ForwardPass(VkDevice device)
|
||||
:mPass(nullptr)
|
||||
{
|
||||
VkAttachmentDescription depthAttachment{};
|
||||
//depthAttachment.format = findDepthFormat();
|
||||
depthAttachment.samples = VK_SAMPLE_COUNT_1_BIT;
|
||||
depthAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||||
depthAttachment.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
||||
depthAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||
depthAttachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
||||
depthAttachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||
depthAttachment.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
||||
|
||||
std::vector<VkAttachmentDescription> attachments = { depthAttachment };
|
||||
std::vector<VkSubpassDescription> subpasses;
|
||||
std::vector<VkSubpassDependency> dependencies;
|
||||
mPass = new RenderPass(device,"forward",attachments, subpasses, dependencies);
|
||||
}
|
||||
}
|
||||
10
engine/src/engine/render/pass/forwardpass.h
Normal file
10
engine/src/engine/render/pass/forwardpass.h
Normal file
@ -0,0 +1,10 @@
|
||||
#include "engine/vulkanapi/vulkan.h"
|
||||
namespace vulkanapi {
|
||||
class RenderPass;
|
||||
class ForwardPass {
|
||||
protected:
|
||||
RenderPass* mPass;
|
||||
public:
|
||||
ForwardPass(VkDevice device);
|
||||
};
|
||||
}
|
||||
8
engine/src/engine/vulkanapi/image/image.cpp
Normal file
8
engine/src/engine/vulkanapi/image/image.cpp
Normal file
@ -0,0 +1,8 @@
|
||||
#include "image.h"
|
||||
namespace vulkanapi {
|
||||
Image::Image(VkImage img)
|
||||
:mPtr(img)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
12
engine/src/engine/vulkanapi/image/image.h
Normal file
12
engine/src/engine/vulkanapi/image/image.h
Normal file
@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include "engine/vulkanapi/vulkan.h"
|
||||
|
||||
namespace vulkanapi {
|
||||
class Image {
|
||||
protected:
|
||||
VkImage mPtr;
|
||||
public:
|
||||
Image(VkImage img);
|
||||
};
|
||||
};
|
||||
22
engine/src/engine/vulkanapi/renderpass/renderpass.cpp
Normal file
22
engine/src/engine/vulkanapi/renderpass/renderpass.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
#include "renderpass.h"
|
||||
namespace vulkanapi {
|
||||
RenderPass::RenderPass(VkDevice device, const char* name,
|
||||
std::vector<VkAttachmentDescription>& attachments,
|
||||
std::vector<VkSubpassDescription>& subpasses,
|
||||
std::vector<VkSubpassDependency>& dependencies)
|
||||
{
|
||||
//pAttachments
|
||||
VkRenderPassCreateInfo create_info{
|
||||
VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
|
||||
nullptr,
|
||||
0,
|
||||
attachments.size(),
|
||||
attachments.data(),
|
||||
subpasses.size(),
|
||||
subpasses.data(),
|
||||
dependencies.size(),
|
||||
dependencies.data()
|
||||
};
|
||||
vkCreateRenderPass(device, &create_info, nullptr, &mPtr);
|
||||
}
|
||||
}
|
||||
17
engine/src/engine/vulkanapi/renderpass/renderpass.h
Normal file
17
engine/src/engine/vulkanapi/renderpass/renderpass.h
Normal file
@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include "engine/vulkanapi/vulkan.h"
|
||||
#include <vector>
|
||||
|
||||
namespace vulkanapi {
|
||||
class RenderPass {
|
||||
protected:
|
||||
VkRenderPass mPtr;
|
||||
public:
|
||||
RenderPass(VkDevice device, const char* name,
|
||||
std::vector<VkAttachmentDescription>& attachments,
|
||||
std::vector<VkSubpassDescription>& subpasses,
|
||||
std::vector<VkSubpassDependency>& dependencies);
|
||||
//colorAttachments, depthAttachment, subpasses, dependencies);
|
||||
};
|
||||
};
|
||||
@ -1,5 +1,6 @@
|
||||
#include "swapchain.h"
|
||||
#include "engine/vulkanapi/device/device.h"
|
||||
#include "engine/vulkanapi/image/image.h"
|
||||
#include "swapchain_help.h"
|
||||
namespace vulkanapi {
|
||||
Swapchain::Swapchain(Device* device, int frames, int width, int height, VkSurfaceKHR presentation_surface)
|
||||
@ -14,12 +15,24 @@ namespace vulkanapi {
|
||||
SelectFormatOfSwapchainImages(physical_device, presentation_surface, { VK_FORMAT_B8G8R8A8_UNORM, VK_COLOR_SPACE_SRGB_NONLINEAR_KHR },
|
||||
image_format, image_color_space);
|
||||
|
||||
VkSurfaceCapabilitiesKHR surface_capabilities;
|
||||
GetCapabilitiesOfPresentationSurface(physical_device, presentation_surface, surface_capabilities);
|
||||
|
||||
VkExtent2D image_size{ (uint32_t)width ,(uint32_t)height };
|
||||
ChooseSizeOfSwapchainImages(surface_capabilities, image_size);
|
||||
|
||||
//调用设备接口,创建交换链
|
||||
VkSwapchainKHR old_swapchain = VK_NULL_HANDLE;
|
||||
CreateSwapchain(device->Ptr(), presentation_surface, frames, { image_format, image_color_space }, { (uint32_t)width ,(uint32_t)height }
|
||||
CreateSwapchain(device->Ptr(), presentation_surface, frames, { image_format, image_color_space }, image_size
|
||||
, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR,
|
||||
VK_PRESENT_MODE_FIFO_KHR, old_swapchain, mPtr);
|
||||
|
||||
std::vector<VkImage> swapchain_images;
|
||||
GetHandlesOfSwapchainImages(device->Ptr(), mPtr, swapchain_images);
|
||||
|
||||
uint32_t image_count = swapchain_images.size();
|
||||
for (auto img : swapchain_images) {
|
||||
mImages.push_back(new Image(img));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,12 +1,15 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "engine/vulkanapi/vulkan.h"
|
||||
|
||||
namespace vulkanapi {
|
||||
class Device;
|
||||
class Image;
|
||||
class Swapchain {
|
||||
protected:
|
||||
VkSwapchainKHR mPtr;
|
||||
std::vector<Image*> mImages;
|
||||
public:
|
||||
Swapchain(Device* device,int frames, int width, int height, VkSurfaceKHR presentation_surface);
|
||||
};
|
||||
|
||||
@ -1,6 +1,39 @@
|
||||
#include "engine/vulkanapi/vulkan/instance/instance.h"
|
||||
#include <iostream>
|
||||
namespace vulkanapi {
|
||||
bool GetCapabilitiesOfPresentationSurface(VkPhysicalDevice physical_device,
|
||||
VkSurfaceKHR presentation_surface,
|
||||
VkSurfaceCapabilitiesKHR& surface_capabilities) {
|
||||
VkResult result = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physical_device, presentation_surface, &surface_capabilities);
|
||||
|
||||
if (VK_SUCCESS != result) {
|
||||
std::cout << "Could not get the capabilities of a presentation surface." << std::endl;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool ChooseSizeOfSwapchainImages(VkSurfaceCapabilitiesKHR const& surface_capabilities,
|
||||
VkExtent2D& size_of_images) {
|
||||
if (0xFFFFFFFF == surface_capabilities.currentExtent.width) {
|
||||
if (size_of_images.width < surface_capabilities.minImageExtent.width) {
|
||||
size_of_images.width = surface_capabilities.minImageExtent.width;
|
||||
}
|
||||
else if (size_of_images.width > surface_capabilities.maxImageExtent.width) {
|
||||
size_of_images.width = surface_capabilities.maxImageExtent.width;
|
||||
}
|
||||
|
||||
if (size_of_images.height < surface_capabilities.minImageExtent.height) {
|
||||
size_of_images.height = surface_capabilities.minImageExtent.height;
|
||||
}
|
||||
else if (size_of_images.height > surface_capabilities.maxImageExtent.height) {
|
||||
size_of_images.height = surface_capabilities.maxImageExtent.height;
|
||||
}
|
||||
}
|
||||
else {
|
||||
size_of_images = surface_capabilities.currentExtent;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool SelectFormatOfSwapchainImages(VkPhysicalDevice physical_device,
|
||||
VkSurfaceKHR presentation_surface,
|
||||
VkSurfaceFormatKHR desired_surface_format,
|
||||
@ -99,6 +132,29 @@ namespace vulkanapi {
|
||||
old_swapchain = VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
bool GetHandlesOfSwapchainImages(VkDevice logical_device,
|
||||
VkSwapchainKHR swapchain,
|
||||
std::vector<VkImage>& swapchain_images) {
|
||||
uint32_t images_count = 0;
|
||||
VkResult result = VK_SUCCESS;
|
||||
|
||||
result = vkGetSwapchainImagesKHR(logical_device, swapchain, &images_count, nullptr);
|
||||
if ((VK_SUCCESS != result) ||
|
||||
(0 == images_count)) {
|
||||
std::cout << "Could not get the number of swapchain images." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
swapchain_images.resize(images_count);
|
||||
result = vkGetSwapchainImagesKHR(logical_device, swapchain, &images_count, swapchain_images.data());
|
||||
if ((VK_SUCCESS != result) ||
|
||||
(0 == images_count)) {
|
||||
std::cout << "Could not enumerate swapchain images." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -12,7 +12,7 @@ std::vector<char const*> extensions = {
|
||||
};
|
||||
std::vector<char const*> layers = {
|
||||
"VK_LAYER_KHRONOS_validation",
|
||||
"VK_LAYER_LUNARG_api_dump",
|
||||
//"VK_LAYER_LUNARG_api_dump",
|
||||
};
|
||||
namespace vulkanapi {
|
||||
Instance::Instance(const char* appName) {
|
||||
@ -36,9 +36,10 @@ namespace vulkanapi {
|
||||
};
|
||||
extensions = _EnabledExtensionNames(extensions);
|
||||
layers = _EnabledLayerNames(layers);
|
||||
VkDebugUtilsMessengerCreateInfoEXT createInfo = _DebugUtilsLayerNext();
|
||||
VkInstanceCreateInfo instance_create_info = {
|
||||
VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, // VkStructureType sType
|
||||
nullptr, // const void * pNext
|
||||
&createInfo, // const void * pNext
|
||||
0, // VkInstanceCreateFlags flags
|
||||
&application_info, // const VkApplicationInfo * pApplicationInfo
|
||||
static_cast<uint32_t>(layers.size()), // uint32_t enabledLayerCount
|
||||
|
||||
@ -72,7 +72,7 @@ namespace vulkanapi {
|
||||
} \
|
||||
}
|
||||
|
||||
#include "ListOfVulkanFunctions.inl"
|
||||
#include "engine/vulkanapi/vulkan_function_list.inl"
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -168,4 +168,23 @@ namespace vulkanapi {
|
||||
}
|
||||
return _layers;
|
||||
}
|
||||
// debug callback
|
||||
static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT,
|
||||
VkDebugUtilsMessageTypeFlagsEXT,
|
||||
const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData,
|
||||
void*)
|
||||
{
|
||||
std::cerr << "validation layer: " << pCallbackData->pMessage << std::endl;
|
||||
return VK_FALSE;
|
||||
}
|
||||
VkDebugUtilsMessengerCreateInfoEXT _DebugUtilsLayerNext() {
|
||||
VkDebugUtilsMessengerCreateInfoEXT createInfo{};
|
||||
createInfo.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT;
|
||||
createInfo.messageSeverity =
|
||||
VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT;
|
||||
createInfo.messageType =
|
||||
VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT;
|
||||
createInfo.pfnUserCallback = debugCallback;
|
||||
return createInfo;
|
||||
}
|
||||
};
|
||||
@ -1,6 +1,7 @@
|
||||
#include <iostream>
|
||||
#include "engine/vulkanapi/vulkan/backend.h"
|
||||
#include "engine/vulkanapi/vulkan/window.h"
|
||||
#include "engine/vulkanapi/renderpass/renderpass.h"
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
@ -8,6 +9,7 @@ int main(int argc, char** argv)
|
||||
const char* name = "hello";
|
||||
auto app = vulkanapi::Backend(name);
|
||||
auto wnd = vulkanapi::Window(&app, 3, 640, 720, name);
|
||||
//auto pass = vulkanapi::RenderPass();
|
||||
cout << name << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user