WIP Vulkan Pipeline refactoring
This commit is contained in:
@@ -932,7 +932,7 @@ KrResult KRContext::createWindowSurface(const KrCreateWindowSurfaceInfo* createW
|
||||
if (m_vulkanInstance == VK_NULL_HANDLE) {
|
||||
return KR_ERROR_VULKAN_REQUIRED;
|
||||
}
|
||||
if (m_surfaces.count(createWindowSurfaceInfo->surfaceHandle)) {
|
||||
if (m_surfaceHandleMap.count(createWindowSurfaceInfo->surfaceHandle)) {
|
||||
return KR_ERROR_DUPLICATE_HANDLE;
|
||||
}
|
||||
|
||||
@@ -959,33 +959,6 @@ KrResult KRContext::createWindowSurface(const KrCreateWindowSurfaceInfo* createW
|
||||
|
||||
m_surfaceHandleMap.insert(std::pair<KrSurfaceMapIndex, KrSurfaceHandle>(createWindowSurfaceInfo->surfaceHandle, surfaceHandle));
|
||||
|
||||
m_pPipelineManager->createPipelines(surfaceHandle);
|
||||
|
||||
{
|
||||
KRPipeline* testPipeline = m_pPipelineManager->get("vulkan_test");
|
||||
KRSurface& surface = *m_surfaces[surfaceHandle];
|
||||
surface.m_swapChainFramebuffers.resize(surface.m_swapChainImageViews.size());
|
||||
|
||||
for (size_t i = 0; i < surface.m_swapChainImageViews.size(); i++) {
|
||||
VkImageView attachments[] = {
|
||||
surface.m_swapChainImageViews[i]
|
||||
};
|
||||
|
||||
VkFramebufferCreateInfo framebufferInfo{};
|
||||
framebufferInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
|
||||
framebufferInfo.renderPass = testPipeline->getRenderPass();
|
||||
framebufferInfo.attachmentCount = 1;
|
||||
framebufferInfo.pAttachments = attachments;
|
||||
framebufferInfo.width = surface.m_swapChainExtent.width;
|
||||
framebufferInfo.height = surface.m_swapChainExtent.height;
|
||||
framebufferInfo.layers = 1;
|
||||
|
||||
if (vkCreateFramebuffer(deviceInfo->m_logicalDevice, &framebufferInfo, nullptr, &surface.m_swapChainFramebuffers[i]) != VK_SUCCESS) {
|
||||
// TODO - Error Handling
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return KR_SUCCESS;
|
||||
#else
|
||||
// Not implemented for this platform
|
||||
|
||||
@@ -109,15 +109,14 @@ const char *KRPipeline::KRENGINE_UNIFORM_NAMES[] = {
|
||||
"fade_color", // KRENGINE_UNIFORM_FADE_COLOR
|
||||
};
|
||||
|
||||
KRPipeline::KRPipeline(KRContext& context, KrSurfaceHandle surfaceHandle, const char* szKey, const std::vector<KRShader*>& shaders)
|
||||
KRPipeline::KRPipeline(KRContext& context, KrDeviceHandle deviceHandle, VkFormat swapChainImageFormat, uint32_t swapChainWidth, uint32_t swapChainHeight, const char* szKey, const std::vector<KRShader*>& shaders)
|
||||
: KRContextObject(context)
|
||||
, m_iProgram(0) // not used for Vulkan
|
||||
{
|
||||
m_pipelineLayout = nullptr;
|
||||
m_graphicsPipeline = nullptr;
|
||||
m_renderPass = nullptr;
|
||||
KRSurface& surface = m_pContext->GetSurfaceInfo(surfaceHandle);
|
||||
KRDevice& device = m_pContext->GetDeviceInfo(surface.m_deviceHandle);
|
||||
KRDevice& device = m_pContext->GetDeviceInfo(deviceHandle);
|
||||
|
||||
strcpy(m_szKey, szKey);
|
||||
|
||||
@@ -145,7 +144,7 @@ KRPipeline::KRPipeline(KRContext& context, KrSurfaceHandle surfaceHandle, const
|
||||
}
|
||||
|
||||
VkAttachmentDescription colorAttachment{};
|
||||
colorAttachment.format = surface.m_swapChainImageFormat;
|
||||
colorAttachment.format = swapChainImageFormat;
|
||||
colorAttachment.samples = VK_SAMPLE_COUNT_1_BIT;
|
||||
colorAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||||
colorAttachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
|
||||
@@ -199,14 +198,15 @@ KRPipeline::KRPipeline(KRContext& context, KrSurfaceHandle surfaceHandle, const
|
||||
VkViewport viewport{};
|
||||
viewport.x = 0.0f;
|
||||
viewport.y = 0.0f;
|
||||
viewport.width = (float)surface.m_swapChainExtent.width;
|
||||
viewport.height = (float)surface.m_swapChainExtent.height;
|
||||
viewport.width = static_cast<float>(swapChainWidth);
|
||||
viewport.height = static_cast<float>(swapChainHeight);
|
||||
viewport.minDepth = 0.0f;
|
||||
viewport.maxDepth = 1.0f;
|
||||
|
||||
VkRect2D scissor{};
|
||||
scissor.offset = { 0, 0 };
|
||||
scissor.extent = surface.m_swapChainExtent;
|
||||
scissor.extent.width = swapChainWidth;
|
||||
scissor.extent.height = swapChainHeight;
|
||||
|
||||
VkPipelineViewportStateCreateInfo viewportState{};
|
||||
viewportState.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
|
||||
|
||||
@@ -44,7 +44,7 @@ class KRShader;
|
||||
|
||||
class KRPipeline : public KRContextObject {
|
||||
public:
|
||||
KRPipeline(KRContext& context, KrSurfaceHandle surfaceHandle, const char* szKey, const std::vector<KRShader*>& shaders);
|
||||
KRPipeline(KRContext& context, KrDeviceHandle deviceHandle, VkFormat swapChainImageFormat, uint32_t swapChainWidth, uint32_t swapChainHeight, const char* szKey, const std::vector<KRShader*>& shaders);
|
||||
KRPipeline(KRContext &context, char *szKey, std::string options, std::string vertShaderSource, const std::string fragShaderSource);
|
||||
virtual ~KRPipeline();
|
||||
const char *getKey() const;
|
||||
|
||||
@@ -62,7 +62,7 @@ KRPipelineManager::~KRPipelineManager() {
|
||||
#endif // ANDROID
|
||||
}
|
||||
|
||||
void KRPipelineManager::createPipelines(KrSurfaceHandle surface)
|
||||
void KRPipelineManager::createPipelines(KRSurface& surface)
|
||||
{
|
||||
{
|
||||
// vulkan_test
|
||||
@@ -70,7 +70,7 @@ void KRPipelineManager::createPipelines(KrSurfaceHandle surface)
|
||||
std::vector<KRShader*> shaders;
|
||||
shaders.push_back(m_pContext->getShaderManager()->get(pipeline_name + ".vert", "spv"));
|
||||
shaders.push_back(m_pContext->getShaderManager()->get(pipeline_name + ".frag", "spv"));
|
||||
KRPipeline* pipeline = new KRPipeline(*m_pContext, surface, pipeline_name.c_str(), shaders);
|
||||
KRPipeline* pipeline = new KRPipeline(*m_pContext, surface.m_deviceHandle, surface.m_swapChainImageFormat, surface.m_swapChainExtent.width, surface.m_swapChainExtent.height , pipeline_name.c_str(), shaders);
|
||||
std::pair<std::string, std::vector<int> > key;
|
||||
key.first = pipeline_name;
|
||||
m_pipelines[key] = pipeline;
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#include "KRCamera.h"
|
||||
#include "KRDataBlock.h"
|
||||
#include "KRNode.h"
|
||||
#include "KRSurface.h"
|
||||
|
||||
using std::map;
|
||||
using std::vector;
|
||||
@@ -51,7 +52,7 @@ class KRPipelineManager : public KRContextObject {
|
||||
public:
|
||||
KRPipelineManager(KRContext &context);
|
||||
virtual ~KRPipelineManager();
|
||||
void createPipelines(KrSurfaceHandle surface);
|
||||
void createPipelines(KRSurface& surface);
|
||||
KRPipeline* get(const char* szKey);
|
||||
|
||||
KRPipeline *getPipeline(const std::string &pipeline_name, KRCamera *pCamera, const std::vector<KRPointLight *> &point_lights, const std::vector<KRDirectionalLight *> &directional_lights, const std::vector<KRSpotLight *>&spot_lights, int bone_count, bool bDiffuseMap, bool bNormalMap, bool bSpecMap, bool bReflectionMap, bool bReflectionCubeMap, bool bLightMap, bool bDiffuseMapScale,bool bSpecMapScale, bool bNormalMapScale, bool bReflectionMapScale, bool bDiffuseMapOffset, bool bSpecMapOffset, bool bNormalMapOffset, bool bReflectionMapOffset, bool bAlphaTest, bool bAlphaBlend, KRNode::RenderPass renderPass, bool bRimColor = false);
|
||||
|
||||
@@ -202,6 +202,29 @@ KrResult KRSurface::initialize()
|
||||
}
|
||||
}
|
||||
|
||||
KRPipelineManager* pipelineManager = m_pContext->getPipelineManager();
|
||||
pipelineManager->createPipelines(*this);
|
||||
|
||||
KRPipeline* testPipeline = pipelineManager->get("vulkan_test");
|
||||
m_swapChainFramebuffers.resize(m_swapChainImageViews.size());
|
||||
|
||||
for (size_t i = 0; i < m_swapChainImageViews.size(); i++) {
|
||||
VkImageView attachments[] = { m_swapChainImageViews[i] };
|
||||
|
||||
VkFramebufferCreateInfo framebufferInfo{};
|
||||
framebufferInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
|
||||
framebufferInfo.renderPass = testPipeline->getRenderPass();
|
||||
framebufferInfo.attachmentCount = 1;
|
||||
framebufferInfo.pAttachments = attachments;
|
||||
framebufferInfo.width = m_swapChainExtent.width;
|
||||
framebufferInfo.height = m_swapChainExtent.height;
|
||||
framebufferInfo.layers = 1;
|
||||
|
||||
if (vkCreateFramebuffer(deviceInfo->m_logicalDevice, &framebufferInfo, nullptr, &m_swapChainFramebuffers[i]) != VK_SUCCESS) {
|
||||
return KR_ERROR_VULKAN_FRAMEBUFFER;
|
||||
}
|
||||
}
|
||||
|
||||
return KR_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ typedef enum {
|
||||
KR_ERROR_VULKAN,
|
||||
KR_ERROR_VULKAN_REQUIRED,
|
||||
KR_ERROR_VULKAN_SWAP_CHAIN,
|
||||
KR_ERROR_VULKAN_FRAMEBUFFER,
|
||||
KR_ERROR_NO_DEVICE,
|
||||
KR_ERROR_SHADER_COMPILE_FAILED,
|
||||
KR_ERROR_UNEXPECTED = 0x10000000,
|
||||
|
||||
Reference in New Issue
Block a user