From d8eba446a154660155d58202203873634b3f906e Mon Sep 17 00:00:00 2001 From: nek0 Date: Thu, 21 Jul 2022 23:12:54 +0200 Subject: [PATCH] detach some create info creation --- src/GraphicsPipeline.hs | 95 ++++++++++++++++++++++++----------------- src/Init.hs | 1 - 2 files changed, 57 insertions(+), 39 deletions(-) diff --git a/src/GraphicsPipeline.hs b/src/GraphicsPipeline.hs index 13f94a9..7d3c7b1 100644 --- a/src/GraphicsPipeline.hs +++ b/src/GraphicsPipeline.hs @@ -19,6 +19,8 @@ import qualified Vulkan.Utils.ShaderQQ.GLSL.Shaderc as Vk -- internal imports import Types +import qualified Vulkan as VK +import qualified Vulkan.CStruct.Extends as VK loadShader :: (MonadResource m) @@ -104,13 +106,56 @@ createRenderPass Vk.destroyRenderPass logicalDevice renderPass Nothing ) +createShaderStageCreateInfo + :: Vk.ShaderStageFlagBits + -> Vk.ShaderModule + -> Vk.PipelineShaderStageCreateInfo '[] +createShaderStageCreateInfo stageBit shaderModule = + Vk.zero + { Vk.stage = stageBit + , Vk.module' = shaderModule + , Vk.name = "main" + } + +createVertexInputAssemblyStateCreateInfo + :: Vk.PrimitiveTopology + -> Vk.PipelineInputAssemblyStateCreateInfo +createVertexInputAssemblyStateCreateInfo topology = + Vk.zero + { Vk.topology = topology + , Vk.primitiveRestartEnable = False + } + +createRasterizationStateCreateInfo + :: Vk.PolygonMode + -> VK.SomeStruct Vk.PipelineRasterizationStateCreateInfo +createRasterizationStateCreateInfo mode = + Vk.SomeStruct $ Vk.zero + { Vk.depthClampEnable = False + , Vk.rasterizerDiscardEnable = False + , Vk.polygonMode = mode + , Vk.lineWidth = 1 + , Vk.cullMode = Vk.CULL_MODE_NONE + , Vk.frontFace = Vk.FRONT_FACE_CLOCKWISE + , Vk.depthBiasEnable = False + , Vk.depthBiasConstantFactor = 0 + , Vk.depthBiasClamp = 0 + , Vk.depthBiasSlopeFactor = 0 + } + +createMultisampleStateCreateInfo + :: Vk.SomeStruct Vk.PipelineMultisampleStateCreateInfo +createMultisampleStateCreateInfo = + Vk.SomeStruct $ Vk.zero + { Vk.sampleShadingEnable = False + , Vk.rasterizationSamples = Vk.SAMPLE_COUNT_1_BIT + } createGraphicsPipelines :: (MonadResource m) => Vk.Device -> Vk.RenderPass -> ShaderContainer - -> BS.ByteString -> V2 CInt -> Int -> Vk.PipelineLayout @@ -119,25 +164,18 @@ createGraphicsPipelines logicalDevice renderPass shaderContainer - stageName (V2 width height) number pipelineLayout = do - let vertexShaderStageCreateInfo = Vk.zero - { Vk.stage = Vk.SHADER_STAGE_VERTEX_BIT - , Vk.module' = containedVertexShader shaderContainer - , Vk.name = stageName - } - fragmentShaderStageCreateInfo = Vk.zero - { Vk.stage = Vk.SHADER_STAGE_FRAGMENT_BIT - , Vk.module' = containedFragmentShader shaderContainer - , Vk.name = stageName - } - pipelineStagesCreateInfos = + let pipelineStagesCreateInfos = V.fromList $ map Vk.SomeStruct - [ vertexShaderStageCreateInfo - , fragmentShaderStageCreateInfo + [ createShaderStageCreateInfo + Vk.SHADER_STAGE_VERTEX_BIT + (containedVertexShader shaderContainer) + , createShaderStageCreateInfo + Vk.SHADER_STAGE_FRAGMENT_BIT + (containedFragmentShader shaderContainer) ] dynamicStates = V.fromList @@ -151,10 +189,6 @@ createGraphicsPipelines { Vk.vertexBindingDescriptions = V.empty -- Fill me? , Vk.vertexAttributeDescriptions = V.empty -- Fill me? } - pipelineInputAssemblyStateCreateInfo = Vk.zero - { Vk.topology = Vk.PRIMITIVE_TOPOLOGY_TRIANGLE_LIST - , Vk.primitiveRestartEnable = False - } viewport = Vk.Viewport { Vk.x = 0 , Vk.y = 0 @@ -171,22 +205,6 @@ createGraphicsPipelines { Vk.viewports = V.singleton viewport , Vk.scissors = V.singleton scissor } - pipelineRasterizationStateCreateInfo = Vk.zero - { Vk.depthClampEnable = False - , Vk.rasterizerDiscardEnable = False - , Vk.polygonMode = Vk.POLYGON_MODE_FILL - , Vk.lineWidth = 1 - , Vk.cullMode = Vk.CULL_MODE_BACK_BIT - , Vk.frontFace = Vk.FRONT_FACE_CLOCKWISE - , Vk.depthBiasEnable = False - , Vk.depthBiasConstantFactor = 0 - , Vk.depthBiasClamp = 0 - , Vk.depthBiasSlopeFactor = 0 - } - pipelineMultisamplingCreateInfo = Vk.zero - { Vk.sampleShadingEnable = False - , Vk.rasterizationSamples = Vk.SAMPLE_COUNT_1_BIT - } colorBlendAttachment = Vk.zero { Vk.colorWriteMask = Vk.COLOR_COMPONENT_R_BIT .|. @@ -209,10 +227,11 @@ createGraphicsPipelines { Vk.stageCount = 2 , Vk.stages = pipelineStagesCreateInfos , Vk.vertexInputState = Just $ Vk.SomeStruct pipelineVertexInputCreateInfo - , Vk.inputAssemblyState = Just pipelineInputAssemblyStateCreateInfo + , Vk.inputAssemblyState = + Just $ createVertexInputAssemblyStateCreateInfo VK.PRIMITIVE_TOPOLOGY_TRIANGLE_LIST , Vk.viewportState = Just $ Vk.SomeStruct pipelineViewportStateCreateInfo - , Vk.rasterizationState = Just $ Vk.SomeStruct pipelineRasterizationStateCreateInfo - , Vk.multisampleState = Just $ Vk.SomeStruct pipelineMultisamplingCreateInfo + , Vk.rasterizationState = Just $ createRasterizationStateCreateInfo Vk.POLYGON_MODE_FILL + , Vk.multisampleState = Just $ createMultisampleStateCreateInfo , Vk.colorBlendState = Just $ Vk.SomeStruct pipelineColorBlendStateCreateInfo , Vk.dynamicState = Just pipelineDynamicStateCreateInfo , Vk.layout = pipelineLayout diff --git a/src/Init.hs b/src/Init.hs index b7b3e47..7b2d0dd 100644 --- a/src/Init.hs +++ b/src/Init.hs @@ -88,7 +88,6 @@ initVulkan window = do vulkanLogicalDevice renderPass shaderContainer - "main" dimensions (length imageViews) pipelineLayout