Added KRPipeline constructor that is not dependent on KRSurface

This commit is contained in:
2022-09-27 18:58:00 -07:00
parent a2a9714f24
commit 230783b3c9
4 changed files with 21 additions and 10 deletions

View File

@@ -110,8 +110,17 @@ const char* KRPipeline::KRENGINE_PUSH_CONSTANT_NAMES[] = {
}; };
KRPipeline::KRPipeline(KRContext& context, KRSurface& surface, const PipelineInfo& info, const char* szKey, const std::vector<KRShader*>& shaders, uint32_t vertexAttributes, ModelFormat modelFormat) KRPipeline::KRPipeline(KRContext& context, KRSurface& surface, const PipelineInfo& info, const char* szKey, const std::vector<KRShader*>& shaders, uint32_t vertexAttributes, ModelFormat modelFormat)
: KRContextObject(context) : KRPipeline(context, surface.m_deviceHandle, surface.getForwardOpaquePass(), surface.getDimensions(), surface.getDimensions(), info, szKey, shaders, vertexAttributes, modelFormat)
{ {
// TODO - renderPass needs to be selected dynamically from info.render_pass
}
KRPipeline::KRPipeline(KRContext& context, KrDeviceHandle deviceHandle, KRRenderPass& renderPass, Vector2i viewport_size, Vector2i scissor_size, const PipelineInfo& info, const char* szKey, const std::vector<KRShader*>& shaders, uint32_t vertexAttributes, ModelFormat modelFormat)
: KRContextObject(context)
, m_deviceHandle(deviceHandle)
{
std::unique_ptr<KRDevice>& device = getContext().getDeviceManager()->getDevice(m_deviceHandle);
for (StageInfo& stageInfo : m_stages) { for (StageInfo& stageInfo : m_stages) {
PushConstantInfo& pushConstants = stageInfo.pushConstants; PushConstantInfo& pushConstants = stageInfo.pushConstants;
pushConstants.buffer = nullptr; pushConstants.buffer = nullptr;
@@ -127,8 +136,6 @@ KRPipeline::KRPipeline(KRContext& context, KRSurface& surface, const PipelineInf
m_descriptorSets.reserve(KRENGINE_MAX_FRAMES_IN_FLIGHT); m_descriptorSets.reserve(KRENGINE_MAX_FRAMES_IN_FLIGHT);
// TODO - Handle device removal // TODO - Handle device removal
m_deviceHandle = surface.m_deviceHandle;
std::unique_ptr<KRDevice>& device = surface.getDevice();
strcpy(m_szKey, szKey); strcpy(m_szKey, szKey);
@@ -260,15 +267,15 @@ KRPipeline::KRPipeline(KRContext& context, KRSurface& surface, const PipelineInf
VkViewport viewport{}; VkViewport viewport{};
viewport.x = 0.0f; viewport.x = 0.0f;
viewport.y = 0.0f; viewport.y = 0.0f;
viewport.width = static_cast<float>(surface.getWidth()); viewport.width = static_cast<float>(viewport_size.x);
viewport.height = static_cast<float>(surface.getHeight()); viewport.height = static_cast<float>(viewport_size.y);
viewport.minDepth = 0.0f; viewport.minDepth = 0.0f;
viewport.maxDepth = 1.0f; viewport.maxDepth = 1.0f;
VkRect2D scissor{}; VkRect2D scissor{};
scissor.offset = { 0, 0 }; scissor.offset = { 0, 0 };
scissor.extent.width = surface.getWidth(); scissor.extent.width = scissor_size.x;
scissor.extent.height = surface.getHeight(); scissor.extent.height = scissor_size.y;
VkPipelineViewportStateCreateInfo viewportState{}; VkPipelineViewportStateCreateInfo viewportState{};
viewportState.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; viewportState.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
@@ -443,8 +450,6 @@ KRPipeline::KRPipeline(KRContext& context, KRSurface& surface, const PipelineInf
depthStencil.front = {}; depthStencil.front = {};
depthStencil.back = {}; depthStencil.back = {};
KRRenderPass& renderPass = surface.getForwardOpaquePass(); // TODO - This needs to be selected dynamically from info.render_pass
VkGraphicsPipelineCreateInfo pipelineInfo{}; VkGraphicsPipelineCreateInfo pipelineInfo{};
pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
pipelineInfo.stageCount = stage_count; pipelineInfo.stageCount = stage_count;

View File

@@ -215,6 +215,7 @@ class KRPipeline : public KRContextObject
{ {
public: public:
KRPipeline(KRContext& context, KrDeviceHandle deviceHandle, KRRenderPass& renderPass, Vector2i viewport_size, Vector2i scissor_size, const PipelineInfo& info, const char* szKey, const std::vector<KRShader*>& shaders, uint32_t vertexAttributes, ModelFormat modelFormat);
KRPipeline(KRContext& context, KRSurface& surface, const PipelineInfo& info, const char* szKey, const std::vector<KRShader*>& shaders, uint32_t vertexAttributes, ModelFormat modelFormat); KRPipeline(KRContext& context, KRSurface& surface, const PipelineInfo& info, const char* szKey, const std::vector<KRShader*>& shaders, uint32_t vertexAttributes, ModelFormat modelFormat);
virtual ~KRPipeline(); virtual ~KRPipeline();
const char* getKey() const; const char* getKey() const;
@@ -249,7 +250,6 @@ public:
projection_matrix, projection_matrix,
camerapos_model_space, camerapos_model_space,
viewport, viewport,
viewport_downsample,
diffusetexture, diffusetexture,
speculartexture, speculartexture,
reflectioncubetexture, reflectioncubetexture,

View File

@@ -232,6 +232,11 @@ uint32_t KRSurface::getHeight() const
return m_swapChain->m_extent.height; return m_swapChain->m_extent.height;
} }
Vector2i KRSurface::getDimensions() const
{
return Vector2i::Create(static_cast<int>(m_swapChain->m_extent.width), static_cast<int>(m_swapChain->m_extent.height));
}
VkFormat KRSurface::getDepthFormat() const VkFormat KRSurface::getDepthFormat() const
{ {
return m_swapChain->m_depthFormat; return m_swapChain->m_depthFormat;

View File

@@ -50,6 +50,7 @@ public:
void destroy(); void destroy();
uint32_t getWidth() const; uint32_t getWidth() const;
uint32_t getHeight() const; uint32_t getHeight() const;
Vector2i getDimensions() const;
VkFormat getDepthFormat() const; VkFormat getDepthFormat() const;
KRSurface(const KRSurface&) = delete; KRSurface(const KRSurface&) = delete;